using System.Runtime.InteropServices; using Google.Protobuf; using Mediapipe.PInvoke; namespace Mediapipe.External; [StructLayout(LayoutKind.Sequential)] internal readonly struct SerializedProto { private readonly nint _str; private readonly int _length; public void Dispose() { UnsafeNativeMethods.delete_array__PKc(_str); } public unsafe T Deserialize(MessageParser parser) where T : IMessage { ReadOnlySpan bytes = new((byte*)_str, _length); return parser.ParseFrom(bytes); } public unsafe void WriteTo(T proto) where T : IMessage { ReadOnlySpan bytes = new((byte*)_str, _length); proto.MergeFrom(bytes); } }