internal static void MergeFrom(this IMessage message, ReadOnlySpan <byte> data, bool discardUnknownFields, ExtensionRegistry registry) { ParseContext.Initialize(data, out ParseContext ctx); ctx.DiscardUnknownFields = discardUnknownFields; ctx.ExtensionRegistry = registry; ParsingPrimitivesMessages.ReadRawMessage(ref ctx, message); ParsingPrimitivesMessages.CheckReadEndOfStreamTag(ref ctx.state); }
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); }
/// <summary> /// Verifies that the last call to ReadTag() returned tag 0 - in other words, /// we've reached the end of the stream when we expected to. /// </summary> /// <exception cref="InvalidProtocolBufferException">The /// tag read was not the one specified</exception> internal void CheckReadEndOfStreamTag() { ParsingPrimitivesMessages.CheckReadEndOfStreamTag(ref state); }