package json import ( "encoding/json" "git.loafle.net/commons/rpc-go/protocol" ) var null = json.RawMessage([]byte("null")) // ---------------------------------------------------------------------------- // Codec // ---------------------------------------------------------------------------- // NewServerCodec returns a new JSON Codec. func NewServerCodec() protocol.ServerCodec { return &ServerCodec{} } // ServerCodec creates a ServerRequestCodec to process each request. type ServerCodec struct { } func (sc *ServerCodec) NewRequest(buf []byte) (protocol.ServerRequestCodec, error) { return newServerRequestCodec(buf) } func (sc *ServerCodec) NewNotification(method string, args []interface{}) ([]byte, error) { params, err := convertParamsToStringArray(args) if nil != err { return nil, err } noti := &serverNotification{Method: method, Params: params} res := &serverResponse{Version: Version, Result: noti} return json.Marshal(res) }