jhump/protoreflect

Optional fields are considered oneofs?

zchenyu opened this issue · 2 comments

If I have an optional field, the fieldDescriptor.GetOneOf() seems to be non-nil with name name:"_my_field". Is this expected?

I found this: https://github.com/protocolbuffers/protobuf/blob/main/docs/implementing_proto3_presence.md

To minimize this risk we chose a descriptor representation that is semantically compatible with existing proto3 reflection. Every proto3 optional field is placed into a one-field oneof. We call this a "synthetic" oneof, as it was not present in the source .proto file.

Is there some way to distinguish between these synthetic oneofs vs real ones? Basically I'm trying to loop over all FieldDescriptors in a MessageDescriptor, ignoring ones that are part of a oneof.