1

I am trying to create a message with a repeated field which has some default values. I'm starting slow, with a simple int repeated (my final goal is a repeated message which all fields are have some value default)

so, to start my proto is:

syntax = "proto2"
import "google/protobuf/descriptor.proto";
import "nanopb.proto";

message MyDefault {
  repeated int32 default = 1 [(nanopb).max_count = 3];
}

extend google.protobuf.FieldOptions {
  optional MyDefault my_default = 1234;
}

message M {
  repeated int32 x = 1 [(my_default) = {default: [1, 2, 3]}, (nanopb).max_count = 3];
}

protobuf is compiled, but no trace to my default values.

me and stuff
  • 195
  • 1
  • 5
  • 12
  • Are you using Proto2 or Proto3? Can you add this to your example? From the usage of optinal I assume you are using Proto2. That is good as in Proto3 default values are not supported, they are always set to zero or false. – Bart Feb 16 '20 at 09:23
  • yes, I'm using proto2 since 3 doesn't support default, as you mentioned... (will add to my question) – me and stuff Feb 16 '20 at 09:28
  • I've searched through the documentation and unit tests of nanopb but at this moment I can not find an awnser. – Bart Feb 16 '20 at 09:51

1 Answers1

0

There are no default values for repeated fields in nanopb currently. As far as I know, they don't exist in other protobuf implementations either.

Some other protobuf libraries do provide access to custom field options, but nanopb currently does not.

jpa
  • 10,351
  • 1
  • 28
  • 45