I have the following proto definition
syntax = "proto3";
message SimpleMessage {
repeated int32 lucky_numbers = 1;
}
and options file
SimpleMessage.lucky_numbers max_size:10 fixed_length:true
I run protoc with the following
protoc --plugin=protoc-gen-nanopb=nanopb/generator/protoc-gen-nanopb ./simple.proto "--nanopb_out=-v -f simple.options:."
and it correctly picks up options (don't know why it prints the same stuff twice)
Options for SimpleMessage.lucky_numbers: max_size: 10
proto3: true
fixed_length: true
Now when I check the generated simple.pb.h
, I see that
/* Struct definitions */
typedef struct _SimpleMessage {
pb_callback_t lucky_numbers;
} SimpleMessage;
I was expecting int32_t lucky_numbers[10];
as the documentation indicated. Any idea where I went wrong?
Try this:
SimpleMessage.lucky_numbers max_count:10 fixed_count:true
The length settings are for strings and bytes fields, while the count settings are for arrays. They are separate, because you can have arrays of strings and specify both options.
The documentation for the field options is here, and the most complete information is in the source code comments.
The reason for the doubled up debugging messages is that nanopb generator does a preliminary parse of all input files to collect any dependencies, and then parses the files it was asked to generate again.