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)
55
55
{
56
56
if ( handle is null ) {
57
57
return new byte [ 0 ] ;
58
- }
59
58
var data = handle . ToArray ( ) ;
60
59
return data ;
61
60
}
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
+ }
62
80
63
81
[ UnmanagedFunctionPointer ( CallingConvention . Winapi ) ]
64
82
public delegate void Deallocator ( IntPtr data , IntPtr size , ref DeallocatorArgs args ) ;
You can’t perform that action at this time.
0 commit comments