From 83215a8fd214355703b5c9004345e2380ef6130b Mon Sep 17 00:00:00 2001 From: crusader Date: Fri, 6 Apr 2018 16:50:10 +0900 Subject: [PATCH] ing --- protocol/json/client.go | 1 + protocol/json/server.go | 16 ++++++++++++++++ protocol/server_codec.go | 1 + registry/rpc_registry.go | 2 +- 4 files changed, 19 insertions(+), 1 deletion(-) diff --git a/protocol/json/client.go b/protocol/json/client.go index 8a2d4c8..3cbf64d 100644 --- a/protocol/json/client.go +++ b/protocol/json/client.go @@ -34,6 +34,7 @@ func (cc *ClientCodec) NewRequest(method string, args []interface{}, id interfac return json.Marshal(req) } + func (cc *ClientCodec) NewResponse(buf []byte) (protocol.ClientResponseCodec, error) { return newClientResponseCodec(buf) } diff --git a/protocol/json/server.go b/protocol/json/server.go index 0c044e1..89319dd 100644 --- a/protocol/json/server.go +++ b/protocol/json/server.go @@ -25,6 +25,22 @@ func (sc *ServerCodec) NewRequest(buf []byte) (protocol.ServerRequestCodec, erro return newServerRequestCodec(buf) } +func (sc *ServerCodec) NewRequestWithString(method string, params []string, id interface{}) (protocol.ServerRequestCodec, error) { + req := &clientRequest{ + Version: Version, + Method: method, + Params: params, + ID: id, + } + + buf, err := json.Marshal(req) + if nil != err { + return nil, err + } + + return sc.NewRequest(buf) +} + func (sc *ServerCodec) NewNotification(method string, args []interface{}) ([]byte, error) { params, err := convertParamsToStringArray(args) if nil != err { diff --git a/protocol/server_codec.go b/protocol/server_codec.go index 00da440..46be2dc 100644 --- a/protocol/server_codec.go +++ b/protocol/server_codec.go @@ -3,6 +3,7 @@ package protocol // ServerCodec creates a ServerRequestCodec to process each request. type ServerCodec interface { NewRequest(buf []byte) (ServerRequestCodec, error) + NewRequestWithString(method string, params []string, id interface{}) (ServerRequestCodec, error) NewNotification(method string, args []interface{}) ([]byte, error) } diff --git a/registry/rpc_registry.go b/registry/rpc_registry.go index 577198d..422d3ce 100644 --- a/registry/rpc_registry.go +++ b/registry/rpc_registry.go @@ -91,7 +91,7 @@ func (rr *rpcRegistry) HasMethod(method string) bool { // Codecs are defined to process a given serialization scheme, e.g., JSON or // XML. A codec is chosen based on the "Content-Type" header from the request, // excluding the charset definition. -func (rr *rpcRegistry) Invoke(codec protocol.RegistryCodec) (result interface{}, err error) { +func (rr *rpcRegistry) Invoke(codec protocol.RegistryCodec, leadingParams ...interface{}) (result interface{}, err error) { serviceSpec, methodSpec, errGet := rr.services.get(codec.Method()) if nil != errGet { return nil, errGet