You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
wang-xiaowu
changed the title
if the message has an option field with a return value, the proto will attach a same name field with _ prefix. why?
if the message has an optional field with a return value, the proto will attach a same name field with _ prefix. why?
May 27, 2024
We got bit by this in our application recently where we were passing the response from a gRPC response through camelcase-keys, where when we got something like { msg: 'foo', _msg: 'msg' }, the camelcase version was { msg: 'msg' }.
While we can modify our usage of camelcase-keys, it'd be nice if the loader could just not have these _ fields as we don't view them as useful at all.
For reference, we're also using @grpc/proto-loader with the same settings as above.
OK, I see what's happening here: Protobuf.js internally represents optional fields as a single-member oneof group named as the underscore-prefixed field name. The plain object message representation includes the oneof group as a separate key to indicate which member is set because you set the oneofs option to true.
You can disable this behavior by setting the oneofs option to false.
This behavior can only be changed in Protobuf.js, so I have filed an issue there: protobufjs/protobuf.js#2037.
Problem description
if the message has an option field with a return value, the proto will attach a same name field with
_
prefix. why?Reproduction steps
server retun
real result client got
Environment
Additional context
The text was updated successfully, but these errors were encountered: