SkipLastField() public method

Skips the data for the field with the tag we've just read. This should be called directly after ReadTag, when the caller wishes to skip an unknown field.
This method throws 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.
The last tag was an end-group tag The last read operation read to the end of the logical stream
public SkipLastField ( ) : void
return void
Ejemplo n.º 1
0
        public void SkipGroup()
        {
            // Create an output stream with a group in:
            // Field 1: string "field 1"
            // Field 2: group containing:
            //   Field 1: fixed int32 value 100
            //   Field 2: string "ignore me"
            //   Field 3: nested group containing
            //      Field 1: fixed int64 value 1000
            // Field 3: string "field 3"
            var stream = new MemoryStream();
            var output = new CodedOutputStream(stream);

            output.WriteTag(1, WireFormat.WireType.LengthDelimited);
            output.WriteString("field 1");

            // The outer group...
            output.WriteTag(2, WireFormat.WireType.StartGroup);
            output.WriteTag(1, WireFormat.WireType.Fixed32);
            output.WriteFixed32(100);
            output.WriteTag(2, WireFormat.WireType.LengthDelimited);
            output.WriteString("ignore me");
            // The nested group...
            output.WriteTag(3, WireFormat.WireType.StartGroup);
            output.WriteTag(1, WireFormat.WireType.Fixed64);
            output.WriteFixed64(1000);
            // Note: Not sure the field number is relevant for end group...
            output.WriteTag(3, WireFormat.WireType.EndGroup);

            // End the outer group
            output.WriteTag(2, WireFormat.WireType.EndGroup);

            output.WriteTag(3, WireFormat.WireType.LengthDelimited);
            output.WriteString("field 3");
            output.Flush();
            stream.Position = 0;

            // Now act like a generated client
            var input = new CodedInputStream(stream);

            Assert.AreEqual(WireFormat.MakeTag(1, WireFormat.WireType.LengthDelimited), input.ReadTag());
            Assert.AreEqual("field 1", input.ReadString());
            Assert.AreEqual(WireFormat.MakeTag(2, WireFormat.WireType.StartGroup), input.ReadTag());
            input.SkipLastField(); // Should consume the whole group, including the nested one.
            Assert.AreEqual(WireFormat.MakeTag(3, WireFormat.WireType.LengthDelimited), input.ReadTag());
            Assert.AreEqual("field 3", input.ReadString());
        }
Ejemplo n.º 2
0
                public void MergeFrom(CodedInputStream input)
                {
                    while (true)
                    {
IL_D9:
                        uint num;
                        uint arg_9E_0 = ((num = input.ReadTag()) != 0u) ? 123760098u : 340881777u;
                        while (true)
                        {
                            uint num2;
                            switch ((num2 = (arg_9E_0 ^ 2069247364u)) % 8u)
                            {
                            case 0u:
                                input.SkipLastField();
                                arg_9E_0 = (num2 * 3109966835u ^ 1634015013u);
                                continue;

                            case 1u:
                                goto IL_D9;

                            case 2u:
                                this.End = input.ReadInt32();
                                arg_9E_0 = 651504541u;
                                continue;

                            case 3u:
                                this.Start = input.ReadInt32();
                                arg_9E_0   = 651504541u;
                                continue;

                            case 4u:
                                arg_9E_0 = (((num == 16u) ? 3653100894u : 3502071340u) ^ num2 * 176730384u);
                                continue;

                            case 6u:
                                arg_9E_0 = ((num != 8u) ? 730284952u : 1349205327u);
                                continue;

                            case 7u:
                                arg_9E_0 = 123760098u;
                                continue;
                            }
                            return;
                        }
                    }
                }
Ejemplo n.º 3
0
 /// <summary>
 /// Create a new UnknownFieldSet if unknownFields is null.
 /// Parse a single field from <paramref name="input"/> and merge it
 /// into unknownFields. If <paramref name="input"/> is configured to discard unknown fields,
 /// <paramref name="unknownFields"/> will be returned as-is and the field will be skipped.
 /// </summary>
 /// <param name="unknownFields">The UnknownFieldSet which need to be merged</param>
 /// <param name="input">The coded input stream containing the field</param>
 /// <returns>The merged UnknownFieldSet</returns>
 public static UnknownFieldSet MergeFieldFrom(UnknownFieldSet unknownFields,
                                              CodedInputStream input)
 {
     if (input.DiscardUnknownFields)
     {
         input.SkipLastField();
         return(unknownFields);
     }
     if (unknownFields == null)
     {
         unknownFields = new UnknownFieldSet();
     }
     if (!unknownFields.MergeFieldFrom(input))
     {
         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);
 }
        public void EndOfStreamReachedWhileSkippingGroup()
        {
            var stream = new MemoryStream();
            var output = new CodedOutputStream(stream);

            output.WriteTag(1, WireFormat.WireType.StartGroup);
            output.WriteTag(2, WireFormat.WireType.StartGroup);
            output.WriteTag(2, WireFormat.WireType.EndGroup);

            output.Flush();
            stream.Position = 0;

            // Now act like a generated client
            var input = new CodedInputStream(stream);

            input.ReadTag();
            Assert.Throws <InvalidProtocolBufferException>(() => input.SkipLastField());
        }
        public void RecursionLimitAppliedWhileSkippingGroup()
        {
            var stream = new MemoryStream();
            var output = new CodedOutputStream(stream);

            for (int i = 0; i < CodedInputStream.DefaultRecursionLimit + 1; i++)
            {
                output.WriteTag(1, WireFormat.WireType.StartGroup);
            }
            for (int i = 0; i < CodedInputStream.DefaultRecursionLimit + 1; i++)
            {
                output.WriteTag(1, WireFormat.WireType.EndGroup);
            }
            output.Flush();
            stream.Position = 0;

            // Now act like a generated client
            var input = new CodedInputStream(stream);

            Assert.AreEqual(WireFormat.MakeTag(1, WireFormat.WireType.StartGroup), input.ReadTag());
            Assert.Throws <InvalidProtocolBufferException>(() => input.SkipLastField());
        }
Ejemplo n.º 6
0
            internal static T Read <T>(CodedInputStream input, FieldCodec <T> codec)
            {
                int length   = input.ReadLength();
                int oldLimit = input.PushLimit(length);

                uint tag;
                T    value = codec.DefaultValue;

                while ((tag = input.ReadTag()) != 0)
                {
                    if (tag == codec.Tag)
                    {
                        value = codec.Read(input);
                    }
                    else
                    {
                        input.SkipLastField();
                    }
                }
                input.CheckReadEndOfStreamTag();
                input.PopLimit(oldLimit);

                return(value);
            }
Ejemplo n.º 7
0
        public void SkipGroup()
        {
            // Create an output stream with a group in:
            // Field 1: string "field 1"
            // Field 2: group containing:
            //   Field 1: fixed int32 value 100
            //   Field 2: string "ignore me"
            //   Field 3: nested group containing
            //      Field 1: fixed int64 value 1000
            // Field 3: string "field 3"
            var stream = new MemoryStream();
            var output = new CodedOutputStream(stream);
            output.WriteTag(1, WireFormat.WireType.LengthDelimited);
            output.WriteString("field 1");

            // The outer group...
            output.WriteTag(2, WireFormat.WireType.StartGroup);
            output.WriteTag(1, WireFormat.WireType.Fixed32);
            output.WriteFixed32(100);
            output.WriteTag(2, WireFormat.WireType.LengthDelimited);
            output.WriteString("ignore me");
            // The nested group...
            output.WriteTag(3, WireFormat.WireType.StartGroup);
            output.WriteTag(1, WireFormat.WireType.Fixed64);
            output.WriteFixed64(1000);
            // Note: Not sure the field number is relevant for end group...
            output.WriteTag(3, WireFormat.WireType.EndGroup);

            // End the outer group
            output.WriteTag(2, WireFormat.WireType.EndGroup);

            output.WriteTag(3, WireFormat.WireType.LengthDelimited);
            output.WriteString("field 3");
            output.Flush();
            stream.Position = 0;

            // Now act like a generated client
            var input = new CodedInputStream(stream);
            Assert.AreEqual(WireFormat.MakeTag(1, WireFormat.WireType.LengthDelimited), input.ReadTag());
            Assert.AreEqual("field 1", input.ReadString());
            Assert.AreEqual(WireFormat.MakeTag(2, WireFormat.WireType.StartGroup), input.ReadTag());
            input.SkipLastField(); // Should consume the whole group, including the nested one.
            Assert.AreEqual(WireFormat.MakeTag(3, WireFormat.WireType.LengthDelimited), input.ReadTag());
            Assert.AreEqual("field 3", input.ReadString());
        }
Ejemplo n.º 8
0
        public void EndOfStreamReachedWhileSkippingGroup()
        {
            var stream = new MemoryStream();
            var output = new CodedOutputStream(stream);
            output.WriteTag(1, WireFormat.WireType.StartGroup);
            output.WriteTag(2, WireFormat.WireType.StartGroup);
            output.WriteTag(2, WireFormat.WireType.EndGroup);

            output.Flush();
            stream.Position = 0;

            // Now act like a generated client
            var input = new CodedInputStream(stream);
            input.ReadTag();
            Assert.Throws<InvalidProtocolBufferException>(() => input.SkipLastField());
        }
Ejemplo n.º 9
0
        public void RecursionLimitAppliedWhileSkippingGroup()
        {
            var stream = new MemoryStream();
            var output = new CodedOutputStream(stream);
            for (int i = 0; i < CodedInputStream.DefaultRecursionLimit + 1; i++)
            {
                output.WriteTag(1, WireFormat.WireType.StartGroup);
            }
            for (int i = 0; i < CodedInputStream.DefaultRecursionLimit + 1; i++)
            {
                output.WriteTag(1, WireFormat.WireType.EndGroup);
            }
            output.Flush();
            stream.Position = 0;

            // Now act like a generated client
            var input = new CodedInputStream(stream);
            Assert.AreEqual(WireFormat.MakeTag(1, WireFormat.WireType.StartGroup), input.ReadTag());
            Assert.Throws<InvalidProtocolBufferException>(() => input.SkipLastField());
        }
Ejemplo n.º 10
0
            internal static T Read <T>(CodedInputStream input, FieldCodec <T> codec)
            {
                int byteLimit = input.ReadLength();
                T   result;

                while (true)
                {
IL_FA:
                    uint arg_C8_0 = 1476935752u;
                    while (true)
                    {
                        uint num;
                        switch ((num = (arg_C8_0 ^ 2018772964u)) % 9u)
                        {
                        case 0u:
                            input.SkipLastField();
                            arg_C8_0 = 1768391466u;
                            continue;

                        case 1u:
                        {
                            uint num2;
                            arg_C8_0 = (((num2 = input.ReadTag()) == 0u) ? 789788880u : 1000495088u);
                            continue;
                        }

                        case 3u:
                            arg_C8_0 = (num * 422428889u ^ 15908708u);
                            continue;

                        case 4u:
                            result   = codec.Read(input);
                            arg_C8_0 = (num * 2015424451u ^ 1456283564u);
                            continue;

                        case 5u:
                        {
                            uint num2;
                            arg_C8_0 = ((num2 == codec.Tag) ? 627669222u : 345821031u);
                            continue;
                        }

                        case 6u:
                        {
                            input.CheckReadEndOfStreamTag();
                            int oldLimit;
                            input.PopLimit(oldLimit);
                            arg_C8_0 = (num * 1368242210u ^ 1133084529u);
                            continue;
                        }

                        case 7u:
                        {
                            int oldLimit = input.PushLimit(byteLimit);
                            result   = codec.DefaultValue;
                            arg_C8_0 = (num * 2466023856u ^ 3651674u);
                            continue;
                        }

                        case 8u:
                            goto IL_FA;
                        }
                        return(result);
                    }
                }
                return(result);
            }
Ejemplo n.º 11
0
                public void MergeFrom(CodedInputStream input)
                {
                    while (true)
                    {
IL_22B:
                        uint num;
                        uint arg_1C7_0 = ((num = input.ReadTag()) != 0u) ? 3338900507u : 3490427704u;
                        while (true)
                        {
                            uint num2;
                            switch ((num2 = (arg_1C7_0 ^ 3575757851u)) % 18u)
                            {
                            case 0u:
                                arg_1C7_0 = (num2 * 4161478824u ^ 2103420624u);
                                continue;

                            case 1u:
                                this.path_.AddEntriesFrom(input, SourceCodeInfo.Types.Location._repeated_path_codec);
                                arg_1C7_0 = 2227857680u;
                                continue;

                            case 2u:
                                arg_1C7_0 = ((num <= 16u) ? 2859386605u : 4283208004u);
                                continue;

                            case 3u:
                                arg_1C7_0 = (((num != 34u) ? 1520889365u : 1267782305u) ^ num2 * 2173165572u);
                                continue;

                            case 4u:
                                this.TrailingComments = input.ReadString();
                                arg_1C7_0             = 2227857680u;
                                continue;

                            case 5u:
                                arg_1C7_0 = 3338900507u;
                                continue;

                            case 6u:
                                arg_1C7_0 = (num2 * 2358789655u ^ 2159803823u);
                                continue;

                            case 8u:
                                input.SkipLastField();
                                arg_1C7_0 = 2183611349u;
                                continue;

                            case 9u:
                                arg_1C7_0 = ((num == 18u) ? 2447739934u : 2669850999u);
                                continue;

                            case 10u:
                                arg_1C7_0 = (((num != 8u) ? 3280687541u : 3841024010u) ^ num2 * 3329312757u);
                                continue;

                            case 11u:
                                this.LeadingComments = input.ReadString();
                                arg_1C7_0            = 2227857680u;
                                continue;

                            case 12u:
                                arg_1C7_0 = (((num != 26u) ? 3138895318u : 3479952318u) ^ num2 * 1481422129u);
                                continue;

                            case 13u:
                                arg_1C7_0 = (((num != 16u) ? 278902393u : 1407783438u) ^ num2 * 615822576u);
                                continue;

                            case 14u:
                                arg_1C7_0 = (num2 * 255842685u ^ 4130925702u);
                                continue;

                            case 15u:
                                goto IL_22B;

                            case 16u:
                                arg_1C7_0 = (((num != 10u) ? 1246054996u : 1063320292u) ^ num2 * 84701410u);
                                continue;

                            case 17u:
                                this.span_.AddEntriesFrom(input, SourceCodeInfo.Types.Location._repeated_span_codec);
                                arg_1C7_0 = 3200795651u;
                                continue;
                            }
                            return;
                        }
                    }
                }