Support .Netstandard 2.0 (#193)

This commit is contained in:
Fangjun Kuang
2023-07-02 22:57:48 +08:00
committed by GitHub
parent 0dd2d41f27
commit 2c436606bd
5 changed files with 43 additions and 6 deletions

View File

@@ -4,6 +4,7 @@
using System.Linq;
using System.Collections.Generic;
using System.Runtime.InteropServices;
using System.Text;
using System;
namespace SherpaOnnx
@@ -116,7 +117,25 @@ namespace SherpaOnnx
public OfflineRecognizerResult(IntPtr handle)
{
Impl impl = (Impl)Marshal.PtrToStructure(handle, typeof(Impl));
_text = Marshal.PtrToStringUTF8(impl.Text);
// PtrToStringUTF8() requires .net standard 2.1
// _text = Marshal.PtrToStringUTF8(impl.Text);
int length = 0;
unsafe
{
byte* buffer = (byte*)impl.Text;
while (*buffer != 0)
{
++buffer;
}
length = (int)(buffer - (byte*)impl.Text);
}
byte[] stringBuffer = new byte[length];
Marshal.Copy(impl.Text, stringBuffer, 0, length);
_text = Encoding.UTF8.GetString(stringBuffer);
}
[StructLayout(LayoutKind.Sequential)]