28 lines
810 B
Go
28 lines
810 B
Go
|
package codec
|
||
|
|
||
|
import (
|
||
|
"io"
|
||
|
)
|
||
|
|
||
|
// ----------------------------------------------------------------------------
|
||
|
// Codec
|
||
|
// ----------------------------------------------------------------------------
|
||
|
|
||
|
// Codec creates a CodecRequest to process each request.
|
||
|
type Codec interface {
|
||
|
NewRequest(r io.Reader) (CodecRequest, bool)
|
||
|
}
|
||
|
|
||
|
// 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{})
|
||
|
// Writes an error produced by the server.
|
||
|
WriteError(w io.Writer, status int, err error)
|
||
|
}
|