summaryrefslogtreecommitdiff
path: root/vendor/github.com/bytedance/sonic/api.go
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/github.com/bytedance/sonic/api.go')
-rw-r--r--vendor/github.com/bytedance/sonic/api.go33
1 files changed, 33 insertions, 0 deletions
diff --git a/vendor/github.com/bytedance/sonic/api.go b/vendor/github.com/bytedance/sonic/api.go
index 093329127..af6be70a4 100644
--- a/vendor/github.com/bytedance/sonic/api.go
+++ b/vendor/github.com/bytedance/sonic/api.go
@@ -23,6 +23,16 @@ import (
`github.com/bytedance/sonic/internal/rt`
)
+const (
+ // UseStdJSON indicates you are using fallback implementation (encoding/json)
+ UseStdJSON = iota
+ // UseSonicJSON indicates you are using real sonic implementation
+ UseSonicJSON
+)
+
+// APIKind is the kind of API, 0 is std json, 1 is sonic.
+const APIKind = apiKind
+
// Config is a combination of sonic/encoder.Options and sonic/decoder.Options
type Config struct {
// EscapeHTML indicates encoder to escape all HTML characters
@@ -74,9 +84,16 @@ type Config struct {
// NoValidateJSONMarshaler indicates that the encoder should not validate the output string
// after encoding the JSONMarshaler to JSON.
NoValidateJSONMarshaler bool
+
+ // NoValidateJSONSkip indicates the decoder should not validate the JSON value when skipping it,
+ // such as unknown-fields, mismatched-type, redundant elements..
+ NoValidateJSONSkip bool
// NoEncoderNewline indicates that the encoder should not add a newline after every message
NoEncoderNewline bool
+
+ // Encode Infinity or Nan float into `null`, instead of returning an error.
+ EncodeNullForInfOrNan bool
}
var (
@@ -96,6 +113,7 @@ var (
ConfigFastest = Config{
NoQuoteTextMarshaler: true,
NoValidateJSONMarshaler: true,
+ NoValidateJSONSkip: true,
}.Froze()
)
@@ -157,6 +175,13 @@ func Marshal(val interface{}) ([]byte, error) {
return ConfigDefault.Marshal(val)
}
+// MarshalIndent is like Marshal but applies Indent to format the output.
+// Each JSON element in the output will begin on a new line beginning with prefix
+// followed by one or more copies of indent according to the indentation nesting.
+func MarshalIndent(v interface{}, prefix, indent string) ([]byte, error) {
+ return ConfigDefault.MarshalIndent(v, prefix, indent)
+}
+
// MarshalString returns the JSON encoding string of v.
func MarshalString(val interface{}) (string, error) {
return ConfigDefault.MarshalToString(val)
@@ -189,6 +214,14 @@ func Get(src []byte, path ...interface{}) (ast.Node, error) {
return GetCopyFromString(rt.Mem2Str(src), path...)
}
+//GetWithOptions searches and locates the given path from src json,
+// with specific options of ast.Searcher
+func GetWithOptions(src []byte, opts ast.SearchOptions, path ...interface{}) (ast.Node, error) {
+ s := ast.NewSearcher(rt.Mem2Str(src))
+ s.SearchOptions = opts
+ return s.GetByPath(path...)
+}
+
// GetFromString is same with Get except src is string.
//
// WARNING: The returned JSON is **Referenced** from the input.