isPacked property
bool
get
isPacked
Whether a numeric field is repeated and must be encoded with packed encoding.
In proto3 repeated fields are encoded as packed by default. proto2
requires [packed=true]
option.
Implementation
bool get isPacked {
if (!isRepeated) {
return false; // only repeated fields can be packed
}
if (!baseType.isPackable) {
return false;
}
switch (parent.fileGen!.syntax) {
case ProtoSyntax.proto3:
if (!descriptor.hasOptions()) {
return true; // packed by default in proto3
} else {
return !descriptor.options.hasPacked() || descriptor.options.packed;
}
case ProtoSyntax.proto2:
if (!descriptor.hasOptions()) {
return false; // not packed by default in proto3
} else {
return descriptor.options.packed;
}
}
}