protoc-c/c_field.cc: Fix proto3 field packing #330

Fixes #330 and makes scalar repeated fields packed by default in proto3.

https://developers.google.com/protocol-buffers/docs/encoding#packed:
In proto3, repeated fields of scalar numeric types are packed by
default.
This commit is contained in:
Ilya Lipnitskiy 2019-05-17 13:17:58 -07:00
parent 6aa7dc7a10
commit 69c39824cf

View File

@ -140,8 +140,14 @@ void FieldGenerator::GenerateDescriptorInitializerGeneric(io::Printer* printer,
if (descriptor_->label() == FieldDescriptor::LABEL_REPEATED
&& is_packable_type (descriptor_->type())
&& descriptor_->options().packed())
&& descriptor_->options().packed()) {
variables["flags"] += " | PROTOBUF_C_FIELD_FLAG_PACKED";
} else if (descriptor_->label() == FieldDescriptor::LABEL_REPEATED
&& is_packable_type (descriptor_->type())
&& FieldSyntax(descriptor_) == 3
&& !descriptor_->options().has_packed()) {
variables["flags"] += " | PROTOBUF_C_FIELD_FLAG_PACKED";
}
if (descriptor_->options().deprecated())
variables["flags"] += " | PROTOBUF_C_FIELD_FLAG_DEPRECATED";