public class MessagePacker
extends java.lang.Object
implements java.io.Closeable
MessagePacker provides packXXX methods for writing values in the message pack format. To write raw string or binary data, first use packRawStringHeader or packBinaryHeader to specify the data length, then call writePayload(...) method.
MessagePacker class has no guarantee to produce the correct message-pack format data if it is not used correctly: packXXX methods of primitive values always produce the correct format, but packXXXHeader (e.g. array, map, ext) must be followed by correct number of array/map/ext type values. packRawStringHeader(length) and packBinaryHeader(length) must be followed by writePayload( ... length) to supply the binary data of the specified length in the header.
Constructor and Description |
---|
MessagePacker(MessageBufferOutput out)
Create an MessagePacker that outputs the packed data to the given
MessageBufferOutput |
MessagePacker(MessageBufferOutput out,
MessagePack.Config config) |
public MessagePacker(MessageBufferOutput out)
MessageBufferOutput
out
- MessageBufferOutput. Use OutputStreamBufferOutput
, ChannelBufferOutput
or
your own implementation of MessageBufferOutput
interface.public MessagePacker(MessageBufferOutput out, MessagePack.Config config)
public MessageBufferOutput reset(MessageBufferOutput out) throws java.io.IOException
out
- new outputjava.io.IOException
public long getTotalWrittenBytes()
public void flush() throws java.io.IOException
java.io.IOException
public void close() throws java.io.IOException
close
in interface java.io.Closeable
close
in interface java.lang.AutoCloseable
java.io.IOException
public MessagePacker packNil() throws java.io.IOException
java.io.IOException
public MessagePacker packBoolean(boolean b) throws java.io.IOException
java.io.IOException
public MessagePacker packByte(byte b) throws java.io.IOException
java.io.IOException
public MessagePacker packShort(short v) throws java.io.IOException
java.io.IOException
public MessagePacker packInt(int r) throws java.io.IOException
java.io.IOException
public MessagePacker packLong(long v) throws java.io.IOException
java.io.IOException
public MessagePacker packBigInteger(java.math.BigInteger bi) throws java.io.IOException
java.io.IOException
public MessagePacker packFloat(float v) throws java.io.IOException
java.io.IOException
public MessagePacker packDouble(double v) throws java.io.IOException
java.io.IOException
public MessagePacker packString(java.lang.String s) throws java.io.IOException
s
- java.io.IOException
public MessagePacker packArrayHeader(int arraySize) throws java.io.IOException
java.io.IOException
public MessagePacker packMapHeader(int mapSize) throws java.io.IOException
java.io.IOException
public MessagePacker packValue(Value v) throws java.io.IOException
java.io.IOException
public MessagePacker packExtensionTypeHeader(byte extType, int payloadLen) throws java.io.IOException
java.io.IOException
public MessagePacker packBinaryHeader(int len) throws java.io.IOException
java.io.IOException
public MessagePacker packRawStringHeader(int len) throws java.io.IOException
java.io.IOException
public MessagePacker writePayload(java.nio.ByteBuffer src) throws java.io.IOException
java.io.IOException
public MessagePacker writePayload(byte[] src) throws java.io.IOException
java.io.IOException
public MessagePacker writePayload(byte[] src, int off, int len) throws java.io.IOException
java.io.IOException