Documentation
¶
Overview ¶
Package jsonrpc2 provides fast jsonrpc 2.0 message encoding and decoding based on jsoniter, with http/tcp implements and examples
Visit repo https://github.com/c0mm4nd/go-jsonrpc2 and get more details
Index ¶
- Variables
- func IsBatchMarshal(raw []byte) bool
- func MarshalMessageBatch(m *JsonRpcMessage) ([]byte, error)
- type Error
- type JsonMsgType
- type JsonRpcMessage
- func NewJsonRpcError(id interface{}, errParams *Error) *JsonRpcMessage
- func NewJsonRpcNotification(method string, params []byte) *JsonRpcMessage
- func NewJsonRpcRequest(id interface{}, method string, params []byte) *JsonRpcMessage
- func NewJsonRpcSuccess(id interface{}, result []byte) *JsonRpcMessage
- func UnmarshalMessage(raw []byte) (*JsonRpcMessage, error)
- type JsonRpcMessageBatch
Constants ¶
This section is empty.
Variables ¶
var ( ErrParseFailed = errors.New("parse error") ErrInternalError = errors.New("invalid params") ErrInvalidParams = errors.New("invalid params") ErrMethodNotFound = errors.New("method not found") ErrInvalidRequest = errors.New("invalid request") )
some built-in errors
var JSON = new(stdJSON)
JSON is the json parser inside the jsonrpc2, developers can change parser via assign another (un)marshaller into this symbol
Functions ¶
func IsBatchMarshal ¶
IsBatchMarshal is a helper to check whether the rawbytes are from a jsonrpc message batch
func MarshalMessageBatch ¶
func MarshalMessageBatch(m *JsonRpcMessage) ([]byte, error)
Types ¶
type Error ¶
type JsonMsgType ¶
type JsonMsgType int
const ( TypeInvalidMsg JsonMsgType = iota TypeNotificationMsg TypeRequestMsg TypeErrorMsg TypeSuccessMsg )
type JsonRpcMessage ¶
type JsonRpcMessage struct { Version string `json:"jsonrpc"` Method string `json:"method,omitempty"` Params *json.RawMessage `json:"params,omitempty"` Result *json.RawMessage `json:"result,omitempty"` Error *Error `json:"error,omitempty"` ID interface{} `json:"id,omitempty"` }
func NewJsonRpcError ¶
func NewJsonRpcError(id interface{}, errParams *Error) *JsonRpcMessage
NewJsonRpcError returns a JSON-RPC 2.0 error message structures.
func NewJsonRpcNotification ¶
func NewJsonRpcNotification(method string, params []byte) *JsonRpcMessage
NewJsonRpcNotification returns a JSON-RPC 2.0 notification message structures which doesnt have id. params should be json marshaled
func NewJsonRpcRequest ¶
func NewJsonRpcRequest(id interface{}, method string, params []byte) *JsonRpcMessage
NewJsonRpcRequest returns a JSON-RPC 2.0 request message structures. id must be string/int/nil type. params should be json marshaled
func NewJsonRpcSuccess ¶
func NewJsonRpcSuccess(id interface{}, result []byte) *JsonRpcMessage
NewJsonRpcSuccess returns a JSON-RPC 2.0 success message structures. result should be json marshaled
func UnmarshalMessage ¶
func UnmarshalMessage(raw []byte) (*JsonRpcMessage, error)
func (*JsonRpcMessage) GetType ¶
func (m *JsonRpcMessage) GetType() JsonMsgType
func (*JsonRpcMessage) LoadParams ¶
func (msg *JsonRpcMessage) LoadParams(paramsPtr interface{}) error
LoadParams reads the params from raw bytes to the pointer
func (*JsonRpcMessage) WithParams ¶
func (msg *JsonRpcMessage) WithParams(params interface{}) error
WithParams converts the params into raw bytes and store in the message
type JsonRpcMessageBatch ¶
type JsonRpcMessageBatch []*JsonRpcMessage
func NewJsonRpcMessageBatch ¶
func NewJsonRpcMessageBatch(messages ...*JsonRpcMessage) JsonRpcMessageBatch
func UnmarshalMessageBatch ¶
func UnmarshalMessageBatch(raw []byte) (JsonRpcMessageBatch, error)
func (*JsonRpcMessageBatch) Marshal ¶
func (b *JsonRpcMessageBatch) Marshal() ([]byte, error)
func (*JsonRpcMessageBatch) Unmarshal ¶
func (b *JsonRpcMessageBatch) Unmarshal(raw []byte) (*JsonRpcMessageBatch, error)
Directories
¶
Path | Synopsis |
---|---|
Package jsonrpc2http provides http implement of [jsonrpc2](https://godoc.org/github.com/c0mm4nd/go-jsonrpc2), the fast jsonrpc 2.0 message encoding and decoding based on jsoniter Visit repo https://godoc.org/github.com/c0mm4nd/go-jsonrpc2 and get example
|
Package jsonrpc2http provides http implement of [jsonrpc2](https://godoc.org/github.com/c0mm4nd/go-jsonrpc2), the fast jsonrpc 2.0 message encoding and decoding based on jsoniter Visit repo https://godoc.org/github.com/c0mm4nd/go-jsonrpc2 and get example |
Package jsonrpc2net provides net(tcp, udp) implement of [jsonrpc2](https://godoc.org/github.com/c0mm4nd/go-jsonrpc2), the fast jsonrpc 2.0 message encoding and decoding Visit repo https://godoc.org/github.com/c0mm4nd/go-jsonrpc2 and get example
|
Package jsonrpc2net provides net(tcp, udp) implement of [jsonrpc2](https://godoc.org/github.com/c0mm4nd/go-jsonrpc2), the fast jsonrpc 2.0 message encoding and decoding Visit repo https://godoc.org/github.com/c0mm4nd/go-jsonrpc2 and get example |
Package jsonrpc2ws provides websocket implement of [jsonrpc2](https://godoc.org/github.com/c0mm4nd/go-jsonrpc2), the fast jsonrpc 2.0 message encoding and decoding Visit repo https://godoc.org/github.com/c0mm4nd/go-jsonrpc2 and get example
|
Package jsonrpc2ws provides websocket implement of [jsonrpc2](https://godoc.org/github.com/c0mm4nd/go-jsonrpc2), the fast jsonrpc 2.0 message encoding and decoding Visit repo https://godoc.org/github.com/c0mm4nd/go-jsonrpc2 and get example |