Skip to content
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

createPackageDefinition without doing file I/O? #550

Closed
dckc opened this issue Sep 14, 2018 · 5 comments
Closed

createPackageDefinition without doing file I/O? #550

dckc opened this issue Sep 14, 2018 · 5 comments

Comments

@dckc
Copy link

dckc commented Sep 14, 2018

Is your feature request related to a problem? Please describe.

I have a service DeployService that uses types such as Par. I'm using Par.create() and such in one part of my app where I'm not doing any I/O, and making calls to DeployService in other parts of the app.

I can make a Protobuf.Root from the .json version of my message types that I get from pbjs. This is fine for Par.create() and such. But I don't see how to get a PackageDefinition from this root. The only option I see is loadPackageDefinition that does all the work of pbjs again, only at runtime.

Describe the solution you'd like

export createPackageDefinition.

Or at least make the Protobuf.Root available from the PackageDefinition.

Describe alternatives you've considered

I considered forking this code and adding the export declaration.

But out of expediency: I'm loading the message types twice: once for Par.create() and such, and again for gRPC calls.

Additional context

for reference, the project I'm working on is https://github.com/JoshOrndorff/RChain-API

cc @JoshOrndorff

@murgatroid99
Copy link
Member

One of the primary goals of the proto-loader library is to avoid tying the API too directly to Protobuf.js's API, because we've been burned by that before. We are looking into other solutions for exposing message reflection information in the proto-loader library output, but we never had the intention of allowing people to construct message objects using Protobuf.js APIs made available by the output of gRPC. So if you actually have to construct message objects, you should continue to load the message types separately as you are currently doing.

@dckc
Copy link
Author

dckc commented Sep 14, 2018

OK, I'll try to forget I ever knew that Protobuf.js was in there.

@dckc dckc closed this as completed Sep 14, 2018
@nicolasnoble
Copy link
Member

Also, there's no support for grpc using pbjs / pbts at the moment. See #528.

@nicolasnoble
Copy link
Member

Or in other words, if you want compile-time code generation of your proto definitions, please use protoc instead. See https://github.com/grpc/grpc/tree/master/examples/node/static_codegen

@c0b
Copy link

c0b commented Nov 30, 2018

from protobufjs/protobuf.js#1117 also in need of the createPackageDefinition to be exported as well,

I am using the dynamic_codegen but not from *.proto files, because my project's main proto file is importing many other system wide *.proto files as well, like github.com/gogo/protobuf/gogoproto/gogo.proto and others as well, it will be problematic of deploying all those plain text *.proto files, and I found that using protoc to compile into a single protoset format binary file is very handy, so using require("protobufjs/ext/descriptor") to decode from the binary protoset format, got a Protobuf.Root instance, need to call this createPackageDefinition with Root instance,

https://github.com/grpc/grpc/blob/master/examples/node/dynamic_codegen/greeter_client.js
https://github.com/dcodeIO/protobuf.js/tree/master/ext/descriptor

So far my solution is to have a copy of this compiled proto-loader/index.js code, and just export createPackageDefinition locally for my other code to use, ( because this proto-loader code is small and probably won't change often https://github.com/grpc/grpc-node/tree/master/packages/proto-loader/src )

this solution is not perfect, but works for my need; hopefully @nicoasnobble @murgatroid99 you guys can make a better solution

@lock lock bot locked as resolved and limited conversation to collaborators Feb 28, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants