msgpack-cli icon indicating copy to clipboard operation
msgpack-cli copied to clipboard

msgpack on dotnet micro framework

Open fdb-git opened this issue 12 years ago • 4 comments

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

fdb-git avatar Apr 26 '13 15:04 fdb-git

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.

yfakariya avatar Apr 29 '13 12:04 yfakariya

Ok, thak you so much, Yusuke. Bye.

fdb-git avatar Apr 29 '13 12:04 fdb-git

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

fdb-git avatar May 14 '13 15:05 fdb-git

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);
}

yfakariya avatar May 15 '13 15:05 yfakariya