File tree Expand file tree Collapse file tree 2 files changed +13
-7
lines changed
tracer/src/Datadog.Trace/LibDatadog Expand file tree Collapse file tree 2 files changed +13
-7
lines changed Original file line number Diff line number Diff line change 5
5
6
6
#nullable enable
7
7
8
+ using System ;
8
9
using System . Runtime . InteropServices ;
9
10
using System . Text ;
10
11
using Datadog . Trace . Logging ;
@@ -25,8 +26,6 @@ internal readonly struct Error
25
26
26
27
public LibDatadogException ToException ( )
27
28
{
28
- var messageBytes = Message . ToByteArray ( ) ;
29
- var message = Encoding . UTF8 . GetString ( messageBytes ) ;
30
- return new LibDatadogException ( message ) ;
29
+ return new LibDatadogException ( Message . ToUtf8String ( ) ) ;
31
30
}
32
31
}
Original file line number Diff line number Diff line change 7
7
8
8
using System ;
9
9
using System . Runtime . InteropServices ;
10
+ using System . Text ;
10
11
11
12
namespace Datadog . Trace . LibDatadog ;
12
13
@@ -17,10 +18,16 @@ internal readonly struct FFIVec
17
18
internal readonly nuint Length ;
18
19
internal readonly nuint Capacity ;
19
20
20
- public byte [ ] ToByteArray ( )
21
+ public string ToUtf8String ( )
21
22
{
22
- var bytes = new byte [ Length ] ;
23
- Marshal . Copy ( Data , bytes , 0 , ( int ) Length ) ;
24
- return bytes ;
23
+ unsafe
24
+ {
25
+ #if NETCOREAPP
26
+ var messageBytes = new ReadOnlySpan < byte > ( Data . ToPointer ( ) , ( int ) Length ) ;
27
+ return Encoding . UTF8 . GetString ( messageBytes ) ;
28
+ #else
29
+ return Encoding . UTF8 . GetString ( ( byte * ) Data . ToPointer ( ) , ( int ) Length ) ;
30
+ #endif
31
+ }
25
32
}
26
33
}
You can’t perform that action at this time.
0 commit comments