I am using MessagePack version 3.1.4 for binary serialization/deserialization. With the most basic code and decorating my fields/properties with the Key attribute:
public static byte[] Serialize<T>(T source)
{
using (var stream = new MemoryStream())
{
MessagePackSerializer.Serialize(stream, source);
return stream.ToArray();
}
}
public static T Deserialize<T>(byte[] source)
{
using (var stream = new MemoryStream(source))
{
return MessagePackSerializer.Deserialize<T>(stream);
}
}
Then the byte array is stored in a database.
I would like to serialize an object once and have the other references to that object serialized as references. Perhaps this is not the right approach.
I want to preserve these references during deserialization. To summarize: the goal is to obtain two identical objects between serialization and deserialization.
How can this be done?