msgpack2

package
v2.3.8+incompatible Latest Latest
Warning

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

Go to latest
Published: Aug 2, 2018 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrNullResult = errors.New("result is null")
View Source
var Version = "2.0"

var null = json.RawMessage([]byte("null"))

Functions

func DecodeClientResponse

func DecodeClientResponse(r io.Reader, reply interface{}) error

DecodeClientResponse decodes the response body of a client request into the interface reply.

func EncodeClientRequest

func EncodeClientRequest(method string, args interface{}) ([]byte, error)

EncodeClientRequest encodes parameters for a JSON-RPC client request.

Types

type Codec

type Codec struct {
	// contains filtered or unexported fields
}

Codec creates a CodecRequest to process each request.

func NewCodec

func NewCodec() *Codec

NewCodec returns a new JSON Codec.

func NewCustomCodec

func NewCustomCodec(encSel rpc.EncoderSelector) *Codec

NewcustomCodec returns a new JSON Codec based on passed encoder selector.

func (*Codec) NewRequest

func (c *Codec) NewRequest(r *http.Request) rpc.CodecRequest

NewRequest returns a CodecRequest.

type CodecRequest

type CodecRequest struct {
	// contains filtered or unexported fields
}

CodecRequest decodes and encodes a single request.

func (*CodecRequest) Method

func (c *CodecRequest) Method() (string, error)

Method returns the RPC method for the current request.

The method uses a dotted notation as in "Service.Method".

func (*CodecRequest) ReadRequest

func (c *CodecRequest) ReadRequest(args interface{}) error

ReadRequest fills the request object for the RPC method.

ReadRequest parses request parameters in two supported forms in accordance with http://www.jsonrpc.org/specification#parameter_structures

by-position: params MUST be an Array, containing the values in the Server expected order.

by-name: params MUST be an Object, with member names that match the Server expected parameter names. The absence of expected names MAY result in an error being generated. The names MUST match exactly, including case, to the method's expected parameters.

func (*CodecRequest) WriteError

func (c *CodecRequest) WriteError(w http.ResponseWriter, status int, err error)

func (*CodecRequest) WriteResponse

func (c *CodecRequest) WriteResponse(w http.ResponseWriter, reply interface{})

WriteResponse encodes the response and writes it to the ResponseWriter.

type EmptyResponse

type EmptyResponse struct {
}

type Error

type Error struct {
	// A Number that indicates the error type that occurred.
	Code ErrorCode `msgpack:"code"` /* required */

	// A String providing a short description of the error.
	// The message SHOULD be limited to a concise single sentence.
	Message string `msgpack:"message"` /* required */

	// A Primitive or Structured value that contains additional information about the error.
	Data interface{} `msgpack:"data"` /* optional */
}

func (*Error) Error

func (e *Error) Error() string

type ErrorCode

type ErrorCode int
const (
	E_PARSE       ErrorCode = -32700
	E_INVALID_REQ ErrorCode = -32600
	E_NO_METHOD   ErrorCode = -32601
	E_BAD_PARAMS  ErrorCode = -32602
	E_INTERNAL    ErrorCode = -32603
	E_SERVER      ErrorCode = -32000
)

Jump to

Keyboard shortcuts

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