public class MessagePack
extends java.lang.Object
Deserializing objects from binary:
Input type | Factory method | Return type |
---|---|---|
byte[] | newDefaultUnpacker(byte[], int, int) | MessageUnpacker |
ByteBuffer | newDefaultUnpacker(ByteBuffer) | MessageUnpacker |
InputStream | newDefaultUnpacker(InputStream) | MessageUnpacker |
ReadableByteChannel | newDefaultUnpacker(ReadableByteChannel) | MessageUnpacker |
MessageBufferInput | newDefaultUnpacker(MessageBufferInput) | MessageUnpacker |
Serializing objects into binary:
Output type | Factory method | Return type |
---|---|---|
byte[] | newDefaultBufferPacker() | MessageBufferPacker |
OutputStream | newDefaultPacker(OutputStream) | MessagePacker |
WritableByteChannel | newDefaultPacker(WritableByteChannel) | MessagePacker |
MessageBufferOutput | newDefaultPacker(MessageBufferOutput) | MessagePacker |
Modifier and Type | Class and Description |
---|---|
static class |
MessagePack.Code
The prefix code set of MessagePack format.
|
static class |
MessagePack.PackerConfig
MessagePacker configuration.
|
static class |
MessagePack.UnpackerConfig
MessageUnpacker configuration.
|
Modifier and Type | Field and Description |
---|---|
static MessagePack.PackerConfig |
DEFAULT_PACKER_CONFIG
Configuration of a
MessagePacker used by newDefaultPacker(MessageBufferOutput) and newDefaultBufferPacker() methods. |
static MessagePack.UnpackerConfig |
DEFAULT_UNPACKER_CONFIG
Configuration of a
MessageUnpacker used by newDefaultUnpacker(MessageBufferInput) methods. |
static java.nio.charset.Charset |
UTF8 |
Modifier and Type | Method and Description |
---|---|
static MessageBufferPacker |
newDefaultBufferPacker()
Creates a packer that serializes objects into byte arrays.
|
static MessagePacker |
newDefaultPacker(MessageBufferOutput out)
Creates a packer that serializes objects into the specified output.
|
static MessagePacker |
newDefaultPacker(java.io.OutputStream out)
Creates a packer that serializes objects into the specified output stream.
|
static MessagePacker |
newDefaultPacker(java.nio.channels.WritableByteChannel channel)
Creates a packer that serializes objects into the specified writable channel.
|
static MessageUnpacker |
newDefaultUnpacker(byte[] contents)
Creates an unpacker that deserializes objects from a specified byte array.
|
static MessageUnpacker |
newDefaultUnpacker(byte[] contents,
int offset,
int length)
Creates an unpacker that deserializes objects from subarray of a specified byte array.
|
static MessageUnpacker |
newDefaultUnpacker(java.nio.ByteBuffer contents)
Creates an unpacker that deserializes objects from a specified ByteBuffer.
|
static MessageUnpacker |
newDefaultUnpacker(java.io.InputStream in)
Creates an unpacker that deserializes objects from a specified input stream.
|
static MessageUnpacker |
newDefaultUnpacker(MessageBufferInput in)
Creates an unpacker that deserializes objects from a specified input.
|
static MessageUnpacker |
newDefaultUnpacker(java.nio.channels.ReadableByteChannel channel)
Creates an unpacker that deserializes objects from a specified readable channel.
|
public static final java.nio.charset.Charset UTF8
public static final MessagePack.PackerConfig DEFAULT_PACKER_CONFIG
MessagePacker
used by newDefaultPacker(MessageBufferOutput)
and newDefaultBufferPacker()
methods.public static final MessagePack.UnpackerConfig DEFAULT_UNPACKER_CONFIG
MessageUnpacker
used by newDefaultUnpacker(MessageBufferInput)
methods.public static MessagePacker newDefaultPacker(MessageBufferOutput out)
MessageBufferOutput
is an interface that lets applications customize memory
allocation of internal buffer of MessagePacker
. You may prefer newDefaultBufferPacker()
,
newDefaultPacker(OutputStream)
, or newDefaultPacker(WritableByteChannel)
methods instead.
This method is equivalent to DEFAULT_PACKER_CONFIG.newPacker(out)
.
out
- A MessageBufferOutput that allocates buffer chunks and receives the buffer chunks with packed data filled in thempublic static MessagePacker newDefaultPacker(java.io.OutputStream out)
Note that you don't have to wrap OutputStream in BufferedOutputStream because MessagePacker has buffering internally.
This method is equivalent to DEFAULT_PACKER_CONFIG.newPacker(out)
.
out
- The output stream that receives sequence of bytespublic static MessagePacker newDefaultPacker(java.nio.channels.WritableByteChannel channel)
This method is equivalent to DEFAULT_PACKER_CONFIG.newPacker(channel)
.
channel
- The output channel that receives sequence of bytespublic static MessageBufferPacker newDefaultBufferPacker()
This method provides an optimized implementation of newDefaultBufferPacker(new ByteArrayOutputStream())
.
This method is equivalent to DEFAULT_PACKER_CONFIG.newBufferPacker()
.
public static MessageUnpacker newDefaultUnpacker(MessageBufferInput in)
MessageBufferInput
is an interface that lets applications customize memory
allocation of internal buffer of MessageUnpacker
. You may prefer
newDefaultUnpacker(InputStream)
, newDefaultUnpacker(ReadableByteChannel)
,
newDefaultUnpacker(byte[], int, int)
, or newDefaultUnpacker(ByteBuffer)
methods instead.
This method is equivalent to DEFAULT_UNPACKER_CONFIG.newDefaultUnpacker(in)
.
in
- The input stream that provides sequence of buffer chunks and optionally reuses them when MessageUnpacker consumed one completelypublic static MessageUnpacker newDefaultUnpacker(java.io.InputStream in)
Note that you don't have to wrap InputStream in BufferedInputStream because MessageUnpacker has buffering internally.
This method is equivalent to DEFAULT_UNPACKER_CONFIG.newDefaultUnpacker(in)
.
in
- The input stream that provides sequence of bytespublic static MessageUnpacker newDefaultUnpacker(java.nio.channels.ReadableByteChannel channel)
This method is equivalent to DEFAULT_UNPACKER_CONFIG.newDefaultUnpacker(in)
.
channel
- The input channel that provides sequence of bytespublic static MessageUnpacker newDefaultUnpacker(byte[] contents)
This method provides an optimized implementation of newDefaultUnpacker(new ByteArrayInputStream(contents))
.
This method is equivalent to DEFAULT_UNPACKER_CONFIG.newDefaultUnpacker(contents)
.
contents
- The byte array that contains packed objects in MessagePack formatpublic static MessageUnpacker newDefaultUnpacker(byte[] contents, int offset, int length)
This method provides an optimized implementation of newDefaultUnpacker(new ByteArrayInputStream(contents, offset, length))
.
This method is equivalent to DEFAULT_UNPACKER_CONFIG.newDefaultUnpacker(contents)
.
contents
- The byte array that contains packed objectsoffset
- The index of the first bytelength
- The number of bytespublic static MessageUnpacker newDefaultUnpacker(java.nio.ByteBuffer contents)
Note that the returned unpacker reads data from the current position of the ByteBuffer until its limit.
However, its position does not change when unpacker reads data. You may use
MessageUnpacker.getTotalReadBytes()
to get actual amount of bytes used in ByteBuffer.
This method supports both non-direct buffer and direct buffer.
contents
- The byte buffer that contains packed objects