Esempio n. 1
0
        public void WriteTo_Message()
        {
            var message1 = new ForeignMessage {
                C = 20
            };
            var message2 = new ForeignMessage {
                C = 25
            };
            uint tag   = WireFormat.MakeTag(10, WireFormat.WireType.LengthDelimited);
            var  field = new RepeatedField <ForeignMessage> {
                message1, message2
            };
            var stream = new MemoryStream();
            var output = new CodedOutputStream(stream);

            field.WriteTo(output, FieldCodec.ForMessage(tag, ForeignMessage.Parser));
            output.Flush();
            stream.Position = 0;

            var input = new CodedInputStream(stream);

            input.AssertNextTag(tag);
            Assert.AreEqual(message1, input.ReadMessage(ForeignMessage.Parser));
            input.AssertNextTag(tag);
            Assert.AreEqual(message2, input.ReadMessage(ForeignMessage.Parser));
            Assert.IsTrue(input.IsAtEnd);
        }
Esempio n. 2
0
        public void AddEntriesFrom_Message()
        {
            var message1 = new ForeignMessage {
                C = 2000
            };
            var message2 = new ForeignMessage {
                C = -250
            };

            uint tag    = WireFormat.MakeTag(10, WireFormat.WireType.LengthDelimited);
            var  stream = new MemoryStream();
            var  output = new CodedOutputStream(stream);

            output.WriteTag(tag);
            output.WriteMessage(message1);
            output.WriteTag(tag);
            output.WriteMessage(message2);
            output.Flush();
            stream.Position = 0;

            var field = new RepeatedField <ForeignMessage>();
            var input = new CodedInputStream(stream);

            input.AssertNextTag(tag);
            field.AddEntriesFrom(input, FieldCodec.ForMessage(tag, ForeignMessage.Parser));
            CollectionAssert.AreEqual(new[] { message1, message2 }, field);
            Assert.IsTrue(input.IsAtEnd);
        }