Java Code Examples for org.msgpack.core.MessageBufferPacker#packString()

The following examples show how to use org.msgpack.core.MessageBufferPacker#packString() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AbstractMaestroNote.java    From maestro-java with Apache License 2.0 6 votes vote down vote up
protected MessageBufferPacker pack() throws IOException {
    MessageBufferPacker packer = MessagePack.newDefaultBufferPacker();

    packer.packShort(noteType.getValue());
    packer.packLong(maestroCommand.getValue());

    correlate();

    packer.packString(correlation.getCorrelationId());
    packer.packString(correlation.getMessageId());

    if (logger.isTraceEnabled()) {
        logger.trace("Packed this {} note with correlation id {} and message id {}", this.maestroCommand,
                correlation.getCorrelationId(), correlation.getMessageId());
    }

    return packer;
}
 
Example 2
Source File: Message.java    From locust4j with MIT License 6 votes vote down vote up
public byte[] getBytes() throws IOException {
    MessageBufferPacker packer = MessagePack.newDefaultBufferPacker();
    Visitor visitor = new Visitor(packer);
    // a message contains three fields, (type & data & nodeID)
    packer.packArrayHeader(3);
    packer.packString(this.type);
    if (this.data != null) {
        packer.packMapHeader(this.data.size());
        for (Map.Entry<String, Object> entry : this.data.entrySet()) {
            packer.packString(entry.getKey());
            visitor.visit(entry.getValue());
        }
    } else {
        packer.packNil();
    }
    packer.packString(this.nodeID);
    byte[] bytes = packer.toByteArray();
    packer.close();
    return bytes;
}
 
Example 3
Source File: SerializationUtils.java    From maestro-java with Apache License 2.0 5 votes vote down vote up
public static void pack(final MessageBufferPacker packer, final SutDetails sutDetails) throws IOException {
    packer.packInt(sutDetails.getSutId());
    packer.packString(sutDetails.getSutName());
    packer.packString(sutDetails.getSutVersion());
    packer.packString(sutDetails.getSutJvmVersion());
    packer.packString(sutDetails.getSutOtherInfo());
    packer.packString(sutDetails.getSutTags());
    packer.packString(sutDetails.getLabName());
    packer.packString(sutDetails.getTestTags());
}
 
Example 4
Source File: TestFailedNotification.java    From maestro-java with Apache License 2.0 5 votes vote down vote up
@Override
protected MessageBufferPacker pack() throws IOException {
    MessageBufferPacker packer = super.pack();

    SerializationUtils.pack(packer, test);
    packer.packString(message);

    return packer;
}
 
Example 5
Source File: SerializationUtils.java    From maestro-java with Apache License 2.0 5 votes vote down vote up
public static void pack(final MessageBufferPacker packer, final Test test) throws IOException {
    packer.packInt(test.getTestNumber());
    packer.packInt(test.getTestIteration());
    packer.packString(test.getTestName());
    packer.packString(test.getScriptName());

    pack(packer, test.getTestDetails());
}
 
Example 6
Source File: Serializer.java    From tinkergraph-gremlin with Apache License 2.0 5 votes vote down vote up
/**
 * format: `[ValueType.id, value]`
 */
private void packPropertyValue(final MessageBufferPacker packer, final Object value) throws IOException {
  packer.packArrayHeader(2);
  if (value instanceof Boolean) {
    packer.packByte(ValueTypes.BOOLEAN.id);
    packer.packBoolean((Boolean) value);
  } else if (value instanceof String) {
    packer.packByte(ValueTypes.STRING.id);
    packer.packString((String) value);
  } else if (value instanceof Byte) {
    packer.packByte(ValueTypes.BYTE.id);
    packer.packByte((byte) value);
  } else if (value instanceof Short) {
    packer.packByte(ValueTypes.SHORT.id);
    packer.packShort((short) value);
  } else if (value instanceof Integer) {
    packer.packByte(ValueTypes.INTEGER.id);
    packer.packInt((int) value);
  } else if (value instanceof Long) {
    packer.packByte(ValueTypes.LONG.id);
    packer.packLong((long) value);
  } else if (value instanceof Float) {
    packer.packByte(ValueTypes.FLOAT.id);
    packer.packFloat((float) value);
  } else if (value instanceof Double) {
    packer.packByte(ValueTypes.DOUBLE.id);
    packer.packFloat((float) value); //msgpack doesn't support double, but we still want to deserialize it as a double later
  } else if (value instanceof List) {
    packer.packByte(ValueTypes.LIST.id);
    List listValue = (List) value;
    packer.packArrayHeader(listValue.size());
    final Iterator listIter = listValue.iterator();
    while (listIter.hasNext()) {
      packPropertyValue(packer, listIter.next());
    }
  } else {
    throw new NotImplementedException("id type `" + value.getClass() + "` not yet supported");
  }
}
 
Example 7
Source File: TestStartedNotification.java    From maestro-java with Apache License 2.0 5 votes vote down vote up
@Override
protected MessageBufferPacker pack() throws IOException {
    MessageBufferPacker packer = super.pack();

    SerializationUtils.pack(packer, test);
    packer.packString(message);

    return packer;
}
 
Example 8
Source File: MaestroNotification.java    From maestro-java with Apache License 2.0 5 votes vote down vote up
@Override
protected MessageBufferPacker pack() throws IOException {
    MessageBufferPacker packer = super.pack();

    packer.packString(this.id);
    packer.packString(peerInfo.groupInfo().memberName());
    packer.packString(peerInfo.groupInfo().groupName());
    packer.packInt(peerInfo.getRole().getCode());
    packer.packString(peerInfo.peerName());
    packer.packString(peerInfo.peerHost());

    return packer;
}
 
Example 9
Source File: GetResponse.java    From maestro-java with Apache License 2.0 5 votes vote down vote up
@Override
protected MessageBufferPacker pack() throws IOException {
    MessageBufferPacker packer = super.pack();

    packer.packLong(option.getValue());
    packer.packString(value);

    return packer;
}
 
Example 10
Source File: Serializer.java    From tinkergraph-gremlin with Apache License 2.0 5 votes vote down vote up
/**
 * when deserializing, msgpack can't differentiate between e.g. int and long, so we need to encode the type as well - doing that with an array
 * i.e. format is: Map[PropertyName, Array(TypeId, PropertyValue)]
 */
private void packProperties(MessageBufferPacker packer, Map<String, Object> properties) throws IOException {
  packer.packMapHeader(properties.size());
  for (Map.Entry<String, Object> property : properties.entrySet()) {
    packer.packString(property.getKey());
    packPropertyValue(packer, property.getValue());
  }
}
 
Example 11
Source File: AbstractMaestroNotification.java    From maestro-java with Apache License 2.0 5 votes vote down vote up
@Override
protected MessageBufferPacker pack() throws IOException {
    MessageBufferPacker packer = super.pack();

    packer.packString(this.id);
    packer.packString(peerInfo.groupInfo().memberName());
    packer.packString(peerInfo.groupInfo().groupName());
    packer.packInt(peerInfo.getRole().getCode());
    packer.packString(peerInfo.peerName());
    packer.packString(peerInfo.peerHost());

    return packer;
}
 
Example 12
Source File: UserCommand1Request.java    From maestro-java with Apache License 2.0 5 votes vote down vote up
@Override
protected MessageBufferPacker pack() throws IOException {
    MessageBufferPacker packer = super.pack();

    packer.packLong(option);

    if (payload != null) {
        packer.packString(this.payload);
    }

    return packer;
}
 
Example 13
Source File: UserCommand1Response.java    From maestro-java with Apache License 2.0 5 votes vote down vote up
@Override
protected MessageBufferPacker pack() throws IOException {
    MessageBufferPacker packer = super.pack();

    packer.packString(this.status);

    return packer;
}
 
Example 14
Source File: StatsResponse.java    From maestro-java with Apache License 2.0 5 votes vote down vote up
@Override
protected MessageBufferPacker pack() throws IOException {
    MessageBufferPacker packer = super.pack();

    packer.packLong(this.childCount);
    packer.packString(this.roleInfo);
    packer.packShort(this.statsType);
    packer.packString(this.timestamp);
    packer.packLong(this.count);
    packer.packDouble(this.rate);
    packer.packDouble(this.latency);

    return packer;
}
 
Example 15
Source File: StartWorker.java    From maestro-java with Apache License 2.0 5 votes vote down vote up
@Override
final protected MessageBufferPacker pack() throws IOException {
    MessageBufferPacker packer = super.pack();

    packer.packString(options.getWorkerName());

    return packer;
}
 
Example 16
Source File: AgentSourceRequest.java    From maestro-java with Apache License 2.0 5 votes vote down vote up
@Override
protected MessageBufferPacker pack() throws IOException {
    MessageBufferPacker packer = super.pack();

    packer.packString(this.sourceUrl);

    if (this.branch != null) {
        packer.packString(branch);
    }

    return packer;
}
 
Example 17
Source File: SetRequest.java    From maestro-java with Apache License 2.0 5 votes vote down vote up
@Override
protected MessageBufferPacker pack() throws IOException {
    MessageBufferPacker packer = super.pack();

    packer.packLong(option.getValue());
    packer.packString(this.value);

    return packer;
}
 
Example 18
Source File: MaestroData.java    From maestro-java with Apache License 2.0 5 votes vote down vote up
@Override
protected MessageBufferPacker pack() throws IOException {
    MessageBufferPacker packer = super.pack();

    packer.packString(this.id);
    packer.packString(peerInfo.groupInfo().memberName());
    packer.packString(peerInfo.groupInfo().groupName());
    packer.packInt(peerInfo.getRole().getCode());
    packer.packString(peerInfo.peerName());
    packer.packString(peerInfo.peerHost());

    return packer;
}
 
Example 19
Source File: DataDstMsgPack.java    From xresloader with MIT License 4 votes vote down vote up
@SuppressWarnings("unchecked")
private void writeData(MessageBufferPacker packer, Object data) throws IOException {
    // null
    if (null == data) {
        packer.packNil();
        return;
    }

    // 字符串&二进制
    if (data instanceof String) {
        packer.packString((String) data);
        return;
    }

    // 数字
    // 枚举值已被转为Java Long,会在这里执行
    if (data instanceof Integer) {
        packer.packInt((Integer) data);
        return;
    }
    if (data instanceof Long) {
        packer.packLong((long) data);
        return;
    }
    if (data instanceof Short) {
        packer.packLong((short) data);
        return;
    }
    if (data instanceof Float) {
        packer.packFloat((float) data);
        return;
    }
    if (data instanceof Double) {
        packer.packDouble((double) data);
        return;
    }
    if (data instanceof Byte) {
        packer.packByte((byte) data);
        return;
    }
    if (data instanceof java.math.BigInteger) {
        packer.packBigInteger((java.math.BigInteger) data);
        return;
    }

    // 布尔
    if (data instanceof Boolean) {
        packer.packBoolean((Boolean) data);
        return;
    }

    // 列表
    if (data instanceof List<?>) {
        packer.packArrayHeader(((List<?>) data).size());
        for (Object subobj : (List<?>) data) {
            writeData(packer, subobj);
        }
        return;
    }

    // Hashmap
    if (data instanceof Map<?, ?>) {
        Map<?, ?> mp = (Map<?, ?>) data;

        ArrayList<Map.Entry<?, ?>> sorted_array = new ArrayList<Map.Entry<?, ?>>();
        sorted_array.ensureCapacity(mp.size());
        sorted_array.addAll(mp.entrySet());
        sorted_array.sort((l, r) -> {
            if (l.getValue() instanceof Integer && r.getValue() instanceof Integer) {
                return ((Integer) l.getValue()).compareTo((Integer) r.getValue());
            }

            if (l.getKey() instanceof Integer && r.getKey() instanceof Integer) {
                return ((Integer) l.getKey()).compareTo((Integer) r.getKey());
            } else if (l.getKey() instanceof Long && r.getKey() instanceof Long) {
                return ((Long) l.getKey()).compareTo((Long) r.getKey());
            } else {
                return l.getKey().toString().compareTo(r.getKey().toString());
            }
        });

        packer.packMapHeader(sorted_array.size());
        for (Map.Entry<?, ?> item : sorted_array) {
            writeData(packer, item.getKey());
            writeData(packer, item.getValue());
        }

        return;
    }

    packer.packString(data.toString());
}
 
Example 20
Source File: SerializationUtils.java    From maestro-java with Apache License 2.0 4 votes vote down vote up
public static void pack(final MessageBufferPacker packer, final TestDetails testDetails) throws IOException {
    packer.packString(testDetails.getTestDescription());
    packer.packString(testDetails.getTestComments());
}