Documentation ¶
Index ¶
- Constants
- func ToJSONRaw(data cborpatch.RawMessage) (json.RawMessage, error)
- type Error
- type Handler
- type Request
- func (req *Request) DecodeParams(params any) error
- func (req *Request) Error(err error) *Response
- func (req *Request) Grow(n int)
- func (req *Request) InvalidMethod() *Response
- func (req *Request) InvalidParams(msg string) *Response
- func (req *Request) ReadFrom(r io.Reader) (int64, error)
- func (req *Request) Result(result any) *Response
- func (req *Request) ResultRaw(result cbor.RawMessage) *Response
- func (req *Request) String() string
- type Response
Constants ¶
const ( CodeParseError = -32700 CodeInvalidRequest = -32600 CodeMethodNotFound = -32601 CodeInvalidParams = -32602 CodeInternalError = -32603 // -32000 to -32599 Server error, Reserved for implementation-defined server-errors. CodeServerError = -32000 )
refer to JSON-RPC 2.0. https://www.jsonrpc.org/specification
const (
MIMEApplicationCBOR = "application/cbor"
)
Variables ¶
This section is empty.
Functions ¶
func ToJSONRaw ¶ added in v0.1.0
func ToJSONRaw(data cborpatch.RawMessage) (json.RawMessage, error)
ToJSONRaw try to convert a CBOR RawMessage to JSON RawMessage. If the CBOR RawMessage is invalid, it returns an error. If conversion fails, it returns a base64&checksum JSON RawMessage converting by encoding.EncodeToQuoteString.
Types ¶
type Request ¶
type Request struct { ID string `cbor:"id"` Method string `cbor:"method"` Params cbor.RawMessage `cbor:"params,omitempty"` // contains filtered or unexported fields }
Request represents a CBOR-RPC request.
func (*Request) DecodeParams ¶
DecodeParams decodes the request parameters into the given value.
func (*Request) InvalidMethod ¶
InvalidMethod returns a invalid method response from the request.
func (*Request) InvalidParams ¶
InvalidParams returns a invalid params response from the request with the given message.
func (*Request) ReadFrom ¶
ReadFrom decodes the request from the given reader. ReadFrom implements io.ReaderFrom interface.
type Response ¶
type Response struct { ID string `cbor:"id"` Error *Error `cbor:"error,omitempty"` Result cbor.RawMessage `cbor:"result,omitempty"` // contains filtered or unexported fields }
This is a simple implementation of CBOR-RPC. Full reference to https://www.jsonrpc.org/specification Response represents a CBOR-RPC response.
func (*Response) DecodeResult ¶
DecodeResult decodes the result into the given value.