From bb8b8ac4ce9d4a5566f271cb5fdc05e77ab331c6 Mon Sep 17 00:00:00 2001 From: zhangmeng <775834166@qq.com> Date: 星期五, 19 一月 2024 09:09:35 +0800 Subject: [PATCH] replace json lib --- param.go | 45 +++++++++++++++++++++++---------------------- micronode.go | 5 ++++- hbusc.go | 4 +++- 3 files changed, 30 insertions(+), 24 deletions(-) diff --git a/hbusc.go b/hbusc.go index 3146286..3b8901f 100644 --- a/hbusc.go +++ b/hbusc.go @@ -7,7 +7,7 @@ // "encoding/json" "errors" "fmt" - json "github.com/json-iterator/go" + jsoniter "github.com/json-iterator/go" "os" "sync" "time" @@ -263,6 +263,7 @@ dest := bhome_msg.BHAddress{} if bhsgo.Request(&dest, req, &pid, &mrt, milliSecs) { var reply Reply + var json = jsoniter.ConfigCompatibleWithStandardLibrary if err := json.Unmarshal(mrt.Data, &reply); err != nil { h.printLog("bhsgo.Request ret true, but unmarshal err:", err, " mrt.Data:", string(mrt.Data)) return nil, err @@ -295,6 +296,7 @@ } func (h *BHBus) Reply(src unsafe.Pointer, i *Reply) error { + var json = jsoniter.ConfigCompatibleWithStandardLibrary data, err := json.Marshal(i) if err != nil { return err diff --git a/micronode.go b/micronode.go index 9d329fd..ac96b52 100644 --- a/micronode.go +++ b/micronode.go @@ -3,9 +3,9 @@ import ( "basic.com/valib/c_bhomebus.git/proto/source/bhome_msg" "context" - "encoding/json" "errors" "fmt" + jsoniter "github.com/json-iterator/go" "os" "sync" "time" @@ -111,6 +111,7 @@ ms.printLog("1:", time.Since(t)) t = time.Now() + var json = jsoniter.ConfigCompatibleWithStandardLibrary rb, _ := json.Marshal(request) msgR := &bhome_msg.MsgRequestTopic{ Topic: []byte(request.Path), @@ -121,6 +122,7 @@ } func (ms *MicroNode) RequestTopic(serverId string, request Request, milliSecs int) (*Reply, error) { + var json = jsoniter.ConfigCompatibleWithStandardLibrary rb, _ := json.Marshal(request) msgR := &bhome_msg.MsgRequestTopic{ Topic: []byte(request.Path), @@ -161,6 +163,7 @@ if ms.handlers == nil { return } + var json = jsoniter.ConfigCompatibleWithStandardLibrary var reqBody Request var ri *Reply diff --git a/param.go b/param.go index 8e7e2a2..856c827 100644 --- a/param.go +++ b/param.go @@ -1,35 +1,35 @@ package bhomeclient import ( - "encoding/json" "errors" + jsoniter "github.com/json-iterator/go" ) type Request struct { - Path string `json:"path"` - Method string `json:"method"` - ContentType string `json:"contentType"` - HeaderMap map[string][]string `json:"headerMap"` - QueryMap map[string][]string `json:"queryMap"` - FormMap map[string][]string `json:"formMap"` - PostFormMap map[string][]string `json:"postFormMap"` - Body []byte `json:"body"` - File FileArg `json:"file"` - MultiFiles []FileArg `json:"multiFiles""` + Path string `json:"path"` + Method string `json:"method"` + ContentType string `json:"contentType"` + HeaderMap map[string][]string `json:"headerMap"` + QueryMap map[string][]string `json:"queryMap"` + FormMap map[string][]string `json:"formMap"` + PostFormMap map[string][]string `json:"postFormMap"` + Body []byte `json:"body"` + File FileArg `json:"file"` + MultiFiles []FileArg `json:"multiFiles""` - SrcProc ProcInfo `json:"srcProc"` //璇锋眰鏉ユ簮杩涚▼ + SrcProc ProcInfo `json:"srcProc"` //璇锋眰鏉ユ簮杩涚▼ } type FileArg struct { - Name string `json:"name"` - Size int64 `json:"size"` - Bytes []byte `json:"bytes"` + Name string `json:"name"` + Size int64 `json:"size"` + Bytes []byte `json:"bytes"` } type Reply struct { - Success bool `json:"success"` - Msg string `json:"msg"` - Data interface{} `json:"data"` + Success bool `json:"success"` + Msg string `json:"msg"` + Data interface{} `json:"data"` } func (r *Request) Header(key string) string { @@ -54,19 +54,20 @@ } func (r *Request) BindJSON(v interface{}) error { + var json = jsoniter.ConfigCompatibleWithStandardLibrary return json.Unmarshal(r.Body, &v) } func (r *Request) FormFile() (*FileArg, error) { - if r.File.Name != "" && r.File.Size >0 && r.File.Bytes !=nil { - return &r.File,nil + if r.File.Name != "" && r.File.Size > 0 && r.File.Bytes != nil { + return &r.File, nil } return nil, errors.New("file not found") } func (r *Request) FormFiles() (*[]FileArg, error) { - if r.MultiFiles != nil && len(r.MultiFiles) >0 { + if r.MultiFiles != nil && len(r.MultiFiles) > 0 { return &r.MultiFiles, nil } - return nil,errors.New("multi files not found") + return nil, errors.New("multi files not found") } -- Gitblit v1.8.0