src/Orleans.Serialization/Buffers/Reader.cs
/// <summary>
/// Reads a variable-width <see cref="uint"/> from the input.
/// </summary>
/// <returns>The <see cref="uint"/> which was read.</returns>
Reads a variable-width  from the input.
Reads a variable - width from the input .
[MethodImpl(MethodImplOptions.AggressiveInlining)]
        public unsafe uint ReadVarUInt32()
        {
            if (IsReadOnlySequenceInput || IsSpanInput)
            {
                var pos = _bufferPos;
                if (!BitConverter.IsLittleEndian || pos + 8 > _currentSpan.Length)
                {
                    return ReadVarUInt32Slow();
                }
                ref byte readHead = ref Unsafe.Add(ref MemoryMarshal.GetReference(_currentSpan), pos);
                ulong result = Unsafe.ReadUnaligned<ulong>(ref readHead);
                var bytesNeeded = BitOperations.TrailingZeroCount(result) + 1;
                result >>= bytesNeeded;
                _bufferPos += bytesNeeded;
                var fullWidthReadMask = ~((ulong)bytesNeeded - 6 + 1);
                var mask = ((1UL << (bytesNeeded * 7)) - 1) | fullWidthReadMask;
                result &= mask;
                return (uint)result;
            }
            else
            {
                return ReadVarUInt32Slow();
            }
        }
[ MethodImpl ( MethodImplOptions . AggressiveInlining ) ] public unsafe uint ReadVarUInt32 ( ) { if ( IsReadOnlySequenceInput || IsSpanInput ) { var pos = _bufferPos ; if ( ! BitConverter . IsLittleEndian || pos + 8 > _currentSpan . Length ) { return ReadVarUInt32Slow ( ) ; } ref byte readHead = ref Unsafe . Add ( ref MemoryMarshal . GetReference ( _currentSpan ) , pos ) ; ulong result = Unsafe . ReadUnaligned < ulong > ( ref readHead ) ; var bytesNeeded = BitOperations . TrailingZeroCount ( result ) + 1 ; result >>= bytesNeeded ; _bufferPos += bytesNeeded ; var fullWidthReadMask = ~ ( ( ulong ) bytesNeeded - 6 + 1 ) ; var mask = ( ( 1UL << ( bytesNeeded * 7 ) ) - 1 ) | fullWidthReadMask ; result &= mask ; return ( uint ) result ; } else { return ReadVarUInt32Slow ( ) ; } }
Reads a variable-width  from the input.
Reads a variable - width from the input .
// The number of zeros in the msb position dictates the number of bytes to be read. // Up to a maximum of 5 for a 32bit integer. // Mask off invalid data
The  which was read.
The which was read .