rpc/protocol/codec.go
crusader f7cd07b3cc ing
2017-10-27 14:24:46 +09:00

30 lines
919 B
Go

package protocol
import (
"io"
)
// ----------------------------------------------------------------------------
// Codec
// ----------------------------------------------------------------------------
// Codec creates a CodecRequest to process each request.
type Codec interface {
// NewRequest is constructor of new request object
// error io.ErrUnexpectedEOF or io.EOF
NewRequest(rc io.Reader) (CodecRequest, error)
}
// 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.
WriteResponse(io.Writer, interface{}) error
// Writes an error produced by the server.
WriteError(w io.Writer, status int, err error) error
}