Skip to content

Consider a leaner protocol (backwards compatible) #426

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

Open
setreadygo opened this issue May 1, 2019 · 0 comments
Open

Consider a leaner protocol (backwards compatible) #426

setreadygo opened this issue May 1, 2019 · 0 comments

Comments

@setreadygo
Copy link

setreadygo commented May 1, 2019

Love what you guys are doing, I was going to implementing my own json 2.0 RPC in exactly the same way until I found your project. I have some ideas for improvement with the spec. The official spec is quite old now (2013), so I propose an unofficial 3.0 that is backwards compatible with 2.0:

  1. Version string needs to be only acquired once on initialization. A metadata request is sent when the client connects and the server reports back. If no request is made the server defaults to 2.0. If the server sends an error message back then the client defaults back to 2.0. Now we can do whatever we want without worrying about protocol incompatibility. In javascript it would look like this
socket.once('data', handleMetadata).on('data', handleData)
socket.write(JSON.stringify({ jsonrpc: "2.0", method: "@__version", params: "3.0", id: "" })
  1. Keys can be shortened: { m: "...", k: "...", p: { ... } }
  2. One struct used for both requests and responses { m: 0, k: "...", p: "error msg" }
  3. Key order enforced for quicker encoding/decoding, no whitespace (excluding the param field) should also be enforced for decoding. Only the params field needs to be encoding/decoded which fixes Request<T> and Response<T> for faster serialization #212. The params payload is always last.
  4. pubsub required for 3.0 compliance. As of right now you guys are implementing pubsub, but I can't find anything that supports it because it's not in the 2.0 spec. I've resorted to making my own javascript implementation

Other ideas:

  • Compression support, not worth it in my opinion because you can just compress the params field when you need to for large data in specific functions. The way it would work is the client and server communicate which compressors they support and agree on something and use that.
  • Different serialization formats. Also not really worth it because json tends to be the quickest, but you could do the same as above and have the two discuss which codecs they support and which the client prefers like msgpack or whatever.
  • Drop the json spec for the header and use it only for the payload. Use something like semicolon delimited fields like methodname;key;{....}
  • Go even further and use json values with positional arguments. methodname;key;arg1;arg2;

Anyways, this stuff is all rather minor but I wanted to throw the idea out there. It may be easier to have an inefficient 2.0 protocol and create a tighter 3.0 spec that makes it easy to implement in rust than it would be to try to wrestle with rust to make an optimized 2.0 implementation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants