ludocode / mpack

MPack - A C encoder/decoder for the MessagePack serialization format / msgpack.org[C]
MIT License
533 stars 82 forks source link

Mixing binary and trees #78

Closed JorenJoestar closed 4 years ago

JorenJoestar commented 4 years ago

Hello everyone, more than an issue this is me trying to understand how to use this fantastic library!

I am experimenting with it and am trying to serialize data - in this case a simple 'stretchy buffer' like stb_ds array. It just contains an header and the data all in contiguous memory.

I was thinking to first serialize the header as a blob and then for each element serialize the containing type.

I am finding hard to mix binary and map - what is a suggested way of using this API ? Tried searching around the web, but mixing binaries and trees does not seem possible.

What is the best way of handling this ?

Thank you!

JorenJoestar commented 4 years ago

Ok nevermind - found!

I was using mpack_writer_bytes instead of bin inside a map. Currently this works:

mpack_start_map( &writer, 1 ); mpack_write_cstr( &writer, "init" ); mpack_write_bin( &writer, (const char*)stbds_header( test_array ), sizeof( stbds_array_header ) ); mpack_finish_map( &writer );

this is a great news. I can serialize trivial structs as a binary if I need.

Leaving this post for anybody else interested!