dotnet/orleans

Does MessagePack also follow the DeepCopy strategy?

jerviscui opened this issue · 1 comments

I checked the source code and MessagePackCodec doesn't support [Immutable] attribute. Right?

https://github.com/dotnet/orleans/blob/b57d9e3e0a3d9206f071a7ed52d5ede837744d59/src/Orleans.Serialization.MessagePack/MessagePackCodec.cs#L184C1-L208C6

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