File tree Expand file tree Collapse file tree 1 file changed +19
-1
lines changed
src/TensorFlowNET.Core/APIs Expand file tree Collapse file tree 1 file changed +19
-1
lines changed Original file line number Diff line number Diff 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 ) ;
You can’t perform that action at this time.
0 commit comments