Documentation ¶
Overview ¶
Package codec is an interface for encoding messages
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func InstallPlugin ¶
InstallPlugin to install the codec plugins
Types ¶
type ClientCodec ¶
type ClientCodec interface { ReadResponseHeader(*Response) error ReadResponseBody(interface{}) error // WriteRequest must be safe for concurrent use by multiple goroutines. // don't return bytes WriteRequest(*Request) error Close() error }
ClientCodec writes RPC requests and reads RPC responses in the client side of an RPC session. ReadResponseHeader and ReadResponseBody are called in pairs to read requests. WriteRequest writes a request to the connection ReadResponseBody could be called with a nil param to force the body of the response to be read and then discarded.
type Codec ¶
type Codec interface { // 编码函数. Marshal(v interface{}) ([]byte, error) // 解码函数. Unmarshal(data []byte, v interface{}) error }
Codec 编解码接口
type NewClientCodec ¶
type NewClientCodec func(io.ReadWriteCloser) ClientCodec
NewClientCodec takes in a connection/buffer and returns a new client codec
type NewServerCodec ¶
type NewServerCodec func(io.ReadWriteCloser) ServerCodec
NewServerCodec takes in a connection/buffer and returns a new server codec
type Request ¶
type Request struct { ID uint64 SchemaID string OperationID string Error string Header map[string]string Arg interface{} }
Request Message represents detailed information about the communication, likely followed by the body. In the case of an error, body may be nil
type Response ¶
type Response struct { ID uint64 SchemaID string OperationID string Error string Header map[string]string // contains filtered or unexported fields }
Response Message represents detailed information about the communication, likely followed by the body. In the case of an error, body may be nil
type ServerCodec ¶
type ServerCodec interface { ReadRequestHeader(*Request) error ReadRequestBody(interface{}) error // WriteResponse must be safe for concurrent use by multiple goroutines. WriteResponse(r *Response) error Close() error }
ServerCodec reads RPC requests and writes RPC responses in the server side of an RPC session. ReadRequestHeader and ReadRequestBody are called in pairs to read requests from the connection. WriteResponse writes a response back. ReadRequestBody could be called with a nil param to force the body of the request to be read and discarded.