2

I am experiencing difficulties with using MsgPack custom serializer in C#. Say, I have the following class:

public class A
{
    public int intA;
    public string strA;
    public B nestedB;
}
public class B
{
    public string strB;
    public int intB; 
} 

I am writing custom deserializer for class A. So my method looks like:

protected override A UnpackFromCore(Unpacker unpacker)
{
     int inta;
     unpacker.ReadInt32(out inta);
     string stra;
     unpacker.ReadString(out stra);
     B b = new B;
     // ??? How to get B from unpacker
     unpacker.?????(b);
}

Everything goes fine with primitive types, but how to extract instance of class B from unpacker? Wiki documentation is quite poor, and not to much information on the Internet regarding MessagePack C# implementation. Any kind of help or advice would be greatly appreciated.

1 Answer 1

1

Here is what I found so far:

  • Before serializing an instance, MsgPack serializes the number of instance fields;
  • After that all fields are serialized alphabetically by default, if they are not marked with DataMember or MessagePackMember attributes (otherwise they are ordered by order or id attribute properties respectively);
  • Unfortunately I haven't found anything what could help to determine this piece of data which holds the number of fields, since all attributes like IsCollectionHeader, IsArrayHeader, IsMapHeader on it are set to false;

So this is still unclear.

Actually it's not necessary for me to dig deeper in this, so I consider this problem as resolved. Maybe my answer could be helpful for somebody else.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.