← Back

ofxMessagePack

github.com/elliotwoods/ofxMessagePack · @elliotwoods
OF 0.11 Utilities

Implementation of MessagePack for openFrameworks (based on msgpack-c)

13 5 Last commit 4y ago Created 12y ago

README

ofxMessagePack



Implementation of MessagePack for openFrameworks (based on msgpack-c)

Usage



If you want to save something to a file (e.g. a vector of something), then use:

ofxMessagePack::Packer packer;
packer << myObjectThatIWantToPack;
packer.save("filename.bin");


If you want to load something from a file, then use:

ofxMessagePack::Unpacker unpacker;
unpacker.load("filename.bin");
unpacker >> myObjectThatIWantToPack;


If you don't want to use files (e.g. you're sending via network), then you can use:

ofxMessagePack::Packer packer;
...
ofBuffer buffer = packer.getBuffer();
...
ofxMessagePack::Unpacker unpacker;
unpacker.setBuffer(buffer);


If you want to use MessagePack with custom data types (e.g. your own classes), then you need to add a line to your class definition, e.g.:

class MyPoint {
public:
  float x;
  float y;
  
  MSGPACK_DEFINE(x, y)
};


Notice how the fields x and y are explicitly declared to MessagePack.

Generally MessagePack can natively serialise/deserialise the usual types (int, double, bool, string, etc) and can also handle containers (vector, map, etc. For everything else, use MSGPACK_DEFINE(…).

Note



There is an existing addon for MessagePack at https://github.com/hiroyuki/ofxMessagePack (from which I got the osx libs). That addon works a little differently than this one, so make sure to check that one out also and see which one you prefer.

Get this addon

HTTPS
SSH