internal static float?ReadFloatWrapperSlow(ref ReadOnlySpan <byte> buffer, ref ParserInternalState state) { int length = ParsingPrimitives.ParseLength(ref buffer, ref state); if (length == 0) { return(0F); } int finalBufferPos = state.totalBytesRetired + state.bufferPos + length; float result = 0F; do { // field=1, type=32-bit = tag of 13 if (ParsingPrimitives.ParseTag(ref buffer, ref state) == 13) { result = ParsingPrimitives.ParseFloat(ref buffer, ref state); } else { ParsingPrimitivesMessages.SkipLastField(ref buffer, ref state); } }while (state.totalBytesRetired + state.bufferPos < finalBufferPos); return(result); }
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); }
internal static uint?ReadUInt32WrapperSlow(ref ReadOnlySpan <byte> buffer, ref ParserInternalState state) { int length = ParsingPrimitives.ParseLength(ref buffer, ref state); if (length == 0) { return(0); } int finalBufferPos = state.totalBytesRetired + state.bufferPos + length; uint result = 0; do { // field=1, type=varint = tag of 8 if (ParsingPrimitives.ParseTag(ref buffer, ref state) == 8) { result = ParsingPrimitives.ParseRawVarint32(ref buffer, ref state); } else { ParsingPrimitivesMessages.SkipLastField(ref buffer, ref state); } }while (state.totalBytesRetired + state.bufferPos < finalBufferPos); return(result); }
internal static double?ReadDoubleWrapperSlow(ref ReadOnlySpan <byte> buffer, ref ParserInternalState state) { int length = ParsingPrimitives.ParseLength(ref buffer, ref state); if (length == 0) { return(0D); } int finalBufferPos = state.totalBytesRetired + state.bufferPos + length; double result = 0D; do { // field=1, type=64-bit = tag of 9 if (ParsingPrimitives.ParseTag(ref buffer, ref state) == 9) { result = ParsingPrimitives.ParseDouble(ref buffer, ref state); } else { ParsingPrimitivesMessages.SkipLastField(ref buffer, ref state); } }while (state.totalBytesRetired + state.bufferPos < finalBufferPos); return(result); }
/// <summary> /// Skip a group. /// </summary> public static void SkipGroup(ref ReadOnlySpan <byte> buffer, ref ParserInternalState state, uint startGroupTag) { // Note: Currently we expect this to be the way that groups are read. We could put the recursion // depth changes into the ReadTag method instead, potentially... state.recursionDepth++; if (state.recursionDepth >= state.recursionLimit) { throw InvalidProtocolBufferException.RecursionLimitExceeded(); } uint tag; while (true) { tag = ParsingPrimitives.ParseTag(ref buffer, ref state); if (tag == 0) { throw InvalidProtocolBufferException.TruncatedMessage(); } // Can't call SkipLastField for this case- that would throw. if (WireFormat.GetTagWireType(tag) == WireFormat.WireType.EndGroup) { break; } // This recursion will allow us to handle nested groups. SkipLastField(ref buffer, ref state); } int startField = WireFormat.GetTagFieldNumber(startGroupTag); int endField = WireFormat.GetTagFieldNumber(tag); if (startField != endField) { throw new InvalidProtocolBufferException( $"Mismatched end-group tag. Started with field {startField}; ended with field {endField}"); } state.recursionDepth--; }
/// <summary> /// Reads a field tag, returning the tag of 0 for "end of stream". /// </summary> /// <remarks> /// If this method returns 0, it doesn't necessarily mean the end of all /// the data in this CodedInputStream; it may be the end of the logical stream /// for an embedded message, for example. /// </remarks> /// <returns>The next field tag, or 0 for end of stream. (0 is never a valid tag.)</returns> public uint ReadTag() { var span = new ReadOnlySpan <byte>(buffer); return(ParsingPrimitives.ParseTag(ref span, ref state)); }
public uint ReadTag() { return(ParsingPrimitives.ParseTag(ref buffer, ref state)); }