<dependency>
<groupId>org.msgpack</groupId>
<artifactId>msgpack-core</artifactId>
<version>0.9.3</version>
</dependency>
import org.msgpack.core.MessageBufferPacker;
import org.msgpack.core.MessagePack;
import org.msgpack.core.MessagePacker;
public class MsgPackEncoder {
public static byte[] encode(Object data) throws IOException {
MessageBufferPacker packer = MessagePack.newDefaultBufferPacker();
packer.packObject(data);
byte[] packedData = packer.toByteArray();
packer.close();
return packedData;
}
public static void main(String[] args) throws IOException {
String message = "Hello, MsgPack!";
byte[] packedData = encode(message);
System.out.println(Arrays.toString(packedData));
}
}
import org.msgpack.core.MessageBufferUnpacker;
import org.msgpack.core.MessagePack;
import org.msgpack.core.MessageUnpacker;
public class MsgPackDecoder {
public static Object decode(byte[] data) throws IOException {
MessageBufferUnpacker unpacker = MessagePack.newDefaultUnpacker(data);
Object unpackedData = unpacker.unpackObject();
unpacker.close();
return unpackedData;
}
public static void main(String[] args) throws IOException {
Object unpackedData = decode(packedData);
System.out.println(unpackedData);
}
}