简体   繁体   中英

c: default values for repeated fields with nanopb (protobuf)

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM