Fangjun Kuang
Committed by GitHub

Support .Netstandard 2.0 (#193)

cmake_minimum_required(VERSION 3.13 FATAL_ERROR)
project(sherpa-onnx)
set(SHERPA_ONNX_VERSION "1.4.7")
set(SHERPA_ONNX_VERSION "1.4.8")
# Disable warning about
#
... ...
... ... @@ -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)]
... ...
/// Copyright (c) 2023 Xiaomi Corporation (authors: Fangjun Kuang)
/// Copyright (c) 2023 by manyeyes
using System.Linq;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System;
namespace SherpaOnnx
... ... @@ -116,7 +117,24 @@ namespace SherpaOnnx
public OnlineRecognizerResult(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)]
... ...
... ... @@ -4,7 +4,7 @@
<PackageReadmeFile>README.md</PackageReadmeFile>
<OutputType>Library</OutputType>
<LangVersion>10.0</LangVersion>
<TargetFrameworks>netstandard2.1;netcoreapp3.1;net6.0;net7.0</TargetFrameworks>
<TargetFrameworks>netstandard2.0;netcoreapp3.1;net6.0;net7.0</TargetFrameworks>
<RuntimeIdentifiers>linux-x64;osx-x64;win-x64</RuntimeIdentifiers>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<AssemblyName>sherpa-onnx</AssemblyName>
... ...
... ... @@ -3,7 +3,7 @@
<PackageLicenseExpression>Apache-2.0</PackageLicenseExpression>
<PackageReadmeFile>README.md</PackageReadmeFile>
<OutputType>Library</OutputType>
<TargetFrameworks>netstandard2.0;netcoreapp3.1;net6.0</TargetFrameworks>
<TargetFrameworks>netstandard2.0;netcoreapp3.1;net6.0;net7.0</TargetFrameworks>
<RuntimeIdentifier>{{ dotnet_rid }}</RuntimeIdentifier>
<AssemblyName>sherpa-onnx</AssemblyName>
<Version>{{ version }}</Version>
... ...