Documentation
¶
Overview ¶
Package jsonrpc speaks the JSON half of stdiorpc's protocol over a pipe: Content-Length-delimited frames carrying JSON-RPC 2.0 bodies, with the canonical gRPC status codes numbering a refused call. It is shared by the WebAssembly commands, whose frames are read without net/textproto so the networking packages stay out of a small binary.
Index ¶
Constants ¶
const ( ContentTypeJSON = "application/json" ContentTypeProtobuf = "application/proto" )
Content types a frame may carry, as stdiorpc reads them. Only JSON is served; a protobuf frame is refused rather than answered in kind.
const ( CodeCanceled = 1 CodeUnknown = 2 CodeInvalidArgument = 3 CodeDeadlineExceeded = 4 CodeNotFound = 5 CodeResourceExhausted = 8 CodeFailedPrecondition = 9 CodeUnimplemented = 12 CodeInternal = 13 )
The canonical gRPC status codes an answer is reported under, numbered as every transport of the service numbers them.
const MaxHeaderBytes = 64 << 10
MaxHeaderBytes bounds the header lines of one frame in place of textproto's limits, so an endless line is refused before it is buffered.
Variables ¶
This section is empty.
Functions ¶
func Envelope ¶
Envelope is the JSON-RPC answer the JS host surface returns for one call: the result body, or the error's code and message, under a null id.
func ErrorParts ¶
ErrorParts reads the canonical status code and message a failed call is answered with; the codes number the same as gRPC's.
func ReadHeader ¶ added in v0.13.0
ReadHeader reads one frame's MIME header from r, refusing one over MaxHeaderBytes.
func Serve ¶
Serve reads Content-Length-delimited frames from r and writes answers to w until r reaches its end, speaking the JSON half of stdiorpc's protocol: the same framing, envelope and error codes, with a protobuf frame refused since this product carries no protobuf. Calls are handled sequentially and answered in order.
Types ¶
type Error ¶
Error is a refused call: the canonical status code and its message.
func Decode ¶
Decode reads the request body as protojson does over the lowerCamel field names: unknown fields are ignored, absent params are the empty request.