rpc/protocol/json/client.go

40 lines
914 B
Go
Raw Permalink Normal View History

2017-10-26 16:21:35 +09:00
package json
import (
2018-03-23 12:48:20 +09:00
"encoding/json"
2017-10-31 18:25:44 +09:00
"git.loafle.net/commons_go/rpc/protocol"
2017-10-26 16:21:35 +09:00
)
2017-10-31 18:25:44 +09:00
// ----------------------------------------------------------------------------
// Codec
// ----------------------------------------------------------------------------
// NewClientCodec returns a new JSON Codec.
2017-11-26 19:15:51 +09:00
func NewClientCodec() protocol.ClientCodec {
2018-03-23 16:43:05 +09:00
return &ClientCodec{}
2017-10-31 18:25:44 +09:00
}
// ClientCodec creates a ClientCodecRequest to process each request.
type ClientCodec struct {
2018-03-23 16:43:05 +09:00
}
2018-03-24 02:26:41 +09:00
func (cc *ClientCodec) NewRequest(method string, args []interface{}, id interface{}) ([]byte, error) {
2018-03-23 22:45:48 +09:00
params, err := convertParamsToStringArray(args)
if nil != err {
return nil, err
}
req := &clientRequest{
Version: Version,
Method: method,
Params: params,
ID: id,
}
return json.Marshal(req)
}
2018-03-24 02:26:41 +09:00
func (cc *ClientCodec) NewResponse(buf []byte) (protocol.ClientResponseCodec, error) {
return newClientResponseCodec(buf)
2018-03-23 22:45:48 +09:00
}