diff options
author | 2023-11-27 13:15:03 +0000 | |
---|---|---|
committer | 2023-11-27 13:15:03 +0000 | |
commit | 66b77acb1c8b86f0be3836ccaf31683c0bfa317a (patch) | |
tree | 9a255a8ea8ef97229b6d75d17de45bdac1755be9 /vendor/github.com/bytedance/sonic/decoder/decoder_compat.go | |
parent | [bugfix] Add Actor to outgoing poll vote Create; other fixes (#2384) (diff) | |
download | gotosocial-66b77acb1c8b86f0be3836ccaf31683c0bfa317a.tar.xz |
[chore]: Bump github.com/gin-contrib/cors from 1.4.0 to 1.5.0 (#2388)
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Diffstat (limited to 'vendor/github.com/bytedance/sonic/decoder/decoder_compat.go')
-rw-r--r-- | vendor/github.com/bytedance/sonic/decoder/decoder_compat.go | 78 |
1 files changed, 38 insertions, 40 deletions
diff --git a/vendor/github.com/bytedance/sonic/decoder/decoder_compat.go b/vendor/github.com/bytedance/sonic/decoder/decoder_compat.go index e6b9463d7..84bae4387 100644 --- a/vendor/github.com/bytedance/sonic/decoder/decoder_compat.go +++ b/vendor/github.com/bytedance/sonic/decoder/decoder_compat.go @@ -1,4 +1,4 @@ -// +build !amd64 go1.21 +// +build !amd64 !go1.16 go1.22 /* * Copyright 2023 ByteDance Inc. @@ -14,28 +14,34 @@ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. -*/ + */ package decoder import ( - `encoding/json` - `bytes` - `reflect` - `github.com/bytedance/sonic/internal/native/types` - `github.com/bytedance/sonic/option` - `io` + `bytes` + `encoding/json` + `io` + `reflect` + `unsafe` + + `github.com/bytedance/sonic/internal/native/types` + `github.com/bytedance/sonic/option` ) +func init() { + println("WARNING: sonic only supports Go1.16~1.20 && CPU amd64, but your environment is not suitable") +} + const ( - _F_use_int64 = iota - _F_use_number - _F_disable_urc - _F_disable_unknown - _F_copy_string - _F_validate_string - - _F_allow_control = 31 + _F_use_int64 = 0 + _F_disable_urc = 2 + _F_disable_unknown = 3 + _F_copy_string = 4 + + _F_use_number = types.B_USE_NUMBER + _F_validate_string = types.B_VALIDATE_STRING + _F_allow_control = types.B_ALLOW_CONTROL ) type Options uint64 @@ -106,10 +112,10 @@ func (self *Decoder) CheckTrailings() error { func (self *Decoder) Decode(val interface{}) error { r := bytes.NewBufferString(self.s) dec := json.NewDecoder(r) - if (self.f | uint64(OptionUseNumber)) != 0 { + if (self.f & uint64(OptionUseNumber)) != 0 { dec.UseNumber() } - if (self.f | uint64(OptionDisableUnknown)) != 0 { + if (self.f & uint64(OptionDisableUnknown)) != 0 { dec.DisallowUnknownFields() } return dec.Decode(val) @@ -163,34 +169,26 @@ func Pretouch(vt reflect.Type, opts ...option.CompileOption) error { return nil } -type StreamDecoder struct { - r io.Reader - buf []byte - scanp int - scanned int64 - err error - Decoder -} +type StreamDecoder = json.Decoder // NewStreamDecoder adapts to encoding/json.NewDecoder API. // // NewStreamDecoder returns a new decoder that reads from r. func NewStreamDecoder(r io.Reader) *StreamDecoder { - return &StreamDecoder{r : r} + return json.NewDecoder(r) } -// Decode decodes input stream into val with corresponding data. -// Redundantly bytes may be read and left in its buffer, and can be used at next call. -// Either io error from underlying io.Reader (except io.EOF) -// or syntax error from data will be recorded and stop subsequently decoding. -func (self *StreamDecoder) Decode(val interface{}) (err error) { - dec := json.NewDecoder(self.r) - if (self.f | uint64(OptionUseNumber)) != 0 { - dec.UseNumber() - } - if (self.f | uint64(OptionDisableUnknown)) != 0 { - dec.DisallowUnknownFields() - } - return dec.Decode(val) +// SyntaxError represents json syntax error +type SyntaxError json.SyntaxError + +// Description +func (s SyntaxError) Description() string { + return (*json.SyntaxError)(unsafe.Pointer(&s)).Error() +} +// Error +func (s SyntaxError) Error() string { + return (*json.SyntaxError)(unsafe.Pointer(&s)).Error() } +// MismatchTypeError represents dismatching between json and object +type MismatchTypeError json.UnmarshalTypeError
\ No newline at end of file |