package json import ( "encoding/json" "git.loafle.net/commons_go/rpc/protocol" ) // ---------------------------------------------------------------------------- // Codec // ---------------------------------------------------------------------------- // NewClientCodec returns a new JSON Codec. func NewClientCodec() protocol.ClientCodec { return &ClientCodec{} } // ClientCodec creates a ClientCodecRequest to process each request. type ClientCodec struct { } func (cc *ClientCodec) NewRequest(method string, args []interface{}, id interface{}) ([]byte, error) { params, err := convertParamsToStringArray(args) if nil != err { return nil, err } req := &clientRequest{ Version: Version, Method: method, Params: params, ID: id, } return json.Marshal(req) } func (cc *ClientCodec) NewResponse(buf []byte) (protocol.ClientResponseCodec, error) { return newClientResponseCodec(buf) }