Protobuf.js: RPC server code example?

Created on 3 Apr 2017  路  5Comments  路  Source: protobufjs/protobuf.js

protobuf.js version: 6.6.5

Hello. I'm writing a protobuf RPC service, and client code that uses it. I read all through the documentation and examples, and what I am not seeing is: a server-side code example of an RPC server. Could someone show one, or say the reason why you don't believe there should be one shown?

I see example code, with no text near it saying whether it is meant to be a client-side example or a server-side example. Shouldn't you say that by each example? Without it being explicitly labeled, it isn't clear what code is meant to be run where, since Protobuf.js can run in Node and also in a web browser. I have concluded that some of the RPC code examples are meant to be client-side, but I haven't found any examples that are clearly server-side code, so I don't know whether Protobuf.js is meant to implement both sides of the RPC or not. In fact, the documentation doesn't mention that either (shouldn't it?).

Thanks in advance!

enhancement question

Most helpful comment

I agree that there should be no implementation in protobufjs for an RPC server. The whole reason we're attempting to use this project is that it's hands off on the transport mechanism and is just a mature encoding/decoding library with TS support.

That being said, there should be enough in the documentation to give hints at how to implement a server. For instance, how to read a protobuf body (binary or JSON) and determine what the message is, if it's an RPC request, what method, etc.

All 5 comments

You are right, there is neither specific server-side code nor documentation currently. It is intentional, though, that the library does not make any assumptions about the actual transport channel.

Also note that such a transport channel differs significantly on the server because the server does not just send and receive messages like a client but actually processes requests.

For example, if your server is based on http requests, it'd require an http library and probably some sort of routing. The routing then defines which message type is used to decode received data, then executing specific logic and encoding a response.

Nonetheless, there are server-side RPC implementations provided for specific use cases or libraries afaik, for example one using express (seems to be a bit outdated though).

Thanks for the quick reply. The express-protobuf code is an example of code that does something similar to what I'm trying to do (protobuf RPC over express), so thanks for that. It is, however, an undocumented, terse, hard to follow example. I am starting to understand it.

Even if it is intentional that Protobuf.js does not make assumptions about the transport channel, it would make the example code on your project's page much clearer if you add / modify these things in the docs:

  • State in a paragraph that Protobuf.js's code is meant to implement both the client and server side of the RPC implementation. Without this the user can only wonder whether you meant to offer code for implementing the server side (it is currently only clear that you are offering client side code).
  • Write by each code example that the following code is the same on both the client and the server side of RPC. (Even better would be to show two snippets: one that you label as the client, making a request and handling the response, and a second one that you label as the server, where it is receiving the request and doing a one liner of processing on it to generate and send a response. Without stating which it is, the user may think an example is for the client when it's for the server, and vice versa. Or, may think that it is client side only when it isn't.
  • Have one example, on your page, somewhere, showing a runnable example of a server that implements an RPC service. At least then it would be clear and explicit how even one example works to connect up a transport. It would be fine to use express for this because it is simple, and because most people will likely want to use express. Without this, the user has zero examples of how that is meant to work.

Closing this issue for now as it hasn't received any replies recently. Feel free to reopen it if necessary!

Yes, that's fine. Thank you for your edits. I read through them and it all appeared to be helpful improvements. I'm still of the opinion that the docs are missing several fundamental things, but I may contribute to improving that in the future. Thanks for your help!

I agree that there should be no implementation in protobufjs for an RPC server. The whole reason we're attempting to use this project is that it's hands off on the transport mechanism and is just a mature encoding/decoding library with TS support.

That being said, there should be enough in the documentation to give hints at how to implement a server. For instance, how to read a protobuf body (binary or JSON) and determine what the message is, if it's an RPC request, what method, etc.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

mj-mehdizadeh picture mj-mehdizadeh  路  5Comments

ArvoGuo picture ArvoGuo  路  4Comments

filipednb picture filipednb  路  5Comments

b1naryMan picture b1naryMan  路  4Comments

taylorcode picture taylorcode  路  4Comments