Esempio n. 1
0
            public void TestRoundTripWithTag()
            {
                var stream      = new MemoryStream();
                var codedOutput = new CodedOutputStream(stream);

                codec.WriteTagAndValue(codedOutput, sampleValue);
                codedOutput.Flush();
                stream.Position = 0;
                var codedInput = new CodedInputStream(stream);

                codedInput.AssertNextTag(codec.Tag);
                Assert.AreEqual(sampleValue, codec.Read(codedInput));
                Assert.IsTrue(codedInput.IsAtEnd);
            }
Esempio n. 2
0
        public void CodedInputStream_LimitReachedRightAfterTag()
        {
            MemoryStream ms  = new MemoryStream();
            var          cos = new CodedOutputStream(ms);

            cos.WriteTag(11, WireFormat.WireType.Varint);
            Assert.AreEqual(1, cos.Position);
            cos.WriteString("some extra padding");  // ensure is currentLimit distinct from the end of the buffer.
            cos.Flush();

            var cis = new CodedInputStream(ms.ToArray());

            cis.PushLimit(1);  // make sure we reach the limit right after reading the tag.

            // we still must read the tag correctly, even though the tag is at the very end of our limited input
            // (which is a corner case and will most likely result in an error when trying to read value of the field
            // described by this tag, but it would be a logical error not to read the tag that's actually present).
            // See https://github.com/protocolbuffers/protobuf/pull/7289
            cis.AssertNextTag(WireFormat.MakeTag(11, WireFormat.WireType.Varint));
        }