11using System . Runtime . CompilerServices ;
22
3+ using TACTSharp . Utils ;
4+
35namespace TACTSharp . Extensions
46{
57 internal static class SpanExtensions
@@ -11,5 +13,33 @@ public static StridedReadOnlySpan<T> WithStride<T>(this ReadOnlySpan<T> span, in
1113 [ MethodImpl ( MethodImplOptions . AggressiveInlining ) ]
1214 public static StridedSpan < T > WithStride < T > ( this Span < T > span , int stride )
1315 => new ( span , stride ) ;
16+
17+ [ MethodImpl ( MethodImplOptions . AggressiveInlining ) ]
18+ public static ushort ReadUInt16BE ( this ReadOnlySpan < byte > source )
19+ => BinaryPrimitives . ReadUInt16BigEndian ( source ) ;
20+
21+ [ MethodImpl ( MethodImplOptions . AggressiveInlining ) ]
22+ public static short ReadInt16BE ( this ReadOnlySpan < byte > source )
23+ => BinaryPrimitives . ReadInt16BigEndian ( source ) ;
24+
25+ [ MethodImpl ( MethodImplOptions . AggressiveInlining ) ]
26+ public static int ReadInt24BE ( this ReadOnlySpan < byte > source )
27+ => source [ 2 ] | source [ 1 ] << 8 | source [ 0 ] << 16 ;
28+
29+ [ MethodImpl ( MethodImplOptions . AggressiveInlining ) ]
30+ public static int ReadInt32BE ( this ReadOnlySpan < byte > source )
31+ => BinaryPrimitives . ReadInt32BigEndian ( source ) ;
32+
33+ [ MethodImpl ( MethodImplOptions . AggressiveInlining ) ]
34+ public static uint ReadUInt32BE ( this ReadOnlySpan < byte > source )
35+ => BinaryPrimitives . ReadUInt32BigEndian ( source ) ;
36+
37+ [ MethodImpl ( MethodImplOptions . AggressiveInlining ) ]
38+ public static long ReadInt40BE ( this ReadOnlySpan < byte > source )
39+ => source [ 4 ] | source [ 3 ] << 8 | source [ 2 ] << 16 | source [ 1 ] << 24 | source [ 0 ] << 32 ;
40+
41+ [ MethodImpl ( MethodImplOptions . AggressiveInlining ) ]
42+ public static string ReadNullTermString ( this ReadOnlySpan < byte > source )
43+ => Encoding . UTF8 . GetString ( source [ ..source . IndexOf ( ( byte ) 0 ) ] ) ;
1444 }
1545}
0 commit comments