コード例 #1
0
        internal static ulong?ReadUInt64WrapperSlow(ref ReadOnlySpan <byte> buffer, ref ParserInternalState state)
        {
            // field=1, type=varint = tag of 8
            const int expectedTag = 8;
            int       length      = ParsingPrimitives.ParseLength(ref buffer, ref state);

            if (length == 0)
            {
                return(0L);
            }
            int   finalBufferPos = state.totalBytesRetired + state.bufferPos + length;
            ulong result         = 0L;

            do
            {
                if (ParsingPrimitives.ParseTag(ref buffer, ref state) == expectedTag)
                {
                    result = ParsingPrimitives.ParseRawVarint64(ref buffer, ref state);
                }
                else
                {
                    ParsingPrimitivesMessages.SkipLastField(ref buffer, ref state);
                }
            }while (state.totalBytesRetired + state.bufferPos < finalBufferPos);
            return(result);
        }
コード例 #2
0
        internal static ulong?ReadUInt64Wrapper(ref ReadOnlySpan <byte> buffer, ref ParserInternalState state)
        {
            // field=1, type=varint = tag of 8
            const int expectedTag = 8;

            // length:1 + tag:1 + value:10(varint64-max) = 12 bytes
            if (state.bufferPos + 12 <= state.bufferSize)
            {
                // The entire wrapper message is already contained in `buffer`.
                int pos0   = state.bufferPos;
                int length = buffer[state.bufferPos++];
                if (length == 0)
                {
                    return(0L);
                }
                // Length will always fit in a single byte.
                if (length >= 128)
                {
                    state.bufferPos = pos0;
                    return(ReadUInt64WrapperSlow(ref buffer, ref state));
                }
                int finalBufferPos = state.bufferPos + length;
                if (buffer[state.bufferPos++] != expectedTag)
                {
                    state.bufferPos = pos0;
                    return(ReadUInt64WrapperSlow(ref buffer, ref state));
                }
                var result = ParsingPrimitives.ParseRawVarint64(ref buffer, ref state);
                // Verify this message only contained a single field.
                if (state.bufferPos != finalBufferPos)
                {
                    state.bufferPos = pos0;
                    return(ReadUInt64WrapperSlow(ref buffer, ref state));
                }
                return(result);
            }
            else
            {
                return(ReadUInt64WrapperSlow(ref buffer, ref state));
            }
        }
コード例 #3
0
 public bool ReadBool()
 {
     return(ParsingPrimitives.ParseRawVarint64(ref buffer, ref state) != 0);
 }
コード例 #4
0
 public long ReadSInt64()
 {
     return(ParsingPrimitives.DecodeZigZag64(ParsingPrimitives.ParseRawVarint64(ref buffer, ref state)));
 }
コード例 #5
0
 public long ReadInt64()
 {
     return((long)ParsingPrimitives.ParseRawVarint64(ref buffer, ref state));
 }