diff --git a/src/google/protobuf/decoding.d b/src/google/protobuf/decoding.d index 9eb7cbe..a085cc8 100644 --- a/src/google/protobuf/decoding.d +++ b/src/google/protobuf/decoding.d @@ -229,6 +229,32 @@ unittest assert(buff.empty); } +unittest +{ + import std.array : array; + import std.typecons : Yes; + + import google.protobuf.encoding : toProtobuf; + + struct Foo + { + @Proto(1) int[] bar = protoDefaultValue!(int[]); + @Proto(2, Wire.none, Yes.packed) int[] baz = protoDefaultValue!(int[]); + } + + Foo foo; + foo.bar = [1, 2]; + foo.baz = [3, 4]; + auto buff = foo.toProtobuf.array; + + foo = Foo.init; + assert(foo.bar.empty); + assert(foo.baz.empty); + foo = buff.fromProtobuf!Foo; + assert(foo.bar == [1, 2]); + assert(foo.baz == [3, 4]); +} + private static void fromProtobufByField(alias field, T, R)(ref R inputRange, ref T message) if (isInputRange!R) { diff --git a/src/google/protobuf/encoding.d b/src/google/protobuf/encoding.d index a2822c5..04ac4ce 100644 --- a/src/google/protobuf/encoding.d +++ b/src/google/protobuf/encoding.d @@ -205,6 +205,24 @@ unittest assert(emptyMessage.toProtobuf.empty); } +unittest +{ + import std.array : array; + import std.typecons : Yes; + + struct Foo + { + @Proto(1) int[] bar = protoDefaultValue!(int[]); + @Proto(2, Wire.none, Yes.packed) int[] baz = protoDefaultValue!(int[]); + } + + Foo foo; + assert(foo.toProtobuf.empty); + foo.bar = [1, 2]; + foo.baz = [3, 4]; + assert(foo.toProtobuf.array == [0x08, 0x01, 0x08, 0x02, 0x12, 0x02, 0x03, 0x04]); +} + unittest { struct Foo