protobuf.js version: 7.1.2
We are parsing a .proto file in proto3 format with protobufjs.loadSync. Using the resulting parsed objects, we need to distinguish between a field that is marked optional vs. a field that is not marked optional and also not marked required. Unfortunately, the protobufjs parser always sets Field.optional to the value of !Field.required, so we can't detect the optional keyword in the parsed Field object.
We use the Golang protobuf library with the same .proto file (in proto3 format) which generates different Golang code for fields marked optional, vs. fields not marked as either optional or required. We need to use the protobufjs parser in a similar way.
For example, we would like to detect the difference between the parsed field1 and field2 objects in this .proto file:
syntax = "proto3";
message Message1 {
string field1 = 1;
optional string field2 = 2;
}
protobuf.js version: 7.1.2
We are parsing a
.protofile inproto3format withprotobufjs.loadSync. Using the resulting parsed objects, we need to distinguish between a field that is markedoptionalvs. a field that is not markedoptionaland also not markedrequired. Unfortunately, the protobufjs parser always setsField.optionalto the value of!Field.required, so we can't detect theoptionalkeyword in the parsedFieldobject.We use the Golang protobuf library with the same
.protofile (inproto3format) which generates different Golang code for fields markedoptional, vs. fields not marked as eitheroptionalorrequired. We need to use the protobufjs parser in a similar way.For example, we would like to detect the difference between the parsed
field1andfield2objects in this.protofile: