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
protobuf.js version: 6.8.7 - latest master as of raising.
I have a use case that requires decoding a descriptor that uses options. Options are implemented as extensions on the MessageOptions message type used in the Descriptor.
The issue arises when decoding a descriptor that contains:
Multiple messages that use this custom option.
The custom message type that is the value type of the option.
The extension of the MessageOptions message type by this custom message type.
The most fundamental issue is that the extension is added to a new instance of the MessageOptions message type that exists in the new Root, which isn't actually the MessageOptions being used to decode the rest of the descriptor (the one being used to decode is loaded from the descriptor.json file and is accessed via the exports property.
I tried replacing the exports used by ext/descriptor/index.js (E.g. exports.MessageOptions) with the google.protobuf namespace that was extracted from my descriptor that had the extended MessageOptions Type. This works, but requires that the field names are camelCased as the field names in the JSON used to populate the initial exports are camelCased. The default behaviour of decoding is to use the original snake_case as that's what the strings are in the descriptor.
So to reiterate - my solution is to call Root.fromDescriptor() once to get the google.protobuf Namespace that contains the extended MessageOptions and then call Root.fromDescriptor() with the google.protobuf namespace in place of the original exports to get the full descriptor contents:
protobuf.js version:
6.8.7
- latest master as of raising.I have a use case that requires decoding a descriptor that uses options. Options are implemented as extensions on the
MessageOptions
message type used in the Descriptor.The issue arises when decoding a descriptor that contains:
MessageOptions
message type by this custom message type.The most fundamental issue is that the extension is added to a new instance of the
MessageOptions
message type that exists in the newRoot
, which isn't actually theMessageOptions
being used to decode the rest of the descriptor (the one being used to decode is loaded from thedescriptor.json
file and is accessed via theexports
property.I tried replacing the
exports
used byext/descriptor/index.js
(E.g.exports.MessageOptions
) with thegoogle.protobuf
namespace that was extracted from my descriptor that had the extendedMessageOptions
Type. This works, but requires that the field names are camelCased as the field names in the JSON used to populate the initialexports
are camelCased. The default behaviour of decoding is to use the original snake_case as that's what the strings are in the descriptor.So to reiterate - my solution is to call
Root.fromDescriptor()
once to get thegoogle.protobuf
Namespace that contains the extendedMessageOptions
and then callRoot.fromDescriptor()
with thegoogle.protobuf
namespace in place of the originalexports
to get the full descriptor contents:I thought I'd describe the problem in an issue to avoid polluting the PR I've raised with a feature request.
The required code changes to
fromDescriptor
are in #1073.The text was updated successfully, but these errors were encountered: