codec

package
v0.9.34 Latest Latest
Warning

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

Go to latest
Published: Jun 30, 2015 License: LGPL-2.1-or-later Imports: 6 Imported by: 0

Documentation

Index

Constants

View Source
const (
	READ_TIMEOUT      = 15 // read timeout 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)
	// 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)

Serialize obj to JSON and write it to conn

func (*JsonCodec) ReadResponse

func (self *JsonCodec) ReadResponse() (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