コード例 #1
0
        public void MapWithOnlyValue()
        {
            // Hand-craft the stream to contain a single entry with just a value.
            var memoryStream = new MemoryStream();
            var output       = new CodedOutputStream(memoryStream);

            output.WriteTag(TestMap.MapInt32ForeignMessageFieldNumber, WireFormat.WireType.LengthDelimited);
            var nestedMessage = new ForeignMessage {
                C = 20
            };

            // Size of the entry (tag, size written by WriteMessage, data written by WriteMessage)
            output.WriteLength(2 + nestedMessage.CalculateSize());
            output.WriteTag(2, WireFormat.WireType.LengthDelimited);
            output.WriteMessage(nestedMessage);
            output.Flush();

            MessageParsingHelpers.AssertReadingMessage(
                TestMap.Parser,
                memoryStream.ToArray(),
                parsed =>
            {
                Assert.AreEqual(nestedMessage, parsed.MapInt32ForeignMessage[0]);
            });
        }
コード例 #2
0
        public void MapWithOnlyValue()
        {
            // Hand-craft the stream to contain a single entry with just a value.
            var memoryStream = new MemoryStream();
            var output       = CodedOutputStream.CreateInstance(memoryStream);

            output.WriteTag(TestMap.MapInt32ForeignMessageFieldNumber, WireFormat.WireType.LengthDelimited);
            var nestedMessage = new ForeignMessage {
                C = 20
            };

            // Size of the entry (tag, size written by WriteMessage, data written by WriteMessage)
            output.WriteRawVarint32((uint)(nestedMessage.CalculateSize() + 3));
            output.WriteTag(2, WireFormat.WireType.LengthDelimited);
            output.WriteMessage(nestedMessage);
            output.Flush();

            var parsed = TestMap.Parser.ParseFrom(memoryStream.ToArray());

            Assert.AreEqual(nestedMessage, parsed.MapInt32ForeignMessage[0]);
        }