Does MessagePack also follow the DeepCopy strategy?
jerviscui opened this issue · 1 comments
jerviscui commented
Does MessagePack also follow the DeepCopy strategy?
doc: https://learn.microsoft.com/en-us/dotnet/orleans/host/configuration-guide/serialization-immutability
jerviscui commented
I checked the source code and MessagePackCodec doesn't support [Immutable] attribute. Right?
object IDeepCopier.DeepCopy(object input, CopyContext context)
{
if (context.TryGetCopy(input, out object result))
{
return result;
}
var bufferWriter = new BufferWriterBox<PooledBuffer>(new());
try
{
var msgPackWriter = new MessagePackWriter(bufferWriter);
MessagePackSerializer.Serialize(input.GetType(), ref msgPackWriter, input, _options.SerializerOptions);
msgPackWriter.Flush();
var sequence = bufferWriter.Value.AsReadOnlySequence();
result = MessagePackSerializer.Deserialize(input.GetType(), sequence, _options.SerializerOptions);
}
catch
{
bufferWriter.Value.Dispose();
}
context.RecordCopy(input, result);
return result;
}