diff --git a/src/TensorFlowNET.Core/APIs/c_api.cs b/src/TensorFlowNET.Core/APIs/c_api.cs index d4744e78..559176a5 100644 --- a/src/TensorFlowNET.Core/APIs/c_api.cs +++ b/src/TensorFlowNET.Core/APIs/c_api.cs @@ -55,10 +55,28 @@ namespace Tensorflow { if(handle is null){ return new byte[0]; - } var data = handle.ToArray(); return data; } + + public unsafe static byte[] ByteStringPieceFromNativeString(IntPtr handle) + { + if (handle == IntPtr.Zero) + { + return new byte[0]; + } + + byte* str_data = (byte*)handle.ToPointer(); + List bytes = new List(); + byte current = 255; + while (current != ((byte)'\0')) + { + current = *(str_data++); + bytes.Add(current); + } + var data = bytes.ToArray(); + return data; + } [UnmanagedFunctionPointer(CallingConvention.Winapi)] public delegate void Deallocator(IntPtr data, IntPtr size, ref DeallocatorArgs args);