codec

package
v1.3.1 Latest Latest
Warning

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

Go to latest
Published: Oct 31, 2015 License: GPL-3.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

View Source
const (
	READ_TIMEOUT      = 60 // in seconds
	MAX_REQUEST_SIZE  = 1024 * 1024
	MAX_RESPONSE_SIZE = 1024 * 1024
)

Variables

This section is empty.

Functions

This section is empty.

Types

type ApiCoder

type ApiCoder interface {
	// Parse message to request from underlying stream
	ReadRequest() ([]*shared.Request, bool, error)
	// Parse response message from underlying stream
	ReadResponse() (interface{}, error)
	// Read raw message from underlying stream
	Recv() (interface{}, error)
	// Encode response to encoded form in underlying stream
	WriteResponse(interface{}) error
	// Decode single message from data
	Decode([]byte, interface{}) error
	// Encode msg to encoded form
	Encode(msg interface{}) ([]byte, error)
	// close the underlying stream
	Close()
}

(de)serialization support for rpc interface

func NewJsonCoder

func NewJsonCoder(conn net.Conn) ApiCoder

Create new JSON coder instance

type Codec

type Codec int
const (
	JSON Codec = iota
)

supported codecs

func (Codec) New

func (c Codec) New(conn net.Conn) ApiCoder

create a new coder instance

type JsonCodec

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

Json serialization support

func (*JsonCodec) Close

func (self *JsonCodec) Close()

Close decoder and encoder

func (*JsonCodec) Decode

func (self *JsonCodec) Decode(data []byte, msg interface{}) error

Decode data

func (*JsonCodec) Encode

func (self *JsonCodec) Encode(msg interface{}) ([]byte, error)

Encode message

func (*JsonCodec) ReadRequest

func (self *JsonCodec) ReadRequest() (requests []*shared.Request, isBatch bool, err error)

Read incoming request and parse it to RPC request

func (*JsonCodec) ReadResponse

func (self *JsonCodec) ReadResponse() (interface{}, error)

func (*JsonCodec) Recv added in v1.1.0

func (self *JsonCodec) Recv() (interface{}, error)

func (*JsonCodec) WriteResponse

func (self *JsonCodec) WriteResponse(res interface{}) error

Parse JSON data from conn to obj

Jump to

Keyboard shortcuts

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