Ejemplo n.º 1
0
        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);
        }
Ejemplo n.º 2
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);
        }
Ejemplo n.º 3
0
        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);
        }
Ejemplo n.º 4
0
        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);
        }
Ejemplo n.º 5
0
 public static UnknownFieldSet MergeFieldFrom(UnknownFieldSet unknownFields,
                                              ref ParseContext ctx)
 {
     if (ctx.DiscardUnknownFields)
     {
         ParsingPrimitivesMessages.SkipLastField(ref ctx.buffer, ref ctx.state);
         return(unknownFields);
     }
     if (unknownFields == null)
     {
         unknownFields = new UnknownFieldSet();
     }
     if (!unknownFields.MergeFieldFrom(ref ctx))
     {
         throw new InvalidProtocolBufferException("Merge an unknown field of end-group tag, indicating that the corresponding start-group was missing."); // match the old code-gen
     }
     return(unknownFields);
 }
Ejemplo n.º 6
0
            internal static T Read <T>(ref ParseContext ctx, FieldCodec <T> codec)
            {
                int length   = ctx.ReadLength();
                int oldLimit = SegmentedBufferHelper.PushLimit(ref ctx.state, length);

                uint tag;
                T    value = codec.DefaultValue;

                while ((tag = ctx.ReadTag()) != 0)
                {
                    if (tag == codec.Tag)
                    {
                        value = codec.Read(ref ctx);
                    }
                    else
                    {
                        ParsingPrimitivesMessages.SkipLastField(ref ctx.buffer, ref ctx.state);
                    }
                }
                ParsingPrimitivesMessages.CheckReadEndOfStreamTag(ref ctx.state);
                SegmentedBufferHelper.PopLimit(ref ctx.state, oldLimit);

                return(value);
            }
Ejemplo n.º 7
0
        /// <summary>
        /// Skips the data for the field with the tag we've just read.
        /// This should be called directly after <see cref="ReadTag"/>, when
        /// the caller wishes to skip an unknown field.
        /// </summary>
        /// <remarks>
        /// This method throws <see cref="InvalidProtocolBufferException"/> if the last-read tag was an end-group tag.
        /// If a caller wishes to skip a group, they should skip the whole group, by calling this method after reading the
        /// start-group tag. This behavior allows callers to call this method on any field they don't understand, correctly
        /// resulting in an error if an end-group tag has not been paired with an earlier start-group tag.
        /// </remarks>
        /// <exception cref="InvalidProtocolBufferException">The last tag was an end-group tag</exception>
        /// <exception cref="InvalidOperationException">The last read operation read to the end of the logical stream</exception>
        public void SkipLastField()
        {
            var span = new ReadOnlySpan <byte>(buffer);

            ParsingPrimitivesMessages.SkipLastField(ref span, ref state);
        }