codec

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: May 2, 2022 License: MIT Imports: 12 Imported by: 0

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

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.

func Read_Data_Frame

func Read_Data_Frame(r net.Conn, obj interface{}, read_timeout time.Duration, max_frame_size uint64) error

reads our data, length prefix blocks

func Write_Data_Frame

func Write_Data_Frame(w net.Conn, obj interface{}, write_timeout time.Duration) error

reads our data, length prefix blocks

Types

type ClientCodec

type ClientCodec struct {
	sync.Mutex
	// contains filtered or unexported fields
}

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

func (s *ClientCodec) ReadHeader(req *bi_rpc.Request, resp *bi_rpc.Response) error

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

Jump to

Keyboard shortcuts

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