Alternate msppack implementation for Java.
This implementation complements the standard msgpack library for Java:
- (Much) Simpler API
- No external dependencies
- No builtin support for native object serialization, annotations, or RPC.
- It's very minimalistic - at the time of this writing, the entire redistributable
library is only ~11kb ... with full library sources for reference.
List<Object> objects = Arrays.asList("potatoes", false, 11, null);
byte data = MsgPack.pack(objects);
Object unpacked = MsgPack.unpack(data);
System.out.println("Unpacked data: " + unpacked);
See Test.java for more examples.
You can also pack/unpack to/from Data(Output/Input)Streams.
You can also specify unpacking options:
Object unpacked = MsgPack.unpack(data, UNPACK_RAW_AS_STRING);
to unpack things as something other than a raw byte.
This implementation uses the builtin Java types:
- Number (byte, short, int, and long are considered interchangeable when packing/unpacking, other considerations)
- String (UTF-8), byte, or ByteBuffer (the *whole* buffer) (always unpacked as a ByteBuffer)
- Map (any type may be used for packing, always unpacked as a HashMap)
- List (any type may be used for packing, always unpacked as an ArrayList)
Passing any other type to MsgPack.pack() will throw an IllegalArumentException.
Note that the implementation does no recursion checks - If you pass a cyclic object
it will hang in an infinite loop.