org.msgpack
Class MessagePack

java.lang.Object
  extended by org.msgpack.MessagePack
Direct Known Subclasses:
JSON

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.


Constructor Summary
MessagePack()
           
MessagePack(MessagePack msgpack)
           
 
Method Summary
<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.
 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.
static byte[] pack(Object v)
          Deprecated. write(Object)
static void pack(OutputStream out, Object v)
          Deprecated. write(OutputStream, Object)
static
<T> void
pack(OutputStream out, T v, Template<T> template)
          Deprecated. write(OutputStream, Object, Template)
static
<T> byte[]
pack(T v, Template<T> template)
          Deprecated. write(Object, Template)
 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, 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. read(byte[], Class)
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. read(InputStream)
static
<T> T
unpack(InputStream in, Class<T> klass)
          Deprecated. read(InputStream, Class)
static
<T> T
unpack(InputStream in, T to)
          Deprecated. read(InputStream, Object)
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.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

MessagePack

public MessagePack()
Since:
0.6.0

MessagePack

public MessagePack(MessagePack msgpack)
Parameters:
msgpack -
Since:
0.6.0
Method Detail

setClassLoader

public void setClassLoader(ClassLoader cl)
Parameters:
cl -
Since:
0.6.0

createPacker

public Packer createPacker(OutputStream out)
Returns serializer that enables serializing objects into OutputStream object.

Parameters:
out - output stream
Returns:
stream-based serializer
Since:
0.6.0

createBufferPacker

public BufferPacker createBufferPacker()
Returns serializer that enables serializing objects into buffer.

Returns:
buffer-based serializer
Since:
0.6.0

createBufferPacker

public BufferPacker createBufferPacker(int bufferSize)
Returns serializer that enables serializing objects into buffer.

Parameters:
bufferSize - initial size of buffer
Returns:
buffer-based serializer
Since:
0.6.0

createUnpacker

public Unpacker createUnpacker(InputStream in)
Returns deserializer that enables deserializing InputStream object.

Parameters:
in - input stream
Returns:
stream-based deserializer
Since:
0.6.0

createBufferUnpacker

public BufferUnpacker createBufferUnpacker()
Returns empty deserializer that enables deserializing buffer.

Returns:
buffer-based deserializer
Since:
0.6.0

createBufferUnpacker

public BufferUnpacker createBufferUnpacker(byte[] bytes)
Returns deserializer that enables deserializing buffer.

Parameters:
bytes - input byte array
Returns:
buffer-based deserializer
Since:
0.6.0

createBufferUnpacker

public BufferUnpacker createBufferUnpacker(byte[] bytes,
                                           int off,
                                           int len)
Returns deserializer that enables deserializing buffer.

Parameters:
bytes -
off -
len -
Returns:
buffer-based deserializer
Since:
0.6.0

createBufferUnpacker

public BufferUnpacker createBufferUnpacker(ByteBuffer buffer)
Returns deserializer that enables deserializing buffer.

Parameters:
buffer - input ByteBuffer object
Returns:
buffer-based deserializer
Since:
0.6.0

write

public <T> byte[] write(T v)
             throws IOException
Serializes specified object.

Parameters:
v - serialized object
Returns:
output byte array
Throws:
IOException
Since:
0.6.0

write

public <T> byte[] write(T v,
                        Template<T> template)
             throws IOException
Serializes specified object. It allows serializing object by specified template.

Parameters:
v -
template -
Returns:
Throws:
IOException
Since:
0.6.0

write

public <T> void write(OutputStream out,
                      T v)
           throws IOException
Serializes specified object to output stream.

Parameters:
out - output stream
v - serialized object
Throws:
IOException
Since:
0.6.0

write

public <T> void write(OutputStream out,
                      T v,
                      Template<T> template)
           throws IOException
Serializes object to output stream by specified template.

Parameters:
out - output stream
v - serialized object
template - serializer/deserializer for the object
Throws:
IOException
Since:
0.6.0

write

public byte[] write(Value v)
             throws IOException
Serializes Value object to byte array.

Parameters:
v - serialized Value object
Returns:
output byte array
Throws:
IOException
Since:
0.6.0

read

public Value read(byte[] bytes)
           throws IOException
Deserializes specified byte array to Value object.

Parameters:
bytes - input byte array
Returns:
Throws:
IOException
Since:
0.6.0

read

public Value read(byte[] bytes,
                  int off,
                  int len)
           throws IOException
Deserializes byte array to Value object.

Parameters:
bytes -
off -
len -
Returns:
Throws:
IOException
Since:
0.6.0

read

public Value read(ByteBuffer buffer)
           throws IOException
Deserializes ByteBuffer object to Value object.

Parameters:
buffer - input buffer
Returns:
Throws:
IOException
Since:
0.6.0

read

public Value read(InputStream in)
           throws IOException
Deserializes input stream to Value object.

Parameters:
in - input stream
Returns:
deserialized Value object
Throws:
IOException
Since:
0.6.0

read

public <T> T read(byte[] bytes,
                  T v)
       throws IOException
Deserializes byte array to object.

Parameters:
bytes - input byte array
v -
Returns:
Throws:
IOException
Since:
0.6.0

read

public <T> T read(byte[] bytes,
                  Template<T> tmpl)
       throws IOException
Deserializes byte array to object according to template.

Parameters:
bytes - input byte array
tmpl - template
Returns:
Throws:
IOException
Since:
0.6.0

read

public <T> T read(byte[] bytes,
                  Class<T> c)
       throws IOException
Deserializes byte array to object of specified class.

Parameters:
bytes - input byte array
c -
Returns:
Throws:
IOException
Since:
0.6.0

read

public <T> T read(byte[] bytes,
                  T v,
                  Template<T> tmpl)
       throws IOException
Deserializes byte array to object according to specified template.

Parameters:
bytes - input byte array
v -
tmpl - template
Returns:
Throws:
IOException
Since:
0.6.0

read

public <T> T read(ByteBuffer b,
                  T v)
       throws IOException
Deserializes buffer to object.

Parameters:
b - input ByteBuffer object
v -
Returns:
Throws:
IOException
Since:
0.6.0

read

public <T> T read(ByteBuffer b,
                  Template<T> tmpl)
       throws IOException
Deserializes buffer to object according to template.

Parameters:
b - input buffer object
tmpl -
Returns:
Throws:
IOException
Since:
0.6.0

read

public <T> T read(ByteBuffer b,
                  Class<T> c)
       throws IOException
Deserializes buffer to object of specified class.

Parameters:
b -
c -
Returns:
Throws:
IOException
Since:
0.6.0

read

public <T> T read(ByteBuffer b,
                  T v,
                  Template<T> tmpl)
       throws IOException
Deserializes buffer to object according to template.

Parameters:
b - input buffer object
v -
tmpl -
Returns:
Throws:
IOException
Since:
0.6.0

read

public <T> T read(InputStream in,
                  T v)
       throws IOException
Deserializes input stream to object.

Parameters:
in - input stream
v -
Returns:
Throws:
IOException
Since:
0.6.0

read

public <T> T read(InputStream in,
                  Template<T> tmpl)
       throws IOException
Deserializes input stream to object according to template.

Parameters:
in - input stream
tmpl -
Returns:
Throws:
IOException
Since:
0.6.0

read

public <T> T read(InputStream in,
                  Class<T> c)
       throws IOException
Deserializes input stream to object of specified class.

Parameters:
in -
c -
Returns:
Throws:
IOException
Since:
0.6.0

read

public <T> T read(InputStream in,
                  T v,
                  Template<T> tmpl)
       throws IOException
Deserializes input stream to object according to template

Parameters:
in - input stream
v -
tmpl -
Returns:
Throws:
IOException
Since:
0.6.0

convert

public <T> T convert(Value v,
                     T to)
          throws IOException
Converts specified Value object to object.

Parameters:
v -
to -
Returns:
Throws:
IOException
Since:
0.6.0

convert

public <T> T convert(Value v,
                     Class<T> c)
          throws IOException
Converts Value object to object specified class.

Parameters:
v -
c -
Returns:
Throws:
IOException
Since:
0.6.0

unconvert

public <T> Value unconvert(T v)
                throws IOException
Unconverts specified object to Value object.

Parameters:
v -
Returns:
Throws:
IOException
Since:
0.6.0

register

public void register(Class<?> type)
Registers Template object for objects of specified class. Template object is a pair of serializer and deserializer for object serialization. It is generated automatically.

Parameters:
type -
Since:
0.6.0

register

public <T> void register(Class<T> type,
                         Template<T> template)
Registers specified Template object associated by class.

Parameters:
type -
template -
Since:
0.6.0
See Also:
register(Class)

unregister

public boolean unregister(Class<?> type)
Unregisters Template object for objects of specified class.

Parameters:
type -
Returns:
Since:
0.6.0

unregister

public void unregister()
Unregisters all Template objects that have been registered in advance.

Since:
0.6.0

lookup

public <T> Template<T> lookup(Class<T> type)
Looks up a Template object, which is serializer/deserializer associated by specified class.

Parameters:
type -
Returns:
Since:
0.6.0

pack

@Deprecated
public static byte[] pack(Object v)
                   throws IOException
Deprecated. write(Object)

Serializes specified object and returns the byte array.

Parameters:
v -
Returns:
Throws:
IOException

pack

@Deprecated
public static void pack(OutputStream out,
                                   Object v)
                 throws IOException
Deprecated. write(OutputStream, Object)

Serializes specified object to output stream.

Parameters:
out -
v -
Throws:
IOException

pack

@Deprecated
public static <T> byte[] pack(T v,
                                         Template<T> template)
                   throws IOException
Deprecated. write(Object, Template)

Serializes object by specified template and return the byte array.

Parameters:
v -
template -
Returns:
Throws:
IOException

pack

@Deprecated
public static <T> void pack(OutputStream out,
                                       T v,
                                       Template<T> template)
                 throws IOException
Deprecated. write(OutputStream, Object, Template)

Serializes object to output stream. The object is serialized by specified template.

Parameters:
out -
v -
template -
Throws:
IOException

unpack

@Deprecated
public static Value unpack(byte[] bytes)
                    throws IOException
Deprecated. 

Converts byte array to object.

Parameters:
bytes -
Returns:
Throws:
IOException

unpack

@Deprecated
public static <T> T unpack(byte[] bytes,
                                      Template<T> template)
                throws IOException
Deprecated. 

Throws:
IOException

unpack

@Deprecated
public static <T> T unpack(byte[] bytes,
                                      Template<T> template,
                                      T to)
                throws IOException
Deprecated. 

Throws:
IOException

unpack

@Deprecated
public static <T> T unpack(byte[] bytes,
                                      Class<T> klass)
                throws IOException
Deprecated. read(byte[], Class)

Deserializes byte array to object of specified class.

Parameters:
bytes -
klass -
Returns:
Throws:
IOException

unpack

@Deprecated
public static <T> T unpack(byte[] bytes,
                                      T to)
                throws IOException
Deprecated. 

Deserializes byte array to object.

Parameters:
bytes -
to -
Returns:
Throws:
IOException

unpack

@Deprecated
public static Value unpack(InputStream in)
                    throws IOException
Deprecated. read(InputStream)

Converts input stream to Value object.

Parameters:
in -
Returns:
Throws:
IOException

unpack

@Deprecated
public static <T> T unpack(InputStream in,
                                      Template<T> tmpl)
                throws IOException,
                       MessageTypeException
Deprecated. 

Parameters:
in -
tmpl -
Returns:
Throws:
IOException
MessageTypeException

unpack

@Deprecated
public static <T> T unpack(InputStream in,
                                      Template<T> tmpl,
                                      T to)
                throws IOException,
                       MessageTypeException
Deprecated. 

Parameters:
in -
tmpl -
to -
Returns:
Throws:
IOException
MessageTypeException

unpack

@Deprecated
public static <T> T unpack(InputStream in,
                                      Class<T> klass)
                throws IOException
Deprecated. read(InputStream, Class)

Deserializes input stream to object of specified class.

Parameters:
in -
klass -
Returns:
Throws:
IOException

unpack

@Deprecated
public static <T> T unpack(InputStream in,
                                      T to)
                throws IOException
Deprecated. read(InputStream, Object)

Deserializes input stream to object.

Parameters:
in -
to -
Returns:
Throws:
IOException


Copyright © 2011. All Rights Reserved.