Class MessagePack
- java.lang.Object
-
- org.msgpack.core.MessagePack
-
public class MessagePack extends java.lang.ObjectConvenience class to build packer and unpacker classes. You can select an appropriate factory method as following.Deserializing objects from binary:
Input type Factory method Return type byte[] newDefaultUnpacker(byte[], int, int)MessageUnpackerByteBuffer newDefaultUnpacker(ByteBuffer)MessageUnpackerInputStream newDefaultUnpacker(InputStream)MessageUnpackerReadableByteChannel newDefaultUnpacker(ReadableByteChannel)MessageUnpackerMessageBufferInputnewDefaultUnpacker(MessageBufferInput)MessageUnpackerSerializing objects into binary:
Output type Factory method Return type byte[] newDefaultBufferPacker()MessageBufferPackerOutputStream newDefaultPacker(OutputStream)MessagePackerWritableByteChannel newDefaultPacker(WritableByteChannel)MessagePackerMessageBufferOutputnewDefaultPacker(MessageBufferOutput)MessagePacker
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classMessagePack.CodeThe prefix code set of MessagePack format.static classMessagePack.PackerConfigMessagePacker configuration.static classMessagePack.UnpackerConfigMessageUnpacker configuration.
-
Field Summary
Fields Modifier and Type Field Description static MessagePack.PackerConfigDEFAULT_PACKER_CONFIGConfiguration of aMessagePackerused bynewDefaultPacker(MessageBufferOutput)andnewDefaultBufferPacker()methods.static MessagePack.UnpackerConfigDEFAULT_UNPACKER_CONFIGConfiguration of aMessageUnpackerused bynewDefaultUnpacker(MessageBufferInput)methods.static java.nio.charset.CharsetUTF8
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static MessageBufferPackernewDefaultBufferPacker()Creates a packer that serializes objects into byte arrays.static MessagePackernewDefaultPacker(java.io.OutputStream out)Creates a packer that serializes objects into the specified output stream.static MessagePackernewDefaultPacker(java.nio.channels.WritableByteChannel channel)Creates a packer that serializes objects into the specified writable channel.static MessagePackernewDefaultPacker(MessageBufferOutput out)Creates a packer that serializes objects into the specified output.static MessageUnpackernewDefaultUnpacker(byte[] contents)Creates an unpacker that deserializes objects from a specified byte array.static MessageUnpackernewDefaultUnpacker(byte[] contents, int offset, int length)Creates an unpacker that deserializes objects from subarray of a specified byte array.static MessageUnpackernewDefaultUnpacker(java.io.InputStream in)Creates an unpacker that deserializes objects from a specified input stream.static MessageUnpackernewDefaultUnpacker(java.nio.ByteBuffer contents)Creates an unpacker that deserializes objects from a specified ByteBuffer.static MessageUnpackernewDefaultUnpacker(java.nio.channels.ReadableByteChannel channel)Creates an unpacker that deserializes objects from a specified readable channel.static MessageUnpackernewDefaultUnpacker(MessageBufferInput in)Creates an unpacker that deserializes objects from a specified input.
-
-
-
Field Detail
-
UTF8
public static final java.nio.charset.Charset UTF8
-
DEFAULT_PACKER_CONFIG
public static final MessagePack.PackerConfig DEFAULT_PACKER_CONFIG
Configuration of aMessagePackerused bynewDefaultPacker(MessageBufferOutput)andnewDefaultBufferPacker()methods.
-
DEFAULT_UNPACKER_CONFIG
public static final MessagePack.UnpackerConfig DEFAULT_UNPACKER_CONFIG
Configuration of aMessageUnpackerused bynewDefaultUnpacker(MessageBufferInput)methods.
-
-
Method Detail
-
newDefaultPacker
public static MessagePacker newDefaultPacker(MessageBufferOutput out)
Creates a packer that serializes objects into the specified output.MessageBufferOutputis an interface that lets applications customize memory allocation of internal buffer ofMessagePacker. You may prefernewDefaultBufferPacker(),newDefaultPacker(OutputStream), ornewDefaultPacker(WritableByteChannel)methods instead.This method is equivalent to
DEFAULT_PACKER_CONFIG.newPacker(out).- Parameters:
out- A MessageBufferOutput that allocates buffer chunks and receives the buffer chunks with packed data filled in them- Returns:
- A new MessagePacker instance
-
newDefaultPacker
public static MessagePacker newDefaultPacker(java.io.OutputStream out)
Creates a packer that serializes objects into the specified output stream.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).- Parameters:
out- The output stream that receives sequence of bytes- Returns:
- A new MessagePacker instance
-
newDefaultPacker
public static MessagePacker newDefaultPacker(java.nio.channels.WritableByteChannel channel)
Creates a packer that serializes objects into the specified writable channel.This method is equivalent to
DEFAULT_PACKER_CONFIG.newPacker(channel).- Parameters:
channel- The output channel that receives sequence of bytes- Returns:
- A new MessagePacker instance
-
newDefaultBufferPacker
public static MessageBufferPacker newDefaultBufferPacker()
Creates a packer that serializes objects into byte arrays.This method provides an optimized implementation of
newDefaultBufferPacker(new ByteArrayOutputStream()). This method is equivalent toDEFAULT_PACKER_CONFIG.newBufferPacker().- Returns:
- A new MessageBufferPacker instance
-
newDefaultUnpacker
public static MessageUnpacker newDefaultUnpacker(MessageBufferInput in)
Creates an unpacker that deserializes objects from a specified input.MessageBufferInputis an interface that lets applications customize memory allocation of internal buffer ofMessageUnpacker. You may prefernewDefaultUnpacker(InputStream),newDefaultUnpacker(ReadableByteChannel),newDefaultUnpacker(byte[], int, int), ornewDefaultUnpacker(ByteBuffer)methods instead.This method is equivalent to
DEFAULT_UNPACKER_CONFIG.newDefaultUnpacker(in).- Parameters:
in- The input stream that provides sequence of buffer chunks and optionally reuses them when MessageUnpacker consumed one completely- Returns:
- A new MessageUnpacker instance
-
newDefaultUnpacker
public static MessageUnpacker newDefaultUnpacker(java.io.InputStream in)
Creates an unpacker that deserializes objects from a specified input stream.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).- Parameters:
in- The input stream that provides sequence of bytes- Returns:
- A new MessageUnpacker instance
-
newDefaultUnpacker
public static MessageUnpacker newDefaultUnpacker(java.nio.channels.ReadableByteChannel channel)
Creates an unpacker that deserializes objects from a specified readable channel.This method is equivalent to
DEFAULT_UNPACKER_CONFIG.newDefaultUnpacker(in).- Parameters:
channel- The input channel that provides sequence of bytes- Returns:
- A new MessageUnpacker instance
-
newDefaultUnpacker
public static MessageUnpacker newDefaultUnpacker(byte[] contents)
Creates an unpacker that deserializes objects from a specified byte array.This method provides an optimized implementation of
newDefaultUnpacker(new ByteArrayInputStream(contents)).This method is equivalent to
DEFAULT_UNPACKER_CONFIG.newDefaultUnpacker(contents).- Parameters:
contents- The byte array that contains packed objects in MessagePack format- Returns:
- A new MessageUnpacker instance that will never throw IOException
-
newDefaultUnpacker
public static MessageUnpacker newDefaultUnpacker(byte[] contents, int offset, int length)
Creates an unpacker that deserializes objects from subarray of a specified byte array.This method provides an optimized implementation of
newDefaultUnpacker(new ByteArrayInputStream(contents, offset, length)).This method is equivalent to
DEFAULT_UNPACKER_CONFIG.newDefaultUnpacker(contents).- Parameters:
contents- The byte array that contains packed objectsoffset- The index of the first bytelength- The number of bytes- Returns:
- A new MessageUnpacker instance that will never throw IOException
-
newDefaultUnpacker
public static MessageUnpacker newDefaultUnpacker(java.nio.ByteBuffer contents)
Creates an unpacker that deserializes objects from a specified ByteBuffer.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.
- Parameters:
contents- The byte buffer that contains packed objects- Returns:
- A new MessageUnpacker instance that will never throw IOException
-
-