diff options
author | Jon Skeet <jonskeet@google.com> | 2016-01-15 10:13:56 +0000 |
---|---|---|
committer | Jon Skeet <jonskeet@google.com> | 2016-01-15 10:13:56 +0000 |
commit | f262611ff65d5a5d1b4665e2d339f108ef29fcf9 (patch) | |
tree | 64f71fc6bb7351df375afdecf799ceb23ed228ee /csharp/src/Google.Protobuf.Test | |
parent | f2fe50bfc516cdab99f51fa2ca90ba0db1ef6637 (diff) | |
download | protobuf-f262611ff65d5a5d1b4665e2d339f108ef29fcf9.tar.gz protobuf-f262611ff65d5a5d1b4665e2d339f108ef29fcf9.tar.bz2 protobuf-f262611ff65d5a5d1b4665e2d339f108ef29fcf9.zip |
Fix handling of repeated wrappers
Previously we were incorrectly packing wrapper types.
This also refactors FieldCodec a bit as well, using more C# 6-ness.
Diffstat (limited to 'csharp/src/Google.Protobuf.Test')
-rw-r--r-- | csharp/src/Google.Protobuf.Test/WellKnownTypes/WrappersTest.cs | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/csharp/src/Google.Protobuf.Test/WellKnownTypes/WrappersTest.cs b/csharp/src/Google.Protobuf.Test/WellKnownTypes/WrappersTest.cs index b72ef982..a2c833fe 100644 --- a/csharp/src/Google.Protobuf.Test/WellKnownTypes/WrappersTest.cs +++ b/csharp/src/Google.Protobuf.Test/WellKnownTypes/WrappersTest.cs @@ -149,6 +149,30 @@ namespace Google.Protobuf.WellKnownTypes } [Test] + public void RepeatedWrappersBinaryFormat() + { + // At one point we accidentally used a packed format for repeated wrappers, which is wrong (and weird). + // This test is just to prove that we use the right format. + + var rawOutput = new MemoryStream(); + var output = new CodedOutputStream(rawOutput); + // Write a value of 5 + output.WriteTag(RepeatedWellKnownTypes.Int32FieldFieldNumber, WireFormat.WireType.LengthDelimited); + output.WriteLength(2); + output.WriteTag(WrappersReflection.WrapperValueFieldNumber, WireFormat.WireType.Varint); + output.WriteInt32(5); + // Write a value of 0 (empty message) + output.WriteTag(RepeatedWellKnownTypes.Int32FieldFieldNumber, WireFormat.WireType.LengthDelimited); + output.WriteLength(0); + output.Flush(); + var expectedBytes = rawOutput.ToArray(); + + var message = new RepeatedWellKnownTypes { Int32Field = { 5, 0 } }; + var actualBytes = message.ToByteArray(); + Assert.AreEqual(expectedBytes, actualBytes); + } + + [Test] public void MapWrappersSerializeDeserialize() { // Note: no null values here, as they are prohibited in map fields |