This commit is contained in:
2025-02-06 11:14:33 +08:00
commit 07847a2d9e
535 changed files with 65131 additions and 0 deletions

View File

@ -0,0 +1,36 @@
package jsonhelper
import (
"github.com/bytedance/sonic"
jsonIterator "github.com/json-iterator/go"
"github.com/vmihailenco/msgpack/v5"
)
var (
IJson = jsonIterator.ConfigCompatibleWithStandardLibrary
// Marshal is exported by common package.
Marshal = IJson.Marshal
// Unmarshal is exported by common package.
Unmarshal = IJson.Unmarshal
// MarshalIndent is exported by common package.
MarshalIndent = IJson.MarshalIndent
// NewDecoder is exported by common package.
NewDecoder = IJson.NewDecoder
// NewEncoder is exported by common package.
NewEncoder = IJson.NewEncoder
// MarshalMsgPack msgpack方式序列化
MarshalMsgPack = msgpack.Marshal
// msgpack方式反序列化
UnmarshalMsgPack = msgpack.Unmarshal
NewDecoderMsgPack = msgpack.NewDecoder
NewEncoderMsgPack = msgpack.NewEncoder
)
func ToJsonString(v interface{}) string {
if result, err := sonic.Marshal(v); err == nil {
return string(result)
}
return ""
}