diff --git a/protoc_gen_d/protoc-gen-d.d b/protoc_gen_d/protoc-gen-d.d index 42c83b2..afdde39 100644 --- a/protoc_gen_d/protoc-gen-d.d +++ b/protoc_gen_d/protoc-gen-d.d @@ -379,7 +379,15 @@ class CodeGenerator import std.conv : to; import std.range : join; - return [field.number.to!string, wireByField(field).toString].stripRight("").stripRight("Wire.none").join(", "); + static string packedByField(FieldDescriptorProto field) + { + return (field.options && field.options.packed) ? "Yes.packed" : "No.packed"; + } + + return [field.number.to!string, wireByField(field).toString, packedByField(field)] + .stripRight("No.packed") + .stripRight("Wire.none") + .join(", "); } private string fieldInitializer(FieldDescriptorProto field) diff --git a/src/google/protobuf/common.d b/src/google/protobuf/common.d index 5a5c791..7cb8b05 100644 --- a/src/google/protobuf/common.d +++ b/src/google/protobuf/common.d @@ -1,5 +1,10 @@ module google.protobuf.common; +static import std.typecons; + +alias No = std.typecons.No; +alias Yes = std.typecons.Yes; + alias bytes = ubyte[]; auto protoDefaultValue(T)() diff --git a/test/generated_code.d b/test/generated_code.d index 70c5f2a..a26828b 100644 --- a/test/generated_code.d +++ b/test/generated_code.d @@ -134,6 +134,16 @@ class ForeignMessage @Proto(1) int c = protoDefaultValue!int; } +class PackedRepeated +{ + @Proto(1) int[] defaultPackedInts = protoDefaultValue!(int[]); + @Proto(2, Wire.none, Yes.packed) int[] packedInts = protoDefaultValue!(int[]); + @Proto(3) int[] nonPackedInts = protoDefaultValue!(int[]); + @Proto(4) bool[] defaultPackedBools = protoDefaultValue!(bool[]); + @Proto(5, Wire.none, Yes.packed) bool[] packedBools = protoDefaultValue!(bool[]); + @Proto(6) bool[] nonPackedBools = protoDefaultValue!(bool[]); +} + enum ForeignEnum { FOREIGN_FOO = 0, diff --git a/test/generated_code.proto b/test/generated_code.proto index be6a879..dd22f33 100644 --- a/test/generated_code.proto +++ b/test/generated_code.proto @@ -122,3 +122,13 @@ enum ForeignEnum { FOREIGN_BAR = 1; FOREIGN_BAZ = 2; } + +message PackedRepeated { + repeated int32 defaultPackedInts = 1; + repeated int32 packedInts = 2 [packed=true]; + repeated int32 nonPackedInts = 3 [packed=false]; + + repeated bool defaultPackedBools = 4; + repeated bool packedBools = 5 [packed=true]; + repeated bool nonPackedBools = 6 [packed=false]; +}