This commit is contained in:
crusader 2018-04-06 16:50:10 +09:00
parent cd7081c731
commit 83215a8fd2
4 changed files with 19 additions and 1 deletions

View File

@ -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)
}

View File

@ -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 {

View File

@ -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)
}

View File

@ -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