org.msgpack.core.MessageBufferPacker Java Examples

The following examples show how to use org.msgpack.core.MessageBufferPacker. 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: LogResponse.java    From maestro-java with Apache License 2.0 6 votes vote down vote up
private void packData(final MessageBufferPacker packer, final InputStream inputStream) throws IOException {
    logger.debug("Skipping {} bytes", pos);

    int chunkSize = getChunkSize(LOG_RESPONSE_MAX_PAYLOAD_SIZE);
    byte[] data = new byte[chunkSize];
    final int read = inputStream.read(data, 0, chunkSize);
    if (read == -1) {
        logger.error("End of buffer has been reached");

        // TODO: check if needs to throw an exception
    }

    packer.packBinaryHeader(chunkSize);
    packer.writePayload(data, 0, chunkSize);

    pos = pos + chunkSize;

    if (!hasNext()) {
        logger.trace("Completed sending the file chunks. Closing the input stream");
        inputStream.close();
    }
}
 
Example #2
Source File: DataDstMsgPack.java    From xresloader with MIT License 6 votes vote down vote up
@Override
public final byte[] build(DataDstImpl compiler) throws ConvException {
    MessageBufferPacker packer = MessagePack.newDefaultBufferPacker();

    DataDstJava.DataDstObject data_obj = build_data(compiler);

    try {
        packer.packMapHeader(3);
        packer.packString("header");
        writeData(packer, data_obj.header);
        packer.packString("data_block");
        writeData(packer, data_obj.body);
        packer.packString("data_message_type");
        writeData(packer, data_obj.data_message_type);
    } catch (IOException e) {
        this.logErrorMessage("MessagePacker write failed.");
        e.printStackTrace();
    }

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

    try {
        packer.packInt(locationType.getCode());
        SerializationUtils.pack(packer, this.locationTypeInfo);
        packer.packString(fileName);
        packer.packInt(index);
        packer.packInt(total);

        packer.packLong(fileSize);
        packer.packString(fileHash);

        packData(packer);
    } catch (Exception e) {
        packer.close();

        throw e;
    }

    return packer;
}
 
Example #4
Source File: Serializer.java    From tinkergraph-gremlin with Apache License 2.0 6 votes vote down vote up
public byte[] serialize(A a) throws IOException {
  long start = System.currentTimeMillis();
  try (MessageBufferPacker packer = MessagePack.newDefaultBufferPacker()) {
    packer.packLong(getId(a));
    packer.packString(getLabel(a));

    packEdgeIds(packer, getEdgeIds(a, Direction.IN));
    packEdgeIds(packer, getEdgeIds(a, Direction.OUT));
    packProperties(packer, getProperties(a));

    serializedCount++;
    serializationTimeSpentMillis += System.currentTimeMillis() - start;
    if (serializedCount % 100000 == 0) {
      float avgSerializationTime = serializationTimeSpentMillis / (float) serializedCount;
      logger.debug("stats: serialized " + serializedCount + " instances in total (avg time: " + avgSerializationTime + "ms)");
    }
    return packer.toByteArray();
  }
}
 
Example #5
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 #6
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 #7
Source File: PingRequest.java    From maestro-java with Apache License 2.0 5 votes vote down vote up
protected MessageBufferPacker pack() throws IOException {
    MessageBufferPacker packer = super.pack();

    packer.packLong(sec);
    packer.packLong(usec);

    return packer;
}
 
Example #8
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 #9
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 #10
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 TestExecutionInfo testExecutionInfo) throws IOException {
    pack(packer, testExecutionInfo.getTest());

    packer.packBoolean(testExecutionInfo.hasSutDetails());
    if (testExecutionInfo.hasSutDetails()) {
        pack(packer, testExecutionInfo.getSutDetails());
    }
}
 
Example #11
Source File: PingResponse.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.elapsed);

    return packer;
}
 
Example #12
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 #13
Source File: GroupJoinRequest.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(groupInfo.memberName());
    packer.packString(groupInfo.groupName());

    return packer;
}
 
Example #14
Source File: StartInspector.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.payload);

    return packer;
}
 
Example #15
Source File: DataDstMsgPack.java    From xresloader with MIT License 5 votes vote down vote up
/**
 * 转储常量数据
 * 
 * @return 常量数据,不支持的时候返回空
 */
public final byte[] dumpConst(HashMap<String, Object> data) throws ConvException, IOException {
    MessageBufferPacker packer = MessagePack.newDefaultBufferPacker();

    try {
        writeData(packer, data);
    } catch (IOException e) {
        this.logErrorMessage("MessagePacker write failed.");
        e.printStackTrace();
    }

    return packer.toByteArray();
}
 
Example #16
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 #17
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 #18
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 #19
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 #20
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 #21
Source File: Serializer.java    From tinkergraph-gremlin with Apache License 2.0 5 votes vote down vote up
/**
 * format: two `Map<Label, Array<EdgeId>>`, i.e. one Map for `IN` and one for `OUT` edges
 */
private void packEdgeIds(final MessageBufferPacker packer,
                         final Map<String, TLongSet> edgeIdsByLabel) throws IOException {
  packer.packMapHeader(edgeIdsByLabel.size());
  for (Map.Entry<String, TLongSet> entry : edgeIdsByLabel.entrySet()) {
    final String label = entry.getKey();
    packer.packString(label);
    final TLongSet edgeIds = entry.getValue();
    packer.packArrayHeader(edgeIds.size());
    final TLongIterator edgeIdIter = edgeIds.iterator();
    while (edgeIdIter.hasNext()) {
      packer.packLong(edgeIdIter.next());
    }
  }
}
 
Example #22
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 #23
Source File: DrainRequest.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.duration);
    packer.packString(this.url);
    packer.packString(this.parallelCount);
    packer.packString(this.workerName);

    return packer;
}
 
Example #24
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 #25
Source File: GetRequest.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());

    return packer;
}
 
Example #26
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 #27
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 #28
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 #29
Source File: InternalError.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.packInt(errorCode.getCode());
    packer.packString(message);

    return packer;
}
 
Example #30
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;
}