Skip to content

Commit

Permalink
使用原生json,测试性能
Browse files Browse the repository at this point in the history
  • Loading branch information
steden committed Nov 30, 2024
1 parent 1fa214f commit dcd3415
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion snc/json.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package snc

import (
"bytes"
"encoding/json"

"github.com/bytedance/sonic"
"github.com/bytedance/sonic/option"
)
Expand All @@ -21,10 +24,15 @@ func init() {
}.Froze()
}

// 将json转换成对象(反序列化)
func Unmarshal(data []byte, v any) error {
return snc.Unmarshal(data, v)
d := json.NewDecoder(bytes.NewReader(data))
d.UseNumber()
return d.Decode(v)
//return snc.Unmarshal(data, v)
}

// 将对象转换成json(序列化)
func Marshal(val any) ([]byte, error) {
return snc.Marshal(val)
}
Expand Down

0 comments on commit dcd3415

Please sign in to comment.