I want to add string array in protocol buffer message, which I am not able to do. I have written as below
repeated string data = 1[packed=true];
I got the below error:
[packed = true] can only be specified for repeated primitive fields.
I could able to do it for int arrays with same syntax. I am confused why the string is considered as non-primitive type. Can anyone help me please.? Thanks !!
The Protobuf serialization mechanism is given through the protoc application, this compiler will parse the . proto file and will generate as output, source files according to the configured language by its arguments, in this case, C++. You can also obtain more information about, reading the section compiler invocation.
Protocol buffers messages always use little-endian encoding. Implementations running on big-endian architectures should be doing the conversions automatically. If you are receiving data in wrong order, I would suggest using protoc --decode_raw to see whether the error occurs on the transmission or reception side.
Using proto2 Message TypesIt's possible to import proto2 message types and use them in your proto3 messages, and vice versa. However, proto2 enums cannot be used directly in proto3 syntax (it's okay if an imported proto2 message uses them).
Proto3 is the latest version of Protocol Buffers and includes the following changes from proto2: Field presence, also known as hasField , is removed by default for primitive fields. An unset primitive field has a language-defined default value.
Refer to the section "Specifying Field Rules" of the the Protobuf Documentation. Essentially, packing only makes sense for numeric fields.
Preserving a quote for prosperity:
For historical reasons, repeated fields of basic numeric types aren't encoded as efficiently as they could be. New code should use the special option [packed=true] to get a more efficient encoding.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With