/
json_sonic.go
40 lines (29 loc) · 938 Bytes
/
json_sonic.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
//go:build (darwin || linux || windows) && amd64
// +build darwin linux windows
// +build amd64
package util
import (
"io"
"github.com/bytedance/sonic"
sonicdecoder "github.com/bytedance/sonic/decoder"
sonicencoder "github.com/bytedance/sonic/encoder"
"github.com/pkg/errors"
)
func marshalJSON(v interface{}) ([]byte, error) {
b, err := sonic.Marshal(v) //nolint:wrapcheck //...
return b, errors.WithStack(err)
}
func unmarshalJSON(b []byte, v interface{}) error {
err := sonic.Unmarshal(b, v) //nolint:wrapcheck //...
return errors.WithStack(err)
}
func marshalJSONIndent(i interface{}) ([]byte, error) {
b, err := sonicencoder.EncodeIndented(i, "", " ", 0) //nolint:wrapcheck //...
return b, errors.WithStack(err)
}
func newJSONStreamEncoder(w io.Writer) StreamEncoder {
return sonicencoder.NewStreamEncoder(w)
}
func newJSONStreamDecoder(r io.Reader) StreamDecoder {
return sonicdecoder.NewStreamDecoder(r)
}