protobuf.js
protobuf.js copied to clipboard
Is the example rpcImpl in the README.md correct?
The example given is:
const rpcImpl = function(method, requestData, callback) {
client.makeUnaryRequest(
method.name,
arg => arg,
arg => arg,
requestData,
callback
)
}
That gives a method call to the path "SayHello" which won't actually work against the helloworld example server - it needs to include the namespace and service in the path: "/helloworld.Greeter/SayHello".
The below seems to work for me:
const rpcImpl = function (method, requestData, callback) {
const service = method.parent, namespace = service.parent;
client.makeUnaryRequest(
"/" + namespace.name + "." + service.name + "/" + method.name,
arg => arg,
arg => arg,
requestData,
callback
)
}
I spent about a day's worth of work before figuring this out on my own. I searched here to find that I'm not the only one. Is this the correct way? If so, we should update the example.
method.parent do not exist anymore. I had to hardcode for now.
@longility `package parentName;
syntax = "proto3";`
if you will use this in your proto file then you will get method.parent
I do have that @Mohammad-Khalid23 . I'm generating my code like this, which works, but maybe I'm missing something:
pbjs -t static-module -w commonjs -o src/junk-domain/__grpc-stubs__/profile.js ../profile/*.Api/Protos/*.proto
pbts -o src/junk-domain/__grpc-stubs__/profile.d.ts src/junk-domain/__grpc-stubs__/profile.js
I followed this: https://www.npmjs.com/package/protobufjs#pbts-for-typescript
Yeah, I ran into this today as well. I don't have any parent value either. Assuming that there are indeed some cases where that parent value isn't present, isn't this an actual problem with the library, rather than just with the example? Or is the intended usage pattern to capture the namespace & service class in the RPC implementation? That would seem a bit odd to me, given that the name is passed in already.
I have the same problem. Is it resolved?
Correct, this example is no longer accurate. Even the gRPC library is updated and now has more fields on makeUnaryRequest.
For f’s sake, since 2021 nobody updated the docs nor solved this issue. Do we really have to manually hack our paths in the fng call, or there is another ticket hidden from the internet that explains how it’s supposed to be used in 2024?