1111using System . Buffers ;
1212using System . Buffers . Binary ;
1313using System . Collections . Generic ;
14+ using System . Diagnostics ;
1415using System . IO ;
1516using System . Runtime . CompilerServices ;
1617using System . Runtime . InteropServices ;
@@ -45,7 +46,7 @@ public static int ParseLength(ref ReadOnlySpan<byte> buffer, ref ParserInternalS
4546
4647 /// <summary>
4748 /// Parses the next tag.
48- /// If the end of logical stream was reached, an invalid tag of 0 is returned.
49+ /// If the end of logical stream was reached, an invalid tag of 0 is returned.
4950 /// </summary>
5051 public static uint ParseTag ( ref ReadOnlySpan < byte > buffer , ref ParserInternalState state )
5152 {
@@ -382,7 +383,7 @@ public static float ParseFloat(ref ReadOnlySpan<byte> buffer, ref ParserInternal
382383 // ReadUnaligned uses processor architecture for endianness.
383384 float result = Unsafe . ReadUnaligned < float > ( ref MemoryMarshal . GetReference ( buffer . Slice ( state . bufferPos , length ) ) ) ;
384385 state . bufferPos += length ;
385- return result ;
386+ return result ;
386387 }
387388
388389 private static unsafe float ParseFloatSlow ( ref ReadOnlySpan < byte > buffer , ref ParserInternalState state )
@@ -737,7 +738,7 @@ public static uint ReadRawVarint32(Stream input)
737738 /// </summary>
738739 /// <remarks>
739740 /// ZigZag encodes signed integers into values that can be efficiently
740- /// encoded with varint. (Otherwise, negative values must be
741+ /// encoded with varint. (Otherwise, negative values must be
741742 /// sign-extended to 32 bits to be varint encoded, thus always taking
742743 /// 5 bytes on the wire.)
743744 /// </remarks>
@@ -751,7 +752,7 @@ public static int DecodeZigZag32(uint n)
751752 /// </summary>
752753 /// <remarks>
753754 /// ZigZag encodes signed integers into values that can be efficiently
754- /// encoded with varint. (Otherwise, negative values must be
755+ /// encoded with varint. (Otherwise, negative values must be
755756 /// sign-extended to 64 bits to be varint encoded, thus always taking
756757 /// 10 bytes on the wire.)
757758 /// </remarks>
@@ -810,5 +811,25 @@ private static void ReadRawBytesIntoSpan(ref ReadOnlySpan<byte> buffer, ref Pars
810811 state . bufferPos += unreadSpan . Length ;
811812 }
812813 }
814+
815+ /// <summary>
816+ /// Read LittleEndian packed field from buffer of specified length into a span.
817+ /// The amount of data available and the current limit should be checked before calling this method.
818+ /// </summary>
819+ internal static void ReadPackedFieldLittleEndian ( ref ReadOnlySpan < byte > buffer , ref ParserInternalState state , int length , Span < byte > outBuffer )
820+ {
821+ Debug . Assert ( BitConverter . IsLittleEndian ) ;
822+
823+ if ( length <= state . bufferSize - state . bufferPos )
824+ {
825+ buffer . Slice ( state . bufferPos , length ) . CopyTo ( outBuffer ) ;
826+ state . bufferPos += length ;
827+ }
828+ else
829+ {
830+ ReadRawBytesIntoSpan ( ref buffer , ref state , length , outBuffer ) ;
831+ }
832+ }
833+
813834 }
814835}
0 commit comments