1- using System . Runtime . CompilerServices ;
1+ using System . Buffers . Binary ;
2+ using System . Runtime . CompilerServices ;
3+ using System . Text ;
4+
5+ using TACTSharp . Utils ;
26
37namespace TACTSharp . Extensions
48{
@@ -11,5 +15,37 @@ public static StridedReadOnlySpan<T> WithStride<T>(this ReadOnlySpan<T> span, in
1115 [ MethodImpl ( MethodImplOptions . AggressiveInlining ) ]
1216 public static StridedSpan < T > WithStride < T > ( this Span < T > span , int stride )
1317 => new ( span , stride ) ;
18+
19+ [ MethodImpl ( MethodImplOptions . AggressiveInlining ) ]
20+ public static ushort ReadUInt16BE ( this ReadOnlySpan < byte > source )
21+ => BinaryPrimitives . ReadUInt16BigEndian ( source ) ;
22+
23+ [ MethodImpl ( MethodImplOptions . AggressiveInlining ) ]
24+ public static short ReadInt16BE ( this ReadOnlySpan < byte > source )
25+ => BinaryPrimitives . ReadInt16BigEndian ( source ) ;
26+
27+ [ MethodImpl ( MethodImplOptions . AggressiveInlining ) ]
28+ public static int ReadInt24BE ( this ReadOnlySpan < byte > source )
29+ => source [ 2 ] | source [ 1 ] << 8 | source [ 0 ] << 16 ;
30+
31+ [ MethodImpl ( MethodImplOptions . AggressiveInlining ) ]
32+ public static int ReadInt32BE ( this ReadOnlySpan < byte > source )
33+ => BinaryPrimitives . ReadInt32BigEndian ( source ) ;
34+
35+ [ MethodImpl ( MethodImplOptions . AggressiveInlining ) ]
36+ public static int ReadInt32LE ( this ReadOnlySpan < byte > source )
37+ => BinaryPrimitives . ReadInt32LittleEndian ( source ) ;
38+
39+ [ MethodImpl ( MethodImplOptions . AggressiveInlining ) ]
40+ public static uint ReadUInt32BE ( this ReadOnlySpan < byte > source )
41+ => BinaryPrimitives . ReadUInt32BigEndian ( source ) ;
42+
43+ [ MethodImpl ( MethodImplOptions . AggressiveInlining ) ]
44+ public static long ReadInt40BE ( this ReadOnlySpan < byte > source )
45+ => source [ 4 ] | source [ 3 ] << 8 | source [ 2 ] << 16 | source [ 1 ] << 24 | source [ 0 ] << 32 ;
46+
47+ [ MethodImpl ( MethodImplOptions . AggressiveInlining ) ]
48+ public static string ReadNullTermString ( this ReadOnlySpan < byte > source )
49+ => Encoding . UTF8 . GetString ( source [ ..source . IndexOf ( ( byte ) 0 ) ] ) ;
1450 }
1551}
0 commit comments