Documentation
¶
Index ¶
Constants ¶
View Source
const ( //type of Encoder and Decoder //the type can be gob,json,protobuf. //the protobuf is the most efficient GobType string = "application/gob" JsonType string = "application/json" )
View Source
const MagicNumber = 0x3bef5c
Variables ¶
View Source
var DefaultOption = &Option{ MagicNumber: MagicNumber, CodecType: "application/gob", ConnectTimeOut: time.Second * 10, }
if not diffine Opiton will use defaultOption
View Source
var NewCodecFuncMap map[string]NewCodecFunc
Functions ¶
Types ¶
type Codec ¶
type Codec interface { io.Closer ReadHeader(*Header) error ReadBody(interface{}) error Write(*Header, interface{}) error }
interface for coding Message
func NewGobCodec ¶
func NewGobCodec(conn io.ReadWriteCloser) Codec
func NewJsonCodec ¶
func NewJsonCodec(conn io.ReadWriteCloser) Codec
type GobCodec ¶
type GobCodec struct {
// contains filtered or unexported fields
}
Gob is less efficient than json
func (*GobCodec) ReadHeader ¶
type Header ¶
type Header struct { ServiceMethod string //format "Service.Method" call mathordName SeqNum uint64 //sequence number chosen by client Error string }
head means server name and method name outher info in body such as args,reply,error
type JsonCodec ¶
type JsonCodec struct {
// contains filtered or unexported fields
}
func (*JsonCodec) ReadHeader ¶
type NewCodecFunc ¶
type NewCodecFunc func(io.ReadWriteCloser) Codec
Click to show internal directories.
Click to hide internal directories.