msgpack / msgpack-cli

MessagePack implementation for Common Language Infrastructure / msgpack.org[C#]
http://msgpack.org
Apache License 2.0
835 stars 175 forks source link

msgpack on dotnet micro framework #5

Open fdb-git opened 11 years ago

fdb-git commented 11 years ago

I would use msgpack on Netduino using its .net microframework. Might work? Alternatively, you know a library for microfw?

yfakariya commented 11 years ago

MsgPack-CLI might not work on .NET Micro Framework because MsgPack.Serialization APIs depend on dynamic code generation via System.Reflection.Emit or expression tree. I don't know any alternative libraries, but Packer/Unpacker primitive APIs in msgpack-cli might help you to create or interpret msgpack stream. It is not very convenience, but it might work.

fdb-git commented 11 years ago

Ok, thak you so much, Yusuke. Bye.

fdb-git commented 11 years ago

I didn't found what are the classes that implement the serialization of Map and Array.

I found the class MsgPack takes care of serializing simple data, but could not find where is the basic serialization of Map and Array

yfakariya commented 11 years ago

You can do that with Packer API. There are 2 steps to make array or map. 1) Write a header value which represents items count of the array or the map via PackArrayHeader or PackMapHeader respectedly. 2) Write a body via Pack methods for each items in the array or the map. Note that you just pack items as non-collection items.

Example:

// Array
List<int> items = ...;
Packer packer = ...;
packer.PackArrayHeader(items); // or, just write packer.PackArrayHeader(items.Count)
foreach( var item in items) 
{
    packer.Pack(item);
}

// Map
Dictionary<string, int> items = ...;
Packer packer = ...;
packer.PackMapHeader(items); // or, just write packer.PackMapHeader(items.Count)
foreach( var item in items) 
{
    packer.PackString(item.Key);
    packer.Pack(item.Value);
}