Simple MsgPack is a simple Java library for handling MessagePack data. It doesn’t do any object mapping, but maps to special objects representing MessagePack types. For most cases you might be better off using the official library org.msgpack:msgpack. https://dissem.ch/msgpack/
Go to file
2017-11-21 07:31:10 +01:00
buildSrc/src/main Migrated to Kotlin 2017-09-21 16:25:03 +02:00
gradle/wrapper fixed build. I'm embarassed that I didn't notice the empty JAR file. 2017-11-21 07:30:14 +01:00
src Migrated to Kotlin 2017-09-21 16:25:03 +02:00
.gitignore initial commit 2017-01-18 17:34:20 +01:00
.travis.yml Updated README.md and Travis config file 2017-01-27 08:40:52 +01:00
build.gradle fixed build. I'm embarassed that I didn't notice the empty JAR file. 2017-11-21 07:30:14 +01:00
CHANGELOG.md Added changelog 2017-09-21 16:28:41 +02:00
gradle.properties Add default gradle settings 2017-01-27 13:32:16 +01:00
gradlew fixed build. I'm embarassed that I didn't notice the empty JAR file. 2017-11-21 07:30:14 +01:00
gradlew.bat initial commit 2017-01-18 17:34:20 +01:00
LICENSE Added license (Apache 2.0) 2017-01-23 17:38:02 +01:00
README.md Migrated to Kotlin 2017-09-21 16:25:03 +02:00
settings.gradle initial commit 2017-01-18 17:34:20 +01:00

Simple MessagePack

Maven Central Javadoc Apache 2

This is a simple Kotlin/Java library for handling MessagePack data. It doesn't do any object mapping, but maps to special objects representing MessagePack types. To build, use command ./gradlew build.

For most cases you might be better off using org.msgpack:msgpack, but I found that I needed something that generically represents the internal structure of the data.

Simple MessagePack uses Semantic Versioning, meaning as long as the major version doesn't change, nothing should break if you update. Be aware though that this doesn't necessarily applies for SNAPSHOT builds and the development branch.

Master

Build Status Code Quality Test Coverage

Develop

Build Status Code Quality Test Coverage

Limitations

  • There is no fallback to BigInteger for large integer type numbers, so there might be an integer overflow when reading too large numbers
  • MPFloat uses the data type you're using to decide on precision (float 32 or 64) - not the actual value. E.g. 0.5 could be saved perfectly as a float 42, but if you provide a double value, it will be stored as float 64, wasting 4 bytes.
  • If you want to use the 'ext format family', you'll need to implement and register your own MPType and MPType.Unpacker.
  • Be aware that custom MPType.Unpacker take precedence over the default unpackers, i.e. if you accidentally define your unpacker to handle strings, for example, you won't be able to unpack any regular strings anymore.

Setup

Add msgpack as Gradle dependency:

compile "ch.dissem.msgpack:msgpack:1.0.0"

Usage

Serialize Data

First, you'll need to create some msgpack objects to serialize:

MPMap<MPString, MPType<?>> object = new MPMap<>();
object.put(new MPString("compact"), new MPBoolean(true));
object.put(new MPString("schema"), new MPInteger(0));

or the shorthand version for simple types:

import static ch.dissem.msgpack.types.Utils.mp;

MPMap<MPString, MPType<?>> object = new MPMap<>();
object.put(mp("compact"), mp(true));
object.put(mp("schema"), mp(0));

then just use pack(OutputStream):

OutputStream out = ...;
object.pack(out);

Deserialize Data

For deserializing data there is the reader object:

Reader reader = Reader.getInstance()

just use reader.read(InputStream). Unfortunately you'll need to make sure you got what you expected, the following example might result in ClassCastException at weird places:

InputStream in = ...;
MPType read = reader.read(in);
MPMap<MPString, MPString> map = (MPMap<MPString, MPString>) read;
String value = map.get(mp("key")).getValue();