ing
This commit is contained in:
parent
cd7081c731
commit
83215a8fd2
|
@ -34,6 +34,7 @@ func (cc *ClientCodec) NewRequest(method string, args []interface{}, id interfac
|
||||||
|
|
||||||
return json.Marshal(req)
|
return json.Marshal(req)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (cc *ClientCodec) NewResponse(buf []byte) (protocol.ClientResponseCodec, error) {
|
func (cc *ClientCodec) NewResponse(buf []byte) (protocol.ClientResponseCodec, error) {
|
||||||
return newClientResponseCodec(buf)
|
return newClientResponseCodec(buf)
|
||||||
}
|
}
|
||||||
|
|
|
@ -25,6 +25,22 @@ func (sc *ServerCodec) NewRequest(buf []byte) (protocol.ServerRequestCodec, erro
|
||||||
return newServerRequestCodec(buf)
|
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) {
|
func (sc *ServerCodec) NewNotification(method string, args []interface{}) ([]byte, error) {
|
||||||
params, err := convertParamsToStringArray(args)
|
params, err := convertParamsToStringArray(args)
|
||||||
if nil != err {
|
if nil != err {
|
||||||
|
|
|
@ -3,6 +3,7 @@ package protocol
|
||||||
// ServerCodec creates a ServerRequestCodec to process each request.
|
// ServerCodec creates a ServerRequestCodec to process each request.
|
||||||
type ServerCodec interface {
|
type ServerCodec interface {
|
||||||
NewRequest(buf []byte) (ServerRequestCodec, error)
|
NewRequest(buf []byte) (ServerRequestCodec, error)
|
||||||
|
NewRequestWithString(method string, params []string, id interface{}) (ServerRequestCodec, error)
|
||||||
NewNotification(method string, args []interface{}) ([]byte, error)
|
NewNotification(method string, args []interface{}) ([]byte, error)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -91,7 +91,7 @@ func (rr *rpcRegistry) HasMethod(method string) bool {
|
||||||
// Codecs are defined to process a given serialization scheme, e.g., JSON or
|
// 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,
|
// XML. A codec is chosen based on the "Content-Type" header from the request,
|
||||||
// excluding the charset definition.
|
// 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())
|
serviceSpec, methodSpec, errGet := rr.services.get(codec.Method())
|
||||||
if nil != errGet {
|
if nil != errGet {
|
||||||
return nil, errGet
|
return nil, errGet
|
||||||
|
|
Loading…
Reference in New Issue
Block a user