rpc/client/rwc/socket/client_rwc_handlers.go
crusader 08688dfb2f ing
2018-03-23 16:43:05 +09:00

62 lines
1.7 KiB
Go

package socket
import (
"git.loafle.net/commons_go/logging"
"git.loafle.net/commons_go/rpc/client"
"git.loafle.net/commons_go/rpc/protocol"
csc "git.loafle.net/commons_go/server/client"
)
func New(socketBuilder csc.SocketBuilder) client.ClientReadWriteCloseHandler {
return &ClientReadWriteCloseHandlers{
SocketBuilder: socketBuilder,
}
}
type ClientReadWriteCloseHandlers struct {
client.ClientReadWriteCloseHandlers
SocketBuilder csc.SocketBuilder
}
func (crwch *ClientReadWriteCloseHandlers) Connect(clientCTX client.ClientContext) (interface{}, error) {
return csc.NewSocket(crwch.SocketBuilder, clientCTX)
}
func (crwch *ClientReadWriteCloseHandlers) NewDecoder(clientCTX client.ClientContext, codec protocol.ClientCodec, conn interface{}) (interface{}, error) {
soc := conn.(csc.Socket)
return codec.NewDecoder(soc), nil
}
func (crwch *ClientReadWriteCloseHandlers) ReadResponse(clientCTX client.ClientContext, codec protocol.ClientCodec, decoder interface{}) (protocol.ClientResponseCodec, error) {
resCodec, err := codec.NewResponse(decoder)
return resCodec, err
}
func (crwch *ClientReadWriteCloseHandlers) WriteRequest(clientCTX client.ClientContext, codec protocol.ClientCodec, conn interface{}, method string, params []interface{}, id interface{}) error {
var (
wErr error
)
soc := conn.(csc.Socket)
wErr = codec.WriteRequest(soc, method, params, id)
return wErr
}
func (crwch *ClientReadWriteCloseHandlers) Disconnect(clientCTX client.ClientContext, conn interface{}) {
soc := conn.(csc.Socket)
soc.Close()
}
func (crwch *ClientReadWriteCloseHandlers) Validate() {
crwch.ClientReadWriteCloseHandlers.Validate()
if nil == crwch.SocketBuilder {
logging.Logger().Panicf("RPC Client: SocketBuilder must be specified")
}
}