rpc/protocol/client_codec.go

46 lines
915 B
Go
Raw Normal View History

2017-10-31 09:25:44 +00:00
package protocol
import (
"io"
)
2017-11-26 10:15:51 +00:00
type MessageType int
const (
MessageTypeUnknown MessageType = iota
MessageTypeRequest
MessageTypeResponse
MessageTypeNotification
)
2017-10-31 09:25:44 +00:00
// ClientCodec creates a ClientCodecRequest to process each request.
type ClientCodec interface {
2017-11-26 10:15:51 +00:00
WriteRequest(w io.Writer, method string, args interface{}, id interface{}) error
NewMessage(rc io.Reader) (ClientMessageCodec, error)
2017-10-31 09:25:44 +00:00
}
2017-11-26 10:15:51 +00:00
type ClientRequestCodec interface {
RegistryCodec
}
// ClientMessageCodec decodes a response or notification using a specific
2017-10-31 09:25:44 +00:00
// serialization scheme.
2017-11-26 10:15:51 +00:00
type ClientMessageCodec interface {
MessageType() MessageType
// Reads the message filling the RPC response or notification.
MessageCodec() (interface{}, error)
Close()
2017-10-31 09:25:44 +00:00
}
2017-11-26 10:15:51 +00:00
type ClientResponseCodec interface {
2017-11-01 09:58:16 +00:00
Result(result interface{}) error
2017-10-31 09:25:44 +00:00
Error() error
2017-11-26 10:15:51 +00:00
ID() interface{}
Close()
2017-10-31 09:25:44 +00:00
}
2017-11-26 10:15:51 +00:00
type ClientNotificationCodec interface {
2017-10-31 09:25:44 +00:00
RegistryCodec
}