ing
This commit is contained in:
parent
4fe1fa640d
commit
258c206988
|
@ -6,5 +6,3 @@ import:
|
|||
- package: gopkg.in/natefinch/npipe.v2
|
||||
- package: git.loafle.net/commons_go/websocket_fasthttp
|
||||
- package: git.loafle.net/commons_go/util
|
||||
- package: github.com/json-iterator/go
|
||||
version: 1.1.3
|
||||
|
|
|
@ -1,11 +1,11 @@
|
|||
package json
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"io"
|
||||
|
||||
"git.loafle.net/commons_go/rpc/codec"
|
||||
"git.loafle.net/commons_go/rpc/protocol"
|
||||
jsoniter "github.com/json-iterator/go"
|
||||
)
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
|
@ -40,7 +40,7 @@ func (cc *ClientCodec) WriteRequest(w io.Writer, method string, args []interface
|
|||
ID: id,
|
||||
}
|
||||
|
||||
encoder := jsoniter.NewEncoder(cc.codecSel.SelectByWriter(w).Encode(w))
|
||||
encoder := json.NewEncoder(cc.codecSel.SelectByWriter(w).Encode(w))
|
||||
if err := encoder.Encode(req); nil != err {
|
||||
return err
|
||||
}
|
||||
|
|
|
@ -6,7 +6,6 @@ import (
|
|||
"git.loafle.net/commons_go/rpc/codec"
|
||||
crp "git.loafle.net/commons_go/rpc/protocol"
|
||||
cuej "git.loafle.net/commons_go/util/encoding/json"
|
||||
jsoniter "github.com/json-iterator/go"
|
||||
)
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
|
@ -56,7 +55,7 @@ func (cnc *ClientNotificationCodec) Params() ([]string, error) {
|
|||
if cnc.err == nil && cnc.noti.Params != nil {
|
||||
var values []string
|
||||
|
||||
if err := jsoniter.Unmarshal(*cnc.noti.Params, &values); err != nil {
|
||||
if err := json.Unmarshal(*cnc.noti.Params, &values); err != nil {
|
||||
cnc.err = &Error{
|
||||
Code: crp.E_INVALID_REQ,
|
||||
Message: err.Error(),
|
||||
|
|
|
@ -8,7 +8,6 @@ import (
|
|||
"git.loafle.net/commons_go/rpc/codec"
|
||||
"git.loafle.net/commons_go/rpc/protocol"
|
||||
crp "git.loafle.net/commons_go/rpc/protocol"
|
||||
jsoniter "github.com/json-iterator/go"
|
||||
)
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
|
@ -35,7 +34,7 @@ func (crc *ClientResponseCodec) ID() interface{} {
|
|||
|
||||
func (crc *ClientResponseCodec) Result(result interface{}) error {
|
||||
if nil == crc.err && nil != crc.res.Result {
|
||||
if err := jsoniter.Unmarshal(*crc.res.Result, result); nil != err {
|
||||
if err := json.Unmarshal(*crc.res.Result, result); nil != err {
|
||||
crc.err = &Error{
|
||||
Code: crp.E_PARSE,
|
||||
Message: err.Error(),
|
||||
|
@ -57,7 +56,7 @@ func (crc *ClientResponseCodec) Notification() (protocol.ClientNotificationCodec
|
|||
}
|
||||
|
||||
noti := &clientNotification{}
|
||||
err := jsoniter.Unmarshal(*crc.res.Result, noti)
|
||||
err := json.Unmarshal(*crc.res.Result, noti)
|
||||
if nil != err {
|
||||
return nil, err
|
||||
}
|
||||
|
@ -67,8 +66,7 @@ func (crc *ClientResponseCodec) Notification() (protocol.ClientNotificationCodec
|
|||
|
||||
// newClientMessageCodec returns a new ClientMessageCodec.
|
||||
func newClientResponseCodec(r io.Reader, codec codec.Codec) (protocol.ClientResponseCodec, error) {
|
||||
|
||||
decoder := jsoniter.NewDecoder(r)
|
||||
decoder := json.NewDecoder(r)
|
||||
if nil == r {
|
||||
return nil, io.EOF
|
||||
}
|
||||
|
|
|
@ -1,11 +1,5 @@
|
|||
package json
|
||||
|
||||
// import (
|
||||
// jsoniter "github.com/json-iterator/go"
|
||||
// )
|
||||
|
||||
// var json = jsoniter.ConfigCompatibleWithStandardLibrary
|
||||
|
||||
const (
|
||||
Name = "jsonrpc"
|
||||
Version = "2.0"
|
||||
|
|
|
@ -6,7 +6,6 @@ import (
|
|||
|
||||
"git.loafle.net/commons_go/rpc/codec"
|
||||
"git.loafle.net/commons_go/rpc/protocol"
|
||||
jsoniter "github.com/json-iterator/go"
|
||||
)
|
||||
|
||||
var null = json.RawMessage([]byte("null"))
|
||||
|
@ -45,7 +44,7 @@ func (sc *ServerCodec) WriteNotification(w io.Writer, method string, args []inte
|
|||
noti := &serverNotification{Method: method, Params: params}
|
||||
res := &serverResponse{Version: Version, Result: noti}
|
||||
|
||||
encoder := jsoniter.NewEncoder(sc.codecSel.SelectByWriter(w).Encode(w))
|
||||
encoder := json.NewEncoder(sc.codecSel.SelectByWriter(w).Encode(w))
|
||||
// Not sure in which case will this happen. But seems harmless.
|
||||
if err := encoder.Encode(res); nil != err {
|
||||
return err
|
||||
|
|
|
@ -8,7 +8,6 @@ import (
|
|||
"git.loafle.net/commons_go/rpc/protocol"
|
||||
crp "git.loafle.net/commons_go/rpc/protocol"
|
||||
cuej "git.loafle.net/commons_go/util/encoding/json"
|
||||
jsoniter "github.com/json-iterator/go"
|
||||
)
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
|
@ -39,7 +38,7 @@ type serverRequest struct {
|
|||
// newRequestCodec returns a new ServerRequestCodec.
|
||||
func newServerRequestCodec(r io.Reader, codec codec.Codec) (protocol.ServerRequestCodec, error) {
|
||||
// Decode the request body and check if RPC method is valid.
|
||||
decoder := jsoniter.NewDecoder(r)
|
||||
decoder := json.NewDecoder(r)
|
||||
if nil == r {
|
||||
return nil, io.EOF
|
||||
}
|
||||
|
@ -119,7 +118,7 @@ func (src *ServerRequestCodec) Params() ([]string, error) {
|
|||
if src.err == nil && src.req.Params != nil {
|
||||
var values []string
|
||||
|
||||
if err := jsoniter.Unmarshal(*src.req.Params, &values); err != nil {
|
||||
if err := json.Unmarshal(*src.req.Params, &values); err != nil {
|
||||
src.err = &Error{
|
||||
Code: crp.E_INVALID_REQ,
|
||||
Message: err.Error(),
|
||||
|
@ -155,7 +154,7 @@ func (src *ServerRequestCodec) WriteError(w io.Writer, status int, err error) er
|
|||
func (src *ServerRequestCodec) writeServerResponse(w io.Writer, res *serverResponse) error {
|
||||
// ID is null for notifications and they don't have a response.
|
||||
if src.req.ID != nil {
|
||||
encoder := jsoniter.NewEncoder(src.codec.Encode(w))
|
||||
encoder := json.NewEncoder(src.codec.Encode(w))
|
||||
// Not sure in which case will this happen. But seems harmless.
|
||||
if err := encoder.Encode(res); nil != err {
|
||||
return err
|
||||
|
|
|
@ -1,11 +1,11 @@
|
|||
package json
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"reflect"
|
||||
|
||||
cur "git.loafle.net/commons_go/util/reflect"
|
||||
jsoniter "github.com/json-iterator/go"
|
||||
)
|
||||
|
||||
func convertParamsToStringArray(params []interface{}) ([]string, error) {
|
||||
|
@ -20,7 +20,7 @@ func convertParamsToStringArray(params []interface{}) ([]string, error) {
|
|||
case reflect.String:
|
||||
values = append(values, param.(string))
|
||||
case reflect.Array, reflect.Slice, reflect.Map, reflect.Struct:
|
||||
b, err := jsoniter.Marshal(param)
|
||||
b, err := json.Marshal(param)
|
||||
if nil != err {
|
||||
return nil, err
|
||||
}
|
||||
|
@ -29,7 +29,7 @@ func convertParamsToStringArray(params []interface{}) ([]string, error) {
|
|||
if t.Elem().Kind() != reflect.Struct {
|
||||
return nil, fmt.Errorf("Pointer of param[%d] is permitted only Struct type", i)
|
||||
}
|
||||
b, err := jsoniter.Marshal(param)
|
||||
b, err := json.Marshal(param)
|
||||
if nil != err {
|
||||
return nil, err
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user