Wes xx mediapipe integration
This commit is contained in:
32
Packages/com.github.homuler.mediapipe/Runtime/Scripts/External/SerializedProto.cs
vendored
Normal file
32
Packages/com.github.homuler.mediapipe/Runtime/Scripts/External/SerializedProto.cs
vendored
Normal file
@@ -0,0 +1,32 @@
|
||||
// Copyright (c) 2021 homuler
|
||||
//
|
||||
// Use of this source code is governed by an MIT-style
|
||||
// license that can be found in the LICENSE file or at
|
||||
// https://opensource.org/licenses/MIT.
|
||||
|
||||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
using pb = Google.Protobuf;
|
||||
|
||||
namespace Mediapipe
|
||||
{
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
internal readonly struct SerializedProto
|
||||
{
|
||||
private readonly IntPtr _str;
|
||||
private readonly int _length;
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
UnsafeNativeMethods.delete_array__PKc(_str);
|
||||
}
|
||||
|
||||
public T Deserialize<T>(pb::MessageParser<T> parser) where T : pb::IMessage<T>
|
||||
{
|
||||
var bytes = new byte[_length];
|
||||
Marshal.Copy(_str, bytes, 0, bytes.Length);
|
||||
return parser.ParseFrom(bytes);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user