-
Notifications
You must be signed in to change notification settings - Fork 68
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Consider providing a convenient accessor for custom options from Desc* types #701
Comments
It is correct that For example, a Protobuf enum is described by the message message EnumDescriptorProto {
// ...
optional EnumOptions options = 3;
// ...
} If you define an enum option, you extend You can retrieve the option value again from this message field. Here is how you would do it for an enum: declare const descEnum: DescEnum;
if (descEnum.proto.options && hasExtension(descEnum.proto.options, my_option)) {
const myOption = getExtension(descEnum.proto.options, my_option);
// ... We have a full tutorial here, which also links to a runnable example.
|
getExtension
doesn't work with enums.
I use protobuf-es not only with the generated types but also with const descriptorSet = createDescriptorSet(/* read this file... */);
for (const [name, descriptor] of descriptorSet.messages) {
if (findCustomScalarOption(descriptor, /* magic number */ 1234567, ScalarType.BOOL)) {
// Do something with the message which has a specified option
}
} It would be better that to keep |
This is implemented for V2 in #828 |
It looks like
getExtension
could only be used on Message instance but not Descriptors asfindCustomScalarOption
used to do.What if I want to get the options without creating a new instance but only with the Descriptors, such as get options from an enum?
It would be better if these extension related interfaces could be used with Types, aka Descriptors, instead of instances.
The text was updated successfully, but these errors were encountered: