rpc/protocol/codec.go

30 lines
919 B
Go
Raw Normal View History

2017-10-26 07:21:35 +00:00
package protocol
2017-10-25 14:52:47 +00:00
import (
"io"
)
// ----------------------------------------------------------------------------
// Codec
// ----------------------------------------------------------------------------
// Codec creates a CodecRequest to process each request.
type Codec interface {
2017-10-27 05:24:46 +00:00
// NewRequest is constructor of new request object
// error io.ErrUnexpectedEOF or io.EOF
2017-10-27 05:18:11 +00:00
NewRequest(rc io.Reader) (CodecRequest, error)
2017-10-25 14:52:47 +00:00
}
// CodecRequest decodes a request and encodes a response using a specific
// serialization scheme.
type CodecRequest interface {
// Reads the request and returns the RPC method name.
Method() (string, error)
// Reads the request filling the RPC method args.
ReadRequest(interface{}) error
// Writes the response using the RPC method reply.
2017-10-26 07:21:35 +00:00
WriteResponse(io.Writer, interface{}) error
2017-10-25 14:52:47 +00:00
// Writes an error produced by the server.
2017-10-26 07:21:35 +00:00
WriteError(w io.Writer, status int, err error) error
2017-10-25 14:52:47 +00:00
}