ing
This commit is contained in:
parent
b284554280
commit
eac00359db
|
@ -9,7 +9,7 @@ import (
|
|||
|
||||
func Handle(sh ServerHandler, codec protocol.ServerCodec, r io.Reader, w io.Writer) error {
|
||||
return rpc.Handle(sh, codec, r, w, func(codecReq protocol.ServerCodecRequest) (result interface{}, err error) {
|
||||
var params []byte
|
||||
var params []string
|
||||
if params, err = codecReq.Params(); nil != err {
|
||||
return nil, err
|
||||
}
|
||||
|
|
|
@ -7,5 +7,5 @@ import (
|
|||
type ServerHandler interface {
|
||||
rpc.ServerHandler
|
||||
|
||||
Invoke(method string, params []byte) (result interface{}, err error)
|
||||
Invoke(method string, params []string) (result interface{}, err error)
|
||||
}
|
||||
|
|
|
@ -10,7 +10,7 @@ type ServerHandlers struct {
|
|||
rpc.ServerHandlers
|
||||
}
|
||||
|
||||
func (sh *ServerHandlers) Invoke(method string, params []byte) (result interface{}, err error) {
|
||||
func (sh *ServerHandlers) Invoke(method string, params []string) (result interface{}, err error) {
|
||||
|
||||
return nil, errors.New("Server: Handler method[Invoke] of Server is not implement")
|
||||
}
|
||||
|
|
|
@ -62,9 +62,20 @@ func (ccn *ClientCodecNotify) ReadParams(args []interface{}) error {
|
|||
return ccn.err
|
||||
}
|
||||
|
||||
func (ccn *ClientCodecNotify) Params() ([]byte, error) {
|
||||
func (ccn *ClientCodecNotify) Params() ([]string, error) {
|
||||
if ccn.err == nil && ccn.notify.Params != nil {
|
||||
return *ccn.notify.Params, nil
|
||||
var results []string
|
||||
|
||||
if err := json.Unmarshal(*ccn.notify.Params, &results); err != nil {
|
||||
ccn.err = &Error{
|
||||
Code: E_INVALID_REQ,
|
||||
Message: err.Error(),
|
||||
Data: ccn.notify.Params,
|
||||
}
|
||||
return nil, ccn.err
|
||||
}
|
||||
|
||||
return results, nil
|
||||
}
|
||||
return nil, ccn.err
|
||||
}
|
||||
|
|
|
@ -202,9 +202,20 @@ func (scr *ServerCodecRequest) ReadParams(args []interface{}) error {
|
|||
return scr.err
|
||||
}
|
||||
|
||||
func (scr *ServerCodecRequest) Params() ([]byte, error) {
|
||||
func (scr *ServerCodecRequest) Params() ([]string, error) {
|
||||
if scr.err == nil && scr.request.Params != nil {
|
||||
return *scr.request.Params, nil
|
||||
var results []string
|
||||
|
||||
if err := json.Unmarshal(*scr.request.Params, &results); err != nil {
|
||||
scr.err = &Error{
|
||||
Code: E_INVALID_REQ,
|
||||
Message: err.Error(),
|
||||
Data: scr.request.Params,
|
||||
}
|
||||
return nil, scr.err
|
||||
}
|
||||
|
||||
return results, nil
|
||||
}
|
||||
return nil, scr.err
|
||||
}
|
||||
|
|
|
@ -9,6 +9,6 @@ type RegistryCodec interface {
|
|||
Method() string
|
||||
// Reads the request filling the RPC method args.
|
||||
ReadParams(args []interface{}) error
|
||||
Params() ([]byte, error)
|
||||
Params() ([]string, error)
|
||||
Complete()
|
||||
}
|
||||
|
|
|
@ -8,6 +8,7 @@ import (
|
|||
|
||||
type ServerHandler interface {
|
||||
RegisterCodec(codec protocol.ServerCodec, contentType string)
|
||||
GetCodec(contentType string) (protocol.ServerCodec, error)
|
||||
|
||||
OnPreRead(r io.Reader)
|
||||
OnPostRead(r io.Reader)
|
||||
|
@ -17,6 +18,4 @@ type ServerHandler interface {
|
|||
|
||||
OnPreWriteError(w io.Writer, err error)
|
||||
OnPostWriteError(w io.Writer, err error)
|
||||
|
||||
GetCodec(contentType string) (protocol.ServerCodec, error)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user