diff --git a/Mediapipe.Net/External/SerializedProto.cs b/Mediapipe.Net/External/SerializedProto.cs new file mode 100644 index 0000000..63b07fa --- /dev/null +++ b/Mediapipe.Net/External/SerializedProto.cs @@ -0,0 +1,28 @@ +// Copyright (c) homuler and Vignette +// This file is part of MediaPipe.NET. +// MediaPipe.NET is licensed under the MIT License. See LICENSE for details. + +using System; +using System.Runtime.InteropServices; +using Google.Protobuf; +using Mediapipe.Net.Native; + +namespace Mediapipe.Net.External; + +[StructLayout(LayoutKind.Sequential)] +internal struct SerializedProto +{ + public IntPtr StrPtr; + public int Length; + + // TODO: That Dispose() method is looking very sus... + // Might wanna investigate if it's better as a child of Disposable. + public void Dispose() => UnsafeNativeMethods.delete_array__PKc(StrPtr); + + public T Deserialize(MessageParser parser) where T : IMessage + { + byte[] bytes = new byte[Length]; + Marshal.Copy(StrPtr, bytes, 0, bytes.Length); + return parser.ParseFrom(bytes); + } +}