diff options
Diffstat (limited to 'vendor/github.com/bytedance/sonic/encoder')
| -rw-r--r-- | vendor/github.com/bytedance/sonic/encoder/encoder_amd64.go | 8 | ||||
| -rw-r--r-- | vendor/github.com/bytedance/sonic/encoder/encoder_compat.go | 35 | 
2 files changed, 27 insertions, 16 deletions
diff --git a/vendor/github.com/bytedance/sonic/encoder/encoder_amd64.go b/vendor/github.com/bytedance/sonic/encoder/encoder_amd64.go index fa107c73f..e93b09a25 100644 --- a/vendor/github.com/bytedance/sonic/encoder/encoder_amd64.go +++ b/vendor/github.com/bytedance/sonic/encoder/encoder_amd64.go @@ -1,4 +1,4 @@ -// +build amd64,go1.15,!go1.21 +// +build amd64,go1.16,!go1.22  /*   * Copyright 2023 ByteDance Inc. @@ -59,6 +59,10 @@ const (      // before encoding it into JSON.      ValidateString Options = encoder.ValidateString +    // NoValidateJSONMarshaler indicates that the encoder should not validate the output string +    // after encoding the JSONMarshaler to JSON. +    NoValidateJSONMarshaler Options = encoder.NoValidateJSONMarshaler +      // CompatibleWithStd is used to be compatible with std encoder.      CompatibleWithStd Options = encoder.CompatibleWithStd  ) @@ -105,4 +109,4 @@ var (      //      // NewStreamEncoder returns a new encoder that write to w.      NewStreamEncoder = encoder.NewStreamEncoder -)
\ No newline at end of file +) diff --git a/vendor/github.com/bytedance/sonic/encoder/encoder_compat.go b/vendor/github.com/bytedance/sonic/encoder/encoder_compat.go index afa80d561..2e02b59cd 100644 --- a/vendor/github.com/bytedance/sonic/encoder/encoder_compat.go +++ b/vendor/github.com/bytedance/sonic/encoder/encoder_compat.go @@ -1,4 +1,4 @@ -// +build !amd64 go1.21 +// +build !amd64 !go1.16 go1.22  /*  * Copyright 2023 ByteDance Inc. @@ -27,6 +27,10 @@ import (      `github.com/bytedance/sonic/option`  ) +func init() { +    println("WARNING: sonic only supports Go1.16~1.20 && CPU amd64, but your environment is not suitable") +} +  // Options is a set of encoding options.  type Options uint64 @@ -37,6 +41,7 @@ const (      bitNoQuoteTextMarshaler      bitNoNullSliceOrMap      bitValidateString +    bitNoValidateJSONMarshaler      // used for recursive compile      bitPointerValue = 63 @@ -68,6 +73,10 @@ const (      // ValidateString indicates that encoder should validate the input string      // before encoding it into JSON.      ValidateString       Options = 1 << bitValidateString + +    // NoValidateJSONMarshaler indicates that the encoder should not validate the output string +    // after encoding the JSONMarshaler to JSON. +    NoValidateJSONMarshaler Options = 1 << bitNoValidateJSONMarshaler      // CompatibleWithStd is used to be compatible with std encoder.      CompatibleWithStd Options = SortMapKeys | EscapeHTML | CompactMarshaler @@ -112,6 +121,15 @@ func (self *Encoder) SetValidateString(f bool) {      }  } +// SetNoValidateJSONMarshaler specifies if option NoValidateJSONMarshaler opens +func (self *Encoder) SetNoValidateJSONMarshaler(f bool) { +    if f { +        self.Opts |= NoValidateJSONMarshaler +    } else { +        self.Opts &= ^NoValidateJSONMarshaler +    } +} +  // SetCompactMarshaler specifies if option CompactMarshaler opens  func (self *Encoder) SetCompactMarshaler(f bool) {      if f { @@ -212,23 +230,12 @@ func Valid(data []byte) (ok bool, start int) {  }  // StreamEncoder uses io.Writer as  -type StreamEncoder struct { -   w io.Writer -   Encoder -} +type StreamEncoder = json.Encoder  // NewStreamEncoder adapts to encoding/json.NewDecoder API.  //  // NewStreamEncoder returns a new encoder that write to w.  func NewStreamEncoder(w io.Writer) *StreamEncoder { -   return &StreamEncoder{w: w} +   return json.NewEncoder(w)  } -// Encode encodes interface{} as JSON to io.Writer -func (enc *StreamEncoder) Encode(val interface{}) (err error) { -   jenc := json.NewEncoder(enc.w) -   jenc.SetEscapeHTML((enc.Opts & EscapeHTML) != 0) -   jenc.SetIndent(enc.prefix, enc.indent) -   err = jenc.Encode(val) -   return err -}  | 
