Documentation ¶
Overview ¶
Package jsonrpc implements a JSON-RPC ClientCodec and ServerCodec for the bi_rpc package.
Beside struct types, JSONCodec allows using positional arguments. Use []interface{} as the type of argument when sending and receiving methods.
Positional arguments example:
server.Handle("add", func(client *bi_rpc.Client, args []interface{}, result *float64) error { *result = args[0].(float64) + args[1].(float64) return nil }) var result float64 client.Call("add", []interface{}{1, 2}, &result)
Index ¶
- func NewJSONCodec(conn io.ReadWriteCloser) bi_rpc.Codec
- func Read_Data_Frame(r net.Conn, obj interface{}, read_timeout time.Duration, max_frame_size uint64) error
- func Write_Data_Frame(w net.Conn, obj interface{}, write_timeout time.Duration) error
- type ClientCodec
- func (c *ClientCodec) Close() error
- func (s *ClientCodec) ReadHeader(req *bi_rpc.Request, resp *bi_rpc.Response) error
- func (s *ClientCodec) ReadRequestBody(obj interface{}) error
- func (c *ClientCodec) ReadResponseBody(obj interface{}) error
- func (c *ClientCodec) ReadResponseHeader(resp *bi_rpc.Response) error
- func (c *ClientCodec) WriteRequest(req *bi_rpc.Request, obj interface{}) error
- func (c *ClientCodec) WriteResponse(resp *bi_rpc.Response, obj interface{}) error
- type RequestResponse
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func NewJSONCodec ¶
func NewJSONCodec(conn io.ReadWriteCloser) bi_rpc.Codec
NewJSONCodec returns a new bi_rpc.Codec using JSON-RPC on conn.
Types ¶
type ClientCodec ¶
ClientCodec implements the rpc.ClientCodec interface for generic golang objects.
func NewCBORCodec ¶
func NewCBORCodec(conn net.Conn) *ClientCodec
NewClientCodec returns a ClientCodec for communicating with the ServerCodec on the other end of the conn. to support deadlines we use net.conn
func NewCBORCodec_ ¶
func NewCBORCodec_(conn net.Conn, read_timeout time.Duration, write_timeout time.Duration, max_frame_size uint64) *ClientCodec
max_frame_size is neglected in checking process when <=0
func (*ClientCodec) Close ¶
func (c *ClientCodec) Close() error
Close closes the underlying connection.
func (*ClientCodec) ReadHeader ¶
ReadRequestHeader reads the header (which is prefixed by a 4 byte lil endian length indicating its size) from the connection, decodes it, and stores the fields in the given request.
func (*ClientCodec) ReadRequestBody ¶
func (s *ClientCodec) ReadRequestBody(obj interface{}) error
ReadRequestBody reads a 4 byte length from the connection and decodes that many subsequent bytes into the object
func (*ClientCodec) ReadResponseBody ¶
func (c *ClientCodec) ReadResponseBody(obj interface{}) error
ReadResponseBody reads a 4 byte length from the connection and decodes that many subsequent bytes into the given object (which should be a pointer to a struct).
func (*ClientCodec) ReadResponseHeader ¶
func (c *ClientCodec) ReadResponseHeader(resp *bi_rpc.Response) error
ReadResponseHeader reads a 4 byte length from the connection and decodes that many subsequent bytes into the given object, decodes it, and stores the fields in the given request.
func (*ClientCodec) WriteRequest ¶
func (c *ClientCodec) WriteRequest(req *bi_rpc.Request, obj interface{}) error
WriteRequest writes the 4 byte length from the connection and encodes that many subsequent bytes into the given object.
func (*ClientCodec) WriteResponse ¶
func (c *ClientCodec) WriteResponse(resp *bi_rpc.Response, obj interface{}) error
WriteResponse writes the appropriate header. If the response was invalid, the size of the body of the resp is reported as having size zero and is not sent.
type RequestResponse ¶
type RequestResponse struct { Method string `cbor:"M"` // format: "Service.Method" Seq uint64 `cbor:"S"` // echoes that of the request Error string `cbor:"E"` // error, if any. }
it processes both