Skip to content

Commit 649db14

Browse files
authored
Merge branch 'master' into rnn-dev
2 parents 69b3bce + 46e2162 commit 649db14

File tree

1 file changed

+19
-1
lines changed

1 file changed

+19
-1
lines changed

src/TensorFlowNET.Core/APIs/c_api.cs

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,10 +55,28 @@ public unsafe static byte[] ByteStringPiece(Buffer? handle)
5555
{
5656
if(handle is null){
5757
return new byte[0];
58-
}
5958
var data = handle.ToArray();
6059
return data;
6160
}
61+
62+
public unsafe static byte[] ByteStringPieceFromNativeString(IntPtr handle)
63+
{
64+
if (handle == IntPtr.Zero)
65+
{
66+
return new byte[0];
67+
}
68+
69+
byte* str_data = (byte*)handle.ToPointer();
70+
List<byte> bytes = new List<byte>();
71+
byte current = 255;
72+
while (current != ((byte)'\0'))
73+
{
74+
current = *(str_data++);
75+
bytes.Add(current);
76+
}
77+
var data = bytes.ToArray();
78+
return data;
79+
}
6280

6381
[UnmanagedFunctionPointer(CallingConvention.Winapi)]
6482
public delegate void Deallocator(IntPtr data, IntPtr size, ref DeallocatorArgs args);

0 commit comments

Comments
 (0)