-
Notifications
You must be signed in to change notification settings - Fork 71
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
Provide custom options at runtime #397
Comments
enum, enum fields, messages, message fields, and files can also have options, but I'd agree that service and rpc are some of the most interesting ones. We've punted on this feature so far because some users don't want to ship their options in a bundle, so this can become complicated. Can I ask what you want to use it for? |
we use our custom options for various needs.
and then there are google http annotations which we also use. |
Also backtracking reference (from I'm trying to migrate gradually to |
Thanks for the info @hugebdu. Appreciate the input and this is definitely something we have on our minds. As @timostamm mentioned though, it becomes complicated with some users who don't want their option values shipped as part of the bundle. So, making both camps happy is tricky and probably involves some sort of plugin option. It's something we'd like to think through and get right, so I don't see us implementing this anytime soon but it's on our radar. In the meantime, though, you could implement your own plugin using Protobuf-ES' plugin framework. Custom options are available to you during code generation time (docs). Maybe that solution would work for you? |
@smaye81 I have a workaround for now - I generate a binary descriptor as well and use it at runtime for all the option-bound logic. Thanks |
Protocol Buffers v22.0 adds the feature option retention. This could potentially help us here to control which options should be included in generated code. |
Is there any easy generic way to convert custom options to JSON (as appears in 10x |
@hugebdu, support for extensions was just released in v1.7.0, making this very feasible. Assuming you have a binary import { createDescriptorSet, createRegistryFromDescriptors } from "@bufbuild/protobuf";
import { readFileSync } from "node:fs";
const set = createDescriptorSet(readFileSync("./set.binpb"));
const reg = createRegistryFromDescriptors(set);
for (const file of set.files) {
for (const service of file.services) {
for (const method of service.methods) {
const options = method.proto.options;
if (!options) {
continue;
}
const json = options.toJsonString({ typeRegistry: reg, prettySpaces: 2 });
console.log(`Options on ${method}: ${json}`);
}
}
} For the test data from protobuf-ts, the output is:
As you can see, the field We'll provide a mechanism to retrieve custom options at runtime as well. We'll keep this issue updated. |
@timostamm king! 👑 |
This is up next for us. I've update the title of this issue to better reflect that we intend to support (custom) options at runtime for all Protobuf types. |
This is implemented in version 2 with the functions |
@protobuf-ts/runtime-rpc/reflection-info#MethodInfo
hasoptions
.Any plans to have it in
protobuf-es
as well?Same applies to
ServiceInfo
Thanks
The text was updated successfully, but these errors were encountered: