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

The following examples show how to use org.msgpack.core.MessageBufferPacker#toByteArray() . 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: 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 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: 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 4
Source File: AbstractMaestroNote.java    From maestro-java with Apache License 2.0 3 votes vote down vote up
final public byte[] serialize() throws IOException {
    MessageBufferPacker packer = pack();

    packer.close();

    return packer.toByteArray();
}