Skip to content

Commit

Permalink
Support .Netstandard 2.0 (#193)
Browse files Browse the repository at this point in the history
  • Loading branch information
csukuangfj authored Jul 2, 2023
1 parent 0dd2d41 commit 2c43660
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 6 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
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
#
Expand Down
21 changes: 20 additions & 1 deletion scripts/dotnet/offline.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using System.Linq;
using System.Collections.Generic;
using System.Runtime.InteropServices;
using System.Text;
using System;

namespace SherpaOnnx
Expand Down Expand Up @@ -116,7 +117,25 @@ public class OfflineRecognizerResult
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)]
Expand Down
22 changes: 20 additions & 2 deletions scripts/dotnet/online.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
/// 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
Expand Down Expand Up @@ -116,7 +117,24 @@ public class OnlineRecognizerResult
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)]
Expand Down
2 changes: 1 addition & 1 deletion scripts/dotnet/sherpa-onnx.csproj.in
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down
2 changes: 1 addition & 1 deletion scripts/dotnet/sherpa-onnx.csproj.runtime.in
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down

0 comments on commit 2c43660

Please sign in to comment.