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-26 07:21:35 +00:00
|
|
|
NewRequest(rc io.Reader) CodecRequest
|
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
|
|
|
}
|