public class MessagePacker
extends java.lang.Object
implements java.io.Closeable, java.io.Flushable
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.
| Modifier and Type | Field and Description |
|---|---|
protected MessageBufferOutput |
out |
| Modifier | Constructor and Description |
|---|---|
protected |
MessagePacker(MessageBufferOutput out,
MessagePack.PackerConfig config)
Create an MessagePacker that outputs the packed data to the given
MessageBufferOutput. |
protected MessageBufferOutput out
protected MessagePacker(MessageBufferOutput out, MessagePack.PackerConfig config)
MessageBufferOutput.
This method is available for subclasses to override. Use MessagePack.PackerConfig.newPacker method to instanciate this implementation.out - MessageBufferOutput. Use OutputStreamBufferOutput, ChannelBufferOutput or
your own implementation of MessageBufferOutput interface.public MessageBufferOutput reset(MessageBufferOutput out) throws java.io.IOException
out - new outputjava.io.IOExceptionpublic long getTotalWrittenBytes()
public void flush()
throws java.io.IOException
flush in interface java.io.Flushablejava.io.IOExceptionpublic void close()
throws java.io.IOException
close in interface java.io.Closeableclose in interface java.lang.AutoCloseablejava.io.IOExceptionpublic MessagePacker packNil() throws java.io.IOException
java.io.IOExceptionpublic MessagePacker packBoolean(boolean b) throws java.io.IOException
java.io.IOExceptionpublic MessagePacker packByte(byte b) throws java.io.IOException
java.io.IOExceptionpublic MessagePacker packShort(short v) throws java.io.IOException
java.io.IOExceptionpublic MessagePacker packInt(int r) throws java.io.IOException
java.io.IOExceptionpublic MessagePacker packLong(long v) throws java.io.IOException
java.io.IOExceptionpublic MessagePacker packBigInteger(java.math.BigInteger bi) throws java.io.IOException
java.io.IOExceptionpublic MessagePacker packFloat(float v) throws java.io.IOException
java.io.IOExceptionpublic MessagePacker packDouble(double v) throws java.io.IOException
java.io.IOExceptionpublic MessagePacker packString(java.lang.String s) throws java.io.IOException
s - java.io.IOExceptionpublic MessagePacker packArrayHeader(int arraySize) throws java.io.IOException
java.io.IOExceptionpublic MessagePacker packMapHeader(int mapSize) throws java.io.IOException
java.io.IOExceptionpublic MessagePacker packValue(Value v) throws java.io.IOException
java.io.IOExceptionpublic MessagePacker packExtensionTypeHeader(byte extType, int payloadLen) throws java.io.IOException
java.io.IOExceptionpublic MessagePacker packBinaryHeader(int len) throws java.io.IOException
java.io.IOExceptionpublic MessagePacker packRawStringHeader(int len) throws java.io.IOException
java.io.IOExceptionpublic MessagePacker writePayload(byte[] src) throws java.io.IOException
src - the data to addjava.io.IOExceptionpublic MessagePacker writePayload(byte[] src, int off, int len) throws java.io.IOException
src - the data to addoff - the start offset in the datalen - the number of bytes to addjava.io.IOExceptionpublic MessagePacker addPayload(byte[] src) throws java.io.IOException
src - the data to addjava.io.IOExceptionpublic MessagePacker addPayload(byte[] src, int off, int len) throws java.io.IOException
src - the data to addoff - the start offset in the datalen - the number of bytes to addjava.io.IOException