-
-
Notifications
You must be signed in to change notification settings - Fork 312
add jsonrpc serialization to rpc #4623
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
base: main
Are you sure you want to change the base?
Conversation
|
jsonRpcMessage = { | ||
jsonrpc: "2.0", | ||
method: response.tag, | ||
params: response.payload, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Generally for the RPC module, payload
should be:
a) optional
b) not just Schema.Struct
E.g. JSON RPC commonly uses positional tuples for payloads and for some methods, the payload can also be optional entirely. In these cases, the params
key should not be set (but most implementations will accept an empty array or empty object anyways).
export const jsonrpc: Effect.Effect<RpcSerialization["Type"]> = Effect.sync(() => { | ||
const decoder = new TextDecoder() | ||
return RpcSerialization.of({ | ||
contentType: "application/json-rpc", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some JSON RPC server will NOT accept application/json-rpc
(as ridiculous as that sounds).
In these cases, we could either require the user to override the header in their client or alternatively we'd have to change how the muxing currently behaves when e.g. application/json
is set and instead make that more explicitly configurable here (I think I'd prefer that).
supportsBigInt: false, | ||
unsafeMake: () => ({ | ||
decode: (bytes) => { | ||
const decoded: JsonRpcMessage = JSON.parse(typeof bytes === "string" ? bytes : decoder.decode(bytes)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some JSON RPC server support batch requests.
No description provided.