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/maoxs2/go-jsonrpc2 and get more details
Index ¶
- Variables
- func IsBatchMarshal(raw []byte) bool
- func MarshalMessage(m *JsonRpcMessage) ([]byte, error)
- func MarshalMessageBatch(m *JsonRpcMessage) ([]byte, error)
- type Error
- 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
- type MsgType
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 (
EmptyArrayBytes, _ = json.Marshal(map[string]interface{}{}) // {}
EmptyListBytes, _ = json.Marshal([]interface{}{}) // []
)
some helper variables
Functions ¶
func IsBatchMarshal ¶
IsBatchMarshal is a helper to check whether the rawbytes are from a jsonrpc message batch
func MarshalMessage ¶
func MarshalMessage(m *JsonRpcMessage) ([]byte, error)
func MarshalMessageBatch ¶
func MarshalMessageBatch(m *JsonRpcMessage) ([]byte, error)
Types ¶
type Error ¶
type JsonRpcMessage ¶
type JsonRpcMessage struct { Version string `json:"jsonrpc"` Method string `json:"method,omitempty"` Params jsoniter.RawMessage `json:"params,omitempty"` Result jsoniter.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() MsgType
func (*JsonRpcMessage) Marshal ¶
func (m *JsonRpcMessage) Marshal() ([]byte, error)
func (*JsonRpcMessage) Unmarshal ¶
func (m *JsonRpcMessage) Unmarshal(raw []byte) (*JsonRpcMessage, error)
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/maoxs2/go-jsonrpc2), the fast jsonrpc 2.0 message encoding and decoding based on jsoniter Visit repo https://godoc.org/github.com/maoxs2/go-jsonrpc2 and get example
|
Package jsonrpc2http provides http implement of [jsonrpc2](https://godoc.org/github.com/maoxs2/go-jsonrpc2), the fast jsonrpc 2.0 message encoding and decoding based on jsoniter Visit repo https://godoc.org/github.com/maoxs2/go-jsonrpc2 and get example |
Package jsonrpc2http provides net(tcp, udp) implement of [jsonrpc2](https://godoc.org/github.com/maoxs2/go-jsonrpc2), the fast jsonrpc 2.0 message encoding and decoding based on jsoniter Visit repo https://godoc.org/github.com/maoxs2/go-jsonrpc2 and get example
|
Package jsonrpc2http provides net(tcp, udp) implement of [jsonrpc2](https://godoc.org/github.com/maoxs2/go-jsonrpc2), the fast jsonrpc 2.0 message encoding and decoding based on jsoniter Visit repo https://godoc.org/github.com/maoxs2/go-jsonrpc2 and get example |