public class MessagePack extends Object
This is basic class to use MessagePack for Java. It creates serializers and deserializers for objects of classes.
See Quick Start for Java on MessagePack wiki.
Modifier | Constructor and Description |
---|---|
|
MessagePack() |
|
MessagePack(MessagePack msgpack) |
protected |
MessagePack(TemplateRegistry registry) |
Modifier and Type | Method and Description |
---|---|
<T> T |
convert(Value v,
Class<T> c)
Converts
Value object to object specified class. |
<T> T |
convert(Value v,
T to)
Converts specified
Value object to object. |
<T> T |
convert(Value v,
Template<T> tmpl)
Converts
Value object to object according to template |
BufferPacker |
createBufferPacker()
Returns serializer that enables serializing objects into buffer.
|
BufferPacker |
createBufferPacker(int bufferSize)
Returns serializer that enables serializing objects into buffer.
|
BufferUnpacker |
createBufferUnpacker()
Returns empty deserializer that enables deserializing buffer.
|
BufferUnpacker |
createBufferUnpacker(byte[] bytes)
Returns deserializer that enables deserializing buffer.
|
BufferUnpacker |
createBufferUnpacker(byte[] bytes,
int off,
int len)
Returns deserializer that enables deserializing buffer.
|
BufferUnpacker |
createBufferUnpacker(ByteBuffer buffer)
Returns deserializer that enables deserializing buffer.
|
Packer |
createPacker(OutputStream out)
Returns serializer that enables serializing objects into
OutputStream object. |
Unpacker |
createUnpacker(InputStream in)
Returns deserializer that enables deserializing
InputStream object. |
<T> Template<T> |
lookup(Class<T> type)
Looks up a
Template object, which is
serializer/deserializer associated by specified class. |
Template<?> |
lookup(Type type) |
static byte[] |
pack(Object v)
Deprecated.
|
static void |
pack(OutputStream out,
Object v)
Deprecated.
|
static <T> void |
pack(OutputStream out,
T v,
Template<T> template)
Deprecated.
|
static <T> byte[] |
pack(T v,
Template<T> template)
Deprecated.
|
Value |
read(byte[] bytes)
Deserializes specified byte array to
Value
object. |
<T> T |
read(byte[] bytes,
Class<T> c)
Deserializes byte array to object of specified class.
|
Value |
read(byte[] bytes,
int off,
int len)
Deserializes byte array to
Value object. |
<T> T |
read(byte[] bytes,
int off,
int len,
Class<T> c)
Deserializes byte array to object.
|
<T> T |
read(byte[] bytes,
T v)
Deserializes byte array to object.
|
<T> T |
read(byte[] bytes,
Template<T> tmpl)
Deserializes byte array to object according to template.
|
<T> T |
read(byte[] bytes,
T v,
Template<T> tmpl)
Deserializes byte array to object according to specified template.
|
Value |
read(ByteBuffer buffer)
Deserializes
ByteBuffer object to
Value object. |
<T> T |
read(ByteBuffer b,
Class<T> c)
Deserializes buffer to object of specified class.
|
<T> T |
read(ByteBuffer b,
T v)
Deserializes buffer to object.
|
<T> T |
read(ByteBuffer b,
Template<T> tmpl)
Deserializes buffer to object according to template.
|
<T> T |
read(ByteBuffer b,
T v,
Template<T> tmpl)
Deserializes buffer to object according to template.
|
Value |
read(InputStream in)
Deserializes input stream to
Value object. |
<T> T |
read(InputStream in,
Class<T> c)
Deserializes input stream to object of specified class.
|
<T> T |
read(InputStream in,
T v)
Deserializes input stream to object.
|
<T> T |
read(InputStream in,
Template<T> tmpl)
Deserializes input stream to object according to template.
|
<T> T |
read(InputStream in,
T v,
Template<T> tmpl)
Deserializes input stream to object according to template
|
void |
register(Class<?> type)
Registers
Template object for objects of
specified class. |
<T> void |
register(Class<T> type,
Template<T> template)
Registers specified
Template object
associated by class. |
void |
setClassLoader(ClassLoader cl) |
<T> Value |
unconvert(T v)
Unconverts specified object to
Value object. |
static Value |
unpack(byte[] bytes)
Deprecated.
|
static <T> T |
unpack(byte[] bytes,
Class<T> klass)
Deprecated.
|
static <T> T |
unpack(byte[] bytes,
T to)
Deprecated.
|
static <T> T |
unpack(byte[] bytes,
Template<T> template)
Deprecated.
|
static <T> T |
unpack(byte[] bytes,
Template<T> template,
T to)
Deprecated.
|
static Value |
unpack(InputStream in)
Deprecated.
|
static <T> T |
unpack(InputStream in,
Class<T> klass)
Deprecated.
|
static <T> T |
unpack(InputStream in,
T to)
Deprecated.
|
static <T> T |
unpack(InputStream in,
Template<T> tmpl)
Deprecated.
|
static <T> T |
unpack(InputStream in,
Template<T> tmpl,
T to)
Deprecated.
|
void |
unregister()
Unregisters all
Template objects that have
been registered in advance. |
boolean |
unregister(Class<?> type)
Unregisters
Template object for objects of
specified class. |
<T> void |
write(OutputStream out,
T v)
Serializes specified object to output stream.
|
<T> void |
write(OutputStream out,
T v,
Template<T> template)
Serializes object to output stream by specified template.
|
<T> byte[] |
write(T v)
Serializes specified object.
|
<T> byte[] |
write(T v,
Template<T> template)
Serializes specified object.
|
byte[] |
write(Value v)
Serializes
Value object to byte array. |
public MessagePack()
public MessagePack(MessagePack msgpack)
msgpack
- protected MessagePack(TemplateRegistry registry)
public void setClassLoader(ClassLoader cl)
cl
- public Packer createPacker(OutputStream out)
OutputStream
object.out
- output streampublic BufferPacker createBufferPacker()
public BufferPacker createBufferPacker(int bufferSize)
bufferSize
- initial size of bufferpublic Unpacker createUnpacker(InputStream in)
InputStream
object.in
- input streampublic BufferUnpacker createBufferUnpacker()
public BufferUnpacker createBufferUnpacker(byte[] bytes)
bytes
- input byte arraypublic BufferUnpacker createBufferUnpacker(byte[] bytes, int off, int len)
bytes
- off
- len
- public BufferUnpacker createBufferUnpacker(ByteBuffer buffer)
buffer
- input ByteBuffer
objectpublic <T> byte[] write(T v) throws IOException
v
- serialized objectIOException
public <T> byte[] write(T v, Template<T> template) throws IOException
v
- template
- IOException
public <T> void write(OutputStream out, T v) throws IOException
out
- output streamv
- serialized objectIOException
public <T> void write(OutputStream out, T v, Template<T> template) throws IOException
out
- output streamv
- serialized objecttemplate
- serializer/deserializer for the objectIOException
public byte[] write(Value v) throws IOException
Value
object to byte array.v
- serialized Value
objectIOException
public Value read(byte[] bytes) throws IOException
Value
object.bytes
- input byte arrayIOException
public Value read(byte[] bytes, int off, int len) throws IOException
Value
object.bytes
- off
- len
- IOException
public Value read(ByteBuffer buffer) throws IOException
ByteBuffer
object to
Value
object.buffer
- input bufferIOException
public Value read(InputStream in) throws IOException
Value
object.in
- input streamValue
objectIOException
public <T> T read(byte[] bytes, T v) throws IOException
bytes
- input byte arrayv
- IOException
public <T> T read(byte[] bytes, Template<T> tmpl) throws IOException
bytes
- input byte arraytmpl
- templateIOException
public <T> T read(byte[] bytes, Class<T> c) throws IOException
bytes
- input byte arrayc
- IOException
public <T> T read(byte[] bytes, T v, Template<T> tmpl) throws IOException
bytes
- input byte arrayv
- tmpl
- templateIOException
public <T> T read(byte[] bytes, int off, int len, Class<T> c) throws IOException
bytes
- input byte arrayv
- IOException
public <T> T read(ByteBuffer b, T v) throws IOException
b
- input ByteBuffer
objectv
- IOException
public <T> T read(ByteBuffer b, Template<T> tmpl) throws IOException
b
- input buffer objecttmpl
- IOException
public <T> T read(ByteBuffer b, Class<T> c) throws IOException
b
- c
- IOException
public <T> T read(ByteBuffer b, T v, Template<T> tmpl) throws IOException
b
- input buffer objectv
- tmpl
- IOException
public <T> T read(InputStream in, T v) throws IOException
in
- input streamv
- IOException
public <T> T read(InputStream in, Template<T> tmpl) throws IOException
in
- input streamtmpl
- IOException
public <T> T read(InputStream in, Class<T> c) throws IOException
in
- c
- IOException
public <T> T read(InputStream in, T v, Template<T> tmpl) throws IOException
in
- input streamv
- tmpl
- IOException
public <T> T convert(Value v, T to) throws IOException
Value
object to object.v
- to
- IOException
public <T> T convert(Value v, Class<T> c) throws IOException
Value
object to object specified class.v
- c
- IOException
public <T> T convert(Value v, Template<T> tmpl) throws IOException
Value
object to object according to templatev
- tmpl
- IOException
public <T> Value unconvert(T v) throws IOException
Value
object.v
- IOException
public void register(Class<?> type)
Template
object for objects of
specified class. Template object is a pair of serializer and
deserializer for object serialization. It is generated automatically.type
- public <T> void register(Class<T> type, Template<T> template)
Template
object
associated by class.type
- template
- register(Class)
public boolean unregister(Class<?> type)
Template
object for objects of
specified class.type
- public void unregister()
Template
objects that have
been registered in advance.public <T> Template<T> lookup(Class<T> type)
Template
object, which is
serializer/deserializer associated by specified class.type
- @Deprecated public static byte[] pack(Object v) throws IOException
write(Object)
v
- IOException
@Deprecated public static void pack(OutputStream out, Object v) throws IOException
write(OutputStream, Object)
out
- v
- IOException
@Deprecated public static <T> byte[] pack(T v, Template<T> template) throws IOException
write(Object, Template)
v
- template
- IOException
@Deprecated public static <T> void pack(OutputStream out, T v, Template<T> template) throws IOException
write(OutputStream, Object, Template)
out
- v
- template
- IOException
@Deprecated public static Value unpack(byte[] bytes) throws IOException
read(byte[])
Value
object.bytes
- IOException
@Deprecated public static <T> T unpack(byte[] bytes, Template<T> template) throws IOException
IOException
@Deprecated public static <T> T unpack(byte[] bytes, Template<T> template, T to) throws IOException
IOException
@Deprecated public static <T> T unpack(byte[] bytes, Class<T> klass) throws IOException
read(byte[], Class)
bytes
- klass
- IOException
@Deprecated public static <T> T unpack(byte[] bytes, T to) throws IOException
bytes
- to
- IOException
@Deprecated public static Value unpack(InputStream in) throws IOException
read(InputStream)
Value
object.in
- IOException
@Deprecated public static <T> T unpack(InputStream in, Template<T> tmpl) throws IOException, MessageTypeException
in
- tmpl
- IOException
MessageTypeException
@Deprecated public static <T> T unpack(InputStream in, Template<T> tmpl, T to) throws IOException, MessageTypeException
in
- tmpl
- to
- IOException
MessageTypeException
@Deprecated public static <T> T unpack(InputStream in, Class<T> klass) throws IOException
read(InputStream, Class)
in
- klass
- IOException
@Deprecated public static <T> T unpack(InputStream in, T to) throws IOException
read(InputStream, Object)
in
- to
- IOException
Copyright © 2015. All Rights Reserved.