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 { // WriteRequest must be safe for concurrent use by multiple goroutines. // don't return bytes WriteRequest(*Request) error ReadResponseHeader(*Response) error ReadResponseBody(interface{}) error Close() error }
A ClientCodec implements writing of RPC requests and reading of RPC responses for the client side of an RPC session. The client calls WriteRequest to write a request to the connection and calls ReadResponseHeader and ReadResponseBody in pairs to read responses. The client calls Close when finished with the connection. ReadResponseBody may be called with a nil argument 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 }
A ServerCodec implements reading of RPC requests and writing of RPC responses for the server side of an RPC session. The server calls ReadRequestHeader and ReadRequestBody in pairs to read requests from the connection, and it calls WriteResponse to write a response back. The server calls Close when finished with the connection. ReadRequestBody may be called with a nil argument to force the body of the request to be read and discarded.