cborrpc

package
v0.0.4 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 18, 2022 License: AGPL-3.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
const (
	CodeParseError     = -32700
	CodeInvalidRequest = -32600
	CodeMethodNotFound = -32601
	CodeInvalidParams  = -32602
	CodeInternalError  = -32603
	// -32000 to -32599	Server error, Reserved for implementation-defined server-errors.
	CodeServerError = -32000
)
View Source
const (
	MIMEApplicationCBOR = "application/cbor"
)

Variables

This section is empty.

Functions

func ToJSON

func ToJSON(data cborpatch.RawMessage) json.RawMessage

Types

type Error

type Error struct {
	Code    int         `json:"code" cbor:"code"`
	Message string      `json:"message" cbor:"message"`
	Data    interface{} `json:"data,omitempty" cbor:"data,omitempty"`
}

func (*Error) Error

func (e *Error) Error() string

type Handler

type Handler interface {
	ServeRPC(context.Context, *Request) *Response
	OnError(context.Context, *Error)
}

type Request

type Request struct {
	ID     string          `cbor:"id,omitempty"`
	Method string          `cbor:"method"`
	Params cbor.RawMessage `cbor:"params,omitempty"`
	// contains filtered or unexported fields
}

This is a simple implementation of CBOR-RPC. Full reference to https://www.jsonrpc.org/specification

func (*Request) DecodeParams

func (req *Request) DecodeParams(params interface{}) error

func (*Request) Error

func (req *Request) Error(err error) *Response

func (*Request) Grow

func (req *Request) Grow(n int)

func (*Request) InvalidMethod

func (req *Request) InvalidMethod() *Response

func (*Request) InvalidParams

func (req *Request) InvalidParams(msg string) *Response

func (*Request) ReadFrom

func (req *Request) ReadFrom(r io.Reader) (int64, error)

func (*Request) Result

func (req *Request) Result(result interface{}) *Response

func (*Request) ResultRaw

func (req *Request) ResultRaw(result cbor.RawMessage) *Response

func (*Request) String

func (req *Request) String() string

type Response

type Response struct {
	ID     string          `cbor:"id,omitempty"`
	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

func (*Response) DecodeResult

func (res *Response) DecodeResult(result interface{}) error

func (*Response) Grow

func (res *Response) Grow(n int)

func (*Response) ReadFrom

func (res *Response) ReadFrom(r io.Reader) (int64, error)

func (*Response) String

func (res *Response) String() string

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL