public void RoundTrip_Maps() { var message = new TestMap { MapBoolBool = { { false, true }, { true, false } }, MapInt32Bytes = { { 5, ByteString.CopyFrom(6, 7, 8) }, { 25, ByteString.CopyFrom(1, 2,3, 4, 5) }, { 10, ByteString.Empty } }, MapInt32ForeignMessage = { { 0, new ForeignMessage { C = 10 } }, { 5, new ForeignMessage() }, }, MapInt32Enum = { { 1, MapEnum.MAP_ENUM_BAR }, { 2000, MapEnum.MAP_ENUM_FOO } } }; byte[] bytes = message.ToByteArray(); TestMap parsed = TestMap.Parser.ParseFrom(bytes); Assert.AreEqual(message, parsed); }
public void RoundTrip_Maps() { var message = new TestMap { MapBoolBool = { { false, true }, { true, false } }, MapInt32Bytes = { { 5, ByteString.CopyFrom(6, 7, 8) }, { 25, ByteString.CopyFrom(1, 2,3, 4, 5) }, { 10, ByteString.Empty } }, MapInt32ForeignMessage = { { 0, new ForeignMessage { C = 10 } }, { 5, new ForeignMessage() }, }, MapInt32Enum = { { 1, MapEnum.Bar }, { 2000, MapEnum.Foo } } }; byte[] bytes = message.ToByteArray(); MessageParsingHelpers.AssertRoundtrip(TestMap.Parser, message); }
public void MapWithEmptyEntry() { var message = new TestMap { MapInt32Bytes = { { 0, ByteString.Empty } } }; byte[] bytes = message.ToByteArray(); Assert.AreEqual(2, bytes.Length); // Tag for field entry (1 byte), length of entry (0; 1 byte) var parsed = TestMap.Parser.ParseFrom(bytes); Assert.AreEqual(1, parsed.MapInt32Bytes.Count); Assert.AreEqual(ByteString.Empty, parsed.MapInt32Bytes[0]); }
public void MapWithEmptyEntry() { var message = new TestMap { MapInt32Bytes = { { 0, ByteString.Empty } } }; byte[] bytes = message.ToByteArray(); Assert.AreEqual(2, bytes.Length); // Tag for field entry (1 byte), length of entry (0; 1 byte) MessageParsingHelpers.AssertReadingMessage( TestMap.Parser, bytes, parsed => { Assert.AreEqual(1, parsed.MapInt32Bytes.Count); Assert.AreEqual(ByteString.Empty, parsed.MapInt32Bytes[0]); }); }
public void RoundTrip_Maps() { var message = new TestMap { MapBoolBool = { { false, true }, { true, false } }, MapInt32Bytes = { { 5, ByteString.CopyFrom(6, 7, 8) }, { 25, ByteString.CopyFrom(1, 2, 3, 4, 5) }, { 10, ByteString.Empty } }, MapInt32ForeignMessage = { { 0, new ForeignMessage { C = 10 } }, { 5, null }, }, MapInt32Enum = { { 1, MapEnum.MAP_ENUM_BAR }, { 2000, MapEnum.MAP_ENUM_FOO } } }; byte[] bytes = message.ToByteArray(); TestMap parsed = TestMap.Parser.ParseFrom(bytes); Assert.AreEqual(message, parsed); }