This commit is contained in:
crusader 2017-11-09 17:38:02 +09:00
parent b284554280
commit eac00359db
7 changed files with 31 additions and 10 deletions

View File

@ -9,7 +9,7 @@ import (
func Handle(sh ServerHandler, codec protocol.ServerCodec, r io.Reader, w io.Writer) error { 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) { 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 { if params, err = codecReq.Params(); nil != err {
return nil, err return nil, err
} }

View File

@ -7,5 +7,5 @@ import (
type ServerHandler interface { type ServerHandler interface {
rpc.ServerHandler rpc.ServerHandler
Invoke(method string, params []byte) (result interface{}, err error) Invoke(method string, params []string) (result interface{}, err error)
} }

View File

@ -10,7 +10,7 @@ type ServerHandlers struct {
rpc.ServerHandlers 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") return nil, errors.New("Server: Handler method[Invoke] of Server is not implement")
} }

View File

@ -62,9 +62,20 @@ func (ccn *ClientCodecNotify) ReadParams(args []interface{}) error {
return ccn.err return ccn.err
} }
func (ccn *ClientCodecNotify) Params() ([]byte, error) { func (ccn *ClientCodecNotify) Params() ([]string, error) {
if ccn.err == nil && ccn.notify.Params != nil { 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 return nil, ccn.err
} }

View File

@ -202,9 +202,20 @@ func (scr *ServerCodecRequest) ReadParams(args []interface{}) error {
return scr.err return scr.err
} }
func (scr *ServerCodecRequest) Params() ([]byte, error) { func (scr *ServerCodecRequest) Params() ([]string, error) {
if scr.err == nil && scr.request.Params != nil { 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 return nil, scr.err
} }

View File

@ -9,6 +9,6 @@ type RegistryCodec interface {
Method() string Method() string
// Reads the request filling the RPC method args. // Reads the request filling the RPC method args.
ReadParams(args []interface{}) error ReadParams(args []interface{}) error
Params() ([]byte, error) Params() ([]string, error)
Complete() Complete()
} }

View File

@ -8,6 +8,7 @@ import (
type ServerHandler interface { type ServerHandler interface {
RegisterCodec(codec protocol.ServerCodec, contentType string) RegisterCodec(codec protocol.ServerCodec, contentType string)
GetCodec(contentType string) (protocol.ServerCodec, error)
OnPreRead(r io.Reader) OnPreRead(r io.Reader)
OnPostRead(r io.Reader) OnPostRead(r io.Reader)
@ -17,6 +18,4 @@ type ServerHandler interface {
OnPreWriteError(w io.Writer, err error) OnPreWriteError(w io.Writer, err error)
OnPostWriteError(w io.Writer, err error) OnPostWriteError(w io.Writer, err error)
GetCodec(contentType string) (protocol.ServerCodec, error)
} }