rpc/protocol/codec.go
crusader f22f37a6dc ing
2017-10-27 14:18:11 +09:00

28 lines
827 B
Go

package protocol
import (
"io"
)
// ----------------------------------------------------------------------------
// Codec
// ----------------------------------------------------------------------------
// Codec creates a CodecRequest to process each request.
type Codec interface {
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
}