rpc/protocol/codec.go
crusader 0c7808f8e3 ing
2017-10-26 16:21:35 +09:00

28 lines
818 B
Go

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