Skip to content

Commit

Permalink
Default to packed repeated primitive fields in proto3.
Browse files Browse the repository at this point in the history
Fixes stepancheg#704.

In proto3, repeated primitive fields should be packed by default:
https://protobuf.dev/programming-guides/encoding/#packed
  • Loading branch information
rcorre committed Jan 16, 2024
1 parent 0d2dbd8 commit 98b15a7
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion protobuf-codegen/src/gen/field/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,16 @@ impl<'a> FieldGen<'a> {

FieldKind::Repeated(RepeatedField {
elem,
packed: field.field.proto().options.get_or_default().packed(),
packed: field
.field
.proto()
.options
.get_or_default()
.packed
.unwrap_or(match field.message.scope.file_scope.syntax() {
Syntax::Proto2 => false,
Syntax::Proto3 => true,
}),
})
}
RuntimeFieldType::Singular(..) => {
Expand Down

0 comments on commit 98b15a7

Please sign in to comment.