From b1af8fd87760b34e3ff2fd3bda38f211815a0473 Mon Sep 17 00:00:00 2001 From: Terin Stock Date: Sun, 9 Mar 2025 17:47:56 +0100 Subject: [chore] remove vendor --- vendor/github.com/ugorji/go/codec/0_importpath.go | 7 - vendor/github.com/ugorji/go/codec/LICENSE | 22 - vendor/github.com/ugorji/go/codec/README.md | 316 - .../ugorji/go/codec/base.fastpath.generated.go | 259 - .../go/codec/base.fastpath.notmono.generated.go | 6259 ---------- .../github.com/ugorji/go/codec/base.notfastpath.go | 34 - .../ugorji/go/codec/base.notfastpath.notmono.go | 26 - vendor/github.com/ugorji/go/codec/binc.base.go | 194 - .../go/codec/binc.fastpath.mono.generated.go | 12482 ------------------- vendor/github.com/ugorji/go/codec/binc.go | 1066 -- .../ugorji/go/codec/binc.mono.generated.go | 8158 ------------ .../go/codec/binc.notfastpath.mono.generated.go | 52 - vendor/github.com/ugorji/go/codec/build.sh | 219 - vendor/github.com/ugorji/go/codec/cbor.base.go | 160 - .../go/codec/cbor.fastpath.mono.generated.go | 12482 ------------------- vendor/github.com/ugorji/go/codec/cbor.go | 995 -- .../ugorji/go/codec/cbor.mono.generated.go | 7985 ------------ .../go/codec/cbor.notfastpath.mono.generated.go | 52 - vendor/github.com/ugorji/go/codec/custom_time.go | 191 - vendor/github.com/ugorji/go/codec/decimal.go | 513 - vendor/github.com/ugorji/go/codec/decode.base.go | 944 -- vendor/github.com/ugorji/go/codec/decode.go | 1961 --- vendor/github.com/ugorji/go/codec/doc.go | 341 - vendor/github.com/ugorji/go/codec/encode.base.go | 461 - vendor/github.com/ugorji/go/codec/encode.go | 1652 --- vendor/github.com/ugorji/go/codec/fastpath.go.tmpl | 134 - .../ugorji/go/codec/fastpath.notmono.go.tmpl | 525 - vendor/github.com/ugorji/go/codec/gen.go | 426 - vendor/github.com/ugorji/go/codec/gen_mono.go | 586 - .../ugorji/go/codec/goversion_check_supported.go | 20 - .../ugorji/go/codec/goversion_noswissmap_unsafe.go | 16 - .../ugorji/go/codec/goversion_swissmap_unsafe.go | 15 - vendor/github.com/ugorji/go/codec/helper.go | 3278 ----- vendor/github.com/ugorji/go/codec/helper.s | 0 .../ugorji/go/codec/helper_not_unsafe.go | 706 -- .../ugorji/go/codec/helper_notunsafe_or_notgc.go | 59 - vendor/github.com/ugorji/go/codec/helper_unsafe.go | 1258 -- .../ugorji/go/codec/helper_unsafe_compiler_gc.go | 242 - .../go/codec/helper_unsafe_compiler_not_gc.go | 81 - vendor/github.com/ugorji/go/codec/init.mono.go | 130 - vendor/github.com/ugorji/go/codec/init.notmono.go | 313 - vendor/github.com/ugorji/go/codec/json.base.go | 504 - .../go/codec/json.fastpath.mono.generated.go | 12482 ------------------- vendor/github.com/ugorji/go/codec/json.go | 1225 -- .../ugorji/go/codec/json.mono.generated.go | 8339 ------------- .../go/codec/json.notfastpath.mono.generated.go | 52 - .../ugorji/go/codec/mammoth_test.go.tmpl | 324 - vendor/github.com/ugorji/go/codec/msgpack.base.go | 299 - .../go/codec/msgpack.fastpath.mono.generated.go | 12482 ------------------- vendor/github.com/ugorji/go/codec/msgpack.go | 1019 -- .../ugorji/go/codec/msgpack.mono.generated.go | 8046 ------------ .../go/codec/msgpack.notfastpath.mono.generated.go | 52 - vendor/github.com/ugorji/go/codec/reader.go | 830 -- vendor/github.com/ugorji/go/codec/rpc.go | 228 - vendor/github.com/ugorji/go/codec/simple.base.go | 97 - .../go/codec/simple.fastpath.mono.generated.go | 12482 ------------------- vendor/github.com/ugorji/go/codec/simple.go | 749 -- .../ugorji/go/codec/simple.mono.generated.go | 7549 ----------- .../go/codec/simple.notfastpath.mono.generated.go | 52 - .../ugorji/go/codec/test-cbor-goldens.json | 639 - vendor/github.com/ugorji/go/codec/test.py | 138 - vendor/github.com/ugorji/go/codec/writer.go | 239 - 62 files changed, 132447 deletions(-) delete mode 100644 vendor/github.com/ugorji/go/codec/0_importpath.go delete mode 100644 vendor/github.com/ugorji/go/codec/LICENSE delete mode 100644 vendor/github.com/ugorji/go/codec/README.md delete mode 100644 vendor/github.com/ugorji/go/codec/base.fastpath.generated.go delete mode 100644 vendor/github.com/ugorji/go/codec/base.fastpath.notmono.generated.go delete mode 100644 vendor/github.com/ugorji/go/codec/base.notfastpath.go delete mode 100644 vendor/github.com/ugorji/go/codec/base.notfastpath.notmono.go delete mode 100644 vendor/github.com/ugorji/go/codec/binc.base.go delete mode 100644 vendor/github.com/ugorji/go/codec/binc.fastpath.mono.generated.go delete mode 100644 vendor/github.com/ugorji/go/codec/binc.go delete mode 100644 vendor/github.com/ugorji/go/codec/binc.mono.generated.go delete mode 100644 vendor/github.com/ugorji/go/codec/binc.notfastpath.mono.generated.go delete mode 100644 vendor/github.com/ugorji/go/codec/build.sh delete mode 100644 vendor/github.com/ugorji/go/codec/cbor.base.go delete mode 100644 vendor/github.com/ugorji/go/codec/cbor.fastpath.mono.generated.go delete mode 100644 vendor/github.com/ugorji/go/codec/cbor.go delete mode 100644 vendor/github.com/ugorji/go/codec/cbor.mono.generated.go delete mode 100644 vendor/github.com/ugorji/go/codec/cbor.notfastpath.mono.generated.go delete mode 100644 vendor/github.com/ugorji/go/codec/custom_time.go delete mode 100644 vendor/github.com/ugorji/go/codec/decimal.go delete mode 100644 vendor/github.com/ugorji/go/codec/decode.base.go delete mode 100644 vendor/github.com/ugorji/go/codec/decode.go delete mode 100644 vendor/github.com/ugorji/go/codec/doc.go delete mode 100644 vendor/github.com/ugorji/go/codec/encode.base.go delete mode 100644 vendor/github.com/ugorji/go/codec/encode.go delete mode 100644 vendor/github.com/ugorji/go/codec/fastpath.go.tmpl delete mode 100644 vendor/github.com/ugorji/go/codec/fastpath.notmono.go.tmpl delete mode 100644 vendor/github.com/ugorji/go/codec/gen.go delete mode 100644 vendor/github.com/ugorji/go/codec/gen_mono.go delete mode 100644 vendor/github.com/ugorji/go/codec/goversion_check_supported.go delete mode 100644 vendor/github.com/ugorji/go/codec/goversion_noswissmap_unsafe.go delete mode 100644 vendor/github.com/ugorji/go/codec/goversion_swissmap_unsafe.go delete mode 100644 vendor/github.com/ugorji/go/codec/helper.go delete mode 100644 vendor/github.com/ugorji/go/codec/helper.s delete mode 100644 vendor/github.com/ugorji/go/codec/helper_not_unsafe.go delete mode 100644 vendor/github.com/ugorji/go/codec/helper_notunsafe_or_notgc.go delete mode 100644 vendor/github.com/ugorji/go/codec/helper_unsafe.go delete mode 100644 vendor/github.com/ugorji/go/codec/helper_unsafe_compiler_gc.go delete mode 100644 vendor/github.com/ugorji/go/codec/helper_unsafe_compiler_not_gc.go delete mode 100644 vendor/github.com/ugorji/go/codec/init.mono.go delete mode 100644 vendor/github.com/ugorji/go/codec/init.notmono.go delete mode 100644 vendor/github.com/ugorji/go/codec/json.base.go delete mode 100644 vendor/github.com/ugorji/go/codec/json.fastpath.mono.generated.go delete mode 100644 vendor/github.com/ugorji/go/codec/json.go delete mode 100644 vendor/github.com/ugorji/go/codec/json.mono.generated.go delete mode 100644 vendor/github.com/ugorji/go/codec/json.notfastpath.mono.generated.go delete mode 100644 vendor/github.com/ugorji/go/codec/mammoth_test.go.tmpl delete mode 100644 vendor/github.com/ugorji/go/codec/msgpack.base.go delete mode 100644 vendor/github.com/ugorji/go/codec/msgpack.fastpath.mono.generated.go delete mode 100644 vendor/github.com/ugorji/go/codec/msgpack.go delete mode 100644 vendor/github.com/ugorji/go/codec/msgpack.mono.generated.go delete mode 100644 vendor/github.com/ugorji/go/codec/msgpack.notfastpath.mono.generated.go delete mode 100644 vendor/github.com/ugorji/go/codec/reader.go delete mode 100644 vendor/github.com/ugorji/go/codec/rpc.go delete mode 100644 vendor/github.com/ugorji/go/codec/simple.base.go delete mode 100644 vendor/github.com/ugorji/go/codec/simple.fastpath.mono.generated.go delete mode 100644 vendor/github.com/ugorji/go/codec/simple.go delete mode 100644 vendor/github.com/ugorji/go/codec/simple.mono.generated.go delete mode 100644 vendor/github.com/ugorji/go/codec/simple.notfastpath.mono.generated.go delete mode 100644 vendor/github.com/ugorji/go/codec/test-cbor-goldens.json delete mode 100644 vendor/github.com/ugorji/go/codec/test.py delete mode 100644 vendor/github.com/ugorji/go/codec/writer.go (limited to 'vendor/github.com/ugorji/go/codec') diff --git a/vendor/github.com/ugorji/go/codec/0_importpath.go b/vendor/github.com/ugorji/go/codec/0_importpath.go deleted file mode 100644 index adbe862c2..000000000 --- a/vendor/github.com/ugorji/go/codec/0_importpath.go +++ /dev/null @@ -1,7 +0,0 @@ -// Copyright (c) 2012-2018 Ugorji Nwoke. All rights reserved. -// Use of this source code is governed by a MIT license found in the LICENSE file. - -package codec // import "github.com/ugorji/go/codec" - -// This establishes that this package must be imported as github.com/ugorji/go/codec. -// It makes forking easier, and plays well with pre-module releases of go. diff --git a/vendor/github.com/ugorji/go/codec/LICENSE b/vendor/github.com/ugorji/go/codec/LICENSE deleted file mode 100644 index 36a8bcf10..000000000 --- a/vendor/github.com/ugorji/go/codec/LICENSE +++ /dev/null @@ -1,22 +0,0 @@ -The MIT License (MIT) - -Copyright (c) 2012-2020 Ugorji Nwoke. -All rights reserved. - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. diff --git a/vendor/github.com/ugorji/go/codec/README.md b/vendor/github.com/ugorji/go/codec/README.md deleted file mode 100644 index d50e90e45..000000000 --- a/vendor/github.com/ugorji/go/codec/README.md +++ /dev/null @@ -1,316 +0,0 @@ -# Package Documentation for github.com/ugorji/go/codec - -Package codec provides a High Performance, Feature-Rich Idiomatic Go 1.4+ -codec/encoding library for binc, msgpack, cbor, json. - -Supported Serialization formats are: - - - msgpack: https://github.com/msgpack/msgpack - - binc: http://github.com/ugorji/binc - - cbor: http://cbor.io http://tools.ietf.org/html/rfc7049 - - json: http://json.org http://tools.ietf.org/html/rfc7159 - - simple: - -This package will carefully use 'package unsafe' for performance reasons -in specific places. You can build without unsafe use by passing the safe or -appengine tag i.e. 'go install -tags=codec.safe ...'. - -This library works with both the standard `gc` and the `gccgo` compilers. - -For detailed usage information, read the primer at -http://ugorji.net/blog/go-codec-primer . - -The idiomatic Go support is as seen in other encoding packages in the standard -library (ie json, xml, gob, etc). - -Rich Feature Set includes: - - - Simple but extremely powerful and feature-rich API - - Support for go 1.4 and above, while selectively using newer APIs for later - releases - - Excellent code coverage ( > 90% ) - - Very High Performance. Our extensive benchmarks show us outperforming Gob, - Json, Bson, etc by 2-4X. - - Careful selected use of 'unsafe' for targeted performance gains. - - 100% safe mode supported, where 'unsafe' is not used at all. - - Lock-free (sans mutex) concurrency for scaling to 100's of cores - - In-place updates during decode, with option to zero value in maps and slices - prior to decode - - Coerce types where appropriate e.g. decode an int in the stream into a - float, decode numbers from formatted strings, etc - - Corner Cases: Overflows, nil maps/slices, nil values in streams are handled - correctly - - Standard field renaming via tags - - Support for omitting empty fields during an encoding - - Encoding from any value and decoding into pointer to any value (struct, - slice, map, primitives, pointers, interface{}, etc) - - Extensions to support efficient encoding/decoding of any named types - - Support encoding.(Binary|Text)(M|Unm)arshaler interfaces - - Support using existence of `IsZero() bool` to determine if a value is a zero - value. Analogous to time.Time.IsZero() bool. - - Decoding without a schema (into a interface{}). Includes Options to - configure what specific map or slice type to use when decoding an encoded - list or map into a nil interface{} - - Mapping a non-interface type to an interface, so we can decode appropriately - into any interface type with a correctly configured non-interface value. - - Encode a struct as an array, and decode struct from an array in the data - stream - - Option to encode struct keys as numbers (instead of strings) (to support - structured streams with fields encoded as numeric codes) - - Comprehensive support for anonymous fields - - Fast (no-reflection) encoding/decoding of common maps and slices - - Code-generation for faster performance, supported in go 1.6+ - - Support binary (e.g. messagepack, cbor) and text (e.g. json) formats - - Support indefinite-length formats to enable true streaming (for formats - which support it e.g. json, cbor) - - Support canonical encoding, where a value is ALWAYS encoded as same - sequence of bytes. This mostly applies to maps, where iteration order is - non-deterministic. - - NIL in data stream decoded as zero value - - Never silently skip data when decoding. User decides whether to return an - error or silently skip data when keys or indexes in the data stream do not - map to fields in the struct. - - Detect and error when encoding a cyclic reference (instead of stack overflow - shutdown) - - Encode/Decode from/to chan types (for iterative streaming support) - - Drop-in replacement for encoding/json. `json:` key in struct tag supported. - - Provides a RPC Server and Client Codec for net/rpc communication protocol. - - Handle unique idiosyncrasies of codecs e.g. For messagepack, - configure how ambiguities in handling raw bytes are resolved and provide - rpc server/client codec to support msgpack-rpc protocol defined at: - https://github.com/msgpack-rpc/msgpack-rpc/blob/master/spec.md - -# Supported build tags - -We gain performance by code-generating fast-paths for slices and maps of built-in types, -and monomorphizing generic code explicitly so we gain inlining and de-virtualization benefits. - -The results are 20-40% performance improvements. - -Building and running is configured using build tags as below. - -At runtime: - -- codec.safe: run in safe mode (not using unsafe optimizations) -- codec.notmono: use generics code (bypassing performance-boosting monomorphized code) -- codec.notfastpath: skip fast path code for slices and maps of built-in types (number, bool, string, bytes) - -Each of these "runtime" tags have a convenience synonym i.e. safe, notmono, notfastpath. -Pls use these mostly during development - use codec.XXX in your go files. - -Build only: - -- codec.build: used to generate fastpath and monomorphization code - -Test only: - -- codec.notmammoth: skip the mammoth generated tests - -# Extension Support - -Users can register a function to handle the encoding or decoding of their custom -types. - -There are no restrictions on what the custom type can be. Some examples: - -```go - type BisSet []int - type BitSet64 uint64 - type UUID string - type MyStructWithUnexportedFields struct { a int; b bool; c []int; } - type GifImage struct { ... } -``` - -As an illustration, MyStructWithUnexportedFields would normally be encoded as -an empty map because it has no exported fields, while UUID would be encoded as a -string. However, with extension support, you can encode any of these however you -like. - -There is also seamless support provided for registering an extension (with a -tag) but letting the encoding mechanism default to the standard way. - -# Custom Encoding and Decoding - -This package maintains symmetry in the encoding and decoding halfs. We determine -how to encode or decode by walking this decision tree - - - is there an extension registered for the type? - - is type a codec.Selfer? - - is format binary, and is type a encoding.BinaryMarshaler and - BinaryUnmarshaler? - - is format specifically json, and is type a encoding/json.Marshaler and - Unmarshaler? - - is format text-based, and type an encoding.TextMarshaler and - TextUnmarshaler? - - else we use a pair of functions based on the "kind" of the type e.g. map, - slice, int64, etc - -This symmetry is important to reduce chances of issues happening because the -encoding and decoding sides are out of sync e.g. decoded via very specific -encoding.TextUnmarshaler but encoded via kind-specific generalized mode. - -Consequently, if a type only defines one-half of the symmetry (e.g. -it implements UnmarshalJSON() but not MarshalJSON() ), then that type doesn't -satisfy the check and we will continue walking down the decision tree. - -# RPC - -RPC Client and Server Codecs are implemented, so the codecs can be used with the -standard net/rpc package. - -# Usage - -The Handle is SAFE for concurrent READ, but NOT SAFE for concurrent -modification. - -The Encoder and Decoder are NOT safe for concurrent use. - -Consequently, the usage model is basically: - - - Create and initialize the Handle before any use. Once created, DO NOT modify - it. - - Multiple Encoders or Decoders can now use the Handle concurrently. They only - read information off the Handle (never write). - - However, each Encoder or Decoder MUST not be used concurrently - - To re-use an Encoder/Decoder, call Reset(...) on it first. This allows you - use state maintained on the Encoder/Decoder. - -Sample usage model: - -```go - // create and configure Handle - var ( - bh codec.BincHandle - mh codec.MsgpackHandle - ch codec.CborHandle - ) - - mh.MapType = reflect.TypeOf(map[string]interface{}(nil)) - - // configure extensions - // e.g. for msgpack, define functions and enable Time support for tag 1 - // mh.SetExt(reflect.TypeOf(time.Time{}), 1, myExt) - - // create and use decoder/encoder - var ( - r io.Reader - w io.Writer - b []byte - h = &bh // or mh to use msgpack - ) - - dec = codec.NewDecoder(r, h) - dec = codec.NewDecoderBytes(b, h) - err = dec.Decode(&v) - - enc = codec.NewEncoder(w, h) - enc = codec.NewEncoderBytes(&b, h) - err = enc.Encode(v) - - //RPC Server - go func() { - for { - conn, err := listener.Accept() - rpcCodec := codec.GoRpc.ServerCodec(conn, h) - //OR rpcCodec := codec.MsgpackSpecRpc.ServerCodec(conn, h) - rpc.ServeCodec(rpcCodec) - } - }() - - //RPC Communication (client side) - conn, err = net.Dial("tcp", "localhost:5555") - rpcCodec := codec.GoRpc.ClientCodec(conn, h) - //OR rpcCodec := codec.MsgpackSpecRpc.ClientCodec(conn, h) - client := rpc.NewClientWithCodec(rpcCodec) -``` - -# Running Tests - -To run tests, use the following: - -``` - go test -``` - -To run the full suite of tests, use the following: - -``` - go test -tags alltests -run Suite -``` - -You can run the tag 'codec.safe' to run tests or build in safe mode. e.g. - -``` - go test -tags codec.safe -run Json - go test -tags "alltests codec.safe" -run Suite -``` - -You can run the tag 'codec.notmono' to build bypassing the monomorphized code e.g. - -``` - go test -tags codec.notmono -run Json -``` - -# Running Benchmarks - -``` - cd bench - go test -bench . -benchmem -benchtime 1s -``` - -Please see http://github.com/ugorji/go-codec-bench . - -# Caveats - -Struct fields matching the following are ignored during encoding and decoding - - - struct tag value set to - - - func, complex numbers, unsafe pointers - - unexported and not embedded - - unexported and embedded and not struct kind - - unexported and embedded pointers (from go1.10) - -Every other field in a struct will be encoded/decoded. - -Embedded fields are encoded as if they exist in the top-level struct, with some -caveats. See Encode documentation. - -## Exported Package API - -```go -const CborStreamBytes byte = 0x5f ... -const GenVersion = 28 -var SelfExt = &extFailWrapper{} -var GoRpc goRpc -var MsgpackSpecRpc msgpackSpecRpc -func GenHelper() (g genHelper) -type BasicHandle struct{ ... } -type BincHandle struct{ ... } -type BytesExt interface{ ... } -type CborHandle struct{ ... } -type DecodeOptions struct{ ... } -type Decoder struct{ ... } - func NewDecoder(r io.Reader, h Handle) *Decoder - func NewDecoderBytes(in []byte, h Handle) *Decoder - func NewDecoderString(s string, h Handle) *Decoder -type EncodeOptions struct{ ... } -type Encoder struct{ ... } - func NewEncoder(w io.Writer, h Handle) *Encoder - func NewEncoderBytes(out *[]byte, h Handle) *Encoder -type Ext interface{ ... } -type Handle interface{ ... } -type InterfaceExt interface{ ... } -type JsonHandle struct{ ... } -type MapBySlice interface{ ... } -type MissingFielder interface{ ... } -type MsgpackHandle struct{ ... } -type MsgpackSpecRpcMultiArgs []interface{} -type RPCOptions struct{ ... } -type Raw []byte -type RawExt struct{ ... } -type Rpc interface{ ... } -type Selfer interface{ ... } -type SimpleHandle struct{ ... } -type TypeInfos struct{ ... } - func NewTypeInfos(tags []string) *TypeInfos -``` diff --git a/vendor/github.com/ugorji/go/codec/base.fastpath.generated.go b/vendor/github.com/ugorji/go/codec/base.fastpath.generated.go deleted file mode 100644 index d1fbba460..000000000 --- a/vendor/github.com/ugorji/go/codec/base.fastpath.generated.go +++ /dev/null @@ -1,259 +0,0 @@ -//go:build !notfastpath && !codec.notfastpath - -// Copyright (c) 2012-2020 Ugorji Nwoke. All rights reserved. -// Use of this source code is governed by a MIT license found in the LICENSE file. - -// Code generated from fastpath.go.tmpl - DO NOT EDIT. - -package codec - -// Fast path functions try to create a fast path encode or decode implementation -// for common maps and slices. -// -// We define the functions and register them in this single file -// so as not to pollute the encode.go and decode.go, and create a dependency in there. -// This file can be omitted without causing a build failure. -// -// The advantage of fast paths is: -// - Many calls bypass reflection altogether -// -// Currently support -// - slice of all builtin types (numeric, bool, string, []byte) -// - maps of builtin types to builtin or interface{} type, EXCEPT FOR -// keys of type uintptr, int8/16/32, uint16/32, float32/64, bool, interface{} -// AND values of type type int8/16/32, uint16/32 -// This should provide adequate "typical" implementations. -// -// Note that fast track decode functions must handle values for which an address cannot be obtained. -// For example: -// m2 := map[string]int{} -// p2 := []interface{}{m2} -// // decoding into p2 will bomb if fast track functions do not treat like unaddressable. -// - -import ( - "reflect" - "slices" - "sort" -) - -const fastpathEnabled = true - -type fastpathARtid [56]uintptr - -type fastpathRtRtid struct { - rtid uintptr - rt reflect.Type -} -type fastpathARtRtid [56]fastpathRtRtid - -var ( - fastpathAvRtidArr fastpathARtid - fastpathAvRtRtidArr fastpathARtRtid - fastpathAvRtid = fastpathAvRtidArr[:] - fastpathAvRtRtid = fastpathAvRtRtidArr[:] -) - -func fastpathAvIndex(rtid uintptr) (i uint, ok bool) { - return searchRtids(fastpathAvRtid, rtid) -} - -func init() { - var i uint = 0 - fn := func(v interface{}) { - xrt := reflect.TypeOf(v) - xrtid := rt2id(xrt) - xptrtid := rt2id(reflect.PointerTo(xrt)) - fastpathAvRtid[i] = xrtid - fastpathAvRtRtid[i] = fastpathRtRtid{rtid: xrtid, rt: xrt} - encBuiltinRtids = append(encBuiltinRtids, xrtid, xptrtid) - decBuiltinRtids = append(decBuiltinRtids, xrtid, xptrtid) - i++ - } - - fn([]interface{}(nil)) - fn([]string(nil)) - fn([][]byte(nil)) - fn([]float32(nil)) - fn([]float64(nil)) - fn([]uint8(nil)) - fn([]uint64(nil)) - fn([]int(nil)) - fn([]int32(nil)) - fn([]int64(nil)) - fn([]bool(nil)) - - fn(map[string]interface{}(nil)) - fn(map[string]string(nil)) - fn(map[string][]byte(nil)) - fn(map[string]uint8(nil)) - fn(map[string]uint64(nil)) - fn(map[string]int(nil)) - fn(map[string]int32(nil)) - fn(map[string]float64(nil)) - fn(map[string]bool(nil)) - fn(map[uint8]interface{}(nil)) - fn(map[uint8]string(nil)) - fn(map[uint8][]byte(nil)) - fn(map[uint8]uint8(nil)) - fn(map[uint8]uint64(nil)) - fn(map[uint8]int(nil)) - fn(map[uint8]int32(nil)) - fn(map[uint8]float64(nil)) - fn(map[uint8]bool(nil)) - fn(map[uint64]interface{}(nil)) - fn(map[uint64]string(nil)) - fn(map[uint64][]byte(nil)) - fn(map[uint64]uint8(nil)) - fn(map[uint64]uint64(nil)) - fn(map[uint64]int(nil)) - fn(map[uint64]int32(nil)) - fn(map[uint64]float64(nil)) - fn(map[uint64]bool(nil)) - fn(map[int]interface{}(nil)) - fn(map[int]string(nil)) - fn(map[int][]byte(nil)) - fn(map[int]uint8(nil)) - fn(map[int]uint64(nil)) - fn(map[int]int(nil)) - fn(map[int]int32(nil)) - fn(map[int]float64(nil)) - fn(map[int]bool(nil)) - fn(map[int32]interface{}(nil)) - fn(map[int32]string(nil)) - fn(map[int32][]byte(nil)) - fn(map[int32]uint8(nil)) - fn(map[int32]uint64(nil)) - fn(map[int32]int(nil)) - fn(map[int32]int32(nil)) - fn(map[int32]float64(nil)) - fn(map[int32]bool(nil)) - - sort.Slice(fastpathAvRtid, func(i, j int) bool { return fastpathAvRtid[i] < fastpathAvRtid[j] }) - sort.Slice(fastpathAvRtRtid, func(i, j int) bool { return fastpathAvRtRtid[i].rtid < fastpathAvRtRtid[j].rtid }) - slices.Sort(encBuiltinRtids) - slices.Sort(decBuiltinRtids) -} - -func fastpathDecodeSetZeroTypeSwitch(iv interface{}) bool { - switch v := iv.(type) { - case *[]interface{}: - *v = nil - case *[]string: - *v = nil - case *[][]byte: - *v = nil - case *[]float32: - *v = nil - case *[]float64: - *v = nil - case *[]uint8: - *v = nil - case *[]uint64: - *v = nil - case *[]int: - *v = nil - case *[]int32: - *v = nil - case *[]int64: - *v = nil - case *[]bool: - *v = nil - - case *map[string]interface{}: - *v = nil - case *map[string]string: - *v = nil - case *map[string][]byte: - *v = nil - case *map[string]uint8: - *v = nil - case *map[string]uint64: - *v = nil - case *map[string]int: - *v = nil - case *map[string]int32: - *v = nil - case *map[string]float64: - *v = nil - case *map[string]bool: - *v = nil - case *map[uint8]interface{}: - *v = nil - case *map[uint8]string: - *v = nil - case *map[uint8][]byte: - *v = nil - case *map[uint8]uint8: - *v = nil - case *map[uint8]uint64: - *v = nil - case *map[uint8]int: - *v = nil - case *map[uint8]int32: - *v = nil - case *map[uint8]float64: - *v = nil - case *map[uint8]bool: - *v = nil - case *map[uint64]interface{}: - *v = nil - case *map[uint64]string: - *v = nil - case *map[uint64][]byte: - *v = nil - case *map[uint64]uint8: - *v = nil - case *map[uint64]uint64: - *v = nil - case *map[uint64]int: - *v = nil - case *map[uint64]int32: - *v = nil - case *map[uint64]float64: - *v = nil - case *map[uint64]bool: - *v = nil - case *map[int]interface{}: - *v = nil - case *map[int]string: - *v = nil - case *map[int][]byte: - *v = nil - case *map[int]uint8: - *v = nil - case *map[int]uint64: - *v = nil - case *map[int]int: - *v = nil - case *map[int]int32: - *v = nil - case *map[int]float64: - *v = nil - case *map[int]bool: - *v = nil - case *map[int32]interface{}: - *v = nil - case *map[int32]string: - *v = nil - case *map[int32][]byte: - *v = nil - case *map[int32]uint8: - *v = nil - case *map[int32]uint64: - *v = nil - case *map[int32]int: - *v = nil - case *map[int32]int32: - *v = nil - case *map[int32]float64: - *v = nil - case *map[int32]bool: - *v = nil - - default: - _ = v // workaround https://github.com/golang/go/issues/12927 seen in go1.4 - return false - } - return true -} diff --git a/vendor/github.com/ugorji/go/codec/base.fastpath.notmono.generated.go b/vendor/github.com/ugorji/go/codec/base.fastpath.notmono.generated.go deleted file mode 100644 index 572383463..000000000 --- a/vendor/github.com/ugorji/go/codec/base.fastpath.notmono.generated.go +++ /dev/null @@ -1,6259 +0,0 @@ -//go:build !notfastpath && !codec.notfastpath && (notmono || codec.notmono) - -// Copyright (c) 2012-2020 Ugorji Nwoke. All rights reserved. -// Use of this source code is governed by a MIT license found in the LICENSE file. - -// Code generated from fastpath.notmono.go.tmpl - DO NOT EDIT. - -package codec - -import ( - "reflect" - "slices" - "sort" -) - -type fastpathE[T encDriver] struct { - rtid uintptr - rt reflect.Type - encfn func(*encoder[T], *encFnInfo, reflect.Value) -} -type fastpathD[T decDriver] struct { - rtid uintptr - rt reflect.Type - decfn func(*decoder[T], *decFnInfo, reflect.Value) -} -type fastpathEs[T encDriver] [56]fastpathE[T] -type fastpathDs[T decDriver] [56]fastpathD[T] - -type fastpathET[T encDriver] struct{} -type fastpathDT[T decDriver] struct{} - -func (helperEncDriver[T]) fastpathEList() *fastpathEs[T] { - var i uint = 0 - var s fastpathEs[T] - fn := func(v interface{}, fe func(*encoder[T], *encFnInfo, reflect.Value)) { - xrt := reflect.TypeOf(v) - s[i] = fastpathE[T]{rt2id(xrt), xrt, fe} - i++ - } - - fn([]interface{}(nil), (*encoder[T]).fastpathEncSliceIntfR) - fn([]string(nil), (*encoder[T]).fastpathEncSliceStringR) - fn([][]byte(nil), (*encoder[T]).fastpathEncSliceBytesR) - fn([]float32(nil), (*encoder[T]).fastpathEncSliceFloat32R) - fn([]float64(nil), (*encoder[T]).fastpathEncSliceFloat64R) - fn([]uint8(nil), (*encoder[T]).fastpathEncSliceUint8R) - fn([]uint64(nil), (*encoder[T]).fastpathEncSliceUint64R) - fn([]int(nil), (*encoder[T]).fastpathEncSliceIntR) - fn([]int32(nil), (*encoder[T]).fastpathEncSliceInt32R) - fn([]int64(nil), (*encoder[T]).fastpathEncSliceInt64R) - fn([]bool(nil), (*encoder[T]).fastpathEncSliceBoolR) - - fn(map[string]interface{}(nil), (*encoder[T]).fastpathEncMapStringIntfR) - fn(map[string]string(nil), (*encoder[T]).fastpathEncMapStringStringR) - fn(map[string][]byte(nil), (*encoder[T]).fastpathEncMapStringBytesR) - fn(map[string]uint8(nil), (*encoder[T]).fastpathEncMapStringUint8R) - fn(map[string]uint64(nil), (*encoder[T]).fastpathEncMapStringUint64R) - fn(map[string]int(nil), (*encoder[T]).fastpathEncMapStringIntR) - fn(map[string]int32(nil), (*encoder[T]).fastpathEncMapStringInt32R) - fn(map[string]float64(nil), (*encoder[T]).fastpathEncMapStringFloat64R) - fn(map[string]bool(nil), (*encoder[T]).fastpathEncMapStringBoolR) - fn(map[uint8]interface{}(nil), (*encoder[T]).fastpathEncMapUint8IntfR) - fn(map[uint8]string(nil), (*encoder[T]).fastpathEncMapUint8StringR) - fn(map[uint8][]byte(nil), (*encoder[T]).fastpathEncMapUint8BytesR) - fn(map[uint8]uint8(nil), (*encoder[T]).fastpathEncMapUint8Uint8R) - fn(map[uint8]uint64(nil), (*encoder[T]).fastpathEncMapUint8Uint64R) - fn(map[uint8]int(nil), (*encoder[T]).fastpathEncMapUint8IntR) - fn(map[uint8]int32(nil), (*encoder[T]).fastpathEncMapUint8Int32R) - fn(map[uint8]float64(nil), (*encoder[T]).fastpathEncMapUint8Float64R) - fn(map[uint8]bool(nil), (*encoder[T]).fastpathEncMapUint8BoolR) - fn(map[uint64]interface{}(nil), (*encoder[T]).fastpathEncMapUint64IntfR) - fn(map[uint64]string(nil), (*encoder[T]).fastpathEncMapUint64StringR) - fn(map[uint64][]byte(nil), (*encoder[T]).fastpathEncMapUint64BytesR) - fn(map[uint64]uint8(nil), (*encoder[T]).fastpathEncMapUint64Uint8R) - fn(map[uint64]uint64(nil), (*encoder[T]).fastpathEncMapUint64Uint64R) - fn(map[uint64]int(nil), (*encoder[T]).fastpathEncMapUint64IntR) - fn(map[uint64]int32(nil), (*encoder[T]).fastpathEncMapUint64Int32R) - fn(map[uint64]float64(nil), (*encoder[T]).fastpathEncMapUint64Float64R) - fn(map[uint64]bool(nil), (*encoder[T]).fastpathEncMapUint64BoolR) - fn(map[int]interface{}(nil), (*encoder[T]).fastpathEncMapIntIntfR) - fn(map[int]string(nil), (*encoder[T]).fastpathEncMapIntStringR) - fn(map[int][]byte(nil), (*encoder[T]).fastpathEncMapIntBytesR) - fn(map[int]uint8(nil), (*encoder[T]).fastpathEncMapIntUint8R) - fn(map[int]uint64(nil), (*encoder[T]).fastpathEncMapIntUint64R) - fn(map[int]int(nil), (*encoder[T]).fastpathEncMapIntIntR) - fn(map[int]int32(nil), (*encoder[T]).fastpathEncMapIntInt32R) - fn(map[int]float64(nil), (*encoder[T]).fastpathEncMapIntFloat64R) - fn(map[int]bool(nil), (*encoder[T]).fastpathEncMapIntBoolR) - fn(map[int32]interface{}(nil), (*encoder[T]).fastpathEncMapInt32IntfR) - fn(map[int32]string(nil), (*encoder[T]).fastpathEncMapInt32StringR) - fn(map[int32][]byte(nil), (*encoder[T]).fastpathEncMapInt32BytesR) - fn(map[int32]uint8(nil), (*encoder[T]).fastpathEncMapInt32Uint8R) - fn(map[int32]uint64(nil), (*encoder[T]).fastpathEncMapInt32Uint64R) - fn(map[int32]int(nil), (*encoder[T]).fastpathEncMapInt32IntR) - fn(map[int32]int32(nil), (*encoder[T]).fastpathEncMapInt32Int32R) - fn(map[int32]float64(nil), (*encoder[T]).fastpathEncMapInt32Float64R) - fn(map[int32]bool(nil), (*encoder[T]).fastpathEncMapInt32BoolR) - - sort.Slice(s[:], func(i, j int) bool { return s[i].rtid < s[j].rtid }) - return &s -} - -func (helperDecDriver[T]) fastpathDList() *fastpathDs[T] { - var i uint = 0 - var s fastpathDs[T] - fn := func(v interface{}, fd func(*decoder[T], *decFnInfo, reflect.Value)) { - xrt := reflect.TypeOf(v) - s[i] = fastpathD[T]{rt2id(xrt), xrt, fd} - i++ - } - - fn([]interface{}(nil), (*decoder[T]).fastpathDecSliceIntfR) - fn([]string(nil), (*decoder[T]).fastpathDecSliceStringR) - fn([][]byte(nil), (*decoder[T]).fastpathDecSliceBytesR) - fn([]float32(nil), (*decoder[T]).fastpathDecSliceFloat32R) - fn([]float64(nil), (*decoder[T]).fastpathDecSliceFloat64R) - fn([]uint8(nil), (*decoder[T]).fastpathDecSliceUint8R) - fn([]uint64(nil), (*decoder[T]).fastpathDecSliceUint64R) - fn([]int(nil), (*decoder[T]).fastpathDecSliceIntR) - fn([]int32(nil), (*decoder[T]).fastpathDecSliceInt32R) - fn([]int64(nil), (*decoder[T]).fastpathDecSliceInt64R) - fn([]bool(nil), (*decoder[T]).fastpathDecSliceBoolR) - - fn(map[string]interface{}(nil), (*decoder[T]).fastpathDecMapStringIntfR) - fn(map[string]string(nil), (*decoder[T]).fastpathDecMapStringStringR) - fn(map[string][]byte(nil), (*decoder[T]).fastpathDecMapStringBytesR) - fn(map[string]uint8(nil), (*decoder[T]).fastpathDecMapStringUint8R) - fn(map[string]uint64(nil), (*decoder[T]).fastpathDecMapStringUint64R) - fn(map[string]int(nil), (*decoder[T]).fastpathDecMapStringIntR) - fn(map[string]int32(nil), (*decoder[T]).fastpathDecMapStringInt32R) - fn(map[string]float64(nil), (*decoder[T]).fastpathDecMapStringFloat64R) - fn(map[string]bool(nil), (*decoder[T]).fastpathDecMapStringBoolR) - fn(map[uint8]interface{}(nil), (*decoder[T]).fastpathDecMapUint8IntfR) - fn(map[uint8]string(nil), (*decoder[T]).fastpathDecMapUint8StringR) - fn(map[uint8][]byte(nil), (*decoder[T]).fastpathDecMapUint8BytesR) - fn(map[uint8]uint8(nil), (*decoder[T]).fastpathDecMapUint8Uint8R) - fn(map[uint8]uint64(nil), (*decoder[T]).fastpathDecMapUint8Uint64R) - fn(map[uint8]int(nil), (*decoder[T]).fastpathDecMapUint8IntR) - fn(map[uint8]int32(nil), (*decoder[T]).fastpathDecMapUint8Int32R) - fn(map[uint8]float64(nil), (*decoder[T]).fastpathDecMapUint8Float64R) - fn(map[uint8]bool(nil), (*decoder[T]).fastpathDecMapUint8BoolR) - fn(map[uint64]interface{}(nil), (*decoder[T]).fastpathDecMapUint64IntfR) - fn(map[uint64]string(nil), (*decoder[T]).fastpathDecMapUint64StringR) - fn(map[uint64][]byte(nil), (*decoder[T]).fastpathDecMapUint64BytesR) - fn(map[uint64]uint8(nil), (*decoder[T]).fastpathDecMapUint64Uint8R) - fn(map[uint64]uint64(nil), (*decoder[T]).fastpathDecMapUint64Uint64R) - fn(map[uint64]int(nil), (*decoder[T]).fastpathDecMapUint64IntR) - fn(map[uint64]int32(nil), (*decoder[T]).fastpathDecMapUint64Int32R) - fn(map[uint64]float64(nil), (*decoder[T]).fastpathDecMapUint64Float64R) - fn(map[uint64]bool(nil), (*decoder[T]).fastpathDecMapUint64BoolR) - fn(map[int]interface{}(nil), (*decoder[T]).fastpathDecMapIntIntfR) - fn(map[int]string(nil), (*decoder[T]).fastpathDecMapIntStringR) - fn(map[int][]byte(nil), (*decoder[T]).fastpathDecMapIntBytesR) - fn(map[int]uint8(nil), (*decoder[T]).fastpathDecMapIntUint8R) - fn(map[int]uint64(nil), (*decoder[T]).fastpathDecMapIntUint64R) - fn(map[int]int(nil), (*decoder[T]).fastpathDecMapIntIntR) - fn(map[int]int32(nil), (*decoder[T]).fastpathDecMapIntInt32R) - fn(map[int]float64(nil), (*decoder[T]).fastpathDecMapIntFloat64R) - fn(map[int]bool(nil), (*decoder[T]).fastpathDecMapIntBoolR) - fn(map[int32]interface{}(nil), (*decoder[T]).fastpathDecMapInt32IntfR) - fn(map[int32]string(nil), (*decoder[T]).fastpathDecMapInt32StringR) - fn(map[int32][]byte(nil), (*decoder[T]).fastpathDecMapInt32BytesR) - fn(map[int32]uint8(nil), (*decoder[T]).fastpathDecMapInt32Uint8R) - fn(map[int32]uint64(nil), (*decoder[T]).fastpathDecMapInt32Uint64R) - fn(map[int32]int(nil), (*decoder[T]).fastpathDecMapInt32IntR) - fn(map[int32]int32(nil), (*decoder[T]).fastpathDecMapInt32Int32R) - fn(map[int32]float64(nil), (*decoder[T]).fastpathDecMapInt32Float64R) - fn(map[int32]bool(nil), (*decoder[T]).fastpathDecMapInt32BoolR) - - sort.Slice(s[:], func(i, j int) bool { return s[i].rtid < s[j].rtid }) - return &s -} - -// -- encode - -// -- -- fast path type switch -func (helperEncDriver[T]) fastpathEncodeTypeSwitch(iv interface{}, e *encoder[T]) bool { - var ft fastpathET[T] - switch v := iv.(type) { - case []interface{}: - if v == nil { - e.e.writeNilArray() - } else { - ft.EncSliceIntfV(v, e) - } - case []string: - if v == nil { - e.e.writeNilArray() - } else { - ft.EncSliceStringV(v, e) - } - case [][]byte: - if v == nil { - e.e.writeNilArray() - } else { - ft.EncSliceBytesV(v, e) - } - case []float32: - if v == nil { - e.e.writeNilArray() - } else { - ft.EncSliceFloat32V(v, e) - } - case []float64: - if v == nil { - e.e.writeNilArray() - } else { - ft.EncSliceFloat64V(v, e) - } - case []uint8: - if v == nil { - e.e.writeNilArray() - } else { - ft.EncSliceUint8V(v, e) - } - case []uint64: - if v == nil { - e.e.writeNilArray() - } else { - ft.EncSliceUint64V(v, e) - } - case []int: - if v == nil { - e.e.writeNilArray() - } else { - ft.EncSliceIntV(v, e) - } - case []int32: - if v == nil { - e.e.writeNilArray() - } else { - ft.EncSliceInt32V(v, e) - } - case []int64: - if v == nil { - e.e.writeNilArray() - } else { - ft.EncSliceInt64V(v, e) - } - case []bool: - if v == nil { - e.e.writeNilArray() - } else { - ft.EncSliceBoolV(v, e) - } - case map[string]interface{}: - if v == nil { - e.e.writeNilMap() - } else { - ft.EncMapStringIntfV(v, e) - } - case map[string]string: - if v == nil { - e.e.writeNilMap() - } else { - ft.EncMapStringStringV(v, e) - } - case map[string][]byte: - if v == nil { - e.e.writeNilMap() - } else { - ft.EncMapStringBytesV(v, e) - } - case map[string]uint8: - if v == nil { - e.e.writeNilMap() - } else { - ft.EncMapStringUint8V(v, e) - } - case map[string]uint64: - if v == nil { - e.e.writeNilMap() - } else { - ft.EncMapStringUint64V(v, e) - } - case map[string]int: - if v == nil { - e.e.writeNilMap() - } else { - ft.EncMapStringIntV(v, e) - } - case map[string]int32: - if v == nil { - e.e.writeNilMap() - } else { - ft.EncMapStringInt32V(v, e) - } - case map[string]float64: - if v == nil { - e.e.writeNilMap() - } else { - ft.EncMapStringFloat64V(v, e) - } - case map[string]bool: - if v == nil { - e.e.writeNilMap() - } else { - ft.EncMapStringBoolV(v, e) - } - case map[uint8]interface{}: - if v == nil { - e.e.writeNilMap() - } else { - ft.EncMapUint8IntfV(v, e) - } - case map[uint8]string: - if v == nil { - e.e.writeNilMap() - } else { - ft.EncMapUint8StringV(v, e) - } - case map[uint8][]byte: - if v == nil { - e.e.writeNilMap() - } else { - ft.EncMapUint8BytesV(v, e) - } - case map[uint8]uint8: - if v == nil { - e.e.writeNilMap() - } else { - ft.EncMapUint8Uint8V(v, e) - } - case map[uint8]uint64: - if v == nil { - e.e.writeNilMap() - } else { - ft.EncMapUint8Uint64V(v, e) - } - case map[uint8]int: - if v == nil { - e.e.writeNilMap() - } else { - ft.EncMapUint8IntV(v, e) - } - case map[uint8]int32: - if v == nil { - e.e.writeNilMap() - } else { - ft.EncMapUint8Int32V(v, e) - } - case map[uint8]float64: - if v == nil { - e.e.writeNilMap() - } else { - ft.EncMapUint8Float64V(v, e) - } - case map[uint8]bool: - if v == nil { - e.e.writeNilMap() - } else { - ft.EncMapUint8BoolV(v, e) - } - case map[uint64]interface{}: - if v == nil { - e.e.writeNilMap() - } else { - ft.EncMapUint64IntfV(v, e) - } - case map[uint64]string: - if v == nil { - e.e.writeNilMap() - } else { - ft.EncMapUint64StringV(v, e) - } - case map[uint64][]byte: - if v == nil { - e.e.writeNilMap() - } else { - ft.EncMapUint64BytesV(v, e) - } - case map[uint64]uint8: - if v == nil { - e.e.writeNilMap() - } else { - ft.EncMapUint64Uint8V(v, e) - } - case map[uint64]uint64: - if v == nil { - e.e.writeNilMap() - } else { - ft.EncMapUint64Uint64V(v, e) - } - case map[uint64]int: - if v == nil { - e.e.writeNilMap() - } else { - ft.EncMapUint64IntV(v, e) - } - case map[uint64]int32: - if v == nil { - e.e.writeNilMap() - } else { - ft.EncMapUint64Int32V(v, e) - } - case map[uint64]float64: - if v == nil { - e.e.writeNilMap() - } else { - ft.EncMapUint64Float64V(v, e) - } - case map[uint64]bool: - if v == nil { - e.e.writeNilMap() - } else { - ft.EncMapUint64BoolV(v, e) - } - case map[int]interface{}: - if v == nil { - e.e.writeNilMap() - } else { - ft.EncMapIntIntfV(v, e) - } - case map[int]string: - if v == nil { - e.e.writeNilMap() - } else { - ft.EncMapIntStringV(v, e) - } - case map[int][]byte: - if v == nil { - e.e.writeNilMap() - } else { - ft.EncMapIntBytesV(v, e) - } - case map[int]uint8: - if v == nil { - e.e.writeNilMap() - } else { - ft.EncMapIntUint8V(v, e) - } - case map[int]uint64: - if v == nil { - e.e.writeNilMap() - } else { - ft.EncMapIntUint64V(v, e) - } - case map[int]int: - if v == nil { - e.e.writeNilMap() - } else { - ft.EncMapIntIntV(v, e) - } - case map[int]int32: - if v == nil { - e.e.writeNilMap() - } else { - ft.EncMapIntInt32V(v, e) - } - case map[int]float64: - if v == nil { - e.e.writeNilMap() - } else { - ft.EncMapIntFloat64V(v, e) - } - case map[int]bool: - if v == nil { - e.e.writeNilMap() - } else { - ft.EncMapIntBoolV(v, e) - } - case map[int32]interface{}: - if v == nil { - e.e.writeNilMap() - } else { - ft.EncMapInt32IntfV(v, e) - } - case map[int32]string: - if v == nil { - e.e.writeNilMap() - } else { - ft.EncMapInt32StringV(v, e) - } - case map[int32][]byte: - if v == nil { - e.e.writeNilMap() - } else { - ft.EncMapInt32BytesV(v, e) - } - case map[int32]uint8: - if v == nil { - e.e.writeNilMap() - } else { - ft.EncMapInt32Uint8V(v, e) - } - case map[int32]uint64: - if v == nil { - e.e.writeNilMap() - } else { - ft.EncMapInt32Uint64V(v, e) - } - case map[int32]int: - if v == nil { - e.e.writeNilMap() - } else { - ft.EncMapInt32IntV(v, e) - } - case map[int32]int32: - if v == nil { - e.e.writeNilMap() - } else { - ft.EncMapInt32Int32V(v, e) - } - case map[int32]float64: - if v == nil { - e.e.writeNilMap() - } else { - ft.EncMapInt32Float64V(v, e) - } - case map[int32]bool: - if v == nil { - e.e.writeNilMap() - } else { - ft.EncMapInt32BoolV(v, e) - } - default: - _ = v // workaround https://github.com/golang/go/issues/12927 seen in go1.4 - return false - } - return true -} - -// -- -- fast path functions -func (e *encoder[T]) fastpathEncSliceIntfR(f *encFnInfo, rv reflect.Value) { - var ft fastpathET[T] - var v []interface{} - if rv.Kind() == reflect.Array { - rvGetSlice4Array(rv, &v) - } else { - v = rv2i(rv).([]interface{}) - } - if f.ti.mbs { - ft.EncAsMapSliceIntfV(v, e) - return - } - ft.EncSliceIntfV(v, e) -} -func (fastpathET[T]) EncSliceIntfV(v []interface{}, e *encoder[T]) { - if len(v) == 0 { - e.c = 0 - e.e.WriteArrayEmpty() - return - } - e.arrayStart(len(v)) - for j := range v { - e.c = containerArrayElem - e.e.WriteArrayElem(j == 0) - if !e.encodeBuiltin(v[j]) { - e.encodeR(reflect.ValueOf(v[j])) - } - } - e.c = 0 - e.e.WriteArrayEnd() -} -func (fastpathET[T]) EncAsMapSliceIntfV(v []interface{}, e *encoder[T]) { - if len(v) == 0 { - e.c = 0 - e.e.WriteMapEmpty() - return - } - e.haltOnMbsOddLen(len(v)) - e.mapStart(len(v) >> 1) // e.mapStart(len(v) / 2) - for j := range v { - if j&1 == 0 { // if j%2 == 0 { - e.c = containerMapKey - e.e.WriteMapElemKey(j == 0) - } else { - e.mapElemValue() - } - if !e.encodeBuiltin(v[j]) { - e.encodeR(reflect.ValueOf(v[j])) - } - } - e.c = 0 - e.e.WriteMapEnd() -} - -func (e *encoder[T]) fastpathEncSliceStringR(f *encFnInfo, rv reflect.Value) { - var ft fastpathET[T] - var v []string - if rv.Kind() == reflect.Array { - rvGetSlice4Array(rv, &v) - } else { - v = rv2i(rv).([]string) - } - if f.ti.mbs { - ft.EncAsMapSliceStringV(v, e) - return - } - ft.EncSliceStringV(v, e) -} -func (fastpathET[T]) EncSliceStringV(v []string, e *encoder[T]) { - if len(v) == 0 { - e.c = 0 - e.e.WriteArrayEmpty() - return - } - e.arrayStart(len(v)) - for j := range v { - e.c = containerArrayElem - e.e.WriteArrayElem(j == 0) - e.e.EncodeString(v[j]) - } - e.c = 0 - e.e.WriteArrayEnd() -} -func (fastpathET[T]) EncAsMapSliceStringV(v []string, e *encoder[T]) { - if len(v) == 0 { - e.c = 0 - e.e.WriteMapEmpty() - return - } - e.haltOnMbsOddLen(len(v)) - e.mapStart(len(v) >> 1) // e.mapStart(len(v) / 2) - for j := range v { - if j&1 == 0 { // if j%2 == 0 { - e.c = containerMapKey - e.e.WriteMapElemKey(j == 0) - } else { - e.mapElemValue() - } - e.e.EncodeString(v[j]) - } - e.c = 0 - e.e.WriteMapEnd() -} - -func (e *encoder[T]) fastpathEncSliceBytesR(f *encFnInfo, rv reflect.Value) { - var ft fastpathET[T] - var v [][]byte - if rv.Kind() == reflect.Array { - rvGetSlice4Array(rv, &v) - } else { - v = rv2i(rv).([][]byte) - } - if f.ti.mbs { - ft.EncAsMapSliceBytesV(v, e) - return - } - ft.EncSliceBytesV(v, e) -} -func (fastpathET[T]) EncSliceBytesV(v [][]byte, e *encoder[T]) { - if len(v) == 0 { - e.c = 0 - e.e.WriteArrayEmpty() - return - } - e.arrayStart(len(v)) - for j := range v { - e.c = containerArrayElem - e.e.WriteArrayElem(j == 0) - e.e.EncodeBytes(v[j]) - } - e.c = 0 - e.e.WriteArrayEnd() -} -func (fastpathET[T]) EncAsMapSliceBytesV(v [][]byte, e *encoder[T]) { - if len(v) == 0 { - e.c = 0 - e.e.WriteMapEmpty() - return - } - e.haltOnMbsOddLen(len(v)) - e.mapStart(len(v) >> 1) // e.mapStart(len(v) / 2) - for j := range v { - if j&1 == 0 { // if j%2 == 0 { - e.c = containerMapKey - e.e.WriteMapElemKey(j == 0) - } else { - e.mapElemValue() - } - e.e.EncodeBytes(v[j]) - } - e.c = 0 - e.e.WriteMapEnd() -} - -func (e *encoder[T]) fastpathEncSliceFloat32R(f *encFnInfo, rv reflect.Value) { - var ft fastpathET[T] - var v []float32 - if rv.Kind() == reflect.Array { - rvGetSlice4Array(rv, &v) - } else { - v = rv2i(rv).([]float32) - } - if f.ti.mbs { - ft.EncAsMapSliceFloat32V(v, e) - return - } - ft.EncSliceFloat32V(v, e) -} -func (fastpathET[T]) EncSliceFloat32V(v []float32, e *encoder[T]) { - if len(v) == 0 { - e.c = 0 - e.e.WriteArrayEmpty() - return - } - e.arrayStart(len(v)) - for j := range v { - e.c = containerArrayElem - e.e.WriteArrayElem(j == 0) - e.e.EncodeFloat32(v[j]) - } - e.c = 0 - e.e.WriteArrayEnd() -} -func (fastpathET[T]) EncAsMapSliceFloat32V(v []float32, e *encoder[T]) { - if len(v) == 0 { - e.c = 0 - e.e.WriteMapEmpty() - return - } - e.haltOnMbsOddLen(len(v)) - e.mapStart(len(v) >> 1) // e.mapStart(len(v) / 2) - for j := range v { - if j&1 == 0 { // if j%2 == 0 { - e.c = containerMapKey - e.e.WriteMapElemKey(j == 0) - } else { - e.mapElemValue() - } - e.e.EncodeFloat32(v[j]) - } - e.c = 0 - e.e.WriteMapEnd() -} - -func (e *encoder[T]) fastpathEncSliceFloat64R(f *encFnInfo, rv reflect.Value) { - var ft fastpathET[T] - var v []float64 - if rv.Kind() == reflect.Array { - rvGetSlice4Array(rv, &v) - } else { - v = rv2i(rv).([]float64) - } - if f.ti.mbs { - ft.EncAsMapSliceFloat64V(v, e) - return - } - ft.EncSliceFloat64V(v, e) -} -func (fastpathET[T]) EncSliceFloat64V(v []float64, e *encoder[T]) { - if len(v) == 0 { - e.c = 0 - e.e.WriteArrayEmpty() - return - } - e.arrayStart(len(v)) - for j := range v { - e.c = containerArrayElem - e.e.WriteArrayElem(j == 0) - e.e.EncodeFloat64(v[j]) - } - e.c = 0 - e.e.WriteArrayEnd() -} -func (fastpathET[T]) EncAsMapSliceFloat64V(v []float64, e *encoder[T]) { - if len(v) == 0 { - e.c = 0 - e.e.WriteMapEmpty() - return - } - e.haltOnMbsOddLen(len(v)) - e.mapStart(len(v) >> 1) // e.mapStart(len(v) / 2) - for j := range v { - if j&1 == 0 { // if j%2 == 0 { - e.c = containerMapKey - e.e.WriteMapElemKey(j == 0) - } else { - e.mapElemValue() - } - e.e.EncodeFloat64(v[j]) - } - e.c = 0 - e.e.WriteMapEnd() -} - -func (e *encoder[T]) fastpathEncSliceUint8R(f *encFnInfo, rv reflect.Value) { - var ft fastpathET[T] - var v []uint8 - if rv.Kind() == reflect.Array { - rvGetSlice4Array(rv, &v) - } else { - v = rv2i(rv).([]uint8) - } - if f.ti.mbs { - ft.EncAsMapSliceUint8V(v, e) - return - } - ft.EncSliceUint8V(v, e) -} -func (fastpathET[T]) EncSliceUint8V(v []uint8, e *encoder[T]) { - e.e.EncodeStringBytesRaw(v) -} -func (fastpathET[T]) EncAsMapSliceUint8V(v []uint8, e *encoder[T]) { - if len(v) == 0 { - e.c = 0 - e.e.WriteMapEmpty() - return - } - e.haltOnMbsOddLen(len(v)) - e.mapStart(len(v) >> 1) // e.mapStart(len(v) / 2) - for j := range v { - if j&1 == 0 { // if j%2 == 0 { - e.c = containerMapKey - e.e.WriteMapElemKey(j == 0) - } else { - e.mapElemValue() - } - e.e.EncodeUint(uint64(v[j])) - } - e.c = 0 - e.e.WriteMapEnd() -} - -func (e *encoder[T]) fastpathEncSliceUint64R(f *encFnInfo, rv reflect.Value) { - var ft fastpathET[T] - var v []uint64 - if rv.Kind() == reflect.Array { - rvGetSlice4Array(rv, &v) - } else { - v = rv2i(rv).([]uint64) - } - if f.ti.mbs { - ft.EncAsMapSliceUint64V(v, e) - return - } - ft.EncSliceUint64V(v, e) -} -func (fastpathET[T]) EncSliceUint64V(v []uint64, e *encoder[T]) { - if len(v) == 0 { - e.c = 0 - e.e.WriteArrayEmpty() - return - } - e.arrayStart(len(v)) - for j := range v { - e.c = containerArrayElem - e.e.WriteArrayElem(j == 0) - e.e.EncodeUint(v[j]) - } - e.c = 0 - e.e.WriteArrayEnd() -} -func (fastpathET[T]) EncAsMapSliceUint64V(v []uint64, e *encoder[T]) { - if len(v) == 0 { - e.c = 0 - e.e.WriteMapEmpty() - return - } - e.haltOnMbsOddLen(len(v)) - e.mapStart(len(v) >> 1) // e.mapStart(len(v) / 2) - for j := range v { - if j&1 == 0 { // if j%2 == 0 { - e.c = containerMapKey - e.e.WriteMapElemKey(j == 0) - } else { - e.mapElemValue() - } - e.e.EncodeUint(v[j]) - } - e.c = 0 - e.e.WriteMapEnd() -} - -func (e *encoder[T]) fastpathEncSliceIntR(f *encFnInfo, rv reflect.Value) { - var ft fastpathET[T] - var v []int - if rv.Kind() == reflect.Array { - rvGetSlice4Array(rv, &v) - } else { - v = rv2i(rv).([]int) - } - if f.ti.mbs { - ft.EncAsMapSliceIntV(v, e) - return - } - ft.EncSliceIntV(v, e) -} -func (fastpathET[T]) EncSliceIntV(v []int, e *encoder[T]) { - if len(v) == 0 { - e.c = 0 - e.e.WriteArrayEmpty() - return - } - e.arrayStart(len(v)) - for j := range v { - e.c = containerArrayElem - e.e.WriteArrayElem(j == 0) - e.e.EncodeInt(int64(v[j])) - } - e.c = 0 - e.e.WriteArrayEnd() -} -func (fastpathET[T]) EncAsMapSliceIntV(v []int, e *encoder[T]) { - if len(v) == 0 { - e.c = 0 - e.e.WriteMapEmpty() - return - } - e.haltOnMbsOddLen(len(v)) - e.mapStart(len(v) >> 1) // e.mapStart(len(v) / 2) - for j := range v { - if j&1 == 0 { // if j%2 == 0 { - e.c = containerMapKey - e.e.WriteMapElemKey(j == 0) - } else { - e.mapElemValue() - } - e.e.EncodeInt(int64(v[j])) - } - e.c = 0 - e.e.WriteMapEnd() -} - -func (e *encoder[T]) fastpathEncSliceInt32R(f *encFnInfo, rv reflect.Value) { - var ft fastpathET[T] - var v []int32 - if rv.Kind() == reflect.Array { - rvGetSlice4Array(rv, &v) - } else { - v = rv2i(rv).([]int32) - } - if f.ti.mbs { - ft.EncAsMapSliceInt32V(v, e) - return - } - ft.EncSliceInt32V(v, e) -} -func (fastpathET[T]) EncSliceInt32V(v []int32, e *encoder[T]) { - if len(v) == 0 { - e.c = 0 - e.e.WriteArrayEmpty() - return - } - e.arrayStart(len(v)) - for j := range v { - e.c = containerArrayElem - e.e.WriteArrayElem(j == 0) - e.e.EncodeInt(int64(v[j])) - } - e.c = 0 - e.e.WriteArrayEnd() -} -func (fastpathET[T]) EncAsMapSliceInt32V(v []int32, e *encoder[T]) { - if len(v) == 0 { - e.c = 0 - e.e.WriteMapEmpty() - return - } - e.haltOnMbsOddLen(len(v)) - e.mapStart(len(v) >> 1) // e.mapStart(len(v) / 2) - for j := range v { - if j&1 == 0 { // if j%2 == 0 { - e.c = containerMapKey - e.e.WriteMapElemKey(j == 0) - } else { - e.mapElemValue() - } - e.e.EncodeInt(int64(v[j])) - } - e.c = 0 - e.e.WriteMapEnd() -} - -func (e *encoder[T]) fastpathEncSliceInt64R(f *encFnInfo, rv reflect.Value) { - var ft fastpathET[T] - var v []int64 - if rv.Kind() == reflect.Array { - rvGetSlice4Array(rv, &v) - } else { - v = rv2i(rv).([]int64) - } - if f.ti.mbs { - ft.EncAsMapSliceInt64V(v, e) - return - } - ft.EncSliceInt64V(v, e) -} -func (fastpathET[T]) EncSliceInt64V(v []int64, e *encoder[T]) { - if len(v) == 0 { - e.c = 0 - e.e.WriteArrayEmpty() - return - } - e.arrayStart(len(v)) - for j := range v { - e.c = containerArrayElem - e.e.WriteArrayElem(j == 0) - e.e.EncodeInt(v[j]) - } - e.c = 0 - e.e.WriteArrayEnd() -} -func (fastpathET[T]) EncAsMapSliceInt64V(v []int64, e *encoder[T]) { - if len(v) == 0 { - e.c = 0 - e.e.WriteMapEmpty() - return - } - e.haltOnMbsOddLen(len(v)) - e.mapStart(len(v) >> 1) // e.mapStart(len(v) / 2) - for j := range v { - if j&1 == 0 { // if j%2 == 0 { - e.c = containerMapKey - e.e.WriteMapElemKey(j == 0) - } else { - e.mapElemValue() - } - e.e.EncodeInt(v[j]) - } - e.c = 0 - e.e.WriteMapEnd() -} - -func (e *encoder[T]) fastpathEncSliceBoolR(f *encFnInfo, rv reflect.Value) { - var ft fastpathET[T] - var v []bool - if rv.Kind() == reflect.Array { - rvGetSlice4Array(rv, &v) - } else { - v = rv2i(rv).([]bool) - } - if f.ti.mbs { - ft.EncAsMapSliceBoolV(v, e) - return - } - ft.EncSliceBoolV(v, e) -} -func (fastpathET[T]) EncSliceBoolV(v []bool, e *encoder[T]) { - if len(v) == 0 { - e.c = 0 - e.e.WriteArrayEmpty() - return - } - e.arrayStart(len(v)) - for j := range v { - e.c = containerArrayElem - e.e.WriteArrayElem(j == 0) - e.e.EncodeBool(v[j]) - } - e.c = 0 - e.e.WriteArrayEnd() -} -func (fastpathET[T]) EncAsMapSliceBoolV(v []bool, e *encoder[T]) { - if len(v) == 0 { - e.c = 0 - e.e.WriteMapEmpty() - return - } - e.haltOnMbsOddLen(len(v)) - e.mapStart(len(v) >> 1) // e.mapStart(len(v) / 2) - for j := range v { - if j&1 == 0 { // if j%2 == 0 { - e.c = containerMapKey - e.e.WriteMapElemKey(j == 0) - } else { - e.mapElemValue() - } - e.e.EncodeBool(v[j]) - } - e.c = 0 - e.e.WriteMapEnd() -} - -func (e *encoder[T]) fastpathEncMapStringIntfR(f *encFnInfo, rv reflect.Value) { - fastpathET[T]{}.EncMapStringIntfV(rv2i(rv).(map[string]interface{}), e) -} -func (fastpathET[T]) EncMapStringIntfV(v map[string]interface{}, e *encoder[T]) { - if len(v) == 0 { - e.e.WriteMapEmpty() - return - } - var i uint - e.mapStart(len(v)) - if e.h.Canonical { - v2 := make([]string, len(v)) - for k := range v { - v2[i] = k - i++ - } - slices.Sort(v2) - for i, k2 := range v2 { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeString(k2) - e.mapElemValue() - if !e.encodeBuiltin(v[k2]) { - e.encodeR(reflect.ValueOf(v[k2])) - } - } - } else { - i = 0 - for k2, v2 := range v { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeString(k2) - e.mapElemValue() - if !e.encodeBuiltin(v2) { - e.encodeR(reflect.ValueOf(v2)) - } - i++ - } - } - e.c = 0 - e.e.WriteMapEnd() -} -func (e *encoder[T]) fastpathEncMapStringStringR(f *encFnInfo, rv reflect.Value) { - fastpathET[T]{}.EncMapStringStringV(rv2i(rv).(map[string]string), e) -} -func (fastpathET[T]) EncMapStringStringV(v map[string]string, e *encoder[T]) { - if len(v) == 0 { - e.e.WriteMapEmpty() - return - } - var i uint - e.mapStart(len(v)) - if e.h.Canonical { - v2 := make([]string, len(v)) - for k := range v { - v2[i] = k - i++ - } - slices.Sort(v2) - for i, k2 := range v2 { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeString(k2) - e.mapElemValue() - e.e.EncodeString(v[k2]) - } - } else { - i = 0 - for k2, v2 := range v { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeString(k2) - e.mapElemValue() - e.e.EncodeString(v2) - i++ - } - } - e.c = 0 - e.e.WriteMapEnd() -} -func (e *encoder[T]) fastpathEncMapStringBytesR(f *encFnInfo, rv reflect.Value) { - fastpathET[T]{}.EncMapStringBytesV(rv2i(rv).(map[string][]byte), e) -} -func (fastpathET[T]) EncMapStringBytesV(v map[string][]byte, e *encoder[T]) { - if len(v) == 0 { - e.e.WriteMapEmpty() - return - } - var i uint - e.mapStart(len(v)) - if e.h.Canonical { - v2 := make([]string, len(v)) - for k := range v { - v2[i] = k - i++ - } - slices.Sort(v2) - for i, k2 := range v2 { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeString(k2) - e.mapElemValue() - e.e.EncodeBytes(v[k2]) - } - } else { - i = 0 - for k2, v2 := range v { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeString(k2) - e.mapElemValue() - e.e.EncodeBytes(v2) - i++ - } - } - e.c = 0 - e.e.WriteMapEnd() -} -func (e *encoder[T]) fastpathEncMapStringUint8R(f *encFnInfo, rv reflect.Value) { - fastpathET[T]{}.EncMapStringUint8V(rv2i(rv).(map[string]uint8), e) -} -func (fastpathET[T]) EncMapStringUint8V(v map[string]uint8, e *encoder[T]) { - if len(v) == 0 { - e.e.WriteMapEmpty() - return - } - var i uint - e.mapStart(len(v)) - if e.h.Canonical { - v2 := make([]string, len(v)) - for k := range v { - v2[i] = k - i++ - } - slices.Sort(v2) - for i, k2 := range v2 { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeString(k2) - e.mapElemValue() - e.e.EncodeUint(uint64(v[k2])) - } - } else { - i = 0 - for k2, v2 := range v { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeString(k2) - e.mapElemValue() - e.e.EncodeUint(uint64(v2)) - i++ - } - } - e.c = 0 - e.e.WriteMapEnd() -} -func (e *encoder[T]) fastpathEncMapStringUint64R(f *encFnInfo, rv reflect.Value) { - fastpathET[T]{}.EncMapStringUint64V(rv2i(rv).(map[string]uint64), e) -} -func (fastpathET[T]) EncMapStringUint64V(v map[string]uint64, e *encoder[T]) { - if len(v) == 0 { - e.e.WriteMapEmpty() - return - } - var i uint - e.mapStart(len(v)) - if e.h.Canonical { - v2 := make([]string, len(v)) - for k := range v { - v2[i] = k - i++ - } - slices.Sort(v2) - for i, k2 := range v2 { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeString(k2) - e.mapElemValue() - e.e.EncodeUint(v[k2]) - } - } else { - i = 0 - for k2, v2 := range v { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeString(k2) - e.mapElemValue() - e.e.EncodeUint(v2) - i++ - } - } - e.c = 0 - e.e.WriteMapEnd() -} -func (e *encoder[T]) fastpathEncMapStringIntR(f *encFnInfo, rv reflect.Value) { - fastpathET[T]{}.EncMapStringIntV(rv2i(rv).(map[string]int), e) -} -func (fastpathET[T]) EncMapStringIntV(v map[string]int, e *encoder[T]) { - if len(v) == 0 { - e.e.WriteMapEmpty() - return - } - var i uint - e.mapStart(len(v)) - if e.h.Canonical { - v2 := make([]string, len(v)) - for k := range v { - v2[i] = k - i++ - } - slices.Sort(v2) - for i, k2 := range v2 { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeString(k2) - e.mapElemValue() - e.e.EncodeInt(int64(v[k2])) - } - } else { - i = 0 - for k2, v2 := range v { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeString(k2) - e.mapElemValue() - e.e.EncodeInt(int64(v2)) - i++ - } - } - e.c = 0 - e.e.WriteMapEnd() -} -func (e *encoder[T]) fastpathEncMapStringInt32R(f *encFnInfo, rv reflect.Value) { - fastpathET[T]{}.EncMapStringInt32V(rv2i(rv).(map[string]int32), e) -} -func (fastpathET[T]) EncMapStringInt32V(v map[string]int32, e *encoder[T]) { - if len(v) == 0 { - e.e.WriteMapEmpty() - return - } - var i uint - e.mapStart(len(v)) - if e.h.Canonical { - v2 := make([]string, len(v)) - for k := range v { - v2[i] = k - i++ - } - slices.Sort(v2) - for i, k2 := range v2 { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeString(k2) - e.mapElemValue() - e.e.EncodeInt(int64(v[k2])) - } - } else { - i = 0 - for k2, v2 := range v { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeString(k2) - e.mapElemValue() - e.e.EncodeInt(int64(v2)) - i++ - } - } - e.c = 0 - e.e.WriteMapEnd() -} -func (e *encoder[T]) fastpathEncMapStringFloat64R(f *encFnInfo, rv reflect.Value) { - fastpathET[T]{}.EncMapStringFloat64V(rv2i(rv).(map[string]float64), e) -} -func (fastpathET[T]) EncMapStringFloat64V(v map[string]float64, e *encoder[T]) { - if len(v) == 0 { - e.e.WriteMapEmpty() - return - } - var i uint - e.mapStart(len(v)) - if e.h.Canonical { - v2 := make([]string, len(v)) - for k := range v { - v2[i] = k - i++ - } - slices.Sort(v2) - for i, k2 := range v2 { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeString(k2) - e.mapElemValue() - e.e.EncodeFloat64(v[k2]) - } - } else { - i = 0 - for k2, v2 := range v { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeString(k2) - e.mapElemValue() - e.e.EncodeFloat64(v2) - i++ - } - } - e.c = 0 - e.e.WriteMapEnd() -} -func (e *encoder[T]) fastpathEncMapStringBoolR(f *encFnInfo, rv reflect.Value) { - fastpathET[T]{}.EncMapStringBoolV(rv2i(rv).(map[string]bool), e) -} -func (fastpathET[T]) EncMapStringBoolV(v map[string]bool, e *encoder[T]) { - if len(v) == 0 { - e.e.WriteMapEmpty() - return - } - var i uint - e.mapStart(len(v)) - if e.h.Canonical { - v2 := make([]string, len(v)) - for k := range v { - v2[i] = k - i++ - } - slices.Sort(v2) - for i, k2 := range v2 { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeString(k2) - e.mapElemValue() - e.e.EncodeBool(v[k2]) - } - } else { - i = 0 - for k2, v2 := range v { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeString(k2) - e.mapElemValue() - e.e.EncodeBool(v2) - i++ - } - } - e.c = 0 - e.e.WriteMapEnd() -} -func (e *encoder[T]) fastpathEncMapUint8IntfR(f *encFnInfo, rv reflect.Value) { - fastpathET[T]{}.EncMapUint8IntfV(rv2i(rv).(map[uint8]interface{}), e) -} -func (fastpathET[T]) EncMapUint8IntfV(v map[uint8]interface{}, e *encoder[T]) { - if len(v) == 0 { - e.e.WriteMapEmpty() - return - } - var i uint - e.mapStart(len(v)) - if e.h.Canonical { - v2 := make([]uint8, len(v)) - for k := range v { - v2[i] = k - i++ - } - slices.Sort(v2) - for i, k2 := range v2 { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeUint(uint64(k2)) - e.mapElemValue() - if !e.encodeBuiltin(v[k2]) { - e.encodeR(reflect.ValueOf(v[k2])) - } - } - } else { - i = 0 - for k2, v2 := range v { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeUint(uint64(k2)) - e.mapElemValue() - if !e.encodeBuiltin(v2) { - e.encodeR(reflect.ValueOf(v2)) - } - i++ - } - } - e.c = 0 - e.e.WriteMapEnd() -} -func (e *encoder[T]) fastpathEncMapUint8StringR(f *encFnInfo, rv reflect.Value) { - fastpathET[T]{}.EncMapUint8StringV(rv2i(rv).(map[uint8]string), e) -} -func (fastpathET[T]) EncMapUint8StringV(v map[uint8]string, e *encoder[T]) { - if len(v) == 0 { - e.e.WriteMapEmpty() - return - } - var i uint - e.mapStart(len(v)) - if e.h.Canonical { - v2 := make([]uint8, len(v)) - for k := range v { - v2[i] = k - i++ - } - slices.Sort(v2) - for i, k2 := range v2 { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeUint(uint64(k2)) - e.mapElemValue() - e.e.EncodeString(v[k2]) - } - } else { - i = 0 - for k2, v2 := range v { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeUint(uint64(k2)) - e.mapElemValue() - e.e.EncodeString(v2) - i++ - } - } - e.c = 0 - e.e.WriteMapEnd() -} -func (e *encoder[T]) fastpathEncMapUint8BytesR(f *encFnInfo, rv reflect.Value) { - fastpathET[T]{}.EncMapUint8BytesV(rv2i(rv).(map[uint8][]byte), e) -} -func (fastpathET[T]) EncMapUint8BytesV(v map[uint8][]byte, e *encoder[T]) { - if len(v) == 0 { - e.e.WriteMapEmpty() - return - } - var i uint - e.mapStart(len(v)) - if e.h.Canonical { - v2 := make([]uint8, len(v)) - for k := range v { - v2[i] = k - i++ - } - slices.Sort(v2) - for i, k2 := range v2 { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeUint(uint64(k2)) - e.mapElemValue() - e.e.EncodeBytes(v[k2]) - } - } else { - i = 0 - for k2, v2 := range v { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeUint(uint64(k2)) - e.mapElemValue() - e.e.EncodeBytes(v2) - i++ - } - } - e.c = 0 - e.e.WriteMapEnd() -} -func (e *encoder[T]) fastpathEncMapUint8Uint8R(f *encFnInfo, rv reflect.Value) { - fastpathET[T]{}.EncMapUint8Uint8V(rv2i(rv).(map[uint8]uint8), e) -} -func (fastpathET[T]) EncMapUint8Uint8V(v map[uint8]uint8, e *encoder[T]) { - if len(v) == 0 { - e.e.WriteMapEmpty() - return - } - var i uint - e.mapStart(len(v)) - if e.h.Canonical { - v2 := make([]uint8, len(v)) - for k := range v { - v2[i] = k - i++ - } - slices.Sort(v2) - for i, k2 := range v2 { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeUint(uint64(k2)) - e.mapElemValue() - e.e.EncodeUint(uint64(v[k2])) - } - } else { - i = 0 - for k2, v2 := range v { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeUint(uint64(k2)) - e.mapElemValue() - e.e.EncodeUint(uint64(v2)) - i++ - } - } - e.c = 0 - e.e.WriteMapEnd() -} -func (e *encoder[T]) fastpathEncMapUint8Uint64R(f *encFnInfo, rv reflect.Value) { - fastpathET[T]{}.EncMapUint8Uint64V(rv2i(rv).(map[uint8]uint64), e) -} -func (fastpathET[T]) EncMapUint8Uint64V(v map[uint8]uint64, e *encoder[T]) { - if len(v) == 0 { - e.e.WriteMapEmpty() - return - } - var i uint - e.mapStart(len(v)) - if e.h.Canonical { - v2 := make([]uint8, len(v)) - for k := range v { - v2[i] = k - i++ - } - slices.Sort(v2) - for i, k2 := range v2 { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeUint(uint64(k2)) - e.mapElemValue() - e.e.EncodeUint(v[k2]) - } - } else { - i = 0 - for k2, v2 := range v { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeUint(uint64(k2)) - e.mapElemValue() - e.e.EncodeUint(v2) - i++ - } - } - e.c = 0 - e.e.WriteMapEnd() -} -func (e *encoder[T]) fastpathEncMapUint8IntR(f *encFnInfo, rv reflect.Value) { - fastpathET[T]{}.EncMapUint8IntV(rv2i(rv).(map[uint8]int), e) -} -func (fastpathET[T]) EncMapUint8IntV(v map[uint8]int, e *encoder[T]) { - if len(v) == 0 { - e.e.WriteMapEmpty() - return - } - var i uint - e.mapStart(len(v)) - if e.h.Canonical { - v2 := make([]uint8, len(v)) - for k := range v { - v2[i] = k - i++ - } - slices.Sort(v2) - for i, k2 := range v2 { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeUint(uint64(k2)) - e.mapElemValue() - e.e.EncodeInt(int64(v[k2])) - } - } else { - i = 0 - for k2, v2 := range v { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeUint(uint64(k2)) - e.mapElemValue() - e.e.EncodeInt(int64(v2)) - i++ - } - } - e.c = 0 - e.e.WriteMapEnd() -} -func (e *encoder[T]) fastpathEncMapUint8Int32R(f *encFnInfo, rv reflect.Value) { - fastpathET[T]{}.EncMapUint8Int32V(rv2i(rv).(map[uint8]int32), e) -} -func (fastpathET[T]) EncMapUint8Int32V(v map[uint8]int32, e *encoder[T]) { - if len(v) == 0 { - e.e.WriteMapEmpty() - return - } - var i uint - e.mapStart(len(v)) - if e.h.Canonical { - v2 := make([]uint8, len(v)) - for k := range v { - v2[i] = k - i++ - } - slices.Sort(v2) - for i, k2 := range v2 { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeUint(uint64(k2)) - e.mapElemValue() - e.e.EncodeInt(int64(v[k2])) - } - } else { - i = 0 - for k2, v2 := range v { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeUint(uint64(k2)) - e.mapElemValue() - e.e.EncodeInt(int64(v2)) - i++ - } - } - e.c = 0 - e.e.WriteMapEnd() -} -func (e *encoder[T]) fastpathEncMapUint8Float64R(f *encFnInfo, rv reflect.Value) { - fastpathET[T]{}.EncMapUint8Float64V(rv2i(rv).(map[uint8]float64), e) -} -func (fastpathET[T]) EncMapUint8Float64V(v map[uint8]float64, e *encoder[T]) { - if len(v) == 0 { - e.e.WriteMapEmpty() - return - } - var i uint - e.mapStart(len(v)) - if e.h.Canonical { - v2 := make([]uint8, len(v)) - for k := range v { - v2[i] = k - i++ - } - slices.Sort(v2) - for i, k2 := range v2 { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeUint(uint64(k2)) - e.mapElemValue() - e.e.EncodeFloat64(v[k2]) - } - } else { - i = 0 - for k2, v2 := range v { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeUint(uint64(k2)) - e.mapElemValue() - e.e.EncodeFloat64(v2) - i++ - } - } - e.c = 0 - e.e.WriteMapEnd() -} -func (e *encoder[T]) fastpathEncMapUint8BoolR(f *encFnInfo, rv reflect.Value) { - fastpathET[T]{}.EncMapUint8BoolV(rv2i(rv).(map[uint8]bool), e) -} -func (fastpathET[T]) EncMapUint8BoolV(v map[uint8]bool, e *encoder[T]) { - if len(v) == 0 { - e.e.WriteMapEmpty() - return - } - var i uint - e.mapStart(len(v)) - if e.h.Canonical { - v2 := make([]uint8, len(v)) - for k := range v { - v2[i] = k - i++ - } - slices.Sort(v2) - for i, k2 := range v2 { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeUint(uint64(k2)) - e.mapElemValue() - e.e.EncodeBool(v[k2]) - } - } else { - i = 0 - for k2, v2 := range v { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeUint(uint64(k2)) - e.mapElemValue() - e.e.EncodeBool(v2) - i++ - } - } - e.c = 0 - e.e.WriteMapEnd() -} -func (e *encoder[T]) fastpathEncMapUint64IntfR(f *encFnInfo, rv reflect.Value) { - fastpathET[T]{}.EncMapUint64IntfV(rv2i(rv).(map[uint64]interface{}), e) -} -func (fastpathET[T]) EncMapUint64IntfV(v map[uint64]interface{}, e *encoder[T]) { - if len(v) == 0 { - e.e.WriteMapEmpty() - return - } - var i uint - e.mapStart(len(v)) - if e.h.Canonical { - v2 := make([]uint64, len(v)) - for k := range v { - v2[i] = k - i++ - } - slices.Sort(v2) - for i, k2 := range v2 { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeUint(k2) - e.mapElemValue() - if !e.encodeBuiltin(v[k2]) { - e.encodeR(reflect.ValueOf(v[k2])) - } - } - } else { - i = 0 - for k2, v2 := range v { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeUint(k2) - e.mapElemValue() - if !e.encodeBuiltin(v2) { - e.encodeR(reflect.ValueOf(v2)) - } - i++ - } - } - e.c = 0 - e.e.WriteMapEnd() -} -func (e *encoder[T]) fastpathEncMapUint64StringR(f *encFnInfo, rv reflect.Value) { - fastpathET[T]{}.EncMapUint64StringV(rv2i(rv).(map[uint64]string), e) -} -func (fastpathET[T]) EncMapUint64StringV(v map[uint64]string, e *encoder[T]) { - if len(v) == 0 { - e.e.WriteMapEmpty() - return - } - var i uint - e.mapStart(len(v)) - if e.h.Canonical { - v2 := make([]uint64, len(v)) - for k := range v { - v2[i] = k - i++ - } - slices.Sort(v2) - for i, k2 := range v2 { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeUint(k2) - e.mapElemValue() - e.e.EncodeString(v[k2]) - } - } else { - i = 0 - for k2, v2 := range v { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeUint(k2) - e.mapElemValue() - e.e.EncodeString(v2) - i++ - } - } - e.c = 0 - e.e.WriteMapEnd() -} -func (e *encoder[T]) fastpathEncMapUint64BytesR(f *encFnInfo, rv reflect.Value) { - fastpathET[T]{}.EncMapUint64BytesV(rv2i(rv).(map[uint64][]byte), e) -} -func (fastpathET[T]) EncMapUint64BytesV(v map[uint64][]byte, e *encoder[T]) { - if len(v) == 0 { - e.e.WriteMapEmpty() - return - } - var i uint - e.mapStart(len(v)) - if e.h.Canonical { - v2 := make([]uint64, len(v)) - for k := range v { - v2[i] = k - i++ - } - slices.Sort(v2) - for i, k2 := range v2 { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeUint(k2) - e.mapElemValue() - e.e.EncodeBytes(v[k2]) - } - } else { - i = 0 - for k2, v2 := range v { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeUint(k2) - e.mapElemValue() - e.e.EncodeBytes(v2) - i++ - } - } - e.c = 0 - e.e.WriteMapEnd() -} -func (e *encoder[T]) fastpathEncMapUint64Uint8R(f *encFnInfo, rv reflect.Value) { - fastpathET[T]{}.EncMapUint64Uint8V(rv2i(rv).(map[uint64]uint8), e) -} -func (fastpathET[T]) EncMapUint64Uint8V(v map[uint64]uint8, e *encoder[T]) { - if len(v) == 0 { - e.e.WriteMapEmpty() - return - } - var i uint - e.mapStart(len(v)) - if e.h.Canonical { - v2 := make([]uint64, len(v)) - for k := range v { - v2[i] = k - i++ - } - slices.Sort(v2) - for i, k2 := range v2 { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeUint(k2) - e.mapElemValue() - e.e.EncodeUint(uint64(v[k2])) - } - } else { - i = 0 - for k2, v2 := range v { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeUint(k2) - e.mapElemValue() - e.e.EncodeUint(uint64(v2)) - i++ - } - } - e.c = 0 - e.e.WriteMapEnd() -} -func (e *encoder[T]) fastpathEncMapUint64Uint64R(f *encFnInfo, rv reflect.Value) { - fastpathET[T]{}.EncMapUint64Uint64V(rv2i(rv).(map[uint64]uint64), e) -} -func (fastpathET[T]) EncMapUint64Uint64V(v map[uint64]uint64, e *encoder[T]) { - if len(v) == 0 { - e.e.WriteMapEmpty() - return - } - var i uint - e.mapStart(len(v)) - if e.h.Canonical { - v2 := make([]uint64, len(v)) - for k := range v { - v2[i] = k - i++ - } - slices.Sort(v2) - for i, k2 := range v2 { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeUint(k2) - e.mapElemValue() - e.e.EncodeUint(v[k2]) - } - } else { - i = 0 - for k2, v2 := range v { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeUint(k2) - e.mapElemValue() - e.e.EncodeUint(v2) - i++ - } - } - e.c = 0 - e.e.WriteMapEnd() -} -func (e *encoder[T]) fastpathEncMapUint64IntR(f *encFnInfo, rv reflect.Value) { - fastpathET[T]{}.EncMapUint64IntV(rv2i(rv).(map[uint64]int), e) -} -func (fastpathET[T]) EncMapUint64IntV(v map[uint64]int, e *encoder[T]) { - if len(v) == 0 { - e.e.WriteMapEmpty() - return - } - var i uint - e.mapStart(len(v)) - if e.h.Canonical { - v2 := make([]uint64, len(v)) - for k := range v { - v2[i] = k - i++ - } - slices.Sort(v2) - for i, k2 := range v2 { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeUint(k2) - e.mapElemValue() - e.e.EncodeInt(int64(v[k2])) - } - } else { - i = 0 - for k2, v2 := range v { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeUint(k2) - e.mapElemValue() - e.e.EncodeInt(int64(v2)) - i++ - } - } - e.c = 0 - e.e.WriteMapEnd() -} -func (e *encoder[T]) fastpathEncMapUint64Int32R(f *encFnInfo, rv reflect.Value) { - fastpathET[T]{}.EncMapUint64Int32V(rv2i(rv).(map[uint64]int32), e) -} -func (fastpathET[T]) EncMapUint64Int32V(v map[uint64]int32, e *encoder[T]) { - if len(v) == 0 { - e.e.WriteMapEmpty() - return - } - var i uint - e.mapStart(len(v)) - if e.h.Canonical { - v2 := make([]uint64, len(v)) - for k := range v { - v2[i] = k - i++ - } - slices.Sort(v2) - for i, k2 := range v2 { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeUint(k2) - e.mapElemValue() - e.e.EncodeInt(int64(v[k2])) - } - } else { - i = 0 - for k2, v2 := range v { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeUint(k2) - e.mapElemValue() - e.e.EncodeInt(int64(v2)) - i++ - } - } - e.c = 0 - e.e.WriteMapEnd() -} -func (e *encoder[T]) fastpathEncMapUint64Float64R(f *encFnInfo, rv reflect.Value) { - fastpathET[T]{}.EncMapUint64Float64V(rv2i(rv).(map[uint64]float64), e) -} -func (fastpathET[T]) EncMapUint64Float64V(v map[uint64]float64, e *encoder[T]) { - if len(v) == 0 { - e.e.WriteMapEmpty() - return - } - var i uint - e.mapStart(len(v)) - if e.h.Canonical { - v2 := make([]uint64, len(v)) - for k := range v { - v2[i] = k - i++ - } - slices.Sort(v2) - for i, k2 := range v2 { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeUint(k2) - e.mapElemValue() - e.e.EncodeFloat64(v[k2]) - } - } else { - i = 0 - for k2, v2 := range v { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeUint(k2) - e.mapElemValue() - e.e.EncodeFloat64(v2) - i++ - } - } - e.c = 0 - e.e.WriteMapEnd() -} -func (e *encoder[T]) fastpathEncMapUint64BoolR(f *encFnInfo, rv reflect.Value) { - fastpathET[T]{}.EncMapUint64BoolV(rv2i(rv).(map[uint64]bool), e) -} -func (fastpathET[T]) EncMapUint64BoolV(v map[uint64]bool, e *encoder[T]) { - if len(v) == 0 { - e.e.WriteMapEmpty() - return - } - var i uint - e.mapStart(len(v)) - if e.h.Canonical { - v2 := make([]uint64, len(v)) - for k := range v { - v2[i] = k - i++ - } - slices.Sort(v2) - for i, k2 := range v2 { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeUint(k2) - e.mapElemValue() - e.e.EncodeBool(v[k2]) - } - } else { - i = 0 - for k2, v2 := range v { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeUint(k2) - e.mapElemValue() - e.e.EncodeBool(v2) - i++ - } - } - e.c = 0 - e.e.WriteMapEnd() -} -func (e *encoder[T]) fastpathEncMapIntIntfR(f *encFnInfo, rv reflect.Value) { - fastpathET[T]{}.EncMapIntIntfV(rv2i(rv).(map[int]interface{}), e) -} -func (fastpathET[T]) EncMapIntIntfV(v map[int]interface{}, e *encoder[T]) { - if len(v) == 0 { - e.e.WriteMapEmpty() - return - } - var i uint - e.mapStart(len(v)) - if e.h.Canonical { - v2 := make([]int, len(v)) - for k := range v { - v2[i] = k - i++ - } - slices.Sort(v2) - for i, k2 := range v2 { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeInt(int64(k2)) - e.mapElemValue() - if !e.encodeBuiltin(v[k2]) { - e.encodeR(reflect.ValueOf(v[k2])) - } - } - } else { - i = 0 - for k2, v2 := range v { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeInt(int64(k2)) - e.mapElemValue() - if !e.encodeBuiltin(v2) { - e.encodeR(reflect.ValueOf(v2)) - } - i++ - } - } - e.c = 0 - e.e.WriteMapEnd() -} -func (e *encoder[T]) fastpathEncMapIntStringR(f *encFnInfo, rv reflect.Value) { - fastpathET[T]{}.EncMapIntStringV(rv2i(rv).(map[int]string), e) -} -func (fastpathET[T]) EncMapIntStringV(v map[int]string, e *encoder[T]) { - if len(v) == 0 { - e.e.WriteMapEmpty() - return - } - var i uint - e.mapStart(len(v)) - if e.h.Canonical { - v2 := make([]int, len(v)) - for k := range v { - v2[i] = k - i++ - } - slices.Sort(v2) - for i, k2 := range v2 { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeInt(int64(k2)) - e.mapElemValue() - e.e.EncodeString(v[k2]) - } - } else { - i = 0 - for k2, v2 := range v { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeInt(int64(k2)) - e.mapElemValue() - e.e.EncodeString(v2) - i++ - } - } - e.c = 0 - e.e.WriteMapEnd() -} -func (e *encoder[T]) fastpathEncMapIntBytesR(f *encFnInfo, rv reflect.Value) { - fastpathET[T]{}.EncMapIntBytesV(rv2i(rv).(map[int][]byte), e) -} -func (fastpathET[T]) EncMapIntBytesV(v map[int][]byte, e *encoder[T]) { - if len(v) == 0 { - e.e.WriteMapEmpty() - return - } - var i uint - e.mapStart(len(v)) - if e.h.Canonical { - v2 := make([]int, len(v)) - for k := range v { - v2[i] = k - i++ - } - slices.Sort(v2) - for i, k2 := range v2 { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeInt(int64(k2)) - e.mapElemValue() - e.e.EncodeBytes(v[k2]) - } - } else { - i = 0 - for k2, v2 := range v { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeInt(int64(k2)) - e.mapElemValue() - e.e.EncodeBytes(v2) - i++ - } - } - e.c = 0 - e.e.WriteMapEnd() -} -func (e *encoder[T]) fastpathEncMapIntUint8R(f *encFnInfo, rv reflect.Value) { - fastpathET[T]{}.EncMapIntUint8V(rv2i(rv).(map[int]uint8), e) -} -func (fastpathET[T]) EncMapIntUint8V(v map[int]uint8, e *encoder[T]) { - if len(v) == 0 { - e.e.WriteMapEmpty() - return - } - var i uint - e.mapStart(len(v)) - if e.h.Canonical { - v2 := make([]int, len(v)) - for k := range v { - v2[i] = k - i++ - } - slices.Sort(v2) - for i, k2 := range v2 { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeInt(int64(k2)) - e.mapElemValue() - e.e.EncodeUint(uint64(v[k2])) - } - } else { - i = 0 - for k2, v2 := range v { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeInt(int64(k2)) - e.mapElemValue() - e.e.EncodeUint(uint64(v2)) - i++ - } - } - e.c = 0 - e.e.WriteMapEnd() -} -func (e *encoder[T]) fastpathEncMapIntUint64R(f *encFnInfo, rv reflect.Value) { - fastpathET[T]{}.EncMapIntUint64V(rv2i(rv).(map[int]uint64), e) -} -func (fastpathET[T]) EncMapIntUint64V(v map[int]uint64, e *encoder[T]) { - if len(v) == 0 { - e.e.WriteMapEmpty() - return - } - var i uint - e.mapStart(len(v)) - if e.h.Canonical { - v2 := make([]int, len(v)) - for k := range v { - v2[i] = k - i++ - } - slices.Sort(v2) - for i, k2 := range v2 { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeInt(int64(k2)) - e.mapElemValue() - e.e.EncodeUint(v[k2]) - } - } else { - i = 0 - for k2, v2 := range v { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeInt(int64(k2)) - e.mapElemValue() - e.e.EncodeUint(v2) - i++ - } - } - e.c = 0 - e.e.WriteMapEnd() -} -func (e *encoder[T]) fastpathEncMapIntIntR(f *encFnInfo, rv reflect.Value) { - fastpathET[T]{}.EncMapIntIntV(rv2i(rv).(map[int]int), e) -} -func (fastpathET[T]) EncMapIntIntV(v map[int]int, e *encoder[T]) { - if len(v) == 0 { - e.e.WriteMapEmpty() - return - } - var i uint - e.mapStart(len(v)) - if e.h.Canonical { - v2 := make([]int, len(v)) - for k := range v { - v2[i] = k - i++ - } - slices.Sort(v2) - for i, k2 := range v2 { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeInt(int64(k2)) - e.mapElemValue() - e.e.EncodeInt(int64(v[k2])) - } - } else { - i = 0 - for k2, v2 := range v { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeInt(int64(k2)) - e.mapElemValue() - e.e.EncodeInt(int64(v2)) - i++ - } - } - e.c = 0 - e.e.WriteMapEnd() -} -func (e *encoder[T]) fastpathEncMapIntInt32R(f *encFnInfo, rv reflect.Value) { - fastpathET[T]{}.EncMapIntInt32V(rv2i(rv).(map[int]int32), e) -} -func (fastpathET[T]) EncMapIntInt32V(v map[int]int32, e *encoder[T]) { - if len(v) == 0 { - e.e.WriteMapEmpty() - return - } - var i uint - e.mapStart(len(v)) - if e.h.Canonical { - v2 := make([]int, len(v)) - for k := range v { - v2[i] = k - i++ - } - slices.Sort(v2) - for i, k2 := range v2 { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeInt(int64(k2)) - e.mapElemValue() - e.e.EncodeInt(int64(v[k2])) - } - } else { - i = 0 - for k2, v2 := range v { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeInt(int64(k2)) - e.mapElemValue() - e.e.EncodeInt(int64(v2)) - i++ - } - } - e.c = 0 - e.e.WriteMapEnd() -} -func (e *encoder[T]) fastpathEncMapIntFloat64R(f *encFnInfo, rv reflect.Value) { - fastpathET[T]{}.EncMapIntFloat64V(rv2i(rv).(map[int]float64), e) -} -func (fastpathET[T]) EncMapIntFloat64V(v map[int]float64, e *encoder[T]) { - if len(v) == 0 { - e.e.WriteMapEmpty() - return - } - var i uint - e.mapStart(len(v)) - if e.h.Canonical { - v2 := make([]int, len(v)) - for k := range v { - v2[i] = k - i++ - } - slices.Sort(v2) - for i, k2 := range v2 { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeInt(int64(k2)) - e.mapElemValue() - e.e.EncodeFloat64(v[k2]) - } - } else { - i = 0 - for k2, v2 := range v { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeInt(int64(k2)) - e.mapElemValue() - e.e.EncodeFloat64(v2) - i++ - } - } - e.c = 0 - e.e.WriteMapEnd() -} -func (e *encoder[T]) fastpathEncMapIntBoolR(f *encFnInfo, rv reflect.Value) { - fastpathET[T]{}.EncMapIntBoolV(rv2i(rv).(map[int]bool), e) -} -func (fastpathET[T]) EncMapIntBoolV(v map[int]bool, e *encoder[T]) { - if len(v) == 0 { - e.e.WriteMapEmpty() - return - } - var i uint - e.mapStart(len(v)) - if e.h.Canonical { - v2 := make([]int, len(v)) - for k := range v { - v2[i] = k - i++ - } - slices.Sort(v2) - for i, k2 := range v2 { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeInt(int64(k2)) - e.mapElemValue() - e.e.EncodeBool(v[k2]) - } - } else { - i = 0 - for k2, v2 := range v { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeInt(int64(k2)) - e.mapElemValue() - e.e.EncodeBool(v2) - i++ - } - } - e.c = 0 - e.e.WriteMapEnd() -} -func (e *encoder[T]) fastpathEncMapInt32IntfR(f *encFnInfo, rv reflect.Value) { - fastpathET[T]{}.EncMapInt32IntfV(rv2i(rv).(map[int32]interface{}), e) -} -func (fastpathET[T]) EncMapInt32IntfV(v map[int32]interface{}, e *encoder[T]) { - if len(v) == 0 { - e.e.WriteMapEmpty() - return - } - var i uint - e.mapStart(len(v)) - if e.h.Canonical { - v2 := make([]int32, len(v)) - for k := range v { - v2[i] = k - i++ - } - slices.Sort(v2) - for i, k2 := range v2 { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeInt(int64(k2)) - e.mapElemValue() - if !e.encodeBuiltin(v[k2]) { - e.encodeR(reflect.ValueOf(v[k2])) - } - } - } else { - i = 0 - for k2, v2 := range v { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeInt(int64(k2)) - e.mapElemValue() - if !e.encodeBuiltin(v2) { - e.encodeR(reflect.ValueOf(v2)) - } - i++ - } - } - e.c = 0 - e.e.WriteMapEnd() -} -func (e *encoder[T]) fastpathEncMapInt32StringR(f *encFnInfo, rv reflect.Value) { - fastpathET[T]{}.EncMapInt32StringV(rv2i(rv).(map[int32]string), e) -} -func (fastpathET[T]) EncMapInt32StringV(v map[int32]string, e *encoder[T]) { - if len(v) == 0 { - e.e.WriteMapEmpty() - return - } - var i uint - e.mapStart(len(v)) - if e.h.Canonical { - v2 := make([]int32, len(v)) - for k := range v { - v2[i] = k - i++ - } - slices.Sort(v2) - for i, k2 := range v2 { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeInt(int64(k2)) - e.mapElemValue() - e.e.EncodeString(v[k2]) - } - } else { - i = 0 - for k2, v2 := range v { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeInt(int64(k2)) - e.mapElemValue() - e.e.EncodeString(v2) - i++ - } - } - e.c = 0 - e.e.WriteMapEnd() -} -func (e *encoder[T]) fastpathEncMapInt32BytesR(f *encFnInfo, rv reflect.Value) { - fastpathET[T]{}.EncMapInt32BytesV(rv2i(rv).(map[int32][]byte), e) -} -func (fastpathET[T]) EncMapInt32BytesV(v map[int32][]byte, e *encoder[T]) { - if len(v) == 0 { - e.e.WriteMapEmpty() - return - } - var i uint - e.mapStart(len(v)) - if e.h.Canonical { - v2 := make([]int32, len(v)) - for k := range v { - v2[i] = k - i++ - } - slices.Sort(v2) - for i, k2 := range v2 { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeInt(int64(k2)) - e.mapElemValue() - e.e.EncodeBytes(v[k2]) - } - } else { - i = 0 - for k2, v2 := range v { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeInt(int64(k2)) - e.mapElemValue() - e.e.EncodeBytes(v2) - i++ - } - } - e.c = 0 - e.e.WriteMapEnd() -} -func (e *encoder[T]) fastpathEncMapInt32Uint8R(f *encFnInfo, rv reflect.Value) { - fastpathET[T]{}.EncMapInt32Uint8V(rv2i(rv).(map[int32]uint8), e) -} -func (fastpathET[T]) EncMapInt32Uint8V(v map[int32]uint8, e *encoder[T]) { - if len(v) == 0 { - e.e.WriteMapEmpty() - return - } - var i uint - e.mapStart(len(v)) - if e.h.Canonical { - v2 := make([]int32, len(v)) - for k := range v { - v2[i] = k - i++ - } - slices.Sort(v2) - for i, k2 := range v2 { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeInt(int64(k2)) - e.mapElemValue() - e.e.EncodeUint(uint64(v[k2])) - } - } else { - i = 0 - for k2, v2 := range v { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeInt(int64(k2)) - e.mapElemValue() - e.e.EncodeUint(uint64(v2)) - i++ - } - } - e.c = 0 - e.e.WriteMapEnd() -} -func (e *encoder[T]) fastpathEncMapInt32Uint64R(f *encFnInfo, rv reflect.Value) { - fastpathET[T]{}.EncMapInt32Uint64V(rv2i(rv).(map[int32]uint64), e) -} -func (fastpathET[T]) EncMapInt32Uint64V(v map[int32]uint64, e *encoder[T]) { - if len(v) == 0 { - e.e.WriteMapEmpty() - return - } - var i uint - e.mapStart(len(v)) - if e.h.Canonical { - v2 := make([]int32, len(v)) - for k := range v { - v2[i] = k - i++ - } - slices.Sort(v2) - for i, k2 := range v2 { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeInt(int64(k2)) - e.mapElemValue() - e.e.EncodeUint(v[k2]) - } - } else { - i = 0 - for k2, v2 := range v { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeInt(int64(k2)) - e.mapElemValue() - e.e.EncodeUint(v2) - i++ - } - } - e.c = 0 - e.e.WriteMapEnd() -} -func (e *encoder[T]) fastpathEncMapInt32IntR(f *encFnInfo, rv reflect.Value) { - fastpathET[T]{}.EncMapInt32IntV(rv2i(rv).(map[int32]int), e) -} -func (fastpathET[T]) EncMapInt32IntV(v map[int32]int, e *encoder[T]) { - if len(v) == 0 { - e.e.WriteMapEmpty() - return - } - var i uint - e.mapStart(len(v)) - if e.h.Canonical { - v2 := make([]int32, len(v)) - for k := range v { - v2[i] = k - i++ - } - slices.Sort(v2) - for i, k2 := range v2 { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeInt(int64(k2)) - e.mapElemValue() - e.e.EncodeInt(int64(v[k2])) - } - } else { - i = 0 - for k2, v2 := range v { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeInt(int64(k2)) - e.mapElemValue() - e.e.EncodeInt(int64(v2)) - i++ - } - } - e.c = 0 - e.e.WriteMapEnd() -} -func (e *encoder[T]) fastpathEncMapInt32Int32R(f *encFnInfo, rv reflect.Value) { - fastpathET[T]{}.EncMapInt32Int32V(rv2i(rv).(map[int32]int32), e) -} -func (fastpathET[T]) EncMapInt32Int32V(v map[int32]int32, e *encoder[T]) { - if len(v) == 0 { - e.e.WriteMapEmpty() - return - } - var i uint - e.mapStart(len(v)) - if e.h.Canonical { - v2 := make([]int32, len(v)) - for k := range v { - v2[i] = k - i++ - } - slices.Sort(v2) - for i, k2 := range v2 { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeInt(int64(k2)) - e.mapElemValue() - e.e.EncodeInt(int64(v[k2])) - } - } else { - i = 0 - for k2, v2 := range v { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeInt(int64(k2)) - e.mapElemValue() - e.e.EncodeInt(int64(v2)) - i++ - } - } - e.c = 0 - e.e.WriteMapEnd() -} -func (e *encoder[T]) fastpathEncMapInt32Float64R(f *encFnInfo, rv reflect.Value) { - fastpathET[T]{}.EncMapInt32Float64V(rv2i(rv).(map[int32]float64), e) -} -func (fastpathET[T]) EncMapInt32Float64V(v map[int32]float64, e *encoder[T]) { - if len(v) == 0 { - e.e.WriteMapEmpty() - return - } - var i uint - e.mapStart(len(v)) - if e.h.Canonical { - v2 := make([]int32, len(v)) - for k := range v { - v2[i] = k - i++ - } - slices.Sort(v2) - for i, k2 := range v2 { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeInt(int64(k2)) - e.mapElemValue() - e.e.EncodeFloat64(v[k2]) - } - } else { - i = 0 - for k2, v2 := range v { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeInt(int64(k2)) - e.mapElemValue() - e.e.EncodeFloat64(v2) - i++ - } - } - e.c = 0 - e.e.WriteMapEnd() -} -func (e *encoder[T]) fastpathEncMapInt32BoolR(f *encFnInfo, rv reflect.Value) { - fastpathET[T]{}.EncMapInt32BoolV(rv2i(rv).(map[int32]bool), e) -} -func (fastpathET[T]) EncMapInt32BoolV(v map[int32]bool, e *encoder[T]) { - if len(v) == 0 { - e.e.WriteMapEmpty() - return - } - var i uint - e.mapStart(len(v)) - if e.h.Canonical { - v2 := make([]int32, len(v)) - for k := range v { - v2[i] = k - i++ - } - slices.Sort(v2) - for i, k2 := range v2 { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeInt(int64(k2)) - e.mapElemValue() - e.e.EncodeBool(v[k2]) - } - } else { - i = 0 - for k2, v2 := range v { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeInt(int64(k2)) - e.mapElemValue() - e.e.EncodeBool(v2) - i++ - } - } - e.c = 0 - e.e.WriteMapEnd() -} - -// -- decode - -// -- -- fast path type switch -func (helperDecDriver[T]) fastpathDecodeTypeSwitch(iv interface{}, d *decoder[T]) bool { - var ft fastpathDT[T] - var changed bool - var containerLen int - switch v := iv.(type) { - case []interface{}: - ft.DecSliceIntfN(v, d) - case *[]interface{}: - var v2 []interface{} - if v2, changed = ft.DecSliceIntfY(*v, d); changed { - *v = v2 - } - case []string: - ft.DecSliceStringN(v, d) - case *[]string: - var v2 []string - if v2, changed = ft.DecSliceStringY(*v, d); changed { - *v = v2 - } - case [][]byte: - ft.DecSliceBytesN(v, d) - case *[][]byte: - var v2 [][]byte - if v2, changed = ft.DecSliceBytesY(*v, d); changed { - *v = v2 - } - case []float32: - ft.DecSliceFloat32N(v, d) - case *[]float32: - var v2 []float32 - if v2, changed = ft.DecSliceFloat32Y(*v, d); changed { - *v = v2 - } - case []float64: - ft.DecSliceFloat64N(v, d) - case *[]float64: - var v2 []float64 - if v2, changed = ft.DecSliceFloat64Y(*v, d); changed { - *v = v2 - } - case []uint8: - ft.DecSliceUint8N(v, d) - case *[]uint8: - var v2 []uint8 - if v2, changed = ft.DecSliceUint8Y(*v, d); changed { - *v = v2 - } - case []uint64: - ft.DecSliceUint64N(v, d) - case *[]uint64: - var v2 []uint64 - if v2, changed = ft.DecSliceUint64Y(*v, d); changed { - *v = v2 - } - case []int: - ft.DecSliceIntN(v, d) - case *[]int: - var v2 []int - if v2, changed = ft.DecSliceIntY(*v, d); changed { - *v = v2 - } - case []int32: - ft.DecSliceInt32N(v, d) - case *[]int32: - var v2 []int32 - if v2, changed = ft.DecSliceInt32Y(*v, d); changed { - *v = v2 - } - case []int64: - ft.DecSliceInt64N(v, d) - case *[]int64: - var v2 []int64 - if v2, changed = ft.DecSliceInt64Y(*v, d); changed { - *v = v2 - } - case []bool: - ft.DecSliceBoolN(v, d) - case *[]bool: - var v2 []bool - if v2, changed = ft.DecSliceBoolY(*v, d); changed { - *v = v2 - } - case map[string]interface{}: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen != containerLenNil { - if containerLen != 0 { - ft.DecMapStringIntfL(v, containerLen, d) - } - d.mapEnd() - } - case *map[string]interface{}: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen == containerLenNil { - *v = nil - } else { - if *v == nil { - *v = make(map[string]interface{}, decInferLen(containerLen, d.maxInitLen(), 32)) - } - if containerLen != 0 { - ft.DecMapStringIntfL(*v, containerLen, d) - } - d.mapEnd() - } - case map[string]string: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen != containerLenNil { - if containerLen != 0 { - ft.DecMapStringStringL(v, containerLen, d) - } - d.mapEnd() - } - case *map[string]string: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen == containerLenNil { - *v = nil - } else { - if *v == nil { - *v = make(map[string]string, decInferLen(containerLen, d.maxInitLen(), 32)) - } - if containerLen != 0 { - ft.DecMapStringStringL(*v, containerLen, d) - } - d.mapEnd() - } - case map[string][]byte: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen != containerLenNil { - if containerLen != 0 { - ft.DecMapStringBytesL(v, containerLen, d) - } - d.mapEnd() - } - case *map[string][]byte: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen == containerLenNil { - *v = nil - } else { - if *v == nil { - *v = make(map[string][]byte, decInferLen(containerLen, d.maxInitLen(), 40)) - } - if containerLen != 0 { - ft.DecMapStringBytesL(*v, containerLen, d) - } - d.mapEnd() - } - case map[string]uint8: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen != containerLenNil { - if containerLen != 0 { - ft.DecMapStringUint8L(v, containerLen, d) - } - d.mapEnd() - } - case *map[string]uint8: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen == containerLenNil { - *v = nil - } else { - if *v == nil { - *v = make(map[string]uint8, decInferLen(containerLen, d.maxInitLen(), 17)) - } - if containerLen != 0 { - ft.DecMapStringUint8L(*v, containerLen, d) - } - d.mapEnd() - } - case map[string]uint64: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen != containerLenNil { - if containerLen != 0 { - ft.DecMapStringUint64L(v, containerLen, d) - } - d.mapEnd() - } - case *map[string]uint64: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen == containerLenNil { - *v = nil - } else { - if *v == nil { - *v = make(map[string]uint64, decInferLen(containerLen, d.maxInitLen(), 24)) - } - if containerLen != 0 { - ft.DecMapStringUint64L(*v, containerLen, d) - } - d.mapEnd() - } - case map[string]int: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen != containerLenNil { - if containerLen != 0 { - ft.DecMapStringIntL(v, containerLen, d) - } - d.mapEnd() - } - case *map[string]int: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen == containerLenNil { - *v = nil - } else { - if *v == nil { - *v = make(map[string]int, decInferLen(containerLen, d.maxInitLen(), 24)) - } - if containerLen != 0 { - ft.DecMapStringIntL(*v, containerLen, d) - } - d.mapEnd() - } - case map[string]int32: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen != containerLenNil { - if containerLen != 0 { - ft.DecMapStringInt32L(v, containerLen, d) - } - d.mapEnd() - } - case *map[string]int32: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen == containerLenNil { - *v = nil - } else { - if *v == nil { - *v = make(map[string]int32, decInferLen(containerLen, d.maxInitLen(), 20)) - } - if containerLen != 0 { - ft.DecMapStringInt32L(*v, containerLen, d) - } - d.mapEnd() - } - case map[string]float64: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen != containerLenNil { - if containerLen != 0 { - ft.DecMapStringFloat64L(v, containerLen, d) - } - d.mapEnd() - } - case *map[string]float64: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen == containerLenNil { - *v = nil - } else { - if *v == nil { - *v = make(map[string]float64, decInferLen(containerLen, d.maxInitLen(), 24)) - } - if containerLen != 0 { - ft.DecMapStringFloat64L(*v, containerLen, d) - } - d.mapEnd() - } - case map[string]bool: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen != containerLenNil { - if containerLen != 0 { - ft.DecMapStringBoolL(v, containerLen, d) - } - d.mapEnd() - } - case *map[string]bool: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen == containerLenNil { - *v = nil - } else { - if *v == nil { - *v = make(map[string]bool, decInferLen(containerLen, d.maxInitLen(), 17)) - } - if containerLen != 0 { - ft.DecMapStringBoolL(*v, containerLen, d) - } - d.mapEnd() - } - case map[uint8]interface{}: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen != containerLenNil { - if containerLen != 0 { - ft.DecMapUint8IntfL(v, containerLen, d) - } - d.mapEnd() - } - case *map[uint8]interface{}: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen == containerLenNil { - *v = nil - } else { - if *v == nil { - *v = make(map[uint8]interface{}, decInferLen(containerLen, d.maxInitLen(), 17)) - } - if containerLen != 0 { - ft.DecMapUint8IntfL(*v, containerLen, d) - } - d.mapEnd() - } - case map[uint8]string: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen != containerLenNil { - if containerLen != 0 { - ft.DecMapUint8StringL(v, containerLen, d) - } - d.mapEnd() - } - case *map[uint8]string: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen == containerLenNil { - *v = nil - } else { - if *v == nil { - *v = make(map[uint8]string, decInferLen(containerLen, d.maxInitLen(), 17)) - } - if containerLen != 0 { - ft.DecMapUint8StringL(*v, containerLen, d) - } - d.mapEnd() - } - case map[uint8][]byte: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen != containerLenNil { - if containerLen != 0 { - ft.DecMapUint8BytesL(v, containerLen, d) - } - d.mapEnd() - } - case *map[uint8][]byte: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen == containerLenNil { - *v = nil - } else { - if *v == nil { - *v = make(map[uint8][]byte, decInferLen(containerLen, d.maxInitLen(), 25)) - } - if containerLen != 0 { - ft.DecMapUint8BytesL(*v, containerLen, d) - } - d.mapEnd() - } - case map[uint8]uint8: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen != containerLenNil { - if containerLen != 0 { - ft.DecMapUint8Uint8L(v, containerLen, d) - } - d.mapEnd() - } - case *map[uint8]uint8: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen == containerLenNil { - *v = nil - } else { - if *v == nil { - *v = make(map[uint8]uint8, decInferLen(containerLen, d.maxInitLen(), 2)) - } - if containerLen != 0 { - ft.DecMapUint8Uint8L(*v, containerLen, d) - } - d.mapEnd() - } - case map[uint8]uint64: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen != containerLenNil { - if containerLen != 0 { - ft.DecMapUint8Uint64L(v, containerLen, d) - } - d.mapEnd() - } - case *map[uint8]uint64: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen == containerLenNil { - *v = nil - } else { - if *v == nil { - *v = make(map[uint8]uint64, decInferLen(containerLen, d.maxInitLen(), 9)) - } - if containerLen != 0 { - ft.DecMapUint8Uint64L(*v, containerLen, d) - } - d.mapEnd() - } - case map[uint8]int: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen != containerLenNil { - if containerLen != 0 { - ft.DecMapUint8IntL(v, containerLen, d) - } - d.mapEnd() - } - case *map[uint8]int: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen == containerLenNil { - *v = nil - } else { - if *v == nil { - *v = make(map[uint8]int, decInferLen(containerLen, d.maxInitLen(), 9)) - } - if containerLen != 0 { - ft.DecMapUint8IntL(*v, containerLen, d) - } - d.mapEnd() - } - case map[uint8]int32: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen != containerLenNil { - if containerLen != 0 { - ft.DecMapUint8Int32L(v, containerLen, d) - } - d.mapEnd() - } - case *map[uint8]int32: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen == containerLenNil { - *v = nil - } else { - if *v == nil { - *v = make(map[uint8]int32, decInferLen(containerLen, d.maxInitLen(), 5)) - } - if containerLen != 0 { - ft.DecMapUint8Int32L(*v, containerLen, d) - } - d.mapEnd() - } - case map[uint8]float64: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen != containerLenNil { - if containerLen != 0 { - ft.DecMapUint8Float64L(v, containerLen, d) - } - d.mapEnd() - } - case *map[uint8]float64: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen == containerLenNil { - *v = nil - } else { - if *v == nil { - *v = make(map[uint8]float64, decInferLen(containerLen, d.maxInitLen(), 9)) - } - if containerLen != 0 { - ft.DecMapUint8Float64L(*v, containerLen, d) - } - d.mapEnd() - } - case map[uint8]bool: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen != containerLenNil { - if containerLen != 0 { - ft.DecMapUint8BoolL(v, containerLen, d) - } - d.mapEnd() - } - case *map[uint8]bool: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen == containerLenNil { - *v = nil - } else { - if *v == nil { - *v = make(map[uint8]bool, decInferLen(containerLen, d.maxInitLen(), 2)) - } - if containerLen != 0 { - ft.DecMapUint8BoolL(*v, containerLen, d) - } - d.mapEnd() - } - case map[uint64]interface{}: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen != containerLenNil { - if containerLen != 0 { - ft.DecMapUint64IntfL(v, containerLen, d) - } - d.mapEnd() - } - case *map[uint64]interface{}: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen == containerLenNil { - *v = nil - } else { - if *v == nil { - *v = make(map[uint64]interface{}, decInferLen(containerLen, d.maxInitLen(), 24)) - } - if containerLen != 0 { - ft.DecMapUint64IntfL(*v, containerLen, d) - } - d.mapEnd() - } - case map[uint64]string: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen != containerLenNil { - if containerLen != 0 { - ft.DecMapUint64StringL(v, containerLen, d) - } - d.mapEnd() - } - case *map[uint64]string: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen == containerLenNil { - *v = nil - } else { - if *v == nil { - *v = make(map[uint64]string, decInferLen(containerLen, d.maxInitLen(), 24)) - } - if containerLen != 0 { - ft.DecMapUint64StringL(*v, containerLen, d) - } - d.mapEnd() - } - case map[uint64][]byte: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen != containerLenNil { - if containerLen != 0 { - ft.DecMapUint64BytesL(v, containerLen, d) - } - d.mapEnd() - } - case *map[uint64][]byte: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen == containerLenNil { - *v = nil - } else { - if *v == nil { - *v = make(map[uint64][]byte, decInferLen(containerLen, d.maxInitLen(), 32)) - } - if containerLen != 0 { - ft.DecMapUint64BytesL(*v, containerLen, d) - } - d.mapEnd() - } - case map[uint64]uint8: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen != containerLenNil { - if containerLen != 0 { - ft.DecMapUint64Uint8L(v, containerLen, d) - } - d.mapEnd() - } - case *map[uint64]uint8: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen == containerLenNil { - *v = nil - } else { - if *v == nil { - *v = make(map[uint64]uint8, decInferLen(containerLen, d.maxInitLen(), 9)) - } - if containerLen != 0 { - ft.DecMapUint64Uint8L(*v, containerLen, d) - } - d.mapEnd() - } - case map[uint64]uint64: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen != containerLenNil { - if containerLen != 0 { - ft.DecMapUint64Uint64L(v, containerLen, d) - } - d.mapEnd() - } - case *map[uint64]uint64: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen == containerLenNil { - *v = nil - } else { - if *v == nil { - *v = make(map[uint64]uint64, decInferLen(containerLen, d.maxInitLen(), 16)) - } - if containerLen != 0 { - ft.DecMapUint64Uint64L(*v, containerLen, d) - } - d.mapEnd() - } - case map[uint64]int: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen != containerLenNil { - if containerLen != 0 { - ft.DecMapUint64IntL(v, containerLen, d) - } - d.mapEnd() - } - case *map[uint64]int: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen == containerLenNil { - *v = nil - } else { - if *v == nil { - *v = make(map[uint64]int, decInferLen(containerLen, d.maxInitLen(), 16)) - } - if containerLen != 0 { - ft.DecMapUint64IntL(*v, containerLen, d) - } - d.mapEnd() - } - case map[uint64]int32: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen != containerLenNil { - if containerLen != 0 { - ft.DecMapUint64Int32L(v, containerLen, d) - } - d.mapEnd() - } - case *map[uint64]int32: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen == containerLenNil { - *v = nil - } else { - if *v == nil { - *v = make(map[uint64]int32, decInferLen(containerLen, d.maxInitLen(), 12)) - } - if containerLen != 0 { - ft.DecMapUint64Int32L(*v, containerLen, d) - } - d.mapEnd() - } - case map[uint64]float64: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen != containerLenNil { - if containerLen != 0 { - ft.DecMapUint64Float64L(v, containerLen, d) - } - d.mapEnd() - } - case *map[uint64]float64: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen == containerLenNil { - *v = nil - } else { - if *v == nil { - *v = make(map[uint64]float64, decInferLen(containerLen, d.maxInitLen(), 16)) - } - if containerLen != 0 { - ft.DecMapUint64Float64L(*v, containerLen, d) - } - d.mapEnd() - } - case map[uint64]bool: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen != containerLenNil { - if containerLen != 0 { - ft.DecMapUint64BoolL(v, containerLen, d) - } - d.mapEnd() - } - case *map[uint64]bool: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen == containerLenNil { - *v = nil - } else { - if *v == nil { - *v = make(map[uint64]bool, decInferLen(containerLen, d.maxInitLen(), 9)) - } - if containerLen != 0 { - ft.DecMapUint64BoolL(*v, containerLen, d) - } - d.mapEnd() - } - case map[int]interface{}: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen != containerLenNil { - if containerLen != 0 { - ft.DecMapIntIntfL(v, containerLen, d) - } - d.mapEnd() - } - case *map[int]interface{}: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen == containerLenNil { - *v = nil - } else { - if *v == nil { - *v = make(map[int]interface{}, decInferLen(containerLen, d.maxInitLen(), 24)) - } - if containerLen != 0 { - ft.DecMapIntIntfL(*v, containerLen, d) - } - d.mapEnd() - } - case map[int]string: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen != containerLenNil { - if containerLen != 0 { - ft.DecMapIntStringL(v, containerLen, d) - } - d.mapEnd() - } - case *map[int]string: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen == containerLenNil { - *v = nil - } else { - if *v == nil { - *v = make(map[int]string, decInferLen(containerLen, d.maxInitLen(), 24)) - } - if containerLen != 0 { - ft.DecMapIntStringL(*v, containerLen, d) - } - d.mapEnd() - } - case map[int][]byte: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen != containerLenNil { - if containerLen != 0 { - ft.DecMapIntBytesL(v, containerLen, d) - } - d.mapEnd() - } - case *map[int][]byte: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen == containerLenNil { - *v = nil - } else { - if *v == nil { - *v = make(map[int][]byte, decInferLen(containerLen, d.maxInitLen(), 32)) - } - if containerLen != 0 { - ft.DecMapIntBytesL(*v, containerLen, d) - } - d.mapEnd() - } - case map[int]uint8: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen != containerLenNil { - if containerLen != 0 { - ft.DecMapIntUint8L(v, containerLen, d) - } - d.mapEnd() - } - case *map[int]uint8: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen == containerLenNil { - *v = nil - } else { - if *v == nil { - *v = make(map[int]uint8, decInferLen(containerLen, d.maxInitLen(), 9)) - } - if containerLen != 0 { - ft.DecMapIntUint8L(*v, containerLen, d) - } - d.mapEnd() - } - case map[int]uint64: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen != containerLenNil { - if containerLen != 0 { - ft.DecMapIntUint64L(v, containerLen, d) - } - d.mapEnd() - } - case *map[int]uint64: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen == containerLenNil { - *v = nil - } else { - if *v == nil { - *v = make(map[int]uint64, decInferLen(containerLen, d.maxInitLen(), 16)) - } - if containerLen != 0 { - ft.DecMapIntUint64L(*v, containerLen, d) - } - d.mapEnd() - } - case map[int]int: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen != containerLenNil { - if containerLen != 0 { - ft.DecMapIntIntL(v, containerLen, d) - } - d.mapEnd() - } - case *map[int]int: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen == containerLenNil { - *v = nil - } else { - if *v == nil { - *v = make(map[int]int, decInferLen(containerLen, d.maxInitLen(), 16)) - } - if containerLen != 0 { - ft.DecMapIntIntL(*v, containerLen, d) - } - d.mapEnd() - } - case map[int]int32: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen != containerLenNil { - if containerLen != 0 { - ft.DecMapIntInt32L(v, containerLen, d) - } - d.mapEnd() - } - case *map[int]int32: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen == containerLenNil { - *v = nil - } else { - if *v == nil { - *v = make(map[int]int32, decInferLen(containerLen, d.maxInitLen(), 12)) - } - if containerLen != 0 { - ft.DecMapIntInt32L(*v, containerLen, d) - } - d.mapEnd() - } - case map[int]float64: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen != containerLenNil { - if containerLen != 0 { - ft.DecMapIntFloat64L(v, containerLen, d) - } - d.mapEnd() - } - case *map[int]float64: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen == containerLenNil { - *v = nil - } else { - if *v == nil { - *v = make(map[int]float64, decInferLen(containerLen, d.maxInitLen(), 16)) - } - if containerLen != 0 { - ft.DecMapIntFloat64L(*v, containerLen, d) - } - d.mapEnd() - } - case map[int]bool: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen != containerLenNil { - if containerLen != 0 { - ft.DecMapIntBoolL(v, containerLen, d) - } - d.mapEnd() - } - case *map[int]bool: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen == containerLenNil { - *v = nil - } else { - if *v == nil { - *v = make(map[int]bool, decInferLen(containerLen, d.maxInitLen(), 9)) - } - if containerLen != 0 { - ft.DecMapIntBoolL(*v, containerLen, d) - } - d.mapEnd() - } - case map[int32]interface{}: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen != containerLenNil { - if containerLen != 0 { - ft.DecMapInt32IntfL(v, containerLen, d) - } - d.mapEnd() - } - case *map[int32]interface{}: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen == containerLenNil { - *v = nil - } else { - if *v == nil { - *v = make(map[int32]interface{}, decInferLen(containerLen, d.maxInitLen(), 20)) - } - if containerLen != 0 { - ft.DecMapInt32IntfL(*v, containerLen, d) - } - d.mapEnd() - } - case map[int32]string: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen != containerLenNil { - if containerLen != 0 { - ft.DecMapInt32StringL(v, containerLen, d) - } - d.mapEnd() - } - case *map[int32]string: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen == containerLenNil { - *v = nil - } else { - if *v == nil { - *v = make(map[int32]string, decInferLen(containerLen, d.maxInitLen(), 20)) - } - if containerLen != 0 { - ft.DecMapInt32StringL(*v, containerLen, d) - } - d.mapEnd() - } - case map[int32][]byte: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen != containerLenNil { - if containerLen != 0 { - ft.DecMapInt32BytesL(v, containerLen, d) - } - d.mapEnd() - } - case *map[int32][]byte: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen == containerLenNil { - *v = nil - } else { - if *v == nil { - *v = make(map[int32][]byte, decInferLen(containerLen, d.maxInitLen(), 28)) - } - if containerLen != 0 { - ft.DecMapInt32BytesL(*v, containerLen, d) - } - d.mapEnd() - } - case map[int32]uint8: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen != containerLenNil { - if containerLen != 0 { - ft.DecMapInt32Uint8L(v, containerLen, d) - } - d.mapEnd() - } - case *map[int32]uint8: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen == containerLenNil { - *v = nil - } else { - if *v == nil { - *v = make(map[int32]uint8, decInferLen(containerLen, d.maxInitLen(), 5)) - } - if containerLen != 0 { - ft.DecMapInt32Uint8L(*v, containerLen, d) - } - d.mapEnd() - } - case map[int32]uint64: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen != containerLenNil { - if containerLen != 0 { - ft.DecMapInt32Uint64L(v, containerLen, d) - } - d.mapEnd() - } - case *map[int32]uint64: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen == containerLenNil { - *v = nil - } else { - if *v == nil { - *v = make(map[int32]uint64, decInferLen(containerLen, d.maxInitLen(), 12)) - } - if containerLen != 0 { - ft.DecMapInt32Uint64L(*v, containerLen, d) - } - d.mapEnd() - } - case map[int32]int: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen != containerLenNil { - if containerLen != 0 { - ft.DecMapInt32IntL(v, containerLen, d) - } - d.mapEnd() - } - case *map[int32]int: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen == containerLenNil { - *v = nil - } else { - if *v == nil { - *v = make(map[int32]int, decInferLen(containerLen, d.maxInitLen(), 12)) - } - if containerLen != 0 { - ft.DecMapInt32IntL(*v, containerLen, d) - } - d.mapEnd() - } - case map[int32]int32: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen != containerLenNil { - if containerLen != 0 { - ft.DecMapInt32Int32L(v, containerLen, d) - } - d.mapEnd() - } - case *map[int32]int32: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen == containerLenNil { - *v = nil - } else { - if *v == nil { - *v = make(map[int32]int32, decInferLen(containerLen, d.maxInitLen(), 8)) - } - if containerLen != 0 { - ft.DecMapInt32Int32L(*v, containerLen, d) - } - d.mapEnd() - } - case map[int32]float64: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen != containerLenNil { - if containerLen != 0 { - ft.DecMapInt32Float64L(v, containerLen, d) - } - d.mapEnd() - } - case *map[int32]float64: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen == containerLenNil { - *v = nil - } else { - if *v == nil { - *v = make(map[int32]float64, decInferLen(containerLen, d.maxInitLen(), 12)) - } - if containerLen != 0 { - ft.DecMapInt32Float64L(*v, containerLen, d) - } - d.mapEnd() - } - case map[int32]bool: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen != containerLenNil { - if containerLen != 0 { - ft.DecMapInt32BoolL(v, containerLen, d) - } - d.mapEnd() - } - case *map[int32]bool: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen == containerLenNil { - *v = nil - } else { - if *v == nil { - *v = make(map[int32]bool, decInferLen(containerLen, d.maxInitLen(), 5)) - } - if containerLen != 0 { - ft.DecMapInt32BoolL(*v, containerLen, d) - } - d.mapEnd() - } - default: - _ = v // workaround https://github.com/golang/go/issues/12927 seen in go1.4 - return false - } - return true -} - -// -- -- fast path functions - -func (d *decoder[T]) fastpathDecSliceIntfR(f *decFnInfo, rv reflect.Value) { - var ft fastpathDT[T] - switch rv.Kind() { - case reflect.Ptr: - v := rv2i(rv).(*[]interface{}) - if vv, changed := ft.DecSliceIntfY(*v, d); changed { - *v = vv - } - case reflect.Array: - var v []interface{} - rvGetSlice4Array(rv, &v) - ft.DecSliceIntfN(v, d) - default: - ft.DecSliceIntfN(rv2i(rv).([]interface{}), d) - } -} -func (fastpathDT[T]) DecSliceIntfY(v []interface{}, d *decoder[T]) (v2 []interface{}, changed bool) { - ctyp := d.d.ContainerType() - if ctyp == valueTypeNil { - return nil, v != nil - } - var containerLenS int - isArray := ctyp == valueTypeArray - if isArray { - containerLenS = d.arrayStart(d.d.ReadArrayStart()) - } else if ctyp == valueTypeMap { - containerLenS = d.mapStart(d.d.ReadMapStart()) * 2 - } else { - halt.errorStr2("decoding into a slice, expect map/array - got ", ctyp.String()) - } - hasLen := containerLenS >= 0 - var j int - fnv := func(dst []interface{}) { v, changed = dst, true } - for ; d.containerNext(j, containerLenS, hasLen); j++ { - if j == 0 { - if containerLenS == len(v) { - } else if containerLenS < 0 || containerLenS > cap(v) { - if xlen := int(decInferLen(containerLenS, d.maxInitLen(), 16)); xlen <= cap(v) { - fnv(v[:uint(xlen)]) - } else { - v2 = make([]interface{}, uint(xlen)) - copy(v2, v) - fnv(v2) - } - } else { - fnv(v[:containerLenS]) - } - } - if isArray { - d.arrayElem(j == 0) - } else if j&1 == 0 { - d.mapElemKey(j == 0) - } else { - d.mapElemValue() - } - if j >= len(v) { - fnv(append(v, nil)) - } - d.decode(&v[uint(j)]) - } - if j < len(v) { - fnv(v[:uint(j)]) - } else if j == 0 && v == nil { - fnv([]interface{}{}) - } - if isArray { - d.arrayEnd() - } else { - d.mapEnd() - } - return v, changed -} -func (fastpathDT[T]) DecSliceIntfN(v []interface{}, d *decoder[T]) { - ctyp := d.d.ContainerType() - if ctyp == valueTypeNil { - return - } - var containerLenS int - isArray := ctyp == valueTypeArray - if isArray { - containerLenS = d.arrayStart(d.d.ReadArrayStart()) - } else if ctyp == valueTypeMap { - containerLenS = d.mapStart(d.d.ReadMapStart()) * 2 - } else { - halt.errorStr2("decoding into a slice, expect map/array - got ", ctyp.String()) - } - hasLen := containerLenS >= 0 - for j := 0; d.containerNext(j, containerLenS, hasLen); j++ { - if isArray { - d.arrayElem(j == 0) - } else if j&1 == 0 { - d.mapElemKey(j == 0) - } else { - d.mapElemValue() - } - if j < len(v) { - d.decode(&v[uint(j)]) - } else { - d.arrayCannotExpand(len(v), j+1) - d.swallow() - } - } - if isArray { - d.arrayEnd() - } else { - d.mapEnd() - } -} - -func (d *decoder[T]) fastpathDecSliceStringR(f *decFnInfo, rv reflect.Value) { - var ft fastpathDT[T] - switch rv.Kind() { - case reflect.Ptr: - v := rv2i(rv).(*[]string) - if vv, changed := ft.DecSliceStringY(*v, d); changed { - *v = vv - } - case reflect.Array: - var v []string - rvGetSlice4Array(rv, &v) - ft.DecSliceStringN(v, d) - default: - ft.DecSliceStringN(rv2i(rv).([]string), d) - } -} -func (fastpathDT[T]) DecSliceStringY(v []string, d *decoder[T]) (v2 []string, changed bool) { - ctyp := d.d.ContainerType() - if ctyp == valueTypeNil { - return nil, v != nil - } - var containerLenS int - isArray := ctyp == valueTypeArray - if isArray { - containerLenS = d.arrayStart(d.d.ReadArrayStart()) - } else if ctyp == valueTypeMap { - containerLenS = d.mapStart(d.d.ReadMapStart()) * 2 - } else { - halt.errorStr2("decoding into a slice, expect map/array - got ", ctyp.String()) - } - hasLen := containerLenS >= 0 - var j int - fnv := func(dst []string) { v, changed = dst, true } - for ; d.containerNext(j, containerLenS, hasLen); j++ { - if j == 0 { - if containerLenS == len(v) { - } else if containerLenS < 0 || containerLenS > cap(v) { - if xlen := int(decInferLen(containerLenS, d.maxInitLen(), 16)); xlen <= cap(v) { - fnv(v[:uint(xlen)]) - } else { - v2 = make([]string, uint(xlen)) - copy(v2, v) - fnv(v2) - } - } else { - fnv(v[:containerLenS]) - } - } - if isArray { - d.arrayElem(j == 0) - } else if j&1 == 0 { - d.mapElemKey(j == 0) - } else { - d.mapElemValue() - } - if j >= len(v) { - fnv(append(v, "")) - } - v[uint(j)] = d.detach2Str(d.d.DecodeStringAsBytes()) - } - if j < len(v) { - fnv(v[:uint(j)]) - } else if j == 0 && v == nil { - fnv([]string{}) - } - if isArray { - d.arrayEnd() - } else { - d.mapEnd() - } - return v, changed -} -func (fastpathDT[T]) DecSliceStringN(v []string, d *decoder[T]) { - ctyp := d.d.ContainerType() - if ctyp == valueTypeNil { - return - } - var containerLenS int - isArray := ctyp == valueTypeArray - if isArray { - containerLenS = d.arrayStart(d.d.ReadArrayStart()) - } else if ctyp == valueTypeMap { - containerLenS = d.mapStart(d.d.ReadMapStart()) * 2 - } else { - halt.errorStr2("decoding into a slice, expect map/array - got ", ctyp.String()) - } - hasLen := containerLenS >= 0 - for j := 0; d.containerNext(j, containerLenS, hasLen); j++ { - if isArray { - d.arrayElem(j == 0) - } else if j&1 == 0 { - d.mapElemKey(j == 0) - } else { - d.mapElemValue() - } - if j < len(v) { - v[uint(j)] = d.detach2Str(d.d.DecodeStringAsBytes()) - } else { - d.arrayCannotExpand(len(v), j+1) - d.swallow() - } - } - if isArray { - d.arrayEnd() - } else { - d.mapEnd() - } -} - -func (d *decoder[T]) fastpathDecSliceBytesR(f *decFnInfo, rv reflect.Value) { - var ft fastpathDT[T] - switch rv.Kind() { - case reflect.Ptr: - v := rv2i(rv).(*[][]byte) - if vv, changed := ft.DecSliceBytesY(*v, d); changed { - *v = vv - } - case reflect.Array: - var v [][]byte - rvGetSlice4Array(rv, &v) - ft.DecSliceBytesN(v, d) - default: - ft.DecSliceBytesN(rv2i(rv).([][]byte), d) - } -} -func (fastpathDT[T]) DecSliceBytesY(v [][]byte, d *decoder[T]) (v2 [][]byte, changed bool) { - ctyp := d.d.ContainerType() - if ctyp == valueTypeNil { - return nil, v != nil - } - var containerLenS int - isArray := ctyp == valueTypeArray - if isArray { - containerLenS = d.arrayStart(d.d.ReadArrayStart()) - } else if ctyp == valueTypeMap { - containerLenS = d.mapStart(d.d.ReadMapStart()) * 2 - } else { - halt.errorStr2("decoding into a slice, expect map/array - got ", ctyp.String()) - } - hasLen := containerLenS >= 0 - var j int - fnv := func(dst [][]byte) { v, changed = dst, true } - for ; d.containerNext(j, containerLenS, hasLen); j++ { - if j == 0 { - if containerLenS == len(v) { - } else if containerLenS < 0 || containerLenS > cap(v) { - if xlen := int(decInferLen(containerLenS, d.maxInitLen(), 24)); xlen <= cap(v) { - fnv(v[:uint(xlen)]) - } else { - v2 = make([][]byte, uint(xlen)) - copy(v2, v) - fnv(v2) - } - } else { - fnv(v[:containerLenS]) - } - } - if isArray { - d.arrayElem(j == 0) - } else if j&1 == 0 { - d.mapElemKey(j == 0) - } else { - d.mapElemValue() - } - if j >= len(v) { - fnv(append(v, nil)) - } - v[uint(j)] = bytesOKdbi(d.decodeBytesInto(v[uint(j)], false)) - } - if j < len(v) { - fnv(v[:uint(j)]) - } else if j == 0 && v == nil { - fnv([][]byte{}) - } - if isArray { - d.arrayEnd() - } else { - d.mapEnd() - } - return v, changed -} -func (fastpathDT[T]) DecSliceBytesN(v [][]byte, d *decoder[T]) { - ctyp := d.d.ContainerType() - if ctyp == valueTypeNil { - return - } - var containerLenS int - isArray := ctyp == valueTypeArray - if isArray { - containerLenS = d.arrayStart(d.d.ReadArrayStart()) - } else if ctyp == valueTypeMap { - containerLenS = d.mapStart(d.d.ReadMapStart()) * 2 - } else { - halt.errorStr2("decoding into a slice, expect map/array - got ", ctyp.String()) - } - hasLen := containerLenS >= 0 - for j := 0; d.containerNext(j, containerLenS, hasLen); j++ { - if isArray { - d.arrayElem(j == 0) - } else if j&1 == 0 { - d.mapElemKey(j == 0) - } else { - d.mapElemValue() - } - if j < len(v) { - v[uint(j)] = bytesOKdbi(d.decodeBytesInto(v[uint(j)], false)) - } else { - d.arrayCannotExpand(len(v), j+1) - d.swallow() - } - } - if isArray { - d.arrayEnd() - } else { - d.mapEnd() - } -} - -func (d *decoder[T]) fastpathDecSliceFloat32R(f *decFnInfo, rv reflect.Value) { - var ft fastpathDT[T] - switch rv.Kind() { - case reflect.Ptr: - v := rv2i(rv).(*[]float32) - if vv, changed := ft.DecSliceFloat32Y(*v, d); changed { - *v = vv - } - case reflect.Array: - var v []float32 - rvGetSlice4Array(rv, &v) - ft.DecSliceFloat32N(v, d) - default: - ft.DecSliceFloat32N(rv2i(rv).([]float32), d) - } -} -func (fastpathDT[T]) DecSliceFloat32Y(v []float32, d *decoder[T]) (v2 []float32, changed bool) { - ctyp := d.d.ContainerType() - if ctyp == valueTypeNil { - return nil, v != nil - } - var containerLenS int - isArray := ctyp == valueTypeArray - if isArray { - containerLenS = d.arrayStart(d.d.ReadArrayStart()) - } else if ctyp == valueTypeMap { - containerLenS = d.mapStart(d.d.ReadMapStart()) * 2 - } else { - halt.errorStr2("decoding into a slice, expect map/array - got ", ctyp.String()) - } - hasLen := containerLenS >= 0 - var j int - fnv := func(dst []float32) { v, changed = dst, true } - for ; d.containerNext(j, containerLenS, hasLen); j++ { - if j == 0 { - if containerLenS == len(v) { - } else if containerLenS < 0 || containerLenS > cap(v) { - if xlen := int(decInferLen(containerLenS, d.maxInitLen(), 4)); xlen <= cap(v) { - fnv(v[:uint(xlen)]) - } else { - v2 = make([]float32, uint(xlen)) - copy(v2, v) - fnv(v2) - } - } else { - fnv(v[:containerLenS]) - } - } - if isArray { - d.arrayElem(j == 0) - } else if j&1 == 0 { - d.mapElemKey(j == 0) - } else { - d.mapElemValue() - } - if j >= len(v) { - fnv(append(v, 0)) - } - v[uint(j)] = float32(d.d.DecodeFloat32()) - } - if j < len(v) { - fnv(v[:uint(j)]) - } else if j == 0 && v == nil { - fnv([]float32{}) - } - if isArray { - d.arrayEnd() - } else { - d.mapEnd() - } - return v, changed -} -func (fastpathDT[T]) DecSliceFloat32N(v []float32, d *decoder[T]) { - ctyp := d.d.ContainerType() - if ctyp == valueTypeNil { - return - } - var containerLenS int - isArray := ctyp == valueTypeArray - if isArray { - containerLenS = d.arrayStart(d.d.ReadArrayStart()) - } else if ctyp == valueTypeMap { - containerLenS = d.mapStart(d.d.ReadMapStart()) * 2 - } else { - halt.errorStr2("decoding into a slice, expect map/array - got ", ctyp.String()) - } - hasLen := containerLenS >= 0 - for j := 0; d.containerNext(j, containerLenS, hasLen); j++ { - if isArray { - d.arrayElem(j == 0) - } else if j&1 == 0 { - d.mapElemKey(j == 0) - } else { - d.mapElemValue() - } - if j < len(v) { - v[uint(j)] = float32(d.d.DecodeFloat32()) - } else { - d.arrayCannotExpand(len(v), j+1) - d.swallow() - } - } - if isArray { - d.arrayEnd() - } else { - d.mapEnd() - } -} - -func (d *decoder[T]) fastpathDecSliceFloat64R(f *decFnInfo, rv reflect.Value) { - var ft fastpathDT[T] - switch rv.Kind() { - case reflect.Ptr: - v := rv2i(rv).(*[]float64) - if vv, changed := ft.DecSliceFloat64Y(*v, d); changed { - *v = vv - } - case reflect.Array: - var v []float64 - rvGetSlice4Array(rv, &v) - ft.DecSliceFloat64N(v, d) - default: - ft.DecSliceFloat64N(rv2i(rv).([]float64), d) - } -} -func (fastpathDT[T]) DecSliceFloat64Y(v []float64, d *decoder[T]) (v2 []float64, changed bool) { - ctyp := d.d.ContainerType() - if ctyp == valueTypeNil { - return nil, v != nil - } - var containerLenS int - isArray := ctyp == valueTypeArray - if isArray { - containerLenS = d.arrayStart(d.d.ReadArrayStart()) - } else if ctyp == valueTypeMap { - containerLenS = d.mapStart(d.d.ReadMapStart()) * 2 - } else { - halt.errorStr2("decoding into a slice, expect map/array - got ", ctyp.String()) - } - hasLen := containerLenS >= 0 - var j int - fnv := func(dst []float64) { v, changed = dst, true } - for ; d.containerNext(j, containerLenS, hasLen); j++ { - if j == 0 { - if containerLenS == len(v) { - } else if containerLenS < 0 || containerLenS > cap(v) { - if xlen := int(decInferLen(containerLenS, d.maxInitLen(), 8)); xlen <= cap(v) { - fnv(v[:uint(xlen)]) - } else { - v2 = make([]float64, uint(xlen)) - copy(v2, v) - fnv(v2) - } - } else { - fnv(v[:containerLenS]) - } - } - if isArray { - d.arrayElem(j == 0) - } else if j&1 == 0 { - d.mapElemKey(j == 0) - } else { - d.mapElemValue() - } - if j >= len(v) { - fnv(append(v, 0)) - } - v[uint(j)] = d.d.DecodeFloat64() - } - if j < len(v) { - fnv(v[:uint(j)]) - } else if j == 0 && v == nil { - fnv([]float64{}) - } - if isArray { - d.arrayEnd() - } else { - d.mapEnd() - } - return v, changed -} -func (fastpathDT[T]) DecSliceFloat64N(v []float64, d *decoder[T]) { - ctyp := d.d.ContainerType() - if ctyp == valueTypeNil { - return - } - var containerLenS int - isArray := ctyp == valueTypeArray - if isArray { - containerLenS = d.arrayStart(d.d.ReadArrayStart()) - } else if ctyp == valueTypeMap { - containerLenS = d.mapStart(d.d.ReadMapStart()) * 2 - } else { - halt.errorStr2("decoding into a slice, expect map/array - got ", ctyp.String()) - } - hasLen := containerLenS >= 0 - for j := 0; d.containerNext(j, containerLenS, hasLen); j++ { - if isArray { - d.arrayElem(j == 0) - } else if j&1 == 0 { - d.mapElemKey(j == 0) - } else { - d.mapElemValue() - } - if j < len(v) { - v[uint(j)] = d.d.DecodeFloat64() - } else { - d.arrayCannotExpand(len(v), j+1) - d.swallow() - } - } - if isArray { - d.arrayEnd() - } else { - d.mapEnd() - } -} - -func (d *decoder[T]) fastpathDecSliceUint8R(f *decFnInfo, rv reflect.Value) { - var ft fastpathDT[T] - switch rv.Kind() { - case reflect.Ptr: - v := rv2i(rv).(*[]uint8) - if vv, changed := ft.DecSliceUint8Y(*v, d); changed { - *v = vv - } - case reflect.Array: - var v []uint8 - rvGetSlice4Array(rv, &v) - ft.DecSliceUint8N(v, d) - default: - ft.DecSliceUint8N(rv2i(rv).([]uint8), d) - } -} -func (fastpathDT[T]) DecSliceUint8Y(v []uint8, d *decoder[T]) (v2 []uint8, changed bool) { - ctyp := d.d.ContainerType() - if ctyp == valueTypeNil { - return nil, v != nil - } - if ctyp != valueTypeMap { - var dbi dBytesIntoState - v2, dbi = d.decodeBytesInto(v[:len(v):len(v)], false) - return v2, dbi != dBytesIntoParamOut - } - containerLenS := d.mapStart(d.d.ReadMapStart()) * 2 - hasLen := containerLenS >= 0 - var j int - fnv := func(dst []uint8) { v, changed = dst, true } - for ; d.containerNext(j, containerLenS, hasLen); j++ { - if j == 0 { - if containerLenS == len(v) { - } else if containerLenS < 0 || containerLenS > cap(v) { - if xlen := int(decInferLen(containerLenS, d.maxInitLen(), 1)); xlen <= cap(v) { - fnv(v[:uint(xlen)]) - } else { - v2 = make([]uint8, uint(xlen)) - copy(v2, v) - fnv(v2) - } - } else { - fnv(v[:containerLenS]) - } - } - if j&1 == 0 { - d.mapElemKey(j == 0) - } else { - d.mapElemValue() - } - if j >= len(v) { - fnv(append(v, 0)) - } - v[uint(j)] = uint8(chkOvf.UintV(d.d.DecodeUint64(), 8)) - } - if j < len(v) { - fnv(v[:uint(j)]) - } else if j == 0 && v == nil { - fnv([]uint8{}) - } - d.mapEnd() - return v, changed -} -func (fastpathDT[T]) DecSliceUint8N(v []uint8, d *decoder[T]) { - ctyp := d.d.ContainerType() - if ctyp == valueTypeNil { - return - } - if ctyp != valueTypeMap { - d.decodeBytesInto(v[:len(v):len(v)], true) - return - } - containerLenS := d.mapStart(d.d.ReadMapStart()) * 2 - hasLen := containerLenS >= 0 - for j := 0; d.containerNext(j, containerLenS, hasLen); j++ { - if j&1 == 0 { - d.mapElemKey(j == 0) - } else { - d.mapElemValue() - } - if j < len(v) { - v[uint(j)] = uint8(chkOvf.UintV(d.d.DecodeUint64(), 8)) - } else { - d.arrayCannotExpand(len(v), j+1) - d.swallow() - } - } - d.mapEnd() -} - -func (d *decoder[T]) fastpathDecSliceUint64R(f *decFnInfo, rv reflect.Value) { - var ft fastpathDT[T] - switch rv.Kind() { - case reflect.Ptr: - v := rv2i(rv).(*[]uint64) - if vv, changed := ft.DecSliceUint64Y(*v, d); changed { - *v = vv - } - case reflect.Array: - var v []uint64 - rvGetSlice4Array(rv, &v) - ft.DecSliceUint64N(v, d) - default: - ft.DecSliceUint64N(rv2i(rv).([]uint64), d) - } -} -func (fastpathDT[T]) DecSliceUint64Y(v []uint64, d *decoder[T]) (v2 []uint64, changed bool) { - ctyp := d.d.ContainerType() - if ctyp == valueTypeNil { - return nil, v != nil - } - var containerLenS int - isArray := ctyp == valueTypeArray - if isArray { - containerLenS = d.arrayStart(d.d.ReadArrayStart()) - } else if ctyp == valueTypeMap { - containerLenS = d.mapStart(d.d.ReadMapStart()) * 2 - } else { - halt.errorStr2("decoding into a slice, expect map/array - got ", ctyp.String()) - } - hasLen := containerLenS >= 0 - var j int - fnv := func(dst []uint64) { v, changed = dst, true } - for ; d.containerNext(j, containerLenS, hasLen); j++ { - if j == 0 { - if containerLenS == len(v) { - } else if containerLenS < 0 || containerLenS > cap(v) { - if xlen := int(decInferLen(containerLenS, d.maxInitLen(), 8)); xlen <= cap(v) { - fnv(v[:uint(xlen)]) - } else { - v2 = make([]uint64, uint(xlen)) - copy(v2, v) - fnv(v2) - } - } else { - fnv(v[:containerLenS]) - } - } - if isArray { - d.arrayElem(j == 0) - } else if j&1 == 0 { - d.mapElemKey(j == 0) - } else { - d.mapElemValue() - } - if j >= len(v) { - fnv(append(v, 0)) - } - v[uint(j)] = d.d.DecodeUint64() - } - if j < len(v) { - fnv(v[:uint(j)]) - } else if j == 0 && v == nil { - fnv([]uint64{}) - } - if isArray { - d.arrayEnd() - } else { - d.mapEnd() - } - return v, changed -} -func (fastpathDT[T]) DecSliceUint64N(v []uint64, d *decoder[T]) { - ctyp := d.d.ContainerType() - if ctyp == valueTypeNil { - return - } - var containerLenS int - isArray := ctyp == valueTypeArray - if isArray { - containerLenS = d.arrayStart(d.d.ReadArrayStart()) - } else if ctyp == valueTypeMap { - containerLenS = d.mapStart(d.d.ReadMapStart()) * 2 - } else { - halt.errorStr2("decoding into a slice, expect map/array - got ", ctyp.String()) - } - hasLen := containerLenS >= 0 - for j := 0; d.containerNext(j, containerLenS, hasLen); j++ { - if isArray { - d.arrayElem(j == 0) - } else if j&1 == 0 { - d.mapElemKey(j == 0) - } else { - d.mapElemValue() - } - if j < len(v) { - v[uint(j)] = d.d.DecodeUint64() - } else { - d.arrayCannotExpand(len(v), j+1) - d.swallow() - } - } - if isArray { - d.arrayEnd() - } else { - d.mapEnd() - } -} - -func (d *decoder[T]) fastpathDecSliceIntR(f *decFnInfo, rv reflect.Value) { - var ft fastpathDT[T] - switch rv.Kind() { - case reflect.Ptr: - v := rv2i(rv).(*[]int) - if vv, changed := ft.DecSliceIntY(*v, d); changed { - *v = vv - } - case reflect.Array: - var v []int - rvGetSlice4Array(rv, &v) - ft.DecSliceIntN(v, d) - default: - ft.DecSliceIntN(rv2i(rv).([]int), d) - } -} -func (fastpathDT[T]) DecSliceIntY(v []int, d *decoder[T]) (v2 []int, changed bool) { - ctyp := d.d.ContainerType() - if ctyp == valueTypeNil { - return nil, v != nil - } - var containerLenS int - isArray := ctyp == valueTypeArray - if isArray { - containerLenS = d.arrayStart(d.d.ReadArrayStart()) - } else if ctyp == valueTypeMap { - containerLenS = d.mapStart(d.d.ReadMapStart()) * 2 - } else { - halt.errorStr2("decoding into a slice, expect map/array - got ", ctyp.String()) - } - hasLen := containerLenS >= 0 - var j int - fnv := func(dst []int) { v, changed = dst, true } - for ; d.containerNext(j, containerLenS, hasLen); j++ { - if j == 0 { - if containerLenS == len(v) { - } else if containerLenS < 0 || containerLenS > cap(v) { - if xlen := int(decInferLen(containerLenS, d.maxInitLen(), 8)); xlen <= cap(v) { - fnv(v[:uint(xlen)]) - } else { - v2 = make([]int, uint(xlen)) - copy(v2, v) - fnv(v2) - } - } else { - fnv(v[:containerLenS]) - } - } - if isArray { - d.arrayElem(j == 0) - } else if j&1 == 0 { - d.mapElemKey(j == 0) - } else { - d.mapElemValue() - } - if j >= len(v) { - fnv(append(v, 0)) - } - v[uint(j)] = int(chkOvf.IntV(d.d.DecodeInt64(), intBitsize)) - } - if j < len(v) { - fnv(v[:uint(j)]) - } else if j == 0 && v == nil { - fnv([]int{}) - } - if isArray { - d.arrayEnd() - } else { - d.mapEnd() - } - return v, changed -} -func (fastpathDT[T]) DecSliceIntN(v []int, d *decoder[T]) { - ctyp := d.d.ContainerType() - if ctyp == valueTypeNil { - return - } - var containerLenS int - isArray := ctyp == valueTypeArray - if isArray { - containerLenS = d.arrayStart(d.d.ReadArrayStart()) - } else if ctyp == valueTypeMap { - containerLenS = d.mapStart(d.d.ReadMapStart()) * 2 - } else { - halt.errorStr2("decoding into a slice, expect map/array - got ", ctyp.String()) - } - hasLen := containerLenS >= 0 - for j := 0; d.containerNext(j, containerLenS, hasLen); j++ { - if isArray { - d.arrayElem(j == 0) - } else if j&1 == 0 { - d.mapElemKey(j == 0) - } else { - d.mapElemValue() - } - if j < len(v) { - v[uint(j)] = int(chkOvf.IntV(d.d.DecodeInt64(), intBitsize)) - } else { - d.arrayCannotExpand(len(v), j+1) - d.swallow() - } - } - if isArray { - d.arrayEnd() - } else { - d.mapEnd() - } -} - -func (d *decoder[T]) fastpathDecSliceInt32R(f *decFnInfo, rv reflect.Value) { - var ft fastpathDT[T] - switch rv.Kind() { - case reflect.Ptr: - v := rv2i(rv).(*[]int32) - if vv, changed := ft.DecSliceInt32Y(*v, d); changed { - *v = vv - } - case reflect.Array: - var v []int32 - rvGetSlice4Array(rv, &v) - ft.DecSliceInt32N(v, d) - default: - ft.DecSliceInt32N(rv2i(rv).([]int32), d) - } -} -func (fastpathDT[T]) DecSliceInt32Y(v []int32, d *decoder[T]) (v2 []int32, changed bool) { - ctyp := d.d.ContainerType() - if ctyp == valueTypeNil { - return nil, v != nil - } - var containerLenS int - isArray := ctyp == valueTypeArray - if isArray { - containerLenS = d.arrayStart(d.d.ReadArrayStart()) - } else if ctyp == valueTypeMap { - containerLenS = d.mapStart(d.d.ReadMapStart()) * 2 - } else { - halt.errorStr2("decoding into a slice, expect map/array - got ", ctyp.String()) - } - hasLen := containerLenS >= 0 - var j int - fnv := func(dst []int32) { v, changed = dst, true } - for ; d.containerNext(j, containerLenS, hasLen); j++ { - if j == 0 { - if containerLenS == len(v) { - } else if containerLenS < 0 || containerLenS > cap(v) { - if xlen := int(decInferLen(containerLenS, d.maxInitLen(), 4)); xlen <= cap(v) { - fnv(v[:uint(xlen)]) - } else { - v2 = make([]int32, uint(xlen)) - copy(v2, v) - fnv(v2) - } - } else { - fnv(v[:containerLenS]) - } - } - if isArray { - d.arrayElem(j == 0) - } else if j&1 == 0 { - d.mapElemKey(j == 0) - } else { - d.mapElemValue() - } - if j >= len(v) { - fnv(append(v, 0)) - } - v[uint(j)] = int32(chkOvf.IntV(d.d.DecodeInt64(), 32)) - } - if j < len(v) { - fnv(v[:uint(j)]) - } else if j == 0 && v == nil { - fnv([]int32{}) - } - if isArray { - d.arrayEnd() - } else { - d.mapEnd() - } - return v, changed -} -func (fastpathDT[T]) DecSliceInt32N(v []int32, d *decoder[T]) { - ctyp := d.d.ContainerType() - if ctyp == valueTypeNil { - return - } - var containerLenS int - isArray := ctyp == valueTypeArray - if isArray { - containerLenS = d.arrayStart(d.d.ReadArrayStart()) - } else if ctyp == valueTypeMap { - containerLenS = d.mapStart(d.d.ReadMapStart()) * 2 - } else { - halt.errorStr2("decoding into a slice, expect map/array - got ", ctyp.String()) - } - hasLen := containerLenS >= 0 - for j := 0; d.containerNext(j, containerLenS, hasLen); j++ { - if isArray { - d.arrayElem(j == 0) - } else if j&1 == 0 { - d.mapElemKey(j == 0) - } else { - d.mapElemValue() - } - if j < len(v) { - v[uint(j)] = int32(chkOvf.IntV(d.d.DecodeInt64(), 32)) - } else { - d.arrayCannotExpand(len(v), j+1) - d.swallow() - } - } - if isArray { - d.arrayEnd() - } else { - d.mapEnd() - } -} - -func (d *decoder[T]) fastpathDecSliceInt64R(f *decFnInfo, rv reflect.Value) { - var ft fastpathDT[T] - switch rv.Kind() { - case reflect.Ptr: - v := rv2i(rv).(*[]int64) - if vv, changed := ft.DecSliceInt64Y(*v, d); changed { - *v = vv - } - case reflect.Array: - var v []int64 - rvGetSlice4Array(rv, &v) - ft.DecSliceInt64N(v, d) - default: - ft.DecSliceInt64N(rv2i(rv).([]int64), d) - } -} -func (fastpathDT[T]) DecSliceInt64Y(v []int64, d *decoder[T]) (v2 []int64, changed bool) { - ctyp := d.d.ContainerType() - if ctyp == valueTypeNil { - return nil, v != nil - } - var containerLenS int - isArray := ctyp == valueTypeArray - if isArray { - containerLenS = d.arrayStart(d.d.ReadArrayStart()) - } else if ctyp == valueTypeMap { - containerLenS = d.mapStart(d.d.ReadMapStart()) * 2 - } else { - halt.errorStr2("decoding into a slice, expect map/array - got ", ctyp.String()) - } - hasLen := containerLenS >= 0 - var j int - fnv := func(dst []int64) { v, changed = dst, true } - for ; d.containerNext(j, containerLenS, hasLen); j++ { - if j == 0 { - if containerLenS == len(v) { - } else if containerLenS < 0 || containerLenS > cap(v) { - if xlen := int(decInferLen(containerLenS, d.maxInitLen(), 8)); xlen <= cap(v) { - fnv(v[:uint(xlen)]) - } else { - v2 = make([]int64, uint(xlen)) - copy(v2, v) - fnv(v2) - } - } else { - fnv(v[:containerLenS]) - } - } - if isArray { - d.arrayElem(j == 0) - } else if j&1 == 0 { - d.mapElemKey(j == 0) - } else { - d.mapElemValue() - } - if j >= len(v) { - fnv(append(v, 0)) - } - v[uint(j)] = d.d.DecodeInt64() - } - if j < len(v) { - fnv(v[:uint(j)]) - } else if j == 0 && v == nil { - fnv([]int64{}) - } - if isArray { - d.arrayEnd() - } else { - d.mapEnd() - } - return v, changed -} -func (fastpathDT[T]) DecSliceInt64N(v []int64, d *decoder[T]) { - ctyp := d.d.ContainerType() - if ctyp == valueTypeNil { - return - } - var containerLenS int - isArray := ctyp == valueTypeArray - if isArray { - containerLenS = d.arrayStart(d.d.ReadArrayStart()) - } else if ctyp == valueTypeMap { - containerLenS = d.mapStart(d.d.ReadMapStart()) * 2 - } else { - halt.errorStr2("decoding into a slice, expect map/array - got ", ctyp.String()) - } - hasLen := containerLenS >= 0 - for j := 0; d.containerNext(j, containerLenS, hasLen); j++ { - if isArray { - d.arrayElem(j == 0) - } else if j&1 == 0 { - d.mapElemKey(j == 0) - } else { - d.mapElemValue() - } - if j < len(v) { - v[uint(j)] = d.d.DecodeInt64() - } else { - d.arrayCannotExpand(len(v), j+1) - d.swallow() - } - } - if isArray { - d.arrayEnd() - } else { - d.mapEnd() - } -} - -func (d *decoder[T]) fastpathDecSliceBoolR(f *decFnInfo, rv reflect.Value) { - var ft fastpathDT[T] - switch rv.Kind() { - case reflect.Ptr: - v := rv2i(rv).(*[]bool) - if vv, changed := ft.DecSliceBoolY(*v, d); changed { - *v = vv - } - case reflect.Array: - var v []bool - rvGetSlice4Array(rv, &v) - ft.DecSliceBoolN(v, d) - default: - ft.DecSliceBoolN(rv2i(rv).([]bool), d) - } -} -func (fastpathDT[T]) DecSliceBoolY(v []bool, d *decoder[T]) (v2 []bool, changed bool) { - ctyp := d.d.ContainerType() - if ctyp == valueTypeNil { - return nil, v != nil - } - var containerLenS int - isArray := ctyp == valueTypeArray - if isArray { - containerLenS = d.arrayStart(d.d.ReadArrayStart()) - } else if ctyp == valueTypeMap { - containerLenS = d.mapStart(d.d.ReadMapStart()) * 2 - } else { - halt.errorStr2("decoding into a slice, expect map/array - got ", ctyp.String()) - } - hasLen := containerLenS >= 0 - var j int - fnv := func(dst []bool) { v, changed = dst, true } - for ; d.containerNext(j, containerLenS, hasLen); j++ { - if j == 0 { - if containerLenS == len(v) { - } else if containerLenS < 0 || containerLenS > cap(v) { - if xlen := int(decInferLen(containerLenS, d.maxInitLen(), 1)); xlen <= cap(v) { - fnv(v[:uint(xlen)]) - } else { - v2 = make([]bool, uint(xlen)) - copy(v2, v) - fnv(v2) - } - } else { - fnv(v[:containerLenS]) - } - } - if isArray { - d.arrayElem(j == 0) - } else if j&1 == 0 { - d.mapElemKey(j == 0) - } else { - d.mapElemValue() - } - if j >= len(v) { - fnv(append(v, false)) - } - v[uint(j)] = d.d.DecodeBool() - } - if j < len(v) { - fnv(v[:uint(j)]) - } else if j == 0 && v == nil { - fnv([]bool{}) - } - if isArray { - d.arrayEnd() - } else { - d.mapEnd() - } - return v, changed -} -func (fastpathDT[T]) DecSliceBoolN(v []bool, d *decoder[T]) { - ctyp := d.d.ContainerType() - if ctyp == valueTypeNil { - return - } - var containerLenS int - isArray := ctyp == valueTypeArray - if isArray { - containerLenS = d.arrayStart(d.d.ReadArrayStart()) - } else if ctyp == valueTypeMap { - containerLenS = d.mapStart(d.d.ReadMapStart()) * 2 - } else { - halt.errorStr2("decoding into a slice, expect map/array - got ", ctyp.String()) - } - hasLen := containerLenS >= 0 - for j := 0; d.containerNext(j, containerLenS, hasLen); j++ { - if isArray { - d.arrayElem(j == 0) - } else if j&1 == 0 { - d.mapElemKey(j == 0) - } else { - d.mapElemValue() - } - if j < len(v) { - v[uint(j)] = d.d.DecodeBool() - } else { - d.arrayCannotExpand(len(v), j+1) - d.swallow() - } - } - if isArray { - d.arrayEnd() - } else { - d.mapEnd() - } -} -func (d *decoder[T]) fastpathDecMapStringIntfR(f *decFnInfo, rv reflect.Value) { - var ft fastpathDT[T] - containerLen := d.mapStart(d.d.ReadMapStart()) - if rv.Kind() == reflect.Ptr { - vp, _ := rv2i(rv).(*map[string]interface{}) - if *vp == nil { - *vp = make(map[string]interface{}, decInferLen(containerLen, d.maxInitLen(), 32)) - } - if containerLen != 0 { - ft.DecMapStringIntfL(*vp, containerLen, d) - } - } else if containerLen != 0 { - ft.DecMapStringIntfL(rv2i(rv).(map[string]interface{}), containerLen, d) - } - d.mapEnd() -} -func (fastpathDT[T]) DecMapStringIntfL(v map[string]interface{}, containerLen int, d *decoder[T]) { - if v == nil { - halt.errorInt("cannot decode into nil map[string]interface{} given stream length: ", int64(containerLen)) - } - var mv interface{} - mapGet := !d.h.MapValueReset && !d.h.InterfaceReset - hasLen := containerLen >= 0 - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - mk := d.detach2Str(d.d.DecodeStringAsBytes()) - d.mapElemValue() - if mapGet { - mv = v[mk] - } else { - mv = nil - } - d.decode(&mv) - v[mk] = mv - } -} -func (d *decoder[T]) fastpathDecMapStringStringR(f *decFnInfo, rv reflect.Value) { - var ft fastpathDT[T] - containerLen := d.mapStart(d.d.ReadMapStart()) - if rv.Kind() == reflect.Ptr { - vp, _ := rv2i(rv).(*map[string]string) - if *vp == nil { - *vp = make(map[string]string, decInferLen(containerLen, d.maxInitLen(), 32)) - } - if containerLen != 0 { - ft.DecMapStringStringL(*vp, containerLen, d) - } - } else if containerLen != 0 { - ft.DecMapStringStringL(rv2i(rv).(map[string]string), containerLen, d) - } - d.mapEnd() -} -func (fastpathDT[T]) DecMapStringStringL(v map[string]string, containerLen int, d *decoder[T]) { - if v == nil { - halt.errorInt("cannot decode into nil map[string]string given stream length: ", int64(containerLen)) - } - hasLen := containerLen >= 0 - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - mk := d.detach2Str(d.d.DecodeStringAsBytes()) - d.mapElemValue() - v[mk] = d.detach2Str(d.d.DecodeStringAsBytes()) - } -} -func (d *decoder[T]) fastpathDecMapStringBytesR(f *decFnInfo, rv reflect.Value) { - var ft fastpathDT[T] - containerLen := d.mapStart(d.d.ReadMapStart()) - if rv.Kind() == reflect.Ptr { - vp, _ := rv2i(rv).(*map[string][]byte) - if *vp == nil { - *vp = make(map[string][]byte, decInferLen(containerLen, d.maxInitLen(), 40)) - } - if containerLen != 0 { - ft.DecMapStringBytesL(*vp, containerLen, d) - } - } else if containerLen != 0 { - ft.DecMapStringBytesL(rv2i(rv).(map[string][]byte), containerLen, d) - } - d.mapEnd() -} -func (fastpathDT[T]) DecMapStringBytesL(v map[string][]byte, containerLen int, d *decoder[T]) { - if v == nil { - halt.errorInt("cannot decode into nil map[string][]byte given stream length: ", int64(containerLen)) - } - var mv []byte - mapGet := !d.h.MapValueReset - hasLen := containerLen >= 0 - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - mk := d.detach2Str(d.d.DecodeStringAsBytes()) - d.mapElemValue() - if mapGet { - mv = v[mk] - } else { - mv = nil - } - v[mk], _ = d.decodeBytesInto(mv, false) - } -} -func (d *decoder[T]) fastpathDecMapStringUint8R(f *decFnInfo, rv reflect.Value) { - var ft fastpathDT[T] - containerLen := d.mapStart(d.d.ReadMapStart()) - if rv.Kind() == reflect.Ptr { - vp, _ := rv2i(rv).(*map[string]uint8) - if *vp == nil { - *vp = make(map[string]uint8, decInferLen(containerLen, d.maxInitLen(), 17)) - } - if containerLen != 0 { - ft.DecMapStringUint8L(*vp, containerLen, d) - } - } else if containerLen != 0 { - ft.DecMapStringUint8L(rv2i(rv).(map[string]uint8), containerLen, d) - } - d.mapEnd() -} -func (fastpathDT[T]) DecMapStringUint8L(v map[string]uint8, containerLen int, d *decoder[T]) { - if v == nil { - halt.errorInt("cannot decode into nil map[string]uint8 given stream length: ", int64(containerLen)) - } - hasLen := containerLen >= 0 - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - mk := d.detach2Str(d.d.DecodeStringAsBytes()) - d.mapElemValue() - v[mk] = uint8(chkOvf.UintV(d.d.DecodeUint64(), 8)) - } -} -func (d *decoder[T]) fastpathDecMapStringUint64R(f *decFnInfo, rv reflect.Value) { - var ft fastpathDT[T] - containerLen := d.mapStart(d.d.ReadMapStart()) - if rv.Kind() == reflect.Ptr { - vp, _ := rv2i(rv).(*map[string]uint64) - if *vp == nil { - *vp = make(map[string]uint64, decInferLen(containerLen, d.maxInitLen(), 24)) - } - if containerLen != 0 { - ft.DecMapStringUint64L(*vp, containerLen, d) - } - } else if containerLen != 0 { - ft.DecMapStringUint64L(rv2i(rv).(map[string]uint64), containerLen, d) - } - d.mapEnd() -} -func (fastpathDT[T]) DecMapStringUint64L(v map[string]uint64, containerLen int, d *decoder[T]) { - if v == nil { - halt.errorInt("cannot decode into nil map[string]uint64 given stream length: ", int64(containerLen)) - } - hasLen := containerLen >= 0 - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - mk := d.detach2Str(d.d.DecodeStringAsBytes()) - d.mapElemValue() - v[mk] = d.d.DecodeUint64() - } -} -func (d *decoder[T]) fastpathDecMapStringIntR(f *decFnInfo, rv reflect.Value) { - var ft fastpathDT[T] - containerLen := d.mapStart(d.d.ReadMapStart()) - if rv.Kind() == reflect.Ptr { - vp, _ := rv2i(rv).(*map[string]int) - if *vp == nil { - *vp = make(map[string]int, decInferLen(containerLen, d.maxInitLen(), 24)) - } - if containerLen != 0 { - ft.DecMapStringIntL(*vp, containerLen, d) - } - } else if containerLen != 0 { - ft.DecMapStringIntL(rv2i(rv).(map[string]int), containerLen, d) - } - d.mapEnd() -} -func (fastpathDT[T]) DecMapStringIntL(v map[string]int, containerLen int, d *decoder[T]) { - if v == nil { - halt.errorInt("cannot decode into nil map[string]int given stream length: ", int64(containerLen)) - } - hasLen := containerLen >= 0 - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - mk := d.detach2Str(d.d.DecodeStringAsBytes()) - d.mapElemValue() - v[mk] = int(chkOvf.IntV(d.d.DecodeInt64(), intBitsize)) - } -} -func (d *decoder[T]) fastpathDecMapStringInt32R(f *decFnInfo, rv reflect.Value) { - var ft fastpathDT[T] - containerLen := d.mapStart(d.d.ReadMapStart()) - if rv.Kind() == reflect.Ptr { - vp, _ := rv2i(rv).(*map[string]int32) - if *vp == nil { - *vp = make(map[string]int32, decInferLen(containerLen, d.maxInitLen(), 20)) - } - if containerLen != 0 { - ft.DecMapStringInt32L(*vp, containerLen, d) - } - } else if containerLen != 0 { - ft.DecMapStringInt32L(rv2i(rv).(map[string]int32), containerLen, d) - } - d.mapEnd() -} -func (fastpathDT[T]) DecMapStringInt32L(v map[string]int32, containerLen int, d *decoder[T]) { - if v == nil { - halt.errorInt("cannot decode into nil map[string]int32 given stream length: ", int64(containerLen)) - } - hasLen := containerLen >= 0 - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - mk := d.detach2Str(d.d.DecodeStringAsBytes()) - d.mapElemValue() - v[mk] = int32(chkOvf.IntV(d.d.DecodeInt64(), 32)) - } -} -func (d *decoder[T]) fastpathDecMapStringFloat64R(f *decFnInfo, rv reflect.Value) { - var ft fastpathDT[T] - containerLen := d.mapStart(d.d.ReadMapStart()) - if rv.Kind() == reflect.Ptr { - vp, _ := rv2i(rv).(*map[string]float64) - if *vp == nil { - *vp = make(map[string]float64, decInferLen(containerLen, d.maxInitLen(), 24)) - } - if containerLen != 0 { - ft.DecMapStringFloat64L(*vp, containerLen, d) - } - } else if containerLen != 0 { - ft.DecMapStringFloat64L(rv2i(rv).(map[string]float64), containerLen, d) - } - d.mapEnd() -} -func (fastpathDT[T]) DecMapStringFloat64L(v map[string]float64, containerLen int, d *decoder[T]) { - if v == nil { - halt.errorInt("cannot decode into nil map[string]float64 given stream length: ", int64(containerLen)) - } - hasLen := containerLen >= 0 - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - mk := d.detach2Str(d.d.DecodeStringAsBytes()) - d.mapElemValue() - v[mk] = d.d.DecodeFloat64() - } -} -func (d *decoder[T]) fastpathDecMapStringBoolR(f *decFnInfo, rv reflect.Value) { - var ft fastpathDT[T] - containerLen := d.mapStart(d.d.ReadMapStart()) - if rv.Kind() == reflect.Ptr { - vp, _ := rv2i(rv).(*map[string]bool) - if *vp == nil { - *vp = make(map[string]bool, decInferLen(containerLen, d.maxInitLen(), 17)) - } - if containerLen != 0 { - ft.DecMapStringBoolL(*vp, containerLen, d) - } - } else if containerLen != 0 { - ft.DecMapStringBoolL(rv2i(rv).(map[string]bool), containerLen, d) - } - d.mapEnd() -} -func (fastpathDT[T]) DecMapStringBoolL(v map[string]bool, containerLen int, d *decoder[T]) { - if v == nil { - halt.errorInt("cannot decode into nil map[string]bool given stream length: ", int64(containerLen)) - } - hasLen := containerLen >= 0 - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - mk := d.detach2Str(d.d.DecodeStringAsBytes()) - d.mapElemValue() - v[mk] = d.d.DecodeBool() - } -} -func (d *decoder[T]) fastpathDecMapUint8IntfR(f *decFnInfo, rv reflect.Value) { - var ft fastpathDT[T] - containerLen := d.mapStart(d.d.ReadMapStart()) - if rv.Kind() == reflect.Ptr { - vp, _ := rv2i(rv).(*map[uint8]interface{}) - if *vp == nil { - *vp = make(map[uint8]interface{}, decInferLen(containerLen, d.maxInitLen(), 17)) - } - if containerLen != 0 { - ft.DecMapUint8IntfL(*vp, containerLen, d) - } - } else if containerLen != 0 { - ft.DecMapUint8IntfL(rv2i(rv).(map[uint8]interface{}), containerLen, d) - } - d.mapEnd() -} -func (fastpathDT[T]) DecMapUint8IntfL(v map[uint8]interface{}, containerLen int, d *decoder[T]) { - if v == nil { - halt.errorInt("cannot decode into nil map[uint8]interface{} given stream length: ", int64(containerLen)) - } - var mv interface{} - mapGet := !d.h.MapValueReset && !d.h.InterfaceReset - hasLen := containerLen >= 0 - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - mk := uint8(chkOvf.UintV(d.d.DecodeUint64(), 8)) - d.mapElemValue() - if mapGet { - mv = v[mk] - } else { - mv = nil - } - d.decode(&mv) - v[mk] = mv - } -} -func (d *decoder[T]) fastpathDecMapUint8StringR(f *decFnInfo, rv reflect.Value) { - var ft fastpathDT[T] - containerLen := d.mapStart(d.d.ReadMapStart()) - if rv.Kind() == reflect.Ptr { - vp, _ := rv2i(rv).(*map[uint8]string) - if *vp == nil { - *vp = make(map[uint8]string, decInferLen(containerLen, d.maxInitLen(), 17)) - } - if containerLen != 0 { - ft.DecMapUint8StringL(*vp, containerLen, d) - } - } else if containerLen != 0 { - ft.DecMapUint8StringL(rv2i(rv).(map[uint8]string), containerLen, d) - } - d.mapEnd() -} -func (fastpathDT[T]) DecMapUint8StringL(v map[uint8]string, containerLen int, d *decoder[T]) { - if v == nil { - halt.errorInt("cannot decode into nil map[uint8]string given stream length: ", int64(containerLen)) - } - hasLen := containerLen >= 0 - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - mk := uint8(chkOvf.UintV(d.d.DecodeUint64(), 8)) - d.mapElemValue() - v[mk] = d.detach2Str(d.d.DecodeStringAsBytes()) - } -} -func (d *decoder[T]) fastpathDecMapUint8BytesR(f *decFnInfo, rv reflect.Value) { - var ft fastpathDT[T] - containerLen := d.mapStart(d.d.ReadMapStart()) - if rv.Kind() == reflect.Ptr { - vp, _ := rv2i(rv).(*map[uint8][]byte) - if *vp == nil { - *vp = make(map[uint8][]byte, decInferLen(containerLen, d.maxInitLen(), 25)) - } - if containerLen != 0 { - ft.DecMapUint8BytesL(*vp, containerLen, d) - } - } else if containerLen != 0 { - ft.DecMapUint8BytesL(rv2i(rv).(map[uint8][]byte), containerLen, d) - } - d.mapEnd() -} -func (fastpathDT[T]) DecMapUint8BytesL(v map[uint8][]byte, containerLen int, d *decoder[T]) { - if v == nil { - halt.errorInt("cannot decode into nil map[uint8][]byte given stream length: ", int64(containerLen)) - } - var mv []byte - mapGet := !d.h.MapValueReset - hasLen := containerLen >= 0 - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - mk := uint8(chkOvf.UintV(d.d.DecodeUint64(), 8)) - d.mapElemValue() - if mapGet { - mv = v[mk] - } else { - mv = nil - } - v[mk], _ = d.decodeBytesInto(mv, false) - } -} -func (d *decoder[T]) fastpathDecMapUint8Uint8R(f *decFnInfo, rv reflect.Value) { - var ft fastpathDT[T] - containerLen := d.mapStart(d.d.ReadMapStart()) - if rv.Kind() == reflect.Ptr { - vp, _ := rv2i(rv).(*map[uint8]uint8) - if *vp == nil { - *vp = make(map[uint8]uint8, decInferLen(containerLen, d.maxInitLen(), 2)) - } - if containerLen != 0 { - ft.DecMapUint8Uint8L(*vp, containerLen, d) - } - } else if containerLen != 0 { - ft.DecMapUint8Uint8L(rv2i(rv).(map[uint8]uint8), containerLen, d) - } - d.mapEnd() -} -func (fastpathDT[T]) DecMapUint8Uint8L(v map[uint8]uint8, containerLen int, d *decoder[T]) { - if v == nil { - halt.errorInt("cannot decode into nil map[uint8]uint8 given stream length: ", int64(containerLen)) - } - hasLen := containerLen >= 0 - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - mk := uint8(chkOvf.UintV(d.d.DecodeUint64(), 8)) - d.mapElemValue() - v[mk] = uint8(chkOvf.UintV(d.d.DecodeUint64(), 8)) - } -} -func (d *decoder[T]) fastpathDecMapUint8Uint64R(f *decFnInfo, rv reflect.Value) { - var ft fastpathDT[T] - containerLen := d.mapStart(d.d.ReadMapStart()) - if rv.Kind() == reflect.Ptr { - vp, _ := rv2i(rv).(*map[uint8]uint64) - if *vp == nil { - *vp = make(map[uint8]uint64, decInferLen(containerLen, d.maxInitLen(), 9)) - } - if containerLen != 0 { - ft.DecMapUint8Uint64L(*vp, containerLen, d) - } - } else if containerLen != 0 { - ft.DecMapUint8Uint64L(rv2i(rv).(map[uint8]uint64), containerLen, d) - } - d.mapEnd() -} -func (fastpathDT[T]) DecMapUint8Uint64L(v map[uint8]uint64, containerLen int, d *decoder[T]) { - if v == nil { - halt.errorInt("cannot decode into nil map[uint8]uint64 given stream length: ", int64(containerLen)) - } - hasLen := containerLen >= 0 - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - mk := uint8(chkOvf.UintV(d.d.DecodeUint64(), 8)) - d.mapElemValue() - v[mk] = d.d.DecodeUint64() - } -} -func (d *decoder[T]) fastpathDecMapUint8IntR(f *decFnInfo, rv reflect.Value) { - var ft fastpathDT[T] - containerLen := d.mapStart(d.d.ReadMapStart()) - if rv.Kind() == reflect.Ptr { - vp, _ := rv2i(rv).(*map[uint8]int) - if *vp == nil { - *vp = make(map[uint8]int, decInferLen(containerLen, d.maxInitLen(), 9)) - } - if containerLen != 0 { - ft.DecMapUint8IntL(*vp, containerLen, d) - } - } else if containerLen != 0 { - ft.DecMapUint8IntL(rv2i(rv).(map[uint8]int), containerLen, d) - } - d.mapEnd() -} -func (fastpathDT[T]) DecMapUint8IntL(v map[uint8]int, containerLen int, d *decoder[T]) { - if v == nil { - halt.errorInt("cannot decode into nil map[uint8]int given stream length: ", int64(containerLen)) - } - hasLen := containerLen >= 0 - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - mk := uint8(chkOvf.UintV(d.d.DecodeUint64(), 8)) - d.mapElemValue() - v[mk] = int(chkOvf.IntV(d.d.DecodeInt64(), intBitsize)) - } -} -func (d *decoder[T]) fastpathDecMapUint8Int32R(f *decFnInfo, rv reflect.Value) { - var ft fastpathDT[T] - containerLen := d.mapStart(d.d.ReadMapStart()) - if rv.Kind() == reflect.Ptr { - vp, _ := rv2i(rv).(*map[uint8]int32) - if *vp == nil { - *vp = make(map[uint8]int32, decInferLen(containerLen, d.maxInitLen(), 5)) - } - if containerLen != 0 { - ft.DecMapUint8Int32L(*vp, containerLen, d) - } - } else if containerLen != 0 { - ft.DecMapUint8Int32L(rv2i(rv).(map[uint8]int32), containerLen, d) - } - d.mapEnd() -} -func (fastpathDT[T]) DecMapUint8Int32L(v map[uint8]int32, containerLen int, d *decoder[T]) { - if v == nil { - halt.errorInt("cannot decode into nil map[uint8]int32 given stream length: ", int64(containerLen)) - } - hasLen := containerLen >= 0 - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - mk := uint8(chkOvf.UintV(d.d.DecodeUint64(), 8)) - d.mapElemValue() - v[mk] = int32(chkOvf.IntV(d.d.DecodeInt64(), 32)) - } -} -func (d *decoder[T]) fastpathDecMapUint8Float64R(f *decFnInfo, rv reflect.Value) { - var ft fastpathDT[T] - containerLen := d.mapStart(d.d.ReadMapStart()) - if rv.Kind() == reflect.Ptr { - vp, _ := rv2i(rv).(*map[uint8]float64) - if *vp == nil { - *vp = make(map[uint8]float64, decInferLen(containerLen, d.maxInitLen(), 9)) - } - if containerLen != 0 { - ft.DecMapUint8Float64L(*vp, containerLen, d) - } - } else if containerLen != 0 { - ft.DecMapUint8Float64L(rv2i(rv).(map[uint8]float64), containerLen, d) - } - d.mapEnd() -} -func (fastpathDT[T]) DecMapUint8Float64L(v map[uint8]float64, containerLen int, d *decoder[T]) { - if v == nil { - halt.errorInt("cannot decode into nil map[uint8]float64 given stream length: ", int64(containerLen)) - } - hasLen := containerLen >= 0 - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - mk := uint8(chkOvf.UintV(d.d.DecodeUint64(), 8)) - d.mapElemValue() - v[mk] = d.d.DecodeFloat64() - } -} -func (d *decoder[T]) fastpathDecMapUint8BoolR(f *decFnInfo, rv reflect.Value) { - var ft fastpathDT[T] - containerLen := d.mapStart(d.d.ReadMapStart()) - if rv.Kind() == reflect.Ptr { - vp, _ := rv2i(rv).(*map[uint8]bool) - if *vp == nil { - *vp = make(map[uint8]bool, decInferLen(containerLen, d.maxInitLen(), 2)) - } - if containerLen != 0 { - ft.DecMapUint8BoolL(*vp, containerLen, d) - } - } else if containerLen != 0 { - ft.DecMapUint8BoolL(rv2i(rv).(map[uint8]bool), containerLen, d) - } - d.mapEnd() -} -func (fastpathDT[T]) DecMapUint8BoolL(v map[uint8]bool, containerLen int, d *decoder[T]) { - if v == nil { - halt.errorInt("cannot decode into nil map[uint8]bool given stream length: ", int64(containerLen)) - } - hasLen := containerLen >= 0 - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - mk := uint8(chkOvf.UintV(d.d.DecodeUint64(), 8)) - d.mapElemValue() - v[mk] = d.d.DecodeBool() - } -} -func (d *decoder[T]) fastpathDecMapUint64IntfR(f *decFnInfo, rv reflect.Value) { - var ft fastpathDT[T] - containerLen := d.mapStart(d.d.ReadMapStart()) - if rv.Kind() == reflect.Ptr { - vp, _ := rv2i(rv).(*map[uint64]interface{}) - if *vp == nil { - *vp = make(map[uint64]interface{}, decInferLen(containerLen, d.maxInitLen(), 24)) - } - if containerLen != 0 { - ft.DecMapUint64IntfL(*vp, containerLen, d) - } - } else if containerLen != 0 { - ft.DecMapUint64IntfL(rv2i(rv).(map[uint64]interface{}), containerLen, d) - } - d.mapEnd() -} -func (fastpathDT[T]) DecMapUint64IntfL(v map[uint64]interface{}, containerLen int, d *decoder[T]) { - if v == nil { - halt.errorInt("cannot decode into nil map[uint64]interface{} given stream length: ", int64(containerLen)) - } - var mv interface{} - mapGet := !d.h.MapValueReset && !d.h.InterfaceReset - hasLen := containerLen >= 0 - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - mk := d.d.DecodeUint64() - d.mapElemValue() - if mapGet { - mv = v[mk] - } else { - mv = nil - } - d.decode(&mv) - v[mk] = mv - } -} -func (d *decoder[T]) fastpathDecMapUint64StringR(f *decFnInfo, rv reflect.Value) { - var ft fastpathDT[T] - containerLen := d.mapStart(d.d.ReadMapStart()) - if rv.Kind() == reflect.Ptr { - vp, _ := rv2i(rv).(*map[uint64]string) - if *vp == nil { - *vp = make(map[uint64]string, decInferLen(containerLen, d.maxInitLen(), 24)) - } - if containerLen != 0 { - ft.DecMapUint64StringL(*vp, containerLen, d) - } - } else if containerLen != 0 { - ft.DecMapUint64StringL(rv2i(rv).(map[uint64]string), containerLen, d) - } - d.mapEnd() -} -func (fastpathDT[T]) DecMapUint64StringL(v map[uint64]string, containerLen int, d *decoder[T]) { - if v == nil { - halt.errorInt("cannot decode into nil map[uint64]string given stream length: ", int64(containerLen)) - } - hasLen := containerLen >= 0 - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - mk := d.d.DecodeUint64() - d.mapElemValue() - v[mk] = d.detach2Str(d.d.DecodeStringAsBytes()) - } -} -func (d *decoder[T]) fastpathDecMapUint64BytesR(f *decFnInfo, rv reflect.Value) { - var ft fastpathDT[T] - containerLen := d.mapStart(d.d.ReadMapStart()) - if rv.Kind() == reflect.Ptr { - vp, _ := rv2i(rv).(*map[uint64][]byte) - if *vp == nil { - *vp = make(map[uint64][]byte, decInferLen(containerLen, d.maxInitLen(), 32)) - } - if containerLen != 0 { - ft.DecMapUint64BytesL(*vp, containerLen, d) - } - } else if containerLen != 0 { - ft.DecMapUint64BytesL(rv2i(rv).(map[uint64][]byte), containerLen, d) - } - d.mapEnd() -} -func (fastpathDT[T]) DecMapUint64BytesL(v map[uint64][]byte, containerLen int, d *decoder[T]) { - if v == nil { - halt.errorInt("cannot decode into nil map[uint64][]byte given stream length: ", int64(containerLen)) - } - var mv []byte - mapGet := !d.h.MapValueReset - hasLen := containerLen >= 0 - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - mk := d.d.DecodeUint64() - d.mapElemValue() - if mapGet { - mv = v[mk] - } else { - mv = nil - } - v[mk], _ = d.decodeBytesInto(mv, false) - } -} -func (d *decoder[T]) fastpathDecMapUint64Uint8R(f *decFnInfo, rv reflect.Value) { - var ft fastpathDT[T] - containerLen := d.mapStart(d.d.ReadMapStart()) - if rv.Kind() == reflect.Ptr { - vp, _ := rv2i(rv).(*map[uint64]uint8) - if *vp == nil { - *vp = make(map[uint64]uint8, decInferLen(containerLen, d.maxInitLen(), 9)) - } - if containerLen != 0 { - ft.DecMapUint64Uint8L(*vp, containerLen, d) - } - } else if containerLen != 0 { - ft.DecMapUint64Uint8L(rv2i(rv).(map[uint64]uint8), containerLen, d) - } - d.mapEnd() -} -func (fastpathDT[T]) DecMapUint64Uint8L(v map[uint64]uint8, containerLen int, d *decoder[T]) { - if v == nil { - halt.errorInt("cannot decode into nil map[uint64]uint8 given stream length: ", int64(containerLen)) - } - hasLen := containerLen >= 0 - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - mk := d.d.DecodeUint64() - d.mapElemValue() - v[mk] = uint8(chkOvf.UintV(d.d.DecodeUint64(), 8)) - } -} -func (d *decoder[T]) fastpathDecMapUint64Uint64R(f *decFnInfo, rv reflect.Value) { - var ft fastpathDT[T] - containerLen := d.mapStart(d.d.ReadMapStart()) - if rv.Kind() == reflect.Ptr { - vp, _ := rv2i(rv).(*map[uint64]uint64) - if *vp == nil { - *vp = make(map[uint64]uint64, decInferLen(containerLen, d.maxInitLen(), 16)) - } - if containerLen != 0 { - ft.DecMapUint64Uint64L(*vp, containerLen, d) - } - } else if containerLen != 0 { - ft.DecMapUint64Uint64L(rv2i(rv).(map[uint64]uint64), containerLen, d) - } - d.mapEnd() -} -func (fastpathDT[T]) DecMapUint64Uint64L(v map[uint64]uint64, containerLen int, d *decoder[T]) { - if v == nil { - halt.errorInt("cannot decode into nil map[uint64]uint64 given stream length: ", int64(containerLen)) - } - hasLen := containerLen >= 0 - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - mk := d.d.DecodeUint64() - d.mapElemValue() - v[mk] = d.d.DecodeUint64() - } -} -func (d *decoder[T]) fastpathDecMapUint64IntR(f *decFnInfo, rv reflect.Value) { - var ft fastpathDT[T] - containerLen := d.mapStart(d.d.ReadMapStart()) - if rv.Kind() == reflect.Ptr { - vp, _ := rv2i(rv).(*map[uint64]int) - if *vp == nil { - *vp = make(map[uint64]int, decInferLen(containerLen, d.maxInitLen(), 16)) - } - if containerLen != 0 { - ft.DecMapUint64IntL(*vp, containerLen, d) - } - } else if containerLen != 0 { - ft.DecMapUint64IntL(rv2i(rv).(map[uint64]int), containerLen, d) - } - d.mapEnd() -} -func (fastpathDT[T]) DecMapUint64IntL(v map[uint64]int, containerLen int, d *decoder[T]) { - if v == nil { - halt.errorInt("cannot decode into nil map[uint64]int given stream length: ", int64(containerLen)) - } - hasLen := containerLen >= 0 - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - mk := d.d.DecodeUint64() - d.mapElemValue() - v[mk] = int(chkOvf.IntV(d.d.DecodeInt64(), intBitsize)) - } -} -func (d *decoder[T]) fastpathDecMapUint64Int32R(f *decFnInfo, rv reflect.Value) { - var ft fastpathDT[T] - containerLen := d.mapStart(d.d.ReadMapStart()) - if rv.Kind() == reflect.Ptr { - vp, _ := rv2i(rv).(*map[uint64]int32) - if *vp == nil { - *vp = make(map[uint64]int32, decInferLen(containerLen, d.maxInitLen(), 12)) - } - if containerLen != 0 { - ft.DecMapUint64Int32L(*vp, containerLen, d) - } - } else if containerLen != 0 { - ft.DecMapUint64Int32L(rv2i(rv).(map[uint64]int32), containerLen, d) - } - d.mapEnd() -} -func (fastpathDT[T]) DecMapUint64Int32L(v map[uint64]int32, containerLen int, d *decoder[T]) { - if v == nil { - halt.errorInt("cannot decode into nil map[uint64]int32 given stream length: ", int64(containerLen)) - } - hasLen := containerLen >= 0 - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - mk := d.d.DecodeUint64() - d.mapElemValue() - v[mk] = int32(chkOvf.IntV(d.d.DecodeInt64(), 32)) - } -} -func (d *decoder[T]) fastpathDecMapUint64Float64R(f *decFnInfo, rv reflect.Value) { - var ft fastpathDT[T] - containerLen := d.mapStart(d.d.ReadMapStart()) - if rv.Kind() == reflect.Ptr { - vp, _ := rv2i(rv).(*map[uint64]float64) - if *vp == nil { - *vp = make(map[uint64]float64, decInferLen(containerLen, d.maxInitLen(), 16)) - } - if containerLen != 0 { - ft.DecMapUint64Float64L(*vp, containerLen, d) - } - } else if containerLen != 0 { - ft.DecMapUint64Float64L(rv2i(rv).(map[uint64]float64), containerLen, d) - } - d.mapEnd() -} -func (fastpathDT[T]) DecMapUint64Float64L(v map[uint64]float64, containerLen int, d *decoder[T]) { - if v == nil { - halt.errorInt("cannot decode into nil map[uint64]float64 given stream length: ", int64(containerLen)) - } - hasLen := containerLen >= 0 - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - mk := d.d.DecodeUint64() - d.mapElemValue() - v[mk] = d.d.DecodeFloat64() - } -} -func (d *decoder[T]) fastpathDecMapUint64BoolR(f *decFnInfo, rv reflect.Value) { - var ft fastpathDT[T] - containerLen := d.mapStart(d.d.ReadMapStart()) - if rv.Kind() == reflect.Ptr { - vp, _ := rv2i(rv).(*map[uint64]bool) - if *vp == nil { - *vp = make(map[uint64]bool, decInferLen(containerLen, d.maxInitLen(), 9)) - } - if containerLen != 0 { - ft.DecMapUint64BoolL(*vp, containerLen, d) - } - } else if containerLen != 0 { - ft.DecMapUint64BoolL(rv2i(rv).(map[uint64]bool), containerLen, d) - } - d.mapEnd() -} -func (fastpathDT[T]) DecMapUint64BoolL(v map[uint64]bool, containerLen int, d *decoder[T]) { - if v == nil { - halt.errorInt("cannot decode into nil map[uint64]bool given stream length: ", int64(containerLen)) - } - hasLen := containerLen >= 0 - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - mk := d.d.DecodeUint64() - d.mapElemValue() - v[mk] = d.d.DecodeBool() - } -} -func (d *decoder[T]) fastpathDecMapIntIntfR(f *decFnInfo, rv reflect.Value) { - var ft fastpathDT[T] - containerLen := d.mapStart(d.d.ReadMapStart()) - if rv.Kind() == reflect.Ptr { - vp, _ := rv2i(rv).(*map[int]interface{}) - if *vp == nil { - *vp = make(map[int]interface{}, decInferLen(containerLen, d.maxInitLen(), 24)) - } - if containerLen != 0 { - ft.DecMapIntIntfL(*vp, containerLen, d) - } - } else if containerLen != 0 { - ft.DecMapIntIntfL(rv2i(rv).(map[int]interface{}), containerLen, d) - } - d.mapEnd() -} -func (fastpathDT[T]) DecMapIntIntfL(v map[int]interface{}, containerLen int, d *decoder[T]) { - if v == nil { - halt.errorInt("cannot decode into nil map[int]interface{} given stream length: ", int64(containerLen)) - } - var mv interface{} - mapGet := !d.h.MapValueReset && !d.h.InterfaceReset - hasLen := containerLen >= 0 - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - mk := int(chkOvf.IntV(d.d.DecodeInt64(), intBitsize)) - d.mapElemValue() - if mapGet { - mv = v[mk] - } else { - mv = nil - } - d.decode(&mv) - v[mk] = mv - } -} -func (d *decoder[T]) fastpathDecMapIntStringR(f *decFnInfo, rv reflect.Value) { - var ft fastpathDT[T] - containerLen := d.mapStart(d.d.ReadMapStart()) - if rv.Kind() == reflect.Ptr { - vp, _ := rv2i(rv).(*map[int]string) - if *vp == nil { - *vp = make(map[int]string, decInferLen(containerLen, d.maxInitLen(), 24)) - } - if containerLen != 0 { - ft.DecMapIntStringL(*vp, containerLen, d) - } - } else if containerLen != 0 { - ft.DecMapIntStringL(rv2i(rv).(map[int]string), containerLen, d) - } - d.mapEnd() -} -func (fastpathDT[T]) DecMapIntStringL(v map[int]string, containerLen int, d *decoder[T]) { - if v == nil { - halt.errorInt("cannot decode into nil map[int]string given stream length: ", int64(containerLen)) - } - hasLen := containerLen >= 0 - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - mk := int(chkOvf.IntV(d.d.DecodeInt64(), intBitsize)) - d.mapElemValue() - v[mk] = d.detach2Str(d.d.DecodeStringAsBytes()) - } -} -func (d *decoder[T]) fastpathDecMapIntBytesR(f *decFnInfo, rv reflect.Value) { - var ft fastpathDT[T] - containerLen := d.mapStart(d.d.ReadMapStart()) - if rv.Kind() == reflect.Ptr { - vp, _ := rv2i(rv).(*map[int][]byte) - if *vp == nil { - *vp = make(map[int][]byte, decInferLen(containerLen, d.maxInitLen(), 32)) - } - if containerLen != 0 { - ft.DecMapIntBytesL(*vp, containerLen, d) - } - } else if containerLen != 0 { - ft.DecMapIntBytesL(rv2i(rv).(map[int][]byte), containerLen, d) - } - d.mapEnd() -} -func (fastpathDT[T]) DecMapIntBytesL(v map[int][]byte, containerLen int, d *decoder[T]) { - if v == nil { - halt.errorInt("cannot decode into nil map[int][]byte given stream length: ", int64(containerLen)) - } - var mv []byte - mapGet := !d.h.MapValueReset - hasLen := containerLen >= 0 - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - mk := int(chkOvf.IntV(d.d.DecodeInt64(), intBitsize)) - d.mapElemValue() - if mapGet { - mv = v[mk] - } else { - mv = nil - } - v[mk], _ = d.decodeBytesInto(mv, false) - } -} -func (d *decoder[T]) fastpathDecMapIntUint8R(f *decFnInfo, rv reflect.Value) { - var ft fastpathDT[T] - containerLen := d.mapStart(d.d.ReadMapStart()) - if rv.Kind() == reflect.Ptr { - vp, _ := rv2i(rv).(*map[int]uint8) - if *vp == nil { - *vp = make(map[int]uint8, decInferLen(containerLen, d.maxInitLen(), 9)) - } - if containerLen != 0 { - ft.DecMapIntUint8L(*vp, containerLen, d) - } - } else if containerLen != 0 { - ft.DecMapIntUint8L(rv2i(rv).(map[int]uint8), containerLen, d) - } - d.mapEnd() -} -func (fastpathDT[T]) DecMapIntUint8L(v map[int]uint8, containerLen int, d *decoder[T]) { - if v == nil { - halt.errorInt("cannot decode into nil map[int]uint8 given stream length: ", int64(containerLen)) - } - hasLen := containerLen >= 0 - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - mk := int(chkOvf.IntV(d.d.DecodeInt64(), intBitsize)) - d.mapElemValue() - v[mk] = uint8(chkOvf.UintV(d.d.DecodeUint64(), 8)) - } -} -func (d *decoder[T]) fastpathDecMapIntUint64R(f *decFnInfo, rv reflect.Value) { - var ft fastpathDT[T] - containerLen := d.mapStart(d.d.ReadMapStart()) - if rv.Kind() == reflect.Ptr { - vp, _ := rv2i(rv).(*map[int]uint64) - if *vp == nil { - *vp = make(map[int]uint64, decInferLen(containerLen, d.maxInitLen(), 16)) - } - if containerLen != 0 { - ft.DecMapIntUint64L(*vp, containerLen, d) - } - } else if containerLen != 0 { - ft.DecMapIntUint64L(rv2i(rv).(map[int]uint64), containerLen, d) - } - d.mapEnd() -} -func (fastpathDT[T]) DecMapIntUint64L(v map[int]uint64, containerLen int, d *decoder[T]) { - if v == nil { - halt.errorInt("cannot decode into nil map[int]uint64 given stream length: ", int64(containerLen)) - } - hasLen := containerLen >= 0 - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - mk := int(chkOvf.IntV(d.d.DecodeInt64(), intBitsize)) - d.mapElemValue() - v[mk] = d.d.DecodeUint64() - } -} -func (d *decoder[T]) fastpathDecMapIntIntR(f *decFnInfo, rv reflect.Value) { - var ft fastpathDT[T] - containerLen := d.mapStart(d.d.ReadMapStart()) - if rv.Kind() == reflect.Ptr { - vp, _ := rv2i(rv).(*map[int]int) - if *vp == nil { - *vp = make(map[int]int, decInferLen(containerLen, d.maxInitLen(), 16)) - } - if containerLen != 0 { - ft.DecMapIntIntL(*vp, containerLen, d) - } - } else if containerLen != 0 { - ft.DecMapIntIntL(rv2i(rv).(map[int]int), containerLen, d) - } - d.mapEnd() -} -func (fastpathDT[T]) DecMapIntIntL(v map[int]int, containerLen int, d *decoder[T]) { - if v == nil { - halt.errorInt("cannot decode into nil map[int]int given stream length: ", int64(containerLen)) - } - hasLen := containerLen >= 0 - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - mk := int(chkOvf.IntV(d.d.DecodeInt64(), intBitsize)) - d.mapElemValue() - v[mk] = int(chkOvf.IntV(d.d.DecodeInt64(), intBitsize)) - } -} -func (d *decoder[T]) fastpathDecMapIntInt32R(f *decFnInfo, rv reflect.Value) { - var ft fastpathDT[T] - containerLen := d.mapStart(d.d.ReadMapStart()) - if rv.Kind() == reflect.Ptr { - vp, _ := rv2i(rv).(*map[int]int32) - if *vp == nil { - *vp = make(map[int]int32, decInferLen(containerLen, d.maxInitLen(), 12)) - } - if containerLen != 0 { - ft.DecMapIntInt32L(*vp, containerLen, d) - } - } else if containerLen != 0 { - ft.DecMapIntInt32L(rv2i(rv).(map[int]int32), containerLen, d) - } - d.mapEnd() -} -func (fastpathDT[T]) DecMapIntInt32L(v map[int]int32, containerLen int, d *decoder[T]) { - if v == nil { - halt.errorInt("cannot decode into nil map[int]int32 given stream length: ", int64(containerLen)) - } - hasLen := containerLen >= 0 - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - mk := int(chkOvf.IntV(d.d.DecodeInt64(), intBitsize)) - d.mapElemValue() - v[mk] = int32(chkOvf.IntV(d.d.DecodeInt64(), 32)) - } -} -func (d *decoder[T]) fastpathDecMapIntFloat64R(f *decFnInfo, rv reflect.Value) { - var ft fastpathDT[T] - containerLen := d.mapStart(d.d.ReadMapStart()) - if rv.Kind() == reflect.Ptr { - vp, _ := rv2i(rv).(*map[int]float64) - if *vp == nil { - *vp = make(map[int]float64, decInferLen(containerLen, d.maxInitLen(), 16)) - } - if containerLen != 0 { - ft.DecMapIntFloat64L(*vp, containerLen, d) - } - } else if containerLen != 0 { - ft.DecMapIntFloat64L(rv2i(rv).(map[int]float64), containerLen, d) - } - d.mapEnd() -} -func (fastpathDT[T]) DecMapIntFloat64L(v map[int]float64, containerLen int, d *decoder[T]) { - if v == nil { - halt.errorInt("cannot decode into nil map[int]float64 given stream length: ", int64(containerLen)) - } - hasLen := containerLen >= 0 - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - mk := int(chkOvf.IntV(d.d.DecodeInt64(), intBitsize)) - d.mapElemValue() - v[mk] = d.d.DecodeFloat64() - } -} -func (d *decoder[T]) fastpathDecMapIntBoolR(f *decFnInfo, rv reflect.Value) { - var ft fastpathDT[T] - containerLen := d.mapStart(d.d.ReadMapStart()) - if rv.Kind() == reflect.Ptr { - vp, _ := rv2i(rv).(*map[int]bool) - if *vp == nil { - *vp = make(map[int]bool, decInferLen(containerLen, d.maxInitLen(), 9)) - } - if containerLen != 0 { - ft.DecMapIntBoolL(*vp, containerLen, d) - } - } else if containerLen != 0 { - ft.DecMapIntBoolL(rv2i(rv).(map[int]bool), containerLen, d) - } - d.mapEnd() -} -func (fastpathDT[T]) DecMapIntBoolL(v map[int]bool, containerLen int, d *decoder[T]) { - if v == nil { - halt.errorInt("cannot decode into nil map[int]bool given stream length: ", int64(containerLen)) - } - hasLen := containerLen >= 0 - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - mk := int(chkOvf.IntV(d.d.DecodeInt64(), intBitsize)) - d.mapElemValue() - v[mk] = d.d.DecodeBool() - } -} -func (d *decoder[T]) fastpathDecMapInt32IntfR(f *decFnInfo, rv reflect.Value) { - var ft fastpathDT[T] - containerLen := d.mapStart(d.d.ReadMapStart()) - if rv.Kind() == reflect.Ptr { - vp, _ := rv2i(rv).(*map[int32]interface{}) - if *vp == nil { - *vp = make(map[int32]interface{}, decInferLen(containerLen, d.maxInitLen(), 20)) - } - if containerLen != 0 { - ft.DecMapInt32IntfL(*vp, containerLen, d) - } - } else if containerLen != 0 { - ft.DecMapInt32IntfL(rv2i(rv).(map[int32]interface{}), containerLen, d) - } - d.mapEnd() -} -func (fastpathDT[T]) DecMapInt32IntfL(v map[int32]interface{}, containerLen int, d *decoder[T]) { - if v == nil { - halt.errorInt("cannot decode into nil map[int32]interface{} given stream length: ", int64(containerLen)) - } - var mv interface{} - mapGet := !d.h.MapValueReset && !d.h.InterfaceReset - hasLen := containerLen >= 0 - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - mk := int32(chkOvf.IntV(d.d.DecodeInt64(), 32)) - d.mapElemValue() - if mapGet { - mv = v[mk] - } else { - mv = nil - } - d.decode(&mv) - v[mk] = mv - } -} -func (d *decoder[T]) fastpathDecMapInt32StringR(f *decFnInfo, rv reflect.Value) { - var ft fastpathDT[T] - containerLen := d.mapStart(d.d.ReadMapStart()) - if rv.Kind() == reflect.Ptr { - vp, _ := rv2i(rv).(*map[int32]string) - if *vp == nil { - *vp = make(map[int32]string, decInferLen(containerLen, d.maxInitLen(), 20)) - } - if containerLen != 0 { - ft.DecMapInt32StringL(*vp, containerLen, d) - } - } else if containerLen != 0 { - ft.DecMapInt32StringL(rv2i(rv).(map[int32]string), containerLen, d) - } - d.mapEnd() -} -func (fastpathDT[T]) DecMapInt32StringL(v map[int32]string, containerLen int, d *decoder[T]) { - if v == nil { - halt.errorInt("cannot decode into nil map[int32]string given stream length: ", int64(containerLen)) - } - hasLen := containerLen >= 0 - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - mk := int32(chkOvf.IntV(d.d.DecodeInt64(), 32)) - d.mapElemValue() - v[mk] = d.detach2Str(d.d.DecodeStringAsBytes()) - } -} -func (d *decoder[T]) fastpathDecMapInt32BytesR(f *decFnInfo, rv reflect.Value) { - var ft fastpathDT[T] - containerLen := d.mapStart(d.d.ReadMapStart()) - if rv.Kind() == reflect.Ptr { - vp, _ := rv2i(rv).(*map[int32][]byte) - if *vp == nil { - *vp = make(map[int32][]byte, decInferLen(containerLen, d.maxInitLen(), 28)) - } - if containerLen != 0 { - ft.DecMapInt32BytesL(*vp, containerLen, d) - } - } else if containerLen != 0 { - ft.DecMapInt32BytesL(rv2i(rv).(map[int32][]byte), containerLen, d) - } - d.mapEnd() -} -func (fastpathDT[T]) DecMapInt32BytesL(v map[int32][]byte, containerLen int, d *decoder[T]) { - if v == nil { - halt.errorInt("cannot decode into nil map[int32][]byte given stream length: ", int64(containerLen)) - } - var mv []byte - mapGet := !d.h.MapValueReset - hasLen := containerLen >= 0 - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - mk := int32(chkOvf.IntV(d.d.DecodeInt64(), 32)) - d.mapElemValue() - if mapGet { - mv = v[mk] - } else { - mv = nil - } - v[mk], _ = d.decodeBytesInto(mv, false) - } -} -func (d *decoder[T]) fastpathDecMapInt32Uint8R(f *decFnInfo, rv reflect.Value) { - var ft fastpathDT[T] - containerLen := d.mapStart(d.d.ReadMapStart()) - if rv.Kind() == reflect.Ptr { - vp, _ := rv2i(rv).(*map[int32]uint8) - if *vp == nil { - *vp = make(map[int32]uint8, decInferLen(containerLen, d.maxInitLen(), 5)) - } - if containerLen != 0 { - ft.DecMapInt32Uint8L(*vp, containerLen, d) - } - } else if containerLen != 0 { - ft.DecMapInt32Uint8L(rv2i(rv).(map[int32]uint8), containerLen, d) - } - d.mapEnd() -} -func (fastpathDT[T]) DecMapInt32Uint8L(v map[int32]uint8, containerLen int, d *decoder[T]) { - if v == nil { - halt.errorInt("cannot decode into nil map[int32]uint8 given stream length: ", int64(containerLen)) - } - hasLen := containerLen >= 0 - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - mk := int32(chkOvf.IntV(d.d.DecodeInt64(), 32)) - d.mapElemValue() - v[mk] = uint8(chkOvf.UintV(d.d.DecodeUint64(), 8)) - } -} -func (d *decoder[T]) fastpathDecMapInt32Uint64R(f *decFnInfo, rv reflect.Value) { - var ft fastpathDT[T] - containerLen := d.mapStart(d.d.ReadMapStart()) - if rv.Kind() == reflect.Ptr { - vp, _ := rv2i(rv).(*map[int32]uint64) - if *vp == nil { - *vp = make(map[int32]uint64, decInferLen(containerLen, d.maxInitLen(), 12)) - } - if containerLen != 0 { - ft.DecMapInt32Uint64L(*vp, containerLen, d) - } - } else if containerLen != 0 { - ft.DecMapInt32Uint64L(rv2i(rv).(map[int32]uint64), containerLen, d) - } - d.mapEnd() -} -func (fastpathDT[T]) DecMapInt32Uint64L(v map[int32]uint64, containerLen int, d *decoder[T]) { - if v == nil { - halt.errorInt("cannot decode into nil map[int32]uint64 given stream length: ", int64(containerLen)) - } - hasLen := containerLen >= 0 - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - mk := int32(chkOvf.IntV(d.d.DecodeInt64(), 32)) - d.mapElemValue() - v[mk] = d.d.DecodeUint64() - } -} -func (d *decoder[T]) fastpathDecMapInt32IntR(f *decFnInfo, rv reflect.Value) { - var ft fastpathDT[T] - containerLen := d.mapStart(d.d.ReadMapStart()) - if rv.Kind() == reflect.Ptr { - vp, _ := rv2i(rv).(*map[int32]int) - if *vp == nil { - *vp = make(map[int32]int, decInferLen(containerLen, d.maxInitLen(), 12)) - } - if containerLen != 0 { - ft.DecMapInt32IntL(*vp, containerLen, d) - } - } else if containerLen != 0 { - ft.DecMapInt32IntL(rv2i(rv).(map[int32]int), containerLen, d) - } - d.mapEnd() -} -func (fastpathDT[T]) DecMapInt32IntL(v map[int32]int, containerLen int, d *decoder[T]) { - if v == nil { - halt.errorInt("cannot decode into nil map[int32]int given stream length: ", int64(containerLen)) - } - hasLen := containerLen >= 0 - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - mk := int32(chkOvf.IntV(d.d.DecodeInt64(), 32)) - d.mapElemValue() - v[mk] = int(chkOvf.IntV(d.d.DecodeInt64(), intBitsize)) - } -} -func (d *decoder[T]) fastpathDecMapInt32Int32R(f *decFnInfo, rv reflect.Value) { - var ft fastpathDT[T] - containerLen := d.mapStart(d.d.ReadMapStart()) - if rv.Kind() == reflect.Ptr { - vp, _ := rv2i(rv).(*map[int32]int32) - if *vp == nil { - *vp = make(map[int32]int32, decInferLen(containerLen, d.maxInitLen(), 8)) - } - if containerLen != 0 { - ft.DecMapInt32Int32L(*vp, containerLen, d) - } - } else if containerLen != 0 { - ft.DecMapInt32Int32L(rv2i(rv).(map[int32]int32), containerLen, d) - } - d.mapEnd() -} -func (fastpathDT[T]) DecMapInt32Int32L(v map[int32]int32, containerLen int, d *decoder[T]) { - if v == nil { - halt.errorInt("cannot decode into nil map[int32]int32 given stream length: ", int64(containerLen)) - } - hasLen := containerLen >= 0 - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - mk := int32(chkOvf.IntV(d.d.DecodeInt64(), 32)) - d.mapElemValue() - v[mk] = int32(chkOvf.IntV(d.d.DecodeInt64(), 32)) - } -} -func (d *decoder[T]) fastpathDecMapInt32Float64R(f *decFnInfo, rv reflect.Value) { - var ft fastpathDT[T] - containerLen := d.mapStart(d.d.ReadMapStart()) - if rv.Kind() == reflect.Ptr { - vp, _ := rv2i(rv).(*map[int32]float64) - if *vp == nil { - *vp = make(map[int32]float64, decInferLen(containerLen, d.maxInitLen(), 12)) - } - if containerLen != 0 { - ft.DecMapInt32Float64L(*vp, containerLen, d) - } - } else if containerLen != 0 { - ft.DecMapInt32Float64L(rv2i(rv).(map[int32]float64), containerLen, d) - } - d.mapEnd() -} -func (fastpathDT[T]) DecMapInt32Float64L(v map[int32]float64, containerLen int, d *decoder[T]) { - if v == nil { - halt.errorInt("cannot decode into nil map[int32]float64 given stream length: ", int64(containerLen)) - } - hasLen := containerLen >= 0 - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - mk := int32(chkOvf.IntV(d.d.DecodeInt64(), 32)) - d.mapElemValue() - v[mk] = d.d.DecodeFloat64() - } -} -func (d *decoder[T]) fastpathDecMapInt32BoolR(f *decFnInfo, rv reflect.Value) { - var ft fastpathDT[T] - containerLen := d.mapStart(d.d.ReadMapStart()) - if rv.Kind() == reflect.Ptr { - vp, _ := rv2i(rv).(*map[int32]bool) - if *vp == nil { - *vp = make(map[int32]bool, decInferLen(containerLen, d.maxInitLen(), 5)) - } - if containerLen != 0 { - ft.DecMapInt32BoolL(*vp, containerLen, d) - } - } else if containerLen != 0 { - ft.DecMapInt32BoolL(rv2i(rv).(map[int32]bool), containerLen, d) - } - d.mapEnd() -} -func (fastpathDT[T]) DecMapInt32BoolL(v map[int32]bool, containerLen int, d *decoder[T]) { - if v == nil { - halt.errorInt("cannot decode into nil map[int32]bool given stream length: ", int64(containerLen)) - } - hasLen := containerLen >= 0 - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - mk := int32(chkOvf.IntV(d.d.DecodeInt64(), 32)) - d.mapElemValue() - v[mk] = d.d.DecodeBool() - } -} diff --git a/vendor/github.com/ugorji/go/codec/base.notfastpath.go b/vendor/github.com/ugorji/go/codec/base.notfastpath.go deleted file mode 100644 index b4c41fb9f..000000000 --- a/vendor/github.com/ugorji/go/codec/base.notfastpath.go +++ /dev/null @@ -1,34 +0,0 @@ -// Copyright (c) 2012-2020 Ugorji Nwoke. All rights reserved. -// Use of this source code is governed by a MIT license found in the LICENSE file. - -//go:build notfastpath || codec.notfastpath - -package codec - -import "reflect" - -const fastpathEnabled = false - -// The generated fast-path code is very large, and adds a few seconds to the build time. -// This causes test execution, execution of small tools which use codec, etc -// to take a long time. -// -// To mitigate, we now support the notfastpath tag. -// This tag disables fastpath during build, allowing for faster build, test execution, -// short-program runs, etc. - -// func fastpathEncodeTypeSwitchSlice(iv interface{}, e *Encoder) bool { return false } -// func fastpathEncodeTypeSwitchMap(iv interface{}, e *Encoder) bool { return false } - -func fastpathDecodeSetZeroTypeSwitch(iv interface{}) bool { return false } - -func fastpathAvIndex(rtid uintptr) (uint, bool) { return 0, false } - -type fastpathRtRtid struct { - rtid uintptr - rt reflect.Type -} - -type fastpathARtRtid [0]fastpathRtRtid - -var fastpathAvRtRtid fastpathARtRtid diff --git a/vendor/github.com/ugorji/go/codec/base.notfastpath.notmono.go b/vendor/github.com/ugorji/go/codec/base.notfastpath.notmono.go deleted file mode 100644 index a692849b5..000000000 --- a/vendor/github.com/ugorji/go/codec/base.notfastpath.notmono.go +++ /dev/null @@ -1,26 +0,0 @@ -//go:build notfastpath || (codec.notfastpath && (notmono || codec.notmono)) - -// Copyright (c) 2012-2020 Ugorji Nwoke. All rights reserved. -// Use of this source code is governed by a MIT license found in the LICENSE file. - -package codec - -import "reflect" - -// type fastpathT struct{} -type fastpathE[T encDriver] struct { - rt reflect.Type - encfn func(*encoder[T], *encFnInfo, reflect.Value) -} -type fastpathD[T decDriver] struct { - rt reflect.Type - decfn func(*decoder[T], *decFnInfo, reflect.Value) -} -type fastpathEs[T encDriver] [0]fastpathE[T] -type fastpathDs[T decDriver] [0]fastpathD[T] - -func (helperEncDriver[T]) fastpathEncodeTypeSwitch(iv interface{}, e *encoder[T]) bool { return false } -func (helperDecDriver[T]) fastpathDecodeTypeSwitch(iv interface{}, d *decoder[T]) bool { return false } - -func (helperEncDriver[T]) fastpathEList() (v *fastpathEs[T]) { return } -func (helperDecDriver[T]) fastpathDList() (v *fastpathDs[T]) { return } diff --git a/vendor/github.com/ugorji/go/codec/binc.base.go b/vendor/github.com/ugorji/go/codec/binc.base.go deleted file mode 100644 index 29da5acdb..000000000 --- a/vendor/github.com/ugorji/go/codec/binc.base.go +++ /dev/null @@ -1,194 +0,0 @@ -// Copyright (c) 2012-2020 Ugorji Nwoke. All rights reserved. -// Use of this source code is governed by a MIT license found in the LICENSE file. - -package codec - -import ( - "reflect" - "time" -) - -// Symbol management: -// - symbols are stored in a symbol map during encoding and decoding. -// - the symbols persist until the (En|De)coder ResetXXX method is called. - -const bincDoPrune = true - -// vd as low 4 bits (there are 16 slots) -const ( - bincVdSpecial byte = iota - bincVdPosInt - bincVdNegInt - bincVdFloat - - bincVdString - bincVdByteArray - bincVdArray - bincVdMap - - bincVdTimestamp - bincVdSmallInt - _ // bincVdUnicodeOther - bincVdSymbol - - _ // bincVdDecimal - _ // open slot - _ // open slot - bincVdCustomExt = 0x0f -) - -const ( - bincSpNil byte = iota - bincSpFalse - bincSpTrue - bincSpNan - bincSpPosInf - bincSpNegInf - bincSpZeroFloat - bincSpZero - bincSpNegOne -) - -const ( - _ byte = iota // bincFlBin16 - bincFlBin32 - _ // bincFlBin32e - bincFlBin64 - _ // bincFlBin64e - // others not currently supported -) - -const bincBdNil = 0 // bincVdSpecial<<4 | bincSpNil // staticcheck barfs on this (SA4016) - -var ( - bincdescSpecialVsNames = map[byte]string{ - bincSpNil: "nil", - bincSpFalse: "false", - bincSpTrue: "true", - bincSpNan: "float", - bincSpPosInf: "float", - bincSpNegInf: "float", - bincSpZeroFloat: "float", - bincSpZero: "uint", - bincSpNegOne: "int", - } - bincdescVdNames = map[byte]string{ - bincVdSpecial: "special", - bincVdSmallInt: "uint", - bincVdPosInt: "uint", - bincVdFloat: "float", - bincVdSymbol: "string", - bincVdString: "string", - bincVdByteArray: "bytes", - bincVdTimestamp: "time", - bincVdCustomExt: "ext", - bincVdArray: "array", - bincVdMap: "map", - } -) - -func bincdescbd(bd byte) (s string) { - return bincdesc(bd>>4, bd&0x0f) -} - -func bincdesc(vd, vs byte) (s string) { - if vd == bincVdSpecial { - s = bincdescSpecialVsNames[vs] - } else { - s = bincdescVdNames[vd] - } - if s == "" { - s = "unknown" - } - return -} - -type bincEncState struct { - m map[string]uint16 // symbols -} - -// func (e *bincEncState) restoreState(v interface{}) { e.m = v.(map[string]uint16) } -// func (e bincEncState) captureState() interface{} { return e.m } -// func (e *bincEncState) resetState() { e.m = nil } -// func (e *bincEncState) reset() { e.resetState() } -func (e *bincEncState) reset() { e.m = nil } - -type bincDecState struct { - bdRead bool - bd byte - vd byte - vs byte - - _ bool - // MARKER: consider using binary search here instead of a map (ie bincDecSymbol) - s map[uint16][]byte -} - -// func (x bincDecState) captureState() interface{} { return x } -// func (x *bincDecState) resetState() { *x = bincDecState{} } -// func (x *bincDecState) reset() { x.resetState() } -// func (x *bincDecState) restoreState(v interface{}) { *x = v.(bincDecState) } -func (x *bincDecState) reset() { *x = bincDecState{} } - -//------------------------------------ - -// BincHandle is a Handle for the Binc Schema-Free Encoding Format -// defined at https://github.com/ugorji/binc . -// -// BincHandle currently supports all Binc features with the following EXCEPTIONS: -// - only integers up to 64 bits of precision are supported. -// big integers are unsupported. -// - Only IEEE 754 binary32 and binary64 floats are supported (ie Go float32 and float64 types). -// extended precision and decimal IEEE 754 floats are unsupported. -// - Only UTF-8 strings supported. -// Unicode_Other Binc types (UTF16, UTF32) are currently unsupported. -// -// Note that these EXCEPTIONS are temporary and full support is possible and may happen soon. -type BincHandle struct { - binaryEncodingType - notJsonType - // noElemSeparators - BasicHandle - - // AsSymbols defines what should be encoded as symbols. - // - // Encoding as symbols can reduce the encoded size significantly. - // - // However, during decoding, each string to be encoded as a symbol must - // be checked to see if it has been seen before. Consequently, encoding time - // will increase if using symbols, because string comparisons has a clear cost. - // - // Values: - // - 0: default: library uses best judgement - // - 1: use symbols - // - 2: do not use symbols - AsSymbols uint8 - - // AsSymbols: may later on introduce more options ... - // - m: map keys - // - s: struct fields - // - n: none - // - a: all: same as m, s, ... - - // _ [7]uint64 // padding (cache-aligned) -} - -// Name returns the name of the handle: binc -func (h *BincHandle) Name() string { return "binc" } - -func (h *BincHandle) desc(bd byte) string { return bincdesc(bd>>4, bd&0x0f) } - -// SetBytesExt sets an extension -func (h *BincHandle) SetBytesExt(rt reflect.Type, tag uint64, ext BytesExt) (err error) { - return h.SetExt(rt, tag, makeExt(ext)) -} - -// var timeDigits = [...]byte{'0', '1', '2', '3', '4', '5', '6', '7', '8', '9'} - -func bincEncodeTime(t time.Time) []byte { - return customEncodeTime(t) -} - -func bincDecodeTime(bs []byte) (tt time.Time, err error) { - return customDecodeTime(bs) -} diff --git a/vendor/github.com/ugorji/go/codec/binc.fastpath.mono.generated.go b/vendor/github.com/ugorji/go/codec/binc.fastpath.mono.generated.go deleted file mode 100644 index 7721027e1..000000000 --- a/vendor/github.com/ugorji/go/codec/binc.fastpath.mono.generated.go +++ /dev/null @@ -1,12482 +0,0 @@ -//go:build !notmono && !codec.notmono && !notfastpath && !codec.notfastpath - -// Copyright (c) 2012-2020 Ugorji Nwoke. All rights reserved. -// Use of this source code is governed by a MIT license found in the LICENSE file. - -package codec - -import ( - "reflect" - "slices" - "sort" -) - -type fastpathEBincBytes struct { - rtid uintptr - rt reflect.Type - encfn func(*encoderBincBytes, *encFnInfo, reflect.Value) -} -type fastpathDBincBytes struct { - rtid uintptr - rt reflect.Type - decfn func(*decoderBincBytes, *decFnInfo, reflect.Value) -} -type fastpathEsBincBytes [56]fastpathEBincBytes -type fastpathDsBincBytes [56]fastpathDBincBytes -type fastpathETBincBytes struct{} -type fastpathDTBincBytes struct{} - -func (helperEncDriverBincBytes) fastpathEList() *fastpathEsBincBytes { - var i uint = 0 - var s fastpathEsBincBytes - fn := func(v interface{}, fe func(*encoderBincBytes, *encFnInfo, reflect.Value)) { - xrt := reflect.TypeOf(v) - s[i] = fastpathEBincBytes{rt2id(xrt), xrt, fe} - i++ - } - - fn([]interface{}(nil), (*encoderBincBytes).fastpathEncSliceIntfR) - fn([]string(nil), (*encoderBincBytes).fastpathEncSliceStringR) - fn([][]byte(nil), (*encoderBincBytes).fastpathEncSliceBytesR) - fn([]float32(nil), (*encoderBincBytes).fastpathEncSliceFloat32R) - fn([]float64(nil), (*encoderBincBytes).fastpathEncSliceFloat64R) - fn([]uint8(nil), (*encoderBincBytes).fastpathEncSliceUint8R) - fn([]uint64(nil), (*encoderBincBytes).fastpathEncSliceUint64R) - fn([]int(nil), (*encoderBincBytes).fastpathEncSliceIntR) - fn([]int32(nil), (*encoderBincBytes).fastpathEncSliceInt32R) - fn([]int64(nil), (*encoderBincBytes).fastpathEncSliceInt64R) - fn([]bool(nil), (*encoderBincBytes).fastpathEncSliceBoolR) - - fn(map[string]interface{}(nil), (*encoderBincBytes).fastpathEncMapStringIntfR) - fn(map[string]string(nil), (*encoderBincBytes).fastpathEncMapStringStringR) - fn(map[string][]byte(nil), (*encoderBincBytes).fastpathEncMapStringBytesR) - fn(map[string]uint8(nil), (*encoderBincBytes).fastpathEncMapStringUint8R) - fn(map[string]uint64(nil), (*encoderBincBytes).fastpathEncMapStringUint64R) - fn(map[string]int(nil), (*encoderBincBytes).fastpathEncMapStringIntR) - fn(map[string]int32(nil), (*encoderBincBytes).fastpathEncMapStringInt32R) - fn(map[string]float64(nil), (*encoderBincBytes).fastpathEncMapStringFloat64R) - fn(map[string]bool(nil), (*encoderBincBytes).fastpathEncMapStringBoolR) - fn(map[uint8]interface{}(nil), (*encoderBincBytes).fastpathEncMapUint8IntfR) - fn(map[uint8]string(nil), (*encoderBincBytes).fastpathEncMapUint8StringR) - fn(map[uint8][]byte(nil), (*encoderBincBytes).fastpathEncMapUint8BytesR) - fn(map[uint8]uint8(nil), (*encoderBincBytes).fastpathEncMapUint8Uint8R) - fn(map[uint8]uint64(nil), (*encoderBincBytes).fastpathEncMapUint8Uint64R) - fn(map[uint8]int(nil), (*encoderBincBytes).fastpathEncMapUint8IntR) - fn(map[uint8]int32(nil), (*encoderBincBytes).fastpathEncMapUint8Int32R) - fn(map[uint8]float64(nil), (*encoderBincBytes).fastpathEncMapUint8Float64R) - fn(map[uint8]bool(nil), (*encoderBincBytes).fastpathEncMapUint8BoolR) - fn(map[uint64]interface{}(nil), (*encoderBincBytes).fastpathEncMapUint64IntfR) - fn(map[uint64]string(nil), (*encoderBincBytes).fastpathEncMapUint64StringR) - fn(map[uint64][]byte(nil), (*encoderBincBytes).fastpathEncMapUint64BytesR) - fn(map[uint64]uint8(nil), (*encoderBincBytes).fastpathEncMapUint64Uint8R) - fn(map[uint64]uint64(nil), (*encoderBincBytes).fastpathEncMapUint64Uint64R) - fn(map[uint64]int(nil), (*encoderBincBytes).fastpathEncMapUint64IntR) - fn(map[uint64]int32(nil), (*encoderBincBytes).fastpathEncMapUint64Int32R) - fn(map[uint64]float64(nil), (*encoderBincBytes).fastpathEncMapUint64Float64R) - fn(map[uint64]bool(nil), (*encoderBincBytes).fastpathEncMapUint64BoolR) - fn(map[int]interface{}(nil), (*encoderBincBytes).fastpathEncMapIntIntfR) - fn(map[int]string(nil), (*encoderBincBytes).fastpathEncMapIntStringR) - fn(map[int][]byte(nil), (*encoderBincBytes).fastpathEncMapIntBytesR) - fn(map[int]uint8(nil), (*encoderBincBytes).fastpathEncMapIntUint8R) - fn(map[int]uint64(nil), (*encoderBincBytes).fastpathEncMapIntUint64R) - fn(map[int]int(nil), (*encoderBincBytes).fastpathEncMapIntIntR) - fn(map[int]int32(nil), (*encoderBincBytes).fastpathEncMapIntInt32R) - fn(map[int]float64(nil), (*encoderBincBytes).fastpathEncMapIntFloat64R) - fn(map[int]bool(nil), (*encoderBincBytes).fastpathEncMapIntBoolR) - fn(map[int32]interface{}(nil), (*encoderBincBytes).fastpathEncMapInt32IntfR) - fn(map[int32]string(nil), (*encoderBincBytes).fastpathEncMapInt32StringR) - fn(map[int32][]byte(nil), (*encoderBincBytes).fastpathEncMapInt32BytesR) - fn(map[int32]uint8(nil), (*encoderBincBytes).fastpathEncMapInt32Uint8R) - fn(map[int32]uint64(nil), (*encoderBincBytes).fastpathEncMapInt32Uint64R) - fn(map[int32]int(nil), (*encoderBincBytes).fastpathEncMapInt32IntR) - fn(map[int32]int32(nil), (*encoderBincBytes).fastpathEncMapInt32Int32R) - fn(map[int32]float64(nil), (*encoderBincBytes).fastpathEncMapInt32Float64R) - fn(map[int32]bool(nil), (*encoderBincBytes).fastpathEncMapInt32BoolR) - - sort.Slice(s[:], func(i, j int) bool { return s[i].rtid < s[j].rtid }) - return &s -} - -func (helperDecDriverBincBytes) fastpathDList() *fastpathDsBincBytes { - var i uint = 0 - var s fastpathDsBincBytes - fn := func(v interface{}, fd func(*decoderBincBytes, *decFnInfo, reflect.Value)) { - xrt := reflect.TypeOf(v) - s[i] = fastpathDBincBytes{rt2id(xrt), xrt, fd} - i++ - } - - fn([]interface{}(nil), (*decoderBincBytes).fastpathDecSliceIntfR) - fn([]string(nil), (*decoderBincBytes).fastpathDecSliceStringR) - fn([][]byte(nil), (*decoderBincBytes).fastpathDecSliceBytesR) - fn([]float32(nil), (*decoderBincBytes).fastpathDecSliceFloat32R) - fn([]float64(nil), (*decoderBincBytes).fastpathDecSliceFloat64R) - fn([]uint8(nil), (*decoderBincBytes).fastpathDecSliceUint8R) - fn([]uint64(nil), (*decoderBincBytes).fastpathDecSliceUint64R) - fn([]int(nil), (*decoderBincBytes).fastpathDecSliceIntR) - fn([]int32(nil), (*decoderBincBytes).fastpathDecSliceInt32R) - fn([]int64(nil), (*decoderBincBytes).fastpathDecSliceInt64R) - fn([]bool(nil), (*decoderBincBytes).fastpathDecSliceBoolR) - - fn(map[string]interface{}(nil), (*decoderBincBytes).fastpathDecMapStringIntfR) - fn(map[string]string(nil), (*decoderBincBytes).fastpathDecMapStringStringR) - fn(map[string][]byte(nil), (*decoderBincBytes).fastpathDecMapStringBytesR) - fn(map[string]uint8(nil), (*decoderBincBytes).fastpathDecMapStringUint8R) - fn(map[string]uint64(nil), (*decoderBincBytes).fastpathDecMapStringUint64R) - fn(map[string]int(nil), (*decoderBincBytes).fastpathDecMapStringIntR) - fn(map[string]int32(nil), (*decoderBincBytes).fastpathDecMapStringInt32R) - fn(map[string]float64(nil), (*decoderBincBytes).fastpathDecMapStringFloat64R) - fn(map[string]bool(nil), (*decoderBincBytes).fastpathDecMapStringBoolR) - fn(map[uint8]interface{}(nil), (*decoderBincBytes).fastpathDecMapUint8IntfR) - fn(map[uint8]string(nil), (*decoderBincBytes).fastpathDecMapUint8StringR) - fn(map[uint8][]byte(nil), (*decoderBincBytes).fastpathDecMapUint8BytesR) - fn(map[uint8]uint8(nil), (*decoderBincBytes).fastpathDecMapUint8Uint8R) - fn(map[uint8]uint64(nil), (*decoderBincBytes).fastpathDecMapUint8Uint64R) - fn(map[uint8]int(nil), (*decoderBincBytes).fastpathDecMapUint8IntR) - fn(map[uint8]int32(nil), (*decoderBincBytes).fastpathDecMapUint8Int32R) - fn(map[uint8]float64(nil), (*decoderBincBytes).fastpathDecMapUint8Float64R) - fn(map[uint8]bool(nil), (*decoderBincBytes).fastpathDecMapUint8BoolR) - fn(map[uint64]interface{}(nil), (*decoderBincBytes).fastpathDecMapUint64IntfR) - fn(map[uint64]string(nil), (*decoderBincBytes).fastpathDecMapUint64StringR) - fn(map[uint64][]byte(nil), (*decoderBincBytes).fastpathDecMapUint64BytesR) - fn(map[uint64]uint8(nil), (*decoderBincBytes).fastpathDecMapUint64Uint8R) - fn(map[uint64]uint64(nil), (*decoderBincBytes).fastpathDecMapUint64Uint64R) - fn(map[uint64]int(nil), (*decoderBincBytes).fastpathDecMapUint64IntR) - fn(map[uint64]int32(nil), (*decoderBincBytes).fastpathDecMapUint64Int32R) - fn(map[uint64]float64(nil), (*decoderBincBytes).fastpathDecMapUint64Float64R) - fn(map[uint64]bool(nil), (*decoderBincBytes).fastpathDecMapUint64BoolR) - fn(map[int]interface{}(nil), (*decoderBincBytes).fastpathDecMapIntIntfR) - fn(map[int]string(nil), (*decoderBincBytes).fastpathDecMapIntStringR) - fn(map[int][]byte(nil), (*decoderBincBytes).fastpathDecMapIntBytesR) - fn(map[int]uint8(nil), (*decoderBincBytes).fastpathDecMapIntUint8R) - fn(map[int]uint64(nil), (*decoderBincBytes).fastpathDecMapIntUint64R) - fn(map[int]int(nil), (*decoderBincBytes).fastpathDecMapIntIntR) - fn(map[int]int32(nil), (*decoderBincBytes).fastpathDecMapIntInt32R) - fn(map[int]float64(nil), (*decoderBincBytes).fastpathDecMapIntFloat64R) - fn(map[int]bool(nil), (*decoderBincBytes).fastpathDecMapIntBoolR) - fn(map[int32]interface{}(nil), (*decoderBincBytes).fastpathDecMapInt32IntfR) - fn(map[int32]string(nil), (*decoderBincBytes).fastpathDecMapInt32StringR) - fn(map[int32][]byte(nil), (*decoderBincBytes).fastpathDecMapInt32BytesR) - fn(map[int32]uint8(nil), (*decoderBincBytes).fastpathDecMapInt32Uint8R) - fn(map[int32]uint64(nil), (*decoderBincBytes).fastpathDecMapInt32Uint64R) - fn(map[int32]int(nil), (*decoderBincBytes).fastpathDecMapInt32IntR) - fn(map[int32]int32(nil), (*decoderBincBytes).fastpathDecMapInt32Int32R) - fn(map[int32]float64(nil), (*decoderBincBytes).fastpathDecMapInt32Float64R) - fn(map[int32]bool(nil), (*decoderBincBytes).fastpathDecMapInt32BoolR) - - sort.Slice(s[:], func(i, j int) bool { return s[i].rtid < s[j].rtid }) - return &s -} - -func (helperEncDriverBincBytes) fastpathEncodeTypeSwitch(iv interface{}, e *encoderBincBytes) bool { - var ft fastpathETBincBytes - switch v := iv.(type) { - case []interface{}: - if v == nil { - e.e.writeNilArray() - } else { - ft.EncSliceIntfV(v, e) - } - case []string: - if v == nil { - e.e.writeNilArray() - } else { - ft.EncSliceStringV(v, e) - } - case [][]byte: - if v == nil { - e.e.writeNilArray() - } else { - ft.EncSliceBytesV(v, e) - } - case []float32: - if v == nil { - e.e.writeNilArray() - } else { - ft.EncSliceFloat32V(v, e) - } - case []float64: - if v == nil { - e.e.writeNilArray() - } else { - ft.EncSliceFloat64V(v, e) - } - case []uint8: - if v == nil { - e.e.writeNilArray() - } else { - ft.EncSliceUint8V(v, e) - } - case []uint64: - if v == nil { - e.e.writeNilArray() - } else { - ft.EncSliceUint64V(v, e) - } - case []int: - if v == nil { - e.e.writeNilArray() - } else { - ft.EncSliceIntV(v, e) - } - case []int32: - if v == nil { - e.e.writeNilArray() - } else { - ft.EncSliceInt32V(v, e) - } - case []int64: - if v == nil { - e.e.writeNilArray() - } else { - ft.EncSliceInt64V(v, e) - } - case []bool: - if v == nil { - e.e.writeNilArray() - } else { - ft.EncSliceBoolV(v, e) - } - case map[string]interface{}: - if v == nil { - e.e.writeNilMap() - } else { - ft.EncMapStringIntfV(v, e) - } - case map[string]string: - if v == nil { - e.e.writeNilMap() - } else { - ft.EncMapStringStringV(v, e) - } - case map[string][]byte: - if v == nil { - e.e.writeNilMap() - } else { - ft.EncMapStringBytesV(v, e) - } - case map[string]uint8: - if v == nil { - e.e.writeNilMap() - } else { - ft.EncMapStringUint8V(v, e) - } - case map[string]uint64: - if v == nil { - e.e.writeNilMap() - } else { - ft.EncMapStringUint64V(v, e) - } - case map[string]int: - if v == nil { - e.e.writeNilMap() - } else { - ft.EncMapStringIntV(v, e) - } - case map[string]int32: - if v == nil { - e.e.writeNilMap() - } else { - ft.EncMapStringInt32V(v, e) - } - case map[string]float64: - if v == nil { - e.e.writeNilMap() - } else { - ft.EncMapStringFloat64V(v, e) - } - case map[string]bool: - if v == nil { - e.e.writeNilMap() - } else { - ft.EncMapStringBoolV(v, e) - } - case map[uint8]interface{}: - if v == nil { - e.e.writeNilMap() - } else { - ft.EncMapUint8IntfV(v, e) - } - case map[uint8]string: - if v == nil { - e.e.writeNilMap() - } else { - ft.EncMapUint8StringV(v, e) - } - case map[uint8][]byte: - if v == nil { - e.e.writeNilMap() - } else { - ft.EncMapUint8BytesV(v, e) - } - case map[uint8]uint8: - if v == nil { - e.e.writeNilMap() - } else { - ft.EncMapUint8Uint8V(v, e) - } - case map[uint8]uint64: - if v == nil { - e.e.writeNilMap() - } else { - ft.EncMapUint8Uint64V(v, e) - } - case map[uint8]int: - if v == nil { - e.e.writeNilMap() - } else { - ft.EncMapUint8IntV(v, e) - } - case map[uint8]int32: - if v == nil { - e.e.writeNilMap() - } else { - ft.EncMapUint8Int32V(v, e) - } - case map[uint8]float64: - if v == nil { - e.e.writeNilMap() - } else { - ft.EncMapUint8Float64V(v, e) - } - case map[uint8]bool: - if v == nil { - e.e.writeNilMap() - } else { - ft.EncMapUint8BoolV(v, e) - } - case map[uint64]interface{}: - if v == nil { - e.e.writeNilMap() - } else { - ft.EncMapUint64IntfV(v, e) - } - case map[uint64]string: - if v == nil { - e.e.writeNilMap() - } else { - ft.EncMapUint64StringV(v, e) - } - case map[uint64][]byte: - if v == nil { - e.e.writeNilMap() - } else { - ft.EncMapUint64BytesV(v, e) - } - case map[uint64]uint8: - if v == nil { - e.e.writeNilMap() - } else { - ft.EncMapUint64Uint8V(v, e) - } - case map[uint64]uint64: - if v == nil { - e.e.writeNilMap() - } else { - ft.EncMapUint64Uint64V(v, e) - } - case map[uint64]int: - if v == nil { - e.e.writeNilMap() - } else { - ft.EncMapUint64IntV(v, e) - } - case map[uint64]int32: - if v == nil { - e.e.writeNilMap() - } else { - ft.EncMapUint64Int32V(v, e) - } - case map[uint64]float64: - if v == nil { - e.e.writeNilMap() - } else { - ft.EncMapUint64Float64V(v, e) - } - case map[uint64]bool: - if v == nil { - e.e.writeNilMap() - } else { - ft.EncMapUint64BoolV(v, e) - } - case map[int]interface{}: - if v == nil { - e.e.writeNilMap() - } else { - ft.EncMapIntIntfV(v, e) - } - case map[int]string: - if v == nil { - e.e.writeNilMap() - } else { - ft.EncMapIntStringV(v, e) - } - case map[int][]byte: - if v == nil { - e.e.writeNilMap() - } else { - ft.EncMapIntBytesV(v, e) - } - case map[int]uint8: - if v == nil { - e.e.writeNilMap() - } else { - ft.EncMapIntUint8V(v, e) - } - case map[int]uint64: - if v == nil { - e.e.writeNilMap() - } else { - ft.EncMapIntUint64V(v, e) - } - case map[int]int: - if v == nil { - e.e.writeNilMap() - } else { - ft.EncMapIntIntV(v, e) - } - case map[int]int32: - if v == nil { - e.e.writeNilMap() - } else { - ft.EncMapIntInt32V(v, e) - } - case map[int]float64: - if v == nil { - e.e.writeNilMap() - } else { - ft.EncMapIntFloat64V(v, e) - } - case map[int]bool: - if v == nil { - e.e.writeNilMap() - } else { - ft.EncMapIntBoolV(v, e) - } - case map[int32]interface{}: - if v == nil { - e.e.writeNilMap() - } else { - ft.EncMapInt32IntfV(v, e) - } - case map[int32]string: - if v == nil { - e.e.writeNilMap() - } else { - ft.EncMapInt32StringV(v, e) - } - case map[int32][]byte: - if v == nil { - e.e.writeNilMap() - } else { - ft.EncMapInt32BytesV(v, e) - } - case map[int32]uint8: - if v == nil { - e.e.writeNilMap() - } else { - ft.EncMapInt32Uint8V(v, e) - } - case map[int32]uint64: - if v == nil { - e.e.writeNilMap() - } else { - ft.EncMapInt32Uint64V(v, e) - } - case map[int32]int: - if v == nil { - e.e.writeNilMap() - } else { - ft.EncMapInt32IntV(v, e) - } - case map[int32]int32: - if v == nil { - e.e.writeNilMap() - } else { - ft.EncMapInt32Int32V(v, e) - } - case map[int32]float64: - if v == nil { - e.e.writeNilMap() - } else { - ft.EncMapInt32Float64V(v, e) - } - case map[int32]bool: - if v == nil { - e.e.writeNilMap() - } else { - ft.EncMapInt32BoolV(v, e) - } - default: - _ = v - return false - } - return true -} - -func (e *encoderBincBytes) fastpathEncSliceIntfR(f *encFnInfo, rv reflect.Value) { - var ft fastpathETBincBytes - var v []interface{} - if rv.Kind() == reflect.Array { - rvGetSlice4Array(rv, &v) - } else { - v = rv2i(rv).([]interface{}) - } - if f.ti.mbs { - ft.EncAsMapSliceIntfV(v, e) - return - } - ft.EncSliceIntfV(v, e) -} -func (fastpathETBincBytes) EncSliceIntfV(v []interface{}, e *encoderBincBytes) { - if len(v) == 0 { - e.c = 0 - e.e.WriteArrayEmpty() - return - } - e.arrayStart(len(v)) - for j := range v { - e.c = containerArrayElem - e.e.WriteArrayElem(j == 0) - if !e.encodeBuiltin(v[j]) { - e.encodeR(reflect.ValueOf(v[j])) - } - } - e.c = 0 - e.e.WriteArrayEnd() -} -func (fastpathETBincBytes) EncAsMapSliceIntfV(v []interface{}, e *encoderBincBytes) { - if len(v) == 0 { - e.c = 0 - e.e.WriteMapEmpty() - return - } - e.haltOnMbsOddLen(len(v)) - e.mapStart(len(v) >> 1) - for j := range v { - if j&1 == 0 { - e.c = containerMapKey - e.e.WriteMapElemKey(j == 0) - } else { - e.mapElemValue() - } - if !e.encodeBuiltin(v[j]) { - e.encodeR(reflect.ValueOf(v[j])) - } - } - e.c = 0 - e.e.WriteMapEnd() -} - -func (e *encoderBincBytes) fastpathEncSliceStringR(f *encFnInfo, rv reflect.Value) { - var ft fastpathETBincBytes - var v []string - if rv.Kind() == reflect.Array { - rvGetSlice4Array(rv, &v) - } else { - v = rv2i(rv).([]string) - } - if f.ti.mbs { - ft.EncAsMapSliceStringV(v, e) - return - } - ft.EncSliceStringV(v, e) -} -func (fastpathETBincBytes) EncSliceStringV(v []string, e *encoderBincBytes) { - if len(v) == 0 { - e.c = 0 - e.e.WriteArrayEmpty() - return - } - e.arrayStart(len(v)) - for j := range v { - e.c = containerArrayElem - e.e.WriteArrayElem(j == 0) - e.e.EncodeString(v[j]) - } - e.c = 0 - e.e.WriteArrayEnd() -} -func (fastpathETBincBytes) EncAsMapSliceStringV(v []string, e *encoderBincBytes) { - if len(v) == 0 { - e.c = 0 - e.e.WriteMapEmpty() - return - } - e.haltOnMbsOddLen(len(v)) - e.mapStart(len(v) >> 1) - for j := range v { - if j&1 == 0 { - e.c = containerMapKey - e.e.WriteMapElemKey(j == 0) - } else { - e.mapElemValue() - } - e.e.EncodeString(v[j]) - } - e.c = 0 - e.e.WriteMapEnd() -} - -func (e *encoderBincBytes) fastpathEncSliceBytesR(f *encFnInfo, rv reflect.Value) { - var ft fastpathETBincBytes - var v [][]byte - if rv.Kind() == reflect.Array { - rvGetSlice4Array(rv, &v) - } else { - v = rv2i(rv).([][]byte) - } - if f.ti.mbs { - ft.EncAsMapSliceBytesV(v, e) - return - } - ft.EncSliceBytesV(v, e) -} -func (fastpathETBincBytes) EncSliceBytesV(v [][]byte, e *encoderBincBytes) { - if len(v) == 0 { - e.c = 0 - e.e.WriteArrayEmpty() - return - } - e.arrayStart(len(v)) - for j := range v { - e.c = containerArrayElem - e.e.WriteArrayElem(j == 0) - e.e.EncodeBytes(v[j]) - } - e.c = 0 - e.e.WriteArrayEnd() -} -func (fastpathETBincBytes) EncAsMapSliceBytesV(v [][]byte, e *encoderBincBytes) { - if len(v) == 0 { - e.c = 0 - e.e.WriteMapEmpty() - return - } - e.haltOnMbsOddLen(len(v)) - e.mapStart(len(v) >> 1) - for j := range v { - if j&1 == 0 { - e.c = containerMapKey - e.e.WriteMapElemKey(j == 0) - } else { - e.mapElemValue() - } - e.e.EncodeBytes(v[j]) - } - e.c = 0 - e.e.WriteMapEnd() -} - -func (e *encoderBincBytes) fastpathEncSliceFloat32R(f *encFnInfo, rv reflect.Value) { - var ft fastpathETBincBytes - var v []float32 - if rv.Kind() == reflect.Array { - rvGetSlice4Array(rv, &v) - } else { - v = rv2i(rv).([]float32) - } - if f.ti.mbs { - ft.EncAsMapSliceFloat32V(v, e) - return - } - ft.EncSliceFloat32V(v, e) -} -func (fastpathETBincBytes) EncSliceFloat32V(v []float32, e *encoderBincBytes) { - if len(v) == 0 { - e.c = 0 - e.e.WriteArrayEmpty() - return - } - e.arrayStart(len(v)) - for j := range v { - e.c = containerArrayElem - e.e.WriteArrayElem(j == 0) - e.e.EncodeFloat32(v[j]) - } - e.c = 0 - e.e.WriteArrayEnd() -} -func (fastpathETBincBytes) EncAsMapSliceFloat32V(v []float32, e *encoderBincBytes) { - if len(v) == 0 { - e.c = 0 - e.e.WriteMapEmpty() - return - } - e.haltOnMbsOddLen(len(v)) - e.mapStart(len(v) >> 1) - for j := range v { - if j&1 == 0 { - e.c = containerMapKey - e.e.WriteMapElemKey(j == 0) - } else { - e.mapElemValue() - } - e.e.EncodeFloat32(v[j]) - } - e.c = 0 - e.e.WriteMapEnd() -} - -func (e *encoderBincBytes) fastpathEncSliceFloat64R(f *encFnInfo, rv reflect.Value) { - var ft fastpathETBincBytes - var v []float64 - if rv.Kind() == reflect.Array { - rvGetSlice4Array(rv, &v) - } else { - v = rv2i(rv).([]float64) - } - if f.ti.mbs { - ft.EncAsMapSliceFloat64V(v, e) - return - } - ft.EncSliceFloat64V(v, e) -} -func (fastpathETBincBytes) EncSliceFloat64V(v []float64, e *encoderBincBytes) { - if len(v) == 0 { - e.c = 0 - e.e.WriteArrayEmpty() - return - } - e.arrayStart(len(v)) - for j := range v { - e.c = containerArrayElem - e.e.WriteArrayElem(j == 0) - e.e.EncodeFloat64(v[j]) - } - e.c = 0 - e.e.WriteArrayEnd() -} -func (fastpathETBincBytes) EncAsMapSliceFloat64V(v []float64, e *encoderBincBytes) { - if len(v) == 0 { - e.c = 0 - e.e.WriteMapEmpty() - return - } - e.haltOnMbsOddLen(len(v)) - e.mapStart(len(v) >> 1) - for j := range v { - if j&1 == 0 { - e.c = containerMapKey - e.e.WriteMapElemKey(j == 0) - } else { - e.mapElemValue() - } - e.e.EncodeFloat64(v[j]) - } - e.c = 0 - e.e.WriteMapEnd() -} - -func (e *encoderBincBytes) fastpathEncSliceUint8R(f *encFnInfo, rv reflect.Value) { - var ft fastpathETBincBytes - var v []uint8 - if rv.Kind() == reflect.Array { - rvGetSlice4Array(rv, &v) - } else { - v = rv2i(rv).([]uint8) - } - if f.ti.mbs { - ft.EncAsMapSliceUint8V(v, e) - return - } - ft.EncSliceUint8V(v, e) -} -func (fastpathETBincBytes) EncSliceUint8V(v []uint8, e *encoderBincBytes) { - e.e.EncodeStringBytesRaw(v) -} -func (fastpathETBincBytes) EncAsMapSliceUint8V(v []uint8, e *encoderBincBytes) { - if len(v) == 0 { - e.c = 0 - e.e.WriteMapEmpty() - return - } - e.haltOnMbsOddLen(len(v)) - e.mapStart(len(v) >> 1) - for j := range v { - if j&1 == 0 { - e.c = containerMapKey - e.e.WriteMapElemKey(j == 0) - } else { - e.mapElemValue() - } - e.e.EncodeUint(uint64(v[j])) - } - e.c = 0 - e.e.WriteMapEnd() -} - -func (e *encoderBincBytes) fastpathEncSliceUint64R(f *encFnInfo, rv reflect.Value) { - var ft fastpathETBincBytes - var v []uint64 - if rv.Kind() == reflect.Array { - rvGetSlice4Array(rv, &v) - } else { - v = rv2i(rv).([]uint64) - } - if f.ti.mbs { - ft.EncAsMapSliceUint64V(v, e) - return - } - ft.EncSliceUint64V(v, e) -} -func (fastpathETBincBytes) EncSliceUint64V(v []uint64, e *encoderBincBytes) { - if len(v) == 0 { - e.c = 0 - e.e.WriteArrayEmpty() - return - } - e.arrayStart(len(v)) - for j := range v { - e.c = containerArrayElem - e.e.WriteArrayElem(j == 0) - e.e.EncodeUint(v[j]) - } - e.c = 0 - e.e.WriteArrayEnd() -} -func (fastpathETBincBytes) EncAsMapSliceUint64V(v []uint64, e *encoderBincBytes) { - if len(v) == 0 { - e.c = 0 - e.e.WriteMapEmpty() - return - } - e.haltOnMbsOddLen(len(v)) - e.mapStart(len(v) >> 1) - for j := range v { - if j&1 == 0 { - e.c = containerMapKey - e.e.WriteMapElemKey(j == 0) - } else { - e.mapElemValue() - } - e.e.EncodeUint(v[j]) - } - e.c = 0 - e.e.WriteMapEnd() -} - -func (e *encoderBincBytes) fastpathEncSliceIntR(f *encFnInfo, rv reflect.Value) { - var ft fastpathETBincBytes - var v []int - if rv.Kind() == reflect.Array { - rvGetSlice4Array(rv, &v) - } else { - v = rv2i(rv).([]int) - } - if f.ti.mbs { - ft.EncAsMapSliceIntV(v, e) - return - } - ft.EncSliceIntV(v, e) -} -func (fastpathETBincBytes) EncSliceIntV(v []int, e *encoderBincBytes) { - if len(v) == 0 { - e.c = 0 - e.e.WriteArrayEmpty() - return - } - e.arrayStart(len(v)) - for j := range v { - e.c = containerArrayElem - e.e.WriteArrayElem(j == 0) - e.e.EncodeInt(int64(v[j])) - } - e.c = 0 - e.e.WriteArrayEnd() -} -func (fastpathETBincBytes) EncAsMapSliceIntV(v []int, e *encoderBincBytes) { - if len(v) == 0 { - e.c = 0 - e.e.WriteMapEmpty() - return - } - e.haltOnMbsOddLen(len(v)) - e.mapStart(len(v) >> 1) - for j := range v { - if j&1 == 0 { - e.c = containerMapKey - e.e.WriteMapElemKey(j == 0) - } else { - e.mapElemValue() - } - e.e.EncodeInt(int64(v[j])) - } - e.c = 0 - e.e.WriteMapEnd() -} - -func (e *encoderBincBytes) fastpathEncSliceInt32R(f *encFnInfo, rv reflect.Value) { - var ft fastpathETBincBytes - var v []int32 - if rv.Kind() == reflect.Array { - rvGetSlice4Array(rv, &v) - } else { - v = rv2i(rv).([]int32) - } - if f.ti.mbs { - ft.EncAsMapSliceInt32V(v, e) - return - } - ft.EncSliceInt32V(v, e) -} -func (fastpathETBincBytes) EncSliceInt32V(v []int32, e *encoderBincBytes) { - if len(v) == 0 { - e.c = 0 - e.e.WriteArrayEmpty() - return - } - e.arrayStart(len(v)) - for j := range v { - e.c = containerArrayElem - e.e.WriteArrayElem(j == 0) - e.e.EncodeInt(int64(v[j])) - } - e.c = 0 - e.e.WriteArrayEnd() -} -func (fastpathETBincBytes) EncAsMapSliceInt32V(v []int32, e *encoderBincBytes) { - if len(v) == 0 { - e.c = 0 - e.e.WriteMapEmpty() - return - } - e.haltOnMbsOddLen(len(v)) - e.mapStart(len(v) >> 1) - for j := range v { - if j&1 == 0 { - e.c = containerMapKey - e.e.WriteMapElemKey(j == 0) - } else { - e.mapElemValue() - } - e.e.EncodeInt(int64(v[j])) - } - e.c = 0 - e.e.WriteMapEnd() -} - -func (e *encoderBincBytes) fastpathEncSliceInt64R(f *encFnInfo, rv reflect.Value) { - var ft fastpathETBincBytes - var v []int64 - if rv.Kind() == reflect.Array { - rvGetSlice4Array(rv, &v) - } else { - v = rv2i(rv).([]int64) - } - if f.ti.mbs { - ft.EncAsMapSliceInt64V(v, e) - return - } - ft.EncSliceInt64V(v, e) -} -func (fastpathETBincBytes) EncSliceInt64V(v []int64, e *encoderBincBytes) { - if len(v) == 0 { - e.c = 0 - e.e.WriteArrayEmpty() - return - } - e.arrayStart(len(v)) - for j := range v { - e.c = containerArrayElem - e.e.WriteArrayElem(j == 0) - e.e.EncodeInt(v[j]) - } - e.c = 0 - e.e.WriteArrayEnd() -} -func (fastpathETBincBytes) EncAsMapSliceInt64V(v []int64, e *encoderBincBytes) { - if len(v) == 0 { - e.c = 0 - e.e.WriteMapEmpty() - return - } - e.haltOnMbsOddLen(len(v)) - e.mapStart(len(v) >> 1) - for j := range v { - if j&1 == 0 { - e.c = containerMapKey - e.e.WriteMapElemKey(j == 0) - } else { - e.mapElemValue() - } - e.e.EncodeInt(v[j]) - } - e.c = 0 - e.e.WriteMapEnd() -} - -func (e *encoderBincBytes) fastpathEncSliceBoolR(f *encFnInfo, rv reflect.Value) { - var ft fastpathETBincBytes - var v []bool - if rv.Kind() == reflect.Array { - rvGetSlice4Array(rv, &v) - } else { - v = rv2i(rv).([]bool) - } - if f.ti.mbs { - ft.EncAsMapSliceBoolV(v, e) - return - } - ft.EncSliceBoolV(v, e) -} -func (fastpathETBincBytes) EncSliceBoolV(v []bool, e *encoderBincBytes) { - if len(v) == 0 { - e.c = 0 - e.e.WriteArrayEmpty() - return - } - e.arrayStart(len(v)) - for j := range v { - e.c = containerArrayElem - e.e.WriteArrayElem(j == 0) - e.e.EncodeBool(v[j]) - } - e.c = 0 - e.e.WriteArrayEnd() -} -func (fastpathETBincBytes) EncAsMapSliceBoolV(v []bool, e *encoderBincBytes) { - if len(v) == 0 { - e.c = 0 - e.e.WriteMapEmpty() - return - } - e.haltOnMbsOddLen(len(v)) - e.mapStart(len(v) >> 1) - for j := range v { - if j&1 == 0 { - e.c = containerMapKey - e.e.WriteMapElemKey(j == 0) - } else { - e.mapElemValue() - } - e.e.EncodeBool(v[j]) - } - e.c = 0 - e.e.WriteMapEnd() -} - -func (e *encoderBincBytes) fastpathEncMapStringIntfR(f *encFnInfo, rv reflect.Value) { - fastpathETBincBytes{}.EncMapStringIntfV(rv2i(rv).(map[string]interface{}), e) -} -func (fastpathETBincBytes) EncMapStringIntfV(v map[string]interface{}, e *encoderBincBytes) { - if len(v) == 0 { - e.e.WriteMapEmpty() - return - } - var i uint - e.mapStart(len(v)) - if e.h.Canonical { - v2 := make([]string, len(v)) - for k := range v { - v2[i] = k - i++ - } - slices.Sort(v2) - for i, k2 := range v2 { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeString(k2) - e.mapElemValue() - if !e.encodeBuiltin(v[k2]) { - e.encodeR(reflect.ValueOf(v[k2])) - } - } - } else { - i = 0 - for k2, v2 := range v { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeString(k2) - e.mapElemValue() - if !e.encodeBuiltin(v2) { - e.encodeR(reflect.ValueOf(v2)) - } - i++ - } - } - e.c = 0 - e.e.WriteMapEnd() -} -func (e *encoderBincBytes) fastpathEncMapStringStringR(f *encFnInfo, rv reflect.Value) { - fastpathETBincBytes{}.EncMapStringStringV(rv2i(rv).(map[string]string), e) -} -func (fastpathETBincBytes) EncMapStringStringV(v map[string]string, e *encoderBincBytes) { - if len(v) == 0 { - e.e.WriteMapEmpty() - return - } - var i uint - e.mapStart(len(v)) - if e.h.Canonical { - v2 := make([]string, len(v)) - for k := range v { - v2[i] = k - i++ - } - slices.Sort(v2) - for i, k2 := range v2 { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeString(k2) - e.mapElemValue() - e.e.EncodeString(v[k2]) - } - } else { - i = 0 - for k2, v2 := range v { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeString(k2) - e.mapElemValue() - e.e.EncodeString(v2) - i++ - } - } - e.c = 0 - e.e.WriteMapEnd() -} -func (e *encoderBincBytes) fastpathEncMapStringBytesR(f *encFnInfo, rv reflect.Value) { - fastpathETBincBytes{}.EncMapStringBytesV(rv2i(rv).(map[string][]byte), e) -} -func (fastpathETBincBytes) EncMapStringBytesV(v map[string][]byte, e *encoderBincBytes) { - if len(v) == 0 { - e.e.WriteMapEmpty() - return - } - var i uint - e.mapStart(len(v)) - if e.h.Canonical { - v2 := make([]string, len(v)) - for k := range v { - v2[i] = k - i++ - } - slices.Sort(v2) - for i, k2 := range v2 { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeString(k2) - e.mapElemValue() - e.e.EncodeBytes(v[k2]) - } - } else { - i = 0 - for k2, v2 := range v { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeString(k2) - e.mapElemValue() - e.e.EncodeBytes(v2) - i++ - } - } - e.c = 0 - e.e.WriteMapEnd() -} -func (e *encoderBincBytes) fastpathEncMapStringUint8R(f *encFnInfo, rv reflect.Value) { - fastpathETBincBytes{}.EncMapStringUint8V(rv2i(rv).(map[string]uint8), e) -} -func (fastpathETBincBytes) EncMapStringUint8V(v map[string]uint8, e *encoderBincBytes) { - if len(v) == 0 { - e.e.WriteMapEmpty() - return - } - var i uint - e.mapStart(len(v)) - if e.h.Canonical { - v2 := make([]string, len(v)) - for k := range v { - v2[i] = k - i++ - } - slices.Sort(v2) - for i, k2 := range v2 { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeString(k2) - e.mapElemValue() - e.e.EncodeUint(uint64(v[k2])) - } - } else { - i = 0 - for k2, v2 := range v { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeString(k2) - e.mapElemValue() - e.e.EncodeUint(uint64(v2)) - i++ - } - } - e.c = 0 - e.e.WriteMapEnd() -} -func (e *encoderBincBytes) fastpathEncMapStringUint64R(f *encFnInfo, rv reflect.Value) { - fastpathETBincBytes{}.EncMapStringUint64V(rv2i(rv).(map[string]uint64), e) -} -func (fastpathETBincBytes) EncMapStringUint64V(v map[string]uint64, e *encoderBincBytes) { - if len(v) == 0 { - e.e.WriteMapEmpty() - return - } - var i uint - e.mapStart(len(v)) - if e.h.Canonical { - v2 := make([]string, len(v)) - for k := range v { - v2[i] = k - i++ - } - slices.Sort(v2) - for i, k2 := range v2 { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeString(k2) - e.mapElemValue() - e.e.EncodeUint(v[k2]) - } - } else { - i = 0 - for k2, v2 := range v { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeString(k2) - e.mapElemValue() - e.e.EncodeUint(v2) - i++ - } - } - e.c = 0 - e.e.WriteMapEnd() -} -func (e *encoderBincBytes) fastpathEncMapStringIntR(f *encFnInfo, rv reflect.Value) { - fastpathETBincBytes{}.EncMapStringIntV(rv2i(rv).(map[string]int), e) -} -func (fastpathETBincBytes) EncMapStringIntV(v map[string]int, e *encoderBincBytes) { - if len(v) == 0 { - e.e.WriteMapEmpty() - return - } - var i uint - e.mapStart(len(v)) - if e.h.Canonical { - v2 := make([]string, len(v)) - for k := range v { - v2[i] = k - i++ - } - slices.Sort(v2) - for i, k2 := range v2 { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeString(k2) - e.mapElemValue() - e.e.EncodeInt(int64(v[k2])) - } - } else { - i = 0 - for k2, v2 := range v { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeString(k2) - e.mapElemValue() - e.e.EncodeInt(int64(v2)) - i++ - } - } - e.c = 0 - e.e.WriteMapEnd() -} -func (e *encoderBincBytes) fastpathEncMapStringInt32R(f *encFnInfo, rv reflect.Value) { - fastpathETBincBytes{}.EncMapStringInt32V(rv2i(rv).(map[string]int32), e) -} -func (fastpathETBincBytes) EncMapStringInt32V(v map[string]int32, e *encoderBincBytes) { - if len(v) == 0 { - e.e.WriteMapEmpty() - return - } - var i uint - e.mapStart(len(v)) - if e.h.Canonical { - v2 := make([]string, len(v)) - for k := range v { - v2[i] = k - i++ - } - slices.Sort(v2) - for i, k2 := range v2 { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeString(k2) - e.mapElemValue() - e.e.EncodeInt(int64(v[k2])) - } - } else { - i = 0 - for k2, v2 := range v { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeString(k2) - e.mapElemValue() - e.e.EncodeInt(int64(v2)) - i++ - } - } - e.c = 0 - e.e.WriteMapEnd() -} -func (e *encoderBincBytes) fastpathEncMapStringFloat64R(f *encFnInfo, rv reflect.Value) { - fastpathETBincBytes{}.EncMapStringFloat64V(rv2i(rv).(map[string]float64), e) -} -func (fastpathETBincBytes) EncMapStringFloat64V(v map[string]float64, e *encoderBincBytes) { - if len(v) == 0 { - e.e.WriteMapEmpty() - return - } - var i uint - e.mapStart(len(v)) - if e.h.Canonical { - v2 := make([]string, len(v)) - for k := range v { - v2[i] = k - i++ - } - slices.Sort(v2) - for i, k2 := range v2 { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeString(k2) - e.mapElemValue() - e.e.EncodeFloat64(v[k2]) - } - } else { - i = 0 - for k2, v2 := range v { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeString(k2) - e.mapElemValue() - e.e.EncodeFloat64(v2) - i++ - } - } - e.c = 0 - e.e.WriteMapEnd() -} -func (e *encoderBincBytes) fastpathEncMapStringBoolR(f *encFnInfo, rv reflect.Value) { - fastpathETBincBytes{}.EncMapStringBoolV(rv2i(rv).(map[string]bool), e) -} -func (fastpathETBincBytes) EncMapStringBoolV(v map[string]bool, e *encoderBincBytes) { - if len(v) == 0 { - e.e.WriteMapEmpty() - return - } - var i uint - e.mapStart(len(v)) - if e.h.Canonical { - v2 := make([]string, len(v)) - for k := range v { - v2[i] = k - i++ - } - slices.Sort(v2) - for i, k2 := range v2 { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeString(k2) - e.mapElemValue() - e.e.EncodeBool(v[k2]) - } - } else { - i = 0 - for k2, v2 := range v { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeString(k2) - e.mapElemValue() - e.e.EncodeBool(v2) - i++ - } - } - e.c = 0 - e.e.WriteMapEnd() -} -func (e *encoderBincBytes) fastpathEncMapUint8IntfR(f *encFnInfo, rv reflect.Value) { - fastpathETBincBytes{}.EncMapUint8IntfV(rv2i(rv).(map[uint8]interface{}), e) -} -func (fastpathETBincBytes) EncMapUint8IntfV(v map[uint8]interface{}, e *encoderBincBytes) { - if len(v) == 0 { - e.e.WriteMapEmpty() - return - } - var i uint - e.mapStart(len(v)) - if e.h.Canonical { - v2 := make([]uint8, len(v)) - for k := range v { - v2[i] = k - i++ - } - slices.Sort(v2) - for i, k2 := range v2 { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeUint(uint64(k2)) - e.mapElemValue() - if !e.encodeBuiltin(v[k2]) { - e.encodeR(reflect.ValueOf(v[k2])) - } - } - } else { - i = 0 - for k2, v2 := range v { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeUint(uint64(k2)) - e.mapElemValue() - if !e.encodeBuiltin(v2) { - e.encodeR(reflect.ValueOf(v2)) - } - i++ - } - } - e.c = 0 - e.e.WriteMapEnd() -} -func (e *encoderBincBytes) fastpathEncMapUint8StringR(f *encFnInfo, rv reflect.Value) { - fastpathETBincBytes{}.EncMapUint8StringV(rv2i(rv).(map[uint8]string), e) -} -func (fastpathETBincBytes) EncMapUint8StringV(v map[uint8]string, e *encoderBincBytes) { - if len(v) == 0 { - e.e.WriteMapEmpty() - return - } - var i uint - e.mapStart(len(v)) - if e.h.Canonical { - v2 := make([]uint8, len(v)) - for k := range v { - v2[i] = k - i++ - } - slices.Sort(v2) - for i, k2 := range v2 { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeUint(uint64(k2)) - e.mapElemValue() - e.e.EncodeString(v[k2]) - } - } else { - i = 0 - for k2, v2 := range v { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeUint(uint64(k2)) - e.mapElemValue() - e.e.EncodeString(v2) - i++ - } - } - e.c = 0 - e.e.WriteMapEnd() -} -func (e *encoderBincBytes) fastpathEncMapUint8BytesR(f *encFnInfo, rv reflect.Value) { - fastpathETBincBytes{}.EncMapUint8BytesV(rv2i(rv).(map[uint8][]byte), e) -} -func (fastpathETBincBytes) EncMapUint8BytesV(v map[uint8][]byte, e *encoderBincBytes) { - if len(v) == 0 { - e.e.WriteMapEmpty() - return - } - var i uint - e.mapStart(len(v)) - if e.h.Canonical { - v2 := make([]uint8, len(v)) - for k := range v { - v2[i] = k - i++ - } - slices.Sort(v2) - for i, k2 := range v2 { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeUint(uint64(k2)) - e.mapElemValue() - e.e.EncodeBytes(v[k2]) - } - } else { - i = 0 - for k2, v2 := range v { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeUint(uint64(k2)) - e.mapElemValue() - e.e.EncodeBytes(v2) - i++ - } - } - e.c = 0 - e.e.WriteMapEnd() -} -func (e *encoderBincBytes) fastpathEncMapUint8Uint8R(f *encFnInfo, rv reflect.Value) { - fastpathETBincBytes{}.EncMapUint8Uint8V(rv2i(rv).(map[uint8]uint8), e) -} -func (fastpathETBincBytes) EncMapUint8Uint8V(v map[uint8]uint8, e *encoderBincBytes) { - if len(v) == 0 { - e.e.WriteMapEmpty() - return - } - var i uint - e.mapStart(len(v)) - if e.h.Canonical { - v2 := make([]uint8, len(v)) - for k := range v { - v2[i] = k - i++ - } - slices.Sort(v2) - for i, k2 := range v2 { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeUint(uint64(k2)) - e.mapElemValue() - e.e.EncodeUint(uint64(v[k2])) - } - } else { - i = 0 - for k2, v2 := range v { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeUint(uint64(k2)) - e.mapElemValue() - e.e.EncodeUint(uint64(v2)) - i++ - } - } - e.c = 0 - e.e.WriteMapEnd() -} -func (e *encoderBincBytes) fastpathEncMapUint8Uint64R(f *encFnInfo, rv reflect.Value) { - fastpathETBincBytes{}.EncMapUint8Uint64V(rv2i(rv).(map[uint8]uint64), e) -} -func (fastpathETBincBytes) EncMapUint8Uint64V(v map[uint8]uint64, e *encoderBincBytes) { - if len(v) == 0 { - e.e.WriteMapEmpty() - return - } - var i uint - e.mapStart(len(v)) - if e.h.Canonical { - v2 := make([]uint8, len(v)) - for k := range v { - v2[i] = k - i++ - } - slices.Sort(v2) - for i, k2 := range v2 { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeUint(uint64(k2)) - e.mapElemValue() - e.e.EncodeUint(v[k2]) - } - } else { - i = 0 - for k2, v2 := range v { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeUint(uint64(k2)) - e.mapElemValue() - e.e.EncodeUint(v2) - i++ - } - } - e.c = 0 - e.e.WriteMapEnd() -} -func (e *encoderBincBytes) fastpathEncMapUint8IntR(f *encFnInfo, rv reflect.Value) { - fastpathETBincBytes{}.EncMapUint8IntV(rv2i(rv).(map[uint8]int), e) -} -func (fastpathETBincBytes) EncMapUint8IntV(v map[uint8]int, e *encoderBincBytes) { - if len(v) == 0 { - e.e.WriteMapEmpty() - return - } - var i uint - e.mapStart(len(v)) - if e.h.Canonical { - v2 := make([]uint8, len(v)) - for k := range v { - v2[i] = k - i++ - } - slices.Sort(v2) - for i, k2 := range v2 { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeUint(uint64(k2)) - e.mapElemValue() - e.e.EncodeInt(int64(v[k2])) - } - } else { - i = 0 - for k2, v2 := range v { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeUint(uint64(k2)) - e.mapElemValue() - e.e.EncodeInt(int64(v2)) - i++ - } - } - e.c = 0 - e.e.WriteMapEnd() -} -func (e *encoderBincBytes) fastpathEncMapUint8Int32R(f *encFnInfo, rv reflect.Value) { - fastpathETBincBytes{}.EncMapUint8Int32V(rv2i(rv).(map[uint8]int32), e) -} -func (fastpathETBincBytes) EncMapUint8Int32V(v map[uint8]int32, e *encoderBincBytes) { - if len(v) == 0 { - e.e.WriteMapEmpty() - return - } - var i uint - e.mapStart(len(v)) - if e.h.Canonical { - v2 := make([]uint8, len(v)) - for k := range v { - v2[i] = k - i++ - } - slices.Sort(v2) - for i, k2 := range v2 { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeUint(uint64(k2)) - e.mapElemValue() - e.e.EncodeInt(int64(v[k2])) - } - } else { - i = 0 - for k2, v2 := range v { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeUint(uint64(k2)) - e.mapElemValue() - e.e.EncodeInt(int64(v2)) - i++ - } - } - e.c = 0 - e.e.WriteMapEnd() -} -func (e *encoderBincBytes) fastpathEncMapUint8Float64R(f *encFnInfo, rv reflect.Value) { - fastpathETBincBytes{}.EncMapUint8Float64V(rv2i(rv).(map[uint8]float64), e) -} -func (fastpathETBincBytes) EncMapUint8Float64V(v map[uint8]float64, e *encoderBincBytes) { - if len(v) == 0 { - e.e.WriteMapEmpty() - return - } - var i uint - e.mapStart(len(v)) - if e.h.Canonical { - v2 := make([]uint8, len(v)) - for k := range v { - v2[i] = k - i++ - } - slices.Sort(v2) - for i, k2 := range v2 { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeUint(uint64(k2)) - e.mapElemValue() - e.e.EncodeFloat64(v[k2]) - } - } else { - i = 0 - for k2, v2 := range v { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeUint(uint64(k2)) - e.mapElemValue() - e.e.EncodeFloat64(v2) - i++ - } - } - e.c = 0 - e.e.WriteMapEnd() -} -func (e *encoderBincBytes) fastpathEncMapUint8BoolR(f *encFnInfo, rv reflect.Value) { - fastpathETBincBytes{}.EncMapUint8BoolV(rv2i(rv).(map[uint8]bool), e) -} -func (fastpathETBincBytes) EncMapUint8BoolV(v map[uint8]bool, e *encoderBincBytes) { - if len(v) == 0 { - e.e.WriteMapEmpty() - return - } - var i uint - e.mapStart(len(v)) - if e.h.Canonical { - v2 := make([]uint8, len(v)) - for k := range v { - v2[i] = k - i++ - } - slices.Sort(v2) - for i, k2 := range v2 { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeUint(uint64(k2)) - e.mapElemValue() - e.e.EncodeBool(v[k2]) - } - } else { - i = 0 - for k2, v2 := range v { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeUint(uint64(k2)) - e.mapElemValue() - e.e.EncodeBool(v2) - i++ - } - } - e.c = 0 - e.e.WriteMapEnd() -} -func (e *encoderBincBytes) fastpathEncMapUint64IntfR(f *encFnInfo, rv reflect.Value) { - fastpathETBincBytes{}.EncMapUint64IntfV(rv2i(rv).(map[uint64]interface{}), e) -} -func (fastpathETBincBytes) EncMapUint64IntfV(v map[uint64]interface{}, e *encoderBincBytes) { - if len(v) == 0 { - e.e.WriteMapEmpty() - return - } - var i uint - e.mapStart(len(v)) - if e.h.Canonical { - v2 := make([]uint64, len(v)) - for k := range v { - v2[i] = k - i++ - } - slices.Sort(v2) - for i, k2 := range v2 { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeUint(k2) - e.mapElemValue() - if !e.encodeBuiltin(v[k2]) { - e.encodeR(reflect.ValueOf(v[k2])) - } - } - } else { - i = 0 - for k2, v2 := range v { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeUint(k2) - e.mapElemValue() - if !e.encodeBuiltin(v2) { - e.encodeR(reflect.ValueOf(v2)) - } - i++ - } - } - e.c = 0 - e.e.WriteMapEnd() -} -func (e *encoderBincBytes) fastpathEncMapUint64StringR(f *encFnInfo, rv reflect.Value) { - fastpathETBincBytes{}.EncMapUint64StringV(rv2i(rv).(map[uint64]string), e) -} -func (fastpathETBincBytes) EncMapUint64StringV(v map[uint64]string, e *encoderBincBytes) { - if len(v) == 0 { - e.e.WriteMapEmpty() - return - } - var i uint - e.mapStart(len(v)) - if e.h.Canonical { - v2 := make([]uint64, len(v)) - for k := range v { - v2[i] = k - i++ - } - slices.Sort(v2) - for i, k2 := range v2 { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeUint(k2) - e.mapElemValue() - e.e.EncodeString(v[k2]) - } - } else { - i = 0 - for k2, v2 := range v { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeUint(k2) - e.mapElemValue() - e.e.EncodeString(v2) - i++ - } - } - e.c = 0 - e.e.WriteMapEnd() -} -func (e *encoderBincBytes) fastpathEncMapUint64BytesR(f *encFnInfo, rv reflect.Value) { - fastpathETBincBytes{}.EncMapUint64BytesV(rv2i(rv).(map[uint64][]byte), e) -} -func (fastpathETBincBytes) EncMapUint64BytesV(v map[uint64][]byte, e *encoderBincBytes) { - if len(v) == 0 { - e.e.WriteMapEmpty() - return - } - var i uint - e.mapStart(len(v)) - if e.h.Canonical { - v2 := make([]uint64, len(v)) - for k := range v { - v2[i] = k - i++ - } - slices.Sort(v2) - for i, k2 := range v2 { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeUint(k2) - e.mapElemValue() - e.e.EncodeBytes(v[k2]) - } - } else { - i = 0 - for k2, v2 := range v { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeUint(k2) - e.mapElemValue() - e.e.EncodeBytes(v2) - i++ - } - } - e.c = 0 - e.e.WriteMapEnd() -} -func (e *encoderBincBytes) fastpathEncMapUint64Uint8R(f *encFnInfo, rv reflect.Value) { - fastpathETBincBytes{}.EncMapUint64Uint8V(rv2i(rv).(map[uint64]uint8), e) -} -func (fastpathETBincBytes) EncMapUint64Uint8V(v map[uint64]uint8, e *encoderBincBytes) { - if len(v) == 0 { - e.e.WriteMapEmpty() - return - } - var i uint - e.mapStart(len(v)) - if e.h.Canonical { - v2 := make([]uint64, len(v)) - for k := range v { - v2[i] = k - i++ - } - slices.Sort(v2) - for i, k2 := range v2 { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeUint(k2) - e.mapElemValue() - e.e.EncodeUint(uint64(v[k2])) - } - } else { - i = 0 - for k2, v2 := range v { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeUint(k2) - e.mapElemValue() - e.e.EncodeUint(uint64(v2)) - i++ - } - } - e.c = 0 - e.e.WriteMapEnd() -} -func (e *encoderBincBytes) fastpathEncMapUint64Uint64R(f *encFnInfo, rv reflect.Value) { - fastpathETBincBytes{}.EncMapUint64Uint64V(rv2i(rv).(map[uint64]uint64), e) -} -func (fastpathETBincBytes) EncMapUint64Uint64V(v map[uint64]uint64, e *encoderBincBytes) { - if len(v) == 0 { - e.e.WriteMapEmpty() - return - } - var i uint - e.mapStart(len(v)) - if e.h.Canonical { - v2 := make([]uint64, len(v)) - for k := range v { - v2[i] = k - i++ - } - slices.Sort(v2) - for i, k2 := range v2 { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeUint(k2) - e.mapElemValue() - e.e.EncodeUint(v[k2]) - } - } else { - i = 0 - for k2, v2 := range v { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeUint(k2) - e.mapElemValue() - e.e.EncodeUint(v2) - i++ - } - } - e.c = 0 - e.e.WriteMapEnd() -} -func (e *encoderBincBytes) fastpathEncMapUint64IntR(f *encFnInfo, rv reflect.Value) { - fastpathETBincBytes{}.EncMapUint64IntV(rv2i(rv).(map[uint64]int), e) -} -func (fastpathETBincBytes) EncMapUint64IntV(v map[uint64]int, e *encoderBincBytes) { - if len(v) == 0 { - e.e.WriteMapEmpty() - return - } - var i uint - e.mapStart(len(v)) - if e.h.Canonical { - v2 := make([]uint64, len(v)) - for k := range v { - v2[i] = k - i++ - } - slices.Sort(v2) - for i, k2 := range v2 { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeUint(k2) - e.mapElemValue() - e.e.EncodeInt(int64(v[k2])) - } - } else { - i = 0 - for k2, v2 := range v { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeUint(k2) - e.mapElemValue() - e.e.EncodeInt(int64(v2)) - i++ - } - } - e.c = 0 - e.e.WriteMapEnd() -} -func (e *encoderBincBytes) fastpathEncMapUint64Int32R(f *encFnInfo, rv reflect.Value) { - fastpathETBincBytes{}.EncMapUint64Int32V(rv2i(rv).(map[uint64]int32), e) -} -func (fastpathETBincBytes) EncMapUint64Int32V(v map[uint64]int32, e *encoderBincBytes) { - if len(v) == 0 { - e.e.WriteMapEmpty() - return - } - var i uint - e.mapStart(len(v)) - if e.h.Canonical { - v2 := make([]uint64, len(v)) - for k := range v { - v2[i] = k - i++ - } - slices.Sort(v2) - for i, k2 := range v2 { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeUint(k2) - e.mapElemValue() - e.e.EncodeInt(int64(v[k2])) - } - } else { - i = 0 - for k2, v2 := range v { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeUint(k2) - e.mapElemValue() - e.e.EncodeInt(int64(v2)) - i++ - } - } - e.c = 0 - e.e.WriteMapEnd() -} -func (e *encoderBincBytes) fastpathEncMapUint64Float64R(f *encFnInfo, rv reflect.Value) { - fastpathETBincBytes{}.EncMapUint64Float64V(rv2i(rv).(map[uint64]float64), e) -} -func (fastpathETBincBytes) EncMapUint64Float64V(v map[uint64]float64, e *encoderBincBytes) { - if len(v) == 0 { - e.e.WriteMapEmpty() - return - } - var i uint - e.mapStart(len(v)) - if e.h.Canonical { - v2 := make([]uint64, len(v)) - for k := range v { - v2[i] = k - i++ - } - slices.Sort(v2) - for i, k2 := range v2 { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeUint(k2) - e.mapElemValue() - e.e.EncodeFloat64(v[k2]) - } - } else { - i = 0 - for k2, v2 := range v { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeUint(k2) - e.mapElemValue() - e.e.EncodeFloat64(v2) - i++ - } - } - e.c = 0 - e.e.WriteMapEnd() -} -func (e *encoderBincBytes) fastpathEncMapUint64BoolR(f *encFnInfo, rv reflect.Value) { - fastpathETBincBytes{}.EncMapUint64BoolV(rv2i(rv).(map[uint64]bool), e) -} -func (fastpathETBincBytes) EncMapUint64BoolV(v map[uint64]bool, e *encoderBincBytes) { - if len(v) == 0 { - e.e.WriteMapEmpty() - return - } - var i uint - e.mapStart(len(v)) - if e.h.Canonical { - v2 := make([]uint64, len(v)) - for k := range v { - v2[i] = k - i++ - } - slices.Sort(v2) - for i, k2 := range v2 { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeUint(k2) - e.mapElemValue() - e.e.EncodeBool(v[k2]) - } - } else { - i = 0 - for k2, v2 := range v { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeUint(k2) - e.mapElemValue() - e.e.EncodeBool(v2) - i++ - } - } - e.c = 0 - e.e.WriteMapEnd() -} -func (e *encoderBincBytes) fastpathEncMapIntIntfR(f *encFnInfo, rv reflect.Value) { - fastpathETBincBytes{}.EncMapIntIntfV(rv2i(rv).(map[int]interface{}), e) -} -func (fastpathETBincBytes) EncMapIntIntfV(v map[int]interface{}, e *encoderBincBytes) { - if len(v) == 0 { - e.e.WriteMapEmpty() - return - } - var i uint - e.mapStart(len(v)) - if e.h.Canonical { - v2 := make([]int, len(v)) - for k := range v { - v2[i] = k - i++ - } - slices.Sort(v2) - for i, k2 := range v2 { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeInt(int64(k2)) - e.mapElemValue() - if !e.encodeBuiltin(v[k2]) { - e.encodeR(reflect.ValueOf(v[k2])) - } - } - } else { - i = 0 - for k2, v2 := range v { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeInt(int64(k2)) - e.mapElemValue() - if !e.encodeBuiltin(v2) { - e.encodeR(reflect.ValueOf(v2)) - } - i++ - } - } - e.c = 0 - e.e.WriteMapEnd() -} -func (e *encoderBincBytes) fastpathEncMapIntStringR(f *encFnInfo, rv reflect.Value) { - fastpathETBincBytes{}.EncMapIntStringV(rv2i(rv).(map[int]string), e) -} -func (fastpathETBincBytes) EncMapIntStringV(v map[int]string, e *encoderBincBytes) { - if len(v) == 0 { - e.e.WriteMapEmpty() - return - } - var i uint - e.mapStart(len(v)) - if e.h.Canonical { - v2 := make([]int, len(v)) - for k := range v { - v2[i] = k - i++ - } - slices.Sort(v2) - for i, k2 := range v2 { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeInt(int64(k2)) - e.mapElemValue() - e.e.EncodeString(v[k2]) - } - } else { - i = 0 - for k2, v2 := range v { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeInt(int64(k2)) - e.mapElemValue() - e.e.EncodeString(v2) - i++ - } - } - e.c = 0 - e.e.WriteMapEnd() -} -func (e *encoderBincBytes) fastpathEncMapIntBytesR(f *encFnInfo, rv reflect.Value) { - fastpathETBincBytes{}.EncMapIntBytesV(rv2i(rv).(map[int][]byte), e) -} -func (fastpathETBincBytes) EncMapIntBytesV(v map[int][]byte, e *encoderBincBytes) { - if len(v) == 0 { - e.e.WriteMapEmpty() - return - } - var i uint - e.mapStart(len(v)) - if e.h.Canonical { - v2 := make([]int, len(v)) - for k := range v { - v2[i] = k - i++ - } - slices.Sort(v2) - for i, k2 := range v2 { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeInt(int64(k2)) - e.mapElemValue() - e.e.EncodeBytes(v[k2]) - } - } else { - i = 0 - for k2, v2 := range v { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeInt(int64(k2)) - e.mapElemValue() - e.e.EncodeBytes(v2) - i++ - } - } - e.c = 0 - e.e.WriteMapEnd() -} -func (e *encoderBincBytes) fastpathEncMapIntUint8R(f *encFnInfo, rv reflect.Value) { - fastpathETBincBytes{}.EncMapIntUint8V(rv2i(rv).(map[int]uint8), e) -} -func (fastpathETBincBytes) EncMapIntUint8V(v map[int]uint8, e *encoderBincBytes) { - if len(v) == 0 { - e.e.WriteMapEmpty() - return - } - var i uint - e.mapStart(len(v)) - if e.h.Canonical { - v2 := make([]int, len(v)) - for k := range v { - v2[i] = k - i++ - } - slices.Sort(v2) - for i, k2 := range v2 { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeInt(int64(k2)) - e.mapElemValue() - e.e.EncodeUint(uint64(v[k2])) - } - } else { - i = 0 - for k2, v2 := range v { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeInt(int64(k2)) - e.mapElemValue() - e.e.EncodeUint(uint64(v2)) - i++ - } - } - e.c = 0 - e.e.WriteMapEnd() -} -func (e *encoderBincBytes) fastpathEncMapIntUint64R(f *encFnInfo, rv reflect.Value) { - fastpathETBincBytes{}.EncMapIntUint64V(rv2i(rv).(map[int]uint64), e) -} -func (fastpathETBincBytes) EncMapIntUint64V(v map[int]uint64, e *encoderBincBytes) { - if len(v) == 0 { - e.e.WriteMapEmpty() - return - } - var i uint - e.mapStart(len(v)) - if e.h.Canonical { - v2 := make([]int, len(v)) - for k := range v { - v2[i] = k - i++ - } - slices.Sort(v2) - for i, k2 := range v2 { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeInt(int64(k2)) - e.mapElemValue() - e.e.EncodeUint(v[k2]) - } - } else { - i = 0 - for k2, v2 := range v { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeInt(int64(k2)) - e.mapElemValue() - e.e.EncodeUint(v2) - i++ - } - } - e.c = 0 - e.e.WriteMapEnd() -} -func (e *encoderBincBytes) fastpathEncMapIntIntR(f *encFnInfo, rv reflect.Value) { - fastpathETBincBytes{}.EncMapIntIntV(rv2i(rv).(map[int]int), e) -} -func (fastpathETBincBytes) EncMapIntIntV(v map[int]int, e *encoderBincBytes) { - if len(v) == 0 { - e.e.WriteMapEmpty() - return - } - var i uint - e.mapStart(len(v)) - if e.h.Canonical { - v2 := make([]int, len(v)) - for k := range v { - v2[i] = k - i++ - } - slices.Sort(v2) - for i, k2 := range v2 { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeInt(int64(k2)) - e.mapElemValue() - e.e.EncodeInt(int64(v[k2])) - } - } else { - i = 0 - for k2, v2 := range v { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeInt(int64(k2)) - e.mapElemValue() - e.e.EncodeInt(int64(v2)) - i++ - } - } - e.c = 0 - e.e.WriteMapEnd() -} -func (e *encoderBincBytes) fastpathEncMapIntInt32R(f *encFnInfo, rv reflect.Value) { - fastpathETBincBytes{}.EncMapIntInt32V(rv2i(rv).(map[int]int32), e) -} -func (fastpathETBincBytes) EncMapIntInt32V(v map[int]int32, e *encoderBincBytes) { - if len(v) == 0 { - e.e.WriteMapEmpty() - return - } - var i uint - e.mapStart(len(v)) - if e.h.Canonical { - v2 := make([]int, len(v)) - for k := range v { - v2[i] = k - i++ - } - slices.Sort(v2) - for i, k2 := range v2 { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeInt(int64(k2)) - e.mapElemValue() - e.e.EncodeInt(int64(v[k2])) - } - } else { - i = 0 - for k2, v2 := range v { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeInt(int64(k2)) - e.mapElemValue() - e.e.EncodeInt(int64(v2)) - i++ - } - } - e.c = 0 - e.e.WriteMapEnd() -} -func (e *encoderBincBytes) fastpathEncMapIntFloat64R(f *encFnInfo, rv reflect.Value) { - fastpathETBincBytes{}.EncMapIntFloat64V(rv2i(rv).(map[int]float64), e) -} -func (fastpathETBincBytes) EncMapIntFloat64V(v map[int]float64, e *encoderBincBytes) { - if len(v) == 0 { - e.e.WriteMapEmpty() - return - } - var i uint - e.mapStart(len(v)) - if e.h.Canonical { - v2 := make([]int, len(v)) - for k := range v { - v2[i] = k - i++ - } - slices.Sort(v2) - for i, k2 := range v2 { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeInt(int64(k2)) - e.mapElemValue() - e.e.EncodeFloat64(v[k2]) - } - } else { - i = 0 - for k2, v2 := range v { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeInt(int64(k2)) - e.mapElemValue() - e.e.EncodeFloat64(v2) - i++ - } - } - e.c = 0 - e.e.WriteMapEnd() -} -func (e *encoderBincBytes) fastpathEncMapIntBoolR(f *encFnInfo, rv reflect.Value) { - fastpathETBincBytes{}.EncMapIntBoolV(rv2i(rv).(map[int]bool), e) -} -func (fastpathETBincBytes) EncMapIntBoolV(v map[int]bool, e *encoderBincBytes) { - if len(v) == 0 { - e.e.WriteMapEmpty() - return - } - var i uint - e.mapStart(len(v)) - if e.h.Canonical { - v2 := make([]int, len(v)) - for k := range v { - v2[i] = k - i++ - } - slices.Sort(v2) - for i, k2 := range v2 { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeInt(int64(k2)) - e.mapElemValue() - e.e.EncodeBool(v[k2]) - } - } else { - i = 0 - for k2, v2 := range v { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeInt(int64(k2)) - e.mapElemValue() - e.e.EncodeBool(v2) - i++ - } - } - e.c = 0 - e.e.WriteMapEnd() -} -func (e *encoderBincBytes) fastpathEncMapInt32IntfR(f *encFnInfo, rv reflect.Value) { - fastpathETBincBytes{}.EncMapInt32IntfV(rv2i(rv).(map[int32]interface{}), e) -} -func (fastpathETBincBytes) EncMapInt32IntfV(v map[int32]interface{}, e *encoderBincBytes) { - if len(v) == 0 { - e.e.WriteMapEmpty() - return - } - var i uint - e.mapStart(len(v)) - if e.h.Canonical { - v2 := make([]int32, len(v)) - for k := range v { - v2[i] = k - i++ - } - slices.Sort(v2) - for i, k2 := range v2 { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeInt(int64(k2)) - e.mapElemValue() - if !e.encodeBuiltin(v[k2]) { - e.encodeR(reflect.ValueOf(v[k2])) - } - } - } else { - i = 0 - for k2, v2 := range v { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeInt(int64(k2)) - e.mapElemValue() - if !e.encodeBuiltin(v2) { - e.encodeR(reflect.ValueOf(v2)) - } - i++ - } - } - e.c = 0 - e.e.WriteMapEnd() -} -func (e *encoderBincBytes) fastpathEncMapInt32StringR(f *encFnInfo, rv reflect.Value) { - fastpathETBincBytes{}.EncMapInt32StringV(rv2i(rv).(map[int32]string), e) -} -func (fastpathETBincBytes) EncMapInt32StringV(v map[int32]string, e *encoderBincBytes) { - if len(v) == 0 { - e.e.WriteMapEmpty() - return - } - var i uint - e.mapStart(len(v)) - if e.h.Canonical { - v2 := make([]int32, len(v)) - for k := range v { - v2[i] = k - i++ - } - slices.Sort(v2) - for i, k2 := range v2 { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeInt(int64(k2)) - e.mapElemValue() - e.e.EncodeString(v[k2]) - } - } else { - i = 0 - for k2, v2 := range v { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeInt(int64(k2)) - e.mapElemValue() - e.e.EncodeString(v2) - i++ - } - } - e.c = 0 - e.e.WriteMapEnd() -} -func (e *encoderBincBytes) fastpathEncMapInt32BytesR(f *encFnInfo, rv reflect.Value) { - fastpathETBincBytes{}.EncMapInt32BytesV(rv2i(rv).(map[int32][]byte), e) -} -func (fastpathETBincBytes) EncMapInt32BytesV(v map[int32][]byte, e *encoderBincBytes) { - if len(v) == 0 { - e.e.WriteMapEmpty() - return - } - var i uint - e.mapStart(len(v)) - if e.h.Canonical { - v2 := make([]int32, len(v)) - for k := range v { - v2[i] = k - i++ - } - slices.Sort(v2) - for i, k2 := range v2 { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeInt(int64(k2)) - e.mapElemValue() - e.e.EncodeBytes(v[k2]) - } - } else { - i = 0 - for k2, v2 := range v { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeInt(int64(k2)) - e.mapElemValue() - e.e.EncodeBytes(v2) - i++ - } - } - e.c = 0 - e.e.WriteMapEnd() -} -func (e *encoderBincBytes) fastpathEncMapInt32Uint8R(f *encFnInfo, rv reflect.Value) { - fastpathETBincBytes{}.EncMapInt32Uint8V(rv2i(rv).(map[int32]uint8), e) -} -func (fastpathETBincBytes) EncMapInt32Uint8V(v map[int32]uint8, e *encoderBincBytes) { - if len(v) == 0 { - e.e.WriteMapEmpty() - return - } - var i uint - e.mapStart(len(v)) - if e.h.Canonical { - v2 := make([]int32, len(v)) - for k := range v { - v2[i] = k - i++ - } - slices.Sort(v2) - for i, k2 := range v2 { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeInt(int64(k2)) - e.mapElemValue() - e.e.EncodeUint(uint64(v[k2])) - } - } else { - i = 0 - for k2, v2 := range v { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeInt(int64(k2)) - e.mapElemValue() - e.e.EncodeUint(uint64(v2)) - i++ - } - } - e.c = 0 - e.e.WriteMapEnd() -} -func (e *encoderBincBytes) fastpathEncMapInt32Uint64R(f *encFnInfo, rv reflect.Value) { - fastpathETBincBytes{}.EncMapInt32Uint64V(rv2i(rv).(map[int32]uint64), e) -} -func (fastpathETBincBytes) EncMapInt32Uint64V(v map[int32]uint64, e *encoderBincBytes) { - if len(v) == 0 { - e.e.WriteMapEmpty() - return - } - var i uint - e.mapStart(len(v)) - if e.h.Canonical { - v2 := make([]int32, len(v)) - for k := range v { - v2[i] = k - i++ - } - slices.Sort(v2) - for i, k2 := range v2 { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeInt(int64(k2)) - e.mapElemValue() - e.e.EncodeUint(v[k2]) - } - } else { - i = 0 - for k2, v2 := range v { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeInt(int64(k2)) - e.mapElemValue() - e.e.EncodeUint(v2) - i++ - } - } - e.c = 0 - e.e.WriteMapEnd() -} -func (e *encoderBincBytes) fastpathEncMapInt32IntR(f *encFnInfo, rv reflect.Value) { - fastpathETBincBytes{}.EncMapInt32IntV(rv2i(rv).(map[int32]int), e) -} -func (fastpathETBincBytes) EncMapInt32IntV(v map[int32]int, e *encoderBincBytes) { - if len(v) == 0 { - e.e.WriteMapEmpty() - return - } - var i uint - e.mapStart(len(v)) - if e.h.Canonical { - v2 := make([]int32, len(v)) - for k := range v { - v2[i] = k - i++ - } - slices.Sort(v2) - for i, k2 := range v2 { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeInt(int64(k2)) - e.mapElemValue() - e.e.EncodeInt(int64(v[k2])) - } - } else { - i = 0 - for k2, v2 := range v { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeInt(int64(k2)) - e.mapElemValue() - e.e.EncodeInt(int64(v2)) - i++ - } - } - e.c = 0 - e.e.WriteMapEnd() -} -func (e *encoderBincBytes) fastpathEncMapInt32Int32R(f *encFnInfo, rv reflect.Value) { - fastpathETBincBytes{}.EncMapInt32Int32V(rv2i(rv).(map[int32]int32), e) -} -func (fastpathETBincBytes) EncMapInt32Int32V(v map[int32]int32, e *encoderBincBytes) { - if len(v) == 0 { - e.e.WriteMapEmpty() - return - } - var i uint - e.mapStart(len(v)) - if e.h.Canonical { - v2 := make([]int32, len(v)) - for k := range v { - v2[i] = k - i++ - } - slices.Sort(v2) - for i, k2 := range v2 { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeInt(int64(k2)) - e.mapElemValue() - e.e.EncodeInt(int64(v[k2])) - } - } else { - i = 0 - for k2, v2 := range v { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeInt(int64(k2)) - e.mapElemValue() - e.e.EncodeInt(int64(v2)) - i++ - } - } - e.c = 0 - e.e.WriteMapEnd() -} -func (e *encoderBincBytes) fastpathEncMapInt32Float64R(f *encFnInfo, rv reflect.Value) { - fastpathETBincBytes{}.EncMapInt32Float64V(rv2i(rv).(map[int32]float64), e) -} -func (fastpathETBincBytes) EncMapInt32Float64V(v map[int32]float64, e *encoderBincBytes) { - if len(v) == 0 { - e.e.WriteMapEmpty() - return - } - var i uint - e.mapStart(len(v)) - if e.h.Canonical { - v2 := make([]int32, len(v)) - for k := range v { - v2[i] = k - i++ - } - slices.Sort(v2) - for i, k2 := range v2 { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeInt(int64(k2)) - e.mapElemValue() - e.e.EncodeFloat64(v[k2]) - } - } else { - i = 0 - for k2, v2 := range v { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeInt(int64(k2)) - e.mapElemValue() - e.e.EncodeFloat64(v2) - i++ - } - } - e.c = 0 - e.e.WriteMapEnd() -} -func (e *encoderBincBytes) fastpathEncMapInt32BoolR(f *encFnInfo, rv reflect.Value) { - fastpathETBincBytes{}.EncMapInt32BoolV(rv2i(rv).(map[int32]bool), e) -} -func (fastpathETBincBytes) EncMapInt32BoolV(v map[int32]bool, e *encoderBincBytes) { - if len(v) == 0 { - e.e.WriteMapEmpty() - return - } - var i uint - e.mapStart(len(v)) - if e.h.Canonical { - v2 := make([]int32, len(v)) - for k := range v { - v2[i] = k - i++ - } - slices.Sort(v2) - for i, k2 := range v2 { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeInt(int64(k2)) - e.mapElemValue() - e.e.EncodeBool(v[k2]) - } - } else { - i = 0 - for k2, v2 := range v { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeInt(int64(k2)) - e.mapElemValue() - e.e.EncodeBool(v2) - i++ - } - } - e.c = 0 - e.e.WriteMapEnd() -} - -func (helperDecDriverBincBytes) fastpathDecodeTypeSwitch(iv interface{}, d *decoderBincBytes) bool { - var ft fastpathDTBincBytes - var changed bool - var containerLen int - switch v := iv.(type) { - case []interface{}: - ft.DecSliceIntfN(v, d) - case *[]interface{}: - var v2 []interface{} - if v2, changed = ft.DecSliceIntfY(*v, d); changed { - *v = v2 - } - case []string: - ft.DecSliceStringN(v, d) - case *[]string: - var v2 []string - if v2, changed = ft.DecSliceStringY(*v, d); changed { - *v = v2 - } - case [][]byte: - ft.DecSliceBytesN(v, d) - case *[][]byte: - var v2 [][]byte - if v2, changed = ft.DecSliceBytesY(*v, d); changed { - *v = v2 - } - case []float32: - ft.DecSliceFloat32N(v, d) - case *[]float32: - var v2 []float32 - if v2, changed = ft.DecSliceFloat32Y(*v, d); changed { - *v = v2 - } - case []float64: - ft.DecSliceFloat64N(v, d) - case *[]float64: - var v2 []float64 - if v2, changed = ft.DecSliceFloat64Y(*v, d); changed { - *v = v2 - } - case []uint8: - ft.DecSliceUint8N(v, d) - case *[]uint8: - var v2 []uint8 - if v2, changed = ft.DecSliceUint8Y(*v, d); changed { - *v = v2 - } - case []uint64: - ft.DecSliceUint64N(v, d) - case *[]uint64: - var v2 []uint64 - if v2, changed = ft.DecSliceUint64Y(*v, d); changed { - *v = v2 - } - case []int: - ft.DecSliceIntN(v, d) - case *[]int: - var v2 []int - if v2, changed = ft.DecSliceIntY(*v, d); changed { - *v = v2 - } - case []int32: - ft.DecSliceInt32N(v, d) - case *[]int32: - var v2 []int32 - if v2, changed = ft.DecSliceInt32Y(*v, d); changed { - *v = v2 - } - case []int64: - ft.DecSliceInt64N(v, d) - case *[]int64: - var v2 []int64 - if v2, changed = ft.DecSliceInt64Y(*v, d); changed { - *v = v2 - } - case []bool: - ft.DecSliceBoolN(v, d) - case *[]bool: - var v2 []bool - if v2, changed = ft.DecSliceBoolY(*v, d); changed { - *v = v2 - } - case map[string]interface{}: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen != containerLenNil { - if containerLen != 0 { - ft.DecMapStringIntfL(v, containerLen, d) - } - d.mapEnd() - } - case *map[string]interface{}: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen == containerLenNil { - *v = nil - } else { - if *v == nil { - *v = make(map[string]interface{}, decInferLen(containerLen, d.maxInitLen(), 32)) - } - if containerLen != 0 { - ft.DecMapStringIntfL(*v, containerLen, d) - } - d.mapEnd() - } - case map[string]string: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen != containerLenNil { - if containerLen != 0 { - ft.DecMapStringStringL(v, containerLen, d) - } - d.mapEnd() - } - case *map[string]string: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen == containerLenNil { - *v = nil - } else { - if *v == nil { - *v = make(map[string]string, decInferLen(containerLen, d.maxInitLen(), 32)) - } - if containerLen != 0 { - ft.DecMapStringStringL(*v, containerLen, d) - } - d.mapEnd() - } - case map[string][]byte: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen != containerLenNil { - if containerLen != 0 { - ft.DecMapStringBytesL(v, containerLen, d) - } - d.mapEnd() - } - case *map[string][]byte: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen == containerLenNil { - *v = nil - } else { - if *v == nil { - *v = make(map[string][]byte, decInferLen(containerLen, d.maxInitLen(), 40)) - } - if containerLen != 0 { - ft.DecMapStringBytesL(*v, containerLen, d) - } - d.mapEnd() - } - case map[string]uint8: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen != containerLenNil { - if containerLen != 0 { - ft.DecMapStringUint8L(v, containerLen, d) - } - d.mapEnd() - } - case *map[string]uint8: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen == containerLenNil { - *v = nil - } else { - if *v == nil { - *v = make(map[string]uint8, decInferLen(containerLen, d.maxInitLen(), 17)) - } - if containerLen != 0 { - ft.DecMapStringUint8L(*v, containerLen, d) - } - d.mapEnd() - } - case map[string]uint64: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen != containerLenNil { - if containerLen != 0 { - ft.DecMapStringUint64L(v, containerLen, d) - } - d.mapEnd() - } - case *map[string]uint64: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen == containerLenNil { - *v = nil - } else { - if *v == nil { - *v = make(map[string]uint64, decInferLen(containerLen, d.maxInitLen(), 24)) - } - if containerLen != 0 { - ft.DecMapStringUint64L(*v, containerLen, d) - } - d.mapEnd() - } - case map[string]int: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen != containerLenNil { - if containerLen != 0 { - ft.DecMapStringIntL(v, containerLen, d) - } - d.mapEnd() - } - case *map[string]int: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen == containerLenNil { - *v = nil - } else { - if *v == nil { - *v = make(map[string]int, decInferLen(containerLen, d.maxInitLen(), 24)) - } - if containerLen != 0 { - ft.DecMapStringIntL(*v, containerLen, d) - } - d.mapEnd() - } - case map[string]int32: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen != containerLenNil { - if containerLen != 0 { - ft.DecMapStringInt32L(v, containerLen, d) - } - d.mapEnd() - } - case *map[string]int32: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen == containerLenNil { - *v = nil - } else { - if *v == nil { - *v = make(map[string]int32, decInferLen(containerLen, d.maxInitLen(), 20)) - } - if containerLen != 0 { - ft.DecMapStringInt32L(*v, containerLen, d) - } - d.mapEnd() - } - case map[string]float64: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen != containerLenNil { - if containerLen != 0 { - ft.DecMapStringFloat64L(v, containerLen, d) - } - d.mapEnd() - } - case *map[string]float64: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen == containerLenNil { - *v = nil - } else { - if *v == nil { - *v = make(map[string]float64, decInferLen(containerLen, d.maxInitLen(), 24)) - } - if containerLen != 0 { - ft.DecMapStringFloat64L(*v, containerLen, d) - } - d.mapEnd() - } - case map[string]bool: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen != containerLenNil { - if containerLen != 0 { - ft.DecMapStringBoolL(v, containerLen, d) - } - d.mapEnd() - } - case *map[string]bool: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen == containerLenNil { - *v = nil - } else { - if *v == nil { - *v = make(map[string]bool, decInferLen(containerLen, d.maxInitLen(), 17)) - } - if containerLen != 0 { - ft.DecMapStringBoolL(*v, containerLen, d) - } - d.mapEnd() - } - case map[uint8]interface{}: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen != containerLenNil { - if containerLen != 0 { - ft.DecMapUint8IntfL(v, containerLen, d) - } - d.mapEnd() - } - case *map[uint8]interface{}: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen == containerLenNil { - *v = nil - } else { - if *v == nil { - *v = make(map[uint8]interface{}, decInferLen(containerLen, d.maxInitLen(), 17)) - } - if containerLen != 0 { - ft.DecMapUint8IntfL(*v, containerLen, d) - } - d.mapEnd() - } - case map[uint8]string: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen != containerLenNil { - if containerLen != 0 { - ft.DecMapUint8StringL(v, containerLen, d) - } - d.mapEnd() - } - case *map[uint8]string: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen == containerLenNil { - *v = nil - } else { - if *v == nil { - *v = make(map[uint8]string, decInferLen(containerLen, d.maxInitLen(), 17)) - } - if containerLen != 0 { - ft.DecMapUint8StringL(*v, containerLen, d) - } - d.mapEnd() - } - case map[uint8][]byte: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen != containerLenNil { - if containerLen != 0 { - ft.DecMapUint8BytesL(v, containerLen, d) - } - d.mapEnd() - } - case *map[uint8][]byte: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen == containerLenNil { - *v = nil - } else { - if *v == nil { - *v = make(map[uint8][]byte, decInferLen(containerLen, d.maxInitLen(), 25)) - } - if containerLen != 0 { - ft.DecMapUint8BytesL(*v, containerLen, d) - } - d.mapEnd() - } - case map[uint8]uint8: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen != containerLenNil { - if containerLen != 0 { - ft.DecMapUint8Uint8L(v, containerLen, d) - } - d.mapEnd() - } - case *map[uint8]uint8: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen == containerLenNil { - *v = nil - } else { - if *v == nil { - *v = make(map[uint8]uint8, decInferLen(containerLen, d.maxInitLen(), 2)) - } - if containerLen != 0 { - ft.DecMapUint8Uint8L(*v, containerLen, d) - } - d.mapEnd() - } - case map[uint8]uint64: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen != containerLenNil { - if containerLen != 0 { - ft.DecMapUint8Uint64L(v, containerLen, d) - } - d.mapEnd() - } - case *map[uint8]uint64: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen == containerLenNil { - *v = nil - } else { - if *v == nil { - *v = make(map[uint8]uint64, decInferLen(containerLen, d.maxInitLen(), 9)) - } - if containerLen != 0 { - ft.DecMapUint8Uint64L(*v, containerLen, d) - } - d.mapEnd() - } - case map[uint8]int: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen != containerLenNil { - if containerLen != 0 { - ft.DecMapUint8IntL(v, containerLen, d) - } - d.mapEnd() - } - case *map[uint8]int: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen == containerLenNil { - *v = nil - } else { - if *v == nil { - *v = make(map[uint8]int, decInferLen(containerLen, d.maxInitLen(), 9)) - } - if containerLen != 0 { - ft.DecMapUint8IntL(*v, containerLen, d) - } - d.mapEnd() - } - case map[uint8]int32: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen != containerLenNil { - if containerLen != 0 { - ft.DecMapUint8Int32L(v, containerLen, d) - } - d.mapEnd() - } - case *map[uint8]int32: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen == containerLenNil { - *v = nil - } else { - if *v == nil { - *v = make(map[uint8]int32, decInferLen(containerLen, d.maxInitLen(), 5)) - } - if containerLen != 0 { - ft.DecMapUint8Int32L(*v, containerLen, d) - } - d.mapEnd() - } - case map[uint8]float64: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen != containerLenNil { - if containerLen != 0 { - ft.DecMapUint8Float64L(v, containerLen, d) - } - d.mapEnd() - } - case *map[uint8]float64: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen == containerLenNil { - *v = nil - } else { - if *v == nil { - *v = make(map[uint8]float64, decInferLen(containerLen, d.maxInitLen(), 9)) - } - if containerLen != 0 { - ft.DecMapUint8Float64L(*v, containerLen, d) - } - d.mapEnd() - } - case map[uint8]bool: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen != containerLenNil { - if containerLen != 0 { - ft.DecMapUint8BoolL(v, containerLen, d) - } - d.mapEnd() - } - case *map[uint8]bool: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen == containerLenNil { - *v = nil - } else { - if *v == nil { - *v = make(map[uint8]bool, decInferLen(containerLen, d.maxInitLen(), 2)) - } - if containerLen != 0 { - ft.DecMapUint8BoolL(*v, containerLen, d) - } - d.mapEnd() - } - case map[uint64]interface{}: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen != containerLenNil { - if containerLen != 0 { - ft.DecMapUint64IntfL(v, containerLen, d) - } - d.mapEnd() - } - case *map[uint64]interface{}: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen == containerLenNil { - *v = nil - } else { - if *v == nil { - *v = make(map[uint64]interface{}, decInferLen(containerLen, d.maxInitLen(), 24)) - } - if containerLen != 0 { - ft.DecMapUint64IntfL(*v, containerLen, d) - } - d.mapEnd() - } - case map[uint64]string: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen != containerLenNil { - if containerLen != 0 { - ft.DecMapUint64StringL(v, containerLen, d) - } - d.mapEnd() - } - case *map[uint64]string: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen == containerLenNil { - *v = nil - } else { - if *v == nil { - *v = make(map[uint64]string, decInferLen(containerLen, d.maxInitLen(), 24)) - } - if containerLen != 0 { - ft.DecMapUint64StringL(*v, containerLen, d) - } - d.mapEnd() - } - case map[uint64][]byte: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen != containerLenNil { - if containerLen != 0 { - ft.DecMapUint64BytesL(v, containerLen, d) - } - d.mapEnd() - } - case *map[uint64][]byte: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen == containerLenNil { - *v = nil - } else { - if *v == nil { - *v = make(map[uint64][]byte, decInferLen(containerLen, d.maxInitLen(), 32)) - } - if containerLen != 0 { - ft.DecMapUint64BytesL(*v, containerLen, d) - } - d.mapEnd() - } - case map[uint64]uint8: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen != containerLenNil { - if containerLen != 0 { - ft.DecMapUint64Uint8L(v, containerLen, d) - } - d.mapEnd() - } - case *map[uint64]uint8: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen == containerLenNil { - *v = nil - } else { - if *v == nil { - *v = make(map[uint64]uint8, decInferLen(containerLen, d.maxInitLen(), 9)) - } - if containerLen != 0 { - ft.DecMapUint64Uint8L(*v, containerLen, d) - } - d.mapEnd() - } - case map[uint64]uint64: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen != containerLenNil { - if containerLen != 0 { - ft.DecMapUint64Uint64L(v, containerLen, d) - } - d.mapEnd() - } - case *map[uint64]uint64: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen == containerLenNil { - *v = nil - } else { - if *v == nil { - *v = make(map[uint64]uint64, decInferLen(containerLen, d.maxInitLen(), 16)) - } - if containerLen != 0 { - ft.DecMapUint64Uint64L(*v, containerLen, d) - } - d.mapEnd() - } - case map[uint64]int: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen != containerLenNil { - if containerLen != 0 { - ft.DecMapUint64IntL(v, containerLen, d) - } - d.mapEnd() - } - case *map[uint64]int: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen == containerLenNil { - *v = nil - } else { - if *v == nil { - *v = make(map[uint64]int, decInferLen(containerLen, d.maxInitLen(), 16)) - } - if containerLen != 0 { - ft.DecMapUint64IntL(*v, containerLen, d) - } - d.mapEnd() - } - case map[uint64]int32: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen != containerLenNil { - if containerLen != 0 { - ft.DecMapUint64Int32L(v, containerLen, d) - } - d.mapEnd() - } - case *map[uint64]int32: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen == containerLenNil { - *v = nil - } else { - if *v == nil { - *v = make(map[uint64]int32, decInferLen(containerLen, d.maxInitLen(), 12)) - } - if containerLen != 0 { - ft.DecMapUint64Int32L(*v, containerLen, d) - } - d.mapEnd() - } - case map[uint64]float64: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen != containerLenNil { - if containerLen != 0 { - ft.DecMapUint64Float64L(v, containerLen, d) - } - d.mapEnd() - } - case *map[uint64]float64: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen == containerLenNil { - *v = nil - } else { - if *v == nil { - *v = make(map[uint64]float64, decInferLen(containerLen, d.maxInitLen(), 16)) - } - if containerLen != 0 { - ft.DecMapUint64Float64L(*v, containerLen, d) - } - d.mapEnd() - } - case map[uint64]bool: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen != containerLenNil { - if containerLen != 0 { - ft.DecMapUint64BoolL(v, containerLen, d) - } - d.mapEnd() - } - case *map[uint64]bool: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen == containerLenNil { - *v = nil - } else { - if *v == nil { - *v = make(map[uint64]bool, decInferLen(containerLen, d.maxInitLen(), 9)) - } - if containerLen != 0 { - ft.DecMapUint64BoolL(*v, containerLen, d) - } - d.mapEnd() - } - case map[int]interface{}: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen != containerLenNil { - if containerLen != 0 { - ft.DecMapIntIntfL(v, containerLen, d) - } - d.mapEnd() - } - case *map[int]interface{}: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen == containerLenNil { - *v = nil - } else { - if *v == nil { - *v = make(map[int]interface{}, decInferLen(containerLen, d.maxInitLen(), 24)) - } - if containerLen != 0 { - ft.DecMapIntIntfL(*v, containerLen, d) - } - d.mapEnd() - } - case map[int]string: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen != containerLenNil { - if containerLen != 0 { - ft.DecMapIntStringL(v, containerLen, d) - } - d.mapEnd() - } - case *map[int]string: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen == containerLenNil { - *v = nil - } else { - if *v == nil { - *v = make(map[int]string, decInferLen(containerLen, d.maxInitLen(), 24)) - } - if containerLen != 0 { - ft.DecMapIntStringL(*v, containerLen, d) - } - d.mapEnd() - } - case map[int][]byte: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen != containerLenNil { - if containerLen != 0 { - ft.DecMapIntBytesL(v, containerLen, d) - } - d.mapEnd() - } - case *map[int][]byte: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen == containerLenNil { - *v = nil - } else { - if *v == nil { - *v = make(map[int][]byte, decInferLen(containerLen, d.maxInitLen(), 32)) - } - if containerLen != 0 { - ft.DecMapIntBytesL(*v, containerLen, d) - } - d.mapEnd() - } - case map[int]uint8: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen != containerLenNil { - if containerLen != 0 { - ft.DecMapIntUint8L(v, containerLen, d) - } - d.mapEnd() - } - case *map[int]uint8: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen == containerLenNil { - *v = nil - } else { - if *v == nil { - *v = make(map[int]uint8, decInferLen(containerLen, d.maxInitLen(), 9)) - } - if containerLen != 0 { - ft.DecMapIntUint8L(*v, containerLen, d) - } - d.mapEnd() - } - case map[int]uint64: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen != containerLenNil { - if containerLen != 0 { - ft.DecMapIntUint64L(v, containerLen, d) - } - d.mapEnd() - } - case *map[int]uint64: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen == containerLenNil { - *v = nil - } else { - if *v == nil { - *v = make(map[int]uint64, decInferLen(containerLen, d.maxInitLen(), 16)) - } - if containerLen != 0 { - ft.DecMapIntUint64L(*v, containerLen, d) - } - d.mapEnd() - } - case map[int]int: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen != containerLenNil { - if containerLen != 0 { - ft.DecMapIntIntL(v, containerLen, d) - } - d.mapEnd() - } - case *map[int]int: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen == containerLenNil { - *v = nil - } else { - if *v == nil { - *v = make(map[int]int, decInferLen(containerLen, d.maxInitLen(), 16)) - } - if containerLen != 0 { - ft.DecMapIntIntL(*v, containerLen, d) - } - d.mapEnd() - } - case map[int]int32: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen != containerLenNil { - if containerLen != 0 { - ft.DecMapIntInt32L(v, containerLen, d) - } - d.mapEnd() - } - case *map[int]int32: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen == containerLenNil { - *v = nil - } else { - if *v == nil { - *v = make(map[int]int32, decInferLen(containerLen, d.maxInitLen(), 12)) - } - if containerLen != 0 { - ft.DecMapIntInt32L(*v, containerLen, d) - } - d.mapEnd() - } - case map[int]float64: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen != containerLenNil { - if containerLen != 0 { - ft.DecMapIntFloat64L(v, containerLen, d) - } - d.mapEnd() - } - case *map[int]float64: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen == containerLenNil { - *v = nil - } else { - if *v == nil { - *v = make(map[int]float64, decInferLen(containerLen, d.maxInitLen(), 16)) - } - if containerLen != 0 { - ft.DecMapIntFloat64L(*v, containerLen, d) - } - d.mapEnd() - } - case map[int]bool: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen != containerLenNil { - if containerLen != 0 { - ft.DecMapIntBoolL(v, containerLen, d) - } - d.mapEnd() - } - case *map[int]bool: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen == containerLenNil { - *v = nil - } else { - if *v == nil { - *v = make(map[int]bool, decInferLen(containerLen, d.maxInitLen(), 9)) - } - if containerLen != 0 { - ft.DecMapIntBoolL(*v, containerLen, d) - } - d.mapEnd() - } - case map[int32]interface{}: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen != containerLenNil { - if containerLen != 0 { - ft.DecMapInt32IntfL(v, containerLen, d) - } - d.mapEnd() - } - case *map[int32]interface{}: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen == containerLenNil { - *v = nil - } else { - if *v == nil { - *v = make(map[int32]interface{}, decInferLen(containerLen, d.maxInitLen(), 20)) - } - if containerLen != 0 { - ft.DecMapInt32IntfL(*v, containerLen, d) - } - d.mapEnd() - } - case map[int32]string: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen != containerLenNil { - if containerLen != 0 { - ft.DecMapInt32StringL(v, containerLen, d) - } - d.mapEnd() - } - case *map[int32]string: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen == containerLenNil { - *v = nil - } else { - if *v == nil { - *v = make(map[int32]string, decInferLen(containerLen, d.maxInitLen(), 20)) - } - if containerLen != 0 { - ft.DecMapInt32StringL(*v, containerLen, d) - } - d.mapEnd() - } - case map[int32][]byte: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen != containerLenNil { - if containerLen != 0 { - ft.DecMapInt32BytesL(v, containerLen, d) - } - d.mapEnd() - } - case *map[int32][]byte: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen == containerLenNil { - *v = nil - } else { - if *v == nil { - *v = make(map[int32][]byte, decInferLen(containerLen, d.maxInitLen(), 28)) - } - if containerLen != 0 { - ft.DecMapInt32BytesL(*v, containerLen, d) - } - d.mapEnd() - } - case map[int32]uint8: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen != containerLenNil { - if containerLen != 0 { - ft.DecMapInt32Uint8L(v, containerLen, d) - } - d.mapEnd() - } - case *map[int32]uint8: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen == containerLenNil { - *v = nil - } else { - if *v == nil { - *v = make(map[int32]uint8, decInferLen(containerLen, d.maxInitLen(), 5)) - } - if containerLen != 0 { - ft.DecMapInt32Uint8L(*v, containerLen, d) - } - d.mapEnd() - } - case map[int32]uint64: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen != containerLenNil { - if containerLen != 0 { - ft.DecMapInt32Uint64L(v, containerLen, d) - } - d.mapEnd() - } - case *map[int32]uint64: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen == containerLenNil { - *v = nil - } else { - if *v == nil { - *v = make(map[int32]uint64, decInferLen(containerLen, d.maxInitLen(), 12)) - } - if containerLen != 0 { - ft.DecMapInt32Uint64L(*v, containerLen, d) - } - d.mapEnd() - } - case map[int32]int: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen != containerLenNil { - if containerLen != 0 { - ft.DecMapInt32IntL(v, containerLen, d) - } - d.mapEnd() - } - case *map[int32]int: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen == containerLenNil { - *v = nil - } else { - if *v == nil { - *v = make(map[int32]int, decInferLen(containerLen, d.maxInitLen(), 12)) - } - if containerLen != 0 { - ft.DecMapInt32IntL(*v, containerLen, d) - } - d.mapEnd() - } - case map[int32]int32: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen != containerLenNil { - if containerLen != 0 { - ft.DecMapInt32Int32L(v, containerLen, d) - } - d.mapEnd() - } - case *map[int32]int32: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen == containerLenNil { - *v = nil - } else { - if *v == nil { - *v = make(map[int32]int32, decInferLen(containerLen, d.maxInitLen(), 8)) - } - if containerLen != 0 { - ft.DecMapInt32Int32L(*v, containerLen, d) - } - d.mapEnd() - } - case map[int32]float64: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen != containerLenNil { - if containerLen != 0 { - ft.DecMapInt32Float64L(v, containerLen, d) - } - d.mapEnd() - } - case *map[int32]float64: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen == containerLenNil { - *v = nil - } else { - if *v == nil { - *v = make(map[int32]float64, decInferLen(containerLen, d.maxInitLen(), 12)) - } - if containerLen != 0 { - ft.DecMapInt32Float64L(*v, containerLen, d) - } - d.mapEnd() - } - case map[int32]bool: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen != containerLenNil { - if containerLen != 0 { - ft.DecMapInt32BoolL(v, containerLen, d) - } - d.mapEnd() - } - case *map[int32]bool: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen == containerLenNil { - *v = nil - } else { - if *v == nil { - *v = make(map[int32]bool, decInferLen(containerLen, d.maxInitLen(), 5)) - } - if containerLen != 0 { - ft.DecMapInt32BoolL(*v, containerLen, d) - } - d.mapEnd() - } - default: - _ = v - return false - } - return true -} - -func (d *decoderBincBytes) fastpathDecSliceIntfR(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTBincBytes - switch rv.Kind() { - case reflect.Ptr: - v := rv2i(rv).(*[]interface{}) - if vv, changed := ft.DecSliceIntfY(*v, d); changed { - *v = vv - } - case reflect.Array: - var v []interface{} - rvGetSlice4Array(rv, &v) - ft.DecSliceIntfN(v, d) - default: - ft.DecSliceIntfN(rv2i(rv).([]interface{}), d) - } -} -func (fastpathDTBincBytes) DecSliceIntfY(v []interface{}, d *decoderBincBytes) (v2 []interface{}, changed bool) { - ctyp := d.d.ContainerType() - if ctyp == valueTypeNil { - return nil, v != nil - } - var containerLenS int - isArray := ctyp == valueTypeArray - if isArray { - containerLenS = d.arrayStart(d.d.ReadArrayStart()) - } else if ctyp == valueTypeMap { - containerLenS = d.mapStart(d.d.ReadMapStart()) * 2 - } else { - halt.errorStr2("decoding into a slice, expect map/array - got ", ctyp.String()) - } - hasLen := containerLenS >= 0 - var j int - fnv := func(dst []interface{}) { v, changed = dst, true } - for ; d.containerNext(j, containerLenS, hasLen); j++ { - if j == 0 { - if containerLenS == len(v) { - } else if containerLenS < 0 || containerLenS > cap(v) { - if xlen := int(decInferLen(containerLenS, d.maxInitLen(), 16)); xlen <= cap(v) { - fnv(v[:uint(xlen)]) - } else { - v2 = make([]interface{}, uint(xlen)) - copy(v2, v) - fnv(v2) - } - } else { - fnv(v[:containerLenS]) - } - } - if isArray { - d.arrayElem(j == 0) - } else if j&1 == 0 { - d.mapElemKey(j == 0) - } else { - d.mapElemValue() - } - if j >= len(v) { - fnv(append(v, nil)) - } - d.decode(&v[uint(j)]) - } - if j < len(v) { - fnv(v[:uint(j)]) - } else if j == 0 && v == nil { - fnv([]interface{}{}) - } - if isArray { - d.arrayEnd() - } else { - d.mapEnd() - } - return v, changed -} -func (fastpathDTBincBytes) DecSliceIntfN(v []interface{}, d *decoderBincBytes) { - ctyp := d.d.ContainerType() - if ctyp == valueTypeNil { - return - } - var containerLenS int - isArray := ctyp == valueTypeArray - if isArray { - containerLenS = d.arrayStart(d.d.ReadArrayStart()) - } else if ctyp == valueTypeMap { - containerLenS = d.mapStart(d.d.ReadMapStart()) * 2 - } else { - halt.errorStr2("decoding into a slice, expect map/array - got ", ctyp.String()) - } - hasLen := containerLenS >= 0 - for j := 0; d.containerNext(j, containerLenS, hasLen); j++ { - if isArray { - d.arrayElem(j == 0) - } else if j&1 == 0 { - d.mapElemKey(j == 0) - } else { - d.mapElemValue() - } - if j < len(v) { - d.decode(&v[uint(j)]) - } else { - d.arrayCannotExpand(len(v), j+1) - d.swallow() - } - } - if isArray { - d.arrayEnd() - } else { - d.mapEnd() - } -} - -func (d *decoderBincBytes) fastpathDecSliceStringR(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTBincBytes - switch rv.Kind() { - case reflect.Ptr: - v := rv2i(rv).(*[]string) - if vv, changed := ft.DecSliceStringY(*v, d); changed { - *v = vv - } - case reflect.Array: - var v []string - rvGetSlice4Array(rv, &v) - ft.DecSliceStringN(v, d) - default: - ft.DecSliceStringN(rv2i(rv).([]string), d) - } -} -func (fastpathDTBincBytes) DecSliceStringY(v []string, d *decoderBincBytes) (v2 []string, changed bool) { - ctyp := d.d.ContainerType() - if ctyp == valueTypeNil { - return nil, v != nil - } - var containerLenS int - isArray := ctyp == valueTypeArray - if isArray { - containerLenS = d.arrayStart(d.d.ReadArrayStart()) - } else if ctyp == valueTypeMap { - containerLenS = d.mapStart(d.d.ReadMapStart()) * 2 - } else { - halt.errorStr2("decoding into a slice, expect map/array - got ", ctyp.String()) - } - hasLen := containerLenS >= 0 - var j int - fnv := func(dst []string) { v, changed = dst, true } - for ; d.containerNext(j, containerLenS, hasLen); j++ { - if j == 0 { - if containerLenS == len(v) { - } else if containerLenS < 0 || containerLenS > cap(v) { - if xlen := int(decInferLen(containerLenS, d.maxInitLen(), 16)); xlen <= cap(v) { - fnv(v[:uint(xlen)]) - } else { - v2 = make([]string, uint(xlen)) - copy(v2, v) - fnv(v2) - } - } else { - fnv(v[:containerLenS]) - } - } - if isArray { - d.arrayElem(j == 0) - } else if j&1 == 0 { - d.mapElemKey(j == 0) - } else { - d.mapElemValue() - } - if j >= len(v) { - fnv(append(v, "")) - } - v[uint(j)] = d.detach2Str(d.d.DecodeStringAsBytes()) - } - if j < len(v) { - fnv(v[:uint(j)]) - } else if j == 0 && v == nil { - fnv([]string{}) - } - if isArray { - d.arrayEnd() - } else { - d.mapEnd() - } - return v, changed -} -func (fastpathDTBincBytes) DecSliceStringN(v []string, d *decoderBincBytes) { - ctyp := d.d.ContainerType() - if ctyp == valueTypeNil { - return - } - var containerLenS int - isArray := ctyp == valueTypeArray - if isArray { - containerLenS = d.arrayStart(d.d.ReadArrayStart()) - } else if ctyp == valueTypeMap { - containerLenS = d.mapStart(d.d.ReadMapStart()) * 2 - } else { - halt.errorStr2("decoding into a slice, expect map/array - got ", ctyp.String()) - } - hasLen := containerLenS >= 0 - for j := 0; d.containerNext(j, containerLenS, hasLen); j++ { - if isArray { - d.arrayElem(j == 0) - } else if j&1 == 0 { - d.mapElemKey(j == 0) - } else { - d.mapElemValue() - } - if j < len(v) { - v[uint(j)] = d.detach2Str(d.d.DecodeStringAsBytes()) - } else { - d.arrayCannotExpand(len(v), j+1) - d.swallow() - } - } - if isArray { - d.arrayEnd() - } else { - d.mapEnd() - } -} - -func (d *decoderBincBytes) fastpathDecSliceBytesR(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTBincBytes - switch rv.Kind() { - case reflect.Ptr: - v := rv2i(rv).(*[][]byte) - if vv, changed := ft.DecSliceBytesY(*v, d); changed { - *v = vv - } - case reflect.Array: - var v [][]byte - rvGetSlice4Array(rv, &v) - ft.DecSliceBytesN(v, d) - default: - ft.DecSliceBytesN(rv2i(rv).([][]byte), d) - } -} -func (fastpathDTBincBytes) DecSliceBytesY(v [][]byte, d *decoderBincBytes) (v2 [][]byte, changed bool) { - ctyp := d.d.ContainerType() - if ctyp == valueTypeNil { - return nil, v != nil - } - var containerLenS int - isArray := ctyp == valueTypeArray - if isArray { - containerLenS = d.arrayStart(d.d.ReadArrayStart()) - } else if ctyp == valueTypeMap { - containerLenS = d.mapStart(d.d.ReadMapStart()) * 2 - } else { - halt.errorStr2("decoding into a slice, expect map/array - got ", ctyp.String()) - } - hasLen := containerLenS >= 0 - var j int - fnv := func(dst [][]byte) { v, changed = dst, true } - for ; d.containerNext(j, containerLenS, hasLen); j++ { - if j == 0 { - if containerLenS == len(v) { - } else if containerLenS < 0 || containerLenS > cap(v) { - if xlen := int(decInferLen(containerLenS, d.maxInitLen(), 24)); xlen <= cap(v) { - fnv(v[:uint(xlen)]) - } else { - v2 = make([][]byte, uint(xlen)) - copy(v2, v) - fnv(v2) - } - } else { - fnv(v[:containerLenS]) - } - } - if isArray { - d.arrayElem(j == 0) - } else if j&1 == 0 { - d.mapElemKey(j == 0) - } else { - d.mapElemValue() - } - if j >= len(v) { - fnv(append(v, nil)) - } - v[uint(j)] = bytesOKdbi(d.decodeBytesInto(v[uint(j)], false)) - } - if j < len(v) { - fnv(v[:uint(j)]) - } else if j == 0 && v == nil { - fnv([][]byte{}) - } - if isArray { - d.arrayEnd() - } else { - d.mapEnd() - } - return v, changed -} -func (fastpathDTBincBytes) DecSliceBytesN(v [][]byte, d *decoderBincBytes) { - ctyp := d.d.ContainerType() - if ctyp == valueTypeNil { - return - } - var containerLenS int - isArray := ctyp == valueTypeArray - if isArray { - containerLenS = d.arrayStart(d.d.ReadArrayStart()) - } else if ctyp == valueTypeMap { - containerLenS = d.mapStart(d.d.ReadMapStart()) * 2 - } else { - halt.errorStr2("decoding into a slice, expect map/array - got ", ctyp.String()) - } - hasLen := containerLenS >= 0 - for j := 0; d.containerNext(j, containerLenS, hasLen); j++ { - if isArray { - d.arrayElem(j == 0) - } else if j&1 == 0 { - d.mapElemKey(j == 0) - } else { - d.mapElemValue() - } - if j < len(v) { - v[uint(j)] = bytesOKdbi(d.decodeBytesInto(v[uint(j)], false)) - } else { - d.arrayCannotExpand(len(v), j+1) - d.swallow() - } - } - if isArray { - d.arrayEnd() - } else { - d.mapEnd() - } -} - -func (d *decoderBincBytes) fastpathDecSliceFloat32R(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTBincBytes - switch rv.Kind() { - case reflect.Ptr: - v := rv2i(rv).(*[]float32) - if vv, changed := ft.DecSliceFloat32Y(*v, d); changed { - *v = vv - } - case reflect.Array: - var v []float32 - rvGetSlice4Array(rv, &v) - ft.DecSliceFloat32N(v, d) - default: - ft.DecSliceFloat32N(rv2i(rv).([]float32), d) - } -} -func (fastpathDTBincBytes) DecSliceFloat32Y(v []float32, d *decoderBincBytes) (v2 []float32, changed bool) { - ctyp := d.d.ContainerType() - if ctyp == valueTypeNil { - return nil, v != nil - } - var containerLenS int - isArray := ctyp == valueTypeArray - if isArray { - containerLenS = d.arrayStart(d.d.ReadArrayStart()) - } else if ctyp == valueTypeMap { - containerLenS = d.mapStart(d.d.ReadMapStart()) * 2 - } else { - halt.errorStr2("decoding into a slice, expect map/array - got ", ctyp.String()) - } - hasLen := containerLenS >= 0 - var j int - fnv := func(dst []float32) { v, changed = dst, true } - for ; d.containerNext(j, containerLenS, hasLen); j++ { - if j == 0 { - if containerLenS == len(v) { - } else if containerLenS < 0 || containerLenS > cap(v) { - if xlen := int(decInferLen(containerLenS, d.maxInitLen(), 4)); xlen <= cap(v) { - fnv(v[:uint(xlen)]) - } else { - v2 = make([]float32, uint(xlen)) - copy(v2, v) - fnv(v2) - } - } else { - fnv(v[:containerLenS]) - } - } - if isArray { - d.arrayElem(j == 0) - } else if j&1 == 0 { - d.mapElemKey(j == 0) - } else { - d.mapElemValue() - } - if j >= len(v) { - fnv(append(v, 0)) - } - v[uint(j)] = float32(d.d.DecodeFloat32()) - } - if j < len(v) { - fnv(v[:uint(j)]) - } else if j == 0 && v == nil { - fnv([]float32{}) - } - if isArray { - d.arrayEnd() - } else { - d.mapEnd() - } - return v, changed -} -func (fastpathDTBincBytes) DecSliceFloat32N(v []float32, d *decoderBincBytes) { - ctyp := d.d.ContainerType() - if ctyp == valueTypeNil { - return - } - var containerLenS int - isArray := ctyp == valueTypeArray - if isArray { - containerLenS = d.arrayStart(d.d.ReadArrayStart()) - } else if ctyp == valueTypeMap { - containerLenS = d.mapStart(d.d.ReadMapStart()) * 2 - } else { - halt.errorStr2("decoding into a slice, expect map/array - got ", ctyp.String()) - } - hasLen := containerLenS >= 0 - for j := 0; d.containerNext(j, containerLenS, hasLen); j++ { - if isArray { - d.arrayElem(j == 0) - } else if j&1 == 0 { - d.mapElemKey(j == 0) - } else { - d.mapElemValue() - } - if j < len(v) { - v[uint(j)] = float32(d.d.DecodeFloat32()) - } else { - d.arrayCannotExpand(len(v), j+1) - d.swallow() - } - } - if isArray { - d.arrayEnd() - } else { - d.mapEnd() - } -} - -func (d *decoderBincBytes) fastpathDecSliceFloat64R(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTBincBytes - switch rv.Kind() { - case reflect.Ptr: - v := rv2i(rv).(*[]float64) - if vv, changed := ft.DecSliceFloat64Y(*v, d); changed { - *v = vv - } - case reflect.Array: - var v []float64 - rvGetSlice4Array(rv, &v) - ft.DecSliceFloat64N(v, d) - default: - ft.DecSliceFloat64N(rv2i(rv).([]float64), d) - } -} -func (fastpathDTBincBytes) DecSliceFloat64Y(v []float64, d *decoderBincBytes) (v2 []float64, changed bool) { - ctyp := d.d.ContainerType() - if ctyp == valueTypeNil { - return nil, v != nil - } - var containerLenS int - isArray := ctyp == valueTypeArray - if isArray { - containerLenS = d.arrayStart(d.d.ReadArrayStart()) - } else if ctyp == valueTypeMap { - containerLenS = d.mapStart(d.d.ReadMapStart()) * 2 - } else { - halt.errorStr2("decoding into a slice, expect map/array - got ", ctyp.String()) - } - hasLen := containerLenS >= 0 - var j int - fnv := func(dst []float64) { v, changed = dst, true } - for ; d.containerNext(j, containerLenS, hasLen); j++ { - if j == 0 { - if containerLenS == len(v) { - } else if containerLenS < 0 || containerLenS > cap(v) { - if xlen := int(decInferLen(containerLenS, d.maxInitLen(), 8)); xlen <= cap(v) { - fnv(v[:uint(xlen)]) - } else { - v2 = make([]float64, uint(xlen)) - copy(v2, v) - fnv(v2) - } - } else { - fnv(v[:containerLenS]) - } - } - if isArray { - d.arrayElem(j == 0) - } else if j&1 == 0 { - d.mapElemKey(j == 0) - } else { - d.mapElemValue() - } - if j >= len(v) { - fnv(append(v, 0)) - } - v[uint(j)] = d.d.DecodeFloat64() - } - if j < len(v) { - fnv(v[:uint(j)]) - } else if j == 0 && v == nil { - fnv([]float64{}) - } - if isArray { - d.arrayEnd() - } else { - d.mapEnd() - } - return v, changed -} -func (fastpathDTBincBytes) DecSliceFloat64N(v []float64, d *decoderBincBytes) { - ctyp := d.d.ContainerType() - if ctyp == valueTypeNil { - return - } - var containerLenS int - isArray := ctyp == valueTypeArray - if isArray { - containerLenS = d.arrayStart(d.d.ReadArrayStart()) - } else if ctyp == valueTypeMap { - containerLenS = d.mapStart(d.d.ReadMapStart()) * 2 - } else { - halt.errorStr2("decoding into a slice, expect map/array - got ", ctyp.String()) - } - hasLen := containerLenS >= 0 - for j := 0; d.containerNext(j, containerLenS, hasLen); j++ { - if isArray { - d.arrayElem(j == 0) - } else if j&1 == 0 { - d.mapElemKey(j == 0) - } else { - d.mapElemValue() - } - if j < len(v) { - v[uint(j)] = d.d.DecodeFloat64() - } else { - d.arrayCannotExpand(len(v), j+1) - d.swallow() - } - } - if isArray { - d.arrayEnd() - } else { - d.mapEnd() - } -} - -func (d *decoderBincBytes) fastpathDecSliceUint8R(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTBincBytes - switch rv.Kind() { - case reflect.Ptr: - v := rv2i(rv).(*[]uint8) - if vv, changed := ft.DecSliceUint8Y(*v, d); changed { - *v = vv - } - case reflect.Array: - var v []uint8 - rvGetSlice4Array(rv, &v) - ft.DecSliceUint8N(v, d) - default: - ft.DecSliceUint8N(rv2i(rv).([]uint8), d) - } -} -func (fastpathDTBincBytes) DecSliceUint8Y(v []uint8, d *decoderBincBytes) (v2 []uint8, changed bool) { - ctyp := d.d.ContainerType() - if ctyp == valueTypeNil { - return nil, v != nil - } - if ctyp != valueTypeMap { - var dbi dBytesIntoState - v2, dbi = d.decodeBytesInto(v[:len(v):len(v)], false) - return v2, dbi != dBytesIntoParamOut - } - containerLenS := d.mapStart(d.d.ReadMapStart()) * 2 - hasLen := containerLenS >= 0 - var j int - fnv := func(dst []uint8) { v, changed = dst, true } - for ; d.containerNext(j, containerLenS, hasLen); j++ { - if j == 0 { - if containerLenS == len(v) { - } else if containerLenS < 0 || containerLenS > cap(v) { - if xlen := int(decInferLen(containerLenS, d.maxInitLen(), 1)); xlen <= cap(v) { - fnv(v[:uint(xlen)]) - } else { - v2 = make([]uint8, uint(xlen)) - copy(v2, v) - fnv(v2) - } - } else { - fnv(v[:containerLenS]) - } - } - if j&1 == 0 { - d.mapElemKey(j == 0) - } else { - d.mapElemValue() - } - if j >= len(v) { - fnv(append(v, 0)) - } - v[uint(j)] = uint8(chkOvf.UintV(d.d.DecodeUint64(), 8)) - } - if j < len(v) { - fnv(v[:uint(j)]) - } else if j == 0 && v == nil { - fnv([]uint8{}) - } - d.mapEnd() - return v, changed -} -func (fastpathDTBincBytes) DecSliceUint8N(v []uint8, d *decoderBincBytes) { - ctyp := d.d.ContainerType() - if ctyp == valueTypeNil { - return - } - if ctyp != valueTypeMap { - d.decodeBytesInto(v[:len(v):len(v)], true) - return - } - containerLenS := d.mapStart(d.d.ReadMapStart()) * 2 - hasLen := containerLenS >= 0 - for j := 0; d.containerNext(j, containerLenS, hasLen); j++ { - if j&1 == 0 { - d.mapElemKey(j == 0) - } else { - d.mapElemValue() - } - if j < len(v) { - v[uint(j)] = uint8(chkOvf.UintV(d.d.DecodeUint64(), 8)) - } else { - d.arrayCannotExpand(len(v), j+1) - d.swallow() - } - } - d.mapEnd() -} - -func (d *decoderBincBytes) fastpathDecSliceUint64R(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTBincBytes - switch rv.Kind() { - case reflect.Ptr: - v := rv2i(rv).(*[]uint64) - if vv, changed := ft.DecSliceUint64Y(*v, d); changed { - *v = vv - } - case reflect.Array: - var v []uint64 - rvGetSlice4Array(rv, &v) - ft.DecSliceUint64N(v, d) - default: - ft.DecSliceUint64N(rv2i(rv).([]uint64), d) - } -} -func (fastpathDTBincBytes) DecSliceUint64Y(v []uint64, d *decoderBincBytes) (v2 []uint64, changed bool) { - ctyp := d.d.ContainerType() - if ctyp == valueTypeNil { - return nil, v != nil - } - var containerLenS int - isArray := ctyp == valueTypeArray - if isArray { - containerLenS = d.arrayStart(d.d.ReadArrayStart()) - } else if ctyp == valueTypeMap { - containerLenS = d.mapStart(d.d.ReadMapStart()) * 2 - } else { - halt.errorStr2("decoding into a slice, expect map/array - got ", ctyp.String()) - } - hasLen := containerLenS >= 0 - var j int - fnv := func(dst []uint64) { v, changed = dst, true } - for ; d.containerNext(j, containerLenS, hasLen); j++ { - if j == 0 { - if containerLenS == len(v) { - } else if containerLenS < 0 || containerLenS > cap(v) { - if xlen := int(decInferLen(containerLenS, d.maxInitLen(), 8)); xlen <= cap(v) { - fnv(v[:uint(xlen)]) - } else { - v2 = make([]uint64, uint(xlen)) - copy(v2, v) - fnv(v2) - } - } else { - fnv(v[:containerLenS]) - } - } - if isArray { - d.arrayElem(j == 0) - } else if j&1 == 0 { - d.mapElemKey(j == 0) - } else { - d.mapElemValue() - } - if j >= len(v) { - fnv(append(v, 0)) - } - v[uint(j)] = d.d.DecodeUint64() - } - if j < len(v) { - fnv(v[:uint(j)]) - } else if j == 0 && v == nil { - fnv([]uint64{}) - } - if isArray { - d.arrayEnd() - } else { - d.mapEnd() - } - return v, changed -} -func (fastpathDTBincBytes) DecSliceUint64N(v []uint64, d *decoderBincBytes) { - ctyp := d.d.ContainerType() - if ctyp == valueTypeNil { - return - } - var containerLenS int - isArray := ctyp == valueTypeArray - if isArray { - containerLenS = d.arrayStart(d.d.ReadArrayStart()) - } else if ctyp == valueTypeMap { - containerLenS = d.mapStart(d.d.ReadMapStart()) * 2 - } else { - halt.errorStr2("decoding into a slice, expect map/array - got ", ctyp.String()) - } - hasLen := containerLenS >= 0 - for j := 0; d.containerNext(j, containerLenS, hasLen); j++ { - if isArray { - d.arrayElem(j == 0) - } else if j&1 == 0 { - d.mapElemKey(j == 0) - } else { - d.mapElemValue() - } - if j < len(v) { - v[uint(j)] = d.d.DecodeUint64() - } else { - d.arrayCannotExpand(len(v), j+1) - d.swallow() - } - } - if isArray { - d.arrayEnd() - } else { - d.mapEnd() - } -} - -func (d *decoderBincBytes) fastpathDecSliceIntR(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTBincBytes - switch rv.Kind() { - case reflect.Ptr: - v := rv2i(rv).(*[]int) - if vv, changed := ft.DecSliceIntY(*v, d); changed { - *v = vv - } - case reflect.Array: - var v []int - rvGetSlice4Array(rv, &v) - ft.DecSliceIntN(v, d) - default: - ft.DecSliceIntN(rv2i(rv).([]int), d) - } -} -func (fastpathDTBincBytes) DecSliceIntY(v []int, d *decoderBincBytes) (v2 []int, changed bool) { - ctyp := d.d.ContainerType() - if ctyp == valueTypeNil { - return nil, v != nil - } - var containerLenS int - isArray := ctyp == valueTypeArray - if isArray { - containerLenS = d.arrayStart(d.d.ReadArrayStart()) - } else if ctyp == valueTypeMap { - containerLenS = d.mapStart(d.d.ReadMapStart()) * 2 - } else { - halt.errorStr2("decoding into a slice, expect map/array - got ", ctyp.String()) - } - hasLen := containerLenS >= 0 - var j int - fnv := func(dst []int) { v, changed = dst, true } - for ; d.containerNext(j, containerLenS, hasLen); j++ { - if j == 0 { - if containerLenS == len(v) { - } else if containerLenS < 0 || containerLenS > cap(v) { - if xlen := int(decInferLen(containerLenS, d.maxInitLen(), 8)); xlen <= cap(v) { - fnv(v[:uint(xlen)]) - } else { - v2 = make([]int, uint(xlen)) - copy(v2, v) - fnv(v2) - } - } else { - fnv(v[:containerLenS]) - } - } - if isArray { - d.arrayElem(j == 0) - } else if j&1 == 0 { - d.mapElemKey(j == 0) - } else { - d.mapElemValue() - } - if j >= len(v) { - fnv(append(v, 0)) - } - v[uint(j)] = int(chkOvf.IntV(d.d.DecodeInt64(), intBitsize)) - } - if j < len(v) { - fnv(v[:uint(j)]) - } else if j == 0 && v == nil { - fnv([]int{}) - } - if isArray { - d.arrayEnd() - } else { - d.mapEnd() - } - return v, changed -} -func (fastpathDTBincBytes) DecSliceIntN(v []int, d *decoderBincBytes) { - ctyp := d.d.ContainerType() - if ctyp == valueTypeNil { - return - } - var containerLenS int - isArray := ctyp == valueTypeArray - if isArray { - containerLenS = d.arrayStart(d.d.ReadArrayStart()) - } else if ctyp == valueTypeMap { - containerLenS = d.mapStart(d.d.ReadMapStart()) * 2 - } else { - halt.errorStr2("decoding into a slice, expect map/array - got ", ctyp.String()) - } - hasLen := containerLenS >= 0 - for j := 0; d.containerNext(j, containerLenS, hasLen); j++ { - if isArray { - d.arrayElem(j == 0) - } else if j&1 == 0 { - d.mapElemKey(j == 0) - } else { - d.mapElemValue() - } - if j < len(v) { - v[uint(j)] = int(chkOvf.IntV(d.d.DecodeInt64(), intBitsize)) - } else { - d.arrayCannotExpand(len(v), j+1) - d.swallow() - } - } - if isArray { - d.arrayEnd() - } else { - d.mapEnd() - } -} - -func (d *decoderBincBytes) fastpathDecSliceInt32R(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTBincBytes - switch rv.Kind() { - case reflect.Ptr: - v := rv2i(rv).(*[]int32) - if vv, changed := ft.DecSliceInt32Y(*v, d); changed { - *v = vv - } - case reflect.Array: - var v []int32 - rvGetSlice4Array(rv, &v) - ft.DecSliceInt32N(v, d) - default: - ft.DecSliceInt32N(rv2i(rv).([]int32), d) - } -} -func (fastpathDTBincBytes) DecSliceInt32Y(v []int32, d *decoderBincBytes) (v2 []int32, changed bool) { - ctyp := d.d.ContainerType() - if ctyp == valueTypeNil { - return nil, v != nil - } - var containerLenS int - isArray := ctyp == valueTypeArray - if isArray { - containerLenS = d.arrayStart(d.d.ReadArrayStart()) - } else if ctyp == valueTypeMap { - containerLenS = d.mapStart(d.d.ReadMapStart()) * 2 - } else { - halt.errorStr2("decoding into a slice, expect map/array - got ", ctyp.String()) - } - hasLen := containerLenS >= 0 - var j int - fnv := func(dst []int32) { v, changed = dst, true } - for ; d.containerNext(j, containerLenS, hasLen); j++ { - if j == 0 { - if containerLenS == len(v) { - } else if containerLenS < 0 || containerLenS > cap(v) { - if xlen := int(decInferLen(containerLenS, d.maxInitLen(), 4)); xlen <= cap(v) { - fnv(v[:uint(xlen)]) - } else { - v2 = make([]int32, uint(xlen)) - copy(v2, v) - fnv(v2) - } - } else { - fnv(v[:containerLenS]) - } - } - if isArray { - d.arrayElem(j == 0) - } else if j&1 == 0 { - d.mapElemKey(j == 0) - } else { - d.mapElemValue() - } - if j >= len(v) { - fnv(append(v, 0)) - } - v[uint(j)] = int32(chkOvf.IntV(d.d.DecodeInt64(), 32)) - } - if j < len(v) { - fnv(v[:uint(j)]) - } else if j == 0 && v == nil { - fnv([]int32{}) - } - if isArray { - d.arrayEnd() - } else { - d.mapEnd() - } - return v, changed -} -func (fastpathDTBincBytes) DecSliceInt32N(v []int32, d *decoderBincBytes) { - ctyp := d.d.ContainerType() - if ctyp == valueTypeNil { - return - } - var containerLenS int - isArray := ctyp == valueTypeArray - if isArray { - containerLenS = d.arrayStart(d.d.ReadArrayStart()) - } else if ctyp == valueTypeMap { - containerLenS = d.mapStart(d.d.ReadMapStart()) * 2 - } else { - halt.errorStr2("decoding into a slice, expect map/array - got ", ctyp.String()) - } - hasLen := containerLenS >= 0 - for j := 0; d.containerNext(j, containerLenS, hasLen); j++ { - if isArray { - d.arrayElem(j == 0) - } else if j&1 == 0 { - d.mapElemKey(j == 0) - } else { - d.mapElemValue() - } - if j < len(v) { - v[uint(j)] = int32(chkOvf.IntV(d.d.DecodeInt64(), 32)) - } else { - d.arrayCannotExpand(len(v), j+1) - d.swallow() - } - } - if isArray { - d.arrayEnd() - } else { - d.mapEnd() - } -} - -func (d *decoderBincBytes) fastpathDecSliceInt64R(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTBincBytes - switch rv.Kind() { - case reflect.Ptr: - v := rv2i(rv).(*[]int64) - if vv, changed := ft.DecSliceInt64Y(*v, d); changed { - *v = vv - } - case reflect.Array: - var v []int64 - rvGetSlice4Array(rv, &v) - ft.DecSliceInt64N(v, d) - default: - ft.DecSliceInt64N(rv2i(rv).([]int64), d) - } -} -func (fastpathDTBincBytes) DecSliceInt64Y(v []int64, d *decoderBincBytes) (v2 []int64, changed bool) { - ctyp := d.d.ContainerType() - if ctyp == valueTypeNil { - return nil, v != nil - } - var containerLenS int - isArray := ctyp == valueTypeArray - if isArray { - containerLenS = d.arrayStart(d.d.ReadArrayStart()) - } else if ctyp == valueTypeMap { - containerLenS = d.mapStart(d.d.ReadMapStart()) * 2 - } else { - halt.errorStr2("decoding into a slice, expect map/array - got ", ctyp.String()) - } - hasLen := containerLenS >= 0 - var j int - fnv := func(dst []int64) { v, changed = dst, true } - for ; d.containerNext(j, containerLenS, hasLen); j++ { - if j == 0 { - if containerLenS == len(v) { - } else if containerLenS < 0 || containerLenS > cap(v) { - if xlen := int(decInferLen(containerLenS, d.maxInitLen(), 8)); xlen <= cap(v) { - fnv(v[:uint(xlen)]) - } else { - v2 = make([]int64, uint(xlen)) - copy(v2, v) - fnv(v2) - } - } else { - fnv(v[:containerLenS]) - } - } - if isArray { - d.arrayElem(j == 0) - } else if j&1 == 0 { - d.mapElemKey(j == 0) - } else { - d.mapElemValue() - } - if j >= len(v) { - fnv(append(v, 0)) - } - v[uint(j)] = d.d.DecodeInt64() - } - if j < len(v) { - fnv(v[:uint(j)]) - } else if j == 0 && v == nil { - fnv([]int64{}) - } - if isArray { - d.arrayEnd() - } else { - d.mapEnd() - } - return v, changed -} -func (fastpathDTBincBytes) DecSliceInt64N(v []int64, d *decoderBincBytes) { - ctyp := d.d.ContainerType() - if ctyp == valueTypeNil { - return - } - var containerLenS int - isArray := ctyp == valueTypeArray - if isArray { - containerLenS = d.arrayStart(d.d.ReadArrayStart()) - } else if ctyp == valueTypeMap { - containerLenS = d.mapStart(d.d.ReadMapStart()) * 2 - } else { - halt.errorStr2("decoding into a slice, expect map/array - got ", ctyp.String()) - } - hasLen := containerLenS >= 0 - for j := 0; d.containerNext(j, containerLenS, hasLen); j++ { - if isArray { - d.arrayElem(j == 0) - } else if j&1 == 0 { - d.mapElemKey(j == 0) - } else { - d.mapElemValue() - } - if j < len(v) { - v[uint(j)] = d.d.DecodeInt64() - } else { - d.arrayCannotExpand(len(v), j+1) - d.swallow() - } - } - if isArray { - d.arrayEnd() - } else { - d.mapEnd() - } -} - -func (d *decoderBincBytes) fastpathDecSliceBoolR(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTBincBytes - switch rv.Kind() { - case reflect.Ptr: - v := rv2i(rv).(*[]bool) - if vv, changed := ft.DecSliceBoolY(*v, d); changed { - *v = vv - } - case reflect.Array: - var v []bool - rvGetSlice4Array(rv, &v) - ft.DecSliceBoolN(v, d) - default: - ft.DecSliceBoolN(rv2i(rv).([]bool), d) - } -} -func (fastpathDTBincBytes) DecSliceBoolY(v []bool, d *decoderBincBytes) (v2 []bool, changed bool) { - ctyp := d.d.ContainerType() - if ctyp == valueTypeNil { - return nil, v != nil - } - var containerLenS int - isArray := ctyp == valueTypeArray - if isArray { - containerLenS = d.arrayStart(d.d.ReadArrayStart()) - } else if ctyp == valueTypeMap { - containerLenS = d.mapStart(d.d.ReadMapStart()) * 2 - } else { - halt.errorStr2("decoding into a slice, expect map/array - got ", ctyp.String()) - } - hasLen := containerLenS >= 0 - var j int - fnv := func(dst []bool) { v, changed = dst, true } - for ; d.containerNext(j, containerLenS, hasLen); j++ { - if j == 0 { - if containerLenS == len(v) { - } else if containerLenS < 0 || containerLenS > cap(v) { - if xlen := int(decInferLen(containerLenS, d.maxInitLen(), 1)); xlen <= cap(v) { - fnv(v[:uint(xlen)]) - } else { - v2 = make([]bool, uint(xlen)) - copy(v2, v) - fnv(v2) - } - } else { - fnv(v[:containerLenS]) - } - } - if isArray { - d.arrayElem(j == 0) - } else if j&1 == 0 { - d.mapElemKey(j == 0) - } else { - d.mapElemValue() - } - if j >= len(v) { - fnv(append(v, false)) - } - v[uint(j)] = d.d.DecodeBool() - } - if j < len(v) { - fnv(v[:uint(j)]) - } else if j == 0 && v == nil { - fnv([]bool{}) - } - if isArray { - d.arrayEnd() - } else { - d.mapEnd() - } - return v, changed -} -func (fastpathDTBincBytes) DecSliceBoolN(v []bool, d *decoderBincBytes) { - ctyp := d.d.ContainerType() - if ctyp == valueTypeNil { - return - } - var containerLenS int - isArray := ctyp == valueTypeArray - if isArray { - containerLenS = d.arrayStart(d.d.ReadArrayStart()) - } else if ctyp == valueTypeMap { - containerLenS = d.mapStart(d.d.ReadMapStart()) * 2 - } else { - halt.errorStr2("decoding into a slice, expect map/array - got ", ctyp.String()) - } - hasLen := containerLenS >= 0 - for j := 0; d.containerNext(j, containerLenS, hasLen); j++ { - if isArray { - d.arrayElem(j == 0) - } else if j&1 == 0 { - d.mapElemKey(j == 0) - } else { - d.mapElemValue() - } - if j < len(v) { - v[uint(j)] = d.d.DecodeBool() - } else { - d.arrayCannotExpand(len(v), j+1) - d.swallow() - } - } - if isArray { - d.arrayEnd() - } else { - d.mapEnd() - } -} -func (d *decoderBincBytes) fastpathDecMapStringIntfR(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTBincBytes - containerLen := d.mapStart(d.d.ReadMapStart()) - if rv.Kind() == reflect.Ptr { - vp, _ := rv2i(rv).(*map[string]interface{}) - if *vp == nil { - *vp = make(map[string]interface{}, decInferLen(containerLen, d.maxInitLen(), 32)) - } - if containerLen != 0 { - ft.DecMapStringIntfL(*vp, containerLen, d) - } - } else if containerLen != 0 { - ft.DecMapStringIntfL(rv2i(rv).(map[string]interface{}), containerLen, d) - } - d.mapEnd() -} -func (fastpathDTBincBytes) DecMapStringIntfL(v map[string]interface{}, containerLen int, d *decoderBincBytes) { - if v == nil { - halt.errorInt("cannot decode into nil map[string]interface{} given stream length: ", int64(containerLen)) - } - var mv interface{} - mapGet := !d.h.MapValueReset && !d.h.InterfaceReset - hasLen := containerLen >= 0 - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - mk := d.detach2Str(d.d.DecodeStringAsBytes()) - d.mapElemValue() - if mapGet { - mv = v[mk] - } else { - mv = nil - } - d.decode(&mv) - v[mk] = mv - } -} -func (d *decoderBincBytes) fastpathDecMapStringStringR(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTBincBytes - containerLen := d.mapStart(d.d.ReadMapStart()) - if rv.Kind() == reflect.Ptr { - vp, _ := rv2i(rv).(*map[string]string) - if *vp == nil { - *vp = make(map[string]string, decInferLen(containerLen, d.maxInitLen(), 32)) - } - if containerLen != 0 { - ft.DecMapStringStringL(*vp, containerLen, d) - } - } else if containerLen != 0 { - ft.DecMapStringStringL(rv2i(rv).(map[string]string), containerLen, d) - } - d.mapEnd() -} -func (fastpathDTBincBytes) DecMapStringStringL(v map[string]string, containerLen int, d *decoderBincBytes) { - if v == nil { - halt.errorInt("cannot decode into nil map[string]string given stream length: ", int64(containerLen)) - } - hasLen := containerLen >= 0 - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - mk := d.detach2Str(d.d.DecodeStringAsBytes()) - d.mapElemValue() - v[mk] = d.detach2Str(d.d.DecodeStringAsBytes()) - } -} -func (d *decoderBincBytes) fastpathDecMapStringBytesR(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTBincBytes - containerLen := d.mapStart(d.d.ReadMapStart()) - if rv.Kind() == reflect.Ptr { - vp, _ := rv2i(rv).(*map[string][]byte) - if *vp == nil { - *vp = make(map[string][]byte, decInferLen(containerLen, d.maxInitLen(), 40)) - } - if containerLen != 0 { - ft.DecMapStringBytesL(*vp, containerLen, d) - } - } else if containerLen != 0 { - ft.DecMapStringBytesL(rv2i(rv).(map[string][]byte), containerLen, d) - } - d.mapEnd() -} -func (fastpathDTBincBytes) DecMapStringBytesL(v map[string][]byte, containerLen int, d *decoderBincBytes) { - if v == nil { - halt.errorInt("cannot decode into nil map[string][]byte given stream length: ", int64(containerLen)) - } - var mv []byte - mapGet := !d.h.MapValueReset - hasLen := containerLen >= 0 - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - mk := d.detach2Str(d.d.DecodeStringAsBytes()) - d.mapElemValue() - if mapGet { - mv = v[mk] - } else { - mv = nil - } - v[mk], _ = d.decodeBytesInto(mv, false) - } -} -func (d *decoderBincBytes) fastpathDecMapStringUint8R(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTBincBytes - containerLen := d.mapStart(d.d.ReadMapStart()) - if rv.Kind() == reflect.Ptr { - vp, _ := rv2i(rv).(*map[string]uint8) - if *vp == nil { - *vp = make(map[string]uint8, decInferLen(containerLen, d.maxInitLen(), 17)) - } - if containerLen != 0 { - ft.DecMapStringUint8L(*vp, containerLen, d) - } - } else if containerLen != 0 { - ft.DecMapStringUint8L(rv2i(rv).(map[string]uint8), containerLen, d) - } - d.mapEnd() -} -func (fastpathDTBincBytes) DecMapStringUint8L(v map[string]uint8, containerLen int, d *decoderBincBytes) { - if v == nil { - halt.errorInt("cannot decode into nil map[string]uint8 given stream length: ", int64(containerLen)) - } - hasLen := containerLen >= 0 - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - mk := d.detach2Str(d.d.DecodeStringAsBytes()) - d.mapElemValue() - v[mk] = uint8(chkOvf.UintV(d.d.DecodeUint64(), 8)) - } -} -func (d *decoderBincBytes) fastpathDecMapStringUint64R(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTBincBytes - containerLen := d.mapStart(d.d.ReadMapStart()) - if rv.Kind() == reflect.Ptr { - vp, _ := rv2i(rv).(*map[string]uint64) - if *vp == nil { - *vp = make(map[string]uint64, decInferLen(containerLen, d.maxInitLen(), 24)) - } - if containerLen != 0 { - ft.DecMapStringUint64L(*vp, containerLen, d) - } - } else if containerLen != 0 { - ft.DecMapStringUint64L(rv2i(rv).(map[string]uint64), containerLen, d) - } - d.mapEnd() -} -func (fastpathDTBincBytes) DecMapStringUint64L(v map[string]uint64, containerLen int, d *decoderBincBytes) { - if v == nil { - halt.errorInt("cannot decode into nil map[string]uint64 given stream length: ", int64(containerLen)) - } - hasLen := containerLen >= 0 - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - mk := d.detach2Str(d.d.DecodeStringAsBytes()) - d.mapElemValue() - v[mk] = d.d.DecodeUint64() - } -} -func (d *decoderBincBytes) fastpathDecMapStringIntR(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTBincBytes - containerLen := d.mapStart(d.d.ReadMapStart()) - if rv.Kind() == reflect.Ptr { - vp, _ := rv2i(rv).(*map[string]int) - if *vp == nil { - *vp = make(map[string]int, decInferLen(containerLen, d.maxInitLen(), 24)) - } - if containerLen != 0 { - ft.DecMapStringIntL(*vp, containerLen, d) - } - } else if containerLen != 0 { - ft.DecMapStringIntL(rv2i(rv).(map[string]int), containerLen, d) - } - d.mapEnd() -} -func (fastpathDTBincBytes) DecMapStringIntL(v map[string]int, containerLen int, d *decoderBincBytes) { - if v == nil { - halt.errorInt("cannot decode into nil map[string]int given stream length: ", int64(containerLen)) - } - hasLen := containerLen >= 0 - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - mk := d.detach2Str(d.d.DecodeStringAsBytes()) - d.mapElemValue() - v[mk] = int(chkOvf.IntV(d.d.DecodeInt64(), intBitsize)) - } -} -func (d *decoderBincBytes) fastpathDecMapStringInt32R(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTBincBytes - containerLen := d.mapStart(d.d.ReadMapStart()) - if rv.Kind() == reflect.Ptr { - vp, _ := rv2i(rv).(*map[string]int32) - if *vp == nil { - *vp = make(map[string]int32, decInferLen(containerLen, d.maxInitLen(), 20)) - } - if containerLen != 0 { - ft.DecMapStringInt32L(*vp, containerLen, d) - } - } else if containerLen != 0 { - ft.DecMapStringInt32L(rv2i(rv).(map[string]int32), containerLen, d) - } - d.mapEnd() -} -func (fastpathDTBincBytes) DecMapStringInt32L(v map[string]int32, containerLen int, d *decoderBincBytes) { - if v == nil { - halt.errorInt("cannot decode into nil map[string]int32 given stream length: ", int64(containerLen)) - } - hasLen := containerLen >= 0 - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - mk := d.detach2Str(d.d.DecodeStringAsBytes()) - d.mapElemValue() - v[mk] = int32(chkOvf.IntV(d.d.DecodeInt64(), 32)) - } -} -func (d *decoderBincBytes) fastpathDecMapStringFloat64R(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTBincBytes - containerLen := d.mapStart(d.d.ReadMapStart()) - if rv.Kind() == reflect.Ptr { - vp, _ := rv2i(rv).(*map[string]float64) - if *vp == nil { - *vp = make(map[string]float64, decInferLen(containerLen, d.maxInitLen(), 24)) - } - if containerLen != 0 { - ft.DecMapStringFloat64L(*vp, containerLen, d) - } - } else if containerLen != 0 { - ft.DecMapStringFloat64L(rv2i(rv).(map[string]float64), containerLen, d) - } - d.mapEnd() -} -func (fastpathDTBincBytes) DecMapStringFloat64L(v map[string]float64, containerLen int, d *decoderBincBytes) { - if v == nil { - halt.errorInt("cannot decode into nil map[string]float64 given stream length: ", int64(containerLen)) - } - hasLen := containerLen >= 0 - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - mk := d.detach2Str(d.d.DecodeStringAsBytes()) - d.mapElemValue() - v[mk] = d.d.DecodeFloat64() - } -} -func (d *decoderBincBytes) fastpathDecMapStringBoolR(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTBincBytes - containerLen := d.mapStart(d.d.ReadMapStart()) - if rv.Kind() == reflect.Ptr { - vp, _ := rv2i(rv).(*map[string]bool) - if *vp == nil { - *vp = make(map[string]bool, decInferLen(containerLen, d.maxInitLen(), 17)) - } - if containerLen != 0 { - ft.DecMapStringBoolL(*vp, containerLen, d) - } - } else if containerLen != 0 { - ft.DecMapStringBoolL(rv2i(rv).(map[string]bool), containerLen, d) - } - d.mapEnd() -} -func (fastpathDTBincBytes) DecMapStringBoolL(v map[string]bool, containerLen int, d *decoderBincBytes) { - if v == nil { - halt.errorInt("cannot decode into nil map[string]bool given stream length: ", int64(containerLen)) - } - hasLen := containerLen >= 0 - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - mk := d.detach2Str(d.d.DecodeStringAsBytes()) - d.mapElemValue() - v[mk] = d.d.DecodeBool() - } -} -func (d *decoderBincBytes) fastpathDecMapUint8IntfR(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTBincBytes - containerLen := d.mapStart(d.d.ReadMapStart()) - if rv.Kind() == reflect.Ptr { - vp, _ := rv2i(rv).(*map[uint8]interface{}) - if *vp == nil { - *vp = make(map[uint8]interface{}, decInferLen(containerLen, d.maxInitLen(), 17)) - } - if containerLen != 0 { - ft.DecMapUint8IntfL(*vp, containerLen, d) - } - } else if containerLen != 0 { - ft.DecMapUint8IntfL(rv2i(rv).(map[uint8]interface{}), containerLen, d) - } - d.mapEnd() -} -func (fastpathDTBincBytes) DecMapUint8IntfL(v map[uint8]interface{}, containerLen int, d *decoderBincBytes) { - if v == nil { - halt.errorInt("cannot decode into nil map[uint8]interface{} given stream length: ", int64(containerLen)) - } - var mv interface{} - mapGet := !d.h.MapValueReset && !d.h.InterfaceReset - hasLen := containerLen >= 0 - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - mk := uint8(chkOvf.UintV(d.d.DecodeUint64(), 8)) - d.mapElemValue() - if mapGet { - mv = v[mk] - } else { - mv = nil - } - d.decode(&mv) - v[mk] = mv - } -} -func (d *decoderBincBytes) fastpathDecMapUint8StringR(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTBincBytes - containerLen := d.mapStart(d.d.ReadMapStart()) - if rv.Kind() == reflect.Ptr { - vp, _ := rv2i(rv).(*map[uint8]string) - if *vp == nil { - *vp = make(map[uint8]string, decInferLen(containerLen, d.maxInitLen(), 17)) - } - if containerLen != 0 { - ft.DecMapUint8StringL(*vp, containerLen, d) - } - } else if containerLen != 0 { - ft.DecMapUint8StringL(rv2i(rv).(map[uint8]string), containerLen, d) - } - d.mapEnd() -} -func (fastpathDTBincBytes) DecMapUint8StringL(v map[uint8]string, containerLen int, d *decoderBincBytes) { - if v == nil { - halt.errorInt("cannot decode into nil map[uint8]string given stream length: ", int64(containerLen)) - } - hasLen := containerLen >= 0 - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - mk := uint8(chkOvf.UintV(d.d.DecodeUint64(), 8)) - d.mapElemValue() - v[mk] = d.detach2Str(d.d.DecodeStringAsBytes()) - } -} -func (d *decoderBincBytes) fastpathDecMapUint8BytesR(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTBincBytes - containerLen := d.mapStart(d.d.ReadMapStart()) - if rv.Kind() == reflect.Ptr { - vp, _ := rv2i(rv).(*map[uint8][]byte) - if *vp == nil { - *vp = make(map[uint8][]byte, decInferLen(containerLen, d.maxInitLen(), 25)) - } - if containerLen != 0 { - ft.DecMapUint8BytesL(*vp, containerLen, d) - } - } else if containerLen != 0 { - ft.DecMapUint8BytesL(rv2i(rv).(map[uint8][]byte), containerLen, d) - } - d.mapEnd() -} -func (fastpathDTBincBytes) DecMapUint8BytesL(v map[uint8][]byte, containerLen int, d *decoderBincBytes) { - if v == nil { - halt.errorInt("cannot decode into nil map[uint8][]byte given stream length: ", int64(containerLen)) - } - var mv []byte - mapGet := !d.h.MapValueReset - hasLen := containerLen >= 0 - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - mk := uint8(chkOvf.UintV(d.d.DecodeUint64(), 8)) - d.mapElemValue() - if mapGet { - mv = v[mk] - } else { - mv = nil - } - v[mk], _ = d.decodeBytesInto(mv, false) - } -} -func (d *decoderBincBytes) fastpathDecMapUint8Uint8R(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTBincBytes - containerLen := d.mapStart(d.d.ReadMapStart()) - if rv.Kind() == reflect.Ptr { - vp, _ := rv2i(rv).(*map[uint8]uint8) - if *vp == nil { - *vp = make(map[uint8]uint8, decInferLen(containerLen, d.maxInitLen(), 2)) - } - if containerLen != 0 { - ft.DecMapUint8Uint8L(*vp, containerLen, d) - } - } else if containerLen != 0 { - ft.DecMapUint8Uint8L(rv2i(rv).(map[uint8]uint8), containerLen, d) - } - d.mapEnd() -} -func (fastpathDTBincBytes) DecMapUint8Uint8L(v map[uint8]uint8, containerLen int, d *decoderBincBytes) { - if v == nil { - halt.errorInt("cannot decode into nil map[uint8]uint8 given stream length: ", int64(containerLen)) - } - hasLen := containerLen >= 0 - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - mk := uint8(chkOvf.UintV(d.d.DecodeUint64(), 8)) - d.mapElemValue() - v[mk] = uint8(chkOvf.UintV(d.d.DecodeUint64(), 8)) - } -} -func (d *decoderBincBytes) fastpathDecMapUint8Uint64R(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTBincBytes - containerLen := d.mapStart(d.d.ReadMapStart()) - if rv.Kind() == reflect.Ptr { - vp, _ := rv2i(rv).(*map[uint8]uint64) - if *vp == nil { - *vp = make(map[uint8]uint64, decInferLen(containerLen, d.maxInitLen(), 9)) - } - if containerLen != 0 { - ft.DecMapUint8Uint64L(*vp, containerLen, d) - } - } else if containerLen != 0 { - ft.DecMapUint8Uint64L(rv2i(rv).(map[uint8]uint64), containerLen, d) - } - d.mapEnd() -} -func (fastpathDTBincBytes) DecMapUint8Uint64L(v map[uint8]uint64, containerLen int, d *decoderBincBytes) { - if v == nil { - halt.errorInt("cannot decode into nil map[uint8]uint64 given stream length: ", int64(containerLen)) - } - hasLen := containerLen >= 0 - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - mk := uint8(chkOvf.UintV(d.d.DecodeUint64(), 8)) - d.mapElemValue() - v[mk] = d.d.DecodeUint64() - } -} -func (d *decoderBincBytes) fastpathDecMapUint8IntR(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTBincBytes - containerLen := d.mapStart(d.d.ReadMapStart()) - if rv.Kind() == reflect.Ptr { - vp, _ := rv2i(rv).(*map[uint8]int) - if *vp == nil { - *vp = make(map[uint8]int, decInferLen(containerLen, d.maxInitLen(), 9)) - } - if containerLen != 0 { - ft.DecMapUint8IntL(*vp, containerLen, d) - } - } else if containerLen != 0 { - ft.DecMapUint8IntL(rv2i(rv).(map[uint8]int), containerLen, d) - } - d.mapEnd() -} -func (fastpathDTBincBytes) DecMapUint8IntL(v map[uint8]int, containerLen int, d *decoderBincBytes) { - if v == nil { - halt.errorInt("cannot decode into nil map[uint8]int given stream length: ", int64(containerLen)) - } - hasLen := containerLen >= 0 - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - mk := uint8(chkOvf.UintV(d.d.DecodeUint64(), 8)) - d.mapElemValue() - v[mk] = int(chkOvf.IntV(d.d.DecodeInt64(), intBitsize)) - } -} -func (d *decoderBincBytes) fastpathDecMapUint8Int32R(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTBincBytes - containerLen := d.mapStart(d.d.ReadMapStart()) - if rv.Kind() == reflect.Ptr { - vp, _ := rv2i(rv).(*map[uint8]int32) - if *vp == nil { - *vp = make(map[uint8]int32, decInferLen(containerLen, d.maxInitLen(), 5)) - } - if containerLen != 0 { - ft.DecMapUint8Int32L(*vp, containerLen, d) - } - } else if containerLen != 0 { - ft.DecMapUint8Int32L(rv2i(rv).(map[uint8]int32), containerLen, d) - } - d.mapEnd() -} -func (fastpathDTBincBytes) DecMapUint8Int32L(v map[uint8]int32, containerLen int, d *decoderBincBytes) { - if v == nil { - halt.errorInt("cannot decode into nil map[uint8]int32 given stream length: ", int64(containerLen)) - } - hasLen := containerLen >= 0 - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - mk := uint8(chkOvf.UintV(d.d.DecodeUint64(), 8)) - d.mapElemValue() - v[mk] = int32(chkOvf.IntV(d.d.DecodeInt64(), 32)) - } -} -func (d *decoderBincBytes) fastpathDecMapUint8Float64R(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTBincBytes - containerLen := d.mapStart(d.d.ReadMapStart()) - if rv.Kind() == reflect.Ptr { - vp, _ := rv2i(rv).(*map[uint8]float64) - if *vp == nil { - *vp = make(map[uint8]float64, decInferLen(containerLen, d.maxInitLen(), 9)) - } - if containerLen != 0 { - ft.DecMapUint8Float64L(*vp, containerLen, d) - } - } else if containerLen != 0 { - ft.DecMapUint8Float64L(rv2i(rv).(map[uint8]float64), containerLen, d) - } - d.mapEnd() -} -func (fastpathDTBincBytes) DecMapUint8Float64L(v map[uint8]float64, containerLen int, d *decoderBincBytes) { - if v == nil { - halt.errorInt("cannot decode into nil map[uint8]float64 given stream length: ", int64(containerLen)) - } - hasLen := containerLen >= 0 - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - mk := uint8(chkOvf.UintV(d.d.DecodeUint64(), 8)) - d.mapElemValue() - v[mk] = d.d.DecodeFloat64() - } -} -func (d *decoderBincBytes) fastpathDecMapUint8BoolR(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTBincBytes - containerLen := d.mapStart(d.d.ReadMapStart()) - if rv.Kind() == reflect.Ptr { - vp, _ := rv2i(rv).(*map[uint8]bool) - if *vp == nil { - *vp = make(map[uint8]bool, decInferLen(containerLen, d.maxInitLen(), 2)) - } - if containerLen != 0 { - ft.DecMapUint8BoolL(*vp, containerLen, d) - } - } else if containerLen != 0 { - ft.DecMapUint8BoolL(rv2i(rv).(map[uint8]bool), containerLen, d) - } - d.mapEnd() -} -func (fastpathDTBincBytes) DecMapUint8BoolL(v map[uint8]bool, containerLen int, d *decoderBincBytes) { - if v == nil { - halt.errorInt("cannot decode into nil map[uint8]bool given stream length: ", int64(containerLen)) - } - hasLen := containerLen >= 0 - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - mk := uint8(chkOvf.UintV(d.d.DecodeUint64(), 8)) - d.mapElemValue() - v[mk] = d.d.DecodeBool() - } -} -func (d *decoderBincBytes) fastpathDecMapUint64IntfR(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTBincBytes - containerLen := d.mapStart(d.d.ReadMapStart()) - if rv.Kind() == reflect.Ptr { - vp, _ := rv2i(rv).(*map[uint64]interface{}) - if *vp == nil { - *vp = make(map[uint64]interface{}, decInferLen(containerLen, d.maxInitLen(), 24)) - } - if containerLen != 0 { - ft.DecMapUint64IntfL(*vp, containerLen, d) - } - } else if containerLen != 0 { - ft.DecMapUint64IntfL(rv2i(rv).(map[uint64]interface{}), containerLen, d) - } - d.mapEnd() -} -func (fastpathDTBincBytes) DecMapUint64IntfL(v map[uint64]interface{}, containerLen int, d *decoderBincBytes) { - if v == nil { - halt.errorInt("cannot decode into nil map[uint64]interface{} given stream length: ", int64(containerLen)) - } - var mv interface{} - mapGet := !d.h.MapValueReset && !d.h.InterfaceReset - hasLen := containerLen >= 0 - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - mk := d.d.DecodeUint64() - d.mapElemValue() - if mapGet { - mv = v[mk] - } else { - mv = nil - } - d.decode(&mv) - v[mk] = mv - } -} -func (d *decoderBincBytes) fastpathDecMapUint64StringR(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTBincBytes - containerLen := d.mapStart(d.d.ReadMapStart()) - if rv.Kind() == reflect.Ptr { - vp, _ := rv2i(rv).(*map[uint64]string) - if *vp == nil { - *vp = make(map[uint64]string, decInferLen(containerLen, d.maxInitLen(), 24)) - } - if containerLen != 0 { - ft.DecMapUint64StringL(*vp, containerLen, d) - } - } else if containerLen != 0 { - ft.DecMapUint64StringL(rv2i(rv).(map[uint64]string), containerLen, d) - } - d.mapEnd() -} -func (fastpathDTBincBytes) DecMapUint64StringL(v map[uint64]string, containerLen int, d *decoderBincBytes) { - if v == nil { - halt.errorInt("cannot decode into nil map[uint64]string given stream length: ", int64(containerLen)) - } - hasLen := containerLen >= 0 - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - mk := d.d.DecodeUint64() - d.mapElemValue() - v[mk] = d.detach2Str(d.d.DecodeStringAsBytes()) - } -} -func (d *decoderBincBytes) fastpathDecMapUint64BytesR(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTBincBytes - containerLen := d.mapStart(d.d.ReadMapStart()) - if rv.Kind() == reflect.Ptr { - vp, _ := rv2i(rv).(*map[uint64][]byte) - if *vp == nil { - *vp = make(map[uint64][]byte, decInferLen(containerLen, d.maxInitLen(), 32)) - } - if containerLen != 0 { - ft.DecMapUint64BytesL(*vp, containerLen, d) - } - } else if containerLen != 0 { - ft.DecMapUint64BytesL(rv2i(rv).(map[uint64][]byte), containerLen, d) - } - d.mapEnd() -} -func (fastpathDTBincBytes) DecMapUint64BytesL(v map[uint64][]byte, containerLen int, d *decoderBincBytes) { - if v == nil { - halt.errorInt("cannot decode into nil map[uint64][]byte given stream length: ", int64(containerLen)) - } - var mv []byte - mapGet := !d.h.MapValueReset - hasLen := containerLen >= 0 - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - mk := d.d.DecodeUint64() - d.mapElemValue() - if mapGet { - mv = v[mk] - } else { - mv = nil - } - v[mk], _ = d.decodeBytesInto(mv, false) - } -} -func (d *decoderBincBytes) fastpathDecMapUint64Uint8R(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTBincBytes - containerLen := d.mapStart(d.d.ReadMapStart()) - if rv.Kind() == reflect.Ptr { - vp, _ := rv2i(rv).(*map[uint64]uint8) - if *vp == nil { - *vp = make(map[uint64]uint8, decInferLen(containerLen, d.maxInitLen(), 9)) - } - if containerLen != 0 { - ft.DecMapUint64Uint8L(*vp, containerLen, d) - } - } else if containerLen != 0 { - ft.DecMapUint64Uint8L(rv2i(rv).(map[uint64]uint8), containerLen, d) - } - d.mapEnd() -} -func (fastpathDTBincBytes) DecMapUint64Uint8L(v map[uint64]uint8, containerLen int, d *decoderBincBytes) { - if v == nil { - halt.errorInt("cannot decode into nil map[uint64]uint8 given stream length: ", int64(containerLen)) - } - hasLen := containerLen >= 0 - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - mk := d.d.DecodeUint64() - d.mapElemValue() - v[mk] = uint8(chkOvf.UintV(d.d.DecodeUint64(), 8)) - } -} -func (d *decoderBincBytes) fastpathDecMapUint64Uint64R(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTBincBytes - containerLen := d.mapStart(d.d.ReadMapStart()) - if rv.Kind() == reflect.Ptr { - vp, _ := rv2i(rv).(*map[uint64]uint64) - if *vp == nil { - *vp = make(map[uint64]uint64, decInferLen(containerLen, d.maxInitLen(), 16)) - } - if containerLen != 0 { - ft.DecMapUint64Uint64L(*vp, containerLen, d) - } - } else if containerLen != 0 { - ft.DecMapUint64Uint64L(rv2i(rv).(map[uint64]uint64), containerLen, d) - } - d.mapEnd() -} -func (fastpathDTBincBytes) DecMapUint64Uint64L(v map[uint64]uint64, containerLen int, d *decoderBincBytes) { - if v == nil { - halt.errorInt("cannot decode into nil map[uint64]uint64 given stream length: ", int64(containerLen)) - } - hasLen := containerLen >= 0 - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - mk := d.d.DecodeUint64() - d.mapElemValue() - v[mk] = d.d.DecodeUint64() - } -} -func (d *decoderBincBytes) fastpathDecMapUint64IntR(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTBincBytes - containerLen := d.mapStart(d.d.ReadMapStart()) - if rv.Kind() == reflect.Ptr { - vp, _ := rv2i(rv).(*map[uint64]int) - if *vp == nil { - *vp = make(map[uint64]int, decInferLen(containerLen, d.maxInitLen(), 16)) - } - if containerLen != 0 { - ft.DecMapUint64IntL(*vp, containerLen, d) - } - } else if containerLen != 0 { - ft.DecMapUint64IntL(rv2i(rv).(map[uint64]int), containerLen, d) - } - d.mapEnd() -} -func (fastpathDTBincBytes) DecMapUint64IntL(v map[uint64]int, containerLen int, d *decoderBincBytes) { - if v == nil { - halt.errorInt("cannot decode into nil map[uint64]int given stream length: ", int64(containerLen)) - } - hasLen := containerLen >= 0 - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - mk := d.d.DecodeUint64() - d.mapElemValue() - v[mk] = int(chkOvf.IntV(d.d.DecodeInt64(), intBitsize)) - } -} -func (d *decoderBincBytes) fastpathDecMapUint64Int32R(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTBincBytes - containerLen := d.mapStart(d.d.ReadMapStart()) - if rv.Kind() == reflect.Ptr { - vp, _ := rv2i(rv).(*map[uint64]int32) - if *vp == nil { - *vp = make(map[uint64]int32, decInferLen(containerLen, d.maxInitLen(), 12)) - } - if containerLen != 0 { - ft.DecMapUint64Int32L(*vp, containerLen, d) - } - } else if containerLen != 0 { - ft.DecMapUint64Int32L(rv2i(rv).(map[uint64]int32), containerLen, d) - } - d.mapEnd() -} -func (fastpathDTBincBytes) DecMapUint64Int32L(v map[uint64]int32, containerLen int, d *decoderBincBytes) { - if v == nil { - halt.errorInt("cannot decode into nil map[uint64]int32 given stream length: ", int64(containerLen)) - } - hasLen := containerLen >= 0 - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - mk := d.d.DecodeUint64() - d.mapElemValue() - v[mk] = int32(chkOvf.IntV(d.d.DecodeInt64(), 32)) - } -} -func (d *decoderBincBytes) fastpathDecMapUint64Float64R(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTBincBytes - containerLen := d.mapStart(d.d.ReadMapStart()) - if rv.Kind() == reflect.Ptr { - vp, _ := rv2i(rv).(*map[uint64]float64) - if *vp == nil { - *vp = make(map[uint64]float64, decInferLen(containerLen, d.maxInitLen(), 16)) - } - if containerLen != 0 { - ft.DecMapUint64Float64L(*vp, containerLen, d) - } - } else if containerLen != 0 { - ft.DecMapUint64Float64L(rv2i(rv).(map[uint64]float64), containerLen, d) - } - d.mapEnd() -} -func (fastpathDTBincBytes) DecMapUint64Float64L(v map[uint64]float64, containerLen int, d *decoderBincBytes) { - if v == nil { - halt.errorInt("cannot decode into nil map[uint64]float64 given stream length: ", int64(containerLen)) - } - hasLen := containerLen >= 0 - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - mk := d.d.DecodeUint64() - d.mapElemValue() - v[mk] = d.d.DecodeFloat64() - } -} -func (d *decoderBincBytes) fastpathDecMapUint64BoolR(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTBincBytes - containerLen := d.mapStart(d.d.ReadMapStart()) - if rv.Kind() == reflect.Ptr { - vp, _ := rv2i(rv).(*map[uint64]bool) - if *vp == nil { - *vp = make(map[uint64]bool, decInferLen(containerLen, d.maxInitLen(), 9)) - } - if containerLen != 0 { - ft.DecMapUint64BoolL(*vp, containerLen, d) - } - } else if containerLen != 0 { - ft.DecMapUint64BoolL(rv2i(rv).(map[uint64]bool), containerLen, d) - } - d.mapEnd() -} -func (fastpathDTBincBytes) DecMapUint64BoolL(v map[uint64]bool, containerLen int, d *decoderBincBytes) { - if v == nil { - halt.errorInt("cannot decode into nil map[uint64]bool given stream length: ", int64(containerLen)) - } - hasLen := containerLen >= 0 - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - mk := d.d.DecodeUint64() - d.mapElemValue() - v[mk] = d.d.DecodeBool() - } -} -func (d *decoderBincBytes) fastpathDecMapIntIntfR(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTBincBytes - containerLen := d.mapStart(d.d.ReadMapStart()) - if rv.Kind() == reflect.Ptr { - vp, _ := rv2i(rv).(*map[int]interface{}) - if *vp == nil { - *vp = make(map[int]interface{}, decInferLen(containerLen, d.maxInitLen(), 24)) - } - if containerLen != 0 { - ft.DecMapIntIntfL(*vp, containerLen, d) - } - } else if containerLen != 0 { - ft.DecMapIntIntfL(rv2i(rv).(map[int]interface{}), containerLen, d) - } - d.mapEnd() -} -func (fastpathDTBincBytes) DecMapIntIntfL(v map[int]interface{}, containerLen int, d *decoderBincBytes) { - if v == nil { - halt.errorInt("cannot decode into nil map[int]interface{} given stream length: ", int64(containerLen)) - } - var mv interface{} - mapGet := !d.h.MapValueReset && !d.h.InterfaceReset - hasLen := containerLen >= 0 - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - mk := int(chkOvf.IntV(d.d.DecodeInt64(), intBitsize)) - d.mapElemValue() - if mapGet { - mv = v[mk] - } else { - mv = nil - } - d.decode(&mv) - v[mk] = mv - } -} -func (d *decoderBincBytes) fastpathDecMapIntStringR(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTBincBytes - containerLen := d.mapStart(d.d.ReadMapStart()) - if rv.Kind() == reflect.Ptr { - vp, _ := rv2i(rv).(*map[int]string) - if *vp == nil { - *vp = make(map[int]string, decInferLen(containerLen, d.maxInitLen(), 24)) - } - if containerLen != 0 { - ft.DecMapIntStringL(*vp, containerLen, d) - } - } else if containerLen != 0 { - ft.DecMapIntStringL(rv2i(rv).(map[int]string), containerLen, d) - } - d.mapEnd() -} -func (fastpathDTBincBytes) DecMapIntStringL(v map[int]string, containerLen int, d *decoderBincBytes) { - if v == nil { - halt.errorInt("cannot decode into nil map[int]string given stream length: ", int64(containerLen)) - } - hasLen := containerLen >= 0 - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - mk := int(chkOvf.IntV(d.d.DecodeInt64(), intBitsize)) - d.mapElemValue() - v[mk] = d.detach2Str(d.d.DecodeStringAsBytes()) - } -} -func (d *decoderBincBytes) fastpathDecMapIntBytesR(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTBincBytes - containerLen := d.mapStart(d.d.ReadMapStart()) - if rv.Kind() == reflect.Ptr { - vp, _ := rv2i(rv).(*map[int][]byte) - if *vp == nil { - *vp = make(map[int][]byte, decInferLen(containerLen, d.maxInitLen(), 32)) - } - if containerLen != 0 { - ft.DecMapIntBytesL(*vp, containerLen, d) - } - } else if containerLen != 0 { - ft.DecMapIntBytesL(rv2i(rv).(map[int][]byte), containerLen, d) - } - d.mapEnd() -} -func (fastpathDTBincBytes) DecMapIntBytesL(v map[int][]byte, containerLen int, d *decoderBincBytes) { - if v == nil { - halt.errorInt("cannot decode into nil map[int][]byte given stream length: ", int64(containerLen)) - } - var mv []byte - mapGet := !d.h.MapValueReset - hasLen := containerLen >= 0 - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - mk := int(chkOvf.IntV(d.d.DecodeInt64(), intBitsize)) - d.mapElemValue() - if mapGet { - mv = v[mk] - } else { - mv = nil - } - v[mk], _ = d.decodeBytesInto(mv, false) - } -} -func (d *decoderBincBytes) fastpathDecMapIntUint8R(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTBincBytes - containerLen := d.mapStart(d.d.ReadMapStart()) - if rv.Kind() == reflect.Ptr { - vp, _ := rv2i(rv).(*map[int]uint8) - if *vp == nil { - *vp = make(map[int]uint8, decInferLen(containerLen, d.maxInitLen(), 9)) - } - if containerLen != 0 { - ft.DecMapIntUint8L(*vp, containerLen, d) - } - } else if containerLen != 0 { - ft.DecMapIntUint8L(rv2i(rv).(map[int]uint8), containerLen, d) - } - d.mapEnd() -} -func (fastpathDTBincBytes) DecMapIntUint8L(v map[int]uint8, containerLen int, d *decoderBincBytes) { - if v == nil { - halt.errorInt("cannot decode into nil map[int]uint8 given stream length: ", int64(containerLen)) - } - hasLen := containerLen >= 0 - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - mk := int(chkOvf.IntV(d.d.DecodeInt64(), intBitsize)) - d.mapElemValue() - v[mk] = uint8(chkOvf.UintV(d.d.DecodeUint64(), 8)) - } -} -func (d *decoderBincBytes) fastpathDecMapIntUint64R(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTBincBytes - containerLen := d.mapStart(d.d.ReadMapStart()) - if rv.Kind() == reflect.Ptr { - vp, _ := rv2i(rv).(*map[int]uint64) - if *vp == nil { - *vp = make(map[int]uint64, decInferLen(containerLen, d.maxInitLen(), 16)) - } - if containerLen != 0 { - ft.DecMapIntUint64L(*vp, containerLen, d) - } - } else if containerLen != 0 { - ft.DecMapIntUint64L(rv2i(rv).(map[int]uint64), containerLen, d) - } - d.mapEnd() -} -func (fastpathDTBincBytes) DecMapIntUint64L(v map[int]uint64, containerLen int, d *decoderBincBytes) { - if v == nil { - halt.errorInt("cannot decode into nil map[int]uint64 given stream length: ", int64(containerLen)) - } - hasLen := containerLen >= 0 - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - mk := int(chkOvf.IntV(d.d.DecodeInt64(), intBitsize)) - d.mapElemValue() - v[mk] = d.d.DecodeUint64() - } -} -func (d *decoderBincBytes) fastpathDecMapIntIntR(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTBincBytes - containerLen := d.mapStart(d.d.ReadMapStart()) - if rv.Kind() == reflect.Ptr { - vp, _ := rv2i(rv).(*map[int]int) - if *vp == nil { - *vp = make(map[int]int, decInferLen(containerLen, d.maxInitLen(), 16)) - } - if containerLen != 0 { - ft.DecMapIntIntL(*vp, containerLen, d) - } - } else if containerLen != 0 { - ft.DecMapIntIntL(rv2i(rv).(map[int]int), containerLen, d) - } - d.mapEnd() -} -func (fastpathDTBincBytes) DecMapIntIntL(v map[int]int, containerLen int, d *decoderBincBytes) { - if v == nil { - halt.errorInt("cannot decode into nil map[int]int given stream length: ", int64(containerLen)) - } - hasLen := containerLen >= 0 - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - mk := int(chkOvf.IntV(d.d.DecodeInt64(), intBitsize)) - d.mapElemValue() - v[mk] = int(chkOvf.IntV(d.d.DecodeInt64(), intBitsize)) - } -} -func (d *decoderBincBytes) fastpathDecMapIntInt32R(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTBincBytes - containerLen := d.mapStart(d.d.ReadMapStart()) - if rv.Kind() == reflect.Ptr { - vp, _ := rv2i(rv).(*map[int]int32) - if *vp == nil { - *vp = make(map[int]int32, decInferLen(containerLen, d.maxInitLen(), 12)) - } - if containerLen != 0 { - ft.DecMapIntInt32L(*vp, containerLen, d) - } - } else if containerLen != 0 { - ft.DecMapIntInt32L(rv2i(rv).(map[int]int32), containerLen, d) - } - d.mapEnd() -} -func (fastpathDTBincBytes) DecMapIntInt32L(v map[int]int32, containerLen int, d *decoderBincBytes) { - if v == nil { - halt.errorInt("cannot decode into nil map[int]int32 given stream length: ", int64(containerLen)) - } - hasLen := containerLen >= 0 - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - mk := int(chkOvf.IntV(d.d.DecodeInt64(), intBitsize)) - d.mapElemValue() - v[mk] = int32(chkOvf.IntV(d.d.DecodeInt64(), 32)) - } -} -func (d *decoderBincBytes) fastpathDecMapIntFloat64R(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTBincBytes - containerLen := d.mapStart(d.d.ReadMapStart()) - if rv.Kind() == reflect.Ptr { - vp, _ := rv2i(rv).(*map[int]float64) - if *vp == nil { - *vp = make(map[int]float64, decInferLen(containerLen, d.maxInitLen(), 16)) - } - if containerLen != 0 { - ft.DecMapIntFloat64L(*vp, containerLen, d) - } - } else if containerLen != 0 { - ft.DecMapIntFloat64L(rv2i(rv).(map[int]float64), containerLen, d) - } - d.mapEnd() -} -func (fastpathDTBincBytes) DecMapIntFloat64L(v map[int]float64, containerLen int, d *decoderBincBytes) { - if v == nil { - halt.errorInt("cannot decode into nil map[int]float64 given stream length: ", int64(containerLen)) - } - hasLen := containerLen >= 0 - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - mk := int(chkOvf.IntV(d.d.DecodeInt64(), intBitsize)) - d.mapElemValue() - v[mk] = d.d.DecodeFloat64() - } -} -func (d *decoderBincBytes) fastpathDecMapIntBoolR(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTBincBytes - containerLen := d.mapStart(d.d.ReadMapStart()) - if rv.Kind() == reflect.Ptr { - vp, _ := rv2i(rv).(*map[int]bool) - if *vp == nil { - *vp = make(map[int]bool, decInferLen(containerLen, d.maxInitLen(), 9)) - } - if containerLen != 0 { - ft.DecMapIntBoolL(*vp, containerLen, d) - } - } else if containerLen != 0 { - ft.DecMapIntBoolL(rv2i(rv).(map[int]bool), containerLen, d) - } - d.mapEnd() -} -func (fastpathDTBincBytes) DecMapIntBoolL(v map[int]bool, containerLen int, d *decoderBincBytes) { - if v == nil { - halt.errorInt("cannot decode into nil map[int]bool given stream length: ", int64(containerLen)) - } - hasLen := containerLen >= 0 - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - mk := int(chkOvf.IntV(d.d.DecodeInt64(), intBitsize)) - d.mapElemValue() - v[mk] = d.d.DecodeBool() - } -} -func (d *decoderBincBytes) fastpathDecMapInt32IntfR(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTBincBytes - containerLen := d.mapStart(d.d.ReadMapStart()) - if rv.Kind() == reflect.Ptr { - vp, _ := rv2i(rv).(*map[int32]interface{}) - if *vp == nil { - *vp = make(map[int32]interface{}, decInferLen(containerLen, d.maxInitLen(), 20)) - } - if containerLen != 0 { - ft.DecMapInt32IntfL(*vp, containerLen, d) - } - } else if containerLen != 0 { - ft.DecMapInt32IntfL(rv2i(rv).(map[int32]interface{}), containerLen, d) - } - d.mapEnd() -} -func (fastpathDTBincBytes) DecMapInt32IntfL(v map[int32]interface{}, containerLen int, d *decoderBincBytes) { - if v == nil { - halt.errorInt("cannot decode into nil map[int32]interface{} given stream length: ", int64(containerLen)) - } - var mv interface{} - mapGet := !d.h.MapValueReset && !d.h.InterfaceReset - hasLen := containerLen >= 0 - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - mk := int32(chkOvf.IntV(d.d.DecodeInt64(), 32)) - d.mapElemValue() - if mapGet { - mv = v[mk] - } else { - mv = nil - } - d.decode(&mv) - v[mk] = mv - } -} -func (d *decoderBincBytes) fastpathDecMapInt32StringR(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTBincBytes - containerLen := d.mapStart(d.d.ReadMapStart()) - if rv.Kind() == reflect.Ptr { - vp, _ := rv2i(rv).(*map[int32]string) - if *vp == nil { - *vp = make(map[int32]string, decInferLen(containerLen, d.maxInitLen(), 20)) - } - if containerLen != 0 { - ft.DecMapInt32StringL(*vp, containerLen, d) - } - } else if containerLen != 0 { - ft.DecMapInt32StringL(rv2i(rv).(map[int32]string), containerLen, d) - } - d.mapEnd() -} -func (fastpathDTBincBytes) DecMapInt32StringL(v map[int32]string, containerLen int, d *decoderBincBytes) { - if v == nil { - halt.errorInt("cannot decode into nil map[int32]string given stream length: ", int64(containerLen)) - } - hasLen := containerLen >= 0 - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - mk := int32(chkOvf.IntV(d.d.DecodeInt64(), 32)) - d.mapElemValue() - v[mk] = d.detach2Str(d.d.DecodeStringAsBytes()) - } -} -func (d *decoderBincBytes) fastpathDecMapInt32BytesR(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTBincBytes - containerLen := d.mapStart(d.d.ReadMapStart()) - if rv.Kind() == reflect.Ptr { - vp, _ := rv2i(rv).(*map[int32][]byte) - if *vp == nil { - *vp = make(map[int32][]byte, decInferLen(containerLen, d.maxInitLen(), 28)) - } - if containerLen != 0 { - ft.DecMapInt32BytesL(*vp, containerLen, d) - } - } else if containerLen != 0 { - ft.DecMapInt32BytesL(rv2i(rv).(map[int32][]byte), containerLen, d) - } - d.mapEnd() -} -func (fastpathDTBincBytes) DecMapInt32BytesL(v map[int32][]byte, containerLen int, d *decoderBincBytes) { - if v == nil { - halt.errorInt("cannot decode into nil map[int32][]byte given stream length: ", int64(containerLen)) - } - var mv []byte - mapGet := !d.h.MapValueReset - hasLen := containerLen >= 0 - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - mk := int32(chkOvf.IntV(d.d.DecodeInt64(), 32)) - d.mapElemValue() - if mapGet { - mv = v[mk] - } else { - mv = nil - } - v[mk], _ = d.decodeBytesInto(mv, false) - } -} -func (d *decoderBincBytes) fastpathDecMapInt32Uint8R(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTBincBytes - containerLen := d.mapStart(d.d.ReadMapStart()) - if rv.Kind() == reflect.Ptr { - vp, _ := rv2i(rv).(*map[int32]uint8) - if *vp == nil { - *vp = make(map[int32]uint8, decInferLen(containerLen, d.maxInitLen(), 5)) - } - if containerLen != 0 { - ft.DecMapInt32Uint8L(*vp, containerLen, d) - } - } else if containerLen != 0 { - ft.DecMapInt32Uint8L(rv2i(rv).(map[int32]uint8), containerLen, d) - } - d.mapEnd() -} -func (fastpathDTBincBytes) DecMapInt32Uint8L(v map[int32]uint8, containerLen int, d *decoderBincBytes) { - if v == nil { - halt.errorInt("cannot decode into nil map[int32]uint8 given stream length: ", int64(containerLen)) - } - hasLen := containerLen >= 0 - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - mk := int32(chkOvf.IntV(d.d.DecodeInt64(), 32)) - d.mapElemValue() - v[mk] = uint8(chkOvf.UintV(d.d.DecodeUint64(), 8)) - } -} -func (d *decoderBincBytes) fastpathDecMapInt32Uint64R(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTBincBytes - containerLen := d.mapStart(d.d.ReadMapStart()) - if rv.Kind() == reflect.Ptr { - vp, _ := rv2i(rv).(*map[int32]uint64) - if *vp == nil { - *vp = make(map[int32]uint64, decInferLen(containerLen, d.maxInitLen(), 12)) - } - if containerLen != 0 { - ft.DecMapInt32Uint64L(*vp, containerLen, d) - } - } else if containerLen != 0 { - ft.DecMapInt32Uint64L(rv2i(rv).(map[int32]uint64), containerLen, d) - } - d.mapEnd() -} -func (fastpathDTBincBytes) DecMapInt32Uint64L(v map[int32]uint64, containerLen int, d *decoderBincBytes) { - if v == nil { - halt.errorInt("cannot decode into nil map[int32]uint64 given stream length: ", int64(containerLen)) - } - hasLen := containerLen >= 0 - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - mk := int32(chkOvf.IntV(d.d.DecodeInt64(), 32)) - d.mapElemValue() - v[mk] = d.d.DecodeUint64() - } -} -func (d *decoderBincBytes) fastpathDecMapInt32IntR(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTBincBytes - containerLen := d.mapStart(d.d.ReadMapStart()) - if rv.Kind() == reflect.Ptr { - vp, _ := rv2i(rv).(*map[int32]int) - if *vp == nil { - *vp = make(map[int32]int, decInferLen(containerLen, d.maxInitLen(), 12)) - } - if containerLen != 0 { - ft.DecMapInt32IntL(*vp, containerLen, d) - } - } else if containerLen != 0 { - ft.DecMapInt32IntL(rv2i(rv).(map[int32]int), containerLen, d) - } - d.mapEnd() -} -func (fastpathDTBincBytes) DecMapInt32IntL(v map[int32]int, containerLen int, d *decoderBincBytes) { - if v == nil { - halt.errorInt("cannot decode into nil map[int32]int given stream length: ", int64(containerLen)) - } - hasLen := containerLen >= 0 - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - mk := int32(chkOvf.IntV(d.d.DecodeInt64(), 32)) - d.mapElemValue() - v[mk] = int(chkOvf.IntV(d.d.DecodeInt64(), intBitsize)) - } -} -func (d *decoderBincBytes) fastpathDecMapInt32Int32R(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTBincBytes - containerLen := d.mapStart(d.d.ReadMapStart()) - if rv.Kind() == reflect.Ptr { - vp, _ := rv2i(rv).(*map[int32]int32) - if *vp == nil { - *vp = make(map[int32]int32, decInferLen(containerLen, d.maxInitLen(), 8)) - } - if containerLen != 0 { - ft.DecMapInt32Int32L(*vp, containerLen, d) - } - } else if containerLen != 0 { - ft.DecMapInt32Int32L(rv2i(rv).(map[int32]int32), containerLen, d) - } - d.mapEnd() -} -func (fastpathDTBincBytes) DecMapInt32Int32L(v map[int32]int32, containerLen int, d *decoderBincBytes) { - if v == nil { - halt.errorInt("cannot decode into nil map[int32]int32 given stream length: ", int64(containerLen)) - } - hasLen := containerLen >= 0 - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - mk := int32(chkOvf.IntV(d.d.DecodeInt64(), 32)) - d.mapElemValue() - v[mk] = int32(chkOvf.IntV(d.d.DecodeInt64(), 32)) - } -} -func (d *decoderBincBytes) fastpathDecMapInt32Float64R(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTBincBytes - containerLen := d.mapStart(d.d.ReadMapStart()) - if rv.Kind() == reflect.Ptr { - vp, _ := rv2i(rv).(*map[int32]float64) - if *vp == nil { - *vp = make(map[int32]float64, decInferLen(containerLen, d.maxInitLen(), 12)) - } - if containerLen != 0 { - ft.DecMapInt32Float64L(*vp, containerLen, d) - } - } else if containerLen != 0 { - ft.DecMapInt32Float64L(rv2i(rv).(map[int32]float64), containerLen, d) - } - d.mapEnd() -} -func (fastpathDTBincBytes) DecMapInt32Float64L(v map[int32]float64, containerLen int, d *decoderBincBytes) { - if v == nil { - halt.errorInt("cannot decode into nil map[int32]float64 given stream length: ", int64(containerLen)) - } - hasLen := containerLen >= 0 - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - mk := int32(chkOvf.IntV(d.d.DecodeInt64(), 32)) - d.mapElemValue() - v[mk] = d.d.DecodeFloat64() - } -} -func (d *decoderBincBytes) fastpathDecMapInt32BoolR(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTBincBytes - containerLen := d.mapStart(d.d.ReadMapStart()) - if rv.Kind() == reflect.Ptr { - vp, _ := rv2i(rv).(*map[int32]bool) - if *vp == nil { - *vp = make(map[int32]bool, decInferLen(containerLen, d.maxInitLen(), 5)) - } - if containerLen != 0 { - ft.DecMapInt32BoolL(*vp, containerLen, d) - } - } else if containerLen != 0 { - ft.DecMapInt32BoolL(rv2i(rv).(map[int32]bool), containerLen, d) - } - d.mapEnd() -} -func (fastpathDTBincBytes) DecMapInt32BoolL(v map[int32]bool, containerLen int, d *decoderBincBytes) { - if v == nil { - halt.errorInt("cannot decode into nil map[int32]bool given stream length: ", int64(containerLen)) - } - hasLen := containerLen >= 0 - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - mk := int32(chkOvf.IntV(d.d.DecodeInt64(), 32)) - d.mapElemValue() - v[mk] = d.d.DecodeBool() - } -} - -type fastpathEBincIO struct { - rtid uintptr - rt reflect.Type - encfn func(*encoderBincIO, *encFnInfo, reflect.Value) -} -type fastpathDBincIO struct { - rtid uintptr - rt reflect.Type - decfn func(*decoderBincIO, *decFnInfo, reflect.Value) -} -type fastpathEsBincIO [56]fastpathEBincIO -type fastpathDsBincIO [56]fastpathDBincIO -type fastpathETBincIO struct{} -type fastpathDTBincIO struct{} - -func (helperEncDriverBincIO) fastpathEList() *fastpathEsBincIO { - var i uint = 0 - var s fastpathEsBincIO - fn := func(v interface{}, fe func(*encoderBincIO, *encFnInfo, reflect.Value)) { - xrt := reflect.TypeOf(v) - s[i] = fastpathEBincIO{rt2id(xrt), xrt, fe} - i++ - } - - fn([]interface{}(nil), (*encoderBincIO).fastpathEncSliceIntfR) - fn([]string(nil), (*encoderBincIO).fastpathEncSliceStringR) - fn([][]byte(nil), (*encoderBincIO).fastpathEncSliceBytesR) - fn([]float32(nil), (*encoderBincIO).fastpathEncSliceFloat32R) - fn([]float64(nil), (*encoderBincIO).fastpathEncSliceFloat64R) - fn([]uint8(nil), (*encoderBincIO).fastpathEncSliceUint8R) - fn([]uint64(nil), (*encoderBincIO).fastpathEncSliceUint64R) - fn([]int(nil), (*encoderBincIO).fastpathEncSliceIntR) - fn([]int32(nil), (*encoderBincIO).fastpathEncSliceInt32R) - fn([]int64(nil), (*encoderBincIO).fastpathEncSliceInt64R) - fn([]bool(nil), (*encoderBincIO).fastpathEncSliceBoolR) - - fn(map[string]interface{}(nil), (*encoderBincIO).fastpathEncMapStringIntfR) - fn(map[string]string(nil), (*encoderBincIO).fastpathEncMapStringStringR) - fn(map[string][]byte(nil), (*encoderBincIO).fastpathEncMapStringBytesR) - fn(map[string]uint8(nil), (*encoderBincIO).fastpathEncMapStringUint8R) - fn(map[string]uint64(nil), (*encoderBincIO).fastpathEncMapStringUint64R) - fn(map[string]int(nil), (*encoderBincIO).fastpathEncMapStringIntR) - fn(map[string]int32(nil), (*encoderBincIO).fastpathEncMapStringInt32R) - fn(map[string]float64(nil), (*encoderBincIO).fastpathEncMapStringFloat64R) - fn(map[string]bool(nil), (*encoderBincIO).fastpathEncMapStringBoolR) - fn(map[uint8]interface{}(nil), (*encoderBincIO).fastpathEncMapUint8IntfR) - fn(map[uint8]string(nil), (*encoderBincIO).fastpathEncMapUint8StringR) - fn(map[uint8][]byte(nil), (*encoderBincIO).fastpathEncMapUint8BytesR) - fn(map[uint8]uint8(nil), (*encoderBincIO).fastpathEncMapUint8Uint8R) - fn(map[uint8]uint64(nil), (*encoderBincIO).fastpathEncMapUint8Uint64R) - fn(map[uint8]int(nil), (*encoderBincIO).fastpathEncMapUint8IntR) - fn(map[uint8]int32(nil), (*encoderBincIO).fastpathEncMapUint8Int32R) - fn(map[uint8]float64(nil), (*encoderBincIO).fastpathEncMapUint8Float64R) - fn(map[uint8]bool(nil), (*encoderBincIO).fastpathEncMapUint8BoolR) - fn(map[uint64]interface{}(nil), (*encoderBincIO).fastpathEncMapUint64IntfR) - fn(map[uint64]string(nil), (*encoderBincIO).fastpathEncMapUint64StringR) - fn(map[uint64][]byte(nil), (*encoderBincIO).fastpathEncMapUint64BytesR) - fn(map[uint64]uint8(nil), (*encoderBincIO).fastpathEncMapUint64Uint8R) - fn(map[uint64]uint64(nil), (*encoderBincIO).fastpathEncMapUint64Uint64R) - fn(map[uint64]int(nil), (*encoderBincIO).fastpathEncMapUint64IntR) - fn(map[uint64]int32(nil), (*encoderBincIO).fastpathEncMapUint64Int32R) - fn(map[uint64]float64(nil), (*encoderBincIO).fastpathEncMapUint64Float64R) - fn(map[uint64]bool(nil), (*encoderBincIO).fastpathEncMapUint64BoolR) - fn(map[int]interface{}(nil), (*encoderBincIO).fastpathEncMapIntIntfR) - fn(map[int]string(nil), (*encoderBincIO).fastpathEncMapIntStringR) - fn(map[int][]byte(nil), (*encoderBincIO).fastpathEncMapIntBytesR) - fn(map[int]uint8(nil), (*encoderBincIO).fastpathEncMapIntUint8R) - fn(map[int]uint64(nil), (*encoderBincIO).fastpathEncMapIntUint64R) - fn(map[int]int(nil), (*encoderBincIO).fastpathEncMapIntIntR) - fn(map[int]int32(nil), (*encoderBincIO).fastpathEncMapIntInt32R) - fn(map[int]float64(nil), (*encoderBincIO).fastpathEncMapIntFloat64R) - fn(map[int]bool(nil), (*encoderBincIO).fastpathEncMapIntBoolR) - fn(map[int32]interface{}(nil), (*encoderBincIO).fastpathEncMapInt32IntfR) - fn(map[int32]string(nil), (*encoderBincIO).fastpathEncMapInt32StringR) - fn(map[int32][]byte(nil), (*encoderBincIO).fastpathEncMapInt32BytesR) - fn(map[int32]uint8(nil), (*encoderBincIO).fastpathEncMapInt32Uint8R) - fn(map[int32]uint64(nil), (*encoderBincIO).fastpathEncMapInt32Uint64R) - fn(map[int32]int(nil), (*encoderBincIO).fastpathEncMapInt32IntR) - fn(map[int32]int32(nil), (*encoderBincIO).fastpathEncMapInt32Int32R) - fn(map[int32]float64(nil), (*encoderBincIO).fastpathEncMapInt32Float64R) - fn(map[int32]bool(nil), (*encoderBincIO).fastpathEncMapInt32BoolR) - - sort.Slice(s[:], func(i, j int) bool { return s[i].rtid < s[j].rtid }) - return &s -} - -func (helperDecDriverBincIO) fastpathDList() *fastpathDsBincIO { - var i uint = 0 - var s fastpathDsBincIO - fn := func(v interface{}, fd func(*decoderBincIO, *decFnInfo, reflect.Value)) { - xrt := reflect.TypeOf(v) - s[i] = fastpathDBincIO{rt2id(xrt), xrt, fd} - i++ - } - - fn([]interface{}(nil), (*decoderBincIO).fastpathDecSliceIntfR) - fn([]string(nil), (*decoderBincIO).fastpathDecSliceStringR) - fn([][]byte(nil), (*decoderBincIO).fastpathDecSliceBytesR) - fn([]float32(nil), (*decoderBincIO).fastpathDecSliceFloat32R) - fn([]float64(nil), (*decoderBincIO).fastpathDecSliceFloat64R) - fn([]uint8(nil), (*decoderBincIO).fastpathDecSliceUint8R) - fn([]uint64(nil), (*decoderBincIO).fastpathDecSliceUint64R) - fn([]int(nil), (*decoderBincIO).fastpathDecSliceIntR) - fn([]int32(nil), (*decoderBincIO).fastpathDecSliceInt32R) - fn([]int64(nil), (*decoderBincIO).fastpathDecSliceInt64R) - fn([]bool(nil), (*decoderBincIO).fastpathDecSliceBoolR) - - fn(map[string]interface{}(nil), (*decoderBincIO).fastpathDecMapStringIntfR) - fn(map[string]string(nil), (*decoderBincIO).fastpathDecMapStringStringR) - fn(map[string][]byte(nil), (*decoderBincIO).fastpathDecMapStringBytesR) - fn(map[string]uint8(nil), (*decoderBincIO).fastpathDecMapStringUint8R) - fn(map[string]uint64(nil), (*decoderBincIO).fastpathDecMapStringUint64R) - fn(map[string]int(nil), (*decoderBincIO).fastpathDecMapStringIntR) - fn(map[string]int32(nil), (*decoderBincIO).fastpathDecMapStringInt32R) - fn(map[string]float64(nil), (*decoderBincIO).fastpathDecMapStringFloat64R) - fn(map[string]bool(nil), (*decoderBincIO).fastpathDecMapStringBoolR) - fn(map[uint8]interface{}(nil), (*decoderBincIO).fastpathDecMapUint8IntfR) - fn(map[uint8]string(nil), (*decoderBincIO).fastpathDecMapUint8StringR) - fn(map[uint8][]byte(nil), (*decoderBincIO).fastpathDecMapUint8BytesR) - fn(map[uint8]uint8(nil), (*decoderBincIO).fastpathDecMapUint8Uint8R) - fn(map[uint8]uint64(nil), (*decoderBincIO).fastpathDecMapUint8Uint64R) - fn(map[uint8]int(nil), (*decoderBincIO).fastpathDecMapUint8IntR) - fn(map[uint8]int32(nil), (*decoderBincIO).fastpathDecMapUint8Int32R) - fn(map[uint8]float64(nil), (*decoderBincIO).fastpathDecMapUint8Float64R) - fn(map[uint8]bool(nil), (*decoderBincIO).fastpathDecMapUint8BoolR) - fn(map[uint64]interface{}(nil), (*decoderBincIO).fastpathDecMapUint64IntfR) - fn(map[uint64]string(nil), (*decoderBincIO).fastpathDecMapUint64StringR) - fn(map[uint64][]byte(nil), (*decoderBincIO).fastpathDecMapUint64BytesR) - fn(map[uint64]uint8(nil), (*decoderBincIO).fastpathDecMapUint64Uint8R) - fn(map[uint64]uint64(nil), (*decoderBincIO).fastpathDecMapUint64Uint64R) - fn(map[uint64]int(nil), (*decoderBincIO).fastpathDecMapUint64IntR) - fn(map[uint64]int32(nil), (*decoderBincIO).fastpathDecMapUint64Int32R) - fn(map[uint64]float64(nil), (*decoderBincIO).fastpathDecMapUint64Float64R) - fn(map[uint64]bool(nil), (*decoderBincIO).fastpathDecMapUint64BoolR) - fn(map[int]interface{}(nil), (*decoderBincIO).fastpathDecMapIntIntfR) - fn(map[int]string(nil), (*decoderBincIO).fastpathDecMapIntStringR) - fn(map[int][]byte(nil), (*decoderBincIO).fastpathDecMapIntBytesR) - fn(map[int]uint8(nil), (*decoderBincIO).fastpathDecMapIntUint8R) - fn(map[int]uint64(nil), (*decoderBincIO).fastpathDecMapIntUint64R) - fn(map[int]int(nil), (*decoderBincIO).fastpathDecMapIntIntR) - fn(map[int]int32(nil), (*decoderBincIO).fastpathDecMapIntInt32R) - fn(map[int]float64(nil), (*decoderBincIO).fastpathDecMapIntFloat64R) - fn(map[int]bool(nil), (*decoderBincIO).fastpathDecMapIntBoolR) - fn(map[int32]interface{}(nil), (*decoderBincIO).fastpathDecMapInt32IntfR) - fn(map[int32]string(nil), (*decoderBincIO).fastpathDecMapInt32StringR) - fn(map[int32][]byte(nil), (*decoderBincIO).fastpathDecMapInt32BytesR) - fn(map[int32]uint8(nil), (*decoderBincIO).fastpathDecMapInt32Uint8R) - fn(map[int32]uint64(nil), (*decoderBincIO).fastpathDecMapInt32Uint64R) - fn(map[int32]int(nil), (*decoderBincIO).fastpathDecMapInt32IntR) - fn(map[int32]int32(nil), (*decoderBincIO).fastpathDecMapInt32Int32R) - fn(map[int32]float64(nil), (*decoderBincIO).fastpathDecMapInt32Float64R) - fn(map[int32]bool(nil), (*decoderBincIO).fastpathDecMapInt32BoolR) - - sort.Slice(s[:], func(i, j int) bool { return s[i].rtid < s[j].rtid }) - return &s -} - -func (helperEncDriverBincIO) fastpathEncodeTypeSwitch(iv interface{}, e *encoderBincIO) bool { - var ft fastpathETBincIO - switch v := iv.(type) { - case []interface{}: - if v == nil { - e.e.writeNilArray() - } else { - ft.EncSliceIntfV(v, e) - } - case []string: - if v == nil { - e.e.writeNilArray() - } else { - ft.EncSliceStringV(v, e) - } - case [][]byte: - if v == nil { - e.e.writeNilArray() - } else { - ft.EncSliceBytesV(v, e) - } - case []float32: - if v == nil { - e.e.writeNilArray() - } else { - ft.EncSliceFloat32V(v, e) - } - case []float64: - if v == nil { - e.e.writeNilArray() - } else { - ft.EncSliceFloat64V(v, e) - } - case []uint8: - if v == nil { - e.e.writeNilArray() - } else { - ft.EncSliceUint8V(v, e) - } - case []uint64: - if v == nil { - e.e.writeNilArray() - } else { - ft.EncSliceUint64V(v, e) - } - case []int: - if v == nil { - e.e.writeNilArray() - } else { - ft.EncSliceIntV(v, e) - } - case []int32: - if v == nil { - e.e.writeNilArray() - } else { - ft.EncSliceInt32V(v, e) - } - case []int64: - if v == nil { - e.e.writeNilArray() - } else { - ft.EncSliceInt64V(v, e) - } - case []bool: - if v == nil { - e.e.writeNilArray() - } else { - ft.EncSliceBoolV(v, e) - } - case map[string]interface{}: - if v == nil { - e.e.writeNilMap() - } else { - ft.EncMapStringIntfV(v, e) - } - case map[string]string: - if v == nil { - e.e.writeNilMap() - } else { - ft.EncMapStringStringV(v, e) - } - case map[string][]byte: - if v == nil { - e.e.writeNilMap() - } else { - ft.EncMapStringBytesV(v, e) - } - case map[string]uint8: - if v == nil { - e.e.writeNilMap() - } else { - ft.EncMapStringUint8V(v, e) - } - case map[string]uint64: - if v == nil { - e.e.writeNilMap() - } else { - ft.EncMapStringUint64V(v, e) - } - case map[string]int: - if v == nil { - e.e.writeNilMap() - } else { - ft.EncMapStringIntV(v, e) - } - case map[string]int32: - if v == nil { - e.e.writeNilMap() - } else { - ft.EncMapStringInt32V(v, e) - } - case map[string]float64: - if v == nil { - e.e.writeNilMap() - } else { - ft.EncMapStringFloat64V(v, e) - } - case map[string]bool: - if v == nil { - e.e.writeNilMap() - } else { - ft.EncMapStringBoolV(v, e) - } - case map[uint8]interface{}: - if v == nil { - e.e.writeNilMap() - } else { - ft.EncMapUint8IntfV(v, e) - } - case map[uint8]string: - if v == nil { - e.e.writeNilMap() - } else { - ft.EncMapUint8StringV(v, e) - } - case map[uint8][]byte: - if v == nil { - e.e.writeNilMap() - } else { - ft.EncMapUint8BytesV(v, e) - } - case map[uint8]uint8: - if v == nil { - e.e.writeNilMap() - } else { - ft.EncMapUint8Uint8V(v, e) - } - case map[uint8]uint64: - if v == nil { - e.e.writeNilMap() - } else { - ft.EncMapUint8Uint64V(v, e) - } - case map[uint8]int: - if v == nil { - e.e.writeNilMap() - } else { - ft.EncMapUint8IntV(v, e) - } - case map[uint8]int32: - if v == nil { - e.e.writeNilMap() - } else { - ft.EncMapUint8Int32V(v, e) - } - case map[uint8]float64: - if v == nil { - e.e.writeNilMap() - } else { - ft.EncMapUint8Float64V(v, e) - } - case map[uint8]bool: - if v == nil { - e.e.writeNilMap() - } else { - ft.EncMapUint8BoolV(v, e) - } - case map[uint64]interface{}: - if v == nil { - e.e.writeNilMap() - } else { - ft.EncMapUint64IntfV(v, e) - } - case map[uint64]string: - if v == nil { - e.e.writeNilMap() - } else { - ft.EncMapUint64StringV(v, e) - } - case map[uint64][]byte: - if v == nil { - e.e.writeNilMap() - } else { - ft.EncMapUint64BytesV(v, e) - } - case map[uint64]uint8: - if v == nil { - e.e.writeNilMap() - } else { - ft.EncMapUint64Uint8V(v, e) - } - case map[uint64]uint64: - if v == nil { - e.e.writeNilMap() - } else { - ft.EncMapUint64Uint64V(v, e) - } - case map[uint64]int: - if v == nil { - e.e.writeNilMap() - } else { - ft.EncMapUint64IntV(v, e) - } - case map[uint64]int32: - if v == nil { - e.e.writeNilMap() - } else { - ft.EncMapUint64Int32V(v, e) - } - case map[uint64]float64: - if v == nil { - e.e.writeNilMap() - } else { - ft.EncMapUint64Float64V(v, e) - } - case map[uint64]bool: - if v == nil { - e.e.writeNilMap() - } else { - ft.EncMapUint64BoolV(v, e) - } - case map[int]interface{}: - if v == nil { - e.e.writeNilMap() - } else { - ft.EncMapIntIntfV(v, e) - } - case map[int]string: - if v == nil { - e.e.writeNilMap() - } else { - ft.EncMapIntStringV(v, e) - } - case map[int][]byte: - if v == nil { - e.e.writeNilMap() - } else { - ft.EncMapIntBytesV(v, e) - } - case map[int]uint8: - if v == nil { - e.e.writeNilMap() - } else { - ft.EncMapIntUint8V(v, e) - } - case map[int]uint64: - if v == nil { - e.e.writeNilMap() - } else { - ft.EncMapIntUint64V(v, e) - } - case map[int]int: - if v == nil { - e.e.writeNilMap() - } else { - ft.EncMapIntIntV(v, e) - } - case map[int]int32: - if v == nil { - e.e.writeNilMap() - } else { - ft.EncMapIntInt32V(v, e) - } - case map[int]float64: - if v == nil { - e.e.writeNilMap() - } else { - ft.EncMapIntFloat64V(v, e) - } - case map[int]bool: - if v == nil { - e.e.writeNilMap() - } else { - ft.EncMapIntBoolV(v, e) - } - case map[int32]interface{}: - if v == nil { - e.e.writeNilMap() - } else { - ft.EncMapInt32IntfV(v, e) - } - case map[int32]string: - if v == nil { - e.e.writeNilMap() - } else { - ft.EncMapInt32StringV(v, e) - } - case map[int32][]byte: - if v == nil { - e.e.writeNilMap() - } else { - ft.EncMapInt32BytesV(v, e) - } - case map[int32]uint8: - if v == nil { - e.e.writeNilMap() - } else { - ft.EncMapInt32Uint8V(v, e) - } - case map[int32]uint64: - if v == nil { - e.e.writeNilMap() - } else { - ft.EncMapInt32Uint64V(v, e) - } - case map[int32]int: - if v == nil { - e.e.writeNilMap() - } else { - ft.EncMapInt32IntV(v, e) - } - case map[int32]int32: - if v == nil { - e.e.writeNilMap() - } else { - ft.EncMapInt32Int32V(v, e) - } - case map[int32]float64: - if v == nil { - e.e.writeNilMap() - } else { - ft.EncMapInt32Float64V(v, e) - } - case map[int32]bool: - if v == nil { - e.e.writeNilMap() - } else { - ft.EncMapInt32BoolV(v, e) - } - default: - _ = v - return false - } - return true -} - -func (e *encoderBincIO) fastpathEncSliceIntfR(f *encFnInfo, rv reflect.Value) { - var ft fastpathETBincIO - var v []interface{} - if rv.Kind() == reflect.Array { - rvGetSlice4Array(rv, &v) - } else { - v = rv2i(rv).([]interface{}) - } - if f.ti.mbs { - ft.EncAsMapSliceIntfV(v, e) - return - } - ft.EncSliceIntfV(v, e) -} -func (fastpathETBincIO) EncSliceIntfV(v []interface{}, e *encoderBincIO) { - if len(v) == 0 { - e.c = 0 - e.e.WriteArrayEmpty() - return - } - e.arrayStart(len(v)) - for j := range v { - e.c = containerArrayElem - e.e.WriteArrayElem(j == 0) - if !e.encodeBuiltin(v[j]) { - e.encodeR(reflect.ValueOf(v[j])) - } - } - e.c = 0 - e.e.WriteArrayEnd() -} -func (fastpathETBincIO) EncAsMapSliceIntfV(v []interface{}, e *encoderBincIO) { - if len(v) == 0 { - e.c = 0 - e.e.WriteMapEmpty() - return - } - e.haltOnMbsOddLen(len(v)) - e.mapStart(len(v) >> 1) - for j := range v { - if j&1 == 0 { - e.c = containerMapKey - e.e.WriteMapElemKey(j == 0) - } else { - e.mapElemValue() - } - if !e.encodeBuiltin(v[j]) { - e.encodeR(reflect.ValueOf(v[j])) - } - } - e.c = 0 - e.e.WriteMapEnd() -} - -func (e *encoderBincIO) fastpathEncSliceStringR(f *encFnInfo, rv reflect.Value) { - var ft fastpathETBincIO - var v []string - if rv.Kind() == reflect.Array { - rvGetSlice4Array(rv, &v) - } else { - v = rv2i(rv).([]string) - } - if f.ti.mbs { - ft.EncAsMapSliceStringV(v, e) - return - } - ft.EncSliceStringV(v, e) -} -func (fastpathETBincIO) EncSliceStringV(v []string, e *encoderBincIO) { - if len(v) == 0 { - e.c = 0 - e.e.WriteArrayEmpty() - return - } - e.arrayStart(len(v)) - for j := range v { - e.c = containerArrayElem - e.e.WriteArrayElem(j == 0) - e.e.EncodeString(v[j]) - } - e.c = 0 - e.e.WriteArrayEnd() -} -func (fastpathETBincIO) EncAsMapSliceStringV(v []string, e *encoderBincIO) { - if len(v) == 0 { - e.c = 0 - e.e.WriteMapEmpty() - return - } - e.haltOnMbsOddLen(len(v)) - e.mapStart(len(v) >> 1) - for j := range v { - if j&1 == 0 { - e.c = containerMapKey - e.e.WriteMapElemKey(j == 0) - } else { - e.mapElemValue() - } - e.e.EncodeString(v[j]) - } - e.c = 0 - e.e.WriteMapEnd() -} - -func (e *encoderBincIO) fastpathEncSliceBytesR(f *encFnInfo, rv reflect.Value) { - var ft fastpathETBincIO - var v [][]byte - if rv.Kind() == reflect.Array { - rvGetSlice4Array(rv, &v) - } else { - v = rv2i(rv).([][]byte) - } - if f.ti.mbs { - ft.EncAsMapSliceBytesV(v, e) - return - } - ft.EncSliceBytesV(v, e) -} -func (fastpathETBincIO) EncSliceBytesV(v [][]byte, e *encoderBincIO) { - if len(v) == 0 { - e.c = 0 - e.e.WriteArrayEmpty() - return - } - e.arrayStart(len(v)) - for j := range v { - e.c = containerArrayElem - e.e.WriteArrayElem(j == 0) - e.e.EncodeBytes(v[j]) - } - e.c = 0 - e.e.WriteArrayEnd() -} -func (fastpathETBincIO) EncAsMapSliceBytesV(v [][]byte, e *encoderBincIO) { - if len(v) == 0 { - e.c = 0 - e.e.WriteMapEmpty() - return - } - e.haltOnMbsOddLen(len(v)) - e.mapStart(len(v) >> 1) - for j := range v { - if j&1 == 0 { - e.c = containerMapKey - e.e.WriteMapElemKey(j == 0) - } else { - e.mapElemValue() - } - e.e.EncodeBytes(v[j]) - } - e.c = 0 - e.e.WriteMapEnd() -} - -func (e *encoderBincIO) fastpathEncSliceFloat32R(f *encFnInfo, rv reflect.Value) { - var ft fastpathETBincIO - var v []float32 - if rv.Kind() == reflect.Array { - rvGetSlice4Array(rv, &v) - } else { - v = rv2i(rv).([]float32) - } - if f.ti.mbs { - ft.EncAsMapSliceFloat32V(v, e) - return - } - ft.EncSliceFloat32V(v, e) -} -func (fastpathETBincIO) EncSliceFloat32V(v []float32, e *encoderBincIO) { - if len(v) == 0 { - e.c = 0 - e.e.WriteArrayEmpty() - return - } - e.arrayStart(len(v)) - for j := range v { - e.c = containerArrayElem - e.e.WriteArrayElem(j == 0) - e.e.EncodeFloat32(v[j]) - } - e.c = 0 - e.e.WriteArrayEnd() -} -func (fastpathETBincIO) EncAsMapSliceFloat32V(v []float32, e *encoderBincIO) { - if len(v) == 0 { - e.c = 0 - e.e.WriteMapEmpty() - return - } - e.haltOnMbsOddLen(len(v)) - e.mapStart(len(v) >> 1) - for j := range v { - if j&1 == 0 { - e.c = containerMapKey - e.e.WriteMapElemKey(j == 0) - } else { - e.mapElemValue() - } - e.e.EncodeFloat32(v[j]) - } - e.c = 0 - e.e.WriteMapEnd() -} - -func (e *encoderBincIO) fastpathEncSliceFloat64R(f *encFnInfo, rv reflect.Value) { - var ft fastpathETBincIO - var v []float64 - if rv.Kind() == reflect.Array { - rvGetSlice4Array(rv, &v) - } else { - v = rv2i(rv).([]float64) - } - if f.ti.mbs { - ft.EncAsMapSliceFloat64V(v, e) - return - } - ft.EncSliceFloat64V(v, e) -} -func (fastpathETBincIO) EncSliceFloat64V(v []float64, e *encoderBincIO) { - if len(v) == 0 { - e.c = 0 - e.e.WriteArrayEmpty() - return - } - e.arrayStart(len(v)) - for j := range v { - e.c = containerArrayElem - e.e.WriteArrayElem(j == 0) - e.e.EncodeFloat64(v[j]) - } - e.c = 0 - e.e.WriteArrayEnd() -} -func (fastpathETBincIO) EncAsMapSliceFloat64V(v []float64, e *encoderBincIO) { - if len(v) == 0 { - e.c = 0 - e.e.WriteMapEmpty() - return - } - e.haltOnMbsOddLen(len(v)) - e.mapStart(len(v) >> 1) - for j := range v { - if j&1 == 0 { - e.c = containerMapKey - e.e.WriteMapElemKey(j == 0) - } else { - e.mapElemValue() - } - e.e.EncodeFloat64(v[j]) - } - e.c = 0 - e.e.WriteMapEnd() -} - -func (e *encoderBincIO) fastpathEncSliceUint8R(f *encFnInfo, rv reflect.Value) { - var ft fastpathETBincIO - var v []uint8 - if rv.Kind() == reflect.Array { - rvGetSlice4Array(rv, &v) - } else { - v = rv2i(rv).([]uint8) - } - if f.ti.mbs { - ft.EncAsMapSliceUint8V(v, e) - return - } - ft.EncSliceUint8V(v, e) -} -func (fastpathETBincIO) EncSliceUint8V(v []uint8, e *encoderBincIO) { - e.e.EncodeStringBytesRaw(v) -} -func (fastpathETBincIO) EncAsMapSliceUint8V(v []uint8, e *encoderBincIO) { - if len(v) == 0 { - e.c = 0 - e.e.WriteMapEmpty() - return - } - e.haltOnMbsOddLen(len(v)) - e.mapStart(len(v) >> 1) - for j := range v { - if j&1 == 0 { - e.c = containerMapKey - e.e.WriteMapElemKey(j == 0) - } else { - e.mapElemValue() - } - e.e.EncodeUint(uint64(v[j])) - } - e.c = 0 - e.e.WriteMapEnd() -} - -func (e *encoderBincIO) fastpathEncSliceUint64R(f *encFnInfo, rv reflect.Value) { - var ft fastpathETBincIO - var v []uint64 - if rv.Kind() == reflect.Array { - rvGetSlice4Array(rv, &v) - } else { - v = rv2i(rv).([]uint64) - } - if f.ti.mbs { - ft.EncAsMapSliceUint64V(v, e) - return - } - ft.EncSliceUint64V(v, e) -} -func (fastpathETBincIO) EncSliceUint64V(v []uint64, e *encoderBincIO) { - if len(v) == 0 { - e.c = 0 - e.e.WriteArrayEmpty() - return - } - e.arrayStart(len(v)) - for j := range v { - e.c = containerArrayElem - e.e.WriteArrayElem(j == 0) - e.e.EncodeUint(v[j]) - } - e.c = 0 - e.e.WriteArrayEnd() -} -func (fastpathETBincIO) EncAsMapSliceUint64V(v []uint64, e *encoderBincIO) { - if len(v) == 0 { - e.c = 0 - e.e.WriteMapEmpty() - return - } - e.haltOnMbsOddLen(len(v)) - e.mapStart(len(v) >> 1) - for j := range v { - if j&1 == 0 { - e.c = containerMapKey - e.e.WriteMapElemKey(j == 0) - } else { - e.mapElemValue() - } - e.e.EncodeUint(v[j]) - } - e.c = 0 - e.e.WriteMapEnd() -} - -func (e *encoderBincIO) fastpathEncSliceIntR(f *encFnInfo, rv reflect.Value) { - var ft fastpathETBincIO - var v []int - if rv.Kind() == reflect.Array { - rvGetSlice4Array(rv, &v) - } else { - v = rv2i(rv).([]int) - } - if f.ti.mbs { - ft.EncAsMapSliceIntV(v, e) - return - } - ft.EncSliceIntV(v, e) -} -func (fastpathETBincIO) EncSliceIntV(v []int, e *encoderBincIO) { - if len(v) == 0 { - e.c = 0 - e.e.WriteArrayEmpty() - return - } - e.arrayStart(len(v)) - for j := range v { - e.c = containerArrayElem - e.e.WriteArrayElem(j == 0) - e.e.EncodeInt(int64(v[j])) - } - e.c = 0 - e.e.WriteArrayEnd() -} -func (fastpathETBincIO) EncAsMapSliceIntV(v []int, e *encoderBincIO) { - if len(v) == 0 { - e.c = 0 - e.e.WriteMapEmpty() - return - } - e.haltOnMbsOddLen(len(v)) - e.mapStart(len(v) >> 1) - for j := range v { - if j&1 == 0 { - e.c = containerMapKey - e.e.WriteMapElemKey(j == 0) - } else { - e.mapElemValue() - } - e.e.EncodeInt(int64(v[j])) - } - e.c = 0 - e.e.WriteMapEnd() -} - -func (e *encoderBincIO) fastpathEncSliceInt32R(f *encFnInfo, rv reflect.Value) { - var ft fastpathETBincIO - var v []int32 - if rv.Kind() == reflect.Array { - rvGetSlice4Array(rv, &v) - } else { - v = rv2i(rv).([]int32) - } - if f.ti.mbs { - ft.EncAsMapSliceInt32V(v, e) - return - } - ft.EncSliceInt32V(v, e) -} -func (fastpathETBincIO) EncSliceInt32V(v []int32, e *encoderBincIO) { - if len(v) == 0 { - e.c = 0 - e.e.WriteArrayEmpty() - return - } - e.arrayStart(len(v)) - for j := range v { - e.c = containerArrayElem - e.e.WriteArrayElem(j == 0) - e.e.EncodeInt(int64(v[j])) - } - e.c = 0 - e.e.WriteArrayEnd() -} -func (fastpathETBincIO) EncAsMapSliceInt32V(v []int32, e *encoderBincIO) { - if len(v) == 0 { - e.c = 0 - e.e.WriteMapEmpty() - return - } - e.haltOnMbsOddLen(len(v)) - e.mapStart(len(v) >> 1) - for j := range v { - if j&1 == 0 { - e.c = containerMapKey - e.e.WriteMapElemKey(j == 0) - } else { - e.mapElemValue() - } - e.e.EncodeInt(int64(v[j])) - } - e.c = 0 - e.e.WriteMapEnd() -} - -func (e *encoderBincIO) fastpathEncSliceInt64R(f *encFnInfo, rv reflect.Value) { - var ft fastpathETBincIO - var v []int64 - if rv.Kind() == reflect.Array { - rvGetSlice4Array(rv, &v) - } else { - v = rv2i(rv).([]int64) - } - if f.ti.mbs { - ft.EncAsMapSliceInt64V(v, e) - return - } - ft.EncSliceInt64V(v, e) -} -func (fastpathETBincIO) EncSliceInt64V(v []int64, e *encoderBincIO) { - if len(v) == 0 { - e.c = 0 - e.e.WriteArrayEmpty() - return - } - e.arrayStart(len(v)) - for j := range v { - e.c = containerArrayElem - e.e.WriteArrayElem(j == 0) - e.e.EncodeInt(v[j]) - } - e.c = 0 - e.e.WriteArrayEnd() -} -func (fastpathETBincIO) EncAsMapSliceInt64V(v []int64, e *encoderBincIO) { - if len(v) == 0 { - e.c = 0 - e.e.WriteMapEmpty() - return - } - e.haltOnMbsOddLen(len(v)) - e.mapStart(len(v) >> 1) - for j := range v { - if j&1 == 0 { - e.c = containerMapKey - e.e.WriteMapElemKey(j == 0) - } else { - e.mapElemValue() - } - e.e.EncodeInt(v[j]) - } - e.c = 0 - e.e.WriteMapEnd() -} - -func (e *encoderBincIO) fastpathEncSliceBoolR(f *encFnInfo, rv reflect.Value) { - var ft fastpathETBincIO - var v []bool - if rv.Kind() == reflect.Array { - rvGetSlice4Array(rv, &v) - } else { - v = rv2i(rv).([]bool) - } - if f.ti.mbs { - ft.EncAsMapSliceBoolV(v, e) - return - } - ft.EncSliceBoolV(v, e) -} -func (fastpathETBincIO) EncSliceBoolV(v []bool, e *encoderBincIO) { - if len(v) == 0 { - e.c = 0 - e.e.WriteArrayEmpty() - return - } - e.arrayStart(len(v)) - for j := range v { - e.c = containerArrayElem - e.e.WriteArrayElem(j == 0) - e.e.EncodeBool(v[j]) - } - e.c = 0 - e.e.WriteArrayEnd() -} -func (fastpathETBincIO) EncAsMapSliceBoolV(v []bool, e *encoderBincIO) { - if len(v) == 0 { - e.c = 0 - e.e.WriteMapEmpty() - return - } - e.haltOnMbsOddLen(len(v)) - e.mapStart(len(v) >> 1) - for j := range v { - if j&1 == 0 { - e.c = containerMapKey - e.e.WriteMapElemKey(j == 0) - } else { - e.mapElemValue() - } - e.e.EncodeBool(v[j]) - } - e.c = 0 - e.e.WriteMapEnd() -} - -func (e *encoderBincIO) fastpathEncMapStringIntfR(f *encFnInfo, rv reflect.Value) { - fastpathETBincIO{}.EncMapStringIntfV(rv2i(rv).(map[string]interface{}), e) -} -func (fastpathETBincIO) EncMapStringIntfV(v map[string]interface{}, e *encoderBincIO) { - if len(v) == 0 { - e.e.WriteMapEmpty() - return - } - var i uint - e.mapStart(len(v)) - if e.h.Canonical { - v2 := make([]string, len(v)) - for k := range v { - v2[i] = k - i++ - } - slices.Sort(v2) - for i, k2 := range v2 { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeString(k2) - e.mapElemValue() - if !e.encodeBuiltin(v[k2]) { - e.encodeR(reflect.ValueOf(v[k2])) - } - } - } else { - i = 0 - for k2, v2 := range v { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeString(k2) - e.mapElemValue() - if !e.encodeBuiltin(v2) { - e.encodeR(reflect.ValueOf(v2)) - } - i++ - } - } - e.c = 0 - e.e.WriteMapEnd() -} -func (e *encoderBincIO) fastpathEncMapStringStringR(f *encFnInfo, rv reflect.Value) { - fastpathETBincIO{}.EncMapStringStringV(rv2i(rv).(map[string]string), e) -} -func (fastpathETBincIO) EncMapStringStringV(v map[string]string, e *encoderBincIO) { - if len(v) == 0 { - e.e.WriteMapEmpty() - return - } - var i uint - e.mapStart(len(v)) - if e.h.Canonical { - v2 := make([]string, len(v)) - for k := range v { - v2[i] = k - i++ - } - slices.Sort(v2) - for i, k2 := range v2 { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeString(k2) - e.mapElemValue() - e.e.EncodeString(v[k2]) - } - } else { - i = 0 - for k2, v2 := range v { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeString(k2) - e.mapElemValue() - e.e.EncodeString(v2) - i++ - } - } - e.c = 0 - e.e.WriteMapEnd() -} -func (e *encoderBincIO) fastpathEncMapStringBytesR(f *encFnInfo, rv reflect.Value) { - fastpathETBincIO{}.EncMapStringBytesV(rv2i(rv).(map[string][]byte), e) -} -func (fastpathETBincIO) EncMapStringBytesV(v map[string][]byte, e *encoderBincIO) { - if len(v) == 0 { - e.e.WriteMapEmpty() - return - } - var i uint - e.mapStart(len(v)) - if e.h.Canonical { - v2 := make([]string, len(v)) - for k := range v { - v2[i] = k - i++ - } - slices.Sort(v2) - for i, k2 := range v2 { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeString(k2) - e.mapElemValue() - e.e.EncodeBytes(v[k2]) - } - } else { - i = 0 - for k2, v2 := range v { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeString(k2) - e.mapElemValue() - e.e.EncodeBytes(v2) - i++ - } - } - e.c = 0 - e.e.WriteMapEnd() -} -func (e *encoderBincIO) fastpathEncMapStringUint8R(f *encFnInfo, rv reflect.Value) { - fastpathETBincIO{}.EncMapStringUint8V(rv2i(rv).(map[string]uint8), e) -} -func (fastpathETBincIO) EncMapStringUint8V(v map[string]uint8, e *encoderBincIO) { - if len(v) == 0 { - e.e.WriteMapEmpty() - return - } - var i uint - e.mapStart(len(v)) - if e.h.Canonical { - v2 := make([]string, len(v)) - for k := range v { - v2[i] = k - i++ - } - slices.Sort(v2) - for i, k2 := range v2 { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeString(k2) - e.mapElemValue() - e.e.EncodeUint(uint64(v[k2])) - } - } else { - i = 0 - for k2, v2 := range v { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeString(k2) - e.mapElemValue() - e.e.EncodeUint(uint64(v2)) - i++ - } - } - e.c = 0 - e.e.WriteMapEnd() -} -func (e *encoderBincIO) fastpathEncMapStringUint64R(f *encFnInfo, rv reflect.Value) { - fastpathETBincIO{}.EncMapStringUint64V(rv2i(rv).(map[string]uint64), e) -} -func (fastpathETBincIO) EncMapStringUint64V(v map[string]uint64, e *encoderBincIO) { - if len(v) == 0 { - e.e.WriteMapEmpty() - return - } - var i uint - e.mapStart(len(v)) - if e.h.Canonical { - v2 := make([]string, len(v)) - for k := range v { - v2[i] = k - i++ - } - slices.Sort(v2) - for i, k2 := range v2 { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeString(k2) - e.mapElemValue() - e.e.EncodeUint(v[k2]) - } - } else { - i = 0 - for k2, v2 := range v { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeString(k2) - e.mapElemValue() - e.e.EncodeUint(v2) - i++ - } - } - e.c = 0 - e.e.WriteMapEnd() -} -func (e *encoderBincIO) fastpathEncMapStringIntR(f *encFnInfo, rv reflect.Value) { - fastpathETBincIO{}.EncMapStringIntV(rv2i(rv).(map[string]int), e) -} -func (fastpathETBincIO) EncMapStringIntV(v map[string]int, e *encoderBincIO) { - if len(v) == 0 { - e.e.WriteMapEmpty() - return - } - var i uint - e.mapStart(len(v)) - if e.h.Canonical { - v2 := make([]string, len(v)) - for k := range v { - v2[i] = k - i++ - } - slices.Sort(v2) - for i, k2 := range v2 { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeString(k2) - e.mapElemValue() - e.e.EncodeInt(int64(v[k2])) - } - } else { - i = 0 - for k2, v2 := range v { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeString(k2) - e.mapElemValue() - e.e.EncodeInt(int64(v2)) - i++ - } - } - e.c = 0 - e.e.WriteMapEnd() -} -func (e *encoderBincIO) fastpathEncMapStringInt32R(f *encFnInfo, rv reflect.Value) { - fastpathETBincIO{}.EncMapStringInt32V(rv2i(rv).(map[string]int32), e) -} -func (fastpathETBincIO) EncMapStringInt32V(v map[string]int32, e *encoderBincIO) { - if len(v) == 0 { - e.e.WriteMapEmpty() - return - } - var i uint - e.mapStart(len(v)) - if e.h.Canonical { - v2 := make([]string, len(v)) - for k := range v { - v2[i] = k - i++ - } - slices.Sort(v2) - for i, k2 := range v2 { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeString(k2) - e.mapElemValue() - e.e.EncodeInt(int64(v[k2])) - } - } else { - i = 0 - for k2, v2 := range v { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeString(k2) - e.mapElemValue() - e.e.EncodeInt(int64(v2)) - i++ - } - } - e.c = 0 - e.e.WriteMapEnd() -} -func (e *encoderBincIO) fastpathEncMapStringFloat64R(f *encFnInfo, rv reflect.Value) { - fastpathETBincIO{}.EncMapStringFloat64V(rv2i(rv).(map[string]float64), e) -} -func (fastpathETBincIO) EncMapStringFloat64V(v map[string]float64, e *encoderBincIO) { - if len(v) == 0 { - e.e.WriteMapEmpty() - return - } - var i uint - e.mapStart(len(v)) - if e.h.Canonical { - v2 := make([]string, len(v)) - for k := range v { - v2[i] = k - i++ - } - slices.Sort(v2) - for i, k2 := range v2 { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeString(k2) - e.mapElemValue() - e.e.EncodeFloat64(v[k2]) - } - } else { - i = 0 - for k2, v2 := range v { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeString(k2) - e.mapElemValue() - e.e.EncodeFloat64(v2) - i++ - } - } - e.c = 0 - e.e.WriteMapEnd() -} -func (e *encoderBincIO) fastpathEncMapStringBoolR(f *encFnInfo, rv reflect.Value) { - fastpathETBincIO{}.EncMapStringBoolV(rv2i(rv).(map[string]bool), e) -} -func (fastpathETBincIO) EncMapStringBoolV(v map[string]bool, e *encoderBincIO) { - if len(v) == 0 { - e.e.WriteMapEmpty() - return - } - var i uint - e.mapStart(len(v)) - if e.h.Canonical { - v2 := make([]string, len(v)) - for k := range v { - v2[i] = k - i++ - } - slices.Sort(v2) - for i, k2 := range v2 { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeString(k2) - e.mapElemValue() - e.e.EncodeBool(v[k2]) - } - } else { - i = 0 - for k2, v2 := range v { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeString(k2) - e.mapElemValue() - e.e.EncodeBool(v2) - i++ - } - } - e.c = 0 - e.e.WriteMapEnd() -} -func (e *encoderBincIO) fastpathEncMapUint8IntfR(f *encFnInfo, rv reflect.Value) { - fastpathETBincIO{}.EncMapUint8IntfV(rv2i(rv).(map[uint8]interface{}), e) -} -func (fastpathETBincIO) EncMapUint8IntfV(v map[uint8]interface{}, e *encoderBincIO) { - if len(v) == 0 { - e.e.WriteMapEmpty() - return - } - var i uint - e.mapStart(len(v)) - if e.h.Canonical { - v2 := make([]uint8, len(v)) - for k := range v { - v2[i] = k - i++ - } - slices.Sort(v2) - for i, k2 := range v2 { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeUint(uint64(k2)) - e.mapElemValue() - if !e.encodeBuiltin(v[k2]) { - e.encodeR(reflect.ValueOf(v[k2])) - } - } - } else { - i = 0 - for k2, v2 := range v { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeUint(uint64(k2)) - e.mapElemValue() - if !e.encodeBuiltin(v2) { - e.encodeR(reflect.ValueOf(v2)) - } - i++ - } - } - e.c = 0 - e.e.WriteMapEnd() -} -func (e *encoderBincIO) fastpathEncMapUint8StringR(f *encFnInfo, rv reflect.Value) { - fastpathETBincIO{}.EncMapUint8StringV(rv2i(rv).(map[uint8]string), e) -} -func (fastpathETBincIO) EncMapUint8StringV(v map[uint8]string, e *encoderBincIO) { - if len(v) == 0 { - e.e.WriteMapEmpty() - return - } - var i uint - e.mapStart(len(v)) - if e.h.Canonical { - v2 := make([]uint8, len(v)) - for k := range v { - v2[i] = k - i++ - } - slices.Sort(v2) - for i, k2 := range v2 { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeUint(uint64(k2)) - e.mapElemValue() - e.e.EncodeString(v[k2]) - } - } else { - i = 0 - for k2, v2 := range v { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeUint(uint64(k2)) - e.mapElemValue() - e.e.EncodeString(v2) - i++ - } - } - e.c = 0 - e.e.WriteMapEnd() -} -func (e *encoderBincIO) fastpathEncMapUint8BytesR(f *encFnInfo, rv reflect.Value) { - fastpathETBincIO{}.EncMapUint8BytesV(rv2i(rv).(map[uint8][]byte), e) -} -func (fastpathETBincIO) EncMapUint8BytesV(v map[uint8][]byte, e *encoderBincIO) { - if len(v) == 0 { - e.e.WriteMapEmpty() - return - } - var i uint - e.mapStart(len(v)) - if e.h.Canonical { - v2 := make([]uint8, len(v)) - for k := range v { - v2[i] = k - i++ - } - slices.Sort(v2) - for i, k2 := range v2 { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeUint(uint64(k2)) - e.mapElemValue() - e.e.EncodeBytes(v[k2]) - } - } else { - i = 0 - for k2, v2 := range v { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeUint(uint64(k2)) - e.mapElemValue() - e.e.EncodeBytes(v2) - i++ - } - } - e.c = 0 - e.e.WriteMapEnd() -} -func (e *encoderBincIO) fastpathEncMapUint8Uint8R(f *encFnInfo, rv reflect.Value) { - fastpathETBincIO{}.EncMapUint8Uint8V(rv2i(rv).(map[uint8]uint8), e) -} -func (fastpathETBincIO) EncMapUint8Uint8V(v map[uint8]uint8, e *encoderBincIO) { - if len(v) == 0 { - e.e.WriteMapEmpty() - return - } - var i uint - e.mapStart(len(v)) - if e.h.Canonical { - v2 := make([]uint8, len(v)) - for k := range v { - v2[i] = k - i++ - } - slices.Sort(v2) - for i, k2 := range v2 { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeUint(uint64(k2)) - e.mapElemValue() - e.e.EncodeUint(uint64(v[k2])) - } - } else { - i = 0 - for k2, v2 := range v { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeUint(uint64(k2)) - e.mapElemValue() - e.e.EncodeUint(uint64(v2)) - i++ - } - } - e.c = 0 - e.e.WriteMapEnd() -} -func (e *encoderBincIO) fastpathEncMapUint8Uint64R(f *encFnInfo, rv reflect.Value) { - fastpathETBincIO{}.EncMapUint8Uint64V(rv2i(rv).(map[uint8]uint64), e) -} -func (fastpathETBincIO) EncMapUint8Uint64V(v map[uint8]uint64, e *encoderBincIO) { - if len(v) == 0 { - e.e.WriteMapEmpty() - return - } - var i uint - e.mapStart(len(v)) - if e.h.Canonical { - v2 := make([]uint8, len(v)) - for k := range v { - v2[i] = k - i++ - } - slices.Sort(v2) - for i, k2 := range v2 { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeUint(uint64(k2)) - e.mapElemValue() - e.e.EncodeUint(v[k2]) - } - } else { - i = 0 - for k2, v2 := range v { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeUint(uint64(k2)) - e.mapElemValue() - e.e.EncodeUint(v2) - i++ - } - } - e.c = 0 - e.e.WriteMapEnd() -} -func (e *encoderBincIO) fastpathEncMapUint8IntR(f *encFnInfo, rv reflect.Value) { - fastpathETBincIO{}.EncMapUint8IntV(rv2i(rv).(map[uint8]int), e) -} -func (fastpathETBincIO) EncMapUint8IntV(v map[uint8]int, e *encoderBincIO) { - if len(v) == 0 { - e.e.WriteMapEmpty() - return - } - var i uint - e.mapStart(len(v)) - if e.h.Canonical { - v2 := make([]uint8, len(v)) - for k := range v { - v2[i] = k - i++ - } - slices.Sort(v2) - for i, k2 := range v2 { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeUint(uint64(k2)) - e.mapElemValue() - e.e.EncodeInt(int64(v[k2])) - } - } else { - i = 0 - for k2, v2 := range v { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeUint(uint64(k2)) - e.mapElemValue() - e.e.EncodeInt(int64(v2)) - i++ - } - } - e.c = 0 - e.e.WriteMapEnd() -} -func (e *encoderBincIO) fastpathEncMapUint8Int32R(f *encFnInfo, rv reflect.Value) { - fastpathETBincIO{}.EncMapUint8Int32V(rv2i(rv).(map[uint8]int32), e) -} -func (fastpathETBincIO) EncMapUint8Int32V(v map[uint8]int32, e *encoderBincIO) { - if len(v) == 0 { - e.e.WriteMapEmpty() - return - } - var i uint - e.mapStart(len(v)) - if e.h.Canonical { - v2 := make([]uint8, len(v)) - for k := range v { - v2[i] = k - i++ - } - slices.Sort(v2) - for i, k2 := range v2 { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeUint(uint64(k2)) - e.mapElemValue() - e.e.EncodeInt(int64(v[k2])) - } - } else { - i = 0 - for k2, v2 := range v { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeUint(uint64(k2)) - e.mapElemValue() - e.e.EncodeInt(int64(v2)) - i++ - } - } - e.c = 0 - e.e.WriteMapEnd() -} -func (e *encoderBincIO) fastpathEncMapUint8Float64R(f *encFnInfo, rv reflect.Value) { - fastpathETBincIO{}.EncMapUint8Float64V(rv2i(rv).(map[uint8]float64), e) -} -func (fastpathETBincIO) EncMapUint8Float64V(v map[uint8]float64, e *encoderBincIO) { - if len(v) == 0 { - e.e.WriteMapEmpty() - return - } - var i uint - e.mapStart(len(v)) - if e.h.Canonical { - v2 := make([]uint8, len(v)) - for k := range v { - v2[i] = k - i++ - } - slices.Sort(v2) - for i, k2 := range v2 { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeUint(uint64(k2)) - e.mapElemValue() - e.e.EncodeFloat64(v[k2]) - } - } else { - i = 0 - for k2, v2 := range v { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeUint(uint64(k2)) - e.mapElemValue() - e.e.EncodeFloat64(v2) - i++ - } - } - e.c = 0 - e.e.WriteMapEnd() -} -func (e *encoderBincIO) fastpathEncMapUint8BoolR(f *encFnInfo, rv reflect.Value) { - fastpathETBincIO{}.EncMapUint8BoolV(rv2i(rv).(map[uint8]bool), e) -} -func (fastpathETBincIO) EncMapUint8BoolV(v map[uint8]bool, e *encoderBincIO) { - if len(v) == 0 { - e.e.WriteMapEmpty() - return - } - var i uint - e.mapStart(len(v)) - if e.h.Canonical { - v2 := make([]uint8, len(v)) - for k := range v { - v2[i] = k - i++ - } - slices.Sort(v2) - for i, k2 := range v2 { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeUint(uint64(k2)) - e.mapElemValue() - e.e.EncodeBool(v[k2]) - } - } else { - i = 0 - for k2, v2 := range v { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeUint(uint64(k2)) - e.mapElemValue() - e.e.EncodeBool(v2) - i++ - } - } - e.c = 0 - e.e.WriteMapEnd() -} -func (e *encoderBincIO) fastpathEncMapUint64IntfR(f *encFnInfo, rv reflect.Value) { - fastpathETBincIO{}.EncMapUint64IntfV(rv2i(rv).(map[uint64]interface{}), e) -} -func (fastpathETBincIO) EncMapUint64IntfV(v map[uint64]interface{}, e *encoderBincIO) { - if len(v) == 0 { - e.e.WriteMapEmpty() - return - } - var i uint - e.mapStart(len(v)) - if e.h.Canonical { - v2 := make([]uint64, len(v)) - for k := range v { - v2[i] = k - i++ - } - slices.Sort(v2) - for i, k2 := range v2 { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeUint(k2) - e.mapElemValue() - if !e.encodeBuiltin(v[k2]) { - e.encodeR(reflect.ValueOf(v[k2])) - } - } - } else { - i = 0 - for k2, v2 := range v { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeUint(k2) - e.mapElemValue() - if !e.encodeBuiltin(v2) { - e.encodeR(reflect.ValueOf(v2)) - } - i++ - } - } - e.c = 0 - e.e.WriteMapEnd() -} -func (e *encoderBincIO) fastpathEncMapUint64StringR(f *encFnInfo, rv reflect.Value) { - fastpathETBincIO{}.EncMapUint64StringV(rv2i(rv).(map[uint64]string), e) -} -func (fastpathETBincIO) EncMapUint64StringV(v map[uint64]string, e *encoderBincIO) { - if len(v) == 0 { - e.e.WriteMapEmpty() - return - } - var i uint - e.mapStart(len(v)) - if e.h.Canonical { - v2 := make([]uint64, len(v)) - for k := range v { - v2[i] = k - i++ - } - slices.Sort(v2) - for i, k2 := range v2 { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeUint(k2) - e.mapElemValue() - e.e.EncodeString(v[k2]) - } - } else { - i = 0 - for k2, v2 := range v { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeUint(k2) - e.mapElemValue() - e.e.EncodeString(v2) - i++ - } - } - e.c = 0 - e.e.WriteMapEnd() -} -func (e *encoderBincIO) fastpathEncMapUint64BytesR(f *encFnInfo, rv reflect.Value) { - fastpathETBincIO{}.EncMapUint64BytesV(rv2i(rv).(map[uint64][]byte), e) -} -func (fastpathETBincIO) EncMapUint64BytesV(v map[uint64][]byte, e *encoderBincIO) { - if len(v) == 0 { - e.e.WriteMapEmpty() - return - } - var i uint - e.mapStart(len(v)) - if e.h.Canonical { - v2 := make([]uint64, len(v)) - for k := range v { - v2[i] = k - i++ - } - slices.Sort(v2) - for i, k2 := range v2 { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeUint(k2) - e.mapElemValue() - e.e.EncodeBytes(v[k2]) - } - } else { - i = 0 - for k2, v2 := range v { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeUint(k2) - e.mapElemValue() - e.e.EncodeBytes(v2) - i++ - } - } - e.c = 0 - e.e.WriteMapEnd() -} -func (e *encoderBincIO) fastpathEncMapUint64Uint8R(f *encFnInfo, rv reflect.Value) { - fastpathETBincIO{}.EncMapUint64Uint8V(rv2i(rv).(map[uint64]uint8), e) -} -func (fastpathETBincIO) EncMapUint64Uint8V(v map[uint64]uint8, e *encoderBincIO) { - if len(v) == 0 { - e.e.WriteMapEmpty() - return - } - var i uint - e.mapStart(len(v)) - if e.h.Canonical { - v2 := make([]uint64, len(v)) - for k := range v { - v2[i] = k - i++ - } - slices.Sort(v2) - for i, k2 := range v2 { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeUint(k2) - e.mapElemValue() - e.e.EncodeUint(uint64(v[k2])) - } - } else { - i = 0 - for k2, v2 := range v { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeUint(k2) - e.mapElemValue() - e.e.EncodeUint(uint64(v2)) - i++ - } - } - e.c = 0 - e.e.WriteMapEnd() -} -func (e *encoderBincIO) fastpathEncMapUint64Uint64R(f *encFnInfo, rv reflect.Value) { - fastpathETBincIO{}.EncMapUint64Uint64V(rv2i(rv).(map[uint64]uint64), e) -} -func (fastpathETBincIO) EncMapUint64Uint64V(v map[uint64]uint64, e *encoderBincIO) { - if len(v) == 0 { - e.e.WriteMapEmpty() - return - } - var i uint - e.mapStart(len(v)) - if e.h.Canonical { - v2 := make([]uint64, len(v)) - for k := range v { - v2[i] = k - i++ - } - slices.Sort(v2) - for i, k2 := range v2 { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeUint(k2) - e.mapElemValue() - e.e.EncodeUint(v[k2]) - } - } else { - i = 0 - for k2, v2 := range v { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeUint(k2) - e.mapElemValue() - e.e.EncodeUint(v2) - i++ - } - } - e.c = 0 - e.e.WriteMapEnd() -} -func (e *encoderBincIO) fastpathEncMapUint64IntR(f *encFnInfo, rv reflect.Value) { - fastpathETBincIO{}.EncMapUint64IntV(rv2i(rv).(map[uint64]int), e) -} -func (fastpathETBincIO) EncMapUint64IntV(v map[uint64]int, e *encoderBincIO) { - if len(v) == 0 { - e.e.WriteMapEmpty() - return - } - var i uint - e.mapStart(len(v)) - if e.h.Canonical { - v2 := make([]uint64, len(v)) - for k := range v { - v2[i] = k - i++ - } - slices.Sort(v2) - for i, k2 := range v2 { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeUint(k2) - e.mapElemValue() - e.e.EncodeInt(int64(v[k2])) - } - } else { - i = 0 - for k2, v2 := range v { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeUint(k2) - e.mapElemValue() - e.e.EncodeInt(int64(v2)) - i++ - } - } - e.c = 0 - e.e.WriteMapEnd() -} -func (e *encoderBincIO) fastpathEncMapUint64Int32R(f *encFnInfo, rv reflect.Value) { - fastpathETBincIO{}.EncMapUint64Int32V(rv2i(rv).(map[uint64]int32), e) -} -func (fastpathETBincIO) EncMapUint64Int32V(v map[uint64]int32, e *encoderBincIO) { - if len(v) == 0 { - e.e.WriteMapEmpty() - return - } - var i uint - e.mapStart(len(v)) - if e.h.Canonical { - v2 := make([]uint64, len(v)) - for k := range v { - v2[i] = k - i++ - } - slices.Sort(v2) - for i, k2 := range v2 { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeUint(k2) - e.mapElemValue() - e.e.EncodeInt(int64(v[k2])) - } - } else { - i = 0 - for k2, v2 := range v { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeUint(k2) - e.mapElemValue() - e.e.EncodeInt(int64(v2)) - i++ - } - } - e.c = 0 - e.e.WriteMapEnd() -} -func (e *encoderBincIO) fastpathEncMapUint64Float64R(f *encFnInfo, rv reflect.Value) { - fastpathETBincIO{}.EncMapUint64Float64V(rv2i(rv).(map[uint64]float64), e) -} -func (fastpathETBincIO) EncMapUint64Float64V(v map[uint64]float64, e *encoderBincIO) { - if len(v) == 0 { - e.e.WriteMapEmpty() - return - } - var i uint - e.mapStart(len(v)) - if e.h.Canonical { - v2 := make([]uint64, len(v)) - for k := range v { - v2[i] = k - i++ - } - slices.Sort(v2) - for i, k2 := range v2 { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeUint(k2) - e.mapElemValue() - e.e.EncodeFloat64(v[k2]) - } - } else { - i = 0 - for k2, v2 := range v { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeUint(k2) - e.mapElemValue() - e.e.EncodeFloat64(v2) - i++ - } - } - e.c = 0 - e.e.WriteMapEnd() -} -func (e *encoderBincIO) fastpathEncMapUint64BoolR(f *encFnInfo, rv reflect.Value) { - fastpathETBincIO{}.EncMapUint64BoolV(rv2i(rv).(map[uint64]bool), e) -} -func (fastpathETBincIO) EncMapUint64BoolV(v map[uint64]bool, e *encoderBincIO) { - if len(v) == 0 { - e.e.WriteMapEmpty() - return - } - var i uint - e.mapStart(len(v)) - if e.h.Canonical { - v2 := make([]uint64, len(v)) - for k := range v { - v2[i] = k - i++ - } - slices.Sort(v2) - for i, k2 := range v2 { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeUint(k2) - e.mapElemValue() - e.e.EncodeBool(v[k2]) - } - } else { - i = 0 - for k2, v2 := range v { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeUint(k2) - e.mapElemValue() - e.e.EncodeBool(v2) - i++ - } - } - e.c = 0 - e.e.WriteMapEnd() -} -func (e *encoderBincIO) fastpathEncMapIntIntfR(f *encFnInfo, rv reflect.Value) { - fastpathETBincIO{}.EncMapIntIntfV(rv2i(rv).(map[int]interface{}), e) -} -func (fastpathETBincIO) EncMapIntIntfV(v map[int]interface{}, e *encoderBincIO) { - if len(v) == 0 { - e.e.WriteMapEmpty() - return - } - var i uint - e.mapStart(len(v)) - if e.h.Canonical { - v2 := make([]int, len(v)) - for k := range v { - v2[i] = k - i++ - } - slices.Sort(v2) - for i, k2 := range v2 { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeInt(int64(k2)) - e.mapElemValue() - if !e.encodeBuiltin(v[k2]) { - e.encodeR(reflect.ValueOf(v[k2])) - } - } - } else { - i = 0 - for k2, v2 := range v { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeInt(int64(k2)) - e.mapElemValue() - if !e.encodeBuiltin(v2) { - e.encodeR(reflect.ValueOf(v2)) - } - i++ - } - } - e.c = 0 - e.e.WriteMapEnd() -} -func (e *encoderBincIO) fastpathEncMapIntStringR(f *encFnInfo, rv reflect.Value) { - fastpathETBincIO{}.EncMapIntStringV(rv2i(rv).(map[int]string), e) -} -func (fastpathETBincIO) EncMapIntStringV(v map[int]string, e *encoderBincIO) { - if len(v) == 0 { - e.e.WriteMapEmpty() - return - } - var i uint - e.mapStart(len(v)) - if e.h.Canonical { - v2 := make([]int, len(v)) - for k := range v { - v2[i] = k - i++ - } - slices.Sort(v2) - for i, k2 := range v2 { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeInt(int64(k2)) - e.mapElemValue() - e.e.EncodeString(v[k2]) - } - } else { - i = 0 - for k2, v2 := range v { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeInt(int64(k2)) - e.mapElemValue() - e.e.EncodeString(v2) - i++ - } - } - e.c = 0 - e.e.WriteMapEnd() -} -func (e *encoderBincIO) fastpathEncMapIntBytesR(f *encFnInfo, rv reflect.Value) { - fastpathETBincIO{}.EncMapIntBytesV(rv2i(rv).(map[int][]byte), e) -} -func (fastpathETBincIO) EncMapIntBytesV(v map[int][]byte, e *encoderBincIO) { - if len(v) == 0 { - e.e.WriteMapEmpty() - return - } - var i uint - e.mapStart(len(v)) - if e.h.Canonical { - v2 := make([]int, len(v)) - for k := range v { - v2[i] = k - i++ - } - slices.Sort(v2) - for i, k2 := range v2 { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeInt(int64(k2)) - e.mapElemValue() - e.e.EncodeBytes(v[k2]) - } - } else { - i = 0 - for k2, v2 := range v { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeInt(int64(k2)) - e.mapElemValue() - e.e.EncodeBytes(v2) - i++ - } - } - e.c = 0 - e.e.WriteMapEnd() -} -func (e *encoderBincIO) fastpathEncMapIntUint8R(f *encFnInfo, rv reflect.Value) { - fastpathETBincIO{}.EncMapIntUint8V(rv2i(rv).(map[int]uint8), e) -} -func (fastpathETBincIO) EncMapIntUint8V(v map[int]uint8, e *encoderBincIO) { - if len(v) == 0 { - e.e.WriteMapEmpty() - return - } - var i uint - e.mapStart(len(v)) - if e.h.Canonical { - v2 := make([]int, len(v)) - for k := range v { - v2[i] = k - i++ - } - slices.Sort(v2) - for i, k2 := range v2 { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeInt(int64(k2)) - e.mapElemValue() - e.e.EncodeUint(uint64(v[k2])) - } - } else { - i = 0 - for k2, v2 := range v { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeInt(int64(k2)) - e.mapElemValue() - e.e.EncodeUint(uint64(v2)) - i++ - } - } - e.c = 0 - e.e.WriteMapEnd() -} -func (e *encoderBincIO) fastpathEncMapIntUint64R(f *encFnInfo, rv reflect.Value) { - fastpathETBincIO{}.EncMapIntUint64V(rv2i(rv).(map[int]uint64), e) -} -func (fastpathETBincIO) EncMapIntUint64V(v map[int]uint64, e *encoderBincIO) { - if len(v) == 0 { - e.e.WriteMapEmpty() - return - } - var i uint - e.mapStart(len(v)) - if e.h.Canonical { - v2 := make([]int, len(v)) - for k := range v { - v2[i] = k - i++ - } - slices.Sort(v2) - for i, k2 := range v2 { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeInt(int64(k2)) - e.mapElemValue() - e.e.EncodeUint(v[k2]) - } - } else { - i = 0 - for k2, v2 := range v { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeInt(int64(k2)) - e.mapElemValue() - e.e.EncodeUint(v2) - i++ - } - } - e.c = 0 - e.e.WriteMapEnd() -} -func (e *encoderBincIO) fastpathEncMapIntIntR(f *encFnInfo, rv reflect.Value) { - fastpathETBincIO{}.EncMapIntIntV(rv2i(rv).(map[int]int), e) -} -func (fastpathETBincIO) EncMapIntIntV(v map[int]int, e *encoderBincIO) { - if len(v) == 0 { - e.e.WriteMapEmpty() - return - } - var i uint - e.mapStart(len(v)) - if e.h.Canonical { - v2 := make([]int, len(v)) - for k := range v { - v2[i] = k - i++ - } - slices.Sort(v2) - for i, k2 := range v2 { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeInt(int64(k2)) - e.mapElemValue() - e.e.EncodeInt(int64(v[k2])) - } - } else { - i = 0 - for k2, v2 := range v { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeInt(int64(k2)) - e.mapElemValue() - e.e.EncodeInt(int64(v2)) - i++ - } - } - e.c = 0 - e.e.WriteMapEnd() -} -func (e *encoderBincIO) fastpathEncMapIntInt32R(f *encFnInfo, rv reflect.Value) { - fastpathETBincIO{}.EncMapIntInt32V(rv2i(rv).(map[int]int32), e) -} -func (fastpathETBincIO) EncMapIntInt32V(v map[int]int32, e *encoderBincIO) { - if len(v) == 0 { - e.e.WriteMapEmpty() - return - } - var i uint - e.mapStart(len(v)) - if e.h.Canonical { - v2 := make([]int, len(v)) - for k := range v { - v2[i] = k - i++ - } - slices.Sort(v2) - for i, k2 := range v2 { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeInt(int64(k2)) - e.mapElemValue() - e.e.EncodeInt(int64(v[k2])) - } - } else { - i = 0 - for k2, v2 := range v { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeInt(int64(k2)) - e.mapElemValue() - e.e.EncodeInt(int64(v2)) - i++ - } - } - e.c = 0 - e.e.WriteMapEnd() -} -func (e *encoderBincIO) fastpathEncMapIntFloat64R(f *encFnInfo, rv reflect.Value) { - fastpathETBincIO{}.EncMapIntFloat64V(rv2i(rv).(map[int]float64), e) -} -func (fastpathETBincIO) EncMapIntFloat64V(v map[int]float64, e *encoderBincIO) { - if len(v) == 0 { - e.e.WriteMapEmpty() - return - } - var i uint - e.mapStart(len(v)) - if e.h.Canonical { - v2 := make([]int, len(v)) - for k := range v { - v2[i] = k - i++ - } - slices.Sort(v2) - for i, k2 := range v2 { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeInt(int64(k2)) - e.mapElemValue() - e.e.EncodeFloat64(v[k2]) - } - } else { - i = 0 - for k2, v2 := range v { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeInt(int64(k2)) - e.mapElemValue() - e.e.EncodeFloat64(v2) - i++ - } - } - e.c = 0 - e.e.WriteMapEnd() -} -func (e *encoderBincIO) fastpathEncMapIntBoolR(f *encFnInfo, rv reflect.Value) { - fastpathETBincIO{}.EncMapIntBoolV(rv2i(rv).(map[int]bool), e) -} -func (fastpathETBincIO) EncMapIntBoolV(v map[int]bool, e *encoderBincIO) { - if len(v) == 0 { - e.e.WriteMapEmpty() - return - } - var i uint - e.mapStart(len(v)) - if e.h.Canonical { - v2 := make([]int, len(v)) - for k := range v { - v2[i] = k - i++ - } - slices.Sort(v2) - for i, k2 := range v2 { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeInt(int64(k2)) - e.mapElemValue() - e.e.EncodeBool(v[k2]) - } - } else { - i = 0 - for k2, v2 := range v { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeInt(int64(k2)) - e.mapElemValue() - e.e.EncodeBool(v2) - i++ - } - } - e.c = 0 - e.e.WriteMapEnd() -} -func (e *encoderBincIO) fastpathEncMapInt32IntfR(f *encFnInfo, rv reflect.Value) { - fastpathETBincIO{}.EncMapInt32IntfV(rv2i(rv).(map[int32]interface{}), e) -} -func (fastpathETBincIO) EncMapInt32IntfV(v map[int32]interface{}, e *encoderBincIO) { - if len(v) == 0 { - e.e.WriteMapEmpty() - return - } - var i uint - e.mapStart(len(v)) - if e.h.Canonical { - v2 := make([]int32, len(v)) - for k := range v { - v2[i] = k - i++ - } - slices.Sort(v2) - for i, k2 := range v2 { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeInt(int64(k2)) - e.mapElemValue() - if !e.encodeBuiltin(v[k2]) { - e.encodeR(reflect.ValueOf(v[k2])) - } - } - } else { - i = 0 - for k2, v2 := range v { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeInt(int64(k2)) - e.mapElemValue() - if !e.encodeBuiltin(v2) { - e.encodeR(reflect.ValueOf(v2)) - } - i++ - } - } - e.c = 0 - e.e.WriteMapEnd() -} -func (e *encoderBincIO) fastpathEncMapInt32StringR(f *encFnInfo, rv reflect.Value) { - fastpathETBincIO{}.EncMapInt32StringV(rv2i(rv).(map[int32]string), e) -} -func (fastpathETBincIO) EncMapInt32StringV(v map[int32]string, e *encoderBincIO) { - if len(v) == 0 { - e.e.WriteMapEmpty() - return - } - var i uint - e.mapStart(len(v)) - if e.h.Canonical { - v2 := make([]int32, len(v)) - for k := range v { - v2[i] = k - i++ - } - slices.Sort(v2) - for i, k2 := range v2 { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeInt(int64(k2)) - e.mapElemValue() - e.e.EncodeString(v[k2]) - } - } else { - i = 0 - for k2, v2 := range v { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeInt(int64(k2)) - e.mapElemValue() - e.e.EncodeString(v2) - i++ - } - } - e.c = 0 - e.e.WriteMapEnd() -} -func (e *encoderBincIO) fastpathEncMapInt32BytesR(f *encFnInfo, rv reflect.Value) { - fastpathETBincIO{}.EncMapInt32BytesV(rv2i(rv).(map[int32][]byte), e) -} -func (fastpathETBincIO) EncMapInt32BytesV(v map[int32][]byte, e *encoderBincIO) { - if len(v) == 0 { - e.e.WriteMapEmpty() - return - } - var i uint - e.mapStart(len(v)) - if e.h.Canonical { - v2 := make([]int32, len(v)) - for k := range v { - v2[i] = k - i++ - } - slices.Sort(v2) - for i, k2 := range v2 { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeInt(int64(k2)) - e.mapElemValue() - e.e.EncodeBytes(v[k2]) - } - } else { - i = 0 - for k2, v2 := range v { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeInt(int64(k2)) - e.mapElemValue() - e.e.EncodeBytes(v2) - i++ - } - } - e.c = 0 - e.e.WriteMapEnd() -} -func (e *encoderBincIO) fastpathEncMapInt32Uint8R(f *encFnInfo, rv reflect.Value) { - fastpathETBincIO{}.EncMapInt32Uint8V(rv2i(rv).(map[int32]uint8), e) -} -func (fastpathETBincIO) EncMapInt32Uint8V(v map[int32]uint8, e *encoderBincIO) { - if len(v) == 0 { - e.e.WriteMapEmpty() - return - } - var i uint - e.mapStart(len(v)) - if e.h.Canonical { - v2 := make([]int32, len(v)) - for k := range v { - v2[i] = k - i++ - } - slices.Sort(v2) - for i, k2 := range v2 { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeInt(int64(k2)) - e.mapElemValue() - e.e.EncodeUint(uint64(v[k2])) - } - } else { - i = 0 - for k2, v2 := range v { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeInt(int64(k2)) - e.mapElemValue() - e.e.EncodeUint(uint64(v2)) - i++ - } - } - e.c = 0 - e.e.WriteMapEnd() -} -func (e *encoderBincIO) fastpathEncMapInt32Uint64R(f *encFnInfo, rv reflect.Value) { - fastpathETBincIO{}.EncMapInt32Uint64V(rv2i(rv).(map[int32]uint64), e) -} -func (fastpathETBincIO) EncMapInt32Uint64V(v map[int32]uint64, e *encoderBincIO) { - if len(v) == 0 { - e.e.WriteMapEmpty() - return - } - var i uint - e.mapStart(len(v)) - if e.h.Canonical { - v2 := make([]int32, len(v)) - for k := range v { - v2[i] = k - i++ - } - slices.Sort(v2) - for i, k2 := range v2 { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeInt(int64(k2)) - e.mapElemValue() - e.e.EncodeUint(v[k2]) - } - } else { - i = 0 - for k2, v2 := range v { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeInt(int64(k2)) - e.mapElemValue() - e.e.EncodeUint(v2) - i++ - } - } - e.c = 0 - e.e.WriteMapEnd() -} -func (e *encoderBincIO) fastpathEncMapInt32IntR(f *encFnInfo, rv reflect.Value) { - fastpathETBincIO{}.EncMapInt32IntV(rv2i(rv).(map[int32]int), e) -} -func (fastpathETBincIO) EncMapInt32IntV(v map[int32]int, e *encoderBincIO) { - if len(v) == 0 { - e.e.WriteMapEmpty() - return - } - var i uint - e.mapStart(len(v)) - if e.h.Canonical { - v2 := make([]int32, len(v)) - for k := range v { - v2[i] = k - i++ - } - slices.Sort(v2) - for i, k2 := range v2 { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeInt(int64(k2)) - e.mapElemValue() - e.e.EncodeInt(int64(v[k2])) - } - } else { - i = 0 - for k2, v2 := range v { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeInt(int64(k2)) - e.mapElemValue() - e.e.EncodeInt(int64(v2)) - i++ - } - } - e.c = 0 - e.e.WriteMapEnd() -} -func (e *encoderBincIO) fastpathEncMapInt32Int32R(f *encFnInfo, rv reflect.Value) { - fastpathETBincIO{}.EncMapInt32Int32V(rv2i(rv).(map[int32]int32), e) -} -func (fastpathETBincIO) EncMapInt32Int32V(v map[int32]int32, e *encoderBincIO) { - if len(v) == 0 { - e.e.WriteMapEmpty() - return - } - var i uint - e.mapStart(len(v)) - if e.h.Canonical { - v2 := make([]int32, len(v)) - for k := range v { - v2[i] = k - i++ - } - slices.Sort(v2) - for i, k2 := range v2 { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeInt(int64(k2)) - e.mapElemValue() - e.e.EncodeInt(int64(v[k2])) - } - } else { - i = 0 - for k2, v2 := range v { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeInt(int64(k2)) - e.mapElemValue() - e.e.EncodeInt(int64(v2)) - i++ - } - } - e.c = 0 - e.e.WriteMapEnd() -} -func (e *encoderBincIO) fastpathEncMapInt32Float64R(f *encFnInfo, rv reflect.Value) { - fastpathETBincIO{}.EncMapInt32Float64V(rv2i(rv).(map[int32]float64), e) -} -func (fastpathETBincIO) EncMapInt32Float64V(v map[int32]float64, e *encoderBincIO) { - if len(v) == 0 { - e.e.WriteMapEmpty() - return - } - var i uint - e.mapStart(len(v)) - if e.h.Canonical { - v2 := make([]int32, len(v)) - for k := range v { - v2[i] = k - i++ - } - slices.Sort(v2) - for i, k2 := range v2 { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeInt(int64(k2)) - e.mapElemValue() - e.e.EncodeFloat64(v[k2]) - } - } else { - i = 0 - for k2, v2 := range v { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeInt(int64(k2)) - e.mapElemValue() - e.e.EncodeFloat64(v2) - i++ - } - } - e.c = 0 - e.e.WriteMapEnd() -} -func (e *encoderBincIO) fastpathEncMapInt32BoolR(f *encFnInfo, rv reflect.Value) { - fastpathETBincIO{}.EncMapInt32BoolV(rv2i(rv).(map[int32]bool), e) -} -func (fastpathETBincIO) EncMapInt32BoolV(v map[int32]bool, e *encoderBincIO) { - if len(v) == 0 { - e.e.WriteMapEmpty() - return - } - var i uint - e.mapStart(len(v)) - if e.h.Canonical { - v2 := make([]int32, len(v)) - for k := range v { - v2[i] = k - i++ - } - slices.Sort(v2) - for i, k2 := range v2 { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeInt(int64(k2)) - e.mapElemValue() - e.e.EncodeBool(v[k2]) - } - } else { - i = 0 - for k2, v2 := range v { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeInt(int64(k2)) - e.mapElemValue() - e.e.EncodeBool(v2) - i++ - } - } - e.c = 0 - e.e.WriteMapEnd() -} - -func (helperDecDriverBincIO) fastpathDecodeTypeSwitch(iv interface{}, d *decoderBincIO) bool { - var ft fastpathDTBincIO - var changed bool - var containerLen int - switch v := iv.(type) { - case []interface{}: - ft.DecSliceIntfN(v, d) - case *[]interface{}: - var v2 []interface{} - if v2, changed = ft.DecSliceIntfY(*v, d); changed { - *v = v2 - } - case []string: - ft.DecSliceStringN(v, d) - case *[]string: - var v2 []string - if v2, changed = ft.DecSliceStringY(*v, d); changed { - *v = v2 - } - case [][]byte: - ft.DecSliceBytesN(v, d) - case *[][]byte: - var v2 [][]byte - if v2, changed = ft.DecSliceBytesY(*v, d); changed { - *v = v2 - } - case []float32: - ft.DecSliceFloat32N(v, d) - case *[]float32: - var v2 []float32 - if v2, changed = ft.DecSliceFloat32Y(*v, d); changed { - *v = v2 - } - case []float64: - ft.DecSliceFloat64N(v, d) - case *[]float64: - var v2 []float64 - if v2, changed = ft.DecSliceFloat64Y(*v, d); changed { - *v = v2 - } - case []uint8: - ft.DecSliceUint8N(v, d) - case *[]uint8: - var v2 []uint8 - if v2, changed = ft.DecSliceUint8Y(*v, d); changed { - *v = v2 - } - case []uint64: - ft.DecSliceUint64N(v, d) - case *[]uint64: - var v2 []uint64 - if v2, changed = ft.DecSliceUint64Y(*v, d); changed { - *v = v2 - } - case []int: - ft.DecSliceIntN(v, d) - case *[]int: - var v2 []int - if v2, changed = ft.DecSliceIntY(*v, d); changed { - *v = v2 - } - case []int32: - ft.DecSliceInt32N(v, d) - case *[]int32: - var v2 []int32 - if v2, changed = ft.DecSliceInt32Y(*v, d); changed { - *v = v2 - } - case []int64: - ft.DecSliceInt64N(v, d) - case *[]int64: - var v2 []int64 - if v2, changed = ft.DecSliceInt64Y(*v, d); changed { - *v = v2 - } - case []bool: - ft.DecSliceBoolN(v, d) - case *[]bool: - var v2 []bool - if v2, changed = ft.DecSliceBoolY(*v, d); changed { - *v = v2 - } - case map[string]interface{}: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen != containerLenNil { - if containerLen != 0 { - ft.DecMapStringIntfL(v, containerLen, d) - } - d.mapEnd() - } - case *map[string]interface{}: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen == containerLenNil { - *v = nil - } else { - if *v == nil { - *v = make(map[string]interface{}, decInferLen(containerLen, d.maxInitLen(), 32)) - } - if containerLen != 0 { - ft.DecMapStringIntfL(*v, containerLen, d) - } - d.mapEnd() - } - case map[string]string: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen != containerLenNil { - if containerLen != 0 { - ft.DecMapStringStringL(v, containerLen, d) - } - d.mapEnd() - } - case *map[string]string: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen == containerLenNil { - *v = nil - } else { - if *v == nil { - *v = make(map[string]string, decInferLen(containerLen, d.maxInitLen(), 32)) - } - if containerLen != 0 { - ft.DecMapStringStringL(*v, containerLen, d) - } - d.mapEnd() - } - case map[string][]byte: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen != containerLenNil { - if containerLen != 0 { - ft.DecMapStringBytesL(v, containerLen, d) - } - d.mapEnd() - } - case *map[string][]byte: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen == containerLenNil { - *v = nil - } else { - if *v == nil { - *v = make(map[string][]byte, decInferLen(containerLen, d.maxInitLen(), 40)) - } - if containerLen != 0 { - ft.DecMapStringBytesL(*v, containerLen, d) - } - d.mapEnd() - } - case map[string]uint8: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen != containerLenNil { - if containerLen != 0 { - ft.DecMapStringUint8L(v, containerLen, d) - } - d.mapEnd() - } - case *map[string]uint8: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen == containerLenNil { - *v = nil - } else { - if *v == nil { - *v = make(map[string]uint8, decInferLen(containerLen, d.maxInitLen(), 17)) - } - if containerLen != 0 { - ft.DecMapStringUint8L(*v, containerLen, d) - } - d.mapEnd() - } - case map[string]uint64: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen != containerLenNil { - if containerLen != 0 { - ft.DecMapStringUint64L(v, containerLen, d) - } - d.mapEnd() - } - case *map[string]uint64: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen == containerLenNil { - *v = nil - } else { - if *v == nil { - *v = make(map[string]uint64, decInferLen(containerLen, d.maxInitLen(), 24)) - } - if containerLen != 0 { - ft.DecMapStringUint64L(*v, containerLen, d) - } - d.mapEnd() - } - case map[string]int: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen != containerLenNil { - if containerLen != 0 { - ft.DecMapStringIntL(v, containerLen, d) - } - d.mapEnd() - } - case *map[string]int: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen == containerLenNil { - *v = nil - } else { - if *v == nil { - *v = make(map[string]int, decInferLen(containerLen, d.maxInitLen(), 24)) - } - if containerLen != 0 { - ft.DecMapStringIntL(*v, containerLen, d) - } - d.mapEnd() - } - case map[string]int32: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen != containerLenNil { - if containerLen != 0 { - ft.DecMapStringInt32L(v, containerLen, d) - } - d.mapEnd() - } - case *map[string]int32: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen == containerLenNil { - *v = nil - } else { - if *v == nil { - *v = make(map[string]int32, decInferLen(containerLen, d.maxInitLen(), 20)) - } - if containerLen != 0 { - ft.DecMapStringInt32L(*v, containerLen, d) - } - d.mapEnd() - } - case map[string]float64: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen != containerLenNil { - if containerLen != 0 { - ft.DecMapStringFloat64L(v, containerLen, d) - } - d.mapEnd() - } - case *map[string]float64: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen == containerLenNil { - *v = nil - } else { - if *v == nil { - *v = make(map[string]float64, decInferLen(containerLen, d.maxInitLen(), 24)) - } - if containerLen != 0 { - ft.DecMapStringFloat64L(*v, containerLen, d) - } - d.mapEnd() - } - case map[string]bool: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen != containerLenNil { - if containerLen != 0 { - ft.DecMapStringBoolL(v, containerLen, d) - } - d.mapEnd() - } - case *map[string]bool: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen == containerLenNil { - *v = nil - } else { - if *v == nil { - *v = make(map[string]bool, decInferLen(containerLen, d.maxInitLen(), 17)) - } - if containerLen != 0 { - ft.DecMapStringBoolL(*v, containerLen, d) - } - d.mapEnd() - } - case map[uint8]interface{}: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen != containerLenNil { - if containerLen != 0 { - ft.DecMapUint8IntfL(v, containerLen, d) - } - d.mapEnd() - } - case *map[uint8]interface{}: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen == containerLenNil { - *v = nil - } else { - if *v == nil { - *v = make(map[uint8]interface{}, decInferLen(containerLen, d.maxInitLen(), 17)) - } - if containerLen != 0 { - ft.DecMapUint8IntfL(*v, containerLen, d) - } - d.mapEnd() - } - case map[uint8]string: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen != containerLenNil { - if containerLen != 0 { - ft.DecMapUint8StringL(v, containerLen, d) - } - d.mapEnd() - } - case *map[uint8]string: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen == containerLenNil { - *v = nil - } else { - if *v == nil { - *v = make(map[uint8]string, decInferLen(containerLen, d.maxInitLen(), 17)) - } - if containerLen != 0 { - ft.DecMapUint8StringL(*v, containerLen, d) - } - d.mapEnd() - } - case map[uint8][]byte: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen != containerLenNil { - if containerLen != 0 { - ft.DecMapUint8BytesL(v, containerLen, d) - } - d.mapEnd() - } - case *map[uint8][]byte: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen == containerLenNil { - *v = nil - } else { - if *v == nil { - *v = make(map[uint8][]byte, decInferLen(containerLen, d.maxInitLen(), 25)) - } - if containerLen != 0 { - ft.DecMapUint8BytesL(*v, containerLen, d) - } - d.mapEnd() - } - case map[uint8]uint8: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen != containerLenNil { - if containerLen != 0 { - ft.DecMapUint8Uint8L(v, containerLen, d) - } - d.mapEnd() - } - case *map[uint8]uint8: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen == containerLenNil { - *v = nil - } else { - if *v == nil { - *v = make(map[uint8]uint8, decInferLen(containerLen, d.maxInitLen(), 2)) - } - if containerLen != 0 { - ft.DecMapUint8Uint8L(*v, containerLen, d) - } - d.mapEnd() - } - case map[uint8]uint64: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen != containerLenNil { - if containerLen != 0 { - ft.DecMapUint8Uint64L(v, containerLen, d) - } - d.mapEnd() - } - case *map[uint8]uint64: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen == containerLenNil { - *v = nil - } else { - if *v == nil { - *v = make(map[uint8]uint64, decInferLen(containerLen, d.maxInitLen(), 9)) - } - if containerLen != 0 { - ft.DecMapUint8Uint64L(*v, containerLen, d) - } - d.mapEnd() - } - case map[uint8]int: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen != containerLenNil { - if containerLen != 0 { - ft.DecMapUint8IntL(v, containerLen, d) - } - d.mapEnd() - } - case *map[uint8]int: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen == containerLenNil { - *v = nil - } else { - if *v == nil { - *v = make(map[uint8]int, decInferLen(containerLen, d.maxInitLen(), 9)) - } - if containerLen != 0 { - ft.DecMapUint8IntL(*v, containerLen, d) - } - d.mapEnd() - } - case map[uint8]int32: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen != containerLenNil { - if containerLen != 0 { - ft.DecMapUint8Int32L(v, containerLen, d) - } - d.mapEnd() - } - case *map[uint8]int32: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen == containerLenNil { - *v = nil - } else { - if *v == nil { - *v = make(map[uint8]int32, decInferLen(containerLen, d.maxInitLen(), 5)) - } - if containerLen != 0 { - ft.DecMapUint8Int32L(*v, containerLen, d) - } - d.mapEnd() - } - case map[uint8]float64: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen != containerLenNil { - if containerLen != 0 { - ft.DecMapUint8Float64L(v, containerLen, d) - } - d.mapEnd() - } - case *map[uint8]float64: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen == containerLenNil { - *v = nil - } else { - if *v == nil { - *v = make(map[uint8]float64, decInferLen(containerLen, d.maxInitLen(), 9)) - } - if containerLen != 0 { - ft.DecMapUint8Float64L(*v, containerLen, d) - } - d.mapEnd() - } - case map[uint8]bool: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen != containerLenNil { - if containerLen != 0 { - ft.DecMapUint8BoolL(v, containerLen, d) - } - d.mapEnd() - } - case *map[uint8]bool: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen == containerLenNil { - *v = nil - } else { - if *v == nil { - *v = make(map[uint8]bool, decInferLen(containerLen, d.maxInitLen(), 2)) - } - if containerLen != 0 { - ft.DecMapUint8BoolL(*v, containerLen, d) - } - d.mapEnd() - } - case map[uint64]interface{}: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen != containerLenNil { - if containerLen != 0 { - ft.DecMapUint64IntfL(v, containerLen, d) - } - d.mapEnd() - } - case *map[uint64]interface{}: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen == containerLenNil { - *v = nil - } else { - if *v == nil { - *v = make(map[uint64]interface{}, decInferLen(containerLen, d.maxInitLen(), 24)) - } - if containerLen != 0 { - ft.DecMapUint64IntfL(*v, containerLen, d) - } - d.mapEnd() - } - case map[uint64]string: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen != containerLenNil { - if containerLen != 0 { - ft.DecMapUint64StringL(v, containerLen, d) - } - d.mapEnd() - } - case *map[uint64]string: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen == containerLenNil { - *v = nil - } else { - if *v == nil { - *v = make(map[uint64]string, decInferLen(containerLen, d.maxInitLen(), 24)) - } - if containerLen != 0 { - ft.DecMapUint64StringL(*v, containerLen, d) - } - d.mapEnd() - } - case map[uint64][]byte: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen != containerLenNil { - if containerLen != 0 { - ft.DecMapUint64BytesL(v, containerLen, d) - } - d.mapEnd() - } - case *map[uint64][]byte: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen == containerLenNil { - *v = nil - } else { - if *v == nil { - *v = make(map[uint64][]byte, decInferLen(containerLen, d.maxInitLen(), 32)) - } - if containerLen != 0 { - ft.DecMapUint64BytesL(*v, containerLen, d) - } - d.mapEnd() - } - case map[uint64]uint8: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen != containerLenNil { - if containerLen != 0 { - ft.DecMapUint64Uint8L(v, containerLen, d) - } - d.mapEnd() - } - case *map[uint64]uint8: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen == containerLenNil { - *v = nil - } else { - if *v == nil { - *v = make(map[uint64]uint8, decInferLen(containerLen, d.maxInitLen(), 9)) - } - if containerLen != 0 { - ft.DecMapUint64Uint8L(*v, containerLen, d) - } - d.mapEnd() - } - case map[uint64]uint64: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen != containerLenNil { - if containerLen != 0 { - ft.DecMapUint64Uint64L(v, containerLen, d) - } - d.mapEnd() - } - case *map[uint64]uint64: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen == containerLenNil { - *v = nil - } else { - if *v == nil { - *v = make(map[uint64]uint64, decInferLen(containerLen, d.maxInitLen(), 16)) - } - if containerLen != 0 { - ft.DecMapUint64Uint64L(*v, containerLen, d) - } - d.mapEnd() - } - case map[uint64]int: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen != containerLenNil { - if containerLen != 0 { - ft.DecMapUint64IntL(v, containerLen, d) - } - d.mapEnd() - } - case *map[uint64]int: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen == containerLenNil { - *v = nil - } else { - if *v == nil { - *v = make(map[uint64]int, decInferLen(containerLen, d.maxInitLen(), 16)) - } - if containerLen != 0 { - ft.DecMapUint64IntL(*v, containerLen, d) - } - d.mapEnd() - } - case map[uint64]int32: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen != containerLenNil { - if containerLen != 0 { - ft.DecMapUint64Int32L(v, containerLen, d) - } - d.mapEnd() - } - case *map[uint64]int32: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen == containerLenNil { - *v = nil - } else { - if *v == nil { - *v = make(map[uint64]int32, decInferLen(containerLen, d.maxInitLen(), 12)) - } - if containerLen != 0 { - ft.DecMapUint64Int32L(*v, containerLen, d) - } - d.mapEnd() - } - case map[uint64]float64: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen != containerLenNil { - if containerLen != 0 { - ft.DecMapUint64Float64L(v, containerLen, d) - } - d.mapEnd() - } - case *map[uint64]float64: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen == containerLenNil { - *v = nil - } else { - if *v == nil { - *v = make(map[uint64]float64, decInferLen(containerLen, d.maxInitLen(), 16)) - } - if containerLen != 0 { - ft.DecMapUint64Float64L(*v, containerLen, d) - } - d.mapEnd() - } - case map[uint64]bool: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen != containerLenNil { - if containerLen != 0 { - ft.DecMapUint64BoolL(v, containerLen, d) - } - d.mapEnd() - } - case *map[uint64]bool: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen == containerLenNil { - *v = nil - } else { - if *v == nil { - *v = make(map[uint64]bool, decInferLen(containerLen, d.maxInitLen(), 9)) - } - if containerLen != 0 { - ft.DecMapUint64BoolL(*v, containerLen, d) - } - d.mapEnd() - } - case map[int]interface{}: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen != containerLenNil { - if containerLen != 0 { - ft.DecMapIntIntfL(v, containerLen, d) - } - d.mapEnd() - } - case *map[int]interface{}: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen == containerLenNil { - *v = nil - } else { - if *v == nil { - *v = make(map[int]interface{}, decInferLen(containerLen, d.maxInitLen(), 24)) - } - if containerLen != 0 { - ft.DecMapIntIntfL(*v, containerLen, d) - } - d.mapEnd() - } - case map[int]string: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen != containerLenNil { - if containerLen != 0 { - ft.DecMapIntStringL(v, containerLen, d) - } - d.mapEnd() - } - case *map[int]string: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen == containerLenNil { - *v = nil - } else { - if *v == nil { - *v = make(map[int]string, decInferLen(containerLen, d.maxInitLen(), 24)) - } - if containerLen != 0 { - ft.DecMapIntStringL(*v, containerLen, d) - } - d.mapEnd() - } - case map[int][]byte: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen != containerLenNil { - if containerLen != 0 { - ft.DecMapIntBytesL(v, containerLen, d) - } - d.mapEnd() - } - case *map[int][]byte: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen == containerLenNil { - *v = nil - } else { - if *v == nil { - *v = make(map[int][]byte, decInferLen(containerLen, d.maxInitLen(), 32)) - } - if containerLen != 0 { - ft.DecMapIntBytesL(*v, containerLen, d) - } - d.mapEnd() - } - case map[int]uint8: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen != containerLenNil { - if containerLen != 0 { - ft.DecMapIntUint8L(v, containerLen, d) - } - d.mapEnd() - } - case *map[int]uint8: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen == containerLenNil { - *v = nil - } else { - if *v == nil { - *v = make(map[int]uint8, decInferLen(containerLen, d.maxInitLen(), 9)) - } - if containerLen != 0 { - ft.DecMapIntUint8L(*v, containerLen, d) - } - d.mapEnd() - } - case map[int]uint64: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen != containerLenNil { - if containerLen != 0 { - ft.DecMapIntUint64L(v, containerLen, d) - } - d.mapEnd() - } - case *map[int]uint64: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen == containerLenNil { - *v = nil - } else { - if *v == nil { - *v = make(map[int]uint64, decInferLen(containerLen, d.maxInitLen(), 16)) - } - if containerLen != 0 { - ft.DecMapIntUint64L(*v, containerLen, d) - } - d.mapEnd() - } - case map[int]int: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen != containerLenNil { - if containerLen != 0 { - ft.DecMapIntIntL(v, containerLen, d) - } - d.mapEnd() - } - case *map[int]int: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen == containerLenNil { - *v = nil - } else { - if *v == nil { - *v = make(map[int]int, decInferLen(containerLen, d.maxInitLen(), 16)) - } - if containerLen != 0 { - ft.DecMapIntIntL(*v, containerLen, d) - } - d.mapEnd() - } - case map[int]int32: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen != containerLenNil { - if containerLen != 0 { - ft.DecMapIntInt32L(v, containerLen, d) - } - d.mapEnd() - } - case *map[int]int32: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen == containerLenNil { - *v = nil - } else { - if *v == nil { - *v = make(map[int]int32, decInferLen(containerLen, d.maxInitLen(), 12)) - } - if containerLen != 0 { - ft.DecMapIntInt32L(*v, containerLen, d) - } - d.mapEnd() - } - case map[int]float64: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen != containerLenNil { - if containerLen != 0 { - ft.DecMapIntFloat64L(v, containerLen, d) - } - d.mapEnd() - } - case *map[int]float64: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen == containerLenNil { - *v = nil - } else { - if *v == nil { - *v = make(map[int]float64, decInferLen(containerLen, d.maxInitLen(), 16)) - } - if containerLen != 0 { - ft.DecMapIntFloat64L(*v, containerLen, d) - } - d.mapEnd() - } - case map[int]bool: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen != containerLenNil { - if containerLen != 0 { - ft.DecMapIntBoolL(v, containerLen, d) - } - d.mapEnd() - } - case *map[int]bool: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen == containerLenNil { - *v = nil - } else { - if *v == nil { - *v = make(map[int]bool, decInferLen(containerLen, d.maxInitLen(), 9)) - } - if containerLen != 0 { - ft.DecMapIntBoolL(*v, containerLen, d) - } - d.mapEnd() - } - case map[int32]interface{}: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen != containerLenNil { - if containerLen != 0 { - ft.DecMapInt32IntfL(v, containerLen, d) - } - d.mapEnd() - } - case *map[int32]interface{}: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen == containerLenNil { - *v = nil - } else { - if *v == nil { - *v = make(map[int32]interface{}, decInferLen(containerLen, d.maxInitLen(), 20)) - } - if containerLen != 0 { - ft.DecMapInt32IntfL(*v, containerLen, d) - } - d.mapEnd() - } - case map[int32]string: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen != containerLenNil { - if containerLen != 0 { - ft.DecMapInt32StringL(v, containerLen, d) - } - d.mapEnd() - } - case *map[int32]string: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen == containerLenNil { - *v = nil - } else { - if *v == nil { - *v = make(map[int32]string, decInferLen(containerLen, d.maxInitLen(), 20)) - } - if containerLen != 0 { - ft.DecMapInt32StringL(*v, containerLen, d) - } - d.mapEnd() - } - case map[int32][]byte: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen != containerLenNil { - if containerLen != 0 { - ft.DecMapInt32BytesL(v, containerLen, d) - } - d.mapEnd() - } - case *map[int32][]byte: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen == containerLenNil { - *v = nil - } else { - if *v == nil { - *v = make(map[int32][]byte, decInferLen(containerLen, d.maxInitLen(), 28)) - } - if containerLen != 0 { - ft.DecMapInt32BytesL(*v, containerLen, d) - } - d.mapEnd() - } - case map[int32]uint8: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen != containerLenNil { - if containerLen != 0 { - ft.DecMapInt32Uint8L(v, containerLen, d) - } - d.mapEnd() - } - case *map[int32]uint8: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen == containerLenNil { - *v = nil - } else { - if *v == nil { - *v = make(map[int32]uint8, decInferLen(containerLen, d.maxInitLen(), 5)) - } - if containerLen != 0 { - ft.DecMapInt32Uint8L(*v, containerLen, d) - } - d.mapEnd() - } - case map[int32]uint64: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen != containerLenNil { - if containerLen != 0 { - ft.DecMapInt32Uint64L(v, containerLen, d) - } - d.mapEnd() - } - case *map[int32]uint64: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen == containerLenNil { - *v = nil - } else { - if *v == nil { - *v = make(map[int32]uint64, decInferLen(containerLen, d.maxInitLen(), 12)) - } - if containerLen != 0 { - ft.DecMapInt32Uint64L(*v, containerLen, d) - } - d.mapEnd() - } - case map[int32]int: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen != containerLenNil { - if containerLen != 0 { - ft.DecMapInt32IntL(v, containerLen, d) - } - d.mapEnd() - } - case *map[int32]int: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen == containerLenNil { - *v = nil - } else { - if *v == nil { - *v = make(map[int32]int, decInferLen(containerLen, d.maxInitLen(), 12)) - } - if containerLen != 0 { - ft.DecMapInt32IntL(*v, containerLen, d) - } - d.mapEnd() - } - case map[int32]int32: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen != containerLenNil { - if containerLen != 0 { - ft.DecMapInt32Int32L(v, containerLen, d) - } - d.mapEnd() - } - case *map[int32]int32: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen == containerLenNil { - *v = nil - } else { - if *v == nil { - *v = make(map[int32]int32, decInferLen(containerLen, d.maxInitLen(), 8)) - } - if containerLen != 0 { - ft.DecMapInt32Int32L(*v, containerLen, d) - } - d.mapEnd() - } - case map[int32]float64: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen != containerLenNil { - if containerLen != 0 { - ft.DecMapInt32Float64L(v, containerLen, d) - } - d.mapEnd() - } - case *map[int32]float64: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen == containerLenNil { - *v = nil - } else { - if *v == nil { - *v = make(map[int32]float64, decInferLen(containerLen, d.maxInitLen(), 12)) - } - if containerLen != 0 { - ft.DecMapInt32Float64L(*v, containerLen, d) - } - d.mapEnd() - } - case map[int32]bool: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen != containerLenNil { - if containerLen != 0 { - ft.DecMapInt32BoolL(v, containerLen, d) - } - d.mapEnd() - } - case *map[int32]bool: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen == containerLenNil { - *v = nil - } else { - if *v == nil { - *v = make(map[int32]bool, decInferLen(containerLen, d.maxInitLen(), 5)) - } - if containerLen != 0 { - ft.DecMapInt32BoolL(*v, containerLen, d) - } - d.mapEnd() - } - default: - _ = v - return false - } - return true -} - -func (d *decoderBincIO) fastpathDecSliceIntfR(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTBincIO - switch rv.Kind() { - case reflect.Ptr: - v := rv2i(rv).(*[]interface{}) - if vv, changed := ft.DecSliceIntfY(*v, d); changed { - *v = vv - } - case reflect.Array: - var v []interface{} - rvGetSlice4Array(rv, &v) - ft.DecSliceIntfN(v, d) - default: - ft.DecSliceIntfN(rv2i(rv).([]interface{}), d) - } -} -func (fastpathDTBincIO) DecSliceIntfY(v []interface{}, d *decoderBincIO) (v2 []interface{}, changed bool) { - ctyp := d.d.ContainerType() - if ctyp == valueTypeNil { - return nil, v != nil - } - var containerLenS int - isArray := ctyp == valueTypeArray - if isArray { - containerLenS = d.arrayStart(d.d.ReadArrayStart()) - } else if ctyp == valueTypeMap { - containerLenS = d.mapStart(d.d.ReadMapStart()) * 2 - } else { - halt.errorStr2("decoding into a slice, expect map/array - got ", ctyp.String()) - } - hasLen := containerLenS >= 0 - var j int - fnv := func(dst []interface{}) { v, changed = dst, true } - for ; d.containerNext(j, containerLenS, hasLen); j++ { - if j == 0 { - if containerLenS == len(v) { - } else if containerLenS < 0 || containerLenS > cap(v) { - if xlen := int(decInferLen(containerLenS, d.maxInitLen(), 16)); xlen <= cap(v) { - fnv(v[:uint(xlen)]) - } else { - v2 = make([]interface{}, uint(xlen)) - copy(v2, v) - fnv(v2) - } - } else { - fnv(v[:containerLenS]) - } - } - if isArray { - d.arrayElem(j == 0) - } else if j&1 == 0 { - d.mapElemKey(j == 0) - } else { - d.mapElemValue() - } - if j >= len(v) { - fnv(append(v, nil)) - } - d.decode(&v[uint(j)]) - } - if j < len(v) { - fnv(v[:uint(j)]) - } else if j == 0 && v == nil { - fnv([]interface{}{}) - } - if isArray { - d.arrayEnd() - } else { - d.mapEnd() - } - return v, changed -} -func (fastpathDTBincIO) DecSliceIntfN(v []interface{}, d *decoderBincIO) { - ctyp := d.d.ContainerType() - if ctyp == valueTypeNil { - return - } - var containerLenS int - isArray := ctyp == valueTypeArray - if isArray { - containerLenS = d.arrayStart(d.d.ReadArrayStart()) - } else if ctyp == valueTypeMap { - containerLenS = d.mapStart(d.d.ReadMapStart()) * 2 - } else { - halt.errorStr2("decoding into a slice, expect map/array - got ", ctyp.String()) - } - hasLen := containerLenS >= 0 - for j := 0; d.containerNext(j, containerLenS, hasLen); j++ { - if isArray { - d.arrayElem(j == 0) - } else if j&1 == 0 { - d.mapElemKey(j == 0) - } else { - d.mapElemValue() - } - if j < len(v) { - d.decode(&v[uint(j)]) - } else { - d.arrayCannotExpand(len(v), j+1) - d.swallow() - } - } - if isArray { - d.arrayEnd() - } else { - d.mapEnd() - } -} - -func (d *decoderBincIO) fastpathDecSliceStringR(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTBincIO - switch rv.Kind() { - case reflect.Ptr: - v := rv2i(rv).(*[]string) - if vv, changed := ft.DecSliceStringY(*v, d); changed { - *v = vv - } - case reflect.Array: - var v []string - rvGetSlice4Array(rv, &v) - ft.DecSliceStringN(v, d) - default: - ft.DecSliceStringN(rv2i(rv).([]string), d) - } -} -func (fastpathDTBincIO) DecSliceStringY(v []string, d *decoderBincIO) (v2 []string, changed bool) { - ctyp := d.d.ContainerType() - if ctyp == valueTypeNil { - return nil, v != nil - } - var containerLenS int - isArray := ctyp == valueTypeArray - if isArray { - containerLenS = d.arrayStart(d.d.ReadArrayStart()) - } else if ctyp == valueTypeMap { - containerLenS = d.mapStart(d.d.ReadMapStart()) * 2 - } else { - halt.errorStr2("decoding into a slice, expect map/array - got ", ctyp.String()) - } - hasLen := containerLenS >= 0 - var j int - fnv := func(dst []string) { v, changed = dst, true } - for ; d.containerNext(j, containerLenS, hasLen); j++ { - if j == 0 { - if containerLenS == len(v) { - } else if containerLenS < 0 || containerLenS > cap(v) { - if xlen := int(decInferLen(containerLenS, d.maxInitLen(), 16)); xlen <= cap(v) { - fnv(v[:uint(xlen)]) - } else { - v2 = make([]string, uint(xlen)) - copy(v2, v) - fnv(v2) - } - } else { - fnv(v[:containerLenS]) - } - } - if isArray { - d.arrayElem(j == 0) - } else if j&1 == 0 { - d.mapElemKey(j == 0) - } else { - d.mapElemValue() - } - if j >= len(v) { - fnv(append(v, "")) - } - v[uint(j)] = d.detach2Str(d.d.DecodeStringAsBytes()) - } - if j < len(v) { - fnv(v[:uint(j)]) - } else if j == 0 && v == nil { - fnv([]string{}) - } - if isArray { - d.arrayEnd() - } else { - d.mapEnd() - } - return v, changed -} -func (fastpathDTBincIO) DecSliceStringN(v []string, d *decoderBincIO) { - ctyp := d.d.ContainerType() - if ctyp == valueTypeNil { - return - } - var containerLenS int - isArray := ctyp == valueTypeArray - if isArray { - containerLenS = d.arrayStart(d.d.ReadArrayStart()) - } else if ctyp == valueTypeMap { - containerLenS = d.mapStart(d.d.ReadMapStart()) * 2 - } else { - halt.errorStr2("decoding into a slice, expect map/array - got ", ctyp.String()) - } - hasLen := containerLenS >= 0 - for j := 0; d.containerNext(j, containerLenS, hasLen); j++ { - if isArray { - d.arrayElem(j == 0) - } else if j&1 == 0 { - d.mapElemKey(j == 0) - } else { - d.mapElemValue() - } - if j < len(v) { - v[uint(j)] = d.detach2Str(d.d.DecodeStringAsBytes()) - } else { - d.arrayCannotExpand(len(v), j+1) - d.swallow() - } - } - if isArray { - d.arrayEnd() - } else { - d.mapEnd() - } -} - -func (d *decoderBincIO) fastpathDecSliceBytesR(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTBincIO - switch rv.Kind() { - case reflect.Ptr: - v := rv2i(rv).(*[][]byte) - if vv, changed := ft.DecSliceBytesY(*v, d); changed { - *v = vv - } - case reflect.Array: - var v [][]byte - rvGetSlice4Array(rv, &v) - ft.DecSliceBytesN(v, d) - default: - ft.DecSliceBytesN(rv2i(rv).([][]byte), d) - } -} -func (fastpathDTBincIO) DecSliceBytesY(v [][]byte, d *decoderBincIO) (v2 [][]byte, changed bool) { - ctyp := d.d.ContainerType() - if ctyp == valueTypeNil { - return nil, v != nil - } - var containerLenS int - isArray := ctyp == valueTypeArray - if isArray { - containerLenS = d.arrayStart(d.d.ReadArrayStart()) - } else if ctyp == valueTypeMap { - containerLenS = d.mapStart(d.d.ReadMapStart()) * 2 - } else { - halt.errorStr2("decoding into a slice, expect map/array - got ", ctyp.String()) - } - hasLen := containerLenS >= 0 - var j int - fnv := func(dst [][]byte) { v, changed = dst, true } - for ; d.containerNext(j, containerLenS, hasLen); j++ { - if j == 0 { - if containerLenS == len(v) { - } else if containerLenS < 0 || containerLenS > cap(v) { - if xlen := int(decInferLen(containerLenS, d.maxInitLen(), 24)); xlen <= cap(v) { - fnv(v[:uint(xlen)]) - } else { - v2 = make([][]byte, uint(xlen)) - copy(v2, v) - fnv(v2) - } - } else { - fnv(v[:containerLenS]) - } - } - if isArray { - d.arrayElem(j == 0) - } else if j&1 == 0 { - d.mapElemKey(j == 0) - } else { - d.mapElemValue() - } - if j >= len(v) { - fnv(append(v, nil)) - } - v[uint(j)] = bytesOKdbi(d.decodeBytesInto(v[uint(j)], false)) - } - if j < len(v) { - fnv(v[:uint(j)]) - } else if j == 0 && v == nil { - fnv([][]byte{}) - } - if isArray { - d.arrayEnd() - } else { - d.mapEnd() - } - return v, changed -} -func (fastpathDTBincIO) DecSliceBytesN(v [][]byte, d *decoderBincIO) { - ctyp := d.d.ContainerType() - if ctyp == valueTypeNil { - return - } - var containerLenS int - isArray := ctyp == valueTypeArray - if isArray { - containerLenS = d.arrayStart(d.d.ReadArrayStart()) - } else if ctyp == valueTypeMap { - containerLenS = d.mapStart(d.d.ReadMapStart()) * 2 - } else { - halt.errorStr2("decoding into a slice, expect map/array - got ", ctyp.String()) - } - hasLen := containerLenS >= 0 - for j := 0; d.containerNext(j, containerLenS, hasLen); j++ { - if isArray { - d.arrayElem(j == 0) - } else if j&1 == 0 { - d.mapElemKey(j == 0) - } else { - d.mapElemValue() - } - if j < len(v) { - v[uint(j)] = bytesOKdbi(d.decodeBytesInto(v[uint(j)], false)) - } else { - d.arrayCannotExpand(len(v), j+1) - d.swallow() - } - } - if isArray { - d.arrayEnd() - } else { - d.mapEnd() - } -} - -func (d *decoderBincIO) fastpathDecSliceFloat32R(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTBincIO - switch rv.Kind() { - case reflect.Ptr: - v := rv2i(rv).(*[]float32) - if vv, changed := ft.DecSliceFloat32Y(*v, d); changed { - *v = vv - } - case reflect.Array: - var v []float32 - rvGetSlice4Array(rv, &v) - ft.DecSliceFloat32N(v, d) - default: - ft.DecSliceFloat32N(rv2i(rv).([]float32), d) - } -} -func (fastpathDTBincIO) DecSliceFloat32Y(v []float32, d *decoderBincIO) (v2 []float32, changed bool) { - ctyp := d.d.ContainerType() - if ctyp == valueTypeNil { - return nil, v != nil - } - var containerLenS int - isArray := ctyp == valueTypeArray - if isArray { - containerLenS = d.arrayStart(d.d.ReadArrayStart()) - } else if ctyp == valueTypeMap { - containerLenS = d.mapStart(d.d.ReadMapStart()) * 2 - } else { - halt.errorStr2("decoding into a slice, expect map/array - got ", ctyp.String()) - } - hasLen := containerLenS >= 0 - var j int - fnv := func(dst []float32) { v, changed = dst, true } - for ; d.containerNext(j, containerLenS, hasLen); j++ { - if j == 0 { - if containerLenS == len(v) { - } else if containerLenS < 0 || containerLenS > cap(v) { - if xlen := int(decInferLen(containerLenS, d.maxInitLen(), 4)); xlen <= cap(v) { - fnv(v[:uint(xlen)]) - } else { - v2 = make([]float32, uint(xlen)) - copy(v2, v) - fnv(v2) - } - } else { - fnv(v[:containerLenS]) - } - } - if isArray { - d.arrayElem(j == 0) - } else if j&1 == 0 { - d.mapElemKey(j == 0) - } else { - d.mapElemValue() - } - if j >= len(v) { - fnv(append(v, 0)) - } - v[uint(j)] = float32(d.d.DecodeFloat32()) - } - if j < len(v) { - fnv(v[:uint(j)]) - } else if j == 0 && v == nil { - fnv([]float32{}) - } - if isArray { - d.arrayEnd() - } else { - d.mapEnd() - } - return v, changed -} -func (fastpathDTBincIO) DecSliceFloat32N(v []float32, d *decoderBincIO) { - ctyp := d.d.ContainerType() - if ctyp == valueTypeNil { - return - } - var containerLenS int - isArray := ctyp == valueTypeArray - if isArray { - containerLenS = d.arrayStart(d.d.ReadArrayStart()) - } else if ctyp == valueTypeMap { - containerLenS = d.mapStart(d.d.ReadMapStart()) * 2 - } else { - halt.errorStr2("decoding into a slice, expect map/array - got ", ctyp.String()) - } - hasLen := containerLenS >= 0 - for j := 0; d.containerNext(j, containerLenS, hasLen); j++ { - if isArray { - d.arrayElem(j == 0) - } else if j&1 == 0 { - d.mapElemKey(j == 0) - } else { - d.mapElemValue() - } - if j < len(v) { - v[uint(j)] = float32(d.d.DecodeFloat32()) - } else { - d.arrayCannotExpand(len(v), j+1) - d.swallow() - } - } - if isArray { - d.arrayEnd() - } else { - d.mapEnd() - } -} - -func (d *decoderBincIO) fastpathDecSliceFloat64R(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTBincIO - switch rv.Kind() { - case reflect.Ptr: - v := rv2i(rv).(*[]float64) - if vv, changed := ft.DecSliceFloat64Y(*v, d); changed { - *v = vv - } - case reflect.Array: - var v []float64 - rvGetSlice4Array(rv, &v) - ft.DecSliceFloat64N(v, d) - default: - ft.DecSliceFloat64N(rv2i(rv).([]float64), d) - } -} -func (fastpathDTBincIO) DecSliceFloat64Y(v []float64, d *decoderBincIO) (v2 []float64, changed bool) { - ctyp := d.d.ContainerType() - if ctyp == valueTypeNil { - return nil, v != nil - } - var containerLenS int - isArray := ctyp == valueTypeArray - if isArray { - containerLenS = d.arrayStart(d.d.ReadArrayStart()) - } else if ctyp == valueTypeMap { - containerLenS = d.mapStart(d.d.ReadMapStart()) * 2 - } else { - halt.errorStr2("decoding into a slice, expect map/array - got ", ctyp.String()) - } - hasLen := containerLenS >= 0 - var j int - fnv := func(dst []float64) { v, changed = dst, true } - for ; d.containerNext(j, containerLenS, hasLen); j++ { - if j == 0 { - if containerLenS == len(v) { - } else if containerLenS < 0 || containerLenS > cap(v) { - if xlen := int(decInferLen(containerLenS, d.maxInitLen(), 8)); xlen <= cap(v) { - fnv(v[:uint(xlen)]) - } else { - v2 = make([]float64, uint(xlen)) - copy(v2, v) - fnv(v2) - } - } else { - fnv(v[:containerLenS]) - } - } - if isArray { - d.arrayElem(j == 0) - } else if j&1 == 0 { - d.mapElemKey(j == 0) - } else { - d.mapElemValue() - } - if j >= len(v) { - fnv(append(v, 0)) - } - v[uint(j)] = d.d.DecodeFloat64() - } - if j < len(v) { - fnv(v[:uint(j)]) - } else if j == 0 && v == nil { - fnv([]float64{}) - } - if isArray { - d.arrayEnd() - } else { - d.mapEnd() - } - return v, changed -} -func (fastpathDTBincIO) DecSliceFloat64N(v []float64, d *decoderBincIO) { - ctyp := d.d.ContainerType() - if ctyp == valueTypeNil { - return - } - var containerLenS int - isArray := ctyp == valueTypeArray - if isArray { - containerLenS = d.arrayStart(d.d.ReadArrayStart()) - } else if ctyp == valueTypeMap { - containerLenS = d.mapStart(d.d.ReadMapStart()) * 2 - } else { - halt.errorStr2("decoding into a slice, expect map/array - got ", ctyp.String()) - } - hasLen := containerLenS >= 0 - for j := 0; d.containerNext(j, containerLenS, hasLen); j++ { - if isArray { - d.arrayElem(j == 0) - } else if j&1 == 0 { - d.mapElemKey(j == 0) - } else { - d.mapElemValue() - } - if j < len(v) { - v[uint(j)] = d.d.DecodeFloat64() - } else { - d.arrayCannotExpand(len(v), j+1) - d.swallow() - } - } - if isArray { - d.arrayEnd() - } else { - d.mapEnd() - } -} - -func (d *decoderBincIO) fastpathDecSliceUint8R(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTBincIO - switch rv.Kind() { - case reflect.Ptr: - v := rv2i(rv).(*[]uint8) - if vv, changed := ft.DecSliceUint8Y(*v, d); changed { - *v = vv - } - case reflect.Array: - var v []uint8 - rvGetSlice4Array(rv, &v) - ft.DecSliceUint8N(v, d) - default: - ft.DecSliceUint8N(rv2i(rv).([]uint8), d) - } -} -func (fastpathDTBincIO) DecSliceUint8Y(v []uint8, d *decoderBincIO) (v2 []uint8, changed bool) { - ctyp := d.d.ContainerType() - if ctyp == valueTypeNil { - return nil, v != nil - } - if ctyp != valueTypeMap { - var dbi dBytesIntoState - v2, dbi = d.decodeBytesInto(v[:len(v):len(v)], false) - return v2, dbi != dBytesIntoParamOut - } - containerLenS := d.mapStart(d.d.ReadMapStart()) * 2 - hasLen := containerLenS >= 0 - var j int - fnv := func(dst []uint8) { v, changed = dst, true } - for ; d.containerNext(j, containerLenS, hasLen); j++ { - if j == 0 { - if containerLenS == len(v) { - } else if containerLenS < 0 || containerLenS > cap(v) { - if xlen := int(decInferLen(containerLenS, d.maxInitLen(), 1)); xlen <= cap(v) { - fnv(v[:uint(xlen)]) - } else { - v2 = make([]uint8, uint(xlen)) - copy(v2, v) - fnv(v2) - } - } else { - fnv(v[:containerLenS]) - } - } - if j&1 == 0 { - d.mapElemKey(j == 0) - } else { - d.mapElemValue() - } - if j >= len(v) { - fnv(append(v, 0)) - } - v[uint(j)] = uint8(chkOvf.UintV(d.d.DecodeUint64(), 8)) - } - if j < len(v) { - fnv(v[:uint(j)]) - } else if j == 0 && v == nil { - fnv([]uint8{}) - } - d.mapEnd() - return v, changed -} -func (fastpathDTBincIO) DecSliceUint8N(v []uint8, d *decoderBincIO) { - ctyp := d.d.ContainerType() - if ctyp == valueTypeNil { - return - } - if ctyp != valueTypeMap { - d.decodeBytesInto(v[:len(v):len(v)], true) - return - } - containerLenS := d.mapStart(d.d.ReadMapStart()) * 2 - hasLen := containerLenS >= 0 - for j := 0; d.containerNext(j, containerLenS, hasLen); j++ { - if j&1 == 0 { - d.mapElemKey(j == 0) - } else { - d.mapElemValue() - } - if j < len(v) { - v[uint(j)] = uint8(chkOvf.UintV(d.d.DecodeUint64(), 8)) - } else { - d.arrayCannotExpand(len(v), j+1) - d.swallow() - } - } - d.mapEnd() -} - -func (d *decoderBincIO) fastpathDecSliceUint64R(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTBincIO - switch rv.Kind() { - case reflect.Ptr: - v := rv2i(rv).(*[]uint64) - if vv, changed := ft.DecSliceUint64Y(*v, d); changed { - *v = vv - } - case reflect.Array: - var v []uint64 - rvGetSlice4Array(rv, &v) - ft.DecSliceUint64N(v, d) - default: - ft.DecSliceUint64N(rv2i(rv).([]uint64), d) - } -} -func (fastpathDTBincIO) DecSliceUint64Y(v []uint64, d *decoderBincIO) (v2 []uint64, changed bool) { - ctyp := d.d.ContainerType() - if ctyp == valueTypeNil { - return nil, v != nil - } - var containerLenS int - isArray := ctyp == valueTypeArray - if isArray { - containerLenS = d.arrayStart(d.d.ReadArrayStart()) - } else if ctyp == valueTypeMap { - containerLenS = d.mapStart(d.d.ReadMapStart()) * 2 - } else { - halt.errorStr2("decoding into a slice, expect map/array - got ", ctyp.String()) - } - hasLen := containerLenS >= 0 - var j int - fnv := func(dst []uint64) { v, changed = dst, true } - for ; d.containerNext(j, containerLenS, hasLen); j++ { - if j == 0 { - if containerLenS == len(v) { - } else if containerLenS < 0 || containerLenS > cap(v) { - if xlen := int(decInferLen(containerLenS, d.maxInitLen(), 8)); xlen <= cap(v) { - fnv(v[:uint(xlen)]) - } else { - v2 = make([]uint64, uint(xlen)) - copy(v2, v) - fnv(v2) - } - } else { - fnv(v[:containerLenS]) - } - } - if isArray { - d.arrayElem(j == 0) - } else if j&1 == 0 { - d.mapElemKey(j == 0) - } else { - d.mapElemValue() - } - if j >= len(v) { - fnv(append(v, 0)) - } - v[uint(j)] = d.d.DecodeUint64() - } - if j < len(v) { - fnv(v[:uint(j)]) - } else if j == 0 && v == nil { - fnv([]uint64{}) - } - if isArray { - d.arrayEnd() - } else { - d.mapEnd() - } - return v, changed -} -func (fastpathDTBincIO) DecSliceUint64N(v []uint64, d *decoderBincIO) { - ctyp := d.d.ContainerType() - if ctyp == valueTypeNil { - return - } - var containerLenS int - isArray := ctyp == valueTypeArray - if isArray { - containerLenS = d.arrayStart(d.d.ReadArrayStart()) - } else if ctyp == valueTypeMap { - containerLenS = d.mapStart(d.d.ReadMapStart()) * 2 - } else { - halt.errorStr2("decoding into a slice, expect map/array - got ", ctyp.String()) - } - hasLen := containerLenS >= 0 - for j := 0; d.containerNext(j, containerLenS, hasLen); j++ { - if isArray { - d.arrayElem(j == 0) - } else if j&1 == 0 { - d.mapElemKey(j == 0) - } else { - d.mapElemValue() - } - if j < len(v) { - v[uint(j)] = d.d.DecodeUint64() - } else { - d.arrayCannotExpand(len(v), j+1) - d.swallow() - } - } - if isArray { - d.arrayEnd() - } else { - d.mapEnd() - } -} - -func (d *decoderBincIO) fastpathDecSliceIntR(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTBincIO - switch rv.Kind() { - case reflect.Ptr: - v := rv2i(rv).(*[]int) - if vv, changed := ft.DecSliceIntY(*v, d); changed { - *v = vv - } - case reflect.Array: - var v []int - rvGetSlice4Array(rv, &v) - ft.DecSliceIntN(v, d) - default: - ft.DecSliceIntN(rv2i(rv).([]int), d) - } -} -func (fastpathDTBincIO) DecSliceIntY(v []int, d *decoderBincIO) (v2 []int, changed bool) { - ctyp := d.d.ContainerType() - if ctyp == valueTypeNil { - return nil, v != nil - } - var containerLenS int - isArray := ctyp == valueTypeArray - if isArray { - containerLenS = d.arrayStart(d.d.ReadArrayStart()) - } else if ctyp == valueTypeMap { - containerLenS = d.mapStart(d.d.ReadMapStart()) * 2 - } else { - halt.errorStr2("decoding into a slice, expect map/array - got ", ctyp.String()) - } - hasLen := containerLenS >= 0 - var j int - fnv := func(dst []int) { v, changed = dst, true } - for ; d.containerNext(j, containerLenS, hasLen); j++ { - if j == 0 { - if containerLenS == len(v) { - } else if containerLenS < 0 || containerLenS > cap(v) { - if xlen := int(decInferLen(containerLenS, d.maxInitLen(), 8)); xlen <= cap(v) { - fnv(v[:uint(xlen)]) - } else { - v2 = make([]int, uint(xlen)) - copy(v2, v) - fnv(v2) - } - } else { - fnv(v[:containerLenS]) - } - } - if isArray { - d.arrayElem(j == 0) - } else if j&1 == 0 { - d.mapElemKey(j == 0) - } else { - d.mapElemValue() - } - if j >= len(v) { - fnv(append(v, 0)) - } - v[uint(j)] = int(chkOvf.IntV(d.d.DecodeInt64(), intBitsize)) - } - if j < len(v) { - fnv(v[:uint(j)]) - } else if j == 0 && v == nil { - fnv([]int{}) - } - if isArray { - d.arrayEnd() - } else { - d.mapEnd() - } - return v, changed -} -func (fastpathDTBincIO) DecSliceIntN(v []int, d *decoderBincIO) { - ctyp := d.d.ContainerType() - if ctyp == valueTypeNil { - return - } - var containerLenS int - isArray := ctyp == valueTypeArray - if isArray { - containerLenS = d.arrayStart(d.d.ReadArrayStart()) - } else if ctyp == valueTypeMap { - containerLenS = d.mapStart(d.d.ReadMapStart()) * 2 - } else { - halt.errorStr2("decoding into a slice, expect map/array - got ", ctyp.String()) - } - hasLen := containerLenS >= 0 - for j := 0; d.containerNext(j, containerLenS, hasLen); j++ { - if isArray { - d.arrayElem(j == 0) - } else if j&1 == 0 { - d.mapElemKey(j == 0) - } else { - d.mapElemValue() - } - if j < len(v) { - v[uint(j)] = int(chkOvf.IntV(d.d.DecodeInt64(), intBitsize)) - } else { - d.arrayCannotExpand(len(v), j+1) - d.swallow() - } - } - if isArray { - d.arrayEnd() - } else { - d.mapEnd() - } -} - -func (d *decoderBincIO) fastpathDecSliceInt32R(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTBincIO - switch rv.Kind() { - case reflect.Ptr: - v := rv2i(rv).(*[]int32) - if vv, changed := ft.DecSliceInt32Y(*v, d); changed { - *v = vv - } - case reflect.Array: - var v []int32 - rvGetSlice4Array(rv, &v) - ft.DecSliceInt32N(v, d) - default: - ft.DecSliceInt32N(rv2i(rv).([]int32), d) - } -} -func (fastpathDTBincIO) DecSliceInt32Y(v []int32, d *decoderBincIO) (v2 []int32, changed bool) { - ctyp := d.d.ContainerType() - if ctyp == valueTypeNil { - return nil, v != nil - } - var containerLenS int - isArray := ctyp == valueTypeArray - if isArray { - containerLenS = d.arrayStart(d.d.ReadArrayStart()) - } else if ctyp == valueTypeMap { - containerLenS = d.mapStart(d.d.ReadMapStart()) * 2 - } else { - halt.errorStr2("decoding into a slice, expect map/array - got ", ctyp.String()) - } - hasLen := containerLenS >= 0 - var j int - fnv := func(dst []int32) { v, changed = dst, true } - for ; d.containerNext(j, containerLenS, hasLen); j++ { - if j == 0 { - if containerLenS == len(v) { - } else if containerLenS < 0 || containerLenS > cap(v) { - if xlen := int(decInferLen(containerLenS, d.maxInitLen(), 4)); xlen <= cap(v) { - fnv(v[:uint(xlen)]) - } else { - v2 = make([]int32, uint(xlen)) - copy(v2, v) - fnv(v2) - } - } else { - fnv(v[:containerLenS]) - } - } - if isArray { - d.arrayElem(j == 0) - } else if j&1 == 0 { - d.mapElemKey(j == 0) - } else { - d.mapElemValue() - } - if j >= len(v) { - fnv(append(v, 0)) - } - v[uint(j)] = int32(chkOvf.IntV(d.d.DecodeInt64(), 32)) - } - if j < len(v) { - fnv(v[:uint(j)]) - } else if j == 0 && v == nil { - fnv([]int32{}) - } - if isArray { - d.arrayEnd() - } else { - d.mapEnd() - } - return v, changed -} -func (fastpathDTBincIO) DecSliceInt32N(v []int32, d *decoderBincIO) { - ctyp := d.d.ContainerType() - if ctyp == valueTypeNil { - return - } - var containerLenS int - isArray := ctyp == valueTypeArray - if isArray { - containerLenS = d.arrayStart(d.d.ReadArrayStart()) - } else if ctyp == valueTypeMap { - containerLenS = d.mapStart(d.d.ReadMapStart()) * 2 - } else { - halt.errorStr2("decoding into a slice, expect map/array - got ", ctyp.String()) - } - hasLen := containerLenS >= 0 - for j := 0; d.containerNext(j, containerLenS, hasLen); j++ { - if isArray { - d.arrayElem(j == 0) - } else if j&1 == 0 { - d.mapElemKey(j == 0) - } else { - d.mapElemValue() - } - if j < len(v) { - v[uint(j)] = int32(chkOvf.IntV(d.d.DecodeInt64(), 32)) - } else { - d.arrayCannotExpand(len(v), j+1) - d.swallow() - } - } - if isArray { - d.arrayEnd() - } else { - d.mapEnd() - } -} - -func (d *decoderBincIO) fastpathDecSliceInt64R(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTBincIO - switch rv.Kind() { - case reflect.Ptr: - v := rv2i(rv).(*[]int64) - if vv, changed := ft.DecSliceInt64Y(*v, d); changed { - *v = vv - } - case reflect.Array: - var v []int64 - rvGetSlice4Array(rv, &v) - ft.DecSliceInt64N(v, d) - default: - ft.DecSliceInt64N(rv2i(rv).([]int64), d) - } -} -func (fastpathDTBincIO) DecSliceInt64Y(v []int64, d *decoderBincIO) (v2 []int64, changed bool) { - ctyp := d.d.ContainerType() - if ctyp == valueTypeNil { - return nil, v != nil - } - var containerLenS int - isArray := ctyp == valueTypeArray - if isArray { - containerLenS = d.arrayStart(d.d.ReadArrayStart()) - } else if ctyp == valueTypeMap { - containerLenS = d.mapStart(d.d.ReadMapStart()) * 2 - } else { - halt.errorStr2("decoding into a slice, expect map/array - got ", ctyp.String()) - } - hasLen := containerLenS >= 0 - var j int - fnv := func(dst []int64) { v, changed = dst, true } - for ; d.containerNext(j, containerLenS, hasLen); j++ { - if j == 0 { - if containerLenS == len(v) { - } else if containerLenS < 0 || containerLenS > cap(v) { - if xlen := int(decInferLen(containerLenS, d.maxInitLen(), 8)); xlen <= cap(v) { - fnv(v[:uint(xlen)]) - } else { - v2 = make([]int64, uint(xlen)) - copy(v2, v) - fnv(v2) - } - } else { - fnv(v[:containerLenS]) - } - } - if isArray { - d.arrayElem(j == 0) - } else if j&1 == 0 { - d.mapElemKey(j == 0) - } else { - d.mapElemValue() - } - if j >= len(v) { - fnv(append(v, 0)) - } - v[uint(j)] = d.d.DecodeInt64() - } - if j < len(v) { - fnv(v[:uint(j)]) - } else if j == 0 && v == nil { - fnv([]int64{}) - } - if isArray { - d.arrayEnd() - } else { - d.mapEnd() - } - return v, changed -} -func (fastpathDTBincIO) DecSliceInt64N(v []int64, d *decoderBincIO) { - ctyp := d.d.ContainerType() - if ctyp == valueTypeNil { - return - } - var containerLenS int - isArray := ctyp == valueTypeArray - if isArray { - containerLenS = d.arrayStart(d.d.ReadArrayStart()) - } else if ctyp == valueTypeMap { - containerLenS = d.mapStart(d.d.ReadMapStart()) * 2 - } else { - halt.errorStr2("decoding into a slice, expect map/array - got ", ctyp.String()) - } - hasLen := containerLenS >= 0 - for j := 0; d.containerNext(j, containerLenS, hasLen); j++ { - if isArray { - d.arrayElem(j == 0) - } else if j&1 == 0 { - d.mapElemKey(j == 0) - } else { - d.mapElemValue() - } - if j < len(v) { - v[uint(j)] = d.d.DecodeInt64() - } else { - d.arrayCannotExpand(len(v), j+1) - d.swallow() - } - } - if isArray { - d.arrayEnd() - } else { - d.mapEnd() - } -} - -func (d *decoderBincIO) fastpathDecSliceBoolR(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTBincIO - switch rv.Kind() { - case reflect.Ptr: - v := rv2i(rv).(*[]bool) - if vv, changed := ft.DecSliceBoolY(*v, d); changed { - *v = vv - } - case reflect.Array: - var v []bool - rvGetSlice4Array(rv, &v) - ft.DecSliceBoolN(v, d) - default: - ft.DecSliceBoolN(rv2i(rv).([]bool), d) - } -} -func (fastpathDTBincIO) DecSliceBoolY(v []bool, d *decoderBincIO) (v2 []bool, changed bool) { - ctyp := d.d.ContainerType() - if ctyp == valueTypeNil { - return nil, v != nil - } - var containerLenS int - isArray := ctyp == valueTypeArray - if isArray { - containerLenS = d.arrayStart(d.d.ReadArrayStart()) - } else if ctyp == valueTypeMap { - containerLenS = d.mapStart(d.d.ReadMapStart()) * 2 - } else { - halt.errorStr2("decoding into a slice, expect map/array - got ", ctyp.String()) - } - hasLen := containerLenS >= 0 - var j int - fnv := func(dst []bool) { v, changed = dst, true } - for ; d.containerNext(j, containerLenS, hasLen); j++ { - if j == 0 { - if containerLenS == len(v) { - } else if containerLenS < 0 || containerLenS > cap(v) { - if xlen := int(decInferLen(containerLenS, d.maxInitLen(), 1)); xlen <= cap(v) { - fnv(v[:uint(xlen)]) - } else { - v2 = make([]bool, uint(xlen)) - copy(v2, v) - fnv(v2) - } - } else { - fnv(v[:containerLenS]) - } - } - if isArray { - d.arrayElem(j == 0) - } else if j&1 == 0 { - d.mapElemKey(j == 0) - } else { - d.mapElemValue() - } - if j >= len(v) { - fnv(append(v, false)) - } - v[uint(j)] = d.d.DecodeBool() - } - if j < len(v) { - fnv(v[:uint(j)]) - } else if j == 0 && v == nil { - fnv([]bool{}) - } - if isArray { - d.arrayEnd() - } else { - d.mapEnd() - } - return v, changed -} -func (fastpathDTBincIO) DecSliceBoolN(v []bool, d *decoderBincIO) { - ctyp := d.d.ContainerType() - if ctyp == valueTypeNil { - return - } - var containerLenS int - isArray := ctyp == valueTypeArray - if isArray { - containerLenS = d.arrayStart(d.d.ReadArrayStart()) - } else if ctyp == valueTypeMap { - containerLenS = d.mapStart(d.d.ReadMapStart()) * 2 - } else { - halt.errorStr2("decoding into a slice, expect map/array - got ", ctyp.String()) - } - hasLen := containerLenS >= 0 - for j := 0; d.containerNext(j, containerLenS, hasLen); j++ { - if isArray { - d.arrayElem(j == 0) - } else if j&1 == 0 { - d.mapElemKey(j == 0) - } else { - d.mapElemValue() - } - if j < len(v) { - v[uint(j)] = d.d.DecodeBool() - } else { - d.arrayCannotExpand(len(v), j+1) - d.swallow() - } - } - if isArray { - d.arrayEnd() - } else { - d.mapEnd() - } -} -func (d *decoderBincIO) fastpathDecMapStringIntfR(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTBincIO - containerLen := d.mapStart(d.d.ReadMapStart()) - if rv.Kind() == reflect.Ptr { - vp, _ := rv2i(rv).(*map[string]interface{}) - if *vp == nil { - *vp = make(map[string]interface{}, decInferLen(containerLen, d.maxInitLen(), 32)) - } - if containerLen != 0 { - ft.DecMapStringIntfL(*vp, containerLen, d) - } - } else if containerLen != 0 { - ft.DecMapStringIntfL(rv2i(rv).(map[string]interface{}), containerLen, d) - } - d.mapEnd() -} -func (fastpathDTBincIO) DecMapStringIntfL(v map[string]interface{}, containerLen int, d *decoderBincIO) { - if v == nil { - halt.errorInt("cannot decode into nil map[string]interface{} given stream length: ", int64(containerLen)) - } - var mv interface{} - mapGet := !d.h.MapValueReset && !d.h.InterfaceReset - hasLen := containerLen >= 0 - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - mk := d.detach2Str(d.d.DecodeStringAsBytes()) - d.mapElemValue() - if mapGet { - mv = v[mk] - } else { - mv = nil - } - d.decode(&mv) - v[mk] = mv - } -} -func (d *decoderBincIO) fastpathDecMapStringStringR(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTBincIO - containerLen := d.mapStart(d.d.ReadMapStart()) - if rv.Kind() == reflect.Ptr { - vp, _ := rv2i(rv).(*map[string]string) - if *vp == nil { - *vp = make(map[string]string, decInferLen(containerLen, d.maxInitLen(), 32)) - } - if containerLen != 0 { - ft.DecMapStringStringL(*vp, containerLen, d) - } - } else if containerLen != 0 { - ft.DecMapStringStringL(rv2i(rv).(map[string]string), containerLen, d) - } - d.mapEnd() -} -func (fastpathDTBincIO) DecMapStringStringL(v map[string]string, containerLen int, d *decoderBincIO) { - if v == nil { - halt.errorInt("cannot decode into nil map[string]string given stream length: ", int64(containerLen)) - } - hasLen := containerLen >= 0 - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - mk := d.detach2Str(d.d.DecodeStringAsBytes()) - d.mapElemValue() - v[mk] = d.detach2Str(d.d.DecodeStringAsBytes()) - } -} -func (d *decoderBincIO) fastpathDecMapStringBytesR(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTBincIO - containerLen := d.mapStart(d.d.ReadMapStart()) - if rv.Kind() == reflect.Ptr { - vp, _ := rv2i(rv).(*map[string][]byte) - if *vp == nil { - *vp = make(map[string][]byte, decInferLen(containerLen, d.maxInitLen(), 40)) - } - if containerLen != 0 { - ft.DecMapStringBytesL(*vp, containerLen, d) - } - } else if containerLen != 0 { - ft.DecMapStringBytesL(rv2i(rv).(map[string][]byte), containerLen, d) - } - d.mapEnd() -} -func (fastpathDTBincIO) DecMapStringBytesL(v map[string][]byte, containerLen int, d *decoderBincIO) { - if v == nil { - halt.errorInt("cannot decode into nil map[string][]byte given stream length: ", int64(containerLen)) - } - var mv []byte - mapGet := !d.h.MapValueReset - hasLen := containerLen >= 0 - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - mk := d.detach2Str(d.d.DecodeStringAsBytes()) - d.mapElemValue() - if mapGet { - mv = v[mk] - } else { - mv = nil - } - v[mk], _ = d.decodeBytesInto(mv, false) - } -} -func (d *decoderBincIO) fastpathDecMapStringUint8R(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTBincIO - containerLen := d.mapStart(d.d.ReadMapStart()) - if rv.Kind() == reflect.Ptr { - vp, _ := rv2i(rv).(*map[string]uint8) - if *vp == nil { - *vp = make(map[string]uint8, decInferLen(containerLen, d.maxInitLen(), 17)) - } - if containerLen != 0 { - ft.DecMapStringUint8L(*vp, containerLen, d) - } - } else if containerLen != 0 { - ft.DecMapStringUint8L(rv2i(rv).(map[string]uint8), containerLen, d) - } - d.mapEnd() -} -func (fastpathDTBincIO) DecMapStringUint8L(v map[string]uint8, containerLen int, d *decoderBincIO) { - if v == nil { - halt.errorInt("cannot decode into nil map[string]uint8 given stream length: ", int64(containerLen)) - } - hasLen := containerLen >= 0 - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - mk := d.detach2Str(d.d.DecodeStringAsBytes()) - d.mapElemValue() - v[mk] = uint8(chkOvf.UintV(d.d.DecodeUint64(), 8)) - } -} -func (d *decoderBincIO) fastpathDecMapStringUint64R(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTBincIO - containerLen := d.mapStart(d.d.ReadMapStart()) - if rv.Kind() == reflect.Ptr { - vp, _ := rv2i(rv).(*map[string]uint64) - if *vp == nil { - *vp = make(map[string]uint64, decInferLen(containerLen, d.maxInitLen(), 24)) - } - if containerLen != 0 { - ft.DecMapStringUint64L(*vp, containerLen, d) - } - } else if containerLen != 0 { - ft.DecMapStringUint64L(rv2i(rv).(map[string]uint64), containerLen, d) - } - d.mapEnd() -} -func (fastpathDTBincIO) DecMapStringUint64L(v map[string]uint64, containerLen int, d *decoderBincIO) { - if v == nil { - halt.errorInt("cannot decode into nil map[string]uint64 given stream length: ", int64(containerLen)) - } - hasLen := containerLen >= 0 - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - mk := d.detach2Str(d.d.DecodeStringAsBytes()) - d.mapElemValue() - v[mk] = d.d.DecodeUint64() - } -} -func (d *decoderBincIO) fastpathDecMapStringIntR(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTBincIO - containerLen := d.mapStart(d.d.ReadMapStart()) - if rv.Kind() == reflect.Ptr { - vp, _ := rv2i(rv).(*map[string]int) - if *vp == nil { - *vp = make(map[string]int, decInferLen(containerLen, d.maxInitLen(), 24)) - } - if containerLen != 0 { - ft.DecMapStringIntL(*vp, containerLen, d) - } - } else if containerLen != 0 { - ft.DecMapStringIntL(rv2i(rv).(map[string]int), containerLen, d) - } - d.mapEnd() -} -func (fastpathDTBincIO) DecMapStringIntL(v map[string]int, containerLen int, d *decoderBincIO) { - if v == nil { - halt.errorInt("cannot decode into nil map[string]int given stream length: ", int64(containerLen)) - } - hasLen := containerLen >= 0 - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - mk := d.detach2Str(d.d.DecodeStringAsBytes()) - d.mapElemValue() - v[mk] = int(chkOvf.IntV(d.d.DecodeInt64(), intBitsize)) - } -} -func (d *decoderBincIO) fastpathDecMapStringInt32R(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTBincIO - containerLen := d.mapStart(d.d.ReadMapStart()) - if rv.Kind() == reflect.Ptr { - vp, _ := rv2i(rv).(*map[string]int32) - if *vp == nil { - *vp = make(map[string]int32, decInferLen(containerLen, d.maxInitLen(), 20)) - } - if containerLen != 0 { - ft.DecMapStringInt32L(*vp, containerLen, d) - } - } else if containerLen != 0 { - ft.DecMapStringInt32L(rv2i(rv).(map[string]int32), containerLen, d) - } - d.mapEnd() -} -func (fastpathDTBincIO) DecMapStringInt32L(v map[string]int32, containerLen int, d *decoderBincIO) { - if v == nil { - halt.errorInt("cannot decode into nil map[string]int32 given stream length: ", int64(containerLen)) - } - hasLen := containerLen >= 0 - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - mk := d.detach2Str(d.d.DecodeStringAsBytes()) - d.mapElemValue() - v[mk] = int32(chkOvf.IntV(d.d.DecodeInt64(), 32)) - } -} -func (d *decoderBincIO) fastpathDecMapStringFloat64R(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTBincIO - containerLen := d.mapStart(d.d.ReadMapStart()) - if rv.Kind() == reflect.Ptr { - vp, _ := rv2i(rv).(*map[string]float64) - if *vp == nil { - *vp = make(map[string]float64, decInferLen(containerLen, d.maxInitLen(), 24)) - } - if containerLen != 0 { - ft.DecMapStringFloat64L(*vp, containerLen, d) - } - } else if containerLen != 0 { - ft.DecMapStringFloat64L(rv2i(rv).(map[string]float64), containerLen, d) - } - d.mapEnd() -} -func (fastpathDTBincIO) DecMapStringFloat64L(v map[string]float64, containerLen int, d *decoderBincIO) { - if v == nil { - halt.errorInt("cannot decode into nil map[string]float64 given stream length: ", int64(containerLen)) - } - hasLen := containerLen >= 0 - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - mk := d.detach2Str(d.d.DecodeStringAsBytes()) - d.mapElemValue() - v[mk] = d.d.DecodeFloat64() - } -} -func (d *decoderBincIO) fastpathDecMapStringBoolR(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTBincIO - containerLen := d.mapStart(d.d.ReadMapStart()) - if rv.Kind() == reflect.Ptr { - vp, _ := rv2i(rv).(*map[string]bool) - if *vp == nil { - *vp = make(map[string]bool, decInferLen(containerLen, d.maxInitLen(), 17)) - } - if containerLen != 0 { - ft.DecMapStringBoolL(*vp, containerLen, d) - } - } else if containerLen != 0 { - ft.DecMapStringBoolL(rv2i(rv).(map[string]bool), containerLen, d) - } - d.mapEnd() -} -func (fastpathDTBincIO) DecMapStringBoolL(v map[string]bool, containerLen int, d *decoderBincIO) { - if v == nil { - halt.errorInt("cannot decode into nil map[string]bool given stream length: ", int64(containerLen)) - } - hasLen := containerLen >= 0 - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - mk := d.detach2Str(d.d.DecodeStringAsBytes()) - d.mapElemValue() - v[mk] = d.d.DecodeBool() - } -} -func (d *decoderBincIO) fastpathDecMapUint8IntfR(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTBincIO - containerLen := d.mapStart(d.d.ReadMapStart()) - if rv.Kind() == reflect.Ptr { - vp, _ := rv2i(rv).(*map[uint8]interface{}) - if *vp == nil { - *vp = make(map[uint8]interface{}, decInferLen(containerLen, d.maxInitLen(), 17)) - } - if containerLen != 0 { - ft.DecMapUint8IntfL(*vp, containerLen, d) - } - } else if containerLen != 0 { - ft.DecMapUint8IntfL(rv2i(rv).(map[uint8]interface{}), containerLen, d) - } - d.mapEnd() -} -func (fastpathDTBincIO) DecMapUint8IntfL(v map[uint8]interface{}, containerLen int, d *decoderBincIO) { - if v == nil { - halt.errorInt("cannot decode into nil map[uint8]interface{} given stream length: ", int64(containerLen)) - } - var mv interface{} - mapGet := !d.h.MapValueReset && !d.h.InterfaceReset - hasLen := containerLen >= 0 - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - mk := uint8(chkOvf.UintV(d.d.DecodeUint64(), 8)) - d.mapElemValue() - if mapGet { - mv = v[mk] - } else { - mv = nil - } - d.decode(&mv) - v[mk] = mv - } -} -func (d *decoderBincIO) fastpathDecMapUint8StringR(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTBincIO - containerLen := d.mapStart(d.d.ReadMapStart()) - if rv.Kind() == reflect.Ptr { - vp, _ := rv2i(rv).(*map[uint8]string) - if *vp == nil { - *vp = make(map[uint8]string, decInferLen(containerLen, d.maxInitLen(), 17)) - } - if containerLen != 0 { - ft.DecMapUint8StringL(*vp, containerLen, d) - } - } else if containerLen != 0 { - ft.DecMapUint8StringL(rv2i(rv).(map[uint8]string), containerLen, d) - } - d.mapEnd() -} -func (fastpathDTBincIO) DecMapUint8StringL(v map[uint8]string, containerLen int, d *decoderBincIO) { - if v == nil { - halt.errorInt("cannot decode into nil map[uint8]string given stream length: ", int64(containerLen)) - } - hasLen := containerLen >= 0 - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - mk := uint8(chkOvf.UintV(d.d.DecodeUint64(), 8)) - d.mapElemValue() - v[mk] = d.detach2Str(d.d.DecodeStringAsBytes()) - } -} -func (d *decoderBincIO) fastpathDecMapUint8BytesR(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTBincIO - containerLen := d.mapStart(d.d.ReadMapStart()) - if rv.Kind() == reflect.Ptr { - vp, _ := rv2i(rv).(*map[uint8][]byte) - if *vp == nil { - *vp = make(map[uint8][]byte, decInferLen(containerLen, d.maxInitLen(), 25)) - } - if containerLen != 0 { - ft.DecMapUint8BytesL(*vp, containerLen, d) - } - } else if containerLen != 0 { - ft.DecMapUint8BytesL(rv2i(rv).(map[uint8][]byte), containerLen, d) - } - d.mapEnd() -} -func (fastpathDTBincIO) DecMapUint8BytesL(v map[uint8][]byte, containerLen int, d *decoderBincIO) { - if v == nil { - halt.errorInt("cannot decode into nil map[uint8][]byte given stream length: ", int64(containerLen)) - } - var mv []byte - mapGet := !d.h.MapValueReset - hasLen := containerLen >= 0 - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - mk := uint8(chkOvf.UintV(d.d.DecodeUint64(), 8)) - d.mapElemValue() - if mapGet { - mv = v[mk] - } else { - mv = nil - } - v[mk], _ = d.decodeBytesInto(mv, false) - } -} -func (d *decoderBincIO) fastpathDecMapUint8Uint8R(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTBincIO - containerLen := d.mapStart(d.d.ReadMapStart()) - if rv.Kind() == reflect.Ptr { - vp, _ := rv2i(rv).(*map[uint8]uint8) - if *vp == nil { - *vp = make(map[uint8]uint8, decInferLen(containerLen, d.maxInitLen(), 2)) - } - if containerLen != 0 { - ft.DecMapUint8Uint8L(*vp, containerLen, d) - } - } else if containerLen != 0 { - ft.DecMapUint8Uint8L(rv2i(rv).(map[uint8]uint8), containerLen, d) - } - d.mapEnd() -} -func (fastpathDTBincIO) DecMapUint8Uint8L(v map[uint8]uint8, containerLen int, d *decoderBincIO) { - if v == nil { - halt.errorInt("cannot decode into nil map[uint8]uint8 given stream length: ", int64(containerLen)) - } - hasLen := containerLen >= 0 - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - mk := uint8(chkOvf.UintV(d.d.DecodeUint64(), 8)) - d.mapElemValue() - v[mk] = uint8(chkOvf.UintV(d.d.DecodeUint64(), 8)) - } -} -func (d *decoderBincIO) fastpathDecMapUint8Uint64R(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTBincIO - containerLen := d.mapStart(d.d.ReadMapStart()) - if rv.Kind() == reflect.Ptr { - vp, _ := rv2i(rv).(*map[uint8]uint64) - if *vp == nil { - *vp = make(map[uint8]uint64, decInferLen(containerLen, d.maxInitLen(), 9)) - } - if containerLen != 0 { - ft.DecMapUint8Uint64L(*vp, containerLen, d) - } - } else if containerLen != 0 { - ft.DecMapUint8Uint64L(rv2i(rv).(map[uint8]uint64), containerLen, d) - } - d.mapEnd() -} -func (fastpathDTBincIO) DecMapUint8Uint64L(v map[uint8]uint64, containerLen int, d *decoderBincIO) { - if v == nil { - halt.errorInt("cannot decode into nil map[uint8]uint64 given stream length: ", int64(containerLen)) - } - hasLen := containerLen >= 0 - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - mk := uint8(chkOvf.UintV(d.d.DecodeUint64(), 8)) - d.mapElemValue() - v[mk] = d.d.DecodeUint64() - } -} -func (d *decoderBincIO) fastpathDecMapUint8IntR(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTBincIO - containerLen := d.mapStart(d.d.ReadMapStart()) - if rv.Kind() == reflect.Ptr { - vp, _ := rv2i(rv).(*map[uint8]int) - if *vp == nil { - *vp = make(map[uint8]int, decInferLen(containerLen, d.maxInitLen(), 9)) - } - if containerLen != 0 { - ft.DecMapUint8IntL(*vp, containerLen, d) - } - } else if containerLen != 0 { - ft.DecMapUint8IntL(rv2i(rv).(map[uint8]int), containerLen, d) - } - d.mapEnd() -} -func (fastpathDTBincIO) DecMapUint8IntL(v map[uint8]int, containerLen int, d *decoderBincIO) { - if v == nil { - halt.errorInt("cannot decode into nil map[uint8]int given stream length: ", int64(containerLen)) - } - hasLen := containerLen >= 0 - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - mk := uint8(chkOvf.UintV(d.d.DecodeUint64(), 8)) - d.mapElemValue() - v[mk] = int(chkOvf.IntV(d.d.DecodeInt64(), intBitsize)) - } -} -func (d *decoderBincIO) fastpathDecMapUint8Int32R(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTBincIO - containerLen := d.mapStart(d.d.ReadMapStart()) - if rv.Kind() == reflect.Ptr { - vp, _ := rv2i(rv).(*map[uint8]int32) - if *vp == nil { - *vp = make(map[uint8]int32, decInferLen(containerLen, d.maxInitLen(), 5)) - } - if containerLen != 0 { - ft.DecMapUint8Int32L(*vp, containerLen, d) - } - } else if containerLen != 0 { - ft.DecMapUint8Int32L(rv2i(rv).(map[uint8]int32), containerLen, d) - } - d.mapEnd() -} -func (fastpathDTBincIO) DecMapUint8Int32L(v map[uint8]int32, containerLen int, d *decoderBincIO) { - if v == nil { - halt.errorInt("cannot decode into nil map[uint8]int32 given stream length: ", int64(containerLen)) - } - hasLen := containerLen >= 0 - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - mk := uint8(chkOvf.UintV(d.d.DecodeUint64(), 8)) - d.mapElemValue() - v[mk] = int32(chkOvf.IntV(d.d.DecodeInt64(), 32)) - } -} -func (d *decoderBincIO) fastpathDecMapUint8Float64R(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTBincIO - containerLen := d.mapStart(d.d.ReadMapStart()) - if rv.Kind() == reflect.Ptr { - vp, _ := rv2i(rv).(*map[uint8]float64) - if *vp == nil { - *vp = make(map[uint8]float64, decInferLen(containerLen, d.maxInitLen(), 9)) - } - if containerLen != 0 { - ft.DecMapUint8Float64L(*vp, containerLen, d) - } - } else if containerLen != 0 { - ft.DecMapUint8Float64L(rv2i(rv).(map[uint8]float64), containerLen, d) - } - d.mapEnd() -} -func (fastpathDTBincIO) DecMapUint8Float64L(v map[uint8]float64, containerLen int, d *decoderBincIO) { - if v == nil { - halt.errorInt("cannot decode into nil map[uint8]float64 given stream length: ", int64(containerLen)) - } - hasLen := containerLen >= 0 - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - mk := uint8(chkOvf.UintV(d.d.DecodeUint64(), 8)) - d.mapElemValue() - v[mk] = d.d.DecodeFloat64() - } -} -func (d *decoderBincIO) fastpathDecMapUint8BoolR(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTBincIO - containerLen := d.mapStart(d.d.ReadMapStart()) - if rv.Kind() == reflect.Ptr { - vp, _ := rv2i(rv).(*map[uint8]bool) - if *vp == nil { - *vp = make(map[uint8]bool, decInferLen(containerLen, d.maxInitLen(), 2)) - } - if containerLen != 0 { - ft.DecMapUint8BoolL(*vp, containerLen, d) - } - } else if containerLen != 0 { - ft.DecMapUint8BoolL(rv2i(rv).(map[uint8]bool), containerLen, d) - } - d.mapEnd() -} -func (fastpathDTBincIO) DecMapUint8BoolL(v map[uint8]bool, containerLen int, d *decoderBincIO) { - if v == nil { - halt.errorInt("cannot decode into nil map[uint8]bool given stream length: ", int64(containerLen)) - } - hasLen := containerLen >= 0 - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - mk := uint8(chkOvf.UintV(d.d.DecodeUint64(), 8)) - d.mapElemValue() - v[mk] = d.d.DecodeBool() - } -} -func (d *decoderBincIO) fastpathDecMapUint64IntfR(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTBincIO - containerLen := d.mapStart(d.d.ReadMapStart()) - if rv.Kind() == reflect.Ptr { - vp, _ := rv2i(rv).(*map[uint64]interface{}) - if *vp == nil { - *vp = make(map[uint64]interface{}, decInferLen(containerLen, d.maxInitLen(), 24)) - } - if containerLen != 0 { - ft.DecMapUint64IntfL(*vp, containerLen, d) - } - } else if containerLen != 0 { - ft.DecMapUint64IntfL(rv2i(rv).(map[uint64]interface{}), containerLen, d) - } - d.mapEnd() -} -func (fastpathDTBincIO) DecMapUint64IntfL(v map[uint64]interface{}, containerLen int, d *decoderBincIO) { - if v == nil { - halt.errorInt("cannot decode into nil map[uint64]interface{} given stream length: ", int64(containerLen)) - } - var mv interface{} - mapGet := !d.h.MapValueReset && !d.h.InterfaceReset - hasLen := containerLen >= 0 - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - mk := d.d.DecodeUint64() - d.mapElemValue() - if mapGet { - mv = v[mk] - } else { - mv = nil - } - d.decode(&mv) - v[mk] = mv - } -} -func (d *decoderBincIO) fastpathDecMapUint64StringR(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTBincIO - containerLen := d.mapStart(d.d.ReadMapStart()) - if rv.Kind() == reflect.Ptr { - vp, _ := rv2i(rv).(*map[uint64]string) - if *vp == nil { - *vp = make(map[uint64]string, decInferLen(containerLen, d.maxInitLen(), 24)) - } - if containerLen != 0 { - ft.DecMapUint64StringL(*vp, containerLen, d) - } - } else if containerLen != 0 { - ft.DecMapUint64StringL(rv2i(rv).(map[uint64]string), containerLen, d) - } - d.mapEnd() -} -func (fastpathDTBincIO) DecMapUint64StringL(v map[uint64]string, containerLen int, d *decoderBincIO) { - if v == nil { - halt.errorInt("cannot decode into nil map[uint64]string given stream length: ", int64(containerLen)) - } - hasLen := containerLen >= 0 - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - mk := d.d.DecodeUint64() - d.mapElemValue() - v[mk] = d.detach2Str(d.d.DecodeStringAsBytes()) - } -} -func (d *decoderBincIO) fastpathDecMapUint64BytesR(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTBincIO - containerLen := d.mapStart(d.d.ReadMapStart()) - if rv.Kind() == reflect.Ptr { - vp, _ := rv2i(rv).(*map[uint64][]byte) - if *vp == nil { - *vp = make(map[uint64][]byte, decInferLen(containerLen, d.maxInitLen(), 32)) - } - if containerLen != 0 { - ft.DecMapUint64BytesL(*vp, containerLen, d) - } - } else if containerLen != 0 { - ft.DecMapUint64BytesL(rv2i(rv).(map[uint64][]byte), containerLen, d) - } - d.mapEnd() -} -func (fastpathDTBincIO) DecMapUint64BytesL(v map[uint64][]byte, containerLen int, d *decoderBincIO) { - if v == nil { - halt.errorInt("cannot decode into nil map[uint64][]byte given stream length: ", int64(containerLen)) - } - var mv []byte - mapGet := !d.h.MapValueReset - hasLen := containerLen >= 0 - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - mk := d.d.DecodeUint64() - d.mapElemValue() - if mapGet { - mv = v[mk] - } else { - mv = nil - } - v[mk], _ = d.decodeBytesInto(mv, false) - } -} -func (d *decoderBincIO) fastpathDecMapUint64Uint8R(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTBincIO - containerLen := d.mapStart(d.d.ReadMapStart()) - if rv.Kind() == reflect.Ptr { - vp, _ := rv2i(rv).(*map[uint64]uint8) - if *vp == nil { - *vp = make(map[uint64]uint8, decInferLen(containerLen, d.maxInitLen(), 9)) - } - if containerLen != 0 { - ft.DecMapUint64Uint8L(*vp, containerLen, d) - } - } else if containerLen != 0 { - ft.DecMapUint64Uint8L(rv2i(rv).(map[uint64]uint8), containerLen, d) - } - d.mapEnd() -} -func (fastpathDTBincIO) DecMapUint64Uint8L(v map[uint64]uint8, containerLen int, d *decoderBincIO) { - if v == nil { - halt.errorInt("cannot decode into nil map[uint64]uint8 given stream length: ", int64(containerLen)) - } - hasLen := containerLen >= 0 - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - mk := d.d.DecodeUint64() - d.mapElemValue() - v[mk] = uint8(chkOvf.UintV(d.d.DecodeUint64(), 8)) - } -} -func (d *decoderBincIO) fastpathDecMapUint64Uint64R(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTBincIO - containerLen := d.mapStart(d.d.ReadMapStart()) - if rv.Kind() == reflect.Ptr { - vp, _ := rv2i(rv).(*map[uint64]uint64) - if *vp == nil { - *vp = make(map[uint64]uint64, decInferLen(containerLen, d.maxInitLen(), 16)) - } - if containerLen != 0 { - ft.DecMapUint64Uint64L(*vp, containerLen, d) - } - } else if containerLen != 0 { - ft.DecMapUint64Uint64L(rv2i(rv).(map[uint64]uint64), containerLen, d) - } - d.mapEnd() -} -func (fastpathDTBincIO) DecMapUint64Uint64L(v map[uint64]uint64, containerLen int, d *decoderBincIO) { - if v == nil { - halt.errorInt("cannot decode into nil map[uint64]uint64 given stream length: ", int64(containerLen)) - } - hasLen := containerLen >= 0 - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - mk := d.d.DecodeUint64() - d.mapElemValue() - v[mk] = d.d.DecodeUint64() - } -} -func (d *decoderBincIO) fastpathDecMapUint64IntR(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTBincIO - containerLen := d.mapStart(d.d.ReadMapStart()) - if rv.Kind() == reflect.Ptr { - vp, _ := rv2i(rv).(*map[uint64]int) - if *vp == nil { - *vp = make(map[uint64]int, decInferLen(containerLen, d.maxInitLen(), 16)) - } - if containerLen != 0 { - ft.DecMapUint64IntL(*vp, containerLen, d) - } - } else if containerLen != 0 { - ft.DecMapUint64IntL(rv2i(rv).(map[uint64]int), containerLen, d) - } - d.mapEnd() -} -func (fastpathDTBincIO) DecMapUint64IntL(v map[uint64]int, containerLen int, d *decoderBincIO) { - if v == nil { - halt.errorInt("cannot decode into nil map[uint64]int given stream length: ", int64(containerLen)) - } - hasLen := containerLen >= 0 - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - mk := d.d.DecodeUint64() - d.mapElemValue() - v[mk] = int(chkOvf.IntV(d.d.DecodeInt64(), intBitsize)) - } -} -func (d *decoderBincIO) fastpathDecMapUint64Int32R(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTBincIO - containerLen := d.mapStart(d.d.ReadMapStart()) - if rv.Kind() == reflect.Ptr { - vp, _ := rv2i(rv).(*map[uint64]int32) - if *vp == nil { - *vp = make(map[uint64]int32, decInferLen(containerLen, d.maxInitLen(), 12)) - } - if containerLen != 0 { - ft.DecMapUint64Int32L(*vp, containerLen, d) - } - } else if containerLen != 0 { - ft.DecMapUint64Int32L(rv2i(rv).(map[uint64]int32), containerLen, d) - } - d.mapEnd() -} -func (fastpathDTBincIO) DecMapUint64Int32L(v map[uint64]int32, containerLen int, d *decoderBincIO) { - if v == nil { - halt.errorInt("cannot decode into nil map[uint64]int32 given stream length: ", int64(containerLen)) - } - hasLen := containerLen >= 0 - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - mk := d.d.DecodeUint64() - d.mapElemValue() - v[mk] = int32(chkOvf.IntV(d.d.DecodeInt64(), 32)) - } -} -func (d *decoderBincIO) fastpathDecMapUint64Float64R(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTBincIO - containerLen := d.mapStart(d.d.ReadMapStart()) - if rv.Kind() == reflect.Ptr { - vp, _ := rv2i(rv).(*map[uint64]float64) - if *vp == nil { - *vp = make(map[uint64]float64, decInferLen(containerLen, d.maxInitLen(), 16)) - } - if containerLen != 0 { - ft.DecMapUint64Float64L(*vp, containerLen, d) - } - } else if containerLen != 0 { - ft.DecMapUint64Float64L(rv2i(rv).(map[uint64]float64), containerLen, d) - } - d.mapEnd() -} -func (fastpathDTBincIO) DecMapUint64Float64L(v map[uint64]float64, containerLen int, d *decoderBincIO) { - if v == nil { - halt.errorInt("cannot decode into nil map[uint64]float64 given stream length: ", int64(containerLen)) - } - hasLen := containerLen >= 0 - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - mk := d.d.DecodeUint64() - d.mapElemValue() - v[mk] = d.d.DecodeFloat64() - } -} -func (d *decoderBincIO) fastpathDecMapUint64BoolR(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTBincIO - containerLen := d.mapStart(d.d.ReadMapStart()) - if rv.Kind() == reflect.Ptr { - vp, _ := rv2i(rv).(*map[uint64]bool) - if *vp == nil { - *vp = make(map[uint64]bool, decInferLen(containerLen, d.maxInitLen(), 9)) - } - if containerLen != 0 { - ft.DecMapUint64BoolL(*vp, containerLen, d) - } - } else if containerLen != 0 { - ft.DecMapUint64BoolL(rv2i(rv).(map[uint64]bool), containerLen, d) - } - d.mapEnd() -} -func (fastpathDTBincIO) DecMapUint64BoolL(v map[uint64]bool, containerLen int, d *decoderBincIO) { - if v == nil { - halt.errorInt("cannot decode into nil map[uint64]bool given stream length: ", int64(containerLen)) - } - hasLen := containerLen >= 0 - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - mk := d.d.DecodeUint64() - d.mapElemValue() - v[mk] = d.d.DecodeBool() - } -} -func (d *decoderBincIO) fastpathDecMapIntIntfR(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTBincIO - containerLen := d.mapStart(d.d.ReadMapStart()) - if rv.Kind() == reflect.Ptr { - vp, _ := rv2i(rv).(*map[int]interface{}) - if *vp == nil { - *vp = make(map[int]interface{}, decInferLen(containerLen, d.maxInitLen(), 24)) - } - if containerLen != 0 { - ft.DecMapIntIntfL(*vp, containerLen, d) - } - } else if containerLen != 0 { - ft.DecMapIntIntfL(rv2i(rv).(map[int]interface{}), containerLen, d) - } - d.mapEnd() -} -func (fastpathDTBincIO) DecMapIntIntfL(v map[int]interface{}, containerLen int, d *decoderBincIO) { - if v == nil { - halt.errorInt("cannot decode into nil map[int]interface{} given stream length: ", int64(containerLen)) - } - var mv interface{} - mapGet := !d.h.MapValueReset && !d.h.InterfaceReset - hasLen := containerLen >= 0 - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - mk := int(chkOvf.IntV(d.d.DecodeInt64(), intBitsize)) - d.mapElemValue() - if mapGet { - mv = v[mk] - } else { - mv = nil - } - d.decode(&mv) - v[mk] = mv - } -} -func (d *decoderBincIO) fastpathDecMapIntStringR(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTBincIO - containerLen := d.mapStart(d.d.ReadMapStart()) - if rv.Kind() == reflect.Ptr { - vp, _ := rv2i(rv).(*map[int]string) - if *vp == nil { - *vp = make(map[int]string, decInferLen(containerLen, d.maxInitLen(), 24)) - } - if containerLen != 0 { - ft.DecMapIntStringL(*vp, containerLen, d) - } - } else if containerLen != 0 { - ft.DecMapIntStringL(rv2i(rv).(map[int]string), containerLen, d) - } - d.mapEnd() -} -func (fastpathDTBincIO) DecMapIntStringL(v map[int]string, containerLen int, d *decoderBincIO) { - if v == nil { - halt.errorInt("cannot decode into nil map[int]string given stream length: ", int64(containerLen)) - } - hasLen := containerLen >= 0 - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - mk := int(chkOvf.IntV(d.d.DecodeInt64(), intBitsize)) - d.mapElemValue() - v[mk] = d.detach2Str(d.d.DecodeStringAsBytes()) - } -} -func (d *decoderBincIO) fastpathDecMapIntBytesR(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTBincIO - containerLen := d.mapStart(d.d.ReadMapStart()) - if rv.Kind() == reflect.Ptr { - vp, _ := rv2i(rv).(*map[int][]byte) - if *vp == nil { - *vp = make(map[int][]byte, decInferLen(containerLen, d.maxInitLen(), 32)) - } - if containerLen != 0 { - ft.DecMapIntBytesL(*vp, containerLen, d) - } - } else if containerLen != 0 { - ft.DecMapIntBytesL(rv2i(rv).(map[int][]byte), containerLen, d) - } - d.mapEnd() -} -func (fastpathDTBincIO) DecMapIntBytesL(v map[int][]byte, containerLen int, d *decoderBincIO) { - if v == nil { - halt.errorInt("cannot decode into nil map[int][]byte given stream length: ", int64(containerLen)) - } - var mv []byte - mapGet := !d.h.MapValueReset - hasLen := containerLen >= 0 - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - mk := int(chkOvf.IntV(d.d.DecodeInt64(), intBitsize)) - d.mapElemValue() - if mapGet { - mv = v[mk] - } else { - mv = nil - } - v[mk], _ = d.decodeBytesInto(mv, false) - } -} -func (d *decoderBincIO) fastpathDecMapIntUint8R(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTBincIO - containerLen := d.mapStart(d.d.ReadMapStart()) - if rv.Kind() == reflect.Ptr { - vp, _ := rv2i(rv).(*map[int]uint8) - if *vp == nil { - *vp = make(map[int]uint8, decInferLen(containerLen, d.maxInitLen(), 9)) - } - if containerLen != 0 { - ft.DecMapIntUint8L(*vp, containerLen, d) - } - } else if containerLen != 0 { - ft.DecMapIntUint8L(rv2i(rv).(map[int]uint8), containerLen, d) - } - d.mapEnd() -} -func (fastpathDTBincIO) DecMapIntUint8L(v map[int]uint8, containerLen int, d *decoderBincIO) { - if v == nil { - halt.errorInt("cannot decode into nil map[int]uint8 given stream length: ", int64(containerLen)) - } - hasLen := containerLen >= 0 - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - mk := int(chkOvf.IntV(d.d.DecodeInt64(), intBitsize)) - d.mapElemValue() - v[mk] = uint8(chkOvf.UintV(d.d.DecodeUint64(), 8)) - } -} -func (d *decoderBincIO) fastpathDecMapIntUint64R(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTBincIO - containerLen := d.mapStart(d.d.ReadMapStart()) - if rv.Kind() == reflect.Ptr { - vp, _ := rv2i(rv).(*map[int]uint64) - if *vp == nil { - *vp = make(map[int]uint64, decInferLen(containerLen, d.maxInitLen(), 16)) - } - if containerLen != 0 { - ft.DecMapIntUint64L(*vp, containerLen, d) - } - } else if containerLen != 0 { - ft.DecMapIntUint64L(rv2i(rv).(map[int]uint64), containerLen, d) - } - d.mapEnd() -} -func (fastpathDTBincIO) DecMapIntUint64L(v map[int]uint64, containerLen int, d *decoderBincIO) { - if v == nil { - halt.errorInt("cannot decode into nil map[int]uint64 given stream length: ", int64(containerLen)) - } - hasLen := containerLen >= 0 - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - mk := int(chkOvf.IntV(d.d.DecodeInt64(), intBitsize)) - d.mapElemValue() - v[mk] = d.d.DecodeUint64() - } -} -func (d *decoderBincIO) fastpathDecMapIntIntR(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTBincIO - containerLen := d.mapStart(d.d.ReadMapStart()) - if rv.Kind() == reflect.Ptr { - vp, _ := rv2i(rv).(*map[int]int) - if *vp == nil { - *vp = make(map[int]int, decInferLen(containerLen, d.maxInitLen(), 16)) - } - if containerLen != 0 { - ft.DecMapIntIntL(*vp, containerLen, d) - } - } else if containerLen != 0 { - ft.DecMapIntIntL(rv2i(rv).(map[int]int), containerLen, d) - } - d.mapEnd() -} -func (fastpathDTBincIO) DecMapIntIntL(v map[int]int, containerLen int, d *decoderBincIO) { - if v == nil { - halt.errorInt("cannot decode into nil map[int]int given stream length: ", int64(containerLen)) - } - hasLen := containerLen >= 0 - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - mk := int(chkOvf.IntV(d.d.DecodeInt64(), intBitsize)) - d.mapElemValue() - v[mk] = int(chkOvf.IntV(d.d.DecodeInt64(), intBitsize)) - } -} -func (d *decoderBincIO) fastpathDecMapIntInt32R(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTBincIO - containerLen := d.mapStart(d.d.ReadMapStart()) - if rv.Kind() == reflect.Ptr { - vp, _ := rv2i(rv).(*map[int]int32) - if *vp == nil { - *vp = make(map[int]int32, decInferLen(containerLen, d.maxInitLen(), 12)) - } - if containerLen != 0 { - ft.DecMapIntInt32L(*vp, containerLen, d) - } - } else if containerLen != 0 { - ft.DecMapIntInt32L(rv2i(rv).(map[int]int32), containerLen, d) - } - d.mapEnd() -} -func (fastpathDTBincIO) DecMapIntInt32L(v map[int]int32, containerLen int, d *decoderBincIO) { - if v == nil { - halt.errorInt("cannot decode into nil map[int]int32 given stream length: ", int64(containerLen)) - } - hasLen := containerLen >= 0 - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - mk := int(chkOvf.IntV(d.d.DecodeInt64(), intBitsize)) - d.mapElemValue() - v[mk] = int32(chkOvf.IntV(d.d.DecodeInt64(), 32)) - } -} -func (d *decoderBincIO) fastpathDecMapIntFloat64R(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTBincIO - containerLen := d.mapStart(d.d.ReadMapStart()) - if rv.Kind() == reflect.Ptr { - vp, _ := rv2i(rv).(*map[int]float64) - if *vp == nil { - *vp = make(map[int]float64, decInferLen(containerLen, d.maxInitLen(), 16)) - } - if containerLen != 0 { - ft.DecMapIntFloat64L(*vp, containerLen, d) - } - } else if containerLen != 0 { - ft.DecMapIntFloat64L(rv2i(rv).(map[int]float64), containerLen, d) - } - d.mapEnd() -} -func (fastpathDTBincIO) DecMapIntFloat64L(v map[int]float64, containerLen int, d *decoderBincIO) { - if v == nil { - halt.errorInt("cannot decode into nil map[int]float64 given stream length: ", int64(containerLen)) - } - hasLen := containerLen >= 0 - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - mk := int(chkOvf.IntV(d.d.DecodeInt64(), intBitsize)) - d.mapElemValue() - v[mk] = d.d.DecodeFloat64() - } -} -func (d *decoderBincIO) fastpathDecMapIntBoolR(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTBincIO - containerLen := d.mapStart(d.d.ReadMapStart()) - if rv.Kind() == reflect.Ptr { - vp, _ := rv2i(rv).(*map[int]bool) - if *vp == nil { - *vp = make(map[int]bool, decInferLen(containerLen, d.maxInitLen(), 9)) - } - if containerLen != 0 { - ft.DecMapIntBoolL(*vp, containerLen, d) - } - } else if containerLen != 0 { - ft.DecMapIntBoolL(rv2i(rv).(map[int]bool), containerLen, d) - } - d.mapEnd() -} -func (fastpathDTBincIO) DecMapIntBoolL(v map[int]bool, containerLen int, d *decoderBincIO) { - if v == nil { - halt.errorInt("cannot decode into nil map[int]bool given stream length: ", int64(containerLen)) - } - hasLen := containerLen >= 0 - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - mk := int(chkOvf.IntV(d.d.DecodeInt64(), intBitsize)) - d.mapElemValue() - v[mk] = d.d.DecodeBool() - } -} -func (d *decoderBincIO) fastpathDecMapInt32IntfR(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTBincIO - containerLen := d.mapStart(d.d.ReadMapStart()) - if rv.Kind() == reflect.Ptr { - vp, _ := rv2i(rv).(*map[int32]interface{}) - if *vp == nil { - *vp = make(map[int32]interface{}, decInferLen(containerLen, d.maxInitLen(), 20)) - } - if containerLen != 0 { - ft.DecMapInt32IntfL(*vp, containerLen, d) - } - } else if containerLen != 0 { - ft.DecMapInt32IntfL(rv2i(rv).(map[int32]interface{}), containerLen, d) - } - d.mapEnd() -} -func (fastpathDTBincIO) DecMapInt32IntfL(v map[int32]interface{}, containerLen int, d *decoderBincIO) { - if v == nil { - halt.errorInt("cannot decode into nil map[int32]interface{} given stream length: ", int64(containerLen)) - } - var mv interface{} - mapGet := !d.h.MapValueReset && !d.h.InterfaceReset - hasLen := containerLen >= 0 - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - mk := int32(chkOvf.IntV(d.d.DecodeInt64(), 32)) - d.mapElemValue() - if mapGet { - mv = v[mk] - } else { - mv = nil - } - d.decode(&mv) - v[mk] = mv - } -} -func (d *decoderBincIO) fastpathDecMapInt32StringR(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTBincIO - containerLen := d.mapStart(d.d.ReadMapStart()) - if rv.Kind() == reflect.Ptr { - vp, _ := rv2i(rv).(*map[int32]string) - if *vp == nil { - *vp = make(map[int32]string, decInferLen(containerLen, d.maxInitLen(), 20)) - } - if containerLen != 0 { - ft.DecMapInt32StringL(*vp, containerLen, d) - } - } else if containerLen != 0 { - ft.DecMapInt32StringL(rv2i(rv).(map[int32]string), containerLen, d) - } - d.mapEnd() -} -func (fastpathDTBincIO) DecMapInt32StringL(v map[int32]string, containerLen int, d *decoderBincIO) { - if v == nil { - halt.errorInt("cannot decode into nil map[int32]string given stream length: ", int64(containerLen)) - } - hasLen := containerLen >= 0 - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - mk := int32(chkOvf.IntV(d.d.DecodeInt64(), 32)) - d.mapElemValue() - v[mk] = d.detach2Str(d.d.DecodeStringAsBytes()) - } -} -func (d *decoderBincIO) fastpathDecMapInt32BytesR(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTBincIO - containerLen := d.mapStart(d.d.ReadMapStart()) - if rv.Kind() == reflect.Ptr { - vp, _ := rv2i(rv).(*map[int32][]byte) - if *vp == nil { - *vp = make(map[int32][]byte, decInferLen(containerLen, d.maxInitLen(), 28)) - } - if containerLen != 0 { - ft.DecMapInt32BytesL(*vp, containerLen, d) - } - } else if containerLen != 0 { - ft.DecMapInt32BytesL(rv2i(rv).(map[int32][]byte), containerLen, d) - } - d.mapEnd() -} -func (fastpathDTBincIO) DecMapInt32BytesL(v map[int32][]byte, containerLen int, d *decoderBincIO) { - if v == nil { - halt.errorInt("cannot decode into nil map[int32][]byte given stream length: ", int64(containerLen)) - } - var mv []byte - mapGet := !d.h.MapValueReset - hasLen := containerLen >= 0 - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - mk := int32(chkOvf.IntV(d.d.DecodeInt64(), 32)) - d.mapElemValue() - if mapGet { - mv = v[mk] - } else { - mv = nil - } - v[mk], _ = d.decodeBytesInto(mv, false) - } -} -func (d *decoderBincIO) fastpathDecMapInt32Uint8R(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTBincIO - containerLen := d.mapStart(d.d.ReadMapStart()) - if rv.Kind() == reflect.Ptr { - vp, _ := rv2i(rv).(*map[int32]uint8) - if *vp == nil { - *vp = make(map[int32]uint8, decInferLen(containerLen, d.maxInitLen(), 5)) - } - if containerLen != 0 { - ft.DecMapInt32Uint8L(*vp, containerLen, d) - } - } else if containerLen != 0 { - ft.DecMapInt32Uint8L(rv2i(rv).(map[int32]uint8), containerLen, d) - } - d.mapEnd() -} -func (fastpathDTBincIO) DecMapInt32Uint8L(v map[int32]uint8, containerLen int, d *decoderBincIO) { - if v == nil { - halt.errorInt("cannot decode into nil map[int32]uint8 given stream length: ", int64(containerLen)) - } - hasLen := containerLen >= 0 - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - mk := int32(chkOvf.IntV(d.d.DecodeInt64(), 32)) - d.mapElemValue() - v[mk] = uint8(chkOvf.UintV(d.d.DecodeUint64(), 8)) - } -} -func (d *decoderBincIO) fastpathDecMapInt32Uint64R(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTBincIO - containerLen := d.mapStart(d.d.ReadMapStart()) - if rv.Kind() == reflect.Ptr { - vp, _ := rv2i(rv).(*map[int32]uint64) - if *vp == nil { - *vp = make(map[int32]uint64, decInferLen(containerLen, d.maxInitLen(), 12)) - } - if containerLen != 0 { - ft.DecMapInt32Uint64L(*vp, containerLen, d) - } - } else if containerLen != 0 { - ft.DecMapInt32Uint64L(rv2i(rv).(map[int32]uint64), containerLen, d) - } - d.mapEnd() -} -func (fastpathDTBincIO) DecMapInt32Uint64L(v map[int32]uint64, containerLen int, d *decoderBincIO) { - if v == nil { - halt.errorInt("cannot decode into nil map[int32]uint64 given stream length: ", int64(containerLen)) - } - hasLen := containerLen >= 0 - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - mk := int32(chkOvf.IntV(d.d.DecodeInt64(), 32)) - d.mapElemValue() - v[mk] = d.d.DecodeUint64() - } -} -func (d *decoderBincIO) fastpathDecMapInt32IntR(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTBincIO - containerLen := d.mapStart(d.d.ReadMapStart()) - if rv.Kind() == reflect.Ptr { - vp, _ := rv2i(rv).(*map[int32]int) - if *vp == nil { - *vp = make(map[int32]int, decInferLen(containerLen, d.maxInitLen(), 12)) - } - if containerLen != 0 { - ft.DecMapInt32IntL(*vp, containerLen, d) - } - } else if containerLen != 0 { - ft.DecMapInt32IntL(rv2i(rv).(map[int32]int), containerLen, d) - } - d.mapEnd() -} -func (fastpathDTBincIO) DecMapInt32IntL(v map[int32]int, containerLen int, d *decoderBincIO) { - if v == nil { - halt.errorInt("cannot decode into nil map[int32]int given stream length: ", int64(containerLen)) - } - hasLen := containerLen >= 0 - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - mk := int32(chkOvf.IntV(d.d.DecodeInt64(), 32)) - d.mapElemValue() - v[mk] = int(chkOvf.IntV(d.d.DecodeInt64(), intBitsize)) - } -} -func (d *decoderBincIO) fastpathDecMapInt32Int32R(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTBincIO - containerLen := d.mapStart(d.d.ReadMapStart()) - if rv.Kind() == reflect.Ptr { - vp, _ := rv2i(rv).(*map[int32]int32) - if *vp == nil { - *vp = make(map[int32]int32, decInferLen(containerLen, d.maxInitLen(), 8)) - } - if containerLen != 0 { - ft.DecMapInt32Int32L(*vp, containerLen, d) - } - } else if containerLen != 0 { - ft.DecMapInt32Int32L(rv2i(rv).(map[int32]int32), containerLen, d) - } - d.mapEnd() -} -func (fastpathDTBincIO) DecMapInt32Int32L(v map[int32]int32, containerLen int, d *decoderBincIO) { - if v == nil { - halt.errorInt("cannot decode into nil map[int32]int32 given stream length: ", int64(containerLen)) - } - hasLen := containerLen >= 0 - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - mk := int32(chkOvf.IntV(d.d.DecodeInt64(), 32)) - d.mapElemValue() - v[mk] = int32(chkOvf.IntV(d.d.DecodeInt64(), 32)) - } -} -func (d *decoderBincIO) fastpathDecMapInt32Float64R(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTBincIO - containerLen := d.mapStart(d.d.ReadMapStart()) - if rv.Kind() == reflect.Ptr { - vp, _ := rv2i(rv).(*map[int32]float64) - if *vp == nil { - *vp = make(map[int32]float64, decInferLen(containerLen, d.maxInitLen(), 12)) - } - if containerLen != 0 { - ft.DecMapInt32Float64L(*vp, containerLen, d) - } - } else if containerLen != 0 { - ft.DecMapInt32Float64L(rv2i(rv).(map[int32]float64), containerLen, d) - } - d.mapEnd() -} -func (fastpathDTBincIO) DecMapInt32Float64L(v map[int32]float64, containerLen int, d *decoderBincIO) { - if v == nil { - halt.errorInt("cannot decode into nil map[int32]float64 given stream length: ", int64(containerLen)) - } - hasLen := containerLen >= 0 - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - mk := int32(chkOvf.IntV(d.d.DecodeInt64(), 32)) - d.mapElemValue() - v[mk] = d.d.DecodeFloat64() - } -} -func (d *decoderBincIO) fastpathDecMapInt32BoolR(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTBincIO - containerLen := d.mapStart(d.d.ReadMapStart()) - if rv.Kind() == reflect.Ptr { - vp, _ := rv2i(rv).(*map[int32]bool) - if *vp == nil { - *vp = make(map[int32]bool, decInferLen(containerLen, d.maxInitLen(), 5)) - } - if containerLen != 0 { - ft.DecMapInt32BoolL(*vp, containerLen, d) - } - } else if containerLen != 0 { - ft.DecMapInt32BoolL(rv2i(rv).(map[int32]bool), containerLen, d) - } - d.mapEnd() -} -func (fastpathDTBincIO) DecMapInt32BoolL(v map[int32]bool, containerLen int, d *decoderBincIO) { - if v == nil { - halt.errorInt("cannot decode into nil map[int32]bool given stream length: ", int64(containerLen)) - } - hasLen := containerLen >= 0 - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - mk := int32(chkOvf.IntV(d.d.DecodeInt64(), 32)) - d.mapElemValue() - v[mk] = d.d.DecodeBool() - } -} diff --git a/vendor/github.com/ugorji/go/codec/binc.go b/vendor/github.com/ugorji/go/codec/binc.go deleted file mode 100644 index 34513550d..000000000 --- a/vendor/github.com/ugorji/go/codec/binc.go +++ /dev/null @@ -1,1066 +0,0 @@ -//go:build notmono || codec.notmono - -// Copyright (c) 2012-2020 Ugorji Nwoke. All rights reserved. -// Use of this source code is governed by a MIT license found in the LICENSE file. - -package codec - -import ( - "io" - "math" - "reflect" - "time" - "unicode/utf8" -) - -type bincEncDriver[T encWriter] struct { - noBuiltInTypes - encDriverNoopContainerWriter - encDriverContainerNoTrackerT - encInit2er - - h *BincHandle - e *encoderBase - w T - bincEncState -} - -func (e *bincEncDriver[T]) EncodeNil() { - e.w.writen1(bincBdNil) -} - -func (e *bincEncDriver[T]) EncodeTime(t time.Time) { - if t.IsZero() { - e.EncodeNil() - } else { - bs := bincEncodeTime(t) - e.w.writen1(bincVdTimestamp<<4 | uint8(len(bs))) - e.w.writeb(bs) - } -} - -func (e *bincEncDriver[T]) EncodeBool(b bool) { - if b { - e.w.writen1(bincVdSpecial<<4 | bincSpTrue) - } else { - e.w.writen1(bincVdSpecial<<4 | bincSpFalse) - } -} - -func (e *bincEncDriver[T]) encSpFloat(f float64) (done bool) { - if f == 0 { - e.w.writen1(bincVdSpecial<<4 | bincSpZeroFloat) - } else if math.IsNaN(float64(f)) { - e.w.writen1(bincVdSpecial<<4 | bincSpNan) - } else if math.IsInf(float64(f), +1) { - e.w.writen1(bincVdSpecial<<4 | bincSpPosInf) - } else if math.IsInf(float64(f), -1) { - e.w.writen1(bincVdSpecial<<4 | bincSpNegInf) - } else { - return - } - return true -} - -func (e *bincEncDriver[T]) EncodeFloat32(f float32) { - if !e.encSpFloat(float64(f)) { - e.w.writen1(bincVdFloat<<4 | bincFlBin32) - e.w.writen4(bigen.PutUint32(math.Float32bits(f))) - } -} - -func (e *bincEncDriver[T]) EncodeFloat64(f float64) { - if e.encSpFloat(f) { - return - } - b := bigen.PutUint64(math.Float64bits(f)) - if bincDoPrune { - i := 7 - for ; i >= 0 && (b[i] == 0); i-- { - } - i++ - if i <= 6 { - e.w.writen1(bincVdFloat<<4 | 0x8 | bincFlBin64) - e.w.writen1(byte(i)) - e.w.writeb(b[:i]) - return - } - } - e.w.writen1(bincVdFloat<<4 | bincFlBin64) - e.w.writen8(b) -} - -func (e *bincEncDriver[T]) encIntegerPrune32(bd byte, pos bool, v uint64) { - b := bigen.PutUint32(uint32(v)) - if bincDoPrune { - i := byte(pruneSignExt(b[:], pos)) - e.w.writen1(bd | 3 - i) - e.w.writeb(b[i:]) - } else { - e.w.writen1(bd | 3) - e.w.writen4(b) - } -} - -func (e *bincEncDriver[T]) encIntegerPrune64(bd byte, pos bool, v uint64) { - b := bigen.PutUint64(v) - if bincDoPrune { - i := byte(pruneSignExt(b[:], pos)) - e.w.writen1(bd | 7 - i) - e.w.writeb(b[i:]) - } else { - e.w.writen1(bd | 7) - e.w.writen8(b) - } -} - -func (e *bincEncDriver[T]) EncodeInt(v int64) { - if v >= 0 { - e.encUint(bincVdPosInt<<4, true, uint64(v)) - } else if v == -1 { - e.w.writen1(bincVdSpecial<<4 | bincSpNegOne) - } else { - e.encUint(bincVdNegInt<<4, false, uint64(-v)) - } -} - -func (e *bincEncDriver[T]) EncodeUint(v uint64) { - e.encUint(bincVdPosInt<<4, true, v) -} - -func (e *bincEncDriver[T]) encUint(bd byte, pos bool, v uint64) { - if v == 0 { - e.w.writen1(bincVdSpecial<<4 | bincSpZero) - } else if pos && v >= 1 && v <= 16 { - e.w.writen1(bincVdSmallInt<<4 | byte(v-1)) - } else if v <= math.MaxUint8 { - e.w.writen2(bd, byte(v)) // bd|0x0 - } else if v <= math.MaxUint16 { - e.w.writen1(bd | 0x01) - e.w.writen2(bigen.PutUint16(uint16(v))) - } else if v <= math.MaxUint32 { - e.encIntegerPrune32(bd, pos, v) - } else { - e.encIntegerPrune64(bd, pos, v) - } -} - -func (e *bincEncDriver[T]) EncodeExt(v interface{}, basetype reflect.Type, xtag uint64, ext Ext) { - var bs0, bs []byte - if ext == SelfExt { - bs0 = e.e.blist.get(1024) - bs = bs0 - sideEncode(e.h, &e.h.sideEncPool, func(se encoderI) { oneOffEncode(se, v, &bs, basetype, true) }) - } else { - bs = ext.WriteExt(v) - } - if bs == nil { - e.writeNilBytes() - goto END - } - e.encodeExtPreamble(uint8(xtag), len(bs)) - e.w.writeb(bs) -END: - if ext == SelfExt { - e.e.blist.put(bs) - if !byteSliceSameData(bs0, bs) { - e.e.blist.put(bs0) - } - } -} - -func (e *bincEncDriver[T]) EncodeRawExt(re *RawExt) { - e.encodeExtPreamble(uint8(re.Tag), len(re.Data)) - e.w.writeb(re.Data) -} - -func (e *bincEncDriver[T]) encodeExtPreamble(xtag byte, length int) { - e.encLen(bincVdCustomExt<<4, uint64(length)) - e.w.writen1(xtag) -} - -func (e *bincEncDriver[T]) WriteArrayStart(length int) { - e.encLen(bincVdArray<<4, uint64(length)) -} - -func (e *bincEncDriver[T]) WriteMapStart(length int) { - e.encLen(bincVdMap<<4, uint64(length)) -} - -func (e *bincEncDriver[T]) WriteArrayEmpty() { - // e.WriteArrayStart(0) = e.encLen(bincVdArray<<4, 0) - e.w.writen1(bincVdArray<<4 | uint8(0+4)) -} - -func (e *bincEncDriver[T]) WriteMapEmpty() { - // e.WriteMapStart(0) = e.encLen(bincVdMap<<4, 0) - e.w.writen1(bincVdMap<<4 | uint8(0+4)) -} - -func (e *bincEncDriver[T]) EncodeSymbol(v string) { - //symbols only offer benefit when string length > 1. - //This is because strings with length 1 take only 2 bytes to store - //(bd with embedded length, and single byte for string val). - - l := len(v) - if l == 0 { - e.encBytesLen(cUTF8, 0) - return - } else if l == 1 { - e.encBytesLen(cUTF8, 1) - e.w.writen1(v[0]) - return - } - if e.m == nil { - e.m = make(map[string]uint16, 16) - } - ui, ok := e.m[v] - if ok { - if ui <= math.MaxUint8 { - e.w.writen2(bincVdSymbol<<4, byte(ui)) - } else { - e.w.writen1(bincVdSymbol<<4 | 0x8) - e.w.writen2(bigen.PutUint16(ui)) - } - } else { - e.e.seq++ - ui = e.e.seq - e.m[v] = ui - var lenprec uint8 - if l <= math.MaxUint8 { - // lenprec = 0 - } else if l <= math.MaxUint16 { - lenprec = 1 - } else if int64(l) <= math.MaxUint32 { - lenprec = 2 - } else { - lenprec = 3 - } - if ui <= math.MaxUint8 { - e.w.writen2(bincVdSymbol<<4|0x4|lenprec, byte(ui)) // bincVdSymbol<<4|0x0|0x4|lenprec - } else { - e.w.writen1(bincVdSymbol<<4 | 0x8 | 0x4 | lenprec) - e.w.writen2(bigen.PutUint16(ui)) - } - if lenprec == 0 { - e.w.writen1(byte(l)) - } else if lenprec == 1 { - e.w.writen2(bigen.PutUint16(uint16(l))) - } else if lenprec == 2 { - e.w.writen4(bigen.PutUint32(uint32(l))) - } else { - e.w.writen8(bigen.PutUint64(uint64(l))) - } - e.w.writestr(v) - } -} - -func (e *bincEncDriver[T]) EncodeString(v string) { - if e.h.StringToRaw { - e.encLen(bincVdByteArray<<4, uint64(len(v))) - if len(v) > 0 { - e.w.writestr(v) - } - return - } - e.EncodeStringEnc(cUTF8, v) -} - -func (e *bincEncDriver[T]) EncodeStringNoEscape4Json(v string) { e.EncodeString(v) } - -func (e *bincEncDriver[T]) EncodeStringEnc(c charEncoding, v string) { - if e.e.c == containerMapKey && c == cUTF8 && (e.h.AsSymbols == 1) { - e.EncodeSymbol(v) - return - } - e.encLen(bincVdString<<4, uint64(len(v))) - if len(v) > 0 { - e.w.writestr(v) - } -} - -func (e *bincEncDriver[T]) EncodeStringBytesRaw(v []byte) { - e.encLen(bincVdByteArray<<4, uint64(len(v))) - if len(v) > 0 { - e.w.writeb(v) - } -} - -func (e *bincEncDriver[T]) EncodeBytes(v []byte) { - if v == nil { - e.writeNilBytes() - return - } - e.EncodeStringBytesRaw(v) -} - -func (e *bincEncDriver[T]) writeNilOr(v byte) { - if !e.h.NilCollectionToZeroLength { - v = bincBdNil - } - e.w.writen1(v) -} - -func (e *bincEncDriver[T]) writeNilArray() { - e.writeNilOr(bincVdArray<<4 | uint8(0+4)) -} - -func (e *bincEncDriver[T]) writeNilMap() { - e.writeNilOr(bincVdMap<<4 | uint8(0+4)) -} - -func (e *bincEncDriver[T]) writeNilBytes() { - e.writeNilOr(bincVdArray<<4 | uint8(0+4)) -} - -func (e *bincEncDriver[T]) encBytesLen(c charEncoding, length uint64) { - // MARKER: we currently only support UTF-8 (string) and RAW (bytearray). - // We should consider supporting bincUnicodeOther. - - if c == cRAW { - e.encLen(bincVdByteArray<<4, length) - } else { - e.encLen(bincVdString<<4, length) - } -} - -func (e *bincEncDriver[T]) encLen(bd byte, l uint64) { - if l < 12 { - e.w.writen1(bd | uint8(l+4)) - } else { - e.encLenNumber(bd, l) - } -} - -func (e *bincEncDriver[T]) encLenNumber(bd byte, v uint64) { - if v <= math.MaxUint8 { - e.w.writen2(bd, byte(v)) - } else if v <= math.MaxUint16 { - e.w.writen1(bd | 0x01) - e.w.writen2(bigen.PutUint16(uint16(v))) - } else if v <= math.MaxUint32 { - e.w.writen1(bd | 0x02) - e.w.writen4(bigen.PutUint32(uint32(v))) - } else { - e.w.writen1(bd | 0x03) - e.w.writen8(bigen.PutUint64(uint64(v))) - } -} - -//------------------------------------ - -type bincDecDriver[T decReader] struct { - decDriverNoopContainerReader - // decDriverNoopNumberHelper - decInit2er - noBuiltInTypes - - h *BincHandle - d *decoderBase - r T - - bincDecState - - // bytes bool -} - -func (d *bincDecDriver[T]) readNextBd() { - d.bd = d.r.readn1() - d.vd = d.bd >> 4 - d.vs = d.bd & 0x0f - d.bdRead = true -} - -func (d *bincDecDriver[T]) advanceNil() (null bool) { - if !d.bdRead { - d.readNextBd() - } - if d.bd == bincBdNil { - d.bdRead = false - return true // null = true - } - return -} - -func (d *bincDecDriver[T]) TryNil() bool { - return d.advanceNil() -} - -func (d *bincDecDriver[T]) ContainerType() (vt valueType) { - if !d.bdRead { - d.readNextBd() - } - if d.bd == bincBdNil { - d.bdRead = false - return valueTypeNil - } else if d.vd == bincVdByteArray { - return valueTypeBytes - } else if d.vd == bincVdString { - return valueTypeString - } else if d.vd == bincVdArray { - return valueTypeArray - } else if d.vd == bincVdMap { - return valueTypeMap - } - return valueTypeUnset -} - -func (d *bincDecDriver[T]) DecodeTime() (t time.Time) { - if d.advanceNil() { - return - } - if d.vd != bincVdTimestamp { - halt.errorf("cannot decode time - %s %x-%x/%s", msgBadDesc, d.vd, d.vs, bincdesc(d.vd, d.vs)) - } - t, err := bincDecodeTime(d.r.readx(uint(d.vs))) - halt.onerror(err) - d.bdRead = false - return -} - -func (d *bincDecDriver[T]) decFloatPruned(maxlen uint8) { - l := d.r.readn1() - if l > maxlen { - halt.errorf("cannot read float - at most %v bytes used to represent float - received %v bytes", maxlen, l) - } - for i := l; i < maxlen; i++ { - d.d.b[i] = 0 - } - d.r.readb(d.d.b[0:l]) -} - -func (d *bincDecDriver[T]) decFloatPre32() (b [4]byte) { - if d.vs&0x8 == 0 { - b = d.r.readn4() - } else { - d.decFloatPruned(4) - copy(b[:], d.d.b[:]) - } - return -} - -func (d *bincDecDriver[T]) decFloatPre64() (b [8]byte) { - if d.vs&0x8 == 0 { - b = d.r.readn8() - } else { - d.decFloatPruned(8) - copy(b[:], d.d.b[:]) - } - return -} - -func (d *bincDecDriver[T]) decFloatVal() (f float64) { - switch d.vs & 0x7 { - case bincFlBin32: - f = float64(math.Float32frombits(bigen.Uint32(d.decFloatPre32()))) - case bincFlBin64: - f = math.Float64frombits(bigen.Uint64(d.decFloatPre64())) - default: - // ok = false - halt.errorf("read float supports only float32/64 - %s %x-%x/%s", msgBadDesc, d.vd, d.vs, bincdesc(d.vd, d.vs)) - } - return -} - -func (d *bincDecDriver[T]) decUint() (v uint64) { - switch d.vs { - case 0: - v = uint64(d.r.readn1()) - case 1: - v = uint64(bigen.Uint16(d.r.readn2())) - case 2: - b3 := d.r.readn3() - var b [4]byte - copy(b[1:], b3[:]) - v = uint64(bigen.Uint32(b)) - case 3: - v = uint64(bigen.Uint32(d.r.readn4())) - case 4, 5, 6: - // lim := 7 - d.vs - // bs := d.d.b[lim:8] - // d.r.readb(bs) - // var b [8]byte - // copy(b[lim:], bs) - // v = bigen.Uint64(b) - bs := d.d.b[:8] - clear(bs) - d.r.readb(bs[(7 - d.vs):]) - v = bigen.Uint64(*(*[8]byte)(bs)) - case 7: - v = bigen.Uint64(d.r.readn8()) - default: - halt.errorf("unsigned integers with greater than 64 bits of precision not supported: d.vs: %v %x", d.vs, d.vs) - } - return -} - -func (d *bincDecDriver[T]) uintBytes() (bs []byte) { - switch d.vs { - case 0: - bs = d.d.b[:1] - bs[0] = d.r.readn1() - return - case 1: - bs = d.d.b[:2] - case 2: - bs = d.d.b[:3] - case 3: - bs = d.d.b[:4] - case 4, 5, 6: - lim := 7 - d.vs - bs = d.d.b[lim:8] - case 7: - bs = d.d.b[:8] - default: - halt.errorf("unsigned integers with greater than 64 bits of precision not supported: d.vs: %v %x", d.vs, d.vs) - } - d.r.readb(bs) - return -} - -func (d *bincDecDriver[T]) decInteger() (ui uint64, neg, ok bool) { - ok = true - vd, vs := d.vd, d.vs - if vd == bincVdPosInt { - ui = d.decUint() - } else if vd == bincVdNegInt { - ui = d.decUint() - neg = true - } else if vd == bincVdSmallInt { - ui = uint64(d.vs) + 1 - } else if vd == bincVdSpecial { - if vs == bincSpZero { - // i = 0 - } else if vs == bincSpNegOne { - neg = true - ui = 1 - } else { - ok = false - // halt.errorf("integer decode has invalid special value %x-%x/%s", d.vd, d.vs, bincdesc(d.vd, d.vs)) - } - } else { - ok = false - // halt.errorf("integer can only be decoded from int/uint. d.bd: 0x%x, d.vd: 0x%x", d.bd, d.vd) - } - return -} - -func (d *bincDecDriver[T]) decFloat() (f float64, ok bool) { - ok = true - vd, vs := d.vd, d.vs - if vd == bincVdSpecial { - if vs == bincSpNan { - f = math.NaN() - } else if vs == bincSpPosInf { - f = math.Inf(1) - } else if vs == bincSpZeroFloat || vs == bincSpZero { - - } else if vs == bincSpNegInf { - f = math.Inf(-1) - } else { - ok = false - // halt.errorf("float - invalid special value %x-%x/%s", d.vd, d.vs, bincdesc(d.vd, d.vs)) - } - } else if vd == bincVdFloat { - f = d.decFloatVal() - } else { - ok = false - } - return -} - -func (d *bincDecDriver[T]) DecodeInt64() (i int64) { - if d.advanceNil() { - return - } - v1, v2, v3 := d.decInteger() - i = decNegintPosintFloatNumberHelper{d}.int64(v1, v2, v3, false) - d.bdRead = false - return -} - -func (d *bincDecDriver[T]) DecodeUint64() (ui uint64) { - if d.advanceNil() { - return - } - ui = decNegintPosintFloatNumberHelper{d}.uint64(d.decInteger()) - d.bdRead = false - return -} - -func (d *bincDecDriver[T]) DecodeFloat64() (f float64) { - if d.advanceNil() { - return - } - v1, v2 := d.decFloat() - f = decNegintPosintFloatNumberHelper{d}.float64(v1, v2, false) - d.bdRead = false - return -} - -func (d *bincDecDriver[T]) DecodeBool() (b bool) { - if d.advanceNil() { - return - } - if d.bd == (bincVdSpecial | bincSpFalse) { - // b = false - } else if d.bd == (bincVdSpecial | bincSpTrue) { - b = true - } else { - halt.errorf("bool - %s %x-%x/%s", msgBadDesc, d.vd, d.vs, bincdesc(d.vd, d.vs)) - } - d.bdRead = false - return -} - -func (d *bincDecDriver[T]) ReadMapStart() (length int) { - if d.advanceNil() { - return containerLenNil - } - if d.vd != bincVdMap { - halt.errorf("map - %s %x-%x/%s", msgBadDesc, d.vd, d.vs, bincdesc(d.vd, d.vs)) - } - length = d.decLen() - d.bdRead = false - return -} - -func (d *bincDecDriver[T]) ReadArrayStart() (length int) { - if d.advanceNil() { - return containerLenNil - } - if d.vd != bincVdArray { - halt.errorf("array - %s %x-%x/%s", msgBadDesc, d.vd, d.vs, bincdesc(d.vd, d.vs)) - } - length = d.decLen() - d.bdRead = false - return -} - -func (d *bincDecDriver[T]) decLen() int { - if d.vs > 3 { - return int(d.vs - 4) - } - return int(d.decLenNumber()) -} - -func (d *bincDecDriver[T]) decLenNumber() (v uint64) { - if x := d.vs; x == 0 { - v = uint64(d.r.readn1()) - } else if x == 1 { - v = uint64(bigen.Uint16(d.r.readn2())) - } else if x == 2 { - v = uint64(bigen.Uint32(d.r.readn4())) - } else { - v = bigen.Uint64(d.r.readn8()) - } - return -} - -// func (d *bincDecDriver[T]) decStringBytes(bs []byte, zerocopy bool) (bs2 []byte) { -func (d *bincDecDriver[T]) DecodeStringAsBytes() (bs []byte, state dBytesAttachState) { - if d.advanceNil() { - return - } - var cond bool - var slen = -1 - switch d.vd { - case bincVdString, bincVdByteArray: - slen = d.decLen() - bs, cond = d.r.readxb(uint(slen)) - state = d.d.attachState(cond) - case bincVdSymbol: - // zerocopy doesn't apply for symbols, - // as the values must be stored in a table for later use. - var symbol uint16 - vs := d.vs - if vs&0x8 == 0 { - symbol = uint16(d.r.readn1()) - } else { - symbol = uint16(bigen.Uint16(d.r.readn2())) - } - if d.s == nil { - d.s = make(map[uint16][]byte, 16) - } - - if vs&0x4 == 0 { - bs = d.s[symbol] - } else { - switch vs & 0x3 { - case 0: - slen = int(d.r.readn1()) - case 1: - slen = int(bigen.Uint16(d.r.readn2())) - case 2: - slen = int(bigen.Uint32(d.r.readn4())) - case 3: - slen = int(bigen.Uint64(d.r.readn8())) - } - // As we are using symbols, do not store any part of - // the parameter bs in the map, as it might be a shared buffer. - bs, cond = d.r.readxb(uint(slen)) - bs = d.d.detach2Bytes(bs, d.d.attachState(cond)) - d.s[symbol] = bs - } - state = dBytesDetach - default: - halt.errorf("string/bytes - %s %x-%x/%s", msgBadDesc, d.vd, d.vs, bincdesc(d.vd, d.vs)) - } - - if d.h.ValidateUnicode && !utf8.Valid(bs) { - halt.errorf("DecodeStringAsBytes: invalid UTF-8: %s", bs) - } - - d.bdRead = false - return -} - -func (d *bincDecDriver[T]) DecodeBytes() (bs []byte, state dBytesAttachState) { - if d.advanceNil() { - return - } - var cond bool - if d.vd == bincVdArray { - slen := d.ReadArrayStart() - bs, cond = usableByteSlice(d.d.buf, slen) - for i := 0; i < slen; i++ { - bs[i] = uint8(chkOvf.UintV(d.DecodeUint64(), 8)) - } - for i := len(bs); i < slen; i++ { - bs = append(bs, uint8(chkOvf.UintV(d.DecodeUint64(), 8))) - } - if cond { - d.d.buf = bs - } - state = dBytesAttachBuffer - return - } - if !(d.vd == bincVdString || d.vd == bincVdByteArray) { - halt.errorf("bytes - %s %x-%x/%s", msgBadDesc, d.vd, d.vs, bincdesc(d.vd, d.vs)) - } - clen := d.decLen() - d.bdRead = false - bs, cond = d.r.readxb(uint(clen)) - state = d.d.attachState(cond) - return -} - -func (d *bincDecDriver[T]) DecodeExt(rv interface{}, basetype reflect.Type, xtag uint64, ext Ext) { - xbs, _, _, ok := d.decodeExtV(ext != nil, xtag) - if !ok { - return - } - if ext == SelfExt { - sideDecode(d.h, &d.h.sideDecPool, func(sd decoderI) { oneOffDecode(sd, rv, xbs, basetype, true) }) - } else { - ext.ReadExt(rv, xbs) - } -} - -func (d *bincDecDriver[T]) DecodeRawExt(re *RawExt) { - xbs, realxtag, state, ok := d.decodeExtV(false, 0) - if !ok { - return - } - re.Tag = uint64(realxtag) - re.setData(xbs, state >= dBytesAttachViewZerocopy) -} - -func (d *bincDecDriver[T]) decodeExtV(verifyTag bool, xtagIn uint64) (xbs []byte, xtag byte, bstate dBytesAttachState, ok bool) { - if xtagIn > 0xff { - halt.errorf("ext: tag must be <= 0xff; got: %v", xtagIn) - } - if d.advanceNil() { - return - } - tag := uint8(xtagIn) - if d.vd == bincVdCustomExt { - l := d.decLen() - xtag = d.r.readn1() - if verifyTag && xtag != tag { - halt.errorf("wrong extension tag - got %b, expecting: %v", xtag, tag) - } - xbs, ok = d.r.readxb(uint(l)) - bstate = d.d.attachState(ok) - // zerocopy = d.d.bytes - } else if d.vd == bincVdByteArray { - xbs, bstate = d.DecodeBytes() - } else { - halt.errorf("ext expects extensions or byte array - %s %x-%x/%s", msgBadDesc, d.vd, d.vs, bincdesc(d.vd, d.vs)) - } - d.bdRead = false - ok = true - return -} - -func (d *bincDecDriver[T]) DecodeNaked() { - if !d.bdRead { - d.readNextBd() - } - - n := d.d.naked() - var decodeFurther bool - - switch d.vd { - case bincVdSpecial: - switch d.vs { - case bincSpNil: - n.v = valueTypeNil - case bincSpFalse: - n.v = valueTypeBool - n.b = false - case bincSpTrue: - n.v = valueTypeBool - n.b = true - case bincSpNan: - n.v = valueTypeFloat - n.f = math.NaN() - case bincSpPosInf: - n.v = valueTypeFloat - n.f = math.Inf(1) - case bincSpNegInf: - n.v = valueTypeFloat - n.f = math.Inf(-1) - case bincSpZeroFloat: - n.v = valueTypeFloat - n.f = float64(0) - case bincSpZero: - n.v = valueTypeUint - n.u = uint64(0) // int8(0) - case bincSpNegOne: - n.v = valueTypeInt - n.i = int64(-1) // int8(-1) - default: - halt.errorf("cannot infer value - unrecognized special value %x-%x/%s", d.vd, d.vs, bincdesc(d.vd, d.vs)) - } - case bincVdSmallInt: - n.v = valueTypeUint - n.u = uint64(int8(d.vs)) + 1 // int8(d.vs) + 1 - case bincVdPosInt: - n.v = valueTypeUint - n.u = d.decUint() - case bincVdNegInt: - n.v = valueTypeInt - n.i = -(int64(d.decUint())) - case bincVdFloat: - n.v = valueTypeFloat - n.f = d.decFloatVal() - case bincVdString: - n.v = valueTypeString - n.s = d.d.detach2Str(d.DecodeStringAsBytes()) - case bincVdByteArray: - d.d.fauxUnionReadRawBytes(d, false, d.h.RawToString) //, d.h.ZeroCopy) - case bincVdSymbol: - n.v = valueTypeSymbol - n.s = d.d.detach2Str(d.DecodeStringAsBytes()) - case bincVdTimestamp: - n.v = valueTypeTime - tt, err := bincDecodeTime(d.r.readx(uint(d.vs))) - halt.onerror(err) - n.t = tt - case bincVdCustomExt: - n.v = valueTypeExt - l := d.decLen() - n.u = uint64(d.r.readn1()) - n.l = d.r.readx(uint(l)) - case bincVdArray: - n.v = valueTypeArray - decodeFurther = true - case bincVdMap: - n.v = valueTypeMap - decodeFurther = true - default: - halt.errorf("cannot infer value - %s %x-%x/%s", msgBadDesc, d.vd, d.vs, bincdesc(d.vd, d.vs)) - } - - if !decodeFurther { - d.bdRead = false - } - if n.v == valueTypeUint && d.h.SignedInteger { - n.v = valueTypeInt - n.i = int64(n.u) - } -} - -func (d *bincDecDriver[T]) nextValueBytes() (v []byte) { - if !d.bdRead { - d.readNextBd() - } - d.r.startRecording() - d.nextValueBytesBdReadR() - v = d.r.stopRecording() - d.bdRead = false - return -} - -// func (d *bincDecDriver[T]) nextValueBytesR(v0 []byte) (v []byte) { -// d.readNextBd() -// v = v0 -// var h decNextValueBytesHelper -// h.append1(&v, d.bytes, d.bd) -// return d.nextValueBytesBdReadR(v) -// } - -func (d *bincDecDriver[T]) nextValueBytesBdReadR() { - fnLen := func(vs byte) uint { - switch vs { - case 0: - x := d.r.readn1() - return uint(x) - case 1: - x := d.r.readn2() - return uint(bigen.Uint16(x)) - case 2: - x := d.r.readn4() - return uint(bigen.Uint32(x)) - case 3: - x := d.r.readn8() - return uint(bigen.Uint64(x)) - default: - return uint(vs - 4) - } - } - - var clen uint - - switch d.vd { - case bincVdSpecial: - switch d.vs { - case bincSpNil, bincSpFalse, bincSpTrue, bincSpNan, bincSpPosInf: // pass - case bincSpNegInf, bincSpZeroFloat, bincSpZero, bincSpNegOne: // pass - default: - halt.errorf("cannot infer value - unrecognized special value %x-%x/%s", d.vd, d.vs, bincdesc(d.vd, d.vs)) - } - case bincVdSmallInt: // pass - case bincVdPosInt, bincVdNegInt: - d.uintBytes() - case bincVdFloat: - fn := func(xlen byte) { - if d.vs&0x8 != 0 { - xlen = d.r.readn1() - if xlen > 8 { - halt.errorf("cannot read float - at most 8 bytes used to represent float - received %v bytes", xlen) - } - } - d.r.readb(d.d.b[:xlen]) - } - switch d.vs & 0x7 { - case bincFlBin32: - fn(4) - case bincFlBin64: - fn(8) - default: - halt.errorf("read float supports only float32/64 - %s %x-%x/%s", msgBadDesc, d.vd, d.vs, bincdesc(d.vd, d.vs)) - } - case bincVdString, bincVdByteArray: - clen = fnLen(d.vs) - d.r.skip(clen) - case bincVdSymbol: - if d.vs&0x8 == 0 { - d.r.readn1() - } else { - d.r.skip(2) - } - if d.vs&0x4 != 0 { - clen = fnLen(d.vs & 0x3) - d.r.skip(clen) - } - case bincVdTimestamp: - d.r.skip(uint(d.vs)) - case bincVdCustomExt: - clen = fnLen(d.vs) - d.r.readn1() // tag - d.r.skip(clen) - case bincVdArray: - clen = fnLen(d.vs) - for i := uint(0); i < clen; i++ { - d.readNextBd() - d.nextValueBytesBdReadR() - } - case bincVdMap: - clen = fnLen(d.vs) - for i := uint(0); i < clen; i++ { - d.readNextBd() - d.nextValueBytesBdReadR() - d.readNextBd() - d.nextValueBytesBdReadR() - } - default: - halt.errorf("cannot infer value - %s %x-%x/%s", msgBadDesc, d.vd, d.vs, bincdesc(d.vd, d.vs)) - } - return -} - -// ---- -// -// The following below are similar across all format files (except for the format name). -// -// We keep them together here, so that we can easily copy and compare. - -// ---- - -func (d *bincEncDriver[T]) init(hh Handle, shared *encoderBase, enc encoderI) (fp interface{}) { - callMake(&d.w) - d.h = hh.(*BincHandle) - d.e = shared - if shared.bytes { - fp = bincFpEncBytes - } else { - fp = bincFpEncIO - } - // d.w.init() - d.init2(enc) - return -} - -func (e *bincEncDriver[T]) writeBytesAsis(b []byte) { e.w.writeb(b) } - -// func (e *bincEncDriver[T]) writeStringAsisDblQuoted(v string) { e.w.writeqstr(v) } - -func (e *bincEncDriver[T]) writerEnd() { e.w.end() } - -func (e *bincEncDriver[T]) resetOutBytes(out *[]byte) { - e.w.resetBytes(*out, out) -} - -func (e *bincEncDriver[T]) resetOutIO(out io.Writer) { - e.w.resetIO(out, e.h.WriterBufferSize, &e.e.blist) -} - -// ---- - -func (d *bincDecDriver[T]) init(hh Handle, shared *decoderBase, dec decoderI) (fp interface{}) { - callMake(&d.r) - d.h = hh.(*BincHandle) - d.d = shared - if shared.bytes { - fp = bincFpDecBytes - } else { - fp = bincFpDecIO - } - // d.r.init() - d.init2(dec) - return -} - -func (d *bincDecDriver[T]) NumBytesRead() int { - return int(d.r.numread()) -} - -func (d *bincDecDriver[T]) resetInBytes(in []byte) { - d.r.resetBytes(in) -} - -func (d *bincDecDriver[T]) resetInIO(r io.Reader) { - d.r.resetIO(r, d.h.ReaderBufferSize, d.h.MaxInitLen, &d.d.blist) -} - -// ---- (custom stanza) - -func (d *bincDecDriver[T]) descBd() string { - return sprintf("%v (%s)", d.bd, bincdescbd(d.bd)) -} - -func (d *bincDecDriver[T]) DecodeFloat32() (f float32) { - return float32(chkOvf.Float32V(d.DecodeFloat64())) -} diff --git a/vendor/github.com/ugorji/go/codec/binc.mono.generated.go b/vendor/github.com/ugorji/go/codec/binc.mono.generated.go deleted file mode 100644 index 78a76027c..000000000 --- a/vendor/github.com/ugorji/go/codec/binc.mono.generated.go +++ /dev/null @@ -1,8158 +0,0 @@ -//go:build !notmono && !codec.notmono - -// Copyright (c) 2012-2020 Ugorji Nwoke. All rights reserved. -// Use of this source code is governed by a MIT license found in the LICENSE file. - -package codec - -import ( - "encoding" - - "io" - "math" - "reflect" - "slices" - "sort" - "strconv" - "sync" - "time" - "unicode/utf8" -) - -type helperEncDriverBincBytes struct{} -type encFnBincBytes struct { - i encFnInfo - fe func(*encoderBincBytes, *encFnInfo, reflect.Value) -} -type encRtidFnBincBytes struct { - rtid uintptr - fn *encFnBincBytes -} -type encoderBincBytes struct { - dh helperEncDriverBincBytes - fp *fastpathEsBincBytes - e bincEncDriverBytes - encoderBase -} -type helperDecDriverBincBytes struct{} -type decFnBincBytes struct { - i decFnInfo - fd func(*decoderBincBytes, *decFnInfo, reflect.Value) -} -type decRtidFnBincBytes struct { - rtid uintptr - fn *decFnBincBytes -} -type decoderBincBytes struct { - dh helperDecDriverBincBytes - fp *fastpathDsBincBytes - d bincDecDriverBytes - decoderBase -} -type bincEncDriverBytes struct { - noBuiltInTypes - encDriverNoopContainerWriter - encDriverContainerNoTrackerT - encInit2er - - h *BincHandle - e *encoderBase - w bytesEncAppender - bincEncState -} -type bincDecDriverBytes struct { - decDriverNoopContainerReader - - decInit2er - noBuiltInTypes - - h *BincHandle - d *decoderBase - r bytesDecReader - - bincDecState -} - -func (e *encoderBincBytes) rawExt(_ *encFnInfo, rv reflect.Value) { - if re := rv2i(rv).(*RawExt); re == nil { - e.e.EncodeNil() - } else { - e.e.EncodeRawExt(re) - } -} - -func (e *encoderBincBytes) ext(f *encFnInfo, rv reflect.Value) { - e.e.EncodeExt(rv2i(rv), f.ti.rt, f.xfTag, f.xfFn) -} - -func (e *encoderBincBytes) selferMarshal(_ *encFnInfo, rv reflect.Value) { - rv2i(rv).(Selfer).CodecEncodeSelf(&Encoder{e}) -} - -func (e *encoderBincBytes) binaryMarshal(_ *encFnInfo, rv reflect.Value) { - bs, fnerr := rv2i(rv).(encoding.BinaryMarshaler).MarshalBinary() - e.marshalRaw(bs, fnerr) -} - -func (e *encoderBincBytes) textMarshal(_ *encFnInfo, rv reflect.Value) { - bs, fnerr := rv2i(rv).(encoding.TextMarshaler).MarshalText() - e.marshalUtf8(bs, fnerr) -} - -func (e *encoderBincBytes) jsonMarshal(_ *encFnInfo, rv reflect.Value) { - bs, fnerr := rv2i(rv).(jsonMarshaler).MarshalJSON() - e.marshalAsis(bs, fnerr) -} - -func (e *encoderBincBytes) raw(_ *encFnInfo, rv reflect.Value) { - e.rawBytes(rv2i(rv).(Raw)) -} - -func (e *encoderBincBytes) encodeComplex64(v complex64) { - if imag(v) != 0 { - halt.errorf("cannot encode complex number: %v, with imaginary values: %v", any(v), any(imag(v))) - } - e.e.EncodeFloat32(real(v)) -} - -func (e *encoderBincBytes) encodeComplex128(v complex128) { - if imag(v) != 0 { - halt.errorf("cannot encode complex number: %v, with imaginary values: %v", any(v), any(imag(v))) - } - e.e.EncodeFloat64(real(v)) -} - -func (e *encoderBincBytes) kBool(_ *encFnInfo, rv reflect.Value) { - e.e.EncodeBool(rvGetBool(rv)) -} - -func (e *encoderBincBytes) kTime(_ *encFnInfo, rv reflect.Value) { - e.e.EncodeTime(rvGetTime(rv)) -} - -func (e *encoderBincBytes) kString(_ *encFnInfo, rv reflect.Value) { - e.e.EncodeString(rvGetString(rv)) -} - -func (e *encoderBincBytes) kFloat32(_ *encFnInfo, rv reflect.Value) { - e.e.EncodeFloat32(rvGetFloat32(rv)) -} - -func (e *encoderBincBytes) kFloat64(_ *encFnInfo, rv reflect.Value) { - e.e.EncodeFloat64(rvGetFloat64(rv)) -} - -func (e *encoderBincBytes) kComplex64(_ *encFnInfo, rv reflect.Value) { - e.encodeComplex64(rvGetComplex64(rv)) -} - -func (e *encoderBincBytes) kComplex128(_ *encFnInfo, rv reflect.Value) { - e.encodeComplex128(rvGetComplex128(rv)) -} - -func (e *encoderBincBytes) kInt(_ *encFnInfo, rv reflect.Value) { - e.e.EncodeInt(int64(rvGetInt(rv))) -} - -func (e *encoderBincBytes) kInt8(_ *encFnInfo, rv reflect.Value) { - e.e.EncodeInt(int64(rvGetInt8(rv))) -} - -func (e *encoderBincBytes) kInt16(_ *encFnInfo, rv reflect.Value) { - e.e.EncodeInt(int64(rvGetInt16(rv))) -} - -func (e *encoderBincBytes) kInt32(_ *encFnInfo, rv reflect.Value) { - e.e.EncodeInt(int64(rvGetInt32(rv))) -} - -func (e *encoderBincBytes) kInt64(_ *encFnInfo, rv reflect.Value) { - e.e.EncodeInt(int64(rvGetInt64(rv))) -} - -func (e *encoderBincBytes) kUint(_ *encFnInfo, rv reflect.Value) { - e.e.EncodeUint(uint64(rvGetUint(rv))) -} - -func (e *encoderBincBytes) kUint8(_ *encFnInfo, rv reflect.Value) { - e.e.EncodeUint(uint64(rvGetUint8(rv))) -} - -func (e *encoderBincBytes) kUint16(_ *encFnInfo, rv reflect.Value) { - e.e.EncodeUint(uint64(rvGetUint16(rv))) -} - -func (e *encoderBincBytes) kUint32(_ *encFnInfo, rv reflect.Value) { - e.e.EncodeUint(uint64(rvGetUint32(rv))) -} - -func (e *encoderBincBytes) kUint64(_ *encFnInfo, rv reflect.Value) { - e.e.EncodeUint(uint64(rvGetUint64(rv))) -} - -func (e *encoderBincBytes) kUintptr(_ *encFnInfo, rv reflect.Value) { - e.e.EncodeUint(uint64(rvGetUintptr(rv))) -} - -func (e *encoderBincBytes) kSeqFn(rt reflect.Type) (fn *encFnBincBytes) { - - if rt = baseRT(rt); rt.Kind() != reflect.Interface { - fn = e.fn(rt) - } - return -} - -func (e *encoderBincBytes) kArrayWMbs(rv reflect.Value, ti *typeInfo, isSlice bool) { - var l int - if isSlice { - l = rvLenSlice(rv) - } else { - l = rv.Len() - } - if l == 0 { - e.e.WriteMapEmpty() - return - } - e.haltOnMbsOddLen(l) - e.mapStart(l >> 1) - - var fn *encFnBincBytes - builtin := ti.tielem.flagEncBuiltin - if !builtin { - fn = e.kSeqFn(ti.elem) - } - - j := 0 - e.c = containerMapKey - e.e.WriteMapElemKey(true) - for { - rvv := rvArrayIndex(rv, j, ti, isSlice) - if builtin { - e.encodeIB(rv2i(baseRVRV(rvv))) - } else { - e.encodeValue(rvv, fn) - } - j++ - if j == l { - break - } - if j&1 == 0 { - e.c = containerMapKey - e.e.WriteMapElemKey(false) - } else { - e.mapElemValue() - } - } - e.c = 0 - e.e.WriteMapEnd() - -} - -func (e *encoderBincBytes) kArrayW(rv reflect.Value, ti *typeInfo, isSlice bool) { - var l int - if isSlice { - l = rvLenSlice(rv) - } else { - l = rv.Len() - } - if l <= 0 { - e.e.WriteArrayEmpty() - return - } - e.arrayStart(l) - - var fn *encFnBincBytes - if !ti.tielem.flagEncBuiltin { - fn = e.kSeqFn(ti.elem) - } - - j := 0 - e.c = containerArrayElem - e.e.WriteArrayElem(true) - builtin := ti.tielem.flagEncBuiltin - for { - rvv := rvArrayIndex(rv, j, ti, isSlice) - if builtin { - e.encodeIB(rv2i(baseRVRV(rvv))) - } else { - e.encodeValue(rvv, fn) - } - j++ - if j == l { - break - } - e.c = containerArrayElem - e.e.WriteArrayElem(false) - } - - e.c = 0 - e.e.WriteArrayEnd() -} - -func (e *encoderBincBytes) kChan(f *encFnInfo, rv reflect.Value) { - if f.ti.chandir&uint8(reflect.RecvDir) == 0 { - halt.errorStr("send-only channel cannot be encoded") - } - if !f.ti.mbs && uint8TypId == rt2id(f.ti.elem) { - e.kSliceBytesChan(rv) - return - } - rtslice := reflect.SliceOf(f.ti.elem) - rv = chanToSlice(rv, rtslice, e.h.ChanRecvTimeout) - ti := e.h.getTypeInfo(rt2id(rtslice), rtslice) - if f.ti.mbs { - e.kArrayWMbs(rv, ti, true) - } else { - e.kArrayW(rv, ti, true) - } -} - -func (e *encoderBincBytes) kSlice(f *encFnInfo, rv reflect.Value) { - if f.ti.mbs { - e.kArrayWMbs(rv, f.ti, true) - } else if f.ti.rtid == uint8SliceTypId || uint8TypId == rt2id(f.ti.elem) { - - e.e.EncodeBytes(rvGetBytes(rv)) - } else { - e.kArrayW(rv, f.ti, true) - } -} - -func (e *encoderBincBytes) kArray(f *encFnInfo, rv reflect.Value) { - if f.ti.mbs { - e.kArrayWMbs(rv, f.ti, false) - } else if handleBytesWithinKArray && uint8TypId == rt2id(f.ti.elem) { - e.e.EncodeStringBytesRaw(rvGetArrayBytes(rv, nil)) - } else { - e.kArrayW(rv, f.ti, false) - } -} - -func (e *encoderBincBytes) kSliceBytesChan(rv reflect.Value) { - - bs0 := e.blist.peek(32, true) - bs := bs0 - - irv := rv2i(rv) - ch, ok := irv.(<-chan byte) - if !ok { - ch = irv.(chan byte) - } - -L1: - switch timeout := e.h.ChanRecvTimeout; { - case timeout == 0: - for { - select { - case b := <-ch: - bs = append(bs, b) - default: - break L1 - } - } - case timeout > 0: - tt := time.NewTimer(timeout) - for { - select { - case b := <-ch: - bs = append(bs, b) - case <-tt.C: - - break L1 - } - } - default: - for b := range ch { - bs = append(bs, b) - } - } - - e.e.EncodeBytes(bs) - e.blist.put(bs) - if !byteSliceSameData(bs0, bs) { - e.blist.put(bs0) - } -} - -func (e *encoderBincBytes) kStructFieldKey(keyType valueType, encName string) { - - if keyType == valueTypeString { - e.e.EncodeString(encName) - } else if keyType == valueTypeInt { - e.e.EncodeInt(must.Int(strconv.ParseInt(encName, 10, 64))) - } else if keyType == valueTypeUint { - e.e.EncodeUint(must.Uint(strconv.ParseUint(encName, 10, 64))) - } else if keyType == valueTypeFloat { - e.e.EncodeFloat64(must.Float(strconv.ParseFloat(encName, 64))) - } else { - halt.errorStr2("invalid struct key type: ", keyType.String()) - } - -} - -func (e *encoderBincBytes) kStructSimple(f *encFnInfo, rv reflect.Value) { - _ = e.e - tisfi := f.ti.sfi.source() - - chkCirRef := e.h.CheckCircularRef - var si *structFieldInfo - var j int - - if f.ti.toArray || e.h.StructToArray { - if len(tisfi) == 0 { - e.e.WriteArrayEmpty() - return - } - e.arrayStart(len(tisfi)) - for j, si = range tisfi { - e.c = containerArrayElem - e.e.WriteArrayElem(j == 0) - if si.encBuiltin { - e.encodeIB(rv2i(si.fieldNoAlloc(rv, true))) - } else { - e.encodeValue(si.fieldNoAlloc(rv, !chkCirRef), nil) - } - } - e.c = 0 - e.e.WriteArrayEnd() - } else { - if len(tisfi) == 0 { - e.e.WriteMapEmpty() - return - } - if e.h.Canonical { - tisfi = f.ti.sfi.sorted() - } - e.mapStart(len(tisfi)) - for j, si = range tisfi { - e.c = containerMapKey - e.e.WriteMapElemKey(j == 0) - e.e.EncodeStringNoEscape4Json(si.encName) - e.mapElemValue() - if si.encBuiltin { - e.encodeIB(rv2i(si.fieldNoAlloc(rv, true))) - } else { - e.encodeValue(si.fieldNoAlloc(rv, !chkCirRef), nil) - } - } - e.c = 0 - e.e.WriteMapEnd() - } -} - -func (e *encoderBincBytes) kStruct(f *encFnInfo, rv reflect.Value) { - _ = e.e - ti := f.ti - toMap := !(ti.toArray || e.h.StructToArray) - var mf map[string]interface{} - if ti.flagMissingFielder { - toMap = true - mf = rv2i(rv).(MissingFielder).CodecMissingFields() - } else if ti.flagMissingFielderPtr { - toMap = true - if rv.CanAddr() { - mf = rv2i(rvAddr(rv, ti.ptr)).(MissingFielder).CodecMissingFields() - } else { - mf = rv2i(e.addrRV(rv, ti.rt, ti.ptr)).(MissingFielder).CodecMissingFields() - } - } - newlen := len(mf) - tisfi := ti.sfi.source() - newlen += len(tisfi) - - var fkvs = e.slist.get(newlen)[:newlen] - - recur := e.h.RecursiveEmptyCheck - chkCirRef := e.h.CheckCircularRef - - var xlen int - - var kv sfiRv - var j int - var sf encStructFieldObj - if toMap { - newlen = 0 - if e.h.Canonical { - tisfi = f.ti.sfi.sorted() - } - for _, si := range tisfi { - - if si.omitEmpty { - kv.r = si.fieldNoAlloc(rv, false) - if isEmptyValue(kv.r, e.h.TypeInfos, recur) { - continue - } - } else { - kv.r = si.fieldNoAlloc(rv, si.encBuiltin || !chkCirRef) - } - kv.v = si - fkvs[newlen] = kv - newlen++ - } - - var mf2s []stringIntf - if len(mf) != 0 { - mf2s = make([]stringIntf, 0, len(mf)) - for k, v := range mf { - if k == "" { - continue - } - if ti.infoFieldOmitempty && isEmptyValue(reflect.ValueOf(v), e.h.TypeInfos, recur) { - continue - } - mf2s = append(mf2s, stringIntf{k, v}) - } - } - - xlen = newlen + len(mf2s) - if xlen == 0 { - e.e.WriteMapEmpty() - goto END - } - - e.mapStart(xlen) - - if len(mf2s) != 0 && e.h.Canonical { - mf2w := make([]encStructFieldObj, newlen+len(mf2s)) - for j = 0; j < newlen; j++ { - kv = fkvs[j] - mf2w[j] = encStructFieldObj{kv.v.encName, kv.r, nil, true, - !kv.v.encNameEscape4Json, kv.v.encBuiltin} - } - for _, v := range mf2s { - mf2w[j] = encStructFieldObj{v.v, reflect.Value{}, v.i, false, false, false} - j++ - } - sort.Sort((encStructFieldObjSlice)(mf2w)) - for j, sf = range mf2w { - e.c = containerMapKey - e.e.WriteMapElemKey(j == 0) - if ti.keyType == valueTypeString && sf.noEsc4json { - e.e.EncodeStringNoEscape4Json(sf.key) - } else { - e.kStructFieldKey(ti.keyType, sf.key) - } - e.mapElemValue() - if sf.isRv { - if sf.builtin { - e.encodeIB(rv2i(baseRVRV(sf.rv))) - } else { - e.encodeValue(sf.rv, nil) - } - } else { - if !e.encodeBuiltin(sf.intf) { - e.encodeR(reflect.ValueOf(sf.intf)) - } - - } - } - } else { - keytyp := ti.keyType - for j = 0; j < newlen; j++ { - kv = fkvs[j] - e.c = containerMapKey - e.e.WriteMapElemKey(j == 0) - if ti.keyType == valueTypeString && !kv.v.encNameEscape4Json { - e.e.EncodeStringNoEscape4Json(kv.v.encName) - } else { - e.kStructFieldKey(keytyp, kv.v.encName) - } - e.mapElemValue() - if kv.v.encBuiltin { - e.encodeIB(rv2i(baseRVRV(kv.r))) - } else { - e.encodeValue(kv.r, nil) - } - } - for _, v := range mf2s { - e.c = containerMapKey - e.e.WriteMapElemKey(j == 0) - e.kStructFieldKey(keytyp, v.v) - e.mapElemValue() - if !e.encodeBuiltin(v.i) { - e.encodeR(reflect.ValueOf(v.i)) - } - - j++ - } - } - - e.c = 0 - e.e.WriteMapEnd() - } else { - newlen = len(tisfi) - for i, si := range tisfi { - - if si.omitEmpty { - - kv.r = si.fieldNoAlloc(rv, false) - if isEmptyContainerValue(kv.r, e.h.TypeInfos, recur) { - kv.r = reflect.Value{} - } - } else { - kv.r = si.fieldNoAlloc(rv, si.encBuiltin || !chkCirRef) - } - kv.v = si - fkvs[i] = kv - } - - if newlen == 0 { - e.e.WriteArrayEmpty() - goto END - } - - e.arrayStart(newlen) - for j = 0; j < newlen; j++ { - e.c = containerArrayElem - e.e.WriteArrayElem(j == 0) - kv = fkvs[j] - if !kv.r.IsValid() { - e.e.EncodeNil() - } else if kv.v.encBuiltin { - e.encodeIB(rv2i(baseRVRV(kv.r))) - } else { - e.encodeValue(kv.r, nil) - } - } - e.c = 0 - e.e.WriteArrayEnd() - } - -END: - - e.slist.put(fkvs) -} - -func (e *encoderBincBytes) kMap(f *encFnInfo, rv reflect.Value) { - _ = e.e - l := rvLenMap(rv) - if l == 0 { - e.e.WriteMapEmpty() - return - } - e.mapStart(l) - - var keyFn, valFn *encFnBincBytes - - ktypeKind := reflect.Kind(f.ti.keykind) - vtypeKind := reflect.Kind(f.ti.elemkind) - - rtval := f.ti.elem - rtvalkind := vtypeKind - for rtvalkind == reflect.Ptr { - rtval = rtval.Elem() - rtvalkind = rtval.Kind() - } - if rtvalkind != reflect.Interface { - valFn = e.fn(rtval) - } - - var rvv = mapAddrLoopvarRV(f.ti.elem, vtypeKind) - - rtkey := f.ti.key - var keyTypeIsString = stringTypId == rt2id(rtkey) - if keyTypeIsString { - keyFn = e.fn(rtkey) - } else { - for rtkey.Kind() == reflect.Ptr { - rtkey = rtkey.Elem() - } - if rtkey.Kind() != reflect.Interface { - keyFn = e.fn(rtkey) - } - } - - if e.h.Canonical { - e.kMapCanonical(f.ti, rv, rvv, keyFn, valFn) - e.c = 0 - e.e.WriteMapEnd() - return - } - - var rvk = mapAddrLoopvarRV(f.ti.key, ktypeKind) - - var it mapIter - mapRange(&it, rv, rvk, rvv, true) - - kbuiltin := f.ti.tikey.flagEncBuiltin - vbuiltin := f.ti.tielem.flagEncBuiltin - for j := 0; it.Next(); j++ { - rv = it.Key() - e.c = containerMapKey - e.e.WriteMapElemKey(j == 0) - if keyTypeIsString { - e.e.EncodeString(rvGetString(rv)) - } else if kbuiltin { - e.encodeIB(rv2i(baseRVRV(rv))) - } else { - e.encodeValue(rv, keyFn) - } - e.mapElemValue() - rv = it.Value() - if vbuiltin { - e.encodeIB(rv2i(baseRVRV(rv))) - } else { - e.encodeValue(it.Value(), valFn) - } - } - it.Done() - - e.c = 0 - e.e.WriteMapEnd() -} - -func (e *encoderBincBytes) kMapCanonical(ti *typeInfo, rv, rvv reflect.Value, keyFn, valFn *encFnBincBytes) { - _ = e.e - - rtkey := ti.key - rtkeydecl := rtkey.PkgPath() == "" && rtkey.Name() != "" - - mks := rv.MapKeys() - rtkeyKind := rtkey.Kind() - mparams := getMapReqParams(ti) - - switch rtkeyKind { - case reflect.Bool: - - if len(mks) == 2 && mks[0].Bool() { - mks[0], mks[1] = mks[1], mks[0] - } - for i := range mks { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - if rtkeydecl { - e.e.EncodeBool(mks[i].Bool()) - } else { - e.encodeValueNonNil(mks[i], keyFn) - } - e.mapElemValue() - e.encodeValue(mapGet(rv, mks[i], rvv, mparams), valFn) - } - case reflect.String: - mksv := make([]orderedRv[string], len(mks)) - for i, k := range mks { - v := &mksv[i] - v.r = k - v.v = rvGetString(k) - } - slices.SortFunc(mksv, cmpOrderedRv) - for i := range mksv { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - if rtkeydecl { - e.e.EncodeString(mksv[i].v) - } else { - e.encodeValueNonNil(mksv[i].r, keyFn) - } - e.mapElemValue() - e.encodeValue(mapGet(rv, mksv[i].r, rvv, mparams), valFn) - } - case reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64, reflect.Uint, reflect.Uintptr: - mksv := make([]orderedRv[uint64], len(mks)) - for i, k := range mks { - v := &mksv[i] - v.r = k - v.v = k.Uint() - } - slices.SortFunc(mksv, cmpOrderedRv) - for i := range mksv { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - if rtkeydecl { - e.e.EncodeUint(mksv[i].v) - } else { - e.encodeValueNonNil(mksv[i].r, keyFn) - } - e.mapElemValue() - e.encodeValue(mapGet(rv, mksv[i].r, rvv, mparams), valFn) - } - case reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64, reflect.Int: - mksv := make([]orderedRv[int64], len(mks)) - for i, k := range mks { - v := &mksv[i] - v.r = k - v.v = k.Int() - } - slices.SortFunc(mksv, cmpOrderedRv) - for i := range mksv { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - if rtkeydecl { - e.e.EncodeInt(mksv[i].v) - } else { - e.encodeValueNonNil(mksv[i].r, keyFn) - } - e.mapElemValue() - e.encodeValue(mapGet(rv, mksv[i].r, rvv, mparams), valFn) - } - case reflect.Float32: - mksv := make([]orderedRv[float64], len(mks)) - for i, k := range mks { - v := &mksv[i] - v.r = k - v.v = k.Float() - } - slices.SortFunc(mksv, cmpOrderedRv) - for i := range mksv { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - if rtkeydecl { - e.e.EncodeFloat32(float32(mksv[i].v)) - } else { - e.encodeValueNonNil(mksv[i].r, keyFn) - } - e.mapElemValue() - e.encodeValue(mapGet(rv, mksv[i].r, rvv, mparams), valFn) - } - case reflect.Float64: - mksv := make([]orderedRv[float64], len(mks)) - for i, k := range mks { - v := &mksv[i] - v.r = k - v.v = k.Float() - } - slices.SortFunc(mksv, cmpOrderedRv) - for i := range mksv { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - if rtkeydecl { - e.e.EncodeFloat64(mksv[i].v) - } else { - e.encodeValueNonNil(mksv[i].r, keyFn) - } - e.mapElemValue() - e.encodeValue(mapGet(rv, mksv[i].r, rvv, mparams), valFn) - } - default: - if rtkey == timeTyp { - mksv := make([]timeRv, len(mks)) - for i, k := range mks { - v := &mksv[i] - v.r = k - v.v = rv2i(k).(time.Time) - } - slices.SortFunc(mksv, cmpTimeRv) - for i := range mksv { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeTime(mksv[i].v) - e.mapElemValue() - e.encodeValue(mapGet(rv, mksv[i].r, rvv, mparams), valFn) - } - break - } - - bs0 := e.blist.get(len(mks) * 16) - mksv := bs0 - mksbv := make([]bytesRv, len(mks)) - - sideEncode(e.hh, &e.h.sideEncPool, func(se encoderI) { - se.ResetBytes(&mksv) - for i, k := range mks { - v := &mksbv[i] - l := len(mksv) - se.setContainerState(containerMapKey) - se.encodeR(baseRVRV(k)) - se.atEndOfEncode() - se.writerEnd() - v.r = k - v.v = mksv[l:] - } - }) - - slices.SortFunc(mksbv, cmpBytesRv) - for j := range mksbv { - e.c = containerMapKey - e.e.WriteMapElemKey(j == 0) - e.e.writeBytesAsis(mksbv[j].v) - e.mapElemValue() - e.encodeValue(mapGet(rv, mksbv[j].r, rvv, mparams), valFn) - } - e.blist.put(mksv) - if !byteSliceSameData(bs0, mksv) { - e.blist.put(bs0) - } - } -} - -func (e *encoderBincBytes) init(h Handle) { - initHandle(h) - callMake(&e.e) - e.hh = h - e.h = h.getBasicHandle() - - e.err = errEncoderNotInitialized - - e.fp = e.e.init(h, &e.encoderBase, e).(*fastpathEsBincBytes) - - if e.bytes { - e.rtidFn = &e.h.rtidFnsEncBytes - e.rtidFnNoExt = &e.h.rtidFnsEncNoExtBytes - } else { - e.rtidFn = &e.h.rtidFnsEncIO - e.rtidFnNoExt = &e.h.rtidFnsEncNoExtIO - } - - e.reset() -} - -func (e *encoderBincBytes) reset() { - e.e.reset() - if e.ci != nil { - e.ci = e.ci[:0] - } - e.c = 0 - e.calls = 0 - e.seq = 0 - e.err = nil -} - -func (e *encoderBincBytes) Encode(v interface{}) (err error) { - - defer panicValToErr(e, callRecoverSentinel, &e.err, &err, debugging) - e.mustEncode(v) - return -} - -func (e *encoderBincBytes) MustEncode(v interface{}) { - defer panicValToErr(e, callRecoverSentinel, &e.err, nil, true) - e.mustEncode(v) - return -} - -func (e *encoderBincBytes) mustEncode(v interface{}) { - halt.onerror(e.err) - if e.hh == nil { - halt.onerror(errNoFormatHandle) - } - - e.calls++ - if !e.encodeBuiltin(v) { - e.encodeR(reflect.ValueOf(v)) - } - - e.calls-- - if e.calls == 0 { - e.e.atEndOfEncode() - e.e.writerEnd() - } -} - -func (e *encoderBincBytes) encodeI(iv interface{}) { - if !e.encodeBuiltin(iv) { - e.encodeR(reflect.ValueOf(iv)) - } -} - -func (e *encoderBincBytes) encodeIB(iv interface{}) { - if !e.encodeBuiltin(iv) { - - halt.errorStr("[should not happen] invalid type passed to encodeBuiltin") - } -} - -func (e *encoderBincBytes) encodeR(base reflect.Value) { - e.encodeValue(base, nil) -} - -func (e *encoderBincBytes) encodeBuiltin(iv interface{}) (ok bool) { - ok = true - switch v := iv.(type) { - case nil: - e.e.EncodeNil() - - case Raw: - e.rawBytes(v) - case string: - e.e.EncodeString(v) - case bool: - e.e.EncodeBool(v) - case int: - e.e.EncodeInt(int64(v)) - case int8: - e.e.EncodeInt(int64(v)) - case int16: - e.e.EncodeInt(int64(v)) - case int32: - e.e.EncodeInt(int64(v)) - case int64: - e.e.EncodeInt(v) - case uint: - e.e.EncodeUint(uint64(v)) - case uint8: - e.e.EncodeUint(uint64(v)) - case uint16: - e.e.EncodeUint(uint64(v)) - case uint32: - e.e.EncodeUint(uint64(v)) - case uint64: - e.e.EncodeUint(v) - case uintptr: - e.e.EncodeUint(uint64(v)) - case float32: - e.e.EncodeFloat32(v) - case float64: - e.e.EncodeFloat64(v) - case complex64: - e.encodeComplex64(v) - case complex128: - e.encodeComplex128(v) - case time.Time: - e.e.EncodeTime(v) - case []byte: - e.e.EncodeBytes(v) - default: - - ok = !skipFastpathTypeSwitchInDirectCall && e.dh.fastpathEncodeTypeSwitch(iv, e) - } - return -} - -func (e *encoderBincBytes) encodeValue(rv reflect.Value, fn *encFnBincBytes) { - - var ciPushes int - - var rvp reflect.Value - var rvpValid bool - -RV: - switch rv.Kind() { - case reflect.Ptr: - if rvIsNil(rv) { - e.e.EncodeNil() - goto END - } - rvpValid = true - rvp = rv - rv = rv.Elem() - - if e.h.CheckCircularRef && e.ci.canPushElemKind(rv.Kind()) { - e.ci.push(rv2i(rvp)) - ciPushes++ - } - goto RV - case reflect.Interface: - if rvIsNil(rv) { - e.e.EncodeNil() - goto END - } - rvpValid = false - rvp = reflect.Value{} - rv = rv.Elem() - fn = nil - goto RV - case reflect.Map: - if rvIsNil(rv) { - if e.h.NilCollectionToZeroLength { - e.e.WriteMapEmpty() - } else { - e.e.EncodeNil() - } - goto END - } - case reflect.Slice, reflect.Chan: - if rvIsNil(rv) { - if e.h.NilCollectionToZeroLength { - e.e.WriteArrayEmpty() - } else { - e.e.EncodeNil() - } - goto END - } - case reflect.Invalid, reflect.Func: - e.e.EncodeNil() - goto END - } - - if fn == nil { - fn = e.fn(rv.Type()) - } - - if !fn.i.addrE { - - } else if rvpValid { - rv = rvp - } else if rv.CanAddr() { - rv = rvAddr(rv, fn.i.ti.ptr) - } else { - rv = e.addrRV(rv, fn.i.ti.rt, fn.i.ti.ptr) - } - fn.fe(e, &fn.i, rv) - -END: - if ciPushes > 0 { - e.ci.pop(ciPushes) - } -} - -func (e *encoderBincBytes) encodeValueNonNil(rv reflect.Value, fn *encFnBincBytes) { - - if fn.i.addrE { - if rv.CanAddr() { - rv = rvAddr(rv, fn.i.ti.ptr) - } else { - rv = e.addrRV(rv, fn.i.ti.rt, fn.i.ti.ptr) - } - } - fn.fe(e, &fn.i, rv) -} - -func (e *encoderBincBytes) encodeAs(v interface{}, t reflect.Type, ext bool) { - if ext { - e.encodeValue(baseRV(v), e.fn(t)) - } else { - e.encodeValue(baseRV(v), e.fnNoExt(t)) - } -} - -func (e *encoderBincBytes) marshalUtf8(bs []byte, fnerr error) { - halt.onerror(fnerr) - if bs == nil { - e.e.EncodeNil() - } else { - e.e.EncodeString(stringView(bs)) - } -} - -func (e *encoderBincBytes) marshalAsis(bs []byte, fnerr error) { - halt.onerror(fnerr) - if bs == nil { - e.e.EncodeNil() - } else { - e.e.writeBytesAsis(bs) - } -} - -func (e *encoderBincBytes) marshalRaw(bs []byte, fnerr error) { - halt.onerror(fnerr) - e.e.EncodeBytes(bs) -} - -func (e *encoderBincBytes) rawBytes(vv Raw) { - v := []byte(vv) - if !e.h.Raw { - halt.errorBytes("Raw values cannot be encoded: ", v) - } - e.e.writeBytesAsis(v) -} - -func (e *encoderBincBytes) fn(t reflect.Type) *encFnBincBytes { - return e.dh.encFnViaBH(t, e.rtidFn, e.h, e.fp, false) -} - -func (e *encoderBincBytes) fnNoExt(t reflect.Type) *encFnBincBytes { - return e.dh.encFnViaBH(t, e.rtidFnNoExt, e.h, e.fp, true) -} - -func (e *encoderBincBytes) mapStart(length int) { - e.e.WriteMapStart(length) - e.c = containerMapStart -} - -func (e *encoderBincBytes) mapElemValue() { - e.e.WriteMapElemValue() - e.c = containerMapValue -} - -func (e *encoderBincBytes) arrayStart(length int) { - e.e.WriteArrayStart(length) - e.c = containerArrayStart -} - -func (e *encoderBincBytes) writerEnd() { - e.e.writerEnd() -} - -func (e *encoderBincBytes) atEndOfEncode() { - e.e.atEndOfEncode() -} - -func (e *encoderBincBytes) Reset(w io.Writer) { - if e.bytes { - halt.onerror(errEncNoResetBytesWithWriter) - } - e.reset() - if w == nil { - w = io.Discard - } - e.e.resetOutIO(w) -} - -func (e *encoderBincBytes) ResetBytes(out *[]byte) { - if !e.bytes { - halt.onerror(errEncNoResetWriterWithBytes) - } - e.resetBytes(out) -} - -func (e *encoderBincBytes) resetBytes(out *[]byte) { - e.reset() - if out == nil { - out = &bytesEncAppenderDefOut - } - e.e.resetOutBytes(out) -} - -func (helperEncDriverBincBytes) newEncoderBytes(out *[]byte, h Handle) *encoderBincBytes { - var c1 encoderBincBytes - c1.bytes = true - c1.init(h) - c1.ResetBytes(out) - return &c1 -} - -func (helperEncDriverBincBytes) newEncoderIO(out io.Writer, h Handle) *encoderBincBytes { - var c1 encoderBincBytes - c1.bytes = false - c1.init(h) - c1.Reset(out) - return &c1 -} - -func (helperEncDriverBincBytes) encFnloadFastpathUnderlying(ti *typeInfo, fp *fastpathEsBincBytes) (f *fastpathEBincBytes, u reflect.Type) { - rtid := rt2id(ti.fastpathUnderlying) - idx, ok := fastpathAvIndex(rtid) - if !ok { - return - } - f = &fp[idx] - if uint8(reflect.Array) == ti.kind { - u = reflect.ArrayOf(ti.rt.Len(), ti.elem) - } else { - u = f.rt - } - return -} - -func (helperEncDriverBincBytes) encFindRtidFn(s []encRtidFnBincBytes, rtid uintptr) (i uint, fn *encFnBincBytes) { - - var h uint - var j = uint(len(s)) -LOOP: - if i < j { - h = (i + j) >> 1 - if s[h].rtid < rtid { - i = h + 1 - } else { - j = h - } - goto LOOP - } - if i < uint(len(s)) && s[i].rtid == rtid { - fn = s[i].fn - } - return -} - -func (helperEncDriverBincBytes) encFromRtidFnSlice(fns *atomicRtidFnSlice) (s []encRtidFnBincBytes) { - if v := fns.load(); v != nil { - s = *(lowLevelToPtr[[]encRtidFnBincBytes](v)) - } - return -} - -func (dh helperEncDriverBincBytes) encFnViaBH(rt reflect.Type, fns *atomicRtidFnSlice, - x *BasicHandle, fp *fastpathEsBincBytes, checkExt bool) (fn *encFnBincBytes) { - return dh.encFnVia(rt, fns, x.typeInfos(), &x.mu, x.extHandle, fp, - checkExt, x.CheckCircularRef, x.timeBuiltin, x.binaryHandle, x.jsonHandle) -} - -func (dh helperEncDriverBincBytes) encFnVia(rt reflect.Type, fns *atomicRtidFnSlice, - tinfos *TypeInfos, mu *sync.Mutex, exth extHandle, fp *fastpathEsBincBytes, - checkExt, checkCircularRef, timeBuiltin, binaryEncoding, json bool) (fn *encFnBincBytes) { - rtid := rt2id(rt) - var sp []encRtidFnBincBytes = dh.encFromRtidFnSlice(fns) - if sp != nil { - _, fn = dh.encFindRtidFn(sp, rtid) - } - if fn == nil { - fn = dh.encFnViaLoader(rt, rtid, fns, tinfos, mu, exth, fp, checkExt, checkCircularRef, timeBuiltin, binaryEncoding, json) - } - return -} - -func (dh helperEncDriverBincBytes) encFnViaLoader(rt reflect.Type, rtid uintptr, fns *atomicRtidFnSlice, - tinfos *TypeInfos, mu *sync.Mutex, exth extHandle, fp *fastpathEsBincBytes, - checkExt, checkCircularRef, timeBuiltin, binaryEncoding, json bool) (fn *encFnBincBytes) { - - fn = dh.encFnLoad(rt, rtid, tinfos, exth, fp, checkExt, checkCircularRef, timeBuiltin, binaryEncoding, json) - var sp []encRtidFnBincBytes - mu.Lock() - sp = dh.encFromRtidFnSlice(fns) - - if sp == nil { - sp = []encRtidFnBincBytes{{rtid, fn}} - fns.store(ptrToLowLevel(&sp)) - } else { - idx, fn2 := dh.encFindRtidFn(sp, rtid) - if fn2 == nil { - sp2 := make([]encRtidFnBincBytes, len(sp)+1) - copy(sp2[idx+1:], sp[idx:]) - copy(sp2, sp[:idx]) - sp2[idx] = encRtidFnBincBytes{rtid, fn} - fns.store(ptrToLowLevel(&sp2)) - } - } - mu.Unlock() - return -} - -func (dh helperEncDriverBincBytes) encFnLoad(rt reflect.Type, rtid uintptr, tinfos *TypeInfos, - exth extHandle, fp *fastpathEsBincBytes, - checkExt, checkCircularRef, timeBuiltin, binaryEncoding, json bool) (fn *encFnBincBytes) { - fn = new(encFnBincBytes) - fi := &(fn.i) - ti := tinfos.get(rtid, rt) - fi.ti = ti - rk := reflect.Kind(ti.kind) - - if rtid == timeTypId && timeBuiltin { - fn.fe = (*encoderBincBytes).kTime - } else if rtid == rawTypId { - fn.fe = (*encoderBincBytes).raw - } else if rtid == rawExtTypId { - fn.fe = (*encoderBincBytes).rawExt - fi.addrE = true - } else if xfFn := exth.getExt(rtid, checkExt); xfFn != nil { - fi.xfTag, fi.xfFn = xfFn.tag, xfFn.ext - fn.fe = (*encoderBincBytes).ext - if rk == reflect.Struct || rk == reflect.Array { - fi.addrE = true - } - } else if ti.flagSelfer || ti.flagSelferPtr { - fn.fe = (*encoderBincBytes).selferMarshal - fi.addrE = ti.flagSelferPtr - } else if supportMarshalInterfaces && binaryEncoding && - (ti.flagBinaryMarshaler || ti.flagBinaryMarshalerPtr) && - (ti.flagBinaryUnmarshaler || ti.flagBinaryUnmarshalerPtr) { - fn.fe = (*encoderBincBytes).binaryMarshal - fi.addrE = ti.flagBinaryMarshalerPtr - } else if supportMarshalInterfaces && !binaryEncoding && json && - (ti.flagJsonMarshaler || ti.flagJsonMarshalerPtr) && - (ti.flagJsonUnmarshaler || ti.flagJsonUnmarshalerPtr) { - - fn.fe = (*encoderBincBytes).jsonMarshal - fi.addrE = ti.flagJsonMarshalerPtr - } else if supportMarshalInterfaces && !binaryEncoding && - (ti.flagTextMarshaler || ti.flagTextMarshalerPtr) && - (ti.flagTextUnmarshaler || ti.flagTextUnmarshalerPtr) { - fn.fe = (*encoderBincBytes).textMarshal - fi.addrE = ti.flagTextMarshalerPtr - } else { - if fastpathEnabled && (rk == reflect.Map || rk == reflect.Slice || rk == reflect.Array) { - - var rtid2 uintptr - if !ti.flagHasPkgPath { - rtid2 = rtid - if rk == reflect.Array { - rtid2 = rt2id(ti.key) - } - if idx, ok := fastpathAvIndex(rtid2); ok { - fn.fe = fp[idx].encfn - } - } else { - - xfe, xrt := dh.encFnloadFastpathUnderlying(ti, fp) - if xfe != nil { - xfnf := xfe.encfn - fn.fe = func(e *encoderBincBytes, xf *encFnInfo, xrv reflect.Value) { - xfnf(e, xf, rvConvert(xrv, xrt)) - } - } - } - } - if fn.fe == nil { - switch rk { - case reflect.Bool: - fn.fe = (*encoderBincBytes).kBool - case reflect.String: - - fn.fe = (*encoderBincBytes).kString - case reflect.Int: - fn.fe = (*encoderBincBytes).kInt - case reflect.Int8: - fn.fe = (*encoderBincBytes).kInt8 - case reflect.Int16: - fn.fe = (*encoderBincBytes).kInt16 - case reflect.Int32: - fn.fe = (*encoderBincBytes).kInt32 - case reflect.Int64: - fn.fe = (*encoderBincBytes).kInt64 - case reflect.Uint: - fn.fe = (*encoderBincBytes).kUint - case reflect.Uint8: - fn.fe = (*encoderBincBytes).kUint8 - case reflect.Uint16: - fn.fe = (*encoderBincBytes).kUint16 - case reflect.Uint32: - fn.fe = (*encoderBincBytes).kUint32 - case reflect.Uint64: - fn.fe = (*encoderBincBytes).kUint64 - case reflect.Uintptr: - fn.fe = (*encoderBincBytes).kUintptr - case reflect.Float32: - fn.fe = (*encoderBincBytes).kFloat32 - case reflect.Float64: - fn.fe = (*encoderBincBytes).kFloat64 - case reflect.Complex64: - fn.fe = (*encoderBincBytes).kComplex64 - case reflect.Complex128: - fn.fe = (*encoderBincBytes).kComplex128 - case reflect.Chan: - fn.fe = (*encoderBincBytes).kChan - case reflect.Slice: - fn.fe = (*encoderBincBytes).kSlice - case reflect.Array: - fn.fe = (*encoderBincBytes).kArray - case reflect.Struct: - if ti.simple { - fn.fe = (*encoderBincBytes).kStructSimple - } else { - fn.fe = (*encoderBincBytes).kStruct - } - case reflect.Map: - fn.fe = (*encoderBincBytes).kMap - case reflect.Interface: - - fn.fe = (*encoderBincBytes).kErr - default: - - fn.fe = (*encoderBincBytes).kErr - } - } - } - return -} -func (d *decoderBincBytes) rawExt(f *decFnInfo, rv reflect.Value) { - d.d.DecodeRawExt(rv2i(rv).(*RawExt)) -} - -func (d *decoderBincBytes) ext(f *decFnInfo, rv reflect.Value) { - d.d.DecodeExt(rv2i(rv), f.ti.rt, f.xfTag, f.xfFn) -} - -func (d *decoderBincBytes) selferUnmarshal(_ *decFnInfo, rv reflect.Value) { - rv2i(rv).(Selfer).CodecDecodeSelf(&Decoder{d}) -} - -func (d *decoderBincBytes) binaryUnmarshal(_ *decFnInfo, rv reflect.Value) { - bm := rv2i(rv).(encoding.BinaryUnmarshaler) - xbs, _ := d.d.DecodeBytes() - fnerr := bm.UnmarshalBinary(xbs) - halt.onerror(fnerr) -} - -func (d *decoderBincBytes) textUnmarshal(_ *decFnInfo, rv reflect.Value) { - tm := rv2i(rv).(encoding.TextUnmarshaler) - fnerr := tm.UnmarshalText(bytesOKs(d.d.DecodeStringAsBytes())) - halt.onerror(fnerr) -} - -func (d *decoderBincBytes) jsonUnmarshal(_ *decFnInfo, rv reflect.Value) { - d.jsonUnmarshalV(rv2i(rv).(jsonUnmarshaler)) -} - -func (d *decoderBincBytes) jsonUnmarshalV(tm jsonUnmarshaler) { - - halt.onerror(tm.UnmarshalJSON(d.d.nextValueBytes())) -} - -func (d *decoderBincBytes) kErr(_ *decFnInfo, rv reflect.Value) { - halt.errorf("unsupported decoding kind: %s, for %#v", rv.Kind(), rv) - -} - -func (d *decoderBincBytes) raw(_ *decFnInfo, rv reflect.Value) { - rvSetBytes(rv, d.rawBytes()) -} - -func (d *decoderBincBytes) kString(_ *decFnInfo, rv reflect.Value) { - rvSetString(rv, d.detach2Str(d.d.DecodeStringAsBytes())) -} - -func (d *decoderBincBytes) kBool(_ *decFnInfo, rv reflect.Value) { - rvSetBool(rv, d.d.DecodeBool()) -} - -func (d *decoderBincBytes) kTime(_ *decFnInfo, rv reflect.Value) { - rvSetTime(rv, d.d.DecodeTime()) -} - -func (d *decoderBincBytes) kFloat32(_ *decFnInfo, rv reflect.Value) { - rvSetFloat32(rv, d.d.DecodeFloat32()) -} - -func (d *decoderBincBytes) kFloat64(_ *decFnInfo, rv reflect.Value) { - rvSetFloat64(rv, d.d.DecodeFloat64()) -} - -func (d *decoderBincBytes) kComplex64(_ *decFnInfo, rv reflect.Value) { - rvSetComplex64(rv, complex(d.d.DecodeFloat32(), 0)) -} - -func (d *decoderBincBytes) kComplex128(_ *decFnInfo, rv reflect.Value) { - rvSetComplex128(rv, complex(d.d.DecodeFloat64(), 0)) -} - -func (d *decoderBincBytes) kInt(_ *decFnInfo, rv reflect.Value) { - rvSetInt(rv, int(chkOvf.IntV(d.d.DecodeInt64(), intBitsize))) -} - -func (d *decoderBincBytes) kInt8(_ *decFnInfo, rv reflect.Value) { - rvSetInt8(rv, int8(chkOvf.IntV(d.d.DecodeInt64(), 8))) -} - -func (d *decoderBincBytes) kInt16(_ *decFnInfo, rv reflect.Value) { - rvSetInt16(rv, int16(chkOvf.IntV(d.d.DecodeInt64(), 16))) -} - -func (d *decoderBincBytes) kInt32(_ *decFnInfo, rv reflect.Value) { - rvSetInt32(rv, int32(chkOvf.IntV(d.d.DecodeInt64(), 32))) -} - -func (d *decoderBincBytes) kInt64(_ *decFnInfo, rv reflect.Value) { - rvSetInt64(rv, d.d.DecodeInt64()) -} - -func (d *decoderBincBytes) kUint(_ *decFnInfo, rv reflect.Value) { - rvSetUint(rv, uint(chkOvf.UintV(d.d.DecodeUint64(), uintBitsize))) -} - -func (d *decoderBincBytes) kUintptr(_ *decFnInfo, rv reflect.Value) { - rvSetUintptr(rv, uintptr(chkOvf.UintV(d.d.DecodeUint64(), uintBitsize))) -} - -func (d *decoderBincBytes) kUint8(_ *decFnInfo, rv reflect.Value) { - rvSetUint8(rv, uint8(chkOvf.UintV(d.d.DecodeUint64(), 8))) -} - -func (d *decoderBincBytes) kUint16(_ *decFnInfo, rv reflect.Value) { - rvSetUint16(rv, uint16(chkOvf.UintV(d.d.DecodeUint64(), 16))) -} - -func (d *decoderBincBytes) kUint32(_ *decFnInfo, rv reflect.Value) { - rvSetUint32(rv, uint32(chkOvf.UintV(d.d.DecodeUint64(), 32))) -} - -func (d *decoderBincBytes) kUint64(_ *decFnInfo, rv reflect.Value) { - rvSetUint64(rv, d.d.DecodeUint64()) -} - -func (d *decoderBincBytes) kInterfaceNaked(f *decFnInfo) (rvn reflect.Value) { - - n := d.naked() - d.d.DecodeNaked() - - if decFailNonEmptyIntf && f.ti.numMeth > 0 { - halt.errorf("cannot decode non-nil codec value into nil %v (%v methods)", f.ti.rt, f.ti.numMeth) - } - - switch n.v { - case valueTypeMap: - mtid := d.mtid - if mtid == 0 { - if d.jsms { - mtid = mapStrIntfTypId - } else { - mtid = mapIntfIntfTypId - } - } - if mtid == mapStrIntfTypId { - var v2 map[string]interface{} - d.decode(&v2) - rvn = rv4iptr(&v2).Elem() - } else if mtid == mapIntfIntfTypId { - var v2 map[interface{}]interface{} - d.decode(&v2) - rvn = rv4iptr(&v2).Elem() - } else if d.mtr { - rvn = reflect.New(d.h.MapType) - d.decode(rv2i(rvn)) - rvn = rvn.Elem() - } else { - - rvn = rvZeroAddrK(d.h.MapType, reflect.Map) - d.decodeValue(rvn, nil) - } - case valueTypeArray: - if d.stid == 0 || d.stid == intfSliceTypId { - var v2 []interface{} - d.decode(&v2) - rvn = rv4iptr(&v2).Elem() - } else if d.str { - rvn = reflect.New(d.h.SliceType) - d.decode(rv2i(rvn)) - rvn = rvn.Elem() - } else { - rvn = rvZeroAddrK(d.h.SliceType, reflect.Slice) - d.decodeValue(rvn, nil) - } - if d.h.PreferArrayOverSlice { - rvn = rvGetArray4Slice(rvn) - } - case valueTypeExt: - tag, bytes := n.u, n.l - bfn := d.h.getExtForTag(tag) - var re = RawExt{Tag: tag} - if bytes == nil { - - if bfn == nil { - d.decode(&re.Value) - rvn = rv4iptr(&re).Elem() - } else if bfn.ext == SelfExt { - rvn = rvZeroAddrK(bfn.rt, bfn.rt.Kind()) - d.decodeValue(rvn, d.fnNoExt(bfn.rt)) - } else { - rvn = reflect.New(bfn.rt) - d.interfaceExtConvertAndDecode(rv2i(rvn), bfn.ext) - rvn = rvn.Elem() - } - } else { - - if bfn == nil { - re.setData(bytes, false) - rvn = rv4iptr(&re).Elem() - } else { - rvn = reflect.New(bfn.rt) - if bfn.ext == SelfExt { - sideDecode(d.hh, &d.h.sideDecPool, func(sd decoderI) { oneOffDecode(sd, rv2i(rvn), bytes, bfn.rt, true) }) - } else { - bfn.ext.ReadExt(rv2i(rvn), bytes) - } - rvn = rvn.Elem() - } - } - - if d.h.PreferPointerForStructOrArray && rvn.CanAddr() { - if rk := rvn.Kind(); rk == reflect.Array || rk == reflect.Struct { - rvn = rvn.Addr() - } - } - case valueTypeNil: - - case valueTypeInt: - rvn = n.ri() - case valueTypeUint: - rvn = n.ru() - case valueTypeFloat: - rvn = n.rf() - case valueTypeBool: - rvn = n.rb() - case valueTypeString, valueTypeSymbol: - rvn = n.rs() - case valueTypeBytes: - rvn = n.rl() - case valueTypeTime: - rvn = n.rt() - default: - halt.errorStr2("kInterfaceNaked: unexpected valueType: ", n.v.String()) - } - return -} - -func (d *decoderBincBytes) kInterface(f *decFnInfo, rv reflect.Value) { - - isnilrv := rvIsNil(rv) - - var rvn reflect.Value - - if d.h.InterfaceReset { - - rvn = d.h.intf2impl(f.ti.rtid) - if !rvn.IsValid() { - rvn = d.kInterfaceNaked(f) - if rvn.IsValid() { - rvSetIntf(rv, rvn) - } else if !isnilrv { - decSetNonNilRV2Zero4Intf(rv) - } - return - } - } else if isnilrv { - - rvn = d.h.intf2impl(f.ti.rtid) - if !rvn.IsValid() { - rvn = d.kInterfaceNaked(f) - if rvn.IsValid() { - rvSetIntf(rv, rvn) - } - return - } - } else { - - rvn = rv.Elem() - } - - canDecode, _ := isDecodeable(rvn) - - if !canDecode { - rvn2 := d.oneShotAddrRV(rvn.Type(), rvn.Kind()) - rvSetDirect(rvn2, rvn) - rvn = rvn2 - } - - d.decodeValue(rvn, nil) - rvSetIntf(rv, rvn) -} - -func (d *decoderBincBytes) kStructField(si *structFieldInfo, rv reflect.Value) { - if d.d.TryNil() { - rv = si.fieldNoAlloc(rv, true) - if rv.IsValid() { - decSetNonNilRV2Zero(rv) - } - } else if si.decBuiltin { - rv = rvAddr(si.fieldAlloc(rv), si.ptrTyp) - d.decode(rv2i(rv)) - } else { - fn := d.fn(si.baseTyp) - rv = si.fieldAlloc(rv) - if fn.i.addrD { - rv = rvAddr(rv, si.ptrTyp) - } - fn.fd(d, &fn.i, rv) - } -} - -func (d *decoderBincBytes) kStructSimple(f *decFnInfo, rv reflect.Value) { - _ = d.d - ctyp := d.d.ContainerType() - ti := f.ti - if ctyp == valueTypeMap { - containerLen := d.mapStart(d.d.ReadMapStart()) - if containerLen == 0 { - d.mapEnd() - return - } - hasLen := containerLen >= 0 - var rvkencname []byte - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - sab, att := d.d.DecodeStringAsBytes() - rvkencname = d.usableStructFieldNameBytes(rvkencname, sab, att) - d.mapElemValue() - if si := ti.siForEncName(rvkencname); si != nil { - d.kStructField(si, rv) - } else { - d.structFieldNotFound(-1, stringView(rvkencname)) - } - } - d.mapEnd() - } else if ctyp == valueTypeArray { - containerLen := d.arrayStart(d.d.ReadArrayStart()) - if containerLen == 0 { - d.arrayEnd() - return - } - - tisfi := ti.sfi.source() - hasLen := containerLen >= 0 - - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.arrayElem(j == 0) - if j < len(tisfi) { - d.kStructField(tisfi[j], rv) - } else { - d.structFieldNotFound(j, "") - } - } - d.arrayEnd() - } else { - halt.onerror(errNeedMapOrArrayDecodeToStruct) - } -} - -func (d *decoderBincBytes) kStruct(f *decFnInfo, rv reflect.Value) { - _ = d.d - ctyp := d.d.ContainerType() - ti := f.ti - var mf MissingFielder - if ti.flagMissingFielder { - mf = rv2i(rv).(MissingFielder) - } else if ti.flagMissingFielderPtr { - mf = rv2i(rvAddr(rv, ti.ptr)).(MissingFielder) - } - if ctyp == valueTypeMap { - containerLen := d.mapStart(d.d.ReadMapStart()) - if containerLen == 0 { - d.mapEnd() - return - } - hasLen := containerLen >= 0 - var name2 []byte - var rvkencname []byte - tkt := ti.keyType - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - - if tkt == valueTypeString { - sab, att := d.d.DecodeStringAsBytes() - rvkencname = d.usableStructFieldNameBytes(rvkencname, sab, att) - } else if tkt == valueTypeInt { - rvkencname = strconv.AppendInt(d.b[:0], d.d.DecodeInt64(), 10) - } else if tkt == valueTypeUint { - rvkencname = strconv.AppendUint(d.b[:0], d.d.DecodeUint64(), 10) - } else if tkt == valueTypeFloat { - rvkencname = strconv.AppendFloat(d.b[:0], d.d.DecodeFloat64(), 'f', -1, 64) - } else { - halt.errorStr2("invalid struct key type: ", ti.keyType.String()) - } - - d.mapElemValue() - if si := ti.siForEncName(rvkencname); si != nil { - d.kStructField(si, rv) - } else if mf != nil { - - name2 = append(name2[:0], rvkencname...) - var f interface{} - d.decode(&f) - if !mf.CodecMissingField(name2, f) && d.h.ErrorIfNoField { - halt.errorStr2("no matching struct field when decoding stream map with key: ", stringView(name2)) - } - } else { - d.structFieldNotFound(-1, stringView(rvkencname)) - } - } - d.mapEnd() - } else if ctyp == valueTypeArray { - containerLen := d.arrayStart(d.d.ReadArrayStart()) - if containerLen == 0 { - d.arrayEnd() - return - } - - tisfi := ti.sfi.source() - hasLen := containerLen >= 0 - - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.arrayElem(j == 0) - if j < len(tisfi) { - d.kStructField(tisfi[j], rv) - } else { - d.structFieldNotFound(j, "") - } - } - - d.arrayEnd() - } else { - halt.onerror(errNeedMapOrArrayDecodeToStruct) - } -} - -func (d *decoderBincBytes) kSlice(f *decFnInfo, rv reflect.Value) { - _ = d.d - - ti := f.ti - rvCanset := rv.CanSet() - - ctyp := d.d.ContainerType() - if ctyp == valueTypeBytes || ctyp == valueTypeString { - - if !(ti.rtid == uint8SliceTypId || ti.elemkind == uint8(reflect.Uint8)) { - halt.errorf("bytes/string in stream must decode into slice/array of bytes, not %v", ti.rt) - } - rvbs := rvGetBytes(rv) - if rvCanset { - bs2, bst := d.decodeBytesInto(rvbs, false) - if bst != dBytesIntoParamOut { - rvSetBytes(rv, bs2) - } - } else { - - d.decodeBytesInto(rvbs[:len(rvbs):len(rvbs)], true) - } - return - } - - var containerLenS int - isArray := ctyp == valueTypeArray - if isArray { - containerLenS = d.arrayStart(d.d.ReadArrayStart()) - } else if ctyp == valueTypeMap { - containerLenS = d.mapStart(d.d.ReadMapStart()) * 2 - } else { - halt.errorStr2("decoding into a slice, expect map/array - got ", ctyp.String()) - } - - if containerLenS == 0 { - if rvCanset { - if rvIsNil(rv) { - rvSetDirect(rv, rvSliceZeroCap(ti.rt)) - } else { - rvSetSliceLen(rv, 0) - } - } - if isArray { - d.arrayEnd() - } else { - d.mapEnd() - } - return - } - - rtelem0Mut := !scalarBitset.isset(ti.elemkind) - rtelem := ti.elem - - for k := reflect.Kind(ti.elemkind); k == reflect.Ptr; k = rtelem.Kind() { - rtelem = rtelem.Elem() - } - - var fn *decFnBincBytes - - var rvChanged bool - - var rv0 = rv - var rv9 reflect.Value - - rvlen := rvLenSlice(rv) - rvcap := rvCapSlice(rv) - maxInitLen := d.maxInitLen() - hasLen := containerLenS >= 0 - if hasLen { - if containerLenS > rvcap { - oldRvlenGtZero := rvlen > 0 - rvlen1 := int(decInferLen(containerLenS, maxInitLen, uint(ti.elemsize))) - if rvlen1 == rvlen { - } else if rvlen1 <= rvcap { - if rvCanset { - rvlen = rvlen1 - rvSetSliceLen(rv, rvlen) - } - } else if rvCanset { - rvlen = rvlen1 - rv, rvCanset = rvMakeSlice(rv, f.ti, rvlen, rvlen) - rvcap = rvlen - rvChanged = !rvCanset - } else { - halt.errorStr("cannot decode into non-settable slice") - } - if rvChanged && oldRvlenGtZero && rtelem0Mut { - rvCopySlice(rv, rv0, rtelem) - } - } else if containerLenS != rvlen { - if rvCanset { - rvlen = containerLenS - rvSetSliceLen(rv, rvlen) - } - } - } - - var elemReset = d.h.SliceElementReset - - var rtelemIsPtr bool - var rtelemElem reflect.Type - builtin := ti.tielem.flagDecBuiltin - if builtin { - rtelemIsPtr = ti.elemkind == uint8(reflect.Ptr) - if rtelemIsPtr { - rtelemElem = ti.elem.Elem() - } - } - - var j int - for ; d.containerNext(j, containerLenS, hasLen); j++ { - if j == 0 { - if rvIsNil(rv) { - if rvCanset { - rvlen = int(decInferLen(containerLenS, maxInitLen, uint(ti.elemsize))) - rv, rvCanset = rvMakeSlice(rv, f.ti, rvlen, rvlen) - rvcap = rvlen - rvChanged = !rvCanset - } else { - halt.errorStr("cannot decode into non-settable slice") - } - } - if fn == nil { - fn = d.fn(rtelem) - } - } - - if ctyp == valueTypeArray { - d.arrayElem(j == 0) - } else if j&1 == 0 { - d.mapElemKey(j == 0) - } else { - d.mapElemValue() - } - - if j >= rvlen { - - if rvlen < rvcap { - rvlen = rvcap - if rvCanset { - rvSetSliceLen(rv, rvlen) - } else if rvChanged { - rv = rvSlice(rv, rvlen) - } else { - halt.onerror(errExpandSliceCannotChange) - } - } else { - if !(rvCanset || rvChanged) { - halt.onerror(errExpandSliceCannotChange) - } - rv, rvcap, rvCanset = rvGrowSlice(rv, f.ti, rvcap, 1) - - rvlen = rvcap - rvChanged = !rvCanset - } - } - - rv9 = rvArrayIndex(rv, j, f.ti, true) - if elemReset { - rvSetZero(rv9) - } - if d.d.TryNil() { - rvSetZero(rv9) - } else if builtin { - if rtelemIsPtr { - if rvIsNil(rv9) { - rvSetDirect(rv9, reflect.New(rtelemElem)) - } - d.decode(rv2i(rv9)) - } else { - d.decode(rv2i(rvAddr(rv9, ti.tielem.ptr))) - } - } else { - d.decodeValueNoCheckNil(rv9, fn) - } - } - if j < rvlen { - if rvCanset { - rvSetSliceLen(rv, j) - } else if rvChanged { - rv = rvSlice(rv, j) - } - - } else if j == 0 && rvIsNil(rv) { - if rvCanset { - rv = rvSliceZeroCap(ti.rt) - rvCanset = false - rvChanged = true - } - } - if isArray { - d.arrayEnd() - } else { - d.mapEnd() - } - - if rvChanged { - rvSetDirect(rv0, rv) - } -} - -func (d *decoderBincBytes) kArray(f *decFnInfo, rv reflect.Value) { - _ = d.d - - ti := f.ti - ctyp := d.d.ContainerType() - if handleBytesWithinKArray && (ctyp == valueTypeBytes || ctyp == valueTypeString) { - - if ti.elemkind != uint8(reflect.Uint8) { - halt.errorf("bytes/string in stream can decode into array of bytes, but not %v", ti.rt) - } - rvbs := rvGetArrayBytes(rv, nil) - d.decodeBytesInto(rvbs, true) - return - } - - var containerLenS int - isArray := ctyp == valueTypeArray - if isArray { - containerLenS = d.arrayStart(d.d.ReadArrayStart()) - } else if ctyp == valueTypeMap { - containerLenS = d.mapStart(d.d.ReadMapStart()) * 2 - } else { - halt.errorStr2("decoding into a slice, expect map/array - got ", ctyp.String()) - } - - if containerLenS == 0 { - if isArray { - d.arrayEnd() - } else { - d.mapEnd() - } - return - } - - rtelem := ti.elem - for k := reflect.Kind(ti.elemkind); k == reflect.Ptr; k = rtelem.Kind() { - rtelem = rtelem.Elem() - } - - var rv9 reflect.Value - - rvlen := rv.Len() - hasLen := containerLenS >= 0 - if hasLen && containerLenS > rvlen { - halt.errorf("cannot decode into array with length: %v, less than container length: %v", any(rvlen), any(containerLenS)) - } - - var elemReset = d.h.SliceElementReset - - var rtelemIsPtr bool - var rtelemElem reflect.Type - var fn *decFnBincBytes - builtin := ti.tielem.flagDecBuiltin - if builtin { - rtelemIsPtr = ti.elemkind == uint8(reflect.Ptr) - if rtelemIsPtr { - rtelemElem = ti.elem.Elem() - } - } else { - fn = d.fn(rtelem) - } - - for j := 0; d.containerNext(j, containerLenS, hasLen); j++ { - if ctyp == valueTypeArray { - d.arrayElem(j == 0) - } else if j&1 == 0 { - d.mapElemKey(j == 0) - } else { - d.mapElemValue() - } - - if j >= rvlen { - d.arrayCannotExpand(rvlen, j+1) - d.swallow() - continue - } - - rv9 = rvArrayIndex(rv, j, f.ti, false) - if elemReset { - rvSetZero(rv9) - } - if d.d.TryNil() { - rvSetZero(rv9) - } else if builtin { - if rtelemIsPtr { - if rvIsNil(rv9) { - rvSetDirect(rv9, reflect.New(rtelemElem)) - } - d.decode(rv2i(rv9)) - } else { - d.decode(rv2i(rvAddr(rv9, ti.tielem.ptr))) - } - } else { - d.decodeValueNoCheckNil(rv9, fn) - } - } - if isArray { - d.arrayEnd() - } else { - d.mapEnd() - } -} - -func (d *decoderBincBytes) kChan(f *decFnInfo, rv reflect.Value) { - _ = d.d - - ti := f.ti - if ti.chandir&uint8(reflect.SendDir) == 0 { - halt.errorStr("receive-only channel cannot be decoded") - } - ctyp := d.d.ContainerType() - if ctyp == valueTypeBytes || ctyp == valueTypeString { - - if !(ti.rtid == uint8SliceTypId || ti.elemkind == uint8(reflect.Uint8)) { - halt.errorf("bytes/string in stream must decode into slice/array of bytes, not %v", ti.rt) - } - bs2, _ := d.d.DecodeBytes() - irv := rv2i(rv) - ch, ok := irv.(chan<- byte) - if !ok { - ch = irv.(chan byte) - } - for _, b := range bs2 { - ch <- b - } - return - } - - var rvCanset = rv.CanSet() - - var containerLenS int - isArray := ctyp == valueTypeArray - if isArray { - containerLenS = d.arrayStart(d.d.ReadArrayStart()) - } else if ctyp == valueTypeMap { - containerLenS = d.mapStart(d.d.ReadMapStart()) * 2 - } else { - halt.errorStr2("decoding into a slice, expect map/array - got ", ctyp.String()) - } - - if containerLenS == 0 { - if rvCanset && rvIsNil(rv) { - rvSetDirect(rv, reflect.MakeChan(ti.rt, 0)) - } - if isArray { - d.arrayEnd() - } else { - d.mapEnd() - } - return - } - - rtelem := ti.elem - useTransient := decUseTransient && ti.elemkind != byte(reflect.Ptr) && ti.tielem.flagCanTransient - - for k := reflect.Kind(ti.elemkind); k == reflect.Ptr; k = rtelem.Kind() { - rtelem = rtelem.Elem() - } - - var fn *decFnBincBytes - - var rvChanged bool - var rv0 = rv - var rv9 reflect.Value - - var rvlen int - hasLen := containerLenS >= 0 - maxInitLen := d.maxInitLen() - - for j := 0; d.containerNext(j, containerLenS, hasLen); j++ { - if j == 0 { - if rvIsNil(rv) { - if hasLen { - rvlen = int(decInferLen(containerLenS, maxInitLen, uint(ti.elemsize))) - } else { - rvlen = decDefChanCap - } - if rvCanset { - rv = reflect.MakeChan(ti.rt, rvlen) - rvChanged = true - } else { - halt.errorStr("cannot decode into non-settable chan") - } - } - if fn == nil { - fn = d.fn(rtelem) - } - } - - if ctyp == valueTypeArray { - d.arrayElem(j == 0) - } else if j&1 == 0 { - d.mapElemKey(j == 0) - } else { - d.mapElemValue() - } - - if rv9.IsValid() { - rvSetZero(rv9) - } else if useTransient { - rv9 = d.perType.TransientAddrK(ti.elem, reflect.Kind(ti.elemkind)) - } else { - rv9 = rvZeroAddrK(ti.elem, reflect.Kind(ti.elemkind)) - } - if !d.d.TryNil() { - d.decodeValueNoCheckNil(rv9, fn) - } - rv.Send(rv9) - } - if isArray { - d.arrayEnd() - } else { - d.mapEnd() - } - - if rvChanged { - rvSetDirect(rv0, rv) - } - -} - -func (d *decoderBincBytes) kMap(f *decFnInfo, rv reflect.Value) { - _ = d.d - containerLen := d.mapStart(d.d.ReadMapStart()) - ti := f.ti - if rvIsNil(rv) { - rvlen := int(decInferLen(containerLen, d.maxInitLen(), uint(ti.keysize+ti.elemsize))) - rvSetDirect(rv, makeMapReflect(ti.rt, rvlen)) - } - - if containerLen == 0 { - d.mapEnd() - return - } - - ktype, vtype := ti.key, ti.elem - ktypeId := rt2id(ktype) - vtypeKind := reflect.Kind(ti.elemkind) - ktypeKind := reflect.Kind(ti.keykind) - mparams := getMapReqParams(ti) - - vtypePtr := vtypeKind == reflect.Ptr - ktypePtr := ktypeKind == reflect.Ptr - - vTransient := decUseTransient && !vtypePtr && ti.tielem.flagCanTransient - - kTransient := vTransient && !ktypePtr && ti.tikey.flagCanTransient - - var vtypeElem reflect.Type - - var keyFn, valFn *decFnBincBytes - var ktypeLo, vtypeLo = ktype, vtype - - if ktypeKind == reflect.Ptr { - for ktypeLo = ktype.Elem(); ktypeLo.Kind() == reflect.Ptr; ktypeLo = ktypeLo.Elem() { - } - } - - if vtypePtr { - vtypeElem = vtype.Elem() - for vtypeLo = vtypeElem; vtypeLo.Kind() == reflect.Ptr; vtypeLo = vtypeLo.Elem() { - } - } - - rvkMut := !scalarBitset.isset(ti.keykind) - rvvMut := !scalarBitset.isset(ti.elemkind) - rvvCanNil := isnilBitset.isset(ti.elemkind) - - var rvk, rvkn, rvv, rvvn, rvva, rvvz reflect.Value - - var doMapGet, doMapSet bool - - if !d.h.MapValueReset { - if rvvMut && (vtypeKind != reflect.Interface || !d.h.InterfaceReset) { - doMapGet = true - rvva = mapAddrLoopvarRV(vtype, vtypeKind) - } - } - - ktypeIsString := ktypeId == stringTypId - ktypeIsIntf := ktypeId == intfTypId - hasLen := containerLen >= 0 - - var kstr2bs []byte - var kstr string - - var mapKeyStringSharesBytesBuf bool - var att dBytesAttachState - - var vElem, kElem reflect.Type - kbuiltin := ti.tikey.flagDecBuiltin && ti.keykind != uint8(reflect.Slice) - vbuiltin := ti.tielem.flagDecBuiltin - if kbuiltin && ktypePtr { - kElem = ti.key.Elem() - } - if vbuiltin && vtypePtr { - vElem = ti.elem.Elem() - } - - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - mapKeyStringSharesBytesBuf = false - kstr = "" - if j == 0 { - - if kTransient { - rvk = d.perType.TransientAddr2K(ktype, ktypeKind) - } else { - rvk = rvZeroAddrK(ktype, ktypeKind) - } - if !rvkMut { - rvkn = rvk - } - if !rvvMut { - if vTransient { - rvvn = d.perType.TransientAddrK(vtype, vtypeKind) - } else { - rvvn = rvZeroAddrK(vtype, vtypeKind) - } - } - if !ktypeIsString && keyFn == nil { - keyFn = d.fn(ktypeLo) - } - if valFn == nil { - valFn = d.fn(vtypeLo) - } - } else if rvkMut { - rvSetZero(rvk) - } else { - rvk = rvkn - } - - d.mapElemKey(j == 0) - - if d.d.TryNil() { - rvSetZero(rvk) - } else if ktypeIsString { - kstr2bs, att = d.d.DecodeStringAsBytes() - kstr, mapKeyStringSharesBytesBuf = d.bytes2Str(kstr2bs, att) - rvSetString(rvk, kstr) - } else { - if kbuiltin { - if ktypePtr { - if rvIsNil(rvk) { - rvSetDirect(rvk, reflect.New(kElem)) - } - d.decode(rv2i(rvk)) - } else { - d.decode(rv2i(rvAddr(rvk, ti.tikey.ptr))) - } - } else { - d.decodeValueNoCheckNil(rvk, keyFn) - } - - if ktypeIsIntf { - if rvk2 := rvk.Elem(); rvk2.IsValid() && rvk2.Type() == uint8SliceTyp { - kstr2bs = rvGetBytes(rvk2) - kstr, mapKeyStringSharesBytesBuf = d.bytes2Str(kstr2bs, dBytesAttachView) - rvSetIntf(rvk, rv4istr(kstr)) - } - - } - } - - if mapKeyStringSharesBytesBuf && d.bufio { - if ktypeIsString { - rvSetString(rvk, d.detach2Str(kstr2bs, att)) - } else { - rvSetIntf(rvk, rv4istr(d.detach2Str(kstr2bs, att))) - } - mapKeyStringSharesBytesBuf = false - } - - d.mapElemValue() - - if d.d.TryNil() { - if mapKeyStringSharesBytesBuf { - if ktypeIsString { - rvSetString(rvk, d.detach2Str(kstr2bs, att)) - } else { - rvSetIntf(rvk, rv4istr(d.detach2Str(kstr2bs, att))) - } - } - - if !rvvz.IsValid() { - rvvz = rvZeroK(vtype, vtypeKind) - } - mapSet(rv, rvk, rvvz, mparams) - continue - } - - doMapSet = true - - if !rvvMut { - rvv = rvvn - } else if !doMapGet { - goto NEW_RVV - } else { - rvv = mapGet(rv, rvk, rvva, mparams) - if !rvv.IsValid() || (rvvCanNil && rvIsNil(rvv)) { - goto NEW_RVV - } - switch vtypeKind { - case reflect.Ptr, reflect.Map: - doMapSet = false - case reflect.Interface: - - rvvn = rvv.Elem() - if k := rvvn.Kind(); (k == reflect.Ptr || k == reflect.Map) && !rvIsNil(rvvn) { - d.decodeValueNoCheckNil(rvvn, nil) - continue - } - - rvvn = rvZeroAddrK(vtype, vtypeKind) - rvSetIntf(rvvn, rvv) - rvv = rvvn - default: - - if vTransient { - rvvn = d.perType.TransientAddrK(vtype, vtypeKind) - } else { - rvvn = rvZeroAddrK(vtype, vtypeKind) - } - rvSetDirect(rvvn, rvv) - rvv = rvvn - } - } - goto DECODE_VALUE_NO_CHECK_NIL - - NEW_RVV: - if vtypePtr { - rvv = reflect.New(vtypeElem) - } else if vTransient { - rvv = d.perType.TransientAddrK(vtype, vtypeKind) - } else { - rvv = rvZeroAddrK(vtype, vtypeKind) - } - - DECODE_VALUE_NO_CHECK_NIL: - if doMapSet && mapKeyStringSharesBytesBuf { - if ktypeIsString { - rvSetString(rvk, d.detach2Str(kstr2bs, att)) - } else { - rvSetIntf(rvk, rv4istr(d.detach2Str(kstr2bs, att))) - } - } - if vbuiltin { - if vtypePtr { - if rvIsNil(rvv) { - rvSetDirect(rvv, reflect.New(vElem)) - } - d.decode(rv2i(rvv)) - } else { - d.decode(rv2i(rvAddr(rvv, ti.tielem.ptr))) - } - } else { - d.decodeValueNoCheckNil(rvv, valFn) - } - if doMapSet { - mapSet(rv, rvk, rvv, mparams) - } - } - - d.mapEnd() -} - -func (d *decoderBincBytes) init(h Handle) { - initHandle(h) - callMake(&d.d) - d.hh = h - d.h = h.getBasicHandle() - - d.err = errDecoderNotInitialized - - if d.h.InternString && d.is == nil { - d.is.init() - } - - d.fp = d.d.init(h, &d.decoderBase, d).(*fastpathDsBincBytes) - - if d.bytes { - d.rtidFn = &d.h.rtidFnsDecBytes - d.rtidFnNoExt = &d.h.rtidFnsDecNoExtBytes - } else { - d.bufio = d.h.ReaderBufferSize > 0 - d.rtidFn = &d.h.rtidFnsDecIO - d.rtidFnNoExt = &d.h.rtidFnsDecNoExtIO - } - - d.reset() - -} - -func (d *decoderBincBytes) reset() { - d.d.reset() - d.err = nil - d.c = 0 - d.depth = 0 - d.calls = 0 - - d.maxdepth = decDefMaxDepth - if d.h.MaxDepth > 0 { - d.maxdepth = d.h.MaxDepth - } - d.mtid = 0 - d.stid = 0 - d.mtr = false - d.str = false - if d.h.MapType != nil { - d.mtid = rt2id(d.h.MapType) - _, d.mtr = fastpathAvIndex(d.mtid) - } - if d.h.SliceType != nil { - d.stid = rt2id(d.h.SliceType) - _, d.str = fastpathAvIndex(d.stid) - } -} - -func (d *decoderBincBytes) Reset(r io.Reader) { - if d.bytes { - halt.onerror(errDecNoResetBytesWithReader) - } - d.reset() - if r == nil { - r = &eofReader - } - d.d.resetInIO(r) -} - -func (d *decoderBincBytes) ResetBytes(in []byte) { - if !d.bytes { - halt.onerror(errDecNoResetReaderWithBytes) - } - d.resetBytes(in) -} - -func (d *decoderBincBytes) resetBytes(in []byte) { - d.reset() - if in == nil { - in = zeroByteSlice - } - d.d.resetInBytes(in) -} - -func (d *decoderBincBytes) ResetString(s string) { - d.ResetBytes(bytesView(s)) -} - -func (d *decoderBincBytes) Decode(v interface{}) (err error) { - - defer panicValToErr(d, callRecoverSentinel, &d.err, &err, debugging) - d.mustDecode(v) - return -} - -func (d *decoderBincBytes) MustDecode(v interface{}) { - defer panicValToErr(d, callRecoverSentinel, &d.err, nil, true) - d.mustDecode(v) - return -} - -func (d *decoderBincBytes) mustDecode(v interface{}) { - halt.onerror(d.err) - if d.hh == nil { - halt.onerror(errNoFormatHandle) - } - - d.calls++ - d.decode(v) - d.calls-- -} - -func (d *decoderBincBytes) Release() {} - -func (d *decoderBincBytes) swallow() { - d.d.nextValueBytes() -} - -func (d *decoderBincBytes) nextValueBytes() []byte { - return d.d.nextValueBytes() -} - -func (d *decoderBincBytes) decode(iv interface{}) { - _ = d.d - - rv, ok := isNil(iv, true) - if ok { - halt.onerror(errCannotDecodeIntoNil) - } - - switch v := iv.(type) { - - case *string: - *v = d.detach2Str(d.d.DecodeStringAsBytes()) - case *bool: - *v = d.d.DecodeBool() - case *int: - *v = int(chkOvf.IntV(d.d.DecodeInt64(), intBitsize)) - case *int8: - *v = int8(chkOvf.IntV(d.d.DecodeInt64(), 8)) - case *int16: - *v = int16(chkOvf.IntV(d.d.DecodeInt64(), 16)) - case *int32: - *v = int32(chkOvf.IntV(d.d.DecodeInt64(), 32)) - case *int64: - *v = d.d.DecodeInt64() - case *uint: - *v = uint(chkOvf.UintV(d.d.DecodeUint64(), uintBitsize)) - case *uint8: - *v = uint8(chkOvf.UintV(d.d.DecodeUint64(), 8)) - case *uint16: - *v = uint16(chkOvf.UintV(d.d.DecodeUint64(), 16)) - case *uint32: - *v = uint32(chkOvf.UintV(d.d.DecodeUint64(), 32)) - case *uint64: - *v = d.d.DecodeUint64() - case *uintptr: - *v = uintptr(chkOvf.UintV(d.d.DecodeUint64(), uintBitsize)) - case *float32: - *v = d.d.DecodeFloat32() - case *float64: - *v = d.d.DecodeFloat64() - case *complex64: - *v = complex(d.d.DecodeFloat32(), 0) - case *complex128: - *v = complex(d.d.DecodeFloat64(), 0) - case *[]byte: - *v, _ = d.decodeBytesInto(*v, false) - case []byte: - - d.decodeBytesInto(v[:len(v):len(v)], true) - case *time.Time: - *v = d.d.DecodeTime() - case *Raw: - *v = d.rawBytes() - - case *interface{}: - d.decodeValue(rv4iptr(v), nil) - - case reflect.Value: - if ok, _ = isDecodeable(v); !ok { - d.haltAsNotDecodeable(v) - } - d.decodeValue(v, nil) - - default: - - if skipFastpathTypeSwitchInDirectCall || !d.dh.fastpathDecodeTypeSwitch(iv, d) { - if !rv.IsValid() { - rv = reflect.ValueOf(iv) - } - if ok, _ = isDecodeable(rv); !ok { - d.haltAsNotDecodeable(rv) - } - d.decodeValue(rv, nil) - } - } -} - -func (d *decoderBincBytes) decodeValue(rv reflect.Value, fn *decFnBincBytes) { - if d.d.TryNil() { - decSetNonNilRV2Zero(rv) - } else { - d.decodeValueNoCheckNil(rv, fn) - } -} - -func (d *decoderBincBytes) decodeValueNoCheckNil(rv reflect.Value, fn *decFnBincBytes) { - - var rvp reflect.Value - var rvpValid bool -PTR: - if rv.Kind() == reflect.Ptr { - rvpValid = true - if rvIsNil(rv) { - rvSetDirect(rv, reflect.New(rv.Type().Elem())) - } - rvp = rv - rv = rv.Elem() - goto PTR - } - - if fn == nil { - fn = d.fn(rv.Type()) - } - if fn.i.addrD { - if rvpValid { - rv = rvp - } else if rv.CanAddr() { - rv = rvAddr(rv, fn.i.ti.ptr) - } else if fn.i.addrDf { - halt.errorStr("cannot decode into a non-pointer value") - } - } - fn.fd(d, &fn.i, rv) -} - -func (d *decoderBincBytes) decodeAs(v interface{}, t reflect.Type, ext bool) { - if ext { - d.decodeValue(baseRV(v), d.fn(t)) - } else { - d.decodeValue(baseRV(v), d.fnNoExt(t)) - } -} - -func (d *decoderBincBytes) structFieldNotFound(index int, rvkencname string) { - - if d.h.ErrorIfNoField { - if index >= 0 { - halt.errorInt("no matching struct field found when decoding stream array at index ", int64(index)) - } else if rvkencname != "" { - halt.errorStr2("no matching struct field found when decoding stream map with key ", rvkencname) - } - } - d.swallow() -} - -func (d *decoderBincBytes) decodeBytesInto(out []byte, mustFit bool) (v []byte, state dBytesIntoState) { - v, att := d.d.DecodeBytes() - if cap(v) == 0 || (att >= dBytesAttachViewZerocopy && !mustFit) { - - return - } - if len(v) == 0 { - v = zeroByteSlice - return - } - if len(out) == len(v) { - state = dBytesIntoParamOut - } else if cap(out) >= len(v) { - out = out[:len(v)] - state = dBytesIntoParamOutSlice - } else if mustFit { - halt.errorf("bytes capacity insufficient for decoded bytes: got/expected: %d/%d", len(v), len(out)) - } else { - out = make([]byte, len(v)) - state = dBytesIntoNew - } - copy(out, v) - v = out - return -} - -func (d *decoderBincBytes) rawBytes() (v []byte) { - - v = d.d.nextValueBytes() - if d.bytes && !d.h.ZeroCopy { - vv := make([]byte, len(v)) - copy(vv, v) - v = vv - } - return -} - -func (d *decoderBincBytes) wrapErr(v error, err *error) { - *err = wrapCodecErr(v, d.hh.Name(), d.d.NumBytesRead(), false) -} - -func (d *decoderBincBytes) NumBytesRead() int { - return d.d.NumBytesRead() -} - -func (d *decoderBincBytes) containerNext(j, containerLen int, hasLen bool) bool { - - if hasLen { - return j < containerLen - } - return !d.d.CheckBreak() -} - -func (d *decoderBincBytes) mapElemKey(firstTime bool) { - d.d.ReadMapElemKey(firstTime) - d.c = containerMapKey -} - -func (d *decoderBincBytes) mapElemValue() { - d.d.ReadMapElemValue() - d.c = containerMapValue -} - -func (d *decoderBincBytes) mapEnd() { - d.d.ReadMapEnd() - d.depthDecr() - d.c = 0 -} - -func (d *decoderBincBytes) arrayElem(firstTime bool) { - d.d.ReadArrayElem(firstTime) - d.c = containerArrayElem -} - -func (d *decoderBincBytes) arrayEnd() { - d.d.ReadArrayEnd() - d.depthDecr() - d.c = 0 -} - -func (d *decoderBincBytes) interfaceExtConvertAndDecode(v interface{}, ext InterfaceExt) { - - var vv interface{} - d.decode(&vv) - ext.UpdateExt(v, vv) - -} - -func (d *decoderBincBytes) fn(t reflect.Type) *decFnBincBytes { - return d.dh.decFnViaBH(t, d.rtidFn, d.h, d.fp, false) -} - -func (d *decoderBincBytes) fnNoExt(t reflect.Type) *decFnBincBytes { - return d.dh.decFnViaBH(t, d.rtidFnNoExt, d.h, d.fp, true) -} - -func (helperDecDriverBincBytes) newDecoderBytes(in []byte, h Handle) *decoderBincBytes { - var c1 decoderBincBytes - c1.bytes = true - c1.init(h) - c1.ResetBytes(in) - return &c1 -} - -func (helperDecDriverBincBytes) newDecoderIO(in io.Reader, h Handle) *decoderBincBytes { - var c1 decoderBincBytes - c1.init(h) - c1.Reset(in) - return &c1 -} - -func (helperDecDriverBincBytes) decFnloadFastpathUnderlying(ti *typeInfo, fp *fastpathDsBincBytes) (f *fastpathDBincBytes, u reflect.Type) { - rtid := rt2id(ti.fastpathUnderlying) - idx, ok := fastpathAvIndex(rtid) - if !ok { - return - } - f = &fp[idx] - if uint8(reflect.Array) == ti.kind { - u = reflect.ArrayOf(ti.rt.Len(), ti.elem) - } else { - u = f.rt - } - return -} - -func (helperDecDriverBincBytes) decFindRtidFn(s []decRtidFnBincBytes, rtid uintptr) (i uint, fn *decFnBincBytes) { - - var h uint - var j = uint(len(s)) -LOOP: - if i < j { - h = (i + j) >> 1 - if s[h].rtid < rtid { - i = h + 1 - } else { - j = h - } - goto LOOP - } - if i < uint(len(s)) && s[i].rtid == rtid { - fn = s[i].fn - } - return -} - -func (helperDecDriverBincBytes) decFromRtidFnSlice(fns *atomicRtidFnSlice) (s []decRtidFnBincBytes) { - if v := fns.load(); v != nil { - s = *(lowLevelToPtr[[]decRtidFnBincBytes](v)) - } - return -} - -func (dh helperDecDriverBincBytes) decFnViaBH(rt reflect.Type, fns *atomicRtidFnSlice, x *BasicHandle, fp *fastpathDsBincBytes, - checkExt bool) (fn *decFnBincBytes) { - return dh.decFnVia(rt, fns, x.typeInfos(), &x.mu, x.extHandle, fp, - checkExt, x.CheckCircularRef, x.timeBuiltin, x.binaryHandle, x.jsonHandle) -} - -func (dh helperDecDriverBincBytes) decFnVia(rt reflect.Type, fns *atomicRtidFnSlice, - tinfos *TypeInfos, mu *sync.Mutex, exth extHandle, fp *fastpathDsBincBytes, - checkExt, checkCircularRef, timeBuiltin, binaryEncoding, json bool) (fn *decFnBincBytes) { - rtid := rt2id(rt) - var sp []decRtidFnBincBytes = dh.decFromRtidFnSlice(fns) - if sp != nil { - _, fn = dh.decFindRtidFn(sp, rtid) - } - if fn == nil { - fn = dh.decFnViaLoader(rt, rtid, fns, tinfos, mu, exth, fp, checkExt, checkCircularRef, timeBuiltin, binaryEncoding, json) - } - return -} - -func (dh helperDecDriverBincBytes) decFnViaLoader(rt reflect.Type, rtid uintptr, fns *atomicRtidFnSlice, - tinfos *TypeInfos, mu *sync.Mutex, exth extHandle, fp *fastpathDsBincBytes, - checkExt, checkCircularRef, timeBuiltin, binaryEncoding, json bool) (fn *decFnBincBytes) { - - fn = dh.decFnLoad(rt, rtid, tinfos, exth, fp, checkExt, checkCircularRef, timeBuiltin, binaryEncoding, json) - var sp []decRtidFnBincBytes - mu.Lock() - sp = dh.decFromRtidFnSlice(fns) - - if sp == nil { - sp = []decRtidFnBincBytes{{rtid, fn}} - fns.store(ptrToLowLevel(&sp)) - } else { - idx, fn2 := dh.decFindRtidFn(sp, rtid) - if fn2 == nil { - sp2 := make([]decRtidFnBincBytes, len(sp)+1) - copy(sp2[idx+1:], sp[idx:]) - copy(sp2, sp[:idx]) - sp2[idx] = decRtidFnBincBytes{rtid, fn} - fns.store(ptrToLowLevel(&sp2)) - } - } - mu.Unlock() - return -} - -func (dh helperDecDriverBincBytes) decFnLoad(rt reflect.Type, rtid uintptr, tinfos *TypeInfos, - exth extHandle, fp *fastpathDsBincBytes, - checkExt, checkCircularRef, timeBuiltin, binaryEncoding, json bool) (fn *decFnBincBytes) { - fn = new(decFnBincBytes) - fi := &(fn.i) - ti := tinfos.get(rtid, rt) - fi.ti = ti - rk := reflect.Kind(ti.kind) - - fi.addrDf = true - - if rtid == timeTypId && timeBuiltin { - fn.fd = (*decoderBincBytes).kTime - } else if rtid == rawTypId { - fn.fd = (*decoderBincBytes).raw - } else if rtid == rawExtTypId { - fn.fd = (*decoderBincBytes).rawExt - fi.addrD = true - } else if xfFn := exth.getExt(rtid, checkExt); xfFn != nil { - fi.xfTag, fi.xfFn = xfFn.tag, xfFn.ext - fn.fd = (*decoderBincBytes).ext - fi.addrD = true - } else if ti.flagSelfer || ti.flagSelferPtr { - fn.fd = (*decoderBincBytes).selferUnmarshal - fi.addrD = ti.flagSelferPtr - } else if supportMarshalInterfaces && binaryEncoding && - (ti.flagBinaryMarshaler || ti.flagBinaryMarshalerPtr) && - (ti.flagBinaryUnmarshaler || ti.flagBinaryUnmarshalerPtr) { - fn.fd = (*decoderBincBytes).binaryUnmarshal - fi.addrD = ti.flagBinaryUnmarshalerPtr - } else if supportMarshalInterfaces && !binaryEncoding && json && - (ti.flagJsonMarshaler || ti.flagJsonMarshalerPtr) && - (ti.flagJsonUnmarshaler || ti.flagJsonUnmarshalerPtr) { - - fn.fd = (*decoderBincBytes).jsonUnmarshal - fi.addrD = ti.flagJsonUnmarshalerPtr - } else if supportMarshalInterfaces && !binaryEncoding && - (ti.flagTextMarshaler || ti.flagTextMarshalerPtr) && - (ti.flagTextUnmarshaler || ti.flagTextUnmarshalerPtr) { - fn.fd = (*decoderBincBytes).textUnmarshal - fi.addrD = ti.flagTextUnmarshalerPtr - } else { - if fastpathEnabled && (rk == reflect.Map || rk == reflect.Slice || rk == reflect.Array) { - var rtid2 uintptr - if !ti.flagHasPkgPath { - rtid2 = rtid - if rk == reflect.Array { - rtid2 = rt2id(ti.key) - } - if idx, ok := fastpathAvIndex(rtid2); ok { - fn.fd = fp[idx].decfn - fi.addrD = true - fi.addrDf = false - if rk == reflect.Array { - fi.addrD = false - } - } - } else { - - xfe, xrt := dh.decFnloadFastpathUnderlying(ti, fp) - if xfe != nil { - xfnf2 := xfe.decfn - if rk == reflect.Array { - fi.addrD = false - fn.fd = func(d *decoderBincBytes, xf *decFnInfo, xrv reflect.Value) { - xfnf2(d, xf, rvConvert(xrv, xrt)) - } - } else { - fi.addrD = true - fi.addrDf = false - xptr2rt := reflect.PointerTo(xrt) - fn.fd = func(d *decoderBincBytes, xf *decFnInfo, xrv reflect.Value) { - if xrv.Kind() == reflect.Ptr { - xfnf2(d, xf, rvConvert(xrv, xptr2rt)) - } else { - xfnf2(d, xf, rvConvert(xrv, xrt)) - } - } - } - } - } - } - if fn.fd == nil { - switch rk { - case reflect.Bool: - fn.fd = (*decoderBincBytes).kBool - case reflect.String: - fn.fd = (*decoderBincBytes).kString - case reflect.Int: - fn.fd = (*decoderBincBytes).kInt - case reflect.Int8: - fn.fd = (*decoderBincBytes).kInt8 - case reflect.Int16: - fn.fd = (*decoderBincBytes).kInt16 - case reflect.Int32: - fn.fd = (*decoderBincBytes).kInt32 - case reflect.Int64: - fn.fd = (*decoderBincBytes).kInt64 - case reflect.Uint: - fn.fd = (*decoderBincBytes).kUint - case reflect.Uint8: - fn.fd = (*decoderBincBytes).kUint8 - case reflect.Uint16: - fn.fd = (*decoderBincBytes).kUint16 - case reflect.Uint32: - fn.fd = (*decoderBincBytes).kUint32 - case reflect.Uint64: - fn.fd = (*decoderBincBytes).kUint64 - case reflect.Uintptr: - fn.fd = (*decoderBincBytes).kUintptr - case reflect.Float32: - fn.fd = (*decoderBincBytes).kFloat32 - case reflect.Float64: - fn.fd = (*decoderBincBytes).kFloat64 - case reflect.Complex64: - fn.fd = (*decoderBincBytes).kComplex64 - case reflect.Complex128: - fn.fd = (*decoderBincBytes).kComplex128 - case reflect.Chan: - fn.fd = (*decoderBincBytes).kChan - case reflect.Slice: - fn.fd = (*decoderBincBytes).kSlice - case reflect.Array: - fi.addrD = false - fn.fd = (*decoderBincBytes).kArray - case reflect.Struct: - if ti.simple { - fn.fd = (*decoderBincBytes).kStructSimple - } else { - fn.fd = (*decoderBincBytes).kStruct - } - case reflect.Map: - fn.fd = (*decoderBincBytes).kMap - case reflect.Interface: - - fn.fd = (*decoderBincBytes).kInterface - default: - - fn.fd = (*decoderBincBytes).kErr - } - } - } - return -} -func (e *bincEncDriverBytes) EncodeNil() { - e.w.writen1(bincBdNil) -} - -func (e *bincEncDriverBytes) EncodeTime(t time.Time) { - if t.IsZero() { - e.EncodeNil() - } else { - bs := bincEncodeTime(t) - e.w.writen1(bincVdTimestamp<<4 | uint8(len(bs))) - e.w.writeb(bs) - } -} - -func (e *bincEncDriverBytes) EncodeBool(b bool) { - if b { - e.w.writen1(bincVdSpecial<<4 | bincSpTrue) - } else { - e.w.writen1(bincVdSpecial<<4 | bincSpFalse) - } -} - -func (e *bincEncDriverBytes) encSpFloat(f float64) (done bool) { - if f == 0 { - e.w.writen1(bincVdSpecial<<4 | bincSpZeroFloat) - } else if math.IsNaN(float64(f)) { - e.w.writen1(bincVdSpecial<<4 | bincSpNan) - } else if math.IsInf(float64(f), +1) { - e.w.writen1(bincVdSpecial<<4 | bincSpPosInf) - } else if math.IsInf(float64(f), -1) { - e.w.writen1(bincVdSpecial<<4 | bincSpNegInf) - } else { - return - } - return true -} - -func (e *bincEncDriverBytes) EncodeFloat32(f float32) { - if !e.encSpFloat(float64(f)) { - e.w.writen1(bincVdFloat<<4 | bincFlBin32) - e.w.writen4(bigen.PutUint32(math.Float32bits(f))) - } -} - -func (e *bincEncDriverBytes) EncodeFloat64(f float64) { - if e.encSpFloat(f) { - return - } - b := bigen.PutUint64(math.Float64bits(f)) - if bincDoPrune { - i := 7 - for ; i >= 0 && (b[i] == 0); i-- { - } - i++ - if i <= 6 { - e.w.writen1(bincVdFloat<<4 | 0x8 | bincFlBin64) - e.w.writen1(byte(i)) - e.w.writeb(b[:i]) - return - } - } - e.w.writen1(bincVdFloat<<4 | bincFlBin64) - e.w.writen8(b) -} - -func (e *bincEncDriverBytes) encIntegerPrune32(bd byte, pos bool, v uint64) { - b := bigen.PutUint32(uint32(v)) - if bincDoPrune { - i := byte(pruneSignExt(b[:], pos)) - e.w.writen1(bd | 3 - i) - e.w.writeb(b[i:]) - } else { - e.w.writen1(bd | 3) - e.w.writen4(b) - } -} - -func (e *bincEncDriverBytes) encIntegerPrune64(bd byte, pos bool, v uint64) { - b := bigen.PutUint64(v) - if bincDoPrune { - i := byte(pruneSignExt(b[:], pos)) - e.w.writen1(bd | 7 - i) - e.w.writeb(b[i:]) - } else { - e.w.writen1(bd | 7) - e.w.writen8(b) - } -} - -func (e *bincEncDriverBytes) EncodeInt(v int64) { - if v >= 0 { - e.encUint(bincVdPosInt<<4, true, uint64(v)) - } else if v == -1 { - e.w.writen1(bincVdSpecial<<4 | bincSpNegOne) - } else { - e.encUint(bincVdNegInt<<4, false, uint64(-v)) - } -} - -func (e *bincEncDriverBytes) EncodeUint(v uint64) { - e.encUint(bincVdPosInt<<4, true, v) -} - -func (e *bincEncDriverBytes) encUint(bd byte, pos bool, v uint64) { - if v == 0 { - e.w.writen1(bincVdSpecial<<4 | bincSpZero) - } else if pos && v >= 1 && v <= 16 { - e.w.writen1(bincVdSmallInt<<4 | byte(v-1)) - } else if v <= math.MaxUint8 { - e.w.writen2(bd, byte(v)) - } else if v <= math.MaxUint16 { - e.w.writen1(bd | 0x01) - e.w.writen2(bigen.PutUint16(uint16(v))) - } else if v <= math.MaxUint32 { - e.encIntegerPrune32(bd, pos, v) - } else { - e.encIntegerPrune64(bd, pos, v) - } -} - -func (e *bincEncDriverBytes) EncodeExt(v interface{}, basetype reflect.Type, xtag uint64, ext Ext) { - var bs0, bs []byte - if ext == SelfExt { - bs0 = e.e.blist.get(1024) - bs = bs0 - sideEncode(e.h, &e.h.sideEncPool, func(se encoderI) { oneOffEncode(se, v, &bs, basetype, true) }) - } else { - bs = ext.WriteExt(v) - } - if bs == nil { - e.writeNilBytes() - goto END - } - e.encodeExtPreamble(uint8(xtag), len(bs)) - e.w.writeb(bs) -END: - if ext == SelfExt { - e.e.blist.put(bs) - if !byteSliceSameData(bs0, bs) { - e.e.blist.put(bs0) - } - } -} - -func (e *bincEncDriverBytes) EncodeRawExt(re *RawExt) { - e.encodeExtPreamble(uint8(re.Tag), len(re.Data)) - e.w.writeb(re.Data) -} - -func (e *bincEncDriverBytes) encodeExtPreamble(xtag byte, length int) { - e.encLen(bincVdCustomExt<<4, uint64(length)) - e.w.writen1(xtag) -} - -func (e *bincEncDriverBytes) WriteArrayStart(length int) { - e.encLen(bincVdArray<<4, uint64(length)) -} - -func (e *bincEncDriverBytes) WriteMapStart(length int) { - e.encLen(bincVdMap<<4, uint64(length)) -} - -func (e *bincEncDriverBytes) WriteArrayEmpty() { - - e.w.writen1(bincVdArray<<4 | uint8(0+4)) -} - -func (e *bincEncDriverBytes) WriteMapEmpty() { - - e.w.writen1(bincVdMap<<4 | uint8(0+4)) -} - -func (e *bincEncDriverBytes) EncodeSymbol(v string) { - - l := len(v) - if l == 0 { - e.encBytesLen(cUTF8, 0) - return - } else if l == 1 { - e.encBytesLen(cUTF8, 1) - e.w.writen1(v[0]) - return - } - if e.m == nil { - e.m = make(map[string]uint16, 16) - } - ui, ok := e.m[v] - if ok { - if ui <= math.MaxUint8 { - e.w.writen2(bincVdSymbol<<4, byte(ui)) - } else { - e.w.writen1(bincVdSymbol<<4 | 0x8) - e.w.writen2(bigen.PutUint16(ui)) - } - } else { - e.e.seq++ - ui = e.e.seq - e.m[v] = ui - var lenprec uint8 - if l <= math.MaxUint8 { - - } else if l <= math.MaxUint16 { - lenprec = 1 - } else if int64(l) <= math.MaxUint32 { - lenprec = 2 - } else { - lenprec = 3 - } - if ui <= math.MaxUint8 { - e.w.writen2(bincVdSymbol<<4|0x4|lenprec, byte(ui)) - } else { - e.w.writen1(bincVdSymbol<<4 | 0x8 | 0x4 | lenprec) - e.w.writen2(bigen.PutUint16(ui)) - } - if lenprec == 0 { - e.w.writen1(byte(l)) - } else if lenprec == 1 { - e.w.writen2(bigen.PutUint16(uint16(l))) - } else if lenprec == 2 { - e.w.writen4(bigen.PutUint32(uint32(l))) - } else { - e.w.writen8(bigen.PutUint64(uint64(l))) - } - e.w.writestr(v) - } -} - -func (e *bincEncDriverBytes) EncodeString(v string) { - if e.h.StringToRaw { - e.encLen(bincVdByteArray<<4, uint64(len(v))) - if len(v) > 0 { - e.w.writestr(v) - } - return - } - e.EncodeStringEnc(cUTF8, v) -} - -func (e *bincEncDriverBytes) EncodeStringNoEscape4Json(v string) { e.EncodeString(v) } - -func (e *bincEncDriverBytes) EncodeStringEnc(c charEncoding, v string) { - if e.e.c == containerMapKey && c == cUTF8 && (e.h.AsSymbols == 1) { - e.EncodeSymbol(v) - return - } - e.encLen(bincVdString<<4, uint64(len(v))) - if len(v) > 0 { - e.w.writestr(v) - } -} - -func (e *bincEncDriverBytes) EncodeStringBytesRaw(v []byte) { - e.encLen(bincVdByteArray<<4, uint64(len(v))) - if len(v) > 0 { - e.w.writeb(v) - } -} - -func (e *bincEncDriverBytes) EncodeBytes(v []byte) { - if v == nil { - e.writeNilBytes() - return - } - e.EncodeStringBytesRaw(v) -} - -func (e *bincEncDriverBytes) writeNilOr(v byte) { - if !e.h.NilCollectionToZeroLength { - v = bincBdNil - } - e.w.writen1(v) -} - -func (e *bincEncDriverBytes) writeNilArray() { - e.writeNilOr(bincVdArray<<4 | uint8(0+4)) -} - -func (e *bincEncDriverBytes) writeNilMap() { - e.writeNilOr(bincVdMap<<4 | uint8(0+4)) -} - -func (e *bincEncDriverBytes) writeNilBytes() { - e.writeNilOr(bincVdArray<<4 | uint8(0+4)) -} - -func (e *bincEncDriverBytes) encBytesLen(c charEncoding, length uint64) { - - if c == cRAW { - e.encLen(bincVdByteArray<<4, length) - } else { - e.encLen(bincVdString<<4, length) - } -} - -func (e *bincEncDriverBytes) encLen(bd byte, l uint64) { - if l < 12 { - e.w.writen1(bd | uint8(l+4)) - } else { - e.encLenNumber(bd, l) - } -} - -func (e *bincEncDriverBytes) encLenNumber(bd byte, v uint64) { - if v <= math.MaxUint8 { - e.w.writen2(bd, byte(v)) - } else if v <= math.MaxUint16 { - e.w.writen1(bd | 0x01) - e.w.writen2(bigen.PutUint16(uint16(v))) - } else if v <= math.MaxUint32 { - e.w.writen1(bd | 0x02) - e.w.writen4(bigen.PutUint32(uint32(v))) - } else { - e.w.writen1(bd | 0x03) - e.w.writen8(bigen.PutUint64(uint64(v))) - } -} - -func (d *bincDecDriverBytes) readNextBd() { - d.bd = d.r.readn1() - d.vd = d.bd >> 4 - d.vs = d.bd & 0x0f - d.bdRead = true -} - -func (d *bincDecDriverBytes) advanceNil() (null bool) { - if !d.bdRead { - d.readNextBd() - } - if d.bd == bincBdNil { - d.bdRead = false - return true - } - return -} - -func (d *bincDecDriverBytes) TryNil() bool { - return d.advanceNil() -} - -func (d *bincDecDriverBytes) ContainerType() (vt valueType) { - if !d.bdRead { - d.readNextBd() - } - if d.bd == bincBdNil { - d.bdRead = false - return valueTypeNil - } else if d.vd == bincVdByteArray { - return valueTypeBytes - } else if d.vd == bincVdString { - return valueTypeString - } else if d.vd == bincVdArray { - return valueTypeArray - } else if d.vd == bincVdMap { - return valueTypeMap - } - return valueTypeUnset -} - -func (d *bincDecDriverBytes) DecodeTime() (t time.Time) { - if d.advanceNil() { - return - } - if d.vd != bincVdTimestamp { - halt.errorf("cannot decode time - %s %x-%x/%s", msgBadDesc, d.vd, d.vs, bincdesc(d.vd, d.vs)) - } - t, err := bincDecodeTime(d.r.readx(uint(d.vs))) - halt.onerror(err) - d.bdRead = false - return -} - -func (d *bincDecDriverBytes) decFloatPruned(maxlen uint8) { - l := d.r.readn1() - if l > maxlen { - halt.errorf("cannot read float - at most %v bytes used to represent float - received %v bytes", maxlen, l) - } - for i := l; i < maxlen; i++ { - d.d.b[i] = 0 - } - d.r.readb(d.d.b[0:l]) -} - -func (d *bincDecDriverBytes) decFloatPre32() (b [4]byte) { - if d.vs&0x8 == 0 { - b = d.r.readn4() - } else { - d.decFloatPruned(4) - copy(b[:], d.d.b[:]) - } - return -} - -func (d *bincDecDriverBytes) decFloatPre64() (b [8]byte) { - if d.vs&0x8 == 0 { - b = d.r.readn8() - } else { - d.decFloatPruned(8) - copy(b[:], d.d.b[:]) - } - return -} - -func (d *bincDecDriverBytes) decFloatVal() (f float64) { - switch d.vs & 0x7 { - case bincFlBin32: - f = float64(math.Float32frombits(bigen.Uint32(d.decFloatPre32()))) - case bincFlBin64: - f = math.Float64frombits(bigen.Uint64(d.decFloatPre64())) - default: - - halt.errorf("read float supports only float32/64 - %s %x-%x/%s", msgBadDesc, d.vd, d.vs, bincdesc(d.vd, d.vs)) - } - return -} - -func (d *bincDecDriverBytes) decUint() (v uint64) { - switch d.vs { - case 0: - v = uint64(d.r.readn1()) - case 1: - v = uint64(bigen.Uint16(d.r.readn2())) - case 2: - b3 := d.r.readn3() - var b [4]byte - copy(b[1:], b3[:]) - v = uint64(bigen.Uint32(b)) - case 3: - v = uint64(bigen.Uint32(d.r.readn4())) - case 4, 5, 6: - - bs := d.d.b[:8] - clear(bs) - d.r.readb(bs[(7 - d.vs):]) - v = bigen.Uint64(*(*[8]byte)(bs)) - case 7: - v = bigen.Uint64(d.r.readn8()) - default: - halt.errorf("unsigned integers with greater than 64 bits of precision not supported: d.vs: %v %x", d.vs, d.vs) - } - return -} - -func (d *bincDecDriverBytes) uintBytes() (bs []byte) { - switch d.vs { - case 0: - bs = d.d.b[:1] - bs[0] = d.r.readn1() - return - case 1: - bs = d.d.b[:2] - case 2: - bs = d.d.b[:3] - case 3: - bs = d.d.b[:4] - case 4, 5, 6: - lim := 7 - d.vs - bs = d.d.b[lim:8] - case 7: - bs = d.d.b[:8] - default: - halt.errorf("unsigned integers with greater than 64 bits of precision not supported: d.vs: %v %x", d.vs, d.vs) - } - d.r.readb(bs) - return -} - -func (d *bincDecDriverBytes) decInteger() (ui uint64, neg, ok bool) { - ok = true - vd, vs := d.vd, d.vs - if vd == bincVdPosInt { - ui = d.decUint() - } else if vd == bincVdNegInt { - ui = d.decUint() - neg = true - } else if vd == bincVdSmallInt { - ui = uint64(d.vs) + 1 - } else if vd == bincVdSpecial { - if vs == bincSpZero { - - } else if vs == bincSpNegOne { - neg = true - ui = 1 - } else { - ok = false - - } - } else { - ok = false - - } - return -} - -func (d *bincDecDriverBytes) decFloat() (f float64, ok bool) { - ok = true - vd, vs := d.vd, d.vs - if vd == bincVdSpecial { - if vs == bincSpNan { - f = math.NaN() - } else if vs == bincSpPosInf { - f = math.Inf(1) - } else if vs == bincSpZeroFloat || vs == bincSpZero { - - } else if vs == bincSpNegInf { - f = math.Inf(-1) - } else { - ok = false - - } - } else if vd == bincVdFloat { - f = d.decFloatVal() - } else { - ok = false - } - return -} - -func (d *bincDecDriverBytes) DecodeInt64() (i int64) { - if d.advanceNil() { - return - } - v1, v2, v3 := d.decInteger() - i = decNegintPosintFloatNumberHelper{d}.int64(v1, v2, v3, false) - d.bdRead = false - return -} - -func (d *bincDecDriverBytes) DecodeUint64() (ui uint64) { - if d.advanceNil() { - return - } - ui = decNegintPosintFloatNumberHelper{d}.uint64(d.decInteger()) - d.bdRead = false - return -} - -func (d *bincDecDriverBytes) DecodeFloat64() (f float64) { - if d.advanceNil() { - return - } - v1, v2 := d.decFloat() - f = decNegintPosintFloatNumberHelper{d}.float64(v1, v2, false) - d.bdRead = false - return -} - -func (d *bincDecDriverBytes) DecodeBool() (b bool) { - if d.advanceNil() { - return - } - if d.bd == (bincVdSpecial | bincSpFalse) { - - } else if d.bd == (bincVdSpecial | bincSpTrue) { - b = true - } else { - halt.errorf("bool - %s %x-%x/%s", msgBadDesc, d.vd, d.vs, bincdesc(d.vd, d.vs)) - } - d.bdRead = false - return -} - -func (d *bincDecDriverBytes) ReadMapStart() (length int) { - if d.advanceNil() { - return containerLenNil - } - if d.vd != bincVdMap { - halt.errorf("map - %s %x-%x/%s", msgBadDesc, d.vd, d.vs, bincdesc(d.vd, d.vs)) - } - length = d.decLen() - d.bdRead = false - return -} - -func (d *bincDecDriverBytes) ReadArrayStart() (length int) { - if d.advanceNil() { - return containerLenNil - } - if d.vd != bincVdArray { - halt.errorf("array - %s %x-%x/%s", msgBadDesc, d.vd, d.vs, bincdesc(d.vd, d.vs)) - } - length = d.decLen() - d.bdRead = false - return -} - -func (d *bincDecDriverBytes) decLen() int { - if d.vs > 3 { - return int(d.vs - 4) - } - return int(d.decLenNumber()) -} - -func (d *bincDecDriverBytes) decLenNumber() (v uint64) { - if x := d.vs; x == 0 { - v = uint64(d.r.readn1()) - } else if x == 1 { - v = uint64(bigen.Uint16(d.r.readn2())) - } else if x == 2 { - v = uint64(bigen.Uint32(d.r.readn4())) - } else { - v = bigen.Uint64(d.r.readn8()) - } - return -} - -func (d *bincDecDriverBytes) DecodeStringAsBytes() (bs []byte, state dBytesAttachState) { - if d.advanceNil() { - return - } - var cond bool - var slen = -1 - switch d.vd { - case bincVdString, bincVdByteArray: - slen = d.decLen() - bs, cond = d.r.readxb(uint(slen)) - state = d.d.attachState(cond) - case bincVdSymbol: - - var symbol uint16 - vs := d.vs - if vs&0x8 == 0 { - symbol = uint16(d.r.readn1()) - } else { - symbol = uint16(bigen.Uint16(d.r.readn2())) - } - if d.s == nil { - d.s = make(map[uint16][]byte, 16) - } - - if vs&0x4 == 0 { - bs = d.s[symbol] - } else { - switch vs & 0x3 { - case 0: - slen = int(d.r.readn1()) - case 1: - slen = int(bigen.Uint16(d.r.readn2())) - case 2: - slen = int(bigen.Uint32(d.r.readn4())) - case 3: - slen = int(bigen.Uint64(d.r.readn8())) - } - - bs, cond = d.r.readxb(uint(slen)) - bs = d.d.detach2Bytes(bs, d.d.attachState(cond)) - d.s[symbol] = bs - } - state = dBytesDetach - default: - halt.errorf("string/bytes - %s %x-%x/%s", msgBadDesc, d.vd, d.vs, bincdesc(d.vd, d.vs)) - } - - if d.h.ValidateUnicode && !utf8.Valid(bs) { - halt.errorf("DecodeStringAsBytes: invalid UTF-8: %s", bs) - } - - d.bdRead = false - return -} - -func (d *bincDecDriverBytes) DecodeBytes() (bs []byte, state dBytesAttachState) { - if d.advanceNil() { - return - } - var cond bool - if d.vd == bincVdArray { - slen := d.ReadArrayStart() - bs, cond = usableByteSlice(d.d.buf, slen) - for i := 0; i < slen; i++ { - bs[i] = uint8(chkOvf.UintV(d.DecodeUint64(), 8)) - } - for i := len(bs); i < slen; i++ { - bs = append(bs, uint8(chkOvf.UintV(d.DecodeUint64(), 8))) - } - if cond { - d.d.buf = bs - } - state = dBytesAttachBuffer - return - } - if !(d.vd == bincVdString || d.vd == bincVdByteArray) { - halt.errorf("bytes - %s %x-%x/%s", msgBadDesc, d.vd, d.vs, bincdesc(d.vd, d.vs)) - } - clen := d.decLen() - d.bdRead = false - bs, cond = d.r.readxb(uint(clen)) - state = d.d.attachState(cond) - return -} - -func (d *bincDecDriverBytes) DecodeExt(rv interface{}, basetype reflect.Type, xtag uint64, ext Ext) { - xbs, _, _, ok := d.decodeExtV(ext != nil, xtag) - if !ok { - return - } - if ext == SelfExt { - sideDecode(d.h, &d.h.sideDecPool, func(sd decoderI) { oneOffDecode(sd, rv, xbs, basetype, true) }) - } else { - ext.ReadExt(rv, xbs) - } -} - -func (d *bincDecDriverBytes) DecodeRawExt(re *RawExt) { - xbs, realxtag, state, ok := d.decodeExtV(false, 0) - if !ok { - return - } - re.Tag = uint64(realxtag) - re.setData(xbs, state >= dBytesAttachViewZerocopy) -} - -func (d *bincDecDriverBytes) decodeExtV(verifyTag bool, xtagIn uint64) (xbs []byte, xtag byte, bstate dBytesAttachState, ok bool) { - if xtagIn > 0xff { - halt.errorf("ext: tag must be <= 0xff; got: %v", xtagIn) - } - if d.advanceNil() { - return - } - tag := uint8(xtagIn) - if d.vd == bincVdCustomExt { - l := d.decLen() - xtag = d.r.readn1() - if verifyTag && xtag != tag { - halt.errorf("wrong extension tag - got %b, expecting: %v", xtag, tag) - } - xbs, ok = d.r.readxb(uint(l)) - bstate = d.d.attachState(ok) - - } else if d.vd == bincVdByteArray { - xbs, bstate = d.DecodeBytes() - } else { - halt.errorf("ext expects extensions or byte array - %s %x-%x/%s", msgBadDesc, d.vd, d.vs, bincdesc(d.vd, d.vs)) - } - d.bdRead = false - ok = true - return -} - -func (d *bincDecDriverBytes) DecodeNaked() { - if !d.bdRead { - d.readNextBd() - } - - n := d.d.naked() - var decodeFurther bool - - switch d.vd { - case bincVdSpecial: - switch d.vs { - case bincSpNil: - n.v = valueTypeNil - case bincSpFalse: - n.v = valueTypeBool - n.b = false - case bincSpTrue: - n.v = valueTypeBool - n.b = true - case bincSpNan: - n.v = valueTypeFloat - n.f = math.NaN() - case bincSpPosInf: - n.v = valueTypeFloat - n.f = math.Inf(1) - case bincSpNegInf: - n.v = valueTypeFloat - n.f = math.Inf(-1) - case bincSpZeroFloat: - n.v = valueTypeFloat - n.f = float64(0) - case bincSpZero: - n.v = valueTypeUint - n.u = uint64(0) - case bincSpNegOne: - n.v = valueTypeInt - n.i = int64(-1) - default: - halt.errorf("cannot infer value - unrecognized special value %x-%x/%s", d.vd, d.vs, bincdesc(d.vd, d.vs)) - } - case bincVdSmallInt: - n.v = valueTypeUint - n.u = uint64(int8(d.vs)) + 1 - case bincVdPosInt: - n.v = valueTypeUint - n.u = d.decUint() - case bincVdNegInt: - n.v = valueTypeInt - n.i = -(int64(d.decUint())) - case bincVdFloat: - n.v = valueTypeFloat - n.f = d.decFloatVal() - case bincVdString: - n.v = valueTypeString - n.s = d.d.detach2Str(d.DecodeStringAsBytes()) - case bincVdByteArray: - d.d.fauxUnionReadRawBytes(d, false, d.h.RawToString) - case bincVdSymbol: - n.v = valueTypeSymbol - n.s = d.d.detach2Str(d.DecodeStringAsBytes()) - case bincVdTimestamp: - n.v = valueTypeTime - tt, err := bincDecodeTime(d.r.readx(uint(d.vs))) - halt.onerror(err) - n.t = tt - case bincVdCustomExt: - n.v = valueTypeExt - l := d.decLen() - n.u = uint64(d.r.readn1()) - n.l = d.r.readx(uint(l)) - case bincVdArray: - n.v = valueTypeArray - decodeFurther = true - case bincVdMap: - n.v = valueTypeMap - decodeFurther = true - default: - halt.errorf("cannot infer value - %s %x-%x/%s", msgBadDesc, d.vd, d.vs, bincdesc(d.vd, d.vs)) - } - - if !decodeFurther { - d.bdRead = false - } - if n.v == valueTypeUint && d.h.SignedInteger { - n.v = valueTypeInt - n.i = int64(n.u) - } -} - -func (d *bincDecDriverBytes) nextValueBytes() (v []byte) { - if !d.bdRead { - d.readNextBd() - } - d.r.startRecording() - d.nextValueBytesBdReadR() - v = d.r.stopRecording() - d.bdRead = false - return -} - -func (d *bincDecDriverBytes) nextValueBytesBdReadR() { - fnLen := func(vs byte) uint { - switch vs { - case 0: - x := d.r.readn1() - return uint(x) - case 1: - x := d.r.readn2() - return uint(bigen.Uint16(x)) - case 2: - x := d.r.readn4() - return uint(bigen.Uint32(x)) - case 3: - x := d.r.readn8() - return uint(bigen.Uint64(x)) - default: - return uint(vs - 4) - } - } - - var clen uint - - switch d.vd { - case bincVdSpecial: - switch d.vs { - case bincSpNil, bincSpFalse, bincSpTrue, bincSpNan, bincSpPosInf: - case bincSpNegInf, bincSpZeroFloat, bincSpZero, bincSpNegOne: - default: - halt.errorf("cannot infer value - unrecognized special value %x-%x/%s", d.vd, d.vs, bincdesc(d.vd, d.vs)) - } - case bincVdSmallInt: - case bincVdPosInt, bincVdNegInt: - d.uintBytes() - case bincVdFloat: - fn := func(xlen byte) { - if d.vs&0x8 != 0 { - xlen = d.r.readn1() - if xlen > 8 { - halt.errorf("cannot read float - at most 8 bytes used to represent float - received %v bytes", xlen) - } - } - d.r.readb(d.d.b[:xlen]) - } - switch d.vs & 0x7 { - case bincFlBin32: - fn(4) - case bincFlBin64: - fn(8) - default: - halt.errorf("read float supports only float32/64 - %s %x-%x/%s", msgBadDesc, d.vd, d.vs, bincdesc(d.vd, d.vs)) - } - case bincVdString, bincVdByteArray: - clen = fnLen(d.vs) - d.r.skip(clen) - case bincVdSymbol: - if d.vs&0x8 == 0 { - d.r.readn1() - } else { - d.r.skip(2) - } - if d.vs&0x4 != 0 { - clen = fnLen(d.vs & 0x3) - d.r.skip(clen) - } - case bincVdTimestamp: - d.r.skip(uint(d.vs)) - case bincVdCustomExt: - clen = fnLen(d.vs) - d.r.readn1() - d.r.skip(clen) - case bincVdArray: - clen = fnLen(d.vs) - for i := uint(0); i < clen; i++ { - d.readNextBd() - d.nextValueBytesBdReadR() - } - case bincVdMap: - clen = fnLen(d.vs) - for i := uint(0); i < clen; i++ { - d.readNextBd() - d.nextValueBytesBdReadR() - d.readNextBd() - d.nextValueBytesBdReadR() - } - default: - halt.errorf("cannot infer value - %s %x-%x/%s", msgBadDesc, d.vd, d.vs, bincdesc(d.vd, d.vs)) - } - return -} - -func (d *bincEncDriverBytes) init(hh Handle, shared *encoderBase, enc encoderI) (fp interface{}) { - callMake(&d.w) - d.h = hh.(*BincHandle) - d.e = shared - if shared.bytes { - fp = bincFpEncBytes - } else { - fp = bincFpEncIO - } - - d.init2(enc) - return -} - -func (e *bincEncDriverBytes) writeBytesAsis(b []byte) { e.w.writeb(b) } - -func (e *bincEncDriverBytes) writerEnd() { e.w.end() } - -func (e *bincEncDriverBytes) resetOutBytes(out *[]byte) { - e.w.resetBytes(*out, out) -} - -func (e *bincEncDriverBytes) resetOutIO(out io.Writer) { - e.w.resetIO(out, e.h.WriterBufferSize, &e.e.blist) -} - -func (d *bincDecDriverBytes) init(hh Handle, shared *decoderBase, dec decoderI) (fp interface{}) { - callMake(&d.r) - d.h = hh.(*BincHandle) - d.d = shared - if shared.bytes { - fp = bincFpDecBytes - } else { - fp = bincFpDecIO - } - - d.init2(dec) - return -} - -func (d *bincDecDriverBytes) NumBytesRead() int { - return int(d.r.numread()) -} - -func (d *bincDecDriverBytes) resetInBytes(in []byte) { - d.r.resetBytes(in) -} - -func (d *bincDecDriverBytes) resetInIO(r io.Reader) { - d.r.resetIO(r, d.h.ReaderBufferSize, d.h.MaxInitLen, &d.d.blist) -} - -func (d *bincDecDriverBytes) descBd() string { - return sprintf("%v (%s)", d.bd, bincdescbd(d.bd)) -} - -func (d *bincDecDriverBytes) DecodeFloat32() (f float32) { - return float32(chkOvf.Float32V(d.DecodeFloat64())) -} - -type helperEncDriverBincIO struct{} -type encFnBincIO struct { - i encFnInfo - fe func(*encoderBincIO, *encFnInfo, reflect.Value) -} -type encRtidFnBincIO struct { - rtid uintptr - fn *encFnBincIO -} -type encoderBincIO struct { - dh helperEncDriverBincIO - fp *fastpathEsBincIO - e bincEncDriverIO - encoderBase -} -type helperDecDriverBincIO struct{} -type decFnBincIO struct { - i decFnInfo - fd func(*decoderBincIO, *decFnInfo, reflect.Value) -} -type decRtidFnBincIO struct { - rtid uintptr - fn *decFnBincIO -} -type decoderBincIO struct { - dh helperDecDriverBincIO - fp *fastpathDsBincIO - d bincDecDriverIO - decoderBase -} -type bincEncDriverIO struct { - noBuiltInTypes - encDriverNoopContainerWriter - encDriverContainerNoTrackerT - encInit2er - - h *BincHandle - e *encoderBase - w bufioEncWriter - bincEncState -} -type bincDecDriverIO struct { - decDriverNoopContainerReader - - decInit2er - noBuiltInTypes - - h *BincHandle - d *decoderBase - r ioDecReader - - bincDecState -} - -func (e *encoderBincIO) rawExt(_ *encFnInfo, rv reflect.Value) { - if re := rv2i(rv).(*RawExt); re == nil { - e.e.EncodeNil() - } else { - e.e.EncodeRawExt(re) - } -} - -func (e *encoderBincIO) ext(f *encFnInfo, rv reflect.Value) { - e.e.EncodeExt(rv2i(rv), f.ti.rt, f.xfTag, f.xfFn) -} - -func (e *encoderBincIO) selferMarshal(_ *encFnInfo, rv reflect.Value) { - rv2i(rv).(Selfer).CodecEncodeSelf(&Encoder{e}) -} - -func (e *encoderBincIO) binaryMarshal(_ *encFnInfo, rv reflect.Value) { - bs, fnerr := rv2i(rv).(encoding.BinaryMarshaler).MarshalBinary() - e.marshalRaw(bs, fnerr) -} - -func (e *encoderBincIO) textMarshal(_ *encFnInfo, rv reflect.Value) { - bs, fnerr := rv2i(rv).(encoding.TextMarshaler).MarshalText() - e.marshalUtf8(bs, fnerr) -} - -func (e *encoderBincIO) jsonMarshal(_ *encFnInfo, rv reflect.Value) { - bs, fnerr := rv2i(rv).(jsonMarshaler).MarshalJSON() - e.marshalAsis(bs, fnerr) -} - -func (e *encoderBincIO) raw(_ *encFnInfo, rv reflect.Value) { - e.rawBytes(rv2i(rv).(Raw)) -} - -func (e *encoderBincIO) encodeComplex64(v complex64) { - if imag(v) != 0 { - halt.errorf("cannot encode complex number: %v, with imaginary values: %v", any(v), any(imag(v))) - } - e.e.EncodeFloat32(real(v)) -} - -func (e *encoderBincIO) encodeComplex128(v complex128) { - if imag(v) != 0 { - halt.errorf("cannot encode complex number: %v, with imaginary values: %v", any(v), any(imag(v))) - } - e.e.EncodeFloat64(real(v)) -} - -func (e *encoderBincIO) kBool(_ *encFnInfo, rv reflect.Value) { - e.e.EncodeBool(rvGetBool(rv)) -} - -func (e *encoderBincIO) kTime(_ *encFnInfo, rv reflect.Value) { - e.e.EncodeTime(rvGetTime(rv)) -} - -func (e *encoderBincIO) kString(_ *encFnInfo, rv reflect.Value) { - e.e.EncodeString(rvGetString(rv)) -} - -func (e *encoderBincIO) kFloat32(_ *encFnInfo, rv reflect.Value) { - e.e.EncodeFloat32(rvGetFloat32(rv)) -} - -func (e *encoderBincIO) kFloat64(_ *encFnInfo, rv reflect.Value) { - e.e.EncodeFloat64(rvGetFloat64(rv)) -} - -func (e *encoderBincIO) kComplex64(_ *encFnInfo, rv reflect.Value) { - e.encodeComplex64(rvGetComplex64(rv)) -} - -func (e *encoderBincIO) kComplex128(_ *encFnInfo, rv reflect.Value) { - e.encodeComplex128(rvGetComplex128(rv)) -} - -func (e *encoderBincIO) kInt(_ *encFnInfo, rv reflect.Value) { - e.e.EncodeInt(int64(rvGetInt(rv))) -} - -func (e *encoderBincIO) kInt8(_ *encFnInfo, rv reflect.Value) { - e.e.EncodeInt(int64(rvGetInt8(rv))) -} - -func (e *encoderBincIO) kInt16(_ *encFnInfo, rv reflect.Value) { - e.e.EncodeInt(int64(rvGetInt16(rv))) -} - -func (e *encoderBincIO) kInt32(_ *encFnInfo, rv reflect.Value) { - e.e.EncodeInt(int64(rvGetInt32(rv))) -} - -func (e *encoderBincIO) kInt64(_ *encFnInfo, rv reflect.Value) { - e.e.EncodeInt(int64(rvGetInt64(rv))) -} - -func (e *encoderBincIO) kUint(_ *encFnInfo, rv reflect.Value) { - e.e.EncodeUint(uint64(rvGetUint(rv))) -} - -func (e *encoderBincIO) kUint8(_ *encFnInfo, rv reflect.Value) { - e.e.EncodeUint(uint64(rvGetUint8(rv))) -} - -func (e *encoderBincIO) kUint16(_ *encFnInfo, rv reflect.Value) { - e.e.EncodeUint(uint64(rvGetUint16(rv))) -} - -func (e *encoderBincIO) kUint32(_ *encFnInfo, rv reflect.Value) { - e.e.EncodeUint(uint64(rvGetUint32(rv))) -} - -func (e *encoderBincIO) kUint64(_ *encFnInfo, rv reflect.Value) { - e.e.EncodeUint(uint64(rvGetUint64(rv))) -} - -func (e *encoderBincIO) kUintptr(_ *encFnInfo, rv reflect.Value) { - e.e.EncodeUint(uint64(rvGetUintptr(rv))) -} - -func (e *encoderBincIO) kSeqFn(rt reflect.Type) (fn *encFnBincIO) { - - if rt = baseRT(rt); rt.Kind() != reflect.Interface { - fn = e.fn(rt) - } - return -} - -func (e *encoderBincIO) kArrayWMbs(rv reflect.Value, ti *typeInfo, isSlice bool) { - var l int - if isSlice { - l = rvLenSlice(rv) - } else { - l = rv.Len() - } - if l == 0 { - e.e.WriteMapEmpty() - return - } - e.haltOnMbsOddLen(l) - e.mapStart(l >> 1) - - var fn *encFnBincIO - builtin := ti.tielem.flagEncBuiltin - if !builtin { - fn = e.kSeqFn(ti.elem) - } - - j := 0 - e.c = containerMapKey - e.e.WriteMapElemKey(true) - for { - rvv := rvArrayIndex(rv, j, ti, isSlice) - if builtin { - e.encodeIB(rv2i(baseRVRV(rvv))) - } else { - e.encodeValue(rvv, fn) - } - j++ - if j == l { - break - } - if j&1 == 0 { - e.c = containerMapKey - e.e.WriteMapElemKey(false) - } else { - e.mapElemValue() - } - } - e.c = 0 - e.e.WriteMapEnd() - -} - -func (e *encoderBincIO) kArrayW(rv reflect.Value, ti *typeInfo, isSlice bool) { - var l int - if isSlice { - l = rvLenSlice(rv) - } else { - l = rv.Len() - } - if l <= 0 { - e.e.WriteArrayEmpty() - return - } - e.arrayStart(l) - - var fn *encFnBincIO - if !ti.tielem.flagEncBuiltin { - fn = e.kSeqFn(ti.elem) - } - - j := 0 - e.c = containerArrayElem - e.e.WriteArrayElem(true) - builtin := ti.tielem.flagEncBuiltin - for { - rvv := rvArrayIndex(rv, j, ti, isSlice) - if builtin { - e.encodeIB(rv2i(baseRVRV(rvv))) - } else { - e.encodeValue(rvv, fn) - } - j++ - if j == l { - break - } - e.c = containerArrayElem - e.e.WriteArrayElem(false) - } - - e.c = 0 - e.e.WriteArrayEnd() -} - -func (e *encoderBincIO) kChan(f *encFnInfo, rv reflect.Value) { - if f.ti.chandir&uint8(reflect.RecvDir) == 0 { - halt.errorStr("send-only channel cannot be encoded") - } - if !f.ti.mbs && uint8TypId == rt2id(f.ti.elem) { - e.kSliceBytesChan(rv) - return - } - rtslice := reflect.SliceOf(f.ti.elem) - rv = chanToSlice(rv, rtslice, e.h.ChanRecvTimeout) - ti := e.h.getTypeInfo(rt2id(rtslice), rtslice) - if f.ti.mbs { - e.kArrayWMbs(rv, ti, true) - } else { - e.kArrayW(rv, ti, true) - } -} - -func (e *encoderBincIO) kSlice(f *encFnInfo, rv reflect.Value) { - if f.ti.mbs { - e.kArrayWMbs(rv, f.ti, true) - } else if f.ti.rtid == uint8SliceTypId || uint8TypId == rt2id(f.ti.elem) { - - e.e.EncodeBytes(rvGetBytes(rv)) - } else { - e.kArrayW(rv, f.ti, true) - } -} - -func (e *encoderBincIO) kArray(f *encFnInfo, rv reflect.Value) { - if f.ti.mbs { - e.kArrayWMbs(rv, f.ti, false) - } else if handleBytesWithinKArray && uint8TypId == rt2id(f.ti.elem) { - e.e.EncodeStringBytesRaw(rvGetArrayBytes(rv, nil)) - } else { - e.kArrayW(rv, f.ti, false) - } -} - -func (e *encoderBincIO) kSliceBytesChan(rv reflect.Value) { - - bs0 := e.blist.peek(32, true) - bs := bs0 - - irv := rv2i(rv) - ch, ok := irv.(<-chan byte) - if !ok { - ch = irv.(chan byte) - } - -L1: - switch timeout := e.h.ChanRecvTimeout; { - case timeout == 0: - for { - select { - case b := <-ch: - bs = append(bs, b) - default: - break L1 - } - } - case timeout > 0: - tt := time.NewTimer(timeout) - for { - select { - case b := <-ch: - bs = append(bs, b) - case <-tt.C: - - break L1 - } - } - default: - for b := range ch { - bs = append(bs, b) - } - } - - e.e.EncodeBytes(bs) - e.blist.put(bs) - if !byteSliceSameData(bs0, bs) { - e.blist.put(bs0) - } -} - -func (e *encoderBincIO) kStructFieldKey(keyType valueType, encName string) { - - if keyType == valueTypeString { - e.e.EncodeString(encName) - } else if keyType == valueTypeInt { - e.e.EncodeInt(must.Int(strconv.ParseInt(encName, 10, 64))) - } else if keyType == valueTypeUint { - e.e.EncodeUint(must.Uint(strconv.ParseUint(encName, 10, 64))) - } else if keyType == valueTypeFloat { - e.e.EncodeFloat64(must.Float(strconv.ParseFloat(encName, 64))) - } else { - halt.errorStr2("invalid struct key type: ", keyType.String()) - } - -} - -func (e *encoderBincIO) kStructSimple(f *encFnInfo, rv reflect.Value) { - _ = e.e - tisfi := f.ti.sfi.source() - - chkCirRef := e.h.CheckCircularRef - var si *structFieldInfo - var j int - - if f.ti.toArray || e.h.StructToArray { - if len(tisfi) == 0 { - e.e.WriteArrayEmpty() - return - } - e.arrayStart(len(tisfi)) - for j, si = range tisfi { - e.c = containerArrayElem - e.e.WriteArrayElem(j == 0) - if si.encBuiltin { - e.encodeIB(rv2i(si.fieldNoAlloc(rv, true))) - } else { - e.encodeValue(si.fieldNoAlloc(rv, !chkCirRef), nil) - } - } - e.c = 0 - e.e.WriteArrayEnd() - } else { - if len(tisfi) == 0 { - e.e.WriteMapEmpty() - return - } - if e.h.Canonical { - tisfi = f.ti.sfi.sorted() - } - e.mapStart(len(tisfi)) - for j, si = range tisfi { - e.c = containerMapKey - e.e.WriteMapElemKey(j == 0) - e.e.EncodeStringNoEscape4Json(si.encName) - e.mapElemValue() - if si.encBuiltin { - e.encodeIB(rv2i(si.fieldNoAlloc(rv, true))) - } else { - e.encodeValue(si.fieldNoAlloc(rv, !chkCirRef), nil) - } - } - e.c = 0 - e.e.WriteMapEnd() - } -} - -func (e *encoderBincIO) kStruct(f *encFnInfo, rv reflect.Value) { - _ = e.e - ti := f.ti - toMap := !(ti.toArray || e.h.StructToArray) - var mf map[string]interface{} - if ti.flagMissingFielder { - toMap = true - mf = rv2i(rv).(MissingFielder).CodecMissingFields() - } else if ti.flagMissingFielderPtr { - toMap = true - if rv.CanAddr() { - mf = rv2i(rvAddr(rv, ti.ptr)).(MissingFielder).CodecMissingFields() - } else { - mf = rv2i(e.addrRV(rv, ti.rt, ti.ptr)).(MissingFielder).CodecMissingFields() - } - } - newlen := len(mf) - tisfi := ti.sfi.source() - newlen += len(tisfi) - - var fkvs = e.slist.get(newlen)[:newlen] - - recur := e.h.RecursiveEmptyCheck - chkCirRef := e.h.CheckCircularRef - - var xlen int - - var kv sfiRv - var j int - var sf encStructFieldObj - if toMap { - newlen = 0 - if e.h.Canonical { - tisfi = f.ti.sfi.sorted() - } - for _, si := range tisfi { - - if si.omitEmpty { - kv.r = si.fieldNoAlloc(rv, false) - if isEmptyValue(kv.r, e.h.TypeInfos, recur) { - continue - } - } else { - kv.r = si.fieldNoAlloc(rv, si.encBuiltin || !chkCirRef) - } - kv.v = si - fkvs[newlen] = kv - newlen++ - } - - var mf2s []stringIntf - if len(mf) != 0 { - mf2s = make([]stringIntf, 0, len(mf)) - for k, v := range mf { - if k == "" { - continue - } - if ti.infoFieldOmitempty && isEmptyValue(reflect.ValueOf(v), e.h.TypeInfos, recur) { - continue - } - mf2s = append(mf2s, stringIntf{k, v}) - } - } - - xlen = newlen + len(mf2s) - if xlen == 0 { - e.e.WriteMapEmpty() - goto END - } - - e.mapStart(xlen) - - if len(mf2s) != 0 && e.h.Canonical { - mf2w := make([]encStructFieldObj, newlen+len(mf2s)) - for j = 0; j < newlen; j++ { - kv = fkvs[j] - mf2w[j] = encStructFieldObj{kv.v.encName, kv.r, nil, true, - !kv.v.encNameEscape4Json, kv.v.encBuiltin} - } - for _, v := range mf2s { - mf2w[j] = encStructFieldObj{v.v, reflect.Value{}, v.i, false, false, false} - j++ - } - sort.Sort((encStructFieldObjSlice)(mf2w)) - for j, sf = range mf2w { - e.c = containerMapKey - e.e.WriteMapElemKey(j == 0) - if ti.keyType == valueTypeString && sf.noEsc4json { - e.e.EncodeStringNoEscape4Json(sf.key) - } else { - e.kStructFieldKey(ti.keyType, sf.key) - } - e.mapElemValue() - if sf.isRv { - if sf.builtin { - e.encodeIB(rv2i(baseRVRV(sf.rv))) - } else { - e.encodeValue(sf.rv, nil) - } - } else { - if !e.encodeBuiltin(sf.intf) { - e.encodeR(reflect.ValueOf(sf.intf)) - } - - } - } - } else { - keytyp := ti.keyType - for j = 0; j < newlen; j++ { - kv = fkvs[j] - e.c = containerMapKey - e.e.WriteMapElemKey(j == 0) - if ti.keyType == valueTypeString && !kv.v.encNameEscape4Json { - e.e.EncodeStringNoEscape4Json(kv.v.encName) - } else { - e.kStructFieldKey(keytyp, kv.v.encName) - } - e.mapElemValue() - if kv.v.encBuiltin { - e.encodeIB(rv2i(baseRVRV(kv.r))) - } else { - e.encodeValue(kv.r, nil) - } - } - for _, v := range mf2s { - e.c = containerMapKey - e.e.WriteMapElemKey(j == 0) - e.kStructFieldKey(keytyp, v.v) - e.mapElemValue() - if !e.encodeBuiltin(v.i) { - e.encodeR(reflect.ValueOf(v.i)) - } - - j++ - } - } - - e.c = 0 - e.e.WriteMapEnd() - } else { - newlen = len(tisfi) - for i, si := range tisfi { - - if si.omitEmpty { - - kv.r = si.fieldNoAlloc(rv, false) - if isEmptyContainerValue(kv.r, e.h.TypeInfos, recur) { - kv.r = reflect.Value{} - } - } else { - kv.r = si.fieldNoAlloc(rv, si.encBuiltin || !chkCirRef) - } - kv.v = si - fkvs[i] = kv - } - - if newlen == 0 { - e.e.WriteArrayEmpty() - goto END - } - - e.arrayStart(newlen) - for j = 0; j < newlen; j++ { - e.c = containerArrayElem - e.e.WriteArrayElem(j == 0) - kv = fkvs[j] - if !kv.r.IsValid() { - e.e.EncodeNil() - } else if kv.v.encBuiltin { - e.encodeIB(rv2i(baseRVRV(kv.r))) - } else { - e.encodeValue(kv.r, nil) - } - } - e.c = 0 - e.e.WriteArrayEnd() - } - -END: - - e.slist.put(fkvs) -} - -func (e *encoderBincIO) kMap(f *encFnInfo, rv reflect.Value) { - _ = e.e - l := rvLenMap(rv) - if l == 0 { - e.e.WriteMapEmpty() - return - } - e.mapStart(l) - - var keyFn, valFn *encFnBincIO - - ktypeKind := reflect.Kind(f.ti.keykind) - vtypeKind := reflect.Kind(f.ti.elemkind) - - rtval := f.ti.elem - rtvalkind := vtypeKind - for rtvalkind == reflect.Ptr { - rtval = rtval.Elem() - rtvalkind = rtval.Kind() - } - if rtvalkind != reflect.Interface { - valFn = e.fn(rtval) - } - - var rvv = mapAddrLoopvarRV(f.ti.elem, vtypeKind) - - rtkey := f.ti.key - var keyTypeIsString = stringTypId == rt2id(rtkey) - if keyTypeIsString { - keyFn = e.fn(rtkey) - } else { - for rtkey.Kind() == reflect.Ptr { - rtkey = rtkey.Elem() - } - if rtkey.Kind() != reflect.Interface { - keyFn = e.fn(rtkey) - } - } - - if e.h.Canonical { - e.kMapCanonical(f.ti, rv, rvv, keyFn, valFn) - e.c = 0 - e.e.WriteMapEnd() - return - } - - var rvk = mapAddrLoopvarRV(f.ti.key, ktypeKind) - - var it mapIter - mapRange(&it, rv, rvk, rvv, true) - - kbuiltin := f.ti.tikey.flagEncBuiltin - vbuiltin := f.ti.tielem.flagEncBuiltin - for j := 0; it.Next(); j++ { - rv = it.Key() - e.c = containerMapKey - e.e.WriteMapElemKey(j == 0) - if keyTypeIsString { - e.e.EncodeString(rvGetString(rv)) - } else if kbuiltin { - e.encodeIB(rv2i(baseRVRV(rv))) - } else { - e.encodeValue(rv, keyFn) - } - e.mapElemValue() - rv = it.Value() - if vbuiltin { - e.encodeIB(rv2i(baseRVRV(rv))) - } else { - e.encodeValue(it.Value(), valFn) - } - } - it.Done() - - e.c = 0 - e.e.WriteMapEnd() -} - -func (e *encoderBincIO) kMapCanonical(ti *typeInfo, rv, rvv reflect.Value, keyFn, valFn *encFnBincIO) { - _ = e.e - - rtkey := ti.key - rtkeydecl := rtkey.PkgPath() == "" && rtkey.Name() != "" - - mks := rv.MapKeys() - rtkeyKind := rtkey.Kind() - mparams := getMapReqParams(ti) - - switch rtkeyKind { - case reflect.Bool: - - if len(mks) == 2 && mks[0].Bool() { - mks[0], mks[1] = mks[1], mks[0] - } - for i := range mks { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - if rtkeydecl { - e.e.EncodeBool(mks[i].Bool()) - } else { - e.encodeValueNonNil(mks[i], keyFn) - } - e.mapElemValue() - e.encodeValue(mapGet(rv, mks[i], rvv, mparams), valFn) - } - case reflect.String: - mksv := make([]orderedRv[string], len(mks)) - for i, k := range mks { - v := &mksv[i] - v.r = k - v.v = rvGetString(k) - } - slices.SortFunc(mksv, cmpOrderedRv) - for i := range mksv { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - if rtkeydecl { - e.e.EncodeString(mksv[i].v) - } else { - e.encodeValueNonNil(mksv[i].r, keyFn) - } - e.mapElemValue() - e.encodeValue(mapGet(rv, mksv[i].r, rvv, mparams), valFn) - } - case reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64, reflect.Uint, reflect.Uintptr: - mksv := make([]orderedRv[uint64], len(mks)) - for i, k := range mks { - v := &mksv[i] - v.r = k - v.v = k.Uint() - } - slices.SortFunc(mksv, cmpOrderedRv) - for i := range mksv { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - if rtkeydecl { - e.e.EncodeUint(mksv[i].v) - } else { - e.encodeValueNonNil(mksv[i].r, keyFn) - } - e.mapElemValue() - e.encodeValue(mapGet(rv, mksv[i].r, rvv, mparams), valFn) - } - case reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64, reflect.Int: - mksv := make([]orderedRv[int64], len(mks)) - for i, k := range mks { - v := &mksv[i] - v.r = k - v.v = k.Int() - } - slices.SortFunc(mksv, cmpOrderedRv) - for i := range mksv { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - if rtkeydecl { - e.e.EncodeInt(mksv[i].v) - } else { - e.encodeValueNonNil(mksv[i].r, keyFn) - } - e.mapElemValue() - e.encodeValue(mapGet(rv, mksv[i].r, rvv, mparams), valFn) - } - case reflect.Float32: - mksv := make([]orderedRv[float64], len(mks)) - for i, k := range mks { - v := &mksv[i] - v.r = k - v.v = k.Float() - } - slices.SortFunc(mksv, cmpOrderedRv) - for i := range mksv { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - if rtkeydecl { - e.e.EncodeFloat32(float32(mksv[i].v)) - } else { - e.encodeValueNonNil(mksv[i].r, keyFn) - } - e.mapElemValue() - e.encodeValue(mapGet(rv, mksv[i].r, rvv, mparams), valFn) - } - case reflect.Float64: - mksv := make([]orderedRv[float64], len(mks)) - for i, k := range mks { - v := &mksv[i] - v.r = k - v.v = k.Float() - } - slices.SortFunc(mksv, cmpOrderedRv) - for i := range mksv { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - if rtkeydecl { - e.e.EncodeFloat64(mksv[i].v) - } else { - e.encodeValueNonNil(mksv[i].r, keyFn) - } - e.mapElemValue() - e.encodeValue(mapGet(rv, mksv[i].r, rvv, mparams), valFn) - } - default: - if rtkey == timeTyp { - mksv := make([]timeRv, len(mks)) - for i, k := range mks { - v := &mksv[i] - v.r = k - v.v = rv2i(k).(time.Time) - } - slices.SortFunc(mksv, cmpTimeRv) - for i := range mksv { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeTime(mksv[i].v) - e.mapElemValue() - e.encodeValue(mapGet(rv, mksv[i].r, rvv, mparams), valFn) - } - break - } - - bs0 := e.blist.get(len(mks) * 16) - mksv := bs0 - mksbv := make([]bytesRv, len(mks)) - - sideEncode(e.hh, &e.h.sideEncPool, func(se encoderI) { - se.ResetBytes(&mksv) - for i, k := range mks { - v := &mksbv[i] - l := len(mksv) - se.setContainerState(containerMapKey) - se.encodeR(baseRVRV(k)) - se.atEndOfEncode() - se.writerEnd() - v.r = k - v.v = mksv[l:] - } - }) - - slices.SortFunc(mksbv, cmpBytesRv) - for j := range mksbv { - e.c = containerMapKey - e.e.WriteMapElemKey(j == 0) - e.e.writeBytesAsis(mksbv[j].v) - e.mapElemValue() - e.encodeValue(mapGet(rv, mksbv[j].r, rvv, mparams), valFn) - } - e.blist.put(mksv) - if !byteSliceSameData(bs0, mksv) { - e.blist.put(bs0) - } - } -} - -func (e *encoderBincIO) init(h Handle) { - initHandle(h) - callMake(&e.e) - e.hh = h - e.h = h.getBasicHandle() - - e.err = errEncoderNotInitialized - - e.fp = e.e.init(h, &e.encoderBase, e).(*fastpathEsBincIO) - - if e.bytes { - e.rtidFn = &e.h.rtidFnsEncBytes - e.rtidFnNoExt = &e.h.rtidFnsEncNoExtBytes - } else { - e.rtidFn = &e.h.rtidFnsEncIO - e.rtidFnNoExt = &e.h.rtidFnsEncNoExtIO - } - - e.reset() -} - -func (e *encoderBincIO) reset() { - e.e.reset() - if e.ci != nil { - e.ci = e.ci[:0] - } - e.c = 0 - e.calls = 0 - e.seq = 0 - e.err = nil -} - -func (e *encoderBincIO) Encode(v interface{}) (err error) { - - defer panicValToErr(e, callRecoverSentinel, &e.err, &err, debugging) - e.mustEncode(v) - return -} - -func (e *encoderBincIO) MustEncode(v interface{}) { - defer panicValToErr(e, callRecoverSentinel, &e.err, nil, true) - e.mustEncode(v) - return -} - -func (e *encoderBincIO) mustEncode(v interface{}) { - halt.onerror(e.err) - if e.hh == nil { - halt.onerror(errNoFormatHandle) - } - - e.calls++ - if !e.encodeBuiltin(v) { - e.encodeR(reflect.ValueOf(v)) - } - - e.calls-- - if e.calls == 0 { - e.e.atEndOfEncode() - e.e.writerEnd() - } -} - -func (e *encoderBincIO) encodeI(iv interface{}) { - if !e.encodeBuiltin(iv) { - e.encodeR(reflect.ValueOf(iv)) - } -} - -func (e *encoderBincIO) encodeIB(iv interface{}) { - if !e.encodeBuiltin(iv) { - - halt.errorStr("[should not happen] invalid type passed to encodeBuiltin") - } -} - -func (e *encoderBincIO) encodeR(base reflect.Value) { - e.encodeValue(base, nil) -} - -func (e *encoderBincIO) encodeBuiltin(iv interface{}) (ok bool) { - ok = true - switch v := iv.(type) { - case nil: - e.e.EncodeNil() - - case Raw: - e.rawBytes(v) - case string: - e.e.EncodeString(v) - case bool: - e.e.EncodeBool(v) - case int: - e.e.EncodeInt(int64(v)) - case int8: - e.e.EncodeInt(int64(v)) - case int16: - e.e.EncodeInt(int64(v)) - case int32: - e.e.EncodeInt(int64(v)) - case int64: - e.e.EncodeInt(v) - case uint: - e.e.EncodeUint(uint64(v)) - case uint8: - e.e.EncodeUint(uint64(v)) - case uint16: - e.e.EncodeUint(uint64(v)) - case uint32: - e.e.EncodeUint(uint64(v)) - case uint64: - e.e.EncodeUint(v) - case uintptr: - e.e.EncodeUint(uint64(v)) - case float32: - e.e.EncodeFloat32(v) - case float64: - e.e.EncodeFloat64(v) - case complex64: - e.encodeComplex64(v) - case complex128: - e.encodeComplex128(v) - case time.Time: - e.e.EncodeTime(v) - case []byte: - e.e.EncodeBytes(v) - default: - - ok = !skipFastpathTypeSwitchInDirectCall && e.dh.fastpathEncodeTypeSwitch(iv, e) - } - return -} - -func (e *encoderBincIO) encodeValue(rv reflect.Value, fn *encFnBincIO) { - - var ciPushes int - - var rvp reflect.Value - var rvpValid bool - -RV: - switch rv.Kind() { - case reflect.Ptr: - if rvIsNil(rv) { - e.e.EncodeNil() - goto END - } - rvpValid = true - rvp = rv - rv = rv.Elem() - - if e.h.CheckCircularRef && e.ci.canPushElemKind(rv.Kind()) { - e.ci.push(rv2i(rvp)) - ciPushes++ - } - goto RV - case reflect.Interface: - if rvIsNil(rv) { - e.e.EncodeNil() - goto END - } - rvpValid = false - rvp = reflect.Value{} - rv = rv.Elem() - fn = nil - goto RV - case reflect.Map: - if rvIsNil(rv) { - if e.h.NilCollectionToZeroLength { - e.e.WriteMapEmpty() - } else { - e.e.EncodeNil() - } - goto END - } - case reflect.Slice, reflect.Chan: - if rvIsNil(rv) { - if e.h.NilCollectionToZeroLength { - e.e.WriteArrayEmpty() - } else { - e.e.EncodeNil() - } - goto END - } - case reflect.Invalid, reflect.Func: - e.e.EncodeNil() - goto END - } - - if fn == nil { - fn = e.fn(rv.Type()) - } - - if !fn.i.addrE { - - } else if rvpValid { - rv = rvp - } else if rv.CanAddr() { - rv = rvAddr(rv, fn.i.ti.ptr) - } else { - rv = e.addrRV(rv, fn.i.ti.rt, fn.i.ti.ptr) - } - fn.fe(e, &fn.i, rv) - -END: - if ciPushes > 0 { - e.ci.pop(ciPushes) - } -} - -func (e *encoderBincIO) encodeValueNonNil(rv reflect.Value, fn *encFnBincIO) { - - if fn.i.addrE { - if rv.CanAddr() { - rv = rvAddr(rv, fn.i.ti.ptr) - } else { - rv = e.addrRV(rv, fn.i.ti.rt, fn.i.ti.ptr) - } - } - fn.fe(e, &fn.i, rv) -} - -func (e *encoderBincIO) encodeAs(v interface{}, t reflect.Type, ext bool) { - if ext { - e.encodeValue(baseRV(v), e.fn(t)) - } else { - e.encodeValue(baseRV(v), e.fnNoExt(t)) - } -} - -func (e *encoderBincIO) marshalUtf8(bs []byte, fnerr error) { - halt.onerror(fnerr) - if bs == nil { - e.e.EncodeNil() - } else { - e.e.EncodeString(stringView(bs)) - } -} - -func (e *encoderBincIO) marshalAsis(bs []byte, fnerr error) { - halt.onerror(fnerr) - if bs == nil { - e.e.EncodeNil() - } else { - e.e.writeBytesAsis(bs) - } -} - -func (e *encoderBincIO) marshalRaw(bs []byte, fnerr error) { - halt.onerror(fnerr) - e.e.EncodeBytes(bs) -} - -func (e *encoderBincIO) rawBytes(vv Raw) { - v := []byte(vv) - if !e.h.Raw { - halt.errorBytes("Raw values cannot be encoded: ", v) - } - e.e.writeBytesAsis(v) -} - -func (e *encoderBincIO) fn(t reflect.Type) *encFnBincIO { - return e.dh.encFnViaBH(t, e.rtidFn, e.h, e.fp, false) -} - -func (e *encoderBincIO) fnNoExt(t reflect.Type) *encFnBincIO { - return e.dh.encFnViaBH(t, e.rtidFnNoExt, e.h, e.fp, true) -} - -func (e *encoderBincIO) mapStart(length int) { - e.e.WriteMapStart(length) - e.c = containerMapStart -} - -func (e *encoderBincIO) mapElemValue() { - e.e.WriteMapElemValue() - e.c = containerMapValue -} - -func (e *encoderBincIO) arrayStart(length int) { - e.e.WriteArrayStart(length) - e.c = containerArrayStart -} - -func (e *encoderBincIO) writerEnd() { - e.e.writerEnd() -} - -func (e *encoderBincIO) atEndOfEncode() { - e.e.atEndOfEncode() -} - -func (e *encoderBincIO) Reset(w io.Writer) { - if e.bytes { - halt.onerror(errEncNoResetBytesWithWriter) - } - e.reset() - if w == nil { - w = io.Discard - } - e.e.resetOutIO(w) -} - -func (e *encoderBincIO) ResetBytes(out *[]byte) { - if !e.bytes { - halt.onerror(errEncNoResetWriterWithBytes) - } - e.resetBytes(out) -} - -func (e *encoderBincIO) resetBytes(out *[]byte) { - e.reset() - if out == nil { - out = &bytesEncAppenderDefOut - } - e.e.resetOutBytes(out) -} - -func (helperEncDriverBincIO) newEncoderBytes(out *[]byte, h Handle) *encoderBincIO { - var c1 encoderBincIO - c1.bytes = true - c1.init(h) - c1.ResetBytes(out) - return &c1 -} - -func (helperEncDriverBincIO) newEncoderIO(out io.Writer, h Handle) *encoderBincIO { - var c1 encoderBincIO - c1.bytes = false - c1.init(h) - c1.Reset(out) - return &c1 -} - -func (helperEncDriverBincIO) encFnloadFastpathUnderlying(ti *typeInfo, fp *fastpathEsBincIO) (f *fastpathEBincIO, u reflect.Type) { - rtid := rt2id(ti.fastpathUnderlying) - idx, ok := fastpathAvIndex(rtid) - if !ok { - return - } - f = &fp[idx] - if uint8(reflect.Array) == ti.kind { - u = reflect.ArrayOf(ti.rt.Len(), ti.elem) - } else { - u = f.rt - } - return -} - -func (helperEncDriverBincIO) encFindRtidFn(s []encRtidFnBincIO, rtid uintptr) (i uint, fn *encFnBincIO) { - - var h uint - var j = uint(len(s)) -LOOP: - if i < j { - h = (i + j) >> 1 - if s[h].rtid < rtid { - i = h + 1 - } else { - j = h - } - goto LOOP - } - if i < uint(len(s)) && s[i].rtid == rtid { - fn = s[i].fn - } - return -} - -func (helperEncDriverBincIO) encFromRtidFnSlice(fns *atomicRtidFnSlice) (s []encRtidFnBincIO) { - if v := fns.load(); v != nil { - s = *(lowLevelToPtr[[]encRtidFnBincIO](v)) - } - return -} - -func (dh helperEncDriverBincIO) encFnViaBH(rt reflect.Type, fns *atomicRtidFnSlice, - x *BasicHandle, fp *fastpathEsBincIO, checkExt bool) (fn *encFnBincIO) { - return dh.encFnVia(rt, fns, x.typeInfos(), &x.mu, x.extHandle, fp, - checkExt, x.CheckCircularRef, x.timeBuiltin, x.binaryHandle, x.jsonHandle) -} - -func (dh helperEncDriverBincIO) encFnVia(rt reflect.Type, fns *atomicRtidFnSlice, - tinfos *TypeInfos, mu *sync.Mutex, exth extHandle, fp *fastpathEsBincIO, - checkExt, checkCircularRef, timeBuiltin, binaryEncoding, json bool) (fn *encFnBincIO) { - rtid := rt2id(rt) - var sp []encRtidFnBincIO = dh.encFromRtidFnSlice(fns) - if sp != nil { - _, fn = dh.encFindRtidFn(sp, rtid) - } - if fn == nil { - fn = dh.encFnViaLoader(rt, rtid, fns, tinfos, mu, exth, fp, checkExt, checkCircularRef, timeBuiltin, binaryEncoding, json) - } - return -} - -func (dh helperEncDriverBincIO) encFnViaLoader(rt reflect.Type, rtid uintptr, fns *atomicRtidFnSlice, - tinfos *TypeInfos, mu *sync.Mutex, exth extHandle, fp *fastpathEsBincIO, - checkExt, checkCircularRef, timeBuiltin, binaryEncoding, json bool) (fn *encFnBincIO) { - - fn = dh.encFnLoad(rt, rtid, tinfos, exth, fp, checkExt, checkCircularRef, timeBuiltin, binaryEncoding, json) - var sp []encRtidFnBincIO - mu.Lock() - sp = dh.encFromRtidFnSlice(fns) - - if sp == nil { - sp = []encRtidFnBincIO{{rtid, fn}} - fns.store(ptrToLowLevel(&sp)) - } else { - idx, fn2 := dh.encFindRtidFn(sp, rtid) - if fn2 == nil { - sp2 := make([]encRtidFnBincIO, len(sp)+1) - copy(sp2[idx+1:], sp[idx:]) - copy(sp2, sp[:idx]) - sp2[idx] = encRtidFnBincIO{rtid, fn} - fns.store(ptrToLowLevel(&sp2)) - } - } - mu.Unlock() - return -} - -func (dh helperEncDriverBincIO) encFnLoad(rt reflect.Type, rtid uintptr, tinfos *TypeInfos, - exth extHandle, fp *fastpathEsBincIO, - checkExt, checkCircularRef, timeBuiltin, binaryEncoding, json bool) (fn *encFnBincIO) { - fn = new(encFnBincIO) - fi := &(fn.i) - ti := tinfos.get(rtid, rt) - fi.ti = ti - rk := reflect.Kind(ti.kind) - - if rtid == timeTypId && timeBuiltin { - fn.fe = (*encoderBincIO).kTime - } else if rtid == rawTypId { - fn.fe = (*encoderBincIO).raw - } else if rtid == rawExtTypId { - fn.fe = (*encoderBincIO).rawExt - fi.addrE = true - } else if xfFn := exth.getExt(rtid, checkExt); xfFn != nil { - fi.xfTag, fi.xfFn = xfFn.tag, xfFn.ext - fn.fe = (*encoderBincIO).ext - if rk == reflect.Struct || rk == reflect.Array { - fi.addrE = true - } - } else if ti.flagSelfer || ti.flagSelferPtr { - fn.fe = (*encoderBincIO).selferMarshal - fi.addrE = ti.flagSelferPtr - } else if supportMarshalInterfaces && binaryEncoding && - (ti.flagBinaryMarshaler || ti.flagBinaryMarshalerPtr) && - (ti.flagBinaryUnmarshaler || ti.flagBinaryUnmarshalerPtr) { - fn.fe = (*encoderBincIO).binaryMarshal - fi.addrE = ti.flagBinaryMarshalerPtr - } else if supportMarshalInterfaces && !binaryEncoding && json && - (ti.flagJsonMarshaler || ti.flagJsonMarshalerPtr) && - (ti.flagJsonUnmarshaler || ti.flagJsonUnmarshalerPtr) { - - fn.fe = (*encoderBincIO).jsonMarshal - fi.addrE = ti.flagJsonMarshalerPtr - } else if supportMarshalInterfaces && !binaryEncoding && - (ti.flagTextMarshaler || ti.flagTextMarshalerPtr) && - (ti.flagTextUnmarshaler || ti.flagTextUnmarshalerPtr) { - fn.fe = (*encoderBincIO).textMarshal - fi.addrE = ti.flagTextMarshalerPtr - } else { - if fastpathEnabled && (rk == reflect.Map || rk == reflect.Slice || rk == reflect.Array) { - - var rtid2 uintptr - if !ti.flagHasPkgPath { - rtid2 = rtid - if rk == reflect.Array { - rtid2 = rt2id(ti.key) - } - if idx, ok := fastpathAvIndex(rtid2); ok { - fn.fe = fp[idx].encfn - } - } else { - - xfe, xrt := dh.encFnloadFastpathUnderlying(ti, fp) - if xfe != nil { - xfnf := xfe.encfn - fn.fe = func(e *encoderBincIO, xf *encFnInfo, xrv reflect.Value) { - xfnf(e, xf, rvConvert(xrv, xrt)) - } - } - } - } - if fn.fe == nil { - switch rk { - case reflect.Bool: - fn.fe = (*encoderBincIO).kBool - case reflect.String: - - fn.fe = (*encoderBincIO).kString - case reflect.Int: - fn.fe = (*encoderBincIO).kInt - case reflect.Int8: - fn.fe = (*encoderBincIO).kInt8 - case reflect.Int16: - fn.fe = (*encoderBincIO).kInt16 - case reflect.Int32: - fn.fe = (*encoderBincIO).kInt32 - case reflect.Int64: - fn.fe = (*encoderBincIO).kInt64 - case reflect.Uint: - fn.fe = (*encoderBincIO).kUint - case reflect.Uint8: - fn.fe = (*encoderBincIO).kUint8 - case reflect.Uint16: - fn.fe = (*encoderBincIO).kUint16 - case reflect.Uint32: - fn.fe = (*encoderBincIO).kUint32 - case reflect.Uint64: - fn.fe = (*encoderBincIO).kUint64 - case reflect.Uintptr: - fn.fe = (*encoderBincIO).kUintptr - case reflect.Float32: - fn.fe = (*encoderBincIO).kFloat32 - case reflect.Float64: - fn.fe = (*encoderBincIO).kFloat64 - case reflect.Complex64: - fn.fe = (*encoderBincIO).kComplex64 - case reflect.Complex128: - fn.fe = (*encoderBincIO).kComplex128 - case reflect.Chan: - fn.fe = (*encoderBincIO).kChan - case reflect.Slice: - fn.fe = (*encoderBincIO).kSlice - case reflect.Array: - fn.fe = (*encoderBincIO).kArray - case reflect.Struct: - if ti.simple { - fn.fe = (*encoderBincIO).kStructSimple - } else { - fn.fe = (*encoderBincIO).kStruct - } - case reflect.Map: - fn.fe = (*encoderBincIO).kMap - case reflect.Interface: - - fn.fe = (*encoderBincIO).kErr - default: - - fn.fe = (*encoderBincIO).kErr - } - } - } - return -} -func (d *decoderBincIO) rawExt(f *decFnInfo, rv reflect.Value) { - d.d.DecodeRawExt(rv2i(rv).(*RawExt)) -} - -func (d *decoderBincIO) ext(f *decFnInfo, rv reflect.Value) { - d.d.DecodeExt(rv2i(rv), f.ti.rt, f.xfTag, f.xfFn) -} - -func (d *decoderBincIO) selferUnmarshal(_ *decFnInfo, rv reflect.Value) { - rv2i(rv).(Selfer).CodecDecodeSelf(&Decoder{d}) -} - -func (d *decoderBincIO) binaryUnmarshal(_ *decFnInfo, rv reflect.Value) { - bm := rv2i(rv).(encoding.BinaryUnmarshaler) - xbs, _ := d.d.DecodeBytes() - fnerr := bm.UnmarshalBinary(xbs) - halt.onerror(fnerr) -} - -func (d *decoderBincIO) textUnmarshal(_ *decFnInfo, rv reflect.Value) { - tm := rv2i(rv).(encoding.TextUnmarshaler) - fnerr := tm.UnmarshalText(bytesOKs(d.d.DecodeStringAsBytes())) - halt.onerror(fnerr) -} - -func (d *decoderBincIO) jsonUnmarshal(_ *decFnInfo, rv reflect.Value) { - d.jsonUnmarshalV(rv2i(rv).(jsonUnmarshaler)) -} - -func (d *decoderBincIO) jsonUnmarshalV(tm jsonUnmarshaler) { - - halt.onerror(tm.UnmarshalJSON(d.d.nextValueBytes())) -} - -func (d *decoderBincIO) kErr(_ *decFnInfo, rv reflect.Value) { - halt.errorf("unsupported decoding kind: %s, for %#v", rv.Kind(), rv) - -} - -func (d *decoderBincIO) raw(_ *decFnInfo, rv reflect.Value) { - rvSetBytes(rv, d.rawBytes()) -} - -func (d *decoderBincIO) kString(_ *decFnInfo, rv reflect.Value) { - rvSetString(rv, d.detach2Str(d.d.DecodeStringAsBytes())) -} - -func (d *decoderBincIO) kBool(_ *decFnInfo, rv reflect.Value) { - rvSetBool(rv, d.d.DecodeBool()) -} - -func (d *decoderBincIO) kTime(_ *decFnInfo, rv reflect.Value) { - rvSetTime(rv, d.d.DecodeTime()) -} - -func (d *decoderBincIO) kFloat32(_ *decFnInfo, rv reflect.Value) { - rvSetFloat32(rv, d.d.DecodeFloat32()) -} - -func (d *decoderBincIO) kFloat64(_ *decFnInfo, rv reflect.Value) { - rvSetFloat64(rv, d.d.DecodeFloat64()) -} - -func (d *decoderBincIO) kComplex64(_ *decFnInfo, rv reflect.Value) { - rvSetComplex64(rv, complex(d.d.DecodeFloat32(), 0)) -} - -func (d *decoderBincIO) kComplex128(_ *decFnInfo, rv reflect.Value) { - rvSetComplex128(rv, complex(d.d.DecodeFloat64(), 0)) -} - -func (d *decoderBincIO) kInt(_ *decFnInfo, rv reflect.Value) { - rvSetInt(rv, int(chkOvf.IntV(d.d.DecodeInt64(), intBitsize))) -} - -func (d *decoderBincIO) kInt8(_ *decFnInfo, rv reflect.Value) { - rvSetInt8(rv, int8(chkOvf.IntV(d.d.DecodeInt64(), 8))) -} - -func (d *decoderBincIO) kInt16(_ *decFnInfo, rv reflect.Value) { - rvSetInt16(rv, int16(chkOvf.IntV(d.d.DecodeInt64(), 16))) -} - -func (d *decoderBincIO) kInt32(_ *decFnInfo, rv reflect.Value) { - rvSetInt32(rv, int32(chkOvf.IntV(d.d.DecodeInt64(), 32))) -} - -func (d *decoderBincIO) kInt64(_ *decFnInfo, rv reflect.Value) { - rvSetInt64(rv, d.d.DecodeInt64()) -} - -func (d *decoderBincIO) kUint(_ *decFnInfo, rv reflect.Value) { - rvSetUint(rv, uint(chkOvf.UintV(d.d.DecodeUint64(), uintBitsize))) -} - -func (d *decoderBincIO) kUintptr(_ *decFnInfo, rv reflect.Value) { - rvSetUintptr(rv, uintptr(chkOvf.UintV(d.d.DecodeUint64(), uintBitsize))) -} - -func (d *decoderBincIO) kUint8(_ *decFnInfo, rv reflect.Value) { - rvSetUint8(rv, uint8(chkOvf.UintV(d.d.DecodeUint64(), 8))) -} - -func (d *decoderBincIO) kUint16(_ *decFnInfo, rv reflect.Value) { - rvSetUint16(rv, uint16(chkOvf.UintV(d.d.DecodeUint64(), 16))) -} - -func (d *decoderBincIO) kUint32(_ *decFnInfo, rv reflect.Value) { - rvSetUint32(rv, uint32(chkOvf.UintV(d.d.DecodeUint64(), 32))) -} - -func (d *decoderBincIO) kUint64(_ *decFnInfo, rv reflect.Value) { - rvSetUint64(rv, d.d.DecodeUint64()) -} - -func (d *decoderBincIO) kInterfaceNaked(f *decFnInfo) (rvn reflect.Value) { - - n := d.naked() - d.d.DecodeNaked() - - if decFailNonEmptyIntf && f.ti.numMeth > 0 { - halt.errorf("cannot decode non-nil codec value into nil %v (%v methods)", f.ti.rt, f.ti.numMeth) - } - - switch n.v { - case valueTypeMap: - mtid := d.mtid - if mtid == 0 { - if d.jsms { - mtid = mapStrIntfTypId - } else { - mtid = mapIntfIntfTypId - } - } - if mtid == mapStrIntfTypId { - var v2 map[string]interface{} - d.decode(&v2) - rvn = rv4iptr(&v2).Elem() - } else if mtid == mapIntfIntfTypId { - var v2 map[interface{}]interface{} - d.decode(&v2) - rvn = rv4iptr(&v2).Elem() - } else if d.mtr { - rvn = reflect.New(d.h.MapType) - d.decode(rv2i(rvn)) - rvn = rvn.Elem() - } else { - - rvn = rvZeroAddrK(d.h.MapType, reflect.Map) - d.decodeValue(rvn, nil) - } - case valueTypeArray: - if d.stid == 0 || d.stid == intfSliceTypId { - var v2 []interface{} - d.decode(&v2) - rvn = rv4iptr(&v2).Elem() - } else if d.str { - rvn = reflect.New(d.h.SliceType) - d.decode(rv2i(rvn)) - rvn = rvn.Elem() - } else { - rvn = rvZeroAddrK(d.h.SliceType, reflect.Slice) - d.decodeValue(rvn, nil) - } - if d.h.PreferArrayOverSlice { - rvn = rvGetArray4Slice(rvn) - } - case valueTypeExt: - tag, bytes := n.u, n.l - bfn := d.h.getExtForTag(tag) - var re = RawExt{Tag: tag} - if bytes == nil { - - if bfn == nil { - d.decode(&re.Value) - rvn = rv4iptr(&re).Elem() - } else if bfn.ext == SelfExt { - rvn = rvZeroAddrK(bfn.rt, bfn.rt.Kind()) - d.decodeValue(rvn, d.fnNoExt(bfn.rt)) - } else { - rvn = reflect.New(bfn.rt) - d.interfaceExtConvertAndDecode(rv2i(rvn), bfn.ext) - rvn = rvn.Elem() - } - } else { - - if bfn == nil { - re.setData(bytes, false) - rvn = rv4iptr(&re).Elem() - } else { - rvn = reflect.New(bfn.rt) - if bfn.ext == SelfExt { - sideDecode(d.hh, &d.h.sideDecPool, func(sd decoderI) { oneOffDecode(sd, rv2i(rvn), bytes, bfn.rt, true) }) - } else { - bfn.ext.ReadExt(rv2i(rvn), bytes) - } - rvn = rvn.Elem() - } - } - - if d.h.PreferPointerForStructOrArray && rvn.CanAddr() { - if rk := rvn.Kind(); rk == reflect.Array || rk == reflect.Struct { - rvn = rvn.Addr() - } - } - case valueTypeNil: - - case valueTypeInt: - rvn = n.ri() - case valueTypeUint: - rvn = n.ru() - case valueTypeFloat: - rvn = n.rf() - case valueTypeBool: - rvn = n.rb() - case valueTypeString, valueTypeSymbol: - rvn = n.rs() - case valueTypeBytes: - rvn = n.rl() - case valueTypeTime: - rvn = n.rt() - default: - halt.errorStr2("kInterfaceNaked: unexpected valueType: ", n.v.String()) - } - return -} - -func (d *decoderBincIO) kInterface(f *decFnInfo, rv reflect.Value) { - - isnilrv := rvIsNil(rv) - - var rvn reflect.Value - - if d.h.InterfaceReset { - - rvn = d.h.intf2impl(f.ti.rtid) - if !rvn.IsValid() { - rvn = d.kInterfaceNaked(f) - if rvn.IsValid() { - rvSetIntf(rv, rvn) - } else if !isnilrv { - decSetNonNilRV2Zero4Intf(rv) - } - return - } - } else if isnilrv { - - rvn = d.h.intf2impl(f.ti.rtid) - if !rvn.IsValid() { - rvn = d.kInterfaceNaked(f) - if rvn.IsValid() { - rvSetIntf(rv, rvn) - } - return - } - } else { - - rvn = rv.Elem() - } - - canDecode, _ := isDecodeable(rvn) - - if !canDecode { - rvn2 := d.oneShotAddrRV(rvn.Type(), rvn.Kind()) - rvSetDirect(rvn2, rvn) - rvn = rvn2 - } - - d.decodeValue(rvn, nil) - rvSetIntf(rv, rvn) -} - -func (d *decoderBincIO) kStructField(si *structFieldInfo, rv reflect.Value) { - if d.d.TryNil() { - rv = si.fieldNoAlloc(rv, true) - if rv.IsValid() { - decSetNonNilRV2Zero(rv) - } - } else if si.decBuiltin { - rv = rvAddr(si.fieldAlloc(rv), si.ptrTyp) - d.decode(rv2i(rv)) - } else { - fn := d.fn(si.baseTyp) - rv = si.fieldAlloc(rv) - if fn.i.addrD { - rv = rvAddr(rv, si.ptrTyp) - } - fn.fd(d, &fn.i, rv) - } -} - -func (d *decoderBincIO) kStructSimple(f *decFnInfo, rv reflect.Value) { - _ = d.d - ctyp := d.d.ContainerType() - ti := f.ti - if ctyp == valueTypeMap { - containerLen := d.mapStart(d.d.ReadMapStart()) - if containerLen == 0 { - d.mapEnd() - return - } - hasLen := containerLen >= 0 - var rvkencname []byte - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - sab, att := d.d.DecodeStringAsBytes() - rvkencname = d.usableStructFieldNameBytes(rvkencname, sab, att) - d.mapElemValue() - if si := ti.siForEncName(rvkencname); si != nil { - d.kStructField(si, rv) - } else { - d.structFieldNotFound(-1, stringView(rvkencname)) - } - } - d.mapEnd() - } else if ctyp == valueTypeArray { - containerLen := d.arrayStart(d.d.ReadArrayStart()) - if containerLen == 0 { - d.arrayEnd() - return - } - - tisfi := ti.sfi.source() - hasLen := containerLen >= 0 - - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.arrayElem(j == 0) - if j < len(tisfi) { - d.kStructField(tisfi[j], rv) - } else { - d.structFieldNotFound(j, "") - } - } - d.arrayEnd() - } else { - halt.onerror(errNeedMapOrArrayDecodeToStruct) - } -} - -func (d *decoderBincIO) kStruct(f *decFnInfo, rv reflect.Value) { - _ = d.d - ctyp := d.d.ContainerType() - ti := f.ti - var mf MissingFielder - if ti.flagMissingFielder { - mf = rv2i(rv).(MissingFielder) - } else if ti.flagMissingFielderPtr { - mf = rv2i(rvAddr(rv, ti.ptr)).(MissingFielder) - } - if ctyp == valueTypeMap { - containerLen := d.mapStart(d.d.ReadMapStart()) - if containerLen == 0 { - d.mapEnd() - return - } - hasLen := containerLen >= 0 - var name2 []byte - var rvkencname []byte - tkt := ti.keyType - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - - if tkt == valueTypeString { - sab, att := d.d.DecodeStringAsBytes() - rvkencname = d.usableStructFieldNameBytes(rvkencname, sab, att) - } else if tkt == valueTypeInt { - rvkencname = strconv.AppendInt(d.b[:0], d.d.DecodeInt64(), 10) - } else if tkt == valueTypeUint { - rvkencname = strconv.AppendUint(d.b[:0], d.d.DecodeUint64(), 10) - } else if tkt == valueTypeFloat { - rvkencname = strconv.AppendFloat(d.b[:0], d.d.DecodeFloat64(), 'f', -1, 64) - } else { - halt.errorStr2("invalid struct key type: ", ti.keyType.String()) - } - - d.mapElemValue() - if si := ti.siForEncName(rvkencname); si != nil { - d.kStructField(si, rv) - } else if mf != nil { - - name2 = append(name2[:0], rvkencname...) - var f interface{} - d.decode(&f) - if !mf.CodecMissingField(name2, f) && d.h.ErrorIfNoField { - halt.errorStr2("no matching struct field when decoding stream map with key: ", stringView(name2)) - } - } else { - d.structFieldNotFound(-1, stringView(rvkencname)) - } - } - d.mapEnd() - } else if ctyp == valueTypeArray { - containerLen := d.arrayStart(d.d.ReadArrayStart()) - if containerLen == 0 { - d.arrayEnd() - return - } - - tisfi := ti.sfi.source() - hasLen := containerLen >= 0 - - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.arrayElem(j == 0) - if j < len(tisfi) { - d.kStructField(tisfi[j], rv) - } else { - d.structFieldNotFound(j, "") - } - } - - d.arrayEnd() - } else { - halt.onerror(errNeedMapOrArrayDecodeToStruct) - } -} - -func (d *decoderBincIO) kSlice(f *decFnInfo, rv reflect.Value) { - _ = d.d - - ti := f.ti - rvCanset := rv.CanSet() - - ctyp := d.d.ContainerType() - if ctyp == valueTypeBytes || ctyp == valueTypeString { - - if !(ti.rtid == uint8SliceTypId || ti.elemkind == uint8(reflect.Uint8)) { - halt.errorf("bytes/string in stream must decode into slice/array of bytes, not %v", ti.rt) - } - rvbs := rvGetBytes(rv) - if rvCanset { - bs2, bst := d.decodeBytesInto(rvbs, false) - if bst != dBytesIntoParamOut { - rvSetBytes(rv, bs2) - } - } else { - - d.decodeBytesInto(rvbs[:len(rvbs):len(rvbs)], true) - } - return - } - - var containerLenS int - isArray := ctyp == valueTypeArray - if isArray { - containerLenS = d.arrayStart(d.d.ReadArrayStart()) - } else if ctyp == valueTypeMap { - containerLenS = d.mapStart(d.d.ReadMapStart()) * 2 - } else { - halt.errorStr2("decoding into a slice, expect map/array - got ", ctyp.String()) - } - - if containerLenS == 0 { - if rvCanset { - if rvIsNil(rv) { - rvSetDirect(rv, rvSliceZeroCap(ti.rt)) - } else { - rvSetSliceLen(rv, 0) - } - } - if isArray { - d.arrayEnd() - } else { - d.mapEnd() - } - return - } - - rtelem0Mut := !scalarBitset.isset(ti.elemkind) - rtelem := ti.elem - - for k := reflect.Kind(ti.elemkind); k == reflect.Ptr; k = rtelem.Kind() { - rtelem = rtelem.Elem() - } - - var fn *decFnBincIO - - var rvChanged bool - - var rv0 = rv - var rv9 reflect.Value - - rvlen := rvLenSlice(rv) - rvcap := rvCapSlice(rv) - maxInitLen := d.maxInitLen() - hasLen := containerLenS >= 0 - if hasLen { - if containerLenS > rvcap { - oldRvlenGtZero := rvlen > 0 - rvlen1 := int(decInferLen(containerLenS, maxInitLen, uint(ti.elemsize))) - if rvlen1 == rvlen { - } else if rvlen1 <= rvcap { - if rvCanset { - rvlen = rvlen1 - rvSetSliceLen(rv, rvlen) - } - } else if rvCanset { - rvlen = rvlen1 - rv, rvCanset = rvMakeSlice(rv, f.ti, rvlen, rvlen) - rvcap = rvlen - rvChanged = !rvCanset - } else { - halt.errorStr("cannot decode into non-settable slice") - } - if rvChanged && oldRvlenGtZero && rtelem0Mut { - rvCopySlice(rv, rv0, rtelem) - } - } else if containerLenS != rvlen { - if rvCanset { - rvlen = containerLenS - rvSetSliceLen(rv, rvlen) - } - } - } - - var elemReset = d.h.SliceElementReset - - var rtelemIsPtr bool - var rtelemElem reflect.Type - builtin := ti.tielem.flagDecBuiltin - if builtin { - rtelemIsPtr = ti.elemkind == uint8(reflect.Ptr) - if rtelemIsPtr { - rtelemElem = ti.elem.Elem() - } - } - - var j int - for ; d.containerNext(j, containerLenS, hasLen); j++ { - if j == 0 { - if rvIsNil(rv) { - if rvCanset { - rvlen = int(decInferLen(containerLenS, maxInitLen, uint(ti.elemsize))) - rv, rvCanset = rvMakeSlice(rv, f.ti, rvlen, rvlen) - rvcap = rvlen - rvChanged = !rvCanset - } else { - halt.errorStr("cannot decode into non-settable slice") - } - } - if fn == nil { - fn = d.fn(rtelem) - } - } - - if ctyp == valueTypeArray { - d.arrayElem(j == 0) - } else if j&1 == 0 { - d.mapElemKey(j == 0) - } else { - d.mapElemValue() - } - - if j >= rvlen { - - if rvlen < rvcap { - rvlen = rvcap - if rvCanset { - rvSetSliceLen(rv, rvlen) - } else if rvChanged { - rv = rvSlice(rv, rvlen) - } else { - halt.onerror(errExpandSliceCannotChange) - } - } else { - if !(rvCanset || rvChanged) { - halt.onerror(errExpandSliceCannotChange) - } - rv, rvcap, rvCanset = rvGrowSlice(rv, f.ti, rvcap, 1) - - rvlen = rvcap - rvChanged = !rvCanset - } - } - - rv9 = rvArrayIndex(rv, j, f.ti, true) - if elemReset { - rvSetZero(rv9) - } - if d.d.TryNil() { - rvSetZero(rv9) - } else if builtin { - if rtelemIsPtr { - if rvIsNil(rv9) { - rvSetDirect(rv9, reflect.New(rtelemElem)) - } - d.decode(rv2i(rv9)) - } else { - d.decode(rv2i(rvAddr(rv9, ti.tielem.ptr))) - } - } else { - d.decodeValueNoCheckNil(rv9, fn) - } - } - if j < rvlen { - if rvCanset { - rvSetSliceLen(rv, j) - } else if rvChanged { - rv = rvSlice(rv, j) - } - - } else if j == 0 && rvIsNil(rv) { - if rvCanset { - rv = rvSliceZeroCap(ti.rt) - rvCanset = false - rvChanged = true - } - } - if isArray { - d.arrayEnd() - } else { - d.mapEnd() - } - - if rvChanged { - rvSetDirect(rv0, rv) - } -} - -func (d *decoderBincIO) kArray(f *decFnInfo, rv reflect.Value) { - _ = d.d - - ti := f.ti - ctyp := d.d.ContainerType() - if handleBytesWithinKArray && (ctyp == valueTypeBytes || ctyp == valueTypeString) { - - if ti.elemkind != uint8(reflect.Uint8) { - halt.errorf("bytes/string in stream can decode into array of bytes, but not %v", ti.rt) - } - rvbs := rvGetArrayBytes(rv, nil) - d.decodeBytesInto(rvbs, true) - return - } - - var containerLenS int - isArray := ctyp == valueTypeArray - if isArray { - containerLenS = d.arrayStart(d.d.ReadArrayStart()) - } else if ctyp == valueTypeMap { - containerLenS = d.mapStart(d.d.ReadMapStart()) * 2 - } else { - halt.errorStr2("decoding into a slice, expect map/array - got ", ctyp.String()) - } - - if containerLenS == 0 { - if isArray { - d.arrayEnd() - } else { - d.mapEnd() - } - return - } - - rtelem := ti.elem - for k := reflect.Kind(ti.elemkind); k == reflect.Ptr; k = rtelem.Kind() { - rtelem = rtelem.Elem() - } - - var rv9 reflect.Value - - rvlen := rv.Len() - hasLen := containerLenS >= 0 - if hasLen && containerLenS > rvlen { - halt.errorf("cannot decode into array with length: %v, less than container length: %v", any(rvlen), any(containerLenS)) - } - - var elemReset = d.h.SliceElementReset - - var rtelemIsPtr bool - var rtelemElem reflect.Type - var fn *decFnBincIO - builtin := ti.tielem.flagDecBuiltin - if builtin { - rtelemIsPtr = ti.elemkind == uint8(reflect.Ptr) - if rtelemIsPtr { - rtelemElem = ti.elem.Elem() - } - } else { - fn = d.fn(rtelem) - } - - for j := 0; d.containerNext(j, containerLenS, hasLen); j++ { - if ctyp == valueTypeArray { - d.arrayElem(j == 0) - } else if j&1 == 0 { - d.mapElemKey(j == 0) - } else { - d.mapElemValue() - } - - if j >= rvlen { - d.arrayCannotExpand(rvlen, j+1) - d.swallow() - continue - } - - rv9 = rvArrayIndex(rv, j, f.ti, false) - if elemReset { - rvSetZero(rv9) - } - if d.d.TryNil() { - rvSetZero(rv9) - } else if builtin { - if rtelemIsPtr { - if rvIsNil(rv9) { - rvSetDirect(rv9, reflect.New(rtelemElem)) - } - d.decode(rv2i(rv9)) - } else { - d.decode(rv2i(rvAddr(rv9, ti.tielem.ptr))) - } - } else { - d.decodeValueNoCheckNil(rv9, fn) - } - } - if isArray { - d.arrayEnd() - } else { - d.mapEnd() - } -} - -func (d *decoderBincIO) kChan(f *decFnInfo, rv reflect.Value) { - _ = d.d - - ti := f.ti - if ti.chandir&uint8(reflect.SendDir) == 0 { - halt.errorStr("receive-only channel cannot be decoded") - } - ctyp := d.d.ContainerType() - if ctyp == valueTypeBytes || ctyp == valueTypeString { - - if !(ti.rtid == uint8SliceTypId || ti.elemkind == uint8(reflect.Uint8)) { - halt.errorf("bytes/string in stream must decode into slice/array of bytes, not %v", ti.rt) - } - bs2, _ := d.d.DecodeBytes() - irv := rv2i(rv) - ch, ok := irv.(chan<- byte) - if !ok { - ch = irv.(chan byte) - } - for _, b := range bs2 { - ch <- b - } - return - } - - var rvCanset = rv.CanSet() - - var containerLenS int - isArray := ctyp == valueTypeArray - if isArray { - containerLenS = d.arrayStart(d.d.ReadArrayStart()) - } else if ctyp == valueTypeMap { - containerLenS = d.mapStart(d.d.ReadMapStart()) * 2 - } else { - halt.errorStr2("decoding into a slice, expect map/array - got ", ctyp.String()) - } - - if containerLenS == 0 { - if rvCanset && rvIsNil(rv) { - rvSetDirect(rv, reflect.MakeChan(ti.rt, 0)) - } - if isArray { - d.arrayEnd() - } else { - d.mapEnd() - } - return - } - - rtelem := ti.elem - useTransient := decUseTransient && ti.elemkind != byte(reflect.Ptr) && ti.tielem.flagCanTransient - - for k := reflect.Kind(ti.elemkind); k == reflect.Ptr; k = rtelem.Kind() { - rtelem = rtelem.Elem() - } - - var fn *decFnBincIO - - var rvChanged bool - var rv0 = rv - var rv9 reflect.Value - - var rvlen int - hasLen := containerLenS >= 0 - maxInitLen := d.maxInitLen() - - for j := 0; d.containerNext(j, containerLenS, hasLen); j++ { - if j == 0 { - if rvIsNil(rv) { - if hasLen { - rvlen = int(decInferLen(containerLenS, maxInitLen, uint(ti.elemsize))) - } else { - rvlen = decDefChanCap - } - if rvCanset { - rv = reflect.MakeChan(ti.rt, rvlen) - rvChanged = true - } else { - halt.errorStr("cannot decode into non-settable chan") - } - } - if fn == nil { - fn = d.fn(rtelem) - } - } - - if ctyp == valueTypeArray { - d.arrayElem(j == 0) - } else if j&1 == 0 { - d.mapElemKey(j == 0) - } else { - d.mapElemValue() - } - - if rv9.IsValid() { - rvSetZero(rv9) - } else if useTransient { - rv9 = d.perType.TransientAddrK(ti.elem, reflect.Kind(ti.elemkind)) - } else { - rv9 = rvZeroAddrK(ti.elem, reflect.Kind(ti.elemkind)) - } - if !d.d.TryNil() { - d.decodeValueNoCheckNil(rv9, fn) - } - rv.Send(rv9) - } - if isArray { - d.arrayEnd() - } else { - d.mapEnd() - } - - if rvChanged { - rvSetDirect(rv0, rv) - } - -} - -func (d *decoderBincIO) kMap(f *decFnInfo, rv reflect.Value) { - _ = d.d - containerLen := d.mapStart(d.d.ReadMapStart()) - ti := f.ti - if rvIsNil(rv) { - rvlen := int(decInferLen(containerLen, d.maxInitLen(), uint(ti.keysize+ti.elemsize))) - rvSetDirect(rv, makeMapReflect(ti.rt, rvlen)) - } - - if containerLen == 0 { - d.mapEnd() - return - } - - ktype, vtype := ti.key, ti.elem - ktypeId := rt2id(ktype) - vtypeKind := reflect.Kind(ti.elemkind) - ktypeKind := reflect.Kind(ti.keykind) - mparams := getMapReqParams(ti) - - vtypePtr := vtypeKind == reflect.Ptr - ktypePtr := ktypeKind == reflect.Ptr - - vTransient := decUseTransient && !vtypePtr && ti.tielem.flagCanTransient - - kTransient := vTransient && !ktypePtr && ti.tikey.flagCanTransient - - var vtypeElem reflect.Type - - var keyFn, valFn *decFnBincIO - var ktypeLo, vtypeLo = ktype, vtype - - if ktypeKind == reflect.Ptr { - for ktypeLo = ktype.Elem(); ktypeLo.Kind() == reflect.Ptr; ktypeLo = ktypeLo.Elem() { - } - } - - if vtypePtr { - vtypeElem = vtype.Elem() - for vtypeLo = vtypeElem; vtypeLo.Kind() == reflect.Ptr; vtypeLo = vtypeLo.Elem() { - } - } - - rvkMut := !scalarBitset.isset(ti.keykind) - rvvMut := !scalarBitset.isset(ti.elemkind) - rvvCanNil := isnilBitset.isset(ti.elemkind) - - var rvk, rvkn, rvv, rvvn, rvva, rvvz reflect.Value - - var doMapGet, doMapSet bool - - if !d.h.MapValueReset { - if rvvMut && (vtypeKind != reflect.Interface || !d.h.InterfaceReset) { - doMapGet = true - rvva = mapAddrLoopvarRV(vtype, vtypeKind) - } - } - - ktypeIsString := ktypeId == stringTypId - ktypeIsIntf := ktypeId == intfTypId - hasLen := containerLen >= 0 - - var kstr2bs []byte - var kstr string - - var mapKeyStringSharesBytesBuf bool - var att dBytesAttachState - - var vElem, kElem reflect.Type - kbuiltin := ti.tikey.flagDecBuiltin && ti.keykind != uint8(reflect.Slice) - vbuiltin := ti.tielem.flagDecBuiltin - if kbuiltin && ktypePtr { - kElem = ti.key.Elem() - } - if vbuiltin && vtypePtr { - vElem = ti.elem.Elem() - } - - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - mapKeyStringSharesBytesBuf = false - kstr = "" - if j == 0 { - - if kTransient { - rvk = d.perType.TransientAddr2K(ktype, ktypeKind) - } else { - rvk = rvZeroAddrK(ktype, ktypeKind) - } - if !rvkMut { - rvkn = rvk - } - if !rvvMut { - if vTransient { - rvvn = d.perType.TransientAddrK(vtype, vtypeKind) - } else { - rvvn = rvZeroAddrK(vtype, vtypeKind) - } - } - if !ktypeIsString && keyFn == nil { - keyFn = d.fn(ktypeLo) - } - if valFn == nil { - valFn = d.fn(vtypeLo) - } - } else if rvkMut { - rvSetZero(rvk) - } else { - rvk = rvkn - } - - d.mapElemKey(j == 0) - - if d.d.TryNil() { - rvSetZero(rvk) - } else if ktypeIsString { - kstr2bs, att = d.d.DecodeStringAsBytes() - kstr, mapKeyStringSharesBytesBuf = d.bytes2Str(kstr2bs, att) - rvSetString(rvk, kstr) - } else { - if kbuiltin { - if ktypePtr { - if rvIsNil(rvk) { - rvSetDirect(rvk, reflect.New(kElem)) - } - d.decode(rv2i(rvk)) - } else { - d.decode(rv2i(rvAddr(rvk, ti.tikey.ptr))) - } - } else { - d.decodeValueNoCheckNil(rvk, keyFn) - } - - if ktypeIsIntf { - if rvk2 := rvk.Elem(); rvk2.IsValid() && rvk2.Type() == uint8SliceTyp { - kstr2bs = rvGetBytes(rvk2) - kstr, mapKeyStringSharesBytesBuf = d.bytes2Str(kstr2bs, dBytesAttachView) - rvSetIntf(rvk, rv4istr(kstr)) - } - - } - } - - if mapKeyStringSharesBytesBuf && d.bufio { - if ktypeIsString { - rvSetString(rvk, d.detach2Str(kstr2bs, att)) - } else { - rvSetIntf(rvk, rv4istr(d.detach2Str(kstr2bs, att))) - } - mapKeyStringSharesBytesBuf = false - } - - d.mapElemValue() - - if d.d.TryNil() { - if mapKeyStringSharesBytesBuf { - if ktypeIsString { - rvSetString(rvk, d.detach2Str(kstr2bs, att)) - } else { - rvSetIntf(rvk, rv4istr(d.detach2Str(kstr2bs, att))) - } - } - - if !rvvz.IsValid() { - rvvz = rvZeroK(vtype, vtypeKind) - } - mapSet(rv, rvk, rvvz, mparams) - continue - } - - doMapSet = true - - if !rvvMut { - rvv = rvvn - } else if !doMapGet { - goto NEW_RVV - } else { - rvv = mapGet(rv, rvk, rvva, mparams) - if !rvv.IsValid() || (rvvCanNil && rvIsNil(rvv)) { - goto NEW_RVV - } - switch vtypeKind { - case reflect.Ptr, reflect.Map: - doMapSet = false - case reflect.Interface: - - rvvn = rvv.Elem() - if k := rvvn.Kind(); (k == reflect.Ptr || k == reflect.Map) && !rvIsNil(rvvn) { - d.decodeValueNoCheckNil(rvvn, nil) - continue - } - - rvvn = rvZeroAddrK(vtype, vtypeKind) - rvSetIntf(rvvn, rvv) - rvv = rvvn - default: - - if vTransient { - rvvn = d.perType.TransientAddrK(vtype, vtypeKind) - } else { - rvvn = rvZeroAddrK(vtype, vtypeKind) - } - rvSetDirect(rvvn, rvv) - rvv = rvvn - } - } - goto DECODE_VALUE_NO_CHECK_NIL - - NEW_RVV: - if vtypePtr { - rvv = reflect.New(vtypeElem) - } else if vTransient { - rvv = d.perType.TransientAddrK(vtype, vtypeKind) - } else { - rvv = rvZeroAddrK(vtype, vtypeKind) - } - - DECODE_VALUE_NO_CHECK_NIL: - if doMapSet && mapKeyStringSharesBytesBuf { - if ktypeIsString { - rvSetString(rvk, d.detach2Str(kstr2bs, att)) - } else { - rvSetIntf(rvk, rv4istr(d.detach2Str(kstr2bs, att))) - } - } - if vbuiltin { - if vtypePtr { - if rvIsNil(rvv) { - rvSetDirect(rvv, reflect.New(vElem)) - } - d.decode(rv2i(rvv)) - } else { - d.decode(rv2i(rvAddr(rvv, ti.tielem.ptr))) - } - } else { - d.decodeValueNoCheckNil(rvv, valFn) - } - if doMapSet { - mapSet(rv, rvk, rvv, mparams) - } - } - - d.mapEnd() -} - -func (d *decoderBincIO) init(h Handle) { - initHandle(h) - callMake(&d.d) - d.hh = h - d.h = h.getBasicHandle() - - d.err = errDecoderNotInitialized - - if d.h.InternString && d.is == nil { - d.is.init() - } - - d.fp = d.d.init(h, &d.decoderBase, d).(*fastpathDsBincIO) - - if d.bytes { - d.rtidFn = &d.h.rtidFnsDecBytes - d.rtidFnNoExt = &d.h.rtidFnsDecNoExtBytes - } else { - d.bufio = d.h.ReaderBufferSize > 0 - d.rtidFn = &d.h.rtidFnsDecIO - d.rtidFnNoExt = &d.h.rtidFnsDecNoExtIO - } - - d.reset() - -} - -func (d *decoderBincIO) reset() { - d.d.reset() - d.err = nil - d.c = 0 - d.depth = 0 - d.calls = 0 - - d.maxdepth = decDefMaxDepth - if d.h.MaxDepth > 0 { - d.maxdepth = d.h.MaxDepth - } - d.mtid = 0 - d.stid = 0 - d.mtr = false - d.str = false - if d.h.MapType != nil { - d.mtid = rt2id(d.h.MapType) - _, d.mtr = fastpathAvIndex(d.mtid) - } - if d.h.SliceType != nil { - d.stid = rt2id(d.h.SliceType) - _, d.str = fastpathAvIndex(d.stid) - } -} - -func (d *decoderBincIO) Reset(r io.Reader) { - if d.bytes { - halt.onerror(errDecNoResetBytesWithReader) - } - d.reset() - if r == nil { - r = &eofReader - } - d.d.resetInIO(r) -} - -func (d *decoderBincIO) ResetBytes(in []byte) { - if !d.bytes { - halt.onerror(errDecNoResetReaderWithBytes) - } - d.resetBytes(in) -} - -func (d *decoderBincIO) resetBytes(in []byte) { - d.reset() - if in == nil { - in = zeroByteSlice - } - d.d.resetInBytes(in) -} - -func (d *decoderBincIO) ResetString(s string) { - d.ResetBytes(bytesView(s)) -} - -func (d *decoderBincIO) Decode(v interface{}) (err error) { - - defer panicValToErr(d, callRecoverSentinel, &d.err, &err, debugging) - d.mustDecode(v) - return -} - -func (d *decoderBincIO) MustDecode(v interface{}) { - defer panicValToErr(d, callRecoverSentinel, &d.err, nil, true) - d.mustDecode(v) - return -} - -func (d *decoderBincIO) mustDecode(v interface{}) { - halt.onerror(d.err) - if d.hh == nil { - halt.onerror(errNoFormatHandle) - } - - d.calls++ - d.decode(v) - d.calls-- -} - -func (d *decoderBincIO) Release() {} - -func (d *decoderBincIO) swallow() { - d.d.nextValueBytes() -} - -func (d *decoderBincIO) nextValueBytes() []byte { - return d.d.nextValueBytes() -} - -func (d *decoderBincIO) decode(iv interface{}) { - _ = d.d - - rv, ok := isNil(iv, true) - if ok { - halt.onerror(errCannotDecodeIntoNil) - } - - switch v := iv.(type) { - - case *string: - *v = d.detach2Str(d.d.DecodeStringAsBytes()) - case *bool: - *v = d.d.DecodeBool() - case *int: - *v = int(chkOvf.IntV(d.d.DecodeInt64(), intBitsize)) - case *int8: - *v = int8(chkOvf.IntV(d.d.DecodeInt64(), 8)) - case *int16: - *v = int16(chkOvf.IntV(d.d.DecodeInt64(), 16)) - case *int32: - *v = int32(chkOvf.IntV(d.d.DecodeInt64(), 32)) - case *int64: - *v = d.d.DecodeInt64() - case *uint: - *v = uint(chkOvf.UintV(d.d.DecodeUint64(), uintBitsize)) - case *uint8: - *v = uint8(chkOvf.UintV(d.d.DecodeUint64(), 8)) - case *uint16: - *v = uint16(chkOvf.UintV(d.d.DecodeUint64(), 16)) - case *uint32: - *v = uint32(chkOvf.UintV(d.d.DecodeUint64(), 32)) - case *uint64: - *v = d.d.DecodeUint64() - case *uintptr: - *v = uintptr(chkOvf.UintV(d.d.DecodeUint64(), uintBitsize)) - case *float32: - *v = d.d.DecodeFloat32() - case *float64: - *v = d.d.DecodeFloat64() - case *complex64: - *v = complex(d.d.DecodeFloat32(), 0) - case *complex128: - *v = complex(d.d.DecodeFloat64(), 0) - case *[]byte: - *v, _ = d.decodeBytesInto(*v, false) - case []byte: - - d.decodeBytesInto(v[:len(v):len(v)], true) - case *time.Time: - *v = d.d.DecodeTime() - case *Raw: - *v = d.rawBytes() - - case *interface{}: - d.decodeValue(rv4iptr(v), nil) - - case reflect.Value: - if ok, _ = isDecodeable(v); !ok { - d.haltAsNotDecodeable(v) - } - d.decodeValue(v, nil) - - default: - - if skipFastpathTypeSwitchInDirectCall || !d.dh.fastpathDecodeTypeSwitch(iv, d) { - if !rv.IsValid() { - rv = reflect.ValueOf(iv) - } - if ok, _ = isDecodeable(rv); !ok { - d.haltAsNotDecodeable(rv) - } - d.decodeValue(rv, nil) - } - } -} - -func (d *decoderBincIO) decodeValue(rv reflect.Value, fn *decFnBincIO) { - if d.d.TryNil() { - decSetNonNilRV2Zero(rv) - } else { - d.decodeValueNoCheckNil(rv, fn) - } -} - -func (d *decoderBincIO) decodeValueNoCheckNil(rv reflect.Value, fn *decFnBincIO) { - - var rvp reflect.Value - var rvpValid bool -PTR: - if rv.Kind() == reflect.Ptr { - rvpValid = true - if rvIsNil(rv) { - rvSetDirect(rv, reflect.New(rv.Type().Elem())) - } - rvp = rv - rv = rv.Elem() - goto PTR - } - - if fn == nil { - fn = d.fn(rv.Type()) - } - if fn.i.addrD { - if rvpValid { - rv = rvp - } else if rv.CanAddr() { - rv = rvAddr(rv, fn.i.ti.ptr) - } else if fn.i.addrDf { - halt.errorStr("cannot decode into a non-pointer value") - } - } - fn.fd(d, &fn.i, rv) -} - -func (d *decoderBincIO) decodeAs(v interface{}, t reflect.Type, ext bool) { - if ext { - d.decodeValue(baseRV(v), d.fn(t)) - } else { - d.decodeValue(baseRV(v), d.fnNoExt(t)) - } -} - -func (d *decoderBincIO) structFieldNotFound(index int, rvkencname string) { - - if d.h.ErrorIfNoField { - if index >= 0 { - halt.errorInt("no matching struct field found when decoding stream array at index ", int64(index)) - } else if rvkencname != "" { - halt.errorStr2("no matching struct field found when decoding stream map with key ", rvkencname) - } - } - d.swallow() -} - -func (d *decoderBincIO) decodeBytesInto(out []byte, mustFit bool) (v []byte, state dBytesIntoState) { - v, att := d.d.DecodeBytes() - if cap(v) == 0 || (att >= dBytesAttachViewZerocopy && !mustFit) { - - return - } - if len(v) == 0 { - v = zeroByteSlice - return - } - if len(out) == len(v) { - state = dBytesIntoParamOut - } else if cap(out) >= len(v) { - out = out[:len(v)] - state = dBytesIntoParamOutSlice - } else if mustFit { - halt.errorf("bytes capacity insufficient for decoded bytes: got/expected: %d/%d", len(v), len(out)) - } else { - out = make([]byte, len(v)) - state = dBytesIntoNew - } - copy(out, v) - v = out - return -} - -func (d *decoderBincIO) rawBytes() (v []byte) { - - v = d.d.nextValueBytes() - if d.bytes && !d.h.ZeroCopy { - vv := make([]byte, len(v)) - copy(vv, v) - v = vv - } - return -} - -func (d *decoderBincIO) wrapErr(v error, err *error) { - *err = wrapCodecErr(v, d.hh.Name(), d.d.NumBytesRead(), false) -} - -func (d *decoderBincIO) NumBytesRead() int { - return d.d.NumBytesRead() -} - -func (d *decoderBincIO) containerNext(j, containerLen int, hasLen bool) bool { - - if hasLen { - return j < containerLen - } - return !d.d.CheckBreak() -} - -func (d *decoderBincIO) mapElemKey(firstTime bool) { - d.d.ReadMapElemKey(firstTime) - d.c = containerMapKey -} - -func (d *decoderBincIO) mapElemValue() { - d.d.ReadMapElemValue() - d.c = containerMapValue -} - -func (d *decoderBincIO) mapEnd() { - d.d.ReadMapEnd() - d.depthDecr() - d.c = 0 -} - -func (d *decoderBincIO) arrayElem(firstTime bool) { - d.d.ReadArrayElem(firstTime) - d.c = containerArrayElem -} - -func (d *decoderBincIO) arrayEnd() { - d.d.ReadArrayEnd() - d.depthDecr() - d.c = 0 -} - -func (d *decoderBincIO) interfaceExtConvertAndDecode(v interface{}, ext InterfaceExt) { - - var vv interface{} - d.decode(&vv) - ext.UpdateExt(v, vv) - -} - -func (d *decoderBincIO) fn(t reflect.Type) *decFnBincIO { - return d.dh.decFnViaBH(t, d.rtidFn, d.h, d.fp, false) -} - -func (d *decoderBincIO) fnNoExt(t reflect.Type) *decFnBincIO { - return d.dh.decFnViaBH(t, d.rtidFnNoExt, d.h, d.fp, true) -} - -func (helperDecDriverBincIO) newDecoderBytes(in []byte, h Handle) *decoderBincIO { - var c1 decoderBincIO - c1.bytes = true - c1.init(h) - c1.ResetBytes(in) - return &c1 -} - -func (helperDecDriverBincIO) newDecoderIO(in io.Reader, h Handle) *decoderBincIO { - var c1 decoderBincIO - c1.init(h) - c1.Reset(in) - return &c1 -} - -func (helperDecDriverBincIO) decFnloadFastpathUnderlying(ti *typeInfo, fp *fastpathDsBincIO) (f *fastpathDBincIO, u reflect.Type) { - rtid := rt2id(ti.fastpathUnderlying) - idx, ok := fastpathAvIndex(rtid) - if !ok { - return - } - f = &fp[idx] - if uint8(reflect.Array) == ti.kind { - u = reflect.ArrayOf(ti.rt.Len(), ti.elem) - } else { - u = f.rt - } - return -} - -func (helperDecDriverBincIO) decFindRtidFn(s []decRtidFnBincIO, rtid uintptr) (i uint, fn *decFnBincIO) { - - var h uint - var j = uint(len(s)) -LOOP: - if i < j { - h = (i + j) >> 1 - if s[h].rtid < rtid { - i = h + 1 - } else { - j = h - } - goto LOOP - } - if i < uint(len(s)) && s[i].rtid == rtid { - fn = s[i].fn - } - return -} - -func (helperDecDriverBincIO) decFromRtidFnSlice(fns *atomicRtidFnSlice) (s []decRtidFnBincIO) { - if v := fns.load(); v != nil { - s = *(lowLevelToPtr[[]decRtidFnBincIO](v)) - } - return -} - -func (dh helperDecDriverBincIO) decFnViaBH(rt reflect.Type, fns *atomicRtidFnSlice, x *BasicHandle, fp *fastpathDsBincIO, - checkExt bool) (fn *decFnBincIO) { - return dh.decFnVia(rt, fns, x.typeInfos(), &x.mu, x.extHandle, fp, - checkExt, x.CheckCircularRef, x.timeBuiltin, x.binaryHandle, x.jsonHandle) -} - -func (dh helperDecDriverBincIO) decFnVia(rt reflect.Type, fns *atomicRtidFnSlice, - tinfos *TypeInfos, mu *sync.Mutex, exth extHandle, fp *fastpathDsBincIO, - checkExt, checkCircularRef, timeBuiltin, binaryEncoding, json bool) (fn *decFnBincIO) { - rtid := rt2id(rt) - var sp []decRtidFnBincIO = dh.decFromRtidFnSlice(fns) - if sp != nil { - _, fn = dh.decFindRtidFn(sp, rtid) - } - if fn == nil { - fn = dh.decFnViaLoader(rt, rtid, fns, tinfos, mu, exth, fp, checkExt, checkCircularRef, timeBuiltin, binaryEncoding, json) - } - return -} - -func (dh helperDecDriverBincIO) decFnViaLoader(rt reflect.Type, rtid uintptr, fns *atomicRtidFnSlice, - tinfos *TypeInfos, mu *sync.Mutex, exth extHandle, fp *fastpathDsBincIO, - checkExt, checkCircularRef, timeBuiltin, binaryEncoding, json bool) (fn *decFnBincIO) { - - fn = dh.decFnLoad(rt, rtid, tinfos, exth, fp, checkExt, checkCircularRef, timeBuiltin, binaryEncoding, json) - var sp []decRtidFnBincIO - mu.Lock() - sp = dh.decFromRtidFnSlice(fns) - - if sp == nil { - sp = []decRtidFnBincIO{{rtid, fn}} - fns.store(ptrToLowLevel(&sp)) - } else { - idx, fn2 := dh.decFindRtidFn(sp, rtid) - if fn2 == nil { - sp2 := make([]decRtidFnBincIO, len(sp)+1) - copy(sp2[idx+1:], sp[idx:]) - copy(sp2, sp[:idx]) - sp2[idx] = decRtidFnBincIO{rtid, fn} - fns.store(ptrToLowLevel(&sp2)) - } - } - mu.Unlock() - return -} - -func (dh helperDecDriverBincIO) decFnLoad(rt reflect.Type, rtid uintptr, tinfos *TypeInfos, - exth extHandle, fp *fastpathDsBincIO, - checkExt, checkCircularRef, timeBuiltin, binaryEncoding, json bool) (fn *decFnBincIO) { - fn = new(decFnBincIO) - fi := &(fn.i) - ti := tinfos.get(rtid, rt) - fi.ti = ti - rk := reflect.Kind(ti.kind) - - fi.addrDf = true - - if rtid == timeTypId && timeBuiltin { - fn.fd = (*decoderBincIO).kTime - } else if rtid == rawTypId { - fn.fd = (*decoderBincIO).raw - } else if rtid == rawExtTypId { - fn.fd = (*decoderBincIO).rawExt - fi.addrD = true - } else if xfFn := exth.getExt(rtid, checkExt); xfFn != nil { - fi.xfTag, fi.xfFn = xfFn.tag, xfFn.ext - fn.fd = (*decoderBincIO).ext - fi.addrD = true - } else if ti.flagSelfer || ti.flagSelferPtr { - fn.fd = (*decoderBincIO).selferUnmarshal - fi.addrD = ti.flagSelferPtr - } else if supportMarshalInterfaces && binaryEncoding && - (ti.flagBinaryMarshaler || ti.flagBinaryMarshalerPtr) && - (ti.flagBinaryUnmarshaler || ti.flagBinaryUnmarshalerPtr) { - fn.fd = (*decoderBincIO).binaryUnmarshal - fi.addrD = ti.flagBinaryUnmarshalerPtr - } else if supportMarshalInterfaces && !binaryEncoding && json && - (ti.flagJsonMarshaler || ti.flagJsonMarshalerPtr) && - (ti.flagJsonUnmarshaler || ti.flagJsonUnmarshalerPtr) { - - fn.fd = (*decoderBincIO).jsonUnmarshal - fi.addrD = ti.flagJsonUnmarshalerPtr - } else if supportMarshalInterfaces && !binaryEncoding && - (ti.flagTextMarshaler || ti.flagTextMarshalerPtr) && - (ti.flagTextUnmarshaler || ti.flagTextUnmarshalerPtr) { - fn.fd = (*decoderBincIO).textUnmarshal - fi.addrD = ti.flagTextUnmarshalerPtr - } else { - if fastpathEnabled && (rk == reflect.Map || rk == reflect.Slice || rk == reflect.Array) { - var rtid2 uintptr - if !ti.flagHasPkgPath { - rtid2 = rtid - if rk == reflect.Array { - rtid2 = rt2id(ti.key) - } - if idx, ok := fastpathAvIndex(rtid2); ok { - fn.fd = fp[idx].decfn - fi.addrD = true - fi.addrDf = false - if rk == reflect.Array { - fi.addrD = false - } - } - } else { - - xfe, xrt := dh.decFnloadFastpathUnderlying(ti, fp) - if xfe != nil { - xfnf2 := xfe.decfn - if rk == reflect.Array { - fi.addrD = false - fn.fd = func(d *decoderBincIO, xf *decFnInfo, xrv reflect.Value) { - xfnf2(d, xf, rvConvert(xrv, xrt)) - } - } else { - fi.addrD = true - fi.addrDf = false - xptr2rt := reflect.PointerTo(xrt) - fn.fd = func(d *decoderBincIO, xf *decFnInfo, xrv reflect.Value) { - if xrv.Kind() == reflect.Ptr { - xfnf2(d, xf, rvConvert(xrv, xptr2rt)) - } else { - xfnf2(d, xf, rvConvert(xrv, xrt)) - } - } - } - } - } - } - if fn.fd == nil { - switch rk { - case reflect.Bool: - fn.fd = (*decoderBincIO).kBool - case reflect.String: - fn.fd = (*decoderBincIO).kString - case reflect.Int: - fn.fd = (*decoderBincIO).kInt - case reflect.Int8: - fn.fd = (*decoderBincIO).kInt8 - case reflect.Int16: - fn.fd = (*decoderBincIO).kInt16 - case reflect.Int32: - fn.fd = (*decoderBincIO).kInt32 - case reflect.Int64: - fn.fd = (*decoderBincIO).kInt64 - case reflect.Uint: - fn.fd = (*decoderBincIO).kUint - case reflect.Uint8: - fn.fd = (*decoderBincIO).kUint8 - case reflect.Uint16: - fn.fd = (*decoderBincIO).kUint16 - case reflect.Uint32: - fn.fd = (*decoderBincIO).kUint32 - case reflect.Uint64: - fn.fd = (*decoderBincIO).kUint64 - case reflect.Uintptr: - fn.fd = (*decoderBincIO).kUintptr - case reflect.Float32: - fn.fd = (*decoderBincIO).kFloat32 - case reflect.Float64: - fn.fd = (*decoderBincIO).kFloat64 - case reflect.Complex64: - fn.fd = (*decoderBincIO).kComplex64 - case reflect.Complex128: - fn.fd = (*decoderBincIO).kComplex128 - case reflect.Chan: - fn.fd = (*decoderBincIO).kChan - case reflect.Slice: - fn.fd = (*decoderBincIO).kSlice - case reflect.Array: - fi.addrD = false - fn.fd = (*decoderBincIO).kArray - case reflect.Struct: - if ti.simple { - fn.fd = (*decoderBincIO).kStructSimple - } else { - fn.fd = (*decoderBincIO).kStruct - } - case reflect.Map: - fn.fd = (*decoderBincIO).kMap - case reflect.Interface: - - fn.fd = (*decoderBincIO).kInterface - default: - - fn.fd = (*decoderBincIO).kErr - } - } - } - return -} -func (e *bincEncDriverIO) EncodeNil() { - e.w.writen1(bincBdNil) -} - -func (e *bincEncDriverIO) EncodeTime(t time.Time) { - if t.IsZero() { - e.EncodeNil() - } else { - bs := bincEncodeTime(t) - e.w.writen1(bincVdTimestamp<<4 | uint8(len(bs))) - e.w.writeb(bs) - } -} - -func (e *bincEncDriverIO) EncodeBool(b bool) { - if b { - e.w.writen1(bincVdSpecial<<4 | bincSpTrue) - } else { - e.w.writen1(bincVdSpecial<<4 | bincSpFalse) - } -} - -func (e *bincEncDriverIO) encSpFloat(f float64) (done bool) { - if f == 0 { - e.w.writen1(bincVdSpecial<<4 | bincSpZeroFloat) - } else if math.IsNaN(float64(f)) { - e.w.writen1(bincVdSpecial<<4 | bincSpNan) - } else if math.IsInf(float64(f), +1) { - e.w.writen1(bincVdSpecial<<4 | bincSpPosInf) - } else if math.IsInf(float64(f), -1) { - e.w.writen1(bincVdSpecial<<4 | bincSpNegInf) - } else { - return - } - return true -} - -func (e *bincEncDriverIO) EncodeFloat32(f float32) { - if !e.encSpFloat(float64(f)) { - e.w.writen1(bincVdFloat<<4 | bincFlBin32) - e.w.writen4(bigen.PutUint32(math.Float32bits(f))) - } -} - -func (e *bincEncDriverIO) EncodeFloat64(f float64) { - if e.encSpFloat(f) { - return - } - b := bigen.PutUint64(math.Float64bits(f)) - if bincDoPrune { - i := 7 - for ; i >= 0 && (b[i] == 0); i-- { - } - i++ - if i <= 6 { - e.w.writen1(bincVdFloat<<4 | 0x8 | bincFlBin64) - e.w.writen1(byte(i)) - e.w.writeb(b[:i]) - return - } - } - e.w.writen1(bincVdFloat<<4 | bincFlBin64) - e.w.writen8(b) -} - -func (e *bincEncDriverIO) encIntegerPrune32(bd byte, pos bool, v uint64) { - b := bigen.PutUint32(uint32(v)) - if bincDoPrune { - i := byte(pruneSignExt(b[:], pos)) - e.w.writen1(bd | 3 - i) - e.w.writeb(b[i:]) - } else { - e.w.writen1(bd | 3) - e.w.writen4(b) - } -} - -func (e *bincEncDriverIO) encIntegerPrune64(bd byte, pos bool, v uint64) { - b := bigen.PutUint64(v) - if bincDoPrune { - i := byte(pruneSignExt(b[:], pos)) - e.w.writen1(bd | 7 - i) - e.w.writeb(b[i:]) - } else { - e.w.writen1(bd | 7) - e.w.writen8(b) - } -} - -func (e *bincEncDriverIO) EncodeInt(v int64) { - if v >= 0 { - e.encUint(bincVdPosInt<<4, true, uint64(v)) - } else if v == -1 { - e.w.writen1(bincVdSpecial<<4 | bincSpNegOne) - } else { - e.encUint(bincVdNegInt<<4, false, uint64(-v)) - } -} - -func (e *bincEncDriverIO) EncodeUint(v uint64) { - e.encUint(bincVdPosInt<<4, true, v) -} - -func (e *bincEncDriverIO) encUint(bd byte, pos bool, v uint64) { - if v == 0 { - e.w.writen1(bincVdSpecial<<4 | bincSpZero) - } else if pos && v >= 1 && v <= 16 { - e.w.writen1(bincVdSmallInt<<4 | byte(v-1)) - } else if v <= math.MaxUint8 { - e.w.writen2(bd, byte(v)) - } else if v <= math.MaxUint16 { - e.w.writen1(bd | 0x01) - e.w.writen2(bigen.PutUint16(uint16(v))) - } else if v <= math.MaxUint32 { - e.encIntegerPrune32(bd, pos, v) - } else { - e.encIntegerPrune64(bd, pos, v) - } -} - -func (e *bincEncDriverIO) EncodeExt(v interface{}, basetype reflect.Type, xtag uint64, ext Ext) { - var bs0, bs []byte - if ext == SelfExt { - bs0 = e.e.blist.get(1024) - bs = bs0 - sideEncode(e.h, &e.h.sideEncPool, func(se encoderI) { oneOffEncode(se, v, &bs, basetype, true) }) - } else { - bs = ext.WriteExt(v) - } - if bs == nil { - e.writeNilBytes() - goto END - } - e.encodeExtPreamble(uint8(xtag), len(bs)) - e.w.writeb(bs) -END: - if ext == SelfExt { - e.e.blist.put(bs) - if !byteSliceSameData(bs0, bs) { - e.e.blist.put(bs0) - } - } -} - -func (e *bincEncDriverIO) EncodeRawExt(re *RawExt) { - e.encodeExtPreamble(uint8(re.Tag), len(re.Data)) - e.w.writeb(re.Data) -} - -func (e *bincEncDriverIO) encodeExtPreamble(xtag byte, length int) { - e.encLen(bincVdCustomExt<<4, uint64(length)) - e.w.writen1(xtag) -} - -func (e *bincEncDriverIO) WriteArrayStart(length int) { - e.encLen(bincVdArray<<4, uint64(length)) -} - -func (e *bincEncDriverIO) WriteMapStart(length int) { - e.encLen(bincVdMap<<4, uint64(length)) -} - -func (e *bincEncDriverIO) WriteArrayEmpty() { - - e.w.writen1(bincVdArray<<4 | uint8(0+4)) -} - -func (e *bincEncDriverIO) WriteMapEmpty() { - - e.w.writen1(bincVdMap<<4 | uint8(0+4)) -} - -func (e *bincEncDriverIO) EncodeSymbol(v string) { - - l := len(v) - if l == 0 { - e.encBytesLen(cUTF8, 0) - return - } else if l == 1 { - e.encBytesLen(cUTF8, 1) - e.w.writen1(v[0]) - return - } - if e.m == nil { - e.m = make(map[string]uint16, 16) - } - ui, ok := e.m[v] - if ok { - if ui <= math.MaxUint8 { - e.w.writen2(bincVdSymbol<<4, byte(ui)) - } else { - e.w.writen1(bincVdSymbol<<4 | 0x8) - e.w.writen2(bigen.PutUint16(ui)) - } - } else { - e.e.seq++ - ui = e.e.seq - e.m[v] = ui - var lenprec uint8 - if l <= math.MaxUint8 { - - } else if l <= math.MaxUint16 { - lenprec = 1 - } else if int64(l) <= math.MaxUint32 { - lenprec = 2 - } else { - lenprec = 3 - } - if ui <= math.MaxUint8 { - e.w.writen2(bincVdSymbol<<4|0x4|lenprec, byte(ui)) - } else { - e.w.writen1(bincVdSymbol<<4 | 0x8 | 0x4 | lenprec) - e.w.writen2(bigen.PutUint16(ui)) - } - if lenprec == 0 { - e.w.writen1(byte(l)) - } else if lenprec == 1 { - e.w.writen2(bigen.PutUint16(uint16(l))) - } else if lenprec == 2 { - e.w.writen4(bigen.PutUint32(uint32(l))) - } else { - e.w.writen8(bigen.PutUint64(uint64(l))) - } - e.w.writestr(v) - } -} - -func (e *bincEncDriverIO) EncodeString(v string) { - if e.h.StringToRaw { - e.encLen(bincVdByteArray<<4, uint64(len(v))) - if len(v) > 0 { - e.w.writestr(v) - } - return - } - e.EncodeStringEnc(cUTF8, v) -} - -func (e *bincEncDriverIO) EncodeStringNoEscape4Json(v string) { e.EncodeString(v) } - -func (e *bincEncDriverIO) EncodeStringEnc(c charEncoding, v string) { - if e.e.c == containerMapKey && c == cUTF8 && (e.h.AsSymbols == 1) { - e.EncodeSymbol(v) - return - } - e.encLen(bincVdString<<4, uint64(len(v))) - if len(v) > 0 { - e.w.writestr(v) - } -} - -func (e *bincEncDriverIO) EncodeStringBytesRaw(v []byte) { - e.encLen(bincVdByteArray<<4, uint64(len(v))) - if len(v) > 0 { - e.w.writeb(v) - } -} - -func (e *bincEncDriverIO) EncodeBytes(v []byte) { - if v == nil { - e.writeNilBytes() - return - } - e.EncodeStringBytesRaw(v) -} - -func (e *bincEncDriverIO) writeNilOr(v byte) { - if !e.h.NilCollectionToZeroLength { - v = bincBdNil - } - e.w.writen1(v) -} - -func (e *bincEncDriverIO) writeNilArray() { - e.writeNilOr(bincVdArray<<4 | uint8(0+4)) -} - -func (e *bincEncDriverIO) writeNilMap() { - e.writeNilOr(bincVdMap<<4 | uint8(0+4)) -} - -func (e *bincEncDriverIO) writeNilBytes() { - e.writeNilOr(bincVdArray<<4 | uint8(0+4)) -} - -func (e *bincEncDriverIO) encBytesLen(c charEncoding, length uint64) { - - if c == cRAW { - e.encLen(bincVdByteArray<<4, length) - } else { - e.encLen(bincVdString<<4, length) - } -} - -func (e *bincEncDriverIO) encLen(bd byte, l uint64) { - if l < 12 { - e.w.writen1(bd | uint8(l+4)) - } else { - e.encLenNumber(bd, l) - } -} - -func (e *bincEncDriverIO) encLenNumber(bd byte, v uint64) { - if v <= math.MaxUint8 { - e.w.writen2(bd, byte(v)) - } else if v <= math.MaxUint16 { - e.w.writen1(bd | 0x01) - e.w.writen2(bigen.PutUint16(uint16(v))) - } else if v <= math.MaxUint32 { - e.w.writen1(bd | 0x02) - e.w.writen4(bigen.PutUint32(uint32(v))) - } else { - e.w.writen1(bd | 0x03) - e.w.writen8(bigen.PutUint64(uint64(v))) - } -} - -func (d *bincDecDriverIO) readNextBd() { - d.bd = d.r.readn1() - d.vd = d.bd >> 4 - d.vs = d.bd & 0x0f - d.bdRead = true -} - -func (d *bincDecDriverIO) advanceNil() (null bool) { - if !d.bdRead { - d.readNextBd() - } - if d.bd == bincBdNil { - d.bdRead = false - return true - } - return -} - -func (d *bincDecDriverIO) TryNil() bool { - return d.advanceNil() -} - -func (d *bincDecDriverIO) ContainerType() (vt valueType) { - if !d.bdRead { - d.readNextBd() - } - if d.bd == bincBdNil { - d.bdRead = false - return valueTypeNil - } else if d.vd == bincVdByteArray { - return valueTypeBytes - } else if d.vd == bincVdString { - return valueTypeString - } else if d.vd == bincVdArray { - return valueTypeArray - } else if d.vd == bincVdMap { - return valueTypeMap - } - return valueTypeUnset -} - -func (d *bincDecDriverIO) DecodeTime() (t time.Time) { - if d.advanceNil() { - return - } - if d.vd != bincVdTimestamp { - halt.errorf("cannot decode time - %s %x-%x/%s", msgBadDesc, d.vd, d.vs, bincdesc(d.vd, d.vs)) - } - t, err := bincDecodeTime(d.r.readx(uint(d.vs))) - halt.onerror(err) - d.bdRead = false - return -} - -func (d *bincDecDriverIO) decFloatPruned(maxlen uint8) { - l := d.r.readn1() - if l > maxlen { - halt.errorf("cannot read float - at most %v bytes used to represent float - received %v bytes", maxlen, l) - } - for i := l; i < maxlen; i++ { - d.d.b[i] = 0 - } - d.r.readb(d.d.b[0:l]) -} - -func (d *bincDecDriverIO) decFloatPre32() (b [4]byte) { - if d.vs&0x8 == 0 { - b = d.r.readn4() - } else { - d.decFloatPruned(4) - copy(b[:], d.d.b[:]) - } - return -} - -func (d *bincDecDriverIO) decFloatPre64() (b [8]byte) { - if d.vs&0x8 == 0 { - b = d.r.readn8() - } else { - d.decFloatPruned(8) - copy(b[:], d.d.b[:]) - } - return -} - -func (d *bincDecDriverIO) decFloatVal() (f float64) { - switch d.vs & 0x7 { - case bincFlBin32: - f = float64(math.Float32frombits(bigen.Uint32(d.decFloatPre32()))) - case bincFlBin64: - f = math.Float64frombits(bigen.Uint64(d.decFloatPre64())) - default: - - halt.errorf("read float supports only float32/64 - %s %x-%x/%s", msgBadDesc, d.vd, d.vs, bincdesc(d.vd, d.vs)) - } - return -} - -func (d *bincDecDriverIO) decUint() (v uint64) { - switch d.vs { - case 0: - v = uint64(d.r.readn1()) - case 1: - v = uint64(bigen.Uint16(d.r.readn2())) - case 2: - b3 := d.r.readn3() - var b [4]byte - copy(b[1:], b3[:]) - v = uint64(bigen.Uint32(b)) - case 3: - v = uint64(bigen.Uint32(d.r.readn4())) - case 4, 5, 6: - - bs := d.d.b[:8] - clear(bs) - d.r.readb(bs[(7 - d.vs):]) - v = bigen.Uint64(*(*[8]byte)(bs)) - case 7: - v = bigen.Uint64(d.r.readn8()) - default: - halt.errorf("unsigned integers with greater than 64 bits of precision not supported: d.vs: %v %x", d.vs, d.vs) - } - return -} - -func (d *bincDecDriverIO) uintBytes() (bs []byte) { - switch d.vs { - case 0: - bs = d.d.b[:1] - bs[0] = d.r.readn1() - return - case 1: - bs = d.d.b[:2] - case 2: - bs = d.d.b[:3] - case 3: - bs = d.d.b[:4] - case 4, 5, 6: - lim := 7 - d.vs - bs = d.d.b[lim:8] - case 7: - bs = d.d.b[:8] - default: - halt.errorf("unsigned integers with greater than 64 bits of precision not supported: d.vs: %v %x", d.vs, d.vs) - } - d.r.readb(bs) - return -} - -func (d *bincDecDriverIO) decInteger() (ui uint64, neg, ok bool) { - ok = true - vd, vs := d.vd, d.vs - if vd == bincVdPosInt { - ui = d.decUint() - } else if vd == bincVdNegInt { - ui = d.decUint() - neg = true - } else if vd == bincVdSmallInt { - ui = uint64(d.vs) + 1 - } else if vd == bincVdSpecial { - if vs == bincSpZero { - - } else if vs == bincSpNegOne { - neg = true - ui = 1 - } else { - ok = false - - } - } else { - ok = false - - } - return -} - -func (d *bincDecDriverIO) decFloat() (f float64, ok bool) { - ok = true - vd, vs := d.vd, d.vs - if vd == bincVdSpecial { - if vs == bincSpNan { - f = math.NaN() - } else if vs == bincSpPosInf { - f = math.Inf(1) - } else if vs == bincSpZeroFloat || vs == bincSpZero { - - } else if vs == bincSpNegInf { - f = math.Inf(-1) - } else { - ok = false - - } - } else if vd == bincVdFloat { - f = d.decFloatVal() - } else { - ok = false - } - return -} - -func (d *bincDecDriverIO) DecodeInt64() (i int64) { - if d.advanceNil() { - return - } - v1, v2, v3 := d.decInteger() - i = decNegintPosintFloatNumberHelper{d}.int64(v1, v2, v3, false) - d.bdRead = false - return -} - -func (d *bincDecDriverIO) DecodeUint64() (ui uint64) { - if d.advanceNil() { - return - } - ui = decNegintPosintFloatNumberHelper{d}.uint64(d.decInteger()) - d.bdRead = false - return -} - -func (d *bincDecDriverIO) DecodeFloat64() (f float64) { - if d.advanceNil() { - return - } - v1, v2 := d.decFloat() - f = decNegintPosintFloatNumberHelper{d}.float64(v1, v2, false) - d.bdRead = false - return -} - -func (d *bincDecDriverIO) DecodeBool() (b bool) { - if d.advanceNil() { - return - } - if d.bd == (bincVdSpecial | bincSpFalse) { - - } else if d.bd == (bincVdSpecial | bincSpTrue) { - b = true - } else { - halt.errorf("bool - %s %x-%x/%s", msgBadDesc, d.vd, d.vs, bincdesc(d.vd, d.vs)) - } - d.bdRead = false - return -} - -func (d *bincDecDriverIO) ReadMapStart() (length int) { - if d.advanceNil() { - return containerLenNil - } - if d.vd != bincVdMap { - halt.errorf("map - %s %x-%x/%s", msgBadDesc, d.vd, d.vs, bincdesc(d.vd, d.vs)) - } - length = d.decLen() - d.bdRead = false - return -} - -func (d *bincDecDriverIO) ReadArrayStart() (length int) { - if d.advanceNil() { - return containerLenNil - } - if d.vd != bincVdArray { - halt.errorf("array - %s %x-%x/%s", msgBadDesc, d.vd, d.vs, bincdesc(d.vd, d.vs)) - } - length = d.decLen() - d.bdRead = false - return -} - -func (d *bincDecDriverIO) decLen() int { - if d.vs > 3 { - return int(d.vs - 4) - } - return int(d.decLenNumber()) -} - -func (d *bincDecDriverIO) decLenNumber() (v uint64) { - if x := d.vs; x == 0 { - v = uint64(d.r.readn1()) - } else if x == 1 { - v = uint64(bigen.Uint16(d.r.readn2())) - } else if x == 2 { - v = uint64(bigen.Uint32(d.r.readn4())) - } else { - v = bigen.Uint64(d.r.readn8()) - } - return -} - -func (d *bincDecDriverIO) DecodeStringAsBytes() (bs []byte, state dBytesAttachState) { - if d.advanceNil() { - return - } - var cond bool - var slen = -1 - switch d.vd { - case bincVdString, bincVdByteArray: - slen = d.decLen() - bs, cond = d.r.readxb(uint(slen)) - state = d.d.attachState(cond) - case bincVdSymbol: - - var symbol uint16 - vs := d.vs - if vs&0x8 == 0 { - symbol = uint16(d.r.readn1()) - } else { - symbol = uint16(bigen.Uint16(d.r.readn2())) - } - if d.s == nil { - d.s = make(map[uint16][]byte, 16) - } - - if vs&0x4 == 0 { - bs = d.s[symbol] - } else { - switch vs & 0x3 { - case 0: - slen = int(d.r.readn1()) - case 1: - slen = int(bigen.Uint16(d.r.readn2())) - case 2: - slen = int(bigen.Uint32(d.r.readn4())) - case 3: - slen = int(bigen.Uint64(d.r.readn8())) - } - - bs, cond = d.r.readxb(uint(slen)) - bs = d.d.detach2Bytes(bs, d.d.attachState(cond)) - d.s[symbol] = bs - } - state = dBytesDetach - default: - halt.errorf("string/bytes - %s %x-%x/%s", msgBadDesc, d.vd, d.vs, bincdesc(d.vd, d.vs)) - } - - if d.h.ValidateUnicode && !utf8.Valid(bs) { - halt.errorf("DecodeStringAsBytes: invalid UTF-8: %s", bs) - } - - d.bdRead = false - return -} - -func (d *bincDecDriverIO) DecodeBytes() (bs []byte, state dBytesAttachState) { - if d.advanceNil() { - return - } - var cond bool - if d.vd == bincVdArray { - slen := d.ReadArrayStart() - bs, cond = usableByteSlice(d.d.buf, slen) - for i := 0; i < slen; i++ { - bs[i] = uint8(chkOvf.UintV(d.DecodeUint64(), 8)) - } - for i := len(bs); i < slen; i++ { - bs = append(bs, uint8(chkOvf.UintV(d.DecodeUint64(), 8))) - } - if cond { - d.d.buf = bs - } - state = dBytesAttachBuffer - return - } - if !(d.vd == bincVdString || d.vd == bincVdByteArray) { - halt.errorf("bytes - %s %x-%x/%s", msgBadDesc, d.vd, d.vs, bincdesc(d.vd, d.vs)) - } - clen := d.decLen() - d.bdRead = false - bs, cond = d.r.readxb(uint(clen)) - state = d.d.attachState(cond) - return -} - -func (d *bincDecDriverIO) DecodeExt(rv interface{}, basetype reflect.Type, xtag uint64, ext Ext) { - xbs, _, _, ok := d.decodeExtV(ext != nil, xtag) - if !ok { - return - } - if ext == SelfExt { - sideDecode(d.h, &d.h.sideDecPool, func(sd decoderI) { oneOffDecode(sd, rv, xbs, basetype, true) }) - } else { - ext.ReadExt(rv, xbs) - } -} - -func (d *bincDecDriverIO) DecodeRawExt(re *RawExt) { - xbs, realxtag, state, ok := d.decodeExtV(false, 0) - if !ok { - return - } - re.Tag = uint64(realxtag) - re.setData(xbs, state >= dBytesAttachViewZerocopy) -} - -func (d *bincDecDriverIO) decodeExtV(verifyTag bool, xtagIn uint64) (xbs []byte, xtag byte, bstate dBytesAttachState, ok bool) { - if xtagIn > 0xff { - halt.errorf("ext: tag must be <= 0xff; got: %v", xtagIn) - } - if d.advanceNil() { - return - } - tag := uint8(xtagIn) - if d.vd == bincVdCustomExt { - l := d.decLen() - xtag = d.r.readn1() - if verifyTag && xtag != tag { - halt.errorf("wrong extension tag - got %b, expecting: %v", xtag, tag) - } - xbs, ok = d.r.readxb(uint(l)) - bstate = d.d.attachState(ok) - - } else if d.vd == bincVdByteArray { - xbs, bstate = d.DecodeBytes() - } else { - halt.errorf("ext expects extensions or byte array - %s %x-%x/%s", msgBadDesc, d.vd, d.vs, bincdesc(d.vd, d.vs)) - } - d.bdRead = false - ok = true - return -} - -func (d *bincDecDriverIO) DecodeNaked() { - if !d.bdRead { - d.readNextBd() - } - - n := d.d.naked() - var decodeFurther bool - - switch d.vd { - case bincVdSpecial: - switch d.vs { - case bincSpNil: - n.v = valueTypeNil - case bincSpFalse: - n.v = valueTypeBool - n.b = false - case bincSpTrue: - n.v = valueTypeBool - n.b = true - case bincSpNan: - n.v = valueTypeFloat - n.f = math.NaN() - case bincSpPosInf: - n.v = valueTypeFloat - n.f = math.Inf(1) - case bincSpNegInf: - n.v = valueTypeFloat - n.f = math.Inf(-1) - case bincSpZeroFloat: - n.v = valueTypeFloat - n.f = float64(0) - case bincSpZero: - n.v = valueTypeUint - n.u = uint64(0) - case bincSpNegOne: - n.v = valueTypeInt - n.i = int64(-1) - default: - halt.errorf("cannot infer value - unrecognized special value %x-%x/%s", d.vd, d.vs, bincdesc(d.vd, d.vs)) - } - case bincVdSmallInt: - n.v = valueTypeUint - n.u = uint64(int8(d.vs)) + 1 - case bincVdPosInt: - n.v = valueTypeUint - n.u = d.decUint() - case bincVdNegInt: - n.v = valueTypeInt - n.i = -(int64(d.decUint())) - case bincVdFloat: - n.v = valueTypeFloat - n.f = d.decFloatVal() - case bincVdString: - n.v = valueTypeString - n.s = d.d.detach2Str(d.DecodeStringAsBytes()) - case bincVdByteArray: - d.d.fauxUnionReadRawBytes(d, false, d.h.RawToString) - case bincVdSymbol: - n.v = valueTypeSymbol - n.s = d.d.detach2Str(d.DecodeStringAsBytes()) - case bincVdTimestamp: - n.v = valueTypeTime - tt, err := bincDecodeTime(d.r.readx(uint(d.vs))) - halt.onerror(err) - n.t = tt - case bincVdCustomExt: - n.v = valueTypeExt - l := d.decLen() - n.u = uint64(d.r.readn1()) - n.l = d.r.readx(uint(l)) - case bincVdArray: - n.v = valueTypeArray - decodeFurther = true - case bincVdMap: - n.v = valueTypeMap - decodeFurther = true - default: - halt.errorf("cannot infer value - %s %x-%x/%s", msgBadDesc, d.vd, d.vs, bincdesc(d.vd, d.vs)) - } - - if !decodeFurther { - d.bdRead = false - } - if n.v == valueTypeUint && d.h.SignedInteger { - n.v = valueTypeInt - n.i = int64(n.u) - } -} - -func (d *bincDecDriverIO) nextValueBytes() (v []byte) { - if !d.bdRead { - d.readNextBd() - } - d.r.startRecording() - d.nextValueBytesBdReadR() - v = d.r.stopRecording() - d.bdRead = false - return -} - -func (d *bincDecDriverIO) nextValueBytesBdReadR() { - fnLen := func(vs byte) uint { - switch vs { - case 0: - x := d.r.readn1() - return uint(x) - case 1: - x := d.r.readn2() - return uint(bigen.Uint16(x)) - case 2: - x := d.r.readn4() - return uint(bigen.Uint32(x)) - case 3: - x := d.r.readn8() - return uint(bigen.Uint64(x)) - default: - return uint(vs - 4) - } - } - - var clen uint - - switch d.vd { - case bincVdSpecial: - switch d.vs { - case bincSpNil, bincSpFalse, bincSpTrue, bincSpNan, bincSpPosInf: - case bincSpNegInf, bincSpZeroFloat, bincSpZero, bincSpNegOne: - default: - halt.errorf("cannot infer value - unrecognized special value %x-%x/%s", d.vd, d.vs, bincdesc(d.vd, d.vs)) - } - case bincVdSmallInt: - case bincVdPosInt, bincVdNegInt: - d.uintBytes() - case bincVdFloat: - fn := func(xlen byte) { - if d.vs&0x8 != 0 { - xlen = d.r.readn1() - if xlen > 8 { - halt.errorf("cannot read float - at most 8 bytes used to represent float - received %v bytes", xlen) - } - } - d.r.readb(d.d.b[:xlen]) - } - switch d.vs & 0x7 { - case bincFlBin32: - fn(4) - case bincFlBin64: - fn(8) - default: - halt.errorf("read float supports only float32/64 - %s %x-%x/%s", msgBadDesc, d.vd, d.vs, bincdesc(d.vd, d.vs)) - } - case bincVdString, bincVdByteArray: - clen = fnLen(d.vs) - d.r.skip(clen) - case bincVdSymbol: - if d.vs&0x8 == 0 { - d.r.readn1() - } else { - d.r.skip(2) - } - if d.vs&0x4 != 0 { - clen = fnLen(d.vs & 0x3) - d.r.skip(clen) - } - case bincVdTimestamp: - d.r.skip(uint(d.vs)) - case bincVdCustomExt: - clen = fnLen(d.vs) - d.r.readn1() - d.r.skip(clen) - case bincVdArray: - clen = fnLen(d.vs) - for i := uint(0); i < clen; i++ { - d.readNextBd() - d.nextValueBytesBdReadR() - } - case bincVdMap: - clen = fnLen(d.vs) - for i := uint(0); i < clen; i++ { - d.readNextBd() - d.nextValueBytesBdReadR() - d.readNextBd() - d.nextValueBytesBdReadR() - } - default: - halt.errorf("cannot infer value - %s %x-%x/%s", msgBadDesc, d.vd, d.vs, bincdesc(d.vd, d.vs)) - } - return -} - -func (d *bincEncDriverIO) init(hh Handle, shared *encoderBase, enc encoderI) (fp interface{}) { - callMake(&d.w) - d.h = hh.(*BincHandle) - d.e = shared - if shared.bytes { - fp = bincFpEncBytes - } else { - fp = bincFpEncIO - } - - d.init2(enc) - return -} - -func (e *bincEncDriverIO) writeBytesAsis(b []byte) { e.w.writeb(b) } - -func (e *bincEncDriverIO) writerEnd() { e.w.end() } - -func (e *bincEncDriverIO) resetOutBytes(out *[]byte) { - e.w.resetBytes(*out, out) -} - -func (e *bincEncDriverIO) resetOutIO(out io.Writer) { - e.w.resetIO(out, e.h.WriterBufferSize, &e.e.blist) -} - -func (d *bincDecDriverIO) init(hh Handle, shared *decoderBase, dec decoderI) (fp interface{}) { - callMake(&d.r) - d.h = hh.(*BincHandle) - d.d = shared - if shared.bytes { - fp = bincFpDecBytes - } else { - fp = bincFpDecIO - } - - d.init2(dec) - return -} - -func (d *bincDecDriverIO) NumBytesRead() int { - return int(d.r.numread()) -} - -func (d *bincDecDriverIO) resetInBytes(in []byte) { - d.r.resetBytes(in) -} - -func (d *bincDecDriverIO) resetInIO(r io.Reader) { - d.r.resetIO(r, d.h.ReaderBufferSize, d.h.MaxInitLen, &d.d.blist) -} - -func (d *bincDecDriverIO) descBd() string { - return sprintf("%v (%s)", d.bd, bincdescbd(d.bd)) -} - -func (d *bincDecDriverIO) DecodeFloat32() (f float32) { - return float32(chkOvf.Float32V(d.DecodeFloat64())) -} diff --git a/vendor/github.com/ugorji/go/codec/binc.notfastpath.mono.generated.go b/vendor/github.com/ugorji/go/codec/binc.notfastpath.mono.generated.go deleted file mode 100644 index ca893afcd..000000000 --- a/vendor/github.com/ugorji/go/codec/binc.notfastpath.mono.generated.go +++ /dev/null @@ -1,52 +0,0 @@ -//go:build !notmono && !codec.notmono && (notfastpath || codec.notfastpath) - -// Copyright (c) 2012-2020 Ugorji Nwoke. All rights reserved. -// Use of this source code is governed by a MIT license found in the LICENSE file. - -package codec - -import ( - "reflect" -) - -type fastpathEBincBytes struct { - rt reflect.Type - encfn func(*encoderBincBytes, *encFnInfo, reflect.Value) -} -type fastpathDBincBytes struct { - rt reflect.Type - decfn func(*decoderBincBytes, *decFnInfo, reflect.Value) -} -type fastpathEsBincBytes [0]fastpathEBincBytes -type fastpathDsBincBytes [0]fastpathDBincBytes - -func (helperEncDriverBincBytes) fastpathEncodeTypeSwitch(iv interface{}, e *encoderBincBytes) bool { - return false -} -func (helperDecDriverBincBytes) fastpathDecodeTypeSwitch(iv interface{}, d *decoderBincBytes) bool { - return false -} - -func (helperEncDriverBincBytes) fastpathEList() (v *fastpathEsBincBytes) { return } -func (helperDecDriverBincBytes) fastpathDList() (v *fastpathDsBincBytes) { return } - -type fastpathEBincIO struct { - rt reflect.Type - encfn func(*encoderBincIO, *encFnInfo, reflect.Value) -} -type fastpathDBincIO struct { - rt reflect.Type - decfn func(*decoderBincIO, *decFnInfo, reflect.Value) -} -type fastpathEsBincIO [0]fastpathEBincIO -type fastpathDsBincIO [0]fastpathDBincIO - -func (helperEncDriverBincIO) fastpathEncodeTypeSwitch(iv interface{}, e *encoderBincIO) bool { - return false -} -func (helperDecDriverBincIO) fastpathDecodeTypeSwitch(iv interface{}, d *decoderBincIO) bool { - return false -} - -func (helperEncDriverBincIO) fastpathEList() (v *fastpathEsBincIO) { return } -func (helperDecDriverBincIO) fastpathDList() (v *fastpathDsBincIO) { return } diff --git a/vendor/github.com/ugorji/go/codec/build.sh b/vendor/github.com/ugorji/go/codec/build.sh deleted file mode 100644 index 5214c7b03..000000000 --- a/vendor/github.com/ugorji/go/codec/build.sh +++ /dev/null @@ -1,219 +0,0 @@ -#!/bin/bash - -# Build and Run the different test permutations. -# This helps validate that nothing gets broken. - -_build_proceed() { - # return success (0) if we should, and 1 (fail) if not - if [[ "${zforce}" ]]; then return 0; fi - for a in "fastpath.generated.go" "json.mono.generated.go"; do - if [[ ! -e "$a" ]]; then return 0; fi - for b in `ls -1 *.go.tmpl gen.go gen_mono.go values_test.go`; do - if [[ "$a" -ot "$b" ]]; then return 0; fi - done - done - return 1 -} - -# _build generates fastpath.go -_build() { - # if ! [[ "${zforce}" || $(_ng "fastpath.generated.go") || $(_ng "json.mono.generated.go") ]]; then return 0; fi - _build_proceed - if [ $? -eq 1 ]; then return 0; fi - if [ "${zbak}" ]; then - _zts=`date '+%m%d%Y_%H%M%S'` - _gg=".generated.go" - [ -e "fastpath${_gg}" ] && mv fastpath${_gg} fastpath${_gg}__${_zts}.bak - [ -e "gen${_gg}" ] && mv gen${_gg} gen${_gg}__${_zts}.bak - fi - - rm -f fast*path.generated.go *mono*generated.go *_generated_test.go gen-from-tmpl*.generated.go - - local btags="codec.build codec.notmono codec.safe codec.notfastpath" - - cat > gen-from-tmpl.codec.generated.go < gen-from-tmpl.generated.go <>>> TAGS: 'alltests $i'; RUN: 'TestCodecSuite'" - _tests_run_one - [[ "$zwait" == "1" ]] && wait - # if [[ "$?" != 0 ]]; then return 1; fi - done - wait - [[ "$zcover" == "1" ]] && - echo "go tool covdata output" && - ${gocmd} tool covdata percent -i $covdir && - ${gocmd} tool covdata textfmt -i $covdir -o __cov.out && - ${gocmd} tool cover -html=__cov.out -} - -_usage() { - # hidden args: - # -pf [p=prebuild (f=force)] - - cat < t=tests [e=extra, s=short, o=cover, w=wait] - -[md] -> [m=make, d=race detector] - -v -> v=verbose (more v's to increase verbose level) -EOF - if [[ "$(type -t _usage_run)" = "function" ]]; then _usage_run ; fi -} - -_main() { - if [[ -z "$1" ]]; then _usage; return 1; fi - local x # determines the main action to run in this build - local zforce # force - local zcover # generate cover profile and show in browser when done - local zwait # run tests in sequence, not parallel ie wait for one to finish before starting another - local zextra # means run extra (python based tests, etc) during testing - - local ztestargs=() - local zargs=() - local zverbose=() - local zbenchflags="" - - local gocmd=${MYGOCMD:-go} - - OPTIND=1 - while getopts ":cetmnrgpfvldsowikxyz" flag - do - case "x$flag" in - 'xw') zwait=1 ;; - 'xv') zverbose+=(1) ;; - 'xo') zcover=1 ;; - 'xe') zextra=1 ;; - 'xf') zforce=1 ;; - 'xs') ztestargs+=("-short") ;; - 'xl') zargs+=("-gcflags"); zargs+=("-l=4") ;; - 'xn') zargs+=("-gcflags"); zargs+=("-m=2") ;; - 'xd') zargs+=("-race") ;; - # 'xi') x='i'; zbenchflags=${OPTARG} ;; - x\?) _usage; return 1 ;; - *) x=$flag ;; - esac - done - shift $((OPTIND-1)) - # echo ">>>> _main: extra args: $@" - case "x$x" in - 'xt') _tests "$@" ;; - 'xm') _make "$@" ;; - 'xr') _release "$@" ;; - 'xg') _go ;; - 'xp') _prebuild "$@" ;; - 'xc') _clean "$@" ;; - esac - - # handle from local run.sh - case "x$x" in - 'xi') _check_inlining_one "$@" ;; - 'xk') _go_compiler_validation_suite ;; - 'xx') _analyze_checks "$@" ;; - 'xy') _analyze_debug_types "$@" ;; - 'xz') _analyze_do_inlining_and_more "$@" ;; - esac - # unset zforce zargs zbenchflags -} - -[ "." = `dirname $0` ] && _main "$@" - -# _xtrace() { -# local - -# set -x -# "${@}" -# } diff --git a/vendor/github.com/ugorji/go/codec/cbor.base.go b/vendor/github.com/ugorji/go/codec/cbor.base.go deleted file mode 100644 index fad562a63..000000000 --- a/vendor/github.com/ugorji/go/codec/cbor.base.go +++ /dev/null @@ -1,160 +0,0 @@ -// Copyright (c) 2012-2020 Ugorji Nwoke. All rights reserved. -// Use of this source code is governed by a MIT license found in the LICENSE file. - -package codec - -import ( - "reflect" -) - -// major -const ( - cborMajorUint byte = iota - cborMajorNegInt - cborMajorBytes - cborMajorString - cborMajorArray - cborMajorMap - cborMajorTag - cborMajorSimpleOrFloat -) - -// simple -const ( - cborBdFalse byte = 0xf4 + iota - cborBdTrue - cborBdNil - cborBdUndefined - cborBdExt - cborBdFloat16 - cborBdFloat32 - cborBdFloat64 -) - -// indefinite -const ( - cborBdIndefiniteBytes byte = 0x5f - cborBdIndefiniteString byte = 0x7f - cborBdIndefiniteArray byte = 0x9f - cborBdIndefiniteMap byte = 0xbf - cborBdBreak byte = 0xff -) - -// These define some in-stream descriptors for -// manual encoding e.g. when doing explicit indefinite-length -const ( - CborStreamBytes byte = 0x5f - CborStreamString byte = 0x7f - CborStreamArray byte = 0x9f - CborStreamMap byte = 0xbf - CborStreamBreak byte = 0xff -) - -// base values -const ( - cborBaseUint byte = 0x00 - cborBaseNegInt byte = 0x20 - cborBaseBytes byte = 0x40 - cborBaseString byte = 0x60 - cborBaseArray byte = 0x80 - cborBaseMap byte = 0xa0 - cborBaseTag byte = 0xc0 - cborBaseSimple byte = 0xe0 -) - -// const ( -// cborSelfDesrTag byte = 0xd9 -// cborSelfDesrTag2 byte = 0xd9 -// cborSelfDesrTag3 byte = 0xf7 -// ) - -var ( - cbordescSimpleNames = map[byte]string{ - cborBdNil: "nil", - cborBdFalse: "false", - cborBdTrue: "true", - cborBdFloat16: "float", - cborBdFloat32: "float", - cborBdFloat64: "float", - cborBdBreak: "break", - } - cbordescIndefNames = map[byte]string{ - cborBdIndefiniteBytes: "bytes*", - cborBdIndefiniteString: "string*", - cborBdIndefiniteArray: "array*", - cborBdIndefiniteMap: "map*", - } - cbordescMajorNames = map[byte]string{ - cborMajorUint: "(u)int", - cborMajorNegInt: "int", - cborMajorBytes: "bytes", - cborMajorString: "string", - cborMajorArray: "array", - cborMajorMap: "map", - cborMajorTag: "tag", - cborMajorSimpleOrFloat: "simple", - } -) - -func cbordesc(bd byte) (s string) { - bm := bd >> 5 - if bm == cborMajorSimpleOrFloat { - s = cbordescSimpleNames[bd] - } else { - s = cbordescMajorNames[bm] - if s == "" { - s = cbordescIndefNames[bd] - } - } - if s == "" { - s = "unknown" - } - return -} - -// ------------------------- - -// CborHandle is a Handle for the CBOR encoding format, -// defined at http://tools.ietf.org/html/rfc7049 and documented further at http://cbor.io . -// -// CBOR is comprehensively supported, including support for: -// - indefinite-length arrays/maps/bytes/strings -// - (extension) tags in range 0..0xffff (0 .. 65535) -// - half, single and double-precision floats -// - all numbers (1, 2, 4 and 8-byte signed and unsigned integers) -// - nil, true, false, ... -// - arrays and maps, bytes and text strings -// -// None of the optional extensions (with tags) defined in the spec are supported out-of-the-box. -// Users can implement them as needed (using SetExt), including spec-documented ones: -// - timestamp, BigNum, BigFloat, Decimals, -// - Encoded Text (e.g. URL, regexp, base64, MIME Message), etc. -type CborHandle struct { - binaryEncodingType - notJsonType - // noElemSeparators - BasicHandle - - // IndefiniteLength=true, means that we encode using indefinitelength - IndefiniteLength bool - - // TimeRFC3339 says to encode time.Time using RFC3339 format. - // If unset, we encode time.Time using seconds past epoch. - TimeRFC3339 bool - - // SkipUnexpectedTags says to skip over any tags for which extensions are - // not defined. This is in keeping with the cbor spec on "Optional Tagging of Items". - // - // Furthermore, this allows the skipping over of the Self Describing Tag 0xd9d9f7. - SkipUnexpectedTags bool -} - -// Name returns the name of the handle: cbor -func (h *CborHandle) Name() string { return "cbor" } - -func (h *CborHandle) desc(bd byte) string { return cbordesc(bd) } - -// SetInterfaceExt sets an extension -func (h *CborHandle) SetInterfaceExt(rt reflect.Type, tag uint64, ext InterfaceExt) (err error) { - return h.SetExt(rt, tag, makeExt(ext)) -} diff --git a/vendor/github.com/ugorji/go/codec/cbor.fastpath.mono.generated.go b/vendor/github.com/ugorji/go/codec/cbor.fastpath.mono.generated.go deleted file mode 100644 index d9456f3e8..000000000 --- a/vendor/github.com/ugorji/go/codec/cbor.fastpath.mono.generated.go +++ /dev/null @@ -1,12482 +0,0 @@ -//go:build !notmono && !codec.notmono && !notfastpath && !codec.notfastpath - -// Copyright (c) 2012-2020 Ugorji Nwoke. All rights reserved. -// Use of this source code is governed by a MIT license found in the LICENSE file. - -package codec - -import ( - "reflect" - "slices" - "sort" -) - -type fastpathECborBytes struct { - rtid uintptr - rt reflect.Type - encfn func(*encoderCborBytes, *encFnInfo, reflect.Value) -} -type fastpathDCborBytes struct { - rtid uintptr - rt reflect.Type - decfn func(*decoderCborBytes, *decFnInfo, reflect.Value) -} -type fastpathEsCborBytes [56]fastpathECborBytes -type fastpathDsCborBytes [56]fastpathDCborBytes -type fastpathETCborBytes struct{} -type fastpathDTCborBytes struct{} - -func (helperEncDriverCborBytes) fastpathEList() *fastpathEsCborBytes { - var i uint = 0 - var s fastpathEsCborBytes - fn := func(v interface{}, fe func(*encoderCborBytes, *encFnInfo, reflect.Value)) { - xrt := reflect.TypeOf(v) - s[i] = fastpathECborBytes{rt2id(xrt), xrt, fe} - i++ - } - - fn([]interface{}(nil), (*encoderCborBytes).fastpathEncSliceIntfR) - fn([]string(nil), (*encoderCborBytes).fastpathEncSliceStringR) - fn([][]byte(nil), (*encoderCborBytes).fastpathEncSliceBytesR) - fn([]float32(nil), (*encoderCborBytes).fastpathEncSliceFloat32R) - fn([]float64(nil), (*encoderCborBytes).fastpathEncSliceFloat64R) - fn([]uint8(nil), (*encoderCborBytes).fastpathEncSliceUint8R) - fn([]uint64(nil), (*encoderCborBytes).fastpathEncSliceUint64R) - fn([]int(nil), (*encoderCborBytes).fastpathEncSliceIntR) - fn([]int32(nil), (*encoderCborBytes).fastpathEncSliceInt32R) - fn([]int64(nil), (*encoderCborBytes).fastpathEncSliceInt64R) - fn([]bool(nil), (*encoderCborBytes).fastpathEncSliceBoolR) - - fn(map[string]interface{}(nil), (*encoderCborBytes).fastpathEncMapStringIntfR) - fn(map[string]string(nil), (*encoderCborBytes).fastpathEncMapStringStringR) - fn(map[string][]byte(nil), (*encoderCborBytes).fastpathEncMapStringBytesR) - fn(map[string]uint8(nil), (*encoderCborBytes).fastpathEncMapStringUint8R) - fn(map[string]uint64(nil), (*encoderCborBytes).fastpathEncMapStringUint64R) - fn(map[string]int(nil), (*encoderCborBytes).fastpathEncMapStringIntR) - fn(map[string]int32(nil), (*encoderCborBytes).fastpathEncMapStringInt32R) - fn(map[string]float64(nil), (*encoderCborBytes).fastpathEncMapStringFloat64R) - fn(map[string]bool(nil), (*encoderCborBytes).fastpathEncMapStringBoolR) - fn(map[uint8]interface{}(nil), (*encoderCborBytes).fastpathEncMapUint8IntfR) - fn(map[uint8]string(nil), (*encoderCborBytes).fastpathEncMapUint8StringR) - fn(map[uint8][]byte(nil), (*encoderCborBytes).fastpathEncMapUint8BytesR) - fn(map[uint8]uint8(nil), (*encoderCborBytes).fastpathEncMapUint8Uint8R) - fn(map[uint8]uint64(nil), (*encoderCborBytes).fastpathEncMapUint8Uint64R) - fn(map[uint8]int(nil), (*encoderCborBytes).fastpathEncMapUint8IntR) - fn(map[uint8]int32(nil), (*encoderCborBytes).fastpathEncMapUint8Int32R) - fn(map[uint8]float64(nil), (*encoderCborBytes).fastpathEncMapUint8Float64R) - fn(map[uint8]bool(nil), (*encoderCborBytes).fastpathEncMapUint8BoolR) - fn(map[uint64]interface{}(nil), (*encoderCborBytes).fastpathEncMapUint64IntfR) - fn(map[uint64]string(nil), (*encoderCborBytes).fastpathEncMapUint64StringR) - fn(map[uint64][]byte(nil), (*encoderCborBytes).fastpathEncMapUint64BytesR) - fn(map[uint64]uint8(nil), (*encoderCborBytes).fastpathEncMapUint64Uint8R) - fn(map[uint64]uint64(nil), (*encoderCborBytes).fastpathEncMapUint64Uint64R) - fn(map[uint64]int(nil), (*encoderCborBytes).fastpathEncMapUint64IntR) - fn(map[uint64]int32(nil), (*encoderCborBytes).fastpathEncMapUint64Int32R) - fn(map[uint64]float64(nil), (*encoderCborBytes).fastpathEncMapUint64Float64R) - fn(map[uint64]bool(nil), (*encoderCborBytes).fastpathEncMapUint64BoolR) - fn(map[int]interface{}(nil), (*encoderCborBytes).fastpathEncMapIntIntfR) - fn(map[int]string(nil), (*encoderCborBytes).fastpathEncMapIntStringR) - fn(map[int][]byte(nil), (*encoderCborBytes).fastpathEncMapIntBytesR) - fn(map[int]uint8(nil), (*encoderCborBytes).fastpathEncMapIntUint8R) - fn(map[int]uint64(nil), (*encoderCborBytes).fastpathEncMapIntUint64R) - fn(map[int]int(nil), (*encoderCborBytes).fastpathEncMapIntIntR) - fn(map[int]int32(nil), (*encoderCborBytes).fastpathEncMapIntInt32R) - fn(map[int]float64(nil), (*encoderCborBytes).fastpathEncMapIntFloat64R) - fn(map[int]bool(nil), (*encoderCborBytes).fastpathEncMapIntBoolR) - fn(map[int32]interface{}(nil), (*encoderCborBytes).fastpathEncMapInt32IntfR) - fn(map[int32]string(nil), (*encoderCborBytes).fastpathEncMapInt32StringR) - fn(map[int32][]byte(nil), (*encoderCborBytes).fastpathEncMapInt32BytesR) - fn(map[int32]uint8(nil), (*encoderCborBytes).fastpathEncMapInt32Uint8R) - fn(map[int32]uint64(nil), (*encoderCborBytes).fastpathEncMapInt32Uint64R) - fn(map[int32]int(nil), (*encoderCborBytes).fastpathEncMapInt32IntR) - fn(map[int32]int32(nil), (*encoderCborBytes).fastpathEncMapInt32Int32R) - fn(map[int32]float64(nil), (*encoderCborBytes).fastpathEncMapInt32Float64R) - fn(map[int32]bool(nil), (*encoderCborBytes).fastpathEncMapInt32BoolR) - - sort.Slice(s[:], func(i, j int) bool { return s[i].rtid < s[j].rtid }) - return &s -} - -func (helperDecDriverCborBytes) fastpathDList() *fastpathDsCborBytes { - var i uint = 0 - var s fastpathDsCborBytes - fn := func(v interface{}, fd func(*decoderCborBytes, *decFnInfo, reflect.Value)) { - xrt := reflect.TypeOf(v) - s[i] = fastpathDCborBytes{rt2id(xrt), xrt, fd} - i++ - } - - fn([]interface{}(nil), (*decoderCborBytes).fastpathDecSliceIntfR) - fn([]string(nil), (*decoderCborBytes).fastpathDecSliceStringR) - fn([][]byte(nil), (*decoderCborBytes).fastpathDecSliceBytesR) - fn([]float32(nil), (*decoderCborBytes).fastpathDecSliceFloat32R) - fn([]float64(nil), (*decoderCborBytes).fastpathDecSliceFloat64R) - fn([]uint8(nil), (*decoderCborBytes).fastpathDecSliceUint8R) - fn([]uint64(nil), (*decoderCborBytes).fastpathDecSliceUint64R) - fn([]int(nil), (*decoderCborBytes).fastpathDecSliceIntR) - fn([]int32(nil), (*decoderCborBytes).fastpathDecSliceInt32R) - fn([]int64(nil), (*decoderCborBytes).fastpathDecSliceInt64R) - fn([]bool(nil), (*decoderCborBytes).fastpathDecSliceBoolR) - - fn(map[string]interface{}(nil), (*decoderCborBytes).fastpathDecMapStringIntfR) - fn(map[string]string(nil), (*decoderCborBytes).fastpathDecMapStringStringR) - fn(map[string][]byte(nil), (*decoderCborBytes).fastpathDecMapStringBytesR) - fn(map[string]uint8(nil), (*decoderCborBytes).fastpathDecMapStringUint8R) - fn(map[string]uint64(nil), (*decoderCborBytes).fastpathDecMapStringUint64R) - fn(map[string]int(nil), (*decoderCborBytes).fastpathDecMapStringIntR) - fn(map[string]int32(nil), (*decoderCborBytes).fastpathDecMapStringInt32R) - fn(map[string]float64(nil), (*decoderCborBytes).fastpathDecMapStringFloat64R) - fn(map[string]bool(nil), (*decoderCborBytes).fastpathDecMapStringBoolR) - fn(map[uint8]interface{}(nil), (*decoderCborBytes).fastpathDecMapUint8IntfR) - fn(map[uint8]string(nil), (*decoderCborBytes).fastpathDecMapUint8StringR) - fn(map[uint8][]byte(nil), (*decoderCborBytes).fastpathDecMapUint8BytesR) - fn(map[uint8]uint8(nil), (*decoderCborBytes).fastpathDecMapUint8Uint8R) - fn(map[uint8]uint64(nil), (*decoderCborBytes).fastpathDecMapUint8Uint64R) - fn(map[uint8]int(nil), (*decoderCborBytes).fastpathDecMapUint8IntR) - fn(map[uint8]int32(nil), (*decoderCborBytes).fastpathDecMapUint8Int32R) - fn(map[uint8]float64(nil), (*decoderCborBytes).fastpathDecMapUint8Float64R) - fn(map[uint8]bool(nil), (*decoderCborBytes).fastpathDecMapUint8BoolR) - fn(map[uint64]interface{}(nil), (*decoderCborBytes).fastpathDecMapUint64IntfR) - fn(map[uint64]string(nil), (*decoderCborBytes).fastpathDecMapUint64StringR) - fn(map[uint64][]byte(nil), (*decoderCborBytes).fastpathDecMapUint64BytesR) - fn(map[uint64]uint8(nil), (*decoderCborBytes).fastpathDecMapUint64Uint8R) - fn(map[uint64]uint64(nil), (*decoderCborBytes).fastpathDecMapUint64Uint64R) - fn(map[uint64]int(nil), (*decoderCborBytes).fastpathDecMapUint64IntR) - fn(map[uint64]int32(nil), (*decoderCborBytes).fastpathDecMapUint64Int32R) - fn(map[uint64]float64(nil), (*decoderCborBytes).fastpathDecMapUint64Float64R) - fn(map[uint64]bool(nil), (*decoderCborBytes).fastpathDecMapUint64BoolR) - fn(map[int]interface{}(nil), (*decoderCborBytes).fastpathDecMapIntIntfR) - fn(map[int]string(nil), (*decoderCborBytes).fastpathDecMapIntStringR) - fn(map[int][]byte(nil), (*decoderCborBytes).fastpathDecMapIntBytesR) - fn(map[int]uint8(nil), (*decoderCborBytes).fastpathDecMapIntUint8R) - fn(map[int]uint64(nil), (*decoderCborBytes).fastpathDecMapIntUint64R) - fn(map[int]int(nil), (*decoderCborBytes).fastpathDecMapIntIntR) - fn(map[int]int32(nil), (*decoderCborBytes).fastpathDecMapIntInt32R) - fn(map[int]float64(nil), (*decoderCborBytes).fastpathDecMapIntFloat64R) - fn(map[int]bool(nil), (*decoderCborBytes).fastpathDecMapIntBoolR) - fn(map[int32]interface{}(nil), (*decoderCborBytes).fastpathDecMapInt32IntfR) - fn(map[int32]string(nil), (*decoderCborBytes).fastpathDecMapInt32StringR) - fn(map[int32][]byte(nil), (*decoderCborBytes).fastpathDecMapInt32BytesR) - fn(map[int32]uint8(nil), (*decoderCborBytes).fastpathDecMapInt32Uint8R) - fn(map[int32]uint64(nil), (*decoderCborBytes).fastpathDecMapInt32Uint64R) - fn(map[int32]int(nil), (*decoderCborBytes).fastpathDecMapInt32IntR) - fn(map[int32]int32(nil), (*decoderCborBytes).fastpathDecMapInt32Int32R) - fn(map[int32]float64(nil), (*decoderCborBytes).fastpathDecMapInt32Float64R) - fn(map[int32]bool(nil), (*decoderCborBytes).fastpathDecMapInt32BoolR) - - sort.Slice(s[:], func(i, j int) bool { return s[i].rtid < s[j].rtid }) - return &s -} - -func (helperEncDriverCborBytes) fastpathEncodeTypeSwitch(iv interface{}, e *encoderCborBytes) bool { - var ft fastpathETCborBytes - switch v := iv.(type) { - case []interface{}: - if v == nil { - e.e.writeNilArray() - } else { - ft.EncSliceIntfV(v, e) - } - case []string: - if v == nil { - e.e.writeNilArray() - } else { - ft.EncSliceStringV(v, e) - } - case [][]byte: - if v == nil { - e.e.writeNilArray() - } else { - ft.EncSliceBytesV(v, e) - } - case []float32: - if v == nil { - e.e.writeNilArray() - } else { - ft.EncSliceFloat32V(v, e) - } - case []float64: - if v == nil { - e.e.writeNilArray() - } else { - ft.EncSliceFloat64V(v, e) - } - case []uint8: - if v == nil { - e.e.writeNilArray() - } else { - ft.EncSliceUint8V(v, e) - } - case []uint64: - if v == nil { - e.e.writeNilArray() - } else { - ft.EncSliceUint64V(v, e) - } - case []int: - if v == nil { - e.e.writeNilArray() - } else { - ft.EncSliceIntV(v, e) - } - case []int32: - if v == nil { - e.e.writeNilArray() - } else { - ft.EncSliceInt32V(v, e) - } - case []int64: - if v == nil { - e.e.writeNilArray() - } else { - ft.EncSliceInt64V(v, e) - } - case []bool: - if v == nil { - e.e.writeNilArray() - } else { - ft.EncSliceBoolV(v, e) - } - case map[string]interface{}: - if v == nil { - e.e.writeNilMap() - } else { - ft.EncMapStringIntfV(v, e) - } - case map[string]string: - if v == nil { - e.e.writeNilMap() - } else { - ft.EncMapStringStringV(v, e) - } - case map[string][]byte: - if v == nil { - e.e.writeNilMap() - } else { - ft.EncMapStringBytesV(v, e) - } - case map[string]uint8: - if v == nil { - e.e.writeNilMap() - } else { - ft.EncMapStringUint8V(v, e) - } - case map[string]uint64: - if v == nil { - e.e.writeNilMap() - } else { - ft.EncMapStringUint64V(v, e) - } - case map[string]int: - if v == nil { - e.e.writeNilMap() - } else { - ft.EncMapStringIntV(v, e) - } - case map[string]int32: - if v == nil { - e.e.writeNilMap() - } else { - ft.EncMapStringInt32V(v, e) - } - case map[string]float64: - if v == nil { - e.e.writeNilMap() - } else { - ft.EncMapStringFloat64V(v, e) - } - case map[string]bool: - if v == nil { - e.e.writeNilMap() - } else { - ft.EncMapStringBoolV(v, e) - } - case map[uint8]interface{}: - if v == nil { - e.e.writeNilMap() - } else { - ft.EncMapUint8IntfV(v, e) - } - case map[uint8]string: - if v == nil { - e.e.writeNilMap() - } else { - ft.EncMapUint8StringV(v, e) - } - case map[uint8][]byte: - if v == nil { - e.e.writeNilMap() - } else { - ft.EncMapUint8BytesV(v, e) - } - case map[uint8]uint8: - if v == nil { - e.e.writeNilMap() - } else { - ft.EncMapUint8Uint8V(v, e) - } - case map[uint8]uint64: - if v == nil { - e.e.writeNilMap() - } else { - ft.EncMapUint8Uint64V(v, e) - } - case map[uint8]int: - if v == nil { - e.e.writeNilMap() - } else { - ft.EncMapUint8IntV(v, e) - } - case map[uint8]int32: - if v == nil { - e.e.writeNilMap() - } else { - ft.EncMapUint8Int32V(v, e) - } - case map[uint8]float64: - if v == nil { - e.e.writeNilMap() - } else { - ft.EncMapUint8Float64V(v, e) - } - case map[uint8]bool: - if v == nil { - e.e.writeNilMap() - } else { - ft.EncMapUint8BoolV(v, e) - } - case map[uint64]interface{}: - if v == nil { - e.e.writeNilMap() - } else { - ft.EncMapUint64IntfV(v, e) - } - case map[uint64]string: - if v == nil { - e.e.writeNilMap() - } else { - ft.EncMapUint64StringV(v, e) - } - case map[uint64][]byte: - if v == nil { - e.e.writeNilMap() - } else { - ft.EncMapUint64BytesV(v, e) - } - case map[uint64]uint8: - if v == nil { - e.e.writeNilMap() - } else { - ft.EncMapUint64Uint8V(v, e) - } - case map[uint64]uint64: - if v == nil { - e.e.writeNilMap() - } else { - ft.EncMapUint64Uint64V(v, e) - } - case map[uint64]int: - if v == nil { - e.e.writeNilMap() - } else { - ft.EncMapUint64IntV(v, e) - } - case map[uint64]int32: - if v == nil { - e.e.writeNilMap() - } else { - ft.EncMapUint64Int32V(v, e) - } - case map[uint64]float64: - if v == nil { - e.e.writeNilMap() - } else { - ft.EncMapUint64Float64V(v, e) - } - case map[uint64]bool: - if v == nil { - e.e.writeNilMap() - } else { - ft.EncMapUint64BoolV(v, e) - } - case map[int]interface{}: - if v == nil { - e.e.writeNilMap() - } else { - ft.EncMapIntIntfV(v, e) - } - case map[int]string: - if v == nil { - e.e.writeNilMap() - } else { - ft.EncMapIntStringV(v, e) - } - case map[int][]byte: - if v == nil { - e.e.writeNilMap() - } else { - ft.EncMapIntBytesV(v, e) - } - case map[int]uint8: - if v == nil { - e.e.writeNilMap() - } else { - ft.EncMapIntUint8V(v, e) - } - case map[int]uint64: - if v == nil { - e.e.writeNilMap() - } else { - ft.EncMapIntUint64V(v, e) - } - case map[int]int: - if v == nil { - e.e.writeNilMap() - } else { - ft.EncMapIntIntV(v, e) - } - case map[int]int32: - if v == nil { - e.e.writeNilMap() - } else { - ft.EncMapIntInt32V(v, e) - } - case map[int]float64: - if v == nil { - e.e.writeNilMap() - } else { - ft.EncMapIntFloat64V(v, e) - } - case map[int]bool: - if v == nil { - e.e.writeNilMap() - } else { - ft.EncMapIntBoolV(v, e) - } - case map[int32]interface{}: - if v == nil { - e.e.writeNilMap() - } else { - ft.EncMapInt32IntfV(v, e) - } - case map[int32]string: - if v == nil { - e.e.writeNilMap() - } else { - ft.EncMapInt32StringV(v, e) - } - case map[int32][]byte: - if v == nil { - e.e.writeNilMap() - } else { - ft.EncMapInt32BytesV(v, e) - } - case map[int32]uint8: - if v == nil { - e.e.writeNilMap() - } else { - ft.EncMapInt32Uint8V(v, e) - } - case map[int32]uint64: - if v == nil { - e.e.writeNilMap() - } else { - ft.EncMapInt32Uint64V(v, e) - } - case map[int32]int: - if v == nil { - e.e.writeNilMap() - } else { - ft.EncMapInt32IntV(v, e) - } - case map[int32]int32: - if v == nil { - e.e.writeNilMap() - } else { - ft.EncMapInt32Int32V(v, e) - } - case map[int32]float64: - if v == nil { - e.e.writeNilMap() - } else { - ft.EncMapInt32Float64V(v, e) - } - case map[int32]bool: - if v == nil { - e.e.writeNilMap() - } else { - ft.EncMapInt32BoolV(v, e) - } - default: - _ = v - return false - } - return true -} - -func (e *encoderCborBytes) fastpathEncSliceIntfR(f *encFnInfo, rv reflect.Value) { - var ft fastpathETCborBytes - var v []interface{} - if rv.Kind() == reflect.Array { - rvGetSlice4Array(rv, &v) - } else { - v = rv2i(rv).([]interface{}) - } - if f.ti.mbs { - ft.EncAsMapSliceIntfV(v, e) - return - } - ft.EncSliceIntfV(v, e) -} -func (fastpathETCborBytes) EncSliceIntfV(v []interface{}, e *encoderCborBytes) { - if len(v) == 0 { - e.c = 0 - e.e.WriteArrayEmpty() - return - } - e.arrayStart(len(v)) - for j := range v { - e.c = containerArrayElem - e.e.WriteArrayElem(j == 0) - if !e.encodeBuiltin(v[j]) { - e.encodeR(reflect.ValueOf(v[j])) - } - } - e.c = 0 - e.e.WriteArrayEnd() -} -func (fastpathETCborBytes) EncAsMapSliceIntfV(v []interface{}, e *encoderCborBytes) { - if len(v) == 0 { - e.c = 0 - e.e.WriteMapEmpty() - return - } - e.haltOnMbsOddLen(len(v)) - e.mapStart(len(v) >> 1) - for j := range v { - if j&1 == 0 { - e.c = containerMapKey - e.e.WriteMapElemKey(j == 0) - } else { - e.mapElemValue() - } - if !e.encodeBuiltin(v[j]) { - e.encodeR(reflect.ValueOf(v[j])) - } - } - e.c = 0 - e.e.WriteMapEnd() -} - -func (e *encoderCborBytes) fastpathEncSliceStringR(f *encFnInfo, rv reflect.Value) { - var ft fastpathETCborBytes - var v []string - if rv.Kind() == reflect.Array { - rvGetSlice4Array(rv, &v) - } else { - v = rv2i(rv).([]string) - } - if f.ti.mbs { - ft.EncAsMapSliceStringV(v, e) - return - } - ft.EncSliceStringV(v, e) -} -func (fastpathETCborBytes) EncSliceStringV(v []string, e *encoderCborBytes) { - if len(v) == 0 { - e.c = 0 - e.e.WriteArrayEmpty() - return - } - e.arrayStart(len(v)) - for j := range v { - e.c = containerArrayElem - e.e.WriteArrayElem(j == 0) - e.e.EncodeString(v[j]) - } - e.c = 0 - e.e.WriteArrayEnd() -} -func (fastpathETCborBytes) EncAsMapSliceStringV(v []string, e *encoderCborBytes) { - if len(v) == 0 { - e.c = 0 - e.e.WriteMapEmpty() - return - } - e.haltOnMbsOddLen(len(v)) - e.mapStart(len(v) >> 1) - for j := range v { - if j&1 == 0 { - e.c = containerMapKey - e.e.WriteMapElemKey(j == 0) - } else { - e.mapElemValue() - } - e.e.EncodeString(v[j]) - } - e.c = 0 - e.e.WriteMapEnd() -} - -func (e *encoderCborBytes) fastpathEncSliceBytesR(f *encFnInfo, rv reflect.Value) { - var ft fastpathETCborBytes - var v [][]byte - if rv.Kind() == reflect.Array { - rvGetSlice4Array(rv, &v) - } else { - v = rv2i(rv).([][]byte) - } - if f.ti.mbs { - ft.EncAsMapSliceBytesV(v, e) - return - } - ft.EncSliceBytesV(v, e) -} -func (fastpathETCborBytes) EncSliceBytesV(v [][]byte, e *encoderCborBytes) { - if len(v) == 0 { - e.c = 0 - e.e.WriteArrayEmpty() - return - } - e.arrayStart(len(v)) - for j := range v { - e.c = containerArrayElem - e.e.WriteArrayElem(j == 0) - e.e.EncodeBytes(v[j]) - } - e.c = 0 - e.e.WriteArrayEnd() -} -func (fastpathETCborBytes) EncAsMapSliceBytesV(v [][]byte, e *encoderCborBytes) { - if len(v) == 0 { - e.c = 0 - e.e.WriteMapEmpty() - return - } - e.haltOnMbsOddLen(len(v)) - e.mapStart(len(v) >> 1) - for j := range v { - if j&1 == 0 { - e.c = containerMapKey - e.e.WriteMapElemKey(j == 0) - } else { - e.mapElemValue() - } - e.e.EncodeBytes(v[j]) - } - e.c = 0 - e.e.WriteMapEnd() -} - -func (e *encoderCborBytes) fastpathEncSliceFloat32R(f *encFnInfo, rv reflect.Value) { - var ft fastpathETCborBytes - var v []float32 - if rv.Kind() == reflect.Array { - rvGetSlice4Array(rv, &v) - } else { - v = rv2i(rv).([]float32) - } - if f.ti.mbs { - ft.EncAsMapSliceFloat32V(v, e) - return - } - ft.EncSliceFloat32V(v, e) -} -func (fastpathETCborBytes) EncSliceFloat32V(v []float32, e *encoderCborBytes) { - if len(v) == 0 { - e.c = 0 - e.e.WriteArrayEmpty() - return - } - e.arrayStart(len(v)) - for j := range v { - e.c = containerArrayElem - e.e.WriteArrayElem(j == 0) - e.e.EncodeFloat32(v[j]) - } - e.c = 0 - e.e.WriteArrayEnd() -} -func (fastpathETCborBytes) EncAsMapSliceFloat32V(v []float32, e *encoderCborBytes) { - if len(v) == 0 { - e.c = 0 - e.e.WriteMapEmpty() - return - } - e.haltOnMbsOddLen(len(v)) - e.mapStart(len(v) >> 1) - for j := range v { - if j&1 == 0 { - e.c = containerMapKey - e.e.WriteMapElemKey(j == 0) - } else { - e.mapElemValue() - } - e.e.EncodeFloat32(v[j]) - } - e.c = 0 - e.e.WriteMapEnd() -} - -func (e *encoderCborBytes) fastpathEncSliceFloat64R(f *encFnInfo, rv reflect.Value) { - var ft fastpathETCborBytes - var v []float64 - if rv.Kind() == reflect.Array { - rvGetSlice4Array(rv, &v) - } else { - v = rv2i(rv).([]float64) - } - if f.ti.mbs { - ft.EncAsMapSliceFloat64V(v, e) - return - } - ft.EncSliceFloat64V(v, e) -} -func (fastpathETCborBytes) EncSliceFloat64V(v []float64, e *encoderCborBytes) { - if len(v) == 0 { - e.c = 0 - e.e.WriteArrayEmpty() - return - } - e.arrayStart(len(v)) - for j := range v { - e.c = containerArrayElem - e.e.WriteArrayElem(j == 0) - e.e.EncodeFloat64(v[j]) - } - e.c = 0 - e.e.WriteArrayEnd() -} -func (fastpathETCborBytes) EncAsMapSliceFloat64V(v []float64, e *encoderCborBytes) { - if len(v) == 0 { - e.c = 0 - e.e.WriteMapEmpty() - return - } - e.haltOnMbsOddLen(len(v)) - e.mapStart(len(v) >> 1) - for j := range v { - if j&1 == 0 { - e.c = containerMapKey - e.e.WriteMapElemKey(j == 0) - } else { - e.mapElemValue() - } - e.e.EncodeFloat64(v[j]) - } - e.c = 0 - e.e.WriteMapEnd() -} - -func (e *encoderCborBytes) fastpathEncSliceUint8R(f *encFnInfo, rv reflect.Value) { - var ft fastpathETCborBytes - var v []uint8 - if rv.Kind() == reflect.Array { - rvGetSlice4Array(rv, &v) - } else { - v = rv2i(rv).([]uint8) - } - if f.ti.mbs { - ft.EncAsMapSliceUint8V(v, e) - return - } - ft.EncSliceUint8V(v, e) -} -func (fastpathETCborBytes) EncSliceUint8V(v []uint8, e *encoderCborBytes) { - e.e.EncodeStringBytesRaw(v) -} -func (fastpathETCborBytes) EncAsMapSliceUint8V(v []uint8, e *encoderCborBytes) { - if len(v) == 0 { - e.c = 0 - e.e.WriteMapEmpty() - return - } - e.haltOnMbsOddLen(len(v)) - e.mapStart(len(v) >> 1) - for j := range v { - if j&1 == 0 { - e.c = containerMapKey - e.e.WriteMapElemKey(j == 0) - } else { - e.mapElemValue() - } - e.e.EncodeUint(uint64(v[j])) - } - e.c = 0 - e.e.WriteMapEnd() -} - -func (e *encoderCborBytes) fastpathEncSliceUint64R(f *encFnInfo, rv reflect.Value) { - var ft fastpathETCborBytes - var v []uint64 - if rv.Kind() == reflect.Array { - rvGetSlice4Array(rv, &v) - } else { - v = rv2i(rv).([]uint64) - } - if f.ti.mbs { - ft.EncAsMapSliceUint64V(v, e) - return - } - ft.EncSliceUint64V(v, e) -} -func (fastpathETCborBytes) EncSliceUint64V(v []uint64, e *encoderCborBytes) { - if len(v) == 0 { - e.c = 0 - e.e.WriteArrayEmpty() - return - } - e.arrayStart(len(v)) - for j := range v { - e.c = containerArrayElem - e.e.WriteArrayElem(j == 0) - e.e.EncodeUint(v[j]) - } - e.c = 0 - e.e.WriteArrayEnd() -} -func (fastpathETCborBytes) EncAsMapSliceUint64V(v []uint64, e *encoderCborBytes) { - if len(v) == 0 { - e.c = 0 - e.e.WriteMapEmpty() - return - } - e.haltOnMbsOddLen(len(v)) - e.mapStart(len(v) >> 1) - for j := range v { - if j&1 == 0 { - e.c = containerMapKey - e.e.WriteMapElemKey(j == 0) - } else { - e.mapElemValue() - } - e.e.EncodeUint(v[j]) - } - e.c = 0 - e.e.WriteMapEnd() -} - -func (e *encoderCborBytes) fastpathEncSliceIntR(f *encFnInfo, rv reflect.Value) { - var ft fastpathETCborBytes - var v []int - if rv.Kind() == reflect.Array { - rvGetSlice4Array(rv, &v) - } else { - v = rv2i(rv).([]int) - } - if f.ti.mbs { - ft.EncAsMapSliceIntV(v, e) - return - } - ft.EncSliceIntV(v, e) -} -func (fastpathETCborBytes) EncSliceIntV(v []int, e *encoderCborBytes) { - if len(v) == 0 { - e.c = 0 - e.e.WriteArrayEmpty() - return - } - e.arrayStart(len(v)) - for j := range v { - e.c = containerArrayElem - e.e.WriteArrayElem(j == 0) - e.e.EncodeInt(int64(v[j])) - } - e.c = 0 - e.e.WriteArrayEnd() -} -func (fastpathETCborBytes) EncAsMapSliceIntV(v []int, e *encoderCborBytes) { - if len(v) == 0 { - e.c = 0 - e.e.WriteMapEmpty() - return - } - e.haltOnMbsOddLen(len(v)) - e.mapStart(len(v) >> 1) - for j := range v { - if j&1 == 0 { - e.c = containerMapKey - e.e.WriteMapElemKey(j == 0) - } else { - e.mapElemValue() - } - e.e.EncodeInt(int64(v[j])) - } - e.c = 0 - e.e.WriteMapEnd() -} - -func (e *encoderCborBytes) fastpathEncSliceInt32R(f *encFnInfo, rv reflect.Value) { - var ft fastpathETCborBytes - var v []int32 - if rv.Kind() == reflect.Array { - rvGetSlice4Array(rv, &v) - } else { - v = rv2i(rv).([]int32) - } - if f.ti.mbs { - ft.EncAsMapSliceInt32V(v, e) - return - } - ft.EncSliceInt32V(v, e) -} -func (fastpathETCborBytes) EncSliceInt32V(v []int32, e *encoderCborBytes) { - if len(v) == 0 { - e.c = 0 - e.e.WriteArrayEmpty() - return - } - e.arrayStart(len(v)) - for j := range v { - e.c = containerArrayElem - e.e.WriteArrayElem(j == 0) - e.e.EncodeInt(int64(v[j])) - } - e.c = 0 - e.e.WriteArrayEnd() -} -func (fastpathETCborBytes) EncAsMapSliceInt32V(v []int32, e *encoderCborBytes) { - if len(v) == 0 { - e.c = 0 - e.e.WriteMapEmpty() - return - } - e.haltOnMbsOddLen(len(v)) - e.mapStart(len(v) >> 1) - for j := range v { - if j&1 == 0 { - e.c = containerMapKey - e.e.WriteMapElemKey(j == 0) - } else { - e.mapElemValue() - } - e.e.EncodeInt(int64(v[j])) - } - e.c = 0 - e.e.WriteMapEnd() -} - -func (e *encoderCborBytes) fastpathEncSliceInt64R(f *encFnInfo, rv reflect.Value) { - var ft fastpathETCborBytes - var v []int64 - if rv.Kind() == reflect.Array { - rvGetSlice4Array(rv, &v) - } else { - v = rv2i(rv).([]int64) - } - if f.ti.mbs { - ft.EncAsMapSliceInt64V(v, e) - return - } - ft.EncSliceInt64V(v, e) -} -func (fastpathETCborBytes) EncSliceInt64V(v []int64, e *encoderCborBytes) { - if len(v) == 0 { - e.c = 0 - e.e.WriteArrayEmpty() - return - } - e.arrayStart(len(v)) - for j := range v { - e.c = containerArrayElem - e.e.WriteArrayElem(j == 0) - e.e.EncodeInt(v[j]) - } - e.c = 0 - e.e.WriteArrayEnd() -} -func (fastpathETCborBytes) EncAsMapSliceInt64V(v []int64, e *encoderCborBytes) { - if len(v) == 0 { - e.c = 0 - e.e.WriteMapEmpty() - return - } - e.haltOnMbsOddLen(len(v)) - e.mapStart(len(v) >> 1) - for j := range v { - if j&1 == 0 { - e.c = containerMapKey - e.e.WriteMapElemKey(j == 0) - } else { - e.mapElemValue() - } - e.e.EncodeInt(v[j]) - } - e.c = 0 - e.e.WriteMapEnd() -} - -func (e *encoderCborBytes) fastpathEncSliceBoolR(f *encFnInfo, rv reflect.Value) { - var ft fastpathETCborBytes - var v []bool - if rv.Kind() == reflect.Array { - rvGetSlice4Array(rv, &v) - } else { - v = rv2i(rv).([]bool) - } - if f.ti.mbs { - ft.EncAsMapSliceBoolV(v, e) - return - } - ft.EncSliceBoolV(v, e) -} -func (fastpathETCborBytes) EncSliceBoolV(v []bool, e *encoderCborBytes) { - if len(v) == 0 { - e.c = 0 - e.e.WriteArrayEmpty() - return - } - e.arrayStart(len(v)) - for j := range v { - e.c = containerArrayElem - e.e.WriteArrayElem(j == 0) - e.e.EncodeBool(v[j]) - } - e.c = 0 - e.e.WriteArrayEnd() -} -func (fastpathETCborBytes) EncAsMapSliceBoolV(v []bool, e *encoderCborBytes) { - if len(v) == 0 { - e.c = 0 - e.e.WriteMapEmpty() - return - } - e.haltOnMbsOddLen(len(v)) - e.mapStart(len(v) >> 1) - for j := range v { - if j&1 == 0 { - e.c = containerMapKey - e.e.WriteMapElemKey(j == 0) - } else { - e.mapElemValue() - } - e.e.EncodeBool(v[j]) - } - e.c = 0 - e.e.WriteMapEnd() -} - -func (e *encoderCborBytes) fastpathEncMapStringIntfR(f *encFnInfo, rv reflect.Value) { - fastpathETCborBytes{}.EncMapStringIntfV(rv2i(rv).(map[string]interface{}), e) -} -func (fastpathETCborBytes) EncMapStringIntfV(v map[string]interface{}, e *encoderCborBytes) { - if len(v) == 0 { - e.e.WriteMapEmpty() - return - } - var i uint - e.mapStart(len(v)) - if e.h.Canonical { - v2 := make([]string, len(v)) - for k := range v { - v2[i] = k - i++ - } - slices.Sort(v2) - for i, k2 := range v2 { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeString(k2) - e.mapElemValue() - if !e.encodeBuiltin(v[k2]) { - e.encodeR(reflect.ValueOf(v[k2])) - } - } - } else { - i = 0 - for k2, v2 := range v { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeString(k2) - e.mapElemValue() - if !e.encodeBuiltin(v2) { - e.encodeR(reflect.ValueOf(v2)) - } - i++ - } - } - e.c = 0 - e.e.WriteMapEnd() -} -func (e *encoderCborBytes) fastpathEncMapStringStringR(f *encFnInfo, rv reflect.Value) { - fastpathETCborBytes{}.EncMapStringStringV(rv2i(rv).(map[string]string), e) -} -func (fastpathETCborBytes) EncMapStringStringV(v map[string]string, e *encoderCborBytes) { - if len(v) == 0 { - e.e.WriteMapEmpty() - return - } - var i uint - e.mapStart(len(v)) - if e.h.Canonical { - v2 := make([]string, len(v)) - for k := range v { - v2[i] = k - i++ - } - slices.Sort(v2) - for i, k2 := range v2 { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeString(k2) - e.mapElemValue() - e.e.EncodeString(v[k2]) - } - } else { - i = 0 - for k2, v2 := range v { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeString(k2) - e.mapElemValue() - e.e.EncodeString(v2) - i++ - } - } - e.c = 0 - e.e.WriteMapEnd() -} -func (e *encoderCborBytes) fastpathEncMapStringBytesR(f *encFnInfo, rv reflect.Value) { - fastpathETCborBytes{}.EncMapStringBytesV(rv2i(rv).(map[string][]byte), e) -} -func (fastpathETCborBytes) EncMapStringBytesV(v map[string][]byte, e *encoderCborBytes) { - if len(v) == 0 { - e.e.WriteMapEmpty() - return - } - var i uint - e.mapStart(len(v)) - if e.h.Canonical { - v2 := make([]string, len(v)) - for k := range v { - v2[i] = k - i++ - } - slices.Sort(v2) - for i, k2 := range v2 { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeString(k2) - e.mapElemValue() - e.e.EncodeBytes(v[k2]) - } - } else { - i = 0 - for k2, v2 := range v { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeString(k2) - e.mapElemValue() - e.e.EncodeBytes(v2) - i++ - } - } - e.c = 0 - e.e.WriteMapEnd() -} -func (e *encoderCborBytes) fastpathEncMapStringUint8R(f *encFnInfo, rv reflect.Value) { - fastpathETCborBytes{}.EncMapStringUint8V(rv2i(rv).(map[string]uint8), e) -} -func (fastpathETCborBytes) EncMapStringUint8V(v map[string]uint8, e *encoderCborBytes) { - if len(v) == 0 { - e.e.WriteMapEmpty() - return - } - var i uint - e.mapStart(len(v)) - if e.h.Canonical { - v2 := make([]string, len(v)) - for k := range v { - v2[i] = k - i++ - } - slices.Sort(v2) - for i, k2 := range v2 { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeString(k2) - e.mapElemValue() - e.e.EncodeUint(uint64(v[k2])) - } - } else { - i = 0 - for k2, v2 := range v { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeString(k2) - e.mapElemValue() - e.e.EncodeUint(uint64(v2)) - i++ - } - } - e.c = 0 - e.e.WriteMapEnd() -} -func (e *encoderCborBytes) fastpathEncMapStringUint64R(f *encFnInfo, rv reflect.Value) { - fastpathETCborBytes{}.EncMapStringUint64V(rv2i(rv).(map[string]uint64), e) -} -func (fastpathETCborBytes) EncMapStringUint64V(v map[string]uint64, e *encoderCborBytes) { - if len(v) == 0 { - e.e.WriteMapEmpty() - return - } - var i uint - e.mapStart(len(v)) - if e.h.Canonical { - v2 := make([]string, len(v)) - for k := range v { - v2[i] = k - i++ - } - slices.Sort(v2) - for i, k2 := range v2 { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeString(k2) - e.mapElemValue() - e.e.EncodeUint(v[k2]) - } - } else { - i = 0 - for k2, v2 := range v { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeString(k2) - e.mapElemValue() - e.e.EncodeUint(v2) - i++ - } - } - e.c = 0 - e.e.WriteMapEnd() -} -func (e *encoderCborBytes) fastpathEncMapStringIntR(f *encFnInfo, rv reflect.Value) { - fastpathETCborBytes{}.EncMapStringIntV(rv2i(rv).(map[string]int), e) -} -func (fastpathETCborBytes) EncMapStringIntV(v map[string]int, e *encoderCborBytes) { - if len(v) == 0 { - e.e.WriteMapEmpty() - return - } - var i uint - e.mapStart(len(v)) - if e.h.Canonical { - v2 := make([]string, len(v)) - for k := range v { - v2[i] = k - i++ - } - slices.Sort(v2) - for i, k2 := range v2 { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeString(k2) - e.mapElemValue() - e.e.EncodeInt(int64(v[k2])) - } - } else { - i = 0 - for k2, v2 := range v { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeString(k2) - e.mapElemValue() - e.e.EncodeInt(int64(v2)) - i++ - } - } - e.c = 0 - e.e.WriteMapEnd() -} -func (e *encoderCborBytes) fastpathEncMapStringInt32R(f *encFnInfo, rv reflect.Value) { - fastpathETCborBytes{}.EncMapStringInt32V(rv2i(rv).(map[string]int32), e) -} -func (fastpathETCborBytes) EncMapStringInt32V(v map[string]int32, e *encoderCborBytes) { - if len(v) == 0 { - e.e.WriteMapEmpty() - return - } - var i uint - e.mapStart(len(v)) - if e.h.Canonical { - v2 := make([]string, len(v)) - for k := range v { - v2[i] = k - i++ - } - slices.Sort(v2) - for i, k2 := range v2 { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeString(k2) - e.mapElemValue() - e.e.EncodeInt(int64(v[k2])) - } - } else { - i = 0 - for k2, v2 := range v { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeString(k2) - e.mapElemValue() - e.e.EncodeInt(int64(v2)) - i++ - } - } - e.c = 0 - e.e.WriteMapEnd() -} -func (e *encoderCborBytes) fastpathEncMapStringFloat64R(f *encFnInfo, rv reflect.Value) { - fastpathETCborBytes{}.EncMapStringFloat64V(rv2i(rv).(map[string]float64), e) -} -func (fastpathETCborBytes) EncMapStringFloat64V(v map[string]float64, e *encoderCborBytes) { - if len(v) == 0 { - e.e.WriteMapEmpty() - return - } - var i uint - e.mapStart(len(v)) - if e.h.Canonical { - v2 := make([]string, len(v)) - for k := range v { - v2[i] = k - i++ - } - slices.Sort(v2) - for i, k2 := range v2 { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeString(k2) - e.mapElemValue() - e.e.EncodeFloat64(v[k2]) - } - } else { - i = 0 - for k2, v2 := range v { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeString(k2) - e.mapElemValue() - e.e.EncodeFloat64(v2) - i++ - } - } - e.c = 0 - e.e.WriteMapEnd() -} -func (e *encoderCborBytes) fastpathEncMapStringBoolR(f *encFnInfo, rv reflect.Value) { - fastpathETCborBytes{}.EncMapStringBoolV(rv2i(rv).(map[string]bool), e) -} -func (fastpathETCborBytes) EncMapStringBoolV(v map[string]bool, e *encoderCborBytes) { - if len(v) == 0 { - e.e.WriteMapEmpty() - return - } - var i uint - e.mapStart(len(v)) - if e.h.Canonical { - v2 := make([]string, len(v)) - for k := range v { - v2[i] = k - i++ - } - slices.Sort(v2) - for i, k2 := range v2 { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeString(k2) - e.mapElemValue() - e.e.EncodeBool(v[k2]) - } - } else { - i = 0 - for k2, v2 := range v { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeString(k2) - e.mapElemValue() - e.e.EncodeBool(v2) - i++ - } - } - e.c = 0 - e.e.WriteMapEnd() -} -func (e *encoderCborBytes) fastpathEncMapUint8IntfR(f *encFnInfo, rv reflect.Value) { - fastpathETCborBytes{}.EncMapUint8IntfV(rv2i(rv).(map[uint8]interface{}), e) -} -func (fastpathETCborBytes) EncMapUint8IntfV(v map[uint8]interface{}, e *encoderCborBytes) { - if len(v) == 0 { - e.e.WriteMapEmpty() - return - } - var i uint - e.mapStart(len(v)) - if e.h.Canonical { - v2 := make([]uint8, len(v)) - for k := range v { - v2[i] = k - i++ - } - slices.Sort(v2) - for i, k2 := range v2 { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeUint(uint64(k2)) - e.mapElemValue() - if !e.encodeBuiltin(v[k2]) { - e.encodeR(reflect.ValueOf(v[k2])) - } - } - } else { - i = 0 - for k2, v2 := range v { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeUint(uint64(k2)) - e.mapElemValue() - if !e.encodeBuiltin(v2) { - e.encodeR(reflect.ValueOf(v2)) - } - i++ - } - } - e.c = 0 - e.e.WriteMapEnd() -} -func (e *encoderCborBytes) fastpathEncMapUint8StringR(f *encFnInfo, rv reflect.Value) { - fastpathETCborBytes{}.EncMapUint8StringV(rv2i(rv).(map[uint8]string), e) -} -func (fastpathETCborBytes) EncMapUint8StringV(v map[uint8]string, e *encoderCborBytes) { - if len(v) == 0 { - e.e.WriteMapEmpty() - return - } - var i uint - e.mapStart(len(v)) - if e.h.Canonical { - v2 := make([]uint8, len(v)) - for k := range v { - v2[i] = k - i++ - } - slices.Sort(v2) - for i, k2 := range v2 { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeUint(uint64(k2)) - e.mapElemValue() - e.e.EncodeString(v[k2]) - } - } else { - i = 0 - for k2, v2 := range v { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeUint(uint64(k2)) - e.mapElemValue() - e.e.EncodeString(v2) - i++ - } - } - e.c = 0 - e.e.WriteMapEnd() -} -func (e *encoderCborBytes) fastpathEncMapUint8BytesR(f *encFnInfo, rv reflect.Value) { - fastpathETCborBytes{}.EncMapUint8BytesV(rv2i(rv).(map[uint8][]byte), e) -} -func (fastpathETCborBytes) EncMapUint8BytesV(v map[uint8][]byte, e *encoderCborBytes) { - if len(v) == 0 { - e.e.WriteMapEmpty() - return - } - var i uint - e.mapStart(len(v)) - if e.h.Canonical { - v2 := make([]uint8, len(v)) - for k := range v { - v2[i] = k - i++ - } - slices.Sort(v2) - for i, k2 := range v2 { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeUint(uint64(k2)) - e.mapElemValue() - e.e.EncodeBytes(v[k2]) - } - } else { - i = 0 - for k2, v2 := range v { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeUint(uint64(k2)) - e.mapElemValue() - e.e.EncodeBytes(v2) - i++ - } - } - e.c = 0 - e.e.WriteMapEnd() -} -func (e *encoderCborBytes) fastpathEncMapUint8Uint8R(f *encFnInfo, rv reflect.Value) { - fastpathETCborBytes{}.EncMapUint8Uint8V(rv2i(rv).(map[uint8]uint8), e) -} -func (fastpathETCborBytes) EncMapUint8Uint8V(v map[uint8]uint8, e *encoderCborBytes) { - if len(v) == 0 { - e.e.WriteMapEmpty() - return - } - var i uint - e.mapStart(len(v)) - if e.h.Canonical { - v2 := make([]uint8, len(v)) - for k := range v { - v2[i] = k - i++ - } - slices.Sort(v2) - for i, k2 := range v2 { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeUint(uint64(k2)) - e.mapElemValue() - e.e.EncodeUint(uint64(v[k2])) - } - } else { - i = 0 - for k2, v2 := range v { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeUint(uint64(k2)) - e.mapElemValue() - e.e.EncodeUint(uint64(v2)) - i++ - } - } - e.c = 0 - e.e.WriteMapEnd() -} -func (e *encoderCborBytes) fastpathEncMapUint8Uint64R(f *encFnInfo, rv reflect.Value) { - fastpathETCborBytes{}.EncMapUint8Uint64V(rv2i(rv).(map[uint8]uint64), e) -} -func (fastpathETCborBytes) EncMapUint8Uint64V(v map[uint8]uint64, e *encoderCborBytes) { - if len(v) == 0 { - e.e.WriteMapEmpty() - return - } - var i uint - e.mapStart(len(v)) - if e.h.Canonical { - v2 := make([]uint8, len(v)) - for k := range v { - v2[i] = k - i++ - } - slices.Sort(v2) - for i, k2 := range v2 { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeUint(uint64(k2)) - e.mapElemValue() - e.e.EncodeUint(v[k2]) - } - } else { - i = 0 - for k2, v2 := range v { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeUint(uint64(k2)) - e.mapElemValue() - e.e.EncodeUint(v2) - i++ - } - } - e.c = 0 - e.e.WriteMapEnd() -} -func (e *encoderCborBytes) fastpathEncMapUint8IntR(f *encFnInfo, rv reflect.Value) { - fastpathETCborBytes{}.EncMapUint8IntV(rv2i(rv).(map[uint8]int), e) -} -func (fastpathETCborBytes) EncMapUint8IntV(v map[uint8]int, e *encoderCborBytes) { - if len(v) == 0 { - e.e.WriteMapEmpty() - return - } - var i uint - e.mapStart(len(v)) - if e.h.Canonical { - v2 := make([]uint8, len(v)) - for k := range v { - v2[i] = k - i++ - } - slices.Sort(v2) - for i, k2 := range v2 { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeUint(uint64(k2)) - e.mapElemValue() - e.e.EncodeInt(int64(v[k2])) - } - } else { - i = 0 - for k2, v2 := range v { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeUint(uint64(k2)) - e.mapElemValue() - e.e.EncodeInt(int64(v2)) - i++ - } - } - e.c = 0 - e.e.WriteMapEnd() -} -func (e *encoderCborBytes) fastpathEncMapUint8Int32R(f *encFnInfo, rv reflect.Value) { - fastpathETCborBytes{}.EncMapUint8Int32V(rv2i(rv).(map[uint8]int32), e) -} -func (fastpathETCborBytes) EncMapUint8Int32V(v map[uint8]int32, e *encoderCborBytes) { - if len(v) == 0 { - e.e.WriteMapEmpty() - return - } - var i uint - e.mapStart(len(v)) - if e.h.Canonical { - v2 := make([]uint8, len(v)) - for k := range v { - v2[i] = k - i++ - } - slices.Sort(v2) - for i, k2 := range v2 { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeUint(uint64(k2)) - e.mapElemValue() - e.e.EncodeInt(int64(v[k2])) - } - } else { - i = 0 - for k2, v2 := range v { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeUint(uint64(k2)) - e.mapElemValue() - e.e.EncodeInt(int64(v2)) - i++ - } - } - e.c = 0 - e.e.WriteMapEnd() -} -func (e *encoderCborBytes) fastpathEncMapUint8Float64R(f *encFnInfo, rv reflect.Value) { - fastpathETCborBytes{}.EncMapUint8Float64V(rv2i(rv).(map[uint8]float64), e) -} -func (fastpathETCborBytes) EncMapUint8Float64V(v map[uint8]float64, e *encoderCborBytes) { - if len(v) == 0 { - e.e.WriteMapEmpty() - return - } - var i uint - e.mapStart(len(v)) - if e.h.Canonical { - v2 := make([]uint8, len(v)) - for k := range v { - v2[i] = k - i++ - } - slices.Sort(v2) - for i, k2 := range v2 { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeUint(uint64(k2)) - e.mapElemValue() - e.e.EncodeFloat64(v[k2]) - } - } else { - i = 0 - for k2, v2 := range v { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeUint(uint64(k2)) - e.mapElemValue() - e.e.EncodeFloat64(v2) - i++ - } - } - e.c = 0 - e.e.WriteMapEnd() -} -func (e *encoderCborBytes) fastpathEncMapUint8BoolR(f *encFnInfo, rv reflect.Value) { - fastpathETCborBytes{}.EncMapUint8BoolV(rv2i(rv).(map[uint8]bool), e) -} -func (fastpathETCborBytes) EncMapUint8BoolV(v map[uint8]bool, e *encoderCborBytes) { - if len(v) == 0 { - e.e.WriteMapEmpty() - return - } - var i uint - e.mapStart(len(v)) - if e.h.Canonical { - v2 := make([]uint8, len(v)) - for k := range v { - v2[i] = k - i++ - } - slices.Sort(v2) - for i, k2 := range v2 { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeUint(uint64(k2)) - e.mapElemValue() - e.e.EncodeBool(v[k2]) - } - } else { - i = 0 - for k2, v2 := range v { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeUint(uint64(k2)) - e.mapElemValue() - e.e.EncodeBool(v2) - i++ - } - } - e.c = 0 - e.e.WriteMapEnd() -} -func (e *encoderCborBytes) fastpathEncMapUint64IntfR(f *encFnInfo, rv reflect.Value) { - fastpathETCborBytes{}.EncMapUint64IntfV(rv2i(rv).(map[uint64]interface{}), e) -} -func (fastpathETCborBytes) EncMapUint64IntfV(v map[uint64]interface{}, e *encoderCborBytes) { - if len(v) == 0 { - e.e.WriteMapEmpty() - return - } - var i uint - e.mapStart(len(v)) - if e.h.Canonical { - v2 := make([]uint64, len(v)) - for k := range v { - v2[i] = k - i++ - } - slices.Sort(v2) - for i, k2 := range v2 { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeUint(k2) - e.mapElemValue() - if !e.encodeBuiltin(v[k2]) { - e.encodeR(reflect.ValueOf(v[k2])) - } - } - } else { - i = 0 - for k2, v2 := range v { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeUint(k2) - e.mapElemValue() - if !e.encodeBuiltin(v2) { - e.encodeR(reflect.ValueOf(v2)) - } - i++ - } - } - e.c = 0 - e.e.WriteMapEnd() -} -func (e *encoderCborBytes) fastpathEncMapUint64StringR(f *encFnInfo, rv reflect.Value) { - fastpathETCborBytes{}.EncMapUint64StringV(rv2i(rv).(map[uint64]string), e) -} -func (fastpathETCborBytes) EncMapUint64StringV(v map[uint64]string, e *encoderCborBytes) { - if len(v) == 0 { - e.e.WriteMapEmpty() - return - } - var i uint - e.mapStart(len(v)) - if e.h.Canonical { - v2 := make([]uint64, len(v)) - for k := range v { - v2[i] = k - i++ - } - slices.Sort(v2) - for i, k2 := range v2 { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeUint(k2) - e.mapElemValue() - e.e.EncodeString(v[k2]) - } - } else { - i = 0 - for k2, v2 := range v { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeUint(k2) - e.mapElemValue() - e.e.EncodeString(v2) - i++ - } - } - e.c = 0 - e.e.WriteMapEnd() -} -func (e *encoderCborBytes) fastpathEncMapUint64BytesR(f *encFnInfo, rv reflect.Value) { - fastpathETCborBytes{}.EncMapUint64BytesV(rv2i(rv).(map[uint64][]byte), e) -} -func (fastpathETCborBytes) EncMapUint64BytesV(v map[uint64][]byte, e *encoderCborBytes) { - if len(v) == 0 { - e.e.WriteMapEmpty() - return - } - var i uint - e.mapStart(len(v)) - if e.h.Canonical { - v2 := make([]uint64, len(v)) - for k := range v { - v2[i] = k - i++ - } - slices.Sort(v2) - for i, k2 := range v2 { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeUint(k2) - e.mapElemValue() - e.e.EncodeBytes(v[k2]) - } - } else { - i = 0 - for k2, v2 := range v { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeUint(k2) - e.mapElemValue() - e.e.EncodeBytes(v2) - i++ - } - } - e.c = 0 - e.e.WriteMapEnd() -} -func (e *encoderCborBytes) fastpathEncMapUint64Uint8R(f *encFnInfo, rv reflect.Value) { - fastpathETCborBytes{}.EncMapUint64Uint8V(rv2i(rv).(map[uint64]uint8), e) -} -func (fastpathETCborBytes) EncMapUint64Uint8V(v map[uint64]uint8, e *encoderCborBytes) { - if len(v) == 0 { - e.e.WriteMapEmpty() - return - } - var i uint - e.mapStart(len(v)) - if e.h.Canonical { - v2 := make([]uint64, len(v)) - for k := range v { - v2[i] = k - i++ - } - slices.Sort(v2) - for i, k2 := range v2 { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeUint(k2) - e.mapElemValue() - e.e.EncodeUint(uint64(v[k2])) - } - } else { - i = 0 - for k2, v2 := range v { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeUint(k2) - e.mapElemValue() - e.e.EncodeUint(uint64(v2)) - i++ - } - } - e.c = 0 - e.e.WriteMapEnd() -} -func (e *encoderCborBytes) fastpathEncMapUint64Uint64R(f *encFnInfo, rv reflect.Value) { - fastpathETCborBytes{}.EncMapUint64Uint64V(rv2i(rv).(map[uint64]uint64), e) -} -func (fastpathETCborBytes) EncMapUint64Uint64V(v map[uint64]uint64, e *encoderCborBytes) { - if len(v) == 0 { - e.e.WriteMapEmpty() - return - } - var i uint - e.mapStart(len(v)) - if e.h.Canonical { - v2 := make([]uint64, len(v)) - for k := range v { - v2[i] = k - i++ - } - slices.Sort(v2) - for i, k2 := range v2 { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeUint(k2) - e.mapElemValue() - e.e.EncodeUint(v[k2]) - } - } else { - i = 0 - for k2, v2 := range v { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeUint(k2) - e.mapElemValue() - e.e.EncodeUint(v2) - i++ - } - } - e.c = 0 - e.e.WriteMapEnd() -} -func (e *encoderCborBytes) fastpathEncMapUint64IntR(f *encFnInfo, rv reflect.Value) { - fastpathETCborBytes{}.EncMapUint64IntV(rv2i(rv).(map[uint64]int), e) -} -func (fastpathETCborBytes) EncMapUint64IntV(v map[uint64]int, e *encoderCborBytes) { - if len(v) == 0 { - e.e.WriteMapEmpty() - return - } - var i uint - e.mapStart(len(v)) - if e.h.Canonical { - v2 := make([]uint64, len(v)) - for k := range v { - v2[i] = k - i++ - } - slices.Sort(v2) - for i, k2 := range v2 { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeUint(k2) - e.mapElemValue() - e.e.EncodeInt(int64(v[k2])) - } - } else { - i = 0 - for k2, v2 := range v { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeUint(k2) - e.mapElemValue() - e.e.EncodeInt(int64(v2)) - i++ - } - } - e.c = 0 - e.e.WriteMapEnd() -} -func (e *encoderCborBytes) fastpathEncMapUint64Int32R(f *encFnInfo, rv reflect.Value) { - fastpathETCborBytes{}.EncMapUint64Int32V(rv2i(rv).(map[uint64]int32), e) -} -func (fastpathETCborBytes) EncMapUint64Int32V(v map[uint64]int32, e *encoderCborBytes) { - if len(v) == 0 { - e.e.WriteMapEmpty() - return - } - var i uint - e.mapStart(len(v)) - if e.h.Canonical { - v2 := make([]uint64, len(v)) - for k := range v { - v2[i] = k - i++ - } - slices.Sort(v2) - for i, k2 := range v2 { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeUint(k2) - e.mapElemValue() - e.e.EncodeInt(int64(v[k2])) - } - } else { - i = 0 - for k2, v2 := range v { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeUint(k2) - e.mapElemValue() - e.e.EncodeInt(int64(v2)) - i++ - } - } - e.c = 0 - e.e.WriteMapEnd() -} -func (e *encoderCborBytes) fastpathEncMapUint64Float64R(f *encFnInfo, rv reflect.Value) { - fastpathETCborBytes{}.EncMapUint64Float64V(rv2i(rv).(map[uint64]float64), e) -} -func (fastpathETCborBytes) EncMapUint64Float64V(v map[uint64]float64, e *encoderCborBytes) { - if len(v) == 0 { - e.e.WriteMapEmpty() - return - } - var i uint - e.mapStart(len(v)) - if e.h.Canonical { - v2 := make([]uint64, len(v)) - for k := range v { - v2[i] = k - i++ - } - slices.Sort(v2) - for i, k2 := range v2 { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeUint(k2) - e.mapElemValue() - e.e.EncodeFloat64(v[k2]) - } - } else { - i = 0 - for k2, v2 := range v { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeUint(k2) - e.mapElemValue() - e.e.EncodeFloat64(v2) - i++ - } - } - e.c = 0 - e.e.WriteMapEnd() -} -func (e *encoderCborBytes) fastpathEncMapUint64BoolR(f *encFnInfo, rv reflect.Value) { - fastpathETCborBytes{}.EncMapUint64BoolV(rv2i(rv).(map[uint64]bool), e) -} -func (fastpathETCborBytes) EncMapUint64BoolV(v map[uint64]bool, e *encoderCborBytes) { - if len(v) == 0 { - e.e.WriteMapEmpty() - return - } - var i uint - e.mapStart(len(v)) - if e.h.Canonical { - v2 := make([]uint64, len(v)) - for k := range v { - v2[i] = k - i++ - } - slices.Sort(v2) - for i, k2 := range v2 { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeUint(k2) - e.mapElemValue() - e.e.EncodeBool(v[k2]) - } - } else { - i = 0 - for k2, v2 := range v { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeUint(k2) - e.mapElemValue() - e.e.EncodeBool(v2) - i++ - } - } - e.c = 0 - e.e.WriteMapEnd() -} -func (e *encoderCborBytes) fastpathEncMapIntIntfR(f *encFnInfo, rv reflect.Value) { - fastpathETCborBytes{}.EncMapIntIntfV(rv2i(rv).(map[int]interface{}), e) -} -func (fastpathETCborBytes) EncMapIntIntfV(v map[int]interface{}, e *encoderCborBytes) { - if len(v) == 0 { - e.e.WriteMapEmpty() - return - } - var i uint - e.mapStart(len(v)) - if e.h.Canonical { - v2 := make([]int, len(v)) - for k := range v { - v2[i] = k - i++ - } - slices.Sort(v2) - for i, k2 := range v2 { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeInt(int64(k2)) - e.mapElemValue() - if !e.encodeBuiltin(v[k2]) { - e.encodeR(reflect.ValueOf(v[k2])) - } - } - } else { - i = 0 - for k2, v2 := range v { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeInt(int64(k2)) - e.mapElemValue() - if !e.encodeBuiltin(v2) { - e.encodeR(reflect.ValueOf(v2)) - } - i++ - } - } - e.c = 0 - e.e.WriteMapEnd() -} -func (e *encoderCborBytes) fastpathEncMapIntStringR(f *encFnInfo, rv reflect.Value) { - fastpathETCborBytes{}.EncMapIntStringV(rv2i(rv).(map[int]string), e) -} -func (fastpathETCborBytes) EncMapIntStringV(v map[int]string, e *encoderCborBytes) { - if len(v) == 0 { - e.e.WriteMapEmpty() - return - } - var i uint - e.mapStart(len(v)) - if e.h.Canonical { - v2 := make([]int, len(v)) - for k := range v { - v2[i] = k - i++ - } - slices.Sort(v2) - for i, k2 := range v2 { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeInt(int64(k2)) - e.mapElemValue() - e.e.EncodeString(v[k2]) - } - } else { - i = 0 - for k2, v2 := range v { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeInt(int64(k2)) - e.mapElemValue() - e.e.EncodeString(v2) - i++ - } - } - e.c = 0 - e.e.WriteMapEnd() -} -func (e *encoderCborBytes) fastpathEncMapIntBytesR(f *encFnInfo, rv reflect.Value) { - fastpathETCborBytes{}.EncMapIntBytesV(rv2i(rv).(map[int][]byte), e) -} -func (fastpathETCborBytes) EncMapIntBytesV(v map[int][]byte, e *encoderCborBytes) { - if len(v) == 0 { - e.e.WriteMapEmpty() - return - } - var i uint - e.mapStart(len(v)) - if e.h.Canonical { - v2 := make([]int, len(v)) - for k := range v { - v2[i] = k - i++ - } - slices.Sort(v2) - for i, k2 := range v2 { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeInt(int64(k2)) - e.mapElemValue() - e.e.EncodeBytes(v[k2]) - } - } else { - i = 0 - for k2, v2 := range v { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeInt(int64(k2)) - e.mapElemValue() - e.e.EncodeBytes(v2) - i++ - } - } - e.c = 0 - e.e.WriteMapEnd() -} -func (e *encoderCborBytes) fastpathEncMapIntUint8R(f *encFnInfo, rv reflect.Value) { - fastpathETCborBytes{}.EncMapIntUint8V(rv2i(rv).(map[int]uint8), e) -} -func (fastpathETCborBytes) EncMapIntUint8V(v map[int]uint8, e *encoderCborBytes) { - if len(v) == 0 { - e.e.WriteMapEmpty() - return - } - var i uint - e.mapStart(len(v)) - if e.h.Canonical { - v2 := make([]int, len(v)) - for k := range v { - v2[i] = k - i++ - } - slices.Sort(v2) - for i, k2 := range v2 { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeInt(int64(k2)) - e.mapElemValue() - e.e.EncodeUint(uint64(v[k2])) - } - } else { - i = 0 - for k2, v2 := range v { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeInt(int64(k2)) - e.mapElemValue() - e.e.EncodeUint(uint64(v2)) - i++ - } - } - e.c = 0 - e.e.WriteMapEnd() -} -func (e *encoderCborBytes) fastpathEncMapIntUint64R(f *encFnInfo, rv reflect.Value) { - fastpathETCborBytes{}.EncMapIntUint64V(rv2i(rv).(map[int]uint64), e) -} -func (fastpathETCborBytes) EncMapIntUint64V(v map[int]uint64, e *encoderCborBytes) { - if len(v) == 0 { - e.e.WriteMapEmpty() - return - } - var i uint - e.mapStart(len(v)) - if e.h.Canonical { - v2 := make([]int, len(v)) - for k := range v { - v2[i] = k - i++ - } - slices.Sort(v2) - for i, k2 := range v2 { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeInt(int64(k2)) - e.mapElemValue() - e.e.EncodeUint(v[k2]) - } - } else { - i = 0 - for k2, v2 := range v { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeInt(int64(k2)) - e.mapElemValue() - e.e.EncodeUint(v2) - i++ - } - } - e.c = 0 - e.e.WriteMapEnd() -} -func (e *encoderCborBytes) fastpathEncMapIntIntR(f *encFnInfo, rv reflect.Value) { - fastpathETCborBytes{}.EncMapIntIntV(rv2i(rv).(map[int]int), e) -} -func (fastpathETCborBytes) EncMapIntIntV(v map[int]int, e *encoderCborBytes) { - if len(v) == 0 { - e.e.WriteMapEmpty() - return - } - var i uint - e.mapStart(len(v)) - if e.h.Canonical { - v2 := make([]int, len(v)) - for k := range v { - v2[i] = k - i++ - } - slices.Sort(v2) - for i, k2 := range v2 { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeInt(int64(k2)) - e.mapElemValue() - e.e.EncodeInt(int64(v[k2])) - } - } else { - i = 0 - for k2, v2 := range v { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeInt(int64(k2)) - e.mapElemValue() - e.e.EncodeInt(int64(v2)) - i++ - } - } - e.c = 0 - e.e.WriteMapEnd() -} -func (e *encoderCborBytes) fastpathEncMapIntInt32R(f *encFnInfo, rv reflect.Value) { - fastpathETCborBytes{}.EncMapIntInt32V(rv2i(rv).(map[int]int32), e) -} -func (fastpathETCborBytes) EncMapIntInt32V(v map[int]int32, e *encoderCborBytes) { - if len(v) == 0 { - e.e.WriteMapEmpty() - return - } - var i uint - e.mapStart(len(v)) - if e.h.Canonical { - v2 := make([]int, len(v)) - for k := range v { - v2[i] = k - i++ - } - slices.Sort(v2) - for i, k2 := range v2 { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeInt(int64(k2)) - e.mapElemValue() - e.e.EncodeInt(int64(v[k2])) - } - } else { - i = 0 - for k2, v2 := range v { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeInt(int64(k2)) - e.mapElemValue() - e.e.EncodeInt(int64(v2)) - i++ - } - } - e.c = 0 - e.e.WriteMapEnd() -} -func (e *encoderCborBytes) fastpathEncMapIntFloat64R(f *encFnInfo, rv reflect.Value) { - fastpathETCborBytes{}.EncMapIntFloat64V(rv2i(rv).(map[int]float64), e) -} -func (fastpathETCborBytes) EncMapIntFloat64V(v map[int]float64, e *encoderCborBytes) { - if len(v) == 0 { - e.e.WriteMapEmpty() - return - } - var i uint - e.mapStart(len(v)) - if e.h.Canonical { - v2 := make([]int, len(v)) - for k := range v { - v2[i] = k - i++ - } - slices.Sort(v2) - for i, k2 := range v2 { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeInt(int64(k2)) - e.mapElemValue() - e.e.EncodeFloat64(v[k2]) - } - } else { - i = 0 - for k2, v2 := range v { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeInt(int64(k2)) - e.mapElemValue() - e.e.EncodeFloat64(v2) - i++ - } - } - e.c = 0 - e.e.WriteMapEnd() -} -func (e *encoderCborBytes) fastpathEncMapIntBoolR(f *encFnInfo, rv reflect.Value) { - fastpathETCborBytes{}.EncMapIntBoolV(rv2i(rv).(map[int]bool), e) -} -func (fastpathETCborBytes) EncMapIntBoolV(v map[int]bool, e *encoderCborBytes) { - if len(v) == 0 { - e.e.WriteMapEmpty() - return - } - var i uint - e.mapStart(len(v)) - if e.h.Canonical { - v2 := make([]int, len(v)) - for k := range v { - v2[i] = k - i++ - } - slices.Sort(v2) - for i, k2 := range v2 { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeInt(int64(k2)) - e.mapElemValue() - e.e.EncodeBool(v[k2]) - } - } else { - i = 0 - for k2, v2 := range v { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeInt(int64(k2)) - e.mapElemValue() - e.e.EncodeBool(v2) - i++ - } - } - e.c = 0 - e.e.WriteMapEnd() -} -func (e *encoderCborBytes) fastpathEncMapInt32IntfR(f *encFnInfo, rv reflect.Value) { - fastpathETCborBytes{}.EncMapInt32IntfV(rv2i(rv).(map[int32]interface{}), e) -} -func (fastpathETCborBytes) EncMapInt32IntfV(v map[int32]interface{}, e *encoderCborBytes) { - if len(v) == 0 { - e.e.WriteMapEmpty() - return - } - var i uint - e.mapStart(len(v)) - if e.h.Canonical { - v2 := make([]int32, len(v)) - for k := range v { - v2[i] = k - i++ - } - slices.Sort(v2) - for i, k2 := range v2 { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeInt(int64(k2)) - e.mapElemValue() - if !e.encodeBuiltin(v[k2]) { - e.encodeR(reflect.ValueOf(v[k2])) - } - } - } else { - i = 0 - for k2, v2 := range v { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeInt(int64(k2)) - e.mapElemValue() - if !e.encodeBuiltin(v2) { - e.encodeR(reflect.ValueOf(v2)) - } - i++ - } - } - e.c = 0 - e.e.WriteMapEnd() -} -func (e *encoderCborBytes) fastpathEncMapInt32StringR(f *encFnInfo, rv reflect.Value) { - fastpathETCborBytes{}.EncMapInt32StringV(rv2i(rv).(map[int32]string), e) -} -func (fastpathETCborBytes) EncMapInt32StringV(v map[int32]string, e *encoderCborBytes) { - if len(v) == 0 { - e.e.WriteMapEmpty() - return - } - var i uint - e.mapStart(len(v)) - if e.h.Canonical { - v2 := make([]int32, len(v)) - for k := range v { - v2[i] = k - i++ - } - slices.Sort(v2) - for i, k2 := range v2 { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeInt(int64(k2)) - e.mapElemValue() - e.e.EncodeString(v[k2]) - } - } else { - i = 0 - for k2, v2 := range v { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeInt(int64(k2)) - e.mapElemValue() - e.e.EncodeString(v2) - i++ - } - } - e.c = 0 - e.e.WriteMapEnd() -} -func (e *encoderCborBytes) fastpathEncMapInt32BytesR(f *encFnInfo, rv reflect.Value) { - fastpathETCborBytes{}.EncMapInt32BytesV(rv2i(rv).(map[int32][]byte), e) -} -func (fastpathETCborBytes) EncMapInt32BytesV(v map[int32][]byte, e *encoderCborBytes) { - if len(v) == 0 { - e.e.WriteMapEmpty() - return - } - var i uint - e.mapStart(len(v)) - if e.h.Canonical { - v2 := make([]int32, len(v)) - for k := range v { - v2[i] = k - i++ - } - slices.Sort(v2) - for i, k2 := range v2 { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeInt(int64(k2)) - e.mapElemValue() - e.e.EncodeBytes(v[k2]) - } - } else { - i = 0 - for k2, v2 := range v { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeInt(int64(k2)) - e.mapElemValue() - e.e.EncodeBytes(v2) - i++ - } - } - e.c = 0 - e.e.WriteMapEnd() -} -func (e *encoderCborBytes) fastpathEncMapInt32Uint8R(f *encFnInfo, rv reflect.Value) { - fastpathETCborBytes{}.EncMapInt32Uint8V(rv2i(rv).(map[int32]uint8), e) -} -func (fastpathETCborBytes) EncMapInt32Uint8V(v map[int32]uint8, e *encoderCborBytes) { - if len(v) == 0 { - e.e.WriteMapEmpty() - return - } - var i uint - e.mapStart(len(v)) - if e.h.Canonical { - v2 := make([]int32, len(v)) - for k := range v { - v2[i] = k - i++ - } - slices.Sort(v2) - for i, k2 := range v2 { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeInt(int64(k2)) - e.mapElemValue() - e.e.EncodeUint(uint64(v[k2])) - } - } else { - i = 0 - for k2, v2 := range v { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeInt(int64(k2)) - e.mapElemValue() - e.e.EncodeUint(uint64(v2)) - i++ - } - } - e.c = 0 - e.e.WriteMapEnd() -} -func (e *encoderCborBytes) fastpathEncMapInt32Uint64R(f *encFnInfo, rv reflect.Value) { - fastpathETCborBytes{}.EncMapInt32Uint64V(rv2i(rv).(map[int32]uint64), e) -} -func (fastpathETCborBytes) EncMapInt32Uint64V(v map[int32]uint64, e *encoderCborBytes) { - if len(v) == 0 { - e.e.WriteMapEmpty() - return - } - var i uint - e.mapStart(len(v)) - if e.h.Canonical { - v2 := make([]int32, len(v)) - for k := range v { - v2[i] = k - i++ - } - slices.Sort(v2) - for i, k2 := range v2 { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeInt(int64(k2)) - e.mapElemValue() - e.e.EncodeUint(v[k2]) - } - } else { - i = 0 - for k2, v2 := range v { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeInt(int64(k2)) - e.mapElemValue() - e.e.EncodeUint(v2) - i++ - } - } - e.c = 0 - e.e.WriteMapEnd() -} -func (e *encoderCborBytes) fastpathEncMapInt32IntR(f *encFnInfo, rv reflect.Value) { - fastpathETCborBytes{}.EncMapInt32IntV(rv2i(rv).(map[int32]int), e) -} -func (fastpathETCborBytes) EncMapInt32IntV(v map[int32]int, e *encoderCborBytes) { - if len(v) == 0 { - e.e.WriteMapEmpty() - return - } - var i uint - e.mapStart(len(v)) - if e.h.Canonical { - v2 := make([]int32, len(v)) - for k := range v { - v2[i] = k - i++ - } - slices.Sort(v2) - for i, k2 := range v2 { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeInt(int64(k2)) - e.mapElemValue() - e.e.EncodeInt(int64(v[k2])) - } - } else { - i = 0 - for k2, v2 := range v { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeInt(int64(k2)) - e.mapElemValue() - e.e.EncodeInt(int64(v2)) - i++ - } - } - e.c = 0 - e.e.WriteMapEnd() -} -func (e *encoderCborBytes) fastpathEncMapInt32Int32R(f *encFnInfo, rv reflect.Value) { - fastpathETCborBytes{}.EncMapInt32Int32V(rv2i(rv).(map[int32]int32), e) -} -func (fastpathETCborBytes) EncMapInt32Int32V(v map[int32]int32, e *encoderCborBytes) { - if len(v) == 0 { - e.e.WriteMapEmpty() - return - } - var i uint - e.mapStart(len(v)) - if e.h.Canonical { - v2 := make([]int32, len(v)) - for k := range v { - v2[i] = k - i++ - } - slices.Sort(v2) - for i, k2 := range v2 { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeInt(int64(k2)) - e.mapElemValue() - e.e.EncodeInt(int64(v[k2])) - } - } else { - i = 0 - for k2, v2 := range v { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeInt(int64(k2)) - e.mapElemValue() - e.e.EncodeInt(int64(v2)) - i++ - } - } - e.c = 0 - e.e.WriteMapEnd() -} -func (e *encoderCborBytes) fastpathEncMapInt32Float64R(f *encFnInfo, rv reflect.Value) { - fastpathETCborBytes{}.EncMapInt32Float64V(rv2i(rv).(map[int32]float64), e) -} -func (fastpathETCborBytes) EncMapInt32Float64V(v map[int32]float64, e *encoderCborBytes) { - if len(v) == 0 { - e.e.WriteMapEmpty() - return - } - var i uint - e.mapStart(len(v)) - if e.h.Canonical { - v2 := make([]int32, len(v)) - for k := range v { - v2[i] = k - i++ - } - slices.Sort(v2) - for i, k2 := range v2 { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeInt(int64(k2)) - e.mapElemValue() - e.e.EncodeFloat64(v[k2]) - } - } else { - i = 0 - for k2, v2 := range v { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeInt(int64(k2)) - e.mapElemValue() - e.e.EncodeFloat64(v2) - i++ - } - } - e.c = 0 - e.e.WriteMapEnd() -} -func (e *encoderCborBytes) fastpathEncMapInt32BoolR(f *encFnInfo, rv reflect.Value) { - fastpathETCborBytes{}.EncMapInt32BoolV(rv2i(rv).(map[int32]bool), e) -} -func (fastpathETCborBytes) EncMapInt32BoolV(v map[int32]bool, e *encoderCborBytes) { - if len(v) == 0 { - e.e.WriteMapEmpty() - return - } - var i uint - e.mapStart(len(v)) - if e.h.Canonical { - v2 := make([]int32, len(v)) - for k := range v { - v2[i] = k - i++ - } - slices.Sort(v2) - for i, k2 := range v2 { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeInt(int64(k2)) - e.mapElemValue() - e.e.EncodeBool(v[k2]) - } - } else { - i = 0 - for k2, v2 := range v { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeInt(int64(k2)) - e.mapElemValue() - e.e.EncodeBool(v2) - i++ - } - } - e.c = 0 - e.e.WriteMapEnd() -} - -func (helperDecDriverCborBytes) fastpathDecodeTypeSwitch(iv interface{}, d *decoderCborBytes) bool { - var ft fastpathDTCborBytes - var changed bool - var containerLen int - switch v := iv.(type) { - case []interface{}: - ft.DecSliceIntfN(v, d) - case *[]interface{}: - var v2 []interface{} - if v2, changed = ft.DecSliceIntfY(*v, d); changed { - *v = v2 - } - case []string: - ft.DecSliceStringN(v, d) - case *[]string: - var v2 []string - if v2, changed = ft.DecSliceStringY(*v, d); changed { - *v = v2 - } - case [][]byte: - ft.DecSliceBytesN(v, d) - case *[][]byte: - var v2 [][]byte - if v2, changed = ft.DecSliceBytesY(*v, d); changed { - *v = v2 - } - case []float32: - ft.DecSliceFloat32N(v, d) - case *[]float32: - var v2 []float32 - if v2, changed = ft.DecSliceFloat32Y(*v, d); changed { - *v = v2 - } - case []float64: - ft.DecSliceFloat64N(v, d) - case *[]float64: - var v2 []float64 - if v2, changed = ft.DecSliceFloat64Y(*v, d); changed { - *v = v2 - } - case []uint8: - ft.DecSliceUint8N(v, d) - case *[]uint8: - var v2 []uint8 - if v2, changed = ft.DecSliceUint8Y(*v, d); changed { - *v = v2 - } - case []uint64: - ft.DecSliceUint64N(v, d) - case *[]uint64: - var v2 []uint64 - if v2, changed = ft.DecSliceUint64Y(*v, d); changed { - *v = v2 - } - case []int: - ft.DecSliceIntN(v, d) - case *[]int: - var v2 []int - if v2, changed = ft.DecSliceIntY(*v, d); changed { - *v = v2 - } - case []int32: - ft.DecSliceInt32N(v, d) - case *[]int32: - var v2 []int32 - if v2, changed = ft.DecSliceInt32Y(*v, d); changed { - *v = v2 - } - case []int64: - ft.DecSliceInt64N(v, d) - case *[]int64: - var v2 []int64 - if v2, changed = ft.DecSliceInt64Y(*v, d); changed { - *v = v2 - } - case []bool: - ft.DecSliceBoolN(v, d) - case *[]bool: - var v2 []bool - if v2, changed = ft.DecSliceBoolY(*v, d); changed { - *v = v2 - } - case map[string]interface{}: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen != containerLenNil { - if containerLen != 0 { - ft.DecMapStringIntfL(v, containerLen, d) - } - d.mapEnd() - } - case *map[string]interface{}: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen == containerLenNil { - *v = nil - } else { - if *v == nil { - *v = make(map[string]interface{}, decInferLen(containerLen, d.maxInitLen(), 32)) - } - if containerLen != 0 { - ft.DecMapStringIntfL(*v, containerLen, d) - } - d.mapEnd() - } - case map[string]string: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen != containerLenNil { - if containerLen != 0 { - ft.DecMapStringStringL(v, containerLen, d) - } - d.mapEnd() - } - case *map[string]string: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen == containerLenNil { - *v = nil - } else { - if *v == nil { - *v = make(map[string]string, decInferLen(containerLen, d.maxInitLen(), 32)) - } - if containerLen != 0 { - ft.DecMapStringStringL(*v, containerLen, d) - } - d.mapEnd() - } - case map[string][]byte: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen != containerLenNil { - if containerLen != 0 { - ft.DecMapStringBytesL(v, containerLen, d) - } - d.mapEnd() - } - case *map[string][]byte: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen == containerLenNil { - *v = nil - } else { - if *v == nil { - *v = make(map[string][]byte, decInferLen(containerLen, d.maxInitLen(), 40)) - } - if containerLen != 0 { - ft.DecMapStringBytesL(*v, containerLen, d) - } - d.mapEnd() - } - case map[string]uint8: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen != containerLenNil { - if containerLen != 0 { - ft.DecMapStringUint8L(v, containerLen, d) - } - d.mapEnd() - } - case *map[string]uint8: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen == containerLenNil { - *v = nil - } else { - if *v == nil { - *v = make(map[string]uint8, decInferLen(containerLen, d.maxInitLen(), 17)) - } - if containerLen != 0 { - ft.DecMapStringUint8L(*v, containerLen, d) - } - d.mapEnd() - } - case map[string]uint64: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen != containerLenNil { - if containerLen != 0 { - ft.DecMapStringUint64L(v, containerLen, d) - } - d.mapEnd() - } - case *map[string]uint64: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen == containerLenNil { - *v = nil - } else { - if *v == nil { - *v = make(map[string]uint64, decInferLen(containerLen, d.maxInitLen(), 24)) - } - if containerLen != 0 { - ft.DecMapStringUint64L(*v, containerLen, d) - } - d.mapEnd() - } - case map[string]int: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen != containerLenNil { - if containerLen != 0 { - ft.DecMapStringIntL(v, containerLen, d) - } - d.mapEnd() - } - case *map[string]int: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen == containerLenNil { - *v = nil - } else { - if *v == nil { - *v = make(map[string]int, decInferLen(containerLen, d.maxInitLen(), 24)) - } - if containerLen != 0 { - ft.DecMapStringIntL(*v, containerLen, d) - } - d.mapEnd() - } - case map[string]int32: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen != containerLenNil { - if containerLen != 0 { - ft.DecMapStringInt32L(v, containerLen, d) - } - d.mapEnd() - } - case *map[string]int32: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen == containerLenNil { - *v = nil - } else { - if *v == nil { - *v = make(map[string]int32, decInferLen(containerLen, d.maxInitLen(), 20)) - } - if containerLen != 0 { - ft.DecMapStringInt32L(*v, containerLen, d) - } - d.mapEnd() - } - case map[string]float64: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen != containerLenNil { - if containerLen != 0 { - ft.DecMapStringFloat64L(v, containerLen, d) - } - d.mapEnd() - } - case *map[string]float64: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen == containerLenNil { - *v = nil - } else { - if *v == nil { - *v = make(map[string]float64, decInferLen(containerLen, d.maxInitLen(), 24)) - } - if containerLen != 0 { - ft.DecMapStringFloat64L(*v, containerLen, d) - } - d.mapEnd() - } - case map[string]bool: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen != containerLenNil { - if containerLen != 0 { - ft.DecMapStringBoolL(v, containerLen, d) - } - d.mapEnd() - } - case *map[string]bool: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen == containerLenNil { - *v = nil - } else { - if *v == nil { - *v = make(map[string]bool, decInferLen(containerLen, d.maxInitLen(), 17)) - } - if containerLen != 0 { - ft.DecMapStringBoolL(*v, containerLen, d) - } - d.mapEnd() - } - case map[uint8]interface{}: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen != containerLenNil { - if containerLen != 0 { - ft.DecMapUint8IntfL(v, containerLen, d) - } - d.mapEnd() - } - case *map[uint8]interface{}: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen == containerLenNil { - *v = nil - } else { - if *v == nil { - *v = make(map[uint8]interface{}, decInferLen(containerLen, d.maxInitLen(), 17)) - } - if containerLen != 0 { - ft.DecMapUint8IntfL(*v, containerLen, d) - } - d.mapEnd() - } - case map[uint8]string: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen != containerLenNil { - if containerLen != 0 { - ft.DecMapUint8StringL(v, containerLen, d) - } - d.mapEnd() - } - case *map[uint8]string: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen == containerLenNil { - *v = nil - } else { - if *v == nil { - *v = make(map[uint8]string, decInferLen(containerLen, d.maxInitLen(), 17)) - } - if containerLen != 0 { - ft.DecMapUint8StringL(*v, containerLen, d) - } - d.mapEnd() - } - case map[uint8][]byte: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen != containerLenNil { - if containerLen != 0 { - ft.DecMapUint8BytesL(v, containerLen, d) - } - d.mapEnd() - } - case *map[uint8][]byte: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen == containerLenNil { - *v = nil - } else { - if *v == nil { - *v = make(map[uint8][]byte, decInferLen(containerLen, d.maxInitLen(), 25)) - } - if containerLen != 0 { - ft.DecMapUint8BytesL(*v, containerLen, d) - } - d.mapEnd() - } - case map[uint8]uint8: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen != containerLenNil { - if containerLen != 0 { - ft.DecMapUint8Uint8L(v, containerLen, d) - } - d.mapEnd() - } - case *map[uint8]uint8: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen == containerLenNil { - *v = nil - } else { - if *v == nil { - *v = make(map[uint8]uint8, decInferLen(containerLen, d.maxInitLen(), 2)) - } - if containerLen != 0 { - ft.DecMapUint8Uint8L(*v, containerLen, d) - } - d.mapEnd() - } - case map[uint8]uint64: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen != containerLenNil { - if containerLen != 0 { - ft.DecMapUint8Uint64L(v, containerLen, d) - } - d.mapEnd() - } - case *map[uint8]uint64: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen == containerLenNil { - *v = nil - } else { - if *v == nil { - *v = make(map[uint8]uint64, decInferLen(containerLen, d.maxInitLen(), 9)) - } - if containerLen != 0 { - ft.DecMapUint8Uint64L(*v, containerLen, d) - } - d.mapEnd() - } - case map[uint8]int: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen != containerLenNil { - if containerLen != 0 { - ft.DecMapUint8IntL(v, containerLen, d) - } - d.mapEnd() - } - case *map[uint8]int: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen == containerLenNil { - *v = nil - } else { - if *v == nil { - *v = make(map[uint8]int, decInferLen(containerLen, d.maxInitLen(), 9)) - } - if containerLen != 0 { - ft.DecMapUint8IntL(*v, containerLen, d) - } - d.mapEnd() - } - case map[uint8]int32: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen != containerLenNil { - if containerLen != 0 { - ft.DecMapUint8Int32L(v, containerLen, d) - } - d.mapEnd() - } - case *map[uint8]int32: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen == containerLenNil { - *v = nil - } else { - if *v == nil { - *v = make(map[uint8]int32, decInferLen(containerLen, d.maxInitLen(), 5)) - } - if containerLen != 0 { - ft.DecMapUint8Int32L(*v, containerLen, d) - } - d.mapEnd() - } - case map[uint8]float64: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen != containerLenNil { - if containerLen != 0 { - ft.DecMapUint8Float64L(v, containerLen, d) - } - d.mapEnd() - } - case *map[uint8]float64: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen == containerLenNil { - *v = nil - } else { - if *v == nil { - *v = make(map[uint8]float64, decInferLen(containerLen, d.maxInitLen(), 9)) - } - if containerLen != 0 { - ft.DecMapUint8Float64L(*v, containerLen, d) - } - d.mapEnd() - } - case map[uint8]bool: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen != containerLenNil { - if containerLen != 0 { - ft.DecMapUint8BoolL(v, containerLen, d) - } - d.mapEnd() - } - case *map[uint8]bool: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen == containerLenNil { - *v = nil - } else { - if *v == nil { - *v = make(map[uint8]bool, decInferLen(containerLen, d.maxInitLen(), 2)) - } - if containerLen != 0 { - ft.DecMapUint8BoolL(*v, containerLen, d) - } - d.mapEnd() - } - case map[uint64]interface{}: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen != containerLenNil { - if containerLen != 0 { - ft.DecMapUint64IntfL(v, containerLen, d) - } - d.mapEnd() - } - case *map[uint64]interface{}: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen == containerLenNil { - *v = nil - } else { - if *v == nil { - *v = make(map[uint64]interface{}, decInferLen(containerLen, d.maxInitLen(), 24)) - } - if containerLen != 0 { - ft.DecMapUint64IntfL(*v, containerLen, d) - } - d.mapEnd() - } - case map[uint64]string: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen != containerLenNil { - if containerLen != 0 { - ft.DecMapUint64StringL(v, containerLen, d) - } - d.mapEnd() - } - case *map[uint64]string: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen == containerLenNil { - *v = nil - } else { - if *v == nil { - *v = make(map[uint64]string, decInferLen(containerLen, d.maxInitLen(), 24)) - } - if containerLen != 0 { - ft.DecMapUint64StringL(*v, containerLen, d) - } - d.mapEnd() - } - case map[uint64][]byte: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen != containerLenNil { - if containerLen != 0 { - ft.DecMapUint64BytesL(v, containerLen, d) - } - d.mapEnd() - } - case *map[uint64][]byte: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen == containerLenNil { - *v = nil - } else { - if *v == nil { - *v = make(map[uint64][]byte, decInferLen(containerLen, d.maxInitLen(), 32)) - } - if containerLen != 0 { - ft.DecMapUint64BytesL(*v, containerLen, d) - } - d.mapEnd() - } - case map[uint64]uint8: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen != containerLenNil { - if containerLen != 0 { - ft.DecMapUint64Uint8L(v, containerLen, d) - } - d.mapEnd() - } - case *map[uint64]uint8: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen == containerLenNil { - *v = nil - } else { - if *v == nil { - *v = make(map[uint64]uint8, decInferLen(containerLen, d.maxInitLen(), 9)) - } - if containerLen != 0 { - ft.DecMapUint64Uint8L(*v, containerLen, d) - } - d.mapEnd() - } - case map[uint64]uint64: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen != containerLenNil { - if containerLen != 0 { - ft.DecMapUint64Uint64L(v, containerLen, d) - } - d.mapEnd() - } - case *map[uint64]uint64: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen == containerLenNil { - *v = nil - } else { - if *v == nil { - *v = make(map[uint64]uint64, decInferLen(containerLen, d.maxInitLen(), 16)) - } - if containerLen != 0 { - ft.DecMapUint64Uint64L(*v, containerLen, d) - } - d.mapEnd() - } - case map[uint64]int: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen != containerLenNil { - if containerLen != 0 { - ft.DecMapUint64IntL(v, containerLen, d) - } - d.mapEnd() - } - case *map[uint64]int: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen == containerLenNil { - *v = nil - } else { - if *v == nil { - *v = make(map[uint64]int, decInferLen(containerLen, d.maxInitLen(), 16)) - } - if containerLen != 0 { - ft.DecMapUint64IntL(*v, containerLen, d) - } - d.mapEnd() - } - case map[uint64]int32: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen != containerLenNil { - if containerLen != 0 { - ft.DecMapUint64Int32L(v, containerLen, d) - } - d.mapEnd() - } - case *map[uint64]int32: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen == containerLenNil { - *v = nil - } else { - if *v == nil { - *v = make(map[uint64]int32, decInferLen(containerLen, d.maxInitLen(), 12)) - } - if containerLen != 0 { - ft.DecMapUint64Int32L(*v, containerLen, d) - } - d.mapEnd() - } - case map[uint64]float64: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen != containerLenNil { - if containerLen != 0 { - ft.DecMapUint64Float64L(v, containerLen, d) - } - d.mapEnd() - } - case *map[uint64]float64: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen == containerLenNil { - *v = nil - } else { - if *v == nil { - *v = make(map[uint64]float64, decInferLen(containerLen, d.maxInitLen(), 16)) - } - if containerLen != 0 { - ft.DecMapUint64Float64L(*v, containerLen, d) - } - d.mapEnd() - } - case map[uint64]bool: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen != containerLenNil { - if containerLen != 0 { - ft.DecMapUint64BoolL(v, containerLen, d) - } - d.mapEnd() - } - case *map[uint64]bool: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen == containerLenNil { - *v = nil - } else { - if *v == nil { - *v = make(map[uint64]bool, decInferLen(containerLen, d.maxInitLen(), 9)) - } - if containerLen != 0 { - ft.DecMapUint64BoolL(*v, containerLen, d) - } - d.mapEnd() - } - case map[int]interface{}: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen != containerLenNil { - if containerLen != 0 { - ft.DecMapIntIntfL(v, containerLen, d) - } - d.mapEnd() - } - case *map[int]interface{}: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen == containerLenNil { - *v = nil - } else { - if *v == nil { - *v = make(map[int]interface{}, decInferLen(containerLen, d.maxInitLen(), 24)) - } - if containerLen != 0 { - ft.DecMapIntIntfL(*v, containerLen, d) - } - d.mapEnd() - } - case map[int]string: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen != containerLenNil { - if containerLen != 0 { - ft.DecMapIntStringL(v, containerLen, d) - } - d.mapEnd() - } - case *map[int]string: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen == containerLenNil { - *v = nil - } else { - if *v == nil { - *v = make(map[int]string, decInferLen(containerLen, d.maxInitLen(), 24)) - } - if containerLen != 0 { - ft.DecMapIntStringL(*v, containerLen, d) - } - d.mapEnd() - } - case map[int][]byte: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen != containerLenNil { - if containerLen != 0 { - ft.DecMapIntBytesL(v, containerLen, d) - } - d.mapEnd() - } - case *map[int][]byte: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen == containerLenNil { - *v = nil - } else { - if *v == nil { - *v = make(map[int][]byte, decInferLen(containerLen, d.maxInitLen(), 32)) - } - if containerLen != 0 { - ft.DecMapIntBytesL(*v, containerLen, d) - } - d.mapEnd() - } - case map[int]uint8: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen != containerLenNil { - if containerLen != 0 { - ft.DecMapIntUint8L(v, containerLen, d) - } - d.mapEnd() - } - case *map[int]uint8: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen == containerLenNil { - *v = nil - } else { - if *v == nil { - *v = make(map[int]uint8, decInferLen(containerLen, d.maxInitLen(), 9)) - } - if containerLen != 0 { - ft.DecMapIntUint8L(*v, containerLen, d) - } - d.mapEnd() - } - case map[int]uint64: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen != containerLenNil { - if containerLen != 0 { - ft.DecMapIntUint64L(v, containerLen, d) - } - d.mapEnd() - } - case *map[int]uint64: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen == containerLenNil { - *v = nil - } else { - if *v == nil { - *v = make(map[int]uint64, decInferLen(containerLen, d.maxInitLen(), 16)) - } - if containerLen != 0 { - ft.DecMapIntUint64L(*v, containerLen, d) - } - d.mapEnd() - } - case map[int]int: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen != containerLenNil { - if containerLen != 0 { - ft.DecMapIntIntL(v, containerLen, d) - } - d.mapEnd() - } - case *map[int]int: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen == containerLenNil { - *v = nil - } else { - if *v == nil { - *v = make(map[int]int, decInferLen(containerLen, d.maxInitLen(), 16)) - } - if containerLen != 0 { - ft.DecMapIntIntL(*v, containerLen, d) - } - d.mapEnd() - } - case map[int]int32: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen != containerLenNil { - if containerLen != 0 { - ft.DecMapIntInt32L(v, containerLen, d) - } - d.mapEnd() - } - case *map[int]int32: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen == containerLenNil { - *v = nil - } else { - if *v == nil { - *v = make(map[int]int32, decInferLen(containerLen, d.maxInitLen(), 12)) - } - if containerLen != 0 { - ft.DecMapIntInt32L(*v, containerLen, d) - } - d.mapEnd() - } - case map[int]float64: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen != containerLenNil { - if containerLen != 0 { - ft.DecMapIntFloat64L(v, containerLen, d) - } - d.mapEnd() - } - case *map[int]float64: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen == containerLenNil { - *v = nil - } else { - if *v == nil { - *v = make(map[int]float64, decInferLen(containerLen, d.maxInitLen(), 16)) - } - if containerLen != 0 { - ft.DecMapIntFloat64L(*v, containerLen, d) - } - d.mapEnd() - } - case map[int]bool: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen != containerLenNil { - if containerLen != 0 { - ft.DecMapIntBoolL(v, containerLen, d) - } - d.mapEnd() - } - case *map[int]bool: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen == containerLenNil { - *v = nil - } else { - if *v == nil { - *v = make(map[int]bool, decInferLen(containerLen, d.maxInitLen(), 9)) - } - if containerLen != 0 { - ft.DecMapIntBoolL(*v, containerLen, d) - } - d.mapEnd() - } - case map[int32]interface{}: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen != containerLenNil { - if containerLen != 0 { - ft.DecMapInt32IntfL(v, containerLen, d) - } - d.mapEnd() - } - case *map[int32]interface{}: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen == containerLenNil { - *v = nil - } else { - if *v == nil { - *v = make(map[int32]interface{}, decInferLen(containerLen, d.maxInitLen(), 20)) - } - if containerLen != 0 { - ft.DecMapInt32IntfL(*v, containerLen, d) - } - d.mapEnd() - } - case map[int32]string: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen != containerLenNil { - if containerLen != 0 { - ft.DecMapInt32StringL(v, containerLen, d) - } - d.mapEnd() - } - case *map[int32]string: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen == containerLenNil { - *v = nil - } else { - if *v == nil { - *v = make(map[int32]string, decInferLen(containerLen, d.maxInitLen(), 20)) - } - if containerLen != 0 { - ft.DecMapInt32StringL(*v, containerLen, d) - } - d.mapEnd() - } - case map[int32][]byte: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen != containerLenNil { - if containerLen != 0 { - ft.DecMapInt32BytesL(v, containerLen, d) - } - d.mapEnd() - } - case *map[int32][]byte: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen == containerLenNil { - *v = nil - } else { - if *v == nil { - *v = make(map[int32][]byte, decInferLen(containerLen, d.maxInitLen(), 28)) - } - if containerLen != 0 { - ft.DecMapInt32BytesL(*v, containerLen, d) - } - d.mapEnd() - } - case map[int32]uint8: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen != containerLenNil { - if containerLen != 0 { - ft.DecMapInt32Uint8L(v, containerLen, d) - } - d.mapEnd() - } - case *map[int32]uint8: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen == containerLenNil { - *v = nil - } else { - if *v == nil { - *v = make(map[int32]uint8, decInferLen(containerLen, d.maxInitLen(), 5)) - } - if containerLen != 0 { - ft.DecMapInt32Uint8L(*v, containerLen, d) - } - d.mapEnd() - } - case map[int32]uint64: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen != containerLenNil { - if containerLen != 0 { - ft.DecMapInt32Uint64L(v, containerLen, d) - } - d.mapEnd() - } - case *map[int32]uint64: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen == containerLenNil { - *v = nil - } else { - if *v == nil { - *v = make(map[int32]uint64, decInferLen(containerLen, d.maxInitLen(), 12)) - } - if containerLen != 0 { - ft.DecMapInt32Uint64L(*v, containerLen, d) - } - d.mapEnd() - } - case map[int32]int: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen != containerLenNil { - if containerLen != 0 { - ft.DecMapInt32IntL(v, containerLen, d) - } - d.mapEnd() - } - case *map[int32]int: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen == containerLenNil { - *v = nil - } else { - if *v == nil { - *v = make(map[int32]int, decInferLen(containerLen, d.maxInitLen(), 12)) - } - if containerLen != 0 { - ft.DecMapInt32IntL(*v, containerLen, d) - } - d.mapEnd() - } - case map[int32]int32: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen != containerLenNil { - if containerLen != 0 { - ft.DecMapInt32Int32L(v, containerLen, d) - } - d.mapEnd() - } - case *map[int32]int32: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen == containerLenNil { - *v = nil - } else { - if *v == nil { - *v = make(map[int32]int32, decInferLen(containerLen, d.maxInitLen(), 8)) - } - if containerLen != 0 { - ft.DecMapInt32Int32L(*v, containerLen, d) - } - d.mapEnd() - } - case map[int32]float64: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen != containerLenNil { - if containerLen != 0 { - ft.DecMapInt32Float64L(v, containerLen, d) - } - d.mapEnd() - } - case *map[int32]float64: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen == containerLenNil { - *v = nil - } else { - if *v == nil { - *v = make(map[int32]float64, decInferLen(containerLen, d.maxInitLen(), 12)) - } - if containerLen != 0 { - ft.DecMapInt32Float64L(*v, containerLen, d) - } - d.mapEnd() - } - case map[int32]bool: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen != containerLenNil { - if containerLen != 0 { - ft.DecMapInt32BoolL(v, containerLen, d) - } - d.mapEnd() - } - case *map[int32]bool: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen == containerLenNil { - *v = nil - } else { - if *v == nil { - *v = make(map[int32]bool, decInferLen(containerLen, d.maxInitLen(), 5)) - } - if containerLen != 0 { - ft.DecMapInt32BoolL(*v, containerLen, d) - } - d.mapEnd() - } - default: - _ = v - return false - } - return true -} - -func (d *decoderCborBytes) fastpathDecSliceIntfR(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTCborBytes - switch rv.Kind() { - case reflect.Ptr: - v := rv2i(rv).(*[]interface{}) - if vv, changed := ft.DecSliceIntfY(*v, d); changed { - *v = vv - } - case reflect.Array: - var v []interface{} - rvGetSlice4Array(rv, &v) - ft.DecSliceIntfN(v, d) - default: - ft.DecSliceIntfN(rv2i(rv).([]interface{}), d) - } -} -func (fastpathDTCborBytes) DecSliceIntfY(v []interface{}, d *decoderCborBytes) (v2 []interface{}, changed bool) { - ctyp := d.d.ContainerType() - if ctyp == valueTypeNil { - return nil, v != nil - } - var containerLenS int - isArray := ctyp == valueTypeArray - if isArray { - containerLenS = d.arrayStart(d.d.ReadArrayStart()) - } else if ctyp == valueTypeMap { - containerLenS = d.mapStart(d.d.ReadMapStart()) * 2 - } else { - halt.errorStr2("decoding into a slice, expect map/array - got ", ctyp.String()) - } - hasLen := containerLenS >= 0 - var j int - fnv := func(dst []interface{}) { v, changed = dst, true } - for ; d.containerNext(j, containerLenS, hasLen); j++ { - if j == 0 { - if containerLenS == len(v) { - } else if containerLenS < 0 || containerLenS > cap(v) { - if xlen := int(decInferLen(containerLenS, d.maxInitLen(), 16)); xlen <= cap(v) { - fnv(v[:uint(xlen)]) - } else { - v2 = make([]interface{}, uint(xlen)) - copy(v2, v) - fnv(v2) - } - } else { - fnv(v[:containerLenS]) - } - } - if isArray { - d.arrayElem(j == 0) - } else if j&1 == 0 { - d.mapElemKey(j == 0) - } else { - d.mapElemValue() - } - if j >= len(v) { - fnv(append(v, nil)) - } - d.decode(&v[uint(j)]) - } - if j < len(v) { - fnv(v[:uint(j)]) - } else if j == 0 && v == nil { - fnv([]interface{}{}) - } - if isArray { - d.arrayEnd() - } else { - d.mapEnd() - } - return v, changed -} -func (fastpathDTCborBytes) DecSliceIntfN(v []interface{}, d *decoderCborBytes) { - ctyp := d.d.ContainerType() - if ctyp == valueTypeNil { - return - } - var containerLenS int - isArray := ctyp == valueTypeArray - if isArray { - containerLenS = d.arrayStart(d.d.ReadArrayStart()) - } else if ctyp == valueTypeMap { - containerLenS = d.mapStart(d.d.ReadMapStart()) * 2 - } else { - halt.errorStr2("decoding into a slice, expect map/array - got ", ctyp.String()) - } - hasLen := containerLenS >= 0 - for j := 0; d.containerNext(j, containerLenS, hasLen); j++ { - if isArray { - d.arrayElem(j == 0) - } else if j&1 == 0 { - d.mapElemKey(j == 0) - } else { - d.mapElemValue() - } - if j < len(v) { - d.decode(&v[uint(j)]) - } else { - d.arrayCannotExpand(len(v), j+1) - d.swallow() - } - } - if isArray { - d.arrayEnd() - } else { - d.mapEnd() - } -} - -func (d *decoderCborBytes) fastpathDecSliceStringR(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTCborBytes - switch rv.Kind() { - case reflect.Ptr: - v := rv2i(rv).(*[]string) - if vv, changed := ft.DecSliceStringY(*v, d); changed { - *v = vv - } - case reflect.Array: - var v []string - rvGetSlice4Array(rv, &v) - ft.DecSliceStringN(v, d) - default: - ft.DecSliceStringN(rv2i(rv).([]string), d) - } -} -func (fastpathDTCborBytes) DecSliceStringY(v []string, d *decoderCborBytes) (v2 []string, changed bool) { - ctyp := d.d.ContainerType() - if ctyp == valueTypeNil { - return nil, v != nil - } - var containerLenS int - isArray := ctyp == valueTypeArray - if isArray { - containerLenS = d.arrayStart(d.d.ReadArrayStart()) - } else if ctyp == valueTypeMap { - containerLenS = d.mapStart(d.d.ReadMapStart()) * 2 - } else { - halt.errorStr2("decoding into a slice, expect map/array - got ", ctyp.String()) - } - hasLen := containerLenS >= 0 - var j int - fnv := func(dst []string) { v, changed = dst, true } - for ; d.containerNext(j, containerLenS, hasLen); j++ { - if j == 0 { - if containerLenS == len(v) { - } else if containerLenS < 0 || containerLenS > cap(v) { - if xlen := int(decInferLen(containerLenS, d.maxInitLen(), 16)); xlen <= cap(v) { - fnv(v[:uint(xlen)]) - } else { - v2 = make([]string, uint(xlen)) - copy(v2, v) - fnv(v2) - } - } else { - fnv(v[:containerLenS]) - } - } - if isArray { - d.arrayElem(j == 0) - } else if j&1 == 0 { - d.mapElemKey(j == 0) - } else { - d.mapElemValue() - } - if j >= len(v) { - fnv(append(v, "")) - } - v[uint(j)] = d.detach2Str(d.d.DecodeStringAsBytes()) - } - if j < len(v) { - fnv(v[:uint(j)]) - } else if j == 0 && v == nil { - fnv([]string{}) - } - if isArray { - d.arrayEnd() - } else { - d.mapEnd() - } - return v, changed -} -func (fastpathDTCborBytes) DecSliceStringN(v []string, d *decoderCborBytes) { - ctyp := d.d.ContainerType() - if ctyp == valueTypeNil { - return - } - var containerLenS int - isArray := ctyp == valueTypeArray - if isArray { - containerLenS = d.arrayStart(d.d.ReadArrayStart()) - } else if ctyp == valueTypeMap { - containerLenS = d.mapStart(d.d.ReadMapStart()) * 2 - } else { - halt.errorStr2("decoding into a slice, expect map/array - got ", ctyp.String()) - } - hasLen := containerLenS >= 0 - for j := 0; d.containerNext(j, containerLenS, hasLen); j++ { - if isArray { - d.arrayElem(j == 0) - } else if j&1 == 0 { - d.mapElemKey(j == 0) - } else { - d.mapElemValue() - } - if j < len(v) { - v[uint(j)] = d.detach2Str(d.d.DecodeStringAsBytes()) - } else { - d.arrayCannotExpand(len(v), j+1) - d.swallow() - } - } - if isArray { - d.arrayEnd() - } else { - d.mapEnd() - } -} - -func (d *decoderCborBytes) fastpathDecSliceBytesR(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTCborBytes - switch rv.Kind() { - case reflect.Ptr: - v := rv2i(rv).(*[][]byte) - if vv, changed := ft.DecSliceBytesY(*v, d); changed { - *v = vv - } - case reflect.Array: - var v [][]byte - rvGetSlice4Array(rv, &v) - ft.DecSliceBytesN(v, d) - default: - ft.DecSliceBytesN(rv2i(rv).([][]byte), d) - } -} -func (fastpathDTCborBytes) DecSliceBytesY(v [][]byte, d *decoderCborBytes) (v2 [][]byte, changed bool) { - ctyp := d.d.ContainerType() - if ctyp == valueTypeNil { - return nil, v != nil - } - var containerLenS int - isArray := ctyp == valueTypeArray - if isArray { - containerLenS = d.arrayStart(d.d.ReadArrayStart()) - } else if ctyp == valueTypeMap { - containerLenS = d.mapStart(d.d.ReadMapStart()) * 2 - } else { - halt.errorStr2("decoding into a slice, expect map/array - got ", ctyp.String()) - } - hasLen := containerLenS >= 0 - var j int - fnv := func(dst [][]byte) { v, changed = dst, true } - for ; d.containerNext(j, containerLenS, hasLen); j++ { - if j == 0 { - if containerLenS == len(v) { - } else if containerLenS < 0 || containerLenS > cap(v) { - if xlen := int(decInferLen(containerLenS, d.maxInitLen(), 24)); xlen <= cap(v) { - fnv(v[:uint(xlen)]) - } else { - v2 = make([][]byte, uint(xlen)) - copy(v2, v) - fnv(v2) - } - } else { - fnv(v[:containerLenS]) - } - } - if isArray { - d.arrayElem(j == 0) - } else if j&1 == 0 { - d.mapElemKey(j == 0) - } else { - d.mapElemValue() - } - if j >= len(v) { - fnv(append(v, nil)) - } - v[uint(j)] = bytesOKdbi(d.decodeBytesInto(v[uint(j)], false)) - } - if j < len(v) { - fnv(v[:uint(j)]) - } else if j == 0 && v == nil { - fnv([][]byte{}) - } - if isArray { - d.arrayEnd() - } else { - d.mapEnd() - } - return v, changed -} -func (fastpathDTCborBytes) DecSliceBytesN(v [][]byte, d *decoderCborBytes) { - ctyp := d.d.ContainerType() - if ctyp == valueTypeNil { - return - } - var containerLenS int - isArray := ctyp == valueTypeArray - if isArray { - containerLenS = d.arrayStart(d.d.ReadArrayStart()) - } else if ctyp == valueTypeMap { - containerLenS = d.mapStart(d.d.ReadMapStart()) * 2 - } else { - halt.errorStr2("decoding into a slice, expect map/array - got ", ctyp.String()) - } - hasLen := containerLenS >= 0 - for j := 0; d.containerNext(j, containerLenS, hasLen); j++ { - if isArray { - d.arrayElem(j == 0) - } else if j&1 == 0 { - d.mapElemKey(j == 0) - } else { - d.mapElemValue() - } - if j < len(v) { - v[uint(j)] = bytesOKdbi(d.decodeBytesInto(v[uint(j)], false)) - } else { - d.arrayCannotExpand(len(v), j+1) - d.swallow() - } - } - if isArray { - d.arrayEnd() - } else { - d.mapEnd() - } -} - -func (d *decoderCborBytes) fastpathDecSliceFloat32R(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTCborBytes - switch rv.Kind() { - case reflect.Ptr: - v := rv2i(rv).(*[]float32) - if vv, changed := ft.DecSliceFloat32Y(*v, d); changed { - *v = vv - } - case reflect.Array: - var v []float32 - rvGetSlice4Array(rv, &v) - ft.DecSliceFloat32N(v, d) - default: - ft.DecSliceFloat32N(rv2i(rv).([]float32), d) - } -} -func (fastpathDTCborBytes) DecSliceFloat32Y(v []float32, d *decoderCborBytes) (v2 []float32, changed bool) { - ctyp := d.d.ContainerType() - if ctyp == valueTypeNil { - return nil, v != nil - } - var containerLenS int - isArray := ctyp == valueTypeArray - if isArray { - containerLenS = d.arrayStart(d.d.ReadArrayStart()) - } else if ctyp == valueTypeMap { - containerLenS = d.mapStart(d.d.ReadMapStart()) * 2 - } else { - halt.errorStr2("decoding into a slice, expect map/array - got ", ctyp.String()) - } - hasLen := containerLenS >= 0 - var j int - fnv := func(dst []float32) { v, changed = dst, true } - for ; d.containerNext(j, containerLenS, hasLen); j++ { - if j == 0 { - if containerLenS == len(v) { - } else if containerLenS < 0 || containerLenS > cap(v) { - if xlen := int(decInferLen(containerLenS, d.maxInitLen(), 4)); xlen <= cap(v) { - fnv(v[:uint(xlen)]) - } else { - v2 = make([]float32, uint(xlen)) - copy(v2, v) - fnv(v2) - } - } else { - fnv(v[:containerLenS]) - } - } - if isArray { - d.arrayElem(j == 0) - } else if j&1 == 0 { - d.mapElemKey(j == 0) - } else { - d.mapElemValue() - } - if j >= len(v) { - fnv(append(v, 0)) - } - v[uint(j)] = float32(d.d.DecodeFloat32()) - } - if j < len(v) { - fnv(v[:uint(j)]) - } else if j == 0 && v == nil { - fnv([]float32{}) - } - if isArray { - d.arrayEnd() - } else { - d.mapEnd() - } - return v, changed -} -func (fastpathDTCborBytes) DecSliceFloat32N(v []float32, d *decoderCborBytes) { - ctyp := d.d.ContainerType() - if ctyp == valueTypeNil { - return - } - var containerLenS int - isArray := ctyp == valueTypeArray - if isArray { - containerLenS = d.arrayStart(d.d.ReadArrayStart()) - } else if ctyp == valueTypeMap { - containerLenS = d.mapStart(d.d.ReadMapStart()) * 2 - } else { - halt.errorStr2("decoding into a slice, expect map/array - got ", ctyp.String()) - } - hasLen := containerLenS >= 0 - for j := 0; d.containerNext(j, containerLenS, hasLen); j++ { - if isArray { - d.arrayElem(j == 0) - } else if j&1 == 0 { - d.mapElemKey(j == 0) - } else { - d.mapElemValue() - } - if j < len(v) { - v[uint(j)] = float32(d.d.DecodeFloat32()) - } else { - d.arrayCannotExpand(len(v), j+1) - d.swallow() - } - } - if isArray { - d.arrayEnd() - } else { - d.mapEnd() - } -} - -func (d *decoderCborBytes) fastpathDecSliceFloat64R(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTCborBytes - switch rv.Kind() { - case reflect.Ptr: - v := rv2i(rv).(*[]float64) - if vv, changed := ft.DecSliceFloat64Y(*v, d); changed { - *v = vv - } - case reflect.Array: - var v []float64 - rvGetSlice4Array(rv, &v) - ft.DecSliceFloat64N(v, d) - default: - ft.DecSliceFloat64N(rv2i(rv).([]float64), d) - } -} -func (fastpathDTCborBytes) DecSliceFloat64Y(v []float64, d *decoderCborBytes) (v2 []float64, changed bool) { - ctyp := d.d.ContainerType() - if ctyp == valueTypeNil { - return nil, v != nil - } - var containerLenS int - isArray := ctyp == valueTypeArray - if isArray { - containerLenS = d.arrayStart(d.d.ReadArrayStart()) - } else if ctyp == valueTypeMap { - containerLenS = d.mapStart(d.d.ReadMapStart()) * 2 - } else { - halt.errorStr2("decoding into a slice, expect map/array - got ", ctyp.String()) - } - hasLen := containerLenS >= 0 - var j int - fnv := func(dst []float64) { v, changed = dst, true } - for ; d.containerNext(j, containerLenS, hasLen); j++ { - if j == 0 { - if containerLenS == len(v) { - } else if containerLenS < 0 || containerLenS > cap(v) { - if xlen := int(decInferLen(containerLenS, d.maxInitLen(), 8)); xlen <= cap(v) { - fnv(v[:uint(xlen)]) - } else { - v2 = make([]float64, uint(xlen)) - copy(v2, v) - fnv(v2) - } - } else { - fnv(v[:containerLenS]) - } - } - if isArray { - d.arrayElem(j == 0) - } else if j&1 == 0 { - d.mapElemKey(j == 0) - } else { - d.mapElemValue() - } - if j >= len(v) { - fnv(append(v, 0)) - } - v[uint(j)] = d.d.DecodeFloat64() - } - if j < len(v) { - fnv(v[:uint(j)]) - } else if j == 0 && v == nil { - fnv([]float64{}) - } - if isArray { - d.arrayEnd() - } else { - d.mapEnd() - } - return v, changed -} -func (fastpathDTCborBytes) DecSliceFloat64N(v []float64, d *decoderCborBytes) { - ctyp := d.d.ContainerType() - if ctyp == valueTypeNil { - return - } - var containerLenS int - isArray := ctyp == valueTypeArray - if isArray { - containerLenS = d.arrayStart(d.d.ReadArrayStart()) - } else if ctyp == valueTypeMap { - containerLenS = d.mapStart(d.d.ReadMapStart()) * 2 - } else { - halt.errorStr2("decoding into a slice, expect map/array - got ", ctyp.String()) - } - hasLen := containerLenS >= 0 - for j := 0; d.containerNext(j, containerLenS, hasLen); j++ { - if isArray { - d.arrayElem(j == 0) - } else if j&1 == 0 { - d.mapElemKey(j == 0) - } else { - d.mapElemValue() - } - if j < len(v) { - v[uint(j)] = d.d.DecodeFloat64() - } else { - d.arrayCannotExpand(len(v), j+1) - d.swallow() - } - } - if isArray { - d.arrayEnd() - } else { - d.mapEnd() - } -} - -func (d *decoderCborBytes) fastpathDecSliceUint8R(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTCborBytes - switch rv.Kind() { - case reflect.Ptr: - v := rv2i(rv).(*[]uint8) - if vv, changed := ft.DecSliceUint8Y(*v, d); changed { - *v = vv - } - case reflect.Array: - var v []uint8 - rvGetSlice4Array(rv, &v) - ft.DecSliceUint8N(v, d) - default: - ft.DecSliceUint8N(rv2i(rv).([]uint8), d) - } -} -func (fastpathDTCborBytes) DecSliceUint8Y(v []uint8, d *decoderCborBytes) (v2 []uint8, changed bool) { - ctyp := d.d.ContainerType() - if ctyp == valueTypeNil { - return nil, v != nil - } - if ctyp != valueTypeMap { - var dbi dBytesIntoState - v2, dbi = d.decodeBytesInto(v[:len(v):len(v)], false) - return v2, dbi != dBytesIntoParamOut - } - containerLenS := d.mapStart(d.d.ReadMapStart()) * 2 - hasLen := containerLenS >= 0 - var j int - fnv := func(dst []uint8) { v, changed = dst, true } - for ; d.containerNext(j, containerLenS, hasLen); j++ { - if j == 0 { - if containerLenS == len(v) { - } else if containerLenS < 0 || containerLenS > cap(v) { - if xlen := int(decInferLen(containerLenS, d.maxInitLen(), 1)); xlen <= cap(v) { - fnv(v[:uint(xlen)]) - } else { - v2 = make([]uint8, uint(xlen)) - copy(v2, v) - fnv(v2) - } - } else { - fnv(v[:containerLenS]) - } - } - if j&1 == 0 { - d.mapElemKey(j == 0) - } else { - d.mapElemValue() - } - if j >= len(v) { - fnv(append(v, 0)) - } - v[uint(j)] = uint8(chkOvf.UintV(d.d.DecodeUint64(), 8)) - } - if j < len(v) { - fnv(v[:uint(j)]) - } else if j == 0 && v == nil { - fnv([]uint8{}) - } - d.mapEnd() - return v, changed -} -func (fastpathDTCborBytes) DecSliceUint8N(v []uint8, d *decoderCborBytes) { - ctyp := d.d.ContainerType() - if ctyp == valueTypeNil { - return - } - if ctyp != valueTypeMap { - d.decodeBytesInto(v[:len(v):len(v)], true) - return - } - containerLenS := d.mapStart(d.d.ReadMapStart()) * 2 - hasLen := containerLenS >= 0 - for j := 0; d.containerNext(j, containerLenS, hasLen); j++ { - if j&1 == 0 { - d.mapElemKey(j == 0) - } else { - d.mapElemValue() - } - if j < len(v) { - v[uint(j)] = uint8(chkOvf.UintV(d.d.DecodeUint64(), 8)) - } else { - d.arrayCannotExpand(len(v), j+1) - d.swallow() - } - } - d.mapEnd() -} - -func (d *decoderCborBytes) fastpathDecSliceUint64R(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTCborBytes - switch rv.Kind() { - case reflect.Ptr: - v := rv2i(rv).(*[]uint64) - if vv, changed := ft.DecSliceUint64Y(*v, d); changed { - *v = vv - } - case reflect.Array: - var v []uint64 - rvGetSlice4Array(rv, &v) - ft.DecSliceUint64N(v, d) - default: - ft.DecSliceUint64N(rv2i(rv).([]uint64), d) - } -} -func (fastpathDTCborBytes) DecSliceUint64Y(v []uint64, d *decoderCborBytes) (v2 []uint64, changed bool) { - ctyp := d.d.ContainerType() - if ctyp == valueTypeNil { - return nil, v != nil - } - var containerLenS int - isArray := ctyp == valueTypeArray - if isArray { - containerLenS = d.arrayStart(d.d.ReadArrayStart()) - } else if ctyp == valueTypeMap { - containerLenS = d.mapStart(d.d.ReadMapStart()) * 2 - } else { - halt.errorStr2("decoding into a slice, expect map/array - got ", ctyp.String()) - } - hasLen := containerLenS >= 0 - var j int - fnv := func(dst []uint64) { v, changed = dst, true } - for ; d.containerNext(j, containerLenS, hasLen); j++ { - if j == 0 { - if containerLenS == len(v) { - } else if containerLenS < 0 || containerLenS > cap(v) { - if xlen := int(decInferLen(containerLenS, d.maxInitLen(), 8)); xlen <= cap(v) { - fnv(v[:uint(xlen)]) - } else { - v2 = make([]uint64, uint(xlen)) - copy(v2, v) - fnv(v2) - } - } else { - fnv(v[:containerLenS]) - } - } - if isArray { - d.arrayElem(j == 0) - } else if j&1 == 0 { - d.mapElemKey(j == 0) - } else { - d.mapElemValue() - } - if j >= len(v) { - fnv(append(v, 0)) - } - v[uint(j)] = d.d.DecodeUint64() - } - if j < len(v) { - fnv(v[:uint(j)]) - } else if j == 0 && v == nil { - fnv([]uint64{}) - } - if isArray { - d.arrayEnd() - } else { - d.mapEnd() - } - return v, changed -} -func (fastpathDTCborBytes) DecSliceUint64N(v []uint64, d *decoderCborBytes) { - ctyp := d.d.ContainerType() - if ctyp == valueTypeNil { - return - } - var containerLenS int - isArray := ctyp == valueTypeArray - if isArray { - containerLenS = d.arrayStart(d.d.ReadArrayStart()) - } else if ctyp == valueTypeMap { - containerLenS = d.mapStart(d.d.ReadMapStart()) * 2 - } else { - halt.errorStr2("decoding into a slice, expect map/array - got ", ctyp.String()) - } - hasLen := containerLenS >= 0 - for j := 0; d.containerNext(j, containerLenS, hasLen); j++ { - if isArray { - d.arrayElem(j == 0) - } else if j&1 == 0 { - d.mapElemKey(j == 0) - } else { - d.mapElemValue() - } - if j < len(v) { - v[uint(j)] = d.d.DecodeUint64() - } else { - d.arrayCannotExpand(len(v), j+1) - d.swallow() - } - } - if isArray { - d.arrayEnd() - } else { - d.mapEnd() - } -} - -func (d *decoderCborBytes) fastpathDecSliceIntR(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTCborBytes - switch rv.Kind() { - case reflect.Ptr: - v := rv2i(rv).(*[]int) - if vv, changed := ft.DecSliceIntY(*v, d); changed { - *v = vv - } - case reflect.Array: - var v []int - rvGetSlice4Array(rv, &v) - ft.DecSliceIntN(v, d) - default: - ft.DecSliceIntN(rv2i(rv).([]int), d) - } -} -func (fastpathDTCborBytes) DecSliceIntY(v []int, d *decoderCborBytes) (v2 []int, changed bool) { - ctyp := d.d.ContainerType() - if ctyp == valueTypeNil { - return nil, v != nil - } - var containerLenS int - isArray := ctyp == valueTypeArray - if isArray { - containerLenS = d.arrayStart(d.d.ReadArrayStart()) - } else if ctyp == valueTypeMap { - containerLenS = d.mapStart(d.d.ReadMapStart()) * 2 - } else { - halt.errorStr2("decoding into a slice, expect map/array - got ", ctyp.String()) - } - hasLen := containerLenS >= 0 - var j int - fnv := func(dst []int) { v, changed = dst, true } - for ; d.containerNext(j, containerLenS, hasLen); j++ { - if j == 0 { - if containerLenS == len(v) { - } else if containerLenS < 0 || containerLenS > cap(v) { - if xlen := int(decInferLen(containerLenS, d.maxInitLen(), 8)); xlen <= cap(v) { - fnv(v[:uint(xlen)]) - } else { - v2 = make([]int, uint(xlen)) - copy(v2, v) - fnv(v2) - } - } else { - fnv(v[:containerLenS]) - } - } - if isArray { - d.arrayElem(j == 0) - } else if j&1 == 0 { - d.mapElemKey(j == 0) - } else { - d.mapElemValue() - } - if j >= len(v) { - fnv(append(v, 0)) - } - v[uint(j)] = int(chkOvf.IntV(d.d.DecodeInt64(), intBitsize)) - } - if j < len(v) { - fnv(v[:uint(j)]) - } else if j == 0 && v == nil { - fnv([]int{}) - } - if isArray { - d.arrayEnd() - } else { - d.mapEnd() - } - return v, changed -} -func (fastpathDTCborBytes) DecSliceIntN(v []int, d *decoderCborBytes) { - ctyp := d.d.ContainerType() - if ctyp == valueTypeNil { - return - } - var containerLenS int - isArray := ctyp == valueTypeArray - if isArray { - containerLenS = d.arrayStart(d.d.ReadArrayStart()) - } else if ctyp == valueTypeMap { - containerLenS = d.mapStart(d.d.ReadMapStart()) * 2 - } else { - halt.errorStr2("decoding into a slice, expect map/array - got ", ctyp.String()) - } - hasLen := containerLenS >= 0 - for j := 0; d.containerNext(j, containerLenS, hasLen); j++ { - if isArray { - d.arrayElem(j == 0) - } else if j&1 == 0 { - d.mapElemKey(j == 0) - } else { - d.mapElemValue() - } - if j < len(v) { - v[uint(j)] = int(chkOvf.IntV(d.d.DecodeInt64(), intBitsize)) - } else { - d.arrayCannotExpand(len(v), j+1) - d.swallow() - } - } - if isArray { - d.arrayEnd() - } else { - d.mapEnd() - } -} - -func (d *decoderCborBytes) fastpathDecSliceInt32R(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTCborBytes - switch rv.Kind() { - case reflect.Ptr: - v := rv2i(rv).(*[]int32) - if vv, changed := ft.DecSliceInt32Y(*v, d); changed { - *v = vv - } - case reflect.Array: - var v []int32 - rvGetSlice4Array(rv, &v) - ft.DecSliceInt32N(v, d) - default: - ft.DecSliceInt32N(rv2i(rv).([]int32), d) - } -} -func (fastpathDTCborBytes) DecSliceInt32Y(v []int32, d *decoderCborBytes) (v2 []int32, changed bool) { - ctyp := d.d.ContainerType() - if ctyp == valueTypeNil { - return nil, v != nil - } - var containerLenS int - isArray := ctyp == valueTypeArray - if isArray { - containerLenS = d.arrayStart(d.d.ReadArrayStart()) - } else if ctyp == valueTypeMap { - containerLenS = d.mapStart(d.d.ReadMapStart()) * 2 - } else { - halt.errorStr2("decoding into a slice, expect map/array - got ", ctyp.String()) - } - hasLen := containerLenS >= 0 - var j int - fnv := func(dst []int32) { v, changed = dst, true } - for ; d.containerNext(j, containerLenS, hasLen); j++ { - if j == 0 { - if containerLenS == len(v) { - } else if containerLenS < 0 || containerLenS > cap(v) { - if xlen := int(decInferLen(containerLenS, d.maxInitLen(), 4)); xlen <= cap(v) { - fnv(v[:uint(xlen)]) - } else { - v2 = make([]int32, uint(xlen)) - copy(v2, v) - fnv(v2) - } - } else { - fnv(v[:containerLenS]) - } - } - if isArray { - d.arrayElem(j == 0) - } else if j&1 == 0 { - d.mapElemKey(j == 0) - } else { - d.mapElemValue() - } - if j >= len(v) { - fnv(append(v, 0)) - } - v[uint(j)] = int32(chkOvf.IntV(d.d.DecodeInt64(), 32)) - } - if j < len(v) { - fnv(v[:uint(j)]) - } else if j == 0 && v == nil { - fnv([]int32{}) - } - if isArray { - d.arrayEnd() - } else { - d.mapEnd() - } - return v, changed -} -func (fastpathDTCborBytes) DecSliceInt32N(v []int32, d *decoderCborBytes) { - ctyp := d.d.ContainerType() - if ctyp == valueTypeNil { - return - } - var containerLenS int - isArray := ctyp == valueTypeArray - if isArray { - containerLenS = d.arrayStart(d.d.ReadArrayStart()) - } else if ctyp == valueTypeMap { - containerLenS = d.mapStart(d.d.ReadMapStart()) * 2 - } else { - halt.errorStr2("decoding into a slice, expect map/array - got ", ctyp.String()) - } - hasLen := containerLenS >= 0 - for j := 0; d.containerNext(j, containerLenS, hasLen); j++ { - if isArray { - d.arrayElem(j == 0) - } else if j&1 == 0 { - d.mapElemKey(j == 0) - } else { - d.mapElemValue() - } - if j < len(v) { - v[uint(j)] = int32(chkOvf.IntV(d.d.DecodeInt64(), 32)) - } else { - d.arrayCannotExpand(len(v), j+1) - d.swallow() - } - } - if isArray { - d.arrayEnd() - } else { - d.mapEnd() - } -} - -func (d *decoderCborBytes) fastpathDecSliceInt64R(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTCborBytes - switch rv.Kind() { - case reflect.Ptr: - v := rv2i(rv).(*[]int64) - if vv, changed := ft.DecSliceInt64Y(*v, d); changed { - *v = vv - } - case reflect.Array: - var v []int64 - rvGetSlice4Array(rv, &v) - ft.DecSliceInt64N(v, d) - default: - ft.DecSliceInt64N(rv2i(rv).([]int64), d) - } -} -func (fastpathDTCborBytes) DecSliceInt64Y(v []int64, d *decoderCborBytes) (v2 []int64, changed bool) { - ctyp := d.d.ContainerType() - if ctyp == valueTypeNil { - return nil, v != nil - } - var containerLenS int - isArray := ctyp == valueTypeArray - if isArray { - containerLenS = d.arrayStart(d.d.ReadArrayStart()) - } else if ctyp == valueTypeMap { - containerLenS = d.mapStart(d.d.ReadMapStart()) * 2 - } else { - halt.errorStr2("decoding into a slice, expect map/array - got ", ctyp.String()) - } - hasLen := containerLenS >= 0 - var j int - fnv := func(dst []int64) { v, changed = dst, true } - for ; d.containerNext(j, containerLenS, hasLen); j++ { - if j == 0 { - if containerLenS == len(v) { - } else if containerLenS < 0 || containerLenS > cap(v) { - if xlen := int(decInferLen(containerLenS, d.maxInitLen(), 8)); xlen <= cap(v) { - fnv(v[:uint(xlen)]) - } else { - v2 = make([]int64, uint(xlen)) - copy(v2, v) - fnv(v2) - } - } else { - fnv(v[:containerLenS]) - } - } - if isArray { - d.arrayElem(j == 0) - } else if j&1 == 0 { - d.mapElemKey(j == 0) - } else { - d.mapElemValue() - } - if j >= len(v) { - fnv(append(v, 0)) - } - v[uint(j)] = d.d.DecodeInt64() - } - if j < len(v) { - fnv(v[:uint(j)]) - } else if j == 0 && v == nil { - fnv([]int64{}) - } - if isArray { - d.arrayEnd() - } else { - d.mapEnd() - } - return v, changed -} -func (fastpathDTCborBytes) DecSliceInt64N(v []int64, d *decoderCborBytes) { - ctyp := d.d.ContainerType() - if ctyp == valueTypeNil { - return - } - var containerLenS int - isArray := ctyp == valueTypeArray - if isArray { - containerLenS = d.arrayStart(d.d.ReadArrayStart()) - } else if ctyp == valueTypeMap { - containerLenS = d.mapStart(d.d.ReadMapStart()) * 2 - } else { - halt.errorStr2("decoding into a slice, expect map/array - got ", ctyp.String()) - } - hasLen := containerLenS >= 0 - for j := 0; d.containerNext(j, containerLenS, hasLen); j++ { - if isArray { - d.arrayElem(j == 0) - } else if j&1 == 0 { - d.mapElemKey(j == 0) - } else { - d.mapElemValue() - } - if j < len(v) { - v[uint(j)] = d.d.DecodeInt64() - } else { - d.arrayCannotExpand(len(v), j+1) - d.swallow() - } - } - if isArray { - d.arrayEnd() - } else { - d.mapEnd() - } -} - -func (d *decoderCborBytes) fastpathDecSliceBoolR(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTCborBytes - switch rv.Kind() { - case reflect.Ptr: - v := rv2i(rv).(*[]bool) - if vv, changed := ft.DecSliceBoolY(*v, d); changed { - *v = vv - } - case reflect.Array: - var v []bool - rvGetSlice4Array(rv, &v) - ft.DecSliceBoolN(v, d) - default: - ft.DecSliceBoolN(rv2i(rv).([]bool), d) - } -} -func (fastpathDTCborBytes) DecSliceBoolY(v []bool, d *decoderCborBytes) (v2 []bool, changed bool) { - ctyp := d.d.ContainerType() - if ctyp == valueTypeNil { - return nil, v != nil - } - var containerLenS int - isArray := ctyp == valueTypeArray - if isArray { - containerLenS = d.arrayStart(d.d.ReadArrayStart()) - } else if ctyp == valueTypeMap { - containerLenS = d.mapStart(d.d.ReadMapStart()) * 2 - } else { - halt.errorStr2("decoding into a slice, expect map/array - got ", ctyp.String()) - } - hasLen := containerLenS >= 0 - var j int - fnv := func(dst []bool) { v, changed = dst, true } - for ; d.containerNext(j, containerLenS, hasLen); j++ { - if j == 0 { - if containerLenS == len(v) { - } else if containerLenS < 0 || containerLenS > cap(v) { - if xlen := int(decInferLen(containerLenS, d.maxInitLen(), 1)); xlen <= cap(v) { - fnv(v[:uint(xlen)]) - } else { - v2 = make([]bool, uint(xlen)) - copy(v2, v) - fnv(v2) - } - } else { - fnv(v[:containerLenS]) - } - } - if isArray { - d.arrayElem(j == 0) - } else if j&1 == 0 { - d.mapElemKey(j == 0) - } else { - d.mapElemValue() - } - if j >= len(v) { - fnv(append(v, false)) - } - v[uint(j)] = d.d.DecodeBool() - } - if j < len(v) { - fnv(v[:uint(j)]) - } else if j == 0 && v == nil { - fnv([]bool{}) - } - if isArray { - d.arrayEnd() - } else { - d.mapEnd() - } - return v, changed -} -func (fastpathDTCborBytes) DecSliceBoolN(v []bool, d *decoderCborBytes) { - ctyp := d.d.ContainerType() - if ctyp == valueTypeNil { - return - } - var containerLenS int - isArray := ctyp == valueTypeArray - if isArray { - containerLenS = d.arrayStart(d.d.ReadArrayStart()) - } else if ctyp == valueTypeMap { - containerLenS = d.mapStart(d.d.ReadMapStart()) * 2 - } else { - halt.errorStr2("decoding into a slice, expect map/array - got ", ctyp.String()) - } - hasLen := containerLenS >= 0 - for j := 0; d.containerNext(j, containerLenS, hasLen); j++ { - if isArray { - d.arrayElem(j == 0) - } else if j&1 == 0 { - d.mapElemKey(j == 0) - } else { - d.mapElemValue() - } - if j < len(v) { - v[uint(j)] = d.d.DecodeBool() - } else { - d.arrayCannotExpand(len(v), j+1) - d.swallow() - } - } - if isArray { - d.arrayEnd() - } else { - d.mapEnd() - } -} -func (d *decoderCborBytes) fastpathDecMapStringIntfR(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTCborBytes - containerLen := d.mapStart(d.d.ReadMapStart()) - if rv.Kind() == reflect.Ptr { - vp, _ := rv2i(rv).(*map[string]interface{}) - if *vp == nil { - *vp = make(map[string]interface{}, decInferLen(containerLen, d.maxInitLen(), 32)) - } - if containerLen != 0 { - ft.DecMapStringIntfL(*vp, containerLen, d) - } - } else if containerLen != 0 { - ft.DecMapStringIntfL(rv2i(rv).(map[string]interface{}), containerLen, d) - } - d.mapEnd() -} -func (fastpathDTCborBytes) DecMapStringIntfL(v map[string]interface{}, containerLen int, d *decoderCborBytes) { - if v == nil { - halt.errorInt("cannot decode into nil map[string]interface{} given stream length: ", int64(containerLen)) - } - var mv interface{} - mapGet := !d.h.MapValueReset && !d.h.InterfaceReset - hasLen := containerLen >= 0 - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - mk := d.detach2Str(d.d.DecodeStringAsBytes()) - d.mapElemValue() - if mapGet { - mv = v[mk] - } else { - mv = nil - } - d.decode(&mv) - v[mk] = mv - } -} -func (d *decoderCborBytes) fastpathDecMapStringStringR(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTCborBytes - containerLen := d.mapStart(d.d.ReadMapStart()) - if rv.Kind() == reflect.Ptr { - vp, _ := rv2i(rv).(*map[string]string) - if *vp == nil { - *vp = make(map[string]string, decInferLen(containerLen, d.maxInitLen(), 32)) - } - if containerLen != 0 { - ft.DecMapStringStringL(*vp, containerLen, d) - } - } else if containerLen != 0 { - ft.DecMapStringStringL(rv2i(rv).(map[string]string), containerLen, d) - } - d.mapEnd() -} -func (fastpathDTCborBytes) DecMapStringStringL(v map[string]string, containerLen int, d *decoderCborBytes) { - if v == nil { - halt.errorInt("cannot decode into nil map[string]string given stream length: ", int64(containerLen)) - } - hasLen := containerLen >= 0 - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - mk := d.detach2Str(d.d.DecodeStringAsBytes()) - d.mapElemValue() - v[mk] = d.detach2Str(d.d.DecodeStringAsBytes()) - } -} -func (d *decoderCborBytes) fastpathDecMapStringBytesR(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTCborBytes - containerLen := d.mapStart(d.d.ReadMapStart()) - if rv.Kind() == reflect.Ptr { - vp, _ := rv2i(rv).(*map[string][]byte) - if *vp == nil { - *vp = make(map[string][]byte, decInferLen(containerLen, d.maxInitLen(), 40)) - } - if containerLen != 0 { - ft.DecMapStringBytesL(*vp, containerLen, d) - } - } else if containerLen != 0 { - ft.DecMapStringBytesL(rv2i(rv).(map[string][]byte), containerLen, d) - } - d.mapEnd() -} -func (fastpathDTCborBytes) DecMapStringBytesL(v map[string][]byte, containerLen int, d *decoderCborBytes) { - if v == nil { - halt.errorInt("cannot decode into nil map[string][]byte given stream length: ", int64(containerLen)) - } - var mv []byte - mapGet := !d.h.MapValueReset - hasLen := containerLen >= 0 - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - mk := d.detach2Str(d.d.DecodeStringAsBytes()) - d.mapElemValue() - if mapGet { - mv = v[mk] - } else { - mv = nil - } - v[mk], _ = d.decodeBytesInto(mv, false) - } -} -func (d *decoderCborBytes) fastpathDecMapStringUint8R(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTCborBytes - containerLen := d.mapStart(d.d.ReadMapStart()) - if rv.Kind() == reflect.Ptr { - vp, _ := rv2i(rv).(*map[string]uint8) - if *vp == nil { - *vp = make(map[string]uint8, decInferLen(containerLen, d.maxInitLen(), 17)) - } - if containerLen != 0 { - ft.DecMapStringUint8L(*vp, containerLen, d) - } - } else if containerLen != 0 { - ft.DecMapStringUint8L(rv2i(rv).(map[string]uint8), containerLen, d) - } - d.mapEnd() -} -func (fastpathDTCborBytes) DecMapStringUint8L(v map[string]uint8, containerLen int, d *decoderCborBytes) { - if v == nil { - halt.errorInt("cannot decode into nil map[string]uint8 given stream length: ", int64(containerLen)) - } - hasLen := containerLen >= 0 - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - mk := d.detach2Str(d.d.DecodeStringAsBytes()) - d.mapElemValue() - v[mk] = uint8(chkOvf.UintV(d.d.DecodeUint64(), 8)) - } -} -func (d *decoderCborBytes) fastpathDecMapStringUint64R(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTCborBytes - containerLen := d.mapStart(d.d.ReadMapStart()) - if rv.Kind() == reflect.Ptr { - vp, _ := rv2i(rv).(*map[string]uint64) - if *vp == nil { - *vp = make(map[string]uint64, decInferLen(containerLen, d.maxInitLen(), 24)) - } - if containerLen != 0 { - ft.DecMapStringUint64L(*vp, containerLen, d) - } - } else if containerLen != 0 { - ft.DecMapStringUint64L(rv2i(rv).(map[string]uint64), containerLen, d) - } - d.mapEnd() -} -func (fastpathDTCborBytes) DecMapStringUint64L(v map[string]uint64, containerLen int, d *decoderCborBytes) { - if v == nil { - halt.errorInt("cannot decode into nil map[string]uint64 given stream length: ", int64(containerLen)) - } - hasLen := containerLen >= 0 - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - mk := d.detach2Str(d.d.DecodeStringAsBytes()) - d.mapElemValue() - v[mk] = d.d.DecodeUint64() - } -} -func (d *decoderCborBytes) fastpathDecMapStringIntR(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTCborBytes - containerLen := d.mapStart(d.d.ReadMapStart()) - if rv.Kind() == reflect.Ptr { - vp, _ := rv2i(rv).(*map[string]int) - if *vp == nil { - *vp = make(map[string]int, decInferLen(containerLen, d.maxInitLen(), 24)) - } - if containerLen != 0 { - ft.DecMapStringIntL(*vp, containerLen, d) - } - } else if containerLen != 0 { - ft.DecMapStringIntL(rv2i(rv).(map[string]int), containerLen, d) - } - d.mapEnd() -} -func (fastpathDTCborBytes) DecMapStringIntL(v map[string]int, containerLen int, d *decoderCborBytes) { - if v == nil { - halt.errorInt("cannot decode into nil map[string]int given stream length: ", int64(containerLen)) - } - hasLen := containerLen >= 0 - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - mk := d.detach2Str(d.d.DecodeStringAsBytes()) - d.mapElemValue() - v[mk] = int(chkOvf.IntV(d.d.DecodeInt64(), intBitsize)) - } -} -func (d *decoderCborBytes) fastpathDecMapStringInt32R(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTCborBytes - containerLen := d.mapStart(d.d.ReadMapStart()) - if rv.Kind() == reflect.Ptr { - vp, _ := rv2i(rv).(*map[string]int32) - if *vp == nil { - *vp = make(map[string]int32, decInferLen(containerLen, d.maxInitLen(), 20)) - } - if containerLen != 0 { - ft.DecMapStringInt32L(*vp, containerLen, d) - } - } else if containerLen != 0 { - ft.DecMapStringInt32L(rv2i(rv).(map[string]int32), containerLen, d) - } - d.mapEnd() -} -func (fastpathDTCborBytes) DecMapStringInt32L(v map[string]int32, containerLen int, d *decoderCborBytes) { - if v == nil { - halt.errorInt("cannot decode into nil map[string]int32 given stream length: ", int64(containerLen)) - } - hasLen := containerLen >= 0 - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - mk := d.detach2Str(d.d.DecodeStringAsBytes()) - d.mapElemValue() - v[mk] = int32(chkOvf.IntV(d.d.DecodeInt64(), 32)) - } -} -func (d *decoderCborBytes) fastpathDecMapStringFloat64R(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTCborBytes - containerLen := d.mapStart(d.d.ReadMapStart()) - if rv.Kind() == reflect.Ptr { - vp, _ := rv2i(rv).(*map[string]float64) - if *vp == nil { - *vp = make(map[string]float64, decInferLen(containerLen, d.maxInitLen(), 24)) - } - if containerLen != 0 { - ft.DecMapStringFloat64L(*vp, containerLen, d) - } - } else if containerLen != 0 { - ft.DecMapStringFloat64L(rv2i(rv).(map[string]float64), containerLen, d) - } - d.mapEnd() -} -func (fastpathDTCborBytes) DecMapStringFloat64L(v map[string]float64, containerLen int, d *decoderCborBytes) { - if v == nil { - halt.errorInt("cannot decode into nil map[string]float64 given stream length: ", int64(containerLen)) - } - hasLen := containerLen >= 0 - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - mk := d.detach2Str(d.d.DecodeStringAsBytes()) - d.mapElemValue() - v[mk] = d.d.DecodeFloat64() - } -} -func (d *decoderCborBytes) fastpathDecMapStringBoolR(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTCborBytes - containerLen := d.mapStart(d.d.ReadMapStart()) - if rv.Kind() == reflect.Ptr { - vp, _ := rv2i(rv).(*map[string]bool) - if *vp == nil { - *vp = make(map[string]bool, decInferLen(containerLen, d.maxInitLen(), 17)) - } - if containerLen != 0 { - ft.DecMapStringBoolL(*vp, containerLen, d) - } - } else if containerLen != 0 { - ft.DecMapStringBoolL(rv2i(rv).(map[string]bool), containerLen, d) - } - d.mapEnd() -} -func (fastpathDTCborBytes) DecMapStringBoolL(v map[string]bool, containerLen int, d *decoderCborBytes) { - if v == nil { - halt.errorInt("cannot decode into nil map[string]bool given stream length: ", int64(containerLen)) - } - hasLen := containerLen >= 0 - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - mk := d.detach2Str(d.d.DecodeStringAsBytes()) - d.mapElemValue() - v[mk] = d.d.DecodeBool() - } -} -func (d *decoderCborBytes) fastpathDecMapUint8IntfR(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTCborBytes - containerLen := d.mapStart(d.d.ReadMapStart()) - if rv.Kind() == reflect.Ptr { - vp, _ := rv2i(rv).(*map[uint8]interface{}) - if *vp == nil { - *vp = make(map[uint8]interface{}, decInferLen(containerLen, d.maxInitLen(), 17)) - } - if containerLen != 0 { - ft.DecMapUint8IntfL(*vp, containerLen, d) - } - } else if containerLen != 0 { - ft.DecMapUint8IntfL(rv2i(rv).(map[uint8]interface{}), containerLen, d) - } - d.mapEnd() -} -func (fastpathDTCborBytes) DecMapUint8IntfL(v map[uint8]interface{}, containerLen int, d *decoderCborBytes) { - if v == nil { - halt.errorInt("cannot decode into nil map[uint8]interface{} given stream length: ", int64(containerLen)) - } - var mv interface{} - mapGet := !d.h.MapValueReset && !d.h.InterfaceReset - hasLen := containerLen >= 0 - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - mk := uint8(chkOvf.UintV(d.d.DecodeUint64(), 8)) - d.mapElemValue() - if mapGet { - mv = v[mk] - } else { - mv = nil - } - d.decode(&mv) - v[mk] = mv - } -} -func (d *decoderCborBytes) fastpathDecMapUint8StringR(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTCborBytes - containerLen := d.mapStart(d.d.ReadMapStart()) - if rv.Kind() == reflect.Ptr { - vp, _ := rv2i(rv).(*map[uint8]string) - if *vp == nil { - *vp = make(map[uint8]string, decInferLen(containerLen, d.maxInitLen(), 17)) - } - if containerLen != 0 { - ft.DecMapUint8StringL(*vp, containerLen, d) - } - } else if containerLen != 0 { - ft.DecMapUint8StringL(rv2i(rv).(map[uint8]string), containerLen, d) - } - d.mapEnd() -} -func (fastpathDTCborBytes) DecMapUint8StringL(v map[uint8]string, containerLen int, d *decoderCborBytes) { - if v == nil { - halt.errorInt("cannot decode into nil map[uint8]string given stream length: ", int64(containerLen)) - } - hasLen := containerLen >= 0 - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - mk := uint8(chkOvf.UintV(d.d.DecodeUint64(), 8)) - d.mapElemValue() - v[mk] = d.detach2Str(d.d.DecodeStringAsBytes()) - } -} -func (d *decoderCborBytes) fastpathDecMapUint8BytesR(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTCborBytes - containerLen := d.mapStart(d.d.ReadMapStart()) - if rv.Kind() == reflect.Ptr { - vp, _ := rv2i(rv).(*map[uint8][]byte) - if *vp == nil { - *vp = make(map[uint8][]byte, decInferLen(containerLen, d.maxInitLen(), 25)) - } - if containerLen != 0 { - ft.DecMapUint8BytesL(*vp, containerLen, d) - } - } else if containerLen != 0 { - ft.DecMapUint8BytesL(rv2i(rv).(map[uint8][]byte), containerLen, d) - } - d.mapEnd() -} -func (fastpathDTCborBytes) DecMapUint8BytesL(v map[uint8][]byte, containerLen int, d *decoderCborBytes) { - if v == nil { - halt.errorInt("cannot decode into nil map[uint8][]byte given stream length: ", int64(containerLen)) - } - var mv []byte - mapGet := !d.h.MapValueReset - hasLen := containerLen >= 0 - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - mk := uint8(chkOvf.UintV(d.d.DecodeUint64(), 8)) - d.mapElemValue() - if mapGet { - mv = v[mk] - } else { - mv = nil - } - v[mk], _ = d.decodeBytesInto(mv, false) - } -} -func (d *decoderCborBytes) fastpathDecMapUint8Uint8R(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTCborBytes - containerLen := d.mapStart(d.d.ReadMapStart()) - if rv.Kind() == reflect.Ptr { - vp, _ := rv2i(rv).(*map[uint8]uint8) - if *vp == nil { - *vp = make(map[uint8]uint8, decInferLen(containerLen, d.maxInitLen(), 2)) - } - if containerLen != 0 { - ft.DecMapUint8Uint8L(*vp, containerLen, d) - } - } else if containerLen != 0 { - ft.DecMapUint8Uint8L(rv2i(rv).(map[uint8]uint8), containerLen, d) - } - d.mapEnd() -} -func (fastpathDTCborBytes) DecMapUint8Uint8L(v map[uint8]uint8, containerLen int, d *decoderCborBytes) { - if v == nil { - halt.errorInt("cannot decode into nil map[uint8]uint8 given stream length: ", int64(containerLen)) - } - hasLen := containerLen >= 0 - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - mk := uint8(chkOvf.UintV(d.d.DecodeUint64(), 8)) - d.mapElemValue() - v[mk] = uint8(chkOvf.UintV(d.d.DecodeUint64(), 8)) - } -} -func (d *decoderCborBytes) fastpathDecMapUint8Uint64R(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTCborBytes - containerLen := d.mapStart(d.d.ReadMapStart()) - if rv.Kind() == reflect.Ptr { - vp, _ := rv2i(rv).(*map[uint8]uint64) - if *vp == nil { - *vp = make(map[uint8]uint64, decInferLen(containerLen, d.maxInitLen(), 9)) - } - if containerLen != 0 { - ft.DecMapUint8Uint64L(*vp, containerLen, d) - } - } else if containerLen != 0 { - ft.DecMapUint8Uint64L(rv2i(rv).(map[uint8]uint64), containerLen, d) - } - d.mapEnd() -} -func (fastpathDTCborBytes) DecMapUint8Uint64L(v map[uint8]uint64, containerLen int, d *decoderCborBytes) { - if v == nil { - halt.errorInt("cannot decode into nil map[uint8]uint64 given stream length: ", int64(containerLen)) - } - hasLen := containerLen >= 0 - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - mk := uint8(chkOvf.UintV(d.d.DecodeUint64(), 8)) - d.mapElemValue() - v[mk] = d.d.DecodeUint64() - } -} -func (d *decoderCborBytes) fastpathDecMapUint8IntR(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTCborBytes - containerLen := d.mapStart(d.d.ReadMapStart()) - if rv.Kind() == reflect.Ptr { - vp, _ := rv2i(rv).(*map[uint8]int) - if *vp == nil { - *vp = make(map[uint8]int, decInferLen(containerLen, d.maxInitLen(), 9)) - } - if containerLen != 0 { - ft.DecMapUint8IntL(*vp, containerLen, d) - } - } else if containerLen != 0 { - ft.DecMapUint8IntL(rv2i(rv).(map[uint8]int), containerLen, d) - } - d.mapEnd() -} -func (fastpathDTCborBytes) DecMapUint8IntL(v map[uint8]int, containerLen int, d *decoderCborBytes) { - if v == nil { - halt.errorInt("cannot decode into nil map[uint8]int given stream length: ", int64(containerLen)) - } - hasLen := containerLen >= 0 - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - mk := uint8(chkOvf.UintV(d.d.DecodeUint64(), 8)) - d.mapElemValue() - v[mk] = int(chkOvf.IntV(d.d.DecodeInt64(), intBitsize)) - } -} -func (d *decoderCborBytes) fastpathDecMapUint8Int32R(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTCborBytes - containerLen := d.mapStart(d.d.ReadMapStart()) - if rv.Kind() == reflect.Ptr { - vp, _ := rv2i(rv).(*map[uint8]int32) - if *vp == nil { - *vp = make(map[uint8]int32, decInferLen(containerLen, d.maxInitLen(), 5)) - } - if containerLen != 0 { - ft.DecMapUint8Int32L(*vp, containerLen, d) - } - } else if containerLen != 0 { - ft.DecMapUint8Int32L(rv2i(rv).(map[uint8]int32), containerLen, d) - } - d.mapEnd() -} -func (fastpathDTCborBytes) DecMapUint8Int32L(v map[uint8]int32, containerLen int, d *decoderCborBytes) { - if v == nil { - halt.errorInt("cannot decode into nil map[uint8]int32 given stream length: ", int64(containerLen)) - } - hasLen := containerLen >= 0 - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - mk := uint8(chkOvf.UintV(d.d.DecodeUint64(), 8)) - d.mapElemValue() - v[mk] = int32(chkOvf.IntV(d.d.DecodeInt64(), 32)) - } -} -func (d *decoderCborBytes) fastpathDecMapUint8Float64R(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTCborBytes - containerLen := d.mapStart(d.d.ReadMapStart()) - if rv.Kind() == reflect.Ptr { - vp, _ := rv2i(rv).(*map[uint8]float64) - if *vp == nil { - *vp = make(map[uint8]float64, decInferLen(containerLen, d.maxInitLen(), 9)) - } - if containerLen != 0 { - ft.DecMapUint8Float64L(*vp, containerLen, d) - } - } else if containerLen != 0 { - ft.DecMapUint8Float64L(rv2i(rv).(map[uint8]float64), containerLen, d) - } - d.mapEnd() -} -func (fastpathDTCborBytes) DecMapUint8Float64L(v map[uint8]float64, containerLen int, d *decoderCborBytes) { - if v == nil { - halt.errorInt("cannot decode into nil map[uint8]float64 given stream length: ", int64(containerLen)) - } - hasLen := containerLen >= 0 - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - mk := uint8(chkOvf.UintV(d.d.DecodeUint64(), 8)) - d.mapElemValue() - v[mk] = d.d.DecodeFloat64() - } -} -func (d *decoderCborBytes) fastpathDecMapUint8BoolR(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTCborBytes - containerLen := d.mapStart(d.d.ReadMapStart()) - if rv.Kind() == reflect.Ptr { - vp, _ := rv2i(rv).(*map[uint8]bool) - if *vp == nil { - *vp = make(map[uint8]bool, decInferLen(containerLen, d.maxInitLen(), 2)) - } - if containerLen != 0 { - ft.DecMapUint8BoolL(*vp, containerLen, d) - } - } else if containerLen != 0 { - ft.DecMapUint8BoolL(rv2i(rv).(map[uint8]bool), containerLen, d) - } - d.mapEnd() -} -func (fastpathDTCborBytes) DecMapUint8BoolL(v map[uint8]bool, containerLen int, d *decoderCborBytes) { - if v == nil { - halt.errorInt("cannot decode into nil map[uint8]bool given stream length: ", int64(containerLen)) - } - hasLen := containerLen >= 0 - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - mk := uint8(chkOvf.UintV(d.d.DecodeUint64(), 8)) - d.mapElemValue() - v[mk] = d.d.DecodeBool() - } -} -func (d *decoderCborBytes) fastpathDecMapUint64IntfR(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTCborBytes - containerLen := d.mapStart(d.d.ReadMapStart()) - if rv.Kind() == reflect.Ptr { - vp, _ := rv2i(rv).(*map[uint64]interface{}) - if *vp == nil { - *vp = make(map[uint64]interface{}, decInferLen(containerLen, d.maxInitLen(), 24)) - } - if containerLen != 0 { - ft.DecMapUint64IntfL(*vp, containerLen, d) - } - } else if containerLen != 0 { - ft.DecMapUint64IntfL(rv2i(rv).(map[uint64]interface{}), containerLen, d) - } - d.mapEnd() -} -func (fastpathDTCborBytes) DecMapUint64IntfL(v map[uint64]interface{}, containerLen int, d *decoderCborBytes) { - if v == nil { - halt.errorInt("cannot decode into nil map[uint64]interface{} given stream length: ", int64(containerLen)) - } - var mv interface{} - mapGet := !d.h.MapValueReset && !d.h.InterfaceReset - hasLen := containerLen >= 0 - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - mk := d.d.DecodeUint64() - d.mapElemValue() - if mapGet { - mv = v[mk] - } else { - mv = nil - } - d.decode(&mv) - v[mk] = mv - } -} -func (d *decoderCborBytes) fastpathDecMapUint64StringR(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTCborBytes - containerLen := d.mapStart(d.d.ReadMapStart()) - if rv.Kind() == reflect.Ptr { - vp, _ := rv2i(rv).(*map[uint64]string) - if *vp == nil { - *vp = make(map[uint64]string, decInferLen(containerLen, d.maxInitLen(), 24)) - } - if containerLen != 0 { - ft.DecMapUint64StringL(*vp, containerLen, d) - } - } else if containerLen != 0 { - ft.DecMapUint64StringL(rv2i(rv).(map[uint64]string), containerLen, d) - } - d.mapEnd() -} -func (fastpathDTCborBytes) DecMapUint64StringL(v map[uint64]string, containerLen int, d *decoderCborBytes) { - if v == nil { - halt.errorInt("cannot decode into nil map[uint64]string given stream length: ", int64(containerLen)) - } - hasLen := containerLen >= 0 - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - mk := d.d.DecodeUint64() - d.mapElemValue() - v[mk] = d.detach2Str(d.d.DecodeStringAsBytes()) - } -} -func (d *decoderCborBytes) fastpathDecMapUint64BytesR(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTCborBytes - containerLen := d.mapStart(d.d.ReadMapStart()) - if rv.Kind() == reflect.Ptr { - vp, _ := rv2i(rv).(*map[uint64][]byte) - if *vp == nil { - *vp = make(map[uint64][]byte, decInferLen(containerLen, d.maxInitLen(), 32)) - } - if containerLen != 0 { - ft.DecMapUint64BytesL(*vp, containerLen, d) - } - } else if containerLen != 0 { - ft.DecMapUint64BytesL(rv2i(rv).(map[uint64][]byte), containerLen, d) - } - d.mapEnd() -} -func (fastpathDTCborBytes) DecMapUint64BytesL(v map[uint64][]byte, containerLen int, d *decoderCborBytes) { - if v == nil { - halt.errorInt("cannot decode into nil map[uint64][]byte given stream length: ", int64(containerLen)) - } - var mv []byte - mapGet := !d.h.MapValueReset - hasLen := containerLen >= 0 - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - mk := d.d.DecodeUint64() - d.mapElemValue() - if mapGet { - mv = v[mk] - } else { - mv = nil - } - v[mk], _ = d.decodeBytesInto(mv, false) - } -} -func (d *decoderCborBytes) fastpathDecMapUint64Uint8R(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTCborBytes - containerLen := d.mapStart(d.d.ReadMapStart()) - if rv.Kind() == reflect.Ptr { - vp, _ := rv2i(rv).(*map[uint64]uint8) - if *vp == nil { - *vp = make(map[uint64]uint8, decInferLen(containerLen, d.maxInitLen(), 9)) - } - if containerLen != 0 { - ft.DecMapUint64Uint8L(*vp, containerLen, d) - } - } else if containerLen != 0 { - ft.DecMapUint64Uint8L(rv2i(rv).(map[uint64]uint8), containerLen, d) - } - d.mapEnd() -} -func (fastpathDTCborBytes) DecMapUint64Uint8L(v map[uint64]uint8, containerLen int, d *decoderCborBytes) { - if v == nil { - halt.errorInt("cannot decode into nil map[uint64]uint8 given stream length: ", int64(containerLen)) - } - hasLen := containerLen >= 0 - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - mk := d.d.DecodeUint64() - d.mapElemValue() - v[mk] = uint8(chkOvf.UintV(d.d.DecodeUint64(), 8)) - } -} -func (d *decoderCborBytes) fastpathDecMapUint64Uint64R(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTCborBytes - containerLen := d.mapStart(d.d.ReadMapStart()) - if rv.Kind() == reflect.Ptr { - vp, _ := rv2i(rv).(*map[uint64]uint64) - if *vp == nil { - *vp = make(map[uint64]uint64, decInferLen(containerLen, d.maxInitLen(), 16)) - } - if containerLen != 0 { - ft.DecMapUint64Uint64L(*vp, containerLen, d) - } - } else if containerLen != 0 { - ft.DecMapUint64Uint64L(rv2i(rv).(map[uint64]uint64), containerLen, d) - } - d.mapEnd() -} -func (fastpathDTCborBytes) DecMapUint64Uint64L(v map[uint64]uint64, containerLen int, d *decoderCborBytes) { - if v == nil { - halt.errorInt("cannot decode into nil map[uint64]uint64 given stream length: ", int64(containerLen)) - } - hasLen := containerLen >= 0 - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - mk := d.d.DecodeUint64() - d.mapElemValue() - v[mk] = d.d.DecodeUint64() - } -} -func (d *decoderCborBytes) fastpathDecMapUint64IntR(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTCborBytes - containerLen := d.mapStart(d.d.ReadMapStart()) - if rv.Kind() == reflect.Ptr { - vp, _ := rv2i(rv).(*map[uint64]int) - if *vp == nil { - *vp = make(map[uint64]int, decInferLen(containerLen, d.maxInitLen(), 16)) - } - if containerLen != 0 { - ft.DecMapUint64IntL(*vp, containerLen, d) - } - } else if containerLen != 0 { - ft.DecMapUint64IntL(rv2i(rv).(map[uint64]int), containerLen, d) - } - d.mapEnd() -} -func (fastpathDTCborBytes) DecMapUint64IntL(v map[uint64]int, containerLen int, d *decoderCborBytes) { - if v == nil { - halt.errorInt("cannot decode into nil map[uint64]int given stream length: ", int64(containerLen)) - } - hasLen := containerLen >= 0 - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - mk := d.d.DecodeUint64() - d.mapElemValue() - v[mk] = int(chkOvf.IntV(d.d.DecodeInt64(), intBitsize)) - } -} -func (d *decoderCborBytes) fastpathDecMapUint64Int32R(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTCborBytes - containerLen := d.mapStart(d.d.ReadMapStart()) - if rv.Kind() == reflect.Ptr { - vp, _ := rv2i(rv).(*map[uint64]int32) - if *vp == nil { - *vp = make(map[uint64]int32, decInferLen(containerLen, d.maxInitLen(), 12)) - } - if containerLen != 0 { - ft.DecMapUint64Int32L(*vp, containerLen, d) - } - } else if containerLen != 0 { - ft.DecMapUint64Int32L(rv2i(rv).(map[uint64]int32), containerLen, d) - } - d.mapEnd() -} -func (fastpathDTCborBytes) DecMapUint64Int32L(v map[uint64]int32, containerLen int, d *decoderCborBytes) { - if v == nil { - halt.errorInt("cannot decode into nil map[uint64]int32 given stream length: ", int64(containerLen)) - } - hasLen := containerLen >= 0 - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - mk := d.d.DecodeUint64() - d.mapElemValue() - v[mk] = int32(chkOvf.IntV(d.d.DecodeInt64(), 32)) - } -} -func (d *decoderCborBytes) fastpathDecMapUint64Float64R(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTCborBytes - containerLen := d.mapStart(d.d.ReadMapStart()) - if rv.Kind() == reflect.Ptr { - vp, _ := rv2i(rv).(*map[uint64]float64) - if *vp == nil { - *vp = make(map[uint64]float64, decInferLen(containerLen, d.maxInitLen(), 16)) - } - if containerLen != 0 { - ft.DecMapUint64Float64L(*vp, containerLen, d) - } - } else if containerLen != 0 { - ft.DecMapUint64Float64L(rv2i(rv).(map[uint64]float64), containerLen, d) - } - d.mapEnd() -} -func (fastpathDTCborBytes) DecMapUint64Float64L(v map[uint64]float64, containerLen int, d *decoderCborBytes) { - if v == nil { - halt.errorInt("cannot decode into nil map[uint64]float64 given stream length: ", int64(containerLen)) - } - hasLen := containerLen >= 0 - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - mk := d.d.DecodeUint64() - d.mapElemValue() - v[mk] = d.d.DecodeFloat64() - } -} -func (d *decoderCborBytes) fastpathDecMapUint64BoolR(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTCborBytes - containerLen := d.mapStart(d.d.ReadMapStart()) - if rv.Kind() == reflect.Ptr { - vp, _ := rv2i(rv).(*map[uint64]bool) - if *vp == nil { - *vp = make(map[uint64]bool, decInferLen(containerLen, d.maxInitLen(), 9)) - } - if containerLen != 0 { - ft.DecMapUint64BoolL(*vp, containerLen, d) - } - } else if containerLen != 0 { - ft.DecMapUint64BoolL(rv2i(rv).(map[uint64]bool), containerLen, d) - } - d.mapEnd() -} -func (fastpathDTCborBytes) DecMapUint64BoolL(v map[uint64]bool, containerLen int, d *decoderCborBytes) { - if v == nil { - halt.errorInt("cannot decode into nil map[uint64]bool given stream length: ", int64(containerLen)) - } - hasLen := containerLen >= 0 - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - mk := d.d.DecodeUint64() - d.mapElemValue() - v[mk] = d.d.DecodeBool() - } -} -func (d *decoderCborBytes) fastpathDecMapIntIntfR(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTCborBytes - containerLen := d.mapStart(d.d.ReadMapStart()) - if rv.Kind() == reflect.Ptr { - vp, _ := rv2i(rv).(*map[int]interface{}) - if *vp == nil { - *vp = make(map[int]interface{}, decInferLen(containerLen, d.maxInitLen(), 24)) - } - if containerLen != 0 { - ft.DecMapIntIntfL(*vp, containerLen, d) - } - } else if containerLen != 0 { - ft.DecMapIntIntfL(rv2i(rv).(map[int]interface{}), containerLen, d) - } - d.mapEnd() -} -func (fastpathDTCborBytes) DecMapIntIntfL(v map[int]interface{}, containerLen int, d *decoderCborBytes) { - if v == nil { - halt.errorInt("cannot decode into nil map[int]interface{} given stream length: ", int64(containerLen)) - } - var mv interface{} - mapGet := !d.h.MapValueReset && !d.h.InterfaceReset - hasLen := containerLen >= 0 - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - mk := int(chkOvf.IntV(d.d.DecodeInt64(), intBitsize)) - d.mapElemValue() - if mapGet { - mv = v[mk] - } else { - mv = nil - } - d.decode(&mv) - v[mk] = mv - } -} -func (d *decoderCborBytes) fastpathDecMapIntStringR(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTCborBytes - containerLen := d.mapStart(d.d.ReadMapStart()) - if rv.Kind() == reflect.Ptr { - vp, _ := rv2i(rv).(*map[int]string) - if *vp == nil { - *vp = make(map[int]string, decInferLen(containerLen, d.maxInitLen(), 24)) - } - if containerLen != 0 { - ft.DecMapIntStringL(*vp, containerLen, d) - } - } else if containerLen != 0 { - ft.DecMapIntStringL(rv2i(rv).(map[int]string), containerLen, d) - } - d.mapEnd() -} -func (fastpathDTCborBytes) DecMapIntStringL(v map[int]string, containerLen int, d *decoderCborBytes) { - if v == nil { - halt.errorInt("cannot decode into nil map[int]string given stream length: ", int64(containerLen)) - } - hasLen := containerLen >= 0 - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - mk := int(chkOvf.IntV(d.d.DecodeInt64(), intBitsize)) - d.mapElemValue() - v[mk] = d.detach2Str(d.d.DecodeStringAsBytes()) - } -} -func (d *decoderCborBytes) fastpathDecMapIntBytesR(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTCborBytes - containerLen := d.mapStart(d.d.ReadMapStart()) - if rv.Kind() == reflect.Ptr { - vp, _ := rv2i(rv).(*map[int][]byte) - if *vp == nil { - *vp = make(map[int][]byte, decInferLen(containerLen, d.maxInitLen(), 32)) - } - if containerLen != 0 { - ft.DecMapIntBytesL(*vp, containerLen, d) - } - } else if containerLen != 0 { - ft.DecMapIntBytesL(rv2i(rv).(map[int][]byte), containerLen, d) - } - d.mapEnd() -} -func (fastpathDTCborBytes) DecMapIntBytesL(v map[int][]byte, containerLen int, d *decoderCborBytes) { - if v == nil { - halt.errorInt("cannot decode into nil map[int][]byte given stream length: ", int64(containerLen)) - } - var mv []byte - mapGet := !d.h.MapValueReset - hasLen := containerLen >= 0 - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - mk := int(chkOvf.IntV(d.d.DecodeInt64(), intBitsize)) - d.mapElemValue() - if mapGet { - mv = v[mk] - } else { - mv = nil - } - v[mk], _ = d.decodeBytesInto(mv, false) - } -} -func (d *decoderCborBytes) fastpathDecMapIntUint8R(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTCborBytes - containerLen := d.mapStart(d.d.ReadMapStart()) - if rv.Kind() == reflect.Ptr { - vp, _ := rv2i(rv).(*map[int]uint8) - if *vp == nil { - *vp = make(map[int]uint8, decInferLen(containerLen, d.maxInitLen(), 9)) - } - if containerLen != 0 { - ft.DecMapIntUint8L(*vp, containerLen, d) - } - } else if containerLen != 0 { - ft.DecMapIntUint8L(rv2i(rv).(map[int]uint8), containerLen, d) - } - d.mapEnd() -} -func (fastpathDTCborBytes) DecMapIntUint8L(v map[int]uint8, containerLen int, d *decoderCborBytes) { - if v == nil { - halt.errorInt("cannot decode into nil map[int]uint8 given stream length: ", int64(containerLen)) - } - hasLen := containerLen >= 0 - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - mk := int(chkOvf.IntV(d.d.DecodeInt64(), intBitsize)) - d.mapElemValue() - v[mk] = uint8(chkOvf.UintV(d.d.DecodeUint64(), 8)) - } -} -func (d *decoderCborBytes) fastpathDecMapIntUint64R(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTCborBytes - containerLen := d.mapStart(d.d.ReadMapStart()) - if rv.Kind() == reflect.Ptr { - vp, _ := rv2i(rv).(*map[int]uint64) - if *vp == nil { - *vp = make(map[int]uint64, decInferLen(containerLen, d.maxInitLen(), 16)) - } - if containerLen != 0 { - ft.DecMapIntUint64L(*vp, containerLen, d) - } - } else if containerLen != 0 { - ft.DecMapIntUint64L(rv2i(rv).(map[int]uint64), containerLen, d) - } - d.mapEnd() -} -func (fastpathDTCborBytes) DecMapIntUint64L(v map[int]uint64, containerLen int, d *decoderCborBytes) { - if v == nil { - halt.errorInt("cannot decode into nil map[int]uint64 given stream length: ", int64(containerLen)) - } - hasLen := containerLen >= 0 - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - mk := int(chkOvf.IntV(d.d.DecodeInt64(), intBitsize)) - d.mapElemValue() - v[mk] = d.d.DecodeUint64() - } -} -func (d *decoderCborBytes) fastpathDecMapIntIntR(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTCborBytes - containerLen := d.mapStart(d.d.ReadMapStart()) - if rv.Kind() == reflect.Ptr { - vp, _ := rv2i(rv).(*map[int]int) - if *vp == nil { - *vp = make(map[int]int, decInferLen(containerLen, d.maxInitLen(), 16)) - } - if containerLen != 0 { - ft.DecMapIntIntL(*vp, containerLen, d) - } - } else if containerLen != 0 { - ft.DecMapIntIntL(rv2i(rv).(map[int]int), containerLen, d) - } - d.mapEnd() -} -func (fastpathDTCborBytes) DecMapIntIntL(v map[int]int, containerLen int, d *decoderCborBytes) { - if v == nil { - halt.errorInt("cannot decode into nil map[int]int given stream length: ", int64(containerLen)) - } - hasLen := containerLen >= 0 - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - mk := int(chkOvf.IntV(d.d.DecodeInt64(), intBitsize)) - d.mapElemValue() - v[mk] = int(chkOvf.IntV(d.d.DecodeInt64(), intBitsize)) - } -} -func (d *decoderCborBytes) fastpathDecMapIntInt32R(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTCborBytes - containerLen := d.mapStart(d.d.ReadMapStart()) - if rv.Kind() == reflect.Ptr { - vp, _ := rv2i(rv).(*map[int]int32) - if *vp == nil { - *vp = make(map[int]int32, decInferLen(containerLen, d.maxInitLen(), 12)) - } - if containerLen != 0 { - ft.DecMapIntInt32L(*vp, containerLen, d) - } - } else if containerLen != 0 { - ft.DecMapIntInt32L(rv2i(rv).(map[int]int32), containerLen, d) - } - d.mapEnd() -} -func (fastpathDTCborBytes) DecMapIntInt32L(v map[int]int32, containerLen int, d *decoderCborBytes) { - if v == nil { - halt.errorInt("cannot decode into nil map[int]int32 given stream length: ", int64(containerLen)) - } - hasLen := containerLen >= 0 - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - mk := int(chkOvf.IntV(d.d.DecodeInt64(), intBitsize)) - d.mapElemValue() - v[mk] = int32(chkOvf.IntV(d.d.DecodeInt64(), 32)) - } -} -func (d *decoderCborBytes) fastpathDecMapIntFloat64R(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTCborBytes - containerLen := d.mapStart(d.d.ReadMapStart()) - if rv.Kind() == reflect.Ptr { - vp, _ := rv2i(rv).(*map[int]float64) - if *vp == nil { - *vp = make(map[int]float64, decInferLen(containerLen, d.maxInitLen(), 16)) - } - if containerLen != 0 { - ft.DecMapIntFloat64L(*vp, containerLen, d) - } - } else if containerLen != 0 { - ft.DecMapIntFloat64L(rv2i(rv).(map[int]float64), containerLen, d) - } - d.mapEnd() -} -func (fastpathDTCborBytes) DecMapIntFloat64L(v map[int]float64, containerLen int, d *decoderCborBytes) { - if v == nil { - halt.errorInt("cannot decode into nil map[int]float64 given stream length: ", int64(containerLen)) - } - hasLen := containerLen >= 0 - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - mk := int(chkOvf.IntV(d.d.DecodeInt64(), intBitsize)) - d.mapElemValue() - v[mk] = d.d.DecodeFloat64() - } -} -func (d *decoderCborBytes) fastpathDecMapIntBoolR(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTCborBytes - containerLen := d.mapStart(d.d.ReadMapStart()) - if rv.Kind() == reflect.Ptr { - vp, _ := rv2i(rv).(*map[int]bool) - if *vp == nil { - *vp = make(map[int]bool, decInferLen(containerLen, d.maxInitLen(), 9)) - } - if containerLen != 0 { - ft.DecMapIntBoolL(*vp, containerLen, d) - } - } else if containerLen != 0 { - ft.DecMapIntBoolL(rv2i(rv).(map[int]bool), containerLen, d) - } - d.mapEnd() -} -func (fastpathDTCborBytes) DecMapIntBoolL(v map[int]bool, containerLen int, d *decoderCborBytes) { - if v == nil { - halt.errorInt("cannot decode into nil map[int]bool given stream length: ", int64(containerLen)) - } - hasLen := containerLen >= 0 - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - mk := int(chkOvf.IntV(d.d.DecodeInt64(), intBitsize)) - d.mapElemValue() - v[mk] = d.d.DecodeBool() - } -} -func (d *decoderCborBytes) fastpathDecMapInt32IntfR(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTCborBytes - containerLen := d.mapStart(d.d.ReadMapStart()) - if rv.Kind() == reflect.Ptr { - vp, _ := rv2i(rv).(*map[int32]interface{}) - if *vp == nil { - *vp = make(map[int32]interface{}, decInferLen(containerLen, d.maxInitLen(), 20)) - } - if containerLen != 0 { - ft.DecMapInt32IntfL(*vp, containerLen, d) - } - } else if containerLen != 0 { - ft.DecMapInt32IntfL(rv2i(rv).(map[int32]interface{}), containerLen, d) - } - d.mapEnd() -} -func (fastpathDTCborBytes) DecMapInt32IntfL(v map[int32]interface{}, containerLen int, d *decoderCborBytes) { - if v == nil { - halt.errorInt("cannot decode into nil map[int32]interface{} given stream length: ", int64(containerLen)) - } - var mv interface{} - mapGet := !d.h.MapValueReset && !d.h.InterfaceReset - hasLen := containerLen >= 0 - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - mk := int32(chkOvf.IntV(d.d.DecodeInt64(), 32)) - d.mapElemValue() - if mapGet { - mv = v[mk] - } else { - mv = nil - } - d.decode(&mv) - v[mk] = mv - } -} -func (d *decoderCborBytes) fastpathDecMapInt32StringR(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTCborBytes - containerLen := d.mapStart(d.d.ReadMapStart()) - if rv.Kind() == reflect.Ptr { - vp, _ := rv2i(rv).(*map[int32]string) - if *vp == nil { - *vp = make(map[int32]string, decInferLen(containerLen, d.maxInitLen(), 20)) - } - if containerLen != 0 { - ft.DecMapInt32StringL(*vp, containerLen, d) - } - } else if containerLen != 0 { - ft.DecMapInt32StringL(rv2i(rv).(map[int32]string), containerLen, d) - } - d.mapEnd() -} -func (fastpathDTCborBytes) DecMapInt32StringL(v map[int32]string, containerLen int, d *decoderCborBytes) { - if v == nil { - halt.errorInt("cannot decode into nil map[int32]string given stream length: ", int64(containerLen)) - } - hasLen := containerLen >= 0 - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - mk := int32(chkOvf.IntV(d.d.DecodeInt64(), 32)) - d.mapElemValue() - v[mk] = d.detach2Str(d.d.DecodeStringAsBytes()) - } -} -func (d *decoderCborBytes) fastpathDecMapInt32BytesR(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTCborBytes - containerLen := d.mapStart(d.d.ReadMapStart()) - if rv.Kind() == reflect.Ptr { - vp, _ := rv2i(rv).(*map[int32][]byte) - if *vp == nil { - *vp = make(map[int32][]byte, decInferLen(containerLen, d.maxInitLen(), 28)) - } - if containerLen != 0 { - ft.DecMapInt32BytesL(*vp, containerLen, d) - } - } else if containerLen != 0 { - ft.DecMapInt32BytesL(rv2i(rv).(map[int32][]byte), containerLen, d) - } - d.mapEnd() -} -func (fastpathDTCborBytes) DecMapInt32BytesL(v map[int32][]byte, containerLen int, d *decoderCborBytes) { - if v == nil { - halt.errorInt("cannot decode into nil map[int32][]byte given stream length: ", int64(containerLen)) - } - var mv []byte - mapGet := !d.h.MapValueReset - hasLen := containerLen >= 0 - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - mk := int32(chkOvf.IntV(d.d.DecodeInt64(), 32)) - d.mapElemValue() - if mapGet { - mv = v[mk] - } else { - mv = nil - } - v[mk], _ = d.decodeBytesInto(mv, false) - } -} -func (d *decoderCborBytes) fastpathDecMapInt32Uint8R(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTCborBytes - containerLen := d.mapStart(d.d.ReadMapStart()) - if rv.Kind() == reflect.Ptr { - vp, _ := rv2i(rv).(*map[int32]uint8) - if *vp == nil { - *vp = make(map[int32]uint8, decInferLen(containerLen, d.maxInitLen(), 5)) - } - if containerLen != 0 { - ft.DecMapInt32Uint8L(*vp, containerLen, d) - } - } else if containerLen != 0 { - ft.DecMapInt32Uint8L(rv2i(rv).(map[int32]uint8), containerLen, d) - } - d.mapEnd() -} -func (fastpathDTCborBytes) DecMapInt32Uint8L(v map[int32]uint8, containerLen int, d *decoderCborBytes) { - if v == nil { - halt.errorInt("cannot decode into nil map[int32]uint8 given stream length: ", int64(containerLen)) - } - hasLen := containerLen >= 0 - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - mk := int32(chkOvf.IntV(d.d.DecodeInt64(), 32)) - d.mapElemValue() - v[mk] = uint8(chkOvf.UintV(d.d.DecodeUint64(), 8)) - } -} -func (d *decoderCborBytes) fastpathDecMapInt32Uint64R(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTCborBytes - containerLen := d.mapStart(d.d.ReadMapStart()) - if rv.Kind() == reflect.Ptr { - vp, _ := rv2i(rv).(*map[int32]uint64) - if *vp == nil { - *vp = make(map[int32]uint64, decInferLen(containerLen, d.maxInitLen(), 12)) - } - if containerLen != 0 { - ft.DecMapInt32Uint64L(*vp, containerLen, d) - } - } else if containerLen != 0 { - ft.DecMapInt32Uint64L(rv2i(rv).(map[int32]uint64), containerLen, d) - } - d.mapEnd() -} -func (fastpathDTCborBytes) DecMapInt32Uint64L(v map[int32]uint64, containerLen int, d *decoderCborBytes) { - if v == nil { - halt.errorInt("cannot decode into nil map[int32]uint64 given stream length: ", int64(containerLen)) - } - hasLen := containerLen >= 0 - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - mk := int32(chkOvf.IntV(d.d.DecodeInt64(), 32)) - d.mapElemValue() - v[mk] = d.d.DecodeUint64() - } -} -func (d *decoderCborBytes) fastpathDecMapInt32IntR(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTCborBytes - containerLen := d.mapStart(d.d.ReadMapStart()) - if rv.Kind() == reflect.Ptr { - vp, _ := rv2i(rv).(*map[int32]int) - if *vp == nil { - *vp = make(map[int32]int, decInferLen(containerLen, d.maxInitLen(), 12)) - } - if containerLen != 0 { - ft.DecMapInt32IntL(*vp, containerLen, d) - } - } else if containerLen != 0 { - ft.DecMapInt32IntL(rv2i(rv).(map[int32]int), containerLen, d) - } - d.mapEnd() -} -func (fastpathDTCborBytes) DecMapInt32IntL(v map[int32]int, containerLen int, d *decoderCborBytes) { - if v == nil { - halt.errorInt("cannot decode into nil map[int32]int given stream length: ", int64(containerLen)) - } - hasLen := containerLen >= 0 - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - mk := int32(chkOvf.IntV(d.d.DecodeInt64(), 32)) - d.mapElemValue() - v[mk] = int(chkOvf.IntV(d.d.DecodeInt64(), intBitsize)) - } -} -func (d *decoderCborBytes) fastpathDecMapInt32Int32R(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTCborBytes - containerLen := d.mapStart(d.d.ReadMapStart()) - if rv.Kind() == reflect.Ptr { - vp, _ := rv2i(rv).(*map[int32]int32) - if *vp == nil { - *vp = make(map[int32]int32, decInferLen(containerLen, d.maxInitLen(), 8)) - } - if containerLen != 0 { - ft.DecMapInt32Int32L(*vp, containerLen, d) - } - } else if containerLen != 0 { - ft.DecMapInt32Int32L(rv2i(rv).(map[int32]int32), containerLen, d) - } - d.mapEnd() -} -func (fastpathDTCborBytes) DecMapInt32Int32L(v map[int32]int32, containerLen int, d *decoderCborBytes) { - if v == nil { - halt.errorInt("cannot decode into nil map[int32]int32 given stream length: ", int64(containerLen)) - } - hasLen := containerLen >= 0 - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - mk := int32(chkOvf.IntV(d.d.DecodeInt64(), 32)) - d.mapElemValue() - v[mk] = int32(chkOvf.IntV(d.d.DecodeInt64(), 32)) - } -} -func (d *decoderCborBytes) fastpathDecMapInt32Float64R(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTCborBytes - containerLen := d.mapStart(d.d.ReadMapStart()) - if rv.Kind() == reflect.Ptr { - vp, _ := rv2i(rv).(*map[int32]float64) - if *vp == nil { - *vp = make(map[int32]float64, decInferLen(containerLen, d.maxInitLen(), 12)) - } - if containerLen != 0 { - ft.DecMapInt32Float64L(*vp, containerLen, d) - } - } else if containerLen != 0 { - ft.DecMapInt32Float64L(rv2i(rv).(map[int32]float64), containerLen, d) - } - d.mapEnd() -} -func (fastpathDTCborBytes) DecMapInt32Float64L(v map[int32]float64, containerLen int, d *decoderCborBytes) { - if v == nil { - halt.errorInt("cannot decode into nil map[int32]float64 given stream length: ", int64(containerLen)) - } - hasLen := containerLen >= 0 - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - mk := int32(chkOvf.IntV(d.d.DecodeInt64(), 32)) - d.mapElemValue() - v[mk] = d.d.DecodeFloat64() - } -} -func (d *decoderCborBytes) fastpathDecMapInt32BoolR(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTCborBytes - containerLen := d.mapStart(d.d.ReadMapStart()) - if rv.Kind() == reflect.Ptr { - vp, _ := rv2i(rv).(*map[int32]bool) - if *vp == nil { - *vp = make(map[int32]bool, decInferLen(containerLen, d.maxInitLen(), 5)) - } - if containerLen != 0 { - ft.DecMapInt32BoolL(*vp, containerLen, d) - } - } else if containerLen != 0 { - ft.DecMapInt32BoolL(rv2i(rv).(map[int32]bool), containerLen, d) - } - d.mapEnd() -} -func (fastpathDTCborBytes) DecMapInt32BoolL(v map[int32]bool, containerLen int, d *decoderCborBytes) { - if v == nil { - halt.errorInt("cannot decode into nil map[int32]bool given stream length: ", int64(containerLen)) - } - hasLen := containerLen >= 0 - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - mk := int32(chkOvf.IntV(d.d.DecodeInt64(), 32)) - d.mapElemValue() - v[mk] = d.d.DecodeBool() - } -} - -type fastpathECborIO struct { - rtid uintptr - rt reflect.Type - encfn func(*encoderCborIO, *encFnInfo, reflect.Value) -} -type fastpathDCborIO struct { - rtid uintptr - rt reflect.Type - decfn func(*decoderCborIO, *decFnInfo, reflect.Value) -} -type fastpathEsCborIO [56]fastpathECborIO -type fastpathDsCborIO [56]fastpathDCborIO -type fastpathETCborIO struct{} -type fastpathDTCborIO struct{} - -func (helperEncDriverCborIO) fastpathEList() *fastpathEsCborIO { - var i uint = 0 - var s fastpathEsCborIO - fn := func(v interface{}, fe func(*encoderCborIO, *encFnInfo, reflect.Value)) { - xrt := reflect.TypeOf(v) - s[i] = fastpathECborIO{rt2id(xrt), xrt, fe} - i++ - } - - fn([]interface{}(nil), (*encoderCborIO).fastpathEncSliceIntfR) - fn([]string(nil), (*encoderCborIO).fastpathEncSliceStringR) - fn([][]byte(nil), (*encoderCborIO).fastpathEncSliceBytesR) - fn([]float32(nil), (*encoderCborIO).fastpathEncSliceFloat32R) - fn([]float64(nil), (*encoderCborIO).fastpathEncSliceFloat64R) - fn([]uint8(nil), (*encoderCborIO).fastpathEncSliceUint8R) - fn([]uint64(nil), (*encoderCborIO).fastpathEncSliceUint64R) - fn([]int(nil), (*encoderCborIO).fastpathEncSliceIntR) - fn([]int32(nil), (*encoderCborIO).fastpathEncSliceInt32R) - fn([]int64(nil), (*encoderCborIO).fastpathEncSliceInt64R) - fn([]bool(nil), (*encoderCborIO).fastpathEncSliceBoolR) - - fn(map[string]interface{}(nil), (*encoderCborIO).fastpathEncMapStringIntfR) - fn(map[string]string(nil), (*encoderCborIO).fastpathEncMapStringStringR) - fn(map[string][]byte(nil), (*encoderCborIO).fastpathEncMapStringBytesR) - fn(map[string]uint8(nil), (*encoderCborIO).fastpathEncMapStringUint8R) - fn(map[string]uint64(nil), (*encoderCborIO).fastpathEncMapStringUint64R) - fn(map[string]int(nil), (*encoderCborIO).fastpathEncMapStringIntR) - fn(map[string]int32(nil), (*encoderCborIO).fastpathEncMapStringInt32R) - fn(map[string]float64(nil), (*encoderCborIO).fastpathEncMapStringFloat64R) - fn(map[string]bool(nil), (*encoderCborIO).fastpathEncMapStringBoolR) - fn(map[uint8]interface{}(nil), (*encoderCborIO).fastpathEncMapUint8IntfR) - fn(map[uint8]string(nil), (*encoderCborIO).fastpathEncMapUint8StringR) - fn(map[uint8][]byte(nil), (*encoderCborIO).fastpathEncMapUint8BytesR) - fn(map[uint8]uint8(nil), (*encoderCborIO).fastpathEncMapUint8Uint8R) - fn(map[uint8]uint64(nil), (*encoderCborIO).fastpathEncMapUint8Uint64R) - fn(map[uint8]int(nil), (*encoderCborIO).fastpathEncMapUint8IntR) - fn(map[uint8]int32(nil), (*encoderCborIO).fastpathEncMapUint8Int32R) - fn(map[uint8]float64(nil), (*encoderCborIO).fastpathEncMapUint8Float64R) - fn(map[uint8]bool(nil), (*encoderCborIO).fastpathEncMapUint8BoolR) - fn(map[uint64]interface{}(nil), (*encoderCborIO).fastpathEncMapUint64IntfR) - fn(map[uint64]string(nil), (*encoderCborIO).fastpathEncMapUint64StringR) - fn(map[uint64][]byte(nil), (*encoderCborIO).fastpathEncMapUint64BytesR) - fn(map[uint64]uint8(nil), (*encoderCborIO).fastpathEncMapUint64Uint8R) - fn(map[uint64]uint64(nil), (*encoderCborIO).fastpathEncMapUint64Uint64R) - fn(map[uint64]int(nil), (*encoderCborIO).fastpathEncMapUint64IntR) - fn(map[uint64]int32(nil), (*encoderCborIO).fastpathEncMapUint64Int32R) - fn(map[uint64]float64(nil), (*encoderCborIO).fastpathEncMapUint64Float64R) - fn(map[uint64]bool(nil), (*encoderCborIO).fastpathEncMapUint64BoolR) - fn(map[int]interface{}(nil), (*encoderCborIO).fastpathEncMapIntIntfR) - fn(map[int]string(nil), (*encoderCborIO).fastpathEncMapIntStringR) - fn(map[int][]byte(nil), (*encoderCborIO).fastpathEncMapIntBytesR) - fn(map[int]uint8(nil), (*encoderCborIO).fastpathEncMapIntUint8R) - fn(map[int]uint64(nil), (*encoderCborIO).fastpathEncMapIntUint64R) - fn(map[int]int(nil), (*encoderCborIO).fastpathEncMapIntIntR) - fn(map[int]int32(nil), (*encoderCborIO).fastpathEncMapIntInt32R) - fn(map[int]float64(nil), (*encoderCborIO).fastpathEncMapIntFloat64R) - fn(map[int]bool(nil), (*encoderCborIO).fastpathEncMapIntBoolR) - fn(map[int32]interface{}(nil), (*encoderCborIO).fastpathEncMapInt32IntfR) - fn(map[int32]string(nil), (*encoderCborIO).fastpathEncMapInt32StringR) - fn(map[int32][]byte(nil), (*encoderCborIO).fastpathEncMapInt32BytesR) - fn(map[int32]uint8(nil), (*encoderCborIO).fastpathEncMapInt32Uint8R) - fn(map[int32]uint64(nil), (*encoderCborIO).fastpathEncMapInt32Uint64R) - fn(map[int32]int(nil), (*encoderCborIO).fastpathEncMapInt32IntR) - fn(map[int32]int32(nil), (*encoderCborIO).fastpathEncMapInt32Int32R) - fn(map[int32]float64(nil), (*encoderCborIO).fastpathEncMapInt32Float64R) - fn(map[int32]bool(nil), (*encoderCborIO).fastpathEncMapInt32BoolR) - - sort.Slice(s[:], func(i, j int) bool { return s[i].rtid < s[j].rtid }) - return &s -} - -func (helperDecDriverCborIO) fastpathDList() *fastpathDsCborIO { - var i uint = 0 - var s fastpathDsCborIO - fn := func(v interface{}, fd func(*decoderCborIO, *decFnInfo, reflect.Value)) { - xrt := reflect.TypeOf(v) - s[i] = fastpathDCborIO{rt2id(xrt), xrt, fd} - i++ - } - - fn([]interface{}(nil), (*decoderCborIO).fastpathDecSliceIntfR) - fn([]string(nil), (*decoderCborIO).fastpathDecSliceStringR) - fn([][]byte(nil), (*decoderCborIO).fastpathDecSliceBytesR) - fn([]float32(nil), (*decoderCborIO).fastpathDecSliceFloat32R) - fn([]float64(nil), (*decoderCborIO).fastpathDecSliceFloat64R) - fn([]uint8(nil), (*decoderCborIO).fastpathDecSliceUint8R) - fn([]uint64(nil), (*decoderCborIO).fastpathDecSliceUint64R) - fn([]int(nil), (*decoderCborIO).fastpathDecSliceIntR) - fn([]int32(nil), (*decoderCborIO).fastpathDecSliceInt32R) - fn([]int64(nil), (*decoderCborIO).fastpathDecSliceInt64R) - fn([]bool(nil), (*decoderCborIO).fastpathDecSliceBoolR) - - fn(map[string]interface{}(nil), (*decoderCborIO).fastpathDecMapStringIntfR) - fn(map[string]string(nil), (*decoderCborIO).fastpathDecMapStringStringR) - fn(map[string][]byte(nil), (*decoderCborIO).fastpathDecMapStringBytesR) - fn(map[string]uint8(nil), (*decoderCborIO).fastpathDecMapStringUint8R) - fn(map[string]uint64(nil), (*decoderCborIO).fastpathDecMapStringUint64R) - fn(map[string]int(nil), (*decoderCborIO).fastpathDecMapStringIntR) - fn(map[string]int32(nil), (*decoderCborIO).fastpathDecMapStringInt32R) - fn(map[string]float64(nil), (*decoderCborIO).fastpathDecMapStringFloat64R) - fn(map[string]bool(nil), (*decoderCborIO).fastpathDecMapStringBoolR) - fn(map[uint8]interface{}(nil), (*decoderCborIO).fastpathDecMapUint8IntfR) - fn(map[uint8]string(nil), (*decoderCborIO).fastpathDecMapUint8StringR) - fn(map[uint8][]byte(nil), (*decoderCborIO).fastpathDecMapUint8BytesR) - fn(map[uint8]uint8(nil), (*decoderCborIO).fastpathDecMapUint8Uint8R) - fn(map[uint8]uint64(nil), (*decoderCborIO).fastpathDecMapUint8Uint64R) - fn(map[uint8]int(nil), (*decoderCborIO).fastpathDecMapUint8IntR) - fn(map[uint8]int32(nil), (*decoderCborIO).fastpathDecMapUint8Int32R) - fn(map[uint8]float64(nil), (*decoderCborIO).fastpathDecMapUint8Float64R) - fn(map[uint8]bool(nil), (*decoderCborIO).fastpathDecMapUint8BoolR) - fn(map[uint64]interface{}(nil), (*decoderCborIO).fastpathDecMapUint64IntfR) - fn(map[uint64]string(nil), (*decoderCborIO).fastpathDecMapUint64StringR) - fn(map[uint64][]byte(nil), (*decoderCborIO).fastpathDecMapUint64BytesR) - fn(map[uint64]uint8(nil), (*decoderCborIO).fastpathDecMapUint64Uint8R) - fn(map[uint64]uint64(nil), (*decoderCborIO).fastpathDecMapUint64Uint64R) - fn(map[uint64]int(nil), (*decoderCborIO).fastpathDecMapUint64IntR) - fn(map[uint64]int32(nil), (*decoderCborIO).fastpathDecMapUint64Int32R) - fn(map[uint64]float64(nil), (*decoderCborIO).fastpathDecMapUint64Float64R) - fn(map[uint64]bool(nil), (*decoderCborIO).fastpathDecMapUint64BoolR) - fn(map[int]interface{}(nil), (*decoderCborIO).fastpathDecMapIntIntfR) - fn(map[int]string(nil), (*decoderCborIO).fastpathDecMapIntStringR) - fn(map[int][]byte(nil), (*decoderCborIO).fastpathDecMapIntBytesR) - fn(map[int]uint8(nil), (*decoderCborIO).fastpathDecMapIntUint8R) - fn(map[int]uint64(nil), (*decoderCborIO).fastpathDecMapIntUint64R) - fn(map[int]int(nil), (*decoderCborIO).fastpathDecMapIntIntR) - fn(map[int]int32(nil), (*decoderCborIO).fastpathDecMapIntInt32R) - fn(map[int]float64(nil), (*decoderCborIO).fastpathDecMapIntFloat64R) - fn(map[int]bool(nil), (*decoderCborIO).fastpathDecMapIntBoolR) - fn(map[int32]interface{}(nil), (*decoderCborIO).fastpathDecMapInt32IntfR) - fn(map[int32]string(nil), (*decoderCborIO).fastpathDecMapInt32StringR) - fn(map[int32][]byte(nil), (*decoderCborIO).fastpathDecMapInt32BytesR) - fn(map[int32]uint8(nil), (*decoderCborIO).fastpathDecMapInt32Uint8R) - fn(map[int32]uint64(nil), (*decoderCborIO).fastpathDecMapInt32Uint64R) - fn(map[int32]int(nil), (*decoderCborIO).fastpathDecMapInt32IntR) - fn(map[int32]int32(nil), (*decoderCborIO).fastpathDecMapInt32Int32R) - fn(map[int32]float64(nil), (*decoderCborIO).fastpathDecMapInt32Float64R) - fn(map[int32]bool(nil), (*decoderCborIO).fastpathDecMapInt32BoolR) - - sort.Slice(s[:], func(i, j int) bool { return s[i].rtid < s[j].rtid }) - return &s -} - -func (helperEncDriverCborIO) fastpathEncodeTypeSwitch(iv interface{}, e *encoderCborIO) bool { - var ft fastpathETCborIO - switch v := iv.(type) { - case []interface{}: - if v == nil { - e.e.writeNilArray() - } else { - ft.EncSliceIntfV(v, e) - } - case []string: - if v == nil { - e.e.writeNilArray() - } else { - ft.EncSliceStringV(v, e) - } - case [][]byte: - if v == nil { - e.e.writeNilArray() - } else { - ft.EncSliceBytesV(v, e) - } - case []float32: - if v == nil { - e.e.writeNilArray() - } else { - ft.EncSliceFloat32V(v, e) - } - case []float64: - if v == nil { - e.e.writeNilArray() - } else { - ft.EncSliceFloat64V(v, e) - } - case []uint8: - if v == nil { - e.e.writeNilArray() - } else { - ft.EncSliceUint8V(v, e) - } - case []uint64: - if v == nil { - e.e.writeNilArray() - } else { - ft.EncSliceUint64V(v, e) - } - case []int: - if v == nil { - e.e.writeNilArray() - } else { - ft.EncSliceIntV(v, e) - } - case []int32: - if v == nil { - e.e.writeNilArray() - } else { - ft.EncSliceInt32V(v, e) - } - case []int64: - if v == nil { - e.e.writeNilArray() - } else { - ft.EncSliceInt64V(v, e) - } - case []bool: - if v == nil { - e.e.writeNilArray() - } else { - ft.EncSliceBoolV(v, e) - } - case map[string]interface{}: - if v == nil { - e.e.writeNilMap() - } else { - ft.EncMapStringIntfV(v, e) - } - case map[string]string: - if v == nil { - e.e.writeNilMap() - } else { - ft.EncMapStringStringV(v, e) - } - case map[string][]byte: - if v == nil { - e.e.writeNilMap() - } else { - ft.EncMapStringBytesV(v, e) - } - case map[string]uint8: - if v == nil { - e.e.writeNilMap() - } else { - ft.EncMapStringUint8V(v, e) - } - case map[string]uint64: - if v == nil { - e.e.writeNilMap() - } else { - ft.EncMapStringUint64V(v, e) - } - case map[string]int: - if v == nil { - e.e.writeNilMap() - } else { - ft.EncMapStringIntV(v, e) - } - case map[string]int32: - if v == nil { - e.e.writeNilMap() - } else { - ft.EncMapStringInt32V(v, e) - } - case map[string]float64: - if v == nil { - e.e.writeNilMap() - } else { - ft.EncMapStringFloat64V(v, e) - } - case map[string]bool: - if v == nil { - e.e.writeNilMap() - } else { - ft.EncMapStringBoolV(v, e) - } - case map[uint8]interface{}: - if v == nil { - e.e.writeNilMap() - } else { - ft.EncMapUint8IntfV(v, e) - } - case map[uint8]string: - if v == nil { - e.e.writeNilMap() - } else { - ft.EncMapUint8StringV(v, e) - } - case map[uint8][]byte: - if v == nil { - e.e.writeNilMap() - } else { - ft.EncMapUint8BytesV(v, e) - } - case map[uint8]uint8: - if v == nil { - e.e.writeNilMap() - } else { - ft.EncMapUint8Uint8V(v, e) - } - case map[uint8]uint64: - if v == nil { - e.e.writeNilMap() - } else { - ft.EncMapUint8Uint64V(v, e) - } - case map[uint8]int: - if v == nil { - e.e.writeNilMap() - } else { - ft.EncMapUint8IntV(v, e) - } - case map[uint8]int32: - if v == nil { - e.e.writeNilMap() - } else { - ft.EncMapUint8Int32V(v, e) - } - case map[uint8]float64: - if v == nil { - e.e.writeNilMap() - } else { - ft.EncMapUint8Float64V(v, e) - } - case map[uint8]bool: - if v == nil { - e.e.writeNilMap() - } else { - ft.EncMapUint8BoolV(v, e) - } - case map[uint64]interface{}: - if v == nil { - e.e.writeNilMap() - } else { - ft.EncMapUint64IntfV(v, e) - } - case map[uint64]string: - if v == nil { - e.e.writeNilMap() - } else { - ft.EncMapUint64StringV(v, e) - } - case map[uint64][]byte: - if v == nil { - e.e.writeNilMap() - } else { - ft.EncMapUint64BytesV(v, e) - } - case map[uint64]uint8: - if v == nil { - e.e.writeNilMap() - } else { - ft.EncMapUint64Uint8V(v, e) - } - case map[uint64]uint64: - if v == nil { - e.e.writeNilMap() - } else { - ft.EncMapUint64Uint64V(v, e) - } - case map[uint64]int: - if v == nil { - e.e.writeNilMap() - } else { - ft.EncMapUint64IntV(v, e) - } - case map[uint64]int32: - if v == nil { - e.e.writeNilMap() - } else { - ft.EncMapUint64Int32V(v, e) - } - case map[uint64]float64: - if v == nil { - e.e.writeNilMap() - } else { - ft.EncMapUint64Float64V(v, e) - } - case map[uint64]bool: - if v == nil { - e.e.writeNilMap() - } else { - ft.EncMapUint64BoolV(v, e) - } - case map[int]interface{}: - if v == nil { - e.e.writeNilMap() - } else { - ft.EncMapIntIntfV(v, e) - } - case map[int]string: - if v == nil { - e.e.writeNilMap() - } else { - ft.EncMapIntStringV(v, e) - } - case map[int][]byte: - if v == nil { - e.e.writeNilMap() - } else { - ft.EncMapIntBytesV(v, e) - } - case map[int]uint8: - if v == nil { - e.e.writeNilMap() - } else { - ft.EncMapIntUint8V(v, e) - } - case map[int]uint64: - if v == nil { - e.e.writeNilMap() - } else { - ft.EncMapIntUint64V(v, e) - } - case map[int]int: - if v == nil { - e.e.writeNilMap() - } else { - ft.EncMapIntIntV(v, e) - } - case map[int]int32: - if v == nil { - e.e.writeNilMap() - } else { - ft.EncMapIntInt32V(v, e) - } - case map[int]float64: - if v == nil { - e.e.writeNilMap() - } else { - ft.EncMapIntFloat64V(v, e) - } - case map[int]bool: - if v == nil { - e.e.writeNilMap() - } else { - ft.EncMapIntBoolV(v, e) - } - case map[int32]interface{}: - if v == nil { - e.e.writeNilMap() - } else { - ft.EncMapInt32IntfV(v, e) - } - case map[int32]string: - if v == nil { - e.e.writeNilMap() - } else { - ft.EncMapInt32StringV(v, e) - } - case map[int32][]byte: - if v == nil { - e.e.writeNilMap() - } else { - ft.EncMapInt32BytesV(v, e) - } - case map[int32]uint8: - if v == nil { - e.e.writeNilMap() - } else { - ft.EncMapInt32Uint8V(v, e) - } - case map[int32]uint64: - if v == nil { - e.e.writeNilMap() - } else { - ft.EncMapInt32Uint64V(v, e) - } - case map[int32]int: - if v == nil { - e.e.writeNilMap() - } else { - ft.EncMapInt32IntV(v, e) - } - case map[int32]int32: - if v == nil { - e.e.writeNilMap() - } else { - ft.EncMapInt32Int32V(v, e) - } - case map[int32]float64: - if v == nil { - e.e.writeNilMap() - } else { - ft.EncMapInt32Float64V(v, e) - } - case map[int32]bool: - if v == nil { - e.e.writeNilMap() - } else { - ft.EncMapInt32BoolV(v, e) - } - default: - _ = v - return false - } - return true -} - -func (e *encoderCborIO) fastpathEncSliceIntfR(f *encFnInfo, rv reflect.Value) { - var ft fastpathETCborIO - var v []interface{} - if rv.Kind() == reflect.Array { - rvGetSlice4Array(rv, &v) - } else { - v = rv2i(rv).([]interface{}) - } - if f.ti.mbs { - ft.EncAsMapSliceIntfV(v, e) - return - } - ft.EncSliceIntfV(v, e) -} -func (fastpathETCborIO) EncSliceIntfV(v []interface{}, e *encoderCborIO) { - if len(v) == 0 { - e.c = 0 - e.e.WriteArrayEmpty() - return - } - e.arrayStart(len(v)) - for j := range v { - e.c = containerArrayElem - e.e.WriteArrayElem(j == 0) - if !e.encodeBuiltin(v[j]) { - e.encodeR(reflect.ValueOf(v[j])) - } - } - e.c = 0 - e.e.WriteArrayEnd() -} -func (fastpathETCborIO) EncAsMapSliceIntfV(v []interface{}, e *encoderCborIO) { - if len(v) == 0 { - e.c = 0 - e.e.WriteMapEmpty() - return - } - e.haltOnMbsOddLen(len(v)) - e.mapStart(len(v) >> 1) - for j := range v { - if j&1 == 0 { - e.c = containerMapKey - e.e.WriteMapElemKey(j == 0) - } else { - e.mapElemValue() - } - if !e.encodeBuiltin(v[j]) { - e.encodeR(reflect.ValueOf(v[j])) - } - } - e.c = 0 - e.e.WriteMapEnd() -} - -func (e *encoderCborIO) fastpathEncSliceStringR(f *encFnInfo, rv reflect.Value) { - var ft fastpathETCborIO - var v []string - if rv.Kind() == reflect.Array { - rvGetSlice4Array(rv, &v) - } else { - v = rv2i(rv).([]string) - } - if f.ti.mbs { - ft.EncAsMapSliceStringV(v, e) - return - } - ft.EncSliceStringV(v, e) -} -func (fastpathETCborIO) EncSliceStringV(v []string, e *encoderCborIO) { - if len(v) == 0 { - e.c = 0 - e.e.WriteArrayEmpty() - return - } - e.arrayStart(len(v)) - for j := range v { - e.c = containerArrayElem - e.e.WriteArrayElem(j == 0) - e.e.EncodeString(v[j]) - } - e.c = 0 - e.e.WriteArrayEnd() -} -func (fastpathETCborIO) EncAsMapSliceStringV(v []string, e *encoderCborIO) { - if len(v) == 0 { - e.c = 0 - e.e.WriteMapEmpty() - return - } - e.haltOnMbsOddLen(len(v)) - e.mapStart(len(v) >> 1) - for j := range v { - if j&1 == 0 { - e.c = containerMapKey - e.e.WriteMapElemKey(j == 0) - } else { - e.mapElemValue() - } - e.e.EncodeString(v[j]) - } - e.c = 0 - e.e.WriteMapEnd() -} - -func (e *encoderCborIO) fastpathEncSliceBytesR(f *encFnInfo, rv reflect.Value) { - var ft fastpathETCborIO - var v [][]byte - if rv.Kind() == reflect.Array { - rvGetSlice4Array(rv, &v) - } else { - v = rv2i(rv).([][]byte) - } - if f.ti.mbs { - ft.EncAsMapSliceBytesV(v, e) - return - } - ft.EncSliceBytesV(v, e) -} -func (fastpathETCborIO) EncSliceBytesV(v [][]byte, e *encoderCborIO) { - if len(v) == 0 { - e.c = 0 - e.e.WriteArrayEmpty() - return - } - e.arrayStart(len(v)) - for j := range v { - e.c = containerArrayElem - e.e.WriteArrayElem(j == 0) - e.e.EncodeBytes(v[j]) - } - e.c = 0 - e.e.WriteArrayEnd() -} -func (fastpathETCborIO) EncAsMapSliceBytesV(v [][]byte, e *encoderCborIO) { - if len(v) == 0 { - e.c = 0 - e.e.WriteMapEmpty() - return - } - e.haltOnMbsOddLen(len(v)) - e.mapStart(len(v) >> 1) - for j := range v { - if j&1 == 0 { - e.c = containerMapKey - e.e.WriteMapElemKey(j == 0) - } else { - e.mapElemValue() - } - e.e.EncodeBytes(v[j]) - } - e.c = 0 - e.e.WriteMapEnd() -} - -func (e *encoderCborIO) fastpathEncSliceFloat32R(f *encFnInfo, rv reflect.Value) { - var ft fastpathETCborIO - var v []float32 - if rv.Kind() == reflect.Array { - rvGetSlice4Array(rv, &v) - } else { - v = rv2i(rv).([]float32) - } - if f.ti.mbs { - ft.EncAsMapSliceFloat32V(v, e) - return - } - ft.EncSliceFloat32V(v, e) -} -func (fastpathETCborIO) EncSliceFloat32V(v []float32, e *encoderCborIO) { - if len(v) == 0 { - e.c = 0 - e.e.WriteArrayEmpty() - return - } - e.arrayStart(len(v)) - for j := range v { - e.c = containerArrayElem - e.e.WriteArrayElem(j == 0) - e.e.EncodeFloat32(v[j]) - } - e.c = 0 - e.e.WriteArrayEnd() -} -func (fastpathETCborIO) EncAsMapSliceFloat32V(v []float32, e *encoderCborIO) { - if len(v) == 0 { - e.c = 0 - e.e.WriteMapEmpty() - return - } - e.haltOnMbsOddLen(len(v)) - e.mapStart(len(v) >> 1) - for j := range v { - if j&1 == 0 { - e.c = containerMapKey - e.e.WriteMapElemKey(j == 0) - } else { - e.mapElemValue() - } - e.e.EncodeFloat32(v[j]) - } - e.c = 0 - e.e.WriteMapEnd() -} - -func (e *encoderCborIO) fastpathEncSliceFloat64R(f *encFnInfo, rv reflect.Value) { - var ft fastpathETCborIO - var v []float64 - if rv.Kind() == reflect.Array { - rvGetSlice4Array(rv, &v) - } else { - v = rv2i(rv).([]float64) - } - if f.ti.mbs { - ft.EncAsMapSliceFloat64V(v, e) - return - } - ft.EncSliceFloat64V(v, e) -} -func (fastpathETCborIO) EncSliceFloat64V(v []float64, e *encoderCborIO) { - if len(v) == 0 { - e.c = 0 - e.e.WriteArrayEmpty() - return - } - e.arrayStart(len(v)) - for j := range v { - e.c = containerArrayElem - e.e.WriteArrayElem(j == 0) - e.e.EncodeFloat64(v[j]) - } - e.c = 0 - e.e.WriteArrayEnd() -} -func (fastpathETCborIO) EncAsMapSliceFloat64V(v []float64, e *encoderCborIO) { - if len(v) == 0 { - e.c = 0 - e.e.WriteMapEmpty() - return - } - e.haltOnMbsOddLen(len(v)) - e.mapStart(len(v) >> 1) - for j := range v { - if j&1 == 0 { - e.c = containerMapKey - e.e.WriteMapElemKey(j == 0) - } else { - e.mapElemValue() - } - e.e.EncodeFloat64(v[j]) - } - e.c = 0 - e.e.WriteMapEnd() -} - -func (e *encoderCborIO) fastpathEncSliceUint8R(f *encFnInfo, rv reflect.Value) { - var ft fastpathETCborIO - var v []uint8 - if rv.Kind() == reflect.Array { - rvGetSlice4Array(rv, &v) - } else { - v = rv2i(rv).([]uint8) - } - if f.ti.mbs { - ft.EncAsMapSliceUint8V(v, e) - return - } - ft.EncSliceUint8V(v, e) -} -func (fastpathETCborIO) EncSliceUint8V(v []uint8, e *encoderCborIO) { - e.e.EncodeStringBytesRaw(v) -} -func (fastpathETCborIO) EncAsMapSliceUint8V(v []uint8, e *encoderCborIO) { - if len(v) == 0 { - e.c = 0 - e.e.WriteMapEmpty() - return - } - e.haltOnMbsOddLen(len(v)) - e.mapStart(len(v) >> 1) - for j := range v { - if j&1 == 0 { - e.c = containerMapKey - e.e.WriteMapElemKey(j == 0) - } else { - e.mapElemValue() - } - e.e.EncodeUint(uint64(v[j])) - } - e.c = 0 - e.e.WriteMapEnd() -} - -func (e *encoderCborIO) fastpathEncSliceUint64R(f *encFnInfo, rv reflect.Value) { - var ft fastpathETCborIO - var v []uint64 - if rv.Kind() == reflect.Array { - rvGetSlice4Array(rv, &v) - } else { - v = rv2i(rv).([]uint64) - } - if f.ti.mbs { - ft.EncAsMapSliceUint64V(v, e) - return - } - ft.EncSliceUint64V(v, e) -} -func (fastpathETCborIO) EncSliceUint64V(v []uint64, e *encoderCborIO) { - if len(v) == 0 { - e.c = 0 - e.e.WriteArrayEmpty() - return - } - e.arrayStart(len(v)) - for j := range v { - e.c = containerArrayElem - e.e.WriteArrayElem(j == 0) - e.e.EncodeUint(v[j]) - } - e.c = 0 - e.e.WriteArrayEnd() -} -func (fastpathETCborIO) EncAsMapSliceUint64V(v []uint64, e *encoderCborIO) { - if len(v) == 0 { - e.c = 0 - e.e.WriteMapEmpty() - return - } - e.haltOnMbsOddLen(len(v)) - e.mapStart(len(v) >> 1) - for j := range v { - if j&1 == 0 { - e.c = containerMapKey - e.e.WriteMapElemKey(j == 0) - } else { - e.mapElemValue() - } - e.e.EncodeUint(v[j]) - } - e.c = 0 - e.e.WriteMapEnd() -} - -func (e *encoderCborIO) fastpathEncSliceIntR(f *encFnInfo, rv reflect.Value) { - var ft fastpathETCborIO - var v []int - if rv.Kind() == reflect.Array { - rvGetSlice4Array(rv, &v) - } else { - v = rv2i(rv).([]int) - } - if f.ti.mbs { - ft.EncAsMapSliceIntV(v, e) - return - } - ft.EncSliceIntV(v, e) -} -func (fastpathETCborIO) EncSliceIntV(v []int, e *encoderCborIO) { - if len(v) == 0 { - e.c = 0 - e.e.WriteArrayEmpty() - return - } - e.arrayStart(len(v)) - for j := range v { - e.c = containerArrayElem - e.e.WriteArrayElem(j == 0) - e.e.EncodeInt(int64(v[j])) - } - e.c = 0 - e.e.WriteArrayEnd() -} -func (fastpathETCborIO) EncAsMapSliceIntV(v []int, e *encoderCborIO) { - if len(v) == 0 { - e.c = 0 - e.e.WriteMapEmpty() - return - } - e.haltOnMbsOddLen(len(v)) - e.mapStart(len(v) >> 1) - for j := range v { - if j&1 == 0 { - e.c = containerMapKey - e.e.WriteMapElemKey(j == 0) - } else { - e.mapElemValue() - } - e.e.EncodeInt(int64(v[j])) - } - e.c = 0 - e.e.WriteMapEnd() -} - -func (e *encoderCborIO) fastpathEncSliceInt32R(f *encFnInfo, rv reflect.Value) { - var ft fastpathETCborIO - var v []int32 - if rv.Kind() == reflect.Array { - rvGetSlice4Array(rv, &v) - } else { - v = rv2i(rv).([]int32) - } - if f.ti.mbs { - ft.EncAsMapSliceInt32V(v, e) - return - } - ft.EncSliceInt32V(v, e) -} -func (fastpathETCborIO) EncSliceInt32V(v []int32, e *encoderCborIO) { - if len(v) == 0 { - e.c = 0 - e.e.WriteArrayEmpty() - return - } - e.arrayStart(len(v)) - for j := range v { - e.c = containerArrayElem - e.e.WriteArrayElem(j == 0) - e.e.EncodeInt(int64(v[j])) - } - e.c = 0 - e.e.WriteArrayEnd() -} -func (fastpathETCborIO) EncAsMapSliceInt32V(v []int32, e *encoderCborIO) { - if len(v) == 0 { - e.c = 0 - e.e.WriteMapEmpty() - return - } - e.haltOnMbsOddLen(len(v)) - e.mapStart(len(v) >> 1) - for j := range v { - if j&1 == 0 { - e.c = containerMapKey - e.e.WriteMapElemKey(j == 0) - } else { - e.mapElemValue() - } - e.e.EncodeInt(int64(v[j])) - } - e.c = 0 - e.e.WriteMapEnd() -} - -func (e *encoderCborIO) fastpathEncSliceInt64R(f *encFnInfo, rv reflect.Value) { - var ft fastpathETCborIO - var v []int64 - if rv.Kind() == reflect.Array { - rvGetSlice4Array(rv, &v) - } else { - v = rv2i(rv).([]int64) - } - if f.ti.mbs { - ft.EncAsMapSliceInt64V(v, e) - return - } - ft.EncSliceInt64V(v, e) -} -func (fastpathETCborIO) EncSliceInt64V(v []int64, e *encoderCborIO) { - if len(v) == 0 { - e.c = 0 - e.e.WriteArrayEmpty() - return - } - e.arrayStart(len(v)) - for j := range v { - e.c = containerArrayElem - e.e.WriteArrayElem(j == 0) - e.e.EncodeInt(v[j]) - } - e.c = 0 - e.e.WriteArrayEnd() -} -func (fastpathETCborIO) EncAsMapSliceInt64V(v []int64, e *encoderCborIO) { - if len(v) == 0 { - e.c = 0 - e.e.WriteMapEmpty() - return - } - e.haltOnMbsOddLen(len(v)) - e.mapStart(len(v) >> 1) - for j := range v { - if j&1 == 0 { - e.c = containerMapKey - e.e.WriteMapElemKey(j == 0) - } else { - e.mapElemValue() - } - e.e.EncodeInt(v[j]) - } - e.c = 0 - e.e.WriteMapEnd() -} - -func (e *encoderCborIO) fastpathEncSliceBoolR(f *encFnInfo, rv reflect.Value) { - var ft fastpathETCborIO - var v []bool - if rv.Kind() == reflect.Array { - rvGetSlice4Array(rv, &v) - } else { - v = rv2i(rv).([]bool) - } - if f.ti.mbs { - ft.EncAsMapSliceBoolV(v, e) - return - } - ft.EncSliceBoolV(v, e) -} -func (fastpathETCborIO) EncSliceBoolV(v []bool, e *encoderCborIO) { - if len(v) == 0 { - e.c = 0 - e.e.WriteArrayEmpty() - return - } - e.arrayStart(len(v)) - for j := range v { - e.c = containerArrayElem - e.e.WriteArrayElem(j == 0) - e.e.EncodeBool(v[j]) - } - e.c = 0 - e.e.WriteArrayEnd() -} -func (fastpathETCborIO) EncAsMapSliceBoolV(v []bool, e *encoderCborIO) { - if len(v) == 0 { - e.c = 0 - e.e.WriteMapEmpty() - return - } - e.haltOnMbsOddLen(len(v)) - e.mapStart(len(v) >> 1) - for j := range v { - if j&1 == 0 { - e.c = containerMapKey - e.e.WriteMapElemKey(j == 0) - } else { - e.mapElemValue() - } - e.e.EncodeBool(v[j]) - } - e.c = 0 - e.e.WriteMapEnd() -} - -func (e *encoderCborIO) fastpathEncMapStringIntfR(f *encFnInfo, rv reflect.Value) { - fastpathETCborIO{}.EncMapStringIntfV(rv2i(rv).(map[string]interface{}), e) -} -func (fastpathETCborIO) EncMapStringIntfV(v map[string]interface{}, e *encoderCborIO) { - if len(v) == 0 { - e.e.WriteMapEmpty() - return - } - var i uint - e.mapStart(len(v)) - if e.h.Canonical { - v2 := make([]string, len(v)) - for k := range v { - v2[i] = k - i++ - } - slices.Sort(v2) - for i, k2 := range v2 { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeString(k2) - e.mapElemValue() - if !e.encodeBuiltin(v[k2]) { - e.encodeR(reflect.ValueOf(v[k2])) - } - } - } else { - i = 0 - for k2, v2 := range v { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeString(k2) - e.mapElemValue() - if !e.encodeBuiltin(v2) { - e.encodeR(reflect.ValueOf(v2)) - } - i++ - } - } - e.c = 0 - e.e.WriteMapEnd() -} -func (e *encoderCborIO) fastpathEncMapStringStringR(f *encFnInfo, rv reflect.Value) { - fastpathETCborIO{}.EncMapStringStringV(rv2i(rv).(map[string]string), e) -} -func (fastpathETCborIO) EncMapStringStringV(v map[string]string, e *encoderCborIO) { - if len(v) == 0 { - e.e.WriteMapEmpty() - return - } - var i uint - e.mapStart(len(v)) - if e.h.Canonical { - v2 := make([]string, len(v)) - for k := range v { - v2[i] = k - i++ - } - slices.Sort(v2) - for i, k2 := range v2 { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeString(k2) - e.mapElemValue() - e.e.EncodeString(v[k2]) - } - } else { - i = 0 - for k2, v2 := range v { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeString(k2) - e.mapElemValue() - e.e.EncodeString(v2) - i++ - } - } - e.c = 0 - e.e.WriteMapEnd() -} -func (e *encoderCborIO) fastpathEncMapStringBytesR(f *encFnInfo, rv reflect.Value) { - fastpathETCborIO{}.EncMapStringBytesV(rv2i(rv).(map[string][]byte), e) -} -func (fastpathETCborIO) EncMapStringBytesV(v map[string][]byte, e *encoderCborIO) { - if len(v) == 0 { - e.e.WriteMapEmpty() - return - } - var i uint - e.mapStart(len(v)) - if e.h.Canonical { - v2 := make([]string, len(v)) - for k := range v { - v2[i] = k - i++ - } - slices.Sort(v2) - for i, k2 := range v2 { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeString(k2) - e.mapElemValue() - e.e.EncodeBytes(v[k2]) - } - } else { - i = 0 - for k2, v2 := range v { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeString(k2) - e.mapElemValue() - e.e.EncodeBytes(v2) - i++ - } - } - e.c = 0 - e.e.WriteMapEnd() -} -func (e *encoderCborIO) fastpathEncMapStringUint8R(f *encFnInfo, rv reflect.Value) { - fastpathETCborIO{}.EncMapStringUint8V(rv2i(rv).(map[string]uint8), e) -} -func (fastpathETCborIO) EncMapStringUint8V(v map[string]uint8, e *encoderCborIO) { - if len(v) == 0 { - e.e.WriteMapEmpty() - return - } - var i uint - e.mapStart(len(v)) - if e.h.Canonical { - v2 := make([]string, len(v)) - for k := range v { - v2[i] = k - i++ - } - slices.Sort(v2) - for i, k2 := range v2 { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeString(k2) - e.mapElemValue() - e.e.EncodeUint(uint64(v[k2])) - } - } else { - i = 0 - for k2, v2 := range v { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeString(k2) - e.mapElemValue() - e.e.EncodeUint(uint64(v2)) - i++ - } - } - e.c = 0 - e.e.WriteMapEnd() -} -func (e *encoderCborIO) fastpathEncMapStringUint64R(f *encFnInfo, rv reflect.Value) { - fastpathETCborIO{}.EncMapStringUint64V(rv2i(rv).(map[string]uint64), e) -} -func (fastpathETCborIO) EncMapStringUint64V(v map[string]uint64, e *encoderCborIO) { - if len(v) == 0 { - e.e.WriteMapEmpty() - return - } - var i uint - e.mapStart(len(v)) - if e.h.Canonical { - v2 := make([]string, len(v)) - for k := range v { - v2[i] = k - i++ - } - slices.Sort(v2) - for i, k2 := range v2 { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeString(k2) - e.mapElemValue() - e.e.EncodeUint(v[k2]) - } - } else { - i = 0 - for k2, v2 := range v { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeString(k2) - e.mapElemValue() - e.e.EncodeUint(v2) - i++ - } - } - e.c = 0 - e.e.WriteMapEnd() -} -func (e *encoderCborIO) fastpathEncMapStringIntR(f *encFnInfo, rv reflect.Value) { - fastpathETCborIO{}.EncMapStringIntV(rv2i(rv).(map[string]int), e) -} -func (fastpathETCborIO) EncMapStringIntV(v map[string]int, e *encoderCborIO) { - if len(v) == 0 { - e.e.WriteMapEmpty() - return - } - var i uint - e.mapStart(len(v)) - if e.h.Canonical { - v2 := make([]string, len(v)) - for k := range v { - v2[i] = k - i++ - } - slices.Sort(v2) - for i, k2 := range v2 { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeString(k2) - e.mapElemValue() - e.e.EncodeInt(int64(v[k2])) - } - } else { - i = 0 - for k2, v2 := range v { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeString(k2) - e.mapElemValue() - e.e.EncodeInt(int64(v2)) - i++ - } - } - e.c = 0 - e.e.WriteMapEnd() -} -func (e *encoderCborIO) fastpathEncMapStringInt32R(f *encFnInfo, rv reflect.Value) { - fastpathETCborIO{}.EncMapStringInt32V(rv2i(rv).(map[string]int32), e) -} -func (fastpathETCborIO) EncMapStringInt32V(v map[string]int32, e *encoderCborIO) { - if len(v) == 0 { - e.e.WriteMapEmpty() - return - } - var i uint - e.mapStart(len(v)) - if e.h.Canonical { - v2 := make([]string, len(v)) - for k := range v { - v2[i] = k - i++ - } - slices.Sort(v2) - for i, k2 := range v2 { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeString(k2) - e.mapElemValue() - e.e.EncodeInt(int64(v[k2])) - } - } else { - i = 0 - for k2, v2 := range v { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeString(k2) - e.mapElemValue() - e.e.EncodeInt(int64(v2)) - i++ - } - } - e.c = 0 - e.e.WriteMapEnd() -} -func (e *encoderCborIO) fastpathEncMapStringFloat64R(f *encFnInfo, rv reflect.Value) { - fastpathETCborIO{}.EncMapStringFloat64V(rv2i(rv).(map[string]float64), e) -} -func (fastpathETCborIO) EncMapStringFloat64V(v map[string]float64, e *encoderCborIO) { - if len(v) == 0 { - e.e.WriteMapEmpty() - return - } - var i uint - e.mapStart(len(v)) - if e.h.Canonical { - v2 := make([]string, len(v)) - for k := range v { - v2[i] = k - i++ - } - slices.Sort(v2) - for i, k2 := range v2 { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeString(k2) - e.mapElemValue() - e.e.EncodeFloat64(v[k2]) - } - } else { - i = 0 - for k2, v2 := range v { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeString(k2) - e.mapElemValue() - e.e.EncodeFloat64(v2) - i++ - } - } - e.c = 0 - e.e.WriteMapEnd() -} -func (e *encoderCborIO) fastpathEncMapStringBoolR(f *encFnInfo, rv reflect.Value) { - fastpathETCborIO{}.EncMapStringBoolV(rv2i(rv).(map[string]bool), e) -} -func (fastpathETCborIO) EncMapStringBoolV(v map[string]bool, e *encoderCborIO) { - if len(v) == 0 { - e.e.WriteMapEmpty() - return - } - var i uint - e.mapStart(len(v)) - if e.h.Canonical { - v2 := make([]string, len(v)) - for k := range v { - v2[i] = k - i++ - } - slices.Sort(v2) - for i, k2 := range v2 { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeString(k2) - e.mapElemValue() - e.e.EncodeBool(v[k2]) - } - } else { - i = 0 - for k2, v2 := range v { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeString(k2) - e.mapElemValue() - e.e.EncodeBool(v2) - i++ - } - } - e.c = 0 - e.e.WriteMapEnd() -} -func (e *encoderCborIO) fastpathEncMapUint8IntfR(f *encFnInfo, rv reflect.Value) { - fastpathETCborIO{}.EncMapUint8IntfV(rv2i(rv).(map[uint8]interface{}), e) -} -func (fastpathETCborIO) EncMapUint8IntfV(v map[uint8]interface{}, e *encoderCborIO) { - if len(v) == 0 { - e.e.WriteMapEmpty() - return - } - var i uint - e.mapStart(len(v)) - if e.h.Canonical { - v2 := make([]uint8, len(v)) - for k := range v { - v2[i] = k - i++ - } - slices.Sort(v2) - for i, k2 := range v2 { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeUint(uint64(k2)) - e.mapElemValue() - if !e.encodeBuiltin(v[k2]) { - e.encodeR(reflect.ValueOf(v[k2])) - } - } - } else { - i = 0 - for k2, v2 := range v { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeUint(uint64(k2)) - e.mapElemValue() - if !e.encodeBuiltin(v2) { - e.encodeR(reflect.ValueOf(v2)) - } - i++ - } - } - e.c = 0 - e.e.WriteMapEnd() -} -func (e *encoderCborIO) fastpathEncMapUint8StringR(f *encFnInfo, rv reflect.Value) { - fastpathETCborIO{}.EncMapUint8StringV(rv2i(rv).(map[uint8]string), e) -} -func (fastpathETCborIO) EncMapUint8StringV(v map[uint8]string, e *encoderCborIO) { - if len(v) == 0 { - e.e.WriteMapEmpty() - return - } - var i uint - e.mapStart(len(v)) - if e.h.Canonical { - v2 := make([]uint8, len(v)) - for k := range v { - v2[i] = k - i++ - } - slices.Sort(v2) - for i, k2 := range v2 { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeUint(uint64(k2)) - e.mapElemValue() - e.e.EncodeString(v[k2]) - } - } else { - i = 0 - for k2, v2 := range v { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeUint(uint64(k2)) - e.mapElemValue() - e.e.EncodeString(v2) - i++ - } - } - e.c = 0 - e.e.WriteMapEnd() -} -func (e *encoderCborIO) fastpathEncMapUint8BytesR(f *encFnInfo, rv reflect.Value) { - fastpathETCborIO{}.EncMapUint8BytesV(rv2i(rv).(map[uint8][]byte), e) -} -func (fastpathETCborIO) EncMapUint8BytesV(v map[uint8][]byte, e *encoderCborIO) { - if len(v) == 0 { - e.e.WriteMapEmpty() - return - } - var i uint - e.mapStart(len(v)) - if e.h.Canonical { - v2 := make([]uint8, len(v)) - for k := range v { - v2[i] = k - i++ - } - slices.Sort(v2) - for i, k2 := range v2 { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeUint(uint64(k2)) - e.mapElemValue() - e.e.EncodeBytes(v[k2]) - } - } else { - i = 0 - for k2, v2 := range v { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeUint(uint64(k2)) - e.mapElemValue() - e.e.EncodeBytes(v2) - i++ - } - } - e.c = 0 - e.e.WriteMapEnd() -} -func (e *encoderCborIO) fastpathEncMapUint8Uint8R(f *encFnInfo, rv reflect.Value) { - fastpathETCborIO{}.EncMapUint8Uint8V(rv2i(rv).(map[uint8]uint8), e) -} -func (fastpathETCborIO) EncMapUint8Uint8V(v map[uint8]uint8, e *encoderCborIO) { - if len(v) == 0 { - e.e.WriteMapEmpty() - return - } - var i uint - e.mapStart(len(v)) - if e.h.Canonical { - v2 := make([]uint8, len(v)) - for k := range v { - v2[i] = k - i++ - } - slices.Sort(v2) - for i, k2 := range v2 { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeUint(uint64(k2)) - e.mapElemValue() - e.e.EncodeUint(uint64(v[k2])) - } - } else { - i = 0 - for k2, v2 := range v { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeUint(uint64(k2)) - e.mapElemValue() - e.e.EncodeUint(uint64(v2)) - i++ - } - } - e.c = 0 - e.e.WriteMapEnd() -} -func (e *encoderCborIO) fastpathEncMapUint8Uint64R(f *encFnInfo, rv reflect.Value) { - fastpathETCborIO{}.EncMapUint8Uint64V(rv2i(rv).(map[uint8]uint64), e) -} -func (fastpathETCborIO) EncMapUint8Uint64V(v map[uint8]uint64, e *encoderCborIO) { - if len(v) == 0 { - e.e.WriteMapEmpty() - return - } - var i uint - e.mapStart(len(v)) - if e.h.Canonical { - v2 := make([]uint8, len(v)) - for k := range v { - v2[i] = k - i++ - } - slices.Sort(v2) - for i, k2 := range v2 { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeUint(uint64(k2)) - e.mapElemValue() - e.e.EncodeUint(v[k2]) - } - } else { - i = 0 - for k2, v2 := range v { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeUint(uint64(k2)) - e.mapElemValue() - e.e.EncodeUint(v2) - i++ - } - } - e.c = 0 - e.e.WriteMapEnd() -} -func (e *encoderCborIO) fastpathEncMapUint8IntR(f *encFnInfo, rv reflect.Value) { - fastpathETCborIO{}.EncMapUint8IntV(rv2i(rv).(map[uint8]int), e) -} -func (fastpathETCborIO) EncMapUint8IntV(v map[uint8]int, e *encoderCborIO) { - if len(v) == 0 { - e.e.WriteMapEmpty() - return - } - var i uint - e.mapStart(len(v)) - if e.h.Canonical { - v2 := make([]uint8, len(v)) - for k := range v { - v2[i] = k - i++ - } - slices.Sort(v2) - for i, k2 := range v2 { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeUint(uint64(k2)) - e.mapElemValue() - e.e.EncodeInt(int64(v[k2])) - } - } else { - i = 0 - for k2, v2 := range v { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeUint(uint64(k2)) - e.mapElemValue() - e.e.EncodeInt(int64(v2)) - i++ - } - } - e.c = 0 - e.e.WriteMapEnd() -} -func (e *encoderCborIO) fastpathEncMapUint8Int32R(f *encFnInfo, rv reflect.Value) { - fastpathETCborIO{}.EncMapUint8Int32V(rv2i(rv).(map[uint8]int32), e) -} -func (fastpathETCborIO) EncMapUint8Int32V(v map[uint8]int32, e *encoderCborIO) { - if len(v) == 0 { - e.e.WriteMapEmpty() - return - } - var i uint - e.mapStart(len(v)) - if e.h.Canonical { - v2 := make([]uint8, len(v)) - for k := range v { - v2[i] = k - i++ - } - slices.Sort(v2) - for i, k2 := range v2 { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeUint(uint64(k2)) - e.mapElemValue() - e.e.EncodeInt(int64(v[k2])) - } - } else { - i = 0 - for k2, v2 := range v { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeUint(uint64(k2)) - e.mapElemValue() - e.e.EncodeInt(int64(v2)) - i++ - } - } - e.c = 0 - e.e.WriteMapEnd() -} -func (e *encoderCborIO) fastpathEncMapUint8Float64R(f *encFnInfo, rv reflect.Value) { - fastpathETCborIO{}.EncMapUint8Float64V(rv2i(rv).(map[uint8]float64), e) -} -func (fastpathETCborIO) EncMapUint8Float64V(v map[uint8]float64, e *encoderCborIO) { - if len(v) == 0 { - e.e.WriteMapEmpty() - return - } - var i uint - e.mapStart(len(v)) - if e.h.Canonical { - v2 := make([]uint8, len(v)) - for k := range v { - v2[i] = k - i++ - } - slices.Sort(v2) - for i, k2 := range v2 { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeUint(uint64(k2)) - e.mapElemValue() - e.e.EncodeFloat64(v[k2]) - } - } else { - i = 0 - for k2, v2 := range v { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeUint(uint64(k2)) - e.mapElemValue() - e.e.EncodeFloat64(v2) - i++ - } - } - e.c = 0 - e.e.WriteMapEnd() -} -func (e *encoderCborIO) fastpathEncMapUint8BoolR(f *encFnInfo, rv reflect.Value) { - fastpathETCborIO{}.EncMapUint8BoolV(rv2i(rv).(map[uint8]bool), e) -} -func (fastpathETCborIO) EncMapUint8BoolV(v map[uint8]bool, e *encoderCborIO) { - if len(v) == 0 { - e.e.WriteMapEmpty() - return - } - var i uint - e.mapStart(len(v)) - if e.h.Canonical { - v2 := make([]uint8, len(v)) - for k := range v { - v2[i] = k - i++ - } - slices.Sort(v2) - for i, k2 := range v2 { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeUint(uint64(k2)) - e.mapElemValue() - e.e.EncodeBool(v[k2]) - } - } else { - i = 0 - for k2, v2 := range v { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeUint(uint64(k2)) - e.mapElemValue() - e.e.EncodeBool(v2) - i++ - } - } - e.c = 0 - e.e.WriteMapEnd() -} -func (e *encoderCborIO) fastpathEncMapUint64IntfR(f *encFnInfo, rv reflect.Value) { - fastpathETCborIO{}.EncMapUint64IntfV(rv2i(rv).(map[uint64]interface{}), e) -} -func (fastpathETCborIO) EncMapUint64IntfV(v map[uint64]interface{}, e *encoderCborIO) { - if len(v) == 0 { - e.e.WriteMapEmpty() - return - } - var i uint - e.mapStart(len(v)) - if e.h.Canonical { - v2 := make([]uint64, len(v)) - for k := range v { - v2[i] = k - i++ - } - slices.Sort(v2) - for i, k2 := range v2 { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeUint(k2) - e.mapElemValue() - if !e.encodeBuiltin(v[k2]) { - e.encodeR(reflect.ValueOf(v[k2])) - } - } - } else { - i = 0 - for k2, v2 := range v { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeUint(k2) - e.mapElemValue() - if !e.encodeBuiltin(v2) { - e.encodeR(reflect.ValueOf(v2)) - } - i++ - } - } - e.c = 0 - e.e.WriteMapEnd() -} -func (e *encoderCborIO) fastpathEncMapUint64StringR(f *encFnInfo, rv reflect.Value) { - fastpathETCborIO{}.EncMapUint64StringV(rv2i(rv).(map[uint64]string), e) -} -func (fastpathETCborIO) EncMapUint64StringV(v map[uint64]string, e *encoderCborIO) { - if len(v) == 0 { - e.e.WriteMapEmpty() - return - } - var i uint - e.mapStart(len(v)) - if e.h.Canonical { - v2 := make([]uint64, len(v)) - for k := range v { - v2[i] = k - i++ - } - slices.Sort(v2) - for i, k2 := range v2 { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeUint(k2) - e.mapElemValue() - e.e.EncodeString(v[k2]) - } - } else { - i = 0 - for k2, v2 := range v { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeUint(k2) - e.mapElemValue() - e.e.EncodeString(v2) - i++ - } - } - e.c = 0 - e.e.WriteMapEnd() -} -func (e *encoderCborIO) fastpathEncMapUint64BytesR(f *encFnInfo, rv reflect.Value) { - fastpathETCborIO{}.EncMapUint64BytesV(rv2i(rv).(map[uint64][]byte), e) -} -func (fastpathETCborIO) EncMapUint64BytesV(v map[uint64][]byte, e *encoderCborIO) { - if len(v) == 0 { - e.e.WriteMapEmpty() - return - } - var i uint - e.mapStart(len(v)) - if e.h.Canonical { - v2 := make([]uint64, len(v)) - for k := range v { - v2[i] = k - i++ - } - slices.Sort(v2) - for i, k2 := range v2 { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeUint(k2) - e.mapElemValue() - e.e.EncodeBytes(v[k2]) - } - } else { - i = 0 - for k2, v2 := range v { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeUint(k2) - e.mapElemValue() - e.e.EncodeBytes(v2) - i++ - } - } - e.c = 0 - e.e.WriteMapEnd() -} -func (e *encoderCborIO) fastpathEncMapUint64Uint8R(f *encFnInfo, rv reflect.Value) { - fastpathETCborIO{}.EncMapUint64Uint8V(rv2i(rv).(map[uint64]uint8), e) -} -func (fastpathETCborIO) EncMapUint64Uint8V(v map[uint64]uint8, e *encoderCborIO) { - if len(v) == 0 { - e.e.WriteMapEmpty() - return - } - var i uint - e.mapStart(len(v)) - if e.h.Canonical { - v2 := make([]uint64, len(v)) - for k := range v { - v2[i] = k - i++ - } - slices.Sort(v2) - for i, k2 := range v2 { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeUint(k2) - e.mapElemValue() - e.e.EncodeUint(uint64(v[k2])) - } - } else { - i = 0 - for k2, v2 := range v { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeUint(k2) - e.mapElemValue() - e.e.EncodeUint(uint64(v2)) - i++ - } - } - e.c = 0 - e.e.WriteMapEnd() -} -func (e *encoderCborIO) fastpathEncMapUint64Uint64R(f *encFnInfo, rv reflect.Value) { - fastpathETCborIO{}.EncMapUint64Uint64V(rv2i(rv).(map[uint64]uint64), e) -} -func (fastpathETCborIO) EncMapUint64Uint64V(v map[uint64]uint64, e *encoderCborIO) { - if len(v) == 0 { - e.e.WriteMapEmpty() - return - } - var i uint - e.mapStart(len(v)) - if e.h.Canonical { - v2 := make([]uint64, len(v)) - for k := range v { - v2[i] = k - i++ - } - slices.Sort(v2) - for i, k2 := range v2 { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeUint(k2) - e.mapElemValue() - e.e.EncodeUint(v[k2]) - } - } else { - i = 0 - for k2, v2 := range v { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeUint(k2) - e.mapElemValue() - e.e.EncodeUint(v2) - i++ - } - } - e.c = 0 - e.e.WriteMapEnd() -} -func (e *encoderCborIO) fastpathEncMapUint64IntR(f *encFnInfo, rv reflect.Value) { - fastpathETCborIO{}.EncMapUint64IntV(rv2i(rv).(map[uint64]int), e) -} -func (fastpathETCborIO) EncMapUint64IntV(v map[uint64]int, e *encoderCborIO) { - if len(v) == 0 { - e.e.WriteMapEmpty() - return - } - var i uint - e.mapStart(len(v)) - if e.h.Canonical { - v2 := make([]uint64, len(v)) - for k := range v { - v2[i] = k - i++ - } - slices.Sort(v2) - for i, k2 := range v2 { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeUint(k2) - e.mapElemValue() - e.e.EncodeInt(int64(v[k2])) - } - } else { - i = 0 - for k2, v2 := range v { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeUint(k2) - e.mapElemValue() - e.e.EncodeInt(int64(v2)) - i++ - } - } - e.c = 0 - e.e.WriteMapEnd() -} -func (e *encoderCborIO) fastpathEncMapUint64Int32R(f *encFnInfo, rv reflect.Value) { - fastpathETCborIO{}.EncMapUint64Int32V(rv2i(rv).(map[uint64]int32), e) -} -func (fastpathETCborIO) EncMapUint64Int32V(v map[uint64]int32, e *encoderCborIO) { - if len(v) == 0 { - e.e.WriteMapEmpty() - return - } - var i uint - e.mapStart(len(v)) - if e.h.Canonical { - v2 := make([]uint64, len(v)) - for k := range v { - v2[i] = k - i++ - } - slices.Sort(v2) - for i, k2 := range v2 { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeUint(k2) - e.mapElemValue() - e.e.EncodeInt(int64(v[k2])) - } - } else { - i = 0 - for k2, v2 := range v { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeUint(k2) - e.mapElemValue() - e.e.EncodeInt(int64(v2)) - i++ - } - } - e.c = 0 - e.e.WriteMapEnd() -} -func (e *encoderCborIO) fastpathEncMapUint64Float64R(f *encFnInfo, rv reflect.Value) { - fastpathETCborIO{}.EncMapUint64Float64V(rv2i(rv).(map[uint64]float64), e) -} -func (fastpathETCborIO) EncMapUint64Float64V(v map[uint64]float64, e *encoderCborIO) { - if len(v) == 0 { - e.e.WriteMapEmpty() - return - } - var i uint - e.mapStart(len(v)) - if e.h.Canonical { - v2 := make([]uint64, len(v)) - for k := range v { - v2[i] = k - i++ - } - slices.Sort(v2) - for i, k2 := range v2 { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeUint(k2) - e.mapElemValue() - e.e.EncodeFloat64(v[k2]) - } - } else { - i = 0 - for k2, v2 := range v { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeUint(k2) - e.mapElemValue() - e.e.EncodeFloat64(v2) - i++ - } - } - e.c = 0 - e.e.WriteMapEnd() -} -func (e *encoderCborIO) fastpathEncMapUint64BoolR(f *encFnInfo, rv reflect.Value) { - fastpathETCborIO{}.EncMapUint64BoolV(rv2i(rv).(map[uint64]bool), e) -} -func (fastpathETCborIO) EncMapUint64BoolV(v map[uint64]bool, e *encoderCborIO) { - if len(v) == 0 { - e.e.WriteMapEmpty() - return - } - var i uint - e.mapStart(len(v)) - if e.h.Canonical { - v2 := make([]uint64, len(v)) - for k := range v { - v2[i] = k - i++ - } - slices.Sort(v2) - for i, k2 := range v2 { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeUint(k2) - e.mapElemValue() - e.e.EncodeBool(v[k2]) - } - } else { - i = 0 - for k2, v2 := range v { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeUint(k2) - e.mapElemValue() - e.e.EncodeBool(v2) - i++ - } - } - e.c = 0 - e.e.WriteMapEnd() -} -func (e *encoderCborIO) fastpathEncMapIntIntfR(f *encFnInfo, rv reflect.Value) { - fastpathETCborIO{}.EncMapIntIntfV(rv2i(rv).(map[int]interface{}), e) -} -func (fastpathETCborIO) EncMapIntIntfV(v map[int]interface{}, e *encoderCborIO) { - if len(v) == 0 { - e.e.WriteMapEmpty() - return - } - var i uint - e.mapStart(len(v)) - if e.h.Canonical { - v2 := make([]int, len(v)) - for k := range v { - v2[i] = k - i++ - } - slices.Sort(v2) - for i, k2 := range v2 { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeInt(int64(k2)) - e.mapElemValue() - if !e.encodeBuiltin(v[k2]) { - e.encodeR(reflect.ValueOf(v[k2])) - } - } - } else { - i = 0 - for k2, v2 := range v { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeInt(int64(k2)) - e.mapElemValue() - if !e.encodeBuiltin(v2) { - e.encodeR(reflect.ValueOf(v2)) - } - i++ - } - } - e.c = 0 - e.e.WriteMapEnd() -} -func (e *encoderCborIO) fastpathEncMapIntStringR(f *encFnInfo, rv reflect.Value) { - fastpathETCborIO{}.EncMapIntStringV(rv2i(rv).(map[int]string), e) -} -func (fastpathETCborIO) EncMapIntStringV(v map[int]string, e *encoderCborIO) { - if len(v) == 0 { - e.e.WriteMapEmpty() - return - } - var i uint - e.mapStart(len(v)) - if e.h.Canonical { - v2 := make([]int, len(v)) - for k := range v { - v2[i] = k - i++ - } - slices.Sort(v2) - for i, k2 := range v2 { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeInt(int64(k2)) - e.mapElemValue() - e.e.EncodeString(v[k2]) - } - } else { - i = 0 - for k2, v2 := range v { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeInt(int64(k2)) - e.mapElemValue() - e.e.EncodeString(v2) - i++ - } - } - e.c = 0 - e.e.WriteMapEnd() -} -func (e *encoderCborIO) fastpathEncMapIntBytesR(f *encFnInfo, rv reflect.Value) { - fastpathETCborIO{}.EncMapIntBytesV(rv2i(rv).(map[int][]byte), e) -} -func (fastpathETCborIO) EncMapIntBytesV(v map[int][]byte, e *encoderCborIO) { - if len(v) == 0 { - e.e.WriteMapEmpty() - return - } - var i uint - e.mapStart(len(v)) - if e.h.Canonical { - v2 := make([]int, len(v)) - for k := range v { - v2[i] = k - i++ - } - slices.Sort(v2) - for i, k2 := range v2 { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeInt(int64(k2)) - e.mapElemValue() - e.e.EncodeBytes(v[k2]) - } - } else { - i = 0 - for k2, v2 := range v { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeInt(int64(k2)) - e.mapElemValue() - e.e.EncodeBytes(v2) - i++ - } - } - e.c = 0 - e.e.WriteMapEnd() -} -func (e *encoderCborIO) fastpathEncMapIntUint8R(f *encFnInfo, rv reflect.Value) { - fastpathETCborIO{}.EncMapIntUint8V(rv2i(rv).(map[int]uint8), e) -} -func (fastpathETCborIO) EncMapIntUint8V(v map[int]uint8, e *encoderCborIO) { - if len(v) == 0 { - e.e.WriteMapEmpty() - return - } - var i uint - e.mapStart(len(v)) - if e.h.Canonical { - v2 := make([]int, len(v)) - for k := range v { - v2[i] = k - i++ - } - slices.Sort(v2) - for i, k2 := range v2 { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeInt(int64(k2)) - e.mapElemValue() - e.e.EncodeUint(uint64(v[k2])) - } - } else { - i = 0 - for k2, v2 := range v { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeInt(int64(k2)) - e.mapElemValue() - e.e.EncodeUint(uint64(v2)) - i++ - } - } - e.c = 0 - e.e.WriteMapEnd() -} -func (e *encoderCborIO) fastpathEncMapIntUint64R(f *encFnInfo, rv reflect.Value) { - fastpathETCborIO{}.EncMapIntUint64V(rv2i(rv).(map[int]uint64), e) -} -func (fastpathETCborIO) EncMapIntUint64V(v map[int]uint64, e *encoderCborIO) { - if len(v) == 0 { - e.e.WriteMapEmpty() - return - } - var i uint - e.mapStart(len(v)) - if e.h.Canonical { - v2 := make([]int, len(v)) - for k := range v { - v2[i] = k - i++ - } - slices.Sort(v2) - for i, k2 := range v2 { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeInt(int64(k2)) - e.mapElemValue() - e.e.EncodeUint(v[k2]) - } - } else { - i = 0 - for k2, v2 := range v { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeInt(int64(k2)) - e.mapElemValue() - e.e.EncodeUint(v2) - i++ - } - } - e.c = 0 - e.e.WriteMapEnd() -} -func (e *encoderCborIO) fastpathEncMapIntIntR(f *encFnInfo, rv reflect.Value) { - fastpathETCborIO{}.EncMapIntIntV(rv2i(rv).(map[int]int), e) -} -func (fastpathETCborIO) EncMapIntIntV(v map[int]int, e *encoderCborIO) { - if len(v) == 0 { - e.e.WriteMapEmpty() - return - } - var i uint - e.mapStart(len(v)) - if e.h.Canonical { - v2 := make([]int, len(v)) - for k := range v { - v2[i] = k - i++ - } - slices.Sort(v2) - for i, k2 := range v2 { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeInt(int64(k2)) - e.mapElemValue() - e.e.EncodeInt(int64(v[k2])) - } - } else { - i = 0 - for k2, v2 := range v { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeInt(int64(k2)) - e.mapElemValue() - e.e.EncodeInt(int64(v2)) - i++ - } - } - e.c = 0 - e.e.WriteMapEnd() -} -func (e *encoderCborIO) fastpathEncMapIntInt32R(f *encFnInfo, rv reflect.Value) { - fastpathETCborIO{}.EncMapIntInt32V(rv2i(rv).(map[int]int32), e) -} -func (fastpathETCborIO) EncMapIntInt32V(v map[int]int32, e *encoderCborIO) { - if len(v) == 0 { - e.e.WriteMapEmpty() - return - } - var i uint - e.mapStart(len(v)) - if e.h.Canonical { - v2 := make([]int, len(v)) - for k := range v { - v2[i] = k - i++ - } - slices.Sort(v2) - for i, k2 := range v2 { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeInt(int64(k2)) - e.mapElemValue() - e.e.EncodeInt(int64(v[k2])) - } - } else { - i = 0 - for k2, v2 := range v { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeInt(int64(k2)) - e.mapElemValue() - e.e.EncodeInt(int64(v2)) - i++ - } - } - e.c = 0 - e.e.WriteMapEnd() -} -func (e *encoderCborIO) fastpathEncMapIntFloat64R(f *encFnInfo, rv reflect.Value) { - fastpathETCborIO{}.EncMapIntFloat64V(rv2i(rv).(map[int]float64), e) -} -func (fastpathETCborIO) EncMapIntFloat64V(v map[int]float64, e *encoderCborIO) { - if len(v) == 0 { - e.e.WriteMapEmpty() - return - } - var i uint - e.mapStart(len(v)) - if e.h.Canonical { - v2 := make([]int, len(v)) - for k := range v { - v2[i] = k - i++ - } - slices.Sort(v2) - for i, k2 := range v2 { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeInt(int64(k2)) - e.mapElemValue() - e.e.EncodeFloat64(v[k2]) - } - } else { - i = 0 - for k2, v2 := range v { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeInt(int64(k2)) - e.mapElemValue() - e.e.EncodeFloat64(v2) - i++ - } - } - e.c = 0 - e.e.WriteMapEnd() -} -func (e *encoderCborIO) fastpathEncMapIntBoolR(f *encFnInfo, rv reflect.Value) { - fastpathETCborIO{}.EncMapIntBoolV(rv2i(rv).(map[int]bool), e) -} -func (fastpathETCborIO) EncMapIntBoolV(v map[int]bool, e *encoderCborIO) { - if len(v) == 0 { - e.e.WriteMapEmpty() - return - } - var i uint - e.mapStart(len(v)) - if e.h.Canonical { - v2 := make([]int, len(v)) - for k := range v { - v2[i] = k - i++ - } - slices.Sort(v2) - for i, k2 := range v2 { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeInt(int64(k2)) - e.mapElemValue() - e.e.EncodeBool(v[k2]) - } - } else { - i = 0 - for k2, v2 := range v { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeInt(int64(k2)) - e.mapElemValue() - e.e.EncodeBool(v2) - i++ - } - } - e.c = 0 - e.e.WriteMapEnd() -} -func (e *encoderCborIO) fastpathEncMapInt32IntfR(f *encFnInfo, rv reflect.Value) { - fastpathETCborIO{}.EncMapInt32IntfV(rv2i(rv).(map[int32]interface{}), e) -} -func (fastpathETCborIO) EncMapInt32IntfV(v map[int32]interface{}, e *encoderCborIO) { - if len(v) == 0 { - e.e.WriteMapEmpty() - return - } - var i uint - e.mapStart(len(v)) - if e.h.Canonical { - v2 := make([]int32, len(v)) - for k := range v { - v2[i] = k - i++ - } - slices.Sort(v2) - for i, k2 := range v2 { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeInt(int64(k2)) - e.mapElemValue() - if !e.encodeBuiltin(v[k2]) { - e.encodeR(reflect.ValueOf(v[k2])) - } - } - } else { - i = 0 - for k2, v2 := range v { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeInt(int64(k2)) - e.mapElemValue() - if !e.encodeBuiltin(v2) { - e.encodeR(reflect.ValueOf(v2)) - } - i++ - } - } - e.c = 0 - e.e.WriteMapEnd() -} -func (e *encoderCborIO) fastpathEncMapInt32StringR(f *encFnInfo, rv reflect.Value) { - fastpathETCborIO{}.EncMapInt32StringV(rv2i(rv).(map[int32]string), e) -} -func (fastpathETCborIO) EncMapInt32StringV(v map[int32]string, e *encoderCborIO) { - if len(v) == 0 { - e.e.WriteMapEmpty() - return - } - var i uint - e.mapStart(len(v)) - if e.h.Canonical { - v2 := make([]int32, len(v)) - for k := range v { - v2[i] = k - i++ - } - slices.Sort(v2) - for i, k2 := range v2 { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeInt(int64(k2)) - e.mapElemValue() - e.e.EncodeString(v[k2]) - } - } else { - i = 0 - for k2, v2 := range v { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeInt(int64(k2)) - e.mapElemValue() - e.e.EncodeString(v2) - i++ - } - } - e.c = 0 - e.e.WriteMapEnd() -} -func (e *encoderCborIO) fastpathEncMapInt32BytesR(f *encFnInfo, rv reflect.Value) { - fastpathETCborIO{}.EncMapInt32BytesV(rv2i(rv).(map[int32][]byte), e) -} -func (fastpathETCborIO) EncMapInt32BytesV(v map[int32][]byte, e *encoderCborIO) { - if len(v) == 0 { - e.e.WriteMapEmpty() - return - } - var i uint - e.mapStart(len(v)) - if e.h.Canonical { - v2 := make([]int32, len(v)) - for k := range v { - v2[i] = k - i++ - } - slices.Sort(v2) - for i, k2 := range v2 { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeInt(int64(k2)) - e.mapElemValue() - e.e.EncodeBytes(v[k2]) - } - } else { - i = 0 - for k2, v2 := range v { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeInt(int64(k2)) - e.mapElemValue() - e.e.EncodeBytes(v2) - i++ - } - } - e.c = 0 - e.e.WriteMapEnd() -} -func (e *encoderCborIO) fastpathEncMapInt32Uint8R(f *encFnInfo, rv reflect.Value) { - fastpathETCborIO{}.EncMapInt32Uint8V(rv2i(rv).(map[int32]uint8), e) -} -func (fastpathETCborIO) EncMapInt32Uint8V(v map[int32]uint8, e *encoderCborIO) { - if len(v) == 0 { - e.e.WriteMapEmpty() - return - } - var i uint - e.mapStart(len(v)) - if e.h.Canonical { - v2 := make([]int32, len(v)) - for k := range v { - v2[i] = k - i++ - } - slices.Sort(v2) - for i, k2 := range v2 { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeInt(int64(k2)) - e.mapElemValue() - e.e.EncodeUint(uint64(v[k2])) - } - } else { - i = 0 - for k2, v2 := range v { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeInt(int64(k2)) - e.mapElemValue() - e.e.EncodeUint(uint64(v2)) - i++ - } - } - e.c = 0 - e.e.WriteMapEnd() -} -func (e *encoderCborIO) fastpathEncMapInt32Uint64R(f *encFnInfo, rv reflect.Value) { - fastpathETCborIO{}.EncMapInt32Uint64V(rv2i(rv).(map[int32]uint64), e) -} -func (fastpathETCborIO) EncMapInt32Uint64V(v map[int32]uint64, e *encoderCborIO) { - if len(v) == 0 { - e.e.WriteMapEmpty() - return - } - var i uint - e.mapStart(len(v)) - if e.h.Canonical { - v2 := make([]int32, len(v)) - for k := range v { - v2[i] = k - i++ - } - slices.Sort(v2) - for i, k2 := range v2 { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeInt(int64(k2)) - e.mapElemValue() - e.e.EncodeUint(v[k2]) - } - } else { - i = 0 - for k2, v2 := range v { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeInt(int64(k2)) - e.mapElemValue() - e.e.EncodeUint(v2) - i++ - } - } - e.c = 0 - e.e.WriteMapEnd() -} -func (e *encoderCborIO) fastpathEncMapInt32IntR(f *encFnInfo, rv reflect.Value) { - fastpathETCborIO{}.EncMapInt32IntV(rv2i(rv).(map[int32]int), e) -} -func (fastpathETCborIO) EncMapInt32IntV(v map[int32]int, e *encoderCborIO) { - if len(v) == 0 { - e.e.WriteMapEmpty() - return - } - var i uint - e.mapStart(len(v)) - if e.h.Canonical { - v2 := make([]int32, len(v)) - for k := range v { - v2[i] = k - i++ - } - slices.Sort(v2) - for i, k2 := range v2 { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeInt(int64(k2)) - e.mapElemValue() - e.e.EncodeInt(int64(v[k2])) - } - } else { - i = 0 - for k2, v2 := range v { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeInt(int64(k2)) - e.mapElemValue() - e.e.EncodeInt(int64(v2)) - i++ - } - } - e.c = 0 - e.e.WriteMapEnd() -} -func (e *encoderCborIO) fastpathEncMapInt32Int32R(f *encFnInfo, rv reflect.Value) { - fastpathETCborIO{}.EncMapInt32Int32V(rv2i(rv).(map[int32]int32), e) -} -func (fastpathETCborIO) EncMapInt32Int32V(v map[int32]int32, e *encoderCborIO) { - if len(v) == 0 { - e.e.WriteMapEmpty() - return - } - var i uint - e.mapStart(len(v)) - if e.h.Canonical { - v2 := make([]int32, len(v)) - for k := range v { - v2[i] = k - i++ - } - slices.Sort(v2) - for i, k2 := range v2 { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeInt(int64(k2)) - e.mapElemValue() - e.e.EncodeInt(int64(v[k2])) - } - } else { - i = 0 - for k2, v2 := range v { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeInt(int64(k2)) - e.mapElemValue() - e.e.EncodeInt(int64(v2)) - i++ - } - } - e.c = 0 - e.e.WriteMapEnd() -} -func (e *encoderCborIO) fastpathEncMapInt32Float64R(f *encFnInfo, rv reflect.Value) { - fastpathETCborIO{}.EncMapInt32Float64V(rv2i(rv).(map[int32]float64), e) -} -func (fastpathETCborIO) EncMapInt32Float64V(v map[int32]float64, e *encoderCborIO) { - if len(v) == 0 { - e.e.WriteMapEmpty() - return - } - var i uint - e.mapStart(len(v)) - if e.h.Canonical { - v2 := make([]int32, len(v)) - for k := range v { - v2[i] = k - i++ - } - slices.Sort(v2) - for i, k2 := range v2 { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeInt(int64(k2)) - e.mapElemValue() - e.e.EncodeFloat64(v[k2]) - } - } else { - i = 0 - for k2, v2 := range v { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeInt(int64(k2)) - e.mapElemValue() - e.e.EncodeFloat64(v2) - i++ - } - } - e.c = 0 - e.e.WriteMapEnd() -} -func (e *encoderCborIO) fastpathEncMapInt32BoolR(f *encFnInfo, rv reflect.Value) { - fastpathETCborIO{}.EncMapInt32BoolV(rv2i(rv).(map[int32]bool), e) -} -func (fastpathETCborIO) EncMapInt32BoolV(v map[int32]bool, e *encoderCborIO) { - if len(v) == 0 { - e.e.WriteMapEmpty() - return - } - var i uint - e.mapStart(len(v)) - if e.h.Canonical { - v2 := make([]int32, len(v)) - for k := range v { - v2[i] = k - i++ - } - slices.Sort(v2) - for i, k2 := range v2 { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeInt(int64(k2)) - e.mapElemValue() - e.e.EncodeBool(v[k2]) - } - } else { - i = 0 - for k2, v2 := range v { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeInt(int64(k2)) - e.mapElemValue() - e.e.EncodeBool(v2) - i++ - } - } - e.c = 0 - e.e.WriteMapEnd() -} - -func (helperDecDriverCborIO) fastpathDecodeTypeSwitch(iv interface{}, d *decoderCborIO) bool { - var ft fastpathDTCborIO - var changed bool - var containerLen int - switch v := iv.(type) { - case []interface{}: - ft.DecSliceIntfN(v, d) - case *[]interface{}: - var v2 []interface{} - if v2, changed = ft.DecSliceIntfY(*v, d); changed { - *v = v2 - } - case []string: - ft.DecSliceStringN(v, d) - case *[]string: - var v2 []string - if v2, changed = ft.DecSliceStringY(*v, d); changed { - *v = v2 - } - case [][]byte: - ft.DecSliceBytesN(v, d) - case *[][]byte: - var v2 [][]byte - if v2, changed = ft.DecSliceBytesY(*v, d); changed { - *v = v2 - } - case []float32: - ft.DecSliceFloat32N(v, d) - case *[]float32: - var v2 []float32 - if v2, changed = ft.DecSliceFloat32Y(*v, d); changed { - *v = v2 - } - case []float64: - ft.DecSliceFloat64N(v, d) - case *[]float64: - var v2 []float64 - if v2, changed = ft.DecSliceFloat64Y(*v, d); changed { - *v = v2 - } - case []uint8: - ft.DecSliceUint8N(v, d) - case *[]uint8: - var v2 []uint8 - if v2, changed = ft.DecSliceUint8Y(*v, d); changed { - *v = v2 - } - case []uint64: - ft.DecSliceUint64N(v, d) - case *[]uint64: - var v2 []uint64 - if v2, changed = ft.DecSliceUint64Y(*v, d); changed { - *v = v2 - } - case []int: - ft.DecSliceIntN(v, d) - case *[]int: - var v2 []int - if v2, changed = ft.DecSliceIntY(*v, d); changed { - *v = v2 - } - case []int32: - ft.DecSliceInt32N(v, d) - case *[]int32: - var v2 []int32 - if v2, changed = ft.DecSliceInt32Y(*v, d); changed { - *v = v2 - } - case []int64: - ft.DecSliceInt64N(v, d) - case *[]int64: - var v2 []int64 - if v2, changed = ft.DecSliceInt64Y(*v, d); changed { - *v = v2 - } - case []bool: - ft.DecSliceBoolN(v, d) - case *[]bool: - var v2 []bool - if v2, changed = ft.DecSliceBoolY(*v, d); changed { - *v = v2 - } - case map[string]interface{}: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen != containerLenNil { - if containerLen != 0 { - ft.DecMapStringIntfL(v, containerLen, d) - } - d.mapEnd() - } - case *map[string]interface{}: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen == containerLenNil { - *v = nil - } else { - if *v == nil { - *v = make(map[string]interface{}, decInferLen(containerLen, d.maxInitLen(), 32)) - } - if containerLen != 0 { - ft.DecMapStringIntfL(*v, containerLen, d) - } - d.mapEnd() - } - case map[string]string: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen != containerLenNil { - if containerLen != 0 { - ft.DecMapStringStringL(v, containerLen, d) - } - d.mapEnd() - } - case *map[string]string: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen == containerLenNil { - *v = nil - } else { - if *v == nil { - *v = make(map[string]string, decInferLen(containerLen, d.maxInitLen(), 32)) - } - if containerLen != 0 { - ft.DecMapStringStringL(*v, containerLen, d) - } - d.mapEnd() - } - case map[string][]byte: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen != containerLenNil { - if containerLen != 0 { - ft.DecMapStringBytesL(v, containerLen, d) - } - d.mapEnd() - } - case *map[string][]byte: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen == containerLenNil { - *v = nil - } else { - if *v == nil { - *v = make(map[string][]byte, decInferLen(containerLen, d.maxInitLen(), 40)) - } - if containerLen != 0 { - ft.DecMapStringBytesL(*v, containerLen, d) - } - d.mapEnd() - } - case map[string]uint8: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen != containerLenNil { - if containerLen != 0 { - ft.DecMapStringUint8L(v, containerLen, d) - } - d.mapEnd() - } - case *map[string]uint8: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen == containerLenNil { - *v = nil - } else { - if *v == nil { - *v = make(map[string]uint8, decInferLen(containerLen, d.maxInitLen(), 17)) - } - if containerLen != 0 { - ft.DecMapStringUint8L(*v, containerLen, d) - } - d.mapEnd() - } - case map[string]uint64: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen != containerLenNil { - if containerLen != 0 { - ft.DecMapStringUint64L(v, containerLen, d) - } - d.mapEnd() - } - case *map[string]uint64: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen == containerLenNil { - *v = nil - } else { - if *v == nil { - *v = make(map[string]uint64, decInferLen(containerLen, d.maxInitLen(), 24)) - } - if containerLen != 0 { - ft.DecMapStringUint64L(*v, containerLen, d) - } - d.mapEnd() - } - case map[string]int: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen != containerLenNil { - if containerLen != 0 { - ft.DecMapStringIntL(v, containerLen, d) - } - d.mapEnd() - } - case *map[string]int: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen == containerLenNil { - *v = nil - } else { - if *v == nil { - *v = make(map[string]int, decInferLen(containerLen, d.maxInitLen(), 24)) - } - if containerLen != 0 { - ft.DecMapStringIntL(*v, containerLen, d) - } - d.mapEnd() - } - case map[string]int32: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen != containerLenNil { - if containerLen != 0 { - ft.DecMapStringInt32L(v, containerLen, d) - } - d.mapEnd() - } - case *map[string]int32: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen == containerLenNil { - *v = nil - } else { - if *v == nil { - *v = make(map[string]int32, decInferLen(containerLen, d.maxInitLen(), 20)) - } - if containerLen != 0 { - ft.DecMapStringInt32L(*v, containerLen, d) - } - d.mapEnd() - } - case map[string]float64: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen != containerLenNil { - if containerLen != 0 { - ft.DecMapStringFloat64L(v, containerLen, d) - } - d.mapEnd() - } - case *map[string]float64: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen == containerLenNil { - *v = nil - } else { - if *v == nil { - *v = make(map[string]float64, decInferLen(containerLen, d.maxInitLen(), 24)) - } - if containerLen != 0 { - ft.DecMapStringFloat64L(*v, containerLen, d) - } - d.mapEnd() - } - case map[string]bool: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen != containerLenNil { - if containerLen != 0 { - ft.DecMapStringBoolL(v, containerLen, d) - } - d.mapEnd() - } - case *map[string]bool: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen == containerLenNil { - *v = nil - } else { - if *v == nil { - *v = make(map[string]bool, decInferLen(containerLen, d.maxInitLen(), 17)) - } - if containerLen != 0 { - ft.DecMapStringBoolL(*v, containerLen, d) - } - d.mapEnd() - } - case map[uint8]interface{}: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen != containerLenNil { - if containerLen != 0 { - ft.DecMapUint8IntfL(v, containerLen, d) - } - d.mapEnd() - } - case *map[uint8]interface{}: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen == containerLenNil { - *v = nil - } else { - if *v == nil { - *v = make(map[uint8]interface{}, decInferLen(containerLen, d.maxInitLen(), 17)) - } - if containerLen != 0 { - ft.DecMapUint8IntfL(*v, containerLen, d) - } - d.mapEnd() - } - case map[uint8]string: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen != containerLenNil { - if containerLen != 0 { - ft.DecMapUint8StringL(v, containerLen, d) - } - d.mapEnd() - } - case *map[uint8]string: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen == containerLenNil { - *v = nil - } else { - if *v == nil { - *v = make(map[uint8]string, decInferLen(containerLen, d.maxInitLen(), 17)) - } - if containerLen != 0 { - ft.DecMapUint8StringL(*v, containerLen, d) - } - d.mapEnd() - } - case map[uint8][]byte: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen != containerLenNil { - if containerLen != 0 { - ft.DecMapUint8BytesL(v, containerLen, d) - } - d.mapEnd() - } - case *map[uint8][]byte: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen == containerLenNil { - *v = nil - } else { - if *v == nil { - *v = make(map[uint8][]byte, decInferLen(containerLen, d.maxInitLen(), 25)) - } - if containerLen != 0 { - ft.DecMapUint8BytesL(*v, containerLen, d) - } - d.mapEnd() - } - case map[uint8]uint8: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen != containerLenNil { - if containerLen != 0 { - ft.DecMapUint8Uint8L(v, containerLen, d) - } - d.mapEnd() - } - case *map[uint8]uint8: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen == containerLenNil { - *v = nil - } else { - if *v == nil { - *v = make(map[uint8]uint8, decInferLen(containerLen, d.maxInitLen(), 2)) - } - if containerLen != 0 { - ft.DecMapUint8Uint8L(*v, containerLen, d) - } - d.mapEnd() - } - case map[uint8]uint64: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen != containerLenNil { - if containerLen != 0 { - ft.DecMapUint8Uint64L(v, containerLen, d) - } - d.mapEnd() - } - case *map[uint8]uint64: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen == containerLenNil { - *v = nil - } else { - if *v == nil { - *v = make(map[uint8]uint64, decInferLen(containerLen, d.maxInitLen(), 9)) - } - if containerLen != 0 { - ft.DecMapUint8Uint64L(*v, containerLen, d) - } - d.mapEnd() - } - case map[uint8]int: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen != containerLenNil { - if containerLen != 0 { - ft.DecMapUint8IntL(v, containerLen, d) - } - d.mapEnd() - } - case *map[uint8]int: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen == containerLenNil { - *v = nil - } else { - if *v == nil { - *v = make(map[uint8]int, decInferLen(containerLen, d.maxInitLen(), 9)) - } - if containerLen != 0 { - ft.DecMapUint8IntL(*v, containerLen, d) - } - d.mapEnd() - } - case map[uint8]int32: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen != containerLenNil { - if containerLen != 0 { - ft.DecMapUint8Int32L(v, containerLen, d) - } - d.mapEnd() - } - case *map[uint8]int32: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen == containerLenNil { - *v = nil - } else { - if *v == nil { - *v = make(map[uint8]int32, decInferLen(containerLen, d.maxInitLen(), 5)) - } - if containerLen != 0 { - ft.DecMapUint8Int32L(*v, containerLen, d) - } - d.mapEnd() - } - case map[uint8]float64: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen != containerLenNil { - if containerLen != 0 { - ft.DecMapUint8Float64L(v, containerLen, d) - } - d.mapEnd() - } - case *map[uint8]float64: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen == containerLenNil { - *v = nil - } else { - if *v == nil { - *v = make(map[uint8]float64, decInferLen(containerLen, d.maxInitLen(), 9)) - } - if containerLen != 0 { - ft.DecMapUint8Float64L(*v, containerLen, d) - } - d.mapEnd() - } - case map[uint8]bool: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen != containerLenNil { - if containerLen != 0 { - ft.DecMapUint8BoolL(v, containerLen, d) - } - d.mapEnd() - } - case *map[uint8]bool: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen == containerLenNil { - *v = nil - } else { - if *v == nil { - *v = make(map[uint8]bool, decInferLen(containerLen, d.maxInitLen(), 2)) - } - if containerLen != 0 { - ft.DecMapUint8BoolL(*v, containerLen, d) - } - d.mapEnd() - } - case map[uint64]interface{}: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen != containerLenNil { - if containerLen != 0 { - ft.DecMapUint64IntfL(v, containerLen, d) - } - d.mapEnd() - } - case *map[uint64]interface{}: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen == containerLenNil { - *v = nil - } else { - if *v == nil { - *v = make(map[uint64]interface{}, decInferLen(containerLen, d.maxInitLen(), 24)) - } - if containerLen != 0 { - ft.DecMapUint64IntfL(*v, containerLen, d) - } - d.mapEnd() - } - case map[uint64]string: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen != containerLenNil { - if containerLen != 0 { - ft.DecMapUint64StringL(v, containerLen, d) - } - d.mapEnd() - } - case *map[uint64]string: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen == containerLenNil { - *v = nil - } else { - if *v == nil { - *v = make(map[uint64]string, decInferLen(containerLen, d.maxInitLen(), 24)) - } - if containerLen != 0 { - ft.DecMapUint64StringL(*v, containerLen, d) - } - d.mapEnd() - } - case map[uint64][]byte: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen != containerLenNil { - if containerLen != 0 { - ft.DecMapUint64BytesL(v, containerLen, d) - } - d.mapEnd() - } - case *map[uint64][]byte: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen == containerLenNil { - *v = nil - } else { - if *v == nil { - *v = make(map[uint64][]byte, decInferLen(containerLen, d.maxInitLen(), 32)) - } - if containerLen != 0 { - ft.DecMapUint64BytesL(*v, containerLen, d) - } - d.mapEnd() - } - case map[uint64]uint8: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen != containerLenNil { - if containerLen != 0 { - ft.DecMapUint64Uint8L(v, containerLen, d) - } - d.mapEnd() - } - case *map[uint64]uint8: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen == containerLenNil { - *v = nil - } else { - if *v == nil { - *v = make(map[uint64]uint8, decInferLen(containerLen, d.maxInitLen(), 9)) - } - if containerLen != 0 { - ft.DecMapUint64Uint8L(*v, containerLen, d) - } - d.mapEnd() - } - case map[uint64]uint64: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen != containerLenNil { - if containerLen != 0 { - ft.DecMapUint64Uint64L(v, containerLen, d) - } - d.mapEnd() - } - case *map[uint64]uint64: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen == containerLenNil { - *v = nil - } else { - if *v == nil { - *v = make(map[uint64]uint64, decInferLen(containerLen, d.maxInitLen(), 16)) - } - if containerLen != 0 { - ft.DecMapUint64Uint64L(*v, containerLen, d) - } - d.mapEnd() - } - case map[uint64]int: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen != containerLenNil { - if containerLen != 0 { - ft.DecMapUint64IntL(v, containerLen, d) - } - d.mapEnd() - } - case *map[uint64]int: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen == containerLenNil { - *v = nil - } else { - if *v == nil { - *v = make(map[uint64]int, decInferLen(containerLen, d.maxInitLen(), 16)) - } - if containerLen != 0 { - ft.DecMapUint64IntL(*v, containerLen, d) - } - d.mapEnd() - } - case map[uint64]int32: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen != containerLenNil { - if containerLen != 0 { - ft.DecMapUint64Int32L(v, containerLen, d) - } - d.mapEnd() - } - case *map[uint64]int32: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen == containerLenNil { - *v = nil - } else { - if *v == nil { - *v = make(map[uint64]int32, decInferLen(containerLen, d.maxInitLen(), 12)) - } - if containerLen != 0 { - ft.DecMapUint64Int32L(*v, containerLen, d) - } - d.mapEnd() - } - case map[uint64]float64: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen != containerLenNil { - if containerLen != 0 { - ft.DecMapUint64Float64L(v, containerLen, d) - } - d.mapEnd() - } - case *map[uint64]float64: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen == containerLenNil { - *v = nil - } else { - if *v == nil { - *v = make(map[uint64]float64, decInferLen(containerLen, d.maxInitLen(), 16)) - } - if containerLen != 0 { - ft.DecMapUint64Float64L(*v, containerLen, d) - } - d.mapEnd() - } - case map[uint64]bool: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen != containerLenNil { - if containerLen != 0 { - ft.DecMapUint64BoolL(v, containerLen, d) - } - d.mapEnd() - } - case *map[uint64]bool: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen == containerLenNil { - *v = nil - } else { - if *v == nil { - *v = make(map[uint64]bool, decInferLen(containerLen, d.maxInitLen(), 9)) - } - if containerLen != 0 { - ft.DecMapUint64BoolL(*v, containerLen, d) - } - d.mapEnd() - } - case map[int]interface{}: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen != containerLenNil { - if containerLen != 0 { - ft.DecMapIntIntfL(v, containerLen, d) - } - d.mapEnd() - } - case *map[int]interface{}: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen == containerLenNil { - *v = nil - } else { - if *v == nil { - *v = make(map[int]interface{}, decInferLen(containerLen, d.maxInitLen(), 24)) - } - if containerLen != 0 { - ft.DecMapIntIntfL(*v, containerLen, d) - } - d.mapEnd() - } - case map[int]string: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen != containerLenNil { - if containerLen != 0 { - ft.DecMapIntStringL(v, containerLen, d) - } - d.mapEnd() - } - case *map[int]string: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen == containerLenNil { - *v = nil - } else { - if *v == nil { - *v = make(map[int]string, decInferLen(containerLen, d.maxInitLen(), 24)) - } - if containerLen != 0 { - ft.DecMapIntStringL(*v, containerLen, d) - } - d.mapEnd() - } - case map[int][]byte: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen != containerLenNil { - if containerLen != 0 { - ft.DecMapIntBytesL(v, containerLen, d) - } - d.mapEnd() - } - case *map[int][]byte: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen == containerLenNil { - *v = nil - } else { - if *v == nil { - *v = make(map[int][]byte, decInferLen(containerLen, d.maxInitLen(), 32)) - } - if containerLen != 0 { - ft.DecMapIntBytesL(*v, containerLen, d) - } - d.mapEnd() - } - case map[int]uint8: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen != containerLenNil { - if containerLen != 0 { - ft.DecMapIntUint8L(v, containerLen, d) - } - d.mapEnd() - } - case *map[int]uint8: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen == containerLenNil { - *v = nil - } else { - if *v == nil { - *v = make(map[int]uint8, decInferLen(containerLen, d.maxInitLen(), 9)) - } - if containerLen != 0 { - ft.DecMapIntUint8L(*v, containerLen, d) - } - d.mapEnd() - } - case map[int]uint64: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen != containerLenNil { - if containerLen != 0 { - ft.DecMapIntUint64L(v, containerLen, d) - } - d.mapEnd() - } - case *map[int]uint64: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen == containerLenNil { - *v = nil - } else { - if *v == nil { - *v = make(map[int]uint64, decInferLen(containerLen, d.maxInitLen(), 16)) - } - if containerLen != 0 { - ft.DecMapIntUint64L(*v, containerLen, d) - } - d.mapEnd() - } - case map[int]int: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen != containerLenNil { - if containerLen != 0 { - ft.DecMapIntIntL(v, containerLen, d) - } - d.mapEnd() - } - case *map[int]int: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen == containerLenNil { - *v = nil - } else { - if *v == nil { - *v = make(map[int]int, decInferLen(containerLen, d.maxInitLen(), 16)) - } - if containerLen != 0 { - ft.DecMapIntIntL(*v, containerLen, d) - } - d.mapEnd() - } - case map[int]int32: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen != containerLenNil { - if containerLen != 0 { - ft.DecMapIntInt32L(v, containerLen, d) - } - d.mapEnd() - } - case *map[int]int32: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen == containerLenNil { - *v = nil - } else { - if *v == nil { - *v = make(map[int]int32, decInferLen(containerLen, d.maxInitLen(), 12)) - } - if containerLen != 0 { - ft.DecMapIntInt32L(*v, containerLen, d) - } - d.mapEnd() - } - case map[int]float64: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen != containerLenNil { - if containerLen != 0 { - ft.DecMapIntFloat64L(v, containerLen, d) - } - d.mapEnd() - } - case *map[int]float64: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen == containerLenNil { - *v = nil - } else { - if *v == nil { - *v = make(map[int]float64, decInferLen(containerLen, d.maxInitLen(), 16)) - } - if containerLen != 0 { - ft.DecMapIntFloat64L(*v, containerLen, d) - } - d.mapEnd() - } - case map[int]bool: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen != containerLenNil { - if containerLen != 0 { - ft.DecMapIntBoolL(v, containerLen, d) - } - d.mapEnd() - } - case *map[int]bool: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen == containerLenNil { - *v = nil - } else { - if *v == nil { - *v = make(map[int]bool, decInferLen(containerLen, d.maxInitLen(), 9)) - } - if containerLen != 0 { - ft.DecMapIntBoolL(*v, containerLen, d) - } - d.mapEnd() - } - case map[int32]interface{}: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen != containerLenNil { - if containerLen != 0 { - ft.DecMapInt32IntfL(v, containerLen, d) - } - d.mapEnd() - } - case *map[int32]interface{}: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen == containerLenNil { - *v = nil - } else { - if *v == nil { - *v = make(map[int32]interface{}, decInferLen(containerLen, d.maxInitLen(), 20)) - } - if containerLen != 0 { - ft.DecMapInt32IntfL(*v, containerLen, d) - } - d.mapEnd() - } - case map[int32]string: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen != containerLenNil { - if containerLen != 0 { - ft.DecMapInt32StringL(v, containerLen, d) - } - d.mapEnd() - } - case *map[int32]string: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen == containerLenNil { - *v = nil - } else { - if *v == nil { - *v = make(map[int32]string, decInferLen(containerLen, d.maxInitLen(), 20)) - } - if containerLen != 0 { - ft.DecMapInt32StringL(*v, containerLen, d) - } - d.mapEnd() - } - case map[int32][]byte: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen != containerLenNil { - if containerLen != 0 { - ft.DecMapInt32BytesL(v, containerLen, d) - } - d.mapEnd() - } - case *map[int32][]byte: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen == containerLenNil { - *v = nil - } else { - if *v == nil { - *v = make(map[int32][]byte, decInferLen(containerLen, d.maxInitLen(), 28)) - } - if containerLen != 0 { - ft.DecMapInt32BytesL(*v, containerLen, d) - } - d.mapEnd() - } - case map[int32]uint8: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen != containerLenNil { - if containerLen != 0 { - ft.DecMapInt32Uint8L(v, containerLen, d) - } - d.mapEnd() - } - case *map[int32]uint8: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen == containerLenNil { - *v = nil - } else { - if *v == nil { - *v = make(map[int32]uint8, decInferLen(containerLen, d.maxInitLen(), 5)) - } - if containerLen != 0 { - ft.DecMapInt32Uint8L(*v, containerLen, d) - } - d.mapEnd() - } - case map[int32]uint64: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen != containerLenNil { - if containerLen != 0 { - ft.DecMapInt32Uint64L(v, containerLen, d) - } - d.mapEnd() - } - case *map[int32]uint64: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen == containerLenNil { - *v = nil - } else { - if *v == nil { - *v = make(map[int32]uint64, decInferLen(containerLen, d.maxInitLen(), 12)) - } - if containerLen != 0 { - ft.DecMapInt32Uint64L(*v, containerLen, d) - } - d.mapEnd() - } - case map[int32]int: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen != containerLenNil { - if containerLen != 0 { - ft.DecMapInt32IntL(v, containerLen, d) - } - d.mapEnd() - } - case *map[int32]int: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen == containerLenNil { - *v = nil - } else { - if *v == nil { - *v = make(map[int32]int, decInferLen(containerLen, d.maxInitLen(), 12)) - } - if containerLen != 0 { - ft.DecMapInt32IntL(*v, containerLen, d) - } - d.mapEnd() - } - case map[int32]int32: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen != containerLenNil { - if containerLen != 0 { - ft.DecMapInt32Int32L(v, containerLen, d) - } - d.mapEnd() - } - case *map[int32]int32: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen == containerLenNil { - *v = nil - } else { - if *v == nil { - *v = make(map[int32]int32, decInferLen(containerLen, d.maxInitLen(), 8)) - } - if containerLen != 0 { - ft.DecMapInt32Int32L(*v, containerLen, d) - } - d.mapEnd() - } - case map[int32]float64: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen != containerLenNil { - if containerLen != 0 { - ft.DecMapInt32Float64L(v, containerLen, d) - } - d.mapEnd() - } - case *map[int32]float64: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen == containerLenNil { - *v = nil - } else { - if *v == nil { - *v = make(map[int32]float64, decInferLen(containerLen, d.maxInitLen(), 12)) - } - if containerLen != 0 { - ft.DecMapInt32Float64L(*v, containerLen, d) - } - d.mapEnd() - } - case map[int32]bool: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen != containerLenNil { - if containerLen != 0 { - ft.DecMapInt32BoolL(v, containerLen, d) - } - d.mapEnd() - } - case *map[int32]bool: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen == containerLenNil { - *v = nil - } else { - if *v == nil { - *v = make(map[int32]bool, decInferLen(containerLen, d.maxInitLen(), 5)) - } - if containerLen != 0 { - ft.DecMapInt32BoolL(*v, containerLen, d) - } - d.mapEnd() - } - default: - _ = v - return false - } - return true -} - -func (d *decoderCborIO) fastpathDecSliceIntfR(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTCborIO - switch rv.Kind() { - case reflect.Ptr: - v := rv2i(rv).(*[]interface{}) - if vv, changed := ft.DecSliceIntfY(*v, d); changed { - *v = vv - } - case reflect.Array: - var v []interface{} - rvGetSlice4Array(rv, &v) - ft.DecSliceIntfN(v, d) - default: - ft.DecSliceIntfN(rv2i(rv).([]interface{}), d) - } -} -func (fastpathDTCborIO) DecSliceIntfY(v []interface{}, d *decoderCborIO) (v2 []interface{}, changed bool) { - ctyp := d.d.ContainerType() - if ctyp == valueTypeNil { - return nil, v != nil - } - var containerLenS int - isArray := ctyp == valueTypeArray - if isArray { - containerLenS = d.arrayStart(d.d.ReadArrayStart()) - } else if ctyp == valueTypeMap { - containerLenS = d.mapStart(d.d.ReadMapStart()) * 2 - } else { - halt.errorStr2("decoding into a slice, expect map/array - got ", ctyp.String()) - } - hasLen := containerLenS >= 0 - var j int - fnv := func(dst []interface{}) { v, changed = dst, true } - for ; d.containerNext(j, containerLenS, hasLen); j++ { - if j == 0 { - if containerLenS == len(v) { - } else if containerLenS < 0 || containerLenS > cap(v) { - if xlen := int(decInferLen(containerLenS, d.maxInitLen(), 16)); xlen <= cap(v) { - fnv(v[:uint(xlen)]) - } else { - v2 = make([]interface{}, uint(xlen)) - copy(v2, v) - fnv(v2) - } - } else { - fnv(v[:containerLenS]) - } - } - if isArray { - d.arrayElem(j == 0) - } else if j&1 == 0 { - d.mapElemKey(j == 0) - } else { - d.mapElemValue() - } - if j >= len(v) { - fnv(append(v, nil)) - } - d.decode(&v[uint(j)]) - } - if j < len(v) { - fnv(v[:uint(j)]) - } else if j == 0 && v == nil { - fnv([]interface{}{}) - } - if isArray { - d.arrayEnd() - } else { - d.mapEnd() - } - return v, changed -} -func (fastpathDTCborIO) DecSliceIntfN(v []interface{}, d *decoderCborIO) { - ctyp := d.d.ContainerType() - if ctyp == valueTypeNil { - return - } - var containerLenS int - isArray := ctyp == valueTypeArray - if isArray { - containerLenS = d.arrayStart(d.d.ReadArrayStart()) - } else if ctyp == valueTypeMap { - containerLenS = d.mapStart(d.d.ReadMapStart()) * 2 - } else { - halt.errorStr2("decoding into a slice, expect map/array - got ", ctyp.String()) - } - hasLen := containerLenS >= 0 - for j := 0; d.containerNext(j, containerLenS, hasLen); j++ { - if isArray { - d.arrayElem(j == 0) - } else if j&1 == 0 { - d.mapElemKey(j == 0) - } else { - d.mapElemValue() - } - if j < len(v) { - d.decode(&v[uint(j)]) - } else { - d.arrayCannotExpand(len(v), j+1) - d.swallow() - } - } - if isArray { - d.arrayEnd() - } else { - d.mapEnd() - } -} - -func (d *decoderCborIO) fastpathDecSliceStringR(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTCborIO - switch rv.Kind() { - case reflect.Ptr: - v := rv2i(rv).(*[]string) - if vv, changed := ft.DecSliceStringY(*v, d); changed { - *v = vv - } - case reflect.Array: - var v []string - rvGetSlice4Array(rv, &v) - ft.DecSliceStringN(v, d) - default: - ft.DecSliceStringN(rv2i(rv).([]string), d) - } -} -func (fastpathDTCborIO) DecSliceStringY(v []string, d *decoderCborIO) (v2 []string, changed bool) { - ctyp := d.d.ContainerType() - if ctyp == valueTypeNil { - return nil, v != nil - } - var containerLenS int - isArray := ctyp == valueTypeArray - if isArray { - containerLenS = d.arrayStart(d.d.ReadArrayStart()) - } else if ctyp == valueTypeMap { - containerLenS = d.mapStart(d.d.ReadMapStart()) * 2 - } else { - halt.errorStr2("decoding into a slice, expect map/array - got ", ctyp.String()) - } - hasLen := containerLenS >= 0 - var j int - fnv := func(dst []string) { v, changed = dst, true } - for ; d.containerNext(j, containerLenS, hasLen); j++ { - if j == 0 { - if containerLenS == len(v) { - } else if containerLenS < 0 || containerLenS > cap(v) { - if xlen := int(decInferLen(containerLenS, d.maxInitLen(), 16)); xlen <= cap(v) { - fnv(v[:uint(xlen)]) - } else { - v2 = make([]string, uint(xlen)) - copy(v2, v) - fnv(v2) - } - } else { - fnv(v[:containerLenS]) - } - } - if isArray { - d.arrayElem(j == 0) - } else if j&1 == 0 { - d.mapElemKey(j == 0) - } else { - d.mapElemValue() - } - if j >= len(v) { - fnv(append(v, "")) - } - v[uint(j)] = d.detach2Str(d.d.DecodeStringAsBytes()) - } - if j < len(v) { - fnv(v[:uint(j)]) - } else if j == 0 && v == nil { - fnv([]string{}) - } - if isArray { - d.arrayEnd() - } else { - d.mapEnd() - } - return v, changed -} -func (fastpathDTCborIO) DecSliceStringN(v []string, d *decoderCborIO) { - ctyp := d.d.ContainerType() - if ctyp == valueTypeNil { - return - } - var containerLenS int - isArray := ctyp == valueTypeArray - if isArray { - containerLenS = d.arrayStart(d.d.ReadArrayStart()) - } else if ctyp == valueTypeMap { - containerLenS = d.mapStart(d.d.ReadMapStart()) * 2 - } else { - halt.errorStr2("decoding into a slice, expect map/array - got ", ctyp.String()) - } - hasLen := containerLenS >= 0 - for j := 0; d.containerNext(j, containerLenS, hasLen); j++ { - if isArray { - d.arrayElem(j == 0) - } else if j&1 == 0 { - d.mapElemKey(j == 0) - } else { - d.mapElemValue() - } - if j < len(v) { - v[uint(j)] = d.detach2Str(d.d.DecodeStringAsBytes()) - } else { - d.arrayCannotExpand(len(v), j+1) - d.swallow() - } - } - if isArray { - d.arrayEnd() - } else { - d.mapEnd() - } -} - -func (d *decoderCborIO) fastpathDecSliceBytesR(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTCborIO - switch rv.Kind() { - case reflect.Ptr: - v := rv2i(rv).(*[][]byte) - if vv, changed := ft.DecSliceBytesY(*v, d); changed { - *v = vv - } - case reflect.Array: - var v [][]byte - rvGetSlice4Array(rv, &v) - ft.DecSliceBytesN(v, d) - default: - ft.DecSliceBytesN(rv2i(rv).([][]byte), d) - } -} -func (fastpathDTCborIO) DecSliceBytesY(v [][]byte, d *decoderCborIO) (v2 [][]byte, changed bool) { - ctyp := d.d.ContainerType() - if ctyp == valueTypeNil { - return nil, v != nil - } - var containerLenS int - isArray := ctyp == valueTypeArray - if isArray { - containerLenS = d.arrayStart(d.d.ReadArrayStart()) - } else if ctyp == valueTypeMap { - containerLenS = d.mapStart(d.d.ReadMapStart()) * 2 - } else { - halt.errorStr2("decoding into a slice, expect map/array - got ", ctyp.String()) - } - hasLen := containerLenS >= 0 - var j int - fnv := func(dst [][]byte) { v, changed = dst, true } - for ; d.containerNext(j, containerLenS, hasLen); j++ { - if j == 0 { - if containerLenS == len(v) { - } else if containerLenS < 0 || containerLenS > cap(v) { - if xlen := int(decInferLen(containerLenS, d.maxInitLen(), 24)); xlen <= cap(v) { - fnv(v[:uint(xlen)]) - } else { - v2 = make([][]byte, uint(xlen)) - copy(v2, v) - fnv(v2) - } - } else { - fnv(v[:containerLenS]) - } - } - if isArray { - d.arrayElem(j == 0) - } else if j&1 == 0 { - d.mapElemKey(j == 0) - } else { - d.mapElemValue() - } - if j >= len(v) { - fnv(append(v, nil)) - } - v[uint(j)] = bytesOKdbi(d.decodeBytesInto(v[uint(j)], false)) - } - if j < len(v) { - fnv(v[:uint(j)]) - } else if j == 0 && v == nil { - fnv([][]byte{}) - } - if isArray { - d.arrayEnd() - } else { - d.mapEnd() - } - return v, changed -} -func (fastpathDTCborIO) DecSliceBytesN(v [][]byte, d *decoderCborIO) { - ctyp := d.d.ContainerType() - if ctyp == valueTypeNil { - return - } - var containerLenS int - isArray := ctyp == valueTypeArray - if isArray { - containerLenS = d.arrayStart(d.d.ReadArrayStart()) - } else if ctyp == valueTypeMap { - containerLenS = d.mapStart(d.d.ReadMapStart()) * 2 - } else { - halt.errorStr2("decoding into a slice, expect map/array - got ", ctyp.String()) - } - hasLen := containerLenS >= 0 - for j := 0; d.containerNext(j, containerLenS, hasLen); j++ { - if isArray { - d.arrayElem(j == 0) - } else if j&1 == 0 { - d.mapElemKey(j == 0) - } else { - d.mapElemValue() - } - if j < len(v) { - v[uint(j)] = bytesOKdbi(d.decodeBytesInto(v[uint(j)], false)) - } else { - d.arrayCannotExpand(len(v), j+1) - d.swallow() - } - } - if isArray { - d.arrayEnd() - } else { - d.mapEnd() - } -} - -func (d *decoderCborIO) fastpathDecSliceFloat32R(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTCborIO - switch rv.Kind() { - case reflect.Ptr: - v := rv2i(rv).(*[]float32) - if vv, changed := ft.DecSliceFloat32Y(*v, d); changed { - *v = vv - } - case reflect.Array: - var v []float32 - rvGetSlice4Array(rv, &v) - ft.DecSliceFloat32N(v, d) - default: - ft.DecSliceFloat32N(rv2i(rv).([]float32), d) - } -} -func (fastpathDTCborIO) DecSliceFloat32Y(v []float32, d *decoderCborIO) (v2 []float32, changed bool) { - ctyp := d.d.ContainerType() - if ctyp == valueTypeNil { - return nil, v != nil - } - var containerLenS int - isArray := ctyp == valueTypeArray - if isArray { - containerLenS = d.arrayStart(d.d.ReadArrayStart()) - } else if ctyp == valueTypeMap { - containerLenS = d.mapStart(d.d.ReadMapStart()) * 2 - } else { - halt.errorStr2("decoding into a slice, expect map/array - got ", ctyp.String()) - } - hasLen := containerLenS >= 0 - var j int - fnv := func(dst []float32) { v, changed = dst, true } - for ; d.containerNext(j, containerLenS, hasLen); j++ { - if j == 0 { - if containerLenS == len(v) { - } else if containerLenS < 0 || containerLenS > cap(v) { - if xlen := int(decInferLen(containerLenS, d.maxInitLen(), 4)); xlen <= cap(v) { - fnv(v[:uint(xlen)]) - } else { - v2 = make([]float32, uint(xlen)) - copy(v2, v) - fnv(v2) - } - } else { - fnv(v[:containerLenS]) - } - } - if isArray { - d.arrayElem(j == 0) - } else if j&1 == 0 { - d.mapElemKey(j == 0) - } else { - d.mapElemValue() - } - if j >= len(v) { - fnv(append(v, 0)) - } - v[uint(j)] = float32(d.d.DecodeFloat32()) - } - if j < len(v) { - fnv(v[:uint(j)]) - } else if j == 0 && v == nil { - fnv([]float32{}) - } - if isArray { - d.arrayEnd() - } else { - d.mapEnd() - } - return v, changed -} -func (fastpathDTCborIO) DecSliceFloat32N(v []float32, d *decoderCborIO) { - ctyp := d.d.ContainerType() - if ctyp == valueTypeNil { - return - } - var containerLenS int - isArray := ctyp == valueTypeArray - if isArray { - containerLenS = d.arrayStart(d.d.ReadArrayStart()) - } else if ctyp == valueTypeMap { - containerLenS = d.mapStart(d.d.ReadMapStart()) * 2 - } else { - halt.errorStr2("decoding into a slice, expect map/array - got ", ctyp.String()) - } - hasLen := containerLenS >= 0 - for j := 0; d.containerNext(j, containerLenS, hasLen); j++ { - if isArray { - d.arrayElem(j == 0) - } else if j&1 == 0 { - d.mapElemKey(j == 0) - } else { - d.mapElemValue() - } - if j < len(v) { - v[uint(j)] = float32(d.d.DecodeFloat32()) - } else { - d.arrayCannotExpand(len(v), j+1) - d.swallow() - } - } - if isArray { - d.arrayEnd() - } else { - d.mapEnd() - } -} - -func (d *decoderCborIO) fastpathDecSliceFloat64R(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTCborIO - switch rv.Kind() { - case reflect.Ptr: - v := rv2i(rv).(*[]float64) - if vv, changed := ft.DecSliceFloat64Y(*v, d); changed { - *v = vv - } - case reflect.Array: - var v []float64 - rvGetSlice4Array(rv, &v) - ft.DecSliceFloat64N(v, d) - default: - ft.DecSliceFloat64N(rv2i(rv).([]float64), d) - } -} -func (fastpathDTCborIO) DecSliceFloat64Y(v []float64, d *decoderCborIO) (v2 []float64, changed bool) { - ctyp := d.d.ContainerType() - if ctyp == valueTypeNil { - return nil, v != nil - } - var containerLenS int - isArray := ctyp == valueTypeArray - if isArray { - containerLenS = d.arrayStart(d.d.ReadArrayStart()) - } else if ctyp == valueTypeMap { - containerLenS = d.mapStart(d.d.ReadMapStart()) * 2 - } else { - halt.errorStr2("decoding into a slice, expect map/array - got ", ctyp.String()) - } - hasLen := containerLenS >= 0 - var j int - fnv := func(dst []float64) { v, changed = dst, true } - for ; d.containerNext(j, containerLenS, hasLen); j++ { - if j == 0 { - if containerLenS == len(v) { - } else if containerLenS < 0 || containerLenS > cap(v) { - if xlen := int(decInferLen(containerLenS, d.maxInitLen(), 8)); xlen <= cap(v) { - fnv(v[:uint(xlen)]) - } else { - v2 = make([]float64, uint(xlen)) - copy(v2, v) - fnv(v2) - } - } else { - fnv(v[:containerLenS]) - } - } - if isArray { - d.arrayElem(j == 0) - } else if j&1 == 0 { - d.mapElemKey(j == 0) - } else { - d.mapElemValue() - } - if j >= len(v) { - fnv(append(v, 0)) - } - v[uint(j)] = d.d.DecodeFloat64() - } - if j < len(v) { - fnv(v[:uint(j)]) - } else if j == 0 && v == nil { - fnv([]float64{}) - } - if isArray { - d.arrayEnd() - } else { - d.mapEnd() - } - return v, changed -} -func (fastpathDTCborIO) DecSliceFloat64N(v []float64, d *decoderCborIO) { - ctyp := d.d.ContainerType() - if ctyp == valueTypeNil { - return - } - var containerLenS int - isArray := ctyp == valueTypeArray - if isArray { - containerLenS = d.arrayStart(d.d.ReadArrayStart()) - } else if ctyp == valueTypeMap { - containerLenS = d.mapStart(d.d.ReadMapStart()) * 2 - } else { - halt.errorStr2("decoding into a slice, expect map/array - got ", ctyp.String()) - } - hasLen := containerLenS >= 0 - for j := 0; d.containerNext(j, containerLenS, hasLen); j++ { - if isArray { - d.arrayElem(j == 0) - } else if j&1 == 0 { - d.mapElemKey(j == 0) - } else { - d.mapElemValue() - } - if j < len(v) { - v[uint(j)] = d.d.DecodeFloat64() - } else { - d.arrayCannotExpand(len(v), j+1) - d.swallow() - } - } - if isArray { - d.arrayEnd() - } else { - d.mapEnd() - } -} - -func (d *decoderCborIO) fastpathDecSliceUint8R(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTCborIO - switch rv.Kind() { - case reflect.Ptr: - v := rv2i(rv).(*[]uint8) - if vv, changed := ft.DecSliceUint8Y(*v, d); changed { - *v = vv - } - case reflect.Array: - var v []uint8 - rvGetSlice4Array(rv, &v) - ft.DecSliceUint8N(v, d) - default: - ft.DecSliceUint8N(rv2i(rv).([]uint8), d) - } -} -func (fastpathDTCborIO) DecSliceUint8Y(v []uint8, d *decoderCborIO) (v2 []uint8, changed bool) { - ctyp := d.d.ContainerType() - if ctyp == valueTypeNil { - return nil, v != nil - } - if ctyp != valueTypeMap { - var dbi dBytesIntoState - v2, dbi = d.decodeBytesInto(v[:len(v):len(v)], false) - return v2, dbi != dBytesIntoParamOut - } - containerLenS := d.mapStart(d.d.ReadMapStart()) * 2 - hasLen := containerLenS >= 0 - var j int - fnv := func(dst []uint8) { v, changed = dst, true } - for ; d.containerNext(j, containerLenS, hasLen); j++ { - if j == 0 { - if containerLenS == len(v) { - } else if containerLenS < 0 || containerLenS > cap(v) { - if xlen := int(decInferLen(containerLenS, d.maxInitLen(), 1)); xlen <= cap(v) { - fnv(v[:uint(xlen)]) - } else { - v2 = make([]uint8, uint(xlen)) - copy(v2, v) - fnv(v2) - } - } else { - fnv(v[:containerLenS]) - } - } - if j&1 == 0 { - d.mapElemKey(j == 0) - } else { - d.mapElemValue() - } - if j >= len(v) { - fnv(append(v, 0)) - } - v[uint(j)] = uint8(chkOvf.UintV(d.d.DecodeUint64(), 8)) - } - if j < len(v) { - fnv(v[:uint(j)]) - } else if j == 0 && v == nil { - fnv([]uint8{}) - } - d.mapEnd() - return v, changed -} -func (fastpathDTCborIO) DecSliceUint8N(v []uint8, d *decoderCborIO) { - ctyp := d.d.ContainerType() - if ctyp == valueTypeNil { - return - } - if ctyp != valueTypeMap { - d.decodeBytesInto(v[:len(v):len(v)], true) - return - } - containerLenS := d.mapStart(d.d.ReadMapStart()) * 2 - hasLen := containerLenS >= 0 - for j := 0; d.containerNext(j, containerLenS, hasLen); j++ { - if j&1 == 0 { - d.mapElemKey(j == 0) - } else { - d.mapElemValue() - } - if j < len(v) { - v[uint(j)] = uint8(chkOvf.UintV(d.d.DecodeUint64(), 8)) - } else { - d.arrayCannotExpand(len(v), j+1) - d.swallow() - } - } - d.mapEnd() -} - -func (d *decoderCborIO) fastpathDecSliceUint64R(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTCborIO - switch rv.Kind() { - case reflect.Ptr: - v := rv2i(rv).(*[]uint64) - if vv, changed := ft.DecSliceUint64Y(*v, d); changed { - *v = vv - } - case reflect.Array: - var v []uint64 - rvGetSlice4Array(rv, &v) - ft.DecSliceUint64N(v, d) - default: - ft.DecSliceUint64N(rv2i(rv).([]uint64), d) - } -} -func (fastpathDTCborIO) DecSliceUint64Y(v []uint64, d *decoderCborIO) (v2 []uint64, changed bool) { - ctyp := d.d.ContainerType() - if ctyp == valueTypeNil { - return nil, v != nil - } - var containerLenS int - isArray := ctyp == valueTypeArray - if isArray { - containerLenS = d.arrayStart(d.d.ReadArrayStart()) - } else if ctyp == valueTypeMap { - containerLenS = d.mapStart(d.d.ReadMapStart()) * 2 - } else { - halt.errorStr2("decoding into a slice, expect map/array - got ", ctyp.String()) - } - hasLen := containerLenS >= 0 - var j int - fnv := func(dst []uint64) { v, changed = dst, true } - for ; d.containerNext(j, containerLenS, hasLen); j++ { - if j == 0 { - if containerLenS == len(v) { - } else if containerLenS < 0 || containerLenS > cap(v) { - if xlen := int(decInferLen(containerLenS, d.maxInitLen(), 8)); xlen <= cap(v) { - fnv(v[:uint(xlen)]) - } else { - v2 = make([]uint64, uint(xlen)) - copy(v2, v) - fnv(v2) - } - } else { - fnv(v[:containerLenS]) - } - } - if isArray { - d.arrayElem(j == 0) - } else if j&1 == 0 { - d.mapElemKey(j == 0) - } else { - d.mapElemValue() - } - if j >= len(v) { - fnv(append(v, 0)) - } - v[uint(j)] = d.d.DecodeUint64() - } - if j < len(v) { - fnv(v[:uint(j)]) - } else if j == 0 && v == nil { - fnv([]uint64{}) - } - if isArray { - d.arrayEnd() - } else { - d.mapEnd() - } - return v, changed -} -func (fastpathDTCborIO) DecSliceUint64N(v []uint64, d *decoderCborIO) { - ctyp := d.d.ContainerType() - if ctyp == valueTypeNil { - return - } - var containerLenS int - isArray := ctyp == valueTypeArray - if isArray { - containerLenS = d.arrayStart(d.d.ReadArrayStart()) - } else if ctyp == valueTypeMap { - containerLenS = d.mapStart(d.d.ReadMapStart()) * 2 - } else { - halt.errorStr2("decoding into a slice, expect map/array - got ", ctyp.String()) - } - hasLen := containerLenS >= 0 - for j := 0; d.containerNext(j, containerLenS, hasLen); j++ { - if isArray { - d.arrayElem(j == 0) - } else if j&1 == 0 { - d.mapElemKey(j == 0) - } else { - d.mapElemValue() - } - if j < len(v) { - v[uint(j)] = d.d.DecodeUint64() - } else { - d.arrayCannotExpand(len(v), j+1) - d.swallow() - } - } - if isArray { - d.arrayEnd() - } else { - d.mapEnd() - } -} - -func (d *decoderCborIO) fastpathDecSliceIntR(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTCborIO - switch rv.Kind() { - case reflect.Ptr: - v := rv2i(rv).(*[]int) - if vv, changed := ft.DecSliceIntY(*v, d); changed { - *v = vv - } - case reflect.Array: - var v []int - rvGetSlice4Array(rv, &v) - ft.DecSliceIntN(v, d) - default: - ft.DecSliceIntN(rv2i(rv).([]int), d) - } -} -func (fastpathDTCborIO) DecSliceIntY(v []int, d *decoderCborIO) (v2 []int, changed bool) { - ctyp := d.d.ContainerType() - if ctyp == valueTypeNil { - return nil, v != nil - } - var containerLenS int - isArray := ctyp == valueTypeArray - if isArray { - containerLenS = d.arrayStart(d.d.ReadArrayStart()) - } else if ctyp == valueTypeMap { - containerLenS = d.mapStart(d.d.ReadMapStart()) * 2 - } else { - halt.errorStr2("decoding into a slice, expect map/array - got ", ctyp.String()) - } - hasLen := containerLenS >= 0 - var j int - fnv := func(dst []int) { v, changed = dst, true } - for ; d.containerNext(j, containerLenS, hasLen); j++ { - if j == 0 { - if containerLenS == len(v) { - } else if containerLenS < 0 || containerLenS > cap(v) { - if xlen := int(decInferLen(containerLenS, d.maxInitLen(), 8)); xlen <= cap(v) { - fnv(v[:uint(xlen)]) - } else { - v2 = make([]int, uint(xlen)) - copy(v2, v) - fnv(v2) - } - } else { - fnv(v[:containerLenS]) - } - } - if isArray { - d.arrayElem(j == 0) - } else if j&1 == 0 { - d.mapElemKey(j == 0) - } else { - d.mapElemValue() - } - if j >= len(v) { - fnv(append(v, 0)) - } - v[uint(j)] = int(chkOvf.IntV(d.d.DecodeInt64(), intBitsize)) - } - if j < len(v) { - fnv(v[:uint(j)]) - } else if j == 0 && v == nil { - fnv([]int{}) - } - if isArray { - d.arrayEnd() - } else { - d.mapEnd() - } - return v, changed -} -func (fastpathDTCborIO) DecSliceIntN(v []int, d *decoderCborIO) { - ctyp := d.d.ContainerType() - if ctyp == valueTypeNil { - return - } - var containerLenS int - isArray := ctyp == valueTypeArray - if isArray { - containerLenS = d.arrayStart(d.d.ReadArrayStart()) - } else if ctyp == valueTypeMap { - containerLenS = d.mapStart(d.d.ReadMapStart()) * 2 - } else { - halt.errorStr2("decoding into a slice, expect map/array - got ", ctyp.String()) - } - hasLen := containerLenS >= 0 - for j := 0; d.containerNext(j, containerLenS, hasLen); j++ { - if isArray { - d.arrayElem(j == 0) - } else if j&1 == 0 { - d.mapElemKey(j == 0) - } else { - d.mapElemValue() - } - if j < len(v) { - v[uint(j)] = int(chkOvf.IntV(d.d.DecodeInt64(), intBitsize)) - } else { - d.arrayCannotExpand(len(v), j+1) - d.swallow() - } - } - if isArray { - d.arrayEnd() - } else { - d.mapEnd() - } -} - -func (d *decoderCborIO) fastpathDecSliceInt32R(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTCborIO - switch rv.Kind() { - case reflect.Ptr: - v := rv2i(rv).(*[]int32) - if vv, changed := ft.DecSliceInt32Y(*v, d); changed { - *v = vv - } - case reflect.Array: - var v []int32 - rvGetSlice4Array(rv, &v) - ft.DecSliceInt32N(v, d) - default: - ft.DecSliceInt32N(rv2i(rv).([]int32), d) - } -} -func (fastpathDTCborIO) DecSliceInt32Y(v []int32, d *decoderCborIO) (v2 []int32, changed bool) { - ctyp := d.d.ContainerType() - if ctyp == valueTypeNil { - return nil, v != nil - } - var containerLenS int - isArray := ctyp == valueTypeArray - if isArray { - containerLenS = d.arrayStart(d.d.ReadArrayStart()) - } else if ctyp == valueTypeMap { - containerLenS = d.mapStart(d.d.ReadMapStart()) * 2 - } else { - halt.errorStr2("decoding into a slice, expect map/array - got ", ctyp.String()) - } - hasLen := containerLenS >= 0 - var j int - fnv := func(dst []int32) { v, changed = dst, true } - for ; d.containerNext(j, containerLenS, hasLen); j++ { - if j == 0 { - if containerLenS == len(v) { - } else if containerLenS < 0 || containerLenS > cap(v) { - if xlen := int(decInferLen(containerLenS, d.maxInitLen(), 4)); xlen <= cap(v) { - fnv(v[:uint(xlen)]) - } else { - v2 = make([]int32, uint(xlen)) - copy(v2, v) - fnv(v2) - } - } else { - fnv(v[:containerLenS]) - } - } - if isArray { - d.arrayElem(j == 0) - } else if j&1 == 0 { - d.mapElemKey(j == 0) - } else { - d.mapElemValue() - } - if j >= len(v) { - fnv(append(v, 0)) - } - v[uint(j)] = int32(chkOvf.IntV(d.d.DecodeInt64(), 32)) - } - if j < len(v) { - fnv(v[:uint(j)]) - } else if j == 0 && v == nil { - fnv([]int32{}) - } - if isArray { - d.arrayEnd() - } else { - d.mapEnd() - } - return v, changed -} -func (fastpathDTCborIO) DecSliceInt32N(v []int32, d *decoderCborIO) { - ctyp := d.d.ContainerType() - if ctyp == valueTypeNil { - return - } - var containerLenS int - isArray := ctyp == valueTypeArray - if isArray { - containerLenS = d.arrayStart(d.d.ReadArrayStart()) - } else if ctyp == valueTypeMap { - containerLenS = d.mapStart(d.d.ReadMapStart()) * 2 - } else { - halt.errorStr2("decoding into a slice, expect map/array - got ", ctyp.String()) - } - hasLen := containerLenS >= 0 - for j := 0; d.containerNext(j, containerLenS, hasLen); j++ { - if isArray { - d.arrayElem(j == 0) - } else if j&1 == 0 { - d.mapElemKey(j == 0) - } else { - d.mapElemValue() - } - if j < len(v) { - v[uint(j)] = int32(chkOvf.IntV(d.d.DecodeInt64(), 32)) - } else { - d.arrayCannotExpand(len(v), j+1) - d.swallow() - } - } - if isArray { - d.arrayEnd() - } else { - d.mapEnd() - } -} - -func (d *decoderCborIO) fastpathDecSliceInt64R(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTCborIO - switch rv.Kind() { - case reflect.Ptr: - v := rv2i(rv).(*[]int64) - if vv, changed := ft.DecSliceInt64Y(*v, d); changed { - *v = vv - } - case reflect.Array: - var v []int64 - rvGetSlice4Array(rv, &v) - ft.DecSliceInt64N(v, d) - default: - ft.DecSliceInt64N(rv2i(rv).([]int64), d) - } -} -func (fastpathDTCborIO) DecSliceInt64Y(v []int64, d *decoderCborIO) (v2 []int64, changed bool) { - ctyp := d.d.ContainerType() - if ctyp == valueTypeNil { - return nil, v != nil - } - var containerLenS int - isArray := ctyp == valueTypeArray - if isArray { - containerLenS = d.arrayStart(d.d.ReadArrayStart()) - } else if ctyp == valueTypeMap { - containerLenS = d.mapStart(d.d.ReadMapStart()) * 2 - } else { - halt.errorStr2("decoding into a slice, expect map/array - got ", ctyp.String()) - } - hasLen := containerLenS >= 0 - var j int - fnv := func(dst []int64) { v, changed = dst, true } - for ; d.containerNext(j, containerLenS, hasLen); j++ { - if j == 0 { - if containerLenS == len(v) { - } else if containerLenS < 0 || containerLenS > cap(v) { - if xlen := int(decInferLen(containerLenS, d.maxInitLen(), 8)); xlen <= cap(v) { - fnv(v[:uint(xlen)]) - } else { - v2 = make([]int64, uint(xlen)) - copy(v2, v) - fnv(v2) - } - } else { - fnv(v[:containerLenS]) - } - } - if isArray { - d.arrayElem(j == 0) - } else if j&1 == 0 { - d.mapElemKey(j == 0) - } else { - d.mapElemValue() - } - if j >= len(v) { - fnv(append(v, 0)) - } - v[uint(j)] = d.d.DecodeInt64() - } - if j < len(v) { - fnv(v[:uint(j)]) - } else if j == 0 && v == nil { - fnv([]int64{}) - } - if isArray { - d.arrayEnd() - } else { - d.mapEnd() - } - return v, changed -} -func (fastpathDTCborIO) DecSliceInt64N(v []int64, d *decoderCborIO) { - ctyp := d.d.ContainerType() - if ctyp == valueTypeNil { - return - } - var containerLenS int - isArray := ctyp == valueTypeArray - if isArray { - containerLenS = d.arrayStart(d.d.ReadArrayStart()) - } else if ctyp == valueTypeMap { - containerLenS = d.mapStart(d.d.ReadMapStart()) * 2 - } else { - halt.errorStr2("decoding into a slice, expect map/array - got ", ctyp.String()) - } - hasLen := containerLenS >= 0 - for j := 0; d.containerNext(j, containerLenS, hasLen); j++ { - if isArray { - d.arrayElem(j == 0) - } else if j&1 == 0 { - d.mapElemKey(j == 0) - } else { - d.mapElemValue() - } - if j < len(v) { - v[uint(j)] = d.d.DecodeInt64() - } else { - d.arrayCannotExpand(len(v), j+1) - d.swallow() - } - } - if isArray { - d.arrayEnd() - } else { - d.mapEnd() - } -} - -func (d *decoderCborIO) fastpathDecSliceBoolR(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTCborIO - switch rv.Kind() { - case reflect.Ptr: - v := rv2i(rv).(*[]bool) - if vv, changed := ft.DecSliceBoolY(*v, d); changed { - *v = vv - } - case reflect.Array: - var v []bool - rvGetSlice4Array(rv, &v) - ft.DecSliceBoolN(v, d) - default: - ft.DecSliceBoolN(rv2i(rv).([]bool), d) - } -} -func (fastpathDTCborIO) DecSliceBoolY(v []bool, d *decoderCborIO) (v2 []bool, changed bool) { - ctyp := d.d.ContainerType() - if ctyp == valueTypeNil { - return nil, v != nil - } - var containerLenS int - isArray := ctyp == valueTypeArray - if isArray { - containerLenS = d.arrayStart(d.d.ReadArrayStart()) - } else if ctyp == valueTypeMap { - containerLenS = d.mapStart(d.d.ReadMapStart()) * 2 - } else { - halt.errorStr2("decoding into a slice, expect map/array - got ", ctyp.String()) - } - hasLen := containerLenS >= 0 - var j int - fnv := func(dst []bool) { v, changed = dst, true } - for ; d.containerNext(j, containerLenS, hasLen); j++ { - if j == 0 { - if containerLenS == len(v) { - } else if containerLenS < 0 || containerLenS > cap(v) { - if xlen := int(decInferLen(containerLenS, d.maxInitLen(), 1)); xlen <= cap(v) { - fnv(v[:uint(xlen)]) - } else { - v2 = make([]bool, uint(xlen)) - copy(v2, v) - fnv(v2) - } - } else { - fnv(v[:containerLenS]) - } - } - if isArray { - d.arrayElem(j == 0) - } else if j&1 == 0 { - d.mapElemKey(j == 0) - } else { - d.mapElemValue() - } - if j >= len(v) { - fnv(append(v, false)) - } - v[uint(j)] = d.d.DecodeBool() - } - if j < len(v) { - fnv(v[:uint(j)]) - } else if j == 0 && v == nil { - fnv([]bool{}) - } - if isArray { - d.arrayEnd() - } else { - d.mapEnd() - } - return v, changed -} -func (fastpathDTCborIO) DecSliceBoolN(v []bool, d *decoderCborIO) { - ctyp := d.d.ContainerType() - if ctyp == valueTypeNil { - return - } - var containerLenS int - isArray := ctyp == valueTypeArray - if isArray { - containerLenS = d.arrayStart(d.d.ReadArrayStart()) - } else if ctyp == valueTypeMap { - containerLenS = d.mapStart(d.d.ReadMapStart()) * 2 - } else { - halt.errorStr2("decoding into a slice, expect map/array - got ", ctyp.String()) - } - hasLen := containerLenS >= 0 - for j := 0; d.containerNext(j, containerLenS, hasLen); j++ { - if isArray { - d.arrayElem(j == 0) - } else if j&1 == 0 { - d.mapElemKey(j == 0) - } else { - d.mapElemValue() - } - if j < len(v) { - v[uint(j)] = d.d.DecodeBool() - } else { - d.arrayCannotExpand(len(v), j+1) - d.swallow() - } - } - if isArray { - d.arrayEnd() - } else { - d.mapEnd() - } -} -func (d *decoderCborIO) fastpathDecMapStringIntfR(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTCborIO - containerLen := d.mapStart(d.d.ReadMapStart()) - if rv.Kind() == reflect.Ptr { - vp, _ := rv2i(rv).(*map[string]interface{}) - if *vp == nil { - *vp = make(map[string]interface{}, decInferLen(containerLen, d.maxInitLen(), 32)) - } - if containerLen != 0 { - ft.DecMapStringIntfL(*vp, containerLen, d) - } - } else if containerLen != 0 { - ft.DecMapStringIntfL(rv2i(rv).(map[string]interface{}), containerLen, d) - } - d.mapEnd() -} -func (fastpathDTCborIO) DecMapStringIntfL(v map[string]interface{}, containerLen int, d *decoderCborIO) { - if v == nil { - halt.errorInt("cannot decode into nil map[string]interface{} given stream length: ", int64(containerLen)) - } - var mv interface{} - mapGet := !d.h.MapValueReset && !d.h.InterfaceReset - hasLen := containerLen >= 0 - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - mk := d.detach2Str(d.d.DecodeStringAsBytes()) - d.mapElemValue() - if mapGet { - mv = v[mk] - } else { - mv = nil - } - d.decode(&mv) - v[mk] = mv - } -} -func (d *decoderCborIO) fastpathDecMapStringStringR(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTCborIO - containerLen := d.mapStart(d.d.ReadMapStart()) - if rv.Kind() == reflect.Ptr { - vp, _ := rv2i(rv).(*map[string]string) - if *vp == nil { - *vp = make(map[string]string, decInferLen(containerLen, d.maxInitLen(), 32)) - } - if containerLen != 0 { - ft.DecMapStringStringL(*vp, containerLen, d) - } - } else if containerLen != 0 { - ft.DecMapStringStringL(rv2i(rv).(map[string]string), containerLen, d) - } - d.mapEnd() -} -func (fastpathDTCborIO) DecMapStringStringL(v map[string]string, containerLen int, d *decoderCborIO) { - if v == nil { - halt.errorInt("cannot decode into nil map[string]string given stream length: ", int64(containerLen)) - } - hasLen := containerLen >= 0 - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - mk := d.detach2Str(d.d.DecodeStringAsBytes()) - d.mapElemValue() - v[mk] = d.detach2Str(d.d.DecodeStringAsBytes()) - } -} -func (d *decoderCborIO) fastpathDecMapStringBytesR(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTCborIO - containerLen := d.mapStart(d.d.ReadMapStart()) - if rv.Kind() == reflect.Ptr { - vp, _ := rv2i(rv).(*map[string][]byte) - if *vp == nil { - *vp = make(map[string][]byte, decInferLen(containerLen, d.maxInitLen(), 40)) - } - if containerLen != 0 { - ft.DecMapStringBytesL(*vp, containerLen, d) - } - } else if containerLen != 0 { - ft.DecMapStringBytesL(rv2i(rv).(map[string][]byte), containerLen, d) - } - d.mapEnd() -} -func (fastpathDTCborIO) DecMapStringBytesL(v map[string][]byte, containerLen int, d *decoderCborIO) { - if v == nil { - halt.errorInt("cannot decode into nil map[string][]byte given stream length: ", int64(containerLen)) - } - var mv []byte - mapGet := !d.h.MapValueReset - hasLen := containerLen >= 0 - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - mk := d.detach2Str(d.d.DecodeStringAsBytes()) - d.mapElemValue() - if mapGet { - mv = v[mk] - } else { - mv = nil - } - v[mk], _ = d.decodeBytesInto(mv, false) - } -} -func (d *decoderCborIO) fastpathDecMapStringUint8R(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTCborIO - containerLen := d.mapStart(d.d.ReadMapStart()) - if rv.Kind() == reflect.Ptr { - vp, _ := rv2i(rv).(*map[string]uint8) - if *vp == nil { - *vp = make(map[string]uint8, decInferLen(containerLen, d.maxInitLen(), 17)) - } - if containerLen != 0 { - ft.DecMapStringUint8L(*vp, containerLen, d) - } - } else if containerLen != 0 { - ft.DecMapStringUint8L(rv2i(rv).(map[string]uint8), containerLen, d) - } - d.mapEnd() -} -func (fastpathDTCborIO) DecMapStringUint8L(v map[string]uint8, containerLen int, d *decoderCborIO) { - if v == nil { - halt.errorInt("cannot decode into nil map[string]uint8 given stream length: ", int64(containerLen)) - } - hasLen := containerLen >= 0 - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - mk := d.detach2Str(d.d.DecodeStringAsBytes()) - d.mapElemValue() - v[mk] = uint8(chkOvf.UintV(d.d.DecodeUint64(), 8)) - } -} -func (d *decoderCborIO) fastpathDecMapStringUint64R(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTCborIO - containerLen := d.mapStart(d.d.ReadMapStart()) - if rv.Kind() == reflect.Ptr { - vp, _ := rv2i(rv).(*map[string]uint64) - if *vp == nil { - *vp = make(map[string]uint64, decInferLen(containerLen, d.maxInitLen(), 24)) - } - if containerLen != 0 { - ft.DecMapStringUint64L(*vp, containerLen, d) - } - } else if containerLen != 0 { - ft.DecMapStringUint64L(rv2i(rv).(map[string]uint64), containerLen, d) - } - d.mapEnd() -} -func (fastpathDTCborIO) DecMapStringUint64L(v map[string]uint64, containerLen int, d *decoderCborIO) { - if v == nil { - halt.errorInt("cannot decode into nil map[string]uint64 given stream length: ", int64(containerLen)) - } - hasLen := containerLen >= 0 - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - mk := d.detach2Str(d.d.DecodeStringAsBytes()) - d.mapElemValue() - v[mk] = d.d.DecodeUint64() - } -} -func (d *decoderCborIO) fastpathDecMapStringIntR(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTCborIO - containerLen := d.mapStart(d.d.ReadMapStart()) - if rv.Kind() == reflect.Ptr { - vp, _ := rv2i(rv).(*map[string]int) - if *vp == nil { - *vp = make(map[string]int, decInferLen(containerLen, d.maxInitLen(), 24)) - } - if containerLen != 0 { - ft.DecMapStringIntL(*vp, containerLen, d) - } - } else if containerLen != 0 { - ft.DecMapStringIntL(rv2i(rv).(map[string]int), containerLen, d) - } - d.mapEnd() -} -func (fastpathDTCborIO) DecMapStringIntL(v map[string]int, containerLen int, d *decoderCborIO) { - if v == nil { - halt.errorInt("cannot decode into nil map[string]int given stream length: ", int64(containerLen)) - } - hasLen := containerLen >= 0 - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - mk := d.detach2Str(d.d.DecodeStringAsBytes()) - d.mapElemValue() - v[mk] = int(chkOvf.IntV(d.d.DecodeInt64(), intBitsize)) - } -} -func (d *decoderCborIO) fastpathDecMapStringInt32R(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTCborIO - containerLen := d.mapStart(d.d.ReadMapStart()) - if rv.Kind() == reflect.Ptr { - vp, _ := rv2i(rv).(*map[string]int32) - if *vp == nil { - *vp = make(map[string]int32, decInferLen(containerLen, d.maxInitLen(), 20)) - } - if containerLen != 0 { - ft.DecMapStringInt32L(*vp, containerLen, d) - } - } else if containerLen != 0 { - ft.DecMapStringInt32L(rv2i(rv).(map[string]int32), containerLen, d) - } - d.mapEnd() -} -func (fastpathDTCborIO) DecMapStringInt32L(v map[string]int32, containerLen int, d *decoderCborIO) { - if v == nil { - halt.errorInt("cannot decode into nil map[string]int32 given stream length: ", int64(containerLen)) - } - hasLen := containerLen >= 0 - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - mk := d.detach2Str(d.d.DecodeStringAsBytes()) - d.mapElemValue() - v[mk] = int32(chkOvf.IntV(d.d.DecodeInt64(), 32)) - } -} -func (d *decoderCborIO) fastpathDecMapStringFloat64R(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTCborIO - containerLen := d.mapStart(d.d.ReadMapStart()) - if rv.Kind() == reflect.Ptr { - vp, _ := rv2i(rv).(*map[string]float64) - if *vp == nil { - *vp = make(map[string]float64, decInferLen(containerLen, d.maxInitLen(), 24)) - } - if containerLen != 0 { - ft.DecMapStringFloat64L(*vp, containerLen, d) - } - } else if containerLen != 0 { - ft.DecMapStringFloat64L(rv2i(rv).(map[string]float64), containerLen, d) - } - d.mapEnd() -} -func (fastpathDTCborIO) DecMapStringFloat64L(v map[string]float64, containerLen int, d *decoderCborIO) { - if v == nil { - halt.errorInt("cannot decode into nil map[string]float64 given stream length: ", int64(containerLen)) - } - hasLen := containerLen >= 0 - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - mk := d.detach2Str(d.d.DecodeStringAsBytes()) - d.mapElemValue() - v[mk] = d.d.DecodeFloat64() - } -} -func (d *decoderCborIO) fastpathDecMapStringBoolR(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTCborIO - containerLen := d.mapStart(d.d.ReadMapStart()) - if rv.Kind() == reflect.Ptr { - vp, _ := rv2i(rv).(*map[string]bool) - if *vp == nil { - *vp = make(map[string]bool, decInferLen(containerLen, d.maxInitLen(), 17)) - } - if containerLen != 0 { - ft.DecMapStringBoolL(*vp, containerLen, d) - } - } else if containerLen != 0 { - ft.DecMapStringBoolL(rv2i(rv).(map[string]bool), containerLen, d) - } - d.mapEnd() -} -func (fastpathDTCborIO) DecMapStringBoolL(v map[string]bool, containerLen int, d *decoderCborIO) { - if v == nil { - halt.errorInt("cannot decode into nil map[string]bool given stream length: ", int64(containerLen)) - } - hasLen := containerLen >= 0 - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - mk := d.detach2Str(d.d.DecodeStringAsBytes()) - d.mapElemValue() - v[mk] = d.d.DecodeBool() - } -} -func (d *decoderCborIO) fastpathDecMapUint8IntfR(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTCborIO - containerLen := d.mapStart(d.d.ReadMapStart()) - if rv.Kind() == reflect.Ptr { - vp, _ := rv2i(rv).(*map[uint8]interface{}) - if *vp == nil { - *vp = make(map[uint8]interface{}, decInferLen(containerLen, d.maxInitLen(), 17)) - } - if containerLen != 0 { - ft.DecMapUint8IntfL(*vp, containerLen, d) - } - } else if containerLen != 0 { - ft.DecMapUint8IntfL(rv2i(rv).(map[uint8]interface{}), containerLen, d) - } - d.mapEnd() -} -func (fastpathDTCborIO) DecMapUint8IntfL(v map[uint8]interface{}, containerLen int, d *decoderCborIO) { - if v == nil { - halt.errorInt("cannot decode into nil map[uint8]interface{} given stream length: ", int64(containerLen)) - } - var mv interface{} - mapGet := !d.h.MapValueReset && !d.h.InterfaceReset - hasLen := containerLen >= 0 - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - mk := uint8(chkOvf.UintV(d.d.DecodeUint64(), 8)) - d.mapElemValue() - if mapGet { - mv = v[mk] - } else { - mv = nil - } - d.decode(&mv) - v[mk] = mv - } -} -func (d *decoderCborIO) fastpathDecMapUint8StringR(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTCborIO - containerLen := d.mapStart(d.d.ReadMapStart()) - if rv.Kind() == reflect.Ptr { - vp, _ := rv2i(rv).(*map[uint8]string) - if *vp == nil { - *vp = make(map[uint8]string, decInferLen(containerLen, d.maxInitLen(), 17)) - } - if containerLen != 0 { - ft.DecMapUint8StringL(*vp, containerLen, d) - } - } else if containerLen != 0 { - ft.DecMapUint8StringL(rv2i(rv).(map[uint8]string), containerLen, d) - } - d.mapEnd() -} -func (fastpathDTCborIO) DecMapUint8StringL(v map[uint8]string, containerLen int, d *decoderCborIO) { - if v == nil { - halt.errorInt("cannot decode into nil map[uint8]string given stream length: ", int64(containerLen)) - } - hasLen := containerLen >= 0 - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - mk := uint8(chkOvf.UintV(d.d.DecodeUint64(), 8)) - d.mapElemValue() - v[mk] = d.detach2Str(d.d.DecodeStringAsBytes()) - } -} -func (d *decoderCborIO) fastpathDecMapUint8BytesR(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTCborIO - containerLen := d.mapStart(d.d.ReadMapStart()) - if rv.Kind() == reflect.Ptr { - vp, _ := rv2i(rv).(*map[uint8][]byte) - if *vp == nil { - *vp = make(map[uint8][]byte, decInferLen(containerLen, d.maxInitLen(), 25)) - } - if containerLen != 0 { - ft.DecMapUint8BytesL(*vp, containerLen, d) - } - } else if containerLen != 0 { - ft.DecMapUint8BytesL(rv2i(rv).(map[uint8][]byte), containerLen, d) - } - d.mapEnd() -} -func (fastpathDTCborIO) DecMapUint8BytesL(v map[uint8][]byte, containerLen int, d *decoderCborIO) { - if v == nil { - halt.errorInt("cannot decode into nil map[uint8][]byte given stream length: ", int64(containerLen)) - } - var mv []byte - mapGet := !d.h.MapValueReset - hasLen := containerLen >= 0 - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - mk := uint8(chkOvf.UintV(d.d.DecodeUint64(), 8)) - d.mapElemValue() - if mapGet { - mv = v[mk] - } else { - mv = nil - } - v[mk], _ = d.decodeBytesInto(mv, false) - } -} -func (d *decoderCborIO) fastpathDecMapUint8Uint8R(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTCborIO - containerLen := d.mapStart(d.d.ReadMapStart()) - if rv.Kind() == reflect.Ptr { - vp, _ := rv2i(rv).(*map[uint8]uint8) - if *vp == nil { - *vp = make(map[uint8]uint8, decInferLen(containerLen, d.maxInitLen(), 2)) - } - if containerLen != 0 { - ft.DecMapUint8Uint8L(*vp, containerLen, d) - } - } else if containerLen != 0 { - ft.DecMapUint8Uint8L(rv2i(rv).(map[uint8]uint8), containerLen, d) - } - d.mapEnd() -} -func (fastpathDTCborIO) DecMapUint8Uint8L(v map[uint8]uint8, containerLen int, d *decoderCborIO) { - if v == nil { - halt.errorInt("cannot decode into nil map[uint8]uint8 given stream length: ", int64(containerLen)) - } - hasLen := containerLen >= 0 - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - mk := uint8(chkOvf.UintV(d.d.DecodeUint64(), 8)) - d.mapElemValue() - v[mk] = uint8(chkOvf.UintV(d.d.DecodeUint64(), 8)) - } -} -func (d *decoderCborIO) fastpathDecMapUint8Uint64R(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTCborIO - containerLen := d.mapStart(d.d.ReadMapStart()) - if rv.Kind() == reflect.Ptr { - vp, _ := rv2i(rv).(*map[uint8]uint64) - if *vp == nil { - *vp = make(map[uint8]uint64, decInferLen(containerLen, d.maxInitLen(), 9)) - } - if containerLen != 0 { - ft.DecMapUint8Uint64L(*vp, containerLen, d) - } - } else if containerLen != 0 { - ft.DecMapUint8Uint64L(rv2i(rv).(map[uint8]uint64), containerLen, d) - } - d.mapEnd() -} -func (fastpathDTCborIO) DecMapUint8Uint64L(v map[uint8]uint64, containerLen int, d *decoderCborIO) { - if v == nil { - halt.errorInt("cannot decode into nil map[uint8]uint64 given stream length: ", int64(containerLen)) - } - hasLen := containerLen >= 0 - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - mk := uint8(chkOvf.UintV(d.d.DecodeUint64(), 8)) - d.mapElemValue() - v[mk] = d.d.DecodeUint64() - } -} -func (d *decoderCborIO) fastpathDecMapUint8IntR(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTCborIO - containerLen := d.mapStart(d.d.ReadMapStart()) - if rv.Kind() == reflect.Ptr { - vp, _ := rv2i(rv).(*map[uint8]int) - if *vp == nil { - *vp = make(map[uint8]int, decInferLen(containerLen, d.maxInitLen(), 9)) - } - if containerLen != 0 { - ft.DecMapUint8IntL(*vp, containerLen, d) - } - } else if containerLen != 0 { - ft.DecMapUint8IntL(rv2i(rv).(map[uint8]int), containerLen, d) - } - d.mapEnd() -} -func (fastpathDTCborIO) DecMapUint8IntL(v map[uint8]int, containerLen int, d *decoderCborIO) { - if v == nil { - halt.errorInt("cannot decode into nil map[uint8]int given stream length: ", int64(containerLen)) - } - hasLen := containerLen >= 0 - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - mk := uint8(chkOvf.UintV(d.d.DecodeUint64(), 8)) - d.mapElemValue() - v[mk] = int(chkOvf.IntV(d.d.DecodeInt64(), intBitsize)) - } -} -func (d *decoderCborIO) fastpathDecMapUint8Int32R(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTCborIO - containerLen := d.mapStart(d.d.ReadMapStart()) - if rv.Kind() == reflect.Ptr { - vp, _ := rv2i(rv).(*map[uint8]int32) - if *vp == nil { - *vp = make(map[uint8]int32, decInferLen(containerLen, d.maxInitLen(), 5)) - } - if containerLen != 0 { - ft.DecMapUint8Int32L(*vp, containerLen, d) - } - } else if containerLen != 0 { - ft.DecMapUint8Int32L(rv2i(rv).(map[uint8]int32), containerLen, d) - } - d.mapEnd() -} -func (fastpathDTCborIO) DecMapUint8Int32L(v map[uint8]int32, containerLen int, d *decoderCborIO) { - if v == nil { - halt.errorInt("cannot decode into nil map[uint8]int32 given stream length: ", int64(containerLen)) - } - hasLen := containerLen >= 0 - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - mk := uint8(chkOvf.UintV(d.d.DecodeUint64(), 8)) - d.mapElemValue() - v[mk] = int32(chkOvf.IntV(d.d.DecodeInt64(), 32)) - } -} -func (d *decoderCborIO) fastpathDecMapUint8Float64R(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTCborIO - containerLen := d.mapStart(d.d.ReadMapStart()) - if rv.Kind() == reflect.Ptr { - vp, _ := rv2i(rv).(*map[uint8]float64) - if *vp == nil { - *vp = make(map[uint8]float64, decInferLen(containerLen, d.maxInitLen(), 9)) - } - if containerLen != 0 { - ft.DecMapUint8Float64L(*vp, containerLen, d) - } - } else if containerLen != 0 { - ft.DecMapUint8Float64L(rv2i(rv).(map[uint8]float64), containerLen, d) - } - d.mapEnd() -} -func (fastpathDTCborIO) DecMapUint8Float64L(v map[uint8]float64, containerLen int, d *decoderCborIO) { - if v == nil { - halt.errorInt("cannot decode into nil map[uint8]float64 given stream length: ", int64(containerLen)) - } - hasLen := containerLen >= 0 - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - mk := uint8(chkOvf.UintV(d.d.DecodeUint64(), 8)) - d.mapElemValue() - v[mk] = d.d.DecodeFloat64() - } -} -func (d *decoderCborIO) fastpathDecMapUint8BoolR(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTCborIO - containerLen := d.mapStart(d.d.ReadMapStart()) - if rv.Kind() == reflect.Ptr { - vp, _ := rv2i(rv).(*map[uint8]bool) - if *vp == nil { - *vp = make(map[uint8]bool, decInferLen(containerLen, d.maxInitLen(), 2)) - } - if containerLen != 0 { - ft.DecMapUint8BoolL(*vp, containerLen, d) - } - } else if containerLen != 0 { - ft.DecMapUint8BoolL(rv2i(rv).(map[uint8]bool), containerLen, d) - } - d.mapEnd() -} -func (fastpathDTCborIO) DecMapUint8BoolL(v map[uint8]bool, containerLen int, d *decoderCborIO) { - if v == nil { - halt.errorInt("cannot decode into nil map[uint8]bool given stream length: ", int64(containerLen)) - } - hasLen := containerLen >= 0 - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - mk := uint8(chkOvf.UintV(d.d.DecodeUint64(), 8)) - d.mapElemValue() - v[mk] = d.d.DecodeBool() - } -} -func (d *decoderCborIO) fastpathDecMapUint64IntfR(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTCborIO - containerLen := d.mapStart(d.d.ReadMapStart()) - if rv.Kind() == reflect.Ptr { - vp, _ := rv2i(rv).(*map[uint64]interface{}) - if *vp == nil { - *vp = make(map[uint64]interface{}, decInferLen(containerLen, d.maxInitLen(), 24)) - } - if containerLen != 0 { - ft.DecMapUint64IntfL(*vp, containerLen, d) - } - } else if containerLen != 0 { - ft.DecMapUint64IntfL(rv2i(rv).(map[uint64]interface{}), containerLen, d) - } - d.mapEnd() -} -func (fastpathDTCborIO) DecMapUint64IntfL(v map[uint64]interface{}, containerLen int, d *decoderCborIO) { - if v == nil { - halt.errorInt("cannot decode into nil map[uint64]interface{} given stream length: ", int64(containerLen)) - } - var mv interface{} - mapGet := !d.h.MapValueReset && !d.h.InterfaceReset - hasLen := containerLen >= 0 - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - mk := d.d.DecodeUint64() - d.mapElemValue() - if mapGet { - mv = v[mk] - } else { - mv = nil - } - d.decode(&mv) - v[mk] = mv - } -} -func (d *decoderCborIO) fastpathDecMapUint64StringR(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTCborIO - containerLen := d.mapStart(d.d.ReadMapStart()) - if rv.Kind() == reflect.Ptr { - vp, _ := rv2i(rv).(*map[uint64]string) - if *vp == nil { - *vp = make(map[uint64]string, decInferLen(containerLen, d.maxInitLen(), 24)) - } - if containerLen != 0 { - ft.DecMapUint64StringL(*vp, containerLen, d) - } - } else if containerLen != 0 { - ft.DecMapUint64StringL(rv2i(rv).(map[uint64]string), containerLen, d) - } - d.mapEnd() -} -func (fastpathDTCborIO) DecMapUint64StringL(v map[uint64]string, containerLen int, d *decoderCborIO) { - if v == nil { - halt.errorInt("cannot decode into nil map[uint64]string given stream length: ", int64(containerLen)) - } - hasLen := containerLen >= 0 - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - mk := d.d.DecodeUint64() - d.mapElemValue() - v[mk] = d.detach2Str(d.d.DecodeStringAsBytes()) - } -} -func (d *decoderCborIO) fastpathDecMapUint64BytesR(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTCborIO - containerLen := d.mapStart(d.d.ReadMapStart()) - if rv.Kind() == reflect.Ptr { - vp, _ := rv2i(rv).(*map[uint64][]byte) - if *vp == nil { - *vp = make(map[uint64][]byte, decInferLen(containerLen, d.maxInitLen(), 32)) - } - if containerLen != 0 { - ft.DecMapUint64BytesL(*vp, containerLen, d) - } - } else if containerLen != 0 { - ft.DecMapUint64BytesL(rv2i(rv).(map[uint64][]byte), containerLen, d) - } - d.mapEnd() -} -func (fastpathDTCborIO) DecMapUint64BytesL(v map[uint64][]byte, containerLen int, d *decoderCborIO) { - if v == nil { - halt.errorInt("cannot decode into nil map[uint64][]byte given stream length: ", int64(containerLen)) - } - var mv []byte - mapGet := !d.h.MapValueReset - hasLen := containerLen >= 0 - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - mk := d.d.DecodeUint64() - d.mapElemValue() - if mapGet { - mv = v[mk] - } else { - mv = nil - } - v[mk], _ = d.decodeBytesInto(mv, false) - } -} -func (d *decoderCborIO) fastpathDecMapUint64Uint8R(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTCborIO - containerLen := d.mapStart(d.d.ReadMapStart()) - if rv.Kind() == reflect.Ptr { - vp, _ := rv2i(rv).(*map[uint64]uint8) - if *vp == nil { - *vp = make(map[uint64]uint8, decInferLen(containerLen, d.maxInitLen(), 9)) - } - if containerLen != 0 { - ft.DecMapUint64Uint8L(*vp, containerLen, d) - } - } else if containerLen != 0 { - ft.DecMapUint64Uint8L(rv2i(rv).(map[uint64]uint8), containerLen, d) - } - d.mapEnd() -} -func (fastpathDTCborIO) DecMapUint64Uint8L(v map[uint64]uint8, containerLen int, d *decoderCborIO) { - if v == nil { - halt.errorInt("cannot decode into nil map[uint64]uint8 given stream length: ", int64(containerLen)) - } - hasLen := containerLen >= 0 - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - mk := d.d.DecodeUint64() - d.mapElemValue() - v[mk] = uint8(chkOvf.UintV(d.d.DecodeUint64(), 8)) - } -} -func (d *decoderCborIO) fastpathDecMapUint64Uint64R(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTCborIO - containerLen := d.mapStart(d.d.ReadMapStart()) - if rv.Kind() == reflect.Ptr { - vp, _ := rv2i(rv).(*map[uint64]uint64) - if *vp == nil { - *vp = make(map[uint64]uint64, decInferLen(containerLen, d.maxInitLen(), 16)) - } - if containerLen != 0 { - ft.DecMapUint64Uint64L(*vp, containerLen, d) - } - } else if containerLen != 0 { - ft.DecMapUint64Uint64L(rv2i(rv).(map[uint64]uint64), containerLen, d) - } - d.mapEnd() -} -func (fastpathDTCborIO) DecMapUint64Uint64L(v map[uint64]uint64, containerLen int, d *decoderCborIO) { - if v == nil { - halt.errorInt("cannot decode into nil map[uint64]uint64 given stream length: ", int64(containerLen)) - } - hasLen := containerLen >= 0 - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - mk := d.d.DecodeUint64() - d.mapElemValue() - v[mk] = d.d.DecodeUint64() - } -} -func (d *decoderCborIO) fastpathDecMapUint64IntR(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTCborIO - containerLen := d.mapStart(d.d.ReadMapStart()) - if rv.Kind() == reflect.Ptr { - vp, _ := rv2i(rv).(*map[uint64]int) - if *vp == nil { - *vp = make(map[uint64]int, decInferLen(containerLen, d.maxInitLen(), 16)) - } - if containerLen != 0 { - ft.DecMapUint64IntL(*vp, containerLen, d) - } - } else if containerLen != 0 { - ft.DecMapUint64IntL(rv2i(rv).(map[uint64]int), containerLen, d) - } - d.mapEnd() -} -func (fastpathDTCborIO) DecMapUint64IntL(v map[uint64]int, containerLen int, d *decoderCborIO) { - if v == nil { - halt.errorInt("cannot decode into nil map[uint64]int given stream length: ", int64(containerLen)) - } - hasLen := containerLen >= 0 - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - mk := d.d.DecodeUint64() - d.mapElemValue() - v[mk] = int(chkOvf.IntV(d.d.DecodeInt64(), intBitsize)) - } -} -func (d *decoderCborIO) fastpathDecMapUint64Int32R(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTCborIO - containerLen := d.mapStart(d.d.ReadMapStart()) - if rv.Kind() == reflect.Ptr { - vp, _ := rv2i(rv).(*map[uint64]int32) - if *vp == nil { - *vp = make(map[uint64]int32, decInferLen(containerLen, d.maxInitLen(), 12)) - } - if containerLen != 0 { - ft.DecMapUint64Int32L(*vp, containerLen, d) - } - } else if containerLen != 0 { - ft.DecMapUint64Int32L(rv2i(rv).(map[uint64]int32), containerLen, d) - } - d.mapEnd() -} -func (fastpathDTCborIO) DecMapUint64Int32L(v map[uint64]int32, containerLen int, d *decoderCborIO) { - if v == nil { - halt.errorInt("cannot decode into nil map[uint64]int32 given stream length: ", int64(containerLen)) - } - hasLen := containerLen >= 0 - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - mk := d.d.DecodeUint64() - d.mapElemValue() - v[mk] = int32(chkOvf.IntV(d.d.DecodeInt64(), 32)) - } -} -func (d *decoderCborIO) fastpathDecMapUint64Float64R(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTCborIO - containerLen := d.mapStart(d.d.ReadMapStart()) - if rv.Kind() == reflect.Ptr { - vp, _ := rv2i(rv).(*map[uint64]float64) - if *vp == nil { - *vp = make(map[uint64]float64, decInferLen(containerLen, d.maxInitLen(), 16)) - } - if containerLen != 0 { - ft.DecMapUint64Float64L(*vp, containerLen, d) - } - } else if containerLen != 0 { - ft.DecMapUint64Float64L(rv2i(rv).(map[uint64]float64), containerLen, d) - } - d.mapEnd() -} -func (fastpathDTCborIO) DecMapUint64Float64L(v map[uint64]float64, containerLen int, d *decoderCborIO) { - if v == nil { - halt.errorInt("cannot decode into nil map[uint64]float64 given stream length: ", int64(containerLen)) - } - hasLen := containerLen >= 0 - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - mk := d.d.DecodeUint64() - d.mapElemValue() - v[mk] = d.d.DecodeFloat64() - } -} -func (d *decoderCborIO) fastpathDecMapUint64BoolR(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTCborIO - containerLen := d.mapStart(d.d.ReadMapStart()) - if rv.Kind() == reflect.Ptr { - vp, _ := rv2i(rv).(*map[uint64]bool) - if *vp == nil { - *vp = make(map[uint64]bool, decInferLen(containerLen, d.maxInitLen(), 9)) - } - if containerLen != 0 { - ft.DecMapUint64BoolL(*vp, containerLen, d) - } - } else if containerLen != 0 { - ft.DecMapUint64BoolL(rv2i(rv).(map[uint64]bool), containerLen, d) - } - d.mapEnd() -} -func (fastpathDTCborIO) DecMapUint64BoolL(v map[uint64]bool, containerLen int, d *decoderCborIO) { - if v == nil { - halt.errorInt("cannot decode into nil map[uint64]bool given stream length: ", int64(containerLen)) - } - hasLen := containerLen >= 0 - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - mk := d.d.DecodeUint64() - d.mapElemValue() - v[mk] = d.d.DecodeBool() - } -} -func (d *decoderCborIO) fastpathDecMapIntIntfR(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTCborIO - containerLen := d.mapStart(d.d.ReadMapStart()) - if rv.Kind() == reflect.Ptr { - vp, _ := rv2i(rv).(*map[int]interface{}) - if *vp == nil { - *vp = make(map[int]interface{}, decInferLen(containerLen, d.maxInitLen(), 24)) - } - if containerLen != 0 { - ft.DecMapIntIntfL(*vp, containerLen, d) - } - } else if containerLen != 0 { - ft.DecMapIntIntfL(rv2i(rv).(map[int]interface{}), containerLen, d) - } - d.mapEnd() -} -func (fastpathDTCborIO) DecMapIntIntfL(v map[int]interface{}, containerLen int, d *decoderCborIO) { - if v == nil { - halt.errorInt("cannot decode into nil map[int]interface{} given stream length: ", int64(containerLen)) - } - var mv interface{} - mapGet := !d.h.MapValueReset && !d.h.InterfaceReset - hasLen := containerLen >= 0 - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - mk := int(chkOvf.IntV(d.d.DecodeInt64(), intBitsize)) - d.mapElemValue() - if mapGet { - mv = v[mk] - } else { - mv = nil - } - d.decode(&mv) - v[mk] = mv - } -} -func (d *decoderCborIO) fastpathDecMapIntStringR(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTCborIO - containerLen := d.mapStart(d.d.ReadMapStart()) - if rv.Kind() == reflect.Ptr { - vp, _ := rv2i(rv).(*map[int]string) - if *vp == nil { - *vp = make(map[int]string, decInferLen(containerLen, d.maxInitLen(), 24)) - } - if containerLen != 0 { - ft.DecMapIntStringL(*vp, containerLen, d) - } - } else if containerLen != 0 { - ft.DecMapIntStringL(rv2i(rv).(map[int]string), containerLen, d) - } - d.mapEnd() -} -func (fastpathDTCborIO) DecMapIntStringL(v map[int]string, containerLen int, d *decoderCborIO) { - if v == nil { - halt.errorInt("cannot decode into nil map[int]string given stream length: ", int64(containerLen)) - } - hasLen := containerLen >= 0 - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - mk := int(chkOvf.IntV(d.d.DecodeInt64(), intBitsize)) - d.mapElemValue() - v[mk] = d.detach2Str(d.d.DecodeStringAsBytes()) - } -} -func (d *decoderCborIO) fastpathDecMapIntBytesR(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTCborIO - containerLen := d.mapStart(d.d.ReadMapStart()) - if rv.Kind() == reflect.Ptr { - vp, _ := rv2i(rv).(*map[int][]byte) - if *vp == nil { - *vp = make(map[int][]byte, decInferLen(containerLen, d.maxInitLen(), 32)) - } - if containerLen != 0 { - ft.DecMapIntBytesL(*vp, containerLen, d) - } - } else if containerLen != 0 { - ft.DecMapIntBytesL(rv2i(rv).(map[int][]byte), containerLen, d) - } - d.mapEnd() -} -func (fastpathDTCborIO) DecMapIntBytesL(v map[int][]byte, containerLen int, d *decoderCborIO) { - if v == nil { - halt.errorInt("cannot decode into nil map[int][]byte given stream length: ", int64(containerLen)) - } - var mv []byte - mapGet := !d.h.MapValueReset - hasLen := containerLen >= 0 - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - mk := int(chkOvf.IntV(d.d.DecodeInt64(), intBitsize)) - d.mapElemValue() - if mapGet { - mv = v[mk] - } else { - mv = nil - } - v[mk], _ = d.decodeBytesInto(mv, false) - } -} -func (d *decoderCborIO) fastpathDecMapIntUint8R(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTCborIO - containerLen := d.mapStart(d.d.ReadMapStart()) - if rv.Kind() == reflect.Ptr { - vp, _ := rv2i(rv).(*map[int]uint8) - if *vp == nil { - *vp = make(map[int]uint8, decInferLen(containerLen, d.maxInitLen(), 9)) - } - if containerLen != 0 { - ft.DecMapIntUint8L(*vp, containerLen, d) - } - } else if containerLen != 0 { - ft.DecMapIntUint8L(rv2i(rv).(map[int]uint8), containerLen, d) - } - d.mapEnd() -} -func (fastpathDTCborIO) DecMapIntUint8L(v map[int]uint8, containerLen int, d *decoderCborIO) { - if v == nil { - halt.errorInt("cannot decode into nil map[int]uint8 given stream length: ", int64(containerLen)) - } - hasLen := containerLen >= 0 - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - mk := int(chkOvf.IntV(d.d.DecodeInt64(), intBitsize)) - d.mapElemValue() - v[mk] = uint8(chkOvf.UintV(d.d.DecodeUint64(), 8)) - } -} -func (d *decoderCborIO) fastpathDecMapIntUint64R(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTCborIO - containerLen := d.mapStart(d.d.ReadMapStart()) - if rv.Kind() == reflect.Ptr { - vp, _ := rv2i(rv).(*map[int]uint64) - if *vp == nil { - *vp = make(map[int]uint64, decInferLen(containerLen, d.maxInitLen(), 16)) - } - if containerLen != 0 { - ft.DecMapIntUint64L(*vp, containerLen, d) - } - } else if containerLen != 0 { - ft.DecMapIntUint64L(rv2i(rv).(map[int]uint64), containerLen, d) - } - d.mapEnd() -} -func (fastpathDTCborIO) DecMapIntUint64L(v map[int]uint64, containerLen int, d *decoderCborIO) { - if v == nil { - halt.errorInt("cannot decode into nil map[int]uint64 given stream length: ", int64(containerLen)) - } - hasLen := containerLen >= 0 - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - mk := int(chkOvf.IntV(d.d.DecodeInt64(), intBitsize)) - d.mapElemValue() - v[mk] = d.d.DecodeUint64() - } -} -func (d *decoderCborIO) fastpathDecMapIntIntR(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTCborIO - containerLen := d.mapStart(d.d.ReadMapStart()) - if rv.Kind() == reflect.Ptr { - vp, _ := rv2i(rv).(*map[int]int) - if *vp == nil { - *vp = make(map[int]int, decInferLen(containerLen, d.maxInitLen(), 16)) - } - if containerLen != 0 { - ft.DecMapIntIntL(*vp, containerLen, d) - } - } else if containerLen != 0 { - ft.DecMapIntIntL(rv2i(rv).(map[int]int), containerLen, d) - } - d.mapEnd() -} -func (fastpathDTCborIO) DecMapIntIntL(v map[int]int, containerLen int, d *decoderCborIO) { - if v == nil { - halt.errorInt("cannot decode into nil map[int]int given stream length: ", int64(containerLen)) - } - hasLen := containerLen >= 0 - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - mk := int(chkOvf.IntV(d.d.DecodeInt64(), intBitsize)) - d.mapElemValue() - v[mk] = int(chkOvf.IntV(d.d.DecodeInt64(), intBitsize)) - } -} -func (d *decoderCborIO) fastpathDecMapIntInt32R(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTCborIO - containerLen := d.mapStart(d.d.ReadMapStart()) - if rv.Kind() == reflect.Ptr { - vp, _ := rv2i(rv).(*map[int]int32) - if *vp == nil { - *vp = make(map[int]int32, decInferLen(containerLen, d.maxInitLen(), 12)) - } - if containerLen != 0 { - ft.DecMapIntInt32L(*vp, containerLen, d) - } - } else if containerLen != 0 { - ft.DecMapIntInt32L(rv2i(rv).(map[int]int32), containerLen, d) - } - d.mapEnd() -} -func (fastpathDTCborIO) DecMapIntInt32L(v map[int]int32, containerLen int, d *decoderCborIO) { - if v == nil { - halt.errorInt("cannot decode into nil map[int]int32 given stream length: ", int64(containerLen)) - } - hasLen := containerLen >= 0 - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - mk := int(chkOvf.IntV(d.d.DecodeInt64(), intBitsize)) - d.mapElemValue() - v[mk] = int32(chkOvf.IntV(d.d.DecodeInt64(), 32)) - } -} -func (d *decoderCborIO) fastpathDecMapIntFloat64R(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTCborIO - containerLen := d.mapStart(d.d.ReadMapStart()) - if rv.Kind() == reflect.Ptr { - vp, _ := rv2i(rv).(*map[int]float64) - if *vp == nil { - *vp = make(map[int]float64, decInferLen(containerLen, d.maxInitLen(), 16)) - } - if containerLen != 0 { - ft.DecMapIntFloat64L(*vp, containerLen, d) - } - } else if containerLen != 0 { - ft.DecMapIntFloat64L(rv2i(rv).(map[int]float64), containerLen, d) - } - d.mapEnd() -} -func (fastpathDTCborIO) DecMapIntFloat64L(v map[int]float64, containerLen int, d *decoderCborIO) { - if v == nil { - halt.errorInt("cannot decode into nil map[int]float64 given stream length: ", int64(containerLen)) - } - hasLen := containerLen >= 0 - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - mk := int(chkOvf.IntV(d.d.DecodeInt64(), intBitsize)) - d.mapElemValue() - v[mk] = d.d.DecodeFloat64() - } -} -func (d *decoderCborIO) fastpathDecMapIntBoolR(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTCborIO - containerLen := d.mapStart(d.d.ReadMapStart()) - if rv.Kind() == reflect.Ptr { - vp, _ := rv2i(rv).(*map[int]bool) - if *vp == nil { - *vp = make(map[int]bool, decInferLen(containerLen, d.maxInitLen(), 9)) - } - if containerLen != 0 { - ft.DecMapIntBoolL(*vp, containerLen, d) - } - } else if containerLen != 0 { - ft.DecMapIntBoolL(rv2i(rv).(map[int]bool), containerLen, d) - } - d.mapEnd() -} -func (fastpathDTCborIO) DecMapIntBoolL(v map[int]bool, containerLen int, d *decoderCborIO) { - if v == nil { - halt.errorInt("cannot decode into nil map[int]bool given stream length: ", int64(containerLen)) - } - hasLen := containerLen >= 0 - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - mk := int(chkOvf.IntV(d.d.DecodeInt64(), intBitsize)) - d.mapElemValue() - v[mk] = d.d.DecodeBool() - } -} -func (d *decoderCborIO) fastpathDecMapInt32IntfR(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTCborIO - containerLen := d.mapStart(d.d.ReadMapStart()) - if rv.Kind() == reflect.Ptr { - vp, _ := rv2i(rv).(*map[int32]interface{}) - if *vp == nil { - *vp = make(map[int32]interface{}, decInferLen(containerLen, d.maxInitLen(), 20)) - } - if containerLen != 0 { - ft.DecMapInt32IntfL(*vp, containerLen, d) - } - } else if containerLen != 0 { - ft.DecMapInt32IntfL(rv2i(rv).(map[int32]interface{}), containerLen, d) - } - d.mapEnd() -} -func (fastpathDTCborIO) DecMapInt32IntfL(v map[int32]interface{}, containerLen int, d *decoderCborIO) { - if v == nil { - halt.errorInt("cannot decode into nil map[int32]interface{} given stream length: ", int64(containerLen)) - } - var mv interface{} - mapGet := !d.h.MapValueReset && !d.h.InterfaceReset - hasLen := containerLen >= 0 - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - mk := int32(chkOvf.IntV(d.d.DecodeInt64(), 32)) - d.mapElemValue() - if mapGet { - mv = v[mk] - } else { - mv = nil - } - d.decode(&mv) - v[mk] = mv - } -} -func (d *decoderCborIO) fastpathDecMapInt32StringR(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTCborIO - containerLen := d.mapStart(d.d.ReadMapStart()) - if rv.Kind() == reflect.Ptr { - vp, _ := rv2i(rv).(*map[int32]string) - if *vp == nil { - *vp = make(map[int32]string, decInferLen(containerLen, d.maxInitLen(), 20)) - } - if containerLen != 0 { - ft.DecMapInt32StringL(*vp, containerLen, d) - } - } else if containerLen != 0 { - ft.DecMapInt32StringL(rv2i(rv).(map[int32]string), containerLen, d) - } - d.mapEnd() -} -func (fastpathDTCborIO) DecMapInt32StringL(v map[int32]string, containerLen int, d *decoderCborIO) { - if v == nil { - halt.errorInt("cannot decode into nil map[int32]string given stream length: ", int64(containerLen)) - } - hasLen := containerLen >= 0 - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - mk := int32(chkOvf.IntV(d.d.DecodeInt64(), 32)) - d.mapElemValue() - v[mk] = d.detach2Str(d.d.DecodeStringAsBytes()) - } -} -func (d *decoderCborIO) fastpathDecMapInt32BytesR(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTCborIO - containerLen := d.mapStart(d.d.ReadMapStart()) - if rv.Kind() == reflect.Ptr { - vp, _ := rv2i(rv).(*map[int32][]byte) - if *vp == nil { - *vp = make(map[int32][]byte, decInferLen(containerLen, d.maxInitLen(), 28)) - } - if containerLen != 0 { - ft.DecMapInt32BytesL(*vp, containerLen, d) - } - } else if containerLen != 0 { - ft.DecMapInt32BytesL(rv2i(rv).(map[int32][]byte), containerLen, d) - } - d.mapEnd() -} -func (fastpathDTCborIO) DecMapInt32BytesL(v map[int32][]byte, containerLen int, d *decoderCborIO) { - if v == nil { - halt.errorInt("cannot decode into nil map[int32][]byte given stream length: ", int64(containerLen)) - } - var mv []byte - mapGet := !d.h.MapValueReset - hasLen := containerLen >= 0 - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - mk := int32(chkOvf.IntV(d.d.DecodeInt64(), 32)) - d.mapElemValue() - if mapGet { - mv = v[mk] - } else { - mv = nil - } - v[mk], _ = d.decodeBytesInto(mv, false) - } -} -func (d *decoderCborIO) fastpathDecMapInt32Uint8R(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTCborIO - containerLen := d.mapStart(d.d.ReadMapStart()) - if rv.Kind() == reflect.Ptr { - vp, _ := rv2i(rv).(*map[int32]uint8) - if *vp == nil { - *vp = make(map[int32]uint8, decInferLen(containerLen, d.maxInitLen(), 5)) - } - if containerLen != 0 { - ft.DecMapInt32Uint8L(*vp, containerLen, d) - } - } else if containerLen != 0 { - ft.DecMapInt32Uint8L(rv2i(rv).(map[int32]uint8), containerLen, d) - } - d.mapEnd() -} -func (fastpathDTCborIO) DecMapInt32Uint8L(v map[int32]uint8, containerLen int, d *decoderCborIO) { - if v == nil { - halt.errorInt("cannot decode into nil map[int32]uint8 given stream length: ", int64(containerLen)) - } - hasLen := containerLen >= 0 - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - mk := int32(chkOvf.IntV(d.d.DecodeInt64(), 32)) - d.mapElemValue() - v[mk] = uint8(chkOvf.UintV(d.d.DecodeUint64(), 8)) - } -} -func (d *decoderCborIO) fastpathDecMapInt32Uint64R(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTCborIO - containerLen := d.mapStart(d.d.ReadMapStart()) - if rv.Kind() == reflect.Ptr { - vp, _ := rv2i(rv).(*map[int32]uint64) - if *vp == nil { - *vp = make(map[int32]uint64, decInferLen(containerLen, d.maxInitLen(), 12)) - } - if containerLen != 0 { - ft.DecMapInt32Uint64L(*vp, containerLen, d) - } - } else if containerLen != 0 { - ft.DecMapInt32Uint64L(rv2i(rv).(map[int32]uint64), containerLen, d) - } - d.mapEnd() -} -func (fastpathDTCborIO) DecMapInt32Uint64L(v map[int32]uint64, containerLen int, d *decoderCborIO) { - if v == nil { - halt.errorInt("cannot decode into nil map[int32]uint64 given stream length: ", int64(containerLen)) - } - hasLen := containerLen >= 0 - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - mk := int32(chkOvf.IntV(d.d.DecodeInt64(), 32)) - d.mapElemValue() - v[mk] = d.d.DecodeUint64() - } -} -func (d *decoderCborIO) fastpathDecMapInt32IntR(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTCborIO - containerLen := d.mapStart(d.d.ReadMapStart()) - if rv.Kind() == reflect.Ptr { - vp, _ := rv2i(rv).(*map[int32]int) - if *vp == nil { - *vp = make(map[int32]int, decInferLen(containerLen, d.maxInitLen(), 12)) - } - if containerLen != 0 { - ft.DecMapInt32IntL(*vp, containerLen, d) - } - } else if containerLen != 0 { - ft.DecMapInt32IntL(rv2i(rv).(map[int32]int), containerLen, d) - } - d.mapEnd() -} -func (fastpathDTCborIO) DecMapInt32IntL(v map[int32]int, containerLen int, d *decoderCborIO) { - if v == nil { - halt.errorInt("cannot decode into nil map[int32]int given stream length: ", int64(containerLen)) - } - hasLen := containerLen >= 0 - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - mk := int32(chkOvf.IntV(d.d.DecodeInt64(), 32)) - d.mapElemValue() - v[mk] = int(chkOvf.IntV(d.d.DecodeInt64(), intBitsize)) - } -} -func (d *decoderCborIO) fastpathDecMapInt32Int32R(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTCborIO - containerLen := d.mapStart(d.d.ReadMapStart()) - if rv.Kind() == reflect.Ptr { - vp, _ := rv2i(rv).(*map[int32]int32) - if *vp == nil { - *vp = make(map[int32]int32, decInferLen(containerLen, d.maxInitLen(), 8)) - } - if containerLen != 0 { - ft.DecMapInt32Int32L(*vp, containerLen, d) - } - } else if containerLen != 0 { - ft.DecMapInt32Int32L(rv2i(rv).(map[int32]int32), containerLen, d) - } - d.mapEnd() -} -func (fastpathDTCborIO) DecMapInt32Int32L(v map[int32]int32, containerLen int, d *decoderCborIO) { - if v == nil { - halt.errorInt("cannot decode into nil map[int32]int32 given stream length: ", int64(containerLen)) - } - hasLen := containerLen >= 0 - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - mk := int32(chkOvf.IntV(d.d.DecodeInt64(), 32)) - d.mapElemValue() - v[mk] = int32(chkOvf.IntV(d.d.DecodeInt64(), 32)) - } -} -func (d *decoderCborIO) fastpathDecMapInt32Float64R(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTCborIO - containerLen := d.mapStart(d.d.ReadMapStart()) - if rv.Kind() == reflect.Ptr { - vp, _ := rv2i(rv).(*map[int32]float64) - if *vp == nil { - *vp = make(map[int32]float64, decInferLen(containerLen, d.maxInitLen(), 12)) - } - if containerLen != 0 { - ft.DecMapInt32Float64L(*vp, containerLen, d) - } - } else if containerLen != 0 { - ft.DecMapInt32Float64L(rv2i(rv).(map[int32]float64), containerLen, d) - } - d.mapEnd() -} -func (fastpathDTCborIO) DecMapInt32Float64L(v map[int32]float64, containerLen int, d *decoderCborIO) { - if v == nil { - halt.errorInt("cannot decode into nil map[int32]float64 given stream length: ", int64(containerLen)) - } - hasLen := containerLen >= 0 - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - mk := int32(chkOvf.IntV(d.d.DecodeInt64(), 32)) - d.mapElemValue() - v[mk] = d.d.DecodeFloat64() - } -} -func (d *decoderCborIO) fastpathDecMapInt32BoolR(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTCborIO - containerLen := d.mapStart(d.d.ReadMapStart()) - if rv.Kind() == reflect.Ptr { - vp, _ := rv2i(rv).(*map[int32]bool) - if *vp == nil { - *vp = make(map[int32]bool, decInferLen(containerLen, d.maxInitLen(), 5)) - } - if containerLen != 0 { - ft.DecMapInt32BoolL(*vp, containerLen, d) - } - } else if containerLen != 0 { - ft.DecMapInt32BoolL(rv2i(rv).(map[int32]bool), containerLen, d) - } - d.mapEnd() -} -func (fastpathDTCborIO) DecMapInt32BoolL(v map[int32]bool, containerLen int, d *decoderCborIO) { - if v == nil { - halt.errorInt("cannot decode into nil map[int32]bool given stream length: ", int64(containerLen)) - } - hasLen := containerLen >= 0 - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - mk := int32(chkOvf.IntV(d.d.DecodeInt64(), 32)) - d.mapElemValue() - v[mk] = d.d.DecodeBool() - } -} diff --git a/vendor/github.com/ugorji/go/codec/cbor.go b/vendor/github.com/ugorji/go/codec/cbor.go deleted file mode 100644 index 2229a2b26..000000000 --- a/vendor/github.com/ugorji/go/codec/cbor.go +++ /dev/null @@ -1,995 +0,0 @@ -//go:build notmono || codec.notmono - -// Copyright (c) 2012-2020 Ugorji Nwoke. All rights reserved. -// Use of this source code is governed by a MIT license found in the LICENSE file. - -package codec - -import ( - "io" - "math" - "math/big" - "reflect" - "time" - "unicode/utf8" -) - -// ------------------- - -type cborEncDriver[T encWriter] struct { - noBuiltInTypes - encDriverNoState - encDriverNoopContainerWriter - encDriverContainerNoTrackerT - - h *CborHandle - e *encoderBase - w T - enc encoderI - - // scratch buffer for: encode time, numbers, etc - // - // RFC3339Nano uses 35 chars: 2006-01-02T15:04:05.999999999Z07:00 - b [40]byte -} - -func (e *cborEncDriver[T]) EncodeNil() { - e.w.writen1(cborBdNil) -} - -func (e *cborEncDriver[T]) EncodeBool(b bool) { - if b { - e.w.writen1(cborBdTrue) - } else { - e.w.writen1(cborBdFalse) - } -} - -func (e *cborEncDriver[T]) EncodeFloat32(f float32) { - b := math.Float32bits(f) - if e.h.OptimumSize { - if h := floatToHalfFloatBits(b); halfFloatToFloatBits(h) == b { - e.w.writen1(cborBdFloat16) - e.w.writen2(bigen.PutUint16(h)) - return - } - } - e.w.writen1(cborBdFloat32) - e.w.writen4(bigen.PutUint32(b)) -} - -func (e *cborEncDriver[T]) EncodeFloat64(f float64) { - if e.h.OptimumSize { - if f32 := float32(f); float64(f32) == f { - e.EncodeFloat32(f32) - return - } - } - e.w.writen1(cborBdFloat64) - e.w.writen8(bigen.PutUint64(math.Float64bits(f))) -} - -func (e *cborEncDriver[T]) encUint(v uint64, bd byte) { - if v <= 0x17 { - e.w.writen1(byte(v) + bd) - } else if v <= math.MaxUint8 { - e.w.writen2(bd+0x18, uint8(v)) - } else if v <= math.MaxUint16 { - e.w.writen1(bd + 0x19) - e.w.writen2(bigen.PutUint16(uint16(v))) - } else if v <= math.MaxUint32 { - e.w.writen1(bd + 0x1a) - e.w.writen4(bigen.PutUint32(uint32(v))) - } else { // if v <= math.MaxUint64 { - e.w.writen1(bd + 0x1b) - e.w.writen8(bigen.PutUint64(v)) - } -} - -func (e *cborEncDriver[T]) EncodeInt(v int64) { - if v < 0 { - e.encUint(uint64(-1-v), cborBaseNegInt) - } else { - e.encUint(uint64(v), cborBaseUint) - } -} - -func (e *cborEncDriver[T]) EncodeUint(v uint64) { - e.encUint(v, cborBaseUint) -} - -func (e *cborEncDriver[T]) encLen(bd byte, length int) { - e.encUint(uint64(length), bd) -} - -func (e *cborEncDriver[T]) EncodeTime(t time.Time) { - if t.IsZero() { - e.EncodeNil() - } else if e.h.TimeRFC3339 { - e.encUint(0, cborBaseTag) - e.encStringBytesS(cborBaseString, stringView(t.AppendFormat(e.b[:0], time.RFC3339Nano))) - } else { - e.encUint(1, cborBaseTag) - t = t.UTC().Round(time.Microsecond) - sec, nsec := t.Unix(), uint64(t.Nanosecond()) - if nsec == 0 { - e.EncodeInt(sec) - } else { - e.EncodeFloat64(float64(sec) + float64(nsec)/1e9) - } - } -} - -func (e *cborEncDriver[T]) EncodeExt(rv interface{}, basetype reflect.Type, xtag uint64, ext Ext) { - e.encUint(uint64(xtag), cborBaseTag) - if ext == SelfExt { - e.enc.encodeAs(rv, basetype, false) - } else if v := ext.ConvertExt(rv); v == nil { - e.writeNilBytes() - } else { - e.enc.encodeI(v) - } -} - -func (e *cborEncDriver[T]) EncodeRawExt(re *RawExt) { - e.encUint(uint64(re.Tag), cborBaseTag) - if re.Data != nil { - e.w.writeb(re.Data) - } else if re.Value != nil { - e.enc.encodeI(re.Value) - } else { - e.EncodeNil() - } -} - -func (e *cborEncDriver[T]) WriteArrayEmpty() { - if e.h.IndefiniteLength { - e.w.writen2(cborBdIndefiniteArray, cborBdBreak) - } else { - e.w.writen1(cborBaseArray) - // e.encLen(cborBaseArray, 0) - } -} - -func (e *cborEncDriver[T]) WriteMapEmpty() { - if e.h.IndefiniteLength { - e.w.writen2(cborBdIndefiniteMap, cborBdBreak) - } else { - e.w.writen1(cborBaseMap) - // e.encLen(cborBaseMap, 0) - } -} - -func (e *cborEncDriver[T]) WriteArrayStart(length int) { - if e.h.IndefiniteLength { - e.w.writen1(cborBdIndefiniteArray) - } else { - e.encLen(cborBaseArray, length) - } -} - -func (e *cborEncDriver[T]) WriteMapStart(length int) { - if e.h.IndefiniteLength { - e.w.writen1(cborBdIndefiniteMap) - } else { - e.encLen(cborBaseMap, length) - } -} - -func (e *cborEncDriver[T]) WriteMapEnd() { - if e.h.IndefiniteLength { - e.w.writen1(cborBdBreak) - } -} - -func (e *cborEncDriver[T]) WriteArrayEnd() { - if e.h.IndefiniteLength { - e.w.writen1(cborBdBreak) - } -} - -func (e *cborEncDriver[T]) EncodeString(v string) { - bb := cborBaseString - if e.h.StringToRaw { - bb = cborBaseBytes - } - e.encStringBytesS(bb, v) -} - -func (e *cborEncDriver[T]) EncodeStringNoEscape4Json(v string) { e.EncodeString(v) } - -func (e *cborEncDriver[T]) EncodeStringBytesRaw(v []byte) { - e.encStringBytesS(cborBaseBytes, stringView(v)) -} - -func (e *cborEncDriver[T]) encStringBytesS(bb byte, v string) { - if e.h.IndefiniteLength { - if bb == cborBaseBytes { - e.w.writen1(cborBdIndefiniteBytes) - } else { - e.w.writen1(cborBdIndefiniteString) - } - vlen := uint(len(v)) - n := max(4, min(vlen/4, 1024)) - for i := uint(0); i < vlen; { - i2 := i + n - if i2 >= vlen { - i2 = vlen - } - v2 := v[i:i2] - e.encLen(bb, len(v2)) - e.w.writestr(v2) - i = i2 - } - e.w.writen1(cborBdBreak) - } else { - e.encLen(bb, len(v)) - e.w.writestr(v) - } -} - -func (e *cborEncDriver[T]) EncodeBytes(v []byte) { - if v == nil { - e.writeNilBytes() - return - } - e.EncodeStringBytesRaw(v) -} - -func (e *cborEncDriver[T]) writeNilOr(v byte) { - if !e.h.NilCollectionToZeroLength { - v = cborBdNil - } - e.w.writen1(v) -} - -func (e *cborEncDriver[T]) writeNilArray() { - e.writeNilOr(cborBaseArray) -} - -func (e *cborEncDriver[T]) writeNilMap() { - e.writeNilOr(cborBaseMap) -} - -func (e *cborEncDriver[T]) writeNilBytes() { - e.writeNilOr(cborBaseBytes) -} - -// ---------------------- - -type cborDecDriver[T decReader] struct { - decDriverNoopContainerReader - // decDriverNoopNumberHelper - noBuiltInTypes - - h *CborHandle - d *decoderBase - r T - dec decoderI - bdAndBdread - // st bool // skip tags - // bytes bool -} - -func (d *cborDecDriver[T]) readNextBd() { - d.bd = d.r.readn1() - d.bdRead = true -} - -func (d *cborDecDriver[T]) advanceNil() (null bool) { - if !d.bdRead { - d.readNextBd() - } - if d.bd == cborBdNil || d.bd == cborBdUndefined { - d.bdRead = false - return true // null = true - } - return -} - -func (d *cborDecDriver[T]) TryNil() bool { - return d.advanceNil() -} - -// skipTags is called to skip any tags in the stream. -// -// Since any value can be tagged, then we should call skipTags -// before any value is decoded. -// -// By definition, skipTags should not be called before -// checking for break, or nil or undefined. -func (d *cborDecDriver[T]) skipTags() { - for d.bd>>5 == cborMajorTag { - d.decUint() - d.bd = d.r.readn1() - } -} - -func (d *cborDecDriver[T]) ContainerType() (vt valueType) { - if !d.bdRead { - d.readNextBd() - } - if d.h.SkipUnexpectedTags { - d.skipTags() - } - if d.bd == cborBdNil { - d.bdRead = false // always consume nil after seeing it in container type - return valueTypeNil - } - major := d.bd >> 5 - if major == cborMajorBytes { - return valueTypeBytes - } else if major == cborMajorString { - return valueTypeString - } else if major == cborMajorArray { - return valueTypeArray - } else if major == cborMajorMap { - return valueTypeMap - } - return valueTypeUnset -} - -func (d *cborDecDriver[T]) CheckBreak() (v bool) { - if !d.bdRead { - d.readNextBd() - } - if d.bd == cborBdBreak { - d.bdRead = false - v = true - } - return -} - -func (d *cborDecDriver[T]) decUint() (ui uint64) { - v := d.bd & 0x1f - if v <= 0x17 { - ui = uint64(v) - } else if v == 0x18 { - ui = uint64(d.r.readn1()) - } else if v == 0x19 { - ui = uint64(bigen.Uint16(d.r.readn2())) - } else if v == 0x1a { - ui = uint64(bigen.Uint32(d.r.readn4())) - } else if v == 0x1b { - ui = uint64(bigen.Uint64(d.r.readn8())) - } else { - halt.errorf("invalid descriptor decoding uint: %x/%s (%x)", d.bd, cbordesc(d.bd), v) - } - return -} - -func (d *cborDecDriver[T]) decLen() int { - return int(d.decUint()) -} - -func (d *cborDecDriver[T]) decFloat() (f float64, ok bool) { - ok = true - switch d.bd { - case cborBdFloat16: - f = float64(math.Float32frombits(halfFloatToFloatBits(bigen.Uint16(d.r.readn2())))) - case cborBdFloat32: - f = float64(math.Float32frombits(bigen.Uint32(d.r.readn4()))) - case cborBdFloat64: - f = math.Float64frombits(bigen.Uint64(d.r.readn8())) - default: - if d.bd>>5 == cborMajorTag { - // extension tag for bignum/decimal - switch d.bd & 0x1f { // tag - case 2: - f = d.decTagBigIntAsFloat(false) - case 3: - f = d.decTagBigIntAsFloat(true) - case 4: - f = d.decTagBigFloatAsFloat(true) - case 5: - f = d.decTagBigFloatAsFloat(false) - default: - ok = false - } - } else { - ok = false - } - } - return -} - -func (d *cborDecDriver[T]) decInteger() (ui uint64, neg, ok bool) { - ok = true - switch d.bd >> 5 { - case cborMajorUint: - ui = d.decUint() - case cborMajorNegInt: - ui = d.decUint() - neg = true - default: - ok = false - } - return -} - -func (d *cborDecDriver[T]) DecodeInt64() (i int64) { - if d.advanceNil() { - return - } - if d.h.SkipUnexpectedTags { - d.skipTags() - } - v1, v2, v3 := d.decInteger() - i = decNegintPosintFloatNumberHelper{d}.int64(v1, v2, v3, true) - d.bdRead = false - return -} - -func (d *cborDecDriver[T]) DecodeUint64() (ui uint64) { - if d.advanceNil() { - return - } - if d.h.SkipUnexpectedTags { - d.skipTags() - } - ui = decNegintPosintFloatNumberHelper{d}.uint64(d.decInteger()) - d.bdRead = false - return -} - -func (d *cborDecDriver[T]) DecodeFloat64() (f float64) { - if d.advanceNil() { - return - } - if d.h.SkipUnexpectedTags { - d.skipTags() - } - v1, v2 := d.decFloat() - f = decNegintPosintFloatNumberHelper{d}.float64(v1, v2, true) - d.bdRead = false - return -} - -// bool can be decoded from bool only (single byte). -func (d *cborDecDriver[T]) DecodeBool() (b bool) { - if d.advanceNil() { - return - } - if d.h.SkipUnexpectedTags { - d.skipTags() - } - if d.bd == cborBdTrue { - b = true - } else if d.bd == cborBdFalse { - } else { - halt.errorf("not bool - %s %x/%s", msgBadDesc, d.bd, cbordesc(d.bd)) - } - d.bdRead = false - return -} - -func (d *cborDecDriver[T]) ReadMapStart() (length int) { - if d.advanceNil() { - return containerLenNil - } - if d.h.SkipUnexpectedTags { - d.skipTags() - } - d.bdRead = false - if d.bd == cborBdIndefiniteMap { - return containerLenUnknown - } - if d.bd>>5 != cborMajorMap { - halt.errorf("error reading map; got major type: %x, expected %x/%s", d.bd>>5, cborMajorMap, cbordesc(d.bd)) - } - return d.decLen() -} - -func (d *cborDecDriver[T]) ReadArrayStart() (length int) { - if d.advanceNil() { - return containerLenNil - } - if d.h.SkipUnexpectedTags { - d.skipTags() - } - d.bdRead = false - if d.bd == cborBdIndefiniteArray { - return containerLenUnknown - } - if d.bd>>5 != cborMajorArray { - halt.errorf("invalid array; got major type: %x, expect: %x/%s", d.bd>>5, cborMajorArray, cbordesc(d.bd)) - } - return d.decLen() -} - -// MARKER d.d.buf is ONLY used within DecodeBytes. -// Safe to use freely here only. - -func (d *cborDecDriver[T]) DecodeBytes() (bs []byte, state dBytesAttachState) { - if d.advanceNil() { - return - } - if d.h.SkipUnexpectedTags { - d.skipTags() - } - fnEnsureNonNilBytes := func() { - // buf is nil at first. Ensure a non-nil value is returned. - if bs == nil { - bs = zeroByteSlice - state = dBytesDetach - } - } - if d.bd == cborBdIndefiniteBytes || d.bd == cborBdIndefiniteString { - major := d.bd >> 5 - val4str := d.h.ValidateUnicode && major == cborMajorString - bs = d.d.buf[:0] - d.bdRead = false - for !d.CheckBreak() { - if d.bd>>5 != major { - const msg = "malformed indefinite string/bytes %x (%s); " + - "contains chunk with major type %v, expected %v" - halt.errorf(msg, d.bd, cbordesc(d.bd), d.bd>>5, major) - } - n := uint(d.decLen()) - bs = append(bs, d.r.readx(n)...) - d.bdRead = false - if val4str && !utf8.Valid(bs[len(bs)-int(n):]) { - const msg = "indefinite-length text string contains chunk " + - "that is not a valid utf-8 sequence: 0x%x" - halt.errorf(msg, bs[len(bs)-int(n):]) - } - } - d.bdRead = false - d.d.buf = bs - state = dBytesAttachBuffer - fnEnsureNonNilBytes() - return - } - if d.bd == cborBdIndefiniteArray { - d.bdRead = false - bs = d.d.buf[:0] - for !d.CheckBreak() { - bs = append(bs, uint8(chkOvf.UintV(d.DecodeUint64(), 8))) - } - d.d.buf = bs - state = dBytesAttachBuffer - fnEnsureNonNilBytes() - return - } - var cond bool - if d.bd>>5 == cborMajorArray { - d.bdRead = false - slen := d.decLen() - bs, cond = usableByteSlice(d.d.buf, slen) - for i := 0; i < len(bs); i++ { - bs[i] = uint8(chkOvf.UintV(d.DecodeUint64(), 8)) - } - for i := len(bs); i < slen; i++ { - bs = append(bs, uint8(chkOvf.UintV(d.DecodeUint64(), 8))) - } - if cond { - d.d.buf = bs - } - state = dBytesAttachBuffer - fnEnsureNonNilBytes() - return - } - clen := d.decLen() - d.bdRead = false - bs, cond = d.r.readxb(uint(clen)) - state = d.d.attachState(cond) - return -} - -func (d *cborDecDriver[T]) DecodeStringAsBytes() (out []byte, state dBytesAttachState) { - out, state = d.DecodeBytes() - if d.h.ValidateUnicode && !utf8.Valid(out) { - halt.errorf("DecodeStringAsBytes: invalid UTF-8: %s", out) - } - return -} - -func (d *cborDecDriver[T]) DecodeTime() (t time.Time) { - if d.advanceNil() { - return - } - if d.bd>>5 != cborMajorTag { - halt.errorf("error reading tag; expected major type: %x, got: %x", cborMajorTag, d.bd>>5) - } - xtag := d.decUint() - d.bdRead = false - return d.decodeTime(xtag) -} - -func (d *cborDecDriver[T]) decodeTime(xtag uint64) (t time.Time) { - switch xtag { - case 0: - var err error - t, err = time.Parse(time.RFC3339, stringView(bytesOKs(d.DecodeStringAsBytes()))) - halt.onerror(err) - case 1: - f1, f2 := math.Modf(d.DecodeFloat64()) - t = time.Unix(int64(f1), int64(f2*1e9)) - default: - halt.errorf("invalid tag for time.Time - expecting 0 or 1, got 0x%x", xtag) - } - t = t.UTC().Round(time.Microsecond) - return -} - -func (d *cborDecDriver[T]) preDecodeExt(checkTag bool, xtag uint64) (realxtag uint64, ok bool) { - if d.advanceNil() { - return - } - if d.bd>>5 != cborMajorTag { - halt.errorf("error reading tag; expected major type: %x, got: %x", cborMajorTag, d.bd>>5) - } - realxtag = d.decUint() - d.bdRead = false - if checkTag && xtag != realxtag { - halt.errorf("Wrong extension tag. Got %b. Expecting: %v", realxtag, xtag) - } - ok = true - return -} - -func (d *cborDecDriver[T]) DecodeRawExt(re *RawExt) { - if realxtag, ok := d.preDecodeExt(false, 0); ok { - re.Tag = realxtag - d.dec.decode(&re.Value) - d.bdRead = false - } -} - -func (d *cborDecDriver[T]) DecodeExt(rv interface{}, basetype reflect.Type, xtag uint64, ext Ext) { - if _, ok := d.preDecodeExt(true, xtag); ok { - if ext == SelfExt { - d.dec.decodeAs(rv, basetype, false) - } else { - d.dec.interfaceExtConvertAndDecode(rv, ext) - } - d.bdRead = false - } -} - -func (d *cborDecDriver[T]) decTagBigIntAsFloat(neg bool) (f float64) { - bs, _ := d.DecodeBytes() - bi := new(big.Int).SetBytes(bs) - if neg { // neg big.Int - bi0 := bi - bi = new(big.Int).Sub(big.NewInt(-1), bi0) - } - f, _ = bi.Float64() - return -} - -func (d *cborDecDriver[T]) decTagBigFloatAsFloat(decimal bool) (f float64) { - if nn := d.r.readn1(); nn != 82 { - halt.errorf("(%d) decoding decimal/big.Float: expected 2 numbers", nn) - } - exp := d.DecodeInt64() - mant := d.DecodeInt64() - if decimal { // m*(10**e) - // MARKER: if precision/other issues crop, consider using big.Float on base 10. - // The logic is more convoluted, which is why we leverage readFloatResult for now. - rf := readFloatResult{exp: int8(exp)} - if mant >= 0 { - rf.mantissa = uint64(mant) - } else { - rf.neg = true - rf.mantissa = uint64(-mant) - } - f, _ = parseFloat64_reader(rf) - // f = float64(mant) * math.Pow10(exp) - } else { // m*(2**e) - // f = float64(mant) * math.Pow(2, exp) - bfm := new(big.Float).SetPrec(64).SetInt64(mant) - bf := new(big.Float).SetPrec(64).SetMantExp(bfm, int(exp)) - f, _ = bf.Float64() - } - return -} - -func (d *cborDecDriver[T]) DecodeNaked() { - if !d.bdRead { - d.readNextBd() - } - - n := d.d.naked() - var decodeFurther bool - switch d.bd >> 5 { - case cborMajorUint: - if d.h.SignedInteger { - n.v = valueTypeInt - n.i = d.DecodeInt64() - } else { - n.v = valueTypeUint - n.u = d.DecodeUint64() - } - case cborMajorNegInt: - n.v = valueTypeInt - n.i = d.DecodeInt64() - case cborMajorBytes: - d.d.fauxUnionReadRawBytes(d, false, d.h.RawToString) //, d.h.ZeroCopy) - case cborMajorString: - n.v = valueTypeString - n.s = d.d.detach2Str(d.DecodeStringAsBytes()) - case cborMajorArray: - n.v = valueTypeArray - decodeFurther = true - case cborMajorMap: - n.v = valueTypeMap - decodeFurther = true - case cborMajorTag: - n.v = valueTypeExt - n.u = d.decUint() - d.bdRead = false - n.l = nil - xx := d.h.getExtForTag(n.u) - if xx == nil { - switch n.u { - case 0, 1: - n.v = valueTypeTime - n.t = d.decodeTime(n.u) - case 2: - n.f = d.decTagBigIntAsFloat(false) - n.v = valueTypeFloat - case 3: - n.f = d.decTagBigIntAsFloat(true) - n.v = valueTypeFloat - case 4: - n.f = d.decTagBigFloatAsFloat(true) - n.v = valueTypeFloat - case 5: - n.f = d.decTagBigFloatAsFloat(false) - n.v = valueTypeFloat - case 55799: // skip - d.DecodeNaked() - default: - if d.h.SkipUnexpectedTags { - d.DecodeNaked() - } - // else we will use standard mode to decode ext e.g. into a RawExt - } - return - } - // if n.u == 0 || n.u == 1 { - // d.bdRead = false - // n.v = valueTypeTime - // n.t = d.decodeTime(n.u) - // } else if d.h.SkipUnexpectedTags && d.h.getExtForTag(n.u) == nil { - // // d.skipTags() // no need to call this - tags already skipped - // d.bdRead = false - // d.DecodeNaked() - // return // return when done (as true recursive function) - // } - case cborMajorSimpleOrFloat: - switch d.bd { - case cborBdNil, cborBdUndefined: - n.v = valueTypeNil - case cborBdFalse: - n.v = valueTypeBool - n.b = false - case cborBdTrue: - n.v = valueTypeBool - n.b = true - case cborBdFloat16, cborBdFloat32, cborBdFloat64: - n.v = valueTypeFloat - n.f = d.DecodeFloat64() - default: - halt.errorf("decodeNaked: Unrecognized d.bd: 0x%x", d.bd) - } - default: // should never happen - halt.errorf("decodeNaked: Unrecognized d.bd: 0x%x", d.bd) - } - if !decodeFurther { - d.bdRead = false - } -} - -func (d *cborDecDriver[T]) uintBytes() (v []byte, ui uint64) { - // this is only used by nextValueBytes, so it's ok to - // use readx and bigenstd here. - switch vv := d.bd & 0x1f; vv { - case 0x18: - v = d.r.readx(1) - ui = uint64(v[0]) - case 0x19: - v = d.r.readx(2) - ui = uint64(bigenstd.Uint16(v)) - case 0x1a: - v = d.r.readx(4) - ui = uint64(bigenstd.Uint32(v)) - case 0x1b: - v = d.r.readx(8) - ui = uint64(bigenstd.Uint64(v)) - default: - if vv > 0x1b { - halt.errorf("invalid descriptor decoding uint: %x/%s", d.bd, cbordesc(d.bd)) - } - ui = uint64(vv) - } - return -} - -func (d *cborDecDriver[T]) nextValueBytes() (v []byte) { - if !d.bdRead { - d.readNextBd() - } - d.r.startRecording() - d.nextValueBytesBdReadR() - v = d.r.stopRecording() - d.bdRead = false - return -} - -// func (d *cborDecDriver[T]) nextValueBytesR(v0 []byte) (v []byte) { -// d.readNextBd() -// v0 = append(v0, d.bd) -// d.r.startRecording(v0) -// d.nextValueBytesBdReadR() -// v = d.r.stopRecording() -// return -// } - -func (d *cborDecDriver[T]) nextValueBytesBdReadR() { - // var bs []byte - var ui uint64 - - switch d.bd >> 5 { - case cborMajorUint, cborMajorNegInt: - d.uintBytes() - case cborMajorString, cborMajorBytes: - if d.bd == cborBdIndefiniteBytes || d.bd == cborBdIndefiniteString { - for { - d.readNextBd() - if d.bd == cborBdBreak { - break - } - _, ui = d.uintBytes() - d.r.skip(uint(ui)) - } - } else { - _, ui = d.uintBytes() - d.r.skip(uint(ui)) - } - case cborMajorArray: - if d.bd == cborBdIndefiniteArray { - for { - d.readNextBd() - if d.bd == cborBdBreak { - break - } - d.nextValueBytesBdReadR() - } - } else { - _, ui = d.uintBytes() - for i := uint64(0); i < ui; i++ { - d.readNextBd() - d.nextValueBytesBdReadR() - } - } - case cborMajorMap: - if d.bd == cborBdIndefiniteMap { - for { - d.readNextBd() - if d.bd == cborBdBreak { - break - } - d.nextValueBytesBdReadR() - d.readNextBd() - d.nextValueBytesBdReadR() - } - } else { - _, ui = d.uintBytes() - for i := uint64(0); i < ui; i++ { - d.readNextBd() - d.nextValueBytesBdReadR() - d.readNextBd() - d.nextValueBytesBdReadR() - } - } - case cborMajorTag: - d.uintBytes() - d.readNextBd() - d.nextValueBytesBdReadR() - case cborMajorSimpleOrFloat: - switch d.bd { - case cborBdNil, cborBdUndefined, cborBdFalse, cborBdTrue: // pass - case cborBdFloat16: - d.r.skip(2) - case cborBdFloat32: - d.r.skip(4) - case cborBdFloat64: - d.r.skip(8) - default: - halt.errorf("nextValueBytes: Unrecognized d.bd: 0x%x", d.bd) - } - default: // should never happen - halt.errorf("nextValueBytes: Unrecognized d.bd: 0x%x", d.bd) - } - return -} - -func (d *cborDecDriver[T]) reset() { - d.bdAndBdread.reset() - // d.st = d.h.SkipUnexpectedTags -} - -// ---- -// -// The following below are similar across all format files (except for the format name). -// -// We keep them together here, so that we can easily copy and compare. - -// ---- - -func (d *cborEncDriver[T]) init(hh Handle, shared *encoderBase, enc encoderI) (fp interface{}) { - callMake(&d.w) - d.h = hh.(*CborHandle) - d.e = shared - if shared.bytes { - fp = cborFpEncBytes - } else { - fp = cborFpEncIO - } - // d.w.init() - d.init2(enc) - return -} - -func (e *cborEncDriver[T]) writeBytesAsis(b []byte) { e.w.writeb(b) } - -// func (e *cborEncDriver[T]) writeStringAsisDblQuoted(v string) { e.w.writeqstr(v) } - -func (e *cborEncDriver[T]) writerEnd() { e.w.end() } - -func (e *cborEncDriver[T]) resetOutBytes(out *[]byte) { - e.w.resetBytes(*out, out) -} - -func (e *cborEncDriver[T]) resetOutIO(out io.Writer) { - e.w.resetIO(out, e.h.WriterBufferSize, &e.e.blist) -} - -// ---- - -func (d *cborDecDriver[T]) init(hh Handle, shared *decoderBase, dec decoderI) (fp interface{}) { - callMake(&d.r) - d.h = hh.(*CborHandle) - d.d = shared - if shared.bytes { - fp = cborFpDecBytes - } else { - fp = cborFpDecIO - } - // d.r.init() - d.init2(dec) - return -} - -func (d *cborDecDriver[T]) NumBytesRead() int { - return int(d.r.numread()) -} - -func (d *cborDecDriver[T]) resetInBytes(in []byte) { - d.r.resetBytes(in) -} - -func (d *cborDecDriver[T]) resetInIO(r io.Reader) { - d.r.resetIO(r, d.h.ReaderBufferSize, d.h.MaxInitLen, &d.d.blist) -} - -// ---- (custom stanza) - -func (d *cborDecDriver[T]) descBd() string { - return sprintf("%v (%s)", d.bd, cbordesc(d.bd)) -} - -func (d *cborDecDriver[T]) DecodeFloat32() (f float32) { - return float32(chkOvf.Float32V(d.DecodeFloat64())) -} - -func (d *cborEncDriver[T]) init2(enc encoderI) { - d.enc = enc -} - -func (d *cborDecDriver[T]) init2(dec decoderI) { - d.dec = dec - // d.d.cbor = true -} diff --git a/vendor/github.com/ugorji/go/codec/cbor.mono.generated.go b/vendor/github.com/ugorji/go/codec/cbor.mono.generated.go deleted file mode 100644 index 572d5cb56..000000000 --- a/vendor/github.com/ugorji/go/codec/cbor.mono.generated.go +++ /dev/null @@ -1,7985 +0,0 @@ -//go:build !notmono && !codec.notmono - -// Copyright (c) 2012-2020 Ugorji Nwoke. All rights reserved. -// Use of this source code is governed by a MIT license found in the LICENSE file. - -package codec - -import ( - "encoding" - - "io" - "math" - "math/big" - "reflect" - "slices" - "sort" - "strconv" - "sync" - "time" - "unicode/utf8" -) - -type helperEncDriverCborBytes struct{} -type encFnCborBytes struct { - i encFnInfo - fe func(*encoderCborBytes, *encFnInfo, reflect.Value) -} -type encRtidFnCborBytes struct { - rtid uintptr - fn *encFnCborBytes -} -type encoderCborBytes struct { - dh helperEncDriverCborBytes - fp *fastpathEsCborBytes - e cborEncDriverBytes - encoderBase -} -type helperDecDriverCborBytes struct{} -type decFnCborBytes struct { - i decFnInfo - fd func(*decoderCborBytes, *decFnInfo, reflect.Value) -} -type decRtidFnCborBytes struct { - rtid uintptr - fn *decFnCborBytes -} -type decoderCborBytes struct { - dh helperDecDriverCborBytes - fp *fastpathDsCborBytes - d cborDecDriverBytes - decoderBase -} -type cborEncDriverBytes struct { - noBuiltInTypes - encDriverNoState - encDriverNoopContainerWriter - encDriverContainerNoTrackerT - - h *CborHandle - e *encoderBase - w bytesEncAppender - enc encoderI - - b [40]byte -} -type cborDecDriverBytes struct { - decDriverNoopContainerReader - - noBuiltInTypes - - h *CborHandle - d *decoderBase - r bytesDecReader - dec decoderI - bdAndBdread -} - -func (e *encoderCborBytes) rawExt(_ *encFnInfo, rv reflect.Value) { - if re := rv2i(rv).(*RawExt); re == nil { - e.e.EncodeNil() - } else { - e.e.EncodeRawExt(re) - } -} - -func (e *encoderCborBytes) ext(f *encFnInfo, rv reflect.Value) { - e.e.EncodeExt(rv2i(rv), f.ti.rt, f.xfTag, f.xfFn) -} - -func (e *encoderCborBytes) selferMarshal(_ *encFnInfo, rv reflect.Value) { - rv2i(rv).(Selfer).CodecEncodeSelf(&Encoder{e}) -} - -func (e *encoderCborBytes) binaryMarshal(_ *encFnInfo, rv reflect.Value) { - bs, fnerr := rv2i(rv).(encoding.BinaryMarshaler).MarshalBinary() - e.marshalRaw(bs, fnerr) -} - -func (e *encoderCborBytes) textMarshal(_ *encFnInfo, rv reflect.Value) { - bs, fnerr := rv2i(rv).(encoding.TextMarshaler).MarshalText() - e.marshalUtf8(bs, fnerr) -} - -func (e *encoderCborBytes) jsonMarshal(_ *encFnInfo, rv reflect.Value) { - bs, fnerr := rv2i(rv).(jsonMarshaler).MarshalJSON() - e.marshalAsis(bs, fnerr) -} - -func (e *encoderCborBytes) raw(_ *encFnInfo, rv reflect.Value) { - e.rawBytes(rv2i(rv).(Raw)) -} - -func (e *encoderCborBytes) encodeComplex64(v complex64) { - if imag(v) != 0 { - halt.errorf("cannot encode complex number: %v, with imaginary values: %v", any(v), any(imag(v))) - } - e.e.EncodeFloat32(real(v)) -} - -func (e *encoderCborBytes) encodeComplex128(v complex128) { - if imag(v) != 0 { - halt.errorf("cannot encode complex number: %v, with imaginary values: %v", any(v), any(imag(v))) - } - e.e.EncodeFloat64(real(v)) -} - -func (e *encoderCborBytes) kBool(_ *encFnInfo, rv reflect.Value) { - e.e.EncodeBool(rvGetBool(rv)) -} - -func (e *encoderCborBytes) kTime(_ *encFnInfo, rv reflect.Value) { - e.e.EncodeTime(rvGetTime(rv)) -} - -func (e *encoderCborBytes) kString(_ *encFnInfo, rv reflect.Value) { - e.e.EncodeString(rvGetString(rv)) -} - -func (e *encoderCborBytes) kFloat32(_ *encFnInfo, rv reflect.Value) { - e.e.EncodeFloat32(rvGetFloat32(rv)) -} - -func (e *encoderCborBytes) kFloat64(_ *encFnInfo, rv reflect.Value) { - e.e.EncodeFloat64(rvGetFloat64(rv)) -} - -func (e *encoderCborBytes) kComplex64(_ *encFnInfo, rv reflect.Value) { - e.encodeComplex64(rvGetComplex64(rv)) -} - -func (e *encoderCborBytes) kComplex128(_ *encFnInfo, rv reflect.Value) { - e.encodeComplex128(rvGetComplex128(rv)) -} - -func (e *encoderCborBytes) kInt(_ *encFnInfo, rv reflect.Value) { - e.e.EncodeInt(int64(rvGetInt(rv))) -} - -func (e *encoderCborBytes) kInt8(_ *encFnInfo, rv reflect.Value) { - e.e.EncodeInt(int64(rvGetInt8(rv))) -} - -func (e *encoderCborBytes) kInt16(_ *encFnInfo, rv reflect.Value) { - e.e.EncodeInt(int64(rvGetInt16(rv))) -} - -func (e *encoderCborBytes) kInt32(_ *encFnInfo, rv reflect.Value) { - e.e.EncodeInt(int64(rvGetInt32(rv))) -} - -func (e *encoderCborBytes) kInt64(_ *encFnInfo, rv reflect.Value) { - e.e.EncodeInt(int64(rvGetInt64(rv))) -} - -func (e *encoderCborBytes) kUint(_ *encFnInfo, rv reflect.Value) { - e.e.EncodeUint(uint64(rvGetUint(rv))) -} - -func (e *encoderCborBytes) kUint8(_ *encFnInfo, rv reflect.Value) { - e.e.EncodeUint(uint64(rvGetUint8(rv))) -} - -func (e *encoderCborBytes) kUint16(_ *encFnInfo, rv reflect.Value) { - e.e.EncodeUint(uint64(rvGetUint16(rv))) -} - -func (e *encoderCborBytes) kUint32(_ *encFnInfo, rv reflect.Value) { - e.e.EncodeUint(uint64(rvGetUint32(rv))) -} - -func (e *encoderCborBytes) kUint64(_ *encFnInfo, rv reflect.Value) { - e.e.EncodeUint(uint64(rvGetUint64(rv))) -} - -func (e *encoderCborBytes) kUintptr(_ *encFnInfo, rv reflect.Value) { - e.e.EncodeUint(uint64(rvGetUintptr(rv))) -} - -func (e *encoderCborBytes) kSeqFn(rt reflect.Type) (fn *encFnCborBytes) { - - if rt = baseRT(rt); rt.Kind() != reflect.Interface { - fn = e.fn(rt) - } - return -} - -func (e *encoderCborBytes) kArrayWMbs(rv reflect.Value, ti *typeInfo, isSlice bool) { - var l int - if isSlice { - l = rvLenSlice(rv) - } else { - l = rv.Len() - } - if l == 0 { - e.e.WriteMapEmpty() - return - } - e.haltOnMbsOddLen(l) - e.mapStart(l >> 1) - - var fn *encFnCborBytes - builtin := ti.tielem.flagEncBuiltin - if !builtin { - fn = e.kSeqFn(ti.elem) - } - - j := 0 - e.c = containerMapKey - e.e.WriteMapElemKey(true) - for { - rvv := rvArrayIndex(rv, j, ti, isSlice) - if builtin { - e.encodeIB(rv2i(baseRVRV(rvv))) - } else { - e.encodeValue(rvv, fn) - } - j++ - if j == l { - break - } - if j&1 == 0 { - e.c = containerMapKey - e.e.WriteMapElemKey(false) - } else { - e.mapElemValue() - } - } - e.c = 0 - e.e.WriteMapEnd() - -} - -func (e *encoderCborBytes) kArrayW(rv reflect.Value, ti *typeInfo, isSlice bool) { - var l int - if isSlice { - l = rvLenSlice(rv) - } else { - l = rv.Len() - } - if l <= 0 { - e.e.WriteArrayEmpty() - return - } - e.arrayStart(l) - - var fn *encFnCborBytes - if !ti.tielem.flagEncBuiltin { - fn = e.kSeqFn(ti.elem) - } - - j := 0 - e.c = containerArrayElem - e.e.WriteArrayElem(true) - builtin := ti.tielem.flagEncBuiltin - for { - rvv := rvArrayIndex(rv, j, ti, isSlice) - if builtin { - e.encodeIB(rv2i(baseRVRV(rvv))) - } else { - e.encodeValue(rvv, fn) - } - j++ - if j == l { - break - } - e.c = containerArrayElem - e.e.WriteArrayElem(false) - } - - e.c = 0 - e.e.WriteArrayEnd() -} - -func (e *encoderCborBytes) kChan(f *encFnInfo, rv reflect.Value) { - if f.ti.chandir&uint8(reflect.RecvDir) == 0 { - halt.errorStr("send-only channel cannot be encoded") - } - if !f.ti.mbs && uint8TypId == rt2id(f.ti.elem) { - e.kSliceBytesChan(rv) - return - } - rtslice := reflect.SliceOf(f.ti.elem) - rv = chanToSlice(rv, rtslice, e.h.ChanRecvTimeout) - ti := e.h.getTypeInfo(rt2id(rtslice), rtslice) - if f.ti.mbs { - e.kArrayWMbs(rv, ti, true) - } else { - e.kArrayW(rv, ti, true) - } -} - -func (e *encoderCborBytes) kSlice(f *encFnInfo, rv reflect.Value) { - if f.ti.mbs { - e.kArrayWMbs(rv, f.ti, true) - } else if f.ti.rtid == uint8SliceTypId || uint8TypId == rt2id(f.ti.elem) { - - e.e.EncodeBytes(rvGetBytes(rv)) - } else { - e.kArrayW(rv, f.ti, true) - } -} - -func (e *encoderCborBytes) kArray(f *encFnInfo, rv reflect.Value) { - if f.ti.mbs { - e.kArrayWMbs(rv, f.ti, false) - } else if handleBytesWithinKArray && uint8TypId == rt2id(f.ti.elem) { - e.e.EncodeStringBytesRaw(rvGetArrayBytes(rv, nil)) - } else { - e.kArrayW(rv, f.ti, false) - } -} - -func (e *encoderCborBytes) kSliceBytesChan(rv reflect.Value) { - - bs0 := e.blist.peek(32, true) - bs := bs0 - - irv := rv2i(rv) - ch, ok := irv.(<-chan byte) - if !ok { - ch = irv.(chan byte) - } - -L1: - switch timeout := e.h.ChanRecvTimeout; { - case timeout == 0: - for { - select { - case b := <-ch: - bs = append(bs, b) - default: - break L1 - } - } - case timeout > 0: - tt := time.NewTimer(timeout) - for { - select { - case b := <-ch: - bs = append(bs, b) - case <-tt.C: - - break L1 - } - } - default: - for b := range ch { - bs = append(bs, b) - } - } - - e.e.EncodeBytes(bs) - e.blist.put(bs) - if !byteSliceSameData(bs0, bs) { - e.blist.put(bs0) - } -} - -func (e *encoderCborBytes) kStructFieldKey(keyType valueType, encName string) { - - if keyType == valueTypeString { - e.e.EncodeString(encName) - } else if keyType == valueTypeInt { - e.e.EncodeInt(must.Int(strconv.ParseInt(encName, 10, 64))) - } else if keyType == valueTypeUint { - e.e.EncodeUint(must.Uint(strconv.ParseUint(encName, 10, 64))) - } else if keyType == valueTypeFloat { - e.e.EncodeFloat64(must.Float(strconv.ParseFloat(encName, 64))) - } else { - halt.errorStr2("invalid struct key type: ", keyType.String()) - } - -} - -func (e *encoderCborBytes) kStructSimple(f *encFnInfo, rv reflect.Value) { - _ = e.e - tisfi := f.ti.sfi.source() - - chkCirRef := e.h.CheckCircularRef - var si *structFieldInfo - var j int - - if f.ti.toArray || e.h.StructToArray { - if len(tisfi) == 0 { - e.e.WriteArrayEmpty() - return - } - e.arrayStart(len(tisfi)) - for j, si = range tisfi { - e.c = containerArrayElem - e.e.WriteArrayElem(j == 0) - if si.encBuiltin { - e.encodeIB(rv2i(si.fieldNoAlloc(rv, true))) - } else { - e.encodeValue(si.fieldNoAlloc(rv, !chkCirRef), nil) - } - } - e.c = 0 - e.e.WriteArrayEnd() - } else { - if len(tisfi) == 0 { - e.e.WriteMapEmpty() - return - } - if e.h.Canonical { - tisfi = f.ti.sfi.sorted() - } - e.mapStart(len(tisfi)) - for j, si = range tisfi { - e.c = containerMapKey - e.e.WriteMapElemKey(j == 0) - e.e.EncodeStringNoEscape4Json(si.encName) - e.mapElemValue() - if si.encBuiltin { - e.encodeIB(rv2i(si.fieldNoAlloc(rv, true))) - } else { - e.encodeValue(si.fieldNoAlloc(rv, !chkCirRef), nil) - } - } - e.c = 0 - e.e.WriteMapEnd() - } -} - -func (e *encoderCborBytes) kStruct(f *encFnInfo, rv reflect.Value) { - _ = e.e - ti := f.ti - toMap := !(ti.toArray || e.h.StructToArray) - var mf map[string]interface{} - if ti.flagMissingFielder { - toMap = true - mf = rv2i(rv).(MissingFielder).CodecMissingFields() - } else if ti.flagMissingFielderPtr { - toMap = true - if rv.CanAddr() { - mf = rv2i(rvAddr(rv, ti.ptr)).(MissingFielder).CodecMissingFields() - } else { - mf = rv2i(e.addrRV(rv, ti.rt, ti.ptr)).(MissingFielder).CodecMissingFields() - } - } - newlen := len(mf) - tisfi := ti.sfi.source() - newlen += len(tisfi) - - var fkvs = e.slist.get(newlen)[:newlen] - - recur := e.h.RecursiveEmptyCheck - chkCirRef := e.h.CheckCircularRef - - var xlen int - - var kv sfiRv - var j int - var sf encStructFieldObj - if toMap { - newlen = 0 - if e.h.Canonical { - tisfi = f.ti.sfi.sorted() - } - for _, si := range tisfi { - - if si.omitEmpty { - kv.r = si.fieldNoAlloc(rv, false) - if isEmptyValue(kv.r, e.h.TypeInfos, recur) { - continue - } - } else { - kv.r = si.fieldNoAlloc(rv, si.encBuiltin || !chkCirRef) - } - kv.v = si - fkvs[newlen] = kv - newlen++ - } - - var mf2s []stringIntf - if len(mf) != 0 { - mf2s = make([]stringIntf, 0, len(mf)) - for k, v := range mf { - if k == "" { - continue - } - if ti.infoFieldOmitempty && isEmptyValue(reflect.ValueOf(v), e.h.TypeInfos, recur) { - continue - } - mf2s = append(mf2s, stringIntf{k, v}) - } - } - - xlen = newlen + len(mf2s) - if xlen == 0 { - e.e.WriteMapEmpty() - goto END - } - - e.mapStart(xlen) - - if len(mf2s) != 0 && e.h.Canonical { - mf2w := make([]encStructFieldObj, newlen+len(mf2s)) - for j = 0; j < newlen; j++ { - kv = fkvs[j] - mf2w[j] = encStructFieldObj{kv.v.encName, kv.r, nil, true, - !kv.v.encNameEscape4Json, kv.v.encBuiltin} - } - for _, v := range mf2s { - mf2w[j] = encStructFieldObj{v.v, reflect.Value{}, v.i, false, false, false} - j++ - } - sort.Sort((encStructFieldObjSlice)(mf2w)) - for j, sf = range mf2w { - e.c = containerMapKey - e.e.WriteMapElemKey(j == 0) - if ti.keyType == valueTypeString && sf.noEsc4json { - e.e.EncodeStringNoEscape4Json(sf.key) - } else { - e.kStructFieldKey(ti.keyType, sf.key) - } - e.mapElemValue() - if sf.isRv { - if sf.builtin { - e.encodeIB(rv2i(baseRVRV(sf.rv))) - } else { - e.encodeValue(sf.rv, nil) - } - } else { - if !e.encodeBuiltin(sf.intf) { - e.encodeR(reflect.ValueOf(sf.intf)) - } - - } - } - } else { - keytyp := ti.keyType - for j = 0; j < newlen; j++ { - kv = fkvs[j] - e.c = containerMapKey - e.e.WriteMapElemKey(j == 0) - if ti.keyType == valueTypeString && !kv.v.encNameEscape4Json { - e.e.EncodeStringNoEscape4Json(kv.v.encName) - } else { - e.kStructFieldKey(keytyp, kv.v.encName) - } - e.mapElemValue() - if kv.v.encBuiltin { - e.encodeIB(rv2i(baseRVRV(kv.r))) - } else { - e.encodeValue(kv.r, nil) - } - } - for _, v := range mf2s { - e.c = containerMapKey - e.e.WriteMapElemKey(j == 0) - e.kStructFieldKey(keytyp, v.v) - e.mapElemValue() - if !e.encodeBuiltin(v.i) { - e.encodeR(reflect.ValueOf(v.i)) - } - - j++ - } - } - - e.c = 0 - e.e.WriteMapEnd() - } else { - newlen = len(tisfi) - for i, si := range tisfi { - - if si.omitEmpty { - - kv.r = si.fieldNoAlloc(rv, false) - if isEmptyContainerValue(kv.r, e.h.TypeInfos, recur) { - kv.r = reflect.Value{} - } - } else { - kv.r = si.fieldNoAlloc(rv, si.encBuiltin || !chkCirRef) - } - kv.v = si - fkvs[i] = kv - } - - if newlen == 0 { - e.e.WriteArrayEmpty() - goto END - } - - e.arrayStart(newlen) - for j = 0; j < newlen; j++ { - e.c = containerArrayElem - e.e.WriteArrayElem(j == 0) - kv = fkvs[j] - if !kv.r.IsValid() { - e.e.EncodeNil() - } else if kv.v.encBuiltin { - e.encodeIB(rv2i(baseRVRV(kv.r))) - } else { - e.encodeValue(kv.r, nil) - } - } - e.c = 0 - e.e.WriteArrayEnd() - } - -END: - - e.slist.put(fkvs) -} - -func (e *encoderCborBytes) kMap(f *encFnInfo, rv reflect.Value) { - _ = e.e - l := rvLenMap(rv) - if l == 0 { - e.e.WriteMapEmpty() - return - } - e.mapStart(l) - - var keyFn, valFn *encFnCborBytes - - ktypeKind := reflect.Kind(f.ti.keykind) - vtypeKind := reflect.Kind(f.ti.elemkind) - - rtval := f.ti.elem - rtvalkind := vtypeKind - for rtvalkind == reflect.Ptr { - rtval = rtval.Elem() - rtvalkind = rtval.Kind() - } - if rtvalkind != reflect.Interface { - valFn = e.fn(rtval) - } - - var rvv = mapAddrLoopvarRV(f.ti.elem, vtypeKind) - - rtkey := f.ti.key - var keyTypeIsString = stringTypId == rt2id(rtkey) - if keyTypeIsString { - keyFn = e.fn(rtkey) - } else { - for rtkey.Kind() == reflect.Ptr { - rtkey = rtkey.Elem() - } - if rtkey.Kind() != reflect.Interface { - keyFn = e.fn(rtkey) - } - } - - if e.h.Canonical { - e.kMapCanonical(f.ti, rv, rvv, keyFn, valFn) - e.c = 0 - e.e.WriteMapEnd() - return - } - - var rvk = mapAddrLoopvarRV(f.ti.key, ktypeKind) - - var it mapIter - mapRange(&it, rv, rvk, rvv, true) - - kbuiltin := f.ti.tikey.flagEncBuiltin - vbuiltin := f.ti.tielem.flagEncBuiltin - for j := 0; it.Next(); j++ { - rv = it.Key() - e.c = containerMapKey - e.e.WriteMapElemKey(j == 0) - if keyTypeIsString { - e.e.EncodeString(rvGetString(rv)) - } else if kbuiltin { - e.encodeIB(rv2i(baseRVRV(rv))) - } else { - e.encodeValue(rv, keyFn) - } - e.mapElemValue() - rv = it.Value() - if vbuiltin { - e.encodeIB(rv2i(baseRVRV(rv))) - } else { - e.encodeValue(it.Value(), valFn) - } - } - it.Done() - - e.c = 0 - e.e.WriteMapEnd() -} - -func (e *encoderCborBytes) kMapCanonical(ti *typeInfo, rv, rvv reflect.Value, keyFn, valFn *encFnCborBytes) { - _ = e.e - - rtkey := ti.key - rtkeydecl := rtkey.PkgPath() == "" && rtkey.Name() != "" - - mks := rv.MapKeys() - rtkeyKind := rtkey.Kind() - mparams := getMapReqParams(ti) - - switch rtkeyKind { - case reflect.Bool: - - if len(mks) == 2 && mks[0].Bool() { - mks[0], mks[1] = mks[1], mks[0] - } - for i := range mks { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - if rtkeydecl { - e.e.EncodeBool(mks[i].Bool()) - } else { - e.encodeValueNonNil(mks[i], keyFn) - } - e.mapElemValue() - e.encodeValue(mapGet(rv, mks[i], rvv, mparams), valFn) - } - case reflect.String: - mksv := make([]orderedRv[string], len(mks)) - for i, k := range mks { - v := &mksv[i] - v.r = k - v.v = rvGetString(k) - } - slices.SortFunc(mksv, cmpOrderedRv) - for i := range mksv { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - if rtkeydecl { - e.e.EncodeString(mksv[i].v) - } else { - e.encodeValueNonNil(mksv[i].r, keyFn) - } - e.mapElemValue() - e.encodeValue(mapGet(rv, mksv[i].r, rvv, mparams), valFn) - } - case reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64, reflect.Uint, reflect.Uintptr: - mksv := make([]orderedRv[uint64], len(mks)) - for i, k := range mks { - v := &mksv[i] - v.r = k - v.v = k.Uint() - } - slices.SortFunc(mksv, cmpOrderedRv) - for i := range mksv { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - if rtkeydecl { - e.e.EncodeUint(mksv[i].v) - } else { - e.encodeValueNonNil(mksv[i].r, keyFn) - } - e.mapElemValue() - e.encodeValue(mapGet(rv, mksv[i].r, rvv, mparams), valFn) - } - case reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64, reflect.Int: - mksv := make([]orderedRv[int64], len(mks)) - for i, k := range mks { - v := &mksv[i] - v.r = k - v.v = k.Int() - } - slices.SortFunc(mksv, cmpOrderedRv) - for i := range mksv { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - if rtkeydecl { - e.e.EncodeInt(mksv[i].v) - } else { - e.encodeValueNonNil(mksv[i].r, keyFn) - } - e.mapElemValue() - e.encodeValue(mapGet(rv, mksv[i].r, rvv, mparams), valFn) - } - case reflect.Float32: - mksv := make([]orderedRv[float64], len(mks)) - for i, k := range mks { - v := &mksv[i] - v.r = k - v.v = k.Float() - } - slices.SortFunc(mksv, cmpOrderedRv) - for i := range mksv { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - if rtkeydecl { - e.e.EncodeFloat32(float32(mksv[i].v)) - } else { - e.encodeValueNonNil(mksv[i].r, keyFn) - } - e.mapElemValue() - e.encodeValue(mapGet(rv, mksv[i].r, rvv, mparams), valFn) - } - case reflect.Float64: - mksv := make([]orderedRv[float64], len(mks)) - for i, k := range mks { - v := &mksv[i] - v.r = k - v.v = k.Float() - } - slices.SortFunc(mksv, cmpOrderedRv) - for i := range mksv { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - if rtkeydecl { - e.e.EncodeFloat64(mksv[i].v) - } else { - e.encodeValueNonNil(mksv[i].r, keyFn) - } - e.mapElemValue() - e.encodeValue(mapGet(rv, mksv[i].r, rvv, mparams), valFn) - } - default: - if rtkey == timeTyp { - mksv := make([]timeRv, len(mks)) - for i, k := range mks { - v := &mksv[i] - v.r = k - v.v = rv2i(k).(time.Time) - } - slices.SortFunc(mksv, cmpTimeRv) - for i := range mksv { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeTime(mksv[i].v) - e.mapElemValue() - e.encodeValue(mapGet(rv, mksv[i].r, rvv, mparams), valFn) - } - break - } - - bs0 := e.blist.get(len(mks) * 16) - mksv := bs0 - mksbv := make([]bytesRv, len(mks)) - - sideEncode(e.hh, &e.h.sideEncPool, func(se encoderI) { - se.ResetBytes(&mksv) - for i, k := range mks { - v := &mksbv[i] - l := len(mksv) - se.setContainerState(containerMapKey) - se.encodeR(baseRVRV(k)) - se.atEndOfEncode() - se.writerEnd() - v.r = k - v.v = mksv[l:] - } - }) - - slices.SortFunc(mksbv, cmpBytesRv) - for j := range mksbv { - e.c = containerMapKey - e.e.WriteMapElemKey(j == 0) - e.e.writeBytesAsis(mksbv[j].v) - e.mapElemValue() - e.encodeValue(mapGet(rv, mksbv[j].r, rvv, mparams), valFn) - } - e.blist.put(mksv) - if !byteSliceSameData(bs0, mksv) { - e.blist.put(bs0) - } - } -} - -func (e *encoderCborBytes) init(h Handle) { - initHandle(h) - callMake(&e.e) - e.hh = h - e.h = h.getBasicHandle() - - e.err = errEncoderNotInitialized - - e.fp = e.e.init(h, &e.encoderBase, e).(*fastpathEsCborBytes) - - if e.bytes { - e.rtidFn = &e.h.rtidFnsEncBytes - e.rtidFnNoExt = &e.h.rtidFnsEncNoExtBytes - } else { - e.rtidFn = &e.h.rtidFnsEncIO - e.rtidFnNoExt = &e.h.rtidFnsEncNoExtIO - } - - e.reset() -} - -func (e *encoderCborBytes) reset() { - e.e.reset() - if e.ci != nil { - e.ci = e.ci[:0] - } - e.c = 0 - e.calls = 0 - e.seq = 0 - e.err = nil -} - -func (e *encoderCborBytes) Encode(v interface{}) (err error) { - - defer panicValToErr(e, callRecoverSentinel, &e.err, &err, debugging) - e.mustEncode(v) - return -} - -func (e *encoderCborBytes) MustEncode(v interface{}) { - defer panicValToErr(e, callRecoverSentinel, &e.err, nil, true) - e.mustEncode(v) - return -} - -func (e *encoderCborBytes) mustEncode(v interface{}) { - halt.onerror(e.err) - if e.hh == nil { - halt.onerror(errNoFormatHandle) - } - - e.calls++ - if !e.encodeBuiltin(v) { - e.encodeR(reflect.ValueOf(v)) - } - - e.calls-- - if e.calls == 0 { - e.e.atEndOfEncode() - e.e.writerEnd() - } -} - -func (e *encoderCborBytes) encodeI(iv interface{}) { - if !e.encodeBuiltin(iv) { - e.encodeR(reflect.ValueOf(iv)) - } -} - -func (e *encoderCborBytes) encodeIB(iv interface{}) { - if !e.encodeBuiltin(iv) { - - halt.errorStr("[should not happen] invalid type passed to encodeBuiltin") - } -} - -func (e *encoderCborBytes) encodeR(base reflect.Value) { - e.encodeValue(base, nil) -} - -func (e *encoderCborBytes) encodeBuiltin(iv interface{}) (ok bool) { - ok = true - switch v := iv.(type) { - case nil: - e.e.EncodeNil() - - case Raw: - e.rawBytes(v) - case string: - e.e.EncodeString(v) - case bool: - e.e.EncodeBool(v) - case int: - e.e.EncodeInt(int64(v)) - case int8: - e.e.EncodeInt(int64(v)) - case int16: - e.e.EncodeInt(int64(v)) - case int32: - e.e.EncodeInt(int64(v)) - case int64: - e.e.EncodeInt(v) - case uint: - e.e.EncodeUint(uint64(v)) - case uint8: - e.e.EncodeUint(uint64(v)) - case uint16: - e.e.EncodeUint(uint64(v)) - case uint32: - e.e.EncodeUint(uint64(v)) - case uint64: - e.e.EncodeUint(v) - case uintptr: - e.e.EncodeUint(uint64(v)) - case float32: - e.e.EncodeFloat32(v) - case float64: - e.e.EncodeFloat64(v) - case complex64: - e.encodeComplex64(v) - case complex128: - e.encodeComplex128(v) - case time.Time: - e.e.EncodeTime(v) - case []byte: - e.e.EncodeBytes(v) - default: - - ok = !skipFastpathTypeSwitchInDirectCall && e.dh.fastpathEncodeTypeSwitch(iv, e) - } - return -} - -func (e *encoderCborBytes) encodeValue(rv reflect.Value, fn *encFnCborBytes) { - - var ciPushes int - - var rvp reflect.Value - var rvpValid bool - -RV: - switch rv.Kind() { - case reflect.Ptr: - if rvIsNil(rv) { - e.e.EncodeNil() - goto END - } - rvpValid = true - rvp = rv - rv = rv.Elem() - - if e.h.CheckCircularRef && e.ci.canPushElemKind(rv.Kind()) { - e.ci.push(rv2i(rvp)) - ciPushes++ - } - goto RV - case reflect.Interface: - if rvIsNil(rv) { - e.e.EncodeNil() - goto END - } - rvpValid = false - rvp = reflect.Value{} - rv = rv.Elem() - fn = nil - goto RV - case reflect.Map: - if rvIsNil(rv) { - if e.h.NilCollectionToZeroLength { - e.e.WriteMapEmpty() - } else { - e.e.EncodeNil() - } - goto END - } - case reflect.Slice, reflect.Chan: - if rvIsNil(rv) { - if e.h.NilCollectionToZeroLength { - e.e.WriteArrayEmpty() - } else { - e.e.EncodeNil() - } - goto END - } - case reflect.Invalid, reflect.Func: - e.e.EncodeNil() - goto END - } - - if fn == nil { - fn = e.fn(rv.Type()) - } - - if !fn.i.addrE { - - } else if rvpValid { - rv = rvp - } else if rv.CanAddr() { - rv = rvAddr(rv, fn.i.ti.ptr) - } else { - rv = e.addrRV(rv, fn.i.ti.rt, fn.i.ti.ptr) - } - fn.fe(e, &fn.i, rv) - -END: - if ciPushes > 0 { - e.ci.pop(ciPushes) - } -} - -func (e *encoderCborBytes) encodeValueNonNil(rv reflect.Value, fn *encFnCborBytes) { - - if fn.i.addrE { - if rv.CanAddr() { - rv = rvAddr(rv, fn.i.ti.ptr) - } else { - rv = e.addrRV(rv, fn.i.ti.rt, fn.i.ti.ptr) - } - } - fn.fe(e, &fn.i, rv) -} - -func (e *encoderCborBytes) encodeAs(v interface{}, t reflect.Type, ext bool) { - if ext { - e.encodeValue(baseRV(v), e.fn(t)) - } else { - e.encodeValue(baseRV(v), e.fnNoExt(t)) - } -} - -func (e *encoderCborBytes) marshalUtf8(bs []byte, fnerr error) { - halt.onerror(fnerr) - if bs == nil { - e.e.EncodeNil() - } else { - e.e.EncodeString(stringView(bs)) - } -} - -func (e *encoderCborBytes) marshalAsis(bs []byte, fnerr error) { - halt.onerror(fnerr) - if bs == nil { - e.e.EncodeNil() - } else { - e.e.writeBytesAsis(bs) - } -} - -func (e *encoderCborBytes) marshalRaw(bs []byte, fnerr error) { - halt.onerror(fnerr) - e.e.EncodeBytes(bs) -} - -func (e *encoderCborBytes) rawBytes(vv Raw) { - v := []byte(vv) - if !e.h.Raw { - halt.errorBytes("Raw values cannot be encoded: ", v) - } - e.e.writeBytesAsis(v) -} - -func (e *encoderCborBytes) fn(t reflect.Type) *encFnCborBytes { - return e.dh.encFnViaBH(t, e.rtidFn, e.h, e.fp, false) -} - -func (e *encoderCborBytes) fnNoExt(t reflect.Type) *encFnCborBytes { - return e.dh.encFnViaBH(t, e.rtidFnNoExt, e.h, e.fp, true) -} - -func (e *encoderCborBytes) mapStart(length int) { - e.e.WriteMapStart(length) - e.c = containerMapStart -} - -func (e *encoderCborBytes) mapElemValue() { - e.e.WriteMapElemValue() - e.c = containerMapValue -} - -func (e *encoderCborBytes) arrayStart(length int) { - e.e.WriteArrayStart(length) - e.c = containerArrayStart -} - -func (e *encoderCborBytes) writerEnd() { - e.e.writerEnd() -} - -func (e *encoderCborBytes) atEndOfEncode() { - e.e.atEndOfEncode() -} - -func (e *encoderCborBytes) Reset(w io.Writer) { - if e.bytes { - halt.onerror(errEncNoResetBytesWithWriter) - } - e.reset() - if w == nil { - w = io.Discard - } - e.e.resetOutIO(w) -} - -func (e *encoderCborBytes) ResetBytes(out *[]byte) { - if !e.bytes { - halt.onerror(errEncNoResetWriterWithBytes) - } - e.resetBytes(out) -} - -func (e *encoderCborBytes) resetBytes(out *[]byte) { - e.reset() - if out == nil { - out = &bytesEncAppenderDefOut - } - e.e.resetOutBytes(out) -} - -func (helperEncDriverCborBytes) newEncoderBytes(out *[]byte, h Handle) *encoderCborBytes { - var c1 encoderCborBytes - c1.bytes = true - c1.init(h) - c1.ResetBytes(out) - return &c1 -} - -func (helperEncDriverCborBytes) newEncoderIO(out io.Writer, h Handle) *encoderCborBytes { - var c1 encoderCborBytes - c1.bytes = false - c1.init(h) - c1.Reset(out) - return &c1 -} - -func (helperEncDriverCborBytes) encFnloadFastpathUnderlying(ti *typeInfo, fp *fastpathEsCborBytes) (f *fastpathECborBytes, u reflect.Type) { - rtid := rt2id(ti.fastpathUnderlying) - idx, ok := fastpathAvIndex(rtid) - if !ok { - return - } - f = &fp[idx] - if uint8(reflect.Array) == ti.kind { - u = reflect.ArrayOf(ti.rt.Len(), ti.elem) - } else { - u = f.rt - } - return -} - -func (helperEncDriverCborBytes) encFindRtidFn(s []encRtidFnCborBytes, rtid uintptr) (i uint, fn *encFnCborBytes) { - - var h uint - var j = uint(len(s)) -LOOP: - if i < j { - h = (i + j) >> 1 - if s[h].rtid < rtid { - i = h + 1 - } else { - j = h - } - goto LOOP - } - if i < uint(len(s)) && s[i].rtid == rtid { - fn = s[i].fn - } - return -} - -func (helperEncDriverCborBytes) encFromRtidFnSlice(fns *atomicRtidFnSlice) (s []encRtidFnCborBytes) { - if v := fns.load(); v != nil { - s = *(lowLevelToPtr[[]encRtidFnCborBytes](v)) - } - return -} - -func (dh helperEncDriverCborBytes) encFnViaBH(rt reflect.Type, fns *atomicRtidFnSlice, - x *BasicHandle, fp *fastpathEsCborBytes, checkExt bool) (fn *encFnCborBytes) { - return dh.encFnVia(rt, fns, x.typeInfos(), &x.mu, x.extHandle, fp, - checkExt, x.CheckCircularRef, x.timeBuiltin, x.binaryHandle, x.jsonHandle) -} - -func (dh helperEncDriverCborBytes) encFnVia(rt reflect.Type, fns *atomicRtidFnSlice, - tinfos *TypeInfos, mu *sync.Mutex, exth extHandle, fp *fastpathEsCborBytes, - checkExt, checkCircularRef, timeBuiltin, binaryEncoding, json bool) (fn *encFnCborBytes) { - rtid := rt2id(rt) - var sp []encRtidFnCborBytes = dh.encFromRtidFnSlice(fns) - if sp != nil { - _, fn = dh.encFindRtidFn(sp, rtid) - } - if fn == nil { - fn = dh.encFnViaLoader(rt, rtid, fns, tinfos, mu, exth, fp, checkExt, checkCircularRef, timeBuiltin, binaryEncoding, json) - } - return -} - -func (dh helperEncDriverCborBytes) encFnViaLoader(rt reflect.Type, rtid uintptr, fns *atomicRtidFnSlice, - tinfos *TypeInfos, mu *sync.Mutex, exth extHandle, fp *fastpathEsCborBytes, - checkExt, checkCircularRef, timeBuiltin, binaryEncoding, json bool) (fn *encFnCborBytes) { - - fn = dh.encFnLoad(rt, rtid, tinfos, exth, fp, checkExt, checkCircularRef, timeBuiltin, binaryEncoding, json) - var sp []encRtidFnCborBytes - mu.Lock() - sp = dh.encFromRtidFnSlice(fns) - - if sp == nil { - sp = []encRtidFnCborBytes{{rtid, fn}} - fns.store(ptrToLowLevel(&sp)) - } else { - idx, fn2 := dh.encFindRtidFn(sp, rtid) - if fn2 == nil { - sp2 := make([]encRtidFnCborBytes, len(sp)+1) - copy(sp2[idx+1:], sp[idx:]) - copy(sp2, sp[:idx]) - sp2[idx] = encRtidFnCborBytes{rtid, fn} - fns.store(ptrToLowLevel(&sp2)) - } - } - mu.Unlock() - return -} - -func (dh helperEncDriverCborBytes) encFnLoad(rt reflect.Type, rtid uintptr, tinfos *TypeInfos, - exth extHandle, fp *fastpathEsCborBytes, - checkExt, checkCircularRef, timeBuiltin, binaryEncoding, json bool) (fn *encFnCborBytes) { - fn = new(encFnCborBytes) - fi := &(fn.i) - ti := tinfos.get(rtid, rt) - fi.ti = ti - rk := reflect.Kind(ti.kind) - - if rtid == timeTypId && timeBuiltin { - fn.fe = (*encoderCborBytes).kTime - } else if rtid == rawTypId { - fn.fe = (*encoderCborBytes).raw - } else if rtid == rawExtTypId { - fn.fe = (*encoderCborBytes).rawExt - fi.addrE = true - } else if xfFn := exth.getExt(rtid, checkExt); xfFn != nil { - fi.xfTag, fi.xfFn = xfFn.tag, xfFn.ext - fn.fe = (*encoderCborBytes).ext - if rk == reflect.Struct || rk == reflect.Array { - fi.addrE = true - } - } else if ti.flagSelfer || ti.flagSelferPtr { - fn.fe = (*encoderCborBytes).selferMarshal - fi.addrE = ti.flagSelferPtr - } else if supportMarshalInterfaces && binaryEncoding && - (ti.flagBinaryMarshaler || ti.flagBinaryMarshalerPtr) && - (ti.flagBinaryUnmarshaler || ti.flagBinaryUnmarshalerPtr) { - fn.fe = (*encoderCborBytes).binaryMarshal - fi.addrE = ti.flagBinaryMarshalerPtr - } else if supportMarshalInterfaces && !binaryEncoding && json && - (ti.flagJsonMarshaler || ti.flagJsonMarshalerPtr) && - (ti.flagJsonUnmarshaler || ti.flagJsonUnmarshalerPtr) { - - fn.fe = (*encoderCborBytes).jsonMarshal - fi.addrE = ti.flagJsonMarshalerPtr - } else if supportMarshalInterfaces && !binaryEncoding && - (ti.flagTextMarshaler || ti.flagTextMarshalerPtr) && - (ti.flagTextUnmarshaler || ti.flagTextUnmarshalerPtr) { - fn.fe = (*encoderCborBytes).textMarshal - fi.addrE = ti.flagTextMarshalerPtr - } else { - if fastpathEnabled && (rk == reflect.Map || rk == reflect.Slice || rk == reflect.Array) { - - var rtid2 uintptr - if !ti.flagHasPkgPath { - rtid2 = rtid - if rk == reflect.Array { - rtid2 = rt2id(ti.key) - } - if idx, ok := fastpathAvIndex(rtid2); ok { - fn.fe = fp[idx].encfn - } - } else { - - xfe, xrt := dh.encFnloadFastpathUnderlying(ti, fp) - if xfe != nil { - xfnf := xfe.encfn - fn.fe = func(e *encoderCborBytes, xf *encFnInfo, xrv reflect.Value) { - xfnf(e, xf, rvConvert(xrv, xrt)) - } - } - } - } - if fn.fe == nil { - switch rk { - case reflect.Bool: - fn.fe = (*encoderCborBytes).kBool - case reflect.String: - - fn.fe = (*encoderCborBytes).kString - case reflect.Int: - fn.fe = (*encoderCborBytes).kInt - case reflect.Int8: - fn.fe = (*encoderCborBytes).kInt8 - case reflect.Int16: - fn.fe = (*encoderCborBytes).kInt16 - case reflect.Int32: - fn.fe = (*encoderCborBytes).kInt32 - case reflect.Int64: - fn.fe = (*encoderCborBytes).kInt64 - case reflect.Uint: - fn.fe = (*encoderCborBytes).kUint - case reflect.Uint8: - fn.fe = (*encoderCborBytes).kUint8 - case reflect.Uint16: - fn.fe = (*encoderCborBytes).kUint16 - case reflect.Uint32: - fn.fe = (*encoderCborBytes).kUint32 - case reflect.Uint64: - fn.fe = (*encoderCborBytes).kUint64 - case reflect.Uintptr: - fn.fe = (*encoderCborBytes).kUintptr - case reflect.Float32: - fn.fe = (*encoderCborBytes).kFloat32 - case reflect.Float64: - fn.fe = (*encoderCborBytes).kFloat64 - case reflect.Complex64: - fn.fe = (*encoderCborBytes).kComplex64 - case reflect.Complex128: - fn.fe = (*encoderCborBytes).kComplex128 - case reflect.Chan: - fn.fe = (*encoderCborBytes).kChan - case reflect.Slice: - fn.fe = (*encoderCborBytes).kSlice - case reflect.Array: - fn.fe = (*encoderCborBytes).kArray - case reflect.Struct: - if ti.simple { - fn.fe = (*encoderCborBytes).kStructSimple - } else { - fn.fe = (*encoderCborBytes).kStruct - } - case reflect.Map: - fn.fe = (*encoderCborBytes).kMap - case reflect.Interface: - - fn.fe = (*encoderCborBytes).kErr - default: - - fn.fe = (*encoderCborBytes).kErr - } - } - } - return -} -func (d *decoderCborBytes) rawExt(f *decFnInfo, rv reflect.Value) { - d.d.DecodeRawExt(rv2i(rv).(*RawExt)) -} - -func (d *decoderCborBytes) ext(f *decFnInfo, rv reflect.Value) { - d.d.DecodeExt(rv2i(rv), f.ti.rt, f.xfTag, f.xfFn) -} - -func (d *decoderCborBytes) selferUnmarshal(_ *decFnInfo, rv reflect.Value) { - rv2i(rv).(Selfer).CodecDecodeSelf(&Decoder{d}) -} - -func (d *decoderCborBytes) binaryUnmarshal(_ *decFnInfo, rv reflect.Value) { - bm := rv2i(rv).(encoding.BinaryUnmarshaler) - xbs, _ := d.d.DecodeBytes() - fnerr := bm.UnmarshalBinary(xbs) - halt.onerror(fnerr) -} - -func (d *decoderCborBytes) textUnmarshal(_ *decFnInfo, rv reflect.Value) { - tm := rv2i(rv).(encoding.TextUnmarshaler) - fnerr := tm.UnmarshalText(bytesOKs(d.d.DecodeStringAsBytes())) - halt.onerror(fnerr) -} - -func (d *decoderCborBytes) jsonUnmarshal(_ *decFnInfo, rv reflect.Value) { - d.jsonUnmarshalV(rv2i(rv).(jsonUnmarshaler)) -} - -func (d *decoderCborBytes) jsonUnmarshalV(tm jsonUnmarshaler) { - - halt.onerror(tm.UnmarshalJSON(d.d.nextValueBytes())) -} - -func (d *decoderCborBytes) kErr(_ *decFnInfo, rv reflect.Value) { - halt.errorf("unsupported decoding kind: %s, for %#v", rv.Kind(), rv) - -} - -func (d *decoderCborBytes) raw(_ *decFnInfo, rv reflect.Value) { - rvSetBytes(rv, d.rawBytes()) -} - -func (d *decoderCborBytes) kString(_ *decFnInfo, rv reflect.Value) { - rvSetString(rv, d.detach2Str(d.d.DecodeStringAsBytes())) -} - -func (d *decoderCborBytes) kBool(_ *decFnInfo, rv reflect.Value) { - rvSetBool(rv, d.d.DecodeBool()) -} - -func (d *decoderCborBytes) kTime(_ *decFnInfo, rv reflect.Value) { - rvSetTime(rv, d.d.DecodeTime()) -} - -func (d *decoderCborBytes) kFloat32(_ *decFnInfo, rv reflect.Value) { - rvSetFloat32(rv, d.d.DecodeFloat32()) -} - -func (d *decoderCborBytes) kFloat64(_ *decFnInfo, rv reflect.Value) { - rvSetFloat64(rv, d.d.DecodeFloat64()) -} - -func (d *decoderCborBytes) kComplex64(_ *decFnInfo, rv reflect.Value) { - rvSetComplex64(rv, complex(d.d.DecodeFloat32(), 0)) -} - -func (d *decoderCborBytes) kComplex128(_ *decFnInfo, rv reflect.Value) { - rvSetComplex128(rv, complex(d.d.DecodeFloat64(), 0)) -} - -func (d *decoderCborBytes) kInt(_ *decFnInfo, rv reflect.Value) { - rvSetInt(rv, int(chkOvf.IntV(d.d.DecodeInt64(), intBitsize))) -} - -func (d *decoderCborBytes) kInt8(_ *decFnInfo, rv reflect.Value) { - rvSetInt8(rv, int8(chkOvf.IntV(d.d.DecodeInt64(), 8))) -} - -func (d *decoderCborBytes) kInt16(_ *decFnInfo, rv reflect.Value) { - rvSetInt16(rv, int16(chkOvf.IntV(d.d.DecodeInt64(), 16))) -} - -func (d *decoderCborBytes) kInt32(_ *decFnInfo, rv reflect.Value) { - rvSetInt32(rv, int32(chkOvf.IntV(d.d.DecodeInt64(), 32))) -} - -func (d *decoderCborBytes) kInt64(_ *decFnInfo, rv reflect.Value) { - rvSetInt64(rv, d.d.DecodeInt64()) -} - -func (d *decoderCborBytes) kUint(_ *decFnInfo, rv reflect.Value) { - rvSetUint(rv, uint(chkOvf.UintV(d.d.DecodeUint64(), uintBitsize))) -} - -func (d *decoderCborBytes) kUintptr(_ *decFnInfo, rv reflect.Value) { - rvSetUintptr(rv, uintptr(chkOvf.UintV(d.d.DecodeUint64(), uintBitsize))) -} - -func (d *decoderCborBytes) kUint8(_ *decFnInfo, rv reflect.Value) { - rvSetUint8(rv, uint8(chkOvf.UintV(d.d.DecodeUint64(), 8))) -} - -func (d *decoderCborBytes) kUint16(_ *decFnInfo, rv reflect.Value) { - rvSetUint16(rv, uint16(chkOvf.UintV(d.d.DecodeUint64(), 16))) -} - -func (d *decoderCborBytes) kUint32(_ *decFnInfo, rv reflect.Value) { - rvSetUint32(rv, uint32(chkOvf.UintV(d.d.DecodeUint64(), 32))) -} - -func (d *decoderCborBytes) kUint64(_ *decFnInfo, rv reflect.Value) { - rvSetUint64(rv, d.d.DecodeUint64()) -} - -func (d *decoderCborBytes) kInterfaceNaked(f *decFnInfo) (rvn reflect.Value) { - - n := d.naked() - d.d.DecodeNaked() - - if decFailNonEmptyIntf && f.ti.numMeth > 0 { - halt.errorf("cannot decode non-nil codec value into nil %v (%v methods)", f.ti.rt, f.ti.numMeth) - } - - switch n.v { - case valueTypeMap: - mtid := d.mtid - if mtid == 0 { - if d.jsms { - mtid = mapStrIntfTypId - } else { - mtid = mapIntfIntfTypId - } - } - if mtid == mapStrIntfTypId { - var v2 map[string]interface{} - d.decode(&v2) - rvn = rv4iptr(&v2).Elem() - } else if mtid == mapIntfIntfTypId { - var v2 map[interface{}]interface{} - d.decode(&v2) - rvn = rv4iptr(&v2).Elem() - } else if d.mtr { - rvn = reflect.New(d.h.MapType) - d.decode(rv2i(rvn)) - rvn = rvn.Elem() - } else { - - rvn = rvZeroAddrK(d.h.MapType, reflect.Map) - d.decodeValue(rvn, nil) - } - case valueTypeArray: - if d.stid == 0 || d.stid == intfSliceTypId { - var v2 []interface{} - d.decode(&v2) - rvn = rv4iptr(&v2).Elem() - } else if d.str { - rvn = reflect.New(d.h.SliceType) - d.decode(rv2i(rvn)) - rvn = rvn.Elem() - } else { - rvn = rvZeroAddrK(d.h.SliceType, reflect.Slice) - d.decodeValue(rvn, nil) - } - if d.h.PreferArrayOverSlice { - rvn = rvGetArray4Slice(rvn) - } - case valueTypeExt: - tag, bytes := n.u, n.l - bfn := d.h.getExtForTag(tag) - var re = RawExt{Tag: tag} - if bytes == nil { - - if bfn == nil { - d.decode(&re.Value) - rvn = rv4iptr(&re).Elem() - } else if bfn.ext == SelfExt { - rvn = rvZeroAddrK(bfn.rt, bfn.rt.Kind()) - d.decodeValue(rvn, d.fnNoExt(bfn.rt)) - } else { - rvn = reflect.New(bfn.rt) - d.interfaceExtConvertAndDecode(rv2i(rvn), bfn.ext) - rvn = rvn.Elem() - } - } else { - - if bfn == nil { - re.setData(bytes, false) - rvn = rv4iptr(&re).Elem() - } else { - rvn = reflect.New(bfn.rt) - if bfn.ext == SelfExt { - sideDecode(d.hh, &d.h.sideDecPool, func(sd decoderI) { oneOffDecode(sd, rv2i(rvn), bytes, bfn.rt, true) }) - } else { - bfn.ext.ReadExt(rv2i(rvn), bytes) - } - rvn = rvn.Elem() - } - } - - if d.h.PreferPointerForStructOrArray && rvn.CanAddr() { - if rk := rvn.Kind(); rk == reflect.Array || rk == reflect.Struct { - rvn = rvn.Addr() - } - } - case valueTypeNil: - - case valueTypeInt: - rvn = n.ri() - case valueTypeUint: - rvn = n.ru() - case valueTypeFloat: - rvn = n.rf() - case valueTypeBool: - rvn = n.rb() - case valueTypeString, valueTypeSymbol: - rvn = n.rs() - case valueTypeBytes: - rvn = n.rl() - case valueTypeTime: - rvn = n.rt() - default: - halt.errorStr2("kInterfaceNaked: unexpected valueType: ", n.v.String()) - } - return -} - -func (d *decoderCborBytes) kInterface(f *decFnInfo, rv reflect.Value) { - - isnilrv := rvIsNil(rv) - - var rvn reflect.Value - - if d.h.InterfaceReset { - - rvn = d.h.intf2impl(f.ti.rtid) - if !rvn.IsValid() { - rvn = d.kInterfaceNaked(f) - if rvn.IsValid() { - rvSetIntf(rv, rvn) - } else if !isnilrv { - decSetNonNilRV2Zero4Intf(rv) - } - return - } - } else if isnilrv { - - rvn = d.h.intf2impl(f.ti.rtid) - if !rvn.IsValid() { - rvn = d.kInterfaceNaked(f) - if rvn.IsValid() { - rvSetIntf(rv, rvn) - } - return - } - } else { - - rvn = rv.Elem() - } - - canDecode, _ := isDecodeable(rvn) - - if !canDecode { - rvn2 := d.oneShotAddrRV(rvn.Type(), rvn.Kind()) - rvSetDirect(rvn2, rvn) - rvn = rvn2 - } - - d.decodeValue(rvn, nil) - rvSetIntf(rv, rvn) -} - -func (d *decoderCborBytes) kStructField(si *structFieldInfo, rv reflect.Value) { - if d.d.TryNil() { - rv = si.fieldNoAlloc(rv, true) - if rv.IsValid() { - decSetNonNilRV2Zero(rv) - } - } else if si.decBuiltin { - rv = rvAddr(si.fieldAlloc(rv), si.ptrTyp) - d.decode(rv2i(rv)) - } else { - fn := d.fn(si.baseTyp) - rv = si.fieldAlloc(rv) - if fn.i.addrD { - rv = rvAddr(rv, si.ptrTyp) - } - fn.fd(d, &fn.i, rv) - } -} - -func (d *decoderCborBytes) kStructSimple(f *decFnInfo, rv reflect.Value) { - _ = d.d - ctyp := d.d.ContainerType() - ti := f.ti - if ctyp == valueTypeMap { - containerLen := d.mapStart(d.d.ReadMapStart()) - if containerLen == 0 { - d.mapEnd() - return - } - hasLen := containerLen >= 0 - var rvkencname []byte - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - sab, att := d.d.DecodeStringAsBytes() - rvkencname = d.usableStructFieldNameBytes(rvkencname, sab, att) - d.mapElemValue() - if si := ti.siForEncName(rvkencname); si != nil { - d.kStructField(si, rv) - } else { - d.structFieldNotFound(-1, stringView(rvkencname)) - } - } - d.mapEnd() - } else if ctyp == valueTypeArray { - containerLen := d.arrayStart(d.d.ReadArrayStart()) - if containerLen == 0 { - d.arrayEnd() - return - } - - tisfi := ti.sfi.source() - hasLen := containerLen >= 0 - - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.arrayElem(j == 0) - if j < len(tisfi) { - d.kStructField(tisfi[j], rv) - } else { - d.structFieldNotFound(j, "") - } - } - d.arrayEnd() - } else { - halt.onerror(errNeedMapOrArrayDecodeToStruct) - } -} - -func (d *decoderCborBytes) kStruct(f *decFnInfo, rv reflect.Value) { - _ = d.d - ctyp := d.d.ContainerType() - ti := f.ti - var mf MissingFielder - if ti.flagMissingFielder { - mf = rv2i(rv).(MissingFielder) - } else if ti.flagMissingFielderPtr { - mf = rv2i(rvAddr(rv, ti.ptr)).(MissingFielder) - } - if ctyp == valueTypeMap { - containerLen := d.mapStart(d.d.ReadMapStart()) - if containerLen == 0 { - d.mapEnd() - return - } - hasLen := containerLen >= 0 - var name2 []byte - var rvkencname []byte - tkt := ti.keyType - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - - if tkt == valueTypeString { - sab, att := d.d.DecodeStringAsBytes() - rvkencname = d.usableStructFieldNameBytes(rvkencname, sab, att) - } else if tkt == valueTypeInt { - rvkencname = strconv.AppendInt(d.b[:0], d.d.DecodeInt64(), 10) - } else if tkt == valueTypeUint { - rvkencname = strconv.AppendUint(d.b[:0], d.d.DecodeUint64(), 10) - } else if tkt == valueTypeFloat { - rvkencname = strconv.AppendFloat(d.b[:0], d.d.DecodeFloat64(), 'f', -1, 64) - } else { - halt.errorStr2("invalid struct key type: ", ti.keyType.String()) - } - - d.mapElemValue() - if si := ti.siForEncName(rvkencname); si != nil { - d.kStructField(si, rv) - } else if mf != nil { - - name2 = append(name2[:0], rvkencname...) - var f interface{} - d.decode(&f) - if !mf.CodecMissingField(name2, f) && d.h.ErrorIfNoField { - halt.errorStr2("no matching struct field when decoding stream map with key: ", stringView(name2)) - } - } else { - d.structFieldNotFound(-1, stringView(rvkencname)) - } - } - d.mapEnd() - } else if ctyp == valueTypeArray { - containerLen := d.arrayStart(d.d.ReadArrayStart()) - if containerLen == 0 { - d.arrayEnd() - return - } - - tisfi := ti.sfi.source() - hasLen := containerLen >= 0 - - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.arrayElem(j == 0) - if j < len(tisfi) { - d.kStructField(tisfi[j], rv) - } else { - d.structFieldNotFound(j, "") - } - } - - d.arrayEnd() - } else { - halt.onerror(errNeedMapOrArrayDecodeToStruct) - } -} - -func (d *decoderCborBytes) kSlice(f *decFnInfo, rv reflect.Value) { - _ = d.d - - ti := f.ti - rvCanset := rv.CanSet() - - ctyp := d.d.ContainerType() - if ctyp == valueTypeBytes || ctyp == valueTypeString { - - if !(ti.rtid == uint8SliceTypId || ti.elemkind == uint8(reflect.Uint8)) { - halt.errorf("bytes/string in stream must decode into slice/array of bytes, not %v", ti.rt) - } - rvbs := rvGetBytes(rv) - if rvCanset { - bs2, bst := d.decodeBytesInto(rvbs, false) - if bst != dBytesIntoParamOut { - rvSetBytes(rv, bs2) - } - } else { - - d.decodeBytesInto(rvbs[:len(rvbs):len(rvbs)], true) - } - return - } - - var containerLenS int - isArray := ctyp == valueTypeArray - if isArray { - containerLenS = d.arrayStart(d.d.ReadArrayStart()) - } else if ctyp == valueTypeMap { - containerLenS = d.mapStart(d.d.ReadMapStart()) * 2 - } else { - halt.errorStr2("decoding into a slice, expect map/array - got ", ctyp.String()) - } - - if containerLenS == 0 { - if rvCanset { - if rvIsNil(rv) { - rvSetDirect(rv, rvSliceZeroCap(ti.rt)) - } else { - rvSetSliceLen(rv, 0) - } - } - if isArray { - d.arrayEnd() - } else { - d.mapEnd() - } - return - } - - rtelem0Mut := !scalarBitset.isset(ti.elemkind) - rtelem := ti.elem - - for k := reflect.Kind(ti.elemkind); k == reflect.Ptr; k = rtelem.Kind() { - rtelem = rtelem.Elem() - } - - var fn *decFnCborBytes - - var rvChanged bool - - var rv0 = rv - var rv9 reflect.Value - - rvlen := rvLenSlice(rv) - rvcap := rvCapSlice(rv) - maxInitLen := d.maxInitLen() - hasLen := containerLenS >= 0 - if hasLen { - if containerLenS > rvcap { - oldRvlenGtZero := rvlen > 0 - rvlen1 := int(decInferLen(containerLenS, maxInitLen, uint(ti.elemsize))) - if rvlen1 == rvlen { - } else if rvlen1 <= rvcap { - if rvCanset { - rvlen = rvlen1 - rvSetSliceLen(rv, rvlen) - } - } else if rvCanset { - rvlen = rvlen1 - rv, rvCanset = rvMakeSlice(rv, f.ti, rvlen, rvlen) - rvcap = rvlen - rvChanged = !rvCanset - } else { - halt.errorStr("cannot decode into non-settable slice") - } - if rvChanged && oldRvlenGtZero && rtelem0Mut { - rvCopySlice(rv, rv0, rtelem) - } - } else if containerLenS != rvlen { - if rvCanset { - rvlen = containerLenS - rvSetSliceLen(rv, rvlen) - } - } - } - - var elemReset = d.h.SliceElementReset - - var rtelemIsPtr bool - var rtelemElem reflect.Type - builtin := ti.tielem.flagDecBuiltin - if builtin { - rtelemIsPtr = ti.elemkind == uint8(reflect.Ptr) - if rtelemIsPtr { - rtelemElem = ti.elem.Elem() - } - } - - var j int - for ; d.containerNext(j, containerLenS, hasLen); j++ { - if j == 0 { - if rvIsNil(rv) { - if rvCanset { - rvlen = int(decInferLen(containerLenS, maxInitLen, uint(ti.elemsize))) - rv, rvCanset = rvMakeSlice(rv, f.ti, rvlen, rvlen) - rvcap = rvlen - rvChanged = !rvCanset - } else { - halt.errorStr("cannot decode into non-settable slice") - } - } - if fn == nil { - fn = d.fn(rtelem) - } - } - - if ctyp == valueTypeArray { - d.arrayElem(j == 0) - } else if j&1 == 0 { - d.mapElemKey(j == 0) - } else { - d.mapElemValue() - } - - if j >= rvlen { - - if rvlen < rvcap { - rvlen = rvcap - if rvCanset { - rvSetSliceLen(rv, rvlen) - } else if rvChanged { - rv = rvSlice(rv, rvlen) - } else { - halt.onerror(errExpandSliceCannotChange) - } - } else { - if !(rvCanset || rvChanged) { - halt.onerror(errExpandSliceCannotChange) - } - rv, rvcap, rvCanset = rvGrowSlice(rv, f.ti, rvcap, 1) - - rvlen = rvcap - rvChanged = !rvCanset - } - } - - rv9 = rvArrayIndex(rv, j, f.ti, true) - if elemReset { - rvSetZero(rv9) - } - if d.d.TryNil() { - rvSetZero(rv9) - } else if builtin { - if rtelemIsPtr { - if rvIsNil(rv9) { - rvSetDirect(rv9, reflect.New(rtelemElem)) - } - d.decode(rv2i(rv9)) - } else { - d.decode(rv2i(rvAddr(rv9, ti.tielem.ptr))) - } - } else { - d.decodeValueNoCheckNil(rv9, fn) - } - } - if j < rvlen { - if rvCanset { - rvSetSliceLen(rv, j) - } else if rvChanged { - rv = rvSlice(rv, j) - } - - } else if j == 0 && rvIsNil(rv) { - if rvCanset { - rv = rvSliceZeroCap(ti.rt) - rvCanset = false - rvChanged = true - } - } - if isArray { - d.arrayEnd() - } else { - d.mapEnd() - } - - if rvChanged { - rvSetDirect(rv0, rv) - } -} - -func (d *decoderCborBytes) kArray(f *decFnInfo, rv reflect.Value) { - _ = d.d - - ti := f.ti - ctyp := d.d.ContainerType() - if handleBytesWithinKArray && (ctyp == valueTypeBytes || ctyp == valueTypeString) { - - if ti.elemkind != uint8(reflect.Uint8) { - halt.errorf("bytes/string in stream can decode into array of bytes, but not %v", ti.rt) - } - rvbs := rvGetArrayBytes(rv, nil) - d.decodeBytesInto(rvbs, true) - return - } - - var containerLenS int - isArray := ctyp == valueTypeArray - if isArray { - containerLenS = d.arrayStart(d.d.ReadArrayStart()) - } else if ctyp == valueTypeMap { - containerLenS = d.mapStart(d.d.ReadMapStart()) * 2 - } else { - halt.errorStr2("decoding into a slice, expect map/array - got ", ctyp.String()) - } - - if containerLenS == 0 { - if isArray { - d.arrayEnd() - } else { - d.mapEnd() - } - return - } - - rtelem := ti.elem - for k := reflect.Kind(ti.elemkind); k == reflect.Ptr; k = rtelem.Kind() { - rtelem = rtelem.Elem() - } - - var rv9 reflect.Value - - rvlen := rv.Len() - hasLen := containerLenS >= 0 - if hasLen && containerLenS > rvlen { - halt.errorf("cannot decode into array with length: %v, less than container length: %v", any(rvlen), any(containerLenS)) - } - - var elemReset = d.h.SliceElementReset - - var rtelemIsPtr bool - var rtelemElem reflect.Type - var fn *decFnCborBytes - builtin := ti.tielem.flagDecBuiltin - if builtin { - rtelemIsPtr = ti.elemkind == uint8(reflect.Ptr) - if rtelemIsPtr { - rtelemElem = ti.elem.Elem() - } - } else { - fn = d.fn(rtelem) - } - - for j := 0; d.containerNext(j, containerLenS, hasLen); j++ { - if ctyp == valueTypeArray { - d.arrayElem(j == 0) - } else if j&1 == 0 { - d.mapElemKey(j == 0) - } else { - d.mapElemValue() - } - - if j >= rvlen { - d.arrayCannotExpand(rvlen, j+1) - d.swallow() - continue - } - - rv9 = rvArrayIndex(rv, j, f.ti, false) - if elemReset { - rvSetZero(rv9) - } - if d.d.TryNil() { - rvSetZero(rv9) - } else if builtin { - if rtelemIsPtr { - if rvIsNil(rv9) { - rvSetDirect(rv9, reflect.New(rtelemElem)) - } - d.decode(rv2i(rv9)) - } else { - d.decode(rv2i(rvAddr(rv9, ti.tielem.ptr))) - } - } else { - d.decodeValueNoCheckNil(rv9, fn) - } - } - if isArray { - d.arrayEnd() - } else { - d.mapEnd() - } -} - -func (d *decoderCborBytes) kChan(f *decFnInfo, rv reflect.Value) { - _ = d.d - - ti := f.ti - if ti.chandir&uint8(reflect.SendDir) == 0 { - halt.errorStr("receive-only channel cannot be decoded") - } - ctyp := d.d.ContainerType() - if ctyp == valueTypeBytes || ctyp == valueTypeString { - - if !(ti.rtid == uint8SliceTypId || ti.elemkind == uint8(reflect.Uint8)) { - halt.errorf("bytes/string in stream must decode into slice/array of bytes, not %v", ti.rt) - } - bs2, _ := d.d.DecodeBytes() - irv := rv2i(rv) - ch, ok := irv.(chan<- byte) - if !ok { - ch = irv.(chan byte) - } - for _, b := range bs2 { - ch <- b - } - return - } - - var rvCanset = rv.CanSet() - - var containerLenS int - isArray := ctyp == valueTypeArray - if isArray { - containerLenS = d.arrayStart(d.d.ReadArrayStart()) - } else if ctyp == valueTypeMap { - containerLenS = d.mapStart(d.d.ReadMapStart()) * 2 - } else { - halt.errorStr2("decoding into a slice, expect map/array - got ", ctyp.String()) - } - - if containerLenS == 0 { - if rvCanset && rvIsNil(rv) { - rvSetDirect(rv, reflect.MakeChan(ti.rt, 0)) - } - if isArray { - d.arrayEnd() - } else { - d.mapEnd() - } - return - } - - rtelem := ti.elem - useTransient := decUseTransient && ti.elemkind != byte(reflect.Ptr) && ti.tielem.flagCanTransient - - for k := reflect.Kind(ti.elemkind); k == reflect.Ptr; k = rtelem.Kind() { - rtelem = rtelem.Elem() - } - - var fn *decFnCborBytes - - var rvChanged bool - var rv0 = rv - var rv9 reflect.Value - - var rvlen int - hasLen := containerLenS >= 0 - maxInitLen := d.maxInitLen() - - for j := 0; d.containerNext(j, containerLenS, hasLen); j++ { - if j == 0 { - if rvIsNil(rv) { - if hasLen { - rvlen = int(decInferLen(containerLenS, maxInitLen, uint(ti.elemsize))) - } else { - rvlen = decDefChanCap - } - if rvCanset { - rv = reflect.MakeChan(ti.rt, rvlen) - rvChanged = true - } else { - halt.errorStr("cannot decode into non-settable chan") - } - } - if fn == nil { - fn = d.fn(rtelem) - } - } - - if ctyp == valueTypeArray { - d.arrayElem(j == 0) - } else if j&1 == 0 { - d.mapElemKey(j == 0) - } else { - d.mapElemValue() - } - - if rv9.IsValid() { - rvSetZero(rv9) - } else if useTransient { - rv9 = d.perType.TransientAddrK(ti.elem, reflect.Kind(ti.elemkind)) - } else { - rv9 = rvZeroAddrK(ti.elem, reflect.Kind(ti.elemkind)) - } - if !d.d.TryNil() { - d.decodeValueNoCheckNil(rv9, fn) - } - rv.Send(rv9) - } - if isArray { - d.arrayEnd() - } else { - d.mapEnd() - } - - if rvChanged { - rvSetDirect(rv0, rv) - } - -} - -func (d *decoderCborBytes) kMap(f *decFnInfo, rv reflect.Value) { - _ = d.d - containerLen := d.mapStart(d.d.ReadMapStart()) - ti := f.ti - if rvIsNil(rv) { - rvlen := int(decInferLen(containerLen, d.maxInitLen(), uint(ti.keysize+ti.elemsize))) - rvSetDirect(rv, makeMapReflect(ti.rt, rvlen)) - } - - if containerLen == 0 { - d.mapEnd() - return - } - - ktype, vtype := ti.key, ti.elem - ktypeId := rt2id(ktype) - vtypeKind := reflect.Kind(ti.elemkind) - ktypeKind := reflect.Kind(ti.keykind) - mparams := getMapReqParams(ti) - - vtypePtr := vtypeKind == reflect.Ptr - ktypePtr := ktypeKind == reflect.Ptr - - vTransient := decUseTransient && !vtypePtr && ti.tielem.flagCanTransient - - kTransient := vTransient && !ktypePtr && ti.tikey.flagCanTransient - - var vtypeElem reflect.Type - - var keyFn, valFn *decFnCborBytes - var ktypeLo, vtypeLo = ktype, vtype - - if ktypeKind == reflect.Ptr { - for ktypeLo = ktype.Elem(); ktypeLo.Kind() == reflect.Ptr; ktypeLo = ktypeLo.Elem() { - } - } - - if vtypePtr { - vtypeElem = vtype.Elem() - for vtypeLo = vtypeElem; vtypeLo.Kind() == reflect.Ptr; vtypeLo = vtypeLo.Elem() { - } - } - - rvkMut := !scalarBitset.isset(ti.keykind) - rvvMut := !scalarBitset.isset(ti.elemkind) - rvvCanNil := isnilBitset.isset(ti.elemkind) - - var rvk, rvkn, rvv, rvvn, rvva, rvvz reflect.Value - - var doMapGet, doMapSet bool - - if !d.h.MapValueReset { - if rvvMut && (vtypeKind != reflect.Interface || !d.h.InterfaceReset) { - doMapGet = true - rvva = mapAddrLoopvarRV(vtype, vtypeKind) - } - } - - ktypeIsString := ktypeId == stringTypId - ktypeIsIntf := ktypeId == intfTypId - hasLen := containerLen >= 0 - - var kstr2bs []byte - var kstr string - - var mapKeyStringSharesBytesBuf bool - var att dBytesAttachState - - var vElem, kElem reflect.Type - kbuiltin := ti.tikey.flagDecBuiltin && ti.keykind != uint8(reflect.Slice) - vbuiltin := ti.tielem.flagDecBuiltin - if kbuiltin && ktypePtr { - kElem = ti.key.Elem() - } - if vbuiltin && vtypePtr { - vElem = ti.elem.Elem() - } - - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - mapKeyStringSharesBytesBuf = false - kstr = "" - if j == 0 { - - if kTransient { - rvk = d.perType.TransientAddr2K(ktype, ktypeKind) - } else { - rvk = rvZeroAddrK(ktype, ktypeKind) - } - if !rvkMut { - rvkn = rvk - } - if !rvvMut { - if vTransient { - rvvn = d.perType.TransientAddrK(vtype, vtypeKind) - } else { - rvvn = rvZeroAddrK(vtype, vtypeKind) - } - } - if !ktypeIsString && keyFn == nil { - keyFn = d.fn(ktypeLo) - } - if valFn == nil { - valFn = d.fn(vtypeLo) - } - } else if rvkMut { - rvSetZero(rvk) - } else { - rvk = rvkn - } - - d.mapElemKey(j == 0) - - if d.d.TryNil() { - rvSetZero(rvk) - } else if ktypeIsString { - kstr2bs, att = d.d.DecodeStringAsBytes() - kstr, mapKeyStringSharesBytesBuf = d.bytes2Str(kstr2bs, att) - rvSetString(rvk, kstr) - } else { - if kbuiltin { - if ktypePtr { - if rvIsNil(rvk) { - rvSetDirect(rvk, reflect.New(kElem)) - } - d.decode(rv2i(rvk)) - } else { - d.decode(rv2i(rvAddr(rvk, ti.tikey.ptr))) - } - } else { - d.decodeValueNoCheckNil(rvk, keyFn) - } - - if ktypeIsIntf { - if rvk2 := rvk.Elem(); rvk2.IsValid() && rvk2.Type() == uint8SliceTyp { - kstr2bs = rvGetBytes(rvk2) - kstr, mapKeyStringSharesBytesBuf = d.bytes2Str(kstr2bs, dBytesAttachView) - rvSetIntf(rvk, rv4istr(kstr)) - } - - } - } - - if mapKeyStringSharesBytesBuf && d.bufio { - if ktypeIsString { - rvSetString(rvk, d.detach2Str(kstr2bs, att)) - } else { - rvSetIntf(rvk, rv4istr(d.detach2Str(kstr2bs, att))) - } - mapKeyStringSharesBytesBuf = false - } - - d.mapElemValue() - - if d.d.TryNil() { - if mapKeyStringSharesBytesBuf { - if ktypeIsString { - rvSetString(rvk, d.detach2Str(kstr2bs, att)) - } else { - rvSetIntf(rvk, rv4istr(d.detach2Str(kstr2bs, att))) - } - } - - if !rvvz.IsValid() { - rvvz = rvZeroK(vtype, vtypeKind) - } - mapSet(rv, rvk, rvvz, mparams) - continue - } - - doMapSet = true - - if !rvvMut { - rvv = rvvn - } else if !doMapGet { - goto NEW_RVV - } else { - rvv = mapGet(rv, rvk, rvva, mparams) - if !rvv.IsValid() || (rvvCanNil && rvIsNil(rvv)) { - goto NEW_RVV - } - switch vtypeKind { - case reflect.Ptr, reflect.Map: - doMapSet = false - case reflect.Interface: - - rvvn = rvv.Elem() - if k := rvvn.Kind(); (k == reflect.Ptr || k == reflect.Map) && !rvIsNil(rvvn) { - d.decodeValueNoCheckNil(rvvn, nil) - continue - } - - rvvn = rvZeroAddrK(vtype, vtypeKind) - rvSetIntf(rvvn, rvv) - rvv = rvvn - default: - - if vTransient { - rvvn = d.perType.TransientAddrK(vtype, vtypeKind) - } else { - rvvn = rvZeroAddrK(vtype, vtypeKind) - } - rvSetDirect(rvvn, rvv) - rvv = rvvn - } - } - goto DECODE_VALUE_NO_CHECK_NIL - - NEW_RVV: - if vtypePtr { - rvv = reflect.New(vtypeElem) - } else if vTransient { - rvv = d.perType.TransientAddrK(vtype, vtypeKind) - } else { - rvv = rvZeroAddrK(vtype, vtypeKind) - } - - DECODE_VALUE_NO_CHECK_NIL: - if doMapSet && mapKeyStringSharesBytesBuf { - if ktypeIsString { - rvSetString(rvk, d.detach2Str(kstr2bs, att)) - } else { - rvSetIntf(rvk, rv4istr(d.detach2Str(kstr2bs, att))) - } - } - if vbuiltin { - if vtypePtr { - if rvIsNil(rvv) { - rvSetDirect(rvv, reflect.New(vElem)) - } - d.decode(rv2i(rvv)) - } else { - d.decode(rv2i(rvAddr(rvv, ti.tielem.ptr))) - } - } else { - d.decodeValueNoCheckNil(rvv, valFn) - } - if doMapSet { - mapSet(rv, rvk, rvv, mparams) - } - } - - d.mapEnd() -} - -func (d *decoderCborBytes) init(h Handle) { - initHandle(h) - callMake(&d.d) - d.hh = h - d.h = h.getBasicHandle() - - d.err = errDecoderNotInitialized - - if d.h.InternString && d.is == nil { - d.is.init() - } - - d.fp = d.d.init(h, &d.decoderBase, d).(*fastpathDsCborBytes) - - if d.bytes { - d.rtidFn = &d.h.rtidFnsDecBytes - d.rtidFnNoExt = &d.h.rtidFnsDecNoExtBytes - } else { - d.bufio = d.h.ReaderBufferSize > 0 - d.rtidFn = &d.h.rtidFnsDecIO - d.rtidFnNoExt = &d.h.rtidFnsDecNoExtIO - } - - d.reset() - -} - -func (d *decoderCborBytes) reset() { - d.d.reset() - d.err = nil - d.c = 0 - d.depth = 0 - d.calls = 0 - - d.maxdepth = decDefMaxDepth - if d.h.MaxDepth > 0 { - d.maxdepth = d.h.MaxDepth - } - d.mtid = 0 - d.stid = 0 - d.mtr = false - d.str = false - if d.h.MapType != nil { - d.mtid = rt2id(d.h.MapType) - _, d.mtr = fastpathAvIndex(d.mtid) - } - if d.h.SliceType != nil { - d.stid = rt2id(d.h.SliceType) - _, d.str = fastpathAvIndex(d.stid) - } -} - -func (d *decoderCborBytes) Reset(r io.Reader) { - if d.bytes { - halt.onerror(errDecNoResetBytesWithReader) - } - d.reset() - if r == nil { - r = &eofReader - } - d.d.resetInIO(r) -} - -func (d *decoderCborBytes) ResetBytes(in []byte) { - if !d.bytes { - halt.onerror(errDecNoResetReaderWithBytes) - } - d.resetBytes(in) -} - -func (d *decoderCborBytes) resetBytes(in []byte) { - d.reset() - if in == nil { - in = zeroByteSlice - } - d.d.resetInBytes(in) -} - -func (d *decoderCborBytes) ResetString(s string) { - d.ResetBytes(bytesView(s)) -} - -func (d *decoderCborBytes) Decode(v interface{}) (err error) { - - defer panicValToErr(d, callRecoverSentinel, &d.err, &err, debugging) - d.mustDecode(v) - return -} - -func (d *decoderCborBytes) MustDecode(v interface{}) { - defer panicValToErr(d, callRecoverSentinel, &d.err, nil, true) - d.mustDecode(v) - return -} - -func (d *decoderCborBytes) mustDecode(v interface{}) { - halt.onerror(d.err) - if d.hh == nil { - halt.onerror(errNoFormatHandle) - } - - d.calls++ - d.decode(v) - d.calls-- -} - -func (d *decoderCborBytes) Release() {} - -func (d *decoderCborBytes) swallow() { - d.d.nextValueBytes() -} - -func (d *decoderCborBytes) nextValueBytes() []byte { - return d.d.nextValueBytes() -} - -func (d *decoderCborBytes) decode(iv interface{}) { - _ = d.d - - rv, ok := isNil(iv, true) - if ok { - halt.onerror(errCannotDecodeIntoNil) - } - - switch v := iv.(type) { - - case *string: - *v = d.detach2Str(d.d.DecodeStringAsBytes()) - case *bool: - *v = d.d.DecodeBool() - case *int: - *v = int(chkOvf.IntV(d.d.DecodeInt64(), intBitsize)) - case *int8: - *v = int8(chkOvf.IntV(d.d.DecodeInt64(), 8)) - case *int16: - *v = int16(chkOvf.IntV(d.d.DecodeInt64(), 16)) - case *int32: - *v = int32(chkOvf.IntV(d.d.DecodeInt64(), 32)) - case *int64: - *v = d.d.DecodeInt64() - case *uint: - *v = uint(chkOvf.UintV(d.d.DecodeUint64(), uintBitsize)) - case *uint8: - *v = uint8(chkOvf.UintV(d.d.DecodeUint64(), 8)) - case *uint16: - *v = uint16(chkOvf.UintV(d.d.DecodeUint64(), 16)) - case *uint32: - *v = uint32(chkOvf.UintV(d.d.DecodeUint64(), 32)) - case *uint64: - *v = d.d.DecodeUint64() - case *uintptr: - *v = uintptr(chkOvf.UintV(d.d.DecodeUint64(), uintBitsize)) - case *float32: - *v = d.d.DecodeFloat32() - case *float64: - *v = d.d.DecodeFloat64() - case *complex64: - *v = complex(d.d.DecodeFloat32(), 0) - case *complex128: - *v = complex(d.d.DecodeFloat64(), 0) - case *[]byte: - *v, _ = d.decodeBytesInto(*v, false) - case []byte: - - d.decodeBytesInto(v[:len(v):len(v)], true) - case *time.Time: - *v = d.d.DecodeTime() - case *Raw: - *v = d.rawBytes() - - case *interface{}: - d.decodeValue(rv4iptr(v), nil) - - case reflect.Value: - if ok, _ = isDecodeable(v); !ok { - d.haltAsNotDecodeable(v) - } - d.decodeValue(v, nil) - - default: - - if skipFastpathTypeSwitchInDirectCall || !d.dh.fastpathDecodeTypeSwitch(iv, d) { - if !rv.IsValid() { - rv = reflect.ValueOf(iv) - } - if ok, _ = isDecodeable(rv); !ok { - d.haltAsNotDecodeable(rv) - } - d.decodeValue(rv, nil) - } - } -} - -func (d *decoderCborBytes) decodeValue(rv reflect.Value, fn *decFnCborBytes) { - if d.d.TryNil() { - decSetNonNilRV2Zero(rv) - } else { - d.decodeValueNoCheckNil(rv, fn) - } -} - -func (d *decoderCborBytes) decodeValueNoCheckNil(rv reflect.Value, fn *decFnCborBytes) { - - var rvp reflect.Value - var rvpValid bool -PTR: - if rv.Kind() == reflect.Ptr { - rvpValid = true - if rvIsNil(rv) { - rvSetDirect(rv, reflect.New(rv.Type().Elem())) - } - rvp = rv - rv = rv.Elem() - goto PTR - } - - if fn == nil { - fn = d.fn(rv.Type()) - } - if fn.i.addrD { - if rvpValid { - rv = rvp - } else if rv.CanAddr() { - rv = rvAddr(rv, fn.i.ti.ptr) - } else if fn.i.addrDf { - halt.errorStr("cannot decode into a non-pointer value") - } - } - fn.fd(d, &fn.i, rv) -} - -func (d *decoderCborBytes) decodeAs(v interface{}, t reflect.Type, ext bool) { - if ext { - d.decodeValue(baseRV(v), d.fn(t)) - } else { - d.decodeValue(baseRV(v), d.fnNoExt(t)) - } -} - -func (d *decoderCborBytes) structFieldNotFound(index int, rvkencname string) { - - if d.h.ErrorIfNoField { - if index >= 0 { - halt.errorInt("no matching struct field found when decoding stream array at index ", int64(index)) - } else if rvkencname != "" { - halt.errorStr2("no matching struct field found when decoding stream map with key ", rvkencname) - } - } - d.swallow() -} - -func (d *decoderCborBytes) decodeBytesInto(out []byte, mustFit bool) (v []byte, state dBytesIntoState) { - v, att := d.d.DecodeBytes() - if cap(v) == 0 || (att >= dBytesAttachViewZerocopy && !mustFit) { - - return - } - if len(v) == 0 { - v = zeroByteSlice - return - } - if len(out) == len(v) { - state = dBytesIntoParamOut - } else if cap(out) >= len(v) { - out = out[:len(v)] - state = dBytesIntoParamOutSlice - } else if mustFit { - halt.errorf("bytes capacity insufficient for decoded bytes: got/expected: %d/%d", len(v), len(out)) - } else { - out = make([]byte, len(v)) - state = dBytesIntoNew - } - copy(out, v) - v = out - return -} - -func (d *decoderCborBytes) rawBytes() (v []byte) { - - v = d.d.nextValueBytes() - if d.bytes && !d.h.ZeroCopy { - vv := make([]byte, len(v)) - copy(vv, v) - v = vv - } - return -} - -func (d *decoderCborBytes) wrapErr(v error, err *error) { - *err = wrapCodecErr(v, d.hh.Name(), d.d.NumBytesRead(), false) -} - -func (d *decoderCborBytes) NumBytesRead() int { - return d.d.NumBytesRead() -} - -func (d *decoderCborBytes) containerNext(j, containerLen int, hasLen bool) bool { - - if hasLen { - return j < containerLen - } - return !d.d.CheckBreak() -} - -func (d *decoderCborBytes) mapElemKey(firstTime bool) { - d.d.ReadMapElemKey(firstTime) - d.c = containerMapKey -} - -func (d *decoderCborBytes) mapElemValue() { - d.d.ReadMapElemValue() - d.c = containerMapValue -} - -func (d *decoderCborBytes) mapEnd() { - d.d.ReadMapEnd() - d.depthDecr() - d.c = 0 -} - -func (d *decoderCborBytes) arrayElem(firstTime bool) { - d.d.ReadArrayElem(firstTime) - d.c = containerArrayElem -} - -func (d *decoderCborBytes) arrayEnd() { - d.d.ReadArrayEnd() - d.depthDecr() - d.c = 0 -} - -func (d *decoderCborBytes) interfaceExtConvertAndDecode(v interface{}, ext InterfaceExt) { - - var vv interface{} - d.decode(&vv) - ext.UpdateExt(v, vv) - -} - -func (d *decoderCborBytes) fn(t reflect.Type) *decFnCborBytes { - return d.dh.decFnViaBH(t, d.rtidFn, d.h, d.fp, false) -} - -func (d *decoderCborBytes) fnNoExt(t reflect.Type) *decFnCborBytes { - return d.dh.decFnViaBH(t, d.rtidFnNoExt, d.h, d.fp, true) -} - -func (helperDecDriverCborBytes) newDecoderBytes(in []byte, h Handle) *decoderCborBytes { - var c1 decoderCborBytes - c1.bytes = true - c1.init(h) - c1.ResetBytes(in) - return &c1 -} - -func (helperDecDriverCborBytes) newDecoderIO(in io.Reader, h Handle) *decoderCborBytes { - var c1 decoderCborBytes - c1.init(h) - c1.Reset(in) - return &c1 -} - -func (helperDecDriverCborBytes) decFnloadFastpathUnderlying(ti *typeInfo, fp *fastpathDsCborBytes) (f *fastpathDCborBytes, u reflect.Type) { - rtid := rt2id(ti.fastpathUnderlying) - idx, ok := fastpathAvIndex(rtid) - if !ok { - return - } - f = &fp[idx] - if uint8(reflect.Array) == ti.kind { - u = reflect.ArrayOf(ti.rt.Len(), ti.elem) - } else { - u = f.rt - } - return -} - -func (helperDecDriverCborBytes) decFindRtidFn(s []decRtidFnCborBytes, rtid uintptr) (i uint, fn *decFnCborBytes) { - - var h uint - var j = uint(len(s)) -LOOP: - if i < j { - h = (i + j) >> 1 - if s[h].rtid < rtid { - i = h + 1 - } else { - j = h - } - goto LOOP - } - if i < uint(len(s)) && s[i].rtid == rtid { - fn = s[i].fn - } - return -} - -func (helperDecDriverCborBytes) decFromRtidFnSlice(fns *atomicRtidFnSlice) (s []decRtidFnCborBytes) { - if v := fns.load(); v != nil { - s = *(lowLevelToPtr[[]decRtidFnCborBytes](v)) - } - return -} - -func (dh helperDecDriverCborBytes) decFnViaBH(rt reflect.Type, fns *atomicRtidFnSlice, x *BasicHandle, fp *fastpathDsCborBytes, - checkExt bool) (fn *decFnCborBytes) { - return dh.decFnVia(rt, fns, x.typeInfos(), &x.mu, x.extHandle, fp, - checkExt, x.CheckCircularRef, x.timeBuiltin, x.binaryHandle, x.jsonHandle) -} - -func (dh helperDecDriverCborBytes) decFnVia(rt reflect.Type, fns *atomicRtidFnSlice, - tinfos *TypeInfos, mu *sync.Mutex, exth extHandle, fp *fastpathDsCborBytes, - checkExt, checkCircularRef, timeBuiltin, binaryEncoding, json bool) (fn *decFnCborBytes) { - rtid := rt2id(rt) - var sp []decRtidFnCborBytes = dh.decFromRtidFnSlice(fns) - if sp != nil { - _, fn = dh.decFindRtidFn(sp, rtid) - } - if fn == nil { - fn = dh.decFnViaLoader(rt, rtid, fns, tinfos, mu, exth, fp, checkExt, checkCircularRef, timeBuiltin, binaryEncoding, json) - } - return -} - -func (dh helperDecDriverCborBytes) decFnViaLoader(rt reflect.Type, rtid uintptr, fns *atomicRtidFnSlice, - tinfos *TypeInfos, mu *sync.Mutex, exth extHandle, fp *fastpathDsCborBytes, - checkExt, checkCircularRef, timeBuiltin, binaryEncoding, json bool) (fn *decFnCborBytes) { - - fn = dh.decFnLoad(rt, rtid, tinfos, exth, fp, checkExt, checkCircularRef, timeBuiltin, binaryEncoding, json) - var sp []decRtidFnCborBytes - mu.Lock() - sp = dh.decFromRtidFnSlice(fns) - - if sp == nil { - sp = []decRtidFnCborBytes{{rtid, fn}} - fns.store(ptrToLowLevel(&sp)) - } else { - idx, fn2 := dh.decFindRtidFn(sp, rtid) - if fn2 == nil { - sp2 := make([]decRtidFnCborBytes, len(sp)+1) - copy(sp2[idx+1:], sp[idx:]) - copy(sp2, sp[:idx]) - sp2[idx] = decRtidFnCborBytes{rtid, fn} - fns.store(ptrToLowLevel(&sp2)) - } - } - mu.Unlock() - return -} - -func (dh helperDecDriverCborBytes) decFnLoad(rt reflect.Type, rtid uintptr, tinfos *TypeInfos, - exth extHandle, fp *fastpathDsCborBytes, - checkExt, checkCircularRef, timeBuiltin, binaryEncoding, json bool) (fn *decFnCborBytes) { - fn = new(decFnCborBytes) - fi := &(fn.i) - ti := tinfos.get(rtid, rt) - fi.ti = ti - rk := reflect.Kind(ti.kind) - - fi.addrDf = true - - if rtid == timeTypId && timeBuiltin { - fn.fd = (*decoderCborBytes).kTime - } else if rtid == rawTypId { - fn.fd = (*decoderCborBytes).raw - } else if rtid == rawExtTypId { - fn.fd = (*decoderCborBytes).rawExt - fi.addrD = true - } else if xfFn := exth.getExt(rtid, checkExt); xfFn != nil { - fi.xfTag, fi.xfFn = xfFn.tag, xfFn.ext - fn.fd = (*decoderCborBytes).ext - fi.addrD = true - } else if ti.flagSelfer || ti.flagSelferPtr { - fn.fd = (*decoderCborBytes).selferUnmarshal - fi.addrD = ti.flagSelferPtr - } else if supportMarshalInterfaces && binaryEncoding && - (ti.flagBinaryMarshaler || ti.flagBinaryMarshalerPtr) && - (ti.flagBinaryUnmarshaler || ti.flagBinaryUnmarshalerPtr) { - fn.fd = (*decoderCborBytes).binaryUnmarshal - fi.addrD = ti.flagBinaryUnmarshalerPtr - } else if supportMarshalInterfaces && !binaryEncoding && json && - (ti.flagJsonMarshaler || ti.flagJsonMarshalerPtr) && - (ti.flagJsonUnmarshaler || ti.flagJsonUnmarshalerPtr) { - - fn.fd = (*decoderCborBytes).jsonUnmarshal - fi.addrD = ti.flagJsonUnmarshalerPtr - } else if supportMarshalInterfaces && !binaryEncoding && - (ti.flagTextMarshaler || ti.flagTextMarshalerPtr) && - (ti.flagTextUnmarshaler || ti.flagTextUnmarshalerPtr) { - fn.fd = (*decoderCborBytes).textUnmarshal - fi.addrD = ti.flagTextUnmarshalerPtr - } else { - if fastpathEnabled && (rk == reflect.Map || rk == reflect.Slice || rk == reflect.Array) { - var rtid2 uintptr - if !ti.flagHasPkgPath { - rtid2 = rtid - if rk == reflect.Array { - rtid2 = rt2id(ti.key) - } - if idx, ok := fastpathAvIndex(rtid2); ok { - fn.fd = fp[idx].decfn - fi.addrD = true - fi.addrDf = false - if rk == reflect.Array { - fi.addrD = false - } - } - } else { - - xfe, xrt := dh.decFnloadFastpathUnderlying(ti, fp) - if xfe != nil { - xfnf2 := xfe.decfn - if rk == reflect.Array { - fi.addrD = false - fn.fd = func(d *decoderCborBytes, xf *decFnInfo, xrv reflect.Value) { - xfnf2(d, xf, rvConvert(xrv, xrt)) - } - } else { - fi.addrD = true - fi.addrDf = false - xptr2rt := reflect.PointerTo(xrt) - fn.fd = func(d *decoderCborBytes, xf *decFnInfo, xrv reflect.Value) { - if xrv.Kind() == reflect.Ptr { - xfnf2(d, xf, rvConvert(xrv, xptr2rt)) - } else { - xfnf2(d, xf, rvConvert(xrv, xrt)) - } - } - } - } - } - } - if fn.fd == nil { - switch rk { - case reflect.Bool: - fn.fd = (*decoderCborBytes).kBool - case reflect.String: - fn.fd = (*decoderCborBytes).kString - case reflect.Int: - fn.fd = (*decoderCborBytes).kInt - case reflect.Int8: - fn.fd = (*decoderCborBytes).kInt8 - case reflect.Int16: - fn.fd = (*decoderCborBytes).kInt16 - case reflect.Int32: - fn.fd = (*decoderCborBytes).kInt32 - case reflect.Int64: - fn.fd = (*decoderCborBytes).kInt64 - case reflect.Uint: - fn.fd = (*decoderCborBytes).kUint - case reflect.Uint8: - fn.fd = (*decoderCborBytes).kUint8 - case reflect.Uint16: - fn.fd = (*decoderCborBytes).kUint16 - case reflect.Uint32: - fn.fd = (*decoderCborBytes).kUint32 - case reflect.Uint64: - fn.fd = (*decoderCborBytes).kUint64 - case reflect.Uintptr: - fn.fd = (*decoderCborBytes).kUintptr - case reflect.Float32: - fn.fd = (*decoderCborBytes).kFloat32 - case reflect.Float64: - fn.fd = (*decoderCborBytes).kFloat64 - case reflect.Complex64: - fn.fd = (*decoderCborBytes).kComplex64 - case reflect.Complex128: - fn.fd = (*decoderCborBytes).kComplex128 - case reflect.Chan: - fn.fd = (*decoderCborBytes).kChan - case reflect.Slice: - fn.fd = (*decoderCborBytes).kSlice - case reflect.Array: - fi.addrD = false - fn.fd = (*decoderCborBytes).kArray - case reflect.Struct: - if ti.simple { - fn.fd = (*decoderCborBytes).kStructSimple - } else { - fn.fd = (*decoderCborBytes).kStruct - } - case reflect.Map: - fn.fd = (*decoderCborBytes).kMap - case reflect.Interface: - - fn.fd = (*decoderCborBytes).kInterface - default: - - fn.fd = (*decoderCborBytes).kErr - } - } - } - return -} -func (e *cborEncDriverBytes) EncodeNil() { - e.w.writen1(cborBdNil) -} - -func (e *cborEncDriverBytes) EncodeBool(b bool) { - if b { - e.w.writen1(cborBdTrue) - } else { - e.w.writen1(cborBdFalse) - } -} - -func (e *cborEncDriverBytes) EncodeFloat32(f float32) { - b := math.Float32bits(f) - if e.h.OptimumSize { - if h := floatToHalfFloatBits(b); halfFloatToFloatBits(h) == b { - e.w.writen1(cborBdFloat16) - e.w.writen2(bigen.PutUint16(h)) - return - } - } - e.w.writen1(cborBdFloat32) - e.w.writen4(bigen.PutUint32(b)) -} - -func (e *cborEncDriverBytes) EncodeFloat64(f float64) { - if e.h.OptimumSize { - if f32 := float32(f); float64(f32) == f { - e.EncodeFloat32(f32) - return - } - } - e.w.writen1(cborBdFloat64) - e.w.writen8(bigen.PutUint64(math.Float64bits(f))) -} - -func (e *cborEncDriverBytes) encUint(v uint64, bd byte) { - if v <= 0x17 { - e.w.writen1(byte(v) + bd) - } else if v <= math.MaxUint8 { - e.w.writen2(bd+0x18, uint8(v)) - } else if v <= math.MaxUint16 { - e.w.writen1(bd + 0x19) - e.w.writen2(bigen.PutUint16(uint16(v))) - } else if v <= math.MaxUint32 { - e.w.writen1(bd + 0x1a) - e.w.writen4(bigen.PutUint32(uint32(v))) - } else { - e.w.writen1(bd + 0x1b) - e.w.writen8(bigen.PutUint64(v)) - } -} - -func (e *cborEncDriverBytes) EncodeInt(v int64) { - if v < 0 { - e.encUint(uint64(-1-v), cborBaseNegInt) - } else { - e.encUint(uint64(v), cborBaseUint) - } -} - -func (e *cborEncDriverBytes) EncodeUint(v uint64) { - e.encUint(v, cborBaseUint) -} - -func (e *cborEncDriverBytes) encLen(bd byte, length int) { - e.encUint(uint64(length), bd) -} - -func (e *cborEncDriverBytes) EncodeTime(t time.Time) { - if t.IsZero() { - e.EncodeNil() - } else if e.h.TimeRFC3339 { - e.encUint(0, cborBaseTag) - e.encStringBytesS(cborBaseString, stringView(t.AppendFormat(e.b[:0], time.RFC3339Nano))) - } else { - e.encUint(1, cborBaseTag) - t = t.UTC().Round(time.Microsecond) - sec, nsec := t.Unix(), uint64(t.Nanosecond()) - if nsec == 0 { - e.EncodeInt(sec) - } else { - e.EncodeFloat64(float64(sec) + float64(nsec)/1e9) - } - } -} - -func (e *cborEncDriverBytes) EncodeExt(rv interface{}, basetype reflect.Type, xtag uint64, ext Ext) { - e.encUint(uint64(xtag), cborBaseTag) - if ext == SelfExt { - e.enc.encodeAs(rv, basetype, false) - } else if v := ext.ConvertExt(rv); v == nil { - e.writeNilBytes() - } else { - e.enc.encodeI(v) - } -} - -func (e *cborEncDriverBytes) EncodeRawExt(re *RawExt) { - e.encUint(uint64(re.Tag), cborBaseTag) - if re.Data != nil { - e.w.writeb(re.Data) - } else if re.Value != nil { - e.enc.encodeI(re.Value) - } else { - e.EncodeNil() - } -} - -func (e *cborEncDriverBytes) WriteArrayEmpty() { - if e.h.IndefiniteLength { - e.w.writen2(cborBdIndefiniteArray, cborBdBreak) - } else { - e.w.writen1(cborBaseArray) - - } -} - -func (e *cborEncDriverBytes) WriteMapEmpty() { - if e.h.IndefiniteLength { - e.w.writen2(cborBdIndefiniteMap, cborBdBreak) - } else { - e.w.writen1(cborBaseMap) - - } -} - -func (e *cborEncDriverBytes) WriteArrayStart(length int) { - if e.h.IndefiniteLength { - e.w.writen1(cborBdIndefiniteArray) - } else { - e.encLen(cborBaseArray, length) - } -} - -func (e *cborEncDriverBytes) WriteMapStart(length int) { - if e.h.IndefiniteLength { - e.w.writen1(cborBdIndefiniteMap) - } else { - e.encLen(cborBaseMap, length) - } -} - -func (e *cborEncDriverBytes) WriteMapEnd() { - if e.h.IndefiniteLength { - e.w.writen1(cborBdBreak) - } -} - -func (e *cborEncDriverBytes) WriteArrayEnd() { - if e.h.IndefiniteLength { - e.w.writen1(cborBdBreak) - } -} - -func (e *cborEncDriverBytes) EncodeString(v string) { - bb := cborBaseString - if e.h.StringToRaw { - bb = cborBaseBytes - } - e.encStringBytesS(bb, v) -} - -func (e *cborEncDriverBytes) EncodeStringNoEscape4Json(v string) { e.EncodeString(v) } - -func (e *cborEncDriverBytes) EncodeStringBytesRaw(v []byte) { - e.encStringBytesS(cborBaseBytes, stringView(v)) -} - -func (e *cborEncDriverBytes) encStringBytesS(bb byte, v string) { - if e.h.IndefiniteLength { - if bb == cborBaseBytes { - e.w.writen1(cborBdIndefiniteBytes) - } else { - e.w.writen1(cborBdIndefiniteString) - } - vlen := uint(len(v)) - n := max(4, min(vlen/4, 1024)) - for i := uint(0); i < vlen; { - i2 := i + n - if i2 >= vlen { - i2 = vlen - } - v2 := v[i:i2] - e.encLen(bb, len(v2)) - e.w.writestr(v2) - i = i2 - } - e.w.writen1(cborBdBreak) - } else { - e.encLen(bb, len(v)) - e.w.writestr(v) - } -} - -func (e *cborEncDriverBytes) EncodeBytes(v []byte) { - if v == nil { - e.writeNilBytes() - return - } - e.EncodeStringBytesRaw(v) -} - -func (e *cborEncDriverBytes) writeNilOr(v byte) { - if !e.h.NilCollectionToZeroLength { - v = cborBdNil - } - e.w.writen1(v) -} - -func (e *cborEncDriverBytes) writeNilArray() { - e.writeNilOr(cborBaseArray) -} - -func (e *cborEncDriverBytes) writeNilMap() { - e.writeNilOr(cborBaseMap) -} - -func (e *cborEncDriverBytes) writeNilBytes() { - e.writeNilOr(cborBaseBytes) -} - -func (d *cborDecDriverBytes) readNextBd() { - d.bd = d.r.readn1() - d.bdRead = true -} - -func (d *cborDecDriverBytes) advanceNil() (null bool) { - if !d.bdRead { - d.readNextBd() - } - if d.bd == cborBdNil || d.bd == cborBdUndefined { - d.bdRead = false - return true - } - return -} - -func (d *cborDecDriverBytes) TryNil() bool { - return d.advanceNil() -} - -func (d *cborDecDriverBytes) skipTags() { - for d.bd>>5 == cborMajorTag { - d.decUint() - d.bd = d.r.readn1() - } -} - -func (d *cborDecDriverBytes) ContainerType() (vt valueType) { - if !d.bdRead { - d.readNextBd() - } - if d.h.SkipUnexpectedTags { - d.skipTags() - } - if d.bd == cborBdNil { - d.bdRead = false - return valueTypeNil - } - major := d.bd >> 5 - if major == cborMajorBytes { - return valueTypeBytes - } else if major == cborMajorString { - return valueTypeString - } else if major == cborMajorArray { - return valueTypeArray - } else if major == cborMajorMap { - return valueTypeMap - } - return valueTypeUnset -} - -func (d *cborDecDriverBytes) CheckBreak() (v bool) { - if !d.bdRead { - d.readNextBd() - } - if d.bd == cborBdBreak { - d.bdRead = false - v = true - } - return -} - -func (d *cborDecDriverBytes) decUint() (ui uint64) { - v := d.bd & 0x1f - if v <= 0x17 { - ui = uint64(v) - } else if v == 0x18 { - ui = uint64(d.r.readn1()) - } else if v == 0x19 { - ui = uint64(bigen.Uint16(d.r.readn2())) - } else if v == 0x1a { - ui = uint64(bigen.Uint32(d.r.readn4())) - } else if v == 0x1b { - ui = uint64(bigen.Uint64(d.r.readn8())) - } else { - halt.errorf("invalid descriptor decoding uint: %x/%s (%x)", d.bd, cbordesc(d.bd), v) - } - return -} - -func (d *cborDecDriverBytes) decLen() int { - return int(d.decUint()) -} - -func (d *cborDecDriverBytes) decFloat() (f float64, ok bool) { - ok = true - switch d.bd { - case cborBdFloat16: - f = float64(math.Float32frombits(halfFloatToFloatBits(bigen.Uint16(d.r.readn2())))) - case cborBdFloat32: - f = float64(math.Float32frombits(bigen.Uint32(d.r.readn4()))) - case cborBdFloat64: - f = math.Float64frombits(bigen.Uint64(d.r.readn8())) - default: - if d.bd>>5 == cborMajorTag { - - switch d.bd & 0x1f { - case 2: - f = d.decTagBigIntAsFloat(false) - case 3: - f = d.decTagBigIntAsFloat(true) - case 4: - f = d.decTagBigFloatAsFloat(true) - case 5: - f = d.decTagBigFloatAsFloat(false) - default: - ok = false - } - } else { - ok = false - } - } - return -} - -func (d *cborDecDriverBytes) decInteger() (ui uint64, neg, ok bool) { - ok = true - switch d.bd >> 5 { - case cborMajorUint: - ui = d.decUint() - case cborMajorNegInt: - ui = d.decUint() - neg = true - default: - ok = false - } - return -} - -func (d *cborDecDriverBytes) DecodeInt64() (i int64) { - if d.advanceNil() { - return - } - if d.h.SkipUnexpectedTags { - d.skipTags() - } - v1, v2, v3 := d.decInteger() - i = decNegintPosintFloatNumberHelper{d}.int64(v1, v2, v3, true) - d.bdRead = false - return -} - -func (d *cborDecDriverBytes) DecodeUint64() (ui uint64) { - if d.advanceNil() { - return - } - if d.h.SkipUnexpectedTags { - d.skipTags() - } - ui = decNegintPosintFloatNumberHelper{d}.uint64(d.decInteger()) - d.bdRead = false - return -} - -func (d *cborDecDriverBytes) DecodeFloat64() (f float64) { - if d.advanceNil() { - return - } - if d.h.SkipUnexpectedTags { - d.skipTags() - } - v1, v2 := d.decFloat() - f = decNegintPosintFloatNumberHelper{d}.float64(v1, v2, true) - d.bdRead = false - return -} - -func (d *cborDecDriverBytes) DecodeBool() (b bool) { - if d.advanceNil() { - return - } - if d.h.SkipUnexpectedTags { - d.skipTags() - } - if d.bd == cborBdTrue { - b = true - } else if d.bd == cborBdFalse { - } else { - halt.errorf("not bool - %s %x/%s", msgBadDesc, d.bd, cbordesc(d.bd)) - } - d.bdRead = false - return -} - -func (d *cborDecDriverBytes) ReadMapStart() (length int) { - if d.advanceNil() { - return containerLenNil - } - if d.h.SkipUnexpectedTags { - d.skipTags() - } - d.bdRead = false - if d.bd == cborBdIndefiniteMap { - return containerLenUnknown - } - if d.bd>>5 != cborMajorMap { - halt.errorf("error reading map; got major type: %x, expected %x/%s", d.bd>>5, cborMajorMap, cbordesc(d.bd)) - } - return d.decLen() -} - -func (d *cborDecDriverBytes) ReadArrayStart() (length int) { - if d.advanceNil() { - return containerLenNil - } - if d.h.SkipUnexpectedTags { - d.skipTags() - } - d.bdRead = false - if d.bd == cborBdIndefiniteArray { - return containerLenUnknown - } - if d.bd>>5 != cborMajorArray { - halt.errorf("invalid array; got major type: %x, expect: %x/%s", d.bd>>5, cborMajorArray, cbordesc(d.bd)) - } - return d.decLen() -} - -func (d *cborDecDriverBytes) DecodeBytes() (bs []byte, state dBytesAttachState) { - if d.advanceNil() { - return - } - if d.h.SkipUnexpectedTags { - d.skipTags() - } - fnEnsureNonNilBytes := func() { - - if bs == nil { - bs = zeroByteSlice - state = dBytesDetach - } - } - if d.bd == cborBdIndefiniteBytes || d.bd == cborBdIndefiniteString { - major := d.bd >> 5 - val4str := d.h.ValidateUnicode && major == cborMajorString - bs = d.d.buf[:0] - d.bdRead = false - for !d.CheckBreak() { - if d.bd>>5 != major { - const msg = "malformed indefinite string/bytes %x (%s); " + - "contains chunk with major type %v, expected %v" - halt.errorf(msg, d.bd, cbordesc(d.bd), d.bd>>5, major) - } - n := uint(d.decLen()) - bs = append(bs, d.r.readx(n)...) - d.bdRead = false - if val4str && !utf8.Valid(bs[len(bs)-int(n):]) { - const msg = "indefinite-length text string contains chunk " + - "that is not a valid utf-8 sequence: 0x%x" - halt.errorf(msg, bs[len(bs)-int(n):]) - } - } - d.bdRead = false - d.d.buf = bs - state = dBytesAttachBuffer - fnEnsureNonNilBytes() - return - } - if d.bd == cborBdIndefiniteArray { - d.bdRead = false - bs = d.d.buf[:0] - for !d.CheckBreak() { - bs = append(bs, uint8(chkOvf.UintV(d.DecodeUint64(), 8))) - } - d.d.buf = bs - state = dBytesAttachBuffer - fnEnsureNonNilBytes() - return - } - var cond bool - if d.bd>>5 == cborMajorArray { - d.bdRead = false - slen := d.decLen() - bs, cond = usableByteSlice(d.d.buf, slen) - for i := 0; i < len(bs); i++ { - bs[i] = uint8(chkOvf.UintV(d.DecodeUint64(), 8)) - } - for i := len(bs); i < slen; i++ { - bs = append(bs, uint8(chkOvf.UintV(d.DecodeUint64(), 8))) - } - if cond { - d.d.buf = bs - } - state = dBytesAttachBuffer - fnEnsureNonNilBytes() - return - } - clen := d.decLen() - d.bdRead = false - bs, cond = d.r.readxb(uint(clen)) - state = d.d.attachState(cond) - return -} - -func (d *cborDecDriverBytes) DecodeStringAsBytes() (out []byte, state dBytesAttachState) { - out, state = d.DecodeBytes() - if d.h.ValidateUnicode && !utf8.Valid(out) { - halt.errorf("DecodeStringAsBytes: invalid UTF-8: %s", out) - } - return -} - -func (d *cborDecDriverBytes) DecodeTime() (t time.Time) { - if d.advanceNil() { - return - } - if d.bd>>5 != cborMajorTag { - halt.errorf("error reading tag; expected major type: %x, got: %x", cborMajorTag, d.bd>>5) - } - xtag := d.decUint() - d.bdRead = false - return d.decodeTime(xtag) -} - -func (d *cborDecDriverBytes) decodeTime(xtag uint64) (t time.Time) { - switch xtag { - case 0: - var err error - t, err = time.Parse(time.RFC3339, stringView(bytesOKs(d.DecodeStringAsBytes()))) - halt.onerror(err) - case 1: - f1, f2 := math.Modf(d.DecodeFloat64()) - t = time.Unix(int64(f1), int64(f2*1e9)) - default: - halt.errorf("invalid tag for time.Time - expecting 0 or 1, got 0x%x", xtag) - } - t = t.UTC().Round(time.Microsecond) - return -} - -func (d *cborDecDriverBytes) preDecodeExt(checkTag bool, xtag uint64) (realxtag uint64, ok bool) { - if d.advanceNil() { - return - } - if d.bd>>5 != cborMajorTag { - halt.errorf("error reading tag; expected major type: %x, got: %x", cborMajorTag, d.bd>>5) - } - realxtag = d.decUint() - d.bdRead = false - if checkTag && xtag != realxtag { - halt.errorf("Wrong extension tag. Got %b. Expecting: %v", realxtag, xtag) - } - ok = true - return -} - -func (d *cborDecDriverBytes) DecodeRawExt(re *RawExt) { - if realxtag, ok := d.preDecodeExt(false, 0); ok { - re.Tag = realxtag - d.dec.decode(&re.Value) - d.bdRead = false - } -} - -func (d *cborDecDriverBytes) DecodeExt(rv interface{}, basetype reflect.Type, xtag uint64, ext Ext) { - if _, ok := d.preDecodeExt(true, xtag); ok { - if ext == SelfExt { - d.dec.decodeAs(rv, basetype, false) - } else { - d.dec.interfaceExtConvertAndDecode(rv, ext) - } - d.bdRead = false - } -} - -func (d *cborDecDriverBytes) decTagBigIntAsFloat(neg bool) (f float64) { - bs, _ := d.DecodeBytes() - bi := new(big.Int).SetBytes(bs) - if neg { - bi0 := bi - bi = new(big.Int).Sub(big.NewInt(-1), bi0) - } - f, _ = bi.Float64() - return -} - -func (d *cborDecDriverBytes) decTagBigFloatAsFloat(decimal bool) (f float64) { - if nn := d.r.readn1(); nn != 82 { - halt.errorf("(%d) decoding decimal/big.Float: expected 2 numbers", nn) - } - exp := d.DecodeInt64() - mant := d.DecodeInt64() - if decimal { - - rf := readFloatResult{exp: int8(exp)} - if mant >= 0 { - rf.mantissa = uint64(mant) - } else { - rf.neg = true - rf.mantissa = uint64(-mant) - } - f, _ = parseFloat64_reader(rf) - - } else { - - bfm := new(big.Float).SetPrec(64).SetInt64(mant) - bf := new(big.Float).SetPrec(64).SetMantExp(bfm, int(exp)) - f, _ = bf.Float64() - } - return -} - -func (d *cborDecDriverBytes) DecodeNaked() { - if !d.bdRead { - d.readNextBd() - } - - n := d.d.naked() - var decodeFurther bool - switch d.bd >> 5 { - case cborMajorUint: - if d.h.SignedInteger { - n.v = valueTypeInt - n.i = d.DecodeInt64() - } else { - n.v = valueTypeUint - n.u = d.DecodeUint64() - } - case cborMajorNegInt: - n.v = valueTypeInt - n.i = d.DecodeInt64() - case cborMajorBytes: - d.d.fauxUnionReadRawBytes(d, false, d.h.RawToString) - case cborMajorString: - n.v = valueTypeString - n.s = d.d.detach2Str(d.DecodeStringAsBytes()) - case cborMajorArray: - n.v = valueTypeArray - decodeFurther = true - case cborMajorMap: - n.v = valueTypeMap - decodeFurther = true - case cborMajorTag: - n.v = valueTypeExt - n.u = d.decUint() - d.bdRead = false - n.l = nil - xx := d.h.getExtForTag(n.u) - if xx == nil { - switch n.u { - case 0, 1: - n.v = valueTypeTime - n.t = d.decodeTime(n.u) - case 2: - n.f = d.decTagBigIntAsFloat(false) - n.v = valueTypeFloat - case 3: - n.f = d.decTagBigIntAsFloat(true) - n.v = valueTypeFloat - case 4: - n.f = d.decTagBigFloatAsFloat(true) - n.v = valueTypeFloat - case 5: - n.f = d.decTagBigFloatAsFloat(false) - n.v = valueTypeFloat - case 55799: - d.DecodeNaked() - default: - if d.h.SkipUnexpectedTags { - d.DecodeNaked() - } - - } - return - } - - case cborMajorSimpleOrFloat: - switch d.bd { - case cborBdNil, cborBdUndefined: - n.v = valueTypeNil - case cborBdFalse: - n.v = valueTypeBool - n.b = false - case cborBdTrue: - n.v = valueTypeBool - n.b = true - case cborBdFloat16, cborBdFloat32, cborBdFloat64: - n.v = valueTypeFloat - n.f = d.DecodeFloat64() - default: - halt.errorf("decodeNaked: Unrecognized d.bd: 0x%x", d.bd) - } - default: - halt.errorf("decodeNaked: Unrecognized d.bd: 0x%x", d.bd) - } - if !decodeFurther { - d.bdRead = false - } -} - -func (d *cborDecDriverBytes) uintBytes() (v []byte, ui uint64) { - - switch vv := d.bd & 0x1f; vv { - case 0x18: - v = d.r.readx(1) - ui = uint64(v[0]) - case 0x19: - v = d.r.readx(2) - ui = uint64(bigenstd.Uint16(v)) - case 0x1a: - v = d.r.readx(4) - ui = uint64(bigenstd.Uint32(v)) - case 0x1b: - v = d.r.readx(8) - ui = uint64(bigenstd.Uint64(v)) - default: - if vv > 0x1b { - halt.errorf("invalid descriptor decoding uint: %x/%s", d.bd, cbordesc(d.bd)) - } - ui = uint64(vv) - } - return -} - -func (d *cborDecDriverBytes) nextValueBytes() (v []byte) { - if !d.bdRead { - d.readNextBd() - } - d.r.startRecording() - d.nextValueBytesBdReadR() - v = d.r.stopRecording() - d.bdRead = false - return -} - -func (d *cborDecDriverBytes) nextValueBytesBdReadR() { - - var ui uint64 - - switch d.bd >> 5 { - case cborMajorUint, cborMajorNegInt: - d.uintBytes() - case cborMajorString, cborMajorBytes: - if d.bd == cborBdIndefiniteBytes || d.bd == cborBdIndefiniteString { - for { - d.readNextBd() - if d.bd == cborBdBreak { - break - } - _, ui = d.uintBytes() - d.r.skip(uint(ui)) - } - } else { - _, ui = d.uintBytes() - d.r.skip(uint(ui)) - } - case cborMajorArray: - if d.bd == cborBdIndefiniteArray { - for { - d.readNextBd() - if d.bd == cborBdBreak { - break - } - d.nextValueBytesBdReadR() - } - } else { - _, ui = d.uintBytes() - for i := uint64(0); i < ui; i++ { - d.readNextBd() - d.nextValueBytesBdReadR() - } - } - case cborMajorMap: - if d.bd == cborBdIndefiniteMap { - for { - d.readNextBd() - if d.bd == cborBdBreak { - break - } - d.nextValueBytesBdReadR() - d.readNextBd() - d.nextValueBytesBdReadR() - } - } else { - _, ui = d.uintBytes() - for i := uint64(0); i < ui; i++ { - d.readNextBd() - d.nextValueBytesBdReadR() - d.readNextBd() - d.nextValueBytesBdReadR() - } - } - case cborMajorTag: - d.uintBytes() - d.readNextBd() - d.nextValueBytesBdReadR() - case cborMajorSimpleOrFloat: - switch d.bd { - case cborBdNil, cborBdUndefined, cborBdFalse, cborBdTrue: - case cborBdFloat16: - d.r.skip(2) - case cborBdFloat32: - d.r.skip(4) - case cborBdFloat64: - d.r.skip(8) - default: - halt.errorf("nextValueBytes: Unrecognized d.bd: 0x%x", d.bd) - } - default: - halt.errorf("nextValueBytes: Unrecognized d.bd: 0x%x", d.bd) - } - return -} - -func (d *cborDecDriverBytes) reset() { - d.bdAndBdread.reset() - -} - -func (d *cborEncDriverBytes) init(hh Handle, shared *encoderBase, enc encoderI) (fp interface{}) { - callMake(&d.w) - d.h = hh.(*CborHandle) - d.e = shared - if shared.bytes { - fp = cborFpEncBytes - } else { - fp = cborFpEncIO - } - - d.init2(enc) - return -} - -func (e *cborEncDriverBytes) writeBytesAsis(b []byte) { e.w.writeb(b) } - -func (e *cborEncDriverBytes) writerEnd() { e.w.end() } - -func (e *cborEncDriverBytes) resetOutBytes(out *[]byte) { - e.w.resetBytes(*out, out) -} - -func (e *cborEncDriverBytes) resetOutIO(out io.Writer) { - e.w.resetIO(out, e.h.WriterBufferSize, &e.e.blist) -} - -func (d *cborDecDriverBytes) init(hh Handle, shared *decoderBase, dec decoderI) (fp interface{}) { - callMake(&d.r) - d.h = hh.(*CborHandle) - d.d = shared - if shared.bytes { - fp = cborFpDecBytes - } else { - fp = cborFpDecIO - } - - d.init2(dec) - return -} - -func (d *cborDecDriverBytes) NumBytesRead() int { - return int(d.r.numread()) -} - -func (d *cborDecDriverBytes) resetInBytes(in []byte) { - d.r.resetBytes(in) -} - -func (d *cborDecDriverBytes) resetInIO(r io.Reader) { - d.r.resetIO(r, d.h.ReaderBufferSize, d.h.MaxInitLen, &d.d.blist) -} - -func (d *cborDecDriverBytes) descBd() string { - return sprintf("%v (%s)", d.bd, cbordesc(d.bd)) -} - -func (d *cborDecDriverBytes) DecodeFloat32() (f float32) { - return float32(chkOvf.Float32V(d.DecodeFloat64())) -} - -func (d *cborEncDriverBytes) init2(enc encoderI) { - d.enc = enc -} - -func (d *cborDecDriverBytes) init2(dec decoderI) { - d.dec = dec - -} - -type helperEncDriverCborIO struct{} -type encFnCborIO struct { - i encFnInfo - fe func(*encoderCborIO, *encFnInfo, reflect.Value) -} -type encRtidFnCborIO struct { - rtid uintptr - fn *encFnCborIO -} -type encoderCborIO struct { - dh helperEncDriverCborIO - fp *fastpathEsCborIO - e cborEncDriverIO - encoderBase -} -type helperDecDriverCborIO struct{} -type decFnCborIO struct { - i decFnInfo - fd func(*decoderCborIO, *decFnInfo, reflect.Value) -} -type decRtidFnCborIO struct { - rtid uintptr - fn *decFnCborIO -} -type decoderCborIO struct { - dh helperDecDriverCborIO - fp *fastpathDsCborIO - d cborDecDriverIO - decoderBase -} -type cborEncDriverIO struct { - noBuiltInTypes - encDriverNoState - encDriverNoopContainerWriter - encDriverContainerNoTrackerT - - h *CborHandle - e *encoderBase - w bufioEncWriter - enc encoderI - - b [40]byte -} -type cborDecDriverIO struct { - decDriverNoopContainerReader - - noBuiltInTypes - - h *CborHandle - d *decoderBase - r ioDecReader - dec decoderI - bdAndBdread -} - -func (e *encoderCborIO) rawExt(_ *encFnInfo, rv reflect.Value) { - if re := rv2i(rv).(*RawExt); re == nil { - e.e.EncodeNil() - } else { - e.e.EncodeRawExt(re) - } -} - -func (e *encoderCborIO) ext(f *encFnInfo, rv reflect.Value) { - e.e.EncodeExt(rv2i(rv), f.ti.rt, f.xfTag, f.xfFn) -} - -func (e *encoderCborIO) selferMarshal(_ *encFnInfo, rv reflect.Value) { - rv2i(rv).(Selfer).CodecEncodeSelf(&Encoder{e}) -} - -func (e *encoderCborIO) binaryMarshal(_ *encFnInfo, rv reflect.Value) { - bs, fnerr := rv2i(rv).(encoding.BinaryMarshaler).MarshalBinary() - e.marshalRaw(bs, fnerr) -} - -func (e *encoderCborIO) textMarshal(_ *encFnInfo, rv reflect.Value) { - bs, fnerr := rv2i(rv).(encoding.TextMarshaler).MarshalText() - e.marshalUtf8(bs, fnerr) -} - -func (e *encoderCborIO) jsonMarshal(_ *encFnInfo, rv reflect.Value) { - bs, fnerr := rv2i(rv).(jsonMarshaler).MarshalJSON() - e.marshalAsis(bs, fnerr) -} - -func (e *encoderCborIO) raw(_ *encFnInfo, rv reflect.Value) { - e.rawBytes(rv2i(rv).(Raw)) -} - -func (e *encoderCborIO) encodeComplex64(v complex64) { - if imag(v) != 0 { - halt.errorf("cannot encode complex number: %v, with imaginary values: %v", any(v), any(imag(v))) - } - e.e.EncodeFloat32(real(v)) -} - -func (e *encoderCborIO) encodeComplex128(v complex128) { - if imag(v) != 0 { - halt.errorf("cannot encode complex number: %v, with imaginary values: %v", any(v), any(imag(v))) - } - e.e.EncodeFloat64(real(v)) -} - -func (e *encoderCborIO) kBool(_ *encFnInfo, rv reflect.Value) { - e.e.EncodeBool(rvGetBool(rv)) -} - -func (e *encoderCborIO) kTime(_ *encFnInfo, rv reflect.Value) { - e.e.EncodeTime(rvGetTime(rv)) -} - -func (e *encoderCborIO) kString(_ *encFnInfo, rv reflect.Value) { - e.e.EncodeString(rvGetString(rv)) -} - -func (e *encoderCborIO) kFloat32(_ *encFnInfo, rv reflect.Value) { - e.e.EncodeFloat32(rvGetFloat32(rv)) -} - -func (e *encoderCborIO) kFloat64(_ *encFnInfo, rv reflect.Value) { - e.e.EncodeFloat64(rvGetFloat64(rv)) -} - -func (e *encoderCborIO) kComplex64(_ *encFnInfo, rv reflect.Value) { - e.encodeComplex64(rvGetComplex64(rv)) -} - -func (e *encoderCborIO) kComplex128(_ *encFnInfo, rv reflect.Value) { - e.encodeComplex128(rvGetComplex128(rv)) -} - -func (e *encoderCborIO) kInt(_ *encFnInfo, rv reflect.Value) { - e.e.EncodeInt(int64(rvGetInt(rv))) -} - -func (e *encoderCborIO) kInt8(_ *encFnInfo, rv reflect.Value) { - e.e.EncodeInt(int64(rvGetInt8(rv))) -} - -func (e *encoderCborIO) kInt16(_ *encFnInfo, rv reflect.Value) { - e.e.EncodeInt(int64(rvGetInt16(rv))) -} - -func (e *encoderCborIO) kInt32(_ *encFnInfo, rv reflect.Value) { - e.e.EncodeInt(int64(rvGetInt32(rv))) -} - -func (e *encoderCborIO) kInt64(_ *encFnInfo, rv reflect.Value) { - e.e.EncodeInt(int64(rvGetInt64(rv))) -} - -func (e *encoderCborIO) kUint(_ *encFnInfo, rv reflect.Value) { - e.e.EncodeUint(uint64(rvGetUint(rv))) -} - -func (e *encoderCborIO) kUint8(_ *encFnInfo, rv reflect.Value) { - e.e.EncodeUint(uint64(rvGetUint8(rv))) -} - -func (e *encoderCborIO) kUint16(_ *encFnInfo, rv reflect.Value) { - e.e.EncodeUint(uint64(rvGetUint16(rv))) -} - -func (e *encoderCborIO) kUint32(_ *encFnInfo, rv reflect.Value) { - e.e.EncodeUint(uint64(rvGetUint32(rv))) -} - -func (e *encoderCborIO) kUint64(_ *encFnInfo, rv reflect.Value) { - e.e.EncodeUint(uint64(rvGetUint64(rv))) -} - -func (e *encoderCborIO) kUintptr(_ *encFnInfo, rv reflect.Value) { - e.e.EncodeUint(uint64(rvGetUintptr(rv))) -} - -func (e *encoderCborIO) kSeqFn(rt reflect.Type) (fn *encFnCborIO) { - - if rt = baseRT(rt); rt.Kind() != reflect.Interface { - fn = e.fn(rt) - } - return -} - -func (e *encoderCborIO) kArrayWMbs(rv reflect.Value, ti *typeInfo, isSlice bool) { - var l int - if isSlice { - l = rvLenSlice(rv) - } else { - l = rv.Len() - } - if l == 0 { - e.e.WriteMapEmpty() - return - } - e.haltOnMbsOddLen(l) - e.mapStart(l >> 1) - - var fn *encFnCborIO - builtin := ti.tielem.flagEncBuiltin - if !builtin { - fn = e.kSeqFn(ti.elem) - } - - j := 0 - e.c = containerMapKey - e.e.WriteMapElemKey(true) - for { - rvv := rvArrayIndex(rv, j, ti, isSlice) - if builtin { - e.encodeIB(rv2i(baseRVRV(rvv))) - } else { - e.encodeValue(rvv, fn) - } - j++ - if j == l { - break - } - if j&1 == 0 { - e.c = containerMapKey - e.e.WriteMapElemKey(false) - } else { - e.mapElemValue() - } - } - e.c = 0 - e.e.WriteMapEnd() - -} - -func (e *encoderCborIO) kArrayW(rv reflect.Value, ti *typeInfo, isSlice bool) { - var l int - if isSlice { - l = rvLenSlice(rv) - } else { - l = rv.Len() - } - if l <= 0 { - e.e.WriteArrayEmpty() - return - } - e.arrayStart(l) - - var fn *encFnCborIO - if !ti.tielem.flagEncBuiltin { - fn = e.kSeqFn(ti.elem) - } - - j := 0 - e.c = containerArrayElem - e.e.WriteArrayElem(true) - builtin := ti.tielem.flagEncBuiltin - for { - rvv := rvArrayIndex(rv, j, ti, isSlice) - if builtin { - e.encodeIB(rv2i(baseRVRV(rvv))) - } else { - e.encodeValue(rvv, fn) - } - j++ - if j == l { - break - } - e.c = containerArrayElem - e.e.WriteArrayElem(false) - } - - e.c = 0 - e.e.WriteArrayEnd() -} - -func (e *encoderCborIO) kChan(f *encFnInfo, rv reflect.Value) { - if f.ti.chandir&uint8(reflect.RecvDir) == 0 { - halt.errorStr("send-only channel cannot be encoded") - } - if !f.ti.mbs && uint8TypId == rt2id(f.ti.elem) { - e.kSliceBytesChan(rv) - return - } - rtslice := reflect.SliceOf(f.ti.elem) - rv = chanToSlice(rv, rtslice, e.h.ChanRecvTimeout) - ti := e.h.getTypeInfo(rt2id(rtslice), rtslice) - if f.ti.mbs { - e.kArrayWMbs(rv, ti, true) - } else { - e.kArrayW(rv, ti, true) - } -} - -func (e *encoderCborIO) kSlice(f *encFnInfo, rv reflect.Value) { - if f.ti.mbs { - e.kArrayWMbs(rv, f.ti, true) - } else if f.ti.rtid == uint8SliceTypId || uint8TypId == rt2id(f.ti.elem) { - - e.e.EncodeBytes(rvGetBytes(rv)) - } else { - e.kArrayW(rv, f.ti, true) - } -} - -func (e *encoderCborIO) kArray(f *encFnInfo, rv reflect.Value) { - if f.ti.mbs { - e.kArrayWMbs(rv, f.ti, false) - } else if handleBytesWithinKArray && uint8TypId == rt2id(f.ti.elem) { - e.e.EncodeStringBytesRaw(rvGetArrayBytes(rv, nil)) - } else { - e.kArrayW(rv, f.ti, false) - } -} - -func (e *encoderCborIO) kSliceBytesChan(rv reflect.Value) { - - bs0 := e.blist.peek(32, true) - bs := bs0 - - irv := rv2i(rv) - ch, ok := irv.(<-chan byte) - if !ok { - ch = irv.(chan byte) - } - -L1: - switch timeout := e.h.ChanRecvTimeout; { - case timeout == 0: - for { - select { - case b := <-ch: - bs = append(bs, b) - default: - break L1 - } - } - case timeout > 0: - tt := time.NewTimer(timeout) - for { - select { - case b := <-ch: - bs = append(bs, b) - case <-tt.C: - - break L1 - } - } - default: - for b := range ch { - bs = append(bs, b) - } - } - - e.e.EncodeBytes(bs) - e.blist.put(bs) - if !byteSliceSameData(bs0, bs) { - e.blist.put(bs0) - } -} - -func (e *encoderCborIO) kStructFieldKey(keyType valueType, encName string) { - - if keyType == valueTypeString { - e.e.EncodeString(encName) - } else if keyType == valueTypeInt { - e.e.EncodeInt(must.Int(strconv.ParseInt(encName, 10, 64))) - } else if keyType == valueTypeUint { - e.e.EncodeUint(must.Uint(strconv.ParseUint(encName, 10, 64))) - } else if keyType == valueTypeFloat { - e.e.EncodeFloat64(must.Float(strconv.ParseFloat(encName, 64))) - } else { - halt.errorStr2("invalid struct key type: ", keyType.String()) - } - -} - -func (e *encoderCborIO) kStructSimple(f *encFnInfo, rv reflect.Value) { - _ = e.e - tisfi := f.ti.sfi.source() - - chkCirRef := e.h.CheckCircularRef - var si *structFieldInfo - var j int - - if f.ti.toArray || e.h.StructToArray { - if len(tisfi) == 0 { - e.e.WriteArrayEmpty() - return - } - e.arrayStart(len(tisfi)) - for j, si = range tisfi { - e.c = containerArrayElem - e.e.WriteArrayElem(j == 0) - if si.encBuiltin { - e.encodeIB(rv2i(si.fieldNoAlloc(rv, true))) - } else { - e.encodeValue(si.fieldNoAlloc(rv, !chkCirRef), nil) - } - } - e.c = 0 - e.e.WriteArrayEnd() - } else { - if len(tisfi) == 0 { - e.e.WriteMapEmpty() - return - } - if e.h.Canonical { - tisfi = f.ti.sfi.sorted() - } - e.mapStart(len(tisfi)) - for j, si = range tisfi { - e.c = containerMapKey - e.e.WriteMapElemKey(j == 0) - e.e.EncodeStringNoEscape4Json(si.encName) - e.mapElemValue() - if si.encBuiltin { - e.encodeIB(rv2i(si.fieldNoAlloc(rv, true))) - } else { - e.encodeValue(si.fieldNoAlloc(rv, !chkCirRef), nil) - } - } - e.c = 0 - e.e.WriteMapEnd() - } -} - -func (e *encoderCborIO) kStruct(f *encFnInfo, rv reflect.Value) { - _ = e.e - ti := f.ti - toMap := !(ti.toArray || e.h.StructToArray) - var mf map[string]interface{} - if ti.flagMissingFielder { - toMap = true - mf = rv2i(rv).(MissingFielder).CodecMissingFields() - } else if ti.flagMissingFielderPtr { - toMap = true - if rv.CanAddr() { - mf = rv2i(rvAddr(rv, ti.ptr)).(MissingFielder).CodecMissingFields() - } else { - mf = rv2i(e.addrRV(rv, ti.rt, ti.ptr)).(MissingFielder).CodecMissingFields() - } - } - newlen := len(mf) - tisfi := ti.sfi.source() - newlen += len(tisfi) - - var fkvs = e.slist.get(newlen)[:newlen] - - recur := e.h.RecursiveEmptyCheck - chkCirRef := e.h.CheckCircularRef - - var xlen int - - var kv sfiRv - var j int - var sf encStructFieldObj - if toMap { - newlen = 0 - if e.h.Canonical { - tisfi = f.ti.sfi.sorted() - } - for _, si := range tisfi { - - if si.omitEmpty { - kv.r = si.fieldNoAlloc(rv, false) - if isEmptyValue(kv.r, e.h.TypeInfos, recur) { - continue - } - } else { - kv.r = si.fieldNoAlloc(rv, si.encBuiltin || !chkCirRef) - } - kv.v = si - fkvs[newlen] = kv - newlen++ - } - - var mf2s []stringIntf - if len(mf) != 0 { - mf2s = make([]stringIntf, 0, len(mf)) - for k, v := range mf { - if k == "" { - continue - } - if ti.infoFieldOmitempty && isEmptyValue(reflect.ValueOf(v), e.h.TypeInfos, recur) { - continue - } - mf2s = append(mf2s, stringIntf{k, v}) - } - } - - xlen = newlen + len(mf2s) - if xlen == 0 { - e.e.WriteMapEmpty() - goto END - } - - e.mapStart(xlen) - - if len(mf2s) != 0 && e.h.Canonical { - mf2w := make([]encStructFieldObj, newlen+len(mf2s)) - for j = 0; j < newlen; j++ { - kv = fkvs[j] - mf2w[j] = encStructFieldObj{kv.v.encName, kv.r, nil, true, - !kv.v.encNameEscape4Json, kv.v.encBuiltin} - } - for _, v := range mf2s { - mf2w[j] = encStructFieldObj{v.v, reflect.Value{}, v.i, false, false, false} - j++ - } - sort.Sort((encStructFieldObjSlice)(mf2w)) - for j, sf = range mf2w { - e.c = containerMapKey - e.e.WriteMapElemKey(j == 0) - if ti.keyType == valueTypeString && sf.noEsc4json { - e.e.EncodeStringNoEscape4Json(sf.key) - } else { - e.kStructFieldKey(ti.keyType, sf.key) - } - e.mapElemValue() - if sf.isRv { - if sf.builtin { - e.encodeIB(rv2i(baseRVRV(sf.rv))) - } else { - e.encodeValue(sf.rv, nil) - } - } else { - if !e.encodeBuiltin(sf.intf) { - e.encodeR(reflect.ValueOf(sf.intf)) - } - - } - } - } else { - keytyp := ti.keyType - for j = 0; j < newlen; j++ { - kv = fkvs[j] - e.c = containerMapKey - e.e.WriteMapElemKey(j == 0) - if ti.keyType == valueTypeString && !kv.v.encNameEscape4Json { - e.e.EncodeStringNoEscape4Json(kv.v.encName) - } else { - e.kStructFieldKey(keytyp, kv.v.encName) - } - e.mapElemValue() - if kv.v.encBuiltin { - e.encodeIB(rv2i(baseRVRV(kv.r))) - } else { - e.encodeValue(kv.r, nil) - } - } - for _, v := range mf2s { - e.c = containerMapKey - e.e.WriteMapElemKey(j == 0) - e.kStructFieldKey(keytyp, v.v) - e.mapElemValue() - if !e.encodeBuiltin(v.i) { - e.encodeR(reflect.ValueOf(v.i)) - } - - j++ - } - } - - e.c = 0 - e.e.WriteMapEnd() - } else { - newlen = len(tisfi) - for i, si := range tisfi { - - if si.omitEmpty { - - kv.r = si.fieldNoAlloc(rv, false) - if isEmptyContainerValue(kv.r, e.h.TypeInfos, recur) { - kv.r = reflect.Value{} - } - } else { - kv.r = si.fieldNoAlloc(rv, si.encBuiltin || !chkCirRef) - } - kv.v = si - fkvs[i] = kv - } - - if newlen == 0 { - e.e.WriteArrayEmpty() - goto END - } - - e.arrayStart(newlen) - for j = 0; j < newlen; j++ { - e.c = containerArrayElem - e.e.WriteArrayElem(j == 0) - kv = fkvs[j] - if !kv.r.IsValid() { - e.e.EncodeNil() - } else if kv.v.encBuiltin { - e.encodeIB(rv2i(baseRVRV(kv.r))) - } else { - e.encodeValue(kv.r, nil) - } - } - e.c = 0 - e.e.WriteArrayEnd() - } - -END: - - e.slist.put(fkvs) -} - -func (e *encoderCborIO) kMap(f *encFnInfo, rv reflect.Value) { - _ = e.e - l := rvLenMap(rv) - if l == 0 { - e.e.WriteMapEmpty() - return - } - e.mapStart(l) - - var keyFn, valFn *encFnCborIO - - ktypeKind := reflect.Kind(f.ti.keykind) - vtypeKind := reflect.Kind(f.ti.elemkind) - - rtval := f.ti.elem - rtvalkind := vtypeKind - for rtvalkind == reflect.Ptr { - rtval = rtval.Elem() - rtvalkind = rtval.Kind() - } - if rtvalkind != reflect.Interface { - valFn = e.fn(rtval) - } - - var rvv = mapAddrLoopvarRV(f.ti.elem, vtypeKind) - - rtkey := f.ti.key - var keyTypeIsString = stringTypId == rt2id(rtkey) - if keyTypeIsString { - keyFn = e.fn(rtkey) - } else { - for rtkey.Kind() == reflect.Ptr { - rtkey = rtkey.Elem() - } - if rtkey.Kind() != reflect.Interface { - keyFn = e.fn(rtkey) - } - } - - if e.h.Canonical { - e.kMapCanonical(f.ti, rv, rvv, keyFn, valFn) - e.c = 0 - e.e.WriteMapEnd() - return - } - - var rvk = mapAddrLoopvarRV(f.ti.key, ktypeKind) - - var it mapIter - mapRange(&it, rv, rvk, rvv, true) - - kbuiltin := f.ti.tikey.flagEncBuiltin - vbuiltin := f.ti.tielem.flagEncBuiltin - for j := 0; it.Next(); j++ { - rv = it.Key() - e.c = containerMapKey - e.e.WriteMapElemKey(j == 0) - if keyTypeIsString { - e.e.EncodeString(rvGetString(rv)) - } else if kbuiltin { - e.encodeIB(rv2i(baseRVRV(rv))) - } else { - e.encodeValue(rv, keyFn) - } - e.mapElemValue() - rv = it.Value() - if vbuiltin { - e.encodeIB(rv2i(baseRVRV(rv))) - } else { - e.encodeValue(it.Value(), valFn) - } - } - it.Done() - - e.c = 0 - e.e.WriteMapEnd() -} - -func (e *encoderCborIO) kMapCanonical(ti *typeInfo, rv, rvv reflect.Value, keyFn, valFn *encFnCborIO) { - _ = e.e - - rtkey := ti.key - rtkeydecl := rtkey.PkgPath() == "" && rtkey.Name() != "" - - mks := rv.MapKeys() - rtkeyKind := rtkey.Kind() - mparams := getMapReqParams(ti) - - switch rtkeyKind { - case reflect.Bool: - - if len(mks) == 2 && mks[0].Bool() { - mks[0], mks[1] = mks[1], mks[0] - } - for i := range mks { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - if rtkeydecl { - e.e.EncodeBool(mks[i].Bool()) - } else { - e.encodeValueNonNil(mks[i], keyFn) - } - e.mapElemValue() - e.encodeValue(mapGet(rv, mks[i], rvv, mparams), valFn) - } - case reflect.String: - mksv := make([]orderedRv[string], len(mks)) - for i, k := range mks { - v := &mksv[i] - v.r = k - v.v = rvGetString(k) - } - slices.SortFunc(mksv, cmpOrderedRv) - for i := range mksv { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - if rtkeydecl { - e.e.EncodeString(mksv[i].v) - } else { - e.encodeValueNonNil(mksv[i].r, keyFn) - } - e.mapElemValue() - e.encodeValue(mapGet(rv, mksv[i].r, rvv, mparams), valFn) - } - case reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64, reflect.Uint, reflect.Uintptr: - mksv := make([]orderedRv[uint64], len(mks)) - for i, k := range mks { - v := &mksv[i] - v.r = k - v.v = k.Uint() - } - slices.SortFunc(mksv, cmpOrderedRv) - for i := range mksv { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - if rtkeydecl { - e.e.EncodeUint(mksv[i].v) - } else { - e.encodeValueNonNil(mksv[i].r, keyFn) - } - e.mapElemValue() - e.encodeValue(mapGet(rv, mksv[i].r, rvv, mparams), valFn) - } - case reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64, reflect.Int: - mksv := make([]orderedRv[int64], len(mks)) - for i, k := range mks { - v := &mksv[i] - v.r = k - v.v = k.Int() - } - slices.SortFunc(mksv, cmpOrderedRv) - for i := range mksv { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - if rtkeydecl { - e.e.EncodeInt(mksv[i].v) - } else { - e.encodeValueNonNil(mksv[i].r, keyFn) - } - e.mapElemValue() - e.encodeValue(mapGet(rv, mksv[i].r, rvv, mparams), valFn) - } - case reflect.Float32: - mksv := make([]orderedRv[float64], len(mks)) - for i, k := range mks { - v := &mksv[i] - v.r = k - v.v = k.Float() - } - slices.SortFunc(mksv, cmpOrderedRv) - for i := range mksv { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - if rtkeydecl { - e.e.EncodeFloat32(float32(mksv[i].v)) - } else { - e.encodeValueNonNil(mksv[i].r, keyFn) - } - e.mapElemValue() - e.encodeValue(mapGet(rv, mksv[i].r, rvv, mparams), valFn) - } - case reflect.Float64: - mksv := make([]orderedRv[float64], len(mks)) - for i, k := range mks { - v := &mksv[i] - v.r = k - v.v = k.Float() - } - slices.SortFunc(mksv, cmpOrderedRv) - for i := range mksv { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - if rtkeydecl { - e.e.EncodeFloat64(mksv[i].v) - } else { - e.encodeValueNonNil(mksv[i].r, keyFn) - } - e.mapElemValue() - e.encodeValue(mapGet(rv, mksv[i].r, rvv, mparams), valFn) - } - default: - if rtkey == timeTyp { - mksv := make([]timeRv, len(mks)) - for i, k := range mks { - v := &mksv[i] - v.r = k - v.v = rv2i(k).(time.Time) - } - slices.SortFunc(mksv, cmpTimeRv) - for i := range mksv { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeTime(mksv[i].v) - e.mapElemValue() - e.encodeValue(mapGet(rv, mksv[i].r, rvv, mparams), valFn) - } - break - } - - bs0 := e.blist.get(len(mks) * 16) - mksv := bs0 - mksbv := make([]bytesRv, len(mks)) - - sideEncode(e.hh, &e.h.sideEncPool, func(se encoderI) { - se.ResetBytes(&mksv) - for i, k := range mks { - v := &mksbv[i] - l := len(mksv) - se.setContainerState(containerMapKey) - se.encodeR(baseRVRV(k)) - se.atEndOfEncode() - se.writerEnd() - v.r = k - v.v = mksv[l:] - } - }) - - slices.SortFunc(mksbv, cmpBytesRv) - for j := range mksbv { - e.c = containerMapKey - e.e.WriteMapElemKey(j == 0) - e.e.writeBytesAsis(mksbv[j].v) - e.mapElemValue() - e.encodeValue(mapGet(rv, mksbv[j].r, rvv, mparams), valFn) - } - e.blist.put(mksv) - if !byteSliceSameData(bs0, mksv) { - e.blist.put(bs0) - } - } -} - -func (e *encoderCborIO) init(h Handle) { - initHandle(h) - callMake(&e.e) - e.hh = h - e.h = h.getBasicHandle() - - e.err = errEncoderNotInitialized - - e.fp = e.e.init(h, &e.encoderBase, e).(*fastpathEsCborIO) - - if e.bytes { - e.rtidFn = &e.h.rtidFnsEncBytes - e.rtidFnNoExt = &e.h.rtidFnsEncNoExtBytes - } else { - e.rtidFn = &e.h.rtidFnsEncIO - e.rtidFnNoExt = &e.h.rtidFnsEncNoExtIO - } - - e.reset() -} - -func (e *encoderCborIO) reset() { - e.e.reset() - if e.ci != nil { - e.ci = e.ci[:0] - } - e.c = 0 - e.calls = 0 - e.seq = 0 - e.err = nil -} - -func (e *encoderCborIO) Encode(v interface{}) (err error) { - - defer panicValToErr(e, callRecoverSentinel, &e.err, &err, debugging) - e.mustEncode(v) - return -} - -func (e *encoderCborIO) MustEncode(v interface{}) { - defer panicValToErr(e, callRecoverSentinel, &e.err, nil, true) - e.mustEncode(v) - return -} - -func (e *encoderCborIO) mustEncode(v interface{}) { - halt.onerror(e.err) - if e.hh == nil { - halt.onerror(errNoFormatHandle) - } - - e.calls++ - if !e.encodeBuiltin(v) { - e.encodeR(reflect.ValueOf(v)) - } - - e.calls-- - if e.calls == 0 { - e.e.atEndOfEncode() - e.e.writerEnd() - } -} - -func (e *encoderCborIO) encodeI(iv interface{}) { - if !e.encodeBuiltin(iv) { - e.encodeR(reflect.ValueOf(iv)) - } -} - -func (e *encoderCborIO) encodeIB(iv interface{}) { - if !e.encodeBuiltin(iv) { - - halt.errorStr("[should not happen] invalid type passed to encodeBuiltin") - } -} - -func (e *encoderCborIO) encodeR(base reflect.Value) { - e.encodeValue(base, nil) -} - -func (e *encoderCborIO) encodeBuiltin(iv interface{}) (ok bool) { - ok = true - switch v := iv.(type) { - case nil: - e.e.EncodeNil() - - case Raw: - e.rawBytes(v) - case string: - e.e.EncodeString(v) - case bool: - e.e.EncodeBool(v) - case int: - e.e.EncodeInt(int64(v)) - case int8: - e.e.EncodeInt(int64(v)) - case int16: - e.e.EncodeInt(int64(v)) - case int32: - e.e.EncodeInt(int64(v)) - case int64: - e.e.EncodeInt(v) - case uint: - e.e.EncodeUint(uint64(v)) - case uint8: - e.e.EncodeUint(uint64(v)) - case uint16: - e.e.EncodeUint(uint64(v)) - case uint32: - e.e.EncodeUint(uint64(v)) - case uint64: - e.e.EncodeUint(v) - case uintptr: - e.e.EncodeUint(uint64(v)) - case float32: - e.e.EncodeFloat32(v) - case float64: - e.e.EncodeFloat64(v) - case complex64: - e.encodeComplex64(v) - case complex128: - e.encodeComplex128(v) - case time.Time: - e.e.EncodeTime(v) - case []byte: - e.e.EncodeBytes(v) - default: - - ok = !skipFastpathTypeSwitchInDirectCall && e.dh.fastpathEncodeTypeSwitch(iv, e) - } - return -} - -func (e *encoderCborIO) encodeValue(rv reflect.Value, fn *encFnCborIO) { - - var ciPushes int - - var rvp reflect.Value - var rvpValid bool - -RV: - switch rv.Kind() { - case reflect.Ptr: - if rvIsNil(rv) { - e.e.EncodeNil() - goto END - } - rvpValid = true - rvp = rv - rv = rv.Elem() - - if e.h.CheckCircularRef && e.ci.canPushElemKind(rv.Kind()) { - e.ci.push(rv2i(rvp)) - ciPushes++ - } - goto RV - case reflect.Interface: - if rvIsNil(rv) { - e.e.EncodeNil() - goto END - } - rvpValid = false - rvp = reflect.Value{} - rv = rv.Elem() - fn = nil - goto RV - case reflect.Map: - if rvIsNil(rv) { - if e.h.NilCollectionToZeroLength { - e.e.WriteMapEmpty() - } else { - e.e.EncodeNil() - } - goto END - } - case reflect.Slice, reflect.Chan: - if rvIsNil(rv) { - if e.h.NilCollectionToZeroLength { - e.e.WriteArrayEmpty() - } else { - e.e.EncodeNil() - } - goto END - } - case reflect.Invalid, reflect.Func: - e.e.EncodeNil() - goto END - } - - if fn == nil { - fn = e.fn(rv.Type()) - } - - if !fn.i.addrE { - - } else if rvpValid { - rv = rvp - } else if rv.CanAddr() { - rv = rvAddr(rv, fn.i.ti.ptr) - } else { - rv = e.addrRV(rv, fn.i.ti.rt, fn.i.ti.ptr) - } - fn.fe(e, &fn.i, rv) - -END: - if ciPushes > 0 { - e.ci.pop(ciPushes) - } -} - -func (e *encoderCborIO) encodeValueNonNil(rv reflect.Value, fn *encFnCborIO) { - - if fn.i.addrE { - if rv.CanAddr() { - rv = rvAddr(rv, fn.i.ti.ptr) - } else { - rv = e.addrRV(rv, fn.i.ti.rt, fn.i.ti.ptr) - } - } - fn.fe(e, &fn.i, rv) -} - -func (e *encoderCborIO) encodeAs(v interface{}, t reflect.Type, ext bool) { - if ext { - e.encodeValue(baseRV(v), e.fn(t)) - } else { - e.encodeValue(baseRV(v), e.fnNoExt(t)) - } -} - -func (e *encoderCborIO) marshalUtf8(bs []byte, fnerr error) { - halt.onerror(fnerr) - if bs == nil { - e.e.EncodeNil() - } else { - e.e.EncodeString(stringView(bs)) - } -} - -func (e *encoderCborIO) marshalAsis(bs []byte, fnerr error) { - halt.onerror(fnerr) - if bs == nil { - e.e.EncodeNil() - } else { - e.e.writeBytesAsis(bs) - } -} - -func (e *encoderCborIO) marshalRaw(bs []byte, fnerr error) { - halt.onerror(fnerr) - e.e.EncodeBytes(bs) -} - -func (e *encoderCborIO) rawBytes(vv Raw) { - v := []byte(vv) - if !e.h.Raw { - halt.errorBytes("Raw values cannot be encoded: ", v) - } - e.e.writeBytesAsis(v) -} - -func (e *encoderCborIO) fn(t reflect.Type) *encFnCborIO { - return e.dh.encFnViaBH(t, e.rtidFn, e.h, e.fp, false) -} - -func (e *encoderCborIO) fnNoExt(t reflect.Type) *encFnCborIO { - return e.dh.encFnViaBH(t, e.rtidFnNoExt, e.h, e.fp, true) -} - -func (e *encoderCborIO) mapStart(length int) { - e.e.WriteMapStart(length) - e.c = containerMapStart -} - -func (e *encoderCborIO) mapElemValue() { - e.e.WriteMapElemValue() - e.c = containerMapValue -} - -func (e *encoderCborIO) arrayStart(length int) { - e.e.WriteArrayStart(length) - e.c = containerArrayStart -} - -func (e *encoderCborIO) writerEnd() { - e.e.writerEnd() -} - -func (e *encoderCborIO) atEndOfEncode() { - e.e.atEndOfEncode() -} - -func (e *encoderCborIO) Reset(w io.Writer) { - if e.bytes { - halt.onerror(errEncNoResetBytesWithWriter) - } - e.reset() - if w == nil { - w = io.Discard - } - e.e.resetOutIO(w) -} - -func (e *encoderCborIO) ResetBytes(out *[]byte) { - if !e.bytes { - halt.onerror(errEncNoResetWriterWithBytes) - } - e.resetBytes(out) -} - -func (e *encoderCborIO) resetBytes(out *[]byte) { - e.reset() - if out == nil { - out = &bytesEncAppenderDefOut - } - e.e.resetOutBytes(out) -} - -func (helperEncDriverCborIO) newEncoderBytes(out *[]byte, h Handle) *encoderCborIO { - var c1 encoderCborIO - c1.bytes = true - c1.init(h) - c1.ResetBytes(out) - return &c1 -} - -func (helperEncDriverCborIO) newEncoderIO(out io.Writer, h Handle) *encoderCborIO { - var c1 encoderCborIO - c1.bytes = false - c1.init(h) - c1.Reset(out) - return &c1 -} - -func (helperEncDriverCborIO) encFnloadFastpathUnderlying(ti *typeInfo, fp *fastpathEsCborIO) (f *fastpathECborIO, u reflect.Type) { - rtid := rt2id(ti.fastpathUnderlying) - idx, ok := fastpathAvIndex(rtid) - if !ok { - return - } - f = &fp[idx] - if uint8(reflect.Array) == ti.kind { - u = reflect.ArrayOf(ti.rt.Len(), ti.elem) - } else { - u = f.rt - } - return -} - -func (helperEncDriverCborIO) encFindRtidFn(s []encRtidFnCborIO, rtid uintptr) (i uint, fn *encFnCborIO) { - - var h uint - var j = uint(len(s)) -LOOP: - if i < j { - h = (i + j) >> 1 - if s[h].rtid < rtid { - i = h + 1 - } else { - j = h - } - goto LOOP - } - if i < uint(len(s)) && s[i].rtid == rtid { - fn = s[i].fn - } - return -} - -func (helperEncDriverCborIO) encFromRtidFnSlice(fns *atomicRtidFnSlice) (s []encRtidFnCborIO) { - if v := fns.load(); v != nil { - s = *(lowLevelToPtr[[]encRtidFnCborIO](v)) - } - return -} - -func (dh helperEncDriverCborIO) encFnViaBH(rt reflect.Type, fns *atomicRtidFnSlice, - x *BasicHandle, fp *fastpathEsCborIO, checkExt bool) (fn *encFnCborIO) { - return dh.encFnVia(rt, fns, x.typeInfos(), &x.mu, x.extHandle, fp, - checkExt, x.CheckCircularRef, x.timeBuiltin, x.binaryHandle, x.jsonHandle) -} - -func (dh helperEncDriverCborIO) encFnVia(rt reflect.Type, fns *atomicRtidFnSlice, - tinfos *TypeInfos, mu *sync.Mutex, exth extHandle, fp *fastpathEsCborIO, - checkExt, checkCircularRef, timeBuiltin, binaryEncoding, json bool) (fn *encFnCborIO) { - rtid := rt2id(rt) - var sp []encRtidFnCborIO = dh.encFromRtidFnSlice(fns) - if sp != nil { - _, fn = dh.encFindRtidFn(sp, rtid) - } - if fn == nil { - fn = dh.encFnViaLoader(rt, rtid, fns, tinfos, mu, exth, fp, checkExt, checkCircularRef, timeBuiltin, binaryEncoding, json) - } - return -} - -func (dh helperEncDriverCborIO) encFnViaLoader(rt reflect.Type, rtid uintptr, fns *atomicRtidFnSlice, - tinfos *TypeInfos, mu *sync.Mutex, exth extHandle, fp *fastpathEsCborIO, - checkExt, checkCircularRef, timeBuiltin, binaryEncoding, json bool) (fn *encFnCborIO) { - - fn = dh.encFnLoad(rt, rtid, tinfos, exth, fp, checkExt, checkCircularRef, timeBuiltin, binaryEncoding, json) - var sp []encRtidFnCborIO - mu.Lock() - sp = dh.encFromRtidFnSlice(fns) - - if sp == nil { - sp = []encRtidFnCborIO{{rtid, fn}} - fns.store(ptrToLowLevel(&sp)) - } else { - idx, fn2 := dh.encFindRtidFn(sp, rtid) - if fn2 == nil { - sp2 := make([]encRtidFnCborIO, len(sp)+1) - copy(sp2[idx+1:], sp[idx:]) - copy(sp2, sp[:idx]) - sp2[idx] = encRtidFnCborIO{rtid, fn} - fns.store(ptrToLowLevel(&sp2)) - } - } - mu.Unlock() - return -} - -func (dh helperEncDriverCborIO) encFnLoad(rt reflect.Type, rtid uintptr, tinfos *TypeInfos, - exth extHandle, fp *fastpathEsCborIO, - checkExt, checkCircularRef, timeBuiltin, binaryEncoding, json bool) (fn *encFnCborIO) { - fn = new(encFnCborIO) - fi := &(fn.i) - ti := tinfos.get(rtid, rt) - fi.ti = ti - rk := reflect.Kind(ti.kind) - - if rtid == timeTypId && timeBuiltin { - fn.fe = (*encoderCborIO).kTime - } else if rtid == rawTypId { - fn.fe = (*encoderCborIO).raw - } else if rtid == rawExtTypId { - fn.fe = (*encoderCborIO).rawExt - fi.addrE = true - } else if xfFn := exth.getExt(rtid, checkExt); xfFn != nil { - fi.xfTag, fi.xfFn = xfFn.tag, xfFn.ext - fn.fe = (*encoderCborIO).ext - if rk == reflect.Struct || rk == reflect.Array { - fi.addrE = true - } - } else if ti.flagSelfer || ti.flagSelferPtr { - fn.fe = (*encoderCborIO).selferMarshal - fi.addrE = ti.flagSelferPtr - } else if supportMarshalInterfaces && binaryEncoding && - (ti.flagBinaryMarshaler || ti.flagBinaryMarshalerPtr) && - (ti.flagBinaryUnmarshaler || ti.flagBinaryUnmarshalerPtr) { - fn.fe = (*encoderCborIO).binaryMarshal - fi.addrE = ti.flagBinaryMarshalerPtr - } else if supportMarshalInterfaces && !binaryEncoding && json && - (ti.flagJsonMarshaler || ti.flagJsonMarshalerPtr) && - (ti.flagJsonUnmarshaler || ti.flagJsonUnmarshalerPtr) { - - fn.fe = (*encoderCborIO).jsonMarshal - fi.addrE = ti.flagJsonMarshalerPtr - } else if supportMarshalInterfaces && !binaryEncoding && - (ti.flagTextMarshaler || ti.flagTextMarshalerPtr) && - (ti.flagTextUnmarshaler || ti.flagTextUnmarshalerPtr) { - fn.fe = (*encoderCborIO).textMarshal - fi.addrE = ti.flagTextMarshalerPtr - } else { - if fastpathEnabled && (rk == reflect.Map || rk == reflect.Slice || rk == reflect.Array) { - - var rtid2 uintptr - if !ti.flagHasPkgPath { - rtid2 = rtid - if rk == reflect.Array { - rtid2 = rt2id(ti.key) - } - if idx, ok := fastpathAvIndex(rtid2); ok { - fn.fe = fp[idx].encfn - } - } else { - - xfe, xrt := dh.encFnloadFastpathUnderlying(ti, fp) - if xfe != nil { - xfnf := xfe.encfn - fn.fe = func(e *encoderCborIO, xf *encFnInfo, xrv reflect.Value) { - xfnf(e, xf, rvConvert(xrv, xrt)) - } - } - } - } - if fn.fe == nil { - switch rk { - case reflect.Bool: - fn.fe = (*encoderCborIO).kBool - case reflect.String: - - fn.fe = (*encoderCborIO).kString - case reflect.Int: - fn.fe = (*encoderCborIO).kInt - case reflect.Int8: - fn.fe = (*encoderCborIO).kInt8 - case reflect.Int16: - fn.fe = (*encoderCborIO).kInt16 - case reflect.Int32: - fn.fe = (*encoderCborIO).kInt32 - case reflect.Int64: - fn.fe = (*encoderCborIO).kInt64 - case reflect.Uint: - fn.fe = (*encoderCborIO).kUint - case reflect.Uint8: - fn.fe = (*encoderCborIO).kUint8 - case reflect.Uint16: - fn.fe = (*encoderCborIO).kUint16 - case reflect.Uint32: - fn.fe = (*encoderCborIO).kUint32 - case reflect.Uint64: - fn.fe = (*encoderCborIO).kUint64 - case reflect.Uintptr: - fn.fe = (*encoderCborIO).kUintptr - case reflect.Float32: - fn.fe = (*encoderCborIO).kFloat32 - case reflect.Float64: - fn.fe = (*encoderCborIO).kFloat64 - case reflect.Complex64: - fn.fe = (*encoderCborIO).kComplex64 - case reflect.Complex128: - fn.fe = (*encoderCborIO).kComplex128 - case reflect.Chan: - fn.fe = (*encoderCborIO).kChan - case reflect.Slice: - fn.fe = (*encoderCborIO).kSlice - case reflect.Array: - fn.fe = (*encoderCborIO).kArray - case reflect.Struct: - if ti.simple { - fn.fe = (*encoderCborIO).kStructSimple - } else { - fn.fe = (*encoderCborIO).kStruct - } - case reflect.Map: - fn.fe = (*encoderCborIO).kMap - case reflect.Interface: - - fn.fe = (*encoderCborIO).kErr - default: - - fn.fe = (*encoderCborIO).kErr - } - } - } - return -} -func (d *decoderCborIO) rawExt(f *decFnInfo, rv reflect.Value) { - d.d.DecodeRawExt(rv2i(rv).(*RawExt)) -} - -func (d *decoderCborIO) ext(f *decFnInfo, rv reflect.Value) { - d.d.DecodeExt(rv2i(rv), f.ti.rt, f.xfTag, f.xfFn) -} - -func (d *decoderCborIO) selferUnmarshal(_ *decFnInfo, rv reflect.Value) { - rv2i(rv).(Selfer).CodecDecodeSelf(&Decoder{d}) -} - -func (d *decoderCborIO) binaryUnmarshal(_ *decFnInfo, rv reflect.Value) { - bm := rv2i(rv).(encoding.BinaryUnmarshaler) - xbs, _ := d.d.DecodeBytes() - fnerr := bm.UnmarshalBinary(xbs) - halt.onerror(fnerr) -} - -func (d *decoderCborIO) textUnmarshal(_ *decFnInfo, rv reflect.Value) { - tm := rv2i(rv).(encoding.TextUnmarshaler) - fnerr := tm.UnmarshalText(bytesOKs(d.d.DecodeStringAsBytes())) - halt.onerror(fnerr) -} - -func (d *decoderCborIO) jsonUnmarshal(_ *decFnInfo, rv reflect.Value) { - d.jsonUnmarshalV(rv2i(rv).(jsonUnmarshaler)) -} - -func (d *decoderCborIO) jsonUnmarshalV(tm jsonUnmarshaler) { - - halt.onerror(tm.UnmarshalJSON(d.d.nextValueBytes())) -} - -func (d *decoderCborIO) kErr(_ *decFnInfo, rv reflect.Value) { - halt.errorf("unsupported decoding kind: %s, for %#v", rv.Kind(), rv) - -} - -func (d *decoderCborIO) raw(_ *decFnInfo, rv reflect.Value) { - rvSetBytes(rv, d.rawBytes()) -} - -func (d *decoderCborIO) kString(_ *decFnInfo, rv reflect.Value) { - rvSetString(rv, d.detach2Str(d.d.DecodeStringAsBytes())) -} - -func (d *decoderCborIO) kBool(_ *decFnInfo, rv reflect.Value) { - rvSetBool(rv, d.d.DecodeBool()) -} - -func (d *decoderCborIO) kTime(_ *decFnInfo, rv reflect.Value) { - rvSetTime(rv, d.d.DecodeTime()) -} - -func (d *decoderCborIO) kFloat32(_ *decFnInfo, rv reflect.Value) { - rvSetFloat32(rv, d.d.DecodeFloat32()) -} - -func (d *decoderCborIO) kFloat64(_ *decFnInfo, rv reflect.Value) { - rvSetFloat64(rv, d.d.DecodeFloat64()) -} - -func (d *decoderCborIO) kComplex64(_ *decFnInfo, rv reflect.Value) { - rvSetComplex64(rv, complex(d.d.DecodeFloat32(), 0)) -} - -func (d *decoderCborIO) kComplex128(_ *decFnInfo, rv reflect.Value) { - rvSetComplex128(rv, complex(d.d.DecodeFloat64(), 0)) -} - -func (d *decoderCborIO) kInt(_ *decFnInfo, rv reflect.Value) { - rvSetInt(rv, int(chkOvf.IntV(d.d.DecodeInt64(), intBitsize))) -} - -func (d *decoderCborIO) kInt8(_ *decFnInfo, rv reflect.Value) { - rvSetInt8(rv, int8(chkOvf.IntV(d.d.DecodeInt64(), 8))) -} - -func (d *decoderCborIO) kInt16(_ *decFnInfo, rv reflect.Value) { - rvSetInt16(rv, int16(chkOvf.IntV(d.d.DecodeInt64(), 16))) -} - -func (d *decoderCborIO) kInt32(_ *decFnInfo, rv reflect.Value) { - rvSetInt32(rv, int32(chkOvf.IntV(d.d.DecodeInt64(), 32))) -} - -func (d *decoderCborIO) kInt64(_ *decFnInfo, rv reflect.Value) { - rvSetInt64(rv, d.d.DecodeInt64()) -} - -func (d *decoderCborIO) kUint(_ *decFnInfo, rv reflect.Value) { - rvSetUint(rv, uint(chkOvf.UintV(d.d.DecodeUint64(), uintBitsize))) -} - -func (d *decoderCborIO) kUintptr(_ *decFnInfo, rv reflect.Value) { - rvSetUintptr(rv, uintptr(chkOvf.UintV(d.d.DecodeUint64(), uintBitsize))) -} - -func (d *decoderCborIO) kUint8(_ *decFnInfo, rv reflect.Value) { - rvSetUint8(rv, uint8(chkOvf.UintV(d.d.DecodeUint64(), 8))) -} - -func (d *decoderCborIO) kUint16(_ *decFnInfo, rv reflect.Value) { - rvSetUint16(rv, uint16(chkOvf.UintV(d.d.DecodeUint64(), 16))) -} - -func (d *decoderCborIO) kUint32(_ *decFnInfo, rv reflect.Value) { - rvSetUint32(rv, uint32(chkOvf.UintV(d.d.DecodeUint64(), 32))) -} - -func (d *decoderCborIO) kUint64(_ *decFnInfo, rv reflect.Value) { - rvSetUint64(rv, d.d.DecodeUint64()) -} - -func (d *decoderCborIO) kInterfaceNaked(f *decFnInfo) (rvn reflect.Value) { - - n := d.naked() - d.d.DecodeNaked() - - if decFailNonEmptyIntf && f.ti.numMeth > 0 { - halt.errorf("cannot decode non-nil codec value into nil %v (%v methods)", f.ti.rt, f.ti.numMeth) - } - - switch n.v { - case valueTypeMap: - mtid := d.mtid - if mtid == 0 { - if d.jsms { - mtid = mapStrIntfTypId - } else { - mtid = mapIntfIntfTypId - } - } - if mtid == mapStrIntfTypId { - var v2 map[string]interface{} - d.decode(&v2) - rvn = rv4iptr(&v2).Elem() - } else if mtid == mapIntfIntfTypId { - var v2 map[interface{}]interface{} - d.decode(&v2) - rvn = rv4iptr(&v2).Elem() - } else if d.mtr { - rvn = reflect.New(d.h.MapType) - d.decode(rv2i(rvn)) - rvn = rvn.Elem() - } else { - - rvn = rvZeroAddrK(d.h.MapType, reflect.Map) - d.decodeValue(rvn, nil) - } - case valueTypeArray: - if d.stid == 0 || d.stid == intfSliceTypId { - var v2 []interface{} - d.decode(&v2) - rvn = rv4iptr(&v2).Elem() - } else if d.str { - rvn = reflect.New(d.h.SliceType) - d.decode(rv2i(rvn)) - rvn = rvn.Elem() - } else { - rvn = rvZeroAddrK(d.h.SliceType, reflect.Slice) - d.decodeValue(rvn, nil) - } - if d.h.PreferArrayOverSlice { - rvn = rvGetArray4Slice(rvn) - } - case valueTypeExt: - tag, bytes := n.u, n.l - bfn := d.h.getExtForTag(tag) - var re = RawExt{Tag: tag} - if bytes == nil { - - if bfn == nil { - d.decode(&re.Value) - rvn = rv4iptr(&re).Elem() - } else if bfn.ext == SelfExt { - rvn = rvZeroAddrK(bfn.rt, bfn.rt.Kind()) - d.decodeValue(rvn, d.fnNoExt(bfn.rt)) - } else { - rvn = reflect.New(bfn.rt) - d.interfaceExtConvertAndDecode(rv2i(rvn), bfn.ext) - rvn = rvn.Elem() - } - } else { - - if bfn == nil { - re.setData(bytes, false) - rvn = rv4iptr(&re).Elem() - } else { - rvn = reflect.New(bfn.rt) - if bfn.ext == SelfExt { - sideDecode(d.hh, &d.h.sideDecPool, func(sd decoderI) { oneOffDecode(sd, rv2i(rvn), bytes, bfn.rt, true) }) - } else { - bfn.ext.ReadExt(rv2i(rvn), bytes) - } - rvn = rvn.Elem() - } - } - - if d.h.PreferPointerForStructOrArray && rvn.CanAddr() { - if rk := rvn.Kind(); rk == reflect.Array || rk == reflect.Struct { - rvn = rvn.Addr() - } - } - case valueTypeNil: - - case valueTypeInt: - rvn = n.ri() - case valueTypeUint: - rvn = n.ru() - case valueTypeFloat: - rvn = n.rf() - case valueTypeBool: - rvn = n.rb() - case valueTypeString, valueTypeSymbol: - rvn = n.rs() - case valueTypeBytes: - rvn = n.rl() - case valueTypeTime: - rvn = n.rt() - default: - halt.errorStr2("kInterfaceNaked: unexpected valueType: ", n.v.String()) - } - return -} - -func (d *decoderCborIO) kInterface(f *decFnInfo, rv reflect.Value) { - - isnilrv := rvIsNil(rv) - - var rvn reflect.Value - - if d.h.InterfaceReset { - - rvn = d.h.intf2impl(f.ti.rtid) - if !rvn.IsValid() { - rvn = d.kInterfaceNaked(f) - if rvn.IsValid() { - rvSetIntf(rv, rvn) - } else if !isnilrv { - decSetNonNilRV2Zero4Intf(rv) - } - return - } - } else if isnilrv { - - rvn = d.h.intf2impl(f.ti.rtid) - if !rvn.IsValid() { - rvn = d.kInterfaceNaked(f) - if rvn.IsValid() { - rvSetIntf(rv, rvn) - } - return - } - } else { - - rvn = rv.Elem() - } - - canDecode, _ := isDecodeable(rvn) - - if !canDecode { - rvn2 := d.oneShotAddrRV(rvn.Type(), rvn.Kind()) - rvSetDirect(rvn2, rvn) - rvn = rvn2 - } - - d.decodeValue(rvn, nil) - rvSetIntf(rv, rvn) -} - -func (d *decoderCborIO) kStructField(si *structFieldInfo, rv reflect.Value) { - if d.d.TryNil() { - rv = si.fieldNoAlloc(rv, true) - if rv.IsValid() { - decSetNonNilRV2Zero(rv) - } - } else if si.decBuiltin { - rv = rvAddr(si.fieldAlloc(rv), si.ptrTyp) - d.decode(rv2i(rv)) - } else { - fn := d.fn(si.baseTyp) - rv = si.fieldAlloc(rv) - if fn.i.addrD { - rv = rvAddr(rv, si.ptrTyp) - } - fn.fd(d, &fn.i, rv) - } -} - -func (d *decoderCborIO) kStructSimple(f *decFnInfo, rv reflect.Value) { - _ = d.d - ctyp := d.d.ContainerType() - ti := f.ti - if ctyp == valueTypeMap { - containerLen := d.mapStart(d.d.ReadMapStart()) - if containerLen == 0 { - d.mapEnd() - return - } - hasLen := containerLen >= 0 - var rvkencname []byte - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - sab, att := d.d.DecodeStringAsBytes() - rvkencname = d.usableStructFieldNameBytes(rvkencname, sab, att) - d.mapElemValue() - if si := ti.siForEncName(rvkencname); si != nil { - d.kStructField(si, rv) - } else { - d.structFieldNotFound(-1, stringView(rvkencname)) - } - } - d.mapEnd() - } else if ctyp == valueTypeArray { - containerLen := d.arrayStart(d.d.ReadArrayStart()) - if containerLen == 0 { - d.arrayEnd() - return - } - - tisfi := ti.sfi.source() - hasLen := containerLen >= 0 - - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.arrayElem(j == 0) - if j < len(tisfi) { - d.kStructField(tisfi[j], rv) - } else { - d.structFieldNotFound(j, "") - } - } - d.arrayEnd() - } else { - halt.onerror(errNeedMapOrArrayDecodeToStruct) - } -} - -func (d *decoderCborIO) kStruct(f *decFnInfo, rv reflect.Value) { - _ = d.d - ctyp := d.d.ContainerType() - ti := f.ti - var mf MissingFielder - if ti.flagMissingFielder { - mf = rv2i(rv).(MissingFielder) - } else if ti.flagMissingFielderPtr { - mf = rv2i(rvAddr(rv, ti.ptr)).(MissingFielder) - } - if ctyp == valueTypeMap { - containerLen := d.mapStart(d.d.ReadMapStart()) - if containerLen == 0 { - d.mapEnd() - return - } - hasLen := containerLen >= 0 - var name2 []byte - var rvkencname []byte - tkt := ti.keyType - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - - if tkt == valueTypeString { - sab, att := d.d.DecodeStringAsBytes() - rvkencname = d.usableStructFieldNameBytes(rvkencname, sab, att) - } else if tkt == valueTypeInt { - rvkencname = strconv.AppendInt(d.b[:0], d.d.DecodeInt64(), 10) - } else if tkt == valueTypeUint { - rvkencname = strconv.AppendUint(d.b[:0], d.d.DecodeUint64(), 10) - } else if tkt == valueTypeFloat { - rvkencname = strconv.AppendFloat(d.b[:0], d.d.DecodeFloat64(), 'f', -1, 64) - } else { - halt.errorStr2("invalid struct key type: ", ti.keyType.String()) - } - - d.mapElemValue() - if si := ti.siForEncName(rvkencname); si != nil { - d.kStructField(si, rv) - } else if mf != nil { - - name2 = append(name2[:0], rvkencname...) - var f interface{} - d.decode(&f) - if !mf.CodecMissingField(name2, f) && d.h.ErrorIfNoField { - halt.errorStr2("no matching struct field when decoding stream map with key: ", stringView(name2)) - } - } else { - d.structFieldNotFound(-1, stringView(rvkencname)) - } - } - d.mapEnd() - } else if ctyp == valueTypeArray { - containerLen := d.arrayStart(d.d.ReadArrayStart()) - if containerLen == 0 { - d.arrayEnd() - return - } - - tisfi := ti.sfi.source() - hasLen := containerLen >= 0 - - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.arrayElem(j == 0) - if j < len(tisfi) { - d.kStructField(tisfi[j], rv) - } else { - d.structFieldNotFound(j, "") - } - } - - d.arrayEnd() - } else { - halt.onerror(errNeedMapOrArrayDecodeToStruct) - } -} - -func (d *decoderCborIO) kSlice(f *decFnInfo, rv reflect.Value) { - _ = d.d - - ti := f.ti - rvCanset := rv.CanSet() - - ctyp := d.d.ContainerType() - if ctyp == valueTypeBytes || ctyp == valueTypeString { - - if !(ti.rtid == uint8SliceTypId || ti.elemkind == uint8(reflect.Uint8)) { - halt.errorf("bytes/string in stream must decode into slice/array of bytes, not %v", ti.rt) - } - rvbs := rvGetBytes(rv) - if rvCanset { - bs2, bst := d.decodeBytesInto(rvbs, false) - if bst != dBytesIntoParamOut { - rvSetBytes(rv, bs2) - } - } else { - - d.decodeBytesInto(rvbs[:len(rvbs):len(rvbs)], true) - } - return - } - - var containerLenS int - isArray := ctyp == valueTypeArray - if isArray { - containerLenS = d.arrayStart(d.d.ReadArrayStart()) - } else if ctyp == valueTypeMap { - containerLenS = d.mapStart(d.d.ReadMapStart()) * 2 - } else { - halt.errorStr2("decoding into a slice, expect map/array - got ", ctyp.String()) - } - - if containerLenS == 0 { - if rvCanset { - if rvIsNil(rv) { - rvSetDirect(rv, rvSliceZeroCap(ti.rt)) - } else { - rvSetSliceLen(rv, 0) - } - } - if isArray { - d.arrayEnd() - } else { - d.mapEnd() - } - return - } - - rtelem0Mut := !scalarBitset.isset(ti.elemkind) - rtelem := ti.elem - - for k := reflect.Kind(ti.elemkind); k == reflect.Ptr; k = rtelem.Kind() { - rtelem = rtelem.Elem() - } - - var fn *decFnCborIO - - var rvChanged bool - - var rv0 = rv - var rv9 reflect.Value - - rvlen := rvLenSlice(rv) - rvcap := rvCapSlice(rv) - maxInitLen := d.maxInitLen() - hasLen := containerLenS >= 0 - if hasLen { - if containerLenS > rvcap { - oldRvlenGtZero := rvlen > 0 - rvlen1 := int(decInferLen(containerLenS, maxInitLen, uint(ti.elemsize))) - if rvlen1 == rvlen { - } else if rvlen1 <= rvcap { - if rvCanset { - rvlen = rvlen1 - rvSetSliceLen(rv, rvlen) - } - } else if rvCanset { - rvlen = rvlen1 - rv, rvCanset = rvMakeSlice(rv, f.ti, rvlen, rvlen) - rvcap = rvlen - rvChanged = !rvCanset - } else { - halt.errorStr("cannot decode into non-settable slice") - } - if rvChanged && oldRvlenGtZero && rtelem0Mut { - rvCopySlice(rv, rv0, rtelem) - } - } else if containerLenS != rvlen { - if rvCanset { - rvlen = containerLenS - rvSetSliceLen(rv, rvlen) - } - } - } - - var elemReset = d.h.SliceElementReset - - var rtelemIsPtr bool - var rtelemElem reflect.Type - builtin := ti.tielem.flagDecBuiltin - if builtin { - rtelemIsPtr = ti.elemkind == uint8(reflect.Ptr) - if rtelemIsPtr { - rtelemElem = ti.elem.Elem() - } - } - - var j int - for ; d.containerNext(j, containerLenS, hasLen); j++ { - if j == 0 { - if rvIsNil(rv) { - if rvCanset { - rvlen = int(decInferLen(containerLenS, maxInitLen, uint(ti.elemsize))) - rv, rvCanset = rvMakeSlice(rv, f.ti, rvlen, rvlen) - rvcap = rvlen - rvChanged = !rvCanset - } else { - halt.errorStr("cannot decode into non-settable slice") - } - } - if fn == nil { - fn = d.fn(rtelem) - } - } - - if ctyp == valueTypeArray { - d.arrayElem(j == 0) - } else if j&1 == 0 { - d.mapElemKey(j == 0) - } else { - d.mapElemValue() - } - - if j >= rvlen { - - if rvlen < rvcap { - rvlen = rvcap - if rvCanset { - rvSetSliceLen(rv, rvlen) - } else if rvChanged { - rv = rvSlice(rv, rvlen) - } else { - halt.onerror(errExpandSliceCannotChange) - } - } else { - if !(rvCanset || rvChanged) { - halt.onerror(errExpandSliceCannotChange) - } - rv, rvcap, rvCanset = rvGrowSlice(rv, f.ti, rvcap, 1) - - rvlen = rvcap - rvChanged = !rvCanset - } - } - - rv9 = rvArrayIndex(rv, j, f.ti, true) - if elemReset { - rvSetZero(rv9) - } - if d.d.TryNil() { - rvSetZero(rv9) - } else if builtin { - if rtelemIsPtr { - if rvIsNil(rv9) { - rvSetDirect(rv9, reflect.New(rtelemElem)) - } - d.decode(rv2i(rv9)) - } else { - d.decode(rv2i(rvAddr(rv9, ti.tielem.ptr))) - } - } else { - d.decodeValueNoCheckNil(rv9, fn) - } - } - if j < rvlen { - if rvCanset { - rvSetSliceLen(rv, j) - } else if rvChanged { - rv = rvSlice(rv, j) - } - - } else if j == 0 && rvIsNil(rv) { - if rvCanset { - rv = rvSliceZeroCap(ti.rt) - rvCanset = false - rvChanged = true - } - } - if isArray { - d.arrayEnd() - } else { - d.mapEnd() - } - - if rvChanged { - rvSetDirect(rv0, rv) - } -} - -func (d *decoderCborIO) kArray(f *decFnInfo, rv reflect.Value) { - _ = d.d - - ti := f.ti - ctyp := d.d.ContainerType() - if handleBytesWithinKArray && (ctyp == valueTypeBytes || ctyp == valueTypeString) { - - if ti.elemkind != uint8(reflect.Uint8) { - halt.errorf("bytes/string in stream can decode into array of bytes, but not %v", ti.rt) - } - rvbs := rvGetArrayBytes(rv, nil) - d.decodeBytesInto(rvbs, true) - return - } - - var containerLenS int - isArray := ctyp == valueTypeArray - if isArray { - containerLenS = d.arrayStart(d.d.ReadArrayStart()) - } else if ctyp == valueTypeMap { - containerLenS = d.mapStart(d.d.ReadMapStart()) * 2 - } else { - halt.errorStr2("decoding into a slice, expect map/array - got ", ctyp.String()) - } - - if containerLenS == 0 { - if isArray { - d.arrayEnd() - } else { - d.mapEnd() - } - return - } - - rtelem := ti.elem - for k := reflect.Kind(ti.elemkind); k == reflect.Ptr; k = rtelem.Kind() { - rtelem = rtelem.Elem() - } - - var rv9 reflect.Value - - rvlen := rv.Len() - hasLen := containerLenS >= 0 - if hasLen && containerLenS > rvlen { - halt.errorf("cannot decode into array with length: %v, less than container length: %v", any(rvlen), any(containerLenS)) - } - - var elemReset = d.h.SliceElementReset - - var rtelemIsPtr bool - var rtelemElem reflect.Type - var fn *decFnCborIO - builtin := ti.tielem.flagDecBuiltin - if builtin { - rtelemIsPtr = ti.elemkind == uint8(reflect.Ptr) - if rtelemIsPtr { - rtelemElem = ti.elem.Elem() - } - } else { - fn = d.fn(rtelem) - } - - for j := 0; d.containerNext(j, containerLenS, hasLen); j++ { - if ctyp == valueTypeArray { - d.arrayElem(j == 0) - } else if j&1 == 0 { - d.mapElemKey(j == 0) - } else { - d.mapElemValue() - } - - if j >= rvlen { - d.arrayCannotExpand(rvlen, j+1) - d.swallow() - continue - } - - rv9 = rvArrayIndex(rv, j, f.ti, false) - if elemReset { - rvSetZero(rv9) - } - if d.d.TryNil() { - rvSetZero(rv9) - } else if builtin { - if rtelemIsPtr { - if rvIsNil(rv9) { - rvSetDirect(rv9, reflect.New(rtelemElem)) - } - d.decode(rv2i(rv9)) - } else { - d.decode(rv2i(rvAddr(rv9, ti.tielem.ptr))) - } - } else { - d.decodeValueNoCheckNil(rv9, fn) - } - } - if isArray { - d.arrayEnd() - } else { - d.mapEnd() - } -} - -func (d *decoderCborIO) kChan(f *decFnInfo, rv reflect.Value) { - _ = d.d - - ti := f.ti - if ti.chandir&uint8(reflect.SendDir) == 0 { - halt.errorStr("receive-only channel cannot be decoded") - } - ctyp := d.d.ContainerType() - if ctyp == valueTypeBytes || ctyp == valueTypeString { - - if !(ti.rtid == uint8SliceTypId || ti.elemkind == uint8(reflect.Uint8)) { - halt.errorf("bytes/string in stream must decode into slice/array of bytes, not %v", ti.rt) - } - bs2, _ := d.d.DecodeBytes() - irv := rv2i(rv) - ch, ok := irv.(chan<- byte) - if !ok { - ch = irv.(chan byte) - } - for _, b := range bs2 { - ch <- b - } - return - } - - var rvCanset = rv.CanSet() - - var containerLenS int - isArray := ctyp == valueTypeArray - if isArray { - containerLenS = d.arrayStart(d.d.ReadArrayStart()) - } else if ctyp == valueTypeMap { - containerLenS = d.mapStart(d.d.ReadMapStart()) * 2 - } else { - halt.errorStr2("decoding into a slice, expect map/array - got ", ctyp.String()) - } - - if containerLenS == 0 { - if rvCanset && rvIsNil(rv) { - rvSetDirect(rv, reflect.MakeChan(ti.rt, 0)) - } - if isArray { - d.arrayEnd() - } else { - d.mapEnd() - } - return - } - - rtelem := ti.elem - useTransient := decUseTransient && ti.elemkind != byte(reflect.Ptr) && ti.tielem.flagCanTransient - - for k := reflect.Kind(ti.elemkind); k == reflect.Ptr; k = rtelem.Kind() { - rtelem = rtelem.Elem() - } - - var fn *decFnCborIO - - var rvChanged bool - var rv0 = rv - var rv9 reflect.Value - - var rvlen int - hasLen := containerLenS >= 0 - maxInitLen := d.maxInitLen() - - for j := 0; d.containerNext(j, containerLenS, hasLen); j++ { - if j == 0 { - if rvIsNil(rv) { - if hasLen { - rvlen = int(decInferLen(containerLenS, maxInitLen, uint(ti.elemsize))) - } else { - rvlen = decDefChanCap - } - if rvCanset { - rv = reflect.MakeChan(ti.rt, rvlen) - rvChanged = true - } else { - halt.errorStr("cannot decode into non-settable chan") - } - } - if fn == nil { - fn = d.fn(rtelem) - } - } - - if ctyp == valueTypeArray { - d.arrayElem(j == 0) - } else if j&1 == 0 { - d.mapElemKey(j == 0) - } else { - d.mapElemValue() - } - - if rv9.IsValid() { - rvSetZero(rv9) - } else if useTransient { - rv9 = d.perType.TransientAddrK(ti.elem, reflect.Kind(ti.elemkind)) - } else { - rv9 = rvZeroAddrK(ti.elem, reflect.Kind(ti.elemkind)) - } - if !d.d.TryNil() { - d.decodeValueNoCheckNil(rv9, fn) - } - rv.Send(rv9) - } - if isArray { - d.arrayEnd() - } else { - d.mapEnd() - } - - if rvChanged { - rvSetDirect(rv0, rv) - } - -} - -func (d *decoderCborIO) kMap(f *decFnInfo, rv reflect.Value) { - _ = d.d - containerLen := d.mapStart(d.d.ReadMapStart()) - ti := f.ti - if rvIsNil(rv) { - rvlen := int(decInferLen(containerLen, d.maxInitLen(), uint(ti.keysize+ti.elemsize))) - rvSetDirect(rv, makeMapReflect(ti.rt, rvlen)) - } - - if containerLen == 0 { - d.mapEnd() - return - } - - ktype, vtype := ti.key, ti.elem - ktypeId := rt2id(ktype) - vtypeKind := reflect.Kind(ti.elemkind) - ktypeKind := reflect.Kind(ti.keykind) - mparams := getMapReqParams(ti) - - vtypePtr := vtypeKind == reflect.Ptr - ktypePtr := ktypeKind == reflect.Ptr - - vTransient := decUseTransient && !vtypePtr && ti.tielem.flagCanTransient - - kTransient := vTransient && !ktypePtr && ti.tikey.flagCanTransient - - var vtypeElem reflect.Type - - var keyFn, valFn *decFnCborIO - var ktypeLo, vtypeLo = ktype, vtype - - if ktypeKind == reflect.Ptr { - for ktypeLo = ktype.Elem(); ktypeLo.Kind() == reflect.Ptr; ktypeLo = ktypeLo.Elem() { - } - } - - if vtypePtr { - vtypeElem = vtype.Elem() - for vtypeLo = vtypeElem; vtypeLo.Kind() == reflect.Ptr; vtypeLo = vtypeLo.Elem() { - } - } - - rvkMut := !scalarBitset.isset(ti.keykind) - rvvMut := !scalarBitset.isset(ti.elemkind) - rvvCanNil := isnilBitset.isset(ti.elemkind) - - var rvk, rvkn, rvv, rvvn, rvva, rvvz reflect.Value - - var doMapGet, doMapSet bool - - if !d.h.MapValueReset { - if rvvMut && (vtypeKind != reflect.Interface || !d.h.InterfaceReset) { - doMapGet = true - rvva = mapAddrLoopvarRV(vtype, vtypeKind) - } - } - - ktypeIsString := ktypeId == stringTypId - ktypeIsIntf := ktypeId == intfTypId - hasLen := containerLen >= 0 - - var kstr2bs []byte - var kstr string - - var mapKeyStringSharesBytesBuf bool - var att dBytesAttachState - - var vElem, kElem reflect.Type - kbuiltin := ti.tikey.flagDecBuiltin && ti.keykind != uint8(reflect.Slice) - vbuiltin := ti.tielem.flagDecBuiltin - if kbuiltin && ktypePtr { - kElem = ti.key.Elem() - } - if vbuiltin && vtypePtr { - vElem = ti.elem.Elem() - } - - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - mapKeyStringSharesBytesBuf = false - kstr = "" - if j == 0 { - - if kTransient { - rvk = d.perType.TransientAddr2K(ktype, ktypeKind) - } else { - rvk = rvZeroAddrK(ktype, ktypeKind) - } - if !rvkMut { - rvkn = rvk - } - if !rvvMut { - if vTransient { - rvvn = d.perType.TransientAddrK(vtype, vtypeKind) - } else { - rvvn = rvZeroAddrK(vtype, vtypeKind) - } - } - if !ktypeIsString && keyFn == nil { - keyFn = d.fn(ktypeLo) - } - if valFn == nil { - valFn = d.fn(vtypeLo) - } - } else if rvkMut { - rvSetZero(rvk) - } else { - rvk = rvkn - } - - d.mapElemKey(j == 0) - - if d.d.TryNil() { - rvSetZero(rvk) - } else if ktypeIsString { - kstr2bs, att = d.d.DecodeStringAsBytes() - kstr, mapKeyStringSharesBytesBuf = d.bytes2Str(kstr2bs, att) - rvSetString(rvk, kstr) - } else { - if kbuiltin { - if ktypePtr { - if rvIsNil(rvk) { - rvSetDirect(rvk, reflect.New(kElem)) - } - d.decode(rv2i(rvk)) - } else { - d.decode(rv2i(rvAddr(rvk, ti.tikey.ptr))) - } - } else { - d.decodeValueNoCheckNil(rvk, keyFn) - } - - if ktypeIsIntf { - if rvk2 := rvk.Elem(); rvk2.IsValid() && rvk2.Type() == uint8SliceTyp { - kstr2bs = rvGetBytes(rvk2) - kstr, mapKeyStringSharesBytesBuf = d.bytes2Str(kstr2bs, dBytesAttachView) - rvSetIntf(rvk, rv4istr(kstr)) - } - - } - } - - if mapKeyStringSharesBytesBuf && d.bufio { - if ktypeIsString { - rvSetString(rvk, d.detach2Str(kstr2bs, att)) - } else { - rvSetIntf(rvk, rv4istr(d.detach2Str(kstr2bs, att))) - } - mapKeyStringSharesBytesBuf = false - } - - d.mapElemValue() - - if d.d.TryNil() { - if mapKeyStringSharesBytesBuf { - if ktypeIsString { - rvSetString(rvk, d.detach2Str(kstr2bs, att)) - } else { - rvSetIntf(rvk, rv4istr(d.detach2Str(kstr2bs, att))) - } - } - - if !rvvz.IsValid() { - rvvz = rvZeroK(vtype, vtypeKind) - } - mapSet(rv, rvk, rvvz, mparams) - continue - } - - doMapSet = true - - if !rvvMut { - rvv = rvvn - } else if !doMapGet { - goto NEW_RVV - } else { - rvv = mapGet(rv, rvk, rvva, mparams) - if !rvv.IsValid() || (rvvCanNil && rvIsNil(rvv)) { - goto NEW_RVV - } - switch vtypeKind { - case reflect.Ptr, reflect.Map: - doMapSet = false - case reflect.Interface: - - rvvn = rvv.Elem() - if k := rvvn.Kind(); (k == reflect.Ptr || k == reflect.Map) && !rvIsNil(rvvn) { - d.decodeValueNoCheckNil(rvvn, nil) - continue - } - - rvvn = rvZeroAddrK(vtype, vtypeKind) - rvSetIntf(rvvn, rvv) - rvv = rvvn - default: - - if vTransient { - rvvn = d.perType.TransientAddrK(vtype, vtypeKind) - } else { - rvvn = rvZeroAddrK(vtype, vtypeKind) - } - rvSetDirect(rvvn, rvv) - rvv = rvvn - } - } - goto DECODE_VALUE_NO_CHECK_NIL - - NEW_RVV: - if vtypePtr { - rvv = reflect.New(vtypeElem) - } else if vTransient { - rvv = d.perType.TransientAddrK(vtype, vtypeKind) - } else { - rvv = rvZeroAddrK(vtype, vtypeKind) - } - - DECODE_VALUE_NO_CHECK_NIL: - if doMapSet && mapKeyStringSharesBytesBuf { - if ktypeIsString { - rvSetString(rvk, d.detach2Str(kstr2bs, att)) - } else { - rvSetIntf(rvk, rv4istr(d.detach2Str(kstr2bs, att))) - } - } - if vbuiltin { - if vtypePtr { - if rvIsNil(rvv) { - rvSetDirect(rvv, reflect.New(vElem)) - } - d.decode(rv2i(rvv)) - } else { - d.decode(rv2i(rvAddr(rvv, ti.tielem.ptr))) - } - } else { - d.decodeValueNoCheckNil(rvv, valFn) - } - if doMapSet { - mapSet(rv, rvk, rvv, mparams) - } - } - - d.mapEnd() -} - -func (d *decoderCborIO) init(h Handle) { - initHandle(h) - callMake(&d.d) - d.hh = h - d.h = h.getBasicHandle() - - d.err = errDecoderNotInitialized - - if d.h.InternString && d.is == nil { - d.is.init() - } - - d.fp = d.d.init(h, &d.decoderBase, d).(*fastpathDsCborIO) - - if d.bytes { - d.rtidFn = &d.h.rtidFnsDecBytes - d.rtidFnNoExt = &d.h.rtidFnsDecNoExtBytes - } else { - d.bufio = d.h.ReaderBufferSize > 0 - d.rtidFn = &d.h.rtidFnsDecIO - d.rtidFnNoExt = &d.h.rtidFnsDecNoExtIO - } - - d.reset() - -} - -func (d *decoderCborIO) reset() { - d.d.reset() - d.err = nil - d.c = 0 - d.depth = 0 - d.calls = 0 - - d.maxdepth = decDefMaxDepth - if d.h.MaxDepth > 0 { - d.maxdepth = d.h.MaxDepth - } - d.mtid = 0 - d.stid = 0 - d.mtr = false - d.str = false - if d.h.MapType != nil { - d.mtid = rt2id(d.h.MapType) - _, d.mtr = fastpathAvIndex(d.mtid) - } - if d.h.SliceType != nil { - d.stid = rt2id(d.h.SliceType) - _, d.str = fastpathAvIndex(d.stid) - } -} - -func (d *decoderCborIO) Reset(r io.Reader) { - if d.bytes { - halt.onerror(errDecNoResetBytesWithReader) - } - d.reset() - if r == nil { - r = &eofReader - } - d.d.resetInIO(r) -} - -func (d *decoderCborIO) ResetBytes(in []byte) { - if !d.bytes { - halt.onerror(errDecNoResetReaderWithBytes) - } - d.resetBytes(in) -} - -func (d *decoderCborIO) resetBytes(in []byte) { - d.reset() - if in == nil { - in = zeroByteSlice - } - d.d.resetInBytes(in) -} - -func (d *decoderCborIO) ResetString(s string) { - d.ResetBytes(bytesView(s)) -} - -func (d *decoderCborIO) Decode(v interface{}) (err error) { - - defer panicValToErr(d, callRecoverSentinel, &d.err, &err, debugging) - d.mustDecode(v) - return -} - -func (d *decoderCborIO) MustDecode(v interface{}) { - defer panicValToErr(d, callRecoverSentinel, &d.err, nil, true) - d.mustDecode(v) - return -} - -func (d *decoderCborIO) mustDecode(v interface{}) { - halt.onerror(d.err) - if d.hh == nil { - halt.onerror(errNoFormatHandle) - } - - d.calls++ - d.decode(v) - d.calls-- -} - -func (d *decoderCborIO) Release() {} - -func (d *decoderCborIO) swallow() { - d.d.nextValueBytes() -} - -func (d *decoderCborIO) nextValueBytes() []byte { - return d.d.nextValueBytes() -} - -func (d *decoderCborIO) decode(iv interface{}) { - _ = d.d - - rv, ok := isNil(iv, true) - if ok { - halt.onerror(errCannotDecodeIntoNil) - } - - switch v := iv.(type) { - - case *string: - *v = d.detach2Str(d.d.DecodeStringAsBytes()) - case *bool: - *v = d.d.DecodeBool() - case *int: - *v = int(chkOvf.IntV(d.d.DecodeInt64(), intBitsize)) - case *int8: - *v = int8(chkOvf.IntV(d.d.DecodeInt64(), 8)) - case *int16: - *v = int16(chkOvf.IntV(d.d.DecodeInt64(), 16)) - case *int32: - *v = int32(chkOvf.IntV(d.d.DecodeInt64(), 32)) - case *int64: - *v = d.d.DecodeInt64() - case *uint: - *v = uint(chkOvf.UintV(d.d.DecodeUint64(), uintBitsize)) - case *uint8: - *v = uint8(chkOvf.UintV(d.d.DecodeUint64(), 8)) - case *uint16: - *v = uint16(chkOvf.UintV(d.d.DecodeUint64(), 16)) - case *uint32: - *v = uint32(chkOvf.UintV(d.d.DecodeUint64(), 32)) - case *uint64: - *v = d.d.DecodeUint64() - case *uintptr: - *v = uintptr(chkOvf.UintV(d.d.DecodeUint64(), uintBitsize)) - case *float32: - *v = d.d.DecodeFloat32() - case *float64: - *v = d.d.DecodeFloat64() - case *complex64: - *v = complex(d.d.DecodeFloat32(), 0) - case *complex128: - *v = complex(d.d.DecodeFloat64(), 0) - case *[]byte: - *v, _ = d.decodeBytesInto(*v, false) - case []byte: - - d.decodeBytesInto(v[:len(v):len(v)], true) - case *time.Time: - *v = d.d.DecodeTime() - case *Raw: - *v = d.rawBytes() - - case *interface{}: - d.decodeValue(rv4iptr(v), nil) - - case reflect.Value: - if ok, _ = isDecodeable(v); !ok { - d.haltAsNotDecodeable(v) - } - d.decodeValue(v, nil) - - default: - - if skipFastpathTypeSwitchInDirectCall || !d.dh.fastpathDecodeTypeSwitch(iv, d) { - if !rv.IsValid() { - rv = reflect.ValueOf(iv) - } - if ok, _ = isDecodeable(rv); !ok { - d.haltAsNotDecodeable(rv) - } - d.decodeValue(rv, nil) - } - } -} - -func (d *decoderCborIO) decodeValue(rv reflect.Value, fn *decFnCborIO) { - if d.d.TryNil() { - decSetNonNilRV2Zero(rv) - } else { - d.decodeValueNoCheckNil(rv, fn) - } -} - -func (d *decoderCborIO) decodeValueNoCheckNil(rv reflect.Value, fn *decFnCborIO) { - - var rvp reflect.Value - var rvpValid bool -PTR: - if rv.Kind() == reflect.Ptr { - rvpValid = true - if rvIsNil(rv) { - rvSetDirect(rv, reflect.New(rv.Type().Elem())) - } - rvp = rv - rv = rv.Elem() - goto PTR - } - - if fn == nil { - fn = d.fn(rv.Type()) - } - if fn.i.addrD { - if rvpValid { - rv = rvp - } else if rv.CanAddr() { - rv = rvAddr(rv, fn.i.ti.ptr) - } else if fn.i.addrDf { - halt.errorStr("cannot decode into a non-pointer value") - } - } - fn.fd(d, &fn.i, rv) -} - -func (d *decoderCborIO) decodeAs(v interface{}, t reflect.Type, ext bool) { - if ext { - d.decodeValue(baseRV(v), d.fn(t)) - } else { - d.decodeValue(baseRV(v), d.fnNoExt(t)) - } -} - -func (d *decoderCborIO) structFieldNotFound(index int, rvkencname string) { - - if d.h.ErrorIfNoField { - if index >= 0 { - halt.errorInt("no matching struct field found when decoding stream array at index ", int64(index)) - } else if rvkencname != "" { - halt.errorStr2("no matching struct field found when decoding stream map with key ", rvkencname) - } - } - d.swallow() -} - -func (d *decoderCborIO) decodeBytesInto(out []byte, mustFit bool) (v []byte, state dBytesIntoState) { - v, att := d.d.DecodeBytes() - if cap(v) == 0 || (att >= dBytesAttachViewZerocopy && !mustFit) { - - return - } - if len(v) == 0 { - v = zeroByteSlice - return - } - if len(out) == len(v) { - state = dBytesIntoParamOut - } else if cap(out) >= len(v) { - out = out[:len(v)] - state = dBytesIntoParamOutSlice - } else if mustFit { - halt.errorf("bytes capacity insufficient for decoded bytes: got/expected: %d/%d", len(v), len(out)) - } else { - out = make([]byte, len(v)) - state = dBytesIntoNew - } - copy(out, v) - v = out - return -} - -func (d *decoderCborIO) rawBytes() (v []byte) { - - v = d.d.nextValueBytes() - if d.bytes && !d.h.ZeroCopy { - vv := make([]byte, len(v)) - copy(vv, v) - v = vv - } - return -} - -func (d *decoderCborIO) wrapErr(v error, err *error) { - *err = wrapCodecErr(v, d.hh.Name(), d.d.NumBytesRead(), false) -} - -func (d *decoderCborIO) NumBytesRead() int { - return d.d.NumBytesRead() -} - -func (d *decoderCborIO) containerNext(j, containerLen int, hasLen bool) bool { - - if hasLen { - return j < containerLen - } - return !d.d.CheckBreak() -} - -func (d *decoderCborIO) mapElemKey(firstTime bool) { - d.d.ReadMapElemKey(firstTime) - d.c = containerMapKey -} - -func (d *decoderCborIO) mapElemValue() { - d.d.ReadMapElemValue() - d.c = containerMapValue -} - -func (d *decoderCborIO) mapEnd() { - d.d.ReadMapEnd() - d.depthDecr() - d.c = 0 -} - -func (d *decoderCborIO) arrayElem(firstTime bool) { - d.d.ReadArrayElem(firstTime) - d.c = containerArrayElem -} - -func (d *decoderCborIO) arrayEnd() { - d.d.ReadArrayEnd() - d.depthDecr() - d.c = 0 -} - -func (d *decoderCborIO) interfaceExtConvertAndDecode(v interface{}, ext InterfaceExt) { - - var vv interface{} - d.decode(&vv) - ext.UpdateExt(v, vv) - -} - -func (d *decoderCborIO) fn(t reflect.Type) *decFnCborIO { - return d.dh.decFnViaBH(t, d.rtidFn, d.h, d.fp, false) -} - -func (d *decoderCborIO) fnNoExt(t reflect.Type) *decFnCborIO { - return d.dh.decFnViaBH(t, d.rtidFnNoExt, d.h, d.fp, true) -} - -func (helperDecDriverCborIO) newDecoderBytes(in []byte, h Handle) *decoderCborIO { - var c1 decoderCborIO - c1.bytes = true - c1.init(h) - c1.ResetBytes(in) - return &c1 -} - -func (helperDecDriverCborIO) newDecoderIO(in io.Reader, h Handle) *decoderCborIO { - var c1 decoderCborIO - c1.init(h) - c1.Reset(in) - return &c1 -} - -func (helperDecDriverCborIO) decFnloadFastpathUnderlying(ti *typeInfo, fp *fastpathDsCborIO) (f *fastpathDCborIO, u reflect.Type) { - rtid := rt2id(ti.fastpathUnderlying) - idx, ok := fastpathAvIndex(rtid) - if !ok { - return - } - f = &fp[idx] - if uint8(reflect.Array) == ti.kind { - u = reflect.ArrayOf(ti.rt.Len(), ti.elem) - } else { - u = f.rt - } - return -} - -func (helperDecDriverCborIO) decFindRtidFn(s []decRtidFnCborIO, rtid uintptr) (i uint, fn *decFnCborIO) { - - var h uint - var j = uint(len(s)) -LOOP: - if i < j { - h = (i + j) >> 1 - if s[h].rtid < rtid { - i = h + 1 - } else { - j = h - } - goto LOOP - } - if i < uint(len(s)) && s[i].rtid == rtid { - fn = s[i].fn - } - return -} - -func (helperDecDriverCborIO) decFromRtidFnSlice(fns *atomicRtidFnSlice) (s []decRtidFnCborIO) { - if v := fns.load(); v != nil { - s = *(lowLevelToPtr[[]decRtidFnCborIO](v)) - } - return -} - -func (dh helperDecDriverCborIO) decFnViaBH(rt reflect.Type, fns *atomicRtidFnSlice, x *BasicHandle, fp *fastpathDsCborIO, - checkExt bool) (fn *decFnCborIO) { - return dh.decFnVia(rt, fns, x.typeInfos(), &x.mu, x.extHandle, fp, - checkExt, x.CheckCircularRef, x.timeBuiltin, x.binaryHandle, x.jsonHandle) -} - -func (dh helperDecDriverCborIO) decFnVia(rt reflect.Type, fns *atomicRtidFnSlice, - tinfos *TypeInfos, mu *sync.Mutex, exth extHandle, fp *fastpathDsCborIO, - checkExt, checkCircularRef, timeBuiltin, binaryEncoding, json bool) (fn *decFnCborIO) { - rtid := rt2id(rt) - var sp []decRtidFnCborIO = dh.decFromRtidFnSlice(fns) - if sp != nil { - _, fn = dh.decFindRtidFn(sp, rtid) - } - if fn == nil { - fn = dh.decFnViaLoader(rt, rtid, fns, tinfos, mu, exth, fp, checkExt, checkCircularRef, timeBuiltin, binaryEncoding, json) - } - return -} - -func (dh helperDecDriverCborIO) decFnViaLoader(rt reflect.Type, rtid uintptr, fns *atomicRtidFnSlice, - tinfos *TypeInfos, mu *sync.Mutex, exth extHandle, fp *fastpathDsCborIO, - checkExt, checkCircularRef, timeBuiltin, binaryEncoding, json bool) (fn *decFnCborIO) { - - fn = dh.decFnLoad(rt, rtid, tinfos, exth, fp, checkExt, checkCircularRef, timeBuiltin, binaryEncoding, json) - var sp []decRtidFnCborIO - mu.Lock() - sp = dh.decFromRtidFnSlice(fns) - - if sp == nil { - sp = []decRtidFnCborIO{{rtid, fn}} - fns.store(ptrToLowLevel(&sp)) - } else { - idx, fn2 := dh.decFindRtidFn(sp, rtid) - if fn2 == nil { - sp2 := make([]decRtidFnCborIO, len(sp)+1) - copy(sp2[idx+1:], sp[idx:]) - copy(sp2, sp[:idx]) - sp2[idx] = decRtidFnCborIO{rtid, fn} - fns.store(ptrToLowLevel(&sp2)) - } - } - mu.Unlock() - return -} - -func (dh helperDecDriverCborIO) decFnLoad(rt reflect.Type, rtid uintptr, tinfos *TypeInfos, - exth extHandle, fp *fastpathDsCborIO, - checkExt, checkCircularRef, timeBuiltin, binaryEncoding, json bool) (fn *decFnCborIO) { - fn = new(decFnCborIO) - fi := &(fn.i) - ti := tinfos.get(rtid, rt) - fi.ti = ti - rk := reflect.Kind(ti.kind) - - fi.addrDf = true - - if rtid == timeTypId && timeBuiltin { - fn.fd = (*decoderCborIO).kTime - } else if rtid == rawTypId { - fn.fd = (*decoderCborIO).raw - } else if rtid == rawExtTypId { - fn.fd = (*decoderCborIO).rawExt - fi.addrD = true - } else if xfFn := exth.getExt(rtid, checkExt); xfFn != nil { - fi.xfTag, fi.xfFn = xfFn.tag, xfFn.ext - fn.fd = (*decoderCborIO).ext - fi.addrD = true - } else if ti.flagSelfer || ti.flagSelferPtr { - fn.fd = (*decoderCborIO).selferUnmarshal - fi.addrD = ti.flagSelferPtr - } else if supportMarshalInterfaces && binaryEncoding && - (ti.flagBinaryMarshaler || ti.flagBinaryMarshalerPtr) && - (ti.flagBinaryUnmarshaler || ti.flagBinaryUnmarshalerPtr) { - fn.fd = (*decoderCborIO).binaryUnmarshal - fi.addrD = ti.flagBinaryUnmarshalerPtr - } else if supportMarshalInterfaces && !binaryEncoding && json && - (ti.flagJsonMarshaler || ti.flagJsonMarshalerPtr) && - (ti.flagJsonUnmarshaler || ti.flagJsonUnmarshalerPtr) { - - fn.fd = (*decoderCborIO).jsonUnmarshal - fi.addrD = ti.flagJsonUnmarshalerPtr - } else if supportMarshalInterfaces && !binaryEncoding && - (ti.flagTextMarshaler || ti.flagTextMarshalerPtr) && - (ti.flagTextUnmarshaler || ti.flagTextUnmarshalerPtr) { - fn.fd = (*decoderCborIO).textUnmarshal - fi.addrD = ti.flagTextUnmarshalerPtr - } else { - if fastpathEnabled && (rk == reflect.Map || rk == reflect.Slice || rk == reflect.Array) { - var rtid2 uintptr - if !ti.flagHasPkgPath { - rtid2 = rtid - if rk == reflect.Array { - rtid2 = rt2id(ti.key) - } - if idx, ok := fastpathAvIndex(rtid2); ok { - fn.fd = fp[idx].decfn - fi.addrD = true - fi.addrDf = false - if rk == reflect.Array { - fi.addrD = false - } - } - } else { - - xfe, xrt := dh.decFnloadFastpathUnderlying(ti, fp) - if xfe != nil { - xfnf2 := xfe.decfn - if rk == reflect.Array { - fi.addrD = false - fn.fd = func(d *decoderCborIO, xf *decFnInfo, xrv reflect.Value) { - xfnf2(d, xf, rvConvert(xrv, xrt)) - } - } else { - fi.addrD = true - fi.addrDf = false - xptr2rt := reflect.PointerTo(xrt) - fn.fd = func(d *decoderCborIO, xf *decFnInfo, xrv reflect.Value) { - if xrv.Kind() == reflect.Ptr { - xfnf2(d, xf, rvConvert(xrv, xptr2rt)) - } else { - xfnf2(d, xf, rvConvert(xrv, xrt)) - } - } - } - } - } - } - if fn.fd == nil { - switch rk { - case reflect.Bool: - fn.fd = (*decoderCborIO).kBool - case reflect.String: - fn.fd = (*decoderCborIO).kString - case reflect.Int: - fn.fd = (*decoderCborIO).kInt - case reflect.Int8: - fn.fd = (*decoderCborIO).kInt8 - case reflect.Int16: - fn.fd = (*decoderCborIO).kInt16 - case reflect.Int32: - fn.fd = (*decoderCborIO).kInt32 - case reflect.Int64: - fn.fd = (*decoderCborIO).kInt64 - case reflect.Uint: - fn.fd = (*decoderCborIO).kUint - case reflect.Uint8: - fn.fd = (*decoderCborIO).kUint8 - case reflect.Uint16: - fn.fd = (*decoderCborIO).kUint16 - case reflect.Uint32: - fn.fd = (*decoderCborIO).kUint32 - case reflect.Uint64: - fn.fd = (*decoderCborIO).kUint64 - case reflect.Uintptr: - fn.fd = (*decoderCborIO).kUintptr - case reflect.Float32: - fn.fd = (*decoderCborIO).kFloat32 - case reflect.Float64: - fn.fd = (*decoderCborIO).kFloat64 - case reflect.Complex64: - fn.fd = (*decoderCborIO).kComplex64 - case reflect.Complex128: - fn.fd = (*decoderCborIO).kComplex128 - case reflect.Chan: - fn.fd = (*decoderCborIO).kChan - case reflect.Slice: - fn.fd = (*decoderCborIO).kSlice - case reflect.Array: - fi.addrD = false - fn.fd = (*decoderCborIO).kArray - case reflect.Struct: - if ti.simple { - fn.fd = (*decoderCborIO).kStructSimple - } else { - fn.fd = (*decoderCborIO).kStruct - } - case reflect.Map: - fn.fd = (*decoderCborIO).kMap - case reflect.Interface: - - fn.fd = (*decoderCborIO).kInterface - default: - - fn.fd = (*decoderCborIO).kErr - } - } - } - return -} -func (e *cborEncDriverIO) EncodeNil() { - e.w.writen1(cborBdNil) -} - -func (e *cborEncDriverIO) EncodeBool(b bool) { - if b { - e.w.writen1(cborBdTrue) - } else { - e.w.writen1(cborBdFalse) - } -} - -func (e *cborEncDriverIO) EncodeFloat32(f float32) { - b := math.Float32bits(f) - if e.h.OptimumSize { - if h := floatToHalfFloatBits(b); halfFloatToFloatBits(h) == b { - e.w.writen1(cborBdFloat16) - e.w.writen2(bigen.PutUint16(h)) - return - } - } - e.w.writen1(cborBdFloat32) - e.w.writen4(bigen.PutUint32(b)) -} - -func (e *cborEncDriverIO) EncodeFloat64(f float64) { - if e.h.OptimumSize { - if f32 := float32(f); float64(f32) == f { - e.EncodeFloat32(f32) - return - } - } - e.w.writen1(cborBdFloat64) - e.w.writen8(bigen.PutUint64(math.Float64bits(f))) -} - -func (e *cborEncDriverIO) encUint(v uint64, bd byte) { - if v <= 0x17 { - e.w.writen1(byte(v) + bd) - } else if v <= math.MaxUint8 { - e.w.writen2(bd+0x18, uint8(v)) - } else if v <= math.MaxUint16 { - e.w.writen1(bd + 0x19) - e.w.writen2(bigen.PutUint16(uint16(v))) - } else if v <= math.MaxUint32 { - e.w.writen1(bd + 0x1a) - e.w.writen4(bigen.PutUint32(uint32(v))) - } else { - e.w.writen1(bd + 0x1b) - e.w.writen8(bigen.PutUint64(v)) - } -} - -func (e *cborEncDriverIO) EncodeInt(v int64) { - if v < 0 { - e.encUint(uint64(-1-v), cborBaseNegInt) - } else { - e.encUint(uint64(v), cborBaseUint) - } -} - -func (e *cborEncDriverIO) EncodeUint(v uint64) { - e.encUint(v, cborBaseUint) -} - -func (e *cborEncDriverIO) encLen(bd byte, length int) { - e.encUint(uint64(length), bd) -} - -func (e *cborEncDriverIO) EncodeTime(t time.Time) { - if t.IsZero() { - e.EncodeNil() - } else if e.h.TimeRFC3339 { - e.encUint(0, cborBaseTag) - e.encStringBytesS(cborBaseString, stringView(t.AppendFormat(e.b[:0], time.RFC3339Nano))) - } else { - e.encUint(1, cborBaseTag) - t = t.UTC().Round(time.Microsecond) - sec, nsec := t.Unix(), uint64(t.Nanosecond()) - if nsec == 0 { - e.EncodeInt(sec) - } else { - e.EncodeFloat64(float64(sec) + float64(nsec)/1e9) - } - } -} - -func (e *cborEncDriverIO) EncodeExt(rv interface{}, basetype reflect.Type, xtag uint64, ext Ext) { - e.encUint(uint64(xtag), cborBaseTag) - if ext == SelfExt { - e.enc.encodeAs(rv, basetype, false) - } else if v := ext.ConvertExt(rv); v == nil { - e.writeNilBytes() - } else { - e.enc.encodeI(v) - } -} - -func (e *cborEncDriverIO) EncodeRawExt(re *RawExt) { - e.encUint(uint64(re.Tag), cborBaseTag) - if re.Data != nil { - e.w.writeb(re.Data) - } else if re.Value != nil { - e.enc.encodeI(re.Value) - } else { - e.EncodeNil() - } -} - -func (e *cborEncDriverIO) WriteArrayEmpty() { - if e.h.IndefiniteLength { - e.w.writen2(cborBdIndefiniteArray, cborBdBreak) - } else { - e.w.writen1(cborBaseArray) - - } -} - -func (e *cborEncDriverIO) WriteMapEmpty() { - if e.h.IndefiniteLength { - e.w.writen2(cborBdIndefiniteMap, cborBdBreak) - } else { - e.w.writen1(cborBaseMap) - - } -} - -func (e *cborEncDriverIO) WriteArrayStart(length int) { - if e.h.IndefiniteLength { - e.w.writen1(cborBdIndefiniteArray) - } else { - e.encLen(cborBaseArray, length) - } -} - -func (e *cborEncDriverIO) WriteMapStart(length int) { - if e.h.IndefiniteLength { - e.w.writen1(cborBdIndefiniteMap) - } else { - e.encLen(cborBaseMap, length) - } -} - -func (e *cborEncDriverIO) WriteMapEnd() { - if e.h.IndefiniteLength { - e.w.writen1(cborBdBreak) - } -} - -func (e *cborEncDriverIO) WriteArrayEnd() { - if e.h.IndefiniteLength { - e.w.writen1(cborBdBreak) - } -} - -func (e *cborEncDriverIO) EncodeString(v string) { - bb := cborBaseString - if e.h.StringToRaw { - bb = cborBaseBytes - } - e.encStringBytesS(bb, v) -} - -func (e *cborEncDriverIO) EncodeStringNoEscape4Json(v string) { e.EncodeString(v) } - -func (e *cborEncDriverIO) EncodeStringBytesRaw(v []byte) { - e.encStringBytesS(cborBaseBytes, stringView(v)) -} - -func (e *cborEncDriverIO) encStringBytesS(bb byte, v string) { - if e.h.IndefiniteLength { - if bb == cborBaseBytes { - e.w.writen1(cborBdIndefiniteBytes) - } else { - e.w.writen1(cborBdIndefiniteString) - } - vlen := uint(len(v)) - n := max(4, min(vlen/4, 1024)) - for i := uint(0); i < vlen; { - i2 := i + n - if i2 >= vlen { - i2 = vlen - } - v2 := v[i:i2] - e.encLen(bb, len(v2)) - e.w.writestr(v2) - i = i2 - } - e.w.writen1(cborBdBreak) - } else { - e.encLen(bb, len(v)) - e.w.writestr(v) - } -} - -func (e *cborEncDriverIO) EncodeBytes(v []byte) { - if v == nil { - e.writeNilBytes() - return - } - e.EncodeStringBytesRaw(v) -} - -func (e *cborEncDriverIO) writeNilOr(v byte) { - if !e.h.NilCollectionToZeroLength { - v = cborBdNil - } - e.w.writen1(v) -} - -func (e *cborEncDriverIO) writeNilArray() { - e.writeNilOr(cborBaseArray) -} - -func (e *cborEncDriverIO) writeNilMap() { - e.writeNilOr(cborBaseMap) -} - -func (e *cborEncDriverIO) writeNilBytes() { - e.writeNilOr(cborBaseBytes) -} - -func (d *cborDecDriverIO) readNextBd() { - d.bd = d.r.readn1() - d.bdRead = true -} - -func (d *cborDecDriverIO) advanceNil() (null bool) { - if !d.bdRead { - d.readNextBd() - } - if d.bd == cborBdNil || d.bd == cborBdUndefined { - d.bdRead = false - return true - } - return -} - -func (d *cborDecDriverIO) TryNil() bool { - return d.advanceNil() -} - -func (d *cborDecDriverIO) skipTags() { - for d.bd>>5 == cborMajorTag { - d.decUint() - d.bd = d.r.readn1() - } -} - -func (d *cborDecDriverIO) ContainerType() (vt valueType) { - if !d.bdRead { - d.readNextBd() - } - if d.h.SkipUnexpectedTags { - d.skipTags() - } - if d.bd == cborBdNil { - d.bdRead = false - return valueTypeNil - } - major := d.bd >> 5 - if major == cborMajorBytes { - return valueTypeBytes - } else if major == cborMajorString { - return valueTypeString - } else if major == cborMajorArray { - return valueTypeArray - } else if major == cborMajorMap { - return valueTypeMap - } - return valueTypeUnset -} - -func (d *cborDecDriverIO) CheckBreak() (v bool) { - if !d.bdRead { - d.readNextBd() - } - if d.bd == cborBdBreak { - d.bdRead = false - v = true - } - return -} - -func (d *cborDecDriverIO) decUint() (ui uint64) { - v := d.bd & 0x1f - if v <= 0x17 { - ui = uint64(v) - } else if v == 0x18 { - ui = uint64(d.r.readn1()) - } else if v == 0x19 { - ui = uint64(bigen.Uint16(d.r.readn2())) - } else if v == 0x1a { - ui = uint64(bigen.Uint32(d.r.readn4())) - } else if v == 0x1b { - ui = uint64(bigen.Uint64(d.r.readn8())) - } else { - halt.errorf("invalid descriptor decoding uint: %x/%s (%x)", d.bd, cbordesc(d.bd), v) - } - return -} - -func (d *cborDecDriverIO) decLen() int { - return int(d.decUint()) -} - -func (d *cborDecDriverIO) decFloat() (f float64, ok bool) { - ok = true - switch d.bd { - case cborBdFloat16: - f = float64(math.Float32frombits(halfFloatToFloatBits(bigen.Uint16(d.r.readn2())))) - case cborBdFloat32: - f = float64(math.Float32frombits(bigen.Uint32(d.r.readn4()))) - case cborBdFloat64: - f = math.Float64frombits(bigen.Uint64(d.r.readn8())) - default: - if d.bd>>5 == cborMajorTag { - - switch d.bd & 0x1f { - case 2: - f = d.decTagBigIntAsFloat(false) - case 3: - f = d.decTagBigIntAsFloat(true) - case 4: - f = d.decTagBigFloatAsFloat(true) - case 5: - f = d.decTagBigFloatAsFloat(false) - default: - ok = false - } - } else { - ok = false - } - } - return -} - -func (d *cborDecDriverIO) decInteger() (ui uint64, neg, ok bool) { - ok = true - switch d.bd >> 5 { - case cborMajorUint: - ui = d.decUint() - case cborMajorNegInt: - ui = d.decUint() - neg = true - default: - ok = false - } - return -} - -func (d *cborDecDriverIO) DecodeInt64() (i int64) { - if d.advanceNil() { - return - } - if d.h.SkipUnexpectedTags { - d.skipTags() - } - v1, v2, v3 := d.decInteger() - i = decNegintPosintFloatNumberHelper{d}.int64(v1, v2, v3, true) - d.bdRead = false - return -} - -func (d *cborDecDriverIO) DecodeUint64() (ui uint64) { - if d.advanceNil() { - return - } - if d.h.SkipUnexpectedTags { - d.skipTags() - } - ui = decNegintPosintFloatNumberHelper{d}.uint64(d.decInteger()) - d.bdRead = false - return -} - -func (d *cborDecDriverIO) DecodeFloat64() (f float64) { - if d.advanceNil() { - return - } - if d.h.SkipUnexpectedTags { - d.skipTags() - } - v1, v2 := d.decFloat() - f = decNegintPosintFloatNumberHelper{d}.float64(v1, v2, true) - d.bdRead = false - return -} - -func (d *cborDecDriverIO) DecodeBool() (b bool) { - if d.advanceNil() { - return - } - if d.h.SkipUnexpectedTags { - d.skipTags() - } - if d.bd == cborBdTrue { - b = true - } else if d.bd == cborBdFalse { - } else { - halt.errorf("not bool - %s %x/%s", msgBadDesc, d.bd, cbordesc(d.bd)) - } - d.bdRead = false - return -} - -func (d *cborDecDriverIO) ReadMapStart() (length int) { - if d.advanceNil() { - return containerLenNil - } - if d.h.SkipUnexpectedTags { - d.skipTags() - } - d.bdRead = false - if d.bd == cborBdIndefiniteMap { - return containerLenUnknown - } - if d.bd>>5 != cborMajorMap { - halt.errorf("error reading map; got major type: %x, expected %x/%s", d.bd>>5, cborMajorMap, cbordesc(d.bd)) - } - return d.decLen() -} - -func (d *cborDecDriverIO) ReadArrayStart() (length int) { - if d.advanceNil() { - return containerLenNil - } - if d.h.SkipUnexpectedTags { - d.skipTags() - } - d.bdRead = false - if d.bd == cborBdIndefiniteArray { - return containerLenUnknown - } - if d.bd>>5 != cborMajorArray { - halt.errorf("invalid array; got major type: %x, expect: %x/%s", d.bd>>5, cborMajorArray, cbordesc(d.bd)) - } - return d.decLen() -} - -func (d *cborDecDriverIO) DecodeBytes() (bs []byte, state dBytesAttachState) { - if d.advanceNil() { - return - } - if d.h.SkipUnexpectedTags { - d.skipTags() - } - fnEnsureNonNilBytes := func() { - - if bs == nil { - bs = zeroByteSlice - state = dBytesDetach - } - } - if d.bd == cborBdIndefiniteBytes || d.bd == cborBdIndefiniteString { - major := d.bd >> 5 - val4str := d.h.ValidateUnicode && major == cborMajorString - bs = d.d.buf[:0] - d.bdRead = false - for !d.CheckBreak() { - if d.bd>>5 != major { - const msg = "malformed indefinite string/bytes %x (%s); " + - "contains chunk with major type %v, expected %v" - halt.errorf(msg, d.bd, cbordesc(d.bd), d.bd>>5, major) - } - n := uint(d.decLen()) - bs = append(bs, d.r.readx(n)...) - d.bdRead = false - if val4str && !utf8.Valid(bs[len(bs)-int(n):]) { - const msg = "indefinite-length text string contains chunk " + - "that is not a valid utf-8 sequence: 0x%x" - halt.errorf(msg, bs[len(bs)-int(n):]) - } - } - d.bdRead = false - d.d.buf = bs - state = dBytesAttachBuffer - fnEnsureNonNilBytes() - return - } - if d.bd == cborBdIndefiniteArray { - d.bdRead = false - bs = d.d.buf[:0] - for !d.CheckBreak() { - bs = append(bs, uint8(chkOvf.UintV(d.DecodeUint64(), 8))) - } - d.d.buf = bs - state = dBytesAttachBuffer - fnEnsureNonNilBytes() - return - } - var cond bool - if d.bd>>5 == cborMajorArray { - d.bdRead = false - slen := d.decLen() - bs, cond = usableByteSlice(d.d.buf, slen) - for i := 0; i < len(bs); i++ { - bs[i] = uint8(chkOvf.UintV(d.DecodeUint64(), 8)) - } - for i := len(bs); i < slen; i++ { - bs = append(bs, uint8(chkOvf.UintV(d.DecodeUint64(), 8))) - } - if cond { - d.d.buf = bs - } - state = dBytesAttachBuffer - fnEnsureNonNilBytes() - return - } - clen := d.decLen() - d.bdRead = false - bs, cond = d.r.readxb(uint(clen)) - state = d.d.attachState(cond) - return -} - -func (d *cborDecDriverIO) DecodeStringAsBytes() (out []byte, state dBytesAttachState) { - out, state = d.DecodeBytes() - if d.h.ValidateUnicode && !utf8.Valid(out) { - halt.errorf("DecodeStringAsBytes: invalid UTF-8: %s", out) - } - return -} - -func (d *cborDecDriverIO) DecodeTime() (t time.Time) { - if d.advanceNil() { - return - } - if d.bd>>5 != cborMajorTag { - halt.errorf("error reading tag; expected major type: %x, got: %x", cborMajorTag, d.bd>>5) - } - xtag := d.decUint() - d.bdRead = false - return d.decodeTime(xtag) -} - -func (d *cborDecDriverIO) decodeTime(xtag uint64) (t time.Time) { - switch xtag { - case 0: - var err error - t, err = time.Parse(time.RFC3339, stringView(bytesOKs(d.DecodeStringAsBytes()))) - halt.onerror(err) - case 1: - f1, f2 := math.Modf(d.DecodeFloat64()) - t = time.Unix(int64(f1), int64(f2*1e9)) - default: - halt.errorf("invalid tag for time.Time - expecting 0 or 1, got 0x%x", xtag) - } - t = t.UTC().Round(time.Microsecond) - return -} - -func (d *cborDecDriverIO) preDecodeExt(checkTag bool, xtag uint64) (realxtag uint64, ok bool) { - if d.advanceNil() { - return - } - if d.bd>>5 != cborMajorTag { - halt.errorf("error reading tag; expected major type: %x, got: %x", cborMajorTag, d.bd>>5) - } - realxtag = d.decUint() - d.bdRead = false - if checkTag && xtag != realxtag { - halt.errorf("Wrong extension tag. Got %b. Expecting: %v", realxtag, xtag) - } - ok = true - return -} - -func (d *cborDecDriverIO) DecodeRawExt(re *RawExt) { - if realxtag, ok := d.preDecodeExt(false, 0); ok { - re.Tag = realxtag - d.dec.decode(&re.Value) - d.bdRead = false - } -} - -func (d *cborDecDriverIO) DecodeExt(rv interface{}, basetype reflect.Type, xtag uint64, ext Ext) { - if _, ok := d.preDecodeExt(true, xtag); ok { - if ext == SelfExt { - d.dec.decodeAs(rv, basetype, false) - } else { - d.dec.interfaceExtConvertAndDecode(rv, ext) - } - d.bdRead = false - } -} - -func (d *cborDecDriverIO) decTagBigIntAsFloat(neg bool) (f float64) { - bs, _ := d.DecodeBytes() - bi := new(big.Int).SetBytes(bs) - if neg { - bi0 := bi - bi = new(big.Int).Sub(big.NewInt(-1), bi0) - } - f, _ = bi.Float64() - return -} - -func (d *cborDecDriverIO) decTagBigFloatAsFloat(decimal bool) (f float64) { - if nn := d.r.readn1(); nn != 82 { - halt.errorf("(%d) decoding decimal/big.Float: expected 2 numbers", nn) - } - exp := d.DecodeInt64() - mant := d.DecodeInt64() - if decimal { - - rf := readFloatResult{exp: int8(exp)} - if mant >= 0 { - rf.mantissa = uint64(mant) - } else { - rf.neg = true - rf.mantissa = uint64(-mant) - } - f, _ = parseFloat64_reader(rf) - - } else { - - bfm := new(big.Float).SetPrec(64).SetInt64(mant) - bf := new(big.Float).SetPrec(64).SetMantExp(bfm, int(exp)) - f, _ = bf.Float64() - } - return -} - -func (d *cborDecDriverIO) DecodeNaked() { - if !d.bdRead { - d.readNextBd() - } - - n := d.d.naked() - var decodeFurther bool - switch d.bd >> 5 { - case cborMajorUint: - if d.h.SignedInteger { - n.v = valueTypeInt - n.i = d.DecodeInt64() - } else { - n.v = valueTypeUint - n.u = d.DecodeUint64() - } - case cborMajorNegInt: - n.v = valueTypeInt - n.i = d.DecodeInt64() - case cborMajorBytes: - d.d.fauxUnionReadRawBytes(d, false, d.h.RawToString) - case cborMajorString: - n.v = valueTypeString - n.s = d.d.detach2Str(d.DecodeStringAsBytes()) - case cborMajorArray: - n.v = valueTypeArray - decodeFurther = true - case cborMajorMap: - n.v = valueTypeMap - decodeFurther = true - case cborMajorTag: - n.v = valueTypeExt - n.u = d.decUint() - d.bdRead = false - n.l = nil - xx := d.h.getExtForTag(n.u) - if xx == nil { - switch n.u { - case 0, 1: - n.v = valueTypeTime - n.t = d.decodeTime(n.u) - case 2: - n.f = d.decTagBigIntAsFloat(false) - n.v = valueTypeFloat - case 3: - n.f = d.decTagBigIntAsFloat(true) - n.v = valueTypeFloat - case 4: - n.f = d.decTagBigFloatAsFloat(true) - n.v = valueTypeFloat - case 5: - n.f = d.decTagBigFloatAsFloat(false) - n.v = valueTypeFloat - case 55799: - d.DecodeNaked() - default: - if d.h.SkipUnexpectedTags { - d.DecodeNaked() - } - - } - return - } - - case cborMajorSimpleOrFloat: - switch d.bd { - case cborBdNil, cborBdUndefined: - n.v = valueTypeNil - case cborBdFalse: - n.v = valueTypeBool - n.b = false - case cborBdTrue: - n.v = valueTypeBool - n.b = true - case cborBdFloat16, cborBdFloat32, cborBdFloat64: - n.v = valueTypeFloat - n.f = d.DecodeFloat64() - default: - halt.errorf("decodeNaked: Unrecognized d.bd: 0x%x", d.bd) - } - default: - halt.errorf("decodeNaked: Unrecognized d.bd: 0x%x", d.bd) - } - if !decodeFurther { - d.bdRead = false - } -} - -func (d *cborDecDriverIO) uintBytes() (v []byte, ui uint64) { - - switch vv := d.bd & 0x1f; vv { - case 0x18: - v = d.r.readx(1) - ui = uint64(v[0]) - case 0x19: - v = d.r.readx(2) - ui = uint64(bigenstd.Uint16(v)) - case 0x1a: - v = d.r.readx(4) - ui = uint64(bigenstd.Uint32(v)) - case 0x1b: - v = d.r.readx(8) - ui = uint64(bigenstd.Uint64(v)) - default: - if vv > 0x1b { - halt.errorf("invalid descriptor decoding uint: %x/%s", d.bd, cbordesc(d.bd)) - } - ui = uint64(vv) - } - return -} - -func (d *cborDecDriverIO) nextValueBytes() (v []byte) { - if !d.bdRead { - d.readNextBd() - } - d.r.startRecording() - d.nextValueBytesBdReadR() - v = d.r.stopRecording() - d.bdRead = false - return -} - -func (d *cborDecDriverIO) nextValueBytesBdReadR() { - - var ui uint64 - - switch d.bd >> 5 { - case cborMajorUint, cborMajorNegInt: - d.uintBytes() - case cborMajorString, cborMajorBytes: - if d.bd == cborBdIndefiniteBytes || d.bd == cborBdIndefiniteString { - for { - d.readNextBd() - if d.bd == cborBdBreak { - break - } - _, ui = d.uintBytes() - d.r.skip(uint(ui)) - } - } else { - _, ui = d.uintBytes() - d.r.skip(uint(ui)) - } - case cborMajorArray: - if d.bd == cborBdIndefiniteArray { - for { - d.readNextBd() - if d.bd == cborBdBreak { - break - } - d.nextValueBytesBdReadR() - } - } else { - _, ui = d.uintBytes() - for i := uint64(0); i < ui; i++ { - d.readNextBd() - d.nextValueBytesBdReadR() - } - } - case cborMajorMap: - if d.bd == cborBdIndefiniteMap { - for { - d.readNextBd() - if d.bd == cborBdBreak { - break - } - d.nextValueBytesBdReadR() - d.readNextBd() - d.nextValueBytesBdReadR() - } - } else { - _, ui = d.uintBytes() - for i := uint64(0); i < ui; i++ { - d.readNextBd() - d.nextValueBytesBdReadR() - d.readNextBd() - d.nextValueBytesBdReadR() - } - } - case cborMajorTag: - d.uintBytes() - d.readNextBd() - d.nextValueBytesBdReadR() - case cborMajorSimpleOrFloat: - switch d.bd { - case cborBdNil, cborBdUndefined, cborBdFalse, cborBdTrue: - case cborBdFloat16: - d.r.skip(2) - case cborBdFloat32: - d.r.skip(4) - case cborBdFloat64: - d.r.skip(8) - default: - halt.errorf("nextValueBytes: Unrecognized d.bd: 0x%x", d.bd) - } - default: - halt.errorf("nextValueBytes: Unrecognized d.bd: 0x%x", d.bd) - } - return -} - -func (d *cborDecDriverIO) reset() { - d.bdAndBdread.reset() - -} - -func (d *cborEncDriverIO) init(hh Handle, shared *encoderBase, enc encoderI) (fp interface{}) { - callMake(&d.w) - d.h = hh.(*CborHandle) - d.e = shared - if shared.bytes { - fp = cborFpEncBytes - } else { - fp = cborFpEncIO - } - - d.init2(enc) - return -} - -func (e *cborEncDriverIO) writeBytesAsis(b []byte) { e.w.writeb(b) } - -func (e *cborEncDriverIO) writerEnd() { e.w.end() } - -func (e *cborEncDriverIO) resetOutBytes(out *[]byte) { - e.w.resetBytes(*out, out) -} - -func (e *cborEncDriverIO) resetOutIO(out io.Writer) { - e.w.resetIO(out, e.h.WriterBufferSize, &e.e.blist) -} - -func (d *cborDecDriverIO) init(hh Handle, shared *decoderBase, dec decoderI) (fp interface{}) { - callMake(&d.r) - d.h = hh.(*CborHandle) - d.d = shared - if shared.bytes { - fp = cborFpDecBytes - } else { - fp = cborFpDecIO - } - - d.init2(dec) - return -} - -func (d *cborDecDriverIO) NumBytesRead() int { - return int(d.r.numread()) -} - -func (d *cborDecDriverIO) resetInBytes(in []byte) { - d.r.resetBytes(in) -} - -func (d *cborDecDriverIO) resetInIO(r io.Reader) { - d.r.resetIO(r, d.h.ReaderBufferSize, d.h.MaxInitLen, &d.d.blist) -} - -func (d *cborDecDriverIO) descBd() string { - return sprintf("%v (%s)", d.bd, cbordesc(d.bd)) -} - -func (d *cborDecDriverIO) DecodeFloat32() (f float32) { - return float32(chkOvf.Float32V(d.DecodeFloat64())) -} - -func (d *cborEncDriverIO) init2(enc encoderI) { - d.enc = enc -} - -func (d *cborDecDriverIO) init2(dec decoderI) { - d.dec = dec - -} diff --git a/vendor/github.com/ugorji/go/codec/cbor.notfastpath.mono.generated.go b/vendor/github.com/ugorji/go/codec/cbor.notfastpath.mono.generated.go deleted file mode 100644 index 9ae1be245..000000000 --- a/vendor/github.com/ugorji/go/codec/cbor.notfastpath.mono.generated.go +++ /dev/null @@ -1,52 +0,0 @@ -//go:build !notmono && !codec.notmono && (notfastpath || codec.notfastpath) - -// Copyright (c) 2012-2020 Ugorji Nwoke. All rights reserved. -// Use of this source code is governed by a MIT license found in the LICENSE file. - -package codec - -import ( - "reflect" -) - -type fastpathECborBytes struct { - rt reflect.Type - encfn func(*encoderCborBytes, *encFnInfo, reflect.Value) -} -type fastpathDCborBytes struct { - rt reflect.Type - decfn func(*decoderCborBytes, *decFnInfo, reflect.Value) -} -type fastpathEsCborBytes [0]fastpathECborBytes -type fastpathDsCborBytes [0]fastpathDCborBytes - -func (helperEncDriverCborBytes) fastpathEncodeTypeSwitch(iv interface{}, e *encoderCborBytes) bool { - return false -} -func (helperDecDriverCborBytes) fastpathDecodeTypeSwitch(iv interface{}, d *decoderCborBytes) bool { - return false -} - -func (helperEncDriverCborBytes) fastpathEList() (v *fastpathEsCborBytes) { return } -func (helperDecDriverCborBytes) fastpathDList() (v *fastpathDsCborBytes) { return } - -type fastpathECborIO struct { - rt reflect.Type - encfn func(*encoderCborIO, *encFnInfo, reflect.Value) -} -type fastpathDCborIO struct { - rt reflect.Type - decfn func(*decoderCborIO, *decFnInfo, reflect.Value) -} -type fastpathEsCborIO [0]fastpathECborIO -type fastpathDsCborIO [0]fastpathDCborIO - -func (helperEncDriverCborIO) fastpathEncodeTypeSwitch(iv interface{}, e *encoderCborIO) bool { - return false -} -func (helperDecDriverCborIO) fastpathDecodeTypeSwitch(iv interface{}, d *decoderCborIO) bool { - return false -} - -func (helperEncDriverCborIO) fastpathEList() (v *fastpathEsCborIO) { return } -func (helperDecDriverCborIO) fastpathDList() (v *fastpathDsCborIO) { return } diff --git a/vendor/github.com/ugorji/go/codec/custom_time.go b/vendor/github.com/ugorji/go/codec/custom_time.go deleted file mode 100644 index c6d9e9676..000000000 --- a/vendor/github.com/ugorji/go/codec/custom_time.go +++ /dev/null @@ -1,191 +0,0 @@ -// Copyright (c) 2012-2020 Ugorji Nwoke. All rights reserved. -// Use of this source code is governed by a MIT license found in the LICENSE file. - -package codec - -import ( - "math" - "time" -) - -// EncodeTime encodes a time.Time as a []byte, including -// information on the instant in time and UTC offset. -// -// Format Description -// -// A timestamp is composed of 3 components: -// -// - secs: signed integer representing seconds since unix epoch -// - nsces: unsigned integer representing fractional seconds as a -// nanosecond offset within secs, in the range 0 <= nsecs < 1e9 -// - tz: signed integer representing timezone offset in minutes east of UTC, -// and a dst (daylight savings time) flag -// -// When encoding a timestamp, the first byte is the descriptor, which -// defines which components are encoded and how many bytes are used to -// encode secs and nsecs components. *If secs/nsecs is 0 or tz is UTC, it -// is not encoded in the byte array explicitly*. -// -// Descriptor 8 bits are of the form `A B C DDD EE`: -// A: Is secs component encoded? 1 = true -// B: Is nsecs component encoded? 1 = true -// C: Is tz component encoded? 1 = true -// DDD: Number of extra bytes for secs (range 0-7). -// If A = 1, secs encoded in DDD+1 bytes. -// If A = 0, secs is not encoded, and is assumed to be 0. -// If A = 1, then we need at least 1 byte to encode secs. -// DDD says the number of extra bytes beyond that 1. -// E.g. if DDD=0, then secs is represented in 1 byte. -// if DDD=2, then secs is represented in 3 bytes. -// EE: Number of extra bytes for nsecs (range 0-3). -// If B = 1, nsecs encoded in EE+1 bytes (similar to secs/DDD above) -// -// Following the descriptor bytes, subsequent bytes are: -// -// secs component encoded in `DDD + 1` bytes (if A == 1) -// nsecs component encoded in `EE + 1` bytes (if B == 1) -// tz component encoded in 2 bytes (if C == 1) -// -// secs and nsecs components are integers encoded in a BigEndian -// 2-complement encoding format. -// -// tz component is encoded as 2 bytes (16 bits). Most significant bit 15 to -// Least significant bit 0 are described below: -// -// Timezone offset has a range of -12:00 to +14:00 (ie -720 to +840 minutes). -// Bit 15 = have\_dst: set to 1 if we set the dst flag. -// Bit 14 = dst\_on: set to 1 if dst is in effect at the time, or 0 if not. -// Bits 13..0 = timezone offset in minutes. It is a signed integer in Big Endian format. -func customEncodeTime(t time.Time) []byte { - // t := rv2i(rv).(time.Time) - tsecs, tnsecs := t.Unix(), t.Nanosecond() - var ( - bd byte - bs [16]byte - i int = 1 - ) - l := t.Location() - if l == time.UTC { - l = nil - } - if tsecs != 0 { - bd = bd | 0x80 - btmp := bigen.PutUint64(uint64(tsecs)) - f := pruneSignExt(btmp[:], tsecs >= 0) - bd = bd | (byte(7-f) << 2) - copy(bs[i:], btmp[f:]) - i = i + (8 - f) - } - if tnsecs != 0 { - bd = bd | 0x40 - btmp := bigen.PutUint32(uint32(tnsecs)) - f := pruneSignExt(btmp[:4], true) - bd = bd | byte(3-f) - copy(bs[i:], btmp[f:4]) - i = i + (4 - f) - } - if l != nil { - bd = bd | 0x20 - // Note that Go Libs do not give access to dst flag. - _, zoneOffset := t.Zone() - // zoneName, zoneOffset := t.Zone() - zoneOffset /= 60 - z := uint16(zoneOffset) - btmp0, btmp1 := bigen.PutUint16(z) - // clear dst flags - bs[i] = btmp0 & 0x3f - bs[i+1] = btmp1 - i = i + 2 - } - bs[0] = bd - return bs[0:i] -} - -// customDecodeTime decodes a []byte into a time.Time. -func customDecodeTime(bs []byte) (tt time.Time, err error) { - bd := bs[0] - var ( - tsec int64 - tnsec uint32 - tz uint16 - i byte = 1 - i2 byte - n byte - ) - if bd&(1<<7) != 0 { - var btmp [8]byte - n = ((bd >> 2) & 0x7) + 1 - i2 = i + n - copy(btmp[8-n:], bs[i:i2]) - // if first bit of bs[i] is set, then fill btmp[0..8-n] with 0xff (ie sign extend it) - if bs[i]&(1<<7) != 0 { - copy(btmp[0:8-n], bsAll0xff) - } - i = i2 - tsec = int64(bigen.Uint64(btmp)) - } - if bd&(1<<6) != 0 { - var btmp [4]byte - n = (bd & 0x3) + 1 - i2 = i + n - copy(btmp[4-n:], bs[i:i2]) - i = i2 - tnsec = bigen.Uint32(btmp) - } - if bd&(1<<5) == 0 { - tt = time.Unix(tsec, int64(tnsec)).UTC() - return - } - // In stdlib time.Parse, when a date is parsed without a zone name, it uses "" as zone name. - // However, we need name here, so it can be shown when time is printf.d. - // Zone name is in form: UTC-08:00. - // Note that Go Libs do not give access to dst flag, so we ignore dst bits - - tz = bigen.Uint16([2]byte{bs[i], bs[i+1]}) - // sign extend sign bit into top 2 MSB (which were dst bits): - if tz&(1<<13) == 0 { // positive - tz = tz & 0x3fff //clear 2 MSBs: dst bits - } else { // negative - tz = tz | 0xc000 //set 2 MSBs: dst bits - } - tzint := int16(tz) - if tzint == 0 { - tt = time.Unix(tsec, int64(tnsec)).UTC() - } else { - // For Go Time, do not use a descriptive timezone. - // It's unnecessary, and makes it harder to do a reflect.DeepEqual. - // The Offset already tells what the offset should be, if not on UTC and unknown zone name. - // var zoneName = timeLocUTCName(tzint) - tt = time.Unix(tsec, int64(tnsec)).In(time.FixedZone("", int(tzint)*60)) - } - return -} - -// customEncodeTimeAsNum encodes time.Time exactly as cbor does. -func customEncodeTimeAsNum(t time.Time) (r interface{}) { - t = t.UTC().Round(time.Microsecond) - sec, nsec := t.Unix(), uint64(t.Nanosecond()) - if nsec == 0 { - r = sec - } else { - r = float64(sec) + float64(nsec)/1e9 - } - return r -} - -// customDecodeTimeAsNum decodes time.Time exactly as cbor does. -func customDecodeTimeAsNum(v interface{}) (t time.Time) { - switch vv := v.(type) { - case int64: - t = time.Unix(vv, 0) - case uint64: - t = time.Unix((int64)(vv), 0) - case float64: - f1, f2 := math.Modf(vv) - t = time.Unix(int64(f1), int64(f2*1e9)) - default: - halt.errorf("expect int64/float64 for time.Time ext: got %T", v) - } - t = t.UTC().Round(time.Microsecond) - return -} diff --git a/vendor/github.com/ugorji/go/codec/decimal.go b/vendor/github.com/ugorji/go/codec/decimal.go deleted file mode 100644 index 0c74726b3..000000000 --- a/vendor/github.com/ugorji/go/codec/decimal.go +++ /dev/null @@ -1,513 +0,0 @@ -// Copyright (c) 2012-2020 Ugorji Nwoke. All rights reserved. -// Use of this source code is governed by a MIT license found in the LICENSE file. - -package codec - -import ( - "math" - "strconv" -) - -type readFloatResult struct { - mantissa uint64 - exp int8 - neg bool - trunc bool - bad bool // bad decimal string - hardexp bool // exponent is hard to handle (> 2 digits, etc) - ok bool - // sawdot bool - // sawexp bool - //_ [2]bool // padding -} - -// Per go spec, floats are represented in memory as -// IEEE single or double precision floating point values. -// -// We also looked at the source for stdlib math/modf.go, -// reviewed https://github.com/chewxy/math32 -// and read wikipedia documents describing the formats. -// -// It became clear that we could easily look at the bits to determine -// whether any fraction exists. - -func parseFloat32(b []byte) (f float32, err error) { - return parseFloat32_custom(b) -} - -func parseFloat64(b []byte) (f float64, err error) { - return parseFloat64_custom(b) -} - -func parseFloat32_strconv(b []byte) (f float32, err error) { - f64, err := strconv.ParseFloat(stringView(b), 32) - f = float32(f64) - return -} - -func parseFloat64_strconv(b []byte) (f float64, err error) { - return strconv.ParseFloat(stringView(b), 64) -} - -// ------ parseFloat custom below -------- - -// JSON really supports decimal numbers in base 10 notation, with exponent support. -// -// We assume the following: -// - a lot of floating point numbers in json files will have defined precision -// (in terms of number of digits after decimal point), etc. -// - these (referenced above) can be written in exact format. -// -// strconv.ParseFloat has some unnecessary overhead which we can do without -// for the common case: -// -// - expensive char-by-char check to see if underscores are in right place -// - testing for and skipping underscores -// - check if the string matches ignorecase +/- inf, +/- infinity, nan -// - support for base 16 (0xFFFF...) -// -// The functions below will try a fast-path for floats which can be decoded -// without any loss of precision, meaning they: -// -// - fits within the significand bits of the 32-bits or 64-bits -// - exponent fits within the exponent value -// - there is no truncation (any extra numbers are all trailing zeros) -// -// To figure out what the values are for maxMantDigits, use this idea below: -// -// 2^23 = 838 8608 (between 10^ 6 and 10^ 7) (significand bits of uint32) -// 2^32 = 42 9496 7296 (between 10^ 9 and 10^10) (full uint32) -// 2^52 = 4503 5996 2737 0496 (between 10^15 and 10^16) (significand bits of uint64) -// 2^64 = 1844 6744 0737 0955 1616 (between 10^19 and 10^20) (full uint64) -// -// Note: we only allow for up to what can comfortably fit into the significand -// ignoring the exponent, and we only try to parse iff significand fits. - -const ( - fMaxMultiplierForExactPow10_64 = 1e15 - fMaxMultiplierForExactPow10_32 = 1e7 - - fUint64Cutoff = (1<<64-1)/10 + 1 - // fUint32Cutoff = (1<<32-1)/10 + 1 - - fBase = 10 -) - -const ( - thousand = 1000 - million = thousand * thousand - billion = thousand * million - trillion = thousand * billion - quadrillion = thousand * trillion - quintillion = thousand * quadrillion -) - -// Exact powers of 10. -var uint64pow10 = [...]uint64{ - 1, 10, 100, - 1 * thousand, 10 * thousand, 100 * thousand, - 1 * million, 10 * million, 100 * million, - 1 * billion, 10 * billion, 100 * billion, - 1 * trillion, 10 * trillion, 100 * trillion, - 1 * quadrillion, 10 * quadrillion, 100 * quadrillion, - 1 * quintillion, 10 * quintillion, -} -var float64pow10 = [...]float64{ - 1e0, 1e1, 1e2, 1e3, 1e4, 1e5, 1e6, 1e7, 1e8, 1e9, - 1e10, 1e11, 1e12, 1e13, 1e14, 1e15, 1e16, 1e17, 1e18, 1e19, - 1e20, 1e21, 1e22, -} -var float32pow10 = [...]float32{ - 1e0, 1e1, 1e2, 1e3, 1e4, 1e5, 1e6, 1e7, 1e8, 1e9, 1e10, -} - -type floatinfo struct { - mantbits uint8 - - // expbits uint8 // (unused) - // bias int16 // (unused) - // is32bit bool // (unused) - - exactPow10 int8 // Exact powers of ten are <= 10^N (32: 10, 64: 22) - - exactInts int8 // Exact integers are <= 10^N (for non-float, set to 0) - - // maxMantDigits int8 // 10^19 fits in uint64, while 10^9 fits in uint32 - - mantCutoffIsUint64Cutoff bool - - mantCutoff uint64 -} - -var fi32 = floatinfo{23, 10, 7, false, 1<<23 - 1} -var fi64 = floatinfo{52, 22, 15, false, 1<<52 - 1} - -var fi64u = floatinfo{0, 19, 0, true, fUint64Cutoff} - -func noFrac64(fbits uint64) bool { - if fbits == 0 { - return true - } - - exp := uint64(fbits>>52)&0x7FF - 1023 // uint(x>>shift)&mask - bias - // clear top 12+e bits, the integer part; if the rest is 0, then no fraction. - return exp < 52 && fbits<<(12+exp) == 0 // means there's no fractional part -} - -func noFrac32(fbits uint32) bool { - if fbits == 0 { - return true - } - - exp := uint32(fbits>>23)&0xFF - 127 // uint(x>>shift)&mask - bias - // clear top 9+e bits, the integer part; if the rest is 0, then no fraction. - return exp < 23 && fbits<<(9+exp) == 0 // means there's no fractional part -} - -func strconvParseErr(b []byte, fn string) error { - return &strconv.NumError{ - Func: fn, - Err: strconv.ErrSyntax, - Num: string(b), - } -} - -func parseFloat32_reader(r readFloatResult) (f float32, fail bool) { - f = float32(r.mantissa) - if r.exp == 0 { - } else if r.exp < 0 { // int / 10^k - f /= float32pow10[uint8(-r.exp)] - } else { // exp > 0 - if r.exp > fi32.exactPow10 { - f *= float32pow10[r.exp-fi32.exactPow10] - if f > fMaxMultiplierForExactPow10_32 { // exponent too large - outside range - fail = true - return // ok = false - } - f *= float32pow10[fi32.exactPow10] - } else { - f *= float32pow10[uint8(r.exp)] - } - } - if r.neg { - f = -f - } - return -} - -func parseFloat32_custom(b []byte) (f float32, err error) { - r := readFloat(b, fi32) - if r.bad { - return 0, strconvParseErr(b, "ParseFloat") - } - if r.ok { - f, r.bad = parseFloat32_reader(r) - if !r.bad { - return - } - } - return parseFloat32_strconv(b) -} - -func parseFloat64_reader(r readFloatResult) (f float64, fail bool) { - f = float64(r.mantissa) - if r.exp == 0 { - } else if r.exp < 0 { // int / 10^k - f /= float64pow10[-uint8(r.exp)] - } else { // exp > 0 - if r.exp > fi64.exactPow10 { - f *= float64pow10[r.exp-fi64.exactPow10] - if f > fMaxMultiplierForExactPow10_64 { // exponent too large - outside range - fail = true - return - } - f *= float64pow10[fi64.exactPow10] - } else { - f *= float64pow10[uint8(r.exp)] - } - } - if r.neg { - f = -f - } - return -} - -func parseFloat64_custom(b []byte) (f float64, err error) { - r := readFloat(b, fi64) - if r.bad { - return 0, strconvParseErr(b, "ParseFloat") - } - if r.ok { - f, r.bad = parseFloat64_reader(r) - if !r.bad { - return - } - } - return parseFloat64_strconv(b) -} - -func parseUint64_simple(b []byte) (n uint64, ok bool) { - if len(b) > 1 && b[0] == '0' { // punt on numbers with leading zeros - return - } - - var i int - var n1 uint64 - var c uint8 -LOOP: - if i < len(b) { - c = b[i] - // unsigned integers don't overflow well on multiplication, so check cutoff here - // e.g. (maxUint64-5)*10 doesn't overflow well ... - // if n >= fUint64Cutoff || !isDigitChar(b[i]) { // if c < '0' || c > '9' { - if n >= fUint64Cutoff || c < '0' || c > '9' { - return - } else if c == '0' { - n *= fBase - } else { - n1 = n - n = n*fBase + uint64(c-'0') - if n < n1 { - return - } - } - i++ - goto LOOP - } - ok = true - return -} - -func parseUint64_reader(r readFloatResult) (f uint64, fail bool) { - f = r.mantissa - if r.exp == 0 { - } else if r.exp < 0 { // int / 10^k - if f%uint64pow10[uint8(-r.exp)] != 0 { - fail = true - } else { - f /= uint64pow10[uint8(-r.exp)] - } - } else { // exp > 0 - f *= uint64pow10[uint8(r.exp)] - } - return -} - -func parseInteger_bytes(b []byte) (u uint64, neg, ok bool) { - if len(b) == 0 { - ok = true - return - } - if b[0] == '-' { - if len(b) == 1 { - return - } - neg = true - b = b[1:] - } - - u, ok = parseUint64_simple(b) - if ok { - return - } - - r := readFloat(b, fi64u) - if r.ok { - var fail bool - u, fail = parseUint64_reader(r) - if fail { - f, err := parseFloat64(b) - if err != nil { - return - } - if !noFrac64(math.Float64bits(f)) { - return - } - u = uint64(f) - } - ok = true - return - } - return -} - -// parseNumber will return an integer if only composed of [-]?[0-9]+ -// Else it will return a float. -func parseNumber(b []byte, z *fauxUnion, preferSignedInt bool) (err error) { - var ok, neg bool - var f uint64 - - if len(b) == 0 { - return - } - - if b[0] == '-' { - neg = true - f, ok = parseUint64_simple(b[1:]) - } else { - f, ok = parseUint64_simple(b) - } - - if ok { - if neg { - z.v = valueTypeInt - if chkOvf.Uint2Int(f, neg) { - return strconvParseErr(b, "ParseInt") - } - z.i = -int64(f) - } else if preferSignedInt { - z.v = valueTypeInt - if chkOvf.Uint2Int(f, neg) { - return strconvParseErr(b, "ParseInt") - } - z.i = int64(f) - } else { - z.v = valueTypeUint - z.u = f - } - return - } - - z.v = valueTypeFloat - z.f, err = parseFloat64_custom(b) - return -} - -func readFloat(s []byte, y floatinfo) (r readFloatResult) { - var i uint // uint, so that we eliminate bounds checking - var slen = uint(len(s)) - if slen == 0 { - // read an empty string as the zero value - // r.bad = true - r.ok = true - return - } - - if s[0] == '-' { - r.neg = true - i++ - } - - // considered punting early if string has length > maxMantDigits, but doesn't account - // for trailing 0's e.g. 700000000000000000000 can be encoded exactly as it is 7e20 - - var nd, ndMant, dp int8 - var sawdot, sawexp bool - var xu uint64 - - if i+1 < slen && s[i] == '0' { - switch s[i+1] { - case '.', 'e', 'E': - // ok - default: - r.bad = true - return - } - } - -LOOP: - for ; i < slen; i++ { - switch s[i] { - case '.': - if sawdot { - r.bad = true - return - } - sawdot = true - dp = nd - case 'e', 'E': - sawexp = true - break LOOP - case '0': - if nd == 0 { - dp-- - continue LOOP - } - nd++ - if r.mantissa < y.mantCutoff { - r.mantissa *= fBase - ndMant++ - } - case '1', '2', '3', '4', '5', '6', '7', '8', '9': - nd++ - if y.mantCutoffIsUint64Cutoff && r.mantissa < fUint64Cutoff { - r.mantissa *= fBase - xu = r.mantissa + uint64(s[i]-'0') - if xu < r.mantissa { - r.trunc = true - return - } - r.mantissa = xu - } else if r.mantissa < y.mantCutoff { - // mantissa = (mantissa << 1) + (mantissa << 3) + uint64(c-'0') - r.mantissa = r.mantissa*fBase + uint64(s[i]-'0') - } else { - r.trunc = true - return - } - ndMant++ - default: - r.bad = true - return - } - } - - if !sawdot { - dp = nd - } - - if sawexp { - i++ - if i < slen { - var eneg bool - if s[i] == '+' { - i++ - } else if s[i] == '-' { - i++ - eneg = true - } - if i < slen { - // for exact match, exponent is 1 or 2 digits (float64: -22 to 37, float32: -1 to 17). - // exit quick if exponent is more than 2 digits. - if i+2 < slen { - r.hardexp = true - return - } - var e int8 - if s[i] < '0' || s[i] > '9' { // !isDigitChar(s[i]) { // - r.bad = true - return - } - e = int8(s[i] - '0') - i++ - if i < slen { - if s[i] < '0' || s[i] > '9' { // !isDigitChar(s[i]) { // - r.bad = true - return - } - e = e*fBase + int8(s[i]-'0') // (e << 1) + (e << 3) + int8(s[i]-'0') - i++ - } - if eneg { - dp -= e - } else { - dp += e - } - } - } - } - - if r.mantissa != 0 { - r.exp = dp - ndMant - // do not set ok=true for cases we cannot handle - if r.exp < -y.exactPow10 || - r.exp > y.exactInts+y.exactPow10 || - (y.mantbits != 0 && r.mantissa>>y.mantbits != 0) { - r.hardexp = true - return - } - } - - r.ok = true - return -} diff --git a/vendor/github.com/ugorji/go/codec/decode.base.go b/vendor/github.com/ugorji/go/codec/decode.base.go deleted file mode 100644 index e82f40252..000000000 --- a/vendor/github.com/ugorji/go/codec/decode.base.go +++ /dev/null @@ -1,944 +0,0 @@ -// Copyright (c) 2012-2020 Ugorji Nwoke. All rights reserved. -// Use of this source code is governed by a MIT license found in the LICENSE file. - -package codec - -import ( - "errors" - "io" - "math" - "reflect" - "slices" - "sync" - "time" -) - -func init() { - for _, v := range []interface{}{ - (*string)(nil), - (*bool)(nil), - (*int)(nil), - (*int8)(nil), - (*int16)(nil), - (*int32)(nil), - (*int64)(nil), - (*uint)(nil), - (*uint8)(nil), - (*uint16)(nil), - (*uint32)(nil), - (*uint64)(nil), - (*uintptr)(nil), - (*float32)(nil), - (*float64)(nil), - (*complex64)(nil), - (*complex128)(nil), - (*[]byte)(nil), - ([]byte)(nil), - (*time.Time)(nil), - (*Raw)(nil), - (*interface{})(nil), - } { - decBuiltinRtids = append(decBuiltinRtids, i2rtid(v)) - } - slices.Sort(decBuiltinRtids) -} - -const msgBadDesc = "unrecognized descriptor byte" - -var decBuiltinRtids []uintptr - -// decDriver calls (DecodeBytes and DecodeStringAsBytes) return a state -// of the view they return, allowing consumers to handle appropriately. -// -// sequencing of this is intentional: -// - mutable if <= dBytesAttachBuffer (buf | view | invalid) -// - noCopy if >= dBytesAttachViewZerocopy -type dBytesAttachState uint8 - -const ( - dBytesAttachInvalid dBytesAttachState = iota - dBytesAttachView // (bytes && !zerocopy && !buf) - dBytesAttachBuffer // (buf) - dBytesAttachViewZerocopy // (bytes && zerocopy && !buf) - dBytesDetach // (!bytes && !buf) -) - -type dBytesIntoState uint8 - -const ( - dBytesIntoNoChange dBytesIntoState = iota - dBytesIntoParamOut - dBytesIntoParamOutSlice - dBytesIntoNew -) - -func (x dBytesAttachState) String() string { - switch x { - case dBytesAttachInvalid: - return "invalid" - case dBytesAttachView: - return "view" - case dBytesAttachBuffer: - return "buffer" - case dBytesAttachViewZerocopy: - return "view-zerocopy" - case dBytesDetach: - return "detach" - } - return "unknown" -} - -const ( - decDefMaxDepth = 1024 // maximum depth - decDefChanCap = 64 // should be large, as cap cannot be expanded - decScratchByteArrayLen = (4 + 3) * 8 // around cacheLineSize ie ~64, depending on Decoder size - - // MARKER: massage decScratchByteArrayLen to ensure xxxDecDriver structs fit within cacheLine*N - - // decFailNonEmptyIntf configures whether we error - // when decoding naked into a non-empty interface. - // - // Typically, we cannot decode non-nil stream value into - // nil interface with methods (e.g. io.Reader). - // However, in some scenarios, this should be allowed: - // - MapType - // - SliceType - // - Extensions - // - // Consequently, we should relax this. Put it behind a const flag for now. - decFailNonEmptyIntf = false - - // decUseTransient says whether we should use the transient optimization. - // - // There's potential for GC corruption or memory overwrites if transient isn't - // used carefully, so this flag helps turn it off quickly if needed. - // - // Use it everywhere needed so we can completely remove unused code blocks. - decUseTransient = true -) - -var ( - errNeedMapOrArrayDecodeToStruct = errors.New("only encoded map or array can decode into struct") - errCannotDecodeIntoNil = errors.New("cannot decode into nil") - - errExpandSliceCannotChange = errors.New("expand slice: cannot change") - - errDecoderNotInitialized = errors.New("Decoder not initialized") - - errDecUnreadByteNothingToRead = errors.New("cannot unread - nothing has been read") - errDecUnreadByteLastByteNotRead = errors.New("cannot unread - last byte has not been read") - errDecUnreadByteUnknown = errors.New("cannot unread - reason unknown") - errMaxDepthExceeded = errors.New("maximum decoding depth exceeded") -) - -type decNotDecodeableReason uint8 - -const ( - decNotDecodeableReasonUnknown decNotDecodeableReason = iota - decNotDecodeableReasonBadKind - decNotDecodeableReasonNonAddrValue - decNotDecodeableReasonNilReference -) - -type decDriverI interface { - - // this will check if the next token is a break. - CheckBreak() bool - - // TryNil tries to decode as nil. - // If a nil is in the stream, it consumes it and returns true. - // - // Note: if TryNil returns true, that must be handled. - TryNil() bool - - // ContainerType returns one of: Bytes, String, Nil, Slice or Map. - // - // Return unSet if not known. - // - // Note: Implementations MUST fully consume sentinel container types, specifically Nil. - ContainerType() (vt valueType) - - // DecodeNaked will decode primitives (number, bool, string, []byte) and RawExt. - // For maps and arrays, it will not do the decoding in-band, but will signal - // the decoder, so that is done later, by setting the fauxUnion.valueType field. - // - // Note: Numbers are decoded as int64, uint64, float64 only (no smaller sized number types). - // for extensions, DecodeNaked must read the tag and the []byte if it exists. - // if the []byte is not read, then kInterfaceNaked will treat it as a Handle - // that stores the subsequent value in-band, and complete reading the RawExt. - // - // extensions should also use readx to decode them, for efficiency. - // kInterface will extract the detached byte slice if it has to pass it outside its realm. - DecodeNaked() - - DecodeInt64() (i int64) - DecodeUint64() (ui uint64) - - DecodeFloat32() (f float32) - DecodeFloat64() (f float64) - - DecodeBool() (b bool) - - // DecodeStringAsBytes returns the bytes representing a string. - // It will return a view into scratch buffer or input []byte (if applicable). - // - // Note: This can also decode symbols, if supported. - // - // Users should consume it right away and not store it for later use. - DecodeStringAsBytes() (v []byte, state dBytesAttachState) - - // DecodeBytes returns the bytes representing a binary value. - // It will return a view into scratch buffer or input []byte (if applicable). - DecodeBytes() (out []byte, state dBytesAttachState) - // DecodeBytes(bs []byte, isstring, zerocopy bool) (bsOut []byte) - - // DecodeExt will decode into an extension. - // ext is never nil. - DecodeExt(v interface{}, basetype reflect.Type, xtag uint64, ext Ext) - // decodeExt(verifyTag bool, tag byte) (xtag byte, xbs []byte) - - // DecodeRawExt will decode into a *RawExt - DecodeRawExt(re *RawExt) - - DecodeTime() (t time.Time) - - // ReadArrayStart will return the length of the array. - // If the format doesn't prefix the length, it returns containerLenUnknown. - // If the expected array was a nil in the stream, it returns containerLenNil. - ReadArrayStart() int - - // ReadMapStart will return the length of the array. - // If the format doesn't prefix the length, it returns containerLenUnknown. - // If the expected array was a nil in the stream, it returns containerLenNil. - ReadMapStart() int - - decDriverContainerTracker - - reset() - - // atEndOfDecode() - - // nextValueBytes will return the bytes representing the next value in the stream. - // It generally will include the last byte read, as that is a part of the next value - // in the stream. - nextValueBytes() []byte - - // descBd will describe the token descriptor that signifies what type was decoded - descBd() string - - // isBytes() bool - - resetInBytes(in []byte) - resetInIO(r io.Reader) - - NumBytesRead() int - - init(h Handle, shared *decoderBase, dec decoderI) (fp interface{}) - - // driverStateManager - decNegintPosintFloatNumber -} - -type decInit2er struct{} - -func (decInit2er) init2(dec decoderI) {} - -type decDriverContainerTracker interface { - ReadArrayElem(firstTime bool) - ReadMapElemKey(firstTime bool) - ReadMapElemValue() - ReadArrayEnd() - ReadMapEnd() -} - -type decNegintPosintFloatNumber interface { - decInteger() (ui uint64, neg, ok bool) - decFloat() (f float64, ok bool) -} - -type decDriverNoopNumberHelper struct{} - -func (x decDriverNoopNumberHelper) decInteger() (ui uint64, neg, ok bool) { - panic("decInteger unsupported") -} -func (x decDriverNoopNumberHelper) decFloat() (f float64, ok bool) { panic("decFloat unsupported") } - -type decDriverNoopContainerReader struct{} - -func (x decDriverNoopContainerReader) ReadArrayStart() (v int) { panic("ReadArrayStart unsupported") } -func (x decDriverNoopContainerReader) ReadMapStart() (v int) { panic("ReadMapStart unsupported") } -func (x decDriverNoopContainerReader) ReadArrayEnd() {} -func (x decDriverNoopContainerReader) ReadMapEnd() {} -func (x decDriverNoopContainerReader) ReadArrayElem(firstTime bool) {} -func (x decDriverNoopContainerReader) ReadMapElemKey(firstTime bool) {} -func (x decDriverNoopContainerReader) ReadMapElemValue() {} -func (x decDriverNoopContainerReader) CheckBreak() (v bool) { return } - -// ---- - -type decFnInfo struct { - ti *typeInfo - xfFn Ext - xfTag uint64 - addrD bool // decoding into a pointer is preferred - addrDf bool // force: if addrD, then decode function MUST take a ptr -} - -// DecodeOptions captures configuration options during decode. -type DecodeOptions struct { - // MapType specifies type to use during schema-less decoding of a map in the stream. - // If nil (unset), we default to map[string]interface{} iff json handle and MapKeyAsString=true, - // else map[interface{}]interface{}. - MapType reflect.Type - - // SliceType specifies type to use during schema-less decoding of an array in the stream. - // If nil (unset), we default to []interface{} for all formats. - SliceType reflect.Type - - // MaxInitLen defines the maxinum initial length that we "make" a collection - // (string, slice, map, chan). If 0 or negative, we default to a sensible value - // based on the size of an element in the collection. - // - // For example, when decoding, a stream may say that it has 2^64 elements. - // We should not auto-matically provision a slice of that size, to prevent Out-Of-Memory crash. - // Instead, we provision up to MaxInitLen, fill that up, and start appending after that. - MaxInitLen int - - // ReaderBufferSize is the size of the buffer used when reading. - // - // if > 0, we use a smart buffer internally for performance purposes. - ReaderBufferSize int - - // MaxDepth defines the maximum depth when decoding nested - // maps and slices. If 0 or negative, we default to a suitably large number (currently 1024). - MaxDepth int16 - - // If ErrorIfNoField, return an error when decoding a map - // from a codec stream into a struct, and no matching struct field is found. - ErrorIfNoField bool - - // If ErrorIfNoArrayExpand, return an error when decoding a slice/array that cannot be expanded. - // For example, the stream contains an array of 8 items, but you are decoding into a [4]T array, - // or you are decoding into a slice of length 4 which is non-addressable (and so cannot be set). - ErrorIfNoArrayExpand bool - - // If SignedInteger, use the int64 during schema-less decoding of unsigned values (not uint64). - SignedInteger bool - - // MapValueReset controls how we decode into a map value. - // - // By default, we MAY retrieve the mapping for a key, and then decode into that. - // However, especially with big maps, that retrieval may be expensive and unnecessary - // if the stream already contains all that is necessary to recreate the value. - // - // If true, we will never retrieve the previous mapping, - // but rather decode into a new value and set that in the map. - // - // If false, we will retrieve the previous mapping if necessary e.g. - // the previous mapping is a pointer, or is a struct or array with pre-set state, - // or is an interface. - MapValueReset bool - - // SliceElementReset: on decoding a slice, reset the element to a zero value first. - // - // concern: if the slice already contained some garbage, we will decode into that garbage. - SliceElementReset bool - - // InterfaceReset controls how we decode into an interface. - // - // By default, when we see a field that is an interface{...}, - // or a map with interface{...} value, we will attempt decoding into the - // "contained" value. - // - // However, this prevents us from reading a string into an interface{} - // that formerly contained a number. - // - // If true, we will decode into a new "blank" value, and set that in the interface. - // If false, we will decode into whatever is contained in the interface. - InterfaceReset bool - - // InternString controls interning of strings during decoding. - // - // Some handles, e.g. json, typically will read map keys as strings. - // If the set of keys are finite, it may help reduce allocation to - // look them up from a map (than to allocate them afresh). - // - // Note: Handles will be smart when using the intern functionality. - // Every string should not be interned. - // An excellent use-case for interning is struct field names, - // or map keys where key type is string. - InternString bool - - // PreferArrayOverSlice controls whether to decode to an array or a slice. - // - // This only impacts decoding into a nil interface{}. - // - // Consequently, it has no effect on codecgen. - // - // *Note*: This only applies if using go1.5 and above, - // as it requires reflect.ArrayOf support which was absent before go1.5. - PreferArrayOverSlice bool - - // DeleteOnNilMapValue controls how to decode a nil value in the stream. - // - // If true, we will delete the mapping of the key. - // Else, just set the mapping to the zero value of the type. - // - // Deprecated: This does NOTHING and is left behind for compiling compatibility. - // This change is necessitated because 'nil' in a stream now consistently - // means the zero value (ie reset the value to its zero state). - DeleteOnNilMapValue bool - - // RawToString controls how raw bytes in a stream are decoded into a nil interface{}. - // By default, they are decoded as []byte, but can be decoded as string (if configured). - RawToString bool - - // ZeroCopy controls whether decoded values of []byte or string type - // point into the input []byte parameter passed to a NewDecoderBytes/ResetBytes(...) call. - // - // To illustrate, if ZeroCopy and decoding from a []byte (not io.Writer), - // then a []byte or string in the output result may just be a slice of (point into) - // the input bytes. - // - // This optimization prevents unnecessary copying. - // - // However, it is made optional, as the caller MUST ensure that the input parameter []byte is - // not modified after the Decode() happens, as any changes are mirrored in the decoded result. - ZeroCopy bool - - // PreferPointerForStructOrArray controls whether a struct or array - // is stored in a nil interface{}, or a pointer to it. - // - // This mostly impacts when we decode registered extensions. - PreferPointerForStructOrArray bool - - // ValidateUnicode controls will cause decoding to fail if an expected unicode - // string is well-formed but include invalid codepoints. - // - // This could have a performance impact. - ValidateUnicode bool -} - -// ---------------------------------------- - -type decoderBase struct { - perType decPerType - - h *BasicHandle - - rtidFn, rtidFnNoExt *atomicRtidFnSlice - - buf []byte - - // used for interning strings - is internerMap - - err error - - // sd decoderI - - blist bytesFreeList - - mtr bool // is maptype a known type? - str bool // is slicetype a known type? - jsms bool // is json handle, and MapKeyAsString - - bytes bool // uses a bytes reader - bufio bool // uses a ioDecReader with buffer size > 0 - - // ---- cpu cache line boundary? - // ---- writable fields during execution --- *try* to keep in sep cache line - maxdepth int16 - depth int16 - - // Extensions can call Decode() within a current Decode() call. - // We need to know when the top level Decode() call returns, - // so we can decide whether to Release() or not. - calls uint16 // what depth in mustDecode are we in now. - - c containerState - - // decByteState - - n fauxUnion - - // b is an always-available scratch buffer used by Decoder and decDrivers. - // By being always-available, it can be used for one-off things without - // having to get from freelist, use, and return back to freelist. - // - // Use it for a narrow set of things e.g. - // - binc uses it for parsing numbers, represented at 8 or less bytes - // - uses as potential buffer for struct field names - b [decScratchByteArrayLen]byte - - hh Handle - // cache the mapTypeId and sliceTypeId for faster comparisons - mtid uintptr - stid uintptr -} - -func (d *decoderBase) maxInitLen() uint { - return uint(max(1024, d.h.MaxInitLen)) -} - -func (d *decoderBase) naked() *fauxUnion { - return &d.n -} - -func (d *decoderBase) fauxUnionReadRawBytes(dr decDriverI, asString, rawToString bool) { //, handleZeroCopy bool) { - // fauxUnion is only used within DecodeNaked calls; consequently, we should try to intern. - d.n.l, d.n.a = dr.DecodeBytes() - if asString || rawToString { - d.n.v = valueTypeString - d.n.s = d.detach2Str(d.n.l, d.n.a) - } else { - d.n.v = valueTypeBytes - d.n.l = d.detach2Bytes(d.n.l, d.n.a) - } -} - -// Return a fixed (detached) string representation of a []byte. -// -// Possibly get an interned version of a string, -// iff InternString=true and decoding a map key. -// -// This should mostly be used for map keys, struct field names, etc -// where the key type is string. This is because keys of a map/struct are -// typically reused across many objects. -func (d *decoderBase) detach2Str(v []byte, state dBytesAttachState) (s string) { - // note: string([]byte) checks - and optimizes - for len 0 and len 1 - if len(v) <= 1 { - s = string(v) - } else if state >= dBytesAttachViewZerocopy { // !scratchBuf && d.bytes && d.h.ZeroCopy - s = stringView(v) - } else if d.is == nil || d.c != containerMapKey || len(v) > internMaxStrLen { - s = string(v) - } else { - s = d.is.string(v) - } - return -} - -func (d *decoderBase) usableStructFieldNameBytes(buf, v []byte, state dBytesAttachState) (out []byte) { - // In JSON, mapElemValue reads a colon and spaces. - // In bufio mode of ioDecReader, fillbuf could overwrite the read buffer - // which readXXX() calls return sub-slices from. - // - // Consequently, we detach the bytes in this special case. - // - // Note: ioDecReader (non-bufio) and bytesDecReader do not have - // this issue (as no fillbuf exists where bytes might be returned from). - if d.bufio && d.h.jsonHandle && state < dBytesAttachViewZerocopy { - if cap(buf) > len(v) { - out = buf[:len(v)] - } else if len(d.b) > len(v) { - out = d.b[:len(v)] - } else { - out = make([]byte, len(v), max(64, len(v))) - } - copy(out, v) - return - } - return v -} - -func (d *decoderBase) detach2Bytes(in []byte, state dBytesAttachState) (out []byte) { - if cap(in) == 0 || state >= dBytesAttachViewZerocopy { - return in - } - if len(in) == 0 { - return zeroByteSlice - } - out = make([]byte, len(in)) - copy(out, in) - return out -} - -func (d *decoderBase) attachState(usingBufFromReader bool) (r dBytesAttachState) { - if usingBufFromReader { - r = dBytesAttachBuffer - } else if !d.bytes { - r = dBytesDetach - } else if d.h.ZeroCopy { - r = dBytesAttachViewZerocopy - } else { - r = dBytesAttachView - } - return -} - -func (d *decoderBase) mapStart(v int) int { - if v != containerLenNil { - d.depthIncr() - d.c = containerMapStart - } - return v -} - -func (d *decoderBase) HandleName() string { - return d.hh.Name() -} - -func (d *decoderBase) isBytes() bool { - return d.bytes -} - -type decoderI interface { - Decode(v interface{}) (err error) - HandleName() string - MustDecode(v interface{}) - NumBytesRead() int - Release() // deprecated - Reset(r io.Reader) - ResetBytes(in []byte) - ResetString(s string) - - isBytes() bool - wrapErr(v error, err *error) - swallow() - - nextValueBytes() []byte // wrapper method, for use in tests - // getDecDriver() decDriverI - - decode(v interface{}) - decodeAs(v interface{}, t reflect.Type, ext bool) - - interfaceExtConvertAndDecode(v interface{}, ext InterfaceExt) -} - -var errDecNoResetBytesWithReader = errors.New("cannot reset an Decoder reading from []byte with a io.Reader") -var errDecNoResetReaderWithBytes = errors.New("cannot reset an Decoder reading from io.Reader with a []byte") - -func setZero(iv interface{}) { - rv, isnil := isNil(iv, false) - if isnil { - return - } - if !rv.IsValid() { - rv = reflect.ValueOf(iv) - } - if isnilBitset.isset(byte(rv.Kind())) && rvIsNil(rv) { - return - } - // var canDecode bool - switch v := iv.(type) { - case *string: - *v = "" - case *bool: - *v = false - case *int: - *v = 0 - case *int8: - *v = 0 - case *int16: - *v = 0 - case *int32: - *v = 0 - case *int64: - *v = 0 - case *uint: - *v = 0 - case *uint8: - *v = 0 - case *uint16: - *v = 0 - case *uint32: - *v = 0 - case *uint64: - *v = 0 - case *float32: - *v = 0 - case *float64: - *v = 0 - case *complex64: - *v = 0 - case *complex128: - *v = 0 - case *[]byte: - *v = nil - case *Raw: - *v = nil - case *time.Time: - *v = time.Time{} - case reflect.Value: - decSetNonNilRV2Zero(v) - default: - if !fastpathDecodeSetZeroTypeSwitch(iv) { - decSetNonNilRV2Zero(rv) - } - } -} - -// decSetNonNilRV2Zero will set the non-nil value to its zero value. -func decSetNonNilRV2Zero(v reflect.Value) { - // If not decodeable (settable), we do not touch it. - // We considered empty'ing it if not decodeable e.g. - // - if chan, drain it - // - if map, clear it - // - if slice or array, zero all elements up to len - // - // However, we decided instead that we either will set the - // whole value to the zero value, or leave AS IS. - - k := v.Kind() - if k == reflect.Interface { - decSetNonNilRV2Zero4Intf(v) - } else if k == reflect.Ptr { - decSetNonNilRV2Zero4Ptr(v) - } else if v.CanSet() { - rvSetDirectZero(v) - } -} - -func decSetNonNilRV2Zero4Ptr(v reflect.Value) { - ve := v.Elem() - if ve.CanSet() { - rvSetZero(ve) // we can have a pointer to an interface - } else if v.CanSet() { - rvSetZero(v) - } -} - -func decSetNonNilRV2Zero4Intf(v reflect.Value) { - ve := v.Elem() - if ve.CanSet() { - rvSetDirectZero(ve) // interfaces always have element as a non-interface - } else if v.CanSet() { - rvSetZero(v) - } -} - -func (d *decoderBase) arrayCannotExpand(sliceLen, streamLen int) { - if d.h.ErrorIfNoArrayExpand { - halt.errorf("cannot expand array len during decode from %v to %v", any(sliceLen), any(streamLen)) - } -} - -//go:noinline -func (d *decoderBase) haltAsNotDecodeable(rv reflect.Value) { - if !rv.IsValid() { - halt.onerror(errCannotDecodeIntoNil) - } - // check if an interface can be retrieved, before grabbing an interface - if !rv.CanInterface() { - halt.errorf("cannot decode into a value without an interface: %v", rv) - } - halt.errorf("cannot decode into value of kind: %v, %#v", rv.Kind(), rv2i(rv)) -} - -func (d *decoderBase) depthIncr() { - d.depth++ - if d.depth >= d.maxdepth { - halt.onerror(errMaxDepthExceeded) - } -} - -func (d *decoderBase) depthDecr() { - d.depth-- -} - -func (d *decoderBase) arrayStart(v int) int { - if v != containerLenNil { - d.depthIncr() - d.c = containerArrayStart - } - return v -} - -func (d *decoderBase) oneShotAddrRV(rvt reflect.Type, rvk reflect.Kind) reflect.Value { - // MARKER 2025: is this slow for calling oneShot? - if decUseTransient && d.h.getTypeInfo4RT(baseRT(rvt)).flagCanTransient { - return d.perType.TransientAddrK(rvt, rvk) - } - return rvZeroAddrK(rvt, rvk) -} - -// decNegintPosintFloatNumberHelper is used for formats that are binary -// and have distinct ways of storing positive integers vs negative integers -// vs floats, which are uniquely identified by the byte descriptor. -// -// Currently, these formats are binc, cbor and simple. -type decNegintPosintFloatNumberHelper struct { - d decDriverI -} - -func (x decNegintPosintFloatNumberHelper) uint64(ui uint64, neg, ok bool) uint64 { - if ok && !neg { - return ui - } - return x.uint64TryFloat(ok) -} - -func (x decNegintPosintFloatNumberHelper) uint64TryFloat(neg bool) (ui uint64) { - if neg { // neg = true - halt.errorStr("assigning negative signed value to unsigned type") - } - f, ok := x.d.decFloat() - if !(ok && f >= 0 && noFrac64(math.Float64bits(f))) { - halt.errorStr2("invalid number loading uint64, with descriptor: ", x.d.descBd()) - } - return uint64(f) -} - -func (x decNegintPosintFloatNumberHelper) int64(ui uint64, neg, ok, cbor bool) (i int64) { - if ok { - return decNegintPosintFloatNumberHelperInt64v(ui, neg, cbor) - } - // return x.int64TryFloat() - // } - // func (x decNegintPosintFloatNumberHelper) int64TryFloat() (i int64) { - f, ok := x.d.decFloat() - if !(ok && noFrac64(math.Float64bits(f))) { - halt.errorf("invalid number loading uint64 (%v), with descriptor: %s", f, x.d.descBd()) - } - return int64(f) -} - -func (x decNegintPosintFloatNumberHelper) float64(f float64, ok, cbor bool) float64 { - if ok { - return f - } - return x.float64TryInteger(cbor) -} - -func (x decNegintPosintFloatNumberHelper) float64TryInteger(cbor bool) float64 { - ui, neg, ok := x.d.decInteger() - if !ok { - halt.errorStr2("invalid descriptor for float: ", x.d.descBd()) - } - return float64(decNegintPosintFloatNumberHelperInt64v(ui, neg, cbor)) -} - -func decNegintPosintFloatNumberHelperInt64v(ui uint64, neg, incrIfNeg bool) (i int64) { - if neg && incrIfNeg { - ui++ - } - i = chkOvf.SignedIntV(ui) - if neg { - i = -i - } - return -} - -// isDecodeable checks if value can be decoded into -// -// decode can take any reflect.Value that is a inherently addressable i.e. -// - non-nil chan (we will SEND to it) -// - non-nil slice (we will set its elements) -// - non-nil map (we will put into it) -// - non-nil pointer (we can "update" it) -// - func: no -// - interface: no -// - array: if canAddr=true -// - any other value pointer: if canAddr=true -func isDecodeable(rv reflect.Value) (canDecode bool, reason decNotDecodeableReason) { - switch rv.Kind() { - case reflect.Ptr, reflect.Slice, reflect.Chan, reflect.Map: - canDecode = !rvIsNil(rv) - reason = decNotDecodeableReasonNilReference - case reflect.Func, reflect.Interface, reflect.Invalid, reflect.UnsafePointer: - reason = decNotDecodeableReasonBadKind - default: - canDecode = rv.CanAddr() - reason = decNotDecodeableReasonNonAddrValue - } - return -} - -// decInferLen will infer a sensible length, given the following: -// - clen: length wanted. -// - maxlen: max length to be returned. -// if <= 0, it is unset, and we infer it based on the unit size -// - unit: number of bytes for each element of the collection -func decInferLen(clen int, maxlen, unit uint) (n uint) { - // anecdotal testing showed increase in allocation with map length of 16. - // We saw same typical alloc from 0-8, then a 20% increase at 16. - // Thus, we set it to 8. - - const ( - minLenIfUnset = 8 - maxMem = 1024 * 1024 // 1 MB Memory - ) - - // handle when maxlen is not set i.e. <= 0 - - // clen==0: use 0 - // maxlen<=0, clen<0: use default - // maxlen> 0, clen<0: use default - // maxlen<=0, clen>0: infer maxlen, and cap on it - // maxlen> 0, clen>0: cap at maxlen - - if clen == 0 || clen == containerLenNil { - return 0 - } - if clen < 0 { - // if unspecified, return 64 for bytes, ... 8 for uint64, ... and everything else - return max(64/unit, minLenIfUnset) - } - if unit == 0 { - return uint(clen) - } - if maxlen == 0 { - maxlen = maxMem / unit - } - return min(uint(clen), maxlen) -} - -type Decoder struct { - decoderI -} - -// NewDecoder returns a Decoder for decoding a stream of bytes from an io.Reader. -// -// For efficiency, Users are encouraged to configure ReaderBufferSize on the handle -// OR pass in a memory buffered reader (eg bufio.Reader, bytes.Buffer). -func NewDecoder(r io.Reader, h Handle) *Decoder { - return &Decoder{h.newDecoder(r)} -} - -// NewDecoderBytes returns a Decoder which efficiently decodes directly -// from a byte slice with zero copying. -func NewDecoderBytes(in []byte, h Handle) *Decoder { - return &Decoder{h.newDecoderBytes(in)} -} - -// NewDecoderString returns a Decoder which efficiently decodes directly -// from a string with zero copying. -// -// It is a convenience function that calls NewDecoderBytes with a -// []byte view into the string. -// -// This can be an efficient zero-copy if using default mode i.e. without codec.safe tag. -func NewDecoderString(s string, h Handle) *Decoder { - return NewDecoderBytes(bytesView(s), h) -} - -// ---- - -func sideDecode(h Handle, p *sync.Pool, fn func(decoderI)) { - var s decoderI - if usePoolForSideDecode { - s = p.Get().(decoderI) - defer p.Put(s) - } else { - // initialization cycle error - // s = NewDecoderBytes(nil, h).decoderI - s = p.New().(decoderI) - } - fn(s) -} - -func oneOffDecode(sd decoderI, v interface{}, in []byte, basetype reflect.Type, ext bool) { - sd.ResetBytes(in) - sd.decodeAs(v, basetype, ext) - // d.sideDecoder(xbs) - // d.sideDecode(rv, basetype) -} - -func bytesOKdbi(v []byte, _ dBytesIntoState) []byte { - return v -} - -func bytesOKs(bs []byte, _ dBytesAttachState) []byte { - return bs -} diff --git a/vendor/github.com/ugorji/go/codec/decode.go b/vendor/github.com/ugorji/go/codec/decode.go deleted file mode 100644 index eedea89ee..000000000 --- a/vendor/github.com/ugorji/go/codec/decode.go +++ /dev/null @@ -1,1961 +0,0 @@ -//go:build notmono || codec.notmono - -// Copyright (c) 2012-2020 Ugorji Nwoke. All rights reserved. -// Use of this source code is governed by a MIT license found in the LICENSE file. - -package codec - -import ( - "encoding" - "io" - "reflect" - "strconv" - "sync" - "time" -) - -type helperDecDriver[T decDriver] struct{} - -// decFn encapsulates the captured variables and the encode function. -// This way, we only do some calculations one times, and pass to the -// code block that should be called (encapsulated in a function) -// instead of executing the checks every time. -type decFn[T decDriver] struct { - i decFnInfo - fd func(*decoder[T], *decFnInfo, reflect.Value) - // _ [1]uint64 // padding (cache-aligned) -} - -type decRtidFn[T decDriver] struct { - rtid uintptr - fn *decFn[T] -} - -// ---- - -// Decoder reads and decodes an object from an input stream in a supported format. -// -// Decoder is NOT safe for concurrent use i.e. a Decoder cannot be used -// concurrently in multiple goroutines. -// -// However, as Decoder could be allocation heavy to initialize, a Reset method is provided -// so its state can be reused to decode new input streams repeatedly. -// This is the idiomatic way to use. -type decoder[T decDriver] struct { - dh helperDecDriver[T] - fp *fastpathDs[T] - d T - decoderBase -} - -func (d *decoder[T]) rawExt(f *decFnInfo, rv reflect.Value) { - d.d.DecodeRawExt(rv2i(rv).(*RawExt)) -} - -func (d *decoder[T]) ext(f *decFnInfo, rv reflect.Value) { - d.d.DecodeExt(rv2i(rv), f.ti.rt, f.xfTag, f.xfFn) -} - -func (d *decoder[T]) selferUnmarshal(_ *decFnInfo, rv reflect.Value) { - rv2i(rv).(Selfer).CodecDecodeSelf(&Decoder{d}) -} - -func (d *decoder[T]) binaryUnmarshal(_ *decFnInfo, rv reflect.Value) { - bm := rv2i(rv).(encoding.BinaryUnmarshaler) - xbs, _ := d.d.DecodeBytes() - fnerr := bm.UnmarshalBinary(xbs) - halt.onerror(fnerr) -} - -func (d *decoder[T]) textUnmarshal(_ *decFnInfo, rv reflect.Value) { - tm := rv2i(rv).(encoding.TextUnmarshaler) - fnerr := tm.UnmarshalText(bytesOKs(d.d.DecodeStringAsBytes())) - halt.onerror(fnerr) -} - -func (d *decoder[T]) jsonUnmarshal(_ *decFnInfo, rv reflect.Value) { - d.jsonUnmarshalV(rv2i(rv).(jsonUnmarshaler)) -} - -func (d *decoder[T]) jsonUnmarshalV(tm jsonUnmarshaler) { - // grab the bytes to be read, as UnmarshalJSON needs the full JSON so as to unmarshal it itself. - halt.onerror(tm.UnmarshalJSON(d.d.nextValueBytes())) -} - -func (d *decoder[T]) kErr(_ *decFnInfo, rv reflect.Value) { - halt.errorf("unsupported decoding kind: %s, for %#v", rv.Kind(), rv) - // halt.errorStr2("no decoding function defined for kind: ", rv.Kind().String()) -} - -func (d *decoder[T]) raw(_ *decFnInfo, rv reflect.Value) { - rvSetBytes(rv, d.rawBytes()) -} - -func (d *decoder[T]) kString(_ *decFnInfo, rv reflect.Value) { - rvSetString(rv, d.detach2Str(d.d.DecodeStringAsBytes())) -} - -func (d *decoder[T]) kBool(_ *decFnInfo, rv reflect.Value) { - rvSetBool(rv, d.d.DecodeBool()) -} - -func (d *decoder[T]) kTime(_ *decFnInfo, rv reflect.Value) { - rvSetTime(rv, d.d.DecodeTime()) -} - -func (d *decoder[T]) kFloat32(_ *decFnInfo, rv reflect.Value) { - rvSetFloat32(rv, d.d.DecodeFloat32()) -} - -func (d *decoder[T]) kFloat64(_ *decFnInfo, rv reflect.Value) { - rvSetFloat64(rv, d.d.DecodeFloat64()) -} - -func (d *decoder[T]) kComplex64(_ *decFnInfo, rv reflect.Value) { - rvSetComplex64(rv, complex(d.d.DecodeFloat32(), 0)) -} - -func (d *decoder[T]) kComplex128(_ *decFnInfo, rv reflect.Value) { - rvSetComplex128(rv, complex(d.d.DecodeFloat64(), 0)) -} - -func (d *decoder[T]) kInt(_ *decFnInfo, rv reflect.Value) { - rvSetInt(rv, int(chkOvf.IntV(d.d.DecodeInt64(), intBitsize))) -} - -func (d *decoder[T]) kInt8(_ *decFnInfo, rv reflect.Value) { - rvSetInt8(rv, int8(chkOvf.IntV(d.d.DecodeInt64(), 8))) -} - -func (d *decoder[T]) kInt16(_ *decFnInfo, rv reflect.Value) { - rvSetInt16(rv, int16(chkOvf.IntV(d.d.DecodeInt64(), 16))) -} - -func (d *decoder[T]) kInt32(_ *decFnInfo, rv reflect.Value) { - rvSetInt32(rv, int32(chkOvf.IntV(d.d.DecodeInt64(), 32))) -} - -func (d *decoder[T]) kInt64(_ *decFnInfo, rv reflect.Value) { - rvSetInt64(rv, d.d.DecodeInt64()) -} - -func (d *decoder[T]) kUint(_ *decFnInfo, rv reflect.Value) { - rvSetUint(rv, uint(chkOvf.UintV(d.d.DecodeUint64(), uintBitsize))) -} - -func (d *decoder[T]) kUintptr(_ *decFnInfo, rv reflect.Value) { - rvSetUintptr(rv, uintptr(chkOvf.UintV(d.d.DecodeUint64(), uintBitsize))) -} - -func (d *decoder[T]) kUint8(_ *decFnInfo, rv reflect.Value) { - rvSetUint8(rv, uint8(chkOvf.UintV(d.d.DecodeUint64(), 8))) -} - -func (d *decoder[T]) kUint16(_ *decFnInfo, rv reflect.Value) { - rvSetUint16(rv, uint16(chkOvf.UintV(d.d.DecodeUint64(), 16))) -} - -func (d *decoder[T]) kUint32(_ *decFnInfo, rv reflect.Value) { - rvSetUint32(rv, uint32(chkOvf.UintV(d.d.DecodeUint64(), 32))) -} - -func (d *decoder[T]) kUint64(_ *decFnInfo, rv reflect.Value) { - rvSetUint64(rv, d.d.DecodeUint64()) -} - -func (d *decoder[T]) kInterfaceNaked(f *decFnInfo) (rvn reflect.Value) { - // nil interface: - // use some hieristics to decode it appropriately - // based on the detected next value in the stream. - n := d.naked() - d.d.DecodeNaked() - - // We cannot decode non-nil stream value into nil interface with methods (e.g. io.Reader). - // Howver, it is possible that the user has ways to pass in a type for a given interface - // - MapType - // - SliceType - // - Extensions - // - // Consequently, we should relax this. Put it behind a const flag for now. - if decFailNonEmptyIntf && f.ti.numMeth > 0 { - halt.errorf("cannot decode non-nil codec value into nil %v (%v methods)", f.ti.rt, f.ti.numMeth) - } - - // We generally make a pointer to the container here, and pass along, - // so that they will be initialized later when we know the length of the collection. - - switch n.v { - case valueTypeMap: - mtid := d.mtid - if mtid == 0 { - if d.jsms { // if json, default to a map type with string keys - mtid = mapStrIntfTypId // for json performance - } else { - mtid = mapIntfIntfTypId - } - } - if mtid == mapStrIntfTypId { - var v2 map[string]interface{} - d.decode(&v2) - rvn = rv4iptr(&v2).Elem() - } else if mtid == mapIntfIntfTypId { - var v2 map[interface{}]interface{} - d.decode(&v2) - rvn = rv4iptr(&v2).Elem() - } else if d.mtr { - rvn = reflect.New(d.h.MapType) - d.decode(rv2i(rvn)) - rvn = rvn.Elem() - } else { - // // made map is fully initialized for direct modification. - // // There's no need to make a pointer to it first. - // rvn = makeMapReflect(d.h.MapType, 0) - rvn = rvZeroAddrK(d.h.MapType, reflect.Map) - d.decodeValue(rvn, nil) - } - case valueTypeArray: - if d.stid == 0 || d.stid == intfSliceTypId { - var v2 []interface{} - d.decode(&v2) - rvn = rv4iptr(&v2).Elem() - } else if d.str { - rvn = reflect.New(d.h.SliceType) - d.decode(rv2i(rvn)) - rvn = rvn.Elem() - } else { - rvn = rvZeroAddrK(d.h.SliceType, reflect.Slice) - d.decodeValue(rvn, nil) - } - if d.h.PreferArrayOverSlice { - rvn = rvGetArray4Slice(rvn) - } - case valueTypeExt: - tag, bytes := n.u, n.l // calling decode below might taint the values - bfn := d.h.getExtForTag(tag) - var re = RawExt{Tag: tag} - if bytes == nil { - // one of the InterfaceExt ones: json and cbor. - // (likely cbor, as json has no tagging support and won't reveal valueTypeExt) - if bfn == nil { - d.decode(&re.Value) - rvn = rv4iptr(&re).Elem() - } else if bfn.ext == SelfExt { - rvn = rvZeroAddrK(bfn.rt, bfn.rt.Kind()) - d.decodeValue(rvn, d.fnNoExt(bfn.rt)) - } else { - rvn = reflect.New(bfn.rt) - d.interfaceExtConvertAndDecode(rv2i(rvn), bfn.ext) - rvn = rvn.Elem() - } - } else { - // one of the BytesExt ones: binc, msgpack, simple - if bfn == nil { - re.setData(bytes, false) - rvn = rv4iptr(&re).Elem() - } else { - rvn = reflect.New(bfn.rt) - if bfn.ext == SelfExt { - sideDecode(d.hh, &d.h.sideDecPool, func(sd decoderI) { oneOffDecode(sd, rv2i(rvn), bytes, bfn.rt, true) }) - } else { - bfn.ext.ReadExt(rv2i(rvn), bytes) - } - rvn = rvn.Elem() - } - } - // if struct/array, directly store pointer into the interface - if d.h.PreferPointerForStructOrArray && rvn.CanAddr() { - if rk := rvn.Kind(); rk == reflect.Array || rk == reflect.Struct { - rvn = rvn.Addr() - } - } - case valueTypeNil: - // rvn = reflect.Zero(f.ti.rt) - // no-op - case valueTypeInt: - rvn = n.ri() - case valueTypeUint: - rvn = n.ru() - case valueTypeFloat: - rvn = n.rf() - case valueTypeBool: - rvn = n.rb() - case valueTypeString, valueTypeSymbol: - rvn = n.rs() - case valueTypeBytes: - rvn = n.rl() - case valueTypeTime: - rvn = n.rt() - default: - halt.errorStr2("kInterfaceNaked: unexpected valueType: ", n.v.String()) - } - return -} - -func (d *decoder[T]) kInterface(f *decFnInfo, rv reflect.Value) { - // Note: A consequence of how kInterface works, is that - // if an interface already contains something, we try - // to decode into what was there before. - // We do not replace with a generic value (as got from decodeNaked). - // - // every interface passed here MUST be settable. - // - // ensure you call rvSetIntf(...) before returning. - - isnilrv := rvIsNil(rv) - - var rvn reflect.Value - - if d.h.InterfaceReset { - // check if mapping to a type: if so, initialize it and move on - rvn = d.h.intf2impl(f.ti.rtid) - if !rvn.IsValid() { - rvn = d.kInterfaceNaked(f) - if rvn.IsValid() { - rvSetIntf(rv, rvn) - } else if !isnilrv { - decSetNonNilRV2Zero4Intf(rv) - } - return - } - } else if isnilrv { - // check if mapping to a type: if so, initialize it and move on - rvn = d.h.intf2impl(f.ti.rtid) - if !rvn.IsValid() { - rvn = d.kInterfaceNaked(f) - if rvn.IsValid() { - rvSetIntf(rv, rvn) - } - return - } - } else { - // now we have a non-nil interface value, meaning it contains a type - rvn = rv.Elem() - } - - // rvn is now a non-interface type - - canDecode, _ := isDecodeable(rvn) - - // Note: interface{} is settable, but underlying type may not be. - // Consequently, we MAY have to allocate a value (containing the underlying value), - // decode into it, and reset the interface to that new value. - - if !canDecode { - rvn2 := d.oneShotAddrRV(rvn.Type(), rvn.Kind()) - rvSetDirect(rvn2, rvn) - rvn = rvn2 - } - - d.decodeValue(rvn, nil) - rvSetIntf(rv, rvn) -} - -func (d *decoder[T]) kStructField(si *structFieldInfo, rv reflect.Value) { - if d.d.TryNil() { - rv = si.fieldNoAlloc(rv, true) - if rv.IsValid() { - decSetNonNilRV2Zero(rv) - } - } else if si.decBuiltin { - rv = rvAddr(si.fieldAlloc(rv), si.ptrTyp) - d.decode(rv2i(rv)) - } else { - fn := d.fn(si.baseTyp) - rv = si.fieldAlloc(rv) - if fn.i.addrD { - rv = rvAddr(rv, si.ptrTyp) - } - fn.fd(d, &fn.i, rv) - } -} - -func (d *decoder[T]) kStructSimple(f *decFnInfo, rv reflect.Value) { - _ = d.d // early asserts d, d.d are not nil once - ctyp := d.d.ContainerType() - ti := f.ti - if ctyp == valueTypeMap { - containerLen := d.mapStart(d.d.ReadMapStart()) - if containerLen == 0 { - d.mapEnd() - return - } - hasLen := containerLen >= 0 - var rvkencname []byte - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - sab, att := d.d.DecodeStringAsBytes() - rvkencname = d.usableStructFieldNameBytes(rvkencname, sab, att) - d.mapElemValue() - if si := ti.siForEncName(rvkencname); si != nil { - d.kStructField(si, rv) - } else { - d.structFieldNotFound(-1, stringView(rvkencname)) - } - } - d.mapEnd() - } else if ctyp == valueTypeArray { - containerLen := d.arrayStart(d.d.ReadArrayStart()) - if containerLen == 0 { - d.arrayEnd() - return - } - // Not much gain from doing it two ways for array (used less frequently than structs). - tisfi := ti.sfi.source() - hasLen := containerLen >= 0 - - // iterate all the items in the stream. - // - if mapped elem-wise to a field, handle it - // - if more stream items than can be mapped, error it - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.arrayElem(j == 0) - if j < len(tisfi) { - d.kStructField(tisfi[j], rv) - } else { - d.structFieldNotFound(j, "") - } - } - d.arrayEnd() - } else { - halt.onerror(errNeedMapOrArrayDecodeToStruct) - } -} - -func (d *decoder[T]) kStruct(f *decFnInfo, rv reflect.Value) { - _ = d.d // early asserts d, d.d are not nil once - ctyp := d.d.ContainerType() - ti := f.ti - var mf MissingFielder - if ti.flagMissingFielder { - mf = rv2i(rv).(MissingFielder) - } else if ti.flagMissingFielderPtr { - mf = rv2i(rvAddr(rv, ti.ptr)).(MissingFielder) - } - if ctyp == valueTypeMap { - containerLen := d.mapStart(d.d.ReadMapStart()) - if containerLen == 0 { - d.mapEnd() - return - } - hasLen := containerLen >= 0 - var name2 []byte - var rvkencname []byte - tkt := ti.keyType - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - // use if-else since <8 branches and we need good branch prediction for string - if tkt == valueTypeString { - sab, att := d.d.DecodeStringAsBytes() - rvkencname = d.usableStructFieldNameBytes(rvkencname, sab, att) - } else if tkt == valueTypeInt { - rvkencname = strconv.AppendInt(d.b[:0], d.d.DecodeInt64(), 10) - } else if tkt == valueTypeUint { - rvkencname = strconv.AppendUint(d.b[:0], d.d.DecodeUint64(), 10) - } else if tkt == valueTypeFloat { - rvkencname = strconv.AppendFloat(d.b[:0], d.d.DecodeFloat64(), 'f', -1, 64) - } else { - halt.errorStr2("invalid struct key type: ", ti.keyType.String()) - } - - d.mapElemValue() - if si := ti.siForEncName(rvkencname); si != nil { - d.kStructField(si, rv) - } else if mf != nil { - // store rvkencname in new []byte, as it previously shares Decoder.b, which is used in decode - name2 = append(name2[:0], rvkencname...) - var f interface{} - d.decode(&f) - if !mf.CodecMissingField(name2, f) && d.h.ErrorIfNoField { - halt.errorStr2("no matching struct field when decoding stream map with key: ", stringView(name2)) - } - } else { - d.structFieldNotFound(-1, stringView(rvkencname)) - } - } - d.mapEnd() - } else if ctyp == valueTypeArray { - containerLen := d.arrayStart(d.d.ReadArrayStart()) - if containerLen == 0 { - d.arrayEnd() - return - } - // Not much gain from doing it two ways for array. - // Arrays are not used as much for structs. - tisfi := ti.sfi.source() - hasLen := containerLen >= 0 - - // iterate all the items in the stream - // if mapped elem-wise to a field, handle it - // if more stream items than can be mapped, error it - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.arrayElem(j == 0) - if j < len(tisfi) { - d.kStructField(tisfi[j], rv) - } else { - d.structFieldNotFound(j, "") - } - } - - d.arrayEnd() - } else { - halt.onerror(errNeedMapOrArrayDecodeToStruct) - } -} - -func (d *decoder[T]) kSlice(f *decFnInfo, rv reflect.Value) { - _ = d.d // early asserts d, d.d are not nil once - // A slice can be set from a map or array in stream. - // This way, the order can be kept (as order is lost with map). - - // Note: rv is a slice type here - guaranteed - - ti := f.ti - rvCanset := rv.CanSet() - - ctyp := d.d.ContainerType() - if ctyp == valueTypeBytes || ctyp == valueTypeString { - // you can only decode bytes or string in the stream into a slice or array of bytes - if !(ti.rtid == uint8SliceTypId || ti.elemkind == uint8(reflect.Uint8)) { - halt.errorf("bytes/string in stream must decode into slice/array of bytes, not %v", ti.rt) - } - rvbs := rvGetBytes(rv) - if rvCanset { - bs2, bst := d.decodeBytesInto(rvbs, false) - if bst != dBytesIntoParamOut { - rvSetBytes(rv, bs2) - } - } else { - // not addressable byte slice, so do not decode into it past the length - d.decodeBytesInto(rvbs[:len(rvbs):len(rvbs)], true) - } - return - } - - // only expects valueType(Array|Map) - never Nil - var containerLenS int - isArray := ctyp == valueTypeArray - if isArray { - containerLenS = d.arrayStart(d.d.ReadArrayStart()) - } else if ctyp == valueTypeMap { - containerLenS = d.mapStart(d.d.ReadMapStart()) * 2 - } else { - halt.errorStr2("decoding into a slice, expect map/array - got ", ctyp.String()) - } - - // an array can never return a nil slice. so no need to check f.array here. - if containerLenS == 0 { - if rvCanset { - if rvIsNil(rv) { - rvSetDirect(rv, rvSliceZeroCap(ti.rt)) - } else { - rvSetSliceLen(rv, 0) - } - } - if isArray { - d.arrayEnd() - } else { - d.mapEnd() - } - return - } - - rtelem0Mut := !scalarBitset.isset(ti.elemkind) - rtelem := ti.elem - - for k := reflect.Kind(ti.elemkind); k == reflect.Ptr; k = rtelem.Kind() { - rtelem = rtelem.Elem() - } - - var fn *decFn[T] - - var rvChanged bool - - var rv0 = rv - var rv9 reflect.Value - - rvlen := rvLenSlice(rv) - rvcap := rvCapSlice(rv) - maxInitLen := d.maxInitLen() - hasLen := containerLenS >= 0 - if hasLen { - if containerLenS > rvcap { - oldRvlenGtZero := rvlen > 0 - rvlen1 := int(decInferLen(containerLenS, maxInitLen, uint(ti.elemsize))) - if rvlen1 == rvlen { - } else if rvlen1 <= rvcap { - if rvCanset { - rvlen = rvlen1 - rvSetSliceLen(rv, rvlen) - } - } else if rvCanset { // rvlen1 > rvcap - rvlen = rvlen1 - rv, rvCanset = rvMakeSlice(rv, f.ti, rvlen, rvlen) - rvcap = rvlen - rvChanged = !rvCanset - } else { // rvlen1 > rvcap && !canSet - halt.errorStr("cannot decode into non-settable slice") - } - if rvChanged && oldRvlenGtZero && rtelem0Mut { - rvCopySlice(rv, rv0, rtelem) // only copy up to length NOT cap i.e. rv0.Slice(0, rvcap) - } - } else if containerLenS != rvlen { - if rvCanset { - rvlen = containerLenS - rvSetSliceLen(rv, rvlen) - } - } - } - - // consider creating new element once, and just decoding into it. - var elemReset = d.h.SliceElementReset - - // when decoding into slices, there may be more values in the stream than the slice length. - // decodeValue handles this better when coming from an addressable value (known to reflect.Value). - // Consequently, builtin handling skips slices. - - var rtelemIsPtr bool - var rtelemElem reflect.Type - builtin := ti.tielem.flagDecBuiltin - if builtin { - rtelemIsPtr = ti.elemkind == uint8(reflect.Ptr) - if rtelemIsPtr { - rtelemElem = ti.elem.Elem() - } - } - - var j int - for ; d.containerNext(j, containerLenS, hasLen); j++ { - if j == 0 { - if rvIsNil(rv) { // means hasLen = false - if rvCanset { - rvlen = int(decInferLen(containerLenS, maxInitLen, uint(ti.elemsize))) - rv, rvCanset = rvMakeSlice(rv, f.ti, rvlen, rvlen) - rvcap = rvlen - rvChanged = !rvCanset - } else { - halt.errorStr("cannot decode into non-settable slice") - } - } - if fn == nil { - fn = d.fn(rtelem) - } - } - - if ctyp == valueTypeArray { - d.arrayElem(j == 0) - } else if j&1 == 0 { - d.mapElemKey(j == 0) - } else { - d.mapElemValue() - } - - // if indefinite, etc, then expand the slice if necessary - if j >= rvlen { - - // expand the slice up to the cap. - // Note that we did, so we have to reset it later. - - if rvlen < rvcap { - rvlen = rvcap - if rvCanset { - rvSetSliceLen(rv, rvlen) - } else if rvChanged { - rv = rvSlice(rv, rvlen) - } else { - halt.onerror(errExpandSliceCannotChange) - } - } else { - if !(rvCanset || rvChanged) { - halt.onerror(errExpandSliceCannotChange) - } - rv, rvcap, rvCanset = rvGrowSlice(rv, f.ti, rvcap, 1) - // note: 1 requested is hint/minimum - new capacity with more space - rvlen = rvcap - rvChanged = !rvCanset - } - } - - // we check if we can make this an addr, and do builtin - // e.g. if []ints, then fastpath should handle it? - // but if not, we should treat it as each element is *int, and decode into it. - - rv9 = rvArrayIndex(rv, j, f.ti, true) - if elemReset { - rvSetZero(rv9) - } - if d.d.TryNil() { - rvSetZero(rv9) - } else if builtin { - if rtelemIsPtr { - if rvIsNil(rv9) { - rvSetDirect(rv9, reflect.New(rtelemElem)) - } - d.decode(rv2i(rv9)) - } else { - d.decode(rv2i(rvAddr(rv9, ti.tielem.ptr))) // d.decode(rv2i(rv9.Addr())) - } - } else { - d.decodeValueNoCheckNil(rv9, fn) - } - } - if j < rvlen { - if rvCanset { - rvSetSliceLen(rv, j) - } else if rvChanged { - rv = rvSlice(rv, j) - } - // rvlen = j - } else if j == 0 && rvIsNil(rv) { - if rvCanset { - rv = rvSliceZeroCap(ti.rt) - rvCanset = false - rvChanged = true - } - } - if isArray { - d.arrayEnd() - } else { - d.mapEnd() - } - - if rvChanged { // infers rvCanset=true, so it can be reset - rvSetDirect(rv0, rv) - } -} - -func (d *decoder[T]) kArray(f *decFnInfo, rv reflect.Value) { - _ = d.d // early asserts d, d.d are not nil once - // An array can be set from a map or array in stream. - ti := f.ti - ctyp := d.d.ContainerType() - if handleBytesWithinKArray && (ctyp == valueTypeBytes || ctyp == valueTypeString) { - // you can only decode bytes or string in the stream into a slice or array of bytes - if ti.elemkind != uint8(reflect.Uint8) { - halt.errorf("bytes/string in stream can decode into array of bytes, but not %v", ti.rt) - } - rvbs := rvGetArrayBytes(rv, nil) - d.decodeBytesInto(rvbs, true) - return - } - - // only expects valueType(Array|Map) - never Nil - var containerLenS int - isArray := ctyp == valueTypeArray - if isArray { - containerLenS = d.arrayStart(d.d.ReadArrayStart()) - } else if ctyp == valueTypeMap { - containerLenS = d.mapStart(d.d.ReadMapStart()) * 2 - } else { - halt.errorStr2("decoding into a slice, expect map/array - got ", ctyp.String()) - } - - // an array can never return a nil slice. so no need to check f.array here. - if containerLenS == 0 { - if isArray { - d.arrayEnd() - } else { - d.mapEnd() - } - return - } - - rtelem := ti.elem - for k := reflect.Kind(ti.elemkind); k == reflect.Ptr; k = rtelem.Kind() { - rtelem = rtelem.Elem() - } - - var rv9 reflect.Value - - rvlen := rv.Len() // same as cap - hasLen := containerLenS >= 0 - if hasLen && containerLenS > rvlen { - halt.errorf("cannot decode into array with length: %v, less than container length: %v", any(rvlen), any(containerLenS)) - } - - // consider creating new element once, and just decoding into it. - var elemReset = d.h.SliceElementReset - - var rtelemIsPtr bool - var rtelemElem reflect.Type - var fn *decFn[T] - builtin := ti.tielem.flagDecBuiltin - if builtin { - rtelemIsPtr = ti.elemkind == uint8(reflect.Ptr) - if rtelemIsPtr { - rtelemElem = ti.elem.Elem() - } - } else { - fn = d.fn(rtelem) - } - - for j := 0; d.containerNext(j, containerLenS, hasLen); j++ { - if ctyp == valueTypeArray { - d.arrayElem(j == 0) - } else if j&1 == 0 { - d.mapElemKey(j == 0) - } else { - d.mapElemValue() - } - // note that you cannot expand the array if indefinite and we go past array length - if j >= rvlen { - d.arrayCannotExpand(rvlen, j+1) - d.swallow() - continue - } - - rv9 = rvArrayIndex(rv, j, f.ti, false) - if elemReset { - rvSetZero(rv9) - } - if d.d.TryNil() { - rvSetZero(rv9) - } else if builtin { - if rtelemIsPtr { - if rvIsNil(rv9) { - rvSetDirect(rv9, reflect.New(rtelemElem)) - } - d.decode(rv2i(rv9)) - } else { - d.decode(rv2i(rvAddr(rv9, ti.tielem.ptr))) // d.decode(rv2i(rv9.Addr())) - } - } else { - d.decodeValueNoCheckNil(rv9, fn) - } - } - if isArray { - d.arrayEnd() - } else { - d.mapEnd() - } -} - -func (d *decoder[T]) kChan(f *decFnInfo, rv reflect.Value) { - _ = d.d // early asserts d, d.d are not nil once - // A slice can be set from a map or array in stream. - // This way, the order can be kept (as order is lost with map). - - ti := f.ti - if ti.chandir&uint8(reflect.SendDir) == 0 { - halt.errorStr("receive-only channel cannot be decoded") - } - ctyp := d.d.ContainerType() - if ctyp == valueTypeBytes || ctyp == valueTypeString { - // you can only decode bytes or string in the stream into a slice or array of bytes - if !(ti.rtid == uint8SliceTypId || ti.elemkind == uint8(reflect.Uint8)) { - halt.errorf("bytes/string in stream must decode into slice/array of bytes, not %v", ti.rt) - } - bs2, _ := d.d.DecodeBytes() - irv := rv2i(rv) - ch, ok := irv.(chan<- byte) - if !ok { - ch = irv.(chan byte) - } - for _, b := range bs2 { - ch <- b - } - return - } - - var rvCanset = rv.CanSet() - - // only expects valueType(Array|Map) - never Nil - var containerLenS int - isArray := ctyp == valueTypeArray - if isArray { - containerLenS = d.arrayStart(d.d.ReadArrayStart()) - } else if ctyp == valueTypeMap { - containerLenS = d.mapStart(d.d.ReadMapStart()) * 2 - } else { - halt.errorStr2("decoding into a slice, expect map/array - got ", ctyp.String()) - } - - // an array can never return a nil slice. so no need to check f.array here. - if containerLenS == 0 { - if rvCanset && rvIsNil(rv) { - rvSetDirect(rv, reflect.MakeChan(ti.rt, 0)) - } - if isArray { - d.arrayEnd() - } else { - d.mapEnd() - } - return - } - - rtelem := ti.elem - useTransient := decUseTransient && ti.elemkind != byte(reflect.Ptr) && ti.tielem.flagCanTransient - - for k := reflect.Kind(ti.elemkind); k == reflect.Ptr; k = rtelem.Kind() { - rtelem = rtelem.Elem() - } - - var fn *decFn[T] - - var rvChanged bool - var rv0 = rv - var rv9 reflect.Value - - var rvlen int // = rv.Len() - hasLen := containerLenS >= 0 - maxInitLen := d.maxInitLen() - - for j := 0; d.containerNext(j, containerLenS, hasLen); j++ { - if j == 0 { - if rvIsNil(rv) { - if hasLen { - rvlen = int(decInferLen(containerLenS, maxInitLen, uint(ti.elemsize))) - } else { - rvlen = decDefChanCap - } - if rvCanset { - rv = reflect.MakeChan(ti.rt, rvlen) - rvChanged = true - } else { - halt.errorStr("cannot decode into non-settable chan") - } - } - if fn == nil { - fn = d.fn(rtelem) - } - } - - if ctyp == valueTypeArray { - d.arrayElem(j == 0) - } else if j&1 == 0 { - d.mapElemKey(j == 0) - } else { - d.mapElemValue() - } - - if rv9.IsValid() { - rvSetZero(rv9) - } else if useTransient { - rv9 = d.perType.TransientAddrK(ti.elem, reflect.Kind(ti.elemkind)) - } else { - rv9 = rvZeroAddrK(ti.elem, reflect.Kind(ti.elemkind)) - } - if !d.d.TryNil() { - d.decodeValueNoCheckNil(rv9, fn) - } - rv.Send(rv9) - } - if isArray { - d.arrayEnd() - } else { - d.mapEnd() - } - - if rvChanged { // infers rvCanset=true, so it can be reset - rvSetDirect(rv0, rv) - } - -} - -func (d *decoder[T]) kMap(f *decFnInfo, rv reflect.Value) { - _ = d.d // early asserts d, d.d are not nil once - containerLen := d.mapStart(d.d.ReadMapStart()) - ti := f.ti - if rvIsNil(rv) { - rvlen := int(decInferLen(containerLen, d.maxInitLen(), uint(ti.keysize+ti.elemsize))) - rvSetDirect(rv, makeMapReflect(ti.rt, rvlen)) - } - - if containerLen == 0 { - d.mapEnd() - return - } - - ktype, vtype := ti.key, ti.elem - ktypeId := rt2id(ktype) - vtypeKind := reflect.Kind(ti.elemkind) - ktypeKind := reflect.Kind(ti.keykind) - mparams := getMapReqParams(ti) - // kfast := mapKeyFastKindFor(ktypeKind) - // visindirect := mapStoresElemIndirect(uintptr(ti.elemsize)) - // visref := refBitset.isset(ti.elemkind) - - vtypePtr := vtypeKind == reflect.Ptr - ktypePtr := ktypeKind == reflect.Ptr - - vTransient := decUseTransient && !vtypePtr && ti.tielem.flagCanTransient - // keys are transient iff values are transient first - kTransient := vTransient && !ktypePtr && ti.tikey.flagCanTransient - - var vtypeElem reflect.Type - - var keyFn, valFn *decFn[T] - var ktypeLo, vtypeLo = ktype, vtype - - if ktypeKind == reflect.Ptr { - for ktypeLo = ktype.Elem(); ktypeLo.Kind() == reflect.Ptr; ktypeLo = ktypeLo.Elem() { - } - } - - if vtypePtr { - vtypeElem = vtype.Elem() - for vtypeLo = vtypeElem; vtypeLo.Kind() == reflect.Ptr; vtypeLo = vtypeLo.Elem() { - } - } - - rvkMut := !scalarBitset.isset(ti.keykind) // if ktype is immutable, then re-use the same rvk. - rvvMut := !scalarBitset.isset(ti.elemkind) - rvvCanNil := isnilBitset.isset(ti.elemkind) - - // rvk: key - // rvkn: if non-mutable, on each iteration of loop, set rvk to this - // rvv: value - // rvvn: if non-mutable, on each iteration of loop, set rvv to this - // if mutable, may be used as a temporary value for local-scoped operations - // rvva: if mutable, used as transient value for use for key lookup - // rvvz: zero value of map value type, used to do a map set when nil is found in stream - var rvk, rvkn, rvv, rvvn, rvva, rvvz reflect.Value - - // we do a doMapGet if kind is mutable, and InterfaceReset=true if interface - var doMapGet, doMapSet bool - - if !d.h.MapValueReset { - if rvvMut && (vtypeKind != reflect.Interface || !d.h.InterfaceReset) { - doMapGet = true - rvva = mapAddrLoopvarRV(vtype, vtypeKind) - } - } - - ktypeIsString := ktypeId == stringTypId - ktypeIsIntf := ktypeId == intfTypId - hasLen := containerLen >= 0 - - var kstr2bs []byte - var kstr string - - var mapKeyStringSharesBytesBuf bool - var att dBytesAttachState - - // Use a possibly transient (map) value (and key), to reduce allocation - - // when decoding into slices, there may be more values in the stream than the slice length. - // decodeValue handles this better when coming from an addressable value (known to reflect.Value). - // Consequently, builtin handling skips slices. - - var vElem, kElem reflect.Type - kbuiltin := ti.tikey.flagDecBuiltin && ti.keykind != uint8(reflect.Slice) - vbuiltin := ti.tielem.flagDecBuiltin // && ti.elemkind != uint8(reflect.Slice) - if kbuiltin && ktypePtr { - kElem = ti.key.Elem() - } - if vbuiltin && vtypePtr { - vElem = ti.elem.Elem() - } - - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - mapKeyStringSharesBytesBuf = false - kstr = "" - if j == 0 { - // if vtypekind is a scalar and thus value will be decoded using TransientAddrK, - // then it is ok to use TransientAddr2K for the map key. - if kTransient { - rvk = d.perType.TransientAddr2K(ktype, ktypeKind) - } else { - rvk = rvZeroAddrK(ktype, ktypeKind) - } - if !rvkMut { - rvkn = rvk - } - if !rvvMut { - if vTransient { - rvvn = d.perType.TransientAddrK(vtype, vtypeKind) - } else { - rvvn = rvZeroAddrK(vtype, vtypeKind) - } - } - if !ktypeIsString && keyFn == nil { - keyFn = d.fn(ktypeLo) - } - if valFn == nil { - valFn = d.fn(vtypeLo) - } - } else if rvkMut { - rvSetZero(rvk) - } else { - rvk = rvkn - } - - d.mapElemKey(j == 0) - - if d.d.TryNil() { - rvSetZero(rvk) - } else if ktypeIsString { - kstr2bs, att = d.d.DecodeStringAsBytes() - kstr, mapKeyStringSharesBytesBuf = d.bytes2Str(kstr2bs, att) - rvSetString(rvk, kstr) - } else { - if kbuiltin { - if ktypePtr { - if rvIsNil(rvk) { - rvSetDirect(rvk, reflect.New(kElem)) - } - d.decode(rv2i(rvk)) - } else { - d.decode(rv2i(rvAddr(rvk, ti.tikey.ptr))) - } - } else { - d.decodeValueNoCheckNil(rvk, keyFn) - } - // special case if interface wrapping a byte slice - if ktypeIsIntf { - if rvk2 := rvk.Elem(); rvk2.IsValid() && rvk2.Type() == uint8SliceTyp { - kstr2bs = rvGetBytes(rvk2) - kstr, mapKeyStringSharesBytesBuf = d.bytes2Str(kstr2bs, dBytesAttachView) - rvSetIntf(rvk, rv4istr(kstr)) - } - // NOTE: consider failing early if map/slice/func - } - } - - // TryNil will try to read from the stream and check if a nil marker. - // - // When using ioDecReader (specifically in bufio mode), this TryNil call could - // override part of the buffer used for the string key. - // - // To mitigate this, we do a special check for ioDecReader in bufio mode. - if mapKeyStringSharesBytesBuf && d.bufio { - if ktypeIsString { - rvSetString(rvk, d.detach2Str(kstr2bs, att)) - } else { // ktypeIsIntf - rvSetIntf(rvk, rv4istr(d.detach2Str(kstr2bs, att))) - } - mapKeyStringSharesBytesBuf = false - } - - d.mapElemValue() - - if d.d.TryNil() { - if mapKeyStringSharesBytesBuf { - if ktypeIsString { - rvSetString(rvk, d.detach2Str(kstr2bs, att)) - } else { // ktypeIsIntf - rvSetIntf(rvk, rv4istr(d.detach2Str(kstr2bs, att))) - } - } - // since a map, we have to set zero value if needed - if !rvvz.IsValid() { - rvvz = rvZeroK(vtype, vtypeKind) - } - mapSet(rv, rvk, rvvz, mparams) - continue - } - - // there is non-nil content in the stream to decode ... - // consequently, it's ok to just directly create new value to the pointer (if vtypePtr) - - // set doMapSet to false iff u do a get, and the return value is a non-nil pointer - doMapSet = true - - if !rvvMut { - rvv = rvvn - } else if !doMapGet { - goto NEW_RVV - } else { - rvv = mapGet(rv, rvk, rvva, mparams) - if !rvv.IsValid() || (rvvCanNil && rvIsNil(rvv)) { - goto NEW_RVV - } - switch vtypeKind { - case reflect.Ptr, reflect.Map: // ok to decode directly into map - doMapSet = false - case reflect.Interface: - // if an interface{}, just decode into it iff a non-nil ptr/map, else allocate afresh - rvvn = rvv.Elem() - if k := rvvn.Kind(); (k == reflect.Ptr || k == reflect.Map) && !rvIsNil(rvvn) { - d.decodeValueNoCheckNil(rvvn, nil) // valFn is incorrect here - continue - } - // make addressable (so we can set the interface) - rvvn = rvZeroAddrK(vtype, vtypeKind) - rvSetIntf(rvvn, rvv) - rvv = rvvn - default: - // make addressable (so you can set the slice/array elements, etc) - if vTransient { - rvvn = d.perType.TransientAddrK(vtype, vtypeKind) - } else { - rvvn = rvZeroAddrK(vtype, vtypeKind) - } - rvSetDirect(rvvn, rvv) - rvv = rvvn - } - } - goto DECODE_VALUE_NO_CHECK_NIL - - NEW_RVV: - if vtypePtr { - rvv = reflect.New(vtypeElem) // non-nil in stream, so allocate value - } else if vTransient { - rvv = d.perType.TransientAddrK(vtype, vtypeKind) - } else { - rvv = rvZeroAddrK(vtype, vtypeKind) - } - - DECODE_VALUE_NO_CHECK_NIL: - if doMapSet && mapKeyStringSharesBytesBuf { - if ktypeIsString { - rvSetString(rvk, d.detach2Str(kstr2bs, att)) - } else { // ktypeIsIntf - rvSetIntf(rvk, rv4istr(d.detach2Str(kstr2bs, att))) - } - } - if vbuiltin { - if vtypePtr { - if rvIsNil(rvv) { - rvSetDirect(rvv, reflect.New(vElem)) - } - d.decode(rv2i(rvv)) - } else { - d.decode(rv2i(rvAddr(rvv, ti.tielem.ptr))) - } - } else { - d.decodeValueNoCheckNil(rvv, valFn) - } - if doMapSet { - mapSet(rv, rvk, rvv, mparams) - } - } - - d.mapEnd() -} - -func (d *decoder[T]) init(h Handle) { - initHandle(h) - callMake(&d.d) - d.hh = h - d.h = h.getBasicHandle() - // d.zeroCopy = d.h.ZeroCopy - // d.be = h.isBinary() - d.err = errDecoderNotInitialized - - if d.h.InternString && d.is == nil { - d.is.init() - } - - // d.fp = fastpathDList[T]() - d.fp = d.d.init(h, &d.decoderBase, d).(*fastpathDs[T]) // should set js, cbor, bytes, etc - - // d.cbreak = d.js || d.cbor - - if d.bytes { - d.rtidFn = &d.h.rtidFnsDecBytes - d.rtidFnNoExt = &d.h.rtidFnsDecNoExtBytes - } else { - d.bufio = d.h.ReaderBufferSize > 0 - d.rtidFn = &d.h.rtidFnsDecIO - d.rtidFnNoExt = &d.h.rtidFnsDecNoExtIO - } - - d.reset() - // NOTE: do not initialize d.n here. It is lazily initialized in d.naked() -} - -func (d *decoder[T]) reset() { - d.d.reset() - d.err = nil - d.c = 0 - d.depth = 0 - d.calls = 0 - // reset all things which were cached from the Handle, but could change - d.maxdepth = decDefMaxDepth - if d.h.MaxDepth > 0 { - d.maxdepth = d.h.MaxDepth - } - d.mtid = 0 - d.stid = 0 - d.mtr = false - d.str = false - if d.h.MapType != nil { - d.mtid = rt2id(d.h.MapType) - _, d.mtr = fastpathAvIndex(d.mtid) - } - if d.h.SliceType != nil { - d.stid = rt2id(d.h.SliceType) - _, d.str = fastpathAvIndex(d.stid) - } -} - -// Reset the Decoder with a new Reader to decode from, -// clearing all state from last run(s). -func (d *decoder[T]) Reset(r io.Reader) { - if d.bytes { - halt.onerror(errDecNoResetBytesWithReader) - } - d.reset() - if r == nil { - r = &eofReader - } - d.d.resetInIO(r) -} - -// ResetBytes resets the Decoder with a new []byte to decode from, -// clearing all state from last run(s). -func (d *decoder[T]) ResetBytes(in []byte) { - if !d.bytes { - halt.onerror(errDecNoResetReaderWithBytes) - } - d.resetBytes(in) -} - -func (d *decoder[T]) resetBytes(in []byte) { - d.reset() - if in == nil { - in = zeroByteSlice - } - d.d.resetInBytes(in) -} - -// ResetString resets the Decoder with a new string to decode from, -// clearing all state from last run(s). -// -// It is a convenience function that calls ResetBytes with a -// []byte view into the string. -// -// This can be an efficient zero-copy if using default mode i.e. without codec.safe tag. -func (d *decoder[T]) ResetString(s string) { - d.ResetBytes(bytesView(s)) -} - -// Decode decodes the stream from reader and stores the result in the -// value pointed to by v. v cannot be a nil pointer. v can also be -// a reflect.Value of a pointer. -// -// Note that a pointer to a nil interface is not a nil pointer. -// If you do not know what type of stream it is, pass in a pointer to a nil interface. -// We will decode and store a value in that nil interface. -// -// Sample usages: -// -// // Decoding into a non-nil typed value -// var f float32 -// err = codec.NewDecoder(r, handle).Decode(&f) -// -// // Decoding into nil interface -// var v interface{} -// dec := codec.NewDecoder(r, handle) -// err = dec.Decode(&v) -// -// When decoding into a nil interface{}, we will decode into an appropriate value based -// on the contents of the stream: -// - Numbers are decoded as float64, int64 or uint64. -// - Other values are decoded appropriately depending on the type: -// bool, string, []byte, time.Time, etc -// - Extensions are decoded as RawExt (if no ext function registered for the tag) -// -// Configurations exist on the Handle to override defaults -// (e.g. for MapType, SliceType and how to decode raw bytes). -// -// When decoding into a non-nil interface{} value, the mode of encoding is based on the -// type of the value. When a value is seen: -// - If an extension is registered for it, call that extension function -// - If it implements BinaryUnmarshaler, call its UnmarshalBinary(data []byte) error -// - Else decode it based on its reflect.Kind -// -// There are some special rules when decoding into containers (slice/array/map/struct). -// Decode will typically use the stream contents to UPDATE the container i.e. the values -// in these containers will not be zero'ed before decoding. -// - A map can be decoded from a stream map, by updating matching keys. -// - A slice can be decoded from a stream array, -// by updating the first n elements, where n is length of the stream. -// - A slice can be decoded from a stream map, by decoding as if -// it contains a sequence of key-value pairs. -// - A struct can be decoded from a stream map, by updating matching fields. -// - A struct can be decoded from a stream array, -// by updating fields as they occur in the struct (by index). -// -// This in-place update maintains consistency in the decoding philosophy (i.e. we ALWAYS update -// in place by default). However, the consequence of this is that values in slices or maps -// which are not zero'ed before hand, will have part of the prior values in place after decode -// if the stream doesn't contain an update for those parts. -// -// This in-place update can be disabled by configuring the MapValueReset and SliceElementReset -// decode options available on every handle. -// -// Furthermore, when decoding a stream map or array with length of 0 into a nil map or slice, -// we reset the destination map or slice to a zero-length value. -// -// However, when decoding a stream nil, we reset the destination container -// to its "zero" value (e.g. nil for slice/map, etc). -// -// Note: we allow nil values in the stream anywhere except for map keys. -// A nil value in the encoded stream where a map key is expected is treated as an error. -// -// Note that an error from a Decode call will make the Decoder unusable moving forward. -// This is because the state of the Decoder, it's input stream, etc are no longer stable. -// Any subsequent calls to Decode will trigger the same error. -func (d *decoder[T]) Decode(v interface{}) (err error) { - // tried to use closure, as runtime optimizes defer with no params. - // This seemed to be causing weird issues (like circular reference found, unexpected panic, etc). - // Also, see https://github.com/golang/go/issues/14939#issuecomment-417836139 - defer panicValToErr(d, callRecoverSentinel, &d.err, &err, debugging) - d.mustDecode(v) - return -} - -// MustDecode is like Decode, but panics if unable to Decode. -// -// Note: This provides insight to the code location that triggered the error. -// -// Note that an error from a Decode call will make the Decoder unusable moving forward. -// This is because the state of the Decoder, it's input stream, etc are no longer stable. -// Any subsequent calls to Decode will trigger the same error. -func (d *decoder[T]) MustDecode(v interface{}) { - defer panicValToErr(d, callRecoverSentinel, &d.err, nil, true) - d.mustDecode(v) - return -} - -func (d *decoder[T]) mustDecode(v interface{}) { - halt.onerror(d.err) - if d.hh == nil { - halt.onerror(errNoFormatHandle) - } - - // Top-level: v is a pointer and not nil. - d.calls++ - d.decode(v) - d.calls-- -} - -// Release is a no-op. -// -// Deprecated: Pooled resources are not used with a Decoder. -// This method is kept for compatibility reasons only. -func (d *decoder[T]) Release() {} - -func (d *decoder[T]) swallow() { - d.d.nextValueBytes() -} - -func (d *decoder[T]) nextValueBytes() []byte { - return d.d.nextValueBytes() -} - -func (d *decoder[T]) decode(iv interface{}) { - _ = d.d // early asserts d, d.d are not nil once - // a switch with only concrete types can be optimized. - // consequently, we deal with nil and interfaces outside the switch. - - rv, ok := isNil(iv, true) // handle nil pointers also - if ok { - halt.onerror(errCannotDecodeIntoNil) - } - - switch v := iv.(type) { - // case nil: - // case Selfer: - case *string: - *v = d.detach2Str(d.d.DecodeStringAsBytes()) - case *bool: - *v = d.d.DecodeBool() - case *int: - *v = int(chkOvf.IntV(d.d.DecodeInt64(), intBitsize)) - case *int8: - *v = int8(chkOvf.IntV(d.d.DecodeInt64(), 8)) - case *int16: - *v = int16(chkOvf.IntV(d.d.DecodeInt64(), 16)) - case *int32: - *v = int32(chkOvf.IntV(d.d.DecodeInt64(), 32)) - case *int64: - *v = d.d.DecodeInt64() - case *uint: - *v = uint(chkOvf.UintV(d.d.DecodeUint64(), uintBitsize)) - case *uint8: - *v = uint8(chkOvf.UintV(d.d.DecodeUint64(), 8)) - case *uint16: - *v = uint16(chkOvf.UintV(d.d.DecodeUint64(), 16)) - case *uint32: - *v = uint32(chkOvf.UintV(d.d.DecodeUint64(), 32)) - case *uint64: - *v = d.d.DecodeUint64() - case *uintptr: - *v = uintptr(chkOvf.UintV(d.d.DecodeUint64(), uintBitsize)) - case *float32: - *v = d.d.DecodeFloat32() - case *float64: - *v = d.d.DecodeFloat64() - case *complex64: - *v = complex(d.d.DecodeFloat32(), 0) - case *complex128: - *v = complex(d.d.DecodeFloat64(), 0) - case *[]byte: - *v, _ = d.decodeBytesInto(*v, false) - case []byte: - // not addressable byte slice, so do not decode into it past the length - d.decodeBytesInto(v[:len(v):len(v)], true) - case *time.Time: - *v = d.d.DecodeTime() - case *Raw: - *v = d.rawBytes() - - case *interface{}: - d.decodeValue(rv4iptr(v), nil) - - case reflect.Value: - if ok, _ = isDecodeable(v); !ok { - d.haltAsNotDecodeable(v) - } - d.decodeValue(v, nil) - - default: - // we can't check non-predefined types, as they might be a Selfer or extension. - if skipFastpathTypeSwitchInDirectCall || !d.dh.fastpathDecodeTypeSwitch(iv, d) { - if !rv.IsValid() { - rv = reflect.ValueOf(iv) - } - if ok, _ = isDecodeable(rv); !ok { - d.haltAsNotDecodeable(rv) - } - d.decodeValue(rv, nil) - } - } -} - -// decodeValue MUST be called by the actual value we want to decode into, -// not its addr or a reference to it. -// -// This way, we know if it is itself a pointer, and can handle nil in -// the stream effectively. -// -// Note that decodeValue will handle nil in the stream early, so that the -// subsequent calls i.e. kXXX methods, etc do not have to handle it themselves. -func (d *decoder[T]) decodeValue(rv reflect.Value, fn *decFn[T]) { - if d.d.TryNil() { - decSetNonNilRV2Zero(rv) - } else { - d.decodeValueNoCheckNil(rv, fn) - } -} - -func (d *decoder[T]) decodeValueNoCheckNil(rv reflect.Value, fn *decFn[T]) { - // If stream is not containing a nil value, then we can deref to the base - // non-pointer value, and decode into that. - var rvp reflect.Value - var rvpValid bool -PTR: - if rv.Kind() == reflect.Ptr { - rvpValid = true - if rvIsNil(rv) { - rvSetDirect(rv, reflect.New(rv.Type().Elem())) - } - rvp = rv - rv = rv.Elem() - goto PTR - } - - if fn == nil { - fn = d.fn(rv.Type()) - } - if fn.i.addrD { - if rvpValid { - rv = rvp - } else if rv.CanAddr() { - rv = rvAddr(rv, fn.i.ti.ptr) - } else if fn.i.addrDf { - halt.errorStr("cannot decode into a non-pointer value") - } - } - fn.fd(d, &fn.i, rv) -} - -func (d *decoder[T]) decodeAs(v interface{}, t reflect.Type, ext bool) { - if ext { - d.decodeValue(baseRV(v), d.fn(t)) - } else { - d.decodeValue(baseRV(v), d.fnNoExt(t)) - } -} - -func (d *decoder[T]) structFieldNotFound(index int, rvkencname string) { - // Note: rvkencname is used only if there is an error, to pass into halt.errorf. - // Consequently, it is ok to pass in a stringView - // Since rvkencname may be a stringView, do NOT pass it to another function. - if d.h.ErrorIfNoField { - if index >= 0 { - halt.errorInt("no matching struct field found when decoding stream array at index ", int64(index)) - } else if rvkencname != "" { - halt.errorStr2("no matching struct field found when decoding stream map with key ", rvkencname) - } - } - d.swallow() -} - -// decodeBytesInto is a convenience delegate function to decDriver.DecodeBytes. -// It ensures that `in` is not a nil byte, before calling decDriver.DecodeBytes, -// as decDriver.DecodeBytes treats a nil as a hint to use its internal scratch buffer. -func (d *decoder[T]) decodeBytesInto(out []byte, mustFit bool) (v []byte, state dBytesIntoState) { - v, att := d.d.DecodeBytes() - if cap(v) == 0 || (att >= dBytesAttachViewZerocopy && !mustFit) { - // no need to detach (since mustFit=false) - // including v has no capacity (covers v == nil and []byte{}) - return - } - if len(v) == 0 { - v = zeroByteSlice // cannot be re-sliced/appended to - return - } - if len(out) == len(v) { - state = dBytesIntoParamOut - } else if cap(out) >= len(v) { - out = out[:len(v)] - state = dBytesIntoParamOutSlice - } else if mustFit { - halt.errorf("bytes capacity insufficient for decoded bytes: got/expected: %d/%d", len(v), len(out)) - } else { - out = make([]byte, len(v)) - state = dBytesIntoNew - } - copy(out, v) - v = out - return -} - -func (d *decoder[T]) rawBytes() (v []byte) { - // ensure that this is not a view into the bytes - // i.e. if necessary, make new copy always. - v = d.d.nextValueBytes() - if d.bytes && !d.h.ZeroCopy { - vv := make([]byte, len(v)) - copy(vv, v) // using copy here triggers make+copy optimization eliding memclr - v = vv - } - return -} - -func (d *decoder[T]) wrapErr(v error, err *error) { - *err = wrapCodecErr(v, d.hh.Name(), d.d.NumBytesRead(), false) -} - -// NumBytesRead returns the number of bytes read -func (d *decoder[T]) NumBytesRead() int { - return d.d.NumBytesRead() -} - -// ---- container tracking -// Note: We update the .c after calling the callback. -// This way, the callback can know what the last status was. - -// MARKER: do not call mapEnd if mapStart returns containerLenNil. - -// MARKER: optimize decoding since all formats do not truly support all decDriver'ish operations. -// - Read(Map|Array)Start is only supported by all formats. -// - CheckBreak is only supported by json and cbor. -// - Read(Map|Array)End is only supported by json. -// - Read(Map|Array)Elem(Kay|Value) is only supported by json. -// Honor these in the code, to reduce the number of interface calls (even if empty). - -func (d *decoder[T]) containerNext(j, containerLen int, hasLen bool) bool { - // return (hasLen && (j < containerLen)) || (!hasLen && !d.d.CheckBreak()) - if hasLen { - return j < containerLen - } - return !d.d.CheckBreak() -} - -func (d *decoder[T]) mapElemKey(firstTime bool) { - d.d.ReadMapElemKey(firstTime) - d.c = containerMapKey -} - -func (d *decoder[T]) mapElemValue() { - d.d.ReadMapElemValue() - d.c = containerMapValue -} - -func (d *decoder[T]) mapEnd() { - d.d.ReadMapEnd() - d.depthDecr() - d.c = 0 -} - -func (d *decoder[T]) arrayElem(firstTime bool) { - d.d.ReadArrayElem(firstTime) - d.c = containerArrayElem -} - -func (d *decoder[T]) arrayEnd() { - d.d.ReadArrayEnd() - d.depthDecr() - d.c = 0 -} - -func (d *decoder[T]) interfaceExtConvertAndDecode(v interface{}, ext InterfaceExt) { - // The ext may support different types for performance e.g. int if no fractions, else float64 - // Consequently, best mode is: - // - decode next value into an interface{} - // - pass it to the UpdateExt - var vv interface{} - d.decode(&vv) - ext.UpdateExt(v, vv) - // rv := d.interfaceExtConvertAndDecodeGetRV(v, ext) - // d.decodeValue(rv, nil) - // ext.UpdateExt(v, rv2i(rv)) -} - -func (d *decoder[T]) fn(t reflect.Type) *decFn[T] { - return d.dh.decFnViaBH(t, d.rtidFn, d.h, d.fp, false) -} - -func (d *decoder[T]) fnNoExt(t reflect.Type) *decFn[T] { - return d.dh.decFnViaBH(t, d.rtidFnNoExt, d.h, d.fp, true) -} - -// ---- - -func (helperDecDriver[T]) newDecoderBytes(in []byte, h Handle) *decoder[T] { - var c1 decoder[T] - c1.bytes = true - c1.init(h) - c1.ResetBytes(in) // MARKER check for error - return &c1 -} - -func (helperDecDriver[T]) newDecoderIO(in io.Reader, h Handle) *decoder[T] { - var c1 decoder[T] - c1.init(h) - c1.Reset(in) - return &c1 -} - -// ---- - -func (helperDecDriver[T]) decFnloadFastpathUnderlying(ti *typeInfo, fp *fastpathDs[T]) (f *fastpathD[T], u reflect.Type) { - rtid := rt2id(ti.fastpathUnderlying) - idx, ok := fastpathAvIndex(rtid) - if !ok { - return - } - f = &fp[idx] - if uint8(reflect.Array) == ti.kind { - u = reflect.ArrayOf(ti.rt.Len(), ti.elem) - } else { - u = f.rt - } - return -} - -func (helperDecDriver[T]) decFindRtidFn(s []decRtidFn[T], rtid uintptr) (i uint, fn *decFn[T]) { - // binary search. Adapted from sort/search.go. Use goto (not for loop) to allow inlining. - var h uint // var h, i uint - var j = uint(len(s)) -LOOP: - if i < j { - h = (i + j) >> 1 // avoid overflow when computing h // h = i + (j-i)/2 - if s[h].rtid < rtid { - i = h + 1 - } else { - j = h - } - goto LOOP - } - if i < uint(len(s)) && s[i].rtid == rtid { - fn = s[i].fn - } - return -} - -func (helperDecDriver[T]) decFromRtidFnSlice(fns *atomicRtidFnSlice) (s []decRtidFn[T]) { - if v := fns.load(); v != nil { - s = *(lowLevelToPtr[[]decRtidFn[T]](v)) - } - return -} - -func (dh helperDecDriver[T]) decFnViaBH(rt reflect.Type, fns *atomicRtidFnSlice, x *BasicHandle, fp *fastpathDs[T], - checkExt bool) (fn *decFn[T]) { - return dh.decFnVia(rt, fns, x.typeInfos(), &x.mu, x.extHandle, fp, - checkExt, x.CheckCircularRef, x.timeBuiltin, x.binaryHandle, x.jsonHandle) -} - -func (dh helperDecDriver[T]) decFnVia(rt reflect.Type, fns *atomicRtidFnSlice, - tinfos *TypeInfos, mu *sync.Mutex, exth extHandle, fp *fastpathDs[T], - checkExt, checkCircularRef, timeBuiltin, binaryEncoding, json bool) (fn *decFn[T]) { - rtid := rt2id(rt) - var sp []decRtidFn[T] = dh.decFromRtidFnSlice(fns) - if sp != nil { - _, fn = dh.decFindRtidFn(sp, rtid) - } - if fn == nil { - fn = dh.decFnViaLoader(rt, rtid, fns, tinfos, mu, exth, fp, checkExt, checkCircularRef, timeBuiltin, binaryEncoding, json) - } - return -} - -func (dh helperDecDriver[T]) decFnViaLoader(rt reflect.Type, rtid uintptr, fns *atomicRtidFnSlice, - tinfos *TypeInfos, mu *sync.Mutex, exth extHandle, fp *fastpathDs[T], - checkExt, checkCircularRef, timeBuiltin, binaryEncoding, json bool) (fn *decFn[T]) { - - fn = dh.decFnLoad(rt, rtid, tinfos, exth, fp, checkExt, checkCircularRef, timeBuiltin, binaryEncoding, json) - var sp []decRtidFn[T] - mu.Lock() - sp = dh.decFromRtidFnSlice(fns) - // since this is an atomic load/store, we MUST use a different array each time, - // else we have a data race when a store is happening simultaneously with a decFindRtidFn call. - if sp == nil { - sp = []decRtidFn[T]{{rtid, fn}} - fns.store(ptrToLowLevel(&sp)) - } else { - idx, fn2 := dh.decFindRtidFn(sp, rtid) - if fn2 == nil { - sp2 := make([]decRtidFn[T], len(sp)+1) - copy(sp2[idx+1:], sp[idx:]) - copy(sp2, sp[:idx]) - sp2[idx] = decRtidFn[T]{rtid, fn} - fns.store(ptrToLowLevel(&sp2)) - } - } - mu.Unlock() - return -} - -func (dh helperDecDriver[T]) decFnLoad(rt reflect.Type, rtid uintptr, tinfos *TypeInfos, - exth extHandle, fp *fastpathDs[T], - checkExt, checkCircularRef, timeBuiltin, binaryEncoding, json bool) (fn *decFn[T]) { - fn = new(decFn[T]) - fi := &(fn.i) - ti := tinfos.get(rtid, rt) - fi.ti = ti - rk := reflect.Kind(ti.kind) - - // anything can be an extension except the built-in ones: time, raw and rawext. - // ensure we check for these types, then if extension, before checking if - // it implementes one of the pre-declared interfaces. - - fi.addrDf = true - - if rtid == timeTypId && timeBuiltin { - fn.fd = (*decoder[T]).kTime - } else if rtid == rawTypId { - fn.fd = (*decoder[T]).raw - } else if rtid == rawExtTypId { - fn.fd = (*decoder[T]).rawExt - fi.addrD = true - } else if xfFn := exth.getExt(rtid, checkExt); xfFn != nil { - fi.xfTag, fi.xfFn = xfFn.tag, xfFn.ext - fn.fd = (*decoder[T]).ext - fi.addrD = true - } else if ti.flagSelfer || ti.flagSelferPtr { - fn.fd = (*decoder[T]).selferUnmarshal - fi.addrD = ti.flagSelferPtr - } else if supportMarshalInterfaces && binaryEncoding && - (ti.flagBinaryMarshaler || ti.flagBinaryMarshalerPtr) && - (ti.flagBinaryUnmarshaler || ti.flagBinaryUnmarshalerPtr) { - fn.fd = (*decoder[T]).binaryUnmarshal - fi.addrD = ti.flagBinaryUnmarshalerPtr - } else if supportMarshalInterfaces && !binaryEncoding && json && - (ti.flagJsonMarshaler || ti.flagJsonMarshalerPtr) && - (ti.flagJsonUnmarshaler || ti.flagJsonUnmarshalerPtr) { - //If JSON, we should check JSONMarshal before textMarshal - fn.fd = (*decoder[T]).jsonUnmarshal - fi.addrD = ti.flagJsonUnmarshalerPtr - } else if supportMarshalInterfaces && !binaryEncoding && - (ti.flagTextMarshaler || ti.flagTextMarshalerPtr) && - (ti.flagTextUnmarshaler || ti.flagTextUnmarshalerPtr) { - fn.fd = (*decoder[T]).textUnmarshal - fi.addrD = ti.flagTextUnmarshalerPtr - } else { - if fastpathEnabled && (rk == reflect.Map || rk == reflect.Slice || rk == reflect.Array) { - var rtid2 uintptr - if !ti.flagHasPkgPath { // un-named type (slice or mpa or array) - rtid2 = rtid - if rk == reflect.Array { - rtid2 = rt2id(ti.key) // ti.key for arrays = reflect.SliceOf(ti.elem) - } - if idx, ok := fastpathAvIndex(rtid2); ok { - fn.fd = fp[idx].decfn - fi.addrD = true - fi.addrDf = false - if rk == reflect.Array { - fi.addrD = false // decode directly into array value (slice made from it) - } - } - } else { // named type (with underlying type of map or slice or array) - // try to use mapping for underlying type - xfe, xrt := dh.decFnloadFastpathUnderlying(ti, fp) - if xfe != nil { - xfnf2 := xfe.decfn - if rk == reflect.Array { - fi.addrD = false // decode directly into array value (slice made from it) - fn.fd = func(d *decoder[T], xf *decFnInfo, xrv reflect.Value) { - xfnf2(d, xf, rvConvert(xrv, xrt)) - } - } else { - fi.addrD = true - fi.addrDf = false // meaning it can be an address(ptr) or a value - xptr2rt := reflect.PointerTo(xrt) - fn.fd = func(d *decoder[T], xf *decFnInfo, xrv reflect.Value) { - if xrv.Kind() == reflect.Ptr { - xfnf2(d, xf, rvConvert(xrv, xptr2rt)) - } else { - xfnf2(d, xf, rvConvert(xrv, xrt)) - } - } - } - } - } - } - if fn.fd == nil { - switch rk { - case reflect.Bool: - fn.fd = (*decoder[T]).kBool - case reflect.String: - fn.fd = (*decoder[T]).kString - case reflect.Int: - fn.fd = (*decoder[T]).kInt - case reflect.Int8: - fn.fd = (*decoder[T]).kInt8 - case reflect.Int16: - fn.fd = (*decoder[T]).kInt16 - case reflect.Int32: - fn.fd = (*decoder[T]).kInt32 - case reflect.Int64: - fn.fd = (*decoder[T]).kInt64 - case reflect.Uint: - fn.fd = (*decoder[T]).kUint - case reflect.Uint8: - fn.fd = (*decoder[T]).kUint8 - case reflect.Uint16: - fn.fd = (*decoder[T]).kUint16 - case reflect.Uint32: - fn.fd = (*decoder[T]).kUint32 - case reflect.Uint64: - fn.fd = (*decoder[T]).kUint64 - case reflect.Uintptr: - fn.fd = (*decoder[T]).kUintptr - case reflect.Float32: - fn.fd = (*decoder[T]).kFloat32 - case reflect.Float64: - fn.fd = (*decoder[T]).kFloat64 - case reflect.Complex64: - fn.fd = (*decoder[T]).kComplex64 - case reflect.Complex128: - fn.fd = (*decoder[T]).kComplex128 - case reflect.Chan: - fn.fd = (*decoder[T]).kChan - case reflect.Slice: - fn.fd = (*decoder[T]).kSlice - case reflect.Array: - fi.addrD = false // decode directly into array value (slice made from it) - fn.fd = (*decoder[T]).kArray - case reflect.Struct: - if ti.simple { - fn.fd = (*decoder[T]).kStructSimple - } else { - fn.fd = (*decoder[T]).kStruct - } - case reflect.Map: - fn.fd = (*decoder[T]).kMap - case reflect.Interface: - // encode: reflect.Interface are handled already by preEncodeValue - fn.fd = (*decoder[T]).kInterface - default: - // reflect.Ptr and reflect.Interface are handled already by preEncodeValue - fn.fd = (*decoder[T]).kErr - } - } - } - return -} diff --git a/vendor/github.com/ugorji/go/codec/doc.go b/vendor/github.com/ugorji/go/codec/doc.go deleted file mode 100644 index 750dd234a..000000000 --- a/vendor/github.com/ugorji/go/codec/doc.go +++ /dev/null @@ -1,341 +0,0 @@ -// Copyright (c) 2012-2020 Ugorji Nwoke. All rights reserved. -// Use of this source code is governed by a MIT license found in the LICENSE file. - -/* -Package codec provides a -High Performance, Feature-Rich Idiomatic Go 1.4+ codec/encoding library -for binc, msgpack, cbor, json. - -Supported Serialization formats are: - - - msgpack: https://github.com/msgpack/msgpack - - binc: http://github.com/ugorji/binc - - cbor: http://cbor.io http://tools.ietf.org/html/rfc7049 - - json: http://json.org http://tools.ietf.org/html/rfc7159 - - simple: (unpublished) - -This package will carefully use 'package unsafe' for performance reasons in specific places. -You can build without unsafe use by passing the safe or appengine tag -i.e. 'go install -tags=codec.safe ...'. - -This library works with both the standard `gc` and the `gccgo` compilers. - -For detailed usage information, read the primer at http://ugorji.net/blog/go-codec-primer . - -The idiomatic Go support is as seen in other encoding packages in -the standard library (ie json, xml, gob, etc). - -Rich Feature Set includes: - - - Simple but extremely powerful and feature-rich API - - Support for go 1.4 and above, while selectively using newer APIs for later releases - - Excellent code coverage ( > 90% ) - - Very High Performance. - Our extensive benchmarks show us outperforming Gob, Json, Bson, etc by 2-4X. - - Careful selected use of 'unsafe' for targeted performance gains. - - 100% safe mode supported, where 'unsafe' is not used at all. - - Lock-free (sans mutex) concurrency for scaling to 100's of cores - - In-place updates during decode, with option to zero value in maps and slices prior to decode - - Coerce types where appropriate - e.g. decode an int in the stream into a float, decode numbers from formatted strings, etc - - Corner Cases: - Overflows, nil maps/slices, nil values in streams are handled correctly - - Standard field renaming via tags - - Support for omitting empty fields during an encoding - - Encoding from any value and decoding into pointer to any value - (struct, slice, map, primitives, pointers, interface{}, etc) - - Extensions to support efficient encoding/decoding of any named types - - Support encoding.(Binary|Text)(M|Unm)arshaler interfaces - - Support using existence of `IsZero() bool` to determine if a value is a zero value. - Analogous to time.Time.IsZero() bool. - - Decoding without a schema (into a interface{}). - Includes Options to configure what specific map or slice type to use - when decoding an encoded list or map into a nil interface{} - - Mapping a non-interface type to an interface, so we can decode appropriately - into any interface type with a correctly configured non-interface value. - - Encode a struct as an array, and decode struct from an array in the data stream - - Option to encode struct keys as numbers (instead of strings) - (to support structured streams with fields encoded as numeric codes) - - Comprehensive support for anonymous fields - - Fast (no-reflection) encoding/decoding of common maps and slices - - Code-generation for faster performance, supported in go 1.6+ - - Support binary (e.g. messagepack, cbor) and text (e.g. json) formats - - Support indefinite-length formats to enable true streaming - (for formats which support it e.g. json, cbor) - - Support canonical encoding, where a value is ALWAYS encoded as same sequence of bytes. - This mostly applies to maps, where iteration order is non-deterministic. - - NIL in data stream decoded as zero value - - Never silently skip data when decoding. - User decides whether to return an error or silently skip data when keys or indexes - in the data stream do not map to fields in the struct. - - Detect and error when encoding a cyclic reference (instead of stack overflow shutdown) - - Encode/Decode from/to chan types (for iterative streaming support) - - Drop-in replacement for encoding/json. `json:` key in struct tag supported. - - Provides a RPC Server and Client Codec for net/rpc communication protocol. - - Handle unique idiosyncrasies of codecs e.g. - For messagepack, configure how ambiguities in handling raw bytes are resolved and - provide rpc server/client codec to support - msgpack-rpc protocol defined at: - https://github.com/msgpack-rpc/msgpack-rpc/blob/master/spec.md - -# Supported build tags - -We gain performance by code-generating fast-paths for slices and maps of built-in types, -and monomorphizing generic code explicitly so we gain inlining and de-virtualization benefits. - -The results are 20-40% performance improvements. - -Building and running is configured using build tags as below. - -At runtime: - -- codec.safe: run in safe mode (not using unsafe optimizations) -- codec.notmono: use generics code (bypassing performance-boosting monomorphized code) -- codec.notfastpath: skip fast path code for slices and maps of built-in types (number, bool, string, bytes) - -Each of these "runtime" tags have a convenience synonym i.e. safe, notmono, notfastpath. -Pls use these mostly during development - use codec.XXX in your go files. - -Build only: - -- codec.build: used to generate fastpath and monomorphization code - -Test only: - -- codec.notmammoth: skip the mammoth generated tests - -# Extension Support - -Users can register a function to handle the encoding or decoding of -their custom types. - -There are no restrictions on what the custom type can be. Some examples: - - type BisSet []int - type BitSet64 uint64 - type UUID string - type MyStructWithUnexportedFields struct { a int; b bool; c []int; } - type GifImage struct { ... } - -As an illustration, MyStructWithUnexportedFields would normally be -encoded as an empty map because it has no exported fields, while UUID -would be encoded as a string. However, with extension support, you can -encode any of these however you like. - -There is also seamless support provided for registering an extension (with a tag) -but letting the encoding mechanism default to the standard way. - -# Custom Encoding and Decoding - -This package maintains symmetry in the encoding and decoding halfs. -We determine how to encode or decode by walking this decision tree - - - is there an extension registered for the type? - - is type a codec.Selfer? - - is format binary, and is type a encoding.BinaryMarshaler and BinaryUnmarshaler? - - is format specifically json, and is type a encoding/json.Marshaler and Unmarshaler? - - is format text-based, and type an encoding.TextMarshaler and TextUnmarshaler? - - else we use a pair of functions based on the "kind" of the type e.g. map, slice, int64, etc - -This symmetry is important to reduce chances of issues happening because the -encoding and decoding sides are out of sync e.g. decoded via very specific -encoding.TextUnmarshaler but encoded via kind-specific generalized mode. - -Consequently, if a type only defines one-half of the symmetry -(e.g. it implements UnmarshalJSON() but not MarshalJSON() ), -then that type doesn't satisfy the check and we will continue walking down the -decision tree. - -# RPC - -RPC Client and Server Codecs are implemented, so the codecs can be used -with the standard net/rpc package. - -# Usage - -The Handle is SAFE for concurrent READ, but NOT SAFE for concurrent modification. - -The Encoder and Decoder are NOT safe for concurrent use. - -Consequently, the usage model is basically: - - - Create and initialize the Handle before any use. - Once created, DO NOT modify it. - - Multiple Encoders or Decoders can now use the Handle concurrently. - They only read information off the Handle (never write). - - However, each Encoder or Decoder MUST not be used concurrently - - To re-use an Encoder/Decoder, call Reset(...) on it first. - This allows you use state maintained on the Encoder/Decoder. - -Sample usage model: - - // create and configure Handle - var ( - bh codec.BincHandle - mh codec.MsgpackHandle - ch codec.CborHandle - ) - - mh.MapType = reflect.TypeOf(map[string]interface{}(nil)) - - // configure extensions - // e.g. for msgpack, define functions and enable Time support for tag 1 - // mh.SetExt(reflect.TypeOf(time.Time{}), 1, myExt) - - // create and use decoder/encoder - var ( - r io.Reader - w io.Writer - b []byte - h = &bh // or mh to use msgpack - ) - - dec = codec.NewDecoder(r, h) - dec = codec.NewDecoderBytes(b, h) - err = dec.Decode(&v) - - enc = codec.NewEncoder(w, h) - enc = codec.NewEncoderBytes(&b, h) - err = enc.Encode(v) - - //RPC Server - go func() { - for { - conn, err := listener.Accept() - rpcCodec := codec.GoRpc.ServerCodec(conn, h) - //OR rpcCodec := codec.MsgpackSpecRpc.ServerCodec(conn, h) - rpc.ServeCodec(rpcCodec) - } - }() - - //RPC Communication (client side) - conn, err = net.Dial("tcp", "localhost:5555") - rpcCodec := codec.GoRpc.ClientCodec(conn, h) - //OR rpcCodec := codec.MsgpackSpecRpc.ClientCodec(conn, h) - client := rpc.NewClientWithCodec(rpcCodec) - -# Running Tests - -To run tests, use the following: - - go test - -To run the full suite of tests, use the following: - - go test -tags alltests -run Suite - -You can run the tag 'codec.safe' to run tests or build in safe mode. e.g. - - go test -tags codec.safe -run Json - go test -tags "alltests codec.safe" -run Suite - -You can run the tag 'codec.notmono' to build bypassing the monomorphized code e.g. - - go test -tags codec.notmono -run Json - -Running Benchmarks - - cd bench - go test -bench . -benchmem -benchtime 1s - -Please see http://github.com/ugorji/go-codec-bench . - -# Caveats - -Struct fields matching the following are ignored during encoding and decoding - - struct tag value set to - - - func, complex numbers, unsafe pointers - - unexported and not embedded - - unexported and embedded and not struct kind - - unexported and embedded pointers (from go1.10) - -Every other field in a struct will be encoded/decoded. - -Embedded fields are encoded as if they exist in the top-level struct, -with some caveats. See Encode documentation. -*/ -package codec - -/* -Generics - -Generics are used across to board to reduce boilerplate, and hopefully -improve performance by -- reducing need for interface calls (de-virtualization) -- resultant inlining of those calls - -encoder/decoder --> Driver (json/cbor/...) --> input/output (bytes or io abstraction) - -There are 2 * 5 * 2 (20) combinations of monomorphized values. - -Key rules -- do not use top-level generic functions. - Due to type inference, monomorphizing them proves challenging -- only use generic methods. - Monomorphizing is done at the type once, and method names need not change -- do not have method calls have a parameter of an encWriter or decReader. - All those calls are handled directly by the driver. -- Include a helper type for each parameterized thing, and add all generic functions to them e.g. - helperEncWriter[T encWriter] - helperEncReader[T decReader] - helperEncDriver[T encDriver] - helperDecDriver[T decDriver] -- Always use T as the generic type name (when needed) -- No inline types -- No closures taking parameters of generic types - -*/ -/* -Naming convention: - -Currently, as generic and non-generic types/functions/vars are put in the same files, -we suffer because: -- build takes longer as non-generic code is built when a build tag wants only monomorphised code -- files have many lines which are not used at runtime (due to type parameters) -- code coverage is inaccurate on a single run - -To resolve this, we are streamlining our file naming strategy. - -Basically, we will have the following nomenclature for filenames: -- fastpath (tag:notfastpath): *.notfastpath.*.go vs *.fastpath.*.go -- typed parameters (tag:notmono): *.notmono.*.go vs *.mono.*.go -- safe (tag:safe): *.safe.*.go vs *.unsafe.go -- generated files: *.generated.go -- all others (tags:N/A): *.go without safe/mono/fastpath/generated in the name - -The following files will be affected and split/renamed accordingly - -Base files: -- binc.go -- cbor.go -- json.go -- msgpack.go -- simple.go -- decode.go -- encode.go - -For each base file, split into __file__.go (containing type parameters) and __file__.base.go. -__file__.go will only build with notmono. - -Other files: -- fastpath.generated.go -> base.fastpath.generated.go and base.fastpath.notmono.generated.go -- fastpath.not.go -> base.notfastpath.go -- init.go -> init.notmono.go - -Appropriate build tags will be included in the files, and the right ones only used for -monomorphization. -*/ -/* -Caching Handle options for fast runtime use - -If using cached values from Handle options, then -- re-cache them at each reset() call -- reset is always called at the start of each (Must)(En|De)code - - which calls (en|de)coder.reset([]byte|io.Reader|String) - - which calls (en|de)cDriver.reset() -- at reset, (en|de)c(oder|Driver) can re-cache Handle options before each run - -Some examples: -- json: e.rawext,di,d,ks,is / d.rawext -- decode: (decoderBase) d.jsms,mtr,str, -*/ diff --git a/vendor/github.com/ugorji/go/codec/encode.base.go b/vendor/github.com/ugorji/go/codec/encode.base.go deleted file mode 100644 index 0ded90465..000000000 --- a/vendor/github.com/ugorji/go/codec/encode.base.go +++ /dev/null @@ -1,461 +0,0 @@ -// Copyright (c) 2012-2020 Ugorji Nwoke. All rights reserved. -// Use of this source code is governed by a MIT license found in the LICENSE file. - -package codec - -import ( - "cmp" - "errors" - "io" - "reflect" - "slices" - "sync" - "time" -) - -var errEncoderNotInitialized = errors.New("encoder not initialized") - -var encBuiltinRtids []uintptr - -func init() { - for _, v := range []interface{}{ - (string)(""), - (bool)(false), - (int)(0), - (int8)(0), - (int16)(0), - (int32)(0), - (int64)(0), - (uint)(0), - (uint8)(0), - (uint16)(0), - (uint32)(0), - (uint64)(0), - (uintptr)(0), - (float32)(0), - (float64)(0), - (complex64)(0), - (complex128)(0), - (time.Time{}), - ([]byte)(nil), - (Raw{}), - // (interface{})(nil), - } { - t := reflect.TypeOf(v) - encBuiltinRtids = append(encBuiltinRtids, rt2id(t), rt2id(reflect.PointerTo(t))) - } - slices.Sort(encBuiltinRtids) -} - -// encDriver abstracts the actual codec (binc vs msgpack, etc) -type encDriverI interface { - EncodeNil() - EncodeInt(i int64) - EncodeUint(i uint64) - EncodeBool(b bool) - EncodeFloat32(f float32) - EncodeFloat64(f float64) - // re is never nil - EncodeRawExt(re *RawExt) - // ext is never nil - EncodeExt(v interface{}, basetype reflect.Type, xtag uint64, ext Ext) - // EncodeString using cUTF8, honor'ing StringToRaw flag - EncodeString(v string) - EncodeStringNoEscape4Json(v string) - // encode a non-nil []byte - EncodeStringBytesRaw(v []byte) - // encode a []byte as nil, empty or encoded sequence of bytes depending on context - EncodeBytes(v []byte) - EncodeTime(time.Time) - WriteArrayStart(length int) - WriteArrayEnd() - WriteMapStart(length int) - WriteMapEnd() - - // these write a zero-len map or array into the stream - WriteMapEmpty() - WriteArrayEmpty() - - writeNilMap() - writeNilArray() - writeNilBytes() - - // these are no-op except for json - encDriverContainerTracker - - // reset will reset current encoding runtime state, and cached information from the handle - reset() - - atEndOfEncode() - writerEnd() - - writeBytesAsis(b []byte) - // writeStringAsisDblQuoted(v string) - - resetOutBytes(out *[]byte) - resetOutIO(out io.Writer) - - init(h Handle, shared *encoderBase, enc encoderI) (fp interface{}) - - // driverStateManager -} - -type encInit2er struct{} - -func (encInit2er) init2(enc encoderI) {} - -type encDriverContainerTracker interface { - WriteArrayElem(firstTime bool) - WriteMapElemKey(firstTime bool) - WriteMapElemValue() -} - -type encDriverNoState struct{} - -// func (encDriverNoState) captureState() interface{} { return nil } -// func (encDriverNoState) resetState() {} -// func (encDriverNoState) restoreState(v interface{}) {} -func (encDriverNoState) reset() {} - -type encDriverNoopContainerWriter struct{} - -func (encDriverNoopContainerWriter) WriteArrayStart(length int) {} -func (encDriverNoopContainerWriter) WriteArrayEnd() {} -func (encDriverNoopContainerWriter) WriteMapStart(length int) {} -func (encDriverNoopContainerWriter) WriteMapEnd() {} -func (encDriverNoopContainerWriter) atEndOfEncode() {} - -// encStructFieldObj[Slice] is used for sorting when there are missing fields and canonical flag is set -type encStructFieldObj struct { - key string - rv reflect.Value - intf interface{} - isRv bool - noEsc4json bool - builtin bool -} - -type encStructFieldObjSlice []encStructFieldObj - -func (p encStructFieldObjSlice) Len() int { return len(p) } -func (p encStructFieldObjSlice) Swap(i, j int) { p[uint(i)], p[uint(j)] = p[uint(j)], p[uint(i)] } -func (p encStructFieldObjSlice) Less(i, j int) bool { - return p[uint(i)].key < p[uint(j)].key -} - -// ---- - -type orderedRv[T cmp.Ordered] struct { - v T - r reflect.Value -} - -func cmpOrderedRv[T cmp.Ordered](v1, v2 orderedRv[T]) int { - return cmp.Compare(v1.v, v2.v) -} - -// ---- - -type encFnInfo struct { - ti *typeInfo - xfFn Ext - xfTag uint64 - addrE bool - // addrEf bool // force: if addrE, then encode function MUST take a ptr -} - -// ---- - -// EncodeOptions captures configuration options during encode. -type EncodeOptions struct { - // WriterBufferSize is the size of the buffer used when writing. - // - // if > 0, we use a smart buffer internally for performance purposes. - WriterBufferSize int - - // ChanRecvTimeout is the timeout used when selecting from a chan. - // - // Configuring this controls how we receive from a chan during the encoding process. - // - If ==0, we only consume the elements currently available in the chan. - // - if <0, we consume until the chan is closed. - // - If >0, we consume until this timeout. - ChanRecvTimeout time.Duration - - // StructToArray specifies to encode a struct as an array, and not as a map - StructToArray bool - - // Canonical representation means that encoding a value will always result in the same - // sequence of bytes. - // - // This only affects maps, as the iteration order for maps is random. - // - // The implementation MAY use the natural sort order for the map keys if possible: - // - // - If there is a natural sort order (ie for number, bool, string or []byte keys), - // then the map keys are first sorted in natural order and then written - // with corresponding map values to the strema. - // - If there is no natural sort order, then the map keys will first be - // encoded into []byte, and then sorted, - // before writing the sorted keys and the corresponding map values to the stream. - // - Canonical bool - - // CheckCircularRef controls whether we check for circular references - // and error fast during an encode. - // - // If enabled, an error is received if a pointer to a struct - // references itself either directly or through one of its fields (iteratively). - // - // This is opt-in, as there may be a performance hit to checking circular references. - CheckCircularRef bool - - // RecursiveEmptyCheck controls how we determine whether a value is empty. - // - // If true, we descend into interfaces and pointers to reursively check if value is empty. - // - // We *might* check struct fields one by one to see if empty - // (if we cannot directly check if a struct value is equal to its zero value). - // If so, we honor IsZero, Comparable, IsCodecEmpty(), etc. - // Note: This *may* make OmitEmpty more expensive due to the large number of reflect calls. - // - // If false, we check if the value is equal to its zero value (newly allocated state). - RecursiveEmptyCheck bool - - // Raw controls whether we encode Raw values. - // This is a "dangerous" option and must be explicitly set. - // If set, we blindly encode Raw values as-is, without checking - // if they are a correct representation of a value in that format. - // If unset, we error out. - Raw bool - - // StringToRaw controls how strings are encoded. - // - // As a go string is just an (immutable) sequence of bytes, - // it can be encoded either as raw bytes or as a UTF string. - // - // By default, strings are encoded as UTF-8. - // but can be treated as []byte during an encode. - // - // Note that things which we know (by definition) to be UTF-8 - // are ALWAYS encoded as UTF-8 strings. - // These include encoding.TextMarshaler, time.Format calls, struct field names, etc. - StringToRaw bool - - // OptimumSize controls whether we optimize for the smallest size. - // - // Some formats will use this flag to determine whether to encode - // in the smallest size possible, even if it takes slightly longer. - // - // For example, some formats that support half-floats might check if it is possible - // to store a float64 as a half float. Doing this check has a small performance cost, - // but the benefit is that the encoded message will be smaller. - OptimumSize bool - - // NoAddressableReadonly controls whether we try to force a non-addressable value - // to be addressable so we can call a pointer method on it e.g. for types - // that support Selfer, json.Marshaler, etc. - // - // Use it in the very rare occurrence that your types modify a pointer value when calling - // an encode callback function e.g. JsonMarshal, TextMarshal, BinaryMarshal or CodecEncodeSelf. - NoAddressableReadonly bool - - // NilCollectionToZeroLength controls whether we encode nil collections (map, slice, chan) - // as nil (e.g. null if using JSON) or as zero length collections (e.g. [] or {} if using JSON). - // - // This is useful in many scenarios e.g. - // - encoding in go, but decoding the encoded stream in python - // where context of the type is missing but needed - // - // Note: this flag ignores the MapBySlice tag, and will encode nil slices, maps and chan - // in their natural zero-length formats e.g. a slice in json encoded as [] - // (and not nil or {} if MapBySlice tag). - NilCollectionToZeroLength bool -} - -// --------------------------------------------- - -// encoderBase is shared as a field between Encoder and its encDrivers. -// This way, encDrivers need not hold a referece to the Encoder itself. -type encoderBase struct { - perType encPerType - - h *BasicHandle - - // MARKER: these fields below should belong directly in Encoder. - // There should not be any pointers here - just values. - // we pack them here for space efficiency and cache-line optimization. - - rtidFn, rtidFnNoExt *atomicRtidFnSlice - - // se encoderI - err error - - blist bytesFreeList - - // js bool // is json encoder? - // be bool // is binary encoder? - - bytes bool - - c containerState - - calls uint16 - seq uint16 // sequencer (e.g. used by binc for symbols, etc) - - // ---- cpu cache line boundary - hh Handle - - // ---- cpu cache line boundary - - // ---- writable fields during execution --- *try* to keep in sep cache line - - ci circularRefChecker - - slist sfiRvFreeList -} - -func (e *encoderBase) HandleName() string { - return e.hh.Name() -} - -// Release is a no-op. -// -// Deprecated: Pooled resources are not used with an Encoder. -// This method is kept for compatibility reasons only. -func (e *encoderBase) Release() { -} - -func (e *encoderBase) setContainerState(cs containerState) { - if cs != 0 { - e.c = cs - } -} - -func (e *encoderBase) haltOnMbsOddLen(length int) { - if length&1 != 0 { // similar to &1==1 or %2 == 1 - halt.errorInt("mapBySlice requires even slice length, but got ", int64(length)) - } -} - -// addrRV returns a addressable value given that rv is not addressable -func (e *encoderBase) addrRV(rv reflect.Value, typ, ptrType reflect.Type) (rva reflect.Value) { - // if rv.CanAddr() { - // return rvAddr(rv, ptrType) - // } - if e.h.NoAddressableReadonly { - rva = reflect.New(typ) - rvSetDirect(rva.Elem(), rv) - return - } - return rvAddr(e.perType.AddressableRO(rv), ptrType) -} - -func (e *encoderBase) wrapErr(v error, err *error) { - *err = wrapCodecErr(v, e.hh.Name(), 0, true) -} - -func (e *encoderBase) kErr(_ *encFnInfo, rv reflect.Value) { - halt.errorf("unsupported encoding kind: %s, for %#v", rv.Kind(), any(rv)) -} - -func chanToSlice(rv reflect.Value, rtslice reflect.Type, timeout time.Duration) (rvcs reflect.Value) { - rvcs = rvZeroK(rtslice, reflect.Slice) - if timeout < 0 { // consume until close - for { - recv, recvOk := rv.Recv() - if !recvOk { - break - } - rvcs = reflect.Append(rvcs, recv) - } - } else { - cases := make([]reflect.SelectCase, 2) - cases[0] = reflect.SelectCase{Dir: reflect.SelectRecv, Chan: rv} - if timeout == 0 { - cases[1] = reflect.SelectCase{Dir: reflect.SelectDefault} - } else { - tt := time.NewTimer(timeout) - cases[1] = reflect.SelectCase{Dir: reflect.SelectRecv, Chan: reflect.ValueOf(tt.C)} - } - for { - chosen, recv, recvOk := reflect.Select(cases) - if chosen == 1 || !recvOk { - break - } - rvcs = reflect.Append(rvcs, recv) - } - } - return -} - -type encoderI interface { - Encode(v interface{}) error - MustEncode(v interface{}) - Release() - Reset(w io.Writer) - ResetBytes(out *[]byte) - - wrapErr(v error, err *error) - atEndOfEncode() - writerEnd() - - encodeI(v interface{}) - encodeR(v reflect.Value) - encodeAs(v interface{}, t reflect.Type, ext bool) - - setContainerState(cs containerState) // needed for canonical encoding via side encoder -} - -var errEncNoResetBytesWithWriter = errors.New("cannot reset an Encoder which outputs to []byte with a io.Writer") -var errEncNoResetWriterWithBytes = errors.New("cannot reset an Encoder which outputs to io.Writer with a []byte") - -type encDriverContainerNoTrackerT struct{} - -func (encDriverContainerNoTrackerT) WriteArrayElem(firstTime bool) {} -func (encDriverContainerNoTrackerT) WriteMapElemKey(firstTime bool) {} -func (encDriverContainerNoTrackerT) WriteMapElemValue() {} - -type Encoder struct { - encoderI -} - -// NewEncoder returns an Encoder for encoding into an io.Writer. -// -// For efficiency, Users are encouraged to configure WriterBufferSize on the handle -// OR pass in a memory buffered writer (eg bufio.Writer, bytes.Buffer). -func NewEncoder(w io.Writer, h Handle) *Encoder { - return &Encoder{h.newEncoder(w)} -} - -// NewEncoderBytes returns an encoder for encoding directly and efficiently -// into a byte slice, using zero-copying to temporary slices. -// -// It will potentially replace the output byte slice pointed to. -// After encoding, the out parameter contains the encoded contents. -func NewEncoderBytes(out *[]byte, h Handle) *Encoder { - return &Encoder{h.newEncoderBytes(out)} -} - -// ---- - -func sideEncode(h Handle, p *sync.Pool, fn func(encoderI)) { - var s encoderI - if usePoolForSideEncode { - s = p.Get().(encoderI) - defer p.Put(s) - } else { - // initialization cycle error - // s = NewEncoderBytes(nil, h).encoderI - s = p.New().(encoderI) - } - fn(s) -} - -func oneOffEncode(se encoderI, v interface{}, out *[]byte, basetype reflect.Type, ext bool) { - se.ResetBytes(out) - se.encodeAs(v, basetype, ext) - se.atEndOfEncode() - se.writerEnd() - // e.sideEncoder(&bs) - // e.sideEncode(v, basetype, 0) -} diff --git a/vendor/github.com/ugorji/go/codec/encode.go b/vendor/github.com/ugorji/go/codec/encode.go deleted file mode 100644 index b203036b4..000000000 --- a/vendor/github.com/ugorji/go/codec/encode.go +++ /dev/null @@ -1,1652 +0,0 @@ -//go:build notmono || codec.notmono - -// Copyright (c) 2012-2020 Ugorji Nwoke. All rights reserved. -// Use of this source code is governed by a MIT license found in the LICENSE file. - -package codec - -import ( - "encoding" - "io" - "reflect" - "slices" - "sort" - "strconv" - "sync" - "time" -) - -type helperEncDriver[T encDriver] struct{} - -// encFn encapsulates the captured variables and the encode function. -// This way, we only do some calculations one times, and pass to the -// code block that should be called (encapsulated in a function) -// instead of executing the checks every time. -type encFn[T encDriver] struct { - i encFnInfo - fe func(*encoder[T], *encFnInfo, reflect.Value) - // _ [1]uint64 // padding (cache-aligned) -} - -type encRtidFn[T encDriver] struct { - rtid uintptr - fn *encFn[T] -} - -// Encoder writes an object to an output stream in a supported format. -// -// Encoder is NOT safe for concurrent use i.e. a Encoder cannot be used -// concurrently in multiple goroutines. -// -// However, as Encoder could be allocation heavy to initialize, a Reset method is provided -// so its state can be reused to decode new input streams repeatedly. -// This is the idiomatic way to use. -type encoder[T encDriver] struct { - dh helperEncDriver[T] - fp *fastpathEs[T] - e T - encoderBase -} - -func (e *encoder[T]) rawExt(_ *encFnInfo, rv reflect.Value) { - if re := rv2i(rv).(*RawExt); re == nil { - e.e.EncodeNil() - } else { - e.e.EncodeRawExt(re) - } -} - -func (e *encoder[T]) ext(f *encFnInfo, rv reflect.Value) { - e.e.EncodeExt(rv2i(rv), f.ti.rt, f.xfTag, f.xfFn) -} - -func (e *encoder[T]) selferMarshal(_ *encFnInfo, rv reflect.Value) { - rv2i(rv).(Selfer).CodecEncodeSelf(&Encoder{e}) -} - -func (e *encoder[T]) binaryMarshal(_ *encFnInfo, rv reflect.Value) { - bs, fnerr := rv2i(rv).(encoding.BinaryMarshaler).MarshalBinary() - e.marshalRaw(bs, fnerr) -} - -func (e *encoder[T]) textMarshal(_ *encFnInfo, rv reflect.Value) { - bs, fnerr := rv2i(rv).(encoding.TextMarshaler).MarshalText() - e.marshalUtf8(bs, fnerr) -} - -func (e *encoder[T]) jsonMarshal(_ *encFnInfo, rv reflect.Value) { - bs, fnerr := rv2i(rv).(jsonMarshaler).MarshalJSON() - e.marshalAsis(bs, fnerr) -} - -func (e *encoder[T]) raw(_ *encFnInfo, rv reflect.Value) { - e.rawBytes(rv2i(rv).(Raw)) -} - -func (e *encoder[T]) encodeComplex64(v complex64) { - if imag(v) != 0 { - halt.errorf("cannot encode complex number: %v, with imaginary values: %v", any(v), any(imag(v))) - } - e.e.EncodeFloat32(real(v)) -} - -func (e *encoder[T]) encodeComplex128(v complex128) { - if imag(v) != 0 { - halt.errorf("cannot encode complex number: %v, with imaginary values: %v", any(v), any(imag(v))) - } - e.e.EncodeFloat64(real(v)) -} - -func (e *encoder[T]) kBool(_ *encFnInfo, rv reflect.Value) { - e.e.EncodeBool(rvGetBool(rv)) -} - -func (e *encoder[T]) kTime(_ *encFnInfo, rv reflect.Value) { - e.e.EncodeTime(rvGetTime(rv)) -} - -func (e *encoder[T]) kString(_ *encFnInfo, rv reflect.Value) { - e.e.EncodeString(rvGetString(rv)) -} - -func (e *encoder[T]) kFloat32(_ *encFnInfo, rv reflect.Value) { - e.e.EncodeFloat32(rvGetFloat32(rv)) -} - -func (e *encoder[T]) kFloat64(_ *encFnInfo, rv reflect.Value) { - e.e.EncodeFloat64(rvGetFloat64(rv)) -} - -func (e *encoder[T]) kComplex64(_ *encFnInfo, rv reflect.Value) { - e.encodeComplex64(rvGetComplex64(rv)) -} - -func (e *encoder[T]) kComplex128(_ *encFnInfo, rv reflect.Value) { - e.encodeComplex128(rvGetComplex128(rv)) -} - -func (e *encoder[T]) kInt(_ *encFnInfo, rv reflect.Value) { - e.e.EncodeInt(int64(rvGetInt(rv))) -} - -func (e *encoder[T]) kInt8(_ *encFnInfo, rv reflect.Value) { - e.e.EncodeInt(int64(rvGetInt8(rv))) -} - -func (e *encoder[T]) kInt16(_ *encFnInfo, rv reflect.Value) { - e.e.EncodeInt(int64(rvGetInt16(rv))) -} - -func (e *encoder[T]) kInt32(_ *encFnInfo, rv reflect.Value) { - e.e.EncodeInt(int64(rvGetInt32(rv))) -} - -func (e *encoder[T]) kInt64(_ *encFnInfo, rv reflect.Value) { - e.e.EncodeInt(int64(rvGetInt64(rv))) -} - -func (e *encoder[T]) kUint(_ *encFnInfo, rv reflect.Value) { - e.e.EncodeUint(uint64(rvGetUint(rv))) -} - -func (e *encoder[T]) kUint8(_ *encFnInfo, rv reflect.Value) { - e.e.EncodeUint(uint64(rvGetUint8(rv))) -} - -func (e *encoder[T]) kUint16(_ *encFnInfo, rv reflect.Value) { - e.e.EncodeUint(uint64(rvGetUint16(rv))) -} - -func (e *encoder[T]) kUint32(_ *encFnInfo, rv reflect.Value) { - e.e.EncodeUint(uint64(rvGetUint32(rv))) -} - -func (e *encoder[T]) kUint64(_ *encFnInfo, rv reflect.Value) { - e.e.EncodeUint(uint64(rvGetUint64(rv))) -} - -func (e *encoder[T]) kUintptr(_ *encFnInfo, rv reflect.Value) { - e.e.EncodeUint(uint64(rvGetUintptr(rv))) -} - -func (e *encoder[T]) kSeqFn(rt reflect.Type) (fn *encFn[T]) { - // if kind is reflect.Interface, do not pre-determine the encoding type, - // because preEncodeValue may break it down to a concrete type and kInterface will bomb. - if rt = baseRT(rt); rt.Kind() != reflect.Interface { - fn = e.fn(rt) - } - return -} - -func (e *encoder[T]) kArrayWMbs(rv reflect.Value, ti *typeInfo, isSlice bool) { - var l int - if isSlice { - l = rvLenSlice(rv) - } else { - l = rv.Len() - } - if l == 0 { - e.e.WriteMapEmpty() - return - } - e.haltOnMbsOddLen(l) - e.mapStart(l >> 1) // e.mapStart(l / 2) - - var fn *encFn[T] - builtin := ti.tielem.flagEncBuiltin - if !builtin { - fn = e.kSeqFn(ti.elem) - } - - // simulate do...while, since we already handled case of 0-length - j := 0 - e.c = containerMapKey - e.e.WriteMapElemKey(true) - for { - rvv := rvArrayIndex(rv, j, ti, isSlice) - if builtin { - e.encodeIB(rv2i(baseRVRV(rvv))) - } else { - e.encodeValue(rvv, fn) - } - j++ - if j == l { - break - } - if j&1 == 0 { // j%2 == 0 { - e.c = containerMapKey - e.e.WriteMapElemKey(false) - } else { - e.mapElemValue() - } - } - e.c = 0 - e.e.WriteMapEnd() - - // for j := 0; j < l; j++ { - // if j&1 == 0 { // j%2 == 0 { - // e.mapElemKey(j == 0) - // } else { - // e.mapElemValue() - // } - // rvv := rvSliceIndex(rv, j, ti) - // if builtin { - // e.encode(rv2i(baseRVRV(rvv))) - // } else { - // e.encodeValue(rvv, fn) - // } - // } - // e.mapEnd() -} - -func (e *encoder[T]) kArrayW(rv reflect.Value, ti *typeInfo, isSlice bool) { - var l int - if isSlice { - l = rvLenSlice(rv) - } else { - l = rv.Len() - } - if l <= 0 { - e.e.WriteArrayEmpty() - return - } - e.arrayStart(l) - - var fn *encFn[T] - if !ti.tielem.flagEncBuiltin { - fn = e.kSeqFn(ti.elem) - } - - j := 0 - e.c = containerArrayElem - e.e.WriteArrayElem(true) - builtin := ti.tielem.flagEncBuiltin - for { - rvv := rvArrayIndex(rv, j, ti, isSlice) - if builtin { - e.encodeIB(rv2i(baseRVRV(rvv))) - } else { - e.encodeValue(rvv, fn) - } - j++ - if j == l { - break - } - e.c = containerArrayElem - e.e.WriteArrayElem(false) - } - - // if ti.tielem.flagEncBuiltin { - // for j := 0; j < l; j++ { - // e.arrayElem() - // e.encode(rv2i(baseRVRV(rIndex(rv, j, ti)))) - // } - // } else { - // fn := e.kSeqFn(ti.elem) - // for j := 0; j < l; j++ { - // e.arrayElem() - // e.encodeValue(rvArrayIndex(rv, j, ti), fn) - // } - // } - - e.c = 0 - e.e.WriteArrayEnd() -} - -func (e *encoder[T]) kChan(f *encFnInfo, rv reflect.Value) { - if f.ti.chandir&uint8(reflect.RecvDir) == 0 { - halt.errorStr("send-only channel cannot be encoded") - } - if !f.ti.mbs && uint8TypId == rt2id(f.ti.elem) { - e.kSliceBytesChan(rv) - return - } - rtslice := reflect.SliceOf(f.ti.elem) - rv = chanToSlice(rv, rtslice, e.h.ChanRecvTimeout) - ti := e.h.getTypeInfo(rt2id(rtslice), rtslice) - if f.ti.mbs { - e.kArrayWMbs(rv, ti, true) - } else { - e.kArrayW(rv, ti, true) - } -} - -func (e *encoder[T]) kSlice(f *encFnInfo, rv reflect.Value) { - if f.ti.mbs { - e.kArrayWMbs(rv, f.ti, true) - } else if f.ti.rtid == uint8SliceTypId || uint8TypId == rt2id(f.ti.elem) { - // 'uint8TypId == rt2id(f.ti.elem)' checks types having underlying []byte - e.e.EncodeBytes(rvGetBytes(rv)) - } else { - e.kArrayW(rv, f.ti, true) - } -} - -func (e *encoder[T]) kArray(f *encFnInfo, rv reflect.Value) { - if f.ti.mbs { - e.kArrayWMbs(rv, f.ti, false) - } else if handleBytesWithinKArray && uint8TypId == rt2id(f.ti.elem) { - e.e.EncodeStringBytesRaw(rvGetArrayBytes(rv, nil)) // bytes from array never nil - } else { - e.kArrayW(rv, f.ti, false) - } -} - -func (e *encoder[T]) kSliceBytesChan(rv reflect.Value) { - // do not use range, so that the number of elements encoded - // does not change, and encoding does not hang waiting on someone to close chan. - - bs0 := e.blist.peek(32, true) - bs := bs0 - - irv := rv2i(rv) - ch, ok := irv.(<-chan byte) - if !ok { - ch = irv.(chan byte) - } - -L1: - switch timeout := e.h.ChanRecvTimeout; { - case timeout == 0: // only consume available - for { - select { - case b := <-ch: - bs = append(bs, b) - default: - break L1 - } - } - case timeout > 0: // consume until timeout - tt := time.NewTimer(timeout) - for { - select { - case b := <-ch: - bs = append(bs, b) - case <-tt.C: - // close(tt.C) - break L1 - } - } - default: // consume until close - for b := range ch { - bs = append(bs, b) - } - } - - e.e.EncodeBytes(bs) - e.blist.put(bs) - if !byteSliceSameData(bs0, bs) { - e.blist.put(bs0) - } -} - -func (e *encoder[T]) kStructFieldKey(keyType valueType, encName string) { - // use if (not switch) block, so that branch prediction picks valueTypeString first - if keyType == valueTypeString { - e.e.EncodeString(encName) - } else if keyType == valueTypeInt { - e.e.EncodeInt(must.Int(strconv.ParseInt(encName, 10, 64))) - } else if keyType == valueTypeUint { - e.e.EncodeUint(must.Uint(strconv.ParseUint(encName, 10, 64))) - } else if keyType == valueTypeFloat { - e.e.EncodeFloat64(must.Float(strconv.ParseFloat(encName, 64))) - } else { - halt.errorStr2("invalid struct key type: ", keyType.String()) - } - // e.dh.encStructFieldKey(e.e, encName, keyType, encNameAsciiAlphaNum, e.js) -} - -func (e *encoder[T]) kStructSimple(f *encFnInfo, rv reflect.Value) { - _ = e.e // early asserts e, e.e are not nil once - tisfi := f.ti.sfi.source() - - // To bypass encodeValue, we need to handle cases where - // the field is an interface kind. To do this, we need to handle an - // interface or a pointer to an interface differently. - // - // Easiest to just delegate to encodeValue. - - chkCirRef := e.h.CheckCircularRef - var si *structFieldInfo - var j int - // use value of chkCirRef ie if true, then send the addr of the value - if f.ti.toArray || e.h.StructToArray { // toArray - if len(tisfi) == 0 { - e.e.WriteArrayEmpty() - return - } - e.arrayStart(len(tisfi)) - for j, si = range tisfi { - e.c = containerArrayElem - e.e.WriteArrayElem(j == 0) - if si.encBuiltin { - e.encodeIB(rv2i(si.fieldNoAlloc(rv, true))) - } else { - e.encodeValue(si.fieldNoAlloc(rv, !chkCirRef), nil) - } - } - e.c = 0 - e.e.WriteArrayEnd() - } else { - if len(tisfi) == 0 { - e.e.WriteMapEmpty() - return - } - if e.h.Canonical { - tisfi = f.ti.sfi.sorted() - } - e.mapStart(len(tisfi)) - for j, si = range tisfi { - e.c = containerMapKey - e.e.WriteMapElemKey(j == 0) - e.e.EncodeStringNoEscape4Json(si.encName) - e.mapElemValue() - if si.encBuiltin { - e.encodeIB(rv2i(si.fieldNoAlloc(rv, true))) - } else { - e.encodeValue(si.fieldNoAlloc(rv, !chkCirRef), nil) - } - } - e.c = 0 - e.e.WriteMapEnd() - } -} - -func (e *encoder[T]) kStruct(f *encFnInfo, rv reflect.Value) { - _ = e.e // early asserts e, e.e are not nil once - ti := f.ti - toMap := !(ti.toArray || e.h.StructToArray) - var mf map[string]interface{} - if ti.flagMissingFielder { - toMap = true - mf = rv2i(rv).(MissingFielder).CodecMissingFields() - } else if ti.flagMissingFielderPtr { - toMap = true - if rv.CanAddr() { - mf = rv2i(rvAddr(rv, ti.ptr)).(MissingFielder).CodecMissingFields() - } else { - mf = rv2i(e.addrRV(rv, ti.rt, ti.ptr)).(MissingFielder).CodecMissingFields() - } - } - newlen := len(mf) - tisfi := ti.sfi.source() - newlen += len(tisfi) - - var fkvs = e.slist.get(newlen)[:newlen] - - recur := e.h.RecursiveEmptyCheck - chkCirRef := e.h.CheckCircularRef - - var xlen int - - var kv sfiRv - var j int - var sf encStructFieldObj - if toMap { - newlen = 0 - if e.h.Canonical { - tisfi = f.ti.sfi.sorted() - } - for _, si := range tisfi { - // kv.r = si.path.field(rv, false, si.encBuiltin || !chkCirRef) - // if si.omitEmpty && isEmptyValue(kv.r, e.h.TypeInfos, recur) { - // continue - // } - if si.omitEmpty { - kv.r = si.fieldNoAlloc(rv, false) // test actual field val - if isEmptyValue(kv.r, e.h.TypeInfos, recur) { - continue - } - } else { - kv.r = si.fieldNoAlloc(rv, si.encBuiltin || !chkCirRef) - } - kv.v = si - fkvs[newlen] = kv - newlen++ - } - - var mf2s []stringIntf - if len(mf) != 0 { - mf2s = make([]stringIntf, 0, len(mf)) - for k, v := range mf { - if k == "" { - continue - } - if ti.infoFieldOmitempty && isEmptyValue(reflect.ValueOf(v), e.h.TypeInfos, recur) { - continue - } - mf2s = append(mf2s, stringIntf{k, v}) - } - } - - xlen = newlen + len(mf2s) - if xlen == 0 { - e.e.WriteMapEmpty() - goto END - } - - e.mapStart(xlen) - - // When there are missing fields, and Canonical flag is set, - // we cannot have the missing fields and struct fields sorted independently. - // We have to capture them together and sort as a unit. - - if len(mf2s) != 0 && e.h.Canonical { - mf2w := make([]encStructFieldObj, newlen+len(mf2s)) - for j = 0; j < newlen; j++ { - kv = fkvs[j] - mf2w[j] = encStructFieldObj{kv.v.encName, kv.r, nil, true, - !kv.v.encNameEscape4Json, kv.v.encBuiltin} - } - for _, v := range mf2s { - mf2w[j] = encStructFieldObj{v.v, reflect.Value{}, v.i, false, false, false} - j++ - } - sort.Sort((encStructFieldObjSlice)(mf2w)) - for j, sf = range mf2w { - e.c = containerMapKey - e.e.WriteMapElemKey(j == 0) - if ti.keyType == valueTypeString && sf.noEsc4json { - e.e.EncodeStringNoEscape4Json(sf.key) - } else { - e.kStructFieldKey(ti.keyType, sf.key) - } - e.mapElemValue() - if sf.isRv { - if sf.builtin { - e.encodeIB(rv2i(baseRVRV(sf.rv))) - } else { - e.encodeValue(sf.rv, nil) - } - } else { - if !e.encodeBuiltin(sf.intf) { - e.encodeR(reflect.ValueOf(sf.intf)) - } - //e.encodeI(sf.intf) // MARKER inlined - } - } - } else { - keytyp := ti.keyType - for j = 0; j < newlen; j++ { - kv = fkvs[j] - e.c = containerMapKey - e.e.WriteMapElemKey(j == 0) - if ti.keyType == valueTypeString && !kv.v.encNameEscape4Json { - e.e.EncodeStringNoEscape4Json(kv.v.encName) - } else { - e.kStructFieldKey(keytyp, kv.v.encName) - } - e.mapElemValue() - if kv.v.encBuiltin { - e.encodeIB(rv2i(baseRVRV(kv.r))) - } else { - e.encodeValue(kv.r, nil) - } - } - for _, v := range mf2s { - e.c = containerMapKey - e.e.WriteMapElemKey(j == 0) - e.kStructFieldKey(keytyp, v.v) - e.mapElemValue() - if !e.encodeBuiltin(v.i) { - e.encodeR(reflect.ValueOf(v.i)) - } - // e.encodeI(v.i) // MARKER inlined - j++ - } - } - - e.c = 0 - e.e.WriteMapEnd() - } else { - newlen = len(tisfi) - for i, si := range tisfi { // use unsorted array (to match sequence in struct) - // kv.r = si.path.field(rv, false, si.encBuiltin || !chkCirRef) - // kv.r = si.path.field(rv, false, !si.omitEmpty || si.encBuiltin || !chkCirRef) - if si.omitEmpty { - // use the zero value. - // if a reference or struct, set to nil (so you do not output too much) - kv.r = si.fieldNoAlloc(rv, false) // test actual field val - if isEmptyContainerValue(kv.r, e.h.TypeInfos, recur) { - kv.r = reflect.Value{} //encode as nil - } - } else { - kv.r = si.fieldNoAlloc(rv, si.encBuiltin || !chkCirRef) - } - kv.v = si - fkvs[i] = kv - } - - if newlen == 0 { - e.e.WriteArrayEmpty() - goto END - } - - // encode it all - e.arrayStart(newlen) - for j = 0; j < newlen; j++ { - e.c = containerArrayElem - e.e.WriteArrayElem(j == 0) - kv = fkvs[j] - if !kv.r.IsValid() { - e.e.EncodeNil() - } else if kv.v.encBuiltin { - e.encodeIB(rv2i(baseRVRV(kv.r))) - } else { - e.encodeValue(kv.r, nil) - } - } - e.c = 0 - e.e.WriteArrayEnd() - } - -END: - // do not use defer. Instead, use explicit pool return at end of function. - // defer has a cost we are trying to avoid. - // If there is a panic and these slices are not returned, it is ok. - e.slist.put(fkvs) -} - -func (e *encoder[T]) kMap(f *encFnInfo, rv reflect.Value) { - _ = e.e // early asserts e, e.e are not nil once - l := rvLenMap(rv) - if l == 0 { - e.e.WriteMapEmpty() - return - } - e.mapStart(l) - - // determine the underlying key and val encFn's for the map. - // This eliminates some work which is done for each loop iteration i.e. - // rv.Type(), ref.ValueOf(rt).Pointer(), then check map/list for fn. - // - // However, if kind is reflect.Interface, do not pre-determine the - // encoding type, because preEncodeValue may break it down to - // a concrete type and kInterface will bomb. - - var keyFn, valFn *encFn[T] - - ktypeKind := reflect.Kind(f.ti.keykind) - vtypeKind := reflect.Kind(f.ti.elemkind) - - rtval := f.ti.elem - rtvalkind := vtypeKind - for rtvalkind == reflect.Ptr { - rtval = rtval.Elem() - rtvalkind = rtval.Kind() - } - if rtvalkind != reflect.Interface { - valFn = e.fn(rtval) - } - - var rvv = mapAddrLoopvarRV(f.ti.elem, vtypeKind) - - rtkey := f.ti.key - var keyTypeIsString = stringTypId == rt2id(rtkey) // rtkeyid - if keyTypeIsString { - keyFn = e.fn(rtkey) - } else { - for rtkey.Kind() == reflect.Ptr { - rtkey = rtkey.Elem() - } - if rtkey.Kind() != reflect.Interface { - keyFn = e.fn(rtkey) - } - } - - if e.h.Canonical { - e.kMapCanonical(f.ti, rv, rvv, keyFn, valFn) - e.c = 0 - e.e.WriteMapEnd() - return - } - - var rvk = mapAddrLoopvarRV(f.ti.key, ktypeKind) - - var it mapIter - mapRange(&it, rv, rvk, rvv, true) - - kbuiltin := f.ti.tikey.flagEncBuiltin - vbuiltin := f.ti.tielem.flagEncBuiltin - for j := 0; it.Next(); j++ { - rv = it.Key() - e.c = containerMapKey - e.e.WriteMapElemKey(j == 0) - if keyTypeIsString { - e.e.EncodeString(rvGetString(rv)) - } else if kbuiltin { - e.encodeIB(rv2i(baseRVRV(rv))) - } else { - e.encodeValue(rv, keyFn) - } - e.mapElemValue() - rv = it.Value() - if vbuiltin { - e.encodeIB(rv2i(baseRVRV(rv))) - } else { - e.encodeValue(it.Value(), valFn) - } - } - it.Done() - - e.c = 0 - e.e.WriteMapEnd() -} - -func (e *encoder[T]) kMapCanonical(ti *typeInfo, rv, rvv reflect.Value, keyFn, valFn *encFn[T]) { - _ = e.e // early asserts e, e.e are not nil once - // The base kind of the type of the map key is sufficient for ordering. - // We only do out of band if that kind is not ordered (number or string), bool or time.Time. - // If the key is a predeclared type, directly call methods on encDriver e.g. EncodeString - // but if not, call encodeValue, in case it has an extension registered or otherwise. - rtkey := ti.key - rtkeydecl := rtkey.PkgPath() == "" && rtkey.Name() != "" // key type is predeclared - - mks := rv.MapKeys() - rtkeyKind := rtkey.Kind() - mparams := getMapReqParams(ti) - - // kfast := mapKeyFastKindFor(rtkeyKind) - // visindirect := mapStoresElemIndirect(uintptr(ti.elemsize)) - // visref := refBitset.isset(ti.elemkind) - - switch rtkeyKind { - case reflect.Bool: - // though bool keys make no sense in a map, it *could* happen. - // in that case, we MUST support it in reflection mode, - // as that is the fallback for even codecgen and others. - - // sort the keys so that false comes before true - // ie if 2 keys in order (true, false), then swap them - if len(mks) == 2 && mks[0].Bool() { - mks[0], mks[1] = mks[1], mks[0] - } - for i := range mks { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - if rtkeydecl { - e.e.EncodeBool(mks[i].Bool()) - } else { - e.encodeValueNonNil(mks[i], keyFn) - } - e.mapElemValue() - e.encodeValue(mapGet(rv, mks[i], rvv, mparams), valFn) - } - case reflect.String: - mksv := make([]orderedRv[string], len(mks)) - for i, k := range mks { - v := &mksv[i] - v.r = k - v.v = rvGetString(k) - } - slices.SortFunc(mksv, cmpOrderedRv) - for i := range mksv { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - if rtkeydecl { - e.e.EncodeString(mksv[i].v) - } else { - e.encodeValueNonNil(mksv[i].r, keyFn) - } - e.mapElemValue() - e.encodeValue(mapGet(rv, mksv[i].r, rvv, mparams), valFn) - } - case reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64, reflect.Uint, reflect.Uintptr: - mksv := make([]orderedRv[uint64], len(mks)) - for i, k := range mks { - v := &mksv[i] - v.r = k - v.v = k.Uint() - } - slices.SortFunc(mksv, cmpOrderedRv) - for i := range mksv { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - if rtkeydecl { - e.e.EncodeUint(mksv[i].v) - } else { - e.encodeValueNonNil(mksv[i].r, keyFn) - } - e.mapElemValue() - e.encodeValue(mapGet(rv, mksv[i].r, rvv, mparams), valFn) - } - case reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64, reflect.Int: - mksv := make([]orderedRv[int64], len(mks)) - for i, k := range mks { - v := &mksv[i] - v.r = k - v.v = k.Int() - } - slices.SortFunc(mksv, cmpOrderedRv) - for i := range mksv { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - if rtkeydecl { - e.e.EncodeInt(mksv[i].v) - } else { - e.encodeValueNonNil(mksv[i].r, keyFn) - } - e.mapElemValue() - e.encodeValue(mapGet(rv, mksv[i].r, rvv, mparams), valFn) - } - case reflect.Float32: - mksv := make([]orderedRv[float64], len(mks)) - for i, k := range mks { - v := &mksv[i] - v.r = k - v.v = k.Float() - } - slices.SortFunc(mksv, cmpOrderedRv) - for i := range mksv { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - if rtkeydecl { - e.e.EncodeFloat32(float32(mksv[i].v)) - } else { - e.encodeValueNonNil(mksv[i].r, keyFn) - } - e.mapElemValue() - e.encodeValue(mapGet(rv, mksv[i].r, rvv, mparams), valFn) - } - case reflect.Float64: - mksv := make([]orderedRv[float64], len(mks)) - for i, k := range mks { - v := &mksv[i] - v.r = k - v.v = k.Float() - } - slices.SortFunc(mksv, cmpOrderedRv) - for i := range mksv { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - if rtkeydecl { - e.e.EncodeFloat64(mksv[i].v) - } else { - e.encodeValueNonNil(mksv[i].r, keyFn) - } - e.mapElemValue() - e.encodeValue(mapGet(rv, mksv[i].r, rvv, mparams), valFn) - } - default: - if rtkey == timeTyp { - mksv := make([]timeRv, len(mks)) - for i, k := range mks { - v := &mksv[i] - v.r = k - v.v = rv2i(k).(time.Time) - } - slices.SortFunc(mksv, cmpTimeRv) - for i := range mksv { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeTime(mksv[i].v) - e.mapElemValue() - e.encodeValue(mapGet(rv, mksv[i].r, rvv, mparams), valFn) - } - break - } - - // out-of-band - // first encode each key to a []byte first, then sort them, then record - bs0 := e.blist.get(len(mks) * 16) - mksv := bs0 - mksbv := make([]bytesRv, len(mks)) - - sideEncode(e.hh, &e.h.sideEncPool, func(se encoderI) { - se.ResetBytes(&mksv) - for i, k := range mks { - v := &mksbv[i] - l := len(mksv) - se.setContainerState(containerMapKey) - se.encodeR(baseRVRV(k)) - se.atEndOfEncode() - se.writerEnd() - v.r = k - v.v = mksv[l:] - } - }) - - slices.SortFunc(mksbv, cmpBytesRv) - for j := range mksbv { - e.c = containerMapKey - e.e.WriteMapElemKey(j == 0) - e.e.writeBytesAsis(mksbv[j].v) - e.mapElemValue() - e.encodeValue(mapGet(rv, mksbv[j].r, rvv, mparams), valFn) - } - e.blist.put(mksv) - if !byteSliceSameData(bs0, mksv) { - e.blist.put(bs0) - } - } -} - -func (e *encoder[T]) init(h Handle) { - initHandle(h) - callMake(&e.e) - e.hh = h - e.h = h.getBasicHandle() - // e.be = e.hh.isBinary() - e.err = errEncoderNotInitialized - - // e.fp = fastpathEList[T]() - e.fp = e.e.init(h, &e.encoderBase, e).(*fastpathEs[T]) - - if e.bytes { - e.rtidFn = &e.h.rtidFnsEncBytes - e.rtidFnNoExt = &e.h.rtidFnsEncNoExtBytes - } else { - e.rtidFn = &e.h.rtidFnsEncIO - e.rtidFnNoExt = &e.h.rtidFnsEncNoExtIO - } - - e.reset() -} - -func (e *encoder[T]) reset() { - e.e.reset() - if e.ci != nil { - e.ci = e.ci[:0] - } - e.c = 0 - e.calls = 0 - e.seq = 0 - e.err = nil -} - -// Encode writes an object into a stream. -// -// Encoding can be configured via the struct tag for the fields. -// The key (in the struct tags) that we look at is configurable. -// -// By default, we look up the "codec" key in the struct field's tags, -// and fall bak to the "json" key if "codec" is absent. -// That key in struct field's tag value is the key name, -// followed by an optional comma and options. -// -// To set an option on all fields (e.g. omitempty on all fields), you -// can create a field called _struct, and set flags on it. The options -// which can be set on _struct are: -// - omitempty: so all fields are omitted if empty -// - toarray: so struct is encoded as an array -// - int: so struct key names are encoded as signed integers (instead of strings) -// - uint: so struct key names are encoded as unsigned integers (instead of strings) -// - float: so struct key names are encoded as floats (instead of strings) -// -// More details on these below. -// -// Struct values "usually" encode as maps. Each exported struct field is encoded unless: -// - the field's tag is "-", OR -// - the field is empty (empty or the zero value) and its tag specifies the "omitempty" option. -// -// When encoding as a map, the first string in the tag (before the comma) -// is the map key string to use when encoding. -// ... -// This key is typically encoded as a string. -// However, there are instances where the encoded stream has mapping keys encoded as numbers. -// For example, some cbor streams have keys as integer codes in the stream, but they should map -// to fields in a structured object. Consequently, a struct is the natural representation in code. -// For these, configure the struct to encode/decode the keys as numbers (instead of string). -// This is done with the int,uint or float option on the _struct field (see above). -// -// However, struct values may encode as arrays. This happens when: -// - StructToArray Encode option is set, OR -// - the tag on the _struct field sets the "toarray" option -// -// Note that omitempty is ignored when encoding struct values as arrays, -// as an entry must be encoded for each field, to maintain its position. -// -// Values with types that implement MapBySlice are encoded as stream maps. -// -// The empty values (for omitempty option) are false, 0, any nil pointer -// or interface value, and any array, slice, map, or string of length zero. -// -// Anonymous fields are encoded inline except: -// - the struct tag specifies a replacement name (first value) -// - the field is of an interface type -// -// Examples: -// -// // NOTE: 'json:' can be used as struct tag key, in place 'codec:' below. -// type MyStruct struct { -// _struct bool `codec:",omitempty"` //set omitempty for every field -// Field1 string `codec:"-"` //skip this field -// Field2 int `codec:"myName"` //Use key "myName" in encode stream -// Field3 int32 `codec:",omitempty"` //use key "Field3". Omit if empty. -// Field4 bool `codec:"f4,omitempty"` //use key "f4". Omit if empty. -// io.Reader //use key "Reader". -// MyStruct `codec:"my1" //use key "my1". -// MyStruct //inline it -// ... -// } -// -// type MyStruct struct { -// _struct bool `codec:",toarray"` //encode struct as an array -// } -// -// type MyStruct struct { -// _struct bool `codec:",uint"` //encode struct with "unsigned integer" keys -// Field1 string `codec:"1"` //encode Field1 key using: EncodeInt(1) -// Field2 string `codec:"2"` //encode Field2 key using: EncodeInt(2) -// } -// -// The mode of encoding is based on the type of the value. When a value is seen: -// - If a Selfer, call its CodecEncodeSelf method -// - If an extension is registered for it, call that extension function -// - If implements encoding.(Binary|Text|JSON)Marshaler, call Marshal(Binary|Text|JSON) method -// - Else encode it based on its reflect.Kind -// -// Note that struct field names and keys in map[string]XXX will be treated as symbols. -// Some formats support symbols (e.g. binc) and will properly encode the string -// only once in the stream, and use a tag to refer to it thereafter. -// -// Note that an error from an Encode call will make the Encoder unusable moving forward. -// This is because the state of the Encoder, it's output stream, etc are no longer stable. -// Any subsequent calls to Encode will trigger the same error. -func (e *encoder[T]) Encode(v interface{}) (err error) { - // tried to use closure, as runtime optimizes defer with no params. - // This seemed to be causing weird issues (like circular reference found, unexpected panic, etc). - // Also, see https://github.com/golang/go/issues/14939#issuecomment-417836139 - defer panicValToErr(e, callRecoverSentinel, &e.err, &err, debugging) - e.mustEncode(v) - return -} - -// MustEncode is like Encode, but panics if unable to Encode. -// -// Note: This provides insight to the code location that triggered the error. -// -// Note that an error from an Encode call will make the Encoder unusable moving forward. -// This is because the state of the Encoder, it's output stream, etc are no longer stable. -// Any subsequent calls to Encode will trigger the same error. -func (e *encoder[T]) MustEncode(v interface{}) { - defer panicValToErr(e, callRecoverSentinel, &e.err, nil, true) - e.mustEncode(v) - return -} - -func (e *encoder[T]) mustEncode(v interface{}) { - halt.onerror(e.err) - if e.hh == nil { - halt.onerror(errNoFormatHandle) - } - - e.calls++ - if !e.encodeBuiltin(v) { - e.encodeR(reflect.ValueOf(v)) - } - // e.encodeI(v) // MARKER inlined - e.calls-- - if e.calls == 0 { - e.e.atEndOfEncode() - e.e.writerEnd() - } -} - -func (e *encoder[T]) encodeI(iv interface{}) { - if !e.encodeBuiltin(iv) { - e.encodeR(reflect.ValueOf(iv)) - } -} - -func (e *encoder[T]) encodeIB(iv interface{}) { - if !e.encodeBuiltin(iv) { - // panic("invalid type passed to encodeBuiltin") - // halt.errorf("invalid type passed to encodeBuiltin: %T", iv) - // MARKER: calling halt.errorf pulls in fmt.Sprintf/Errorf which makes this non-inlineable - halt.errorStr("[should not happen] invalid type passed to encodeBuiltin") - } -} - -func (e *encoder[T]) encodeR(base reflect.Value) { - e.encodeValue(base, nil) -} - -func (e *encoder[T]) encodeBuiltin(iv interface{}) (ok bool) { - ok = true - switch v := iv.(type) { - case nil: - e.e.EncodeNil() - // case Selfer: - case Raw: - e.rawBytes(v) - case string: - e.e.EncodeString(v) - case bool: - e.e.EncodeBool(v) - case int: - e.e.EncodeInt(int64(v)) - case int8: - e.e.EncodeInt(int64(v)) - case int16: - e.e.EncodeInt(int64(v)) - case int32: - e.e.EncodeInt(int64(v)) - case int64: - e.e.EncodeInt(v) - case uint: - e.e.EncodeUint(uint64(v)) - case uint8: - e.e.EncodeUint(uint64(v)) - case uint16: - e.e.EncodeUint(uint64(v)) - case uint32: - e.e.EncodeUint(uint64(v)) - case uint64: - e.e.EncodeUint(v) - case uintptr: - e.e.EncodeUint(uint64(v)) - case float32: - e.e.EncodeFloat32(v) - case float64: - e.e.EncodeFloat64(v) - case complex64: - e.encodeComplex64(v) - case complex128: - e.encodeComplex128(v) - case time.Time: - e.e.EncodeTime(v) - case []byte: - e.e.EncodeBytes(v) // e.e.EncodeStringBytesRaw(v) - default: - // we can't check non-predefined types, as they might be a Selfer or extension. - ok = !skipFastpathTypeSwitchInDirectCall && e.dh.fastpathEncodeTypeSwitch(iv, e) - } - return -} - -// encodeValue will encode a value. -// -// Note that encodeValue will handle nil in the stream early, so that the -// subsequent calls i.e. kXXX methods, etc do not have to handle it themselves. -func (e *encoder[T]) encodeValue(rv reflect.Value, fn *encFn[T]) { - // MARKER: We check if value is nil here, so that the kXXX method do not have to. - // if a valid fn is passed, it MUST BE for the dereferenced type of rv - - var ciPushes int - // if e.h.CheckCircularRef { - // ciPushes = e.ci.pushRV(rv) - // } - - var rvp reflect.Value - var rvpValid bool - -RV: - switch rv.Kind() { - case reflect.Ptr: - if rvIsNil(rv) { - e.e.EncodeNil() - goto END - } - rvpValid = true - rvp = rv - rv = rv.Elem() - // fn = nil // underlying type still same - no change - if e.h.CheckCircularRef && e.ci.canPushElemKind(rv.Kind()) { - e.ci.push(rv2i(rvp)) - ciPushes++ - } - goto RV - case reflect.Interface: - if rvIsNil(rv) { - e.e.EncodeNil() - goto END - } - rvpValid = false - rvp = reflect.Value{} - rv = rv.Elem() - fn = nil // underlying type may change, so prompt a reset - goto RV - case reflect.Map: - if rvIsNil(rv) { - if e.h.NilCollectionToZeroLength { - e.e.WriteMapEmpty() - } else { - e.e.EncodeNil() - } - goto END - } - case reflect.Slice, reflect.Chan: - if rvIsNil(rv) { - if e.h.NilCollectionToZeroLength { - e.e.WriteArrayEmpty() - } else { - e.e.EncodeNil() - } - goto END - } - case reflect.Invalid, reflect.Func: - e.e.EncodeNil() - goto END - } - - if fn == nil { - fn = e.fn(rv.Type()) - } - - if !fn.i.addrE { // typically, addrE = false, so check it first - // keep rv same - } else if rvpValid { - rv = rvp - } else if rv.CanAddr() { - rv = rvAddr(rv, fn.i.ti.ptr) - } else { - rv = e.addrRV(rv, fn.i.ti.rt, fn.i.ti.ptr) - } - fn.fe(e, &fn.i, rv) - -END: - if ciPushes > 0 { - e.ci.pop(ciPushes) - } -} - -func (e *encoder[T]) encodeValueNonNil(rv reflect.Value, fn *encFn[T]) { - // only call this if a primitive (number, bool, string) OR - // a non-nil collection (map/slice/chan). - // - // Expects fn to be non-nil - if fn.i.addrE { // typically, addrE = false, so check it first - if rv.CanAddr() { - rv = rvAddr(rv, fn.i.ti.ptr) - } else { - rv = e.addrRV(rv, fn.i.ti.rt, fn.i.ti.ptr) - } - } - fn.fe(e, &fn.i, rv) -} - -func (e *encoder[T]) encodeAs(v interface{}, t reflect.Type, ext bool) { - if ext { - e.encodeValue(baseRV(v), e.fn(t)) - } else { - e.encodeValue(baseRV(v), e.fnNoExt(t)) - } -} - -func (e *encoder[T]) marshalUtf8(bs []byte, fnerr error) { - halt.onerror(fnerr) - if bs == nil { - e.e.EncodeNil() - } else { - e.e.EncodeString(stringView(bs)) - } -} - -func (e *encoder[T]) marshalAsis(bs []byte, fnerr error) { - halt.onerror(fnerr) - if bs == nil { - e.e.EncodeNil() - } else { - e.e.writeBytesAsis(bs) // e.asis(bs) - } -} - -func (e *encoder[T]) marshalRaw(bs []byte, fnerr error) { - halt.onerror(fnerr) - e.e.EncodeBytes(bs) -} - -func (e *encoder[T]) rawBytes(vv Raw) { - v := []byte(vv) - if !e.h.Raw { - halt.errorBytes("Raw values cannot be encoded: ", v) - } - e.e.writeBytesAsis(v) -} - -func (e *encoder[T]) fn(t reflect.Type) *encFn[T] { - return e.dh.encFnViaBH(t, e.rtidFn, e.h, e.fp, false) -} - -func (e *encoder[T]) fnNoExt(t reflect.Type) *encFn[T] { - return e.dh.encFnViaBH(t, e.rtidFnNoExt, e.h, e.fp, true) -} - -// ---- container tracker methods -// Note: We update the .c after calling the callback. -// -// Callbacks ie Write(Map|Array)XXX should not use the containerState. -// It is there for post-callback use. -// Instead, callbacks have a parameter to tell if first time or not. -// -// Some code is commented out below, as they are manually inlined. -// Commented code is retained here for convernience. - -func (e *encoder[T]) mapStart(length int) { - e.e.WriteMapStart(length) - e.c = containerMapStart -} - -// func (e *encoder[T]) mapElemKey(firstTime bool) { -// e.e.WriteMapElemKey(firstTime) -// e.c = containerMapKey -// } - -func (e *encoder[T]) mapElemValue() { - e.e.WriteMapElemValue() - e.c = containerMapValue -} - -// func (e *encoder[T]) mapEnd() { -// e.e.WriteMapEnd() -// e.c = 0 -// } - -func (e *encoder[T]) arrayStart(length int) { - e.e.WriteArrayStart(length) - e.c = containerArrayStart -} - -// func (e *encoder[T]) arrayElem(firstTime bool) { -// e.e.WriteArrayElem(firstTime) -// e.c = containerArrayElem -// } - -// func (e *encoder[T]) arrayEnd() { -// e.e.WriteArrayEnd() -// e.c = 0 -// } - -// ---------- - -func (e *encoder[T]) writerEnd() { - e.e.writerEnd() -} - -func (e *encoder[T]) atEndOfEncode() { - e.e.atEndOfEncode() -} - -// Reset resets the Encoder with a new output stream. -// -// This accommodates using the state of the Encoder, -// where it has "cached" information about sub-engines. -func (e *encoder[T]) Reset(w io.Writer) { - if e.bytes { - halt.onerror(errEncNoResetBytesWithWriter) - } - e.reset() - if w == nil { - w = io.Discard - } - e.e.resetOutIO(w) -} - -// ResetBytes resets the Encoder with a new destination output []byte. -func (e *encoder[T]) ResetBytes(out *[]byte) { - if !e.bytes { - halt.onerror(errEncNoResetWriterWithBytes) - } - e.resetBytes(out) -} - -// only call this iff you are sure it is a bytes encoder -func (e *encoder[T]) resetBytes(out *[]byte) { - e.reset() - if out == nil { - out = &bytesEncAppenderDefOut - } - e.e.resetOutBytes(out) -} - -// ---- - -func (helperEncDriver[T]) newEncoderBytes(out *[]byte, h Handle) *encoder[T] { - var c1 encoder[T] - c1.bytes = true - c1.init(h) - c1.ResetBytes(out) - return &c1 -} - -func (helperEncDriver[T]) newEncoderIO(out io.Writer, h Handle) *encoder[T] { - var c1 encoder[T] - c1.bytes = false - c1.init(h) - c1.Reset(out) - return &c1 -} - -func (helperEncDriver[T]) encFnloadFastpathUnderlying(ti *typeInfo, fp *fastpathEs[T]) (f *fastpathE[T], u reflect.Type) { - rtid := rt2id(ti.fastpathUnderlying) - idx, ok := fastpathAvIndex(rtid) - if !ok { - return - } - f = &fp[idx] - if uint8(reflect.Array) == ti.kind { - u = reflect.ArrayOf(ti.rt.Len(), ti.elem) - } else { - u = f.rt - } - return -} - -// ---- - -func (helperEncDriver[T]) encFindRtidFn(s []encRtidFn[T], rtid uintptr) (i uint, fn *encFn[T]) { - // binary search. Adapted from sort/search.go. Use goto (not for loop) to allow inlining. - var h uint // var h, i uint - var j = uint(len(s)) -LOOP: - if i < j { - h = (i + j) >> 1 // avoid overflow when computing h // h = i + (j-i)/2 - if s[h].rtid < rtid { - i = h + 1 - } else { - j = h - } - goto LOOP - } - if i < uint(len(s)) && s[i].rtid == rtid { - fn = s[i].fn - } - return -} - -func (helperEncDriver[T]) encFromRtidFnSlice(fns *atomicRtidFnSlice) (s []encRtidFn[T]) { - if v := fns.load(); v != nil { - s = *(lowLevelToPtr[[]encRtidFn[T]](v)) - } - return -} - -func (dh helperEncDriver[T]) encFnViaBH(rt reflect.Type, fns *atomicRtidFnSlice, - x *BasicHandle, fp *fastpathEs[T], checkExt bool) (fn *encFn[T]) { - return dh.encFnVia(rt, fns, x.typeInfos(), &x.mu, x.extHandle, fp, - checkExt, x.CheckCircularRef, x.timeBuiltin, x.binaryHandle, x.jsonHandle) -} - -func (dh helperEncDriver[T]) encFnVia(rt reflect.Type, fns *atomicRtidFnSlice, - tinfos *TypeInfos, mu *sync.Mutex, exth extHandle, fp *fastpathEs[T], - checkExt, checkCircularRef, timeBuiltin, binaryEncoding, json bool) (fn *encFn[T]) { - rtid := rt2id(rt) - var sp []encRtidFn[T] = dh.encFromRtidFnSlice(fns) - if sp != nil { - _, fn = dh.encFindRtidFn(sp, rtid) - } - if fn == nil { - fn = dh.encFnViaLoader(rt, rtid, fns, tinfos, mu, exth, fp, checkExt, checkCircularRef, timeBuiltin, binaryEncoding, json) - } - return -} - -func (dh helperEncDriver[T]) encFnViaLoader(rt reflect.Type, rtid uintptr, fns *atomicRtidFnSlice, - tinfos *TypeInfos, mu *sync.Mutex, exth extHandle, fp *fastpathEs[T], - checkExt, checkCircularRef, timeBuiltin, binaryEncoding, json bool) (fn *encFn[T]) { - - fn = dh.encFnLoad(rt, rtid, tinfos, exth, fp, checkExt, checkCircularRef, timeBuiltin, binaryEncoding, json) - var sp []encRtidFn[T] - mu.Lock() - sp = dh.encFromRtidFnSlice(fns) - // since this is an atomic load/store, we MUST use a different array each time, - // else we have a data race when a store is happening simultaneously with a encFindRtidFn call. - if sp == nil { - sp = []encRtidFn[T]{{rtid, fn}} - fns.store(ptrToLowLevel(&sp)) - } else { - idx, fn2 := dh.encFindRtidFn(sp, rtid) - if fn2 == nil { - sp2 := make([]encRtidFn[T], len(sp)+1) - copy(sp2[idx+1:], sp[idx:]) - copy(sp2, sp[:idx]) - sp2[idx] = encRtidFn[T]{rtid, fn} - fns.store(ptrToLowLevel(&sp2)) - } - } - mu.Unlock() - return -} - -func (dh helperEncDriver[T]) encFnLoad(rt reflect.Type, rtid uintptr, tinfos *TypeInfos, - exth extHandle, fp *fastpathEs[T], - checkExt, checkCircularRef, timeBuiltin, binaryEncoding, json bool) (fn *encFn[T]) { - fn = new(encFn[T]) - fi := &(fn.i) - ti := tinfos.get(rtid, rt) - fi.ti = ti - rk := reflect.Kind(ti.kind) - - // anything can be an extension except the built-in ones: time, raw and rawext. - // ensure we check for these types, then if extension, before checking if - // it implementes one of the pre-declared interfaces. - - // fi.addrEf = true - - if rtid == timeTypId && timeBuiltin { - fn.fe = (*encoder[T]).kTime - } else if rtid == rawTypId { - fn.fe = (*encoder[T]).raw - } else if rtid == rawExtTypId { - fn.fe = (*encoder[T]).rawExt - fi.addrE = true - } else if xfFn := exth.getExt(rtid, checkExt); xfFn != nil { - fi.xfTag, fi.xfFn = xfFn.tag, xfFn.ext - fn.fe = (*encoder[T]).ext - if rk == reflect.Struct || rk == reflect.Array { - fi.addrE = true - } - } else if ti.flagSelfer || ti.flagSelferPtr { - fn.fe = (*encoder[T]).selferMarshal - fi.addrE = ti.flagSelferPtr - } else if supportMarshalInterfaces && binaryEncoding && - (ti.flagBinaryMarshaler || ti.flagBinaryMarshalerPtr) && - (ti.flagBinaryUnmarshaler || ti.flagBinaryUnmarshalerPtr) { - fn.fe = (*encoder[T]).binaryMarshal - fi.addrE = ti.flagBinaryMarshalerPtr - } else if supportMarshalInterfaces && !binaryEncoding && json && - (ti.flagJsonMarshaler || ti.flagJsonMarshalerPtr) && - (ti.flagJsonUnmarshaler || ti.flagJsonUnmarshalerPtr) { - //If JSON, we should check JSONMarshal before textMarshal - fn.fe = (*encoder[T]).jsonMarshal - fi.addrE = ti.flagJsonMarshalerPtr - } else if supportMarshalInterfaces && !binaryEncoding && - (ti.flagTextMarshaler || ti.flagTextMarshalerPtr) && - (ti.flagTextUnmarshaler || ti.flagTextUnmarshalerPtr) { - fn.fe = (*encoder[T]).textMarshal - fi.addrE = ti.flagTextMarshalerPtr - } else { - if fastpathEnabled && (rk == reflect.Map || rk == reflect.Slice || rk == reflect.Array) { - // by default (without using unsafe), - // if an array is not addressable, converting from an array to a slice - // requires an allocation (see helper_not_unsafe.go: func rvGetSlice4Array). - // - // (Non-addressable arrays mostly occur as keys/values from a map). - // - // However, fastpath functions are mostly for slices of numbers or strings, - // which are small by definition and thus allocation should be fast/cheap in time. - // - // Consequently, the value of doing this quick allocation to elide the overhead cost of - // non-optimized (not-unsafe) reflection is a fair price. - var rtid2 uintptr - if !ti.flagHasPkgPath { // un-named type (slice or mpa or array) - rtid2 = rtid - if rk == reflect.Array { - rtid2 = rt2id(ti.key) // ti.key for arrays = reflect.SliceOf(ti.elem) - } - if idx, ok := fastpathAvIndex(rtid2); ok { - fn.fe = fp[idx].encfn - } - } else { // named type (with underlying type of map or slice or array) - // try to use mapping for underlying type - xfe, xrt := dh.encFnloadFastpathUnderlying(ti, fp) - if xfe != nil { - xfnf := xfe.encfn - fn.fe = func(e *encoder[T], xf *encFnInfo, xrv reflect.Value) { - xfnf(e, xf, rvConvert(xrv, xrt)) - } - } - } - } - if fn.fe == nil { - switch rk { - case reflect.Bool: - fn.fe = (*encoder[T]).kBool - case reflect.String: - // Do not use different functions based on StringToRaw option, as that will statically - // set the function for a string type, and if the Handle is modified thereafter, - // behaviour is non-deterministic - // i.e. DO NOT DO: - // if x.StringToRaw { - // fn.fe = (*encoder[T]).kStringToRaw - // } else { - // fn.fe = (*encoder[T]).kStringEnc - // } - - fn.fe = (*encoder[T]).kString - case reflect.Int: - fn.fe = (*encoder[T]).kInt - case reflect.Int8: - fn.fe = (*encoder[T]).kInt8 - case reflect.Int16: - fn.fe = (*encoder[T]).kInt16 - case reflect.Int32: - fn.fe = (*encoder[T]).kInt32 - case reflect.Int64: - fn.fe = (*encoder[T]).kInt64 - case reflect.Uint: - fn.fe = (*encoder[T]).kUint - case reflect.Uint8: - fn.fe = (*encoder[T]).kUint8 - case reflect.Uint16: - fn.fe = (*encoder[T]).kUint16 - case reflect.Uint32: - fn.fe = (*encoder[T]).kUint32 - case reflect.Uint64: - fn.fe = (*encoder[T]).kUint64 - case reflect.Uintptr: - fn.fe = (*encoder[T]).kUintptr - case reflect.Float32: - fn.fe = (*encoder[T]).kFloat32 - case reflect.Float64: - fn.fe = (*encoder[T]).kFloat64 - case reflect.Complex64: - fn.fe = (*encoder[T]).kComplex64 - case reflect.Complex128: - fn.fe = (*encoder[T]).kComplex128 - case reflect.Chan: - fn.fe = (*encoder[T]).kChan - case reflect.Slice: - fn.fe = (*encoder[T]).kSlice - case reflect.Array: - fn.fe = (*encoder[T]).kArray - case reflect.Struct: - if ti.simple { - fn.fe = (*encoder[T]).kStructSimple - } else { - fn.fe = (*encoder[T]).kStruct - } - case reflect.Map: - fn.fe = (*encoder[T]).kMap - case reflect.Interface: - // encode: reflect.Interface are handled already by preEncodeValue - fn.fe = (*encoder[T]).kErr - default: - // reflect.Ptr and reflect.Interface are handled already by preEncodeValue - fn.fe = (*encoder[T]).kErr - } - } - } - return -} diff --git a/vendor/github.com/ugorji/go/codec/fastpath.go.tmpl b/vendor/github.com/ugorji/go/codec/fastpath.go.tmpl deleted file mode 100644 index db60ea837..000000000 --- a/vendor/github.com/ugorji/go/codec/fastpath.go.tmpl +++ /dev/null @@ -1,134 +0,0 @@ -//go:build !notfastpath && !codec.notfastpath - -// Copyright (c) 2012-2020 Ugorji Nwoke. All rights reserved. -// Use of this source code is governed by a MIT license found in the LICENSE file. - -// Code generated from fastpath.go.tmpl - DO NOT EDIT. - -package codec - -// Fast path functions try to create a fast path encode or decode implementation -// for common maps and slices. -// -// We define the functions and register them in this single file -// so as not to pollute the encode.go and decode.go, and create a dependency in there. -// This file can be omitted without causing a build failure. -// -// The advantage of fast paths is: -// - Many calls bypass reflection altogether -// -// Currently support -// - slice of all builtin types (numeric, bool, string, []byte) -// - maps of builtin types to builtin or interface{} type, EXCEPT FOR -// keys of type uintptr, int8/16/32, uint16/32, float32/64, bool, interface{} -// AND values of type type int8/16/32, uint16/32 -// This should provide adequate "typical" implementations. -// -// Note that fast track decode functions must handle values for which an address cannot be obtained. -// For example: -// m2 := map[string]int{} -// p2 := []interface{}{m2} -// // decoding into p2 will bomb if fast track functions do not treat like unaddressable. -// - -{{/* -// ---------------- -fastpathEncMapR func (mapped to type id), routes to: -- ft.EncMapV - -fastpathEncSliceR func (mapped to type id), delegates to one of: -- ft.EncSliceV -- ft.EncAsMapSliceV (when mapbyslice ie f.ti.mbs=true) - -// ---------------- -fastpathDecSliceR func (mapped to type id), delegates to: -- ft.DecSliceIntfY (when slice CAN be updated) -- ft.DecSliceIntfN (when slice CANNOT be updated e.g. from array or non-addressable slice) - -fastpathDecMapR func (mapped to type id), routes to -- ft.DecMapL (handles ptr which is changeable, and non-pointer which cannot be made if nil) - -// ---------------- -NOTE: -- fastpath typeswitch directly calls the secondary methods for builtin maps/slices with appropriate nil handling: - - except EncAsMapSliceV which only applies to wrapper types not those in the switch -- fastpathEncXXX functions mapped to type ID MUST do nil-checks during encode - - they are only called by decodeValue/encodeValue or other code (same way kMap et al are called) -*/ -}} - -import ( - "reflect" - "sort" - "slices" -) - -const fastpathEnabled = true - -{{/* -const fastpathMapBySliceErrMsg = "mapBySlice requires even slice length, but got %v" -*/ -}} - -type fastpathARtid [{{ .FastpathLen }}]uintptr - -type fastpathRtRtid struct { - rtid uintptr - rt reflect.Type -} -type fastpathARtRtid [{{ .FastpathLen }}]fastpathRtRtid - -var ( - fastpathAvRtidArr fastpathARtid - fastpathAvRtRtidArr fastpathARtRtid - fastpathAvRtid = fastpathAvRtidArr[:] - fastpathAvRtRtid = fastpathAvRtRtidArr[:] -) - -func fastpathAvIndex(rtid uintptr) (i uint, ok bool) { - return searchRtids(fastpathAvRtid, rtid) -} - -func init() { - var i uint = 0 - fn := func(v interface{}) { - xrt := reflect.TypeOf(v) - xrtid := rt2id(xrt) - xptrtid := rt2id(reflect.PointerTo(xrt)) - {{- /* only the base slice/map rtid is put in fastpathAvIndex, since we only handle slices/map/array */}} - fastpathAvRtid[i] = xrtid - fastpathAvRtRtid[i] = fastpathRtRtid{ rtid: xrtid, rt: xrt } - {{- /* fastpath type switches however handle slices/map/array, and pointers to them */}} - encBuiltinRtids = append(encBuiltinRtids, xrtid, xptrtid) - decBuiltinRtids = append(decBuiltinRtids, xrtid, xptrtid) - i++ - } - {{/* do not register []byte in fastpath */}} - {{range .Values}}{{if not .Primitive}}{{if not .MapKey -}} - fn([]{{ .Elem }}(nil)) - {{end}}{{end}}{{end}} - - {{range .Values}}{{if not .Primitive}}{{if .MapKey -}} - fn(map[{{ .MapKey }}]{{ .Elem }}(nil)) - {{end}}{{end}}{{end}} - - sort.Slice(fastpathAvRtid, func(i, j int) bool { return fastpathAvRtid[i] < fastpathAvRtid[j] }) - sort.Slice(fastpathAvRtRtid, func(i, j int) bool { return fastpathAvRtRtid[i].rtid < fastpathAvRtRtid[j].rtid }) - slices.Sort(encBuiltinRtids) - slices.Sort(decBuiltinRtids) -} - -func fastpathDecodeSetZeroTypeSwitch(iv interface{}) bool { - switch v := iv.(type) { -{{range .Values}}{{if not .Primitive}}{{if not .MapKey -}} - case *[]{{ .Elem }}: - *v = nil -{{end}}{{end}}{{end}} -{{range .Values}}{{if not .Primitive}}{{if .MapKey -}} - case *map[{{ .MapKey }}]{{ .Elem }}: - *v = nil -{{end}}{{end}}{{end}} - default: - _ = v // workaround https://github.com/golang/go/issues/12927 seen in go1.4 - return false - } - return true -} diff --git a/vendor/github.com/ugorji/go/codec/fastpath.notmono.go.tmpl b/vendor/github.com/ugorji/go/codec/fastpath.notmono.go.tmpl deleted file mode 100644 index a85a0d23a..000000000 --- a/vendor/github.com/ugorji/go/codec/fastpath.notmono.go.tmpl +++ /dev/null @@ -1,525 +0,0 @@ -//go:build !notfastpath && !codec.notfastpath && (notmono || codec.notmono) - -// Copyright (c) 2012-2020 Ugorji Nwoke. All rights reserved. -// Use of this source code is governed by a MIT license found in the LICENSE file. - -// Code generated from fastpath.notmono.go.tmpl - DO NOT EDIT. - -package codec - -import ( - "reflect" - "sort" - "slices" -) - -type fastpathE[T encDriver] struct { - rtid uintptr - rt reflect.Type - encfn func(*encoder[T], *encFnInfo, reflect.Value) -} -type fastpathD[T decDriver] struct { - rtid uintptr - rt reflect.Type - decfn func(*decoder[T], *decFnInfo, reflect.Value) -} -type fastpathEs[T encDriver] [{{ .FastpathLen }}]fastpathE[T] -type fastpathDs[T decDriver] [{{ .FastpathLen }}]fastpathD[T] - -type fastpathET[T encDriver] struct{} -type fastpathDT[T decDriver] struct{} - -func (helperEncDriver[T]) fastpathEList() *fastpathEs[T] { - var i uint = 0 - var s fastpathEs[T] - fn := func(v interface{}, fe func(*encoder[T], *encFnInfo, reflect.Value)) { - xrt := reflect.TypeOf(v) - s[i] = fastpathE[T]{rt2id(xrt), xrt, fe} - i++ - } - {{/* do not register []byte in fastpath */}} - {{range .Values}}{{if not .Primitive}}{{if not .MapKey -}} - fn([]{{ .Elem }}(nil), (*encoder[T]).{{ .MethodNamePfx "fastpathEnc" false }}R) - {{end}}{{end}}{{end}} - - {{range .Values}}{{if not .Primitive}}{{if .MapKey -}} - fn(map[{{ .MapKey }}]{{ .Elem }}(nil), (*encoder[T]).{{ .MethodNamePfx "fastpathEnc" false }}R) - {{end}}{{end}}{{end}} - - sort.Slice(s[:], func(i, j int) bool { return s[i].rtid < s[j].rtid }) - return &s -} - -func (helperDecDriver[T]) fastpathDList() *fastpathDs[T] { - var i uint = 0 - var s fastpathDs[T] - fn := func(v interface{}, fd func(*decoder[T], *decFnInfo, reflect.Value)) { - xrt := reflect.TypeOf(v) - s[i] = fastpathD[T]{rt2id(xrt), xrt, fd} - i++ - } - {{/* do not register []byte in fastpath */}} - {{range .Values}}{{if not .Primitive}}{{if not .MapKey -}} - fn([]{{ .Elem }}(nil), (*decoder[T]).{{ .MethodNamePfx "fastpathDec" false }}R) - {{end}}{{end}}{{end}} - - {{range .Values}}{{if not .Primitive}}{{if .MapKey -}} - fn(map[{{ .MapKey }}]{{ .Elem }}(nil), (*decoder[T]).{{ .MethodNamePfx "fastpathDec" false }}R) - {{end}}{{end}}{{end}} - - sort.Slice(s[:], func(i, j int) bool { return s[i].rtid < s[j].rtid }) - return &s -} - -// -- encode - -// -- -- fast path type switch -func (helperEncDriver[T]) fastpathEncodeTypeSwitch(iv interface{}, e *encoder[T]) bool { - var ft fastpathET[T] - switch v := iv.(type) { - {{range .Values}}{{if not .Primitive}}{{if not .MapKey -}} - case []{{ .Elem }}: - if v == nil { e.e.writeNilArray() } else { ft.{{ .MethodNamePfx "Enc" false }}V(v, e) } -{{end}}{{end}}{{end -}} - -{{range .Values}}{{if not .Primitive}}{{if .MapKey -}} - case map[{{ .MapKey }}]{{ .Elem }}: - if v == nil { e.e.writeNilMap() } else { ft.{{ .MethodNamePfx "Enc" false }}V(v, e) } -{{end}}{{end}}{{end -}} - - default: - _ = v // workaround https://github.com/golang/go/issues/12927 seen in go1.4 - return false - } - return true -} - -// -- -- fast path functions -{{range .Values}}{{if not .Primitive}}{{if not .MapKey -}} -func (e *encoder[T]) {{ .MethodNamePfx "fastpathEnc" false }}R(f *encFnInfo, rv reflect.Value) { - var ft fastpathET[T] - var v []{{ .Elem }} - if rv.Kind() == reflect.Array { - rvGetSlice4Array(rv, &v) - } else { - v = rv2i(rv).([]{{ .Elem }}) - } - if f.ti.mbs { - ft.{{ .MethodNamePfx "EncAsMap" false }}V(v, e) - return - } - ft.{{ .MethodNamePfx "Enc" false }}V(v, e) -} -func (fastpathET[T]) {{ .MethodNamePfx "Enc" false }}V(v []{{ .Elem }}, e *encoder[T]) { - {{ if eq .Elem "uint8" "byte" -}} - e.e.EncodeStringBytesRaw(v) - {{ else -}} - if len(v) == 0 { - e.c = 0; e.e.WriteArrayEmpty() - return - } - e.arrayStart(len(v)) - for j := range v { - e.c = containerArrayElem; e.e.WriteArrayElem(j == 0) - {{ encmd .Elem "v[j]"}} - } - e.c = 0; e.e.WriteArrayEnd() - {{ end -}} -} -func (fastpathET[T]) {{ .MethodNamePfx "EncAsMap" false }}V(v []{{ .Elem }}, e *encoder[T]) { - if len(v) == 0 { - e.c = 0; e.e.WriteMapEmpty() - return - } - e.haltOnMbsOddLen(len(v)) - e.mapStart(len(v) >> 1) // e.mapStart(len(v) / 2) - for j := range v { - if j&1 == 0 { // if j%2 == 0 { - e.c = containerMapKey; e.e.WriteMapElemKey(j == 0) - } else { - e.mapElemValue() - } - {{ encmd .Elem "v[j]"}} - } - e.c = 0; e.e.WriteMapEnd() -} - -{{end}}{{end}}{{end -}} - -{{range .Values}}{{if not .Primitive}}{{if .MapKey -}} -func (e *encoder[T]) {{ .MethodNamePfx "fastpathEnc" false }}R(f *encFnInfo, rv reflect.Value) { - {{/* var ft fastpathET[T] - ft.{{ .MethodNamePfx "Enc" false }}V(rv2i(rv).(map[{{ .MapKey }}]{{ .Elem }}), e) */ -}} - fastpathET[T]{}.{{ .MethodNamePfx "Enc" false }}V(rv2i(rv).(map[{{ .MapKey }}]{{ .Elem }}), e) -} -func (fastpathET[T]) {{ .MethodNamePfx "Enc" false }}V(v map[{{ .MapKey }}]{{ .Elem }}, e *encoder[T]) { - {{/* if v == nil { e.e.EncodeNil(); return } */ -}} - if len(v) == 0 { - e.e.WriteMapEmpty() - return - } - var i uint - e.mapStart(len(v)) - if e.h.Canonical { {{/* need to figure out .NoCanonical */}} - {{if eq .MapKey "interface{}"}}{{/* out of band */ -}} - var mksv []byte = make([]byte, 0, len(v)*16) // temporary byte slice for the encoding - e2 := NewEncoderBytes(&mksv, e.hh) - v2 := make([]bytesIntf, len(v)) - var l uint {{/* put loop variables outside. seems currently needed for better perf */}} - var vp *bytesIntf - for k2 := range v { - l = uint(len(mksv)) - e2.MustEncode(k2) - vp = &v2[i] - vp.v = mksv[l:] - vp.i = k2 - i++ - } - slices.SortFunc(v2, cmpBytesIntf) - for j := range v2 { - e.c = containerMapKey; e.e.WriteMapElemKey(j == 0) - e.asis(v2[j].v) - e.mapElemValue() - e.encode(v[v2[j].i]) - } {{else}}{{ $x := sorttype .MapKey true}}v2 := make([]{{ $x }}, len(v)) - for k := range v { - v2[i] = {{if eq $x .MapKey}}k{{else}}{{ $x }}(k){{end}} - i++ - } - slices.Sort(v2) - {{/* // sort.Sort({{ sorttype .MapKey false}}(v2)) */ -}} - for i, k2 := range v2 { - e.c = containerMapKey; e.e.WriteMapElemKey(i == 0) - {{if eq .MapKey "string"}} e.e.EncodeString(k2) {{else}}{{ $y := printf "%s(k2)" .MapKey }}{{if eq $x .MapKey }}{{ $y = "k2" }}{{end}}{{ encmd .MapKey $y }}{{end}} - e.mapElemValue() - {{ $y := printf "v[%s(k2)]" .MapKey }}{{if eq $x .MapKey }}{{ $y = "v[k2]" }}{{end}}{{ encmd .Elem $y }} - } {{end}} - } else { - i = 0 - for k2, v2 := range v { - e.c = containerMapKey; e.e.WriteMapElemKey(i == 0) - {{if eq .MapKey "string"}} e.e.EncodeString(k2) {{else}}{{ encmd .MapKey "k2"}}{{end}} - e.mapElemValue() - {{ encmd .Elem "v2"}} - i++ - } - } - e.c = 0; e.e.WriteMapEnd() -} -{{end}}{{end}}{{end -}} - -// -- decode - -// -- -- fast path type switch -func (helperDecDriver[T]) fastpathDecodeTypeSwitch(iv interface{}, d *decoder[T]) bool { - var ft fastpathDT[T] - var changed bool - var containerLen int - switch v := iv.(type) { -{{range .Values}}{{if not .Primitive}}{{if not .MapKey -}} - case []{{ .Elem }}: - ft.{{ .MethodNamePfx "Dec" false }}N(v, d) - case *[]{{ .Elem }}: - var v2 []{{ .Elem }} - if v2, changed = ft.{{ .MethodNamePfx "Dec" false }}Y(*v, d); changed { - *v = v2 - } -{{end}}{{end}}{{end -}} -{{range .Values}}{{if not .Primitive}}{{if .MapKey }}{{/* -// maps only change if nil, and in that case, there's no point copying -*/ -}} - case map[{{ .MapKey }}]{{ .Elem }}: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen != containerLenNil { - if containerLen != 0 { - ft.{{ .MethodNamePfx "Dec" false }}L(v, containerLen, d) - } - d.mapEnd() - } - case *map[{{ .MapKey }}]{{ .Elem }}: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen == containerLenNil { - *v = nil - } else { - if *v == nil { - *v = make(map[{{ .MapKey }}]{{ .Elem }}, decInferLen(containerLen, d.maxInitLen(), {{ .Size }})) - } - if containerLen != 0 { - ft.{{ .MethodNamePfx "Dec" false }}L(*v, containerLen, d) - } - d.mapEnd() - } -{{end}}{{end}}{{end -}} - default: - _ = v // workaround https://github.com/golang/go/issues/12927 seen in go1.4 - return false - } - return true -} - -// -- -- fast path functions -{{range .Values}}{{if not .Primitive}}{{if not .MapKey -}} -{{/* -Slices can change if they -- did not come from an array -- are addressable (from a ptr) -- are settable (e.g. contained in an interface{}) -*/}} -func (d *decoder[T]) {{ .MethodNamePfx "fastpathDec" false }}R(f *decFnInfo, rv reflect.Value) { - var ft fastpathDT[T] - {{/* - // seqTypeArray=true means that we are not getting a pointer, so no need to check that. - if f.seq != seqTypeArray && rv.Kind() == reflect.Ptr { - */ -}} - switch rv.Kind() { - case reflect.Ptr: {{- /* this block is called for types that wrap a fastpath type e.g. wrapSliceUint64 */}} - v := rv2i(rv).(*[]{{ .Elem }}) - if vv, changed := ft.{{ .MethodNamePfx "Dec" false }}Y(*v, d); changed { - *v = vv - } - case reflect.Array: - var v []{{ .Elem }} - rvGetSlice4Array(rv, &v) - ft.{{ .MethodNamePfx "Dec" false }}N(v, d) - default: - ft.{{ .MethodNamePfx "Dec" false }}N(rv2i(rv).([]{{ .Elem }}), d) - } -} -func (fastpathDT[T]) {{ .MethodNamePfx "Dec" false }}Y(v []{{ .Elem }}, d *decoder[T]) (v2 []{{ .Elem }}, changed bool) { - ctyp := d.d.ContainerType() - if ctyp == valueTypeNil { - return nil, v != nil - } - {{ if eq .Elem "uint8" "byte" -}} - if ctyp != valueTypeMap { - var dbi dBytesIntoState - v2, dbi = d.decodeBytesInto(v[:len(v):len(v)], false) - return v2, dbi != dBytesIntoParamOut - } - containerLenS := d.mapStart(d.d.ReadMapStart()) * 2 - {{ else -}} - var containerLenS int - isArray := ctyp == valueTypeArray - if isArray { - containerLenS = d.arrayStart(d.d.ReadArrayStart()) - } else if ctyp == valueTypeMap { - containerLenS = d.mapStart(d.d.ReadMapStart()) * 2 - } else { - halt.errorStr2("decoding into a slice, expect map/array - got ", ctyp.String()) - } - {{ end -}} - hasLen := containerLenS >= 0 - var j int - fnv := func(dst []{{ .Elem }}) { v, changed = dst, true } - for ; d.containerNext(j, containerLenS, hasLen); j++ { - if j == 0 { - if containerLenS == len(v) { - } else if containerLenS < 0 || containerLenS > cap(v) { - if xlen := int(decInferLen(containerLenS, d.maxInitLen(), {{ .Size }})); xlen <= cap(v) { - fnv(v[:uint(xlen)]) - } else { - v2 = make([]{{ .Elem }}, uint(xlen)) - copy(v2, v) - fnv(v2) - } - } else { - fnv(v[:containerLenS]) - } - } - {{ if eq .Elem "uint8" "byte" }}{{ else -}} - if isArray { d.arrayElem(j == 0) } else - {{ end -}} - if j&1 == 0 { d.mapElemKey(j == 0) } else { d.mapElemValue() } - if j >= len(v) { {{- /* // if indefinite, json, etc, then expand the slice (if necessary) */}} - fnv(append(v, {{ zerocmd .Elem }})) - } - {{ if eq .Elem "interface{}" }}d.decode(&v[uint(j)]){{ else }}v[uint(j)] = {{ decmd .Elem false }}{{ end }} - } - if j < len(v) { - fnv(v[:uint(j)]) - } else if j == 0 && v == nil { - fnv([]{{ .Elem }}{}) - } - {{ if eq .Elem "uint8" "byte" -}} - d.mapEnd() - {{ else -}} - if isArray { d.arrayEnd() } else { d.mapEnd() } - {{ end -}} - return v, changed -} -func (fastpathDT[T]) {{ .MethodNamePfx "Dec" false }}N(v []{{ .Elem }}, d *decoder[T]) { - ctyp := d.d.ContainerType() - if ctyp == valueTypeNil { - return - } - {{ if eq .Elem "uint8" "byte" -}} - if ctyp != valueTypeMap { - d.decodeBytesInto(v[:len(v):len(v)], true) - return - } - containerLenS := d.mapStart(d.d.ReadMapStart()) * 2 - {{ else -}} - var containerLenS int - isArray := ctyp == valueTypeArray - if isArray { - containerLenS = d.arrayStart(d.d.ReadArrayStart()) - } else if ctyp == valueTypeMap { - containerLenS = d.mapStart(d.d.ReadMapStart()) * 2 - } else { - halt.errorStr2("decoding into a slice, expect map/array - got ", ctyp.String()) - } - {{ end -}} - hasLen := containerLenS >= 0 - for j := 0; d.containerNext(j, containerLenS, hasLen); j++ { - {{/* // if indefinite, etc, then expand the slice if necessary */ -}} - {{ if not (eq .Elem "uint8" "byte") -}} - if isArray { d.arrayElem(j == 0) } else - {{ end -}} - if j&1 == 0 { d.mapElemKey(j == 0) } else { d.mapElemValue() } - if j < len(v) { - {{ if eq .Elem "interface{}" }}d.decode(&v[uint(j)]){{ else }}v[uint(j)] = {{ decmd .Elem false }}{{ end }} - } else { - d.arrayCannotExpand(len(v), j+1) - d.swallow() - } - } - {{ if eq .Elem "uint8" "byte" -}} - d.mapEnd() - {{ else -}} - if isArray { d.arrayEnd() } else { d.mapEnd() } - {{ end -}} -} -{{end}}{{end}}{{end -}} - -{{range .Values}}{{if not .Primitive}}{{if .MapKey -}} -{{/* -Maps can change if they are -- addressable (from a ptr) -- settable (e.g. contained in an interface{}) -*/ -}} -func (d *decoder[T]) {{ .MethodNamePfx "fastpathDec" false }}R(f *decFnInfo, rv reflect.Value) { - var ft fastpathDT[T] - containerLen := d.mapStart(d.d.ReadMapStart()) - if rv.Kind() == reflect.Ptr { {{- /* this block is called for types that wrap a fastpath type e.g. wrapMapStringUint64 */}} - vp, _ := rv2i(rv).(*map[{{ .MapKey }}]{{ .Elem }}) - if *vp == nil { - *vp = make(map[{{ .MapKey }}]{{ .Elem }}, decInferLen(containerLen, d.maxInitLen(), {{ .Size }})) - } - if containerLen != 0 { - ft.{{ .MethodNamePfx "Dec" false }}L(*vp, containerLen, d) - } - } else if containerLen != 0 { - ft.{{ .MethodNamePfx "Dec" false }}L(rv2i(rv).(map[{{ .MapKey }}]{{ .Elem }}), containerLen, d) - } - d.mapEnd() -} -func (fastpathDT[T]) {{ .MethodNamePfx "Dec" false }}L(v map[{{ .MapKey }}]{{ .Elem }}, containerLen int, d *decoder[T]) { - if v == nil { - halt.errorInt("cannot decode into nil map[{{ .MapKey }}]{{ .Elem }} given stream length: ", int64(containerLen)) - {{/* d.swallowMapContents(containerLen); return */ -}} - } - {{if eq .MapKey "interface{}" -}} - var mk {{ .MapKey }} - {{end -}} - {{ if eq .Elem "interface{}" "[]byte" "bytes" -}} - var mv {{ .Elem }} - mapGet := !d.h.MapValueReset - {{- if eq .Elem "interface{}" -}} - && !d.h.InterfaceReset - {{- end}} - {{end -}} - hasLen := containerLen >= 0 - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - {{ if eq .MapKey "interface{}" -}} - mk = nil - d.decode(&mk) - if bv, bok := mk.([]byte); bok { - mk = d.detach2Str(bv) {{/* // maps cannot have []byte as key. switch to string. */}} - }{{ else }}mk := {{ decmd .MapKey true }}{{ end }} - d.mapElemValue() - {{ if eq .Elem "interface{}" "[]byte" "bytes" -}} - if mapGet { mv = v[mk] } else { mv = nil } - {{ end -}} - {{ if eq .Elem "interface{}" -}} - d.decode(&mv) - v[mk] = mv - {{ else if eq .Elem "[]byte" "bytes" -}} - v[mk], _ = d.decodeBytesInto(mv, false) - {{ else -}} - v[mk] = {{ decmd .Elem false }} - {{ end -}} - } -} -{{end}}{{end}}{{end}} - -{{- /* - -// -- -- fast path type switch -func (helperEncDriver[T]) fastpathEncodeTypeSwitch(iv interface{}, e *encoder[T]) bool { - var ft fastpathET[T] - switch v := iv.(type) { - {{range .Values}}{{if not .Primitive}}{{if not .MapKey -}} - case []{{ .Elem }}: - if v != nil { - ft.{{ .MethodNamePfx "Enc" false }}V(v, e) - } else if e.h.NilCollectionToZeroLength { - e.e.WriteArrayEmpty() - } else { - e.e.EncodeNil() - } - case *[]{{ .Elem }}: - if *v != nil { - ft.{{ .MethodNamePfx "Enc" false }}V(*v, e) - } else if e.h.NilCollectionToZeroLength { - e.e.WriteArrayEmpty() - } else { - e.e.EncodeNil() - } -{{end}}{{end}}{{end -}} - -{{range .Values}}{{if not .Primitive}}{{if .MapKey -}} - case map[{{ .MapKey }}]{{ .Elem }}: - if v != nil { - ft.{{ .MethodNamePfx "Enc" false }}V(v, e) - } else if e.h.NilCollectionToZeroLength { - e.e.WriteMapEmpty() - } else { - e.e.EncodeNil() - } - case *map[{{ .MapKey }}]{{ .Elem }}: - if *v != nil { - ft.{{ .MethodNamePfx "Enc" false }}V(*v, e) - } else if e.h.NilCollectionToZeroLength { - e.e.WriteMapEmpty() - } else { - e.e.EncodeNil() - } -{{end}}{{end}}{{end -}} - - default: - _ = v // workaround https://github.com/golang/go/issues/12927 seen in go1.4 - return false - } - return true -} - -// used within codecgen, which is no longer supported -func (f fastpathDT[T]) {{ .MethodNamePfx "Dec" false }}X(vp *[]{{ .Elem }}, d *decoder[T]) { - if v, changed := f.{{ .MethodNamePfx "Dec" false }}Y(*vp, d); changed { *vp = v } -} - -func (f fastpathDT[T]) {{ .MethodNamePfx "Dec" false }}X(vp *map[{{ .MapKey }}]{{ .Elem }}, d *decoder[T]) { - containerLen := d.mapStart(d.d.ReadMapStart()) - if containerLen == containerLenNil { - *vp = nil - return - } - if *vp == nil { - *vp = make(map[{{ .MapKey }}]{{ .Elem }}, decInferLen(containerLen, d.maxInitLen(), {{ .Size }})) - } - if containerLen != 0 { - f.{{ .MethodNamePfx "Dec" false }}L(*vp, containerLen, d) - } - d.mapEnd() -} - -*/ -}} diff --git a/vendor/github.com/ugorji/go/codec/gen.go b/vendor/github.com/ugorji/go/codec/gen.go deleted file mode 100644 index 4e521adf8..000000000 --- a/vendor/github.com/ugorji/go/codec/gen.go +++ /dev/null @@ -1,426 +0,0 @@ -// Copyright (c) 2012-2020 Ugorji Nwoke. All rights reserved. -// Use of this source code is governed by a MIT license found in the LICENSE file. - -//go:build codec.build - -package codec - -import ( - "bytes" - "encoding/base32" - "errors" - "fmt" - "go/format" - "io" - "os" - "regexp" - "strings" - "sync" - "text/template" - // "ugorji.net/zz" -) - -// --------------------------------------------------- - -const ( - genTopLevelVarName = "x" - - // genFastpathCanonical configures whether we support Canonical in fast path. Low savings. - // - // MARKER: This MUST ALWAYS BE TRUE. fastpath.go.tmpl doesn't handle it being false. - genFastpathCanonical = true - - // genFastpathTrimTypes configures whether we trim uncommon fastpath types. - genFastpathTrimTypes = true -) - -var genFormats = []string{"Json", "Cbor", "Msgpack", "Binc", "Simple"} - -var ( - errGenAllTypesSamePkg = errors.New("All types must be in the same package") - errGenExpectArrayOrMap = errors.New("unexpected type - expecting array/map/slice") - errGenUnexpectedTypeFastpath = errors.New("fastpath: unexpected type - requires map or slice") - - // don't use base64, only 63 characters allowed in valid go identifiers - // ie ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789_ - // - // don't use numbers, as a valid go identifer must start with a letter. - genTypenameEnc = base32.NewEncoding("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdef") - genQNameRegex = regexp.MustCompile(`[A-Za-z_.]+`) -) - -// -------- - -func genCheckErr(err error) { - halt.onerror(err) -} - -func genTitleCaseName(s string) string { - switch s { - case "interface{}", "interface {}": - return "Intf" - case "[]byte", "[]uint8", "bytes": - return "Bytes" - default: - return strings.ToUpper(s[0:1]) + s[1:] - } -} - -// -------- - -type genFastpathV struct { - // genFastpathV is either a primitive (Primitive != "") or a map (MapKey != "") or a slice - MapKey string - Elem string - Primitive string - Size int - NoCanonical bool -} - -func (x *genFastpathV) MethodNamePfx(prefix string, prim bool) string { - var name []byte - if prefix != "" { - name = append(name, prefix...) - } - if prim { - name = append(name, genTitleCaseName(x.Primitive)...) - } else { - if x.MapKey == "" { - name = append(name, "Slice"...) - } else { - name = append(name, "Map"...) - name = append(name, genTitleCaseName(x.MapKey)...) - } - name = append(name, genTitleCaseName(x.Elem)...) - } - return string(name) -} - -// -------- - -type genTmpl struct { - Values []genFastpathV - Formats []string -} - -func (x genTmpl) FastpathLen() (l int) { - for _, v := range x.Values { - // if v.Primitive == "" && !(v.MapKey == "" && v.Elem == "uint8") { - if v.Primitive == "" { - l++ - } - } - return -} - -func genTmplZeroValue(s string) string { - switch s { - case "interface{}", "interface {}": - return "nil" - case "[]byte", "[]uint8", "bytes": - return "nil" - case "bool": - return "false" - case "string": - return `""` - default: - return "0" - } -} - -var genTmplNonZeroValueIdx [6]uint64 -var genTmplNonZeroValueStrs = [...][6]string{ - {`"string-is-an-interface-1"`, "true", `"some-string-1"`, `[]byte("some-string-1")`, "11.1", "111"}, - {`"string-is-an-interface-2"`, "false", `"some-string-2"`, `[]byte("some-string-2")`, "22.2", "77"}, - {`"string-is-an-interface-3"`, "true", `"some-string-3"`, `[]byte("some-string-3")`, "33.3e3", "127"}, -} - -// Note: last numbers must be in range: 0-127 (as they may be put into a int8, uint8, etc) - -func genTmplNonZeroValue(s string) string { - var i int - switch s { - case "interface{}", "interface {}": - i = 0 - case "bool": - i = 1 - case "string": - i = 2 - case "bytes", "[]byte", "[]uint8": - i = 3 - case "float32", "float64", "float", "double", "complex", "complex64", "complex128": - i = 4 - default: - i = 5 - } - genTmplNonZeroValueIdx[i]++ - idx := genTmplNonZeroValueIdx[i] - slen := uint64(len(genTmplNonZeroValueStrs)) - return genTmplNonZeroValueStrs[idx%slen][i] // return string, to remove ambiguity -} - -// Note: used for fastpath only -func genTmplEncCommandAsString(s string, vname string) string { - switch s { - case "uint64": - return "e.e.EncodeUint(" + vname + ")" - case "uint", "uint8", "uint16", "uint32": - return "e.e.EncodeUint(uint64(" + vname + "))" - case "int64": - return "e.e.EncodeInt(" + vname + ")" - case "int", "int8", "int16", "int32": - return "e.e.EncodeInt(int64(" + vname + "))" - case "[]byte", "[]uint8", "bytes": - // return fmt.Sprintf( - // "if %s != nil { e.e.EncodeStringBytesRaw(%s) } "+ - // "else if e.h.NilCollectionToZeroLength { e.e.WriteArrayEmpty() } "+ - // "else { e.e.EncodeNil() }", vname, vname) - // return "e.e.EncodeStringBytesRaw(" + vname + ")" - return "e.e.EncodeBytes(" + vname + ")" - case "string": - return "e.e.EncodeString(" + vname + ")" - case "float32": - return "e.e.EncodeFloat32(" + vname + ")" - case "float64": - return "e.e.EncodeFloat64(" + vname + ")" - case "bool": - return "e.e.EncodeBool(" + vname + ")" - // case "symbol": - // return "e.e.EncodeSymbol(" + vname + ")" - default: - return fmt.Sprintf("if !e.encodeBuiltin(%s) { e.encodeR(reflect.ValueOf(%s)) }", vname, vname) - // return "e.encodeI(" + vname + ")" - } -} - -// Note: used for fastpath only -func genTmplDecCommandAsString(s string, mapkey bool) string { - switch s { - case "uint": - return "uint(chkOvf.UintV(d.d.DecodeUint64(), uintBitsize))" - case "uint8": - return "uint8(chkOvf.UintV(d.d.DecodeUint64(), 8))" - case "uint16": - return "uint16(chkOvf.UintV(d.d.DecodeUint64(), 16))" - case "uint32": - return "uint32(chkOvf.UintV(d.d.DecodeUint64(), 32))" - case "uint64": - return "d.d.DecodeUint64()" - case "uintptr": - return "uintptr(chkOvf.UintV(d.d.DecodeUint64(), uintBitsize))" - case "int": - return "int(chkOvf.IntV(d.d.DecodeInt64(), intBitsize))" - case "int8": - return "int8(chkOvf.IntV(d.d.DecodeInt64(), 8))" - case "int16": - return "int16(chkOvf.IntV(d.d.DecodeInt64(), 16))" - case "int32": - return "int32(chkOvf.IntV(d.d.DecodeInt64(), 32))" - case "int64": - return "d.d.DecodeInt64()" - - case "string": - // if mapkey { - // return "d.stringZC(d.d.DecodeStringAsBytes())" - // } - // return "string(d.d.DecodeStringAsBytes())" - return "d.detach2Str(d.d.DecodeStringAsBytes())" - case "[]byte", "[]uint8", "bytes": - // return "bytesOk(d.d.DecodeBytes())" - return "bytesOKdbi(d.decodeBytesInto(v[uint(j)], false))" - case "float32": - return "float32(d.d.DecodeFloat32())" - case "float64": - return "d.d.DecodeFloat64()" - case "complex64": - return "complex(d.d.DecodeFloat32(), 0)" - case "complex128": - return "complex(d.d.DecodeFloat64(), 0)" - case "bool": - return "d.d.DecodeBool()" - default: - halt.error(errors.New("gen internal: unknown type for decode: " + s)) - } - return "" -} - -func genTmplSortType(s string, elem bool) string { - if elem { - return s - } - return s + "Slice" -} - -// var genTmplMu sync.Mutex -var genTmplV = genTmpl{} -var genTmplFuncs template.FuncMap -var genTmplOnce sync.Once - -func genTmplInit() { - wordSizeBytes := int(intBitsize) / 8 - - typesizes := map[string]int{ - "interface{}": 2 * wordSizeBytes, - "string": 2 * wordSizeBytes, - "[]byte": 3 * wordSizeBytes, - "uint": 1 * wordSizeBytes, - "uint8": 1, - "uint16": 2, - "uint32": 4, - "uint64": 8, - "uintptr": 1 * wordSizeBytes, - "int": 1 * wordSizeBytes, - "int8": 1, - "int16": 2, - "int32": 4, - "int64": 8, - "float32": 4, - "float64": 8, - "complex64": 8, - "complex128": 16, - "bool": 1, - } - - // keep as slice, so it is in specific iteration order. - // Initial order was uint64, string, interface{}, int, int64, ... - - var types = [...]string{ - "interface{}", - "string", - "[]byte", - "float32", - "float64", - "uint", - "uint8", - "uint16", - "uint32", - "uint64", - "uintptr", - "int", - "int8", - "int16", - "int32", - "int64", - "bool", - } - - var primitivetypes, slicetypes, mapkeytypes, mapvaltypes []string - - primitivetypes = types[:] - - slicetypes = types[:] - mapkeytypes = types[:] - mapvaltypes = types[:] - - if genFastpathTrimTypes { - // Note: we only create fastpaths for commonly used types. - // Consequently, things like int8, uint16, uint, etc are commented out. - slicetypes = []string{ - "interface{}", - "string", - "[]byte", - "float32", - "float64", - "uint8", // keep fastpath, so it doesn't have to go through reflection - "uint64", - "int", - "int32", // rune - "int64", - "bool", - } - mapkeytypes = []string{ - "string", - "uint8", // byte - "uint64", // used for keys - "int", // default number key - "int32", // rune - } - mapvaltypes = []string{ - "interface{}", - "string", - "[]byte", - "uint8", // byte - "uint64", // used for keys, etc - "int", // default number - "int32", // rune (mostly used for unicode) - "float64", - "bool", - } - } - - var gt = genTmpl{Formats: genFormats} - - // For each slice or map type, there must be a (symmetrical) Encode and Decode fastpath function - - for _, s := range primitivetypes { - gt.Values = append(gt.Values, - genFastpathV{Primitive: s, Size: typesizes[s], NoCanonical: !genFastpathCanonical}) - } - for _, s := range slicetypes { - gt.Values = append(gt.Values, - genFastpathV{Elem: s, Size: typesizes[s], NoCanonical: !genFastpathCanonical}) - } - for _, s := range mapkeytypes { - for _, ms := range mapvaltypes { - gt.Values = append(gt.Values, - genFastpathV{MapKey: s, Elem: ms, Size: typesizes[s] + typesizes[ms], NoCanonical: !genFastpathCanonical}) - } - } - - funcs := make(template.FuncMap) - // funcs["haspfx"] = strings.HasPrefix - funcs["encmd"] = genTmplEncCommandAsString - funcs["decmd"] = genTmplDecCommandAsString - funcs["zerocmd"] = genTmplZeroValue - funcs["nonzerocmd"] = genTmplNonZeroValue - funcs["hasprefix"] = strings.HasPrefix - funcs["sorttype"] = genTmplSortType - - genTmplV = gt - genTmplFuncs = funcs -} - -// genTmplGoFile is used to generate source files from templates. -func genTmplGoFile(r io.Reader, w io.Writer) (err error) { - genTmplOnce.Do(genTmplInit) - - gt := genTmplV - - t := template.New("").Funcs(genTmplFuncs) - - tmplstr, err := io.ReadAll(r) - if err != nil { - return - } - - if t, err = t.Parse(string(tmplstr)); err != nil { - return - } - - var out bytes.Buffer - err = t.Execute(&out, gt) - if err != nil { - return - } - - bout, err := format.Source(out.Bytes()) - if err != nil { - w.Write(out.Bytes()) // write out if error, so we can still see. - // w.Write(bout) // write out if error, as much as possible, so we can still see. - return - } - w.Write(bout) - return -} - -func genTmplRun2Go(fnameIn, fnameOut string) { - // println("____ " + fnameIn + " --> " + fnameOut + " ______") - fin, err := os.Open(fnameIn) - genCheckErr(err) - defer fin.Close() - fout, err := os.Create(fnameOut) - genCheckErr(err) - defer fout.Close() - err = genTmplGoFile(fin, fout) - genCheckErr(err) -} diff --git a/vendor/github.com/ugorji/go/codec/gen_mono.go b/vendor/github.com/ugorji/go/codec/gen_mono.go deleted file mode 100644 index 841147863..000000000 --- a/vendor/github.com/ugorji/go/codec/gen_mono.go +++ /dev/null @@ -1,586 +0,0 @@ -// Copyright (c) 2012-2020 Ugorji Nwoke. All rights reserved. -// Use of this source code is governed by a MIT license found in the LICENSE file. - -//go:build codec.build - -package codec - -import ( - "go/ast" - "go/format" - "go/parser" - "go/token" - "os" - "slices" - "strings" -) - -// This tool will monomorphize types scoped to a specific format. -// -// This tool only monomorphized the type Name, and not a function Name. -// Explicitly, generic functions are not supported, as they cannot be monomorphized -// to a specific format without a corresponding name change. -// -// However, for types constrained to encWriter or decReader, -// which are shared across formats, there's no place to put them without duplication. - -const genMonoParserMode = parser.AllErrors | parser.SkipObjectResolution - -var genMonoSpecialFieldTypes = []string{"helperDecReader"} - -// These functions should take the address of first param when monomorphized -var genMonoSpecialFunc4Addr = []string{} // {"decByteSlice"} - -var genMonoImportsToSkip = []string{`"errors"`, `"fmt"`, `"net/rpc"`} - -var genMonoRefImportsVia_ = [][2]string{ - // {"errors", "New"}, -} - -var genMonoCallsToSkip = []string{"callMake"} - -type genMonoFieldState uint - -const ( - genMonoFieldRecv genMonoFieldState = iota << 1 - genMonoFieldParamsResult - genMonoFieldStruct -) - -type genMonoImports struct { - set map[string]struct{} - specs []*ast.ImportSpec -} - -type genMono struct { - files map[string][]byte - typParam map[string]*ast.Field - typParamTransient map[string]*ast.Field -} - -func (x *genMono) init() { - x.files = make(map[string][]byte) - x.typParam = make(map[string]*ast.Field) - x.typParamTransient = make(map[string]*ast.Field) -} - -func (x *genMono) reset() { - clear(x.typParam) - clear(x.typParamTransient) -} - -func (m *genMono) hdl(hname string) { - m.reset() - m.do(hname, []string{"encode.go", "decode.go", hname + ".go"}, []string{"base.notfastpath.go", "base.notfastpath.notmono.go"}, "", "") - m.do(hname, []string{"base.notfastpath.notmono.go"}, nil, ".notfastpath", ` && (notfastpath || codec.notfastpath)`) - m.do(hname, []string{"base.fastpath.notmono.generated.go"}, []string{"base.fastpath.generated.go"}, ".fastpath", ` && !notfastpath && !codec.notfastpath`) -} - -func (m *genMono) do(hname string, fnames, tnames []string, fnameInfx string, buildTagsSfx string) { - // keep m.typParams across whole call, as all others use it - const fnameSfx = ".mono.generated.go" - fname := hname + fnameInfx + fnameSfx - - var imports = genMonoImports{set: make(map[string]struct{})} - - r1, fset := m.merge(fnames, tnames, &imports) - m.trFile(r1, hname, true) - - r2, fset := m.merge(fnames, tnames, &imports) - m.trFile(r2, hname, false) - - r0 := genMonoOutInit(imports.specs, fname) - r0.Decls = append(r0.Decls, r1.Decls...) - r0.Decls = append(r0.Decls, r2.Decls...) - - // output r1 to a file - f, err := os.Create(fname) - halt.onerror(err) - defer f.Close() - - var s genMonoStrBuilder - s.s(`//go:build !notmono && !codec.notmono `).s(buildTagsSfx).s(` - -// Copyright (c) 2012-2020 Ugorji Nwoke. All rights reserved. -// Use of this source code is governed by a MIT license found in the LICENSE file. - -`) - _, err = f.Write(s.v) - halt.onerror(err) - err = format.Node(f, fset, r0) - halt.onerror(err) -} - -func (x *genMono) file(fname string) (b []byte) { - b = x.files[fname] - if b == nil { - var err error - b, err = os.ReadFile(fname) - halt.onerror(err) - x.files[fname] = b - } - return -} - -func (x *genMono) merge(fNames, tNames []string, imports *genMonoImports) (dst *ast.File, fset *token.FileSet) { - // typParams used in fnLoadTyps - var typParams map[string]*ast.Field - var loadTyps bool - fnLoadTyps := func(node ast.Node) bool { - var ok bool - switch n := node.(type) { - case *ast.GenDecl: - if n.Tok == token.TYPE { - for _, v := range n.Specs { - nn := v.(*ast.TypeSpec) - ok = genMonoTypeParamsOk(nn.TypeParams) - if ok { - // each decl will have only 1 var/type - typParams[nn.Name.Name] = nn.TypeParams.List[0] - if loadTyps { - dst.Decls = append(dst.Decls, &ast.GenDecl{Tok: n.Tok, Specs: []ast.Spec{v}}) - } - } - } - } - return false - } - return true - } - - // we only merge top-level methods and types - fnIdX := func(n *ast.FuncDecl, n2 *ast.IndexExpr) (ok bool) { - n9, ok9 := n2.Index.(*ast.Ident) - n3, ok := n2.X.(*ast.Ident) // n3 = type name - ok = ok && ok9 && n9.Name == "T" - if ok { - _, ok = x.typParam[n3.Name] - } - return - } - - fnLoadMethodsAndImports := func(node ast.Node) bool { - var ok bool - switch n := node.(type) { - case *ast.FuncDecl: - // TypeParams is nil for methods, as it is defined at the type node - // instead, look at the name, and - // if IndexExpr.Index=T, and IndexExpr.X matches a type name seen already - // then ok = true - if n.Recv == nil || len(n.Recv.List) != 1 { - return false - } - ok = false - switch nn := n.Recv.List[0].Type.(type) { - case *ast.IndexExpr: - ok = fnIdX(n, nn) - case *ast.StarExpr: - switch nn2 := nn.X.(type) { - case *ast.IndexExpr: - ok = fnIdX(n, nn2) - } - } - if ok { - dst.Decls = append(dst.Decls, n) - } - return false - case *ast.GenDecl: - if n.Tok == token.IMPORT { - for _, v := range n.Specs { - nn := v.(*ast.ImportSpec) - if slices.Contains(genMonoImportsToSkip, nn.Path.Value) { - continue - } - if _, ok = imports.set[nn.Path.Value]; !ok { - imports.specs = append(imports.specs, nn) - imports.set[nn.Path.Value] = struct{}{} - } - } - } - return false - } - return true - } - - fset = token.NewFileSet() - fnLoadAsts := func(names []string) (asts []*ast.File) { - for _, fname := range names { - fsrc := x.file(fname) - f, err := parser.ParseFile(fset, fname, fsrc, genMonoParserMode) - halt.onerror(err) - asts = append(asts, f) - } - return - } - - clear(x.typParamTransient) - - dst = &ast.File{ - Name: &ast.Ident{Name: "codec"}, - } - - fs := fnLoadAsts(fNames) - ts := fnLoadAsts(tNames) - - loadTyps = true - typParams = x.typParam - for _, v := range fs { - ast.Inspect(v, fnLoadTyps) - } - loadTyps = false - typParams = x.typParamTransient - for _, v := range ts { - ast.Inspect(v, fnLoadTyps) - } - typParams = nil - for _, v := range fs { - ast.Inspect(v, fnLoadMethodsAndImports) - } - - return -} - -func (x *genMono) trFile(r *ast.File, hname string, isbytes bool) { - fn := func(node ast.Node) bool { - switch n := node.(type) { - case *ast.TypeSpec: - // type x[T encDriver] struct { ... } - if !genMonoTypeParamsOk(n.TypeParams) { - return false - } - x.trType(n, hname, isbytes) - return false - case *ast.FuncDecl: - if n.Recv == nil || len(n.Recv.List) != 1 { - return false - } - if _, ok := n.Recv.List[0].Type.(*ast.Ident); ok { - return false - } - tp := x.trMethodSign(n, hname, isbytes) // receiver, params, results - // handle the body - x.trMethodBody(n.Body, tp, hname, isbytes) - return false - } - return true - } - ast.Inspect(r, fn) - - // set type params to nil, and Pos to NoPos - fn = func(node ast.Node) bool { - switch n := node.(type) { - case *ast.FuncType: - if genMonoTypeParamsOk(n.TypeParams) { - n.TypeParams = nil - } - case *ast.TypeSpec: // for type ... - if genMonoTypeParamsOk(n.TypeParams) { - n.TypeParams = nil - } - } - return true - } - ast.Inspect(r, fn) -} - -func (x *genMono) trType(n *ast.TypeSpec, hname string, isbytes bool) { - sfx, _, _, hnameUp := genMonoIsBytesVals(hname, isbytes) - tp := n.TypeParams.List[0] - switch tp.Type.(*ast.Ident).Name { - case "encDriver", "decDriver": - n.Name.Name += hnameUp + sfx - case "encWriter", "decReader": - n.Name.Name += sfx - } - - // handle the Struct and Array types - switch nn := n.Type.(type) { - case *ast.StructType: - x.trStruct(nn, tp, hname, isbytes) - case *ast.ArrayType: - x.trArray(nn, tp, hname, isbytes) - } -} - -func (x *genMono) trMethodSign(n *ast.FuncDecl, hname string, isbytes bool) (tp *ast.Field) { - // check if recv type is not parameterized - tp = x.trField(n.Recv.List[0], nil, hname, isbytes, genMonoFieldRecv) - // handle params and results - x.trMethodSignNonRecv(n.Type.Params, tp, hname, isbytes) - x.trMethodSignNonRecv(n.Type.Results, tp, hname, isbytes) - return -} - -func (x *genMono) trMethodSignNonRecv(r *ast.FieldList, tp *ast.Field, hname string, isbytes bool) { - if r == nil || len(r.List) == 0 { - return - } - for _, v := range r.List { - x.trField(v, tp, hname, isbytes, genMonoFieldParamsResult) - } -} - -func (x *genMono) trStruct(r *ast.StructType, tp *ast.Field, hname string, isbytes bool) { - // search for fields, and update accordingly - // type x[T encDriver] struct { w T } - // var x *A[T] - // A[T] - if r == nil || r.Fields == nil || len(r.Fields.List) == 0 { - return - } - for _, v := range r.Fields.List { - x.trField(v, tp, hname, isbytes, genMonoFieldStruct) - } -} - -func (x *genMono) trArray(n *ast.ArrayType, tp *ast.Field, hname string, isbytes bool) { - sfx, _, _, hnameUp := genMonoIsBytesVals(hname, isbytes) - // type fastpathEs[T encDriver] [56]fastpathE[T] - // p := tp.Names[0].Name - switch elt := n.Elt.(type) { - // case *ast.InterfaceType: - case *ast.IndexExpr: - if elt.Index.(*ast.Ident).Name == "T" { // generic - n.Elt = ast.NewIdent(elt.X.(*ast.Ident).Name + hnameUp + sfx) - } - } -} - -func (x *genMono) trMethodBody(r *ast.BlockStmt, tp *ast.Field, hname string, isbytes bool) { - // find the parent node for an indexExpr, or a T/*T, and set the value back in there - - fn := func(pnode ast.Node) bool { - var pn *ast.Ident - fnUp := func() { - x.updateIdentForT(pn, hname, tp, isbytes, false) - } - switch n := pnode.(type) { - // case *ast.SelectorExpr: - // case *ast.TypeAssertExpr: - // case *ast.IndexExpr: - case *ast.StarExpr: - if genMonoUpdateIndexExprT(&pn, n.X) { - n.X = pn - fnUp() - } - case *ast.CallExpr: - for i4, n4 := range n.Args { - if genMonoUpdateIndexExprT(&pn, n4) { - n.Args[i4] = pn - fnUp() - } - } - if n4, ok4 := n.Fun.(*ast.Ident); ok4 && slices.Contains(genMonoSpecialFunc4Addr, n4.Name) { - n.Args[0] = &ast.UnaryExpr{Op: token.AND, X: n.Args[0].(*ast.SelectorExpr)} - } - case *ast.CompositeLit: - if genMonoUpdateIndexExprT(&pn, n.Type) { - n.Type = pn - fnUp() - } - case *ast.ArrayType: - if genMonoUpdateIndexExprT(&pn, n.Elt) { - n.Elt = pn - fnUp() - } - case *ast.ValueSpec: - for i2, n2 := range n.Values { - if genMonoUpdateIndexExprT(&pn, n2) { - n.Values[i2] = pn - fnUp() - } - } - if genMonoUpdateIndexExprT(&pn, n.Type) { - n.Type = pn - fnUp() - } - case *ast.BinaryExpr: - // early return here, since the 2 things can apply - if genMonoUpdateIndexExprT(&pn, n.X) { - n.X = pn - fnUp() - } - if genMonoUpdateIndexExprT(&pn, n.Y) { - n.Y = pn - fnUp() - } - return true - } - return true - } - ast.Inspect(r, fn) -} - -func (x *genMono) trField(f *ast.Field, tpt *ast.Field, hname string, isbytes bool, state genMonoFieldState) (tp *ast.Field) { - var pn *ast.Ident - switch nn := f.Type.(type) { - case *ast.IndexExpr: - if genMonoUpdateIndexExprT(&pn, nn) { - f.Type = pn - } - case *ast.StarExpr: - if genMonoUpdateIndexExprT(&pn, nn.X) { - nn.X = pn - } - case *ast.FuncType: - x.trMethodSignNonRecv(nn.Params, tpt, hname, isbytes) - x.trMethodSignNonRecv(nn.Results, tpt, hname, isbytes) - return - case *ast.ArrayType: - x.trArray(nn, tpt, hname, isbytes) - return - case *ast.Ident: - if state == genMonoFieldRecv || nn.Name != "T" { - return - } - pn = nn // "T" - if state == genMonoFieldParamsResult { - f.Type = &ast.StarExpr{X: pn} - } - } - if pn == nil { - return - } - - tp = x.updateIdentForT(pn, hname, tpt, isbytes, true) - return -} - -func (x *genMono) updateIdentForT(pn *ast.Ident, hname string, tp *ast.Field, - isbytes bool, lookupTP bool) (tp2 *ast.Field) { - sfx, writer, reader, hnameUp := genMonoIsBytesVals(hname, isbytes) - // handle special ones e.g. helperDecReader et al - if slices.Contains(genMonoSpecialFieldTypes, pn.Name) { - pn.Name += sfx - return - } - - if pn.Name != "T" && lookupTP { - tp = x.typParam[pn.Name] - if tp == nil { - tp = x.typParamTransient[pn.Name] - } - } - - paramtyp := tp.Type.(*ast.Ident).Name - if pn.Name == "T" { - switch paramtyp { - case "encDriver", "decDriver": - pn.Name = hname + genMonoTitleCase(paramtyp) + sfx - case "encWriter": - pn.Name = writer - case "decReader": - pn.Name = reader - } - } else { - switch paramtyp { - case "encDriver", "decDriver": - pn.Name += hnameUp + sfx - case "encWriter", "decReader": - pn.Name += sfx - } - } - return tp -} - -func genMonoUpdateIndexExprT(pn **ast.Ident, node ast.Node) (pnok bool) { - *pn = nil - if n2, ok := node.(*ast.IndexExpr); ok { - n9, ok9 := n2.Index.(*ast.Ident) - n3, ok := n2.X.(*ast.Ident) - if ok && ok9 && n9.Name == "T" { - *pn, pnok = ast.NewIdent(n3.Name), true - } - } - return -} - -func genMonoTitleCase(s string) string { - return strings.ToUpper(s[:1]) + s[1:] -} - -func genMonoIsBytesVals(hName string, isbytes bool) (suffix, writer, reader, hNameUp string) { - hNameUp = genMonoTitleCase(hName) - if isbytes { - return "Bytes", "bytesEncAppender", "bytesDecReader", hNameUp - } - return "IO", "bufioEncWriter", "ioDecReader", hNameUp -} - -func genMonoTypeParamsOk(v *ast.FieldList) (ok bool) { - if v == nil || v.List == nil || len(v.List) != 1 { - return false - } - pn := v.List[0] - if len(pn.Names) != 1 { - return false - } - pnName := pn.Names[0].Name - if pnName != "T" { - return false - } - // ignore any nodes which are not idents e.g. cmp.orderedRv - vv, ok := pn.Type.(*ast.Ident) - if !ok { - return false - } - switch vv.Name { - case "encDriver", "decDriver", "encWriter", "decReader": - return true - } - return false -} - -func genMonoCopy(src *ast.File) (dst *ast.File) { - dst = &ast.File{ - Name: &ast.Ident{Name: "codec"}, - } - dst.Decls = append(dst.Decls, src.Decls...) - return -} - -type genMonoStrBuilder struct { - v []byte -} - -func (x *genMonoStrBuilder) s(v string) *genMonoStrBuilder { - x.v = append(x.v, v...) - return x -} - -func genMonoOutInit(importSpecs []*ast.ImportSpec, fname string) (f *ast.File) { - // ParseFile seems to skip the //go:build stanza - // it should be written directly into the file - var s genMonoStrBuilder - s.s(` -package codec - -import ( -`) - for _, v := range importSpecs { - s.s("\t").s(v.Path.Value).s("\n") - } - s.s(")\n") - for _, v := range genMonoRefImportsVia_ { - s.s("var _ = ").s(v[0]).s(".").s(v[1]).s("\n") - } - f, err := parser.ParseFile(token.NewFileSet(), fname, s.v, genMonoParserMode) - halt.onerror(err) - return -} - -func genMonoAll() { - // hdls := []Handle{ - // (*SimpleHandle)(nil), - // (*JsonHandle)(nil), - // (*CborHandle)(nil), - // (*BincHandle)(nil), - // (*MsgpackHandle)(nil), - // } - hdls := []string{"simple", "json", "cbor", "binc", "msgpack"} - var m genMono - m.init() - for _, v := range hdls { - m.hdl(v) - } -} diff --git a/vendor/github.com/ugorji/go/codec/goversion_check_supported.go b/vendor/github.com/ugorji/go/codec/goversion_check_supported.go deleted file mode 100644 index 067c5e9ce..000000000 --- a/vendor/github.com/ugorji/go/codec/goversion_check_supported.go +++ /dev/null @@ -1,20 +0,0 @@ -// Copyright (c) 2012-2020 Ugorji Nwoke. All rights reserved. -// Use of this source code is governed by a MIT license found in the LICENSE file. - -//go:build !go1.21 - -package codec - -import "errors" - -// Moving forward, this codec package will support at least the last 4 major Go releases. -// -// As of early summer 2025, codec will support go 1.21, 1.22, 1.23, 1.24 releases of go. -// This allows use of the followin: -// - stabilized generics -// - min/max/clear -// - slice->array conversion - -func init() { - panic(errors.New("codec: supports go 1.21 and above only")) -} diff --git a/vendor/github.com/ugorji/go/codec/goversion_noswissmap_unsafe.go b/vendor/github.com/ugorji/go/codec/goversion_noswissmap_unsafe.go deleted file mode 100644 index ca61f6f08..000000000 --- a/vendor/github.com/ugorji/go/codec/goversion_noswissmap_unsafe.go +++ /dev/null @@ -1,16 +0,0 @@ -// Copyright (c) 2012-2020 Ugorji Nwoke. All rights reserved. -// Use of this source code is governed by a MIT license found in the LICENSE file. - -//go:build !safe && !codec.safe && !appengine && !go1.24 - -package codec - -import "unsafe" - -// retrofited from hIter struct - -type unsafeMapIterPadding struct { - _ [6]unsafe.Pointer // padding: *maptype, *hmap, buckets, *bmap, overflow, oldoverflow, - _ [4]uintptr // padding: uintptr, uint8, bool fields - _ uintptr // padding: wasted (try to fill cache-line at multiple of 4) -} diff --git a/vendor/github.com/ugorji/go/codec/goversion_swissmap_unsafe.go b/vendor/github.com/ugorji/go/codec/goversion_swissmap_unsafe.go deleted file mode 100644 index 5f062e87c..000000000 --- a/vendor/github.com/ugorji/go/codec/goversion_swissmap_unsafe.go +++ /dev/null @@ -1,15 +0,0 @@ -// Copyright (c) 2012-2020 Ugorji Nwoke. All rights reserved. -// Use of this source code is governed by a MIT license found in the LICENSE file. - -//go:build !safe && !codec.safe && !appengine && go1.24 - -package codec - -import "unsafe" - -// retrofited from linknameIter struct (compatibility layer for swissmaps) - -type unsafeMapIterPadding struct { - _ [2]unsafe.Pointer // padding: *abi.SwissMapType, *maps.Iter - _ uintptr // padding: wasted (try to fill cache-line at multiple of 4) -} diff --git a/vendor/github.com/ugorji/go/codec/helper.go b/vendor/github.com/ugorji/go/codec/helper.go deleted file mode 100644 index e737ef2b9..000000000 --- a/vendor/github.com/ugorji/go/codec/helper.go +++ /dev/null @@ -1,3278 +0,0 @@ -// Copyright (c) 2012-2020 Ugorji Nwoke. All rights reserved. -// Use of this source code is governed by a MIT license found in the LICENSE file. - -package codec - -// Contains code shared by both encode and decode. - -// Some shared ideas around encoding/decoding -// ------------------------------------------ -// -// If an interface{} is passed, we first do a type assertion to see if it is -// a primitive type or a map/slice of primitive types, and use a fastpath to handle it. -// -// If we start with a reflect.Value, we are already in reflect.Value land and -// will try to grab the function for the underlying Type and directly call that function. -// This is more performant than calling reflect.Value.Interface(). -// -// This still helps us bypass many layers of reflection, and give best performance. -// -// Containers -// ------------ -// Containers in the stream are either associative arrays (key-value pairs) or -// regular arrays (indexed by incrementing integers). -// -// Some streams support indefinite-length containers, and use a breaking -// byte-sequence to denote that the container has come to an end. -// -// Some streams also are text-based, and use explicit separators to denote the -// end/beginning of different values. -// -// Philosophy -// ------------ -// On decode, this codec will update containers appropriately: -// - If struct, update fields from stream into fields of struct. -// If field in stream not found in struct, handle appropriately (based on option). -// If a struct field has no corresponding value in the stream, leave it AS IS. -// If nil in stream, set value to nil/zero value. -// - If map, update map from stream. -// If the stream value is NIL, set the map to nil. -// - if slice, try to update up to length of array in stream. -// if container len is less than stream array length, -// and container cannot be expanded, handled (based on option). -// This means you can decode 4-element stream array into 1-element array. -// -// ------------------------------------ -// On encode, user can specify omitEmpty. This means that the value will be omitted -// if the zero value. The problem may occur during decode, where omitted values do not affect -// the value being decoded into. This means that if decoding into a struct with an -// int field with current value=5, and the field is omitted in the stream, then after -// decoding, the value will still be 5 (not 0). -// omitEmpty only works if you guarantee that you always decode into zero-values. -// -// ------------------------------------ -// We could have truncated a map to remove keys not available in the stream, -// or set values in the struct which are not in the stream to their zero values. -// We decided against it because there is no efficient way to do it. -// We may introduce it as an option later. -// However, that will require enabling it for both runtime and code generation modes. -// -// To support truncate, we need to do 2 passes over the container: -// map -// - first collect all keys (e.g. in k1) -// - for each key in stream, mark k1 that the key should not be removed -// - after updating map, do second pass and call delete for all keys in k1 which are not marked -// struct: -// - for each field, track the *typeInfo s1 -// - iterate through all s1, and for each one not marked, set value to zero -// - this involves checking the possible anonymous fields which are nil ptrs. -// too much work. -// -// ------------------------------------------ -// Error Handling is done within the library using panic. -// -// This way, the code doesn't have to keep checking if an error has happened, -// and we don't have to keep sending the error value along with each call -// or storing it in the En|Decoder and checking it constantly along the way. -// -// We considered storing the error is En|Decoder. -// - once it has its err field set, it cannot be used again. -// - panicing will be optional, controlled by const flag. -// - code should always check error first and return early. -// -// We eventually decided against it as it makes the code clumsier to always -// check for these error conditions. -// -// ------------------------------------------ -// We use sync.Pool only for the aid of long-lived objects shared across multiple goroutines. -// Encoder, Decoder, enc|decDriver, reader|writer, etc do not fall into this bucket. -// -// Also, GC is much better now, eliminating some of the reasons to use a shared pool structure. -// Instead, the short-lived objects use free-lists that live as long as the object exists. -// -// ------------------------------------------ -// Performance is affected by the following: -// - Bounds Checking -// - Inlining -// - Pointer chasing -// This package tries hard to manage the performance impact of these. -// -// ------------------------------------------ -// To alleviate performance due to pointer-chasing: -// - Prefer non-pointer values in a struct field -// - Refer to these directly within helper classes -// e.g. json.go refers directly to d.d.decRd -// -// We made the changes to embed En/Decoder in en/decDriver, -// but we had to explicitly reference the fields as opposed to using a function -// to get the better performance that we were looking for. -// For example, we explicitly call d.d.decRd.fn() instead of d.d.r().fn(). -// -// ------------------------------------------ -// Bounds Checking -// - Allow bytesDecReader to incur "bounds check error", and recover that as an io error. -// This allows the bounds check branch to always be taken by the branch predictor, -// giving better performance (in theory), while ensuring that the code is shorter. -// -// ------------------------------------------ -// Escape Analysis -// - Prefer to return non-pointers if the value is used right away. -// Newly allocated values returned as pointers will be heap-allocated as they escape. -// -// Prefer functions and methods that -// - take no parameters and -// - return no results and -// - do not allocate. -// These are optimized by the runtime. -// For example, in json, we have dedicated functions for ReadMapElemKey, etc -// which do not delegate to readDelim, as readDelim takes a parameter. -// The difference in runtime was as much as 5%. -// -// ------------------------------------------ -// Handling Nil -// - In dynamic (reflection) mode, decodeValue and encodeValue handle nil at the top -// - Consequently, methods used with them as a parent in the chain e.g. kXXX -// methods do not handle nil. -// - Fastpath methods also do not handle nil. -// The switch called in (en|de)code(...) handles it so the dependent calls don't have to. -// - codecgen will handle nil before calling into the library for further work also. -// -// ------------------------------------------ -// Passing reflect.Kind to functions that take a reflect.Value -// - Note that reflect.Value.Kind() is very cheap, as its fundamentally a binary AND of 2 numbers -// -// ------------------------------------------ -// Transient values during decoding -// -// With reflection, the stack is not used. Consequently, values which may be stack-allocated in -// normal use will cause a heap allocation when using reflection. -// -// There are cases where we know that a value is transient, and we just need to decode into it -// temporarily so we can right away use its value for something else. -// -// In these situations, we can elide the heap allocation by being deliberate with use of a pre-cached -// scratch memory or scratch value. -// -// We use this for situations: -// - decode into a temp value x, and then set x into an interface -// - decode into a temp value, for use as a map key, to lookup up a map value -// - decode into a temp value, for use as a map value, to set into a map -// - decode into a temp value, for sending into a channel -// -// By definition, Transient values are NEVER pointer-shaped values, -// like pointer, func, map, chan. Using transient for pointer-shaped values -// can lead to data corruption when GC tries to follow what it saw as a pointer at one point. -// -// In general, transient values are values which can be decoded as an atomic value -// using a single call to the decDriver. This naturally includes bool or numeric types. -// -// Note that some values which "contain" pointers, specifically string and slice, -// can also be transient. In the case of string, it is decoded as an atomic value. -// In the case of a slice, decoding into its elements always uses an addressable -// value in memory ie we grow the slice, and then decode directly into the memory -// address corresponding to that index in the slice. -// -// To handle these string and slice values, we have to use a scratch value -// which has the same shape of a string or slice. -// -// Consequently, the full range of types which can be transient is: -// - numbers -// - bool -// - string -// - slice -// -// and whbut we MUST use a scratch space with that element -// being defined as an unsafe.Pointer to start with. -// -// We have to be careful with maps. Because we iterate map keys and values during a range, -// we must have 2 variants of the scratch space/value for maps and keys separately. -// -// These are the TransientAddrK and TransientAddr2K methods of decPerType. - -import ( - "bytes" - "encoding" - "encoding/binary" - "encoding/hex" - "errors" - "fmt" - "io" - "math" - "reflect" - "runtime" - "runtime/debug" - "sort" - "strconv" - "strings" - "sync" - "sync/atomic" - "time" - "unicode/utf8" -) - -const ( - // if debugging is true, then - // - within Encode/Decode, do not recover from panic's - // - etc - // - // Note: Negative tests that check for errors will fail, so only use this - // when debugging, and run only one test at a time preferably. - // - // Note: RPC tests depend on getting the error from an Encode/Decode call. - // Consequently, they will always fail if debugging = true. - // - // It is generally set to false - debugging = false - - // if debugLogging is false, debugf calls will be a No-op. - // - // It is generally set to true - debugLogging = true - - // containerLenUnknown is length returned from Read(Map|Array)Len - // when a format doesn't know apiori. - // For example, json doesn't pre-determine the length of a container (sequence/map). - containerLenUnknown = -1 - - // containerLenNil is length returned from Read(Map|Array)Len - // when a 'nil' was encountered in the stream. - containerLenNil = math.MinInt32 - - // [N]byte is handled by converting to []byte first, - // and sending to the dedicated fast-path function for []byte. - // - // Code exists in case our understanding is wrong. - // keep the defensive code behind this flag, so we can remove/hide it if needed. - // For now, we enable the defensive code (ie set it to true). - handleBytesWithinKArray = true - - // Support encoding.(Binary|Text)(Unm|M)arshaler. - // This constant flag will enable or disable it. - supportMarshalInterfaces = true - - // size of the cacheline: defaulting to value for archs: amd64, arm64, 386 - // should use "runtime/internal/sys".CacheLineSize, but that is not exposed. - cacheLineSize = 64 - - wordSizeBits = 32 << (^uint(0) >> 63) // strconv.IntSize - wordSize = wordSizeBits / 8 - - // byteBufSize is the default size of []byte used - // possibly for bufioWriter, etc - byteBufSize = 1 << 10 // 4:16, 6:64, 8:256, 10:1024 - - // MARKER: determines whether to skip calling fastpath(En|De)codeTypeSwitch. - // Calling the fastpath switch in encode() or decode() could be redundant, - // as we still have to introspect it again within fnLoad - // to determine the function to use for values of that type. - skipFastpathTypeSwitchInDirectCall = false - - // maxArrayLen is the size of uint, which determines - // the maximum length of any array. - maxArrayLen = 1<<((32<<(^uint(0)>>63))-1) - 1 - - // ---- below this line, useXXX consts should be true - - usePoolForSFIs = true - useArenaForSFIs = true - - usePoolForTypeInfoLoad = true - - usePoolForSideEncode = true - - usePoolForSideDecode = true - - useBytesFreeList = true - - useSfiRvFreeList = true - - // ---- below this line, useXXX consts should be false - - useBytesFreeListPutGetSeparateCalls = false -) - -const cpu32Bit = ^uint(0)>>32 == 0 - -type rkind byte - -const ( - rkindPtr = rkind(reflect.Ptr) - rkindString = rkind(reflect.String) - rkindChan = rkind(reflect.Chan) -) - -var ( - // use a global mutex to ensure each Handle is initialized. - // We do this, so we don't have to store the basicHandle mutex - // directly in BasicHandle, so it can be shallow-copied. - handleInitMu sync.Mutex - - must mustHdl - halt panicHdl - - digitCharBitset bitset256 - numCharBitset bitset256 - whitespaceCharBitset bitset256 - // asciiAlphaNumBitset bitset256 - - jsonCharHtmlSafeBitset bitset256 - jsonCharSafeBitset bitset256 - - // numCharWithExpBitset64 bitset64 - // numCharNoExpBitset64 bitset64 - // whitespaceCharBitset64 bitset64 - // - // // hasptrBitset sets bit for all kinds which always have internal pointers - // hasptrBitset bitset32 - - // refBitset sets bit for all kinds which are direct internal references - refBitset bitset32 - - // isnilBitset sets bit for all kinds which can be compared to nil - isnilBitset bitset32 - - // numBoolBitset sets bit for all number and bool kinds - numBoolBitset bitset32 - - // numBoolStrSliceBitset sets bits for all kinds which are numbers, bool, strings and slices - numBoolStrSliceBitset bitset32 - - // scalarBitset sets bit for all kinds which are scalars/primitives and thus immutable - scalarBitset bitset32 - - // codecgen is set to true by codecgen, so that tests, etc can use this information as needed. - codecgen bool - - oneByteArr [1]byte - zeroByteSlice = oneByteArr[:0:0] - - eofReader devNullReader - - // string containing all values of a uint8 in sequence. - // We maintain a [256]byte slice, for efficiently making strings with one byte. - // str256 string - - // handleNewFns []handleNewFn - - basicErrDecorator errDecoratorDef - - // sentinel value passed to panicValToErr, signifying to call recover yourself - callRecoverSentinel = new(byte) - - // debugstackOnce is used to put a single debugStack at a certain point (during debugging). - // To use, just call debugstackOnce() wherever you need to see a stack only once. - debugstackOnce = sync.OnceFunc(debug.PrintStack) -) - -var ( - errMapTypeNotMapKind = errors.New("MapType MUST be of Map Kind") - errSliceTypeNotSliceKind = errors.New("SliceType MUST be of Slice Kind") - - errExtFnWriteExtUnsupported = errors.New("BytesExt.WriteExt is not supported") - errExtFnReadExtUnsupported = errors.New("BytesExt.ReadExt is not supported") - errExtFnConvertExtUnsupported = errors.New("InterfaceExt.ConvertExt is not supported") - errExtFnUpdateExtUnsupported = errors.New("InterfaceExt.UpdateExt is not supported") - - errPanicUndefined = errors.New("panic: undefined error") - - errHandleInited = errors.New("cannot modify initialized Handle") - - errNoFormatHandle = errors.New("no handle (cannot identify format)") -) - -var poolForTypeInfoLoad = sync.Pool{ - New: func() interface{} { - return newTypeInfoLoad() - }, -} - -func init() { - numBoolBitset. - set(byte(reflect.Bool)). - set(byte(reflect.Int)). - set(byte(reflect.Int8)). - set(byte(reflect.Int16)). - set(byte(reflect.Int32)). - set(byte(reflect.Int64)). - set(byte(reflect.Uint)). - set(byte(reflect.Uint8)). - set(byte(reflect.Uint16)). - set(byte(reflect.Uint32)). - set(byte(reflect.Uint64)). - set(byte(reflect.Uintptr)). - set(byte(reflect.Float32)). - set(byte(reflect.Float64)). - set(byte(reflect.Complex64)). - set(byte(reflect.Complex128)) - - numBoolStrSliceBitset = numBoolBitset - - numBoolStrSliceBitset. - set(byte(reflect.String)). - set(byte(reflect.Slice)) - - scalarBitset = numBoolBitset - - scalarBitset. - set(byte(reflect.String)) - - // MARKER: reflect.Array is not a scalar, as its contents can be modified. - - refBitset. - set(byte(reflect.Map)). - set(byte(reflect.Ptr)). - set(byte(reflect.Func)). - set(byte(reflect.Chan)). - set(byte(reflect.UnsafePointer)) - - isnilBitset = refBitset - - isnilBitset. - set(byte(reflect.Interface)). - set(byte(reflect.Slice)) - - // hasptrBitset = isnilBitset - // - // hasptrBitset. - // set(byte(reflect.String)) - - for i := byte(0); i <= utf8.RuneSelf; i++ { - // if (i >= '0' && i <= '9') || (i >= 'a' && i <= 'z') || (i >= 'A' && i <= 'Z') || i == '_' { - // asciiAlphaNumBitset.set(i) - // } - switch i { - case ' ', '\t', '\r', '\n': - whitespaceCharBitset.set(i) - case '0', '1', '2', '3', '4', '5', '6', '7', '8', '9': - digitCharBitset.set(i) - numCharBitset.set(i) - case '.', '+', '-': - numCharBitset.set(i) - case 'e', 'E': - numCharBitset.set(i) - } - } - - // populate the safe values as true: note: ASCII control characters are (0-31) - // jsonCharSafeBitset: all true except (0-31) " \ - // jsonCharHtmlSafeBitset: all true except (0-31) " \ < > & - for i := byte(32); i < utf8.RuneSelf; i++ { - switch i { - case '"', '\\': - case '<', '>', '&': - jsonCharSafeBitset.set(i) // = true - default: - jsonCharSafeBitset.set(i) - jsonCharHtmlSafeBitset.set(i) - } - } -} - -func searchRtids(s []uintptr, v uintptr) (i uint, ok bool) { - var h uint - var j uint = uint(len(s)) -LOOP: - if i < j { - h = (i + j) >> 1 // avoid overflow when computing h // h = i + (j-i)/2 - if s[h] < v { - i = h + 1 - } else { - j = h - } - goto LOOP - } - return i, i < uint(len(s)) && s[i] == v -} - -// circularRefChecker holds interfaces during an encoding (if CheckCircularRef=true) -// -// We considered using a []uintptr (slice of pointer addresses) retrievable via rv.UnsafeAddr. -// However, it is possible for the same pointer to point to 2 different types e.g. -// -// type T struct { tHelper } -// Here, for var v T; &v and &v.tHelper are the same pointer. -// -// Consequently, we need a tuple of type and pointer, which interface{} natively provides. -// -// Note: the following references, if seen, can lead to circular references -// - Pointer to struct/slice/array/map (any container) -// - map (reference, where a value in a kv pair could be the map itself) -// - addr of slice/array element -// - add of struct field -type circularRefChecker []interface{} // []uintptr - -func (ci *circularRefChecker) push(v interface{}) { - for _, vv := range *ci { - if eq4i(v, vv) { // error if sptr already seen - halt.errorf("circular reference found: %p, %T", v, v) - } - } - *ci = append(*ci, v) -} - -func (_ *circularRefChecker) canPushElemKind(elemKind reflect.Kind) bool { - switch elemKind { - case reflect.Struct, reflect.Slice, reflect.Array, reflect.Map: - return true - } - return false -} - -func (ci *circularRefChecker) pop(num int) { - *ci = (*ci)[:len(*ci)-num] -} - -type bdAndBdread struct { - bdRead bool - bd byte -} - -func (x *bdAndBdread) reset() { x.bd, x.bdRead = 0, false } - -type clsErr struct { - err error // error on closing - closed bool // is it closed? -} - -type charEncoding uint8 - -const ( - _ charEncoding = iota // make 0 unset - cUTF8 - cUTF16LE - cUTF16BE - cUTF32LE - cUTF32BE - // Deprecated: not a true char encoding value - cRAW charEncoding = 255 -) - -// valueType is the stream type -type valueType uint8 - -const ( - valueTypeUnset valueType = iota - valueTypeNil - valueTypeInt - valueTypeUint - valueTypeFloat - valueTypeBool - valueTypeString - valueTypeSymbol - valueTypeBytes - valueTypeMap - valueTypeArray - valueTypeTime - valueTypeExt - - // valueTypeInvalid = 0xff -) - -var valueTypeStrings = [...]string{ - "Unset", - "Nil", - "Int", - "Uint", - "Float", - "Bool", - "String", - "Symbol", - "Bytes", - "Map", - "Array", - "Timestamp", - "Ext", -} - -func (x valueType) String() string { - if int(x) < len(valueTypeStrings) { - return valueTypeStrings[x] - } - return strconv.FormatInt(int64(x), 10) -} - -// note that containerMapStart and containerArraySend are not sent. -// This is because the ReadXXXStart and EncodeXXXStart already does these. -type containerState uint8 - -const ( - _ containerState = iota - - containerMapStart - containerMapKey - containerMapValue - containerMapEnd - containerArrayStart - containerArrayElem - containerArrayEnd -) - -// do not recurse if a containing type refers to an embedded type -// which refers back to its containing type (via a pointer). -// The second time this back-reference happens, break out, -// so as not to cause an infinite loop. -const rgetMaxRecursion = 2 - -// fauxUnion is used to keep track of the primitives decoded. -// -// Without it, we would have to decode each primitive and wrap it -// in an interface{}, causing an allocation. -// In this model, the primitives are decoded in a "pseudo-atomic" fashion, -// so we can rest assured that no other decoding happens while these -// primitives are being decoded. -// -// maps and arrays are not handled by this mechanism. -type fauxUnion struct { - // r RawExt // used for RawExt, uint, []byte. - - // primitives below - u uint64 - i int64 - f float64 - l []byte - s string - - // ---- cpu cache line boundary? - t time.Time - b bool - - // state - a dBytesAttachState - v valueType -} - -// typeInfoLoad is a transient object used while loading up a typeInfo. -type typeInfoLoad struct { - etypes []uintptr - sfis []structFieldInfo - sfiNames map[string]uint16 -} - -func newTypeInfoLoad() *typeInfoLoad { - return &typeInfoLoad{ - etypes: make([]uintptr, 0, 4), - sfis: make([]structFieldInfo, 0, 4), - sfiNames: make(map[string]uint16, 4), - } -} - -func (x *typeInfoLoad) reset() { - x.etypes = x.etypes[:0] - x.sfis = x.sfis[:0] - clear(x.sfiNames) - // for k := range x.sfiNames { // optimized to zero the map - // delete(x.sfiNames, k) - // } -} - -// mirror json.Marshaler and json.Unmarshaler here, -// so we don't import the encoding/json package - -type jsonMarshaler interface { - MarshalJSON() ([]byte, error) -} -type jsonUnmarshaler interface { - UnmarshalJSON([]byte) error -} - -type isZeroer interface { - IsZero() bool -} - -type isCodecEmptyer interface { - IsCodecEmpty() bool -} - -type outOfBoundsError struct { - capacity uint - requested uint -} - -func (x *outOfBoundsError) Error() string { - return sprintf("out of bounds with capacity = %d, requested %d", x.capacity, x.requested) -} - -type codecError struct { - err error - name string - pos int - encode bool -} - -func (e *codecError) Cause() error { - return e.err -} - -func (e *codecError) Unwrap() error { - return e.err -} - -func (e *codecError) Error() string { - if e.encode { - return fmt.Sprintf("%s encode error: %v", e.name, e.err) - } - return fmt.Sprintf("%s decode error [pos %d]: %v", e.name, e.pos, e.err) -} - -func wrapCodecErr(in error, name string, numbytesread int, encode bool) (out error) { - x, ok := in.(*codecError) - if ok && x.pos == numbytesread && x.name == name && x.encode == encode { - return in - } - return &codecError{in, name, numbytesread, encode} -} - -var ( - bigen bigenHelper - // bigenB bigenWriter[bytesEncAppenderM] - // bigenIO bigenWriter[bufioEncWriterM] - - bigenstd = binary.BigEndian - - structInfoFieldName = "_struct" - - mapStrIntfTyp = reflect.TypeOf(map[string]interface{}(nil)) - mapIntfIntfTyp = reflect.TypeOf(map[interface{}]interface{}(nil)) - intfSliceTyp = reflect.TypeOf([]interface{}(nil)) - intfTyp = intfSliceTyp.Elem() - - reflectValTyp = reflect.TypeOf((*reflect.Value)(nil)).Elem() - - stringTyp = reflect.TypeOf("") - timeTyp = reflect.TypeOf(time.Time{}) - rawExtTyp = reflect.TypeOf(RawExt{}) - rawTyp = reflect.TypeOf(Raw{}) - uintptrTyp = reflect.TypeOf(uintptr(0)) - uint8Typ = reflect.TypeOf(uint8(0)) - uint8SliceTyp = reflect.TypeOf([]uint8(nil)) - uintTyp = reflect.TypeOf(uint(0)) - intTyp = reflect.TypeOf(int(0)) - - mapBySliceTyp = reflect.TypeOf((*MapBySlice)(nil)).Elem() - - binaryMarshalerTyp = reflect.TypeOf((*encoding.BinaryMarshaler)(nil)).Elem() - binaryUnmarshalerTyp = reflect.TypeOf((*encoding.BinaryUnmarshaler)(nil)).Elem() - - textMarshalerTyp = reflect.TypeOf((*encoding.TextMarshaler)(nil)).Elem() - textUnmarshalerTyp = reflect.TypeOf((*encoding.TextUnmarshaler)(nil)).Elem() - - jsonMarshalerTyp = reflect.TypeOf((*jsonMarshaler)(nil)).Elem() - jsonUnmarshalerTyp = reflect.TypeOf((*jsonUnmarshaler)(nil)).Elem() - - selferTyp = reflect.TypeOf((*Selfer)(nil)).Elem() - missingFielderTyp = reflect.TypeOf((*MissingFielder)(nil)).Elem() - iszeroTyp = reflect.TypeOf((*isZeroer)(nil)).Elem() - isCodecEmptyerTyp = reflect.TypeOf((*isCodecEmptyer)(nil)).Elem() - - uint8TypId = rt2id(uint8Typ) - uint8SliceTypId = rt2id(uint8SliceTyp) - rawExtTypId = rt2id(rawExtTyp) - rawTypId = rt2id(rawTyp) - intfTypId = rt2id(intfTyp) - timeTypId = rt2id(timeTyp) - stringTypId = rt2id(stringTyp) - - mapStrIntfTypId = rt2id(mapStrIntfTyp) - mapIntfIntfTypId = rt2id(mapIntfIntfTyp) - intfSliceTypId = rt2id(intfSliceTyp) - // mapBySliceTypId = rt2id(mapBySliceTyp) - - intBitsize = uint8(intTyp.Bits()) - uintBitsize = uint8(uintTyp.Bits()) - - // bsAll0x00 = []byte{0, 0, 0, 0, 0, 0, 0, 0} - bsAll0xff = []byte{0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff} - - chkOvf checkOverflow -) - -var defTypeInfos = NewTypeInfos([]string{"codec", "json"}) - -// SelfExt is a sentinel extension signifying that types -// registered with it SHOULD be encoded and decoded -// based on the native mode of the format. -// -// This allows users to define a tag for an extension, -// but signify that the types should be encoded/decoded as the native encoding. -// This way, users need not also define how to encode or decode the extension. -var SelfExt = &extFailWrapper{} - -// Selfer defines methods by which a value can encode or decode itself. -// -// Any type which implements Selfer will be able to encode or decode itself. -// Consequently, during (en|de)code, this takes precedence over -// (text|binary)(M|Unm)arshal or extension support. -// -// By definition, it is not allowed for a Selfer to directly call Encode or Decode on itself. -// If that is done, Encode/Decode will rightfully fail with a Stack Overflow style error. -// For example, the snippet below will cause such an error. -// -// type testSelferRecur struct{} -// func (s *testSelferRecur) CodecEncodeSelf(e *Encoder) { e.MustEncode(s) } -// func (s *testSelferRecur) CodecDecodeSelf(d *Decoder) { d.MustDecode(s) } -// -// Note: *the first set of bytes of any value MUST NOT represent nil in the format*. -// This is because, during each decode, we first check the the next set of bytes -// represent nil, and if so, we just set the value to nil. -type Selfer interface { - CodecEncodeSelf(*Encoder) - CodecDecodeSelf(*Decoder) -} - -// MissingFielder defines the interface allowing structs to internally decode or encode -// values which do not map to struct fields. -// -// We expect that this interface is bound to a pointer type (so the mutation function works). -// -// A use-case is if a version of a type unexports a field, but you want compatibility between -// both versions during encoding and decoding. -// -// Note that the interface is completely ignored during codecgen. -type MissingFielder interface { - // CodecMissingField is called to set a missing field and value pair. - // - // It returns true if the missing field was set on the struct. - CodecMissingField(field []byte, value interface{}) bool - - // CodecMissingFields returns the set of fields which are not struct fields. - // - // Note that the returned map may be mutated by the caller. - CodecMissingFields() map[string]interface{} -} - -// MapBySlice is a tag interface that denotes the slice or array value should encode as a map -// in the stream, and can be decoded from a map in the stream. -// -// The slice or array must contain a sequence of key-value pairs. -// The length of the slice or array must be even (fully divisible by 2). -// -// This affords storing a map in a specific sequence in the stream. -// -// Example usage: -// -// type T1 []string // or []int or []Point or any other "slice" type -// func (_ T1) MapBySlice{} // T1 now implements MapBySlice, and will be encoded as a map -// type T2 struct { KeyValues T1 } -// -// var kvs = []string{"one", "1", "two", "2", "three", "3"} -// var v2 = T2{ KeyValues: T1(kvs) } -// // v2 will be encoded like the map: {"KeyValues": {"one": "1", "two": "2", "three": "3"} } -// -// The support of MapBySlice affords the following: -// - A slice or array type which implements MapBySlice will be encoded as a map -// - A slice can be decoded from a map in the stream -type MapBySlice interface { - MapBySlice() -} - -// const ( -// rtidfn_Enc_IO = iota -// rtidfn_Enc_IO_NoExt -// rtidfn_Dec_IO -// rtidfn_Dec_IO_NoExt - -// rtidfn_Enc_Bytes -// rtidfn_Enc_Bytes_NoExt -// rtidfn_Dec_Bytes -// rtidfn_Dec_Bytes_NoExt -// ) - -// basicHandleRuntimeState holds onto all BasicHandle runtime and cached config information. -// -// Storing this outside BasicHandle allows us create shallow copies of a Handle, -// which can be used e.g. when we need to modify config fields temporarily. -// Shallow copies are used within tests, so we can modify some config fields for a test -// temporarily when running tests in parallel, without running the risk that a test executing -// in parallel with other tests does not see a transient modified values not meant for it. -type basicHandleRuntimeState struct { - // Note: basicHandleRuntimeState is not comparable, due to these slices here (extHandle, intf2impls). - // If *[]T is used instead, this becomes comparable, at the cost of extra indirection. - // Thses slices are used all the time, so keep as slices (not pointers). - - extHandle - - intf2impls - - // these keep track of the []codecRtidFns for this handle. - // We used a non-generic value so we can: - // - keep these within BasicHandle - // - work around recursive limitations of go's generics - rtidFnsEncIO, - rtidFnsEncNoExtIO, - rtidFnsEncBytes, - rtidFnsEncNoExtBytes, - rtidFnsDecIO, - rtidFnsDecNoExtIO, - rtidFnsDecBytes, - rtidFnsDecNoExtBytes atomicRtidFnSlice - - sideEncPool sync.Pool - sideDecPool sync.Pool - - mu sync.Mutex - - jsonHandle bool - binaryHandle bool - - // timeBuiltin is initialized from TimeNotBuiltin, and used internally by setExt. - // once initialized, it cannot be changed, as the function for encoding/decoding time.Time - // will have been cached and the TimeNotBuiltin value will not be consulted thereafter. - timeBuiltin bool - // _ bool // padding -} - -// BasicHandle encapsulates the common options and extension functions. -// -// Deprecated: DO NOT USE DIRECTLY. EXPORTED FOR GODOC BENEFIT. WILL BE REMOVED. -type BasicHandle struct { - // BasicHandle is always a part of a different type. - // It doesn't have to fit into it own cache lines. - - // TypeInfos is used to get the type info for any type. - // - // If not configured, the default TypeInfos is used, which uses struct tag keys: codec, json - TypeInfos *TypeInfos - - basicHandleRuntimeState - - // ---- cache line - - DecodeOptions - - // ---- cache line - - EncodeOptions - - RPCOptions - - // TimeNotBuiltin configures whether time.Time should be treated as a builtin type. - // - // All Handlers should know how to encode/decode time.Time as part of the core - // format specification, or as a standard extension defined by the format. - // - // However, users can elect to handle time.Time as a custom extension, or via the - // standard library's encoding.Binary(M|Unm)arshaler or Text(M|Unm)arshaler interface. - // To elect this behavior, users can set TimeNotBuiltin=true. - // - // Note: Setting TimeNotBuiltin=true can be used to enable the legacy behavior - // (for Cbor and Msgpack), where time.Time was not a builtin supported type. - // - // Note: DO NOT CHANGE AFTER FIRST USE. - // - // Once a Handle has been initialized (used), do not modify this option. It will be ignored. - TimeNotBuiltin bool - - // ExplicitRelease is ignored and has no effect. - // - // Deprecated: Pools are only used for long-lived objects shared across goroutines. - // It is maintained for backward compatibility. - ExplicitRelease bool - - // ---- cache line - inited uint32 // holds if inited, and also handle flags (binary encoding, json handler, etc) - - // name string -} - -// initHandle does a one-time initialization of the handle. -// After this is run, do not modify the Handle, as some modifications are ignored -// e.g. extensions, registered interfaces, TimeNotBuiltIn, etc -func initHandle(hh Handle) { - x := hh.getBasicHandle() - - // MARKER: We need to simulate once.Do, to ensure no data race within the block. - // Consequently, below would not work. - // - // if atomic.CompareAndSwapUint32(&x.inited, 0, 1) { - // x.be = hh.isBinary() - // x.js = hh.isJson - // x.n = hh.Name()[0] - // } - - // simulate once.Do using our own stored flag and mutex as a CompareAndSwap - // is not sufficient, since a race condition can occur within init(Handle) function. - // init is made noinline, so that this function can be inlined by its caller. - if atomic.LoadUint32(&x.inited) == 0 { - initHandle2(x, hh) - } -} - -// initHandle2 should be called only from codec.initHandle global function. -// make it uninlineable, as it is called at most once for each handle. -// -//go:noinline -func initHandle2(x *BasicHandle, hh Handle) { - handleInitMu.Lock() - defer handleInitMu.Unlock() // use defer, as halt may panic below - if x.inited != 0 { - return - } - x.jsonHandle = hh.isJson() - x.binaryHandle = hh.isBinary() - x.basicInit() - - x.sideEncPool.New = func() any { - return NewEncoderBytes(nil, hh).encoderI - } - x.sideDecPool.New = func() any { - return NewDecoderBytes(nil, hh).decoderI - } - - // hh.init() - - atomic.StoreUint32(&x.inited, 1) -} - -func (x *BasicHandle) basicInit() { - // ensure MapType and SliceType are of correct type - if x.MapType != nil && x.MapType.Kind() != reflect.Map { - halt.onerror(errMapTypeNotMapKind) - } - if x.SliceType != nil && x.SliceType.Kind() != reflect.Slice { - halt.onerror(errSliceTypeNotSliceKind) - } - x.timeBuiltin = !x.TimeNotBuiltin -} - -// func (x *BasicHandle) init() {} - -func (x *BasicHandle) isInited() bool { - return atomic.LoadUint32(&x.inited) != 0 -} - -// clearInited: DANGEROUS - only use in testing, etc -func (x *BasicHandle) clearInited() { - atomic.StoreUint32(&x.inited, 0) -} - -func (x *basicHandleRuntimeState) setExt(rt reflect.Type, tag uint64, ext Ext) (err error) { - rk := rt.Kind() - for rk == reflect.Ptr { - rt = rt.Elem() - rk = rt.Kind() - } - - if rt.PkgPath() == "" || rk == reflect.Interface { // || rk == reflect.Ptr { - return fmt.Errorf("codec.Handle.SetExt: Takes named type, not a pointer or interface: %v", rt) - } - - rtid := rt2id(rt) - // handle all natively supported type appropriately, so they cannot have an extension. - // However, we do not return an error for these, as we do not document that. - // Instead, we silently treat as a no-op, and return. - switch rtid { - case rawTypId, rawExtTypId: - return - case timeTypId: - if x.timeBuiltin { - return - } - } - - for i := range x.extHandle { - v := &x.extHandle[i] - if v.rtid == rtid { - v.tag, v.ext = tag, ext - return - } - } - rtidptr := rt2id(reflect.PtrTo(rt)) - x.extHandle = append(x.extHandle, extTypeTagFn{rtid, rtidptr, rt, tag, ext}) - return -} - -func (x *BasicHandle) getBasicHandle() *BasicHandle { - return x -} - -func (x *BasicHandle) typeInfos() *TypeInfos { - if x.TypeInfos != nil { - return x.TypeInfos - } - return defTypeInfos -} - -// getTypeInfo expects a non-pointer -func (x *BasicHandle) getTypeInfo(rtid uintptr, rt reflect.Type) (pti *typeInfo) { - return x.typeInfos().get(rtid, rt) -} - -func (x *BasicHandle) getTypeInfo4RT(rt reflect.Type) (pti *typeInfo) { - return x.typeInfos().get(rt2id(rt), rt) -} - -// Handle defines a specific encoding format. It also stores any runtime state -// used during an Encoding or Decoding session e.g. stored state about Types, etc. -// -// Once a handle is configured, it can be shared across multiple Encoders and Decoders. -// -// Note that a Handle is NOT safe for concurrent modification. -// -// A Handle also should not be modified after it is configured and has -// been used at least once. This is because stored state may be out of sync with the -// new configuration, and a data race can occur when multiple goroutines access it. -// i.e. multiple Encoders or Decoders in different goroutines. -// -// Consequently, the typical usage model is that a Handle is pre-configured -// before first time use, and not modified while in use. -// Such a pre-configured Handle is safe for concurrent access. -type Handle interface { - Name() string - getBasicHandle() *BasicHandle - isBinary() bool - isJson() bool // json is special for now, so track it - // desc describes the current byte descriptor, or returns "unknown[XXX]" if not understood. - desc(bd byte) string - // init initializes the handle based on handle-specific info (beyond what is in BasicHandle) - // init() - // clone() Handle - newEncoderBytes(out *[]byte) encoderI - newEncoder(w io.Writer) encoderI - - newDecoderBytes(in []byte) decoderI - newDecoder(r io.Reader) decoderI -} - -// Raw represents raw formatted bytes. -// We "blindly" store it during encode and retrieve the raw bytes during decode. -// Note: it is dangerous during encode, so we may gate the behaviour -// behind an Encode flag which must be explicitly set. -type Raw []byte - -// RawExt represents raw unprocessed extension data. -// -// Some codecs will decode extension data as a *RawExt -// if there is no registered extension for the tag. -// -// On encode, encode the Data. If nil, then try to encode the Value. -// -// On decode: store tag, then store bytes and/or decode into Value. -type RawExt struct { - Tag uint64 - // Data is the []byte which represents the raw ext. If nil, ext is exposed in Value. - // Data is used by codecs (e.g. binc, msgpack, simple) which do custom serialization of types - Data []byte - // Value represents the extension, if Data is nil. - // Value is used by codecs (e.g. cbor, json) which leverage the format to do - // custom serialization of the types. - Value interface{} -} - -func (re *RawExt) setData(xbs []byte, zerocopy bool) { - if zerocopy { - re.Data = xbs - } else { - re.Data = append(re.Data[:0], xbs...) - } -} - -// BytesExt handles custom (de)serialization of types to/from []byte. -// It is used by codecs (e.g. binc, msgpack, simple) which do custom serialization of the types. -type BytesExt interface { - // WriteExt converts a value to a []byte. - // - // Note: v is a pointer iff the registered extension type is a struct or array kind. - WriteExt(v interface{}) []byte - - // ReadExt updates a value from a []byte. - // - // Note: dst is always a pointer kind to the registered extension type. - ReadExt(dst interface{}, src []byte) -} - -// InterfaceExt handles custom (de)serialization of types to/from another interface{} value. -// The Encoder or Decoder will then handle the further (de)serialization of that known type. -// -// It is used by codecs (e.g. cbor, json) which use the format to do custom serialization of types. -type InterfaceExt interface { - // ConvertExt converts a value into a simpler interface for easy encoding - // e.g. convert time.Time to int64. - // - // Note: v is a pointer iff the registered extension type is a struct or array kind. - ConvertExt(v interface{}) interface{} - - // UpdateExt updates a value from a simpler interface for easy decoding - // e.g. convert int64 to time.Time. - // - // Note: dst is always a pointer kind to the registered extension type. - UpdateExt(dst interface{}, src interface{}) -} - -// Ext handles custom (de)serialization of custom types / extensions. -type Ext interface { - BytesExt - InterfaceExt -} - -// addExtWrapper is a wrapper implementation to support former AddExt exported method. -type addExtWrapper struct { - encFn func(reflect.Value) ([]byte, error) - decFn func(reflect.Value, []byte) error -} - -func (x addExtWrapper) WriteExt(v interface{}) []byte { - bs, err := x.encFn(reflect.ValueOf(v)) - halt.onerror(err) - return bs -} - -func (x addExtWrapper) ReadExt(v interface{}, bs []byte) { - halt.onerror(x.decFn(reflect.ValueOf(v), bs)) -} - -func (x addExtWrapper) ConvertExt(v interface{}) interface{} { - return x.WriteExt(v) -} - -func (x addExtWrapper) UpdateExt(dest interface{}, v interface{}) { - x.ReadExt(dest, v.([]byte)) -} - -type bytesExtFailer struct{} - -func (bytesExtFailer) WriteExt(v interface{}) []byte { - halt.onerror(errExtFnWriteExtUnsupported) - return nil -} -func (bytesExtFailer) ReadExt(v interface{}, bs []byte) { - halt.onerror(errExtFnReadExtUnsupported) -} - -type interfaceExtFailer struct{} - -func (interfaceExtFailer) ConvertExt(v interface{}) interface{} { - halt.onerror(errExtFnConvertExtUnsupported) - return nil -} -func (interfaceExtFailer) UpdateExt(dest interface{}, v interface{}) { - halt.onerror(errExtFnUpdateExtUnsupported) -} - -type bytesExtWrapper struct { - interfaceExtFailer - BytesExt -} - -type interfaceExtWrapper struct { - bytesExtFailer - InterfaceExt -} - -type extFailWrapper struct { - bytesExtFailer - interfaceExtFailer -} - -type binaryEncodingType struct{} - -func (binaryEncodingType) isBinary() bool { return true } - -type textEncodingType struct{} - -func (textEncodingType) isBinary() bool { return false } - -type notJsonType struct{} - -func (notJsonType) isJson() bool { return false } - -// noBuiltInTypes is embedded into many types which do not support builtins -// e.g. msgpack, simple, cbor. - -type noBuiltInTypes struct{} - -func (noBuiltInTypes) EncodeBuiltin(rt uintptr, v interface{}) {} -func (noBuiltInTypes) DecodeBuiltin(rt uintptr, v interface{}) {} - -// bigenHelper handles ByteOrder operations directly using -// arrays of bytes (not slice of bytes). -// -// Since byteorder operations are very common for encoding and decoding -// numbers, lengths, etc - it is imperative that this operation is as -// fast as possible. Removing indirection (pointer chasing) to look -// at up to 8 bytes helps a lot here. -// -// For times where it is expedient to use a slice, delegate to the -// bigenstd (equal to the binary.BigEndian value). -// -// retrofitted from stdlib: encoding/binary/BigEndian (ByteOrder) -type bigenHelper struct{} - -func (z bigenHelper) PutUint16(v uint16) (b1, b2 byte) { - return byte(v >> 8), byte(v) -} - -func (z bigenHelper) PutUint32(v uint32) (b [4]byte) { - return [...]byte{ - byte(v >> 24), - byte(v >> 16), - byte(v >> 8), - byte(v), - } -} - -func (z bigenHelper) PutUint64(v uint64) (b [8]byte) { - return [...]byte{ - byte(v >> 56), - byte(v >> 48), - byte(v >> 40), - byte(v >> 32), - byte(v >> 24), - byte(v >> 16), - byte(v >> 8), - byte(v), - } -} - -func (z bigenHelper) Uint16(b [2]byte) (v uint16) { - return uint16(b[1]) | - uint16(b[0])<<8 -} - -func (z bigenHelper) Uint32(b [4]byte) (v uint32) { - return uint32(b[3]) | - uint32(b[2])<<8 | - uint32(b[1])<<16 | - uint32(b[0])<<24 -} - -func (z bigenHelper) Uint64(b [8]byte) (v uint64) { - return uint64(b[7]) | - uint64(b[6])<<8 | - uint64(b[5])<<16 | - uint64(b[4])<<24 | - uint64(b[3])<<32 | - uint64(b[2])<<40 | - uint64(b[1])<<48 | - uint64(b[0])<<56 -} - -type extTypeTagFn struct { - rtid uintptr - rtidptr uintptr - rt reflect.Type - tag uint64 - ext Ext -} - -type extHandle []extTypeTagFn - -// AddExt registes an encode and decode function for a reflect.Type. -// To deregister an Ext, call AddExt with nil encfn and/or nil decfn. -// -// Deprecated: Use SetBytesExt or SetInterfaceExt on the Handle instead. -func (x *BasicHandle) AddExt(rt reflect.Type, tag byte, - encfn func(reflect.Value) ([]byte, error), - decfn func(reflect.Value, []byte) error) (err error) { - if encfn == nil || decfn == nil { - return x.SetExt(rt, uint64(tag), nil) - } - return x.SetExt(rt, uint64(tag), addExtWrapper{encfn, decfn}) -} - -// SetExt will set the extension for a tag and reflect.Type. -// Note that the type must be a named type, and specifically not a pointer or Interface. -// An error is returned if that is not honored. -// To Deregister an ext, call SetExt with nil Ext. -// -// It will throw an error if called after the Handle has been initialized. -// -// Deprecated: Use SetBytesExt or SetInterfaceExt on the Handle instead (which *may* internally call this) -func (x *BasicHandle) SetExt(rt reflect.Type, tag uint64, ext Ext) (err error) { - if x.isInited() { - return errHandleInited - } - return x.basicHandleRuntimeState.setExt(rt, tag, ext) -} - -func (o extHandle) getExtForI(x interface{}) (v *extTypeTagFn) { - if len(o) > 0 { - v = o.getExt(i2rtid(x), true) - } - return -} - -func (o extHandle) getExt(rtid uintptr, check bool) (v *extTypeTagFn) { - if !check { - return - } - for i := range o { - v = &o[i] - if v.rtid == rtid || v.rtidptr == rtid { - return - } - } - return nil -} - -func (o extHandle) getExtForTag(tag uint64) (v *extTypeTagFn) { - for i := range o { - v = &o[i] - if v.tag == tag { - return - } - } - return nil -} - -type intf2impl struct { - rtid uintptr // for intf - impl reflect.Type -} - -type intf2impls []intf2impl - -// Intf2Impl maps an interface to an implementing type. -// This allows us support infering the concrete type -// and populating it when passed an interface. -// e.g. var v io.Reader can be decoded as a bytes.Buffer, etc. -// -// Passing a nil impl will clear the mapping. -func (o *intf2impls) Intf2Impl(intf, impl reflect.Type) (err error) { - if impl != nil && !impl.Implements(intf) { - return fmt.Errorf("Intf2Impl: %v does not implement %v", impl, intf) - } - rtid := rt2id(intf) - o2 := *o - for i := range o2 { - v := &o2[i] - if v.rtid == rtid { - v.impl = impl - return - } - } - *o = append(o2, intf2impl{rtid, impl}) - return -} - -func (o intf2impls) intf2impl(rtid uintptr) (rv reflect.Value) { - for i := range o { - v := &o[i] - if v.rtid == rtid { - if v.impl == nil { - return - } - vkind := v.impl.Kind() - if vkind == reflect.Ptr { - return reflect.New(v.impl.Elem()) - } - return rvZeroAddrK(v.impl, vkind) - } - } - return -} - -type structFieldInfoNode struct { - offset uint16 - index uint16 - kind uint8 - numderef uint8 - _ uint16 // padding - - typ reflect.Type -} - -// structFieldinfopathNode is a node in a tree, which allows us easily -// walk the anonymous path. -// -// In the typical case, the node is not embedded/anonymous, and thus the parent -// will be nil and this information becomes a value (not needing any indirection). -type structFieldInfoPathNode struct { - parent *structFieldInfoPathNode - structFieldInfoNode -} - -// depth returns number of valid nodes in the hierachy -func (path *structFieldInfoPathNode) depth() (d int) { -TOP: - if path != nil { - d++ - path = path.parent - goto TOP - } - return -} - -// MARKER: fully working code - commented out as we inline the code in sfi.field(No)Alloc -// // field returns the field of the struct. -// func (n *structFieldInfoPathNode) field(v reflect.Value, alloc, base bool) (rv reflect.Value) { -// if n.parent != nil { -// v = n.parent.field(v, alloc, true) -// if !v.IsValid() { -// return -// } -// } -// return n.structFieldInfoNode.field(v, alloc, base) -// } - -type structFieldInfo struct { - encName string // encode name - - // encNameHash uintptr - - // fieldName string // currently unused - - encNameEscape4Json bool - omitEmpty bool - - ptrKind bool - - encBuiltin bool // is field supported for encoding as a builtin? - decBuiltin bool // is field addr supported for decoding as a builtin? - - node structFieldInfoNode - parents []structFieldInfoNode - - // path structFieldInfoPathNode - - baseTyp reflect.Type - ptrTyp reflect.Type -} - -// MARKER: fully working code - commented out as we inline the code in sfi.field(No)Alloc -// func (n *structFieldInfo) field(v reflect.Value, alloc, base bool) (rv reflect.Value) { -// for i := range n.parents { -// v = n.parents[i].field(v, alloc, true) -// if !v.IsValid() { -// return -// } -// } -// return n.node.field(v, alloc, base) -// } - -func (n *structFieldInfo) fieldAlloc(v reflect.Value) reflect.Value { - // return n.path.field(v, true, true) - // return n.field(v, true, true) - var j, nd uint8 - for i := range n.parents { - v = n.parents[i].rvField(v) - nd = n.parents[i].numderef - for j = 0; j < nd; j++ { - if rvPtrIsNil(v) { - rvSetDirect(v, reflect.New(v.Type().Elem())) - } - v = v.Elem() - } - } - v = n.node.rvField(v) - nd = n.node.numderef - for j = 0; j < nd; j++ { - if rvPtrIsNil(v) { - rvSetDirect(v, reflect.New(v.Type().Elem())) - } - v = v.Elem() - } - return v -} - -func (n *structFieldInfo) fieldNoAlloc(v reflect.Value, base bool) (rv reflect.Value) { - // return n.path.field(v, false, base) - // return n.field(v, false, base) - var j, nd uint8 - for i := range n.parents { - v = n.parents[i].rvField(v) - nd = n.parents[i].numderef - for j = 0; j < nd; j++ { - if rvPtrIsNil(v) { - return reflect.Value{} - } - v = v.Elem() - } - } - v = n.node.rvField(v) - rv = v - nd = n.node.numderef - for j = 0; j < nd; j++ { - if rvPtrIsNil(v) { - return reflect.Value{} - } - v = v.Elem() - } - if base { - rv = v - } - return -} - -func parseStructInfo(stag string) (toArray, omitEmpty bool, keytype valueType) { - keytype = valueTypeString // default - if stag == "" { - return - } - ss := strings.Split(stag, ",") - if len(ss) < 2 { - return - } - for _, s := range ss[1:] { - switch s { - case "omitempty": - omitEmpty = true - case "toarray": - toArray = true - case "int": - keytype = valueTypeInt - case "uint": - keytype = valueTypeUint - case "float": - keytype = valueTypeFloat - // case "bool": - // keytype = valueTypeBool - case "string": - keytype = valueTypeString - } - } - return -} - -func parseStructFieldTag(stag string) (encName string, omitEmpty bool) { - if stag == "" { - return - } - for i, s := range strings.Split(stag, ",") { - if i == 0 { - if s != "" { - encName = s - } - continue - } - if s == "omitempty" { - omitEmpty = true - } - } - return -} - -// ---- - -type uint8To32TrieNode struct { - uint8To32TrieNodeNoKids - kids uint8To32TrieNodeKids -} - -func (x *uint8To32TrieNode) reset(v uint8) { - x.key = v - x.value = 0 - x.valid = false - x.truncKids() -} - -func (x *uint8To32TrieNode) expandKids() (r *uint8To32TrieNode) { - // since we want to reuse the slices, let's not use append as it will - // always overwrite the value. Only append if we're expanding - kids := x.getKids() - if cap(kids) > len(kids) { - kids = kids[:len(kids)+1] - } else { - kids = append(kids, uint8To32TrieNode{}) - } - x.setKids(kids) - r = &kids[len(kids)-1] - return -} - -func (x *uint8To32TrieNode) put(v uint8) (r *uint8To32TrieNode) { - kids := x.getKids() - for i := range kids { - if kids[i].key == v { - return &kids[i] - } - } - - r = x.expandKids() - r.reset(v) - return r -} - -func (x *uint8To32TrieNode) puts(s string, v uint32) (r *uint8To32TrieNode) { - for _, c := range []byte(s) { - x = x.put(c) - } - x.value = v - x.valid = true - return x -} - -func (x *uint8To32TrieNode) gets(s []byte) (v uint32, ok bool) { -TOP: - for _, b := range s { - kids := x.getKids() - for i := range kids { - if kids[i].key == b { - x = &kids[i] - continue TOP - } - } - return 0, false - } - return x.value, x.valid -} - -func (x *uint8To32TrieNode) deepNumKids() (n int) { - kids := x.getKids() - n = len(kids) - for i := range kids { - n += kids[i].deepNumKids() - } - return -} - -// arena just helps all the nodes stay close for better cache-line performance. -// It basically tries to load up all the nodes within a contiguous space of memory. -type uint8To32TrieNodeArena struct { - arena []uint8To32TrieNode - cursor int -} - -func (x *uint8To32TrieNodeArena) init(v *uint8To32TrieNode) (r *uint8To32TrieNode) { - x.arena = make([]uint8To32TrieNode, v.deepNumKids()+1) // incl one for the node, and one buffer - r = &x.arena[0] - x.cursor++ - x.clone(r, v) - return -} - -func (x *uint8To32TrieNodeArena) clone(dst, src *uint8To32TrieNode) { - dst.uint8To32TrieNodeNoKids = src.uint8To32TrieNodeNoKids - // dst.kids = nil - srckids := src.getKids() - c := len(srckids) - if c == 0 { - return - } - dstkids := x.arena[x.cursor:][:c:c] - dst.setKids(dstkids) - x.cursor += c - for i := range srckids { - x.clone(&dstkids[i], &srckids[i]) - } -} - -// ---- - -var pool4SFIs = sync.Pool{ - New: func() interface{} { - return &uint8To32TrieNode{} - }, -} - -func (x *structFieldInfos) finish() { - var src *uint8To32TrieNode - if usePoolForSFIs { - src = pool4SFIs.Get().(*uint8To32TrieNode) - } else { - src = &x.t - } - x.loadSearchTrie(src) - if useArenaForSFIs { - var ar uint8To32TrieNodeArena - x.t = *(ar.init(src)) - } - if usePoolForSFIs { - src.reset(0) - pool4SFIs.Put(src) - } -} - -func (x *structFieldInfos) loadSearchTrie(src *uint8To32TrieNode) { - // load the search trie - for i, v := range x.source() { - src.puts(v.encName, uint32(i)) - } -} - -func (x *structFieldInfos) search(name []byte) (sfi *structFieldInfo) { - n, ok := x.t.gets(name) - if ok { - sfi = x.source()[n] - } - return -} - -type sfiSortedByEncName []*structFieldInfo - -func (p sfiSortedByEncName) Len() int { return len(p) } -func (p sfiSortedByEncName) Swap(i, j int) { p[uint(i)], p[uint(j)] = p[uint(j)], p[uint(i)] } -func (p sfiSortedByEncName) Less(i, j int) bool { return p[uint(i)].encName < p[uint(j)].encName } - -// typeInfo4Container holds information that is only available for -// containers like map, array, chan, slice. -type typeInfo4Container struct { - elem reflect.Type - // key is: - // - if map kind: map key - // - if array kind: sliceOf(elem) - // - if chan kind: sliceof(elem) - key reflect.Type - - // fastpathUnderlying is underlying type of a named slice/map/array, as defined by go spec, - // that is used by fastpath where we defined fastpath functions for the underlying type. - // - // for a map, it's a map; for a slice or array, it's a slice; else its nil. - fastpathUnderlying reflect.Type - - tikey *typeInfo - tielem *typeInfo -} - -// typeInfo keeps static (non-changing readonly) information -// about each (non-ptr) type referenced in the encode/decode sequence. -// -// During an encode/decode sequence, we work as below: -// - If base is a built in type, en/decode base value -// - If base is registered as an extension, en/decode base value -// - If type is binary(M/Unm)arshaler, call Binary(M/Unm)arshal method -// - If type is text(M/Unm)arshaler, call Text(M/Unm)arshal method -// - Else decode appropriately based on the reflect.Kind -type typeInfo struct { - rt reflect.Type - ptr reflect.Type - - // pkgpath string - - rtid uintptr - - numMeth uint16 // number of methods - kind uint8 - chandir uint8 - - // simple=true if a struct, AND - // - none of the fields are tagged "omitempty" - // - no missingFielder - // - keyType is always string - // - noEsc4Json on any fields - simple bool - toArray bool // whether this (struct) type should be encoded as an array - keyType valueType // if struct, how is the field name stored in a stream? default is string - mbs bool // base type (T or *T) is a MapBySlice - - *typeInfo4Container - - // ---- cpu cache line boundary? - - size, keysize, elemsize uint32 - - keykind, elemkind uint8 - - flagHasPkgPath bool // Type.PackagePath != "" - flagComparable bool - flagCanTransient bool - - flagMarshalInterface bool // does this have custom (un)marshal implementation? - - // custom implementation flags - flagIsZeroer bool - flagIsZeroerPtr bool - - flagIsCodecEmptyer bool - flagIsCodecEmptyerPtr bool - - flagBinaryMarshaler bool - flagBinaryMarshalerPtr bool - - flagBinaryUnmarshaler bool - flagBinaryUnmarshalerPtr bool - - flagTextMarshaler bool - flagTextMarshalerPtr bool - - flagTextUnmarshaler bool - flagTextUnmarshalerPtr bool - - flagJsonMarshaler bool - flagJsonMarshalerPtr bool - - flagJsonUnmarshaler bool - flagJsonUnmarshalerPtr bool - - flagSelfer bool - flagSelferPtr bool - - flagMissingFielder bool - flagMissingFielderPtr bool - - flagEncBuiltin bool - flagDecBuiltin bool - - infoFieldOmitempty bool - - // MARKER - may need padding here (like 6 bytes - auto-handled) - sfi structFieldInfos -} - -func (ti *typeInfo) siForEncName(name []byte) (si *structFieldInfo) { - return ti.sfi.search(name) -} - -func (ti *typeInfo) resolve(x []structFieldInfo, ss map[string]uint16) (n int) { - n = len(x) - for i := range x { - ui := uint16(i) - sf := &x[ui] - xn := sf.encName - j, ok := ss[xn] - if !ok { - ss[xn] = ui - continue - } - if ui == j { - continue - } - // if x[i].path.depth() < x[j].path.depth() { // this one is shallower - sf2 := &x[j] - if len(sf.parents) < len(sf2.parents) { // this one is shallower - ss[xn] = ui - sf = sf2 - } - if sf.encName == "" { - continue - } - sf.encName = "" - n-- - } - return -} - -func (ti *typeInfo) init(x []structFieldInfo, n int) { - simple := true - - if ti.flagMissingFielder || ti.flagMissingFielderPtr || - ti.keyType != valueTypeString { - simple = false - } - - // remove all the nils (non-ready) - // m := make(map[string]*structFieldInfo, n) - w := make([]structFieldInfo, n) - y := make([]*structFieldInfo, n+n) - z := y[n:] - y = y[:n] - n = 0 - for i := range x { - sfi := &x[i] - if sfi.encName == "" { - continue - } - if simple && (sfi.omitEmpty || sfi.encNameEscape4Json) { - simple = false - } - w[n] = *sfi - sfi = &w[n] - y[n] = sfi - // m[sfi.encName] = sfi - n++ - } - if n != len(y) { - halt.errorf("failure reading struct %v - expecting %d of %d valid fields, got %d", ti.rt, len(y), len(x), any(n)) - } - - ti.simple = simple - - copy(z, y) - sort.Sort(sfiSortedByEncName(z)) - - ti.sfi.load(y, z) - ti.sfi.finish() - // ti.sfi.byName = m -} - -// isCanTransient returns whether this type can be transient. -// -// # Handling flagCanTransient -// -// We support transient optimization if the kind of the type is -// - a number, bool, string -// - slice (of number/bool) -// - struct with no reference values (pointers, interface, etc) recursively -// - array with no reference values (pointers, interface, etc) recursively -// -// NOTE: all reference types (string, slice, func, map, ptr, interface, etc) have pointers. -// -// If using transient for a type with a pointer, there is the potential for data corruption -// when GC tries to follow a "transient" pointer which may become a non-pointer soon after. -func isCanTransient(t reflect.Type, inclStrSlice bool) (v bool) { - k := t.Kind() - bset := &numBoolBitset - if inclStrSlice { - bset = &numBoolStrSliceBitset - } - if bset.isset(byte(k)) { - v = true - } else if k == reflect.Array { - v = isCanTransient(t.Elem(), false) - } else if k == reflect.Struct { - v = true - for j, jlen := 0, t.NumField(); j < jlen; j++ { - f := t.Field(j) - if !isCanTransient(f.Type, false) { - return false - } - } - } - return -} - -type rtid2ti struct { - rtid uintptr - ti *typeInfo -} - -// TypeInfos caches typeInfo for each type on first inspection. -// -// It is configured with a set of tag keys, which are used to get -// configuration for the type. -type TypeInfos struct { - infos atomic.Pointer[[]rtid2ti] // atomicTypeInfoSlice - mu sync.Mutex - _ uint64 // padding (cache-aligned) - tags []string - _ uint64 // padding (cache-aligned) -} - -// NewTypeInfos creates a TypeInfos given a set of struct tags keys. -// -// This allows users customize the struct tag keys which contain configuration -// of their types. -func NewTypeInfos(tags []string) *TypeInfos { - return &TypeInfos{tags: tags} -} - -func (x *TypeInfos) structTag(t reflect.StructTag) (s string) { - // check for tags: codec, json, in that order. - // this allows seamless support for many configured structs. - for _, x := range x.tags { - s = t.Get(x) - if s != "" { - return s - } - } - return -} - -func findTypeInfo(s []rtid2ti, rtid uintptr) (i uint, ti *typeInfo) { - // binary search. adapted from sort/search.go. - // Note: we use goto (instead of for loop) so this can be inlined. - - var h uint - var j = uint(len(s)) -LOOP: - if i < j { - h = (i + j) >> 1 // avoid overflow when computing h // h = i + (j-i)/2 - if s[h].rtid < rtid { - i = h + 1 - } else { - j = h - } - goto LOOP - } - if i < uint(len(s)) && s[i].rtid == rtid { - ti = s[i].ti - } - return -} - -func (x *TypeInfos) get(rtid uintptr, rt reflect.Type) (pti *typeInfo) { - if pti = x.find(rtid); pti == nil { - pti = x.load(rt) - } - return -} - -func (x *TypeInfos) find(rtid uintptr) (pti *typeInfo) { - sp := x.infos.Load() - if sp != nil { - _, pti = findTypeInfo(*sp, rtid) - } - return -} - -func (x *TypeInfos) load(rt reflect.Type) (pti *typeInfo) { - rk := rt.Kind() - - if rk == reflect.Ptr { // || (rk == reflect.Interface && rtid != intfTypId) { - halt.errorf("invalid kind passed to TypeInfos.get: %v - %v", rk.String(), rt) - } - - rtid := rt2id(rt) - - // do not hold lock while computing this. - // it may lead to duplication, but that's ok. - ti := typeInfo{ - rt: rt, - ptr: reflect.PointerTo(rt), - rtid: rtid, - kind: uint8(rk), - size: uint32(rt.Size()), - numMeth: uint16(rt.NumMethod()), - keyType: valueTypeString, // default it - so it's never 0 - - // pkgpath: rt.PkgPath(), - flagHasPkgPath: rt.PkgPath() != "", - } - - _, ti.flagEncBuiltin = searchRtids(encBuiltinRtids, rtid) - _, ti.flagDecBuiltin = searchRtids(decBuiltinRtids, rtid) - if !ti.flagDecBuiltin { - _, ti.flagDecBuiltin = searchRtids(decBuiltinRtids, rt2id(ti.ptr)) - } - - // bset sets custom implementation flags - bset := func(when bool, b *bool) { - if when { - *b = true - } - } - - var b1, b2 bool - - b1, b2 = implIntf(rt, binaryMarshalerTyp) - bset(b1, &ti.flagBinaryMarshaler) - bset(b2, &ti.flagBinaryMarshalerPtr) - b1, b2 = implIntf(rt, binaryUnmarshalerTyp) - bset(b1, &ti.flagBinaryUnmarshaler) - bset(b2, &ti.flagBinaryUnmarshalerPtr) - b1, b2 = implIntf(rt, textMarshalerTyp) - bset(b1, &ti.flagTextMarshaler) - bset(b2, &ti.flagTextMarshalerPtr) - b1, b2 = implIntf(rt, textUnmarshalerTyp) - bset(b1, &ti.flagTextUnmarshaler) - bset(b2, &ti.flagTextUnmarshalerPtr) - b1, b2 = implIntf(rt, jsonMarshalerTyp) - bset(b1, &ti.flagJsonMarshaler) - bset(b2, &ti.flagJsonMarshalerPtr) - b1, b2 = implIntf(rt, jsonUnmarshalerTyp) - bset(b1, &ti.flagJsonUnmarshaler) - bset(b2, &ti.flagJsonUnmarshalerPtr) - b1, b2 = implIntf(rt, selferTyp) - bset(b1, &ti.flagSelfer) - bset(b2, &ti.flagSelferPtr) - b1, b2 = implIntf(rt, missingFielderTyp) - bset(b1, &ti.flagMissingFielder) - bset(b2, &ti.flagMissingFielderPtr) - b1, b2 = implIntf(rt, iszeroTyp) - bset(b1, &ti.flagIsZeroer) - bset(b2, &ti.flagIsZeroerPtr) - b1, b2 = implIntf(rt, isCodecEmptyerTyp) - bset(b1, &ti.flagIsCodecEmptyer) - bset(b2, &ti.flagIsCodecEmptyerPtr) - - ti.flagMarshalInterface = ti.flagSelfer || ti.flagSelferPtr || - ti.flagBinaryMarshaler || ti.flagBinaryMarshalerPtr || - ti.flagBinaryUnmarshaler || ti.flagBinaryUnmarshalerPtr || - ti.flagTextMarshaler || ti.flagTextMarshalerPtr || - ti.flagTextUnmarshaler || ti.flagTextUnmarshalerPtr || - ti.flagJsonMarshaler || ti.flagJsonMarshalerPtr || - ti.flagJsonUnmarshaler || ti.flagJsonUnmarshalerPtr - - b1 = rt.Comparable() - // bset(b1, &ti.flagComparable) - ti.flagComparable = b1 - - ti.flagCanTransient = isTransientType4Size(ti.size) && isCanTransient(ti.rt, true) - - var tt reflect.Type - switch rk { - case reflect.Struct: - var omitEmpty bool - if f, ok := rt.FieldByName(structInfoFieldName); ok { - ti.toArray, omitEmpty, ti.keyType = parseStructInfo(x.structTag(f.Tag)) - ti.infoFieldOmitempty = omitEmpty - } else { - ti.keyType = valueTypeString - } - var pi interface{} - var pv *typeInfoLoad - if usePoolForTypeInfoLoad { - pi = poolForTypeInfoLoad.Get() - pv = pi.(*typeInfoLoad) - pv.reset() - } else { - pv = newTypeInfoLoad() - } - pv.etypes = append(pv.etypes, ti.rtid) - x.rget(rt, nil, pv, omitEmpty) - n := ti.resolve(pv.sfis, pv.sfiNames) - ti.init(pv.sfis, n) - if usePoolForTypeInfoLoad { - poolForTypeInfoLoad.Put(pi) - } - case reflect.Map: - ti.typeInfo4Container = new(typeInfo4Container) - ti.elem = rt.Elem() - for tt = ti.elem; tt.Kind() == reflect.Ptr; tt = tt.Elem() { - } - ti.tielem = x.get(rt2id(tt), tt) - ti.elemkind = uint8(ti.elem.Kind()) - ti.elemsize = uint32(ti.elem.Size()) - ti.key = rt.Key() - for tt = ti.key; tt.Kind() == reflect.Ptr; tt = tt.Elem() { - } - ti.tikey = x.get(rt2id(tt), tt) - ti.keykind = uint8(ti.key.Kind()) - ti.keysize = uint32(ti.key.Size()) - if ti.flagHasPkgPath { - ti.fastpathUnderlying = reflect.MapOf(ti.key, ti.elem) - } - case reflect.Slice: - ti.typeInfo4Container = new(typeInfo4Container) - ti.mbs, b2 = implIntf(rt, mapBySliceTyp) - if !ti.mbs && b2 { - ti.mbs = b2 - } - ti.elem = rt.Elem() - for tt = ti.elem; tt.Kind() == reflect.Ptr; tt = tt.Elem() { - } - ti.tielem = x.get(rt2id(tt), tt) - ti.elemkind = uint8(ti.elem.Kind()) - ti.elemsize = uint32(ti.elem.Size()) - if ti.flagHasPkgPath { - ti.fastpathUnderlying = reflect.SliceOf(ti.elem) - } - case reflect.Chan: - ti.typeInfo4Container = new(typeInfo4Container) - ti.elem = rt.Elem() - for tt = ti.elem; tt.Kind() == reflect.Ptr; tt = tt.Elem() { - } - ti.tielem = x.get(rt2id(tt), tt) - ti.elemkind = uint8(ti.elem.Kind()) - ti.elemsize = uint32(ti.elem.Size()) - ti.chandir = uint8(rt.ChanDir()) - ti.key = reflect.SliceOf(ti.elem) - ti.keykind = uint8(reflect.Slice) - case reflect.Array: - ti.typeInfo4Container = new(typeInfo4Container) - ti.mbs, b2 = implIntf(rt, mapBySliceTyp) - if !ti.mbs && b2 { - ti.mbs = b2 - } - ti.elem = rt.Elem() - ti.elemkind = uint8(ti.elem.Kind()) - ti.elemsize = uint32(ti.elem.Size()) - for tt = ti.elem; tt.Kind() == reflect.Ptr; tt = tt.Elem() { - } - ti.tielem = x.get(rt2id(tt), tt) - ti.key = reflect.SliceOf(ti.elem) - ti.keykind = uint8(reflect.Slice) - ti.keysize = uint32(ti.key.Size()) - if ti.flagHasPkgPath { - ti.fastpathUnderlying = ti.key - } - - // MARKER: reflect.Ptr cannot happen here, as we halt early if reflect.Ptr passed in - // case reflect.Ptr: - // ti.elem = rt.Elem() - // ti.elemkind = uint8(ti.elem.Kind()) - // ti.elemsize = uint32(ti.elem.Size()) - } - - x.mu.Lock() - var sp []rtid2ti - if spt := x.infos.Load(); spt != nil { - sp = *spt - } - // since this is an atomic load/store, we MUST use a different array each time, - // else we have a data race when a store is happening simultaneously with a findRtidFn call. - if sp == nil { - pti = &ti - sp = []rtid2ti{{rtid, pti}} - x.infos.Store(&sp) - } else { - var idx uint - idx, pti = findTypeInfo(sp, rtid) - if pti == nil { - pti = &ti - sp2 := make([]rtid2ti, len(sp)+1) - copy(sp2[idx+1:], sp[idx:]) - copy(sp2, sp[:idx]) - sp2[idx] = rtid2ti{rtid, pti} - x.infos.Store(&sp2) - } - } - x.mu.Unlock() - return -} - -func (x *TypeInfos) rget(rt reflect.Type, path *structFieldInfoPathNode, pv *typeInfoLoad, defaultOmitEmpty bool) { - // Read up fields and store how to access the value. - // - // It uses go's rules for message selectors, - // which say that the field with the shallowest depth is selected. - // - // Note: we consciously use slices, not a map, to simulate a set. - // Typically, types have < 16 fields, - // and iteration using equals is faster than maps there - flen := rt.NumField() -LOOP: - for j, jlen := uint16(0), uint16(flen); j < jlen; j++ { - f := rt.Field(int(j)) - fkind := f.Type.Kind() - - // skip if a func type, or is unexported, or structTag value == "-" - switch fkind { - case reflect.Func, reflect.UnsafePointer: - continue LOOP - } - - isUnexported := f.PkgPath != "" - if isUnexported && !f.Anonymous { - continue - } - stag := x.structTag(f.Tag) - if stag == "-" { - continue - } - - var numderef uint8 = 0 - ft := f.Type - for ; ft.Kind() == reflect.Ptr; ft = ft.Elem() { - numderef++ - } - - var encName string - var parsed, omitEmpty bool - - ftid := rt2id(ft) - // if anonymous and no struct tag (or it's blank), - // and a struct (or pointer to struct), inline it. - if f.Anonymous && fkind != reflect.Interface { - // ^^ redundant but ok: per go spec, an embedded pointer type cannot be to an interface - isPtr := f.Type.Kind() == reflect.Ptr - isStruct := ft.Kind() == reflect.Struct - - // Ignore embedded fields of unexported non-struct types. - // Also, from go1.10, ignore pointers to unexported struct types - // because unmarshal cannot assign a new struct to an unexported field. - // See https://golang.org/issue/21357 - if isUnexported && (!isStruct || isPtr) { - continue - } - doInline := stag == "" - if !doInline { - encName, omitEmpty = parseStructFieldTag(stag) - parsed = true - doInline = encName == "" // si.isZero() - } - if doInline && isStruct { - // if etypes contains this, don't call rget again (as fields are already seen here) - // - // We cannot recurse forever, but we need to track other field depths. - // So - we break if we see a type twice (not the first time). - // This should be sufficient to handle an embedded type that refers to its - // owning type, which then refers to its embedded type. - processIt := true - numk := 0 - for _, k := range pv.etypes { - if k == ftid { - numk++ - if numk == rgetMaxRecursion { - processIt = false - break - } - } - } - if processIt { - pv.etypes = append(pv.etypes, ftid) - path2 := &structFieldInfoPathNode{ - parent: path, - structFieldInfoNode: structFieldInfoNode{ - typ: f.Type, - offset: uint16(f.Offset), - index: j, - kind: uint8(fkind), - numderef: numderef, - }, - } - x.rget(ft, path2, pv, defaultOmitEmpty) - } - continue - } - } - - // after the anonymous dance: if an unexported field, skip - if isUnexported || f.Name == "" || f.Name == structInfoFieldName { // f.Name cannot be "", but defensively handle it - continue - } - - if !parsed { - encName, omitEmpty = parseStructFieldTag(stag) - parsed = true - } - if encName == "" { - encName = f.Name - } - if defaultOmitEmpty { - omitEmpty = true - } - - var si = structFieldInfo{ - encName: encName, - omitEmpty: omitEmpty, - ptrKind: fkind == reflect.Ptr, - baseTyp: ft, - ptrTyp: reflect.PointerTo(ft), - } - - // si.path = structFieldInfoPathNode{ - // parent: path, - // structFieldInfoNode: structFieldInfoNode{ - // typ: f.Type, - // offset: uint16(f.Offset), - // index: j, - // kind: uint8(fkind), - // numderef: numderef, - // }, - // } - - si.node = structFieldInfoNode{ - typ: f.Type, - offset: uint16(f.Offset), - index: j, - kind: uint8(fkind), - numderef: numderef, - } - - if path != nil { - si.parents = make([]structFieldInfoNode, path.depth()) - for k, p := len(si.parents)-1, path; k >= 0; k-- { - si.parents[k] = p.structFieldInfoNode - p = p.parent - } - } - - // ftid = rt2id(ft) where ft = si.baseTyp) - _, si.encBuiltin = searchRtids(encBuiltinRtids, ftid) - _, si.decBuiltin = searchRtids(decBuiltinRtids, ftid) - if !si.decBuiltin { - _, si.decBuiltin = searchRtids(decBuiltinRtids, rt2id(si.ptrTyp)) - } - // si.encNameHash = maxUintptr() // hashShortString(bytesView(si.encName)) - - for i := len(si.encName) - 1; i >= 0; i-- { // bounds-check elimination - if !jsonCharSafeBitset.isset(si.encName[i]) { - si.encNameEscape4Json = true - break - } - } - - pv.sfis = append(pv.sfis, si) - } -} - -type timeRv struct { - v time.Time - r reflect.Value -} - -type bytesRv struct { - v []byte - r reflect.Value -} - -type stringIntf struct { - v string - i interface{} -} - -func cmpTimeRv(v1, v2 timeRv) int { - return v1.v.Compare(v2.v) -} - -func cmpBytesRv(v1, v2 bytesRv) int { - return bytes.Compare(v1.v, v2.v) -} - -func implIntf(rt, iTyp reflect.Type) (base bool, indir bool) { - // return rt.Implements(iTyp), reflect.PtrTo(rt).Implements(iTyp) - - // if I's method is defined on T (ie T implements I), then *T implements I. - // The converse is not true. - - // Type.Implements can be expensive, as it does a simulataneous linear search across 2 lists - // with alphanumeric string comparisons. - // If we can avoid running one of these 2 calls, we should. - - base = rt.Implements(iTyp) - if base { - indir = true - } else { - indir = reflect.PointerTo(rt).Implements(iTyp) - } - return -} - -func bytesOK(bs []byte, _ bool) []byte { - return bs -} - -func bool2int(b bool) (v uint8) { - // MARKER: optimized to be a single instruction - if b { - v = 1 - } - return -} - -func isSliceBoundsError(s string) bool { - return strings.Contains(s, "index out of range") || // indexing error - strings.Contains(s, "slice bounds out of range") || // slicing error - strings.Contains(s, "cannot convert slice with length") // slice-->array error -} - -func sprintf(format string, v ...interface{}) string { - return fmt.Sprintf(format, v...) -} - -func snip(v []byte) []byte { - return v[:min(96, len(v))] -} - -// These constants are used within debugf. -// If the first parameter to debugf is one of these, it determines -// the ANSI color used within the ANSI terminal. -// -// They make it easier to write different groups of debug statements -// with a visual aid. -const ( - hlSFX = "\033[0m" - hlPFX = "\033[1;" - hlBLACK = hlPFX + "30" + "m" - hlRED = hlPFX + "31" + "m" - hlGREEN = hlPFX + "32" + "m" - hlYELLOW = hlPFX + "33" + "m" - hlBLUE = hlPFX + "34" + "m" - hlPURPLE = hlPFX + "35" + "m" - hlCYAN = hlPFX + "36" + "m" - hlWHITE = hlPFX + "37" + "m" - // hlORANGE = hlYELLOW -) - -// debugf will print debug statements to the screen whether or not debugging is on -// -// Note: if first parameter in a is one of the hlXXX vars, then we treat it as a hint -// to highlight in different colors. -// -//go:noinline -func debugf(s string, a ...any) { - if !debugLogging { - return - } - if len(s) == 0 { - return - } - if s[len(s)-1] != '\n' { - s = s + "\n" - } - if len(a) > 0 { - switch a[0] { - case hlBLACK, hlRED, hlGREEN, hlYELLOW, hlBLUE, hlPURPLE, hlCYAN, hlWHITE: - s = a[0].(string) + s + hlSFX - a = a[1:] - } - } - fmt.Printf(s, a...) -} - -func panicToErr(h errDecorator, fn func()) (err error) { - defer panicValToErr(h, callRecoverSentinel, &err, nil, debugging) - fn() - return -} - -// panicValToErr will convert a panic value into an error -// -// err and recovered are guaranteed to be not nil -func panicValToErr(h errDecorator, recovered interface{}, err, errCopy *error, panicAgain bool) { - if recovered == callRecoverSentinel { - recovered = recover() - } - if recovered == nil || err == nil { - return - } - if recovered == *err { - goto HANDLE_COPY - } - switch xerr := recovered.(type) { - case *outOfBoundsError: - h.wrapErr(xerr, err) - case runtime.Error: - switch d := h.(type) { - case decoderI: - if d.isBytes() && isSliceBoundsError(xerr.Error()) { - // *err = io.ErrUnexpectedEOF - h.wrapErr(io.ErrUnexpectedEOF, err) - } else { - h.wrapErr(xerr, err) - } - default: - h.wrapErr(xerr, err) - } - case error: - switch xerr { - case nil: - case io.EOF, io.ErrUnexpectedEOF, errEncoderNotInitialized, errDecoderNotInitialized: - // treat as special (bubble up) - // *err = xerr - h.wrapErr(xerr, err) - default: - h.wrapErr(xerr, err) - } - case string: - h.wrapErr(errors.New(xerr), err) - // *err = errors.New(xerr) - default: - // we don't expect this to happen (as this library always panics with an error) - h.wrapErr(fmt.Errorf("%v", recovered), err) - } -HANDLE_COPY: - if errCopy != nil { - *errCopy = *err - } - if panicAgain { - panic(*err) - } -} - -func usableByteSlice(bs []byte, slen int) (out []byte, isMadeNew bool) { - const maxCap = 1024 * 1024 * 64 // 64MB - // const skipMaxCap = false // allow to test - - // if slen <= 0 { - // return bs[:0], false // return zeroByteSlice, true - // } - - // slen=0 means it's defined-length of 0. - // slen<0 means non-defined length which would be determined in future. - - // if bs is nil, for length=0, ensure we don't return a nil []byte, - // which will cause DecodeBytes (caller) to return a nil []byte incorrectly. - if slen == 0 { - return zeroByteSlice, false - } - if slen < 0 { - return bs[:0], false - } - if slen <= cap(bs) { - return bs[:slen], false - } - // slen > cap(bs) ... handle memory overload appropriately - return make([]byte, min(slen, maxCap)), true - // if skipMaxCap || slen <= maxCap { - // return make([]byte, slen), true - // } - // return make([]byte, maxCap), true -} - -func makeExt(ext interface{}) Ext { - switch t := ext.(type) { - case Ext: - return t - case BytesExt: - return &bytesExtWrapper{BytesExt: t} - case InterfaceExt: - return &interfaceExtWrapper{InterfaceExt: t} - } - return &extFailWrapper{} -} - -func baseRV(v interface{}) (rv reflect.Value) { - // MARKER TODO try using rv4i not reflect.ValueOf - // use reflect.ValueOf, not rv4i, as of go 1.16beta, rv4i was not inlineable - for rv = reflect.ValueOf(v); rv.Kind() == reflect.Ptr; rv = rv.Elem() { - } - return -} - -func baseRVRV(v reflect.Value) (rv reflect.Value) { - for rv = v; rv.Kind() == reflect.Ptr; rv = rv.Elem() { - } - return -} - -func baseRT(v reflect.Type) (vv reflect.Type) { - for vv = v; vv.Kind() == reflect.Ptr; vv = vv.Elem() { - } - return -} - -// ---- - -// these "checkOverflow" functions must be inlinable, and not call anybody. -// Overflow means that the value cannot be represented without wrapping/overflow. -// Overflow=false does not mean that the value can be represented without losing precision -// (especially for floating point). - -type checkOverflow struct{} - -func (checkOverflow) Float32(v float64) (overflow bool) { - if v < 0 { - v = -v - } - return math.MaxFloat32 < v && v <= math.MaxFloat64 -} -func (checkOverflow) Uint(v uint64, bitsize uint8) (overflow bool) { - if v != 0 && v != (v<<(64-bitsize))>>(64-bitsize) { - overflow = true - } - return -} -func (checkOverflow) Int(v int64, bitsize uint8) (overflow bool) { - if v != 0 && v != (v<<(64-bitsize))>>(64-bitsize) { - overflow = true - } - return -} - -func (checkOverflow) Uint2Int(v uint64, neg bool) (overflow bool) { - return (neg && v > 1<<63) || (!neg && v >= 1<<63) -} - -func (checkOverflow) SignedInt(v uint64) (overflow bool) { - //e.g. -127 to 128 for int8 - // pos := (v >> 63) == 0 - // ui2 := v & 0x7fffffffffffffff - // if pos { - // if ui2 > math.MaxInt64 { - // overflow = true - // } - // } else { - // if ui2 > math.MaxInt64-1 { - // overflow = true - // } - // } - - // a signed integer has overflow if the sign (first) bit is 1 (negative) - // and the numbers after the sign bit is > maxint64 - 1 - overflow = (v>>63) != 0 && v&0x7fffffffffffffff > math.MaxInt64-1 - - return -} - -func (x checkOverflow) Float32V(v float64) float64 { - if x.Float32(v) { - halt.errorFloat("float32 overflow: ", v) - } - return v -} -func (x checkOverflow) UintV(v uint64, bitsize uint8) uint64 { - if x.Uint(v, bitsize) { - halt.errorUint("uint64 overflow: ", v) - } - return v -} -func (x checkOverflow) IntV(v int64, bitsize uint8) int64 { - if x.Int(v, bitsize) { - halt.errorInt("int64 overflow: ", v) - } - return v -} -func (x checkOverflow) SignedIntV(v uint64) int64 { - if x.SignedInt(v) { - halt.errorUint("uint64 to int64 overflow: ", v) - } - return int64(v) -} - -// ------------------ FLOATING POINT ----------------- - -func isNaN64(f float64) bool { return f != f } - -func isWhitespaceChar(v byte) bool { - // these are in order of speed below ... - - return v < 33 - // return v < 33 && whitespaceCharBitset64.isset(v) - // return v < 33 && (v == ' ' || v == '\n' || v == '\t' || v == '\r') - // return v == ' ' || v == '\n' || v == '\t' || v == '\r' - // return whitespaceCharBitset.isset(v) -} - -func isNumberChar(v byte) bool { - // these are in order of speed below ... - - return numCharBitset.isset(v) - // return v < 64 && numCharNoExpBitset64.isset(v) || v == 'e' || v == 'E' - // return v > 42 && v < 102 && numCharWithExpBitset64.isset(v-42) -} - -// ----------------------- - -func pruneSignExt(v []byte, pos bool) (n int) { - if len(v) < 2 { - } else if pos && v[0] == 0 { - for ; v[n] == 0 && n+1 < len(v) && (v[n+1]&(1<<7) == 0); n++ { - } - } else if !pos && v[0] == 0xff { - for ; v[n] == 0xff && n+1 < len(v) && (v[n+1]&(1<<7) != 0); n++ { - } - } - return -} - -func halfFloatToFloatBits(h uint16) (f uint32) { - // retrofitted from: - // - OGRE (Object-Oriented Graphics Rendering Engine) - // function: halfToFloatI https://www.ogre3d.org/docs/api/1.9/_ogre_bitwise_8h_source.html - - s := uint32(h >> 15) - m := uint32(h & 0x03ff) - e := int32((h >> 10) & 0x1f) - - if e == 0 { - if m == 0 { // plus or minus 0 - return s << 31 - } - // Denormalized number -- renormalize it - for (m & 0x0400) == 0 { - m <<= 1 - e -= 1 - } - e += 1 - m &= ^uint32(0x0400) - } else if e == 31 { - if m == 0 { // Inf - return (s << 31) | 0x7f800000 - } - return (s << 31) | 0x7f800000 | (m << 13) // NaN - } - e = e + (127 - 15) - m = m << 13 - return (s << 31) | (uint32(e) << 23) | m -} - -func floatToHalfFloatBits(i uint32) (h uint16) { - // retrofitted from: - // - OGRE (Object-Oriented Graphics Rendering Engine) - // function: halfToFloatI https://www.ogre3d.org/docs/api/1.9/_ogre_bitwise_8h_source.html - // - http://www.java2s.com/example/java-utility-method/float-to/floattohalf-float-f-fae00.html - s := (i >> 16) & 0x8000 - e := int32(((i >> 23) & 0xff) - (127 - 15)) - m := i & 0x7fffff - - var h32 uint32 - - if e <= 0 { - if e < -10 { // zero - h32 = s // track -0 vs +0 - } else { - m = (m | 0x800000) >> uint32(1-e) - h32 = s | (m >> 13) - } - } else if e == 0xff-(127-15) { - if m == 0 { // Inf - h32 = s | 0x7c00 - } else { // NAN - m >>= 13 - var me uint32 - if m == 0 { - me = 1 - } - h32 = s | 0x7c00 | m | me - } - } else { - if e > 30 { // Overflow - h32 = s | 0x7c00 - } else { - h32 = s | (uint32(e) << 10) | (m >> 13) - } - } - h = uint16(h32) - return -} - -// ----------------------- - -type ioFlusher interface { - Flush() error -} - -type ioBuffered interface { - Buffered() int -} - -// ----------------------- - -type sfiRv struct { - v *structFieldInfo - r reflect.Value -} - -// ------ - -// bitset types are better than [256]bool, because they permit the whole -// bitset array being on a single cache line and use less memory. -// -// Also, since pos is a byte (0-255), there's no bounds checks on indexing (cheap). -// -// We previously had bitset128 [16]byte, and bitset32 [4]byte, but those introduces -// bounds checking, so we discarded them, and everyone uses bitset256. -// -// given x > 0 and n > 0 and x is exactly 2^n, then pos/x === pos>>n AND pos%x === pos&(x-1). -// consequently, pos/32 === pos>>5, pos/16 === pos>>4, pos/8 === pos>>3, pos%8 == pos&7 -// -// Note that using >> or & is faster than using / or %, as division is quite expensive if not optimized. - -// MARKER: -// We noticed a little performance degradation when using bitset256 as [32]byte (or bitset32 as uint32). -// For example, json encoding went from 188K ns/op to 168K ns/op (~ 10% reduction). -// Consequently, we are using a [NNN]bool for bitsetNNN. -// To eliminate bounds-checking, we use x % v as that is guaranteed to be within bounds. - -// ---- -type bitset32 [32]bool - -func (x *bitset32) set(pos byte) *bitset32 { - x[pos&31] = true // x[pos%32] = true - return x -} -func (x *bitset32) isset(pos byte) bool { - return x[pos&31] // x[pos%32] -} - -type bitset256 [256]bool - -func (x *bitset256) set(pos byte) *bitset256 { - x[pos] = true - return x -} -func (x *bitset256) isset(pos byte) bool { - return x[pos] -} - -// ------------ - -// panicHdl will panic with the parameters passed. -type panicHdl struct{} - -func (panicHdl) onerror(err error) { - if err != nil { - panic(err) - } -} - -func (panicHdl) error(err error) { panic(err) } - -func (panicHdl) errorStr(s string) { panic(s) } - -func (panicHdl) errorStr2(s, s2 string) { panic(s + s2) } - -func (panicHdl) errorBytes(s string, p1 []byte) { panic(s + stringView(p1)) } - -func (v panicHdl) errorByte(prefix string, p1 byte) { - panic(stringView(append(panicHdlBytes(prefix), p1))) -} - -func (v panicHdl) errorInt(prefix string, p1 int64) { - panic(stringView(strconv.AppendInt(panicHdlBytes(prefix), p1, 10))) - // bs := make([]byte, len(prefix)+8) - // bs = append(bs, prefix...) - // bs = strconv.AppendInt(bs, p1, 10) - // panic(stringView(bs)) -} - -func (v panicHdl) errorUint(prefix string, p1 uint64) { - panic(stringView(strconv.AppendUint(panicHdlBytes(prefix), p1, 10))) -} - -func (v panicHdl) errorFloat(prefix string, p1 float64) { - panic(stringView(strconv.AppendFloat(panicHdlBytes(prefix), p1, 'G', -1, 64))) -} - -// MARKER -// consider adding //go:noinline to errorf and maybe other methods - -// errorf will always panic, using the parameters passed. -// -// Note: it is ok to pass in a stringView, as it will just pass it directly -// to a fmt.Sprintf call and not hold onto it. -// -// Since this is an unexported call, we will not be defensive. -// Callers should ensure a non-empty string and 1+ parameter. -func (panicHdl) errorf(format string, params ...interface{}) { - // if format == "" { - // panic(errPanicUndefined) - // } - // if len(params) == 0 { - // panic(errors.New(format)) - // } - panic(fmt.Errorf(format, params...)) -} - -func panicHdlBytes(prefix string) []byte { - return append(make([]byte, len(prefix)+8), prefix...) -} - -// ---------------------------------------------------- - -type errDecorator interface { - wrapErr(in error, out *error) -} - -type errDecoratorDef struct{} - -func (errDecoratorDef) wrapErr(v error, e *error) { *e = v } - -// ---------------------------------------------------- - -type mustHdl struct{} - -func (mustHdl) String(s string, err error) string { - halt.onerror(err) - return s -} -func (mustHdl) Int(s int64, err error) int64 { - halt.onerror(err) - return s -} -func (mustHdl) Uint(s uint64, err error) uint64 { - halt.onerror(err) - return s -} -func (mustHdl) Float(s float64, err error) float64 { - halt.onerror(err) - return s -} - -// ------------------- - -func freelistCapacity(length int) (capacity int) { - for capacity = 8; capacity < length; capacity *= 2 { - } - return -} - -// bytesFreeList is a list of byte buffers, sorted by cap. -// -// In anecdotal testing (running go test -tsd 1..6), we couldn't get -// the length of the list > 4 at any time. So we believe a linear search -// without bounds checking is sufficient. -// -// Typical usage model: -// -// peek may go together with put, iff pop=true. peek gets largest byte slice temporarily. -// check is used to switch a []byte if necessary -// get/put go together -// -// Given that folks may get a []byte, and then append to it a lot which may re-allocate -// a new []byte, we should try to return both (one received from blist and new one allocated). -// -// Typical usage model for get/put, when we don't know whether we may need more than requested -// -// v0 := blist.get() -// v1 := v0 -// ... use v1 ... -// blist.put(v1) -// if !byteSliceSameData(v0, v1) { -// blist.put(v0) -// } -type bytesFreeList [][]byte - -// peek returns a slice of possibly non-zero'ed bytes, with len=0, -// and with the largest capacity from the list. -func (x *bytesFreeList) peek(length int, pop bool) (out []byte) { - if !useBytesFreeList { - return make([]byte, 0, freelistCapacity(length)) - } - y := *x - if len(y) > 0 { - out = y[len(y)-1] - } - // start buf with a minimum of 64 bytes - const minLenBytes = 64 - if length < minLenBytes { - length = minLenBytes - } - if cap(out) < length { - out = make([]byte, 0, freelistCapacity(length)) - y = append(y, out) - *x = y - } - if pop && len(y) > 0 { - y = y[:len(y)-1] - *x = y - } - return -} - -// get returns a slice of possibly non-zero'ed bytes, with len=0, -// and with cap >= length requested. -func (x *bytesFreeList) get(length int) (out []byte) { - if !useBytesFreeList { - return make([]byte, 0, freelistCapacity(length)) - } - y := *x - for i, v := range y { - if cap(v) >= length { - // *x = append(y[:i], y[i+1:]...) - copy(y[i:], y[i+1:]) - *x = y[:len(y)-1] - return v - } - } - return make([]byte, 0, freelistCapacity(length)) -} - -func (x *bytesFreeList) put(v []byte) { - if !useBytesFreeList || cap(v) == 0 { - return - } - if len(v) != 0 { - v = v[:0] - } - // v = v[:0] - // append the new value, then try to put it in a better position - y := append(*x, v) - *x = y - // MARKER: use simple for loop, so as not to create new slice - // for i, z := range y[:len(y)-1] { - for i := 0; i < len(y)-1; i++ { - if cap(y[i]) > cap(v) { - copy(y[i+1:], y[i:]) - y[i] = v - return - } - } -} - -func (x *bytesFreeList) check(v []byte, length int) (out []byte) { - // ensure inlineable, by moving slow-path out to its own function - if cap(v) >= length { - return v[:0] - } - return x.putGet(v, length) -} - -func (x *bytesFreeList) putGet(v []byte, length int) []byte { - // putGet broken out into its own function, so check is inlineable in general case - - if useBytesFreeListPutGetSeparateCalls { - x.put(v) - return x.get(length) - } - - if !useBytesFreeList { - return make([]byte, 0, freelistCapacity(length)) - } - - // assume cap(v) < length, so put must happen before get - y := *x - var put = cap(v) == 0 // if empty, consider it already put - if !put { - y = append(y, v) - *x = y - } - // for i := 0; i < len(y); i++ { - // z := y[i] - for i, z := range y { - if put { - if cap(z) >= length { - copy(y[i:], y[i+1:]) - y = y[:len(y)-1] - *x = y - return z - } - } else { - if cap(z) > cap(v) { - copy(y[i+1:], y[i:]) - y[i] = v - put = true - } - } - } - return make([]byte, 0, freelistCapacity(length)) -} - -// ------------------------- - -// sfiRvFreeList is used by Encoder for encoding structs, -// where we have to gather the fields first and then -// analyze them for omitEmpty, before knowing the length of the array/map to encode. -// -// Typically, the length here will depend on the number of cycles e.g. -// if type T1 has reference to T1, or T1 has reference to type T2 which has reference to T1. -// -// In the general case, the length of this list at most times is 1, -// so linear search is fine. -type sfiRvFreeList [][]sfiRv - -func (x *sfiRvFreeList) get(length int) (out []sfiRv) { - if !useSfiRvFreeList { - return make([]sfiRv, 0, freelistCapacity(length)) - } - y := *x - - // MARKER: do not use range, as range is not currently inlineable as of go 1.16-beta - // for i, v := range y { - for i := 0; i < len(y); i++ { - v := y[i] - if cap(v) >= length { - // *x = append(y[:i], y[i+1:]...) - copy(y[i:], y[i+1:]) - *x = y[:len(y)-1] - return v - } - } - return make([]sfiRv, 0, freelistCapacity(length)) -} - -func (x *sfiRvFreeList) put(v []sfiRv) { - if !useSfiRvFreeList { - return - } - if len(v) != 0 { - v = v[:0] - } - // append the new value, then try to put it in a better position - y := append(*x, v) - *x = y - // MARKER: do not use range, as range is not currently inlineable as of go 1.16-beta - // for i, z := range y[:len(y)-1] { - for i := 0; i < len(y)-1; i++ { - z := y[i] - if cap(z) > cap(v) { - copy(y[i+1:], y[i:]) - y[i] = v - return - } - } -} - -// ---- multiple interner implementations ---- - -// Hard to tell which is most performant: -// - use a map[string]string - worst perf, no collisions, and unlimited entries -// - use a linear search with move to front heuristics - no collisions, and maxed at 64 entries -// - use a computationally-intensive hash - best performance, some collisions, maxed at 64 entries - -const ( - internMaxStrLen = 16 // if more than 16 bytes, faster to copy than compare bytes - internCap = 64 * 2 // 64 uses 1K bytes RAM, so 128 (anecdotal sweet spot) uses 2K bytes -) - -type internerMap map[string]string - -func (x *internerMap) init() { - *x = make(map[string]string, internCap) -} - -func (x internerMap) string(v []byte) (s string) { - s, ok := x[string(v)] // no allocation here, per go implementation - if !ok { - s = string(v) // new allocation here - x[s] = s - } - return -} - -// ---- - -type bytesEncoder interface { - Encode(dst, src []byte) - Decode(dst, src []byte) (n int, err error) - EncodedLen(n int) int - DecodedLen(n int) int -} - -type hexEncoder struct{} - -func (hexEncoder) Encode(dst, src []byte) { hex.Encode(dst, src) } -func (hexEncoder) Decode(dst, src []byte) (n int, err error) { return hex.Decode(dst, src) } -func (hexEncoder) EncodedLen(n int) int { return hex.EncodedLen(n) } -func (hexEncoder) DecodedLen(n int) int { return hex.DecodedLen(n) } diff --git a/vendor/github.com/ugorji/go/codec/helper.s b/vendor/github.com/ugorji/go/codec/helper.s deleted file mode 100644 index e69de29bb..000000000 diff --git a/vendor/github.com/ugorji/go/codec/helper_not_unsafe.go b/vendor/github.com/ugorji/go/codec/helper_not_unsafe.go deleted file mode 100644 index 413dc39de..000000000 --- a/vendor/github.com/ugorji/go/codec/helper_not_unsafe.go +++ /dev/null @@ -1,706 +0,0 @@ -// Copyright (c) 2012-2020 Ugorji Nwoke. All rights reserved. -// Use of this source code is governed by a MIT license found in the LICENSE file. - -//go:build !go1.9 || safe || codec.safe || appengine - -package codec - -import ( - // "hash/adler32" - "math" - "reflect" - "sync/atomic" - "time" -) - -// This file has safe variants of some helper functions. -// MARKER: See helper_unsafe.go for the usage documentation. - -const safeMode = true - -func isTransientType4Size(size uint32) bool { return true } - -type mapReqParams struct{} - -func getMapReqParams(ti *typeInfo) (r mapReqParams) { return } - -func byteAt(b []byte, index uint) byte { - return b[index] -} - -func setByteAt(b []byte, index uint, val byte) { - b[index] = val -} - -func stringView(v []byte) string { - return string(v) -} - -func bytesView(v string) []byte { - return []byte(v) -} - -func byteSliceSameData(v1 []byte, v2 []byte) bool { - return cap(v1) != 0 && cap(v2) != 0 && &(v1[:1][0]) == &(v2[:1][0]) -} - -func isNil(v interface{}, checkPtr bool) (rv reflect.Value, b bool) { - b = v == nil - if b || !checkPtr { - return - } - rv = reflect.ValueOf(v) - if rv.Kind() == reflect.Ptr { - b = rv.IsNil() - } - return -} - -func ptrToLowLevel(v interface{}) interface{} { - return v -} - -func lowLevelToPtr[T any](v interface{}) *T { - return v.(*T) -} - -func eq4i(i0, i1 interface{}) bool { - return i0 == i1 -} - -func rv4iptr(i interface{}) reflect.Value { return reflect.ValueOf(i) } -func rv4istr(i interface{}) reflect.Value { return reflect.ValueOf(i) } - -func rv2i(rv reflect.Value) interface{} { - if rv.IsValid() { - return rv.Interface() - } - return nil -} - -func rvAddr(rv reflect.Value, ptrType reflect.Type) reflect.Value { - return rv.Addr() -} - -func rvPtrIsNil(rv reflect.Value) bool { - return rv.IsNil() -} - -func rvIsNil(rv reflect.Value) bool { - return rv.IsNil() -} - -func rvSetSliceLen(rv reflect.Value, length int) { - rv.SetLen(length) -} - -func rvZeroAddrK(t reflect.Type, k reflect.Kind) reflect.Value { - return reflect.New(t).Elem() -} - -func rvZeroK(t reflect.Type, k reflect.Kind) reflect.Value { - return reflect.Zero(t) -} - -func rvConvert(v reflect.Value, t reflect.Type) (rv reflect.Value) { - // Note that reflect.Value.Convert(...) will make a copy if it is addressable. - // Since we decode into the passed value, we must try to convert the addressable value.. - if v.CanAddr() { - return v.Addr().Convert(reflect.PtrTo(t)).Elem() - } - return v.Convert(t) -} - -func rt2id(rt reflect.Type) uintptr { - return reflect.ValueOf(rt).Pointer() -} - -func i2rtid(i interface{}) uintptr { - return reflect.ValueOf(reflect.TypeOf(i)).Pointer() -} - -// -------------------------- - -// is this an empty interface/ptr/struct/map/slice/chan/array -func isEmptyContainerValue(v reflect.Value, tinfos *TypeInfos, recursive bool) (empty bool) { - switch v.Kind() { - case reflect.Array: - for i, vlen := 0, v.Len(); i < vlen; i++ { - if !isEmptyValue(v.Index(i), tinfos, false) { - return false - } - } - return true - case reflect.Map, reflect.Slice, reflect.Chan: - return v.IsNil() || v.Len() == 0 - case reflect.Interface, reflect.Ptr: - empty = v.IsNil() - if recursive && !empty { - return isEmptyValue(v.Elem(), tinfos, recursive) - } - return empty - case reflect.Struct: - return isEmptyStruct(v, tinfos, recursive) - } - return false -} - -func isEmptyValue(v reflect.Value, tinfos *TypeInfos, recursive bool) bool { - switch v.Kind() { - case reflect.Invalid: - return true - case reflect.String: - return v.Len() == 0 - case reflect.Array: - // zero := reflect.Zero(v.Type().Elem()) - // can I just check if the whole value is equal to zeros? seems not. - // can I just check if the whole value is equal to its zero value? no. - // Well, then we check if each value is empty without recursive. - for i, vlen := 0, v.Len(); i < vlen; i++ { - if !isEmptyValue(v.Index(i), tinfos, false) { - return false - } - } - return true - case reflect.Map, reflect.Slice, reflect.Chan: - return v.IsNil() || v.Len() == 0 - case reflect.Bool: - return !v.Bool() - case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64: - return v.Int() == 0 - case reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64, reflect.Uintptr: - return v.Uint() == 0 - case reflect.Complex64, reflect.Complex128: - c := v.Complex() - return math.Float64bits(real(c)) == 0 && math.Float64bits(imag(c)) == 0 - case reflect.Float32, reflect.Float64: - return v.Float() == 0 - case reflect.Func, reflect.UnsafePointer: - return v.IsNil() - case reflect.Interface, reflect.Ptr: - isnil := v.IsNil() - if recursive && !isnil { - return isEmptyValue(v.Elem(), tinfos, recursive) - } - return isnil - case reflect.Struct: - return isEmptyStruct(v, tinfos, recursive) - } - return false -} - -// isEmptyStruct is only called from isEmptyValue, and checks if a struct is empty: -// - does it implement IsZero() bool -// - is it comparable, and can i compare directly using == -// - if checkStruct, then walk through the encodable fields -// and check if they are empty or not. -func isEmptyStruct(v reflect.Value, tinfos *TypeInfos, recursive bool) bool { - // v is a struct kind - no need to check again. - // We only check isZero on a struct kind, to reduce the amount of times - // that we lookup the rtid and typeInfo for each type as we walk the tree. - - vt := v.Type() - rtid := rt2id(vt) - if tinfos == nil { - tinfos = defTypeInfos - } - ti := tinfos.get(rtid, vt) - if ti.rtid == timeTypId { - return rv2i(v).(time.Time).IsZero() - } - if ti.flagIsZeroer { - return rv2i(v).(isZeroer).IsZero() - } - if ti.flagIsZeroerPtr && v.CanAddr() { - return rv2i(v.Addr()).(isZeroer).IsZero() - } - if ti.flagIsCodecEmptyer { - return rv2i(v).(isCodecEmptyer).IsCodecEmpty() - } - if ti.flagIsCodecEmptyerPtr && v.CanAddr() { - return rv2i(v.Addr()).(isCodecEmptyer).IsCodecEmpty() - } - if ti.flagComparable { - return rv2i(v) == rv2i(rvZeroK(vt, reflect.Struct)) - } - if !recursive { - return false - } - // We only care about what we can encode/decode, - // so that is what we use to check omitEmpty. - for _, si := range ti.sfi.source() { - sfv := si.fieldNoAlloc(v, true) - if sfv.IsValid() && !isEmptyValue(sfv, tinfos, recursive) { - return false - } - } - return true -} - -func makeMapReflect(t reflect.Type, size int) reflect.Value { - return reflect.MakeMapWithSize(t, size) -} - -// -------------------------- - -type perTypeElem struct { - t reflect.Type - rtid uintptr - zero reflect.Value - addr [2]reflect.Value -} - -func (x *perTypeElem) get(index uint8) (v reflect.Value) { - v = x.addr[index%2] - if v.IsValid() { - v.Set(x.zero) - } else { - v = reflect.New(x.t).Elem() - x.addr[index%2] = v - } - return -} - -type perType struct { - v []perTypeElem -} - -type decPerType = perType - -type encPerType = perType - -func (x *perType) elem(t reflect.Type) *perTypeElem { - rtid := rt2id(t) - var h, i uint - var j = uint(len(x.v)) -LOOP: - if i < j { - h = (i + j) >> 1 // avoid overflow when computing h // h = i + (j-i)/2 - if x.v[h].rtid < rtid { - i = h + 1 - } else { - j = h - } - goto LOOP - } - if i < uint(len(x.v)) { - if x.v[i].rtid != rtid { - x.v = append(x.v, perTypeElem{}) - copy(x.v[i+1:], x.v[i:]) - x.v[i] = perTypeElem{t: t, rtid: rtid, zero: reflect.Zero(t)} - } - } else { - x.v = append(x.v, perTypeElem{t: t, rtid: rtid, zero: reflect.Zero(t)}) - } - return &x.v[i] -} - -func (x *perType) TransientAddrK(t reflect.Type, k reflect.Kind) (rv reflect.Value) { - return x.elem(t).get(0) -} - -func (x *perType) TransientAddr2K(t reflect.Type, k reflect.Kind) (rv reflect.Value) { - return x.elem(t).get(1) -} - -func (x *perType) AddressableRO(v reflect.Value) (rv reflect.Value) { - rv = x.elem(v.Type()).get(0) - rvSetDirect(rv, v) - return -} - -// -------------------------- -type mapIter struct { - t *reflect.MapIter - m reflect.Value - values bool -} - -func (t *mapIter) Next() (r bool) { - return t.t.Next() -} - -func (t *mapIter) Key() reflect.Value { - return t.t.Key() -} - -func (t *mapIter) Value() (r reflect.Value) { - if t.values { - return t.t.Value() - } - return -} - -func (t *mapIter) Done() {} - -func mapRange(t *mapIter, m, k, v reflect.Value, values bool) { - *t = mapIter{ - m: m, - t: m.MapRange(), - values: values, - } -} - -// -------------------------- -type structFieldInfos struct { - c []*structFieldInfo - s []*structFieldInfo - t uint8To32TrieNode - // byName map[string]*structFieldInfo // find sfi given a name -} - -func (x *structFieldInfos) load(source, sorted []*structFieldInfo) { - x.c = source - x.s = sorted -} - -// func (x *structFieldInfos) count() int { return len(x.c) } -func (x *structFieldInfos) source() (v []*structFieldInfo) { return x.c } -func (x *structFieldInfos) sorted() (v []*structFieldInfo) { return x.s } - -// -------------------------- - -type uint8To32TrieNodeNoKids struct { - key uint8 - valid bool // the value marks the end of a full stored string - _ [2]byte // padding - value uint32 -} - -type uint8To32TrieNodeKids = []uint8To32TrieNode - -func (x *uint8To32TrieNode) setKids(kids []uint8To32TrieNode) { x.kids = kids } -func (x *uint8To32TrieNode) getKids() []uint8To32TrieNode { return x.kids } -func (x *uint8To32TrieNode) truncKids() { x.kids = x.kids[:0] } // set len to 0 - -// -------------------------- -func (n *fauxUnion) ru() reflect.Value { - return reflect.ValueOf(&n.u).Elem() -} -func (n *fauxUnion) ri() reflect.Value { - return reflect.ValueOf(&n.i).Elem() -} -func (n *fauxUnion) rf() reflect.Value { - return reflect.ValueOf(&n.f).Elem() -} -func (n *fauxUnion) rl() reflect.Value { - return reflect.ValueOf(&n.l).Elem() -} -func (n *fauxUnion) rs() reflect.Value { - return reflect.ValueOf(&n.s).Elem() -} -func (n *fauxUnion) rt() reflect.Value { - return reflect.ValueOf(&n.t).Elem() -} -func (n *fauxUnion) rb() reflect.Value { - return reflect.ValueOf(&n.b).Elem() -} - -// -------------------------- -func rvSetBytes(rv reflect.Value, v []byte) { - rv.SetBytes(v) -} - -func rvSetString(rv reflect.Value, v string) { - rv.SetString(v) -} - -func rvSetBool(rv reflect.Value, v bool) { - rv.SetBool(v) -} - -func rvSetTime(rv reflect.Value, v time.Time) { - rv.Set(reflect.ValueOf(v)) -} - -func rvSetFloat32(rv reflect.Value, v float32) { - rv.SetFloat(float64(v)) -} - -func rvSetFloat64(rv reflect.Value, v float64) { - rv.SetFloat(v) -} - -func rvSetComplex64(rv reflect.Value, v complex64) { - rv.SetComplex(complex128(v)) -} - -func rvSetComplex128(rv reflect.Value, v complex128) { - rv.SetComplex(v) -} - -func rvSetInt(rv reflect.Value, v int) { - rv.SetInt(int64(v)) -} - -func rvSetInt8(rv reflect.Value, v int8) { - rv.SetInt(int64(v)) -} - -func rvSetInt16(rv reflect.Value, v int16) { - rv.SetInt(int64(v)) -} - -func rvSetInt32(rv reflect.Value, v int32) { - rv.SetInt(int64(v)) -} - -func rvSetInt64(rv reflect.Value, v int64) { - rv.SetInt(v) -} - -func rvSetUint(rv reflect.Value, v uint) { - rv.SetUint(uint64(v)) -} - -func rvSetUintptr(rv reflect.Value, v uintptr) { - rv.SetUint(uint64(v)) -} - -func rvSetUint8(rv reflect.Value, v uint8) { - rv.SetUint(uint64(v)) -} - -func rvSetUint16(rv reflect.Value, v uint16) { - rv.SetUint(uint64(v)) -} - -func rvSetUint32(rv reflect.Value, v uint32) { - rv.SetUint(uint64(v)) -} - -func rvSetUint64(rv reflect.Value, v uint64) { - rv.SetUint(v) -} - -// ---------------- - -func rvSetDirect(rv reflect.Value, v reflect.Value) { - rv.Set(v) -} - -func rvSetDirectZero(rv reflect.Value) { - rv.Set(reflect.Zero(rv.Type())) -} - -// func rvSet(rv reflect.Value, v reflect.Value) { -// rv.Set(v) -// } - -func rvSetIntf(rv reflect.Value, v reflect.Value) { - rv.Set(v) -} - -func rvSetZero(rv reflect.Value) { - rv.Set(reflect.Zero(rv.Type())) -} - -func rvSlice(rv reflect.Value, length int) reflect.Value { - return rv.Slice(0, length) -} - -func rvMakeSlice(rv reflect.Value, ti *typeInfo, xlen, xcap int) (v reflect.Value, set bool) { - v = reflect.MakeSlice(ti.rt, xlen, xcap) - if rv.Len() > 0 { - reflect.Copy(v, rv) - } - return -} - -func rvGrowSlice(rv reflect.Value, ti *typeInfo, cap, incr int) (v reflect.Value, newcap int, set bool) { - newcap = int(growCap(uint(cap), uint(ti.elemsize), uint(incr))) - v = reflect.MakeSlice(ti.rt, newcap, newcap) - if rv.Len() > 0 { - reflect.Copy(v, rv) - } - return -} - -// ---------------- - -func rvArrayIndex(rv reflect.Value, i int, _ *typeInfo, _ bool) reflect.Value { - return rv.Index(i) -} - -// func rvArrayIndex(rv reflect.Value, i int, ti *typeInfo) reflect.Value { -// return rv.Index(i) -// } - -func rvSliceZeroCap(t reflect.Type) (v reflect.Value) { - return reflect.MakeSlice(t, 0, 0) -} - -func rvLenSlice(rv reflect.Value) int { - return rv.Len() -} - -func rvCapSlice(rv reflect.Value) int { - return rv.Cap() -} - -func rvGetArrayBytes(rv reflect.Value, scratch []byte) (bs []byte) { - l := rv.Len() - if scratch == nil && rv.CanAddr() { - return rv.Slice(0, l).Bytes() - } - - if l <= cap(scratch) { - bs = scratch[:l] - } else { - bs = make([]byte, l) - } - reflect.Copy(reflect.ValueOf(bs), rv) - return -} - -func rvGetArray4Slice(rv reflect.Value) (v reflect.Value) { - v = rvZeroAddrK(reflect.ArrayOf(rvLenSlice(rv), rv.Type().Elem()), reflect.Array) - reflect.Copy(v, rv) - return -} - -func rvGetSlice4Array(rv reflect.Value, v interface{}) { - // v is a pointer to a slice to be populated - - // rv.Slice fails if address is not addressable, which can occur during encoding. - // Consequently, check if non-addressable, and if so, make new slice and copy into it first. - // MARKER: this *may* cause allocation if non-addressable, unfortunately. - - rve := reflect.ValueOf(v).Elem() - l := rv.Len() - if rv.CanAddr() { - rve.Set(rv.Slice(0, l)) - } else { - rvs := reflect.MakeSlice(rve.Type(), l, l) - reflect.Copy(rvs, rv) - rve.Set(rvs) - } - // reflect.ValueOf(v).Elem().Set(rv.Slice(0, rv.Len())) -} - -func rvCopySlice(dest, src reflect.Value, _ reflect.Type) { - reflect.Copy(dest, src) -} - -// ------------ - -func rvGetBool(rv reflect.Value) bool { - return rv.Bool() -} - -func rvGetBytes(rv reflect.Value) []byte { - return rv.Bytes() -} - -func rvGetTime(rv reflect.Value) time.Time { - return rv2i(rv).(time.Time) -} - -func rvGetString(rv reflect.Value) string { - return rv.String() -} - -func rvGetFloat64(rv reflect.Value) float64 { - return rv.Float() -} - -func rvGetFloat32(rv reflect.Value) float32 { - return float32(rv.Float()) -} - -func rvGetComplex64(rv reflect.Value) complex64 { - return complex64(rv.Complex()) -} - -func rvGetComplex128(rv reflect.Value) complex128 { - return rv.Complex() -} - -func rvGetInt(rv reflect.Value) int { - return int(rv.Int()) -} - -func rvGetInt8(rv reflect.Value) int8 { - return int8(rv.Int()) -} - -func rvGetInt16(rv reflect.Value) int16 { - return int16(rv.Int()) -} - -func rvGetInt32(rv reflect.Value) int32 { - return int32(rv.Int()) -} - -func rvGetInt64(rv reflect.Value) int64 { - return rv.Int() -} - -func rvGetUint(rv reflect.Value) uint { - return uint(rv.Uint()) -} - -func rvGetUint8(rv reflect.Value) uint8 { - return uint8(rv.Uint()) -} - -func rvGetUint16(rv reflect.Value) uint16 { - return uint16(rv.Uint()) -} - -func rvGetUint32(rv reflect.Value) uint32 { - return uint32(rv.Uint()) -} - -func rvGetUint64(rv reflect.Value) uint64 { - return rv.Uint() -} - -func rvGetUintptr(rv reflect.Value) uintptr { - return uintptr(rv.Uint()) -} - -func rvLenMap(rv reflect.Value) int { - return rv.Len() -} - -// ------------ map range and map indexing ---------- - -func mapSet(m, k, v reflect.Value, _ mapReqParams) { - m.SetMapIndex(k, v) -} - -func mapGet(m, k, v reflect.Value, _ mapReqParams) (vv reflect.Value) { - return m.MapIndex(k) -} - -func mapAddrLoopvarRV(t reflect.Type, k reflect.Kind) (r reflect.Value) { - return // reflect.New(t).Elem() -} - -// ---------- ENCODER optimized --------------- - -func (d *decoderBase) bytes2Str(in []byte, att dBytesAttachState) (s string, mutable bool) { - return d.detach2Str(in, att), false -} - -// ---------- structFieldInfo optimized --------------- - -func (n *structFieldInfoNode) rvField(v reflect.Value) reflect.Value { - return v.Field(int(n.index)) -} - -// ---------- others --------------- - -// -------------------------- -type atomicRtidFnSlice struct { - v atomic.Value -} - -func (x *atomicRtidFnSlice) load() interface{} { - return x.v.Load() -} - -func (x *atomicRtidFnSlice) store(p interface{}) { - x.v.Store(p) -} diff --git a/vendor/github.com/ugorji/go/codec/helper_notunsafe_or_notgc.go b/vendor/github.com/ugorji/go/codec/helper_notunsafe_or_notgc.go deleted file mode 100644 index 420d717e7..000000000 --- a/vendor/github.com/ugorji/go/codec/helper_notunsafe_or_notgc.go +++ /dev/null @@ -1,59 +0,0 @@ -// Copyright (c) 2012-2020 Ugorji Nwoke. All rights reserved. -// Use of this source code is governed by a MIT license found in the LICENSE file. - -//go:build safe || codec.safe || !gc - -package codec - -// growCap will return a new capacity for a slice, given the following: -// - oldCap: current capacity -// - unit: in-memory size of an element -// - num: number of elements to add -func growCap(oldCap, unit, num uint) (newCap uint) { - // appendslice logic (if cap < 1024, *2, else *1.25): - // leads to many copy calls, especially when copying bytes. - // bytes.Buffer model (2*cap + n): much better for bytes. - // smarter way is to take the byte-size of the appended element(type) into account - - // maintain 1 thresholds: - // t1: if cap <= t1, newcap = 2x - // else newcap = 1.5x - // - // t1 is always >= 1024. - // This means that, if unit size >= 16, then always do 2x or 1.5x (ie t1, t2, t3 are all same) - // - // With this, appending for bytes increase by: - // 100% up to 4K - // 50% beyond that - - // unit can be 0 e.g. for struct{}{}; handle that appropriately - maxCap := num + (oldCap * 3 / 2) - if unit == 0 || maxCap > maxArrayLen || maxCap < oldCap { // handle wraparound, etc - return maxArrayLen - } - - var t1 uint = 1024 // default thresholds for large values - if unit <= 4 { - t1 = 8 * 1024 - } else if unit <= 16 { - t1 = 2 * 1024 - } - - newCap = 2 + num - if oldCap > 0 { - if oldCap <= t1 { // [0,t1] - newCap = num + (oldCap * 2) - } else { // (t1,infinity] - newCap = maxCap - } - } - - // ensure newCap takes multiples of a cache line (size is a multiple of 64) - t1 = newCap * unit - if t2 := t1 % 64; t2 != 0 { - t1 += 64 - t2 - newCap = t1 / unit - } - - return -} diff --git a/vendor/github.com/ugorji/go/codec/helper_unsafe.go b/vendor/github.com/ugorji/go/codec/helper_unsafe.go deleted file mode 100644 index 31f3266a4..000000000 --- a/vendor/github.com/ugorji/go/codec/helper_unsafe.go +++ /dev/null @@ -1,1258 +0,0 @@ -// Copyright (c) 2012-2020 Ugorji Nwoke. All rights reserved. -// Use of this source code is governed by a MIT license found in the LICENSE file. - -//go:build !safe && !codec.safe && !appengine && go1.21 - -// minimum of go 1.21 is needed, as that is the minimum for all features and linked functions we need -// - typedmemclr : go1.8 -// - mapassign_fastXXX: go1.9 -// - clear was added in go1.21 -// - unsafe.String(Data): go1.20 -// - unsafe.Add: go1.17 -// - generics/any: go1.18 -// etc - -package codec - -import ( - "reflect" - _ "runtime" // needed for go linkname(s) - "sync/atomic" - "time" - "unsafe" -) - -// This file has unsafe variants of some helper functions. -// MARKER: See helper_unsafe.go for the usage documentation. -// -// There are a number of helper_*unsafe*.go files. -// -// - helper_unsafe -// unsafe variants of dependent functions -// - helper_unsafe_compiler_gc (gc) -// unsafe variants of dependent functions which cannot be shared with gollvm or gccgo -// - helper_not_unsafe_not_gc (gccgo/gollvm or safe) -// safe variants of functions in helper_unsafe_compiler_gc -// - helper_not_unsafe (safe) -// safe variants of functions in helper_unsafe -// - helper_unsafe_compiler_not_gc (gccgo, gollvm) -// unsafe variants of functions/variables which non-standard compilers need -// -// This way, we can judiciously use build tags to include the right set of files -// for any compiler, and make it run optimally in unsafe mode. -// -// As of March 2021, we cannot differentiate whether running with gccgo or gollvm -// using a build constraint, as both satisfy 'gccgo' build tag. -// Consequently, we must use the lowest common denominator to support both. -// -// For reflect.Value code, we decided to do the following: -// - if we know the kind, we can elide conditional checks for -// - SetXXX (Int, Uint, String, Bool, etc) -// - SetLen -// -// We can also optimize many others, incl IsNil, etc -// -// MARKER: Some functions here will not be hit during code coverage runs due to optimizations, e.g. -// - rvCopySlice: called by decode if rvGrowSlice did not set new slice into pointer to orig slice. -// however, helper_unsafe sets it, so no need to call rvCopySlice later -// - rvSlice: same as above -// -// MARKER: Handling flagIndir ---- -// -// flagIndir means that the reflect.Value holds a pointer to the data itself. -// -// flagIndir can be set for: -// - references -// Here, type.IfaceIndir() --> false -// flagIndir is usually false (except when the value is addressable, where in flagIndir may be true) -// - everything else (numbers, bools, string, slice, struct, etc). -// Here, type.IfaceIndir() --> true -// flagIndir is always true -// -// This knowlege is used across this file, e.g. in rv2i and rvRefPtr - -const safeMode = false - -// helperUnsafeDirectAssignMapEntry says that we should not copy the pointer in the map -// to another value during mapRange/iteration and mapGet calls, but directly assign it. -// -// The only callers of mapRange/iteration is encode. -// Here, we just walk through the values and encode them -// -// The only caller of mapGet is decode. -// Here, it does a Get if the underlying value is a pointer, and decodes into that. -// -// For both users, we are very careful NOT to modify or keep the pointers around. -// Consequently, it is ok for take advantage of the performance that the map is not modified -// during an iteration and we can just "peek" at the internal value" in the map and use it. -const helperUnsafeDirectAssignMapEntry = true - -// MARKER: keep in sync with GO_ROOT/src/reflect/value.go -const ( - unsafeFlagStickyRO = 1 << 5 - unsafeFlagEmbedRO = 1 << 6 - unsafeFlagIndir = 1 << 7 - unsafeFlagAddr = 1 << 8 - unsafeFlagRO = unsafeFlagStickyRO | unsafeFlagEmbedRO - // unsafeFlagKindMask = (1 << 5) - 1 // 5 bits for 27 kinds (up to 31) - // unsafeTypeKindDirectIface = 1 << 5 -) - -// transientSizeMax below is used in TransientAddr as the backing storage. -// -// Must be >= 16 as the maximum size is a complex128 (or string on 64-bit machines). -const transientSizeMax = 64 - -// should struct/array support internal strings and slices? -// const transientValueHasStringSlice = false - -func isTransientType4Size(size uint32) bool { return size <= transientSizeMax } - -type unsafeString struct { - Data unsafe.Pointer - Len int -} - -type unsafeSlice struct { - Data unsafe.Pointer - Len int - Cap int -} - -type unsafeIntf struct { - typ unsafe.Pointer - ptr unsafe.Pointer -} - -type unsafeReflectValue struct { - unsafeIntf - flag uintptr -} - -// keep in sync with stdlib runtime/type.go -type unsafeRuntimeType struct { - size uintptr - // ... many other fields here -} - -// unsafeZeroAddr and unsafeZeroSlice points to a read-only block of memory -// used for setting a zero value for most types or creating a read-only -// zero value for a given type. -var ( - unsafeZeroAddr = unsafe.Pointer(&unsafeZeroArr[0]) - unsafeZeroSlice = unsafeSlice{unsafeZeroAddr, 0, 0} -) - -// We use a scratch memory and an unsafeSlice for transient values: -// -// unsafeSlice is used for standalone strings and slices (outside an array or struct). -// scratch memory is used for other kinds, based on contract below: -// - numbers, bool are always transient -// - structs and arrays are transient iff they have no pointers i.e. -// no string, slice, chan, func, interface, map, etc only numbers and bools. -// - slices and strings are transient (using the unsafeSlice) - -type unsafePerTypeElem struct { - arr [transientSizeMax]byte // for bool, number, struct, array kinds - slice unsafeSlice // for string and slice kinds -} - -func (x *unsafePerTypeElem) addrFor(k reflect.Kind) unsafe.Pointer { - if k == reflect.String || k == reflect.Slice { - x.slice = unsafeSlice{} // memclr - return unsafe.Pointer(&x.slice) - } - clear(x.arr[:]) - // x.arr = [transientSizeMax]byte{} // memclr - return unsafe.Pointer(&x.arr) -} - -type perType struct { - elems [2]unsafePerTypeElem -} - -type decPerType = perType - -type encPerType struct{} - -// TransientAddrK is used for getting a *transient* value to be decoded into, -// which will right away be used for something else. -// -// See notes in helper.go about "Transient values during decoding" - -func (x *perType) TransientAddrK(t reflect.Type, k reflect.Kind) reflect.Value { - return rvZeroAddrTransientAnyK(t, k, x.elems[0].addrFor(k)) -} - -func (x *perType) TransientAddr2K(t reflect.Type, k reflect.Kind) reflect.Value { - return rvZeroAddrTransientAnyK(t, k, x.elems[1].addrFor(k)) -} - -func (encPerType) AddressableRO(v reflect.Value) reflect.Value { - return rvAddressableReadonly(v) -} - -// byteAt returns the byte given an index which is guaranteed -// to be within the bounds of the slice i.e. we defensively -// already verified that the index is less than the length of the slice. -func byteAt(b []byte, index uint) byte { - // return b[index] - return *(*byte)(unsafe.Pointer(uintptr((*unsafeSlice)(unsafe.Pointer(&b)).Data) + uintptr(index))) -} - -func setByteAt(b []byte, index uint, val byte) { - // b[index] = val - *(*byte)(unsafe.Pointer(uintptr((*unsafeSlice)(unsafe.Pointer(&b)).Data) + uintptr(index))) = val -} - -// stringView returns a view of the []byte as a string. -// In unsafe mode, it doesn't incur allocation and copying caused by conversion. -// In regular safe mode, it is an allocation and copy. -func stringView(v []byte) string { - return *(*string)(unsafe.Pointer(&v)) -} - -// bytesView returns a view of the string as a []byte. -// In unsafe mode, it doesn't incur allocation and copying caused by conversion. -// In regular safe mode, it is an allocation and copy. -func bytesView(v string) (b []byte) { - sx := (*unsafeString)(unsafe.Pointer(&v)) - bx := (*unsafeSlice)(unsafe.Pointer(&b)) - bx.Data, bx.Len, bx.Cap = sx.Data, sx.Len, sx.Len - return -} - -func byteSliceSameData(v1 []byte, v2 []byte) bool { - return (*unsafeSlice)(unsafe.Pointer(&v1)).Data == (*unsafeSlice)(unsafe.Pointer(&v2)).Data -} - -// isNil checks - without much effort - if an interface is nil. -// -// returned rv is not guaranteed to be valid (e.g. if v == nil). -// -// Note that this will handle all pointer-sized types e.g. -// pointer, map, chan, func, etc. -func isNil(v interface{}, checkPtr bool) (rv reflect.Value, b bool) { - b = ((*unsafeIntf)(unsafe.Pointer(&v))).ptr == nil - return -} - -func ptrToLowLevel[T any](ptr *T) unsafe.Pointer { - return unsafe.Pointer(ptr) -} - -func lowLevelToPtr[T any](v unsafe.Pointer) *T { - return (*T)(v) -} - -// Given that v is a reference (map/func/chan/ptr/unsafepointer) kind, return the pointer -func rvRefPtr(v *unsafeReflectValue) unsafe.Pointer { - if v.flag&unsafeFlagIndir != 0 { - return *(*unsafe.Pointer)(v.ptr) - } - return v.ptr -} - -func eq4i(i0, i1 interface{}) bool { - v0 := (*unsafeIntf)(unsafe.Pointer(&i0)) - v1 := (*unsafeIntf)(unsafe.Pointer(&i1)) - return v0.typ == v1.typ && v0.ptr == v1.ptr -} - -func rv4iptr(i interface{}) (v reflect.Value) { - // Main advantage here is that it is inlined, nothing escapes to heap, i is never nil - uv := (*unsafeReflectValue)(unsafe.Pointer(&v)) - uv.unsafeIntf = *(*unsafeIntf)(unsafe.Pointer(&i)) - uv.flag = uintptr(rkindPtr) - return -} - -func rv4istr(i interface{}) (v reflect.Value) { - // Main advantage here is that it is inlined, nothing escapes to heap, i is never nil - uv := (*unsafeReflectValue)(unsafe.Pointer(&v)) - uv.unsafeIntf = *(*unsafeIntf)(unsafe.Pointer(&i)) - uv.flag = uintptr(rkindString) | unsafeFlagIndir - return -} - -func rv2i(rv reflect.Value) (i interface{}) { - urv := (*unsafeReflectValue)(unsafe.Pointer(&rv)) - if refBitset.isset(byte(rv.Kind())) && urv.flag&unsafeFlagIndir != 0 { - urv.ptr = *(*unsafe.Pointer)(urv.ptr) - } - return *(*interface{})(unsafe.Pointer(&urv.unsafeIntf)) -} - -func rvAddr(rv reflect.Value, ptrType reflect.Type) reflect.Value { - urv := (*unsafeReflectValue)(unsafe.Pointer(&rv)) - urv.flag = (urv.flag & unsafeFlagRO) | uintptr(reflect.Ptr) - urv.typ = ((*unsafeIntf)(unsafe.Pointer(&ptrType))).ptr - return rv -} - -// return true if this rv - got from a pointer kind - is nil. -// For now, only use for struct fields of pointer types, as we're guaranteed -// that flagIndir will never be set. -func rvPtrIsNil(rv reflect.Value) bool { - return rvIsNil(rv) -} - -// checks if a nil'able value is nil -func rvIsNil(rv reflect.Value) bool { - urv := (*unsafeReflectValue)(unsafe.Pointer(&rv)) - if urv.flag&unsafeFlagIndir == 0 { - return urv.ptr == nil - } - // flagIndir is set for a reference (ptr/map/func/unsafepointer/chan) - // OR kind is slice/interface - return *(*unsafe.Pointer)(urv.ptr) == nil -} - -func rvSetSliceLen(rv reflect.Value, length int) { - urv := (*unsafeReflectValue)(unsafe.Pointer(&rv)) - (*unsafeString)(urv.ptr).Len = length -} - -func rvZeroAddrK(t reflect.Type, k reflect.Kind) (rv reflect.Value) { - urv := (*unsafeReflectValue)(unsafe.Pointer(&rv)) - urv.typ = ((*unsafeIntf)(unsafe.Pointer(&t))).ptr - urv.flag = uintptr(k) | unsafeFlagIndir | unsafeFlagAddr - urv.ptr = unsafeNew(urv.typ) - return -} - -func rvZeroAddrTransientAnyK(t reflect.Type, k reflect.Kind, addr unsafe.Pointer) (rv reflect.Value) { - urv := (*unsafeReflectValue)(unsafe.Pointer(&rv)) - urv.typ = ((*unsafeIntf)(unsafe.Pointer(&t))).ptr - urv.flag = uintptr(k) | unsafeFlagIndir | unsafeFlagAddr - urv.ptr = addr - return -} - -func rvZeroK(t reflect.Type, k reflect.Kind) (rv reflect.Value) { - urv := (*unsafeReflectValue)(unsafe.Pointer(&rv)) - urv.typ = ((*unsafeIntf)(unsafe.Pointer(&t))).ptr - if refBitset.isset(byte(k)) { - urv.flag = uintptr(k) - } else if rtsize2(urv.typ) <= uintptr(len(unsafeZeroArr)) { - urv.flag = uintptr(k) | unsafeFlagIndir - urv.ptr = unsafeZeroAddr - } else { // meaning struct or array - urv.flag = uintptr(k) | unsafeFlagIndir | unsafeFlagAddr - urv.ptr = unsafeNew(urv.typ) - } - return -} - -// rvConvert will convert a value to a different type directly, -// ensuring that they still point to the same underlying value. -func rvConvert(v reflect.Value, t reflect.Type) reflect.Value { - uv := (*unsafeReflectValue)(unsafe.Pointer(&v)) - uv.typ = ((*unsafeIntf)(unsafe.Pointer(&t))).ptr - return v -} - -// rvAddressableReadonly returns an addressable reflect.Value. -// -// Use it within encode calls, when you just want to "read" the underlying ptr -// without modifying the value. -// -// Note that it cannot be used for r/w use, as those non-addressable values -// may have been stored in read-only memory, and trying to write the pointer -// may cause a segfault. -func rvAddressableReadonly(v reflect.Value) reflect.Value { - // hack to make an addressable value out of a non-addressable one. - // Assume folks calling it are passing a value that can be addressable, but isn't. - // This assumes that the flagIndir is already set on it. - // so we just set the flagAddr bit on the flag (and do not set the flagIndir). - - uv := (*unsafeReflectValue)(unsafe.Pointer(&v)) - uv.flag = uv.flag | unsafeFlagAddr // | unsafeFlagIndir - - return v -} - -func rtsize2(rt unsafe.Pointer) uintptr { - return ((*unsafeRuntimeType)(rt)).size -} - -func rt2id(rt reflect.Type) uintptr { - return uintptr(((*unsafeIntf)(unsafe.Pointer(&rt))).ptr) -} - -func i2rtid(i interface{}) uintptr { - return uintptr(((*unsafeIntf)(unsafe.Pointer(&i))).typ) -} - -// -------------------------- - -func unsafeCmpZero(ptr unsafe.Pointer, size int) bool { - // verified that size is always within right range, so no chance of OOM - var s1 = unsafeString{ptr, size} - var s2 = unsafeString{unsafeZeroAddr, size} - if size > len(unsafeZeroArr) { - arr := make([]byte, size) - s2.Data = unsafe.Pointer(&arr[0]) - } - return *(*string)(unsafe.Pointer(&s1)) == *(*string)(unsafe.Pointer(&s2)) // memcmp -} - -func isEmptyValue(v reflect.Value, tinfos *TypeInfos, recursive bool) bool { - urv := (*unsafeReflectValue)(unsafe.Pointer(&v)) - if urv.flag == 0 { - return true - } - if recursive { - return isEmptyValueFallbackRecur(urv, v, tinfos) - } - return unsafeCmpZero(urv.ptr, int(rtsize2(urv.typ))) -} - -func isEmptyValueFallbackRecur(urv *unsafeReflectValue, v reflect.Value, tinfos *TypeInfos) bool { - const recursive = true - - switch v.Kind() { - case reflect.Invalid: - return true - case reflect.String: - return (*unsafeString)(urv.ptr).Len == 0 - case reflect.Slice: - return (*unsafeSlice)(urv.ptr).Len == 0 - case reflect.Bool: - return !*(*bool)(urv.ptr) - case reflect.Int: - return *(*int)(urv.ptr) == 0 - case reflect.Int8: - return *(*int8)(urv.ptr) == 0 - case reflect.Int16: - return *(*int16)(urv.ptr) == 0 - case reflect.Int32: - return *(*int32)(urv.ptr) == 0 - case reflect.Int64: - return *(*int64)(urv.ptr) == 0 - case reflect.Uint: - return *(*uint)(urv.ptr) == 0 - case reflect.Uint8: - return *(*uint8)(urv.ptr) == 0 - case reflect.Uint16: - return *(*uint16)(urv.ptr) == 0 - case reflect.Uint32: - return *(*uint32)(urv.ptr) == 0 - case reflect.Uint64: - return *(*uint64)(urv.ptr) == 0 - case reflect.Uintptr: - return *(*uintptr)(urv.ptr) == 0 - case reflect.Float32: - return *(*float32)(urv.ptr) == 0 - case reflect.Float64: - return *(*float64)(urv.ptr) == 0 - case reflect.Complex64: - return unsafeCmpZero(urv.ptr, 8) - case reflect.Complex128: - return unsafeCmpZero(urv.ptr, 16) - case reflect.Struct: - // return isEmptyStruct(v, tinfos, recursive) - if tinfos == nil { - tinfos = defTypeInfos - } - ti := tinfos.find(uintptr(urv.typ)) - if ti == nil { - ti = tinfos.load(v.Type()) - } - return unsafeCmpZero(urv.ptr, int(ti.size)) - case reflect.Interface, reflect.Ptr: - // isnil := urv.ptr == nil // (not sufficient, as a pointer value encodes the type) - isnil := urv.ptr == nil || *(*unsafe.Pointer)(urv.ptr) == nil - if recursive && !isnil { - return isEmptyValue(v.Elem(), tinfos, recursive) - } - return isnil - case reflect.UnsafePointer: - return urv.ptr == nil || *(*unsafe.Pointer)(urv.ptr) == nil - case reflect.Chan: - return urv.ptr == nil || len_chan(rvRefPtr(urv)) == 0 - case reflect.Map: - return urv.ptr == nil || len_map(rvRefPtr(urv)) == 0 - case reflect.Array: - return v.Len() == 0 || - urv.ptr == nil || - urv.typ == nil || - rtsize2(urv.typ) == 0 || - unsafeCmpZero(urv.ptr, int(rtsize2(urv.typ))) - } - return false -} - -// is this an empty interface/ptr/struct/map/slice/chan/array -func isEmptyContainerValue(v reflect.Value, tinfos *TypeInfos, recursive bool) bool { - urv := (*unsafeReflectValue)(unsafe.Pointer(&v)) - switch v.Kind() { - case reflect.Slice: - return (*unsafeSlice)(urv.ptr).Len == 0 - case reflect.Struct: - if tinfos == nil { - tinfos = defTypeInfos - } - ti := tinfos.find(uintptr(urv.typ)) - if ti == nil { - ti = tinfos.load(v.Type()) - } - return unsafeCmpZero(urv.ptr, int(ti.size)) - case reflect.Interface, reflect.Ptr: - // isnil := urv.ptr == nil // (not sufficient, as a pointer value encodes the type) - isnil := urv.ptr == nil || *(*unsafe.Pointer)(urv.ptr) == nil - if recursive && !isnil { - return isEmptyValue(v.Elem(), tinfos, recursive) - } - return isnil - case reflect.Chan: - return urv.ptr == nil || len_chan(rvRefPtr(urv)) == 0 - case reflect.Map: - return urv.ptr == nil || len_map(rvRefPtr(urv)) == 0 - case reflect.Array: - return v.Len() == 0 || - urv.ptr == nil || - urv.typ == nil || - rtsize2(urv.typ) == 0 || - unsafeCmpZero(urv.ptr, int(rtsize2(urv.typ))) - } - return false -} - -// -------------------------- - -type structFieldInfos struct { - c unsafe.Pointer // source - s unsafe.Pointer // sorted - t uint8To32TrieNode - - length int - - // byName map[string]*structFieldInfo // find sfi given a name -} - -// func (x *structFieldInfos) load(source, sorted []*structFieldInfo, sourceNames, sortedNames []string) { -func (x *structFieldInfos) load(source, sorted []*structFieldInfo) { - var s *unsafeSlice - s = (*unsafeSlice)(unsafe.Pointer(&source)) - x.c = s.Data - x.length = s.Len - s = (*unsafeSlice)(unsafe.Pointer(&sorted)) - x.s = s.Data -} - -func (x *structFieldInfos) source() (v []*structFieldInfo) { - *(*unsafeSlice)(unsafe.Pointer(&v)) = unsafeSlice{x.c, x.length, x.length} - return -} - -func (x *structFieldInfos) sorted() (v []*structFieldInfo) { - *(*unsafeSlice)(unsafe.Pointer(&v)) = unsafeSlice{x.s, x.length, x.length} - return -} - -// -------------------------- - -type uint8To32TrieNodeNoKids struct { - key uint8 - valid bool // the value marks the end of a full stored string - numkids uint8 - _ byte // padding - value uint32 -} - -type uint8To32TrieNodeKids = *uint8To32TrieNode - -func (x *uint8To32TrieNode) setKids(kids []uint8To32TrieNode) { - x.numkids = uint8(len(kids)) - x.kids = &kids[0] -} -func (x *uint8To32TrieNode) getKids() (v []uint8To32TrieNode) { - *(*unsafeSlice)(unsafe.Pointer(&v)) = unsafeSlice{unsafe.Pointer(x.kids), int(x.numkids), int(x.numkids)} - return -} -func (x *uint8To32TrieNode) truncKids() { x.numkids = 0 } - -// -------------------------- - -// Note that we do not atomically load/store length and data pointer separately, -// as this could lead to some races. Instead, we atomically load/store cappedSlice. - -type atomicRtidFnSlice struct { - v unsafe.Pointer // *[]codecRtidFn -} - -func (x *atomicRtidFnSlice) load() (s unsafe.Pointer) { - return atomic.LoadPointer(&x.v) -} - -func (x *atomicRtidFnSlice) store(p unsafe.Pointer) { - atomic.StorePointer(&x.v, p) -} - -// -------------------------- - -// to create a reflect.Value for each member field of fauxUnion, -// we first create a global fauxUnion, and create reflect.Value -// for them all. -// This way, we have the flags and type in the reflect.Value. -// Then, when a reflect.Value is called, we just copy it, -// update the ptr to the fauxUnion's, and return it. - -type unsafeDecNakedWrapper struct { - fauxUnion - ru, ri, rf, rl, rs, rb, rt reflect.Value // mapping to the primitives above -} - -func (n *unsafeDecNakedWrapper) init() { - n.ru = rv4iptr(&n.u).Elem() - n.ri = rv4iptr(&n.i).Elem() - n.rf = rv4iptr(&n.f).Elem() - n.rl = rv4iptr(&n.l).Elem() - n.rs = rv4iptr(&n.s).Elem() - n.rt = rv4iptr(&n.t).Elem() - n.rb = rv4iptr(&n.b).Elem() - // n.rr[] = reflect.ValueOf(&n.) -} - -var defUnsafeDecNakedWrapper unsafeDecNakedWrapper - -func init() { - defUnsafeDecNakedWrapper.init() -} - -func (n *fauxUnion) ru() (v reflect.Value) { - v = defUnsafeDecNakedWrapper.ru - ((*unsafeReflectValue)(unsafe.Pointer(&v))).ptr = unsafe.Pointer(&n.u) - return -} -func (n *fauxUnion) ri() (v reflect.Value) { - v = defUnsafeDecNakedWrapper.ri - ((*unsafeReflectValue)(unsafe.Pointer(&v))).ptr = unsafe.Pointer(&n.i) - return -} -func (n *fauxUnion) rf() (v reflect.Value) { - v = defUnsafeDecNakedWrapper.rf - ((*unsafeReflectValue)(unsafe.Pointer(&v))).ptr = unsafe.Pointer(&n.f) - return -} -func (n *fauxUnion) rl() (v reflect.Value) { - v = defUnsafeDecNakedWrapper.rl - ((*unsafeReflectValue)(unsafe.Pointer(&v))).ptr = unsafe.Pointer(&n.l) - return -} -func (n *fauxUnion) rs() (v reflect.Value) { - v = defUnsafeDecNakedWrapper.rs - ((*unsafeReflectValue)(unsafe.Pointer(&v))).ptr = unsafe.Pointer(&n.s) - return -} -func (n *fauxUnion) rt() (v reflect.Value) { - v = defUnsafeDecNakedWrapper.rt - ((*unsafeReflectValue)(unsafe.Pointer(&v))).ptr = unsafe.Pointer(&n.t) - return -} -func (n *fauxUnion) rb() (v reflect.Value) { - v = defUnsafeDecNakedWrapper.rb - ((*unsafeReflectValue)(unsafe.Pointer(&v))).ptr = unsafe.Pointer(&n.b) - return -} - -// -------------------------- -func rvSetBytes(rv reflect.Value, v []byte) { - *(*[]byte)(rvPtr(rv)) = v -} - -func rvSetString(rv reflect.Value, v string) { - *(*string)(rvPtr(rv)) = v -} - -func rvSetBool(rv reflect.Value, v bool) { - *(*bool)(rvPtr(rv)) = v -} - -func rvSetTime(rv reflect.Value, v time.Time) { - *(*time.Time)(rvPtr(rv)) = v -} - -func rvSetFloat32(rv reflect.Value, v float32) { - *(*float32)(rvPtr(rv)) = v -} - -func rvSetFloat64(rv reflect.Value, v float64) { - *(*float64)(rvPtr(rv)) = v -} - -func rvSetComplex64(rv reflect.Value, v complex64) { - *(*complex64)(rvPtr(rv)) = v -} - -func rvSetComplex128(rv reflect.Value, v complex128) { - *(*complex128)(rvPtr(rv)) = v -} - -func rvSetInt(rv reflect.Value, v int) { - *(*int)(rvPtr(rv)) = v -} - -func rvSetInt8(rv reflect.Value, v int8) { - *(*int8)(rvPtr(rv)) = v -} - -func rvSetInt16(rv reflect.Value, v int16) { - *(*int16)(rvPtr(rv)) = v -} - -func rvSetInt32(rv reflect.Value, v int32) { - *(*int32)(rvPtr(rv)) = v -} - -func rvSetInt64(rv reflect.Value, v int64) { - *(*int64)(rvPtr(rv)) = v -} - -func rvSetUint(rv reflect.Value, v uint) { - *(*uint)(rvPtr(rv)) = v -} - -func rvSetUintptr(rv reflect.Value, v uintptr) { - *(*uintptr)(rvPtr(rv)) = v -} - -func rvSetUint8(rv reflect.Value, v uint8) { - *(*uint8)(rvPtr(rv)) = v -} - -func rvSetUint16(rv reflect.Value, v uint16) { - *(*uint16)(rvPtr(rv)) = v -} - -func rvSetUint32(rv reflect.Value, v uint32) { - *(*uint32)(rvPtr(rv)) = v -} - -func rvSetUint64(rv reflect.Value, v uint64) { - *(*uint64)(rvPtr(rv)) = v -} - -// ---------------- - -// rvSetZero is rv.Set(reflect.Zero(rv.Type()) for all kinds (including reflect.Interface). -func rvSetZero(rv reflect.Value) { - rvSetDirectZero(rv) -} - -func rvSetIntf(rv reflect.Value, v reflect.Value) { - rv.Set(v) -} - -// rvSetDirect is rv.Set for all kinds except reflect.Interface. -// -// Callers MUST not pass a value of kind reflect.Interface, as it may cause unexpected segfaults. -func rvSetDirect(rv reflect.Value, v reflect.Value) { - // MARKER: rv.Set for kind reflect.Interface may do a separate allocation if a scalar value. - // The book-keeping is onerous, so we just do the simple ones where a memmove is sufficient. - urv := (*unsafeReflectValue)(unsafe.Pointer(&rv)) - uv := (*unsafeReflectValue)(unsafe.Pointer(&v)) - if uv.flag&unsafeFlagIndir == 0 { - *(*unsafe.Pointer)(urv.ptr) = uv.ptr - } else if uv.ptr != unsafeZeroAddr { - typedmemmove(urv.typ, urv.ptr, uv.ptr) - } else if urv.ptr != unsafeZeroAddr { - typedmemclr(urv.typ, urv.ptr) - } -} - -// rvSetDirectZero is rv.Set(reflect.Zero(rv.Type()) for all kinds except reflect.Interface. -func rvSetDirectZero(rv reflect.Value) { - urv := (*unsafeReflectValue)(unsafe.Pointer(&rv)) - if urv.ptr != unsafeZeroAddr { - typedmemclr(urv.typ, urv.ptr) - } -} - -// rvMakeSlice updates the slice to point to a new array. -// It copies data from old slice to new slice. -// It returns set=true iff it updates it, else it just returns a new slice pointing to a newly made array. -func rvMakeSlice(rv reflect.Value, ti *typeInfo, xlen, xcap int) (_ reflect.Value, set bool) { - urv := (*unsafeReflectValue)(unsafe.Pointer(&rv)) - ux := (*unsafeSlice)(urv.ptr) - t := ((*unsafeIntf)(unsafe.Pointer(&ti.elem))).ptr - s := unsafeSlice{newarray(t, xcap), xlen, xcap} - if ux.Len > 0 { - typedslicecopy(t, s, *ux) - } - *ux = s - return rv, true -} - -// rvSlice returns a sub-slice of the slice given new lenth, -// without modifying passed in value. -// It is typically called when we know that SetLen(...) cannot be done. -func rvSlice(rv reflect.Value, length int) reflect.Value { - urv := (*unsafeReflectValue)(unsafe.Pointer(&rv)) - ux := *(*unsafeSlice)(urv.ptr) // copy slice header - ux.Len = length - urv.ptr = unsafe.Pointer(&ux) - return rv -} - -// rcGrowSlice updates the slice to point to a new array with the cap incremented, and len set to the new cap value. -// It copies data from old slice to new slice. -// It returns set=true iff it updates it, else it just returns a new slice pointing to a newly made array. -func rvGrowSlice(rv reflect.Value, ti *typeInfo, cap, incr int) (v reflect.Value, newcap int, set bool) { - urv := (*unsafeReflectValue)(unsafe.Pointer(&rv)) - ux := (*unsafeSlice)(urv.ptr) - t := ((*unsafeIntf)(unsafe.Pointer(&ti.elem))).ptr - *ux = unsafeGrowslice(t, *ux, cap, incr) - ux.Len = ux.Cap - return rv, ux.Cap, true -} - -// ------------ - -func rvArrayIndex(rv reflect.Value, i int, ti *typeInfo, isSlice bool) (v reflect.Value) { - urv := (*unsafeReflectValue)(unsafe.Pointer(&rv)) - uv := (*unsafeReflectValue)(unsafe.Pointer(&v)) - if isSlice { - uv.ptr = unsafe.Pointer(uintptr(((*unsafeSlice)(urv.ptr)).Data)) - } else { - uv.ptr = unsafe.Pointer(uintptr(urv.ptr)) - } - uv.ptr = unsafe.Add(uv.ptr, ti.elemsize*uint32(i)) - // uv.ptr = unsafe.Pointer(ptr + uintptr(int(ti.elemsize)*i)) - uv.typ = ((*unsafeIntf)(unsafe.Pointer(&ti.elem))).ptr - uv.flag = uintptr(ti.elemkind) | unsafeFlagIndir | unsafeFlagAddr - return -} - -func rvSliceZeroCap(t reflect.Type) (v reflect.Value) { - urv := (*unsafeReflectValue)(unsafe.Pointer(&v)) - urv.typ = ((*unsafeIntf)(unsafe.Pointer(&t))).ptr - urv.flag = uintptr(reflect.Slice) | unsafeFlagIndir - urv.ptr = unsafe.Pointer(&unsafeZeroSlice) - return -} - -func rvLenSlice(rv reflect.Value) int { - urv := (*unsafeReflectValue)(unsafe.Pointer(&rv)) - return (*unsafeSlice)(urv.ptr).Len -} - -func rvCapSlice(rv reflect.Value) int { - urv := (*unsafeReflectValue)(unsafe.Pointer(&rv)) - return (*unsafeSlice)(urv.ptr).Cap -} - -// if scratch is nil, then return a writable view (assuming canAddr=true) -func rvGetArrayBytes(rv reflect.Value, _ []byte) (bs []byte) { - urv := (*unsafeReflectValue)(unsafe.Pointer(&rv)) - bx := (*unsafeSlice)(unsafe.Pointer(&bs)) - // bx.Data, bx.Len, bx.Cap = urv.ptr, rv.Len(), bx.Len - bx.Data = urv.ptr - bx.Len = rv.Len() - bx.Cap = bx.Len - return -} - -func rvGetArray4Slice(rv reflect.Value) (v reflect.Value) { - // It is possible that this slice is based off an array with a larger - // len that we want (where array len == slice cap). - // However, it is ok to create an array type that is a subset of the full - // e.g. full slice is based off a *[16]byte, but we can create a *[4]byte - // off of it. That is ok. - // - // Consequently, we use rvLenSlice, not rvCapSlice. - - t := reflect.ArrayOf(rvLenSlice(rv), rv.Type().Elem()) - // v = rvZeroAddrK(t, reflect.Array) - - uv := (*unsafeReflectValue)(unsafe.Pointer(&v)) - uv.flag = uintptr(reflect.Array) | unsafeFlagIndir | unsafeFlagAddr - uv.typ = ((*unsafeIntf)(unsafe.Pointer(&t))).ptr - - urv := (*unsafeReflectValue)(unsafe.Pointer(&rv)) - uv.ptr = *(*unsafe.Pointer)(urv.ptr) // slice rv has a ptr to the slice. - - return -} - -func rvGetSlice4Array(rv reflect.Value, v interface{}) { - // v is a pointer to a slice to be populated - uv := (*unsafeIntf)(unsafe.Pointer(&v)) - urv := (*unsafeReflectValue)(unsafe.Pointer(&rv)) - - s := (*unsafeSlice)(uv.ptr) - s.Data = urv.ptr - s.Len = rv.Len() - s.Cap = s.Len -} - -func rvCopySlice(dest, src reflect.Value, elemType reflect.Type) { - typedslicecopy((*unsafeIntf)(unsafe.Pointer(&elemType)).ptr, - *(*unsafeSlice)((*unsafeReflectValue)(unsafe.Pointer(&dest)).ptr), - *(*unsafeSlice)((*unsafeReflectValue)(unsafe.Pointer(&src)).ptr)) -} - -// ------------ - -func rvPtr(rv reflect.Value) unsafe.Pointer { - return (*unsafeReflectValue)(unsafe.Pointer(&rv)).ptr -} - -func rvGetBool(rv reflect.Value) bool { - return *(*bool)(rvPtr(rv)) -} - -func rvGetBytes(rv reflect.Value) []byte { - return *(*[]byte)(rvPtr(rv)) -} - -func rvGetTime(rv reflect.Value) time.Time { - return *(*time.Time)(rvPtr(rv)) -} - -func rvGetString(rv reflect.Value) string { - return *(*string)(rvPtr(rv)) -} - -func rvGetFloat64(rv reflect.Value) float64 { - return *(*float64)(rvPtr(rv)) -} - -func rvGetFloat32(rv reflect.Value) float32 { - return *(*float32)(rvPtr(rv)) -} - -func rvGetComplex64(rv reflect.Value) complex64 { - return *(*complex64)(rvPtr(rv)) -} - -func rvGetComplex128(rv reflect.Value) complex128 { - return *(*complex128)(rvPtr(rv)) -} - -func rvGetInt(rv reflect.Value) int { - return *(*int)(rvPtr(rv)) -} - -func rvGetInt8(rv reflect.Value) int8 { - return *(*int8)(rvPtr(rv)) -} - -func rvGetInt16(rv reflect.Value) int16 { - return *(*int16)(rvPtr(rv)) -} - -func rvGetInt32(rv reflect.Value) int32 { - return *(*int32)(rvPtr(rv)) -} - -func rvGetInt64(rv reflect.Value) int64 { - return *(*int64)(rvPtr(rv)) -} - -func rvGetUint(rv reflect.Value) uint { - return *(*uint)(rvPtr(rv)) -} - -func rvGetUint8(rv reflect.Value) uint8 { - return *(*uint8)(rvPtr(rv)) -} - -func rvGetUint16(rv reflect.Value) uint16 { - return *(*uint16)(rvPtr(rv)) -} - -func rvGetUint32(rv reflect.Value) uint32 { - return *(*uint32)(rvPtr(rv)) -} - -func rvGetUint64(rv reflect.Value) uint64 { - return *(*uint64)(rvPtr(rv)) -} - -func rvGetUintptr(rv reflect.Value) uintptr { - return *(*uintptr)(rvPtr(rv)) -} - -func rvLenMap(rv reflect.Value) int { - // maplen is not inlined, because as of go1.16beta, go:linkname's are not inlined. - // thus, faster to call rv.Len() directly. - // - // MARKER: review after https://github.com/golang/go/issues/20019 fixed. - - // return rv.Len() - - return len_map(rvRefPtr((*unsafeReflectValue)(unsafe.Pointer(&rv)))) -} - -// Note: it is hard to find len(...) of an array type, -// as that is a field in the arrayType representing the array, and hard to introspect. -// -// func rvLenArray(rv reflect.Value) int { return rv.Len() } - -// ------------ map range and map indexing ---------- - -// regular calls to map via reflection: MapKeys, MapIndex, MapRange/MapIter etc -// will always allocate for each map key or value. -// -// It is more performant to provide a value that the map entry is set into, -// and that elides the allocation. -// -// go 1.4 through go 1.23 (in runtime/hashmap.go or runtime/map.go) has a hIter struct -// with the first 2 values being pointers for key and value of the current iteration. -// The next 6 values are pointers, followed by numeric types (uintptr, uint8, bool, etc). -// This *hIter is passed to mapiterinit, mapiternext, mapiterkey, mapiterelem. -// -// In go 1.24, swissmap was introduced, and it provides a compatibility layer -// for hIter (called linknameIter). This has only 2 pointer fields after the key and value pointers. -// -// Note: We bypass the reflect wrapper functions and just use the *hIter directly. -// -// When 'faking' these types with our own, we MUST ensure that the GC sees the pointers -// appropriately. These are reflected in goversion_(no)swissmap_unsafe.go files. -// In these files, we pad the extra spaces appropriately. -// -// Note: the faux hIter/linknameIter is directly embedded in unsafeMapIter below - -type unsafeMapIter struct { - mtyp, mptr unsafe.Pointer - k, v unsafeReflectValue - kisref bool - visref bool - mapvalues bool - done bool - started bool - _ [3]byte // padding - it struct { - key unsafe.Pointer - value unsafe.Pointer - _ unsafeMapIterPadding - } -} - -func (t *unsafeMapIter) Next() (r bool) { - if t == nil || t.done { - return - } - if t.started { - mapiternext((unsafe.Pointer)(&t.it)) - } else { - t.started = true - } - - t.done = t.it.key == nil - if t.done { - return - } - - if helperUnsafeDirectAssignMapEntry || t.kisref { - t.k.ptr = t.it.key - } else { - typedmemmove(t.k.typ, t.k.ptr, t.it.key) - } - - if t.mapvalues { - if helperUnsafeDirectAssignMapEntry || t.visref { - t.v.ptr = t.it.value - } else { - typedmemmove(t.v.typ, t.v.ptr, t.it.value) - } - } - - return true -} - -func (t *unsafeMapIter) Key() (r reflect.Value) { - return *(*reflect.Value)(unsafe.Pointer(&t.k)) -} - -func (t *unsafeMapIter) Value() (r reflect.Value) { - return *(*reflect.Value)(unsafe.Pointer(&t.v)) -} - -func (t *unsafeMapIter) Done() {} - -type mapIter struct { - unsafeMapIter -} - -func mapRange(t *mapIter, m, k, v reflect.Value, mapvalues bool) { - if rvIsNil(m) { - t.done = true - return - } - t.done = false - t.started = false - t.mapvalues = mapvalues - - // var urv *unsafeReflectValue - - urv := (*unsafeReflectValue)(unsafe.Pointer(&m)) - t.mtyp = urv.typ - t.mptr = rvRefPtr(urv) - - // t.it = (*unsafeMapHashIter)(reflect_mapiterinit(t.mtyp, t.mptr)) - mapiterinit(t.mtyp, t.mptr, unsafe.Pointer(&t.it)) - - t.k = *(*unsafeReflectValue)(unsafe.Pointer(&k)) - t.kisref = refBitset.isset(byte(k.Kind())) - - if mapvalues { - t.v = *(*unsafeReflectValue)(unsafe.Pointer(&v)) - t.visref = refBitset.isset(byte(v.Kind())) - } else { - t.v = unsafeReflectValue{} - } -} - -// unsafeMapKVPtr returns the pointer if flagIndir, else it returns a pointer to the pointer. -// It is needed as maps always keep a reference to the underlying value. -func unsafeMapKVPtr(urv *unsafeReflectValue) unsafe.Pointer { - if urv.flag&unsafeFlagIndir == 0 { - return unsafe.Pointer(&urv.ptr) - } - return urv.ptr -} - -// return an addressable reflect value that can be used in mapRange and mapGet operations. -// -// all calls to mapGet or mapRange will call here to get an addressable reflect.Value. -func mapAddrLoopvarRV(t reflect.Type, k reflect.Kind) (rv reflect.Value) { - // return rvZeroAddrK(t, k) - urv := (*unsafeReflectValue)(unsafe.Pointer(&rv)) - urv.flag = uintptr(k) | unsafeFlagIndir | unsafeFlagAddr - urv.typ = ((*unsafeIntf)(unsafe.Pointer(&t))).ptr - // since we always set the ptr when helperUnsafeDirectAssignMapEntry=true, - // we should only allocate if it is not true - if !helperUnsafeDirectAssignMapEntry { - urv.ptr = unsafeNew(urv.typ) - } - return -} - -func makeMapReflect(typ reflect.Type, size int) (rv reflect.Value) { - t := (*unsafeIntf)(unsafe.Pointer(&typ)).ptr - urv := (*unsafeReflectValue)(unsafe.Pointer(&rv)) - urv.typ = t - urv.flag = uintptr(reflect.Map) - urv.ptr = makemap(t, size, nil) - return -} - -func (d *decoderBase) bytes2Str(in []byte, state dBytesAttachState) (s string, mutable bool) { - return stringView(in), state <= dBytesAttachBuffer -} - -// ---------- structFieldInfo optimized --------------- - -func (n *structFieldInfoNode) rvField(v reflect.Value) (rv reflect.Value) { - // we already know this is exported, and maybe embedded (based on what si says) - uv := (*unsafeReflectValue)(unsafe.Pointer(&v)) - - urv := (*unsafeReflectValue)(unsafe.Pointer(&rv)) - // clear flagEmbedRO if necessary, and inherit permission bits from v - urv.flag = uv.flag&(unsafeFlagStickyRO|unsafeFlagIndir|unsafeFlagAddr) | uintptr(n.kind) - urv.typ = ((*unsafeIntf)(unsafe.Pointer(&n.typ))).ptr - urv.ptr = unsafe.Pointer(uintptr(uv.ptr) + uintptr(n.offset)) - - // *(*unsafeReflectValue)(unsafe.Pointer(&rv)) = unsafeReflectValue{ - // unsafeIntf: unsafeIntf{ - // typ: ((*unsafeIntf)(unsafe.Pointer(&n.typ))).ptr, - // ptr: unsafe.Pointer(uintptr(uv.ptr) + uintptr(n.offset)), - // }, - // flag: uv.flag&(unsafeFlagStickyRO|unsafeFlagIndir|unsafeFlagAddr) | uintptr(n.kind), - // } - - return -} - -// runtime chan and map are designed such that the first field is the count. -// len builtin uses this to get the length of a chan/map easily. -// leverage this knowledge, since maplen and chanlen functions from runtime package -// are go:linkname'd here, and thus not inlined as of go1.16beta - -func len_map_chan(m unsafe.Pointer) int { - if m == nil { - return 0 - } - return *((*int)(m)) -} - -func len_map(m unsafe.Pointer) int { - // return maplen(m) - return len_map_chan(m) -} -func len_chan(m unsafe.Pointer) int { - // return chanlen(m) - return len_map_chan(m) -} - -func unsafeNew(typ unsafe.Pointer) unsafe.Pointer { - return mallocgc(rtsize2(typ), typ, true) -} - -// ---------- go linknames (LINKED to runtime/reflect) --------------- - -// MARKER: always check that these linknames match subsequent versions of go -// -// Note that as of Jan 2021 (go 1.16 release), go:linkname(s) are not inlined -// outside of the standard library use (e.g. within sync, reflect, etc). -// If these link'ed functions were normally inlined, calling them here would -// not necessarily give a performance boost, due to function overhead. -// -// However, it seems most of these functions are not inlined anyway, -// as only maplen, chanlen and mapaccess are small enough to get inlined. -// -// We checked this by going into $GOROOT/src/runtime and running: -// $ go build -tags codec.notfastpath -gcflags "-m=2" - -// reflect.{unsafe_New, unsafe_NewArray} are not supported in gollvm, -// failing with "error: undefined reference" error. -// however, runtime.{mallocgc, newarray} are supported, so use that instead. - -//go:linkname mallocgc runtime.mallocgc -//go:noescape -func mallocgc(size uintptr, typ unsafe.Pointer, needzero bool) unsafe.Pointer - -//go:linkname newarray runtime.newarray -//go:noescape -func newarray(typ unsafe.Pointer, n int) unsafe.Pointer - -//go:linkname mapiterinit runtime.mapiterinit -//go:noescape -func mapiterinit(typ unsafe.Pointer, m unsafe.Pointer, it unsafe.Pointer) - -//go:linkname mapiternext runtime.mapiternext -//go:noescape -func mapiternext(it unsafe.Pointer) (key unsafe.Pointer) - -//go:linkname mapassign runtime.mapassign -//go:noescape -func mapassign(typ unsafe.Pointer, m unsafe.Pointer, key unsafe.Pointer) unsafe.Pointer - -//go:linkname mapaccess2 runtime.mapaccess2 -//go:noescape -func mapaccess2(typ unsafe.Pointer, m unsafe.Pointer, key unsafe.Pointer) (val unsafe.Pointer, ok bool) - -//go:linkname makemap runtime.makemap -//go:noescape -func makemap(typ unsafe.Pointer, size int, h unsafe.Pointer) unsafe.Pointer - -// reflect.typed{memmove, memclr, slicecopy} will handle checking if the type has pointers or not, -// and if a writeBarrier is needed, before delegating to the right method in the runtime. -// -// This is why we use the functions in reflect, and not the ones in runtime directly. -// Calling runtime.XXX here will lead to memory issues. - -//go:linkname typedslicecopy reflect.typedslicecopy -//go:noescape -func typedslicecopy(elemType unsafe.Pointer, dst, src unsafeSlice) int - -//go:linkname typedmemmove reflect.typedmemmove -//go:noescape -func typedmemmove(typ unsafe.Pointer, dst, src unsafe.Pointer) - -//go:linkname typedmemclr reflect.typedmemclr -//go:noescape -func typedmemclr(typ unsafe.Pointer, dst unsafe.Pointer) diff --git a/vendor/github.com/ugorji/go/codec/helper_unsafe_compiler_gc.go b/vendor/github.com/ugorji/go/codec/helper_unsafe_compiler_gc.go deleted file mode 100644 index 7d1349304..000000000 --- a/vendor/github.com/ugorji/go/codec/helper_unsafe_compiler_gc.go +++ /dev/null @@ -1,242 +0,0 @@ -// Copyright (c) 2012-2020 Ugorji Nwoke. All rights reserved. -// Use of this source code is governed by a MIT license found in the LICENSE file. - -//go:build !safe && !codec.safe && !appengine && go1.9 && gc - -package codec - -import ( - "reflect" - _ "runtime" // needed for go linkname(s) - "unsafe" -) - -// keep in sync with -// -// $GOROOT/src/cmd/compile/internal/gc/reflect.go: MAXKEYSIZE, MAXELEMSIZE -// $GOROOT/src/runtime/map.go: maxKeySize, maxElemSize -// $GOROOT/src/reflect/type.go: maxKeySize, maxElemSize -// -// We use these to determine whether the type is stored indirectly in the map or not. -const ( - // mapMaxKeySize = 128 - mapMaxElemSize = 128 -) - -type mapKeyFastKind uint8 - -const ( - mapKeyFastKindAny = iota + 1 - mapKeyFastKind32 - mapKeyFastKind32ptr - mapKeyFastKind64 - mapKeyFastKind64ptr - mapKeyFastKindStr -) - -var mapKeyFastKindVals [32]mapKeyFastKind - -type mapReqParams struct { - kfast mapKeyFastKind - ref bool - indirect bool -} - -func getMapReqParams(ti *typeInfo) (r mapReqParams) { - r.indirect = mapStoresElemIndirect(uintptr(ti.elemsize)) - r.ref = refBitset.isset(ti.elemkind) - r.kfast = mapKeyFastKindFor(reflect.Kind(ti.keykind)) - return -} - -func init() { - xx := func(f mapKeyFastKind, k ...reflect.Kind) { - for _, v := range k { - mapKeyFastKindVals[byte(v)&31] = f // 'v % 32' equal to 'v & 31' - } - } - - var f mapKeyFastKind - - f = mapKeyFastKind64 - if wordSizeBits == 32 { - f = mapKeyFastKind32 - } - xx(f, reflect.Int, reflect.Uint, reflect.Uintptr) - - f = mapKeyFastKind64ptr - if wordSizeBits == 32 { - f = mapKeyFastKind32ptr - } - xx(f, reflect.Ptr) - - xx(mapKeyFastKindStr, reflect.String) - xx(mapKeyFastKind32, reflect.Uint32, reflect.Int32, reflect.Float32) - xx(mapKeyFastKind64, reflect.Uint64, reflect.Int64, reflect.Float64) -} - -func mapKeyFastKindFor(k reflect.Kind) mapKeyFastKind { - return mapKeyFastKindVals[k&31] -} - -func unsafeGrowslice(typ unsafe.Pointer, old unsafeSlice, cap, incr int) (s unsafeSlice) { - // culled from GOROOT/runtime/slice.go - s = rtgrowslice(old.Data, old.Cap+incr, old.Cap, incr, typ) - s.Len = old.Len - return -} - -// func rvType(rv reflect.Value) reflect.Type { -// return rvPtrToType(((*unsafeReflectValue)(unsafe.Pointer(&rv))).typ) -// // return rv.Type() -// } - -// mapStoresElemIndirect tells if the element type is stored indirectly in the map. -// -// This is used to determine valIsIndirect which is passed into mapSet/mapGet calls. -// -// If valIsIndirect doesn't matter, then just return false and ignore the value -// passed in mapGet/mapSet calls -func mapStoresElemIndirect(elemsize uintptr) bool { - return elemsize > mapMaxElemSize -} - -func mapSet(m, k, v reflect.Value, p mapReqParams) { // valIsRef - var urv = (*unsafeReflectValue)(unsafe.Pointer(&k)) - var kptr = unsafeMapKVPtr(urv) - urv = (*unsafeReflectValue)(unsafe.Pointer(&v)) - var vtyp = urv.typ - var vptr = unsafeMapKVPtr(urv) - - urv = (*unsafeReflectValue)(unsafe.Pointer(&m)) - mptr := rvRefPtr(urv) - - var vvptr unsafe.Pointer - - // mapassign_fastXXX don't take indirect into account. - // It was hard to infer what makes it work all the time. - // Sometimes, we got vvptr == nil when we dereferenced vvptr (if valIsIndirect). - // Consequently, only use fastXXX functions if !valIsIndirect - - if p.indirect { - vvptr = mapassign(urv.typ, mptr, kptr) - // typedmemmove(vtyp, vvptr, vptr) - // // reflect_mapassign(urv.typ, mptr, kptr, vptr) - // return - goto END - } - - switch p.kfast { - case mapKeyFastKind32: - vvptr = mapassign_fast32(urv.typ, mptr, *(*uint32)(kptr)) - case mapKeyFastKind32ptr: - vvptr = mapassign_fast32ptr(urv.typ, mptr, *(*unsafe.Pointer)(kptr)) - case mapKeyFastKind64: - vvptr = mapassign_fast64(urv.typ, mptr, *(*uint64)(kptr)) - case mapKeyFastKind64ptr: - vvptr = mapassign_fast64ptr(urv.typ, mptr, *(*unsafe.Pointer)(kptr)) - case mapKeyFastKindStr: - vvptr = mapassign_faststr(urv.typ, mptr, *(*string)(kptr)) - default: - vvptr = mapassign(urv.typ, mptr, kptr) - } - - // if p.kfast != 0 && valIsIndirect { - // vvptr = *(*unsafe.Pointer)(vvptr) - // } -END: - typedmemmove(vtyp, vvptr, vptr) -} - -func mapGet(m, k, v reflect.Value, p mapReqParams) (_ reflect.Value) { - var urv = (*unsafeReflectValue)(unsafe.Pointer(&k)) - var kptr = unsafeMapKVPtr(urv) - urv = (*unsafeReflectValue)(unsafe.Pointer(&m)) - mptr := rvRefPtr(urv) - - var vvptr unsafe.Pointer - var ok bool - - // Note that mapaccess2_fastXXX functions do not check if the value needs to be copied. - // if they do, we should dereference the pointer and return that - - switch p.kfast { - case mapKeyFastKind32, mapKeyFastKind32ptr: - vvptr, ok = mapaccess2_fast32(urv.typ, mptr, *(*uint32)(kptr)) - case mapKeyFastKind64, mapKeyFastKind64ptr: - vvptr, ok = mapaccess2_fast64(urv.typ, mptr, *(*uint64)(kptr)) - case mapKeyFastKindStr: - vvptr, ok = mapaccess2_faststr(urv.typ, mptr, *(*string)(kptr)) - default: - vvptr, ok = mapaccess2(urv.typ, mptr, kptr) - } - - if !ok { - return - } - - urv = (*unsafeReflectValue)(unsafe.Pointer(&v)) - - if p.kfast != 0 && p.indirect { - urv.ptr = *(*unsafe.Pointer)(vvptr) - } else if helperUnsafeDirectAssignMapEntry || p.ref { - urv.ptr = vvptr - } else { - typedmemmove(urv.typ, urv.ptr, vvptr) - } - - return v -} - -// ---- - -//go:linkname unsafeZeroArr runtime.zeroVal -var unsafeZeroArr [1024]byte - -//go:linkname mapassign_fast32 runtime.mapassign_fast32 -//go:noescape -func mapassign_fast32(typ unsafe.Pointer, m unsafe.Pointer, key uint32) unsafe.Pointer - -//go:linkname mapassign_fast32ptr runtime.mapassign_fast32ptr -//go:noescape -func mapassign_fast32ptr(typ unsafe.Pointer, m unsafe.Pointer, key unsafe.Pointer) unsafe.Pointer - -//go:linkname mapassign_fast64 runtime.mapassign_fast64 -//go:noescape -func mapassign_fast64(typ unsafe.Pointer, m unsafe.Pointer, key uint64) unsafe.Pointer - -//go:linkname mapassign_fast64ptr runtime.mapassign_fast64ptr -//go:noescape -func mapassign_fast64ptr(typ unsafe.Pointer, m unsafe.Pointer, key unsafe.Pointer) unsafe.Pointer - -//go:linkname mapassign_faststr runtime.mapassign_faststr -//go:noescape -func mapassign_faststr(typ unsafe.Pointer, m unsafe.Pointer, s string) unsafe.Pointer - -//go:linkname mapaccess2_fast32 runtime.mapaccess2_fast32 -//go:noescape -func mapaccess2_fast32(typ unsafe.Pointer, m unsafe.Pointer, key uint32) (val unsafe.Pointer, ok bool) - -//go:linkname mapaccess2_fast64 runtime.mapaccess2_fast64 -//go:noescape -func mapaccess2_fast64(typ unsafe.Pointer, m unsafe.Pointer, key uint64) (val unsafe.Pointer, ok bool) - -//go:linkname mapaccess2_faststr runtime.mapaccess2_faststr -//go:noescape -func mapaccess2_faststr(typ unsafe.Pointer, m unsafe.Pointer, key string) (val unsafe.Pointer, ok bool) - -//go:linkname rtgrowslice runtime.growslice -//go:noescape -func rtgrowslice(oldPtr unsafe.Pointer, newLen, oldCap, num int, typ unsafe.Pointer) unsafeSlice - -// ---- - -// //go:linkname rvPtrToType reflect.toType -// //go:noescape -// func rvPtrToType(typ unsafe.Pointer) reflect.Type - -// //go:linkname growslice reflect.growslice -// //go:noescape -// func growslice(typ unsafe.Pointer, old unsafeSlice, cap int) unsafeSlice - -// ---- diff --git a/vendor/github.com/ugorji/go/codec/helper_unsafe_compiler_not_gc.go b/vendor/github.com/ugorji/go/codec/helper_unsafe_compiler_not_gc.go deleted file mode 100644 index e33db296e..000000000 --- a/vendor/github.com/ugorji/go/codec/helper_unsafe_compiler_not_gc.go +++ /dev/null @@ -1,81 +0,0 @@ -// Copyright (c) 2012-2020 Ugorji Nwoke. All rights reserved. -// Use of this source code is governed by a MIT license found in the LICENSE file. - -//go:build !safe && !codec.safe && !appengine && go1.9 && !gc - -package codec - -import ( - "reflect" - _ "runtime" // needed for go linkname(s) - "unsafe" -) - -var unsafeZeroArr [1024]byte - -type mapReqParams struct { - ref bool -} - -func getMapReqParams(ti *typeInfo) (r mapReqParams) { - r.ref = refBitset.isset(ti.elemkind) - return -} - -// runtime.growslice does not work with gccgo, failing with "growslice: cap out of range" error. -// consequently, we just call newarray followed by typedslicecopy directly. - -func unsafeGrowslice(typ unsafe.Pointer, old unsafeSlice, cap, incr int) (v unsafeSlice) { - size := rtsize2(typ) - if size == 0 { - return unsafeSlice{unsafe.Pointer(&unsafeZeroArr[0]), old.Len, cap + incr} - } - newcap := int(growCap(uint(cap), uint(size), uint(incr))) - v = unsafeSlice{Data: newarray(typ, newcap), Len: old.Len, Cap: newcap} - if old.Len > 0 { - typedslicecopy(typ, v, old) - } - // memmove(v.Data, old.Data, size*uintptr(old.Len)) - return -} - -// runtime.{mapassign_fastXXX, mapaccess2_fastXXX} are not supported in gollvm, -// failing with "error: undefined reference" error. -// so we just use runtime.{mapassign, mapaccess2} directly - -func mapSet(m, k, v reflect.Value, p mapReqParams) { - var urv = (*unsafeReflectValue)(unsafe.Pointer(&k)) - var kptr = unsafeMapKVPtr(urv) - urv = (*unsafeReflectValue)(unsafe.Pointer(&v)) - var vtyp = urv.typ - var vptr = unsafeMapKVPtr(urv) - - urv = (*unsafeReflectValue)(unsafe.Pointer(&m)) - mptr := rvRefPtr(urv) - - vvptr := mapassign(urv.typ, mptr, kptr) - typedmemmove(vtyp, vvptr, vptr) -} - -func mapGet(m, k, v reflect.Value, p mapReqParams) (_ reflect.Value) { - var urv = (*unsafeReflectValue)(unsafe.Pointer(&k)) - var kptr = unsafeMapKVPtr(urv) - urv = (*unsafeReflectValue)(unsafe.Pointer(&m)) - mptr := rvRefPtr(urv) - - vvptr, ok := mapaccess2(urv.typ, mptr, kptr) - - if !ok { - return - } - - urv = (*unsafeReflectValue)(unsafe.Pointer(&v)) - - if helperUnsafeDirectAssignMapEntry || p.ref { - urv.ptr = vvptr - } else { - typedmemmove(urv.typ, urv.ptr, vvptr) - } - - return v -} diff --git a/vendor/github.com/ugorji/go/codec/init.mono.go b/vendor/github.com/ugorji/go/codec/init.mono.go deleted file mode 100644 index f4133b026..000000000 --- a/vendor/github.com/ugorji/go/codec/init.mono.go +++ /dev/null @@ -1,130 +0,0 @@ -// Copyright (c) 2012-2020 Ugorji Nwoke. All rights reserved. -// Use of this source code is governed by a MIT license found in the LICENSE file. - -//go:build !notmono && !codec.notmono - -package codec - -import "io" - -func callMake(v interface{}) {} - -type encWriter interface{ encWriterI } -type decReader interface{ decReaderI } -type encDriver interface{ encDriverI } -type decDriver interface{ decDriverI } - -func (h *SimpleHandle) newEncoderBytes(out *[]byte) encoderI { - return helperEncDriverSimpleBytes{}.newEncoderBytes(out, h) -} - -func (h *SimpleHandle) newEncoder(w io.Writer) encoderI { - return helperEncDriverSimpleIO{}.newEncoderIO(w, h) -} - -func (h *SimpleHandle) newDecoderBytes(in []byte) decoderI { - return helperDecDriverSimpleBytes{}.newDecoderBytes(in, h) -} - -func (h *SimpleHandle) newDecoder(r io.Reader) decoderI { - return helperDecDriverSimpleIO{}.newDecoderIO(r, h) -} - -func (h *JsonHandle) newEncoderBytes(out *[]byte) encoderI { - return helperEncDriverJsonBytes{}.newEncoderBytes(out, h) -} - -func (h *JsonHandle) newEncoder(w io.Writer) encoderI { - return helperEncDriverJsonIO{}.newEncoderIO(w, h) -} - -func (h *JsonHandle) newDecoderBytes(in []byte) decoderI { - return helperDecDriverJsonBytes{}.newDecoderBytes(in, h) -} - -func (h *JsonHandle) newDecoder(r io.Reader) decoderI { - return helperDecDriverJsonIO{}.newDecoderIO(r, h) -} - -func (h *MsgpackHandle) newEncoderBytes(out *[]byte) encoderI { - return helperEncDriverMsgpackBytes{}.newEncoderBytes(out, h) -} - -func (h *MsgpackHandle) newEncoder(w io.Writer) encoderI { - return helperEncDriverMsgpackIO{}.newEncoderIO(w, h) -} - -func (h *MsgpackHandle) newDecoderBytes(in []byte) decoderI { - return helperDecDriverMsgpackBytes{}.newDecoderBytes(in, h) -} - -func (h *MsgpackHandle) newDecoder(r io.Reader) decoderI { - return helperDecDriverMsgpackIO{}.newDecoderIO(r, h) -} - -func (h *BincHandle) newEncoderBytes(out *[]byte) encoderI { - return helperEncDriverBincBytes{}.newEncoderBytes(out, h) -} - -func (h *BincHandle) newEncoder(w io.Writer) encoderI { - return helperEncDriverBincIO{}.newEncoderIO(w, h) -} - -func (h *BincHandle) newDecoderBytes(in []byte) decoderI { - return helperDecDriverBincBytes{}.newDecoderBytes(in, h) -} - -func (h *BincHandle) newDecoder(r io.Reader) decoderI { - return helperDecDriverBincIO{}.newDecoderIO(r, h) -} - -func (h *CborHandle) newEncoderBytes(out *[]byte) encoderI { - return helperEncDriverCborBytes{}.newEncoderBytes(out, h) -} - -func (h *CborHandle) newEncoder(w io.Writer) encoderI { - return helperEncDriverCborIO{}.newEncoderIO(w, h) -} - -func (h *CborHandle) newDecoderBytes(in []byte) decoderI { - return helperDecDriverCborBytes{}.newDecoderBytes(in, h) -} - -func (h *CborHandle) newDecoder(r io.Reader) decoderI { - return helperDecDriverCborIO{}.newDecoderIO(r, h) -} - -var ( - bincFpEncIO = helperEncDriverBincIO{}.fastpathEList() - bincFpEncBytes = helperEncDriverBincBytes{}.fastpathEList() - bincFpDecIO = helperDecDriverBincIO{}.fastpathDList() - bincFpDecBytes = helperDecDriverBincBytes{}.fastpathDList() -) - -var ( - cborFpEncIO = helperEncDriverCborIO{}.fastpathEList() - cborFpEncBytes = helperEncDriverCborBytes{}.fastpathEList() - cborFpDecIO = helperDecDriverCborIO{}.fastpathDList() - cborFpDecBytes = helperDecDriverCborBytes{}.fastpathDList() -) - -var ( - jsonFpEncIO = helperEncDriverJsonIO{}.fastpathEList() - jsonFpEncBytes = helperEncDriverJsonBytes{}.fastpathEList() - jsonFpDecIO = helperDecDriverJsonIO{}.fastpathDList() - jsonFpDecBytes = helperDecDriverJsonBytes{}.fastpathDList() -) - -var ( - msgpackFpEncIO = helperEncDriverMsgpackIO{}.fastpathEList() - msgpackFpEncBytes = helperEncDriverMsgpackBytes{}.fastpathEList() - msgpackFpDecIO = helperDecDriverMsgpackIO{}.fastpathDList() - msgpackFpDecBytes = helperDecDriverMsgpackBytes{}.fastpathDList() -) - -var ( - simpleFpEncIO = helperEncDriverSimpleIO{}.fastpathEList() - simpleFpEncBytes = helperEncDriverSimpleBytes{}.fastpathEList() - simpleFpDecIO = helperDecDriverSimpleIO{}.fastpathDList() - simpleFpDecBytes = helperDecDriverSimpleBytes{}.fastpathDList() -) diff --git a/vendor/github.com/ugorji/go/codec/init.notmono.go b/vendor/github.com/ugorji/go/codec/init.notmono.go deleted file mode 100644 index b03fb8503..000000000 --- a/vendor/github.com/ugorji/go/codec/init.notmono.go +++ /dev/null @@ -1,313 +0,0 @@ -// Copyright (c) 2012-2020 Ugorji Nwoke. All rights reserved. -// Use of this source code is governed by a MIT license found in the LICENSE file. - -//go:build notmono || codec.notmono - -package codec - -import ( - "io" -) - -// This contains all the iniatializations of generics. -// Putting it into one file, ensures that we can go generics or not. - -type maker interface{ Make() } - -func callMake(v interface{}) { - v.(maker).Make() -} - -// ---- (writer.go) - -type encWriter interface { - bufioEncWriterM | bytesEncAppenderM - encWriterI -} - -type bytesEncAppenderM struct { - *bytesEncAppender -} - -func (z *bytesEncAppenderM) Make() { - z.bytesEncAppender = new(bytesEncAppender) - z.out = &bytesEncAppenderDefOut -} - -type bufioEncWriterM struct { - *bufioEncWriter -} - -func (z *bufioEncWriterM) Make() { - z.bufioEncWriter = new(bufioEncWriter) - z.w = io.Discard -} - -// ---- reader.go - -type decReader interface { - bytesDecReaderM | ioDecReaderM - - decReaderI -} - -type bytesDecReaderM struct { - *bytesDecReader -} - -func (z *bytesDecReaderM) Make() { - z.bytesDecReader = new(bytesDecReader) -} - -type ioDecReaderM struct { - *ioDecReader -} - -func (z *ioDecReaderM) Make() { - z.ioDecReader = new(ioDecReader) -} - -// type helperEncWriter[T encWriter] struct{} -// type helperDecReader[T decReader] struct{} -// func (helperDecReader[T]) decByteSlice(r T, clen, maxInitLen int, bs []byte) (bsOut []byte) { - -// ---- (encode.go) - -type encDriver interface { - simpleEncDriverM[bufioEncWriterM] | - simpleEncDriverM[bytesEncAppenderM] | - jsonEncDriverM[bufioEncWriterM] | - jsonEncDriverM[bytesEncAppenderM] | - cborEncDriverM[bufioEncWriterM] | - cborEncDriverM[bytesEncAppenderM] | - msgpackEncDriverM[bufioEncWriterM] | - msgpackEncDriverM[bytesEncAppenderM] | - bincEncDriverM[bufioEncWriterM] | - bincEncDriverM[bytesEncAppenderM] - - encDriverI -} - -// ---- (decode.go) - -type decDriver interface { - simpleDecDriverM[bytesDecReaderM] | - simpleDecDriverM[ioDecReaderM] | - jsonDecDriverM[bytesDecReaderM] | - jsonDecDriverM[ioDecReaderM] | - cborDecDriverM[bytesDecReaderM] | - cborDecDriverM[ioDecReaderM] | - msgpackDecDriverM[bytesDecReaderM] | - msgpackDecDriverM[ioDecReaderM] | - bincDecDriverM[bytesDecReaderM] | - bincDecDriverM[ioDecReaderM] - - decDriverI -} - -// Below: .go files - -// ---- (binc.go) - -type bincEncDriverM[T encWriter] struct { - *bincEncDriver[T] -} - -func (d *bincEncDriverM[T]) Make() { - d.bincEncDriver = new(bincEncDriver[T]) -} - -type bincDecDriverM[T decReader] struct { - *bincDecDriver[T] -} - -func (d *bincDecDriverM[T]) Make() { - d.bincDecDriver = new(bincDecDriver[T]) -} - -var ( - bincFpEncIO = helperEncDriver[bincEncDriverM[bufioEncWriterM]]{}.fastpathEList() - bincFpEncBytes = helperEncDriver[bincEncDriverM[bytesEncAppenderM]]{}.fastpathEList() - bincFpDecIO = helperDecDriver[bincDecDriverM[ioDecReaderM]]{}.fastpathDList() - bincFpDecBytes = helperDecDriver[bincDecDriverM[bytesDecReaderM]]{}.fastpathDList() -) - -// ---- (cbor.go) - -type cborEncDriverM[T encWriter] struct { - *cborEncDriver[T] -} - -func (d *cborEncDriverM[T]) Make() { - d.cborEncDriver = new(cborEncDriver[T]) -} - -type cborDecDriverM[T decReader] struct { - *cborDecDriver[T] -} - -func (d *cborDecDriverM[T]) Make() { - d.cborDecDriver = new(cborDecDriver[T]) -} - -var ( - cborFpEncIO = helperEncDriver[cborEncDriverM[bufioEncWriterM]]{}.fastpathEList() - cborFpEncBytes = helperEncDriver[cborEncDriverM[bytesEncAppenderM]]{}.fastpathEList() - cborFpDecIO = helperDecDriver[cborDecDriverM[ioDecReaderM]]{}.fastpathDList() - cborFpDecBytes = helperDecDriver[cborDecDriverM[bytesDecReaderM]]{}.fastpathDList() -) - -// ---- (json.go) - -type jsonEncDriverM[T encWriter] struct { - *jsonEncDriver[T] -} - -func (d *jsonEncDriverM[T]) Make() { - d.jsonEncDriver = new(jsonEncDriver[T]) -} - -type jsonDecDriverM[T decReader] struct { - *jsonDecDriver[T] -} - -func (d *jsonDecDriverM[T]) Make() { - d.jsonDecDriver = new(jsonDecDriver[T]) -} - -var ( - jsonFpEncIO = helperEncDriver[jsonEncDriverM[bufioEncWriterM]]{}.fastpathEList() - jsonFpEncBytes = helperEncDriver[jsonEncDriverM[bytesEncAppenderM]]{}.fastpathEList() - jsonFpDecIO = helperDecDriver[jsonDecDriverM[ioDecReaderM]]{}.fastpathDList() - jsonFpDecBytes = helperDecDriver[jsonDecDriverM[bytesDecReaderM]]{}.fastpathDList() -) - -// ---- (msgpack.go) - -type msgpackEncDriverM[T encWriter] struct { - *msgpackEncDriver[T] -} - -func (d *msgpackEncDriverM[T]) Make() { - d.msgpackEncDriver = new(msgpackEncDriver[T]) -} - -type msgpackDecDriverM[T decReader] struct { - *msgpackDecDriver[T] -} - -func (d *msgpackDecDriverM[T]) Make() { - d.msgpackDecDriver = new(msgpackDecDriver[T]) -} - -var ( - msgpackFpEncIO = helperEncDriver[msgpackEncDriverM[bufioEncWriterM]]{}.fastpathEList() - msgpackFpEncBytes = helperEncDriver[msgpackEncDriverM[bytesEncAppenderM]]{}.fastpathEList() - msgpackFpDecIO = helperDecDriver[msgpackDecDriverM[ioDecReaderM]]{}.fastpathDList() - msgpackFpDecBytes = helperDecDriver[msgpackDecDriverM[bytesDecReaderM]]{}.fastpathDList() -) - -// ---- (simple.go) - -type simpleEncDriverM[T encWriter] struct { - *simpleEncDriver[T] -} - -func (d *simpleEncDriverM[T]) Make() { - d.simpleEncDriver = new(simpleEncDriver[T]) -} - -type simpleDecDriverM[T decReader] struct { - *simpleDecDriver[T] -} - -func (d *simpleDecDriverM[T]) Make() { - d.simpleDecDriver = new(simpleDecDriver[T]) -} - -var ( - simpleFpEncIO = helperEncDriver[simpleEncDriverM[bufioEncWriterM]]{}.fastpathEList() - simpleFpEncBytes = helperEncDriver[simpleEncDriverM[bytesEncAppenderM]]{}.fastpathEList() - simpleFpDecIO = helperDecDriver[simpleDecDriverM[ioDecReaderM]]{}.fastpathDList() - simpleFpDecBytes = helperDecDriver[simpleDecDriverM[bytesDecReaderM]]{}.fastpathDList() -) - -func (h *SimpleHandle) newEncoderBytes(out *[]byte) encoderI { - return helperEncDriver[simpleEncDriverM[bytesEncAppenderM]]{}.newEncoderBytes(out, h) -} - -func (h *SimpleHandle) newEncoder(w io.Writer) encoderI { - return helperEncDriver[simpleEncDriverM[bufioEncWriterM]]{}.newEncoderIO(w, h) -} - -func (h *SimpleHandle) newDecoderBytes(in []byte) decoderI { - return helperDecDriver[simpleDecDriverM[bytesDecReaderM]]{}.newDecoderBytes(in, h) -} - -func (h *SimpleHandle) newDecoder(r io.Reader) decoderI { - return helperDecDriver[simpleDecDriverM[ioDecReaderM]]{}.newDecoderIO(r, h) -} - -func (h *JsonHandle) newEncoderBytes(out *[]byte) encoderI { - return helperEncDriver[jsonEncDriverM[bytesEncAppenderM]]{}.newEncoderBytes(out, h) -} - -func (h *JsonHandle) newEncoder(w io.Writer) encoderI { - return helperEncDriver[jsonEncDriverM[bufioEncWriterM]]{}.newEncoderIO(w, h) -} - -func (h *JsonHandle) newDecoderBytes(in []byte) decoderI { - return helperDecDriver[jsonDecDriverM[bytesDecReaderM]]{}.newDecoderBytes(in, h) -} - -func (h *JsonHandle) newDecoder(r io.Reader) decoderI { - return helperDecDriver[jsonDecDriverM[ioDecReaderM]]{}.newDecoderIO(r, h) -} - -func (h *MsgpackHandle) newEncoderBytes(out *[]byte) encoderI { - return helperEncDriver[msgpackEncDriverM[bytesEncAppenderM]]{}.newEncoderBytes(out, h) -} - -func (h *MsgpackHandle) newEncoder(w io.Writer) encoderI { - return helperEncDriver[msgpackEncDriverM[bufioEncWriterM]]{}.newEncoderIO(w, h) -} - -func (h *MsgpackHandle) newDecoderBytes(in []byte) decoderI { - return helperDecDriver[msgpackDecDriverM[bytesDecReaderM]]{}.newDecoderBytes(in, h) -} - -func (h *MsgpackHandle) newDecoder(r io.Reader) decoderI { - return helperDecDriver[msgpackDecDriverM[ioDecReaderM]]{}.newDecoderIO(r, h) -} - -func (h *CborHandle) newEncoderBytes(out *[]byte) encoderI { - return helperEncDriver[cborEncDriverM[bytesEncAppenderM]]{}.newEncoderBytes(out, h) -} - -func (h *CborHandle) newEncoder(w io.Writer) encoderI { - return helperEncDriver[cborEncDriverM[bufioEncWriterM]]{}.newEncoderIO(w, h) -} - -func (h *CborHandle) newDecoderBytes(in []byte) decoderI { - return helperDecDriver[cborDecDriverM[bytesDecReaderM]]{}.newDecoderBytes(in, h) -} - -func (h *CborHandle) newDecoder(r io.Reader) decoderI { - return helperDecDriver[cborDecDriverM[ioDecReaderM]]{}.newDecoderIO(r, h) -} - -func (h *BincHandle) newEncoderBytes(out *[]byte) encoderI { - return helperEncDriver[bincEncDriverM[bytesEncAppenderM]]{}.newEncoderBytes(out, h) -} - -func (h *BincHandle) newEncoder(w io.Writer) encoderI { - return helperEncDriver[bincEncDriverM[bufioEncWriterM]]{}.newEncoderIO(w, h) -} - -func (h *BincHandle) newDecoderBytes(in []byte) decoderI { - return helperDecDriver[bincDecDriverM[bytesDecReaderM]]{}.newDecoderBytes(in, h) -} - -func (h *BincHandle) newDecoder(r io.Reader) decoderI { - return helperDecDriver[bincDecDriverM[ioDecReaderM]]{}.newDecoderIO(r, h) -} diff --git a/vendor/github.com/ugorji/go/codec/json.base.go b/vendor/github.com/ugorji/go/codec/json.base.go deleted file mode 100644 index d87403393..000000000 --- a/vendor/github.com/ugorji/go/codec/json.base.go +++ /dev/null @@ -1,504 +0,0 @@ -// Copyright (c) 2012-2020 Ugorji Nwoke. All rights reserved. -// Use of this source code is governed by a MIT license found in the LICENSE file. - -package codec - -import ( - "encoding/base32" - "encoding/base64" - "errors" - "math" - "reflect" - "strings" - "time" - "unicode" -) - -//-------------------------------- - -// jsonLits and jsonLitb are defined at the package level, -// so they are guaranteed to be stored efficiently, making -// for better append/string comparison/etc. -// -// (anecdotal evidence from some benchmarking on go 1.20 devel in 20220104) -const jsonLits = `"true"false"null"{}[]` - -const ( - jsonLitT = 1 - jsonLitF = 6 - jsonLitN = 12 - jsonLitM = 17 - jsonLitA = 19 -) - -var jsonLitb = []byte(jsonLits) -var jsonNull = jsonLitb[jsonLitN : jsonLitN+4] -var jsonArrayEmpty = jsonLitb[jsonLitA : jsonLitA+2] -var jsonMapEmpty = jsonLitb[jsonLitM : jsonLitM+2] - -const jsonEncodeUintSmallsString = "" + - "00010203040506070809" + - "10111213141516171819" + - "20212223242526272829" + - "30313233343536373839" + - "40414243444546474849" + - "50515253545556575859" + - "60616263646566676869" + - "70717273747576777879" + - "80818283848586878889" + - "90919293949596979899" - -var jsonEncodeUintSmallsStringBytes = (*[len(jsonEncodeUintSmallsString)]byte)([]byte(jsonEncodeUintSmallsString)) - -const ( - jsonU4Chk2 = '0' - jsonU4Chk1 = 'a' - 10 - jsonU4Chk0 = 'A' - 10 -) - -const ( - // If !jsonValidateSymbols, decoding will be faster, by skipping some checks: - // - If we see first character of null, false or true, - // do not validate subsequent characters. - // - e.g. if we see a n, assume null and skip next 3 characters, - // and do not validate they are ull. - // P.S. Do not expect a significant decoding boost from this. - jsonValidateSymbols = true - - // jsonEscapeMultiByteUnicodeSep controls whether some unicode characters - // that are valid json but may bomb in some contexts are escaped during encoeing. - // - // U+2028 is LINE SEPARATOR. U+2029 is PARAGRAPH SEPARATOR. - // Both technically valid JSON, but bomb on JSONP, so fix here unconditionally. - jsonEscapeMultiByteUnicodeSep = true - - // jsonNakedBoolNumInQuotedStr is used during decoding into a blank interface{} - // to control whether we detect quoted values of bools and null where a map key is expected, - // and treat as nil, true or false. - jsonNakedBoolNumInQuotedStr = true -) - -var ( - // jsonTabs and jsonSpaces are used as caches for indents - jsonTabs [32]byte - jsonSpaces [128]byte - - jsonHexEncoder hexEncoder - // jsonTimeLayout is used to validate time layouts. - // Unfortunately, we couldn't compare time.Time effectively, so punted. - // jsonTimeLayout time.Time -) - -func init() { - for i := 0; i < len(jsonTabs); i++ { - jsonTabs[i] = '\t' - } - for i := 0; i < len(jsonSpaces); i++ { - jsonSpaces[i] = ' ' - } - // jsonTimeLayout, err := time.Parse(time.Layout, time.Layout) - // halt.onerror(err) - // jsonTimeLayout = jsonTimeLayout.Round(time.Second).UTC() -} - -// ---------------- - -type jsonBytesFmt uint8 - -const ( - jsonBytesFmtArray jsonBytesFmt = iota + 1 - jsonBytesFmtBase64 - jsonBytesFmtBase64url - jsonBytesFmtBase32 - jsonBytesFmtBase32hex - jsonBytesFmtBase16 - - jsonBytesFmtHex = jsonBytesFmtBase16 -) - -type jsonTimeFmt uint8 - -const ( - jsonTimeFmtStringLayout jsonTimeFmt = iota + 1 - jsonTimeFmtUnix - jsonTimeFmtUnixMilli - jsonTimeFmtUnixMicro - jsonTimeFmtUnixNano -) - -type jsonBytesFmter = bytesEncoder - -type jsonHandleOpts struct { - rawext bool - // bytesFmt used during encode to determine how to encode []byte - bytesFmt jsonBytesFmt - // timeFmt used during encode to determine how to encode a time.Time - timeFmt jsonTimeFmt - // timeFmtNum used during decode to decode a time.Time from an int64 in the stream - timeFmtNum jsonTimeFmt - // timeFmtLayouts used on decode, to try to parse time.Time until successful - timeFmtLayouts []string - // byteFmters used on decode, to try to parse []byte from a UTF-8 string encoding (e.g. base64) - byteFmters []jsonBytesFmter -} - -func jsonCheckTimeLayout(s string) (ok bool) { - _, err := time.Parse(s, s) - // t...Equal(jsonTimeLayout) always returns false - unsure why - // return err == nil && t.Round(time.Second).UTC().Equal(jsonTimeLayout) - return err == nil -} - -func (x *jsonHandleOpts) reset(h *JsonHandle) { - x.timeFmt = 0 - x.timeFmtNum = 0 - x.timeFmtLayouts = x.timeFmtLayouts[:0] - if len(h.TimeFormat) != 0 { - switch h.TimeFormat[0] { - case "unix": - x.timeFmt = jsonTimeFmtUnix - case "unixmilli": - x.timeFmt = jsonTimeFmtUnixMilli - case "unixmicro": - x.timeFmt = jsonTimeFmtUnixMicro - case "unixnano": - x.timeFmt = jsonTimeFmtUnixNano - } - x.timeFmtNum = x.timeFmt - for _, v := range h.TimeFormat { - if !strings.HasPrefix(v, "unix") && jsonCheckTimeLayout(v) { - x.timeFmtLayouts = append(x.timeFmtLayouts, v) - } - } - } - if x.timeFmt == 0 { // both timeFmt and timeFmtNum are 0 - x.timeFmtNum = jsonTimeFmtUnix - x.timeFmt = jsonTimeFmtStringLayout - if len(x.timeFmtLayouts) == 0 { - x.timeFmtLayouts = append(x.timeFmtLayouts, time.RFC3339Nano) - } - } - - x.bytesFmt = 0 - x.byteFmters = x.byteFmters[:0] - var b64 bool - if len(h.BytesFormat) != 0 { - switch h.BytesFormat[0] { - case "array": - x.bytesFmt = jsonBytesFmtArray - case "base64": - x.bytesFmt = jsonBytesFmtBase64 - case "base64url": - x.bytesFmt = jsonBytesFmtBase64url - case "base32": - x.bytesFmt = jsonBytesFmtBase32 - case "base32hex": - x.bytesFmt = jsonBytesFmtBase32hex - case "base16", "hex": - x.bytesFmt = jsonBytesFmtBase16 - } - for _, v := range h.BytesFormat { - switch v { - // case "array": - case "base64": - x.byteFmters = append(x.byteFmters, base64.StdEncoding) - b64 = true - case "base64url": - x.byteFmters = append(x.byteFmters, base64.URLEncoding) - case "base32": - x.byteFmters = append(x.byteFmters, base32.StdEncoding) - case "base32hex": - x.byteFmters = append(x.byteFmters, base32.HexEncoding) - case "base16", "hex": - x.byteFmters = append(x.byteFmters, &jsonHexEncoder) - } - } - } - if x.bytesFmt == 0 { - // either len==0 OR gibberish was in the first element; resolve here - x.bytesFmt = jsonBytesFmtBase64 - if !b64 { // not present - so insert into pos 0 - x.byteFmters = append(x.byteFmters, nil) - copy(x.byteFmters[1:], x.byteFmters[0:]) - x.byteFmters[0] = base64.StdEncoding - } - } - // ---- - x.rawext = h.RawBytesExt != nil -} - -var jsonEncBoolStrs = [2][2]string{ - {jsonLits[jsonLitF : jsonLitF+5], jsonLits[jsonLitT : jsonLitT+4]}, - {jsonLits[jsonLitF-1 : jsonLitF+6], jsonLits[jsonLitT-1 : jsonLitT+5]}, -} - -func jsonEncodeUint(neg, quotes bool, u uint64, b *[48]byte) []byte { - // MARKER: use setByteAt/byteAt to elide the bounds-checks - // when we are sure that we don't go beyond the bounds. - - // MARKER: copied mostly from std library: strconv/itoa.go - // this should only be called on 64bit OS. - - var ss = jsonEncodeUintSmallsStringBytes[:] - - // typically, 19 or 20 bytes sufficient for decimal encoding a uint64 - var a = b[:24] - var i = uint(len(a)) - - if quotes { - i-- - setByteAt(a, i, '"') - // a[i] = '"' - } - var is, us uint // use uint, as those fit into a register on the platform - if cpu32Bit { - for u >= 1e9 { - q := u / 1e9 - us = uint(u - q*1e9) // u % 1e9 fits into a uint - for j := 4; j > 0; j-- { - is = us % 100 * 2 - us /= 100 - i -= 2 - setByteAt(a, i+1, byteAt(ss, is+1)) - setByteAt(a, i, byteAt(ss, is)) - } - i-- - setByteAt(a, i, byteAt(ss, us*2+1)) - u = q - } - // u is now < 1e9, so is guaranteed to fit into a uint - } - us = uint(u) - for us >= 100 { - is = us % 100 * 2 - us /= 100 - i -= 2 - setByteAt(a, i+1, byteAt(ss, is+1)) - setByteAt(a, i, byteAt(ss, is)) - // a[i+1], a[i] = ss[is+1], ss[is] - } - - // us < 100 - is = us * 2 - i-- - setByteAt(a, i, byteAt(ss, is+1)) - // a[i] = ss[is+1] - if us >= 10 { - i-- - setByteAt(a, i, byteAt(ss, is)) - // a[i] = ss[is] - } - if neg { - i-- - setByteAt(a, i, '-') - // a[i] = '-' - } - if quotes { - i-- - setByteAt(a, i, '"') - // a[i] = '"' - } - return a[i:] -} - -// MARKER: checkLitErr methods to prevent the got/expect parameters from escaping - -//go:noinline -func jsonCheckLitErr3(got, expect [3]byte) { - halt.errorf("expecting %s: got %s", expect, got) -} - -//go:noinline -func jsonCheckLitErr4(got, expect [4]byte) { - halt.errorf("expecting %s: got %s", expect, got) -} - -func jsonSlashURune(cs [4]byte) (rr uint32) { - for _, c := range cs { - // best to use explicit if-else - // - not a table, etc which involve memory loads, array lookup with bounds checks, etc - if c >= '0' && c <= '9' { - rr = rr*16 + uint32(c-jsonU4Chk2) - } else if c >= 'a' && c <= 'f' { - rr = rr*16 + uint32(c-jsonU4Chk1) - } else if c >= 'A' && c <= 'F' { - rr = rr*16 + uint32(c-jsonU4Chk0) - } else { - return unicode.ReplacementChar - } - } - return -} - -func jsonNakedNum(z *fauxUnion, bs []byte, preferFloat, signedInt bool) (err error) { - // Note: jsonNakedNum is NEVER called with a zero-length []byte - if preferFloat { - z.v = valueTypeFloat - z.f, err = parseFloat64(bs) - } else { - err = parseNumber(bs, z, signedInt) - } - return -} - -//---------------------- - -// JsonHandle is a handle for JSON encoding format. -// -// Json is comprehensively supported: -// - decodes numbers into interface{} as int, uint or float64 -// based on how the number looks and some config parameters e.g. PreferFloat, SignedInt, etc. -// - decode integers from float formatted numbers e.g. 1.27e+8 -// - decode any json value (numbers, bool, etc) from quoted strings -// - configurable way to encode/decode []byte . -// by default, encodes and decodes []byte using base64 Std Encoding -// - UTF-8 support for encoding and decoding -// -// It has better performance than the json library in the standard library, -// by leveraging the performance improvements of the codec library. -// -// In addition, it doesn't read more bytes than necessary during a decode, which allows -// reading multiple values from a stream containing json and non-json content. -// For example, a user can read a json value, then a cbor value, then a msgpack value, -// all from the same stream in sequence. -// -// Note that, when decoding quoted strings, invalid UTF-8 or invalid UTF-16 surrogate pairs are -// not treated as an error. Instead, they are replaced by the Unicode replacement character U+FFFD. -// -// Note also that the float values for NaN, +Inf or -Inf are encoded as null, -// as suggested by NOTE 4 of the ECMA-262 ECMAScript Language Specification 5.1 edition. -// see http://www.ecma-international.org/publications/files/ECMA-ST/Ecma-262.pdf . -// -// Note the following behaviour differences vs std-library encoding/json package: -// - struct field names matched in case-sensitive manner -type JsonHandle struct { - textEncodingType - BasicHandle - - // Indent indicates how a value is encoded. - // - If positive, indent by that number of spaces. - // - If negative, indent by that number of tabs. - Indent int8 - - // IntegerAsString controls how integers (signed and unsigned) are encoded. - // - // Per the JSON Spec, JSON numbers are 64-bit floating point numbers. - // Consequently, integers > 2^53 cannot be represented as a JSON number without losing precision. - // This can be mitigated by configuring how to encode integers. - // - // IntegerAsString interpretes the following values: - // - if 'L', then encode integers > 2^53 as a json string. - // - if 'A', then encode all integers as a json string - // containing the exact integer representation as a decimal. - // - else encode all integers as a json number (default) - IntegerAsString byte - - // HTMLCharsAsIs controls how to encode some special characters to html: < > & - // - // By default, we encode them as \uXXX - // to prevent security holes when served from some browsers. - HTMLCharsAsIs bool - - // PreferFloat says that we will default to decoding a number as a float. - // If not set, we will examine the characters of the number and decode as an - // integer type if it doesn't have any of the characters [.eE]. - PreferFloat bool - - // TermWhitespace says that we add a whitespace character - // at the end of an encoding. - // - // The whitespace is important, especially if using numbers in a context - // where multiple items are written to a stream. - TermWhitespace bool - - // MapKeyAsString says to encode all map keys as strings. - // - // Use this to enforce strict json output. - // The only caveat is that nil value is ALWAYS written as null (never as "null") - MapKeyAsString bool - - // _ uint64 // padding (cache line) - - // Note: below, we store hardly-used items e.g. RawBytesExt. - // These values below may straddle a cache line, but they are hardly-used, - // so shouldn't contribute to false-sharing except in rare cases. - - // RawBytesExt, if configured, is used to encode and decode raw bytes in a custom way. - // If not configured, raw bytes are encoded to/from base64 text. - RawBytesExt InterfaceExt - - // TimeFormat is an array of strings representing a time.Time format, with each one being either - // a layout that honor the time.Time.Format specification. - // In addition, at most one of the set below (unix, unixmilli, unixmicro, unixnana) can be specified - // supporting encoding and decoding time as a number relative to the time epoch of Jan 1, 1970. - // - // During encode of a time.Time, the first entry in the array is used (defaults to RFC 3339). - // - // During decode, - // - if a string, then each of the layout formats will be tried in order until a time.Time is decoded. - // - if a number, then the sole unix entry is used. - TimeFormat []string - - // BytesFormat is an array of strings representing how bytes are encoded. - // - // Supported values are base64 (default), base64url, base32, base32hex, base16 (synonymous with hex) and array. - // - // array is a special value configuring that bytes are encoded as a sequence of numbers. - // - // During encode of a []byte, the first entry is used (defaults to base64 if none specified). - // - // During decode - // - if a string, then attempt decoding using each format in sequence until successful. - // - if an array, then decode normally - BytesFormat []string -} - -func (h *JsonHandle) isJson() bool { return true } - -// Name returns the name of the handle: json -func (h *JsonHandle) Name() string { return "json" } - -// func (h *JsonHandle) desc(bd byte) string { return str4byte(bd) } -func (h *JsonHandle) desc(bd byte) string { return string(bd) } - -func (h *JsonHandle) typical() bool { - return h.Indent == 0 && !h.MapKeyAsString && h.IntegerAsString != 'A' && h.IntegerAsString != 'L' -} - -// SetInterfaceExt sets an extension -func (h *JsonHandle) SetInterfaceExt(rt reflect.Type, tag uint64, ext InterfaceExt) (err error) { - return h.SetExt(rt, tag, makeExt(ext)) -} - -func jsonFloatStrconvFmtPrec64(f float64) (fmt byte, prec int8) { - fmt = 'f' - prec = -1 - fbits := math.Float64bits(f) - abs := math.Float64frombits(fbits &^ (1 << 63)) - if abs == 0 || abs == 1 { - prec = 1 - } else if abs < 1e-6 || abs >= 1e21 { - fmt = 'e' - } else if noFrac64(fbits) { - prec = 1 - } - return -} - -func jsonFloatStrconvFmtPrec32(f float32) (fmt byte, prec int8) { - fmt = 'f' - prec = -1 - // directly handle Modf (to get fractions) and Abs (to get absolute) - fbits := math.Float32bits(f) - abs := math.Float32frombits(fbits &^ (1 << 31)) - if abs == 0 || abs == 1 { - prec = 1 - } else if abs < 1e-6 || abs >= 1e21 { - fmt = 'e' - } else if noFrac32(fbits) { - prec = 1 - } - return -} - -var errJsonNoBd = errors.New("descBd unsupported in json") diff --git a/vendor/github.com/ugorji/go/codec/json.fastpath.mono.generated.go b/vendor/github.com/ugorji/go/codec/json.fastpath.mono.generated.go deleted file mode 100644 index b873b0aef..000000000 --- a/vendor/github.com/ugorji/go/codec/json.fastpath.mono.generated.go +++ /dev/null @@ -1,12482 +0,0 @@ -//go:build !notmono && !codec.notmono && !notfastpath && !codec.notfastpath - -// Copyright (c) 2012-2020 Ugorji Nwoke. All rights reserved. -// Use of this source code is governed by a MIT license found in the LICENSE file. - -package codec - -import ( - "reflect" - "slices" - "sort" -) - -type fastpathEJsonBytes struct { - rtid uintptr - rt reflect.Type - encfn func(*encoderJsonBytes, *encFnInfo, reflect.Value) -} -type fastpathDJsonBytes struct { - rtid uintptr - rt reflect.Type - decfn func(*decoderJsonBytes, *decFnInfo, reflect.Value) -} -type fastpathEsJsonBytes [56]fastpathEJsonBytes -type fastpathDsJsonBytes [56]fastpathDJsonBytes -type fastpathETJsonBytes struct{} -type fastpathDTJsonBytes struct{} - -func (helperEncDriverJsonBytes) fastpathEList() *fastpathEsJsonBytes { - var i uint = 0 - var s fastpathEsJsonBytes - fn := func(v interface{}, fe func(*encoderJsonBytes, *encFnInfo, reflect.Value)) { - xrt := reflect.TypeOf(v) - s[i] = fastpathEJsonBytes{rt2id(xrt), xrt, fe} - i++ - } - - fn([]interface{}(nil), (*encoderJsonBytes).fastpathEncSliceIntfR) - fn([]string(nil), (*encoderJsonBytes).fastpathEncSliceStringR) - fn([][]byte(nil), (*encoderJsonBytes).fastpathEncSliceBytesR) - fn([]float32(nil), (*encoderJsonBytes).fastpathEncSliceFloat32R) - fn([]float64(nil), (*encoderJsonBytes).fastpathEncSliceFloat64R) - fn([]uint8(nil), (*encoderJsonBytes).fastpathEncSliceUint8R) - fn([]uint64(nil), (*encoderJsonBytes).fastpathEncSliceUint64R) - fn([]int(nil), (*encoderJsonBytes).fastpathEncSliceIntR) - fn([]int32(nil), (*encoderJsonBytes).fastpathEncSliceInt32R) - fn([]int64(nil), (*encoderJsonBytes).fastpathEncSliceInt64R) - fn([]bool(nil), (*encoderJsonBytes).fastpathEncSliceBoolR) - - fn(map[string]interface{}(nil), (*encoderJsonBytes).fastpathEncMapStringIntfR) - fn(map[string]string(nil), (*encoderJsonBytes).fastpathEncMapStringStringR) - fn(map[string][]byte(nil), (*encoderJsonBytes).fastpathEncMapStringBytesR) - fn(map[string]uint8(nil), (*encoderJsonBytes).fastpathEncMapStringUint8R) - fn(map[string]uint64(nil), (*encoderJsonBytes).fastpathEncMapStringUint64R) - fn(map[string]int(nil), (*encoderJsonBytes).fastpathEncMapStringIntR) - fn(map[string]int32(nil), (*encoderJsonBytes).fastpathEncMapStringInt32R) - fn(map[string]float64(nil), (*encoderJsonBytes).fastpathEncMapStringFloat64R) - fn(map[string]bool(nil), (*encoderJsonBytes).fastpathEncMapStringBoolR) - fn(map[uint8]interface{}(nil), (*encoderJsonBytes).fastpathEncMapUint8IntfR) - fn(map[uint8]string(nil), (*encoderJsonBytes).fastpathEncMapUint8StringR) - fn(map[uint8][]byte(nil), (*encoderJsonBytes).fastpathEncMapUint8BytesR) - fn(map[uint8]uint8(nil), (*encoderJsonBytes).fastpathEncMapUint8Uint8R) - fn(map[uint8]uint64(nil), (*encoderJsonBytes).fastpathEncMapUint8Uint64R) - fn(map[uint8]int(nil), (*encoderJsonBytes).fastpathEncMapUint8IntR) - fn(map[uint8]int32(nil), (*encoderJsonBytes).fastpathEncMapUint8Int32R) - fn(map[uint8]float64(nil), (*encoderJsonBytes).fastpathEncMapUint8Float64R) - fn(map[uint8]bool(nil), (*encoderJsonBytes).fastpathEncMapUint8BoolR) - fn(map[uint64]interface{}(nil), (*encoderJsonBytes).fastpathEncMapUint64IntfR) - fn(map[uint64]string(nil), (*encoderJsonBytes).fastpathEncMapUint64StringR) - fn(map[uint64][]byte(nil), (*encoderJsonBytes).fastpathEncMapUint64BytesR) - fn(map[uint64]uint8(nil), (*encoderJsonBytes).fastpathEncMapUint64Uint8R) - fn(map[uint64]uint64(nil), (*encoderJsonBytes).fastpathEncMapUint64Uint64R) - fn(map[uint64]int(nil), (*encoderJsonBytes).fastpathEncMapUint64IntR) - fn(map[uint64]int32(nil), (*encoderJsonBytes).fastpathEncMapUint64Int32R) - fn(map[uint64]float64(nil), (*encoderJsonBytes).fastpathEncMapUint64Float64R) - fn(map[uint64]bool(nil), (*encoderJsonBytes).fastpathEncMapUint64BoolR) - fn(map[int]interface{}(nil), (*encoderJsonBytes).fastpathEncMapIntIntfR) - fn(map[int]string(nil), (*encoderJsonBytes).fastpathEncMapIntStringR) - fn(map[int][]byte(nil), (*encoderJsonBytes).fastpathEncMapIntBytesR) - fn(map[int]uint8(nil), (*encoderJsonBytes).fastpathEncMapIntUint8R) - fn(map[int]uint64(nil), (*encoderJsonBytes).fastpathEncMapIntUint64R) - fn(map[int]int(nil), (*encoderJsonBytes).fastpathEncMapIntIntR) - fn(map[int]int32(nil), (*encoderJsonBytes).fastpathEncMapIntInt32R) - fn(map[int]float64(nil), (*encoderJsonBytes).fastpathEncMapIntFloat64R) - fn(map[int]bool(nil), (*encoderJsonBytes).fastpathEncMapIntBoolR) - fn(map[int32]interface{}(nil), (*encoderJsonBytes).fastpathEncMapInt32IntfR) - fn(map[int32]string(nil), (*encoderJsonBytes).fastpathEncMapInt32StringR) - fn(map[int32][]byte(nil), (*encoderJsonBytes).fastpathEncMapInt32BytesR) - fn(map[int32]uint8(nil), (*encoderJsonBytes).fastpathEncMapInt32Uint8R) - fn(map[int32]uint64(nil), (*encoderJsonBytes).fastpathEncMapInt32Uint64R) - fn(map[int32]int(nil), (*encoderJsonBytes).fastpathEncMapInt32IntR) - fn(map[int32]int32(nil), (*encoderJsonBytes).fastpathEncMapInt32Int32R) - fn(map[int32]float64(nil), (*encoderJsonBytes).fastpathEncMapInt32Float64R) - fn(map[int32]bool(nil), (*encoderJsonBytes).fastpathEncMapInt32BoolR) - - sort.Slice(s[:], func(i, j int) bool { return s[i].rtid < s[j].rtid }) - return &s -} - -func (helperDecDriverJsonBytes) fastpathDList() *fastpathDsJsonBytes { - var i uint = 0 - var s fastpathDsJsonBytes - fn := func(v interface{}, fd func(*decoderJsonBytes, *decFnInfo, reflect.Value)) { - xrt := reflect.TypeOf(v) - s[i] = fastpathDJsonBytes{rt2id(xrt), xrt, fd} - i++ - } - - fn([]interface{}(nil), (*decoderJsonBytes).fastpathDecSliceIntfR) - fn([]string(nil), (*decoderJsonBytes).fastpathDecSliceStringR) - fn([][]byte(nil), (*decoderJsonBytes).fastpathDecSliceBytesR) - fn([]float32(nil), (*decoderJsonBytes).fastpathDecSliceFloat32R) - fn([]float64(nil), (*decoderJsonBytes).fastpathDecSliceFloat64R) - fn([]uint8(nil), (*decoderJsonBytes).fastpathDecSliceUint8R) - fn([]uint64(nil), (*decoderJsonBytes).fastpathDecSliceUint64R) - fn([]int(nil), (*decoderJsonBytes).fastpathDecSliceIntR) - fn([]int32(nil), (*decoderJsonBytes).fastpathDecSliceInt32R) - fn([]int64(nil), (*decoderJsonBytes).fastpathDecSliceInt64R) - fn([]bool(nil), (*decoderJsonBytes).fastpathDecSliceBoolR) - - fn(map[string]interface{}(nil), (*decoderJsonBytes).fastpathDecMapStringIntfR) - fn(map[string]string(nil), (*decoderJsonBytes).fastpathDecMapStringStringR) - fn(map[string][]byte(nil), (*decoderJsonBytes).fastpathDecMapStringBytesR) - fn(map[string]uint8(nil), (*decoderJsonBytes).fastpathDecMapStringUint8R) - fn(map[string]uint64(nil), (*decoderJsonBytes).fastpathDecMapStringUint64R) - fn(map[string]int(nil), (*decoderJsonBytes).fastpathDecMapStringIntR) - fn(map[string]int32(nil), (*decoderJsonBytes).fastpathDecMapStringInt32R) - fn(map[string]float64(nil), (*decoderJsonBytes).fastpathDecMapStringFloat64R) - fn(map[string]bool(nil), (*decoderJsonBytes).fastpathDecMapStringBoolR) - fn(map[uint8]interface{}(nil), (*decoderJsonBytes).fastpathDecMapUint8IntfR) - fn(map[uint8]string(nil), (*decoderJsonBytes).fastpathDecMapUint8StringR) - fn(map[uint8][]byte(nil), (*decoderJsonBytes).fastpathDecMapUint8BytesR) - fn(map[uint8]uint8(nil), (*decoderJsonBytes).fastpathDecMapUint8Uint8R) - fn(map[uint8]uint64(nil), (*decoderJsonBytes).fastpathDecMapUint8Uint64R) - fn(map[uint8]int(nil), (*decoderJsonBytes).fastpathDecMapUint8IntR) - fn(map[uint8]int32(nil), (*decoderJsonBytes).fastpathDecMapUint8Int32R) - fn(map[uint8]float64(nil), (*decoderJsonBytes).fastpathDecMapUint8Float64R) - fn(map[uint8]bool(nil), (*decoderJsonBytes).fastpathDecMapUint8BoolR) - fn(map[uint64]interface{}(nil), (*decoderJsonBytes).fastpathDecMapUint64IntfR) - fn(map[uint64]string(nil), (*decoderJsonBytes).fastpathDecMapUint64StringR) - fn(map[uint64][]byte(nil), (*decoderJsonBytes).fastpathDecMapUint64BytesR) - fn(map[uint64]uint8(nil), (*decoderJsonBytes).fastpathDecMapUint64Uint8R) - fn(map[uint64]uint64(nil), (*decoderJsonBytes).fastpathDecMapUint64Uint64R) - fn(map[uint64]int(nil), (*decoderJsonBytes).fastpathDecMapUint64IntR) - fn(map[uint64]int32(nil), (*decoderJsonBytes).fastpathDecMapUint64Int32R) - fn(map[uint64]float64(nil), (*decoderJsonBytes).fastpathDecMapUint64Float64R) - fn(map[uint64]bool(nil), (*decoderJsonBytes).fastpathDecMapUint64BoolR) - fn(map[int]interface{}(nil), (*decoderJsonBytes).fastpathDecMapIntIntfR) - fn(map[int]string(nil), (*decoderJsonBytes).fastpathDecMapIntStringR) - fn(map[int][]byte(nil), (*decoderJsonBytes).fastpathDecMapIntBytesR) - fn(map[int]uint8(nil), (*decoderJsonBytes).fastpathDecMapIntUint8R) - fn(map[int]uint64(nil), (*decoderJsonBytes).fastpathDecMapIntUint64R) - fn(map[int]int(nil), (*decoderJsonBytes).fastpathDecMapIntIntR) - fn(map[int]int32(nil), (*decoderJsonBytes).fastpathDecMapIntInt32R) - fn(map[int]float64(nil), (*decoderJsonBytes).fastpathDecMapIntFloat64R) - fn(map[int]bool(nil), (*decoderJsonBytes).fastpathDecMapIntBoolR) - fn(map[int32]interface{}(nil), (*decoderJsonBytes).fastpathDecMapInt32IntfR) - fn(map[int32]string(nil), (*decoderJsonBytes).fastpathDecMapInt32StringR) - fn(map[int32][]byte(nil), (*decoderJsonBytes).fastpathDecMapInt32BytesR) - fn(map[int32]uint8(nil), (*decoderJsonBytes).fastpathDecMapInt32Uint8R) - fn(map[int32]uint64(nil), (*decoderJsonBytes).fastpathDecMapInt32Uint64R) - fn(map[int32]int(nil), (*decoderJsonBytes).fastpathDecMapInt32IntR) - fn(map[int32]int32(nil), (*decoderJsonBytes).fastpathDecMapInt32Int32R) - fn(map[int32]float64(nil), (*decoderJsonBytes).fastpathDecMapInt32Float64R) - fn(map[int32]bool(nil), (*decoderJsonBytes).fastpathDecMapInt32BoolR) - - sort.Slice(s[:], func(i, j int) bool { return s[i].rtid < s[j].rtid }) - return &s -} - -func (helperEncDriverJsonBytes) fastpathEncodeTypeSwitch(iv interface{}, e *encoderJsonBytes) bool { - var ft fastpathETJsonBytes - switch v := iv.(type) { - case []interface{}: - if v == nil { - e.e.writeNilArray() - } else { - ft.EncSliceIntfV(v, e) - } - case []string: - if v == nil { - e.e.writeNilArray() - } else { - ft.EncSliceStringV(v, e) - } - case [][]byte: - if v == nil { - e.e.writeNilArray() - } else { - ft.EncSliceBytesV(v, e) - } - case []float32: - if v == nil { - e.e.writeNilArray() - } else { - ft.EncSliceFloat32V(v, e) - } - case []float64: - if v == nil { - e.e.writeNilArray() - } else { - ft.EncSliceFloat64V(v, e) - } - case []uint8: - if v == nil { - e.e.writeNilArray() - } else { - ft.EncSliceUint8V(v, e) - } - case []uint64: - if v == nil { - e.e.writeNilArray() - } else { - ft.EncSliceUint64V(v, e) - } - case []int: - if v == nil { - e.e.writeNilArray() - } else { - ft.EncSliceIntV(v, e) - } - case []int32: - if v == nil { - e.e.writeNilArray() - } else { - ft.EncSliceInt32V(v, e) - } - case []int64: - if v == nil { - e.e.writeNilArray() - } else { - ft.EncSliceInt64V(v, e) - } - case []bool: - if v == nil { - e.e.writeNilArray() - } else { - ft.EncSliceBoolV(v, e) - } - case map[string]interface{}: - if v == nil { - e.e.writeNilMap() - } else { - ft.EncMapStringIntfV(v, e) - } - case map[string]string: - if v == nil { - e.e.writeNilMap() - } else { - ft.EncMapStringStringV(v, e) - } - case map[string][]byte: - if v == nil { - e.e.writeNilMap() - } else { - ft.EncMapStringBytesV(v, e) - } - case map[string]uint8: - if v == nil { - e.e.writeNilMap() - } else { - ft.EncMapStringUint8V(v, e) - } - case map[string]uint64: - if v == nil { - e.e.writeNilMap() - } else { - ft.EncMapStringUint64V(v, e) - } - case map[string]int: - if v == nil { - e.e.writeNilMap() - } else { - ft.EncMapStringIntV(v, e) - } - case map[string]int32: - if v == nil { - e.e.writeNilMap() - } else { - ft.EncMapStringInt32V(v, e) - } - case map[string]float64: - if v == nil { - e.e.writeNilMap() - } else { - ft.EncMapStringFloat64V(v, e) - } - case map[string]bool: - if v == nil { - e.e.writeNilMap() - } else { - ft.EncMapStringBoolV(v, e) - } - case map[uint8]interface{}: - if v == nil { - e.e.writeNilMap() - } else { - ft.EncMapUint8IntfV(v, e) - } - case map[uint8]string: - if v == nil { - e.e.writeNilMap() - } else { - ft.EncMapUint8StringV(v, e) - } - case map[uint8][]byte: - if v == nil { - e.e.writeNilMap() - } else { - ft.EncMapUint8BytesV(v, e) - } - case map[uint8]uint8: - if v == nil { - e.e.writeNilMap() - } else { - ft.EncMapUint8Uint8V(v, e) - } - case map[uint8]uint64: - if v == nil { - e.e.writeNilMap() - } else { - ft.EncMapUint8Uint64V(v, e) - } - case map[uint8]int: - if v == nil { - e.e.writeNilMap() - } else { - ft.EncMapUint8IntV(v, e) - } - case map[uint8]int32: - if v == nil { - e.e.writeNilMap() - } else { - ft.EncMapUint8Int32V(v, e) - } - case map[uint8]float64: - if v == nil { - e.e.writeNilMap() - } else { - ft.EncMapUint8Float64V(v, e) - } - case map[uint8]bool: - if v == nil { - e.e.writeNilMap() - } else { - ft.EncMapUint8BoolV(v, e) - } - case map[uint64]interface{}: - if v == nil { - e.e.writeNilMap() - } else { - ft.EncMapUint64IntfV(v, e) - } - case map[uint64]string: - if v == nil { - e.e.writeNilMap() - } else { - ft.EncMapUint64StringV(v, e) - } - case map[uint64][]byte: - if v == nil { - e.e.writeNilMap() - } else { - ft.EncMapUint64BytesV(v, e) - } - case map[uint64]uint8: - if v == nil { - e.e.writeNilMap() - } else { - ft.EncMapUint64Uint8V(v, e) - } - case map[uint64]uint64: - if v == nil { - e.e.writeNilMap() - } else { - ft.EncMapUint64Uint64V(v, e) - } - case map[uint64]int: - if v == nil { - e.e.writeNilMap() - } else { - ft.EncMapUint64IntV(v, e) - } - case map[uint64]int32: - if v == nil { - e.e.writeNilMap() - } else { - ft.EncMapUint64Int32V(v, e) - } - case map[uint64]float64: - if v == nil { - e.e.writeNilMap() - } else { - ft.EncMapUint64Float64V(v, e) - } - case map[uint64]bool: - if v == nil { - e.e.writeNilMap() - } else { - ft.EncMapUint64BoolV(v, e) - } - case map[int]interface{}: - if v == nil { - e.e.writeNilMap() - } else { - ft.EncMapIntIntfV(v, e) - } - case map[int]string: - if v == nil { - e.e.writeNilMap() - } else { - ft.EncMapIntStringV(v, e) - } - case map[int][]byte: - if v == nil { - e.e.writeNilMap() - } else { - ft.EncMapIntBytesV(v, e) - } - case map[int]uint8: - if v == nil { - e.e.writeNilMap() - } else { - ft.EncMapIntUint8V(v, e) - } - case map[int]uint64: - if v == nil { - e.e.writeNilMap() - } else { - ft.EncMapIntUint64V(v, e) - } - case map[int]int: - if v == nil { - e.e.writeNilMap() - } else { - ft.EncMapIntIntV(v, e) - } - case map[int]int32: - if v == nil { - e.e.writeNilMap() - } else { - ft.EncMapIntInt32V(v, e) - } - case map[int]float64: - if v == nil { - e.e.writeNilMap() - } else { - ft.EncMapIntFloat64V(v, e) - } - case map[int]bool: - if v == nil { - e.e.writeNilMap() - } else { - ft.EncMapIntBoolV(v, e) - } - case map[int32]interface{}: - if v == nil { - e.e.writeNilMap() - } else { - ft.EncMapInt32IntfV(v, e) - } - case map[int32]string: - if v == nil { - e.e.writeNilMap() - } else { - ft.EncMapInt32StringV(v, e) - } - case map[int32][]byte: - if v == nil { - e.e.writeNilMap() - } else { - ft.EncMapInt32BytesV(v, e) - } - case map[int32]uint8: - if v == nil { - e.e.writeNilMap() - } else { - ft.EncMapInt32Uint8V(v, e) - } - case map[int32]uint64: - if v == nil { - e.e.writeNilMap() - } else { - ft.EncMapInt32Uint64V(v, e) - } - case map[int32]int: - if v == nil { - e.e.writeNilMap() - } else { - ft.EncMapInt32IntV(v, e) - } - case map[int32]int32: - if v == nil { - e.e.writeNilMap() - } else { - ft.EncMapInt32Int32V(v, e) - } - case map[int32]float64: - if v == nil { - e.e.writeNilMap() - } else { - ft.EncMapInt32Float64V(v, e) - } - case map[int32]bool: - if v == nil { - e.e.writeNilMap() - } else { - ft.EncMapInt32BoolV(v, e) - } - default: - _ = v - return false - } - return true -} - -func (e *encoderJsonBytes) fastpathEncSliceIntfR(f *encFnInfo, rv reflect.Value) { - var ft fastpathETJsonBytes - var v []interface{} - if rv.Kind() == reflect.Array { - rvGetSlice4Array(rv, &v) - } else { - v = rv2i(rv).([]interface{}) - } - if f.ti.mbs { - ft.EncAsMapSliceIntfV(v, e) - return - } - ft.EncSliceIntfV(v, e) -} -func (fastpathETJsonBytes) EncSliceIntfV(v []interface{}, e *encoderJsonBytes) { - if len(v) == 0 { - e.c = 0 - e.e.WriteArrayEmpty() - return - } - e.arrayStart(len(v)) - for j := range v { - e.c = containerArrayElem - e.e.WriteArrayElem(j == 0) - if !e.encodeBuiltin(v[j]) { - e.encodeR(reflect.ValueOf(v[j])) - } - } - e.c = 0 - e.e.WriteArrayEnd() -} -func (fastpathETJsonBytes) EncAsMapSliceIntfV(v []interface{}, e *encoderJsonBytes) { - if len(v) == 0 { - e.c = 0 - e.e.WriteMapEmpty() - return - } - e.haltOnMbsOddLen(len(v)) - e.mapStart(len(v) >> 1) - for j := range v { - if j&1 == 0 { - e.c = containerMapKey - e.e.WriteMapElemKey(j == 0) - } else { - e.mapElemValue() - } - if !e.encodeBuiltin(v[j]) { - e.encodeR(reflect.ValueOf(v[j])) - } - } - e.c = 0 - e.e.WriteMapEnd() -} - -func (e *encoderJsonBytes) fastpathEncSliceStringR(f *encFnInfo, rv reflect.Value) { - var ft fastpathETJsonBytes - var v []string - if rv.Kind() == reflect.Array { - rvGetSlice4Array(rv, &v) - } else { - v = rv2i(rv).([]string) - } - if f.ti.mbs { - ft.EncAsMapSliceStringV(v, e) - return - } - ft.EncSliceStringV(v, e) -} -func (fastpathETJsonBytes) EncSliceStringV(v []string, e *encoderJsonBytes) { - if len(v) == 0 { - e.c = 0 - e.e.WriteArrayEmpty() - return - } - e.arrayStart(len(v)) - for j := range v { - e.c = containerArrayElem - e.e.WriteArrayElem(j == 0) - e.e.EncodeString(v[j]) - } - e.c = 0 - e.e.WriteArrayEnd() -} -func (fastpathETJsonBytes) EncAsMapSliceStringV(v []string, e *encoderJsonBytes) { - if len(v) == 0 { - e.c = 0 - e.e.WriteMapEmpty() - return - } - e.haltOnMbsOddLen(len(v)) - e.mapStart(len(v) >> 1) - for j := range v { - if j&1 == 0 { - e.c = containerMapKey - e.e.WriteMapElemKey(j == 0) - } else { - e.mapElemValue() - } - e.e.EncodeString(v[j]) - } - e.c = 0 - e.e.WriteMapEnd() -} - -func (e *encoderJsonBytes) fastpathEncSliceBytesR(f *encFnInfo, rv reflect.Value) { - var ft fastpathETJsonBytes - var v [][]byte - if rv.Kind() == reflect.Array { - rvGetSlice4Array(rv, &v) - } else { - v = rv2i(rv).([][]byte) - } - if f.ti.mbs { - ft.EncAsMapSliceBytesV(v, e) - return - } - ft.EncSliceBytesV(v, e) -} -func (fastpathETJsonBytes) EncSliceBytesV(v [][]byte, e *encoderJsonBytes) { - if len(v) == 0 { - e.c = 0 - e.e.WriteArrayEmpty() - return - } - e.arrayStart(len(v)) - for j := range v { - e.c = containerArrayElem - e.e.WriteArrayElem(j == 0) - e.e.EncodeBytes(v[j]) - } - e.c = 0 - e.e.WriteArrayEnd() -} -func (fastpathETJsonBytes) EncAsMapSliceBytesV(v [][]byte, e *encoderJsonBytes) { - if len(v) == 0 { - e.c = 0 - e.e.WriteMapEmpty() - return - } - e.haltOnMbsOddLen(len(v)) - e.mapStart(len(v) >> 1) - for j := range v { - if j&1 == 0 { - e.c = containerMapKey - e.e.WriteMapElemKey(j == 0) - } else { - e.mapElemValue() - } - e.e.EncodeBytes(v[j]) - } - e.c = 0 - e.e.WriteMapEnd() -} - -func (e *encoderJsonBytes) fastpathEncSliceFloat32R(f *encFnInfo, rv reflect.Value) { - var ft fastpathETJsonBytes - var v []float32 - if rv.Kind() == reflect.Array { - rvGetSlice4Array(rv, &v) - } else { - v = rv2i(rv).([]float32) - } - if f.ti.mbs { - ft.EncAsMapSliceFloat32V(v, e) - return - } - ft.EncSliceFloat32V(v, e) -} -func (fastpathETJsonBytes) EncSliceFloat32V(v []float32, e *encoderJsonBytes) { - if len(v) == 0 { - e.c = 0 - e.e.WriteArrayEmpty() - return - } - e.arrayStart(len(v)) - for j := range v { - e.c = containerArrayElem - e.e.WriteArrayElem(j == 0) - e.e.EncodeFloat32(v[j]) - } - e.c = 0 - e.e.WriteArrayEnd() -} -func (fastpathETJsonBytes) EncAsMapSliceFloat32V(v []float32, e *encoderJsonBytes) { - if len(v) == 0 { - e.c = 0 - e.e.WriteMapEmpty() - return - } - e.haltOnMbsOddLen(len(v)) - e.mapStart(len(v) >> 1) - for j := range v { - if j&1 == 0 { - e.c = containerMapKey - e.e.WriteMapElemKey(j == 0) - } else { - e.mapElemValue() - } - e.e.EncodeFloat32(v[j]) - } - e.c = 0 - e.e.WriteMapEnd() -} - -func (e *encoderJsonBytes) fastpathEncSliceFloat64R(f *encFnInfo, rv reflect.Value) { - var ft fastpathETJsonBytes - var v []float64 - if rv.Kind() == reflect.Array { - rvGetSlice4Array(rv, &v) - } else { - v = rv2i(rv).([]float64) - } - if f.ti.mbs { - ft.EncAsMapSliceFloat64V(v, e) - return - } - ft.EncSliceFloat64V(v, e) -} -func (fastpathETJsonBytes) EncSliceFloat64V(v []float64, e *encoderJsonBytes) { - if len(v) == 0 { - e.c = 0 - e.e.WriteArrayEmpty() - return - } - e.arrayStart(len(v)) - for j := range v { - e.c = containerArrayElem - e.e.WriteArrayElem(j == 0) - e.e.EncodeFloat64(v[j]) - } - e.c = 0 - e.e.WriteArrayEnd() -} -func (fastpathETJsonBytes) EncAsMapSliceFloat64V(v []float64, e *encoderJsonBytes) { - if len(v) == 0 { - e.c = 0 - e.e.WriteMapEmpty() - return - } - e.haltOnMbsOddLen(len(v)) - e.mapStart(len(v) >> 1) - for j := range v { - if j&1 == 0 { - e.c = containerMapKey - e.e.WriteMapElemKey(j == 0) - } else { - e.mapElemValue() - } - e.e.EncodeFloat64(v[j]) - } - e.c = 0 - e.e.WriteMapEnd() -} - -func (e *encoderJsonBytes) fastpathEncSliceUint8R(f *encFnInfo, rv reflect.Value) { - var ft fastpathETJsonBytes - var v []uint8 - if rv.Kind() == reflect.Array { - rvGetSlice4Array(rv, &v) - } else { - v = rv2i(rv).([]uint8) - } - if f.ti.mbs { - ft.EncAsMapSliceUint8V(v, e) - return - } - ft.EncSliceUint8V(v, e) -} -func (fastpathETJsonBytes) EncSliceUint8V(v []uint8, e *encoderJsonBytes) { - e.e.EncodeStringBytesRaw(v) -} -func (fastpathETJsonBytes) EncAsMapSliceUint8V(v []uint8, e *encoderJsonBytes) { - if len(v) == 0 { - e.c = 0 - e.e.WriteMapEmpty() - return - } - e.haltOnMbsOddLen(len(v)) - e.mapStart(len(v) >> 1) - for j := range v { - if j&1 == 0 { - e.c = containerMapKey - e.e.WriteMapElemKey(j == 0) - } else { - e.mapElemValue() - } - e.e.EncodeUint(uint64(v[j])) - } - e.c = 0 - e.e.WriteMapEnd() -} - -func (e *encoderJsonBytes) fastpathEncSliceUint64R(f *encFnInfo, rv reflect.Value) { - var ft fastpathETJsonBytes - var v []uint64 - if rv.Kind() == reflect.Array { - rvGetSlice4Array(rv, &v) - } else { - v = rv2i(rv).([]uint64) - } - if f.ti.mbs { - ft.EncAsMapSliceUint64V(v, e) - return - } - ft.EncSliceUint64V(v, e) -} -func (fastpathETJsonBytes) EncSliceUint64V(v []uint64, e *encoderJsonBytes) { - if len(v) == 0 { - e.c = 0 - e.e.WriteArrayEmpty() - return - } - e.arrayStart(len(v)) - for j := range v { - e.c = containerArrayElem - e.e.WriteArrayElem(j == 0) - e.e.EncodeUint(v[j]) - } - e.c = 0 - e.e.WriteArrayEnd() -} -func (fastpathETJsonBytes) EncAsMapSliceUint64V(v []uint64, e *encoderJsonBytes) { - if len(v) == 0 { - e.c = 0 - e.e.WriteMapEmpty() - return - } - e.haltOnMbsOddLen(len(v)) - e.mapStart(len(v) >> 1) - for j := range v { - if j&1 == 0 { - e.c = containerMapKey - e.e.WriteMapElemKey(j == 0) - } else { - e.mapElemValue() - } - e.e.EncodeUint(v[j]) - } - e.c = 0 - e.e.WriteMapEnd() -} - -func (e *encoderJsonBytes) fastpathEncSliceIntR(f *encFnInfo, rv reflect.Value) { - var ft fastpathETJsonBytes - var v []int - if rv.Kind() == reflect.Array { - rvGetSlice4Array(rv, &v) - } else { - v = rv2i(rv).([]int) - } - if f.ti.mbs { - ft.EncAsMapSliceIntV(v, e) - return - } - ft.EncSliceIntV(v, e) -} -func (fastpathETJsonBytes) EncSliceIntV(v []int, e *encoderJsonBytes) { - if len(v) == 0 { - e.c = 0 - e.e.WriteArrayEmpty() - return - } - e.arrayStart(len(v)) - for j := range v { - e.c = containerArrayElem - e.e.WriteArrayElem(j == 0) - e.e.EncodeInt(int64(v[j])) - } - e.c = 0 - e.e.WriteArrayEnd() -} -func (fastpathETJsonBytes) EncAsMapSliceIntV(v []int, e *encoderJsonBytes) { - if len(v) == 0 { - e.c = 0 - e.e.WriteMapEmpty() - return - } - e.haltOnMbsOddLen(len(v)) - e.mapStart(len(v) >> 1) - for j := range v { - if j&1 == 0 { - e.c = containerMapKey - e.e.WriteMapElemKey(j == 0) - } else { - e.mapElemValue() - } - e.e.EncodeInt(int64(v[j])) - } - e.c = 0 - e.e.WriteMapEnd() -} - -func (e *encoderJsonBytes) fastpathEncSliceInt32R(f *encFnInfo, rv reflect.Value) { - var ft fastpathETJsonBytes - var v []int32 - if rv.Kind() == reflect.Array { - rvGetSlice4Array(rv, &v) - } else { - v = rv2i(rv).([]int32) - } - if f.ti.mbs { - ft.EncAsMapSliceInt32V(v, e) - return - } - ft.EncSliceInt32V(v, e) -} -func (fastpathETJsonBytes) EncSliceInt32V(v []int32, e *encoderJsonBytes) { - if len(v) == 0 { - e.c = 0 - e.e.WriteArrayEmpty() - return - } - e.arrayStart(len(v)) - for j := range v { - e.c = containerArrayElem - e.e.WriteArrayElem(j == 0) - e.e.EncodeInt(int64(v[j])) - } - e.c = 0 - e.e.WriteArrayEnd() -} -func (fastpathETJsonBytes) EncAsMapSliceInt32V(v []int32, e *encoderJsonBytes) { - if len(v) == 0 { - e.c = 0 - e.e.WriteMapEmpty() - return - } - e.haltOnMbsOddLen(len(v)) - e.mapStart(len(v) >> 1) - for j := range v { - if j&1 == 0 { - e.c = containerMapKey - e.e.WriteMapElemKey(j == 0) - } else { - e.mapElemValue() - } - e.e.EncodeInt(int64(v[j])) - } - e.c = 0 - e.e.WriteMapEnd() -} - -func (e *encoderJsonBytes) fastpathEncSliceInt64R(f *encFnInfo, rv reflect.Value) { - var ft fastpathETJsonBytes - var v []int64 - if rv.Kind() == reflect.Array { - rvGetSlice4Array(rv, &v) - } else { - v = rv2i(rv).([]int64) - } - if f.ti.mbs { - ft.EncAsMapSliceInt64V(v, e) - return - } - ft.EncSliceInt64V(v, e) -} -func (fastpathETJsonBytes) EncSliceInt64V(v []int64, e *encoderJsonBytes) { - if len(v) == 0 { - e.c = 0 - e.e.WriteArrayEmpty() - return - } - e.arrayStart(len(v)) - for j := range v { - e.c = containerArrayElem - e.e.WriteArrayElem(j == 0) - e.e.EncodeInt(v[j]) - } - e.c = 0 - e.e.WriteArrayEnd() -} -func (fastpathETJsonBytes) EncAsMapSliceInt64V(v []int64, e *encoderJsonBytes) { - if len(v) == 0 { - e.c = 0 - e.e.WriteMapEmpty() - return - } - e.haltOnMbsOddLen(len(v)) - e.mapStart(len(v) >> 1) - for j := range v { - if j&1 == 0 { - e.c = containerMapKey - e.e.WriteMapElemKey(j == 0) - } else { - e.mapElemValue() - } - e.e.EncodeInt(v[j]) - } - e.c = 0 - e.e.WriteMapEnd() -} - -func (e *encoderJsonBytes) fastpathEncSliceBoolR(f *encFnInfo, rv reflect.Value) { - var ft fastpathETJsonBytes - var v []bool - if rv.Kind() == reflect.Array { - rvGetSlice4Array(rv, &v) - } else { - v = rv2i(rv).([]bool) - } - if f.ti.mbs { - ft.EncAsMapSliceBoolV(v, e) - return - } - ft.EncSliceBoolV(v, e) -} -func (fastpathETJsonBytes) EncSliceBoolV(v []bool, e *encoderJsonBytes) { - if len(v) == 0 { - e.c = 0 - e.e.WriteArrayEmpty() - return - } - e.arrayStart(len(v)) - for j := range v { - e.c = containerArrayElem - e.e.WriteArrayElem(j == 0) - e.e.EncodeBool(v[j]) - } - e.c = 0 - e.e.WriteArrayEnd() -} -func (fastpathETJsonBytes) EncAsMapSliceBoolV(v []bool, e *encoderJsonBytes) { - if len(v) == 0 { - e.c = 0 - e.e.WriteMapEmpty() - return - } - e.haltOnMbsOddLen(len(v)) - e.mapStart(len(v) >> 1) - for j := range v { - if j&1 == 0 { - e.c = containerMapKey - e.e.WriteMapElemKey(j == 0) - } else { - e.mapElemValue() - } - e.e.EncodeBool(v[j]) - } - e.c = 0 - e.e.WriteMapEnd() -} - -func (e *encoderJsonBytes) fastpathEncMapStringIntfR(f *encFnInfo, rv reflect.Value) { - fastpathETJsonBytes{}.EncMapStringIntfV(rv2i(rv).(map[string]interface{}), e) -} -func (fastpathETJsonBytes) EncMapStringIntfV(v map[string]interface{}, e *encoderJsonBytes) { - if len(v) == 0 { - e.e.WriteMapEmpty() - return - } - var i uint - e.mapStart(len(v)) - if e.h.Canonical { - v2 := make([]string, len(v)) - for k := range v { - v2[i] = k - i++ - } - slices.Sort(v2) - for i, k2 := range v2 { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeString(k2) - e.mapElemValue() - if !e.encodeBuiltin(v[k2]) { - e.encodeR(reflect.ValueOf(v[k2])) - } - } - } else { - i = 0 - for k2, v2 := range v { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeString(k2) - e.mapElemValue() - if !e.encodeBuiltin(v2) { - e.encodeR(reflect.ValueOf(v2)) - } - i++ - } - } - e.c = 0 - e.e.WriteMapEnd() -} -func (e *encoderJsonBytes) fastpathEncMapStringStringR(f *encFnInfo, rv reflect.Value) { - fastpathETJsonBytes{}.EncMapStringStringV(rv2i(rv).(map[string]string), e) -} -func (fastpathETJsonBytes) EncMapStringStringV(v map[string]string, e *encoderJsonBytes) { - if len(v) == 0 { - e.e.WriteMapEmpty() - return - } - var i uint - e.mapStart(len(v)) - if e.h.Canonical { - v2 := make([]string, len(v)) - for k := range v { - v2[i] = k - i++ - } - slices.Sort(v2) - for i, k2 := range v2 { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeString(k2) - e.mapElemValue() - e.e.EncodeString(v[k2]) - } - } else { - i = 0 - for k2, v2 := range v { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeString(k2) - e.mapElemValue() - e.e.EncodeString(v2) - i++ - } - } - e.c = 0 - e.e.WriteMapEnd() -} -func (e *encoderJsonBytes) fastpathEncMapStringBytesR(f *encFnInfo, rv reflect.Value) { - fastpathETJsonBytes{}.EncMapStringBytesV(rv2i(rv).(map[string][]byte), e) -} -func (fastpathETJsonBytes) EncMapStringBytesV(v map[string][]byte, e *encoderJsonBytes) { - if len(v) == 0 { - e.e.WriteMapEmpty() - return - } - var i uint - e.mapStart(len(v)) - if e.h.Canonical { - v2 := make([]string, len(v)) - for k := range v { - v2[i] = k - i++ - } - slices.Sort(v2) - for i, k2 := range v2 { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeString(k2) - e.mapElemValue() - e.e.EncodeBytes(v[k2]) - } - } else { - i = 0 - for k2, v2 := range v { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeString(k2) - e.mapElemValue() - e.e.EncodeBytes(v2) - i++ - } - } - e.c = 0 - e.e.WriteMapEnd() -} -func (e *encoderJsonBytes) fastpathEncMapStringUint8R(f *encFnInfo, rv reflect.Value) { - fastpathETJsonBytes{}.EncMapStringUint8V(rv2i(rv).(map[string]uint8), e) -} -func (fastpathETJsonBytes) EncMapStringUint8V(v map[string]uint8, e *encoderJsonBytes) { - if len(v) == 0 { - e.e.WriteMapEmpty() - return - } - var i uint - e.mapStart(len(v)) - if e.h.Canonical { - v2 := make([]string, len(v)) - for k := range v { - v2[i] = k - i++ - } - slices.Sort(v2) - for i, k2 := range v2 { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeString(k2) - e.mapElemValue() - e.e.EncodeUint(uint64(v[k2])) - } - } else { - i = 0 - for k2, v2 := range v { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeString(k2) - e.mapElemValue() - e.e.EncodeUint(uint64(v2)) - i++ - } - } - e.c = 0 - e.e.WriteMapEnd() -} -func (e *encoderJsonBytes) fastpathEncMapStringUint64R(f *encFnInfo, rv reflect.Value) { - fastpathETJsonBytes{}.EncMapStringUint64V(rv2i(rv).(map[string]uint64), e) -} -func (fastpathETJsonBytes) EncMapStringUint64V(v map[string]uint64, e *encoderJsonBytes) { - if len(v) == 0 { - e.e.WriteMapEmpty() - return - } - var i uint - e.mapStart(len(v)) - if e.h.Canonical { - v2 := make([]string, len(v)) - for k := range v { - v2[i] = k - i++ - } - slices.Sort(v2) - for i, k2 := range v2 { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeString(k2) - e.mapElemValue() - e.e.EncodeUint(v[k2]) - } - } else { - i = 0 - for k2, v2 := range v { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeString(k2) - e.mapElemValue() - e.e.EncodeUint(v2) - i++ - } - } - e.c = 0 - e.e.WriteMapEnd() -} -func (e *encoderJsonBytes) fastpathEncMapStringIntR(f *encFnInfo, rv reflect.Value) { - fastpathETJsonBytes{}.EncMapStringIntV(rv2i(rv).(map[string]int), e) -} -func (fastpathETJsonBytes) EncMapStringIntV(v map[string]int, e *encoderJsonBytes) { - if len(v) == 0 { - e.e.WriteMapEmpty() - return - } - var i uint - e.mapStart(len(v)) - if e.h.Canonical { - v2 := make([]string, len(v)) - for k := range v { - v2[i] = k - i++ - } - slices.Sort(v2) - for i, k2 := range v2 { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeString(k2) - e.mapElemValue() - e.e.EncodeInt(int64(v[k2])) - } - } else { - i = 0 - for k2, v2 := range v { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeString(k2) - e.mapElemValue() - e.e.EncodeInt(int64(v2)) - i++ - } - } - e.c = 0 - e.e.WriteMapEnd() -} -func (e *encoderJsonBytes) fastpathEncMapStringInt32R(f *encFnInfo, rv reflect.Value) { - fastpathETJsonBytes{}.EncMapStringInt32V(rv2i(rv).(map[string]int32), e) -} -func (fastpathETJsonBytes) EncMapStringInt32V(v map[string]int32, e *encoderJsonBytes) { - if len(v) == 0 { - e.e.WriteMapEmpty() - return - } - var i uint - e.mapStart(len(v)) - if e.h.Canonical { - v2 := make([]string, len(v)) - for k := range v { - v2[i] = k - i++ - } - slices.Sort(v2) - for i, k2 := range v2 { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeString(k2) - e.mapElemValue() - e.e.EncodeInt(int64(v[k2])) - } - } else { - i = 0 - for k2, v2 := range v { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeString(k2) - e.mapElemValue() - e.e.EncodeInt(int64(v2)) - i++ - } - } - e.c = 0 - e.e.WriteMapEnd() -} -func (e *encoderJsonBytes) fastpathEncMapStringFloat64R(f *encFnInfo, rv reflect.Value) { - fastpathETJsonBytes{}.EncMapStringFloat64V(rv2i(rv).(map[string]float64), e) -} -func (fastpathETJsonBytes) EncMapStringFloat64V(v map[string]float64, e *encoderJsonBytes) { - if len(v) == 0 { - e.e.WriteMapEmpty() - return - } - var i uint - e.mapStart(len(v)) - if e.h.Canonical { - v2 := make([]string, len(v)) - for k := range v { - v2[i] = k - i++ - } - slices.Sort(v2) - for i, k2 := range v2 { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeString(k2) - e.mapElemValue() - e.e.EncodeFloat64(v[k2]) - } - } else { - i = 0 - for k2, v2 := range v { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeString(k2) - e.mapElemValue() - e.e.EncodeFloat64(v2) - i++ - } - } - e.c = 0 - e.e.WriteMapEnd() -} -func (e *encoderJsonBytes) fastpathEncMapStringBoolR(f *encFnInfo, rv reflect.Value) { - fastpathETJsonBytes{}.EncMapStringBoolV(rv2i(rv).(map[string]bool), e) -} -func (fastpathETJsonBytes) EncMapStringBoolV(v map[string]bool, e *encoderJsonBytes) { - if len(v) == 0 { - e.e.WriteMapEmpty() - return - } - var i uint - e.mapStart(len(v)) - if e.h.Canonical { - v2 := make([]string, len(v)) - for k := range v { - v2[i] = k - i++ - } - slices.Sort(v2) - for i, k2 := range v2 { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeString(k2) - e.mapElemValue() - e.e.EncodeBool(v[k2]) - } - } else { - i = 0 - for k2, v2 := range v { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeString(k2) - e.mapElemValue() - e.e.EncodeBool(v2) - i++ - } - } - e.c = 0 - e.e.WriteMapEnd() -} -func (e *encoderJsonBytes) fastpathEncMapUint8IntfR(f *encFnInfo, rv reflect.Value) { - fastpathETJsonBytes{}.EncMapUint8IntfV(rv2i(rv).(map[uint8]interface{}), e) -} -func (fastpathETJsonBytes) EncMapUint8IntfV(v map[uint8]interface{}, e *encoderJsonBytes) { - if len(v) == 0 { - e.e.WriteMapEmpty() - return - } - var i uint - e.mapStart(len(v)) - if e.h.Canonical { - v2 := make([]uint8, len(v)) - for k := range v { - v2[i] = k - i++ - } - slices.Sort(v2) - for i, k2 := range v2 { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeUint(uint64(k2)) - e.mapElemValue() - if !e.encodeBuiltin(v[k2]) { - e.encodeR(reflect.ValueOf(v[k2])) - } - } - } else { - i = 0 - for k2, v2 := range v { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeUint(uint64(k2)) - e.mapElemValue() - if !e.encodeBuiltin(v2) { - e.encodeR(reflect.ValueOf(v2)) - } - i++ - } - } - e.c = 0 - e.e.WriteMapEnd() -} -func (e *encoderJsonBytes) fastpathEncMapUint8StringR(f *encFnInfo, rv reflect.Value) { - fastpathETJsonBytes{}.EncMapUint8StringV(rv2i(rv).(map[uint8]string), e) -} -func (fastpathETJsonBytes) EncMapUint8StringV(v map[uint8]string, e *encoderJsonBytes) { - if len(v) == 0 { - e.e.WriteMapEmpty() - return - } - var i uint - e.mapStart(len(v)) - if e.h.Canonical { - v2 := make([]uint8, len(v)) - for k := range v { - v2[i] = k - i++ - } - slices.Sort(v2) - for i, k2 := range v2 { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeUint(uint64(k2)) - e.mapElemValue() - e.e.EncodeString(v[k2]) - } - } else { - i = 0 - for k2, v2 := range v { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeUint(uint64(k2)) - e.mapElemValue() - e.e.EncodeString(v2) - i++ - } - } - e.c = 0 - e.e.WriteMapEnd() -} -func (e *encoderJsonBytes) fastpathEncMapUint8BytesR(f *encFnInfo, rv reflect.Value) { - fastpathETJsonBytes{}.EncMapUint8BytesV(rv2i(rv).(map[uint8][]byte), e) -} -func (fastpathETJsonBytes) EncMapUint8BytesV(v map[uint8][]byte, e *encoderJsonBytes) { - if len(v) == 0 { - e.e.WriteMapEmpty() - return - } - var i uint - e.mapStart(len(v)) - if e.h.Canonical { - v2 := make([]uint8, len(v)) - for k := range v { - v2[i] = k - i++ - } - slices.Sort(v2) - for i, k2 := range v2 { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeUint(uint64(k2)) - e.mapElemValue() - e.e.EncodeBytes(v[k2]) - } - } else { - i = 0 - for k2, v2 := range v { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeUint(uint64(k2)) - e.mapElemValue() - e.e.EncodeBytes(v2) - i++ - } - } - e.c = 0 - e.e.WriteMapEnd() -} -func (e *encoderJsonBytes) fastpathEncMapUint8Uint8R(f *encFnInfo, rv reflect.Value) { - fastpathETJsonBytes{}.EncMapUint8Uint8V(rv2i(rv).(map[uint8]uint8), e) -} -func (fastpathETJsonBytes) EncMapUint8Uint8V(v map[uint8]uint8, e *encoderJsonBytes) { - if len(v) == 0 { - e.e.WriteMapEmpty() - return - } - var i uint - e.mapStart(len(v)) - if e.h.Canonical { - v2 := make([]uint8, len(v)) - for k := range v { - v2[i] = k - i++ - } - slices.Sort(v2) - for i, k2 := range v2 { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeUint(uint64(k2)) - e.mapElemValue() - e.e.EncodeUint(uint64(v[k2])) - } - } else { - i = 0 - for k2, v2 := range v { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeUint(uint64(k2)) - e.mapElemValue() - e.e.EncodeUint(uint64(v2)) - i++ - } - } - e.c = 0 - e.e.WriteMapEnd() -} -func (e *encoderJsonBytes) fastpathEncMapUint8Uint64R(f *encFnInfo, rv reflect.Value) { - fastpathETJsonBytes{}.EncMapUint8Uint64V(rv2i(rv).(map[uint8]uint64), e) -} -func (fastpathETJsonBytes) EncMapUint8Uint64V(v map[uint8]uint64, e *encoderJsonBytes) { - if len(v) == 0 { - e.e.WriteMapEmpty() - return - } - var i uint - e.mapStart(len(v)) - if e.h.Canonical { - v2 := make([]uint8, len(v)) - for k := range v { - v2[i] = k - i++ - } - slices.Sort(v2) - for i, k2 := range v2 { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeUint(uint64(k2)) - e.mapElemValue() - e.e.EncodeUint(v[k2]) - } - } else { - i = 0 - for k2, v2 := range v { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeUint(uint64(k2)) - e.mapElemValue() - e.e.EncodeUint(v2) - i++ - } - } - e.c = 0 - e.e.WriteMapEnd() -} -func (e *encoderJsonBytes) fastpathEncMapUint8IntR(f *encFnInfo, rv reflect.Value) { - fastpathETJsonBytes{}.EncMapUint8IntV(rv2i(rv).(map[uint8]int), e) -} -func (fastpathETJsonBytes) EncMapUint8IntV(v map[uint8]int, e *encoderJsonBytes) { - if len(v) == 0 { - e.e.WriteMapEmpty() - return - } - var i uint - e.mapStart(len(v)) - if e.h.Canonical { - v2 := make([]uint8, len(v)) - for k := range v { - v2[i] = k - i++ - } - slices.Sort(v2) - for i, k2 := range v2 { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeUint(uint64(k2)) - e.mapElemValue() - e.e.EncodeInt(int64(v[k2])) - } - } else { - i = 0 - for k2, v2 := range v { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeUint(uint64(k2)) - e.mapElemValue() - e.e.EncodeInt(int64(v2)) - i++ - } - } - e.c = 0 - e.e.WriteMapEnd() -} -func (e *encoderJsonBytes) fastpathEncMapUint8Int32R(f *encFnInfo, rv reflect.Value) { - fastpathETJsonBytes{}.EncMapUint8Int32V(rv2i(rv).(map[uint8]int32), e) -} -func (fastpathETJsonBytes) EncMapUint8Int32V(v map[uint8]int32, e *encoderJsonBytes) { - if len(v) == 0 { - e.e.WriteMapEmpty() - return - } - var i uint - e.mapStart(len(v)) - if e.h.Canonical { - v2 := make([]uint8, len(v)) - for k := range v { - v2[i] = k - i++ - } - slices.Sort(v2) - for i, k2 := range v2 { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeUint(uint64(k2)) - e.mapElemValue() - e.e.EncodeInt(int64(v[k2])) - } - } else { - i = 0 - for k2, v2 := range v { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeUint(uint64(k2)) - e.mapElemValue() - e.e.EncodeInt(int64(v2)) - i++ - } - } - e.c = 0 - e.e.WriteMapEnd() -} -func (e *encoderJsonBytes) fastpathEncMapUint8Float64R(f *encFnInfo, rv reflect.Value) { - fastpathETJsonBytes{}.EncMapUint8Float64V(rv2i(rv).(map[uint8]float64), e) -} -func (fastpathETJsonBytes) EncMapUint8Float64V(v map[uint8]float64, e *encoderJsonBytes) { - if len(v) == 0 { - e.e.WriteMapEmpty() - return - } - var i uint - e.mapStart(len(v)) - if e.h.Canonical { - v2 := make([]uint8, len(v)) - for k := range v { - v2[i] = k - i++ - } - slices.Sort(v2) - for i, k2 := range v2 { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeUint(uint64(k2)) - e.mapElemValue() - e.e.EncodeFloat64(v[k2]) - } - } else { - i = 0 - for k2, v2 := range v { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeUint(uint64(k2)) - e.mapElemValue() - e.e.EncodeFloat64(v2) - i++ - } - } - e.c = 0 - e.e.WriteMapEnd() -} -func (e *encoderJsonBytes) fastpathEncMapUint8BoolR(f *encFnInfo, rv reflect.Value) { - fastpathETJsonBytes{}.EncMapUint8BoolV(rv2i(rv).(map[uint8]bool), e) -} -func (fastpathETJsonBytes) EncMapUint8BoolV(v map[uint8]bool, e *encoderJsonBytes) { - if len(v) == 0 { - e.e.WriteMapEmpty() - return - } - var i uint - e.mapStart(len(v)) - if e.h.Canonical { - v2 := make([]uint8, len(v)) - for k := range v { - v2[i] = k - i++ - } - slices.Sort(v2) - for i, k2 := range v2 { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeUint(uint64(k2)) - e.mapElemValue() - e.e.EncodeBool(v[k2]) - } - } else { - i = 0 - for k2, v2 := range v { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeUint(uint64(k2)) - e.mapElemValue() - e.e.EncodeBool(v2) - i++ - } - } - e.c = 0 - e.e.WriteMapEnd() -} -func (e *encoderJsonBytes) fastpathEncMapUint64IntfR(f *encFnInfo, rv reflect.Value) { - fastpathETJsonBytes{}.EncMapUint64IntfV(rv2i(rv).(map[uint64]interface{}), e) -} -func (fastpathETJsonBytes) EncMapUint64IntfV(v map[uint64]interface{}, e *encoderJsonBytes) { - if len(v) == 0 { - e.e.WriteMapEmpty() - return - } - var i uint - e.mapStart(len(v)) - if e.h.Canonical { - v2 := make([]uint64, len(v)) - for k := range v { - v2[i] = k - i++ - } - slices.Sort(v2) - for i, k2 := range v2 { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeUint(k2) - e.mapElemValue() - if !e.encodeBuiltin(v[k2]) { - e.encodeR(reflect.ValueOf(v[k2])) - } - } - } else { - i = 0 - for k2, v2 := range v { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeUint(k2) - e.mapElemValue() - if !e.encodeBuiltin(v2) { - e.encodeR(reflect.ValueOf(v2)) - } - i++ - } - } - e.c = 0 - e.e.WriteMapEnd() -} -func (e *encoderJsonBytes) fastpathEncMapUint64StringR(f *encFnInfo, rv reflect.Value) { - fastpathETJsonBytes{}.EncMapUint64StringV(rv2i(rv).(map[uint64]string), e) -} -func (fastpathETJsonBytes) EncMapUint64StringV(v map[uint64]string, e *encoderJsonBytes) { - if len(v) == 0 { - e.e.WriteMapEmpty() - return - } - var i uint - e.mapStart(len(v)) - if e.h.Canonical { - v2 := make([]uint64, len(v)) - for k := range v { - v2[i] = k - i++ - } - slices.Sort(v2) - for i, k2 := range v2 { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeUint(k2) - e.mapElemValue() - e.e.EncodeString(v[k2]) - } - } else { - i = 0 - for k2, v2 := range v { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeUint(k2) - e.mapElemValue() - e.e.EncodeString(v2) - i++ - } - } - e.c = 0 - e.e.WriteMapEnd() -} -func (e *encoderJsonBytes) fastpathEncMapUint64BytesR(f *encFnInfo, rv reflect.Value) { - fastpathETJsonBytes{}.EncMapUint64BytesV(rv2i(rv).(map[uint64][]byte), e) -} -func (fastpathETJsonBytes) EncMapUint64BytesV(v map[uint64][]byte, e *encoderJsonBytes) { - if len(v) == 0 { - e.e.WriteMapEmpty() - return - } - var i uint - e.mapStart(len(v)) - if e.h.Canonical { - v2 := make([]uint64, len(v)) - for k := range v { - v2[i] = k - i++ - } - slices.Sort(v2) - for i, k2 := range v2 { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeUint(k2) - e.mapElemValue() - e.e.EncodeBytes(v[k2]) - } - } else { - i = 0 - for k2, v2 := range v { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeUint(k2) - e.mapElemValue() - e.e.EncodeBytes(v2) - i++ - } - } - e.c = 0 - e.e.WriteMapEnd() -} -func (e *encoderJsonBytes) fastpathEncMapUint64Uint8R(f *encFnInfo, rv reflect.Value) { - fastpathETJsonBytes{}.EncMapUint64Uint8V(rv2i(rv).(map[uint64]uint8), e) -} -func (fastpathETJsonBytes) EncMapUint64Uint8V(v map[uint64]uint8, e *encoderJsonBytes) { - if len(v) == 0 { - e.e.WriteMapEmpty() - return - } - var i uint - e.mapStart(len(v)) - if e.h.Canonical { - v2 := make([]uint64, len(v)) - for k := range v { - v2[i] = k - i++ - } - slices.Sort(v2) - for i, k2 := range v2 { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeUint(k2) - e.mapElemValue() - e.e.EncodeUint(uint64(v[k2])) - } - } else { - i = 0 - for k2, v2 := range v { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeUint(k2) - e.mapElemValue() - e.e.EncodeUint(uint64(v2)) - i++ - } - } - e.c = 0 - e.e.WriteMapEnd() -} -func (e *encoderJsonBytes) fastpathEncMapUint64Uint64R(f *encFnInfo, rv reflect.Value) { - fastpathETJsonBytes{}.EncMapUint64Uint64V(rv2i(rv).(map[uint64]uint64), e) -} -func (fastpathETJsonBytes) EncMapUint64Uint64V(v map[uint64]uint64, e *encoderJsonBytes) { - if len(v) == 0 { - e.e.WriteMapEmpty() - return - } - var i uint - e.mapStart(len(v)) - if e.h.Canonical { - v2 := make([]uint64, len(v)) - for k := range v { - v2[i] = k - i++ - } - slices.Sort(v2) - for i, k2 := range v2 { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeUint(k2) - e.mapElemValue() - e.e.EncodeUint(v[k2]) - } - } else { - i = 0 - for k2, v2 := range v { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeUint(k2) - e.mapElemValue() - e.e.EncodeUint(v2) - i++ - } - } - e.c = 0 - e.e.WriteMapEnd() -} -func (e *encoderJsonBytes) fastpathEncMapUint64IntR(f *encFnInfo, rv reflect.Value) { - fastpathETJsonBytes{}.EncMapUint64IntV(rv2i(rv).(map[uint64]int), e) -} -func (fastpathETJsonBytes) EncMapUint64IntV(v map[uint64]int, e *encoderJsonBytes) { - if len(v) == 0 { - e.e.WriteMapEmpty() - return - } - var i uint - e.mapStart(len(v)) - if e.h.Canonical { - v2 := make([]uint64, len(v)) - for k := range v { - v2[i] = k - i++ - } - slices.Sort(v2) - for i, k2 := range v2 { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeUint(k2) - e.mapElemValue() - e.e.EncodeInt(int64(v[k2])) - } - } else { - i = 0 - for k2, v2 := range v { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeUint(k2) - e.mapElemValue() - e.e.EncodeInt(int64(v2)) - i++ - } - } - e.c = 0 - e.e.WriteMapEnd() -} -func (e *encoderJsonBytes) fastpathEncMapUint64Int32R(f *encFnInfo, rv reflect.Value) { - fastpathETJsonBytes{}.EncMapUint64Int32V(rv2i(rv).(map[uint64]int32), e) -} -func (fastpathETJsonBytes) EncMapUint64Int32V(v map[uint64]int32, e *encoderJsonBytes) { - if len(v) == 0 { - e.e.WriteMapEmpty() - return - } - var i uint - e.mapStart(len(v)) - if e.h.Canonical { - v2 := make([]uint64, len(v)) - for k := range v { - v2[i] = k - i++ - } - slices.Sort(v2) - for i, k2 := range v2 { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeUint(k2) - e.mapElemValue() - e.e.EncodeInt(int64(v[k2])) - } - } else { - i = 0 - for k2, v2 := range v { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeUint(k2) - e.mapElemValue() - e.e.EncodeInt(int64(v2)) - i++ - } - } - e.c = 0 - e.e.WriteMapEnd() -} -func (e *encoderJsonBytes) fastpathEncMapUint64Float64R(f *encFnInfo, rv reflect.Value) { - fastpathETJsonBytes{}.EncMapUint64Float64V(rv2i(rv).(map[uint64]float64), e) -} -func (fastpathETJsonBytes) EncMapUint64Float64V(v map[uint64]float64, e *encoderJsonBytes) { - if len(v) == 0 { - e.e.WriteMapEmpty() - return - } - var i uint - e.mapStart(len(v)) - if e.h.Canonical { - v2 := make([]uint64, len(v)) - for k := range v { - v2[i] = k - i++ - } - slices.Sort(v2) - for i, k2 := range v2 { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeUint(k2) - e.mapElemValue() - e.e.EncodeFloat64(v[k2]) - } - } else { - i = 0 - for k2, v2 := range v { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeUint(k2) - e.mapElemValue() - e.e.EncodeFloat64(v2) - i++ - } - } - e.c = 0 - e.e.WriteMapEnd() -} -func (e *encoderJsonBytes) fastpathEncMapUint64BoolR(f *encFnInfo, rv reflect.Value) { - fastpathETJsonBytes{}.EncMapUint64BoolV(rv2i(rv).(map[uint64]bool), e) -} -func (fastpathETJsonBytes) EncMapUint64BoolV(v map[uint64]bool, e *encoderJsonBytes) { - if len(v) == 0 { - e.e.WriteMapEmpty() - return - } - var i uint - e.mapStart(len(v)) - if e.h.Canonical { - v2 := make([]uint64, len(v)) - for k := range v { - v2[i] = k - i++ - } - slices.Sort(v2) - for i, k2 := range v2 { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeUint(k2) - e.mapElemValue() - e.e.EncodeBool(v[k2]) - } - } else { - i = 0 - for k2, v2 := range v { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeUint(k2) - e.mapElemValue() - e.e.EncodeBool(v2) - i++ - } - } - e.c = 0 - e.e.WriteMapEnd() -} -func (e *encoderJsonBytes) fastpathEncMapIntIntfR(f *encFnInfo, rv reflect.Value) { - fastpathETJsonBytes{}.EncMapIntIntfV(rv2i(rv).(map[int]interface{}), e) -} -func (fastpathETJsonBytes) EncMapIntIntfV(v map[int]interface{}, e *encoderJsonBytes) { - if len(v) == 0 { - e.e.WriteMapEmpty() - return - } - var i uint - e.mapStart(len(v)) - if e.h.Canonical { - v2 := make([]int, len(v)) - for k := range v { - v2[i] = k - i++ - } - slices.Sort(v2) - for i, k2 := range v2 { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeInt(int64(k2)) - e.mapElemValue() - if !e.encodeBuiltin(v[k2]) { - e.encodeR(reflect.ValueOf(v[k2])) - } - } - } else { - i = 0 - for k2, v2 := range v { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeInt(int64(k2)) - e.mapElemValue() - if !e.encodeBuiltin(v2) { - e.encodeR(reflect.ValueOf(v2)) - } - i++ - } - } - e.c = 0 - e.e.WriteMapEnd() -} -func (e *encoderJsonBytes) fastpathEncMapIntStringR(f *encFnInfo, rv reflect.Value) { - fastpathETJsonBytes{}.EncMapIntStringV(rv2i(rv).(map[int]string), e) -} -func (fastpathETJsonBytes) EncMapIntStringV(v map[int]string, e *encoderJsonBytes) { - if len(v) == 0 { - e.e.WriteMapEmpty() - return - } - var i uint - e.mapStart(len(v)) - if e.h.Canonical { - v2 := make([]int, len(v)) - for k := range v { - v2[i] = k - i++ - } - slices.Sort(v2) - for i, k2 := range v2 { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeInt(int64(k2)) - e.mapElemValue() - e.e.EncodeString(v[k2]) - } - } else { - i = 0 - for k2, v2 := range v { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeInt(int64(k2)) - e.mapElemValue() - e.e.EncodeString(v2) - i++ - } - } - e.c = 0 - e.e.WriteMapEnd() -} -func (e *encoderJsonBytes) fastpathEncMapIntBytesR(f *encFnInfo, rv reflect.Value) { - fastpathETJsonBytes{}.EncMapIntBytesV(rv2i(rv).(map[int][]byte), e) -} -func (fastpathETJsonBytes) EncMapIntBytesV(v map[int][]byte, e *encoderJsonBytes) { - if len(v) == 0 { - e.e.WriteMapEmpty() - return - } - var i uint - e.mapStart(len(v)) - if e.h.Canonical { - v2 := make([]int, len(v)) - for k := range v { - v2[i] = k - i++ - } - slices.Sort(v2) - for i, k2 := range v2 { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeInt(int64(k2)) - e.mapElemValue() - e.e.EncodeBytes(v[k2]) - } - } else { - i = 0 - for k2, v2 := range v { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeInt(int64(k2)) - e.mapElemValue() - e.e.EncodeBytes(v2) - i++ - } - } - e.c = 0 - e.e.WriteMapEnd() -} -func (e *encoderJsonBytes) fastpathEncMapIntUint8R(f *encFnInfo, rv reflect.Value) { - fastpathETJsonBytes{}.EncMapIntUint8V(rv2i(rv).(map[int]uint8), e) -} -func (fastpathETJsonBytes) EncMapIntUint8V(v map[int]uint8, e *encoderJsonBytes) { - if len(v) == 0 { - e.e.WriteMapEmpty() - return - } - var i uint - e.mapStart(len(v)) - if e.h.Canonical { - v2 := make([]int, len(v)) - for k := range v { - v2[i] = k - i++ - } - slices.Sort(v2) - for i, k2 := range v2 { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeInt(int64(k2)) - e.mapElemValue() - e.e.EncodeUint(uint64(v[k2])) - } - } else { - i = 0 - for k2, v2 := range v { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeInt(int64(k2)) - e.mapElemValue() - e.e.EncodeUint(uint64(v2)) - i++ - } - } - e.c = 0 - e.e.WriteMapEnd() -} -func (e *encoderJsonBytes) fastpathEncMapIntUint64R(f *encFnInfo, rv reflect.Value) { - fastpathETJsonBytes{}.EncMapIntUint64V(rv2i(rv).(map[int]uint64), e) -} -func (fastpathETJsonBytes) EncMapIntUint64V(v map[int]uint64, e *encoderJsonBytes) { - if len(v) == 0 { - e.e.WriteMapEmpty() - return - } - var i uint - e.mapStart(len(v)) - if e.h.Canonical { - v2 := make([]int, len(v)) - for k := range v { - v2[i] = k - i++ - } - slices.Sort(v2) - for i, k2 := range v2 { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeInt(int64(k2)) - e.mapElemValue() - e.e.EncodeUint(v[k2]) - } - } else { - i = 0 - for k2, v2 := range v { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeInt(int64(k2)) - e.mapElemValue() - e.e.EncodeUint(v2) - i++ - } - } - e.c = 0 - e.e.WriteMapEnd() -} -func (e *encoderJsonBytes) fastpathEncMapIntIntR(f *encFnInfo, rv reflect.Value) { - fastpathETJsonBytes{}.EncMapIntIntV(rv2i(rv).(map[int]int), e) -} -func (fastpathETJsonBytes) EncMapIntIntV(v map[int]int, e *encoderJsonBytes) { - if len(v) == 0 { - e.e.WriteMapEmpty() - return - } - var i uint - e.mapStart(len(v)) - if e.h.Canonical { - v2 := make([]int, len(v)) - for k := range v { - v2[i] = k - i++ - } - slices.Sort(v2) - for i, k2 := range v2 { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeInt(int64(k2)) - e.mapElemValue() - e.e.EncodeInt(int64(v[k2])) - } - } else { - i = 0 - for k2, v2 := range v { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeInt(int64(k2)) - e.mapElemValue() - e.e.EncodeInt(int64(v2)) - i++ - } - } - e.c = 0 - e.e.WriteMapEnd() -} -func (e *encoderJsonBytes) fastpathEncMapIntInt32R(f *encFnInfo, rv reflect.Value) { - fastpathETJsonBytes{}.EncMapIntInt32V(rv2i(rv).(map[int]int32), e) -} -func (fastpathETJsonBytes) EncMapIntInt32V(v map[int]int32, e *encoderJsonBytes) { - if len(v) == 0 { - e.e.WriteMapEmpty() - return - } - var i uint - e.mapStart(len(v)) - if e.h.Canonical { - v2 := make([]int, len(v)) - for k := range v { - v2[i] = k - i++ - } - slices.Sort(v2) - for i, k2 := range v2 { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeInt(int64(k2)) - e.mapElemValue() - e.e.EncodeInt(int64(v[k2])) - } - } else { - i = 0 - for k2, v2 := range v { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeInt(int64(k2)) - e.mapElemValue() - e.e.EncodeInt(int64(v2)) - i++ - } - } - e.c = 0 - e.e.WriteMapEnd() -} -func (e *encoderJsonBytes) fastpathEncMapIntFloat64R(f *encFnInfo, rv reflect.Value) { - fastpathETJsonBytes{}.EncMapIntFloat64V(rv2i(rv).(map[int]float64), e) -} -func (fastpathETJsonBytes) EncMapIntFloat64V(v map[int]float64, e *encoderJsonBytes) { - if len(v) == 0 { - e.e.WriteMapEmpty() - return - } - var i uint - e.mapStart(len(v)) - if e.h.Canonical { - v2 := make([]int, len(v)) - for k := range v { - v2[i] = k - i++ - } - slices.Sort(v2) - for i, k2 := range v2 { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeInt(int64(k2)) - e.mapElemValue() - e.e.EncodeFloat64(v[k2]) - } - } else { - i = 0 - for k2, v2 := range v { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeInt(int64(k2)) - e.mapElemValue() - e.e.EncodeFloat64(v2) - i++ - } - } - e.c = 0 - e.e.WriteMapEnd() -} -func (e *encoderJsonBytes) fastpathEncMapIntBoolR(f *encFnInfo, rv reflect.Value) { - fastpathETJsonBytes{}.EncMapIntBoolV(rv2i(rv).(map[int]bool), e) -} -func (fastpathETJsonBytes) EncMapIntBoolV(v map[int]bool, e *encoderJsonBytes) { - if len(v) == 0 { - e.e.WriteMapEmpty() - return - } - var i uint - e.mapStart(len(v)) - if e.h.Canonical { - v2 := make([]int, len(v)) - for k := range v { - v2[i] = k - i++ - } - slices.Sort(v2) - for i, k2 := range v2 { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeInt(int64(k2)) - e.mapElemValue() - e.e.EncodeBool(v[k2]) - } - } else { - i = 0 - for k2, v2 := range v { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeInt(int64(k2)) - e.mapElemValue() - e.e.EncodeBool(v2) - i++ - } - } - e.c = 0 - e.e.WriteMapEnd() -} -func (e *encoderJsonBytes) fastpathEncMapInt32IntfR(f *encFnInfo, rv reflect.Value) { - fastpathETJsonBytes{}.EncMapInt32IntfV(rv2i(rv).(map[int32]interface{}), e) -} -func (fastpathETJsonBytes) EncMapInt32IntfV(v map[int32]interface{}, e *encoderJsonBytes) { - if len(v) == 0 { - e.e.WriteMapEmpty() - return - } - var i uint - e.mapStart(len(v)) - if e.h.Canonical { - v2 := make([]int32, len(v)) - for k := range v { - v2[i] = k - i++ - } - slices.Sort(v2) - for i, k2 := range v2 { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeInt(int64(k2)) - e.mapElemValue() - if !e.encodeBuiltin(v[k2]) { - e.encodeR(reflect.ValueOf(v[k2])) - } - } - } else { - i = 0 - for k2, v2 := range v { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeInt(int64(k2)) - e.mapElemValue() - if !e.encodeBuiltin(v2) { - e.encodeR(reflect.ValueOf(v2)) - } - i++ - } - } - e.c = 0 - e.e.WriteMapEnd() -} -func (e *encoderJsonBytes) fastpathEncMapInt32StringR(f *encFnInfo, rv reflect.Value) { - fastpathETJsonBytes{}.EncMapInt32StringV(rv2i(rv).(map[int32]string), e) -} -func (fastpathETJsonBytes) EncMapInt32StringV(v map[int32]string, e *encoderJsonBytes) { - if len(v) == 0 { - e.e.WriteMapEmpty() - return - } - var i uint - e.mapStart(len(v)) - if e.h.Canonical { - v2 := make([]int32, len(v)) - for k := range v { - v2[i] = k - i++ - } - slices.Sort(v2) - for i, k2 := range v2 { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeInt(int64(k2)) - e.mapElemValue() - e.e.EncodeString(v[k2]) - } - } else { - i = 0 - for k2, v2 := range v { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeInt(int64(k2)) - e.mapElemValue() - e.e.EncodeString(v2) - i++ - } - } - e.c = 0 - e.e.WriteMapEnd() -} -func (e *encoderJsonBytes) fastpathEncMapInt32BytesR(f *encFnInfo, rv reflect.Value) { - fastpathETJsonBytes{}.EncMapInt32BytesV(rv2i(rv).(map[int32][]byte), e) -} -func (fastpathETJsonBytes) EncMapInt32BytesV(v map[int32][]byte, e *encoderJsonBytes) { - if len(v) == 0 { - e.e.WriteMapEmpty() - return - } - var i uint - e.mapStart(len(v)) - if e.h.Canonical { - v2 := make([]int32, len(v)) - for k := range v { - v2[i] = k - i++ - } - slices.Sort(v2) - for i, k2 := range v2 { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeInt(int64(k2)) - e.mapElemValue() - e.e.EncodeBytes(v[k2]) - } - } else { - i = 0 - for k2, v2 := range v { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeInt(int64(k2)) - e.mapElemValue() - e.e.EncodeBytes(v2) - i++ - } - } - e.c = 0 - e.e.WriteMapEnd() -} -func (e *encoderJsonBytes) fastpathEncMapInt32Uint8R(f *encFnInfo, rv reflect.Value) { - fastpathETJsonBytes{}.EncMapInt32Uint8V(rv2i(rv).(map[int32]uint8), e) -} -func (fastpathETJsonBytes) EncMapInt32Uint8V(v map[int32]uint8, e *encoderJsonBytes) { - if len(v) == 0 { - e.e.WriteMapEmpty() - return - } - var i uint - e.mapStart(len(v)) - if e.h.Canonical { - v2 := make([]int32, len(v)) - for k := range v { - v2[i] = k - i++ - } - slices.Sort(v2) - for i, k2 := range v2 { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeInt(int64(k2)) - e.mapElemValue() - e.e.EncodeUint(uint64(v[k2])) - } - } else { - i = 0 - for k2, v2 := range v { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeInt(int64(k2)) - e.mapElemValue() - e.e.EncodeUint(uint64(v2)) - i++ - } - } - e.c = 0 - e.e.WriteMapEnd() -} -func (e *encoderJsonBytes) fastpathEncMapInt32Uint64R(f *encFnInfo, rv reflect.Value) { - fastpathETJsonBytes{}.EncMapInt32Uint64V(rv2i(rv).(map[int32]uint64), e) -} -func (fastpathETJsonBytes) EncMapInt32Uint64V(v map[int32]uint64, e *encoderJsonBytes) { - if len(v) == 0 { - e.e.WriteMapEmpty() - return - } - var i uint - e.mapStart(len(v)) - if e.h.Canonical { - v2 := make([]int32, len(v)) - for k := range v { - v2[i] = k - i++ - } - slices.Sort(v2) - for i, k2 := range v2 { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeInt(int64(k2)) - e.mapElemValue() - e.e.EncodeUint(v[k2]) - } - } else { - i = 0 - for k2, v2 := range v { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeInt(int64(k2)) - e.mapElemValue() - e.e.EncodeUint(v2) - i++ - } - } - e.c = 0 - e.e.WriteMapEnd() -} -func (e *encoderJsonBytes) fastpathEncMapInt32IntR(f *encFnInfo, rv reflect.Value) { - fastpathETJsonBytes{}.EncMapInt32IntV(rv2i(rv).(map[int32]int), e) -} -func (fastpathETJsonBytes) EncMapInt32IntV(v map[int32]int, e *encoderJsonBytes) { - if len(v) == 0 { - e.e.WriteMapEmpty() - return - } - var i uint - e.mapStart(len(v)) - if e.h.Canonical { - v2 := make([]int32, len(v)) - for k := range v { - v2[i] = k - i++ - } - slices.Sort(v2) - for i, k2 := range v2 { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeInt(int64(k2)) - e.mapElemValue() - e.e.EncodeInt(int64(v[k2])) - } - } else { - i = 0 - for k2, v2 := range v { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeInt(int64(k2)) - e.mapElemValue() - e.e.EncodeInt(int64(v2)) - i++ - } - } - e.c = 0 - e.e.WriteMapEnd() -} -func (e *encoderJsonBytes) fastpathEncMapInt32Int32R(f *encFnInfo, rv reflect.Value) { - fastpathETJsonBytes{}.EncMapInt32Int32V(rv2i(rv).(map[int32]int32), e) -} -func (fastpathETJsonBytes) EncMapInt32Int32V(v map[int32]int32, e *encoderJsonBytes) { - if len(v) == 0 { - e.e.WriteMapEmpty() - return - } - var i uint - e.mapStart(len(v)) - if e.h.Canonical { - v2 := make([]int32, len(v)) - for k := range v { - v2[i] = k - i++ - } - slices.Sort(v2) - for i, k2 := range v2 { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeInt(int64(k2)) - e.mapElemValue() - e.e.EncodeInt(int64(v[k2])) - } - } else { - i = 0 - for k2, v2 := range v { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeInt(int64(k2)) - e.mapElemValue() - e.e.EncodeInt(int64(v2)) - i++ - } - } - e.c = 0 - e.e.WriteMapEnd() -} -func (e *encoderJsonBytes) fastpathEncMapInt32Float64R(f *encFnInfo, rv reflect.Value) { - fastpathETJsonBytes{}.EncMapInt32Float64V(rv2i(rv).(map[int32]float64), e) -} -func (fastpathETJsonBytes) EncMapInt32Float64V(v map[int32]float64, e *encoderJsonBytes) { - if len(v) == 0 { - e.e.WriteMapEmpty() - return - } - var i uint - e.mapStart(len(v)) - if e.h.Canonical { - v2 := make([]int32, len(v)) - for k := range v { - v2[i] = k - i++ - } - slices.Sort(v2) - for i, k2 := range v2 { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeInt(int64(k2)) - e.mapElemValue() - e.e.EncodeFloat64(v[k2]) - } - } else { - i = 0 - for k2, v2 := range v { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeInt(int64(k2)) - e.mapElemValue() - e.e.EncodeFloat64(v2) - i++ - } - } - e.c = 0 - e.e.WriteMapEnd() -} -func (e *encoderJsonBytes) fastpathEncMapInt32BoolR(f *encFnInfo, rv reflect.Value) { - fastpathETJsonBytes{}.EncMapInt32BoolV(rv2i(rv).(map[int32]bool), e) -} -func (fastpathETJsonBytes) EncMapInt32BoolV(v map[int32]bool, e *encoderJsonBytes) { - if len(v) == 0 { - e.e.WriteMapEmpty() - return - } - var i uint - e.mapStart(len(v)) - if e.h.Canonical { - v2 := make([]int32, len(v)) - for k := range v { - v2[i] = k - i++ - } - slices.Sort(v2) - for i, k2 := range v2 { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeInt(int64(k2)) - e.mapElemValue() - e.e.EncodeBool(v[k2]) - } - } else { - i = 0 - for k2, v2 := range v { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeInt(int64(k2)) - e.mapElemValue() - e.e.EncodeBool(v2) - i++ - } - } - e.c = 0 - e.e.WriteMapEnd() -} - -func (helperDecDriverJsonBytes) fastpathDecodeTypeSwitch(iv interface{}, d *decoderJsonBytes) bool { - var ft fastpathDTJsonBytes - var changed bool - var containerLen int - switch v := iv.(type) { - case []interface{}: - ft.DecSliceIntfN(v, d) - case *[]interface{}: - var v2 []interface{} - if v2, changed = ft.DecSliceIntfY(*v, d); changed { - *v = v2 - } - case []string: - ft.DecSliceStringN(v, d) - case *[]string: - var v2 []string - if v2, changed = ft.DecSliceStringY(*v, d); changed { - *v = v2 - } - case [][]byte: - ft.DecSliceBytesN(v, d) - case *[][]byte: - var v2 [][]byte - if v2, changed = ft.DecSliceBytesY(*v, d); changed { - *v = v2 - } - case []float32: - ft.DecSliceFloat32N(v, d) - case *[]float32: - var v2 []float32 - if v2, changed = ft.DecSliceFloat32Y(*v, d); changed { - *v = v2 - } - case []float64: - ft.DecSliceFloat64N(v, d) - case *[]float64: - var v2 []float64 - if v2, changed = ft.DecSliceFloat64Y(*v, d); changed { - *v = v2 - } - case []uint8: - ft.DecSliceUint8N(v, d) - case *[]uint8: - var v2 []uint8 - if v2, changed = ft.DecSliceUint8Y(*v, d); changed { - *v = v2 - } - case []uint64: - ft.DecSliceUint64N(v, d) - case *[]uint64: - var v2 []uint64 - if v2, changed = ft.DecSliceUint64Y(*v, d); changed { - *v = v2 - } - case []int: - ft.DecSliceIntN(v, d) - case *[]int: - var v2 []int - if v2, changed = ft.DecSliceIntY(*v, d); changed { - *v = v2 - } - case []int32: - ft.DecSliceInt32N(v, d) - case *[]int32: - var v2 []int32 - if v2, changed = ft.DecSliceInt32Y(*v, d); changed { - *v = v2 - } - case []int64: - ft.DecSliceInt64N(v, d) - case *[]int64: - var v2 []int64 - if v2, changed = ft.DecSliceInt64Y(*v, d); changed { - *v = v2 - } - case []bool: - ft.DecSliceBoolN(v, d) - case *[]bool: - var v2 []bool - if v2, changed = ft.DecSliceBoolY(*v, d); changed { - *v = v2 - } - case map[string]interface{}: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen != containerLenNil { - if containerLen != 0 { - ft.DecMapStringIntfL(v, containerLen, d) - } - d.mapEnd() - } - case *map[string]interface{}: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen == containerLenNil { - *v = nil - } else { - if *v == nil { - *v = make(map[string]interface{}, decInferLen(containerLen, d.maxInitLen(), 32)) - } - if containerLen != 0 { - ft.DecMapStringIntfL(*v, containerLen, d) - } - d.mapEnd() - } - case map[string]string: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen != containerLenNil { - if containerLen != 0 { - ft.DecMapStringStringL(v, containerLen, d) - } - d.mapEnd() - } - case *map[string]string: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen == containerLenNil { - *v = nil - } else { - if *v == nil { - *v = make(map[string]string, decInferLen(containerLen, d.maxInitLen(), 32)) - } - if containerLen != 0 { - ft.DecMapStringStringL(*v, containerLen, d) - } - d.mapEnd() - } - case map[string][]byte: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen != containerLenNil { - if containerLen != 0 { - ft.DecMapStringBytesL(v, containerLen, d) - } - d.mapEnd() - } - case *map[string][]byte: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen == containerLenNil { - *v = nil - } else { - if *v == nil { - *v = make(map[string][]byte, decInferLen(containerLen, d.maxInitLen(), 40)) - } - if containerLen != 0 { - ft.DecMapStringBytesL(*v, containerLen, d) - } - d.mapEnd() - } - case map[string]uint8: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen != containerLenNil { - if containerLen != 0 { - ft.DecMapStringUint8L(v, containerLen, d) - } - d.mapEnd() - } - case *map[string]uint8: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen == containerLenNil { - *v = nil - } else { - if *v == nil { - *v = make(map[string]uint8, decInferLen(containerLen, d.maxInitLen(), 17)) - } - if containerLen != 0 { - ft.DecMapStringUint8L(*v, containerLen, d) - } - d.mapEnd() - } - case map[string]uint64: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen != containerLenNil { - if containerLen != 0 { - ft.DecMapStringUint64L(v, containerLen, d) - } - d.mapEnd() - } - case *map[string]uint64: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen == containerLenNil { - *v = nil - } else { - if *v == nil { - *v = make(map[string]uint64, decInferLen(containerLen, d.maxInitLen(), 24)) - } - if containerLen != 0 { - ft.DecMapStringUint64L(*v, containerLen, d) - } - d.mapEnd() - } - case map[string]int: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen != containerLenNil { - if containerLen != 0 { - ft.DecMapStringIntL(v, containerLen, d) - } - d.mapEnd() - } - case *map[string]int: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen == containerLenNil { - *v = nil - } else { - if *v == nil { - *v = make(map[string]int, decInferLen(containerLen, d.maxInitLen(), 24)) - } - if containerLen != 0 { - ft.DecMapStringIntL(*v, containerLen, d) - } - d.mapEnd() - } - case map[string]int32: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen != containerLenNil { - if containerLen != 0 { - ft.DecMapStringInt32L(v, containerLen, d) - } - d.mapEnd() - } - case *map[string]int32: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen == containerLenNil { - *v = nil - } else { - if *v == nil { - *v = make(map[string]int32, decInferLen(containerLen, d.maxInitLen(), 20)) - } - if containerLen != 0 { - ft.DecMapStringInt32L(*v, containerLen, d) - } - d.mapEnd() - } - case map[string]float64: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen != containerLenNil { - if containerLen != 0 { - ft.DecMapStringFloat64L(v, containerLen, d) - } - d.mapEnd() - } - case *map[string]float64: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen == containerLenNil { - *v = nil - } else { - if *v == nil { - *v = make(map[string]float64, decInferLen(containerLen, d.maxInitLen(), 24)) - } - if containerLen != 0 { - ft.DecMapStringFloat64L(*v, containerLen, d) - } - d.mapEnd() - } - case map[string]bool: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen != containerLenNil { - if containerLen != 0 { - ft.DecMapStringBoolL(v, containerLen, d) - } - d.mapEnd() - } - case *map[string]bool: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen == containerLenNil { - *v = nil - } else { - if *v == nil { - *v = make(map[string]bool, decInferLen(containerLen, d.maxInitLen(), 17)) - } - if containerLen != 0 { - ft.DecMapStringBoolL(*v, containerLen, d) - } - d.mapEnd() - } - case map[uint8]interface{}: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen != containerLenNil { - if containerLen != 0 { - ft.DecMapUint8IntfL(v, containerLen, d) - } - d.mapEnd() - } - case *map[uint8]interface{}: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen == containerLenNil { - *v = nil - } else { - if *v == nil { - *v = make(map[uint8]interface{}, decInferLen(containerLen, d.maxInitLen(), 17)) - } - if containerLen != 0 { - ft.DecMapUint8IntfL(*v, containerLen, d) - } - d.mapEnd() - } - case map[uint8]string: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen != containerLenNil { - if containerLen != 0 { - ft.DecMapUint8StringL(v, containerLen, d) - } - d.mapEnd() - } - case *map[uint8]string: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen == containerLenNil { - *v = nil - } else { - if *v == nil { - *v = make(map[uint8]string, decInferLen(containerLen, d.maxInitLen(), 17)) - } - if containerLen != 0 { - ft.DecMapUint8StringL(*v, containerLen, d) - } - d.mapEnd() - } - case map[uint8][]byte: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen != containerLenNil { - if containerLen != 0 { - ft.DecMapUint8BytesL(v, containerLen, d) - } - d.mapEnd() - } - case *map[uint8][]byte: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen == containerLenNil { - *v = nil - } else { - if *v == nil { - *v = make(map[uint8][]byte, decInferLen(containerLen, d.maxInitLen(), 25)) - } - if containerLen != 0 { - ft.DecMapUint8BytesL(*v, containerLen, d) - } - d.mapEnd() - } - case map[uint8]uint8: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen != containerLenNil { - if containerLen != 0 { - ft.DecMapUint8Uint8L(v, containerLen, d) - } - d.mapEnd() - } - case *map[uint8]uint8: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen == containerLenNil { - *v = nil - } else { - if *v == nil { - *v = make(map[uint8]uint8, decInferLen(containerLen, d.maxInitLen(), 2)) - } - if containerLen != 0 { - ft.DecMapUint8Uint8L(*v, containerLen, d) - } - d.mapEnd() - } - case map[uint8]uint64: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen != containerLenNil { - if containerLen != 0 { - ft.DecMapUint8Uint64L(v, containerLen, d) - } - d.mapEnd() - } - case *map[uint8]uint64: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen == containerLenNil { - *v = nil - } else { - if *v == nil { - *v = make(map[uint8]uint64, decInferLen(containerLen, d.maxInitLen(), 9)) - } - if containerLen != 0 { - ft.DecMapUint8Uint64L(*v, containerLen, d) - } - d.mapEnd() - } - case map[uint8]int: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen != containerLenNil { - if containerLen != 0 { - ft.DecMapUint8IntL(v, containerLen, d) - } - d.mapEnd() - } - case *map[uint8]int: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen == containerLenNil { - *v = nil - } else { - if *v == nil { - *v = make(map[uint8]int, decInferLen(containerLen, d.maxInitLen(), 9)) - } - if containerLen != 0 { - ft.DecMapUint8IntL(*v, containerLen, d) - } - d.mapEnd() - } - case map[uint8]int32: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen != containerLenNil { - if containerLen != 0 { - ft.DecMapUint8Int32L(v, containerLen, d) - } - d.mapEnd() - } - case *map[uint8]int32: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen == containerLenNil { - *v = nil - } else { - if *v == nil { - *v = make(map[uint8]int32, decInferLen(containerLen, d.maxInitLen(), 5)) - } - if containerLen != 0 { - ft.DecMapUint8Int32L(*v, containerLen, d) - } - d.mapEnd() - } - case map[uint8]float64: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen != containerLenNil { - if containerLen != 0 { - ft.DecMapUint8Float64L(v, containerLen, d) - } - d.mapEnd() - } - case *map[uint8]float64: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen == containerLenNil { - *v = nil - } else { - if *v == nil { - *v = make(map[uint8]float64, decInferLen(containerLen, d.maxInitLen(), 9)) - } - if containerLen != 0 { - ft.DecMapUint8Float64L(*v, containerLen, d) - } - d.mapEnd() - } - case map[uint8]bool: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen != containerLenNil { - if containerLen != 0 { - ft.DecMapUint8BoolL(v, containerLen, d) - } - d.mapEnd() - } - case *map[uint8]bool: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen == containerLenNil { - *v = nil - } else { - if *v == nil { - *v = make(map[uint8]bool, decInferLen(containerLen, d.maxInitLen(), 2)) - } - if containerLen != 0 { - ft.DecMapUint8BoolL(*v, containerLen, d) - } - d.mapEnd() - } - case map[uint64]interface{}: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen != containerLenNil { - if containerLen != 0 { - ft.DecMapUint64IntfL(v, containerLen, d) - } - d.mapEnd() - } - case *map[uint64]interface{}: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen == containerLenNil { - *v = nil - } else { - if *v == nil { - *v = make(map[uint64]interface{}, decInferLen(containerLen, d.maxInitLen(), 24)) - } - if containerLen != 0 { - ft.DecMapUint64IntfL(*v, containerLen, d) - } - d.mapEnd() - } - case map[uint64]string: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen != containerLenNil { - if containerLen != 0 { - ft.DecMapUint64StringL(v, containerLen, d) - } - d.mapEnd() - } - case *map[uint64]string: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen == containerLenNil { - *v = nil - } else { - if *v == nil { - *v = make(map[uint64]string, decInferLen(containerLen, d.maxInitLen(), 24)) - } - if containerLen != 0 { - ft.DecMapUint64StringL(*v, containerLen, d) - } - d.mapEnd() - } - case map[uint64][]byte: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen != containerLenNil { - if containerLen != 0 { - ft.DecMapUint64BytesL(v, containerLen, d) - } - d.mapEnd() - } - case *map[uint64][]byte: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen == containerLenNil { - *v = nil - } else { - if *v == nil { - *v = make(map[uint64][]byte, decInferLen(containerLen, d.maxInitLen(), 32)) - } - if containerLen != 0 { - ft.DecMapUint64BytesL(*v, containerLen, d) - } - d.mapEnd() - } - case map[uint64]uint8: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen != containerLenNil { - if containerLen != 0 { - ft.DecMapUint64Uint8L(v, containerLen, d) - } - d.mapEnd() - } - case *map[uint64]uint8: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen == containerLenNil { - *v = nil - } else { - if *v == nil { - *v = make(map[uint64]uint8, decInferLen(containerLen, d.maxInitLen(), 9)) - } - if containerLen != 0 { - ft.DecMapUint64Uint8L(*v, containerLen, d) - } - d.mapEnd() - } - case map[uint64]uint64: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen != containerLenNil { - if containerLen != 0 { - ft.DecMapUint64Uint64L(v, containerLen, d) - } - d.mapEnd() - } - case *map[uint64]uint64: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen == containerLenNil { - *v = nil - } else { - if *v == nil { - *v = make(map[uint64]uint64, decInferLen(containerLen, d.maxInitLen(), 16)) - } - if containerLen != 0 { - ft.DecMapUint64Uint64L(*v, containerLen, d) - } - d.mapEnd() - } - case map[uint64]int: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen != containerLenNil { - if containerLen != 0 { - ft.DecMapUint64IntL(v, containerLen, d) - } - d.mapEnd() - } - case *map[uint64]int: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen == containerLenNil { - *v = nil - } else { - if *v == nil { - *v = make(map[uint64]int, decInferLen(containerLen, d.maxInitLen(), 16)) - } - if containerLen != 0 { - ft.DecMapUint64IntL(*v, containerLen, d) - } - d.mapEnd() - } - case map[uint64]int32: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen != containerLenNil { - if containerLen != 0 { - ft.DecMapUint64Int32L(v, containerLen, d) - } - d.mapEnd() - } - case *map[uint64]int32: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen == containerLenNil { - *v = nil - } else { - if *v == nil { - *v = make(map[uint64]int32, decInferLen(containerLen, d.maxInitLen(), 12)) - } - if containerLen != 0 { - ft.DecMapUint64Int32L(*v, containerLen, d) - } - d.mapEnd() - } - case map[uint64]float64: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen != containerLenNil { - if containerLen != 0 { - ft.DecMapUint64Float64L(v, containerLen, d) - } - d.mapEnd() - } - case *map[uint64]float64: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen == containerLenNil { - *v = nil - } else { - if *v == nil { - *v = make(map[uint64]float64, decInferLen(containerLen, d.maxInitLen(), 16)) - } - if containerLen != 0 { - ft.DecMapUint64Float64L(*v, containerLen, d) - } - d.mapEnd() - } - case map[uint64]bool: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen != containerLenNil { - if containerLen != 0 { - ft.DecMapUint64BoolL(v, containerLen, d) - } - d.mapEnd() - } - case *map[uint64]bool: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen == containerLenNil { - *v = nil - } else { - if *v == nil { - *v = make(map[uint64]bool, decInferLen(containerLen, d.maxInitLen(), 9)) - } - if containerLen != 0 { - ft.DecMapUint64BoolL(*v, containerLen, d) - } - d.mapEnd() - } - case map[int]interface{}: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen != containerLenNil { - if containerLen != 0 { - ft.DecMapIntIntfL(v, containerLen, d) - } - d.mapEnd() - } - case *map[int]interface{}: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen == containerLenNil { - *v = nil - } else { - if *v == nil { - *v = make(map[int]interface{}, decInferLen(containerLen, d.maxInitLen(), 24)) - } - if containerLen != 0 { - ft.DecMapIntIntfL(*v, containerLen, d) - } - d.mapEnd() - } - case map[int]string: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen != containerLenNil { - if containerLen != 0 { - ft.DecMapIntStringL(v, containerLen, d) - } - d.mapEnd() - } - case *map[int]string: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen == containerLenNil { - *v = nil - } else { - if *v == nil { - *v = make(map[int]string, decInferLen(containerLen, d.maxInitLen(), 24)) - } - if containerLen != 0 { - ft.DecMapIntStringL(*v, containerLen, d) - } - d.mapEnd() - } - case map[int][]byte: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen != containerLenNil { - if containerLen != 0 { - ft.DecMapIntBytesL(v, containerLen, d) - } - d.mapEnd() - } - case *map[int][]byte: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen == containerLenNil { - *v = nil - } else { - if *v == nil { - *v = make(map[int][]byte, decInferLen(containerLen, d.maxInitLen(), 32)) - } - if containerLen != 0 { - ft.DecMapIntBytesL(*v, containerLen, d) - } - d.mapEnd() - } - case map[int]uint8: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen != containerLenNil { - if containerLen != 0 { - ft.DecMapIntUint8L(v, containerLen, d) - } - d.mapEnd() - } - case *map[int]uint8: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen == containerLenNil { - *v = nil - } else { - if *v == nil { - *v = make(map[int]uint8, decInferLen(containerLen, d.maxInitLen(), 9)) - } - if containerLen != 0 { - ft.DecMapIntUint8L(*v, containerLen, d) - } - d.mapEnd() - } - case map[int]uint64: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen != containerLenNil { - if containerLen != 0 { - ft.DecMapIntUint64L(v, containerLen, d) - } - d.mapEnd() - } - case *map[int]uint64: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen == containerLenNil { - *v = nil - } else { - if *v == nil { - *v = make(map[int]uint64, decInferLen(containerLen, d.maxInitLen(), 16)) - } - if containerLen != 0 { - ft.DecMapIntUint64L(*v, containerLen, d) - } - d.mapEnd() - } - case map[int]int: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen != containerLenNil { - if containerLen != 0 { - ft.DecMapIntIntL(v, containerLen, d) - } - d.mapEnd() - } - case *map[int]int: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen == containerLenNil { - *v = nil - } else { - if *v == nil { - *v = make(map[int]int, decInferLen(containerLen, d.maxInitLen(), 16)) - } - if containerLen != 0 { - ft.DecMapIntIntL(*v, containerLen, d) - } - d.mapEnd() - } - case map[int]int32: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen != containerLenNil { - if containerLen != 0 { - ft.DecMapIntInt32L(v, containerLen, d) - } - d.mapEnd() - } - case *map[int]int32: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen == containerLenNil { - *v = nil - } else { - if *v == nil { - *v = make(map[int]int32, decInferLen(containerLen, d.maxInitLen(), 12)) - } - if containerLen != 0 { - ft.DecMapIntInt32L(*v, containerLen, d) - } - d.mapEnd() - } - case map[int]float64: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen != containerLenNil { - if containerLen != 0 { - ft.DecMapIntFloat64L(v, containerLen, d) - } - d.mapEnd() - } - case *map[int]float64: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen == containerLenNil { - *v = nil - } else { - if *v == nil { - *v = make(map[int]float64, decInferLen(containerLen, d.maxInitLen(), 16)) - } - if containerLen != 0 { - ft.DecMapIntFloat64L(*v, containerLen, d) - } - d.mapEnd() - } - case map[int]bool: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen != containerLenNil { - if containerLen != 0 { - ft.DecMapIntBoolL(v, containerLen, d) - } - d.mapEnd() - } - case *map[int]bool: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen == containerLenNil { - *v = nil - } else { - if *v == nil { - *v = make(map[int]bool, decInferLen(containerLen, d.maxInitLen(), 9)) - } - if containerLen != 0 { - ft.DecMapIntBoolL(*v, containerLen, d) - } - d.mapEnd() - } - case map[int32]interface{}: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen != containerLenNil { - if containerLen != 0 { - ft.DecMapInt32IntfL(v, containerLen, d) - } - d.mapEnd() - } - case *map[int32]interface{}: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen == containerLenNil { - *v = nil - } else { - if *v == nil { - *v = make(map[int32]interface{}, decInferLen(containerLen, d.maxInitLen(), 20)) - } - if containerLen != 0 { - ft.DecMapInt32IntfL(*v, containerLen, d) - } - d.mapEnd() - } - case map[int32]string: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen != containerLenNil { - if containerLen != 0 { - ft.DecMapInt32StringL(v, containerLen, d) - } - d.mapEnd() - } - case *map[int32]string: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen == containerLenNil { - *v = nil - } else { - if *v == nil { - *v = make(map[int32]string, decInferLen(containerLen, d.maxInitLen(), 20)) - } - if containerLen != 0 { - ft.DecMapInt32StringL(*v, containerLen, d) - } - d.mapEnd() - } - case map[int32][]byte: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen != containerLenNil { - if containerLen != 0 { - ft.DecMapInt32BytesL(v, containerLen, d) - } - d.mapEnd() - } - case *map[int32][]byte: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen == containerLenNil { - *v = nil - } else { - if *v == nil { - *v = make(map[int32][]byte, decInferLen(containerLen, d.maxInitLen(), 28)) - } - if containerLen != 0 { - ft.DecMapInt32BytesL(*v, containerLen, d) - } - d.mapEnd() - } - case map[int32]uint8: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen != containerLenNil { - if containerLen != 0 { - ft.DecMapInt32Uint8L(v, containerLen, d) - } - d.mapEnd() - } - case *map[int32]uint8: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen == containerLenNil { - *v = nil - } else { - if *v == nil { - *v = make(map[int32]uint8, decInferLen(containerLen, d.maxInitLen(), 5)) - } - if containerLen != 0 { - ft.DecMapInt32Uint8L(*v, containerLen, d) - } - d.mapEnd() - } - case map[int32]uint64: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen != containerLenNil { - if containerLen != 0 { - ft.DecMapInt32Uint64L(v, containerLen, d) - } - d.mapEnd() - } - case *map[int32]uint64: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen == containerLenNil { - *v = nil - } else { - if *v == nil { - *v = make(map[int32]uint64, decInferLen(containerLen, d.maxInitLen(), 12)) - } - if containerLen != 0 { - ft.DecMapInt32Uint64L(*v, containerLen, d) - } - d.mapEnd() - } - case map[int32]int: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen != containerLenNil { - if containerLen != 0 { - ft.DecMapInt32IntL(v, containerLen, d) - } - d.mapEnd() - } - case *map[int32]int: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen == containerLenNil { - *v = nil - } else { - if *v == nil { - *v = make(map[int32]int, decInferLen(containerLen, d.maxInitLen(), 12)) - } - if containerLen != 0 { - ft.DecMapInt32IntL(*v, containerLen, d) - } - d.mapEnd() - } - case map[int32]int32: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen != containerLenNil { - if containerLen != 0 { - ft.DecMapInt32Int32L(v, containerLen, d) - } - d.mapEnd() - } - case *map[int32]int32: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen == containerLenNil { - *v = nil - } else { - if *v == nil { - *v = make(map[int32]int32, decInferLen(containerLen, d.maxInitLen(), 8)) - } - if containerLen != 0 { - ft.DecMapInt32Int32L(*v, containerLen, d) - } - d.mapEnd() - } - case map[int32]float64: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen != containerLenNil { - if containerLen != 0 { - ft.DecMapInt32Float64L(v, containerLen, d) - } - d.mapEnd() - } - case *map[int32]float64: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen == containerLenNil { - *v = nil - } else { - if *v == nil { - *v = make(map[int32]float64, decInferLen(containerLen, d.maxInitLen(), 12)) - } - if containerLen != 0 { - ft.DecMapInt32Float64L(*v, containerLen, d) - } - d.mapEnd() - } - case map[int32]bool: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen != containerLenNil { - if containerLen != 0 { - ft.DecMapInt32BoolL(v, containerLen, d) - } - d.mapEnd() - } - case *map[int32]bool: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen == containerLenNil { - *v = nil - } else { - if *v == nil { - *v = make(map[int32]bool, decInferLen(containerLen, d.maxInitLen(), 5)) - } - if containerLen != 0 { - ft.DecMapInt32BoolL(*v, containerLen, d) - } - d.mapEnd() - } - default: - _ = v - return false - } - return true -} - -func (d *decoderJsonBytes) fastpathDecSliceIntfR(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTJsonBytes - switch rv.Kind() { - case reflect.Ptr: - v := rv2i(rv).(*[]interface{}) - if vv, changed := ft.DecSliceIntfY(*v, d); changed { - *v = vv - } - case reflect.Array: - var v []interface{} - rvGetSlice4Array(rv, &v) - ft.DecSliceIntfN(v, d) - default: - ft.DecSliceIntfN(rv2i(rv).([]interface{}), d) - } -} -func (fastpathDTJsonBytes) DecSliceIntfY(v []interface{}, d *decoderJsonBytes) (v2 []interface{}, changed bool) { - ctyp := d.d.ContainerType() - if ctyp == valueTypeNil { - return nil, v != nil - } - var containerLenS int - isArray := ctyp == valueTypeArray - if isArray { - containerLenS = d.arrayStart(d.d.ReadArrayStart()) - } else if ctyp == valueTypeMap { - containerLenS = d.mapStart(d.d.ReadMapStart()) * 2 - } else { - halt.errorStr2("decoding into a slice, expect map/array - got ", ctyp.String()) - } - hasLen := containerLenS >= 0 - var j int - fnv := func(dst []interface{}) { v, changed = dst, true } - for ; d.containerNext(j, containerLenS, hasLen); j++ { - if j == 0 { - if containerLenS == len(v) { - } else if containerLenS < 0 || containerLenS > cap(v) { - if xlen := int(decInferLen(containerLenS, d.maxInitLen(), 16)); xlen <= cap(v) { - fnv(v[:uint(xlen)]) - } else { - v2 = make([]interface{}, uint(xlen)) - copy(v2, v) - fnv(v2) - } - } else { - fnv(v[:containerLenS]) - } - } - if isArray { - d.arrayElem(j == 0) - } else if j&1 == 0 { - d.mapElemKey(j == 0) - } else { - d.mapElemValue() - } - if j >= len(v) { - fnv(append(v, nil)) - } - d.decode(&v[uint(j)]) - } - if j < len(v) { - fnv(v[:uint(j)]) - } else if j == 0 && v == nil { - fnv([]interface{}{}) - } - if isArray { - d.arrayEnd() - } else { - d.mapEnd() - } - return v, changed -} -func (fastpathDTJsonBytes) DecSliceIntfN(v []interface{}, d *decoderJsonBytes) { - ctyp := d.d.ContainerType() - if ctyp == valueTypeNil { - return - } - var containerLenS int - isArray := ctyp == valueTypeArray - if isArray { - containerLenS = d.arrayStart(d.d.ReadArrayStart()) - } else if ctyp == valueTypeMap { - containerLenS = d.mapStart(d.d.ReadMapStart()) * 2 - } else { - halt.errorStr2("decoding into a slice, expect map/array - got ", ctyp.String()) - } - hasLen := containerLenS >= 0 - for j := 0; d.containerNext(j, containerLenS, hasLen); j++ { - if isArray { - d.arrayElem(j == 0) - } else if j&1 == 0 { - d.mapElemKey(j == 0) - } else { - d.mapElemValue() - } - if j < len(v) { - d.decode(&v[uint(j)]) - } else { - d.arrayCannotExpand(len(v), j+1) - d.swallow() - } - } - if isArray { - d.arrayEnd() - } else { - d.mapEnd() - } -} - -func (d *decoderJsonBytes) fastpathDecSliceStringR(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTJsonBytes - switch rv.Kind() { - case reflect.Ptr: - v := rv2i(rv).(*[]string) - if vv, changed := ft.DecSliceStringY(*v, d); changed { - *v = vv - } - case reflect.Array: - var v []string - rvGetSlice4Array(rv, &v) - ft.DecSliceStringN(v, d) - default: - ft.DecSliceStringN(rv2i(rv).([]string), d) - } -} -func (fastpathDTJsonBytes) DecSliceStringY(v []string, d *decoderJsonBytes) (v2 []string, changed bool) { - ctyp := d.d.ContainerType() - if ctyp == valueTypeNil { - return nil, v != nil - } - var containerLenS int - isArray := ctyp == valueTypeArray - if isArray { - containerLenS = d.arrayStart(d.d.ReadArrayStart()) - } else if ctyp == valueTypeMap { - containerLenS = d.mapStart(d.d.ReadMapStart()) * 2 - } else { - halt.errorStr2("decoding into a slice, expect map/array - got ", ctyp.String()) - } - hasLen := containerLenS >= 0 - var j int - fnv := func(dst []string) { v, changed = dst, true } - for ; d.containerNext(j, containerLenS, hasLen); j++ { - if j == 0 { - if containerLenS == len(v) { - } else if containerLenS < 0 || containerLenS > cap(v) { - if xlen := int(decInferLen(containerLenS, d.maxInitLen(), 16)); xlen <= cap(v) { - fnv(v[:uint(xlen)]) - } else { - v2 = make([]string, uint(xlen)) - copy(v2, v) - fnv(v2) - } - } else { - fnv(v[:containerLenS]) - } - } - if isArray { - d.arrayElem(j == 0) - } else if j&1 == 0 { - d.mapElemKey(j == 0) - } else { - d.mapElemValue() - } - if j >= len(v) { - fnv(append(v, "")) - } - v[uint(j)] = d.detach2Str(d.d.DecodeStringAsBytes()) - } - if j < len(v) { - fnv(v[:uint(j)]) - } else if j == 0 && v == nil { - fnv([]string{}) - } - if isArray { - d.arrayEnd() - } else { - d.mapEnd() - } - return v, changed -} -func (fastpathDTJsonBytes) DecSliceStringN(v []string, d *decoderJsonBytes) { - ctyp := d.d.ContainerType() - if ctyp == valueTypeNil { - return - } - var containerLenS int - isArray := ctyp == valueTypeArray - if isArray { - containerLenS = d.arrayStart(d.d.ReadArrayStart()) - } else if ctyp == valueTypeMap { - containerLenS = d.mapStart(d.d.ReadMapStart()) * 2 - } else { - halt.errorStr2("decoding into a slice, expect map/array - got ", ctyp.String()) - } - hasLen := containerLenS >= 0 - for j := 0; d.containerNext(j, containerLenS, hasLen); j++ { - if isArray { - d.arrayElem(j == 0) - } else if j&1 == 0 { - d.mapElemKey(j == 0) - } else { - d.mapElemValue() - } - if j < len(v) { - v[uint(j)] = d.detach2Str(d.d.DecodeStringAsBytes()) - } else { - d.arrayCannotExpand(len(v), j+1) - d.swallow() - } - } - if isArray { - d.arrayEnd() - } else { - d.mapEnd() - } -} - -func (d *decoderJsonBytes) fastpathDecSliceBytesR(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTJsonBytes - switch rv.Kind() { - case reflect.Ptr: - v := rv2i(rv).(*[][]byte) - if vv, changed := ft.DecSliceBytesY(*v, d); changed { - *v = vv - } - case reflect.Array: - var v [][]byte - rvGetSlice4Array(rv, &v) - ft.DecSliceBytesN(v, d) - default: - ft.DecSliceBytesN(rv2i(rv).([][]byte), d) - } -} -func (fastpathDTJsonBytes) DecSliceBytesY(v [][]byte, d *decoderJsonBytes) (v2 [][]byte, changed bool) { - ctyp := d.d.ContainerType() - if ctyp == valueTypeNil { - return nil, v != nil - } - var containerLenS int - isArray := ctyp == valueTypeArray - if isArray { - containerLenS = d.arrayStart(d.d.ReadArrayStart()) - } else if ctyp == valueTypeMap { - containerLenS = d.mapStart(d.d.ReadMapStart()) * 2 - } else { - halt.errorStr2("decoding into a slice, expect map/array - got ", ctyp.String()) - } - hasLen := containerLenS >= 0 - var j int - fnv := func(dst [][]byte) { v, changed = dst, true } - for ; d.containerNext(j, containerLenS, hasLen); j++ { - if j == 0 { - if containerLenS == len(v) { - } else if containerLenS < 0 || containerLenS > cap(v) { - if xlen := int(decInferLen(containerLenS, d.maxInitLen(), 24)); xlen <= cap(v) { - fnv(v[:uint(xlen)]) - } else { - v2 = make([][]byte, uint(xlen)) - copy(v2, v) - fnv(v2) - } - } else { - fnv(v[:containerLenS]) - } - } - if isArray { - d.arrayElem(j == 0) - } else if j&1 == 0 { - d.mapElemKey(j == 0) - } else { - d.mapElemValue() - } - if j >= len(v) { - fnv(append(v, nil)) - } - v[uint(j)] = bytesOKdbi(d.decodeBytesInto(v[uint(j)], false)) - } - if j < len(v) { - fnv(v[:uint(j)]) - } else if j == 0 && v == nil { - fnv([][]byte{}) - } - if isArray { - d.arrayEnd() - } else { - d.mapEnd() - } - return v, changed -} -func (fastpathDTJsonBytes) DecSliceBytesN(v [][]byte, d *decoderJsonBytes) { - ctyp := d.d.ContainerType() - if ctyp == valueTypeNil { - return - } - var containerLenS int - isArray := ctyp == valueTypeArray - if isArray { - containerLenS = d.arrayStart(d.d.ReadArrayStart()) - } else if ctyp == valueTypeMap { - containerLenS = d.mapStart(d.d.ReadMapStart()) * 2 - } else { - halt.errorStr2("decoding into a slice, expect map/array - got ", ctyp.String()) - } - hasLen := containerLenS >= 0 - for j := 0; d.containerNext(j, containerLenS, hasLen); j++ { - if isArray { - d.arrayElem(j == 0) - } else if j&1 == 0 { - d.mapElemKey(j == 0) - } else { - d.mapElemValue() - } - if j < len(v) { - v[uint(j)] = bytesOKdbi(d.decodeBytesInto(v[uint(j)], false)) - } else { - d.arrayCannotExpand(len(v), j+1) - d.swallow() - } - } - if isArray { - d.arrayEnd() - } else { - d.mapEnd() - } -} - -func (d *decoderJsonBytes) fastpathDecSliceFloat32R(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTJsonBytes - switch rv.Kind() { - case reflect.Ptr: - v := rv2i(rv).(*[]float32) - if vv, changed := ft.DecSliceFloat32Y(*v, d); changed { - *v = vv - } - case reflect.Array: - var v []float32 - rvGetSlice4Array(rv, &v) - ft.DecSliceFloat32N(v, d) - default: - ft.DecSliceFloat32N(rv2i(rv).([]float32), d) - } -} -func (fastpathDTJsonBytes) DecSliceFloat32Y(v []float32, d *decoderJsonBytes) (v2 []float32, changed bool) { - ctyp := d.d.ContainerType() - if ctyp == valueTypeNil { - return nil, v != nil - } - var containerLenS int - isArray := ctyp == valueTypeArray - if isArray { - containerLenS = d.arrayStart(d.d.ReadArrayStart()) - } else if ctyp == valueTypeMap { - containerLenS = d.mapStart(d.d.ReadMapStart()) * 2 - } else { - halt.errorStr2("decoding into a slice, expect map/array - got ", ctyp.String()) - } - hasLen := containerLenS >= 0 - var j int - fnv := func(dst []float32) { v, changed = dst, true } - for ; d.containerNext(j, containerLenS, hasLen); j++ { - if j == 0 { - if containerLenS == len(v) { - } else if containerLenS < 0 || containerLenS > cap(v) { - if xlen := int(decInferLen(containerLenS, d.maxInitLen(), 4)); xlen <= cap(v) { - fnv(v[:uint(xlen)]) - } else { - v2 = make([]float32, uint(xlen)) - copy(v2, v) - fnv(v2) - } - } else { - fnv(v[:containerLenS]) - } - } - if isArray { - d.arrayElem(j == 0) - } else if j&1 == 0 { - d.mapElemKey(j == 0) - } else { - d.mapElemValue() - } - if j >= len(v) { - fnv(append(v, 0)) - } - v[uint(j)] = float32(d.d.DecodeFloat32()) - } - if j < len(v) { - fnv(v[:uint(j)]) - } else if j == 0 && v == nil { - fnv([]float32{}) - } - if isArray { - d.arrayEnd() - } else { - d.mapEnd() - } - return v, changed -} -func (fastpathDTJsonBytes) DecSliceFloat32N(v []float32, d *decoderJsonBytes) { - ctyp := d.d.ContainerType() - if ctyp == valueTypeNil { - return - } - var containerLenS int - isArray := ctyp == valueTypeArray - if isArray { - containerLenS = d.arrayStart(d.d.ReadArrayStart()) - } else if ctyp == valueTypeMap { - containerLenS = d.mapStart(d.d.ReadMapStart()) * 2 - } else { - halt.errorStr2("decoding into a slice, expect map/array - got ", ctyp.String()) - } - hasLen := containerLenS >= 0 - for j := 0; d.containerNext(j, containerLenS, hasLen); j++ { - if isArray { - d.arrayElem(j == 0) - } else if j&1 == 0 { - d.mapElemKey(j == 0) - } else { - d.mapElemValue() - } - if j < len(v) { - v[uint(j)] = float32(d.d.DecodeFloat32()) - } else { - d.arrayCannotExpand(len(v), j+1) - d.swallow() - } - } - if isArray { - d.arrayEnd() - } else { - d.mapEnd() - } -} - -func (d *decoderJsonBytes) fastpathDecSliceFloat64R(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTJsonBytes - switch rv.Kind() { - case reflect.Ptr: - v := rv2i(rv).(*[]float64) - if vv, changed := ft.DecSliceFloat64Y(*v, d); changed { - *v = vv - } - case reflect.Array: - var v []float64 - rvGetSlice4Array(rv, &v) - ft.DecSliceFloat64N(v, d) - default: - ft.DecSliceFloat64N(rv2i(rv).([]float64), d) - } -} -func (fastpathDTJsonBytes) DecSliceFloat64Y(v []float64, d *decoderJsonBytes) (v2 []float64, changed bool) { - ctyp := d.d.ContainerType() - if ctyp == valueTypeNil { - return nil, v != nil - } - var containerLenS int - isArray := ctyp == valueTypeArray - if isArray { - containerLenS = d.arrayStart(d.d.ReadArrayStart()) - } else if ctyp == valueTypeMap { - containerLenS = d.mapStart(d.d.ReadMapStart()) * 2 - } else { - halt.errorStr2("decoding into a slice, expect map/array - got ", ctyp.String()) - } - hasLen := containerLenS >= 0 - var j int - fnv := func(dst []float64) { v, changed = dst, true } - for ; d.containerNext(j, containerLenS, hasLen); j++ { - if j == 0 { - if containerLenS == len(v) { - } else if containerLenS < 0 || containerLenS > cap(v) { - if xlen := int(decInferLen(containerLenS, d.maxInitLen(), 8)); xlen <= cap(v) { - fnv(v[:uint(xlen)]) - } else { - v2 = make([]float64, uint(xlen)) - copy(v2, v) - fnv(v2) - } - } else { - fnv(v[:containerLenS]) - } - } - if isArray { - d.arrayElem(j == 0) - } else if j&1 == 0 { - d.mapElemKey(j == 0) - } else { - d.mapElemValue() - } - if j >= len(v) { - fnv(append(v, 0)) - } - v[uint(j)] = d.d.DecodeFloat64() - } - if j < len(v) { - fnv(v[:uint(j)]) - } else if j == 0 && v == nil { - fnv([]float64{}) - } - if isArray { - d.arrayEnd() - } else { - d.mapEnd() - } - return v, changed -} -func (fastpathDTJsonBytes) DecSliceFloat64N(v []float64, d *decoderJsonBytes) { - ctyp := d.d.ContainerType() - if ctyp == valueTypeNil { - return - } - var containerLenS int - isArray := ctyp == valueTypeArray - if isArray { - containerLenS = d.arrayStart(d.d.ReadArrayStart()) - } else if ctyp == valueTypeMap { - containerLenS = d.mapStart(d.d.ReadMapStart()) * 2 - } else { - halt.errorStr2("decoding into a slice, expect map/array - got ", ctyp.String()) - } - hasLen := containerLenS >= 0 - for j := 0; d.containerNext(j, containerLenS, hasLen); j++ { - if isArray { - d.arrayElem(j == 0) - } else if j&1 == 0 { - d.mapElemKey(j == 0) - } else { - d.mapElemValue() - } - if j < len(v) { - v[uint(j)] = d.d.DecodeFloat64() - } else { - d.arrayCannotExpand(len(v), j+1) - d.swallow() - } - } - if isArray { - d.arrayEnd() - } else { - d.mapEnd() - } -} - -func (d *decoderJsonBytes) fastpathDecSliceUint8R(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTJsonBytes - switch rv.Kind() { - case reflect.Ptr: - v := rv2i(rv).(*[]uint8) - if vv, changed := ft.DecSliceUint8Y(*v, d); changed { - *v = vv - } - case reflect.Array: - var v []uint8 - rvGetSlice4Array(rv, &v) - ft.DecSliceUint8N(v, d) - default: - ft.DecSliceUint8N(rv2i(rv).([]uint8), d) - } -} -func (fastpathDTJsonBytes) DecSliceUint8Y(v []uint8, d *decoderJsonBytes) (v2 []uint8, changed bool) { - ctyp := d.d.ContainerType() - if ctyp == valueTypeNil { - return nil, v != nil - } - if ctyp != valueTypeMap { - var dbi dBytesIntoState - v2, dbi = d.decodeBytesInto(v[:len(v):len(v)], false) - return v2, dbi != dBytesIntoParamOut - } - containerLenS := d.mapStart(d.d.ReadMapStart()) * 2 - hasLen := containerLenS >= 0 - var j int - fnv := func(dst []uint8) { v, changed = dst, true } - for ; d.containerNext(j, containerLenS, hasLen); j++ { - if j == 0 { - if containerLenS == len(v) { - } else if containerLenS < 0 || containerLenS > cap(v) { - if xlen := int(decInferLen(containerLenS, d.maxInitLen(), 1)); xlen <= cap(v) { - fnv(v[:uint(xlen)]) - } else { - v2 = make([]uint8, uint(xlen)) - copy(v2, v) - fnv(v2) - } - } else { - fnv(v[:containerLenS]) - } - } - if j&1 == 0 { - d.mapElemKey(j == 0) - } else { - d.mapElemValue() - } - if j >= len(v) { - fnv(append(v, 0)) - } - v[uint(j)] = uint8(chkOvf.UintV(d.d.DecodeUint64(), 8)) - } - if j < len(v) { - fnv(v[:uint(j)]) - } else if j == 0 && v == nil { - fnv([]uint8{}) - } - d.mapEnd() - return v, changed -} -func (fastpathDTJsonBytes) DecSliceUint8N(v []uint8, d *decoderJsonBytes) { - ctyp := d.d.ContainerType() - if ctyp == valueTypeNil { - return - } - if ctyp != valueTypeMap { - d.decodeBytesInto(v[:len(v):len(v)], true) - return - } - containerLenS := d.mapStart(d.d.ReadMapStart()) * 2 - hasLen := containerLenS >= 0 - for j := 0; d.containerNext(j, containerLenS, hasLen); j++ { - if j&1 == 0 { - d.mapElemKey(j == 0) - } else { - d.mapElemValue() - } - if j < len(v) { - v[uint(j)] = uint8(chkOvf.UintV(d.d.DecodeUint64(), 8)) - } else { - d.arrayCannotExpand(len(v), j+1) - d.swallow() - } - } - d.mapEnd() -} - -func (d *decoderJsonBytes) fastpathDecSliceUint64R(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTJsonBytes - switch rv.Kind() { - case reflect.Ptr: - v := rv2i(rv).(*[]uint64) - if vv, changed := ft.DecSliceUint64Y(*v, d); changed { - *v = vv - } - case reflect.Array: - var v []uint64 - rvGetSlice4Array(rv, &v) - ft.DecSliceUint64N(v, d) - default: - ft.DecSliceUint64N(rv2i(rv).([]uint64), d) - } -} -func (fastpathDTJsonBytes) DecSliceUint64Y(v []uint64, d *decoderJsonBytes) (v2 []uint64, changed bool) { - ctyp := d.d.ContainerType() - if ctyp == valueTypeNil { - return nil, v != nil - } - var containerLenS int - isArray := ctyp == valueTypeArray - if isArray { - containerLenS = d.arrayStart(d.d.ReadArrayStart()) - } else if ctyp == valueTypeMap { - containerLenS = d.mapStart(d.d.ReadMapStart()) * 2 - } else { - halt.errorStr2("decoding into a slice, expect map/array - got ", ctyp.String()) - } - hasLen := containerLenS >= 0 - var j int - fnv := func(dst []uint64) { v, changed = dst, true } - for ; d.containerNext(j, containerLenS, hasLen); j++ { - if j == 0 { - if containerLenS == len(v) { - } else if containerLenS < 0 || containerLenS > cap(v) { - if xlen := int(decInferLen(containerLenS, d.maxInitLen(), 8)); xlen <= cap(v) { - fnv(v[:uint(xlen)]) - } else { - v2 = make([]uint64, uint(xlen)) - copy(v2, v) - fnv(v2) - } - } else { - fnv(v[:containerLenS]) - } - } - if isArray { - d.arrayElem(j == 0) - } else if j&1 == 0 { - d.mapElemKey(j == 0) - } else { - d.mapElemValue() - } - if j >= len(v) { - fnv(append(v, 0)) - } - v[uint(j)] = d.d.DecodeUint64() - } - if j < len(v) { - fnv(v[:uint(j)]) - } else if j == 0 && v == nil { - fnv([]uint64{}) - } - if isArray { - d.arrayEnd() - } else { - d.mapEnd() - } - return v, changed -} -func (fastpathDTJsonBytes) DecSliceUint64N(v []uint64, d *decoderJsonBytes) { - ctyp := d.d.ContainerType() - if ctyp == valueTypeNil { - return - } - var containerLenS int - isArray := ctyp == valueTypeArray - if isArray { - containerLenS = d.arrayStart(d.d.ReadArrayStart()) - } else if ctyp == valueTypeMap { - containerLenS = d.mapStart(d.d.ReadMapStart()) * 2 - } else { - halt.errorStr2("decoding into a slice, expect map/array - got ", ctyp.String()) - } - hasLen := containerLenS >= 0 - for j := 0; d.containerNext(j, containerLenS, hasLen); j++ { - if isArray { - d.arrayElem(j == 0) - } else if j&1 == 0 { - d.mapElemKey(j == 0) - } else { - d.mapElemValue() - } - if j < len(v) { - v[uint(j)] = d.d.DecodeUint64() - } else { - d.arrayCannotExpand(len(v), j+1) - d.swallow() - } - } - if isArray { - d.arrayEnd() - } else { - d.mapEnd() - } -} - -func (d *decoderJsonBytes) fastpathDecSliceIntR(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTJsonBytes - switch rv.Kind() { - case reflect.Ptr: - v := rv2i(rv).(*[]int) - if vv, changed := ft.DecSliceIntY(*v, d); changed { - *v = vv - } - case reflect.Array: - var v []int - rvGetSlice4Array(rv, &v) - ft.DecSliceIntN(v, d) - default: - ft.DecSliceIntN(rv2i(rv).([]int), d) - } -} -func (fastpathDTJsonBytes) DecSliceIntY(v []int, d *decoderJsonBytes) (v2 []int, changed bool) { - ctyp := d.d.ContainerType() - if ctyp == valueTypeNil { - return nil, v != nil - } - var containerLenS int - isArray := ctyp == valueTypeArray - if isArray { - containerLenS = d.arrayStart(d.d.ReadArrayStart()) - } else if ctyp == valueTypeMap { - containerLenS = d.mapStart(d.d.ReadMapStart()) * 2 - } else { - halt.errorStr2("decoding into a slice, expect map/array - got ", ctyp.String()) - } - hasLen := containerLenS >= 0 - var j int - fnv := func(dst []int) { v, changed = dst, true } - for ; d.containerNext(j, containerLenS, hasLen); j++ { - if j == 0 { - if containerLenS == len(v) { - } else if containerLenS < 0 || containerLenS > cap(v) { - if xlen := int(decInferLen(containerLenS, d.maxInitLen(), 8)); xlen <= cap(v) { - fnv(v[:uint(xlen)]) - } else { - v2 = make([]int, uint(xlen)) - copy(v2, v) - fnv(v2) - } - } else { - fnv(v[:containerLenS]) - } - } - if isArray { - d.arrayElem(j == 0) - } else if j&1 == 0 { - d.mapElemKey(j == 0) - } else { - d.mapElemValue() - } - if j >= len(v) { - fnv(append(v, 0)) - } - v[uint(j)] = int(chkOvf.IntV(d.d.DecodeInt64(), intBitsize)) - } - if j < len(v) { - fnv(v[:uint(j)]) - } else if j == 0 && v == nil { - fnv([]int{}) - } - if isArray { - d.arrayEnd() - } else { - d.mapEnd() - } - return v, changed -} -func (fastpathDTJsonBytes) DecSliceIntN(v []int, d *decoderJsonBytes) { - ctyp := d.d.ContainerType() - if ctyp == valueTypeNil { - return - } - var containerLenS int - isArray := ctyp == valueTypeArray - if isArray { - containerLenS = d.arrayStart(d.d.ReadArrayStart()) - } else if ctyp == valueTypeMap { - containerLenS = d.mapStart(d.d.ReadMapStart()) * 2 - } else { - halt.errorStr2("decoding into a slice, expect map/array - got ", ctyp.String()) - } - hasLen := containerLenS >= 0 - for j := 0; d.containerNext(j, containerLenS, hasLen); j++ { - if isArray { - d.arrayElem(j == 0) - } else if j&1 == 0 { - d.mapElemKey(j == 0) - } else { - d.mapElemValue() - } - if j < len(v) { - v[uint(j)] = int(chkOvf.IntV(d.d.DecodeInt64(), intBitsize)) - } else { - d.arrayCannotExpand(len(v), j+1) - d.swallow() - } - } - if isArray { - d.arrayEnd() - } else { - d.mapEnd() - } -} - -func (d *decoderJsonBytes) fastpathDecSliceInt32R(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTJsonBytes - switch rv.Kind() { - case reflect.Ptr: - v := rv2i(rv).(*[]int32) - if vv, changed := ft.DecSliceInt32Y(*v, d); changed { - *v = vv - } - case reflect.Array: - var v []int32 - rvGetSlice4Array(rv, &v) - ft.DecSliceInt32N(v, d) - default: - ft.DecSliceInt32N(rv2i(rv).([]int32), d) - } -} -func (fastpathDTJsonBytes) DecSliceInt32Y(v []int32, d *decoderJsonBytes) (v2 []int32, changed bool) { - ctyp := d.d.ContainerType() - if ctyp == valueTypeNil { - return nil, v != nil - } - var containerLenS int - isArray := ctyp == valueTypeArray - if isArray { - containerLenS = d.arrayStart(d.d.ReadArrayStart()) - } else if ctyp == valueTypeMap { - containerLenS = d.mapStart(d.d.ReadMapStart()) * 2 - } else { - halt.errorStr2("decoding into a slice, expect map/array - got ", ctyp.String()) - } - hasLen := containerLenS >= 0 - var j int - fnv := func(dst []int32) { v, changed = dst, true } - for ; d.containerNext(j, containerLenS, hasLen); j++ { - if j == 0 { - if containerLenS == len(v) { - } else if containerLenS < 0 || containerLenS > cap(v) { - if xlen := int(decInferLen(containerLenS, d.maxInitLen(), 4)); xlen <= cap(v) { - fnv(v[:uint(xlen)]) - } else { - v2 = make([]int32, uint(xlen)) - copy(v2, v) - fnv(v2) - } - } else { - fnv(v[:containerLenS]) - } - } - if isArray { - d.arrayElem(j == 0) - } else if j&1 == 0 { - d.mapElemKey(j == 0) - } else { - d.mapElemValue() - } - if j >= len(v) { - fnv(append(v, 0)) - } - v[uint(j)] = int32(chkOvf.IntV(d.d.DecodeInt64(), 32)) - } - if j < len(v) { - fnv(v[:uint(j)]) - } else if j == 0 && v == nil { - fnv([]int32{}) - } - if isArray { - d.arrayEnd() - } else { - d.mapEnd() - } - return v, changed -} -func (fastpathDTJsonBytes) DecSliceInt32N(v []int32, d *decoderJsonBytes) { - ctyp := d.d.ContainerType() - if ctyp == valueTypeNil { - return - } - var containerLenS int - isArray := ctyp == valueTypeArray - if isArray { - containerLenS = d.arrayStart(d.d.ReadArrayStart()) - } else if ctyp == valueTypeMap { - containerLenS = d.mapStart(d.d.ReadMapStart()) * 2 - } else { - halt.errorStr2("decoding into a slice, expect map/array - got ", ctyp.String()) - } - hasLen := containerLenS >= 0 - for j := 0; d.containerNext(j, containerLenS, hasLen); j++ { - if isArray { - d.arrayElem(j == 0) - } else if j&1 == 0 { - d.mapElemKey(j == 0) - } else { - d.mapElemValue() - } - if j < len(v) { - v[uint(j)] = int32(chkOvf.IntV(d.d.DecodeInt64(), 32)) - } else { - d.arrayCannotExpand(len(v), j+1) - d.swallow() - } - } - if isArray { - d.arrayEnd() - } else { - d.mapEnd() - } -} - -func (d *decoderJsonBytes) fastpathDecSliceInt64R(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTJsonBytes - switch rv.Kind() { - case reflect.Ptr: - v := rv2i(rv).(*[]int64) - if vv, changed := ft.DecSliceInt64Y(*v, d); changed { - *v = vv - } - case reflect.Array: - var v []int64 - rvGetSlice4Array(rv, &v) - ft.DecSliceInt64N(v, d) - default: - ft.DecSliceInt64N(rv2i(rv).([]int64), d) - } -} -func (fastpathDTJsonBytes) DecSliceInt64Y(v []int64, d *decoderJsonBytes) (v2 []int64, changed bool) { - ctyp := d.d.ContainerType() - if ctyp == valueTypeNil { - return nil, v != nil - } - var containerLenS int - isArray := ctyp == valueTypeArray - if isArray { - containerLenS = d.arrayStart(d.d.ReadArrayStart()) - } else if ctyp == valueTypeMap { - containerLenS = d.mapStart(d.d.ReadMapStart()) * 2 - } else { - halt.errorStr2("decoding into a slice, expect map/array - got ", ctyp.String()) - } - hasLen := containerLenS >= 0 - var j int - fnv := func(dst []int64) { v, changed = dst, true } - for ; d.containerNext(j, containerLenS, hasLen); j++ { - if j == 0 { - if containerLenS == len(v) { - } else if containerLenS < 0 || containerLenS > cap(v) { - if xlen := int(decInferLen(containerLenS, d.maxInitLen(), 8)); xlen <= cap(v) { - fnv(v[:uint(xlen)]) - } else { - v2 = make([]int64, uint(xlen)) - copy(v2, v) - fnv(v2) - } - } else { - fnv(v[:containerLenS]) - } - } - if isArray { - d.arrayElem(j == 0) - } else if j&1 == 0 { - d.mapElemKey(j == 0) - } else { - d.mapElemValue() - } - if j >= len(v) { - fnv(append(v, 0)) - } - v[uint(j)] = d.d.DecodeInt64() - } - if j < len(v) { - fnv(v[:uint(j)]) - } else if j == 0 && v == nil { - fnv([]int64{}) - } - if isArray { - d.arrayEnd() - } else { - d.mapEnd() - } - return v, changed -} -func (fastpathDTJsonBytes) DecSliceInt64N(v []int64, d *decoderJsonBytes) { - ctyp := d.d.ContainerType() - if ctyp == valueTypeNil { - return - } - var containerLenS int - isArray := ctyp == valueTypeArray - if isArray { - containerLenS = d.arrayStart(d.d.ReadArrayStart()) - } else if ctyp == valueTypeMap { - containerLenS = d.mapStart(d.d.ReadMapStart()) * 2 - } else { - halt.errorStr2("decoding into a slice, expect map/array - got ", ctyp.String()) - } - hasLen := containerLenS >= 0 - for j := 0; d.containerNext(j, containerLenS, hasLen); j++ { - if isArray { - d.arrayElem(j == 0) - } else if j&1 == 0 { - d.mapElemKey(j == 0) - } else { - d.mapElemValue() - } - if j < len(v) { - v[uint(j)] = d.d.DecodeInt64() - } else { - d.arrayCannotExpand(len(v), j+1) - d.swallow() - } - } - if isArray { - d.arrayEnd() - } else { - d.mapEnd() - } -} - -func (d *decoderJsonBytes) fastpathDecSliceBoolR(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTJsonBytes - switch rv.Kind() { - case reflect.Ptr: - v := rv2i(rv).(*[]bool) - if vv, changed := ft.DecSliceBoolY(*v, d); changed { - *v = vv - } - case reflect.Array: - var v []bool - rvGetSlice4Array(rv, &v) - ft.DecSliceBoolN(v, d) - default: - ft.DecSliceBoolN(rv2i(rv).([]bool), d) - } -} -func (fastpathDTJsonBytes) DecSliceBoolY(v []bool, d *decoderJsonBytes) (v2 []bool, changed bool) { - ctyp := d.d.ContainerType() - if ctyp == valueTypeNil { - return nil, v != nil - } - var containerLenS int - isArray := ctyp == valueTypeArray - if isArray { - containerLenS = d.arrayStart(d.d.ReadArrayStart()) - } else if ctyp == valueTypeMap { - containerLenS = d.mapStart(d.d.ReadMapStart()) * 2 - } else { - halt.errorStr2("decoding into a slice, expect map/array - got ", ctyp.String()) - } - hasLen := containerLenS >= 0 - var j int - fnv := func(dst []bool) { v, changed = dst, true } - for ; d.containerNext(j, containerLenS, hasLen); j++ { - if j == 0 { - if containerLenS == len(v) { - } else if containerLenS < 0 || containerLenS > cap(v) { - if xlen := int(decInferLen(containerLenS, d.maxInitLen(), 1)); xlen <= cap(v) { - fnv(v[:uint(xlen)]) - } else { - v2 = make([]bool, uint(xlen)) - copy(v2, v) - fnv(v2) - } - } else { - fnv(v[:containerLenS]) - } - } - if isArray { - d.arrayElem(j == 0) - } else if j&1 == 0 { - d.mapElemKey(j == 0) - } else { - d.mapElemValue() - } - if j >= len(v) { - fnv(append(v, false)) - } - v[uint(j)] = d.d.DecodeBool() - } - if j < len(v) { - fnv(v[:uint(j)]) - } else if j == 0 && v == nil { - fnv([]bool{}) - } - if isArray { - d.arrayEnd() - } else { - d.mapEnd() - } - return v, changed -} -func (fastpathDTJsonBytes) DecSliceBoolN(v []bool, d *decoderJsonBytes) { - ctyp := d.d.ContainerType() - if ctyp == valueTypeNil { - return - } - var containerLenS int - isArray := ctyp == valueTypeArray - if isArray { - containerLenS = d.arrayStart(d.d.ReadArrayStart()) - } else if ctyp == valueTypeMap { - containerLenS = d.mapStart(d.d.ReadMapStart()) * 2 - } else { - halt.errorStr2("decoding into a slice, expect map/array - got ", ctyp.String()) - } - hasLen := containerLenS >= 0 - for j := 0; d.containerNext(j, containerLenS, hasLen); j++ { - if isArray { - d.arrayElem(j == 0) - } else if j&1 == 0 { - d.mapElemKey(j == 0) - } else { - d.mapElemValue() - } - if j < len(v) { - v[uint(j)] = d.d.DecodeBool() - } else { - d.arrayCannotExpand(len(v), j+1) - d.swallow() - } - } - if isArray { - d.arrayEnd() - } else { - d.mapEnd() - } -} -func (d *decoderJsonBytes) fastpathDecMapStringIntfR(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTJsonBytes - containerLen := d.mapStart(d.d.ReadMapStart()) - if rv.Kind() == reflect.Ptr { - vp, _ := rv2i(rv).(*map[string]interface{}) - if *vp == nil { - *vp = make(map[string]interface{}, decInferLen(containerLen, d.maxInitLen(), 32)) - } - if containerLen != 0 { - ft.DecMapStringIntfL(*vp, containerLen, d) - } - } else if containerLen != 0 { - ft.DecMapStringIntfL(rv2i(rv).(map[string]interface{}), containerLen, d) - } - d.mapEnd() -} -func (fastpathDTJsonBytes) DecMapStringIntfL(v map[string]interface{}, containerLen int, d *decoderJsonBytes) { - if v == nil { - halt.errorInt("cannot decode into nil map[string]interface{} given stream length: ", int64(containerLen)) - } - var mv interface{} - mapGet := !d.h.MapValueReset && !d.h.InterfaceReset - hasLen := containerLen >= 0 - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - mk := d.detach2Str(d.d.DecodeStringAsBytes()) - d.mapElemValue() - if mapGet { - mv = v[mk] - } else { - mv = nil - } - d.decode(&mv) - v[mk] = mv - } -} -func (d *decoderJsonBytes) fastpathDecMapStringStringR(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTJsonBytes - containerLen := d.mapStart(d.d.ReadMapStart()) - if rv.Kind() == reflect.Ptr { - vp, _ := rv2i(rv).(*map[string]string) - if *vp == nil { - *vp = make(map[string]string, decInferLen(containerLen, d.maxInitLen(), 32)) - } - if containerLen != 0 { - ft.DecMapStringStringL(*vp, containerLen, d) - } - } else if containerLen != 0 { - ft.DecMapStringStringL(rv2i(rv).(map[string]string), containerLen, d) - } - d.mapEnd() -} -func (fastpathDTJsonBytes) DecMapStringStringL(v map[string]string, containerLen int, d *decoderJsonBytes) { - if v == nil { - halt.errorInt("cannot decode into nil map[string]string given stream length: ", int64(containerLen)) - } - hasLen := containerLen >= 0 - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - mk := d.detach2Str(d.d.DecodeStringAsBytes()) - d.mapElemValue() - v[mk] = d.detach2Str(d.d.DecodeStringAsBytes()) - } -} -func (d *decoderJsonBytes) fastpathDecMapStringBytesR(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTJsonBytes - containerLen := d.mapStart(d.d.ReadMapStart()) - if rv.Kind() == reflect.Ptr { - vp, _ := rv2i(rv).(*map[string][]byte) - if *vp == nil { - *vp = make(map[string][]byte, decInferLen(containerLen, d.maxInitLen(), 40)) - } - if containerLen != 0 { - ft.DecMapStringBytesL(*vp, containerLen, d) - } - } else if containerLen != 0 { - ft.DecMapStringBytesL(rv2i(rv).(map[string][]byte), containerLen, d) - } - d.mapEnd() -} -func (fastpathDTJsonBytes) DecMapStringBytesL(v map[string][]byte, containerLen int, d *decoderJsonBytes) { - if v == nil { - halt.errorInt("cannot decode into nil map[string][]byte given stream length: ", int64(containerLen)) - } - var mv []byte - mapGet := !d.h.MapValueReset - hasLen := containerLen >= 0 - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - mk := d.detach2Str(d.d.DecodeStringAsBytes()) - d.mapElemValue() - if mapGet { - mv = v[mk] - } else { - mv = nil - } - v[mk], _ = d.decodeBytesInto(mv, false) - } -} -func (d *decoderJsonBytes) fastpathDecMapStringUint8R(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTJsonBytes - containerLen := d.mapStart(d.d.ReadMapStart()) - if rv.Kind() == reflect.Ptr { - vp, _ := rv2i(rv).(*map[string]uint8) - if *vp == nil { - *vp = make(map[string]uint8, decInferLen(containerLen, d.maxInitLen(), 17)) - } - if containerLen != 0 { - ft.DecMapStringUint8L(*vp, containerLen, d) - } - } else if containerLen != 0 { - ft.DecMapStringUint8L(rv2i(rv).(map[string]uint8), containerLen, d) - } - d.mapEnd() -} -func (fastpathDTJsonBytes) DecMapStringUint8L(v map[string]uint8, containerLen int, d *decoderJsonBytes) { - if v == nil { - halt.errorInt("cannot decode into nil map[string]uint8 given stream length: ", int64(containerLen)) - } - hasLen := containerLen >= 0 - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - mk := d.detach2Str(d.d.DecodeStringAsBytes()) - d.mapElemValue() - v[mk] = uint8(chkOvf.UintV(d.d.DecodeUint64(), 8)) - } -} -func (d *decoderJsonBytes) fastpathDecMapStringUint64R(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTJsonBytes - containerLen := d.mapStart(d.d.ReadMapStart()) - if rv.Kind() == reflect.Ptr { - vp, _ := rv2i(rv).(*map[string]uint64) - if *vp == nil { - *vp = make(map[string]uint64, decInferLen(containerLen, d.maxInitLen(), 24)) - } - if containerLen != 0 { - ft.DecMapStringUint64L(*vp, containerLen, d) - } - } else if containerLen != 0 { - ft.DecMapStringUint64L(rv2i(rv).(map[string]uint64), containerLen, d) - } - d.mapEnd() -} -func (fastpathDTJsonBytes) DecMapStringUint64L(v map[string]uint64, containerLen int, d *decoderJsonBytes) { - if v == nil { - halt.errorInt("cannot decode into nil map[string]uint64 given stream length: ", int64(containerLen)) - } - hasLen := containerLen >= 0 - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - mk := d.detach2Str(d.d.DecodeStringAsBytes()) - d.mapElemValue() - v[mk] = d.d.DecodeUint64() - } -} -func (d *decoderJsonBytes) fastpathDecMapStringIntR(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTJsonBytes - containerLen := d.mapStart(d.d.ReadMapStart()) - if rv.Kind() == reflect.Ptr { - vp, _ := rv2i(rv).(*map[string]int) - if *vp == nil { - *vp = make(map[string]int, decInferLen(containerLen, d.maxInitLen(), 24)) - } - if containerLen != 0 { - ft.DecMapStringIntL(*vp, containerLen, d) - } - } else if containerLen != 0 { - ft.DecMapStringIntL(rv2i(rv).(map[string]int), containerLen, d) - } - d.mapEnd() -} -func (fastpathDTJsonBytes) DecMapStringIntL(v map[string]int, containerLen int, d *decoderJsonBytes) { - if v == nil { - halt.errorInt("cannot decode into nil map[string]int given stream length: ", int64(containerLen)) - } - hasLen := containerLen >= 0 - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - mk := d.detach2Str(d.d.DecodeStringAsBytes()) - d.mapElemValue() - v[mk] = int(chkOvf.IntV(d.d.DecodeInt64(), intBitsize)) - } -} -func (d *decoderJsonBytes) fastpathDecMapStringInt32R(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTJsonBytes - containerLen := d.mapStart(d.d.ReadMapStart()) - if rv.Kind() == reflect.Ptr { - vp, _ := rv2i(rv).(*map[string]int32) - if *vp == nil { - *vp = make(map[string]int32, decInferLen(containerLen, d.maxInitLen(), 20)) - } - if containerLen != 0 { - ft.DecMapStringInt32L(*vp, containerLen, d) - } - } else if containerLen != 0 { - ft.DecMapStringInt32L(rv2i(rv).(map[string]int32), containerLen, d) - } - d.mapEnd() -} -func (fastpathDTJsonBytes) DecMapStringInt32L(v map[string]int32, containerLen int, d *decoderJsonBytes) { - if v == nil { - halt.errorInt("cannot decode into nil map[string]int32 given stream length: ", int64(containerLen)) - } - hasLen := containerLen >= 0 - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - mk := d.detach2Str(d.d.DecodeStringAsBytes()) - d.mapElemValue() - v[mk] = int32(chkOvf.IntV(d.d.DecodeInt64(), 32)) - } -} -func (d *decoderJsonBytes) fastpathDecMapStringFloat64R(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTJsonBytes - containerLen := d.mapStart(d.d.ReadMapStart()) - if rv.Kind() == reflect.Ptr { - vp, _ := rv2i(rv).(*map[string]float64) - if *vp == nil { - *vp = make(map[string]float64, decInferLen(containerLen, d.maxInitLen(), 24)) - } - if containerLen != 0 { - ft.DecMapStringFloat64L(*vp, containerLen, d) - } - } else if containerLen != 0 { - ft.DecMapStringFloat64L(rv2i(rv).(map[string]float64), containerLen, d) - } - d.mapEnd() -} -func (fastpathDTJsonBytes) DecMapStringFloat64L(v map[string]float64, containerLen int, d *decoderJsonBytes) { - if v == nil { - halt.errorInt("cannot decode into nil map[string]float64 given stream length: ", int64(containerLen)) - } - hasLen := containerLen >= 0 - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - mk := d.detach2Str(d.d.DecodeStringAsBytes()) - d.mapElemValue() - v[mk] = d.d.DecodeFloat64() - } -} -func (d *decoderJsonBytes) fastpathDecMapStringBoolR(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTJsonBytes - containerLen := d.mapStart(d.d.ReadMapStart()) - if rv.Kind() == reflect.Ptr { - vp, _ := rv2i(rv).(*map[string]bool) - if *vp == nil { - *vp = make(map[string]bool, decInferLen(containerLen, d.maxInitLen(), 17)) - } - if containerLen != 0 { - ft.DecMapStringBoolL(*vp, containerLen, d) - } - } else if containerLen != 0 { - ft.DecMapStringBoolL(rv2i(rv).(map[string]bool), containerLen, d) - } - d.mapEnd() -} -func (fastpathDTJsonBytes) DecMapStringBoolL(v map[string]bool, containerLen int, d *decoderJsonBytes) { - if v == nil { - halt.errorInt("cannot decode into nil map[string]bool given stream length: ", int64(containerLen)) - } - hasLen := containerLen >= 0 - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - mk := d.detach2Str(d.d.DecodeStringAsBytes()) - d.mapElemValue() - v[mk] = d.d.DecodeBool() - } -} -func (d *decoderJsonBytes) fastpathDecMapUint8IntfR(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTJsonBytes - containerLen := d.mapStart(d.d.ReadMapStart()) - if rv.Kind() == reflect.Ptr { - vp, _ := rv2i(rv).(*map[uint8]interface{}) - if *vp == nil { - *vp = make(map[uint8]interface{}, decInferLen(containerLen, d.maxInitLen(), 17)) - } - if containerLen != 0 { - ft.DecMapUint8IntfL(*vp, containerLen, d) - } - } else if containerLen != 0 { - ft.DecMapUint8IntfL(rv2i(rv).(map[uint8]interface{}), containerLen, d) - } - d.mapEnd() -} -func (fastpathDTJsonBytes) DecMapUint8IntfL(v map[uint8]interface{}, containerLen int, d *decoderJsonBytes) { - if v == nil { - halt.errorInt("cannot decode into nil map[uint8]interface{} given stream length: ", int64(containerLen)) - } - var mv interface{} - mapGet := !d.h.MapValueReset && !d.h.InterfaceReset - hasLen := containerLen >= 0 - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - mk := uint8(chkOvf.UintV(d.d.DecodeUint64(), 8)) - d.mapElemValue() - if mapGet { - mv = v[mk] - } else { - mv = nil - } - d.decode(&mv) - v[mk] = mv - } -} -func (d *decoderJsonBytes) fastpathDecMapUint8StringR(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTJsonBytes - containerLen := d.mapStart(d.d.ReadMapStart()) - if rv.Kind() == reflect.Ptr { - vp, _ := rv2i(rv).(*map[uint8]string) - if *vp == nil { - *vp = make(map[uint8]string, decInferLen(containerLen, d.maxInitLen(), 17)) - } - if containerLen != 0 { - ft.DecMapUint8StringL(*vp, containerLen, d) - } - } else if containerLen != 0 { - ft.DecMapUint8StringL(rv2i(rv).(map[uint8]string), containerLen, d) - } - d.mapEnd() -} -func (fastpathDTJsonBytes) DecMapUint8StringL(v map[uint8]string, containerLen int, d *decoderJsonBytes) { - if v == nil { - halt.errorInt("cannot decode into nil map[uint8]string given stream length: ", int64(containerLen)) - } - hasLen := containerLen >= 0 - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - mk := uint8(chkOvf.UintV(d.d.DecodeUint64(), 8)) - d.mapElemValue() - v[mk] = d.detach2Str(d.d.DecodeStringAsBytes()) - } -} -func (d *decoderJsonBytes) fastpathDecMapUint8BytesR(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTJsonBytes - containerLen := d.mapStart(d.d.ReadMapStart()) - if rv.Kind() == reflect.Ptr { - vp, _ := rv2i(rv).(*map[uint8][]byte) - if *vp == nil { - *vp = make(map[uint8][]byte, decInferLen(containerLen, d.maxInitLen(), 25)) - } - if containerLen != 0 { - ft.DecMapUint8BytesL(*vp, containerLen, d) - } - } else if containerLen != 0 { - ft.DecMapUint8BytesL(rv2i(rv).(map[uint8][]byte), containerLen, d) - } - d.mapEnd() -} -func (fastpathDTJsonBytes) DecMapUint8BytesL(v map[uint8][]byte, containerLen int, d *decoderJsonBytes) { - if v == nil { - halt.errorInt("cannot decode into nil map[uint8][]byte given stream length: ", int64(containerLen)) - } - var mv []byte - mapGet := !d.h.MapValueReset - hasLen := containerLen >= 0 - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - mk := uint8(chkOvf.UintV(d.d.DecodeUint64(), 8)) - d.mapElemValue() - if mapGet { - mv = v[mk] - } else { - mv = nil - } - v[mk], _ = d.decodeBytesInto(mv, false) - } -} -func (d *decoderJsonBytes) fastpathDecMapUint8Uint8R(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTJsonBytes - containerLen := d.mapStart(d.d.ReadMapStart()) - if rv.Kind() == reflect.Ptr { - vp, _ := rv2i(rv).(*map[uint8]uint8) - if *vp == nil { - *vp = make(map[uint8]uint8, decInferLen(containerLen, d.maxInitLen(), 2)) - } - if containerLen != 0 { - ft.DecMapUint8Uint8L(*vp, containerLen, d) - } - } else if containerLen != 0 { - ft.DecMapUint8Uint8L(rv2i(rv).(map[uint8]uint8), containerLen, d) - } - d.mapEnd() -} -func (fastpathDTJsonBytes) DecMapUint8Uint8L(v map[uint8]uint8, containerLen int, d *decoderJsonBytes) { - if v == nil { - halt.errorInt("cannot decode into nil map[uint8]uint8 given stream length: ", int64(containerLen)) - } - hasLen := containerLen >= 0 - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - mk := uint8(chkOvf.UintV(d.d.DecodeUint64(), 8)) - d.mapElemValue() - v[mk] = uint8(chkOvf.UintV(d.d.DecodeUint64(), 8)) - } -} -func (d *decoderJsonBytes) fastpathDecMapUint8Uint64R(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTJsonBytes - containerLen := d.mapStart(d.d.ReadMapStart()) - if rv.Kind() == reflect.Ptr { - vp, _ := rv2i(rv).(*map[uint8]uint64) - if *vp == nil { - *vp = make(map[uint8]uint64, decInferLen(containerLen, d.maxInitLen(), 9)) - } - if containerLen != 0 { - ft.DecMapUint8Uint64L(*vp, containerLen, d) - } - } else if containerLen != 0 { - ft.DecMapUint8Uint64L(rv2i(rv).(map[uint8]uint64), containerLen, d) - } - d.mapEnd() -} -func (fastpathDTJsonBytes) DecMapUint8Uint64L(v map[uint8]uint64, containerLen int, d *decoderJsonBytes) { - if v == nil { - halt.errorInt("cannot decode into nil map[uint8]uint64 given stream length: ", int64(containerLen)) - } - hasLen := containerLen >= 0 - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - mk := uint8(chkOvf.UintV(d.d.DecodeUint64(), 8)) - d.mapElemValue() - v[mk] = d.d.DecodeUint64() - } -} -func (d *decoderJsonBytes) fastpathDecMapUint8IntR(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTJsonBytes - containerLen := d.mapStart(d.d.ReadMapStart()) - if rv.Kind() == reflect.Ptr { - vp, _ := rv2i(rv).(*map[uint8]int) - if *vp == nil { - *vp = make(map[uint8]int, decInferLen(containerLen, d.maxInitLen(), 9)) - } - if containerLen != 0 { - ft.DecMapUint8IntL(*vp, containerLen, d) - } - } else if containerLen != 0 { - ft.DecMapUint8IntL(rv2i(rv).(map[uint8]int), containerLen, d) - } - d.mapEnd() -} -func (fastpathDTJsonBytes) DecMapUint8IntL(v map[uint8]int, containerLen int, d *decoderJsonBytes) { - if v == nil { - halt.errorInt("cannot decode into nil map[uint8]int given stream length: ", int64(containerLen)) - } - hasLen := containerLen >= 0 - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - mk := uint8(chkOvf.UintV(d.d.DecodeUint64(), 8)) - d.mapElemValue() - v[mk] = int(chkOvf.IntV(d.d.DecodeInt64(), intBitsize)) - } -} -func (d *decoderJsonBytes) fastpathDecMapUint8Int32R(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTJsonBytes - containerLen := d.mapStart(d.d.ReadMapStart()) - if rv.Kind() == reflect.Ptr { - vp, _ := rv2i(rv).(*map[uint8]int32) - if *vp == nil { - *vp = make(map[uint8]int32, decInferLen(containerLen, d.maxInitLen(), 5)) - } - if containerLen != 0 { - ft.DecMapUint8Int32L(*vp, containerLen, d) - } - } else if containerLen != 0 { - ft.DecMapUint8Int32L(rv2i(rv).(map[uint8]int32), containerLen, d) - } - d.mapEnd() -} -func (fastpathDTJsonBytes) DecMapUint8Int32L(v map[uint8]int32, containerLen int, d *decoderJsonBytes) { - if v == nil { - halt.errorInt("cannot decode into nil map[uint8]int32 given stream length: ", int64(containerLen)) - } - hasLen := containerLen >= 0 - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - mk := uint8(chkOvf.UintV(d.d.DecodeUint64(), 8)) - d.mapElemValue() - v[mk] = int32(chkOvf.IntV(d.d.DecodeInt64(), 32)) - } -} -func (d *decoderJsonBytes) fastpathDecMapUint8Float64R(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTJsonBytes - containerLen := d.mapStart(d.d.ReadMapStart()) - if rv.Kind() == reflect.Ptr { - vp, _ := rv2i(rv).(*map[uint8]float64) - if *vp == nil { - *vp = make(map[uint8]float64, decInferLen(containerLen, d.maxInitLen(), 9)) - } - if containerLen != 0 { - ft.DecMapUint8Float64L(*vp, containerLen, d) - } - } else if containerLen != 0 { - ft.DecMapUint8Float64L(rv2i(rv).(map[uint8]float64), containerLen, d) - } - d.mapEnd() -} -func (fastpathDTJsonBytes) DecMapUint8Float64L(v map[uint8]float64, containerLen int, d *decoderJsonBytes) { - if v == nil { - halt.errorInt("cannot decode into nil map[uint8]float64 given stream length: ", int64(containerLen)) - } - hasLen := containerLen >= 0 - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - mk := uint8(chkOvf.UintV(d.d.DecodeUint64(), 8)) - d.mapElemValue() - v[mk] = d.d.DecodeFloat64() - } -} -func (d *decoderJsonBytes) fastpathDecMapUint8BoolR(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTJsonBytes - containerLen := d.mapStart(d.d.ReadMapStart()) - if rv.Kind() == reflect.Ptr { - vp, _ := rv2i(rv).(*map[uint8]bool) - if *vp == nil { - *vp = make(map[uint8]bool, decInferLen(containerLen, d.maxInitLen(), 2)) - } - if containerLen != 0 { - ft.DecMapUint8BoolL(*vp, containerLen, d) - } - } else if containerLen != 0 { - ft.DecMapUint8BoolL(rv2i(rv).(map[uint8]bool), containerLen, d) - } - d.mapEnd() -} -func (fastpathDTJsonBytes) DecMapUint8BoolL(v map[uint8]bool, containerLen int, d *decoderJsonBytes) { - if v == nil { - halt.errorInt("cannot decode into nil map[uint8]bool given stream length: ", int64(containerLen)) - } - hasLen := containerLen >= 0 - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - mk := uint8(chkOvf.UintV(d.d.DecodeUint64(), 8)) - d.mapElemValue() - v[mk] = d.d.DecodeBool() - } -} -func (d *decoderJsonBytes) fastpathDecMapUint64IntfR(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTJsonBytes - containerLen := d.mapStart(d.d.ReadMapStart()) - if rv.Kind() == reflect.Ptr { - vp, _ := rv2i(rv).(*map[uint64]interface{}) - if *vp == nil { - *vp = make(map[uint64]interface{}, decInferLen(containerLen, d.maxInitLen(), 24)) - } - if containerLen != 0 { - ft.DecMapUint64IntfL(*vp, containerLen, d) - } - } else if containerLen != 0 { - ft.DecMapUint64IntfL(rv2i(rv).(map[uint64]interface{}), containerLen, d) - } - d.mapEnd() -} -func (fastpathDTJsonBytes) DecMapUint64IntfL(v map[uint64]interface{}, containerLen int, d *decoderJsonBytes) { - if v == nil { - halt.errorInt("cannot decode into nil map[uint64]interface{} given stream length: ", int64(containerLen)) - } - var mv interface{} - mapGet := !d.h.MapValueReset && !d.h.InterfaceReset - hasLen := containerLen >= 0 - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - mk := d.d.DecodeUint64() - d.mapElemValue() - if mapGet { - mv = v[mk] - } else { - mv = nil - } - d.decode(&mv) - v[mk] = mv - } -} -func (d *decoderJsonBytes) fastpathDecMapUint64StringR(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTJsonBytes - containerLen := d.mapStart(d.d.ReadMapStart()) - if rv.Kind() == reflect.Ptr { - vp, _ := rv2i(rv).(*map[uint64]string) - if *vp == nil { - *vp = make(map[uint64]string, decInferLen(containerLen, d.maxInitLen(), 24)) - } - if containerLen != 0 { - ft.DecMapUint64StringL(*vp, containerLen, d) - } - } else if containerLen != 0 { - ft.DecMapUint64StringL(rv2i(rv).(map[uint64]string), containerLen, d) - } - d.mapEnd() -} -func (fastpathDTJsonBytes) DecMapUint64StringL(v map[uint64]string, containerLen int, d *decoderJsonBytes) { - if v == nil { - halt.errorInt("cannot decode into nil map[uint64]string given stream length: ", int64(containerLen)) - } - hasLen := containerLen >= 0 - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - mk := d.d.DecodeUint64() - d.mapElemValue() - v[mk] = d.detach2Str(d.d.DecodeStringAsBytes()) - } -} -func (d *decoderJsonBytes) fastpathDecMapUint64BytesR(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTJsonBytes - containerLen := d.mapStart(d.d.ReadMapStart()) - if rv.Kind() == reflect.Ptr { - vp, _ := rv2i(rv).(*map[uint64][]byte) - if *vp == nil { - *vp = make(map[uint64][]byte, decInferLen(containerLen, d.maxInitLen(), 32)) - } - if containerLen != 0 { - ft.DecMapUint64BytesL(*vp, containerLen, d) - } - } else if containerLen != 0 { - ft.DecMapUint64BytesL(rv2i(rv).(map[uint64][]byte), containerLen, d) - } - d.mapEnd() -} -func (fastpathDTJsonBytes) DecMapUint64BytesL(v map[uint64][]byte, containerLen int, d *decoderJsonBytes) { - if v == nil { - halt.errorInt("cannot decode into nil map[uint64][]byte given stream length: ", int64(containerLen)) - } - var mv []byte - mapGet := !d.h.MapValueReset - hasLen := containerLen >= 0 - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - mk := d.d.DecodeUint64() - d.mapElemValue() - if mapGet { - mv = v[mk] - } else { - mv = nil - } - v[mk], _ = d.decodeBytesInto(mv, false) - } -} -func (d *decoderJsonBytes) fastpathDecMapUint64Uint8R(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTJsonBytes - containerLen := d.mapStart(d.d.ReadMapStart()) - if rv.Kind() == reflect.Ptr { - vp, _ := rv2i(rv).(*map[uint64]uint8) - if *vp == nil { - *vp = make(map[uint64]uint8, decInferLen(containerLen, d.maxInitLen(), 9)) - } - if containerLen != 0 { - ft.DecMapUint64Uint8L(*vp, containerLen, d) - } - } else if containerLen != 0 { - ft.DecMapUint64Uint8L(rv2i(rv).(map[uint64]uint8), containerLen, d) - } - d.mapEnd() -} -func (fastpathDTJsonBytes) DecMapUint64Uint8L(v map[uint64]uint8, containerLen int, d *decoderJsonBytes) { - if v == nil { - halt.errorInt("cannot decode into nil map[uint64]uint8 given stream length: ", int64(containerLen)) - } - hasLen := containerLen >= 0 - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - mk := d.d.DecodeUint64() - d.mapElemValue() - v[mk] = uint8(chkOvf.UintV(d.d.DecodeUint64(), 8)) - } -} -func (d *decoderJsonBytes) fastpathDecMapUint64Uint64R(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTJsonBytes - containerLen := d.mapStart(d.d.ReadMapStart()) - if rv.Kind() == reflect.Ptr { - vp, _ := rv2i(rv).(*map[uint64]uint64) - if *vp == nil { - *vp = make(map[uint64]uint64, decInferLen(containerLen, d.maxInitLen(), 16)) - } - if containerLen != 0 { - ft.DecMapUint64Uint64L(*vp, containerLen, d) - } - } else if containerLen != 0 { - ft.DecMapUint64Uint64L(rv2i(rv).(map[uint64]uint64), containerLen, d) - } - d.mapEnd() -} -func (fastpathDTJsonBytes) DecMapUint64Uint64L(v map[uint64]uint64, containerLen int, d *decoderJsonBytes) { - if v == nil { - halt.errorInt("cannot decode into nil map[uint64]uint64 given stream length: ", int64(containerLen)) - } - hasLen := containerLen >= 0 - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - mk := d.d.DecodeUint64() - d.mapElemValue() - v[mk] = d.d.DecodeUint64() - } -} -func (d *decoderJsonBytes) fastpathDecMapUint64IntR(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTJsonBytes - containerLen := d.mapStart(d.d.ReadMapStart()) - if rv.Kind() == reflect.Ptr { - vp, _ := rv2i(rv).(*map[uint64]int) - if *vp == nil { - *vp = make(map[uint64]int, decInferLen(containerLen, d.maxInitLen(), 16)) - } - if containerLen != 0 { - ft.DecMapUint64IntL(*vp, containerLen, d) - } - } else if containerLen != 0 { - ft.DecMapUint64IntL(rv2i(rv).(map[uint64]int), containerLen, d) - } - d.mapEnd() -} -func (fastpathDTJsonBytes) DecMapUint64IntL(v map[uint64]int, containerLen int, d *decoderJsonBytes) { - if v == nil { - halt.errorInt("cannot decode into nil map[uint64]int given stream length: ", int64(containerLen)) - } - hasLen := containerLen >= 0 - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - mk := d.d.DecodeUint64() - d.mapElemValue() - v[mk] = int(chkOvf.IntV(d.d.DecodeInt64(), intBitsize)) - } -} -func (d *decoderJsonBytes) fastpathDecMapUint64Int32R(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTJsonBytes - containerLen := d.mapStart(d.d.ReadMapStart()) - if rv.Kind() == reflect.Ptr { - vp, _ := rv2i(rv).(*map[uint64]int32) - if *vp == nil { - *vp = make(map[uint64]int32, decInferLen(containerLen, d.maxInitLen(), 12)) - } - if containerLen != 0 { - ft.DecMapUint64Int32L(*vp, containerLen, d) - } - } else if containerLen != 0 { - ft.DecMapUint64Int32L(rv2i(rv).(map[uint64]int32), containerLen, d) - } - d.mapEnd() -} -func (fastpathDTJsonBytes) DecMapUint64Int32L(v map[uint64]int32, containerLen int, d *decoderJsonBytes) { - if v == nil { - halt.errorInt("cannot decode into nil map[uint64]int32 given stream length: ", int64(containerLen)) - } - hasLen := containerLen >= 0 - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - mk := d.d.DecodeUint64() - d.mapElemValue() - v[mk] = int32(chkOvf.IntV(d.d.DecodeInt64(), 32)) - } -} -func (d *decoderJsonBytes) fastpathDecMapUint64Float64R(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTJsonBytes - containerLen := d.mapStart(d.d.ReadMapStart()) - if rv.Kind() == reflect.Ptr { - vp, _ := rv2i(rv).(*map[uint64]float64) - if *vp == nil { - *vp = make(map[uint64]float64, decInferLen(containerLen, d.maxInitLen(), 16)) - } - if containerLen != 0 { - ft.DecMapUint64Float64L(*vp, containerLen, d) - } - } else if containerLen != 0 { - ft.DecMapUint64Float64L(rv2i(rv).(map[uint64]float64), containerLen, d) - } - d.mapEnd() -} -func (fastpathDTJsonBytes) DecMapUint64Float64L(v map[uint64]float64, containerLen int, d *decoderJsonBytes) { - if v == nil { - halt.errorInt("cannot decode into nil map[uint64]float64 given stream length: ", int64(containerLen)) - } - hasLen := containerLen >= 0 - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - mk := d.d.DecodeUint64() - d.mapElemValue() - v[mk] = d.d.DecodeFloat64() - } -} -func (d *decoderJsonBytes) fastpathDecMapUint64BoolR(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTJsonBytes - containerLen := d.mapStart(d.d.ReadMapStart()) - if rv.Kind() == reflect.Ptr { - vp, _ := rv2i(rv).(*map[uint64]bool) - if *vp == nil { - *vp = make(map[uint64]bool, decInferLen(containerLen, d.maxInitLen(), 9)) - } - if containerLen != 0 { - ft.DecMapUint64BoolL(*vp, containerLen, d) - } - } else if containerLen != 0 { - ft.DecMapUint64BoolL(rv2i(rv).(map[uint64]bool), containerLen, d) - } - d.mapEnd() -} -func (fastpathDTJsonBytes) DecMapUint64BoolL(v map[uint64]bool, containerLen int, d *decoderJsonBytes) { - if v == nil { - halt.errorInt("cannot decode into nil map[uint64]bool given stream length: ", int64(containerLen)) - } - hasLen := containerLen >= 0 - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - mk := d.d.DecodeUint64() - d.mapElemValue() - v[mk] = d.d.DecodeBool() - } -} -func (d *decoderJsonBytes) fastpathDecMapIntIntfR(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTJsonBytes - containerLen := d.mapStart(d.d.ReadMapStart()) - if rv.Kind() == reflect.Ptr { - vp, _ := rv2i(rv).(*map[int]interface{}) - if *vp == nil { - *vp = make(map[int]interface{}, decInferLen(containerLen, d.maxInitLen(), 24)) - } - if containerLen != 0 { - ft.DecMapIntIntfL(*vp, containerLen, d) - } - } else if containerLen != 0 { - ft.DecMapIntIntfL(rv2i(rv).(map[int]interface{}), containerLen, d) - } - d.mapEnd() -} -func (fastpathDTJsonBytes) DecMapIntIntfL(v map[int]interface{}, containerLen int, d *decoderJsonBytes) { - if v == nil { - halt.errorInt("cannot decode into nil map[int]interface{} given stream length: ", int64(containerLen)) - } - var mv interface{} - mapGet := !d.h.MapValueReset && !d.h.InterfaceReset - hasLen := containerLen >= 0 - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - mk := int(chkOvf.IntV(d.d.DecodeInt64(), intBitsize)) - d.mapElemValue() - if mapGet { - mv = v[mk] - } else { - mv = nil - } - d.decode(&mv) - v[mk] = mv - } -} -func (d *decoderJsonBytes) fastpathDecMapIntStringR(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTJsonBytes - containerLen := d.mapStart(d.d.ReadMapStart()) - if rv.Kind() == reflect.Ptr { - vp, _ := rv2i(rv).(*map[int]string) - if *vp == nil { - *vp = make(map[int]string, decInferLen(containerLen, d.maxInitLen(), 24)) - } - if containerLen != 0 { - ft.DecMapIntStringL(*vp, containerLen, d) - } - } else if containerLen != 0 { - ft.DecMapIntStringL(rv2i(rv).(map[int]string), containerLen, d) - } - d.mapEnd() -} -func (fastpathDTJsonBytes) DecMapIntStringL(v map[int]string, containerLen int, d *decoderJsonBytes) { - if v == nil { - halt.errorInt("cannot decode into nil map[int]string given stream length: ", int64(containerLen)) - } - hasLen := containerLen >= 0 - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - mk := int(chkOvf.IntV(d.d.DecodeInt64(), intBitsize)) - d.mapElemValue() - v[mk] = d.detach2Str(d.d.DecodeStringAsBytes()) - } -} -func (d *decoderJsonBytes) fastpathDecMapIntBytesR(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTJsonBytes - containerLen := d.mapStart(d.d.ReadMapStart()) - if rv.Kind() == reflect.Ptr { - vp, _ := rv2i(rv).(*map[int][]byte) - if *vp == nil { - *vp = make(map[int][]byte, decInferLen(containerLen, d.maxInitLen(), 32)) - } - if containerLen != 0 { - ft.DecMapIntBytesL(*vp, containerLen, d) - } - } else if containerLen != 0 { - ft.DecMapIntBytesL(rv2i(rv).(map[int][]byte), containerLen, d) - } - d.mapEnd() -} -func (fastpathDTJsonBytes) DecMapIntBytesL(v map[int][]byte, containerLen int, d *decoderJsonBytes) { - if v == nil { - halt.errorInt("cannot decode into nil map[int][]byte given stream length: ", int64(containerLen)) - } - var mv []byte - mapGet := !d.h.MapValueReset - hasLen := containerLen >= 0 - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - mk := int(chkOvf.IntV(d.d.DecodeInt64(), intBitsize)) - d.mapElemValue() - if mapGet { - mv = v[mk] - } else { - mv = nil - } - v[mk], _ = d.decodeBytesInto(mv, false) - } -} -func (d *decoderJsonBytes) fastpathDecMapIntUint8R(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTJsonBytes - containerLen := d.mapStart(d.d.ReadMapStart()) - if rv.Kind() == reflect.Ptr { - vp, _ := rv2i(rv).(*map[int]uint8) - if *vp == nil { - *vp = make(map[int]uint8, decInferLen(containerLen, d.maxInitLen(), 9)) - } - if containerLen != 0 { - ft.DecMapIntUint8L(*vp, containerLen, d) - } - } else if containerLen != 0 { - ft.DecMapIntUint8L(rv2i(rv).(map[int]uint8), containerLen, d) - } - d.mapEnd() -} -func (fastpathDTJsonBytes) DecMapIntUint8L(v map[int]uint8, containerLen int, d *decoderJsonBytes) { - if v == nil { - halt.errorInt("cannot decode into nil map[int]uint8 given stream length: ", int64(containerLen)) - } - hasLen := containerLen >= 0 - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - mk := int(chkOvf.IntV(d.d.DecodeInt64(), intBitsize)) - d.mapElemValue() - v[mk] = uint8(chkOvf.UintV(d.d.DecodeUint64(), 8)) - } -} -func (d *decoderJsonBytes) fastpathDecMapIntUint64R(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTJsonBytes - containerLen := d.mapStart(d.d.ReadMapStart()) - if rv.Kind() == reflect.Ptr { - vp, _ := rv2i(rv).(*map[int]uint64) - if *vp == nil { - *vp = make(map[int]uint64, decInferLen(containerLen, d.maxInitLen(), 16)) - } - if containerLen != 0 { - ft.DecMapIntUint64L(*vp, containerLen, d) - } - } else if containerLen != 0 { - ft.DecMapIntUint64L(rv2i(rv).(map[int]uint64), containerLen, d) - } - d.mapEnd() -} -func (fastpathDTJsonBytes) DecMapIntUint64L(v map[int]uint64, containerLen int, d *decoderJsonBytes) { - if v == nil { - halt.errorInt("cannot decode into nil map[int]uint64 given stream length: ", int64(containerLen)) - } - hasLen := containerLen >= 0 - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - mk := int(chkOvf.IntV(d.d.DecodeInt64(), intBitsize)) - d.mapElemValue() - v[mk] = d.d.DecodeUint64() - } -} -func (d *decoderJsonBytes) fastpathDecMapIntIntR(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTJsonBytes - containerLen := d.mapStart(d.d.ReadMapStart()) - if rv.Kind() == reflect.Ptr { - vp, _ := rv2i(rv).(*map[int]int) - if *vp == nil { - *vp = make(map[int]int, decInferLen(containerLen, d.maxInitLen(), 16)) - } - if containerLen != 0 { - ft.DecMapIntIntL(*vp, containerLen, d) - } - } else if containerLen != 0 { - ft.DecMapIntIntL(rv2i(rv).(map[int]int), containerLen, d) - } - d.mapEnd() -} -func (fastpathDTJsonBytes) DecMapIntIntL(v map[int]int, containerLen int, d *decoderJsonBytes) { - if v == nil { - halt.errorInt("cannot decode into nil map[int]int given stream length: ", int64(containerLen)) - } - hasLen := containerLen >= 0 - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - mk := int(chkOvf.IntV(d.d.DecodeInt64(), intBitsize)) - d.mapElemValue() - v[mk] = int(chkOvf.IntV(d.d.DecodeInt64(), intBitsize)) - } -} -func (d *decoderJsonBytes) fastpathDecMapIntInt32R(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTJsonBytes - containerLen := d.mapStart(d.d.ReadMapStart()) - if rv.Kind() == reflect.Ptr { - vp, _ := rv2i(rv).(*map[int]int32) - if *vp == nil { - *vp = make(map[int]int32, decInferLen(containerLen, d.maxInitLen(), 12)) - } - if containerLen != 0 { - ft.DecMapIntInt32L(*vp, containerLen, d) - } - } else if containerLen != 0 { - ft.DecMapIntInt32L(rv2i(rv).(map[int]int32), containerLen, d) - } - d.mapEnd() -} -func (fastpathDTJsonBytes) DecMapIntInt32L(v map[int]int32, containerLen int, d *decoderJsonBytes) { - if v == nil { - halt.errorInt("cannot decode into nil map[int]int32 given stream length: ", int64(containerLen)) - } - hasLen := containerLen >= 0 - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - mk := int(chkOvf.IntV(d.d.DecodeInt64(), intBitsize)) - d.mapElemValue() - v[mk] = int32(chkOvf.IntV(d.d.DecodeInt64(), 32)) - } -} -func (d *decoderJsonBytes) fastpathDecMapIntFloat64R(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTJsonBytes - containerLen := d.mapStart(d.d.ReadMapStart()) - if rv.Kind() == reflect.Ptr { - vp, _ := rv2i(rv).(*map[int]float64) - if *vp == nil { - *vp = make(map[int]float64, decInferLen(containerLen, d.maxInitLen(), 16)) - } - if containerLen != 0 { - ft.DecMapIntFloat64L(*vp, containerLen, d) - } - } else if containerLen != 0 { - ft.DecMapIntFloat64L(rv2i(rv).(map[int]float64), containerLen, d) - } - d.mapEnd() -} -func (fastpathDTJsonBytes) DecMapIntFloat64L(v map[int]float64, containerLen int, d *decoderJsonBytes) { - if v == nil { - halt.errorInt("cannot decode into nil map[int]float64 given stream length: ", int64(containerLen)) - } - hasLen := containerLen >= 0 - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - mk := int(chkOvf.IntV(d.d.DecodeInt64(), intBitsize)) - d.mapElemValue() - v[mk] = d.d.DecodeFloat64() - } -} -func (d *decoderJsonBytes) fastpathDecMapIntBoolR(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTJsonBytes - containerLen := d.mapStart(d.d.ReadMapStart()) - if rv.Kind() == reflect.Ptr { - vp, _ := rv2i(rv).(*map[int]bool) - if *vp == nil { - *vp = make(map[int]bool, decInferLen(containerLen, d.maxInitLen(), 9)) - } - if containerLen != 0 { - ft.DecMapIntBoolL(*vp, containerLen, d) - } - } else if containerLen != 0 { - ft.DecMapIntBoolL(rv2i(rv).(map[int]bool), containerLen, d) - } - d.mapEnd() -} -func (fastpathDTJsonBytes) DecMapIntBoolL(v map[int]bool, containerLen int, d *decoderJsonBytes) { - if v == nil { - halt.errorInt("cannot decode into nil map[int]bool given stream length: ", int64(containerLen)) - } - hasLen := containerLen >= 0 - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - mk := int(chkOvf.IntV(d.d.DecodeInt64(), intBitsize)) - d.mapElemValue() - v[mk] = d.d.DecodeBool() - } -} -func (d *decoderJsonBytes) fastpathDecMapInt32IntfR(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTJsonBytes - containerLen := d.mapStart(d.d.ReadMapStart()) - if rv.Kind() == reflect.Ptr { - vp, _ := rv2i(rv).(*map[int32]interface{}) - if *vp == nil { - *vp = make(map[int32]interface{}, decInferLen(containerLen, d.maxInitLen(), 20)) - } - if containerLen != 0 { - ft.DecMapInt32IntfL(*vp, containerLen, d) - } - } else if containerLen != 0 { - ft.DecMapInt32IntfL(rv2i(rv).(map[int32]interface{}), containerLen, d) - } - d.mapEnd() -} -func (fastpathDTJsonBytes) DecMapInt32IntfL(v map[int32]interface{}, containerLen int, d *decoderJsonBytes) { - if v == nil { - halt.errorInt("cannot decode into nil map[int32]interface{} given stream length: ", int64(containerLen)) - } - var mv interface{} - mapGet := !d.h.MapValueReset && !d.h.InterfaceReset - hasLen := containerLen >= 0 - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - mk := int32(chkOvf.IntV(d.d.DecodeInt64(), 32)) - d.mapElemValue() - if mapGet { - mv = v[mk] - } else { - mv = nil - } - d.decode(&mv) - v[mk] = mv - } -} -func (d *decoderJsonBytes) fastpathDecMapInt32StringR(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTJsonBytes - containerLen := d.mapStart(d.d.ReadMapStart()) - if rv.Kind() == reflect.Ptr { - vp, _ := rv2i(rv).(*map[int32]string) - if *vp == nil { - *vp = make(map[int32]string, decInferLen(containerLen, d.maxInitLen(), 20)) - } - if containerLen != 0 { - ft.DecMapInt32StringL(*vp, containerLen, d) - } - } else if containerLen != 0 { - ft.DecMapInt32StringL(rv2i(rv).(map[int32]string), containerLen, d) - } - d.mapEnd() -} -func (fastpathDTJsonBytes) DecMapInt32StringL(v map[int32]string, containerLen int, d *decoderJsonBytes) { - if v == nil { - halt.errorInt("cannot decode into nil map[int32]string given stream length: ", int64(containerLen)) - } - hasLen := containerLen >= 0 - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - mk := int32(chkOvf.IntV(d.d.DecodeInt64(), 32)) - d.mapElemValue() - v[mk] = d.detach2Str(d.d.DecodeStringAsBytes()) - } -} -func (d *decoderJsonBytes) fastpathDecMapInt32BytesR(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTJsonBytes - containerLen := d.mapStart(d.d.ReadMapStart()) - if rv.Kind() == reflect.Ptr { - vp, _ := rv2i(rv).(*map[int32][]byte) - if *vp == nil { - *vp = make(map[int32][]byte, decInferLen(containerLen, d.maxInitLen(), 28)) - } - if containerLen != 0 { - ft.DecMapInt32BytesL(*vp, containerLen, d) - } - } else if containerLen != 0 { - ft.DecMapInt32BytesL(rv2i(rv).(map[int32][]byte), containerLen, d) - } - d.mapEnd() -} -func (fastpathDTJsonBytes) DecMapInt32BytesL(v map[int32][]byte, containerLen int, d *decoderJsonBytes) { - if v == nil { - halt.errorInt("cannot decode into nil map[int32][]byte given stream length: ", int64(containerLen)) - } - var mv []byte - mapGet := !d.h.MapValueReset - hasLen := containerLen >= 0 - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - mk := int32(chkOvf.IntV(d.d.DecodeInt64(), 32)) - d.mapElemValue() - if mapGet { - mv = v[mk] - } else { - mv = nil - } - v[mk], _ = d.decodeBytesInto(mv, false) - } -} -func (d *decoderJsonBytes) fastpathDecMapInt32Uint8R(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTJsonBytes - containerLen := d.mapStart(d.d.ReadMapStart()) - if rv.Kind() == reflect.Ptr { - vp, _ := rv2i(rv).(*map[int32]uint8) - if *vp == nil { - *vp = make(map[int32]uint8, decInferLen(containerLen, d.maxInitLen(), 5)) - } - if containerLen != 0 { - ft.DecMapInt32Uint8L(*vp, containerLen, d) - } - } else if containerLen != 0 { - ft.DecMapInt32Uint8L(rv2i(rv).(map[int32]uint8), containerLen, d) - } - d.mapEnd() -} -func (fastpathDTJsonBytes) DecMapInt32Uint8L(v map[int32]uint8, containerLen int, d *decoderJsonBytes) { - if v == nil { - halt.errorInt("cannot decode into nil map[int32]uint8 given stream length: ", int64(containerLen)) - } - hasLen := containerLen >= 0 - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - mk := int32(chkOvf.IntV(d.d.DecodeInt64(), 32)) - d.mapElemValue() - v[mk] = uint8(chkOvf.UintV(d.d.DecodeUint64(), 8)) - } -} -func (d *decoderJsonBytes) fastpathDecMapInt32Uint64R(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTJsonBytes - containerLen := d.mapStart(d.d.ReadMapStart()) - if rv.Kind() == reflect.Ptr { - vp, _ := rv2i(rv).(*map[int32]uint64) - if *vp == nil { - *vp = make(map[int32]uint64, decInferLen(containerLen, d.maxInitLen(), 12)) - } - if containerLen != 0 { - ft.DecMapInt32Uint64L(*vp, containerLen, d) - } - } else if containerLen != 0 { - ft.DecMapInt32Uint64L(rv2i(rv).(map[int32]uint64), containerLen, d) - } - d.mapEnd() -} -func (fastpathDTJsonBytes) DecMapInt32Uint64L(v map[int32]uint64, containerLen int, d *decoderJsonBytes) { - if v == nil { - halt.errorInt("cannot decode into nil map[int32]uint64 given stream length: ", int64(containerLen)) - } - hasLen := containerLen >= 0 - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - mk := int32(chkOvf.IntV(d.d.DecodeInt64(), 32)) - d.mapElemValue() - v[mk] = d.d.DecodeUint64() - } -} -func (d *decoderJsonBytes) fastpathDecMapInt32IntR(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTJsonBytes - containerLen := d.mapStart(d.d.ReadMapStart()) - if rv.Kind() == reflect.Ptr { - vp, _ := rv2i(rv).(*map[int32]int) - if *vp == nil { - *vp = make(map[int32]int, decInferLen(containerLen, d.maxInitLen(), 12)) - } - if containerLen != 0 { - ft.DecMapInt32IntL(*vp, containerLen, d) - } - } else if containerLen != 0 { - ft.DecMapInt32IntL(rv2i(rv).(map[int32]int), containerLen, d) - } - d.mapEnd() -} -func (fastpathDTJsonBytes) DecMapInt32IntL(v map[int32]int, containerLen int, d *decoderJsonBytes) { - if v == nil { - halt.errorInt("cannot decode into nil map[int32]int given stream length: ", int64(containerLen)) - } - hasLen := containerLen >= 0 - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - mk := int32(chkOvf.IntV(d.d.DecodeInt64(), 32)) - d.mapElemValue() - v[mk] = int(chkOvf.IntV(d.d.DecodeInt64(), intBitsize)) - } -} -func (d *decoderJsonBytes) fastpathDecMapInt32Int32R(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTJsonBytes - containerLen := d.mapStart(d.d.ReadMapStart()) - if rv.Kind() == reflect.Ptr { - vp, _ := rv2i(rv).(*map[int32]int32) - if *vp == nil { - *vp = make(map[int32]int32, decInferLen(containerLen, d.maxInitLen(), 8)) - } - if containerLen != 0 { - ft.DecMapInt32Int32L(*vp, containerLen, d) - } - } else if containerLen != 0 { - ft.DecMapInt32Int32L(rv2i(rv).(map[int32]int32), containerLen, d) - } - d.mapEnd() -} -func (fastpathDTJsonBytes) DecMapInt32Int32L(v map[int32]int32, containerLen int, d *decoderJsonBytes) { - if v == nil { - halt.errorInt("cannot decode into nil map[int32]int32 given stream length: ", int64(containerLen)) - } - hasLen := containerLen >= 0 - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - mk := int32(chkOvf.IntV(d.d.DecodeInt64(), 32)) - d.mapElemValue() - v[mk] = int32(chkOvf.IntV(d.d.DecodeInt64(), 32)) - } -} -func (d *decoderJsonBytes) fastpathDecMapInt32Float64R(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTJsonBytes - containerLen := d.mapStart(d.d.ReadMapStart()) - if rv.Kind() == reflect.Ptr { - vp, _ := rv2i(rv).(*map[int32]float64) - if *vp == nil { - *vp = make(map[int32]float64, decInferLen(containerLen, d.maxInitLen(), 12)) - } - if containerLen != 0 { - ft.DecMapInt32Float64L(*vp, containerLen, d) - } - } else if containerLen != 0 { - ft.DecMapInt32Float64L(rv2i(rv).(map[int32]float64), containerLen, d) - } - d.mapEnd() -} -func (fastpathDTJsonBytes) DecMapInt32Float64L(v map[int32]float64, containerLen int, d *decoderJsonBytes) { - if v == nil { - halt.errorInt("cannot decode into nil map[int32]float64 given stream length: ", int64(containerLen)) - } - hasLen := containerLen >= 0 - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - mk := int32(chkOvf.IntV(d.d.DecodeInt64(), 32)) - d.mapElemValue() - v[mk] = d.d.DecodeFloat64() - } -} -func (d *decoderJsonBytes) fastpathDecMapInt32BoolR(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTJsonBytes - containerLen := d.mapStart(d.d.ReadMapStart()) - if rv.Kind() == reflect.Ptr { - vp, _ := rv2i(rv).(*map[int32]bool) - if *vp == nil { - *vp = make(map[int32]bool, decInferLen(containerLen, d.maxInitLen(), 5)) - } - if containerLen != 0 { - ft.DecMapInt32BoolL(*vp, containerLen, d) - } - } else if containerLen != 0 { - ft.DecMapInt32BoolL(rv2i(rv).(map[int32]bool), containerLen, d) - } - d.mapEnd() -} -func (fastpathDTJsonBytes) DecMapInt32BoolL(v map[int32]bool, containerLen int, d *decoderJsonBytes) { - if v == nil { - halt.errorInt("cannot decode into nil map[int32]bool given stream length: ", int64(containerLen)) - } - hasLen := containerLen >= 0 - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - mk := int32(chkOvf.IntV(d.d.DecodeInt64(), 32)) - d.mapElemValue() - v[mk] = d.d.DecodeBool() - } -} - -type fastpathEJsonIO struct { - rtid uintptr - rt reflect.Type - encfn func(*encoderJsonIO, *encFnInfo, reflect.Value) -} -type fastpathDJsonIO struct { - rtid uintptr - rt reflect.Type - decfn func(*decoderJsonIO, *decFnInfo, reflect.Value) -} -type fastpathEsJsonIO [56]fastpathEJsonIO -type fastpathDsJsonIO [56]fastpathDJsonIO -type fastpathETJsonIO struct{} -type fastpathDTJsonIO struct{} - -func (helperEncDriverJsonIO) fastpathEList() *fastpathEsJsonIO { - var i uint = 0 - var s fastpathEsJsonIO - fn := func(v interface{}, fe func(*encoderJsonIO, *encFnInfo, reflect.Value)) { - xrt := reflect.TypeOf(v) - s[i] = fastpathEJsonIO{rt2id(xrt), xrt, fe} - i++ - } - - fn([]interface{}(nil), (*encoderJsonIO).fastpathEncSliceIntfR) - fn([]string(nil), (*encoderJsonIO).fastpathEncSliceStringR) - fn([][]byte(nil), (*encoderJsonIO).fastpathEncSliceBytesR) - fn([]float32(nil), (*encoderJsonIO).fastpathEncSliceFloat32R) - fn([]float64(nil), (*encoderJsonIO).fastpathEncSliceFloat64R) - fn([]uint8(nil), (*encoderJsonIO).fastpathEncSliceUint8R) - fn([]uint64(nil), (*encoderJsonIO).fastpathEncSliceUint64R) - fn([]int(nil), (*encoderJsonIO).fastpathEncSliceIntR) - fn([]int32(nil), (*encoderJsonIO).fastpathEncSliceInt32R) - fn([]int64(nil), (*encoderJsonIO).fastpathEncSliceInt64R) - fn([]bool(nil), (*encoderJsonIO).fastpathEncSliceBoolR) - - fn(map[string]interface{}(nil), (*encoderJsonIO).fastpathEncMapStringIntfR) - fn(map[string]string(nil), (*encoderJsonIO).fastpathEncMapStringStringR) - fn(map[string][]byte(nil), (*encoderJsonIO).fastpathEncMapStringBytesR) - fn(map[string]uint8(nil), (*encoderJsonIO).fastpathEncMapStringUint8R) - fn(map[string]uint64(nil), (*encoderJsonIO).fastpathEncMapStringUint64R) - fn(map[string]int(nil), (*encoderJsonIO).fastpathEncMapStringIntR) - fn(map[string]int32(nil), (*encoderJsonIO).fastpathEncMapStringInt32R) - fn(map[string]float64(nil), (*encoderJsonIO).fastpathEncMapStringFloat64R) - fn(map[string]bool(nil), (*encoderJsonIO).fastpathEncMapStringBoolR) - fn(map[uint8]interface{}(nil), (*encoderJsonIO).fastpathEncMapUint8IntfR) - fn(map[uint8]string(nil), (*encoderJsonIO).fastpathEncMapUint8StringR) - fn(map[uint8][]byte(nil), (*encoderJsonIO).fastpathEncMapUint8BytesR) - fn(map[uint8]uint8(nil), (*encoderJsonIO).fastpathEncMapUint8Uint8R) - fn(map[uint8]uint64(nil), (*encoderJsonIO).fastpathEncMapUint8Uint64R) - fn(map[uint8]int(nil), (*encoderJsonIO).fastpathEncMapUint8IntR) - fn(map[uint8]int32(nil), (*encoderJsonIO).fastpathEncMapUint8Int32R) - fn(map[uint8]float64(nil), (*encoderJsonIO).fastpathEncMapUint8Float64R) - fn(map[uint8]bool(nil), (*encoderJsonIO).fastpathEncMapUint8BoolR) - fn(map[uint64]interface{}(nil), (*encoderJsonIO).fastpathEncMapUint64IntfR) - fn(map[uint64]string(nil), (*encoderJsonIO).fastpathEncMapUint64StringR) - fn(map[uint64][]byte(nil), (*encoderJsonIO).fastpathEncMapUint64BytesR) - fn(map[uint64]uint8(nil), (*encoderJsonIO).fastpathEncMapUint64Uint8R) - fn(map[uint64]uint64(nil), (*encoderJsonIO).fastpathEncMapUint64Uint64R) - fn(map[uint64]int(nil), (*encoderJsonIO).fastpathEncMapUint64IntR) - fn(map[uint64]int32(nil), (*encoderJsonIO).fastpathEncMapUint64Int32R) - fn(map[uint64]float64(nil), (*encoderJsonIO).fastpathEncMapUint64Float64R) - fn(map[uint64]bool(nil), (*encoderJsonIO).fastpathEncMapUint64BoolR) - fn(map[int]interface{}(nil), (*encoderJsonIO).fastpathEncMapIntIntfR) - fn(map[int]string(nil), (*encoderJsonIO).fastpathEncMapIntStringR) - fn(map[int][]byte(nil), (*encoderJsonIO).fastpathEncMapIntBytesR) - fn(map[int]uint8(nil), (*encoderJsonIO).fastpathEncMapIntUint8R) - fn(map[int]uint64(nil), (*encoderJsonIO).fastpathEncMapIntUint64R) - fn(map[int]int(nil), (*encoderJsonIO).fastpathEncMapIntIntR) - fn(map[int]int32(nil), (*encoderJsonIO).fastpathEncMapIntInt32R) - fn(map[int]float64(nil), (*encoderJsonIO).fastpathEncMapIntFloat64R) - fn(map[int]bool(nil), (*encoderJsonIO).fastpathEncMapIntBoolR) - fn(map[int32]interface{}(nil), (*encoderJsonIO).fastpathEncMapInt32IntfR) - fn(map[int32]string(nil), (*encoderJsonIO).fastpathEncMapInt32StringR) - fn(map[int32][]byte(nil), (*encoderJsonIO).fastpathEncMapInt32BytesR) - fn(map[int32]uint8(nil), (*encoderJsonIO).fastpathEncMapInt32Uint8R) - fn(map[int32]uint64(nil), (*encoderJsonIO).fastpathEncMapInt32Uint64R) - fn(map[int32]int(nil), (*encoderJsonIO).fastpathEncMapInt32IntR) - fn(map[int32]int32(nil), (*encoderJsonIO).fastpathEncMapInt32Int32R) - fn(map[int32]float64(nil), (*encoderJsonIO).fastpathEncMapInt32Float64R) - fn(map[int32]bool(nil), (*encoderJsonIO).fastpathEncMapInt32BoolR) - - sort.Slice(s[:], func(i, j int) bool { return s[i].rtid < s[j].rtid }) - return &s -} - -func (helperDecDriverJsonIO) fastpathDList() *fastpathDsJsonIO { - var i uint = 0 - var s fastpathDsJsonIO - fn := func(v interface{}, fd func(*decoderJsonIO, *decFnInfo, reflect.Value)) { - xrt := reflect.TypeOf(v) - s[i] = fastpathDJsonIO{rt2id(xrt), xrt, fd} - i++ - } - - fn([]interface{}(nil), (*decoderJsonIO).fastpathDecSliceIntfR) - fn([]string(nil), (*decoderJsonIO).fastpathDecSliceStringR) - fn([][]byte(nil), (*decoderJsonIO).fastpathDecSliceBytesR) - fn([]float32(nil), (*decoderJsonIO).fastpathDecSliceFloat32R) - fn([]float64(nil), (*decoderJsonIO).fastpathDecSliceFloat64R) - fn([]uint8(nil), (*decoderJsonIO).fastpathDecSliceUint8R) - fn([]uint64(nil), (*decoderJsonIO).fastpathDecSliceUint64R) - fn([]int(nil), (*decoderJsonIO).fastpathDecSliceIntR) - fn([]int32(nil), (*decoderJsonIO).fastpathDecSliceInt32R) - fn([]int64(nil), (*decoderJsonIO).fastpathDecSliceInt64R) - fn([]bool(nil), (*decoderJsonIO).fastpathDecSliceBoolR) - - fn(map[string]interface{}(nil), (*decoderJsonIO).fastpathDecMapStringIntfR) - fn(map[string]string(nil), (*decoderJsonIO).fastpathDecMapStringStringR) - fn(map[string][]byte(nil), (*decoderJsonIO).fastpathDecMapStringBytesR) - fn(map[string]uint8(nil), (*decoderJsonIO).fastpathDecMapStringUint8R) - fn(map[string]uint64(nil), (*decoderJsonIO).fastpathDecMapStringUint64R) - fn(map[string]int(nil), (*decoderJsonIO).fastpathDecMapStringIntR) - fn(map[string]int32(nil), (*decoderJsonIO).fastpathDecMapStringInt32R) - fn(map[string]float64(nil), (*decoderJsonIO).fastpathDecMapStringFloat64R) - fn(map[string]bool(nil), (*decoderJsonIO).fastpathDecMapStringBoolR) - fn(map[uint8]interface{}(nil), (*decoderJsonIO).fastpathDecMapUint8IntfR) - fn(map[uint8]string(nil), (*decoderJsonIO).fastpathDecMapUint8StringR) - fn(map[uint8][]byte(nil), (*decoderJsonIO).fastpathDecMapUint8BytesR) - fn(map[uint8]uint8(nil), (*decoderJsonIO).fastpathDecMapUint8Uint8R) - fn(map[uint8]uint64(nil), (*decoderJsonIO).fastpathDecMapUint8Uint64R) - fn(map[uint8]int(nil), (*decoderJsonIO).fastpathDecMapUint8IntR) - fn(map[uint8]int32(nil), (*decoderJsonIO).fastpathDecMapUint8Int32R) - fn(map[uint8]float64(nil), (*decoderJsonIO).fastpathDecMapUint8Float64R) - fn(map[uint8]bool(nil), (*decoderJsonIO).fastpathDecMapUint8BoolR) - fn(map[uint64]interface{}(nil), (*decoderJsonIO).fastpathDecMapUint64IntfR) - fn(map[uint64]string(nil), (*decoderJsonIO).fastpathDecMapUint64StringR) - fn(map[uint64][]byte(nil), (*decoderJsonIO).fastpathDecMapUint64BytesR) - fn(map[uint64]uint8(nil), (*decoderJsonIO).fastpathDecMapUint64Uint8R) - fn(map[uint64]uint64(nil), (*decoderJsonIO).fastpathDecMapUint64Uint64R) - fn(map[uint64]int(nil), (*decoderJsonIO).fastpathDecMapUint64IntR) - fn(map[uint64]int32(nil), (*decoderJsonIO).fastpathDecMapUint64Int32R) - fn(map[uint64]float64(nil), (*decoderJsonIO).fastpathDecMapUint64Float64R) - fn(map[uint64]bool(nil), (*decoderJsonIO).fastpathDecMapUint64BoolR) - fn(map[int]interface{}(nil), (*decoderJsonIO).fastpathDecMapIntIntfR) - fn(map[int]string(nil), (*decoderJsonIO).fastpathDecMapIntStringR) - fn(map[int][]byte(nil), (*decoderJsonIO).fastpathDecMapIntBytesR) - fn(map[int]uint8(nil), (*decoderJsonIO).fastpathDecMapIntUint8R) - fn(map[int]uint64(nil), (*decoderJsonIO).fastpathDecMapIntUint64R) - fn(map[int]int(nil), (*decoderJsonIO).fastpathDecMapIntIntR) - fn(map[int]int32(nil), (*decoderJsonIO).fastpathDecMapIntInt32R) - fn(map[int]float64(nil), (*decoderJsonIO).fastpathDecMapIntFloat64R) - fn(map[int]bool(nil), (*decoderJsonIO).fastpathDecMapIntBoolR) - fn(map[int32]interface{}(nil), (*decoderJsonIO).fastpathDecMapInt32IntfR) - fn(map[int32]string(nil), (*decoderJsonIO).fastpathDecMapInt32StringR) - fn(map[int32][]byte(nil), (*decoderJsonIO).fastpathDecMapInt32BytesR) - fn(map[int32]uint8(nil), (*decoderJsonIO).fastpathDecMapInt32Uint8R) - fn(map[int32]uint64(nil), (*decoderJsonIO).fastpathDecMapInt32Uint64R) - fn(map[int32]int(nil), (*decoderJsonIO).fastpathDecMapInt32IntR) - fn(map[int32]int32(nil), (*decoderJsonIO).fastpathDecMapInt32Int32R) - fn(map[int32]float64(nil), (*decoderJsonIO).fastpathDecMapInt32Float64R) - fn(map[int32]bool(nil), (*decoderJsonIO).fastpathDecMapInt32BoolR) - - sort.Slice(s[:], func(i, j int) bool { return s[i].rtid < s[j].rtid }) - return &s -} - -func (helperEncDriverJsonIO) fastpathEncodeTypeSwitch(iv interface{}, e *encoderJsonIO) bool { - var ft fastpathETJsonIO - switch v := iv.(type) { - case []interface{}: - if v == nil { - e.e.writeNilArray() - } else { - ft.EncSliceIntfV(v, e) - } - case []string: - if v == nil { - e.e.writeNilArray() - } else { - ft.EncSliceStringV(v, e) - } - case [][]byte: - if v == nil { - e.e.writeNilArray() - } else { - ft.EncSliceBytesV(v, e) - } - case []float32: - if v == nil { - e.e.writeNilArray() - } else { - ft.EncSliceFloat32V(v, e) - } - case []float64: - if v == nil { - e.e.writeNilArray() - } else { - ft.EncSliceFloat64V(v, e) - } - case []uint8: - if v == nil { - e.e.writeNilArray() - } else { - ft.EncSliceUint8V(v, e) - } - case []uint64: - if v == nil { - e.e.writeNilArray() - } else { - ft.EncSliceUint64V(v, e) - } - case []int: - if v == nil { - e.e.writeNilArray() - } else { - ft.EncSliceIntV(v, e) - } - case []int32: - if v == nil { - e.e.writeNilArray() - } else { - ft.EncSliceInt32V(v, e) - } - case []int64: - if v == nil { - e.e.writeNilArray() - } else { - ft.EncSliceInt64V(v, e) - } - case []bool: - if v == nil { - e.e.writeNilArray() - } else { - ft.EncSliceBoolV(v, e) - } - case map[string]interface{}: - if v == nil { - e.e.writeNilMap() - } else { - ft.EncMapStringIntfV(v, e) - } - case map[string]string: - if v == nil { - e.e.writeNilMap() - } else { - ft.EncMapStringStringV(v, e) - } - case map[string][]byte: - if v == nil { - e.e.writeNilMap() - } else { - ft.EncMapStringBytesV(v, e) - } - case map[string]uint8: - if v == nil { - e.e.writeNilMap() - } else { - ft.EncMapStringUint8V(v, e) - } - case map[string]uint64: - if v == nil { - e.e.writeNilMap() - } else { - ft.EncMapStringUint64V(v, e) - } - case map[string]int: - if v == nil { - e.e.writeNilMap() - } else { - ft.EncMapStringIntV(v, e) - } - case map[string]int32: - if v == nil { - e.e.writeNilMap() - } else { - ft.EncMapStringInt32V(v, e) - } - case map[string]float64: - if v == nil { - e.e.writeNilMap() - } else { - ft.EncMapStringFloat64V(v, e) - } - case map[string]bool: - if v == nil { - e.e.writeNilMap() - } else { - ft.EncMapStringBoolV(v, e) - } - case map[uint8]interface{}: - if v == nil { - e.e.writeNilMap() - } else { - ft.EncMapUint8IntfV(v, e) - } - case map[uint8]string: - if v == nil { - e.e.writeNilMap() - } else { - ft.EncMapUint8StringV(v, e) - } - case map[uint8][]byte: - if v == nil { - e.e.writeNilMap() - } else { - ft.EncMapUint8BytesV(v, e) - } - case map[uint8]uint8: - if v == nil { - e.e.writeNilMap() - } else { - ft.EncMapUint8Uint8V(v, e) - } - case map[uint8]uint64: - if v == nil { - e.e.writeNilMap() - } else { - ft.EncMapUint8Uint64V(v, e) - } - case map[uint8]int: - if v == nil { - e.e.writeNilMap() - } else { - ft.EncMapUint8IntV(v, e) - } - case map[uint8]int32: - if v == nil { - e.e.writeNilMap() - } else { - ft.EncMapUint8Int32V(v, e) - } - case map[uint8]float64: - if v == nil { - e.e.writeNilMap() - } else { - ft.EncMapUint8Float64V(v, e) - } - case map[uint8]bool: - if v == nil { - e.e.writeNilMap() - } else { - ft.EncMapUint8BoolV(v, e) - } - case map[uint64]interface{}: - if v == nil { - e.e.writeNilMap() - } else { - ft.EncMapUint64IntfV(v, e) - } - case map[uint64]string: - if v == nil { - e.e.writeNilMap() - } else { - ft.EncMapUint64StringV(v, e) - } - case map[uint64][]byte: - if v == nil { - e.e.writeNilMap() - } else { - ft.EncMapUint64BytesV(v, e) - } - case map[uint64]uint8: - if v == nil { - e.e.writeNilMap() - } else { - ft.EncMapUint64Uint8V(v, e) - } - case map[uint64]uint64: - if v == nil { - e.e.writeNilMap() - } else { - ft.EncMapUint64Uint64V(v, e) - } - case map[uint64]int: - if v == nil { - e.e.writeNilMap() - } else { - ft.EncMapUint64IntV(v, e) - } - case map[uint64]int32: - if v == nil { - e.e.writeNilMap() - } else { - ft.EncMapUint64Int32V(v, e) - } - case map[uint64]float64: - if v == nil { - e.e.writeNilMap() - } else { - ft.EncMapUint64Float64V(v, e) - } - case map[uint64]bool: - if v == nil { - e.e.writeNilMap() - } else { - ft.EncMapUint64BoolV(v, e) - } - case map[int]interface{}: - if v == nil { - e.e.writeNilMap() - } else { - ft.EncMapIntIntfV(v, e) - } - case map[int]string: - if v == nil { - e.e.writeNilMap() - } else { - ft.EncMapIntStringV(v, e) - } - case map[int][]byte: - if v == nil { - e.e.writeNilMap() - } else { - ft.EncMapIntBytesV(v, e) - } - case map[int]uint8: - if v == nil { - e.e.writeNilMap() - } else { - ft.EncMapIntUint8V(v, e) - } - case map[int]uint64: - if v == nil { - e.e.writeNilMap() - } else { - ft.EncMapIntUint64V(v, e) - } - case map[int]int: - if v == nil { - e.e.writeNilMap() - } else { - ft.EncMapIntIntV(v, e) - } - case map[int]int32: - if v == nil { - e.e.writeNilMap() - } else { - ft.EncMapIntInt32V(v, e) - } - case map[int]float64: - if v == nil { - e.e.writeNilMap() - } else { - ft.EncMapIntFloat64V(v, e) - } - case map[int]bool: - if v == nil { - e.e.writeNilMap() - } else { - ft.EncMapIntBoolV(v, e) - } - case map[int32]interface{}: - if v == nil { - e.e.writeNilMap() - } else { - ft.EncMapInt32IntfV(v, e) - } - case map[int32]string: - if v == nil { - e.e.writeNilMap() - } else { - ft.EncMapInt32StringV(v, e) - } - case map[int32][]byte: - if v == nil { - e.e.writeNilMap() - } else { - ft.EncMapInt32BytesV(v, e) - } - case map[int32]uint8: - if v == nil { - e.e.writeNilMap() - } else { - ft.EncMapInt32Uint8V(v, e) - } - case map[int32]uint64: - if v == nil { - e.e.writeNilMap() - } else { - ft.EncMapInt32Uint64V(v, e) - } - case map[int32]int: - if v == nil { - e.e.writeNilMap() - } else { - ft.EncMapInt32IntV(v, e) - } - case map[int32]int32: - if v == nil { - e.e.writeNilMap() - } else { - ft.EncMapInt32Int32V(v, e) - } - case map[int32]float64: - if v == nil { - e.e.writeNilMap() - } else { - ft.EncMapInt32Float64V(v, e) - } - case map[int32]bool: - if v == nil { - e.e.writeNilMap() - } else { - ft.EncMapInt32BoolV(v, e) - } - default: - _ = v - return false - } - return true -} - -func (e *encoderJsonIO) fastpathEncSliceIntfR(f *encFnInfo, rv reflect.Value) { - var ft fastpathETJsonIO - var v []interface{} - if rv.Kind() == reflect.Array { - rvGetSlice4Array(rv, &v) - } else { - v = rv2i(rv).([]interface{}) - } - if f.ti.mbs { - ft.EncAsMapSliceIntfV(v, e) - return - } - ft.EncSliceIntfV(v, e) -} -func (fastpathETJsonIO) EncSliceIntfV(v []interface{}, e *encoderJsonIO) { - if len(v) == 0 { - e.c = 0 - e.e.WriteArrayEmpty() - return - } - e.arrayStart(len(v)) - for j := range v { - e.c = containerArrayElem - e.e.WriteArrayElem(j == 0) - if !e.encodeBuiltin(v[j]) { - e.encodeR(reflect.ValueOf(v[j])) - } - } - e.c = 0 - e.e.WriteArrayEnd() -} -func (fastpathETJsonIO) EncAsMapSliceIntfV(v []interface{}, e *encoderJsonIO) { - if len(v) == 0 { - e.c = 0 - e.e.WriteMapEmpty() - return - } - e.haltOnMbsOddLen(len(v)) - e.mapStart(len(v) >> 1) - for j := range v { - if j&1 == 0 { - e.c = containerMapKey - e.e.WriteMapElemKey(j == 0) - } else { - e.mapElemValue() - } - if !e.encodeBuiltin(v[j]) { - e.encodeR(reflect.ValueOf(v[j])) - } - } - e.c = 0 - e.e.WriteMapEnd() -} - -func (e *encoderJsonIO) fastpathEncSliceStringR(f *encFnInfo, rv reflect.Value) { - var ft fastpathETJsonIO - var v []string - if rv.Kind() == reflect.Array { - rvGetSlice4Array(rv, &v) - } else { - v = rv2i(rv).([]string) - } - if f.ti.mbs { - ft.EncAsMapSliceStringV(v, e) - return - } - ft.EncSliceStringV(v, e) -} -func (fastpathETJsonIO) EncSliceStringV(v []string, e *encoderJsonIO) { - if len(v) == 0 { - e.c = 0 - e.e.WriteArrayEmpty() - return - } - e.arrayStart(len(v)) - for j := range v { - e.c = containerArrayElem - e.e.WriteArrayElem(j == 0) - e.e.EncodeString(v[j]) - } - e.c = 0 - e.e.WriteArrayEnd() -} -func (fastpathETJsonIO) EncAsMapSliceStringV(v []string, e *encoderJsonIO) { - if len(v) == 0 { - e.c = 0 - e.e.WriteMapEmpty() - return - } - e.haltOnMbsOddLen(len(v)) - e.mapStart(len(v) >> 1) - for j := range v { - if j&1 == 0 { - e.c = containerMapKey - e.e.WriteMapElemKey(j == 0) - } else { - e.mapElemValue() - } - e.e.EncodeString(v[j]) - } - e.c = 0 - e.e.WriteMapEnd() -} - -func (e *encoderJsonIO) fastpathEncSliceBytesR(f *encFnInfo, rv reflect.Value) { - var ft fastpathETJsonIO - var v [][]byte - if rv.Kind() == reflect.Array { - rvGetSlice4Array(rv, &v) - } else { - v = rv2i(rv).([][]byte) - } - if f.ti.mbs { - ft.EncAsMapSliceBytesV(v, e) - return - } - ft.EncSliceBytesV(v, e) -} -func (fastpathETJsonIO) EncSliceBytesV(v [][]byte, e *encoderJsonIO) { - if len(v) == 0 { - e.c = 0 - e.e.WriteArrayEmpty() - return - } - e.arrayStart(len(v)) - for j := range v { - e.c = containerArrayElem - e.e.WriteArrayElem(j == 0) - e.e.EncodeBytes(v[j]) - } - e.c = 0 - e.e.WriteArrayEnd() -} -func (fastpathETJsonIO) EncAsMapSliceBytesV(v [][]byte, e *encoderJsonIO) { - if len(v) == 0 { - e.c = 0 - e.e.WriteMapEmpty() - return - } - e.haltOnMbsOddLen(len(v)) - e.mapStart(len(v) >> 1) - for j := range v { - if j&1 == 0 { - e.c = containerMapKey - e.e.WriteMapElemKey(j == 0) - } else { - e.mapElemValue() - } - e.e.EncodeBytes(v[j]) - } - e.c = 0 - e.e.WriteMapEnd() -} - -func (e *encoderJsonIO) fastpathEncSliceFloat32R(f *encFnInfo, rv reflect.Value) { - var ft fastpathETJsonIO - var v []float32 - if rv.Kind() == reflect.Array { - rvGetSlice4Array(rv, &v) - } else { - v = rv2i(rv).([]float32) - } - if f.ti.mbs { - ft.EncAsMapSliceFloat32V(v, e) - return - } - ft.EncSliceFloat32V(v, e) -} -func (fastpathETJsonIO) EncSliceFloat32V(v []float32, e *encoderJsonIO) { - if len(v) == 0 { - e.c = 0 - e.e.WriteArrayEmpty() - return - } - e.arrayStart(len(v)) - for j := range v { - e.c = containerArrayElem - e.e.WriteArrayElem(j == 0) - e.e.EncodeFloat32(v[j]) - } - e.c = 0 - e.e.WriteArrayEnd() -} -func (fastpathETJsonIO) EncAsMapSliceFloat32V(v []float32, e *encoderJsonIO) { - if len(v) == 0 { - e.c = 0 - e.e.WriteMapEmpty() - return - } - e.haltOnMbsOddLen(len(v)) - e.mapStart(len(v) >> 1) - for j := range v { - if j&1 == 0 { - e.c = containerMapKey - e.e.WriteMapElemKey(j == 0) - } else { - e.mapElemValue() - } - e.e.EncodeFloat32(v[j]) - } - e.c = 0 - e.e.WriteMapEnd() -} - -func (e *encoderJsonIO) fastpathEncSliceFloat64R(f *encFnInfo, rv reflect.Value) { - var ft fastpathETJsonIO - var v []float64 - if rv.Kind() == reflect.Array { - rvGetSlice4Array(rv, &v) - } else { - v = rv2i(rv).([]float64) - } - if f.ti.mbs { - ft.EncAsMapSliceFloat64V(v, e) - return - } - ft.EncSliceFloat64V(v, e) -} -func (fastpathETJsonIO) EncSliceFloat64V(v []float64, e *encoderJsonIO) { - if len(v) == 0 { - e.c = 0 - e.e.WriteArrayEmpty() - return - } - e.arrayStart(len(v)) - for j := range v { - e.c = containerArrayElem - e.e.WriteArrayElem(j == 0) - e.e.EncodeFloat64(v[j]) - } - e.c = 0 - e.e.WriteArrayEnd() -} -func (fastpathETJsonIO) EncAsMapSliceFloat64V(v []float64, e *encoderJsonIO) { - if len(v) == 0 { - e.c = 0 - e.e.WriteMapEmpty() - return - } - e.haltOnMbsOddLen(len(v)) - e.mapStart(len(v) >> 1) - for j := range v { - if j&1 == 0 { - e.c = containerMapKey - e.e.WriteMapElemKey(j == 0) - } else { - e.mapElemValue() - } - e.e.EncodeFloat64(v[j]) - } - e.c = 0 - e.e.WriteMapEnd() -} - -func (e *encoderJsonIO) fastpathEncSliceUint8R(f *encFnInfo, rv reflect.Value) { - var ft fastpathETJsonIO - var v []uint8 - if rv.Kind() == reflect.Array { - rvGetSlice4Array(rv, &v) - } else { - v = rv2i(rv).([]uint8) - } - if f.ti.mbs { - ft.EncAsMapSliceUint8V(v, e) - return - } - ft.EncSliceUint8V(v, e) -} -func (fastpathETJsonIO) EncSliceUint8V(v []uint8, e *encoderJsonIO) { - e.e.EncodeStringBytesRaw(v) -} -func (fastpathETJsonIO) EncAsMapSliceUint8V(v []uint8, e *encoderJsonIO) { - if len(v) == 0 { - e.c = 0 - e.e.WriteMapEmpty() - return - } - e.haltOnMbsOddLen(len(v)) - e.mapStart(len(v) >> 1) - for j := range v { - if j&1 == 0 { - e.c = containerMapKey - e.e.WriteMapElemKey(j == 0) - } else { - e.mapElemValue() - } - e.e.EncodeUint(uint64(v[j])) - } - e.c = 0 - e.e.WriteMapEnd() -} - -func (e *encoderJsonIO) fastpathEncSliceUint64R(f *encFnInfo, rv reflect.Value) { - var ft fastpathETJsonIO - var v []uint64 - if rv.Kind() == reflect.Array { - rvGetSlice4Array(rv, &v) - } else { - v = rv2i(rv).([]uint64) - } - if f.ti.mbs { - ft.EncAsMapSliceUint64V(v, e) - return - } - ft.EncSliceUint64V(v, e) -} -func (fastpathETJsonIO) EncSliceUint64V(v []uint64, e *encoderJsonIO) { - if len(v) == 0 { - e.c = 0 - e.e.WriteArrayEmpty() - return - } - e.arrayStart(len(v)) - for j := range v { - e.c = containerArrayElem - e.e.WriteArrayElem(j == 0) - e.e.EncodeUint(v[j]) - } - e.c = 0 - e.e.WriteArrayEnd() -} -func (fastpathETJsonIO) EncAsMapSliceUint64V(v []uint64, e *encoderJsonIO) { - if len(v) == 0 { - e.c = 0 - e.e.WriteMapEmpty() - return - } - e.haltOnMbsOddLen(len(v)) - e.mapStart(len(v) >> 1) - for j := range v { - if j&1 == 0 { - e.c = containerMapKey - e.e.WriteMapElemKey(j == 0) - } else { - e.mapElemValue() - } - e.e.EncodeUint(v[j]) - } - e.c = 0 - e.e.WriteMapEnd() -} - -func (e *encoderJsonIO) fastpathEncSliceIntR(f *encFnInfo, rv reflect.Value) { - var ft fastpathETJsonIO - var v []int - if rv.Kind() == reflect.Array { - rvGetSlice4Array(rv, &v) - } else { - v = rv2i(rv).([]int) - } - if f.ti.mbs { - ft.EncAsMapSliceIntV(v, e) - return - } - ft.EncSliceIntV(v, e) -} -func (fastpathETJsonIO) EncSliceIntV(v []int, e *encoderJsonIO) { - if len(v) == 0 { - e.c = 0 - e.e.WriteArrayEmpty() - return - } - e.arrayStart(len(v)) - for j := range v { - e.c = containerArrayElem - e.e.WriteArrayElem(j == 0) - e.e.EncodeInt(int64(v[j])) - } - e.c = 0 - e.e.WriteArrayEnd() -} -func (fastpathETJsonIO) EncAsMapSliceIntV(v []int, e *encoderJsonIO) { - if len(v) == 0 { - e.c = 0 - e.e.WriteMapEmpty() - return - } - e.haltOnMbsOddLen(len(v)) - e.mapStart(len(v) >> 1) - for j := range v { - if j&1 == 0 { - e.c = containerMapKey - e.e.WriteMapElemKey(j == 0) - } else { - e.mapElemValue() - } - e.e.EncodeInt(int64(v[j])) - } - e.c = 0 - e.e.WriteMapEnd() -} - -func (e *encoderJsonIO) fastpathEncSliceInt32R(f *encFnInfo, rv reflect.Value) { - var ft fastpathETJsonIO - var v []int32 - if rv.Kind() == reflect.Array { - rvGetSlice4Array(rv, &v) - } else { - v = rv2i(rv).([]int32) - } - if f.ti.mbs { - ft.EncAsMapSliceInt32V(v, e) - return - } - ft.EncSliceInt32V(v, e) -} -func (fastpathETJsonIO) EncSliceInt32V(v []int32, e *encoderJsonIO) { - if len(v) == 0 { - e.c = 0 - e.e.WriteArrayEmpty() - return - } - e.arrayStart(len(v)) - for j := range v { - e.c = containerArrayElem - e.e.WriteArrayElem(j == 0) - e.e.EncodeInt(int64(v[j])) - } - e.c = 0 - e.e.WriteArrayEnd() -} -func (fastpathETJsonIO) EncAsMapSliceInt32V(v []int32, e *encoderJsonIO) { - if len(v) == 0 { - e.c = 0 - e.e.WriteMapEmpty() - return - } - e.haltOnMbsOddLen(len(v)) - e.mapStart(len(v) >> 1) - for j := range v { - if j&1 == 0 { - e.c = containerMapKey - e.e.WriteMapElemKey(j == 0) - } else { - e.mapElemValue() - } - e.e.EncodeInt(int64(v[j])) - } - e.c = 0 - e.e.WriteMapEnd() -} - -func (e *encoderJsonIO) fastpathEncSliceInt64R(f *encFnInfo, rv reflect.Value) { - var ft fastpathETJsonIO - var v []int64 - if rv.Kind() == reflect.Array { - rvGetSlice4Array(rv, &v) - } else { - v = rv2i(rv).([]int64) - } - if f.ti.mbs { - ft.EncAsMapSliceInt64V(v, e) - return - } - ft.EncSliceInt64V(v, e) -} -func (fastpathETJsonIO) EncSliceInt64V(v []int64, e *encoderJsonIO) { - if len(v) == 0 { - e.c = 0 - e.e.WriteArrayEmpty() - return - } - e.arrayStart(len(v)) - for j := range v { - e.c = containerArrayElem - e.e.WriteArrayElem(j == 0) - e.e.EncodeInt(v[j]) - } - e.c = 0 - e.e.WriteArrayEnd() -} -func (fastpathETJsonIO) EncAsMapSliceInt64V(v []int64, e *encoderJsonIO) { - if len(v) == 0 { - e.c = 0 - e.e.WriteMapEmpty() - return - } - e.haltOnMbsOddLen(len(v)) - e.mapStart(len(v) >> 1) - for j := range v { - if j&1 == 0 { - e.c = containerMapKey - e.e.WriteMapElemKey(j == 0) - } else { - e.mapElemValue() - } - e.e.EncodeInt(v[j]) - } - e.c = 0 - e.e.WriteMapEnd() -} - -func (e *encoderJsonIO) fastpathEncSliceBoolR(f *encFnInfo, rv reflect.Value) { - var ft fastpathETJsonIO - var v []bool - if rv.Kind() == reflect.Array { - rvGetSlice4Array(rv, &v) - } else { - v = rv2i(rv).([]bool) - } - if f.ti.mbs { - ft.EncAsMapSliceBoolV(v, e) - return - } - ft.EncSliceBoolV(v, e) -} -func (fastpathETJsonIO) EncSliceBoolV(v []bool, e *encoderJsonIO) { - if len(v) == 0 { - e.c = 0 - e.e.WriteArrayEmpty() - return - } - e.arrayStart(len(v)) - for j := range v { - e.c = containerArrayElem - e.e.WriteArrayElem(j == 0) - e.e.EncodeBool(v[j]) - } - e.c = 0 - e.e.WriteArrayEnd() -} -func (fastpathETJsonIO) EncAsMapSliceBoolV(v []bool, e *encoderJsonIO) { - if len(v) == 0 { - e.c = 0 - e.e.WriteMapEmpty() - return - } - e.haltOnMbsOddLen(len(v)) - e.mapStart(len(v) >> 1) - for j := range v { - if j&1 == 0 { - e.c = containerMapKey - e.e.WriteMapElemKey(j == 0) - } else { - e.mapElemValue() - } - e.e.EncodeBool(v[j]) - } - e.c = 0 - e.e.WriteMapEnd() -} - -func (e *encoderJsonIO) fastpathEncMapStringIntfR(f *encFnInfo, rv reflect.Value) { - fastpathETJsonIO{}.EncMapStringIntfV(rv2i(rv).(map[string]interface{}), e) -} -func (fastpathETJsonIO) EncMapStringIntfV(v map[string]interface{}, e *encoderJsonIO) { - if len(v) == 0 { - e.e.WriteMapEmpty() - return - } - var i uint - e.mapStart(len(v)) - if e.h.Canonical { - v2 := make([]string, len(v)) - for k := range v { - v2[i] = k - i++ - } - slices.Sort(v2) - for i, k2 := range v2 { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeString(k2) - e.mapElemValue() - if !e.encodeBuiltin(v[k2]) { - e.encodeR(reflect.ValueOf(v[k2])) - } - } - } else { - i = 0 - for k2, v2 := range v { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeString(k2) - e.mapElemValue() - if !e.encodeBuiltin(v2) { - e.encodeR(reflect.ValueOf(v2)) - } - i++ - } - } - e.c = 0 - e.e.WriteMapEnd() -} -func (e *encoderJsonIO) fastpathEncMapStringStringR(f *encFnInfo, rv reflect.Value) { - fastpathETJsonIO{}.EncMapStringStringV(rv2i(rv).(map[string]string), e) -} -func (fastpathETJsonIO) EncMapStringStringV(v map[string]string, e *encoderJsonIO) { - if len(v) == 0 { - e.e.WriteMapEmpty() - return - } - var i uint - e.mapStart(len(v)) - if e.h.Canonical { - v2 := make([]string, len(v)) - for k := range v { - v2[i] = k - i++ - } - slices.Sort(v2) - for i, k2 := range v2 { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeString(k2) - e.mapElemValue() - e.e.EncodeString(v[k2]) - } - } else { - i = 0 - for k2, v2 := range v { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeString(k2) - e.mapElemValue() - e.e.EncodeString(v2) - i++ - } - } - e.c = 0 - e.e.WriteMapEnd() -} -func (e *encoderJsonIO) fastpathEncMapStringBytesR(f *encFnInfo, rv reflect.Value) { - fastpathETJsonIO{}.EncMapStringBytesV(rv2i(rv).(map[string][]byte), e) -} -func (fastpathETJsonIO) EncMapStringBytesV(v map[string][]byte, e *encoderJsonIO) { - if len(v) == 0 { - e.e.WriteMapEmpty() - return - } - var i uint - e.mapStart(len(v)) - if e.h.Canonical { - v2 := make([]string, len(v)) - for k := range v { - v2[i] = k - i++ - } - slices.Sort(v2) - for i, k2 := range v2 { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeString(k2) - e.mapElemValue() - e.e.EncodeBytes(v[k2]) - } - } else { - i = 0 - for k2, v2 := range v { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeString(k2) - e.mapElemValue() - e.e.EncodeBytes(v2) - i++ - } - } - e.c = 0 - e.e.WriteMapEnd() -} -func (e *encoderJsonIO) fastpathEncMapStringUint8R(f *encFnInfo, rv reflect.Value) { - fastpathETJsonIO{}.EncMapStringUint8V(rv2i(rv).(map[string]uint8), e) -} -func (fastpathETJsonIO) EncMapStringUint8V(v map[string]uint8, e *encoderJsonIO) { - if len(v) == 0 { - e.e.WriteMapEmpty() - return - } - var i uint - e.mapStart(len(v)) - if e.h.Canonical { - v2 := make([]string, len(v)) - for k := range v { - v2[i] = k - i++ - } - slices.Sort(v2) - for i, k2 := range v2 { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeString(k2) - e.mapElemValue() - e.e.EncodeUint(uint64(v[k2])) - } - } else { - i = 0 - for k2, v2 := range v { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeString(k2) - e.mapElemValue() - e.e.EncodeUint(uint64(v2)) - i++ - } - } - e.c = 0 - e.e.WriteMapEnd() -} -func (e *encoderJsonIO) fastpathEncMapStringUint64R(f *encFnInfo, rv reflect.Value) { - fastpathETJsonIO{}.EncMapStringUint64V(rv2i(rv).(map[string]uint64), e) -} -func (fastpathETJsonIO) EncMapStringUint64V(v map[string]uint64, e *encoderJsonIO) { - if len(v) == 0 { - e.e.WriteMapEmpty() - return - } - var i uint - e.mapStart(len(v)) - if e.h.Canonical { - v2 := make([]string, len(v)) - for k := range v { - v2[i] = k - i++ - } - slices.Sort(v2) - for i, k2 := range v2 { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeString(k2) - e.mapElemValue() - e.e.EncodeUint(v[k2]) - } - } else { - i = 0 - for k2, v2 := range v { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeString(k2) - e.mapElemValue() - e.e.EncodeUint(v2) - i++ - } - } - e.c = 0 - e.e.WriteMapEnd() -} -func (e *encoderJsonIO) fastpathEncMapStringIntR(f *encFnInfo, rv reflect.Value) { - fastpathETJsonIO{}.EncMapStringIntV(rv2i(rv).(map[string]int), e) -} -func (fastpathETJsonIO) EncMapStringIntV(v map[string]int, e *encoderJsonIO) { - if len(v) == 0 { - e.e.WriteMapEmpty() - return - } - var i uint - e.mapStart(len(v)) - if e.h.Canonical { - v2 := make([]string, len(v)) - for k := range v { - v2[i] = k - i++ - } - slices.Sort(v2) - for i, k2 := range v2 { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeString(k2) - e.mapElemValue() - e.e.EncodeInt(int64(v[k2])) - } - } else { - i = 0 - for k2, v2 := range v { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeString(k2) - e.mapElemValue() - e.e.EncodeInt(int64(v2)) - i++ - } - } - e.c = 0 - e.e.WriteMapEnd() -} -func (e *encoderJsonIO) fastpathEncMapStringInt32R(f *encFnInfo, rv reflect.Value) { - fastpathETJsonIO{}.EncMapStringInt32V(rv2i(rv).(map[string]int32), e) -} -func (fastpathETJsonIO) EncMapStringInt32V(v map[string]int32, e *encoderJsonIO) { - if len(v) == 0 { - e.e.WriteMapEmpty() - return - } - var i uint - e.mapStart(len(v)) - if e.h.Canonical { - v2 := make([]string, len(v)) - for k := range v { - v2[i] = k - i++ - } - slices.Sort(v2) - for i, k2 := range v2 { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeString(k2) - e.mapElemValue() - e.e.EncodeInt(int64(v[k2])) - } - } else { - i = 0 - for k2, v2 := range v { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeString(k2) - e.mapElemValue() - e.e.EncodeInt(int64(v2)) - i++ - } - } - e.c = 0 - e.e.WriteMapEnd() -} -func (e *encoderJsonIO) fastpathEncMapStringFloat64R(f *encFnInfo, rv reflect.Value) { - fastpathETJsonIO{}.EncMapStringFloat64V(rv2i(rv).(map[string]float64), e) -} -func (fastpathETJsonIO) EncMapStringFloat64V(v map[string]float64, e *encoderJsonIO) { - if len(v) == 0 { - e.e.WriteMapEmpty() - return - } - var i uint - e.mapStart(len(v)) - if e.h.Canonical { - v2 := make([]string, len(v)) - for k := range v { - v2[i] = k - i++ - } - slices.Sort(v2) - for i, k2 := range v2 { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeString(k2) - e.mapElemValue() - e.e.EncodeFloat64(v[k2]) - } - } else { - i = 0 - for k2, v2 := range v { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeString(k2) - e.mapElemValue() - e.e.EncodeFloat64(v2) - i++ - } - } - e.c = 0 - e.e.WriteMapEnd() -} -func (e *encoderJsonIO) fastpathEncMapStringBoolR(f *encFnInfo, rv reflect.Value) { - fastpathETJsonIO{}.EncMapStringBoolV(rv2i(rv).(map[string]bool), e) -} -func (fastpathETJsonIO) EncMapStringBoolV(v map[string]bool, e *encoderJsonIO) { - if len(v) == 0 { - e.e.WriteMapEmpty() - return - } - var i uint - e.mapStart(len(v)) - if e.h.Canonical { - v2 := make([]string, len(v)) - for k := range v { - v2[i] = k - i++ - } - slices.Sort(v2) - for i, k2 := range v2 { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeString(k2) - e.mapElemValue() - e.e.EncodeBool(v[k2]) - } - } else { - i = 0 - for k2, v2 := range v { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeString(k2) - e.mapElemValue() - e.e.EncodeBool(v2) - i++ - } - } - e.c = 0 - e.e.WriteMapEnd() -} -func (e *encoderJsonIO) fastpathEncMapUint8IntfR(f *encFnInfo, rv reflect.Value) { - fastpathETJsonIO{}.EncMapUint8IntfV(rv2i(rv).(map[uint8]interface{}), e) -} -func (fastpathETJsonIO) EncMapUint8IntfV(v map[uint8]interface{}, e *encoderJsonIO) { - if len(v) == 0 { - e.e.WriteMapEmpty() - return - } - var i uint - e.mapStart(len(v)) - if e.h.Canonical { - v2 := make([]uint8, len(v)) - for k := range v { - v2[i] = k - i++ - } - slices.Sort(v2) - for i, k2 := range v2 { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeUint(uint64(k2)) - e.mapElemValue() - if !e.encodeBuiltin(v[k2]) { - e.encodeR(reflect.ValueOf(v[k2])) - } - } - } else { - i = 0 - for k2, v2 := range v { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeUint(uint64(k2)) - e.mapElemValue() - if !e.encodeBuiltin(v2) { - e.encodeR(reflect.ValueOf(v2)) - } - i++ - } - } - e.c = 0 - e.e.WriteMapEnd() -} -func (e *encoderJsonIO) fastpathEncMapUint8StringR(f *encFnInfo, rv reflect.Value) { - fastpathETJsonIO{}.EncMapUint8StringV(rv2i(rv).(map[uint8]string), e) -} -func (fastpathETJsonIO) EncMapUint8StringV(v map[uint8]string, e *encoderJsonIO) { - if len(v) == 0 { - e.e.WriteMapEmpty() - return - } - var i uint - e.mapStart(len(v)) - if e.h.Canonical { - v2 := make([]uint8, len(v)) - for k := range v { - v2[i] = k - i++ - } - slices.Sort(v2) - for i, k2 := range v2 { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeUint(uint64(k2)) - e.mapElemValue() - e.e.EncodeString(v[k2]) - } - } else { - i = 0 - for k2, v2 := range v { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeUint(uint64(k2)) - e.mapElemValue() - e.e.EncodeString(v2) - i++ - } - } - e.c = 0 - e.e.WriteMapEnd() -} -func (e *encoderJsonIO) fastpathEncMapUint8BytesR(f *encFnInfo, rv reflect.Value) { - fastpathETJsonIO{}.EncMapUint8BytesV(rv2i(rv).(map[uint8][]byte), e) -} -func (fastpathETJsonIO) EncMapUint8BytesV(v map[uint8][]byte, e *encoderJsonIO) { - if len(v) == 0 { - e.e.WriteMapEmpty() - return - } - var i uint - e.mapStart(len(v)) - if e.h.Canonical { - v2 := make([]uint8, len(v)) - for k := range v { - v2[i] = k - i++ - } - slices.Sort(v2) - for i, k2 := range v2 { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeUint(uint64(k2)) - e.mapElemValue() - e.e.EncodeBytes(v[k2]) - } - } else { - i = 0 - for k2, v2 := range v { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeUint(uint64(k2)) - e.mapElemValue() - e.e.EncodeBytes(v2) - i++ - } - } - e.c = 0 - e.e.WriteMapEnd() -} -func (e *encoderJsonIO) fastpathEncMapUint8Uint8R(f *encFnInfo, rv reflect.Value) { - fastpathETJsonIO{}.EncMapUint8Uint8V(rv2i(rv).(map[uint8]uint8), e) -} -func (fastpathETJsonIO) EncMapUint8Uint8V(v map[uint8]uint8, e *encoderJsonIO) { - if len(v) == 0 { - e.e.WriteMapEmpty() - return - } - var i uint - e.mapStart(len(v)) - if e.h.Canonical { - v2 := make([]uint8, len(v)) - for k := range v { - v2[i] = k - i++ - } - slices.Sort(v2) - for i, k2 := range v2 { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeUint(uint64(k2)) - e.mapElemValue() - e.e.EncodeUint(uint64(v[k2])) - } - } else { - i = 0 - for k2, v2 := range v { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeUint(uint64(k2)) - e.mapElemValue() - e.e.EncodeUint(uint64(v2)) - i++ - } - } - e.c = 0 - e.e.WriteMapEnd() -} -func (e *encoderJsonIO) fastpathEncMapUint8Uint64R(f *encFnInfo, rv reflect.Value) { - fastpathETJsonIO{}.EncMapUint8Uint64V(rv2i(rv).(map[uint8]uint64), e) -} -func (fastpathETJsonIO) EncMapUint8Uint64V(v map[uint8]uint64, e *encoderJsonIO) { - if len(v) == 0 { - e.e.WriteMapEmpty() - return - } - var i uint - e.mapStart(len(v)) - if e.h.Canonical { - v2 := make([]uint8, len(v)) - for k := range v { - v2[i] = k - i++ - } - slices.Sort(v2) - for i, k2 := range v2 { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeUint(uint64(k2)) - e.mapElemValue() - e.e.EncodeUint(v[k2]) - } - } else { - i = 0 - for k2, v2 := range v { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeUint(uint64(k2)) - e.mapElemValue() - e.e.EncodeUint(v2) - i++ - } - } - e.c = 0 - e.e.WriteMapEnd() -} -func (e *encoderJsonIO) fastpathEncMapUint8IntR(f *encFnInfo, rv reflect.Value) { - fastpathETJsonIO{}.EncMapUint8IntV(rv2i(rv).(map[uint8]int), e) -} -func (fastpathETJsonIO) EncMapUint8IntV(v map[uint8]int, e *encoderJsonIO) { - if len(v) == 0 { - e.e.WriteMapEmpty() - return - } - var i uint - e.mapStart(len(v)) - if e.h.Canonical { - v2 := make([]uint8, len(v)) - for k := range v { - v2[i] = k - i++ - } - slices.Sort(v2) - for i, k2 := range v2 { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeUint(uint64(k2)) - e.mapElemValue() - e.e.EncodeInt(int64(v[k2])) - } - } else { - i = 0 - for k2, v2 := range v { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeUint(uint64(k2)) - e.mapElemValue() - e.e.EncodeInt(int64(v2)) - i++ - } - } - e.c = 0 - e.e.WriteMapEnd() -} -func (e *encoderJsonIO) fastpathEncMapUint8Int32R(f *encFnInfo, rv reflect.Value) { - fastpathETJsonIO{}.EncMapUint8Int32V(rv2i(rv).(map[uint8]int32), e) -} -func (fastpathETJsonIO) EncMapUint8Int32V(v map[uint8]int32, e *encoderJsonIO) { - if len(v) == 0 { - e.e.WriteMapEmpty() - return - } - var i uint - e.mapStart(len(v)) - if e.h.Canonical { - v2 := make([]uint8, len(v)) - for k := range v { - v2[i] = k - i++ - } - slices.Sort(v2) - for i, k2 := range v2 { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeUint(uint64(k2)) - e.mapElemValue() - e.e.EncodeInt(int64(v[k2])) - } - } else { - i = 0 - for k2, v2 := range v { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeUint(uint64(k2)) - e.mapElemValue() - e.e.EncodeInt(int64(v2)) - i++ - } - } - e.c = 0 - e.e.WriteMapEnd() -} -func (e *encoderJsonIO) fastpathEncMapUint8Float64R(f *encFnInfo, rv reflect.Value) { - fastpathETJsonIO{}.EncMapUint8Float64V(rv2i(rv).(map[uint8]float64), e) -} -func (fastpathETJsonIO) EncMapUint8Float64V(v map[uint8]float64, e *encoderJsonIO) { - if len(v) == 0 { - e.e.WriteMapEmpty() - return - } - var i uint - e.mapStart(len(v)) - if e.h.Canonical { - v2 := make([]uint8, len(v)) - for k := range v { - v2[i] = k - i++ - } - slices.Sort(v2) - for i, k2 := range v2 { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeUint(uint64(k2)) - e.mapElemValue() - e.e.EncodeFloat64(v[k2]) - } - } else { - i = 0 - for k2, v2 := range v { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeUint(uint64(k2)) - e.mapElemValue() - e.e.EncodeFloat64(v2) - i++ - } - } - e.c = 0 - e.e.WriteMapEnd() -} -func (e *encoderJsonIO) fastpathEncMapUint8BoolR(f *encFnInfo, rv reflect.Value) { - fastpathETJsonIO{}.EncMapUint8BoolV(rv2i(rv).(map[uint8]bool), e) -} -func (fastpathETJsonIO) EncMapUint8BoolV(v map[uint8]bool, e *encoderJsonIO) { - if len(v) == 0 { - e.e.WriteMapEmpty() - return - } - var i uint - e.mapStart(len(v)) - if e.h.Canonical { - v2 := make([]uint8, len(v)) - for k := range v { - v2[i] = k - i++ - } - slices.Sort(v2) - for i, k2 := range v2 { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeUint(uint64(k2)) - e.mapElemValue() - e.e.EncodeBool(v[k2]) - } - } else { - i = 0 - for k2, v2 := range v { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeUint(uint64(k2)) - e.mapElemValue() - e.e.EncodeBool(v2) - i++ - } - } - e.c = 0 - e.e.WriteMapEnd() -} -func (e *encoderJsonIO) fastpathEncMapUint64IntfR(f *encFnInfo, rv reflect.Value) { - fastpathETJsonIO{}.EncMapUint64IntfV(rv2i(rv).(map[uint64]interface{}), e) -} -func (fastpathETJsonIO) EncMapUint64IntfV(v map[uint64]interface{}, e *encoderJsonIO) { - if len(v) == 0 { - e.e.WriteMapEmpty() - return - } - var i uint - e.mapStart(len(v)) - if e.h.Canonical { - v2 := make([]uint64, len(v)) - for k := range v { - v2[i] = k - i++ - } - slices.Sort(v2) - for i, k2 := range v2 { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeUint(k2) - e.mapElemValue() - if !e.encodeBuiltin(v[k2]) { - e.encodeR(reflect.ValueOf(v[k2])) - } - } - } else { - i = 0 - for k2, v2 := range v { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeUint(k2) - e.mapElemValue() - if !e.encodeBuiltin(v2) { - e.encodeR(reflect.ValueOf(v2)) - } - i++ - } - } - e.c = 0 - e.e.WriteMapEnd() -} -func (e *encoderJsonIO) fastpathEncMapUint64StringR(f *encFnInfo, rv reflect.Value) { - fastpathETJsonIO{}.EncMapUint64StringV(rv2i(rv).(map[uint64]string), e) -} -func (fastpathETJsonIO) EncMapUint64StringV(v map[uint64]string, e *encoderJsonIO) { - if len(v) == 0 { - e.e.WriteMapEmpty() - return - } - var i uint - e.mapStart(len(v)) - if e.h.Canonical { - v2 := make([]uint64, len(v)) - for k := range v { - v2[i] = k - i++ - } - slices.Sort(v2) - for i, k2 := range v2 { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeUint(k2) - e.mapElemValue() - e.e.EncodeString(v[k2]) - } - } else { - i = 0 - for k2, v2 := range v { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeUint(k2) - e.mapElemValue() - e.e.EncodeString(v2) - i++ - } - } - e.c = 0 - e.e.WriteMapEnd() -} -func (e *encoderJsonIO) fastpathEncMapUint64BytesR(f *encFnInfo, rv reflect.Value) { - fastpathETJsonIO{}.EncMapUint64BytesV(rv2i(rv).(map[uint64][]byte), e) -} -func (fastpathETJsonIO) EncMapUint64BytesV(v map[uint64][]byte, e *encoderJsonIO) { - if len(v) == 0 { - e.e.WriteMapEmpty() - return - } - var i uint - e.mapStart(len(v)) - if e.h.Canonical { - v2 := make([]uint64, len(v)) - for k := range v { - v2[i] = k - i++ - } - slices.Sort(v2) - for i, k2 := range v2 { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeUint(k2) - e.mapElemValue() - e.e.EncodeBytes(v[k2]) - } - } else { - i = 0 - for k2, v2 := range v { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeUint(k2) - e.mapElemValue() - e.e.EncodeBytes(v2) - i++ - } - } - e.c = 0 - e.e.WriteMapEnd() -} -func (e *encoderJsonIO) fastpathEncMapUint64Uint8R(f *encFnInfo, rv reflect.Value) { - fastpathETJsonIO{}.EncMapUint64Uint8V(rv2i(rv).(map[uint64]uint8), e) -} -func (fastpathETJsonIO) EncMapUint64Uint8V(v map[uint64]uint8, e *encoderJsonIO) { - if len(v) == 0 { - e.e.WriteMapEmpty() - return - } - var i uint - e.mapStart(len(v)) - if e.h.Canonical { - v2 := make([]uint64, len(v)) - for k := range v { - v2[i] = k - i++ - } - slices.Sort(v2) - for i, k2 := range v2 { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeUint(k2) - e.mapElemValue() - e.e.EncodeUint(uint64(v[k2])) - } - } else { - i = 0 - for k2, v2 := range v { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeUint(k2) - e.mapElemValue() - e.e.EncodeUint(uint64(v2)) - i++ - } - } - e.c = 0 - e.e.WriteMapEnd() -} -func (e *encoderJsonIO) fastpathEncMapUint64Uint64R(f *encFnInfo, rv reflect.Value) { - fastpathETJsonIO{}.EncMapUint64Uint64V(rv2i(rv).(map[uint64]uint64), e) -} -func (fastpathETJsonIO) EncMapUint64Uint64V(v map[uint64]uint64, e *encoderJsonIO) { - if len(v) == 0 { - e.e.WriteMapEmpty() - return - } - var i uint - e.mapStart(len(v)) - if e.h.Canonical { - v2 := make([]uint64, len(v)) - for k := range v { - v2[i] = k - i++ - } - slices.Sort(v2) - for i, k2 := range v2 { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeUint(k2) - e.mapElemValue() - e.e.EncodeUint(v[k2]) - } - } else { - i = 0 - for k2, v2 := range v { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeUint(k2) - e.mapElemValue() - e.e.EncodeUint(v2) - i++ - } - } - e.c = 0 - e.e.WriteMapEnd() -} -func (e *encoderJsonIO) fastpathEncMapUint64IntR(f *encFnInfo, rv reflect.Value) { - fastpathETJsonIO{}.EncMapUint64IntV(rv2i(rv).(map[uint64]int), e) -} -func (fastpathETJsonIO) EncMapUint64IntV(v map[uint64]int, e *encoderJsonIO) { - if len(v) == 0 { - e.e.WriteMapEmpty() - return - } - var i uint - e.mapStart(len(v)) - if e.h.Canonical { - v2 := make([]uint64, len(v)) - for k := range v { - v2[i] = k - i++ - } - slices.Sort(v2) - for i, k2 := range v2 { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeUint(k2) - e.mapElemValue() - e.e.EncodeInt(int64(v[k2])) - } - } else { - i = 0 - for k2, v2 := range v { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeUint(k2) - e.mapElemValue() - e.e.EncodeInt(int64(v2)) - i++ - } - } - e.c = 0 - e.e.WriteMapEnd() -} -func (e *encoderJsonIO) fastpathEncMapUint64Int32R(f *encFnInfo, rv reflect.Value) { - fastpathETJsonIO{}.EncMapUint64Int32V(rv2i(rv).(map[uint64]int32), e) -} -func (fastpathETJsonIO) EncMapUint64Int32V(v map[uint64]int32, e *encoderJsonIO) { - if len(v) == 0 { - e.e.WriteMapEmpty() - return - } - var i uint - e.mapStart(len(v)) - if e.h.Canonical { - v2 := make([]uint64, len(v)) - for k := range v { - v2[i] = k - i++ - } - slices.Sort(v2) - for i, k2 := range v2 { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeUint(k2) - e.mapElemValue() - e.e.EncodeInt(int64(v[k2])) - } - } else { - i = 0 - for k2, v2 := range v { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeUint(k2) - e.mapElemValue() - e.e.EncodeInt(int64(v2)) - i++ - } - } - e.c = 0 - e.e.WriteMapEnd() -} -func (e *encoderJsonIO) fastpathEncMapUint64Float64R(f *encFnInfo, rv reflect.Value) { - fastpathETJsonIO{}.EncMapUint64Float64V(rv2i(rv).(map[uint64]float64), e) -} -func (fastpathETJsonIO) EncMapUint64Float64V(v map[uint64]float64, e *encoderJsonIO) { - if len(v) == 0 { - e.e.WriteMapEmpty() - return - } - var i uint - e.mapStart(len(v)) - if e.h.Canonical { - v2 := make([]uint64, len(v)) - for k := range v { - v2[i] = k - i++ - } - slices.Sort(v2) - for i, k2 := range v2 { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeUint(k2) - e.mapElemValue() - e.e.EncodeFloat64(v[k2]) - } - } else { - i = 0 - for k2, v2 := range v { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeUint(k2) - e.mapElemValue() - e.e.EncodeFloat64(v2) - i++ - } - } - e.c = 0 - e.e.WriteMapEnd() -} -func (e *encoderJsonIO) fastpathEncMapUint64BoolR(f *encFnInfo, rv reflect.Value) { - fastpathETJsonIO{}.EncMapUint64BoolV(rv2i(rv).(map[uint64]bool), e) -} -func (fastpathETJsonIO) EncMapUint64BoolV(v map[uint64]bool, e *encoderJsonIO) { - if len(v) == 0 { - e.e.WriteMapEmpty() - return - } - var i uint - e.mapStart(len(v)) - if e.h.Canonical { - v2 := make([]uint64, len(v)) - for k := range v { - v2[i] = k - i++ - } - slices.Sort(v2) - for i, k2 := range v2 { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeUint(k2) - e.mapElemValue() - e.e.EncodeBool(v[k2]) - } - } else { - i = 0 - for k2, v2 := range v { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeUint(k2) - e.mapElemValue() - e.e.EncodeBool(v2) - i++ - } - } - e.c = 0 - e.e.WriteMapEnd() -} -func (e *encoderJsonIO) fastpathEncMapIntIntfR(f *encFnInfo, rv reflect.Value) { - fastpathETJsonIO{}.EncMapIntIntfV(rv2i(rv).(map[int]interface{}), e) -} -func (fastpathETJsonIO) EncMapIntIntfV(v map[int]interface{}, e *encoderJsonIO) { - if len(v) == 0 { - e.e.WriteMapEmpty() - return - } - var i uint - e.mapStart(len(v)) - if e.h.Canonical { - v2 := make([]int, len(v)) - for k := range v { - v2[i] = k - i++ - } - slices.Sort(v2) - for i, k2 := range v2 { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeInt(int64(k2)) - e.mapElemValue() - if !e.encodeBuiltin(v[k2]) { - e.encodeR(reflect.ValueOf(v[k2])) - } - } - } else { - i = 0 - for k2, v2 := range v { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeInt(int64(k2)) - e.mapElemValue() - if !e.encodeBuiltin(v2) { - e.encodeR(reflect.ValueOf(v2)) - } - i++ - } - } - e.c = 0 - e.e.WriteMapEnd() -} -func (e *encoderJsonIO) fastpathEncMapIntStringR(f *encFnInfo, rv reflect.Value) { - fastpathETJsonIO{}.EncMapIntStringV(rv2i(rv).(map[int]string), e) -} -func (fastpathETJsonIO) EncMapIntStringV(v map[int]string, e *encoderJsonIO) { - if len(v) == 0 { - e.e.WriteMapEmpty() - return - } - var i uint - e.mapStart(len(v)) - if e.h.Canonical { - v2 := make([]int, len(v)) - for k := range v { - v2[i] = k - i++ - } - slices.Sort(v2) - for i, k2 := range v2 { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeInt(int64(k2)) - e.mapElemValue() - e.e.EncodeString(v[k2]) - } - } else { - i = 0 - for k2, v2 := range v { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeInt(int64(k2)) - e.mapElemValue() - e.e.EncodeString(v2) - i++ - } - } - e.c = 0 - e.e.WriteMapEnd() -} -func (e *encoderJsonIO) fastpathEncMapIntBytesR(f *encFnInfo, rv reflect.Value) { - fastpathETJsonIO{}.EncMapIntBytesV(rv2i(rv).(map[int][]byte), e) -} -func (fastpathETJsonIO) EncMapIntBytesV(v map[int][]byte, e *encoderJsonIO) { - if len(v) == 0 { - e.e.WriteMapEmpty() - return - } - var i uint - e.mapStart(len(v)) - if e.h.Canonical { - v2 := make([]int, len(v)) - for k := range v { - v2[i] = k - i++ - } - slices.Sort(v2) - for i, k2 := range v2 { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeInt(int64(k2)) - e.mapElemValue() - e.e.EncodeBytes(v[k2]) - } - } else { - i = 0 - for k2, v2 := range v { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeInt(int64(k2)) - e.mapElemValue() - e.e.EncodeBytes(v2) - i++ - } - } - e.c = 0 - e.e.WriteMapEnd() -} -func (e *encoderJsonIO) fastpathEncMapIntUint8R(f *encFnInfo, rv reflect.Value) { - fastpathETJsonIO{}.EncMapIntUint8V(rv2i(rv).(map[int]uint8), e) -} -func (fastpathETJsonIO) EncMapIntUint8V(v map[int]uint8, e *encoderJsonIO) { - if len(v) == 0 { - e.e.WriteMapEmpty() - return - } - var i uint - e.mapStart(len(v)) - if e.h.Canonical { - v2 := make([]int, len(v)) - for k := range v { - v2[i] = k - i++ - } - slices.Sort(v2) - for i, k2 := range v2 { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeInt(int64(k2)) - e.mapElemValue() - e.e.EncodeUint(uint64(v[k2])) - } - } else { - i = 0 - for k2, v2 := range v { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeInt(int64(k2)) - e.mapElemValue() - e.e.EncodeUint(uint64(v2)) - i++ - } - } - e.c = 0 - e.e.WriteMapEnd() -} -func (e *encoderJsonIO) fastpathEncMapIntUint64R(f *encFnInfo, rv reflect.Value) { - fastpathETJsonIO{}.EncMapIntUint64V(rv2i(rv).(map[int]uint64), e) -} -func (fastpathETJsonIO) EncMapIntUint64V(v map[int]uint64, e *encoderJsonIO) { - if len(v) == 0 { - e.e.WriteMapEmpty() - return - } - var i uint - e.mapStart(len(v)) - if e.h.Canonical { - v2 := make([]int, len(v)) - for k := range v { - v2[i] = k - i++ - } - slices.Sort(v2) - for i, k2 := range v2 { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeInt(int64(k2)) - e.mapElemValue() - e.e.EncodeUint(v[k2]) - } - } else { - i = 0 - for k2, v2 := range v { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeInt(int64(k2)) - e.mapElemValue() - e.e.EncodeUint(v2) - i++ - } - } - e.c = 0 - e.e.WriteMapEnd() -} -func (e *encoderJsonIO) fastpathEncMapIntIntR(f *encFnInfo, rv reflect.Value) { - fastpathETJsonIO{}.EncMapIntIntV(rv2i(rv).(map[int]int), e) -} -func (fastpathETJsonIO) EncMapIntIntV(v map[int]int, e *encoderJsonIO) { - if len(v) == 0 { - e.e.WriteMapEmpty() - return - } - var i uint - e.mapStart(len(v)) - if e.h.Canonical { - v2 := make([]int, len(v)) - for k := range v { - v2[i] = k - i++ - } - slices.Sort(v2) - for i, k2 := range v2 { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeInt(int64(k2)) - e.mapElemValue() - e.e.EncodeInt(int64(v[k2])) - } - } else { - i = 0 - for k2, v2 := range v { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeInt(int64(k2)) - e.mapElemValue() - e.e.EncodeInt(int64(v2)) - i++ - } - } - e.c = 0 - e.e.WriteMapEnd() -} -func (e *encoderJsonIO) fastpathEncMapIntInt32R(f *encFnInfo, rv reflect.Value) { - fastpathETJsonIO{}.EncMapIntInt32V(rv2i(rv).(map[int]int32), e) -} -func (fastpathETJsonIO) EncMapIntInt32V(v map[int]int32, e *encoderJsonIO) { - if len(v) == 0 { - e.e.WriteMapEmpty() - return - } - var i uint - e.mapStart(len(v)) - if e.h.Canonical { - v2 := make([]int, len(v)) - for k := range v { - v2[i] = k - i++ - } - slices.Sort(v2) - for i, k2 := range v2 { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeInt(int64(k2)) - e.mapElemValue() - e.e.EncodeInt(int64(v[k2])) - } - } else { - i = 0 - for k2, v2 := range v { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeInt(int64(k2)) - e.mapElemValue() - e.e.EncodeInt(int64(v2)) - i++ - } - } - e.c = 0 - e.e.WriteMapEnd() -} -func (e *encoderJsonIO) fastpathEncMapIntFloat64R(f *encFnInfo, rv reflect.Value) { - fastpathETJsonIO{}.EncMapIntFloat64V(rv2i(rv).(map[int]float64), e) -} -func (fastpathETJsonIO) EncMapIntFloat64V(v map[int]float64, e *encoderJsonIO) { - if len(v) == 0 { - e.e.WriteMapEmpty() - return - } - var i uint - e.mapStart(len(v)) - if e.h.Canonical { - v2 := make([]int, len(v)) - for k := range v { - v2[i] = k - i++ - } - slices.Sort(v2) - for i, k2 := range v2 { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeInt(int64(k2)) - e.mapElemValue() - e.e.EncodeFloat64(v[k2]) - } - } else { - i = 0 - for k2, v2 := range v { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeInt(int64(k2)) - e.mapElemValue() - e.e.EncodeFloat64(v2) - i++ - } - } - e.c = 0 - e.e.WriteMapEnd() -} -func (e *encoderJsonIO) fastpathEncMapIntBoolR(f *encFnInfo, rv reflect.Value) { - fastpathETJsonIO{}.EncMapIntBoolV(rv2i(rv).(map[int]bool), e) -} -func (fastpathETJsonIO) EncMapIntBoolV(v map[int]bool, e *encoderJsonIO) { - if len(v) == 0 { - e.e.WriteMapEmpty() - return - } - var i uint - e.mapStart(len(v)) - if e.h.Canonical { - v2 := make([]int, len(v)) - for k := range v { - v2[i] = k - i++ - } - slices.Sort(v2) - for i, k2 := range v2 { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeInt(int64(k2)) - e.mapElemValue() - e.e.EncodeBool(v[k2]) - } - } else { - i = 0 - for k2, v2 := range v { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeInt(int64(k2)) - e.mapElemValue() - e.e.EncodeBool(v2) - i++ - } - } - e.c = 0 - e.e.WriteMapEnd() -} -func (e *encoderJsonIO) fastpathEncMapInt32IntfR(f *encFnInfo, rv reflect.Value) { - fastpathETJsonIO{}.EncMapInt32IntfV(rv2i(rv).(map[int32]interface{}), e) -} -func (fastpathETJsonIO) EncMapInt32IntfV(v map[int32]interface{}, e *encoderJsonIO) { - if len(v) == 0 { - e.e.WriteMapEmpty() - return - } - var i uint - e.mapStart(len(v)) - if e.h.Canonical { - v2 := make([]int32, len(v)) - for k := range v { - v2[i] = k - i++ - } - slices.Sort(v2) - for i, k2 := range v2 { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeInt(int64(k2)) - e.mapElemValue() - if !e.encodeBuiltin(v[k2]) { - e.encodeR(reflect.ValueOf(v[k2])) - } - } - } else { - i = 0 - for k2, v2 := range v { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeInt(int64(k2)) - e.mapElemValue() - if !e.encodeBuiltin(v2) { - e.encodeR(reflect.ValueOf(v2)) - } - i++ - } - } - e.c = 0 - e.e.WriteMapEnd() -} -func (e *encoderJsonIO) fastpathEncMapInt32StringR(f *encFnInfo, rv reflect.Value) { - fastpathETJsonIO{}.EncMapInt32StringV(rv2i(rv).(map[int32]string), e) -} -func (fastpathETJsonIO) EncMapInt32StringV(v map[int32]string, e *encoderJsonIO) { - if len(v) == 0 { - e.e.WriteMapEmpty() - return - } - var i uint - e.mapStart(len(v)) - if e.h.Canonical { - v2 := make([]int32, len(v)) - for k := range v { - v2[i] = k - i++ - } - slices.Sort(v2) - for i, k2 := range v2 { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeInt(int64(k2)) - e.mapElemValue() - e.e.EncodeString(v[k2]) - } - } else { - i = 0 - for k2, v2 := range v { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeInt(int64(k2)) - e.mapElemValue() - e.e.EncodeString(v2) - i++ - } - } - e.c = 0 - e.e.WriteMapEnd() -} -func (e *encoderJsonIO) fastpathEncMapInt32BytesR(f *encFnInfo, rv reflect.Value) { - fastpathETJsonIO{}.EncMapInt32BytesV(rv2i(rv).(map[int32][]byte), e) -} -func (fastpathETJsonIO) EncMapInt32BytesV(v map[int32][]byte, e *encoderJsonIO) { - if len(v) == 0 { - e.e.WriteMapEmpty() - return - } - var i uint - e.mapStart(len(v)) - if e.h.Canonical { - v2 := make([]int32, len(v)) - for k := range v { - v2[i] = k - i++ - } - slices.Sort(v2) - for i, k2 := range v2 { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeInt(int64(k2)) - e.mapElemValue() - e.e.EncodeBytes(v[k2]) - } - } else { - i = 0 - for k2, v2 := range v { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeInt(int64(k2)) - e.mapElemValue() - e.e.EncodeBytes(v2) - i++ - } - } - e.c = 0 - e.e.WriteMapEnd() -} -func (e *encoderJsonIO) fastpathEncMapInt32Uint8R(f *encFnInfo, rv reflect.Value) { - fastpathETJsonIO{}.EncMapInt32Uint8V(rv2i(rv).(map[int32]uint8), e) -} -func (fastpathETJsonIO) EncMapInt32Uint8V(v map[int32]uint8, e *encoderJsonIO) { - if len(v) == 0 { - e.e.WriteMapEmpty() - return - } - var i uint - e.mapStart(len(v)) - if e.h.Canonical { - v2 := make([]int32, len(v)) - for k := range v { - v2[i] = k - i++ - } - slices.Sort(v2) - for i, k2 := range v2 { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeInt(int64(k2)) - e.mapElemValue() - e.e.EncodeUint(uint64(v[k2])) - } - } else { - i = 0 - for k2, v2 := range v { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeInt(int64(k2)) - e.mapElemValue() - e.e.EncodeUint(uint64(v2)) - i++ - } - } - e.c = 0 - e.e.WriteMapEnd() -} -func (e *encoderJsonIO) fastpathEncMapInt32Uint64R(f *encFnInfo, rv reflect.Value) { - fastpathETJsonIO{}.EncMapInt32Uint64V(rv2i(rv).(map[int32]uint64), e) -} -func (fastpathETJsonIO) EncMapInt32Uint64V(v map[int32]uint64, e *encoderJsonIO) { - if len(v) == 0 { - e.e.WriteMapEmpty() - return - } - var i uint - e.mapStart(len(v)) - if e.h.Canonical { - v2 := make([]int32, len(v)) - for k := range v { - v2[i] = k - i++ - } - slices.Sort(v2) - for i, k2 := range v2 { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeInt(int64(k2)) - e.mapElemValue() - e.e.EncodeUint(v[k2]) - } - } else { - i = 0 - for k2, v2 := range v { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeInt(int64(k2)) - e.mapElemValue() - e.e.EncodeUint(v2) - i++ - } - } - e.c = 0 - e.e.WriteMapEnd() -} -func (e *encoderJsonIO) fastpathEncMapInt32IntR(f *encFnInfo, rv reflect.Value) { - fastpathETJsonIO{}.EncMapInt32IntV(rv2i(rv).(map[int32]int), e) -} -func (fastpathETJsonIO) EncMapInt32IntV(v map[int32]int, e *encoderJsonIO) { - if len(v) == 0 { - e.e.WriteMapEmpty() - return - } - var i uint - e.mapStart(len(v)) - if e.h.Canonical { - v2 := make([]int32, len(v)) - for k := range v { - v2[i] = k - i++ - } - slices.Sort(v2) - for i, k2 := range v2 { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeInt(int64(k2)) - e.mapElemValue() - e.e.EncodeInt(int64(v[k2])) - } - } else { - i = 0 - for k2, v2 := range v { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeInt(int64(k2)) - e.mapElemValue() - e.e.EncodeInt(int64(v2)) - i++ - } - } - e.c = 0 - e.e.WriteMapEnd() -} -func (e *encoderJsonIO) fastpathEncMapInt32Int32R(f *encFnInfo, rv reflect.Value) { - fastpathETJsonIO{}.EncMapInt32Int32V(rv2i(rv).(map[int32]int32), e) -} -func (fastpathETJsonIO) EncMapInt32Int32V(v map[int32]int32, e *encoderJsonIO) { - if len(v) == 0 { - e.e.WriteMapEmpty() - return - } - var i uint - e.mapStart(len(v)) - if e.h.Canonical { - v2 := make([]int32, len(v)) - for k := range v { - v2[i] = k - i++ - } - slices.Sort(v2) - for i, k2 := range v2 { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeInt(int64(k2)) - e.mapElemValue() - e.e.EncodeInt(int64(v[k2])) - } - } else { - i = 0 - for k2, v2 := range v { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeInt(int64(k2)) - e.mapElemValue() - e.e.EncodeInt(int64(v2)) - i++ - } - } - e.c = 0 - e.e.WriteMapEnd() -} -func (e *encoderJsonIO) fastpathEncMapInt32Float64R(f *encFnInfo, rv reflect.Value) { - fastpathETJsonIO{}.EncMapInt32Float64V(rv2i(rv).(map[int32]float64), e) -} -func (fastpathETJsonIO) EncMapInt32Float64V(v map[int32]float64, e *encoderJsonIO) { - if len(v) == 0 { - e.e.WriteMapEmpty() - return - } - var i uint - e.mapStart(len(v)) - if e.h.Canonical { - v2 := make([]int32, len(v)) - for k := range v { - v2[i] = k - i++ - } - slices.Sort(v2) - for i, k2 := range v2 { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeInt(int64(k2)) - e.mapElemValue() - e.e.EncodeFloat64(v[k2]) - } - } else { - i = 0 - for k2, v2 := range v { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeInt(int64(k2)) - e.mapElemValue() - e.e.EncodeFloat64(v2) - i++ - } - } - e.c = 0 - e.e.WriteMapEnd() -} -func (e *encoderJsonIO) fastpathEncMapInt32BoolR(f *encFnInfo, rv reflect.Value) { - fastpathETJsonIO{}.EncMapInt32BoolV(rv2i(rv).(map[int32]bool), e) -} -func (fastpathETJsonIO) EncMapInt32BoolV(v map[int32]bool, e *encoderJsonIO) { - if len(v) == 0 { - e.e.WriteMapEmpty() - return - } - var i uint - e.mapStart(len(v)) - if e.h.Canonical { - v2 := make([]int32, len(v)) - for k := range v { - v2[i] = k - i++ - } - slices.Sort(v2) - for i, k2 := range v2 { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeInt(int64(k2)) - e.mapElemValue() - e.e.EncodeBool(v[k2]) - } - } else { - i = 0 - for k2, v2 := range v { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeInt(int64(k2)) - e.mapElemValue() - e.e.EncodeBool(v2) - i++ - } - } - e.c = 0 - e.e.WriteMapEnd() -} - -func (helperDecDriverJsonIO) fastpathDecodeTypeSwitch(iv interface{}, d *decoderJsonIO) bool { - var ft fastpathDTJsonIO - var changed bool - var containerLen int - switch v := iv.(type) { - case []interface{}: - ft.DecSliceIntfN(v, d) - case *[]interface{}: - var v2 []interface{} - if v2, changed = ft.DecSliceIntfY(*v, d); changed { - *v = v2 - } - case []string: - ft.DecSliceStringN(v, d) - case *[]string: - var v2 []string - if v2, changed = ft.DecSliceStringY(*v, d); changed { - *v = v2 - } - case [][]byte: - ft.DecSliceBytesN(v, d) - case *[][]byte: - var v2 [][]byte - if v2, changed = ft.DecSliceBytesY(*v, d); changed { - *v = v2 - } - case []float32: - ft.DecSliceFloat32N(v, d) - case *[]float32: - var v2 []float32 - if v2, changed = ft.DecSliceFloat32Y(*v, d); changed { - *v = v2 - } - case []float64: - ft.DecSliceFloat64N(v, d) - case *[]float64: - var v2 []float64 - if v2, changed = ft.DecSliceFloat64Y(*v, d); changed { - *v = v2 - } - case []uint8: - ft.DecSliceUint8N(v, d) - case *[]uint8: - var v2 []uint8 - if v2, changed = ft.DecSliceUint8Y(*v, d); changed { - *v = v2 - } - case []uint64: - ft.DecSliceUint64N(v, d) - case *[]uint64: - var v2 []uint64 - if v2, changed = ft.DecSliceUint64Y(*v, d); changed { - *v = v2 - } - case []int: - ft.DecSliceIntN(v, d) - case *[]int: - var v2 []int - if v2, changed = ft.DecSliceIntY(*v, d); changed { - *v = v2 - } - case []int32: - ft.DecSliceInt32N(v, d) - case *[]int32: - var v2 []int32 - if v2, changed = ft.DecSliceInt32Y(*v, d); changed { - *v = v2 - } - case []int64: - ft.DecSliceInt64N(v, d) - case *[]int64: - var v2 []int64 - if v2, changed = ft.DecSliceInt64Y(*v, d); changed { - *v = v2 - } - case []bool: - ft.DecSliceBoolN(v, d) - case *[]bool: - var v2 []bool - if v2, changed = ft.DecSliceBoolY(*v, d); changed { - *v = v2 - } - case map[string]interface{}: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen != containerLenNil { - if containerLen != 0 { - ft.DecMapStringIntfL(v, containerLen, d) - } - d.mapEnd() - } - case *map[string]interface{}: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen == containerLenNil { - *v = nil - } else { - if *v == nil { - *v = make(map[string]interface{}, decInferLen(containerLen, d.maxInitLen(), 32)) - } - if containerLen != 0 { - ft.DecMapStringIntfL(*v, containerLen, d) - } - d.mapEnd() - } - case map[string]string: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen != containerLenNil { - if containerLen != 0 { - ft.DecMapStringStringL(v, containerLen, d) - } - d.mapEnd() - } - case *map[string]string: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen == containerLenNil { - *v = nil - } else { - if *v == nil { - *v = make(map[string]string, decInferLen(containerLen, d.maxInitLen(), 32)) - } - if containerLen != 0 { - ft.DecMapStringStringL(*v, containerLen, d) - } - d.mapEnd() - } - case map[string][]byte: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen != containerLenNil { - if containerLen != 0 { - ft.DecMapStringBytesL(v, containerLen, d) - } - d.mapEnd() - } - case *map[string][]byte: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen == containerLenNil { - *v = nil - } else { - if *v == nil { - *v = make(map[string][]byte, decInferLen(containerLen, d.maxInitLen(), 40)) - } - if containerLen != 0 { - ft.DecMapStringBytesL(*v, containerLen, d) - } - d.mapEnd() - } - case map[string]uint8: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen != containerLenNil { - if containerLen != 0 { - ft.DecMapStringUint8L(v, containerLen, d) - } - d.mapEnd() - } - case *map[string]uint8: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen == containerLenNil { - *v = nil - } else { - if *v == nil { - *v = make(map[string]uint8, decInferLen(containerLen, d.maxInitLen(), 17)) - } - if containerLen != 0 { - ft.DecMapStringUint8L(*v, containerLen, d) - } - d.mapEnd() - } - case map[string]uint64: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen != containerLenNil { - if containerLen != 0 { - ft.DecMapStringUint64L(v, containerLen, d) - } - d.mapEnd() - } - case *map[string]uint64: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen == containerLenNil { - *v = nil - } else { - if *v == nil { - *v = make(map[string]uint64, decInferLen(containerLen, d.maxInitLen(), 24)) - } - if containerLen != 0 { - ft.DecMapStringUint64L(*v, containerLen, d) - } - d.mapEnd() - } - case map[string]int: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen != containerLenNil { - if containerLen != 0 { - ft.DecMapStringIntL(v, containerLen, d) - } - d.mapEnd() - } - case *map[string]int: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen == containerLenNil { - *v = nil - } else { - if *v == nil { - *v = make(map[string]int, decInferLen(containerLen, d.maxInitLen(), 24)) - } - if containerLen != 0 { - ft.DecMapStringIntL(*v, containerLen, d) - } - d.mapEnd() - } - case map[string]int32: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen != containerLenNil { - if containerLen != 0 { - ft.DecMapStringInt32L(v, containerLen, d) - } - d.mapEnd() - } - case *map[string]int32: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen == containerLenNil { - *v = nil - } else { - if *v == nil { - *v = make(map[string]int32, decInferLen(containerLen, d.maxInitLen(), 20)) - } - if containerLen != 0 { - ft.DecMapStringInt32L(*v, containerLen, d) - } - d.mapEnd() - } - case map[string]float64: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen != containerLenNil { - if containerLen != 0 { - ft.DecMapStringFloat64L(v, containerLen, d) - } - d.mapEnd() - } - case *map[string]float64: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen == containerLenNil { - *v = nil - } else { - if *v == nil { - *v = make(map[string]float64, decInferLen(containerLen, d.maxInitLen(), 24)) - } - if containerLen != 0 { - ft.DecMapStringFloat64L(*v, containerLen, d) - } - d.mapEnd() - } - case map[string]bool: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen != containerLenNil { - if containerLen != 0 { - ft.DecMapStringBoolL(v, containerLen, d) - } - d.mapEnd() - } - case *map[string]bool: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen == containerLenNil { - *v = nil - } else { - if *v == nil { - *v = make(map[string]bool, decInferLen(containerLen, d.maxInitLen(), 17)) - } - if containerLen != 0 { - ft.DecMapStringBoolL(*v, containerLen, d) - } - d.mapEnd() - } - case map[uint8]interface{}: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen != containerLenNil { - if containerLen != 0 { - ft.DecMapUint8IntfL(v, containerLen, d) - } - d.mapEnd() - } - case *map[uint8]interface{}: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen == containerLenNil { - *v = nil - } else { - if *v == nil { - *v = make(map[uint8]interface{}, decInferLen(containerLen, d.maxInitLen(), 17)) - } - if containerLen != 0 { - ft.DecMapUint8IntfL(*v, containerLen, d) - } - d.mapEnd() - } - case map[uint8]string: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen != containerLenNil { - if containerLen != 0 { - ft.DecMapUint8StringL(v, containerLen, d) - } - d.mapEnd() - } - case *map[uint8]string: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen == containerLenNil { - *v = nil - } else { - if *v == nil { - *v = make(map[uint8]string, decInferLen(containerLen, d.maxInitLen(), 17)) - } - if containerLen != 0 { - ft.DecMapUint8StringL(*v, containerLen, d) - } - d.mapEnd() - } - case map[uint8][]byte: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen != containerLenNil { - if containerLen != 0 { - ft.DecMapUint8BytesL(v, containerLen, d) - } - d.mapEnd() - } - case *map[uint8][]byte: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen == containerLenNil { - *v = nil - } else { - if *v == nil { - *v = make(map[uint8][]byte, decInferLen(containerLen, d.maxInitLen(), 25)) - } - if containerLen != 0 { - ft.DecMapUint8BytesL(*v, containerLen, d) - } - d.mapEnd() - } - case map[uint8]uint8: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen != containerLenNil { - if containerLen != 0 { - ft.DecMapUint8Uint8L(v, containerLen, d) - } - d.mapEnd() - } - case *map[uint8]uint8: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen == containerLenNil { - *v = nil - } else { - if *v == nil { - *v = make(map[uint8]uint8, decInferLen(containerLen, d.maxInitLen(), 2)) - } - if containerLen != 0 { - ft.DecMapUint8Uint8L(*v, containerLen, d) - } - d.mapEnd() - } - case map[uint8]uint64: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen != containerLenNil { - if containerLen != 0 { - ft.DecMapUint8Uint64L(v, containerLen, d) - } - d.mapEnd() - } - case *map[uint8]uint64: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen == containerLenNil { - *v = nil - } else { - if *v == nil { - *v = make(map[uint8]uint64, decInferLen(containerLen, d.maxInitLen(), 9)) - } - if containerLen != 0 { - ft.DecMapUint8Uint64L(*v, containerLen, d) - } - d.mapEnd() - } - case map[uint8]int: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen != containerLenNil { - if containerLen != 0 { - ft.DecMapUint8IntL(v, containerLen, d) - } - d.mapEnd() - } - case *map[uint8]int: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen == containerLenNil { - *v = nil - } else { - if *v == nil { - *v = make(map[uint8]int, decInferLen(containerLen, d.maxInitLen(), 9)) - } - if containerLen != 0 { - ft.DecMapUint8IntL(*v, containerLen, d) - } - d.mapEnd() - } - case map[uint8]int32: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen != containerLenNil { - if containerLen != 0 { - ft.DecMapUint8Int32L(v, containerLen, d) - } - d.mapEnd() - } - case *map[uint8]int32: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen == containerLenNil { - *v = nil - } else { - if *v == nil { - *v = make(map[uint8]int32, decInferLen(containerLen, d.maxInitLen(), 5)) - } - if containerLen != 0 { - ft.DecMapUint8Int32L(*v, containerLen, d) - } - d.mapEnd() - } - case map[uint8]float64: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen != containerLenNil { - if containerLen != 0 { - ft.DecMapUint8Float64L(v, containerLen, d) - } - d.mapEnd() - } - case *map[uint8]float64: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen == containerLenNil { - *v = nil - } else { - if *v == nil { - *v = make(map[uint8]float64, decInferLen(containerLen, d.maxInitLen(), 9)) - } - if containerLen != 0 { - ft.DecMapUint8Float64L(*v, containerLen, d) - } - d.mapEnd() - } - case map[uint8]bool: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen != containerLenNil { - if containerLen != 0 { - ft.DecMapUint8BoolL(v, containerLen, d) - } - d.mapEnd() - } - case *map[uint8]bool: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen == containerLenNil { - *v = nil - } else { - if *v == nil { - *v = make(map[uint8]bool, decInferLen(containerLen, d.maxInitLen(), 2)) - } - if containerLen != 0 { - ft.DecMapUint8BoolL(*v, containerLen, d) - } - d.mapEnd() - } - case map[uint64]interface{}: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen != containerLenNil { - if containerLen != 0 { - ft.DecMapUint64IntfL(v, containerLen, d) - } - d.mapEnd() - } - case *map[uint64]interface{}: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen == containerLenNil { - *v = nil - } else { - if *v == nil { - *v = make(map[uint64]interface{}, decInferLen(containerLen, d.maxInitLen(), 24)) - } - if containerLen != 0 { - ft.DecMapUint64IntfL(*v, containerLen, d) - } - d.mapEnd() - } - case map[uint64]string: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen != containerLenNil { - if containerLen != 0 { - ft.DecMapUint64StringL(v, containerLen, d) - } - d.mapEnd() - } - case *map[uint64]string: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen == containerLenNil { - *v = nil - } else { - if *v == nil { - *v = make(map[uint64]string, decInferLen(containerLen, d.maxInitLen(), 24)) - } - if containerLen != 0 { - ft.DecMapUint64StringL(*v, containerLen, d) - } - d.mapEnd() - } - case map[uint64][]byte: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen != containerLenNil { - if containerLen != 0 { - ft.DecMapUint64BytesL(v, containerLen, d) - } - d.mapEnd() - } - case *map[uint64][]byte: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen == containerLenNil { - *v = nil - } else { - if *v == nil { - *v = make(map[uint64][]byte, decInferLen(containerLen, d.maxInitLen(), 32)) - } - if containerLen != 0 { - ft.DecMapUint64BytesL(*v, containerLen, d) - } - d.mapEnd() - } - case map[uint64]uint8: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen != containerLenNil { - if containerLen != 0 { - ft.DecMapUint64Uint8L(v, containerLen, d) - } - d.mapEnd() - } - case *map[uint64]uint8: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen == containerLenNil { - *v = nil - } else { - if *v == nil { - *v = make(map[uint64]uint8, decInferLen(containerLen, d.maxInitLen(), 9)) - } - if containerLen != 0 { - ft.DecMapUint64Uint8L(*v, containerLen, d) - } - d.mapEnd() - } - case map[uint64]uint64: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen != containerLenNil { - if containerLen != 0 { - ft.DecMapUint64Uint64L(v, containerLen, d) - } - d.mapEnd() - } - case *map[uint64]uint64: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen == containerLenNil { - *v = nil - } else { - if *v == nil { - *v = make(map[uint64]uint64, decInferLen(containerLen, d.maxInitLen(), 16)) - } - if containerLen != 0 { - ft.DecMapUint64Uint64L(*v, containerLen, d) - } - d.mapEnd() - } - case map[uint64]int: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen != containerLenNil { - if containerLen != 0 { - ft.DecMapUint64IntL(v, containerLen, d) - } - d.mapEnd() - } - case *map[uint64]int: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen == containerLenNil { - *v = nil - } else { - if *v == nil { - *v = make(map[uint64]int, decInferLen(containerLen, d.maxInitLen(), 16)) - } - if containerLen != 0 { - ft.DecMapUint64IntL(*v, containerLen, d) - } - d.mapEnd() - } - case map[uint64]int32: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen != containerLenNil { - if containerLen != 0 { - ft.DecMapUint64Int32L(v, containerLen, d) - } - d.mapEnd() - } - case *map[uint64]int32: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen == containerLenNil { - *v = nil - } else { - if *v == nil { - *v = make(map[uint64]int32, decInferLen(containerLen, d.maxInitLen(), 12)) - } - if containerLen != 0 { - ft.DecMapUint64Int32L(*v, containerLen, d) - } - d.mapEnd() - } - case map[uint64]float64: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen != containerLenNil { - if containerLen != 0 { - ft.DecMapUint64Float64L(v, containerLen, d) - } - d.mapEnd() - } - case *map[uint64]float64: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen == containerLenNil { - *v = nil - } else { - if *v == nil { - *v = make(map[uint64]float64, decInferLen(containerLen, d.maxInitLen(), 16)) - } - if containerLen != 0 { - ft.DecMapUint64Float64L(*v, containerLen, d) - } - d.mapEnd() - } - case map[uint64]bool: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen != containerLenNil { - if containerLen != 0 { - ft.DecMapUint64BoolL(v, containerLen, d) - } - d.mapEnd() - } - case *map[uint64]bool: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen == containerLenNil { - *v = nil - } else { - if *v == nil { - *v = make(map[uint64]bool, decInferLen(containerLen, d.maxInitLen(), 9)) - } - if containerLen != 0 { - ft.DecMapUint64BoolL(*v, containerLen, d) - } - d.mapEnd() - } - case map[int]interface{}: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen != containerLenNil { - if containerLen != 0 { - ft.DecMapIntIntfL(v, containerLen, d) - } - d.mapEnd() - } - case *map[int]interface{}: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen == containerLenNil { - *v = nil - } else { - if *v == nil { - *v = make(map[int]interface{}, decInferLen(containerLen, d.maxInitLen(), 24)) - } - if containerLen != 0 { - ft.DecMapIntIntfL(*v, containerLen, d) - } - d.mapEnd() - } - case map[int]string: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen != containerLenNil { - if containerLen != 0 { - ft.DecMapIntStringL(v, containerLen, d) - } - d.mapEnd() - } - case *map[int]string: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen == containerLenNil { - *v = nil - } else { - if *v == nil { - *v = make(map[int]string, decInferLen(containerLen, d.maxInitLen(), 24)) - } - if containerLen != 0 { - ft.DecMapIntStringL(*v, containerLen, d) - } - d.mapEnd() - } - case map[int][]byte: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen != containerLenNil { - if containerLen != 0 { - ft.DecMapIntBytesL(v, containerLen, d) - } - d.mapEnd() - } - case *map[int][]byte: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen == containerLenNil { - *v = nil - } else { - if *v == nil { - *v = make(map[int][]byte, decInferLen(containerLen, d.maxInitLen(), 32)) - } - if containerLen != 0 { - ft.DecMapIntBytesL(*v, containerLen, d) - } - d.mapEnd() - } - case map[int]uint8: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen != containerLenNil { - if containerLen != 0 { - ft.DecMapIntUint8L(v, containerLen, d) - } - d.mapEnd() - } - case *map[int]uint8: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen == containerLenNil { - *v = nil - } else { - if *v == nil { - *v = make(map[int]uint8, decInferLen(containerLen, d.maxInitLen(), 9)) - } - if containerLen != 0 { - ft.DecMapIntUint8L(*v, containerLen, d) - } - d.mapEnd() - } - case map[int]uint64: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen != containerLenNil { - if containerLen != 0 { - ft.DecMapIntUint64L(v, containerLen, d) - } - d.mapEnd() - } - case *map[int]uint64: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen == containerLenNil { - *v = nil - } else { - if *v == nil { - *v = make(map[int]uint64, decInferLen(containerLen, d.maxInitLen(), 16)) - } - if containerLen != 0 { - ft.DecMapIntUint64L(*v, containerLen, d) - } - d.mapEnd() - } - case map[int]int: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen != containerLenNil { - if containerLen != 0 { - ft.DecMapIntIntL(v, containerLen, d) - } - d.mapEnd() - } - case *map[int]int: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen == containerLenNil { - *v = nil - } else { - if *v == nil { - *v = make(map[int]int, decInferLen(containerLen, d.maxInitLen(), 16)) - } - if containerLen != 0 { - ft.DecMapIntIntL(*v, containerLen, d) - } - d.mapEnd() - } - case map[int]int32: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen != containerLenNil { - if containerLen != 0 { - ft.DecMapIntInt32L(v, containerLen, d) - } - d.mapEnd() - } - case *map[int]int32: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen == containerLenNil { - *v = nil - } else { - if *v == nil { - *v = make(map[int]int32, decInferLen(containerLen, d.maxInitLen(), 12)) - } - if containerLen != 0 { - ft.DecMapIntInt32L(*v, containerLen, d) - } - d.mapEnd() - } - case map[int]float64: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen != containerLenNil { - if containerLen != 0 { - ft.DecMapIntFloat64L(v, containerLen, d) - } - d.mapEnd() - } - case *map[int]float64: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen == containerLenNil { - *v = nil - } else { - if *v == nil { - *v = make(map[int]float64, decInferLen(containerLen, d.maxInitLen(), 16)) - } - if containerLen != 0 { - ft.DecMapIntFloat64L(*v, containerLen, d) - } - d.mapEnd() - } - case map[int]bool: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen != containerLenNil { - if containerLen != 0 { - ft.DecMapIntBoolL(v, containerLen, d) - } - d.mapEnd() - } - case *map[int]bool: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen == containerLenNil { - *v = nil - } else { - if *v == nil { - *v = make(map[int]bool, decInferLen(containerLen, d.maxInitLen(), 9)) - } - if containerLen != 0 { - ft.DecMapIntBoolL(*v, containerLen, d) - } - d.mapEnd() - } - case map[int32]interface{}: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen != containerLenNil { - if containerLen != 0 { - ft.DecMapInt32IntfL(v, containerLen, d) - } - d.mapEnd() - } - case *map[int32]interface{}: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen == containerLenNil { - *v = nil - } else { - if *v == nil { - *v = make(map[int32]interface{}, decInferLen(containerLen, d.maxInitLen(), 20)) - } - if containerLen != 0 { - ft.DecMapInt32IntfL(*v, containerLen, d) - } - d.mapEnd() - } - case map[int32]string: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen != containerLenNil { - if containerLen != 0 { - ft.DecMapInt32StringL(v, containerLen, d) - } - d.mapEnd() - } - case *map[int32]string: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen == containerLenNil { - *v = nil - } else { - if *v == nil { - *v = make(map[int32]string, decInferLen(containerLen, d.maxInitLen(), 20)) - } - if containerLen != 0 { - ft.DecMapInt32StringL(*v, containerLen, d) - } - d.mapEnd() - } - case map[int32][]byte: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen != containerLenNil { - if containerLen != 0 { - ft.DecMapInt32BytesL(v, containerLen, d) - } - d.mapEnd() - } - case *map[int32][]byte: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen == containerLenNil { - *v = nil - } else { - if *v == nil { - *v = make(map[int32][]byte, decInferLen(containerLen, d.maxInitLen(), 28)) - } - if containerLen != 0 { - ft.DecMapInt32BytesL(*v, containerLen, d) - } - d.mapEnd() - } - case map[int32]uint8: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen != containerLenNil { - if containerLen != 0 { - ft.DecMapInt32Uint8L(v, containerLen, d) - } - d.mapEnd() - } - case *map[int32]uint8: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen == containerLenNil { - *v = nil - } else { - if *v == nil { - *v = make(map[int32]uint8, decInferLen(containerLen, d.maxInitLen(), 5)) - } - if containerLen != 0 { - ft.DecMapInt32Uint8L(*v, containerLen, d) - } - d.mapEnd() - } - case map[int32]uint64: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen != containerLenNil { - if containerLen != 0 { - ft.DecMapInt32Uint64L(v, containerLen, d) - } - d.mapEnd() - } - case *map[int32]uint64: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen == containerLenNil { - *v = nil - } else { - if *v == nil { - *v = make(map[int32]uint64, decInferLen(containerLen, d.maxInitLen(), 12)) - } - if containerLen != 0 { - ft.DecMapInt32Uint64L(*v, containerLen, d) - } - d.mapEnd() - } - case map[int32]int: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen != containerLenNil { - if containerLen != 0 { - ft.DecMapInt32IntL(v, containerLen, d) - } - d.mapEnd() - } - case *map[int32]int: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen == containerLenNil { - *v = nil - } else { - if *v == nil { - *v = make(map[int32]int, decInferLen(containerLen, d.maxInitLen(), 12)) - } - if containerLen != 0 { - ft.DecMapInt32IntL(*v, containerLen, d) - } - d.mapEnd() - } - case map[int32]int32: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen != containerLenNil { - if containerLen != 0 { - ft.DecMapInt32Int32L(v, containerLen, d) - } - d.mapEnd() - } - case *map[int32]int32: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen == containerLenNil { - *v = nil - } else { - if *v == nil { - *v = make(map[int32]int32, decInferLen(containerLen, d.maxInitLen(), 8)) - } - if containerLen != 0 { - ft.DecMapInt32Int32L(*v, containerLen, d) - } - d.mapEnd() - } - case map[int32]float64: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen != containerLenNil { - if containerLen != 0 { - ft.DecMapInt32Float64L(v, containerLen, d) - } - d.mapEnd() - } - case *map[int32]float64: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen == containerLenNil { - *v = nil - } else { - if *v == nil { - *v = make(map[int32]float64, decInferLen(containerLen, d.maxInitLen(), 12)) - } - if containerLen != 0 { - ft.DecMapInt32Float64L(*v, containerLen, d) - } - d.mapEnd() - } - case map[int32]bool: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen != containerLenNil { - if containerLen != 0 { - ft.DecMapInt32BoolL(v, containerLen, d) - } - d.mapEnd() - } - case *map[int32]bool: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen == containerLenNil { - *v = nil - } else { - if *v == nil { - *v = make(map[int32]bool, decInferLen(containerLen, d.maxInitLen(), 5)) - } - if containerLen != 0 { - ft.DecMapInt32BoolL(*v, containerLen, d) - } - d.mapEnd() - } - default: - _ = v - return false - } - return true -} - -func (d *decoderJsonIO) fastpathDecSliceIntfR(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTJsonIO - switch rv.Kind() { - case reflect.Ptr: - v := rv2i(rv).(*[]interface{}) - if vv, changed := ft.DecSliceIntfY(*v, d); changed { - *v = vv - } - case reflect.Array: - var v []interface{} - rvGetSlice4Array(rv, &v) - ft.DecSliceIntfN(v, d) - default: - ft.DecSliceIntfN(rv2i(rv).([]interface{}), d) - } -} -func (fastpathDTJsonIO) DecSliceIntfY(v []interface{}, d *decoderJsonIO) (v2 []interface{}, changed bool) { - ctyp := d.d.ContainerType() - if ctyp == valueTypeNil { - return nil, v != nil - } - var containerLenS int - isArray := ctyp == valueTypeArray - if isArray { - containerLenS = d.arrayStart(d.d.ReadArrayStart()) - } else if ctyp == valueTypeMap { - containerLenS = d.mapStart(d.d.ReadMapStart()) * 2 - } else { - halt.errorStr2("decoding into a slice, expect map/array - got ", ctyp.String()) - } - hasLen := containerLenS >= 0 - var j int - fnv := func(dst []interface{}) { v, changed = dst, true } - for ; d.containerNext(j, containerLenS, hasLen); j++ { - if j == 0 { - if containerLenS == len(v) { - } else if containerLenS < 0 || containerLenS > cap(v) { - if xlen := int(decInferLen(containerLenS, d.maxInitLen(), 16)); xlen <= cap(v) { - fnv(v[:uint(xlen)]) - } else { - v2 = make([]interface{}, uint(xlen)) - copy(v2, v) - fnv(v2) - } - } else { - fnv(v[:containerLenS]) - } - } - if isArray { - d.arrayElem(j == 0) - } else if j&1 == 0 { - d.mapElemKey(j == 0) - } else { - d.mapElemValue() - } - if j >= len(v) { - fnv(append(v, nil)) - } - d.decode(&v[uint(j)]) - } - if j < len(v) { - fnv(v[:uint(j)]) - } else if j == 0 && v == nil { - fnv([]interface{}{}) - } - if isArray { - d.arrayEnd() - } else { - d.mapEnd() - } - return v, changed -} -func (fastpathDTJsonIO) DecSliceIntfN(v []interface{}, d *decoderJsonIO) { - ctyp := d.d.ContainerType() - if ctyp == valueTypeNil { - return - } - var containerLenS int - isArray := ctyp == valueTypeArray - if isArray { - containerLenS = d.arrayStart(d.d.ReadArrayStart()) - } else if ctyp == valueTypeMap { - containerLenS = d.mapStart(d.d.ReadMapStart()) * 2 - } else { - halt.errorStr2("decoding into a slice, expect map/array - got ", ctyp.String()) - } - hasLen := containerLenS >= 0 - for j := 0; d.containerNext(j, containerLenS, hasLen); j++ { - if isArray { - d.arrayElem(j == 0) - } else if j&1 == 0 { - d.mapElemKey(j == 0) - } else { - d.mapElemValue() - } - if j < len(v) { - d.decode(&v[uint(j)]) - } else { - d.arrayCannotExpand(len(v), j+1) - d.swallow() - } - } - if isArray { - d.arrayEnd() - } else { - d.mapEnd() - } -} - -func (d *decoderJsonIO) fastpathDecSliceStringR(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTJsonIO - switch rv.Kind() { - case reflect.Ptr: - v := rv2i(rv).(*[]string) - if vv, changed := ft.DecSliceStringY(*v, d); changed { - *v = vv - } - case reflect.Array: - var v []string - rvGetSlice4Array(rv, &v) - ft.DecSliceStringN(v, d) - default: - ft.DecSliceStringN(rv2i(rv).([]string), d) - } -} -func (fastpathDTJsonIO) DecSliceStringY(v []string, d *decoderJsonIO) (v2 []string, changed bool) { - ctyp := d.d.ContainerType() - if ctyp == valueTypeNil { - return nil, v != nil - } - var containerLenS int - isArray := ctyp == valueTypeArray - if isArray { - containerLenS = d.arrayStart(d.d.ReadArrayStart()) - } else if ctyp == valueTypeMap { - containerLenS = d.mapStart(d.d.ReadMapStart()) * 2 - } else { - halt.errorStr2("decoding into a slice, expect map/array - got ", ctyp.String()) - } - hasLen := containerLenS >= 0 - var j int - fnv := func(dst []string) { v, changed = dst, true } - for ; d.containerNext(j, containerLenS, hasLen); j++ { - if j == 0 { - if containerLenS == len(v) { - } else if containerLenS < 0 || containerLenS > cap(v) { - if xlen := int(decInferLen(containerLenS, d.maxInitLen(), 16)); xlen <= cap(v) { - fnv(v[:uint(xlen)]) - } else { - v2 = make([]string, uint(xlen)) - copy(v2, v) - fnv(v2) - } - } else { - fnv(v[:containerLenS]) - } - } - if isArray { - d.arrayElem(j == 0) - } else if j&1 == 0 { - d.mapElemKey(j == 0) - } else { - d.mapElemValue() - } - if j >= len(v) { - fnv(append(v, "")) - } - v[uint(j)] = d.detach2Str(d.d.DecodeStringAsBytes()) - } - if j < len(v) { - fnv(v[:uint(j)]) - } else if j == 0 && v == nil { - fnv([]string{}) - } - if isArray { - d.arrayEnd() - } else { - d.mapEnd() - } - return v, changed -} -func (fastpathDTJsonIO) DecSliceStringN(v []string, d *decoderJsonIO) { - ctyp := d.d.ContainerType() - if ctyp == valueTypeNil { - return - } - var containerLenS int - isArray := ctyp == valueTypeArray - if isArray { - containerLenS = d.arrayStart(d.d.ReadArrayStart()) - } else if ctyp == valueTypeMap { - containerLenS = d.mapStart(d.d.ReadMapStart()) * 2 - } else { - halt.errorStr2("decoding into a slice, expect map/array - got ", ctyp.String()) - } - hasLen := containerLenS >= 0 - for j := 0; d.containerNext(j, containerLenS, hasLen); j++ { - if isArray { - d.arrayElem(j == 0) - } else if j&1 == 0 { - d.mapElemKey(j == 0) - } else { - d.mapElemValue() - } - if j < len(v) { - v[uint(j)] = d.detach2Str(d.d.DecodeStringAsBytes()) - } else { - d.arrayCannotExpand(len(v), j+1) - d.swallow() - } - } - if isArray { - d.arrayEnd() - } else { - d.mapEnd() - } -} - -func (d *decoderJsonIO) fastpathDecSliceBytesR(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTJsonIO - switch rv.Kind() { - case reflect.Ptr: - v := rv2i(rv).(*[][]byte) - if vv, changed := ft.DecSliceBytesY(*v, d); changed { - *v = vv - } - case reflect.Array: - var v [][]byte - rvGetSlice4Array(rv, &v) - ft.DecSliceBytesN(v, d) - default: - ft.DecSliceBytesN(rv2i(rv).([][]byte), d) - } -} -func (fastpathDTJsonIO) DecSliceBytesY(v [][]byte, d *decoderJsonIO) (v2 [][]byte, changed bool) { - ctyp := d.d.ContainerType() - if ctyp == valueTypeNil { - return nil, v != nil - } - var containerLenS int - isArray := ctyp == valueTypeArray - if isArray { - containerLenS = d.arrayStart(d.d.ReadArrayStart()) - } else if ctyp == valueTypeMap { - containerLenS = d.mapStart(d.d.ReadMapStart()) * 2 - } else { - halt.errorStr2("decoding into a slice, expect map/array - got ", ctyp.String()) - } - hasLen := containerLenS >= 0 - var j int - fnv := func(dst [][]byte) { v, changed = dst, true } - for ; d.containerNext(j, containerLenS, hasLen); j++ { - if j == 0 { - if containerLenS == len(v) { - } else if containerLenS < 0 || containerLenS > cap(v) { - if xlen := int(decInferLen(containerLenS, d.maxInitLen(), 24)); xlen <= cap(v) { - fnv(v[:uint(xlen)]) - } else { - v2 = make([][]byte, uint(xlen)) - copy(v2, v) - fnv(v2) - } - } else { - fnv(v[:containerLenS]) - } - } - if isArray { - d.arrayElem(j == 0) - } else if j&1 == 0 { - d.mapElemKey(j == 0) - } else { - d.mapElemValue() - } - if j >= len(v) { - fnv(append(v, nil)) - } - v[uint(j)] = bytesOKdbi(d.decodeBytesInto(v[uint(j)], false)) - } - if j < len(v) { - fnv(v[:uint(j)]) - } else if j == 0 && v == nil { - fnv([][]byte{}) - } - if isArray { - d.arrayEnd() - } else { - d.mapEnd() - } - return v, changed -} -func (fastpathDTJsonIO) DecSliceBytesN(v [][]byte, d *decoderJsonIO) { - ctyp := d.d.ContainerType() - if ctyp == valueTypeNil { - return - } - var containerLenS int - isArray := ctyp == valueTypeArray - if isArray { - containerLenS = d.arrayStart(d.d.ReadArrayStart()) - } else if ctyp == valueTypeMap { - containerLenS = d.mapStart(d.d.ReadMapStart()) * 2 - } else { - halt.errorStr2("decoding into a slice, expect map/array - got ", ctyp.String()) - } - hasLen := containerLenS >= 0 - for j := 0; d.containerNext(j, containerLenS, hasLen); j++ { - if isArray { - d.arrayElem(j == 0) - } else if j&1 == 0 { - d.mapElemKey(j == 0) - } else { - d.mapElemValue() - } - if j < len(v) { - v[uint(j)] = bytesOKdbi(d.decodeBytesInto(v[uint(j)], false)) - } else { - d.arrayCannotExpand(len(v), j+1) - d.swallow() - } - } - if isArray { - d.arrayEnd() - } else { - d.mapEnd() - } -} - -func (d *decoderJsonIO) fastpathDecSliceFloat32R(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTJsonIO - switch rv.Kind() { - case reflect.Ptr: - v := rv2i(rv).(*[]float32) - if vv, changed := ft.DecSliceFloat32Y(*v, d); changed { - *v = vv - } - case reflect.Array: - var v []float32 - rvGetSlice4Array(rv, &v) - ft.DecSliceFloat32N(v, d) - default: - ft.DecSliceFloat32N(rv2i(rv).([]float32), d) - } -} -func (fastpathDTJsonIO) DecSliceFloat32Y(v []float32, d *decoderJsonIO) (v2 []float32, changed bool) { - ctyp := d.d.ContainerType() - if ctyp == valueTypeNil { - return nil, v != nil - } - var containerLenS int - isArray := ctyp == valueTypeArray - if isArray { - containerLenS = d.arrayStart(d.d.ReadArrayStart()) - } else if ctyp == valueTypeMap { - containerLenS = d.mapStart(d.d.ReadMapStart()) * 2 - } else { - halt.errorStr2("decoding into a slice, expect map/array - got ", ctyp.String()) - } - hasLen := containerLenS >= 0 - var j int - fnv := func(dst []float32) { v, changed = dst, true } - for ; d.containerNext(j, containerLenS, hasLen); j++ { - if j == 0 { - if containerLenS == len(v) { - } else if containerLenS < 0 || containerLenS > cap(v) { - if xlen := int(decInferLen(containerLenS, d.maxInitLen(), 4)); xlen <= cap(v) { - fnv(v[:uint(xlen)]) - } else { - v2 = make([]float32, uint(xlen)) - copy(v2, v) - fnv(v2) - } - } else { - fnv(v[:containerLenS]) - } - } - if isArray { - d.arrayElem(j == 0) - } else if j&1 == 0 { - d.mapElemKey(j == 0) - } else { - d.mapElemValue() - } - if j >= len(v) { - fnv(append(v, 0)) - } - v[uint(j)] = float32(d.d.DecodeFloat32()) - } - if j < len(v) { - fnv(v[:uint(j)]) - } else if j == 0 && v == nil { - fnv([]float32{}) - } - if isArray { - d.arrayEnd() - } else { - d.mapEnd() - } - return v, changed -} -func (fastpathDTJsonIO) DecSliceFloat32N(v []float32, d *decoderJsonIO) { - ctyp := d.d.ContainerType() - if ctyp == valueTypeNil { - return - } - var containerLenS int - isArray := ctyp == valueTypeArray - if isArray { - containerLenS = d.arrayStart(d.d.ReadArrayStart()) - } else if ctyp == valueTypeMap { - containerLenS = d.mapStart(d.d.ReadMapStart()) * 2 - } else { - halt.errorStr2("decoding into a slice, expect map/array - got ", ctyp.String()) - } - hasLen := containerLenS >= 0 - for j := 0; d.containerNext(j, containerLenS, hasLen); j++ { - if isArray { - d.arrayElem(j == 0) - } else if j&1 == 0 { - d.mapElemKey(j == 0) - } else { - d.mapElemValue() - } - if j < len(v) { - v[uint(j)] = float32(d.d.DecodeFloat32()) - } else { - d.arrayCannotExpand(len(v), j+1) - d.swallow() - } - } - if isArray { - d.arrayEnd() - } else { - d.mapEnd() - } -} - -func (d *decoderJsonIO) fastpathDecSliceFloat64R(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTJsonIO - switch rv.Kind() { - case reflect.Ptr: - v := rv2i(rv).(*[]float64) - if vv, changed := ft.DecSliceFloat64Y(*v, d); changed { - *v = vv - } - case reflect.Array: - var v []float64 - rvGetSlice4Array(rv, &v) - ft.DecSliceFloat64N(v, d) - default: - ft.DecSliceFloat64N(rv2i(rv).([]float64), d) - } -} -func (fastpathDTJsonIO) DecSliceFloat64Y(v []float64, d *decoderJsonIO) (v2 []float64, changed bool) { - ctyp := d.d.ContainerType() - if ctyp == valueTypeNil { - return nil, v != nil - } - var containerLenS int - isArray := ctyp == valueTypeArray - if isArray { - containerLenS = d.arrayStart(d.d.ReadArrayStart()) - } else if ctyp == valueTypeMap { - containerLenS = d.mapStart(d.d.ReadMapStart()) * 2 - } else { - halt.errorStr2("decoding into a slice, expect map/array - got ", ctyp.String()) - } - hasLen := containerLenS >= 0 - var j int - fnv := func(dst []float64) { v, changed = dst, true } - for ; d.containerNext(j, containerLenS, hasLen); j++ { - if j == 0 { - if containerLenS == len(v) { - } else if containerLenS < 0 || containerLenS > cap(v) { - if xlen := int(decInferLen(containerLenS, d.maxInitLen(), 8)); xlen <= cap(v) { - fnv(v[:uint(xlen)]) - } else { - v2 = make([]float64, uint(xlen)) - copy(v2, v) - fnv(v2) - } - } else { - fnv(v[:containerLenS]) - } - } - if isArray { - d.arrayElem(j == 0) - } else if j&1 == 0 { - d.mapElemKey(j == 0) - } else { - d.mapElemValue() - } - if j >= len(v) { - fnv(append(v, 0)) - } - v[uint(j)] = d.d.DecodeFloat64() - } - if j < len(v) { - fnv(v[:uint(j)]) - } else if j == 0 && v == nil { - fnv([]float64{}) - } - if isArray { - d.arrayEnd() - } else { - d.mapEnd() - } - return v, changed -} -func (fastpathDTJsonIO) DecSliceFloat64N(v []float64, d *decoderJsonIO) { - ctyp := d.d.ContainerType() - if ctyp == valueTypeNil { - return - } - var containerLenS int - isArray := ctyp == valueTypeArray - if isArray { - containerLenS = d.arrayStart(d.d.ReadArrayStart()) - } else if ctyp == valueTypeMap { - containerLenS = d.mapStart(d.d.ReadMapStart()) * 2 - } else { - halt.errorStr2("decoding into a slice, expect map/array - got ", ctyp.String()) - } - hasLen := containerLenS >= 0 - for j := 0; d.containerNext(j, containerLenS, hasLen); j++ { - if isArray { - d.arrayElem(j == 0) - } else if j&1 == 0 { - d.mapElemKey(j == 0) - } else { - d.mapElemValue() - } - if j < len(v) { - v[uint(j)] = d.d.DecodeFloat64() - } else { - d.arrayCannotExpand(len(v), j+1) - d.swallow() - } - } - if isArray { - d.arrayEnd() - } else { - d.mapEnd() - } -} - -func (d *decoderJsonIO) fastpathDecSliceUint8R(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTJsonIO - switch rv.Kind() { - case reflect.Ptr: - v := rv2i(rv).(*[]uint8) - if vv, changed := ft.DecSliceUint8Y(*v, d); changed { - *v = vv - } - case reflect.Array: - var v []uint8 - rvGetSlice4Array(rv, &v) - ft.DecSliceUint8N(v, d) - default: - ft.DecSliceUint8N(rv2i(rv).([]uint8), d) - } -} -func (fastpathDTJsonIO) DecSliceUint8Y(v []uint8, d *decoderJsonIO) (v2 []uint8, changed bool) { - ctyp := d.d.ContainerType() - if ctyp == valueTypeNil { - return nil, v != nil - } - if ctyp != valueTypeMap { - var dbi dBytesIntoState - v2, dbi = d.decodeBytesInto(v[:len(v):len(v)], false) - return v2, dbi != dBytesIntoParamOut - } - containerLenS := d.mapStart(d.d.ReadMapStart()) * 2 - hasLen := containerLenS >= 0 - var j int - fnv := func(dst []uint8) { v, changed = dst, true } - for ; d.containerNext(j, containerLenS, hasLen); j++ { - if j == 0 { - if containerLenS == len(v) { - } else if containerLenS < 0 || containerLenS > cap(v) { - if xlen := int(decInferLen(containerLenS, d.maxInitLen(), 1)); xlen <= cap(v) { - fnv(v[:uint(xlen)]) - } else { - v2 = make([]uint8, uint(xlen)) - copy(v2, v) - fnv(v2) - } - } else { - fnv(v[:containerLenS]) - } - } - if j&1 == 0 { - d.mapElemKey(j == 0) - } else { - d.mapElemValue() - } - if j >= len(v) { - fnv(append(v, 0)) - } - v[uint(j)] = uint8(chkOvf.UintV(d.d.DecodeUint64(), 8)) - } - if j < len(v) { - fnv(v[:uint(j)]) - } else if j == 0 && v == nil { - fnv([]uint8{}) - } - d.mapEnd() - return v, changed -} -func (fastpathDTJsonIO) DecSliceUint8N(v []uint8, d *decoderJsonIO) { - ctyp := d.d.ContainerType() - if ctyp == valueTypeNil { - return - } - if ctyp != valueTypeMap { - d.decodeBytesInto(v[:len(v):len(v)], true) - return - } - containerLenS := d.mapStart(d.d.ReadMapStart()) * 2 - hasLen := containerLenS >= 0 - for j := 0; d.containerNext(j, containerLenS, hasLen); j++ { - if j&1 == 0 { - d.mapElemKey(j == 0) - } else { - d.mapElemValue() - } - if j < len(v) { - v[uint(j)] = uint8(chkOvf.UintV(d.d.DecodeUint64(), 8)) - } else { - d.arrayCannotExpand(len(v), j+1) - d.swallow() - } - } - d.mapEnd() -} - -func (d *decoderJsonIO) fastpathDecSliceUint64R(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTJsonIO - switch rv.Kind() { - case reflect.Ptr: - v := rv2i(rv).(*[]uint64) - if vv, changed := ft.DecSliceUint64Y(*v, d); changed { - *v = vv - } - case reflect.Array: - var v []uint64 - rvGetSlice4Array(rv, &v) - ft.DecSliceUint64N(v, d) - default: - ft.DecSliceUint64N(rv2i(rv).([]uint64), d) - } -} -func (fastpathDTJsonIO) DecSliceUint64Y(v []uint64, d *decoderJsonIO) (v2 []uint64, changed bool) { - ctyp := d.d.ContainerType() - if ctyp == valueTypeNil { - return nil, v != nil - } - var containerLenS int - isArray := ctyp == valueTypeArray - if isArray { - containerLenS = d.arrayStart(d.d.ReadArrayStart()) - } else if ctyp == valueTypeMap { - containerLenS = d.mapStart(d.d.ReadMapStart()) * 2 - } else { - halt.errorStr2("decoding into a slice, expect map/array - got ", ctyp.String()) - } - hasLen := containerLenS >= 0 - var j int - fnv := func(dst []uint64) { v, changed = dst, true } - for ; d.containerNext(j, containerLenS, hasLen); j++ { - if j == 0 { - if containerLenS == len(v) { - } else if containerLenS < 0 || containerLenS > cap(v) { - if xlen := int(decInferLen(containerLenS, d.maxInitLen(), 8)); xlen <= cap(v) { - fnv(v[:uint(xlen)]) - } else { - v2 = make([]uint64, uint(xlen)) - copy(v2, v) - fnv(v2) - } - } else { - fnv(v[:containerLenS]) - } - } - if isArray { - d.arrayElem(j == 0) - } else if j&1 == 0 { - d.mapElemKey(j == 0) - } else { - d.mapElemValue() - } - if j >= len(v) { - fnv(append(v, 0)) - } - v[uint(j)] = d.d.DecodeUint64() - } - if j < len(v) { - fnv(v[:uint(j)]) - } else if j == 0 && v == nil { - fnv([]uint64{}) - } - if isArray { - d.arrayEnd() - } else { - d.mapEnd() - } - return v, changed -} -func (fastpathDTJsonIO) DecSliceUint64N(v []uint64, d *decoderJsonIO) { - ctyp := d.d.ContainerType() - if ctyp == valueTypeNil { - return - } - var containerLenS int - isArray := ctyp == valueTypeArray - if isArray { - containerLenS = d.arrayStart(d.d.ReadArrayStart()) - } else if ctyp == valueTypeMap { - containerLenS = d.mapStart(d.d.ReadMapStart()) * 2 - } else { - halt.errorStr2("decoding into a slice, expect map/array - got ", ctyp.String()) - } - hasLen := containerLenS >= 0 - for j := 0; d.containerNext(j, containerLenS, hasLen); j++ { - if isArray { - d.arrayElem(j == 0) - } else if j&1 == 0 { - d.mapElemKey(j == 0) - } else { - d.mapElemValue() - } - if j < len(v) { - v[uint(j)] = d.d.DecodeUint64() - } else { - d.arrayCannotExpand(len(v), j+1) - d.swallow() - } - } - if isArray { - d.arrayEnd() - } else { - d.mapEnd() - } -} - -func (d *decoderJsonIO) fastpathDecSliceIntR(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTJsonIO - switch rv.Kind() { - case reflect.Ptr: - v := rv2i(rv).(*[]int) - if vv, changed := ft.DecSliceIntY(*v, d); changed { - *v = vv - } - case reflect.Array: - var v []int - rvGetSlice4Array(rv, &v) - ft.DecSliceIntN(v, d) - default: - ft.DecSliceIntN(rv2i(rv).([]int), d) - } -} -func (fastpathDTJsonIO) DecSliceIntY(v []int, d *decoderJsonIO) (v2 []int, changed bool) { - ctyp := d.d.ContainerType() - if ctyp == valueTypeNil { - return nil, v != nil - } - var containerLenS int - isArray := ctyp == valueTypeArray - if isArray { - containerLenS = d.arrayStart(d.d.ReadArrayStart()) - } else if ctyp == valueTypeMap { - containerLenS = d.mapStart(d.d.ReadMapStart()) * 2 - } else { - halt.errorStr2("decoding into a slice, expect map/array - got ", ctyp.String()) - } - hasLen := containerLenS >= 0 - var j int - fnv := func(dst []int) { v, changed = dst, true } - for ; d.containerNext(j, containerLenS, hasLen); j++ { - if j == 0 { - if containerLenS == len(v) { - } else if containerLenS < 0 || containerLenS > cap(v) { - if xlen := int(decInferLen(containerLenS, d.maxInitLen(), 8)); xlen <= cap(v) { - fnv(v[:uint(xlen)]) - } else { - v2 = make([]int, uint(xlen)) - copy(v2, v) - fnv(v2) - } - } else { - fnv(v[:containerLenS]) - } - } - if isArray { - d.arrayElem(j == 0) - } else if j&1 == 0 { - d.mapElemKey(j == 0) - } else { - d.mapElemValue() - } - if j >= len(v) { - fnv(append(v, 0)) - } - v[uint(j)] = int(chkOvf.IntV(d.d.DecodeInt64(), intBitsize)) - } - if j < len(v) { - fnv(v[:uint(j)]) - } else if j == 0 && v == nil { - fnv([]int{}) - } - if isArray { - d.arrayEnd() - } else { - d.mapEnd() - } - return v, changed -} -func (fastpathDTJsonIO) DecSliceIntN(v []int, d *decoderJsonIO) { - ctyp := d.d.ContainerType() - if ctyp == valueTypeNil { - return - } - var containerLenS int - isArray := ctyp == valueTypeArray - if isArray { - containerLenS = d.arrayStart(d.d.ReadArrayStart()) - } else if ctyp == valueTypeMap { - containerLenS = d.mapStart(d.d.ReadMapStart()) * 2 - } else { - halt.errorStr2("decoding into a slice, expect map/array - got ", ctyp.String()) - } - hasLen := containerLenS >= 0 - for j := 0; d.containerNext(j, containerLenS, hasLen); j++ { - if isArray { - d.arrayElem(j == 0) - } else if j&1 == 0 { - d.mapElemKey(j == 0) - } else { - d.mapElemValue() - } - if j < len(v) { - v[uint(j)] = int(chkOvf.IntV(d.d.DecodeInt64(), intBitsize)) - } else { - d.arrayCannotExpand(len(v), j+1) - d.swallow() - } - } - if isArray { - d.arrayEnd() - } else { - d.mapEnd() - } -} - -func (d *decoderJsonIO) fastpathDecSliceInt32R(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTJsonIO - switch rv.Kind() { - case reflect.Ptr: - v := rv2i(rv).(*[]int32) - if vv, changed := ft.DecSliceInt32Y(*v, d); changed { - *v = vv - } - case reflect.Array: - var v []int32 - rvGetSlice4Array(rv, &v) - ft.DecSliceInt32N(v, d) - default: - ft.DecSliceInt32N(rv2i(rv).([]int32), d) - } -} -func (fastpathDTJsonIO) DecSliceInt32Y(v []int32, d *decoderJsonIO) (v2 []int32, changed bool) { - ctyp := d.d.ContainerType() - if ctyp == valueTypeNil { - return nil, v != nil - } - var containerLenS int - isArray := ctyp == valueTypeArray - if isArray { - containerLenS = d.arrayStart(d.d.ReadArrayStart()) - } else if ctyp == valueTypeMap { - containerLenS = d.mapStart(d.d.ReadMapStart()) * 2 - } else { - halt.errorStr2("decoding into a slice, expect map/array - got ", ctyp.String()) - } - hasLen := containerLenS >= 0 - var j int - fnv := func(dst []int32) { v, changed = dst, true } - for ; d.containerNext(j, containerLenS, hasLen); j++ { - if j == 0 { - if containerLenS == len(v) { - } else if containerLenS < 0 || containerLenS > cap(v) { - if xlen := int(decInferLen(containerLenS, d.maxInitLen(), 4)); xlen <= cap(v) { - fnv(v[:uint(xlen)]) - } else { - v2 = make([]int32, uint(xlen)) - copy(v2, v) - fnv(v2) - } - } else { - fnv(v[:containerLenS]) - } - } - if isArray { - d.arrayElem(j == 0) - } else if j&1 == 0 { - d.mapElemKey(j == 0) - } else { - d.mapElemValue() - } - if j >= len(v) { - fnv(append(v, 0)) - } - v[uint(j)] = int32(chkOvf.IntV(d.d.DecodeInt64(), 32)) - } - if j < len(v) { - fnv(v[:uint(j)]) - } else if j == 0 && v == nil { - fnv([]int32{}) - } - if isArray { - d.arrayEnd() - } else { - d.mapEnd() - } - return v, changed -} -func (fastpathDTJsonIO) DecSliceInt32N(v []int32, d *decoderJsonIO) { - ctyp := d.d.ContainerType() - if ctyp == valueTypeNil { - return - } - var containerLenS int - isArray := ctyp == valueTypeArray - if isArray { - containerLenS = d.arrayStart(d.d.ReadArrayStart()) - } else if ctyp == valueTypeMap { - containerLenS = d.mapStart(d.d.ReadMapStart()) * 2 - } else { - halt.errorStr2("decoding into a slice, expect map/array - got ", ctyp.String()) - } - hasLen := containerLenS >= 0 - for j := 0; d.containerNext(j, containerLenS, hasLen); j++ { - if isArray { - d.arrayElem(j == 0) - } else if j&1 == 0 { - d.mapElemKey(j == 0) - } else { - d.mapElemValue() - } - if j < len(v) { - v[uint(j)] = int32(chkOvf.IntV(d.d.DecodeInt64(), 32)) - } else { - d.arrayCannotExpand(len(v), j+1) - d.swallow() - } - } - if isArray { - d.arrayEnd() - } else { - d.mapEnd() - } -} - -func (d *decoderJsonIO) fastpathDecSliceInt64R(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTJsonIO - switch rv.Kind() { - case reflect.Ptr: - v := rv2i(rv).(*[]int64) - if vv, changed := ft.DecSliceInt64Y(*v, d); changed { - *v = vv - } - case reflect.Array: - var v []int64 - rvGetSlice4Array(rv, &v) - ft.DecSliceInt64N(v, d) - default: - ft.DecSliceInt64N(rv2i(rv).([]int64), d) - } -} -func (fastpathDTJsonIO) DecSliceInt64Y(v []int64, d *decoderJsonIO) (v2 []int64, changed bool) { - ctyp := d.d.ContainerType() - if ctyp == valueTypeNil { - return nil, v != nil - } - var containerLenS int - isArray := ctyp == valueTypeArray - if isArray { - containerLenS = d.arrayStart(d.d.ReadArrayStart()) - } else if ctyp == valueTypeMap { - containerLenS = d.mapStart(d.d.ReadMapStart()) * 2 - } else { - halt.errorStr2("decoding into a slice, expect map/array - got ", ctyp.String()) - } - hasLen := containerLenS >= 0 - var j int - fnv := func(dst []int64) { v, changed = dst, true } - for ; d.containerNext(j, containerLenS, hasLen); j++ { - if j == 0 { - if containerLenS == len(v) { - } else if containerLenS < 0 || containerLenS > cap(v) { - if xlen := int(decInferLen(containerLenS, d.maxInitLen(), 8)); xlen <= cap(v) { - fnv(v[:uint(xlen)]) - } else { - v2 = make([]int64, uint(xlen)) - copy(v2, v) - fnv(v2) - } - } else { - fnv(v[:containerLenS]) - } - } - if isArray { - d.arrayElem(j == 0) - } else if j&1 == 0 { - d.mapElemKey(j == 0) - } else { - d.mapElemValue() - } - if j >= len(v) { - fnv(append(v, 0)) - } - v[uint(j)] = d.d.DecodeInt64() - } - if j < len(v) { - fnv(v[:uint(j)]) - } else if j == 0 && v == nil { - fnv([]int64{}) - } - if isArray { - d.arrayEnd() - } else { - d.mapEnd() - } - return v, changed -} -func (fastpathDTJsonIO) DecSliceInt64N(v []int64, d *decoderJsonIO) { - ctyp := d.d.ContainerType() - if ctyp == valueTypeNil { - return - } - var containerLenS int - isArray := ctyp == valueTypeArray - if isArray { - containerLenS = d.arrayStart(d.d.ReadArrayStart()) - } else if ctyp == valueTypeMap { - containerLenS = d.mapStart(d.d.ReadMapStart()) * 2 - } else { - halt.errorStr2("decoding into a slice, expect map/array - got ", ctyp.String()) - } - hasLen := containerLenS >= 0 - for j := 0; d.containerNext(j, containerLenS, hasLen); j++ { - if isArray { - d.arrayElem(j == 0) - } else if j&1 == 0 { - d.mapElemKey(j == 0) - } else { - d.mapElemValue() - } - if j < len(v) { - v[uint(j)] = d.d.DecodeInt64() - } else { - d.arrayCannotExpand(len(v), j+1) - d.swallow() - } - } - if isArray { - d.arrayEnd() - } else { - d.mapEnd() - } -} - -func (d *decoderJsonIO) fastpathDecSliceBoolR(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTJsonIO - switch rv.Kind() { - case reflect.Ptr: - v := rv2i(rv).(*[]bool) - if vv, changed := ft.DecSliceBoolY(*v, d); changed { - *v = vv - } - case reflect.Array: - var v []bool - rvGetSlice4Array(rv, &v) - ft.DecSliceBoolN(v, d) - default: - ft.DecSliceBoolN(rv2i(rv).([]bool), d) - } -} -func (fastpathDTJsonIO) DecSliceBoolY(v []bool, d *decoderJsonIO) (v2 []bool, changed bool) { - ctyp := d.d.ContainerType() - if ctyp == valueTypeNil { - return nil, v != nil - } - var containerLenS int - isArray := ctyp == valueTypeArray - if isArray { - containerLenS = d.arrayStart(d.d.ReadArrayStart()) - } else if ctyp == valueTypeMap { - containerLenS = d.mapStart(d.d.ReadMapStart()) * 2 - } else { - halt.errorStr2("decoding into a slice, expect map/array - got ", ctyp.String()) - } - hasLen := containerLenS >= 0 - var j int - fnv := func(dst []bool) { v, changed = dst, true } - for ; d.containerNext(j, containerLenS, hasLen); j++ { - if j == 0 { - if containerLenS == len(v) { - } else if containerLenS < 0 || containerLenS > cap(v) { - if xlen := int(decInferLen(containerLenS, d.maxInitLen(), 1)); xlen <= cap(v) { - fnv(v[:uint(xlen)]) - } else { - v2 = make([]bool, uint(xlen)) - copy(v2, v) - fnv(v2) - } - } else { - fnv(v[:containerLenS]) - } - } - if isArray { - d.arrayElem(j == 0) - } else if j&1 == 0 { - d.mapElemKey(j == 0) - } else { - d.mapElemValue() - } - if j >= len(v) { - fnv(append(v, false)) - } - v[uint(j)] = d.d.DecodeBool() - } - if j < len(v) { - fnv(v[:uint(j)]) - } else if j == 0 && v == nil { - fnv([]bool{}) - } - if isArray { - d.arrayEnd() - } else { - d.mapEnd() - } - return v, changed -} -func (fastpathDTJsonIO) DecSliceBoolN(v []bool, d *decoderJsonIO) { - ctyp := d.d.ContainerType() - if ctyp == valueTypeNil { - return - } - var containerLenS int - isArray := ctyp == valueTypeArray - if isArray { - containerLenS = d.arrayStart(d.d.ReadArrayStart()) - } else if ctyp == valueTypeMap { - containerLenS = d.mapStart(d.d.ReadMapStart()) * 2 - } else { - halt.errorStr2("decoding into a slice, expect map/array - got ", ctyp.String()) - } - hasLen := containerLenS >= 0 - for j := 0; d.containerNext(j, containerLenS, hasLen); j++ { - if isArray { - d.arrayElem(j == 0) - } else if j&1 == 0 { - d.mapElemKey(j == 0) - } else { - d.mapElemValue() - } - if j < len(v) { - v[uint(j)] = d.d.DecodeBool() - } else { - d.arrayCannotExpand(len(v), j+1) - d.swallow() - } - } - if isArray { - d.arrayEnd() - } else { - d.mapEnd() - } -} -func (d *decoderJsonIO) fastpathDecMapStringIntfR(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTJsonIO - containerLen := d.mapStart(d.d.ReadMapStart()) - if rv.Kind() == reflect.Ptr { - vp, _ := rv2i(rv).(*map[string]interface{}) - if *vp == nil { - *vp = make(map[string]interface{}, decInferLen(containerLen, d.maxInitLen(), 32)) - } - if containerLen != 0 { - ft.DecMapStringIntfL(*vp, containerLen, d) - } - } else if containerLen != 0 { - ft.DecMapStringIntfL(rv2i(rv).(map[string]interface{}), containerLen, d) - } - d.mapEnd() -} -func (fastpathDTJsonIO) DecMapStringIntfL(v map[string]interface{}, containerLen int, d *decoderJsonIO) { - if v == nil { - halt.errorInt("cannot decode into nil map[string]interface{} given stream length: ", int64(containerLen)) - } - var mv interface{} - mapGet := !d.h.MapValueReset && !d.h.InterfaceReset - hasLen := containerLen >= 0 - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - mk := d.detach2Str(d.d.DecodeStringAsBytes()) - d.mapElemValue() - if mapGet { - mv = v[mk] - } else { - mv = nil - } - d.decode(&mv) - v[mk] = mv - } -} -func (d *decoderJsonIO) fastpathDecMapStringStringR(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTJsonIO - containerLen := d.mapStart(d.d.ReadMapStart()) - if rv.Kind() == reflect.Ptr { - vp, _ := rv2i(rv).(*map[string]string) - if *vp == nil { - *vp = make(map[string]string, decInferLen(containerLen, d.maxInitLen(), 32)) - } - if containerLen != 0 { - ft.DecMapStringStringL(*vp, containerLen, d) - } - } else if containerLen != 0 { - ft.DecMapStringStringL(rv2i(rv).(map[string]string), containerLen, d) - } - d.mapEnd() -} -func (fastpathDTJsonIO) DecMapStringStringL(v map[string]string, containerLen int, d *decoderJsonIO) { - if v == nil { - halt.errorInt("cannot decode into nil map[string]string given stream length: ", int64(containerLen)) - } - hasLen := containerLen >= 0 - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - mk := d.detach2Str(d.d.DecodeStringAsBytes()) - d.mapElemValue() - v[mk] = d.detach2Str(d.d.DecodeStringAsBytes()) - } -} -func (d *decoderJsonIO) fastpathDecMapStringBytesR(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTJsonIO - containerLen := d.mapStart(d.d.ReadMapStart()) - if rv.Kind() == reflect.Ptr { - vp, _ := rv2i(rv).(*map[string][]byte) - if *vp == nil { - *vp = make(map[string][]byte, decInferLen(containerLen, d.maxInitLen(), 40)) - } - if containerLen != 0 { - ft.DecMapStringBytesL(*vp, containerLen, d) - } - } else if containerLen != 0 { - ft.DecMapStringBytesL(rv2i(rv).(map[string][]byte), containerLen, d) - } - d.mapEnd() -} -func (fastpathDTJsonIO) DecMapStringBytesL(v map[string][]byte, containerLen int, d *decoderJsonIO) { - if v == nil { - halt.errorInt("cannot decode into nil map[string][]byte given stream length: ", int64(containerLen)) - } - var mv []byte - mapGet := !d.h.MapValueReset - hasLen := containerLen >= 0 - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - mk := d.detach2Str(d.d.DecodeStringAsBytes()) - d.mapElemValue() - if mapGet { - mv = v[mk] - } else { - mv = nil - } - v[mk], _ = d.decodeBytesInto(mv, false) - } -} -func (d *decoderJsonIO) fastpathDecMapStringUint8R(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTJsonIO - containerLen := d.mapStart(d.d.ReadMapStart()) - if rv.Kind() == reflect.Ptr { - vp, _ := rv2i(rv).(*map[string]uint8) - if *vp == nil { - *vp = make(map[string]uint8, decInferLen(containerLen, d.maxInitLen(), 17)) - } - if containerLen != 0 { - ft.DecMapStringUint8L(*vp, containerLen, d) - } - } else if containerLen != 0 { - ft.DecMapStringUint8L(rv2i(rv).(map[string]uint8), containerLen, d) - } - d.mapEnd() -} -func (fastpathDTJsonIO) DecMapStringUint8L(v map[string]uint8, containerLen int, d *decoderJsonIO) { - if v == nil { - halt.errorInt("cannot decode into nil map[string]uint8 given stream length: ", int64(containerLen)) - } - hasLen := containerLen >= 0 - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - mk := d.detach2Str(d.d.DecodeStringAsBytes()) - d.mapElemValue() - v[mk] = uint8(chkOvf.UintV(d.d.DecodeUint64(), 8)) - } -} -func (d *decoderJsonIO) fastpathDecMapStringUint64R(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTJsonIO - containerLen := d.mapStart(d.d.ReadMapStart()) - if rv.Kind() == reflect.Ptr { - vp, _ := rv2i(rv).(*map[string]uint64) - if *vp == nil { - *vp = make(map[string]uint64, decInferLen(containerLen, d.maxInitLen(), 24)) - } - if containerLen != 0 { - ft.DecMapStringUint64L(*vp, containerLen, d) - } - } else if containerLen != 0 { - ft.DecMapStringUint64L(rv2i(rv).(map[string]uint64), containerLen, d) - } - d.mapEnd() -} -func (fastpathDTJsonIO) DecMapStringUint64L(v map[string]uint64, containerLen int, d *decoderJsonIO) { - if v == nil { - halt.errorInt("cannot decode into nil map[string]uint64 given stream length: ", int64(containerLen)) - } - hasLen := containerLen >= 0 - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - mk := d.detach2Str(d.d.DecodeStringAsBytes()) - d.mapElemValue() - v[mk] = d.d.DecodeUint64() - } -} -func (d *decoderJsonIO) fastpathDecMapStringIntR(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTJsonIO - containerLen := d.mapStart(d.d.ReadMapStart()) - if rv.Kind() == reflect.Ptr { - vp, _ := rv2i(rv).(*map[string]int) - if *vp == nil { - *vp = make(map[string]int, decInferLen(containerLen, d.maxInitLen(), 24)) - } - if containerLen != 0 { - ft.DecMapStringIntL(*vp, containerLen, d) - } - } else if containerLen != 0 { - ft.DecMapStringIntL(rv2i(rv).(map[string]int), containerLen, d) - } - d.mapEnd() -} -func (fastpathDTJsonIO) DecMapStringIntL(v map[string]int, containerLen int, d *decoderJsonIO) { - if v == nil { - halt.errorInt("cannot decode into nil map[string]int given stream length: ", int64(containerLen)) - } - hasLen := containerLen >= 0 - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - mk := d.detach2Str(d.d.DecodeStringAsBytes()) - d.mapElemValue() - v[mk] = int(chkOvf.IntV(d.d.DecodeInt64(), intBitsize)) - } -} -func (d *decoderJsonIO) fastpathDecMapStringInt32R(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTJsonIO - containerLen := d.mapStart(d.d.ReadMapStart()) - if rv.Kind() == reflect.Ptr { - vp, _ := rv2i(rv).(*map[string]int32) - if *vp == nil { - *vp = make(map[string]int32, decInferLen(containerLen, d.maxInitLen(), 20)) - } - if containerLen != 0 { - ft.DecMapStringInt32L(*vp, containerLen, d) - } - } else if containerLen != 0 { - ft.DecMapStringInt32L(rv2i(rv).(map[string]int32), containerLen, d) - } - d.mapEnd() -} -func (fastpathDTJsonIO) DecMapStringInt32L(v map[string]int32, containerLen int, d *decoderJsonIO) { - if v == nil { - halt.errorInt("cannot decode into nil map[string]int32 given stream length: ", int64(containerLen)) - } - hasLen := containerLen >= 0 - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - mk := d.detach2Str(d.d.DecodeStringAsBytes()) - d.mapElemValue() - v[mk] = int32(chkOvf.IntV(d.d.DecodeInt64(), 32)) - } -} -func (d *decoderJsonIO) fastpathDecMapStringFloat64R(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTJsonIO - containerLen := d.mapStart(d.d.ReadMapStart()) - if rv.Kind() == reflect.Ptr { - vp, _ := rv2i(rv).(*map[string]float64) - if *vp == nil { - *vp = make(map[string]float64, decInferLen(containerLen, d.maxInitLen(), 24)) - } - if containerLen != 0 { - ft.DecMapStringFloat64L(*vp, containerLen, d) - } - } else if containerLen != 0 { - ft.DecMapStringFloat64L(rv2i(rv).(map[string]float64), containerLen, d) - } - d.mapEnd() -} -func (fastpathDTJsonIO) DecMapStringFloat64L(v map[string]float64, containerLen int, d *decoderJsonIO) { - if v == nil { - halt.errorInt("cannot decode into nil map[string]float64 given stream length: ", int64(containerLen)) - } - hasLen := containerLen >= 0 - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - mk := d.detach2Str(d.d.DecodeStringAsBytes()) - d.mapElemValue() - v[mk] = d.d.DecodeFloat64() - } -} -func (d *decoderJsonIO) fastpathDecMapStringBoolR(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTJsonIO - containerLen := d.mapStart(d.d.ReadMapStart()) - if rv.Kind() == reflect.Ptr { - vp, _ := rv2i(rv).(*map[string]bool) - if *vp == nil { - *vp = make(map[string]bool, decInferLen(containerLen, d.maxInitLen(), 17)) - } - if containerLen != 0 { - ft.DecMapStringBoolL(*vp, containerLen, d) - } - } else if containerLen != 0 { - ft.DecMapStringBoolL(rv2i(rv).(map[string]bool), containerLen, d) - } - d.mapEnd() -} -func (fastpathDTJsonIO) DecMapStringBoolL(v map[string]bool, containerLen int, d *decoderJsonIO) { - if v == nil { - halt.errorInt("cannot decode into nil map[string]bool given stream length: ", int64(containerLen)) - } - hasLen := containerLen >= 0 - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - mk := d.detach2Str(d.d.DecodeStringAsBytes()) - d.mapElemValue() - v[mk] = d.d.DecodeBool() - } -} -func (d *decoderJsonIO) fastpathDecMapUint8IntfR(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTJsonIO - containerLen := d.mapStart(d.d.ReadMapStart()) - if rv.Kind() == reflect.Ptr { - vp, _ := rv2i(rv).(*map[uint8]interface{}) - if *vp == nil { - *vp = make(map[uint8]interface{}, decInferLen(containerLen, d.maxInitLen(), 17)) - } - if containerLen != 0 { - ft.DecMapUint8IntfL(*vp, containerLen, d) - } - } else if containerLen != 0 { - ft.DecMapUint8IntfL(rv2i(rv).(map[uint8]interface{}), containerLen, d) - } - d.mapEnd() -} -func (fastpathDTJsonIO) DecMapUint8IntfL(v map[uint8]interface{}, containerLen int, d *decoderJsonIO) { - if v == nil { - halt.errorInt("cannot decode into nil map[uint8]interface{} given stream length: ", int64(containerLen)) - } - var mv interface{} - mapGet := !d.h.MapValueReset && !d.h.InterfaceReset - hasLen := containerLen >= 0 - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - mk := uint8(chkOvf.UintV(d.d.DecodeUint64(), 8)) - d.mapElemValue() - if mapGet { - mv = v[mk] - } else { - mv = nil - } - d.decode(&mv) - v[mk] = mv - } -} -func (d *decoderJsonIO) fastpathDecMapUint8StringR(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTJsonIO - containerLen := d.mapStart(d.d.ReadMapStart()) - if rv.Kind() == reflect.Ptr { - vp, _ := rv2i(rv).(*map[uint8]string) - if *vp == nil { - *vp = make(map[uint8]string, decInferLen(containerLen, d.maxInitLen(), 17)) - } - if containerLen != 0 { - ft.DecMapUint8StringL(*vp, containerLen, d) - } - } else if containerLen != 0 { - ft.DecMapUint8StringL(rv2i(rv).(map[uint8]string), containerLen, d) - } - d.mapEnd() -} -func (fastpathDTJsonIO) DecMapUint8StringL(v map[uint8]string, containerLen int, d *decoderJsonIO) { - if v == nil { - halt.errorInt("cannot decode into nil map[uint8]string given stream length: ", int64(containerLen)) - } - hasLen := containerLen >= 0 - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - mk := uint8(chkOvf.UintV(d.d.DecodeUint64(), 8)) - d.mapElemValue() - v[mk] = d.detach2Str(d.d.DecodeStringAsBytes()) - } -} -func (d *decoderJsonIO) fastpathDecMapUint8BytesR(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTJsonIO - containerLen := d.mapStart(d.d.ReadMapStart()) - if rv.Kind() == reflect.Ptr { - vp, _ := rv2i(rv).(*map[uint8][]byte) - if *vp == nil { - *vp = make(map[uint8][]byte, decInferLen(containerLen, d.maxInitLen(), 25)) - } - if containerLen != 0 { - ft.DecMapUint8BytesL(*vp, containerLen, d) - } - } else if containerLen != 0 { - ft.DecMapUint8BytesL(rv2i(rv).(map[uint8][]byte), containerLen, d) - } - d.mapEnd() -} -func (fastpathDTJsonIO) DecMapUint8BytesL(v map[uint8][]byte, containerLen int, d *decoderJsonIO) { - if v == nil { - halt.errorInt("cannot decode into nil map[uint8][]byte given stream length: ", int64(containerLen)) - } - var mv []byte - mapGet := !d.h.MapValueReset - hasLen := containerLen >= 0 - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - mk := uint8(chkOvf.UintV(d.d.DecodeUint64(), 8)) - d.mapElemValue() - if mapGet { - mv = v[mk] - } else { - mv = nil - } - v[mk], _ = d.decodeBytesInto(mv, false) - } -} -func (d *decoderJsonIO) fastpathDecMapUint8Uint8R(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTJsonIO - containerLen := d.mapStart(d.d.ReadMapStart()) - if rv.Kind() == reflect.Ptr { - vp, _ := rv2i(rv).(*map[uint8]uint8) - if *vp == nil { - *vp = make(map[uint8]uint8, decInferLen(containerLen, d.maxInitLen(), 2)) - } - if containerLen != 0 { - ft.DecMapUint8Uint8L(*vp, containerLen, d) - } - } else if containerLen != 0 { - ft.DecMapUint8Uint8L(rv2i(rv).(map[uint8]uint8), containerLen, d) - } - d.mapEnd() -} -func (fastpathDTJsonIO) DecMapUint8Uint8L(v map[uint8]uint8, containerLen int, d *decoderJsonIO) { - if v == nil { - halt.errorInt("cannot decode into nil map[uint8]uint8 given stream length: ", int64(containerLen)) - } - hasLen := containerLen >= 0 - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - mk := uint8(chkOvf.UintV(d.d.DecodeUint64(), 8)) - d.mapElemValue() - v[mk] = uint8(chkOvf.UintV(d.d.DecodeUint64(), 8)) - } -} -func (d *decoderJsonIO) fastpathDecMapUint8Uint64R(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTJsonIO - containerLen := d.mapStart(d.d.ReadMapStart()) - if rv.Kind() == reflect.Ptr { - vp, _ := rv2i(rv).(*map[uint8]uint64) - if *vp == nil { - *vp = make(map[uint8]uint64, decInferLen(containerLen, d.maxInitLen(), 9)) - } - if containerLen != 0 { - ft.DecMapUint8Uint64L(*vp, containerLen, d) - } - } else if containerLen != 0 { - ft.DecMapUint8Uint64L(rv2i(rv).(map[uint8]uint64), containerLen, d) - } - d.mapEnd() -} -func (fastpathDTJsonIO) DecMapUint8Uint64L(v map[uint8]uint64, containerLen int, d *decoderJsonIO) { - if v == nil { - halt.errorInt("cannot decode into nil map[uint8]uint64 given stream length: ", int64(containerLen)) - } - hasLen := containerLen >= 0 - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - mk := uint8(chkOvf.UintV(d.d.DecodeUint64(), 8)) - d.mapElemValue() - v[mk] = d.d.DecodeUint64() - } -} -func (d *decoderJsonIO) fastpathDecMapUint8IntR(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTJsonIO - containerLen := d.mapStart(d.d.ReadMapStart()) - if rv.Kind() == reflect.Ptr { - vp, _ := rv2i(rv).(*map[uint8]int) - if *vp == nil { - *vp = make(map[uint8]int, decInferLen(containerLen, d.maxInitLen(), 9)) - } - if containerLen != 0 { - ft.DecMapUint8IntL(*vp, containerLen, d) - } - } else if containerLen != 0 { - ft.DecMapUint8IntL(rv2i(rv).(map[uint8]int), containerLen, d) - } - d.mapEnd() -} -func (fastpathDTJsonIO) DecMapUint8IntL(v map[uint8]int, containerLen int, d *decoderJsonIO) { - if v == nil { - halt.errorInt("cannot decode into nil map[uint8]int given stream length: ", int64(containerLen)) - } - hasLen := containerLen >= 0 - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - mk := uint8(chkOvf.UintV(d.d.DecodeUint64(), 8)) - d.mapElemValue() - v[mk] = int(chkOvf.IntV(d.d.DecodeInt64(), intBitsize)) - } -} -func (d *decoderJsonIO) fastpathDecMapUint8Int32R(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTJsonIO - containerLen := d.mapStart(d.d.ReadMapStart()) - if rv.Kind() == reflect.Ptr { - vp, _ := rv2i(rv).(*map[uint8]int32) - if *vp == nil { - *vp = make(map[uint8]int32, decInferLen(containerLen, d.maxInitLen(), 5)) - } - if containerLen != 0 { - ft.DecMapUint8Int32L(*vp, containerLen, d) - } - } else if containerLen != 0 { - ft.DecMapUint8Int32L(rv2i(rv).(map[uint8]int32), containerLen, d) - } - d.mapEnd() -} -func (fastpathDTJsonIO) DecMapUint8Int32L(v map[uint8]int32, containerLen int, d *decoderJsonIO) { - if v == nil { - halt.errorInt("cannot decode into nil map[uint8]int32 given stream length: ", int64(containerLen)) - } - hasLen := containerLen >= 0 - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - mk := uint8(chkOvf.UintV(d.d.DecodeUint64(), 8)) - d.mapElemValue() - v[mk] = int32(chkOvf.IntV(d.d.DecodeInt64(), 32)) - } -} -func (d *decoderJsonIO) fastpathDecMapUint8Float64R(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTJsonIO - containerLen := d.mapStart(d.d.ReadMapStart()) - if rv.Kind() == reflect.Ptr { - vp, _ := rv2i(rv).(*map[uint8]float64) - if *vp == nil { - *vp = make(map[uint8]float64, decInferLen(containerLen, d.maxInitLen(), 9)) - } - if containerLen != 0 { - ft.DecMapUint8Float64L(*vp, containerLen, d) - } - } else if containerLen != 0 { - ft.DecMapUint8Float64L(rv2i(rv).(map[uint8]float64), containerLen, d) - } - d.mapEnd() -} -func (fastpathDTJsonIO) DecMapUint8Float64L(v map[uint8]float64, containerLen int, d *decoderJsonIO) { - if v == nil { - halt.errorInt("cannot decode into nil map[uint8]float64 given stream length: ", int64(containerLen)) - } - hasLen := containerLen >= 0 - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - mk := uint8(chkOvf.UintV(d.d.DecodeUint64(), 8)) - d.mapElemValue() - v[mk] = d.d.DecodeFloat64() - } -} -func (d *decoderJsonIO) fastpathDecMapUint8BoolR(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTJsonIO - containerLen := d.mapStart(d.d.ReadMapStart()) - if rv.Kind() == reflect.Ptr { - vp, _ := rv2i(rv).(*map[uint8]bool) - if *vp == nil { - *vp = make(map[uint8]bool, decInferLen(containerLen, d.maxInitLen(), 2)) - } - if containerLen != 0 { - ft.DecMapUint8BoolL(*vp, containerLen, d) - } - } else if containerLen != 0 { - ft.DecMapUint8BoolL(rv2i(rv).(map[uint8]bool), containerLen, d) - } - d.mapEnd() -} -func (fastpathDTJsonIO) DecMapUint8BoolL(v map[uint8]bool, containerLen int, d *decoderJsonIO) { - if v == nil { - halt.errorInt("cannot decode into nil map[uint8]bool given stream length: ", int64(containerLen)) - } - hasLen := containerLen >= 0 - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - mk := uint8(chkOvf.UintV(d.d.DecodeUint64(), 8)) - d.mapElemValue() - v[mk] = d.d.DecodeBool() - } -} -func (d *decoderJsonIO) fastpathDecMapUint64IntfR(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTJsonIO - containerLen := d.mapStart(d.d.ReadMapStart()) - if rv.Kind() == reflect.Ptr { - vp, _ := rv2i(rv).(*map[uint64]interface{}) - if *vp == nil { - *vp = make(map[uint64]interface{}, decInferLen(containerLen, d.maxInitLen(), 24)) - } - if containerLen != 0 { - ft.DecMapUint64IntfL(*vp, containerLen, d) - } - } else if containerLen != 0 { - ft.DecMapUint64IntfL(rv2i(rv).(map[uint64]interface{}), containerLen, d) - } - d.mapEnd() -} -func (fastpathDTJsonIO) DecMapUint64IntfL(v map[uint64]interface{}, containerLen int, d *decoderJsonIO) { - if v == nil { - halt.errorInt("cannot decode into nil map[uint64]interface{} given stream length: ", int64(containerLen)) - } - var mv interface{} - mapGet := !d.h.MapValueReset && !d.h.InterfaceReset - hasLen := containerLen >= 0 - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - mk := d.d.DecodeUint64() - d.mapElemValue() - if mapGet { - mv = v[mk] - } else { - mv = nil - } - d.decode(&mv) - v[mk] = mv - } -} -func (d *decoderJsonIO) fastpathDecMapUint64StringR(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTJsonIO - containerLen := d.mapStart(d.d.ReadMapStart()) - if rv.Kind() == reflect.Ptr { - vp, _ := rv2i(rv).(*map[uint64]string) - if *vp == nil { - *vp = make(map[uint64]string, decInferLen(containerLen, d.maxInitLen(), 24)) - } - if containerLen != 0 { - ft.DecMapUint64StringL(*vp, containerLen, d) - } - } else if containerLen != 0 { - ft.DecMapUint64StringL(rv2i(rv).(map[uint64]string), containerLen, d) - } - d.mapEnd() -} -func (fastpathDTJsonIO) DecMapUint64StringL(v map[uint64]string, containerLen int, d *decoderJsonIO) { - if v == nil { - halt.errorInt("cannot decode into nil map[uint64]string given stream length: ", int64(containerLen)) - } - hasLen := containerLen >= 0 - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - mk := d.d.DecodeUint64() - d.mapElemValue() - v[mk] = d.detach2Str(d.d.DecodeStringAsBytes()) - } -} -func (d *decoderJsonIO) fastpathDecMapUint64BytesR(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTJsonIO - containerLen := d.mapStart(d.d.ReadMapStart()) - if rv.Kind() == reflect.Ptr { - vp, _ := rv2i(rv).(*map[uint64][]byte) - if *vp == nil { - *vp = make(map[uint64][]byte, decInferLen(containerLen, d.maxInitLen(), 32)) - } - if containerLen != 0 { - ft.DecMapUint64BytesL(*vp, containerLen, d) - } - } else if containerLen != 0 { - ft.DecMapUint64BytesL(rv2i(rv).(map[uint64][]byte), containerLen, d) - } - d.mapEnd() -} -func (fastpathDTJsonIO) DecMapUint64BytesL(v map[uint64][]byte, containerLen int, d *decoderJsonIO) { - if v == nil { - halt.errorInt("cannot decode into nil map[uint64][]byte given stream length: ", int64(containerLen)) - } - var mv []byte - mapGet := !d.h.MapValueReset - hasLen := containerLen >= 0 - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - mk := d.d.DecodeUint64() - d.mapElemValue() - if mapGet { - mv = v[mk] - } else { - mv = nil - } - v[mk], _ = d.decodeBytesInto(mv, false) - } -} -func (d *decoderJsonIO) fastpathDecMapUint64Uint8R(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTJsonIO - containerLen := d.mapStart(d.d.ReadMapStart()) - if rv.Kind() == reflect.Ptr { - vp, _ := rv2i(rv).(*map[uint64]uint8) - if *vp == nil { - *vp = make(map[uint64]uint8, decInferLen(containerLen, d.maxInitLen(), 9)) - } - if containerLen != 0 { - ft.DecMapUint64Uint8L(*vp, containerLen, d) - } - } else if containerLen != 0 { - ft.DecMapUint64Uint8L(rv2i(rv).(map[uint64]uint8), containerLen, d) - } - d.mapEnd() -} -func (fastpathDTJsonIO) DecMapUint64Uint8L(v map[uint64]uint8, containerLen int, d *decoderJsonIO) { - if v == nil { - halt.errorInt("cannot decode into nil map[uint64]uint8 given stream length: ", int64(containerLen)) - } - hasLen := containerLen >= 0 - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - mk := d.d.DecodeUint64() - d.mapElemValue() - v[mk] = uint8(chkOvf.UintV(d.d.DecodeUint64(), 8)) - } -} -func (d *decoderJsonIO) fastpathDecMapUint64Uint64R(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTJsonIO - containerLen := d.mapStart(d.d.ReadMapStart()) - if rv.Kind() == reflect.Ptr { - vp, _ := rv2i(rv).(*map[uint64]uint64) - if *vp == nil { - *vp = make(map[uint64]uint64, decInferLen(containerLen, d.maxInitLen(), 16)) - } - if containerLen != 0 { - ft.DecMapUint64Uint64L(*vp, containerLen, d) - } - } else if containerLen != 0 { - ft.DecMapUint64Uint64L(rv2i(rv).(map[uint64]uint64), containerLen, d) - } - d.mapEnd() -} -func (fastpathDTJsonIO) DecMapUint64Uint64L(v map[uint64]uint64, containerLen int, d *decoderJsonIO) { - if v == nil { - halt.errorInt("cannot decode into nil map[uint64]uint64 given stream length: ", int64(containerLen)) - } - hasLen := containerLen >= 0 - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - mk := d.d.DecodeUint64() - d.mapElemValue() - v[mk] = d.d.DecodeUint64() - } -} -func (d *decoderJsonIO) fastpathDecMapUint64IntR(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTJsonIO - containerLen := d.mapStart(d.d.ReadMapStart()) - if rv.Kind() == reflect.Ptr { - vp, _ := rv2i(rv).(*map[uint64]int) - if *vp == nil { - *vp = make(map[uint64]int, decInferLen(containerLen, d.maxInitLen(), 16)) - } - if containerLen != 0 { - ft.DecMapUint64IntL(*vp, containerLen, d) - } - } else if containerLen != 0 { - ft.DecMapUint64IntL(rv2i(rv).(map[uint64]int), containerLen, d) - } - d.mapEnd() -} -func (fastpathDTJsonIO) DecMapUint64IntL(v map[uint64]int, containerLen int, d *decoderJsonIO) { - if v == nil { - halt.errorInt("cannot decode into nil map[uint64]int given stream length: ", int64(containerLen)) - } - hasLen := containerLen >= 0 - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - mk := d.d.DecodeUint64() - d.mapElemValue() - v[mk] = int(chkOvf.IntV(d.d.DecodeInt64(), intBitsize)) - } -} -func (d *decoderJsonIO) fastpathDecMapUint64Int32R(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTJsonIO - containerLen := d.mapStart(d.d.ReadMapStart()) - if rv.Kind() == reflect.Ptr { - vp, _ := rv2i(rv).(*map[uint64]int32) - if *vp == nil { - *vp = make(map[uint64]int32, decInferLen(containerLen, d.maxInitLen(), 12)) - } - if containerLen != 0 { - ft.DecMapUint64Int32L(*vp, containerLen, d) - } - } else if containerLen != 0 { - ft.DecMapUint64Int32L(rv2i(rv).(map[uint64]int32), containerLen, d) - } - d.mapEnd() -} -func (fastpathDTJsonIO) DecMapUint64Int32L(v map[uint64]int32, containerLen int, d *decoderJsonIO) { - if v == nil { - halt.errorInt("cannot decode into nil map[uint64]int32 given stream length: ", int64(containerLen)) - } - hasLen := containerLen >= 0 - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - mk := d.d.DecodeUint64() - d.mapElemValue() - v[mk] = int32(chkOvf.IntV(d.d.DecodeInt64(), 32)) - } -} -func (d *decoderJsonIO) fastpathDecMapUint64Float64R(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTJsonIO - containerLen := d.mapStart(d.d.ReadMapStart()) - if rv.Kind() == reflect.Ptr { - vp, _ := rv2i(rv).(*map[uint64]float64) - if *vp == nil { - *vp = make(map[uint64]float64, decInferLen(containerLen, d.maxInitLen(), 16)) - } - if containerLen != 0 { - ft.DecMapUint64Float64L(*vp, containerLen, d) - } - } else if containerLen != 0 { - ft.DecMapUint64Float64L(rv2i(rv).(map[uint64]float64), containerLen, d) - } - d.mapEnd() -} -func (fastpathDTJsonIO) DecMapUint64Float64L(v map[uint64]float64, containerLen int, d *decoderJsonIO) { - if v == nil { - halt.errorInt("cannot decode into nil map[uint64]float64 given stream length: ", int64(containerLen)) - } - hasLen := containerLen >= 0 - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - mk := d.d.DecodeUint64() - d.mapElemValue() - v[mk] = d.d.DecodeFloat64() - } -} -func (d *decoderJsonIO) fastpathDecMapUint64BoolR(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTJsonIO - containerLen := d.mapStart(d.d.ReadMapStart()) - if rv.Kind() == reflect.Ptr { - vp, _ := rv2i(rv).(*map[uint64]bool) - if *vp == nil { - *vp = make(map[uint64]bool, decInferLen(containerLen, d.maxInitLen(), 9)) - } - if containerLen != 0 { - ft.DecMapUint64BoolL(*vp, containerLen, d) - } - } else if containerLen != 0 { - ft.DecMapUint64BoolL(rv2i(rv).(map[uint64]bool), containerLen, d) - } - d.mapEnd() -} -func (fastpathDTJsonIO) DecMapUint64BoolL(v map[uint64]bool, containerLen int, d *decoderJsonIO) { - if v == nil { - halt.errorInt("cannot decode into nil map[uint64]bool given stream length: ", int64(containerLen)) - } - hasLen := containerLen >= 0 - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - mk := d.d.DecodeUint64() - d.mapElemValue() - v[mk] = d.d.DecodeBool() - } -} -func (d *decoderJsonIO) fastpathDecMapIntIntfR(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTJsonIO - containerLen := d.mapStart(d.d.ReadMapStart()) - if rv.Kind() == reflect.Ptr { - vp, _ := rv2i(rv).(*map[int]interface{}) - if *vp == nil { - *vp = make(map[int]interface{}, decInferLen(containerLen, d.maxInitLen(), 24)) - } - if containerLen != 0 { - ft.DecMapIntIntfL(*vp, containerLen, d) - } - } else if containerLen != 0 { - ft.DecMapIntIntfL(rv2i(rv).(map[int]interface{}), containerLen, d) - } - d.mapEnd() -} -func (fastpathDTJsonIO) DecMapIntIntfL(v map[int]interface{}, containerLen int, d *decoderJsonIO) { - if v == nil { - halt.errorInt("cannot decode into nil map[int]interface{} given stream length: ", int64(containerLen)) - } - var mv interface{} - mapGet := !d.h.MapValueReset && !d.h.InterfaceReset - hasLen := containerLen >= 0 - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - mk := int(chkOvf.IntV(d.d.DecodeInt64(), intBitsize)) - d.mapElemValue() - if mapGet { - mv = v[mk] - } else { - mv = nil - } - d.decode(&mv) - v[mk] = mv - } -} -func (d *decoderJsonIO) fastpathDecMapIntStringR(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTJsonIO - containerLen := d.mapStart(d.d.ReadMapStart()) - if rv.Kind() == reflect.Ptr { - vp, _ := rv2i(rv).(*map[int]string) - if *vp == nil { - *vp = make(map[int]string, decInferLen(containerLen, d.maxInitLen(), 24)) - } - if containerLen != 0 { - ft.DecMapIntStringL(*vp, containerLen, d) - } - } else if containerLen != 0 { - ft.DecMapIntStringL(rv2i(rv).(map[int]string), containerLen, d) - } - d.mapEnd() -} -func (fastpathDTJsonIO) DecMapIntStringL(v map[int]string, containerLen int, d *decoderJsonIO) { - if v == nil { - halt.errorInt("cannot decode into nil map[int]string given stream length: ", int64(containerLen)) - } - hasLen := containerLen >= 0 - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - mk := int(chkOvf.IntV(d.d.DecodeInt64(), intBitsize)) - d.mapElemValue() - v[mk] = d.detach2Str(d.d.DecodeStringAsBytes()) - } -} -func (d *decoderJsonIO) fastpathDecMapIntBytesR(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTJsonIO - containerLen := d.mapStart(d.d.ReadMapStart()) - if rv.Kind() == reflect.Ptr { - vp, _ := rv2i(rv).(*map[int][]byte) - if *vp == nil { - *vp = make(map[int][]byte, decInferLen(containerLen, d.maxInitLen(), 32)) - } - if containerLen != 0 { - ft.DecMapIntBytesL(*vp, containerLen, d) - } - } else if containerLen != 0 { - ft.DecMapIntBytesL(rv2i(rv).(map[int][]byte), containerLen, d) - } - d.mapEnd() -} -func (fastpathDTJsonIO) DecMapIntBytesL(v map[int][]byte, containerLen int, d *decoderJsonIO) { - if v == nil { - halt.errorInt("cannot decode into nil map[int][]byte given stream length: ", int64(containerLen)) - } - var mv []byte - mapGet := !d.h.MapValueReset - hasLen := containerLen >= 0 - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - mk := int(chkOvf.IntV(d.d.DecodeInt64(), intBitsize)) - d.mapElemValue() - if mapGet { - mv = v[mk] - } else { - mv = nil - } - v[mk], _ = d.decodeBytesInto(mv, false) - } -} -func (d *decoderJsonIO) fastpathDecMapIntUint8R(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTJsonIO - containerLen := d.mapStart(d.d.ReadMapStart()) - if rv.Kind() == reflect.Ptr { - vp, _ := rv2i(rv).(*map[int]uint8) - if *vp == nil { - *vp = make(map[int]uint8, decInferLen(containerLen, d.maxInitLen(), 9)) - } - if containerLen != 0 { - ft.DecMapIntUint8L(*vp, containerLen, d) - } - } else if containerLen != 0 { - ft.DecMapIntUint8L(rv2i(rv).(map[int]uint8), containerLen, d) - } - d.mapEnd() -} -func (fastpathDTJsonIO) DecMapIntUint8L(v map[int]uint8, containerLen int, d *decoderJsonIO) { - if v == nil { - halt.errorInt("cannot decode into nil map[int]uint8 given stream length: ", int64(containerLen)) - } - hasLen := containerLen >= 0 - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - mk := int(chkOvf.IntV(d.d.DecodeInt64(), intBitsize)) - d.mapElemValue() - v[mk] = uint8(chkOvf.UintV(d.d.DecodeUint64(), 8)) - } -} -func (d *decoderJsonIO) fastpathDecMapIntUint64R(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTJsonIO - containerLen := d.mapStart(d.d.ReadMapStart()) - if rv.Kind() == reflect.Ptr { - vp, _ := rv2i(rv).(*map[int]uint64) - if *vp == nil { - *vp = make(map[int]uint64, decInferLen(containerLen, d.maxInitLen(), 16)) - } - if containerLen != 0 { - ft.DecMapIntUint64L(*vp, containerLen, d) - } - } else if containerLen != 0 { - ft.DecMapIntUint64L(rv2i(rv).(map[int]uint64), containerLen, d) - } - d.mapEnd() -} -func (fastpathDTJsonIO) DecMapIntUint64L(v map[int]uint64, containerLen int, d *decoderJsonIO) { - if v == nil { - halt.errorInt("cannot decode into nil map[int]uint64 given stream length: ", int64(containerLen)) - } - hasLen := containerLen >= 0 - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - mk := int(chkOvf.IntV(d.d.DecodeInt64(), intBitsize)) - d.mapElemValue() - v[mk] = d.d.DecodeUint64() - } -} -func (d *decoderJsonIO) fastpathDecMapIntIntR(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTJsonIO - containerLen := d.mapStart(d.d.ReadMapStart()) - if rv.Kind() == reflect.Ptr { - vp, _ := rv2i(rv).(*map[int]int) - if *vp == nil { - *vp = make(map[int]int, decInferLen(containerLen, d.maxInitLen(), 16)) - } - if containerLen != 0 { - ft.DecMapIntIntL(*vp, containerLen, d) - } - } else if containerLen != 0 { - ft.DecMapIntIntL(rv2i(rv).(map[int]int), containerLen, d) - } - d.mapEnd() -} -func (fastpathDTJsonIO) DecMapIntIntL(v map[int]int, containerLen int, d *decoderJsonIO) { - if v == nil { - halt.errorInt("cannot decode into nil map[int]int given stream length: ", int64(containerLen)) - } - hasLen := containerLen >= 0 - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - mk := int(chkOvf.IntV(d.d.DecodeInt64(), intBitsize)) - d.mapElemValue() - v[mk] = int(chkOvf.IntV(d.d.DecodeInt64(), intBitsize)) - } -} -func (d *decoderJsonIO) fastpathDecMapIntInt32R(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTJsonIO - containerLen := d.mapStart(d.d.ReadMapStart()) - if rv.Kind() == reflect.Ptr { - vp, _ := rv2i(rv).(*map[int]int32) - if *vp == nil { - *vp = make(map[int]int32, decInferLen(containerLen, d.maxInitLen(), 12)) - } - if containerLen != 0 { - ft.DecMapIntInt32L(*vp, containerLen, d) - } - } else if containerLen != 0 { - ft.DecMapIntInt32L(rv2i(rv).(map[int]int32), containerLen, d) - } - d.mapEnd() -} -func (fastpathDTJsonIO) DecMapIntInt32L(v map[int]int32, containerLen int, d *decoderJsonIO) { - if v == nil { - halt.errorInt("cannot decode into nil map[int]int32 given stream length: ", int64(containerLen)) - } - hasLen := containerLen >= 0 - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - mk := int(chkOvf.IntV(d.d.DecodeInt64(), intBitsize)) - d.mapElemValue() - v[mk] = int32(chkOvf.IntV(d.d.DecodeInt64(), 32)) - } -} -func (d *decoderJsonIO) fastpathDecMapIntFloat64R(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTJsonIO - containerLen := d.mapStart(d.d.ReadMapStart()) - if rv.Kind() == reflect.Ptr { - vp, _ := rv2i(rv).(*map[int]float64) - if *vp == nil { - *vp = make(map[int]float64, decInferLen(containerLen, d.maxInitLen(), 16)) - } - if containerLen != 0 { - ft.DecMapIntFloat64L(*vp, containerLen, d) - } - } else if containerLen != 0 { - ft.DecMapIntFloat64L(rv2i(rv).(map[int]float64), containerLen, d) - } - d.mapEnd() -} -func (fastpathDTJsonIO) DecMapIntFloat64L(v map[int]float64, containerLen int, d *decoderJsonIO) { - if v == nil { - halt.errorInt("cannot decode into nil map[int]float64 given stream length: ", int64(containerLen)) - } - hasLen := containerLen >= 0 - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - mk := int(chkOvf.IntV(d.d.DecodeInt64(), intBitsize)) - d.mapElemValue() - v[mk] = d.d.DecodeFloat64() - } -} -func (d *decoderJsonIO) fastpathDecMapIntBoolR(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTJsonIO - containerLen := d.mapStart(d.d.ReadMapStart()) - if rv.Kind() == reflect.Ptr { - vp, _ := rv2i(rv).(*map[int]bool) - if *vp == nil { - *vp = make(map[int]bool, decInferLen(containerLen, d.maxInitLen(), 9)) - } - if containerLen != 0 { - ft.DecMapIntBoolL(*vp, containerLen, d) - } - } else if containerLen != 0 { - ft.DecMapIntBoolL(rv2i(rv).(map[int]bool), containerLen, d) - } - d.mapEnd() -} -func (fastpathDTJsonIO) DecMapIntBoolL(v map[int]bool, containerLen int, d *decoderJsonIO) { - if v == nil { - halt.errorInt("cannot decode into nil map[int]bool given stream length: ", int64(containerLen)) - } - hasLen := containerLen >= 0 - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - mk := int(chkOvf.IntV(d.d.DecodeInt64(), intBitsize)) - d.mapElemValue() - v[mk] = d.d.DecodeBool() - } -} -func (d *decoderJsonIO) fastpathDecMapInt32IntfR(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTJsonIO - containerLen := d.mapStart(d.d.ReadMapStart()) - if rv.Kind() == reflect.Ptr { - vp, _ := rv2i(rv).(*map[int32]interface{}) - if *vp == nil { - *vp = make(map[int32]interface{}, decInferLen(containerLen, d.maxInitLen(), 20)) - } - if containerLen != 0 { - ft.DecMapInt32IntfL(*vp, containerLen, d) - } - } else if containerLen != 0 { - ft.DecMapInt32IntfL(rv2i(rv).(map[int32]interface{}), containerLen, d) - } - d.mapEnd() -} -func (fastpathDTJsonIO) DecMapInt32IntfL(v map[int32]interface{}, containerLen int, d *decoderJsonIO) { - if v == nil { - halt.errorInt("cannot decode into nil map[int32]interface{} given stream length: ", int64(containerLen)) - } - var mv interface{} - mapGet := !d.h.MapValueReset && !d.h.InterfaceReset - hasLen := containerLen >= 0 - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - mk := int32(chkOvf.IntV(d.d.DecodeInt64(), 32)) - d.mapElemValue() - if mapGet { - mv = v[mk] - } else { - mv = nil - } - d.decode(&mv) - v[mk] = mv - } -} -func (d *decoderJsonIO) fastpathDecMapInt32StringR(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTJsonIO - containerLen := d.mapStart(d.d.ReadMapStart()) - if rv.Kind() == reflect.Ptr { - vp, _ := rv2i(rv).(*map[int32]string) - if *vp == nil { - *vp = make(map[int32]string, decInferLen(containerLen, d.maxInitLen(), 20)) - } - if containerLen != 0 { - ft.DecMapInt32StringL(*vp, containerLen, d) - } - } else if containerLen != 0 { - ft.DecMapInt32StringL(rv2i(rv).(map[int32]string), containerLen, d) - } - d.mapEnd() -} -func (fastpathDTJsonIO) DecMapInt32StringL(v map[int32]string, containerLen int, d *decoderJsonIO) { - if v == nil { - halt.errorInt("cannot decode into nil map[int32]string given stream length: ", int64(containerLen)) - } - hasLen := containerLen >= 0 - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - mk := int32(chkOvf.IntV(d.d.DecodeInt64(), 32)) - d.mapElemValue() - v[mk] = d.detach2Str(d.d.DecodeStringAsBytes()) - } -} -func (d *decoderJsonIO) fastpathDecMapInt32BytesR(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTJsonIO - containerLen := d.mapStart(d.d.ReadMapStart()) - if rv.Kind() == reflect.Ptr { - vp, _ := rv2i(rv).(*map[int32][]byte) - if *vp == nil { - *vp = make(map[int32][]byte, decInferLen(containerLen, d.maxInitLen(), 28)) - } - if containerLen != 0 { - ft.DecMapInt32BytesL(*vp, containerLen, d) - } - } else if containerLen != 0 { - ft.DecMapInt32BytesL(rv2i(rv).(map[int32][]byte), containerLen, d) - } - d.mapEnd() -} -func (fastpathDTJsonIO) DecMapInt32BytesL(v map[int32][]byte, containerLen int, d *decoderJsonIO) { - if v == nil { - halt.errorInt("cannot decode into nil map[int32][]byte given stream length: ", int64(containerLen)) - } - var mv []byte - mapGet := !d.h.MapValueReset - hasLen := containerLen >= 0 - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - mk := int32(chkOvf.IntV(d.d.DecodeInt64(), 32)) - d.mapElemValue() - if mapGet { - mv = v[mk] - } else { - mv = nil - } - v[mk], _ = d.decodeBytesInto(mv, false) - } -} -func (d *decoderJsonIO) fastpathDecMapInt32Uint8R(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTJsonIO - containerLen := d.mapStart(d.d.ReadMapStart()) - if rv.Kind() == reflect.Ptr { - vp, _ := rv2i(rv).(*map[int32]uint8) - if *vp == nil { - *vp = make(map[int32]uint8, decInferLen(containerLen, d.maxInitLen(), 5)) - } - if containerLen != 0 { - ft.DecMapInt32Uint8L(*vp, containerLen, d) - } - } else if containerLen != 0 { - ft.DecMapInt32Uint8L(rv2i(rv).(map[int32]uint8), containerLen, d) - } - d.mapEnd() -} -func (fastpathDTJsonIO) DecMapInt32Uint8L(v map[int32]uint8, containerLen int, d *decoderJsonIO) { - if v == nil { - halt.errorInt("cannot decode into nil map[int32]uint8 given stream length: ", int64(containerLen)) - } - hasLen := containerLen >= 0 - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - mk := int32(chkOvf.IntV(d.d.DecodeInt64(), 32)) - d.mapElemValue() - v[mk] = uint8(chkOvf.UintV(d.d.DecodeUint64(), 8)) - } -} -func (d *decoderJsonIO) fastpathDecMapInt32Uint64R(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTJsonIO - containerLen := d.mapStart(d.d.ReadMapStart()) - if rv.Kind() == reflect.Ptr { - vp, _ := rv2i(rv).(*map[int32]uint64) - if *vp == nil { - *vp = make(map[int32]uint64, decInferLen(containerLen, d.maxInitLen(), 12)) - } - if containerLen != 0 { - ft.DecMapInt32Uint64L(*vp, containerLen, d) - } - } else if containerLen != 0 { - ft.DecMapInt32Uint64L(rv2i(rv).(map[int32]uint64), containerLen, d) - } - d.mapEnd() -} -func (fastpathDTJsonIO) DecMapInt32Uint64L(v map[int32]uint64, containerLen int, d *decoderJsonIO) { - if v == nil { - halt.errorInt("cannot decode into nil map[int32]uint64 given stream length: ", int64(containerLen)) - } - hasLen := containerLen >= 0 - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - mk := int32(chkOvf.IntV(d.d.DecodeInt64(), 32)) - d.mapElemValue() - v[mk] = d.d.DecodeUint64() - } -} -func (d *decoderJsonIO) fastpathDecMapInt32IntR(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTJsonIO - containerLen := d.mapStart(d.d.ReadMapStart()) - if rv.Kind() == reflect.Ptr { - vp, _ := rv2i(rv).(*map[int32]int) - if *vp == nil { - *vp = make(map[int32]int, decInferLen(containerLen, d.maxInitLen(), 12)) - } - if containerLen != 0 { - ft.DecMapInt32IntL(*vp, containerLen, d) - } - } else if containerLen != 0 { - ft.DecMapInt32IntL(rv2i(rv).(map[int32]int), containerLen, d) - } - d.mapEnd() -} -func (fastpathDTJsonIO) DecMapInt32IntL(v map[int32]int, containerLen int, d *decoderJsonIO) { - if v == nil { - halt.errorInt("cannot decode into nil map[int32]int given stream length: ", int64(containerLen)) - } - hasLen := containerLen >= 0 - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - mk := int32(chkOvf.IntV(d.d.DecodeInt64(), 32)) - d.mapElemValue() - v[mk] = int(chkOvf.IntV(d.d.DecodeInt64(), intBitsize)) - } -} -func (d *decoderJsonIO) fastpathDecMapInt32Int32R(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTJsonIO - containerLen := d.mapStart(d.d.ReadMapStart()) - if rv.Kind() == reflect.Ptr { - vp, _ := rv2i(rv).(*map[int32]int32) - if *vp == nil { - *vp = make(map[int32]int32, decInferLen(containerLen, d.maxInitLen(), 8)) - } - if containerLen != 0 { - ft.DecMapInt32Int32L(*vp, containerLen, d) - } - } else if containerLen != 0 { - ft.DecMapInt32Int32L(rv2i(rv).(map[int32]int32), containerLen, d) - } - d.mapEnd() -} -func (fastpathDTJsonIO) DecMapInt32Int32L(v map[int32]int32, containerLen int, d *decoderJsonIO) { - if v == nil { - halt.errorInt("cannot decode into nil map[int32]int32 given stream length: ", int64(containerLen)) - } - hasLen := containerLen >= 0 - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - mk := int32(chkOvf.IntV(d.d.DecodeInt64(), 32)) - d.mapElemValue() - v[mk] = int32(chkOvf.IntV(d.d.DecodeInt64(), 32)) - } -} -func (d *decoderJsonIO) fastpathDecMapInt32Float64R(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTJsonIO - containerLen := d.mapStart(d.d.ReadMapStart()) - if rv.Kind() == reflect.Ptr { - vp, _ := rv2i(rv).(*map[int32]float64) - if *vp == nil { - *vp = make(map[int32]float64, decInferLen(containerLen, d.maxInitLen(), 12)) - } - if containerLen != 0 { - ft.DecMapInt32Float64L(*vp, containerLen, d) - } - } else if containerLen != 0 { - ft.DecMapInt32Float64L(rv2i(rv).(map[int32]float64), containerLen, d) - } - d.mapEnd() -} -func (fastpathDTJsonIO) DecMapInt32Float64L(v map[int32]float64, containerLen int, d *decoderJsonIO) { - if v == nil { - halt.errorInt("cannot decode into nil map[int32]float64 given stream length: ", int64(containerLen)) - } - hasLen := containerLen >= 0 - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - mk := int32(chkOvf.IntV(d.d.DecodeInt64(), 32)) - d.mapElemValue() - v[mk] = d.d.DecodeFloat64() - } -} -func (d *decoderJsonIO) fastpathDecMapInt32BoolR(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTJsonIO - containerLen := d.mapStart(d.d.ReadMapStart()) - if rv.Kind() == reflect.Ptr { - vp, _ := rv2i(rv).(*map[int32]bool) - if *vp == nil { - *vp = make(map[int32]bool, decInferLen(containerLen, d.maxInitLen(), 5)) - } - if containerLen != 0 { - ft.DecMapInt32BoolL(*vp, containerLen, d) - } - } else if containerLen != 0 { - ft.DecMapInt32BoolL(rv2i(rv).(map[int32]bool), containerLen, d) - } - d.mapEnd() -} -func (fastpathDTJsonIO) DecMapInt32BoolL(v map[int32]bool, containerLen int, d *decoderJsonIO) { - if v == nil { - halt.errorInt("cannot decode into nil map[int32]bool given stream length: ", int64(containerLen)) - } - hasLen := containerLen >= 0 - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - mk := int32(chkOvf.IntV(d.d.DecodeInt64(), 32)) - d.mapElemValue() - v[mk] = d.d.DecodeBool() - } -} diff --git a/vendor/github.com/ugorji/go/codec/json.go b/vendor/github.com/ugorji/go/codec/json.go deleted file mode 100644 index ba0e55005..000000000 --- a/vendor/github.com/ugorji/go/codec/json.go +++ /dev/null @@ -1,1225 +0,0 @@ -//go:build notmono || codec.notmono - -// Copyright (c) 2012-2020 Ugorji Nwoke. All rights reserved. -// Use of this source code is governed by a MIT license found in the LICENSE file. - -package codec - -// By default, this json support uses base64 encoding for bytes, because you cannot -// store and read any arbitrary string in json (only unicode). -// However, the user can configre how to encode/decode bytes. -// -// This library specifically supports UTF-8 for encoding and decoding only. -// -// Note that the library will happily encode/decode things which are not valid -// json e.g. a map[int64]string. We do it for consistency. With valid json, -// we will encode and decode appropriately. -// Users can specify their map type if necessary to force it. -// -// We cannot use strconv.(Q|Unq)uote because json quotes/unquotes differently. - -import ( - "encoding/base64" - "io" - "math" - "reflect" - "strconv" - "time" - "unicode" - "unicode/utf16" - "unicode/utf8" -) - -type jsonEncDriver[T encWriter] struct { - noBuiltInTypes - h *JsonHandle - e *encoderBase - s *bitset256 // safe set for characters (taking h.HTMLAsIs into consideration) - - w T - // se interfaceExtWrapper - - enc encoderI - - timeFmtLayout string - byteFmter jsonBytesFmter - // ---- cpu cache line boundary??? - - // bytes2Arr bool - // time2Num bool - timeFmt jsonTimeFmt - bytesFmt jsonBytesFmt - - di int8 // indent per: if negative, use tabs - d bool // indenting? - dl uint16 // indent level - - ks bool // map key as string - is byte // integer as string - - typical bool - - rawext bool // rawext configured on the handle - - // buf *[]byte // used mostly for encoding []byte - - // scratch buffer for: encode time, numbers, etc - // - // RFC3339Nano uses 35 chars: 2006-01-02T15:04:05.999999999Z07:00 - // MaxUint64 uses 20 chars: 18446744073709551615 - // floats are encoded using: f/e fmt, and -1 precision, or 1 if no fractions. - // This means we are limited by the number of characters for the - // mantissa (up to 17), exponent (up to 3), signs (up to 3), dot (up to 1), E (up to 1) - // for a total of 24 characters. - // -xxx.yyyyyyyyyyyye-zzz - // Consequently, 35 characters should be sufficient for encoding time, integers or floats. - // We use up all the remaining bytes to make this use full cache lines. - b [48]byte -} - -func (e *jsonEncDriver[T]) writeIndent() { - e.w.writen1('\n') - x := int(e.di) * int(e.dl) - if e.di < 0 { - x = -x - for x > len(jsonTabs) { - e.w.writeb(jsonTabs[:]) - x -= len(jsonTabs) - } - e.w.writeb(jsonTabs[:x]) - } else { - for x > len(jsonSpaces) { - e.w.writeb(jsonSpaces[:]) - x -= len(jsonSpaces) - } - e.w.writeb(jsonSpaces[:x]) - } -} - -func (e *jsonEncDriver[T]) WriteArrayElem(firstTime bool) { - if !firstTime { - e.w.writen1(',') - } - if e.d { - e.writeIndent() - } -} - -func (e *jsonEncDriver[T]) WriteMapElemKey(firstTime bool) { - if !firstTime { - e.w.writen1(',') - } - if e.d { - e.writeIndent() - } -} - -func (e *jsonEncDriver[T]) WriteMapElemValue() { - if e.d { - e.w.writen2(':', ' ') - } else { - e.w.writen1(':') - } -} - -func (e *jsonEncDriver[T]) EncodeNil() { - // We always encode nil as just null (never in quotes) - // so we can easily decode if a nil in the json stream ie if initial token is n. - - // e.w.writestr(jsonLits[jsonLitN : jsonLitN+4]) - e.w.writeb(jsonNull) -} - -func (e *jsonEncDriver[T]) encodeIntAsUint(v int64, quotes bool) { - neg := v < 0 - if neg { - v = -v - } - e.encodeUint(neg, quotes, uint64(v)) -} - -func (e *jsonEncDriver[T]) EncodeTime(t time.Time) { - // Do NOT use MarshalJSON, as it allocates internally. - // instead, we call AppendFormat directly, using our scratch buffer (e.b) - - if t.IsZero() { - e.EncodeNil() - return - } - switch e.timeFmt { - case jsonTimeFmtStringLayout: - e.b[0] = '"' - b := t.AppendFormat(e.b[1:1], e.timeFmtLayout) - e.b[len(b)+1] = '"' - e.w.writeb(e.b[:len(b)+2]) - case jsonTimeFmtUnix: - e.encodeIntAsUint(t.Unix(), false) - case jsonTimeFmtUnixMilli: - e.encodeIntAsUint(t.UnixMilli(), false) - case jsonTimeFmtUnixMicro: - e.encodeIntAsUint(t.UnixMicro(), false) - case jsonTimeFmtUnixNano: - e.encodeIntAsUint(t.UnixNano(), false) - } -} - -func (e *jsonEncDriver[T]) EncodeExt(rv interface{}, basetype reflect.Type, xtag uint64, ext Ext) { - if ext == SelfExt { - e.enc.encodeAs(rv, basetype, false) - } else if v := ext.ConvertExt(rv); v == nil { - e.writeNilBytes() - } else { - e.enc.encodeI(v) - } -} - -func (e *jsonEncDriver[T]) EncodeRawExt(re *RawExt) { - if re.Data != nil { - e.w.writeb(re.Data) - } else if re.Value != nil { - e.enc.encodeI(re.Value) - } else { - e.EncodeNil() - } -} - -func (e *jsonEncDriver[T]) EncodeBool(b bool) { - e.w.writestr(jsonEncBoolStrs[bool2int(e.ks && e.e.c == containerMapKey)%2][bool2int(b)%2]) -} - -func (e *jsonEncDriver[T]) encodeFloat(f float64, bitsize, fmt byte, prec int8) { - var blen uint - if e.ks && e.e.c == containerMapKey { - blen = 2 + uint(len(strconv.AppendFloat(e.b[1:1], f, fmt, int(prec), int(bitsize)))) - // _ = e.b[:blen] - e.b[0] = '"' - e.b[blen-1] = '"' - e.w.writeb(e.b[:blen]) - } else { - e.w.writeb(strconv.AppendFloat(e.b[:0], f, fmt, int(prec), int(bitsize))) - } -} - -func (e *jsonEncDriver[T]) EncodeFloat64(f float64) { - if math.IsNaN(f) || math.IsInf(f, 0) { - e.EncodeNil() - return - } - fmt, prec := jsonFloatStrconvFmtPrec64(f) - e.encodeFloat(f, 64, fmt, prec) -} - -func (e *jsonEncDriver[T]) EncodeFloat32(f float32) { - if math.IsNaN(float64(f)) || math.IsInf(float64(f), 0) { - e.EncodeNil() - return - } - fmt, prec := jsonFloatStrconvFmtPrec32(f) - e.encodeFloat(float64(f), 32, fmt, prec) -} - -func (e *jsonEncDriver[T]) encodeUint(neg bool, quotes bool, u uint64) { - e.w.writeb(jsonEncodeUint(neg, quotes, u, &e.b)) -} - -func (e *jsonEncDriver[T]) EncodeInt(v int64) { - quotes := e.is == 'A' || e.is == 'L' && (v > 1<<53 || v < -(1<<53)) || - (e.ks && e.e.c == containerMapKey) - - if cpu32Bit { - if quotes { - blen := 2 + len(strconv.AppendInt(e.b[1:1], v, 10)) - e.b[0] = '"' - e.b[blen-1] = '"' - e.w.writeb(e.b[:blen]) - } else { - e.w.writeb(strconv.AppendInt(e.b[:0], v, 10)) - } - return - } - - if v < 0 { - e.encodeUint(true, quotes, uint64(-v)) - } else { - e.encodeUint(false, quotes, uint64(v)) - } -} - -func (e *jsonEncDriver[T]) EncodeUint(v uint64) { - quotes := e.is == 'A' || e.is == 'L' && v > 1<<53 || - (e.ks && e.e.c == containerMapKey) - - if cpu32Bit { - // use strconv directly, as optimized encodeUint only works on 64-bit alone - if quotes { - blen := 2 + len(strconv.AppendUint(e.b[1:1], v, 10)) - e.b[0] = '"' - e.b[blen-1] = '"' - e.w.writeb(e.b[:blen]) - } else { - e.w.writeb(strconv.AppendUint(e.b[:0], v, 10)) - } - return - } - - e.encodeUint(false, quotes, v) -} - -func (e *jsonEncDriver[T]) EncodeString(v string) { - if e.h.StringToRaw { - e.EncodeStringBytesRaw(bytesView(v)) - return - } - e.quoteStr(v) -} - -func (e *jsonEncDriver[T]) EncodeStringNoEscape4Json(v string) { e.w.writeqstr(v) } - -func (e *jsonEncDriver[T]) EncodeStringBytesRaw(v []byte) { - if e.rawext { - // explicitly convert v to interface{} so that v doesn't escape to heap - iv := e.h.RawBytesExt.ConvertExt(any(v)) - if iv == nil { - e.EncodeNil() - } else { - e.enc.encodeI(iv) - } - return - } - - if e.bytesFmt == jsonBytesFmtArray { - e.WriteArrayStart(len(v)) - for j := range v { - e.WriteArrayElem(j == 0) - e.encodeUint(false, false, uint64(v[j])) - } - e.WriteArrayEnd() - return - } - - // hardcode base64, so we call direct (not via interface) and hopefully inline - var slen int - if e.bytesFmt == jsonBytesFmtBase64 { - slen = base64.StdEncoding.EncodedLen(len(v)) - } else { - slen = e.byteFmter.EncodedLen(len(v)) - } - slen += 2 - - // bs := e.e.blist.check(*e.buf, n)[:slen] - // *e.buf = bs - - bs := e.e.blist.peek(slen, false)[:slen] - - if e.bytesFmt == jsonBytesFmtBase64 { - base64.StdEncoding.Encode(bs[1:], v) - } else { - e.byteFmter.Encode(bs[1:], v) - } - - bs[len(bs)-1] = '"' - bs[0] = '"' - e.w.writeb(bs) -} - -func (e *jsonEncDriver[T]) EncodeBytes(v []byte) { - if v == nil { - e.writeNilBytes() - return - } - e.EncodeStringBytesRaw(v) -} - -func (e *jsonEncDriver[T]) writeNilOr(v []byte) { - if !e.h.NilCollectionToZeroLength { - v = jsonNull - } - e.w.writeb(v) -} - -func (e *jsonEncDriver[T]) writeNilBytes() { - e.writeNilOr(jsonArrayEmpty) -} - -func (e *jsonEncDriver[T]) writeNilArray() { - e.writeNilOr(jsonArrayEmpty) -} - -func (e *jsonEncDriver[T]) writeNilMap() { - e.writeNilOr(jsonMapEmpty) -} - -// indent is done as below: -// - newline and indent are added before each mapKey or arrayElem -// - newline and indent are added before each ending, -// except there was no entry (so we can have {} or []) - -func (e *jsonEncDriver[T]) WriteArrayEmpty() { - e.w.writen2('[', ']') -} - -func (e *jsonEncDriver[T]) WriteMapEmpty() { - e.w.writen2('{', '}') -} - -func (e *jsonEncDriver[T]) WriteArrayStart(length int) { - if e.d { - e.dl++ - } - e.w.writen1('[') -} - -func (e *jsonEncDriver[T]) WriteArrayEnd() { - if e.d { - e.dl-- - // No need as encoder handles zero-len already - // if e.e.c != containerArrayStart { - e.writeIndent() - } - e.w.writen1(']') -} - -func (e *jsonEncDriver[T]) WriteMapStart(length int) { - if e.d { - e.dl++ - } - e.w.writen1('{') -} - -func (e *jsonEncDriver[T]) WriteMapEnd() { - if e.d { - e.dl-- - // No need as encoder handles zero-len already - // if e.e.c != containerMapStart { - e.writeIndent() - } - e.w.writen1('}') -} - -func (e *jsonEncDriver[T]) quoteStr(s string) { - // adapted from std pkg encoding/json - const hex = "0123456789abcdef" - e.w.writen1('"') - var i, start uint - for i < uint(len(s)) { - // encode all bytes < 0x20 (except \r, \n). - // also encode < > & to prevent security holes when served to some browsers. - - // We optimize for ascii, by assuming that most characters are in the BMP - // and natively consumed by json without much computation. - - // if 0x20 <= b && b != '\\' && b != '"' && b != '<' && b != '>' && b != '&' { - // if (htmlasis && jsonCharSafeSet.isset(b)) || jsonCharHtmlSafeSet.isset(b) { - b := s[i] - if e.s.isset(b) { - i++ - continue - } - if b < utf8.RuneSelf { - if start < i { - e.w.writestr(s[start:i]) - } - switch b { - case '\\': - e.w.writen2('\\', '\\') - case '"': - e.w.writen2('\\', '"') - case '\n': - e.w.writen2('\\', 'n') - case '\t': - e.w.writen2('\\', 't') - case '\r': - e.w.writen2('\\', 'r') - case '\b': - e.w.writen2('\\', 'b') - case '\f': - e.w.writen2('\\', 'f') - default: - e.w.writestr(`\u00`) - e.w.writen2(hex[b>>4], hex[b&0xF]) - } - i++ - start = i - continue - } - c, size := utf8.DecodeRuneInString(s[i:]) - if c == utf8.RuneError && size == 1 { // meaning invalid encoding (so output as-is) - if start < i { - e.w.writestr(s[start:i]) - } - e.w.writestr(`\uFFFD`) - i++ - start = i - continue - } - // U+2028 is LINE SEPARATOR. U+2029 is PARAGRAPH SEPARATOR. - // Both technically valid JSON, but bomb on JSONP, so fix here *unconditionally*. - if jsonEscapeMultiByteUnicodeSep && (c == '\u2028' || c == '\u2029') { - if start < i { - e.w.writestr(s[start:i]) - } - e.w.writestr(`\u202`) - e.w.writen1(hex[c&0xF]) - i += uint(size) - start = i - continue - } - i += uint(size) - } - if start < uint(len(s)) { - e.w.writestr(s[start:]) - } - e.w.writen1('"') -} - -func (e *jsonEncDriver[T]) atEndOfEncode() { - if e.h.TermWhitespace { - var c byte = ' ' // default is that scalar is written, so output space - if e.e.c != 0 { - c = '\n' // for containers (map/list), output a newline - } - e.w.writen1(c) - } -} - -// ---------- - -type jsonDecDriver[T decReader] struct { - noBuiltInTypes - decDriverNoopNumberHelper - h *JsonHandle - d *decoderBase - - r T - - // scratch buffer used for base64 decoding (DecodeBytes in reuseBuf mode), - // or reading doubleQuoted string (DecodeStringAsBytes, DecodeNaked) - buf []byte - - tok uint8 // used to store the token read right after skipWhiteSpace - _ bool // found null - _ byte // padding - bstr [4]byte // scratch used for string \UXXX parsing - - jsonHandleOpts - - // se interfaceExtWrapper - - // ---- cpu cache line boundary? - - // bytes bool - - dec decoderI -} - -func (d *jsonDecDriver[T]) ReadMapStart() int { - d.advance() - if d.tok == 'n' { - d.checkLit3([3]byte{'u', 'l', 'l'}, d.r.readn3()) - return containerLenNil - } - if d.tok != '{' { - halt.errorByte("read map - expect char '{' but got char: ", d.tok) - } - d.tok = 0 - return containerLenUnknown -} - -func (d *jsonDecDriver[T]) ReadArrayStart() int { - d.advance() - if d.tok == 'n' { - d.checkLit3([3]byte{'u', 'l', 'l'}, d.r.readn3()) - return containerLenNil - } - if d.tok != '[' { - halt.errorByte("read array - expect char '[' but got char ", d.tok) - } - d.tok = 0 - return containerLenUnknown -} - -// MARKER: -// We attempted making sure CheckBreak can be inlined, by moving the skipWhitespace -// call to an explicit (noinline) function call. -// However, this forces CheckBreak to always incur a function call if there was whitespace, -// with no clear benefit. - -func (d *jsonDecDriver[T]) CheckBreak() bool { - d.advance() - return d.tok == '}' || d.tok == ']' -} - -func (d *jsonDecDriver[T]) checkSep(xc byte) { - d.advance() - if d.tok != xc { - d.readDelimError(xc) - } - d.tok = 0 -} - -func (d *jsonDecDriver[T]) ReadArrayElem(firstTime bool) { - if !firstTime { - d.checkSep(',') - } -} - -func (d *jsonDecDriver[T]) ReadArrayEnd() { - d.checkSep(']') -} - -func (d *jsonDecDriver[T]) ReadMapElemKey(firstTime bool) { - d.ReadArrayElem(firstTime) -} - -func (d *jsonDecDriver[T]) ReadMapElemValue() { - d.checkSep(':') -} - -func (d *jsonDecDriver[T]) ReadMapEnd() { - d.checkSep('}') -} - -//go:inline -func (d *jsonDecDriver[T]) readDelimError(xc uint8) { - halt.errorf("read json delimiter - expect char '%c' but got char '%c'", xc, d.tok) -} - -// MARKER: checkLit takes the readn(3|4) result as a parameter so they can be inlined. -// We pass the array directly to errorf, as passing slice pushes past inlining threshold, -// and passing slice also might cause allocation of the bs array on the heap. - -func (d *jsonDecDriver[T]) checkLit3(got, expect [3]byte) { - if jsonValidateSymbols && got != expect { - jsonCheckLitErr3(got, expect) - } - d.tok = 0 -} - -func (d *jsonDecDriver[T]) checkLit4(got, expect [4]byte) { - if jsonValidateSymbols && got != expect { - jsonCheckLitErr4(got, expect) - } - d.tok = 0 -} - -func (d *jsonDecDriver[T]) skipWhitespace() { - d.tok = d.r.skipWhitespace() -} - -func (d *jsonDecDriver[T]) advance() { - // handles jsonReadNum returning possibly non-printable value as tok - if d.tok < 33 { // d.tok == 0 { - d.skipWhitespace() - } -} - -func (d *jsonDecDriver[T]) nextValueBytes() []byte { - consumeString := func() { - TOP: - _, c := d.r.jsonReadAsisChars() - if c == '\\' { // consume next one and try again - d.r.readn1() - goto TOP - } - } - - d.advance() // ignore leading whitespace - d.r.startRecording() - - // cursor = d.d.rb.c - 1 // cursor starts just before non-whitespace token - switch d.tok { - default: - _, d.tok = d.r.jsonReadNum() - case 'n': - d.checkLit3([3]byte{'u', 'l', 'l'}, d.r.readn3()) - case 'f': - d.checkLit4([4]byte{'a', 'l', 's', 'e'}, d.r.readn4()) - case 't': - d.checkLit3([3]byte{'r', 'u', 'e'}, d.r.readn3()) - case '"': - consumeString() - d.tok = 0 - case '{', '[': - var elem struct{} - var stack []struct{} - - stack = append(stack, elem) - - for len(stack) != 0 { - c := d.r.readn1() - switch c { - case '"': - consumeString() - case '{', '[': - stack = append(stack, elem) - case '}', ']': - stack = stack[:len(stack)-1] - } - } - d.tok = 0 - } - return d.r.stopRecording() -} - -func (d *jsonDecDriver[T]) TryNil() bool { - d.advance() - // we don't try to see if quoted "null" was here. - // only the plain string: null denotes a nil (ie not quotes) - if d.tok == 'n' { - d.checkLit3([3]byte{'u', 'l', 'l'}, d.r.readn3()) - return true - } - return false -} - -func (d *jsonDecDriver[T]) DecodeBool() (v bool) { - d.advance() - // bool can be in quotes if and only if it's a map key - fquot := d.d.c == containerMapKey && d.tok == '"' - if fquot { - d.tok = d.r.readn1() - } - switch d.tok { - case 'f': - d.checkLit4([4]byte{'a', 'l', 's', 'e'}, d.r.readn4()) - // v = false - case 't': - d.checkLit3([3]byte{'r', 'u', 'e'}, d.r.readn3()) - v = true - case 'n': - d.checkLit3([3]byte{'u', 'l', 'l'}, d.r.readn3()) - // v = false - default: - halt.errorByte("decode bool: got first char: ", d.tok) - // v = false // "unreachable" - } - if fquot { - d.r.readn1() - } - return -} - -func (d *jsonDecDriver[T]) DecodeTime() (t time.Time) { - // read string, and pass the string into json.unmarshal - d.advance() - if d.tok == 'n' { - d.checkLit3([3]byte{'u', 'l', 'l'}, d.r.readn3()) - return - } - var bs []byte - // if a number, use the timeFmtNum - if d.tok != '"' { - bs, d.tok = d.r.jsonReadNum() - i := d.parseInt64(bs) - switch d.timeFmtNum { - case jsonTimeFmtUnix: - t = time.Unix(i, 0) - case jsonTimeFmtUnixMilli: - t = time.UnixMilli(i) - case jsonTimeFmtUnixMicro: - t = time.UnixMicro(i) - case jsonTimeFmtUnixNano: - t = time.Unix(0, i) - default: - halt.errorStr("invalid timeFmtNum") - } - return - } - - // d.tok is now '"' - // d.ensureReadingString() - bs = d.readUnescapedString() - var err error - for _, v := range d.timeFmtLayouts { - t, err = time.Parse(v, stringView(bs)) - if err == nil { - return - } - } - halt.errorStr("error decoding time") - return -} - -func (d *jsonDecDriver[T]) ContainerType() (vt valueType) { - // check container type by checking the first char - d.advance() - - // optimize this, so we don't do 4 checks but do one computation. - // return jsonContainerSet[d.tok] - - // ContainerType is mostly called for Map and Array, - // so this conditional is good enough (max 2 checks typically) - if d.tok == '{' { - return valueTypeMap - } else if d.tok == '[' { - return valueTypeArray - } else if d.tok == 'n' { - d.checkLit3([3]byte{'u', 'l', 'l'}, d.r.readn3()) - return valueTypeNil - } else if d.tok == '"' { - return valueTypeString - } - return valueTypeUnset -} - -func (d *jsonDecDriver[T]) decNumBytes() (bs []byte) { - d.advance() - if d.tok == '"' { - bs = d.r.jsonReadUntilDblQuote() - d.tok = 0 - } else if d.tok == 'n' { - d.checkLit3([3]byte{'u', 'l', 'l'}, d.r.readn3()) - } else { - bs, d.tok = d.r.jsonReadNum() - } - return -} - -func (d *jsonDecDriver[T]) DecodeUint64() (u uint64) { - b := d.decNumBytes() - u, neg, ok := parseInteger_bytes(b) - if neg { - halt.errorf("negative number cannot be decoded as uint64: %s", any(b)) - } - if !ok { - halt.onerror(strconvParseErr(b, "ParseUint")) - } - return -} - -func (d *jsonDecDriver[T]) DecodeInt64() (v int64) { - return d.parseInt64(d.decNumBytes()) -} - -func (d *jsonDecDriver[T]) parseInt64(b []byte) (v int64) { - u, neg, ok := parseInteger_bytes(b) - if !ok { - halt.onerror(strconvParseErr(b, "ParseInt")) - } - if chkOvf.Uint2Int(u, neg) { - halt.errorBytes("overflow decoding number from ", b) - } - if neg { - v = -int64(u) - } else { - v = int64(u) - } - return -} - -func (d *jsonDecDriver[T]) DecodeFloat64() (f float64) { - var err error - bs := d.decNumBytes() - if len(bs) == 0 { - return - } - f, err = parseFloat64(bs) - halt.onerror(err) - return -} - -func (d *jsonDecDriver[T]) DecodeFloat32() (f float32) { - var err error - bs := d.decNumBytes() - if len(bs) == 0 { - return - } - f, err = parseFloat32(bs) - halt.onerror(err) - return -} - -func (d *jsonDecDriver[T]) advanceNil() (ok bool) { - d.advance() - if d.tok == 'n' { - d.checkLit3([3]byte{'u', 'l', 'l'}, d.r.readn3()) - return true - } - return false -} - -func (d *jsonDecDriver[T]) DecodeExt(rv interface{}, basetype reflect.Type, xtag uint64, ext Ext) { - if d.advanceNil() { - return - } - if ext == SelfExt { - d.dec.decodeAs(rv, basetype, false) - } else { - d.dec.interfaceExtConvertAndDecode(rv, ext) - } -} - -func (d *jsonDecDriver[T]) DecodeRawExt(re *RawExt) { - if d.advanceNil() { - return - } - d.dec.decode(&re.Value) -} - -func (d *jsonDecDriver[T]) decBytesFromArray(bs []byte) []byte { - d.advance() - if d.tok != ']' { - bs = append(bs, uint8(d.DecodeUint64())) - d.advance() - } - for d.tok != ']' { - if d.tok != ',' { - halt.errorByte("read array element - expect char ',' but got char: ", d.tok) - } - d.tok = 0 - bs = append(bs, uint8(chkOvf.UintV(d.DecodeUint64(), 8))) - d.advance() - } - d.tok = 0 - return bs -} - -func (d *jsonDecDriver[T]) DecodeBytes() (bs []byte, state dBytesAttachState) { - d.advance() - state = dBytesDetach - if d.tok == 'n' { - d.checkLit3([3]byte{'u', 'l', 'l'}, d.r.readn3()) - return - } - state = dBytesAttachBuffer - // if decoding into raw bytes, and the RawBytesExt is configured, use it to decode. - if d.rawext { - d.buf = d.buf[:0] - d.dec.interfaceExtConvertAndDecode(&d.buf, d.h.RawBytesExt) - bs = d.buf - return - } - // check if an "array" of uint8's (see ContainerType for how to infer if an array) - if d.tok == '[' { - d.tok = 0 - // bsOut, _ = fastpathTV.DecSliceUint8V(bs, true, d.d) - bs = d.decBytesFromArray(d.buf[:0]) - d.buf = bs - return - } - - // base64 encodes []byte{} as "", and we encode nil []byte as null. - // Consequently, base64 should decode null as a nil []byte, and "" as an empty []byte{}. - - d.ensureReadingString() - bs1 := d.readUnescapedString() - // base64 is most compact of supported formats; it's decodedlen is sufficient for all - slen := base64.StdEncoding.DecodedLen(len(bs1)) - if slen == 0 { - bs = zeroByteSlice - state = dBytesDetach - } else if slen <= cap(d.buf) { - bs = d.buf[:slen] - } else { - d.buf = d.d.blist.putGet(d.buf, slen)[:slen] - bs = d.buf - } - var err error - for _, v := range d.byteFmters { - // slen := v.DecodedLen(len(bs1)) - slen, err = v.Decode(bs, bs1) - if err == nil { - bs = bs[:slen] - return - } - } - halt.errorf("error decoding byte string '%s': %v", any(bs1), err) - return -} - -func (d *jsonDecDriver[T]) DecodeStringAsBytes() (bs []byte, state dBytesAttachState) { - d.advance() - - var cond bool - // common case - hoist outside the switch statement - if d.tok == '"' { - d.tok = 0 - bs, cond = d.dblQuoteStringAsBytes() - state = d.d.attachState(cond) - return - } - - state = dBytesDetach - // handle non-string scalar: null, true, false or a number - switch d.tok { - case 'n': - d.checkLit3([3]byte{'u', 'l', 'l'}, d.r.readn3()) - // out = nil // []byte{} - case 'f': - d.checkLit4([4]byte{'a', 'l', 's', 'e'}, d.r.readn4()) - bs = jsonLitb[jsonLitF : jsonLitF+5] - case 't': - d.checkLit3([3]byte{'r', 'u', 'e'}, d.r.readn3()) - bs = jsonLitb[jsonLitT : jsonLitT+4] - default: - // try to parse a valid number - bs, d.tok = d.r.jsonReadNum() - state = d.d.attachState(!d.d.bytes) - } - return -} - -func (d *jsonDecDriver[T]) ensureReadingString() { - if d.tok != '"' { - halt.errorByte("expecting string starting with '\"'; got ", d.tok) - } -} - -func (d *jsonDecDriver[T]) readUnescapedString() (bs []byte) { - // d.ensureReadingString() - bs = d.r.jsonReadUntilDblQuote() - d.tok = 0 - return -} - -func (d *jsonDecDriver[T]) dblQuoteStringAsBytes() (buf []byte, usingBuf bool) { - bs, c := d.r.jsonReadAsisChars() - if c == '"' { - return bs, !d.d.bytes - } - buf = append(d.buf[:0], bs...) - - checkUtf8 := d.h.ValidateUnicode - usingBuf = true - - for { - // c is now '\' - c = d.r.readn1() - - switch c { - case '"', '\\', '/', '\'': - buf = append(buf, c) - case 'b': - buf = append(buf, '\b') - case 'f': - buf = append(buf, '\f') - case 'n': - buf = append(buf, '\n') - case 'r': - buf = append(buf, '\r') - case 't': - buf = append(buf, '\t') - case 'u': - rr := d.appendStringAsBytesSlashU() - if checkUtf8 && rr == unicode.ReplacementChar { - d.buf = buf - halt.errorBytes("invalid UTF-8 character found after: ", buf) - } - buf = append(buf, d.bstr[:utf8.EncodeRune(d.bstr[:], rr)]...) - default: - d.buf = buf - halt.errorByte("unsupported escaped value: ", c) - } - - bs, c = d.r.jsonReadAsisChars() - buf = append(buf, bs...) - if c == '"' { - break - } - } - d.buf = buf - return -} - -func (d *jsonDecDriver[T]) appendStringAsBytesSlashU() (r rune) { - var rr uint32 - cs := d.r.readn4() - if rr = jsonSlashURune(cs); rr == unicode.ReplacementChar { - return unicode.ReplacementChar - } - r = rune(rr) - if utf16.IsSurrogate(r) { - csu := d.r.readn2() - cs = d.r.readn4() - if csu[0] == '\\' && csu[1] == 'u' { - if rr = jsonSlashURune(cs); rr == unicode.ReplacementChar { - return unicode.ReplacementChar - } - return utf16.DecodeRune(r, rune(rr)) - } - return unicode.ReplacementChar - } - return -} - -func (d *jsonDecDriver[T]) DecodeNaked() { - z := d.d.naked() - - d.advance() - var bs []byte - var err error - switch d.tok { - case 'n': - d.checkLit3([3]byte{'u', 'l', 'l'}, d.r.readn3()) - z.v = valueTypeNil - case 'f': - d.checkLit4([4]byte{'a', 'l', 's', 'e'}, d.r.readn4()) - z.v = valueTypeBool - z.b = false - case 't': - d.checkLit3([3]byte{'r', 'u', 'e'}, d.r.readn3()) - z.v = valueTypeBool - z.b = true - case '{': - z.v = valueTypeMap // don't consume. kInterfaceNaked will call ReadMapStart - case '[': - z.v = valueTypeArray // don't consume. kInterfaceNaked will call ReadArrayStart - case '"': - // if a string, and MapKeyAsString, then try to decode it as a bool or number first - d.tok = 0 - bs, z.b = d.dblQuoteStringAsBytes() - att := d.d.attachState(z.b) - if jsonNakedBoolNumInQuotedStr && - d.h.MapKeyAsString && len(bs) > 0 && d.d.c == containerMapKey { - switch string(bs) { - // case "null": // nil is never quoted - // z.v = valueTypeNil - case "true": - z.v = valueTypeBool - z.b = true - case "false": - z.v = valueTypeBool - z.b = false - default: // check if a number: float, int or uint - if err = jsonNakedNum(z, bs, d.h.PreferFloat, d.h.SignedInteger); err != nil { - z.v = valueTypeString - z.s = d.d.detach2Str(bs, att) - } - } - } else { - z.v = valueTypeString - z.s = d.d.detach2Str(bs, att) - } - default: // number - bs, d.tok = d.r.jsonReadNum() - if len(bs) == 0 { - halt.errorStr("decode number from empty string") - } - if err = jsonNakedNum(z, bs, d.h.PreferFloat, d.h.SignedInteger); err != nil { - halt.errorf("decode number from %s: %v", any(bs), err) - } - } -} - -func (e *jsonEncDriver[T]) reset() { - e.dl = 0 - // e.resetState() - // (htmlasis && jsonCharSafeSet.isset(b)) || jsonCharHtmlSafeSet.isset(b) - // cache values from the handle - e.typical = e.h.typical() - if e.h.HTMLCharsAsIs { - e.s = &jsonCharSafeBitset - } else { - e.s = &jsonCharHtmlSafeBitset - } - e.di = int8(e.h.Indent) - e.d = e.h.Indent != 0 - e.ks = e.h.MapKeyAsString - e.is = e.h.IntegerAsString - - var ho jsonHandleOpts - ho.reset(e.h) - e.timeFmt = ho.timeFmt - e.bytesFmt = ho.bytesFmt - e.timeFmtLayout = "" - e.byteFmter = nil - if len(ho.timeFmtLayouts) > 0 { - e.timeFmtLayout = ho.timeFmtLayouts[0] - } - if len(ho.byteFmters) > 0 { - e.byteFmter = ho.byteFmters[0] - } - e.rawext = ho.rawext -} - -func (d *jsonDecDriver[T]) reset() { - d.buf = d.d.blist.check(d.buf, 256) - d.tok = 0 - // d.resetState() - d.jsonHandleOpts.reset(d.h) -} - -// ---- -// -// The following below are similar across all format files (except for the format name). -// -// We keep them together here, so that we can easily copy and compare. - -// ---- - -func (d *jsonEncDriver[T]) init(hh Handle, shared *encoderBase, enc encoderI) (fp interface{}) { - callMake(&d.w) - d.h = hh.(*JsonHandle) - d.e = shared - if shared.bytes { - fp = jsonFpEncBytes - } else { - fp = jsonFpEncIO - } - // d.w.init() - d.init2(enc) - return -} - -func (e *jsonEncDriver[T]) writeBytesAsis(b []byte) { e.w.writeb(b) } - -// func (e *jsonEncDriver[T]) writeStringAsisDblQuoted(v string) { e.w.writeqstr(v) } -func (e *jsonEncDriver[T]) writerEnd() { e.w.end() } - -func (e *jsonEncDriver[T]) resetOutBytes(out *[]byte) { - e.w.resetBytes(*out, out) -} - -func (e *jsonEncDriver[T]) resetOutIO(out io.Writer) { - e.w.resetIO(out, e.h.WriterBufferSize, &e.e.blist) -} - -// ---- - -func (d *jsonDecDriver[T]) init(hh Handle, shared *decoderBase, dec decoderI) (fp interface{}) { - callMake(&d.r) - d.h = hh.(*JsonHandle) - d.d = shared - if shared.bytes { - fp = jsonFpDecBytes - } else { - fp = jsonFpDecIO - } - // d.r.init() - d.init2(dec) - return -} - -func (d *jsonDecDriver[T]) NumBytesRead() int { - return int(d.r.numread()) -} - -func (d *jsonDecDriver[T]) resetInBytes(in []byte) { - d.r.resetBytes(in) -} - -func (d *jsonDecDriver[T]) resetInIO(r io.Reader) { - d.r.resetIO(r, d.h.ReaderBufferSize, d.h.MaxInitLen, &d.d.blist) -} - -// ---- (custom stanza) - -func (d *jsonDecDriver[T]) descBd() (s string) { - halt.onerror(errJsonNoBd) - return -} - -func (d *jsonEncDriver[T]) init2(enc encoderI) { - d.enc = enc - // d.e.js = true -} - -func (d *jsonDecDriver[T]) init2(dec decoderI) { - d.dec = dec - // var x []byte - // d.buf = &x - // d.buf = new([]byte) - d.buf = d.buf[:0] - // d.d.js = true - d.d.jsms = d.h.MapKeyAsString -} diff --git a/vendor/github.com/ugorji/go/codec/json.mono.generated.go b/vendor/github.com/ugorji/go/codec/json.mono.generated.go deleted file mode 100644 index 12da25c30..000000000 --- a/vendor/github.com/ugorji/go/codec/json.mono.generated.go +++ /dev/null @@ -1,8339 +0,0 @@ -//go:build !notmono && !codec.notmono - -// Copyright (c) 2012-2020 Ugorji Nwoke. All rights reserved. -// Use of this source code is governed by a MIT license found in the LICENSE file. - -package codec - -import ( - "encoding" - - "encoding/base64" - "io" - "math" - "reflect" - "slices" - "sort" - "strconv" - "sync" - "time" - "unicode" - "unicode/utf16" - "unicode/utf8" -) - -type helperEncDriverJsonBytes struct{} -type encFnJsonBytes struct { - i encFnInfo - fe func(*encoderJsonBytes, *encFnInfo, reflect.Value) -} -type encRtidFnJsonBytes struct { - rtid uintptr - fn *encFnJsonBytes -} -type encoderJsonBytes struct { - dh helperEncDriverJsonBytes - fp *fastpathEsJsonBytes - e jsonEncDriverBytes - encoderBase -} -type helperDecDriverJsonBytes struct{} -type decFnJsonBytes struct { - i decFnInfo - fd func(*decoderJsonBytes, *decFnInfo, reflect.Value) -} -type decRtidFnJsonBytes struct { - rtid uintptr - fn *decFnJsonBytes -} -type decoderJsonBytes struct { - dh helperDecDriverJsonBytes - fp *fastpathDsJsonBytes - d jsonDecDriverBytes - decoderBase -} -type jsonEncDriverBytes struct { - noBuiltInTypes - h *JsonHandle - e *encoderBase - s *bitset256 - - w bytesEncAppender - - enc encoderI - - timeFmtLayout string - byteFmter jsonBytesFmter - - timeFmt jsonTimeFmt - bytesFmt jsonBytesFmt - - di int8 - d bool - dl uint16 - - ks bool - is byte - - typical bool - - rawext bool - - b [48]byte -} -type jsonDecDriverBytes struct { - noBuiltInTypes - decDriverNoopNumberHelper - h *JsonHandle - d *decoderBase - - r bytesDecReader - - buf []byte - - tok uint8 - _ bool - _ byte - bstr [4]byte - - jsonHandleOpts - - dec decoderI -} - -func (e *encoderJsonBytes) rawExt(_ *encFnInfo, rv reflect.Value) { - if re := rv2i(rv).(*RawExt); re == nil { - e.e.EncodeNil() - } else { - e.e.EncodeRawExt(re) - } -} - -func (e *encoderJsonBytes) ext(f *encFnInfo, rv reflect.Value) { - e.e.EncodeExt(rv2i(rv), f.ti.rt, f.xfTag, f.xfFn) -} - -func (e *encoderJsonBytes) selferMarshal(_ *encFnInfo, rv reflect.Value) { - rv2i(rv).(Selfer).CodecEncodeSelf(&Encoder{e}) -} - -func (e *encoderJsonBytes) binaryMarshal(_ *encFnInfo, rv reflect.Value) { - bs, fnerr := rv2i(rv).(encoding.BinaryMarshaler).MarshalBinary() - e.marshalRaw(bs, fnerr) -} - -func (e *encoderJsonBytes) textMarshal(_ *encFnInfo, rv reflect.Value) { - bs, fnerr := rv2i(rv).(encoding.TextMarshaler).MarshalText() - e.marshalUtf8(bs, fnerr) -} - -func (e *encoderJsonBytes) jsonMarshal(_ *encFnInfo, rv reflect.Value) { - bs, fnerr := rv2i(rv).(jsonMarshaler).MarshalJSON() - e.marshalAsis(bs, fnerr) -} - -func (e *encoderJsonBytes) raw(_ *encFnInfo, rv reflect.Value) { - e.rawBytes(rv2i(rv).(Raw)) -} - -func (e *encoderJsonBytes) encodeComplex64(v complex64) { - if imag(v) != 0 { - halt.errorf("cannot encode complex number: %v, with imaginary values: %v", any(v), any(imag(v))) - } - e.e.EncodeFloat32(real(v)) -} - -func (e *encoderJsonBytes) encodeComplex128(v complex128) { - if imag(v) != 0 { - halt.errorf("cannot encode complex number: %v, with imaginary values: %v", any(v), any(imag(v))) - } - e.e.EncodeFloat64(real(v)) -} - -func (e *encoderJsonBytes) kBool(_ *encFnInfo, rv reflect.Value) { - e.e.EncodeBool(rvGetBool(rv)) -} - -func (e *encoderJsonBytes) kTime(_ *encFnInfo, rv reflect.Value) { - e.e.EncodeTime(rvGetTime(rv)) -} - -func (e *encoderJsonBytes) kString(_ *encFnInfo, rv reflect.Value) { - e.e.EncodeString(rvGetString(rv)) -} - -func (e *encoderJsonBytes) kFloat32(_ *encFnInfo, rv reflect.Value) { - e.e.EncodeFloat32(rvGetFloat32(rv)) -} - -func (e *encoderJsonBytes) kFloat64(_ *encFnInfo, rv reflect.Value) { - e.e.EncodeFloat64(rvGetFloat64(rv)) -} - -func (e *encoderJsonBytes) kComplex64(_ *encFnInfo, rv reflect.Value) { - e.encodeComplex64(rvGetComplex64(rv)) -} - -func (e *encoderJsonBytes) kComplex128(_ *encFnInfo, rv reflect.Value) { - e.encodeComplex128(rvGetComplex128(rv)) -} - -func (e *encoderJsonBytes) kInt(_ *encFnInfo, rv reflect.Value) { - e.e.EncodeInt(int64(rvGetInt(rv))) -} - -func (e *encoderJsonBytes) kInt8(_ *encFnInfo, rv reflect.Value) { - e.e.EncodeInt(int64(rvGetInt8(rv))) -} - -func (e *encoderJsonBytes) kInt16(_ *encFnInfo, rv reflect.Value) { - e.e.EncodeInt(int64(rvGetInt16(rv))) -} - -func (e *encoderJsonBytes) kInt32(_ *encFnInfo, rv reflect.Value) { - e.e.EncodeInt(int64(rvGetInt32(rv))) -} - -func (e *encoderJsonBytes) kInt64(_ *encFnInfo, rv reflect.Value) { - e.e.EncodeInt(int64(rvGetInt64(rv))) -} - -func (e *encoderJsonBytes) kUint(_ *encFnInfo, rv reflect.Value) { - e.e.EncodeUint(uint64(rvGetUint(rv))) -} - -func (e *encoderJsonBytes) kUint8(_ *encFnInfo, rv reflect.Value) { - e.e.EncodeUint(uint64(rvGetUint8(rv))) -} - -func (e *encoderJsonBytes) kUint16(_ *encFnInfo, rv reflect.Value) { - e.e.EncodeUint(uint64(rvGetUint16(rv))) -} - -func (e *encoderJsonBytes) kUint32(_ *encFnInfo, rv reflect.Value) { - e.e.EncodeUint(uint64(rvGetUint32(rv))) -} - -func (e *encoderJsonBytes) kUint64(_ *encFnInfo, rv reflect.Value) { - e.e.EncodeUint(uint64(rvGetUint64(rv))) -} - -func (e *encoderJsonBytes) kUintptr(_ *encFnInfo, rv reflect.Value) { - e.e.EncodeUint(uint64(rvGetUintptr(rv))) -} - -func (e *encoderJsonBytes) kSeqFn(rt reflect.Type) (fn *encFnJsonBytes) { - - if rt = baseRT(rt); rt.Kind() != reflect.Interface { - fn = e.fn(rt) - } - return -} - -func (e *encoderJsonBytes) kArrayWMbs(rv reflect.Value, ti *typeInfo, isSlice bool) { - var l int - if isSlice { - l = rvLenSlice(rv) - } else { - l = rv.Len() - } - if l == 0 { - e.e.WriteMapEmpty() - return - } - e.haltOnMbsOddLen(l) - e.mapStart(l >> 1) - - var fn *encFnJsonBytes - builtin := ti.tielem.flagEncBuiltin - if !builtin { - fn = e.kSeqFn(ti.elem) - } - - j := 0 - e.c = containerMapKey - e.e.WriteMapElemKey(true) - for { - rvv := rvArrayIndex(rv, j, ti, isSlice) - if builtin { - e.encodeIB(rv2i(baseRVRV(rvv))) - } else { - e.encodeValue(rvv, fn) - } - j++ - if j == l { - break - } - if j&1 == 0 { - e.c = containerMapKey - e.e.WriteMapElemKey(false) - } else { - e.mapElemValue() - } - } - e.c = 0 - e.e.WriteMapEnd() - -} - -func (e *encoderJsonBytes) kArrayW(rv reflect.Value, ti *typeInfo, isSlice bool) { - var l int - if isSlice { - l = rvLenSlice(rv) - } else { - l = rv.Len() - } - if l <= 0 { - e.e.WriteArrayEmpty() - return - } - e.arrayStart(l) - - var fn *encFnJsonBytes - if !ti.tielem.flagEncBuiltin { - fn = e.kSeqFn(ti.elem) - } - - j := 0 - e.c = containerArrayElem - e.e.WriteArrayElem(true) - builtin := ti.tielem.flagEncBuiltin - for { - rvv := rvArrayIndex(rv, j, ti, isSlice) - if builtin { - e.encodeIB(rv2i(baseRVRV(rvv))) - } else { - e.encodeValue(rvv, fn) - } - j++ - if j == l { - break - } - e.c = containerArrayElem - e.e.WriteArrayElem(false) - } - - e.c = 0 - e.e.WriteArrayEnd() -} - -func (e *encoderJsonBytes) kChan(f *encFnInfo, rv reflect.Value) { - if f.ti.chandir&uint8(reflect.RecvDir) == 0 { - halt.errorStr("send-only channel cannot be encoded") - } - if !f.ti.mbs && uint8TypId == rt2id(f.ti.elem) { - e.kSliceBytesChan(rv) - return - } - rtslice := reflect.SliceOf(f.ti.elem) - rv = chanToSlice(rv, rtslice, e.h.ChanRecvTimeout) - ti := e.h.getTypeInfo(rt2id(rtslice), rtslice) - if f.ti.mbs { - e.kArrayWMbs(rv, ti, true) - } else { - e.kArrayW(rv, ti, true) - } -} - -func (e *encoderJsonBytes) kSlice(f *encFnInfo, rv reflect.Value) { - if f.ti.mbs { - e.kArrayWMbs(rv, f.ti, true) - } else if f.ti.rtid == uint8SliceTypId || uint8TypId == rt2id(f.ti.elem) { - - e.e.EncodeBytes(rvGetBytes(rv)) - } else { - e.kArrayW(rv, f.ti, true) - } -} - -func (e *encoderJsonBytes) kArray(f *encFnInfo, rv reflect.Value) { - if f.ti.mbs { - e.kArrayWMbs(rv, f.ti, false) - } else if handleBytesWithinKArray && uint8TypId == rt2id(f.ti.elem) { - e.e.EncodeStringBytesRaw(rvGetArrayBytes(rv, nil)) - } else { - e.kArrayW(rv, f.ti, false) - } -} - -func (e *encoderJsonBytes) kSliceBytesChan(rv reflect.Value) { - - bs0 := e.blist.peek(32, true) - bs := bs0 - - irv := rv2i(rv) - ch, ok := irv.(<-chan byte) - if !ok { - ch = irv.(chan byte) - } - -L1: - switch timeout := e.h.ChanRecvTimeout; { - case timeout == 0: - for { - select { - case b := <-ch: - bs = append(bs, b) - default: - break L1 - } - } - case timeout > 0: - tt := time.NewTimer(timeout) - for { - select { - case b := <-ch: - bs = append(bs, b) - case <-tt.C: - - break L1 - } - } - default: - for b := range ch { - bs = append(bs, b) - } - } - - e.e.EncodeBytes(bs) - e.blist.put(bs) - if !byteSliceSameData(bs0, bs) { - e.blist.put(bs0) - } -} - -func (e *encoderJsonBytes) kStructFieldKey(keyType valueType, encName string) { - - if keyType == valueTypeString { - e.e.EncodeString(encName) - } else if keyType == valueTypeInt { - e.e.EncodeInt(must.Int(strconv.ParseInt(encName, 10, 64))) - } else if keyType == valueTypeUint { - e.e.EncodeUint(must.Uint(strconv.ParseUint(encName, 10, 64))) - } else if keyType == valueTypeFloat { - e.e.EncodeFloat64(must.Float(strconv.ParseFloat(encName, 64))) - } else { - halt.errorStr2("invalid struct key type: ", keyType.String()) - } - -} - -func (e *encoderJsonBytes) kStructSimple(f *encFnInfo, rv reflect.Value) { - _ = e.e - tisfi := f.ti.sfi.source() - - chkCirRef := e.h.CheckCircularRef - var si *structFieldInfo - var j int - - if f.ti.toArray || e.h.StructToArray { - if len(tisfi) == 0 { - e.e.WriteArrayEmpty() - return - } - e.arrayStart(len(tisfi)) - for j, si = range tisfi { - e.c = containerArrayElem - e.e.WriteArrayElem(j == 0) - if si.encBuiltin { - e.encodeIB(rv2i(si.fieldNoAlloc(rv, true))) - } else { - e.encodeValue(si.fieldNoAlloc(rv, !chkCirRef), nil) - } - } - e.c = 0 - e.e.WriteArrayEnd() - } else { - if len(tisfi) == 0 { - e.e.WriteMapEmpty() - return - } - if e.h.Canonical { - tisfi = f.ti.sfi.sorted() - } - e.mapStart(len(tisfi)) - for j, si = range tisfi { - e.c = containerMapKey - e.e.WriteMapElemKey(j == 0) - e.e.EncodeStringNoEscape4Json(si.encName) - e.mapElemValue() - if si.encBuiltin { - e.encodeIB(rv2i(si.fieldNoAlloc(rv, true))) - } else { - e.encodeValue(si.fieldNoAlloc(rv, !chkCirRef), nil) - } - } - e.c = 0 - e.e.WriteMapEnd() - } -} - -func (e *encoderJsonBytes) kStruct(f *encFnInfo, rv reflect.Value) { - _ = e.e - ti := f.ti - toMap := !(ti.toArray || e.h.StructToArray) - var mf map[string]interface{} - if ti.flagMissingFielder { - toMap = true - mf = rv2i(rv).(MissingFielder).CodecMissingFields() - } else if ti.flagMissingFielderPtr { - toMap = true - if rv.CanAddr() { - mf = rv2i(rvAddr(rv, ti.ptr)).(MissingFielder).CodecMissingFields() - } else { - mf = rv2i(e.addrRV(rv, ti.rt, ti.ptr)).(MissingFielder).CodecMissingFields() - } - } - newlen := len(mf) - tisfi := ti.sfi.source() - newlen += len(tisfi) - - var fkvs = e.slist.get(newlen)[:newlen] - - recur := e.h.RecursiveEmptyCheck - chkCirRef := e.h.CheckCircularRef - - var xlen int - - var kv sfiRv - var j int - var sf encStructFieldObj - if toMap { - newlen = 0 - if e.h.Canonical { - tisfi = f.ti.sfi.sorted() - } - for _, si := range tisfi { - - if si.omitEmpty { - kv.r = si.fieldNoAlloc(rv, false) - if isEmptyValue(kv.r, e.h.TypeInfos, recur) { - continue - } - } else { - kv.r = si.fieldNoAlloc(rv, si.encBuiltin || !chkCirRef) - } - kv.v = si - fkvs[newlen] = kv - newlen++ - } - - var mf2s []stringIntf - if len(mf) != 0 { - mf2s = make([]stringIntf, 0, len(mf)) - for k, v := range mf { - if k == "" { - continue - } - if ti.infoFieldOmitempty && isEmptyValue(reflect.ValueOf(v), e.h.TypeInfos, recur) { - continue - } - mf2s = append(mf2s, stringIntf{k, v}) - } - } - - xlen = newlen + len(mf2s) - if xlen == 0 { - e.e.WriteMapEmpty() - goto END - } - - e.mapStart(xlen) - - if len(mf2s) != 0 && e.h.Canonical { - mf2w := make([]encStructFieldObj, newlen+len(mf2s)) - for j = 0; j < newlen; j++ { - kv = fkvs[j] - mf2w[j] = encStructFieldObj{kv.v.encName, kv.r, nil, true, - !kv.v.encNameEscape4Json, kv.v.encBuiltin} - } - for _, v := range mf2s { - mf2w[j] = encStructFieldObj{v.v, reflect.Value{}, v.i, false, false, false} - j++ - } - sort.Sort((encStructFieldObjSlice)(mf2w)) - for j, sf = range mf2w { - e.c = containerMapKey - e.e.WriteMapElemKey(j == 0) - if ti.keyType == valueTypeString && sf.noEsc4json { - e.e.EncodeStringNoEscape4Json(sf.key) - } else { - e.kStructFieldKey(ti.keyType, sf.key) - } - e.mapElemValue() - if sf.isRv { - if sf.builtin { - e.encodeIB(rv2i(baseRVRV(sf.rv))) - } else { - e.encodeValue(sf.rv, nil) - } - } else { - if !e.encodeBuiltin(sf.intf) { - e.encodeR(reflect.ValueOf(sf.intf)) - } - - } - } - } else { - keytyp := ti.keyType - for j = 0; j < newlen; j++ { - kv = fkvs[j] - e.c = containerMapKey - e.e.WriteMapElemKey(j == 0) - if ti.keyType == valueTypeString && !kv.v.encNameEscape4Json { - e.e.EncodeStringNoEscape4Json(kv.v.encName) - } else { - e.kStructFieldKey(keytyp, kv.v.encName) - } - e.mapElemValue() - if kv.v.encBuiltin { - e.encodeIB(rv2i(baseRVRV(kv.r))) - } else { - e.encodeValue(kv.r, nil) - } - } - for _, v := range mf2s { - e.c = containerMapKey - e.e.WriteMapElemKey(j == 0) - e.kStructFieldKey(keytyp, v.v) - e.mapElemValue() - if !e.encodeBuiltin(v.i) { - e.encodeR(reflect.ValueOf(v.i)) - } - - j++ - } - } - - e.c = 0 - e.e.WriteMapEnd() - } else { - newlen = len(tisfi) - for i, si := range tisfi { - - if si.omitEmpty { - - kv.r = si.fieldNoAlloc(rv, false) - if isEmptyContainerValue(kv.r, e.h.TypeInfos, recur) { - kv.r = reflect.Value{} - } - } else { - kv.r = si.fieldNoAlloc(rv, si.encBuiltin || !chkCirRef) - } - kv.v = si - fkvs[i] = kv - } - - if newlen == 0 { - e.e.WriteArrayEmpty() - goto END - } - - e.arrayStart(newlen) - for j = 0; j < newlen; j++ { - e.c = containerArrayElem - e.e.WriteArrayElem(j == 0) - kv = fkvs[j] - if !kv.r.IsValid() { - e.e.EncodeNil() - } else if kv.v.encBuiltin { - e.encodeIB(rv2i(baseRVRV(kv.r))) - } else { - e.encodeValue(kv.r, nil) - } - } - e.c = 0 - e.e.WriteArrayEnd() - } - -END: - - e.slist.put(fkvs) -} - -func (e *encoderJsonBytes) kMap(f *encFnInfo, rv reflect.Value) { - _ = e.e - l := rvLenMap(rv) - if l == 0 { - e.e.WriteMapEmpty() - return - } - e.mapStart(l) - - var keyFn, valFn *encFnJsonBytes - - ktypeKind := reflect.Kind(f.ti.keykind) - vtypeKind := reflect.Kind(f.ti.elemkind) - - rtval := f.ti.elem - rtvalkind := vtypeKind - for rtvalkind == reflect.Ptr { - rtval = rtval.Elem() - rtvalkind = rtval.Kind() - } - if rtvalkind != reflect.Interface { - valFn = e.fn(rtval) - } - - var rvv = mapAddrLoopvarRV(f.ti.elem, vtypeKind) - - rtkey := f.ti.key - var keyTypeIsString = stringTypId == rt2id(rtkey) - if keyTypeIsString { - keyFn = e.fn(rtkey) - } else { - for rtkey.Kind() == reflect.Ptr { - rtkey = rtkey.Elem() - } - if rtkey.Kind() != reflect.Interface { - keyFn = e.fn(rtkey) - } - } - - if e.h.Canonical { - e.kMapCanonical(f.ti, rv, rvv, keyFn, valFn) - e.c = 0 - e.e.WriteMapEnd() - return - } - - var rvk = mapAddrLoopvarRV(f.ti.key, ktypeKind) - - var it mapIter - mapRange(&it, rv, rvk, rvv, true) - - kbuiltin := f.ti.tikey.flagEncBuiltin - vbuiltin := f.ti.tielem.flagEncBuiltin - for j := 0; it.Next(); j++ { - rv = it.Key() - e.c = containerMapKey - e.e.WriteMapElemKey(j == 0) - if keyTypeIsString { - e.e.EncodeString(rvGetString(rv)) - } else if kbuiltin { - e.encodeIB(rv2i(baseRVRV(rv))) - } else { - e.encodeValue(rv, keyFn) - } - e.mapElemValue() - rv = it.Value() - if vbuiltin { - e.encodeIB(rv2i(baseRVRV(rv))) - } else { - e.encodeValue(it.Value(), valFn) - } - } - it.Done() - - e.c = 0 - e.e.WriteMapEnd() -} - -func (e *encoderJsonBytes) kMapCanonical(ti *typeInfo, rv, rvv reflect.Value, keyFn, valFn *encFnJsonBytes) { - _ = e.e - - rtkey := ti.key - rtkeydecl := rtkey.PkgPath() == "" && rtkey.Name() != "" - - mks := rv.MapKeys() - rtkeyKind := rtkey.Kind() - mparams := getMapReqParams(ti) - - switch rtkeyKind { - case reflect.Bool: - - if len(mks) == 2 && mks[0].Bool() { - mks[0], mks[1] = mks[1], mks[0] - } - for i := range mks { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - if rtkeydecl { - e.e.EncodeBool(mks[i].Bool()) - } else { - e.encodeValueNonNil(mks[i], keyFn) - } - e.mapElemValue() - e.encodeValue(mapGet(rv, mks[i], rvv, mparams), valFn) - } - case reflect.String: - mksv := make([]orderedRv[string], len(mks)) - for i, k := range mks { - v := &mksv[i] - v.r = k - v.v = rvGetString(k) - } - slices.SortFunc(mksv, cmpOrderedRv) - for i := range mksv { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - if rtkeydecl { - e.e.EncodeString(mksv[i].v) - } else { - e.encodeValueNonNil(mksv[i].r, keyFn) - } - e.mapElemValue() - e.encodeValue(mapGet(rv, mksv[i].r, rvv, mparams), valFn) - } - case reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64, reflect.Uint, reflect.Uintptr: - mksv := make([]orderedRv[uint64], len(mks)) - for i, k := range mks { - v := &mksv[i] - v.r = k - v.v = k.Uint() - } - slices.SortFunc(mksv, cmpOrderedRv) - for i := range mksv { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - if rtkeydecl { - e.e.EncodeUint(mksv[i].v) - } else { - e.encodeValueNonNil(mksv[i].r, keyFn) - } - e.mapElemValue() - e.encodeValue(mapGet(rv, mksv[i].r, rvv, mparams), valFn) - } - case reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64, reflect.Int: - mksv := make([]orderedRv[int64], len(mks)) - for i, k := range mks { - v := &mksv[i] - v.r = k - v.v = k.Int() - } - slices.SortFunc(mksv, cmpOrderedRv) - for i := range mksv { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - if rtkeydecl { - e.e.EncodeInt(mksv[i].v) - } else { - e.encodeValueNonNil(mksv[i].r, keyFn) - } - e.mapElemValue() - e.encodeValue(mapGet(rv, mksv[i].r, rvv, mparams), valFn) - } - case reflect.Float32: - mksv := make([]orderedRv[float64], len(mks)) - for i, k := range mks { - v := &mksv[i] - v.r = k - v.v = k.Float() - } - slices.SortFunc(mksv, cmpOrderedRv) - for i := range mksv { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - if rtkeydecl { - e.e.EncodeFloat32(float32(mksv[i].v)) - } else { - e.encodeValueNonNil(mksv[i].r, keyFn) - } - e.mapElemValue() - e.encodeValue(mapGet(rv, mksv[i].r, rvv, mparams), valFn) - } - case reflect.Float64: - mksv := make([]orderedRv[float64], len(mks)) - for i, k := range mks { - v := &mksv[i] - v.r = k - v.v = k.Float() - } - slices.SortFunc(mksv, cmpOrderedRv) - for i := range mksv { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - if rtkeydecl { - e.e.EncodeFloat64(mksv[i].v) - } else { - e.encodeValueNonNil(mksv[i].r, keyFn) - } - e.mapElemValue() - e.encodeValue(mapGet(rv, mksv[i].r, rvv, mparams), valFn) - } - default: - if rtkey == timeTyp { - mksv := make([]timeRv, len(mks)) - for i, k := range mks { - v := &mksv[i] - v.r = k - v.v = rv2i(k).(time.Time) - } - slices.SortFunc(mksv, cmpTimeRv) - for i := range mksv { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeTime(mksv[i].v) - e.mapElemValue() - e.encodeValue(mapGet(rv, mksv[i].r, rvv, mparams), valFn) - } - break - } - - bs0 := e.blist.get(len(mks) * 16) - mksv := bs0 - mksbv := make([]bytesRv, len(mks)) - - sideEncode(e.hh, &e.h.sideEncPool, func(se encoderI) { - se.ResetBytes(&mksv) - for i, k := range mks { - v := &mksbv[i] - l := len(mksv) - se.setContainerState(containerMapKey) - se.encodeR(baseRVRV(k)) - se.atEndOfEncode() - se.writerEnd() - v.r = k - v.v = mksv[l:] - } - }) - - slices.SortFunc(mksbv, cmpBytesRv) - for j := range mksbv { - e.c = containerMapKey - e.e.WriteMapElemKey(j == 0) - e.e.writeBytesAsis(mksbv[j].v) - e.mapElemValue() - e.encodeValue(mapGet(rv, mksbv[j].r, rvv, mparams), valFn) - } - e.blist.put(mksv) - if !byteSliceSameData(bs0, mksv) { - e.blist.put(bs0) - } - } -} - -func (e *encoderJsonBytes) init(h Handle) { - initHandle(h) - callMake(&e.e) - e.hh = h - e.h = h.getBasicHandle() - - e.err = errEncoderNotInitialized - - e.fp = e.e.init(h, &e.encoderBase, e).(*fastpathEsJsonBytes) - - if e.bytes { - e.rtidFn = &e.h.rtidFnsEncBytes - e.rtidFnNoExt = &e.h.rtidFnsEncNoExtBytes - } else { - e.rtidFn = &e.h.rtidFnsEncIO - e.rtidFnNoExt = &e.h.rtidFnsEncNoExtIO - } - - e.reset() -} - -func (e *encoderJsonBytes) reset() { - e.e.reset() - if e.ci != nil { - e.ci = e.ci[:0] - } - e.c = 0 - e.calls = 0 - e.seq = 0 - e.err = nil -} - -func (e *encoderJsonBytes) Encode(v interface{}) (err error) { - - defer panicValToErr(e, callRecoverSentinel, &e.err, &err, debugging) - e.mustEncode(v) - return -} - -func (e *encoderJsonBytes) MustEncode(v interface{}) { - defer panicValToErr(e, callRecoverSentinel, &e.err, nil, true) - e.mustEncode(v) - return -} - -func (e *encoderJsonBytes) mustEncode(v interface{}) { - halt.onerror(e.err) - if e.hh == nil { - halt.onerror(errNoFormatHandle) - } - - e.calls++ - if !e.encodeBuiltin(v) { - e.encodeR(reflect.ValueOf(v)) - } - - e.calls-- - if e.calls == 0 { - e.e.atEndOfEncode() - e.e.writerEnd() - } -} - -func (e *encoderJsonBytes) encodeI(iv interface{}) { - if !e.encodeBuiltin(iv) { - e.encodeR(reflect.ValueOf(iv)) - } -} - -func (e *encoderJsonBytes) encodeIB(iv interface{}) { - if !e.encodeBuiltin(iv) { - - halt.errorStr("[should not happen] invalid type passed to encodeBuiltin") - } -} - -func (e *encoderJsonBytes) encodeR(base reflect.Value) { - e.encodeValue(base, nil) -} - -func (e *encoderJsonBytes) encodeBuiltin(iv interface{}) (ok bool) { - ok = true - switch v := iv.(type) { - case nil: - e.e.EncodeNil() - - case Raw: - e.rawBytes(v) - case string: - e.e.EncodeString(v) - case bool: - e.e.EncodeBool(v) - case int: - e.e.EncodeInt(int64(v)) - case int8: - e.e.EncodeInt(int64(v)) - case int16: - e.e.EncodeInt(int64(v)) - case int32: - e.e.EncodeInt(int64(v)) - case int64: - e.e.EncodeInt(v) - case uint: - e.e.EncodeUint(uint64(v)) - case uint8: - e.e.EncodeUint(uint64(v)) - case uint16: - e.e.EncodeUint(uint64(v)) - case uint32: - e.e.EncodeUint(uint64(v)) - case uint64: - e.e.EncodeUint(v) - case uintptr: - e.e.EncodeUint(uint64(v)) - case float32: - e.e.EncodeFloat32(v) - case float64: - e.e.EncodeFloat64(v) - case complex64: - e.encodeComplex64(v) - case complex128: - e.encodeComplex128(v) - case time.Time: - e.e.EncodeTime(v) - case []byte: - e.e.EncodeBytes(v) - default: - - ok = !skipFastpathTypeSwitchInDirectCall && e.dh.fastpathEncodeTypeSwitch(iv, e) - } - return -} - -func (e *encoderJsonBytes) encodeValue(rv reflect.Value, fn *encFnJsonBytes) { - - var ciPushes int - - var rvp reflect.Value - var rvpValid bool - -RV: - switch rv.Kind() { - case reflect.Ptr: - if rvIsNil(rv) { - e.e.EncodeNil() - goto END - } - rvpValid = true - rvp = rv - rv = rv.Elem() - - if e.h.CheckCircularRef && e.ci.canPushElemKind(rv.Kind()) { - e.ci.push(rv2i(rvp)) - ciPushes++ - } - goto RV - case reflect.Interface: - if rvIsNil(rv) { - e.e.EncodeNil() - goto END - } - rvpValid = false - rvp = reflect.Value{} - rv = rv.Elem() - fn = nil - goto RV - case reflect.Map: - if rvIsNil(rv) { - if e.h.NilCollectionToZeroLength { - e.e.WriteMapEmpty() - } else { - e.e.EncodeNil() - } - goto END - } - case reflect.Slice, reflect.Chan: - if rvIsNil(rv) { - if e.h.NilCollectionToZeroLength { - e.e.WriteArrayEmpty() - } else { - e.e.EncodeNil() - } - goto END - } - case reflect.Invalid, reflect.Func: - e.e.EncodeNil() - goto END - } - - if fn == nil { - fn = e.fn(rv.Type()) - } - - if !fn.i.addrE { - - } else if rvpValid { - rv = rvp - } else if rv.CanAddr() { - rv = rvAddr(rv, fn.i.ti.ptr) - } else { - rv = e.addrRV(rv, fn.i.ti.rt, fn.i.ti.ptr) - } - fn.fe(e, &fn.i, rv) - -END: - if ciPushes > 0 { - e.ci.pop(ciPushes) - } -} - -func (e *encoderJsonBytes) encodeValueNonNil(rv reflect.Value, fn *encFnJsonBytes) { - - if fn.i.addrE { - if rv.CanAddr() { - rv = rvAddr(rv, fn.i.ti.ptr) - } else { - rv = e.addrRV(rv, fn.i.ti.rt, fn.i.ti.ptr) - } - } - fn.fe(e, &fn.i, rv) -} - -func (e *encoderJsonBytes) encodeAs(v interface{}, t reflect.Type, ext bool) { - if ext { - e.encodeValue(baseRV(v), e.fn(t)) - } else { - e.encodeValue(baseRV(v), e.fnNoExt(t)) - } -} - -func (e *encoderJsonBytes) marshalUtf8(bs []byte, fnerr error) { - halt.onerror(fnerr) - if bs == nil { - e.e.EncodeNil() - } else { - e.e.EncodeString(stringView(bs)) - } -} - -func (e *encoderJsonBytes) marshalAsis(bs []byte, fnerr error) { - halt.onerror(fnerr) - if bs == nil { - e.e.EncodeNil() - } else { - e.e.writeBytesAsis(bs) - } -} - -func (e *encoderJsonBytes) marshalRaw(bs []byte, fnerr error) { - halt.onerror(fnerr) - e.e.EncodeBytes(bs) -} - -func (e *encoderJsonBytes) rawBytes(vv Raw) { - v := []byte(vv) - if !e.h.Raw { - halt.errorBytes("Raw values cannot be encoded: ", v) - } - e.e.writeBytesAsis(v) -} - -func (e *encoderJsonBytes) fn(t reflect.Type) *encFnJsonBytes { - return e.dh.encFnViaBH(t, e.rtidFn, e.h, e.fp, false) -} - -func (e *encoderJsonBytes) fnNoExt(t reflect.Type) *encFnJsonBytes { - return e.dh.encFnViaBH(t, e.rtidFnNoExt, e.h, e.fp, true) -} - -func (e *encoderJsonBytes) mapStart(length int) { - e.e.WriteMapStart(length) - e.c = containerMapStart -} - -func (e *encoderJsonBytes) mapElemValue() { - e.e.WriteMapElemValue() - e.c = containerMapValue -} - -func (e *encoderJsonBytes) arrayStart(length int) { - e.e.WriteArrayStart(length) - e.c = containerArrayStart -} - -func (e *encoderJsonBytes) writerEnd() { - e.e.writerEnd() -} - -func (e *encoderJsonBytes) atEndOfEncode() { - e.e.atEndOfEncode() -} - -func (e *encoderJsonBytes) Reset(w io.Writer) { - if e.bytes { - halt.onerror(errEncNoResetBytesWithWriter) - } - e.reset() - if w == nil { - w = io.Discard - } - e.e.resetOutIO(w) -} - -func (e *encoderJsonBytes) ResetBytes(out *[]byte) { - if !e.bytes { - halt.onerror(errEncNoResetWriterWithBytes) - } - e.resetBytes(out) -} - -func (e *encoderJsonBytes) resetBytes(out *[]byte) { - e.reset() - if out == nil { - out = &bytesEncAppenderDefOut - } - e.e.resetOutBytes(out) -} - -func (helperEncDriverJsonBytes) newEncoderBytes(out *[]byte, h Handle) *encoderJsonBytes { - var c1 encoderJsonBytes - c1.bytes = true - c1.init(h) - c1.ResetBytes(out) - return &c1 -} - -func (helperEncDriverJsonBytes) newEncoderIO(out io.Writer, h Handle) *encoderJsonBytes { - var c1 encoderJsonBytes - c1.bytes = false - c1.init(h) - c1.Reset(out) - return &c1 -} - -func (helperEncDriverJsonBytes) encFnloadFastpathUnderlying(ti *typeInfo, fp *fastpathEsJsonBytes) (f *fastpathEJsonBytes, u reflect.Type) { - rtid := rt2id(ti.fastpathUnderlying) - idx, ok := fastpathAvIndex(rtid) - if !ok { - return - } - f = &fp[idx] - if uint8(reflect.Array) == ti.kind { - u = reflect.ArrayOf(ti.rt.Len(), ti.elem) - } else { - u = f.rt - } - return -} - -func (helperEncDriverJsonBytes) encFindRtidFn(s []encRtidFnJsonBytes, rtid uintptr) (i uint, fn *encFnJsonBytes) { - - var h uint - var j = uint(len(s)) -LOOP: - if i < j { - h = (i + j) >> 1 - if s[h].rtid < rtid { - i = h + 1 - } else { - j = h - } - goto LOOP - } - if i < uint(len(s)) && s[i].rtid == rtid { - fn = s[i].fn - } - return -} - -func (helperEncDriverJsonBytes) encFromRtidFnSlice(fns *atomicRtidFnSlice) (s []encRtidFnJsonBytes) { - if v := fns.load(); v != nil { - s = *(lowLevelToPtr[[]encRtidFnJsonBytes](v)) - } - return -} - -func (dh helperEncDriverJsonBytes) encFnViaBH(rt reflect.Type, fns *atomicRtidFnSlice, - x *BasicHandle, fp *fastpathEsJsonBytes, checkExt bool) (fn *encFnJsonBytes) { - return dh.encFnVia(rt, fns, x.typeInfos(), &x.mu, x.extHandle, fp, - checkExt, x.CheckCircularRef, x.timeBuiltin, x.binaryHandle, x.jsonHandle) -} - -func (dh helperEncDriverJsonBytes) encFnVia(rt reflect.Type, fns *atomicRtidFnSlice, - tinfos *TypeInfos, mu *sync.Mutex, exth extHandle, fp *fastpathEsJsonBytes, - checkExt, checkCircularRef, timeBuiltin, binaryEncoding, json bool) (fn *encFnJsonBytes) { - rtid := rt2id(rt) - var sp []encRtidFnJsonBytes = dh.encFromRtidFnSlice(fns) - if sp != nil { - _, fn = dh.encFindRtidFn(sp, rtid) - } - if fn == nil { - fn = dh.encFnViaLoader(rt, rtid, fns, tinfos, mu, exth, fp, checkExt, checkCircularRef, timeBuiltin, binaryEncoding, json) - } - return -} - -func (dh helperEncDriverJsonBytes) encFnViaLoader(rt reflect.Type, rtid uintptr, fns *atomicRtidFnSlice, - tinfos *TypeInfos, mu *sync.Mutex, exth extHandle, fp *fastpathEsJsonBytes, - checkExt, checkCircularRef, timeBuiltin, binaryEncoding, json bool) (fn *encFnJsonBytes) { - - fn = dh.encFnLoad(rt, rtid, tinfos, exth, fp, checkExt, checkCircularRef, timeBuiltin, binaryEncoding, json) - var sp []encRtidFnJsonBytes - mu.Lock() - sp = dh.encFromRtidFnSlice(fns) - - if sp == nil { - sp = []encRtidFnJsonBytes{{rtid, fn}} - fns.store(ptrToLowLevel(&sp)) - } else { - idx, fn2 := dh.encFindRtidFn(sp, rtid) - if fn2 == nil { - sp2 := make([]encRtidFnJsonBytes, len(sp)+1) - copy(sp2[idx+1:], sp[idx:]) - copy(sp2, sp[:idx]) - sp2[idx] = encRtidFnJsonBytes{rtid, fn} - fns.store(ptrToLowLevel(&sp2)) - } - } - mu.Unlock() - return -} - -func (dh helperEncDriverJsonBytes) encFnLoad(rt reflect.Type, rtid uintptr, tinfos *TypeInfos, - exth extHandle, fp *fastpathEsJsonBytes, - checkExt, checkCircularRef, timeBuiltin, binaryEncoding, json bool) (fn *encFnJsonBytes) { - fn = new(encFnJsonBytes) - fi := &(fn.i) - ti := tinfos.get(rtid, rt) - fi.ti = ti - rk := reflect.Kind(ti.kind) - - if rtid == timeTypId && timeBuiltin { - fn.fe = (*encoderJsonBytes).kTime - } else if rtid == rawTypId { - fn.fe = (*encoderJsonBytes).raw - } else if rtid == rawExtTypId { - fn.fe = (*encoderJsonBytes).rawExt - fi.addrE = true - } else if xfFn := exth.getExt(rtid, checkExt); xfFn != nil { - fi.xfTag, fi.xfFn = xfFn.tag, xfFn.ext - fn.fe = (*encoderJsonBytes).ext - if rk == reflect.Struct || rk == reflect.Array { - fi.addrE = true - } - } else if ti.flagSelfer || ti.flagSelferPtr { - fn.fe = (*encoderJsonBytes).selferMarshal - fi.addrE = ti.flagSelferPtr - } else if supportMarshalInterfaces && binaryEncoding && - (ti.flagBinaryMarshaler || ti.flagBinaryMarshalerPtr) && - (ti.flagBinaryUnmarshaler || ti.flagBinaryUnmarshalerPtr) { - fn.fe = (*encoderJsonBytes).binaryMarshal - fi.addrE = ti.flagBinaryMarshalerPtr - } else if supportMarshalInterfaces && !binaryEncoding && json && - (ti.flagJsonMarshaler || ti.flagJsonMarshalerPtr) && - (ti.flagJsonUnmarshaler || ti.flagJsonUnmarshalerPtr) { - - fn.fe = (*encoderJsonBytes).jsonMarshal - fi.addrE = ti.flagJsonMarshalerPtr - } else if supportMarshalInterfaces && !binaryEncoding && - (ti.flagTextMarshaler || ti.flagTextMarshalerPtr) && - (ti.flagTextUnmarshaler || ti.flagTextUnmarshalerPtr) { - fn.fe = (*encoderJsonBytes).textMarshal - fi.addrE = ti.flagTextMarshalerPtr - } else { - if fastpathEnabled && (rk == reflect.Map || rk == reflect.Slice || rk == reflect.Array) { - - var rtid2 uintptr - if !ti.flagHasPkgPath { - rtid2 = rtid - if rk == reflect.Array { - rtid2 = rt2id(ti.key) - } - if idx, ok := fastpathAvIndex(rtid2); ok { - fn.fe = fp[idx].encfn - } - } else { - - xfe, xrt := dh.encFnloadFastpathUnderlying(ti, fp) - if xfe != nil { - xfnf := xfe.encfn - fn.fe = func(e *encoderJsonBytes, xf *encFnInfo, xrv reflect.Value) { - xfnf(e, xf, rvConvert(xrv, xrt)) - } - } - } - } - if fn.fe == nil { - switch rk { - case reflect.Bool: - fn.fe = (*encoderJsonBytes).kBool - case reflect.String: - - fn.fe = (*encoderJsonBytes).kString - case reflect.Int: - fn.fe = (*encoderJsonBytes).kInt - case reflect.Int8: - fn.fe = (*encoderJsonBytes).kInt8 - case reflect.Int16: - fn.fe = (*encoderJsonBytes).kInt16 - case reflect.Int32: - fn.fe = (*encoderJsonBytes).kInt32 - case reflect.Int64: - fn.fe = (*encoderJsonBytes).kInt64 - case reflect.Uint: - fn.fe = (*encoderJsonBytes).kUint - case reflect.Uint8: - fn.fe = (*encoderJsonBytes).kUint8 - case reflect.Uint16: - fn.fe = (*encoderJsonBytes).kUint16 - case reflect.Uint32: - fn.fe = (*encoderJsonBytes).kUint32 - case reflect.Uint64: - fn.fe = (*encoderJsonBytes).kUint64 - case reflect.Uintptr: - fn.fe = (*encoderJsonBytes).kUintptr - case reflect.Float32: - fn.fe = (*encoderJsonBytes).kFloat32 - case reflect.Float64: - fn.fe = (*encoderJsonBytes).kFloat64 - case reflect.Complex64: - fn.fe = (*encoderJsonBytes).kComplex64 - case reflect.Complex128: - fn.fe = (*encoderJsonBytes).kComplex128 - case reflect.Chan: - fn.fe = (*encoderJsonBytes).kChan - case reflect.Slice: - fn.fe = (*encoderJsonBytes).kSlice - case reflect.Array: - fn.fe = (*encoderJsonBytes).kArray - case reflect.Struct: - if ti.simple { - fn.fe = (*encoderJsonBytes).kStructSimple - } else { - fn.fe = (*encoderJsonBytes).kStruct - } - case reflect.Map: - fn.fe = (*encoderJsonBytes).kMap - case reflect.Interface: - - fn.fe = (*encoderJsonBytes).kErr - default: - - fn.fe = (*encoderJsonBytes).kErr - } - } - } - return -} -func (d *decoderJsonBytes) rawExt(f *decFnInfo, rv reflect.Value) { - d.d.DecodeRawExt(rv2i(rv).(*RawExt)) -} - -func (d *decoderJsonBytes) ext(f *decFnInfo, rv reflect.Value) { - d.d.DecodeExt(rv2i(rv), f.ti.rt, f.xfTag, f.xfFn) -} - -func (d *decoderJsonBytes) selferUnmarshal(_ *decFnInfo, rv reflect.Value) { - rv2i(rv).(Selfer).CodecDecodeSelf(&Decoder{d}) -} - -func (d *decoderJsonBytes) binaryUnmarshal(_ *decFnInfo, rv reflect.Value) { - bm := rv2i(rv).(encoding.BinaryUnmarshaler) - xbs, _ := d.d.DecodeBytes() - fnerr := bm.UnmarshalBinary(xbs) - halt.onerror(fnerr) -} - -func (d *decoderJsonBytes) textUnmarshal(_ *decFnInfo, rv reflect.Value) { - tm := rv2i(rv).(encoding.TextUnmarshaler) - fnerr := tm.UnmarshalText(bytesOKs(d.d.DecodeStringAsBytes())) - halt.onerror(fnerr) -} - -func (d *decoderJsonBytes) jsonUnmarshal(_ *decFnInfo, rv reflect.Value) { - d.jsonUnmarshalV(rv2i(rv).(jsonUnmarshaler)) -} - -func (d *decoderJsonBytes) jsonUnmarshalV(tm jsonUnmarshaler) { - - halt.onerror(tm.UnmarshalJSON(d.d.nextValueBytes())) -} - -func (d *decoderJsonBytes) kErr(_ *decFnInfo, rv reflect.Value) { - halt.errorf("unsupported decoding kind: %s, for %#v", rv.Kind(), rv) - -} - -func (d *decoderJsonBytes) raw(_ *decFnInfo, rv reflect.Value) { - rvSetBytes(rv, d.rawBytes()) -} - -func (d *decoderJsonBytes) kString(_ *decFnInfo, rv reflect.Value) { - rvSetString(rv, d.detach2Str(d.d.DecodeStringAsBytes())) -} - -func (d *decoderJsonBytes) kBool(_ *decFnInfo, rv reflect.Value) { - rvSetBool(rv, d.d.DecodeBool()) -} - -func (d *decoderJsonBytes) kTime(_ *decFnInfo, rv reflect.Value) { - rvSetTime(rv, d.d.DecodeTime()) -} - -func (d *decoderJsonBytes) kFloat32(_ *decFnInfo, rv reflect.Value) { - rvSetFloat32(rv, d.d.DecodeFloat32()) -} - -func (d *decoderJsonBytes) kFloat64(_ *decFnInfo, rv reflect.Value) { - rvSetFloat64(rv, d.d.DecodeFloat64()) -} - -func (d *decoderJsonBytes) kComplex64(_ *decFnInfo, rv reflect.Value) { - rvSetComplex64(rv, complex(d.d.DecodeFloat32(), 0)) -} - -func (d *decoderJsonBytes) kComplex128(_ *decFnInfo, rv reflect.Value) { - rvSetComplex128(rv, complex(d.d.DecodeFloat64(), 0)) -} - -func (d *decoderJsonBytes) kInt(_ *decFnInfo, rv reflect.Value) { - rvSetInt(rv, int(chkOvf.IntV(d.d.DecodeInt64(), intBitsize))) -} - -func (d *decoderJsonBytes) kInt8(_ *decFnInfo, rv reflect.Value) { - rvSetInt8(rv, int8(chkOvf.IntV(d.d.DecodeInt64(), 8))) -} - -func (d *decoderJsonBytes) kInt16(_ *decFnInfo, rv reflect.Value) { - rvSetInt16(rv, int16(chkOvf.IntV(d.d.DecodeInt64(), 16))) -} - -func (d *decoderJsonBytes) kInt32(_ *decFnInfo, rv reflect.Value) { - rvSetInt32(rv, int32(chkOvf.IntV(d.d.DecodeInt64(), 32))) -} - -func (d *decoderJsonBytes) kInt64(_ *decFnInfo, rv reflect.Value) { - rvSetInt64(rv, d.d.DecodeInt64()) -} - -func (d *decoderJsonBytes) kUint(_ *decFnInfo, rv reflect.Value) { - rvSetUint(rv, uint(chkOvf.UintV(d.d.DecodeUint64(), uintBitsize))) -} - -func (d *decoderJsonBytes) kUintptr(_ *decFnInfo, rv reflect.Value) { - rvSetUintptr(rv, uintptr(chkOvf.UintV(d.d.DecodeUint64(), uintBitsize))) -} - -func (d *decoderJsonBytes) kUint8(_ *decFnInfo, rv reflect.Value) { - rvSetUint8(rv, uint8(chkOvf.UintV(d.d.DecodeUint64(), 8))) -} - -func (d *decoderJsonBytes) kUint16(_ *decFnInfo, rv reflect.Value) { - rvSetUint16(rv, uint16(chkOvf.UintV(d.d.DecodeUint64(), 16))) -} - -func (d *decoderJsonBytes) kUint32(_ *decFnInfo, rv reflect.Value) { - rvSetUint32(rv, uint32(chkOvf.UintV(d.d.DecodeUint64(), 32))) -} - -func (d *decoderJsonBytes) kUint64(_ *decFnInfo, rv reflect.Value) { - rvSetUint64(rv, d.d.DecodeUint64()) -} - -func (d *decoderJsonBytes) kInterfaceNaked(f *decFnInfo) (rvn reflect.Value) { - - n := d.naked() - d.d.DecodeNaked() - - if decFailNonEmptyIntf && f.ti.numMeth > 0 { - halt.errorf("cannot decode non-nil codec value into nil %v (%v methods)", f.ti.rt, f.ti.numMeth) - } - - switch n.v { - case valueTypeMap: - mtid := d.mtid - if mtid == 0 { - if d.jsms { - mtid = mapStrIntfTypId - } else { - mtid = mapIntfIntfTypId - } - } - if mtid == mapStrIntfTypId { - var v2 map[string]interface{} - d.decode(&v2) - rvn = rv4iptr(&v2).Elem() - } else if mtid == mapIntfIntfTypId { - var v2 map[interface{}]interface{} - d.decode(&v2) - rvn = rv4iptr(&v2).Elem() - } else if d.mtr { - rvn = reflect.New(d.h.MapType) - d.decode(rv2i(rvn)) - rvn = rvn.Elem() - } else { - - rvn = rvZeroAddrK(d.h.MapType, reflect.Map) - d.decodeValue(rvn, nil) - } - case valueTypeArray: - if d.stid == 0 || d.stid == intfSliceTypId { - var v2 []interface{} - d.decode(&v2) - rvn = rv4iptr(&v2).Elem() - } else if d.str { - rvn = reflect.New(d.h.SliceType) - d.decode(rv2i(rvn)) - rvn = rvn.Elem() - } else { - rvn = rvZeroAddrK(d.h.SliceType, reflect.Slice) - d.decodeValue(rvn, nil) - } - if d.h.PreferArrayOverSlice { - rvn = rvGetArray4Slice(rvn) - } - case valueTypeExt: - tag, bytes := n.u, n.l - bfn := d.h.getExtForTag(tag) - var re = RawExt{Tag: tag} - if bytes == nil { - - if bfn == nil { - d.decode(&re.Value) - rvn = rv4iptr(&re).Elem() - } else if bfn.ext == SelfExt { - rvn = rvZeroAddrK(bfn.rt, bfn.rt.Kind()) - d.decodeValue(rvn, d.fnNoExt(bfn.rt)) - } else { - rvn = reflect.New(bfn.rt) - d.interfaceExtConvertAndDecode(rv2i(rvn), bfn.ext) - rvn = rvn.Elem() - } - } else { - - if bfn == nil { - re.setData(bytes, false) - rvn = rv4iptr(&re).Elem() - } else { - rvn = reflect.New(bfn.rt) - if bfn.ext == SelfExt { - sideDecode(d.hh, &d.h.sideDecPool, func(sd decoderI) { oneOffDecode(sd, rv2i(rvn), bytes, bfn.rt, true) }) - } else { - bfn.ext.ReadExt(rv2i(rvn), bytes) - } - rvn = rvn.Elem() - } - } - - if d.h.PreferPointerForStructOrArray && rvn.CanAddr() { - if rk := rvn.Kind(); rk == reflect.Array || rk == reflect.Struct { - rvn = rvn.Addr() - } - } - case valueTypeNil: - - case valueTypeInt: - rvn = n.ri() - case valueTypeUint: - rvn = n.ru() - case valueTypeFloat: - rvn = n.rf() - case valueTypeBool: - rvn = n.rb() - case valueTypeString, valueTypeSymbol: - rvn = n.rs() - case valueTypeBytes: - rvn = n.rl() - case valueTypeTime: - rvn = n.rt() - default: - halt.errorStr2("kInterfaceNaked: unexpected valueType: ", n.v.String()) - } - return -} - -func (d *decoderJsonBytes) kInterface(f *decFnInfo, rv reflect.Value) { - - isnilrv := rvIsNil(rv) - - var rvn reflect.Value - - if d.h.InterfaceReset { - - rvn = d.h.intf2impl(f.ti.rtid) - if !rvn.IsValid() { - rvn = d.kInterfaceNaked(f) - if rvn.IsValid() { - rvSetIntf(rv, rvn) - } else if !isnilrv { - decSetNonNilRV2Zero4Intf(rv) - } - return - } - } else if isnilrv { - - rvn = d.h.intf2impl(f.ti.rtid) - if !rvn.IsValid() { - rvn = d.kInterfaceNaked(f) - if rvn.IsValid() { - rvSetIntf(rv, rvn) - } - return - } - } else { - - rvn = rv.Elem() - } - - canDecode, _ := isDecodeable(rvn) - - if !canDecode { - rvn2 := d.oneShotAddrRV(rvn.Type(), rvn.Kind()) - rvSetDirect(rvn2, rvn) - rvn = rvn2 - } - - d.decodeValue(rvn, nil) - rvSetIntf(rv, rvn) -} - -func (d *decoderJsonBytes) kStructField(si *structFieldInfo, rv reflect.Value) { - if d.d.TryNil() { - rv = si.fieldNoAlloc(rv, true) - if rv.IsValid() { - decSetNonNilRV2Zero(rv) - } - } else if si.decBuiltin { - rv = rvAddr(si.fieldAlloc(rv), si.ptrTyp) - d.decode(rv2i(rv)) - } else { - fn := d.fn(si.baseTyp) - rv = si.fieldAlloc(rv) - if fn.i.addrD { - rv = rvAddr(rv, si.ptrTyp) - } - fn.fd(d, &fn.i, rv) - } -} - -func (d *decoderJsonBytes) kStructSimple(f *decFnInfo, rv reflect.Value) { - _ = d.d - ctyp := d.d.ContainerType() - ti := f.ti - if ctyp == valueTypeMap { - containerLen := d.mapStart(d.d.ReadMapStart()) - if containerLen == 0 { - d.mapEnd() - return - } - hasLen := containerLen >= 0 - var rvkencname []byte - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - sab, att := d.d.DecodeStringAsBytes() - rvkencname = d.usableStructFieldNameBytes(rvkencname, sab, att) - d.mapElemValue() - if si := ti.siForEncName(rvkencname); si != nil { - d.kStructField(si, rv) - } else { - d.structFieldNotFound(-1, stringView(rvkencname)) - } - } - d.mapEnd() - } else if ctyp == valueTypeArray { - containerLen := d.arrayStart(d.d.ReadArrayStart()) - if containerLen == 0 { - d.arrayEnd() - return - } - - tisfi := ti.sfi.source() - hasLen := containerLen >= 0 - - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.arrayElem(j == 0) - if j < len(tisfi) { - d.kStructField(tisfi[j], rv) - } else { - d.structFieldNotFound(j, "") - } - } - d.arrayEnd() - } else { - halt.onerror(errNeedMapOrArrayDecodeToStruct) - } -} - -func (d *decoderJsonBytes) kStruct(f *decFnInfo, rv reflect.Value) { - _ = d.d - ctyp := d.d.ContainerType() - ti := f.ti - var mf MissingFielder - if ti.flagMissingFielder { - mf = rv2i(rv).(MissingFielder) - } else if ti.flagMissingFielderPtr { - mf = rv2i(rvAddr(rv, ti.ptr)).(MissingFielder) - } - if ctyp == valueTypeMap { - containerLen := d.mapStart(d.d.ReadMapStart()) - if containerLen == 0 { - d.mapEnd() - return - } - hasLen := containerLen >= 0 - var name2 []byte - var rvkencname []byte - tkt := ti.keyType - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - - if tkt == valueTypeString { - sab, att := d.d.DecodeStringAsBytes() - rvkencname = d.usableStructFieldNameBytes(rvkencname, sab, att) - } else if tkt == valueTypeInt { - rvkencname = strconv.AppendInt(d.b[:0], d.d.DecodeInt64(), 10) - } else if tkt == valueTypeUint { - rvkencname = strconv.AppendUint(d.b[:0], d.d.DecodeUint64(), 10) - } else if tkt == valueTypeFloat { - rvkencname = strconv.AppendFloat(d.b[:0], d.d.DecodeFloat64(), 'f', -1, 64) - } else { - halt.errorStr2("invalid struct key type: ", ti.keyType.String()) - } - - d.mapElemValue() - if si := ti.siForEncName(rvkencname); si != nil { - d.kStructField(si, rv) - } else if mf != nil { - - name2 = append(name2[:0], rvkencname...) - var f interface{} - d.decode(&f) - if !mf.CodecMissingField(name2, f) && d.h.ErrorIfNoField { - halt.errorStr2("no matching struct field when decoding stream map with key: ", stringView(name2)) - } - } else { - d.structFieldNotFound(-1, stringView(rvkencname)) - } - } - d.mapEnd() - } else if ctyp == valueTypeArray { - containerLen := d.arrayStart(d.d.ReadArrayStart()) - if containerLen == 0 { - d.arrayEnd() - return - } - - tisfi := ti.sfi.source() - hasLen := containerLen >= 0 - - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.arrayElem(j == 0) - if j < len(tisfi) { - d.kStructField(tisfi[j], rv) - } else { - d.structFieldNotFound(j, "") - } - } - - d.arrayEnd() - } else { - halt.onerror(errNeedMapOrArrayDecodeToStruct) - } -} - -func (d *decoderJsonBytes) kSlice(f *decFnInfo, rv reflect.Value) { - _ = d.d - - ti := f.ti - rvCanset := rv.CanSet() - - ctyp := d.d.ContainerType() - if ctyp == valueTypeBytes || ctyp == valueTypeString { - - if !(ti.rtid == uint8SliceTypId || ti.elemkind == uint8(reflect.Uint8)) { - halt.errorf("bytes/string in stream must decode into slice/array of bytes, not %v", ti.rt) - } - rvbs := rvGetBytes(rv) - if rvCanset { - bs2, bst := d.decodeBytesInto(rvbs, false) - if bst != dBytesIntoParamOut { - rvSetBytes(rv, bs2) - } - } else { - - d.decodeBytesInto(rvbs[:len(rvbs):len(rvbs)], true) - } - return - } - - var containerLenS int - isArray := ctyp == valueTypeArray - if isArray { - containerLenS = d.arrayStart(d.d.ReadArrayStart()) - } else if ctyp == valueTypeMap { - containerLenS = d.mapStart(d.d.ReadMapStart()) * 2 - } else { - halt.errorStr2("decoding into a slice, expect map/array - got ", ctyp.String()) - } - - if containerLenS == 0 { - if rvCanset { - if rvIsNil(rv) { - rvSetDirect(rv, rvSliceZeroCap(ti.rt)) - } else { - rvSetSliceLen(rv, 0) - } - } - if isArray { - d.arrayEnd() - } else { - d.mapEnd() - } - return - } - - rtelem0Mut := !scalarBitset.isset(ti.elemkind) - rtelem := ti.elem - - for k := reflect.Kind(ti.elemkind); k == reflect.Ptr; k = rtelem.Kind() { - rtelem = rtelem.Elem() - } - - var fn *decFnJsonBytes - - var rvChanged bool - - var rv0 = rv - var rv9 reflect.Value - - rvlen := rvLenSlice(rv) - rvcap := rvCapSlice(rv) - maxInitLen := d.maxInitLen() - hasLen := containerLenS >= 0 - if hasLen { - if containerLenS > rvcap { - oldRvlenGtZero := rvlen > 0 - rvlen1 := int(decInferLen(containerLenS, maxInitLen, uint(ti.elemsize))) - if rvlen1 == rvlen { - } else if rvlen1 <= rvcap { - if rvCanset { - rvlen = rvlen1 - rvSetSliceLen(rv, rvlen) - } - } else if rvCanset { - rvlen = rvlen1 - rv, rvCanset = rvMakeSlice(rv, f.ti, rvlen, rvlen) - rvcap = rvlen - rvChanged = !rvCanset - } else { - halt.errorStr("cannot decode into non-settable slice") - } - if rvChanged && oldRvlenGtZero && rtelem0Mut { - rvCopySlice(rv, rv0, rtelem) - } - } else if containerLenS != rvlen { - if rvCanset { - rvlen = containerLenS - rvSetSliceLen(rv, rvlen) - } - } - } - - var elemReset = d.h.SliceElementReset - - var rtelemIsPtr bool - var rtelemElem reflect.Type - builtin := ti.tielem.flagDecBuiltin - if builtin { - rtelemIsPtr = ti.elemkind == uint8(reflect.Ptr) - if rtelemIsPtr { - rtelemElem = ti.elem.Elem() - } - } - - var j int - for ; d.containerNext(j, containerLenS, hasLen); j++ { - if j == 0 { - if rvIsNil(rv) { - if rvCanset { - rvlen = int(decInferLen(containerLenS, maxInitLen, uint(ti.elemsize))) - rv, rvCanset = rvMakeSlice(rv, f.ti, rvlen, rvlen) - rvcap = rvlen - rvChanged = !rvCanset - } else { - halt.errorStr("cannot decode into non-settable slice") - } - } - if fn == nil { - fn = d.fn(rtelem) - } - } - - if ctyp == valueTypeArray { - d.arrayElem(j == 0) - } else if j&1 == 0 { - d.mapElemKey(j == 0) - } else { - d.mapElemValue() - } - - if j >= rvlen { - - if rvlen < rvcap { - rvlen = rvcap - if rvCanset { - rvSetSliceLen(rv, rvlen) - } else if rvChanged { - rv = rvSlice(rv, rvlen) - } else { - halt.onerror(errExpandSliceCannotChange) - } - } else { - if !(rvCanset || rvChanged) { - halt.onerror(errExpandSliceCannotChange) - } - rv, rvcap, rvCanset = rvGrowSlice(rv, f.ti, rvcap, 1) - - rvlen = rvcap - rvChanged = !rvCanset - } - } - - rv9 = rvArrayIndex(rv, j, f.ti, true) - if elemReset { - rvSetZero(rv9) - } - if d.d.TryNil() { - rvSetZero(rv9) - } else if builtin { - if rtelemIsPtr { - if rvIsNil(rv9) { - rvSetDirect(rv9, reflect.New(rtelemElem)) - } - d.decode(rv2i(rv9)) - } else { - d.decode(rv2i(rvAddr(rv9, ti.tielem.ptr))) - } - } else { - d.decodeValueNoCheckNil(rv9, fn) - } - } - if j < rvlen { - if rvCanset { - rvSetSliceLen(rv, j) - } else if rvChanged { - rv = rvSlice(rv, j) - } - - } else if j == 0 && rvIsNil(rv) { - if rvCanset { - rv = rvSliceZeroCap(ti.rt) - rvCanset = false - rvChanged = true - } - } - if isArray { - d.arrayEnd() - } else { - d.mapEnd() - } - - if rvChanged { - rvSetDirect(rv0, rv) - } -} - -func (d *decoderJsonBytes) kArray(f *decFnInfo, rv reflect.Value) { - _ = d.d - - ti := f.ti - ctyp := d.d.ContainerType() - if handleBytesWithinKArray && (ctyp == valueTypeBytes || ctyp == valueTypeString) { - - if ti.elemkind != uint8(reflect.Uint8) { - halt.errorf("bytes/string in stream can decode into array of bytes, but not %v", ti.rt) - } - rvbs := rvGetArrayBytes(rv, nil) - d.decodeBytesInto(rvbs, true) - return - } - - var containerLenS int - isArray := ctyp == valueTypeArray - if isArray { - containerLenS = d.arrayStart(d.d.ReadArrayStart()) - } else if ctyp == valueTypeMap { - containerLenS = d.mapStart(d.d.ReadMapStart()) * 2 - } else { - halt.errorStr2("decoding into a slice, expect map/array - got ", ctyp.String()) - } - - if containerLenS == 0 { - if isArray { - d.arrayEnd() - } else { - d.mapEnd() - } - return - } - - rtelem := ti.elem - for k := reflect.Kind(ti.elemkind); k == reflect.Ptr; k = rtelem.Kind() { - rtelem = rtelem.Elem() - } - - var rv9 reflect.Value - - rvlen := rv.Len() - hasLen := containerLenS >= 0 - if hasLen && containerLenS > rvlen { - halt.errorf("cannot decode into array with length: %v, less than container length: %v", any(rvlen), any(containerLenS)) - } - - var elemReset = d.h.SliceElementReset - - var rtelemIsPtr bool - var rtelemElem reflect.Type - var fn *decFnJsonBytes - builtin := ti.tielem.flagDecBuiltin - if builtin { - rtelemIsPtr = ti.elemkind == uint8(reflect.Ptr) - if rtelemIsPtr { - rtelemElem = ti.elem.Elem() - } - } else { - fn = d.fn(rtelem) - } - - for j := 0; d.containerNext(j, containerLenS, hasLen); j++ { - if ctyp == valueTypeArray { - d.arrayElem(j == 0) - } else if j&1 == 0 { - d.mapElemKey(j == 0) - } else { - d.mapElemValue() - } - - if j >= rvlen { - d.arrayCannotExpand(rvlen, j+1) - d.swallow() - continue - } - - rv9 = rvArrayIndex(rv, j, f.ti, false) - if elemReset { - rvSetZero(rv9) - } - if d.d.TryNil() { - rvSetZero(rv9) - } else if builtin { - if rtelemIsPtr { - if rvIsNil(rv9) { - rvSetDirect(rv9, reflect.New(rtelemElem)) - } - d.decode(rv2i(rv9)) - } else { - d.decode(rv2i(rvAddr(rv9, ti.tielem.ptr))) - } - } else { - d.decodeValueNoCheckNil(rv9, fn) - } - } - if isArray { - d.arrayEnd() - } else { - d.mapEnd() - } -} - -func (d *decoderJsonBytes) kChan(f *decFnInfo, rv reflect.Value) { - _ = d.d - - ti := f.ti - if ti.chandir&uint8(reflect.SendDir) == 0 { - halt.errorStr("receive-only channel cannot be decoded") - } - ctyp := d.d.ContainerType() - if ctyp == valueTypeBytes || ctyp == valueTypeString { - - if !(ti.rtid == uint8SliceTypId || ti.elemkind == uint8(reflect.Uint8)) { - halt.errorf("bytes/string in stream must decode into slice/array of bytes, not %v", ti.rt) - } - bs2, _ := d.d.DecodeBytes() - irv := rv2i(rv) - ch, ok := irv.(chan<- byte) - if !ok { - ch = irv.(chan byte) - } - for _, b := range bs2 { - ch <- b - } - return - } - - var rvCanset = rv.CanSet() - - var containerLenS int - isArray := ctyp == valueTypeArray - if isArray { - containerLenS = d.arrayStart(d.d.ReadArrayStart()) - } else if ctyp == valueTypeMap { - containerLenS = d.mapStart(d.d.ReadMapStart()) * 2 - } else { - halt.errorStr2("decoding into a slice, expect map/array - got ", ctyp.String()) - } - - if containerLenS == 0 { - if rvCanset && rvIsNil(rv) { - rvSetDirect(rv, reflect.MakeChan(ti.rt, 0)) - } - if isArray { - d.arrayEnd() - } else { - d.mapEnd() - } - return - } - - rtelem := ti.elem - useTransient := decUseTransient && ti.elemkind != byte(reflect.Ptr) && ti.tielem.flagCanTransient - - for k := reflect.Kind(ti.elemkind); k == reflect.Ptr; k = rtelem.Kind() { - rtelem = rtelem.Elem() - } - - var fn *decFnJsonBytes - - var rvChanged bool - var rv0 = rv - var rv9 reflect.Value - - var rvlen int - hasLen := containerLenS >= 0 - maxInitLen := d.maxInitLen() - - for j := 0; d.containerNext(j, containerLenS, hasLen); j++ { - if j == 0 { - if rvIsNil(rv) { - if hasLen { - rvlen = int(decInferLen(containerLenS, maxInitLen, uint(ti.elemsize))) - } else { - rvlen = decDefChanCap - } - if rvCanset { - rv = reflect.MakeChan(ti.rt, rvlen) - rvChanged = true - } else { - halt.errorStr("cannot decode into non-settable chan") - } - } - if fn == nil { - fn = d.fn(rtelem) - } - } - - if ctyp == valueTypeArray { - d.arrayElem(j == 0) - } else if j&1 == 0 { - d.mapElemKey(j == 0) - } else { - d.mapElemValue() - } - - if rv9.IsValid() { - rvSetZero(rv9) - } else if useTransient { - rv9 = d.perType.TransientAddrK(ti.elem, reflect.Kind(ti.elemkind)) - } else { - rv9 = rvZeroAddrK(ti.elem, reflect.Kind(ti.elemkind)) - } - if !d.d.TryNil() { - d.decodeValueNoCheckNil(rv9, fn) - } - rv.Send(rv9) - } - if isArray { - d.arrayEnd() - } else { - d.mapEnd() - } - - if rvChanged { - rvSetDirect(rv0, rv) - } - -} - -func (d *decoderJsonBytes) kMap(f *decFnInfo, rv reflect.Value) { - _ = d.d - containerLen := d.mapStart(d.d.ReadMapStart()) - ti := f.ti - if rvIsNil(rv) { - rvlen := int(decInferLen(containerLen, d.maxInitLen(), uint(ti.keysize+ti.elemsize))) - rvSetDirect(rv, makeMapReflect(ti.rt, rvlen)) - } - - if containerLen == 0 { - d.mapEnd() - return - } - - ktype, vtype := ti.key, ti.elem - ktypeId := rt2id(ktype) - vtypeKind := reflect.Kind(ti.elemkind) - ktypeKind := reflect.Kind(ti.keykind) - mparams := getMapReqParams(ti) - - vtypePtr := vtypeKind == reflect.Ptr - ktypePtr := ktypeKind == reflect.Ptr - - vTransient := decUseTransient && !vtypePtr && ti.tielem.flagCanTransient - - kTransient := vTransient && !ktypePtr && ti.tikey.flagCanTransient - - var vtypeElem reflect.Type - - var keyFn, valFn *decFnJsonBytes - var ktypeLo, vtypeLo = ktype, vtype - - if ktypeKind == reflect.Ptr { - for ktypeLo = ktype.Elem(); ktypeLo.Kind() == reflect.Ptr; ktypeLo = ktypeLo.Elem() { - } - } - - if vtypePtr { - vtypeElem = vtype.Elem() - for vtypeLo = vtypeElem; vtypeLo.Kind() == reflect.Ptr; vtypeLo = vtypeLo.Elem() { - } - } - - rvkMut := !scalarBitset.isset(ti.keykind) - rvvMut := !scalarBitset.isset(ti.elemkind) - rvvCanNil := isnilBitset.isset(ti.elemkind) - - var rvk, rvkn, rvv, rvvn, rvva, rvvz reflect.Value - - var doMapGet, doMapSet bool - - if !d.h.MapValueReset { - if rvvMut && (vtypeKind != reflect.Interface || !d.h.InterfaceReset) { - doMapGet = true - rvva = mapAddrLoopvarRV(vtype, vtypeKind) - } - } - - ktypeIsString := ktypeId == stringTypId - ktypeIsIntf := ktypeId == intfTypId - hasLen := containerLen >= 0 - - var kstr2bs []byte - var kstr string - - var mapKeyStringSharesBytesBuf bool - var att dBytesAttachState - - var vElem, kElem reflect.Type - kbuiltin := ti.tikey.flagDecBuiltin && ti.keykind != uint8(reflect.Slice) - vbuiltin := ti.tielem.flagDecBuiltin - if kbuiltin && ktypePtr { - kElem = ti.key.Elem() - } - if vbuiltin && vtypePtr { - vElem = ti.elem.Elem() - } - - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - mapKeyStringSharesBytesBuf = false - kstr = "" - if j == 0 { - - if kTransient { - rvk = d.perType.TransientAddr2K(ktype, ktypeKind) - } else { - rvk = rvZeroAddrK(ktype, ktypeKind) - } - if !rvkMut { - rvkn = rvk - } - if !rvvMut { - if vTransient { - rvvn = d.perType.TransientAddrK(vtype, vtypeKind) - } else { - rvvn = rvZeroAddrK(vtype, vtypeKind) - } - } - if !ktypeIsString && keyFn == nil { - keyFn = d.fn(ktypeLo) - } - if valFn == nil { - valFn = d.fn(vtypeLo) - } - } else if rvkMut { - rvSetZero(rvk) - } else { - rvk = rvkn - } - - d.mapElemKey(j == 0) - - if d.d.TryNil() { - rvSetZero(rvk) - } else if ktypeIsString { - kstr2bs, att = d.d.DecodeStringAsBytes() - kstr, mapKeyStringSharesBytesBuf = d.bytes2Str(kstr2bs, att) - rvSetString(rvk, kstr) - } else { - if kbuiltin { - if ktypePtr { - if rvIsNil(rvk) { - rvSetDirect(rvk, reflect.New(kElem)) - } - d.decode(rv2i(rvk)) - } else { - d.decode(rv2i(rvAddr(rvk, ti.tikey.ptr))) - } - } else { - d.decodeValueNoCheckNil(rvk, keyFn) - } - - if ktypeIsIntf { - if rvk2 := rvk.Elem(); rvk2.IsValid() && rvk2.Type() == uint8SliceTyp { - kstr2bs = rvGetBytes(rvk2) - kstr, mapKeyStringSharesBytesBuf = d.bytes2Str(kstr2bs, dBytesAttachView) - rvSetIntf(rvk, rv4istr(kstr)) - } - - } - } - - if mapKeyStringSharesBytesBuf && d.bufio { - if ktypeIsString { - rvSetString(rvk, d.detach2Str(kstr2bs, att)) - } else { - rvSetIntf(rvk, rv4istr(d.detach2Str(kstr2bs, att))) - } - mapKeyStringSharesBytesBuf = false - } - - d.mapElemValue() - - if d.d.TryNil() { - if mapKeyStringSharesBytesBuf { - if ktypeIsString { - rvSetString(rvk, d.detach2Str(kstr2bs, att)) - } else { - rvSetIntf(rvk, rv4istr(d.detach2Str(kstr2bs, att))) - } - } - - if !rvvz.IsValid() { - rvvz = rvZeroK(vtype, vtypeKind) - } - mapSet(rv, rvk, rvvz, mparams) - continue - } - - doMapSet = true - - if !rvvMut { - rvv = rvvn - } else if !doMapGet { - goto NEW_RVV - } else { - rvv = mapGet(rv, rvk, rvva, mparams) - if !rvv.IsValid() || (rvvCanNil && rvIsNil(rvv)) { - goto NEW_RVV - } - switch vtypeKind { - case reflect.Ptr, reflect.Map: - doMapSet = false - case reflect.Interface: - - rvvn = rvv.Elem() - if k := rvvn.Kind(); (k == reflect.Ptr || k == reflect.Map) && !rvIsNil(rvvn) { - d.decodeValueNoCheckNil(rvvn, nil) - continue - } - - rvvn = rvZeroAddrK(vtype, vtypeKind) - rvSetIntf(rvvn, rvv) - rvv = rvvn - default: - - if vTransient { - rvvn = d.perType.TransientAddrK(vtype, vtypeKind) - } else { - rvvn = rvZeroAddrK(vtype, vtypeKind) - } - rvSetDirect(rvvn, rvv) - rvv = rvvn - } - } - goto DECODE_VALUE_NO_CHECK_NIL - - NEW_RVV: - if vtypePtr { - rvv = reflect.New(vtypeElem) - } else if vTransient { - rvv = d.perType.TransientAddrK(vtype, vtypeKind) - } else { - rvv = rvZeroAddrK(vtype, vtypeKind) - } - - DECODE_VALUE_NO_CHECK_NIL: - if doMapSet && mapKeyStringSharesBytesBuf { - if ktypeIsString { - rvSetString(rvk, d.detach2Str(kstr2bs, att)) - } else { - rvSetIntf(rvk, rv4istr(d.detach2Str(kstr2bs, att))) - } - } - if vbuiltin { - if vtypePtr { - if rvIsNil(rvv) { - rvSetDirect(rvv, reflect.New(vElem)) - } - d.decode(rv2i(rvv)) - } else { - d.decode(rv2i(rvAddr(rvv, ti.tielem.ptr))) - } - } else { - d.decodeValueNoCheckNil(rvv, valFn) - } - if doMapSet { - mapSet(rv, rvk, rvv, mparams) - } - } - - d.mapEnd() -} - -func (d *decoderJsonBytes) init(h Handle) { - initHandle(h) - callMake(&d.d) - d.hh = h - d.h = h.getBasicHandle() - - d.err = errDecoderNotInitialized - - if d.h.InternString && d.is == nil { - d.is.init() - } - - d.fp = d.d.init(h, &d.decoderBase, d).(*fastpathDsJsonBytes) - - if d.bytes { - d.rtidFn = &d.h.rtidFnsDecBytes - d.rtidFnNoExt = &d.h.rtidFnsDecNoExtBytes - } else { - d.bufio = d.h.ReaderBufferSize > 0 - d.rtidFn = &d.h.rtidFnsDecIO - d.rtidFnNoExt = &d.h.rtidFnsDecNoExtIO - } - - d.reset() - -} - -func (d *decoderJsonBytes) reset() { - d.d.reset() - d.err = nil - d.c = 0 - d.depth = 0 - d.calls = 0 - - d.maxdepth = decDefMaxDepth - if d.h.MaxDepth > 0 { - d.maxdepth = d.h.MaxDepth - } - d.mtid = 0 - d.stid = 0 - d.mtr = false - d.str = false - if d.h.MapType != nil { - d.mtid = rt2id(d.h.MapType) - _, d.mtr = fastpathAvIndex(d.mtid) - } - if d.h.SliceType != nil { - d.stid = rt2id(d.h.SliceType) - _, d.str = fastpathAvIndex(d.stid) - } -} - -func (d *decoderJsonBytes) Reset(r io.Reader) { - if d.bytes { - halt.onerror(errDecNoResetBytesWithReader) - } - d.reset() - if r == nil { - r = &eofReader - } - d.d.resetInIO(r) -} - -func (d *decoderJsonBytes) ResetBytes(in []byte) { - if !d.bytes { - halt.onerror(errDecNoResetReaderWithBytes) - } - d.resetBytes(in) -} - -func (d *decoderJsonBytes) resetBytes(in []byte) { - d.reset() - if in == nil { - in = zeroByteSlice - } - d.d.resetInBytes(in) -} - -func (d *decoderJsonBytes) ResetString(s string) { - d.ResetBytes(bytesView(s)) -} - -func (d *decoderJsonBytes) Decode(v interface{}) (err error) { - - defer panicValToErr(d, callRecoverSentinel, &d.err, &err, debugging) - d.mustDecode(v) - return -} - -func (d *decoderJsonBytes) MustDecode(v interface{}) { - defer panicValToErr(d, callRecoverSentinel, &d.err, nil, true) - d.mustDecode(v) - return -} - -func (d *decoderJsonBytes) mustDecode(v interface{}) { - halt.onerror(d.err) - if d.hh == nil { - halt.onerror(errNoFormatHandle) - } - - d.calls++ - d.decode(v) - d.calls-- -} - -func (d *decoderJsonBytes) Release() {} - -func (d *decoderJsonBytes) swallow() { - d.d.nextValueBytes() -} - -func (d *decoderJsonBytes) nextValueBytes() []byte { - return d.d.nextValueBytes() -} - -func (d *decoderJsonBytes) decode(iv interface{}) { - _ = d.d - - rv, ok := isNil(iv, true) - if ok { - halt.onerror(errCannotDecodeIntoNil) - } - - switch v := iv.(type) { - - case *string: - *v = d.detach2Str(d.d.DecodeStringAsBytes()) - case *bool: - *v = d.d.DecodeBool() - case *int: - *v = int(chkOvf.IntV(d.d.DecodeInt64(), intBitsize)) - case *int8: - *v = int8(chkOvf.IntV(d.d.DecodeInt64(), 8)) - case *int16: - *v = int16(chkOvf.IntV(d.d.DecodeInt64(), 16)) - case *int32: - *v = int32(chkOvf.IntV(d.d.DecodeInt64(), 32)) - case *int64: - *v = d.d.DecodeInt64() - case *uint: - *v = uint(chkOvf.UintV(d.d.DecodeUint64(), uintBitsize)) - case *uint8: - *v = uint8(chkOvf.UintV(d.d.DecodeUint64(), 8)) - case *uint16: - *v = uint16(chkOvf.UintV(d.d.DecodeUint64(), 16)) - case *uint32: - *v = uint32(chkOvf.UintV(d.d.DecodeUint64(), 32)) - case *uint64: - *v = d.d.DecodeUint64() - case *uintptr: - *v = uintptr(chkOvf.UintV(d.d.DecodeUint64(), uintBitsize)) - case *float32: - *v = d.d.DecodeFloat32() - case *float64: - *v = d.d.DecodeFloat64() - case *complex64: - *v = complex(d.d.DecodeFloat32(), 0) - case *complex128: - *v = complex(d.d.DecodeFloat64(), 0) - case *[]byte: - *v, _ = d.decodeBytesInto(*v, false) - case []byte: - - d.decodeBytesInto(v[:len(v):len(v)], true) - case *time.Time: - *v = d.d.DecodeTime() - case *Raw: - *v = d.rawBytes() - - case *interface{}: - d.decodeValue(rv4iptr(v), nil) - - case reflect.Value: - if ok, _ = isDecodeable(v); !ok { - d.haltAsNotDecodeable(v) - } - d.decodeValue(v, nil) - - default: - - if skipFastpathTypeSwitchInDirectCall || !d.dh.fastpathDecodeTypeSwitch(iv, d) { - if !rv.IsValid() { - rv = reflect.ValueOf(iv) - } - if ok, _ = isDecodeable(rv); !ok { - d.haltAsNotDecodeable(rv) - } - d.decodeValue(rv, nil) - } - } -} - -func (d *decoderJsonBytes) decodeValue(rv reflect.Value, fn *decFnJsonBytes) { - if d.d.TryNil() { - decSetNonNilRV2Zero(rv) - } else { - d.decodeValueNoCheckNil(rv, fn) - } -} - -func (d *decoderJsonBytes) decodeValueNoCheckNil(rv reflect.Value, fn *decFnJsonBytes) { - - var rvp reflect.Value - var rvpValid bool -PTR: - if rv.Kind() == reflect.Ptr { - rvpValid = true - if rvIsNil(rv) { - rvSetDirect(rv, reflect.New(rv.Type().Elem())) - } - rvp = rv - rv = rv.Elem() - goto PTR - } - - if fn == nil { - fn = d.fn(rv.Type()) - } - if fn.i.addrD { - if rvpValid { - rv = rvp - } else if rv.CanAddr() { - rv = rvAddr(rv, fn.i.ti.ptr) - } else if fn.i.addrDf { - halt.errorStr("cannot decode into a non-pointer value") - } - } - fn.fd(d, &fn.i, rv) -} - -func (d *decoderJsonBytes) decodeAs(v interface{}, t reflect.Type, ext bool) { - if ext { - d.decodeValue(baseRV(v), d.fn(t)) - } else { - d.decodeValue(baseRV(v), d.fnNoExt(t)) - } -} - -func (d *decoderJsonBytes) structFieldNotFound(index int, rvkencname string) { - - if d.h.ErrorIfNoField { - if index >= 0 { - halt.errorInt("no matching struct field found when decoding stream array at index ", int64(index)) - } else if rvkencname != "" { - halt.errorStr2("no matching struct field found when decoding stream map with key ", rvkencname) - } - } - d.swallow() -} - -func (d *decoderJsonBytes) decodeBytesInto(out []byte, mustFit bool) (v []byte, state dBytesIntoState) { - v, att := d.d.DecodeBytes() - if cap(v) == 0 || (att >= dBytesAttachViewZerocopy && !mustFit) { - - return - } - if len(v) == 0 { - v = zeroByteSlice - return - } - if len(out) == len(v) { - state = dBytesIntoParamOut - } else if cap(out) >= len(v) { - out = out[:len(v)] - state = dBytesIntoParamOutSlice - } else if mustFit { - halt.errorf("bytes capacity insufficient for decoded bytes: got/expected: %d/%d", len(v), len(out)) - } else { - out = make([]byte, len(v)) - state = dBytesIntoNew - } - copy(out, v) - v = out - return -} - -func (d *decoderJsonBytes) rawBytes() (v []byte) { - - v = d.d.nextValueBytes() - if d.bytes && !d.h.ZeroCopy { - vv := make([]byte, len(v)) - copy(vv, v) - v = vv - } - return -} - -func (d *decoderJsonBytes) wrapErr(v error, err *error) { - *err = wrapCodecErr(v, d.hh.Name(), d.d.NumBytesRead(), false) -} - -func (d *decoderJsonBytes) NumBytesRead() int { - return d.d.NumBytesRead() -} - -func (d *decoderJsonBytes) containerNext(j, containerLen int, hasLen bool) bool { - - if hasLen { - return j < containerLen - } - return !d.d.CheckBreak() -} - -func (d *decoderJsonBytes) mapElemKey(firstTime bool) { - d.d.ReadMapElemKey(firstTime) - d.c = containerMapKey -} - -func (d *decoderJsonBytes) mapElemValue() { - d.d.ReadMapElemValue() - d.c = containerMapValue -} - -func (d *decoderJsonBytes) mapEnd() { - d.d.ReadMapEnd() - d.depthDecr() - d.c = 0 -} - -func (d *decoderJsonBytes) arrayElem(firstTime bool) { - d.d.ReadArrayElem(firstTime) - d.c = containerArrayElem -} - -func (d *decoderJsonBytes) arrayEnd() { - d.d.ReadArrayEnd() - d.depthDecr() - d.c = 0 -} - -func (d *decoderJsonBytes) interfaceExtConvertAndDecode(v interface{}, ext InterfaceExt) { - - var vv interface{} - d.decode(&vv) - ext.UpdateExt(v, vv) - -} - -func (d *decoderJsonBytes) fn(t reflect.Type) *decFnJsonBytes { - return d.dh.decFnViaBH(t, d.rtidFn, d.h, d.fp, false) -} - -func (d *decoderJsonBytes) fnNoExt(t reflect.Type) *decFnJsonBytes { - return d.dh.decFnViaBH(t, d.rtidFnNoExt, d.h, d.fp, true) -} - -func (helperDecDriverJsonBytes) newDecoderBytes(in []byte, h Handle) *decoderJsonBytes { - var c1 decoderJsonBytes - c1.bytes = true - c1.init(h) - c1.ResetBytes(in) - return &c1 -} - -func (helperDecDriverJsonBytes) newDecoderIO(in io.Reader, h Handle) *decoderJsonBytes { - var c1 decoderJsonBytes - c1.init(h) - c1.Reset(in) - return &c1 -} - -func (helperDecDriverJsonBytes) decFnloadFastpathUnderlying(ti *typeInfo, fp *fastpathDsJsonBytes) (f *fastpathDJsonBytes, u reflect.Type) { - rtid := rt2id(ti.fastpathUnderlying) - idx, ok := fastpathAvIndex(rtid) - if !ok { - return - } - f = &fp[idx] - if uint8(reflect.Array) == ti.kind { - u = reflect.ArrayOf(ti.rt.Len(), ti.elem) - } else { - u = f.rt - } - return -} - -func (helperDecDriverJsonBytes) decFindRtidFn(s []decRtidFnJsonBytes, rtid uintptr) (i uint, fn *decFnJsonBytes) { - - var h uint - var j = uint(len(s)) -LOOP: - if i < j { - h = (i + j) >> 1 - if s[h].rtid < rtid { - i = h + 1 - } else { - j = h - } - goto LOOP - } - if i < uint(len(s)) && s[i].rtid == rtid { - fn = s[i].fn - } - return -} - -func (helperDecDriverJsonBytes) decFromRtidFnSlice(fns *atomicRtidFnSlice) (s []decRtidFnJsonBytes) { - if v := fns.load(); v != nil { - s = *(lowLevelToPtr[[]decRtidFnJsonBytes](v)) - } - return -} - -func (dh helperDecDriverJsonBytes) decFnViaBH(rt reflect.Type, fns *atomicRtidFnSlice, x *BasicHandle, fp *fastpathDsJsonBytes, - checkExt bool) (fn *decFnJsonBytes) { - return dh.decFnVia(rt, fns, x.typeInfos(), &x.mu, x.extHandle, fp, - checkExt, x.CheckCircularRef, x.timeBuiltin, x.binaryHandle, x.jsonHandle) -} - -func (dh helperDecDriverJsonBytes) decFnVia(rt reflect.Type, fns *atomicRtidFnSlice, - tinfos *TypeInfos, mu *sync.Mutex, exth extHandle, fp *fastpathDsJsonBytes, - checkExt, checkCircularRef, timeBuiltin, binaryEncoding, json bool) (fn *decFnJsonBytes) { - rtid := rt2id(rt) - var sp []decRtidFnJsonBytes = dh.decFromRtidFnSlice(fns) - if sp != nil { - _, fn = dh.decFindRtidFn(sp, rtid) - } - if fn == nil { - fn = dh.decFnViaLoader(rt, rtid, fns, tinfos, mu, exth, fp, checkExt, checkCircularRef, timeBuiltin, binaryEncoding, json) - } - return -} - -func (dh helperDecDriverJsonBytes) decFnViaLoader(rt reflect.Type, rtid uintptr, fns *atomicRtidFnSlice, - tinfos *TypeInfos, mu *sync.Mutex, exth extHandle, fp *fastpathDsJsonBytes, - checkExt, checkCircularRef, timeBuiltin, binaryEncoding, json bool) (fn *decFnJsonBytes) { - - fn = dh.decFnLoad(rt, rtid, tinfos, exth, fp, checkExt, checkCircularRef, timeBuiltin, binaryEncoding, json) - var sp []decRtidFnJsonBytes - mu.Lock() - sp = dh.decFromRtidFnSlice(fns) - - if sp == nil { - sp = []decRtidFnJsonBytes{{rtid, fn}} - fns.store(ptrToLowLevel(&sp)) - } else { - idx, fn2 := dh.decFindRtidFn(sp, rtid) - if fn2 == nil { - sp2 := make([]decRtidFnJsonBytes, len(sp)+1) - copy(sp2[idx+1:], sp[idx:]) - copy(sp2, sp[:idx]) - sp2[idx] = decRtidFnJsonBytes{rtid, fn} - fns.store(ptrToLowLevel(&sp2)) - } - } - mu.Unlock() - return -} - -func (dh helperDecDriverJsonBytes) decFnLoad(rt reflect.Type, rtid uintptr, tinfos *TypeInfos, - exth extHandle, fp *fastpathDsJsonBytes, - checkExt, checkCircularRef, timeBuiltin, binaryEncoding, json bool) (fn *decFnJsonBytes) { - fn = new(decFnJsonBytes) - fi := &(fn.i) - ti := tinfos.get(rtid, rt) - fi.ti = ti - rk := reflect.Kind(ti.kind) - - fi.addrDf = true - - if rtid == timeTypId && timeBuiltin { - fn.fd = (*decoderJsonBytes).kTime - } else if rtid == rawTypId { - fn.fd = (*decoderJsonBytes).raw - } else if rtid == rawExtTypId { - fn.fd = (*decoderJsonBytes).rawExt - fi.addrD = true - } else if xfFn := exth.getExt(rtid, checkExt); xfFn != nil { - fi.xfTag, fi.xfFn = xfFn.tag, xfFn.ext - fn.fd = (*decoderJsonBytes).ext - fi.addrD = true - } else if ti.flagSelfer || ti.flagSelferPtr { - fn.fd = (*decoderJsonBytes).selferUnmarshal - fi.addrD = ti.flagSelferPtr - } else if supportMarshalInterfaces && binaryEncoding && - (ti.flagBinaryMarshaler || ti.flagBinaryMarshalerPtr) && - (ti.flagBinaryUnmarshaler || ti.flagBinaryUnmarshalerPtr) { - fn.fd = (*decoderJsonBytes).binaryUnmarshal - fi.addrD = ti.flagBinaryUnmarshalerPtr - } else if supportMarshalInterfaces && !binaryEncoding && json && - (ti.flagJsonMarshaler || ti.flagJsonMarshalerPtr) && - (ti.flagJsonUnmarshaler || ti.flagJsonUnmarshalerPtr) { - - fn.fd = (*decoderJsonBytes).jsonUnmarshal - fi.addrD = ti.flagJsonUnmarshalerPtr - } else if supportMarshalInterfaces && !binaryEncoding && - (ti.flagTextMarshaler || ti.flagTextMarshalerPtr) && - (ti.flagTextUnmarshaler || ti.flagTextUnmarshalerPtr) { - fn.fd = (*decoderJsonBytes).textUnmarshal - fi.addrD = ti.flagTextUnmarshalerPtr - } else { - if fastpathEnabled && (rk == reflect.Map || rk == reflect.Slice || rk == reflect.Array) { - var rtid2 uintptr - if !ti.flagHasPkgPath { - rtid2 = rtid - if rk == reflect.Array { - rtid2 = rt2id(ti.key) - } - if idx, ok := fastpathAvIndex(rtid2); ok { - fn.fd = fp[idx].decfn - fi.addrD = true - fi.addrDf = false - if rk == reflect.Array { - fi.addrD = false - } - } - } else { - - xfe, xrt := dh.decFnloadFastpathUnderlying(ti, fp) - if xfe != nil { - xfnf2 := xfe.decfn - if rk == reflect.Array { - fi.addrD = false - fn.fd = func(d *decoderJsonBytes, xf *decFnInfo, xrv reflect.Value) { - xfnf2(d, xf, rvConvert(xrv, xrt)) - } - } else { - fi.addrD = true - fi.addrDf = false - xptr2rt := reflect.PointerTo(xrt) - fn.fd = func(d *decoderJsonBytes, xf *decFnInfo, xrv reflect.Value) { - if xrv.Kind() == reflect.Ptr { - xfnf2(d, xf, rvConvert(xrv, xptr2rt)) - } else { - xfnf2(d, xf, rvConvert(xrv, xrt)) - } - } - } - } - } - } - if fn.fd == nil { - switch rk { - case reflect.Bool: - fn.fd = (*decoderJsonBytes).kBool - case reflect.String: - fn.fd = (*decoderJsonBytes).kString - case reflect.Int: - fn.fd = (*decoderJsonBytes).kInt - case reflect.Int8: - fn.fd = (*decoderJsonBytes).kInt8 - case reflect.Int16: - fn.fd = (*decoderJsonBytes).kInt16 - case reflect.Int32: - fn.fd = (*decoderJsonBytes).kInt32 - case reflect.Int64: - fn.fd = (*decoderJsonBytes).kInt64 - case reflect.Uint: - fn.fd = (*decoderJsonBytes).kUint - case reflect.Uint8: - fn.fd = (*decoderJsonBytes).kUint8 - case reflect.Uint16: - fn.fd = (*decoderJsonBytes).kUint16 - case reflect.Uint32: - fn.fd = (*decoderJsonBytes).kUint32 - case reflect.Uint64: - fn.fd = (*decoderJsonBytes).kUint64 - case reflect.Uintptr: - fn.fd = (*decoderJsonBytes).kUintptr - case reflect.Float32: - fn.fd = (*decoderJsonBytes).kFloat32 - case reflect.Float64: - fn.fd = (*decoderJsonBytes).kFloat64 - case reflect.Complex64: - fn.fd = (*decoderJsonBytes).kComplex64 - case reflect.Complex128: - fn.fd = (*decoderJsonBytes).kComplex128 - case reflect.Chan: - fn.fd = (*decoderJsonBytes).kChan - case reflect.Slice: - fn.fd = (*decoderJsonBytes).kSlice - case reflect.Array: - fi.addrD = false - fn.fd = (*decoderJsonBytes).kArray - case reflect.Struct: - if ti.simple { - fn.fd = (*decoderJsonBytes).kStructSimple - } else { - fn.fd = (*decoderJsonBytes).kStruct - } - case reflect.Map: - fn.fd = (*decoderJsonBytes).kMap - case reflect.Interface: - - fn.fd = (*decoderJsonBytes).kInterface - default: - - fn.fd = (*decoderJsonBytes).kErr - } - } - } - return -} -func (e *jsonEncDriverBytes) writeIndent() { - e.w.writen1('\n') - x := int(e.di) * int(e.dl) - if e.di < 0 { - x = -x - for x > len(jsonTabs) { - e.w.writeb(jsonTabs[:]) - x -= len(jsonTabs) - } - e.w.writeb(jsonTabs[:x]) - } else { - for x > len(jsonSpaces) { - e.w.writeb(jsonSpaces[:]) - x -= len(jsonSpaces) - } - e.w.writeb(jsonSpaces[:x]) - } -} - -func (e *jsonEncDriverBytes) WriteArrayElem(firstTime bool) { - if !firstTime { - e.w.writen1(',') - } - if e.d { - e.writeIndent() - } -} - -func (e *jsonEncDriverBytes) WriteMapElemKey(firstTime bool) { - if !firstTime { - e.w.writen1(',') - } - if e.d { - e.writeIndent() - } -} - -func (e *jsonEncDriverBytes) WriteMapElemValue() { - if e.d { - e.w.writen2(':', ' ') - } else { - e.w.writen1(':') - } -} - -func (e *jsonEncDriverBytes) EncodeNil() { - - e.w.writeb(jsonNull) -} - -func (e *jsonEncDriverBytes) encodeIntAsUint(v int64, quotes bool) { - neg := v < 0 - if neg { - v = -v - } - e.encodeUint(neg, quotes, uint64(v)) -} - -func (e *jsonEncDriverBytes) EncodeTime(t time.Time) { - - if t.IsZero() { - e.EncodeNil() - return - } - switch e.timeFmt { - case jsonTimeFmtStringLayout: - e.b[0] = '"' - b := t.AppendFormat(e.b[1:1], e.timeFmtLayout) - e.b[len(b)+1] = '"' - e.w.writeb(e.b[:len(b)+2]) - case jsonTimeFmtUnix: - e.encodeIntAsUint(t.Unix(), false) - case jsonTimeFmtUnixMilli: - e.encodeIntAsUint(t.UnixMilli(), false) - case jsonTimeFmtUnixMicro: - e.encodeIntAsUint(t.UnixMicro(), false) - case jsonTimeFmtUnixNano: - e.encodeIntAsUint(t.UnixNano(), false) - } -} - -func (e *jsonEncDriverBytes) EncodeExt(rv interface{}, basetype reflect.Type, xtag uint64, ext Ext) { - if ext == SelfExt { - e.enc.encodeAs(rv, basetype, false) - } else if v := ext.ConvertExt(rv); v == nil { - e.writeNilBytes() - } else { - e.enc.encodeI(v) - } -} - -func (e *jsonEncDriverBytes) EncodeRawExt(re *RawExt) { - if re.Data != nil { - e.w.writeb(re.Data) - } else if re.Value != nil { - e.enc.encodeI(re.Value) - } else { - e.EncodeNil() - } -} - -func (e *jsonEncDriverBytes) EncodeBool(b bool) { - e.w.writestr(jsonEncBoolStrs[bool2int(e.ks && e.e.c == containerMapKey)%2][bool2int(b)%2]) -} - -func (e *jsonEncDriverBytes) encodeFloat(f float64, bitsize, fmt byte, prec int8) { - var blen uint - if e.ks && e.e.c == containerMapKey { - blen = 2 + uint(len(strconv.AppendFloat(e.b[1:1], f, fmt, int(prec), int(bitsize)))) - - e.b[0] = '"' - e.b[blen-1] = '"' - e.w.writeb(e.b[:blen]) - } else { - e.w.writeb(strconv.AppendFloat(e.b[:0], f, fmt, int(prec), int(bitsize))) - } -} - -func (e *jsonEncDriverBytes) EncodeFloat64(f float64) { - if math.IsNaN(f) || math.IsInf(f, 0) { - e.EncodeNil() - return - } - fmt, prec := jsonFloatStrconvFmtPrec64(f) - e.encodeFloat(f, 64, fmt, prec) -} - -func (e *jsonEncDriverBytes) EncodeFloat32(f float32) { - if math.IsNaN(float64(f)) || math.IsInf(float64(f), 0) { - e.EncodeNil() - return - } - fmt, prec := jsonFloatStrconvFmtPrec32(f) - e.encodeFloat(float64(f), 32, fmt, prec) -} - -func (e *jsonEncDriverBytes) encodeUint(neg bool, quotes bool, u uint64) { - e.w.writeb(jsonEncodeUint(neg, quotes, u, &e.b)) -} - -func (e *jsonEncDriverBytes) EncodeInt(v int64) { - quotes := e.is == 'A' || e.is == 'L' && (v > 1<<53 || v < -(1<<53)) || - (e.ks && e.e.c == containerMapKey) - - if cpu32Bit { - if quotes { - blen := 2 + len(strconv.AppendInt(e.b[1:1], v, 10)) - e.b[0] = '"' - e.b[blen-1] = '"' - e.w.writeb(e.b[:blen]) - } else { - e.w.writeb(strconv.AppendInt(e.b[:0], v, 10)) - } - return - } - - if v < 0 { - e.encodeUint(true, quotes, uint64(-v)) - } else { - e.encodeUint(false, quotes, uint64(v)) - } -} - -func (e *jsonEncDriverBytes) EncodeUint(v uint64) { - quotes := e.is == 'A' || e.is == 'L' && v > 1<<53 || - (e.ks && e.e.c == containerMapKey) - - if cpu32Bit { - - if quotes { - blen := 2 + len(strconv.AppendUint(e.b[1:1], v, 10)) - e.b[0] = '"' - e.b[blen-1] = '"' - e.w.writeb(e.b[:blen]) - } else { - e.w.writeb(strconv.AppendUint(e.b[:0], v, 10)) - } - return - } - - e.encodeUint(false, quotes, v) -} - -func (e *jsonEncDriverBytes) EncodeString(v string) { - if e.h.StringToRaw { - e.EncodeStringBytesRaw(bytesView(v)) - return - } - e.quoteStr(v) -} - -func (e *jsonEncDriverBytes) EncodeStringNoEscape4Json(v string) { e.w.writeqstr(v) } - -func (e *jsonEncDriverBytes) EncodeStringBytesRaw(v []byte) { - if e.rawext { - - iv := e.h.RawBytesExt.ConvertExt(any(v)) - if iv == nil { - e.EncodeNil() - } else { - e.enc.encodeI(iv) - } - return - } - - if e.bytesFmt == jsonBytesFmtArray { - e.WriteArrayStart(len(v)) - for j := range v { - e.WriteArrayElem(j == 0) - e.encodeUint(false, false, uint64(v[j])) - } - e.WriteArrayEnd() - return - } - - var slen int - if e.bytesFmt == jsonBytesFmtBase64 { - slen = base64.StdEncoding.EncodedLen(len(v)) - } else { - slen = e.byteFmter.EncodedLen(len(v)) - } - slen += 2 - - bs := e.e.blist.peek(slen, false)[:slen] - - if e.bytesFmt == jsonBytesFmtBase64 { - base64.StdEncoding.Encode(bs[1:], v) - } else { - e.byteFmter.Encode(bs[1:], v) - } - - bs[len(bs)-1] = '"' - bs[0] = '"' - e.w.writeb(bs) -} - -func (e *jsonEncDriverBytes) EncodeBytes(v []byte) { - if v == nil { - e.writeNilBytes() - return - } - e.EncodeStringBytesRaw(v) -} - -func (e *jsonEncDriverBytes) writeNilOr(v []byte) { - if !e.h.NilCollectionToZeroLength { - v = jsonNull - } - e.w.writeb(v) -} - -func (e *jsonEncDriverBytes) writeNilBytes() { - e.writeNilOr(jsonArrayEmpty) -} - -func (e *jsonEncDriverBytes) writeNilArray() { - e.writeNilOr(jsonArrayEmpty) -} - -func (e *jsonEncDriverBytes) writeNilMap() { - e.writeNilOr(jsonMapEmpty) -} - -func (e *jsonEncDriverBytes) WriteArrayEmpty() { - e.w.writen2('[', ']') -} - -func (e *jsonEncDriverBytes) WriteMapEmpty() { - e.w.writen2('{', '}') -} - -func (e *jsonEncDriverBytes) WriteArrayStart(length int) { - if e.d { - e.dl++ - } - e.w.writen1('[') -} - -func (e *jsonEncDriverBytes) WriteArrayEnd() { - if e.d { - e.dl-- - - e.writeIndent() - } - e.w.writen1(']') -} - -func (e *jsonEncDriverBytes) WriteMapStart(length int) { - if e.d { - e.dl++ - } - e.w.writen1('{') -} - -func (e *jsonEncDriverBytes) WriteMapEnd() { - if e.d { - e.dl-- - - e.writeIndent() - } - e.w.writen1('}') -} - -func (e *jsonEncDriverBytes) quoteStr(s string) { - - const hex = "0123456789abcdef" - e.w.writen1('"') - var i, start uint - for i < uint(len(s)) { - - b := s[i] - if e.s.isset(b) { - i++ - continue - } - if b < utf8.RuneSelf { - if start < i { - e.w.writestr(s[start:i]) - } - switch b { - case '\\': - e.w.writen2('\\', '\\') - case '"': - e.w.writen2('\\', '"') - case '\n': - e.w.writen2('\\', 'n') - case '\t': - e.w.writen2('\\', 't') - case '\r': - e.w.writen2('\\', 'r') - case '\b': - e.w.writen2('\\', 'b') - case '\f': - e.w.writen2('\\', 'f') - default: - e.w.writestr(`\u00`) - e.w.writen2(hex[b>>4], hex[b&0xF]) - } - i++ - start = i - continue - } - c, size := utf8.DecodeRuneInString(s[i:]) - if c == utf8.RuneError && size == 1 { - if start < i { - e.w.writestr(s[start:i]) - } - e.w.writestr(`\uFFFD`) - i++ - start = i - continue - } - - if jsonEscapeMultiByteUnicodeSep && (c == '\u2028' || c == '\u2029') { - if start < i { - e.w.writestr(s[start:i]) - } - e.w.writestr(`\u202`) - e.w.writen1(hex[c&0xF]) - i += uint(size) - start = i - continue - } - i += uint(size) - } - if start < uint(len(s)) { - e.w.writestr(s[start:]) - } - e.w.writen1('"') -} - -func (e *jsonEncDriverBytes) atEndOfEncode() { - if e.h.TermWhitespace { - var c byte = ' ' - if e.e.c != 0 { - c = '\n' - } - e.w.writen1(c) - } -} - -func (d *jsonDecDriverBytes) ReadMapStart() int { - d.advance() - if d.tok == 'n' { - d.checkLit3([3]byte{'u', 'l', 'l'}, d.r.readn3()) - return containerLenNil - } - if d.tok != '{' { - halt.errorByte("read map - expect char '{' but got char: ", d.tok) - } - d.tok = 0 - return containerLenUnknown -} - -func (d *jsonDecDriverBytes) ReadArrayStart() int { - d.advance() - if d.tok == 'n' { - d.checkLit3([3]byte{'u', 'l', 'l'}, d.r.readn3()) - return containerLenNil - } - if d.tok != '[' { - halt.errorByte("read array - expect char '[' but got char ", d.tok) - } - d.tok = 0 - return containerLenUnknown -} - -func (d *jsonDecDriverBytes) CheckBreak() bool { - d.advance() - return d.tok == '}' || d.tok == ']' -} - -func (d *jsonDecDriverBytes) checkSep(xc byte) { - d.advance() - if d.tok != xc { - d.readDelimError(xc) - } - d.tok = 0 -} - -func (d *jsonDecDriverBytes) ReadArrayElem(firstTime bool) { - if !firstTime { - d.checkSep(',') - } -} - -func (d *jsonDecDriverBytes) ReadArrayEnd() { - d.checkSep(']') -} - -func (d *jsonDecDriverBytes) ReadMapElemKey(firstTime bool) { - d.ReadArrayElem(firstTime) -} - -func (d *jsonDecDriverBytes) ReadMapElemValue() { - d.checkSep(':') -} - -func (d *jsonDecDriverBytes) ReadMapEnd() { - d.checkSep('}') -} - -func (d *jsonDecDriverBytes) readDelimError(xc uint8) { - halt.errorf("read json delimiter - expect char '%c' but got char '%c'", xc, d.tok) -} - -func (d *jsonDecDriverBytes) checkLit3(got, expect [3]byte) { - if jsonValidateSymbols && got != expect { - jsonCheckLitErr3(got, expect) - } - d.tok = 0 -} - -func (d *jsonDecDriverBytes) checkLit4(got, expect [4]byte) { - if jsonValidateSymbols && got != expect { - jsonCheckLitErr4(got, expect) - } - d.tok = 0 -} - -func (d *jsonDecDriverBytes) skipWhitespace() { - d.tok = d.r.skipWhitespace() -} - -func (d *jsonDecDriverBytes) advance() { - - if d.tok < 33 { - d.skipWhitespace() - } -} - -func (d *jsonDecDriverBytes) nextValueBytes() []byte { - consumeString := func() { - TOP: - _, c := d.r.jsonReadAsisChars() - if c == '\\' { - d.r.readn1() - goto TOP - } - } - - d.advance() - d.r.startRecording() - - switch d.tok { - default: - _, d.tok = d.r.jsonReadNum() - case 'n': - d.checkLit3([3]byte{'u', 'l', 'l'}, d.r.readn3()) - case 'f': - d.checkLit4([4]byte{'a', 'l', 's', 'e'}, d.r.readn4()) - case 't': - d.checkLit3([3]byte{'r', 'u', 'e'}, d.r.readn3()) - case '"': - consumeString() - d.tok = 0 - case '{', '[': - var elem struct{} - var stack []struct{} - - stack = append(stack, elem) - - for len(stack) != 0 { - c := d.r.readn1() - switch c { - case '"': - consumeString() - case '{', '[': - stack = append(stack, elem) - case '}', ']': - stack = stack[:len(stack)-1] - } - } - d.tok = 0 - } - return d.r.stopRecording() -} - -func (d *jsonDecDriverBytes) TryNil() bool { - d.advance() - - if d.tok == 'n' { - d.checkLit3([3]byte{'u', 'l', 'l'}, d.r.readn3()) - return true - } - return false -} - -func (d *jsonDecDriverBytes) DecodeBool() (v bool) { - d.advance() - - fquot := d.d.c == containerMapKey && d.tok == '"' - if fquot { - d.tok = d.r.readn1() - } - switch d.tok { - case 'f': - d.checkLit4([4]byte{'a', 'l', 's', 'e'}, d.r.readn4()) - - case 't': - d.checkLit3([3]byte{'r', 'u', 'e'}, d.r.readn3()) - v = true - case 'n': - d.checkLit3([3]byte{'u', 'l', 'l'}, d.r.readn3()) - - default: - halt.errorByte("decode bool: got first char: ", d.tok) - - } - if fquot { - d.r.readn1() - } - return -} - -func (d *jsonDecDriverBytes) DecodeTime() (t time.Time) { - - d.advance() - if d.tok == 'n' { - d.checkLit3([3]byte{'u', 'l', 'l'}, d.r.readn3()) - return - } - var bs []byte - - if d.tok != '"' { - bs, d.tok = d.r.jsonReadNum() - i := d.parseInt64(bs) - switch d.timeFmtNum { - case jsonTimeFmtUnix: - t = time.Unix(i, 0) - case jsonTimeFmtUnixMilli: - t = time.UnixMilli(i) - case jsonTimeFmtUnixMicro: - t = time.UnixMicro(i) - case jsonTimeFmtUnixNano: - t = time.Unix(0, i) - default: - halt.errorStr("invalid timeFmtNum") - } - return - } - - bs = d.readUnescapedString() - var err error - for _, v := range d.timeFmtLayouts { - t, err = time.Parse(v, stringView(bs)) - if err == nil { - return - } - } - halt.errorStr("error decoding time") - return -} - -func (d *jsonDecDriverBytes) ContainerType() (vt valueType) { - - d.advance() - - if d.tok == '{' { - return valueTypeMap - } else if d.tok == '[' { - return valueTypeArray - } else if d.tok == 'n' { - d.checkLit3([3]byte{'u', 'l', 'l'}, d.r.readn3()) - return valueTypeNil - } else if d.tok == '"' { - return valueTypeString - } - return valueTypeUnset -} - -func (d *jsonDecDriverBytes) decNumBytes() (bs []byte) { - d.advance() - if d.tok == '"' { - bs = d.r.jsonReadUntilDblQuote() - d.tok = 0 - } else if d.tok == 'n' { - d.checkLit3([3]byte{'u', 'l', 'l'}, d.r.readn3()) - } else { - bs, d.tok = d.r.jsonReadNum() - } - return -} - -func (d *jsonDecDriverBytes) DecodeUint64() (u uint64) { - b := d.decNumBytes() - u, neg, ok := parseInteger_bytes(b) - if neg { - halt.errorf("negative number cannot be decoded as uint64: %s", any(b)) - } - if !ok { - halt.onerror(strconvParseErr(b, "ParseUint")) - } - return -} - -func (d *jsonDecDriverBytes) DecodeInt64() (v int64) { - return d.parseInt64(d.decNumBytes()) -} - -func (d *jsonDecDriverBytes) parseInt64(b []byte) (v int64) { - u, neg, ok := parseInteger_bytes(b) - if !ok { - halt.onerror(strconvParseErr(b, "ParseInt")) - } - if chkOvf.Uint2Int(u, neg) { - halt.errorBytes("overflow decoding number from ", b) - } - if neg { - v = -int64(u) - } else { - v = int64(u) - } - return -} - -func (d *jsonDecDriverBytes) DecodeFloat64() (f float64) { - var err error - bs := d.decNumBytes() - if len(bs) == 0 { - return - } - f, err = parseFloat64(bs) - halt.onerror(err) - return -} - -func (d *jsonDecDriverBytes) DecodeFloat32() (f float32) { - var err error - bs := d.decNumBytes() - if len(bs) == 0 { - return - } - f, err = parseFloat32(bs) - halt.onerror(err) - return -} - -func (d *jsonDecDriverBytes) advanceNil() (ok bool) { - d.advance() - if d.tok == 'n' { - d.checkLit3([3]byte{'u', 'l', 'l'}, d.r.readn3()) - return true - } - return false -} - -func (d *jsonDecDriverBytes) DecodeExt(rv interface{}, basetype reflect.Type, xtag uint64, ext Ext) { - if d.advanceNil() { - return - } - if ext == SelfExt { - d.dec.decodeAs(rv, basetype, false) - } else { - d.dec.interfaceExtConvertAndDecode(rv, ext) - } -} - -func (d *jsonDecDriverBytes) DecodeRawExt(re *RawExt) { - if d.advanceNil() { - return - } - d.dec.decode(&re.Value) -} - -func (d *jsonDecDriverBytes) decBytesFromArray(bs []byte) []byte { - d.advance() - if d.tok != ']' { - bs = append(bs, uint8(d.DecodeUint64())) - d.advance() - } - for d.tok != ']' { - if d.tok != ',' { - halt.errorByte("read array element - expect char ',' but got char: ", d.tok) - } - d.tok = 0 - bs = append(bs, uint8(chkOvf.UintV(d.DecodeUint64(), 8))) - d.advance() - } - d.tok = 0 - return bs -} - -func (d *jsonDecDriverBytes) DecodeBytes() (bs []byte, state dBytesAttachState) { - d.advance() - state = dBytesDetach - if d.tok == 'n' { - d.checkLit3([3]byte{'u', 'l', 'l'}, d.r.readn3()) - return - } - state = dBytesAttachBuffer - - if d.rawext { - d.buf = d.buf[:0] - d.dec.interfaceExtConvertAndDecode(&d.buf, d.h.RawBytesExt) - bs = d.buf - return - } - - if d.tok == '[' { - d.tok = 0 - - bs = d.decBytesFromArray(d.buf[:0]) - d.buf = bs - return - } - - d.ensureReadingString() - bs1 := d.readUnescapedString() - - slen := base64.StdEncoding.DecodedLen(len(bs1)) - if slen == 0 { - bs = zeroByteSlice - state = dBytesDetach - } else if slen <= cap(d.buf) { - bs = d.buf[:slen] - } else { - d.buf = d.d.blist.putGet(d.buf, slen)[:slen] - bs = d.buf - } - var err error - for _, v := range d.byteFmters { - - slen, err = v.Decode(bs, bs1) - if err == nil { - bs = bs[:slen] - return - } - } - halt.errorf("error decoding byte string '%s': %v", any(bs1), err) - return -} - -func (d *jsonDecDriverBytes) DecodeStringAsBytes() (bs []byte, state dBytesAttachState) { - d.advance() - - var cond bool - - if d.tok == '"' { - d.tok = 0 - bs, cond = d.dblQuoteStringAsBytes() - state = d.d.attachState(cond) - return - } - - state = dBytesDetach - - switch d.tok { - case 'n': - d.checkLit3([3]byte{'u', 'l', 'l'}, d.r.readn3()) - - case 'f': - d.checkLit4([4]byte{'a', 'l', 's', 'e'}, d.r.readn4()) - bs = jsonLitb[jsonLitF : jsonLitF+5] - case 't': - d.checkLit3([3]byte{'r', 'u', 'e'}, d.r.readn3()) - bs = jsonLitb[jsonLitT : jsonLitT+4] - default: - - bs, d.tok = d.r.jsonReadNum() - state = d.d.attachState(!d.d.bytes) - } - return -} - -func (d *jsonDecDriverBytes) ensureReadingString() { - if d.tok != '"' { - halt.errorByte("expecting string starting with '\"'; got ", d.tok) - } -} - -func (d *jsonDecDriverBytes) readUnescapedString() (bs []byte) { - - bs = d.r.jsonReadUntilDblQuote() - d.tok = 0 - return -} - -func (d *jsonDecDriverBytes) dblQuoteStringAsBytes() (buf []byte, usingBuf bool) { - bs, c := d.r.jsonReadAsisChars() - if c == '"' { - return bs, !d.d.bytes - } - buf = append(d.buf[:0], bs...) - - checkUtf8 := d.h.ValidateUnicode - usingBuf = true - - for { - - c = d.r.readn1() - - switch c { - case '"', '\\', '/', '\'': - buf = append(buf, c) - case 'b': - buf = append(buf, '\b') - case 'f': - buf = append(buf, '\f') - case 'n': - buf = append(buf, '\n') - case 'r': - buf = append(buf, '\r') - case 't': - buf = append(buf, '\t') - case 'u': - rr := d.appendStringAsBytesSlashU() - if checkUtf8 && rr == unicode.ReplacementChar { - d.buf = buf - halt.errorBytes("invalid UTF-8 character found after: ", buf) - } - buf = append(buf, d.bstr[:utf8.EncodeRune(d.bstr[:], rr)]...) - default: - d.buf = buf - halt.errorByte("unsupported escaped value: ", c) - } - - bs, c = d.r.jsonReadAsisChars() - buf = append(buf, bs...) - if c == '"' { - break - } - } - d.buf = buf - return -} - -func (d *jsonDecDriverBytes) appendStringAsBytesSlashU() (r rune) { - var rr uint32 - cs := d.r.readn4() - if rr = jsonSlashURune(cs); rr == unicode.ReplacementChar { - return unicode.ReplacementChar - } - r = rune(rr) - if utf16.IsSurrogate(r) { - csu := d.r.readn2() - cs = d.r.readn4() - if csu[0] == '\\' && csu[1] == 'u' { - if rr = jsonSlashURune(cs); rr == unicode.ReplacementChar { - return unicode.ReplacementChar - } - return utf16.DecodeRune(r, rune(rr)) - } - return unicode.ReplacementChar - } - return -} - -func (d *jsonDecDriverBytes) DecodeNaked() { - z := d.d.naked() - - d.advance() - var bs []byte - var err error - switch d.tok { - case 'n': - d.checkLit3([3]byte{'u', 'l', 'l'}, d.r.readn3()) - z.v = valueTypeNil - case 'f': - d.checkLit4([4]byte{'a', 'l', 's', 'e'}, d.r.readn4()) - z.v = valueTypeBool - z.b = false - case 't': - d.checkLit3([3]byte{'r', 'u', 'e'}, d.r.readn3()) - z.v = valueTypeBool - z.b = true - case '{': - z.v = valueTypeMap - case '[': - z.v = valueTypeArray - case '"': - - d.tok = 0 - bs, z.b = d.dblQuoteStringAsBytes() - att := d.d.attachState(z.b) - if jsonNakedBoolNumInQuotedStr && - d.h.MapKeyAsString && len(bs) > 0 && d.d.c == containerMapKey { - switch string(bs) { - - case "true": - z.v = valueTypeBool - z.b = true - case "false": - z.v = valueTypeBool - z.b = false - default: - if err = jsonNakedNum(z, bs, d.h.PreferFloat, d.h.SignedInteger); err != nil { - z.v = valueTypeString - z.s = d.d.detach2Str(bs, att) - } - } - } else { - z.v = valueTypeString - z.s = d.d.detach2Str(bs, att) - } - default: - bs, d.tok = d.r.jsonReadNum() - if len(bs) == 0 { - halt.errorStr("decode number from empty string") - } - if err = jsonNakedNum(z, bs, d.h.PreferFloat, d.h.SignedInteger); err != nil { - halt.errorf("decode number from %s: %v", any(bs), err) - } - } -} - -func (e *jsonEncDriverBytes) reset() { - e.dl = 0 - - e.typical = e.h.typical() - if e.h.HTMLCharsAsIs { - e.s = &jsonCharSafeBitset - } else { - e.s = &jsonCharHtmlSafeBitset - } - e.di = int8(e.h.Indent) - e.d = e.h.Indent != 0 - e.ks = e.h.MapKeyAsString - e.is = e.h.IntegerAsString - - var ho jsonHandleOpts - ho.reset(e.h) - e.timeFmt = ho.timeFmt - e.bytesFmt = ho.bytesFmt - e.timeFmtLayout = "" - e.byteFmter = nil - if len(ho.timeFmtLayouts) > 0 { - e.timeFmtLayout = ho.timeFmtLayouts[0] - } - if len(ho.byteFmters) > 0 { - e.byteFmter = ho.byteFmters[0] - } - e.rawext = ho.rawext -} - -func (d *jsonDecDriverBytes) reset() { - d.buf = d.d.blist.check(d.buf, 256) - d.tok = 0 - - d.jsonHandleOpts.reset(d.h) -} - -func (d *jsonEncDriverBytes) init(hh Handle, shared *encoderBase, enc encoderI) (fp interface{}) { - callMake(&d.w) - d.h = hh.(*JsonHandle) - d.e = shared - if shared.bytes { - fp = jsonFpEncBytes - } else { - fp = jsonFpEncIO - } - - d.init2(enc) - return -} - -func (e *jsonEncDriverBytes) writeBytesAsis(b []byte) { e.w.writeb(b) } - -func (e *jsonEncDriverBytes) writerEnd() { e.w.end() } - -func (e *jsonEncDriverBytes) resetOutBytes(out *[]byte) { - e.w.resetBytes(*out, out) -} - -func (e *jsonEncDriverBytes) resetOutIO(out io.Writer) { - e.w.resetIO(out, e.h.WriterBufferSize, &e.e.blist) -} - -func (d *jsonDecDriverBytes) init(hh Handle, shared *decoderBase, dec decoderI) (fp interface{}) { - callMake(&d.r) - d.h = hh.(*JsonHandle) - d.d = shared - if shared.bytes { - fp = jsonFpDecBytes - } else { - fp = jsonFpDecIO - } - - d.init2(dec) - return -} - -func (d *jsonDecDriverBytes) NumBytesRead() int { - return int(d.r.numread()) -} - -func (d *jsonDecDriverBytes) resetInBytes(in []byte) { - d.r.resetBytes(in) -} - -func (d *jsonDecDriverBytes) resetInIO(r io.Reader) { - d.r.resetIO(r, d.h.ReaderBufferSize, d.h.MaxInitLen, &d.d.blist) -} - -func (d *jsonDecDriverBytes) descBd() (s string) { - halt.onerror(errJsonNoBd) - return -} - -func (d *jsonEncDriverBytes) init2(enc encoderI) { - d.enc = enc - -} - -func (d *jsonDecDriverBytes) init2(dec decoderI) { - d.dec = dec - - d.buf = d.buf[:0] - - d.d.jsms = d.h.MapKeyAsString -} - -type helperEncDriverJsonIO struct{} -type encFnJsonIO struct { - i encFnInfo - fe func(*encoderJsonIO, *encFnInfo, reflect.Value) -} -type encRtidFnJsonIO struct { - rtid uintptr - fn *encFnJsonIO -} -type encoderJsonIO struct { - dh helperEncDriverJsonIO - fp *fastpathEsJsonIO - e jsonEncDriverIO - encoderBase -} -type helperDecDriverJsonIO struct{} -type decFnJsonIO struct { - i decFnInfo - fd func(*decoderJsonIO, *decFnInfo, reflect.Value) -} -type decRtidFnJsonIO struct { - rtid uintptr - fn *decFnJsonIO -} -type decoderJsonIO struct { - dh helperDecDriverJsonIO - fp *fastpathDsJsonIO - d jsonDecDriverIO - decoderBase -} -type jsonEncDriverIO struct { - noBuiltInTypes - h *JsonHandle - e *encoderBase - s *bitset256 - - w bufioEncWriter - - enc encoderI - - timeFmtLayout string - byteFmter jsonBytesFmter - - timeFmt jsonTimeFmt - bytesFmt jsonBytesFmt - - di int8 - d bool - dl uint16 - - ks bool - is byte - - typical bool - - rawext bool - - b [48]byte -} -type jsonDecDriverIO struct { - noBuiltInTypes - decDriverNoopNumberHelper - h *JsonHandle - d *decoderBase - - r ioDecReader - - buf []byte - - tok uint8 - _ bool - _ byte - bstr [4]byte - - jsonHandleOpts - - dec decoderI -} - -func (e *encoderJsonIO) rawExt(_ *encFnInfo, rv reflect.Value) { - if re := rv2i(rv).(*RawExt); re == nil { - e.e.EncodeNil() - } else { - e.e.EncodeRawExt(re) - } -} - -func (e *encoderJsonIO) ext(f *encFnInfo, rv reflect.Value) { - e.e.EncodeExt(rv2i(rv), f.ti.rt, f.xfTag, f.xfFn) -} - -func (e *encoderJsonIO) selferMarshal(_ *encFnInfo, rv reflect.Value) { - rv2i(rv).(Selfer).CodecEncodeSelf(&Encoder{e}) -} - -func (e *encoderJsonIO) binaryMarshal(_ *encFnInfo, rv reflect.Value) { - bs, fnerr := rv2i(rv).(encoding.BinaryMarshaler).MarshalBinary() - e.marshalRaw(bs, fnerr) -} - -func (e *encoderJsonIO) textMarshal(_ *encFnInfo, rv reflect.Value) { - bs, fnerr := rv2i(rv).(encoding.TextMarshaler).MarshalText() - e.marshalUtf8(bs, fnerr) -} - -func (e *encoderJsonIO) jsonMarshal(_ *encFnInfo, rv reflect.Value) { - bs, fnerr := rv2i(rv).(jsonMarshaler).MarshalJSON() - e.marshalAsis(bs, fnerr) -} - -func (e *encoderJsonIO) raw(_ *encFnInfo, rv reflect.Value) { - e.rawBytes(rv2i(rv).(Raw)) -} - -func (e *encoderJsonIO) encodeComplex64(v complex64) { - if imag(v) != 0 { - halt.errorf("cannot encode complex number: %v, with imaginary values: %v", any(v), any(imag(v))) - } - e.e.EncodeFloat32(real(v)) -} - -func (e *encoderJsonIO) encodeComplex128(v complex128) { - if imag(v) != 0 { - halt.errorf("cannot encode complex number: %v, with imaginary values: %v", any(v), any(imag(v))) - } - e.e.EncodeFloat64(real(v)) -} - -func (e *encoderJsonIO) kBool(_ *encFnInfo, rv reflect.Value) { - e.e.EncodeBool(rvGetBool(rv)) -} - -func (e *encoderJsonIO) kTime(_ *encFnInfo, rv reflect.Value) { - e.e.EncodeTime(rvGetTime(rv)) -} - -func (e *encoderJsonIO) kString(_ *encFnInfo, rv reflect.Value) { - e.e.EncodeString(rvGetString(rv)) -} - -func (e *encoderJsonIO) kFloat32(_ *encFnInfo, rv reflect.Value) { - e.e.EncodeFloat32(rvGetFloat32(rv)) -} - -func (e *encoderJsonIO) kFloat64(_ *encFnInfo, rv reflect.Value) { - e.e.EncodeFloat64(rvGetFloat64(rv)) -} - -func (e *encoderJsonIO) kComplex64(_ *encFnInfo, rv reflect.Value) { - e.encodeComplex64(rvGetComplex64(rv)) -} - -func (e *encoderJsonIO) kComplex128(_ *encFnInfo, rv reflect.Value) { - e.encodeComplex128(rvGetComplex128(rv)) -} - -func (e *encoderJsonIO) kInt(_ *encFnInfo, rv reflect.Value) { - e.e.EncodeInt(int64(rvGetInt(rv))) -} - -func (e *encoderJsonIO) kInt8(_ *encFnInfo, rv reflect.Value) { - e.e.EncodeInt(int64(rvGetInt8(rv))) -} - -func (e *encoderJsonIO) kInt16(_ *encFnInfo, rv reflect.Value) { - e.e.EncodeInt(int64(rvGetInt16(rv))) -} - -func (e *encoderJsonIO) kInt32(_ *encFnInfo, rv reflect.Value) { - e.e.EncodeInt(int64(rvGetInt32(rv))) -} - -func (e *encoderJsonIO) kInt64(_ *encFnInfo, rv reflect.Value) { - e.e.EncodeInt(int64(rvGetInt64(rv))) -} - -func (e *encoderJsonIO) kUint(_ *encFnInfo, rv reflect.Value) { - e.e.EncodeUint(uint64(rvGetUint(rv))) -} - -func (e *encoderJsonIO) kUint8(_ *encFnInfo, rv reflect.Value) { - e.e.EncodeUint(uint64(rvGetUint8(rv))) -} - -func (e *encoderJsonIO) kUint16(_ *encFnInfo, rv reflect.Value) { - e.e.EncodeUint(uint64(rvGetUint16(rv))) -} - -func (e *encoderJsonIO) kUint32(_ *encFnInfo, rv reflect.Value) { - e.e.EncodeUint(uint64(rvGetUint32(rv))) -} - -func (e *encoderJsonIO) kUint64(_ *encFnInfo, rv reflect.Value) { - e.e.EncodeUint(uint64(rvGetUint64(rv))) -} - -func (e *encoderJsonIO) kUintptr(_ *encFnInfo, rv reflect.Value) { - e.e.EncodeUint(uint64(rvGetUintptr(rv))) -} - -func (e *encoderJsonIO) kSeqFn(rt reflect.Type) (fn *encFnJsonIO) { - - if rt = baseRT(rt); rt.Kind() != reflect.Interface { - fn = e.fn(rt) - } - return -} - -func (e *encoderJsonIO) kArrayWMbs(rv reflect.Value, ti *typeInfo, isSlice bool) { - var l int - if isSlice { - l = rvLenSlice(rv) - } else { - l = rv.Len() - } - if l == 0 { - e.e.WriteMapEmpty() - return - } - e.haltOnMbsOddLen(l) - e.mapStart(l >> 1) - - var fn *encFnJsonIO - builtin := ti.tielem.flagEncBuiltin - if !builtin { - fn = e.kSeqFn(ti.elem) - } - - j := 0 - e.c = containerMapKey - e.e.WriteMapElemKey(true) - for { - rvv := rvArrayIndex(rv, j, ti, isSlice) - if builtin { - e.encodeIB(rv2i(baseRVRV(rvv))) - } else { - e.encodeValue(rvv, fn) - } - j++ - if j == l { - break - } - if j&1 == 0 { - e.c = containerMapKey - e.e.WriteMapElemKey(false) - } else { - e.mapElemValue() - } - } - e.c = 0 - e.e.WriteMapEnd() - -} - -func (e *encoderJsonIO) kArrayW(rv reflect.Value, ti *typeInfo, isSlice bool) { - var l int - if isSlice { - l = rvLenSlice(rv) - } else { - l = rv.Len() - } - if l <= 0 { - e.e.WriteArrayEmpty() - return - } - e.arrayStart(l) - - var fn *encFnJsonIO - if !ti.tielem.flagEncBuiltin { - fn = e.kSeqFn(ti.elem) - } - - j := 0 - e.c = containerArrayElem - e.e.WriteArrayElem(true) - builtin := ti.tielem.flagEncBuiltin - for { - rvv := rvArrayIndex(rv, j, ti, isSlice) - if builtin { - e.encodeIB(rv2i(baseRVRV(rvv))) - } else { - e.encodeValue(rvv, fn) - } - j++ - if j == l { - break - } - e.c = containerArrayElem - e.e.WriteArrayElem(false) - } - - e.c = 0 - e.e.WriteArrayEnd() -} - -func (e *encoderJsonIO) kChan(f *encFnInfo, rv reflect.Value) { - if f.ti.chandir&uint8(reflect.RecvDir) == 0 { - halt.errorStr("send-only channel cannot be encoded") - } - if !f.ti.mbs && uint8TypId == rt2id(f.ti.elem) { - e.kSliceBytesChan(rv) - return - } - rtslice := reflect.SliceOf(f.ti.elem) - rv = chanToSlice(rv, rtslice, e.h.ChanRecvTimeout) - ti := e.h.getTypeInfo(rt2id(rtslice), rtslice) - if f.ti.mbs { - e.kArrayWMbs(rv, ti, true) - } else { - e.kArrayW(rv, ti, true) - } -} - -func (e *encoderJsonIO) kSlice(f *encFnInfo, rv reflect.Value) { - if f.ti.mbs { - e.kArrayWMbs(rv, f.ti, true) - } else if f.ti.rtid == uint8SliceTypId || uint8TypId == rt2id(f.ti.elem) { - - e.e.EncodeBytes(rvGetBytes(rv)) - } else { - e.kArrayW(rv, f.ti, true) - } -} - -func (e *encoderJsonIO) kArray(f *encFnInfo, rv reflect.Value) { - if f.ti.mbs { - e.kArrayWMbs(rv, f.ti, false) - } else if handleBytesWithinKArray && uint8TypId == rt2id(f.ti.elem) { - e.e.EncodeStringBytesRaw(rvGetArrayBytes(rv, nil)) - } else { - e.kArrayW(rv, f.ti, false) - } -} - -func (e *encoderJsonIO) kSliceBytesChan(rv reflect.Value) { - - bs0 := e.blist.peek(32, true) - bs := bs0 - - irv := rv2i(rv) - ch, ok := irv.(<-chan byte) - if !ok { - ch = irv.(chan byte) - } - -L1: - switch timeout := e.h.ChanRecvTimeout; { - case timeout == 0: - for { - select { - case b := <-ch: - bs = append(bs, b) - default: - break L1 - } - } - case timeout > 0: - tt := time.NewTimer(timeout) - for { - select { - case b := <-ch: - bs = append(bs, b) - case <-tt.C: - - break L1 - } - } - default: - for b := range ch { - bs = append(bs, b) - } - } - - e.e.EncodeBytes(bs) - e.blist.put(bs) - if !byteSliceSameData(bs0, bs) { - e.blist.put(bs0) - } -} - -func (e *encoderJsonIO) kStructFieldKey(keyType valueType, encName string) { - - if keyType == valueTypeString { - e.e.EncodeString(encName) - } else if keyType == valueTypeInt { - e.e.EncodeInt(must.Int(strconv.ParseInt(encName, 10, 64))) - } else if keyType == valueTypeUint { - e.e.EncodeUint(must.Uint(strconv.ParseUint(encName, 10, 64))) - } else if keyType == valueTypeFloat { - e.e.EncodeFloat64(must.Float(strconv.ParseFloat(encName, 64))) - } else { - halt.errorStr2("invalid struct key type: ", keyType.String()) - } - -} - -func (e *encoderJsonIO) kStructSimple(f *encFnInfo, rv reflect.Value) { - _ = e.e - tisfi := f.ti.sfi.source() - - chkCirRef := e.h.CheckCircularRef - var si *structFieldInfo - var j int - - if f.ti.toArray || e.h.StructToArray { - if len(tisfi) == 0 { - e.e.WriteArrayEmpty() - return - } - e.arrayStart(len(tisfi)) - for j, si = range tisfi { - e.c = containerArrayElem - e.e.WriteArrayElem(j == 0) - if si.encBuiltin { - e.encodeIB(rv2i(si.fieldNoAlloc(rv, true))) - } else { - e.encodeValue(si.fieldNoAlloc(rv, !chkCirRef), nil) - } - } - e.c = 0 - e.e.WriteArrayEnd() - } else { - if len(tisfi) == 0 { - e.e.WriteMapEmpty() - return - } - if e.h.Canonical { - tisfi = f.ti.sfi.sorted() - } - e.mapStart(len(tisfi)) - for j, si = range tisfi { - e.c = containerMapKey - e.e.WriteMapElemKey(j == 0) - e.e.EncodeStringNoEscape4Json(si.encName) - e.mapElemValue() - if si.encBuiltin { - e.encodeIB(rv2i(si.fieldNoAlloc(rv, true))) - } else { - e.encodeValue(si.fieldNoAlloc(rv, !chkCirRef), nil) - } - } - e.c = 0 - e.e.WriteMapEnd() - } -} - -func (e *encoderJsonIO) kStruct(f *encFnInfo, rv reflect.Value) { - _ = e.e - ti := f.ti - toMap := !(ti.toArray || e.h.StructToArray) - var mf map[string]interface{} - if ti.flagMissingFielder { - toMap = true - mf = rv2i(rv).(MissingFielder).CodecMissingFields() - } else if ti.flagMissingFielderPtr { - toMap = true - if rv.CanAddr() { - mf = rv2i(rvAddr(rv, ti.ptr)).(MissingFielder).CodecMissingFields() - } else { - mf = rv2i(e.addrRV(rv, ti.rt, ti.ptr)).(MissingFielder).CodecMissingFields() - } - } - newlen := len(mf) - tisfi := ti.sfi.source() - newlen += len(tisfi) - - var fkvs = e.slist.get(newlen)[:newlen] - - recur := e.h.RecursiveEmptyCheck - chkCirRef := e.h.CheckCircularRef - - var xlen int - - var kv sfiRv - var j int - var sf encStructFieldObj - if toMap { - newlen = 0 - if e.h.Canonical { - tisfi = f.ti.sfi.sorted() - } - for _, si := range tisfi { - - if si.omitEmpty { - kv.r = si.fieldNoAlloc(rv, false) - if isEmptyValue(kv.r, e.h.TypeInfos, recur) { - continue - } - } else { - kv.r = si.fieldNoAlloc(rv, si.encBuiltin || !chkCirRef) - } - kv.v = si - fkvs[newlen] = kv - newlen++ - } - - var mf2s []stringIntf - if len(mf) != 0 { - mf2s = make([]stringIntf, 0, len(mf)) - for k, v := range mf { - if k == "" { - continue - } - if ti.infoFieldOmitempty && isEmptyValue(reflect.ValueOf(v), e.h.TypeInfos, recur) { - continue - } - mf2s = append(mf2s, stringIntf{k, v}) - } - } - - xlen = newlen + len(mf2s) - if xlen == 0 { - e.e.WriteMapEmpty() - goto END - } - - e.mapStart(xlen) - - if len(mf2s) != 0 && e.h.Canonical { - mf2w := make([]encStructFieldObj, newlen+len(mf2s)) - for j = 0; j < newlen; j++ { - kv = fkvs[j] - mf2w[j] = encStructFieldObj{kv.v.encName, kv.r, nil, true, - !kv.v.encNameEscape4Json, kv.v.encBuiltin} - } - for _, v := range mf2s { - mf2w[j] = encStructFieldObj{v.v, reflect.Value{}, v.i, false, false, false} - j++ - } - sort.Sort((encStructFieldObjSlice)(mf2w)) - for j, sf = range mf2w { - e.c = containerMapKey - e.e.WriteMapElemKey(j == 0) - if ti.keyType == valueTypeString && sf.noEsc4json { - e.e.EncodeStringNoEscape4Json(sf.key) - } else { - e.kStructFieldKey(ti.keyType, sf.key) - } - e.mapElemValue() - if sf.isRv { - if sf.builtin { - e.encodeIB(rv2i(baseRVRV(sf.rv))) - } else { - e.encodeValue(sf.rv, nil) - } - } else { - if !e.encodeBuiltin(sf.intf) { - e.encodeR(reflect.ValueOf(sf.intf)) - } - - } - } - } else { - keytyp := ti.keyType - for j = 0; j < newlen; j++ { - kv = fkvs[j] - e.c = containerMapKey - e.e.WriteMapElemKey(j == 0) - if ti.keyType == valueTypeString && !kv.v.encNameEscape4Json { - e.e.EncodeStringNoEscape4Json(kv.v.encName) - } else { - e.kStructFieldKey(keytyp, kv.v.encName) - } - e.mapElemValue() - if kv.v.encBuiltin { - e.encodeIB(rv2i(baseRVRV(kv.r))) - } else { - e.encodeValue(kv.r, nil) - } - } - for _, v := range mf2s { - e.c = containerMapKey - e.e.WriteMapElemKey(j == 0) - e.kStructFieldKey(keytyp, v.v) - e.mapElemValue() - if !e.encodeBuiltin(v.i) { - e.encodeR(reflect.ValueOf(v.i)) - } - - j++ - } - } - - e.c = 0 - e.e.WriteMapEnd() - } else { - newlen = len(tisfi) - for i, si := range tisfi { - - if si.omitEmpty { - - kv.r = si.fieldNoAlloc(rv, false) - if isEmptyContainerValue(kv.r, e.h.TypeInfos, recur) { - kv.r = reflect.Value{} - } - } else { - kv.r = si.fieldNoAlloc(rv, si.encBuiltin || !chkCirRef) - } - kv.v = si - fkvs[i] = kv - } - - if newlen == 0 { - e.e.WriteArrayEmpty() - goto END - } - - e.arrayStart(newlen) - for j = 0; j < newlen; j++ { - e.c = containerArrayElem - e.e.WriteArrayElem(j == 0) - kv = fkvs[j] - if !kv.r.IsValid() { - e.e.EncodeNil() - } else if kv.v.encBuiltin { - e.encodeIB(rv2i(baseRVRV(kv.r))) - } else { - e.encodeValue(kv.r, nil) - } - } - e.c = 0 - e.e.WriteArrayEnd() - } - -END: - - e.slist.put(fkvs) -} - -func (e *encoderJsonIO) kMap(f *encFnInfo, rv reflect.Value) { - _ = e.e - l := rvLenMap(rv) - if l == 0 { - e.e.WriteMapEmpty() - return - } - e.mapStart(l) - - var keyFn, valFn *encFnJsonIO - - ktypeKind := reflect.Kind(f.ti.keykind) - vtypeKind := reflect.Kind(f.ti.elemkind) - - rtval := f.ti.elem - rtvalkind := vtypeKind - for rtvalkind == reflect.Ptr { - rtval = rtval.Elem() - rtvalkind = rtval.Kind() - } - if rtvalkind != reflect.Interface { - valFn = e.fn(rtval) - } - - var rvv = mapAddrLoopvarRV(f.ti.elem, vtypeKind) - - rtkey := f.ti.key - var keyTypeIsString = stringTypId == rt2id(rtkey) - if keyTypeIsString { - keyFn = e.fn(rtkey) - } else { - for rtkey.Kind() == reflect.Ptr { - rtkey = rtkey.Elem() - } - if rtkey.Kind() != reflect.Interface { - keyFn = e.fn(rtkey) - } - } - - if e.h.Canonical { - e.kMapCanonical(f.ti, rv, rvv, keyFn, valFn) - e.c = 0 - e.e.WriteMapEnd() - return - } - - var rvk = mapAddrLoopvarRV(f.ti.key, ktypeKind) - - var it mapIter - mapRange(&it, rv, rvk, rvv, true) - - kbuiltin := f.ti.tikey.flagEncBuiltin - vbuiltin := f.ti.tielem.flagEncBuiltin - for j := 0; it.Next(); j++ { - rv = it.Key() - e.c = containerMapKey - e.e.WriteMapElemKey(j == 0) - if keyTypeIsString { - e.e.EncodeString(rvGetString(rv)) - } else if kbuiltin { - e.encodeIB(rv2i(baseRVRV(rv))) - } else { - e.encodeValue(rv, keyFn) - } - e.mapElemValue() - rv = it.Value() - if vbuiltin { - e.encodeIB(rv2i(baseRVRV(rv))) - } else { - e.encodeValue(it.Value(), valFn) - } - } - it.Done() - - e.c = 0 - e.e.WriteMapEnd() -} - -func (e *encoderJsonIO) kMapCanonical(ti *typeInfo, rv, rvv reflect.Value, keyFn, valFn *encFnJsonIO) { - _ = e.e - - rtkey := ti.key - rtkeydecl := rtkey.PkgPath() == "" && rtkey.Name() != "" - - mks := rv.MapKeys() - rtkeyKind := rtkey.Kind() - mparams := getMapReqParams(ti) - - switch rtkeyKind { - case reflect.Bool: - - if len(mks) == 2 && mks[0].Bool() { - mks[0], mks[1] = mks[1], mks[0] - } - for i := range mks { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - if rtkeydecl { - e.e.EncodeBool(mks[i].Bool()) - } else { - e.encodeValueNonNil(mks[i], keyFn) - } - e.mapElemValue() - e.encodeValue(mapGet(rv, mks[i], rvv, mparams), valFn) - } - case reflect.String: - mksv := make([]orderedRv[string], len(mks)) - for i, k := range mks { - v := &mksv[i] - v.r = k - v.v = rvGetString(k) - } - slices.SortFunc(mksv, cmpOrderedRv) - for i := range mksv { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - if rtkeydecl { - e.e.EncodeString(mksv[i].v) - } else { - e.encodeValueNonNil(mksv[i].r, keyFn) - } - e.mapElemValue() - e.encodeValue(mapGet(rv, mksv[i].r, rvv, mparams), valFn) - } - case reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64, reflect.Uint, reflect.Uintptr: - mksv := make([]orderedRv[uint64], len(mks)) - for i, k := range mks { - v := &mksv[i] - v.r = k - v.v = k.Uint() - } - slices.SortFunc(mksv, cmpOrderedRv) - for i := range mksv { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - if rtkeydecl { - e.e.EncodeUint(mksv[i].v) - } else { - e.encodeValueNonNil(mksv[i].r, keyFn) - } - e.mapElemValue() - e.encodeValue(mapGet(rv, mksv[i].r, rvv, mparams), valFn) - } - case reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64, reflect.Int: - mksv := make([]orderedRv[int64], len(mks)) - for i, k := range mks { - v := &mksv[i] - v.r = k - v.v = k.Int() - } - slices.SortFunc(mksv, cmpOrderedRv) - for i := range mksv { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - if rtkeydecl { - e.e.EncodeInt(mksv[i].v) - } else { - e.encodeValueNonNil(mksv[i].r, keyFn) - } - e.mapElemValue() - e.encodeValue(mapGet(rv, mksv[i].r, rvv, mparams), valFn) - } - case reflect.Float32: - mksv := make([]orderedRv[float64], len(mks)) - for i, k := range mks { - v := &mksv[i] - v.r = k - v.v = k.Float() - } - slices.SortFunc(mksv, cmpOrderedRv) - for i := range mksv { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - if rtkeydecl { - e.e.EncodeFloat32(float32(mksv[i].v)) - } else { - e.encodeValueNonNil(mksv[i].r, keyFn) - } - e.mapElemValue() - e.encodeValue(mapGet(rv, mksv[i].r, rvv, mparams), valFn) - } - case reflect.Float64: - mksv := make([]orderedRv[float64], len(mks)) - for i, k := range mks { - v := &mksv[i] - v.r = k - v.v = k.Float() - } - slices.SortFunc(mksv, cmpOrderedRv) - for i := range mksv { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - if rtkeydecl { - e.e.EncodeFloat64(mksv[i].v) - } else { - e.encodeValueNonNil(mksv[i].r, keyFn) - } - e.mapElemValue() - e.encodeValue(mapGet(rv, mksv[i].r, rvv, mparams), valFn) - } - default: - if rtkey == timeTyp { - mksv := make([]timeRv, len(mks)) - for i, k := range mks { - v := &mksv[i] - v.r = k - v.v = rv2i(k).(time.Time) - } - slices.SortFunc(mksv, cmpTimeRv) - for i := range mksv { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeTime(mksv[i].v) - e.mapElemValue() - e.encodeValue(mapGet(rv, mksv[i].r, rvv, mparams), valFn) - } - break - } - - bs0 := e.blist.get(len(mks) * 16) - mksv := bs0 - mksbv := make([]bytesRv, len(mks)) - - sideEncode(e.hh, &e.h.sideEncPool, func(se encoderI) { - se.ResetBytes(&mksv) - for i, k := range mks { - v := &mksbv[i] - l := len(mksv) - se.setContainerState(containerMapKey) - se.encodeR(baseRVRV(k)) - se.atEndOfEncode() - se.writerEnd() - v.r = k - v.v = mksv[l:] - } - }) - - slices.SortFunc(mksbv, cmpBytesRv) - for j := range mksbv { - e.c = containerMapKey - e.e.WriteMapElemKey(j == 0) - e.e.writeBytesAsis(mksbv[j].v) - e.mapElemValue() - e.encodeValue(mapGet(rv, mksbv[j].r, rvv, mparams), valFn) - } - e.blist.put(mksv) - if !byteSliceSameData(bs0, mksv) { - e.blist.put(bs0) - } - } -} - -func (e *encoderJsonIO) init(h Handle) { - initHandle(h) - callMake(&e.e) - e.hh = h - e.h = h.getBasicHandle() - - e.err = errEncoderNotInitialized - - e.fp = e.e.init(h, &e.encoderBase, e).(*fastpathEsJsonIO) - - if e.bytes { - e.rtidFn = &e.h.rtidFnsEncBytes - e.rtidFnNoExt = &e.h.rtidFnsEncNoExtBytes - } else { - e.rtidFn = &e.h.rtidFnsEncIO - e.rtidFnNoExt = &e.h.rtidFnsEncNoExtIO - } - - e.reset() -} - -func (e *encoderJsonIO) reset() { - e.e.reset() - if e.ci != nil { - e.ci = e.ci[:0] - } - e.c = 0 - e.calls = 0 - e.seq = 0 - e.err = nil -} - -func (e *encoderJsonIO) Encode(v interface{}) (err error) { - - defer panicValToErr(e, callRecoverSentinel, &e.err, &err, debugging) - e.mustEncode(v) - return -} - -func (e *encoderJsonIO) MustEncode(v interface{}) { - defer panicValToErr(e, callRecoverSentinel, &e.err, nil, true) - e.mustEncode(v) - return -} - -func (e *encoderJsonIO) mustEncode(v interface{}) { - halt.onerror(e.err) - if e.hh == nil { - halt.onerror(errNoFormatHandle) - } - - e.calls++ - if !e.encodeBuiltin(v) { - e.encodeR(reflect.ValueOf(v)) - } - - e.calls-- - if e.calls == 0 { - e.e.atEndOfEncode() - e.e.writerEnd() - } -} - -func (e *encoderJsonIO) encodeI(iv interface{}) { - if !e.encodeBuiltin(iv) { - e.encodeR(reflect.ValueOf(iv)) - } -} - -func (e *encoderJsonIO) encodeIB(iv interface{}) { - if !e.encodeBuiltin(iv) { - - halt.errorStr("[should not happen] invalid type passed to encodeBuiltin") - } -} - -func (e *encoderJsonIO) encodeR(base reflect.Value) { - e.encodeValue(base, nil) -} - -func (e *encoderJsonIO) encodeBuiltin(iv interface{}) (ok bool) { - ok = true - switch v := iv.(type) { - case nil: - e.e.EncodeNil() - - case Raw: - e.rawBytes(v) - case string: - e.e.EncodeString(v) - case bool: - e.e.EncodeBool(v) - case int: - e.e.EncodeInt(int64(v)) - case int8: - e.e.EncodeInt(int64(v)) - case int16: - e.e.EncodeInt(int64(v)) - case int32: - e.e.EncodeInt(int64(v)) - case int64: - e.e.EncodeInt(v) - case uint: - e.e.EncodeUint(uint64(v)) - case uint8: - e.e.EncodeUint(uint64(v)) - case uint16: - e.e.EncodeUint(uint64(v)) - case uint32: - e.e.EncodeUint(uint64(v)) - case uint64: - e.e.EncodeUint(v) - case uintptr: - e.e.EncodeUint(uint64(v)) - case float32: - e.e.EncodeFloat32(v) - case float64: - e.e.EncodeFloat64(v) - case complex64: - e.encodeComplex64(v) - case complex128: - e.encodeComplex128(v) - case time.Time: - e.e.EncodeTime(v) - case []byte: - e.e.EncodeBytes(v) - default: - - ok = !skipFastpathTypeSwitchInDirectCall && e.dh.fastpathEncodeTypeSwitch(iv, e) - } - return -} - -func (e *encoderJsonIO) encodeValue(rv reflect.Value, fn *encFnJsonIO) { - - var ciPushes int - - var rvp reflect.Value - var rvpValid bool - -RV: - switch rv.Kind() { - case reflect.Ptr: - if rvIsNil(rv) { - e.e.EncodeNil() - goto END - } - rvpValid = true - rvp = rv - rv = rv.Elem() - - if e.h.CheckCircularRef && e.ci.canPushElemKind(rv.Kind()) { - e.ci.push(rv2i(rvp)) - ciPushes++ - } - goto RV - case reflect.Interface: - if rvIsNil(rv) { - e.e.EncodeNil() - goto END - } - rvpValid = false - rvp = reflect.Value{} - rv = rv.Elem() - fn = nil - goto RV - case reflect.Map: - if rvIsNil(rv) { - if e.h.NilCollectionToZeroLength { - e.e.WriteMapEmpty() - } else { - e.e.EncodeNil() - } - goto END - } - case reflect.Slice, reflect.Chan: - if rvIsNil(rv) { - if e.h.NilCollectionToZeroLength { - e.e.WriteArrayEmpty() - } else { - e.e.EncodeNil() - } - goto END - } - case reflect.Invalid, reflect.Func: - e.e.EncodeNil() - goto END - } - - if fn == nil { - fn = e.fn(rv.Type()) - } - - if !fn.i.addrE { - - } else if rvpValid { - rv = rvp - } else if rv.CanAddr() { - rv = rvAddr(rv, fn.i.ti.ptr) - } else { - rv = e.addrRV(rv, fn.i.ti.rt, fn.i.ti.ptr) - } - fn.fe(e, &fn.i, rv) - -END: - if ciPushes > 0 { - e.ci.pop(ciPushes) - } -} - -func (e *encoderJsonIO) encodeValueNonNil(rv reflect.Value, fn *encFnJsonIO) { - - if fn.i.addrE { - if rv.CanAddr() { - rv = rvAddr(rv, fn.i.ti.ptr) - } else { - rv = e.addrRV(rv, fn.i.ti.rt, fn.i.ti.ptr) - } - } - fn.fe(e, &fn.i, rv) -} - -func (e *encoderJsonIO) encodeAs(v interface{}, t reflect.Type, ext bool) { - if ext { - e.encodeValue(baseRV(v), e.fn(t)) - } else { - e.encodeValue(baseRV(v), e.fnNoExt(t)) - } -} - -func (e *encoderJsonIO) marshalUtf8(bs []byte, fnerr error) { - halt.onerror(fnerr) - if bs == nil { - e.e.EncodeNil() - } else { - e.e.EncodeString(stringView(bs)) - } -} - -func (e *encoderJsonIO) marshalAsis(bs []byte, fnerr error) { - halt.onerror(fnerr) - if bs == nil { - e.e.EncodeNil() - } else { - e.e.writeBytesAsis(bs) - } -} - -func (e *encoderJsonIO) marshalRaw(bs []byte, fnerr error) { - halt.onerror(fnerr) - e.e.EncodeBytes(bs) -} - -func (e *encoderJsonIO) rawBytes(vv Raw) { - v := []byte(vv) - if !e.h.Raw { - halt.errorBytes("Raw values cannot be encoded: ", v) - } - e.e.writeBytesAsis(v) -} - -func (e *encoderJsonIO) fn(t reflect.Type) *encFnJsonIO { - return e.dh.encFnViaBH(t, e.rtidFn, e.h, e.fp, false) -} - -func (e *encoderJsonIO) fnNoExt(t reflect.Type) *encFnJsonIO { - return e.dh.encFnViaBH(t, e.rtidFnNoExt, e.h, e.fp, true) -} - -func (e *encoderJsonIO) mapStart(length int) { - e.e.WriteMapStart(length) - e.c = containerMapStart -} - -func (e *encoderJsonIO) mapElemValue() { - e.e.WriteMapElemValue() - e.c = containerMapValue -} - -func (e *encoderJsonIO) arrayStart(length int) { - e.e.WriteArrayStart(length) - e.c = containerArrayStart -} - -func (e *encoderJsonIO) writerEnd() { - e.e.writerEnd() -} - -func (e *encoderJsonIO) atEndOfEncode() { - e.e.atEndOfEncode() -} - -func (e *encoderJsonIO) Reset(w io.Writer) { - if e.bytes { - halt.onerror(errEncNoResetBytesWithWriter) - } - e.reset() - if w == nil { - w = io.Discard - } - e.e.resetOutIO(w) -} - -func (e *encoderJsonIO) ResetBytes(out *[]byte) { - if !e.bytes { - halt.onerror(errEncNoResetWriterWithBytes) - } - e.resetBytes(out) -} - -func (e *encoderJsonIO) resetBytes(out *[]byte) { - e.reset() - if out == nil { - out = &bytesEncAppenderDefOut - } - e.e.resetOutBytes(out) -} - -func (helperEncDriverJsonIO) newEncoderBytes(out *[]byte, h Handle) *encoderJsonIO { - var c1 encoderJsonIO - c1.bytes = true - c1.init(h) - c1.ResetBytes(out) - return &c1 -} - -func (helperEncDriverJsonIO) newEncoderIO(out io.Writer, h Handle) *encoderJsonIO { - var c1 encoderJsonIO - c1.bytes = false - c1.init(h) - c1.Reset(out) - return &c1 -} - -func (helperEncDriverJsonIO) encFnloadFastpathUnderlying(ti *typeInfo, fp *fastpathEsJsonIO) (f *fastpathEJsonIO, u reflect.Type) { - rtid := rt2id(ti.fastpathUnderlying) - idx, ok := fastpathAvIndex(rtid) - if !ok { - return - } - f = &fp[idx] - if uint8(reflect.Array) == ti.kind { - u = reflect.ArrayOf(ti.rt.Len(), ti.elem) - } else { - u = f.rt - } - return -} - -func (helperEncDriverJsonIO) encFindRtidFn(s []encRtidFnJsonIO, rtid uintptr) (i uint, fn *encFnJsonIO) { - - var h uint - var j = uint(len(s)) -LOOP: - if i < j { - h = (i + j) >> 1 - if s[h].rtid < rtid { - i = h + 1 - } else { - j = h - } - goto LOOP - } - if i < uint(len(s)) && s[i].rtid == rtid { - fn = s[i].fn - } - return -} - -func (helperEncDriverJsonIO) encFromRtidFnSlice(fns *atomicRtidFnSlice) (s []encRtidFnJsonIO) { - if v := fns.load(); v != nil { - s = *(lowLevelToPtr[[]encRtidFnJsonIO](v)) - } - return -} - -func (dh helperEncDriverJsonIO) encFnViaBH(rt reflect.Type, fns *atomicRtidFnSlice, - x *BasicHandle, fp *fastpathEsJsonIO, checkExt bool) (fn *encFnJsonIO) { - return dh.encFnVia(rt, fns, x.typeInfos(), &x.mu, x.extHandle, fp, - checkExt, x.CheckCircularRef, x.timeBuiltin, x.binaryHandle, x.jsonHandle) -} - -func (dh helperEncDriverJsonIO) encFnVia(rt reflect.Type, fns *atomicRtidFnSlice, - tinfos *TypeInfos, mu *sync.Mutex, exth extHandle, fp *fastpathEsJsonIO, - checkExt, checkCircularRef, timeBuiltin, binaryEncoding, json bool) (fn *encFnJsonIO) { - rtid := rt2id(rt) - var sp []encRtidFnJsonIO = dh.encFromRtidFnSlice(fns) - if sp != nil { - _, fn = dh.encFindRtidFn(sp, rtid) - } - if fn == nil { - fn = dh.encFnViaLoader(rt, rtid, fns, tinfos, mu, exth, fp, checkExt, checkCircularRef, timeBuiltin, binaryEncoding, json) - } - return -} - -func (dh helperEncDriverJsonIO) encFnViaLoader(rt reflect.Type, rtid uintptr, fns *atomicRtidFnSlice, - tinfos *TypeInfos, mu *sync.Mutex, exth extHandle, fp *fastpathEsJsonIO, - checkExt, checkCircularRef, timeBuiltin, binaryEncoding, json bool) (fn *encFnJsonIO) { - - fn = dh.encFnLoad(rt, rtid, tinfos, exth, fp, checkExt, checkCircularRef, timeBuiltin, binaryEncoding, json) - var sp []encRtidFnJsonIO - mu.Lock() - sp = dh.encFromRtidFnSlice(fns) - - if sp == nil { - sp = []encRtidFnJsonIO{{rtid, fn}} - fns.store(ptrToLowLevel(&sp)) - } else { - idx, fn2 := dh.encFindRtidFn(sp, rtid) - if fn2 == nil { - sp2 := make([]encRtidFnJsonIO, len(sp)+1) - copy(sp2[idx+1:], sp[idx:]) - copy(sp2, sp[:idx]) - sp2[idx] = encRtidFnJsonIO{rtid, fn} - fns.store(ptrToLowLevel(&sp2)) - } - } - mu.Unlock() - return -} - -func (dh helperEncDriverJsonIO) encFnLoad(rt reflect.Type, rtid uintptr, tinfos *TypeInfos, - exth extHandle, fp *fastpathEsJsonIO, - checkExt, checkCircularRef, timeBuiltin, binaryEncoding, json bool) (fn *encFnJsonIO) { - fn = new(encFnJsonIO) - fi := &(fn.i) - ti := tinfos.get(rtid, rt) - fi.ti = ti - rk := reflect.Kind(ti.kind) - - if rtid == timeTypId && timeBuiltin { - fn.fe = (*encoderJsonIO).kTime - } else if rtid == rawTypId { - fn.fe = (*encoderJsonIO).raw - } else if rtid == rawExtTypId { - fn.fe = (*encoderJsonIO).rawExt - fi.addrE = true - } else if xfFn := exth.getExt(rtid, checkExt); xfFn != nil { - fi.xfTag, fi.xfFn = xfFn.tag, xfFn.ext - fn.fe = (*encoderJsonIO).ext - if rk == reflect.Struct || rk == reflect.Array { - fi.addrE = true - } - } else if ti.flagSelfer || ti.flagSelferPtr { - fn.fe = (*encoderJsonIO).selferMarshal - fi.addrE = ti.flagSelferPtr - } else if supportMarshalInterfaces && binaryEncoding && - (ti.flagBinaryMarshaler || ti.flagBinaryMarshalerPtr) && - (ti.flagBinaryUnmarshaler || ti.flagBinaryUnmarshalerPtr) { - fn.fe = (*encoderJsonIO).binaryMarshal - fi.addrE = ti.flagBinaryMarshalerPtr - } else if supportMarshalInterfaces && !binaryEncoding && json && - (ti.flagJsonMarshaler || ti.flagJsonMarshalerPtr) && - (ti.flagJsonUnmarshaler || ti.flagJsonUnmarshalerPtr) { - - fn.fe = (*encoderJsonIO).jsonMarshal - fi.addrE = ti.flagJsonMarshalerPtr - } else if supportMarshalInterfaces && !binaryEncoding && - (ti.flagTextMarshaler || ti.flagTextMarshalerPtr) && - (ti.flagTextUnmarshaler || ti.flagTextUnmarshalerPtr) { - fn.fe = (*encoderJsonIO).textMarshal - fi.addrE = ti.flagTextMarshalerPtr - } else { - if fastpathEnabled && (rk == reflect.Map || rk == reflect.Slice || rk == reflect.Array) { - - var rtid2 uintptr - if !ti.flagHasPkgPath { - rtid2 = rtid - if rk == reflect.Array { - rtid2 = rt2id(ti.key) - } - if idx, ok := fastpathAvIndex(rtid2); ok { - fn.fe = fp[idx].encfn - } - } else { - - xfe, xrt := dh.encFnloadFastpathUnderlying(ti, fp) - if xfe != nil { - xfnf := xfe.encfn - fn.fe = func(e *encoderJsonIO, xf *encFnInfo, xrv reflect.Value) { - xfnf(e, xf, rvConvert(xrv, xrt)) - } - } - } - } - if fn.fe == nil { - switch rk { - case reflect.Bool: - fn.fe = (*encoderJsonIO).kBool - case reflect.String: - - fn.fe = (*encoderJsonIO).kString - case reflect.Int: - fn.fe = (*encoderJsonIO).kInt - case reflect.Int8: - fn.fe = (*encoderJsonIO).kInt8 - case reflect.Int16: - fn.fe = (*encoderJsonIO).kInt16 - case reflect.Int32: - fn.fe = (*encoderJsonIO).kInt32 - case reflect.Int64: - fn.fe = (*encoderJsonIO).kInt64 - case reflect.Uint: - fn.fe = (*encoderJsonIO).kUint - case reflect.Uint8: - fn.fe = (*encoderJsonIO).kUint8 - case reflect.Uint16: - fn.fe = (*encoderJsonIO).kUint16 - case reflect.Uint32: - fn.fe = (*encoderJsonIO).kUint32 - case reflect.Uint64: - fn.fe = (*encoderJsonIO).kUint64 - case reflect.Uintptr: - fn.fe = (*encoderJsonIO).kUintptr - case reflect.Float32: - fn.fe = (*encoderJsonIO).kFloat32 - case reflect.Float64: - fn.fe = (*encoderJsonIO).kFloat64 - case reflect.Complex64: - fn.fe = (*encoderJsonIO).kComplex64 - case reflect.Complex128: - fn.fe = (*encoderJsonIO).kComplex128 - case reflect.Chan: - fn.fe = (*encoderJsonIO).kChan - case reflect.Slice: - fn.fe = (*encoderJsonIO).kSlice - case reflect.Array: - fn.fe = (*encoderJsonIO).kArray - case reflect.Struct: - if ti.simple { - fn.fe = (*encoderJsonIO).kStructSimple - } else { - fn.fe = (*encoderJsonIO).kStruct - } - case reflect.Map: - fn.fe = (*encoderJsonIO).kMap - case reflect.Interface: - - fn.fe = (*encoderJsonIO).kErr - default: - - fn.fe = (*encoderJsonIO).kErr - } - } - } - return -} -func (d *decoderJsonIO) rawExt(f *decFnInfo, rv reflect.Value) { - d.d.DecodeRawExt(rv2i(rv).(*RawExt)) -} - -func (d *decoderJsonIO) ext(f *decFnInfo, rv reflect.Value) { - d.d.DecodeExt(rv2i(rv), f.ti.rt, f.xfTag, f.xfFn) -} - -func (d *decoderJsonIO) selferUnmarshal(_ *decFnInfo, rv reflect.Value) { - rv2i(rv).(Selfer).CodecDecodeSelf(&Decoder{d}) -} - -func (d *decoderJsonIO) binaryUnmarshal(_ *decFnInfo, rv reflect.Value) { - bm := rv2i(rv).(encoding.BinaryUnmarshaler) - xbs, _ := d.d.DecodeBytes() - fnerr := bm.UnmarshalBinary(xbs) - halt.onerror(fnerr) -} - -func (d *decoderJsonIO) textUnmarshal(_ *decFnInfo, rv reflect.Value) { - tm := rv2i(rv).(encoding.TextUnmarshaler) - fnerr := tm.UnmarshalText(bytesOKs(d.d.DecodeStringAsBytes())) - halt.onerror(fnerr) -} - -func (d *decoderJsonIO) jsonUnmarshal(_ *decFnInfo, rv reflect.Value) { - d.jsonUnmarshalV(rv2i(rv).(jsonUnmarshaler)) -} - -func (d *decoderJsonIO) jsonUnmarshalV(tm jsonUnmarshaler) { - - halt.onerror(tm.UnmarshalJSON(d.d.nextValueBytes())) -} - -func (d *decoderJsonIO) kErr(_ *decFnInfo, rv reflect.Value) { - halt.errorf("unsupported decoding kind: %s, for %#v", rv.Kind(), rv) - -} - -func (d *decoderJsonIO) raw(_ *decFnInfo, rv reflect.Value) { - rvSetBytes(rv, d.rawBytes()) -} - -func (d *decoderJsonIO) kString(_ *decFnInfo, rv reflect.Value) { - rvSetString(rv, d.detach2Str(d.d.DecodeStringAsBytes())) -} - -func (d *decoderJsonIO) kBool(_ *decFnInfo, rv reflect.Value) { - rvSetBool(rv, d.d.DecodeBool()) -} - -func (d *decoderJsonIO) kTime(_ *decFnInfo, rv reflect.Value) { - rvSetTime(rv, d.d.DecodeTime()) -} - -func (d *decoderJsonIO) kFloat32(_ *decFnInfo, rv reflect.Value) { - rvSetFloat32(rv, d.d.DecodeFloat32()) -} - -func (d *decoderJsonIO) kFloat64(_ *decFnInfo, rv reflect.Value) { - rvSetFloat64(rv, d.d.DecodeFloat64()) -} - -func (d *decoderJsonIO) kComplex64(_ *decFnInfo, rv reflect.Value) { - rvSetComplex64(rv, complex(d.d.DecodeFloat32(), 0)) -} - -func (d *decoderJsonIO) kComplex128(_ *decFnInfo, rv reflect.Value) { - rvSetComplex128(rv, complex(d.d.DecodeFloat64(), 0)) -} - -func (d *decoderJsonIO) kInt(_ *decFnInfo, rv reflect.Value) { - rvSetInt(rv, int(chkOvf.IntV(d.d.DecodeInt64(), intBitsize))) -} - -func (d *decoderJsonIO) kInt8(_ *decFnInfo, rv reflect.Value) { - rvSetInt8(rv, int8(chkOvf.IntV(d.d.DecodeInt64(), 8))) -} - -func (d *decoderJsonIO) kInt16(_ *decFnInfo, rv reflect.Value) { - rvSetInt16(rv, int16(chkOvf.IntV(d.d.DecodeInt64(), 16))) -} - -func (d *decoderJsonIO) kInt32(_ *decFnInfo, rv reflect.Value) { - rvSetInt32(rv, int32(chkOvf.IntV(d.d.DecodeInt64(), 32))) -} - -func (d *decoderJsonIO) kInt64(_ *decFnInfo, rv reflect.Value) { - rvSetInt64(rv, d.d.DecodeInt64()) -} - -func (d *decoderJsonIO) kUint(_ *decFnInfo, rv reflect.Value) { - rvSetUint(rv, uint(chkOvf.UintV(d.d.DecodeUint64(), uintBitsize))) -} - -func (d *decoderJsonIO) kUintptr(_ *decFnInfo, rv reflect.Value) { - rvSetUintptr(rv, uintptr(chkOvf.UintV(d.d.DecodeUint64(), uintBitsize))) -} - -func (d *decoderJsonIO) kUint8(_ *decFnInfo, rv reflect.Value) { - rvSetUint8(rv, uint8(chkOvf.UintV(d.d.DecodeUint64(), 8))) -} - -func (d *decoderJsonIO) kUint16(_ *decFnInfo, rv reflect.Value) { - rvSetUint16(rv, uint16(chkOvf.UintV(d.d.DecodeUint64(), 16))) -} - -func (d *decoderJsonIO) kUint32(_ *decFnInfo, rv reflect.Value) { - rvSetUint32(rv, uint32(chkOvf.UintV(d.d.DecodeUint64(), 32))) -} - -func (d *decoderJsonIO) kUint64(_ *decFnInfo, rv reflect.Value) { - rvSetUint64(rv, d.d.DecodeUint64()) -} - -func (d *decoderJsonIO) kInterfaceNaked(f *decFnInfo) (rvn reflect.Value) { - - n := d.naked() - d.d.DecodeNaked() - - if decFailNonEmptyIntf && f.ti.numMeth > 0 { - halt.errorf("cannot decode non-nil codec value into nil %v (%v methods)", f.ti.rt, f.ti.numMeth) - } - - switch n.v { - case valueTypeMap: - mtid := d.mtid - if mtid == 0 { - if d.jsms { - mtid = mapStrIntfTypId - } else { - mtid = mapIntfIntfTypId - } - } - if mtid == mapStrIntfTypId { - var v2 map[string]interface{} - d.decode(&v2) - rvn = rv4iptr(&v2).Elem() - } else if mtid == mapIntfIntfTypId { - var v2 map[interface{}]interface{} - d.decode(&v2) - rvn = rv4iptr(&v2).Elem() - } else if d.mtr { - rvn = reflect.New(d.h.MapType) - d.decode(rv2i(rvn)) - rvn = rvn.Elem() - } else { - - rvn = rvZeroAddrK(d.h.MapType, reflect.Map) - d.decodeValue(rvn, nil) - } - case valueTypeArray: - if d.stid == 0 || d.stid == intfSliceTypId { - var v2 []interface{} - d.decode(&v2) - rvn = rv4iptr(&v2).Elem() - } else if d.str { - rvn = reflect.New(d.h.SliceType) - d.decode(rv2i(rvn)) - rvn = rvn.Elem() - } else { - rvn = rvZeroAddrK(d.h.SliceType, reflect.Slice) - d.decodeValue(rvn, nil) - } - if d.h.PreferArrayOverSlice { - rvn = rvGetArray4Slice(rvn) - } - case valueTypeExt: - tag, bytes := n.u, n.l - bfn := d.h.getExtForTag(tag) - var re = RawExt{Tag: tag} - if bytes == nil { - - if bfn == nil { - d.decode(&re.Value) - rvn = rv4iptr(&re).Elem() - } else if bfn.ext == SelfExt { - rvn = rvZeroAddrK(bfn.rt, bfn.rt.Kind()) - d.decodeValue(rvn, d.fnNoExt(bfn.rt)) - } else { - rvn = reflect.New(bfn.rt) - d.interfaceExtConvertAndDecode(rv2i(rvn), bfn.ext) - rvn = rvn.Elem() - } - } else { - - if bfn == nil { - re.setData(bytes, false) - rvn = rv4iptr(&re).Elem() - } else { - rvn = reflect.New(bfn.rt) - if bfn.ext == SelfExt { - sideDecode(d.hh, &d.h.sideDecPool, func(sd decoderI) { oneOffDecode(sd, rv2i(rvn), bytes, bfn.rt, true) }) - } else { - bfn.ext.ReadExt(rv2i(rvn), bytes) - } - rvn = rvn.Elem() - } - } - - if d.h.PreferPointerForStructOrArray && rvn.CanAddr() { - if rk := rvn.Kind(); rk == reflect.Array || rk == reflect.Struct { - rvn = rvn.Addr() - } - } - case valueTypeNil: - - case valueTypeInt: - rvn = n.ri() - case valueTypeUint: - rvn = n.ru() - case valueTypeFloat: - rvn = n.rf() - case valueTypeBool: - rvn = n.rb() - case valueTypeString, valueTypeSymbol: - rvn = n.rs() - case valueTypeBytes: - rvn = n.rl() - case valueTypeTime: - rvn = n.rt() - default: - halt.errorStr2("kInterfaceNaked: unexpected valueType: ", n.v.String()) - } - return -} - -func (d *decoderJsonIO) kInterface(f *decFnInfo, rv reflect.Value) { - - isnilrv := rvIsNil(rv) - - var rvn reflect.Value - - if d.h.InterfaceReset { - - rvn = d.h.intf2impl(f.ti.rtid) - if !rvn.IsValid() { - rvn = d.kInterfaceNaked(f) - if rvn.IsValid() { - rvSetIntf(rv, rvn) - } else if !isnilrv { - decSetNonNilRV2Zero4Intf(rv) - } - return - } - } else if isnilrv { - - rvn = d.h.intf2impl(f.ti.rtid) - if !rvn.IsValid() { - rvn = d.kInterfaceNaked(f) - if rvn.IsValid() { - rvSetIntf(rv, rvn) - } - return - } - } else { - - rvn = rv.Elem() - } - - canDecode, _ := isDecodeable(rvn) - - if !canDecode { - rvn2 := d.oneShotAddrRV(rvn.Type(), rvn.Kind()) - rvSetDirect(rvn2, rvn) - rvn = rvn2 - } - - d.decodeValue(rvn, nil) - rvSetIntf(rv, rvn) -} - -func (d *decoderJsonIO) kStructField(si *structFieldInfo, rv reflect.Value) { - if d.d.TryNil() { - rv = si.fieldNoAlloc(rv, true) - if rv.IsValid() { - decSetNonNilRV2Zero(rv) - } - } else if si.decBuiltin { - rv = rvAddr(si.fieldAlloc(rv), si.ptrTyp) - d.decode(rv2i(rv)) - } else { - fn := d.fn(si.baseTyp) - rv = si.fieldAlloc(rv) - if fn.i.addrD { - rv = rvAddr(rv, si.ptrTyp) - } - fn.fd(d, &fn.i, rv) - } -} - -func (d *decoderJsonIO) kStructSimple(f *decFnInfo, rv reflect.Value) { - _ = d.d - ctyp := d.d.ContainerType() - ti := f.ti - if ctyp == valueTypeMap { - containerLen := d.mapStart(d.d.ReadMapStart()) - if containerLen == 0 { - d.mapEnd() - return - } - hasLen := containerLen >= 0 - var rvkencname []byte - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - sab, att := d.d.DecodeStringAsBytes() - rvkencname = d.usableStructFieldNameBytes(rvkencname, sab, att) - d.mapElemValue() - if si := ti.siForEncName(rvkencname); si != nil { - d.kStructField(si, rv) - } else { - d.structFieldNotFound(-1, stringView(rvkencname)) - } - } - d.mapEnd() - } else if ctyp == valueTypeArray { - containerLen := d.arrayStart(d.d.ReadArrayStart()) - if containerLen == 0 { - d.arrayEnd() - return - } - - tisfi := ti.sfi.source() - hasLen := containerLen >= 0 - - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.arrayElem(j == 0) - if j < len(tisfi) { - d.kStructField(tisfi[j], rv) - } else { - d.structFieldNotFound(j, "") - } - } - d.arrayEnd() - } else { - halt.onerror(errNeedMapOrArrayDecodeToStruct) - } -} - -func (d *decoderJsonIO) kStruct(f *decFnInfo, rv reflect.Value) { - _ = d.d - ctyp := d.d.ContainerType() - ti := f.ti - var mf MissingFielder - if ti.flagMissingFielder { - mf = rv2i(rv).(MissingFielder) - } else if ti.flagMissingFielderPtr { - mf = rv2i(rvAddr(rv, ti.ptr)).(MissingFielder) - } - if ctyp == valueTypeMap { - containerLen := d.mapStart(d.d.ReadMapStart()) - if containerLen == 0 { - d.mapEnd() - return - } - hasLen := containerLen >= 0 - var name2 []byte - var rvkencname []byte - tkt := ti.keyType - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - - if tkt == valueTypeString { - sab, att := d.d.DecodeStringAsBytes() - rvkencname = d.usableStructFieldNameBytes(rvkencname, sab, att) - } else if tkt == valueTypeInt { - rvkencname = strconv.AppendInt(d.b[:0], d.d.DecodeInt64(), 10) - } else if tkt == valueTypeUint { - rvkencname = strconv.AppendUint(d.b[:0], d.d.DecodeUint64(), 10) - } else if tkt == valueTypeFloat { - rvkencname = strconv.AppendFloat(d.b[:0], d.d.DecodeFloat64(), 'f', -1, 64) - } else { - halt.errorStr2("invalid struct key type: ", ti.keyType.String()) - } - - d.mapElemValue() - if si := ti.siForEncName(rvkencname); si != nil { - d.kStructField(si, rv) - } else if mf != nil { - - name2 = append(name2[:0], rvkencname...) - var f interface{} - d.decode(&f) - if !mf.CodecMissingField(name2, f) && d.h.ErrorIfNoField { - halt.errorStr2("no matching struct field when decoding stream map with key: ", stringView(name2)) - } - } else { - d.structFieldNotFound(-1, stringView(rvkencname)) - } - } - d.mapEnd() - } else if ctyp == valueTypeArray { - containerLen := d.arrayStart(d.d.ReadArrayStart()) - if containerLen == 0 { - d.arrayEnd() - return - } - - tisfi := ti.sfi.source() - hasLen := containerLen >= 0 - - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.arrayElem(j == 0) - if j < len(tisfi) { - d.kStructField(tisfi[j], rv) - } else { - d.structFieldNotFound(j, "") - } - } - - d.arrayEnd() - } else { - halt.onerror(errNeedMapOrArrayDecodeToStruct) - } -} - -func (d *decoderJsonIO) kSlice(f *decFnInfo, rv reflect.Value) { - _ = d.d - - ti := f.ti - rvCanset := rv.CanSet() - - ctyp := d.d.ContainerType() - if ctyp == valueTypeBytes || ctyp == valueTypeString { - - if !(ti.rtid == uint8SliceTypId || ti.elemkind == uint8(reflect.Uint8)) { - halt.errorf("bytes/string in stream must decode into slice/array of bytes, not %v", ti.rt) - } - rvbs := rvGetBytes(rv) - if rvCanset { - bs2, bst := d.decodeBytesInto(rvbs, false) - if bst != dBytesIntoParamOut { - rvSetBytes(rv, bs2) - } - } else { - - d.decodeBytesInto(rvbs[:len(rvbs):len(rvbs)], true) - } - return - } - - var containerLenS int - isArray := ctyp == valueTypeArray - if isArray { - containerLenS = d.arrayStart(d.d.ReadArrayStart()) - } else if ctyp == valueTypeMap { - containerLenS = d.mapStart(d.d.ReadMapStart()) * 2 - } else { - halt.errorStr2("decoding into a slice, expect map/array - got ", ctyp.String()) - } - - if containerLenS == 0 { - if rvCanset { - if rvIsNil(rv) { - rvSetDirect(rv, rvSliceZeroCap(ti.rt)) - } else { - rvSetSliceLen(rv, 0) - } - } - if isArray { - d.arrayEnd() - } else { - d.mapEnd() - } - return - } - - rtelem0Mut := !scalarBitset.isset(ti.elemkind) - rtelem := ti.elem - - for k := reflect.Kind(ti.elemkind); k == reflect.Ptr; k = rtelem.Kind() { - rtelem = rtelem.Elem() - } - - var fn *decFnJsonIO - - var rvChanged bool - - var rv0 = rv - var rv9 reflect.Value - - rvlen := rvLenSlice(rv) - rvcap := rvCapSlice(rv) - maxInitLen := d.maxInitLen() - hasLen := containerLenS >= 0 - if hasLen { - if containerLenS > rvcap { - oldRvlenGtZero := rvlen > 0 - rvlen1 := int(decInferLen(containerLenS, maxInitLen, uint(ti.elemsize))) - if rvlen1 == rvlen { - } else if rvlen1 <= rvcap { - if rvCanset { - rvlen = rvlen1 - rvSetSliceLen(rv, rvlen) - } - } else if rvCanset { - rvlen = rvlen1 - rv, rvCanset = rvMakeSlice(rv, f.ti, rvlen, rvlen) - rvcap = rvlen - rvChanged = !rvCanset - } else { - halt.errorStr("cannot decode into non-settable slice") - } - if rvChanged && oldRvlenGtZero && rtelem0Mut { - rvCopySlice(rv, rv0, rtelem) - } - } else if containerLenS != rvlen { - if rvCanset { - rvlen = containerLenS - rvSetSliceLen(rv, rvlen) - } - } - } - - var elemReset = d.h.SliceElementReset - - var rtelemIsPtr bool - var rtelemElem reflect.Type - builtin := ti.tielem.flagDecBuiltin - if builtin { - rtelemIsPtr = ti.elemkind == uint8(reflect.Ptr) - if rtelemIsPtr { - rtelemElem = ti.elem.Elem() - } - } - - var j int - for ; d.containerNext(j, containerLenS, hasLen); j++ { - if j == 0 { - if rvIsNil(rv) { - if rvCanset { - rvlen = int(decInferLen(containerLenS, maxInitLen, uint(ti.elemsize))) - rv, rvCanset = rvMakeSlice(rv, f.ti, rvlen, rvlen) - rvcap = rvlen - rvChanged = !rvCanset - } else { - halt.errorStr("cannot decode into non-settable slice") - } - } - if fn == nil { - fn = d.fn(rtelem) - } - } - - if ctyp == valueTypeArray { - d.arrayElem(j == 0) - } else if j&1 == 0 { - d.mapElemKey(j == 0) - } else { - d.mapElemValue() - } - - if j >= rvlen { - - if rvlen < rvcap { - rvlen = rvcap - if rvCanset { - rvSetSliceLen(rv, rvlen) - } else if rvChanged { - rv = rvSlice(rv, rvlen) - } else { - halt.onerror(errExpandSliceCannotChange) - } - } else { - if !(rvCanset || rvChanged) { - halt.onerror(errExpandSliceCannotChange) - } - rv, rvcap, rvCanset = rvGrowSlice(rv, f.ti, rvcap, 1) - - rvlen = rvcap - rvChanged = !rvCanset - } - } - - rv9 = rvArrayIndex(rv, j, f.ti, true) - if elemReset { - rvSetZero(rv9) - } - if d.d.TryNil() { - rvSetZero(rv9) - } else if builtin { - if rtelemIsPtr { - if rvIsNil(rv9) { - rvSetDirect(rv9, reflect.New(rtelemElem)) - } - d.decode(rv2i(rv9)) - } else { - d.decode(rv2i(rvAddr(rv9, ti.tielem.ptr))) - } - } else { - d.decodeValueNoCheckNil(rv9, fn) - } - } - if j < rvlen { - if rvCanset { - rvSetSliceLen(rv, j) - } else if rvChanged { - rv = rvSlice(rv, j) - } - - } else if j == 0 && rvIsNil(rv) { - if rvCanset { - rv = rvSliceZeroCap(ti.rt) - rvCanset = false - rvChanged = true - } - } - if isArray { - d.arrayEnd() - } else { - d.mapEnd() - } - - if rvChanged { - rvSetDirect(rv0, rv) - } -} - -func (d *decoderJsonIO) kArray(f *decFnInfo, rv reflect.Value) { - _ = d.d - - ti := f.ti - ctyp := d.d.ContainerType() - if handleBytesWithinKArray && (ctyp == valueTypeBytes || ctyp == valueTypeString) { - - if ti.elemkind != uint8(reflect.Uint8) { - halt.errorf("bytes/string in stream can decode into array of bytes, but not %v", ti.rt) - } - rvbs := rvGetArrayBytes(rv, nil) - d.decodeBytesInto(rvbs, true) - return - } - - var containerLenS int - isArray := ctyp == valueTypeArray - if isArray { - containerLenS = d.arrayStart(d.d.ReadArrayStart()) - } else if ctyp == valueTypeMap { - containerLenS = d.mapStart(d.d.ReadMapStart()) * 2 - } else { - halt.errorStr2("decoding into a slice, expect map/array - got ", ctyp.String()) - } - - if containerLenS == 0 { - if isArray { - d.arrayEnd() - } else { - d.mapEnd() - } - return - } - - rtelem := ti.elem - for k := reflect.Kind(ti.elemkind); k == reflect.Ptr; k = rtelem.Kind() { - rtelem = rtelem.Elem() - } - - var rv9 reflect.Value - - rvlen := rv.Len() - hasLen := containerLenS >= 0 - if hasLen && containerLenS > rvlen { - halt.errorf("cannot decode into array with length: %v, less than container length: %v", any(rvlen), any(containerLenS)) - } - - var elemReset = d.h.SliceElementReset - - var rtelemIsPtr bool - var rtelemElem reflect.Type - var fn *decFnJsonIO - builtin := ti.tielem.flagDecBuiltin - if builtin { - rtelemIsPtr = ti.elemkind == uint8(reflect.Ptr) - if rtelemIsPtr { - rtelemElem = ti.elem.Elem() - } - } else { - fn = d.fn(rtelem) - } - - for j := 0; d.containerNext(j, containerLenS, hasLen); j++ { - if ctyp == valueTypeArray { - d.arrayElem(j == 0) - } else if j&1 == 0 { - d.mapElemKey(j == 0) - } else { - d.mapElemValue() - } - - if j >= rvlen { - d.arrayCannotExpand(rvlen, j+1) - d.swallow() - continue - } - - rv9 = rvArrayIndex(rv, j, f.ti, false) - if elemReset { - rvSetZero(rv9) - } - if d.d.TryNil() { - rvSetZero(rv9) - } else if builtin { - if rtelemIsPtr { - if rvIsNil(rv9) { - rvSetDirect(rv9, reflect.New(rtelemElem)) - } - d.decode(rv2i(rv9)) - } else { - d.decode(rv2i(rvAddr(rv9, ti.tielem.ptr))) - } - } else { - d.decodeValueNoCheckNil(rv9, fn) - } - } - if isArray { - d.arrayEnd() - } else { - d.mapEnd() - } -} - -func (d *decoderJsonIO) kChan(f *decFnInfo, rv reflect.Value) { - _ = d.d - - ti := f.ti - if ti.chandir&uint8(reflect.SendDir) == 0 { - halt.errorStr("receive-only channel cannot be decoded") - } - ctyp := d.d.ContainerType() - if ctyp == valueTypeBytes || ctyp == valueTypeString { - - if !(ti.rtid == uint8SliceTypId || ti.elemkind == uint8(reflect.Uint8)) { - halt.errorf("bytes/string in stream must decode into slice/array of bytes, not %v", ti.rt) - } - bs2, _ := d.d.DecodeBytes() - irv := rv2i(rv) - ch, ok := irv.(chan<- byte) - if !ok { - ch = irv.(chan byte) - } - for _, b := range bs2 { - ch <- b - } - return - } - - var rvCanset = rv.CanSet() - - var containerLenS int - isArray := ctyp == valueTypeArray - if isArray { - containerLenS = d.arrayStart(d.d.ReadArrayStart()) - } else if ctyp == valueTypeMap { - containerLenS = d.mapStart(d.d.ReadMapStart()) * 2 - } else { - halt.errorStr2("decoding into a slice, expect map/array - got ", ctyp.String()) - } - - if containerLenS == 0 { - if rvCanset && rvIsNil(rv) { - rvSetDirect(rv, reflect.MakeChan(ti.rt, 0)) - } - if isArray { - d.arrayEnd() - } else { - d.mapEnd() - } - return - } - - rtelem := ti.elem - useTransient := decUseTransient && ti.elemkind != byte(reflect.Ptr) && ti.tielem.flagCanTransient - - for k := reflect.Kind(ti.elemkind); k == reflect.Ptr; k = rtelem.Kind() { - rtelem = rtelem.Elem() - } - - var fn *decFnJsonIO - - var rvChanged bool - var rv0 = rv - var rv9 reflect.Value - - var rvlen int - hasLen := containerLenS >= 0 - maxInitLen := d.maxInitLen() - - for j := 0; d.containerNext(j, containerLenS, hasLen); j++ { - if j == 0 { - if rvIsNil(rv) { - if hasLen { - rvlen = int(decInferLen(containerLenS, maxInitLen, uint(ti.elemsize))) - } else { - rvlen = decDefChanCap - } - if rvCanset { - rv = reflect.MakeChan(ti.rt, rvlen) - rvChanged = true - } else { - halt.errorStr("cannot decode into non-settable chan") - } - } - if fn == nil { - fn = d.fn(rtelem) - } - } - - if ctyp == valueTypeArray { - d.arrayElem(j == 0) - } else if j&1 == 0 { - d.mapElemKey(j == 0) - } else { - d.mapElemValue() - } - - if rv9.IsValid() { - rvSetZero(rv9) - } else if useTransient { - rv9 = d.perType.TransientAddrK(ti.elem, reflect.Kind(ti.elemkind)) - } else { - rv9 = rvZeroAddrK(ti.elem, reflect.Kind(ti.elemkind)) - } - if !d.d.TryNil() { - d.decodeValueNoCheckNil(rv9, fn) - } - rv.Send(rv9) - } - if isArray { - d.arrayEnd() - } else { - d.mapEnd() - } - - if rvChanged { - rvSetDirect(rv0, rv) - } - -} - -func (d *decoderJsonIO) kMap(f *decFnInfo, rv reflect.Value) { - _ = d.d - containerLen := d.mapStart(d.d.ReadMapStart()) - ti := f.ti - if rvIsNil(rv) { - rvlen := int(decInferLen(containerLen, d.maxInitLen(), uint(ti.keysize+ti.elemsize))) - rvSetDirect(rv, makeMapReflect(ti.rt, rvlen)) - } - - if containerLen == 0 { - d.mapEnd() - return - } - - ktype, vtype := ti.key, ti.elem - ktypeId := rt2id(ktype) - vtypeKind := reflect.Kind(ti.elemkind) - ktypeKind := reflect.Kind(ti.keykind) - mparams := getMapReqParams(ti) - - vtypePtr := vtypeKind == reflect.Ptr - ktypePtr := ktypeKind == reflect.Ptr - - vTransient := decUseTransient && !vtypePtr && ti.tielem.flagCanTransient - - kTransient := vTransient && !ktypePtr && ti.tikey.flagCanTransient - - var vtypeElem reflect.Type - - var keyFn, valFn *decFnJsonIO - var ktypeLo, vtypeLo = ktype, vtype - - if ktypeKind == reflect.Ptr { - for ktypeLo = ktype.Elem(); ktypeLo.Kind() == reflect.Ptr; ktypeLo = ktypeLo.Elem() { - } - } - - if vtypePtr { - vtypeElem = vtype.Elem() - for vtypeLo = vtypeElem; vtypeLo.Kind() == reflect.Ptr; vtypeLo = vtypeLo.Elem() { - } - } - - rvkMut := !scalarBitset.isset(ti.keykind) - rvvMut := !scalarBitset.isset(ti.elemkind) - rvvCanNil := isnilBitset.isset(ti.elemkind) - - var rvk, rvkn, rvv, rvvn, rvva, rvvz reflect.Value - - var doMapGet, doMapSet bool - - if !d.h.MapValueReset { - if rvvMut && (vtypeKind != reflect.Interface || !d.h.InterfaceReset) { - doMapGet = true - rvva = mapAddrLoopvarRV(vtype, vtypeKind) - } - } - - ktypeIsString := ktypeId == stringTypId - ktypeIsIntf := ktypeId == intfTypId - hasLen := containerLen >= 0 - - var kstr2bs []byte - var kstr string - - var mapKeyStringSharesBytesBuf bool - var att dBytesAttachState - - var vElem, kElem reflect.Type - kbuiltin := ti.tikey.flagDecBuiltin && ti.keykind != uint8(reflect.Slice) - vbuiltin := ti.tielem.flagDecBuiltin - if kbuiltin && ktypePtr { - kElem = ti.key.Elem() - } - if vbuiltin && vtypePtr { - vElem = ti.elem.Elem() - } - - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - mapKeyStringSharesBytesBuf = false - kstr = "" - if j == 0 { - - if kTransient { - rvk = d.perType.TransientAddr2K(ktype, ktypeKind) - } else { - rvk = rvZeroAddrK(ktype, ktypeKind) - } - if !rvkMut { - rvkn = rvk - } - if !rvvMut { - if vTransient { - rvvn = d.perType.TransientAddrK(vtype, vtypeKind) - } else { - rvvn = rvZeroAddrK(vtype, vtypeKind) - } - } - if !ktypeIsString && keyFn == nil { - keyFn = d.fn(ktypeLo) - } - if valFn == nil { - valFn = d.fn(vtypeLo) - } - } else if rvkMut { - rvSetZero(rvk) - } else { - rvk = rvkn - } - - d.mapElemKey(j == 0) - - if d.d.TryNil() { - rvSetZero(rvk) - } else if ktypeIsString { - kstr2bs, att = d.d.DecodeStringAsBytes() - kstr, mapKeyStringSharesBytesBuf = d.bytes2Str(kstr2bs, att) - rvSetString(rvk, kstr) - } else { - if kbuiltin { - if ktypePtr { - if rvIsNil(rvk) { - rvSetDirect(rvk, reflect.New(kElem)) - } - d.decode(rv2i(rvk)) - } else { - d.decode(rv2i(rvAddr(rvk, ti.tikey.ptr))) - } - } else { - d.decodeValueNoCheckNil(rvk, keyFn) - } - - if ktypeIsIntf { - if rvk2 := rvk.Elem(); rvk2.IsValid() && rvk2.Type() == uint8SliceTyp { - kstr2bs = rvGetBytes(rvk2) - kstr, mapKeyStringSharesBytesBuf = d.bytes2Str(kstr2bs, dBytesAttachView) - rvSetIntf(rvk, rv4istr(kstr)) - } - - } - } - - if mapKeyStringSharesBytesBuf && d.bufio { - if ktypeIsString { - rvSetString(rvk, d.detach2Str(kstr2bs, att)) - } else { - rvSetIntf(rvk, rv4istr(d.detach2Str(kstr2bs, att))) - } - mapKeyStringSharesBytesBuf = false - } - - d.mapElemValue() - - if d.d.TryNil() { - if mapKeyStringSharesBytesBuf { - if ktypeIsString { - rvSetString(rvk, d.detach2Str(kstr2bs, att)) - } else { - rvSetIntf(rvk, rv4istr(d.detach2Str(kstr2bs, att))) - } - } - - if !rvvz.IsValid() { - rvvz = rvZeroK(vtype, vtypeKind) - } - mapSet(rv, rvk, rvvz, mparams) - continue - } - - doMapSet = true - - if !rvvMut { - rvv = rvvn - } else if !doMapGet { - goto NEW_RVV - } else { - rvv = mapGet(rv, rvk, rvva, mparams) - if !rvv.IsValid() || (rvvCanNil && rvIsNil(rvv)) { - goto NEW_RVV - } - switch vtypeKind { - case reflect.Ptr, reflect.Map: - doMapSet = false - case reflect.Interface: - - rvvn = rvv.Elem() - if k := rvvn.Kind(); (k == reflect.Ptr || k == reflect.Map) && !rvIsNil(rvvn) { - d.decodeValueNoCheckNil(rvvn, nil) - continue - } - - rvvn = rvZeroAddrK(vtype, vtypeKind) - rvSetIntf(rvvn, rvv) - rvv = rvvn - default: - - if vTransient { - rvvn = d.perType.TransientAddrK(vtype, vtypeKind) - } else { - rvvn = rvZeroAddrK(vtype, vtypeKind) - } - rvSetDirect(rvvn, rvv) - rvv = rvvn - } - } - goto DECODE_VALUE_NO_CHECK_NIL - - NEW_RVV: - if vtypePtr { - rvv = reflect.New(vtypeElem) - } else if vTransient { - rvv = d.perType.TransientAddrK(vtype, vtypeKind) - } else { - rvv = rvZeroAddrK(vtype, vtypeKind) - } - - DECODE_VALUE_NO_CHECK_NIL: - if doMapSet && mapKeyStringSharesBytesBuf { - if ktypeIsString { - rvSetString(rvk, d.detach2Str(kstr2bs, att)) - } else { - rvSetIntf(rvk, rv4istr(d.detach2Str(kstr2bs, att))) - } - } - if vbuiltin { - if vtypePtr { - if rvIsNil(rvv) { - rvSetDirect(rvv, reflect.New(vElem)) - } - d.decode(rv2i(rvv)) - } else { - d.decode(rv2i(rvAddr(rvv, ti.tielem.ptr))) - } - } else { - d.decodeValueNoCheckNil(rvv, valFn) - } - if doMapSet { - mapSet(rv, rvk, rvv, mparams) - } - } - - d.mapEnd() -} - -func (d *decoderJsonIO) init(h Handle) { - initHandle(h) - callMake(&d.d) - d.hh = h - d.h = h.getBasicHandle() - - d.err = errDecoderNotInitialized - - if d.h.InternString && d.is == nil { - d.is.init() - } - - d.fp = d.d.init(h, &d.decoderBase, d).(*fastpathDsJsonIO) - - if d.bytes { - d.rtidFn = &d.h.rtidFnsDecBytes - d.rtidFnNoExt = &d.h.rtidFnsDecNoExtBytes - } else { - d.bufio = d.h.ReaderBufferSize > 0 - d.rtidFn = &d.h.rtidFnsDecIO - d.rtidFnNoExt = &d.h.rtidFnsDecNoExtIO - } - - d.reset() - -} - -func (d *decoderJsonIO) reset() { - d.d.reset() - d.err = nil - d.c = 0 - d.depth = 0 - d.calls = 0 - - d.maxdepth = decDefMaxDepth - if d.h.MaxDepth > 0 { - d.maxdepth = d.h.MaxDepth - } - d.mtid = 0 - d.stid = 0 - d.mtr = false - d.str = false - if d.h.MapType != nil { - d.mtid = rt2id(d.h.MapType) - _, d.mtr = fastpathAvIndex(d.mtid) - } - if d.h.SliceType != nil { - d.stid = rt2id(d.h.SliceType) - _, d.str = fastpathAvIndex(d.stid) - } -} - -func (d *decoderJsonIO) Reset(r io.Reader) { - if d.bytes { - halt.onerror(errDecNoResetBytesWithReader) - } - d.reset() - if r == nil { - r = &eofReader - } - d.d.resetInIO(r) -} - -func (d *decoderJsonIO) ResetBytes(in []byte) { - if !d.bytes { - halt.onerror(errDecNoResetReaderWithBytes) - } - d.resetBytes(in) -} - -func (d *decoderJsonIO) resetBytes(in []byte) { - d.reset() - if in == nil { - in = zeroByteSlice - } - d.d.resetInBytes(in) -} - -func (d *decoderJsonIO) ResetString(s string) { - d.ResetBytes(bytesView(s)) -} - -func (d *decoderJsonIO) Decode(v interface{}) (err error) { - - defer panicValToErr(d, callRecoverSentinel, &d.err, &err, debugging) - d.mustDecode(v) - return -} - -func (d *decoderJsonIO) MustDecode(v interface{}) { - defer panicValToErr(d, callRecoverSentinel, &d.err, nil, true) - d.mustDecode(v) - return -} - -func (d *decoderJsonIO) mustDecode(v interface{}) { - halt.onerror(d.err) - if d.hh == nil { - halt.onerror(errNoFormatHandle) - } - - d.calls++ - d.decode(v) - d.calls-- -} - -func (d *decoderJsonIO) Release() {} - -func (d *decoderJsonIO) swallow() { - d.d.nextValueBytes() -} - -func (d *decoderJsonIO) nextValueBytes() []byte { - return d.d.nextValueBytes() -} - -func (d *decoderJsonIO) decode(iv interface{}) { - _ = d.d - - rv, ok := isNil(iv, true) - if ok { - halt.onerror(errCannotDecodeIntoNil) - } - - switch v := iv.(type) { - - case *string: - *v = d.detach2Str(d.d.DecodeStringAsBytes()) - case *bool: - *v = d.d.DecodeBool() - case *int: - *v = int(chkOvf.IntV(d.d.DecodeInt64(), intBitsize)) - case *int8: - *v = int8(chkOvf.IntV(d.d.DecodeInt64(), 8)) - case *int16: - *v = int16(chkOvf.IntV(d.d.DecodeInt64(), 16)) - case *int32: - *v = int32(chkOvf.IntV(d.d.DecodeInt64(), 32)) - case *int64: - *v = d.d.DecodeInt64() - case *uint: - *v = uint(chkOvf.UintV(d.d.DecodeUint64(), uintBitsize)) - case *uint8: - *v = uint8(chkOvf.UintV(d.d.DecodeUint64(), 8)) - case *uint16: - *v = uint16(chkOvf.UintV(d.d.DecodeUint64(), 16)) - case *uint32: - *v = uint32(chkOvf.UintV(d.d.DecodeUint64(), 32)) - case *uint64: - *v = d.d.DecodeUint64() - case *uintptr: - *v = uintptr(chkOvf.UintV(d.d.DecodeUint64(), uintBitsize)) - case *float32: - *v = d.d.DecodeFloat32() - case *float64: - *v = d.d.DecodeFloat64() - case *complex64: - *v = complex(d.d.DecodeFloat32(), 0) - case *complex128: - *v = complex(d.d.DecodeFloat64(), 0) - case *[]byte: - *v, _ = d.decodeBytesInto(*v, false) - case []byte: - - d.decodeBytesInto(v[:len(v):len(v)], true) - case *time.Time: - *v = d.d.DecodeTime() - case *Raw: - *v = d.rawBytes() - - case *interface{}: - d.decodeValue(rv4iptr(v), nil) - - case reflect.Value: - if ok, _ = isDecodeable(v); !ok { - d.haltAsNotDecodeable(v) - } - d.decodeValue(v, nil) - - default: - - if skipFastpathTypeSwitchInDirectCall || !d.dh.fastpathDecodeTypeSwitch(iv, d) { - if !rv.IsValid() { - rv = reflect.ValueOf(iv) - } - if ok, _ = isDecodeable(rv); !ok { - d.haltAsNotDecodeable(rv) - } - d.decodeValue(rv, nil) - } - } -} - -func (d *decoderJsonIO) decodeValue(rv reflect.Value, fn *decFnJsonIO) { - if d.d.TryNil() { - decSetNonNilRV2Zero(rv) - } else { - d.decodeValueNoCheckNil(rv, fn) - } -} - -func (d *decoderJsonIO) decodeValueNoCheckNil(rv reflect.Value, fn *decFnJsonIO) { - - var rvp reflect.Value - var rvpValid bool -PTR: - if rv.Kind() == reflect.Ptr { - rvpValid = true - if rvIsNil(rv) { - rvSetDirect(rv, reflect.New(rv.Type().Elem())) - } - rvp = rv - rv = rv.Elem() - goto PTR - } - - if fn == nil { - fn = d.fn(rv.Type()) - } - if fn.i.addrD { - if rvpValid { - rv = rvp - } else if rv.CanAddr() { - rv = rvAddr(rv, fn.i.ti.ptr) - } else if fn.i.addrDf { - halt.errorStr("cannot decode into a non-pointer value") - } - } - fn.fd(d, &fn.i, rv) -} - -func (d *decoderJsonIO) decodeAs(v interface{}, t reflect.Type, ext bool) { - if ext { - d.decodeValue(baseRV(v), d.fn(t)) - } else { - d.decodeValue(baseRV(v), d.fnNoExt(t)) - } -} - -func (d *decoderJsonIO) structFieldNotFound(index int, rvkencname string) { - - if d.h.ErrorIfNoField { - if index >= 0 { - halt.errorInt("no matching struct field found when decoding stream array at index ", int64(index)) - } else if rvkencname != "" { - halt.errorStr2("no matching struct field found when decoding stream map with key ", rvkencname) - } - } - d.swallow() -} - -func (d *decoderJsonIO) decodeBytesInto(out []byte, mustFit bool) (v []byte, state dBytesIntoState) { - v, att := d.d.DecodeBytes() - if cap(v) == 0 || (att >= dBytesAttachViewZerocopy && !mustFit) { - - return - } - if len(v) == 0 { - v = zeroByteSlice - return - } - if len(out) == len(v) { - state = dBytesIntoParamOut - } else if cap(out) >= len(v) { - out = out[:len(v)] - state = dBytesIntoParamOutSlice - } else if mustFit { - halt.errorf("bytes capacity insufficient for decoded bytes: got/expected: %d/%d", len(v), len(out)) - } else { - out = make([]byte, len(v)) - state = dBytesIntoNew - } - copy(out, v) - v = out - return -} - -func (d *decoderJsonIO) rawBytes() (v []byte) { - - v = d.d.nextValueBytes() - if d.bytes && !d.h.ZeroCopy { - vv := make([]byte, len(v)) - copy(vv, v) - v = vv - } - return -} - -func (d *decoderJsonIO) wrapErr(v error, err *error) { - *err = wrapCodecErr(v, d.hh.Name(), d.d.NumBytesRead(), false) -} - -func (d *decoderJsonIO) NumBytesRead() int { - return d.d.NumBytesRead() -} - -func (d *decoderJsonIO) containerNext(j, containerLen int, hasLen bool) bool { - - if hasLen { - return j < containerLen - } - return !d.d.CheckBreak() -} - -func (d *decoderJsonIO) mapElemKey(firstTime bool) { - d.d.ReadMapElemKey(firstTime) - d.c = containerMapKey -} - -func (d *decoderJsonIO) mapElemValue() { - d.d.ReadMapElemValue() - d.c = containerMapValue -} - -func (d *decoderJsonIO) mapEnd() { - d.d.ReadMapEnd() - d.depthDecr() - d.c = 0 -} - -func (d *decoderJsonIO) arrayElem(firstTime bool) { - d.d.ReadArrayElem(firstTime) - d.c = containerArrayElem -} - -func (d *decoderJsonIO) arrayEnd() { - d.d.ReadArrayEnd() - d.depthDecr() - d.c = 0 -} - -func (d *decoderJsonIO) interfaceExtConvertAndDecode(v interface{}, ext InterfaceExt) { - - var vv interface{} - d.decode(&vv) - ext.UpdateExt(v, vv) - -} - -func (d *decoderJsonIO) fn(t reflect.Type) *decFnJsonIO { - return d.dh.decFnViaBH(t, d.rtidFn, d.h, d.fp, false) -} - -func (d *decoderJsonIO) fnNoExt(t reflect.Type) *decFnJsonIO { - return d.dh.decFnViaBH(t, d.rtidFnNoExt, d.h, d.fp, true) -} - -func (helperDecDriverJsonIO) newDecoderBytes(in []byte, h Handle) *decoderJsonIO { - var c1 decoderJsonIO - c1.bytes = true - c1.init(h) - c1.ResetBytes(in) - return &c1 -} - -func (helperDecDriverJsonIO) newDecoderIO(in io.Reader, h Handle) *decoderJsonIO { - var c1 decoderJsonIO - c1.init(h) - c1.Reset(in) - return &c1 -} - -func (helperDecDriverJsonIO) decFnloadFastpathUnderlying(ti *typeInfo, fp *fastpathDsJsonIO) (f *fastpathDJsonIO, u reflect.Type) { - rtid := rt2id(ti.fastpathUnderlying) - idx, ok := fastpathAvIndex(rtid) - if !ok { - return - } - f = &fp[idx] - if uint8(reflect.Array) == ti.kind { - u = reflect.ArrayOf(ti.rt.Len(), ti.elem) - } else { - u = f.rt - } - return -} - -func (helperDecDriverJsonIO) decFindRtidFn(s []decRtidFnJsonIO, rtid uintptr) (i uint, fn *decFnJsonIO) { - - var h uint - var j = uint(len(s)) -LOOP: - if i < j { - h = (i + j) >> 1 - if s[h].rtid < rtid { - i = h + 1 - } else { - j = h - } - goto LOOP - } - if i < uint(len(s)) && s[i].rtid == rtid { - fn = s[i].fn - } - return -} - -func (helperDecDriverJsonIO) decFromRtidFnSlice(fns *atomicRtidFnSlice) (s []decRtidFnJsonIO) { - if v := fns.load(); v != nil { - s = *(lowLevelToPtr[[]decRtidFnJsonIO](v)) - } - return -} - -func (dh helperDecDriverJsonIO) decFnViaBH(rt reflect.Type, fns *atomicRtidFnSlice, x *BasicHandle, fp *fastpathDsJsonIO, - checkExt bool) (fn *decFnJsonIO) { - return dh.decFnVia(rt, fns, x.typeInfos(), &x.mu, x.extHandle, fp, - checkExt, x.CheckCircularRef, x.timeBuiltin, x.binaryHandle, x.jsonHandle) -} - -func (dh helperDecDriverJsonIO) decFnVia(rt reflect.Type, fns *atomicRtidFnSlice, - tinfos *TypeInfos, mu *sync.Mutex, exth extHandle, fp *fastpathDsJsonIO, - checkExt, checkCircularRef, timeBuiltin, binaryEncoding, json bool) (fn *decFnJsonIO) { - rtid := rt2id(rt) - var sp []decRtidFnJsonIO = dh.decFromRtidFnSlice(fns) - if sp != nil { - _, fn = dh.decFindRtidFn(sp, rtid) - } - if fn == nil { - fn = dh.decFnViaLoader(rt, rtid, fns, tinfos, mu, exth, fp, checkExt, checkCircularRef, timeBuiltin, binaryEncoding, json) - } - return -} - -func (dh helperDecDriverJsonIO) decFnViaLoader(rt reflect.Type, rtid uintptr, fns *atomicRtidFnSlice, - tinfos *TypeInfos, mu *sync.Mutex, exth extHandle, fp *fastpathDsJsonIO, - checkExt, checkCircularRef, timeBuiltin, binaryEncoding, json bool) (fn *decFnJsonIO) { - - fn = dh.decFnLoad(rt, rtid, tinfos, exth, fp, checkExt, checkCircularRef, timeBuiltin, binaryEncoding, json) - var sp []decRtidFnJsonIO - mu.Lock() - sp = dh.decFromRtidFnSlice(fns) - - if sp == nil { - sp = []decRtidFnJsonIO{{rtid, fn}} - fns.store(ptrToLowLevel(&sp)) - } else { - idx, fn2 := dh.decFindRtidFn(sp, rtid) - if fn2 == nil { - sp2 := make([]decRtidFnJsonIO, len(sp)+1) - copy(sp2[idx+1:], sp[idx:]) - copy(sp2, sp[:idx]) - sp2[idx] = decRtidFnJsonIO{rtid, fn} - fns.store(ptrToLowLevel(&sp2)) - } - } - mu.Unlock() - return -} - -func (dh helperDecDriverJsonIO) decFnLoad(rt reflect.Type, rtid uintptr, tinfos *TypeInfos, - exth extHandle, fp *fastpathDsJsonIO, - checkExt, checkCircularRef, timeBuiltin, binaryEncoding, json bool) (fn *decFnJsonIO) { - fn = new(decFnJsonIO) - fi := &(fn.i) - ti := tinfos.get(rtid, rt) - fi.ti = ti - rk := reflect.Kind(ti.kind) - - fi.addrDf = true - - if rtid == timeTypId && timeBuiltin { - fn.fd = (*decoderJsonIO).kTime - } else if rtid == rawTypId { - fn.fd = (*decoderJsonIO).raw - } else if rtid == rawExtTypId { - fn.fd = (*decoderJsonIO).rawExt - fi.addrD = true - } else if xfFn := exth.getExt(rtid, checkExt); xfFn != nil { - fi.xfTag, fi.xfFn = xfFn.tag, xfFn.ext - fn.fd = (*decoderJsonIO).ext - fi.addrD = true - } else if ti.flagSelfer || ti.flagSelferPtr { - fn.fd = (*decoderJsonIO).selferUnmarshal - fi.addrD = ti.flagSelferPtr - } else if supportMarshalInterfaces && binaryEncoding && - (ti.flagBinaryMarshaler || ti.flagBinaryMarshalerPtr) && - (ti.flagBinaryUnmarshaler || ti.flagBinaryUnmarshalerPtr) { - fn.fd = (*decoderJsonIO).binaryUnmarshal - fi.addrD = ti.flagBinaryUnmarshalerPtr - } else if supportMarshalInterfaces && !binaryEncoding && json && - (ti.flagJsonMarshaler || ti.flagJsonMarshalerPtr) && - (ti.flagJsonUnmarshaler || ti.flagJsonUnmarshalerPtr) { - - fn.fd = (*decoderJsonIO).jsonUnmarshal - fi.addrD = ti.flagJsonUnmarshalerPtr - } else if supportMarshalInterfaces && !binaryEncoding && - (ti.flagTextMarshaler || ti.flagTextMarshalerPtr) && - (ti.flagTextUnmarshaler || ti.flagTextUnmarshalerPtr) { - fn.fd = (*decoderJsonIO).textUnmarshal - fi.addrD = ti.flagTextUnmarshalerPtr - } else { - if fastpathEnabled && (rk == reflect.Map || rk == reflect.Slice || rk == reflect.Array) { - var rtid2 uintptr - if !ti.flagHasPkgPath { - rtid2 = rtid - if rk == reflect.Array { - rtid2 = rt2id(ti.key) - } - if idx, ok := fastpathAvIndex(rtid2); ok { - fn.fd = fp[idx].decfn - fi.addrD = true - fi.addrDf = false - if rk == reflect.Array { - fi.addrD = false - } - } - } else { - - xfe, xrt := dh.decFnloadFastpathUnderlying(ti, fp) - if xfe != nil { - xfnf2 := xfe.decfn - if rk == reflect.Array { - fi.addrD = false - fn.fd = func(d *decoderJsonIO, xf *decFnInfo, xrv reflect.Value) { - xfnf2(d, xf, rvConvert(xrv, xrt)) - } - } else { - fi.addrD = true - fi.addrDf = false - xptr2rt := reflect.PointerTo(xrt) - fn.fd = func(d *decoderJsonIO, xf *decFnInfo, xrv reflect.Value) { - if xrv.Kind() == reflect.Ptr { - xfnf2(d, xf, rvConvert(xrv, xptr2rt)) - } else { - xfnf2(d, xf, rvConvert(xrv, xrt)) - } - } - } - } - } - } - if fn.fd == nil { - switch rk { - case reflect.Bool: - fn.fd = (*decoderJsonIO).kBool - case reflect.String: - fn.fd = (*decoderJsonIO).kString - case reflect.Int: - fn.fd = (*decoderJsonIO).kInt - case reflect.Int8: - fn.fd = (*decoderJsonIO).kInt8 - case reflect.Int16: - fn.fd = (*decoderJsonIO).kInt16 - case reflect.Int32: - fn.fd = (*decoderJsonIO).kInt32 - case reflect.Int64: - fn.fd = (*decoderJsonIO).kInt64 - case reflect.Uint: - fn.fd = (*decoderJsonIO).kUint - case reflect.Uint8: - fn.fd = (*decoderJsonIO).kUint8 - case reflect.Uint16: - fn.fd = (*decoderJsonIO).kUint16 - case reflect.Uint32: - fn.fd = (*decoderJsonIO).kUint32 - case reflect.Uint64: - fn.fd = (*decoderJsonIO).kUint64 - case reflect.Uintptr: - fn.fd = (*decoderJsonIO).kUintptr - case reflect.Float32: - fn.fd = (*decoderJsonIO).kFloat32 - case reflect.Float64: - fn.fd = (*decoderJsonIO).kFloat64 - case reflect.Complex64: - fn.fd = (*decoderJsonIO).kComplex64 - case reflect.Complex128: - fn.fd = (*decoderJsonIO).kComplex128 - case reflect.Chan: - fn.fd = (*decoderJsonIO).kChan - case reflect.Slice: - fn.fd = (*decoderJsonIO).kSlice - case reflect.Array: - fi.addrD = false - fn.fd = (*decoderJsonIO).kArray - case reflect.Struct: - if ti.simple { - fn.fd = (*decoderJsonIO).kStructSimple - } else { - fn.fd = (*decoderJsonIO).kStruct - } - case reflect.Map: - fn.fd = (*decoderJsonIO).kMap - case reflect.Interface: - - fn.fd = (*decoderJsonIO).kInterface - default: - - fn.fd = (*decoderJsonIO).kErr - } - } - } - return -} -func (e *jsonEncDriverIO) writeIndent() { - e.w.writen1('\n') - x := int(e.di) * int(e.dl) - if e.di < 0 { - x = -x - for x > len(jsonTabs) { - e.w.writeb(jsonTabs[:]) - x -= len(jsonTabs) - } - e.w.writeb(jsonTabs[:x]) - } else { - for x > len(jsonSpaces) { - e.w.writeb(jsonSpaces[:]) - x -= len(jsonSpaces) - } - e.w.writeb(jsonSpaces[:x]) - } -} - -func (e *jsonEncDriverIO) WriteArrayElem(firstTime bool) { - if !firstTime { - e.w.writen1(',') - } - if e.d { - e.writeIndent() - } -} - -func (e *jsonEncDriverIO) WriteMapElemKey(firstTime bool) { - if !firstTime { - e.w.writen1(',') - } - if e.d { - e.writeIndent() - } -} - -func (e *jsonEncDriverIO) WriteMapElemValue() { - if e.d { - e.w.writen2(':', ' ') - } else { - e.w.writen1(':') - } -} - -func (e *jsonEncDriverIO) EncodeNil() { - - e.w.writeb(jsonNull) -} - -func (e *jsonEncDriverIO) encodeIntAsUint(v int64, quotes bool) { - neg := v < 0 - if neg { - v = -v - } - e.encodeUint(neg, quotes, uint64(v)) -} - -func (e *jsonEncDriverIO) EncodeTime(t time.Time) { - - if t.IsZero() { - e.EncodeNil() - return - } - switch e.timeFmt { - case jsonTimeFmtStringLayout: - e.b[0] = '"' - b := t.AppendFormat(e.b[1:1], e.timeFmtLayout) - e.b[len(b)+1] = '"' - e.w.writeb(e.b[:len(b)+2]) - case jsonTimeFmtUnix: - e.encodeIntAsUint(t.Unix(), false) - case jsonTimeFmtUnixMilli: - e.encodeIntAsUint(t.UnixMilli(), false) - case jsonTimeFmtUnixMicro: - e.encodeIntAsUint(t.UnixMicro(), false) - case jsonTimeFmtUnixNano: - e.encodeIntAsUint(t.UnixNano(), false) - } -} - -func (e *jsonEncDriverIO) EncodeExt(rv interface{}, basetype reflect.Type, xtag uint64, ext Ext) { - if ext == SelfExt { - e.enc.encodeAs(rv, basetype, false) - } else if v := ext.ConvertExt(rv); v == nil { - e.writeNilBytes() - } else { - e.enc.encodeI(v) - } -} - -func (e *jsonEncDriverIO) EncodeRawExt(re *RawExt) { - if re.Data != nil { - e.w.writeb(re.Data) - } else if re.Value != nil { - e.enc.encodeI(re.Value) - } else { - e.EncodeNil() - } -} - -func (e *jsonEncDriverIO) EncodeBool(b bool) { - e.w.writestr(jsonEncBoolStrs[bool2int(e.ks && e.e.c == containerMapKey)%2][bool2int(b)%2]) -} - -func (e *jsonEncDriverIO) encodeFloat(f float64, bitsize, fmt byte, prec int8) { - var blen uint - if e.ks && e.e.c == containerMapKey { - blen = 2 + uint(len(strconv.AppendFloat(e.b[1:1], f, fmt, int(prec), int(bitsize)))) - - e.b[0] = '"' - e.b[blen-1] = '"' - e.w.writeb(e.b[:blen]) - } else { - e.w.writeb(strconv.AppendFloat(e.b[:0], f, fmt, int(prec), int(bitsize))) - } -} - -func (e *jsonEncDriverIO) EncodeFloat64(f float64) { - if math.IsNaN(f) || math.IsInf(f, 0) { - e.EncodeNil() - return - } - fmt, prec := jsonFloatStrconvFmtPrec64(f) - e.encodeFloat(f, 64, fmt, prec) -} - -func (e *jsonEncDriverIO) EncodeFloat32(f float32) { - if math.IsNaN(float64(f)) || math.IsInf(float64(f), 0) { - e.EncodeNil() - return - } - fmt, prec := jsonFloatStrconvFmtPrec32(f) - e.encodeFloat(float64(f), 32, fmt, prec) -} - -func (e *jsonEncDriverIO) encodeUint(neg bool, quotes bool, u uint64) { - e.w.writeb(jsonEncodeUint(neg, quotes, u, &e.b)) -} - -func (e *jsonEncDriverIO) EncodeInt(v int64) { - quotes := e.is == 'A' || e.is == 'L' && (v > 1<<53 || v < -(1<<53)) || - (e.ks && e.e.c == containerMapKey) - - if cpu32Bit { - if quotes { - blen := 2 + len(strconv.AppendInt(e.b[1:1], v, 10)) - e.b[0] = '"' - e.b[blen-1] = '"' - e.w.writeb(e.b[:blen]) - } else { - e.w.writeb(strconv.AppendInt(e.b[:0], v, 10)) - } - return - } - - if v < 0 { - e.encodeUint(true, quotes, uint64(-v)) - } else { - e.encodeUint(false, quotes, uint64(v)) - } -} - -func (e *jsonEncDriverIO) EncodeUint(v uint64) { - quotes := e.is == 'A' || e.is == 'L' && v > 1<<53 || - (e.ks && e.e.c == containerMapKey) - - if cpu32Bit { - - if quotes { - blen := 2 + len(strconv.AppendUint(e.b[1:1], v, 10)) - e.b[0] = '"' - e.b[blen-1] = '"' - e.w.writeb(e.b[:blen]) - } else { - e.w.writeb(strconv.AppendUint(e.b[:0], v, 10)) - } - return - } - - e.encodeUint(false, quotes, v) -} - -func (e *jsonEncDriverIO) EncodeString(v string) { - if e.h.StringToRaw { - e.EncodeStringBytesRaw(bytesView(v)) - return - } - e.quoteStr(v) -} - -func (e *jsonEncDriverIO) EncodeStringNoEscape4Json(v string) { e.w.writeqstr(v) } - -func (e *jsonEncDriverIO) EncodeStringBytesRaw(v []byte) { - if e.rawext { - - iv := e.h.RawBytesExt.ConvertExt(any(v)) - if iv == nil { - e.EncodeNil() - } else { - e.enc.encodeI(iv) - } - return - } - - if e.bytesFmt == jsonBytesFmtArray { - e.WriteArrayStart(len(v)) - for j := range v { - e.WriteArrayElem(j == 0) - e.encodeUint(false, false, uint64(v[j])) - } - e.WriteArrayEnd() - return - } - - var slen int - if e.bytesFmt == jsonBytesFmtBase64 { - slen = base64.StdEncoding.EncodedLen(len(v)) - } else { - slen = e.byteFmter.EncodedLen(len(v)) - } - slen += 2 - - bs := e.e.blist.peek(slen, false)[:slen] - - if e.bytesFmt == jsonBytesFmtBase64 { - base64.StdEncoding.Encode(bs[1:], v) - } else { - e.byteFmter.Encode(bs[1:], v) - } - - bs[len(bs)-1] = '"' - bs[0] = '"' - e.w.writeb(bs) -} - -func (e *jsonEncDriverIO) EncodeBytes(v []byte) { - if v == nil { - e.writeNilBytes() - return - } - e.EncodeStringBytesRaw(v) -} - -func (e *jsonEncDriverIO) writeNilOr(v []byte) { - if !e.h.NilCollectionToZeroLength { - v = jsonNull - } - e.w.writeb(v) -} - -func (e *jsonEncDriverIO) writeNilBytes() { - e.writeNilOr(jsonArrayEmpty) -} - -func (e *jsonEncDriverIO) writeNilArray() { - e.writeNilOr(jsonArrayEmpty) -} - -func (e *jsonEncDriverIO) writeNilMap() { - e.writeNilOr(jsonMapEmpty) -} - -func (e *jsonEncDriverIO) WriteArrayEmpty() { - e.w.writen2('[', ']') -} - -func (e *jsonEncDriverIO) WriteMapEmpty() { - e.w.writen2('{', '}') -} - -func (e *jsonEncDriverIO) WriteArrayStart(length int) { - if e.d { - e.dl++ - } - e.w.writen1('[') -} - -func (e *jsonEncDriverIO) WriteArrayEnd() { - if e.d { - e.dl-- - - e.writeIndent() - } - e.w.writen1(']') -} - -func (e *jsonEncDriverIO) WriteMapStart(length int) { - if e.d { - e.dl++ - } - e.w.writen1('{') -} - -func (e *jsonEncDriverIO) WriteMapEnd() { - if e.d { - e.dl-- - - e.writeIndent() - } - e.w.writen1('}') -} - -func (e *jsonEncDriverIO) quoteStr(s string) { - - const hex = "0123456789abcdef" - e.w.writen1('"') - var i, start uint - for i < uint(len(s)) { - - b := s[i] - if e.s.isset(b) { - i++ - continue - } - if b < utf8.RuneSelf { - if start < i { - e.w.writestr(s[start:i]) - } - switch b { - case '\\': - e.w.writen2('\\', '\\') - case '"': - e.w.writen2('\\', '"') - case '\n': - e.w.writen2('\\', 'n') - case '\t': - e.w.writen2('\\', 't') - case '\r': - e.w.writen2('\\', 'r') - case '\b': - e.w.writen2('\\', 'b') - case '\f': - e.w.writen2('\\', 'f') - default: - e.w.writestr(`\u00`) - e.w.writen2(hex[b>>4], hex[b&0xF]) - } - i++ - start = i - continue - } - c, size := utf8.DecodeRuneInString(s[i:]) - if c == utf8.RuneError && size == 1 { - if start < i { - e.w.writestr(s[start:i]) - } - e.w.writestr(`\uFFFD`) - i++ - start = i - continue - } - - if jsonEscapeMultiByteUnicodeSep && (c == '\u2028' || c == '\u2029') { - if start < i { - e.w.writestr(s[start:i]) - } - e.w.writestr(`\u202`) - e.w.writen1(hex[c&0xF]) - i += uint(size) - start = i - continue - } - i += uint(size) - } - if start < uint(len(s)) { - e.w.writestr(s[start:]) - } - e.w.writen1('"') -} - -func (e *jsonEncDriverIO) atEndOfEncode() { - if e.h.TermWhitespace { - var c byte = ' ' - if e.e.c != 0 { - c = '\n' - } - e.w.writen1(c) - } -} - -func (d *jsonDecDriverIO) ReadMapStart() int { - d.advance() - if d.tok == 'n' { - d.checkLit3([3]byte{'u', 'l', 'l'}, d.r.readn3()) - return containerLenNil - } - if d.tok != '{' { - halt.errorByte("read map - expect char '{' but got char: ", d.tok) - } - d.tok = 0 - return containerLenUnknown -} - -func (d *jsonDecDriverIO) ReadArrayStart() int { - d.advance() - if d.tok == 'n' { - d.checkLit3([3]byte{'u', 'l', 'l'}, d.r.readn3()) - return containerLenNil - } - if d.tok != '[' { - halt.errorByte("read array - expect char '[' but got char ", d.tok) - } - d.tok = 0 - return containerLenUnknown -} - -func (d *jsonDecDriverIO) CheckBreak() bool { - d.advance() - return d.tok == '}' || d.tok == ']' -} - -func (d *jsonDecDriverIO) checkSep(xc byte) { - d.advance() - if d.tok != xc { - d.readDelimError(xc) - } - d.tok = 0 -} - -func (d *jsonDecDriverIO) ReadArrayElem(firstTime bool) { - if !firstTime { - d.checkSep(',') - } -} - -func (d *jsonDecDriverIO) ReadArrayEnd() { - d.checkSep(']') -} - -func (d *jsonDecDriverIO) ReadMapElemKey(firstTime bool) { - d.ReadArrayElem(firstTime) -} - -func (d *jsonDecDriverIO) ReadMapElemValue() { - d.checkSep(':') -} - -func (d *jsonDecDriverIO) ReadMapEnd() { - d.checkSep('}') -} - -func (d *jsonDecDriverIO) readDelimError(xc uint8) { - halt.errorf("read json delimiter - expect char '%c' but got char '%c'", xc, d.tok) -} - -func (d *jsonDecDriverIO) checkLit3(got, expect [3]byte) { - if jsonValidateSymbols && got != expect { - jsonCheckLitErr3(got, expect) - } - d.tok = 0 -} - -func (d *jsonDecDriverIO) checkLit4(got, expect [4]byte) { - if jsonValidateSymbols && got != expect { - jsonCheckLitErr4(got, expect) - } - d.tok = 0 -} - -func (d *jsonDecDriverIO) skipWhitespace() { - d.tok = d.r.skipWhitespace() -} - -func (d *jsonDecDriverIO) advance() { - - if d.tok < 33 { - d.skipWhitespace() - } -} - -func (d *jsonDecDriverIO) nextValueBytes() []byte { - consumeString := func() { - TOP: - _, c := d.r.jsonReadAsisChars() - if c == '\\' { - d.r.readn1() - goto TOP - } - } - - d.advance() - d.r.startRecording() - - switch d.tok { - default: - _, d.tok = d.r.jsonReadNum() - case 'n': - d.checkLit3([3]byte{'u', 'l', 'l'}, d.r.readn3()) - case 'f': - d.checkLit4([4]byte{'a', 'l', 's', 'e'}, d.r.readn4()) - case 't': - d.checkLit3([3]byte{'r', 'u', 'e'}, d.r.readn3()) - case '"': - consumeString() - d.tok = 0 - case '{', '[': - var elem struct{} - var stack []struct{} - - stack = append(stack, elem) - - for len(stack) != 0 { - c := d.r.readn1() - switch c { - case '"': - consumeString() - case '{', '[': - stack = append(stack, elem) - case '}', ']': - stack = stack[:len(stack)-1] - } - } - d.tok = 0 - } - return d.r.stopRecording() -} - -func (d *jsonDecDriverIO) TryNil() bool { - d.advance() - - if d.tok == 'n' { - d.checkLit3([3]byte{'u', 'l', 'l'}, d.r.readn3()) - return true - } - return false -} - -func (d *jsonDecDriverIO) DecodeBool() (v bool) { - d.advance() - - fquot := d.d.c == containerMapKey && d.tok == '"' - if fquot { - d.tok = d.r.readn1() - } - switch d.tok { - case 'f': - d.checkLit4([4]byte{'a', 'l', 's', 'e'}, d.r.readn4()) - - case 't': - d.checkLit3([3]byte{'r', 'u', 'e'}, d.r.readn3()) - v = true - case 'n': - d.checkLit3([3]byte{'u', 'l', 'l'}, d.r.readn3()) - - default: - halt.errorByte("decode bool: got first char: ", d.tok) - - } - if fquot { - d.r.readn1() - } - return -} - -func (d *jsonDecDriverIO) DecodeTime() (t time.Time) { - - d.advance() - if d.tok == 'n' { - d.checkLit3([3]byte{'u', 'l', 'l'}, d.r.readn3()) - return - } - var bs []byte - - if d.tok != '"' { - bs, d.tok = d.r.jsonReadNum() - i := d.parseInt64(bs) - switch d.timeFmtNum { - case jsonTimeFmtUnix: - t = time.Unix(i, 0) - case jsonTimeFmtUnixMilli: - t = time.UnixMilli(i) - case jsonTimeFmtUnixMicro: - t = time.UnixMicro(i) - case jsonTimeFmtUnixNano: - t = time.Unix(0, i) - default: - halt.errorStr("invalid timeFmtNum") - } - return - } - - bs = d.readUnescapedString() - var err error - for _, v := range d.timeFmtLayouts { - t, err = time.Parse(v, stringView(bs)) - if err == nil { - return - } - } - halt.errorStr("error decoding time") - return -} - -func (d *jsonDecDriverIO) ContainerType() (vt valueType) { - - d.advance() - - if d.tok == '{' { - return valueTypeMap - } else if d.tok == '[' { - return valueTypeArray - } else if d.tok == 'n' { - d.checkLit3([3]byte{'u', 'l', 'l'}, d.r.readn3()) - return valueTypeNil - } else if d.tok == '"' { - return valueTypeString - } - return valueTypeUnset -} - -func (d *jsonDecDriverIO) decNumBytes() (bs []byte) { - d.advance() - if d.tok == '"' { - bs = d.r.jsonReadUntilDblQuote() - d.tok = 0 - } else if d.tok == 'n' { - d.checkLit3([3]byte{'u', 'l', 'l'}, d.r.readn3()) - } else { - bs, d.tok = d.r.jsonReadNum() - } - return -} - -func (d *jsonDecDriverIO) DecodeUint64() (u uint64) { - b := d.decNumBytes() - u, neg, ok := parseInteger_bytes(b) - if neg { - halt.errorf("negative number cannot be decoded as uint64: %s", any(b)) - } - if !ok { - halt.onerror(strconvParseErr(b, "ParseUint")) - } - return -} - -func (d *jsonDecDriverIO) DecodeInt64() (v int64) { - return d.parseInt64(d.decNumBytes()) -} - -func (d *jsonDecDriverIO) parseInt64(b []byte) (v int64) { - u, neg, ok := parseInteger_bytes(b) - if !ok { - halt.onerror(strconvParseErr(b, "ParseInt")) - } - if chkOvf.Uint2Int(u, neg) { - halt.errorBytes("overflow decoding number from ", b) - } - if neg { - v = -int64(u) - } else { - v = int64(u) - } - return -} - -func (d *jsonDecDriverIO) DecodeFloat64() (f float64) { - var err error - bs := d.decNumBytes() - if len(bs) == 0 { - return - } - f, err = parseFloat64(bs) - halt.onerror(err) - return -} - -func (d *jsonDecDriverIO) DecodeFloat32() (f float32) { - var err error - bs := d.decNumBytes() - if len(bs) == 0 { - return - } - f, err = parseFloat32(bs) - halt.onerror(err) - return -} - -func (d *jsonDecDriverIO) advanceNil() (ok bool) { - d.advance() - if d.tok == 'n' { - d.checkLit3([3]byte{'u', 'l', 'l'}, d.r.readn3()) - return true - } - return false -} - -func (d *jsonDecDriverIO) DecodeExt(rv interface{}, basetype reflect.Type, xtag uint64, ext Ext) { - if d.advanceNil() { - return - } - if ext == SelfExt { - d.dec.decodeAs(rv, basetype, false) - } else { - d.dec.interfaceExtConvertAndDecode(rv, ext) - } -} - -func (d *jsonDecDriverIO) DecodeRawExt(re *RawExt) { - if d.advanceNil() { - return - } - d.dec.decode(&re.Value) -} - -func (d *jsonDecDriverIO) decBytesFromArray(bs []byte) []byte { - d.advance() - if d.tok != ']' { - bs = append(bs, uint8(d.DecodeUint64())) - d.advance() - } - for d.tok != ']' { - if d.tok != ',' { - halt.errorByte("read array element - expect char ',' but got char: ", d.tok) - } - d.tok = 0 - bs = append(bs, uint8(chkOvf.UintV(d.DecodeUint64(), 8))) - d.advance() - } - d.tok = 0 - return bs -} - -func (d *jsonDecDriverIO) DecodeBytes() (bs []byte, state dBytesAttachState) { - d.advance() - state = dBytesDetach - if d.tok == 'n' { - d.checkLit3([3]byte{'u', 'l', 'l'}, d.r.readn3()) - return - } - state = dBytesAttachBuffer - - if d.rawext { - d.buf = d.buf[:0] - d.dec.interfaceExtConvertAndDecode(&d.buf, d.h.RawBytesExt) - bs = d.buf - return - } - - if d.tok == '[' { - d.tok = 0 - - bs = d.decBytesFromArray(d.buf[:0]) - d.buf = bs - return - } - - d.ensureReadingString() - bs1 := d.readUnescapedString() - - slen := base64.StdEncoding.DecodedLen(len(bs1)) - if slen == 0 { - bs = zeroByteSlice - state = dBytesDetach - } else if slen <= cap(d.buf) { - bs = d.buf[:slen] - } else { - d.buf = d.d.blist.putGet(d.buf, slen)[:slen] - bs = d.buf - } - var err error - for _, v := range d.byteFmters { - - slen, err = v.Decode(bs, bs1) - if err == nil { - bs = bs[:slen] - return - } - } - halt.errorf("error decoding byte string '%s': %v", any(bs1), err) - return -} - -func (d *jsonDecDriverIO) DecodeStringAsBytes() (bs []byte, state dBytesAttachState) { - d.advance() - - var cond bool - - if d.tok == '"' { - d.tok = 0 - bs, cond = d.dblQuoteStringAsBytes() - state = d.d.attachState(cond) - return - } - - state = dBytesDetach - - switch d.tok { - case 'n': - d.checkLit3([3]byte{'u', 'l', 'l'}, d.r.readn3()) - - case 'f': - d.checkLit4([4]byte{'a', 'l', 's', 'e'}, d.r.readn4()) - bs = jsonLitb[jsonLitF : jsonLitF+5] - case 't': - d.checkLit3([3]byte{'r', 'u', 'e'}, d.r.readn3()) - bs = jsonLitb[jsonLitT : jsonLitT+4] - default: - - bs, d.tok = d.r.jsonReadNum() - state = d.d.attachState(!d.d.bytes) - } - return -} - -func (d *jsonDecDriverIO) ensureReadingString() { - if d.tok != '"' { - halt.errorByte("expecting string starting with '\"'; got ", d.tok) - } -} - -func (d *jsonDecDriverIO) readUnescapedString() (bs []byte) { - - bs = d.r.jsonReadUntilDblQuote() - d.tok = 0 - return -} - -func (d *jsonDecDriverIO) dblQuoteStringAsBytes() (buf []byte, usingBuf bool) { - bs, c := d.r.jsonReadAsisChars() - if c == '"' { - return bs, !d.d.bytes - } - buf = append(d.buf[:0], bs...) - - checkUtf8 := d.h.ValidateUnicode - usingBuf = true - - for { - - c = d.r.readn1() - - switch c { - case '"', '\\', '/', '\'': - buf = append(buf, c) - case 'b': - buf = append(buf, '\b') - case 'f': - buf = append(buf, '\f') - case 'n': - buf = append(buf, '\n') - case 'r': - buf = append(buf, '\r') - case 't': - buf = append(buf, '\t') - case 'u': - rr := d.appendStringAsBytesSlashU() - if checkUtf8 && rr == unicode.ReplacementChar { - d.buf = buf - halt.errorBytes("invalid UTF-8 character found after: ", buf) - } - buf = append(buf, d.bstr[:utf8.EncodeRune(d.bstr[:], rr)]...) - default: - d.buf = buf - halt.errorByte("unsupported escaped value: ", c) - } - - bs, c = d.r.jsonReadAsisChars() - buf = append(buf, bs...) - if c == '"' { - break - } - } - d.buf = buf - return -} - -func (d *jsonDecDriverIO) appendStringAsBytesSlashU() (r rune) { - var rr uint32 - cs := d.r.readn4() - if rr = jsonSlashURune(cs); rr == unicode.ReplacementChar { - return unicode.ReplacementChar - } - r = rune(rr) - if utf16.IsSurrogate(r) { - csu := d.r.readn2() - cs = d.r.readn4() - if csu[0] == '\\' && csu[1] == 'u' { - if rr = jsonSlashURune(cs); rr == unicode.ReplacementChar { - return unicode.ReplacementChar - } - return utf16.DecodeRune(r, rune(rr)) - } - return unicode.ReplacementChar - } - return -} - -func (d *jsonDecDriverIO) DecodeNaked() { - z := d.d.naked() - - d.advance() - var bs []byte - var err error - switch d.tok { - case 'n': - d.checkLit3([3]byte{'u', 'l', 'l'}, d.r.readn3()) - z.v = valueTypeNil - case 'f': - d.checkLit4([4]byte{'a', 'l', 's', 'e'}, d.r.readn4()) - z.v = valueTypeBool - z.b = false - case 't': - d.checkLit3([3]byte{'r', 'u', 'e'}, d.r.readn3()) - z.v = valueTypeBool - z.b = true - case '{': - z.v = valueTypeMap - case '[': - z.v = valueTypeArray - case '"': - - d.tok = 0 - bs, z.b = d.dblQuoteStringAsBytes() - att := d.d.attachState(z.b) - if jsonNakedBoolNumInQuotedStr && - d.h.MapKeyAsString && len(bs) > 0 && d.d.c == containerMapKey { - switch string(bs) { - - case "true": - z.v = valueTypeBool - z.b = true - case "false": - z.v = valueTypeBool - z.b = false - default: - if err = jsonNakedNum(z, bs, d.h.PreferFloat, d.h.SignedInteger); err != nil { - z.v = valueTypeString - z.s = d.d.detach2Str(bs, att) - } - } - } else { - z.v = valueTypeString - z.s = d.d.detach2Str(bs, att) - } - default: - bs, d.tok = d.r.jsonReadNum() - if len(bs) == 0 { - halt.errorStr("decode number from empty string") - } - if err = jsonNakedNum(z, bs, d.h.PreferFloat, d.h.SignedInteger); err != nil { - halt.errorf("decode number from %s: %v", any(bs), err) - } - } -} - -func (e *jsonEncDriverIO) reset() { - e.dl = 0 - - e.typical = e.h.typical() - if e.h.HTMLCharsAsIs { - e.s = &jsonCharSafeBitset - } else { - e.s = &jsonCharHtmlSafeBitset - } - e.di = int8(e.h.Indent) - e.d = e.h.Indent != 0 - e.ks = e.h.MapKeyAsString - e.is = e.h.IntegerAsString - - var ho jsonHandleOpts - ho.reset(e.h) - e.timeFmt = ho.timeFmt - e.bytesFmt = ho.bytesFmt - e.timeFmtLayout = "" - e.byteFmter = nil - if len(ho.timeFmtLayouts) > 0 { - e.timeFmtLayout = ho.timeFmtLayouts[0] - } - if len(ho.byteFmters) > 0 { - e.byteFmter = ho.byteFmters[0] - } - e.rawext = ho.rawext -} - -func (d *jsonDecDriverIO) reset() { - d.buf = d.d.blist.check(d.buf, 256) - d.tok = 0 - - d.jsonHandleOpts.reset(d.h) -} - -func (d *jsonEncDriverIO) init(hh Handle, shared *encoderBase, enc encoderI) (fp interface{}) { - callMake(&d.w) - d.h = hh.(*JsonHandle) - d.e = shared - if shared.bytes { - fp = jsonFpEncBytes - } else { - fp = jsonFpEncIO - } - - d.init2(enc) - return -} - -func (e *jsonEncDriverIO) writeBytesAsis(b []byte) { e.w.writeb(b) } - -func (e *jsonEncDriverIO) writerEnd() { e.w.end() } - -func (e *jsonEncDriverIO) resetOutBytes(out *[]byte) { - e.w.resetBytes(*out, out) -} - -func (e *jsonEncDriverIO) resetOutIO(out io.Writer) { - e.w.resetIO(out, e.h.WriterBufferSize, &e.e.blist) -} - -func (d *jsonDecDriverIO) init(hh Handle, shared *decoderBase, dec decoderI) (fp interface{}) { - callMake(&d.r) - d.h = hh.(*JsonHandle) - d.d = shared - if shared.bytes { - fp = jsonFpDecBytes - } else { - fp = jsonFpDecIO - } - - d.init2(dec) - return -} - -func (d *jsonDecDriverIO) NumBytesRead() int { - return int(d.r.numread()) -} - -func (d *jsonDecDriverIO) resetInBytes(in []byte) { - d.r.resetBytes(in) -} - -func (d *jsonDecDriverIO) resetInIO(r io.Reader) { - d.r.resetIO(r, d.h.ReaderBufferSize, d.h.MaxInitLen, &d.d.blist) -} - -func (d *jsonDecDriverIO) descBd() (s string) { - halt.onerror(errJsonNoBd) - return -} - -func (d *jsonEncDriverIO) init2(enc encoderI) { - d.enc = enc - -} - -func (d *jsonDecDriverIO) init2(dec decoderI) { - d.dec = dec - - d.buf = d.buf[:0] - - d.d.jsms = d.h.MapKeyAsString -} diff --git a/vendor/github.com/ugorji/go/codec/json.notfastpath.mono.generated.go b/vendor/github.com/ugorji/go/codec/json.notfastpath.mono.generated.go deleted file mode 100644 index d23c173be..000000000 --- a/vendor/github.com/ugorji/go/codec/json.notfastpath.mono.generated.go +++ /dev/null @@ -1,52 +0,0 @@ -//go:build !notmono && !codec.notmono && (notfastpath || codec.notfastpath) - -// Copyright (c) 2012-2020 Ugorji Nwoke. All rights reserved. -// Use of this source code is governed by a MIT license found in the LICENSE file. - -package codec - -import ( - "reflect" -) - -type fastpathEJsonBytes struct { - rt reflect.Type - encfn func(*encoderJsonBytes, *encFnInfo, reflect.Value) -} -type fastpathDJsonBytes struct { - rt reflect.Type - decfn func(*decoderJsonBytes, *decFnInfo, reflect.Value) -} -type fastpathEsJsonBytes [0]fastpathEJsonBytes -type fastpathDsJsonBytes [0]fastpathDJsonBytes - -func (helperEncDriverJsonBytes) fastpathEncodeTypeSwitch(iv interface{}, e *encoderJsonBytes) bool { - return false -} -func (helperDecDriverJsonBytes) fastpathDecodeTypeSwitch(iv interface{}, d *decoderJsonBytes) bool { - return false -} - -func (helperEncDriverJsonBytes) fastpathEList() (v *fastpathEsJsonBytes) { return } -func (helperDecDriverJsonBytes) fastpathDList() (v *fastpathDsJsonBytes) { return } - -type fastpathEJsonIO struct { - rt reflect.Type - encfn func(*encoderJsonIO, *encFnInfo, reflect.Value) -} -type fastpathDJsonIO struct { - rt reflect.Type - decfn func(*decoderJsonIO, *decFnInfo, reflect.Value) -} -type fastpathEsJsonIO [0]fastpathEJsonIO -type fastpathDsJsonIO [0]fastpathDJsonIO - -func (helperEncDriverJsonIO) fastpathEncodeTypeSwitch(iv interface{}, e *encoderJsonIO) bool { - return false -} -func (helperDecDriverJsonIO) fastpathDecodeTypeSwitch(iv interface{}, d *decoderJsonIO) bool { - return false -} - -func (helperEncDriverJsonIO) fastpathEList() (v *fastpathEsJsonIO) { return } -func (helperDecDriverJsonIO) fastpathDList() (v *fastpathDsJsonIO) { return } diff --git a/vendor/github.com/ugorji/go/codec/mammoth_test.go.tmpl b/vendor/github.com/ugorji/go/codec/mammoth_test.go.tmpl deleted file mode 100644 index f6a02436e..000000000 --- a/vendor/github.com/ugorji/go/codec/mammoth_test.go.tmpl +++ /dev/null @@ -1,324 +0,0 @@ -//go:build !codec.notmammoth - -// Copyright (c) 2012-2020 Ugorji Nwoke. All rights reserved. -// Use of this source code is governed by a MIT license found in the LICENSE file. - -// Code generated from mammoth_test.go.tmpl - DO NOT EDIT. - -package codec - -import "testing" -import "fmt" -import "reflect" - -// TestMammoth has all the different paths optimized in fastpath -// It has all the primitives, slices and maps. -// -// For each of those types, it has a pointer and a non-pointer field. - -func init() { _ = fmt.Printf } // so we can include fmt as needed - -type TestMammoth struct { - -{{range .Values }}{{if .Primitive -}} -{{ .MethodNamePfx "F" true }} {{ .Primitive }} -{{ .MethodNamePfx "Fptr" true }} *{{ .Primitive }} -{{end}}{{end}} - -{{range .Values }}{{if not .Primitive }}{{if not .MapKey -}} -{{ .MethodNamePfx "F" false }} []{{ .Elem }} -{{ .MethodNamePfx "Fptr" false }} *[]{{ .Elem }} -{{ .MethodNamePfx "Farr4" false }} [4]{{ .Elem }} -{{end}}{{end}}{{end}} - -{{range .Values }}{{if not .Primitive }}{{if .MapKey -}} -{{ .MethodNamePfx "F" false }} map[{{ .MapKey }}]{{ .Elem }} -{{ .MethodNamePfx "Fptr" false }} *map[{{ .MapKey }}]{{ .Elem }} -{{end}}{{end}}{{end}} - -} - -// ----------- - -// Increase codecoverage by covering all the codecgen paths, in fastpath .... -// -// Note: even though this is built based on fastpath, we will run these tests -// in all modes, including notfastpath, etc. -// -// Add test file for creating a mammoth generated file as _mammoth_generated.go -// -// Now, add some types: -// - some that implement BinaryMarshal, TextMarshal, JSONMarshal, and one that implements none of it -// - create a wrapper type that includes TestMammoth2, with it in slices, and maps, and the custom types -// - this wrapper object is what we work encode/decode (so that the codecgen methods are called) - -type testMammoth2Binary uint64 -func (x testMammoth2Binary) MarshalBinary() (data []byte, err error) { -data = make([]byte, 8) -bigenstd.PutUint64(data, uint64(x)) -return -} -func (x *testMammoth2Binary) UnmarshalBinary(data []byte) (err error) { -*x = testMammoth2Binary(bigenstd.Uint64(data)) -return -} - -type testMammoth2Text uint64 -func (x testMammoth2Text) MarshalText() (data []byte, err error) { -data = []byte(fmt.Sprintf("%b", uint64(x))) -return -} -func (x *testMammoth2Text) UnmarshalText(data []byte) (err error) { -_, err = fmt.Sscanf(string(data), "%b", (*uint64)(x)) -return -} - -type testMammoth2Json uint64 -func (x testMammoth2Json) MarshalJSON() (data []byte, err error) { -data = []byte(fmt.Sprintf("%v", uint64(x))) -return -} -func (x *testMammoth2Json) UnmarshalJSON(data []byte) (err error) { -_, err = fmt.Sscanf(string(data), "%v", (*uint64)(x)) -return -} - -type testMammoth2Basic [4]uint64 - -type TestMammoth2Wrapper struct { - V TestMammoth - T testMammoth2Text - B testMammoth2Binary - J testMammoth2Json - C testMammoth2Basic - M map[testMammoth2Basic]TestMammoth - L []TestMammoth - A [4]int64 - - Tcomplex128 complex128 - Tcomplex64 complex64 - Tbytes []uint8 - Tpbytes *[]uint8 -} - -// ----------- - -{{range .Values }}{{if not .Primitive }}{{if not .MapKey -}} -type {{ .MethodNamePfx "typMbs" false }} []{{ .Elem }} -func (_ {{ .MethodNamePfx "typMbs" false }}) MapBySlice() { } -{{end}}{{end}}{{end}} - -{{range .Values }}{{if not .Primitive }}{{if .MapKey -}} -type {{ .MethodNamePfx "typMap" false }} map[{{ .MapKey }}]{{ .Elem }} -{{end}}{{end}}{{end}} - -func __doTestMammothSlices(t *testing.T, h Handle) { -{{range $i, $e := .Values }}{{if not .Primitive }}{{if not .MapKey -}} - var v{{$i}}va [8]{{ .Elem }} - for _, v := range [][]{{ .Elem }}{ nil, {}, { {{ nonzerocmd .Elem }}, {{ zerocmd .Elem }}, {{ zerocmd .Elem }}, {{ nonzerocmd .Elem }} } } { - {{/* - // fmt.Printf(">>>> running mammoth slice v{{$i}}: %v\n", v) - // - encode value to some []byte - // - decode into a length-wise-equal []byte - // - check if equal to initial slice - // - encode ptr to the value - // - check if encode bytes are same - // - decode into ptrs to: nil, then 1-elem slice, equal-length, then large len slice - // - decode into non-addressable slice of equal length, then larger len - // - for each decode, compare elem-by-elem to the original slice - // - - // - rinse and repeat for a MapBySlice version - // - - */ -}} - var v{{$i}}v1, v{{$i}}v2 []{{ .Elem }} - var bs{{$i}} []byte - v{{$i}}v1 = v - bs{{$i}} = testMarshalErr(v{{$i}}v1, h, t, "enc-slice-v{{$i}}") - if v == nil { - v{{$i}}v2 = make([]{{ .Elem }}, 2) - testUnmarshalErr(v{{$i}}v2, bs{{$i}}, h, t, "dec-slice-v{{$i}}") - testDeepEqualErr(v{{$i}}v2[0], v{{$i}}v2[1], t, "equal-slice-v{{$i}}") // should not change - testDeepEqualErr(len(v{{$i}}v2), 2, t, "equal-slice-v{{$i}}") // should not change - v{{$i}}v2 = make([]{{ .Elem }}, 2) - testUnmarshalErr(reflect.ValueOf(v{{$i}}v2), bs{{$i}}, h, t, "dec-slice-v{{$i}}-noaddr") // non-addressable value - testDeepEqualErr(v{{$i}}v2[0], v{{$i}}v2[1], t, "equal-slice-v{{$i}}-noaddr") // should not change - testDeepEqualErr(len(v{{$i}}v2), 2, t, "equal-slice-v{{$i}}") // should not change - } else { - v{{$i}}v2 = make([]{{ .Elem }}, len(v)) - testUnmarshalErr(v{{$i}}v2, bs{{$i}}, h, t, "dec-slice-v{{$i}}") - testDeepEqualErrHandle(v{{$i}}v1, v{{$i}}v2, h, t, "equal-slice-v{{$i}}") - v{{$i}}v2 = make([]{{ .Elem }}, len(v)) - testUnmarshalErr(reflect.ValueOf(v{{$i}}v2), bs{{$i}}, h, t, "dec-slice-v{{$i}}-noaddr") // non-addressable value - testDeepEqualErrHandle(v{{$i}}v1, v{{$i}}v2, h, t, "equal-slice-v{{$i}}-noaddr") - } - testReleaseBytes(bs{{$i}}) - // ... - bs{{$i}} = testMarshalErr(&v{{$i}}v1, h, t, "enc-slice-v{{$i}}-p") - v{{$i}}v2 = nil - testUnmarshalErr(&v{{$i}}v2, bs{{$i}}, h, t, "dec-slice-v{{$i}}-p") - testDeepEqualErrHandle(v{{$i}}v1, v{{$i}}v2, h, t, "equal-slice-v{{$i}}-p") - v{{$i}}va = [8]{{ .Elem }}{} // clear the array - testUnmarshalErr(&v{{$i}}va, bs{{$i}}, h, t, "dec-array-v{{$i}}-p-1") - if v{{$i}}v1 == nil && v{{$i}}v2 == nil { v{{$i}}v2 = []{{ .Elem }}{} } // so we can compare to zero len slice below - testDeepEqualErrHandle(v{{$i}}va[:len(v{{$i}}v2)], v{{$i}}v2, h, t, "equal-array-v{{$i}}-p-1") - v{{$i}}va = [8]{{ .Elem }}{} // clear the array - v{{$i}}v2 = v{{$i}}va[:1:1] - testUnmarshalErr(&v{{$i}}v2, bs{{$i}}, h, t, "dec-slice-v{{$i}}-p-1") - testDeepEqualErrHandle(v{{$i}}v1, v{{$i}}v2, h, t, "equal-slice-v{{$i}}-p-1") - v{{$i}}va = [8]{{ .Elem }}{} // clear the array - v{{$i}}v2 = v{{$i}}va[:len(v{{$i}}v1):len(v{{$i}}v1)] - testUnmarshalErr(&v{{$i}}v2, bs{{$i}}, h, t, "dec-slice-v{{$i}}-p-len") - testDeepEqualErrHandle(v{{$i}}v1, v{{$i}}v2, h, t, "equal-slice-v{{$i}}-p-len") - v{{$i}}va = [8]{{ .Elem }}{} // clear the array - v{{$i}}v2 = v{{$i}}va[:] - testUnmarshalErr(&v{{$i}}v2, bs{{$i}}, h, t, "dec-slice-v{{$i}}-p-cap") - testDeepEqualErrHandle(v{{$i}}v1, v{{$i}}v2, h, t, "equal-slice-v{{$i}}-p-cap") - if len(v{{$i}}v1) > 1 { - v{{$i}}va = [8]{{ .Elem }}{} // clear the array - testUnmarshalErr((&v{{$i}}va)[:len(v{{$i}}v1)], bs{{$i}}, h, t, "dec-slice-v{{$i}}-p-len-noaddr") - testDeepEqualErrHandle(v{{$i}}v1, v{{$i}}va[:len(v{{$i}}v1)], h, t, "equal-slice-v{{$i}}-p-len-noaddr") - v{{$i}}va = [8]{{ .Elem }}{} // clear the array - testUnmarshalErr((&v{{$i}}va)[:], bs{{$i}}, h, t, "dec-slice-v{{$i}}-p-cap-noaddr") - testDeepEqualErrHandle(v{{$i}}v1, v{{$i}}va[:len(v{{$i}}v1)], h, t, "equal-slice-v{{$i}}-p-cap-noaddr") - } - testReleaseBytes(bs{{$i}}) - // ... - var v{{$i}}v3, v{{$i}}v4 {{ .MethodNamePfx "typMbs" false }} - v{{$i}}v2 = nil - if v != nil { v{{$i}}v2 = make([]{{ .Elem }}, len(v)) } - v{{$i}}v3 = {{ .MethodNamePfx "typMbs" false }}(v{{$i}}v1) - v{{$i}}v4 = {{ .MethodNamePfx "typMbs" false }}(v{{$i}}v2) - if v != nil { - bs{{$i}} = testMarshalErr(v{{$i}}v3, h, t, "enc-slice-v{{$i}}-custom") - testUnmarshalErr(v{{$i}}v4, bs{{$i}}, h, t, "dec-slice-v{{$i}}-custom") - testDeepEqualErrHandle(v{{$i}}v3, v{{$i}}v4, h, t, "equal-slice-v{{$i}}-custom") - testReleaseBytes(bs{{$i}}) - } - bs{{$i}} = testMarshalErr(&v{{$i}}v3, h, t, "enc-slice-v{{$i}}-custom-p") - v{{$i}}v2 = nil - v{{$i}}v4 = {{ .MethodNamePfx "typMbs" false }}(v{{$i}}v2) - testUnmarshalErr(&v{{$i}}v4, bs{{$i}}, h, t, "dec-slice-v{{$i}}-custom-p") - testDeepEqualErrHandle(v{{$i}}v3, v{{$i}}v4, h, t, "equal-slice-v{{$i}}-custom-p") - testReleaseBytes(bs{{$i}}) - } -{{end}}{{end}}{{end}} -} - -func __doTestMammothMaps(t *testing.T, h Handle) { -{{range $i, $e := .Values }}{{if not .Primitive }}{{if .MapKey -}} - for _, v := range []map[{{ .MapKey }}]{{ .Elem }}{ nil, {}, { {{ nonzerocmd .MapKey }}:{{ zerocmd .Elem }} {{if ne "bool" .MapKey}}, {{ nonzerocmd .MapKey }}:{{ nonzerocmd .Elem }} {{end}} } } { - {{/* // fmt.Printf(">>>> running mammoth map v{{$i}}: %v\n", v) */ -}} - var v{{$i}}v1, v{{$i}}v2 map[{{ .MapKey }}]{{ .Elem }} - var bs{{$i}} []byte - v{{$i}}v1 = v - bs{{$i}} = testMarshalErr(v{{$i}}v1, h, t, "enc-map-v{{$i}}") - if v != nil { - v{{$i}}v2 = make(map[{{ .MapKey }}]{{ .Elem }}, len(v)) // reset map - testUnmarshalErr(v{{$i}}v2, bs{{$i}}, h, t, "dec-map-v{{$i}}") - testDeepEqualErrHandle(v{{$i}}v1, v{{$i}}v2, h, t, "equal-map-v{{$i}}") - v{{$i}}v2 = make(map[{{ .MapKey }}]{{ .Elem }}, len(v)) // reset map - testUnmarshalErr(reflect.ValueOf(v{{$i}}v2), bs{{$i}}, h, t, "dec-map-v{{$i}}-noaddr") // decode into non-addressable map value - testDeepEqualErrHandle(v{{$i}}v1, v{{$i}}v2, h, t, "equal-map-v{{$i}}-noaddr") - } - if v == nil { v{{$i}}v2 = nil } else { v{{$i}}v2 = make(map[{{ .MapKey }}]{{ .Elem }}, len(v)) } // reset map - testUnmarshalErr(&v{{$i}}v2, bs{{$i}}, h, t, "dec-map-v{{$i}}-p-len") - testDeepEqualErrHandle(v{{$i}}v1, v{{$i}}v2, h, t, "equal-map-v{{$i}}-p-len") - testReleaseBytes(bs{{$i}}) - bs{{$i}} = testMarshalErr(&v{{$i}}v1, h, t, "enc-map-v{{$i}}-p") - v{{$i}}v2 = nil - testUnmarshalErr(&v{{$i}}v2, bs{{$i}}, h, t, "dec-map-v{{$i}}-p-nil") - testDeepEqualErrHandle(v{{$i}}v1, v{{$i}}v2, h, t, "equal-map-v{{$i}}-p-nil") - testReleaseBytes(bs{{$i}}) - // ... - if v == nil { v{{$i}}v2 = nil } else { v{{$i}}v2 = make(map[{{ .MapKey }}]{{ .Elem }}, len(v)) } // reset map - var v{{$i}}v3, v{{$i}}v4 {{ .MethodNamePfx "typMap" false }} - v{{$i}}v3 = {{ .MethodNamePfx "typMap" false }}(v{{$i}}v1) - v{{$i}}v4 = {{ .MethodNamePfx "typMap" false }}(v{{$i}}v2) - if v != nil { - bs{{$i}} = testMarshalErr(v{{$i}}v3, h, t, "enc-map-v{{$i}}-custom") - testUnmarshalErr(v{{$i}}v4, bs{{$i}}, h, t, "dec-map-v{{$i}}-p-len") - testDeepEqualErrHandle(v{{$i}}v3, v{{$i}}v4, h, t, "equal-map-v{{$i}}-p-len") - testReleaseBytes(bs{{$i}}) - } - type s{{$i}}T struct { - M map[{{ .MapKey }}]{{ .Elem }} - Mp *map[{{ .MapKey }}]{{ .Elem }} - } - var m{{$i}}v99 = map[{{ .MapKey }}]{{ .Elem }}{ - {{ zerocmd .MapKey }}: {{ zerocmd .Elem }}, - {{ nonzerocmd .MapKey }}:{{ nonzerocmd .Elem }}, - } - var s{{$i}}v1, s{{$i}}v2 s{{$i}}T - bs{{$i}} = testMarshalErr(s{{$i}}v1, h, t, "enc-map-v{{$i}}-custom") - testUnmarshalErr(&s{{$i}}v2, bs{{$i}}, h, t, "dec-map-v{{$i}}-p-len") - testDeepEqualErrHandle(s{{$i}}v1, s{{$i}}v2, h, t, "equal-map-v{{$i}}-p-len") - testReleaseBytes(bs{{$i}}) - s{{$i}}v2 = s{{$i}}T{} - s{{$i}}v1.M = m{{$i}}v99 - bs{{$i}} = testMarshalErr(s{{$i}}v1, h, t, "enc-map-v{{$i}}-custom") - testUnmarshalErr(&s{{$i}}v2, bs{{$i}}, h, t, "dec-map-v{{$i}}-p-len") - testDeepEqualErrHandle(s{{$i}}v1, s{{$i}}v2, h, t, "equal-map-v{{$i}}-p-len") - testReleaseBytes(bs{{$i}}) - s{{$i}}v2 = s{{$i}}T{} - s{{$i}}v1.Mp = &m{{$i}}v99 - bs{{$i}} = testMarshalErr(s{{$i}}v1, h, t, "enc-map-v{{$i}}-custom") - testUnmarshalErr(&s{{$i}}v2, bs{{$i}}, h, t, "dec-map-v{{$i}}-p-len") - testDeepEqualErrHandle(s{{$i}}v1, s{{$i}}v2, h, t, "equal-map-v{{$i}}-p-len") - testReleaseBytes(bs{{$i}}) - } -{{end}}{{end}}{{end}} - -} - -func doTestMammothMapsAndSlices(t *testing.T, h Handle) { - defer testSetup(t, &h)() - if mh, ok := h.(*MsgpackHandle); ok { - defer func(b bool) { mh.RawToString = b }(mh.RawToString) - mh.RawToString = true - } - __doTestMammothSlices(t, h) - __doTestMammothMaps(t, h) -} - -func doTestMammoth(t *testing.T, h Handle) { - defer testSetup(t, &h)() - if mh, ok := h.(*MsgpackHandle); ok { - defer func(b bool) { mh.RawToString = b }(mh.RawToString) - mh.RawToString = true - } - - name := h.Name() - var b []byte - - var m, m2 TestMammoth - testRandomFillRV(reflect.ValueOf(&m).Elem()) - b = testMarshalErr(&m, h, t, "mammoth-"+name) - - testUnmarshalErr(&m2, b, h, t, "mammoth-"+name) - testDeepEqualErrHandle(&m, &m2, h, t, "mammoth-"+name) - testReleaseBytes(b) - - if testing.Short() { - t.Skipf("skipping rest of mammoth test in -short mode") - } - - var mm, mm2 TestMammoth2Wrapper - testRandomFillRV(reflect.ValueOf(&mm).Elem()) - b = testMarshalErr(&mm, h, t, "mammoth2-"+name) - // os.Stderr.Write([]byte("\n\n\n\n" + string(b) + "\n\n\n\n")) - testUnmarshalErr(&mm2, b, h, t, "mammoth2-"+name) - testDeepEqualErrHandle(&mm, &mm2, h, t, "mammoth2-"+name) - // testMammoth2(t, name, h) - testReleaseBytes(b) -} - -{{range $i, $e := .Formats -}} -func Test{{ . }}Mammoth(t *testing.T) { - doTestMammoth(t, test{{ . }}H) -} -{{end}} -{{range $i, $e := .Formats -}} -func Test{{ . }}MammothMapsAndSlices(t *testing.T) { - doTestMammothMapsAndSlices(t, test{{ . }}H) -} -{{end}} diff --git a/vendor/github.com/ugorji/go/codec/msgpack.base.go b/vendor/github.com/ugorji/go/codec/msgpack.base.go deleted file mode 100644 index 0388f0cec..000000000 --- a/vendor/github.com/ugorji/go/codec/msgpack.base.go +++ /dev/null @@ -1,299 +0,0 @@ -// Copyright (c) 2012-2020 Ugorji Nwoke. All rights reserved. -// Use of this source code is governed by a MIT license found in the LICENSE file. - -package codec - -import ( - "fmt" - "io" - "net/rpc" - "reflect" -) - -const ( - mpPosFixNumMin byte = 0x00 - mpPosFixNumMax byte = 0x7f - mpFixMapMin byte = 0x80 - mpFixMapMax byte = 0x8f - mpFixArrayMin byte = 0x90 - mpFixArrayMax byte = 0x9f - mpFixStrMin byte = 0xa0 - mpFixStrMax byte = 0xbf - mpNil byte = 0xc0 - _ byte = 0xc1 - mpFalse byte = 0xc2 - mpTrue byte = 0xc3 - mpFloat byte = 0xca - mpDouble byte = 0xcb - mpUint8 byte = 0xcc - mpUint16 byte = 0xcd - mpUint32 byte = 0xce - mpUint64 byte = 0xcf - mpInt8 byte = 0xd0 - mpInt16 byte = 0xd1 - mpInt32 byte = 0xd2 - mpInt64 byte = 0xd3 - - // extensions below - mpBin8 byte = 0xc4 - mpBin16 byte = 0xc5 - mpBin32 byte = 0xc6 - mpExt8 byte = 0xc7 - mpExt16 byte = 0xc8 - mpExt32 byte = 0xc9 - mpFixExt1 byte = 0xd4 - mpFixExt2 byte = 0xd5 - mpFixExt4 byte = 0xd6 - mpFixExt8 byte = 0xd7 - mpFixExt16 byte = 0xd8 - - mpStr8 byte = 0xd9 // new - mpStr16 byte = 0xda - mpStr32 byte = 0xdb - - mpArray16 byte = 0xdc - mpArray32 byte = 0xdd - - mpMap16 byte = 0xde - mpMap32 byte = 0xdf - - mpNegFixNumMin byte = 0xe0 - mpNegFixNumMax byte = 0xff -) - -var mpTimeExtTag int8 = -1 -var mpTimeExtTagU = uint8(mpTimeExtTag) - -var mpdescNames = map[byte]string{ - mpNil: "nil", - mpFalse: "false", - mpTrue: "true", - mpFloat: "float", - mpDouble: "float", - mpUint8: "uuint", - mpUint16: "uint", - mpUint32: "uint", - mpUint64: "uint", - mpInt8: "int", - mpInt16: "int", - mpInt32: "int", - mpInt64: "int", - - mpStr8: "string|bytes", - mpStr16: "string|bytes", - mpStr32: "string|bytes", - - mpBin8: "bytes", - mpBin16: "bytes", - mpBin32: "bytes", - - mpArray16: "array", - mpArray32: "array", - - mpMap16: "map", - mpMap32: "map", -} - -func mpdesc(bd byte) (s string) { - s = mpdescNames[bd] - if s == "" { - switch { - case bd >= mpPosFixNumMin && bd <= mpPosFixNumMax, - bd >= mpNegFixNumMin && bd <= mpNegFixNumMax: - s = "int" - case bd >= mpFixStrMin && bd <= mpFixStrMax: - s = "string|bytes" - case bd >= mpFixArrayMin && bd <= mpFixArrayMax: - s = "array" - case bd >= mpFixMapMin && bd <= mpFixMapMax: - s = "map" - case bd >= mpFixExt1 && bd <= mpFixExt16, - bd >= mpExt8 && bd <= mpExt32: - s = "ext" - default: - s = "unknown" - } - } - return -} - -// MsgpackSpecRpcMultiArgs is a special type which signifies to the MsgpackSpecRpcCodec -// that the backend RPC service takes multiple arguments, which have been arranged -// in sequence in the slice. -// -// The Codec then passes it AS-IS to the rpc service (without wrapping it in an -// array of 1 element). -type MsgpackSpecRpcMultiArgs []interface{} - -// A MsgpackContainer type specifies the different types of msgpackContainers. -type msgpackContainerType struct { - fixCutoff, bFixMin, b8, b16, b32 byte - // hasFixMin, has8, has8Always bool -} - -var ( - msgpackContainerRawLegacy = msgpackContainerType{ - 32, mpFixStrMin, 0, mpStr16, mpStr32, - } - msgpackContainerStr = msgpackContainerType{ - 32, mpFixStrMin, mpStr8, mpStr16, mpStr32, // true, true, false, - } - msgpackContainerBin = msgpackContainerType{ - 0, 0, mpBin8, mpBin16, mpBin32, // false, true, true, - } - msgpackContainerList = msgpackContainerType{ - 16, mpFixArrayMin, 0, mpArray16, mpArray32, // true, false, false, - } - msgpackContainerMap = msgpackContainerType{ - 16, mpFixMapMin, 0, mpMap16, mpMap32, // true, false, false, - } -) - -//-------------------------------------------------- - -// MsgpackHandle is a Handle for the Msgpack Schema-Free Encoding Format. -type MsgpackHandle struct { - binaryEncodingType - notJsonType - BasicHandle - - // NoFixedNum says to output all signed integers as 2-bytes, never as 1-byte fixednum. - NoFixedNum bool - - // WriteExt controls whether the new spec is honored. - // - // With WriteExt=true, we can encode configured extensions with extension tags - // and encode string/[]byte/extensions in a way compatible with the new spec - // but incompatible with the old spec. - // - // For compatibility with the old spec, set WriteExt=false. - // - // With WriteExt=false: - // configured extensions are serialized as raw bytes (not msgpack extensions). - // reserved byte descriptors like Str8 and those enabling the new msgpack Binary type - // are not encoded. - WriteExt bool - - // PositiveIntUnsigned says to encode positive integers as unsigned. - PositiveIntUnsigned bool -} - -// Name returns the name of the handle: msgpack -func (h *MsgpackHandle) Name() string { return "msgpack" } - -func (h *MsgpackHandle) desc(bd byte) string { return mpdesc(bd) } - -// SetBytesExt sets an extension -func (h *MsgpackHandle) SetBytesExt(rt reflect.Type, tag uint64, ext BytesExt) (err error) { - return h.SetExt(rt, tag, makeExt(ext)) -} - -//-------------------------------------------------- - -type msgpackSpecRpcCodec struct { - *rpcCodec -} - -// /////////////// Spec RPC Codec /////////////////// -func (c *msgpackSpecRpcCodec) WriteRequest(r *rpc.Request, body interface{}) error { - // WriteRequest can write to both a Go service, and other services that do - // not abide by the 1 argument rule of a Go service. - // We discriminate based on if the body is a MsgpackSpecRpcMultiArgs - var bodyArr []interface{} - if m, ok := body.(MsgpackSpecRpcMultiArgs); ok { - bodyArr = ([]interface{})(m) - } else { - bodyArr = []interface{}{body} - } - r2 := []interface{}{0, uint32(r.Seq), r.ServiceMethod, bodyArr} - return c.write(r2) -} - -func (c *msgpackSpecRpcCodec) WriteResponse(r *rpc.Response, body interface{}) error { - var moe interface{} - if r.Error != "" { - moe = r.Error - } - if moe != nil && body != nil { - body = nil - } - r2 := []interface{}{1, uint32(r.Seq), moe, body} - return c.write(r2) -} - -func (c *msgpackSpecRpcCodec) ReadResponseHeader(r *rpc.Response) error { - return c.parseCustomHeader(1, &r.Seq, &r.Error) -} - -func (c *msgpackSpecRpcCodec) ReadRequestHeader(r *rpc.Request) error { - return c.parseCustomHeader(0, &r.Seq, &r.ServiceMethod) -} - -func (c *msgpackSpecRpcCodec) ReadRequestBody(body interface{}) error { - if body == nil { // read and discard - return c.read(nil) - } - bodyArr := []interface{}{body} - return c.read(&bodyArr) -} - -func (c *msgpackSpecRpcCodec) parseCustomHeader(expectTypeByte byte, msgid *uint64, methodOrError *string) (err error) { - if c.cls.Load().closed { - return io.ErrUnexpectedEOF - } - - // We read the response header by hand - // so that the body can be decoded on its own from the stream at a later time. - - const fia byte = 0x94 //four item array descriptor value - - var ba [1]byte - var n int - for { - n, err = c.r.Read(ba[:]) - if err != nil { - return - } - if n == 1 { - break - } - } - - var b = ba[0] - if b != fia { - err = fmt.Errorf("not array - %s %x/%s", msgBadDesc, b, mpdesc(b)) - } else { - err = c.read(&b) - if err == nil { - if b != expectTypeByte { - err = fmt.Errorf("%s - expecting %v but got %x/%s", msgBadDesc, expectTypeByte, b, mpdesc(b)) - } else { - err = c.read(msgid) - if err == nil { - err = c.read(methodOrError) - } - } - } - } - return -} - -//-------------------------------------------------- - -// msgpackSpecRpc is the implementation of Rpc that uses custom communication protocol -// as defined in the msgpack spec at https://github.com/msgpack-rpc/msgpack-rpc/blob/master/spec.md -type msgpackSpecRpc struct{} - -// MsgpackSpecRpc implements Rpc using the communication protocol defined in -// the msgpack spec at https://github.com/msgpack-rpc/msgpack-rpc/blob/master/spec.md . -// -// See GoRpc documentation, for information on buffering for better performance. -var MsgpackSpecRpc msgpackSpecRpc - -func (x msgpackSpecRpc) ServerCodec(conn io.ReadWriteCloser, h Handle) rpc.ServerCodec { - return &msgpackSpecRpcCodec{newRPCCodec(conn, h)} -} - -func (x msgpackSpecRpc) ClientCodec(conn io.ReadWriteCloser, h Handle) rpc.ClientCodec { - return &msgpackSpecRpcCodec{newRPCCodec(conn, h)} -} diff --git a/vendor/github.com/ugorji/go/codec/msgpack.fastpath.mono.generated.go b/vendor/github.com/ugorji/go/codec/msgpack.fastpath.mono.generated.go deleted file mode 100644 index 6d6a880e8..000000000 --- a/vendor/github.com/ugorji/go/codec/msgpack.fastpath.mono.generated.go +++ /dev/null @@ -1,12482 +0,0 @@ -//go:build !notmono && !codec.notmono && !notfastpath && !codec.notfastpath - -// Copyright (c) 2012-2020 Ugorji Nwoke. All rights reserved. -// Use of this source code is governed by a MIT license found in the LICENSE file. - -package codec - -import ( - "reflect" - "slices" - "sort" -) - -type fastpathEMsgpackBytes struct { - rtid uintptr - rt reflect.Type - encfn func(*encoderMsgpackBytes, *encFnInfo, reflect.Value) -} -type fastpathDMsgpackBytes struct { - rtid uintptr - rt reflect.Type - decfn func(*decoderMsgpackBytes, *decFnInfo, reflect.Value) -} -type fastpathEsMsgpackBytes [56]fastpathEMsgpackBytes -type fastpathDsMsgpackBytes [56]fastpathDMsgpackBytes -type fastpathETMsgpackBytes struct{} -type fastpathDTMsgpackBytes struct{} - -func (helperEncDriverMsgpackBytes) fastpathEList() *fastpathEsMsgpackBytes { - var i uint = 0 - var s fastpathEsMsgpackBytes - fn := func(v interface{}, fe func(*encoderMsgpackBytes, *encFnInfo, reflect.Value)) { - xrt := reflect.TypeOf(v) - s[i] = fastpathEMsgpackBytes{rt2id(xrt), xrt, fe} - i++ - } - - fn([]interface{}(nil), (*encoderMsgpackBytes).fastpathEncSliceIntfR) - fn([]string(nil), (*encoderMsgpackBytes).fastpathEncSliceStringR) - fn([][]byte(nil), (*encoderMsgpackBytes).fastpathEncSliceBytesR) - fn([]float32(nil), (*encoderMsgpackBytes).fastpathEncSliceFloat32R) - fn([]float64(nil), (*encoderMsgpackBytes).fastpathEncSliceFloat64R) - fn([]uint8(nil), (*encoderMsgpackBytes).fastpathEncSliceUint8R) - fn([]uint64(nil), (*encoderMsgpackBytes).fastpathEncSliceUint64R) - fn([]int(nil), (*encoderMsgpackBytes).fastpathEncSliceIntR) - fn([]int32(nil), (*encoderMsgpackBytes).fastpathEncSliceInt32R) - fn([]int64(nil), (*encoderMsgpackBytes).fastpathEncSliceInt64R) - fn([]bool(nil), (*encoderMsgpackBytes).fastpathEncSliceBoolR) - - fn(map[string]interface{}(nil), (*encoderMsgpackBytes).fastpathEncMapStringIntfR) - fn(map[string]string(nil), (*encoderMsgpackBytes).fastpathEncMapStringStringR) - fn(map[string][]byte(nil), (*encoderMsgpackBytes).fastpathEncMapStringBytesR) - fn(map[string]uint8(nil), (*encoderMsgpackBytes).fastpathEncMapStringUint8R) - fn(map[string]uint64(nil), (*encoderMsgpackBytes).fastpathEncMapStringUint64R) - fn(map[string]int(nil), (*encoderMsgpackBytes).fastpathEncMapStringIntR) - fn(map[string]int32(nil), (*encoderMsgpackBytes).fastpathEncMapStringInt32R) - fn(map[string]float64(nil), (*encoderMsgpackBytes).fastpathEncMapStringFloat64R) - fn(map[string]bool(nil), (*encoderMsgpackBytes).fastpathEncMapStringBoolR) - fn(map[uint8]interface{}(nil), (*encoderMsgpackBytes).fastpathEncMapUint8IntfR) - fn(map[uint8]string(nil), (*encoderMsgpackBytes).fastpathEncMapUint8StringR) - fn(map[uint8][]byte(nil), (*encoderMsgpackBytes).fastpathEncMapUint8BytesR) - fn(map[uint8]uint8(nil), (*encoderMsgpackBytes).fastpathEncMapUint8Uint8R) - fn(map[uint8]uint64(nil), (*encoderMsgpackBytes).fastpathEncMapUint8Uint64R) - fn(map[uint8]int(nil), (*encoderMsgpackBytes).fastpathEncMapUint8IntR) - fn(map[uint8]int32(nil), (*encoderMsgpackBytes).fastpathEncMapUint8Int32R) - fn(map[uint8]float64(nil), (*encoderMsgpackBytes).fastpathEncMapUint8Float64R) - fn(map[uint8]bool(nil), (*encoderMsgpackBytes).fastpathEncMapUint8BoolR) - fn(map[uint64]interface{}(nil), (*encoderMsgpackBytes).fastpathEncMapUint64IntfR) - fn(map[uint64]string(nil), (*encoderMsgpackBytes).fastpathEncMapUint64StringR) - fn(map[uint64][]byte(nil), (*encoderMsgpackBytes).fastpathEncMapUint64BytesR) - fn(map[uint64]uint8(nil), (*encoderMsgpackBytes).fastpathEncMapUint64Uint8R) - fn(map[uint64]uint64(nil), (*encoderMsgpackBytes).fastpathEncMapUint64Uint64R) - fn(map[uint64]int(nil), (*encoderMsgpackBytes).fastpathEncMapUint64IntR) - fn(map[uint64]int32(nil), (*encoderMsgpackBytes).fastpathEncMapUint64Int32R) - fn(map[uint64]float64(nil), (*encoderMsgpackBytes).fastpathEncMapUint64Float64R) - fn(map[uint64]bool(nil), (*encoderMsgpackBytes).fastpathEncMapUint64BoolR) - fn(map[int]interface{}(nil), (*encoderMsgpackBytes).fastpathEncMapIntIntfR) - fn(map[int]string(nil), (*encoderMsgpackBytes).fastpathEncMapIntStringR) - fn(map[int][]byte(nil), (*encoderMsgpackBytes).fastpathEncMapIntBytesR) - fn(map[int]uint8(nil), (*encoderMsgpackBytes).fastpathEncMapIntUint8R) - fn(map[int]uint64(nil), (*encoderMsgpackBytes).fastpathEncMapIntUint64R) - fn(map[int]int(nil), (*encoderMsgpackBytes).fastpathEncMapIntIntR) - fn(map[int]int32(nil), (*encoderMsgpackBytes).fastpathEncMapIntInt32R) - fn(map[int]float64(nil), (*encoderMsgpackBytes).fastpathEncMapIntFloat64R) - fn(map[int]bool(nil), (*encoderMsgpackBytes).fastpathEncMapIntBoolR) - fn(map[int32]interface{}(nil), (*encoderMsgpackBytes).fastpathEncMapInt32IntfR) - fn(map[int32]string(nil), (*encoderMsgpackBytes).fastpathEncMapInt32StringR) - fn(map[int32][]byte(nil), (*encoderMsgpackBytes).fastpathEncMapInt32BytesR) - fn(map[int32]uint8(nil), (*encoderMsgpackBytes).fastpathEncMapInt32Uint8R) - fn(map[int32]uint64(nil), (*encoderMsgpackBytes).fastpathEncMapInt32Uint64R) - fn(map[int32]int(nil), (*encoderMsgpackBytes).fastpathEncMapInt32IntR) - fn(map[int32]int32(nil), (*encoderMsgpackBytes).fastpathEncMapInt32Int32R) - fn(map[int32]float64(nil), (*encoderMsgpackBytes).fastpathEncMapInt32Float64R) - fn(map[int32]bool(nil), (*encoderMsgpackBytes).fastpathEncMapInt32BoolR) - - sort.Slice(s[:], func(i, j int) bool { return s[i].rtid < s[j].rtid }) - return &s -} - -func (helperDecDriverMsgpackBytes) fastpathDList() *fastpathDsMsgpackBytes { - var i uint = 0 - var s fastpathDsMsgpackBytes - fn := func(v interface{}, fd func(*decoderMsgpackBytes, *decFnInfo, reflect.Value)) { - xrt := reflect.TypeOf(v) - s[i] = fastpathDMsgpackBytes{rt2id(xrt), xrt, fd} - i++ - } - - fn([]interface{}(nil), (*decoderMsgpackBytes).fastpathDecSliceIntfR) - fn([]string(nil), (*decoderMsgpackBytes).fastpathDecSliceStringR) - fn([][]byte(nil), (*decoderMsgpackBytes).fastpathDecSliceBytesR) - fn([]float32(nil), (*decoderMsgpackBytes).fastpathDecSliceFloat32R) - fn([]float64(nil), (*decoderMsgpackBytes).fastpathDecSliceFloat64R) - fn([]uint8(nil), (*decoderMsgpackBytes).fastpathDecSliceUint8R) - fn([]uint64(nil), (*decoderMsgpackBytes).fastpathDecSliceUint64R) - fn([]int(nil), (*decoderMsgpackBytes).fastpathDecSliceIntR) - fn([]int32(nil), (*decoderMsgpackBytes).fastpathDecSliceInt32R) - fn([]int64(nil), (*decoderMsgpackBytes).fastpathDecSliceInt64R) - fn([]bool(nil), (*decoderMsgpackBytes).fastpathDecSliceBoolR) - - fn(map[string]interface{}(nil), (*decoderMsgpackBytes).fastpathDecMapStringIntfR) - fn(map[string]string(nil), (*decoderMsgpackBytes).fastpathDecMapStringStringR) - fn(map[string][]byte(nil), (*decoderMsgpackBytes).fastpathDecMapStringBytesR) - fn(map[string]uint8(nil), (*decoderMsgpackBytes).fastpathDecMapStringUint8R) - fn(map[string]uint64(nil), (*decoderMsgpackBytes).fastpathDecMapStringUint64R) - fn(map[string]int(nil), (*decoderMsgpackBytes).fastpathDecMapStringIntR) - fn(map[string]int32(nil), (*decoderMsgpackBytes).fastpathDecMapStringInt32R) - fn(map[string]float64(nil), (*decoderMsgpackBytes).fastpathDecMapStringFloat64R) - fn(map[string]bool(nil), (*decoderMsgpackBytes).fastpathDecMapStringBoolR) - fn(map[uint8]interface{}(nil), (*decoderMsgpackBytes).fastpathDecMapUint8IntfR) - fn(map[uint8]string(nil), (*decoderMsgpackBytes).fastpathDecMapUint8StringR) - fn(map[uint8][]byte(nil), (*decoderMsgpackBytes).fastpathDecMapUint8BytesR) - fn(map[uint8]uint8(nil), (*decoderMsgpackBytes).fastpathDecMapUint8Uint8R) - fn(map[uint8]uint64(nil), (*decoderMsgpackBytes).fastpathDecMapUint8Uint64R) - fn(map[uint8]int(nil), (*decoderMsgpackBytes).fastpathDecMapUint8IntR) - fn(map[uint8]int32(nil), (*decoderMsgpackBytes).fastpathDecMapUint8Int32R) - fn(map[uint8]float64(nil), (*decoderMsgpackBytes).fastpathDecMapUint8Float64R) - fn(map[uint8]bool(nil), (*decoderMsgpackBytes).fastpathDecMapUint8BoolR) - fn(map[uint64]interface{}(nil), (*decoderMsgpackBytes).fastpathDecMapUint64IntfR) - fn(map[uint64]string(nil), (*decoderMsgpackBytes).fastpathDecMapUint64StringR) - fn(map[uint64][]byte(nil), (*decoderMsgpackBytes).fastpathDecMapUint64BytesR) - fn(map[uint64]uint8(nil), (*decoderMsgpackBytes).fastpathDecMapUint64Uint8R) - fn(map[uint64]uint64(nil), (*decoderMsgpackBytes).fastpathDecMapUint64Uint64R) - fn(map[uint64]int(nil), (*decoderMsgpackBytes).fastpathDecMapUint64IntR) - fn(map[uint64]int32(nil), (*decoderMsgpackBytes).fastpathDecMapUint64Int32R) - fn(map[uint64]float64(nil), (*decoderMsgpackBytes).fastpathDecMapUint64Float64R) - fn(map[uint64]bool(nil), (*decoderMsgpackBytes).fastpathDecMapUint64BoolR) - fn(map[int]interface{}(nil), (*decoderMsgpackBytes).fastpathDecMapIntIntfR) - fn(map[int]string(nil), (*decoderMsgpackBytes).fastpathDecMapIntStringR) - fn(map[int][]byte(nil), (*decoderMsgpackBytes).fastpathDecMapIntBytesR) - fn(map[int]uint8(nil), (*decoderMsgpackBytes).fastpathDecMapIntUint8R) - fn(map[int]uint64(nil), (*decoderMsgpackBytes).fastpathDecMapIntUint64R) - fn(map[int]int(nil), (*decoderMsgpackBytes).fastpathDecMapIntIntR) - fn(map[int]int32(nil), (*decoderMsgpackBytes).fastpathDecMapIntInt32R) - fn(map[int]float64(nil), (*decoderMsgpackBytes).fastpathDecMapIntFloat64R) - fn(map[int]bool(nil), (*decoderMsgpackBytes).fastpathDecMapIntBoolR) - fn(map[int32]interface{}(nil), (*decoderMsgpackBytes).fastpathDecMapInt32IntfR) - fn(map[int32]string(nil), (*decoderMsgpackBytes).fastpathDecMapInt32StringR) - fn(map[int32][]byte(nil), (*decoderMsgpackBytes).fastpathDecMapInt32BytesR) - fn(map[int32]uint8(nil), (*decoderMsgpackBytes).fastpathDecMapInt32Uint8R) - fn(map[int32]uint64(nil), (*decoderMsgpackBytes).fastpathDecMapInt32Uint64R) - fn(map[int32]int(nil), (*decoderMsgpackBytes).fastpathDecMapInt32IntR) - fn(map[int32]int32(nil), (*decoderMsgpackBytes).fastpathDecMapInt32Int32R) - fn(map[int32]float64(nil), (*decoderMsgpackBytes).fastpathDecMapInt32Float64R) - fn(map[int32]bool(nil), (*decoderMsgpackBytes).fastpathDecMapInt32BoolR) - - sort.Slice(s[:], func(i, j int) bool { return s[i].rtid < s[j].rtid }) - return &s -} - -func (helperEncDriverMsgpackBytes) fastpathEncodeTypeSwitch(iv interface{}, e *encoderMsgpackBytes) bool { - var ft fastpathETMsgpackBytes - switch v := iv.(type) { - case []interface{}: - if v == nil { - e.e.writeNilArray() - } else { - ft.EncSliceIntfV(v, e) - } - case []string: - if v == nil { - e.e.writeNilArray() - } else { - ft.EncSliceStringV(v, e) - } - case [][]byte: - if v == nil { - e.e.writeNilArray() - } else { - ft.EncSliceBytesV(v, e) - } - case []float32: - if v == nil { - e.e.writeNilArray() - } else { - ft.EncSliceFloat32V(v, e) - } - case []float64: - if v == nil { - e.e.writeNilArray() - } else { - ft.EncSliceFloat64V(v, e) - } - case []uint8: - if v == nil { - e.e.writeNilArray() - } else { - ft.EncSliceUint8V(v, e) - } - case []uint64: - if v == nil { - e.e.writeNilArray() - } else { - ft.EncSliceUint64V(v, e) - } - case []int: - if v == nil { - e.e.writeNilArray() - } else { - ft.EncSliceIntV(v, e) - } - case []int32: - if v == nil { - e.e.writeNilArray() - } else { - ft.EncSliceInt32V(v, e) - } - case []int64: - if v == nil { - e.e.writeNilArray() - } else { - ft.EncSliceInt64V(v, e) - } - case []bool: - if v == nil { - e.e.writeNilArray() - } else { - ft.EncSliceBoolV(v, e) - } - case map[string]interface{}: - if v == nil { - e.e.writeNilMap() - } else { - ft.EncMapStringIntfV(v, e) - } - case map[string]string: - if v == nil { - e.e.writeNilMap() - } else { - ft.EncMapStringStringV(v, e) - } - case map[string][]byte: - if v == nil { - e.e.writeNilMap() - } else { - ft.EncMapStringBytesV(v, e) - } - case map[string]uint8: - if v == nil { - e.e.writeNilMap() - } else { - ft.EncMapStringUint8V(v, e) - } - case map[string]uint64: - if v == nil { - e.e.writeNilMap() - } else { - ft.EncMapStringUint64V(v, e) - } - case map[string]int: - if v == nil { - e.e.writeNilMap() - } else { - ft.EncMapStringIntV(v, e) - } - case map[string]int32: - if v == nil { - e.e.writeNilMap() - } else { - ft.EncMapStringInt32V(v, e) - } - case map[string]float64: - if v == nil { - e.e.writeNilMap() - } else { - ft.EncMapStringFloat64V(v, e) - } - case map[string]bool: - if v == nil { - e.e.writeNilMap() - } else { - ft.EncMapStringBoolV(v, e) - } - case map[uint8]interface{}: - if v == nil { - e.e.writeNilMap() - } else { - ft.EncMapUint8IntfV(v, e) - } - case map[uint8]string: - if v == nil { - e.e.writeNilMap() - } else { - ft.EncMapUint8StringV(v, e) - } - case map[uint8][]byte: - if v == nil { - e.e.writeNilMap() - } else { - ft.EncMapUint8BytesV(v, e) - } - case map[uint8]uint8: - if v == nil { - e.e.writeNilMap() - } else { - ft.EncMapUint8Uint8V(v, e) - } - case map[uint8]uint64: - if v == nil { - e.e.writeNilMap() - } else { - ft.EncMapUint8Uint64V(v, e) - } - case map[uint8]int: - if v == nil { - e.e.writeNilMap() - } else { - ft.EncMapUint8IntV(v, e) - } - case map[uint8]int32: - if v == nil { - e.e.writeNilMap() - } else { - ft.EncMapUint8Int32V(v, e) - } - case map[uint8]float64: - if v == nil { - e.e.writeNilMap() - } else { - ft.EncMapUint8Float64V(v, e) - } - case map[uint8]bool: - if v == nil { - e.e.writeNilMap() - } else { - ft.EncMapUint8BoolV(v, e) - } - case map[uint64]interface{}: - if v == nil { - e.e.writeNilMap() - } else { - ft.EncMapUint64IntfV(v, e) - } - case map[uint64]string: - if v == nil { - e.e.writeNilMap() - } else { - ft.EncMapUint64StringV(v, e) - } - case map[uint64][]byte: - if v == nil { - e.e.writeNilMap() - } else { - ft.EncMapUint64BytesV(v, e) - } - case map[uint64]uint8: - if v == nil { - e.e.writeNilMap() - } else { - ft.EncMapUint64Uint8V(v, e) - } - case map[uint64]uint64: - if v == nil { - e.e.writeNilMap() - } else { - ft.EncMapUint64Uint64V(v, e) - } - case map[uint64]int: - if v == nil { - e.e.writeNilMap() - } else { - ft.EncMapUint64IntV(v, e) - } - case map[uint64]int32: - if v == nil { - e.e.writeNilMap() - } else { - ft.EncMapUint64Int32V(v, e) - } - case map[uint64]float64: - if v == nil { - e.e.writeNilMap() - } else { - ft.EncMapUint64Float64V(v, e) - } - case map[uint64]bool: - if v == nil { - e.e.writeNilMap() - } else { - ft.EncMapUint64BoolV(v, e) - } - case map[int]interface{}: - if v == nil { - e.e.writeNilMap() - } else { - ft.EncMapIntIntfV(v, e) - } - case map[int]string: - if v == nil { - e.e.writeNilMap() - } else { - ft.EncMapIntStringV(v, e) - } - case map[int][]byte: - if v == nil { - e.e.writeNilMap() - } else { - ft.EncMapIntBytesV(v, e) - } - case map[int]uint8: - if v == nil { - e.e.writeNilMap() - } else { - ft.EncMapIntUint8V(v, e) - } - case map[int]uint64: - if v == nil { - e.e.writeNilMap() - } else { - ft.EncMapIntUint64V(v, e) - } - case map[int]int: - if v == nil { - e.e.writeNilMap() - } else { - ft.EncMapIntIntV(v, e) - } - case map[int]int32: - if v == nil { - e.e.writeNilMap() - } else { - ft.EncMapIntInt32V(v, e) - } - case map[int]float64: - if v == nil { - e.e.writeNilMap() - } else { - ft.EncMapIntFloat64V(v, e) - } - case map[int]bool: - if v == nil { - e.e.writeNilMap() - } else { - ft.EncMapIntBoolV(v, e) - } - case map[int32]interface{}: - if v == nil { - e.e.writeNilMap() - } else { - ft.EncMapInt32IntfV(v, e) - } - case map[int32]string: - if v == nil { - e.e.writeNilMap() - } else { - ft.EncMapInt32StringV(v, e) - } - case map[int32][]byte: - if v == nil { - e.e.writeNilMap() - } else { - ft.EncMapInt32BytesV(v, e) - } - case map[int32]uint8: - if v == nil { - e.e.writeNilMap() - } else { - ft.EncMapInt32Uint8V(v, e) - } - case map[int32]uint64: - if v == nil { - e.e.writeNilMap() - } else { - ft.EncMapInt32Uint64V(v, e) - } - case map[int32]int: - if v == nil { - e.e.writeNilMap() - } else { - ft.EncMapInt32IntV(v, e) - } - case map[int32]int32: - if v == nil { - e.e.writeNilMap() - } else { - ft.EncMapInt32Int32V(v, e) - } - case map[int32]float64: - if v == nil { - e.e.writeNilMap() - } else { - ft.EncMapInt32Float64V(v, e) - } - case map[int32]bool: - if v == nil { - e.e.writeNilMap() - } else { - ft.EncMapInt32BoolV(v, e) - } - default: - _ = v - return false - } - return true -} - -func (e *encoderMsgpackBytes) fastpathEncSliceIntfR(f *encFnInfo, rv reflect.Value) { - var ft fastpathETMsgpackBytes - var v []interface{} - if rv.Kind() == reflect.Array { - rvGetSlice4Array(rv, &v) - } else { - v = rv2i(rv).([]interface{}) - } - if f.ti.mbs { - ft.EncAsMapSliceIntfV(v, e) - return - } - ft.EncSliceIntfV(v, e) -} -func (fastpathETMsgpackBytes) EncSliceIntfV(v []interface{}, e *encoderMsgpackBytes) { - if len(v) == 0 { - e.c = 0 - e.e.WriteArrayEmpty() - return - } - e.arrayStart(len(v)) - for j := range v { - e.c = containerArrayElem - e.e.WriteArrayElem(j == 0) - if !e.encodeBuiltin(v[j]) { - e.encodeR(reflect.ValueOf(v[j])) - } - } - e.c = 0 - e.e.WriteArrayEnd() -} -func (fastpathETMsgpackBytes) EncAsMapSliceIntfV(v []interface{}, e *encoderMsgpackBytes) { - if len(v) == 0 { - e.c = 0 - e.e.WriteMapEmpty() - return - } - e.haltOnMbsOddLen(len(v)) - e.mapStart(len(v) >> 1) - for j := range v { - if j&1 == 0 { - e.c = containerMapKey - e.e.WriteMapElemKey(j == 0) - } else { - e.mapElemValue() - } - if !e.encodeBuiltin(v[j]) { - e.encodeR(reflect.ValueOf(v[j])) - } - } - e.c = 0 - e.e.WriteMapEnd() -} - -func (e *encoderMsgpackBytes) fastpathEncSliceStringR(f *encFnInfo, rv reflect.Value) { - var ft fastpathETMsgpackBytes - var v []string - if rv.Kind() == reflect.Array { - rvGetSlice4Array(rv, &v) - } else { - v = rv2i(rv).([]string) - } - if f.ti.mbs { - ft.EncAsMapSliceStringV(v, e) - return - } - ft.EncSliceStringV(v, e) -} -func (fastpathETMsgpackBytes) EncSliceStringV(v []string, e *encoderMsgpackBytes) { - if len(v) == 0 { - e.c = 0 - e.e.WriteArrayEmpty() - return - } - e.arrayStart(len(v)) - for j := range v { - e.c = containerArrayElem - e.e.WriteArrayElem(j == 0) - e.e.EncodeString(v[j]) - } - e.c = 0 - e.e.WriteArrayEnd() -} -func (fastpathETMsgpackBytes) EncAsMapSliceStringV(v []string, e *encoderMsgpackBytes) { - if len(v) == 0 { - e.c = 0 - e.e.WriteMapEmpty() - return - } - e.haltOnMbsOddLen(len(v)) - e.mapStart(len(v) >> 1) - for j := range v { - if j&1 == 0 { - e.c = containerMapKey - e.e.WriteMapElemKey(j == 0) - } else { - e.mapElemValue() - } - e.e.EncodeString(v[j]) - } - e.c = 0 - e.e.WriteMapEnd() -} - -func (e *encoderMsgpackBytes) fastpathEncSliceBytesR(f *encFnInfo, rv reflect.Value) { - var ft fastpathETMsgpackBytes - var v [][]byte - if rv.Kind() == reflect.Array { - rvGetSlice4Array(rv, &v) - } else { - v = rv2i(rv).([][]byte) - } - if f.ti.mbs { - ft.EncAsMapSliceBytesV(v, e) - return - } - ft.EncSliceBytesV(v, e) -} -func (fastpathETMsgpackBytes) EncSliceBytesV(v [][]byte, e *encoderMsgpackBytes) { - if len(v) == 0 { - e.c = 0 - e.e.WriteArrayEmpty() - return - } - e.arrayStart(len(v)) - for j := range v { - e.c = containerArrayElem - e.e.WriteArrayElem(j == 0) - e.e.EncodeBytes(v[j]) - } - e.c = 0 - e.e.WriteArrayEnd() -} -func (fastpathETMsgpackBytes) EncAsMapSliceBytesV(v [][]byte, e *encoderMsgpackBytes) { - if len(v) == 0 { - e.c = 0 - e.e.WriteMapEmpty() - return - } - e.haltOnMbsOddLen(len(v)) - e.mapStart(len(v) >> 1) - for j := range v { - if j&1 == 0 { - e.c = containerMapKey - e.e.WriteMapElemKey(j == 0) - } else { - e.mapElemValue() - } - e.e.EncodeBytes(v[j]) - } - e.c = 0 - e.e.WriteMapEnd() -} - -func (e *encoderMsgpackBytes) fastpathEncSliceFloat32R(f *encFnInfo, rv reflect.Value) { - var ft fastpathETMsgpackBytes - var v []float32 - if rv.Kind() == reflect.Array { - rvGetSlice4Array(rv, &v) - } else { - v = rv2i(rv).([]float32) - } - if f.ti.mbs { - ft.EncAsMapSliceFloat32V(v, e) - return - } - ft.EncSliceFloat32V(v, e) -} -func (fastpathETMsgpackBytes) EncSliceFloat32V(v []float32, e *encoderMsgpackBytes) { - if len(v) == 0 { - e.c = 0 - e.e.WriteArrayEmpty() - return - } - e.arrayStart(len(v)) - for j := range v { - e.c = containerArrayElem - e.e.WriteArrayElem(j == 0) - e.e.EncodeFloat32(v[j]) - } - e.c = 0 - e.e.WriteArrayEnd() -} -func (fastpathETMsgpackBytes) EncAsMapSliceFloat32V(v []float32, e *encoderMsgpackBytes) { - if len(v) == 0 { - e.c = 0 - e.e.WriteMapEmpty() - return - } - e.haltOnMbsOddLen(len(v)) - e.mapStart(len(v) >> 1) - for j := range v { - if j&1 == 0 { - e.c = containerMapKey - e.e.WriteMapElemKey(j == 0) - } else { - e.mapElemValue() - } - e.e.EncodeFloat32(v[j]) - } - e.c = 0 - e.e.WriteMapEnd() -} - -func (e *encoderMsgpackBytes) fastpathEncSliceFloat64R(f *encFnInfo, rv reflect.Value) { - var ft fastpathETMsgpackBytes - var v []float64 - if rv.Kind() == reflect.Array { - rvGetSlice4Array(rv, &v) - } else { - v = rv2i(rv).([]float64) - } - if f.ti.mbs { - ft.EncAsMapSliceFloat64V(v, e) - return - } - ft.EncSliceFloat64V(v, e) -} -func (fastpathETMsgpackBytes) EncSliceFloat64V(v []float64, e *encoderMsgpackBytes) { - if len(v) == 0 { - e.c = 0 - e.e.WriteArrayEmpty() - return - } - e.arrayStart(len(v)) - for j := range v { - e.c = containerArrayElem - e.e.WriteArrayElem(j == 0) - e.e.EncodeFloat64(v[j]) - } - e.c = 0 - e.e.WriteArrayEnd() -} -func (fastpathETMsgpackBytes) EncAsMapSliceFloat64V(v []float64, e *encoderMsgpackBytes) { - if len(v) == 0 { - e.c = 0 - e.e.WriteMapEmpty() - return - } - e.haltOnMbsOddLen(len(v)) - e.mapStart(len(v) >> 1) - for j := range v { - if j&1 == 0 { - e.c = containerMapKey - e.e.WriteMapElemKey(j == 0) - } else { - e.mapElemValue() - } - e.e.EncodeFloat64(v[j]) - } - e.c = 0 - e.e.WriteMapEnd() -} - -func (e *encoderMsgpackBytes) fastpathEncSliceUint8R(f *encFnInfo, rv reflect.Value) { - var ft fastpathETMsgpackBytes - var v []uint8 - if rv.Kind() == reflect.Array { - rvGetSlice4Array(rv, &v) - } else { - v = rv2i(rv).([]uint8) - } - if f.ti.mbs { - ft.EncAsMapSliceUint8V(v, e) - return - } - ft.EncSliceUint8V(v, e) -} -func (fastpathETMsgpackBytes) EncSliceUint8V(v []uint8, e *encoderMsgpackBytes) { - e.e.EncodeStringBytesRaw(v) -} -func (fastpathETMsgpackBytes) EncAsMapSliceUint8V(v []uint8, e *encoderMsgpackBytes) { - if len(v) == 0 { - e.c = 0 - e.e.WriteMapEmpty() - return - } - e.haltOnMbsOddLen(len(v)) - e.mapStart(len(v) >> 1) - for j := range v { - if j&1 == 0 { - e.c = containerMapKey - e.e.WriteMapElemKey(j == 0) - } else { - e.mapElemValue() - } - e.e.EncodeUint(uint64(v[j])) - } - e.c = 0 - e.e.WriteMapEnd() -} - -func (e *encoderMsgpackBytes) fastpathEncSliceUint64R(f *encFnInfo, rv reflect.Value) { - var ft fastpathETMsgpackBytes - var v []uint64 - if rv.Kind() == reflect.Array { - rvGetSlice4Array(rv, &v) - } else { - v = rv2i(rv).([]uint64) - } - if f.ti.mbs { - ft.EncAsMapSliceUint64V(v, e) - return - } - ft.EncSliceUint64V(v, e) -} -func (fastpathETMsgpackBytes) EncSliceUint64V(v []uint64, e *encoderMsgpackBytes) { - if len(v) == 0 { - e.c = 0 - e.e.WriteArrayEmpty() - return - } - e.arrayStart(len(v)) - for j := range v { - e.c = containerArrayElem - e.e.WriteArrayElem(j == 0) - e.e.EncodeUint(v[j]) - } - e.c = 0 - e.e.WriteArrayEnd() -} -func (fastpathETMsgpackBytes) EncAsMapSliceUint64V(v []uint64, e *encoderMsgpackBytes) { - if len(v) == 0 { - e.c = 0 - e.e.WriteMapEmpty() - return - } - e.haltOnMbsOddLen(len(v)) - e.mapStart(len(v) >> 1) - for j := range v { - if j&1 == 0 { - e.c = containerMapKey - e.e.WriteMapElemKey(j == 0) - } else { - e.mapElemValue() - } - e.e.EncodeUint(v[j]) - } - e.c = 0 - e.e.WriteMapEnd() -} - -func (e *encoderMsgpackBytes) fastpathEncSliceIntR(f *encFnInfo, rv reflect.Value) { - var ft fastpathETMsgpackBytes - var v []int - if rv.Kind() == reflect.Array { - rvGetSlice4Array(rv, &v) - } else { - v = rv2i(rv).([]int) - } - if f.ti.mbs { - ft.EncAsMapSliceIntV(v, e) - return - } - ft.EncSliceIntV(v, e) -} -func (fastpathETMsgpackBytes) EncSliceIntV(v []int, e *encoderMsgpackBytes) { - if len(v) == 0 { - e.c = 0 - e.e.WriteArrayEmpty() - return - } - e.arrayStart(len(v)) - for j := range v { - e.c = containerArrayElem - e.e.WriteArrayElem(j == 0) - e.e.EncodeInt(int64(v[j])) - } - e.c = 0 - e.e.WriteArrayEnd() -} -func (fastpathETMsgpackBytes) EncAsMapSliceIntV(v []int, e *encoderMsgpackBytes) { - if len(v) == 0 { - e.c = 0 - e.e.WriteMapEmpty() - return - } - e.haltOnMbsOddLen(len(v)) - e.mapStart(len(v) >> 1) - for j := range v { - if j&1 == 0 { - e.c = containerMapKey - e.e.WriteMapElemKey(j == 0) - } else { - e.mapElemValue() - } - e.e.EncodeInt(int64(v[j])) - } - e.c = 0 - e.e.WriteMapEnd() -} - -func (e *encoderMsgpackBytes) fastpathEncSliceInt32R(f *encFnInfo, rv reflect.Value) { - var ft fastpathETMsgpackBytes - var v []int32 - if rv.Kind() == reflect.Array { - rvGetSlice4Array(rv, &v) - } else { - v = rv2i(rv).([]int32) - } - if f.ti.mbs { - ft.EncAsMapSliceInt32V(v, e) - return - } - ft.EncSliceInt32V(v, e) -} -func (fastpathETMsgpackBytes) EncSliceInt32V(v []int32, e *encoderMsgpackBytes) { - if len(v) == 0 { - e.c = 0 - e.e.WriteArrayEmpty() - return - } - e.arrayStart(len(v)) - for j := range v { - e.c = containerArrayElem - e.e.WriteArrayElem(j == 0) - e.e.EncodeInt(int64(v[j])) - } - e.c = 0 - e.e.WriteArrayEnd() -} -func (fastpathETMsgpackBytes) EncAsMapSliceInt32V(v []int32, e *encoderMsgpackBytes) { - if len(v) == 0 { - e.c = 0 - e.e.WriteMapEmpty() - return - } - e.haltOnMbsOddLen(len(v)) - e.mapStart(len(v) >> 1) - for j := range v { - if j&1 == 0 { - e.c = containerMapKey - e.e.WriteMapElemKey(j == 0) - } else { - e.mapElemValue() - } - e.e.EncodeInt(int64(v[j])) - } - e.c = 0 - e.e.WriteMapEnd() -} - -func (e *encoderMsgpackBytes) fastpathEncSliceInt64R(f *encFnInfo, rv reflect.Value) { - var ft fastpathETMsgpackBytes - var v []int64 - if rv.Kind() == reflect.Array { - rvGetSlice4Array(rv, &v) - } else { - v = rv2i(rv).([]int64) - } - if f.ti.mbs { - ft.EncAsMapSliceInt64V(v, e) - return - } - ft.EncSliceInt64V(v, e) -} -func (fastpathETMsgpackBytes) EncSliceInt64V(v []int64, e *encoderMsgpackBytes) { - if len(v) == 0 { - e.c = 0 - e.e.WriteArrayEmpty() - return - } - e.arrayStart(len(v)) - for j := range v { - e.c = containerArrayElem - e.e.WriteArrayElem(j == 0) - e.e.EncodeInt(v[j]) - } - e.c = 0 - e.e.WriteArrayEnd() -} -func (fastpathETMsgpackBytes) EncAsMapSliceInt64V(v []int64, e *encoderMsgpackBytes) { - if len(v) == 0 { - e.c = 0 - e.e.WriteMapEmpty() - return - } - e.haltOnMbsOddLen(len(v)) - e.mapStart(len(v) >> 1) - for j := range v { - if j&1 == 0 { - e.c = containerMapKey - e.e.WriteMapElemKey(j == 0) - } else { - e.mapElemValue() - } - e.e.EncodeInt(v[j]) - } - e.c = 0 - e.e.WriteMapEnd() -} - -func (e *encoderMsgpackBytes) fastpathEncSliceBoolR(f *encFnInfo, rv reflect.Value) { - var ft fastpathETMsgpackBytes - var v []bool - if rv.Kind() == reflect.Array { - rvGetSlice4Array(rv, &v) - } else { - v = rv2i(rv).([]bool) - } - if f.ti.mbs { - ft.EncAsMapSliceBoolV(v, e) - return - } - ft.EncSliceBoolV(v, e) -} -func (fastpathETMsgpackBytes) EncSliceBoolV(v []bool, e *encoderMsgpackBytes) { - if len(v) == 0 { - e.c = 0 - e.e.WriteArrayEmpty() - return - } - e.arrayStart(len(v)) - for j := range v { - e.c = containerArrayElem - e.e.WriteArrayElem(j == 0) - e.e.EncodeBool(v[j]) - } - e.c = 0 - e.e.WriteArrayEnd() -} -func (fastpathETMsgpackBytes) EncAsMapSliceBoolV(v []bool, e *encoderMsgpackBytes) { - if len(v) == 0 { - e.c = 0 - e.e.WriteMapEmpty() - return - } - e.haltOnMbsOddLen(len(v)) - e.mapStart(len(v) >> 1) - for j := range v { - if j&1 == 0 { - e.c = containerMapKey - e.e.WriteMapElemKey(j == 0) - } else { - e.mapElemValue() - } - e.e.EncodeBool(v[j]) - } - e.c = 0 - e.e.WriteMapEnd() -} - -func (e *encoderMsgpackBytes) fastpathEncMapStringIntfR(f *encFnInfo, rv reflect.Value) { - fastpathETMsgpackBytes{}.EncMapStringIntfV(rv2i(rv).(map[string]interface{}), e) -} -func (fastpathETMsgpackBytes) EncMapStringIntfV(v map[string]interface{}, e *encoderMsgpackBytes) { - if len(v) == 0 { - e.e.WriteMapEmpty() - return - } - var i uint - e.mapStart(len(v)) - if e.h.Canonical { - v2 := make([]string, len(v)) - for k := range v { - v2[i] = k - i++ - } - slices.Sort(v2) - for i, k2 := range v2 { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeString(k2) - e.mapElemValue() - if !e.encodeBuiltin(v[k2]) { - e.encodeR(reflect.ValueOf(v[k2])) - } - } - } else { - i = 0 - for k2, v2 := range v { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeString(k2) - e.mapElemValue() - if !e.encodeBuiltin(v2) { - e.encodeR(reflect.ValueOf(v2)) - } - i++ - } - } - e.c = 0 - e.e.WriteMapEnd() -} -func (e *encoderMsgpackBytes) fastpathEncMapStringStringR(f *encFnInfo, rv reflect.Value) { - fastpathETMsgpackBytes{}.EncMapStringStringV(rv2i(rv).(map[string]string), e) -} -func (fastpathETMsgpackBytes) EncMapStringStringV(v map[string]string, e *encoderMsgpackBytes) { - if len(v) == 0 { - e.e.WriteMapEmpty() - return - } - var i uint - e.mapStart(len(v)) - if e.h.Canonical { - v2 := make([]string, len(v)) - for k := range v { - v2[i] = k - i++ - } - slices.Sort(v2) - for i, k2 := range v2 { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeString(k2) - e.mapElemValue() - e.e.EncodeString(v[k2]) - } - } else { - i = 0 - for k2, v2 := range v { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeString(k2) - e.mapElemValue() - e.e.EncodeString(v2) - i++ - } - } - e.c = 0 - e.e.WriteMapEnd() -} -func (e *encoderMsgpackBytes) fastpathEncMapStringBytesR(f *encFnInfo, rv reflect.Value) { - fastpathETMsgpackBytes{}.EncMapStringBytesV(rv2i(rv).(map[string][]byte), e) -} -func (fastpathETMsgpackBytes) EncMapStringBytesV(v map[string][]byte, e *encoderMsgpackBytes) { - if len(v) == 0 { - e.e.WriteMapEmpty() - return - } - var i uint - e.mapStart(len(v)) - if e.h.Canonical { - v2 := make([]string, len(v)) - for k := range v { - v2[i] = k - i++ - } - slices.Sort(v2) - for i, k2 := range v2 { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeString(k2) - e.mapElemValue() - e.e.EncodeBytes(v[k2]) - } - } else { - i = 0 - for k2, v2 := range v { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeString(k2) - e.mapElemValue() - e.e.EncodeBytes(v2) - i++ - } - } - e.c = 0 - e.e.WriteMapEnd() -} -func (e *encoderMsgpackBytes) fastpathEncMapStringUint8R(f *encFnInfo, rv reflect.Value) { - fastpathETMsgpackBytes{}.EncMapStringUint8V(rv2i(rv).(map[string]uint8), e) -} -func (fastpathETMsgpackBytes) EncMapStringUint8V(v map[string]uint8, e *encoderMsgpackBytes) { - if len(v) == 0 { - e.e.WriteMapEmpty() - return - } - var i uint - e.mapStart(len(v)) - if e.h.Canonical { - v2 := make([]string, len(v)) - for k := range v { - v2[i] = k - i++ - } - slices.Sort(v2) - for i, k2 := range v2 { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeString(k2) - e.mapElemValue() - e.e.EncodeUint(uint64(v[k2])) - } - } else { - i = 0 - for k2, v2 := range v { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeString(k2) - e.mapElemValue() - e.e.EncodeUint(uint64(v2)) - i++ - } - } - e.c = 0 - e.e.WriteMapEnd() -} -func (e *encoderMsgpackBytes) fastpathEncMapStringUint64R(f *encFnInfo, rv reflect.Value) { - fastpathETMsgpackBytes{}.EncMapStringUint64V(rv2i(rv).(map[string]uint64), e) -} -func (fastpathETMsgpackBytes) EncMapStringUint64V(v map[string]uint64, e *encoderMsgpackBytes) { - if len(v) == 0 { - e.e.WriteMapEmpty() - return - } - var i uint - e.mapStart(len(v)) - if e.h.Canonical { - v2 := make([]string, len(v)) - for k := range v { - v2[i] = k - i++ - } - slices.Sort(v2) - for i, k2 := range v2 { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeString(k2) - e.mapElemValue() - e.e.EncodeUint(v[k2]) - } - } else { - i = 0 - for k2, v2 := range v { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeString(k2) - e.mapElemValue() - e.e.EncodeUint(v2) - i++ - } - } - e.c = 0 - e.e.WriteMapEnd() -} -func (e *encoderMsgpackBytes) fastpathEncMapStringIntR(f *encFnInfo, rv reflect.Value) { - fastpathETMsgpackBytes{}.EncMapStringIntV(rv2i(rv).(map[string]int), e) -} -func (fastpathETMsgpackBytes) EncMapStringIntV(v map[string]int, e *encoderMsgpackBytes) { - if len(v) == 0 { - e.e.WriteMapEmpty() - return - } - var i uint - e.mapStart(len(v)) - if e.h.Canonical { - v2 := make([]string, len(v)) - for k := range v { - v2[i] = k - i++ - } - slices.Sort(v2) - for i, k2 := range v2 { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeString(k2) - e.mapElemValue() - e.e.EncodeInt(int64(v[k2])) - } - } else { - i = 0 - for k2, v2 := range v { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeString(k2) - e.mapElemValue() - e.e.EncodeInt(int64(v2)) - i++ - } - } - e.c = 0 - e.e.WriteMapEnd() -} -func (e *encoderMsgpackBytes) fastpathEncMapStringInt32R(f *encFnInfo, rv reflect.Value) { - fastpathETMsgpackBytes{}.EncMapStringInt32V(rv2i(rv).(map[string]int32), e) -} -func (fastpathETMsgpackBytes) EncMapStringInt32V(v map[string]int32, e *encoderMsgpackBytes) { - if len(v) == 0 { - e.e.WriteMapEmpty() - return - } - var i uint - e.mapStart(len(v)) - if e.h.Canonical { - v2 := make([]string, len(v)) - for k := range v { - v2[i] = k - i++ - } - slices.Sort(v2) - for i, k2 := range v2 { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeString(k2) - e.mapElemValue() - e.e.EncodeInt(int64(v[k2])) - } - } else { - i = 0 - for k2, v2 := range v { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeString(k2) - e.mapElemValue() - e.e.EncodeInt(int64(v2)) - i++ - } - } - e.c = 0 - e.e.WriteMapEnd() -} -func (e *encoderMsgpackBytes) fastpathEncMapStringFloat64R(f *encFnInfo, rv reflect.Value) { - fastpathETMsgpackBytes{}.EncMapStringFloat64V(rv2i(rv).(map[string]float64), e) -} -func (fastpathETMsgpackBytes) EncMapStringFloat64V(v map[string]float64, e *encoderMsgpackBytes) { - if len(v) == 0 { - e.e.WriteMapEmpty() - return - } - var i uint - e.mapStart(len(v)) - if e.h.Canonical { - v2 := make([]string, len(v)) - for k := range v { - v2[i] = k - i++ - } - slices.Sort(v2) - for i, k2 := range v2 { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeString(k2) - e.mapElemValue() - e.e.EncodeFloat64(v[k2]) - } - } else { - i = 0 - for k2, v2 := range v { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeString(k2) - e.mapElemValue() - e.e.EncodeFloat64(v2) - i++ - } - } - e.c = 0 - e.e.WriteMapEnd() -} -func (e *encoderMsgpackBytes) fastpathEncMapStringBoolR(f *encFnInfo, rv reflect.Value) { - fastpathETMsgpackBytes{}.EncMapStringBoolV(rv2i(rv).(map[string]bool), e) -} -func (fastpathETMsgpackBytes) EncMapStringBoolV(v map[string]bool, e *encoderMsgpackBytes) { - if len(v) == 0 { - e.e.WriteMapEmpty() - return - } - var i uint - e.mapStart(len(v)) - if e.h.Canonical { - v2 := make([]string, len(v)) - for k := range v { - v2[i] = k - i++ - } - slices.Sort(v2) - for i, k2 := range v2 { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeString(k2) - e.mapElemValue() - e.e.EncodeBool(v[k2]) - } - } else { - i = 0 - for k2, v2 := range v { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeString(k2) - e.mapElemValue() - e.e.EncodeBool(v2) - i++ - } - } - e.c = 0 - e.e.WriteMapEnd() -} -func (e *encoderMsgpackBytes) fastpathEncMapUint8IntfR(f *encFnInfo, rv reflect.Value) { - fastpathETMsgpackBytes{}.EncMapUint8IntfV(rv2i(rv).(map[uint8]interface{}), e) -} -func (fastpathETMsgpackBytes) EncMapUint8IntfV(v map[uint8]interface{}, e *encoderMsgpackBytes) { - if len(v) == 0 { - e.e.WriteMapEmpty() - return - } - var i uint - e.mapStart(len(v)) - if e.h.Canonical { - v2 := make([]uint8, len(v)) - for k := range v { - v2[i] = k - i++ - } - slices.Sort(v2) - for i, k2 := range v2 { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeUint(uint64(k2)) - e.mapElemValue() - if !e.encodeBuiltin(v[k2]) { - e.encodeR(reflect.ValueOf(v[k2])) - } - } - } else { - i = 0 - for k2, v2 := range v { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeUint(uint64(k2)) - e.mapElemValue() - if !e.encodeBuiltin(v2) { - e.encodeR(reflect.ValueOf(v2)) - } - i++ - } - } - e.c = 0 - e.e.WriteMapEnd() -} -func (e *encoderMsgpackBytes) fastpathEncMapUint8StringR(f *encFnInfo, rv reflect.Value) { - fastpathETMsgpackBytes{}.EncMapUint8StringV(rv2i(rv).(map[uint8]string), e) -} -func (fastpathETMsgpackBytes) EncMapUint8StringV(v map[uint8]string, e *encoderMsgpackBytes) { - if len(v) == 0 { - e.e.WriteMapEmpty() - return - } - var i uint - e.mapStart(len(v)) - if e.h.Canonical { - v2 := make([]uint8, len(v)) - for k := range v { - v2[i] = k - i++ - } - slices.Sort(v2) - for i, k2 := range v2 { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeUint(uint64(k2)) - e.mapElemValue() - e.e.EncodeString(v[k2]) - } - } else { - i = 0 - for k2, v2 := range v { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeUint(uint64(k2)) - e.mapElemValue() - e.e.EncodeString(v2) - i++ - } - } - e.c = 0 - e.e.WriteMapEnd() -} -func (e *encoderMsgpackBytes) fastpathEncMapUint8BytesR(f *encFnInfo, rv reflect.Value) { - fastpathETMsgpackBytes{}.EncMapUint8BytesV(rv2i(rv).(map[uint8][]byte), e) -} -func (fastpathETMsgpackBytes) EncMapUint8BytesV(v map[uint8][]byte, e *encoderMsgpackBytes) { - if len(v) == 0 { - e.e.WriteMapEmpty() - return - } - var i uint - e.mapStart(len(v)) - if e.h.Canonical { - v2 := make([]uint8, len(v)) - for k := range v { - v2[i] = k - i++ - } - slices.Sort(v2) - for i, k2 := range v2 { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeUint(uint64(k2)) - e.mapElemValue() - e.e.EncodeBytes(v[k2]) - } - } else { - i = 0 - for k2, v2 := range v { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeUint(uint64(k2)) - e.mapElemValue() - e.e.EncodeBytes(v2) - i++ - } - } - e.c = 0 - e.e.WriteMapEnd() -} -func (e *encoderMsgpackBytes) fastpathEncMapUint8Uint8R(f *encFnInfo, rv reflect.Value) { - fastpathETMsgpackBytes{}.EncMapUint8Uint8V(rv2i(rv).(map[uint8]uint8), e) -} -func (fastpathETMsgpackBytes) EncMapUint8Uint8V(v map[uint8]uint8, e *encoderMsgpackBytes) { - if len(v) == 0 { - e.e.WriteMapEmpty() - return - } - var i uint - e.mapStart(len(v)) - if e.h.Canonical { - v2 := make([]uint8, len(v)) - for k := range v { - v2[i] = k - i++ - } - slices.Sort(v2) - for i, k2 := range v2 { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeUint(uint64(k2)) - e.mapElemValue() - e.e.EncodeUint(uint64(v[k2])) - } - } else { - i = 0 - for k2, v2 := range v { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeUint(uint64(k2)) - e.mapElemValue() - e.e.EncodeUint(uint64(v2)) - i++ - } - } - e.c = 0 - e.e.WriteMapEnd() -} -func (e *encoderMsgpackBytes) fastpathEncMapUint8Uint64R(f *encFnInfo, rv reflect.Value) { - fastpathETMsgpackBytes{}.EncMapUint8Uint64V(rv2i(rv).(map[uint8]uint64), e) -} -func (fastpathETMsgpackBytes) EncMapUint8Uint64V(v map[uint8]uint64, e *encoderMsgpackBytes) { - if len(v) == 0 { - e.e.WriteMapEmpty() - return - } - var i uint - e.mapStart(len(v)) - if e.h.Canonical { - v2 := make([]uint8, len(v)) - for k := range v { - v2[i] = k - i++ - } - slices.Sort(v2) - for i, k2 := range v2 { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeUint(uint64(k2)) - e.mapElemValue() - e.e.EncodeUint(v[k2]) - } - } else { - i = 0 - for k2, v2 := range v { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeUint(uint64(k2)) - e.mapElemValue() - e.e.EncodeUint(v2) - i++ - } - } - e.c = 0 - e.e.WriteMapEnd() -} -func (e *encoderMsgpackBytes) fastpathEncMapUint8IntR(f *encFnInfo, rv reflect.Value) { - fastpathETMsgpackBytes{}.EncMapUint8IntV(rv2i(rv).(map[uint8]int), e) -} -func (fastpathETMsgpackBytes) EncMapUint8IntV(v map[uint8]int, e *encoderMsgpackBytes) { - if len(v) == 0 { - e.e.WriteMapEmpty() - return - } - var i uint - e.mapStart(len(v)) - if e.h.Canonical { - v2 := make([]uint8, len(v)) - for k := range v { - v2[i] = k - i++ - } - slices.Sort(v2) - for i, k2 := range v2 { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeUint(uint64(k2)) - e.mapElemValue() - e.e.EncodeInt(int64(v[k2])) - } - } else { - i = 0 - for k2, v2 := range v { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeUint(uint64(k2)) - e.mapElemValue() - e.e.EncodeInt(int64(v2)) - i++ - } - } - e.c = 0 - e.e.WriteMapEnd() -} -func (e *encoderMsgpackBytes) fastpathEncMapUint8Int32R(f *encFnInfo, rv reflect.Value) { - fastpathETMsgpackBytes{}.EncMapUint8Int32V(rv2i(rv).(map[uint8]int32), e) -} -func (fastpathETMsgpackBytes) EncMapUint8Int32V(v map[uint8]int32, e *encoderMsgpackBytes) { - if len(v) == 0 { - e.e.WriteMapEmpty() - return - } - var i uint - e.mapStart(len(v)) - if e.h.Canonical { - v2 := make([]uint8, len(v)) - for k := range v { - v2[i] = k - i++ - } - slices.Sort(v2) - for i, k2 := range v2 { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeUint(uint64(k2)) - e.mapElemValue() - e.e.EncodeInt(int64(v[k2])) - } - } else { - i = 0 - for k2, v2 := range v { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeUint(uint64(k2)) - e.mapElemValue() - e.e.EncodeInt(int64(v2)) - i++ - } - } - e.c = 0 - e.e.WriteMapEnd() -} -func (e *encoderMsgpackBytes) fastpathEncMapUint8Float64R(f *encFnInfo, rv reflect.Value) { - fastpathETMsgpackBytes{}.EncMapUint8Float64V(rv2i(rv).(map[uint8]float64), e) -} -func (fastpathETMsgpackBytes) EncMapUint8Float64V(v map[uint8]float64, e *encoderMsgpackBytes) { - if len(v) == 0 { - e.e.WriteMapEmpty() - return - } - var i uint - e.mapStart(len(v)) - if e.h.Canonical { - v2 := make([]uint8, len(v)) - for k := range v { - v2[i] = k - i++ - } - slices.Sort(v2) - for i, k2 := range v2 { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeUint(uint64(k2)) - e.mapElemValue() - e.e.EncodeFloat64(v[k2]) - } - } else { - i = 0 - for k2, v2 := range v { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeUint(uint64(k2)) - e.mapElemValue() - e.e.EncodeFloat64(v2) - i++ - } - } - e.c = 0 - e.e.WriteMapEnd() -} -func (e *encoderMsgpackBytes) fastpathEncMapUint8BoolR(f *encFnInfo, rv reflect.Value) { - fastpathETMsgpackBytes{}.EncMapUint8BoolV(rv2i(rv).(map[uint8]bool), e) -} -func (fastpathETMsgpackBytes) EncMapUint8BoolV(v map[uint8]bool, e *encoderMsgpackBytes) { - if len(v) == 0 { - e.e.WriteMapEmpty() - return - } - var i uint - e.mapStart(len(v)) - if e.h.Canonical { - v2 := make([]uint8, len(v)) - for k := range v { - v2[i] = k - i++ - } - slices.Sort(v2) - for i, k2 := range v2 { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeUint(uint64(k2)) - e.mapElemValue() - e.e.EncodeBool(v[k2]) - } - } else { - i = 0 - for k2, v2 := range v { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeUint(uint64(k2)) - e.mapElemValue() - e.e.EncodeBool(v2) - i++ - } - } - e.c = 0 - e.e.WriteMapEnd() -} -func (e *encoderMsgpackBytes) fastpathEncMapUint64IntfR(f *encFnInfo, rv reflect.Value) { - fastpathETMsgpackBytes{}.EncMapUint64IntfV(rv2i(rv).(map[uint64]interface{}), e) -} -func (fastpathETMsgpackBytes) EncMapUint64IntfV(v map[uint64]interface{}, e *encoderMsgpackBytes) { - if len(v) == 0 { - e.e.WriteMapEmpty() - return - } - var i uint - e.mapStart(len(v)) - if e.h.Canonical { - v2 := make([]uint64, len(v)) - for k := range v { - v2[i] = k - i++ - } - slices.Sort(v2) - for i, k2 := range v2 { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeUint(k2) - e.mapElemValue() - if !e.encodeBuiltin(v[k2]) { - e.encodeR(reflect.ValueOf(v[k2])) - } - } - } else { - i = 0 - for k2, v2 := range v { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeUint(k2) - e.mapElemValue() - if !e.encodeBuiltin(v2) { - e.encodeR(reflect.ValueOf(v2)) - } - i++ - } - } - e.c = 0 - e.e.WriteMapEnd() -} -func (e *encoderMsgpackBytes) fastpathEncMapUint64StringR(f *encFnInfo, rv reflect.Value) { - fastpathETMsgpackBytes{}.EncMapUint64StringV(rv2i(rv).(map[uint64]string), e) -} -func (fastpathETMsgpackBytes) EncMapUint64StringV(v map[uint64]string, e *encoderMsgpackBytes) { - if len(v) == 0 { - e.e.WriteMapEmpty() - return - } - var i uint - e.mapStart(len(v)) - if e.h.Canonical { - v2 := make([]uint64, len(v)) - for k := range v { - v2[i] = k - i++ - } - slices.Sort(v2) - for i, k2 := range v2 { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeUint(k2) - e.mapElemValue() - e.e.EncodeString(v[k2]) - } - } else { - i = 0 - for k2, v2 := range v { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeUint(k2) - e.mapElemValue() - e.e.EncodeString(v2) - i++ - } - } - e.c = 0 - e.e.WriteMapEnd() -} -func (e *encoderMsgpackBytes) fastpathEncMapUint64BytesR(f *encFnInfo, rv reflect.Value) { - fastpathETMsgpackBytes{}.EncMapUint64BytesV(rv2i(rv).(map[uint64][]byte), e) -} -func (fastpathETMsgpackBytes) EncMapUint64BytesV(v map[uint64][]byte, e *encoderMsgpackBytes) { - if len(v) == 0 { - e.e.WriteMapEmpty() - return - } - var i uint - e.mapStart(len(v)) - if e.h.Canonical { - v2 := make([]uint64, len(v)) - for k := range v { - v2[i] = k - i++ - } - slices.Sort(v2) - for i, k2 := range v2 { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeUint(k2) - e.mapElemValue() - e.e.EncodeBytes(v[k2]) - } - } else { - i = 0 - for k2, v2 := range v { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeUint(k2) - e.mapElemValue() - e.e.EncodeBytes(v2) - i++ - } - } - e.c = 0 - e.e.WriteMapEnd() -} -func (e *encoderMsgpackBytes) fastpathEncMapUint64Uint8R(f *encFnInfo, rv reflect.Value) { - fastpathETMsgpackBytes{}.EncMapUint64Uint8V(rv2i(rv).(map[uint64]uint8), e) -} -func (fastpathETMsgpackBytes) EncMapUint64Uint8V(v map[uint64]uint8, e *encoderMsgpackBytes) { - if len(v) == 0 { - e.e.WriteMapEmpty() - return - } - var i uint - e.mapStart(len(v)) - if e.h.Canonical { - v2 := make([]uint64, len(v)) - for k := range v { - v2[i] = k - i++ - } - slices.Sort(v2) - for i, k2 := range v2 { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeUint(k2) - e.mapElemValue() - e.e.EncodeUint(uint64(v[k2])) - } - } else { - i = 0 - for k2, v2 := range v { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeUint(k2) - e.mapElemValue() - e.e.EncodeUint(uint64(v2)) - i++ - } - } - e.c = 0 - e.e.WriteMapEnd() -} -func (e *encoderMsgpackBytes) fastpathEncMapUint64Uint64R(f *encFnInfo, rv reflect.Value) { - fastpathETMsgpackBytes{}.EncMapUint64Uint64V(rv2i(rv).(map[uint64]uint64), e) -} -func (fastpathETMsgpackBytes) EncMapUint64Uint64V(v map[uint64]uint64, e *encoderMsgpackBytes) { - if len(v) == 0 { - e.e.WriteMapEmpty() - return - } - var i uint - e.mapStart(len(v)) - if e.h.Canonical { - v2 := make([]uint64, len(v)) - for k := range v { - v2[i] = k - i++ - } - slices.Sort(v2) - for i, k2 := range v2 { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeUint(k2) - e.mapElemValue() - e.e.EncodeUint(v[k2]) - } - } else { - i = 0 - for k2, v2 := range v { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeUint(k2) - e.mapElemValue() - e.e.EncodeUint(v2) - i++ - } - } - e.c = 0 - e.e.WriteMapEnd() -} -func (e *encoderMsgpackBytes) fastpathEncMapUint64IntR(f *encFnInfo, rv reflect.Value) { - fastpathETMsgpackBytes{}.EncMapUint64IntV(rv2i(rv).(map[uint64]int), e) -} -func (fastpathETMsgpackBytes) EncMapUint64IntV(v map[uint64]int, e *encoderMsgpackBytes) { - if len(v) == 0 { - e.e.WriteMapEmpty() - return - } - var i uint - e.mapStart(len(v)) - if e.h.Canonical { - v2 := make([]uint64, len(v)) - for k := range v { - v2[i] = k - i++ - } - slices.Sort(v2) - for i, k2 := range v2 { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeUint(k2) - e.mapElemValue() - e.e.EncodeInt(int64(v[k2])) - } - } else { - i = 0 - for k2, v2 := range v { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeUint(k2) - e.mapElemValue() - e.e.EncodeInt(int64(v2)) - i++ - } - } - e.c = 0 - e.e.WriteMapEnd() -} -func (e *encoderMsgpackBytes) fastpathEncMapUint64Int32R(f *encFnInfo, rv reflect.Value) { - fastpathETMsgpackBytes{}.EncMapUint64Int32V(rv2i(rv).(map[uint64]int32), e) -} -func (fastpathETMsgpackBytes) EncMapUint64Int32V(v map[uint64]int32, e *encoderMsgpackBytes) { - if len(v) == 0 { - e.e.WriteMapEmpty() - return - } - var i uint - e.mapStart(len(v)) - if e.h.Canonical { - v2 := make([]uint64, len(v)) - for k := range v { - v2[i] = k - i++ - } - slices.Sort(v2) - for i, k2 := range v2 { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeUint(k2) - e.mapElemValue() - e.e.EncodeInt(int64(v[k2])) - } - } else { - i = 0 - for k2, v2 := range v { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeUint(k2) - e.mapElemValue() - e.e.EncodeInt(int64(v2)) - i++ - } - } - e.c = 0 - e.e.WriteMapEnd() -} -func (e *encoderMsgpackBytes) fastpathEncMapUint64Float64R(f *encFnInfo, rv reflect.Value) { - fastpathETMsgpackBytes{}.EncMapUint64Float64V(rv2i(rv).(map[uint64]float64), e) -} -func (fastpathETMsgpackBytes) EncMapUint64Float64V(v map[uint64]float64, e *encoderMsgpackBytes) { - if len(v) == 0 { - e.e.WriteMapEmpty() - return - } - var i uint - e.mapStart(len(v)) - if e.h.Canonical { - v2 := make([]uint64, len(v)) - for k := range v { - v2[i] = k - i++ - } - slices.Sort(v2) - for i, k2 := range v2 { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeUint(k2) - e.mapElemValue() - e.e.EncodeFloat64(v[k2]) - } - } else { - i = 0 - for k2, v2 := range v { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeUint(k2) - e.mapElemValue() - e.e.EncodeFloat64(v2) - i++ - } - } - e.c = 0 - e.e.WriteMapEnd() -} -func (e *encoderMsgpackBytes) fastpathEncMapUint64BoolR(f *encFnInfo, rv reflect.Value) { - fastpathETMsgpackBytes{}.EncMapUint64BoolV(rv2i(rv).(map[uint64]bool), e) -} -func (fastpathETMsgpackBytes) EncMapUint64BoolV(v map[uint64]bool, e *encoderMsgpackBytes) { - if len(v) == 0 { - e.e.WriteMapEmpty() - return - } - var i uint - e.mapStart(len(v)) - if e.h.Canonical { - v2 := make([]uint64, len(v)) - for k := range v { - v2[i] = k - i++ - } - slices.Sort(v2) - for i, k2 := range v2 { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeUint(k2) - e.mapElemValue() - e.e.EncodeBool(v[k2]) - } - } else { - i = 0 - for k2, v2 := range v { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeUint(k2) - e.mapElemValue() - e.e.EncodeBool(v2) - i++ - } - } - e.c = 0 - e.e.WriteMapEnd() -} -func (e *encoderMsgpackBytes) fastpathEncMapIntIntfR(f *encFnInfo, rv reflect.Value) { - fastpathETMsgpackBytes{}.EncMapIntIntfV(rv2i(rv).(map[int]interface{}), e) -} -func (fastpathETMsgpackBytes) EncMapIntIntfV(v map[int]interface{}, e *encoderMsgpackBytes) { - if len(v) == 0 { - e.e.WriteMapEmpty() - return - } - var i uint - e.mapStart(len(v)) - if e.h.Canonical { - v2 := make([]int, len(v)) - for k := range v { - v2[i] = k - i++ - } - slices.Sort(v2) - for i, k2 := range v2 { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeInt(int64(k2)) - e.mapElemValue() - if !e.encodeBuiltin(v[k2]) { - e.encodeR(reflect.ValueOf(v[k2])) - } - } - } else { - i = 0 - for k2, v2 := range v { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeInt(int64(k2)) - e.mapElemValue() - if !e.encodeBuiltin(v2) { - e.encodeR(reflect.ValueOf(v2)) - } - i++ - } - } - e.c = 0 - e.e.WriteMapEnd() -} -func (e *encoderMsgpackBytes) fastpathEncMapIntStringR(f *encFnInfo, rv reflect.Value) { - fastpathETMsgpackBytes{}.EncMapIntStringV(rv2i(rv).(map[int]string), e) -} -func (fastpathETMsgpackBytes) EncMapIntStringV(v map[int]string, e *encoderMsgpackBytes) { - if len(v) == 0 { - e.e.WriteMapEmpty() - return - } - var i uint - e.mapStart(len(v)) - if e.h.Canonical { - v2 := make([]int, len(v)) - for k := range v { - v2[i] = k - i++ - } - slices.Sort(v2) - for i, k2 := range v2 { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeInt(int64(k2)) - e.mapElemValue() - e.e.EncodeString(v[k2]) - } - } else { - i = 0 - for k2, v2 := range v { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeInt(int64(k2)) - e.mapElemValue() - e.e.EncodeString(v2) - i++ - } - } - e.c = 0 - e.e.WriteMapEnd() -} -func (e *encoderMsgpackBytes) fastpathEncMapIntBytesR(f *encFnInfo, rv reflect.Value) { - fastpathETMsgpackBytes{}.EncMapIntBytesV(rv2i(rv).(map[int][]byte), e) -} -func (fastpathETMsgpackBytes) EncMapIntBytesV(v map[int][]byte, e *encoderMsgpackBytes) { - if len(v) == 0 { - e.e.WriteMapEmpty() - return - } - var i uint - e.mapStart(len(v)) - if e.h.Canonical { - v2 := make([]int, len(v)) - for k := range v { - v2[i] = k - i++ - } - slices.Sort(v2) - for i, k2 := range v2 { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeInt(int64(k2)) - e.mapElemValue() - e.e.EncodeBytes(v[k2]) - } - } else { - i = 0 - for k2, v2 := range v { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeInt(int64(k2)) - e.mapElemValue() - e.e.EncodeBytes(v2) - i++ - } - } - e.c = 0 - e.e.WriteMapEnd() -} -func (e *encoderMsgpackBytes) fastpathEncMapIntUint8R(f *encFnInfo, rv reflect.Value) { - fastpathETMsgpackBytes{}.EncMapIntUint8V(rv2i(rv).(map[int]uint8), e) -} -func (fastpathETMsgpackBytes) EncMapIntUint8V(v map[int]uint8, e *encoderMsgpackBytes) { - if len(v) == 0 { - e.e.WriteMapEmpty() - return - } - var i uint - e.mapStart(len(v)) - if e.h.Canonical { - v2 := make([]int, len(v)) - for k := range v { - v2[i] = k - i++ - } - slices.Sort(v2) - for i, k2 := range v2 { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeInt(int64(k2)) - e.mapElemValue() - e.e.EncodeUint(uint64(v[k2])) - } - } else { - i = 0 - for k2, v2 := range v { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeInt(int64(k2)) - e.mapElemValue() - e.e.EncodeUint(uint64(v2)) - i++ - } - } - e.c = 0 - e.e.WriteMapEnd() -} -func (e *encoderMsgpackBytes) fastpathEncMapIntUint64R(f *encFnInfo, rv reflect.Value) { - fastpathETMsgpackBytes{}.EncMapIntUint64V(rv2i(rv).(map[int]uint64), e) -} -func (fastpathETMsgpackBytes) EncMapIntUint64V(v map[int]uint64, e *encoderMsgpackBytes) { - if len(v) == 0 { - e.e.WriteMapEmpty() - return - } - var i uint - e.mapStart(len(v)) - if e.h.Canonical { - v2 := make([]int, len(v)) - for k := range v { - v2[i] = k - i++ - } - slices.Sort(v2) - for i, k2 := range v2 { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeInt(int64(k2)) - e.mapElemValue() - e.e.EncodeUint(v[k2]) - } - } else { - i = 0 - for k2, v2 := range v { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeInt(int64(k2)) - e.mapElemValue() - e.e.EncodeUint(v2) - i++ - } - } - e.c = 0 - e.e.WriteMapEnd() -} -func (e *encoderMsgpackBytes) fastpathEncMapIntIntR(f *encFnInfo, rv reflect.Value) { - fastpathETMsgpackBytes{}.EncMapIntIntV(rv2i(rv).(map[int]int), e) -} -func (fastpathETMsgpackBytes) EncMapIntIntV(v map[int]int, e *encoderMsgpackBytes) { - if len(v) == 0 { - e.e.WriteMapEmpty() - return - } - var i uint - e.mapStart(len(v)) - if e.h.Canonical { - v2 := make([]int, len(v)) - for k := range v { - v2[i] = k - i++ - } - slices.Sort(v2) - for i, k2 := range v2 { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeInt(int64(k2)) - e.mapElemValue() - e.e.EncodeInt(int64(v[k2])) - } - } else { - i = 0 - for k2, v2 := range v { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeInt(int64(k2)) - e.mapElemValue() - e.e.EncodeInt(int64(v2)) - i++ - } - } - e.c = 0 - e.e.WriteMapEnd() -} -func (e *encoderMsgpackBytes) fastpathEncMapIntInt32R(f *encFnInfo, rv reflect.Value) { - fastpathETMsgpackBytes{}.EncMapIntInt32V(rv2i(rv).(map[int]int32), e) -} -func (fastpathETMsgpackBytes) EncMapIntInt32V(v map[int]int32, e *encoderMsgpackBytes) { - if len(v) == 0 { - e.e.WriteMapEmpty() - return - } - var i uint - e.mapStart(len(v)) - if e.h.Canonical { - v2 := make([]int, len(v)) - for k := range v { - v2[i] = k - i++ - } - slices.Sort(v2) - for i, k2 := range v2 { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeInt(int64(k2)) - e.mapElemValue() - e.e.EncodeInt(int64(v[k2])) - } - } else { - i = 0 - for k2, v2 := range v { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeInt(int64(k2)) - e.mapElemValue() - e.e.EncodeInt(int64(v2)) - i++ - } - } - e.c = 0 - e.e.WriteMapEnd() -} -func (e *encoderMsgpackBytes) fastpathEncMapIntFloat64R(f *encFnInfo, rv reflect.Value) { - fastpathETMsgpackBytes{}.EncMapIntFloat64V(rv2i(rv).(map[int]float64), e) -} -func (fastpathETMsgpackBytes) EncMapIntFloat64V(v map[int]float64, e *encoderMsgpackBytes) { - if len(v) == 0 { - e.e.WriteMapEmpty() - return - } - var i uint - e.mapStart(len(v)) - if e.h.Canonical { - v2 := make([]int, len(v)) - for k := range v { - v2[i] = k - i++ - } - slices.Sort(v2) - for i, k2 := range v2 { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeInt(int64(k2)) - e.mapElemValue() - e.e.EncodeFloat64(v[k2]) - } - } else { - i = 0 - for k2, v2 := range v { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeInt(int64(k2)) - e.mapElemValue() - e.e.EncodeFloat64(v2) - i++ - } - } - e.c = 0 - e.e.WriteMapEnd() -} -func (e *encoderMsgpackBytes) fastpathEncMapIntBoolR(f *encFnInfo, rv reflect.Value) { - fastpathETMsgpackBytes{}.EncMapIntBoolV(rv2i(rv).(map[int]bool), e) -} -func (fastpathETMsgpackBytes) EncMapIntBoolV(v map[int]bool, e *encoderMsgpackBytes) { - if len(v) == 0 { - e.e.WriteMapEmpty() - return - } - var i uint - e.mapStart(len(v)) - if e.h.Canonical { - v2 := make([]int, len(v)) - for k := range v { - v2[i] = k - i++ - } - slices.Sort(v2) - for i, k2 := range v2 { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeInt(int64(k2)) - e.mapElemValue() - e.e.EncodeBool(v[k2]) - } - } else { - i = 0 - for k2, v2 := range v { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeInt(int64(k2)) - e.mapElemValue() - e.e.EncodeBool(v2) - i++ - } - } - e.c = 0 - e.e.WriteMapEnd() -} -func (e *encoderMsgpackBytes) fastpathEncMapInt32IntfR(f *encFnInfo, rv reflect.Value) { - fastpathETMsgpackBytes{}.EncMapInt32IntfV(rv2i(rv).(map[int32]interface{}), e) -} -func (fastpathETMsgpackBytes) EncMapInt32IntfV(v map[int32]interface{}, e *encoderMsgpackBytes) { - if len(v) == 0 { - e.e.WriteMapEmpty() - return - } - var i uint - e.mapStart(len(v)) - if e.h.Canonical { - v2 := make([]int32, len(v)) - for k := range v { - v2[i] = k - i++ - } - slices.Sort(v2) - for i, k2 := range v2 { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeInt(int64(k2)) - e.mapElemValue() - if !e.encodeBuiltin(v[k2]) { - e.encodeR(reflect.ValueOf(v[k2])) - } - } - } else { - i = 0 - for k2, v2 := range v { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeInt(int64(k2)) - e.mapElemValue() - if !e.encodeBuiltin(v2) { - e.encodeR(reflect.ValueOf(v2)) - } - i++ - } - } - e.c = 0 - e.e.WriteMapEnd() -} -func (e *encoderMsgpackBytes) fastpathEncMapInt32StringR(f *encFnInfo, rv reflect.Value) { - fastpathETMsgpackBytes{}.EncMapInt32StringV(rv2i(rv).(map[int32]string), e) -} -func (fastpathETMsgpackBytes) EncMapInt32StringV(v map[int32]string, e *encoderMsgpackBytes) { - if len(v) == 0 { - e.e.WriteMapEmpty() - return - } - var i uint - e.mapStart(len(v)) - if e.h.Canonical { - v2 := make([]int32, len(v)) - for k := range v { - v2[i] = k - i++ - } - slices.Sort(v2) - for i, k2 := range v2 { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeInt(int64(k2)) - e.mapElemValue() - e.e.EncodeString(v[k2]) - } - } else { - i = 0 - for k2, v2 := range v { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeInt(int64(k2)) - e.mapElemValue() - e.e.EncodeString(v2) - i++ - } - } - e.c = 0 - e.e.WriteMapEnd() -} -func (e *encoderMsgpackBytes) fastpathEncMapInt32BytesR(f *encFnInfo, rv reflect.Value) { - fastpathETMsgpackBytes{}.EncMapInt32BytesV(rv2i(rv).(map[int32][]byte), e) -} -func (fastpathETMsgpackBytes) EncMapInt32BytesV(v map[int32][]byte, e *encoderMsgpackBytes) { - if len(v) == 0 { - e.e.WriteMapEmpty() - return - } - var i uint - e.mapStart(len(v)) - if e.h.Canonical { - v2 := make([]int32, len(v)) - for k := range v { - v2[i] = k - i++ - } - slices.Sort(v2) - for i, k2 := range v2 { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeInt(int64(k2)) - e.mapElemValue() - e.e.EncodeBytes(v[k2]) - } - } else { - i = 0 - for k2, v2 := range v { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeInt(int64(k2)) - e.mapElemValue() - e.e.EncodeBytes(v2) - i++ - } - } - e.c = 0 - e.e.WriteMapEnd() -} -func (e *encoderMsgpackBytes) fastpathEncMapInt32Uint8R(f *encFnInfo, rv reflect.Value) { - fastpathETMsgpackBytes{}.EncMapInt32Uint8V(rv2i(rv).(map[int32]uint8), e) -} -func (fastpathETMsgpackBytes) EncMapInt32Uint8V(v map[int32]uint8, e *encoderMsgpackBytes) { - if len(v) == 0 { - e.e.WriteMapEmpty() - return - } - var i uint - e.mapStart(len(v)) - if e.h.Canonical { - v2 := make([]int32, len(v)) - for k := range v { - v2[i] = k - i++ - } - slices.Sort(v2) - for i, k2 := range v2 { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeInt(int64(k2)) - e.mapElemValue() - e.e.EncodeUint(uint64(v[k2])) - } - } else { - i = 0 - for k2, v2 := range v { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeInt(int64(k2)) - e.mapElemValue() - e.e.EncodeUint(uint64(v2)) - i++ - } - } - e.c = 0 - e.e.WriteMapEnd() -} -func (e *encoderMsgpackBytes) fastpathEncMapInt32Uint64R(f *encFnInfo, rv reflect.Value) { - fastpathETMsgpackBytes{}.EncMapInt32Uint64V(rv2i(rv).(map[int32]uint64), e) -} -func (fastpathETMsgpackBytes) EncMapInt32Uint64V(v map[int32]uint64, e *encoderMsgpackBytes) { - if len(v) == 0 { - e.e.WriteMapEmpty() - return - } - var i uint - e.mapStart(len(v)) - if e.h.Canonical { - v2 := make([]int32, len(v)) - for k := range v { - v2[i] = k - i++ - } - slices.Sort(v2) - for i, k2 := range v2 { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeInt(int64(k2)) - e.mapElemValue() - e.e.EncodeUint(v[k2]) - } - } else { - i = 0 - for k2, v2 := range v { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeInt(int64(k2)) - e.mapElemValue() - e.e.EncodeUint(v2) - i++ - } - } - e.c = 0 - e.e.WriteMapEnd() -} -func (e *encoderMsgpackBytes) fastpathEncMapInt32IntR(f *encFnInfo, rv reflect.Value) { - fastpathETMsgpackBytes{}.EncMapInt32IntV(rv2i(rv).(map[int32]int), e) -} -func (fastpathETMsgpackBytes) EncMapInt32IntV(v map[int32]int, e *encoderMsgpackBytes) { - if len(v) == 0 { - e.e.WriteMapEmpty() - return - } - var i uint - e.mapStart(len(v)) - if e.h.Canonical { - v2 := make([]int32, len(v)) - for k := range v { - v2[i] = k - i++ - } - slices.Sort(v2) - for i, k2 := range v2 { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeInt(int64(k2)) - e.mapElemValue() - e.e.EncodeInt(int64(v[k2])) - } - } else { - i = 0 - for k2, v2 := range v { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeInt(int64(k2)) - e.mapElemValue() - e.e.EncodeInt(int64(v2)) - i++ - } - } - e.c = 0 - e.e.WriteMapEnd() -} -func (e *encoderMsgpackBytes) fastpathEncMapInt32Int32R(f *encFnInfo, rv reflect.Value) { - fastpathETMsgpackBytes{}.EncMapInt32Int32V(rv2i(rv).(map[int32]int32), e) -} -func (fastpathETMsgpackBytes) EncMapInt32Int32V(v map[int32]int32, e *encoderMsgpackBytes) { - if len(v) == 0 { - e.e.WriteMapEmpty() - return - } - var i uint - e.mapStart(len(v)) - if e.h.Canonical { - v2 := make([]int32, len(v)) - for k := range v { - v2[i] = k - i++ - } - slices.Sort(v2) - for i, k2 := range v2 { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeInt(int64(k2)) - e.mapElemValue() - e.e.EncodeInt(int64(v[k2])) - } - } else { - i = 0 - for k2, v2 := range v { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeInt(int64(k2)) - e.mapElemValue() - e.e.EncodeInt(int64(v2)) - i++ - } - } - e.c = 0 - e.e.WriteMapEnd() -} -func (e *encoderMsgpackBytes) fastpathEncMapInt32Float64R(f *encFnInfo, rv reflect.Value) { - fastpathETMsgpackBytes{}.EncMapInt32Float64V(rv2i(rv).(map[int32]float64), e) -} -func (fastpathETMsgpackBytes) EncMapInt32Float64V(v map[int32]float64, e *encoderMsgpackBytes) { - if len(v) == 0 { - e.e.WriteMapEmpty() - return - } - var i uint - e.mapStart(len(v)) - if e.h.Canonical { - v2 := make([]int32, len(v)) - for k := range v { - v2[i] = k - i++ - } - slices.Sort(v2) - for i, k2 := range v2 { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeInt(int64(k2)) - e.mapElemValue() - e.e.EncodeFloat64(v[k2]) - } - } else { - i = 0 - for k2, v2 := range v { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeInt(int64(k2)) - e.mapElemValue() - e.e.EncodeFloat64(v2) - i++ - } - } - e.c = 0 - e.e.WriteMapEnd() -} -func (e *encoderMsgpackBytes) fastpathEncMapInt32BoolR(f *encFnInfo, rv reflect.Value) { - fastpathETMsgpackBytes{}.EncMapInt32BoolV(rv2i(rv).(map[int32]bool), e) -} -func (fastpathETMsgpackBytes) EncMapInt32BoolV(v map[int32]bool, e *encoderMsgpackBytes) { - if len(v) == 0 { - e.e.WriteMapEmpty() - return - } - var i uint - e.mapStart(len(v)) - if e.h.Canonical { - v2 := make([]int32, len(v)) - for k := range v { - v2[i] = k - i++ - } - slices.Sort(v2) - for i, k2 := range v2 { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeInt(int64(k2)) - e.mapElemValue() - e.e.EncodeBool(v[k2]) - } - } else { - i = 0 - for k2, v2 := range v { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeInt(int64(k2)) - e.mapElemValue() - e.e.EncodeBool(v2) - i++ - } - } - e.c = 0 - e.e.WriteMapEnd() -} - -func (helperDecDriverMsgpackBytes) fastpathDecodeTypeSwitch(iv interface{}, d *decoderMsgpackBytes) bool { - var ft fastpathDTMsgpackBytes - var changed bool - var containerLen int - switch v := iv.(type) { - case []interface{}: - ft.DecSliceIntfN(v, d) - case *[]interface{}: - var v2 []interface{} - if v2, changed = ft.DecSliceIntfY(*v, d); changed { - *v = v2 - } - case []string: - ft.DecSliceStringN(v, d) - case *[]string: - var v2 []string - if v2, changed = ft.DecSliceStringY(*v, d); changed { - *v = v2 - } - case [][]byte: - ft.DecSliceBytesN(v, d) - case *[][]byte: - var v2 [][]byte - if v2, changed = ft.DecSliceBytesY(*v, d); changed { - *v = v2 - } - case []float32: - ft.DecSliceFloat32N(v, d) - case *[]float32: - var v2 []float32 - if v2, changed = ft.DecSliceFloat32Y(*v, d); changed { - *v = v2 - } - case []float64: - ft.DecSliceFloat64N(v, d) - case *[]float64: - var v2 []float64 - if v2, changed = ft.DecSliceFloat64Y(*v, d); changed { - *v = v2 - } - case []uint8: - ft.DecSliceUint8N(v, d) - case *[]uint8: - var v2 []uint8 - if v2, changed = ft.DecSliceUint8Y(*v, d); changed { - *v = v2 - } - case []uint64: - ft.DecSliceUint64N(v, d) - case *[]uint64: - var v2 []uint64 - if v2, changed = ft.DecSliceUint64Y(*v, d); changed { - *v = v2 - } - case []int: - ft.DecSliceIntN(v, d) - case *[]int: - var v2 []int - if v2, changed = ft.DecSliceIntY(*v, d); changed { - *v = v2 - } - case []int32: - ft.DecSliceInt32N(v, d) - case *[]int32: - var v2 []int32 - if v2, changed = ft.DecSliceInt32Y(*v, d); changed { - *v = v2 - } - case []int64: - ft.DecSliceInt64N(v, d) - case *[]int64: - var v2 []int64 - if v2, changed = ft.DecSliceInt64Y(*v, d); changed { - *v = v2 - } - case []bool: - ft.DecSliceBoolN(v, d) - case *[]bool: - var v2 []bool - if v2, changed = ft.DecSliceBoolY(*v, d); changed { - *v = v2 - } - case map[string]interface{}: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen != containerLenNil { - if containerLen != 0 { - ft.DecMapStringIntfL(v, containerLen, d) - } - d.mapEnd() - } - case *map[string]interface{}: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen == containerLenNil { - *v = nil - } else { - if *v == nil { - *v = make(map[string]interface{}, decInferLen(containerLen, d.maxInitLen(), 32)) - } - if containerLen != 0 { - ft.DecMapStringIntfL(*v, containerLen, d) - } - d.mapEnd() - } - case map[string]string: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen != containerLenNil { - if containerLen != 0 { - ft.DecMapStringStringL(v, containerLen, d) - } - d.mapEnd() - } - case *map[string]string: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen == containerLenNil { - *v = nil - } else { - if *v == nil { - *v = make(map[string]string, decInferLen(containerLen, d.maxInitLen(), 32)) - } - if containerLen != 0 { - ft.DecMapStringStringL(*v, containerLen, d) - } - d.mapEnd() - } - case map[string][]byte: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen != containerLenNil { - if containerLen != 0 { - ft.DecMapStringBytesL(v, containerLen, d) - } - d.mapEnd() - } - case *map[string][]byte: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen == containerLenNil { - *v = nil - } else { - if *v == nil { - *v = make(map[string][]byte, decInferLen(containerLen, d.maxInitLen(), 40)) - } - if containerLen != 0 { - ft.DecMapStringBytesL(*v, containerLen, d) - } - d.mapEnd() - } - case map[string]uint8: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen != containerLenNil { - if containerLen != 0 { - ft.DecMapStringUint8L(v, containerLen, d) - } - d.mapEnd() - } - case *map[string]uint8: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen == containerLenNil { - *v = nil - } else { - if *v == nil { - *v = make(map[string]uint8, decInferLen(containerLen, d.maxInitLen(), 17)) - } - if containerLen != 0 { - ft.DecMapStringUint8L(*v, containerLen, d) - } - d.mapEnd() - } - case map[string]uint64: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen != containerLenNil { - if containerLen != 0 { - ft.DecMapStringUint64L(v, containerLen, d) - } - d.mapEnd() - } - case *map[string]uint64: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen == containerLenNil { - *v = nil - } else { - if *v == nil { - *v = make(map[string]uint64, decInferLen(containerLen, d.maxInitLen(), 24)) - } - if containerLen != 0 { - ft.DecMapStringUint64L(*v, containerLen, d) - } - d.mapEnd() - } - case map[string]int: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen != containerLenNil { - if containerLen != 0 { - ft.DecMapStringIntL(v, containerLen, d) - } - d.mapEnd() - } - case *map[string]int: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen == containerLenNil { - *v = nil - } else { - if *v == nil { - *v = make(map[string]int, decInferLen(containerLen, d.maxInitLen(), 24)) - } - if containerLen != 0 { - ft.DecMapStringIntL(*v, containerLen, d) - } - d.mapEnd() - } - case map[string]int32: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen != containerLenNil { - if containerLen != 0 { - ft.DecMapStringInt32L(v, containerLen, d) - } - d.mapEnd() - } - case *map[string]int32: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen == containerLenNil { - *v = nil - } else { - if *v == nil { - *v = make(map[string]int32, decInferLen(containerLen, d.maxInitLen(), 20)) - } - if containerLen != 0 { - ft.DecMapStringInt32L(*v, containerLen, d) - } - d.mapEnd() - } - case map[string]float64: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen != containerLenNil { - if containerLen != 0 { - ft.DecMapStringFloat64L(v, containerLen, d) - } - d.mapEnd() - } - case *map[string]float64: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen == containerLenNil { - *v = nil - } else { - if *v == nil { - *v = make(map[string]float64, decInferLen(containerLen, d.maxInitLen(), 24)) - } - if containerLen != 0 { - ft.DecMapStringFloat64L(*v, containerLen, d) - } - d.mapEnd() - } - case map[string]bool: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen != containerLenNil { - if containerLen != 0 { - ft.DecMapStringBoolL(v, containerLen, d) - } - d.mapEnd() - } - case *map[string]bool: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen == containerLenNil { - *v = nil - } else { - if *v == nil { - *v = make(map[string]bool, decInferLen(containerLen, d.maxInitLen(), 17)) - } - if containerLen != 0 { - ft.DecMapStringBoolL(*v, containerLen, d) - } - d.mapEnd() - } - case map[uint8]interface{}: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen != containerLenNil { - if containerLen != 0 { - ft.DecMapUint8IntfL(v, containerLen, d) - } - d.mapEnd() - } - case *map[uint8]interface{}: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen == containerLenNil { - *v = nil - } else { - if *v == nil { - *v = make(map[uint8]interface{}, decInferLen(containerLen, d.maxInitLen(), 17)) - } - if containerLen != 0 { - ft.DecMapUint8IntfL(*v, containerLen, d) - } - d.mapEnd() - } - case map[uint8]string: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen != containerLenNil { - if containerLen != 0 { - ft.DecMapUint8StringL(v, containerLen, d) - } - d.mapEnd() - } - case *map[uint8]string: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen == containerLenNil { - *v = nil - } else { - if *v == nil { - *v = make(map[uint8]string, decInferLen(containerLen, d.maxInitLen(), 17)) - } - if containerLen != 0 { - ft.DecMapUint8StringL(*v, containerLen, d) - } - d.mapEnd() - } - case map[uint8][]byte: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen != containerLenNil { - if containerLen != 0 { - ft.DecMapUint8BytesL(v, containerLen, d) - } - d.mapEnd() - } - case *map[uint8][]byte: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen == containerLenNil { - *v = nil - } else { - if *v == nil { - *v = make(map[uint8][]byte, decInferLen(containerLen, d.maxInitLen(), 25)) - } - if containerLen != 0 { - ft.DecMapUint8BytesL(*v, containerLen, d) - } - d.mapEnd() - } - case map[uint8]uint8: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen != containerLenNil { - if containerLen != 0 { - ft.DecMapUint8Uint8L(v, containerLen, d) - } - d.mapEnd() - } - case *map[uint8]uint8: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen == containerLenNil { - *v = nil - } else { - if *v == nil { - *v = make(map[uint8]uint8, decInferLen(containerLen, d.maxInitLen(), 2)) - } - if containerLen != 0 { - ft.DecMapUint8Uint8L(*v, containerLen, d) - } - d.mapEnd() - } - case map[uint8]uint64: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen != containerLenNil { - if containerLen != 0 { - ft.DecMapUint8Uint64L(v, containerLen, d) - } - d.mapEnd() - } - case *map[uint8]uint64: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen == containerLenNil { - *v = nil - } else { - if *v == nil { - *v = make(map[uint8]uint64, decInferLen(containerLen, d.maxInitLen(), 9)) - } - if containerLen != 0 { - ft.DecMapUint8Uint64L(*v, containerLen, d) - } - d.mapEnd() - } - case map[uint8]int: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen != containerLenNil { - if containerLen != 0 { - ft.DecMapUint8IntL(v, containerLen, d) - } - d.mapEnd() - } - case *map[uint8]int: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen == containerLenNil { - *v = nil - } else { - if *v == nil { - *v = make(map[uint8]int, decInferLen(containerLen, d.maxInitLen(), 9)) - } - if containerLen != 0 { - ft.DecMapUint8IntL(*v, containerLen, d) - } - d.mapEnd() - } - case map[uint8]int32: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen != containerLenNil { - if containerLen != 0 { - ft.DecMapUint8Int32L(v, containerLen, d) - } - d.mapEnd() - } - case *map[uint8]int32: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen == containerLenNil { - *v = nil - } else { - if *v == nil { - *v = make(map[uint8]int32, decInferLen(containerLen, d.maxInitLen(), 5)) - } - if containerLen != 0 { - ft.DecMapUint8Int32L(*v, containerLen, d) - } - d.mapEnd() - } - case map[uint8]float64: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen != containerLenNil { - if containerLen != 0 { - ft.DecMapUint8Float64L(v, containerLen, d) - } - d.mapEnd() - } - case *map[uint8]float64: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen == containerLenNil { - *v = nil - } else { - if *v == nil { - *v = make(map[uint8]float64, decInferLen(containerLen, d.maxInitLen(), 9)) - } - if containerLen != 0 { - ft.DecMapUint8Float64L(*v, containerLen, d) - } - d.mapEnd() - } - case map[uint8]bool: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen != containerLenNil { - if containerLen != 0 { - ft.DecMapUint8BoolL(v, containerLen, d) - } - d.mapEnd() - } - case *map[uint8]bool: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen == containerLenNil { - *v = nil - } else { - if *v == nil { - *v = make(map[uint8]bool, decInferLen(containerLen, d.maxInitLen(), 2)) - } - if containerLen != 0 { - ft.DecMapUint8BoolL(*v, containerLen, d) - } - d.mapEnd() - } - case map[uint64]interface{}: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen != containerLenNil { - if containerLen != 0 { - ft.DecMapUint64IntfL(v, containerLen, d) - } - d.mapEnd() - } - case *map[uint64]interface{}: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen == containerLenNil { - *v = nil - } else { - if *v == nil { - *v = make(map[uint64]interface{}, decInferLen(containerLen, d.maxInitLen(), 24)) - } - if containerLen != 0 { - ft.DecMapUint64IntfL(*v, containerLen, d) - } - d.mapEnd() - } - case map[uint64]string: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen != containerLenNil { - if containerLen != 0 { - ft.DecMapUint64StringL(v, containerLen, d) - } - d.mapEnd() - } - case *map[uint64]string: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen == containerLenNil { - *v = nil - } else { - if *v == nil { - *v = make(map[uint64]string, decInferLen(containerLen, d.maxInitLen(), 24)) - } - if containerLen != 0 { - ft.DecMapUint64StringL(*v, containerLen, d) - } - d.mapEnd() - } - case map[uint64][]byte: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen != containerLenNil { - if containerLen != 0 { - ft.DecMapUint64BytesL(v, containerLen, d) - } - d.mapEnd() - } - case *map[uint64][]byte: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen == containerLenNil { - *v = nil - } else { - if *v == nil { - *v = make(map[uint64][]byte, decInferLen(containerLen, d.maxInitLen(), 32)) - } - if containerLen != 0 { - ft.DecMapUint64BytesL(*v, containerLen, d) - } - d.mapEnd() - } - case map[uint64]uint8: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen != containerLenNil { - if containerLen != 0 { - ft.DecMapUint64Uint8L(v, containerLen, d) - } - d.mapEnd() - } - case *map[uint64]uint8: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen == containerLenNil { - *v = nil - } else { - if *v == nil { - *v = make(map[uint64]uint8, decInferLen(containerLen, d.maxInitLen(), 9)) - } - if containerLen != 0 { - ft.DecMapUint64Uint8L(*v, containerLen, d) - } - d.mapEnd() - } - case map[uint64]uint64: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen != containerLenNil { - if containerLen != 0 { - ft.DecMapUint64Uint64L(v, containerLen, d) - } - d.mapEnd() - } - case *map[uint64]uint64: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen == containerLenNil { - *v = nil - } else { - if *v == nil { - *v = make(map[uint64]uint64, decInferLen(containerLen, d.maxInitLen(), 16)) - } - if containerLen != 0 { - ft.DecMapUint64Uint64L(*v, containerLen, d) - } - d.mapEnd() - } - case map[uint64]int: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen != containerLenNil { - if containerLen != 0 { - ft.DecMapUint64IntL(v, containerLen, d) - } - d.mapEnd() - } - case *map[uint64]int: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen == containerLenNil { - *v = nil - } else { - if *v == nil { - *v = make(map[uint64]int, decInferLen(containerLen, d.maxInitLen(), 16)) - } - if containerLen != 0 { - ft.DecMapUint64IntL(*v, containerLen, d) - } - d.mapEnd() - } - case map[uint64]int32: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen != containerLenNil { - if containerLen != 0 { - ft.DecMapUint64Int32L(v, containerLen, d) - } - d.mapEnd() - } - case *map[uint64]int32: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen == containerLenNil { - *v = nil - } else { - if *v == nil { - *v = make(map[uint64]int32, decInferLen(containerLen, d.maxInitLen(), 12)) - } - if containerLen != 0 { - ft.DecMapUint64Int32L(*v, containerLen, d) - } - d.mapEnd() - } - case map[uint64]float64: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen != containerLenNil { - if containerLen != 0 { - ft.DecMapUint64Float64L(v, containerLen, d) - } - d.mapEnd() - } - case *map[uint64]float64: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen == containerLenNil { - *v = nil - } else { - if *v == nil { - *v = make(map[uint64]float64, decInferLen(containerLen, d.maxInitLen(), 16)) - } - if containerLen != 0 { - ft.DecMapUint64Float64L(*v, containerLen, d) - } - d.mapEnd() - } - case map[uint64]bool: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen != containerLenNil { - if containerLen != 0 { - ft.DecMapUint64BoolL(v, containerLen, d) - } - d.mapEnd() - } - case *map[uint64]bool: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen == containerLenNil { - *v = nil - } else { - if *v == nil { - *v = make(map[uint64]bool, decInferLen(containerLen, d.maxInitLen(), 9)) - } - if containerLen != 0 { - ft.DecMapUint64BoolL(*v, containerLen, d) - } - d.mapEnd() - } - case map[int]interface{}: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen != containerLenNil { - if containerLen != 0 { - ft.DecMapIntIntfL(v, containerLen, d) - } - d.mapEnd() - } - case *map[int]interface{}: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen == containerLenNil { - *v = nil - } else { - if *v == nil { - *v = make(map[int]interface{}, decInferLen(containerLen, d.maxInitLen(), 24)) - } - if containerLen != 0 { - ft.DecMapIntIntfL(*v, containerLen, d) - } - d.mapEnd() - } - case map[int]string: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen != containerLenNil { - if containerLen != 0 { - ft.DecMapIntStringL(v, containerLen, d) - } - d.mapEnd() - } - case *map[int]string: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen == containerLenNil { - *v = nil - } else { - if *v == nil { - *v = make(map[int]string, decInferLen(containerLen, d.maxInitLen(), 24)) - } - if containerLen != 0 { - ft.DecMapIntStringL(*v, containerLen, d) - } - d.mapEnd() - } - case map[int][]byte: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen != containerLenNil { - if containerLen != 0 { - ft.DecMapIntBytesL(v, containerLen, d) - } - d.mapEnd() - } - case *map[int][]byte: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen == containerLenNil { - *v = nil - } else { - if *v == nil { - *v = make(map[int][]byte, decInferLen(containerLen, d.maxInitLen(), 32)) - } - if containerLen != 0 { - ft.DecMapIntBytesL(*v, containerLen, d) - } - d.mapEnd() - } - case map[int]uint8: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen != containerLenNil { - if containerLen != 0 { - ft.DecMapIntUint8L(v, containerLen, d) - } - d.mapEnd() - } - case *map[int]uint8: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen == containerLenNil { - *v = nil - } else { - if *v == nil { - *v = make(map[int]uint8, decInferLen(containerLen, d.maxInitLen(), 9)) - } - if containerLen != 0 { - ft.DecMapIntUint8L(*v, containerLen, d) - } - d.mapEnd() - } - case map[int]uint64: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen != containerLenNil { - if containerLen != 0 { - ft.DecMapIntUint64L(v, containerLen, d) - } - d.mapEnd() - } - case *map[int]uint64: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen == containerLenNil { - *v = nil - } else { - if *v == nil { - *v = make(map[int]uint64, decInferLen(containerLen, d.maxInitLen(), 16)) - } - if containerLen != 0 { - ft.DecMapIntUint64L(*v, containerLen, d) - } - d.mapEnd() - } - case map[int]int: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen != containerLenNil { - if containerLen != 0 { - ft.DecMapIntIntL(v, containerLen, d) - } - d.mapEnd() - } - case *map[int]int: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen == containerLenNil { - *v = nil - } else { - if *v == nil { - *v = make(map[int]int, decInferLen(containerLen, d.maxInitLen(), 16)) - } - if containerLen != 0 { - ft.DecMapIntIntL(*v, containerLen, d) - } - d.mapEnd() - } - case map[int]int32: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen != containerLenNil { - if containerLen != 0 { - ft.DecMapIntInt32L(v, containerLen, d) - } - d.mapEnd() - } - case *map[int]int32: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen == containerLenNil { - *v = nil - } else { - if *v == nil { - *v = make(map[int]int32, decInferLen(containerLen, d.maxInitLen(), 12)) - } - if containerLen != 0 { - ft.DecMapIntInt32L(*v, containerLen, d) - } - d.mapEnd() - } - case map[int]float64: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen != containerLenNil { - if containerLen != 0 { - ft.DecMapIntFloat64L(v, containerLen, d) - } - d.mapEnd() - } - case *map[int]float64: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen == containerLenNil { - *v = nil - } else { - if *v == nil { - *v = make(map[int]float64, decInferLen(containerLen, d.maxInitLen(), 16)) - } - if containerLen != 0 { - ft.DecMapIntFloat64L(*v, containerLen, d) - } - d.mapEnd() - } - case map[int]bool: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen != containerLenNil { - if containerLen != 0 { - ft.DecMapIntBoolL(v, containerLen, d) - } - d.mapEnd() - } - case *map[int]bool: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen == containerLenNil { - *v = nil - } else { - if *v == nil { - *v = make(map[int]bool, decInferLen(containerLen, d.maxInitLen(), 9)) - } - if containerLen != 0 { - ft.DecMapIntBoolL(*v, containerLen, d) - } - d.mapEnd() - } - case map[int32]interface{}: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen != containerLenNil { - if containerLen != 0 { - ft.DecMapInt32IntfL(v, containerLen, d) - } - d.mapEnd() - } - case *map[int32]interface{}: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen == containerLenNil { - *v = nil - } else { - if *v == nil { - *v = make(map[int32]interface{}, decInferLen(containerLen, d.maxInitLen(), 20)) - } - if containerLen != 0 { - ft.DecMapInt32IntfL(*v, containerLen, d) - } - d.mapEnd() - } - case map[int32]string: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen != containerLenNil { - if containerLen != 0 { - ft.DecMapInt32StringL(v, containerLen, d) - } - d.mapEnd() - } - case *map[int32]string: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen == containerLenNil { - *v = nil - } else { - if *v == nil { - *v = make(map[int32]string, decInferLen(containerLen, d.maxInitLen(), 20)) - } - if containerLen != 0 { - ft.DecMapInt32StringL(*v, containerLen, d) - } - d.mapEnd() - } - case map[int32][]byte: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen != containerLenNil { - if containerLen != 0 { - ft.DecMapInt32BytesL(v, containerLen, d) - } - d.mapEnd() - } - case *map[int32][]byte: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen == containerLenNil { - *v = nil - } else { - if *v == nil { - *v = make(map[int32][]byte, decInferLen(containerLen, d.maxInitLen(), 28)) - } - if containerLen != 0 { - ft.DecMapInt32BytesL(*v, containerLen, d) - } - d.mapEnd() - } - case map[int32]uint8: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen != containerLenNil { - if containerLen != 0 { - ft.DecMapInt32Uint8L(v, containerLen, d) - } - d.mapEnd() - } - case *map[int32]uint8: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen == containerLenNil { - *v = nil - } else { - if *v == nil { - *v = make(map[int32]uint8, decInferLen(containerLen, d.maxInitLen(), 5)) - } - if containerLen != 0 { - ft.DecMapInt32Uint8L(*v, containerLen, d) - } - d.mapEnd() - } - case map[int32]uint64: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen != containerLenNil { - if containerLen != 0 { - ft.DecMapInt32Uint64L(v, containerLen, d) - } - d.mapEnd() - } - case *map[int32]uint64: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen == containerLenNil { - *v = nil - } else { - if *v == nil { - *v = make(map[int32]uint64, decInferLen(containerLen, d.maxInitLen(), 12)) - } - if containerLen != 0 { - ft.DecMapInt32Uint64L(*v, containerLen, d) - } - d.mapEnd() - } - case map[int32]int: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen != containerLenNil { - if containerLen != 0 { - ft.DecMapInt32IntL(v, containerLen, d) - } - d.mapEnd() - } - case *map[int32]int: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen == containerLenNil { - *v = nil - } else { - if *v == nil { - *v = make(map[int32]int, decInferLen(containerLen, d.maxInitLen(), 12)) - } - if containerLen != 0 { - ft.DecMapInt32IntL(*v, containerLen, d) - } - d.mapEnd() - } - case map[int32]int32: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen != containerLenNil { - if containerLen != 0 { - ft.DecMapInt32Int32L(v, containerLen, d) - } - d.mapEnd() - } - case *map[int32]int32: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen == containerLenNil { - *v = nil - } else { - if *v == nil { - *v = make(map[int32]int32, decInferLen(containerLen, d.maxInitLen(), 8)) - } - if containerLen != 0 { - ft.DecMapInt32Int32L(*v, containerLen, d) - } - d.mapEnd() - } - case map[int32]float64: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen != containerLenNil { - if containerLen != 0 { - ft.DecMapInt32Float64L(v, containerLen, d) - } - d.mapEnd() - } - case *map[int32]float64: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen == containerLenNil { - *v = nil - } else { - if *v == nil { - *v = make(map[int32]float64, decInferLen(containerLen, d.maxInitLen(), 12)) - } - if containerLen != 0 { - ft.DecMapInt32Float64L(*v, containerLen, d) - } - d.mapEnd() - } - case map[int32]bool: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen != containerLenNil { - if containerLen != 0 { - ft.DecMapInt32BoolL(v, containerLen, d) - } - d.mapEnd() - } - case *map[int32]bool: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen == containerLenNil { - *v = nil - } else { - if *v == nil { - *v = make(map[int32]bool, decInferLen(containerLen, d.maxInitLen(), 5)) - } - if containerLen != 0 { - ft.DecMapInt32BoolL(*v, containerLen, d) - } - d.mapEnd() - } - default: - _ = v - return false - } - return true -} - -func (d *decoderMsgpackBytes) fastpathDecSliceIntfR(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTMsgpackBytes - switch rv.Kind() { - case reflect.Ptr: - v := rv2i(rv).(*[]interface{}) - if vv, changed := ft.DecSliceIntfY(*v, d); changed { - *v = vv - } - case reflect.Array: - var v []interface{} - rvGetSlice4Array(rv, &v) - ft.DecSliceIntfN(v, d) - default: - ft.DecSliceIntfN(rv2i(rv).([]interface{}), d) - } -} -func (fastpathDTMsgpackBytes) DecSliceIntfY(v []interface{}, d *decoderMsgpackBytes) (v2 []interface{}, changed bool) { - ctyp := d.d.ContainerType() - if ctyp == valueTypeNil { - return nil, v != nil - } - var containerLenS int - isArray := ctyp == valueTypeArray - if isArray { - containerLenS = d.arrayStart(d.d.ReadArrayStart()) - } else if ctyp == valueTypeMap { - containerLenS = d.mapStart(d.d.ReadMapStart()) * 2 - } else { - halt.errorStr2("decoding into a slice, expect map/array - got ", ctyp.String()) - } - hasLen := containerLenS >= 0 - var j int - fnv := func(dst []interface{}) { v, changed = dst, true } - for ; d.containerNext(j, containerLenS, hasLen); j++ { - if j == 0 { - if containerLenS == len(v) { - } else if containerLenS < 0 || containerLenS > cap(v) { - if xlen := int(decInferLen(containerLenS, d.maxInitLen(), 16)); xlen <= cap(v) { - fnv(v[:uint(xlen)]) - } else { - v2 = make([]interface{}, uint(xlen)) - copy(v2, v) - fnv(v2) - } - } else { - fnv(v[:containerLenS]) - } - } - if isArray { - d.arrayElem(j == 0) - } else if j&1 == 0 { - d.mapElemKey(j == 0) - } else { - d.mapElemValue() - } - if j >= len(v) { - fnv(append(v, nil)) - } - d.decode(&v[uint(j)]) - } - if j < len(v) { - fnv(v[:uint(j)]) - } else if j == 0 && v == nil { - fnv([]interface{}{}) - } - if isArray { - d.arrayEnd() - } else { - d.mapEnd() - } - return v, changed -} -func (fastpathDTMsgpackBytes) DecSliceIntfN(v []interface{}, d *decoderMsgpackBytes) { - ctyp := d.d.ContainerType() - if ctyp == valueTypeNil { - return - } - var containerLenS int - isArray := ctyp == valueTypeArray - if isArray { - containerLenS = d.arrayStart(d.d.ReadArrayStart()) - } else if ctyp == valueTypeMap { - containerLenS = d.mapStart(d.d.ReadMapStart()) * 2 - } else { - halt.errorStr2("decoding into a slice, expect map/array - got ", ctyp.String()) - } - hasLen := containerLenS >= 0 - for j := 0; d.containerNext(j, containerLenS, hasLen); j++ { - if isArray { - d.arrayElem(j == 0) - } else if j&1 == 0 { - d.mapElemKey(j == 0) - } else { - d.mapElemValue() - } - if j < len(v) { - d.decode(&v[uint(j)]) - } else { - d.arrayCannotExpand(len(v), j+1) - d.swallow() - } - } - if isArray { - d.arrayEnd() - } else { - d.mapEnd() - } -} - -func (d *decoderMsgpackBytes) fastpathDecSliceStringR(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTMsgpackBytes - switch rv.Kind() { - case reflect.Ptr: - v := rv2i(rv).(*[]string) - if vv, changed := ft.DecSliceStringY(*v, d); changed { - *v = vv - } - case reflect.Array: - var v []string - rvGetSlice4Array(rv, &v) - ft.DecSliceStringN(v, d) - default: - ft.DecSliceStringN(rv2i(rv).([]string), d) - } -} -func (fastpathDTMsgpackBytes) DecSliceStringY(v []string, d *decoderMsgpackBytes) (v2 []string, changed bool) { - ctyp := d.d.ContainerType() - if ctyp == valueTypeNil { - return nil, v != nil - } - var containerLenS int - isArray := ctyp == valueTypeArray - if isArray { - containerLenS = d.arrayStart(d.d.ReadArrayStart()) - } else if ctyp == valueTypeMap { - containerLenS = d.mapStart(d.d.ReadMapStart()) * 2 - } else { - halt.errorStr2("decoding into a slice, expect map/array - got ", ctyp.String()) - } - hasLen := containerLenS >= 0 - var j int - fnv := func(dst []string) { v, changed = dst, true } - for ; d.containerNext(j, containerLenS, hasLen); j++ { - if j == 0 { - if containerLenS == len(v) { - } else if containerLenS < 0 || containerLenS > cap(v) { - if xlen := int(decInferLen(containerLenS, d.maxInitLen(), 16)); xlen <= cap(v) { - fnv(v[:uint(xlen)]) - } else { - v2 = make([]string, uint(xlen)) - copy(v2, v) - fnv(v2) - } - } else { - fnv(v[:containerLenS]) - } - } - if isArray { - d.arrayElem(j == 0) - } else if j&1 == 0 { - d.mapElemKey(j == 0) - } else { - d.mapElemValue() - } - if j >= len(v) { - fnv(append(v, "")) - } - v[uint(j)] = d.detach2Str(d.d.DecodeStringAsBytes()) - } - if j < len(v) { - fnv(v[:uint(j)]) - } else if j == 0 && v == nil { - fnv([]string{}) - } - if isArray { - d.arrayEnd() - } else { - d.mapEnd() - } - return v, changed -} -func (fastpathDTMsgpackBytes) DecSliceStringN(v []string, d *decoderMsgpackBytes) { - ctyp := d.d.ContainerType() - if ctyp == valueTypeNil { - return - } - var containerLenS int - isArray := ctyp == valueTypeArray - if isArray { - containerLenS = d.arrayStart(d.d.ReadArrayStart()) - } else if ctyp == valueTypeMap { - containerLenS = d.mapStart(d.d.ReadMapStart()) * 2 - } else { - halt.errorStr2("decoding into a slice, expect map/array - got ", ctyp.String()) - } - hasLen := containerLenS >= 0 - for j := 0; d.containerNext(j, containerLenS, hasLen); j++ { - if isArray { - d.arrayElem(j == 0) - } else if j&1 == 0 { - d.mapElemKey(j == 0) - } else { - d.mapElemValue() - } - if j < len(v) { - v[uint(j)] = d.detach2Str(d.d.DecodeStringAsBytes()) - } else { - d.arrayCannotExpand(len(v), j+1) - d.swallow() - } - } - if isArray { - d.arrayEnd() - } else { - d.mapEnd() - } -} - -func (d *decoderMsgpackBytes) fastpathDecSliceBytesR(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTMsgpackBytes - switch rv.Kind() { - case reflect.Ptr: - v := rv2i(rv).(*[][]byte) - if vv, changed := ft.DecSliceBytesY(*v, d); changed { - *v = vv - } - case reflect.Array: - var v [][]byte - rvGetSlice4Array(rv, &v) - ft.DecSliceBytesN(v, d) - default: - ft.DecSliceBytesN(rv2i(rv).([][]byte), d) - } -} -func (fastpathDTMsgpackBytes) DecSliceBytesY(v [][]byte, d *decoderMsgpackBytes) (v2 [][]byte, changed bool) { - ctyp := d.d.ContainerType() - if ctyp == valueTypeNil { - return nil, v != nil - } - var containerLenS int - isArray := ctyp == valueTypeArray - if isArray { - containerLenS = d.arrayStart(d.d.ReadArrayStart()) - } else if ctyp == valueTypeMap { - containerLenS = d.mapStart(d.d.ReadMapStart()) * 2 - } else { - halt.errorStr2("decoding into a slice, expect map/array - got ", ctyp.String()) - } - hasLen := containerLenS >= 0 - var j int - fnv := func(dst [][]byte) { v, changed = dst, true } - for ; d.containerNext(j, containerLenS, hasLen); j++ { - if j == 0 { - if containerLenS == len(v) { - } else if containerLenS < 0 || containerLenS > cap(v) { - if xlen := int(decInferLen(containerLenS, d.maxInitLen(), 24)); xlen <= cap(v) { - fnv(v[:uint(xlen)]) - } else { - v2 = make([][]byte, uint(xlen)) - copy(v2, v) - fnv(v2) - } - } else { - fnv(v[:containerLenS]) - } - } - if isArray { - d.arrayElem(j == 0) - } else if j&1 == 0 { - d.mapElemKey(j == 0) - } else { - d.mapElemValue() - } - if j >= len(v) { - fnv(append(v, nil)) - } - v[uint(j)] = bytesOKdbi(d.decodeBytesInto(v[uint(j)], false)) - } - if j < len(v) { - fnv(v[:uint(j)]) - } else if j == 0 && v == nil { - fnv([][]byte{}) - } - if isArray { - d.arrayEnd() - } else { - d.mapEnd() - } - return v, changed -} -func (fastpathDTMsgpackBytes) DecSliceBytesN(v [][]byte, d *decoderMsgpackBytes) { - ctyp := d.d.ContainerType() - if ctyp == valueTypeNil { - return - } - var containerLenS int - isArray := ctyp == valueTypeArray - if isArray { - containerLenS = d.arrayStart(d.d.ReadArrayStart()) - } else if ctyp == valueTypeMap { - containerLenS = d.mapStart(d.d.ReadMapStart()) * 2 - } else { - halt.errorStr2("decoding into a slice, expect map/array - got ", ctyp.String()) - } - hasLen := containerLenS >= 0 - for j := 0; d.containerNext(j, containerLenS, hasLen); j++ { - if isArray { - d.arrayElem(j == 0) - } else if j&1 == 0 { - d.mapElemKey(j == 0) - } else { - d.mapElemValue() - } - if j < len(v) { - v[uint(j)] = bytesOKdbi(d.decodeBytesInto(v[uint(j)], false)) - } else { - d.arrayCannotExpand(len(v), j+1) - d.swallow() - } - } - if isArray { - d.arrayEnd() - } else { - d.mapEnd() - } -} - -func (d *decoderMsgpackBytes) fastpathDecSliceFloat32R(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTMsgpackBytes - switch rv.Kind() { - case reflect.Ptr: - v := rv2i(rv).(*[]float32) - if vv, changed := ft.DecSliceFloat32Y(*v, d); changed { - *v = vv - } - case reflect.Array: - var v []float32 - rvGetSlice4Array(rv, &v) - ft.DecSliceFloat32N(v, d) - default: - ft.DecSliceFloat32N(rv2i(rv).([]float32), d) - } -} -func (fastpathDTMsgpackBytes) DecSliceFloat32Y(v []float32, d *decoderMsgpackBytes) (v2 []float32, changed bool) { - ctyp := d.d.ContainerType() - if ctyp == valueTypeNil { - return nil, v != nil - } - var containerLenS int - isArray := ctyp == valueTypeArray - if isArray { - containerLenS = d.arrayStart(d.d.ReadArrayStart()) - } else if ctyp == valueTypeMap { - containerLenS = d.mapStart(d.d.ReadMapStart()) * 2 - } else { - halt.errorStr2("decoding into a slice, expect map/array - got ", ctyp.String()) - } - hasLen := containerLenS >= 0 - var j int - fnv := func(dst []float32) { v, changed = dst, true } - for ; d.containerNext(j, containerLenS, hasLen); j++ { - if j == 0 { - if containerLenS == len(v) { - } else if containerLenS < 0 || containerLenS > cap(v) { - if xlen := int(decInferLen(containerLenS, d.maxInitLen(), 4)); xlen <= cap(v) { - fnv(v[:uint(xlen)]) - } else { - v2 = make([]float32, uint(xlen)) - copy(v2, v) - fnv(v2) - } - } else { - fnv(v[:containerLenS]) - } - } - if isArray { - d.arrayElem(j == 0) - } else if j&1 == 0 { - d.mapElemKey(j == 0) - } else { - d.mapElemValue() - } - if j >= len(v) { - fnv(append(v, 0)) - } - v[uint(j)] = float32(d.d.DecodeFloat32()) - } - if j < len(v) { - fnv(v[:uint(j)]) - } else if j == 0 && v == nil { - fnv([]float32{}) - } - if isArray { - d.arrayEnd() - } else { - d.mapEnd() - } - return v, changed -} -func (fastpathDTMsgpackBytes) DecSliceFloat32N(v []float32, d *decoderMsgpackBytes) { - ctyp := d.d.ContainerType() - if ctyp == valueTypeNil { - return - } - var containerLenS int - isArray := ctyp == valueTypeArray - if isArray { - containerLenS = d.arrayStart(d.d.ReadArrayStart()) - } else if ctyp == valueTypeMap { - containerLenS = d.mapStart(d.d.ReadMapStart()) * 2 - } else { - halt.errorStr2("decoding into a slice, expect map/array - got ", ctyp.String()) - } - hasLen := containerLenS >= 0 - for j := 0; d.containerNext(j, containerLenS, hasLen); j++ { - if isArray { - d.arrayElem(j == 0) - } else if j&1 == 0 { - d.mapElemKey(j == 0) - } else { - d.mapElemValue() - } - if j < len(v) { - v[uint(j)] = float32(d.d.DecodeFloat32()) - } else { - d.arrayCannotExpand(len(v), j+1) - d.swallow() - } - } - if isArray { - d.arrayEnd() - } else { - d.mapEnd() - } -} - -func (d *decoderMsgpackBytes) fastpathDecSliceFloat64R(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTMsgpackBytes - switch rv.Kind() { - case reflect.Ptr: - v := rv2i(rv).(*[]float64) - if vv, changed := ft.DecSliceFloat64Y(*v, d); changed { - *v = vv - } - case reflect.Array: - var v []float64 - rvGetSlice4Array(rv, &v) - ft.DecSliceFloat64N(v, d) - default: - ft.DecSliceFloat64N(rv2i(rv).([]float64), d) - } -} -func (fastpathDTMsgpackBytes) DecSliceFloat64Y(v []float64, d *decoderMsgpackBytes) (v2 []float64, changed bool) { - ctyp := d.d.ContainerType() - if ctyp == valueTypeNil { - return nil, v != nil - } - var containerLenS int - isArray := ctyp == valueTypeArray - if isArray { - containerLenS = d.arrayStart(d.d.ReadArrayStart()) - } else if ctyp == valueTypeMap { - containerLenS = d.mapStart(d.d.ReadMapStart()) * 2 - } else { - halt.errorStr2("decoding into a slice, expect map/array - got ", ctyp.String()) - } - hasLen := containerLenS >= 0 - var j int - fnv := func(dst []float64) { v, changed = dst, true } - for ; d.containerNext(j, containerLenS, hasLen); j++ { - if j == 0 { - if containerLenS == len(v) { - } else if containerLenS < 0 || containerLenS > cap(v) { - if xlen := int(decInferLen(containerLenS, d.maxInitLen(), 8)); xlen <= cap(v) { - fnv(v[:uint(xlen)]) - } else { - v2 = make([]float64, uint(xlen)) - copy(v2, v) - fnv(v2) - } - } else { - fnv(v[:containerLenS]) - } - } - if isArray { - d.arrayElem(j == 0) - } else if j&1 == 0 { - d.mapElemKey(j == 0) - } else { - d.mapElemValue() - } - if j >= len(v) { - fnv(append(v, 0)) - } - v[uint(j)] = d.d.DecodeFloat64() - } - if j < len(v) { - fnv(v[:uint(j)]) - } else if j == 0 && v == nil { - fnv([]float64{}) - } - if isArray { - d.arrayEnd() - } else { - d.mapEnd() - } - return v, changed -} -func (fastpathDTMsgpackBytes) DecSliceFloat64N(v []float64, d *decoderMsgpackBytes) { - ctyp := d.d.ContainerType() - if ctyp == valueTypeNil { - return - } - var containerLenS int - isArray := ctyp == valueTypeArray - if isArray { - containerLenS = d.arrayStart(d.d.ReadArrayStart()) - } else if ctyp == valueTypeMap { - containerLenS = d.mapStart(d.d.ReadMapStart()) * 2 - } else { - halt.errorStr2("decoding into a slice, expect map/array - got ", ctyp.String()) - } - hasLen := containerLenS >= 0 - for j := 0; d.containerNext(j, containerLenS, hasLen); j++ { - if isArray { - d.arrayElem(j == 0) - } else if j&1 == 0 { - d.mapElemKey(j == 0) - } else { - d.mapElemValue() - } - if j < len(v) { - v[uint(j)] = d.d.DecodeFloat64() - } else { - d.arrayCannotExpand(len(v), j+1) - d.swallow() - } - } - if isArray { - d.arrayEnd() - } else { - d.mapEnd() - } -} - -func (d *decoderMsgpackBytes) fastpathDecSliceUint8R(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTMsgpackBytes - switch rv.Kind() { - case reflect.Ptr: - v := rv2i(rv).(*[]uint8) - if vv, changed := ft.DecSliceUint8Y(*v, d); changed { - *v = vv - } - case reflect.Array: - var v []uint8 - rvGetSlice4Array(rv, &v) - ft.DecSliceUint8N(v, d) - default: - ft.DecSliceUint8N(rv2i(rv).([]uint8), d) - } -} -func (fastpathDTMsgpackBytes) DecSliceUint8Y(v []uint8, d *decoderMsgpackBytes) (v2 []uint8, changed bool) { - ctyp := d.d.ContainerType() - if ctyp == valueTypeNil { - return nil, v != nil - } - if ctyp != valueTypeMap { - var dbi dBytesIntoState - v2, dbi = d.decodeBytesInto(v[:len(v):len(v)], false) - return v2, dbi != dBytesIntoParamOut - } - containerLenS := d.mapStart(d.d.ReadMapStart()) * 2 - hasLen := containerLenS >= 0 - var j int - fnv := func(dst []uint8) { v, changed = dst, true } - for ; d.containerNext(j, containerLenS, hasLen); j++ { - if j == 0 { - if containerLenS == len(v) { - } else if containerLenS < 0 || containerLenS > cap(v) { - if xlen := int(decInferLen(containerLenS, d.maxInitLen(), 1)); xlen <= cap(v) { - fnv(v[:uint(xlen)]) - } else { - v2 = make([]uint8, uint(xlen)) - copy(v2, v) - fnv(v2) - } - } else { - fnv(v[:containerLenS]) - } - } - if j&1 == 0 { - d.mapElemKey(j == 0) - } else { - d.mapElemValue() - } - if j >= len(v) { - fnv(append(v, 0)) - } - v[uint(j)] = uint8(chkOvf.UintV(d.d.DecodeUint64(), 8)) - } - if j < len(v) { - fnv(v[:uint(j)]) - } else if j == 0 && v == nil { - fnv([]uint8{}) - } - d.mapEnd() - return v, changed -} -func (fastpathDTMsgpackBytes) DecSliceUint8N(v []uint8, d *decoderMsgpackBytes) { - ctyp := d.d.ContainerType() - if ctyp == valueTypeNil { - return - } - if ctyp != valueTypeMap { - d.decodeBytesInto(v[:len(v):len(v)], true) - return - } - containerLenS := d.mapStart(d.d.ReadMapStart()) * 2 - hasLen := containerLenS >= 0 - for j := 0; d.containerNext(j, containerLenS, hasLen); j++ { - if j&1 == 0 { - d.mapElemKey(j == 0) - } else { - d.mapElemValue() - } - if j < len(v) { - v[uint(j)] = uint8(chkOvf.UintV(d.d.DecodeUint64(), 8)) - } else { - d.arrayCannotExpand(len(v), j+1) - d.swallow() - } - } - d.mapEnd() -} - -func (d *decoderMsgpackBytes) fastpathDecSliceUint64R(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTMsgpackBytes - switch rv.Kind() { - case reflect.Ptr: - v := rv2i(rv).(*[]uint64) - if vv, changed := ft.DecSliceUint64Y(*v, d); changed { - *v = vv - } - case reflect.Array: - var v []uint64 - rvGetSlice4Array(rv, &v) - ft.DecSliceUint64N(v, d) - default: - ft.DecSliceUint64N(rv2i(rv).([]uint64), d) - } -} -func (fastpathDTMsgpackBytes) DecSliceUint64Y(v []uint64, d *decoderMsgpackBytes) (v2 []uint64, changed bool) { - ctyp := d.d.ContainerType() - if ctyp == valueTypeNil { - return nil, v != nil - } - var containerLenS int - isArray := ctyp == valueTypeArray - if isArray { - containerLenS = d.arrayStart(d.d.ReadArrayStart()) - } else if ctyp == valueTypeMap { - containerLenS = d.mapStart(d.d.ReadMapStart()) * 2 - } else { - halt.errorStr2("decoding into a slice, expect map/array - got ", ctyp.String()) - } - hasLen := containerLenS >= 0 - var j int - fnv := func(dst []uint64) { v, changed = dst, true } - for ; d.containerNext(j, containerLenS, hasLen); j++ { - if j == 0 { - if containerLenS == len(v) { - } else if containerLenS < 0 || containerLenS > cap(v) { - if xlen := int(decInferLen(containerLenS, d.maxInitLen(), 8)); xlen <= cap(v) { - fnv(v[:uint(xlen)]) - } else { - v2 = make([]uint64, uint(xlen)) - copy(v2, v) - fnv(v2) - } - } else { - fnv(v[:containerLenS]) - } - } - if isArray { - d.arrayElem(j == 0) - } else if j&1 == 0 { - d.mapElemKey(j == 0) - } else { - d.mapElemValue() - } - if j >= len(v) { - fnv(append(v, 0)) - } - v[uint(j)] = d.d.DecodeUint64() - } - if j < len(v) { - fnv(v[:uint(j)]) - } else if j == 0 && v == nil { - fnv([]uint64{}) - } - if isArray { - d.arrayEnd() - } else { - d.mapEnd() - } - return v, changed -} -func (fastpathDTMsgpackBytes) DecSliceUint64N(v []uint64, d *decoderMsgpackBytes) { - ctyp := d.d.ContainerType() - if ctyp == valueTypeNil { - return - } - var containerLenS int - isArray := ctyp == valueTypeArray - if isArray { - containerLenS = d.arrayStart(d.d.ReadArrayStart()) - } else if ctyp == valueTypeMap { - containerLenS = d.mapStart(d.d.ReadMapStart()) * 2 - } else { - halt.errorStr2("decoding into a slice, expect map/array - got ", ctyp.String()) - } - hasLen := containerLenS >= 0 - for j := 0; d.containerNext(j, containerLenS, hasLen); j++ { - if isArray { - d.arrayElem(j == 0) - } else if j&1 == 0 { - d.mapElemKey(j == 0) - } else { - d.mapElemValue() - } - if j < len(v) { - v[uint(j)] = d.d.DecodeUint64() - } else { - d.arrayCannotExpand(len(v), j+1) - d.swallow() - } - } - if isArray { - d.arrayEnd() - } else { - d.mapEnd() - } -} - -func (d *decoderMsgpackBytes) fastpathDecSliceIntR(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTMsgpackBytes - switch rv.Kind() { - case reflect.Ptr: - v := rv2i(rv).(*[]int) - if vv, changed := ft.DecSliceIntY(*v, d); changed { - *v = vv - } - case reflect.Array: - var v []int - rvGetSlice4Array(rv, &v) - ft.DecSliceIntN(v, d) - default: - ft.DecSliceIntN(rv2i(rv).([]int), d) - } -} -func (fastpathDTMsgpackBytes) DecSliceIntY(v []int, d *decoderMsgpackBytes) (v2 []int, changed bool) { - ctyp := d.d.ContainerType() - if ctyp == valueTypeNil { - return nil, v != nil - } - var containerLenS int - isArray := ctyp == valueTypeArray - if isArray { - containerLenS = d.arrayStart(d.d.ReadArrayStart()) - } else if ctyp == valueTypeMap { - containerLenS = d.mapStart(d.d.ReadMapStart()) * 2 - } else { - halt.errorStr2("decoding into a slice, expect map/array - got ", ctyp.String()) - } - hasLen := containerLenS >= 0 - var j int - fnv := func(dst []int) { v, changed = dst, true } - for ; d.containerNext(j, containerLenS, hasLen); j++ { - if j == 0 { - if containerLenS == len(v) { - } else if containerLenS < 0 || containerLenS > cap(v) { - if xlen := int(decInferLen(containerLenS, d.maxInitLen(), 8)); xlen <= cap(v) { - fnv(v[:uint(xlen)]) - } else { - v2 = make([]int, uint(xlen)) - copy(v2, v) - fnv(v2) - } - } else { - fnv(v[:containerLenS]) - } - } - if isArray { - d.arrayElem(j == 0) - } else if j&1 == 0 { - d.mapElemKey(j == 0) - } else { - d.mapElemValue() - } - if j >= len(v) { - fnv(append(v, 0)) - } - v[uint(j)] = int(chkOvf.IntV(d.d.DecodeInt64(), intBitsize)) - } - if j < len(v) { - fnv(v[:uint(j)]) - } else if j == 0 && v == nil { - fnv([]int{}) - } - if isArray { - d.arrayEnd() - } else { - d.mapEnd() - } - return v, changed -} -func (fastpathDTMsgpackBytes) DecSliceIntN(v []int, d *decoderMsgpackBytes) { - ctyp := d.d.ContainerType() - if ctyp == valueTypeNil { - return - } - var containerLenS int - isArray := ctyp == valueTypeArray - if isArray { - containerLenS = d.arrayStart(d.d.ReadArrayStart()) - } else if ctyp == valueTypeMap { - containerLenS = d.mapStart(d.d.ReadMapStart()) * 2 - } else { - halt.errorStr2("decoding into a slice, expect map/array - got ", ctyp.String()) - } - hasLen := containerLenS >= 0 - for j := 0; d.containerNext(j, containerLenS, hasLen); j++ { - if isArray { - d.arrayElem(j == 0) - } else if j&1 == 0 { - d.mapElemKey(j == 0) - } else { - d.mapElemValue() - } - if j < len(v) { - v[uint(j)] = int(chkOvf.IntV(d.d.DecodeInt64(), intBitsize)) - } else { - d.arrayCannotExpand(len(v), j+1) - d.swallow() - } - } - if isArray { - d.arrayEnd() - } else { - d.mapEnd() - } -} - -func (d *decoderMsgpackBytes) fastpathDecSliceInt32R(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTMsgpackBytes - switch rv.Kind() { - case reflect.Ptr: - v := rv2i(rv).(*[]int32) - if vv, changed := ft.DecSliceInt32Y(*v, d); changed { - *v = vv - } - case reflect.Array: - var v []int32 - rvGetSlice4Array(rv, &v) - ft.DecSliceInt32N(v, d) - default: - ft.DecSliceInt32N(rv2i(rv).([]int32), d) - } -} -func (fastpathDTMsgpackBytes) DecSliceInt32Y(v []int32, d *decoderMsgpackBytes) (v2 []int32, changed bool) { - ctyp := d.d.ContainerType() - if ctyp == valueTypeNil { - return nil, v != nil - } - var containerLenS int - isArray := ctyp == valueTypeArray - if isArray { - containerLenS = d.arrayStart(d.d.ReadArrayStart()) - } else if ctyp == valueTypeMap { - containerLenS = d.mapStart(d.d.ReadMapStart()) * 2 - } else { - halt.errorStr2("decoding into a slice, expect map/array - got ", ctyp.String()) - } - hasLen := containerLenS >= 0 - var j int - fnv := func(dst []int32) { v, changed = dst, true } - for ; d.containerNext(j, containerLenS, hasLen); j++ { - if j == 0 { - if containerLenS == len(v) { - } else if containerLenS < 0 || containerLenS > cap(v) { - if xlen := int(decInferLen(containerLenS, d.maxInitLen(), 4)); xlen <= cap(v) { - fnv(v[:uint(xlen)]) - } else { - v2 = make([]int32, uint(xlen)) - copy(v2, v) - fnv(v2) - } - } else { - fnv(v[:containerLenS]) - } - } - if isArray { - d.arrayElem(j == 0) - } else if j&1 == 0 { - d.mapElemKey(j == 0) - } else { - d.mapElemValue() - } - if j >= len(v) { - fnv(append(v, 0)) - } - v[uint(j)] = int32(chkOvf.IntV(d.d.DecodeInt64(), 32)) - } - if j < len(v) { - fnv(v[:uint(j)]) - } else if j == 0 && v == nil { - fnv([]int32{}) - } - if isArray { - d.arrayEnd() - } else { - d.mapEnd() - } - return v, changed -} -func (fastpathDTMsgpackBytes) DecSliceInt32N(v []int32, d *decoderMsgpackBytes) { - ctyp := d.d.ContainerType() - if ctyp == valueTypeNil { - return - } - var containerLenS int - isArray := ctyp == valueTypeArray - if isArray { - containerLenS = d.arrayStart(d.d.ReadArrayStart()) - } else if ctyp == valueTypeMap { - containerLenS = d.mapStart(d.d.ReadMapStart()) * 2 - } else { - halt.errorStr2("decoding into a slice, expect map/array - got ", ctyp.String()) - } - hasLen := containerLenS >= 0 - for j := 0; d.containerNext(j, containerLenS, hasLen); j++ { - if isArray { - d.arrayElem(j == 0) - } else if j&1 == 0 { - d.mapElemKey(j == 0) - } else { - d.mapElemValue() - } - if j < len(v) { - v[uint(j)] = int32(chkOvf.IntV(d.d.DecodeInt64(), 32)) - } else { - d.arrayCannotExpand(len(v), j+1) - d.swallow() - } - } - if isArray { - d.arrayEnd() - } else { - d.mapEnd() - } -} - -func (d *decoderMsgpackBytes) fastpathDecSliceInt64R(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTMsgpackBytes - switch rv.Kind() { - case reflect.Ptr: - v := rv2i(rv).(*[]int64) - if vv, changed := ft.DecSliceInt64Y(*v, d); changed { - *v = vv - } - case reflect.Array: - var v []int64 - rvGetSlice4Array(rv, &v) - ft.DecSliceInt64N(v, d) - default: - ft.DecSliceInt64N(rv2i(rv).([]int64), d) - } -} -func (fastpathDTMsgpackBytes) DecSliceInt64Y(v []int64, d *decoderMsgpackBytes) (v2 []int64, changed bool) { - ctyp := d.d.ContainerType() - if ctyp == valueTypeNil { - return nil, v != nil - } - var containerLenS int - isArray := ctyp == valueTypeArray - if isArray { - containerLenS = d.arrayStart(d.d.ReadArrayStart()) - } else if ctyp == valueTypeMap { - containerLenS = d.mapStart(d.d.ReadMapStart()) * 2 - } else { - halt.errorStr2("decoding into a slice, expect map/array - got ", ctyp.String()) - } - hasLen := containerLenS >= 0 - var j int - fnv := func(dst []int64) { v, changed = dst, true } - for ; d.containerNext(j, containerLenS, hasLen); j++ { - if j == 0 { - if containerLenS == len(v) { - } else if containerLenS < 0 || containerLenS > cap(v) { - if xlen := int(decInferLen(containerLenS, d.maxInitLen(), 8)); xlen <= cap(v) { - fnv(v[:uint(xlen)]) - } else { - v2 = make([]int64, uint(xlen)) - copy(v2, v) - fnv(v2) - } - } else { - fnv(v[:containerLenS]) - } - } - if isArray { - d.arrayElem(j == 0) - } else if j&1 == 0 { - d.mapElemKey(j == 0) - } else { - d.mapElemValue() - } - if j >= len(v) { - fnv(append(v, 0)) - } - v[uint(j)] = d.d.DecodeInt64() - } - if j < len(v) { - fnv(v[:uint(j)]) - } else if j == 0 && v == nil { - fnv([]int64{}) - } - if isArray { - d.arrayEnd() - } else { - d.mapEnd() - } - return v, changed -} -func (fastpathDTMsgpackBytes) DecSliceInt64N(v []int64, d *decoderMsgpackBytes) { - ctyp := d.d.ContainerType() - if ctyp == valueTypeNil { - return - } - var containerLenS int - isArray := ctyp == valueTypeArray - if isArray { - containerLenS = d.arrayStart(d.d.ReadArrayStart()) - } else if ctyp == valueTypeMap { - containerLenS = d.mapStart(d.d.ReadMapStart()) * 2 - } else { - halt.errorStr2("decoding into a slice, expect map/array - got ", ctyp.String()) - } - hasLen := containerLenS >= 0 - for j := 0; d.containerNext(j, containerLenS, hasLen); j++ { - if isArray { - d.arrayElem(j == 0) - } else if j&1 == 0 { - d.mapElemKey(j == 0) - } else { - d.mapElemValue() - } - if j < len(v) { - v[uint(j)] = d.d.DecodeInt64() - } else { - d.arrayCannotExpand(len(v), j+1) - d.swallow() - } - } - if isArray { - d.arrayEnd() - } else { - d.mapEnd() - } -} - -func (d *decoderMsgpackBytes) fastpathDecSliceBoolR(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTMsgpackBytes - switch rv.Kind() { - case reflect.Ptr: - v := rv2i(rv).(*[]bool) - if vv, changed := ft.DecSliceBoolY(*v, d); changed { - *v = vv - } - case reflect.Array: - var v []bool - rvGetSlice4Array(rv, &v) - ft.DecSliceBoolN(v, d) - default: - ft.DecSliceBoolN(rv2i(rv).([]bool), d) - } -} -func (fastpathDTMsgpackBytes) DecSliceBoolY(v []bool, d *decoderMsgpackBytes) (v2 []bool, changed bool) { - ctyp := d.d.ContainerType() - if ctyp == valueTypeNil { - return nil, v != nil - } - var containerLenS int - isArray := ctyp == valueTypeArray - if isArray { - containerLenS = d.arrayStart(d.d.ReadArrayStart()) - } else if ctyp == valueTypeMap { - containerLenS = d.mapStart(d.d.ReadMapStart()) * 2 - } else { - halt.errorStr2("decoding into a slice, expect map/array - got ", ctyp.String()) - } - hasLen := containerLenS >= 0 - var j int - fnv := func(dst []bool) { v, changed = dst, true } - for ; d.containerNext(j, containerLenS, hasLen); j++ { - if j == 0 { - if containerLenS == len(v) { - } else if containerLenS < 0 || containerLenS > cap(v) { - if xlen := int(decInferLen(containerLenS, d.maxInitLen(), 1)); xlen <= cap(v) { - fnv(v[:uint(xlen)]) - } else { - v2 = make([]bool, uint(xlen)) - copy(v2, v) - fnv(v2) - } - } else { - fnv(v[:containerLenS]) - } - } - if isArray { - d.arrayElem(j == 0) - } else if j&1 == 0 { - d.mapElemKey(j == 0) - } else { - d.mapElemValue() - } - if j >= len(v) { - fnv(append(v, false)) - } - v[uint(j)] = d.d.DecodeBool() - } - if j < len(v) { - fnv(v[:uint(j)]) - } else if j == 0 && v == nil { - fnv([]bool{}) - } - if isArray { - d.arrayEnd() - } else { - d.mapEnd() - } - return v, changed -} -func (fastpathDTMsgpackBytes) DecSliceBoolN(v []bool, d *decoderMsgpackBytes) { - ctyp := d.d.ContainerType() - if ctyp == valueTypeNil { - return - } - var containerLenS int - isArray := ctyp == valueTypeArray - if isArray { - containerLenS = d.arrayStart(d.d.ReadArrayStart()) - } else if ctyp == valueTypeMap { - containerLenS = d.mapStart(d.d.ReadMapStart()) * 2 - } else { - halt.errorStr2("decoding into a slice, expect map/array - got ", ctyp.String()) - } - hasLen := containerLenS >= 0 - for j := 0; d.containerNext(j, containerLenS, hasLen); j++ { - if isArray { - d.arrayElem(j == 0) - } else if j&1 == 0 { - d.mapElemKey(j == 0) - } else { - d.mapElemValue() - } - if j < len(v) { - v[uint(j)] = d.d.DecodeBool() - } else { - d.arrayCannotExpand(len(v), j+1) - d.swallow() - } - } - if isArray { - d.arrayEnd() - } else { - d.mapEnd() - } -} -func (d *decoderMsgpackBytes) fastpathDecMapStringIntfR(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTMsgpackBytes - containerLen := d.mapStart(d.d.ReadMapStart()) - if rv.Kind() == reflect.Ptr { - vp, _ := rv2i(rv).(*map[string]interface{}) - if *vp == nil { - *vp = make(map[string]interface{}, decInferLen(containerLen, d.maxInitLen(), 32)) - } - if containerLen != 0 { - ft.DecMapStringIntfL(*vp, containerLen, d) - } - } else if containerLen != 0 { - ft.DecMapStringIntfL(rv2i(rv).(map[string]interface{}), containerLen, d) - } - d.mapEnd() -} -func (fastpathDTMsgpackBytes) DecMapStringIntfL(v map[string]interface{}, containerLen int, d *decoderMsgpackBytes) { - if v == nil { - halt.errorInt("cannot decode into nil map[string]interface{} given stream length: ", int64(containerLen)) - } - var mv interface{} - mapGet := !d.h.MapValueReset && !d.h.InterfaceReset - hasLen := containerLen >= 0 - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - mk := d.detach2Str(d.d.DecodeStringAsBytes()) - d.mapElemValue() - if mapGet { - mv = v[mk] - } else { - mv = nil - } - d.decode(&mv) - v[mk] = mv - } -} -func (d *decoderMsgpackBytes) fastpathDecMapStringStringR(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTMsgpackBytes - containerLen := d.mapStart(d.d.ReadMapStart()) - if rv.Kind() == reflect.Ptr { - vp, _ := rv2i(rv).(*map[string]string) - if *vp == nil { - *vp = make(map[string]string, decInferLen(containerLen, d.maxInitLen(), 32)) - } - if containerLen != 0 { - ft.DecMapStringStringL(*vp, containerLen, d) - } - } else if containerLen != 0 { - ft.DecMapStringStringL(rv2i(rv).(map[string]string), containerLen, d) - } - d.mapEnd() -} -func (fastpathDTMsgpackBytes) DecMapStringStringL(v map[string]string, containerLen int, d *decoderMsgpackBytes) { - if v == nil { - halt.errorInt("cannot decode into nil map[string]string given stream length: ", int64(containerLen)) - } - hasLen := containerLen >= 0 - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - mk := d.detach2Str(d.d.DecodeStringAsBytes()) - d.mapElemValue() - v[mk] = d.detach2Str(d.d.DecodeStringAsBytes()) - } -} -func (d *decoderMsgpackBytes) fastpathDecMapStringBytesR(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTMsgpackBytes - containerLen := d.mapStart(d.d.ReadMapStart()) - if rv.Kind() == reflect.Ptr { - vp, _ := rv2i(rv).(*map[string][]byte) - if *vp == nil { - *vp = make(map[string][]byte, decInferLen(containerLen, d.maxInitLen(), 40)) - } - if containerLen != 0 { - ft.DecMapStringBytesL(*vp, containerLen, d) - } - } else if containerLen != 0 { - ft.DecMapStringBytesL(rv2i(rv).(map[string][]byte), containerLen, d) - } - d.mapEnd() -} -func (fastpathDTMsgpackBytes) DecMapStringBytesL(v map[string][]byte, containerLen int, d *decoderMsgpackBytes) { - if v == nil { - halt.errorInt("cannot decode into nil map[string][]byte given stream length: ", int64(containerLen)) - } - var mv []byte - mapGet := !d.h.MapValueReset - hasLen := containerLen >= 0 - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - mk := d.detach2Str(d.d.DecodeStringAsBytes()) - d.mapElemValue() - if mapGet { - mv = v[mk] - } else { - mv = nil - } - v[mk], _ = d.decodeBytesInto(mv, false) - } -} -func (d *decoderMsgpackBytes) fastpathDecMapStringUint8R(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTMsgpackBytes - containerLen := d.mapStart(d.d.ReadMapStart()) - if rv.Kind() == reflect.Ptr { - vp, _ := rv2i(rv).(*map[string]uint8) - if *vp == nil { - *vp = make(map[string]uint8, decInferLen(containerLen, d.maxInitLen(), 17)) - } - if containerLen != 0 { - ft.DecMapStringUint8L(*vp, containerLen, d) - } - } else if containerLen != 0 { - ft.DecMapStringUint8L(rv2i(rv).(map[string]uint8), containerLen, d) - } - d.mapEnd() -} -func (fastpathDTMsgpackBytes) DecMapStringUint8L(v map[string]uint8, containerLen int, d *decoderMsgpackBytes) { - if v == nil { - halt.errorInt("cannot decode into nil map[string]uint8 given stream length: ", int64(containerLen)) - } - hasLen := containerLen >= 0 - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - mk := d.detach2Str(d.d.DecodeStringAsBytes()) - d.mapElemValue() - v[mk] = uint8(chkOvf.UintV(d.d.DecodeUint64(), 8)) - } -} -func (d *decoderMsgpackBytes) fastpathDecMapStringUint64R(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTMsgpackBytes - containerLen := d.mapStart(d.d.ReadMapStart()) - if rv.Kind() == reflect.Ptr { - vp, _ := rv2i(rv).(*map[string]uint64) - if *vp == nil { - *vp = make(map[string]uint64, decInferLen(containerLen, d.maxInitLen(), 24)) - } - if containerLen != 0 { - ft.DecMapStringUint64L(*vp, containerLen, d) - } - } else if containerLen != 0 { - ft.DecMapStringUint64L(rv2i(rv).(map[string]uint64), containerLen, d) - } - d.mapEnd() -} -func (fastpathDTMsgpackBytes) DecMapStringUint64L(v map[string]uint64, containerLen int, d *decoderMsgpackBytes) { - if v == nil { - halt.errorInt("cannot decode into nil map[string]uint64 given stream length: ", int64(containerLen)) - } - hasLen := containerLen >= 0 - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - mk := d.detach2Str(d.d.DecodeStringAsBytes()) - d.mapElemValue() - v[mk] = d.d.DecodeUint64() - } -} -func (d *decoderMsgpackBytes) fastpathDecMapStringIntR(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTMsgpackBytes - containerLen := d.mapStart(d.d.ReadMapStart()) - if rv.Kind() == reflect.Ptr { - vp, _ := rv2i(rv).(*map[string]int) - if *vp == nil { - *vp = make(map[string]int, decInferLen(containerLen, d.maxInitLen(), 24)) - } - if containerLen != 0 { - ft.DecMapStringIntL(*vp, containerLen, d) - } - } else if containerLen != 0 { - ft.DecMapStringIntL(rv2i(rv).(map[string]int), containerLen, d) - } - d.mapEnd() -} -func (fastpathDTMsgpackBytes) DecMapStringIntL(v map[string]int, containerLen int, d *decoderMsgpackBytes) { - if v == nil { - halt.errorInt("cannot decode into nil map[string]int given stream length: ", int64(containerLen)) - } - hasLen := containerLen >= 0 - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - mk := d.detach2Str(d.d.DecodeStringAsBytes()) - d.mapElemValue() - v[mk] = int(chkOvf.IntV(d.d.DecodeInt64(), intBitsize)) - } -} -func (d *decoderMsgpackBytes) fastpathDecMapStringInt32R(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTMsgpackBytes - containerLen := d.mapStart(d.d.ReadMapStart()) - if rv.Kind() == reflect.Ptr { - vp, _ := rv2i(rv).(*map[string]int32) - if *vp == nil { - *vp = make(map[string]int32, decInferLen(containerLen, d.maxInitLen(), 20)) - } - if containerLen != 0 { - ft.DecMapStringInt32L(*vp, containerLen, d) - } - } else if containerLen != 0 { - ft.DecMapStringInt32L(rv2i(rv).(map[string]int32), containerLen, d) - } - d.mapEnd() -} -func (fastpathDTMsgpackBytes) DecMapStringInt32L(v map[string]int32, containerLen int, d *decoderMsgpackBytes) { - if v == nil { - halt.errorInt("cannot decode into nil map[string]int32 given stream length: ", int64(containerLen)) - } - hasLen := containerLen >= 0 - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - mk := d.detach2Str(d.d.DecodeStringAsBytes()) - d.mapElemValue() - v[mk] = int32(chkOvf.IntV(d.d.DecodeInt64(), 32)) - } -} -func (d *decoderMsgpackBytes) fastpathDecMapStringFloat64R(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTMsgpackBytes - containerLen := d.mapStart(d.d.ReadMapStart()) - if rv.Kind() == reflect.Ptr { - vp, _ := rv2i(rv).(*map[string]float64) - if *vp == nil { - *vp = make(map[string]float64, decInferLen(containerLen, d.maxInitLen(), 24)) - } - if containerLen != 0 { - ft.DecMapStringFloat64L(*vp, containerLen, d) - } - } else if containerLen != 0 { - ft.DecMapStringFloat64L(rv2i(rv).(map[string]float64), containerLen, d) - } - d.mapEnd() -} -func (fastpathDTMsgpackBytes) DecMapStringFloat64L(v map[string]float64, containerLen int, d *decoderMsgpackBytes) { - if v == nil { - halt.errorInt("cannot decode into nil map[string]float64 given stream length: ", int64(containerLen)) - } - hasLen := containerLen >= 0 - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - mk := d.detach2Str(d.d.DecodeStringAsBytes()) - d.mapElemValue() - v[mk] = d.d.DecodeFloat64() - } -} -func (d *decoderMsgpackBytes) fastpathDecMapStringBoolR(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTMsgpackBytes - containerLen := d.mapStart(d.d.ReadMapStart()) - if rv.Kind() == reflect.Ptr { - vp, _ := rv2i(rv).(*map[string]bool) - if *vp == nil { - *vp = make(map[string]bool, decInferLen(containerLen, d.maxInitLen(), 17)) - } - if containerLen != 0 { - ft.DecMapStringBoolL(*vp, containerLen, d) - } - } else if containerLen != 0 { - ft.DecMapStringBoolL(rv2i(rv).(map[string]bool), containerLen, d) - } - d.mapEnd() -} -func (fastpathDTMsgpackBytes) DecMapStringBoolL(v map[string]bool, containerLen int, d *decoderMsgpackBytes) { - if v == nil { - halt.errorInt("cannot decode into nil map[string]bool given stream length: ", int64(containerLen)) - } - hasLen := containerLen >= 0 - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - mk := d.detach2Str(d.d.DecodeStringAsBytes()) - d.mapElemValue() - v[mk] = d.d.DecodeBool() - } -} -func (d *decoderMsgpackBytes) fastpathDecMapUint8IntfR(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTMsgpackBytes - containerLen := d.mapStart(d.d.ReadMapStart()) - if rv.Kind() == reflect.Ptr { - vp, _ := rv2i(rv).(*map[uint8]interface{}) - if *vp == nil { - *vp = make(map[uint8]interface{}, decInferLen(containerLen, d.maxInitLen(), 17)) - } - if containerLen != 0 { - ft.DecMapUint8IntfL(*vp, containerLen, d) - } - } else if containerLen != 0 { - ft.DecMapUint8IntfL(rv2i(rv).(map[uint8]interface{}), containerLen, d) - } - d.mapEnd() -} -func (fastpathDTMsgpackBytes) DecMapUint8IntfL(v map[uint8]interface{}, containerLen int, d *decoderMsgpackBytes) { - if v == nil { - halt.errorInt("cannot decode into nil map[uint8]interface{} given stream length: ", int64(containerLen)) - } - var mv interface{} - mapGet := !d.h.MapValueReset && !d.h.InterfaceReset - hasLen := containerLen >= 0 - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - mk := uint8(chkOvf.UintV(d.d.DecodeUint64(), 8)) - d.mapElemValue() - if mapGet { - mv = v[mk] - } else { - mv = nil - } - d.decode(&mv) - v[mk] = mv - } -} -func (d *decoderMsgpackBytes) fastpathDecMapUint8StringR(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTMsgpackBytes - containerLen := d.mapStart(d.d.ReadMapStart()) - if rv.Kind() == reflect.Ptr { - vp, _ := rv2i(rv).(*map[uint8]string) - if *vp == nil { - *vp = make(map[uint8]string, decInferLen(containerLen, d.maxInitLen(), 17)) - } - if containerLen != 0 { - ft.DecMapUint8StringL(*vp, containerLen, d) - } - } else if containerLen != 0 { - ft.DecMapUint8StringL(rv2i(rv).(map[uint8]string), containerLen, d) - } - d.mapEnd() -} -func (fastpathDTMsgpackBytes) DecMapUint8StringL(v map[uint8]string, containerLen int, d *decoderMsgpackBytes) { - if v == nil { - halt.errorInt("cannot decode into nil map[uint8]string given stream length: ", int64(containerLen)) - } - hasLen := containerLen >= 0 - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - mk := uint8(chkOvf.UintV(d.d.DecodeUint64(), 8)) - d.mapElemValue() - v[mk] = d.detach2Str(d.d.DecodeStringAsBytes()) - } -} -func (d *decoderMsgpackBytes) fastpathDecMapUint8BytesR(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTMsgpackBytes - containerLen := d.mapStart(d.d.ReadMapStart()) - if rv.Kind() == reflect.Ptr { - vp, _ := rv2i(rv).(*map[uint8][]byte) - if *vp == nil { - *vp = make(map[uint8][]byte, decInferLen(containerLen, d.maxInitLen(), 25)) - } - if containerLen != 0 { - ft.DecMapUint8BytesL(*vp, containerLen, d) - } - } else if containerLen != 0 { - ft.DecMapUint8BytesL(rv2i(rv).(map[uint8][]byte), containerLen, d) - } - d.mapEnd() -} -func (fastpathDTMsgpackBytes) DecMapUint8BytesL(v map[uint8][]byte, containerLen int, d *decoderMsgpackBytes) { - if v == nil { - halt.errorInt("cannot decode into nil map[uint8][]byte given stream length: ", int64(containerLen)) - } - var mv []byte - mapGet := !d.h.MapValueReset - hasLen := containerLen >= 0 - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - mk := uint8(chkOvf.UintV(d.d.DecodeUint64(), 8)) - d.mapElemValue() - if mapGet { - mv = v[mk] - } else { - mv = nil - } - v[mk], _ = d.decodeBytesInto(mv, false) - } -} -func (d *decoderMsgpackBytes) fastpathDecMapUint8Uint8R(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTMsgpackBytes - containerLen := d.mapStart(d.d.ReadMapStart()) - if rv.Kind() == reflect.Ptr { - vp, _ := rv2i(rv).(*map[uint8]uint8) - if *vp == nil { - *vp = make(map[uint8]uint8, decInferLen(containerLen, d.maxInitLen(), 2)) - } - if containerLen != 0 { - ft.DecMapUint8Uint8L(*vp, containerLen, d) - } - } else if containerLen != 0 { - ft.DecMapUint8Uint8L(rv2i(rv).(map[uint8]uint8), containerLen, d) - } - d.mapEnd() -} -func (fastpathDTMsgpackBytes) DecMapUint8Uint8L(v map[uint8]uint8, containerLen int, d *decoderMsgpackBytes) { - if v == nil { - halt.errorInt("cannot decode into nil map[uint8]uint8 given stream length: ", int64(containerLen)) - } - hasLen := containerLen >= 0 - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - mk := uint8(chkOvf.UintV(d.d.DecodeUint64(), 8)) - d.mapElemValue() - v[mk] = uint8(chkOvf.UintV(d.d.DecodeUint64(), 8)) - } -} -func (d *decoderMsgpackBytes) fastpathDecMapUint8Uint64R(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTMsgpackBytes - containerLen := d.mapStart(d.d.ReadMapStart()) - if rv.Kind() == reflect.Ptr { - vp, _ := rv2i(rv).(*map[uint8]uint64) - if *vp == nil { - *vp = make(map[uint8]uint64, decInferLen(containerLen, d.maxInitLen(), 9)) - } - if containerLen != 0 { - ft.DecMapUint8Uint64L(*vp, containerLen, d) - } - } else if containerLen != 0 { - ft.DecMapUint8Uint64L(rv2i(rv).(map[uint8]uint64), containerLen, d) - } - d.mapEnd() -} -func (fastpathDTMsgpackBytes) DecMapUint8Uint64L(v map[uint8]uint64, containerLen int, d *decoderMsgpackBytes) { - if v == nil { - halt.errorInt("cannot decode into nil map[uint8]uint64 given stream length: ", int64(containerLen)) - } - hasLen := containerLen >= 0 - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - mk := uint8(chkOvf.UintV(d.d.DecodeUint64(), 8)) - d.mapElemValue() - v[mk] = d.d.DecodeUint64() - } -} -func (d *decoderMsgpackBytes) fastpathDecMapUint8IntR(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTMsgpackBytes - containerLen := d.mapStart(d.d.ReadMapStart()) - if rv.Kind() == reflect.Ptr { - vp, _ := rv2i(rv).(*map[uint8]int) - if *vp == nil { - *vp = make(map[uint8]int, decInferLen(containerLen, d.maxInitLen(), 9)) - } - if containerLen != 0 { - ft.DecMapUint8IntL(*vp, containerLen, d) - } - } else if containerLen != 0 { - ft.DecMapUint8IntL(rv2i(rv).(map[uint8]int), containerLen, d) - } - d.mapEnd() -} -func (fastpathDTMsgpackBytes) DecMapUint8IntL(v map[uint8]int, containerLen int, d *decoderMsgpackBytes) { - if v == nil { - halt.errorInt("cannot decode into nil map[uint8]int given stream length: ", int64(containerLen)) - } - hasLen := containerLen >= 0 - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - mk := uint8(chkOvf.UintV(d.d.DecodeUint64(), 8)) - d.mapElemValue() - v[mk] = int(chkOvf.IntV(d.d.DecodeInt64(), intBitsize)) - } -} -func (d *decoderMsgpackBytes) fastpathDecMapUint8Int32R(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTMsgpackBytes - containerLen := d.mapStart(d.d.ReadMapStart()) - if rv.Kind() == reflect.Ptr { - vp, _ := rv2i(rv).(*map[uint8]int32) - if *vp == nil { - *vp = make(map[uint8]int32, decInferLen(containerLen, d.maxInitLen(), 5)) - } - if containerLen != 0 { - ft.DecMapUint8Int32L(*vp, containerLen, d) - } - } else if containerLen != 0 { - ft.DecMapUint8Int32L(rv2i(rv).(map[uint8]int32), containerLen, d) - } - d.mapEnd() -} -func (fastpathDTMsgpackBytes) DecMapUint8Int32L(v map[uint8]int32, containerLen int, d *decoderMsgpackBytes) { - if v == nil { - halt.errorInt("cannot decode into nil map[uint8]int32 given stream length: ", int64(containerLen)) - } - hasLen := containerLen >= 0 - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - mk := uint8(chkOvf.UintV(d.d.DecodeUint64(), 8)) - d.mapElemValue() - v[mk] = int32(chkOvf.IntV(d.d.DecodeInt64(), 32)) - } -} -func (d *decoderMsgpackBytes) fastpathDecMapUint8Float64R(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTMsgpackBytes - containerLen := d.mapStart(d.d.ReadMapStart()) - if rv.Kind() == reflect.Ptr { - vp, _ := rv2i(rv).(*map[uint8]float64) - if *vp == nil { - *vp = make(map[uint8]float64, decInferLen(containerLen, d.maxInitLen(), 9)) - } - if containerLen != 0 { - ft.DecMapUint8Float64L(*vp, containerLen, d) - } - } else if containerLen != 0 { - ft.DecMapUint8Float64L(rv2i(rv).(map[uint8]float64), containerLen, d) - } - d.mapEnd() -} -func (fastpathDTMsgpackBytes) DecMapUint8Float64L(v map[uint8]float64, containerLen int, d *decoderMsgpackBytes) { - if v == nil { - halt.errorInt("cannot decode into nil map[uint8]float64 given stream length: ", int64(containerLen)) - } - hasLen := containerLen >= 0 - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - mk := uint8(chkOvf.UintV(d.d.DecodeUint64(), 8)) - d.mapElemValue() - v[mk] = d.d.DecodeFloat64() - } -} -func (d *decoderMsgpackBytes) fastpathDecMapUint8BoolR(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTMsgpackBytes - containerLen := d.mapStart(d.d.ReadMapStart()) - if rv.Kind() == reflect.Ptr { - vp, _ := rv2i(rv).(*map[uint8]bool) - if *vp == nil { - *vp = make(map[uint8]bool, decInferLen(containerLen, d.maxInitLen(), 2)) - } - if containerLen != 0 { - ft.DecMapUint8BoolL(*vp, containerLen, d) - } - } else if containerLen != 0 { - ft.DecMapUint8BoolL(rv2i(rv).(map[uint8]bool), containerLen, d) - } - d.mapEnd() -} -func (fastpathDTMsgpackBytes) DecMapUint8BoolL(v map[uint8]bool, containerLen int, d *decoderMsgpackBytes) { - if v == nil { - halt.errorInt("cannot decode into nil map[uint8]bool given stream length: ", int64(containerLen)) - } - hasLen := containerLen >= 0 - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - mk := uint8(chkOvf.UintV(d.d.DecodeUint64(), 8)) - d.mapElemValue() - v[mk] = d.d.DecodeBool() - } -} -func (d *decoderMsgpackBytes) fastpathDecMapUint64IntfR(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTMsgpackBytes - containerLen := d.mapStart(d.d.ReadMapStart()) - if rv.Kind() == reflect.Ptr { - vp, _ := rv2i(rv).(*map[uint64]interface{}) - if *vp == nil { - *vp = make(map[uint64]interface{}, decInferLen(containerLen, d.maxInitLen(), 24)) - } - if containerLen != 0 { - ft.DecMapUint64IntfL(*vp, containerLen, d) - } - } else if containerLen != 0 { - ft.DecMapUint64IntfL(rv2i(rv).(map[uint64]interface{}), containerLen, d) - } - d.mapEnd() -} -func (fastpathDTMsgpackBytes) DecMapUint64IntfL(v map[uint64]interface{}, containerLen int, d *decoderMsgpackBytes) { - if v == nil { - halt.errorInt("cannot decode into nil map[uint64]interface{} given stream length: ", int64(containerLen)) - } - var mv interface{} - mapGet := !d.h.MapValueReset && !d.h.InterfaceReset - hasLen := containerLen >= 0 - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - mk := d.d.DecodeUint64() - d.mapElemValue() - if mapGet { - mv = v[mk] - } else { - mv = nil - } - d.decode(&mv) - v[mk] = mv - } -} -func (d *decoderMsgpackBytes) fastpathDecMapUint64StringR(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTMsgpackBytes - containerLen := d.mapStart(d.d.ReadMapStart()) - if rv.Kind() == reflect.Ptr { - vp, _ := rv2i(rv).(*map[uint64]string) - if *vp == nil { - *vp = make(map[uint64]string, decInferLen(containerLen, d.maxInitLen(), 24)) - } - if containerLen != 0 { - ft.DecMapUint64StringL(*vp, containerLen, d) - } - } else if containerLen != 0 { - ft.DecMapUint64StringL(rv2i(rv).(map[uint64]string), containerLen, d) - } - d.mapEnd() -} -func (fastpathDTMsgpackBytes) DecMapUint64StringL(v map[uint64]string, containerLen int, d *decoderMsgpackBytes) { - if v == nil { - halt.errorInt("cannot decode into nil map[uint64]string given stream length: ", int64(containerLen)) - } - hasLen := containerLen >= 0 - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - mk := d.d.DecodeUint64() - d.mapElemValue() - v[mk] = d.detach2Str(d.d.DecodeStringAsBytes()) - } -} -func (d *decoderMsgpackBytes) fastpathDecMapUint64BytesR(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTMsgpackBytes - containerLen := d.mapStart(d.d.ReadMapStart()) - if rv.Kind() == reflect.Ptr { - vp, _ := rv2i(rv).(*map[uint64][]byte) - if *vp == nil { - *vp = make(map[uint64][]byte, decInferLen(containerLen, d.maxInitLen(), 32)) - } - if containerLen != 0 { - ft.DecMapUint64BytesL(*vp, containerLen, d) - } - } else if containerLen != 0 { - ft.DecMapUint64BytesL(rv2i(rv).(map[uint64][]byte), containerLen, d) - } - d.mapEnd() -} -func (fastpathDTMsgpackBytes) DecMapUint64BytesL(v map[uint64][]byte, containerLen int, d *decoderMsgpackBytes) { - if v == nil { - halt.errorInt("cannot decode into nil map[uint64][]byte given stream length: ", int64(containerLen)) - } - var mv []byte - mapGet := !d.h.MapValueReset - hasLen := containerLen >= 0 - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - mk := d.d.DecodeUint64() - d.mapElemValue() - if mapGet { - mv = v[mk] - } else { - mv = nil - } - v[mk], _ = d.decodeBytesInto(mv, false) - } -} -func (d *decoderMsgpackBytes) fastpathDecMapUint64Uint8R(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTMsgpackBytes - containerLen := d.mapStart(d.d.ReadMapStart()) - if rv.Kind() == reflect.Ptr { - vp, _ := rv2i(rv).(*map[uint64]uint8) - if *vp == nil { - *vp = make(map[uint64]uint8, decInferLen(containerLen, d.maxInitLen(), 9)) - } - if containerLen != 0 { - ft.DecMapUint64Uint8L(*vp, containerLen, d) - } - } else if containerLen != 0 { - ft.DecMapUint64Uint8L(rv2i(rv).(map[uint64]uint8), containerLen, d) - } - d.mapEnd() -} -func (fastpathDTMsgpackBytes) DecMapUint64Uint8L(v map[uint64]uint8, containerLen int, d *decoderMsgpackBytes) { - if v == nil { - halt.errorInt("cannot decode into nil map[uint64]uint8 given stream length: ", int64(containerLen)) - } - hasLen := containerLen >= 0 - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - mk := d.d.DecodeUint64() - d.mapElemValue() - v[mk] = uint8(chkOvf.UintV(d.d.DecodeUint64(), 8)) - } -} -func (d *decoderMsgpackBytes) fastpathDecMapUint64Uint64R(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTMsgpackBytes - containerLen := d.mapStart(d.d.ReadMapStart()) - if rv.Kind() == reflect.Ptr { - vp, _ := rv2i(rv).(*map[uint64]uint64) - if *vp == nil { - *vp = make(map[uint64]uint64, decInferLen(containerLen, d.maxInitLen(), 16)) - } - if containerLen != 0 { - ft.DecMapUint64Uint64L(*vp, containerLen, d) - } - } else if containerLen != 0 { - ft.DecMapUint64Uint64L(rv2i(rv).(map[uint64]uint64), containerLen, d) - } - d.mapEnd() -} -func (fastpathDTMsgpackBytes) DecMapUint64Uint64L(v map[uint64]uint64, containerLen int, d *decoderMsgpackBytes) { - if v == nil { - halt.errorInt("cannot decode into nil map[uint64]uint64 given stream length: ", int64(containerLen)) - } - hasLen := containerLen >= 0 - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - mk := d.d.DecodeUint64() - d.mapElemValue() - v[mk] = d.d.DecodeUint64() - } -} -func (d *decoderMsgpackBytes) fastpathDecMapUint64IntR(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTMsgpackBytes - containerLen := d.mapStart(d.d.ReadMapStart()) - if rv.Kind() == reflect.Ptr { - vp, _ := rv2i(rv).(*map[uint64]int) - if *vp == nil { - *vp = make(map[uint64]int, decInferLen(containerLen, d.maxInitLen(), 16)) - } - if containerLen != 0 { - ft.DecMapUint64IntL(*vp, containerLen, d) - } - } else if containerLen != 0 { - ft.DecMapUint64IntL(rv2i(rv).(map[uint64]int), containerLen, d) - } - d.mapEnd() -} -func (fastpathDTMsgpackBytes) DecMapUint64IntL(v map[uint64]int, containerLen int, d *decoderMsgpackBytes) { - if v == nil { - halt.errorInt("cannot decode into nil map[uint64]int given stream length: ", int64(containerLen)) - } - hasLen := containerLen >= 0 - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - mk := d.d.DecodeUint64() - d.mapElemValue() - v[mk] = int(chkOvf.IntV(d.d.DecodeInt64(), intBitsize)) - } -} -func (d *decoderMsgpackBytes) fastpathDecMapUint64Int32R(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTMsgpackBytes - containerLen := d.mapStart(d.d.ReadMapStart()) - if rv.Kind() == reflect.Ptr { - vp, _ := rv2i(rv).(*map[uint64]int32) - if *vp == nil { - *vp = make(map[uint64]int32, decInferLen(containerLen, d.maxInitLen(), 12)) - } - if containerLen != 0 { - ft.DecMapUint64Int32L(*vp, containerLen, d) - } - } else if containerLen != 0 { - ft.DecMapUint64Int32L(rv2i(rv).(map[uint64]int32), containerLen, d) - } - d.mapEnd() -} -func (fastpathDTMsgpackBytes) DecMapUint64Int32L(v map[uint64]int32, containerLen int, d *decoderMsgpackBytes) { - if v == nil { - halt.errorInt("cannot decode into nil map[uint64]int32 given stream length: ", int64(containerLen)) - } - hasLen := containerLen >= 0 - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - mk := d.d.DecodeUint64() - d.mapElemValue() - v[mk] = int32(chkOvf.IntV(d.d.DecodeInt64(), 32)) - } -} -func (d *decoderMsgpackBytes) fastpathDecMapUint64Float64R(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTMsgpackBytes - containerLen := d.mapStart(d.d.ReadMapStart()) - if rv.Kind() == reflect.Ptr { - vp, _ := rv2i(rv).(*map[uint64]float64) - if *vp == nil { - *vp = make(map[uint64]float64, decInferLen(containerLen, d.maxInitLen(), 16)) - } - if containerLen != 0 { - ft.DecMapUint64Float64L(*vp, containerLen, d) - } - } else if containerLen != 0 { - ft.DecMapUint64Float64L(rv2i(rv).(map[uint64]float64), containerLen, d) - } - d.mapEnd() -} -func (fastpathDTMsgpackBytes) DecMapUint64Float64L(v map[uint64]float64, containerLen int, d *decoderMsgpackBytes) { - if v == nil { - halt.errorInt("cannot decode into nil map[uint64]float64 given stream length: ", int64(containerLen)) - } - hasLen := containerLen >= 0 - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - mk := d.d.DecodeUint64() - d.mapElemValue() - v[mk] = d.d.DecodeFloat64() - } -} -func (d *decoderMsgpackBytes) fastpathDecMapUint64BoolR(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTMsgpackBytes - containerLen := d.mapStart(d.d.ReadMapStart()) - if rv.Kind() == reflect.Ptr { - vp, _ := rv2i(rv).(*map[uint64]bool) - if *vp == nil { - *vp = make(map[uint64]bool, decInferLen(containerLen, d.maxInitLen(), 9)) - } - if containerLen != 0 { - ft.DecMapUint64BoolL(*vp, containerLen, d) - } - } else if containerLen != 0 { - ft.DecMapUint64BoolL(rv2i(rv).(map[uint64]bool), containerLen, d) - } - d.mapEnd() -} -func (fastpathDTMsgpackBytes) DecMapUint64BoolL(v map[uint64]bool, containerLen int, d *decoderMsgpackBytes) { - if v == nil { - halt.errorInt("cannot decode into nil map[uint64]bool given stream length: ", int64(containerLen)) - } - hasLen := containerLen >= 0 - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - mk := d.d.DecodeUint64() - d.mapElemValue() - v[mk] = d.d.DecodeBool() - } -} -func (d *decoderMsgpackBytes) fastpathDecMapIntIntfR(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTMsgpackBytes - containerLen := d.mapStart(d.d.ReadMapStart()) - if rv.Kind() == reflect.Ptr { - vp, _ := rv2i(rv).(*map[int]interface{}) - if *vp == nil { - *vp = make(map[int]interface{}, decInferLen(containerLen, d.maxInitLen(), 24)) - } - if containerLen != 0 { - ft.DecMapIntIntfL(*vp, containerLen, d) - } - } else if containerLen != 0 { - ft.DecMapIntIntfL(rv2i(rv).(map[int]interface{}), containerLen, d) - } - d.mapEnd() -} -func (fastpathDTMsgpackBytes) DecMapIntIntfL(v map[int]interface{}, containerLen int, d *decoderMsgpackBytes) { - if v == nil { - halt.errorInt("cannot decode into nil map[int]interface{} given stream length: ", int64(containerLen)) - } - var mv interface{} - mapGet := !d.h.MapValueReset && !d.h.InterfaceReset - hasLen := containerLen >= 0 - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - mk := int(chkOvf.IntV(d.d.DecodeInt64(), intBitsize)) - d.mapElemValue() - if mapGet { - mv = v[mk] - } else { - mv = nil - } - d.decode(&mv) - v[mk] = mv - } -} -func (d *decoderMsgpackBytes) fastpathDecMapIntStringR(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTMsgpackBytes - containerLen := d.mapStart(d.d.ReadMapStart()) - if rv.Kind() == reflect.Ptr { - vp, _ := rv2i(rv).(*map[int]string) - if *vp == nil { - *vp = make(map[int]string, decInferLen(containerLen, d.maxInitLen(), 24)) - } - if containerLen != 0 { - ft.DecMapIntStringL(*vp, containerLen, d) - } - } else if containerLen != 0 { - ft.DecMapIntStringL(rv2i(rv).(map[int]string), containerLen, d) - } - d.mapEnd() -} -func (fastpathDTMsgpackBytes) DecMapIntStringL(v map[int]string, containerLen int, d *decoderMsgpackBytes) { - if v == nil { - halt.errorInt("cannot decode into nil map[int]string given stream length: ", int64(containerLen)) - } - hasLen := containerLen >= 0 - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - mk := int(chkOvf.IntV(d.d.DecodeInt64(), intBitsize)) - d.mapElemValue() - v[mk] = d.detach2Str(d.d.DecodeStringAsBytes()) - } -} -func (d *decoderMsgpackBytes) fastpathDecMapIntBytesR(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTMsgpackBytes - containerLen := d.mapStart(d.d.ReadMapStart()) - if rv.Kind() == reflect.Ptr { - vp, _ := rv2i(rv).(*map[int][]byte) - if *vp == nil { - *vp = make(map[int][]byte, decInferLen(containerLen, d.maxInitLen(), 32)) - } - if containerLen != 0 { - ft.DecMapIntBytesL(*vp, containerLen, d) - } - } else if containerLen != 0 { - ft.DecMapIntBytesL(rv2i(rv).(map[int][]byte), containerLen, d) - } - d.mapEnd() -} -func (fastpathDTMsgpackBytes) DecMapIntBytesL(v map[int][]byte, containerLen int, d *decoderMsgpackBytes) { - if v == nil { - halt.errorInt("cannot decode into nil map[int][]byte given stream length: ", int64(containerLen)) - } - var mv []byte - mapGet := !d.h.MapValueReset - hasLen := containerLen >= 0 - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - mk := int(chkOvf.IntV(d.d.DecodeInt64(), intBitsize)) - d.mapElemValue() - if mapGet { - mv = v[mk] - } else { - mv = nil - } - v[mk], _ = d.decodeBytesInto(mv, false) - } -} -func (d *decoderMsgpackBytes) fastpathDecMapIntUint8R(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTMsgpackBytes - containerLen := d.mapStart(d.d.ReadMapStart()) - if rv.Kind() == reflect.Ptr { - vp, _ := rv2i(rv).(*map[int]uint8) - if *vp == nil { - *vp = make(map[int]uint8, decInferLen(containerLen, d.maxInitLen(), 9)) - } - if containerLen != 0 { - ft.DecMapIntUint8L(*vp, containerLen, d) - } - } else if containerLen != 0 { - ft.DecMapIntUint8L(rv2i(rv).(map[int]uint8), containerLen, d) - } - d.mapEnd() -} -func (fastpathDTMsgpackBytes) DecMapIntUint8L(v map[int]uint8, containerLen int, d *decoderMsgpackBytes) { - if v == nil { - halt.errorInt("cannot decode into nil map[int]uint8 given stream length: ", int64(containerLen)) - } - hasLen := containerLen >= 0 - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - mk := int(chkOvf.IntV(d.d.DecodeInt64(), intBitsize)) - d.mapElemValue() - v[mk] = uint8(chkOvf.UintV(d.d.DecodeUint64(), 8)) - } -} -func (d *decoderMsgpackBytes) fastpathDecMapIntUint64R(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTMsgpackBytes - containerLen := d.mapStart(d.d.ReadMapStart()) - if rv.Kind() == reflect.Ptr { - vp, _ := rv2i(rv).(*map[int]uint64) - if *vp == nil { - *vp = make(map[int]uint64, decInferLen(containerLen, d.maxInitLen(), 16)) - } - if containerLen != 0 { - ft.DecMapIntUint64L(*vp, containerLen, d) - } - } else if containerLen != 0 { - ft.DecMapIntUint64L(rv2i(rv).(map[int]uint64), containerLen, d) - } - d.mapEnd() -} -func (fastpathDTMsgpackBytes) DecMapIntUint64L(v map[int]uint64, containerLen int, d *decoderMsgpackBytes) { - if v == nil { - halt.errorInt("cannot decode into nil map[int]uint64 given stream length: ", int64(containerLen)) - } - hasLen := containerLen >= 0 - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - mk := int(chkOvf.IntV(d.d.DecodeInt64(), intBitsize)) - d.mapElemValue() - v[mk] = d.d.DecodeUint64() - } -} -func (d *decoderMsgpackBytes) fastpathDecMapIntIntR(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTMsgpackBytes - containerLen := d.mapStart(d.d.ReadMapStart()) - if rv.Kind() == reflect.Ptr { - vp, _ := rv2i(rv).(*map[int]int) - if *vp == nil { - *vp = make(map[int]int, decInferLen(containerLen, d.maxInitLen(), 16)) - } - if containerLen != 0 { - ft.DecMapIntIntL(*vp, containerLen, d) - } - } else if containerLen != 0 { - ft.DecMapIntIntL(rv2i(rv).(map[int]int), containerLen, d) - } - d.mapEnd() -} -func (fastpathDTMsgpackBytes) DecMapIntIntL(v map[int]int, containerLen int, d *decoderMsgpackBytes) { - if v == nil { - halt.errorInt("cannot decode into nil map[int]int given stream length: ", int64(containerLen)) - } - hasLen := containerLen >= 0 - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - mk := int(chkOvf.IntV(d.d.DecodeInt64(), intBitsize)) - d.mapElemValue() - v[mk] = int(chkOvf.IntV(d.d.DecodeInt64(), intBitsize)) - } -} -func (d *decoderMsgpackBytes) fastpathDecMapIntInt32R(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTMsgpackBytes - containerLen := d.mapStart(d.d.ReadMapStart()) - if rv.Kind() == reflect.Ptr { - vp, _ := rv2i(rv).(*map[int]int32) - if *vp == nil { - *vp = make(map[int]int32, decInferLen(containerLen, d.maxInitLen(), 12)) - } - if containerLen != 0 { - ft.DecMapIntInt32L(*vp, containerLen, d) - } - } else if containerLen != 0 { - ft.DecMapIntInt32L(rv2i(rv).(map[int]int32), containerLen, d) - } - d.mapEnd() -} -func (fastpathDTMsgpackBytes) DecMapIntInt32L(v map[int]int32, containerLen int, d *decoderMsgpackBytes) { - if v == nil { - halt.errorInt("cannot decode into nil map[int]int32 given stream length: ", int64(containerLen)) - } - hasLen := containerLen >= 0 - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - mk := int(chkOvf.IntV(d.d.DecodeInt64(), intBitsize)) - d.mapElemValue() - v[mk] = int32(chkOvf.IntV(d.d.DecodeInt64(), 32)) - } -} -func (d *decoderMsgpackBytes) fastpathDecMapIntFloat64R(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTMsgpackBytes - containerLen := d.mapStart(d.d.ReadMapStart()) - if rv.Kind() == reflect.Ptr { - vp, _ := rv2i(rv).(*map[int]float64) - if *vp == nil { - *vp = make(map[int]float64, decInferLen(containerLen, d.maxInitLen(), 16)) - } - if containerLen != 0 { - ft.DecMapIntFloat64L(*vp, containerLen, d) - } - } else if containerLen != 0 { - ft.DecMapIntFloat64L(rv2i(rv).(map[int]float64), containerLen, d) - } - d.mapEnd() -} -func (fastpathDTMsgpackBytes) DecMapIntFloat64L(v map[int]float64, containerLen int, d *decoderMsgpackBytes) { - if v == nil { - halt.errorInt("cannot decode into nil map[int]float64 given stream length: ", int64(containerLen)) - } - hasLen := containerLen >= 0 - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - mk := int(chkOvf.IntV(d.d.DecodeInt64(), intBitsize)) - d.mapElemValue() - v[mk] = d.d.DecodeFloat64() - } -} -func (d *decoderMsgpackBytes) fastpathDecMapIntBoolR(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTMsgpackBytes - containerLen := d.mapStart(d.d.ReadMapStart()) - if rv.Kind() == reflect.Ptr { - vp, _ := rv2i(rv).(*map[int]bool) - if *vp == nil { - *vp = make(map[int]bool, decInferLen(containerLen, d.maxInitLen(), 9)) - } - if containerLen != 0 { - ft.DecMapIntBoolL(*vp, containerLen, d) - } - } else if containerLen != 0 { - ft.DecMapIntBoolL(rv2i(rv).(map[int]bool), containerLen, d) - } - d.mapEnd() -} -func (fastpathDTMsgpackBytes) DecMapIntBoolL(v map[int]bool, containerLen int, d *decoderMsgpackBytes) { - if v == nil { - halt.errorInt("cannot decode into nil map[int]bool given stream length: ", int64(containerLen)) - } - hasLen := containerLen >= 0 - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - mk := int(chkOvf.IntV(d.d.DecodeInt64(), intBitsize)) - d.mapElemValue() - v[mk] = d.d.DecodeBool() - } -} -func (d *decoderMsgpackBytes) fastpathDecMapInt32IntfR(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTMsgpackBytes - containerLen := d.mapStart(d.d.ReadMapStart()) - if rv.Kind() == reflect.Ptr { - vp, _ := rv2i(rv).(*map[int32]interface{}) - if *vp == nil { - *vp = make(map[int32]interface{}, decInferLen(containerLen, d.maxInitLen(), 20)) - } - if containerLen != 0 { - ft.DecMapInt32IntfL(*vp, containerLen, d) - } - } else if containerLen != 0 { - ft.DecMapInt32IntfL(rv2i(rv).(map[int32]interface{}), containerLen, d) - } - d.mapEnd() -} -func (fastpathDTMsgpackBytes) DecMapInt32IntfL(v map[int32]interface{}, containerLen int, d *decoderMsgpackBytes) { - if v == nil { - halt.errorInt("cannot decode into nil map[int32]interface{} given stream length: ", int64(containerLen)) - } - var mv interface{} - mapGet := !d.h.MapValueReset && !d.h.InterfaceReset - hasLen := containerLen >= 0 - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - mk := int32(chkOvf.IntV(d.d.DecodeInt64(), 32)) - d.mapElemValue() - if mapGet { - mv = v[mk] - } else { - mv = nil - } - d.decode(&mv) - v[mk] = mv - } -} -func (d *decoderMsgpackBytes) fastpathDecMapInt32StringR(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTMsgpackBytes - containerLen := d.mapStart(d.d.ReadMapStart()) - if rv.Kind() == reflect.Ptr { - vp, _ := rv2i(rv).(*map[int32]string) - if *vp == nil { - *vp = make(map[int32]string, decInferLen(containerLen, d.maxInitLen(), 20)) - } - if containerLen != 0 { - ft.DecMapInt32StringL(*vp, containerLen, d) - } - } else if containerLen != 0 { - ft.DecMapInt32StringL(rv2i(rv).(map[int32]string), containerLen, d) - } - d.mapEnd() -} -func (fastpathDTMsgpackBytes) DecMapInt32StringL(v map[int32]string, containerLen int, d *decoderMsgpackBytes) { - if v == nil { - halt.errorInt("cannot decode into nil map[int32]string given stream length: ", int64(containerLen)) - } - hasLen := containerLen >= 0 - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - mk := int32(chkOvf.IntV(d.d.DecodeInt64(), 32)) - d.mapElemValue() - v[mk] = d.detach2Str(d.d.DecodeStringAsBytes()) - } -} -func (d *decoderMsgpackBytes) fastpathDecMapInt32BytesR(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTMsgpackBytes - containerLen := d.mapStart(d.d.ReadMapStart()) - if rv.Kind() == reflect.Ptr { - vp, _ := rv2i(rv).(*map[int32][]byte) - if *vp == nil { - *vp = make(map[int32][]byte, decInferLen(containerLen, d.maxInitLen(), 28)) - } - if containerLen != 0 { - ft.DecMapInt32BytesL(*vp, containerLen, d) - } - } else if containerLen != 0 { - ft.DecMapInt32BytesL(rv2i(rv).(map[int32][]byte), containerLen, d) - } - d.mapEnd() -} -func (fastpathDTMsgpackBytes) DecMapInt32BytesL(v map[int32][]byte, containerLen int, d *decoderMsgpackBytes) { - if v == nil { - halt.errorInt("cannot decode into nil map[int32][]byte given stream length: ", int64(containerLen)) - } - var mv []byte - mapGet := !d.h.MapValueReset - hasLen := containerLen >= 0 - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - mk := int32(chkOvf.IntV(d.d.DecodeInt64(), 32)) - d.mapElemValue() - if mapGet { - mv = v[mk] - } else { - mv = nil - } - v[mk], _ = d.decodeBytesInto(mv, false) - } -} -func (d *decoderMsgpackBytes) fastpathDecMapInt32Uint8R(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTMsgpackBytes - containerLen := d.mapStart(d.d.ReadMapStart()) - if rv.Kind() == reflect.Ptr { - vp, _ := rv2i(rv).(*map[int32]uint8) - if *vp == nil { - *vp = make(map[int32]uint8, decInferLen(containerLen, d.maxInitLen(), 5)) - } - if containerLen != 0 { - ft.DecMapInt32Uint8L(*vp, containerLen, d) - } - } else if containerLen != 0 { - ft.DecMapInt32Uint8L(rv2i(rv).(map[int32]uint8), containerLen, d) - } - d.mapEnd() -} -func (fastpathDTMsgpackBytes) DecMapInt32Uint8L(v map[int32]uint8, containerLen int, d *decoderMsgpackBytes) { - if v == nil { - halt.errorInt("cannot decode into nil map[int32]uint8 given stream length: ", int64(containerLen)) - } - hasLen := containerLen >= 0 - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - mk := int32(chkOvf.IntV(d.d.DecodeInt64(), 32)) - d.mapElemValue() - v[mk] = uint8(chkOvf.UintV(d.d.DecodeUint64(), 8)) - } -} -func (d *decoderMsgpackBytes) fastpathDecMapInt32Uint64R(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTMsgpackBytes - containerLen := d.mapStart(d.d.ReadMapStart()) - if rv.Kind() == reflect.Ptr { - vp, _ := rv2i(rv).(*map[int32]uint64) - if *vp == nil { - *vp = make(map[int32]uint64, decInferLen(containerLen, d.maxInitLen(), 12)) - } - if containerLen != 0 { - ft.DecMapInt32Uint64L(*vp, containerLen, d) - } - } else if containerLen != 0 { - ft.DecMapInt32Uint64L(rv2i(rv).(map[int32]uint64), containerLen, d) - } - d.mapEnd() -} -func (fastpathDTMsgpackBytes) DecMapInt32Uint64L(v map[int32]uint64, containerLen int, d *decoderMsgpackBytes) { - if v == nil { - halt.errorInt("cannot decode into nil map[int32]uint64 given stream length: ", int64(containerLen)) - } - hasLen := containerLen >= 0 - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - mk := int32(chkOvf.IntV(d.d.DecodeInt64(), 32)) - d.mapElemValue() - v[mk] = d.d.DecodeUint64() - } -} -func (d *decoderMsgpackBytes) fastpathDecMapInt32IntR(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTMsgpackBytes - containerLen := d.mapStart(d.d.ReadMapStart()) - if rv.Kind() == reflect.Ptr { - vp, _ := rv2i(rv).(*map[int32]int) - if *vp == nil { - *vp = make(map[int32]int, decInferLen(containerLen, d.maxInitLen(), 12)) - } - if containerLen != 0 { - ft.DecMapInt32IntL(*vp, containerLen, d) - } - } else if containerLen != 0 { - ft.DecMapInt32IntL(rv2i(rv).(map[int32]int), containerLen, d) - } - d.mapEnd() -} -func (fastpathDTMsgpackBytes) DecMapInt32IntL(v map[int32]int, containerLen int, d *decoderMsgpackBytes) { - if v == nil { - halt.errorInt("cannot decode into nil map[int32]int given stream length: ", int64(containerLen)) - } - hasLen := containerLen >= 0 - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - mk := int32(chkOvf.IntV(d.d.DecodeInt64(), 32)) - d.mapElemValue() - v[mk] = int(chkOvf.IntV(d.d.DecodeInt64(), intBitsize)) - } -} -func (d *decoderMsgpackBytes) fastpathDecMapInt32Int32R(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTMsgpackBytes - containerLen := d.mapStart(d.d.ReadMapStart()) - if rv.Kind() == reflect.Ptr { - vp, _ := rv2i(rv).(*map[int32]int32) - if *vp == nil { - *vp = make(map[int32]int32, decInferLen(containerLen, d.maxInitLen(), 8)) - } - if containerLen != 0 { - ft.DecMapInt32Int32L(*vp, containerLen, d) - } - } else if containerLen != 0 { - ft.DecMapInt32Int32L(rv2i(rv).(map[int32]int32), containerLen, d) - } - d.mapEnd() -} -func (fastpathDTMsgpackBytes) DecMapInt32Int32L(v map[int32]int32, containerLen int, d *decoderMsgpackBytes) { - if v == nil { - halt.errorInt("cannot decode into nil map[int32]int32 given stream length: ", int64(containerLen)) - } - hasLen := containerLen >= 0 - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - mk := int32(chkOvf.IntV(d.d.DecodeInt64(), 32)) - d.mapElemValue() - v[mk] = int32(chkOvf.IntV(d.d.DecodeInt64(), 32)) - } -} -func (d *decoderMsgpackBytes) fastpathDecMapInt32Float64R(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTMsgpackBytes - containerLen := d.mapStart(d.d.ReadMapStart()) - if rv.Kind() == reflect.Ptr { - vp, _ := rv2i(rv).(*map[int32]float64) - if *vp == nil { - *vp = make(map[int32]float64, decInferLen(containerLen, d.maxInitLen(), 12)) - } - if containerLen != 0 { - ft.DecMapInt32Float64L(*vp, containerLen, d) - } - } else if containerLen != 0 { - ft.DecMapInt32Float64L(rv2i(rv).(map[int32]float64), containerLen, d) - } - d.mapEnd() -} -func (fastpathDTMsgpackBytes) DecMapInt32Float64L(v map[int32]float64, containerLen int, d *decoderMsgpackBytes) { - if v == nil { - halt.errorInt("cannot decode into nil map[int32]float64 given stream length: ", int64(containerLen)) - } - hasLen := containerLen >= 0 - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - mk := int32(chkOvf.IntV(d.d.DecodeInt64(), 32)) - d.mapElemValue() - v[mk] = d.d.DecodeFloat64() - } -} -func (d *decoderMsgpackBytes) fastpathDecMapInt32BoolR(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTMsgpackBytes - containerLen := d.mapStart(d.d.ReadMapStart()) - if rv.Kind() == reflect.Ptr { - vp, _ := rv2i(rv).(*map[int32]bool) - if *vp == nil { - *vp = make(map[int32]bool, decInferLen(containerLen, d.maxInitLen(), 5)) - } - if containerLen != 0 { - ft.DecMapInt32BoolL(*vp, containerLen, d) - } - } else if containerLen != 0 { - ft.DecMapInt32BoolL(rv2i(rv).(map[int32]bool), containerLen, d) - } - d.mapEnd() -} -func (fastpathDTMsgpackBytes) DecMapInt32BoolL(v map[int32]bool, containerLen int, d *decoderMsgpackBytes) { - if v == nil { - halt.errorInt("cannot decode into nil map[int32]bool given stream length: ", int64(containerLen)) - } - hasLen := containerLen >= 0 - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - mk := int32(chkOvf.IntV(d.d.DecodeInt64(), 32)) - d.mapElemValue() - v[mk] = d.d.DecodeBool() - } -} - -type fastpathEMsgpackIO struct { - rtid uintptr - rt reflect.Type - encfn func(*encoderMsgpackIO, *encFnInfo, reflect.Value) -} -type fastpathDMsgpackIO struct { - rtid uintptr - rt reflect.Type - decfn func(*decoderMsgpackIO, *decFnInfo, reflect.Value) -} -type fastpathEsMsgpackIO [56]fastpathEMsgpackIO -type fastpathDsMsgpackIO [56]fastpathDMsgpackIO -type fastpathETMsgpackIO struct{} -type fastpathDTMsgpackIO struct{} - -func (helperEncDriverMsgpackIO) fastpathEList() *fastpathEsMsgpackIO { - var i uint = 0 - var s fastpathEsMsgpackIO - fn := func(v interface{}, fe func(*encoderMsgpackIO, *encFnInfo, reflect.Value)) { - xrt := reflect.TypeOf(v) - s[i] = fastpathEMsgpackIO{rt2id(xrt), xrt, fe} - i++ - } - - fn([]interface{}(nil), (*encoderMsgpackIO).fastpathEncSliceIntfR) - fn([]string(nil), (*encoderMsgpackIO).fastpathEncSliceStringR) - fn([][]byte(nil), (*encoderMsgpackIO).fastpathEncSliceBytesR) - fn([]float32(nil), (*encoderMsgpackIO).fastpathEncSliceFloat32R) - fn([]float64(nil), (*encoderMsgpackIO).fastpathEncSliceFloat64R) - fn([]uint8(nil), (*encoderMsgpackIO).fastpathEncSliceUint8R) - fn([]uint64(nil), (*encoderMsgpackIO).fastpathEncSliceUint64R) - fn([]int(nil), (*encoderMsgpackIO).fastpathEncSliceIntR) - fn([]int32(nil), (*encoderMsgpackIO).fastpathEncSliceInt32R) - fn([]int64(nil), (*encoderMsgpackIO).fastpathEncSliceInt64R) - fn([]bool(nil), (*encoderMsgpackIO).fastpathEncSliceBoolR) - - fn(map[string]interface{}(nil), (*encoderMsgpackIO).fastpathEncMapStringIntfR) - fn(map[string]string(nil), (*encoderMsgpackIO).fastpathEncMapStringStringR) - fn(map[string][]byte(nil), (*encoderMsgpackIO).fastpathEncMapStringBytesR) - fn(map[string]uint8(nil), (*encoderMsgpackIO).fastpathEncMapStringUint8R) - fn(map[string]uint64(nil), (*encoderMsgpackIO).fastpathEncMapStringUint64R) - fn(map[string]int(nil), (*encoderMsgpackIO).fastpathEncMapStringIntR) - fn(map[string]int32(nil), (*encoderMsgpackIO).fastpathEncMapStringInt32R) - fn(map[string]float64(nil), (*encoderMsgpackIO).fastpathEncMapStringFloat64R) - fn(map[string]bool(nil), (*encoderMsgpackIO).fastpathEncMapStringBoolR) - fn(map[uint8]interface{}(nil), (*encoderMsgpackIO).fastpathEncMapUint8IntfR) - fn(map[uint8]string(nil), (*encoderMsgpackIO).fastpathEncMapUint8StringR) - fn(map[uint8][]byte(nil), (*encoderMsgpackIO).fastpathEncMapUint8BytesR) - fn(map[uint8]uint8(nil), (*encoderMsgpackIO).fastpathEncMapUint8Uint8R) - fn(map[uint8]uint64(nil), (*encoderMsgpackIO).fastpathEncMapUint8Uint64R) - fn(map[uint8]int(nil), (*encoderMsgpackIO).fastpathEncMapUint8IntR) - fn(map[uint8]int32(nil), (*encoderMsgpackIO).fastpathEncMapUint8Int32R) - fn(map[uint8]float64(nil), (*encoderMsgpackIO).fastpathEncMapUint8Float64R) - fn(map[uint8]bool(nil), (*encoderMsgpackIO).fastpathEncMapUint8BoolR) - fn(map[uint64]interface{}(nil), (*encoderMsgpackIO).fastpathEncMapUint64IntfR) - fn(map[uint64]string(nil), (*encoderMsgpackIO).fastpathEncMapUint64StringR) - fn(map[uint64][]byte(nil), (*encoderMsgpackIO).fastpathEncMapUint64BytesR) - fn(map[uint64]uint8(nil), (*encoderMsgpackIO).fastpathEncMapUint64Uint8R) - fn(map[uint64]uint64(nil), (*encoderMsgpackIO).fastpathEncMapUint64Uint64R) - fn(map[uint64]int(nil), (*encoderMsgpackIO).fastpathEncMapUint64IntR) - fn(map[uint64]int32(nil), (*encoderMsgpackIO).fastpathEncMapUint64Int32R) - fn(map[uint64]float64(nil), (*encoderMsgpackIO).fastpathEncMapUint64Float64R) - fn(map[uint64]bool(nil), (*encoderMsgpackIO).fastpathEncMapUint64BoolR) - fn(map[int]interface{}(nil), (*encoderMsgpackIO).fastpathEncMapIntIntfR) - fn(map[int]string(nil), (*encoderMsgpackIO).fastpathEncMapIntStringR) - fn(map[int][]byte(nil), (*encoderMsgpackIO).fastpathEncMapIntBytesR) - fn(map[int]uint8(nil), (*encoderMsgpackIO).fastpathEncMapIntUint8R) - fn(map[int]uint64(nil), (*encoderMsgpackIO).fastpathEncMapIntUint64R) - fn(map[int]int(nil), (*encoderMsgpackIO).fastpathEncMapIntIntR) - fn(map[int]int32(nil), (*encoderMsgpackIO).fastpathEncMapIntInt32R) - fn(map[int]float64(nil), (*encoderMsgpackIO).fastpathEncMapIntFloat64R) - fn(map[int]bool(nil), (*encoderMsgpackIO).fastpathEncMapIntBoolR) - fn(map[int32]interface{}(nil), (*encoderMsgpackIO).fastpathEncMapInt32IntfR) - fn(map[int32]string(nil), (*encoderMsgpackIO).fastpathEncMapInt32StringR) - fn(map[int32][]byte(nil), (*encoderMsgpackIO).fastpathEncMapInt32BytesR) - fn(map[int32]uint8(nil), (*encoderMsgpackIO).fastpathEncMapInt32Uint8R) - fn(map[int32]uint64(nil), (*encoderMsgpackIO).fastpathEncMapInt32Uint64R) - fn(map[int32]int(nil), (*encoderMsgpackIO).fastpathEncMapInt32IntR) - fn(map[int32]int32(nil), (*encoderMsgpackIO).fastpathEncMapInt32Int32R) - fn(map[int32]float64(nil), (*encoderMsgpackIO).fastpathEncMapInt32Float64R) - fn(map[int32]bool(nil), (*encoderMsgpackIO).fastpathEncMapInt32BoolR) - - sort.Slice(s[:], func(i, j int) bool { return s[i].rtid < s[j].rtid }) - return &s -} - -func (helperDecDriverMsgpackIO) fastpathDList() *fastpathDsMsgpackIO { - var i uint = 0 - var s fastpathDsMsgpackIO - fn := func(v interface{}, fd func(*decoderMsgpackIO, *decFnInfo, reflect.Value)) { - xrt := reflect.TypeOf(v) - s[i] = fastpathDMsgpackIO{rt2id(xrt), xrt, fd} - i++ - } - - fn([]interface{}(nil), (*decoderMsgpackIO).fastpathDecSliceIntfR) - fn([]string(nil), (*decoderMsgpackIO).fastpathDecSliceStringR) - fn([][]byte(nil), (*decoderMsgpackIO).fastpathDecSliceBytesR) - fn([]float32(nil), (*decoderMsgpackIO).fastpathDecSliceFloat32R) - fn([]float64(nil), (*decoderMsgpackIO).fastpathDecSliceFloat64R) - fn([]uint8(nil), (*decoderMsgpackIO).fastpathDecSliceUint8R) - fn([]uint64(nil), (*decoderMsgpackIO).fastpathDecSliceUint64R) - fn([]int(nil), (*decoderMsgpackIO).fastpathDecSliceIntR) - fn([]int32(nil), (*decoderMsgpackIO).fastpathDecSliceInt32R) - fn([]int64(nil), (*decoderMsgpackIO).fastpathDecSliceInt64R) - fn([]bool(nil), (*decoderMsgpackIO).fastpathDecSliceBoolR) - - fn(map[string]interface{}(nil), (*decoderMsgpackIO).fastpathDecMapStringIntfR) - fn(map[string]string(nil), (*decoderMsgpackIO).fastpathDecMapStringStringR) - fn(map[string][]byte(nil), (*decoderMsgpackIO).fastpathDecMapStringBytesR) - fn(map[string]uint8(nil), (*decoderMsgpackIO).fastpathDecMapStringUint8R) - fn(map[string]uint64(nil), (*decoderMsgpackIO).fastpathDecMapStringUint64R) - fn(map[string]int(nil), (*decoderMsgpackIO).fastpathDecMapStringIntR) - fn(map[string]int32(nil), (*decoderMsgpackIO).fastpathDecMapStringInt32R) - fn(map[string]float64(nil), (*decoderMsgpackIO).fastpathDecMapStringFloat64R) - fn(map[string]bool(nil), (*decoderMsgpackIO).fastpathDecMapStringBoolR) - fn(map[uint8]interface{}(nil), (*decoderMsgpackIO).fastpathDecMapUint8IntfR) - fn(map[uint8]string(nil), (*decoderMsgpackIO).fastpathDecMapUint8StringR) - fn(map[uint8][]byte(nil), (*decoderMsgpackIO).fastpathDecMapUint8BytesR) - fn(map[uint8]uint8(nil), (*decoderMsgpackIO).fastpathDecMapUint8Uint8R) - fn(map[uint8]uint64(nil), (*decoderMsgpackIO).fastpathDecMapUint8Uint64R) - fn(map[uint8]int(nil), (*decoderMsgpackIO).fastpathDecMapUint8IntR) - fn(map[uint8]int32(nil), (*decoderMsgpackIO).fastpathDecMapUint8Int32R) - fn(map[uint8]float64(nil), (*decoderMsgpackIO).fastpathDecMapUint8Float64R) - fn(map[uint8]bool(nil), (*decoderMsgpackIO).fastpathDecMapUint8BoolR) - fn(map[uint64]interface{}(nil), (*decoderMsgpackIO).fastpathDecMapUint64IntfR) - fn(map[uint64]string(nil), (*decoderMsgpackIO).fastpathDecMapUint64StringR) - fn(map[uint64][]byte(nil), (*decoderMsgpackIO).fastpathDecMapUint64BytesR) - fn(map[uint64]uint8(nil), (*decoderMsgpackIO).fastpathDecMapUint64Uint8R) - fn(map[uint64]uint64(nil), (*decoderMsgpackIO).fastpathDecMapUint64Uint64R) - fn(map[uint64]int(nil), (*decoderMsgpackIO).fastpathDecMapUint64IntR) - fn(map[uint64]int32(nil), (*decoderMsgpackIO).fastpathDecMapUint64Int32R) - fn(map[uint64]float64(nil), (*decoderMsgpackIO).fastpathDecMapUint64Float64R) - fn(map[uint64]bool(nil), (*decoderMsgpackIO).fastpathDecMapUint64BoolR) - fn(map[int]interface{}(nil), (*decoderMsgpackIO).fastpathDecMapIntIntfR) - fn(map[int]string(nil), (*decoderMsgpackIO).fastpathDecMapIntStringR) - fn(map[int][]byte(nil), (*decoderMsgpackIO).fastpathDecMapIntBytesR) - fn(map[int]uint8(nil), (*decoderMsgpackIO).fastpathDecMapIntUint8R) - fn(map[int]uint64(nil), (*decoderMsgpackIO).fastpathDecMapIntUint64R) - fn(map[int]int(nil), (*decoderMsgpackIO).fastpathDecMapIntIntR) - fn(map[int]int32(nil), (*decoderMsgpackIO).fastpathDecMapIntInt32R) - fn(map[int]float64(nil), (*decoderMsgpackIO).fastpathDecMapIntFloat64R) - fn(map[int]bool(nil), (*decoderMsgpackIO).fastpathDecMapIntBoolR) - fn(map[int32]interface{}(nil), (*decoderMsgpackIO).fastpathDecMapInt32IntfR) - fn(map[int32]string(nil), (*decoderMsgpackIO).fastpathDecMapInt32StringR) - fn(map[int32][]byte(nil), (*decoderMsgpackIO).fastpathDecMapInt32BytesR) - fn(map[int32]uint8(nil), (*decoderMsgpackIO).fastpathDecMapInt32Uint8R) - fn(map[int32]uint64(nil), (*decoderMsgpackIO).fastpathDecMapInt32Uint64R) - fn(map[int32]int(nil), (*decoderMsgpackIO).fastpathDecMapInt32IntR) - fn(map[int32]int32(nil), (*decoderMsgpackIO).fastpathDecMapInt32Int32R) - fn(map[int32]float64(nil), (*decoderMsgpackIO).fastpathDecMapInt32Float64R) - fn(map[int32]bool(nil), (*decoderMsgpackIO).fastpathDecMapInt32BoolR) - - sort.Slice(s[:], func(i, j int) bool { return s[i].rtid < s[j].rtid }) - return &s -} - -func (helperEncDriverMsgpackIO) fastpathEncodeTypeSwitch(iv interface{}, e *encoderMsgpackIO) bool { - var ft fastpathETMsgpackIO - switch v := iv.(type) { - case []interface{}: - if v == nil { - e.e.writeNilArray() - } else { - ft.EncSliceIntfV(v, e) - } - case []string: - if v == nil { - e.e.writeNilArray() - } else { - ft.EncSliceStringV(v, e) - } - case [][]byte: - if v == nil { - e.e.writeNilArray() - } else { - ft.EncSliceBytesV(v, e) - } - case []float32: - if v == nil { - e.e.writeNilArray() - } else { - ft.EncSliceFloat32V(v, e) - } - case []float64: - if v == nil { - e.e.writeNilArray() - } else { - ft.EncSliceFloat64V(v, e) - } - case []uint8: - if v == nil { - e.e.writeNilArray() - } else { - ft.EncSliceUint8V(v, e) - } - case []uint64: - if v == nil { - e.e.writeNilArray() - } else { - ft.EncSliceUint64V(v, e) - } - case []int: - if v == nil { - e.e.writeNilArray() - } else { - ft.EncSliceIntV(v, e) - } - case []int32: - if v == nil { - e.e.writeNilArray() - } else { - ft.EncSliceInt32V(v, e) - } - case []int64: - if v == nil { - e.e.writeNilArray() - } else { - ft.EncSliceInt64V(v, e) - } - case []bool: - if v == nil { - e.e.writeNilArray() - } else { - ft.EncSliceBoolV(v, e) - } - case map[string]interface{}: - if v == nil { - e.e.writeNilMap() - } else { - ft.EncMapStringIntfV(v, e) - } - case map[string]string: - if v == nil { - e.e.writeNilMap() - } else { - ft.EncMapStringStringV(v, e) - } - case map[string][]byte: - if v == nil { - e.e.writeNilMap() - } else { - ft.EncMapStringBytesV(v, e) - } - case map[string]uint8: - if v == nil { - e.e.writeNilMap() - } else { - ft.EncMapStringUint8V(v, e) - } - case map[string]uint64: - if v == nil { - e.e.writeNilMap() - } else { - ft.EncMapStringUint64V(v, e) - } - case map[string]int: - if v == nil { - e.e.writeNilMap() - } else { - ft.EncMapStringIntV(v, e) - } - case map[string]int32: - if v == nil { - e.e.writeNilMap() - } else { - ft.EncMapStringInt32V(v, e) - } - case map[string]float64: - if v == nil { - e.e.writeNilMap() - } else { - ft.EncMapStringFloat64V(v, e) - } - case map[string]bool: - if v == nil { - e.e.writeNilMap() - } else { - ft.EncMapStringBoolV(v, e) - } - case map[uint8]interface{}: - if v == nil { - e.e.writeNilMap() - } else { - ft.EncMapUint8IntfV(v, e) - } - case map[uint8]string: - if v == nil { - e.e.writeNilMap() - } else { - ft.EncMapUint8StringV(v, e) - } - case map[uint8][]byte: - if v == nil { - e.e.writeNilMap() - } else { - ft.EncMapUint8BytesV(v, e) - } - case map[uint8]uint8: - if v == nil { - e.e.writeNilMap() - } else { - ft.EncMapUint8Uint8V(v, e) - } - case map[uint8]uint64: - if v == nil { - e.e.writeNilMap() - } else { - ft.EncMapUint8Uint64V(v, e) - } - case map[uint8]int: - if v == nil { - e.e.writeNilMap() - } else { - ft.EncMapUint8IntV(v, e) - } - case map[uint8]int32: - if v == nil { - e.e.writeNilMap() - } else { - ft.EncMapUint8Int32V(v, e) - } - case map[uint8]float64: - if v == nil { - e.e.writeNilMap() - } else { - ft.EncMapUint8Float64V(v, e) - } - case map[uint8]bool: - if v == nil { - e.e.writeNilMap() - } else { - ft.EncMapUint8BoolV(v, e) - } - case map[uint64]interface{}: - if v == nil { - e.e.writeNilMap() - } else { - ft.EncMapUint64IntfV(v, e) - } - case map[uint64]string: - if v == nil { - e.e.writeNilMap() - } else { - ft.EncMapUint64StringV(v, e) - } - case map[uint64][]byte: - if v == nil { - e.e.writeNilMap() - } else { - ft.EncMapUint64BytesV(v, e) - } - case map[uint64]uint8: - if v == nil { - e.e.writeNilMap() - } else { - ft.EncMapUint64Uint8V(v, e) - } - case map[uint64]uint64: - if v == nil { - e.e.writeNilMap() - } else { - ft.EncMapUint64Uint64V(v, e) - } - case map[uint64]int: - if v == nil { - e.e.writeNilMap() - } else { - ft.EncMapUint64IntV(v, e) - } - case map[uint64]int32: - if v == nil { - e.e.writeNilMap() - } else { - ft.EncMapUint64Int32V(v, e) - } - case map[uint64]float64: - if v == nil { - e.e.writeNilMap() - } else { - ft.EncMapUint64Float64V(v, e) - } - case map[uint64]bool: - if v == nil { - e.e.writeNilMap() - } else { - ft.EncMapUint64BoolV(v, e) - } - case map[int]interface{}: - if v == nil { - e.e.writeNilMap() - } else { - ft.EncMapIntIntfV(v, e) - } - case map[int]string: - if v == nil { - e.e.writeNilMap() - } else { - ft.EncMapIntStringV(v, e) - } - case map[int][]byte: - if v == nil { - e.e.writeNilMap() - } else { - ft.EncMapIntBytesV(v, e) - } - case map[int]uint8: - if v == nil { - e.e.writeNilMap() - } else { - ft.EncMapIntUint8V(v, e) - } - case map[int]uint64: - if v == nil { - e.e.writeNilMap() - } else { - ft.EncMapIntUint64V(v, e) - } - case map[int]int: - if v == nil { - e.e.writeNilMap() - } else { - ft.EncMapIntIntV(v, e) - } - case map[int]int32: - if v == nil { - e.e.writeNilMap() - } else { - ft.EncMapIntInt32V(v, e) - } - case map[int]float64: - if v == nil { - e.e.writeNilMap() - } else { - ft.EncMapIntFloat64V(v, e) - } - case map[int]bool: - if v == nil { - e.e.writeNilMap() - } else { - ft.EncMapIntBoolV(v, e) - } - case map[int32]interface{}: - if v == nil { - e.e.writeNilMap() - } else { - ft.EncMapInt32IntfV(v, e) - } - case map[int32]string: - if v == nil { - e.e.writeNilMap() - } else { - ft.EncMapInt32StringV(v, e) - } - case map[int32][]byte: - if v == nil { - e.e.writeNilMap() - } else { - ft.EncMapInt32BytesV(v, e) - } - case map[int32]uint8: - if v == nil { - e.e.writeNilMap() - } else { - ft.EncMapInt32Uint8V(v, e) - } - case map[int32]uint64: - if v == nil { - e.e.writeNilMap() - } else { - ft.EncMapInt32Uint64V(v, e) - } - case map[int32]int: - if v == nil { - e.e.writeNilMap() - } else { - ft.EncMapInt32IntV(v, e) - } - case map[int32]int32: - if v == nil { - e.e.writeNilMap() - } else { - ft.EncMapInt32Int32V(v, e) - } - case map[int32]float64: - if v == nil { - e.e.writeNilMap() - } else { - ft.EncMapInt32Float64V(v, e) - } - case map[int32]bool: - if v == nil { - e.e.writeNilMap() - } else { - ft.EncMapInt32BoolV(v, e) - } - default: - _ = v - return false - } - return true -} - -func (e *encoderMsgpackIO) fastpathEncSliceIntfR(f *encFnInfo, rv reflect.Value) { - var ft fastpathETMsgpackIO - var v []interface{} - if rv.Kind() == reflect.Array { - rvGetSlice4Array(rv, &v) - } else { - v = rv2i(rv).([]interface{}) - } - if f.ti.mbs { - ft.EncAsMapSliceIntfV(v, e) - return - } - ft.EncSliceIntfV(v, e) -} -func (fastpathETMsgpackIO) EncSliceIntfV(v []interface{}, e *encoderMsgpackIO) { - if len(v) == 0 { - e.c = 0 - e.e.WriteArrayEmpty() - return - } - e.arrayStart(len(v)) - for j := range v { - e.c = containerArrayElem - e.e.WriteArrayElem(j == 0) - if !e.encodeBuiltin(v[j]) { - e.encodeR(reflect.ValueOf(v[j])) - } - } - e.c = 0 - e.e.WriteArrayEnd() -} -func (fastpathETMsgpackIO) EncAsMapSliceIntfV(v []interface{}, e *encoderMsgpackIO) { - if len(v) == 0 { - e.c = 0 - e.e.WriteMapEmpty() - return - } - e.haltOnMbsOddLen(len(v)) - e.mapStart(len(v) >> 1) - for j := range v { - if j&1 == 0 { - e.c = containerMapKey - e.e.WriteMapElemKey(j == 0) - } else { - e.mapElemValue() - } - if !e.encodeBuiltin(v[j]) { - e.encodeR(reflect.ValueOf(v[j])) - } - } - e.c = 0 - e.e.WriteMapEnd() -} - -func (e *encoderMsgpackIO) fastpathEncSliceStringR(f *encFnInfo, rv reflect.Value) { - var ft fastpathETMsgpackIO - var v []string - if rv.Kind() == reflect.Array { - rvGetSlice4Array(rv, &v) - } else { - v = rv2i(rv).([]string) - } - if f.ti.mbs { - ft.EncAsMapSliceStringV(v, e) - return - } - ft.EncSliceStringV(v, e) -} -func (fastpathETMsgpackIO) EncSliceStringV(v []string, e *encoderMsgpackIO) { - if len(v) == 0 { - e.c = 0 - e.e.WriteArrayEmpty() - return - } - e.arrayStart(len(v)) - for j := range v { - e.c = containerArrayElem - e.e.WriteArrayElem(j == 0) - e.e.EncodeString(v[j]) - } - e.c = 0 - e.e.WriteArrayEnd() -} -func (fastpathETMsgpackIO) EncAsMapSliceStringV(v []string, e *encoderMsgpackIO) { - if len(v) == 0 { - e.c = 0 - e.e.WriteMapEmpty() - return - } - e.haltOnMbsOddLen(len(v)) - e.mapStart(len(v) >> 1) - for j := range v { - if j&1 == 0 { - e.c = containerMapKey - e.e.WriteMapElemKey(j == 0) - } else { - e.mapElemValue() - } - e.e.EncodeString(v[j]) - } - e.c = 0 - e.e.WriteMapEnd() -} - -func (e *encoderMsgpackIO) fastpathEncSliceBytesR(f *encFnInfo, rv reflect.Value) { - var ft fastpathETMsgpackIO - var v [][]byte - if rv.Kind() == reflect.Array { - rvGetSlice4Array(rv, &v) - } else { - v = rv2i(rv).([][]byte) - } - if f.ti.mbs { - ft.EncAsMapSliceBytesV(v, e) - return - } - ft.EncSliceBytesV(v, e) -} -func (fastpathETMsgpackIO) EncSliceBytesV(v [][]byte, e *encoderMsgpackIO) { - if len(v) == 0 { - e.c = 0 - e.e.WriteArrayEmpty() - return - } - e.arrayStart(len(v)) - for j := range v { - e.c = containerArrayElem - e.e.WriteArrayElem(j == 0) - e.e.EncodeBytes(v[j]) - } - e.c = 0 - e.e.WriteArrayEnd() -} -func (fastpathETMsgpackIO) EncAsMapSliceBytesV(v [][]byte, e *encoderMsgpackIO) { - if len(v) == 0 { - e.c = 0 - e.e.WriteMapEmpty() - return - } - e.haltOnMbsOddLen(len(v)) - e.mapStart(len(v) >> 1) - for j := range v { - if j&1 == 0 { - e.c = containerMapKey - e.e.WriteMapElemKey(j == 0) - } else { - e.mapElemValue() - } - e.e.EncodeBytes(v[j]) - } - e.c = 0 - e.e.WriteMapEnd() -} - -func (e *encoderMsgpackIO) fastpathEncSliceFloat32R(f *encFnInfo, rv reflect.Value) { - var ft fastpathETMsgpackIO - var v []float32 - if rv.Kind() == reflect.Array { - rvGetSlice4Array(rv, &v) - } else { - v = rv2i(rv).([]float32) - } - if f.ti.mbs { - ft.EncAsMapSliceFloat32V(v, e) - return - } - ft.EncSliceFloat32V(v, e) -} -func (fastpathETMsgpackIO) EncSliceFloat32V(v []float32, e *encoderMsgpackIO) { - if len(v) == 0 { - e.c = 0 - e.e.WriteArrayEmpty() - return - } - e.arrayStart(len(v)) - for j := range v { - e.c = containerArrayElem - e.e.WriteArrayElem(j == 0) - e.e.EncodeFloat32(v[j]) - } - e.c = 0 - e.e.WriteArrayEnd() -} -func (fastpathETMsgpackIO) EncAsMapSliceFloat32V(v []float32, e *encoderMsgpackIO) { - if len(v) == 0 { - e.c = 0 - e.e.WriteMapEmpty() - return - } - e.haltOnMbsOddLen(len(v)) - e.mapStart(len(v) >> 1) - for j := range v { - if j&1 == 0 { - e.c = containerMapKey - e.e.WriteMapElemKey(j == 0) - } else { - e.mapElemValue() - } - e.e.EncodeFloat32(v[j]) - } - e.c = 0 - e.e.WriteMapEnd() -} - -func (e *encoderMsgpackIO) fastpathEncSliceFloat64R(f *encFnInfo, rv reflect.Value) { - var ft fastpathETMsgpackIO - var v []float64 - if rv.Kind() == reflect.Array { - rvGetSlice4Array(rv, &v) - } else { - v = rv2i(rv).([]float64) - } - if f.ti.mbs { - ft.EncAsMapSliceFloat64V(v, e) - return - } - ft.EncSliceFloat64V(v, e) -} -func (fastpathETMsgpackIO) EncSliceFloat64V(v []float64, e *encoderMsgpackIO) { - if len(v) == 0 { - e.c = 0 - e.e.WriteArrayEmpty() - return - } - e.arrayStart(len(v)) - for j := range v { - e.c = containerArrayElem - e.e.WriteArrayElem(j == 0) - e.e.EncodeFloat64(v[j]) - } - e.c = 0 - e.e.WriteArrayEnd() -} -func (fastpathETMsgpackIO) EncAsMapSliceFloat64V(v []float64, e *encoderMsgpackIO) { - if len(v) == 0 { - e.c = 0 - e.e.WriteMapEmpty() - return - } - e.haltOnMbsOddLen(len(v)) - e.mapStart(len(v) >> 1) - for j := range v { - if j&1 == 0 { - e.c = containerMapKey - e.e.WriteMapElemKey(j == 0) - } else { - e.mapElemValue() - } - e.e.EncodeFloat64(v[j]) - } - e.c = 0 - e.e.WriteMapEnd() -} - -func (e *encoderMsgpackIO) fastpathEncSliceUint8R(f *encFnInfo, rv reflect.Value) { - var ft fastpathETMsgpackIO - var v []uint8 - if rv.Kind() == reflect.Array { - rvGetSlice4Array(rv, &v) - } else { - v = rv2i(rv).([]uint8) - } - if f.ti.mbs { - ft.EncAsMapSliceUint8V(v, e) - return - } - ft.EncSliceUint8V(v, e) -} -func (fastpathETMsgpackIO) EncSliceUint8V(v []uint8, e *encoderMsgpackIO) { - e.e.EncodeStringBytesRaw(v) -} -func (fastpathETMsgpackIO) EncAsMapSliceUint8V(v []uint8, e *encoderMsgpackIO) { - if len(v) == 0 { - e.c = 0 - e.e.WriteMapEmpty() - return - } - e.haltOnMbsOddLen(len(v)) - e.mapStart(len(v) >> 1) - for j := range v { - if j&1 == 0 { - e.c = containerMapKey - e.e.WriteMapElemKey(j == 0) - } else { - e.mapElemValue() - } - e.e.EncodeUint(uint64(v[j])) - } - e.c = 0 - e.e.WriteMapEnd() -} - -func (e *encoderMsgpackIO) fastpathEncSliceUint64R(f *encFnInfo, rv reflect.Value) { - var ft fastpathETMsgpackIO - var v []uint64 - if rv.Kind() == reflect.Array { - rvGetSlice4Array(rv, &v) - } else { - v = rv2i(rv).([]uint64) - } - if f.ti.mbs { - ft.EncAsMapSliceUint64V(v, e) - return - } - ft.EncSliceUint64V(v, e) -} -func (fastpathETMsgpackIO) EncSliceUint64V(v []uint64, e *encoderMsgpackIO) { - if len(v) == 0 { - e.c = 0 - e.e.WriteArrayEmpty() - return - } - e.arrayStart(len(v)) - for j := range v { - e.c = containerArrayElem - e.e.WriteArrayElem(j == 0) - e.e.EncodeUint(v[j]) - } - e.c = 0 - e.e.WriteArrayEnd() -} -func (fastpathETMsgpackIO) EncAsMapSliceUint64V(v []uint64, e *encoderMsgpackIO) { - if len(v) == 0 { - e.c = 0 - e.e.WriteMapEmpty() - return - } - e.haltOnMbsOddLen(len(v)) - e.mapStart(len(v) >> 1) - for j := range v { - if j&1 == 0 { - e.c = containerMapKey - e.e.WriteMapElemKey(j == 0) - } else { - e.mapElemValue() - } - e.e.EncodeUint(v[j]) - } - e.c = 0 - e.e.WriteMapEnd() -} - -func (e *encoderMsgpackIO) fastpathEncSliceIntR(f *encFnInfo, rv reflect.Value) { - var ft fastpathETMsgpackIO - var v []int - if rv.Kind() == reflect.Array { - rvGetSlice4Array(rv, &v) - } else { - v = rv2i(rv).([]int) - } - if f.ti.mbs { - ft.EncAsMapSliceIntV(v, e) - return - } - ft.EncSliceIntV(v, e) -} -func (fastpathETMsgpackIO) EncSliceIntV(v []int, e *encoderMsgpackIO) { - if len(v) == 0 { - e.c = 0 - e.e.WriteArrayEmpty() - return - } - e.arrayStart(len(v)) - for j := range v { - e.c = containerArrayElem - e.e.WriteArrayElem(j == 0) - e.e.EncodeInt(int64(v[j])) - } - e.c = 0 - e.e.WriteArrayEnd() -} -func (fastpathETMsgpackIO) EncAsMapSliceIntV(v []int, e *encoderMsgpackIO) { - if len(v) == 0 { - e.c = 0 - e.e.WriteMapEmpty() - return - } - e.haltOnMbsOddLen(len(v)) - e.mapStart(len(v) >> 1) - for j := range v { - if j&1 == 0 { - e.c = containerMapKey - e.e.WriteMapElemKey(j == 0) - } else { - e.mapElemValue() - } - e.e.EncodeInt(int64(v[j])) - } - e.c = 0 - e.e.WriteMapEnd() -} - -func (e *encoderMsgpackIO) fastpathEncSliceInt32R(f *encFnInfo, rv reflect.Value) { - var ft fastpathETMsgpackIO - var v []int32 - if rv.Kind() == reflect.Array { - rvGetSlice4Array(rv, &v) - } else { - v = rv2i(rv).([]int32) - } - if f.ti.mbs { - ft.EncAsMapSliceInt32V(v, e) - return - } - ft.EncSliceInt32V(v, e) -} -func (fastpathETMsgpackIO) EncSliceInt32V(v []int32, e *encoderMsgpackIO) { - if len(v) == 0 { - e.c = 0 - e.e.WriteArrayEmpty() - return - } - e.arrayStart(len(v)) - for j := range v { - e.c = containerArrayElem - e.e.WriteArrayElem(j == 0) - e.e.EncodeInt(int64(v[j])) - } - e.c = 0 - e.e.WriteArrayEnd() -} -func (fastpathETMsgpackIO) EncAsMapSliceInt32V(v []int32, e *encoderMsgpackIO) { - if len(v) == 0 { - e.c = 0 - e.e.WriteMapEmpty() - return - } - e.haltOnMbsOddLen(len(v)) - e.mapStart(len(v) >> 1) - for j := range v { - if j&1 == 0 { - e.c = containerMapKey - e.e.WriteMapElemKey(j == 0) - } else { - e.mapElemValue() - } - e.e.EncodeInt(int64(v[j])) - } - e.c = 0 - e.e.WriteMapEnd() -} - -func (e *encoderMsgpackIO) fastpathEncSliceInt64R(f *encFnInfo, rv reflect.Value) { - var ft fastpathETMsgpackIO - var v []int64 - if rv.Kind() == reflect.Array { - rvGetSlice4Array(rv, &v) - } else { - v = rv2i(rv).([]int64) - } - if f.ti.mbs { - ft.EncAsMapSliceInt64V(v, e) - return - } - ft.EncSliceInt64V(v, e) -} -func (fastpathETMsgpackIO) EncSliceInt64V(v []int64, e *encoderMsgpackIO) { - if len(v) == 0 { - e.c = 0 - e.e.WriteArrayEmpty() - return - } - e.arrayStart(len(v)) - for j := range v { - e.c = containerArrayElem - e.e.WriteArrayElem(j == 0) - e.e.EncodeInt(v[j]) - } - e.c = 0 - e.e.WriteArrayEnd() -} -func (fastpathETMsgpackIO) EncAsMapSliceInt64V(v []int64, e *encoderMsgpackIO) { - if len(v) == 0 { - e.c = 0 - e.e.WriteMapEmpty() - return - } - e.haltOnMbsOddLen(len(v)) - e.mapStart(len(v) >> 1) - for j := range v { - if j&1 == 0 { - e.c = containerMapKey - e.e.WriteMapElemKey(j == 0) - } else { - e.mapElemValue() - } - e.e.EncodeInt(v[j]) - } - e.c = 0 - e.e.WriteMapEnd() -} - -func (e *encoderMsgpackIO) fastpathEncSliceBoolR(f *encFnInfo, rv reflect.Value) { - var ft fastpathETMsgpackIO - var v []bool - if rv.Kind() == reflect.Array { - rvGetSlice4Array(rv, &v) - } else { - v = rv2i(rv).([]bool) - } - if f.ti.mbs { - ft.EncAsMapSliceBoolV(v, e) - return - } - ft.EncSliceBoolV(v, e) -} -func (fastpathETMsgpackIO) EncSliceBoolV(v []bool, e *encoderMsgpackIO) { - if len(v) == 0 { - e.c = 0 - e.e.WriteArrayEmpty() - return - } - e.arrayStart(len(v)) - for j := range v { - e.c = containerArrayElem - e.e.WriteArrayElem(j == 0) - e.e.EncodeBool(v[j]) - } - e.c = 0 - e.e.WriteArrayEnd() -} -func (fastpathETMsgpackIO) EncAsMapSliceBoolV(v []bool, e *encoderMsgpackIO) { - if len(v) == 0 { - e.c = 0 - e.e.WriteMapEmpty() - return - } - e.haltOnMbsOddLen(len(v)) - e.mapStart(len(v) >> 1) - for j := range v { - if j&1 == 0 { - e.c = containerMapKey - e.e.WriteMapElemKey(j == 0) - } else { - e.mapElemValue() - } - e.e.EncodeBool(v[j]) - } - e.c = 0 - e.e.WriteMapEnd() -} - -func (e *encoderMsgpackIO) fastpathEncMapStringIntfR(f *encFnInfo, rv reflect.Value) { - fastpathETMsgpackIO{}.EncMapStringIntfV(rv2i(rv).(map[string]interface{}), e) -} -func (fastpathETMsgpackIO) EncMapStringIntfV(v map[string]interface{}, e *encoderMsgpackIO) { - if len(v) == 0 { - e.e.WriteMapEmpty() - return - } - var i uint - e.mapStart(len(v)) - if e.h.Canonical { - v2 := make([]string, len(v)) - for k := range v { - v2[i] = k - i++ - } - slices.Sort(v2) - for i, k2 := range v2 { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeString(k2) - e.mapElemValue() - if !e.encodeBuiltin(v[k2]) { - e.encodeR(reflect.ValueOf(v[k2])) - } - } - } else { - i = 0 - for k2, v2 := range v { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeString(k2) - e.mapElemValue() - if !e.encodeBuiltin(v2) { - e.encodeR(reflect.ValueOf(v2)) - } - i++ - } - } - e.c = 0 - e.e.WriteMapEnd() -} -func (e *encoderMsgpackIO) fastpathEncMapStringStringR(f *encFnInfo, rv reflect.Value) { - fastpathETMsgpackIO{}.EncMapStringStringV(rv2i(rv).(map[string]string), e) -} -func (fastpathETMsgpackIO) EncMapStringStringV(v map[string]string, e *encoderMsgpackIO) { - if len(v) == 0 { - e.e.WriteMapEmpty() - return - } - var i uint - e.mapStart(len(v)) - if e.h.Canonical { - v2 := make([]string, len(v)) - for k := range v { - v2[i] = k - i++ - } - slices.Sort(v2) - for i, k2 := range v2 { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeString(k2) - e.mapElemValue() - e.e.EncodeString(v[k2]) - } - } else { - i = 0 - for k2, v2 := range v { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeString(k2) - e.mapElemValue() - e.e.EncodeString(v2) - i++ - } - } - e.c = 0 - e.e.WriteMapEnd() -} -func (e *encoderMsgpackIO) fastpathEncMapStringBytesR(f *encFnInfo, rv reflect.Value) { - fastpathETMsgpackIO{}.EncMapStringBytesV(rv2i(rv).(map[string][]byte), e) -} -func (fastpathETMsgpackIO) EncMapStringBytesV(v map[string][]byte, e *encoderMsgpackIO) { - if len(v) == 0 { - e.e.WriteMapEmpty() - return - } - var i uint - e.mapStart(len(v)) - if e.h.Canonical { - v2 := make([]string, len(v)) - for k := range v { - v2[i] = k - i++ - } - slices.Sort(v2) - for i, k2 := range v2 { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeString(k2) - e.mapElemValue() - e.e.EncodeBytes(v[k2]) - } - } else { - i = 0 - for k2, v2 := range v { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeString(k2) - e.mapElemValue() - e.e.EncodeBytes(v2) - i++ - } - } - e.c = 0 - e.e.WriteMapEnd() -} -func (e *encoderMsgpackIO) fastpathEncMapStringUint8R(f *encFnInfo, rv reflect.Value) { - fastpathETMsgpackIO{}.EncMapStringUint8V(rv2i(rv).(map[string]uint8), e) -} -func (fastpathETMsgpackIO) EncMapStringUint8V(v map[string]uint8, e *encoderMsgpackIO) { - if len(v) == 0 { - e.e.WriteMapEmpty() - return - } - var i uint - e.mapStart(len(v)) - if e.h.Canonical { - v2 := make([]string, len(v)) - for k := range v { - v2[i] = k - i++ - } - slices.Sort(v2) - for i, k2 := range v2 { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeString(k2) - e.mapElemValue() - e.e.EncodeUint(uint64(v[k2])) - } - } else { - i = 0 - for k2, v2 := range v { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeString(k2) - e.mapElemValue() - e.e.EncodeUint(uint64(v2)) - i++ - } - } - e.c = 0 - e.e.WriteMapEnd() -} -func (e *encoderMsgpackIO) fastpathEncMapStringUint64R(f *encFnInfo, rv reflect.Value) { - fastpathETMsgpackIO{}.EncMapStringUint64V(rv2i(rv).(map[string]uint64), e) -} -func (fastpathETMsgpackIO) EncMapStringUint64V(v map[string]uint64, e *encoderMsgpackIO) { - if len(v) == 0 { - e.e.WriteMapEmpty() - return - } - var i uint - e.mapStart(len(v)) - if e.h.Canonical { - v2 := make([]string, len(v)) - for k := range v { - v2[i] = k - i++ - } - slices.Sort(v2) - for i, k2 := range v2 { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeString(k2) - e.mapElemValue() - e.e.EncodeUint(v[k2]) - } - } else { - i = 0 - for k2, v2 := range v { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeString(k2) - e.mapElemValue() - e.e.EncodeUint(v2) - i++ - } - } - e.c = 0 - e.e.WriteMapEnd() -} -func (e *encoderMsgpackIO) fastpathEncMapStringIntR(f *encFnInfo, rv reflect.Value) { - fastpathETMsgpackIO{}.EncMapStringIntV(rv2i(rv).(map[string]int), e) -} -func (fastpathETMsgpackIO) EncMapStringIntV(v map[string]int, e *encoderMsgpackIO) { - if len(v) == 0 { - e.e.WriteMapEmpty() - return - } - var i uint - e.mapStart(len(v)) - if e.h.Canonical { - v2 := make([]string, len(v)) - for k := range v { - v2[i] = k - i++ - } - slices.Sort(v2) - for i, k2 := range v2 { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeString(k2) - e.mapElemValue() - e.e.EncodeInt(int64(v[k2])) - } - } else { - i = 0 - for k2, v2 := range v { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeString(k2) - e.mapElemValue() - e.e.EncodeInt(int64(v2)) - i++ - } - } - e.c = 0 - e.e.WriteMapEnd() -} -func (e *encoderMsgpackIO) fastpathEncMapStringInt32R(f *encFnInfo, rv reflect.Value) { - fastpathETMsgpackIO{}.EncMapStringInt32V(rv2i(rv).(map[string]int32), e) -} -func (fastpathETMsgpackIO) EncMapStringInt32V(v map[string]int32, e *encoderMsgpackIO) { - if len(v) == 0 { - e.e.WriteMapEmpty() - return - } - var i uint - e.mapStart(len(v)) - if e.h.Canonical { - v2 := make([]string, len(v)) - for k := range v { - v2[i] = k - i++ - } - slices.Sort(v2) - for i, k2 := range v2 { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeString(k2) - e.mapElemValue() - e.e.EncodeInt(int64(v[k2])) - } - } else { - i = 0 - for k2, v2 := range v { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeString(k2) - e.mapElemValue() - e.e.EncodeInt(int64(v2)) - i++ - } - } - e.c = 0 - e.e.WriteMapEnd() -} -func (e *encoderMsgpackIO) fastpathEncMapStringFloat64R(f *encFnInfo, rv reflect.Value) { - fastpathETMsgpackIO{}.EncMapStringFloat64V(rv2i(rv).(map[string]float64), e) -} -func (fastpathETMsgpackIO) EncMapStringFloat64V(v map[string]float64, e *encoderMsgpackIO) { - if len(v) == 0 { - e.e.WriteMapEmpty() - return - } - var i uint - e.mapStart(len(v)) - if e.h.Canonical { - v2 := make([]string, len(v)) - for k := range v { - v2[i] = k - i++ - } - slices.Sort(v2) - for i, k2 := range v2 { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeString(k2) - e.mapElemValue() - e.e.EncodeFloat64(v[k2]) - } - } else { - i = 0 - for k2, v2 := range v { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeString(k2) - e.mapElemValue() - e.e.EncodeFloat64(v2) - i++ - } - } - e.c = 0 - e.e.WriteMapEnd() -} -func (e *encoderMsgpackIO) fastpathEncMapStringBoolR(f *encFnInfo, rv reflect.Value) { - fastpathETMsgpackIO{}.EncMapStringBoolV(rv2i(rv).(map[string]bool), e) -} -func (fastpathETMsgpackIO) EncMapStringBoolV(v map[string]bool, e *encoderMsgpackIO) { - if len(v) == 0 { - e.e.WriteMapEmpty() - return - } - var i uint - e.mapStart(len(v)) - if e.h.Canonical { - v2 := make([]string, len(v)) - for k := range v { - v2[i] = k - i++ - } - slices.Sort(v2) - for i, k2 := range v2 { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeString(k2) - e.mapElemValue() - e.e.EncodeBool(v[k2]) - } - } else { - i = 0 - for k2, v2 := range v { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeString(k2) - e.mapElemValue() - e.e.EncodeBool(v2) - i++ - } - } - e.c = 0 - e.e.WriteMapEnd() -} -func (e *encoderMsgpackIO) fastpathEncMapUint8IntfR(f *encFnInfo, rv reflect.Value) { - fastpathETMsgpackIO{}.EncMapUint8IntfV(rv2i(rv).(map[uint8]interface{}), e) -} -func (fastpathETMsgpackIO) EncMapUint8IntfV(v map[uint8]interface{}, e *encoderMsgpackIO) { - if len(v) == 0 { - e.e.WriteMapEmpty() - return - } - var i uint - e.mapStart(len(v)) - if e.h.Canonical { - v2 := make([]uint8, len(v)) - for k := range v { - v2[i] = k - i++ - } - slices.Sort(v2) - for i, k2 := range v2 { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeUint(uint64(k2)) - e.mapElemValue() - if !e.encodeBuiltin(v[k2]) { - e.encodeR(reflect.ValueOf(v[k2])) - } - } - } else { - i = 0 - for k2, v2 := range v { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeUint(uint64(k2)) - e.mapElemValue() - if !e.encodeBuiltin(v2) { - e.encodeR(reflect.ValueOf(v2)) - } - i++ - } - } - e.c = 0 - e.e.WriteMapEnd() -} -func (e *encoderMsgpackIO) fastpathEncMapUint8StringR(f *encFnInfo, rv reflect.Value) { - fastpathETMsgpackIO{}.EncMapUint8StringV(rv2i(rv).(map[uint8]string), e) -} -func (fastpathETMsgpackIO) EncMapUint8StringV(v map[uint8]string, e *encoderMsgpackIO) { - if len(v) == 0 { - e.e.WriteMapEmpty() - return - } - var i uint - e.mapStart(len(v)) - if e.h.Canonical { - v2 := make([]uint8, len(v)) - for k := range v { - v2[i] = k - i++ - } - slices.Sort(v2) - for i, k2 := range v2 { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeUint(uint64(k2)) - e.mapElemValue() - e.e.EncodeString(v[k2]) - } - } else { - i = 0 - for k2, v2 := range v { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeUint(uint64(k2)) - e.mapElemValue() - e.e.EncodeString(v2) - i++ - } - } - e.c = 0 - e.e.WriteMapEnd() -} -func (e *encoderMsgpackIO) fastpathEncMapUint8BytesR(f *encFnInfo, rv reflect.Value) { - fastpathETMsgpackIO{}.EncMapUint8BytesV(rv2i(rv).(map[uint8][]byte), e) -} -func (fastpathETMsgpackIO) EncMapUint8BytesV(v map[uint8][]byte, e *encoderMsgpackIO) { - if len(v) == 0 { - e.e.WriteMapEmpty() - return - } - var i uint - e.mapStart(len(v)) - if e.h.Canonical { - v2 := make([]uint8, len(v)) - for k := range v { - v2[i] = k - i++ - } - slices.Sort(v2) - for i, k2 := range v2 { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeUint(uint64(k2)) - e.mapElemValue() - e.e.EncodeBytes(v[k2]) - } - } else { - i = 0 - for k2, v2 := range v { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeUint(uint64(k2)) - e.mapElemValue() - e.e.EncodeBytes(v2) - i++ - } - } - e.c = 0 - e.e.WriteMapEnd() -} -func (e *encoderMsgpackIO) fastpathEncMapUint8Uint8R(f *encFnInfo, rv reflect.Value) { - fastpathETMsgpackIO{}.EncMapUint8Uint8V(rv2i(rv).(map[uint8]uint8), e) -} -func (fastpathETMsgpackIO) EncMapUint8Uint8V(v map[uint8]uint8, e *encoderMsgpackIO) { - if len(v) == 0 { - e.e.WriteMapEmpty() - return - } - var i uint - e.mapStart(len(v)) - if e.h.Canonical { - v2 := make([]uint8, len(v)) - for k := range v { - v2[i] = k - i++ - } - slices.Sort(v2) - for i, k2 := range v2 { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeUint(uint64(k2)) - e.mapElemValue() - e.e.EncodeUint(uint64(v[k2])) - } - } else { - i = 0 - for k2, v2 := range v { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeUint(uint64(k2)) - e.mapElemValue() - e.e.EncodeUint(uint64(v2)) - i++ - } - } - e.c = 0 - e.e.WriteMapEnd() -} -func (e *encoderMsgpackIO) fastpathEncMapUint8Uint64R(f *encFnInfo, rv reflect.Value) { - fastpathETMsgpackIO{}.EncMapUint8Uint64V(rv2i(rv).(map[uint8]uint64), e) -} -func (fastpathETMsgpackIO) EncMapUint8Uint64V(v map[uint8]uint64, e *encoderMsgpackIO) { - if len(v) == 0 { - e.e.WriteMapEmpty() - return - } - var i uint - e.mapStart(len(v)) - if e.h.Canonical { - v2 := make([]uint8, len(v)) - for k := range v { - v2[i] = k - i++ - } - slices.Sort(v2) - for i, k2 := range v2 { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeUint(uint64(k2)) - e.mapElemValue() - e.e.EncodeUint(v[k2]) - } - } else { - i = 0 - for k2, v2 := range v { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeUint(uint64(k2)) - e.mapElemValue() - e.e.EncodeUint(v2) - i++ - } - } - e.c = 0 - e.e.WriteMapEnd() -} -func (e *encoderMsgpackIO) fastpathEncMapUint8IntR(f *encFnInfo, rv reflect.Value) { - fastpathETMsgpackIO{}.EncMapUint8IntV(rv2i(rv).(map[uint8]int), e) -} -func (fastpathETMsgpackIO) EncMapUint8IntV(v map[uint8]int, e *encoderMsgpackIO) { - if len(v) == 0 { - e.e.WriteMapEmpty() - return - } - var i uint - e.mapStart(len(v)) - if e.h.Canonical { - v2 := make([]uint8, len(v)) - for k := range v { - v2[i] = k - i++ - } - slices.Sort(v2) - for i, k2 := range v2 { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeUint(uint64(k2)) - e.mapElemValue() - e.e.EncodeInt(int64(v[k2])) - } - } else { - i = 0 - for k2, v2 := range v { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeUint(uint64(k2)) - e.mapElemValue() - e.e.EncodeInt(int64(v2)) - i++ - } - } - e.c = 0 - e.e.WriteMapEnd() -} -func (e *encoderMsgpackIO) fastpathEncMapUint8Int32R(f *encFnInfo, rv reflect.Value) { - fastpathETMsgpackIO{}.EncMapUint8Int32V(rv2i(rv).(map[uint8]int32), e) -} -func (fastpathETMsgpackIO) EncMapUint8Int32V(v map[uint8]int32, e *encoderMsgpackIO) { - if len(v) == 0 { - e.e.WriteMapEmpty() - return - } - var i uint - e.mapStart(len(v)) - if e.h.Canonical { - v2 := make([]uint8, len(v)) - for k := range v { - v2[i] = k - i++ - } - slices.Sort(v2) - for i, k2 := range v2 { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeUint(uint64(k2)) - e.mapElemValue() - e.e.EncodeInt(int64(v[k2])) - } - } else { - i = 0 - for k2, v2 := range v { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeUint(uint64(k2)) - e.mapElemValue() - e.e.EncodeInt(int64(v2)) - i++ - } - } - e.c = 0 - e.e.WriteMapEnd() -} -func (e *encoderMsgpackIO) fastpathEncMapUint8Float64R(f *encFnInfo, rv reflect.Value) { - fastpathETMsgpackIO{}.EncMapUint8Float64V(rv2i(rv).(map[uint8]float64), e) -} -func (fastpathETMsgpackIO) EncMapUint8Float64V(v map[uint8]float64, e *encoderMsgpackIO) { - if len(v) == 0 { - e.e.WriteMapEmpty() - return - } - var i uint - e.mapStart(len(v)) - if e.h.Canonical { - v2 := make([]uint8, len(v)) - for k := range v { - v2[i] = k - i++ - } - slices.Sort(v2) - for i, k2 := range v2 { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeUint(uint64(k2)) - e.mapElemValue() - e.e.EncodeFloat64(v[k2]) - } - } else { - i = 0 - for k2, v2 := range v { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeUint(uint64(k2)) - e.mapElemValue() - e.e.EncodeFloat64(v2) - i++ - } - } - e.c = 0 - e.e.WriteMapEnd() -} -func (e *encoderMsgpackIO) fastpathEncMapUint8BoolR(f *encFnInfo, rv reflect.Value) { - fastpathETMsgpackIO{}.EncMapUint8BoolV(rv2i(rv).(map[uint8]bool), e) -} -func (fastpathETMsgpackIO) EncMapUint8BoolV(v map[uint8]bool, e *encoderMsgpackIO) { - if len(v) == 0 { - e.e.WriteMapEmpty() - return - } - var i uint - e.mapStart(len(v)) - if e.h.Canonical { - v2 := make([]uint8, len(v)) - for k := range v { - v2[i] = k - i++ - } - slices.Sort(v2) - for i, k2 := range v2 { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeUint(uint64(k2)) - e.mapElemValue() - e.e.EncodeBool(v[k2]) - } - } else { - i = 0 - for k2, v2 := range v { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeUint(uint64(k2)) - e.mapElemValue() - e.e.EncodeBool(v2) - i++ - } - } - e.c = 0 - e.e.WriteMapEnd() -} -func (e *encoderMsgpackIO) fastpathEncMapUint64IntfR(f *encFnInfo, rv reflect.Value) { - fastpathETMsgpackIO{}.EncMapUint64IntfV(rv2i(rv).(map[uint64]interface{}), e) -} -func (fastpathETMsgpackIO) EncMapUint64IntfV(v map[uint64]interface{}, e *encoderMsgpackIO) { - if len(v) == 0 { - e.e.WriteMapEmpty() - return - } - var i uint - e.mapStart(len(v)) - if e.h.Canonical { - v2 := make([]uint64, len(v)) - for k := range v { - v2[i] = k - i++ - } - slices.Sort(v2) - for i, k2 := range v2 { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeUint(k2) - e.mapElemValue() - if !e.encodeBuiltin(v[k2]) { - e.encodeR(reflect.ValueOf(v[k2])) - } - } - } else { - i = 0 - for k2, v2 := range v { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeUint(k2) - e.mapElemValue() - if !e.encodeBuiltin(v2) { - e.encodeR(reflect.ValueOf(v2)) - } - i++ - } - } - e.c = 0 - e.e.WriteMapEnd() -} -func (e *encoderMsgpackIO) fastpathEncMapUint64StringR(f *encFnInfo, rv reflect.Value) { - fastpathETMsgpackIO{}.EncMapUint64StringV(rv2i(rv).(map[uint64]string), e) -} -func (fastpathETMsgpackIO) EncMapUint64StringV(v map[uint64]string, e *encoderMsgpackIO) { - if len(v) == 0 { - e.e.WriteMapEmpty() - return - } - var i uint - e.mapStart(len(v)) - if e.h.Canonical { - v2 := make([]uint64, len(v)) - for k := range v { - v2[i] = k - i++ - } - slices.Sort(v2) - for i, k2 := range v2 { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeUint(k2) - e.mapElemValue() - e.e.EncodeString(v[k2]) - } - } else { - i = 0 - for k2, v2 := range v { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeUint(k2) - e.mapElemValue() - e.e.EncodeString(v2) - i++ - } - } - e.c = 0 - e.e.WriteMapEnd() -} -func (e *encoderMsgpackIO) fastpathEncMapUint64BytesR(f *encFnInfo, rv reflect.Value) { - fastpathETMsgpackIO{}.EncMapUint64BytesV(rv2i(rv).(map[uint64][]byte), e) -} -func (fastpathETMsgpackIO) EncMapUint64BytesV(v map[uint64][]byte, e *encoderMsgpackIO) { - if len(v) == 0 { - e.e.WriteMapEmpty() - return - } - var i uint - e.mapStart(len(v)) - if e.h.Canonical { - v2 := make([]uint64, len(v)) - for k := range v { - v2[i] = k - i++ - } - slices.Sort(v2) - for i, k2 := range v2 { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeUint(k2) - e.mapElemValue() - e.e.EncodeBytes(v[k2]) - } - } else { - i = 0 - for k2, v2 := range v { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeUint(k2) - e.mapElemValue() - e.e.EncodeBytes(v2) - i++ - } - } - e.c = 0 - e.e.WriteMapEnd() -} -func (e *encoderMsgpackIO) fastpathEncMapUint64Uint8R(f *encFnInfo, rv reflect.Value) { - fastpathETMsgpackIO{}.EncMapUint64Uint8V(rv2i(rv).(map[uint64]uint8), e) -} -func (fastpathETMsgpackIO) EncMapUint64Uint8V(v map[uint64]uint8, e *encoderMsgpackIO) { - if len(v) == 0 { - e.e.WriteMapEmpty() - return - } - var i uint - e.mapStart(len(v)) - if e.h.Canonical { - v2 := make([]uint64, len(v)) - for k := range v { - v2[i] = k - i++ - } - slices.Sort(v2) - for i, k2 := range v2 { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeUint(k2) - e.mapElemValue() - e.e.EncodeUint(uint64(v[k2])) - } - } else { - i = 0 - for k2, v2 := range v { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeUint(k2) - e.mapElemValue() - e.e.EncodeUint(uint64(v2)) - i++ - } - } - e.c = 0 - e.e.WriteMapEnd() -} -func (e *encoderMsgpackIO) fastpathEncMapUint64Uint64R(f *encFnInfo, rv reflect.Value) { - fastpathETMsgpackIO{}.EncMapUint64Uint64V(rv2i(rv).(map[uint64]uint64), e) -} -func (fastpathETMsgpackIO) EncMapUint64Uint64V(v map[uint64]uint64, e *encoderMsgpackIO) { - if len(v) == 0 { - e.e.WriteMapEmpty() - return - } - var i uint - e.mapStart(len(v)) - if e.h.Canonical { - v2 := make([]uint64, len(v)) - for k := range v { - v2[i] = k - i++ - } - slices.Sort(v2) - for i, k2 := range v2 { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeUint(k2) - e.mapElemValue() - e.e.EncodeUint(v[k2]) - } - } else { - i = 0 - for k2, v2 := range v { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeUint(k2) - e.mapElemValue() - e.e.EncodeUint(v2) - i++ - } - } - e.c = 0 - e.e.WriteMapEnd() -} -func (e *encoderMsgpackIO) fastpathEncMapUint64IntR(f *encFnInfo, rv reflect.Value) { - fastpathETMsgpackIO{}.EncMapUint64IntV(rv2i(rv).(map[uint64]int), e) -} -func (fastpathETMsgpackIO) EncMapUint64IntV(v map[uint64]int, e *encoderMsgpackIO) { - if len(v) == 0 { - e.e.WriteMapEmpty() - return - } - var i uint - e.mapStart(len(v)) - if e.h.Canonical { - v2 := make([]uint64, len(v)) - for k := range v { - v2[i] = k - i++ - } - slices.Sort(v2) - for i, k2 := range v2 { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeUint(k2) - e.mapElemValue() - e.e.EncodeInt(int64(v[k2])) - } - } else { - i = 0 - for k2, v2 := range v { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeUint(k2) - e.mapElemValue() - e.e.EncodeInt(int64(v2)) - i++ - } - } - e.c = 0 - e.e.WriteMapEnd() -} -func (e *encoderMsgpackIO) fastpathEncMapUint64Int32R(f *encFnInfo, rv reflect.Value) { - fastpathETMsgpackIO{}.EncMapUint64Int32V(rv2i(rv).(map[uint64]int32), e) -} -func (fastpathETMsgpackIO) EncMapUint64Int32V(v map[uint64]int32, e *encoderMsgpackIO) { - if len(v) == 0 { - e.e.WriteMapEmpty() - return - } - var i uint - e.mapStart(len(v)) - if e.h.Canonical { - v2 := make([]uint64, len(v)) - for k := range v { - v2[i] = k - i++ - } - slices.Sort(v2) - for i, k2 := range v2 { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeUint(k2) - e.mapElemValue() - e.e.EncodeInt(int64(v[k2])) - } - } else { - i = 0 - for k2, v2 := range v { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeUint(k2) - e.mapElemValue() - e.e.EncodeInt(int64(v2)) - i++ - } - } - e.c = 0 - e.e.WriteMapEnd() -} -func (e *encoderMsgpackIO) fastpathEncMapUint64Float64R(f *encFnInfo, rv reflect.Value) { - fastpathETMsgpackIO{}.EncMapUint64Float64V(rv2i(rv).(map[uint64]float64), e) -} -func (fastpathETMsgpackIO) EncMapUint64Float64V(v map[uint64]float64, e *encoderMsgpackIO) { - if len(v) == 0 { - e.e.WriteMapEmpty() - return - } - var i uint - e.mapStart(len(v)) - if e.h.Canonical { - v2 := make([]uint64, len(v)) - for k := range v { - v2[i] = k - i++ - } - slices.Sort(v2) - for i, k2 := range v2 { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeUint(k2) - e.mapElemValue() - e.e.EncodeFloat64(v[k2]) - } - } else { - i = 0 - for k2, v2 := range v { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeUint(k2) - e.mapElemValue() - e.e.EncodeFloat64(v2) - i++ - } - } - e.c = 0 - e.e.WriteMapEnd() -} -func (e *encoderMsgpackIO) fastpathEncMapUint64BoolR(f *encFnInfo, rv reflect.Value) { - fastpathETMsgpackIO{}.EncMapUint64BoolV(rv2i(rv).(map[uint64]bool), e) -} -func (fastpathETMsgpackIO) EncMapUint64BoolV(v map[uint64]bool, e *encoderMsgpackIO) { - if len(v) == 0 { - e.e.WriteMapEmpty() - return - } - var i uint - e.mapStart(len(v)) - if e.h.Canonical { - v2 := make([]uint64, len(v)) - for k := range v { - v2[i] = k - i++ - } - slices.Sort(v2) - for i, k2 := range v2 { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeUint(k2) - e.mapElemValue() - e.e.EncodeBool(v[k2]) - } - } else { - i = 0 - for k2, v2 := range v { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeUint(k2) - e.mapElemValue() - e.e.EncodeBool(v2) - i++ - } - } - e.c = 0 - e.e.WriteMapEnd() -} -func (e *encoderMsgpackIO) fastpathEncMapIntIntfR(f *encFnInfo, rv reflect.Value) { - fastpathETMsgpackIO{}.EncMapIntIntfV(rv2i(rv).(map[int]interface{}), e) -} -func (fastpathETMsgpackIO) EncMapIntIntfV(v map[int]interface{}, e *encoderMsgpackIO) { - if len(v) == 0 { - e.e.WriteMapEmpty() - return - } - var i uint - e.mapStart(len(v)) - if e.h.Canonical { - v2 := make([]int, len(v)) - for k := range v { - v2[i] = k - i++ - } - slices.Sort(v2) - for i, k2 := range v2 { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeInt(int64(k2)) - e.mapElemValue() - if !e.encodeBuiltin(v[k2]) { - e.encodeR(reflect.ValueOf(v[k2])) - } - } - } else { - i = 0 - for k2, v2 := range v { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeInt(int64(k2)) - e.mapElemValue() - if !e.encodeBuiltin(v2) { - e.encodeR(reflect.ValueOf(v2)) - } - i++ - } - } - e.c = 0 - e.e.WriteMapEnd() -} -func (e *encoderMsgpackIO) fastpathEncMapIntStringR(f *encFnInfo, rv reflect.Value) { - fastpathETMsgpackIO{}.EncMapIntStringV(rv2i(rv).(map[int]string), e) -} -func (fastpathETMsgpackIO) EncMapIntStringV(v map[int]string, e *encoderMsgpackIO) { - if len(v) == 0 { - e.e.WriteMapEmpty() - return - } - var i uint - e.mapStart(len(v)) - if e.h.Canonical { - v2 := make([]int, len(v)) - for k := range v { - v2[i] = k - i++ - } - slices.Sort(v2) - for i, k2 := range v2 { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeInt(int64(k2)) - e.mapElemValue() - e.e.EncodeString(v[k2]) - } - } else { - i = 0 - for k2, v2 := range v { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeInt(int64(k2)) - e.mapElemValue() - e.e.EncodeString(v2) - i++ - } - } - e.c = 0 - e.e.WriteMapEnd() -} -func (e *encoderMsgpackIO) fastpathEncMapIntBytesR(f *encFnInfo, rv reflect.Value) { - fastpathETMsgpackIO{}.EncMapIntBytesV(rv2i(rv).(map[int][]byte), e) -} -func (fastpathETMsgpackIO) EncMapIntBytesV(v map[int][]byte, e *encoderMsgpackIO) { - if len(v) == 0 { - e.e.WriteMapEmpty() - return - } - var i uint - e.mapStart(len(v)) - if e.h.Canonical { - v2 := make([]int, len(v)) - for k := range v { - v2[i] = k - i++ - } - slices.Sort(v2) - for i, k2 := range v2 { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeInt(int64(k2)) - e.mapElemValue() - e.e.EncodeBytes(v[k2]) - } - } else { - i = 0 - for k2, v2 := range v { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeInt(int64(k2)) - e.mapElemValue() - e.e.EncodeBytes(v2) - i++ - } - } - e.c = 0 - e.e.WriteMapEnd() -} -func (e *encoderMsgpackIO) fastpathEncMapIntUint8R(f *encFnInfo, rv reflect.Value) { - fastpathETMsgpackIO{}.EncMapIntUint8V(rv2i(rv).(map[int]uint8), e) -} -func (fastpathETMsgpackIO) EncMapIntUint8V(v map[int]uint8, e *encoderMsgpackIO) { - if len(v) == 0 { - e.e.WriteMapEmpty() - return - } - var i uint - e.mapStart(len(v)) - if e.h.Canonical { - v2 := make([]int, len(v)) - for k := range v { - v2[i] = k - i++ - } - slices.Sort(v2) - for i, k2 := range v2 { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeInt(int64(k2)) - e.mapElemValue() - e.e.EncodeUint(uint64(v[k2])) - } - } else { - i = 0 - for k2, v2 := range v { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeInt(int64(k2)) - e.mapElemValue() - e.e.EncodeUint(uint64(v2)) - i++ - } - } - e.c = 0 - e.e.WriteMapEnd() -} -func (e *encoderMsgpackIO) fastpathEncMapIntUint64R(f *encFnInfo, rv reflect.Value) { - fastpathETMsgpackIO{}.EncMapIntUint64V(rv2i(rv).(map[int]uint64), e) -} -func (fastpathETMsgpackIO) EncMapIntUint64V(v map[int]uint64, e *encoderMsgpackIO) { - if len(v) == 0 { - e.e.WriteMapEmpty() - return - } - var i uint - e.mapStart(len(v)) - if e.h.Canonical { - v2 := make([]int, len(v)) - for k := range v { - v2[i] = k - i++ - } - slices.Sort(v2) - for i, k2 := range v2 { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeInt(int64(k2)) - e.mapElemValue() - e.e.EncodeUint(v[k2]) - } - } else { - i = 0 - for k2, v2 := range v { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeInt(int64(k2)) - e.mapElemValue() - e.e.EncodeUint(v2) - i++ - } - } - e.c = 0 - e.e.WriteMapEnd() -} -func (e *encoderMsgpackIO) fastpathEncMapIntIntR(f *encFnInfo, rv reflect.Value) { - fastpathETMsgpackIO{}.EncMapIntIntV(rv2i(rv).(map[int]int), e) -} -func (fastpathETMsgpackIO) EncMapIntIntV(v map[int]int, e *encoderMsgpackIO) { - if len(v) == 0 { - e.e.WriteMapEmpty() - return - } - var i uint - e.mapStart(len(v)) - if e.h.Canonical { - v2 := make([]int, len(v)) - for k := range v { - v2[i] = k - i++ - } - slices.Sort(v2) - for i, k2 := range v2 { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeInt(int64(k2)) - e.mapElemValue() - e.e.EncodeInt(int64(v[k2])) - } - } else { - i = 0 - for k2, v2 := range v { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeInt(int64(k2)) - e.mapElemValue() - e.e.EncodeInt(int64(v2)) - i++ - } - } - e.c = 0 - e.e.WriteMapEnd() -} -func (e *encoderMsgpackIO) fastpathEncMapIntInt32R(f *encFnInfo, rv reflect.Value) { - fastpathETMsgpackIO{}.EncMapIntInt32V(rv2i(rv).(map[int]int32), e) -} -func (fastpathETMsgpackIO) EncMapIntInt32V(v map[int]int32, e *encoderMsgpackIO) { - if len(v) == 0 { - e.e.WriteMapEmpty() - return - } - var i uint - e.mapStart(len(v)) - if e.h.Canonical { - v2 := make([]int, len(v)) - for k := range v { - v2[i] = k - i++ - } - slices.Sort(v2) - for i, k2 := range v2 { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeInt(int64(k2)) - e.mapElemValue() - e.e.EncodeInt(int64(v[k2])) - } - } else { - i = 0 - for k2, v2 := range v { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeInt(int64(k2)) - e.mapElemValue() - e.e.EncodeInt(int64(v2)) - i++ - } - } - e.c = 0 - e.e.WriteMapEnd() -} -func (e *encoderMsgpackIO) fastpathEncMapIntFloat64R(f *encFnInfo, rv reflect.Value) { - fastpathETMsgpackIO{}.EncMapIntFloat64V(rv2i(rv).(map[int]float64), e) -} -func (fastpathETMsgpackIO) EncMapIntFloat64V(v map[int]float64, e *encoderMsgpackIO) { - if len(v) == 0 { - e.e.WriteMapEmpty() - return - } - var i uint - e.mapStart(len(v)) - if e.h.Canonical { - v2 := make([]int, len(v)) - for k := range v { - v2[i] = k - i++ - } - slices.Sort(v2) - for i, k2 := range v2 { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeInt(int64(k2)) - e.mapElemValue() - e.e.EncodeFloat64(v[k2]) - } - } else { - i = 0 - for k2, v2 := range v { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeInt(int64(k2)) - e.mapElemValue() - e.e.EncodeFloat64(v2) - i++ - } - } - e.c = 0 - e.e.WriteMapEnd() -} -func (e *encoderMsgpackIO) fastpathEncMapIntBoolR(f *encFnInfo, rv reflect.Value) { - fastpathETMsgpackIO{}.EncMapIntBoolV(rv2i(rv).(map[int]bool), e) -} -func (fastpathETMsgpackIO) EncMapIntBoolV(v map[int]bool, e *encoderMsgpackIO) { - if len(v) == 0 { - e.e.WriteMapEmpty() - return - } - var i uint - e.mapStart(len(v)) - if e.h.Canonical { - v2 := make([]int, len(v)) - for k := range v { - v2[i] = k - i++ - } - slices.Sort(v2) - for i, k2 := range v2 { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeInt(int64(k2)) - e.mapElemValue() - e.e.EncodeBool(v[k2]) - } - } else { - i = 0 - for k2, v2 := range v { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeInt(int64(k2)) - e.mapElemValue() - e.e.EncodeBool(v2) - i++ - } - } - e.c = 0 - e.e.WriteMapEnd() -} -func (e *encoderMsgpackIO) fastpathEncMapInt32IntfR(f *encFnInfo, rv reflect.Value) { - fastpathETMsgpackIO{}.EncMapInt32IntfV(rv2i(rv).(map[int32]interface{}), e) -} -func (fastpathETMsgpackIO) EncMapInt32IntfV(v map[int32]interface{}, e *encoderMsgpackIO) { - if len(v) == 0 { - e.e.WriteMapEmpty() - return - } - var i uint - e.mapStart(len(v)) - if e.h.Canonical { - v2 := make([]int32, len(v)) - for k := range v { - v2[i] = k - i++ - } - slices.Sort(v2) - for i, k2 := range v2 { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeInt(int64(k2)) - e.mapElemValue() - if !e.encodeBuiltin(v[k2]) { - e.encodeR(reflect.ValueOf(v[k2])) - } - } - } else { - i = 0 - for k2, v2 := range v { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeInt(int64(k2)) - e.mapElemValue() - if !e.encodeBuiltin(v2) { - e.encodeR(reflect.ValueOf(v2)) - } - i++ - } - } - e.c = 0 - e.e.WriteMapEnd() -} -func (e *encoderMsgpackIO) fastpathEncMapInt32StringR(f *encFnInfo, rv reflect.Value) { - fastpathETMsgpackIO{}.EncMapInt32StringV(rv2i(rv).(map[int32]string), e) -} -func (fastpathETMsgpackIO) EncMapInt32StringV(v map[int32]string, e *encoderMsgpackIO) { - if len(v) == 0 { - e.e.WriteMapEmpty() - return - } - var i uint - e.mapStart(len(v)) - if e.h.Canonical { - v2 := make([]int32, len(v)) - for k := range v { - v2[i] = k - i++ - } - slices.Sort(v2) - for i, k2 := range v2 { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeInt(int64(k2)) - e.mapElemValue() - e.e.EncodeString(v[k2]) - } - } else { - i = 0 - for k2, v2 := range v { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeInt(int64(k2)) - e.mapElemValue() - e.e.EncodeString(v2) - i++ - } - } - e.c = 0 - e.e.WriteMapEnd() -} -func (e *encoderMsgpackIO) fastpathEncMapInt32BytesR(f *encFnInfo, rv reflect.Value) { - fastpathETMsgpackIO{}.EncMapInt32BytesV(rv2i(rv).(map[int32][]byte), e) -} -func (fastpathETMsgpackIO) EncMapInt32BytesV(v map[int32][]byte, e *encoderMsgpackIO) { - if len(v) == 0 { - e.e.WriteMapEmpty() - return - } - var i uint - e.mapStart(len(v)) - if e.h.Canonical { - v2 := make([]int32, len(v)) - for k := range v { - v2[i] = k - i++ - } - slices.Sort(v2) - for i, k2 := range v2 { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeInt(int64(k2)) - e.mapElemValue() - e.e.EncodeBytes(v[k2]) - } - } else { - i = 0 - for k2, v2 := range v { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeInt(int64(k2)) - e.mapElemValue() - e.e.EncodeBytes(v2) - i++ - } - } - e.c = 0 - e.e.WriteMapEnd() -} -func (e *encoderMsgpackIO) fastpathEncMapInt32Uint8R(f *encFnInfo, rv reflect.Value) { - fastpathETMsgpackIO{}.EncMapInt32Uint8V(rv2i(rv).(map[int32]uint8), e) -} -func (fastpathETMsgpackIO) EncMapInt32Uint8V(v map[int32]uint8, e *encoderMsgpackIO) { - if len(v) == 0 { - e.e.WriteMapEmpty() - return - } - var i uint - e.mapStart(len(v)) - if e.h.Canonical { - v2 := make([]int32, len(v)) - for k := range v { - v2[i] = k - i++ - } - slices.Sort(v2) - for i, k2 := range v2 { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeInt(int64(k2)) - e.mapElemValue() - e.e.EncodeUint(uint64(v[k2])) - } - } else { - i = 0 - for k2, v2 := range v { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeInt(int64(k2)) - e.mapElemValue() - e.e.EncodeUint(uint64(v2)) - i++ - } - } - e.c = 0 - e.e.WriteMapEnd() -} -func (e *encoderMsgpackIO) fastpathEncMapInt32Uint64R(f *encFnInfo, rv reflect.Value) { - fastpathETMsgpackIO{}.EncMapInt32Uint64V(rv2i(rv).(map[int32]uint64), e) -} -func (fastpathETMsgpackIO) EncMapInt32Uint64V(v map[int32]uint64, e *encoderMsgpackIO) { - if len(v) == 0 { - e.e.WriteMapEmpty() - return - } - var i uint - e.mapStart(len(v)) - if e.h.Canonical { - v2 := make([]int32, len(v)) - for k := range v { - v2[i] = k - i++ - } - slices.Sort(v2) - for i, k2 := range v2 { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeInt(int64(k2)) - e.mapElemValue() - e.e.EncodeUint(v[k2]) - } - } else { - i = 0 - for k2, v2 := range v { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeInt(int64(k2)) - e.mapElemValue() - e.e.EncodeUint(v2) - i++ - } - } - e.c = 0 - e.e.WriteMapEnd() -} -func (e *encoderMsgpackIO) fastpathEncMapInt32IntR(f *encFnInfo, rv reflect.Value) { - fastpathETMsgpackIO{}.EncMapInt32IntV(rv2i(rv).(map[int32]int), e) -} -func (fastpathETMsgpackIO) EncMapInt32IntV(v map[int32]int, e *encoderMsgpackIO) { - if len(v) == 0 { - e.e.WriteMapEmpty() - return - } - var i uint - e.mapStart(len(v)) - if e.h.Canonical { - v2 := make([]int32, len(v)) - for k := range v { - v2[i] = k - i++ - } - slices.Sort(v2) - for i, k2 := range v2 { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeInt(int64(k2)) - e.mapElemValue() - e.e.EncodeInt(int64(v[k2])) - } - } else { - i = 0 - for k2, v2 := range v { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeInt(int64(k2)) - e.mapElemValue() - e.e.EncodeInt(int64(v2)) - i++ - } - } - e.c = 0 - e.e.WriteMapEnd() -} -func (e *encoderMsgpackIO) fastpathEncMapInt32Int32R(f *encFnInfo, rv reflect.Value) { - fastpathETMsgpackIO{}.EncMapInt32Int32V(rv2i(rv).(map[int32]int32), e) -} -func (fastpathETMsgpackIO) EncMapInt32Int32V(v map[int32]int32, e *encoderMsgpackIO) { - if len(v) == 0 { - e.e.WriteMapEmpty() - return - } - var i uint - e.mapStart(len(v)) - if e.h.Canonical { - v2 := make([]int32, len(v)) - for k := range v { - v2[i] = k - i++ - } - slices.Sort(v2) - for i, k2 := range v2 { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeInt(int64(k2)) - e.mapElemValue() - e.e.EncodeInt(int64(v[k2])) - } - } else { - i = 0 - for k2, v2 := range v { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeInt(int64(k2)) - e.mapElemValue() - e.e.EncodeInt(int64(v2)) - i++ - } - } - e.c = 0 - e.e.WriteMapEnd() -} -func (e *encoderMsgpackIO) fastpathEncMapInt32Float64R(f *encFnInfo, rv reflect.Value) { - fastpathETMsgpackIO{}.EncMapInt32Float64V(rv2i(rv).(map[int32]float64), e) -} -func (fastpathETMsgpackIO) EncMapInt32Float64V(v map[int32]float64, e *encoderMsgpackIO) { - if len(v) == 0 { - e.e.WriteMapEmpty() - return - } - var i uint - e.mapStart(len(v)) - if e.h.Canonical { - v2 := make([]int32, len(v)) - for k := range v { - v2[i] = k - i++ - } - slices.Sort(v2) - for i, k2 := range v2 { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeInt(int64(k2)) - e.mapElemValue() - e.e.EncodeFloat64(v[k2]) - } - } else { - i = 0 - for k2, v2 := range v { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeInt(int64(k2)) - e.mapElemValue() - e.e.EncodeFloat64(v2) - i++ - } - } - e.c = 0 - e.e.WriteMapEnd() -} -func (e *encoderMsgpackIO) fastpathEncMapInt32BoolR(f *encFnInfo, rv reflect.Value) { - fastpathETMsgpackIO{}.EncMapInt32BoolV(rv2i(rv).(map[int32]bool), e) -} -func (fastpathETMsgpackIO) EncMapInt32BoolV(v map[int32]bool, e *encoderMsgpackIO) { - if len(v) == 0 { - e.e.WriteMapEmpty() - return - } - var i uint - e.mapStart(len(v)) - if e.h.Canonical { - v2 := make([]int32, len(v)) - for k := range v { - v2[i] = k - i++ - } - slices.Sort(v2) - for i, k2 := range v2 { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeInt(int64(k2)) - e.mapElemValue() - e.e.EncodeBool(v[k2]) - } - } else { - i = 0 - for k2, v2 := range v { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeInt(int64(k2)) - e.mapElemValue() - e.e.EncodeBool(v2) - i++ - } - } - e.c = 0 - e.e.WriteMapEnd() -} - -func (helperDecDriverMsgpackIO) fastpathDecodeTypeSwitch(iv interface{}, d *decoderMsgpackIO) bool { - var ft fastpathDTMsgpackIO - var changed bool - var containerLen int - switch v := iv.(type) { - case []interface{}: - ft.DecSliceIntfN(v, d) - case *[]interface{}: - var v2 []interface{} - if v2, changed = ft.DecSliceIntfY(*v, d); changed { - *v = v2 - } - case []string: - ft.DecSliceStringN(v, d) - case *[]string: - var v2 []string - if v2, changed = ft.DecSliceStringY(*v, d); changed { - *v = v2 - } - case [][]byte: - ft.DecSliceBytesN(v, d) - case *[][]byte: - var v2 [][]byte - if v2, changed = ft.DecSliceBytesY(*v, d); changed { - *v = v2 - } - case []float32: - ft.DecSliceFloat32N(v, d) - case *[]float32: - var v2 []float32 - if v2, changed = ft.DecSliceFloat32Y(*v, d); changed { - *v = v2 - } - case []float64: - ft.DecSliceFloat64N(v, d) - case *[]float64: - var v2 []float64 - if v2, changed = ft.DecSliceFloat64Y(*v, d); changed { - *v = v2 - } - case []uint8: - ft.DecSliceUint8N(v, d) - case *[]uint8: - var v2 []uint8 - if v2, changed = ft.DecSliceUint8Y(*v, d); changed { - *v = v2 - } - case []uint64: - ft.DecSliceUint64N(v, d) - case *[]uint64: - var v2 []uint64 - if v2, changed = ft.DecSliceUint64Y(*v, d); changed { - *v = v2 - } - case []int: - ft.DecSliceIntN(v, d) - case *[]int: - var v2 []int - if v2, changed = ft.DecSliceIntY(*v, d); changed { - *v = v2 - } - case []int32: - ft.DecSliceInt32N(v, d) - case *[]int32: - var v2 []int32 - if v2, changed = ft.DecSliceInt32Y(*v, d); changed { - *v = v2 - } - case []int64: - ft.DecSliceInt64N(v, d) - case *[]int64: - var v2 []int64 - if v2, changed = ft.DecSliceInt64Y(*v, d); changed { - *v = v2 - } - case []bool: - ft.DecSliceBoolN(v, d) - case *[]bool: - var v2 []bool - if v2, changed = ft.DecSliceBoolY(*v, d); changed { - *v = v2 - } - case map[string]interface{}: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen != containerLenNil { - if containerLen != 0 { - ft.DecMapStringIntfL(v, containerLen, d) - } - d.mapEnd() - } - case *map[string]interface{}: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen == containerLenNil { - *v = nil - } else { - if *v == nil { - *v = make(map[string]interface{}, decInferLen(containerLen, d.maxInitLen(), 32)) - } - if containerLen != 0 { - ft.DecMapStringIntfL(*v, containerLen, d) - } - d.mapEnd() - } - case map[string]string: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen != containerLenNil { - if containerLen != 0 { - ft.DecMapStringStringL(v, containerLen, d) - } - d.mapEnd() - } - case *map[string]string: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen == containerLenNil { - *v = nil - } else { - if *v == nil { - *v = make(map[string]string, decInferLen(containerLen, d.maxInitLen(), 32)) - } - if containerLen != 0 { - ft.DecMapStringStringL(*v, containerLen, d) - } - d.mapEnd() - } - case map[string][]byte: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen != containerLenNil { - if containerLen != 0 { - ft.DecMapStringBytesL(v, containerLen, d) - } - d.mapEnd() - } - case *map[string][]byte: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen == containerLenNil { - *v = nil - } else { - if *v == nil { - *v = make(map[string][]byte, decInferLen(containerLen, d.maxInitLen(), 40)) - } - if containerLen != 0 { - ft.DecMapStringBytesL(*v, containerLen, d) - } - d.mapEnd() - } - case map[string]uint8: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen != containerLenNil { - if containerLen != 0 { - ft.DecMapStringUint8L(v, containerLen, d) - } - d.mapEnd() - } - case *map[string]uint8: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen == containerLenNil { - *v = nil - } else { - if *v == nil { - *v = make(map[string]uint8, decInferLen(containerLen, d.maxInitLen(), 17)) - } - if containerLen != 0 { - ft.DecMapStringUint8L(*v, containerLen, d) - } - d.mapEnd() - } - case map[string]uint64: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen != containerLenNil { - if containerLen != 0 { - ft.DecMapStringUint64L(v, containerLen, d) - } - d.mapEnd() - } - case *map[string]uint64: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen == containerLenNil { - *v = nil - } else { - if *v == nil { - *v = make(map[string]uint64, decInferLen(containerLen, d.maxInitLen(), 24)) - } - if containerLen != 0 { - ft.DecMapStringUint64L(*v, containerLen, d) - } - d.mapEnd() - } - case map[string]int: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen != containerLenNil { - if containerLen != 0 { - ft.DecMapStringIntL(v, containerLen, d) - } - d.mapEnd() - } - case *map[string]int: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen == containerLenNil { - *v = nil - } else { - if *v == nil { - *v = make(map[string]int, decInferLen(containerLen, d.maxInitLen(), 24)) - } - if containerLen != 0 { - ft.DecMapStringIntL(*v, containerLen, d) - } - d.mapEnd() - } - case map[string]int32: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen != containerLenNil { - if containerLen != 0 { - ft.DecMapStringInt32L(v, containerLen, d) - } - d.mapEnd() - } - case *map[string]int32: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen == containerLenNil { - *v = nil - } else { - if *v == nil { - *v = make(map[string]int32, decInferLen(containerLen, d.maxInitLen(), 20)) - } - if containerLen != 0 { - ft.DecMapStringInt32L(*v, containerLen, d) - } - d.mapEnd() - } - case map[string]float64: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen != containerLenNil { - if containerLen != 0 { - ft.DecMapStringFloat64L(v, containerLen, d) - } - d.mapEnd() - } - case *map[string]float64: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen == containerLenNil { - *v = nil - } else { - if *v == nil { - *v = make(map[string]float64, decInferLen(containerLen, d.maxInitLen(), 24)) - } - if containerLen != 0 { - ft.DecMapStringFloat64L(*v, containerLen, d) - } - d.mapEnd() - } - case map[string]bool: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen != containerLenNil { - if containerLen != 0 { - ft.DecMapStringBoolL(v, containerLen, d) - } - d.mapEnd() - } - case *map[string]bool: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen == containerLenNil { - *v = nil - } else { - if *v == nil { - *v = make(map[string]bool, decInferLen(containerLen, d.maxInitLen(), 17)) - } - if containerLen != 0 { - ft.DecMapStringBoolL(*v, containerLen, d) - } - d.mapEnd() - } - case map[uint8]interface{}: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen != containerLenNil { - if containerLen != 0 { - ft.DecMapUint8IntfL(v, containerLen, d) - } - d.mapEnd() - } - case *map[uint8]interface{}: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen == containerLenNil { - *v = nil - } else { - if *v == nil { - *v = make(map[uint8]interface{}, decInferLen(containerLen, d.maxInitLen(), 17)) - } - if containerLen != 0 { - ft.DecMapUint8IntfL(*v, containerLen, d) - } - d.mapEnd() - } - case map[uint8]string: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen != containerLenNil { - if containerLen != 0 { - ft.DecMapUint8StringL(v, containerLen, d) - } - d.mapEnd() - } - case *map[uint8]string: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen == containerLenNil { - *v = nil - } else { - if *v == nil { - *v = make(map[uint8]string, decInferLen(containerLen, d.maxInitLen(), 17)) - } - if containerLen != 0 { - ft.DecMapUint8StringL(*v, containerLen, d) - } - d.mapEnd() - } - case map[uint8][]byte: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen != containerLenNil { - if containerLen != 0 { - ft.DecMapUint8BytesL(v, containerLen, d) - } - d.mapEnd() - } - case *map[uint8][]byte: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen == containerLenNil { - *v = nil - } else { - if *v == nil { - *v = make(map[uint8][]byte, decInferLen(containerLen, d.maxInitLen(), 25)) - } - if containerLen != 0 { - ft.DecMapUint8BytesL(*v, containerLen, d) - } - d.mapEnd() - } - case map[uint8]uint8: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen != containerLenNil { - if containerLen != 0 { - ft.DecMapUint8Uint8L(v, containerLen, d) - } - d.mapEnd() - } - case *map[uint8]uint8: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen == containerLenNil { - *v = nil - } else { - if *v == nil { - *v = make(map[uint8]uint8, decInferLen(containerLen, d.maxInitLen(), 2)) - } - if containerLen != 0 { - ft.DecMapUint8Uint8L(*v, containerLen, d) - } - d.mapEnd() - } - case map[uint8]uint64: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen != containerLenNil { - if containerLen != 0 { - ft.DecMapUint8Uint64L(v, containerLen, d) - } - d.mapEnd() - } - case *map[uint8]uint64: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen == containerLenNil { - *v = nil - } else { - if *v == nil { - *v = make(map[uint8]uint64, decInferLen(containerLen, d.maxInitLen(), 9)) - } - if containerLen != 0 { - ft.DecMapUint8Uint64L(*v, containerLen, d) - } - d.mapEnd() - } - case map[uint8]int: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen != containerLenNil { - if containerLen != 0 { - ft.DecMapUint8IntL(v, containerLen, d) - } - d.mapEnd() - } - case *map[uint8]int: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen == containerLenNil { - *v = nil - } else { - if *v == nil { - *v = make(map[uint8]int, decInferLen(containerLen, d.maxInitLen(), 9)) - } - if containerLen != 0 { - ft.DecMapUint8IntL(*v, containerLen, d) - } - d.mapEnd() - } - case map[uint8]int32: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen != containerLenNil { - if containerLen != 0 { - ft.DecMapUint8Int32L(v, containerLen, d) - } - d.mapEnd() - } - case *map[uint8]int32: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen == containerLenNil { - *v = nil - } else { - if *v == nil { - *v = make(map[uint8]int32, decInferLen(containerLen, d.maxInitLen(), 5)) - } - if containerLen != 0 { - ft.DecMapUint8Int32L(*v, containerLen, d) - } - d.mapEnd() - } - case map[uint8]float64: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen != containerLenNil { - if containerLen != 0 { - ft.DecMapUint8Float64L(v, containerLen, d) - } - d.mapEnd() - } - case *map[uint8]float64: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen == containerLenNil { - *v = nil - } else { - if *v == nil { - *v = make(map[uint8]float64, decInferLen(containerLen, d.maxInitLen(), 9)) - } - if containerLen != 0 { - ft.DecMapUint8Float64L(*v, containerLen, d) - } - d.mapEnd() - } - case map[uint8]bool: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen != containerLenNil { - if containerLen != 0 { - ft.DecMapUint8BoolL(v, containerLen, d) - } - d.mapEnd() - } - case *map[uint8]bool: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen == containerLenNil { - *v = nil - } else { - if *v == nil { - *v = make(map[uint8]bool, decInferLen(containerLen, d.maxInitLen(), 2)) - } - if containerLen != 0 { - ft.DecMapUint8BoolL(*v, containerLen, d) - } - d.mapEnd() - } - case map[uint64]interface{}: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen != containerLenNil { - if containerLen != 0 { - ft.DecMapUint64IntfL(v, containerLen, d) - } - d.mapEnd() - } - case *map[uint64]interface{}: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen == containerLenNil { - *v = nil - } else { - if *v == nil { - *v = make(map[uint64]interface{}, decInferLen(containerLen, d.maxInitLen(), 24)) - } - if containerLen != 0 { - ft.DecMapUint64IntfL(*v, containerLen, d) - } - d.mapEnd() - } - case map[uint64]string: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen != containerLenNil { - if containerLen != 0 { - ft.DecMapUint64StringL(v, containerLen, d) - } - d.mapEnd() - } - case *map[uint64]string: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen == containerLenNil { - *v = nil - } else { - if *v == nil { - *v = make(map[uint64]string, decInferLen(containerLen, d.maxInitLen(), 24)) - } - if containerLen != 0 { - ft.DecMapUint64StringL(*v, containerLen, d) - } - d.mapEnd() - } - case map[uint64][]byte: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen != containerLenNil { - if containerLen != 0 { - ft.DecMapUint64BytesL(v, containerLen, d) - } - d.mapEnd() - } - case *map[uint64][]byte: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen == containerLenNil { - *v = nil - } else { - if *v == nil { - *v = make(map[uint64][]byte, decInferLen(containerLen, d.maxInitLen(), 32)) - } - if containerLen != 0 { - ft.DecMapUint64BytesL(*v, containerLen, d) - } - d.mapEnd() - } - case map[uint64]uint8: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen != containerLenNil { - if containerLen != 0 { - ft.DecMapUint64Uint8L(v, containerLen, d) - } - d.mapEnd() - } - case *map[uint64]uint8: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen == containerLenNil { - *v = nil - } else { - if *v == nil { - *v = make(map[uint64]uint8, decInferLen(containerLen, d.maxInitLen(), 9)) - } - if containerLen != 0 { - ft.DecMapUint64Uint8L(*v, containerLen, d) - } - d.mapEnd() - } - case map[uint64]uint64: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen != containerLenNil { - if containerLen != 0 { - ft.DecMapUint64Uint64L(v, containerLen, d) - } - d.mapEnd() - } - case *map[uint64]uint64: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen == containerLenNil { - *v = nil - } else { - if *v == nil { - *v = make(map[uint64]uint64, decInferLen(containerLen, d.maxInitLen(), 16)) - } - if containerLen != 0 { - ft.DecMapUint64Uint64L(*v, containerLen, d) - } - d.mapEnd() - } - case map[uint64]int: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen != containerLenNil { - if containerLen != 0 { - ft.DecMapUint64IntL(v, containerLen, d) - } - d.mapEnd() - } - case *map[uint64]int: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen == containerLenNil { - *v = nil - } else { - if *v == nil { - *v = make(map[uint64]int, decInferLen(containerLen, d.maxInitLen(), 16)) - } - if containerLen != 0 { - ft.DecMapUint64IntL(*v, containerLen, d) - } - d.mapEnd() - } - case map[uint64]int32: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen != containerLenNil { - if containerLen != 0 { - ft.DecMapUint64Int32L(v, containerLen, d) - } - d.mapEnd() - } - case *map[uint64]int32: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen == containerLenNil { - *v = nil - } else { - if *v == nil { - *v = make(map[uint64]int32, decInferLen(containerLen, d.maxInitLen(), 12)) - } - if containerLen != 0 { - ft.DecMapUint64Int32L(*v, containerLen, d) - } - d.mapEnd() - } - case map[uint64]float64: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen != containerLenNil { - if containerLen != 0 { - ft.DecMapUint64Float64L(v, containerLen, d) - } - d.mapEnd() - } - case *map[uint64]float64: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen == containerLenNil { - *v = nil - } else { - if *v == nil { - *v = make(map[uint64]float64, decInferLen(containerLen, d.maxInitLen(), 16)) - } - if containerLen != 0 { - ft.DecMapUint64Float64L(*v, containerLen, d) - } - d.mapEnd() - } - case map[uint64]bool: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen != containerLenNil { - if containerLen != 0 { - ft.DecMapUint64BoolL(v, containerLen, d) - } - d.mapEnd() - } - case *map[uint64]bool: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen == containerLenNil { - *v = nil - } else { - if *v == nil { - *v = make(map[uint64]bool, decInferLen(containerLen, d.maxInitLen(), 9)) - } - if containerLen != 0 { - ft.DecMapUint64BoolL(*v, containerLen, d) - } - d.mapEnd() - } - case map[int]interface{}: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen != containerLenNil { - if containerLen != 0 { - ft.DecMapIntIntfL(v, containerLen, d) - } - d.mapEnd() - } - case *map[int]interface{}: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen == containerLenNil { - *v = nil - } else { - if *v == nil { - *v = make(map[int]interface{}, decInferLen(containerLen, d.maxInitLen(), 24)) - } - if containerLen != 0 { - ft.DecMapIntIntfL(*v, containerLen, d) - } - d.mapEnd() - } - case map[int]string: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen != containerLenNil { - if containerLen != 0 { - ft.DecMapIntStringL(v, containerLen, d) - } - d.mapEnd() - } - case *map[int]string: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen == containerLenNil { - *v = nil - } else { - if *v == nil { - *v = make(map[int]string, decInferLen(containerLen, d.maxInitLen(), 24)) - } - if containerLen != 0 { - ft.DecMapIntStringL(*v, containerLen, d) - } - d.mapEnd() - } - case map[int][]byte: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen != containerLenNil { - if containerLen != 0 { - ft.DecMapIntBytesL(v, containerLen, d) - } - d.mapEnd() - } - case *map[int][]byte: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen == containerLenNil { - *v = nil - } else { - if *v == nil { - *v = make(map[int][]byte, decInferLen(containerLen, d.maxInitLen(), 32)) - } - if containerLen != 0 { - ft.DecMapIntBytesL(*v, containerLen, d) - } - d.mapEnd() - } - case map[int]uint8: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen != containerLenNil { - if containerLen != 0 { - ft.DecMapIntUint8L(v, containerLen, d) - } - d.mapEnd() - } - case *map[int]uint8: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen == containerLenNil { - *v = nil - } else { - if *v == nil { - *v = make(map[int]uint8, decInferLen(containerLen, d.maxInitLen(), 9)) - } - if containerLen != 0 { - ft.DecMapIntUint8L(*v, containerLen, d) - } - d.mapEnd() - } - case map[int]uint64: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen != containerLenNil { - if containerLen != 0 { - ft.DecMapIntUint64L(v, containerLen, d) - } - d.mapEnd() - } - case *map[int]uint64: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen == containerLenNil { - *v = nil - } else { - if *v == nil { - *v = make(map[int]uint64, decInferLen(containerLen, d.maxInitLen(), 16)) - } - if containerLen != 0 { - ft.DecMapIntUint64L(*v, containerLen, d) - } - d.mapEnd() - } - case map[int]int: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen != containerLenNil { - if containerLen != 0 { - ft.DecMapIntIntL(v, containerLen, d) - } - d.mapEnd() - } - case *map[int]int: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen == containerLenNil { - *v = nil - } else { - if *v == nil { - *v = make(map[int]int, decInferLen(containerLen, d.maxInitLen(), 16)) - } - if containerLen != 0 { - ft.DecMapIntIntL(*v, containerLen, d) - } - d.mapEnd() - } - case map[int]int32: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen != containerLenNil { - if containerLen != 0 { - ft.DecMapIntInt32L(v, containerLen, d) - } - d.mapEnd() - } - case *map[int]int32: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen == containerLenNil { - *v = nil - } else { - if *v == nil { - *v = make(map[int]int32, decInferLen(containerLen, d.maxInitLen(), 12)) - } - if containerLen != 0 { - ft.DecMapIntInt32L(*v, containerLen, d) - } - d.mapEnd() - } - case map[int]float64: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen != containerLenNil { - if containerLen != 0 { - ft.DecMapIntFloat64L(v, containerLen, d) - } - d.mapEnd() - } - case *map[int]float64: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen == containerLenNil { - *v = nil - } else { - if *v == nil { - *v = make(map[int]float64, decInferLen(containerLen, d.maxInitLen(), 16)) - } - if containerLen != 0 { - ft.DecMapIntFloat64L(*v, containerLen, d) - } - d.mapEnd() - } - case map[int]bool: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen != containerLenNil { - if containerLen != 0 { - ft.DecMapIntBoolL(v, containerLen, d) - } - d.mapEnd() - } - case *map[int]bool: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen == containerLenNil { - *v = nil - } else { - if *v == nil { - *v = make(map[int]bool, decInferLen(containerLen, d.maxInitLen(), 9)) - } - if containerLen != 0 { - ft.DecMapIntBoolL(*v, containerLen, d) - } - d.mapEnd() - } - case map[int32]interface{}: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen != containerLenNil { - if containerLen != 0 { - ft.DecMapInt32IntfL(v, containerLen, d) - } - d.mapEnd() - } - case *map[int32]interface{}: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen == containerLenNil { - *v = nil - } else { - if *v == nil { - *v = make(map[int32]interface{}, decInferLen(containerLen, d.maxInitLen(), 20)) - } - if containerLen != 0 { - ft.DecMapInt32IntfL(*v, containerLen, d) - } - d.mapEnd() - } - case map[int32]string: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen != containerLenNil { - if containerLen != 0 { - ft.DecMapInt32StringL(v, containerLen, d) - } - d.mapEnd() - } - case *map[int32]string: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen == containerLenNil { - *v = nil - } else { - if *v == nil { - *v = make(map[int32]string, decInferLen(containerLen, d.maxInitLen(), 20)) - } - if containerLen != 0 { - ft.DecMapInt32StringL(*v, containerLen, d) - } - d.mapEnd() - } - case map[int32][]byte: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen != containerLenNil { - if containerLen != 0 { - ft.DecMapInt32BytesL(v, containerLen, d) - } - d.mapEnd() - } - case *map[int32][]byte: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen == containerLenNil { - *v = nil - } else { - if *v == nil { - *v = make(map[int32][]byte, decInferLen(containerLen, d.maxInitLen(), 28)) - } - if containerLen != 0 { - ft.DecMapInt32BytesL(*v, containerLen, d) - } - d.mapEnd() - } - case map[int32]uint8: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen != containerLenNil { - if containerLen != 0 { - ft.DecMapInt32Uint8L(v, containerLen, d) - } - d.mapEnd() - } - case *map[int32]uint8: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen == containerLenNil { - *v = nil - } else { - if *v == nil { - *v = make(map[int32]uint8, decInferLen(containerLen, d.maxInitLen(), 5)) - } - if containerLen != 0 { - ft.DecMapInt32Uint8L(*v, containerLen, d) - } - d.mapEnd() - } - case map[int32]uint64: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen != containerLenNil { - if containerLen != 0 { - ft.DecMapInt32Uint64L(v, containerLen, d) - } - d.mapEnd() - } - case *map[int32]uint64: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen == containerLenNil { - *v = nil - } else { - if *v == nil { - *v = make(map[int32]uint64, decInferLen(containerLen, d.maxInitLen(), 12)) - } - if containerLen != 0 { - ft.DecMapInt32Uint64L(*v, containerLen, d) - } - d.mapEnd() - } - case map[int32]int: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen != containerLenNil { - if containerLen != 0 { - ft.DecMapInt32IntL(v, containerLen, d) - } - d.mapEnd() - } - case *map[int32]int: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen == containerLenNil { - *v = nil - } else { - if *v == nil { - *v = make(map[int32]int, decInferLen(containerLen, d.maxInitLen(), 12)) - } - if containerLen != 0 { - ft.DecMapInt32IntL(*v, containerLen, d) - } - d.mapEnd() - } - case map[int32]int32: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen != containerLenNil { - if containerLen != 0 { - ft.DecMapInt32Int32L(v, containerLen, d) - } - d.mapEnd() - } - case *map[int32]int32: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen == containerLenNil { - *v = nil - } else { - if *v == nil { - *v = make(map[int32]int32, decInferLen(containerLen, d.maxInitLen(), 8)) - } - if containerLen != 0 { - ft.DecMapInt32Int32L(*v, containerLen, d) - } - d.mapEnd() - } - case map[int32]float64: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen != containerLenNil { - if containerLen != 0 { - ft.DecMapInt32Float64L(v, containerLen, d) - } - d.mapEnd() - } - case *map[int32]float64: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen == containerLenNil { - *v = nil - } else { - if *v == nil { - *v = make(map[int32]float64, decInferLen(containerLen, d.maxInitLen(), 12)) - } - if containerLen != 0 { - ft.DecMapInt32Float64L(*v, containerLen, d) - } - d.mapEnd() - } - case map[int32]bool: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen != containerLenNil { - if containerLen != 0 { - ft.DecMapInt32BoolL(v, containerLen, d) - } - d.mapEnd() - } - case *map[int32]bool: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen == containerLenNil { - *v = nil - } else { - if *v == nil { - *v = make(map[int32]bool, decInferLen(containerLen, d.maxInitLen(), 5)) - } - if containerLen != 0 { - ft.DecMapInt32BoolL(*v, containerLen, d) - } - d.mapEnd() - } - default: - _ = v - return false - } - return true -} - -func (d *decoderMsgpackIO) fastpathDecSliceIntfR(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTMsgpackIO - switch rv.Kind() { - case reflect.Ptr: - v := rv2i(rv).(*[]interface{}) - if vv, changed := ft.DecSliceIntfY(*v, d); changed { - *v = vv - } - case reflect.Array: - var v []interface{} - rvGetSlice4Array(rv, &v) - ft.DecSliceIntfN(v, d) - default: - ft.DecSliceIntfN(rv2i(rv).([]interface{}), d) - } -} -func (fastpathDTMsgpackIO) DecSliceIntfY(v []interface{}, d *decoderMsgpackIO) (v2 []interface{}, changed bool) { - ctyp := d.d.ContainerType() - if ctyp == valueTypeNil { - return nil, v != nil - } - var containerLenS int - isArray := ctyp == valueTypeArray - if isArray { - containerLenS = d.arrayStart(d.d.ReadArrayStart()) - } else if ctyp == valueTypeMap { - containerLenS = d.mapStart(d.d.ReadMapStart()) * 2 - } else { - halt.errorStr2("decoding into a slice, expect map/array - got ", ctyp.String()) - } - hasLen := containerLenS >= 0 - var j int - fnv := func(dst []interface{}) { v, changed = dst, true } - for ; d.containerNext(j, containerLenS, hasLen); j++ { - if j == 0 { - if containerLenS == len(v) { - } else if containerLenS < 0 || containerLenS > cap(v) { - if xlen := int(decInferLen(containerLenS, d.maxInitLen(), 16)); xlen <= cap(v) { - fnv(v[:uint(xlen)]) - } else { - v2 = make([]interface{}, uint(xlen)) - copy(v2, v) - fnv(v2) - } - } else { - fnv(v[:containerLenS]) - } - } - if isArray { - d.arrayElem(j == 0) - } else if j&1 == 0 { - d.mapElemKey(j == 0) - } else { - d.mapElemValue() - } - if j >= len(v) { - fnv(append(v, nil)) - } - d.decode(&v[uint(j)]) - } - if j < len(v) { - fnv(v[:uint(j)]) - } else if j == 0 && v == nil { - fnv([]interface{}{}) - } - if isArray { - d.arrayEnd() - } else { - d.mapEnd() - } - return v, changed -} -func (fastpathDTMsgpackIO) DecSliceIntfN(v []interface{}, d *decoderMsgpackIO) { - ctyp := d.d.ContainerType() - if ctyp == valueTypeNil { - return - } - var containerLenS int - isArray := ctyp == valueTypeArray - if isArray { - containerLenS = d.arrayStart(d.d.ReadArrayStart()) - } else if ctyp == valueTypeMap { - containerLenS = d.mapStart(d.d.ReadMapStart()) * 2 - } else { - halt.errorStr2("decoding into a slice, expect map/array - got ", ctyp.String()) - } - hasLen := containerLenS >= 0 - for j := 0; d.containerNext(j, containerLenS, hasLen); j++ { - if isArray { - d.arrayElem(j == 0) - } else if j&1 == 0 { - d.mapElemKey(j == 0) - } else { - d.mapElemValue() - } - if j < len(v) { - d.decode(&v[uint(j)]) - } else { - d.arrayCannotExpand(len(v), j+1) - d.swallow() - } - } - if isArray { - d.arrayEnd() - } else { - d.mapEnd() - } -} - -func (d *decoderMsgpackIO) fastpathDecSliceStringR(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTMsgpackIO - switch rv.Kind() { - case reflect.Ptr: - v := rv2i(rv).(*[]string) - if vv, changed := ft.DecSliceStringY(*v, d); changed { - *v = vv - } - case reflect.Array: - var v []string - rvGetSlice4Array(rv, &v) - ft.DecSliceStringN(v, d) - default: - ft.DecSliceStringN(rv2i(rv).([]string), d) - } -} -func (fastpathDTMsgpackIO) DecSliceStringY(v []string, d *decoderMsgpackIO) (v2 []string, changed bool) { - ctyp := d.d.ContainerType() - if ctyp == valueTypeNil { - return nil, v != nil - } - var containerLenS int - isArray := ctyp == valueTypeArray - if isArray { - containerLenS = d.arrayStart(d.d.ReadArrayStart()) - } else if ctyp == valueTypeMap { - containerLenS = d.mapStart(d.d.ReadMapStart()) * 2 - } else { - halt.errorStr2("decoding into a slice, expect map/array - got ", ctyp.String()) - } - hasLen := containerLenS >= 0 - var j int - fnv := func(dst []string) { v, changed = dst, true } - for ; d.containerNext(j, containerLenS, hasLen); j++ { - if j == 0 { - if containerLenS == len(v) { - } else if containerLenS < 0 || containerLenS > cap(v) { - if xlen := int(decInferLen(containerLenS, d.maxInitLen(), 16)); xlen <= cap(v) { - fnv(v[:uint(xlen)]) - } else { - v2 = make([]string, uint(xlen)) - copy(v2, v) - fnv(v2) - } - } else { - fnv(v[:containerLenS]) - } - } - if isArray { - d.arrayElem(j == 0) - } else if j&1 == 0 { - d.mapElemKey(j == 0) - } else { - d.mapElemValue() - } - if j >= len(v) { - fnv(append(v, "")) - } - v[uint(j)] = d.detach2Str(d.d.DecodeStringAsBytes()) - } - if j < len(v) { - fnv(v[:uint(j)]) - } else if j == 0 && v == nil { - fnv([]string{}) - } - if isArray { - d.arrayEnd() - } else { - d.mapEnd() - } - return v, changed -} -func (fastpathDTMsgpackIO) DecSliceStringN(v []string, d *decoderMsgpackIO) { - ctyp := d.d.ContainerType() - if ctyp == valueTypeNil { - return - } - var containerLenS int - isArray := ctyp == valueTypeArray - if isArray { - containerLenS = d.arrayStart(d.d.ReadArrayStart()) - } else if ctyp == valueTypeMap { - containerLenS = d.mapStart(d.d.ReadMapStart()) * 2 - } else { - halt.errorStr2("decoding into a slice, expect map/array - got ", ctyp.String()) - } - hasLen := containerLenS >= 0 - for j := 0; d.containerNext(j, containerLenS, hasLen); j++ { - if isArray { - d.arrayElem(j == 0) - } else if j&1 == 0 { - d.mapElemKey(j == 0) - } else { - d.mapElemValue() - } - if j < len(v) { - v[uint(j)] = d.detach2Str(d.d.DecodeStringAsBytes()) - } else { - d.arrayCannotExpand(len(v), j+1) - d.swallow() - } - } - if isArray { - d.arrayEnd() - } else { - d.mapEnd() - } -} - -func (d *decoderMsgpackIO) fastpathDecSliceBytesR(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTMsgpackIO - switch rv.Kind() { - case reflect.Ptr: - v := rv2i(rv).(*[][]byte) - if vv, changed := ft.DecSliceBytesY(*v, d); changed { - *v = vv - } - case reflect.Array: - var v [][]byte - rvGetSlice4Array(rv, &v) - ft.DecSliceBytesN(v, d) - default: - ft.DecSliceBytesN(rv2i(rv).([][]byte), d) - } -} -func (fastpathDTMsgpackIO) DecSliceBytesY(v [][]byte, d *decoderMsgpackIO) (v2 [][]byte, changed bool) { - ctyp := d.d.ContainerType() - if ctyp == valueTypeNil { - return nil, v != nil - } - var containerLenS int - isArray := ctyp == valueTypeArray - if isArray { - containerLenS = d.arrayStart(d.d.ReadArrayStart()) - } else if ctyp == valueTypeMap { - containerLenS = d.mapStart(d.d.ReadMapStart()) * 2 - } else { - halt.errorStr2("decoding into a slice, expect map/array - got ", ctyp.String()) - } - hasLen := containerLenS >= 0 - var j int - fnv := func(dst [][]byte) { v, changed = dst, true } - for ; d.containerNext(j, containerLenS, hasLen); j++ { - if j == 0 { - if containerLenS == len(v) { - } else if containerLenS < 0 || containerLenS > cap(v) { - if xlen := int(decInferLen(containerLenS, d.maxInitLen(), 24)); xlen <= cap(v) { - fnv(v[:uint(xlen)]) - } else { - v2 = make([][]byte, uint(xlen)) - copy(v2, v) - fnv(v2) - } - } else { - fnv(v[:containerLenS]) - } - } - if isArray { - d.arrayElem(j == 0) - } else if j&1 == 0 { - d.mapElemKey(j == 0) - } else { - d.mapElemValue() - } - if j >= len(v) { - fnv(append(v, nil)) - } - v[uint(j)] = bytesOKdbi(d.decodeBytesInto(v[uint(j)], false)) - } - if j < len(v) { - fnv(v[:uint(j)]) - } else if j == 0 && v == nil { - fnv([][]byte{}) - } - if isArray { - d.arrayEnd() - } else { - d.mapEnd() - } - return v, changed -} -func (fastpathDTMsgpackIO) DecSliceBytesN(v [][]byte, d *decoderMsgpackIO) { - ctyp := d.d.ContainerType() - if ctyp == valueTypeNil { - return - } - var containerLenS int - isArray := ctyp == valueTypeArray - if isArray { - containerLenS = d.arrayStart(d.d.ReadArrayStart()) - } else if ctyp == valueTypeMap { - containerLenS = d.mapStart(d.d.ReadMapStart()) * 2 - } else { - halt.errorStr2("decoding into a slice, expect map/array - got ", ctyp.String()) - } - hasLen := containerLenS >= 0 - for j := 0; d.containerNext(j, containerLenS, hasLen); j++ { - if isArray { - d.arrayElem(j == 0) - } else if j&1 == 0 { - d.mapElemKey(j == 0) - } else { - d.mapElemValue() - } - if j < len(v) { - v[uint(j)] = bytesOKdbi(d.decodeBytesInto(v[uint(j)], false)) - } else { - d.arrayCannotExpand(len(v), j+1) - d.swallow() - } - } - if isArray { - d.arrayEnd() - } else { - d.mapEnd() - } -} - -func (d *decoderMsgpackIO) fastpathDecSliceFloat32R(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTMsgpackIO - switch rv.Kind() { - case reflect.Ptr: - v := rv2i(rv).(*[]float32) - if vv, changed := ft.DecSliceFloat32Y(*v, d); changed { - *v = vv - } - case reflect.Array: - var v []float32 - rvGetSlice4Array(rv, &v) - ft.DecSliceFloat32N(v, d) - default: - ft.DecSliceFloat32N(rv2i(rv).([]float32), d) - } -} -func (fastpathDTMsgpackIO) DecSliceFloat32Y(v []float32, d *decoderMsgpackIO) (v2 []float32, changed bool) { - ctyp := d.d.ContainerType() - if ctyp == valueTypeNil { - return nil, v != nil - } - var containerLenS int - isArray := ctyp == valueTypeArray - if isArray { - containerLenS = d.arrayStart(d.d.ReadArrayStart()) - } else if ctyp == valueTypeMap { - containerLenS = d.mapStart(d.d.ReadMapStart()) * 2 - } else { - halt.errorStr2("decoding into a slice, expect map/array - got ", ctyp.String()) - } - hasLen := containerLenS >= 0 - var j int - fnv := func(dst []float32) { v, changed = dst, true } - for ; d.containerNext(j, containerLenS, hasLen); j++ { - if j == 0 { - if containerLenS == len(v) { - } else if containerLenS < 0 || containerLenS > cap(v) { - if xlen := int(decInferLen(containerLenS, d.maxInitLen(), 4)); xlen <= cap(v) { - fnv(v[:uint(xlen)]) - } else { - v2 = make([]float32, uint(xlen)) - copy(v2, v) - fnv(v2) - } - } else { - fnv(v[:containerLenS]) - } - } - if isArray { - d.arrayElem(j == 0) - } else if j&1 == 0 { - d.mapElemKey(j == 0) - } else { - d.mapElemValue() - } - if j >= len(v) { - fnv(append(v, 0)) - } - v[uint(j)] = float32(d.d.DecodeFloat32()) - } - if j < len(v) { - fnv(v[:uint(j)]) - } else if j == 0 && v == nil { - fnv([]float32{}) - } - if isArray { - d.arrayEnd() - } else { - d.mapEnd() - } - return v, changed -} -func (fastpathDTMsgpackIO) DecSliceFloat32N(v []float32, d *decoderMsgpackIO) { - ctyp := d.d.ContainerType() - if ctyp == valueTypeNil { - return - } - var containerLenS int - isArray := ctyp == valueTypeArray - if isArray { - containerLenS = d.arrayStart(d.d.ReadArrayStart()) - } else if ctyp == valueTypeMap { - containerLenS = d.mapStart(d.d.ReadMapStart()) * 2 - } else { - halt.errorStr2("decoding into a slice, expect map/array - got ", ctyp.String()) - } - hasLen := containerLenS >= 0 - for j := 0; d.containerNext(j, containerLenS, hasLen); j++ { - if isArray { - d.arrayElem(j == 0) - } else if j&1 == 0 { - d.mapElemKey(j == 0) - } else { - d.mapElemValue() - } - if j < len(v) { - v[uint(j)] = float32(d.d.DecodeFloat32()) - } else { - d.arrayCannotExpand(len(v), j+1) - d.swallow() - } - } - if isArray { - d.arrayEnd() - } else { - d.mapEnd() - } -} - -func (d *decoderMsgpackIO) fastpathDecSliceFloat64R(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTMsgpackIO - switch rv.Kind() { - case reflect.Ptr: - v := rv2i(rv).(*[]float64) - if vv, changed := ft.DecSliceFloat64Y(*v, d); changed { - *v = vv - } - case reflect.Array: - var v []float64 - rvGetSlice4Array(rv, &v) - ft.DecSliceFloat64N(v, d) - default: - ft.DecSliceFloat64N(rv2i(rv).([]float64), d) - } -} -func (fastpathDTMsgpackIO) DecSliceFloat64Y(v []float64, d *decoderMsgpackIO) (v2 []float64, changed bool) { - ctyp := d.d.ContainerType() - if ctyp == valueTypeNil { - return nil, v != nil - } - var containerLenS int - isArray := ctyp == valueTypeArray - if isArray { - containerLenS = d.arrayStart(d.d.ReadArrayStart()) - } else if ctyp == valueTypeMap { - containerLenS = d.mapStart(d.d.ReadMapStart()) * 2 - } else { - halt.errorStr2("decoding into a slice, expect map/array - got ", ctyp.String()) - } - hasLen := containerLenS >= 0 - var j int - fnv := func(dst []float64) { v, changed = dst, true } - for ; d.containerNext(j, containerLenS, hasLen); j++ { - if j == 0 { - if containerLenS == len(v) { - } else if containerLenS < 0 || containerLenS > cap(v) { - if xlen := int(decInferLen(containerLenS, d.maxInitLen(), 8)); xlen <= cap(v) { - fnv(v[:uint(xlen)]) - } else { - v2 = make([]float64, uint(xlen)) - copy(v2, v) - fnv(v2) - } - } else { - fnv(v[:containerLenS]) - } - } - if isArray { - d.arrayElem(j == 0) - } else if j&1 == 0 { - d.mapElemKey(j == 0) - } else { - d.mapElemValue() - } - if j >= len(v) { - fnv(append(v, 0)) - } - v[uint(j)] = d.d.DecodeFloat64() - } - if j < len(v) { - fnv(v[:uint(j)]) - } else if j == 0 && v == nil { - fnv([]float64{}) - } - if isArray { - d.arrayEnd() - } else { - d.mapEnd() - } - return v, changed -} -func (fastpathDTMsgpackIO) DecSliceFloat64N(v []float64, d *decoderMsgpackIO) { - ctyp := d.d.ContainerType() - if ctyp == valueTypeNil { - return - } - var containerLenS int - isArray := ctyp == valueTypeArray - if isArray { - containerLenS = d.arrayStart(d.d.ReadArrayStart()) - } else if ctyp == valueTypeMap { - containerLenS = d.mapStart(d.d.ReadMapStart()) * 2 - } else { - halt.errorStr2("decoding into a slice, expect map/array - got ", ctyp.String()) - } - hasLen := containerLenS >= 0 - for j := 0; d.containerNext(j, containerLenS, hasLen); j++ { - if isArray { - d.arrayElem(j == 0) - } else if j&1 == 0 { - d.mapElemKey(j == 0) - } else { - d.mapElemValue() - } - if j < len(v) { - v[uint(j)] = d.d.DecodeFloat64() - } else { - d.arrayCannotExpand(len(v), j+1) - d.swallow() - } - } - if isArray { - d.arrayEnd() - } else { - d.mapEnd() - } -} - -func (d *decoderMsgpackIO) fastpathDecSliceUint8R(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTMsgpackIO - switch rv.Kind() { - case reflect.Ptr: - v := rv2i(rv).(*[]uint8) - if vv, changed := ft.DecSliceUint8Y(*v, d); changed { - *v = vv - } - case reflect.Array: - var v []uint8 - rvGetSlice4Array(rv, &v) - ft.DecSliceUint8N(v, d) - default: - ft.DecSliceUint8N(rv2i(rv).([]uint8), d) - } -} -func (fastpathDTMsgpackIO) DecSliceUint8Y(v []uint8, d *decoderMsgpackIO) (v2 []uint8, changed bool) { - ctyp := d.d.ContainerType() - if ctyp == valueTypeNil { - return nil, v != nil - } - if ctyp != valueTypeMap { - var dbi dBytesIntoState - v2, dbi = d.decodeBytesInto(v[:len(v):len(v)], false) - return v2, dbi != dBytesIntoParamOut - } - containerLenS := d.mapStart(d.d.ReadMapStart()) * 2 - hasLen := containerLenS >= 0 - var j int - fnv := func(dst []uint8) { v, changed = dst, true } - for ; d.containerNext(j, containerLenS, hasLen); j++ { - if j == 0 { - if containerLenS == len(v) { - } else if containerLenS < 0 || containerLenS > cap(v) { - if xlen := int(decInferLen(containerLenS, d.maxInitLen(), 1)); xlen <= cap(v) { - fnv(v[:uint(xlen)]) - } else { - v2 = make([]uint8, uint(xlen)) - copy(v2, v) - fnv(v2) - } - } else { - fnv(v[:containerLenS]) - } - } - if j&1 == 0 { - d.mapElemKey(j == 0) - } else { - d.mapElemValue() - } - if j >= len(v) { - fnv(append(v, 0)) - } - v[uint(j)] = uint8(chkOvf.UintV(d.d.DecodeUint64(), 8)) - } - if j < len(v) { - fnv(v[:uint(j)]) - } else if j == 0 && v == nil { - fnv([]uint8{}) - } - d.mapEnd() - return v, changed -} -func (fastpathDTMsgpackIO) DecSliceUint8N(v []uint8, d *decoderMsgpackIO) { - ctyp := d.d.ContainerType() - if ctyp == valueTypeNil { - return - } - if ctyp != valueTypeMap { - d.decodeBytesInto(v[:len(v):len(v)], true) - return - } - containerLenS := d.mapStart(d.d.ReadMapStart()) * 2 - hasLen := containerLenS >= 0 - for j := 0; d.containerNext(j, containerLenS, hasLen); j++ { - if j&1 == 0 { - d.mapElemKey(j == 0) - } else { - d.mapElemValue() - } - if j < len(v) { - v[uint(j)] = uint8(chkOvf.UintV(d.d.DecodeUint64(), 8)) - } else { - d.arrayCannotExpand(len(v), j+1) - d.swallow() - } - } - d.mapEnd() -} - -func (d *decoderMsgpackIO) fastpathDecSliceUint64R(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTMsgpackIO - switch rv.Kind() { - case reflect.Ptr: - v := rv2i(rv).(*[]uint64) - if vv, changed := ft.DecSliceUint64Y(*v, d); changed { - *v = vv - } - case reflect.Array: - var v []uint64 - rvGetSlice4Array(rv, &v) - ft.DecSliceUint64N(v, d) - default: - ft.DecSliceUint64N(rv2i(rv).([]uint64), d) - } -} -func (fastpathDTMsgpackIO) DecSliceUint64Y(v []uint64, d *decoderMsgpackIO) (v2 []uint64, changed bool) { - ctyp := d.d.ContainerType() - if ctyp == valueTypeNil { - return nil, v != nil - } - var containerLenS int - isArray := ctyp == valueTypeArray - if isArray { - containerLenS = d.arrayStart(d.d.ReadArrayStart()) - } else if ctyp == valueTypeMap { - containerLenS = d.mapStart(d.d.ReadMapStart()) * 2 - } else { - halt.errorStr2("decoding into a slice, expect map/array - got ", ctyp.String()) - } - hasLen := containerLenS >= 0 - var j int - fnv := func(dst []uint64) { v, changed = dst, true } - for ; d.containerNext(j, containerLenS, hasLen); j++ { - if j == 0 { - if containerLenS == len(v) { - } else if containerLenS < 0 || containerLenS > cap(v) { - if xlen := int(decInferLen(containerLenS, d.maxInitLen(), 8)); xlen <= cap(v) { - fnv(v[:uint(xlen)]) - } else { - v2 = make([]uint64, uint(xlen)) - copy(v2, v) - fnv(v2) - } - } else { - fnv(v[:containerLenS]) - } - } - if isArray { - d.arrayElem(j == 0) - } else if j&1 == 0 { - d.mapElemKey(j == 0) - } else { - d.mapElemValue() - } - if j >= len(v) { - fnv(append(v, 0)) - } - v[uint(j)] = d.d.DecodeUint64() - } - if j < len(v) { - fnv(v[:uint(j)]) - } else if j == 0 && v == nil { - fnv([]uint64{}) - } - if isArray { - d.arrayEnd() - } else { - d.mapEnd() - } - return v, changed -} -func (fastpathDTMsgpackIO) DecSliceUint64N(v []uint64, d *decoderMsgpackIO) { - ctyp := d.d.ContainerType() - if ctyp == valueTypeNil { - return - } - var containerLenS int - isArray := ctyp == valueTypeArray - if isArray { - containerLenS = d.arrayStart(d.d.ReadArrayStart()) - } else if ctyp == valueTypeMap { - containerLenS = d.mapStart(d.d.ReadMapStart()) * 2 - } else { - halt.errorStr2("decoding into a slice, expect map/array - got ", ctyp.String()) - } - hasLen := containerLenS >= 0 - for j := 0; d.containerNext(j, containerLenS, hasLen); j++ { - if isArray { - d.arrayElem(j == 0) - } else if j&1 == 0 { - d.mapElemKey(j == 0) - } else { - d.mapElemValue() - } - if j < len(v) { - v[uint(j)] = d.d.DecodeUint64() - } else { - d.arrayCannotExpand(len(v), j+1) - d.swallow() - } - } - if isArray { - d.arrayEnd() - } else { - d.mapEnd() - } -} - -func (d *decoderMsgpackIO) fastpathDecSliceIntR(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTMsgpackIO - switch rv.Kind() { - case reflect.Ptr: - v := rv2i(rv).(*[]int) - if vv, changed := ft.DecSliceIntY(*v, d); changed { - *v = vv - } - case reflect.Array: - var v []int - rvGetSlice4Array(rv, &v) - ft.DecSliceIntN(v, d) - default: - ft.DecSliceIntN(rv2i(rv).([]int), d) - } -} -func (fastpathDTMsgpackIO) DecSliceIntY(v []int, d *decoderMsgpackIO) (v2 []int, changed bool) { - ctyp := d.d.ContainerType() - if ctyp == valueTypeNil { - return nil, v != nil - } - var containerLenS int - isArray := ctyp == valueTypeArray - if isArray { - containerLenS = d.arrayStart(d.d.ReadArrayStart()) - } else if ctyp == valueTypeMap { - containerLenS = d.mapStart(d.d.ReadMapStart()) * 2 - } else { - halt.errorStr2("decoding into a slice, expect map/array - got ", ctyp.String()) - } - hasLen := containerLenS >= 0 - var j int - fnv := func(dst []int) { v, changed = dst, true } - for ; d.containerNext(j, containerLenS, hasLen); j++ { - if j == 0 { - if containerLenS == len(v) { - } else if containerLenS < 0 || containerLenS > cap(v) { - if xlen := int(decInferLen(containerLenS, d.maxInitLen(), 8)); xlen <= cap(v) { - fnv(v[:uint(xlen)]) - } else { - v2 = make([]int, uint(xlen)) - copy(v2, v) - fnv(v2) - } - } else { - fnv(v[:containerLenS]) - } - } - if isArray { - d.arrayElem(j == 0) - } else if j&1 == 0 { - d.mapElemKey(j == 0) - } else { - d.mapElemValue() - } - if j >= len(v) { - fnv(append(v, 0)) - } - v[uint(j)] = int(chkOvf.IntV(d.d.DecodeInt64(), intBitsize)) - } - if j < len(v) { - fnv(v[:uint(j)]) - } else if j == 0 && v == nil { - fnv([]int{}) - } - if isArray { - d.arrayEnd() - } else { - d.mapEnd() - } - return v, changed -} -func (fastpathDTMsgpackIO) DecSliceIntN(v []int, d *decoderMsgpackIO) { - ctyp := d.d.ContainerType() - if ctyp == valueTypeNil { - return - } - var containerLenS int - isArray := ctyp == valueTypeArray - if isArray { - containerLenS = d.arrayStart(d.d.ReadArrayStart()) - } else if ctyp == valueTypeMap { - containerLenS = d.mapStart(d.d.ReadMapStart()) * 2 - } else { - halt.errorStr2("decoding into a slice, expect map/array - got ", ctyp.String()) - } - hasLen := containerLenS >= 0 - for j := 0; d.containerNext(j, containerLenS, hasLen); j++ { - if isArray { - d.arrayElem(j == 0) - } else if j&1 == 0 { - d.mapElemKey(j == 0) - } else { - d.mapElemValue() - } - if j < len(v) { - v[uint(j)] = int(chkOvf.IntV(d.d.DecodeInt64(), intBitsize)) - } else { - d.arrayCannotExpand(len(v), j+1) - d.swallow() - } - } - if isArray { - d.arrayEnd() - } else { - d.mapEnd() - } -} - -func (d *decoderMsgpackIO) fastpathDecSliceInt32R(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTMsgpackIO - switch rv.Kind() { - case reflect.Ptr: - v := rv2i(rv).(*[]int32) - if vv, changed := ft.DecSliceInt32Y(*v, d); changed { - *v = vv - } - case reflect.Array: - var v []int32 - rvGetSlice4Array(rv, &v) - ft.DecSliceInt32N(v, d) - default: - ft.DecSliceInt32N(rv2i(rv).([]int32), d) - } -} -func (fastpathDTMsgpackIO) DecSliceInt32Y(v []int32, d *decoderMsgpackIO) (v2 []int32, changed bool) { - ctyp := d.d.ContainerType() - if ctyp == valueTypeNil { - return nil, v != nil - } - var containerLenS int - isArray := ctyp == valueTypeArray - if isArray { - containerLenS = d.arrayStart(d.d.ReadArrayStart()) - } else if ctyp == valueTypeMap { - containerLenS = d.mapStart(d.d.ReadMapStart()) * 2 - } else { - halt.errorStr2("decoding into a slice, expect map/array - got ", ctyp.String()) - } - hasLen := containerLenS >= 0 - var j int - fnv := func(dst []int32) { v, changed = dst, true } - for ; d.containerNext(j, containerLenS, hasLen); j++ { - if j == 0 { - if containerLenS == len(v) { - } else if containerLenS < 0 || containerLenS > cap(v) { - if xlen := int(decInferLen(containerLenS, d.maxInitLen(), 4)); xlen <= cap(v) { - fnv(v[:uint(xlen)]) - } else { - v2 = make([]int32, uint(xlen)) - copy(v2, v) - fnv(v2) - } - } else { - fnv(v[:containerLenS]) - } - } - if isArray { - d.arrayElem(j == 0) - } else if j&1 == 0 { - d.mapElemKey(j == 0) - } else { - d.mapElemValue() - } - if j >= len(v) { - fnv(append(v, 0)) - } - v[uint(j)] = int32(chkOvf.IntV(d.d.DecodeInt64(), 32)) - } - if j < len(v) { - fnv(v[:uint(j)]) - } else if j == 0 && v == nil { - fnv([]int32{}) - } - if isArray { - d.arrayEnd() - } else { - d.mapEnd() - } - return v, changed -} -func (fastpathDTMsgpackIO) DecSliceInt32N(v []int32, d *decoderMsgpackIO) { - ctyp := d.d.ContainerType() - if ctyp == valueTypeNil { - return - } - var containerLenS int - isArray := ctyp == valueTypeArray - if isArray { - containerLenS = d.arrayStart(d.d.ReadArrayStart()) - } else if ctyp == valueTypeMap { - containerLenS = d.mapStart(d.d.ReadMapStart()) * 2 - } else { - halt.errorStr2("decoding into a slice, expect map/array - got ", ctyp.String()) - } - hasLen := containerLenS >= 0 - for j := 0; d.containerNext(j, containerLenS, hasLen); j++ { - if isArray { - d.arrayElem(j == 0) - } else if j&1 == 0 { - d.mapElemKey(j == 0) - } else { - d.mapElemValue() - } - if j < len(v) { - v[uint(j)] = int32(chkOvf.IntV(d.d.DecodeInt64(), 32)) - } else { - d.arrayCannotExpand(len(v), j+1) - d.swallow() - } - } - if isArray { - d.arrayEnd() - } else { - d.mapEnd() - } -} - -func (d *decoderMsgpackIO) fastpathDecSliceInt64R(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTMsgpackIO - switch rv.Kind() { - case reflect.Ptr: - v := rv2i(rv).(*[]int64) - if vv, changed := ft.DecSliceInt64Y(*v, d); changed { - *v = vv - } - case reflect.Array: - var v []int64 - rvGetSlice4Array(rv, &v) - ft.DecSliceInt64N(v, d) - default: - ft.DecSliceInt64N(rv2i(rv).([]int64), d) - } -} -func (fastpathDTMsgpackIO) DecSliceInt64Y(v []int64, d *decoderMsgpackIO) (v2 []int64, changed bool) { - ctyp := d.d.ContainerType() - if ctyp == valueTypeNil { - return nil, v != nil - } - var containerLenS int - isArray := ctyp == valueTypeArray - if isArray { - containerLenS = d.arrayStart(d.d.ReadArrayStart()) - } else if ctyp == valueTypeMap { - containerLenS = d.mapStart(d.d.ReadMapStart()) * 2 - } else { - halt.errorStr2("decoding into a slice, expect map/array - got ", ctyp.String()) - } - hasLen := containerLenS >= 0 - var j int - fnv := func(dst []int64) { v, changed = dst, true } - for ; d.containerNext(j, containerLenS, hasLen); j++ { - if j == 0 { - if containerLenS == len(v) { - } else if containerLenS < 0 || containerLenS > cap(v) { - if xlen := int(decInferLen(containerLenS, d.maxInitLen(), 8)); xlen <= cap(v) { - fnv(v[:uint(xlen)]) - } else { - v2 = make([]int64, uint(xlen)) - copy(v2, v) - fnv(v2) - } - } else { - fnv(v[:containerLenS]) - } - } - if isArray { - d.arrayElem(j == 0) - } else if j&1 == 0 { - d.mapElemKey(j == 0) - } else { - d.mapElemValue() - } - if j >= len(v) { - fnv(append(v, 0)) - } - v[uint(j)] = d.d.DecodeInt64() - } - if j < len(v) { - fnv(v[:uint(j)]) - } else if j == 0 && v == nil { - fnv([]int64{}) - } - if isArray { - d.arrayEnd() - } else { - d.mapEnd() - } - return v, changed -} -func (fastpathDTMsgpackIO) DecSliceInt64N(v []int64, d *decoderMsgpackIO) { - ctyp := d.d.ContainerType() - if ctyp == valueTypeNil { - return - } - var containerLenS int - isArray := ctyp == valueTypeArray - if isArray { - containerLenS = d.arrayStart(d.d.ReadArrayStart()) - } else if ctyp == valueTypeMap { - containerLenS = d.mapStart(d.d.ReadMapStart()) * 2 - } else { - halt.errorStr2("decoding into a slice, expect map/array - got ", ctyp.String()) - } - hasLen := containerLenS >= 0 - for j := 0; d.containerNext(j, containerLenS, hasLen); j++ { - if isArray { - d.arrayElem(j == 0) - } else if j&1 == 0 { - d.mapElemKey(j == 0) - } else { - d.mapElemValue() - } - if j < len(v) { - v[uint(j)] = d.d.DecodeInt64() - } else { - d.arrayCannotExpand(len(v), j+1) - d.swallow() - } - } - if isArray { - d.arrayEnd() - } else { - d.mapEnd() - } -} - -func (d *decoderMsgpackIO) fastpathDecSliceBoolR(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTMsgpackIO - switch rv.Kind() { - case reflect.Ptr: - v := rv2i(rv).(*[]bool) - if vv, changed := ft.DecSliceBoolY(*v, d); changed { - *v = vv - } - case reflect.Array: - var v []bool - rvGetSlice4Array(rv, &v) - ft.DecSliceBoolN(v, d) - default: - ft.DecSliceBoolN(rv2i(rv).([]bool), d) - } -} -func (fastpathDTMsgpackIO) DecSliceBoolY(v []bool, d *decoderMsgpackIO) (v2 []bool, changed bool) { - ctyp := d.d.ContainerType() - if ctyp == valueTypeNil { - return nil, v != nil - } - var containerLenS int - isArray := ctyp == valueTypeArray - if isArray { - containerLenS = d.arrayStart(d.d.ReadArrayStart()) - } else if ctyp == valueTypeMap { - containerLenS = d.mapStart(d.d.ReadMapStart()) * 2 - } else { - halt.errorStr2("decoding into a slice, expect map/array - got ", ctyp.String()) - } - hasLen := containerLenS >= 0 - var j int - fnv := func(dst []bool) { v, changed = dst, true } - for ; d.containerNext(j, containerLenS, hasLen); j++ { - if j == 0 { - if containerLenS == len(v) { - } else if containerLenS < 0 || containerLenS > cap(v) { - if xlen := int(decInferLen(containerLenS, d.maxInitLen(), 1)); xlen <= cap(v) { - fnv(v[:uint(xlen)]) - } else { - v2 = make([]bool, uint(xlen)) - copy(v2, v) - fnv(v2) - } - } else { - fnv(v[:containerLenS]) - } - } - if isArray { - d.arrayElem(j == 0) - } else if j&1 == 0 { - d.mapElemKey(j == 0) - } else { - d.mapElemValue() - } - if j >= len(v) { - fnv(append(v, false)) - } - v[uint(j)] = d.d.DecodeBool() - } - if j < len(v) { - fnv(v[:uint(j)]) - } else if j == 0 && v == nil { - fnv([]bool{}) - } - if isArray { - d.arrayEnd() - } else { - d.mapEnd() - } - return v, changed -} -func (fastpathDTMsgpackIO) DecSliceBoolN(v []bool, d *decoderMsgpackIO) { - ctyp := d.d.ContainerType() - if ctyp == valueTypeNil { - return - } - var containerLenS int - isArray := ctyp == valueTypeArray - if isArray { - containerLenS = d.arrayStart(d.d.ReadArrayStart()) - } else if ctyp == valueTypeMap { - containerLenS = d.mapStart(d.d.ReadMapStart()) * 2 - } else { - halt.errorStr2("decoding into a slice, expect map/array - got ", ctyp.String()) - } - hasLen := containerLenS >= 0 - for j := 0; d.containerNext(j, containerLenS, hasLen); j++ { - if isArray { - d.arrayElem(j == 0) - } else if j&1 == 0 { - d.mapElemKey(j == 0) - } else { - d.mapElemValue() - } - if j < len(v) { - v[uint(j)] = d.d.DecodeBool() - } else { - d.arrayCannotExpand(len(v), j+1) - d.swallow() - } - } - if isArray { - d.arrayEnd() - } else { - d.mapEnd() - } -} -func (d *decoderMsgpackIO) fastpathDecMapStringIntfR(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTMsgpackIO - containerLen := d.mapStart(d.d.ReadMapStart()) - if rv.Kind() == reflect.Ptr { - vp, _ := rv2i(rv).(*map[string]interface{}) - if *vp == nil { - *vp = make(map[string]interface{}, decInferLen(containerLen, d.maxInitLen(), 32)) - } - if containerLen != 0 { - ft.DecMapStringIntfL(*vp, containerLen, d) - } - } else if containerLen != 0 { - ft.DecMapStringIntfL(rv2i(rv).(map[string]interface{}), containerLen, d) - } - d.mapEnd() -} -func (fastpathDTMsgpackIO) DecMapStringIntfL(v map[string]interface{}, containerLen int, d *decoderMsgpackIO) { - if v == nil { - halt.errorInt("cannot decode into nil map[string]interface{} given stream length: ", int64(containerLen)) - } - var mv interface{} - mapGet := !d.h.MapValueReset && !d.h.InterfaceReset - hasLen := containerLen >= 0 - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - mk := d.detach2Str(d.d.DecodeStringAsBytes()) - d.mapElemValue() - if mapGet { - mv = v[mk] - } else { - mv = nil - } - d.decode(&mv) - v[mk] = mv - } -} -func (d *decoderMsgpackIO) fastpathDecMapStringStringR(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTMsgpackIO - containerLen := d.mapStart(d.d.ReadMapStart()) - if rv.Kind() == reflect.Ptr { - vp, _ := rv2i(rv).(*map[string]string) - if *vp == nil { - *vp = make(map[string]string, decInferLen(containerLen, d.maxInitLen(), 32)) - } - if containerLen != 0 { - ft.DecMapStringStringL(*vp, containerLen, d) - } - } else if containerLen != 0 { - ft.DecMapStringStringL(rv2i(rv).(map[string]string), containerLen, d) - } - d.mapEnd() -} -func (fastpathDTMsgpackIO) DecMapStringStringL(v map[string]string, containerLen int, d *decoderMsgpackIO) { - if v == nil { - halt.errorInt("cannot decode into nil map[string]string given stream length: ", int64(containerLen)) - } - hasLen := containerLen >= 0 - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - mk := d.detach2Str(d.d.DecodeStringAsBytes()) - d.mapElemValue() - v[mk] = d.detach2Str(d.d.DecodeStringAsBytes()) - } -} -func (d *decoderMsgpackIO) fastpathDecMapStringBytesR(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTMsgpackIO - containerLen := d.mapStart(d.d.ReadMapStart()) - if rv.Kind() == reflect.Ptr { - vp, _ := rv2i(rv).(*map[string][]byte) - if *vp == nil { - *vp = make(map[string][]byte, decInferLen(containerLen, d.maxInitLen(), 40)) - } - if containerLen != 0 { - ft.DecMapStringBytesL(*vp, containerLen, d) - } - } else if containerLen != 0 { - ft.DecMapStringBytesL(rv2i(rv).(map[string][]byte), containerLen, d) - } - d.mapEnd() -} -func (fastpathDTMsgpackIO) DecMapStringBytesL(v map[string][]byte, containerLen int, d *decoderMsgpackIO) { - if v == nil { - halt.errorInt("cannot decode into nil map[string][]byte given stream length: ", int64(containerLen)) - } - var mv []byte - mapGet := !d.h.MapValueReset - hasLen := containerLen >= 0 - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - mk := d.detach2Str(d.d.DecodeStringAsBytes()) - d.mapElemValue() - if mapGet { - mv = v[mk] - } else { - mv = nil - } - v[mk], _ = d.decodeBytesInto(mv, false) - } -} -func (d *decoderMsgpackIO) fastpathDecMapStringUint8R(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTMsgpackIO - containerLen := d.mapStart(d.d.ReadMapStart()) - if rv.Kind() == reflect.Ptr { - vp, _ := rv2i(rv).(*map[string]uint8) - if *vp == nil { - *vp = make(map[string]uint8, decInferLen(containerLen, d.maxInitLen(), 17)) - } - if containerLen != 0 { - ft.DecMapStringUint8L(*vp, containerLen, d) - } - } else if containerLen != 0 { - ft.DecMapStringUint8L(rv2i(rv).(map[string]uint8), containerLen, d) - } - d.mapEnd() -} -func (fastpathDTMsgpackIO) DecMapStringUint8L(v map[string]uint8, containerLen int, d *decoderMsgpackIO) { - if v == nil { - halt.errorInt("cannot decode into nil map[string]uint8 given stream length: ", int64(containerLen)) - } - hasLen := containerLen >= 0 - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - mk := d.detach2Str(d.d.DecodeStringAsBytes()) - d.mapElemValue() - v[mk] = uint8(chkOvf.UintV(d.d.DecodeUint64(), 8)) - } -} -func (d *decoderMsgpackIO) fastpathDecMapStringUint64R(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTMsgpackIO - containerLen := d.mapStart(d.d.ReadMapStart()) - if rv.Kind() == reflect.Ptr { - vp, _ := rv2i(rv).(*map[string]uint64) - if *vp == nil { - *vp = make(map[string]uint64, decInferLen(containerLen, d.maxInitLen(), 24)) - } - if containerLen != 0 { - ft.DecMapStringUint64L(*vp, containerLen, d) - } - } else if containerLen != 0 { - ft.DecMapStringUint64L(rv2i(rv).(map[string]uint64), containerLen, d) - } - d.mapEnd() -} -func (fastpathDTMsgpackIO) DecMapStringUint64L(v map[string]uint64, containerLen int, d *decoderMsgpackIO) { - if v == nil { - halt.errorInt("cannot decode into nil map[string]uint64 given stream length: ", int64(containerLen)) - } - hasLen := containerLen >= 0 - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - mk := d.detach2Str(d.d.DecodeStringAsBytes()) - d.mapElemValue() - v[mk] = d.d.DecodeUint64() - } -} -func (d *decoderMsgpackIO) fastpathDecMapStringIntR(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTMsgpackIO - containerLen := d.mapStart(d.d.ReadMapStart()) - if rv.Kind() == reflect.Ptr { - vp, _ := rv2i(rv).(*map[string]int) - if *vp == nil { - *vp = make(map[string]int, decInferLen(containerLen, d.maxInitLen(), 24)) - } - if containerLen != 0 { - ft.DecMapStringIntL(*vp, containerLen, d) - } - } else if containerLen != 0 { - ft.DecMapStringIntL(rv2i(rv).(map[string]int), containerLen, d) - } - d.mapEnd() -} -func (fastpathDTMsgpackIO) DecMapStringIntL(v map[string]int, containerLen int, d *decoderMsgpackIO) { - if v == nil { - halt.errorInt("cannot decode into nil map[string]int given stream length: ", int64(containerLen)) - } - hasLen := containerLen >= 0 - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - mk := d.detach2Str(d.d.DecodeStringAsBytes()) - d.mapElemValue() - v[mk] = int(chkOvf.IntV(d.d.DecodeInt64(), intBitsize)) - } -} -func (d *decoderMsgpackIO) fastpathDecMapStringInt32R(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTMsgpackIO - containerLen := d.mapStart(d.d.ReadMapStart()) - if rv.Kind() == reflect.Ptr { - vp, _ := rv2i(rv).(*map[string]int32) - if *vp == nil { - *vp = make(map[string]int32, decInferLen(containerLen, d.maxInitLen(), 20)) - } - if containerLen != 0 { - ft.DecMapStringInt32L(*vp, containerLen, d) - } - } else if containerLen != 0 { - ft.DecMapStringInt32L(rv2i(rv).(map[string]int32), containerLen, d) - } - d.mapEnd() -} -func (fastpathDTMsgpackIO) DecMapStringInt32L(v map[string]int32, containerLen int, d *decoderMsgpackIO) { - if v == nil { - halt.errorInt("cannot decode into nil map[string]int32 given stream length: ", int64(containerLen)) - } - hasLen := containerLen >= 0 - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - mk := d.detach2Str(d.d.DecodeStringAsBytes()) - d.mapElemValue() - v[mk] = int32(chkOvf.IntV(d.d.DecodeInt64(), 32)) - } -} -func (d *decoderMsgpackIO) fastpathDecMapStringFloat64R(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTMsgpackIO - containerLen := d.mapStart(d.d.ReadMapStart()) - if rv.Kind() == reflect.Ptr { - vp, _ := rv2i(rv).(*map[string]float64) - if *vp == nil { - *vp = make(map[string]float64, decInferLen(containerLen, d.maxInitLen(), 24)) - } - if containerLen != 0 { - ft.DecMapStringFloat64L(*vp, containerLen, d) - } - } else if containerLen != 0 { - ft.DecMapStringFloat64L(rv2i(rv).(map[string]float64), containerLen, d) - } - d.mapEnd() -} -func (fastpathDTMsgpackIO) DecMapStringFloat64L(v map[string]float64, containerLen int, d *decoderMsgpackIO) { - if v == nil { - halt.errorInt("cannot decode into nil map[string]float64 given stream length: ", int64(containerLen)) - } - hasLen := containerLen >= 0 - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - mk := d.detach2Str(d.d.DecodeStringAsBytes()) - d.mapElemValue() - v[mk] = d.d.DecodeFloat64() - } -} -func (d *decoderMsgpackIO) fastpathDecMapStringBoolR(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTMsgpackIO - containerLen := d.mapStart(d.d.ReadMapStart()) - if rv.Kind() == reflect.Ptr { - vp, _ := rv2i(rv).(*map[string]bool) - if *vp == nil { - *vp = make(map[string]bool, decInferLen(containerLen, d.maxInitLen(), 17)) - } - if containerLen != 0 { - ft.DecMapStringBoolL(*vp, containerLen, d) - } - } else if containerLen != 0 { - ft.DecMapStringBoolL(rv2i(rv).(map[string]bool), containerLen, d) - } - d.mapEnd() -} -func (fastpathDTMsgpackIO) DecMapStringBoolL(v map[string]bool, containerLen int, d *decoderMsgpackIO) { - if v == nil { - halt.errorInt("cannot decode into nil map[string]bool given stream length: ", int64(containerLen)) - } - hasLen := containerLen >= 0 - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - mk := d.detach2Str(d.d.DecodeStringAsBytes()) - d.mapElemValue() - v[mk] = d.d.DecodeBool() - } -} -func (d *decoderMsgpackIO) fastpathDecMapUint8IntfR(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTMsgpackIO - containerLen := d.mapStart(d.d.ReadMapStart()) - if rv.Kind() == reflect.Ptr { - vp, _ := rv2i(rv).(*map[uint8]interface{}) - if *vp == nil { - *vp = make(map[uint8]interface{}, decInferLen(containerLen, d.maxInitLen(), 17)) - } - if containerLen != 0 { - ft.DecMapUint8IntfL(*vp, containerLen, d) - } - } else if containerLen != 0 { - ft.DecMapUint8IntfL(rv2i(rv).(map[uint8]interface{}), containerLen, d) - } - d.mapEnd() -} -func (fastpathDTMsgpackIO) DecMapUint8IntfL(v map[uint8]interface{}, containerLen int, d *decoderMsgpackIO) { - if v == nil { - halt.errorInt("cannot decode into nil map[uint8]interface{} given stream length: ", int64(containerLen)) - } - var mv interface{} - mapGet := !d.h.MapValueReset && !d.h.InterfaceReset - hasLen := containerLen >= 0 - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - mk := uint8(chkOvf.UintV(d.d.DecodeUint64(), 8)) - d.mapElemValue() - if mapGet { - mv = v[mk] - } else { - mv = nil - } - d.decode(&mv) - v[mk] = mv - } -} -func (d *decoderMsgpackIO) fastpathDecMapUint8StringR(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTMsgpackIO - containerLen := d.mapStart(d.d.ReadMapStart()) - if rv.Kind() == reflect.Ptr { - vp, _ := rv2i(rv).(*map[uint8]string) - if *vp == nil { - *vp = make(map[uint8]string, decInferLen(containerLen, d.maxInitLen(), 17)) - } - if containerLen != 0 { - ft.DecMapUint8StringL(*vp, containerLen, d) - } - } else if containerLen != 0 { - ft.DecMapUint8StringL(rv2i(rv).(map[uint8]string), containerLen, d) - } - d.mapEnd() -} -func (fastpathDTMsgpackIO) DecMapUint8StringL(v map[uint8]string, containerLen int, d *decoderMsgpackIO) { - if v == nil { - halt.errorInt("cannot decode into nil map[uint8]string given stream length: ", int64(containerLen)) - } - hasLen := containerLen >= 0 - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - mk := uint8(chkOvf.UintV(d.d.DecodeUint64(), 8)) - d.mapElemValue() - v[mk] = d.detach2Str(d.d.DecodeStringAsBytes()) - } -} -func (d *decoderMsgpackIO) fastpathDecMapUint8BytesR(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTMsgpackIO - containerLen := d.mapStart(d.d.ReadMapStart()) - if rv.Kind() == reflect.Ptr { - vp, _ := rv2i(rv).(*map[uint8][]byte) - if *vp == nil { - *vp = make(map[uint8][]byte, decInferLen(containerLen, d.maxInitLen(), 25)) - } - if containerLen != 0 { - ft.DecMapUint8BytesL(*vp, containerLen, d) - } - } else if containerLen != 0 { - ft.DecMapUint8BytesL(rv2i(rv).(map[uint8][]byte), containerLen, d) - } - d.mapEnd() -} -func (fastpathDTMsgpackIO) DecMapUint8BytesL(v map[uint8][]byte, containerLen int, d *decoderMsgpackIO) { - if v == nil { - halt.errorInt("cannot decode into nil map[uint8][]byte given stream length: ", int64(containerLen)) - } - var mv []byte - mapGet := !d.h.MapValueReset - hasLen := containerLen >= 0 - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - mk := uint8(chkOvf.UintV(d.d.DecodeUint64(), 8)) - d.mapElemValue() - if mapGet { - mv = v[mk] - } else { - mv = nil - } - v[mk], _ = d.decodeBytesInto(mv, false) - } -} -func (d *decoderMsgpackIO) fastpathDecMapUint8Uint8R(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTMsgpackIO - containerLen := d.mapStart(d.d.ReadMapStart()) - if rv.Kind() == reflect.Ptr { - vp, _ := rv2i(rv).(*map[uint8]uint8) - if *vp == nil { - *vp = make(map[uint8]uint8, decInferLen(containerLen, d.maxInitLen(), 2)) - } - if containerLen != 0 { - ft.DecMapUint8Uint8L(*vp, containerLen, d) - } - } else if containerLen != 0 { - ft.DecMapUint8Uint8L(rv2i(rv).(map[uint8]uint8), containerLen, d) - } - d.mapEnd() -} -func (fastpathDTMsgpackIO) DecMapUint8Uint8L(v map[uint8]uint8, containerLen int, d *decoderMsgpackIO) { - if v == nil { - halt.errorInt("cannot decode into nil map[uint8]uint8 given stream length: ", int64(containerLen)) - } - hasLen := containerLen >= 0 - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - mk := uint8(chkOvf.UintV(d.d.DecodeUint64(), 8)) - d.mapElemValue() - v[mk] = uint8(chkOvf.UintV(d.d.DecodeUint64(), 8)) - } -} -func (d *decoderMsgpackIO) fastpathDecMapUint8Uint64R(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTMsgpackIO - containerLen := d.mapStart(d.d.ReadMapStart()) - if rv.Kind() == reflect.Ptr { - vp, _ := rv2i(rv).(*map[uint8]uint64) - if *vp == nil { - *vp = make(map[uint8]uint64, decInferLen(containerLen, d.maxInitLen(), 9)) - } - if containerLen != 0 { - ft.DecMapUint8Uint64L(*vp, containerLen, d) - } - } else if containerLen != 0 { - ft.DecMapUint8Uint64L(rv2i(rv).(map[uint8]uint64), containerLen, d) - } - d.mapEnd() -} -func (fastpathDTMsgpackIO) DecMapUint8Uint64L(v map[uint8]uint64, containerLen int, d *decoderMsgpackIO) { - if v == nil { - halt.errorInt("cannot decode into nil map[uint8]uint64 given stream length: ", int64(containerLen)) - } - hasLen := containerLen >= 0 - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - mk := uint8(chkOvf.UintV(d.d.DecodeUint64(), 8)) - d.mapElemValue() - v[mk] = d.d.DecodeUint64() - } -} -func (d *decoderMsgpackIO) fastpathDecMapUint8IntR(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTMsgpackIO - containerLen := d.mapStart(d.d.ReadMapStart()) - if rv.Kind() == reflect.Ptr { - vp, _ := rv2i(rv).(*map[uint8]int) - if *vp == nil { - *vp = make(map[uint8]int, decInferLen(containerLen, d.maxInitLen(), 9)) - } - if containerLen != 0 { - ft.DecMapUint8IntL(*vp, containerLen, d) - } - } else if containerLen != 0 { - ft.DecMapUint8IntL(rv2i(rv).(map[uint8]int), containerLen, d) - } - d.mapEnd() -} -func (fastpathDTMsgpackIO) DecMapUint8IntL(v map[uint8]int, containerLen int, d *decoderMsgpackIO) { - if v == nil { - halt.errorInt("cannot decode into nil map[uint8]int given stream length: ", int64(containerLen)) - } - hasLen := containerLen >= 0 - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - mk := uint8(chkOvf.UintV(d.d.DecodeUint64(), 8)) - d.mapElemValue() - v[mk] = int(chkOvf.IntV(d.d.DecodeInt64(), intBitsize)) - } -} -func (d *decoderMsgpackIO) fastpathDecMapUint8Int32R(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTMsgpackIO - containerLen := d.mapStart(d.d.ReadMapStart()) - if rv.Kind() == reflect.Ptr { - vp, _ := rv2i(rv).(*map[uint8]int32) - if *vp == nil { - *vp = make(map[uint8]int32, decInferLen(containerLen, d.maxInitLen(), 5)) - } - if containerLen != 0 { - ft.DecMapUint8Int32L(*vp, containerLen, d) - } - } else if containerLen != 0 { - ft.DecMapUint8Int32L(rv2i(rv).(map[uint8]int32), containerLen, d) - } - d.mapEnd() -} -func (fastpathDTMsgpackIO) DecMapUint8Int32L(v map[uint8]int32, containerLen int, d *decoderMsgpackIO) { - if v == nil { - halt.errorInt("cannot decode into nil map[uint8]int32 given stream length: ", int64(containerLen)) - } - hasLen := containerLen >= 0 - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - mk := uint8(chkOvf.UintV(d.d.DecodeUint64(), 8)) - d.mapElemValue() - v[mk] = int32(chkOvf.IntV(d.d.DecodeInt64(), 32)) - } -} -func (d *decoderMsgpackIO) fastpathDecMapUint8Float64R(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTMsgpackIO - containerLen := d.mapStart(d.d.ReadMapStart()) - if rv.Kind() == reflect.Ptr { - vp, _ := rv2i(rv).(*map[uint8]float64) - if *vp == nil { - *vp = make(map[uint8]float64, decInferLen(containerLen, d.maxInitLen(), 9)) - } - if containerLen != 0 { - ft.DecMapUint8Float64L(*vp, containerLen, d) - } - } else if containerLen != 0 { - ft.DecMapUint8Float64L(rv2i(rv).(map[uint8]float64), containerLen, d) - } - d.mapEnd() -} -func (fastpathDTMsgpackIO) DecMapUint8Float64L(v map[uint8]float64, containerLen int, d *decoderMsgpackIO) { - if v == nil { - halt.errorInt("cannot decode into nil map[uint8]float64 given stream length: ", int64(containerLen)) - } - hasLen := containerLen >= 0 - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - mk := uint8(chkOvf.UintV(d.d.DecodeUint64(), 8)) - d.mapElemValue() - v[mk] = d.d.DecodeFloat64() - } -} -func (d *decoderMsgpackIO) fastpathDecMapUint8BoolR(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTMsgpackIO - containerLen := d.mapStart(d.d.ReadMapStart()) - if rv.Kind() == reflect.Ptr { - vp, _ := rv2i(rv).(*map[uint8]bool) - if *vp == nil { - *vp = make(map[uint8]bool, decInferLen(containerLen, d.maxInitLen(), 2)) - } - if containerLen != 0 { - ft.DecMapUint8BoolL(*vp, containerLen, d) - } - } else if containerLen != 0 { - ft.DecMapUint8BoolL(rv2i(rv).(map[uint8]bool), containerLen, d) - } - d.mapEnd() -} -func (fastpathDTMsgpackIO) DecMapUint8BoolL(v map[uint8]bool, containerLen int, d *decoderMsgpackIO) { - if v == nil { - halt.errorInt("cannot decode into nil map[uint8]bool given stream length: ", int64(containerLen)) - } - hasLen := containerLen >= 0 - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - mk := uint8(chkOvf.UintV(d.d.DecodeUint64(), 8)) - d.mapElemValue() - v[mk] = d.d.DecodeBool() - } -} -func (d *decoderMsgpackIO) fastpathDecMapUint64IntfR(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTMsgpackIO - containerLen := d.mapStart(d.d.ReadMapStart()) - if rv.Kind() == reflect.Ptr { - vp, _ := rv2i(rv).(*map[uint64]interface{}) - if *vp == nil { - *vp = make(map[uint64]interface{}, decInferLen(containerLen, d.maxInitLen(), 24)) - } - if containerLen != 0 { - ft.DecMapUint64IntfL(*vp, containerLen, d) - } - } else if containerLen != 0 { - ft.DecMapUint64IntfL(rv2i(rv).(map[uint64]interface{}), containerLen, d) - } - d.mapEnd() -} -func (fastpathDTMsgpackIO) DecMapUint64IntfL(v map[uint64]interface{}, containerLen int, d *decoderMsgpackIO) { - if v == nil { - halt.errorInt("cannot decode into nil map[uint64]interface{} given stream length: ", int64(containerLen)) - } - var mv interface{} - mapGet := !d.h.MapValueReset && !d.h.InterfaceReset - hasLen := containerLen >= 0 - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - mk := d.d.DecodeUint64() - d.mapElemValue() - if mapGet { - mv = v[mk] - } else { - mv = nil - } - d.decode(&mv) - v[mk] = mv - } -} -func (d *decoderMsgpackIO) fastpathDecMapUint64StringR(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTMsgpackIO - containerLen := d.mapStart(d.d.ReadMapStart()) - if rv.Kind() == reflect.Ptr { - vp, _ := rv2i(rv).(*map[uint64]string) - if *vp == nil { - *vp = make(map[uint64]string, decInferLen(containerLen, d.maxInitLen(), 24)) - } - if containerLen != 0 { - ft.DecMapUint64StringL(*vp, containerLen, d) - } - } else if containerLen != 0 { - ft.DecMapUint64StringL(rv2i(rv).(map[uint64]string), containerLen, d) - } - d.mapEnd() -} -func (fastpathDTMsgpackIO) DecMapUint64StringL(v map[uint64]string, containerLen int, d *decoderMsgpackIO) { - if v == nil { - halt.errorInt("cannot decode into nil map[uint64]string given stream length: ", int64(containerLen)) - } - hasLen := containerLen >= 0 - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - mk := d.d.DecodeUint64() - d.mapElemValue() - v[mk] = d.detach2Str(d.d.DecodeStringAsBytes()) - } -} -func (d *decoderMsgpackIO) fastpathDecMapUint64BytesR(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTMsgpackIO - containerLen := d.mapStart(d.d.ReadMapStart()) - if rv.Kind() == reflect.Ptr { - vp, _ := rv2i(rv).(*map[uint64][]byte) - if *vp == nil { - *vp = make(map[uint64][]byte, decInferLen(containerLen, d.maxInitLen(), 32)) - } - if containerLen != 0 { - ft.DecMapUint64BytesL(*vp, containerLen, d) - } - } else if containerLen != 0 { - ft.DecMapUint64BytesL(rv2i(rv).(map[uint64][]byte), containerLen, d) - } - d.mapEnd() -} -func (fastpathDTMsgpackIO) DecMapUint64BytesL(v map[uint64][]byte, containerLen int, d *decoderMsgpackIO) { - if v == nil { - halt.errorInt("cannot decode into nil map[uint64][]byte given stream length: ", int64(containerLen)) - } - var mv []byte - mapGet := !d.h.MapValueReset - hasLen := containerLen >= 0 - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - mk := d.d.DecodeUint64() - d.mapElemValue() - if mapGet { - mv = v[mk] - } else { - mv = nil - } - v[mk], _ = d.decodeBytesInto(mv, false) - } -} -func (d *decoderMsgpackIO) fastpathDecMapUint64Uint8R(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTMsgpackIO - containerLen := d.mapStart(d.d.ReadMapStart()) - if rv.Kind() == reflect.Ptr { - vp, _ := rv2i(rv).(*map[uint64]uint8) - if *vp == nil { - *vp = make(map[uint64]uint8, decInferLen(containerLen, d.maxInitLen(), 9)) - } - if containerLen != 0 { - ft.DecMapUint64Uint8L(*vp, containerLen, d) - } - } else if containerLen != 0 { - ft.DecMapUint64Uint8L(rv2i(rv).(map[uint64]uint8), containerLen, d) - } - d.mapEnd() -} -func (fastpathDTMsgpackIO) DecMapUint64Uint8L(v map[uint64]uint8, containerLen int, d *decoderMsgpackIO) { - if v == nil { - halt.errorInt("cannot decode into nil map[uint64]uint8 given stream length: ", int64(containerLen)) - } - hasLen := containerLen >= 0 - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - mk := d.d.DecodeUint64() - d.mapElemValue() - v[mk] = uint8(chkOvf.UintV(d.d.DecodeUint64(), 8)) - } -} -func (d *decoderMsgpackIO) fastpathDecMapUint64Uint64R(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTMsgpackIO - containerLen := d.mapStart(d.d.ReadMapStart()) - if rv.Kind() == reflect.Ptr { - vp, _ := rv2i(rv).(*map[uint64]uint64) - if *vp == nil { - *vp = make(map[uint64]uint64, decInferLen(containerLen, d.maxInitLen(), 16)) - } - if containerLen != 0 { - ft.DecMapUint64Uint64L(*vp, containerLen, d) - } - } else if containerLen != 0 { - ft.DecMapUint64Uint64L(rv2i(rv).(map[uint64]uint64), containerLen, d) - } - d.mapEnd() -} -func (fastpathDTMsgpackIO) DecMapUint64Uint64L(v map[uint64]uint64, containerLen int, d *decoderMsgpackIO) { - if v == nil { - halt.errorInt("cannot decode into nil map[uint64]uint64 given stream length: ", int64(containerLen)) - } - hasLen := containerLen >= 0 - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - mk := d.d.DecodeUint64() - d.mapElemValue() - v[mk] = d.d.DecodeUint64() - } -} -func (d *decoderMsgpackIO) fastpathDecMapUint64IntR(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTMsgpackIO - containerLen := d.mapStart(d.d.ReadMapStart()) - if rv.Kind() == reflect.Ptr { - vp, _ := rv2i(rv).(*map[uint64]int) - if *vp == nil { - *vp = make(map[uint64]int, decInferLen(containerLen, d.maxInitLen(), 16)) - } - if containerLen != 0 { - ft.DecMapUint64IntL(*vp, containerLen, d) - } - } else if containerLen != 0 { - ft.DecMapUint64IntL(rv2i(rv).(map[uint64]int), containerLen, d) - } - d.mapEnd() -} -func (fastpathDTMsgpackIO) DecMapUint64IntL(v map[uint64]int, containerLen int, d *decoderMsgpackIO) { - if v == nil { - halt.errorInt("cannot decode into nil map[uint64]int given stream length: ", int64(containerLen)) - } - hasLen := containerLen >= 0 - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - mk := d.d.DecodeUint64() - d.mapElemValue() - v[mk] = int(chkOvf.IntV(d.d.DecodeInt64(), intBitsize)) - } -} -func (d *decoderMsgpackIO) fastpathDecMapUint64Int32R(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTMsgpackIO - containerLen := d.mapStart(d.d.ReadMapStart()) - if rv.Kind() == reflect.Ptr { - vp, _ := rv2i(rv).(*map[uint64]int32) - if *vp == nil { - *vp = make(map[uint64]int32, decInferLen(containerLen, d.maxInitLen(), 12)) - } - if containerLen != 0 { - ft.DecMapUint64Int32L(*vp, containerLen, d) - } - } else if containerLen != 0 { - ft.DecMapUint64Int32L(rv2i(rv).(map[uint64]int32), containerLen, d) - } - d.mapEnd() -} -func (fastpathDTMsgpackIO) DecMapUint64Int32L(v map[uint64]int32, containerLen int, d *decoderMsgpackIO) { - if v == nil { - halt.errorInt("cannot decode into nil map[uint64]int32 given stream length: ", int64(containerLen)) - } - hasLen := containerLen >= 0 - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - mk := d.d.DecodeUint64() - d.mapElemValue() - v[mk] = int32(chkOvf.IntV(d.d.DecodeInt64(), 32)) - } -} -func (d *decoderMsgpackIO) fastpathDecMapUint64Float64R(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTMsgpackIO - containerLen := d.mapStart(d.d.ReadMapStart()) - if rv.Kind() == reflect.Ptr { - vp, _ := rv2i(rv).(*map[uint64]float64) - if *vp == nil { - *vp = make(map[uint64]float64, decInferLen(containerLen, d.maxInitLen(), 16)) - } - if containerLen != 0 { - ft.DecMapUint64Float64L(*vp, containerLen, d) - } - } else if containerLen != 0 { - ft.DecMapUint64Float64L(rv2i(rv).(map[uint64]float64), containerLen, d) - } - d.mapEnd() -} -func (fastpathDTMsgpackIO) DecMapUint64Float64L(v map[uint64]float64, containerLen int, d *decoderMsgpackIO) { - if v == nil { - halt.errorInt("cannot decode into nil map[uint64]float64 given stream length: ", int64(containerLen)) - } - hasLen := containerLen >= 0 - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - mk := d.d.DecodeUint64() - d.mapElemValue() - v[mk] = d.d.DecodeFloat64() - } -} -func (d *decoderMsgpackIO) fastpathDecMapUint64BoolR(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTMsgpackIO - containerLen := d.mapStart(d.d.ReadMapStart()) - if rv.Kind() == reflect.Ptr { - vp, _ := rv2i(rv).(*map[uint64]bool) - if *vp == nil { - *vp = make(map[uint64]bool, decInferLen(containerLen, d.maxInitLen(), 9)) - } - if containerLen != 0 { - ft.DecMapUint64BoolL(*vp, containerLen, d) - } - } else if containerLen != 0 { - ft.DecMapUint64BoolL(rv2i(rv).(map[uint64]bool), containerLen, d) - } - d.mapEnd() -} -func (fastpathDTMsgpackIO) DecMapUint64BoolL(v map[uint64]bool, containerLen int, d *decoderMsgpackIO) { - if v == nil { - halt.errorInt("cannot decode into nil map[uint64]bool given stream length: ", int64(containerLen)) - } - hasLen := containerLen >= 0 - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - mk := d.d.DecodeUint64() - d.mapElemValue() - v[mk] = d.d.DecodeBool() - } -} -func (d *decoderMsgpackIO) fastpathDecMapIntIntfR(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTMsgpackIO - containerLen := d.mapStart(d.d.ReadMapStart()) - if rv.Kind() == reflect.Ptr { - vp, _ := rv2i(rv).(*map[int]interface{}) - if *vp == nil { - *vp = make(map[int]interface{}, decInferLen(containerLen, d.maxInitLen(), 24)) - } - if containerLen != 0 { - ft.DecMapIntIntfL(*vp, containerLen, d) - } - } else if containerLen != 0 { - ft.DecMapIntIntfL(rv2i(rv).(map[int]interface{}), containerLen, d) - } - d.mapEnd() -} -func (fastpathDTMsgpackIO) DecMapIntIntfL(v map[int]interface{}, containerLen int, d *decoderMsgpackIO) { - if v == nil { - halt.errorInt("cannot decode into nil map[int]interface{} given stream length: ", int64(containerLen)) - } - var mv interface{} - mapGet := !d.h.MapValueReset && !d.h.InterfaceReset - hasLen := containerLen >= 0 - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - mk := int(chkOvf.IntV(d.d.DecodeInt64(), intBitsize)) - d.mapElemValue() - if mapGet { - mv = v[mk] - } else { - mv = nil - } - d.decode(&mv) - v[mk] = mv - } -} -func (d *decoderMsgpackIO) fastpathDecMapIntStringR(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTMsgpackIO - containerLen := d.mapStart(d.d.ReadMapStart()) - if rv.Kind() == reflect.Ptr { - vp, _ := rv2i(rv).(*map[int]string) - if *vp == nil { - *vp = make(map[int]string, decInferLen(containerLen, d.maxInitLen(), 24)) - } - if containerLen != 0 { - ft.DecMapIntStringL(*vp, containerLen, d) - } - } else if containerLen != 0 { - ft.DecMapIntStringL(rv2i(rv).(map[int]string), containerLen, d) - } - d.mapEnd() -} -func (fastpathDTMsgpackIO) DecMapIntStringL(v map[int]string, containerLen int, d *decoderMsgpackIO) { - if v == nil { - halt.errorInt("cannot decode into nil map[int]string given stream length: ", int64(containerLen)) - } - hasLen := containerLen >= 0 - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - mk := int(chkOvf.IntV(d.d.DecodeInt64(), intBitsize)) - d.mapElemValue() - v[mk] = d.detach2Str(d.d.DecodeStringAsBytes()) - } -} -func (d *decoderMsgpackIO) fastpathDecMapIntBytesR(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTMsgpackIO - containerLen := d.mapStart(d.d.ReadMapStart()) - if rv.Kind() == reflect.Ptr { - vp, _ := rv2i(rv).(*map[int][]byte) - if *vp == nil { - *vp = make(map[int][]byte, decInferLen(containerLen, d.maxInitLen(), 32)) - } - if containerLen != 0 { - ft.DecMapIntBytesL(*vp, containerLen, d) - } - } else if containerLen != 0 { - ft.DecMapIntBytesL(rv2i(rv).(map[int][]byte), containerLen, d) - } - d.mapEnd() -} -func (fastpathDTMsgpackIO) DecMapIntBytesL(v map[int][]byte, containerLen int, d *decoderMsgpackIO) { - if v == nil { - halt.errorInt("cannot decode into nil map[int][]byte given stream length: ", int64(containerLen)) - } - var mv []byte - mapGet := !d.h.MapValueReset - hasLen := containerLen >= 0 - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - mk := int(chkOvf.IntV(d.d.DecodeInt64(), intBitsize)) - d.mapElemValue() - if mapGet { - mv = v[mk] - } else { - mv = nil - } - v[mk], _ = d.decodeBytesInto(mv, false) - } -} -func (d *decoderMsgpackIO) fastpathDecMapIntUint8R(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTMsgpackIO - containerLen := d.mapStart(d.d.ReadMapStart()) - if rv.Kind() == reflect.Ptr { - vp, _ := rv2i(rv).(*map[int]uint8) - if *vp == nil { - *vp = make(map[int]uint8, decInferLen(containerLen, d.maxInitLen(), 9)) - } - if containerLen != 0 { - ft.DecMapIntUint8L(*vp, containerLen, d) - } - } else if containerLen != 0 { - ft.DecMapIntUint8L(rv2i(rv).(map[int]uint8), containerLen, d) - } - d.mapEnd() -} -func (fastpathDTMsgpackIO) DecMapIntUint8L(v map[int]uint8, containerLen int, d *decoderMsgpackIO) { - if v == nil { - halt.errorInt("cannot decode into nil map[int]uint8 given stream length: ", int64(containerLen)) - } - hasLen := containerLen >= 0 - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - mk := int(chkOvf.IntV(d.d.DecodeInt64(), intBitsize)) - d.mapElemValue() - v[mk] = uint8(chkOvf.UintV(d.d.DecodeUint64(), 8)) - } -} -func (d *decoderMsgpackIO) fastpathDecMapIntUint64R(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTMsgpackIO - containerLen := d.mapStart(d.d.ReadMapStart()) - if rv.Kind() == reflect.Ptr { - vp, _ := rv2i(rv).(*map[int]uint64) - if *vp == nil { - *vp = make(map[int]uint64, decInferLen(containerLen, d.maxInitLen(), 16)) - } - if containerLen != 0 { - ft.DecMapIntUint64L(*vp, containerLen, d) - } - } else if containerLen != 0 { - ft.DecMapIntUint64L(rv2i(rv).(map[int]uint64), containerLen, d) - } - d.mapEnd() -} -func (fastpathDTMsgpackIO) DecMapIntUint64L(v map[int]uint64, containerLen int, d *decoderMsgpackIO) { - if v == nil { - halt.errorInt("cannot decode into nil map[int]uint64 given stream length: ", int64(containerLen)) - } - hasLen := containerLen >= 0 - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - mk := int(chkOvf.IntV(d.d.DecodeInt64(), intBitsize)) - d.mapElemValue() - v[mk] = d.d.DecodeUint64() - } -} -func (d *decoderMsgpackIO) fastpathDecMapIntIntR(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTMsgpackIO - containerLen := d.mapStart(d.d.ReadMapStart()) - if rv.Kind() == reflect.Ptr { - vp, _ := rv2i(rv).(*map[int]int) - if *vp == nil { - *vp = make(map[int]int, decInferLen(containerLen, d.maxInitLen(), 16)) - } - if containerLen != 0 { - ft.DecMapIntIntL(*vp, containerLen, d) - } - } else if containerLen != 0 { - ft.DecMapIntIntL(rv2i(rv).(map[int]int), containerLen, d) - } - d.mapEnd() -} -func (fastpathDTMsgpackIO) DecMapIntIntL(v map[int]int, containerLen int, d *decoderMsgpackIO) { - if v == nil { - halt.errorInt("cannot decode into nil map[int]int given stream length: ", int64(containerLen)) - } - hasLen := containerLen >= 0 - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - mk := int(chkOvf.IntV(d.d.DecodeInt64(), intBitsize)) - d.mapElemValue() - v[mk] = int(chkOvf.IntV(d.d.DecodeInt64(), intBitsize)) - } -} -func (d *decoderMsgpackIO) fastpathDecMapIntInt32R(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTMsgpackIO - containerLen := d.mapStart(d.d.ReadMapStart()) - if rv.Kind() == reflect.Ptr { - vp, _ := rv2i(rv).(*map[int]int32) - if *vp == nil { - *vp = make(map[int]int32, decInferLen(containerLen, d.maxInitLen(), 12)) - } - if containerLen != 0 { - ft.DecMapIntInt32L(*vp, containerLen, d) - } - } else if containerLen != 0 { - ft.DecMapIntInt32L(rv2i(rv).(map[int]int32), containerLen, d) - } - d.mapEnd() -} -func (fastpathDTMsgpackIO) DecMapIntInt32L(v map[int]int32, containerLen int, d *decoderMsgpackIO) { - if v == nil { - halt.errorInt("cannot decode into nil map[int]int32 given stream length: ", int64(containerLen)) - } - hasLen := containerLen >= 0 - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - mk := int(chkOvf.IntV(d.d.DecodeInt64(), intBitsize)) - d.mapElemValue() - v[mk] = int32(chkOvf.IntV(d.d.DecodeInt64(), 32)) - } -} -func (d *decoderMsgpackIO) fastpathDecMapIntFloat64R(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTMsgpackIO - containerLen := d.mapStart(d.d.ReadMapStart()) - if rv.Kind() == reflect.Ptr { - vp, _ := rv2i(rv).(*map[int]float64) - if *vp == nil { - *vp = make(map[int]float64, decInferLen(containerLen, d.maxInitLen(), 16)) - } - if containerLen != 0 { - ft.DecMapIntFloat64L(*vp, containerLen, d) - } - } else if containerLen != 0 { - ft.DecMapIntFloat64L(rv2i(rv).(map[int]float64), containerLen, d) - } - d.mapEnd() -} -func (fastpathDTMsgpackIO) DecMapIntFloat64L(v map[int]float64, containerLen int, d *decoderMsgpackIO) { - if v == nil { - halt.errorInt("cannot decode into nil map[int]float64 given stream length: ", int64(containerLen)) - } - hasLen := containerLen >= 0 - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - mk := int(chkOvf.IntV(d.d.DecodeInt64(), intBitsize)) - d.mapElemValue() - v[mk] = d.d.DecodeFloat64() - } -} -func (d *decoderMsgpackIO) fastpathDecMapIntBoolR(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTMsgpackIO - containerLen := d.mapStart(d.d.ReadMapStart()) - if rv.Kind() == reflect.Ptr { - vp, _ := rv2i(rv).(*map[int]bool) - if *vp == nil { - *vp = make(map[int]bool, decInferLen(containerLen, d.maxInitLen(), 9)) - } - if containerLen != 0 { - ft.DecMapIntBoolL(*vp, containerLen, d) - } - } else if containerLen != 0 { - ft.DecMapIntBoolL(rv2i(rv).(map[int]bool), containerLen, d) - } - d.mapEnd() -} -func (fastpathDTMsgpackIO) DecMapIntBoolL(v map[int]bool, containerLen int, d *decoderMsgpackIO) { - if v == nil { - halt.errorInt("cannot decode into nil map[int]bool given stream length: ", int64(containerLen)) - } - hasLen := containerLen >= 0 - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - mk := int(chkOvf.IntV(d.d.DecodeInt64(), intBitsize)) - d.mapElemValue() - v[mk] = d.d.DecodeBool() - } -} -func (d *decoderMsgpackIO) fastpathDecMapInt32IntfR(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTMsgpackIO - containerLen := d.mapStart(d.d.ReadMapStart()) - if rv.Kind() == reflect.Ptr { - vp, _ := rv2i(rv).(*map[int32]interface{}) - if *vp == nil { - *vp = make(map[int32]interface{}, decInferLen(containerLen, d.maxInitLen(), 20)) - } - if containerLen != 0 { - ft.DecMapInt32IntfL(*vp, containerLen, d) - } - } else if containerLen != 0 { - ft.DecMapInt32IntfL(rv2i(rv).(map[int32]interface{}), containerLen, d) - } - d.mapEnd() -} -func (fastpathDTMsgpackIO) DecMapInt32IntfL(v map[int32]interface{}, containerLen int, d *decoderMsgpackIO) { - if v == nil { - halt.errorInt("cannot decode into nil map[int32]interface{} given stream length: ", int64(containerLen)) - } - var mv interface{} - mapGet := !d.h.MapValueReset && !d.h.InterfaceReset - hasLen := containerLen >= 0 - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - mk := int32(chkOvf.IntV(d.d.DecodeInt64(), 32)) - d.mapElemValue() - if mapGet { - mv = v[mk] - } else { - mv = nil - } - d.decode(&mv) - v[mk] = mv - } -} -func (d *decoderMsgpackIO) fastpathDecMapInt32StringR(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTMsgpackIO - containerLen := d.mapStart(d.d.ReadMapStart()) - if rv.Kind() == reflect.Ptr { - vp, _ := rv2i(rv).(*map[int32]string) - if *vp == nil { - *vp = make(map[int32]string, decInferLen(containerLen, d.maxInitLen(), 20)) - } - if containerLen != 0 { - ft.DecMapInt32StringL(*vp, containerLen, d) - } - } else if containerLen != 0 { - ft.DecMapInt32StringL(rv2i(rv).(map[int32]string), containerLen, d) - } - d.mapEnd() -} -func (fastpathDTMsgpackIO) DecMapInt32StringL(v map[int32]string, containerLen int, d *decoderMsgpackIO) { - if v == nil { - halt.errorInt("cannot decode into nil map[int32]string given stream length: ", int64(containerLen)) - } - hasLen := containerLen >= 0 - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - mk := int32(chkOvf.IntV(d.d.DecodeInt64(), 32)) - d.mapElemValue() - v[mk] = d.detach2Str(d.d.DecodeStringAsBytes()) - } -} -func (d *decoderMsgpackIO) fastpathDecMapInt32BytesR(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTMsgpackIO - containerLen := d.mapStart(d.d.ReadMapStart()) - if rv.Kind() == reflect.Ptr { - vp, _ := rv2i(rv).(*map[int32][]byte) - if *vp == nil { - *vp = make(map[int32][]byte, decInferLen(containerLen, d.maxInitLen(), 28)) - } - if containerLen != 0 { - ft.DecMapInt32BytesL(*vp, containerLen, d) - } - } else if containerLen != 0 { - ft.DecMapInt32BytesL(rv2i(rv).(map[int32][]byte), containerLen, d) - } - d.mapEnd() -} -func (fastpathDTMsgpackIO) DecMapInt32BytesL(v map[int32][]byte, containerLen int, d *decoderMsgpackIO) { - if v == nil { - halt.errorInt("cannot decode into nil map[int32][]byte given stream length: ", int64(containerLen)) - } - var mv []byte - mapGet := !d.h.MapValueReset - hasLen := containerLen >= 0 - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - mk := int32(chkOvf.IntV(d.d.DecodeInt64(), 32)) - d.mapElemValue() - if mapGet { - mv = v[mk] - } else { - mv = nil - } - v[mk], _ = d.decodeBytesInto(mv, false) - } -} -func (d *decoderMsgpackIO) fastpathDecMapInt32Uint8R(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTMsgpackIO - containerLen := d.mapStart(d.d.ReadMapStart()) - if rv.Kind() == reflect.Ptr { - vp, _ := rv2i(rv).(*map[int32]uint8) - if *vp == nil { - *vp = make(map[int32]uint8, decInferLen(containerLen, d.maxInitLen(), 5)) - } - if containerLen != 0 { - ft.DecMapInt32Uint8L(*vp, containerLen, d) - } - } else if containerLen != 0 { - ft.DecMapInt32Uint8L(rv2i(rv).(map[int32]uint8), containerLen, d) - } - d.mapEnd() -} -func (fastpathDTMsgpackIO) DecMapInt32Uint8L(v map[int32]uint8, containerLen int, d *decoderMsgpackIO) { - if v == nil { - halt.errorInt("cannot decode into nil map[int32]uint8 given stream length: ", int64(containerLen)) - } - hasLen := containerLen >= 0 - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - mk := int32(chkOvf.IntV(d.d.DecodeInt64(), 32)) - d.mapElemValue() - v[mk] = uint8(chkOvf.UintV(d.d.DecodeUint64(), 8)) - } -} -func (d *decoderMsgpackIO) fastpathDecMapInt32Uint64R(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTMsgpackIO - containerLen := d.mapStart(d.d.ReadMapStart()) - if rv.Kind() == reflect.Ptr { - vp, _ := rv2i(rv).(*map[int32]uint64) - if *vp == nil { - *vp = make(map[int32]uint64, decInferLen(containerLen, d.maxInitLen(), 12)) - } - if containerLen != 0 { - ft.DecMapInt32Uint64L(*vp, containerLen, d) - } - } else if containerLen != 0 { - ft.DecMapInt32Uint64L(rv2i(rv).(map[int32]uint64), containerLen, d) - } - d.mapEnd() -} -func (fastpathDTMsgpackIO) DecMapInt32Uint64L(v map[int32]uint64, containerLen int, d *decoderMsgpackIO) { - if v == nil { - halt.errorInt("cannot decode into nil map[int32]uint64 given stream length: ", int64(containerLen)) - } - hasLen := containerLen >= 0 - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - mk := int32(chkOvf.IntV(d.d.DecodeInt64(), 32)) - d.mapElemValue() - v[mk] = d.d.DecodeUint64() - } -} -func (d *decoderMsgpackIO) fastpathDecMapInt32IntR(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTMsgpackIO - containerLen := d.mapStart(d.d.ReadMapStart()) - if rv.Kind() == reflect.Ptr { - vp, _ := rv2i(rv).(*map[int32]int) - if *vp == nil { - *vp = make(map[int32]int, decInferLen(containerLen, d.maxInitLen(), 12)) - } - if containerLen != 0 { - ft.DecMapInt32IntL(*vp, containerLen, d) - } - } else if containerLen != 0 { - ft.DecMapInt32IntL(rv2i(rv).(map[int32]int), containerLen, d) - } - d.mapEnd() -} -func (fastpathDTMsgpackIO) DecMapInt32IntL(v map[int32]int, containerLen int, d *decoderMsgpackIO) { - if v == nil { - halt.errorInt("cannot decode into nil map[int32]int given stream length: ", int64(containerLen)) - } - hasLen := containerLen >= 0 - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - mk := int32(chkOvf.IntV(d.d.DecodeInt64(), 32)) - d.mapElemValue() - v[mk] = int(chkOvf.IntV(d.d.DecodeInt64(), intBitsize)) - } -} -func (d *decoderMsgpackIO) fastpathDecMapInt32Int32R(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTMsgpackIO - containerLen := d.mapStart(d.d.ReadMapStart()) - if rv.Kind() == reflect.Ptr { - vp, _ := rv2i(rv).(*map[int32]int32) - if *vp == nil { - *vp = make(map[int32]int32, decInferLen(containerLen, d.maxInitLen(), 8)) - } - if containerLen != 0 { - ft.DecMapInt32Int32L(*vp, containerLen, d) - } - } else if containerLen != 0 { - ft.DecMapInt32Int32L(rv2i(rv).(map[int32]int32), containerLen, d) - } - d.mapEnd() -} -func (fastpathDTMsgpackIO) DecMapInt32Int32L(v map[int32]int32, containerLen int, d *decoderMsgpackIO) { - if v == nil { - halt.errorInt("cannot decode into nil map[int32]int32 given stream length: ", int64(containerLen)) - } - hasLen := containerLen >= 0 - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - mk := int32(chkOvf.IntV(d.d.DecodeInt64(), 32)) - d.mapElemValue() - v[mk] = int32(chkOvf.IntV(d.d.DecodeInt64(), 32)) - } -} -func (d *decoderMsgpackIO) fastpathDecMapInt32Float64R(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTMsgpackIO - containerLen := d.mapStart(d.d.ReadMapStart()) - if rv.Kind() == reflect.Ptr { - vp, _ := rv2i(rv).(*map[int32]float64) - if *vp == nil { - *vp = make(map[int32]float64, decInferLen(containerLen, d.maxInitLen(), 12)) - } - if containerLen != 0 { - ft.DecMapInt32Float64L(*vp, containerLen, d) - } - } else if containerLen != 0 { - ft.DecMapInt32Float64L(rv2i(rv).(map[int32]float64), containerLen, d) - } - d.mapEnd() -} -func (fastpathDTMsgpackIO) DecMapInt32Float64L(v map[int32]float64, containerLen int, d *decoderMsgpackIO) { - if v == nil { - halt.errorInt("cannot decode into nil map[int32]float64 given stream length: ", int64(containerLen)) - } - hasLen := containerLen >= 0 - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - mk := int32(chkOvf.IntV(d.d.DecodeInt64(), 32)) - d.mapElemValue() - v[mk] = d.d.DecodeFloat64() - } -} -func (d *decoderMsgpackIO) fastpathDecMapInt32BoolR(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTMsgpackIO - containerLen := d.mapStart(d.d.ReadMapStart()) - if rv.Kind() == reflect.Ptr { - vp, _ := rv2i(rv).(*map[int32]bool) - if *vp == nil { - *vp = make(map[int32]bool, decInferLen(containerLen, d.maxInitLen(), 5)) - } - if containerLen != 0 { - ft.DecMapInt32BoolL(*vp, containerLen, d) - } - } else if containerLen != 0 { - ft.DecMapInt32BoolL(rv2i(rv).(map[int32]bool), containerLen, d) - } - d.mapEnd() -} -func (fastpathDTMsgpackIO) DecMapInt32BoolL(v map[int32]bool, containerLen int, d *decoderMsgpackIO) { - if v == nil { - halt.errorInt("cannot decode into nil map[int32]bool given stream length: ", int64(containerLen)) - } - hasLen := containerLen >= 0 - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - mk := int32(chkOvf.IntV(d.d.DecodeInt64(), 32)) - d.mapElemValue() - v[mk] = d.d.DecodeBool() - } -} diff --git a/vendor/github.com/ugorji/go/codec/msgpack.go b/vendor/github.com/ugorji/go/codec/msgpack.go deleted file mode 100644 index ed8ca99a6..000000000 --- a/vendor/github.com/ugorji/go/codec/msgpack.go +++ /dev/null @@ -1,1019 +0,0 @@ -//go:build notmono || codec.notmono - -// Copyright (c) 2012-2020 Ugorji Nwoke. All rights reserved. -// Use of this source code is governed by a MIT license found in the LICENSE file. - -/* -Msgpack-c implementation powers the c, c++, python, ruby, etc libraries. -We need to maintain compatibility with it and how it encodes integer values -without caring about the type. - -For compatibility with behaviour of msgpack-c reference implementation: - - Go intX (>0) and uintX - IS ENCODED AS - msgpack +ve fixnum, unsigned - - Go intX (<0) - IS ENCODED AS - msgpack -ve fixnum, signed -*/ - -package codec - -import ( - "io" - "math" - "reflect" - "time" - "unicode/utf8" -) - -//--------------------------------------------- - -type msgpackEncDriver[T encWriter] struct { - noBuiltInTypes - encDriverNoopContainerWriter - encDriverNoState - encDriverContainerNoTrackerT - encInit2er - - h *MsgpackHandle - e *encoderBase - w T - // x [8]byte -} - -func (e *msgpackEncDriver[T]) EncodeNil() { - e.w.writen1(mpNil) -} - -func (e *msgpackEncDriver[T]) EncodeInt(i int64) { - if e.h.PositiveIntUnsigned && i >= 0 { - e.EncodeUint(uint64(i)) - } else if i > math.MaxInt8 { - if i <= math.MaxInt16 { - e.w.writen1(mpInt16) - e.w.writen2(bigen.PutUint16(uint16(i))) - } else if i <= math.MaxInt32 { - e.w.writen1(mpInt32) - e.w.writen4(bigen.PutUint32(uint32(i))) - } else { - e.w.writen1(mpInt64) - e.w.writen8(bigen.PutUint64(uint64(i))) - } - } else if i >= -32 { - if e.h.NoFixedNum { - e.w.writen2(mpInt8, byte(i)) - } else { - e.w.writen1(byte(i)) - } - } else if i >= math.MinInt8 { - e.w.writen2(mpInt8, byte(i)) - } else if i >= math.MinInt16 { - e.w.writen1(mpInt16) - e.w.writen2(bigen.PutUint16(uint16(i))) - } else if i >= math.MinInt32 { - e.w.writen1(mpInt32) - e.w.writen4(bigen.PutUint32(uint32(i))) - } else { - e.w.writen1(mpInt64) - e.w.writen8(bigen.PutUint64(uint64(i))) - } -} - -func (e *msgpackEncDriver[T]) EncodeUint(i uint64) { - if i <= math.MaxInt8 { - if e.h.NoFixedNum { - e.w.writen2(mpUint8, byte(i)) - } else { - e.w.writen1(byte(i)) - } - } else if i <= math.MaxUint8 { - e.w.writen2(mpUint8, byte(i)) - } else if i <= math.MaxUint16 { - e.w.writen1(mpUint16) - e.w.writen2(bigen.PutUint16(uint16(i))) - } else if i <= math.MaxUint32 { - e.w.writen1(mpUint32) - e.w.writen4(bigen.PutUint32(uint32(i))) - } else { - e.w.writen1(mpUint64) - e.w.writen8(bigen.PutUint64(uint64(i))) - } -} - -func (e *msgpackEncDriver[T]) EncodeBool(b bool) { - if b { - e.w.writen1(mpTrue) - } else { - e.w.writen1(mpFalse) - } -} - -func (e *msgpackEncDriver[T]) EncodeFloat32(f float32) { - e.w.writen1(mpFloat) - e.w.writen4(bigen.PutUint32(math.Float32bits(f))) -} - -func (e *msgpackEncDriver[T]) EncodeFloat64(f float64) { - e.w.writen1(mpDouble) - e.w.writen8(bigen.PutUint64(math.Float64bits(f))) -} - -func (e *msgpackEncDriver[T]) EncodeTime(t time.Time) { - if t.IsZero() { - e.EncodeNil() - return - } - t = t.UTC() - sec, nsec := t.Unix(), uint64(t.Nanosecond()) - var data64 uint64 - var l = 4 - if sec >= 0 && sec>>34 == 0 { - data64 = (nsec << 34) | uint64(sec) - if data64&0xffffffff00000000 != 0 { - l = 8 - } - } else { - l = 12 - } - if e.h.WriteExt { - e.encodeExtPreamble(mpTimeExtTagU, l) - } else { - e.writeContainerLen(msgpackContainerRawLegacy, l) - } - switch l { - case 4: - e.w.writen4(bigen.PutUint32(uint32(data64))) - case 8: - e.w.writen8(bigen.PutUint64(data64)) - case 12: - e.w.writen4(bigen.PutUint32(uint32(nsec))) - e.w.writen8(bigen.PutUint64(uint64(sec))) - } -} - -func (e *msgpackEncDriver[T]) EncodeExt(v interface{}, basetype reflect.Type, xtag uint64, ext Ext) { - var bs0, bs []byte - if ext == SelfExt { - bs0 = e.e.blist.get(1024) - bs = bs0 - sideEncode(e.h, &e.h.sideEncPool, func(se encoderI) { oneOffEncode(se, v, &bs, basetype, true) }) - } else { - bs = ext.WriteExt(v) - } - if bs == nil { - e.writeNilBytes() - goto END - } - if e.h.WriteExt { - e.encodeExtPreamble(uint8(xtag), len(bs)) - e.w.writeb(bs) - } else { - e.EncodeBytes(bs) - } -END: - if ext == SelfExt { - e.e.blist.put(bs) - if !byteSliceSameData(bs0, bs) { - e.e.blist.put(bs0) - } - } -} - -func (e *msgpackEncDriver[T]) EncodeRawExt(re *RawExt) { - e.encodeExtPreamble(uint8(re.Tag), len(re.Data)) - e.w.writeb(re.Data) -} - -func (e *msgpackEncDriver[T]) encodeExtPreamble(xtag byte, l int) { - if l == 1 { - e.w.writen2(mpFixExt1, xtag) - } else if l == 2 { - e.w.writen2(mpFixExt2, xtag) - } else if l == 4 { - e.w.writen2(mpFixExt4, xtag) - } else if l == 8 { - e.w.writen2(mpFixExt8, xtag) - } else if l == 16 { - e.w.writen2(mpFixExt16, xtag) - } else if l < 256 { - e.w.writen2(mpExt8, byte(l)) - e.w.writen1(xtag) - } else if l < 65536 { - e.w.writen1(mpExt16) - e.w.writen2(bigen.PutUint16(uint16(l))) - e.w.writen1(xtag) - } else { - e.w.writen1(mpExt32) - e.w.writen4(bigen.PutUint32(uint32(l))) - e.w.writen1(xtag) - } -} - -func (e *msgpackEncDriver[T]) WriteArrayStart(length int) { - e.writeContainerLen(msgpackContainerList, length) -} - -func (e *msgpackEncDriver[T]) WriteMapStart(length int) { - e.writeContainerLen(msgpackContainerMap, length) -} - -func (e *msgpackEncDriver[T]) WriteArrayEmpty() { - // e.WriteArrayStart(0) = e.writeContainerLen(msgpackContainerList, 0) - e.w.writen1(mpFixArrayMin) -} - -func (e *msgpackEncDriver[T]) WriteMapEmpty() { - // e.WriteMapStart(0) = e.writeContainerLen(msgpackContainerMap, 0) - e.w.writen1(mpFixMapMin) -} - -func (e *msgpackEncDriver[T]) EncodeString(s string) { - var ct msgpackContainerType - if e.h.WriteExt { - if e.h.StringToRaw { - ct = msgpackContainerBin - } else { - ct = msgpackContainerStr - } - } else { - ct = msgpackContainerRawLegacy - } - e.writeContainerLen(ct, len(s)) - if len(s) > 0 { - e.w.writestr(s) - } -} - -func (e *msgpackEncDriver[T]) EncodeStringNoEscape4Json(v string) { e.EncodeString(v) } - -func (e *msgpackEncDriver[T]) EncodeStringBytesRaw(bs []byte) { - if e.h.WriteExt { - e.writeContainerLen(msgpackContainerBin, len(bs)) - } else { - e.writeContainerLen(msgpackContainerRawLegacy, len(bs)) - } - if len(bs) > 0 { - e.w.writeb(bs) - } -} - -func (e *msgpackEncDriver[T]) EncodeBytes(v []byte) { - if v == nil { - e.writeNilBytes() - return - } - e.EncodeStringBytesRaw(v) -} - -func (e *msgpackEncDriver[T]) writeNilOr(v byte) { - if !e.h.NilCollectionToZeroLength { - v = mpNil - } - e.w.writen1(v) -} - -func (e *msgpackEncDriver[T]) writeNilArray() { - e.writeNilOr(mpFixArrayMin) -} - -func (e *msgpackEncDriver[T]) writeNilMap() { - e.writeNilOr(mpFixMapMin) -} - -func (e *msgpackEncDriver[T]) writeNilBytes() { - e.writeNilOr(mpFixStrMin) -} - -func (e *msgpackEncDriver[T]) writeContainerLen(ct msgpackContainerType, l int) { - if ct.fixCutoff > 0 && l < int(ct.fixCutoff) { - e.w.writen1(ct.bFixMin | byte(l)) - } else if ct.b8 > 0 && l < 256 { - e.w.writen2(ct.b8, uint8(l)) - } else if l < 65536 { - e.w.writen1(ct.b16) - e.w.writen2(bigen.PutUint16(uint16(l))) - } else { - e.w.writen1(ct.b32) - e.w.writen4(bigen.PutUint32(uint32(l))) - } -} - -//--------------------------------------------- - -type msgpackDecDriver[T decReader] struct { - decDriverNoopContainerReader - decDriverNoopNumberHelper - decInit2er - - h *MsgpackHandle - d *decoderBase - r T - - bdAndBdread - // bytes bool - noBuiltInTypes -} - -// Note: This returns either a primitive (int, bool, etc) for non-containers, -// or a containerType, or a specific type denoting nil or extension. -// It is called when a nil interface{} is passed, leaving it up to the DecDriver -// to introspect the stream and decide how best to decode. -// It deciphers the value by looking at the stream first. -func (d *msgpackDecDriver[T]) DecodeNaked() { - if !d.bdRead { - d.readNextBd() - } - bd := d.bd - n := d.d.naked() - var decodeFurther bool - - switch bd { - case mpNil: - n.v = valueTypeNil - d.bdRead = false - case mpFalse: - n.v = valueTypeBool - n.b = false - case mpTrue: - n.v = valueTypeBool - n.b = true - - case mpFloat: - n.v = valueTypeFloat - n.f = float64(math.Float32frombits(bigen.Uint32(d.r.readn4()))) - case mpDouble: - n.v = valueTypeFloat - n.f = math.Float64frombits(bigen.Uint64(d.r.readn8())) - - case mpUint8: - n.v = valueTypeUint - n.u = uint64(d.r.readn1()) - case mpUint16: - n.v = valueTypeUint - n.u = uint64(bigen.Uint16(d.r.readn2())) - case mpUint32: - n.v = valueTypeUint - n.u = uint64(bigen.Uint32(d.r.readn4())) - case mpUint64: - n.v = valueTypeUint - n.u = uint64(bigen.Uint64(d.r.readn8())) - - case mpInt8: - n.v = valueTypeInt - n.i = int64(int8(d.r.readn1())) - case mpInt16: - n.v = valueTypeInt - n.i = int64(int16(bigen.Uint16(d.r.readn2()))) - case mpInt32: - n.v = valueTypeInt - n.i = int64(int32(bigen.Uint32(d.r.readn4()))) - case mpInt64: - n.v = valueTypeInt - n.i = int64(int64(bigen.Uint64(d.r.readn8()))) - - default: - switch { - case bd >= mpPosFixNumMin && bd <= mpPosFixNumMax: - // positive fixnum (always signed) - n.v = valueTypeInt - n.i = int64(int8(bd)) - case bd >= mpNegFixNumMin && bd <= mpNegFixNumMax: - // negative fixnum - n.v = valueTypeInt - n.i = int64(int8(bd)) - case bd == mpStr8, bd == mpStr16, bd == mpStr32, bd >= mpFixStrMin && bd <= mpFixStrMax: - d.d.fauxUnionReadRawBytes(d, d.h.WriteExt, d.h.RawToString) //, d.h.ZeroCopy) - // if d.h.WriteExt || d.h.RawToString { - // n.v = valueTypeString - // n.s = d.d.stringZC(d.DecodeStringAsBytes()) - // } else { - // n.v = valueTypeBytes - // n.l = d.DecodeBytes([]byte{}) - // } - case bd == mpBin8, bd == mpBin16, bd == mpBin32: - d.d.fauxUnionReadRawBytes(d, false, d.h.RawToString) //, d.h.ZeroCopy) - case bd == mpArray16, bd == mpArray32, bd >= mpFixArrayMin && bd <= mpFixArrayMax: - n.v = valueTypeArray - decodeFurther = true - case bd == mpMap16, bd == mpMap32, bd >= mpFixMapMin && bd <= mpFixMapMax: - n.v = valueTypeMap - decodeFurther = true - case bd >= mpFixExt1 && bd <= mpFixExt16, bd >= mpExt8 && bd <= mpExt32: - n.v = valueTypeExt - clen := d.readExtLen() - n.u = uint64(d.r.readn1()) - if n.u == uint64(mpTimeExtTagU) { - n.v = valueTypeTime - n.t = d.decodeTime(clen) - } else { - n.l = d.r.readx(uint(clen)) - } - default: - halt.errorf("cannot infer value: %s: Ox%x/%d/%s", msgBadDesc, bd, bd, mpdesc(bd)) - } - } - if !decodeFurther { - d.bdRead = false - } - if n.v == valueTypeUint && d.h.SignedInteger { - n.v = valueTypeInt - n.i = int64(n.u) - } -} - -func (d *msgpackDecDriver[T]) nextValueBytes() (v []byte) { - if !d.bdRead { - d.readNextBd() - } - d.r.startRecording() - d.nextValueBytesBdReadR() - v = d.r.stopRecording() - d.bdRead = false - return -} - -func (d *msgpackDecDriver[T]) nextValueBytesBdReadR() { - bd := d.bd - - var clen uint - - switch bd { - case mpNil, mpFalse, mpTrue: // pass - case mpUint8, mpInt8: - d.r.readn1() - case mpUint16, mpInt16: - d.r.skip(2) - case mpFloat, mpUint32, mpInt32: - d.r.skip(4) - case mpDouble, mpUint64, mpInt64: - d.r.skip(8) - case mpStr8, mpBin8: - clen = uint(d.r.readn1()) - d.r.skip(clen) - case mpStr16, mpBin16: - x := d.r.readn2() - clen = uint(bigen.Uint16(x)) - d.r.skip(clen) - case mpStr32, mpBin32: - x := d.r.readn4() - clen = uint(bigen.Uint32(x)) - d.r.skip(clen) - case mpFixExt1: - d.r.readn1() // tag - d.r.readn1() - case mpFixExt2: - d.r.readn1() // tag - d.r.skip(2) - case mpFixExt4: - d.r.readn1() // tag - d.r.skip(4) - case mpFixExt8: - d.r.readn1() // tag - d.r.skip(8) - case mpFixExt16: - d.r.readn1() // tag - d.r.skip(16) - case mpExt8: - clen = uint(d.r.readn1()) - d.r.readn1() // tag - d.r.skip(clen) - case mpExt16: - x := d.r.readn2() - clen = uint(bigen.Uint16(x)) - d.r.readn1() // tag - d.r.skip(clen) - case mpExt32: - x := d.r.readn4() - clen = uint(bigen.Uint32(x)) - d.r.readn1() // tag - d.r.skip(clen) - case mpArray16: - x := d.r.readn2() - clen = uint(bigen.Uint16(x)) - for i := uint(0); i < clen; i++ { - d.readNextBd() - d.nextValueBytesBdReadR() - } - case mpArray32: - x := d.r.readn4() - clen = uint(bigen.Uint32(x)) - for i := uint(0); i < clen; i++ { - d.readNextBd() - d.nextValueBytesBdReadR() - } - case mpMap16: - x := d.r.readn2() - clen = uint(bigen.Uint16(x)) - for i := uint(0); i < clen; i++ { - d.readNextBd() - d.nextValueBytesBdReadR() - d.readNextBd() - d.nextValueBytesBdReadR() - } - case mpMap32: - x := d.r.readn4() - clen = uint(bigen.Uint32(x)) - for i := uint(0); i < clen; i++ { - d.readNextBd() - d.nextValueBytesBdReadR() - d.readNextBd() - d.nextValueBytesBdReadR() - } - default: - switch { - case bd >= mpPosFixNumMin && bd <= mpPosFixNumMax: // pass - case bd >= mpNegFixNumMin && bd <= mpNegFixNumMax: // pass - case bd >= mpFixStrMin && bd <= mpFixStrMax: - clen = uint(mpFixStrMin ^ bd) - d.r.skip(clen) - case bd >= mpFixArrayMin && bd <= mpFixArrayMax: - clen = uint(mpFixArrayMin ^ bd) - for i := uint(0); i < clen; i++ { - d.readNextBd() - d.nextValueBytesBdReadR() - } - case bd >= mpFixMapMin && bd <= mpFixMapMax: - clen = uint(mpFixMapMin ^ bd) - for i := uint(0); i < clen; i++ { - d.readNextBd() - d.nextValueBytesBdReadR() - d.readNextBd() - d.nextValueBytesBdReadR() - } - default: - halt.errorf("nextValueBytes: cannot infer value: %s: Ox%x/%d/%s", msgBadDesc, bd, bd, mpdesc(bd)) - } - } - return -} - -func (d *msgpackDecDriver[T]) decFloat4Int32() (f float32) { - fbits := bigen.Uint32(d.r.readn4()) - f = math.Float32frombits(fbits) - if !noFrac32(fbits) { - halt.errorf("assigning integer value from float32 with a fraction: %v", f) - } - return -} - -func (d *msgpackDecDriver[T]) decFloat4Int64() (f float64) { - fbits := bigen.Uint64(d.r.readn8()) - f = math.Float64frombits(fbits) - if !noFrac64(fbits) { - halt.errorf("assigning integer value from float64 with a fraction: %v", f) - } - return -} - -// int can be decoded from msgpack type: intXXX or uintXXX -func (d *msgpackDecDriver[T]) DecodeInt64() (i int64) { - if d.advanceNil() { - return - } - switch d.bd { - case mpUint8: - i = int64(uint64(d.r.readn1())) - case mpUint16: - i = int64(uint64(bigen.Uint16(d.r.readn2()))) - case mpUint32: - i = int64(uint64(bigen.Uint32(d.r.readn4()))) - case mpUint64: - i = int64(bigen.Uint64(d.r.readn8())) - case mpInt8: - i = int64(int8(d.r.readn1())) - case mpInt16: - i = int64(int16(bigen.Uint16(d.r.readn2()))) - case mpInt32: - i = int64(int32(bigen.Uint32(d.r.readn4()))) - case mpInt64: - i = int64(bigen.Uint64(d.r.readn8())) - case mpFloat: - i = int64(d.decFloat4Int32()) - case mpDouble: - i = int64(d.decFloat4Int64()) - default: - switch { - case d.bd >= mpPosFixNumMin && d.bd <= mpPosFixNumMax: - i = int64(int8(d.bd)) - case d.bd >= mpNegFixNumMin && d.bd <= mpNegFixNumMax: - i = int64(int8(d.bd)) - default: - halt.errorf("cannot decode signed integer: %s: %x/%s", msgBadDesc, d.bd, mpdesc(d.bd)) - } - } - d.bdRead = false - return -} - -// uint can be decoded from msgpack type: intXXX or uintXXX -func (d *msgpackDecDriver[T]) DecodeUint64() (ui uint64) { - if d.advanceNil() { - return - } - switch d.bd { - case mpUint8: - ui = uint64(d.r.readn1()) - case mpUint16: - ui = uint64(bigen.Uint16(d.r.readn2())) - case mpUint32: - ui = uint64(bigen.Uint32(d.r.readn4())) - case mpUint64: - ui = bigen.Uint64(d.r.readn8()) - case mpInt8: - if i := int64(int8(d.r.readn1())); i >= 0 { - ui = uint64(i) - } else { - halt.errorf("assigning negative signed value: %v, to unsigned type", i) - } - case mpInt16: - if i := int64(int16(bigen.Uint16(d.r.readn2()))); i >= 0 { - ui = uint64(i) - } else { - halt.errorf("assigning negative signed value: %v, to unsigned type", i) - } - case mpInt32: - if i := int64(int32(bigen.Uint32(d.r.readn4()))); i >= 0 { - ui = uint64(i) - } else { - halt.errorf("assigning negative signed value: %v, to unsigned type", i) - } - case mpInt64: - if i := int64(bigen.Uint64(d.r.readn8())); i >= 0 { - ui = uint64(i) - } else { - halt.errorf("assigning negative signed value: %v, to unsigned type", i) - } - case mpFloat: - if f := d.decFloat4Int32(); f >= 0 { - ui = uint64(f) - } else { - halt.errorf("assigning negative float value: %v, to unsigned type", f) - } - case mpDouble: - if f := d.decFloat4Int64(); f >= 0 { - ui = uint64(f) - } else { - halt.errorf("assigning negative float value: %v, to unsigned type", f) - } - default: - switch { - case d.bd >= mpPosFixNumMin && d.bd <= mpPosFixNumMax: - ui = uint64(d.bd) - case d.bd >= mpNegFixNumMin && d.bd <= mpNegFixNumMax: - halt.errorf("assigning negative signed value: %v, to unsigned type", int(d.bd)) - default: - halt.errorf("cannot decode unsigned integer: %s: %x/%s", msgBadDesc, d.bd, mpdesc(d.bd)) - } - } - d.bdRead = false - return -} - -// float can either be decoded from msgpack type: float, double or intX -func (d *msgpackDecDriver[T]) DecodeFloat64() (f float64) { - if d.advanceNil() { - return - } - if d.bd == mpFloat { - f = float64(math.Float32frombits(bigen.Uint32(d.r.readn4()))) - } else if d.bd == mpDouble { - f = math.Float64frombits(bigen.Uint64(d.r.readn8())) - } else { - f = float64(d.DecodeInt64()) - } - d.bdRead = false - return -} - -// bool can be decoded from bool, fixnum 0 or 1. -func (d *msgpackDecDriver[T]) DecodeBool() (b bool) { - if d.advanceNil() { - return - } - if d.bd == mpFalse || d.bd == 0 { - // b = false - } else if d.bd == mpTrue || d.bd == 1 { - b = true - } else { - halt.errorf("cannot decode bool: %s: %x/%s", msgBadDesc, d.bd, mpdesc(d.bd)) - } - d.bdRead = false - return -} - -func (d *msgpackDecDriver[T]) DecodeBytes() (bs []byte, state dBytesAttachState) { - if d.advanceNil() { - return - } - - var cond bool - bd := d.bd - var clen int - if bd == mpBin8 || bd == mpBin16 || bd == mpBin32 { - clen = d.readContainerLen(msgpackContainerBin) // binary - } else if bd == mpStr8 || bd == mpStr16 || bd == mpStr32 || - (bd >= mpFixStrMin && bd <= mpFixStrMax) { - clen = d.readContainerLen(msgpackContainerStr) // string/raw - } else if bd == mpArray16 || bd == mpArray32 || - (bd >= mpFixArrayMin && bd <= mpFixArrayMax) { - slen := d.ReadArrayStart() - bs, cond = usableByteSlice(d.d.buf, slen) - for i := 0; i < len(bs); i++ { - bs[i] = uint8(chkOvf.UintV(d.DecodeUint64(), 8)) - } - for i := len(bs); i < slen; i++ { - bs = append(bs, uint8(chkOvf.UintV(d.DecodeUint64(), 8))) - } - if cond { - d.d.buf = bs - } - state = dBytesAttachBuffer - return - } else { - halt.errorf("invalid byte descriptor for decoding bytes, got: 0x%x", d.bd) - } - - d.bdRead = false - bs, cond = d.r.readxb(uint(clen)) - state = d.d.attachState(cond) - return -} - -func (d *msgpackDecDriver[T]) DecodeStringAsBytes() (out []byte, state dBytesAttachState) { - out, state = d.DecodeBytes() - if d.h.ValidateUnicode && !utf8.Valid(out) { - halt.errorf("DecodeStringAsBytes: invalid UTF-8: %s", out) - } - return -} - -func (d *msgpackDecDriver[T]) readNextBd() { - d.bd = d.r.readn1() - d.bdRead = true -} - -func (d *msgpackDecDriver[T]) advanceNil() (null bool) { - if !d.bdRead { - d.readNextBd() - } - if d.bd == mpNil { - d.bdRead = false - return true // null = true - } - return -} - -func (d *msgpackDecDriver[T]) TryNil() (v bool) { - return d.advanceNil() -} - -func (d *msgpackDecDriver[T]) ContainerType() (vt valueType) { - if !d.bdRead { - d.readNextBd() - } - bd := d.bd - if bd == mpNil { - d.bdRead = false - return valueTypeNil - } else if bd == mpBin8 || bd == mpBin16 || bd == mpBin32 { - return valueTypeBytes - } else if bd == mpStr8 || bd == mpStr16 || bd == mpStr32 || - (bd >= mpFixStrMin && bd <= mpFixStrMax) { - if d.h.WriteExt || d.h.RawToString { // UTF-8 string (new spec) - return valueTypeString - } - return valueTypeBytes // raw (old spec) - } else if bd == mpArray16 || bd == mpArray32 || (bd >= mpFixArrayMin && bd <= mpFixArrayMax) { - return valueTypeArray - } else if bd == mpMap16 || bd == mpMap32 || (bd >= mpFixMapMin && bd <= mpFixMapMax) { - return valueTypeMap - } - return valueTypeUnset -} - -func (d *msgpackDecDriver[T]) readContainerLen(ct msgpackContainerType) (clen int) { - bd := d.bd - if bd == ct.b8 { - clen = int(d.r.readn1()) - } else if bd == ct.b16 { - clen = int(bigen.Uint16(d.r.readn2())) - } else if bd == ct.b32 { - clen = int(bigen.Uint32(d.r.readn4())) - } else if (ct.bFixMin & bd) == ct.bFixMin { - clen = int(ct.bFixMin ^ bd) - } else { - halt.errorf("cannot read container length: %s: hex: %x, decimal: %d", msgBadDesc, bd, bd) - } - d.bdRead = false - return -} - -func (d *msgpackDecDriver[T]) ReadMapStart() int { - if d.advanceNil() { - return containerLenNil - } - return d.readContainerLen(msgpackContainerMap) -} - -func (d *msgpackDecDriver[T]) ReadArrayStart() int { - if d.advanceNil() { - return containerLenNil - } - return d.readContainerLen(msgpackContainerList) -} - -func (d *msgpackDecDriver[T]) readExtLen() (clen int) { - switch d.bd { - case mpFixExt1: - clen = 1 - case mpFixExt2: - clen = 2 - case mpFixExt4: - clen = 4 - case mpFixExt8: - clen = 8 - case mpFixExt16: - clen = 16 - case mpExt8: - clen = int(d.r.readn1()) - case mpExt16: - clen = int(bigen.Uint16(d.r.readn2())) - case mpExt32: - clen = int(bigen.Uint32(d.r.readn4())) - default: - halt.errorf("decoding ext bytes: found unexpected byte: %x", d.bd) - } - return -} - -func (d *msgpackDecDriver[T]) DecodeTime() (t time.Time) { - // decode time from string bytes or ext - if d.advanceNil() { - return - } - bd := d.bd - var clen int - if bd == mpBin8 || bd == mpBin16 || bd == mpBin32 { - clen = d.readContainerLen(msgpackContainerBin) // binary - } else if bd == mpStr8 || bd == mpStr16 || bd == mpStr32 || - (bd >= mpFixStrMin && bd <= mpFixStrMax) { - clen = d.readContainerLen(msgpackContainerStr) // string/raw - } else { - // expect to see mpFixExt4,-1 OR mpFixExt8,-1 OR mpExt8,12,-1 - d.bdRead = false - b2 := d.r.readn1() - if d.bd == mpFixExt4 && b2 == mpTimeExtTagU { - clen = 4 - } else if d.bd == mpFixExt8 && b2 == mpTimeExtTagU { - clen = 8 - } else if d.bd == mpExt8 && b2 == 12 && d.r.readn1() == mpTimeExtTagU { - clen = 12 - } else { - halt.errorf("invalid stream for decoding time as extension: got 0x%x, 0x%x", d.bd, b2) - } - } - return d.decodeTime(clen) -} - -func (d *msgpackDecDriver[T]) decodeTime(clen int) (t time.Time) { - d.bdRead = false - switch clen { - case 4: - t = time.Unix(int64(bigen.Uint32(d.r.readn4())), 0).UTC() - case 8: - tv := bigen.Uint64(d.r.readn8()) - t = time.Unix(int64(tv&0x00000003ffffffff), int64(tv>>34)).UTC() - case 12: - nsec := bigen.Uint32(d.r.readn4()) - sec := bigen.Uint64(d.r.readn8()) - t = time.Unix(int64(sec), int64(nsec)).UTC() - default: - halt.errorf("invalid length of bytes for decoding time - expecting 4 or 8 or 12, got %d", clen) - } - return -} - -func (d *msgpackDecDriver[T]) DecodeExt(rv interface{}, basetype reflect.Type, xtag uint64, ext Ext) { - xbs, _, _, ok := d.decodeExtV(ext != nil, xtag) - if !ok { - return - } - if ext == SelfExt { - sideDecode(d.h, &d.h.sideDecPool, func(sd decoderI) { oneOffDecode(sd, rv, xbs, basetype, true) }) - } else { - ext.ReadExt(rv, xbs) - } -} - -func (d *msgpackDecDriver[T]) DecodeRawExt(re *RawExt) { - xbs, realxtag, state, ok := d.decodeExtV(false, 0) - if !ok { - return - } - re.Tag = uint64(realxtag) - re.setData(xbs, state >= dBytesAttachViewZerocopy) -} - -func (d *msgpackDecDriver[T]) decodeExtV(verifyTag bool, xtagIn uint64) (xbs []byte, xtag byte, bstate dBytesAttachState, ok bool) { - if xtagIn > 0xff { - halt.errorf("ext: tag must be <= 0xff; got: %v", xtagIn) - } - if d.advanceNil() { - return - } - tag := uint8(xtagIn) - xbd := d.bd - if xbd == mpBin8 || xbd == mpBin16 || xbd == mpBin32 { - xbs, bstate = d.DecodeBytes() - } else if xbd == mpStr8 || xbd == mpStr16 || xbd == mpStr32 || - (xbd >= mpFixStrMin && xbd <= mpFixStrMax) { - xbs, bstate = d.DecodeStringAsBytes() - } else { - clen := d.readExtLen() - xtag = d.r.readn1() - if verifyTag && xtag != tag { - halt.errorf("wrong extension tag - got %b, expecting %v", xtag, tag) - } - xbs, ok = d.r.readxb(uint(clen)) - bstate = d.d.attachState(ok) - // zerocopy = d.d.bytes - } - d.bdRead = false - ok = true - return -} - -// ---- -// -// The following below are similar across all format files (except for the format name). -// -// We keep them together here, so that we can easily copy and compare. - -// ---- - -func (d *msgpackEncDriver[T]) init(hh Handle, shared *encoderBase, enc encoderI) (fp interface{}) { - callMake(&d.w) - d.h = hh.(*MsgpackHandle) - d.e = shared - if shared.bytes { - fp = msgpackFpEncBytes - } else { - fp = msgpackFpEncIO - } - // d.w.init() - d.init2(enc) - return -} - -func (e *msgpackEncDriver[T]) writeBytesAsis(b []byte) { e.w.writeb(b) } - -// func (e *msgpackEncDriver[T]) writeStringAsisDblQuoted(v string) { e.w.writeqstr(v) } - -func (e *msgpackEncDriver[T]) writerEnd() { e.w.end() } - -func (e *msgpackEncDriver[T]) resetOutBytes(out *[]byte) { - e.w.resetBytes(*out, out) -} - -func (e *msgpackEncDriver[T]) resetOutIO(out io.Writer) { - e.w.resetIO(out, e.h.WriterBufferSize, &e.e.blist) -} - -// ---- - -func (d *msgpackDecDriver[T]) init(hh Handle, shared *decoderBase, dec decoderI) (fp interface{}) { - callMake(&d.r) - d.h = hh.(*MsgpackHandle) - d.d = shared - if shared.bytes { - fp = msgpackFpDecBytes - } else { - fp = msgpackFpDecIO - } - // d.r.init() - d.init2(dec) - return -} - -func (d *msgpackDecDriver[T]) NumBytesRead() int { - return int(d.r.numread()) -} - -func (d *msgpackDecDriver[T]) resetInBytes(in []byte) { - d.r.resetBytes(in) -} - -func (d *msgpackDecDriver[T]) resetInIO(r io.Reader) { - d.r.resetIO(r, d.h.ReaderBufferSize, d.h.MaxInitLen, &d.d.blist) -} - -// ---- (custom stanza) - -func (d *msgpackDecDriver[T]) descBd() string { - return sprintf("%v (%s)", d.bd, mpdesc(d.bd)) -} - -func (d *msgpackDecDriver[T]) DecodeFloat32() (f float32) { - return float32(chkOvf.Float32V(d.DecodeFloat64())) -} diff --git a/vendor/github.com/ugorji/go/codec/msgpack.mono.generated.go b/vendor/github.com/ugorji/go/codec/msgpack.mono.generated.go deleted file mode 100644 index ff2fe4af9..000000000 --- a/vendor/github.com/ugorji/go/codec/msgpack.mono.generated.go +++ /dev/null @@ -1,8046 +0,0 @@ -//go:build !notmono && !codec.notmono - -// Copyright (c) 2012-2020 Ugorji Nwoke. All rights reserved. -// Use of this source code is governed by a MIT license found in the LICENSE file. - -package codec - -import ( - "encoding" - - "io" - "math" - "reflect" - "slices" - "sort" - "strconv" - "sync" - "time" - "unicode/utf8" -) - -type helperEncDriverMsgpackBytes struct{} -type encFnMsgpackBytes struct { - i encFnInfo - fe func(*encoderMsgpackBytes, *encFnInfo, reflect.Value) -} -type encRtidFnMsgpackBytes struct { - rtid uintptr - fn *encFnMsgpackBytes -} -type encoderMsgpackBytes struct { - dh helperEncDriverMsgpackBytes - fp *fastpathEsMsgpackBytes - e msgpackEncDriverBytes - encoderBase -} -type helperDecDriverMsgpackBytes struct{} -type decFnMsgpackBytes struct { - i decFnInfo - fd func(*decoderMsgpackBytes, *decFnInfo, reflect.Value) -} -type decRtidFnMsgpackBytes struct { - rtid uintptr - fn *decFnMsgpackBytes -} -type decoderMsgpackBytes struct { - dh helperDecDriverMsgpackBytes - fp *fastpathDsMsgpackBytes - d msgpackDecDriverBytes - decoderBase -} -type msgpackEncDriverBytes struct { - noBuiltInTypes - encDriverNoopContainerWriter - encDriverNoState - encDriverContainerNoTrackerT - encInit2er - - h *MsgpackHandle - e *encoderBase - w bytesEncAppender -} -type msgpackDecDriverBytes struct { - decDriverNoopContainerReader - decDriverNoopNumberHelper - decInit2er - - h *MsgpackHandle - d *decoderBase - r bytesDecReader - - bdAndBdread - - noBuiltInTypes -} - -func (e *encoderMsgpackBytes) rawExt(_ *encFnInfo, rv reflect.Value) { - if re := rv2i(rv).(*RawExt); re == nil { - e.e.EncodeNil() - } else { - e.e.EncodeRawExt(re) - } -} - -func (e *encoderMsgpackBytes) ext(f *encFnInfo, rv reflect.Value) { - e.e.EncodeExt(rv2i(rv), f.ti.rt, f.xfTag, f.xfFn) -} - -func (e *encoderMsgpackBytes) selferMarshal(_ *encFnInfo, rv reflect.Value) { - rv2i(rv).(Selfer).CodecEncodeSelf(&Encoder{e}) -} - -func (e *encoderMsgpackBytes) binaryMarshal(_ *encFnInfo, rv reflect.Value) { - bs, fnerr := rv2i(rv).(encoding.BinaryMarshaler).MarshalBinary() - e.marshalRaw(bs, fnerr) -} - -func (e *encoderMsgpackBytes) textMarshal(_ *encFnInfo, rv reflect.Value) { - bs, fnerr := rv2i(rv).(encoding.TextMarshaler).MarshalText() - e.marshalUtf8(bs, fnerr) -} - -func (e *encoderMsgpackBytes) jsonMarshal(_ *encFnInfo, rv reflect.Value) { - bs, fnerr := rv2i(rv).(jsonMarshaler).MarshalJSON() - e.marshalAsis(bs, fnerr) -} - -func (e *encoderMsgpackBytes) raw(_ *encFnInfo, rv reflect.Value) { - e.rawBytes(rv2i(rv).(Raw)) -} - -func (e *encoderMsgpackBytes) encodeComplex64(v complex64) { - if imag(v) != 0 { - halt.errorf("cannot encode complex number: %v, with imaginary values: %v", any(v), any(imag(v))) - } - e.e.EncodeFloat32(real(v)) -} - -func (e *encoderMsgpackBytes) encodeComplex128(v complex128) { - if imag(v) != 0 { - halt.errorf("cannot encode complex number: %v, with imaginary values: %v", any(v), any(imag(v))) - } - e.e.EncodeFloat64(real(v)) -} - -func (e *encoderMsgpackBytes) kBool(_ *encFnInfo, rv reflect.Value) { - e.e.EncodeBool(rvGetBool(rv)) -} - -func (e *encoderMsgpackBytes) kTime(_ *encFnInfo, rv reflect.Value) { - e.e.EncodeTime(rvGetTime(rv)) -} - -func (e *encoderMsgpackBytes) kString(_ *encFnInfo, rv reflect.Value) { - e.e.EncodeString(rvGetString(rv)) -} - -func (e *encoderMsgpackBytes) kFloat32(_ *encFnInfo, rv reflect.Value) { - e.e.EncodeFloat32(rvGetFloat32(rv)) -} - -func (e *encoderMsgpackBytes) kFloat64(_ *encFnInfo, rv reflect.Value) { - e.e.EncodeFloat64(rvGetFloat64(rv)) -} - -func (e *encoderMsgpackBytes) kComplex64(_ *encFnInfo, rv reflect.Value) { - e.encodeComplex64(rvGetComplex64(rv)) -} - -func (e *encoderMsgpackBytes) kComplex128(_ *encFnInfo, rv reflect.Value) { - e.encodeComplex128(rvGetComplex128(rv)) -} - -func (e *encoderMsgpackBytes) kInt(_ *encFnInfo, rv reflect.Value) { - e.e.EncodeInt(int64(rvGetInt(rv))) -} - -func (e *encoderMsgpackBytes) kInt8(_ *encFnInfo, rv reflect.Value) { - e.e.EncodeInt(int64(rvGetInt8(rv))) -} - -func (e *encoderMsgpackBytes) kInt16(_ *encFnInfo, rv reflect.Value) { - e.e.EncodeInt(int64(rvGetInt16(rv))) -} - -func (e *encoderMsgpackBytes) kInt32(_ *encFnInfo, rv reflect.Value) { - e.e.EncodeInt(int64(rvGetInt32(rv))) -} - -func (e *encoderMsgpackBytes) kInt64(_ *encFnInfo, rv reflect.Value) { - e.e.EncodeInt(int64(rvGetInt64(rv))) -} - -func (e *encoderMsgpackBytes) kUint(_ *encFnInfo, rv reflect.Value) { - e.e.EncodeUint(uint64(rvGetUint(rv))) -} - -func (e *encoderMsgpackBytes) kUint8(_ *encFnInfo, rv reflect.Value) { - e.e.EncodeUint(uint64(rvGetUint8(rv))) -} - -func (e *encoderMsgpackBytes) kUint16(_ *encFnInfo, rv reflect.Value) { - e.e.EncodeUint(uint64(rvGetUint16(rv))) -} - -func (e *encoderMsgpackBytes) kUint32(_ *encFnInfo, rv reflect.Value) { - e.e.EncodeUint(uint64(rvGetUint32(rv))) -} - -func (e *encoderMsgpackBytes) kUint64(_ *encFnInfo, rv reflect.Value) { - e.e.EncodeUint(uint64(rvGetUint64(rv))) -} - -func (e *encoderMsgpackBytes) kUintptr(_ *encFnInfo, rv reflect.Value) { - e.e.EncodeUint(uint64(rvGetUintptr(rv))) -} - -func (e *encoderMsgpackBytes) kSeqFn(rt reflect.Type) (fn *encFnMsgpackBytes) { - - if rt = baseRT(rt); rt.Kind() != reflect.Interface { - fn = e.fn(rt) - } - return -} - -func (e *encoderMsgpackBytes) kArrayWMbs(rv reflect.Value, ti *typeInfo, isSlice bool) { - var l int - if isSlice { - l = rvLenSlice(rv) - } else { - l = rv.Len() - } - if l == 0 { - e.e.WriteMapEmpty() - return - } - e.haltOnMbsOddLen(l) - e.mapStart(l >> 1) - - var fn *encFnMsgpackBytes - builtin := ti.tielem.flagEncBuiltin - if !builtin { - fn = e.kSeqFn(ti.elem) - } - - j := 0 - e.c = containerMapKey - e.e.WriteMapElemKey(true) - for { - rvv := rvArrayIndex(rv, j, ti, isSlice) - if builtin { - e.encodeIB(rv2i(baseRVRV(rvv))) - } else { - e.encodeValue(rvv, fn) - } - j++ - if j == l { - break - } - if j&1 == 0 { - e.c = containerMapKey - e.e.WriteMapElemKey(false) - } else { - e.mapElemValue() - } - } - e.c = 0 - e.e.WriteMapEnd() - -} - -func (e *encoderMsgpackBytes) kArrayW(rv reflect.Value, ti *typeInfo, isSlice bool) { - var l int - if isSlice { - l = rvLenSlice(rv) - } else { - l = rv.Len() - } - if l <= 0 { - e.e.WriteArrayEmpty() - return - } - e.arrayStart(l) - - var fn *encFnMsgpackBytes - if !ti.tielem.flagEncBuiltin { - fn = e.kSeqFn(ti.elem) - } - - j := 0 - e.c = containerArrayElem - e.e.WriteArrayElem(true) - builtin := ti.tielem.flagEncBuiltin - for { - rvv := rvArrayIndex(rv, j, ti, isSlice) - if builtin { - e.encodeIB(rv2i(baseRVRV(rvv))) - } else { - e.encodeValue(rvv, fn) - } - j++ - if j == l { - break - } - e.c = containerArrayElem - e.e.WriteArrayElem(false) - } - - e.c = 0 - e.e.WriteArrayEnd() -} - -func (e *encoderMsgpackBytes) kChan(f *encFnInfo, rv reflect.Value) { - if f.ti.chandir&uint8(reflect.RecvDir) == 0 { - halt.errorStr("send-only channel cannot be encoded") - } - if !f.ti.mbs && uint8TypId == rt2id(f.ti.elem) { - e.kSliceBytesChan(rv) - return - } - rtslice := reflect.SliceOf(f.ti.elem) - rv = chanToSlice(rv, rtslice, e.h.ChanRecvTimeout) - ti := e.h.getTypeInfo(rt2id(rtslice), rtslice) - if f.ti.mbs { - e.kArrayWMbs(rv, ti, true) - } else { - e.kArrayW(rv, ti, true) - } -} - -func (e *encoderMsgpackBytes) kSlice(f *encFnInfo, rv reflect.Value) { - if f.ti.mbs { - e.kArrayWMbs(rv, f.ti, true) - } else if f.ti.rtid == uint8SliceTypId || uint8TypId == rt2id(f.ti.elem) { - - e.e.EncodeBytes(rvGetBytes(rv)) - } else { - e.kArrayW(rv, f.ti, true) - } -} - -func (e *encoderMsgpackBytes) kArray(f *encFnInfo, rv reflect.Value) { - if f.ti.mbs { - e.kArrayWMbs(rv, f.ti, false) - } else if handleBytesWithinKArray && uint8TypId == rt2id(f.ti.elem) { - e.e.EncodeStringBytesRaw(rvGetArrayBytes(rv, nil)) - } else { - e.kArrayW(rv, f.ti, false) - } -} - -func (e *encoderMsgpackBytes) kSliceBytesChan(rv reflect.Value) { - - bs0 := e.blist.peek(32, true) - bs := bs0 - - irv := rv2i(rv) - ch, ok := irv.(<-chan byte) - if !ok { - ch = irv.(chan byte) - } - -L1: - switch timeout := e.h.ChanRecvTimeout; { - case timeout == 0: - for { - select { - case b := <-ch: - bs = append(bs, b) - default: - break L1 - } - } - case timeout > 0: - tt := time.NewTimer(timeout) - for { - select { - case b := <-ch: - bs = append(bs, b) - case <-tt.C: - - break L1 - } - } - default: - for b := range ch { - bs = append(bs, b) - } - } - - e.e.EncodeBytes(bs) - e.blist.put(bs) - if !byteSliceSameData(bs0, bs) { - e.blist.put(bs0) - } -} - -func (e *encoderMsgpackBytes) kStructFieldKey(keyType valueType, encName string) { - - if keyType == valueTypeString { - e.e.EncodeString(encName) - } else if keyType == valueTypeInt { - e.e.EncodeInt(must.Int(strconv.ParseInt(encName, 10, 64))) - } else if keyType == valueTypeUint { - e.e.EncodeUint(must.Uint(strconv.ParseUint(encName, 10, 64))) - } else if keyType == valueTypeFloat { - e.e.EncodeFloat64(must.Float(strconv.ParseFloat(encName, 64))) - } else { - halt.errorStr2("invalid struct key type: ", keyType.String()) - } - -} - -func (e *encoderMsgpackBytes) kStructSimple(f *encFnInfo, rv reflect.Value) { - _ = e.e - tisfi := f.ti.sfi.source() - - chkCirRef := e.h.CheckCircularRef - var si *structFieldInfo - var j int - - if f.ti.toArray || e.h.StructToArray { - if len(tisfi) == 0 { - e.e.WriteArrayEmpty() - return - } - e.arrayStart(len(tisfi)) - for j, si = range tisfi { - e.c = containerArrayElem - e.e.WriteArrayElem(j == 0) - if si.encBuiltin { - e.encodeIB(rv2i(si.fieldNoAlloc(rv, true))) - } else { - e.encodeValue(si.fieldNoAlloc(rv, !chkCirRef), nil) - } - } - e.c = 0 - e.e.WriteArrayEnd() - } else { - if len(tisfi) == 0 { - e.e.WriteMapEmpty() - return - } - if e.h.Canonical { - tisfi = f.ti.sfi.sorted() - } - e.mapStart(len(tisfi)) - for j, si = range tisfi { - e.c = containerMapKey - e.e.WriteMapElemKey(j == 0) - e.e.EncodeStringNoEscape4Json(si.encName) - e.mapElemValue() - if si.encBuiltin { - e.encodeIB(rv2i(si.fieldNoAlloc(rv, true))) - } else { - e.encodeValue(si.fieldNoAlloc(rv, !chkCirRef), nil) - } - } - e.c = 0 - e.e.WriteMapEnd() - } -} - -func (e *encoderMsgpackBytes) kStruct(f *encFnInfo, rv reflect.Value) { - _ = e.e - ti := f.ti - toMap := !(ti.toArray || e.h.StructToArray) - var mf map[string]interface{} - if ti.flagMissingFielder { - toMap = true - mf = rv2i(rv).(MissingFielder).CodecMissingFields() - } else if ti.flagMissingFielderPtr { - toMap = true - if rv.CanAddr() { - mf = rv2i(rvAddr(rv, ti.ptr)).(MissingFielder).CodecMissingFields() - } else { - mf = rv2i(e.addrRV(rv, ti.rt, ti.ptr)).(MissingFielder).CodecMissingFields() - } - } - newlen := len(mf) - tisfi := ti.sfi.source() - newlen += len(tisfi) - - var fkvs = e.slist.get(newlen)[:newlen] - - recur := e.h.RecursiveEmptyCheck - chkCirRef := e.h.CheckCircularRef - - var xlen int - - var kv sfiRv - var j int - var sf encStructFieldObj - if toMap { - newlen = 0 - if e.h.Canonical { - tisfi = f.ti.sfi.sorted() - } - for _, si := range tisfi { - - if si.omitEmpty { - kv.r = si.fieldNoAlloc(rv, false) - if isEmptyValue(kv.r, e.h.TypeInfos, recur) { - continue - } - } else { - kv.r = si.fieldNoAlloc(rv, si.encBuiltin || !chkCirRef) - } - kv.v = si - fkvs[newlen] = kv - newlen++ - } - - var mf2s []stringIntf - if len(mf) != 0 { - mf2s = make([]stringIntf, 0, len(mf)) - for k, v := range mf { - if k == "" { - continue - } - if ti.infoFieldOmitempty && isEmptyValue(reflect.ValueOf(v), e.h.TypeInfos, recur) { - continue - } - mf2s = append(mf2s, stringIntf{k, v}) - } - } - - xlen = newlen + len(mf2s) - if xlen == 0 { - e.e.WriteMapEmpty() - goto END - } - - e.mapStart(xlen) - - if len(mf2s) != 0 && e.h.Canonical { - mf2w := make([]encStructFieldObj, newlen+len(mf2s)) - for j = 0; j < newlen; j++ { - kv = fkvs[j] - mf2w[j] = encStructFieldObj{kv.v.encName, kv.r, nil, true, - !kv.v.encNameEscape4Json, kv.v.encBuiltin} - } - for _, v := range mf2s { - mf2w[j] = encStructFieldObj{v.v, reflect.Value{}, v.i, false, false, false} - j++ - } - sort.Sort((encStructFieldObjSlice)(mf2w)) - for j, sf = range mf2w { - e.c = containerMapKey - e.e.WriteMapElemKey(j == 0) - if ti.keyType == valueTypeString && sf.noEsc4json { - e.e.EncodeStringNoEscape4Json(sf.key) - } else { - e.kStructFieldKey(ti.keyType, sf.key) - } - e.mapElemValue() - if sf.isRv { - if sf.builtin { - e.encodeIB(rv2i(baseRVRV(sf.rv))) - } else { - e.encodeValue(sf.rv, nil) - } - } else { - if !e.encodeBuiltin(sf.intf) { - e.encodeR(reflect.ValueOf(sf.intf)) - } - - } - } - } else { - keytyp := ti.keyType - for j = 0; j < newlen; j++ { - kv = fkvs[j] - e.c = containerMapKey - e.e.WriteMapElemKey(j == 0) - if ti.keyType == valueTypeString && !kv.v.encNameEscape4Json { - e.e.EncodeStringNoEscape4Json(kv.v.encName) - } else { - e.kStructFieldKey(keytyp, kv.v.encName) - } - e.mapElemValue() - if kv.v.encBuiltin { - e.encodeIB(rv2i(baseRVRV(kv.r))) - } else { - e.encodeValue(kv.r, nil) - } - } - for _, v := range mf2s { - e.c = containerMapKey - e.e.WriteMapElemKey(j == 0) - e.kStructFieldKey(keytyp, v.v) - e.mapElemValue() - if !e.encodeBuiltin(v.i) { - e.encodeR(reflect.ValueOf(v.i)) - } - - j++ - } - } - - e.c = 0 - e.e.WriteMapEnd() - } else { - newlen = len(tisfi) - for i, si := range tisfi { - - if si.omitEmpty { - - kv.r = si.fieldNoAlloc(rv, false) - if isEmptyContainerValue(kv.r, e.h.TypeInfos, recur) { - kv.r = reflect.Value{} - } - } else { - kv.r = si.fieldNoAlloc(rv, si.encBuiltin || !chkCirRef) - } - kv.v = si - fkvs[i] = kv - } - - if newlen == 0 { - e.e.WriteArrayEmpty() - goto END - } - - e.arrayStart(newlen) - for j = 0; j < newlen; j++ { - e.c = containerArrayElem - e.e.WriteArrayElem(j == 0) - kv = fkvs[j] - if !kv.r.IsValid() { - e.e.EncodeNil() - } else if kv.v.encBuiltin { - e.encodeIB(rv2i(baseRVRV(kv.r))) - } else { - e.encodeValue(kv.r, nil) - } - } - e.c = 0 - e.e.WriteArrayEnd() - } - -END: - - e.slist.put(fkvs) -} - -func (e *encoderMsgpackBytes) kMap(f *encFnInfo, rv reflect.Value) { - _ = e.e - l := rvLenMap(rv) - if l == 0 { - e.e.WriteMapEmpty() - return - } - e.mapStart(l) - - var keyFn, valFn *encFnMsgpackBytes - - ktypeKind := reflect.Kind(f.ti.keykind) - vtypeKind := reflect.Kind(f.ti.elemkind) - - rtval := f.ti.elem - rtvalkind := vtypeKind - for rtvalkind == reflect.Ptr { - rtval = rtval.Elem() - rtvalkind = rtval.Kind() - } - if rtvalkind != reflect.Interface { - valFn = e.fn(rtval) - } - - var rvv = mapAddrLoopvarRV(f.ti.elem, vtypeKind) - - rtkey := f.ti.key - var keyTypeIsString = stringTypId == rt2id(rtkey) - if keyTypeIsString { - keyFn = e.fn(rtkey) - } else { - for rtkey.Kind() == reflect.Ptr { - rtkey = rtkey.Elem() - } - if rtkey.Kind() != reflect.Interface { - keyFn = e.fn(rtkey) - } - } - - if e.h.Canonical { - e.kMapCanonical(f.ti, rv, rvv, keyFn, valFn) - e.c = 0 - e.e.WriteMapEnd() - return - } - - var rvk = mapAddrLoopvarRV(f.ti.key, ktypeKind) - - var it mapIter - mapRange(&it, rv, rvk, rvv, true) - - kbuiltin := f.ti.tikey.flagEncBuiltin - vbuiltin := f.ti.tielem.flagEncBuiltin - for j := 0; it.Next(); j++ { - rv = it.Key() - e.c = containerMapKey - e.e.WriteMapElemKey(j == 0) - if keyTypeIsString { - e.e.EncodeString(rvGetString(rv)) - } else if kbuiltin { - e.encodeIB(rv2i(baseRVRV(rv))) - } else { - e.encodeValue(rv, keyFn) - } - e.mapElemValue() - rv = it.Value() - if vbuiltin { - e.encodeIB(rv2i(baseRVRV(rv))) - } else { - e.encodeValue(it.Value(), valFn) - } - } - it.Done() - - e.c = 0 - e.e.WriteMapEnd() -} - -func (e *encoderMsgpackBytes) kMapCanonical(ti *typeInfo, rv, rvv reflect.Value, keyFn, valFn *encFnMsgpackBytes) { - _ = e.e - - rtkey := ti.key - rtkeydecl := rtkey.PkgPath() == "" && rtkey.Name() != "" - - mks := rv.MapKeys() - rtkeyKind := rtkey.Kind() - mparams := getMapReqParams(ti) - - switch rtkeyKind { - case reflect.Bool: - - if len(mks) == 2 && mks[0].Bool() { - mks[0], mks[1] = mks[1], mks[0] - } - for i := range mks { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - if rtkeydecl { - e.e.EncodeBool(mks[i].Bool()) - } else { - e.encodeValueNonNil(mks[i], keyFn) - } - e.mapElemValue() - e.encodeValue(mapGet(rv, mks[i], rvv, mparams), valFn) - } - case reflect.String: - mksv := make([]orderedRv[string], len(mks)) - for i, k := range mks { - v := &mksv[i] - v.r = k - v.v = rvGetString(k) - } - slices.SortFunc(mksv, cmpOrderedRv) - for i := range mksv { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - if rtkeydecl { - e.e.EncodeString(mksv[i].v) - } else { - e.encodeValueNonNil(mksv[i].r, keyFn) - } - e.mapElemValue() - e.encodeValue(mapGet(rv, mksv[i].r, rvv, mparams), valFn) - } - case reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64, reflect.Uint, reflect.Uintptr: - mksv := make([]orderedRv[uint64], len(mks)) - for i, k := range mks { - v := &mksv[i] - v.r = k - v.v = k.Uint() - } - slices.SortFunc(mksv, cmpOrderedRv) - for i := range mksv { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - if rtkeydecl { - e.e.EncodeUint(mksv[i].v) - } else { - e.encodeValueNonNil(mksv[i].r, keyFn) - } - e.mapElemValue() - e.encodeValue(mapGet(rv, mksv[i].r, rvv, mparams), valFn) - } - case reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64, reflect.Int: - mksv := make([]orderedRv[int64], len(mks)) - for i, k := range mks { - v := &mksv[i] - v.r = k - v.v = k.Int() - } - slices.SortFunc(mksv, cmpOrderedRv) - for i := range mksv { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - if rtkeydecl { - e.e.EncodeInt(mksv[i].v) - } else { - e.encodeValueNonNil(mksv[i].r, keyFn) - } - e.mapElemValue() - e.encodeValue(mapGet(rv, mksv[i].r, rvv, mparams), valFn) - } - case reflect.Float32: - mksv := make([]orderedRv[float64], len(mks)) - for i, k := range mks { - v := &mksv[i] - v.r = k - v.v = k.Float() - } - slices.SortFunc(mksv, cmpOrderedRv) - for i := range mksv { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - if rtkeydecl { - e.e.EncodeFloat32(float32(mksv[i].v)) - } else { - e.encodeValueNonNil(mksv[i].r, keyFn) - } - e.mapElemValue() - e.encodeValue(mapGet(rv, mksv[i].r, rvv, mparams), valFn) - } - case reflect.Float64: - mksv := make([]orderedRv[float64], len(mks)) - for i, k := range mks { - v := &mksv[i] - v.r = k - v.v = k.Float() - } - slices.SortFunc(mksv, cmpOrderedRv) - for i := range mksv { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - if rtkeydecl { - e.e.EncodeFloat64(mksv[i].v) - } else { - e.encodeValueNonNil(mksv[i].r, keyFn) - } - e.mapElemValue() - e.encodeValue(mapGet(rv, mksv[i].r, rvv, mparams), valFn) - } - default: - if rtkey == timeTyp { - mksv := make([]timeRv, len(mks)) - for i, k := range mks { - v := &mksv[i] - v.r = k - v.v = rv2i(k).(time.Time) - } - slices.SortFunc(mksv, cmpTimeRv) - for i := range mksv { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeTime(mksv[i].v) - e.mapElemValue() - e.encodeValue(mapGet(rv, mksv[i].r, rvv, mparams), valFn) - } - break - } - - bs0 := e.blist.get(len(mks) * 16) - mksv := bs0 - mksbv := make([]bytesRv, len(mks)) - - sideEncode(e.hh, &e.h.sideEncPool, func(se encoderI) { - se.ResetBytes(&mksv) - for i, k := range mks { - v := &mksbv[i] - l := len(mksv) - se.setContainerState(containerMapKey) - se.encodeR(baseRVRV(k)) - se.atEndOfEncode() - se.writerEnd() - v.r = k - v.v = mksv[l:] - } - }) - - slices.SortFunc(mksbv, cmpBytesRv) - for j := range mksbv { - e.c = containerMapKey - e.e.WriteMapElemKey(j == 0) - e.e.writeBytesAsis(mksbv[j].v) - e.mapElemValue() - e.encodeValue(mapGet(rv, mksbv[j].r, rvv, mparams), valFn) - } - e.blist.put(mksv) - if !byteSliceSameData(bs0, mksv) { - e.blist.put(bs0) - } - } -} - -func (e *encoderMsgpackBytes) init(h Handle) { - initHandle(h) - callMake(&e.e) - e.hh = h - e.h = h.getBasicHandle() - - e.err = errEncoderNotInitialized - - e.fp = e.e.init(h, &e.encoderBase, e).(*fastpathEsMsgpackBytes) - - if e.bytes { - e.rtidFn = &e.h.rtidFnsEncBytes - e.rtidFnNoExt = &e.h.rtidFnsEncNoExtBytes - } else { - e.rtidFn = &e.h.rtidFnsEncIO - e.rtidFnNoExt = &e.h.rtidFnsEncNoExtIO - } - - e.reset() -} - -func (e *encoderMsgpackBytes) reset() { - e.e.reset() - if e.ci != nil { - e.ci = e.ci[:0] - } - e.c = 0 - e.calls = 0 - e.seq = 0 - e.err = nil -} - -func (e *encoderMsgpackBytes) Encode(v interface{}) (err error) { - - defer panicValToErr(e, callRecoverSentinel, &e.err, &err, debugging) - e.mustEncode(v) - return -} - -func (e *encoderMsgpackBytes) MustEncode(v interface{}) { - defer panicValToErr(e, callRecoverSentinel, &e.err, nil, true) - e.mustEncode(v) - return -} - -func (e *encoderMsgpackBytes) mustEncode(v interface{}) { - halt.onerror(e.err) - if e.hh == nil { - halt.onerror(errNoFormatHandle) - } - - e.calls++ - if !e.encodeBuiltin(v) { - e.encodeR(reflect.ValueOf(v)) - } - - e.calls-- - if e.calls == 0 { - e.e.atEndOfEncode() - e.e.writerEnd() - } -} - -func (e *encoderMsgpackBytes) encodeI(iv interface{}) { - if !e.encodeBuiltin(iv) { - e.encodeR(reflect.ValueOf(iv)) - } -} - -func (e *encoderMsgpackBytes) encodeIB(iv interface{}) { - if !e.encodeBuiltin(iv) { - - halt.errorStr("[should not happen] invalid type passed to encodeBuiltin") - } -} - -func (e *encoderMsgpackBytes) encodeR(base reflect.Value) { - e.encodeValue(base, nil) -} - -func (e *encoderMsgpackBytes) encodeBuiltin(iv interface{}) (ok bool) { - ok = true - switch v := iv.(type) { - case nil: - e.e.EncodeNil() - - case Raw: - e.rawBytes(v) - case string: - e.e.EncodeString(v) - case bool: - e.e.EncodeBool(v) - case int: - e.e.EncodeInt(int64(v)) - case int8: - e.e.EncodeInt(int64(v)) - case int16: - e.e.EncodeInt(int64(v)) - case int32: - e.e.EncodeInt(int64(v)) - case int64: - e.e.EncodeInt(v) - case uint: - e.e.EncodeUint(uint64(v)) - case uint8: - e.e.EncodeUint(uint64(v)) - case uint16: - e.e.EncodeUint(uint64(v)) - case uint32: - e.e.EncodeUint(uint64(v)) - case uint64: - e.e.EncodeUint(v) - case uintptr: - e.e.EncodeUint(uint64(v)) - case float32: - e.e.EncodeFloat32(v) - case float64: - e.e.EncodeFloat64(v) - case complex64: - e.encodeComplex64(v) - case complex128: - e.encodeComplex128(v) - case time.Time: - e.e.EncodeTime(v) - case []byte: - e.e.EncodeBytes(v) - default: - - ok = !skipFastpathTypeSwitchInDirectCall && e.dh.fastpathEncodeTypeSwitch(iv, e) - } - return -} - -func (e *encoderMsgpackBytes) encodeValue(rv reflect.Value, fn *encFnMsgpackBytes) { - - var ciPushes int - - var rvp reflect.Value - var rvpValid bool - -RV: - switch rv.Kind() { - case reflect.Ptr: - if rvIsNil(rv) { - e.e.EncodeNil() - goto END - } - rvpValid = true - rvp = rv - rv = rv.Elem() - - if e.h.CheckCircularRef && e.ci.canPushElemKind(rv.Kind()) { - e.ci.push(rv2i(rvp)) - ciPushes++ - } - goto RV - case reflect.Interface: - if rvIsNil(rv) { - e.e.EncodeNil() - goto END - } - rvpValid = false - rvp = reflect.Value{} - rv = rv.Elem() - fn = nil - goto RV - case reflect.Map: - if rvIsNil(rv) { - if e.h.NilCollectionToZeroLength { - e.e.WriteMapEmpty() - } else { - e.e.EncodeNil() - } - goto END - } - case reflect.Slice, reflect.Chan: - if rvIsNil(rv) { - if e.h.NilCollectionToZeroLength { - e.e.WriteArrayEmpty() - } else { - e.e.EncodeNil() - } - goto END - } - case reflect.Invalid, reflect.Func: - e.e.EncodeNil() - goto END - } - - if fn == nil { - fn = e.fn(rv.Type()) - } - - if !fn.i.addrE { - - } else if rvpValid { - rv = rvp - } else if rv.CanAddr() { - rv = rvAddr(rv, fn.i.ti.ptr) - } else { - rv = e.addrRV(rv, fn.i.ti.rt, fn.i.ti.ptr) - } - fn.fe(e, &fn.i, rv) - -END: - if ciPushes > 0 { - e.ci.pop(ciPushes) - } -} - -func (e *encoderMsgpackBytes) encodeValueNonNil(rv reflect.Value, fn *encFnMsgpackBytes) { - - if fn.i.addrE { - if rv.CanAddr() { - rv = rvAddr(rv, fn.i.ti.ptr) - } else { - rv = e.addrRV(rv, fn.i.ti.rt, fn.i.ti.ptr) - } - } - fn.fe(e, &fn.i, rv) -} - -func (e *encoderMsgpackBytes) encodeAs(v interface{}, t reflect.Type, ext bool) { - if ext { - e.encodeValue(baseRV(v), e.fn(t)) - } else { - e.encodeValue(baseRV(v), e.fnNoExt(t)) - } -} - -func (e *encoderMsgpackBytes) marshalUtf8(bs []byte, fnerr error) { - halt.onerror(fnerr) - if bs == nil { - e.e.EncodeNil() - } else { - e.e.EncodeString(stringView(bs)) - } -} - -func (e *encoderMsgpackBytes) marshalAsis(bs []byte, fnerr error) { - halt.onerror(fnerr) - if bs == nil { - e.e.EncodeNil() - } else { - e.e.writeBytesAsis(bs) - } -} - -func (e *encoderMsgpackBytes) marshalRaw(bs []byte, fnerr error) { - halt.onerror(fnerr) - e.e.EncodeBytes(bs) -} - -func (e *encoderMsgpackBytes) rawBytes(vv Raw) { - v := []byte(vv) - if !e.h.Raw { - halt.errorBytes("Raw values cannot be encoded: ", v) - } - e.e.writeBytesAsis(v) -} - -func (e *encoderMsgpackBytes) fn(t reflect.Type) *encFnMsgpackBytes { - return e.dh.encFnViaBH(t, e.rtidFn, e.h, e.fp, false) -} - -func (e *encoderMsgpackBytes) fnNoExt(t reflect.Type) *encFnMsgpackBytes { - return e.dh.encFnViaBH(t, e.rtidFnNoExt, e.h, e.fp, true) -} - -func (e *encoderMsgpackBytes) mapStart(length int) { - e.e.WriteMapStart(length) - e.c = containerMapStart -} - -func (e *encoderMsgpackBytes) mapElemValue() { - e.e.WriteMapElemValue() - e.c = containerMapValue -} - -func (e *encoderMsgpackBytes) arrayStart(length int) { - e.e.WriteArrayStart(length) - e.c = containerArrayStart -} - -func (e *encoderMsgpackBytes) writerEnd() { - e.e.writerEnd() -} - -func (e *encoderMsgpackBytes) atEndOfEncode() { - e.e.atEndOfEncode() -} - -func (e *encoderMsgpackBytes) Reset(w io.Writer) { - if e.bytes { - halt.onerror(errEncNoResetBytesWithWriter) - } - e.reset() - if w == nil { - w = io.Discard - } - e.e.resetOutIO(w) -} - -func (e *encoderMsgpackBytes) ResetBytes(out *[]byte) { - if !e.bytes { - halt.onerror(errEncNoResetWriterWithBytes) - } - e.resetBytes(out) -} - -func (e *encoderMsgpackBytes) resetBytes(out *[]byte) { - e.reset() - if out == nil { - out = &bytesEncAppenderDefOut - } - e.e.resetOutBytes(out) -} - -func (helperEncDriverMsgpackBytes) newEncoderBytes(out *[]byte, h Handle) *encoderMsgpackBytes { - var c1 encoderMsgpackBytes - c1.bytes = true - c1.init(h) - c1.ResetBytes(out) - return &c1 -} - -func (helperEncDriverMsgpackBytes) newEncoderIO(out io.Writer, h Handle) *encoderMsgpackBytes { - var c1 encoderMsgpackBytes - c1.bytes = false - c1.init(h) - c1.Reset(out) - return &c1 -} - -func (helperEncDriverMsgpackBytes) encFnloadFastpathUnderlying(ti *typeInfo, fp *fastpathEsMsgpackBytes) (f *fastpathEMsgpackBytes, u reflect.Type) { - rtid := rt2id(ti.fastpathUnderlying) - idx, ok := fastpathAvIndex(rtid) - if !ok { - return - } - f = &fp[idx] - if uint8(reflect.Array) == ti.kind { - u = reflect.ArrayOf(ti.rt.Len(), ti.elem) - } else { - u = f.rt - } - return -} - -func (helperEncDriverMsgpackBytes) encFindRtidFn(s []encRtidFnMsgpackBytes, rtid uintptr) (i uint, fn *encFnMsgpackBytes) { - - var h uint - var j = uint(len(s)) -LOOP: - if i < j { - h = (i + j) >> 1 - if s[h].rtid < rtid { - i = h + 1 - } else { - j = h - } - goto LOOP - } - if i < uint(len(s)) && s[i].rtid == rtid { - fn = s[i].fn - } - return -} - -func (helperEncDriverMsgpackBytes) encFromRtidFnSlice(fns *atomicRtidFnSlice) (s []encRtidFnMsgpackBytes) { - if v := fns.load(); v != nil { - s = *(lowLevelToPtr[[]encRtidFnMsgpackBytes](v)) - } - return -} - -func (dh helperEncDriverMsgpackBytes) encFnViaBH(rt reflect.Type, fns *atomicRtidFnSlice, - x *BasicHandle, fp *fastpathEsMsgpackBytes, checkExt bool) (fn *encFnMsgpackBytes) { - return dh.encFnVia(rt, fns, x.typeInfos(), &x.mu, x.extHandle, fp, - checkExt, x.CheckCircularRef, x.timeBuiltin, x.binaryHandle, x.jsonHandle) -} - -func (dh helperEncDriverMsgpackBytes) encFnVia(rt reflect.Type, fns *atomicRtidFnSlice, - tinfos *TypeInfos, mu *sync.Mutex, exth extHandle, fp *fastpathEsMsgpackBytes, - checkExt, checkCircularRef, timeBuiltin, binaryEncoding, json bool) (fn *encFnMsgpackBytes) { - rtid := rt2id(rt) - var sp []encRtidFnMsgpackBytes = dh.encFromRtidFnSlice(fns) - if sp != nil { - _, fn = dh.encFindRtidFn(sp, rtid) - } - if fn == nil { - fn = dh.encFnViaLoader(rt, rtid, fns, tinfos, mu, exth, fp, checkExt, checkCircularRef, timeBuiltin, binaryEncoding, json) - } - return -} - -func (dh helperEncDriverMsgpackBytes) encFnViaLoader(rt reflect.Type, rtid uintptr, fns *atomicRtidFnSlice, - tinfos *TypeInfos, mu *sync.Mutex, exth extHandle, fp *fastpathEsMsgpackBytes, - checkExt, checkCircularRef, timeBuiltin, binaryEncoding, json bool) (fn *encFnMsgpackBytes) { - - fn = dh.encFnLoad(rt, rtid, tinfos, exth, fp, checkExt, checkCircularRef, timeBuiltin, binaryEncoding, json) - var sp []encRtidFnMsgpackBytes - mu.Lock() - sp = dh.encFromRtidFnSlice(fns) - - if sp == nil { - sp = []encRtidFnMsgpackBytes{{rtid, fn}} - fns.store(ptrToLowLevel(&sp)) - } else { - idx, fn2 := dh.encFindRtidFn(sp, rtid) - if fn2 == nil { - sp2 := make([]encRtidFnMsgpackBytes, len(sp)+1) - copy(sp2[idx+1:], sp[idx:]) - copy(sp2, sp[:idx]) - sp2[idx] = encRtidFnMsgpackBytes{rtid, fn} - fns.store(ptrToLowLevel(&sp2)) - } - } - mu.Unlock() - return -} - -func (dh helperEncDriverMsgpackBytes) encFnLoad(rt reflect.Type, rtid uintptr, tinfos *TypeInfos, - exth extHandle, fp *fastpathEsMsgpackBytes, - checkExt, checkCircularRef, timeBuiltin, binaryEncoding, json bool) (fn *encFnMsgpackBytes) { - fn = new(encFnMsgpackBytes) - fi := &(fn.i) - ti := tinfos.get(rtid, rt) - fi.ti = ti - rk := reflect.Kind(ti.kind) - - if rtid == timeTypId && timeBuiltin { - fn.fe = (*encoderMsgpackBytes).kTime - } else if rtid == rawTypId { - fn.fe = (*encoderMsgpackBytes).raw - } else if rtid == rawExtTypId { - fn.fe = (*encoderMsgpackBytes).rawExt - fi.addrE = true - } else if xfFn := exth.getExt(rtid, checkExt); xfFn != nil { - fi.xfTag, fi.xfFn = xfFn.tag, xfFn.ext - fn.fe = (*encoderMsgpackBytes).ext - if rk == reflect.Struct || rk == reflect.Array { - fi.addrE = true - } - } else if ti.flagSelfer || ti.flagSelferPtr { - fn.fe = (*encoderMsgpackBytes).selferMarshal - fi.addrE = ti.flagSelferPtr - } else if supportMarshalInterfaces && binaryEncoding && - (ti.flagBinaryMarshaler || ti.flagBinaryMarshalerPtr) && - (ti.flagBinaryUnmarshaler || ti.flagBinaryUnmarshalerPtr) { - fn.fe = (*encoderMsgpackBytes).binaryMarshal - fi.addrE = ti.flagBinaryMarshalerPtr - } else if supportMarshalInterfaces && !binaryEncoding && json && - (ti.flagJsonMarshaler || ti.flagJsonMarshalerPtr) && - (ti.flagJsonUnmarshaler || ti.flagJsonUnmarshalerPtr) { - - fn.fe = (*encoderMsgpackBytes).jsonMarshal - fi.addrE = ti.flagJsonMarshalerPtr - } else if supportMarshalInterfaces && !binaryEncoding && - (ti.flagTextMarshaler || ti.flagTextMarshalerPtr) && - (ti.flagTextUnmarshaler || ti.flagTextUnmarshalerPtr) { - fn.fe = (*encoderMsgpackBytes).textMarshal - fi.addrE = ti.flagTextMarshalerPtr - } else { - if fastpathEnabled && (rk == reflect.Map || rk == reflect.Slice || rk == reflect.Array) { - - var rtid2 uintptr - if !ti.flagHasPkgPath { - rtid2 = rtid - if rk == reflect.Array { - rtid2 = rt2id(ti.key) - } - if idx, ok := fastpathAvIndex(rtid2); ok { - fn.fe = fp[idx].encfn - } - } else { - - xfe, xrt := dh.encFnloadFastpathUnderlying(ti, fp) - if xfe != nil { - xfnf := xfe.encfn - fn.fe = func(e *encoderMsgpackBytes, xf *encFnInfo, xrv reflect.Value) { - xfnf(e, xf, rvConvert(xrv, xrt)) - } - } - } - } - if fn.fe == nil { - switch rk { - case reflect.Bool: - fn.fe = (*encoderMsgpackBytes).kBool - case reflect.String: - - fn.fe = (*encoderMsgpackBytes).kString - case reflect.Int: - fn.fe = (*encoderMsgpackBytes).kInt - case reflect.Int8: - fn.fe = (*encoderMsgpackBytes).kInt8 - case reflect.Int16: - fn.fe = (*encoderMsgpackBytes).kInt16 - case reflect.Int32: - fn.fe = (*encoderMsgpackBytes).kInt32 - case reflect.Int64: - fn.fe = (*encoderMsgpackBytes).kInt64 - case reflect.Uint: - fn.fe = (*encoderMsgpackBytes).kUint - case reflect.Uint8: - fn.fe = (*encoderMsgpackBytes).kUint8 - case reflect.Uint16: - fn.fe = (*encoderMsgpackBytes).kUint16 - case reflect.Uint32: - fn.fe = (*encoderMsgpackBytes).kUint32 - case reflect.Uint64: - fn.fe = (*encoderMsgpackBytes).kUint64 - case reflect.Uintptr: - fn.fe = (*encoderMsgpackBytes).kUintptr - case reflect.Float32: - fn.fe = (*encoderMsgpackBytes).kFloat32 - case reflect.Float64: - fn.fe = (*encoderMsgpackBytes).kFloat64 - case reflect.Complex64: - fn.fe = (*encoderMsgpackBytes).kComplex64 - case reflect.Complex128: - fn.fe = (*encoderMsgpackBytes).kComplex128 - case reflect.Chan: - fn.fe = (*encoderMsgpackBytes).kChan - case reflect.Slice: - fn.fe = (*encoderMsgpackBytes).kSlice - case reflect.Array: - fn.fe = (*encoderMsgpackBytes).kArray - case reflect.Struct: - if ti.simple { - fn.fe = (*encoderMsgpackBytes).kStructSimple - } else { - fn.fe = (*encoderMsgpackBytes).kStruct - } - case reflect.Map: - fn.fe = (*encoderMsgpackBytes).kMap - case reflect.Interface: - - fn.fe = (*encoderMsgpackBytes).kErr - default: - - fn.fe = (*encoderMsgpackBytes).kErr - } - } - } - return -} -func (d *decoderMsgpackBytes) rawExt(f *decFnInfo, rv reflect.Value) { - d.d.DecodeRawExt(rv2i(rv).(*RawExt)) -} - -func (d *decoderMsgpackBytes) ext(f *decFnInfo, rv reflect.Value) { - d.d.DecodeExt(rv2i(rv), f.ti.rt, f.xfTag, f.xfFn) -} - -func (d *decoderMsgpackBytes) selferUnmarshal(_ *decFnInfo, rv reflect.Value) { - rv2i(rv).(Selfer).CodecDecodeSelf(&Decoder{d}) -} - -func (d *decoderMsgpackBytes) binaryUnmarshal(_ *decFnInfo, rv reflect.Value) { - bm := rv2i(rv).(encoding.BinaryUnmarshaler) - xbs, _ := d.d.DecodeBytes() - fnerr := bm.UnmarshalBinary(xbs) - halt.onerror(fnerr) -} - -func (d *decoderMsgpackBytes) textUnmarshal(_ *decFnInfo, rv reflect.Value) { - tm := rv2i(rv).(encoding.TextUnmarshaler) - fnerr := tm.UnmarshalText(bytesOKs(d.d.DecodeStringAsBytes())) - halt.onerror(fnerr) -} - -func (d *decoderMsgpackBytes) jsonUnmarshal(_ *decFnInfo, rv reflect.Value) { - d.jsonUnmarshalV(rv2i(rv).(jsonUnmarshaler)) -} - -func (d *decoderMsgpackBytes) jsonUnmarshalV(tm jsonUnmarshaler) { - - halt.onerror(tm.UnmarshalJSON(d.d.nextValueBytes())) -} - -func (d *decoderMsgpackBytes) kErr(_ *decFnInfo, rv reflect.Value) { - halt.errorf("unsupported decoding kind: %s, for %#v", rv.Kind(), rv) - -} - -func (d *decoderMsgpackBytes) raw(_ *decFnInfo, rv reflect.Value) { - rvSetBytes(rv, d.rawBytes()) -} - -func (d *decoderMsgpackBytes) kString(_ *decFnInfo, rv reflect.Value) { - rvSetString(rv, d.detach2Str(d.d.DecodeStringAsBytes())) -} - -func (d *decoderMsgpackBytes) kBool(_ *decFnInfo, rv reflect.Value) { - rvSetBool(rv, d.d.DecodeBool()) -} - -func (d *decoderMsgpackBytes) kTime(_ *decFnInfo, rv reflect.Value) { - rvSetTime(rv, d.d.DecodeTime()) -} - -func (d *decoderMsgpackBytes) kFloat32(_ *decFnInfo, rv reflect.Value) { - rvSetFloat32(rv, d.d.DecodeFloat32()) -} - -func (d *decoderMsgpackBytes) kFloat64(_ *decFnInfo, rv reflect.Value) { - rvSetFloat64(rv, d.d.DecodeFloat64()) -} - -func (d *decoderMsgpackBytes) kComplex64(_ *decFnInfo, rv reflect.Value) { - rvSetComplex64(rv, complex(d.d.DecodeFloat32(), 0)) -} - -func (d *decoderMsgpackBytes) kComplex128(_ *decFnInfo, rv reflect.Value) { - rvSetComplex128(rv, complex(d.d.DecodeFloat64(), 0)) -} - -func (d *decoderMsgpackBytes) kInt(_ *decFnInfo, rv reflect.Value) { - rvSetInt(rv, int(chkOvf.IntV(d.d.DecodeInt64(), intBitsize))) -} - -func (d *decoderMsgpackBytes) kInt8(_ *decFnInfo, rv reflect.Value) { - rvSetInt8(rv, int8(chkOvf.IntV(d.d.DecodeInt64(), 8))) -} - -func (d *decoderMsgpackBytes) kInt16(_ *decFnInfo, rv reflect.Value) { - rvSetInt16(rv, int16(chkOvf.IntV(d.d.DecodeInt64(), 16))) -} - -func (d *decoderMsgpackBytes) kInt32(_ *decFnInfo, rv reflect.Value) { - rvSetInt32(rv, int32(chkOvf.IntV(d.d.DecodeInt64(), 32))) -} - -func (d *decoderMsgpackBytes) kInt64(_ *decFnInfo, rv reflect.Value) { - rvSetInt64(rv, d.d.DecodeInt64()) -} - -func (d *decoderMsgpackBytes) kUint(_ *decFnInfo, rv reflect.Value) { - rvSetUint(rv, uint(chkOvf.UintV(d.d.DecodeUint64(), uintBitsize))) -} - -func (d *decoderMsgpackBytes) kUintptr(_ *decFnInfo, rv reflect.Value) { - rvSetUintptr(rv, uintptr(chkOvf.UintV(d.d.DecodeUint64(), uintBitsize))) -} - -func (d *decoderMsgpackBytes) kUint8(_ *decFnInfo, rv reflect.Value) { - rvSetUint8(rv, uint8(chkOvf.UintV(d.d.DecodeUint64(), 8))) -} - -func (d *decoderMsgpackBytes) kUint16(_ *decFnInfo, rv reflect.Value) { - rvSetUint16(rv, uint16(chkOvf.UintV(d.d.DecodeUint64(), 16))) -} - -func (d *decoderMsgpackBytes) kUint32(_ *decFnInfo, rv reflect.Value) { - rvSetUint32(rv, uint32(chkOvf.UintV(d.d.DecodeUint64(), 32))) -} - -func (d *decoderMsgpackBytes) kUint64(_ *decFnInfo, rv reflect.Value) { - rvSetUint64(rv, d.d.DecodeUint64()) -} - -func (d *decoderMsgpackBytes) kInterfaceNaked(f *decFnInfo) (rvn reflect.Value) { - - n := d.naked() - d.d.DecodeNaked() - - if decFailNonEmptyIntf && f.ti.numMeth > 0 { - halt.errorf("cannot decode non-nil codec value into nil %v (%v methods)", f.ti.rt, f.ti.numMeth) - } - - switch n.v { - case valueTypeMap: - mtid := d.mtid - if mtid == 0 { - if d.jsms { - mtid = mapStrIntfTypId - } else { - mtid = mapIntfIntfTypId - } - } - if mtid == mapStrIntfTypId { - var v2 map[string]interface{} - d.decode(&v2) - rvn = rv4iptr(&v2).Elem() - } else if mtid == mapIntfIntfTypId { - var v2 map[interface{}]interface{} - d.decode(&v2) - rvn = rv4iptr(&v2).Elem() - } else if d.mtr { - rvn = reflect.New(d.h.MapType) - d.decode(rv2i(rvn)) - rvn = rvn.Elem() - } else { - - rvn = rvZeroAddrK(d.h.MapType, reflect.Map) - d.decodeValue(rvn, nil) - } - case valueTypeArray: - if d.stid == 0 || d.stid == intfSliceTypId { - var v2 []interface{} - d.decode(&v2) - rvn = rv4iptr(&v2).Elem() - } else if d.str { - rvn = reflect.New(d.h.SliceType) - d.decode(rv2i(rvn)) - rvn = rvn.Elem() - } else { - rvn = rvZeroAddrK(d.h.SliceType, reflect.Slice) - d.decodeValue(rvn, nil) - } - if d.h.PreferArrayOverSlice { - rvn = rvGetArray4Slice(rvn) - } - case valueTypeExt: - tag, bytes := n.u, n.l - bfn := d.h.getExtForTag(tag) - var re = RawExt{Tag: tag} - if bytes == nil { - - if bfn == nil { - d.decode(&re.Value) - rvn = rv4iptr(&re).Elem() - } else if bfn.ext == SelfExt { - rvn = rvZeroAddrK(bfn.rt, bfn.rt.Kind()) - d.decodeValue(rvn, d.fnNoExt(bfn.rt)) - } else { - rvn = reflect.New(bfn.rt) - d.interfaceExtConvertAndDecode(rv2i(rvn), bfn.ext) - rvn = rvn.Elem() - } - } else { - - if bfn == nil { - re.setData(bytes, false) - rvn = rv4iptr(&re).Elem() - } else { - rvn = reflect.New(bfn.rt) - if bfn.ext == SelfExt { - sideDecode(d.hh, &d.h.sideDecPool, func(sd decoderI) { oneOffDecode(sd, rv2i(rvn), bytes, bfn.rt, true) }) - } else { - bfn.ext.ReadExt(rv2i(rvn), bytes) - } - rvn = rvn.Elem() - } - } - - if d.h.PreferPointerForStructOrArray && rvn.CanAddr() { - if rk := rvn.Kind(); rk == reflect.Array || rk == reflect.Struct { - rvn = rvn.Addr() - } - } - case valueTypeNil: - - case valueTypeInt: - rvn = n.ri() - case valueTypeUint: - rvn = n.ru() - case valueTypeFloat: - rvn = n.rf() - case valueTypeBool: - rvn = n.rb() - case valueTypeString, valueTypeSymbol: - rvn = n.rs() - case valueTypeBytes: - rvn = n.rl() - case valueTypeTime: - rvn = n.rt() - default: - halt.errorStr2("kInterfaceNaked: unexpected valueType: ", n.v.String()) - } - return -} - -func (d *decoderMsgpackBytes) kInterface(f *decFnInfo, rv reflect.Value) { - - isnilrv := rvIsNil(rv) - - var rvn reflect.Value - - if d.h.InterfaceReset { - - rvn = d.h.intf2impl(f.ti.rtid) - if !rvn.IsValid() { - rvn = d.kInterfaceNaked(f) - if rvn.IsValid() { - rvSetIntf(rv, rvn) - } else if !isnilrv { - decSetNonNilRV2Zero4Intf(rv) - } - return - } - } else if isnilrv { - - rvn = d.h.intf2impl(f.ti.rtid) - if !rvn.IsValid() { - rvn = d.kInterfaceNaked(f) - if rvn.IsValid() { - rvSetIntf(rv, rvn) - } - return - } - } else { - - rvn = rv.Elem() - } - - canDecode, _ := isDecodeable(rvn) - - if !canDecode { - rvn2 := d.oneShotAddrRV(rvn.Type(), rvn.Kind()) - rvSetDirect(rvn2, rvn) - rvn = rvn2 - } - - d.decodeValue(rvn, nil) - rvSetIntf(rv, rvn) -} - -func (d *decoderMsgpackBytes) kStructField(si *structFieldInfo, rv reflect.Value) { - if d.d.TryNil() { - rv = si.fieldNoAlloc(rv, true) - if rv.IsValid() { - decSetNonNilRV2Zero(rv) - } - } else if si.decBuiltin { - rv = rvAddr(si.fieldAlloc(rv), si.ptrTyp) - d.decode(rv2i(rv)) - } else { - fn := d.fn(si.baseTyp) - rv = si.fieldAlloc(rv) - if fn.i.addrD { - rv = rvAddr(rv, si.ptrTyp) - } - fn.fd(d, &fn.i, rv) - } -} - -func (d *decoderMsgpackBytes) kStructSimple(f *decFnInfo, rv reflect.Value) { - _ = d.d - ctyp := d.d.ContainerType() - ti := f.ti - if ctyp == valueTypeMap { - containerLen := d.mapStart(d.d.ReadMapStart()) - if containerLen == 0 { - d.mapEnd() - return - } - hasLen := containerLen >= 0 - var rvkencname []byte - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - sab, att := d.d.DecodeStringAsBytes() - rvkencname = d.usableStructFieldNameBytes(rvkencname, sab, att) - d.mapElemValue() - if si := ti.siForEncName(rvkencname); si != nil { - d.kStructField(si, rv) - } else { - d.structFieldNotFound(-1, stringView(rvkencname)) - } - } - d.mapEnd() - } else if ctyp == valueTypeArray { - containerLen := d.arrayStart(d.d.ReadArrayStart()) - if containerLen == 0 { - d.arrayEnd() - return - } - - tisfi := ti.sfi.source() - hasLen := containerLen >= 0 - - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.arrayElem(j == 0) - if j < len(tisfi) { - d.kStructField(tisfi[j], rv) - } else { - d.structFieldNotFound(j, "") - } - } - d.arrayEnd() - } else { - halt.onerror(errNeedMapOrArrayDecodeToStruct) - } -} - -func (d *decoderMsgpackBytes) kStruct(f *decFnInfo, rv reflect.Value) { - _ = d.d - ctyp := d.d.ContainerType() - ti := f.ti - var mf MissingFielder - if ti.flagMissingFielder { - mf = rv2i(rv).(MissingFielder) - } else if ti.flagMissingFielderPtr { - mf = rv2i(rvAddr(rv, ti.ptr)).(MissingFielder) - } - if ctyp == valueTypeMap { - containerLen := d.mapStart(d.d.ReadMapStart()) - if containerLen == 0 { - d.mapEnd() - return - } - hasLen := containerLen >= 0 - var name2 []byte - var rvkencname []byte - tkt := ti.keyType - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - - if tkt == valueTypeString { - sab, att := d.d.DecodeStringAsBytes() - rvkencname = d.usableStructFieldNameBytes(rvkencname, sab, att) - } else if tkt == valueTypeInt { - rvkencname = strconv.AppendInt(d.b[:0], d.d.DecodeInt64(), 10) - } else if tkt == valueTypeUint { - rvkencname = strconv.AppendUint(d.b[:0], d.d.DecodeUint64(), 10) - } else if tkt == valueTypeFloat { - rvkencname = strconv.AppendFloat(d.b[:0], d.d.DecodeFloat64(), 'f', -1, 64) - } else { - halt.errorStr2("invalid struct key type: ", ti.keyType.String()) - } - - d.mapElemValue() - if si := ti.siForEncName(rvkencname); si != nil { - d.kStructField(si, rv) - } else if mf != nil { - - name2 = append(name2[:0], rvkencname...) - var f interface{} - d.decode(&f) - if !mf.CodecMissingField(name2, f) && d.h.ErrorIfNoField { - halt.errorStr2("no matching struct field when decoding stream map with key: ", stringView(name2)) - } - } else { - d.structFieldNotFound(-1, stringView(rvkencname)) - } - } - d.mapEnd() - } else if ctyp == valueTypeArray { - containerLen := d.arrayStart(d.d.ReadArrayStart()) - if containerLen == 0 { - d.arrayEnd() - return - } - - tisfi := ti.sfi.source() - hasLen := containerLen >= 0 - - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.arrayElem(j == 0) - if j < len(tisfi) { - d.kStructField(tisfi[j], rv) - } else { - d.structFieldNotFound(j, "") - } - } - - d.arrayEnd() - } else { - halt.onerror(errNeedMapOrArrayDecodeToStruct) - } -} - -func (d *decoderMsgpackBytes) kSlice(f *decFnInfo, rv reflect.Value) { - _ = d.d - - ti := f.ti - rvCanset := rv.CanSet() - - ctyp := d.d.ContainerType() - if ctyp == valueTypeBytes || ctyp == valueTypeString { - - if !(ti.rtid == uint8SliceTypId || ti.elemkind == uint8(reflect.Uint8)) { - halt.errorf("bytes/string in stream must decode into slice/array of bytes, not %v", ti.rt) - } - rvbs := rvGetBytes(rv) - if rvCanset { - bs2, bst := d.decodeBytesInto(rvbs, false) - if bst != dBytesIntoParamOut { - rvSetBytes(rv, bs2) - } - } else { - - d.decodeBytesInto(rvbs[:len(rvbs):len(rvbs)], true) - } - return - } - - var containerLenS int - isArray := ctyp == valueTypeArray - if isArray { - containerLenS = d.arrayStart(d.d.ReadArrayStart()) - } else if ctyp == valueTypeMap { - containerLenS = d.mapStart(d.d.ReadMapStart()) * 2 - } else { - halt.errorStr2("decoding into a slice, expect map/array - got ", ctyp.String()) - } - - if containerLenS == 0 { - if rvCanset { - if rvIsNil(rv) { - rvSetDirect(rv, rvSliceZeroCap(ti.rt)) - } else { - rvSetSliceLen(rv, 0) - } - } - if isArray { - d.arrayEnd() - } else { - d.mapEnd() - } - return - } - - rtelem0Mut := !scalarBitset.isset(ti.elemkind) - rtelem := ti.elem - - for k := reflect.Kind(ti.elemkind); k == reflect.Ptr; k = rtelem.Kind() { - rtelem = rtelem.Elem() - } - - var fn *decFnMsgpackBytes - - var rvChanged bool - - var rv0 = rv - var rv9 reflect.Value - - rvlen := rvLenSlice(rv) - rvcap := rvCapSlice(rv) - maxInitLen := d.maxInitLen() - hasLen := containerLenS >= 0 - if hasLen { - if containerLenS > rvcap { - oldRvlenGtZero := rvlen > 0 - rvlen1 := int(decInferLen(containerLenS, maxInitLen, uint(ti.elemsize))) - if rvlen1 == rvlen { - } else if rvlen1 <= rvcap { - if rvCanset { - rvlen = rvlen1 - rvSetSliceLen(rv, rvlen) - } - } else if rvCanset { - rvlen = rvlen1 - rv, rvCanset = rvMakeSlice(rv, f.ti, rvlen, rvlen) - rvcap = rvlen - rvChanged = !rvCanset - } else { - halt.errorStr("cannot decode into non-settable slice") - } - if rvChanged && oldRvlenGtZero && rtelem0Mut { - rvCopySlice(rv, rv0, rtelem) - } - } else if containerLenS != rvlen { - if rvCanset { - rvlen = containerLenS - rvSetSliceLen(rv, rvlen) - } - } - } - - var elemReset = d.h.SliceElementReset - - var rtelemIsPtr bool - var rtelemElem reflect.Type - builtin := ti.tielem.flagDecBuiltin - if builtin { - rtelemIsPtr = ti.elemkind == uint8(reflect.Ptr) - if rtelemIsPtr { - rtelemElem = ti.elem.Elem() - } - } - - var j int - for ; d.containerNext(j, containerLenS, hasLen); j++ { - if j == 0 { - if rvIsNil(rv) { - if rvCanset { - rvlen = int(decInferLen(containerLenS, maxInitLen, uint(ti.elemsize))) - rv, rvCanset = rvMakeSlice(rv, f.ti, rvlen, rvlen) - rvcap = rvlen - rvChanged = !rvCanset - } else { - halt.errorStr("cannot decode into non-settable slice") - } - } - if fn == nil { - fn = d.fn(rtelem) - } - } - - if ctyp == valueTypeArray { - d.arrayElem(j == 0) - } else if j&1 == 0 { - d.mapElemKey(j == 0) - } else { - d.mapElemValue() - } - - if j >= rvlen { - - if rvlen < rvcap { - rvlen = rvcap - if rvCanset { - rvSetSliceLen(rv, rvlen) - } else if rvChanged { - rv = rvSlice(rv, rvlen) - } else { - halt.onerror(errExpandSliceCannotChange) - } - } else { - if !(rvCanset || rvChanged) { - halt.onerror(errExpandSliceCannotChange) - } - rv, rvcap, rvCanset = rvGrowSlice(rv, f.ti, rvcap, 1) - - rvlen = rvcap - rvChanged = !rvCanset - } - } - - rv9 = rvArrayIndex(rv, j, f.ti, true) - if elemReset { - rvSetZero(rv9) - } - if d.d.TryNil() { - rvSetZero(rv9) - } else if builtin { - if rtelemIsPtr { - if rvIsNil(rv9) { - rvSetDirect(rv9, reflect.New(rtelemElem)) - } - d.decode(rv2i(rv9)) - } else { - d.decode(rv2i(rvAddr(rv9, ti.tielem.ptr))) - } - } else { - d.decodeValueNoCheckNil(rv9, fn) - } - } - if j < rvlen { - if rvCanset { - rvSetSliceLen(rv, j) - } else if rvChanged { - rv = rvSlice(rv, j) - } - - } else if j == 0 && rvIsNil(rv) { - if rvCanset { - rv = rvSliceZeroCap(ti.rt) - rvCanset = false - rvChanged = true - } - } - if isArray { - d.arrayEnd() - } else { - d.mapEnd() - } - - if rvChanged { - rvSetDirect(rv0, rv) - } -} - -func (d *decoderMsgpackBytes) kArray(f *decFnInfo, rv reflect.Value) { - _ = d.d - - ti := f.ti - ctyp := d.d.ContainerType() - if handleBytesWithinKArray && (ctyp == valueTypeBytes || ctyp == valueTypeString) { - - if ti.elemkind != uint8(reflect.Uint8) { - halt.errorf("bytes/string in stream can decode into array of bytes, but not %v", ti.rt) - } - rvbs := rvGetArrayBytes(rv, nil) - d.decodeBytesInto(rvbs, true) - return - } - - var containerLenS int - isArray := ctyp == valueTypeArray - if isArray { - containerLenS = d.arrayStart(d.d.ReadArrayStart()) - } else if ctyp == valueTypeMap { - containerLenS = d.mapStart(d.d.ReadMapStart()) * 2 - } else { - halt.errorStr2("decoding into a slice, expect map/array - got ", ctyp.String()) - } - - if containerLenS == 0 { - if isArray { - d.arrayEnd() - } else { - d.mapEnd() - } - return - } - - rtelem := ti.elem - for k := reflect.Kind(ti.elemkind); k == reflect.Ptr; k = rtelem.Kind() { - rtelem = rtelem.Elem() - } - - var rv9 reflect.Value - - rvlen := rv.Len() - hasLen := containerLenS >= 0 - if hasLen && containerLenS > rvlen { - halt.errorf("cannot decode into array with length: %v, less than container length: %v", any(rvlen), any(containerLenS)) - } - - var elemReset = d.h.SliceElementReset - - var rtelemIsPtr bool - var rtelemElem reflect.Type - var fn *decFnMsgpackBytes - builtin := ti.tielem.flagDecBuiltin - if builtin { - rtelemIsPtr = ti.elemkind == uint8(reflect.Ptr) - if rtelemIsPtr { - rtelemElem = ti.elem.Elem() - } - } else { - fn = d.fn(rtelem) - } - - for j := 0; d.containerNext(j, containerLenS, hasLen); j++ { - if ctyp == valueTypeArray { - d.arrayElem(j == 0) - } else if j&1 == 0 { - d.mapElemKey(j == 0) - } else { - d.mapElemValue() - } - - if j >= rvlen { - d.arrayCannotExpand(rvlen, j+1) - d.swallow() - continue - } - - rv9 = rvArrayIndex(rv, j, f.ti, false) - if elemReset { - rvSetZero(rv9) - } - if d.d.TryNil() { - rvSetZero(rv9) - } else if builtin { - if rtelemIsPtr { - if rvIsNil(rv9) { - rvSetDirect(rv9, reflect.New(rtelemElem)) - } - d.decode(rv2i(rv9)) - } else { - d.decode(rv2i(rvAddr(rv9, ti.tielem.ptr))) - } - } else { - d.decodeValueNoCheckNil(rv9, fn) - } - } - if isArray { - d.arrayEnd() - } else { - d.mapEnd() - } -} - -func (d *decoderMsgpackBytes) kChan(f *decFnInfo, rv reflect.Value) { - _ = d.d - - ti := f.ti - if ti.chandir&uint8(reflect.SendDir) == 0 { - halt.errorStr("receive-only channel cannot be decoded") - } - ctyp := d.d.ContainerType() - if ctyp == valueTypeBytes || ctyp == valueTypeString { - - if !(ti.rtid == uint8SliceTypId || ti.elemkind == uint8(reflect.Uint8)) { - halt.errorf("bytes/string in stream must decode into slice/array of bytes, not %v", ti.rt) - } - bs2, _ := d.d.DecodeBytes() - irv := rv2i(rv) - ch, ok := irv.(chan<- byte) - if !ok { - ch = irv.(chan byte) - } - for _, b := range bs2 { - ch <- b - } - return - } - - var rvCanset = rv.CanSet() - - var containerLenS int - isArray := ctyp == valueTypeArray - if isArray { - containerLenS = d.arrayStart(d.d.ReadArrayStart()) - } else if ctyp == valueTypeMap { - containerLenS = d.mapStart(d.d.ReadMapStart()) * 2 - } else { - halt.errorStr2("decoding into a slice, expect map/array - got ", ctyp.String()) - } - - if containerLenS == 0 { - if rvCanset && rvIsNil(rv) { - rvSetDirect(rv, reflect.MakeChan(ti.rt, 0)) - } - if isArray { - d.arrayEnd() - } else { - d.mapEnd() - } - return - } - - rtelem := ti.elem - useTransient := decUseTransient && ti.elemkind != byte(reflect.Ptr) && ti.tielem.flagCanTransient - - for k := reflect.Kind(ti.elemkind); k == reflect.Ptr; k = rtelem.Kind() { - rtelem = rtelem.Elem() - } - - var fn *decFnMsgpackBytes - - var rvChanged bool - var rv0 = rv - var rv9 reflect.Value - - var rvlen int - hasLen := containerLenS >= 0 - maxInitLen := d.maxInitLen() - - for j := 0; d.containerNext(j, containerLenS, hasLen); j++ { - if j == 0 { - if rvIsNil(rv) { - if hasLen { - rvlen = int(decInferLen(containerLenS, maxInitLen, uint(ti.elemsize))) - } else { - rvlen = decDefChanCap - } - if rvCanset { - rv = reflect.MakeChan(ti.rt, rvlen) - rvChanged = true - } else { - halt.errorStr("cannot decode into non-settable chan") - } - } - if fn == nil { - fn = d.fn(rtelem) - } - } - - if ctyp == valueTypeArray { - d.arrayElem(j == 0) - } else if j&1 == 0 { - d.mapElemKey(j == 0) - } else { - d.mapElemValue() - } - - if rv9.IsValid() { - rvSetZero(rv9) - } else if useTransient { - rv9 = d.perType.TransientAddrK(ti.elem, reflect.Kind(ti.elemkind)) - } else { - rv9 = rvZeroAddrK(ti.elem, reflect.Kind(ti.elemkind)) - } - if !d.d.TryNil() { - d.decodeValueNoCheckNil(rv9, fn) - } - rv.Send(rv9) - } - if isArray { - d.arrayEnd() - } else { - d.mapEnd() - } - - if rvChanged { - rvSetDirect(rv0, rv) - } - -} - -func (d *decoderMsgpackBytes) kMap(f *decFnInfo, rv reflect.Value) { - _ = d.d - containerLen := d.mapStart(d.d.ReadMapStart()) - ti := f.ti - if rvIsNil(rv) { - rvlen := int(decInferLen(containerLen, d.maxInitLen(), uint(ti.keysize+ti.elemsize))) - rvSetDirect(rv, makeMapReflect(ti.rt, rvlen)) - } - - if containerLen == 0 { - d.mapEnd() - return - } - - ktype, vtype := ti.key, ti.elem - ktypeId := rt2id(ktype) - vtypeKind := reflect.Kind(ti.elemkind) - ktypeKind := reflect.Kind(ti.keykind) - mparams := getMapReqParams(ti) - - vtypePtr := vtypeKind == reflect.Ptr - ktypePtr := ktypeKind == reflect.Ptr - - vTransient := decUseTransient && !vtypePtr && ti.tielem.flagCanTransient - - kTransient := vTransient && !ktypePtr && ti.tikey.flagCanTransient - - var vtypeElem reflect.Type - - var keyFn, valFn *decFnMsgpackBytes - var ktypeLo, vtypeLo = ktype, vtype - - if ktypeKind == reflect.Ptr { - for ktypeLo = ktype.Elem(); ktypeLo.Kind() == reflect.Ptr; ktypeLo = ktypeLo.Elem() { - } - } - - if vtypePtr { - vtypeElem = vtype.Elem() - for vtypeLo = vtypeElem; vtypeLo.Kind() == reflect.Ptr; vtypeLo = vtypeLo.Elem() { - } - } - - rvkMut := !scalarBitset.isset(ti.keykind) - rvvMut := !scalarBitset.isset(ti.elemkind) - rvvCanNil := isnilBitset.isset(ti.elemkind) - - var rvk, rvkn, rvv, rvvn, rvva, rvvz reflect.Value - - var doMapGet, doMapSet bool - - if !d.h.MapValueReset { - if rvvMut && (vtypeKind != reflect.Interface || !d.h.InterfaceReset) { - doMapGet = true - rvva = mapAddrLoopvarRV(vtype, vtypeKind) - } - } - - ktypeIsString := ktypeId == stringTypId - ktypeIsIntf := ktypeId == intfTypId - hasLen := containerLen >= 0 - - var kstr2bs []byte - var kstr string - - var mapKeyStringSharesBytesBuf bool - var att dBytesAttachState - - var vElem, kElem reflect.Type - kbuiltin := ti.tikey.flagDecBuiltin && ti.keykind != uint8(reflect.Slice) - vbuiltin := ti.tielem.flagDecBuiltin - if kbuiltin && ktypePtr { - kElem = ti.key.Elem() - } - if vbuiltin && vtypePtr { - vElem = ti.elem.Elem() - } - - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - mapKeyStringSharesBytesBuf = false - kstr = "" - if j == 0 { - - if kTransient { - rvk = d.perType.TransientAddr2K(ktype, ktypeKind) - } else { - rvk = rvZeroAddrK(ktype, ktypeKind) - } - if !rvkMut { - rvkn = rvk - } - if !rvvMut { - if vTransient { - rvvn = d.perType.TransientAddrK(vtype, vtypeKind) - } else { - rvvn = rvZeroAddrK(vtype, vtypeKind) - } - } - if !ktypeIsString && keyFn == nil { - keyFn = d.fn(ktypeLo) - } - if valFn == nil { - valFn = d.fn(vtypeLo) - } - } else if rvkMut { - rvSetZero(rvk) - } else { - rvk = rvkn - } - - d.mapElemKey(j == 0) - - if d.d.TryNil() { - rvSetZero(rvk) - } else if ktypeIsString { - kstr2bs, att = d.d.DecodeStringAsBytes() - kstr, mapKeyStringSharesBytesBuf = d.bytes2Str(kstr2bs, att) - rvSetString(rvk, kstr) - } else { - if kbuiltin { - if ktypePtr { - if rvIsNil(rvk) { - rvSetDirect(rvk, reflect.New(kElem)) - } - d.decode(rv2i(rvk)) - } else { - d.decode(rv2i(rvAddr(rvk, ti.tikey.ptr))) - } - } else { - d.decodeValueNoCheckNil(rvk, keyFn) - } - - if ktypeIsIntf { - if rvk2 := rvk.Elem(); rvk2.IsValid() && rvk2.Type() == uint8SliceTyp { - kstr2bs = rvGetBytes(rvk2) - kstr, mapKeyStringSharesBytesBuf = d.bytes2Str(kstr2bs, dBytesAttachView) - rvSetIntf(rvk, rv4istr(kstr)) - } - - } - } - - if mapKeyStringSharesBytesBuf && d.bufio { - if ktypeIsString { - rvSetString(rvk, d.detach2Str(kstr2bs, att)) - } else { - rvSetIntf(rvk, rv4istr(d.detach2Str(kstr2bs, att))) - } - mapKeyStringSharesBytesBuf = false - } - - d.mapElemValue() - - if d.d.TryNil() { - if mapKeyStringSharesBytesBuf { - if ktypeIsString { - rvSetString(rvk, d.detach2Str(kstr2bs, att)) - } else { - rvSetIntf(rvk, rv4istr(d.detach2Str(kstr2bs, att))) - } - } - - if !rvvz.IsValid() { - rvvz = rvZeroK(vtype, vtypeKind) - } - mapSet(rv, rvk, rvvz, mparams) - continue - } - - doMapSet = true - - if !rvvMut { - rvv = rvvn - } else if !doMapGet { - goto NEW_RVV - } else { - rvv = mapGet(rv, rvk, rvva, mparams) - if !rvv.IsValid() || (rvvCanNil && rvIsNil(rvv)) { - goto NEW_RVV - } - switch vtypeKind { - case reflect.Ptr, reflect.Map: - doMapSet = false - case reflect.Interface: - - rvvn = rvv.Elem() - if k := rvvn.Kind(); (k == reflect.Ptr || k == reflect.Map) && !rvIsNil(rvvn) { - d.decodeValueNoCheckNil(rvvn, nil) - continue - } - - rvvn = rvZeroAddrK(vtype, vtypeKind) - rvSetIntf(rvvn, rvv) - rvv = rvvn - default: - - if vTransient { - rvvn = d.perType.TransientAddrK(vtype, vtypeKind) - } else { - rvvn = rvZeroAddrK(vtype, vtypeKind) - } - rvSetDirect(rvvn, rvv) - rvv = rvvn - } - } - goto DECODE_VALUE_NO_CHECK_NIL - - NEW_RVV: - if vtypePtr { - rvv = reflect.New(vtypeElem) - } else if vTransient { - rvv = d.perType.TransientAddrK(vtype, vtypeKind) - } else { - rvv = rvZeroAddrK(vtype, vtypeKind) - } - - DECODE_VALUE_NO_CHECK_NIL: - if doMapSet && mapKeyStringSharesBytesBuf { - if ktypeIsString { - rvSetString(rvk, d.detach2Str(kstr2bs, att)) - } else { - rvSetIntf(rvk, rv4istr(d.detach2Str(kstr2bs, att))) - } - } - if vbuiltin { - if vtypePtr { - if rvIsNil(rvv) { - rvSetDirect(rvv, reflect.New(vElem)) - } - d.decode(rv2i(rvv)) - } else { - d.decode(rv2i(rvAddr(rvv, ti.tielem.ptr))) - } - } else { - d.decodeValueNoCheckNil(rvv, valFn) - } - if doMapSet { - mapSet(rv, rvk, rvv, mparams) - } - } - - d.mapEnd() -} - -func (d *decoderMsgpackBytes) init(h Handle) { - initHandle(h) - callMake(&d.d) - d.hh = h - d.h = h.getBasicHandle() - - d.err = errDecoderNotInitialized - - if d.h.InternString && d.is == nil { - d.is.init() - } - - d.fp = d.d.init(h, &d.decoderBase, d).(*fastpathDsMsgpackBytes) - - if d.bytes { - d.rtidFn = &d.h.rtidFnsDecBytes - d.rtidFnNoExt = &d.h.rtidFnsDecNoExtBytes - } else { - d.bufio = d.h.ReaderBufferSize > 0 - d.rtidFn = &d.h.rtidFnsDecIO - d.rtidFnNoExt = &d.h.rtidFnsDecNoExtIO - } - - d.reset() - -} - -func (d *decoderMsgpackBytes) reset() { - d.d.reset() - d.err = nil - d.c = 0 - d.depth = 0 - d.calls = 0 - - d.maxdepth = decDefMaxDepth - if d.h.MaxDepth > 0 { - d.maxdepth = d.h.MaxDepth - } - d.mtid = 0 - d.stid = 0 - d.mtr = false - d.str = false - if d.h.MapType != nil { - d.mtid = rt2id(d.h.MapType) - _, d.mtr = fastpathAvIndex(d.mtid) - } - if d.h.SliceType != nil { - d.stid = rt2id(d.h.SliceType) - _, d.str = fastpathAvIndex(d.stid) - } -} - -func (d *decoderMsgpackBytes) Reset(r io.Reader) { - if d.bytes { - halt.onerror(errDecNoResetBytesWithReader) - } - d.reset() - if r == nil { - r = &eofReader - } - d.d.resetInIO(r) -} - -func (d *decoderMsgpackBytes) ResetBytes(in []byte) { - if !d.bytes { - halt.onerror(errDecNoResetReaderWithBytes) - } - d.resetBytes(in) -} - -func (d *decoderMsgpackBytes) resetBytes(in []byte) { - d.reset() - if in == nil { - in = zeroByteSlice - } - d.d.resetInBytes(in) -} - -func (d *decoderMsgpackBytes) ResetString(s string) { - d.ResetBytes(bytesView(s)) -} - -func (d *decoderMsgpackBytes) Decode(v interface{}) (err error) { - - defer panicValToErr(d, callRecoverSentinel, &d.err, &err, debugging) - d.mustDecode(v) - return -} - -func (d *decoderMsgpackBytes) MustDecode(v interface{}) { - defer panicValToErr(d, callRecoverSentinel, &d.err, nil, true) - d.mustDecode(v) - return -} - -func (d *decoderMsgpackBytes) mustDecode(v interface{}) { - halt.onerror(d.err) - if d.hh == nil { - halt.onerror(errNoFormatHandle) - } - - d.calls++ - d.decode(v) - d.calls-- -} - -func (d *decoderMsgpackBytes) Release() {} - -func (d *decoderMsgpackBytes) swallow() { - d.d.nextValueBytes() -} - -func (d *decoderMsgpackBytes) nextValueBytes() []byte { - return d.d.nextValueBytes() -} - -func (d *decoderMsgpackBytes) decode(iv interface{}) { - _ = d.d - - rv, ok := isNil(iv, true) - if ok { - halt.onerror(errCannotDecodeIntoNil) - } - - switch v := iv.(type) { - - case *string: - *v = d.detach2Str(d.d.DecodeStringAsBytes()) - case *bool: - *v = d.d.DecodeBool() - case *int: - *v = int(chkOvf.IntV(d.d.DecodeInt64(), intBitsize)) - case *int8: - *v = int8(chkOvf.IntV(d.d.DecodeInt64(), 8)) - case *int16: - *v = int16(chkOvf.IntV(d.d.DecodeInt64(), 16)) - case *int32: - *v = int32(chkOvf.IntV(d.d.DecodeInt64(), 32)) - case *int64: - *v = d.d.DecodeInt64() - case *uint: - *v = uint(chkOvf.UintV(d.d.DecodeUint64(), uintBitsize)) - case *uint8: - *v = uint8(chkOvf.UintV(d.d.DecodeUint64(), 8)) - case *uint16: - *v = uint16(chkOvf.UintV(d.d.DecodeUint64(), 16)) - case *uint32: - *v = uint32(chkOvf.UintV(d.d.DecodeUint64(), 32)) - case *uint64: - *v = d.d.DecodeUint64() - case *uintptr: - *v = uintptr(chkOvf.UintV(d.d.DecodeUint64(), uintBitsize)) - case *float32: - *v = d.d.DecodeFloat32() - case *float64: - *v = d.d.DecodeFloat64() - case *complex64: - *v = complex(d.d.DecodeFloat32(), 0) - case *complex128: - *v = complex(d.d.DecodeFloat64(), 0) - case *[]byte: - *v, _ = d.decodeBytesInto(*v, false) - case []byte: - - d.decodeBytesInto(v[:len(v):len(v)], true) - case *time.Time: - *v = d.d.DecodeTime() - case *Raw: - *v = d.rawBytes() - - case *interface{}: - d.decodeValue(rv4iptr(v), nil) - - case reflect.Value: - if ok, _ = isDecodeable(v); !ok { - d.haltAsNotDecodeable(v) - } - d.decodeValue(v, nil) - - default: - - if skipFastpathTypeSwitchInDirectCall || !d.dh.fastpathDecodeTypeSwitch(iv, d) { - if !rv.IsValid() { - rv = reflect.ValueOf(iv) - } - if ok, _ = isDecodeable(rv); !ok { - d.haltAsNotDecodeable(rv) - } - d.decodeValue(rv, nil) - } - } -} - -func (d *decoderMsgpackBytes) decodeValue(rv reflect.Value, fn *decFnMsgpackBytes) { - if d.d.TryNil() { - decSetNonNilRV2Zero(rv) - } else { - d.decodeValueNoCheckNil(rv, fn) - } -} - -func (d *decoderMsgpackBytes) decodeValueNoCheckNil(rv reflect.Value, fn *decFnMsgpackBytes) { - - var rvp reflect.Value - var rvpValid bool -PTR: - if rv.Kind() == reflect.Ptr { - rvpValid = true - if rvIsNil(rv) { - rvSetDirect(rv, reflect.New(rv.Type().Elem())) - } - rvp = rv - rv = rv.Elem() - goto PTR - } - - if fn == nil { - fn = d.fn(rv.Type()) - } - if fn.i.addrD { - if rvpValid { - rv = rvp - } else if rv.CanAddr() { - rv = rvAddr(rv, fn.i.ti.ptr) - } else if fn.i.addrDf { - halt.errorStr("cannot decode into a non-pointer value") - } - } - fn.fd(d, &fn.i, rv) -} - -func (d *decoderMsgpackBytes) decodeAs(v interface{}, t reflect.Type, ext bool) { - if ext { - d.decodeValue(baseRV(v), d.fn(t)) - } else { - d.decodeValue(baseRV(v), d.fnNoExt(t)) - } -} - -func (d *decoderMsgpackBytes) structFieldNotFound(index int, rvkencname string) { - - if d.h.ErrorIfNoField { - if index >= 0 { - halt.errorInt("no matching struct field found when decoding stream array at index ", int64(index)) - } else if rvkencname != "" { - halt.errorStr2("no matching struct field found when decoding stream map with key ", rvkencname) - } - } - d.swallow() -} - -func (d *decoderMsgpackBytes) decodeBytesInto(out []byte, mustFit bool) (v []byte, state dBytesIntoState) { - v, att := d.d.DecodeBytes() - if cap(v) == 0 || (att >= dBytesAttachViewZerocopy && !mustFit) { - - return - } - if len(v) == 0 { - v = zeroByteSlice - return - } - if len(out) == len(v) { - state = dBytesIntoParamOut - } else if cap(out) >= len(v) { - out = out[:len(v)] - state = dBytesIntoParamOutSlice - } else if mustFit { - halt.errorf("bytes capacity insufficient for decoded bytes: got/expected: %d/%d", len(v), len(out)) - } else { - out = make([]byte, len(v)) - state = dBytesIntoNew - } - copy(out, v) - v = out - return -} - -func (d *decoderMsgpackBytes) rawBytes() (v []byte) { - - v = d.d.nextValueBytes() - if d.bytes && !d.h.ZeroCopy { - vv := make([]byte, len(v)) - copy(vv, v) - v = vv - } - return -} - -func (d *decoderMsgpackBytes) wrapErr(v error, err *error) { - *err = wrapCodecErr(v, d.hh.Name(), d.d.NumBytesRead(), false) -} - -func (d *decoderMsgpackBytes) NumBytesRead() int { - return d.d.NumBytesRead() -} - -func (d *decoderMsgpackBytes) containerNext(j, containerLen int, hasLen bool) bool { - - if hasLen { - return j < containerLen - } - return !d.d.CheckBreak() -} - -func (d *decoderMsgpackBytes) mapElemKey(firstTime bool) { - d.d.ReadMapElemKey(firstTime) - d.c = containerMapKey -} - -func (d *decoderMsgpackBytes) mapElemValue() { - d.d.ReadMapElemValue() - d.c = containerMapValue -} - -func (d *decoderMsgpackBytes) mapEnd() { - d.d.ReadMapEnd() - d.depthDecr() - d.c = 0 -} - -func (d *decoderMsgpackBytes) arrayElem(firstTime bool) { - d.d.ReadArrayElem(firstTime) - d.c = containerArrayElem -} - -func (d *decoderMsgpackBytes) arrayEnd() { - d.d.ReadArrayEnd() - d.depthDecr() - d.c = 0 -} - -func (d *decoderMsgpackBytes) interfaceExtConvertAndDecode(v interface{}, ext InterfaceExt) { - - var vv interface{} - d.decode(&vv) - ext.UpdateExt(v, vv) - -} - -func (d *decoderMsgpackBytes) fn(t reflect.Type) *decFnMsgpackBytes { - return d.dh.decFnViaBH(t, d.rtidFn, d.h, d.fp, false) -} - -func (d *decoderMsgpackBytes) fnNoExt(t reflect.Type) *decFnMsgpackBytes { - return d.dh.decFnViaBH(t, d.rtidFnNoExt, d.h, d.fp, true) -} - -func (helperDecDriverMsgpackBytes) newDecoderBytes(in []byte, h Handle) *decoderMsgpackBytes { - var c1 decoderMsgpackBytes - c1.bytes = true - c1.init(h) - c1.ResetBytes(in) - return &c1 -} - -func (helperDecDriverMsgpackBytes) newDecoderIO(in io.Reader, h Handle) *decoderMsgpackBytes { - var c1 decoderMsgpackBytes - c1.init(h) - c1.Reset(in) - return &c1 -} - -func (helperDecDriverMsgpackBytes) decFnloadFastpathUnderlying(ti *typeInfo, fp *fastpathDsMsgpackBytes) (f *fastpathDMsgpackBytes, u reflect.Type) { - rtid := rt2id(ti.fastpathUnderlying) - idx, ok := fastpathAvIndex(rtid) - if !ok { - return - } - f = &fp[idx] - if uint8(reflect.Array) == ti.kind { - u = reflect.ArrayOf(ti.rt.Len(), ti.elem) - } else { - u = f.rt - } - return -} - -func (helperDecDriverMsgpackBytes) decFindRtidFn(s []decRtidFnMsgpackBytes, rtid uintptr) (i uint, fn *decFnMsgpackBytes) { - - var h uint - var j = uint(len(s)) -LOOP: - if i < j { - h = (i + j) >> 1 - if s[h].rtid < rtid { - i = h + 1 - } else { - j = h - } - goto LOOP - } - if i < uint(len(s)) && s[i].rtid == rtid { - fn = s[i].fn - } - return -} - -func (helperDecDriverMsgpackBytes) decFromRtidFnSlice(fns *atomicRtidFnSlice) (s []decRtidFnMsgpackBytes) { - if v := fns.load(); v != nil { - s = *(lowLevelToPtr[[]decRtidFnMsgpackBytes](v)) - } - return -} - -func (dh helperDecDriverMsgpackBytes) decFnViaBH(rt reflect.Type, fns *atomicRtidFnSlice, x *BasicHandle, fp *fastpathDsMsgpackBytes, - checkExt bool) (fn *decFnMsgpackBytes) { - return dh.decFnVia(rt, fns, x.typeInfos(), &x.mu, x.extHandle, fp, - checkExt, x.CheckCircularRef, x.timeBuiltin, x.binaryHandle, x.jsonHandle) -} - -func (dh helperDecDriverMsgpackBytes) decFnVia(rt reflect.Type, fns *atomicRtidFnSlice, - tinfos *TypeInfos, mu *sync.Mutex, exth extHandle, fp *fastpathDsMsgpackBytes, - checkExt, checkCircularRef, timeBuiltin, binaryEncoding, json bool) (fn *decFnMsgpackBytes) { - rtid := rt2id(rt) - var sp []decRtidFnMsgpackBytes = dh.decFromRtidFnSlice(fns) - if sp != nil { - _, fn = dh.decFindRtidFn(sp, rtid) - } - if fn == nil { - fn = dh.decFnViaLoader(rt, rtid, fns, tinfos, mu, exth, fp, checkExt, checkCircularRef, timeBuiltin, binaryEncoding, json) - } - return -} - -func (dh helperDecDriverMsgpackBytes) decFnViaLoader(rt reflect.Type, rtid uintptr, fns *atomicRtidFnSlice, - tinfos *TypeInfos, mu *sync.Mutex, exth extHandle, fp *fastpathDsMsgpackBytes, - checkExt, checkCircularRef, timeBuiltin, binaryEncoding, json bool) (fn *decFnMsgpackBytes) { - - fn = dh.decFnLoad(rt, rtid, tinfos, exth, fp, checkExt, checkCircularRef, timeBuiltin, binaryEncoding, json) - var sp []decRtidFnMsgpackBytes - mu.Lock() - sp = dh.decFromRtidFnSlice(fns) - - if sp == nil { - sp = []decRtidFnMsgpackBytes{{rtid, fn}} - fns.store(ptrToLowLevel(&sp)) - } else { - idx, fn2 := dh.decFindRtidFn(sp, rtid) - if fn2 == nil { - sp2 := make([]decRtidFnMsgpackBytes, len(sp)+1) - copy(sp2[idx+1:], sp[idx:]) - copy(sp2, sp[:idx]) - sp2[idx] = decRtidFnMsgpackBytes{rtid, fn} - fns.store(ptrToLowLevel(&sp2)) - } - } - mu.Unlock() - return -} - -func (dh helperDecDriverMsgpackBytes) decFnLoad(rt reflect.Type, rtid uintptr, tinfos *TypeInfos, - exth extHandle, fp *fastpathDsMsgpackBytes, - checkExt, checkCircularRef, timeBuiltin, binaryEncoding, json bool) (fn *decFnMsgpackBytes) { - fn = new(decFnMsgpackBytes) - fi := &(fn.i) - ti := tinfos.get(rtid, rt) - fi.ti = ti - rk := reflect.Kind(ti.kind) - - fi.addrDf = true - - if rtid == timeTypId && timeBuiltin { - fn.fd = (*decoderMsgpackBytes).kTime - } else if rtid == rawTypId { - fn.fd = (*decoderMsgpackBytes).raw - } else if rtid == rawExtTypId { - fn.fd = (*decoderMsgpackBytes).rawExt - fi.addrD = true - } else if xfFn := exth.getExt(rtid, checkExt); xfFn != nil { - fi.xfTag, fi.xfFn = xfFn.tag, xfFn.ext - fn.fd = (*decoderMsgpackBytes).ext - fi.addrD = true - } else if ti.flagSelfer || ti.flagSelferPtr { - fn.fd = (*decoderMsgpackBytes).selferUnmarshal - fi.addrD = ti.flagSelferPtr - } else if supportMarshalInterfaces && binaryEncoding && - (ti.flagBinaryMarshaler || ti.flagBinaryMarshalerPtr) && - (ti.flagBinaryUnmarshaler || ti.flagBinaryUnmarshalerPtr) { - fn.fd = (*decoderMsgpackBytes).binaryUnmarshal - fi.addrD = ti.flagBinaryUnmarshalerPtr - } else if supportMarshalInterfaces && !binaryEncoding && json && - (ti.flagJsonMarshaler || ti.flagJsonMarshalerPtr) && - (ti.flagJsonUnmarshaler || ti.flagJsonUnmarshalerPtr) { - - fn.fd = (*decoderMsgpackBytes).jsonUnmarshal - fi.addrD = ti.flagJsonUnmarshalerPtr - } else if supportMarshalInterfaces && !binaryEncoding && - (ti.flagTextMarshaler || ti.flagTextMarshalerPtr) && - (ti.flagTextUnmarshaler || ti.flagTextUnmarshalerPtr) { - fn.fd = (*decoderMsgpackBytes).textUnmarshal - fi.addrD = ti.flagTextUnmarshalerPtr - } else { - if fastpathEnabled && (rk == reflect.Map || rk == reflect.Slice || rk == reflect.Array) { - var rtid2 uintptr - if !ti.flagHasPkgPath { - rtid2 = rtid - if rk == reflect.Array { - rtid2 = rt2id(ti.key) - } - if idx, ok := fastpathAvIndex(rtid2); ok { - fn.fd = fp[idx].decfn - fi.addrD = true - fi.addrDf = false - if rk == reflect.Array { - fi.addrD = false - } - } - } else { - - xfe, xrt := dh.decFnloadFastpathUnderlying(ti, fp) - if xfe != nil { - xfnf2 := xfe.decfn - if rk == reflect.Array { - fi.addrD = false - fn.fd = func(d *decoderMsgpackBytes, xf *decFnInfo, xrv reflect.Value) { - xfnf2(d, xf, rvConvert(xrv, xrt)) - } - } else { - fi.addrD = true - fi.addrDf = false - xptr2rt := reflect.PointerTo(xrt) - fn.fd = func(d *decoderMsgpackBytes, xf *decFnInfo, xrv reflect.Value) { - if xrv.Kind() == reflect.Ptr { - xfnf2(d, xf, rvConvert(xrv, xptr2rt)) - } else { - xfnf2(d, xf, rvConvert(xrv, xrt)) - } - } - } - } - } - } - if fn.fd == nil { - switch rk { - case reflect.Bool: - fn.fd = (*decoderMsgpackBytes).kBool - case reflect.String: - fn.fd = (*decoderMsgpackBytes).kString - case reflect.Int: - fn.fd = (*decoderMsgpackBytes).kInt - case reflect.Int8: - fn.fd = (*decoderMsgpackBytes).kInt8 - case reflect.Int16: - fn.fd = (*decoderMsgpackBytes).kInt16 - case reflect.Int32: - fn.fd = (*decoderMsgpackBytes).kInt32 - case reflect.Int64: - fn.fd = (*decoderMsgpackBytes).kInt64 - case reflect.Uint: - fn.fd = (*decoderMsgpackBytes).kUint - case reflect.Uint8: - fn.fd = (*decoderMsgpackBytes).kUint8 - case reflect.Uint16: - fn.fd = (*decoderMsgpackBytes).kUint16 - case reflect.Uint32: - fn.fd = (*decoderMsgpackBytes).kUint32 - case reflect.Uint64: - fn.fd = (*decoderMsgpackBytes).kUint64 - case reflect.Uintptr: - fn.fd = (*decoderMsgpackBytes).kUintptr - case reflect.Float32: - fn.fd = (*decoderMsgpackBytes).kFloat32 - case reflect.Float64: - fn.fd = (*decoderMsgpackBytes).kFloat64 - case reflect.Complex64: - fn.fd = (*decoderMsgpackBytes).kComplex64 - case reflect.Complex128: - fn.fd = (*decoderMsgpackBytes).kComplex128 - case reflect.Chan: - fn.fd = (*decoderMsgpackBytes).kChan - case reflect.Slice: - fn.fd = (*decoderMsgpackBytes).kSlice - case reflect.Array: - fi.addrD = false - fn.fd = (*decoderMsgpackBytes).kArray - case reflect.Struct: - if ti.simple { - fn.fd = (*decoderMsgpackBytes).kStructSimple - } else { - fn.fd = (*decoderMsgpackBytes).kStruct - } - case reflect.Map: - fn.fd = (*decoderMsgpackBytes).kMap - case reflect.Interface: - - fn.fd = (*decoderMsgpackBytes).kInterface - default: - - fn.fd = (*decoderMsgpackBytes).kErr - } - } - } - return -} -func (e *msgpackEncDriverBytes) EncodeNil() { - e.w.writen1(mpNil) -} - -func (e *msgpackEncDriverBytes) EncodeInt(i int64) { - if e.h.PositiveIntUnsigned && i >= 0 { - e.EncodeUint(uint64(i)) - } else if i > math.MaxInt8 { - if i <= math.MaxInt16 { - e.w.writen1(mpInt16) - e.w.writen2(bigen.PutUint16(uint16(i))) - } else if i <= math.MaxInt32 { - e.w.writen1(mpInt32) - e.w.writen4(bigen.PutUint32(uint32(i))) - } else { - e.w.writen1(mpInt64) - e.w.writen8(bigen.PutUint64(uint64(i))) - } - } else if i >= -32 { - if e.h.NoFixedNum { - e.w.writen2(mpInt8, byte(i)) - } else { - e.w.writen1(byte(i)) - } - } else if i >= math.MinInt8 { - e.w.writen2(mpInt8, byte(i)) - } else if i >= math.MinInt16 { - e.w.writen1(mpInt16) - e.w.writen2(bigen.PutUint16(uint16(i))) - } else if i >= math.MinInt32 { - e.w.writen1(mpInt32) - e.w.writen4(bigen.PutUint32(uint32(i))) - } else { - e.w.writen1(mpInt64) - e.w.writen8(bigen.PutUint64(uint64(i))) - } -} - -func (e *msgpackEncDriverBytes) EncodeUint(i uint64) { - if i <= math.MaxInt8 { - if e.h.NoFixedNum { - e.w.writen2(mpUint8, byte(i)) - } else { - e.w.writen1(byte(i)) - } - } else if i <= math.MaxUint8 { - e.w.writen2(mpUint8, byte(i)) - } else if i <= math.MaxUint16 { - e.w.writen1(mpUint16) - e.w.writen2(bigen.PutUint16(uint16(i))) - } else if i <= math.MaxUint32 { - e.w.writen1(mpUint32) - e.w.writen4(bigen.PutUint32(uint32(i))) - } else { - e.w.writen1(mpUint64) - e.w.writen8(bigen.PutUint64(uint64(i))) - } -} - -func (e *msgpackEncDriverBytes) EncodeBool(b bool) { - if b { - e.w.writen1(mpTrue) - } else { - e.w.writen1(mpFalse) - } -} - -func (e *msgpackEncDriverBytes) EncodeFloat32(f float32) { - e.w.writen1(mpFloat) - e.w.writen4(bigen.PutUint32(math.Float32bits(f))) -} - -func (e *msgpackEncDriverBytes) EncodeFloat64(f float64) { - e.w.writen1(mpDouble) - e.w.writen8(bigen.PutUint64(math.Float64bits(f))) -} - -func (e *msgpackEncDriverBytes) EncodeTime(t time.Time) { - if t.IsZero() { - e.EncodeNil() - return - } - t = t.UTC() - sec, nsec := t.Unix(), uint64(t.Nanosecond()) - var data64 uint64 - var l = 4 - if sec >= 0 && sec>>34 == 0 { - data64 = (nsec << 34) | uint64(sec) - if data64&0xffffffff00000000 != 0 { - l = 8 - } - } else { - l = 12 - } - if e.h.WriteExt { - e.encodeExtPreamble(mpTimeExtTagU, l) - } else { - e.writeContainerLen(msgpackContainerRawLegacy, l) - } - switch l { - case 4: - e.w.writen4(bigen.PutUint32(uint32(data64))) - case 8: - e.w.writen8(bigen.PutUint64(data64)) - case 12: - e.w.writen4(bigen.PutUint32(uint32(nsec))) - e.w.writen8(bigen.PutUint64(uint64(sec))) - } -} - -func (e *msgpackEncDriverBytes) EncodeExt(v interface{}, basetype reflect.Type, xtag uint64, ext Ext) { - var bs0, bs []byte - if ext == SelfExt { - bs0 = e.e.blist.get(1024) - bs = bs0 - sideEncode(e.h, &e.h.sideEncPool, func(se encoderI) { oneOffEncode(se, v, &bs, basetype, true) }) - } else { - bs = ext.WriteExt(v) - } - if bs == nil { - e.writeNilBytes() - goto END - } - if e.h.WriteExt { - e.encodeExtPreamble(uint8(xtag), len(bs)) - e.w.writeb(bs) - } else { - e.EncodeBytes(bs) - } -END: - if ext == SelfExt { - e.e.blist.put(bs) - if !byteSliceSameData(bs0, bs) { - e.e.blist.put(bs0) - } - } -} - -func (e *msgpackEncDriverBytes) EncodeRawExt(re *RawExt) { - e.encodeExtPreamble(uint8(re.Tag), len(re.Data)) - e.w.writeb(re.Data) -} - -func (e *msgpackEncDriverBytes) encodeExtPreamble(xtag byte, l int) { - if l == 1 { - e.w.writen2(mpFixExt1, xtag) - } else if l == 2 { - e.w.writen2(mpFixExt2, xtag) - } else if l == 4 { - e.w.writen2(mpFixExt4, xtag) - } else if l == 8 { - e.w.writen2(mpFixExt8, xtag) - } else if l == 16 { - e.w.writen2(mpFixExt16, xtag) - } else if l < 256 { - e.w.writen2(mpExt8, byte(l)) - e.w.writen1(xtag) - } else if l < 65536 { - e.w.writen1(mpExt16) - e.w.writen2(bigen.PutUint16(uint16(l))) - e.w.writen1(xtag) - } else { - e.w.writen1(mpExt32) - e.w.writen4(bigen.PutUint32(uint32(l))) - e.w.writen1(xtag) - } -} - -func (e *msgpackEncDriverBytes) WriteArrayStart(length int) { - e.writeContainerLen(msgpackContainerList, length) -} - -func (e *msgpackEncDriverBytes) WriteMapStart(length int) { - e.writeContainerLen(msgpackContainerMap, length) -} - -func (e *msgpackEncDriverBytes) WriteArrayEmpty() { - - e.w.writen1(mpFixArrayMin) -} - -func (e *msgpackEncDriverBytes) WriteMapEmpty() { - - e.w.writen1(mpFixMapMin) -} - -func (e *msgpackEncDriverBytes) EncodeString(s string) { - var ct msgpackContainerType - if e.h.WriteExt { - if e.h.StringToRaw { - ct = msgpackContainerBin - } else { - ct = msgpackContainerStr - } - } else { - ct = msgpackContainerRawLegacy - } - e.writeContainerLen(ct, len(s)) - if len(s) > 0 { - e.w.writestr(s) - } -} - -func (e *msgpackEncDriverBytes) EncodeStringNoEscape4Json(v string) { e.EncodeString(v) } - -func (e *msgpackEncDriverBytes) EncodeStringBytesRaw(bs []byte) { - if e.h.WriteExt { - e.writeContainerLen(msgpackContainerBin, len(bs)) - } else { - e.writeContainerLen(msgpackContainerRawLegacy, len(bs)) - } - if len(bs) > 0 { - e.w.writeb(bs) - } -} - -func (e *msgpackEncDriverBytes) EncodeBytes(v []byte) { - if v == nil { - e.writeNilBytes() - return - } - e.EncodeStringBytesRaw(v) -} - -func (e *msgpackEncDriverBytes) writeNilOr(v byte) { - if !e.h.NilCollectionToZeroLength { - v = mpNil - } - e.w.writen1(v) -} - -func (e *msgpackEncDriverBytes) writeNilArray() { - e.writeNilOr(mpFixArrayMin) -} - -func (e *msgpackEncDriverBytes) writeNilMap() { - e.writeNilOr(mpFixMapMin) -} - -func (e *msgpackEncDriverBytes) writeNilBytes() { - e.writeNilOr(mpFixStrMin) -} - -func (e *msgpackEncDriverBytes) writeContainerLen(ct msgpackContainerType, l int) { - if ct.fixCutoff > 0 && l < int(ct.fixCutoff) { - e.w.writen1(ct.bFixMin | byte(l)) - } else if ct.b8 > 0 && l < 256 { - e.w.writen2(ct.b8, uint8(l)) - } else if l < 65536 { - e.w.writen1(ct.b16) - e.w.writen2(bigen.PutUint16(uint16(l))) - } else { - e.w.writen1(ct.b32) - e.w.writen4(bigen.PutUint32(uint32(l))) - } -} - -func (d *msgpackDecDriverBytes) DecodeNaked() { - if !d.bdRead { - d.readNextBd() - } - bd := d.bd - n := d.d.naked() - var decodeFurther bool - - switch bd { - case mpNil: - n.v = valueTypeNil - d.bdRead = false - case mpFalse: - n.v = valueTypeBool - n.b = false - case mpTrue: - n.v = valueTypeBool - n.b = true - - case mpFloat: - n.v = valueTypeFloat - n.f = float64(math.Float32frombits(bigen.Uint32(d.r.readn4()))) - case mpDouble: - n.v = valueTypeFloat - n.f = math.Float64frombits(bigen.Uint64(d.r.readn8())) - - case mpUint8: - n.v = valueTypeUint - n.u = uint64(d.r.readn1()) - case mpUint16: - n.v = valueTypeUint - n.u = uint64(bigen.Uint16(d.r.readn2())) - case mpUint32: - n.v = valueTypeUint - n.u = uint64(bigen.Uint32(d.r.readn4())) - case mpUint64: - n.v = valueTypeUint - n.u = uint64(bigen.Uint64(d.r.readn8())) - - case mpInt8: - n.v = valueTypeInt - n.i = int64(int8(d.r.readn1())) - case mpInt16: - n.v = valueTypeInt - n.i = int64(int16(bigen.Uint16(d.r.readn2()))) - case mpInt32: - n.v = valueTypeInt - n.i = int64(int32(bigen.Uint32(d.r.readn4()))) - case mpInt64: - n.v = valueTypeInt - n.i = int64(int64(bigen.Uint64(d.r.readn8()))) - - default: - switch { - case bd >= mpPosFixNumMin && bd <= mpPosFixNumMax: - - n.v = valueTypeInt - n.i = int64(int8(bd)) - case bd >= mpNegFixNumMin && bd <= mpNegFixNumMax: - - n.v = valueTypeInt - n.i = int64(int8(bd)) - case bd == mpStr8, bd == mpStr16, bd == mpStr32, bd >= mpFixStrMin && bd <= mpFixStrMax: - d.d.fauxUnionReadRawBytes(d, d.h.WriteExt, d.h.RawToString) - - case bd == mpBin8, bd == mpBin16, bd == mpBin32: - d.d.fauxUnionReadRawBytes(d, false, d.h.RawToString) - case bd == mpArray16, bd == mpArray32, bd >= mpFixArrayMin && bd <= mpFixArrayMax: - n.v = valueTypeArray - decodeFurther = true - case bd == mpMap16, bd == mpMap32, bd >= mpFixMapMin && bd <= mpFixMapMax: - n.v = valueTypeMap - decodeFurther = true - case bd >= mpFixExt1 && bd <= mpFixExt16, bd >= mpExt8 && bd <= mpExt32: - n.v = valueTypeExt - clen := d.readExtLen() - n.u = uint64(d.r.readn1()) - if n.u == uint64(mpTimeExtTagU) { - n.v = valueTypeTime - n.t = d.decodeTime(clen) - } else { - n.l = d.r.readx(uint(clen)) - } - default: - halt.errorf("cannot infer value: %s: Ox%x/%d/%s", msgBadDesc, bd, bd, mpdesc(bd)) - } - } - if !decodeFurther { - d.bdRead = false - } - if n.v == valueTypeUint && d.h.SignedInteger { - n.v = valueTypeInt - n.i = int64(n.u) - } -} - -func (d *msgpackDecDriverBytes) nextValueBytes() (v []byte) { - if !d.bdRead { - d.readNextBd() - } - d.r.startRecording() - d.nextValueBytesBdReadR() - v = d.r.stopRecording() - d.bdRead = false - return -} - -func (d *msgpackDecDriverBytes) nextValueBytesBdReadR() { - bd := d.bd - - var clen uint - - switch bd { - case mpNil, mpFalse, mpTrue: - case mpUint8, mpInt8: - d.r.readn1() - case mpUint16, mpInt16: - d.r.skip(2) - case mpFloat, mpUint32, mpInt32: - d.r.skip(4) - case mpDouble, mpUint64, mpInt64: - d.r.skip(8) - case mpStr8, mpBin8: - clen = uint(d.r.readn1()) - d.r.skip(clen) - case mpStr16, mpBin16: - x := d.r.readn2() - clen = uint(bigen.Uint16(x)) - d.r.skip(clen) - case mpStr32, mpBin32: - x := d.r.readn4() - clen = uint(bigen.Uint32(x)) - d.r.skip(clen) - case mpFixExt1: - d.r.readn1() - d.r.readn1() - case mpFixExt2: - d.r.readn1() - d.r.skip(2) - case mpFixExt4: - d.r.readn1() - d.r.skip(4) - case mpFixExt8: - d.r.readn1() - d.r.skip(8) - case mpFixExt16: - d.r.readn1() - d.r.skip(16) - case mpExt8: - clen = uint(d.r.readn1()) - d.r.readn1() - d.r.skip(clen) - case mpExt16: - x := d.r.readn2() - clen = uint(bigen.Uint16(x)) - d.r.readn1() - d.r.skip(clen) - case mpExt32: - x := d.r.readn4() - clen = uint(bigen.Uint32(x)) - d.r.readn1() - d.r.skip(clen) - case mpArray16: - x := d.r.readn2() - clen = uint(bigen.Uint16(x)) - for i := uint(0); i < clen; i++ { - d.readNextBd() - d.nextValueBytesBdReadR() - } - case mpArray32: - x := d.r.readn4() - clen = uint(bigen.Uint32(x)) - for i := uint(0); i < clen; i++ { - d.readNextBd() - d.nextValueBytesBdReadR() - } - case mpMap16: - x := d.r.readn2() - clen = uint(bigen.Uint16(x)) - for i := uint(0); i < clen; i++ { - d.readNextBd() - d.nextValueBytesBdReadR() - d.readNextBd() - d.nextValueBytesBdReadR() - } - case mpMap32: - x := d.r.readn4() - clen = uint(bigen.Uint32(x)) - for i := uint(0); i < clen; i++ { - d.readNextBd() - d.nextValueBytesBdReadR() - d.readNextBd() - d.nextValueBytesBdReadR() - } - default: - switch { - case bd >= mpPosFixNumMin && bd <= mpPosFixNumMax: - case bd >= mpNegFixNumMin && bd <= mpNegFixNumMax: - case bd >= mpFixStrMin && bd <= mpFixStrMax: - clen = uint(mpFixStrMin ^ bd) - d.r.skip(clen) - case bd >= mpFixArrayMin && bd <= mpFixArrayMax: - clen = uint(mpFixArrayMin ^ bd) - for i := uint(0); i < clen; i++ { - d.readNextBd() - d.nextValueBytesBdReadR() - } - case bd >= mpFixMapMin && bd <= mpFixMapMax: - clen = uint(mpFixMapMin ^ bd) - for i := uint(0); i < clen; i++ { - d.readNextBd() - d.nextValueBytesBdReadR() - d.readNextBd() - d.nextValueBytesBdReadR() - } - default: - halt.errorf("nextValueBytes: cannot infer value: %s: Ox%x/%d/%s", msgBadDesc, bd, bd, mpdesc(bd)) - } - } - return -} - -func (d *msgpackDecDriverBytes) decFloat4Int32() (f float32) { - fbits := bigen.Uint32(d.r.readn4()) - f = math.Float32frombits(fbits) - if !noFrac32(fbits) { - halt.errorf("assigning integer value from float32 with a fraction: %v", f) - } - return -} - -func (d *msgpackDecDriverBytes) decFloat4Int64() (f float64) { - fbits := bigen.Uint64(d.r.readn8()) - f = math.Float64frombits(fbits) - if !noFrac64(fbits) { - halt.errorf("assigning integer value from float64 with a fraction: %v", f) - } - return -} - -func (d *msgpackDecDriverBytes) DecodeInt64() (i int64) { - if d.advanceNil() { - return - } - switch d.bd { - case mpUint8: - i = int64(uint64(d.r.readn1())) - case mpUint16: - i = int64(uint64(bigen.Uint16(d.r.readn2()))) - case mpUint32: - i = int64(uint64(bigen.Uint32(d.r.readn4()))) - case mpUint64: - i = int64(bigen.Uint64(d.r.readn8())) - case mpInt8: - i = int64(int8(d.r.readn1())) - case mpInt16: - i = int64(int16(bigen.Uint16(d.r.readn2()))) - case mpInt32: - i = int64(int32(bigen.Uint32(d.r.readn4()))) - case mpInt64: - i = int64(bigen.Uint64(d.r.readn8())) - case mpFloat: - i = int64(d.decFloat4Int32()) - case mpDouble: - i = int64(d.decFloat4Int64()) - default: - switch { - case d.bd >= mpPosFixNumMin && d.bd <= mpPosFixNumMax: - i = int64(int8(d.bd)) - case d.bd >= mpNegFixNumMin && d.bd <= mpNegFixNumMax: - i = int64(int8(d.bd)) - default: - halt.errorf("cannot decode signed integer: %s: %x/%s", msgBadDesc, d.bd, mpdesc(d.bd)) - } - } - d.bdRead = false - return -} - -func (d *msgpackDecDriverBytes) DecodeUint64() (ui uint64) { - if d.advanceNil() { - return - } - switch d.bd { - case mpUint8: - ui = uint64(d.r.readn1()) - case mpUint16: - ui = uint64(bigen.Uint16(d.r.readn2())) - case mpUint32: - ui = uint64(bigen.Uint32(d.r.readn4())) - case mpUint64: - ui = bigen.Uint64(d.r.readn8()) - case mpInt8: - if i := int64(int8(d.r.readn1())); i >= 0 { - ui = uint64(i) - } else { - halt.errorf("assigning negative signed value: %v, to unsigned type", i) - } - case mpInt16: - if i := int64(int16(bigen.Uint16(d.r.readn2()))); i >= 0 { - ui = uint64(i) - } else { - halt.errorf("assigning negative signed value: %v, to unsigned type", i) - } - case mpInt32: - if i := int64(int32(bigen.Uint32(d.r.readn4()))); i >= 0 { - ui = uint64(i) - } else { - halt.errorf("assigning negative signed value: %v, to unsigned type", i) - } - case mpInt64: - if i := int64(bigen.Uint64(d.r.readn8())); i >= 0 { - ui = uint64(i) - } else { - halt.errorf("assigning negative signed value: %v, to unsigned type", i) - } - case mpFloat: - if f := d.decFloat4Int32(); f >= 0 { - ui = uint64(f) - } else { - halt.errorf("assigning negative float value: %v, to unsigned type", f) - } - case mpDouble: - if f := d.decFloat4Int64(); f >= 0 { - ui = uint64(f) - } else { - halt.errorf("assigning negative float value: %v, to unsigned type", f) - } - default: - switch { - case d.bd >= mpPosFixNumMin && d.bd <= mpPosFixNumMax: - ui = uint64(d.bd) - case d.bd >= mpNegFixNumMin && d.bd <= mpNegFixNumMax: - halt.errorf("assigning negative signed value: %v, to unsigned type", int(d.bd)) - default: - halt.errorf("cannot decode unsigned integer: %s: %x/%s", msgBadDesc, d.bd, mpdesc(d.bd)) - } - } - d.bdRead = false - return -} - -func (d *msgpackDecDriverBytes) DecodeFloat64() (f float64) { - if d.advanceNil() { - return - } - if d.bd == mpFloat { - f = float64(math.Float32frombits(bigen.Uint32(d.r.readn4()))) - } else if d.bd == mpDouble { - f = math.Float64frombits(bigen.Uint64(d.r.readn8())) - } else { - f = float64(d.DecodeInt64()) - } - d.bdRead = false - return -} - -func (d *msgpackDecDriverBytes) DecodeBool() (b bool) { - if d.advanceNil() { - return - } - if d.bd == mpFalse || d.bd == 0 { - - } else if d.bd == mpTrue || d.bd == 1 { - b = true - } else { - halt.errorf("cannot decode bool: %s: %x/%s", msgBadDesc, d.bd, mpdesc(d.bd)) - } - d.bdRead = false - return -} - -func (d *msgpackDecDriverBytes) DecodeBytes() (bs []byte, state dBytesAttachState) { - if d.advanceNil() { - return - } - - var cond bool - bd := d.bd - var clen int - if bd == mpBin8 || bd == mpBin16 || bd == mpBin32 { - clen = d.readContainerLen(msgpackContainerBin) - } else if bd == mpStr8 || bd == mpStr16 || bd == mpStr32 || - (bd >= mpFixStrMin && bd <= mpFixStrMax) { - clen = d.readContainerLen(msgpackContainerStr) - } else if bd == mpArray16 || bd == mpArray32 || - (bd >= mpFixArrayMin && bd <= mpFixArrayMax) { - slen := d.ReadArrayStart() - bs, cond = usableByteSlice(d.d.buf, slen) - for i := 0; i < len(bs); i++ { - bs[i] = uint8(chkOvf.UintV(d.DecodeUint64(), 8)) - } - for i := len(bs); i < slen; i++ { - bs = append(bs, uint8(chkOvf.UintV(d.DecodeUint64(), 8))) - } - if cond { - d.d.buf = bs - } - state = dBytesAttachBuffer - return - } else { - halt.errorf("invalid byte descriptor for decoding bytes, got: 0x%x", d.bd) - } - - d.bdRead = false - bs, cond = d.r.readxb(uint(clen)) - state = d.d.attachState(cond) - return -} - -func (d *msgpackDecDriverBytes) DecodeStringAsBytes() (out []byte, state dBytesAttachState) { - out, state = d.DecodeBytes() - if d.h.ValidateUnicode && !utf8.Valid(out) { - halt.errorf("DecodeStringAsBytes: invalid UTF-8: %s", out) - } - return -} - -func (d *msgpackDecDriverBytes) readNextBd() { - d.bd = d.r.readn1() - d.bdRead = true -} - -func (d *msgpackDecDriverBytes) advanceNil() (null bool) { - if !d.bdRead { - d.readNextBd() - } - if d.bd == mpNil { - d.bdRead = false - return true - } - return -} - -func (d *msgpackDecDriverBytes) TryNil() (v bool) { - return d.advanceNil() -} - -func (d *msgpackDecDriverBytes) ContainerType() (vt valueType) { - if !d.bdRead { - d.readNextBd() - } - bd := d.bd - if bd == mpNil { - d.bdRead = false - return valueTypeNil - } else if bd == mpBin8 || bd == mpBin16 || bd == mpBin32 { - return valueTypeBytes - } else if bd == mpStr8 || bd == mpStr16 || bd == mpStr32 || - (bd >= mpFixStrMin && bd <= mpFixStrMax) { - if d.h.WriteExt || d.h.RawToString { - return valueTypeString - } - return valueTypeBytes - } else if bd == mpArray16 || bd == mpArray32 || (bd >= mpFixArrayMin && bd <= mpFixArrayMax) { - return valueTypeArray - } else if bd == mpMap16 || bd == mpMap32 || (bd >= mpFixMapMin && bd <= mpFixMapMax) { - return valueTypeMap - } - return valueTypeUnset -} - -func (d *msgpackDecDriverBytes) readContainerLen(ct msgpackContainerType) (clen int) { - bd := d.bd - if bd == ct.b8 { - clen = int(d.r.readn1()) - } else if bd == ct.b16 { - clen = int(bigen.Uint16(d.r.readn2())) - } else if bd == ct.b32 { - clen = int(bigen.Uint32(d.r.readn4())) - } else if (ct.bFixMin & bd) == ct.bFixMin { - clen = int(ct.bFixMin ^ bd) - } else { - halt.errorf("cannot read container length: %s: hex: %x, decimal: %d", msgBadDesc, bd, bd) - } - d.bdRead = false - return -} - -func (d *msgpackDecDriverBytes) ReadMapStart() int { - if d.advanceNil() { - return containerLenNil - } - return d.readContainerLen(msgpackContainerMap) -} - -func (d *msgpackDecDriverBytes) ReadArrayStart() int { - if d.advanceNil() { - return containerLenNil - } - return d.readContainerLen(msgpackContainerList) -} - -func (d *msgpackDecDriverBytes) readExtLen() (clen int) { - switch d.bd { - case mpFixExt1: - clen = 1 - case mpFixExt2: - clen = 2 - case mpFixExt4: - clen = 4 - case mpFixExt8: - clen = 8 - case mpFixExt16: - clen = 16 - case mpExt8: - clen = int(d.r.readn1()) - case mpExt16: - clen = int(bigen.Uint16(d.r.readn2())) - case mpExt32: - clen = int(bigen.Uint32(d.r.readn4())) - default: - halt.errorf("decoding ext bytes: found unexpected byte: %x", d.bd) - } - return -} - -func (d *msgpackDecDriverBytes) DecodeTime() (t time.Time) { - - if d.advanceNil() { - return - } - bd := d.bd - var clen int - if bd == mpBin8 || bd == mpBin16 || bd == mpBin32 { - clen = d.readContainerLen(msgpackContainerBin) - } else if bd == mpStr8 || bd == mpStr16 || bd == mpStr32 || - (bd >= mpFixStrMin && bd <= mpFixStrMax) { - clen = d.readContainerLen(msgpackContainerStr) - } else { - - d.bdRead = false - b2 := d.r.readn1() - if d.bd == mpFixExt4 && b2 == mpTimeExtTagU { - clen = 4 - } else if d.bd == mpFixExt8 && b2 == mpTimeExtTagU { - clen = 8 - } else if d.bd == mpExt8 && b2 == 12 && d.r.readn1() == mpTimeExtTagU { - clen = 12 - } else { - halt.errorf("invalid stream for decoding time as extension: got 0x%x, 0x%x", d.bd, b2) - } - } - return d.decodeTime(clen) -} - -func (d *msgpackDecDriverBytes) decodeTime(clen int) (t time.Time) { - d.bdRead = false - switch clen { - case 4: - t = time.Unix(int64(bigen.Uint32(d.r.readn4())), 0).UTC() - case 8: - tv := bigen.Uint64(d.r.readn8()) - t = time.Unix(int64(tv&0x00000003ffffffff), int64(tv>>34)).UTC() - case 12: - nsec := bigen.Uint32(d.r.readn4()) - sec := bigen.Uint64(d.r.readn8()) - t = time.Unix(int64(sec), int64(nsec)).UTC() - default: - halt.errorf("invalid length of bytes for decoding time - expecting 4 or 8 or 12, got %d", clen) - } - return -} - -func (d *msgpackDecDriverBytes) DecodeExt(rv interface{}, basetype reflect.Type, xtag uint64, ext Ext) { - xbs, _, _, ok := d.decodeExtV(ext != nil, xtag) - if !ok { - return - } - if ext == SelfExt { - sideDecode(d.h, &d.h.sideDecPool, func(sd decoderI) { oneOffDecode(sd, rv, xbs, basetype, true) }) - } else { - ext.ReadExt(rv, xbs) - } -} - -func (d *msgpackDecDriverBytes) DecodeRawExt(re *RawExt) { - xbs, realxtag, state, ok := d.decodeExtV(false, 0) - if !ok { - return - } - re.Tag = uint64(realxtag) - re.setData(xbs, state >= dBytesAttachViewZerocopy) -} - -func (d *msgpackDecDriverBytes) decodeExtV(verifyTag bool, xtagIn uint64) (xbs []byte, xtag byte, bstate dBytesAttachState, ok bool) { - if xtagIn > 0xff { - halt.errorf("ext: tag must be <= 0xff; got: %v", xtagIn) - } - if d.advanceNil() { - return - } - tag := uint8(xtagIn) - xbd := d.bd - if xbd == mpBin8 || xbd == mpBin16 || xbd == mpBin32 { - xbs, bstate = d.DecodeBytes() - } else if xbd == mpStr8 || xbd == mpStr16 || xbd == mpStr32 || - (xbd >= mpFixStrMin && xbd <= mpFixStrMax) { - xbs, bstate = d.DecodeStringAsBytes() - } else { - clen := d.readExtLen() - xtag = d.r.readn1() - if verifyTag && xtag != tag { - halt.errorf("wrong extension tag - got %b, expecting %v", xtag, tag) - } - xbs, ok = d.r.readxb(uint(clen)) - bstate = d.d.attachState(ok) - - } - d.bdRead = false - ok = true - return -} - -func (d *msgpackEncDriverBytes) init(hh Handle, shared *encoderBase, enc encoderI) (fp interface{}) { - callMake(&d.w) - d.h = hh.(*MsgpackHandle) - d.e = shared - if shared.bytes { - fp = msgpackFpEncBytes - } else { - fp = msgpackFpEncIO - } - - d.init2(enc) - return -} - -func (e *msgpackEncDriverBytes) writeBytesAsis(b []byte) { e.w.writeb(b) } - -func (e *msgpackEncDriverBytes) writerEnd() { e.w.end() } - -func (e *msgpackEncDriverBytes) resetOutBytes(out *[]byte) { - e.w.resetBytes(*out, out) -} - -func (e *msgpackEncDriverBytes) resetOutIO(out io.Writer) { - e.w.resetIO(out, e.h.WriterBufferSize, &e.e.blist) -} - -func (d *msgpackDecDriverBytes) init(hh Handle, shared *decoderBase, dec decoderI) (fp interface{}) { - callMake(&d.r) - d.h = hh.(*MsgpackHandle) - d.d = shared - if shared.bytes { - fp = msgpackFpDecBytes - } else { - fp = msgpackFpDecIO - } - - d.init2(dec) - return -} - -func (d *msgpackDecDriverBytes) NumBytesRead() int { - return int(d.r.numread()) -} - -func (d *msgpackDecDriverBytes) resetInBytes(in []byte) { - d.r.resetBytes(in) -} - -func (d *msgpackDecDriverBytes) resetInIO(r io.Reader) { - d.r.resetIO(r, d.h.ReaderBufferSize, d.h.MaxInitLen, &d.d.blist) -} - -func (d *msgpackDecDriverBytes) descBd() string { - return sprintf("%v (%s)", d.bd, mpdesc(d.bd)) -} - -func (d *msgpackDecDriverBytes) DecodeFloat32() (f float32) { - return float32(chkOvf.Float32V(d.DecodeFloat64())) -} - -type helperEncDriverMsgpackIO struct{} -type encFnMsgpackIO struct { - i encFnInfo - fe func(*encoderMsgpackIO, *encFnInfo, reflect.Value) -} -type encRtidFnMsgpackIO struct { - rtid uintptr - fn *encFnMsgpackIO -} -type encoderMsgpackIO struct { - dh helperEncDriverMsgpackIO - fp *fastpathEsMsgpackIO - e msgpackEncDriverIO - encoderBase -} -type helperDecDriverMsgpackIO struct{} -type decFnMsgpackIO struct { - i decFnInfo - fd func(*decoderMsgpackIO, *decFnInfo, reflect.Value) -} -type decRtidFnMsgpackIO struct { - rtid uintptr - fn *decFnMsgpackIO -} -type decoderMsgpackIO struct { - dh helperDecDriverMsgpackIO - fp *fastpathDsMsgpackIO - d msgpackDecDriverIO - decoderBase -} -type msgpackEncDriverIO struct { - noBuiltInTypes - encDriverNoopContainerWriter - encDriverNoState - encDriverContainerNoTrackerT - encInit2er - - h *MsgpackHandle - e *encoderBase - w bufioEncWriter -} -type msgpackDecDriverIO struct { - decDriverNoopContainerReader - decDriverNoopNumberHelper - decInit2er - - h *MsgpackHandle - d *decoderBase - r ioDecReader - - bdAndBdread - - noBuiltInTypes -} - -func (e *encoderMsgpackIO) rawExt(_ *encFnInfo, rv reflect.Value) { - if re := rv2i(rv).(*RawExt); re == nil { - e.e.EncodeNil() - } else { - e.e.EncodeRawExt(re) - } -} - -func (e *encoderMsgpackIO) ext(f *encFnInfo, rv reflect.Value) { - e.e.EncodeExt(rv2i(rv), f.ti.rt, f.xfTag, f.xfFn) -} - -func (e *encoderMsgpackIO) selferMarshal(_ *encFnInfo, rv reflect.Value) { - rv2i(rv).(Selfer).CodecEncodeSelf(&Encoder{e}) -} - -func (e *encoderMsgpackIO) binaryMarshal(_ *encFnInfo, rv reflect.Value) { - bs, fnerr := rv2i(rv).(encoding.BinaryMarshaler).MarshalBinary() - e.marshalRaw(bs, fnerr) -} - -func (e *encoderMsgpackIO) textMarshal(_ *encFnInfo, rv reflect.Value) { - bs, fnerr := rv2i(rv).(encoding.TextMarshaler).MarshalText() - e.marshalUtf8(bs, fnerr) -} - -func (e *encoderMsgpackIO) jsonMarshal(_ *encFnInfo, rv reflect.Value) { - bs, fnerr := rv2i(rv).(jsonMarshaler).MarshalJSON() - e.marshalAsis(bs, fnerr) -} - -func (e *encoderMsgpackIO) raw(_ *encFnInfo, rv reflect.Value) { - e.rawBytes(rv2i(rv).(Raw)) -} - -func (e *encoderMsgpackIO) encodeComplex64(v complex64) { - if imag(v) != 0 { - halt.errorf("cannot encode complex number: %v, with imaginary values: %v", any(v), any(imag(v))) - } - e.e.EncodeFloat32(real(v)) -} - -func (e *encoderMsgpackIO) encodeComplex128(v complex128) { - if imag(v) != 0 { - halt.errorf("cannot encode complex number: %v, with imaginary values: %v", any(v), any(imag(v))) - } - e.e.EncodeFloat64(real(v)) -} - -func (e *encoderMsgpackIO) kBool(_ *encFnInfo, rv reflect.Value) { - e.e.EncodeBool(rvGetBool(rv)) -} - -func (e *encoderMsgpackIO) kTime(_ *encFnInfo, rv reflect.Value) { - e.e.EncodeTime(rvGetTime(rv)) -} - -func (e *encoderMsgpackIO) kString(_ *encFnInfo, rv reflect.Value) { - e.e.EncodeString(rvGetString(rv)) -} - -func (e *encoderMsgpackIO) kFloat32(_ *encFnInfo, rv reflect.Value) { - e.e.EncodeFloat32(rvGetFloat32(rv)) -} - -func (e *encoderMsgpackIO) kFloat64(_ *encFnInfo, rv reflect.Value) { - e.e.EncodeFloat64(rvGetFloat64(rv)) -} - -func (e *encoderMsgpackIO) kComplex64(_ *encFnInfo, rv reflect.Value) { - e.encodeComplex64(rvGetComplex64(rv)) -} - -func (e *encoderMsgpackIO) kComplex128(_ *encFnInfo, rv reflect.Value) { - e.encodeComplex128(rvGetComplex128(rv)) -} - -func (e *encoderMsgpackIO) kInt(_ *encFnInfo, rv reflect.Value) { - e.e.EncodeInt(int64(rvGetInt(rv))) -} - -func (e *encoderMsgpackIO) kInt8(_ *encFnInfo, rv reflect.Value) { - e.e.EncodeInt(int64(rvGetInt8(rv))) -} - -func (e *encoderMsgpackIO) kInt16(_ *encFnInfo, rv reflect.Value) { - e.e.EncodeInt(int64(rvGetInt16(rv))) -} - -func (e *encoderMsgpackIO) kInt32(_ *encFnInfo, rv reflect.Value) { - e.e.EncodeInt(int64(rvGetInt32(rv))) -} - -func (e *encoderMsgpackIO) kInt64(_ *encFnInfo, rv reflect.Value) { - e.e.EncodeInt(int64(rvGetInt64(rv))) -} - -func (e *encoderMsgpackIO) kUint(_ *encFnInfo, rv reflect.Value) { - e.e.EncodeUint(uint64(rvGetUint(rv))) -} - -func (e *encoderMsgpackIO) kUint8(_ *encFnInfo, rv reflect.Value) { - e.e.EncodeUint(uint64(rvGetUint8(rv))) -} - -func (e *encoderMsgpackIO) kUint16(_ *encFnInfo, rv reflect.Value) { - e.e.EncodeUint(uint64(rvGetUint16(rv))) -} - -func (e *encoderMsgpackIO) kUint32(_ *encFnInfo, rv reflect.Value) { - e.e.EncodeUint(uint64(rvGetUint32(rv))) -} - -func (e *encoderMsgpackIO) kUint64(_ *encFnInfo, rv reflect.Value) { - e.e.EncodeUint(uint64(rvGetUint64(rv))) -} - -func (e *encoderMsgpackIO) kUintptr(_ *encFnInfo, rv reflect.Value) { - e.e.EncodeUint(uint64(rvGetUintptr(rv))) -} - -func (e *encoderMsgpackIO) kSeqFn(rt reflect.Type) (fn *encFnMsgpackIO) { - - if rt = baseRT(rt); rt.Kind() != reflect.Interface { - fn = e.fn(rt) - } - return -} - -func (e *encoderMsgpackIO) kArrayWMbs(rv reflect.Value, ti *typeInfo, isSlice bool) { - var l int - if isSlice { - l = rvLenSlice(rv) - } else { - l = rv.Len() - } - if l == 0 { - e.e.WriteMapEmpty() - return - } - e.haltOnMbsOddLen(l) - e.mapStart(l >> 1) - - var fn *encFnMsgpackIO - builtin := ti.tielem.flagEncBuiltin - if !builtin { - fn = e.kSeqFn(ti.elem) - } - - j := 0 - e.c = containerMapKey - e.e.WriteMapElemKey(true) - for { - rvv := rvArrayIndex(rv, j, ti, isSlice) - if builtin { - e.encodeIB(rv2i(baseRVRV(rvv))) - } else { - e.encodeValue(rvv, fn) - } - j++ - if j == l { - break - } - if j&1 == 0 { - e.c = containerMapKey - e.e.WriteMapElemKey(false) - } else { - e.mapElemValue() - } - } - e.c = 0 - e.e.WriteMapEnd() - -} - -func (e *encoderMsgpackIO) kArrayW(rv reflect.Value, ti *typeInfo, isSlice bool) { - var l int - if isSlice { - l = rvLenSlice(rv) - } else { - l = rv.Len() - } - if l <= 0 { - e.e.WriteArrayEmpty() - return - } - e.arrayStart(l) - - var fn *encFnMsgpackIO - if !ti.tielem.flagEncBuiltin { - fn = e.kSeqFn(ti.elem) - } - - j := 0 - e.c = containerArrayElem - e.e.WriteArrayElem(true) - builtin := ti.tielem.flagEncBuiltin - for { - rvv := rvArrayIndex(rv, j, ti, isSlice) - if builtin { - e.encodeIB(rv2i(baseRVRV(rvv))) - } else { - e.encodeValue(rvv, fn) - } - j++ - if j == l { - break - } - e.c = containerArrayElem - e.e.WriteArrayElem(false) - } - - e.c = 0 - e.e.WriteArrayEnd() -} - -func (e *encoderMsgpackIO) kChan(f *encFnInfo, rv reflect.Value) { - if f.ti.chandir&uint8(reflect.RecvDir) == 0 { - halt.errorStr("send-only channel cannot be encoded") - } - if !f.ti.mbs && uint8TypId == rt2id(f.ti.elem) { - e.kSliceBytesChan(rv) - return - } - rtslice := reflect.SliceOf(f.ti.elem) - rv = chanToSlice(rv, rtslice, e.h.ChanRecvTimeout) - ti := e.h.getTypeInfo(rt2id(rtslice), rtslice) - if f.ti.mbs { - e.kArrayWMbs(rv, ti, true) - } else { - e.kArrayW(rv, ti, true) - } -} - -func (e *encoderMsgpackIO) kSlice(f *encFnInfo, rv reflect.Value) { - if f.ti.mbs { - e.kArrayWMbs(rv, f.ti, true) - } else if f.ti.rtid == uint8SliceTypId || uint8TypId == rt2id(f.ti.elem) { - - e.e.EncodeBytes(rvGetBytes(rv)) - } else { - e.kArrayW(rv, f.ti, true) - } -} - -func (e *encoderMsgpackIO) kArray(f *encFnInfo, rv reflect.Value) { - if f.ti.mbs { - e.kArrayWMbs(rv, f.ti, false) - } else if handleBytesWithinKArray && uint8TypId == rt2id(f.ti.elem) { - e.e.EncodeStringBytesRaw(rvGetArrayBytes(rv, nil)) - } else { - e.kArrayW(rv, f.ti, false) - } -} - -func (e *encoderMsgpackIO) kSliceBytesChan(rv reflect.Value) { - - bs0 := e.blist.peek(32, true) - bs := bs0 - - irv := rv2i(rv) - ch, ok := irv.(<-chan byte) - if !ok { - ch = irv.(chan byte) - } - -L1: - switch timeout := e.h.ChanRecvTimeout; { - case timeout == 0: - for { - select { - case b := <-ch: - bs = append(bs, b) - default: - break L1 - } - } - case timeout > 0: - tt := time.NewTimer(timeout) - for { - select { - case b := <-ch: - bs = append(bs, b) - case <-tt.C: - - break L1 - } - } - default: - for b := range ch { - bs = append(bs, b) - } - } - - e.e.EncodeBytes(bs) - e.blist.put(bs) - if !byteSliceSameData(bs0, bs) { - e.blist.put(bs0) - } -} - -func (e *encoderMsgpackIO) kStructFieldKey(keyType valueType, encName string) { - - if keyType == valueTypeString { - e.e.EncodeString(encName) - } else if keyType == valueTypeInt { - e.e.EncodeInt(must.Int(strconv.ParseInt(encName, 10, 64))) - } else if keyType == valueTypeUint { - e.e.EncodeUint(must.Uint(strconv.ParseUint(encName, 10, 64))) - } else if keyType == valueTypeFloat { - e.e.EncodeFloat64(must.Float(strconv.ParseFloat(encName, 64))) - } else { - halt.errorStr2("invalid struct key type: ", keyType.String()) - } - -} - -func (e *encoderMsgpackIO) kStructSimple(f *encFnInfo, rv reflect.Value) { - _ = e.e - tisfi := f.ti.sfi.source() - - chkCirRef := e.h.CheckCircularRef - var si *structFieldInfo - var j int - - if f.ti.toArray || e.h.StructToArray { - if len(tisfi) == 0 { - e.e.WriteArrayEmpty() - return - } - e.arrayStart(len(tisfi)) - for j, si = range tisfi { - e.c = containerArrayElem - e.e.WriteArrayElem(j == 0) - if si.encBuiltin { - e.encodeIB(rv2i(si.fieldNoAlloc(rv, true))) - } else { - e.encodeValue(si.fieldNoAlloc(rv, !chkCirRef), nil) - } - } - e.c = 0 - e.e.WriteArrayEnd() - } else { - if len(tisfi) == 0 { - e.e.WriteMapEmpty() - return - } - if e.h.Canonical { - tisfi = f.ti.sfi.sorted() - } - e.mapStart(len(tisfi)) - for j, si = range tisfi { - e.c = containerMapKey - e.e.WriteMapElemKey(j == 0) - e.e.EncodeStringNoEscape4Json(si.encName) - e.mapElemValue() - if si.encBuiltin { - e.encodeIB(rv2i(si.fieldNoAlloc(rv, true))) - } else { - e.encodeValue(si.fieldNoAlloc(rv, !chkCirRef), nil) - } - } - e.c = 0 - e.e.WriteMapEnd() - } -} - -func (e *encoderMsgpackIO) kStruct(f *encFnInfo, rv reflect.Value) { - _ = e.e - ti := f.ti - toMap := !(ti.toArray || e.h.StructToArray) - var mf map[string]interface{} - if ti.flagMissingFielder { - toMap = true - mf = rv2i(rv).(MissingFielder).CodecMissingFields() - } else if ti.flagMissingFielderPtr { - toMap = true - if rv.CanAddr() { - mf = rv2i(rvAddr(rv, ti.ptr)).(MissingFielder).CodecMissingFields() - } else { - mf = rv2i(e.addrRV(rv, ti.rt, ti.ptr)).(MissingFielder).CodecMissingFields() - } - } - newlen := len(mf) - tisfi := ti.sfi.source() - newlen += len(tisfi) - - var fkvs = e.slist.get(newlen)[:newlen] - - recur := e.h.RecursiveEmptyCheck - chkCirRef := e.h.CheckCircularRef - - var xlen int - - var kv sfiRv - var j int - var sf encStructFieldObj - if toMap { - newlen = 0 - if e.h.Canonical { - tisfi = f.ti.sfi.sorted() - } - for _, si := range tisfi { - - if si.omitEmpty { - kv.r = si.fieldNoAlloc(rv, false) - if isEmptyValue(kv.r, e.h.TypeInfos, recur) { - continue - } - } else { - kv.r = si.fieldNoAlloc(rv, si.encBuiltin || !chkCirRef) - } - kv.v = si - fkvs[newlen] = kv - newlen++ - } - - var mf2s []stringIntf - if len(mf) != 0 { - mf2s = make([]stringIntf, 0, len(mf)) - for k, v := range mf { - if k == "" { - continue - } - if ti.infoFieldOmitempty && isEmptyValue(reflect.ValueOf(v), e.h.TypeInfos, recur) { - continue - } - mf2s = append(mf2s, stringIntf{k, v}) - } - } - - xlen = newlen + len(mf2s) - if xlen == 0 { - e.e.WriteMapEmpty() - goto END - } - - e.mapStart(xlen) - - if len(mf2s) != 0 && e.h.Canonical { - mf2w := make([]encStructFieldObj, newlen+len(mf2s)) - for j = 0; j < newlen; j++ { - kv = fkvs[j] - mf2w[j] = encStructFieldObj{kv.v.encName, kv.r, nil, true, - !kv.v.encNameEscape4Json, kv.v.encBuiltin} - } - for _, v := range mf2s { - mf2w[j] = encStructFieldObj{v.v, reflect.Value{}, v.i, false, false, false} - j++ - } - sort.Sort((encStructFieldObjSlice)(mf2w)) - for j, sf = range mf2w { - e.c = containerMapKey - e.e.WriteMapElemKey(j == 0) - if ti.keyType == valueTypeString && sf.noEsc4json { - e.e.EncodeStringNoEscape4Json(sf.key) - } else { - e.kStructFieldKey(ti.keyType, sf.key) - } - e.mapElemValue() - if sf.isRv { - if sf.builtin { - e.encodeIB(rv2i(baseRVRV(sf.rv))) - } else { - e.encodeValue(sf.rv, nil) - } - } else { - if !e.encodeBuiltin(sf.intf) { - e.encodeR(reflect.ValueOf(sf.intf)) - } - - } - } - } else { - keytyp := ti.keyType - for j = 0; j < newlen; j++ { - kv = fkvs[j] - e.c = containerMapKey - e.e.WriteMapElemKey(j == 0) - if ti.keyType == valueTypeString && !kv.v.encNameEscape4Json { - e.e.EncodeStringNoEscape4Json(kv.v.encName) - } else { - e.kStructFieldKey(keytyp, kv.v.encName) - } - e.mapElemValue() - if kv.v.encBuiltin { - e.encodeIB(rv2i(baseRVRV(kv.r))) - } else { - e.encodeValue(kv.r, nil) - } - } - for _, v := range mf2s { - e.c = containerMapKey - e.e.WriteMapElemKey(j == 0) - e.kStructFieldKey(keytyp, v.v) - e.mapElemValue() - if !e.encodeBuiltin(v.i) { - e.encodeR(reflect.ValueOf(v.i)) - } - - j++ - } - } - - e.c = 0 - e.e.WriteMapEnd() - } else { - newlen = len(tisfi) - for i, si := range tisfi { - - if si.omitEmpty { - - kv.r = si.fieldNoAlloc(rv, false) - if isEmptyContainerValue(kv.r, e.h.TypeInfos, recur) { - kv.r = reflect.Value{} - } - } else { - kv.r = si.fieldNoAlloc(rv, si.encBuiltin || !chkCirRef) - } - kv.v = si - fkvs[i] = kv - } - - if newlen == 0 { - e.e.WriteArrayEmpty() - goto END - } - - e.arrayStart(newlen) - for j = 0; j < newlen; j++ { - e.c = containerArrayElem - e.e.WriteArrayElem(j == 0) - kv = fkvs[j] - if !kv.r.IsValid() { - e.e.EncodeNil() - } else if kv.v.encBuiltin { - e.encodeIB(rv2i(baseRVRV(kv.r))) - } else { - e.encodeValue(kv.r, nil) - } - } - e.c = 0 - e.e.WriteArrayEnd() - } - -END: - - e.slist.put(fkvs) -} - -func (e *encoderMsgpackIO) kMap(f *encFnInfo, rv reflect.Value) { - _ = e.e - l := rvLenMap(rv) - if l == 0 { - e.e.WriteMapEmpty() - return - } - e.mapStart(l) - - var keyFn, valFn *encFnMsgpackIO - - ktypeKind := reflect.Kind(f.ti.keykind) - vtypeKind := reflect.Kind(f.ti.elemkind) - - rtval := f.ti.elem - rtvalkind := vtypeKind - for rtvalkind == reflect.Ptr { - rtval = rtval.Elem() - rtvalkind = rtval.Kind() - } - if rtvalkind != reflect.Interface { - valFn = e.fn(rtval) - } - - var rvv = mapAddrLoopvarRV(f.ti.elem, vtypeKind) - - rtkey := f.ti.key - var keyTypeIsString = stringTypId == rt2id(rtkey) - if keyTypeIsString { - keyFn = e.fn(rtkey) - } else { - for rtkey.Kind() == reflect.Ptr { - rtkey = rtkey.Elem() - } - if rtkey.Kind() != reflect.Interface { - keyFn = e.fn(rtkey) - } - } - - if e.h.Canonical { - e.kMapCanonical(f.ti, rv, rvv, keyFn, valFn) - e.c = 0 - e.e.WriteMapEnd() - return - } - - var rvk = mapAddrLoopvarRV(f.ti.key, ktypeKind) - - var it mapIter - mapRange(&it, rv, rvk, rvv, true) - - kbuiltin := f.ti.tikey.flagEncBuiltin - vbuiltin := f.ti.tielem.flagEncBuiltin - for j := 0; it.Next(); j++ { - rv = it.Key() - e.c = containerMapKey - e.e.WriteMapElemKey(j == 0) - if keyTypeIsString { - e.e.EncodeString(rvGetString(rv)) - } else if kbuiltin { - e.encodeIB(rv2i(baseRVRV(rv))) - } else { - e.encodeValue(rv, keyFn) - } - e.mapElemValue() - rv = it.Value() - if vbuiltin { - e.encodeIB(rv2i(baseRVRV(rv))) - } else { - e.encodeValue(it.Value(), valFn) - } - } - it.Done() - - e.c = 0 - e.e.WriteMapEnd() -} - -func (e *encoderMsgpackIO) kMapCanonical(ti *typeInfo, rv, rvv reflect.Value, keyFn, valFn *encFnMsgpackIO) { - _ = e.e - - rtkey := ti.key - rtkeydecl := rtkey.PkgPath() == "" && rtkey.Name() != "" - - mks := rv.MapKeys() - rtkeyKind := rtkey.Kind() - mparams := getMapReqParams(ti) - - switch rtkeyKind { - case reflect.Bool: - - if len(mks) == 2 && mks[0].Bool() { - mks[0], mks[1] = mks[1], mks[0] - } - for i := range mks { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - if rtkeydecl { - e.e.EncodeBool(mks[i].Bool()) - } else { - e.encodeValueNonNil(mks[i], keyFn) - } - e.mapElemValue() - e.encodeValue(mapGet(rv, mks[i], rvv, mparams), valFn) - } - case reflect.String: - mksv := make([]orderedRv[string], len(mks)) - for i, k := range mks { - v := &mksv[i] - v.r = k - v.v = rvGetString(k) - } - slices.SortFunc(mksv, cmpOrderedRv) - for i := range mksv { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - if rtkeydecl { - e.e.EncodeString(mksv[i].v) - } else { - e.encodeValueNonNil(mksv[i].r, keyFn) - } - e.mapElemValue() - e.encodeValue(mapGet(rv, mksv[i].r, rvv, mparams), valFn) - } - case reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64, reflect.Uint, reflect.Uintptr: - mksv := make([]orderedRv[uint64], len(mks)) - for i, k := range mks { - v := &mksv[i] - v.r = k - v.v = k.Uint() - } - slices.SortFunc(mksv, cmpOrderedRv) - for i := range mksv { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - if rtkeydecl { - e.e.EncodeUint(mksv[i].v) - } else { - e.encodeValueNonNil(mksv[i].r, keyFn) - } - e.mapElemValue() - e.encodeValue(mapGet(rv, mksv[i].r, rvv, mparams), valFn) - } - case reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64, reflect.Int: - mksv := make([]orderedRv[int64], len(mks)) - for i, k := range mks { - v := &mksv[i] - v.r = k - v.v = k.Int() - } - slices.SortFunc(mksv, cmpOrderedRv) - for i := range mksv { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - if rtkeydecl { - e.e.EncodeInt(mksv[i].v) - } else { - e.encodeValueNonNil(mksv[i].r, keyFn) - } - e.mapElemValue() - e.encodeValue(mapGet(rv, mksv[i].r, rvv, mparams), valFn) - } - case reflect.Float32: - mksv := make([]orderedRv[float64], len(mks)) - for i, k := range mks { - v := &mksv[i] - v.r = k - v.v = k.Float() - } - slices.SortFunc(mksv, cmpOrderedRv) - for i := range mksv { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - if rtkeydecl { - e.e.EncodeFloat32(float32(mksv[i].v)) - } else { - e.encodeValueNonNil(mksv[i].r, keyFn) - } - e.mapElemValue() - e.encodeValue(mapGet(rv, mksv[i].r, rvv, mparams), valFn) - } - case reflect.Float64: - mksv := make([]orderedRv[float64], len(mks)) - for i, k := range mks { - v := &mksv[i] - v.r = k - v.v = k.Float() - } - slices.SortFunc(mksv, cmpOrderedRv) - for i := range mksv { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - if rtkeydecl { - e.e.EncodeFloat64(mksv[i].v) - } else { - e.encodeValueNonNil(mksv[i].r, keyFn) - } - e.mapElemValue() - e.encodeValue(mapGet(rv, mksv[i].r, rvv, mparams), valFn) - } - default: - if rtkey == timeTyp { - mksv := make([]timeRv, len(mks)) - for i, k := range mks { - v := &mksv[i] - v.r = k - v.v = rv2i(k).(time.Time) - } - slices.SortFunc(mksv, cmpTimeRv) - for i := range mksv { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeTime(mksv[i].v) - e.mapElemValue() - e.encodeValue(mapGet(rv, mksv[i].r, rvv, mparams), valFn) - } - break - } - - bs0 := e.blist.get(len(mks) * 16) - mksv := bs0 - mksbv := make([]bytesRv, len(mks)) - - sideEncode(e.hh, &e.h.sideEncPool, func(se encoderI) { - se.ResetBytes(&mksv) - for i, k := range mks { - v := &mksbv[i] - l := len(mksv) - se.setContainerState(containerMapKey) - se.encodeR(baseRVRV(k)) - se.atEndOfEncode() - se.writerEnd() - v.r = k - v.v = mksv[l:] - } - }) - - slices.SortFunc(mksbv, cmpBytesRv) - for j := range mksbv { - e.c = containerMapKey - e.e.WriteMapElemKey(j == 0) - e.e.writeBytesAsis(mksbv[j].v) - e.mapElemValue() - e.encodeValue(mapGet(rv, mksbv[j].r, rvv, mparams), valFn) - } - e.blist.put(mksv) - if !byteSliceSameData(bs0, mksv) { - e.blist.put(bs0) - } - } -} - -func (e *encoderMsgpackIO) init(h Handle) { - initHandle(h) - callMake(&e.e) - e.hh = h - e.h = h.getBasicHandle() - - e.err = errEncoderNotInitialized - - e.fp = e.e.init(h, &e.encoderBase, e).(*fastpathEsMsgpackIO) - - if e.bytes { - e.rtidFn = &e.h.rtidFnsEncBytes - e.rtidFnNoExt = &e.h.rtidFnsEncNoExtBytes - } else { - e.rtidFn = &e.h.rtidFnsEncIO - e.rtidFnNoExt = &e.h.rtidFnsEncNoExtIO - } - - e.reset() -} - -func (e *encoderMsgpackIO) reset() { - e.e.reset() - if e.ci != nil { - e.ci = e.ci[:0] - } - e.c = 0 - e.calls = 0 - e.seq = 0 - e.err = nil -} - -func (e *encoderMsgpackIO) Encode(v interface{}) (err error) { - - defer panicValToErr(e, callRecoverSentinel, &e.err, &err, debugging) - e.mustEncode(v) - return -} - -func (e *encoderMsgpackIO) MustEncode(v interface{}) { - defer panicValToErr(e, callRecoverSentinel, &e.err, nil, true) - e.mustEncode(v) - return -} - -func (e *encoderMsgpackIO) mustEncode(v interface{}) { - halt.onerror(e.err) - if e.hh == nil { - halt.onerror(errNoFormatHandle) - } - - e.calls++ - if !e.encodeBuiltin(v) { - e.encodeR(reflect.ValueOf(v)) - } - - e.calls-- - if e.calls == 0 { - e.e.atEndOfEncode() - e.e.writerEnd() - } -} - -func (e *encoderMsgpackIO) encodeI(iv interface{}) { - if !e.encodeBuiltin(iv) { - e.encodeR(reflect.ValueOf(iv)) - } -} - -func (e *encoderMsgpackIO) encodeIB(iv interface{}) { - if !e.encodeBuiltin(iv) { - - halt.errorStr("[should not happen] invalid type passed to encodeBuiltin") - } -} - -func (e *encoderMsgpackIO) encodeR(base reflect.Value) { - e.encodeValue(base, nil) -} - -func (e *encoderMsgpackIO) encodeBuiltin(iv interface{}) (ok bool) { - ok = true - switch v := iv.(type) { - case nil: - e.e.EncodeNil() - - case Raw: - e.rawBytes(v) - case string: - e.e.EncodeString(v) - case bool: - e.e.EncodeBool(v) - case int: - e.e.EncodeInt(int64(v)) - case int8: - e.e.EncodeInt(int64(v)) - case int16: - e.e.EncodeInt(int64(v)) - case int32: - e.e.EncodeInt(int64(v)) - case int64: - e.e.EncodeInt(v) - case uint: - e.e.EncodeUint(uint64(v)) - case uint8: - e.e.EncodeUint(uint64(v)) - case uint16: - e.e.EncodeUint(uint64(v)) - case uint32: - e.e.EncodeUint(uint64(v)) - case uint64: - e.e.EncodeUint(v) - case uintptr: - e.e.EncodeUint(uint64(v)) - case float32: - e.e.EncodeFloat32(v) - case float64: - e.e.EncodeFloat64(v) - case complex64: - e.encodeComplex64(v) - case complex128: - e.encodeComplex128(v) - case time.Time: - e.e.EncodeTime(v) - case []byte: - e.e.EncodeBytes(v) - default: - - ok = !skipFastpathTypeSwitchInDirectCall && e.dh.fastpathEncodeTypeSwitch(iv, e) - } - return -} - -func (e *encoderMsgpackIO) encodeValue(rv reflect.Value, fn *encFnMsgpackIO) { - - var ciPushes int - - var rvp reflect.Value - var rvpValid bool - -RV: - switch rv.Kind() { - case reflect.Ptr: - if rvIsNil(rv) { - e.e.EncodeNil() - goto END - } - rvpValid = true - rvp = rv - rv = rv.Elem() - - if e.h.CheckCircularRef && e.ci.canPushElemKind(rv.Kind()) { - e.ci.push(rv2i(rvp)) - ciPushes++ - } - goto RV - case reflect.Interface: - if rvIsNil(rv) { - e.e.EncodeNil() - goto END - } - rvpValid = false - rvp = reflect.Value{} - rv = rv.Elem() - fn = nil - goto RV - case reflect.Map: - if rvIsNil(rv) { - if e.h.NilCollectionToZeroLength { - e.e.WriteMapEmpty() - } else { - e.e.EncodeNil() - } - goto END - } - case reflect.Slice, reflect.Chan: - if rvIsNil(rv) { - if e.h.NilCollectionToZeroLength { - e.e.WriteArrayEmpty() - } else { - e.e.EncodeNil() - } - goto END - } - case reflect.Invalid, reflect.Func: - e.e.EncodeNil() - goto END - } - - if fn == nil { - fn = e.fn(rv.Type()) - } - - if !fn.i.addrE { - - } else if rvpValid { - rv = rvp - } else if rv.CanAddr() { - rv = rvAddr(rv, fn.i.ti.ptr) - } else { - rv = e.addrRV(rv, fn.i.ti.rt, fn.i.ti.ptr) - } - fn.fe(e, &fn.i, rv) - -END: - if ciPushes > 0 { - e.ci.pop(ciPushes) - } -} - -func (e *encoderMsgpackIO) encodeValueNonNil(rv reflect.Value, fn *encFnMsgpackIO) { - - if fn.i.addrE { - if rv.CanAddr() { - rv = rvAddr(rv, fn.i.ti.ptr) - } else { - rv = e.addrRV(rv, fn.i.ti.rt, fn.i.ti.ptr) - } - } - fn.fe(e, &fn.i, rv) -} - -func (e *encoderMsgpackIO) encodeAs(v interface{}, t reflect.Type, ext bool) { - if ext { - e.encodeValue(baseRV(v), e.fn(t)) - } else { - e.encodeValue(baseRV(v), e.fnNoExt(t)) - } -} - -func (e *encoderMsgpackIO) marshalUtf8(bs []byte, fnerr error) { - halt.onerror(fnerr) - if bs == nil { - e.e.EncodeNil() - } else { - e.e.EncodeString(stringView(bs)) - } -} - -func (e *encoderMsgpackIO) marshalAsis(bs []byte, fnerr error) { - halt.onerror(fnerr) - if bs == nil { - e.e.EncodeNil() - } else { - e.e.writeBytesAsis(bs) - } -} - -func (e *encoderMsgpackIO) marshalRaw(bs []byte, fnerr error) { - halt.onerror(fnerr) - e.e.EncodeBytes(bs) -} - -func (e *encoderMsgpackIO) rawBytes(vv Raw) { - v := []byte(vv) - if !e.h.Raw { - halt.errorBytes("Raw values cannot be encoded: ", v) - } - e.e.writeBytesAsis(v) -} - -func (e *encoderMsgpackIO) fn(t reflect.Type) *encFnMsgpackIO { - return e.dh.encFnViaBH(t, e.rtidFn, e.h, e.fp, false) -} - -func (e *encoderMsgpackIO) fnNoExt(t reflect.Type) *encFnMsgpackIO { - return e.dh.encFnViaBH(t, e.rtidFnNoExt, e.h, e.fp, true) -} - -func (e *encoderMsgpackIO) mapStart(length int) { - e.e.WriteMapStart(length) - e.c = containerMapStart -} - -func (e *encoderMsgpackIO) mapElemValue() { - e.e.WriteMapElemValue() - e.c = containerMapValue -} - -func (e *encoderMsgpackIO) arrayStart(length int) { - e.e.WriteArrayStart(length) - e.c = containerArrayStart -} - -func (e *encoderMsgpackIO) writerEnd() { - e.e.writerEnd() -} - -func (e *encoderMsgpackIO) atEndOfEncode() { - e.e.atEndOfEncode() -} - -func (e *encoderMsgpackIO) Reset(w io.Writer) { - if e.bytes { - halt.onerror(errEncNoResetBytesWithWriter) - } - e.reset() - if w == nil { - w = io.Discard - } - e.e.resetOutIO(w) -} - -func (e *encoderMsgpackIO) ResetBytes(out *[]byte) { - if !e.bytes { - halt.onerror(errEncNoResetWriterWithBytes) - } - e.resetBytes(out) -} - -func (e *encoderMsgpackIO) resetBytes(out *[]byte) { - e.reset() - if out == nil { - out = &bytesEncAppenderDefOut - } - e.e.resetOutBytes(out) -} - -func (helperEncDriverMsgpackIO) newEncoderBytes(out *[]byte, h Handle) *encoderMsgpackIO { - var c1 encoderMsgpackIO - c1.bytes = true - c1.init(h) - c1.ResetBytes(out) - return &c1 -} - -func (helperEncDriverMsgpackIO) newEncoderIO(out io.Writer, h Handle) *encoderMsgpackIO { - var c1 encoderMsgpackIO - c1.bytes = false - c1.init(h) - c1.Reset(out) - return &c1 -} - -func (helperEncDriverMsgpackIO) encFnloadFastpathUnderlying(ti *typeInfo, fp *fastpathEsMsgpackIO) (f *fastpathEMsgpackIO, u reflect.Type) { - rtid := rt2id(ti.fastpathUnderlying) - idx, ok := fastpathAvIndex(rtid) - if !ok { - return - } - f = &fp[idx] - if uint8(reflect.Array) == ti.kind { - u = reflect.ArrayOf(ti.rt.Len(), ti.elem) - } else { - u = f.rt - } - return -} - -func (helperEncDriverMsgpackIO) encFindRtidFn(s []encRtidFnMsgpackIO, rtid uintptr) (i uint, fn *encFnMsgpackIO) { - - var h uint - var j = uint(len(s)) -LOOP: - if i < j { - h = (i + j) >> 1 - if s[h].rtid < rtid { - i = h + 1 - } else { - j = h - } - goto LOOP - } - if i < uint(len(s)) && s[i].rtid == rtid { - fn = s[i].fn - } - return -} - -func (helperEncDriverMsgpackIO) encFromRtidFnSlice(fns *atomicRtidFnSlice) (s []encRtidFnMsgpackIO) { - if v := fns.load(); v != nil { - s = *(lowLevelToPtr[[]encRtidFnMsgpackIO](v)) - } - return -} - -func (dh helperEncDriverMsgpackIO) encFnViaBH(rt reflect.Type, fns *atomicRtidFnSlice, - x *BasicHandle, fp *fastpathEsMsgpackIO, checkExt bool) (fn *encFnMsgpackIO) { - return dh.encFnVia(rt, fns, x.typeInfos(), &x.mu, x.extHandle, fp, - checkExt, x.CheckCircularRef, x.timeBuiltin, x.binaryHandle, x.jsonHandle) -} - -func (dh helperEncDriverMsgpackIO) encFnVia(rt reflect.Type, fns *atomicRtidFnSlice, - tinfos *TypeInfos, mu *sync.Mutex, exth extHandle, fp *fastpathEsMsgpackIO, - checkExt, checkCircularRef, timeBuiltin, binaryEncoding, json bool) (fn *encFnMsgpackIO) { - rtid := rt2id(rt) - var sp []encRtidFnMsgpackIO = dh.encFromRtidFnSlice(fns) - if sp != nil { - _, fn = dh.encFindRtidFn(sp, rtid) - } - if fn == nil { - fn = dh.encFnViaLoader(rt, rtid, fns, tinfos, mu, exth, fp, checkExt, checkCircularRef, timeBuiltin, binaryEncoding, json) - } - return -} - -func (dh helperEncDriverMsgpackIO) encFnViaLoader(rt reflect.Type, rtid uintptr, fns *atomicRtidFnSlice, - tinfos *TypeInfos, mu *sync.Mutex, exth extHandle, fp *fastpathEsMsgpackIO, - checkExt, checkCircularRef, timeBuiltin, binaryEncoding, json bool) (fn *encFnMsgpackIO) { - - fn = dh.encFnLoad(rt, rtid, tinfos, exth, fp, checkExt, checkCircularRef, timeBuiltin, binaryEncoding, json) - var sp []encRtidFnMsgpackIO - mu.Lock() - sp = dh.encFromRtidFnSlice(fns) - - if sp == nil { - sp = []encRtidFnMsgpackIO{{rtid, fn}} - fns.store(ptrToLowLevel(&sp)) - } else { - idx, fn2 := dh.encFindRtidFn(sp, rtid) - if fn2 == nil { - sp2 := make([]encRtidFnMsgpackIO, len(sp)+1) - copy(sp2[idx+1:], sp[idx:]) - copy(sp2, sp[:idx]) - sp2[idx] = encRtidFnMsgpackIO{rtid, fn} - fns.store(ptrToLowLevel(&sp2)) - } - } - mu.Unlock() - return -} - -func (dh helperEncDriverMsgpackIO) encFnLoad(rt reflect.Type, rtid uintptr, tinfos *TypeInfos, - exth extHandle, fp *fastpathEsMsgpackIO, - checkExt, checkCircularRef, timeBuiltin, binaryEncoding, json bool) (fn *encFnMsgpackIO) { - fn = new(encFnMsgpackIO) - fi := &(fn.i) - ti := tinfos.get(rtid, rt) - fi.ti = ti - rk := reflect.Kind(ti.kind) - - if rtid == timeTypId && timeBuiltin { - fn.fe = (*encoderMsgpackIO).kTime - } else if rtid == rawTypId { - fn.fe = (*encoderMsgpackIO).raw - } else if rtid == rawExtTypId { - fn.fe = (*encoderMsgpackIO).rawExt - fi.addrE = true - } else if xfFn := exth.getExt(rtid, checkExt); xfFn != nil { - fi.xfTag, fi.xfFn = xfFn.tag, xfFn.ext - fn.fe = (*encoderMsgpackIO).ext - if rk == reflect.Struct || rk == reflect.Array { - fi.addrE = true - } - } else if ti.flagSelfer || ti.flagSelferPtr { - fn.fe = (*encoderMsgpackIO).selferMarshal - fi.addrE = ti.flagSelferPtr - } else if supportMarshalInterfaces && binaryEncoding && - (ti.flagBinaryMarshaler || ti.flagBinaryMarshalerPtr) && - (ti.flagBinaryUnmarshaler || ti.flagBinaryUnmarshalerPtr) { - fn.fe = (*encoderMsgpackIO).binaryMarshal - fi.addrE = ti.flagBinaryMarshalerPtr - } else if supportMarshalInterfaces && !binaryEncoding && json && - (ti.flagJsonMarshaler || ti.flagJsonMarshalerPtr) && - (ti.flagJsonUnmarshaler || ti.flagJsonUnmarshalerPtr) { - - fn.fe = (*encoderMsgpackIO).jsonMarshal - fi.addrE = ti.flagJsonMarshalerPtr - } else if supportMarshalInterfaces && !binaryEncoding && - (ti.flagTextMarshaler || ti.flagTextMarshalerPtr) && - (ti.flagTextUnmarshaler || ti.flagTextUnmarshalerPtr) { - fn.fe = (*encoderMsgpackIO).textMarshal - fi.addrE = ti.flagTextMarshalerPtr - } else { - if fastpathEnabled && (rk == reflect.Map || rk == reflect.Slice || rk == reflect.Array) { - - var rtid2 uintptr - if !ti.flagHasPkgPath { - rtid2 = rtid - if rk == reflect.Array { - rtid2 = rt2id(ti.key) - } - if idx, ok := fastpathAvIndex(rtid2); ok { - fn.fe = fp[idx].encfn - } - } else { - - xfe, xrt := dh.encFnloadFastpathUnderlying(ti, fp) - if xfe != nil { - xfnf := xfe.encfn - fn.fe = func(e *encoderMsgpackIO, xf *encFnInfo, xrv reflect.Value) { - xfnf(e, xf, rvConvert(xrv, xrt)) - } - } - } - } - if fn.fe == nil { - switch rk { - case reflect.Bool: - fn.fe = (*encoderMsgpackIO).kBool - case reflect.String: - - fn.fe = (*encoderMsgpackIO).kString - case reflect.Int: - fn.fe = (*encoderMsgpackIO).kInt - case reflect.Int8: - fn.fe = (*encoderMsgpackIO).kInt8 - case reflect.Int16: - fn.fe = (*encoderMsgpackIO).kInt16 - case reflect.Int32: - fn.fe = (*encoderMsgpackIO).kInt32 - case reflect.Int64: - fn.fe = (*encoderMsgpackIO).kInt64 - case reflect.Uint: - fn.fe = (*encoderMsgpackIO).kUint - case reflect.Uint8: - fn.fe = (*encoderMsgpackIO).kUint8 - case reflect.Uint16: - fn.fe = (*encoderMsgpackIO).kUint16 - case reflect.Uint32: - fn.fe = (*encoderMsgpackIO).kUint32 - case reflect.Uint64: - fn.fe = (*encoderMsgpackIO).kUint64 - case reflect.Uintptr: - fn.fe = (*encoderMsgpackIO).kUintptr - case reflect.Float32: - fn.fe = (*encoderMsgpackIO).kFloat32 - case reflect.Float64: - fn.fe = (*encoderMsgpackIO).kFloat64 - case reflect.Complex64: - fn.fe = (*encoderMsgpackIO).kComplex64 - case reflect.Complex128: - fn.fe = (*encoderMsgpackIO).kComplex128 - case reflect.Chan: - fn.fe = (*encoderMsgpackIO).kChan - case reflect.Slice: - fn.fe = (*encoderMsgpackIO).kSlice - case reflect.Array: - fn.fe = (*encoderMsgpackIO).kArray - case reflect.Struct: - if ti.simple { - fn.fe = (*encoderMsgpackIO).kStructSimple - } else { - fn.fe = (*encoderMsgpackIO).kStruct - } - case reflect.Map: - fn.fe = (*encoderMsgpackIO).kMap - case reflect.Interface: - - fn.fe = (*encoderMsgpackIO).kErr - default: - - fn.fe = (*encoderMsgpackIO).kErr - } - } - } - return -} -func (d *decoderMsgpackIO) rawExt(f *decFnInfo, rv reflect.Value) { - d.d.DecodeRawExt(rv2i(rv).(*RawExt)) -} - -func (d *decoderMsgpackIO) ext(f *decFnInfo, rv reflect.Value) { - d.d.DecodeExt(rv2i(rv), f.ti.rt, f.xfTag, f.xfFn) -} - -func (d *decoderMsgpackIO) selferUnmarshal(_ *decFnInfo, rv reflect.Value) { - rv2i(rv).(Selfer).CodecDecodeSelf(&Decoder{d}) -} - -func (d *decoderMsgpackIO) binaryUnmarshal(_ *decFnInfo, rv reflect.Value) { - bm := rv2i(rv).(encoding.BinaryUnmarshaler) - xbs, _ := d.d.DecodeBytes() - fnerr := bm.UnmarshalBinary(xbs) - halt.onerror(fnerr) -} - -func (d *decoderMsgpackIO) textUnmarshal(_ *decFnInfo, rv reflect.Value) { - tm := rv2i(rv).(encoding.TextUnmarshaler) - fnerr := tm.UnmarshalText(bytesOKs(d.d.DecodeStringAsBytes())) - halt.onerror(fnerr) -} - -func (d *decoderMsgpackIO) jsonUnmarshal(_ *decFnInfo, rv reflect.Value) { - d.jsonUnmarshalV(rv2i(rv).(jsonUnmarshaler)) -} - -func (d *decoderMsgpackIO) jsonUnmarshalV(tm jsonUnmarshaler) { - - halt.onerror(tm.UnmarshalJSON(d.d.nextValueBytes())) -} - -func (d *decoderMsgpackIO) kErr(_ *decFnInfo, rv reflect.Value) { - halt.errorf("unsupported decoding kind: %s, for %#v", rv.Kind(), rv) - -} - -func (d *decoderMsgpackIO) raw(_ *decFnInfo, rv reflect.Value) { - rvSetBytes(rv, d.rawBytes()) -} - -func (d *decoderMsgpackIO) kString(_ *decFnInfo, rv reflect.Value) { - rvSetString(rv, d.detach2Str(d.d.DecodeStringAsBytes())) -} - -func (d *decoderMsgpackIO) kBool(_ *decFnInfo, rv reflect.Value) { - rvSetBool(rv, d.d.DecodeBool()) -} - -func (d *decoderMsgpackIO) kTime(_ *decFnInfo, rv reflect.Value) { - rvSetTime(rv, d.d.DecodeTime()) -} - -func (d *decoderMsgpackIO) kFloat32(_ *decFnInfo, rv reflect.Value) { - rvSetFloat32(rv, d.d.DecodeFloat32()) -} - -func (d *decoderMsgpackIO) kFloat64(_ *decFnInfo, rv reflect.Value) { - rvSetFloat64(rv, d.d.DecodeFloat64()) -} - -func (d *decoderMsgpackIO) kComplex64(_ *decFnInfo, rv reflect.Value) { - rvSetComplex64(rv, complex(d.d.DecodeFloat32(), 0)) -} - -func (d *decoderMsgpackIO) kComplex128(_ *decFnInfo, rv reflect.Value) { - rvSetComplex128(rv, complex(d.d.DecodeFloat64(), 0)) -} - -func (d *decoderMsgpackIO) kInt(_ *decFnInfo, rv reflect.Value) { - rvSetInt(rv, int(chkOvf.IntV(d.d.DecodeInt64(), intBitsize))) -} - -func (d *decoderMsgpackIO) kInt8(_ *decFnInfo, rv reflect.Value) { - rvSetInt8(rv, int8(chkOvf.IntV(d.d.DecodeInt64(), 8))) -} - -func (d *decoderMsgpackIO) kInt16(_ *decFnInfo, rv reflect.Value) { - rvSetInt16(rv, int16(chkOvf.IntV(d.d.DecodeInt64(), 16))) -} - -func (d *decoderMsgpackIO) kInt32(_ *decFnInfo, rv reflect.Value) { - rvSetInt32(rv, int32(chkOvf.IntV(d.d.DecodeInt64(), 32))) -} - -func (d *decoderMsgpackIO) kInt64(_ *decFnInfo, rv reflect.Value) { - rvSetInt64(rv, d.d.DecodeInt64()) -} - -func (d *decoderMsgpackIO) kUint(_ *decFnInfo, rv reflect.Value) { - rvSetUint(rv, uint(chkOvf.UintV(d.d.DecodeUint64(), uintBitsize))) -} - -func (d *decoderMsgpackIO) kUintptr(_ *decFnInfo, rv reflect.Value) { - rvSetUintptr(rv, uintptr(chkOvf.UintV(d.d.DecodeUint64(), uintBitsize))) -} - -func (d *decoderMsgpackIO) kUint8(_ *decFnInfo, rv reflect.Value) { - rvSetUint8(rv, uint8(chkOvf.UintV(d.d.DecodeUint64(), 8))) -} - -func (d *decoderMsgpackIO) kUint16(_ *decFnInfo, rv reflect.Value) { - rvSetUint16(rv, uint16(chkOvf.UintV(d.d.DecodeUint64(), 16))) -} - -func (d *decoderMsgpackIO) kUint32(_ *decFnInfo, rv reflect.Value) { - rvSetUint32(rv, uint32(chkOvf.UintV(d.d.DecodeUint64(), 32))) -} - -func (d *decoderMsgpackIO) kUint64(_ *decFnInfo, rv reflect.Value) { - rvSetUint64(rv, d.d.DecodeUint64()) -} - -func (d *decoderMsgpackIO) kInterfaceNaked(f *decFnInfo) (rvn reflect.Value) { - - n := d.naked() - d.d.DecodeNaked() - - if decFailNonEmptyIntf && f.ti.numMeth > 0 { - halt.errorf("cannot decode non-nil codec value into nil %v (%v methods)", f.ti.rt, f.ti.numMeth) - } - - switch n.v { - case valueTypeMap: - mtid := d.mtid - if mtid == 0 { - if d.jsms { - mtid = mapStrIntfTypId - } else { - mtid = mapIntfIntfTypId - } - } - if mtid == mapStrIntfTypId { - var v2 map[string]interface{} - d.decode(&v2) - rvn = rv4iptr(&v2).Elem() - } else if mtid == mapIntfIntfTypId { - var v2 map[interface{}]interface{} - d.decode(&v2) - rvn = rv4iptr(&v2).Elem() - } else if d.mtr { - rvn = reflect.New(d.h.MapType) - d.decode(rv2i(rvn)) - rvn = rvn.Elem() - } else { - - rvn = rvZeroAddrK(d.h.MapType, reflect.Map) - d.decodeValue(rvn, nil) - } - case valueTypeArray: - if d.stid == 0 || d.stid == intfSliceTypId { - var v2 []interface{} - d.decode(&v2) - rvn = rv4iptr(&v2).Elem() - } else if d.str { - rvn = reflect.New(d.h.SliceType) - d.decode(rv2i(rvn)) - rvn = rvn.Elem() - } else { - rvn = rvZeroAddrK(d.h.SliceType, reflect.Slice) - d.decodeValue(rvn, nil) - } - if d.h.PreferArrayOverSlice { - rvn = rvGetArray4Slice(rvn) - } - case valueTypeExt: - tag, bytes := n.u, n.l - bfn := d.h.getExtForTag(tag) - var re = RawExt{Tag: tag} - if bytes == nil { - - if bfn == nil { - d.decode(&re.Value) - rvn = rv4iptr(&re).Elem() - } else if bfn.ext == SelfExt { - rvn = rvZeroAddrK(bfn.rt, bfn.rt.Kind()) - d.decodeValue(rvn, d.fnNoExt(bfn.rt)) - } else { - rvn = reflect.New(bfn.rt) - d.interfaceExtConvertAndDecode(rv2i(rvn), bfn.ext) - rvn = rvn.Elem() - } - } else { - - if bfn == nil { - re.setData(bytes, false) - rvn = rv4iptr(&re).Elem() - } else { - rvn = reflect.New(bfn.rt) - if bfn.ext == SelfExt { - sideDecode(d.hh, &d.h.sideDecPool, func(sd decoderI) { oneOffDecode(sd, rv2i(rvn), bytes, bfn.rt, true) }) - } else { - bfn.ext.ReadExt(rv2i(rvn), bytes) - } - rvn = rvn.Elem() - } - } - - if d.h.PreferPointerForStructOrArray && rvn.CanAddr() { - if rk := rvn.Kind(); rk == reflect.Array || rk == reflect.Struct { - rvn = rvn.Addr() - } - } - case valueTypeNil: - - case valueTypeInt: - rvn = n.ri() - case valueTypeUint: - rvn = n.ru() - case valueTypeFloat: - rvn = n.rf() - case valueTypeBool: - rvn = n.rb() - case valueTypeString, valueTypeSymbol: - rvn = n.rs() - case valueTypeBytes: - rvn = n.rl() - case valueTypeTime: - rvn = n.rt() - default: - halt.errorStr2("kInterfaceNaked: unexpected valueType: ", n.v.String()) - } - return -} - -func (d *decoderMsgpackIO) kInterface(f *decFnInfo, rv reflect.Value) { - - isnilrv := rvIsNil(rv) - - var rvn reflect.Value - - if d.h.InterfaceReset { - - rvn = d.h.intf2impl(f.ti.rtid) - if !rvn.IsValid() { - rvn = d.kInterfaceNaked(f) - if rvn.IsValid() { - rvSetIntf(rv, rvn) - } else if !isnilrv { - decSetNonNilRV2Zero4Intf(rv) - } - return - } - } else if isnilrv { - - rvn = d.h.intf2impl(f.ti.rtid) - if !rvn.IsValid() { - rvn = d.kInterfaceNaked(f) - if rvn.IsValid() { - rvSetIntf(rv, rvn) - } - return - } - } else { - - rvn = rv.Elem() - } - - canDecode, _ := isDecodeable(rvn) - - if !canDecode { - rvn2 := d.oneShotAddrRV(rvn.Type(), rvn.Kind()) - rvSetDirect(rvn2, rvn) - rvn = rvn2 - } - - d.decodeValue(rvn, nil) - rvSetIntf(rv, rvn) -} - -func (d *decoderMsgpackIO) kStructField(si *structFieldInfo, rv reflect.Value) { - if d.d.TryNil() { - rv = si.fieldNoAlloc(rv, true) - if rv.IsValid() { - decSetNonNilRV2Zero(rv) - } - } else if si.decBuiltin { - rv = rvAddr(si.fieldAlloc(rv), si.ptrTyp) - d.decode(rv2i(rv)) - } else { - fn := d.fn(si.baseTyp) - rv = si.fieldAlloc(rv) - if fn.i.addrD { - rv = rvAddr(rv, si.ptrTyp) - } - fn.fd(d, &fn.i, rv) - } -} - -func (d *decoderMsgpackIO) kStructSimple(f *decFnInfo, rv reflect.Value) { - _ = d.d - ctyp := d.d.ContainerType() - ti := f.ti - if ctyp == valueTypeMap { - containerLen := d.mapStart(d.d.ReadMapStart()) - if containerLen == 0 { - d.mapEnd() - return - } - hasLen := containerLen >= 0 - var rvkencname []byte - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - sab, att := d.d.DecodeStringAsBytes() - rvkencname = d.usableStructFieldNameBytes(rvkencname, sab, att) - d.mapElemValue() - if si := ti.siForEncName(rvkencname); si != nil { - d.kStructField(si, rv) - } else { - d.structFieldNotFound(-1, stringView(rvkencname)) - } - } - d.mapEnd() - } else if ctyp == valueTypeArray { - containerLen := d.arrayStart(d.d.ReadArrayStart()) - if containerLen == 0 { - d.arrayEnd() - return - } - - tisfi := ti.sfi.source() - hasLen := containerLen >= 0 - - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.arrayElem(j == 0) - if j < len(tisfi) { - d.kStructField(tisfi[j], rv) - } else { - d.structFieldNotFound(j, "") - } - } - d.arrayEnd() - } else { - halt.onerror(errNeedMapOrArrayDecodeToStruct) - } -} - -func (d *decoderMsgpackIO) kStruct(f *decFnInfo, rv reflect.Value) { - _ = d.d - ctyp := d.d.ContainerType() - ti := f.ti - var mf MissingFielder - if ti.flagMissingFielder { - mf = rv2i(rv).(MissingFielder) - } else if ti.flagMissingFielderPtr { - mf = rv2i(rvAddr(rv, ti.ptr)).(MissingFielder) - } - if ctyp == valueTypeMap { - containerLen := d.mapStart(d.d.ReadMapStart()) - if containerLen == 0 { - d.mapEnd() - return - } - hasLen := containerLen >= 0 - var name2 []byte - var rvkencname []byte - tkt := ti.keyType - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - - if tkt == valueTypeString { - sab, att := d.d.DecodeStringAsBytes() - rvkencname = d.usableStructFieldNameBytes(rvkencname, sab, att) - } else if tkt == valueTypeInt { - rvkencname = strconv.AppendInt(d.b[:0], d.d.DecodeInt64(), 10) - } else if tkt == valueTypeUint { - rvkencname = strconv.AppendUint(d.b[:0], d.d.DecodeUint64(), 10) - } else if tkt == valueTypeFloat { - rvkencname = strconv.AppendFloat(d.b[:0], d.d.DecodeFloat64(), 'f', -1, 64) - } else { - halt.errorStr2("invalid struct key type: ", ti.keyType.String()) - } - - d.mapElemValue() - if si := ti.siForEncName(rvkencname); si != nil { - d.kStructField(si, rv) - } else if mf != nil { - - name2 = append(name2[:0], rvkencname...) - var f interface{} - d.decode(&f) - if !mf.CodecMissingField(name2, f) && d.h.ErrorIfNoField { - halt.errorStr2("no matching struct field when decoding stream map with key: ", stringView(name2)) - } - } else { - d.structFieldNotFound(-1, stringView(rvkencname)) - } - } - d.mapEnd() - } else if ctyp == valueTypeArray { - containerLen := d.arrayStart(d.d.ReadArrayStart()) - if containerLen == 0 { - d.arrayEnd() - return - } - - tisfi := ti.sfi.source() - hasLen := containerLen >= 0 - - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.arrayElem(j == 0) - if j < len(tisfi) { - d.kStructField(tisfi[j], rv) - } else { - d.structFieldNotFound(j, "") - } - } - - d.arrayEnd() - } else { - halt.onerror(errNeedMapOrArrayDecodeToStruct) - } -} - -func (d *decoderMsgpackIO) kSlice(f *decFnInfo, rv reflect.Value) { - _ = d.d - - ti := f.ti - rvCanset := rv.CanSet() - - ctyp := d.d.ContainerType() - if ctyp == valueTypeBytes || ctyp == valueTypeString { - - if !(ti.rtid == uint8SliceTypId || ti.elemkind == uint8(reflect.Uint8)) { - halt.errorf("bytes/string in stream must decode into slice/array of bytes, not %v", ti.rt) - } - rvbs := rvGetBytes(rv) - if rvCanset { - bs2, bst := d.decodeBytesInto(rvbs, false) - if bst != dBytesIntoParamOut { - rvSetBytes(rv, bs2) - } - } else { - - d.decodeBytesInto(rvbs[:len(rvbs):len(rvbs)], true) - } - return - } - - var containerLenS int - isArray := ctyp == valueTypeArray - if isArray { - containerLenS = d.arrayStart(d.d.ReadArrayStart()) - } else if ctyp == valueTypeMap { - containerLenS = d.mapStart(d.d.ReadMapStart()) * 2 - } else { - halt.errorStr2("decoding into a slice, expect map/array - got ", ctyp.String()) - } - - if containerLenS == 0 { - if rvCanset { - if rvIsNil(rv) { - rvSetDirect(rv, rvSliceZeroCap(ti.rt)) - } else { - rvSetSliceLen(rv, 0) - } - } - if isArray { - d.arrayEnd() - } else { - d.mapEnd() - } - return - } - - rtelem0Mut := !scalarBitset.isset(ti.elemkind) - rtelem := ti.elem - - for k := reflect.Kind(ti.elemkind); k == reflect.Ptr; k = rtelem.Kind() { - rtelem = rtelem.Elem() - } - - var fn *decFnMsgpackIO - - var rvChanged bool - - var rv0 = rv - var rv9 reflect.Value - - rvlen := rvLenSlice(rv) - rvcap := rvCapSlice(rv) - maxInitLen := d.maxInitLen() - hasLen := containerLenS >= 0 - if hasLen { - if containerLenS > rvcap { - oldRvlenGtZero := rvlen > 0 - rvlen1 := int(decInferLen(containerLenS, maxInitLen, uint(ti.elemsize))) - if rvlen1 == rvlen { - } else if rvlen1 <= rvcap { - if rvCanset { - rvlen = rvlen1 - rvSetSliceLen(rv, rvlen) - } - } else if rvCanset { - rvlen = rvlen1 - rv, rvCanset = rvMakeSlice(rv, f.ti, rvlen, rvlen) - rvcap = rvlen - rvChanged = !rvCanset - } else { - halt.errorStr("cannot decode into non-settable slice") - } - if rvChanged && oldRvlenGtZero && rtelem0Mut { - rvCopySlice(rv, rv0, rtelem) - } - } else if containerLenS != rvlen { - if rvCanset { - rvlen = containerLenS - rvSetSliceLen(rv, rvlen) - } - } - } - - var elemReset = d.h.SliceElementReset - - var rtelemIsPtr bool - var rtelemElem reflect.Type - builtin := ti.tielem.flagDecBuiltin - if builtin { - rtelemIsPtr = ti.elemkind == uint8(reflect.Ptr) - if rtelemIsPtr { - rtelemElem = ti.elem.Elem() - } - } - - var j int - for ; d.containerNext(j, containerLenS, hasLen); j++ { - if j == 0 { - if rvIsNil(rv) { - if rvCanset { - rvlen = int(decInferLen(containerLenS, maxInitLen, uint(ti.elemsize))) - rv, rvCanset = rvMakeSlice(rv, f.ti, rvlen, rvlen) - rvcap = rvlen - rvChanged = !rvCanset - } else { - halt.errorStr("cannot decode into non-settable slice") - } - } - if fn == nil { - fn = d.fn(rtelem) - } - } - - if ctyp == valueTypeArray { - d.arrayElem(j == 0) - } else if j&1 == 0 { - d.mapElemKey(j == 0) - } else { - d.mapElemValue() - } - - if j >= rvlen { - - if rvlen < rvcap { - rvlen = rvcap - if rvCanset { - rvSetSliceLen(rv, rvlen) - } else if rvChanged { - rv = rvSlice(rv, rvlen) - } else { - halt.onerror(errExpandSliceCannotChange) - } - } else { - if !(rvCanset || rvChanged) { - halt.onerror(errExpandSliceCannotChange) - } - rv, rvcap, rvCanset = rvGrowSlice(rv, f.ti, rvcap, 1) - - rvlen = rvcap - rvChanged = !rvCanset - } - } - - rv9 = rvArrayIndex(rv, j, f.ti, true) - if elemReset { - rvSetZero(rv9) - } - if d.d.TryNil() { - rvSetZero(rv9) - } else if builtin { - if rtelemIsPtr { - if rvIsNil(rv9) { - rvSetDirect(rv9, reflect.New(rtelemElem)) - } - d.decode(rv2i(rv9)) - } else { - d.decode(rv2i(rvAddr(rv9, ti.tielem.ptr))) - } - } else { - d.decodeValueNoCheckNil(rv9, fn) - } - } - if j < rvlen { - if rvCanset { - rvSetSliceLen(rv, j) - } else if rvChanged { - rv = rvSlice(rv, j) - } - - } else if j == 0 && rvIsNil(rv) { - if rvCanset { - rv = rvSliceZeroCap(ti.rt) - rvCanset = false - rvChanged = true - } - } - if isArray { - d.arrayEnd() - } else { - d.mapEnd() - } - - if rvChanged { - rvSetDirect(rv0, rv) - } -} - -func (d *decoderMsgpackIO) kArray(f *decFnInfo, rv reflect.Value) { - _ = d.d - - ti := f.ti - ctyp := d.d.ContainerType() - if handleBytesWithinKArray && (ctyp == valueTypeBytes || ctyp == valueTypeString) { - - if ti.elemkind != uint8(reflect.Uint8) { - halt.errorf("bytes/string in stream can decode into array of bytes, but not %v", ti.rt) - } - rvbs := rvGetArrayBytes(rv, nil) - d.decodeBytesInto(rvbs, true) - return - } - - var containerLenS int - isArray := ctyp == valueTypeArray - if isArray { - containerLenS = d.arrayStart(d.d.ReadArrayStart()) - } else if ctyp == valueTypeMap { - containerLenS = d.mapStart(d.d.ReadMapStart()) * 2 - } else { - halt.errorStr2("decoding into a slice, expect map/array - got ", ctyp.String()) - } - - if containerLenS == 0 { - if isArray { - d.arrayEnd() - } else { - d.mapEnd() - } - return - } - - rtelem := ti.elem - for k := reflect.Kind(ti.elemkind); k == reflect.Ptr; k = rtelem.Kind() { - rtelem = rtelem.Elem() - } - - var rv9 reflect.Value - - rvlen := rv.Len() - hasLen := containerLenS >= 0 - if hasLen && containerLenS > rvlen { - halt.errorf("cannot decode into array with length: %v, less than container length: %v", any(rvlen), any(containerLenS)) - } - - var elemReset = d.h.SliceElementReset - - var rtelemIsPtr bool - var rtelemElem reflect.Type - var fn *decFnMsgpackIO - builtin := ti.tielem.flagDecBuiltin - if builtin { - rtelemIsPtr = ti.elemkind == uint8(reflect.Ptr) - if rtelemIsPtr { - rtelemElem = ti.elem.Elem() - } - } else { - fn = d.fn(rtelem) - } - - for j := 0; d.containerNext(j, containerLenS, hasLen); j++ { - if ctyp == valueTypeArray { - d.arrayElem(j == 0) - } else if j&1 == 0 { - d.mapElemKey(j == 0) - } else { - d.mapElemValue() - } - - if j >= rvlen { - d.arrayCannotExpand(rvlen, j+1) - d.swallow() - continue - } - - rv9 = rvArrayIndex(rv, j, f.ti, false) - if elemReset { - rvSetZero(rv9) - } - if d.d.TryNil() { - rvSetZero(rv9) - } else if builtin { - if rtelemIsPtr { - if rvIsNil(rv9) { - rvSetDirect(rv9, reflect.New(rtelemElem)) - } - d.decode(rv2i(rv9)) - } else { - d.decode(rv2i(rvAddr(rv9, ti.tielem.ptr))) - } - } else { - d.decodeValueNoCheckNil(rv9, fn) - } - } - if isArray { - d.arrayEnd() - } else { - d.mapEnd() - } -} - -func (d *decoderMsgpackIO) kChan(f *decFnInfo, rv reflect.Value) { - _ = d.d - - ti := f.ti - if ti.chandir&uint8(reflect.SendDir) == 0 { - halt.errorStr("receive-only channel cannot be decoded") - } - ctyp := d.d.ContainerType() - if ctyp == valueTypeBytes || ctyp == valueTypeString { - - if !(ti.rtid == uint8SliceTypId || ti.elemkind == uint8(reflect.Uint8)) { - halt.errorf("bytes/string in stream must decode into slice/array of bytes, not %v", ti.rt) - } - bs2, _ := d.d.DecodeBytes() - irv := rv2i(rv) - ch, ok := irv.(chan<- byte) - if !ok { - ch = irv.(chan byte) - } - for _, b := range bs2 { - ch <- b - } - return - } - - var rvCanset = rv.CanSet() - - var containerLenS int - isArray := ctyp == valueTypeArray - if isArray { - containerLenS = d.arrayStart(d.d.ReadArrayStart()) - } else if ctyp == valueTypeMap { - containerLenS = d.mapStart(d.d.ReadMapStart()) * 2 - } else { - halt.errorStr2("decoding into a slice, expect map/array - got ", ctyp.String()) - } - - if containerLenS == 0 { - if rvCanset && rvIsNil(rv) { - rvSetDirect(rv, reflect.MakeChan(ti.rt, 0)) - } - if isArray { - d.arrayEnd() - } else { - d.mapEnd() - } - return - } - - rtelem := ti.elem - useTransient := decUseTransient && ti.elemkind != byte(reflect.Ptr) && ti.tielem.flagCanTransient - - for k := reflect.Kind(ti.elemkind); k == reflect.Ptr; k = rtelem.Kind() { - rtelem = rtelem.Elem() - } - - var fn *decFnMsgpackIO - - var rvChanged bool - var rv0 = rv - var rv9 reflect.Value - - var rvlen int - hasLen := containerLenS >= 0 - maxInitLen := d.maxInitLen() - - for j := 0; d.containerNext(j, containerLenS, hasLen); j++ { - if j == 0 { - if rvIsNil(rv) { - if hasLen { - rvlen = int(decInferLen(containerLenS, maxInitLen, uint(ti.elemsize))) - } else { - rvlen = decDefChanCap - } - if rvCanset { - rv = reflect.MakeChan(ti.rt, rvlen) - rvChanged = true - } else { - halt.errorStr("cannot decode into non-settable chan") - } - } - if fn == nil { - fn = d.fn(rtelem) - } - } - - if ctyp == valueTypeArray { - d.arrayElem(j == 0) - } else if j&1 == 0 { - d.mapElemKey(j == 0) - } else { - d.mapElemValue() - } - - if rv9.IsValid() { - rvSetZero(rv9) - } else if useTransient { - rv9 = d.perType.TransientAddrK(ti.elem, reflect.Kind(ti.elemkind)) - } else { - rv9 = rvZeroAddrK(ti.elem, reflect.Kind(ti.elemkind)) - } - if !d.d.TryNil() { - d.decodeValueNoCheckNil(rv9, fn) - } - rv.Send(rv9) - } - if isArray { - d.arrayEnd() - } else { - d.mapEnd() - } - - if rvChanged { - rvSetDirect(rv0, rv) - } - -} - -func (d *decoderMsgpackIO) kMap(f *decFnInfo, rv reflect.Value) { - _ = d.d - containerLen := d.mapStart(d.d.ReadMapStart()) - ti := f.ti - if rvIsNil(rv) { - rvlen := int(decInferLen(containerLen, d.maxInitLen(), uint(ti.keysize+ti.elemsize))) - rvSetDirect(rv, makeMapReflect(ti.rt, rvlen)) - } - - if containerLen == 0 { - d.mapEnd() - return - } - - ktype, vtype := ti.key, ti.elem - ktypeId := rt2id(ktype) - vtypeKind := reflect.Kind(ti.elemkind) - ktypeKind := reflect.Kind(ti.keykind) - mparams := getMapReqParams(ti) - - vtypePtr := vtypeKind == reflect.Ptr - ktypePtr := ktypeKind == reflect.Ptr - - vTransient := decUseTransient && !vtypePtr && ti.tielem.flagCanTransient - - kTransient := vTransient && !ktypePtr && ti.tikey.flagCanTransient - - var vtypeElem reflect.Type - - var keyFn, valFn *decFnMsgpackIO - var ktypeLo, vtypeLo = ktype, vtype - - if ktypeKind == reflect.Ptr { - for ktypeLo = ktype.Elem(); ktypeLo.Kind() == reflect.Ptr; ktypeLo = ktypeLo.Elem() { - } - } - - if vtypePtr { - vtypeElem = vtype.Elem() - for vtypeLo = vtypeElem; vtypeLo.Kind() == reflect.Ptr; vtypeLo = vtypeLo.Elem() { - } - } - - rvkMut := !scalarBitset.isset(ti.keykind) - rvvMut := !scalarBitset.isset(ti.elemkind) - rvvCanNil := isnilBitset.isset(ti.elemkind) - - var rvk, rvkn, rvv, rvvn, rvva, rvvz reflect.Value - - var doMapGet, doMapSet bool - - if !d.h.MapValueReset { - if rvvMut && (vtypeKind != reflect.Interface || !d.h.InterfaceReset) { - doMapGet = true - rvva = mapAddrLoopvarRV(vtype, vtypeKind) - } - } - - ktypeIsString := ktypeId == stringTypId - ktypeIsIntf := ktypeId == intfTypId - hasLen := containerLen >= 0 - - var kstr2bs []byte - var kstr string - - var mapKeyStringSharesBytesBuf bool - var att dBytesAttachState - - var vElem, kElem reflect.Type - kbuiltin := ti.tikey.flagDecBuiltin && ti.keykind != uint8(reflect.Slice) - vbuiltin := ti.tielem.flagDecBuiltin - if kbuiltin && ktypePtr { - kElem = ti.key.Elem() - } - if vbuiltin && vtypePtr { - vElem = ti.elem.Elem() - } - - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - mapKeyStringSharesBytesBuf = false - kstr = "" - if j == 0 { - - if kTransient { - rvk = d.perType.TransientAddr2K(ktype, ktypeKind) - } else { - rvk = rvZeroAddrK(ktype, ktypeKind) - } - if !rvkMut { - rvkn = rvk - } - if !rvvMut { - if vTransient { - rvvn = d.perType.TransientAddrK(vtype, vtypeKind) - } else { - rvvn = rvZeroAddrK(vtype, vtypeKind) - } - } - if !ktypeIsString && keyFn == nil { - keyFn = d.fn(ktypeLo) - } - if valFn == nil { - valFn = d.fn(vtypeLo) - } - } else if rvkMut { - rvSetZero(rvk) - } else { - rvk = rvkn - } - - d.mapElemKey(j == 0) - - if d.d.TryNil() { - rvSetZero(rvk) - } else if ktypeIsString { - kstr2bs, att = d.d.DecodeStringAsBytes() - kstr, mapKeyStringSharesBytesBuf = d.bytes2Str(kstr2bs, att) - rvSetString(rvk, kstr) - } else { - if kbuiltin { - if ktypePtr { - if rvIsNil(rvk) { - rvSetDirect(rvk, reflect.New(kElem)) - } - d.decode(rv2i(rvk)) - } else { - d.decode(rv2i(rvAddr(rvk, ti.tikey.ptr))) - } - } else { - d.decodeValueNoCheckNil(rvk, keyFn) - } - - if ktypeIsIntf { - if rvk2 := rvk.Elem(); rvk2.IsValid() && rvk2.Type() == uint8SliceTyp { - kstr2bs = rvGetBytes(rvk2) - kstr, mapKeyStringSharesBytesBuf = d.bytes2Str(kstr2bs, dBytesAttachView) - rvSetIntf(rvk, rv4istr(kstr)) - } - - } - } - - if mapKeyStringSharesBytesBuf && d.bufio { - if ktypeIsString { - rvSetString(rvk, d.detach2Str(kstr2bs, att)) - } else { - rvSetIntf(rvk, rv4istr(d.detach2Str(kstr2bs, att))) - } - mapKeyStringSharesBytesBuf = false - } - - d.mapElemValue() - - if d.d.TryNil() { - if mapKeyStringSharesBytesBuf { - if ktypeIsString { - rvSetString(rvk, d.detach2Str(kstr2bs, att)) - } else { - rvSetIntf(rvk, rv4istr(d.detach2Str(kstr2bs, att))) - } - } - - if !rvvz.IsValid() { - rvvz = rvZeroK(vtype, vtypeKind) - } - mapSet(rv, rvk, rvvz, mparams) - continue - } - - doMapSet = true - - if !rvvMut { - rvv = rvvn - } else if !doMapGet { - goto NEW_RVV - } else { - rvv = mapGet(rv, rvk, rvva, mparams) - if !rvv.IsValid() || (rvvCanNil && rvIsNil(rvv)) { - goto NEW_RVV - } - switch vtypeKind { - case reflect.Ptr, reflect.Map: - doMapSet = false - case reflect.Interface: - - rvvn = rvv.Elem() - if k := rvvn.Kind(); (k == reflect.Ptr || k == reflect.Map) && !rvIsNil(rvvn) { - d.decodeValueNoCheckNil(rvvn, nil) - continue - } - - rvvn = rvZeroAddrK(vtype, vtypeKind) - rvSetIntf(rvvn, rvv) - rvv = rvvn - default: - - if vTransient { - rvvn = d.perType.TransientAddrK(vtype, vtypeKind) - } else { - rvvn = rvZeroAddrK(vtype, vtypeKind) - } - rvSetDirect(rvvn, rvv) - rvv = rvvn - } - } - goto DECODE_VALUE_NO_CHECK_NIL - - NEW_RVV: - if vtypePtr { - rvv = reflect.New(vtypeElem) - } else if vTransient { - rvv = d.perType.TransientAddrK(vtype, vtypeKind) - } else { - rvv = rvZeroAddrK(vtype, vtypeKind) - } - - DECODE_VALUE_NO_CHECK_NIL: - if doMapSet && mapKeyStringSharesBytesBuf { - if ktypeIsString { - rvSetString(rvk, d.detach2Str(kstr2bs, att)) - } else { - rvSetIntf(rvk, rv4istr(d.detach2Str(kstr2bs, att))) - } - } - if vbuiltin { - if vtypePtr { - if rvIsNil(rvv) { - rvSetDirect(rvv, reflect.New(vElem)) - } - d.decode(rv2i(rvv)) - } else { - d.decode(rv2i(rvAddr(rvv, ti.tielem.ptr))) - } - } else { - d.decodeValueNoCheckNil(rvv, valFn) - } - if doMapSet { - mapSet(rv, rvk, rvv, mparams) - } - } - - d.mapEnd() -} - -func (d *decoderMsgpackIO) init(h Handle) { - initHandle(h) - callMake(&d.d) - d.hh = h - d.h = h.getBasicHandle() - - d.err = errDecoderNotInitialized - - if d.h.InternString && d.is == nil { - d.is.init() - } - - d.fp = d.d.init(h, &d.decoderBase, d).(*fastpathDsMsgpackIO) - - if d.bytes { - d.rtidFn = &d.h.rtidFnsDecBytes - d.rtidFnNoExt = &d.h.rtidFnsDecNoExtBytes - } else { - d.bufio = d.h.ReaderBufferSize > 0 - d.rtidFn = &d.h.rtidFnsDecIO - d.rtidFnNoExt = &d.h.rtidFnsDecNoExtIO - } - - d.reset() - -} - -func (d *decoderMsgpackIO) reset() { - d.d.reset() - d.err = nil - d.c = 0 - d.depth = 0 - d.calls = 0 - - d.maxdepth = decDefMaxDepth - if d.h.MaxDepth > 0 { - d.maxdepth = d.h.MaxDepth - } - d.mtid = 0 - d.stid = 0 - d.mtr = false - d.str = false - if d.h.MapType != nil { - d.mtid = rt2id(d.h.MapType) - _, d.mtr = fastpathAvIndex(d.mtid) - } - if d.h.SliceType != nil { - d.stid = rt2id(d.h.SliceType) - _, d.str = fastpathAvIndex(d.stid) - } -} - -func (d *decoderMsgpackIO) Reset(r io.Reader) { - if d.bytes { - halt.onerror(errDecNoResetBytesWithReader) - } - d.reset() - if r == nil { - r = &eofReader - } - d.d.resetInIO(r) -} - -func (d *decoderMsgpackIO) ResetBytes(in []byte) { - if !d.bytes { - halt.onerror(errDecNoResetReaderWithBytes) - } - d.resetBytes(in) -} - -func (d *decoderMsgpackIO) resetBytes(in []byte) { - d.reset() - if in == nil { - in = zeroByteSlice - } - d.d.resetInBytes(in) -} - -func (d *decoderMsgpackIO) ResetString(s string) { - d.ResetBytes(bytesView(s)) -} - -func (d *decoderMsgpackIO) Decode(v interface{}) (err error) { - - defer panicValToErr(d, callRecoverSentinel, &d.err, &err, debugging) - d.mustDecode(v) - return -} - -func (d *decoderMsgpackIO) MustDecode(v interface{}) { - defer panicValToErr(d, callRecoverSentinel, &d.err, nil, true) - d.mustDecode(v) - return -} - -func (d *decoderMsgpackIO) mustDecode(v interface{}) { - halt.onerror(d.err) - if d.hh == nil { - halt.onerror(errNoFormatHandle) - } - - d.calls++ - d.decode(v) - d.calls-- -} - -func (d *decoderMsgpackIO) Release() {} - -func (d *decoderMsgpackIO) swallow() { - d.d.nextValueBytes() -} - -func (d *decoderMsgpackIO) nextValueBytes() []byte { - return d.d.nextValueBytes() -} - -func (d *decoderMsgpackIO) decode(iv interface{}) { - _ = d.d - - rv, ok := isNil(iv, true) - if ok { - halt.onerror(errCannotDecodeIntoNil) - } - - switch v := iv.(type) { - - case *string: - *v = d.detach2Str(d.d.DecodeStringAsBytes()) - case *bool: - *v = d.d.DecodeBool() - case *int: - *v = int(chkOvf.IntV(d.d.DecodeInt64(), intBitsize)) - case *int8: - *v = int8(chkOvf.IntV(d.d.DecodeInt64(), 8)) - case *int16: - *v = int16(chkOvf.IntV(d.d.DecodeInt64(), 16)) - case *int32: - *v = int32(chkOvf.IntV(d.d.DecodeInt64(), 32)) - case *int64: - *v = d.d.DecodeInt64() - case *uint: - *v = uint(chkOvf.UintV(d.d.DecodeUint64(), uintBitsize)) - case *uint8: - *v = uint8(chkOvf.UintV(d.d.DecodeUint64(), 8)) - case *uint16: - *v = uint16(chkOvf.UintV(d.d.DecodeUint64(), 16)) - case *uint32: - *v = uint32(chkOvf.UintV(d.d.DecodeUint64(), 32)) - case *uint64: - *v = d.d.DecodeUint64() - case *uintptr: - *v = uintptr(chkOvf.UintV(d.d.DecodeUint64(), uintBitsize)) - case *float32: - *v = d.d.DecodeFloat32() - case *float64: - *v = d.d.DecodeFloat64() - case *complex64: - *v = complex(d.d.DecodeFloat32(), 0) - case *complex128: - *v = complex(d.d.DecodeFloat64(), 0) - case *[]byte: - *v, _ = d.decodeBytesInto(*v, false) - case []byte: - - d.decodeBytesInto(v[:len(v):len(v)], true) - case *time.Time: - *v = d.d.DecodeTime() - case *Raw: - *v = d.rawBytes() - - case *interface{}: - d.decodeValue(rv4iptr(v), nil) - - case reflect.Value: - if ok, _ = isDecodeable(v); !ok { - d.haltAsNotDecodeable(v) - } - d.decodeValue(v, nil) - - default: - - if skipFastpathTypeSwitchInDirectCall || !d.dh.fastpathDecodeTypeSwitch(iv, d) { - if !rv.IsValid() { - rv = reflect.ValueOf(iv) - } - if ok, _ = isDecodeable(rv); !ok { - d.haltAsNotDecodeable(rv) - } - d.decodeValue(rv, nil) - } - } -} - -func (d *decoderMsgpackIO) decodeValue(rv reflect.Value, fn *decFnMsgpackIO) { - if d.d.TryNil() { - decSetNonNilRV2Zero(rv) - } else { - d.decodeValueNoCheckNil(rv, fn) - } -} - -func (d *decoderMsgpackIO) decodeValueNoCheckNil(rv reflect.Value, fn *decFnMsgpackIO) { - - var rvp reflect.Value - var rvpValid bool -PTR: - if rv.Kind() == reflect.Ptr { - rvpValid = true - if rvIsNil(rv) { - rvSetDirect(rv, reflect.New(rv.Type().Elem())) - } - rvp = rv - rv = rv.Elem() - goto PTR - } - - if fn == nil { - fn = d.fn(rv.Type()) - } - if fn.i.addrD { - if rvpValid { - rv = rvp - } else if rv.CanAddr() { - rv = rvAddr(rv, fn.i.ti.ptr) - } else if fn.i.addrDf { - halt.errorStr("cannot decode into a non-pointer value") - } - } - fn.fd(d, &fn.i, rv) -} - -func (d *decoderMsgpackIO) decodeAs(v interface{}, t reflect.Type, ext bool) { - if ext { - d.decodeValue(baseRV(v), d.fn(t)) - } else { - d.decodeValue(baseRV(v), d.fnNoExt(t)) - } -} - -func (d *decoderMsgpackIO) structFieldNotFound(index int, rvkencname string) { - - if d.h.ErrorIfNoField { - if index >= 0 { - halt.errorInt("no matching struct field found when decoding stream array at index ", int64(index)) - } else if rvkencname != "" { - halt.errorStr2("no matching struct field found when decoding stream map with key ", rvkencname) - } - } - d.swallow() -} - -func (d *decoderMsgpackIO) decodeBytesInto(out []byte, mustFit bool) (v []byte, state dBytesIntoState) { - v, att := d.d.DecodeBytes() - if cap(v) == 0 || (att >= dBytesAttachViewZerocopy && !mustFit) { - - return - } - if len(v) == 0 { - v = zeroByteSlice - return - } - if len(out) == len(v) { - state = dBytesIntoParamOut - } else if cap(out) >= len(v) { - out = out[:len(v)] - state = dBytesIntoParamOutSlice - } else if mustFit { - halt.errorf("bytes capacity insufficient for decoded bytes: got/expected: %d/%d", len(v), len(out)) - } else { - out = make([]byte, len(v)) - state = dBytesIntoNew - } - copy(out, v) - v = out - return -} - -func (d *decoderMsgpackIO) rawBytes() (v []byte) { - - v = d.d.nextValueBytes() - if d.bytes && !d.h.ZeroCopy { - vv := make([]byte, len(v)) - copy(vv, v) - v = vv - } - return -} - -func (d *decoderMsgpackIO) wrapErr(v error, err *error) { - *err = wrapCodecErr(v, d.hh.Name(), d.d.NumBytesRead(), false) -} - -func (d *decoderMsgpackIO) NumBytesRead() int { - return d.d.NumBytesRead() -} - -func (d *decoderMsgpackIO) containerNext(j, containerLen int, hasLen bool) bool { - - if hasLen { - return j < containerLen - } - return !d.d.CheckBreak() -} - -func (d *decoderMsgpackIO) mapElemKey(firstTime bool) { - d.d.ReadMapElemKey(firstTime) - d.c = containerMapKey -} - -func (d *decoderMsgpackIO) mapElemValue() { - d.d.ReadMapElemValue() - d.c = containerMapValue -} - -func (d *decoderMsgpackIO) mapEnd() { - d.d.ReadMapEnd() - d.depthDecr() - d.c = 0 -} - -func (d *decoderMsgpackIO) arrayElem(firstTime bool) { - d.d.ReadArrayElem(firstTime) - d.c = containerArrayElem -} - -func (d *decoderMsgpackIO) arrayEnd() { - d.d.ReadArrayEnd() - d.depthDecr() - d.c = 0 -} - -func (d *decoderMsgpackIO) interfaceExtConvertAndDecode(v interface{}, ext InterfaceExt) { - - var vv interface{} - d.decode(&vv) - ext.UpdateExt(v, vv) - -} - -func (d *decoderMsgpackIO) fn(t reflect.Type) *decFnMsgpackIO { - return d.dh.decFnViaBH(t, d.rtidFn, d.h, d.fp, false) -} - -func (d *decoderMsgpackIO) fnNoExt(t reflect.Type) *decFnMsgpackIO { - return d.dh.decFnViaBH(t, d.rtidFnNoExt, d.h, d.fp, true) -} - -func (helperDecDriverMsgpackIO) newDecoderBytes(in []byte, h Handle) *decoderMsgpackIO { - var c1 decoderMsgpackIO - c1.bytes = true - c1.init(h) - c1.ResetBytes(in) - return &c1 -} - -func (helperDecDriverMsgpackIO) newDecoderIO(in io.Reader, h Handle) *decoderMsgpackIO { - var c1 decoderMsgpackIO - c1.init(h) - c1.Reset(in) - return &c1 -} - -func (helperDecDriverMsgpackIO) decFnloadFastpathUnderlying(ti *typeInfo, fp *fastpathDsMsgpackIO) (f *fastpathDMsgpackIO, u reflect.Type) { - rtid := rt2id(ti.fastpathUnderlying) - idx, ok := fastpathAvIndex(rtid) - if !ok { - return - } - f = &fp[idx] - if uint8(reflect.Array) == ti.kind { - u = reflect.ArrayOf(ti.rt.Len(), ti.elem) - } else { - u = f.rt - } - return -} - -func (helperDecDriverMsgpackIO) decFindRtidFn(s []decRtidFnMsgpackIO, rtid uintptr) (i uint, fn *decFnMsgpackIO) { - - var h uint - var j = uint(len(s)) -LOOP: - if i < j { - h = (i + j) >> 1 - if s[h].rtid < rtid { - i = h + 1 - } else { - j = h - } - goto LOOP - } - if i < uint(len(s)) && s[i].rtid == rtid { - fn = s[i].fn - } - return -} - -func (helperDecDriverMsgpackIO) decFromRtidFnSlice(fns *atomicRtidFnSlice) (s []decRtidFnMsgpackIO) { - if v := fns.load(); v != nil { - s = *(lowLevelToPtr[[]decRtidFnMsgpackIO](v)) - } - return -} - -func (dh helperDecDriverMsgpackIO) decFnViaBH(rt reflect.Type, fns *atomicRtidFnSlice, x *BasicHandle, fp *fastpathDsMsgpackIO, - checkExt bool) (fn *decFnMsgpackIO) { - return dh.decFnVia(rt, fns, x.typeInfos(), &x.mu, x.extHandle, fp, - checkExt, x.CheckCircularRef, x.timeBuiltin, x.binaryHandle, x.jsonHandle) -} - -func (dh helperDecDriverMsgpackIO) decFnVia(rt reflect.Type, fns *atomicRtidFnSlice, - tinfos *TypeInfos, mu *sync.Mutex, exth extHandle, fp *fastpathDsMsgpackIO, - checkExt, checkCircularRef, timeBuiltin, binaryEncoding, json bool) (fn *decFnMsgpackIO) { - rtid := rt2id(rt) - var sp []decRtidFnMsgpackIO = dh.decFromRtidFnSlice(fns) - if sp != nil { - _, fn = dh.decFindRtidFn(sp, rtid) - } - if fn == nil { - fn = dh.decFnViaLoader(rt, rtid, fns, tinfos, mu, exth, fp, checkExt, checkCircularRef, timeBuiltin, binaryEncoding, json) - } - return -} - -func (dh helperDecDriverMsgpackIO) decFnViaLoader(rt reflect.Type, rtid uintptr, fns *atomicRtidFnSlice, - tinfos *TypeInfos, mu *sync.Mutex, exth extHandle, fp *fastpathDsMsgpackIO, - checkExt, checkCircularRef, timeBuiltin, binaryEncoding, json bool) (fn *decFnMsgpackIO) { - - fn = dh.decFnLoad(rt, rtid, tinfos, exth, fp, checkExt, checkCircularRef, timeBuiltin, binaryEncoding, json) - var sp []decRtidFnMsgpackIO - mu.Lock() - sp = dh.decFromRtidFnSlice(fns) - - if sp == nil { - sp = []decRtidFnMsgpackIO{{rtid, fn}} - fns.store(ptrToLowLevel(&sp)) - } else { - idx, fn2 := dh.decFindRtidFn(sp, rtid) - if fn2 == nil { - sp2 := make([]decRtidFnMsgpackIO, len(sp)+1) - copy(sp2[idx+1:], sp[idx:]) - copy(sp2, sp[:idx]) - sp2[idx] = decRtidFnMsgpackIO{rtid, fn} - fns.store(ptrToLowLevel(&sp2)) - } - } - mu.Unlock() - return -} - -func (dh helperDecDriverMsgpackIO) decFnLoad(rt reflect.Type, rtid uintptr, tinfos *TypeInfos, - exth extHandle, fp *fastpathDsMsgpackIO, - checkExt, checkCircularRef, timeBuiltin, binaryEncoding, json bool) (fn *decFnMsgpackIO) { - fn = new(decFnMsgpackIO) - fi := &(fn.i) - ti := tinfos.get(rtid, rt) - fi.ti = ti - rk := reflect.Kind(ti.kind) - - fi.addrDf = true - - if rtid == timeTypId && timeBuiltin { - fn.fd = (*decoderMsgpackIO).kTime - } else if rtid == rawTypId { - fn.fd = (*decoderMsgpackIO).raw - } else if rtid == rawExtTypId { - fn.fd = (*decoderMsgpackIO).rawExt - fi.addrD = true - } else if xfFn := exth.getExt(rtid, checkExt); xfFn != nil { - fi.xfTag, fi.xfFn = xfFn.tag, xfFn.ext - fn.fd = (*decoderMsgpackIO).ext - fi.addrD = true - } else if ti.flagSelfer || ti.flagSelferPtr { - fn.fd = (*decoderMsgpackIO).selferUnmarshal - fi.addrD = ti.flagSelferPtr - } else if supportMarshalInterfaces && binaryEncoding && - (ti.flagBinaryMarshaler || ti.flagBinaryMarshalerPtr) && - (ti.flagBinaryUnmarshaler || ti.flagBinaryUnmarshalerPtr) { - fn.fd = (*decoderMsgpackIO).binaryUnmarshal - fi.addrD = ti.flagBinaryUnmarshalerPtr - } else if supportMarshalInterfaces && !binaryEncoding && json && - (ti.flagJsonMarshaler || ti.flagJsonMarshalerPtr) && - (ti.flagJsonUnmarshaler || ti.flagJsonUnmarshalerPtr) { - - fn.fd = (*decoderMsgpackIO).jsonUnmarshal - fi.addrD = ti.flagJsonUnmarshalerPtr - } else if supportMarshalInterfaces && !binaryEncoding && - (ti.flagTextMarshaler || ti.flagTextMarshalerPtr) && - (ti.flagTextUnmarshaler || ti.flagTextUnmarshalerPtr) { - fn.fd = (*decoderMsgpackIO).textUnmarshal - fi.addrD = ti.flagTextUnmarshalerPtr - } else { - if fastpathEnabled && (rk == reflect.Map || rk == reflect.Slice || rk == reflect.Array) { - var rtid2 uintptr - if !ti.flagHasPkgPath { - rtid2 = rtid - if rk == reflect.Array { - rtid2 = rt2id(ti.key) - } - if idx, ok := fastpathAvIndex(rtid2); ok { - fn.fd = fp[idx].decfn - fi.addrD = true - fi.addrDf = false - if rk == reflect.Array { - fi.addrD = false - } - } - } else { - - xfe, xrt := dh.decFnloadFastpathUnderlying(ti, fp) - if xfe != nil { - xfnf2 := xfe.decfn - if rk == reflect.Array { - fi.addrD = false - fn.fd = func(d *decoderMsgpackIO, xf *decFnInfo, xrv reflect.Value) { - xfnf2(d, xf, rvConvert(xrv, xrt)) - } - } else { - fi.addrD = true - fi.addrDf = false - xptr2rt := reflect.PointerTo(xrt) - fn.fd = func(d *decoderMsgpackIO, xf *decFnInfo, xrv reflect.Value) { - if xrv.Kind() == reflect.Ptr { - xfnf2(d, xf, rvConvert(xrv, xptr2rt)) - } else { - xfnf2(d, xf, rvConvert(xrv, xrt)) - } - } - } - } - } - } - if fn.fd == nil { - switch rk { - case reflect.Bool: - fn.fd = (*decoderMsgpackIO).kBool - case reflect.String: - fn.fd = (*decoderMsgpackIO).kString - case reflect.Int: - fn.fd = (*decoderMsgpackIO).kInt - case reflect.Int8: - fn.fd = (*decoderMsgpackIO).kInt8 - case reflect.Int16: - fn.fd = (*decoderMsgpackIO).kInt16 - case reflect.Int32: - fn.fd = (*decoderMsgpackIO).kInt32 - case reflect.Int64: - fn.fd = (*decoderMsgpackIO).kInt64 - case reflect.Uint: - fn.fd = (*decoderMsgpackIO).kUint - case reflect.Uint8: - fn.fd = (*decoderMsgpackIO).kUint8 - case reflect.Uint16: - fn.fd = (*decoderMsgpackIO).kUint16 - case reflect.Uint32: - fn.fd = (*decoderMsgpackIO).kUint32 - case reflect.Uint64: - fn.fd = (*decoderMsgpackIO).kUint64 - case reflect.Uintptr: - fn.fd = (*decoderMsgpackIO).kUintptr - case reflect.Float32: - fn.fd = (*decoderMsgpackIO).kFloat32 - case reflect.Float64: - fn.fd = (*decoderMsgpackIO).kFloat64 - case reflect.Complex64: - fn.fd = (*decoderMsgpackIO).kComplex64 - case reflect.Complex128: - fn.fd = (*decoderMsgpackIO).kComplex128 - case reflect.Chan: - fn.fd = (*decoderMsgpackIO).kChan - case reflect.Slice: - fn.fd = (*decoderMsgpackIO).kSlice - case reflect.Array: - fi.addrD = false - fn.fd = (*decoderMsgpackIO).kArray - case reflect.Struct: - if ti.simple { - fn.fd = (*decoderMsgpackIO).kStructSimple - } else { - fn.fd = (*decoderMsgpackIO).kStruct - } - case reflect.Map: - fn.fd = (*decoderMsgpackIO).kMap - case reflect.Interface: - - fn.fd = (*decoderMsgpackIO).kInterface - default: - - fn.fd = (*decoderMsgpackIO).kErr - } - } - } - return -} -func (e *msgpackEncDriverIO) EncodeNil() { - e.w.writen1(mpNil) -} - -func (e *msgpackEncDriverIO) EncodeInt(i int64) { - if e.h.PositiveIntUnsigned && i >= 0 { - e.EncodeUint(uint64(i)) - } else if i > math.MaxInt8 { - if i <= math.MaxInt16 { - e.w.writen1(mpInt16) - e.w.writen2(bigen.PutUint16(uint16(i))) - } else if i <= math.MaxInt32 { - e.w.writen1(mpInt32) - e.w.writen4(bigen.PutUint32(uint32(i))) - } else { - e.w.writen1(mpInt64) - e.w.writen8(bigen.PutUint64(uint64(i))) - } - } else if i >= -32 { - if e.h.NoFixedNum { - e.w.writen2(mpInt8, byte(i)) - } else { - e.w.writen1(byte(i)) - } - } else if i >= math.MinInt8 { - e.w.writen2(mpInt8, byte(i)) - } else if i >= math.MinInt16 { - e.w.writen1(mpInt16) - e.w.writen2(bigen.PutUint16(uint16(i))) - } else if i >= math.MinInt32 { - e.w.writen1(mpInt32) - e.w.writen4(bigen.PutUint32(uint32(i))) - } else { - e.w.writen1(mpInt64) - e.w.writen8(bigen.PutUint64(uint64(i))) - } -} - -func (e *msgpackEncDriverIO) EncodeUint(i uint64) { - if i <= math.MaxInt8 { - if e.h.NoFixedNum { - e.w.writen2(mpUint8, byte(i)) - } else { - e.w.writen1(byte(i)) - } - } else if i <= math.MaxUint8 { - e.w.writen2(mpUint8, byte(i)) - } else if i <= math.MaxUint16 { - e.w.writen1(mpUint16) - e.w.writen2(bigen.PutUint16(uint16(i))) - } else if i <= math.MaxUint32 { - e.w.writen1(mpUint32) - e.w.writen4(bigen.PutUint32(uint32(i))) - } else { - e.w.writen1(mpUint64) - e.w.writen8(bigen.PutUint64(uint64(i))) - } -} - -func (e *msgpackEncDriverIO) EncodeBool(b bool) { - if b { - e.w.writen1(mpTrue) - } else { - e.w.writen1(mpFalse) - } -} - -func (e *msgpackEncDriverIO) EncodeFloat32(f float32) { - e.w.writen1(mpFloat) - e.w.writen4(bigen.PutUint32(math.Float32bits(f))) -} - -func (e *msgpackEncDriverIO) EncodeFloat64(f float64) { - e.w.writen1(mpDouble) - e.w.writen8(bigen.PutUint64(math.Float64bits(f))) -} - -func (e *msgpackEncDriverIO) EncodeTime(t time.Time) { - if t.IsZero() { - e.EncodeNil() - return - } - t = t.UTC() - sec, nsec := t.Unix(), uint64(t.Nanosecond()) - var data64 uint64 - var l = 4 - if sec >= 0 && sec>>34 == 0 { - data64 = (nsec << 34) | uint64(sec) - if data64&0xffffffff00000000 != 0 { - l = 8 - } - } else { - l = 12 - } - if e.h.WriteExt { - e.encodeExtPreamble(mpTimeExtTagU, l) - } else { - e.writeContainerLen(msgpackContainerRawLegacy, l) - } - switch l { - case 4: - e.w.writen4(bigen.PutUint32(uint32(data64))) - case 8: - e.w.writen8(bigen.PutUint64(data64)) - case 12: - e.w.writen4(bigen.PutUint32(uint32(nsec))) - e.w.writen8(bigen.PutUint64(uint64(sec))) - } -} - -func (e *msgpackEncDriverIO) EncodeExt(v interface{}, basetype reflect.Type, xtag uint64, ext Ext) { - var bs0, bs []byte - if ext == SelfExt { - bs0 = e.e.blist.get(1024) - bs = bs0 - sideEncode(e.h, &e.h.sideEncPool, func(se encoderI) { oneOffEncode(se, v, &bs, basetype, true) }) - } else { - bs = ext.WriteExt(v) - } - if bs == nil { - e.writeNilBytes() - goto END - } - if e.h.WriteExt { - e.encodeExtPreamble(uint8(xtag), len(bs)) - e.w.writeb(bs) - } else { - e.EncodeBytes(bs) - } -END: - if ext == SelfExt { - e.e.blist.put(bs) - if !byteSliceSameData(bs0, bs) { - e.e.blist.put(bs0) - } - } -} - -func (e *msgpackEncDriverIO) EncodeRawExt(re *RawExt) { - e.encodeExtPreamble(uint8(re.Tag), len(re.Data)) - e.w.writeb(re.Data) -} - -func (e *msgpackEncDriverIO) encodeExtPreamble(xtag byte, l int) { - if l == 1 { - e.w.writen2(mpFixExt1, xtag) - } else if l == 2 { - e.w.writen2(mpFixExt2, xtag) - } else if l == 4 { - e.w.writen2(mpFixExt4, xtag) - } else if l == 8 { - e.w.writen2(mpFixExt8, xtag) - } else if l == 16 { - e.w.writen2(mpFixExt16, xtag) - } else if l < 256 { - e.w.writen2(mpExt8, byte(l)) - e.w.writen1(xtag) - } else if l < 65536 { - e.w.writen1(mpExt16) - e.w.writen2(bigen.PutUint16(uint16(l))) - e.w.writen1(xtag) - } else { - e.w.writen1(mpExt32) - e.w.writen4(bigen.PutUint32(uint32(l))) - e.w.writen1(xtag) - } -} - -func (e *msgpackEncDriverIO) WriteArrayStart(length int) { - e.writeContainerLen(msgpackContainerList, length) -} - -func (e *msgpackEncDriverIO) WriteMapStart(length int) { - e.writeContainerLen(msgpackContainerMap, length) -} - -func (e *msgpackEncDriverIO) WriteArrayEmpty() { - - e.w.writen1(mpFixArrayMin) -} - -func (e *msgpackEncDriverIO) WriteMapEmpty() { - - e.w.writen1(mpFixMapMin) -} - -func (e *msgpackEncDriverIO) EncodeString(s string) { - var ct msgpackContainerType - if e.h.WriteExt { - if e.h.StringToRaw { - ct = msgpackContainerBin - } else { - ct = msgpackContainerStr - } - } else { - ct = msgpackContainerRawLegacy - } - e.writeContainerLen(ct, len(s)) - if len(s) > 0 { - e.w.writestr(s) - } -} - -func (e *msgpackEncDriverIO) EncodeStringNoEscape4Json(v string) { e.EncodeString(v) } - -func (e *msgpackEncDriverIO) EncodeStringBytesRaw(bs []byte) { - if e.h.WriteExt { - e.writeContainerLen(msgpackContainerBin, len(bs)) - } else { - e.writeContainerLen(msgpackContainerRawLegacy, len(bs)) - } - if len(bs) > 0 { - e.w.writeb(bs) - } -} - -func (e *msgpackEncDriverIO) EncodeBytes(v []byte) { - if v == nil { - e.writeNilBytes() - return - } - e.EncodeStringBytesRaw(v) -} - -func (e *msgpackEncDriverIO) writeNilOr(v byte) { - if !e.h.NilCollectionToZeroLength { - v = mpNil - } - e.w.writen1(v) -} - -func (e *msgpackEncDriverIO) writeNilArray() { - e.writeNilOr(mpFixArrayMin) -} - -func (e *msgpackEncDriverIO) writeNilMap() { - e.writeNilOr(mpFixMapMin) -} - -func (e *msgpackEncDriverIO) writeNilBytes() { - e.writeNilOr(mpFixStrMin) -} - -func (e *msgpackEncDriverIO) writeContainerLen(ct msgpackContainerType, l int) { - if ct.fixCutoff > 0 && l < int(ct.fixCutoff) { - e.w.writen1(ct.bFixMin | byte(l)) - } else if ct.b8 > 0 && l < 256 { - e.w.writen2(ct.b8, uint8(l)) - } else if l < 65536 { - e.w.writen1(ct.b16) - e.w.writen2(bigen.PutUint16(uint16(l))) - } else { - e.w.writen1(ct.b32) - e.w.writen4(bigen.PutUint32(uint32(l))) - } -} - -func (d *msgpackDecDriverIO) DecodeNaked() { - if !d.bdRead { - d.readNextBd() - } - bd := d.bd - n := d.d.naked() - var decodeFurther bool - - switch bd { - case mpNil: - n.v = valueTypeNil - d.bdRead = false - case mpFalse: - n.v = valueTypeBool - n.b = false - case mpTrue: - n.v = valueTypeBool - n.b = true - - case mpFloat: - n.v = valueTypeFloat - n.f = float64(math.Float32frombits(bigen.Uint32(d.r.readn4()))) - case mpDouble: - n.v = valueTypeFloat - n.f = math.Float64frombits(bigen.Uint64(d.r.readn8())) - - case mpUint8: - n.v = valueTypeUint - n.u = uint64(d.r.readn1()) - case mpUint16: - n.v = valueTypeUint - n.u = uint64(bigen.Uint16(d.r.readn2())) - case mpUint32: - n.v = valueTypeUint - n.u = uint64(bigen.Uint32(d.r.readn4())) - case mpUint64: - n.v = valueTypeUint - n.u = uint64(bigen.Uint64(d.r.readn8())) - - case mpInt8: - n.v = valueTypeInt - n.i = int64(int8(d.r.readn1())) - case mpInt16: - n.v = valueTypeInt - n.i = int64(int16(bigen.Uint16(d.r.readn2()))) - case mpInt32: - n.v = valueTypeInt - n.i = int64(int32(bigen.Uint32(d.r.readn4()))) - case mpInt64: - n.v = valueTypeInt - n.i = int64(int64(bigen.Uint64(d.r.readn8()))) - - default: - switch { - case bd >= mpPosFixNumMin && bd <= mpPosFixNumMax: - - n.v = valueTypeInt - n.i = int64(int8(bd)) - case bd >= mpNegFixNumMin && bd <= mpNegFixNumMax: - - n.v = valueTypeInt - n.i = int64(int8(bd)) - case bd == mpStr8, bd == mpStr16, bd == mpStr32, bd >= mpFixStrMin && bd <= mpFixStrMax: - d.d.fauxUnionReadRawBytes(d, d.h.WriteExt, d.h.RawToString) - - case bd == mpBin8, bd == mpBin16, bd == mpBin32: - d.d.fauxUnionReadRawBytes(d, false, d.h.RawToString) - case bd == mpArray16, bd == mpArray32, bd >= mpFixArrayMin && bd <= mpFixArrayMax: - n.v = valueTypeArray - decodeFurther = true - case bd == mpMap16, bd == mpMap32, bd >= mpFixMapMin && bd <= mpFixMapMax: - n.v = valueTypeMap - decodeFurther = true - case bd >= mpFixExt1 && bd <= mpFixExt16, bd >= mpExt8 && bd <= mpExt32: - n.v = valueTypeExt - clen := d.readExtLen() - n.u = uint64(d.r.readn1()) - if n.u == uint64(mpTimeExtTagU) { - n.v = valueTypeTime - n.t = d.decodeTime(clen) - } else { - n.l = d.r.readx(uint(clen)) - } - default: - halt.errorf("cannot infer value: %s: Ox%x/%d/%s", msgBadDesc, bd, bd, mpdesc(bd)) - } - } - if !decodeFurther { - d.bdRead = false - } - if n.v == valueTypeUint && d.h.SignedInteger { - n.v = valueTypeInt - n.i = int64(n.u) - } -} - -func (d *msgpackDecDriverIO) nextValueBytes() (v []byte) { - if !d.bdRead { - d.readNextBd() - } - d.r.startRecording() - d.nextValueBytesBdReadR() - v = d.r.stopRecording() - d.bdRead = false - return -} - -func (d *msgpackDecDriverIO) nextValueBytesBdReadR() { - bd := d.bd - - var clen uint - - switch bd { - case mpNil, mpFalse, mpTrue: - case mpUint8, mpInt8: - d.r.readn1() - case mpUint16, mpInt16: - d.r.skip(2) - case mpFloat, mpUint32, mpInt32: - d.r.skip(4) - case mpDouble, mpUint64, mpInt64: - d.r.skip(8) - case mpStr8, mpBin8: - clen = uint(d.r.readn1()) - d.r.skip(clen) - case mpStr16, mpBin16: - x := d.r.readn2() - clen = uint(bigen.Uint16(x)) - d.r.skip(clen) - case mpStr32, mpBin32: - x := d.r.readn4() - clen = uint(bigen.Uint32(x)) - d.r.skip(clen) - case mpFixExt1: - d.r.readn1() - d.r.readn1() - case mpFixExt2: - d.r.readn1() - d.r.skip(2) - case mpFixExt4: - d.r.readn1() - d.r.skip(4) - case mpFixExt8: - d.r.readn1() - d.r.skip(8) - case mpFixExt16: - d.r.readn1() - d.r.skip(16) - case mpExt8: - clen = uint(d.r.readn1()) - d.r.readn1() - d.r.skip(clen) - case mpExt16: - x := d.r.readn2() - clen = uint(bigen.Uint16(x)) - d.r.readn1() - d.r.skip(clen) - case mpExt32: - x := d.r.readn4() - clen = uint(bigen.Uint32(x)) - d.r.readn1() - d.r.skip(clen) - case mpArray16: - x := d.r.readn2() - clen = uint(bigen.Uint16(x)) - for i := uint(0); i < clen; i++ { - d.readNextBd() - d.nextValueBytesBdReadR() - } - case mpArray32: - x := d.r.readn4() - clen = uint(bigen.Uint32(x)) - for i := uint(0); i < clen; i++ { - d.readNextBd() - d.nextValueBytesBdReadR() - } - case mpMap16: - x := d.r.readn2() - clen = uint(bigen.Uint16(x)) - for i := uint(0); i < clen; i++ { - d.readNextBd() - d.nextValueBytesBdReadR() - d.readNextBd() - d.nextValueBytesBdReadR() - } - case mpMap32: - x := d.r.readn4() - clen = uint(bigen.Uint32(x)) - for i := uint(0); i < clen; i++ { - d.readNextBd() - d.nextValueBytesBdReadR() - d.readNextBd() - d.nextValueBytesBdReadR() - } - default: - switch { - case bd >= mpPosFixNumMin && bd <= mpPosFixNumMax: - case bd >= mpNegFixNumMin && bd <= mpNegFixNumMax: - case bd >= mpFixStrMin && bd <= mpFixStrMax: - clen = uint(mpFixStrMin ^ bd) - d.r.skip(clen) - case bd >= mpFixArrayMin && bd <= mpFixArrayMax: - clen = uint(mpFixArrayMin ^ bd) - for i := uint(0); i < clen; i++ { - d.readNextBd() - d.nextValueBytesBdReadR() - } - case bd >= mpFixMapMin && bd <= mpFixMapMax: - clen = uint(mpFixMapMin ^ bd) - for i := uint(0); i < clen; i++ { - d.readNextBd() - d.nextValueBytesBdReadR() - d.readNextBd() - d.nextValueBytesBdReadR() - } - default: - halt.errorf("nextValueBytes: cannot infer value: %s: Ox%x/%d/%s", msgBadDesc, bd, bd, mpdesc(bd)) - } - } - return -} - -func (d *msgpackDecDriverIO) decFloat4Int32() (f float32) { - fbits := bigen.Uint32(d.r.readn4()) - f = math.Float32frombits(fbits) - if !noFrac32(fbits) { - halt.errorf("assigning integer value from float32 with a fraction: %v", f) - } - return -} - -func (d *msgpackDecDriverIO) decFloat4Int64() (f float64) { - fbits := bigen.Uint64(d.r.readn8()) - f = math.Float64frombits(fbits) - if !noFrac64(fbits) { - halt.errorf("assigning integer value from float64 with a fraction: %v", f) - } - return -} - -func (d *msgpackDecDriverIO) DecodeInt64() (i int64) { - if d.advanceNil() { - return - } - switch d.bd { - case mpUint8: - i = int64(uint64(d.r.readn1())) - case mpUint16: - i = int64(uint64(bigen.Uint16(d.r.readn2()))) - case mpUint32: - i = int64(uint64(bigen.Uint32(d.r.readn4()))) - case mpUint64: - i = int64(bigen.Uint64(d.r.readn8())) - case mpInt8: - i = int64(int8(d.r.readn1())) - case mpInt16: - i = int64(int16(bigen.Uint16(d.r.readn2()))) - case mpInt32: - i = int64(int32(bigen.Uint32(d.r.readn4()))) - case mpInt64: - i = int64(bigen.Uint64(d.r.readn8())) - case mpFloat: - i = int64(d.decFloat4Int32()) - case mpDouble: - i = int64(d.decFloat4Int64()) - default: - switch { - case d.bd >= mpPosFixNumMin && d.bd <= mpPosFixNumMax: - i = int64(int8(d.bd)) - case d.bd >= mpNegFixNumMin && d.bd <= mpNegFixNumMax: - i = int64(int8(d.bd)) - default: - halt.errorf("cannot decode signed integer: %s: %x/%s", msgBadDesc, d.bd, mpdesc(d.bd)) - } - } - d.bdRead = false - return -} - -func (d *msgpackDecDriverIO) DecodeUint64() (ui uint64) { - if d.advanceNil() { - return - } - switch d.bd { - case mpUint8: - ui = uint64(d.r.readn1()) - case mpUint16: - ui = uint64(bigen.Uint16(d.r.readn2())) - case mpUint32: - ui = uint64(bigen.Uint32(d.r.readn4())) - case mpUint64: - ui = bigen.Uint64(d.r.readn8()) - case mpInt8: - if i := int64(int8(d.r.readn1())); i >= 0 { - ui = uint64(i) - } else { - halt.errorf("assigning negative signed value: %v, to unsigned type", i) - } - case mpInt16: - if i := int64(int16(bigen.Uint16(d.r.readn2()))); i >= 0 { - ui = uint64(i) - } else { - halt.errorf("assigning negative signed value: %v, to unsigned type", i) - } - case mpInt32: - if i := int64(int32(bigen.Uint32(d.r.readn4()))); i >= 0 { - ui = uint64(i) - } else { - halt.errorf("assigning negative signed value: %v, to unsigned type", i) - } - case mpInt64: - if i := int64(bigen.Uint64(d.r.readn8())); i >= 0 { - ui = uint64(i) - } else { - halt.errorf("assigning negative signed value: %v, to unsigned type", i) - } - case mpFloat: - if f := d.decFloat4Int32(); f >= 0 { - ui = uint64(f) - } else { - halt.errorf("assigning negative float value: %v, to unsigned type", f) - } - case mpDouble: - if f := d.decFloat4Int64(); f >= 0 { - ui = uint64(f) - } else { - halt.errorf("assigning negative float value: %v, to unsigned type", f) - } - default: - switch { - case d.bd >= mpPosFixNumMin && d.bd <= mpPosFixNumMax: - ui = uint64(d.bd) - case d.bd >= mpNegFixNumMin && d.bd <= mpNegFixNumMax: - halt.errorf("assigning negative signed value: %v, to unsigned type", int(d.bd)) - default: - halt.errorf("cannot decode unsigned integer: %s: %x/%s", msgBadDesc, d.bd, mpdesc(d.bd)) - } - } - d.bdRead = false - return -} - -func (d *msgpackDecDriverIO) DecodeFloat64() (f float64) { - if d.advanceNil() { - return - } - if d.bd == mpFloat { - f = float64(math.Float32frombits(bigen.Uint32(d.r.readn4()))) - } else if d.bd == mpDouble { - f = math.Float64frombits(bigen.Uint64(d.r.readn8())) - } else { - f = float64(d.DecodeInt64()) - } - d.bdRead = false - return -} - -func (d *msgpackDecDriverIO) DecodeBool() (b bool) { - if d.advanceNil() { - return - } - if d.bd == mpFalse || d.bd == 0 { - - } else if d.bd == mpTrue || d.bd == 1 { - b = true - } else { - halt.errorf("cannot decode bool: %s: %x/%s", msgBadDesc, d.bd, mpdesc(d.bd)) - } - d.bdRead = false - return -} - -func (d *msgpackDecDriverIO) DecodeBytes() (bs []byte, state dBytesAttachState) { - if d.advanceNil() { - return - } - - var cond bool - bd := d.bd - var clen int - if bd == mpBin8 || bd == mpBin16 || bd == mpBin32 { - clen = d.readContainerLen(msgpackContainerBin) - } else if bd == mpStr8 || bd == mpStr16 || bd == mpStr32 || - (bd >= mpFixStrMin && bd <= mpFixStrMax) { - clen = d.readContainerLen(msgpackContainerStr) - } else if bd == mpArray16 || bd == mpArray32 || - (bd >= mpFixArrayMin && bd <= mpFixArrayMax) { - slen := d.ReadArrayStart() - bs, cond = usableByteSlice(d.d.buf, slen) - for i := 0; i < len(bs); i++ { - bs[i] = uint8(chkOvf.UintV(d.DecodeUint64(), 8)) - } - for i := len(bs); i < slen; i++ { - bs = append(bs, uint8(chkOvf.UintV(d.DecodeUint64(), 8))) - } - if cond { - d.d.buf = bs - } - state = dBytesAttachBuffer - return - } else { - halt.errorf("invalid byte descriptor for decoding bytes, got: 0x%x", d.bd) - } - - d.bdRead = false - bs, cond = d.r.readxb(uint(clen)) - state = d.d.attachState(cond) - return -} - -func (d *msgpackDecDriverIO) DecodeStringAsBytes() (out []byte, state dBytesAttachState) { - out, state = d.DecodeBytes() - if d.h.ValidateUnicode && !utf8.Valid(out) { - halt.errorf("DecodeStringAsBytes: invalid UTF-8: %s", out) - } - return -} - -func (d *msgpackDecDriverIO) readNextBd() { - d.bd = d.r.readn1() - d.bdRead = true -} - -func (d *msgpackDecDriverIO) advanceNil() (null bool) { - if !d.bdRead { - d.readNextBd() - } - if d.bd == mpNil { - d.bdRead = false - return true - } - return -} - -func (d *msgpackDecDriverIO) TryNil() (v bool) { - return d.advanceNil() -} - -func (d *msgpackDecDriverIO) ContainerType() (vt valueType) { - if !d.bdRead { - d.readNextBd() - } - bd := d.bd - if bd == mpNil { - d.bdRead = false - return valueTypeNil - } else if bd == mpBin8 || bd == mpBin16 || bd == mpBin32 { - return valueTypeBytes - } else if bd == mpStr8 || bd == mpStr16 || bd == mpStr32 || - (bd >= mpFixStrMin && bd <= mpFixStrMax) { - if d.h.WriteExt || d.h.RawToString { - return valueTypeString - } - return valueTypeBytes - } else if bd == mpArray16 || bd == mpArray32 || (bd >= mpFixArrayMin && bd <= mpFixArrayMax) { - return valueTypeArray - } else if bd == mpMap16 || bd == mpMap32 || (bd >= mpFixMapMin && bd <= mpFixMapMax) { - return valueTypeMap - } - return valueTypeUnset -} - -func (d *msgpackDecDriverIO) readContainerLen(ct msgpackContainerType) (clen int) { - bd := d.bd - if bd == ct.b8 { - clen = int(d.r.readn1()) - } else if bd == ct.b16 { - clen = int(bigen.Uint16(d.r.readn2())) - } else if bd == ct.b32 { - clen = int(bigen.Uint32(d.r.readn4())) - } else if (ct.bFixMin & bd) == ct.bFixMin { - clen = int(ct.bFixMin ^ bd) - } else { - halt.errorf("cannot read container length: %s: hex: %x, decimal: %d", msgBadDesc, bd, bd) - } - d.bdRead = false - return -} - -func (d *msgpackDecDriverIO) ReadMapStart() int { - if d.advanceNil() { - return containerLenNil - } - return d.readContainerLen(msgpackContainerMap) -} - -func (d *msgpackDecDriverIO) ReadArrayStart() int { - if d.advanceNil() { - return containerLenNil - } - return d.readContainerLen(msgpackContainerList) -} - -func (d *msgpackDecDriverIO) readExtLen() (clen int) { - switch d.bd { - case mpFixExt1: - clen = 1 - case mpFixExt2: - clen = 2 - case mpFixExt4: - clen = 4 - case mpFixExt8: - clen = 8 - case mpFixExt16: - clen = 16 - case mpExt8: - clen = int(d.r.readn1()) - case mpExt16: - clen = int(bigen.Uint16(d.r.readn2())) - case mpExt32: - clen = int(bigen.Uint32(d.r.readn4())) - default: - halt.errorf("decoding ext bytes: found unexpected byte: %x", d.bd) - } - return -} - -func (d *msgpackDecDriverIO) DecodeTime() (t time.Time) { - - if d.advanceNil() { - return - } - bd := d.bd - var clen int - if bd == mpBin8 || bd == mpBin16 || bd == mpBin32 { - clen = d.readContainerLen(msgpackContainerBin) - } else if bd == mpStr8 || bd == mpStr16 || bd == mpStr32 || - (bd >= mpFixStrMin && bd <= mpFixStrMax) { - clen = d.readContainerLen(msgpackContainerStr) - } else { - - d.bdRead = false - b2 := d.r.readn1() - if d.bd == mpFixExt4 && b2 == mpTimeExtTagU { - clen = 4 - } else if d.bd == mpFixExt8 && b2 == mpTimeExtTagU { - clen = 8 - } else if d.bd == mpExt8 && b2 == 12 && d.r.readn1() == mpTimeExtTagU { - clen = 12 - } else { - halt.errorf("invalid stream for decoding time as extension: got 0x%x, 0x%x", d.bd, b2) - } - } - return d.decodeTime(clen) -} - -func (d *msgpackDecDriverIO) decodeTime(clen int) (t time.Time) { - d.bdRead = false - switch clen { - case 4: - t = time.Unix(int64(bigen.Uint32(d.r.readn4())), 0).UTC() - case 8: - tv := bigen.Uint64(d.r.readn8()) - t = time.Unix(int64(tv&0x00000003ffffffff), int64(tv>>34)).UTC() - case 12: - nsec := bigen.Uint32(d.r.readn4()) - sec := bigen.Uint64(d.r.readn8()) - t = time.Unix(int64(sec), int64(nsec)).UTC() - default: - halt.errorf("invalid length of bytes for decoding time - expecting 4 or 8 or 12, got %d", clen) - } - return -} - -func (d *msgpackDecDriverIO) DecodeExt(rv interface{}, basetype reflect.Type, xtag uint64, ext Ext) { - xbs, _, _, ok := d.decodeExtV(ext != nil, xtag) - if !ok { - return - } - if ext == SelfExt { - sideDecode(d.h, &d.h.sideDecPool, func(sd decoderI) { oneOffDecode(sd, rv, xbs, basetype, true) }) - } else { - ext.ReadExt(rv, xbs) - } -} - -func (d *msgpackDecDriverIO) DecodeRawExt(re *RawExt) { - xbs, realxtag, state, ok := d.decodeExtV(false, 0) - if !ok { - return - } - re.Tag = uint64(realxtag) - re.setData(xbs, state >= dBytesAttachViewZerocopy) -} - -func (d *msgpackDecDriverIO) decodeExtV(verifyTag bool, xtagIn uint64) (xbs []byte, xtag byte, bstate dBytesAttachState, ok bool) { - if xtagIn > 0xff { - halt.errorf("ext: tag must be <= 0xff; got: %v", xtagIn) - } - if d.advanceNil() { - return - } - tag := uint8(xtagIn) - xbd := d.bd - if xbd == mpBin8 || xbd == mpBin16 || xbd == mpBin32 { - xbs, bstate = d.DecodeBytes() - } else if xbd == mpStr8 || xbd == mpStr16 || xbd == mpStr32 || - (xbd >= mpFixStrMin && xbd <= mpFixStrMax) { - xbs, bstate = d.DecodeStringAsBytes() - } else { - clen := d.readExtLen() - xtag = d.r.readn1() - if verifyTag && xtag != tag { - halt.errorf("wrong extension tag - got %b, expecting %v", xtag, tag) - } - xbs, ok = d.r.readxb(uint(clen)) - bstate = d.d.attachState(ok) - - } - d.bdRead = false - ok = true - return -} - -func (d *msgpackEncDriverIO) init(hh Handle, shared *encoderBase, enc encoderI) (fp interface{}) { - callMake(&d.w) - d.h = hh.(*MsgpackHandle) - d.e = shared - if shared.bytes { - fp = msgpackFpEncBytes - } else { - fp = msgpackFpEncIO - } - - d.init2(enc) - return -} - -func (e *msgpackEncDriverIO) writeBytesAsis(b []byte) { e.w.writeb(b) } - -func (e *msgpackEncDriverIO) writerEnd() { e.w.end() } - -func (e *msgpackEncDriverIO) resetOutBytes(out *[]byte) { - e.w.resetBytes(*out, out) -} - -func (e *msgpackEncDriverIO) resetOutIO(out io.Writer) { - e.w.resetIO(out, e.h.WriterBufferSize, &e.e.blist) -} - -func (d *msgpackDecDriverIO) init(hh Handle, shared *decoderBase, dec decoderI) (fp interface{}) { - callMake(&d.r) - d.h = hh.(*MsgpackHandle) - d.d = shared - if shared.bytes { - fp = msgpackFpDecBytes - } else { - fp = msgpackFpDecIO - } - - d.init2(dec) - return -} - -func (d *msgpackDecDriverIO) NumBytesRead() int { - return int(d.r.numread()) -} - -func (d *msgpackDecDriverIO) resetInBytes(in []byte) { - d.r.resetBytes(in) -} - -func (d *msgpackDecDriverIO) resetInIO(r io.Reader) { - d.r.resetIO(r, d.h.ReaderBufferSize, d.h.MaxInitLen, &d.d.blist) -} - -func (d *msgpackDecDriverIO) descBd() string { - return sprintf("%v (%s)", d.bd, mpdesc(d.bd)) -} - -func (d *msgpackDecDriverIO) DecodeFloat32() (f float32) { - return float32(chkOvf.Float32V(d.DecodeFloat64())) -} diff --git a/vendor/github.com/ugorji/go/codec/msgpack.notfastpath.mono.generated.go b/vendor/github.com/ugorji/go/codec/msgpack.notfastpath.mono.generated.go deleted file mode 100644 index b4f7d2465..000000000 --- a/vendor/github.com/ugorji/go/codec/msgpack.notfastpath.mono.generated.go +++ /dev/null @@ -1,52 +0,0 @@ -//go:build !notmono && !codec.notmono && (notfastpath || codec.notfastpath) - -// Copyright (c) 2012-2020 Ugorji Nwoke. All rights reserved. -// Use of this source code is governed by a MIT license found in the LICENSE file. - -package codec - -import ( - "reflect" -) - -type fastpathEMsgpackBytes struct { - rt reflect.Type - encfn func(*encoderMsgpackBytes, *encFnInfo, reflect.Value) -} -type fastpathDMsgpackBytes struct { - rt reflect.Type - decfn func(*decoderMsgpackBytes, *decFnInfo, reflect.Value) -} -type fastpathEsMsgpackBytes [0]fastpathEMsgpackBytes -type fastpathDsMsgpackBytes [0]fastpathDMsgpackBytes - -func (helperEncDriverMsgpackBytes) fastpathEncodeTypeSwitch(iv interface{}, e *encoderMsgpackBytes) bool { - return false -} -func (helperDecDriverMsgpackBytes) fastpathDecodeTypeSwitch(iv interface{}, d *decoderMsgpackBytes) bool { - return false -} - -func (helperEncDriverMsgpackBytes) fastpathEList() (v *fastpathEsMsgpackBytes) { return } -func (helperDecDriverMsgpackBytes) fastpathDList() (v *fastpathDsMsgpackBytes) { return } - -type fastpathEMsgpackIO struct { - rt reflect.Type - encfn func(*encoderMsgpackIO, *encFnInfo, reflect.Value) -} -type fastpathDMsgpackIO struct { - rt reflect.Type - decfn func(*decoderMsgpackIO, *decFnInfo, reflect.Value) -} -type fastpathEsMsgpackIO [0]fastpathEMsgpackIO -type fastpathDsMsgpackIO [0]fastpathDMsgpackIO - -func (helperEncDriverMsgpackIO) fastpathEncodeTypeSwitch(iv interface{}, e *encoderMsgpackIO) bool { - return false -} -func (helperDecDriverMsgpackIO) fastpathDecodeTypeSwitch(iv interface{}, d *decoderMsgpackIO) bool { - return false -} - -func (helperEncDriverMsgpackIO) fastpathEList() (v *fastpathEsMsgpackIO) { return } -func (helperDecDriverMsgpackIO) fastpathDList() (v *fastpathDsMsgpackIO) { return } diff --git a/vendor/github.com/ugorji/go/codec/reader.go b/vendor/github.com/ugorji/go/codec/reader.go deleted file mode 100644 index 86c403ab5..000000000 --- a/vendor/github.com/ugorji/go/codec/reader.go +++ /dev/null @@ -1,830 +0,0 @@ -// Copyright (c) 2012-2020 Ugorji Nwoke. All rights reserved. -// Use of this source code is governed by a MIT license found in the LICENSE file. - -package codec - -import ( - "errors" - "io" - "os" -) - -// decReader abstracts the reading source, allowing implementations that can -// read from an io.Reader or directly off a byte slice with zero-copying. -type decReaderI interface { - // readx will return a view of the []byte in one of 2 ways: - // - direct view into []byte which decoding is happening from (if bytes) - // - view into a mutable []byte which the ioReader is using (if IO) - // - // Users should directly consume the contents read, and not store for future use. - readx(n uint) []byte - - // skip n bytes - skip(n uint) - - readb([]byte) - - // readxb will read n bytes, returning as out, and a flag stating whether - // an internal buffer (not the view) was used. - readxb(n uint) (out []byte, usingBuf bool) - - readn1() byte - readn2() [2]byte - readn3() [3]byte - readn4() [4]byte - readn8() [8]byte - // readn1eof() (v uint8, eof bool) - - // // read up to 8 bytes at a time - // readn(num uint8) (v [8]byte) - - numread() uint // number of bytes read - - // skip any whitespace characters, and return the first non-matching byte - skipWhitespace() (token byte) - - // jsonReadNum will read a sequence of numeric characters, checking from the last - // read byte. It will return a sequence of numeric characters (v), - // and the next token character (tok - returned separately), - // - // if an EOF is found before the next token is seen, it returns a token value of 0. - jsonReadNum() (v []byte, token byte) - - // jsonReadAsisChars recognizes 2 terminal characters (" or \). - // jsonReadAsisChars will read json plain characters until it reaches a terminal char, - // and returns a slice up to the terminal char (excluded), - // and also returns the terminal char separately (" or \). - jsonReadAsisChars() (v []byte, terminal byte) - - // readUntil will read characters until it reaches a ", - // return a slice up to " (excluded) - jsonReadUntilDblQuote() (v []byte) - - // skip will skip any byte that matches, and return the first non-matching byte - // skip(accept *bitset256) (token byte) - - // readTo will read any byte that matches, stopping once no-longer matching. - // readTo(accept *bitset256) (out []byte) - - // // readUntil will read characters until it reaches a stop char, - // // return a slice up to the terminal byte (excluded) - // readUntil(stop byte) (out []byte) - - // only supported when reading from bytes - // bytesReadFrom(startpos uint) []byte - - // isBytes() bool - resetIO(r io.Reader, bufsize int, maxInitLen int, blist *bytesFreeList) - - resetBytes(in []byte) - - // nextValueBytes() captures bytes read between a call to startRecording and stopRecording. - // startRecording will always includes the last byte read. - startRecording() - // stopRecording will include all bytes read between the point of startRecording and now. - stopRecording() []byte -} - -// // ------------------------------------------------ - -const maxConsecutiveEmptyReads = 16 // 2 is sufficient, 16 is enough, 64 is optimal - -// const defBufReaderSize = 4096 - -// -------------------- - -// ioReaderByteScanner contains the io.Reader and io.ByteScanner interfaces -type ioReaderByteScanner interface { - io.Reader - io.ByteScanner -} - -// MARKER: why not separate bufioDecReader from ioDecReader? -// -// We tried, but only readn1 of bufioDecReader came close to being -// inlined (at inline cost 82). All other methods were at inline cost >= 90. -// -// Consequently, there's no performance impact from having both together -// (except a single if z.bufio branch, which is likely well predicted and happens -// only once per call (right at the top). - -// ioDecReader is a decReader that reads off an io.Reader. -type ioDecReader struct { - r io.Reader - - blist *bytesFreeList - - maxInitLen uint - - n uint // num read - - bufsize uint - - bufio bool // are we buffering (rc and wc are valid) - rbr bool // r is a byte reader - recording bool // are we recording (src and erc are valid) - done bool // did we reach EOF and are we done? - - // valid when: bufio=false - b [1]byte // tiny buffer for reading single byte (if z.br == nil) - l byte // last byte read - br io.ByteReader // main reader used for ReadByte - - // valid when: bufio=true - wc uint // read cursor - rc uint // write cursor - err error - - // valid when: recording=true - recc uint // start-recording cursor (valid: recording=true) - - buf []byte // buffer for bufio OR recording (if !bufio) -} - -func (z *ioDecReader) resetBytes(in []byte) { - halt.errorStr("resetBytes unsupported by ioDecReader") -} - -func (z *ioDecReader) resetIO(r io.Reader, bufsize int, maxInitLen int, blist *bytesFreeList) { - buf := z.buf - *z = ioDecReader{} - z.maxInitLen = max(1024, uint(maxInitLen)) - z.blist = blist - z.buf = blist.check(buf, max(256, bufsize)) - z.bufsize = uint(max(0, bufsize)) - z.bufio = z.bufsize > 0 - if z.bufio { - z.buf = z.buf[:cap(z.buf)] - } else { - z.buf = z.buf[:0] - } - if r == nil { - z.r = &eofReader - } else { - z.r = r - } - z.br, z.rbr = z.r.(io.ByteReader) -} - -func (z *ioDecReader) numread() uint { - return z.n -} - -func (z *ioDecReader) readn2() [2]byte { - return ([2]byte)(z.readx(2)) - // using readb forced return bs onto heap, unnecessarily - // z.readb(bs[:]) - // return -} - -func (z *ioDecReader) readn3() [3]byte { - return ([3]byte)(z.readx(3)) -} - -func (z *ioDecReader) readn4() [4]byte { - return ([4]byte)(z.readx(4)) -} - -func (z *ioDecReader) readn8() [8]byte { - return ([8]byte)(z.readx(8)) -} - -func (z *ioDecReader) readx(n uint) (bs []byte) { - return bytesOK(z.readxb(n)) -} - -func (z *ioDecReader) readErr() (err error) { - err, z.err = z.err, nil - return -} - -func (z *ioDecReader) checkErr() { - halt.onerror(z.readErr()) -} - -func (z *ioDecReader) readOne() (b byte, err error) { - n, err := z.r.Read(z.b[:]) - if n == 1 { - err = nil - b = z.b[0] - } - return -} - -// fillbuf reads a new chunk into the buffer. -func (z *ioDecReader) fillbuf(bufsize uint) (numShift, numRead uint) { - z.checkErr() - bufsize = max(bufsize, z.bufsize) - - // Slide existing data to beginning. - if z.recording { - numShift = z.recc // recc is always <= rc - } else { - numShift = z.rc - } - if numShift > 0 { - numShift-- // never shift last byte read out - } - copy(z.buf, z.buf[numShift:z.wc]) - z.wc -= numShift - z.rc -= numShift - if z.recording { - z.recc -= numShift - } - // add enough to allow u to read up to bufsize again iff - // - buf is fully written - // - NOTE: don't pre-allocate more until needed - if uint(len(z.buf)) == z.wc { - if bufsize+z.wc < uint(cap(z.buf)) { - z.buf = z.buf[:uint(cap(z.buf))] - } else { - bufsize = max(uint(cap(z.buf)*3/2), bufsize+z.wc) - buf := z.blist.get(int(bufsize)) - buf = buf[:cap(buf)] - copy(buf, z.buf[:z.wc]) - z.blist.put(z.buf) - z.buf = buf - } - } - // Read new data: try a limited number of times. - // if n == 0: try up to maxConsecutiveEmptyReads - // if n > 0 and err == nil: try one more time (to see if we get n == 0 and EOF) - for i := maxConsecutiveEmptyReads; i > 0; i-- { - n, err := z.r.Read(z.buf[z.wc:]) - numRead += uint(n) - z.wc += uint(n) - if err != nil { - // if os read dealine, and we have read something, return - z.err = err - if err == io.EOF { - z.done = true - } else if errors.Is(err, os.ErrDeadlineExceeded) { - // os read deadline, but some bytes read: return (don't store err) - z.err = nil - } - return - } - - // if z.wc == uint(len(z.buf)) { - // return - // } - // only read one time if results returned - // if n > 0 && i > 2 { - // i = 2 // try max one more time (to see about getting EOF) - // } - - // Once you have some data from this read call, move on. - // Consequently, a blocked Read has less chance of happening. - if n > 0 { - return - } - } - z.err = io.ErrNoProgress // either no data read OR not enough data read, without an EOF - return -} - -func (z *ioDecReader) readb(bs []byte) { - if len(bs) == 0 { - return - } - var err error - var n int - if z.bufio { - BUFIO: - for z.rc == z.wc { - z.fillbuf(0) - } - n = copy(bs, z.buf[z.rc:z.wc]) - z.rc += uint(n) - z.n += uint(n) - if n == len(bs) { - return - } - bs = bs[n:] - goto BUFIO - } - - // -------- NOT BUFIO ------ - - var nn uint - bs0 := bs -READER: - n, err = z.r.Read(bs) - if n > 0 { - z.l = bs[n-1] - nn += uint(n) - bs = bs[n:] - } - if len(bs) != 0 && err == nil { - goto READER - } - if z.recording { - z.buf = append(z.buf, bs0[:nn]...) - } - z.n += nn - if len(bs) != 0 { - halt.onerror(err) - halt.errorf("ioDecReader.readb read %d out of %d bytes requested", nn, len(bs0)) - } - return -} - -func (z *ioDecReader) readn1() (b uint8) { - if z.bufio { - for z.rc == z.wc { - z.fillbuf(0) - } - b = z.buf[z.rc] - z.rc++ - z.n++ - return - } - - // -------- NOT BUFIO ------ - - var err error - if z.rbr { - b, err = z.br.ReadByte() - } else { - b, err = z.readOne() - } - halt.onerror(err) - z.l = b - z.n++ - if z.recording { - z.buf = append(z.buf, b) - } - return -} - -func (z *ioDecReader) readxb(n uint) (out []byte, useBuf bool) { - if n == 0 { - return zeroByteSlice, false - } - - if z.bufio { - BUFIO: - nn := int(n+z.rc) - int(z.wc) - if nn > 0 { - z.fillbuf(decInferLen(nn, z.maxInitLen, 1)) - goto BUFIO - } - pos := z.rc - z.rc += uint(n) - z.n += uint(n) - out = z.buf[pos:z.rc] - useBuf = true - return - } - - // -------- NOT BUFIO ------ - - useBuf = true - out = z.buf - r0 := uint(len(out)) - r := r0 - nn := int(n) - var n2 uint - for nn > 0 { - n2 = r + decInferLen(int(nn), z.maxInitLen, 1) - if cap(out) < int(n2) { - out2 := z.blist.putGet(out, int(n2))[:n2] // make([]byte, len2+len3) - copy(out2, out) - out = out2 - } else { - out = out[:n2] - } - n3, err := z.r.Read(out[r:n2]) - if n3 > 0 { - z.l = out[r+uint(n3)-1] - nn -= n3 - r += uint(n3) - } - halt.onerror(err) - } - z.buf = out[:r0+n] - out = out[r0 : r0+n] - z.n += n - return -} - -func (z *ioDecReader) skip(n uint) { - if n == 0 { - return - } - - if z.bufio { - BUFIO: - n2 := min(n, z.wc-z.rc) - // handle in-line, so z.buf doesn't grow much (since we're skipping) - // ie by setting z.rc, fillbuf should keep shifting left (unless recording) - z.rc += n2 - z.n += n2 - n -= n2 - if n > 0 { - z.fillbuf(decInferLen(int(n+z.rc)-int(z.wc), z.maxInitLen, 1)) - goto BUFIO - } - return - } - - // -------- NOT BUFIO ------ - - var out []byte - var fromBlist bool - if z.recording { - out = z.buf - } else { - nn := int(decInferLen(int(n), z.maxInitLen, 1)) - if cap(z.buf) >= nn/2 { - out = z.buf[:cap(z.buf)] - } else { - fromBlist = true - out = z.blist.get(nn) - } - } - - var r, n2 uint - nn := int(n) - for nn > 0 { - n2 = uint(nn) - if z.recording { - r = uint(len(out)) - n2 = r + decInferLen(int(nn), z.maxInitLen, 1) - if cap(out) < int(n2) { - out2 := z.blist.putGet(out, int(n2))[:n2] // make([]byte, len2+len3) - copy(out2, out) - out = out2 - } else { - out = out[:n2] - } - } - n3, err := z.r.Read(out[r:n2]) - if n3 > 0 { - z.l = out[r+uint(n3)-1] - z.n += uint(n3) - nn -= n3 - } - halt.onerror(err) - } - if z.recording { - z.buf = out - } else if fromBlist { - z.blist.put(out) - } - return -} - -// ---- JSON SPECIFIC HELPERS HERE ---- - -func (z *ioDecReader) jsonReadNum() (bs []byte, token byte) { - var start, pos, end uint - if z.bufio { - // read and fill into buf, then take substring - start = z.rc - 1 // include last byte read - pos = start - BUFIO: - if pos == z.wc { - if z.done { - end = pos - goto END - } - numshift, numread := z.fillbuf(0) - start -= numshift - pos -= numshift - if numread == 0 { - end = pos - goto END - } - } - token = z.buf[pos] - pos++ - if isNumberChar(token) { - goto BUFIO - } - end = pos - 1 - END: - z.n += (pos - z.rc) - z.rc = pos - return z.buf[start:end], token - } - - // if not recording, add the last read byte into buf - if !z.recording { - z.buf = append(z.buf[:0], z.l) - } - start = uint(len(z.buf) - 1) // incl last byte in z.buf - var b byte - var err error - -READER: - if z.rbr { - b, err = z.br.ReadByte() - } else { - b, err = z.readOne() - } - if err == io.EOF { - return z.buf[start:], 0 - } - halt.onerror(err) - z.l = b - z.n++ - z.buf = append(z.buf, b) - if isNumberChar(b) { - goto READER - } - return z.buf[start : len(z.buf)-1], b -} - -func (z *ioDecReader) skipWhitespace() (tok byte) { - var pos uint - if z.bufio { - pos = z.rc - BUFIO: - if pos == z.wc { - if z.done { - halt.onerror(io.ErrUnexpectedEOF) - } - numshift, numread := z.fillbuf(0) - pos -= numshift - if numread == 0 { - halt.onerror(io.ErrUnexpectedEOF) - } - } - tok = z.buf[pos] - pos++ - if isWhitespaceChar(tok) { - goto BUFIO - } - z.n += (pos - z.rc) - z.rc = pos - return tok - } - - var err error -READER: - if z.rbr { - tok, err = z.br.ReadByte() - } else { - tok, err = z.readOne() - } - halt.onerror(err) - z.n++ - z.l = tok - if z.recording { - z.buf = append(z.buf, tok) - } - if isWhitespaceChar(tok) { - goto READER - } - return tok -} - -func (z *ioDecReader) readUntil(stop1, stop2 byte) (bs []byte, tok byte) { - var start, pos uint - if z.bufio { - start = z.rc - pos = start - BUFIO: - if pos == z.wc { - if z.done { - halt.onerror(io.ErrUnexpectedEOF) - } - numshift, numread := z.fillbuf(0) - start -= numshift - pos -= numshift - if numread == 0 { - halt.onerror(io.ErrUnexpectedEOF) - } - } - tok = z.buf[pos] - pos++ - if tok == stop1 || tok == stop2 { - z.n += (pos - z.rc) - z.rc = pos - return z.buf[start : pos-1], tok - } - goto BUFIO - } - - var err error - if !z.recording { - z.buf = z.buf[:0] - } - start = uint(len(z.buf)) -READER: - if z.rbr { - tok, err = z.br.ReadByte() - } else { - tok, err = z.readOne() - } - halt.onerror(err) - z.n++ - z.l = tok - z.buf = append(z.buf, tok) - if tok == stop1 || tok == stop2 { - return z.buf[start : len(z.buf)-1], tok - } - goto READER -} - -func (z *ioDecReader) jsonReadAsisChars() (bs []byte, tok byte) { - return z.readUntil('"', '\\') -} - -func (z *ioDecReader) jsonReadUntilDblQuote() (bs []byte) { - bs, _ = z.readUntil('"', 0) - return -} - -// ---- start/stop recording ---- - -func (z *ioDecReader) startRecording() { - z.recording = true - // always include last byte read - if z.bufio { - z.recc = z.rc - 1 - } else { - z.buf = append(z.buf[:0], z.l) - } -} - -func (z *ioDecReader) stopRecording() (v []byte) { - z.recording = false - if z.bufio { - v = z.buf[z.recc:z.rc] - z.recc = 0 - } else { - v = z.buf - z.buf = z.buf[:0] - } - return -} - -// ------------------------------------ - -// bytesDecReader is a decReader that reads off a byte slice with zero copying -// -// Note: we do not try to convert index'ing out of bounds to an io error. -// instead, we let it bubble up to the exported Encode/Decode method -// and recover it as an io error. -// -// Every function here MUST defensively check bounds either explicitly -// or via a bounds check. -// -// see panicValToErr(...) function in helper.go. -type bytesDecReader struct { - b []byte // data - c uint // cursor - r uint // recording cursor - xb []byte // buffer for readxb -} - -func (z *bytesDecReader) resetIO(r io.Reader, bufsize int, maxInitLen int, blist *bytesFreeList) { - halt.errorStr("resetIO unsupported by bytesDecReader") -} - -func (z *bytesDecReader) resetBytes(in []byte) { - // it's ok to resize a nil slice, so long as it's not past 0 - z.b = in[:len(in):len(in)] // reslicing must not go past capacity - z.c = 0 -} - -func (z *bytesDecReader) numread() uint { - return z.c -} - -// Note: slicing from a non-constant start position is more expensive, -// as more computation is required to decipher the pointer start position. -// However, we do it only once, and it's better than reslicing both z.b and return value. - -func (z *bytesDecReader) readx(n uint) (bs []byte) { - bs = z.b[z.c : z.c+n] - z.c += n - return -} - -func (z *bytesDecReader) skip(n uint) { - if z.c+n > uint(cap(z.b)) { - halt.error(&outOfBoundsError{uint(cap(z.b)), z.c + n}) - } - z.c += n -} - -func (z *bytesDecReader) readxb(n uint) (out []byte, usingBuf bool) { - return z.readx(n), false -} - -func (z *bytesDecReader) readb(bs []byte) { - copy(bs, z.readx(uint(len(bs)))) -} - -func (z *bytesDecReader) readn1() (v uint8) { - v = z.b[z.c] - z.c++ - return -} - -func (z *bytesDecReader) readn2() (bs [2]byte) { - bs = [2]byte(z.b[z.c:]) - z.c += 2 - return -} - -func (z *bytesDecReader) readn3() (bs [3]byte) { - bs = [3]byte(z.b[z.c:]) - z.c += 3 - return -} - -func (z *bytesDecReader) readn4() (bs [4]byte) { - bs = [4]byte(z.b[z.c:]) - z.c += 4 - return -} - -func (z *bytesDecReader) readn8() (bs [8]byte) { - bs = [8]byte(z.b[z.c:]) - z.c += 8 - return -} - -func (z *bytesDecReader) jsonReadNum() (bs []byte, token byte) { - start := z.c - 1 // include last byte - i := start -LOOP: - // gracefully handle end of slice (~= EOF) - if i < uint(len(z.b)) { - if isNumberChar(z.b[i]) { - i++ - goto LOOP - } - token = z.b[i] - } - z.c = i + 1 - bs = z.b[start:i] // byteSliceOf(z.b, start, i) - return -} - -func (z *bytesDecReader) jsonReadAsisChars() (bs []byte, token byte) { - i := z.c -LOOP: - token = z.b[i] - i++ - if token == '"' || token == '\\' { - // z.c, i = i, z.c - // return byteSliceOf(z.b, i, z.c-1), token - bs = z.b[z.c : i-1] - z.c = i - return - // return z.b[i : z.c-1], token - } - goto LOOP -} - -func (z *bytesDecReader) skipWhitespace() (token byte) { - i := z.c -LOOP: - // setting token before check reduces inlining cost, - // making containerNext inlineable - token = z.b[i] - if !isWhitespaceChar(token) { - z.c = i + 1 - return - } - i++ - goto LOOP -} - -func (z *bytesDecReader) jsonReadUntilDblQuote() (out []byte) { - i := z.c -LOOP: - if z.b[i] == '"' { - out = z.b[z.c:i] // byteSliceOf(z.b, z.c, i) - z.c = i + 1 - return - } - i++ - goto LOOP -} - -func (z *bytesDecReader) startRecording() { - z.r = z.c - 1 -} - -func (z *bytesDecReader) stopRecording() (v []byte) { - v = z.b[z.r:z.c] - z.r = 0 - return -} - -type devNullReader struct{} - -func (devNullReader) Read(p []byte) (int, error) { return 0, io.EOF } -func (devNullReader) Close() error { return nil } -func (devNullReader) ReadByte() (byte, error) { return 0, io.EOF } -func (devNullReader) UnreadByte() error { return io.EOF } - -// MARKER: readn{1,2,3,4,8} should throw an out of bounds error if past length. -// MARKER: readn1: explicitly ensure bounds check is done -// MARKER: readn{2,3,4,8}: ensure you slice z.b completely so we get bounds error if past end. diff --git a/vendor/github.com/ugorji/go/codec/rpc.go b/vendor/github.com/ugorji/go/codec/rpc.go deleted file mode 100644 index bdc535b6d..000000000 --- a/vendor/github.com/ugorji/go/codec/rpc.go +++ /dev/null @@ -1,228 +0,0 @@ -// Copyright (c) 2012-2020 Ugorji Nwoke. All rights reserved. -// Use of this source code is governed by a MIT license found in the LICENSE file. - -package codec - -import ( - "errors" - "io" - "net" - "net/rpc" - "sync/atomic" -) - -var ( - errRpcIsClosed = errors.New("rpc - connection has been closed") - errRpcNoConn = errors.New("rpc - no connection") - - rpcSpaceArr = [1]byte{' '} -) - -// Rpc provides a rpc Server or Client Codec for rpc communication. -type Rpc interface { - ServerCodec(conn io.ReadWriteCloser, h Handle) rpc.ServerCodec - ClientCodec(conn io.ReadWriteCloser, h Handle) rpc.ClientCodec -} - -// RPCOptions holds options specific to rpc functionality -type RPCOptions struct { - // RPCNoBuffer configures whether we attempt to buffer reads and writes during RPC calls. - // - // Set RPCNoBuffer=true to turn buffering off. - // - // Buffering can still be done if buffered connections are passed in, or - // buffering is configured on the handle. - // - // Deprecated: Buffering should be configured at the Handle or by using a buffer Reader. - // Setting this has no effect anymore (after v1.2.12 - authored 2025-05-06) - RPCNoBuffer bool -} - -// rpcCodec defines the struct members and common methods. -type rpcCodec struct { - c io.Closer - r io.Reader - w io.Writer - f ioFlusher - nc net.Conn - dec *Decoder - enc *Encoder - h Handle - - cls atomic.Pointer[clsErr] -} - -func newRPCCodec(conn io.ReadWriteCloser, h Handle) *rpcCodec { - nc, _ := conn.(net.Conn) - f, _ := conn.(ioFlusher) - rc := &rpcCodec{ - h: h, - c: conn, - w: conn, - r: conn, - f: f, - nc: nc, - enc: NewEncoder(conn, h), - dec: NewDecoder(conn, h), - } - rc.cls.Store(new(clsErr)) - return rc -} - -func (c *rpcCodec) write(obj ...interface{}) (err error) { - err = c.ready() - if err != nil { - return - } - if c.f != nil { - defer func() { - flushErr := c.f.Flush() - if flushErr != nil && err == nil { - err = flushErr - } - }() - } - - for _, o := range obj { - err = c.enc.Encode(o) - if err != nil { - return - } - // defensive: ensure a space is always written after each encoding, - // in case the value was a number, and encoding a value right after - // without a space will lead to invalid output. - if c.h.isJson() { - _, err = c.w.Write(rpcSpaceArr[:]) - if err != nil { - return - } - } - } - return -} - -func (c *rpcCodec) read(obj interface{}) (err error) { - err = c.ready() - if err == nil { - // Setting ReadDeadline should not be necessary, - // especially since it only works for net.Conn (not generic ioReadCloser). - // if c.nc != nil { - // c.nc.SetReadDeadline(time.Now().Add(1 * time.Second)) - // } - - // Note: If nil is passed in, we should read and discard - if obj == nil { - // return c.dec.Decode(&obj) - err = panicToErr(c.dec, func() { c.dec.swallow() }) - } else { - err = c.dec.Decode(obj) - } - } - return -} - -func (c *rpcCodec) Close() (err error) { - if c.c != nil { - cls := c.cls.Load() - if !cls.closed { - // writing to same pointer could lead to a data race (always make new one) - cls = &clsErr{closed: true, err: c.c.Close()} - c.cls.Store(cls) - } - err = cls.err - } - return -} - -func (c *rpcCodec) ready() (err error) { - if c.c == nil { - err = errRpcNoConn - } else { - cls := c.cls.Load() - if cls != nil && cls.closed { - if err = cls.err; err == nil { - err = errRpcIsClosed - } - } - } - return -} - -func (c *rpcCodec) ReadResponseBody(body interface{}) error { - return c.read(body) -} - -// ------------------------------------- - -type goRpcCodec struct { - *rpcCodec -} - -func (c *goRpcCodec) WriteRequest(r *rpc.Request, body interface{}) error { - return c.write(r, body) -} - -func (c *goRpcCodec) WriteResponse(r *rpc.Response, body interface{}) error { - return c.write(r, body) -} - -func (c *goRpcCodec) ReadResponseHeader(r *rpc.Response) error { - return c.read(r) -} - -func (c *goRpcCodec) ReadRequestHeader(r *rpc.Request) error { - return c.read(r) -} - -func (c *goRpcCodec) ReadRequestBody(body interface{}) error { - return c.read(body) -} - -// ------------------------------------- - -// goRpc is the implementation of Rpc that uses the communication protocol -// as defined in net/rpc package. -type goRpc struct{} - -// GoRpc implements Rpc using the communication protocol defined in net/rpc package. -// -// Note: network connection (from net.Dial, of type io.ReadWriteCloser) is not buffered. -// -// For performance, you should configure WriterBufferSize and ReaderBufferSize on the handle. -// This ensures we use an adequate buffer during reading and writing. -// If not configured, we will internally initialize and use a buffer during reads and writes. -// This can be turned off via the RPCNoBuffer option on the Handle. -// -// var handle codec.JsonHandle -// handle.RPCNoBuffer = true // turns off attempt by rpc module to initialize a buffer -// -// Example 1: one way of configuring buffering explicitly: -// -// var handle codec.JsonHandle // codec handle -// handle.ReaderBufferSize = 1024 -// handle.WriterBufferSize = 1024 -// var conn io.ReadWriteCloser // connection got from a socket -// var serverCodec = GoRpc.ServerCodec(conn, handle) -// var clientCodec = GoRpc.ClientCodec(conn, handle) -// -// Example 2: you can also explicitly create a buffered connection yourself, -// and not worry about configuring the buffer sizes in the Handle. -// -// var handle codec.Handle // codec handle -// var conn io.ReadWriteCloser // connection got from a socket -// var bufconn = struct { // bufconn here is a buffered io.ReadWriteCloser -// io.Closer -// *bufio.Reader -// *bufio.Writer -// }{conn, bufio.NewReader(conn), bufio.NewWriter(conn)} -// var serverCodec = GoRpc.ServerCodec(bufconn, handle) -// var clientCodec = GoRpc.ClientCodec(bufconn, handle) -var GoRpc goRpc - -func (x goRpc) ServerCodec(conn io.ReadWriteCloser, h Handle) rpc.ServerCodec { - return &goRpcCodec{newRPCCodec(conn, h)} -} - -func (x goRpc) ClientCodec(conn io.ReadWriteCloser, h Handle) rpc.ClientCodec { - return &goRpcCodec{newRPCCodec(conn, h)} -} diff --git a/vendor/github.com/ugorji/go/codec/simple.base.go b/vendor/github.com/ugorji/go/codec/simple.base.go deleted file mode 100644 index 2522282cf..000000000 --- a/vendor/github.com/ugorji/go/codec/simple.base.go +++ /dev/null @@ -1,97 +0,0 @@ -// Copyright (c) 2012-2020 Ugorji Nwoke. All rights reserved. -// Use of this source code is governed by a MIT license found in the LICENSE file. - -package codec - -import ( - "reflect" -) - -const ( - _ uint8 = iota - simpleVdNil = 1 - simpleVdFalse = 2 - simpleVdTrue = 3 - simpleVdFloat32 = 4 - simpleVdFloat64 = 5 - - // each lasts for 4 (ie n, n+1, n+2, n+3) - simpleVdPosInt = 8 - simpleVdNegInt = 12 - - simpleVdTime = 24 - - // containers: each lasts for 8 (ie n, n+1, n+2, ... n+7) - simpleVdString = 216 - simpleVdByteArray = 224 - simpleVdArray = 232 - simpleVdMap = 240 - simpleVdExt = 248 -) - -var simpledescNames = map[byte]string{ - simpleVdNil: "null", - simpleVdFalse: "false", - simpleVdTrue: "true", - simpleVdFloat32: "float32", - simpleVdFloat64: "float64", - - simpleVdPosInt: "+int", - simpleVdNegInt: "-int", - - simpleVdTime: "time", - - simpleVdString: "string", - simpleVdByteArray: "binary", - simpleVdArray: "array", - simpleVdMap: "map", - simpleVdExt: "ext", -} - -func simpledesc(bd byte) (s string) { - s = simpledescNames[bd] - if s == "" { - s = "unknown" - } - return -} - -//------------------------------------ - -// SimpleHandle is a Handle for a very simple encoding format. -// -// simple is a simplistic codec similar to binc, but not as compact. -// - Encoding of a value is always preceded by the descriptor byte (bd) -// - True, false, nil are encoded fully in 1 byte (the descriptor) -// - Integers (intXXX, uintXXX) are encoded in 1, 2, 4 or 8 bytes (plus a descriptor byte). -// There are positive (uintXXX and intXXX >= 0) and negative (intXXX < 0) integers. -// - Floats are encoded in 4 or 8 bytes (plus a descriptor byte) -// - Length of containers (strings, bytes, array, map, extensions) -// are encoded in 0, 1, 2, 4 or 8 bytes. -// Zero-length containers have no length encoded. -// For others, the number of bytes is given by pow(2, bd%3) -// - maps are encoded as [bd] [length] [[key][value]]... -// - arrays are encoded as [bd] [length] [value]... -// - extensions are encoded as [bd] [length] [tag] [byte]... -// - strings/bytearrays are encoded as [bd] [length] [byte]... -// - time.Time are encoded as [bd] [length] [byte]... -// -// The full spec will be published soon. -type SimpleHandle struct { - binaryEncodingType - notJsonType - BasicHandle - - // EncZeroValuesAsNil says to encode zero values for numbers, bool, string, etc as nil - EncZeroValuesAsNil bool -} - -// Name returns the name of the handle: simple -func (h *SimpleHandle) Name() string { return "simple" } - -func (h *SimpleHandle) desc(bd byte) string { return simpledesc(bd) } - -// SetBytesExt sets an extension -func (h *SimpleHandle) SetBytesExt(rt reflect.Type, tag uint64, ext BytesExt) (err error) { - return h.SetExt(rt, tag, makeExt(ext)) -} diff --git a/vendor/github.com/ugorji/go/codec/simple.fastpath.mono.generated.go b/vendor/github.com/ugorji/go/codec/simple.fastpath.mono.generated.go deleted file mode 100644 index 329c4bfe5..000000000 --- a/vendor/github.com/ugorji/go/codec/simple.fastpath.mono.generated.go +++ /dev/null @@ -1,12482 +0,0 @@ -//go:build !notmono && !codec.notmono && !notfastpath && !codec.notfastpath - -// Copyright (c) 2012-2020 Ugorji Nwoke. All rights reserved. -// Use of this source code is governed by a MIT license found in the LICENSE file. - -package codec - -import ( - "reflect" - "slices" - "sort" -) - -type fastpathESimpleBytes struct { - rtid uintptr - rt reflect.Type - encfn func(*encoderSimpleBytes, *encFnInfo, reflect.Value) -} -type fastpathDSimpleBytes struct { - rtid uintptr - rt reflect.Type - decfn func(*decoderSimpleBytes, *decFnInfo, reflect.Value) -} -type fastpathEsSimpleBytes [56]fastpathESimpleBytes -type fastpathDsSimpleBytes [56]fastpathDSimpleBytes -type fastpathETSimpleBytes struct{} -type fastpathDTSimpleBytes struct{} - -func (helperEncDriverSimpleBytes) fastpathEList() *fastpathEsSimpleBytes { - var i uint = 0 - var s fastpathEsSimpleBytes - fn := func(v interface{}, fe func(*encoderSimpleBytes, *encFnInfo, reflect.Value)) { - xrt := reflect.TypeOf(v) - s[i] = fastpathESimpleBytes{rt2id(xrt), xrt, fe} - i++ - } - - fn([]interface{}(nil), (*encoderSimpleBytes).fastpathEncSliceIntfR) - fn([]string(nil), (*encoderSimpleBytes).fastpathEncSliceStringR) - fn([][]byte(nil), (*encoderSimpleBytes).fastpathEncSliceBytesR) - fn([]float32(nil), (*encoderSimpleBytes).fastpathEncSliceFloat32R) - fn([]float64(nil), (*encoderSimpleBytes).fastpathEncSliceFloat64R) - fn([]uint8(nil), (*encoderSimpleBytes).fastpathEncSliceUint8R) - fn([]uint64(nil), (*encoderSimpleBytes).fastpathEncSliceUint64R) - fn([]int(nil), (*encoderSimpleBytes).fastpathEncSliceIntR) - fn([]int32(nil), (*encoderSimpleBytes).fastpathEncSliceInt32R) - fn([]int64(nil), (*encoderSimpleBytes).fastpathEncSliceInt64R) - fn([]bool(nil), (*encoderSimpleBytes).fastpathEncSliceBoolR) - - fn(map[string]interface{}(nil), (*encoderSimpleBytes).fastpathEncMapStringIntfR) - fn(map[string]string(nil), (*encoderSimpleBytes).fastpathEncMapStringStringR) - fn(map[string][]byte(nil), (*encoderSimpleBytes).fastpathEncMapStringBytesR) - fn(map[string]uint8(nil), (*encoderSimpleBytes).fastpathEncMapStringUint8R) - fn(map[string]uint64(nil), (*encoderSimpleBytes).fastpathEncMapStringUint64R) - fn(map[string]int(nil), (*encoderSimpleBytes).fastpathEncMapStringIntR) - fn(map[string]int32(nil), (*encoderSimpleBytes).fastpathEncMapStringInt32R) - fn(map[string]float64(nil), (*encoderSimpleBytes).fastpathEncMapStringFloat64R) - fn(map[string]bool(nil), (*encoderSimpleBytes).fastpathEncMapStringBoolR) - fn(map[uint8]interface{}(nil), (*encoderSimpleBytes).fastpathEncMapUint8IntfR) - fn(map[uint8]string(nil), (*encoderSimpleBytes).fastpathEncMapUint8StringR) - fn(map[uint8][]byte(nil), (*encoderSimpleBytes).fastpathEncMapUint8BytesR) - fn(map[uint8]uint8(nil), (*encoderSimpleBytes).fastpathEncMapUint8Uint8R) - fn(map[uint8]uint64(nil), (*encoderSimpleBytes).fastpathEncMapUint8Uint64R) - fn(map[uint8]int(nil), (*encoderSimpleBytes).fastpathEncMapUint8IntR) - fn(map[uint8]int32(nil), (*encoderSimpleBytes).fastpathEncMapUint8Int32R) - fn(map[uint8]float64(nil), (*encoderSimpleBytes).fastpathEncMapUint8Float64R) - fn(map[uint8]bool(nil), (*encoderSimpleBytes).fastpathEncMapUint8BoolR) - fn(map[uint64]interface{}(nil), (*encoderSimpleBytes).fastpathEncMapUint64IntfR) - fn(map[uint64]string(nil), (*encoderSimpleBytes).fastpathEncMapUint64StringR) - fn(map[uint64][]byte(nil), (*encoderSimpleBytes).fastpathEncMapUint64BytesR) - fn(map[uint64]uint8(nil), (*encoderSimpleBytes).fastpathEncMapUint64Uint8R) - fn(map[uint64]uint64(nil), (*encoderSimpleBytes).fastpathEncMapUint64Uint64R) - fn(map[uint64]int(nil), (*encoderSimpleBytes).fastpathEncMapUint64IntR) - fn(map[uint64]int32(nil), (*encoderSimpleBytes).fastpathEncMapUint64Int32R) - fn(map[uint64]float64(nil), (*encoderSimpleBytes).fastpathEncMapUint64Float64R) - fn(map[uint64]bool(nil), (*encoderSimpleBytes).fastpathEncMapUint64BoolR) - fn(map[int]interface{}(nil), (*encoderSimpleBytes).fastpathEncMapIntIntfR) - fn(map[int]string(nil), (*encoderSimpleBytes).fastpathEncMapIntStringR) - fn(map[int][]byte(nil), (*encoderSimpleBytes).fastpathEncMapIntBytesR) - fn(map[int]uint8(nil), (*encoderSimpleBytes).fastpathEncMapIntUint8R) - fn(map[int]uint64(nil), (*encoderSimpleBytes).fastpathEncMapIntUint64R) - fn(map[int]int(nil), (*encoderSimpleBytes).fastpathEncMapIntIntR) - fn(map[int]int32(nil), (*encoderSimpleBytes).fastpathEncMapIntInt32R) - fn(map[int]float64(nil), (*encoderSimpleBytes).fastpathEncMapIntFloat64R) - fn(map[int]bool(nil), (*encoderSimpleBytes).fastpathEncMapIntBoolR) - fn(map[int32]interface{}(nil), (*encoderSimpleBytes).fastpathEncMapInt32IntfR) - fn(map[int32]string(nil), (*encoderSimpleBytes).fastpathEncMapInt32StringR) - fn(map[int32][]byte(nil), (*encoderSimpleBytes).fastpathEncMapInt32BytesR) - fn(map[int32]uint8(nil), (*encoderSimpleBytes).fastpathEncMapInt32Uint8R) - fn(map[int32]uint64(nil), (*encoderSimpleBytes).fastpathEncMapInt32Uint64R) - fn(map[int32]int(nil), (*encoderSimpleBytes).fastpathEncMapInt32IntR) - fn(map[int32]int32(nil), (*encoderSimpleBytes).fastpathEncMapInt32Int32R) - fn(map[int32]float64(nil), (*encoderSimpleBytes).fastpathEncMapInt32Float64R) - fn(map[int32]bool(nil), (*encoderSimpleBytes).fastpathEncMapInt32BoolR) - - sort.Slice(s[:], func(i, j int) bool { return s[i].rtid < s[j].rtid }) - return &s -} - -func (helperDecDriverSimpleBytes) fastpathDList() *fastpathDsSimpleBytes { - var i uint = 0 - var s fastpathDsSimpleBytes - fn := func(v interface{}, fd func(*decoderSimpleBytes, *decFnInfo, reflect.Value)) { - xrt := reflect.TypeOf(v) - s[i] = fastpathDSimpleBytes{rt2id(xrt), xrt, fd} - i++ - } - - fn([]interface{}(nil), (*decoderSimpleBytes).fastpathDecSliceIntfR) - fn([]string(nil), (*decoderSimpleBytes).fastpathDecSliceStringR) - fn([][]byte(nil), (*decoderSimpleBytes).fastpathDecSliceBytesR) - fn([]float32(nil), (*decoderSimpleBytes).fastpathDecSliceFloat32R) - fn([]float64(nil), (*decoderSimpleBytes).fastpathDecSliceFloat64R) - fn([]uint8(nil), (*decoderSimpleBytes).fastpathDecSliceUint8R) - fn([]uint64(nil), (*decoderSimpleBytes).fastpathDecSliceUint64R) - fn([]int(nil), (*decoderSimpleBytes).fastpathDecSliceIntR) - fn([]int32(nil), (*decoderSimpleBytes).fastpathDecSliceInt32R) - fn([]int64(nil), (*decoderSimpleBytes).fastpathDecSliceInt64R) - fn([]bool(nil), (*decoderSimpleBytes).fastpathDecSliceBoolR) - - fn(map[string]interface{}(nil), (*decoderSimpleBytes).fastpathDecMapStringIntfR) - fn(map[string]string(nil), (*decoderSimpleBytes).fastpathDecMapStringStringR) - fn(map[string][]byte(nil), (*decoderSimpleBytes).fastpathDecMapStringBytesR) - fn(map[string]uint8(nil), (*decoderSimpleBytes).fastpathDecMapStringUint8R) - fn(map[string]uint64(nil), (*decoderSimpleBytes).fastpathDecMapStringUint64R) - fn(map[string]int(nil), (*decoderSimpleBytes).fastpathDecMapStringIntR) - fn(map[string]int32(nil), (*decoderSimpleBytes).fastpathDecMapStringInt32R) - fn(map[string]float64(nil), (*decoderSimpleBytes).fastpathDecMapStringFloat64R) - fn(map[string]bool(nil), (*decoderSimpleBytes).fastpathDecMapStringBoolR) - fn(map[uint8]interface{}(nil), (*decoderSimpleBytes).fastpathDecMapUint8IntfR) - fn(map[uint8]string(nil), (*decoderSimpleBytes).fastpathDecMapUint8StringR) - fn(map[uint8][]byte(nil), (*decoderSimpleBytes).fastpathDecMapUint8BytesR) - fn(map[uint8]uint8(nil), (*decoderSimpleBytes).fastpathDecMapUint8Uint8R) - fn(map[uint8]uint64(nil), (*decoderSimpleBytes).fastpathDecMapUint8Uint64R) - fn(map[uint8]int(nil), (*decoderSimpleBytes).fastpathDecMapUint8IntR) - fn(map[uint8]int32(nil), (*decoderSimpleBytes).fastpathDecMapUint8Int32R) - fn(map[uint8]float64(nil), (*decoderSimpleBytes).fastpathDecMapUint8Float64R) - fn(map[uint8]bool(nil), (*decoderSimpleBytes).fastpathDecMapUint8BoolR) - fn(map[uint64]interface{}(nil), (*decoderSimpleBytes).fastpathDecMapUint64IntfR) - fn(map[uint64]string(nil), (*decoderSimpleBytes).fastpathDecMapUint64StringR) - fn(map[uint64][]byte(nil), (*decoderSimpleBytes).fastpathDecMapUint64BytesR) - fn(map[uint64]uint8(nil), (*decoderSimpleBytes).fastpathDecMapUint64Uint8R) - fn(map[uint64]uint64(nil), (*decoderSimpleBytes).fastpathDecMapUint64Uint64R) - fn(map[uint64]int(nil), (*decoderSimpleBytes).fastpathDecMapUint64IntR) - fn(map[uint64]int32(nil), (*decoderSimpleBytes).fastpathDecMapUint64Int32R) - fn(map[uint64]float64(nil), (*decoderSimpleBytes).fastpathDecMapUint64Float64R) - fn(map[uint64]bool(nil), (*decoderSimpleBytes).fastpathDecMapUint64BoolR) - fn(map[int]interface{}(nil), (*decoderSimpleBytes).fastpathDecMapIntIntfR) - fn(map[int]string(nil), (*decoderSimpleBytes).fastpathDecMapIntStringR) - fn(map[int][]byte(nil), (*decoderSimpleBytes).fastpathDecMapIntBytesR) - fn(map[int]uint8(nil), (*decoderSimpleBytes).fastpathDecMapIntUint8R) - fn(map[int]uint64(nil), (*decoderSimpleBytes).fastpathDecMapIntUint64R) - fn(map[int]int(nil), (*decoderSimpleBytes).fastpathDecMapIntIntR) - fn(map[int]int32(nil), (*decoderSimpleBytes).fastpathDecMapIntInt32R) - fn(map[int]float64(nil), (*decoderSimpleBytes).fastpathDecMapIntFloat64R) - fn(map[int]bool(nil), (*decoderSimpleBytes).fastpathDecMapIntBoolR) - fn(map[int32]interface{}(nil), (*decoderSimpleBytes).fastpathDecMapInt32IntfR) - fn(map[int32]string(nil), (*decoderSimpleBytes).fastpathDecMapInt32StringR) - fn(map[int32][]byte(nil), (*decoderSimpleBytes).fastpathDecMapInt32BytesR) - fn(map[int32]uint8(nil), (*decoderSimpleBytes).fastpathDecMapInt32Uint8R) - fn(map[int32]uint64(nil), (*decoderSimpleBytes).fastpathDecMapInt32Uint64R) - fn(map[int32]int(nil), (*decoderSimpleBytes).fastpathDecMapInt32IntR) - fn(map[int32]int32(nil), (*decoderSimpleBytes).fastpathDecMapInt32Int32R) - fn(map[int32]float64(nil), (*decoderSimpleBytes).fastpathDecMapInt32Float64R) - fn(map[int32]bool(nil), (*decoderSimpleBytes).fastpathDecMapInt32BoolR) - - sort.Slice(s[:], func(i, j int) bool { return s[i].rtid < s[j].rtid }) - return &s -} - -func (helperEncDriverSimpleBytes) fastpathEncodeTypeSwitch(iv interface{}, e *encoderSimpleBytes) bool { - var ft fastpathETSimpleBytes - switch v := iv.(type) { - case []interface{}: - if v == nil { - e.e.writeNilArray() - } else { - ft.EncSliceIntfV(v, e) - } - case []string: - if v == nil { - e.e.writeNilArray() - } else { - ft.EncSliceStringV(v, e) - } - case [][]byte: - if v == nil { - e.e.writeNilArray() - } else { - ft.EncSliceBytesV(v, e) - } - case []float32: - if v == nil { - e.e.writeNilArray() - } else { - ft.EncSliceFloat32V(v, e) - } - case []float64: - if v == nil { - e.e.writeNilArray() - } else { - ft.EncSliceFloat64V(v, e) - } - case []uint8: - if v == nil { - e.e.writeNilArray() - } else { - ft.EncSliceUint8V(v, e) - } - case []uint64: - if v == nil { - e.e.writeNilArray() - } else { - ft.EncSliceUint64V(v, e) - } - case []int: - if v == nil { - e.e.writeNilArray() - } else { - ft.EncSliceIntV(v, e) - } - case []int32: - if v == nil { - e.e.writeNilArray() - } else { - ft.EncSliceInt32V(v, e) - } - case []int64: - if v == nil { - e.e.writeNilArray() - } else { - ft.EncSliceInt64V(v, e) - } - case []bool: - if v == nil { - e.e.writeNilArray() - } else { - ft.EncSliceBoolV(v, e) - } - case map[string]interface{}: - if v == nil { - e.e.writeNilMap() - } else { - ft.EncMapStringIntfV(v, e) - } - case map[string]string: - if v == nil { - e.e.writeNilMap() - } else { - ft.EncMapStringStringV(v, e) - } - case map[string][]byte: - if v == nil { - e.e.writeNilMap() - } else { - ft.EncMapStringBytesV(v, e) - } - case map[string]uint8: - if v == nil { - e.e.writeNilMap() - } else { - ft.EncMapStringUint8V(v, e) - } - case map[string]uint64: - if v == nil { - e.e.writeNilMap() - } else { - ft.EncMapStringUint64V(v, e) - } - case map[string]int: - if v == nil { - e.e.writeNilMap() - } else { - ft.EncMapStringIntV(v, e) - } - case map[string]int32: - if v == nil { - e.e.writeNilMap() - } else { - ft.EncMapStringInt32V(v, e) - } - case map[string]float64: - if v == nil { - e.e.writeNilMap() - } else { - ft.EncMapStringFloat64V(v, e) - } - case map[string]bool: - if v == nil { - e.e.writeNilMap() - } else { - ft.EncMapStringBoolV(v, e) - } - case map[uint8]interface{}: - if v == nil { - e.e.writeNilMap() - } else { - ft.EncMapUint8IntfV(v, e) - } - case map[uint8]string: - if v == nil { - e.e.writeNilMap() - } else { - ft.EncMapUint8StringV(v, e) - } - case map[uint8][]byte: - if v == nil { - e.e.writeNilMap() - } else { - ft.EncMapUint8BytesV(v, e) - } - case map[uint8]uint8: - if v == nil { - e.e.writeNilMap() - } else { - ft.EncMapUint8Uint8V(v, e) - } - case map[uint8]uint64: - if v == nil { - e.e.writeNilMap() - } else { - ft.EncMapUint8Uint64V(v, e) - } - case map[uint8]int: - if v == nil { - e.e.writeNilMap() - } else { - ft.EncMapUint8IntV(v, e) - } - case map[uint8]int32: - if v == nil { - e.e.writeNilMap() - } else { - ft.EncMapUint8Int32V(v, e) - } - case map[uint8]float64: - if v == nil { - e.e.writeNilMap() - } else { - ft.EncMapUint8Float64V(v, e) - } - case map[uint8]bool: - if v == nil { - e.e.writeNilMap() - } else { - ft.EncMapUint8BoolV(v, e) - } - case map[uint64]interface{}: - if v == nil { - e.e.writeNilMap() - } else { - ft.EncMapUint64IntfV(v, e) - } - case map[uint64]string: - if v == nil { - e.e.writeNilMap() - } else { - ft.EncMapUint64StringV(v, e) - } - case map[uint64][]byte: - if v == nil { - e.e.writeNilMap() - } else { - ft.EncMapUint64BytesV(v, e) - } - case map[uint64]uint8: - if v == nil { - e.e.writeNilMap() - } else { - ft.EncMapUint64Uint8V(v, e) - } - case map[uint64]uint64: - if v == nil { - e.e.writeNilMap() - } else { - ft.EncMapUint64Uint64V(v, e) - } - case map[uint64]int: - if v == nil { - e.e.writeNilMap() - } else { - ft.EncMapUint64IntV(v, e) - } - case map[uint64]int32: - if v == nil { - e.e.writeNilMap() - } else { - ft.EncMapUint64Int32V(v, e) - } - case map[uint64]float64: - if v == nil { - e.e.writeNilMap() - } else { - ft.EncMapUint64Float64V(v, e) - } - case map[uint64]bool: - if v == nil { - e.e.writeNilMap() - } else { - ft.EncMapUint64BoolV(v, e) - } - case map[int]interface{}: - if v == nil { - e.e.writeNilMap() - } else { - ft.EncMapIntIntfV(v, e) - } - case map[int]string: - if v == nil { - e.e.writeNilMap() - } else { - ft.EncMapIntStringV(v, e) - } - case map[int][]byte: - if v == nil { - e.e.writeNilMap() - } else { - ft.EncMapIntBytesV(v, e) - } - case map[int]uint8: - if v == nil { - e.e.writeNilMap() - } else { - ft.EncMapIntUint8V(v, e) - } - case map[int]uint64: - if v == nil { - e.e.writeNilMap() - } else { - ft.EncMapIntUint64V(v, e) - } - case map[int]int: - if v == nil { - e.e.writeNilMap() - } else { - ft.EncMapIntIntV(v, e) - } - case map[int]int32: - if v == nil { - e.e.writeNilMap() - } else { - ft.EncMapIntInt32V(v, e) - } - case map[int]float64: - if v == nil { - e.e.writeNilMap() - } else { - ft.EncMapIntFloat64V(v, e) - } - case map[int]bool: - if v == nil { - e.e.writeNilMap() - } else { - ft.EncMapIntBoolV(v, e) - } - case map[int32]interface{}: - if v == nil { - e.e.writeNilMap() - } else { - ft.EncMapInt32IntfV(v, e) - } - case map[int32]string: - if v == nil { - e.e.writeNilMap() - } else { - ft.EncMapInt32StringV(v, e) - } - case map[int32][]byte: - if v == nil { - e.e.writeNilMap() - } else { - ft.EncMapInt32BytesV(v, e) - } - case map[int32]uint8: - if v == nil { - e.e.writeNilMap() - } else { - ft.EncMapInt32Uint8V(v, e) - } - case map[int32]uint64: - if v == nil { - e.e.writeNilMap() - } else { - ft.EncMapInt32Uint64V(v, e) - } - case map[int32]int: - if v == nil { - e.e.writeNilMap() - } else { - ft.EncMapInt32IntV(v, e) - } - case map[int32]int32: - if v == nil { - e.e.writeNilMap() - } else { - ft.EncMapInt32Int32V(v, e) - } - case map[int32]float64: - if v == nil { - e.e.writeNilMap() - } else { - ft.EncMapInt32Float64V(v, e) - } - case map[int32]bool: - if v == nil { - e.e.writeNilMap() - } else { - ft.EncMapInt32BoolV(v, e) - } - default: - _ = v - return false - } - return true -} - -func (e *encoderSimpleBytes) fastpathEncSliceIntfR(f *encFnInfo, rv reflect.Value) { - var ft fastpathETSimpleBytes - var v []interface{} - if rv.Kind() == reflect.Array { - rvGetSlice4Array(rv, &v) - } else { - v = rv2i(rv).([]interface{}) - } - if f.ti.mbs { - ft.EncAsMapSliceIntfV(v, e) - return - } - ft.EncSliceIntfV(v, e) -} -func (fastpathETSimpleBytes) EncSliceIntfV(v []interface{}, e *encoderSimpleBytes) { - if len(v) == 0 { - e.c = 0 - e.e.WriteArrayEmpty() - return - } - e.arrayStart(len(v)) - for j := range v { - e.c = containerArrayElem - e.e.WriteArrayElem(j == 0) - if !e.encodeBuiltin(v[j]) { - e.encodeR(reflect.ValueOf(v[j])) - } - } - e.c = 0 - e.e.WriteArrayEnd() -} -func (fastpathETSimpleBytes) EncAsMapSliceIntfV(v []interface{}, e *encoderSimpleBytes) { - if len(v) == 0 { - e.c = 0 - e.e.WriteMapEmpty() - return - } - e.haltOnMbsOddLen(len(v)) - e.mapStart(len(v) >> 1) - for j := range v { - if j&1 == 0 { - e.c = containerMapKey - e.e.WriteMapElemKey(j == 0) - } else { - e.mapElemValue() - } - if !e.encodeBuiltin(v[j]) { - e.encodeR(reflect.ValueOf(v[j])) - } - } - e.c = 0 - e.e.WriteMapEnd() -} - -func (e *encoderSimpleBytes) fastpathEncSliceStringR(f *encFnInfo, rv reflect.Value) { - var ft fastpathETSimpleBytes - var v []string - if rv.Kind() == reflect.Array { - rvGetSlice4Array(rv, &v) - } else { - v = rv2i(rv).([]string) - } - if f.ti.mbs { - ft.EncAsMapSliceStringV(v, e) - return - } - ft.EncSliceStringV(v, e) -} -func (fastpathETSimpleBytes) EncSliceStringV(v []string, e *encoderSimpleBytes) { - if len(v) == 0 { - e.c = 0 - e.e.WriteArrayEmpty() - return - } - e.arrayStart(len(v)) - for j := range v { - e.c = containerArrayElem - e.e.WriteArrayElem(j == 0) - e.e.EncodeString(v[j]) - } - e.c = 0 - e.e.WriteArrayEnd() -} -func (fastpathETSimpleBytes) EncAsMapSliceStringV(v []string, e *encoderSimpleBytes) { - if len(v) == 0 { - e.c = 0 - e.e.WriteMapEmpty() - return - } - e.haltOnMbsOddLen(len(v)) - e.mapStart(len(v) >> 1) - for j := range v { - if j&1 == 0 { - e.c = containerMapKey - e.e.WriteMapElemKey(j == 0) - } else { - e.mapElemValue() - } - e.e.EncodeString(v[j]) - } - e.c = 0 - e.e.WriteMapEnd() -} - -func (e *encoderSimpleBytes) fastpathEncSliceBytesR(f *encFnInfo, rv reflect.Value) { - var ft fastpathETSimpleBytes - var v [][]byte - if rv.Kind() == reflect.Array { - rvGetSlice4Array(rv, &v) - } else { - v = rv2i(rv).([][]byte) - } - if f.ti.mbs { - ft.EncAsMapSliceBytesV(v, e) - return - } - ft.EncSliceBytesV(v, e) -} -func (fastpathETSimpleBytes) EncSliceBytesV(v [][]byte, e *encoderSimpleBytes) { - if len(v) == 0 { - e.c = 0 - e.e.WriteArrayEmpty() - return - } - e.arrayStart(len(v)) - for j := range v { - e.c = containerArrayElem - e.e.WriteArrayElem(j == 0) - e.e.EncodeBytes(v[j]) - } - e.c = 0 - e.e.WriteArrayEnd() -} -func (fastpathETSimpleBytes) EncAsMapSliceBytesV(v [][]byte, e *encoderSimpleBytes) { - if len(v) == 0 { - e.c = 0 - e.e.WriteMapEmpty() - return - } - e.haltOnMbsOddLen(len(v)) - e.mapStart(len(v) >> 1) - for j := range v { - if j&1 == 0 { - e.c = containerMapKey - e.e.WriteMapElemKey(j == 0) - } else { - e.mapElemValue() - } - e.e.EncodeBytes(v[j]) - } - e.c = 0 - e.e.WriteMapEnd() -} - -func (e *encoderSimpleBytes) fastpathEncSliceFloat32R(f *encFnInfo, rv reflect.Value) { - var ft fastpathETSimpleBytes - var v []float32 - if rv.Kind() == reflect.Array { - rvGetSlice4Array(rv, &v) - } else { - v = rv2i(rv).([]float32) - } - if f.ti.mbs { - ft.EncAsMapSliceFloat32V(v, e) - return - } - ft.EncSliceFloat32V(v, e) -} -func (fastpathETSimpleBytes) EncSliceFloat32V(v []float32, e *encoderSimpleBytes) { - if len(v) == 0 { - e.c = 0 - e.e.WriteArrayEmpty() - return - } - e.arrayStart(len(v)) - for j := range v { - e.c = containerArrayElem - e.e.WriteArrayElem(j == 0) - e.e.EncodeFloat32(v[j]) - } - e.c = 0 - e.e.WriteArrayEnd() -} -func (fastpathETSimpleBytes) EncAsMapSliceFloat32V(v []float32, e *encoderSimpleBytes) { - if len(v) == 0 { - e.c = 0 - e.e.WriteMapEmpty() - return - } - e.haltOnMbsOddLen(len(v)) - e.mapStart(len(v) >> 1) - for j := range v { - if j&1 == 0 { - e.c = containerMapKey - e.e.WriteMapElemKey(j == 0) - } else { - e.mapElemValue() - } - e.e.EncodeFloat32(v[j]) - } - e.c = 0 - e.e.WriteMapEnd() -} - -func (e *encoderSimpleBytes) fastpathEncSliceFloat64R(f *encFnInfo, rv reflect.Value) { - var ft fastpathETSimpleBytes - var v []float64 - if rv.Kind() == reflect.Array { - rvGetSlice4Array(rv, &v) - } else { - v = rv2i(rv).([]float64) - } - if f.ti.mbs { - ft.EncAsMapSliceFloat64V(v, e) - return - } - ft.EncSliceFloat64V(v, e) -} -func (fastpathETSimpleBytes) EncSliceFloat64V(v []float64, e *encoderSimpleBytes) { - if len(v) == 0 { - e.c = 0 - e.e.WriteArrayEmpty() - return - } - e.arrayStart(len(v)) - for j := range v { - e.c = containerArrayElem - e.e.WriteArrayElem(j == 0) - e.e.EncodeFloat64(v[j]) - } - e.c = 0 - e.e.WriteArrayEnd() -} -func (fastpathETSimpleBytes) EncAsMapSliceFloat64V(v []float64, e *encoderSimpleBytes) { - if len(v) == 0 { - e.c = 0 - e.e.WriteMapEmpty() - return - } - e.haltOnMbsOddLen(len(v)) - e.mapStart(len(v) >> 1) - for j := range v { - if j&1 == 0 { - e.c = containerMapKey - e.e.WriteMapElemKey(j == 0) - } else { - e.mapElemValue() - } - e.e.EncodeFloat64(v[j]) - } - e.c = 0 - e.e.WriteMapEnd() -} - -func (e *encoderSimpleBytes) fastpathEncSliceUint8R(f *encFnInfo, rv reflect.Value) { - var ft fastpathETSimpleBytes - var v []uint8 - if rv.Kind() == reflect.Array { - rvGetSlice4Array(rv, &v) - } else { - v = rv2i(rv).([]uint8) - } - if f.ti.mbs { - ft.EncAsMapSliceUint8V(v, e) - return - } - ft.EncSliceUint8V(v, e) -} -func (fastpathETSimpleBytes) EncSliceUint8V(v []uint8, e *encoderSimpleBytes) { - e.e.EncodeStringBytesRaw(v) -} -func (fastpathETSimpleBytes) EncAsMapSliceUint8V(v []uint8, e *encoderSimpleBytes) { - if len(v) == 0 { - e.c = 0 - e.e.WriteMapEmpty() - return - } - e.haltOnMbsOddLen(len(v)) - e.mapStart(len(v) >> 1) - for j := range v { - if j&1 == 0 { - e.c = containerMapKey - e.e.WriteMapElemKey(j == 0) - } else { - e.mapElemValue() - } - e.e.EncodeUint(uint64(v[j])) - } - e.c = 0 - e.e.WriteMapEnd() -} - -func (e *encoderSimpleBytes) fastpathEncSliceUint64R(f *encFnInfo, rv reflect.Value) { - var ft fastpathETSimpleBytes - var v []uint64 - if rv.Kind() == reflect.Array { - rvGetSlice4Array(rv, &v) - } else { - v = rv2i(rv).([]uint64) - } - if f.ti.mbs { - ft.EncAsMapSliceUint64V(v, e) - return - } - ft.EncSliceUint64V(v, e) -} -func (fastpathETSimpleBytes) EncSliceUint64V(v []uint64, e *encoderSimpleBytes) { - if len(v) == 0 { - e.c = 0 - e.e.WriteArrayEmpty() - return - } - e.arrayStart(len(v)) - for j := range v { - e.c = containerArrayElem - e.e.WriteArrayElem(j == 0) - e.e.EncodeUint(v[j]) - } - e.c = 0 - e.e.WriteArrayEnd() -} -func (fastpathETSimpleBytes) EncAsMapSliceUint64V(v []uint64, e *encoderSimpleBytes) { - if len(v) == 0 { - e.c = 0 - e.e.WriteMapEmpty() - return - } - e.haltOnMbsOddLen(len(v)) - e.mapStart(len(v) >> 1) - for j := range v { - if j&1 == 0 { - e.c = containerMapKey - e.e.WriteMapElemKey(j == 0) - } else { - e.mapElemValue() - } - e.e.EncodeUint(v[j]) - } - e.c = 0 - e.e.WriteMapEnd() -} - -func (e *encoderSimpleBytes) fastpathEncSliceIntR(f *encFnInfo, rv reflect.Value) { - var ft fastpathETSimpleBytes - var v []int - if rv.Kind() == reflect.Array { - rvGetSlice4Array(rv, &v) - } else { - v = rv2i(rv).([]int) - } - if f.ti.mbs { - ft.EncAsMapSliceIntV(v, e) - return - } - ft.EncSliceIntV(v, e) -} -func (fastpathETSimpleBytes) EncSliceIntV(v []int, e *encoderSimpleBytes) { - if len(v) == 0 { - e.c = 0 - e.e.WriteArrayEmpty() - return - } - e.arrayStart(len(v)) - for j := range v { - e.c = containerArrayElem - e.e.WriteArrayElem(j == 0) - e.e.EncodeInt(int64(v[j])) - } - e.c = 0 - e.e.WriteArrayEnd() -} -func (fastpathETSimpleBytes) EncAsMapSliceIntV(v []int, e *encoderSimpleBytes) { - if len(v) == 0 { - e.c = 0 - e.e.WriteMapEmpty() - return - } - e.haltOnMbsOddLen(len(v)) - e.mapStart(len(v) >> 1) - for j := range v { - if j&1 == 0 { - e.c = containerMapKey - e.e.WriteMapElemKey(j == 0) - } else { - e.mapElemValue() - } - e.e.EncodeInt(int64(v[j])) - } - e.c = 0 - e.e.WriteMapEnd() -} - -func (e *encoderSimpleBytes) fastpathEncSliceInt32R(f *encFnInfo, rv reflect.Value) { - var ft fastpathETSimpleBytes - var v []int32 - if rv.Kind() == reflect.Array { - rvGetSlice4Array(rv, &v) - } else { - v = rv2i(rv).([]int32) - } - if f.ti.mbs { - ft.EncAsMapSliceInt32V(v, e) - return - } - ft.EncSliceInt32V(v, e) -} -func (fastpathETSimpleBytes) EncSliceInt32V(v []int32, e *encoderSimpleBytes) { - if len(v) == 0 { - e.c = 0 - e.e.WriteArrayEmpty() - return - } - e.arrayStart(len(v)) - for j := range v { - e.c = containerArrayElem - e.e.WriteArrayElem(j == 0) - e.e.EncodeInt(int64(v[j])) - } - e.c = 0 - e.e.WriteArrayEnd() -} -func (fastpathETSimpleBytes) EncAsMapSliceInt32V(v []int32, e *encoderSimpleBytes) { - if len(v) == 0 { - e.c = 0 - e.e.WriteMapEmpty() - return - } - e.haltOnMbsOddLen(len(v)) - e.mapStart(len(v) >> 1) - for j := range v { - if j&1 == 0 { - e.c = containerMapKey - e.e.WriteMapElemKey(j == 0) - } else { - e.mapElemValue() - } - e.e.EncodeInt(int64(v[j])) - } - e.c = 0 - e.e.WriteMapEnd() -} - -func (e *encoderSimpleBytes) fastpathEncSliceInt64R(f *encFnInfo, rv reflect.Value) { - var ft fastpathETSimpleBytes - var v []int64 - if rv.Kind() == reflect.Array { - rvGetSlice4Array(rv, &v) - } else { - v = rv2i(rv).([]int64) - } - if f.ti.mbs { - ft.EncAsMapSliceInt64V(v, e) - return - } - ft.EncSliceInt64V(v, e) -} -func (fastpathETSimpleBytes) EncSliceInt64V(v []int64, e *encoderSimpleBytes) { - if len(v) == 0 { - e.c = 0 - e.e.WriteArrayEmpty() - return - } - e.arrayStart(len(v)) - for j := range v { - e.c = containerArrayElem - e.e.WriteArrayElem(j == 0) - e.e.EncodeInt(v[j]) - } - e.c = 0 - e.e.WriteArrayEnd() -} -func (fastpathETSimpleBytes) EncAsMapSliceInt64V(v []int64, e *encoderSimpleBytes) { - if len(v) == 0 { - e.c = 0 - e.e.WriteMapEmpty() - return - } - e.haltOnMbsOddLen(len(v)) - e.mapStart(len(v) >> 1) - for j := range v { - if j&1 == 0 { - e.c = containerMapKey - e.e.WriteMapElemKey(j == 0) - } else { - e.mapElemValue() - } - e.e.EncodeInt(v[j]) - } - e.c = 0 - e.e.WriteMapEnd() -} - -func (e *encoderSimpleBytes) fastpathEncSliceBoolR(f *encFnInfo, rv reflect.Value) { - var ft fastpathETSimpleBytes - var v []bool - if rv.Kind() == reflect.Array { - rvGetSlice4Array(rv, &v) - } else { - v = rv2i(rv).([]bool) - } - if f.ti.mbs { - ft.EncAsMapSliceBoolV(v, e) - return - } - ft.EncSliceBoolV(v, e) -} -func (fastpathETSimpleBytes) EncSliceBoolV(v []bool, e *encoderSimpleBytes) { - if len(v) == 0 { - e.c = 0 - e.e.WriteArrayEmpty() - return - } - e.arrayStart(len(v)) - for j := range v { - e.c = containerArrayElem - e.e.WriteArrayElem(j == 0) - e.e.EncodeBool(v[j]) - } - e.c = 0 - e.e.WriteArrayEnd() -} -func (fastpathETSimpleBytes) EncAsMapSliceBoolV(v []bool, e *encoderSimpleBytes) { - if len(v) == 0 { - e.c = 0 - e.e.WriteMapEmpty() - return - } - e.haltOnMbsOddLen(len(v)) - e.mapStart(len(v) >> 1) - for j := range v { - if j&1 == 0 { - e.c = containerMapKey - e.e.WriteMapElemKey(j == 0) - } else { - e.mapElemValue() - } - e.e.EncodeBool(v[j]) - } - e.c = 0 - e.e.WriteMapEnd() -} - -func (e *encoderSimpleBytes) fastpathEncMapStringIntfR(f *encFnInfo, rv reflect.Value) { - fastpathETSimpleBytes{}.EncMapStringIntfV(rv2i(rv).(map[string]interface{}), e) -} -func (fastpathETSimpleBytes) EncMapStringIntfV(v map[string]interface{}, e *encoderSimpleBytes) { - if len(v) == 0 { - e.e.WriteMapEmpty() - return - } - var i uint - e.mapStart(len(v)) - if e.h.Canonical { - v2 := make([]string, len(v)) - for k := range v { - v2[i] = k - i++ - } - slices.Sort(v2) - for i, k2 := range v2 { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeString(k2) - e.mapElemValue() - if !e.encodeBuiltin(v[k2]) { - e.encodeR(reflect.ValueOf(v[k2])) - } - } - } else { - i = 0 - for k2, v2 := range v { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeString(k2) - e.mapElemValue() - if !e.encodeBuiltin(v2) { - e.encodeR(reflect.ValueOf(v2)) - } - i++ - } - } - e.c = 0 - e.e.WriteMapEnd() -} -func (e *encoderSimpleBytes) fastpathEncMapStringStringR(f *encFnInfo, rv reflect.Value) { - fastpathETSimpleBytes{}.EncMapStringStringV(rv2i(rv).(map[string]string), e) -} -func (fastpathETSimpleBytes) EncMapStringStringV(v map[string]string, e *encoderSimpleBytes) { - if len(v) == 0 { - e.e.WriteMapEmpty() - return - } - var i uint - e.mapStart(len(v)) - if e.h.Canonical { - v2 := make([]string, len(v)) - for k := range v { - v2[i] = k - i++ - } - slices.Sort(v2) - for i, k2 := range v2 { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeString(k2) - e.mapElemValue() - e.e.EncodeString(v[k2]) - } - } else { - i = 0 - for k2, v2 := range v { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeString(k2) - e.mapElemValue() - e.e.EncodeString(v2) - i++ - } - } - e.c = 0 - e.e.WriteMapEnd() -} -func (e *encoderSimpleBytes) fastpathEncMapStringBytesR(f *encFnInfo, rv reflect.Value) { - fastpathETSimpleBytes{}.EncMapStringBytesV(rv2i(rv).(map[string][]byte), e) -} -func (fastpathETSimpleBytes) EncMapStringBytesV(v map[string][]byte, e *encoderSimpleBytes) { - if len(v) == 0 { - e.e.WriteMapEmpty() - return - } - var i uint - e.mapStart(len(v)) - if e.h.Canonical { - v2 := make([]string, len(v)) - for k := range v { - v2[i] = k - i++ - } - slices.Sort(v2) - for i, k2 := range v2 { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeString(k2) - e.mapElemValue() - e.e.EncodeBytes(v[k2]) - } - } else { - i = 0 - for k2, v2 := range v { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeString(k2) - e.mapElemValue() - e.e.EncodeBytes(v2) - i++ - } - } - e.c = 0 - e.e.WriteMapEnd() -} -func (e *encoderSimpleBytes) fastpathEncMapStringUint8R(f *encFnInfo, rv reflect.Value) { - fastpathETSimpleBytes{}.EncMapStringUint8V(rv2i(rv).(map[string]uint8), e) -} -func (fastpathETSimpleBytes) EncMapStringUint8V(v map[string]uint8, e *encoderSimpleBytes) { - if len(v) == 0 { - e.e.WriteMapEmpty() - return - } - var i uint - e.mapStart(len(v)) - if e.h.Canonical { - v2 := make([]string, len(v)) - for k := range v { - v2[i] = k - i++ - } - slices.Sort(v2) - for i, k2 := range v2 { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeString(k2) - e.mapElemValue() - e.e.EncodeUint(uint64(v[k2])) - } - } else { - i = 0 - for k2, v2 := range v { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeString(k2) - e.mapElemValue() - e.e.EncodeUint(uint64(v2)) - i++ - } - } - e.c = 0 - e.e.WriteMapEnd() -} -func (e *encoderSimpleBytes) fastpathEncMapStringUint64R(f *encFnInfo, rv reflect.Value) { - fastpathETSimpleBytes{}.EncMapStringUint64V(rv2i(rv).(map[string]uint64), e) -} -func (fastpathETSimpleBytes) EncMapStringUint64V(v map[string]uint64, e *encoderSimpleBytes) { - if len(v) == 0 { - e.e.WriteMapEmpty() - return - } - var i uint - e.mapStart(len(v)) - if e.h.Canonical { - v2 := make([]string, len(v)) - for k := range v { - v2[i] = k - i++ - } - slices.Sort(v2) - for i, k2 := range v2 { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeString(k2) - e.mapElemValue() - e.e.EncodeUint(v[k2]) - } - } else { - i = 0 - for k2, v2 := range v { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeString(k2) - e.mapElemValue() - e.e.EncodeUint(v2) - i++ - } - } - e.c = 0 - e.e.WriteMapEnd() -} -func (e *encoderSimpleBytes) fastpathEncMapStringIntR(f *encFnInfo, rv reflect.Value) { - fastpathETSimpleBytes{}.EncMapStringIntV(rv2i(rv).(map[string]int), e) -} -func (fastpathETSimpleBytes) EncMapStringIntV(v map[string]int, e *encoderSimpleBytes) { - if len(v) == 0 { - e.e.WriteMapEmpty() - return - } - var i uint - e.mapStart(len(v)) - if e.h.Canonical { - v2 := make([]string, len(v)) - for k := range v { - v2[i] = k - i++ - } - slices.Sort(v2) - for i, k2 := range v2 { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeString(k2) - e.mapElemValue() - e.e.EncodeInt(int64(v[k2])) - } - } else { - i = 0 - for k2, v2 := range v { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeString(k2) - e.mapElemValue() - e.e.EncodeInt(int64(v2)) - i++ - } - } - e.c = 0 - e.e.WriteMapEnd() -} -func (e *encoderSimpleBytes) fastpathEncMapStringInt32R(f *encFnInfo, rv reflect.Value) { - fastpathETSimpleBytes{}.EncMapStringInt32V(rv2i(rv).(map[string]int32), e) -} -func (fastpathETSimpleBytes) EncMapStringInt32V(v map[string]int32, e *encoderSimpleBytes) { - if len(v) == 0 { - e.e.WriteMapEmpty() - return - } - var i uint - e.mapStart(len(v)) - if e.h.Canonical { - v2 := make([]string, len(v)) - for k := range v { - v2[i] = k - i++ - } - slices.Sort(v2) - for i, k2 := range v2 { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeString(k2) - e.mapElemValue() - e.e.EncodeInt(int64(v[k2])) - } - } else { - i = 0 - for k2, v2 := range v { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeString(k2) - e.mapElemValue() - e.e.EncodeInt(int64(v2)) - i++ - } - } - e.c = 0 - e.e.WriteMapEnd() -} -func (e *encoderSimpleBytes) fastpathEncMapStringFloat64R(f *encFnInfo, rv reflect.Value) { - fastpathETSimpleBytes{}.EncMapStringFloat64V(rv2i(rv).(map[string]float64), e) -} -func (fastpathETSimpleBytes) EncMapStringFloat64V(v map[string]float64, e *encoderSimpleBytes) { - if len(v) == 0 { - e.e.WriteMapEmpty() - return - } - var i uint - e.mapStart(len(v)) - if e.h.Canonical { - v2 := make([]string, len(v)) - for k := range v { - v2[i] = k - i++ - } - slices.Sort(v2) - for i, k2 := range v2 { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeString(k2) - e.mapElemValue() - e.e.EncodeFloat64(v[k2]) - } - } else { - i = 0 - for k2, v2 := range v { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeString(k2) - e.mapElemValue() - e.e.EncodeFloat64(v2) - i++ - } - } - e.c = 0 - e.e.WriteMapEnd() -} -func (e *encoderSimpleBytes) fastpathEncMapStringBoolR(f *encFnInfo, rv reflect.Value) { - fastpathETSimpleBytes{}.EncMapStringBoolV(rv2i(rv).(map[string]bool), e) -} -func (fastpathETSimpleBytes) EncMapStringBoolV(v map[string]bool, e *encoderSimpleBytes) { - if len(v) == 0 { - e.e.WriteMapEmpty() - return - } - var i uint - e.mapStart(len(v)) - if e.h.Canonical { - v2 := make([]string, len(v)) - for k := range v { - v2[i] = k - i++ - } - slices.Sort(v2) - for i, k2 := range v2 { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeString(k2) - e.mapElemValue() - e.e.EncodeBool(v[k2]) - } - } else { - i = 0 - for k2, v2 := range v { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeString(k2) - e.mapElemValue() - e.e.EncodeBool(v2) - i++ - } - } - e.c = 0 - e.e.WriteMapEnd() -} -func (e *encoderSimpleBytes) fastpathEncMapUint8IntfR(f *encFnInfo, rv reflect.Value) { - fastpathETSimpleBytes{}.EncMapUint8IntfV(rv2i(rv).(map[uint8]interface{}), e) -} -func (fastpathETSimpleBytes) EncMapUint8IntfV(v map[uint8]interface{}, e *encoderSimpleBytes) { - if len(v) == 0 { - e.e.WriteMapEmpty() - return - } - var i uint - e.mapStart(len(v)) - if e.h.Canonical { - v2 := make([]uint8, len(v)) - for k := range v { - v2[i] = k - i++ - } - slices.Sort(v2) - for i, k2 := range v2 { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeUint(uint64(k2)) - e.mapElemValue() - if !e.encodeBuiltin(v[k2]) { - e.encodeR(reflect.ValueOf(v[k2])) - } - } - } else { - i = 0 - for k2, v2 := range v { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeUint(uint64(k2)) - e.mapElemValue() - if !e.encodeBuiltin(v2) { - e.encodeR(reflect.ValueOf(v2)) - } - i++ - } - } - e.c = 0 - e.e.WriteMapEnd() -} -func (e *encoderSimpleBytes) fastpathEncMapUint8StringR(f *encFnInfo, rv reflect.Value) { - fastpathETSimpleBytes{}.EncMapUint8StringV(rv2i(rv).(map[uint8]string), e) -} -func (fastpathETSimpleBytes) EncMapUint8StringV(v map[uint8]string, e *encoderSimpleBytes) { - if len(v) == 0 { - e.e.WriteMapEmpty() - return - } - var i uint - e.mapStart(len(v)) - if e.h.Canonical { - v2 := make([]uint8, len(v)) - for k := range v { - v2[i] = k - i++ - } - slices.Sort(v2) - for i, k2 := range v2 { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeUint(uint64(k2)) - e.mapElemValue() - e.e.EncodeString(v[k2]) - } - } else { - i = 0 - for k2, v2 := range v { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeUint(uint64(k2)) - e.mapElemValue() - e.e.EncodeString(v2) - i++ - } - } - e.c = 0 - e.e.WriteMapEnd() -} -func (e *encoderSimpleBytes) fastpathEncMapUint8BytesR(f *encFnInfo, rv reflect.Value) { - fastpathETSimpleBytes{}.EncMapUint8BytesV(rv2i(rv).(map[uint8][]byte), e) -} -func (fastpathETSimpleBytes) EncMapUint8BytesV(v map[uint8][]byte, e *encoderSimpleBytes) { - if len(v) == 0 { - e.e.WriteMapEmpty() - return - } - var i uint - e.mapStart(len(v)) - if e.h.Canonical { - v2 := make([]uint8, len(v)) - for k := range v { - v2[i] = k - i++ - } - slices.Sort(v2) - for i, k2 := range v2 { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeUint(uint64(k2)) - e.mapElemValue() - e.e.EncodeBytes(v[k2]) - } - } else { - i = 0 - for k2, v2 := range v { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeUint(uint64(k2)) - e.mapElemValue() - e.e.EncodeBytes(v2) - i++ - } - } - e.c = 0 - e.e.WriteMapEnd() -} -func (e *encoderSimpleBytes) fastpathEncMapUint8Uint8R(f *encFnInfo, rv reflect.Value) { - fastpathETSimpleBytes{}.EncMapUint8Uint8V(rv2i(rv).(map[uint8]uint8), e) -} -func (fastpathETSimpleBytes) EncMapUint8Uint8V(v map[uint8]uint8, e *encoderSimpleBytes) { - if len(v) == 0 { - e.e.WriteMapEmpty() - return - } - var i uint - e.mapStart(len(v)) - if e.h.Canonical { - v2 := make([]uint8, len(v)) - for k := range v { - v2[i] = k - i++ - } - slices.Sort(v2) - for i, k2 := range v2 { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeUint(uint64(k2)) - e.mapElemValue() - e.e.EncodeUint(uint64(v[k2])) - } - } else { - i = 0 - for k2, v2 := range v { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeUint(uint64(k2)) - e.mapElemValue() - e.e.EncodeUint(uint64(v2)) - i++ - } - } - e.c = 0 - e.e.WriteMapEnd() -} -func (e *encoderSimpleBytes) fastpathEncMapUint8Uint64R(f *encFnInfo, rv reflect.Value) { - fastpathETSimpleBytes{}.EncMapUint8Uint64V(rv2i(rv).(map[uint8]uint64), e) -} -func (fastpathETSimpleBytes) EncMapUint8Uint64V(v map[uint8]uint64, e *encoderSimpleBytes) { - if len(v) == 0 { - e.e.WriteMapEmpty() - return - } - var i uint - e.mapStart(len(v)) - if e.h.Canonical { - v2 := make([]uint8, len(v)) - for k := range v { - v2[i] = k - i++ - } - slices.Sort(v2) - for i, k2 := range v2 { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeUint(uint64(k2)) - e.mapElemValue() - e.e.EncodeUint(v[k2]) - } - } else { - i = 0 - for k2, v2 := range v { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeUint(uint64(k2)) - e.mapElemValue() - e.e.EncodeUint(v2) - i++ - } - } - e.c = 0 - e.e.WriteMapEnd() -} -func (e *encoderSimpleBytes) fastpathEncMapUint8IntR(f *encFnInfo, rv reflect.Value) { - fastpathETSimpleBytes{}.EncMapUint8IntV(rv2i(rv).(map[uint8]int), e) -} -func (fastpathETSimpleBytes) EncMapUint8IntV(v map[uint8]int, e *encoderSimpleBytes) { - if len(v) == 0 { - e.e.WriteMapEmpty() - return - } - var i uint - e.mapStart(len(v)) - if e.h.Canonical { - v2 := make([]uint8, len(v)) - for k := range v { - v2[i] = k - i++ - } - slices.Sort(v2) - for i, k2 := range v2 { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeUint(uint64(k2)) - e.mapElemValue() - e.e.EncodeInt(int64(v[k2])) - } - } else { - i = 0 - for k2, v2 := range v { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeUint(uint64(k2)) - e.mapElemValue() - e.e.EncodeInt(int64(v2)) - i++ - } - } - e.c = 0 - e.e.WriteMapEnd() -} -func (e *encoderSimpleBytes) fastpathEncMapUint8Int32R(f *encFnInfo, rv reflect.Value) { - fastpathETSimpleBytes{}.EncMapUint8Int32V(rv2i(rv).(map[uint8]int32), e) -} -func (fastpathETSimpleBytes) EncMapUint8Int32V(v map[uint8]int32, e *encoderSimpleBytes) { - if len(v) == 0 { - e.e.WriteMapEmpty() - return - } - var i uint - e.mapStart(len(v)) - if e.h.Canonical { - v2 := make([]uint8, len(v)) - for k := range v { - v2[i] = k - i++ - } - slices.Sort(v2) - for i, k2 := range v2 { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeUint(uint64(k2)) - e.mapElemValue() - e.e.EncodeInt(int64(v[k2])) - } - } else { - i = 0 - for k2, v2 := range v { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeUint(uint64(k2)) - e.mapElemValue() - e.e.EncodeInt(int64(v2)) - i++ - } - } - e.c = 0 - e.e.WriteMapEnd() -} -func (e *encoderSimpleBytes) fastpathEncMapUint8Float64R(f *encFnInfo, rv reflect.Value) { - fastpathETSimpleBytes{}.EncMapUint8Float64V(rv2i(rv).(map[uint8]float64), e) -} -func (fastpathETSimpleBytes) EncMapUint8Float64V(v map[uint8]float64, e *encoderSimpleBytes) { - if len(v) == 0 { - e.e.WriteMapEmpty() - return - } - var i uint - e.mapStart(len(v)) - if e.h.Canonical { - v2 := make([]uint8, len(v)) - for k := range v { - v2[i] = k - i++ - } - slices.Sort(v2) - for i, k2 := range v2 { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeUint(uint64(k2)) - e.mapElemValue() - e.e.EncodeFloat64(v[k2]) - } - } else { - i = 0 - for k2, v2 := range v { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeUint(uint64(k2)) - e.mapElemValue() - e.e.EncodeFloat64(v2) - i++ - } - } - e.c = 0 - e.e.WriteMapEnd() -} -func (e *encoderSimpleBytes) fastpathEncMapUint8BoolR(f *encFnInfo, rv reflect.Value) { - fastpathETSimpleBytes{}.EncMapUint8BoolV(rv2i(rv).(map[uint8]bool), e) -} -func (fastpathETSimpleBytes) EncMapUint8BoolV(v map[uint8]bool, e *encoderSimpleBytes) { - if len(v) == 0 { - e.e.WriteMapEmpty() - return - } - var i uint - e.mapStart(len(v)) - if e.h.Canonical { - v2 := make([]uint8, len(v)) - for k := range v { - v2[i] = k - i++ - } - slices.Sort(v2) - for i, k2 := range v2 { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeUint(uint64(k2)) - e.mapElemValue() - e.e.EncodeBool(v[k2]) - } - } else { - i = 0 - for k2, v2 := range v { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeUint(uint64(k2)) - e.mapElemValue() - e.e.EncodeBool(v2) - i++ - } - } - e.c = 0 - e.e.WriteMapEnd() -} -func (e *encoderSimpleBytes) fastpathEncMapUint64IntfR(f *encFnInfo, rv reflect.Value) { - fastpathETSimpleBytes{}.EncMapUint64IntfV(rv2i(rv).(map[uint64]interface{}), e) -} -func (fastpathETSimpleBytes) EncMapUint64IntfV(v map[uint64]interface{}, e *encoderSimpleBytes) { - if len(v) == 0 { - e.e.WriteMapEmpty() - return - } - var i uint - e.mapStart(len(v)) - if e.h.Canonical { - v2 := make([]uint64, len(v)) - for k := range v { - v2[i] = k - i++ - } - slices.Sort(v2) - for i, k2 := range v2 { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeUint(k2) - e.mapElemValue() - if !e.encodeBuiltin(v[k2]) { - e.encodeR(reflect.ValueOf(v[k2])) - } - } - } else { - i = 0 - for k2, v2 := range v { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeUint(k2) - e.mapElemValue() - if !e.encodeBuiltin(v2) { - e.encodeR(reflect.ValueOf(v2)) - } - i++ - } - } - e.c = 0 - e.e.WriteMapEnd() -} -func (e *encoderSimpleBytes) fastpathEncMapUint64StringR(f *encFnInfo, rv reflect.Value) { - fastpathETSimpleBytes{}.EncMapUint64StringV(rv2i(rv).(map[uint64]string), e) -} -func (fastpathETSimpleBytes) EncMapUint64StringV(v map[uint64]string, e *encoderSimpleBytes) { - if len(v) == 0 { - e.e.WriteMapEmpty() - return - } - var i uint - e.mapStart(len(v)) - if e.h.Canonical { - v2 := make([]uint64, len(v)) - for k := range v { - v2[i] = k - i++ - } - slices.Sort(v2) - for i, k2 := range v2 { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeUint(k2) - e.mapElemValue() - e.e.EncodeString(v[k2]) - } - } else { - i = 0 - for k2, v2 := range v { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeUint(k2) - e.mapElemValue() - e.e.EncodeString(v2) - i++ - } - } - e.c = 0 - e.e.WriteMapEnd() -} -func (e *encoderSimpleBytes) fastpathEncMapUint64BytesR(f *encFnInfo, rv reflect.Value) { - fastpathETSimpleBytes{}.EncMapUint64BytesV(rv2i(rv).(map[uint64][]byte), e) -} -func (fastpathETSimpleBytes) EncMapUint64BytesV(v map[uint64][]byte, e *encoderSimpleBytes) { - if len(v) == 0 { - e.e.WriteMapEmpty() - return - } - var i uint - e.mapStart(len(v)) - if e.h.Canonical { - v2 := make([]uint64, len(v)) - for k := range v { - v2[i] = k - i++ - } - slices.Sort(v2) - for i, k2 := range v2 { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeUint(k2) - e.mapElemValue() - e.e.EncodeBytes(v[k2]) - } - } else { - i = 0 - for k2, v2 := range v { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeUint(k2) - e.mapElemValue() - e.e.EncodeBytes(v2) - i++ - } - } - e.c = 0 - e.e.WriteMapEnd() -} -func (e *encoderSimpleBytes) fastpathEncMapUint64Uint8R(f *encFnInfo, rv reflect.Value) { - fastpathETSimpleBytes{}.EncMapUint64Uint8V(rv2i(rv).(map[uint64]uint8), e) -} -func (fastpathETSimpleBytes) EncMapUint64Uint8V(v map[uint64]uint8, e *encoderSimpleBytes) { - if len(v) == 0 { - e.e.WriteMapEmpty() - return - } - var i uint - e.mapStart(len(v)) - if e.h.Canonical { - v2 := make([]uint64, len(v)) - for k := range v { - v2[i] = k - i++ - } - slices.Sort(v2) - for i, k2 := range v2 { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeUint(k2) - e.mapElemValue() - e.e.EncodeUint(uint64(v[k2])) - } - } else { - i = 0 - for k2, v2 := range v { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeUint(k2) - e.mapElemValue() - e.e.EncodeUint(uint64(v2)) - i++ - } - } - e.c = 0 - e.e.WriteMapEnd() -} -func (e *encoderSimpleBytes) fastpathEncMapUint64Uint64R(f *encFnInfo, rv reflect.Value) { - fastpathETSimpleBytes{}.EncMapUint64Uint64V(rv2i(rv).(map[uint64]uint64), e) -} -func (fastpathETSimpleBytes) EncMapUint64Uint64V(v map[uint64]uint64, e *encoderSimpleBytes) { - if len(v) == 0 { - e.e.WriteMapEmpty() - return - } - var i uint - e.mapStart(len(v)) - if e.h.Canonical { - v2 := make([]uint64, len(v)) - for k := range v { - v2[i] = k - i++ - } - slices.Sort(v2) - for i, k2 := range v2 { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeUint(k2) - e.mapElemValue() - e.e.EncodeUint(v[k2]) - } - } else { - i = 0 - for k2, v2 := range v { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeUint(k2) - e.mapElemValue() - e.e.EncodeUint(v2) - i++ - } - } - e.c = 0 - e.e.WriteMapEnd() -} -func (e *encoderSimpleBytes) fastpathEncMapUint64IntR(f *encFnInfo, rv reflect.Value) { - fastpathETSimpleBytes{}.EncMapUint64IntV(rv2i(rv).(map[uint64]int), e) -} -func (fastpathETSimpleBytes) EncMapUint64IntV(v map[uint64]int, e *encoderSimpleBytes) { - if len(v) == 0 { - e.e.WriteMapEmpty() - return - } - var i uint - e.mapStart(len(v)) - if e.h.Canonical { - v2 := make([]uint64, len(v)) - for k := range v { - v2[i] = k - i++ - } - slices.Sort(v2) - for i, k2 := range v2 { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeUint(k2) - e.mapElemValue() - e.e.EncodeInt(int64(v[k2])) - } - } else { - i = 0 - for k2, v2 := range v { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeUint(k2) - e.mapElemValue() - e.e.EncodeInt(int64(v2)) - i++ - } - } - e.c = 0 - e.e.WriteMapEnd() -} -func (e *encoderSimpleBytes) fastpathEncMapUint64Int32R(f *encFnInfo, rv reflect.Value) { - fastpathETSimpleBytes{}.EncMapUint64Int32V(rv2i(rv).(map[uint64]int32), e) -} -func (fastpathETSimpleBytes) EncMapUint64Int32V(v map[uint64]int32, e *encoderSimpleBytes) { - if len(v) == 0 { - e.e.WriteMapEmpty() - return - } - var i uint - e.mapStart(len(v)) - if e.h.Canonical { - v2 := make([]uint64, len(v)) - for k := range v { - v2[i] = k - i++ - } - slices.Sort(v2) - for i, k2 := range v2 { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeUint(k2) - e.mapElemValue() - e.e.EncodeInt(int64(v[k2])) - } - } else { - i = 0 - for k2, v2 := range v { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeUint(k2) - e.mapElemValue() - e.e.EncodeInt(int64(v2)) - i++ - } - } - e.c = 0 - e.e.WriteMapEnd() -} -func (e *encoderSimpleBytes) fastpathEncMapUint64Float64R(f *encFnInfo, rv reflect.Value) { - fastpathETSimpleBytes{}.EncMapUint64Float64V(rv2i(rv).(map[uint64]float64), e) -} -func (fastpathETSimpleBytes) EncMapUint64Float64V(v map[uint64]float64, e *encoderSimpleBytes) { - if len(v) == 0 { - e.e.WriteMapEmpty() - return - } - var i uint - e.mapStart(len(v)) - if e.h.Canonical { - v2 := make([]uint64, len(v)) - for k := range v { - v2[i] = k - i++ - } - slices.Sort(v2) - for i, k2 := range v2 { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeUint(k2) - e.mapElemValue() - e.e.EncodeFloat64(v[k2]) - } - } else { - i = 0 - for k2, v2 := range v { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeUint(k2) - e.mapElemValue() - e.e.EncodeFloat64(v2) - i++ - } - } - e.c = 0 - e.e.WriteMapEnd() -} -func (e *encoderSimpleBytes) fastpathEncMapUint64BoolR(f *encFnInfo, rv reflect.Value) { - fastpathETSimpleBytes{}.EncMapUint64BoolV(rv2i(rv).(map[uint64]bool), e) -} -func (fastpathETSimpleBytes) EncMapUint64BoolV(v map[uint64]bool, e *encoderSimpleBytes) { - if len(v) == 0 { - e.e.WriteMapEmpty() - return - } - var i uint - e.mapStart(len(v)) - if e.h.Canonical { - v2 := make([]uint64, len(v)) - for k := range v { - v2[i] = k - i++ - } - slices.Sort(v2) - for i, k2 := range v2 { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeUint(k2) - e.mapElemValue() - e.e.EncodeBool(v[k2]) - } - } else { - i = 0 - for k2, v2 := range v { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeUint(k2) - e.mapElemValue() - e.e.EncodeBool(v2) - i++ - } - } - e.c = 0 - e.e.WriteMapEnd() -} -func (e *encoderSimpleBytes) fastpathEncMapIntIntfR(f *encFnInfo, rv reflect.Value) { - fastpathETSimpleBytes{}.EncMapIntIntfV(rv2i(rv).(map[int]interface{}), e) -} -func (fastpathETSimpleBytes) EncMapIntIntfV(v map[int]interface{}, e *encoderSimpleBytes) { - if len(v) == 0 { - e.e.WriteMapEmpty() - return - } - var i uint - e.mapStart(len(v)) - if e.h.Canonical { - v2 := make([]int, len(v)) - for k := range v { - v2[i] = k - i++ - } - slices.Sort(v2) - for i, k2 := range v2 { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeInt(int64(k2)) - e.mapElemValue() - if !e.encodeBuiltin(v[k2]) { - e.encodeR(reflect.ValueOf(v[k2])) - } - } - } else { - i = 0 - for k2, v2 := range v { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeInt(int64(k2)) - e.mapElemValue() - if !e.encodeBuiltin(v2) { - e.encodeR(reflect.ValueOf(v2)) - } - i++ - } - } - e.c = 0 - e.e.WriteMapEnd() -} -func (e *encoderSimpleBytes) fastpathEncMapIntStringR(f *encFnInfo, rv reflect.Value) { - fastpathETSimpleBytes{}.EncMapIntStringV(rv2i(rv).(map[int]string), e) -} -func (fastpathETSimpleBytes) EncMapIntStringV(v map[int]string, e *encoderSimpleBytes) { - if len(v) == 0 { - e.e.WriteMapEmpty() - return - } - var i uint - e.mapStart(len(v)) - if e.h.Canonical { - v2 := make([]int, len(v)) - for k := range v { - v2[i] = k - i++ - } - slices.Sort(v2) - for i, k2 := range v2 { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeInt(int64(k2)) - e.mapElemValue() - e.e.EncodeString(v[k2]) - } - } else { - i = 0 - for k2, v2 := range v { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeInt(int64(k2)) - e.mapElemValue() - e.e.EncodeString(v2) - i++ - } - } - e.c = 0 - e.e.WriteMapEnd() -} -func (e *encoderSimpleBytes) fastpathEncMapIntBytesR(f *encFnInfo, rv reflect.Value) { - fastpathETSimpleBytes{}.EncMapIntBytesV(rv2i(rv).(map[int][]byte), e) -} -func (fastpathETSimpleBytes) EncMapIntBytesV(v map[int][]byte, e *encoderSimpleBytes) { - if len(v) == 0 { - e.e.WriteMapEmpty() - return - } - var i uint - e.mapStart(len(v)) - if e.h.Canonical { - v2 := make([]int, len(v)) - for k := range v { - v2[i] = k - i++ - } - slices.Sort(v2) - for i, k2 := range v2 { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeInt(int64(k2)) - e.mapElemValue() - e.e.EncodeBytes(v[k2]) - } - } else { - i = 0 - for k2, v2 := range v { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeInt(int64(k2)) - e.mapElemValue() - e.e.EncodeBytes(v2) - i++ - } - } - e.c = 0 - e.e.WriteMapEnd() -} -func (e *encoderSimpleBytes) fastpathEncMapIntUint8R(f *encFnInfo, rv reflect.Value) { - fastpathETSimpleBytes{}.EncMapIntUint8V(rv2i(rv).(map[int]uint8), e) -} -func (fastpathETSimpleBytes) EncMapIntUint8V(v map[int]uint8, e *encoderSimpleBytes) { - if len(v) == 0 { - e.e.WriteMapEmpty() - return - } - var i uint - e.mapStart(len(v)) - if e.h.Canonical { - v2 := make([]int, len(v)) - for k := range v { - v2[i] = k - i++ - } - slices.Sort(v2) - for i, k2 := range v2 { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeInt(int64(k2)) - e.mapElemValue() - e.e.EncodeUint(uint64(v[k2])) - } - } else { - i = 0 - for k2, v2 := range v { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeInt(int64(k2)) - e.mapElemValue() - e.e.EncodeUint(uint64(v2)) - i++ - } - } - e.c = 0 - e.e.WriteMapEnd() -} -func (e *encoderSimpleBytes) fastpathEncMapIntUint64R(f *encFnInfo, rv reflect.Value) { - fastpathETSimpleBytes{}.EncMapIntUint64V(rv2i(rv).(map[int]uint64), e) -} -func (fastpathETSimpleBytes) EncMapIntUint64V(v map[int]uint64, e *encoderSimpleBytes) { - if len(v) == 0 { - e.e.WriteMapEmpty() - return - } - var i uint - e.mapStart(len(v)) - if e.h.Canonical { - v2 := make([]int, len(v)) - for k := range v { - v2[i] = k - i++ - } - slices.Sort(v2) - for i, k2 := range v2 { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeInt(int64(k2)) - e.mapElemValue() - e.e.EncodeUint(v[k2]) - } - } else { - i = 0 - for k2, v2 := range v { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeInt(int64(k2)) - e.mapElemValue() - e.e.EncodeUint(v2) - i++ - } - } - e.c = 0 - e.e.WriteMapEnd() -} -func (e *encoderSimpleBytes) fastpathEncMapIntIntR(f *encFnInfo, rv reflect.Value) { - fastpathETSimpleBytes{}.EncMapIntIntV(rv2i(rv).(map[int]int), e) -} -func (fastpathETSimpleBytes) EncMapIntIntV(v map[int]int, e *encoderSimpleBytes) { - if len(v) == 0 { - e.e.WriteMapEmpty() - return - } - var i uint - e.mapStart(len(v)) - if e.h.Canonical { - v2 := make([]int, len(v)) - for k := range v { - v2[i] = k - i++ - } - slices.Sort(v2) - for i, k2 := range v2 { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeInt(int64(k2)) - e.mapElemValue() - e.e.EncodeInt(int64(v[k2])) - } - } else { - i = 0 - for k2, v2 := range v { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeInt(int64(k2)) - e.mapElemValue() - e.e.EncodeInt(int64(v2)) - i++ - } - } - e.c = 0 - e.e.WriteMapEnd() -} -func (e *encoderSimpleBytes) fastpathEncMapIntInt32R(f *encFnInfo, rv reflect.Value) { - fastpathETSimpleBytes{}.EncMapIntInt32V(rv2i(rv).(map[int]int32), e) -} -func (fastpathETSimpleBytes) EncMapIntInt32V(v map[int]int32, e *encoderSimpleBytes) { - if len(v) == 0 { - e.e.WriteMapEmpty() - return - } - var i uint - e.mapStart(len(v)) - if e.h.Canonical { - v2 := make([]int, len(v)) - for k := range v { - v2[i] = k - i++ - } - slices.Sort(v2) - for i, k2 := range v2 { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeInt(int64(k2)) - e.mapElemValue() - e.e.EncodeInt(int64(v[k2])) - } - } else { - i = 0 - for k2, v2 := range v { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeInt(int64(k2)) - e.mapElemValue() - e.e.EncodeInt(int64(v2)) - i++ - } - } - e.c = 0 - e.e.WriteMapEnd() -} -func (e *encoderSimpleBytes) fastpathEncMapIntFloat64R(f *encFnInfo, rv reflect.Value) { - fastpathETSimpleBytes{}.EncMapIntFloat64V(rv2i(rv).(map[int]float64), e) -} -func (fastpathETSimpleBytes) EncMapIntFloat64V(v map[int]float64, e *encoderSimpleBytes) { - if len(v) == 0 { - e.e.WriteMapEmpty() - return - } - var i uint - e.mapStart(len(v)) - if e.h.Canonical { - v2 := make([]int, len(v)) - for k := range v { - v2[i] = k - i++ - } - slices.Sort(v2) - for i, k2 := range v2 { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeInt(int64(k2)) - e.mapElemValue() - e.e.EncodeFloat64(v[k2]) - } - } else { - i = 0 - for k2, v2 := range v { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeInt(int64(k2)) - e.mapElemValue() - e.e.EncodeFloat64(v2) - i++ - } - } - e.c = 0 - e.e.WriteMapEnd() -} -func (e *encoderSimpleBytes) fastpathEncMapIntBoolR(f *encFnInfo, rv reflect.Value) { - fastpathETSimpleBytes{}.EncMapIntBoolV(rv2i(rv).(map[int]bool), e) -} -func (fastpathETSimpleBytes) EncMapIntBoolV(v map[int]bool, e *encoderSimpleBytes) { - if len(v) == 0 { - e.e.WriteMapEmpty() - return - } - var i uint - e.mapStart(len(v)) - if e.h.Canonical { - v2 := make([]int, len(v)) - for k := range v { - v2[i] = k - i++ - } - slices.Sort(v2) - for i, k2 := range v2 { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeInt(int64(k2)) - e.mapElemValue() - e.e.EncodeBool(v[k2]) - } - } else { - i = 0 - for k2, v2 := range v { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeInt(int64(k2)) - e.mapElemValue() - e.e.EncodeBool(v2) - i++ - } - } - e.c = 0 - e.e.WriteMapEnd() -} -func (e *encoderSimpleBytes) fastpathEncMapInt32IntfR(f *encFnInfo, rv reflect.Value) { - fastpathETSimpleBytes{}.EncMapInt32IntfV(rv2i(rv).(map[int32]interface{}), e) -} -func (fastpathETSimpleBytes) EncMapInt32IntfV(v map[int32]interface{}, e *encoderSimpleBytes) { - if len(v) == 0 { - e.e.WriteMapEmpty() - return - } - var i uint - e.mapStart(len(v)) - if e.h.Canonical { - v2 := make([]int32, len(v)) - for k := range v { - v2[i] = k - i++ - } - slices.Sort(v2) - for i, k2 := range v2 { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeInt(int64(k2)) - e.mapElemValue() - if !e.encodeBuiltin(v[k2]) { - e.encodeR(reflect.ValueOf(v[k2])) - } - } - } else { - i = 0 - for k2, v2 := range v { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeInt(int64(k2)) - e.mapElemValue() - if !e.encodeBuiltin(v2) { - e.encodeR(reflect.ValueOf(v2)) - } - i++ - } - } - e.c = 0 - e.e.WriteMapEnd() -} -func (e *encoderSimpleBytes) fastpathEncMapInt32StringR(f *encFnInfo, rv reflect.Value) { - fastpathETSimpleBytes{}.EncMapInt32StringV(rv2i(rv).(map[int32]string), e) -} -func (fastpathETSimpleBytes) EncMapInt32StringV(v map[int32]string, e *encoderSimpleBytes) { - if len(v) == 0 { - e.e.WriteMapEmpty() - return - } - var i uint - e.mapStart(len(v)) - if e.h.Canonical { - v2 := make([]int32, len(v)) - for k := range v { - v2[i] = k - i++ - } - slices.Sort(v2) - for i, k2 := range v2 { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeInt(int64(k2)) - e.mapElemValue() - e.e.EncodeString(v[k2]) - } - } else { - i = 0 - for k2, v2 := range v { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeInt(int64(k2)) - e.mapElemValue() - e.e.EncodeString(v2) - i++ - } - } - e.c = 0 - e.e.WriteMapEnd() -} -func (e *encoderSimpleBytes) fastpathEncMapInt32BytesR(f *encFnInfo, rv reflect.Value) { - fastpathETSimpleBytes{}.EncMapInt32BytesV(rv2i(rv).(map[int32][]byte), e) -} -func (fastpathETSimpleBytes) EncMapInt32BytesV(v map[int32][]byte, e *encoderSimpleBytes) { - if len(v) == 0 { - e.e.WriteMapEmpty() - return - } - var i uint - e.mapStart(len(v)) - if e.h.Canonical { - v2 := make([]int32, len(v)) - for k := range v { - v2[i] = k - i++ - } - slices.Sort(v2) - for i, k2 := range v2 { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeInt(int64(k2)) - e.mapElemValue() - e.e.EncodeBytes(v[k2]) - } - } else { - i = 0 - for k2, v2 := range v { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeInt(int64(k2)) - e.mapElemValue() - e.e.EncodeBytes(v2) - i++ - } - } - e.c = 0 - e.e.WriteMapEnd() -} -func (e *encoderSimpleBytes) fastpathEncMapInt32Uint8R(f *encFnInfo, rv reflect.Value) { - fastpathETSimpleBytes{}.EncMapInt32Uint8V(rv2i(rv).(map[int32]uint8), e) -} -func (fastpathETSimpleBytes) EncMapInt32Uint8V(v map[int32]uint8, e *encoderSimpleBytes) { - if len(v) == 0 { - e.e.WriteMapEmpty() - return - } - var i uint - e.mapStart(len(v)) - if e.h.Canonical { - v2 := make([]int32, len(v)) - for k := range v { - v2[i] = k - i++ - } - slices.Sort(v2) - for i, k2 := range v2 { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeInt(int64(k2)) - e.mapElemValue() - e.e.EncodeUint(uint64(v[k2])) - } - } else { - i = 0 - for k2, v2 := range v { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeInt(int64(k2)) - e.mapElemValue() - e.e.EncodeUint(uint64(v2)) - i++ - } - } - e.c = 0 - e.e.WriteMapEnd() -} -func (e *encoderSimpleBytes) fastpathEncMapInt32Uint64R(f *encFnInfo, rv reflect.Value) { - fastpathETSimpleBytes{}.EncMapInt32Uint64V(rv2i(rv).(map[int32]uint64), e) -} -func (fastpathETSimpleBytes) EncMapInt32Uint64V(v map[int32]uint64, e *encoderSimpleBytes) { - if len(v) == 0 { - e.e.WriteMapEmpty() - return - } - var i uint - e.mapStart(len(v)) - if e.h.Canonical { - v2 := make([]int32, len(v)) - for k := range v { - v2[i] = k - i++ - } - slices.Sort(v2) - for i, k2 := range v2 { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeInt(int64(k2)) - e.mapElemValue() - e.e.EncodeUint(v[k2]) - } - } else { - i = 0 - for k2, v2 := range v { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeInt(int64(k2)) - e.mapElemValue() - e.e.EncodeUint(v2) - i++ - } - } - e.c = 0 - e.e.WriteMapEnd() -} -func (e *encoderSimpleBytes) fastpathEncMapInt32IntR(f *encFnInfo, rv reflect.Value) { - fastpathETSimpleBytes{}.EncMapInt32IntV(rv2i(rv).(map[int32]int), e) -} -func (fastpathETSimpleBytes) EncMapInt32IntV(v map[int32]int, e *encoderSimpleBytes) { - if len(v) == 0 { - e.e.WriteMapEmpty() - return - } - var i uint - e.mapStart(len(v)) - if e.h.Canonical { - v2 := make([]int32, len(v)) - for k := range v { - v2[i] = k - i++ - } - slices.Sort(v2) - for i, k2 := range v2 { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeInt(int64(k2)) - e.mapElemValue() - e.e.EncodeInt(int64(v[k2])) - } - } else { - i = 0 - for k2, v2 := range v { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeInt(int64(k2)) - e.mapElemValue() - e.e.EncodeInt(int64(v2)) - i++ - } - } - e.c = 0 - e.e.WriteMapEnd() -} -func (e *encoderSimpleBytes) fastpathEncMapInt32Int32R(f *encFnInfo, rv reflect.Value) { - fastpathETSimpleBytes{}.EncMapInt32Int32V(rv2i(rv).(map[int32]int32), e) -} -func (fastpathETSimpleBytes) EncMapInt32Int32V(v map[int32]int32, e *encoderSimpleBytes) { - if len(v) == 0 { - e.e.WriteMapEmpty() - return - } - var i uint - e.mapStart(len(v)) - if e.h.Canonical { - v2 := make([]int32, len(v)) - for k := range v { - v2[i] = k - i++ - } - slices.Sort(v2) - for i, k2 := range v2 { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeInt(int64(k2)) - e.mapElemValue() - e.e.EncodeInt(int64(v[k2])) - } - } else { - i = 0 - for k2, v2 := range v { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeInt(int64(k2)) - e.mapElemValue() - e.e.EncodeInt(int64(v2)) - i++ - } - } - e.c = 0 - e.e.WriteMapEnd() -} -func (e *encoderSimpleBytes) fastpathEncMapInt32Float64R(f *encFnInfo, rv reflect.Value) { - fastpathETSimpleBytes{}.EncMapInt32Float64V(rv2i(rv).(map[int32]float64), e) -} -func (fastpathETSimpleBytes) EncMapInt32Float64V(v map[int32]float64, e *encoderSimpleBytes) { - if len(v) == 0 { - e.e.WriteMapEmpty() - return - } - var i uint - e.mapStart(len(v)) - if e.h.Canonical { - v2 := make([]int32, len(v)) - for k := range v { - v2[i] = k - i++ - } - slices.Sort(v2) - for i, k2 := range v2 { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeInt(int64(k2)) - e.mapElemValue() - e.e.EncodeFloat64(v[k2]) - } - } else { - i = 0 - for k2, v2 := range v { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeInt(int64(k2)) - e.mapElemValue() - e.e.EncodeFloat64(v2) - i++ - } - } - e.c = 0 - e.e.WriteMapEnd() -} -func (e *encoderSimpleBytes) fastpathEncMapInt32BoolR(f *encFnInfo, rv reflect.Value) { - fastpathETSimpleBytes{}.EncMapInt32BoolV(rv2i(rv).(map[int32]bool), e) -} -func (fastpathETSimpleBytes) EncMapInt32BoolV(v map[int32]bool, e *encoderSimpleBytes) { - if len(v) == 0 { - e.e.WriteMapEmpty() - return - } - var i uint - e.mapStart(len(v)) - if e.h.Canonical { - v2 := make([]int32, len(v)) - for k := range v { - v2[i] = k - i++ - } - slices.Sort(v2) - for i, k2 := range v2 { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeInt(int64(k2)) - e.mapElemValue() - e.e.EncodeBool(v[k2]) - } - } else { - i = 0 - for k2, v2 := range v { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeInt(int64(k2)) - e.mapElemValue() - e.e.EncodeBool(v2) - i++ - } - } - e.c = 0 - e.e.WriteMapEnd() -} - -func (helperDecDriverSimpleBytes) fastpathDecodeTypeSwitch(iv interface{}, d *decoderSimpleBytes) bool { - var ft fastpathDTSimpleBytes - var changed bool - var containerLen int - switch v := iv.(type) { - case []interface{}: - ft.DecSliceIntfN(v, d) - case *[]interface{}: - var v2 []interface{} - if v2, changed = ft.DecSliceIntfY(*v, d); changed { - *v = v2 - } - case []string: - ft.DecSliceStringN(v, d) - case *[]string: - var v2 []string - if v2, changed = ft.DecSliceStringY(*v, d); changed { - *v = v2 - } - case [][]byte: - ft.DecSliceBytesN(v, d) - case *[][]byte: - var v2 [][]byte - if v2, changed = ft.DecSliceBytesY(*v, d); changed { - *v = v2 - } - case []float32: - ft.DecSliceFloat32N(v, d) - case *[]float32: - var v2 []float32 - if v2, changed = ft.DecSliceFloat32Y(*v, d); changed { - *v = v2 - } - case []float64: - ft.DecSliceFloat64N(v, d) - case *[]float64: - var v2 []float64 - if v2, changed = ft.DecSliceFloat64Y(*v, d); changed { - *v = v2 - } - case []uint8: - ft.DecSliceUint8N(v, d) - case *[]uint8: - var v2 []uint8 - if v2, changed = ft.DecSliceUint8Y(*v, d); changed { - *v = v2 - } - case []uint64: - ft.DecSliceUint64N(v, d) - case *[]uint64: - var v2 []uint64 - if v2, changed = ft.DecSliceUint64Y(*v, d); changed { - *v = v2 - } - case []int: - ft.DecSliceIntN(v, d) - case *[]int: - var v2 []int - if v2, changed = ft.DecSliceIntY(*v, d); changed { - *v = v2 - } - case []int32: - ft.DecSliceInt32N(v, d) - case *[]int32: - var v2 []int32 - if v2, changed = ft.DecSliceInt32Y(*v, d); changed { - *v = v2 - } - case []int64: - ft.DecSliceInt64N(v, d) - case *[]int64: - var v2 []int64 - if v2, changed = ft.DecSliceInt64Y(*v, d); changed { - *v = v2 - } - case []bool: - ft.DecSliceBoolN(v, d) - case *[]bool: - var v2 []bool - if v2, changed = ft.DecSliceBoolY(*v, d); changed { - *v = v2 - } - case map[string]interface{}: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen != containerLenNil { - if containerLen != 0 { - ft.DecMapStringIntfL(v, containerLen, d) - } - d.mapEnd() - } - case *map[string]interface{}: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen == containerLenNil { - *v = nil - } else { - if *v == nil { - *v = make(map[string]interface{}, decInferLen(containerLen, d.maxInitLen(), 32)) - } - if containerLen != 0 { - ft.DecMapStringIntfL(*v, containerLen, d) - } - d.mapEnd() - } - case map[string]string: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen != containerLenNil { - if containerLen != 0 { - ft.DecMapStringStringL(v, containerLen, d) - } - d.mapEnd() - } - case *map[string]string: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen == containerLenNil { - *v = nil - } else { - if *v == nil { - *v = make(map[string]string, decInferLen(containerLen, d.maxInitLen(), 32)) - } - if containerLen != 0 { - ft.DecMapStringStringL(*v, containerLen, d) - } - d.mapEnd() - } - case map[string][]byte: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen != containerLenNil { - if containerLen != 0 { - ft.DecMapStringBytesL(v, containerLen, d) - } - d.mapEnd() - } - case *map[string][]byte: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen == containerLenNil { - *v = nil - } else { - if *v == nil { - *v = make(map[string][]byte, decInferLen(containerLen, d.maxInitLen(), 40)) - } - if containerLen != 0 { - ft.DecMapStringBytesL(*v, containerLen, d) - } - d.mapEnd() - } - case map[string]uint8: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen != containerLenNil { - if containerLen != 0 { - ft.DecMapStringUint8L(v, containerLen, d) - } - d.mapEnd() - } - case *map[string]uint8: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen == containerLenNil { - *v = nil - } else { - if *v == nil { - *v = make(map[string]uint8, decInferLen(containerLen, d.maxInitLen(), 17)) - } - if containerLen != 0 { - ft.DecMapStringUint8L(*v, containerLen, d) - } - d.mapEnd() - } - case map[string]uint64: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen != containerLenNil { - if containerLen != 0 { - ft.DecMapStringUint64L(v, containerLen, d) - } - d.mapEnd() - } - case *map[string]uint64: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen == containerLenNil { - *v = nil - } else { - if *v == nil { - *v = make(map[string]uint64, decInferLen(containerLen, d.maxInitLen(), 24)) - } - if containerLen != 0 { - ft.DecMapStringUint64L(*v, containerLen, d) - } - d.mapEnd() - } - case map[string]int: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen != containerLenNil { - if containerLen != 0 { - ft.DecMapStringIntL(v, containerLen, d) - } - d.mapEnd() - } - case *map[string]int: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen == containerLenNil { - *v = nil - } else { - if *v == nil { - *v = make(map[string]int, decInferLen(containerLen, d.maxInitLen(), 24)) - } - if containerLen != 0 { - ft.DecMapStringIntL(*v, containerLen, d) - } - d.mapEnd() - } - case map[string]int32: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen != containerLenNil { - if containerLen != 0 { - ft.DecMapStringInt32L(v, containerLen, d) - } - d.mapEnd() - } - case *map[string]int32: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen == containerLenNil { - *v = nil - } else { - if *v == nil { - *v = make(map[string]int32, decInferLen(containerLen, d.maxInitLen(), 20)) - } - if containerLen != 0 { - ft.DecMapStringInt32L(*v, containerLen, d) - } - d.mapEnd() - } - case map[string]float64: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen != containerLenNil { - if containerLen != 0 { - ft.DecMapStringFloat64L(v, containerLen, d) - } - d.mapEnd() - } - case *map[string]float64: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen == containerLenNil { - *v = nil - } else { - if *v == nil { - *v = make(map[string]float64, decInferLen(containerLen, d.maxInitLen(), 24)) - } - if containerLen != 0 { - ft.DecMapStringFloat64L(*v, containerLen, d) - } - d.mapEnd() - } - case map[string]bool: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen != containerLenNil { - if containerLen != 0 { - ft.DecMapStringBoolL(v, containerLen, d) - } - d.mapEnd() - } - case *map[string]bool: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen == containerLenNil { - *v = nil - } else { - if *v == nil { - *v = make(map[string]bool, decInferLen(containerLen, d.maxInitLen(), 17)) - } - if containerLen != 0 { - ft.DecMapStringBoolL(*v, containerLen, d) - } - d.mapEnd() - } - case map[uint8]interface{}: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen != containerLenNil { - if containerLen != 0 { - ft.DecMapUint8IntfL(v, containerLen, d) - } - d.mapEnd() - } - case *map[uint8]interface{}: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen == containerLenNil { - *v = nil - } else { - if *v == nil { - *v = make(map[uint8]interface{}, decInferLen(containerLen, d.maxInitLen(), 17)) - } - if containerLen != 0 { - ft.DecMapUint8IntfL(*v, containerLen, d) - } - d.mapEnd() - } - case map[uint8]string: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen != containerLenNil { - if containerLen != 0 { - ft.DecMapUint8StringL(v, containerLen, d) - } - d.mapEnd() - } - case *map[uint8]string: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen == containerLenNil { - *v = nil - } else { - if *v == nil { - *v = make(map[uint8]string, decInferLen(containerLen, d.maxInitLen(), 17)) - } - if containerLen != 0 { - ft.DecMapUint8StringL(*v, containerLen, d) - } - d.mapEnd() - } - case map[uint8][]byte: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen != containerLenNil { - if containerLen != 0 { - ft.DecMapUint8BytesL(v, containerLen, d) - } - d.mapEnd() - } - case *map[uint8][]byte: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen == containerLenNil { - *v = nil - } else { - if *v == nil { - *v = make(map[uint8][]byte, decInferLen(containerLen, d.maxInitLen(), 25)) - } - if containerLen != 0 { - ft.DecMapUint8BytesL(*v, containerLen, d) - } - d.mapEnd() - } - case map[uint8]uint8: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen != containerLenNil { - if containerLen != 0 { - ft.DecMapUint8Uint8L(v, containerLen, d) - } - d.mapEnd() - } - case *map[uint8]uint8: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen == containerLenNil { - *v = nil - } else { - if *v == nil { - *v = make(map[uint8]uint8, decInferLen(containerLen, d.maxInitLen(), 2)) - } - if containerLen != 0 { - ft.DecMapUint8Uint8L(*v, containerLen, d) - } - d.mapEnd() - } - case map[uint8]uint64: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen != containerLenNil { - if containerLen != 0 { - ft.DecMapUint8Uint64L(v, containerLen, d) - } - d.mapEnd() - } - case *map[uint8]uint64: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen == containerLenNil { - *v = nil - } else { - if *v == nil { - *v = make(map[uint8]uint64, decInferLen(containerLen, d.maxInitLen(), 9)) - } - if containerLen != 0 { - ft.DecMapUint8Uint64L(*v, containerLen, d) - } - d.mapEnd() - } - case map[uint8]int: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen != containerLenNil { - if containerLen != 0 { - ft.DecMapUint8IntL(v, containerLen, d) - } - d.mapEnd() - } - case *map[uint8]int: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen == containerLenNil { - *v = nil - } else { - if *v == nil { - *v = make(map[uint8]int, decInferLen(containerLen, d.maxInitLen(), 9)) - } - if containerLen != 0 { - ft.DecMapUint8IntL(*v, containerLen, d) - } - d.mapEnd() - } - case map[uint8]int32: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen != containerLenNil { - if containerLen != 0 { - ft.DecMapUint8Int32L(v, containerLen, d) - } - d.mapEnd() - } - case *map[uint8]int32: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen == containerLenNil { - *v = nil - } else { - if *v == nil { - *v = make(map[uint8]int32, decInferLen(containerLen, d.maxInitLen(), 5)) - } - if containerLen != 0 { - ft.DecMapUint8Int32L(*v, containerLen, d) - } - d.mapEnd() - } - case map[uint8]float64: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen != containerLenNil { - if containerLen != 0 { - ft.DecMapUint8Float64L(v, containerLen, d) - } - d.mapEnd() - } - case *map[uint8]float64: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen == containerLenNil { - *v = nil - } else { - if *v == nil { - *v = make(map[uint8]float64, decInferLen(containerLen, d.maxInitLen(), 9)) - } - if containerLen != 0 { - ft.DecMapUint8Float64L(*v, containerLen, d) - } - d.mapEnd() - } - case map[uint8]bool: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen != containerLenNil { - if containerLen != 0 { - ft.DecMapUint8BoolL(v, containerLen, d) - } - d.mapEnd() - } - case *map[uint8]bool: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen == containerLenNil { - *v = nil - } else { - if *v == nil { - *v = make(map[uint8]bool, decInferLen(containerLen, d.maxInitLen(), 2)) - } - if containerLen != 0 { - ft.DecMapUint8BoolL(*v, containerLen, d) - } - d.mapEnd() - } - case map[uint64]interface{}: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen != containerLenNil { - if containerLen != 0 { - ft.DecMapUint64IntfL(v, containerLen, d) - } - d.mapEnd() - } - case *map[uint64]interface{}: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen == containerLenNil { - *v = nil - } else { - if *v == nil { - *v = make(map[uint64]interface{}, decInferLen(containerLen, d.maxInitLen(), 24)) - } - if containerLen != 0 { - ft.DecMapUint64IntfL(*v, containerLen, d) - } - d.mapEnd() - } - case map[uint64]string: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen != containerLenNil { - if containerLen != 0 { - ft.DecMapUint64StringL(v, containerLen, d) - } - d.mapEnd() - } - case *map[uint64]string: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen == containerLenNil { - *v = nil - } else { - if *v == nil { - *v = make(map[uint64]string, decInferLen(containerLen, d.maxInitLen(), 24)) - } - if containerLen != 0 { - ft.DecMapUint64StringL(*v, containerLen, d) - } - d.mapEnd() - } - case map[uint64][]byte: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen != containerLenNil { - if containerLen != 0 { - ft.DecMapUint64BytesL(v, containerLen, d) - } - d.mapEnd() - } - case *map[uint64][]byte: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen == containerLenNil { - *v = nil - } else { - if *v == nil { - *v = make(map[uint64][]byte, decInferLen(containerLen, d.maxInitLen(), 32)) - } - if containerLen != 0 { - ft.DecMapUint64BytesL(*v, containerLen, d) - } - d.mapEnd() - } - case map[uint64]uint8: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen != containerLenNil { - if containerLen != 0 { - ft.DecMapUint64Uint8L(v, containerLen, d) - } - d.mapEnd() - } - case *map[uint64]uint8: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen == containerLenNil { - *v = nil - } else { - if *v == nil { - *v = make(map[uint64]uint8, decInferLen(containerLen, d.maxInitLen(), 9)) - } - if containerLen != 0 { - ft.DecMapUint64Uint8L(*v, containerLen, d) - } - d.mapEnd() - } - case map[uint64]uint64: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen != containerLenNil { - if containerLen != 0 { - ft.DecMapUint64Uint64L(v, containerLen, d) - } - d.mapEnd() - } - case *map[uint64]uint64: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen == containerLenNil { - *v = nil - } else { - if *v == nil { - *v = make(map[uint64]uint64, decInferLen(containerLen, d.maxInitLen(), 16)) - } - if containerLen != 0 { - ft.DecMapUint64Uint64L(*v, containerLen, d) - } - d.mapEnd() - } - case map[uint64]int: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen != containerLenNil { - if containerLen != 0 { - ft.DecMapUint64IntL(v, containerLen, d) - } - d.mapEnd() - } - case *map[uint64]int: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen == containerLenNil { - *v = nil - } else { - if *v == nil { - *v = make(map[uint64]int, decInferLen(containerLen, d.maxInitLen(), 16)) - } - if containerLen != 0 { - ft.DecMapUint64IntL(*v, containerLen, d) - } - d.mapEnd() - } - case map[uint64]int32: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen != containerLenNil { - if containerLen != 0 { - ft.DecMapUint64Int32L(v, containerLen, d) - } - d.mapEnd() - } - case *map[uint64]int32: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen == containerLenNil { - *v = nil - } else { - if *v == nil { - *v = make(map[uint64]int32, decInferLen(containerLen, d.maxInitLen(), 12)) - } - if containerLen != 0 { - ft.DecMapUint64Int32L(*v, containerLen, d) - } - d.mapEnd() - } - case map[uint64]float64: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen != containerLenNil { - if containerLen != 0 { - ft.DecMapUint64Float64L(v, containerLen, d) - } - d.mapEnd() - } - case *map[uint64]float64: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen == containerLenNil { - *v = nil - } else { - if *v == nil { - *v = make(map[uint64]float64, decInferLen(containerLen, d.maxInitLen(), 16)) - } - if containerLen != 0 { - ft.DecMapUint64Float64L(*v, containerLen, d) - } - d.mapEnd() - } - case map[uint64]bool: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen != containerLenNil { - if containerLen != 0 { - ft.DecMapUint64BoolL(v, containerLen, d) - } - d.mapEnd() - } - case *map[uint64]bool: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen == containerLenNil { - *v = nil - } else { - if *v == nil { - *v = make(map[uint64]bool, decInferLen(containerLen, d.maxInitLen(), 9)) - } - if containerLen != 0 { - ft.DecMapUint64BoolL(*v, containerLen, d) - } - d.mapEnd() - } - case map[int]interface{}: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen != containerLenNil { - if containerLen != 0 { - ft.DecMapIntIntfL(v, containerLen, d) - } - d.mapEnd() - } - case *map[int]interface{}: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen == containerLenNil { - *v = nil - } else { - if *v == nil { - *v = make(map[int]interface{}, decInferLen(containerLen, d.maxInitLen(), 24)) - } - if containerLen != 0 { - ft.DecMapIntIntfL(*v, containerLen, d) - } - d.mapEnd() - } - case map[int]string: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen != containerLenNil { - if containerLen != 0 { - ft.DecMapIntStringL(v, containerLen, d) - } - d.mapEnd() - } - case *map[int]string: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen == containerLenNil { - *v = nil - } else { - if *v == nil { - *v = make(map[int]string, decInferLen(containerLen, d.maxInitLen(), 24)) - } - if containerLen != 0 { - ft.DecMapIntStringL(*v, containerLen, d) - } - d.mapEnd() - } - case map[int][]byte: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen != containerLenNil { - if containerLen != 0 { - ft.DecMapIntBytesL(v, containerLen, d) - } - d.mapEnd() - } - case *map[int][]byte: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen == containerLenNil { - *v = nil - } else { - if *v == nil { - *v = make(map[int][]byte, decInferLen(containerLen, d.maxInitLen(), 32)) - } - if containerLen != 0 { - ft.DecMapIntBytesL(*v, containerLen, d) - } - d.mapEnd() - } - case map[int]uint8: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen != containerLenNil { - if containerLen != 0 { - ft.DecMapIntUint8L(v, containerLen, d) - } - d.mapEnd() - } - case *map[int]uint8: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen == containerLenNil { - *v = nil - } else { - if *v == nil { - *v = make(map[int]uint8, decInferLen(containerLen, d.maxInitLen(), 9)) - } - if containerLen != 0 { - ft.DecMapIntUint8L(*v, containerLen, d) - } - d.mapEnd() - } - case map[int]uint64: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen != containerLenNil { - if containerLen != 0 { - ft.DecMapIntUint64L(v, containerLen, d) - } - d.mapEnd() - } - case *map[int]uint64: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen == containerLenNil { - *v = nil - } else { - if *v == nil { - *v = make(map[int]uint64, decInferLen(containerLen, d.maxInitLen(), 16)) - } - if containerLen != 0 { - ft.DecMapIntUint64L(*v, containerLen, d) - } - d.mapEnd() - } - case map[int]int: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen != containerLenNil { - if containerLen != 0 { - ft.DecMapIntIntL(v, containerLen, d) - } - d.mapEnd() - } - case *map[int]int: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen == containerLenNil { - *v = nil - } else { - if *v == nil { - *v = make(map[int]int, decInferLen(containerLen, d.maxInitLen(), 16)) - } - if containerLen != 0 { - ft.DecMapIntIntL(*v, containerLen, d) - } - d.mapEnd() - } - case map[int]int32: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen != containerLenNil { - if containerLen != 0 { - ft.DecMapIntInt32L(v, containerLen, d) - } - d.mapEnd() - } - case *map[int]int32: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen == containerLenNil { - *v = nil - } else { - if *v == nil { - *v = make(map[int]int32, decInferLen(containerLen, d.maxInitLen(), 12)) - } - if containerLen != 0 { - ft.DecMapIntInt32L(*v, containerLen, d) - } - d.mapEnd() - } - case map[int]float64: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen != containerLenNil { - if containerLen != 0 { - ft.DecMapIntFloat64L(v, containerLen, d) - } - d.mapEnd() - } - case *map[int]float64: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen == containerLenNil { - *v = nil - } else { - if *v == nil { - *v = make(map[int]float64, decInferLen(containerLen, d.maxInitLen(), 16)) - } - if containerLen != 0 { - ft.DecMapIntFloat64L(*v, containerLen, d) - } - d.mapEnd() - } - case map[int]bool: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen != containerLenNil { - if containerLen != 0 { - ft.DecMapIntBoolL(v, containerLen, d) - } - d.mapEnd() - } - case *map[int]bool: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen == containerLenNil { - *v = nil - } else { - if *v == nil { - *v = make(map[int]bool, decInferLen(containerLen, d.maxInitLen(), 9)) - } - if containerLen != 0 { - ft.DecMapIntBoolL(*v, containerLen, d) - } - d.mapEnd() - } - case map[int32]interface{}: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen != containerLenNil { - if containerLen != 0 { - ft.DecMapInt32IntfL(v, containerLen, d) - } - d.mapEnd() - } - case *map[int32]interface{}: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen == containerLenNil { - *v = nil - } else { - if *v == nil { - *v = make(map[int32]interface{}, decInferLen(containerLen, d.maxInitLen(), 20)) - } - if containerLen != 0 { - ft.DecMapInt32IntfL(*v, containerLen, d) - } - d.mapEnd() - } - case map[int32]string: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen != containerLenNil { - if containerLen != 0 { - ft.DecMapInt32StringL(v, containerLen, d) - } - d.mapEnd() - } - case *map[int32]string: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen == containerLenNil { - *v = nil - } else { - if *v == nil { - *v = make(map[int32]string, decInferLen(containerLen, d.maxInitLen(), 20)) - } - if containerLen != 0 { - ft.DecMapInt32StringL(*v, containerLen, d) - } - d.mapEnd() - } - case map[int32][]byte: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen != containerLenNil { - if containerLen != 0 { - ft.DecMapInt32BytesL(v, containerLen, d) - } - d.mapEnd() - } - case *map[int32][]byte: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen == containerLenNil { - *v = nil - } else { - if *v == nil { - *v = make(map[int32][]byte, decInferLen(containerLen, d.maxInitLen(), 28)) - } - if containerLen != 0 { - ft.DecMapInt32BytesL(*v, containerLen, d) - } - d.mapEnd() - } - case map[int32]uint8: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen != containerLenNil { - if containerLen != 0 { - ft.DecMapInt32Uint8L(v, containerLen, d) - } - d.mapEnd() - } - case *map[int32]uint8: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen == containerLenNil { - *v = nil - } else { - if *v == nil { - *v = make(map[int32]uint8, decInferLen(containerLen, d.maxInitLen(), 5)) - } - if containerLen != 0 { - ft.DecMapInt32Uint8L(*v, containerLen, d) - } - d.mapEnd() - } - case map[int32]uint64: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen != containerLenNil { - if containerLen != 0 { - ft.DecMapInt32Uint64L(v, containerLen, d) - } - d.mapEnd() - } - case *map[int32]uint64: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen == containerLenNil { - *v = nil - } else { - if *v == nil { - *v = make(map[int32]uint64, decInferLen(containerLen, d.maxInitLen(), 12)) - } - if containerLen != 0 { - ft.DecMapInt32Uint64L(*v, containerLen, d) - } - d.mapEnd() - } - case map[int32]int: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen != containerLenNil { - if containerLen != 0 { - ft.DecMapInt32IntL(v, containerLen, d) - } - d.mapEnd() - } - case *map[int32]int: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen == containerLenNil { - *v = nil - } else { - if *v == nil { - *v = make(map[int32]int, decInferLen(containerLen, d.maxInitLen(), 12)) - } - if containerLen != 0 { - ft.DecMapInt32IntL(*v, containerLen, d) - } - d.mapEnd() - } - case map[int32]int32: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen != containerLenNil { - if containerLen != 0 { - ft.DecMapInt32Int32L(v, containerLen, d) - } - d.mapEnd() - } - case *map[int32]int32: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen == containerLenNil { - *v = nil - } else { - if *v == nil { - *v = make(map[int32]int32, decInferLen(containerLen, d.maxInitLen(), 8)) - } - if containerLen != 0 { - ft.DecMapInt32Int32L(*v, containerLen, d) - } - d.mapEnd() - } - case map[int32]float64: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen != containerLenNil { - if containerLen != 0 { - ft.DecMapInt32Float64L(v, containerLen, d) - } - d.mapEnd() - } - case *map[int32]float64: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen == containerLenNil { - *v = nil - } else { - if *v == nil { - *v = make(map[int32]float64, decInferLen(containerLen, d.maxInitLen(), 12)) - } - if containerLen != 0 { - ft.DecMapInt32Float64L(*v, containerLen, d) - } - d.mapEnd() - } - case map[int32]bool: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen != containerLenNil { - if containerLen != 0 { - ft.DecMapInt32BoolL(v, containerLen, d) - } - d.mapEnd() - } - case *map[int32]bool: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen == containerLenNil { - *v = nil - } else { - if *v == nil { - *v = make(map[int32]bool, decInferLen(containerLen, d.maxInitLen(), 5)) - } - if containerLen != 0 { - ft.DecMapInt32BoolL(*v, containerLen, d) - } - d.mapEnd() - } - default: - _ = v - return false - } - return true -} - -func (d *decoderSimpleBytes) fastpathDecSliceIntfR(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTSimpleBytes - switch rv.Kind() { - case reflect.Ptr: - v := rv2i(rv).(*[]interface{}) - if vv, changed := ft.DecSliceIntfY(*v, d); changed { - *v = vv - } - case reflect.Array: - var v []interface{} - rvGetSlice4Array(rv, &v) - ft.DecSliceIntfN(v, d) - default: - ft.DecSliceIntfN(rv2i(rv).([]interface{}), d) - } -} -func (fastpathDTSimpleBytes) DecSliceIntfY(v []interface{}, d *decoderSimpleBytes) (v2 []interface{}, changed bool) { - ctyp := d.d.ContainerType() - if ctyp == valueTypeNil { - return nil, v != nil - } - var containerLenS int - isArray := ctyp == valueTypeArray - if isArray { - containerLenS = d.arrayStart(d.d.ReadArrayStart()) - } else if ctyp == valueTypeMap { - containerLenS = d.mapStart(d.d.ReadMapStart()) * 2 - } else { - halt.errorStr2("decoding into a slice, expect map/array - got ", ctyp.String()) - } - hasLen := containerLenS >= 0 - var j int - fnv := func(dst []interface{}) { v, changed = dst, true } - for ; d.containerNext(j, containerLenS, hasLen); j++ { - if j == 0 { - if containerLenS == len(v) { - } else if containerLenS < 0 || containerLenS > cap(v) { - if xlen := int(decInferLen(containerLenS, d.maxInitLen(), 16)); xlen <= cap(v) { - fnv(v[:uint(xlen)]) - } else { - v2 = make([]interface{}, uint(xlen)) - copy(v2, v) - fnv(v2) - } - } else { - fnv(v[:containerLenS]) - } - } - if isArray { - d.arrayElem(j == 0) - } else if j&1 == 0 { - d.mapElemKey(j == 0) - } else { - d.mapElemValue() - } - if j >= len(v) { - fnv(append(v, nil)) - } - d.decode(&v[uint(j)]) - } - if j < len(v) { - fnv(v[:uint(j)]) - } else if j == 0 && v == nil { - fnv([]interface{}{}) - } - if isArray { - d.arrayEnd() - } else { - d.mapEnd() - } - return v, changed -} -func (fastpathDTSimpleBytes) DecSliceIntfN(v []interface{}, d *decoderSimpleBytes) { - ctyp := d.d.ContainerType() - if ctyp == valueTypeNil { - return - } - var containerLenS int - isArray := ctyp == valueTypeArray - if isArray { - containerLenS = d.arrayStart(d.d.ReadArrayStart()) - } else if ctyp == valueTypeMap { - containerLenS = d.mapStart(d.d.ReadMapStart()) * 2 - } else { - halt.errorStr2("decoding into a slice, expect map/array - got ", ctyp.String()) - } - hasLen := containerLenS >= 0 - for j := 0; d.containerNext(j, containerLenS, hasLen); j++ { - if isArray { - d.arrayElem(j == 0) - } else if j&1 == 0 { - d.mapElemKey(j == 0) - } else { - d.mapElemValue() - } - if j < len(v) { - d.decode(&v[uint(j)]) - } else { - d.arrayCannotExpand(len(v), j+1) - d.swallow() - } - } - if isArray { - d.arrayEnd() - } else { - d.mapEnd() - } -} - -func (d *decoderSimpleBytes) fastpathDecSliceStringR(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTSimpleBytes - switch rv.Kind() { - case reflect.Ptr: - v := rv2i(rv).(*[]string) - if vv, changed := ft.DecSliceStringY(*v, d); changed { - *v = vv - } - case reflect.Array: - var v []string - rvGetSlice4Array(rv, &v) - ft.DecSliceStringN(v, d) - default: - ft.DecSliceStringN(rv2i(rv).([]string), d) - } -} -func (fastpathDTSimpleBytes) DecSliceStringY(v []string, d *decoderSimpleBytes) (v2 []string, changed bool) { - ctyp := d.d.ContainerType() - if ctyp == valueTypeNil { - return nil, v != nil - } - var containerLenS int - isArray := ctyp == valueTypeArray - if isArray { - containerLenS = d.arrayStart(d.d.ReadArrayStart()) - } else if ctyp == valueTypeMap { - containerLenS = d.mapStart(d.d.ReadMapStart()) * 2 - } else { - halt.errorStr2("decoding into a slice, expect map/array - got ", ctyp.String()) - } - hasLen := containerLenS >= 0 - var j int - fnv := func(dst []string) { v, changed = dst, true } - for ; d.containerNext(j, containerLenS, hasLen); j++ { - if j == 0 { - if containerLenS == len(v) { - } else if containerLenS < 0 || containerLenS > cap(v) { - if xlen := int(decInferLen(containerLenS, d.maxInitLen(), 16)); xlen <= cap(v) { - fnv(v[:uint(xlen)]) - } else { - v2 = make([]string, uint(xlen)) - copy(v2, v) - fnv(v2) - } - } else { - fnv(v[:containerLenS]) - } - } - if isArray { - d.arrayElem(j == 0) - } else if j&1 == 0 { - d.mapElemKey(j == 0) - } else { - d.mapElemValue() - } - if j >= len(v) { - fnv(append(v, "")) - } - v[uint(j)] = d.detach2Str(d.d.DecodeStringAsBytes()) - } - if j < len(v) { - fnv(v[:uint(j)]) - } else if j == 0 && v == nil { - fnv([]string{}) - } - if isArray { - d.arrayEnd() - } else { - d.mapEnd() - } - return v, changed -} -func (fastpathDTSimpleBytes) DecSliceStringN(v []string, d *decoderSimpleBytes) { - ctyp := d.d.ContainerType() - if ctyp == valueTypeNil { - return - } - var containerLenS int - isArray := ctyp == valueTypeArray - if isArray { - containerLenS = d.arrayStart(d.d.ReadArrayStart()) - } else if ctyp == valueTypeMap { - containerLenS = d.mapStart(d.d.ReadMapStart()) * 2 - } else { - halt.errorStr2("decoding into a slice, expect map/array - got ", ctyp.String()) - } - hasLen := containerLenS >= 0 - for j := 0; d.containerNext(j, containerLenS, hasLen); j++ { - if isArray { - d.arrayElem(j == 0) - } else if j&1 == 0 { - d.mapElemKey(j == 0) - } else { - d.mapElemValue() - } - if j < len(v) { - v[uint(j)] = d.detach2Str(d.d.DecodeStringAsBytes()) - } else { - d.arrayCannotExpand(len(v), j+1) - d.swallow() - } - } - if isArray { - d.arrayEnd() - } else { - d.mapEnd() - } -} - -func (d *decoderSimpleBytes) fastpathDecSliceBytesR(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTSimpleBytes - switch rv.Kind() { - case reflect.Ptr: - v := rv2i(rv).(*[][]byte) - if vv, changed := ft.DecSliceBytesY(*v, d); changed { - *v = vv - } - case reflect.Array: - var v [][]byte - rvGetSlice4Array(rv, &v) - ft.DecSliceBytesN(v, d) - default: - ft.DecSliceBytesN(rv2i(rv).([][]byte), d) - } -} -func (fastpathDTSimpleBytes) DecSliceBytesY(v [][]byte, d *decoderSimpleBytes) (v2 [][]byte, changed bool) { - ctyp := d.d.ContainerType() - if ctyp == valueTypeNil { - return nil, v != nil - } - var containerLenS int - isArray := ctyp == valueTypeArray - if isArray { - containerLenS = d.arrayStart(d.d.ReadArrayStart()) - } else if ctyp == valueTypeMap { - containerLenS = d.mapStart(d.d.ReadMapStart()) * 2 - } else { - halt.errorStr2("decoding into a slice, expect map/array - got ", ctyp.String()) - } - hasLen := containerLenS >= 0 - var j int - fnv := func(dst [][]byte) { v, changed = dst, true } - for ; d.containerNext(j, containerLenS, hasLen); j++ { - if j == 0 { - if containerLenS == len(v) { - } else if containerLenS < 0 || containerLenS > cap(v) { - if xlen := int(decInferLen(containerLenS, d.maxInitLen(), 24)); xlen <= cap(v) { - fnv(v[:uint(xlen)]) - } else { - v2 = make([][]byte, uint(xlen)) - copy(v2, v) - fnv(v2) - } - } else { - fnv(v[:containerLenS]) - } - } - if isArray { - d.arrayElem(j == 0) - } else if j&1 == 0 { - d.mapElemKey(j == 0) - } else { - d.mapElemValue() - } - if j >= len(v) { - fnv(append(v, nil)) - } - v[uint(j)] = bytesOKdbi(d.decodeBytesInto(v[uint(j)], false)) - } - if j < len(v) { - fnv(v[:uint(j)]) - } else if j == 0 && v == nil { - fnv([][]byte{}) - } - if isArray { - d.arrayEnd() - } else { - d.mapEnd() - } - return v, changed -} -func (fastpathDTSimpleBytes) DecSliceBytesN(v [][]byte, d *decoderSimpleBytes) { - ctyp := d.d.ContainerType() - if ctyp == valueTypeNil { - return - } - var containerLenS int - isArray := ctyp == valueTypeArray - if isArray { - containerLenS = d.arrayStart(d.d.ReadArrayStart()) - } else if ctyp == valueTypeMap { - containerLenS = d.mapStart(d.d.ReadMapStart()) * 2 - } else { - halt.errorStr2("decoding into a slice, expect map/array - got ", ctyp.String()) - } - hasLen := containerLenS >= 0 - for j := 0; d.containerNext(j, containerLenS, hasLen); j++ { - if isArray { - d.arrayElem(j == 0) - } else if j&1 == 0 { - d.mapElemKey(j == 0) - } else { - d.mapElemValue() - } - if j < len(v) { - v[uint(j)] = bytesOKdbi(d.decodeBytesInto(v[uint(j)], false)) - } else { - d.arrayCannotExpand(len(v), j+1) - d.swallow() - } - } - if isArray { - d.arrayEnd() - } else { - d.mapEnd() - } -} - -func (d *decoderSimpleBytes) fastpathDecSliceFloat32R(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTSimpleBytes - switch rv.Kind() { - case reflect.Ptr: - v := rv2i(rv).(*[]float32) - if vv, changed := ft.DecSliceFloat32Y(*v, d); changed { - *v = vv - } - case reflect.Array: - var v []float32 - rvGetSlice4Array(rv, &v) - ft.DecSliceFloat32N(v, d) - default: - ft.DecSliceFloat32N(rv2i(rv).([]float32), d) - } -} -func (fastpathDTSimpleBytes) DecSliceFloat32Y(v []float32, d *decoderSimpleBytes) (v2 []float32, changed bool) { - ctyp := d.d.ContainerType() - if ctyp == valueTypeNil { - return nil, v != nil - } - var containerLenS int - isArray := ctyp == valueTypeArray - if isArray { - containerLenS = d.arrayStart(d.d.ReadArrayStart()) - } else if ctyp == valueTypeMap { - containerLenS = d.mapStart(d.d.ReadMapStart()) * 2 - } else { - halt.errorStr2("decoding into a slice, expect map/array - got ", ctyp.String()) - } - hasLen := containerLenS >= 0 - var j int - fnv := func(dst []float32) { v, changed = dst, true } - for ; d.containerNext(j, containerLenS, hasLen); j++ { - if j == 0 { - if containerLenS == len(v) { - } else if containerLenS < 0 || containerLenS > cap(v) { - if xlen := int(decInferLen(containerLenS, d.maxInitLen(), 4)); xlen <= cap(v) { - fnv(v[:uint(xlen)]) - } else { - v2 = make([]float32, uint(xlen)) - copy(v2, v) - fnv(v2) - } - } else { - fnv(v[:containerLenS]) - } - } - if isArray { - d.arrayElem(j == 0) - } else if j&1 == 0 { - d.mapElemKey(j == 0) - } else { - d.mapElemValue() - } - if j >= len(v) { - fnv(append(v, 0)) - } - v[uint(j)] = float32(d.d.DecodeFloat32()) - } - if j < len(v) { - fnv(v[:uint(j)]) - } else if j == 0 && v == nil { - fnv([]float32{}) - } - if isArray { - d.arrayEnd() - } else { - d.mapEnd() - } - return v, changed -} -func (fastpathDTSimpleBytes) DecSliceFloat32N(v []float32, d *decoderSimpleBytes) { - ctyp := d.d.ContainerType() - if ctyp == valueTypeNil { - return - } - var containerLenS int - isArray := ctyp == valueTypeArray - if isArray { - containerLenS = d.arrayStart(d.d.ReadArrayStart()) - } else if ctyp == valueTypeMap { - containerLenS = d.mapStart(d.d.ReadMapStart()) * 2 - } else { - halt.errorStr2("decoding into a slice, expect map/array - got ", ctyp.String()) - } - hasLen := containerLenS >= 0 - for j := 0; d.containerNext(j, containerLenS, hasLen); j++ { - if isArray { - d.arrayElem(j == 0) - } else if j&1 == 0 { - d.mapElemKey(j == 0) - } else { - d.mapElemValue() - } - if j < len(v) { - v[uint(j)] = float32(d.d.DecodeFloat32()) - } else { - d.arrayCannotExpand(len(v), j+1) - d.swallow() - } - } - if isArray { - d.arrayEnd() - } else { - d.mapEnd() - } -} - -func (d *decoderSimpleBytes) fastpathDecSliceFloat64R(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTSimpleBytes - switch rv.Kind() { - case reflect.Ptr: - v := rv2i(rv).(*[]float64) - if vv, changed := ft.DecSliceFloat64Y(*v, d); changed { - *v = vv - } - case reflect.Array: - var v []float64 - rvGetSlice4Array(rv, &v) - ft.DecSliceFloat64N(v, d) - default: - ft.DecSliceFloat64N(rv2i(rv).([]float64), d) - } -} -func (fastpathDTSimpleBytes) DecSliceFloat64Y(v []float64, d *decoderSimpleBytes) (v2 []float64, changed bool) { - ctyp := d.d.ContainerType() - if ctyp == valueTypeNil { - return nil, v != nil - } - var containerLenS int - isArray := ctyp == valueTypeArray - if isArray { - containerLenS = d.arrayStart(d.d.ReadArrayStart()) - } else if ctyp == valueTypeMap { - containerLenS = d.mapStart(d.d.ReadMapStart()) * 2 - } else { - halt.errorStr2("decoding into a slice, expect map/array - got ", ctyp.String()) - } - hasLen := containerLenS >= 0 - var j int - fnv := func(dst []float64) { v, changed = dst, true } - for ; d.containerNext(j, containerLenS, hasLen); j++ { - if j == 0 { - if containerLenS == len(v) { - } else if containerLenS < 0 || containerLenS > cap(v) { - if xlen := int(decInferLen(containerLenS, d.maxInitLen(), 8)); xlen <= cap(v) { - fnv(v[:uint(xlen)]) - } else { - v2 = make([]float64, uint(xlen)) - copy(v2, v) - fnv(v2) - } - } else { - fnv(v[:containerLenS]) - } - } - if isArray { - d.arrayElem(j == 0) - } else if j&1 == 0 { - d.mapElemKey(j == 0) - } else { - d.mapElemValue() - } - if j >= len(v) { - fnv(append(v, 0)) - } - v[uint(j)] = d.d.DecodeFloat64() - } - if j < len(v) { - fnv(v[:uint(j)]) - } else if j == 0 && v == nil { - fnv([]float64{}) - } - if isArray { - d.arrayEnd() - } else { - d.mapEnd() - } - return v, changed -} -func (fastpathDTSimpleBytes) DecSliceFloat64N(v []float64, d *decoderSimpleBytes) { - ctyp := d.d.ContainerType() - if ctyp == valueTypeNil { - return - } - var containerLenS int - isArray := ctyp == valueTypeArray - if isArray { - containerLenS = d.arrayStart(d.d.ReadArrayStart()) - } else if ctyp == valueTypeMap { - containerLenS = d.mapStart(d.d.ReadMapStart()) * 2 - } else { - halt.errorStr2("decoding into a slice, expect map/array - got ", ctyp.String()) - } - hasLen := containerLenS >= 0 - for j := 0; d.containerNext(j, containerLenS, hasLen); j++ { - if isArray { - d.arrayElem(j == 0) - } else if j&1 == 0 { - d.mapElemKey(j == 0) - } else { - d.mapElemValue() - } - if j < len(v) { - v[uint(j)] = d.d.DecodeFloat64() - } else { - d.arrayCannotExpand(len(v), j+1) - d.swallow() - } - } - if isArray { - d.arrayEnd() - } else { - d.mapEnd() - } -} - -func (d *decoderSimpleBytes) fastpathDecSliceUint8R(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTSimpleBytes - switch rv.Kind() { - case reflect.Ptr: - v := rv2i(rv).(*[]uint8) - if vv, changed := ft.DecSliceUint8Y(*v, d); changed { - *v = vv - } - case reflect.Array: - var v []uint8 - rvGetSlice4Array(rv, &v) - ft.DecSliceUint8N(v, d) - default: - ft.DecSliceUint8N(rv2i(rv).([]uint8), d) - } -} -func (fastpathDTSimpleBytes) DecSliceUint8Y(v []uint8, d *decoderSimpleBytes) (v2 []uint8, changed bool) { - ctyp := d.d.ContainerType() - if ctyp == valueTypeNil { - return nil, v != nil - } - if ctyp != valueTypeMap { - var dbi dBytesIntoState - v2, dbi = d.decodeBytesInto(v[:len(v):len(v)], false) - return v2, dbi != dBytesIntoParamOut - } - containerLenS := d.mapStart(d.d.ReadMapStart()) * 2 - hasLen := containerLenS >= 0 - var j int - fnv := func(dst []uint8) { v, changed = dst, true } - for ; d.containerNext(j, containerLenS, hasLen); j++ { - if j == 0 { - if containerLenS == len(v) { - } else if containerLenS < 0 || containerLenS > cap(v) { - if xlen := int(decInferLen(containerLenS, d.maxInitLen(), 1)); xlen <= cap(v) { - fnv(v[:uint(xlen)]) - } else { - v2 = make([]uint8, uint(xlen)) - copy(v2, v) - fnv(v2) - } - } else { - fnv(v[:containerLenS]) - } - } - if j&1 == 0 { - d.mapElemKey(j == 0) - } else { - d.mapElemValue() - } - if j >= len(v) { - fnv(append(v, 0)) - } - v[uint(j)] = uint8(chkOvf.UintV(d.d.DecodeUint64(), 8)) - } - if j < len(v) { - fnv(v[:uint(j)]) - } else if j == 0 && v == nil { - fnv([]uint8{}) - } - d.mapEnd() - return v, changed -} -func (fastpathDTSimpleBytes) DecSliceUint8N(v []uint8, d *decoderSimpleBytes) { - ctyp := d.d.ContainerType() - if ctyp == valueTypeNil { - return - } - if ctyp != valueTypeMap { - d.decodeBytesInto(v[:len(v):len(v)], true) - return - } - containerLenS := d.mapStart(d.d.ReadMapStart()) * 2 - hasLen := containerLenS >= 0 - for j := 0; d.containerNext(j, containerLenS, hasLen); j++ { - if j&1 == 0 { - d.mapElemKey(j == 0) - } else { - d.mapElemValue() - } - if j < len(v) { - v[uint(j)] = uint8(chkOvf.UintV(d.d.DecodeUint64(), 8)) - } else { - d.arrayCannotExpand(len(v), j+1) - d.swallow() - } - } - d.mapEnd() -} - -func (d *decoderSimpleBytes) fastpathDecSliceUint64R(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTSimpleBytes - switch rv.Kind() { - case reflect.Ptr: - v := rv2i(rv).(*[]uint64) - if vv, changed := ft.DecSliceUint64Y(*v, d); changed { - *v = vv - } - case reflect.Array: - var v []uint64 - rvGetSlice4Array(rv, &v) - ft.DecSliceUint64N(v, d) - default: - ft.DecSliceUint64N(rv2i(rv).([]uint64), d) - } -} -func (fastpathDTSimpleBytes) DecSliceUint64Y(v []uint64, d *decoderSimpleBytes) (v2 []uint64, changed bool) { - ctyp := d.d.ContainerType() - if ctyp == valueTypeNil { - return nil, v != nil - } - var containerLenS int - isArray := ctyp == valueTypeArray - if isArray { - containerLenS = d.arrayStart(d.d.ReadArrayStart()) - } else if ctyp == valueTypeMap { - containerLenS = d.mapStart(d.d.ReadMapStart()) * 2 - } else { - halt.errorStr2("decoding into a slice, expect map/array - got ", ctyp.String()) - } - hasLen := containerLenS >= 0 - var j int - fnv := func(dst []uint64) { v, changed = dst, true } - for ; d.containerNext(j, containerLenS, hasLen); j++ { - if j == 0 { - if containerLenS == len(v) { - } else if containerLenS < 0 || containerLenS > cap(v) { - if xlen := int(decInferLen(containerLenS, d.maxInitLen(), 8)); xlen <= cap(v) { - fnv(v[:uint(xlen)]) - } else { - v2 = make([]uint64, uint(xlen)) - copy(v2, v) - fnv(v2) - } - } else { - fnv(v[:containerLenS]) - } - } - if isArray { - d.arrayElem(j == 0) - } else if j&1 == 0 { - d.mapElemKey(j == 0) - } else { - d.mapElemValue() - } - if j >= len(v) { - fnv(append(v, 0)) - } - v[uint(j)] = d.d.DecodeUint64() - } - if j < len(v) { - fnv(v[:uint(j)]) - } else if j == 0 && v == nil { - fnv([]uint64{}) - } - if isArray { - d.arrayEnd() - } else { - d.mapEnd() - } - return v, changed -} -func (fastpathDTSimpleBytes) DecSliceUint64N(v []uint64, d *decoderSimpleBytes) { - ctyp := d.d.ContainerType() - if ctyp == valueTypeNil { - return - } - var containerLenS int - isArray := ctyp == valueTypeArray - if isArray { - containerLenS = d.arrayStart(d.d.ReadArrayStart()) - } else if ctyp == valueTypeMap { - containerLenS = d.mapStart(d.d.ReadMapStart()) * 2 - } else { - halt.errorStr2("decoding into a slice, expect map/array - got ", ctyp.String()) - } - hasLen := containerLenS >= 0 - for j := 0; d.containerNext(j, containerLenS, hasLen); j++ { - if isArray { - d.arrayElem(j == 0) - } else if j&1 == 0 { - d.mapElemKey(j == 0) - } else { - d.mapElemValue() - } - if j < len(v) { - v[uint(j)] = d.d.DecodeUint64() - } else { - d.arrayCannotExpand(len(v), j+1) - d.swallow() - } - } - if isArray { - d.arrayEnd() - } else { - d.mapEnd() - } -} - -func (d *decoderSimpleBytes) fastpathDecSliceIntR(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTSimpleBytes - switch rv.Kind() { - case reflect.Ptr: - v := rv2i(rv).(*[]int) - if vv, changed := ft.DecSliceIntY(*v, d); changed { - *v = vv - } - case reflect.Array: - var v []int - rvGetSlice4Array(rv, &v) - ft.DecSliceIntN(v, d) - default: - ft.DecSliceIntN(rv2i(rv).([]int), d) - } -} -func (fastpathDTSimpleBytes) DecSliceIntY(v []int, d *decoderSimpleBytes) (v2 []int, changed bool) { - ctyp := d.d.ContainerType() - if ctyp == valueTypeNil { - return nil, v != nil - } - var containerLenS int - isArray := ctyp == valueTypeArray - if isArray { - containerLenS = d.arrayStart(d.d.ReadArrayStart()) - } else if ctyp == valueTypeMap { - containerLenS = d.mapStart(d.d.ReadMapStart()) * 2 - } else { - halt.errorStr2("decoding into a slice, expect map/array - got ", ctyp.String()) - } - hasLen := containerLenS >= 0 - var j int - fnv := func(dst []int) { v, changed = dst, true } - for ; d.containerNext(j, containerLenS, hasLen); j++ { - if j == 0 { - if containerLenS == len(v) { - } else if containerLenS < 0 || containerLenS > cap(v) { - if xlen := int(decInferLen(containerLenS, d.maxInitLen(), 8)); xlen <= cap(v) { - fnv(v[:uint(xlen)]) - } else { - v2 = make([]int, uint(xlen)) - copy(v2, v) - fnv(v2) - } - } else { - fnv(v[:containerLenS]) - } - } - if isArray { - d.arrayElem(j == 0) - } else if j&1 == 0 { - d.mapElemKey(j == 0) - } else { - d.mapElemValue() - } - if j >= len(v) { - fnv(append(v, 0)) - } - v[uint(j)] = int(chkOvf.IntV(d.d.DecodeInt64(), intBitsize)) - } - if j < len(v) { - fnv(v[:uint(j)]) - } else if j == 0 && v == nil { - fnv([]int{}) - } - if isArray { - d.arrayEnd() - } else { - d.mapEnd() - } - return v, changed -} -func (fastpathDTSimpleBytes) DecSliceIntN(v []int, d *decoderSimpleBytes) { - ctyp := d.d.ContainerType() - if ctyp == valueTypeNil { - return - } - var containerLenS int - isArray := ctyp == valueTypeArray - if isArray { - containerLenS = d.arrayStart(d.d.ReadArrayStart()) - } else if ctyp == valueTypeMap { - containerLenS = d.mapStart(d.d.ReadMapStart()) * 2 - } else { - halt.errorStr2("decoding into a slice, expect map/array - got ", ctyp.String()) - } - hasLen := containerLenS >= 0 - for j := 0; d.containerNext(j, containerLenS, hasLen); j++ { - if isArray { - d.arrayElem(j == 0) - } else if j&1 == 0 { - d.mapElemKey(j == 0) - } else { - d.mapElemValue() - } - if j < len(v) { - v[uint(j)] = int(chkOvf.IntV(d.d.DecodeInt64(), intBitsize)) - } else { - d.arrayCannotExpand(len(v), j+1) - d.swallow() - } - } - if isArray { - d.arrayEnd() - } else { - d.mapEnd() - } -} - -func (d *decoderSimpleBytes) fastpathDecSliceInt32R(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTSimpleBytes - switch rv.Kind() { - case reflect.Ptr: - v := rv2i(rv).(*[]int32) - if vv, changed := ft.DecSliceInt32Y(*v, d); changed { - *v = vv - } - case reflect.Array: - var v []int32 - rvGetSlice4Array(rv, &v) - ft.DecSliceInt32N(v, d) - default: - ft.DecSliceInt32N(rv2i(rv).([]int32), d) - } -} -func (fastpathDTSimpleBytes) DecSliceInt32Y(v []int32, d *decoderSimpleBytes) (v2 []int32, changed bool) { - ctyp := d.d.ContainerType() - if ctyp == valueTypeNil { - return nil, v != nil - } - var containerLenS int - isArray := ctyp == valueTypeArray - if isArray { - containerLenS = d.arrayStart(d.d.ReadArrayStart()) - } else if ctyp == valueTypeMap { - containerLenS = d.mapStart(d.d.ReadMapStart()) * 2 - } else { - halt.errorStr2("decoding into a slice, expect map/array - got ", ctyp.String()) - } - hasLen := containerLenS >= 0 - var j int - fnv := func(dst []int32) { v, changed = dst, true } - for ; d.containerNext(j, containerLenS, hasLen); j++ { - if j == 0 { - if containerLenS == len(v) { - } else if containerLenS < 0 || containerLenS > cap(v) { - if xlen := int(decInferLen(containerLenS, d.maxInitLen(), 4)); xlen <= cap(v) { - fnv(v[:uint(xlen)]) - } else { - v2 = make([]int32, uint(xlen)) - copy(v2, v) - fnv(v2) - } - } else { - fnv(v[:containerLenS]) - } - } - if isArray { - d.arrayElem(j == 0) - } else if j&1 == 0 { - d.mapElemKey(j == 0) - } else { - d.mapElemValue() - } - if j >= len(v) { - fnv(append(v, 0)) - } - v[uint(j)] = int32(chkOvf.IntV(d.d.DecodeInt64(), 32)) - } - if j < len(v) { - fnv(v[:uint(j)]) - } else if j == 0 && v == nil { - fnv([]int32{}) - } - if isArray { - d.arrayEnd() - } else { - d.mapEnd() - } - return v, changed -} -func (fastpathDTSimpleBytes) DecSliceInt32N(v []int32, d *decoderSimpleBytes) { - ctyp := d.d.ContainerType() - if ctyp == valueTypeNil { - return - } - var containerLenS int - isArray := ctyp == valueTypeArray - if isArray { - containerLenS = d.arrayStart(d.d.ReadArrayStart()) - } else if ctyp == valueTypeMap { - containerLenS = d.mapStart(d.d.ReadMapStart()) * 2 - } else { - halt.errorStr2("decoding into a slice, expect map/array - got ", ctyp.String()) - } - hasLen := containerLenS >= 0 - for j := 0; d.containerNext(j, containerLenS, hasLen); j++ { - if isArray { - d.arrayElem(j == 0) - } else if j&1 == 0 { - d.mapElemKey(j == 0) - } else { - d.mapElemValue() - } - if j < len(v) { - v[uint(j)] = int32(chkOvf.IntV(d.d.DecodeInt64(), 32)) - } else { - d.arrayCannotExpand(len(v), j+1) - d.swallow() - } - } - if isArray { - d.arrayEnd() - } else { - d.mapEnd() - } -} - -func (d *decoderSimpleBytes) fastpathDecSliceInt64R(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTSimpleBytes - switch rv.Kind() { - case reflect.Ptr: - v := rv2i(rv).(*[]int64) - if vv, changed := ft.DecSliceInt64Y(*v, d); changed { - *v = vv - } - case reflect.Array: - var v []int64 - rvGetSlice4Array(rv, &v) - ft.DecSliceInt64N(v, d) - default: - ft.DecSliceInt64N(rv2i(rv).([]int64), d) - } -} -func (fastpathDTSimpleBytes) DecSliceInt64Y(v []int64, d *decoderSimpleBytes) (v2 []int64, changed bool) { - ctyp := d.d.ContainerType() - if ctyp == valueTypeNil { - return nil, v != nil - } - var containerLenS int - isArray := ctyp == valueTypeArray - if isArray { - containerLenS = d.arrayStart(d.d.ReadArrayStart()) - } else if ctyp == valueTypeMap { - containerLenS = d.mapStart(d.d.ReadMapStart()) * 2 - } else { - halt.errorStr2("decoding into a slice, expect map/array - got ", ctyp.String()) - } - hasLen := containerLenS >= 0 - var j int - fnv := func(dst []int64) { v, changed = dst, true } - for ; d.containerNext(j, containerLenS, hasLen); j++ { - if j == 0 { - if containerLenS == len(v) { - } else if containerLenS < 0 || containerLenS > cap(v) { - if xlen := int(decInferLen(containerLenS, d.maxInitLen(), 8)); xlen <= cap(v) { - fnv(v[:uint(xlen)]) - } else { - v2 = make([]int64, uint(xlen)) - copy(v2, v) - fnv(v2) - } - } else { - fnv(v[:containerLenS]) - } - } - if isArray { - d.arrayElem(j == 0) - } else if j&1 == 0 { - d.mapElemKey(j == 0) - } else { - d.mapElemValue() - } - if j >= len(v) { - fnv(append(v, 0)) - } - v[uint(j)] = d.d.DecodeInt64() - } - if j < len(v) { - fnv(v[:uint(j)]) - } else if j == 0 && v == nil { - fnv([]int64{}) - } - if isArray { - d.arrayEnd() - } else { - d.mapEnd() - } - return v, changed -} -func (fastpathDTSimpleBytes) DecSliceInt64N(v []int64, d *decoderSimpleBytes) { - ctyp := d.d.ContainerType() - if ctyp == valueTypeNil { - return - } - var containerLenS int - isArray := ctyp == valueTypeArray - if isArray { - containerLenS = d.arrayStart(d.d.ReadArrayStart()) - } else if ctyp == valueTypeMap { - containerLenS = d.mapStart(d.d.ReadMapStart()) * 2 - } else { - halt.errorStr2("decoding into a slice, expect map/array - got ", ctyp.String()) - } - hasLen := containerLenS >= 0 - for j := 0; d.containerNext(j, containerLenS, hasLen); j++ { - if isArray { - d.arrayElem(j == 0) - } else if j&1 == 0 { - d.mapElemKey(j == 0) - } else { - d.mapElemValue() - } - if j < len(v) { - v[uint(j)] = d.d.DecodeInt64() - } else { - d.arrayCannotExpand(len(v), j+1) - d.swallow() - } - } - if isArray { - d.arrayEnd() - } else { - d.mapEnd() - } -} - -func (d *decoderSimpleBytes) fastpathDecSliceBoolR(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTSimpleBytes - switch rv.Kind() { - case reflect.Ptr: - v := rv2i(rv).(*[]bool) - if vv, changed := ft.DecSliceBoolY(*v, d); changed { - *v = vv - } - case reflect.Array: - var v []bool - rvGetSlice4Array(rv, &v) - ft.DecSliceBoolN(v, d) - default: - ft.DecSliceBoolN(rv2i(rv).([]bool), d) - } -} -func (fastpathDTSimpleBytes) DecSliceBoolY(v []bool, d *decoderSimpleBytes) (v2 []bool, changed bool) { - ctyp := d.d.ContainerType() - if ctyp == valueTypeNil { - return nil, v != nil - } - var containerLenS int - isArray := ctyp == valueTypeArray - if isArray { - containerLenS = d.arrayStart(d.d.ReadArrayStart()) - } else if ctyp == valueTypeMap { - containerLenS = d.mapStart(d.d.ReadMapStart()) * 2 - } else { - halt.errorStr2("decoding into a slice, expect map/array - got ", ctyp.String()) - } - hasLen := containerLenS >= 0 - var j int - fnv := func(dst []bool) { v, changed = dst, true } - for ; d.containerNext(j, containerLenS, hasLen); j++ { - if j == 0 { - if containerLenS == len(v) { - } else if containerLenS < 0 || containerLenS > cap(v) { - if xlen := int(decInferLen(containerLenS, d.maxInitLen(), 1)); xlen <= cap(v) { - fnv(v[:uint(xlen)]) - } else { - v2 = make([]bool, uint(xlen)) - copy(v2, v) - fnv(v2) - } - } else { - fnv(v[:containerLenS]) - } - } - if isArray { - d.arrayElem(j == 0) - } else if j&1 == 0 { - d.mapElemKey(j == 0) - } else { - d.mapElemValue() - } - if j >= len(v) { - fnv(append(v, false)) - } - v[uint(j)] = d.d.DecodeBool() - } - if j < len(v) { - fnv(v[:uint(j)]) - } else if j == 0 && v == nil { - fnv([]bool{}) - } - if isArray { - d.arrayEnd() - } else { - d.mapEnd() - } - return v, changed -} -func (fastpathDTSimpleBytes) DecSliceBoolN(v []bool, d *decoderSimpleBytes) { - ctyp := d.d.ContainerType() - if ctyp == valueTypeNil { - return - } - var containerLenS int - isArray := ctyp == valueTypeArray - if isArray { - containerLenS = d.arrayStart(d.d.ReadArrayStart()) - } else if ctyp == valueTypeMap { - containerLenS = d.mapStart(d.d.ReadMapStart()) * 2 - } else { - halt.errorStr2("decoding into a slice, expect map/array - got ", ctyp.String()) - } - hasLen := containerLenS >= 0 - for j := 0; d.containerNext(j, containerLenS, hasLen); j++ { - if isArray { - d.arrayElem(j == 0) - } else if j&1 == 0 { - d.mapElemKey(j == 0) - } else { - d.mapElemValue() - } - if j < len(v) { - v[uint(j)] = d.d.DecodeBool() - } else { - d.arrayCannotExpand(len(v), j+1) - d.swallow() - } - } - if isArray { - d.arrayEnd() - } else { - d.mapEnd() - } -} -func (d *decoderSimpleBytes) fastpathDecMapStringIntfR(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTSimpleBytes - containerLen := d.mapStart(d.d.ReadMapStart()) - if rv.Kind() == reflect.Ptr { - vp, _ := rv2i(rv).(*map[string]interface{}) - if *vp == nil { - *vp = make(map[string]interface{}, decInferLen(containerLen, d.maxInitLen(), 32)) - } - if containerLen != 0 { - ft.DecMapStringIntfL(*vp, containerLen, d) - } - } else if containerLen != 0 { - ft.DecMapStringIntfL(rv2i(rv).(map[string]interface{}), containerLen, d) - } - d.mapEnd() -} -func (fastpathDTSimpleBytes) DecMapStringIntfL(v map[string]interface{}, containerLen int, d *decoderSimpleBytes) { - if v == nil { - halt.errorInt("cannot decode into nil map[string]interface{} given stream length: ", int64(containerLen)) - } - var mv interface{} - mapGet := !d.h.MapValueReset && !d.h.InterfaceReset - hasLen := containerLen >= 0 - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - mk := d.detach2Str(d.d.DecodeStringAsBytes()) - d.mapElemValue() - if mapGet { - mv = v[mk] - } else { - mv = nil - } - d.decode(&mv) - v[mk] = mv - } -} -func (d *decoderSimpleBytes) fastpathDecMapStringStringR(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTSimpleBytes - containerLen := d.mapStart(d.d.ReadMapStart()) - if rv.Kind() == reflect.Ptr { - vp, _ := rv2i(rv).(*map[string]string) - if *vp == nil { - *vp = make(map[string]string, decInferLen(containerLen, d.maxInitLen(), 32)) - } - if containerLen != 0 { - ft.DecMapStringStringL(*vp, containerLen, d) - } - } else if containerLen != 0 { - ft.DecMapStringStringL(rv2i(rv).(map[string]string), containerLen, d) - } - d.mapEnd() -} -func (fastpathDTSimpleBytes) DecMapStringStringL(v map[string]string, containerLen int, d *decoderSimpleBytes) { - if v == nil { - halt.errorInt("cannot decode into nil map[string]string given stream length: ", int64(containerLen)) - } - hasLen := containerLen >= 0 - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - mk := d.detach2Str(d.d.DecodeStringAsBytes()) - d.mapElemValue() - v[mk] = d.detach2Str(d.d.DecodeStringAsBytes()) - } -} -func (d *decoderSimpleBytes) fastpathDecMapStringBytesR(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTSimpleBytes - containerLen := d.mapStart(d.d.ReadMapStart()) - if rv.Kind() == reflect.Ptr { - vp, _ := rv2i(rv).(*map[string][]byte) - if *vp == nil { - *vp = make(map[string][]byte, decInferLen(containerLen, d.maxInitLen(), 40)) - } - if containerLen != 0 { - ft.DecMapStringBytesL(*vp, containerLen, d) - } - } else if containerLen != 0 { - ft.DecMapStringBytesL(rv2i(rv).(map[string][]byte), containerLen, d) - } - d.mapEnd() -} -func (fastpathDTSimpleBytes) DecMapStringBytesL(v map[string][]byte, containerLen int, d *decoderSimpleBytes) { - if v == nil { - halt.errorInt("cannot decode into nil map[string][]byte given stream length: ", int64(containerLen)) - } - var mv []byte - mapGet := !d.h.MapValueReset - hasLen := containerLen >= 0 - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - mk := d.detach2Str(d.d.DecodeStringAsBytes()) - d.mapElemValue() - if mapGet { - mv = v[mk] - } else { - mv = nil - } - v[mk], _ = d.decodeBytesInto(mv, false) - } -} -func (d *decoderSimpleBytes) fastpathDecMapStringUint8R(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTSimpleBytes - containerLen := d.mapStart(d.d.ReadMapStart()) - if rv.Kind() == reflect.Ptr { - vp, _ := rv2i(rv).(*map[string]uint8) - if *vp == nil { - *vp = make(map[string]uint8, decInferLen(containerLen, d.maxInitLen(), 17)) - } - if containerLen != 0 { - ft.DecMapStringUint8L(*vp, containerLen, d) - } - } else if containerLen != 0 { - ft.DecMapStringUint8L(rv2i(rv).(map[string]uint8), containerLen, d) - } - d.mapEnd() -} -func (fastpathDTSimpleBytes) DecMapStringUint8L(v map[string]uint8, containerLen int, d *decoderSimpleBytes) { - if v == nil { - halt.errorInt("cannot decode into nil map[string]uint8 given stream length: ", int64(containerLen)) - } - hasLen := containerLen >= 0 - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - mk := d.detach2Str(d.d.DecodeStringAsBytes()) - d.mapElemValue() - v[mk] = uint8(chkOvf.UintV(d.d.DecodeUint64(), 8)) - } -} -func (d *decoderSimpleBytes) fastpathDecMapStringUint64R(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTSimpleBytes - containerLen := d.mapStart(d.d.ReadMapStart()) - if rv.Kind() == reflect.Ptr { - vp, _ := rv2i(rv).(*map[string]uint64) - if *vp == nil { - *vp = make(map[string]uint64, decInferLen(containerLen, d.maxInitLen(), 24)) - } - if containerLen != 0 { - ft.DecMapStringUint64L(*vp, containerLen, d) - } - } else if containerLen != 0 { - ft.DecMapStringUint64L(rv2i(rv).(map[string]uint64), containerLen, d) - } - d.mapEnd() -} -func (fastpathDTSimpleBytes) DecMapStringUint64L(v map[string]uint64, containerLen int, d *decoderSimpleBytes) { - if v == nil { - halt.errorInt("cannot decode into nil map[string]uint64 given stream length: ", int64(containerLen)) - } - hasLen := containerLen >= 0 - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - mk := d.detach2Str(d.d.DecodeStringAsBytes()) - d.mapElemValue() - v[mk] = d.d.DecodeUint64() - } -} -func (d *decoderSimpleBytes) fastpathDecMapStringIntR(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTSimpleBytes - containerLen := d.mapStart(d.d.ReadMapStart()) - if rv.Kind() == reflect.Ptr { - vp, _ := rv2i(rv).(*map[string]int) - if *vp == nil { - *vp = make(map[string]int, decInferLen(containerLen, d.maxInitLen(), 24)) - } - if containerLen != 0 { - ft.DecMapStringIntL(*vp, containerLen, d) - } - } else if containerLen != 0 { - ft.DecMapStringIntL(rv2i(rv).(map[string]int), containerLen, d) - } - d.mapEnd() -} -func (fastpathDTSimpleBytes) DecMapStringIntL(v map[string]int, containerLen int, d *decoderSimpleBytes) { - if v == nil { - halt.errorInt("cannot decode into nil map[string]int given stream length: ", int64(containerLen)) - } - hasLen := containerLen >= 0 - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - mk := d.detach2Str(d.d.DecodeStringAsBytes()) - d.mapElemValue() - v[mk] = int(chkOvf.IntV(d.d.DecodeInt64(), intBitsize)) - } -} -func (d *decoderSimpleBytes) fastpathDecMapStringInt32R(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTSimpleBytes - containerLen := d.mapStart(d.d.ReadMapStart()) - if rv.Kind() == reflect.Ptr { - vp, _ := rv2i(rv).(*map[string]int32) - if *vp == nil { - *vp = make(map[string]int32, decInferLen(containerLen, d.maxInitLen(), 20)) - } - if containerLen != 0 { - ft.DecMapStringInt32L(*vp, containerLen, d) - } - } else if containerLen != 0 { - ft.DecMapStringInt32L(rv2i(rv).(map[string]int32), containerLen, d) - } - d.mapEnd() -} -func (fastpathDTSimpleBytes) DecMapStringInt32L(v map[string]int32, containerLen int, d *decoderSimpleBytes) { - if v == nil { - halt.errorInt("cannot decode into nil map[string]int32 given stream length: ", int64(containerLen)) - } - hasLen := containerLen >= 0 - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - mk := d.detach2Str(d.d.DecodeStringAsBytes()) - d.mapElemValue() - v[mk] = int32(chkOvf.IntV(d.d.DecodeInt64(), 32)) - } -} -func (d *decoderSimpleBytes) fastpathDecMapStringFloat64R(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTSimpleBytes - containerLen := d.mapStart(d.d.ReadMapStart()) - if rv.Kind() == reflect.Ptr { - vp, _ := rv2i(rv).(*map[string]float64) - if *vp == nil { - *vp = make(map[string]float64, decInferLen(containerLen, d.maxInitLen(), 24)) - } - if containerLen != 0 { - ft.DecMapStringFloat64L(*vp, containerLen, d) - } - } else if containerLen != 0 { - ft.DecMapStringFloat64L(rv2i(rv).(map[string]float64), containerLen, d) - } - d.mapEnd() -} -func (fastpathDTSimpleBytes) DecMapStringFloat64L(v map[string]float64, containerLen int, d *decoderSimpleBytes) { - if v == nil { - halt.errorInt("cannot decode into nil map[string]float64 given stream length: ", int64(containerLen)) - } - hasLen := containerLen >= 0 - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - mk := d.detach2Str(d.d.DecodeStringAsBytes()) - d.mapElemValue() - v[mk] = d.d.DecodeFloat64() - } -} -func (d *decoderSimpleBytes) fastpathDecMapStringBoolR(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTSimpleBytes - containerLen := d.mapStart(d.d.ReadMapStart()) - if rv.Kind() == reflect.Ptr { - vp, _ := rv2i(rv).(*map[string]bool) - if *vp == nil { - *vp = make(map[string]bool, decInferLen(containerLen, d.maxInitLen(), 17)) - } - if containerLen != 0 { - ft.DecMapStringBoolL(*vp, containerLen, d) - } - } else if containerLen != 0 { - ft.DecMapStringBoolL(rv2i(rv).(map[string]bool), containerLen, d) - } - d.mapEnd() -} -func (fastpathDTSimpleBytes) DecMapStringBoolL(v map[string]bool, containerLen int, d *decoderSimpleBytes) { - if v == nil { - halt.errorInt("cannot decode into nil map[string]bool given stream length: ", int64(containerLen)) - } - hasLen := containerLen >= 0 - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - mk := d.detach2Str(d.d.DecodeStringAsBytes()) - d.mapElemValue() - v[mk] = d.d.DecodeBool() - } -} -func (d *decoderSimpleBytes) fastpathDecMapUint8IntfR(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTSimpleBytes - containerLen := d.mapStart(d.d.ReadMapStart()) - if rv.Kind() == reflect.Ptr { - vp, _ := rv2i(rv).(*map[uint8]interface{}) - if *vp == nil { - *vp = make(map[uint8]interface{}, decInferLen(containerLen, d.maxInitLen(), 17)) - } - if containerLen != 0 { - ft.DecMapUint8IntfL(*vp, containerLen, d) - } - } else if containerLen != 0 { - ft.DecMapUint8IntfL(rv2i(rv).(map[uint8]interface{}), containerLen, d) - } - d.mapEnd() -} -func (fastpathDTSimpleBytes) DecMapUint8IntfL(v map[uint8]interface{}, containerLen int, d *decoderSimpleBytes) { - if v == nil { - halt.errorInt("cannot decode into nil map[uint8]interface{} given stream length: ", int64(containerLen)) - } - var mv interface{} - mapGet := !d.h.MapValueReset && !d.h.InterfaceReset - hasLen := containerLen >= 0 - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - mk := uint8(chkOvf.UintV(d.d.DecodeUint64(), 8)) - d.mapElemValue() - if mapGet { - mv = v[mk] - } else { - mv = nil - } - d.decode(&mv) - v[mk] = mv - } -} -func (d *decoderSimpleBytes) fastpathDecMapUint8StringR(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTSimpleBytes - containerLen := d.mapStart(d.d.ReadMapStart()) - if rv.Kind() == reflect.Ptr { - vp, _ := rv2i(rv).(*map[uint8]string) - if *vp == nil { - *vp = make(map[uint8]string, decInferLen(containerLen, d.maxInitLen(), 17)) - } - if containerLen != 0 { - ft.DecMapUint8StringL(*vp, containerLen, d) - } - } else if containerLen != 0 { - ft.DecMapUint8StringL(rv2i(rv).(map[uint8]string), containerLen, d) - } - d.mapEnd() -} -func (fastpathDTSimpleBytes) DecMapUint8StringL(v map[uint8]string, containerLen int, d *decoderSimpleBytes) { - if v == nil { - halt.errorInt("cannot decode into nil map[uint8]string given stream length: ", int64(containerLen)) - } - hasLen := containerLen >= 0 - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - mk := uint8(chkOvf.UintV(d.d.DecodeUint64(), 8)) - d.mapElemValue() - v[mk] = d.detach2Str(d.d.DecodeStringAsBytes()) - } -} -func (d *decoderSimpleBytes) fastpathDecMapUint8BytesR(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTSimpleBytes - containerLen := d.mapStart(d.d.ReadMapStart()) - if rv.Kind() == reflect.Ptr { - vp, _ := rv2i(rv).(*map[uint8][]byte) - if *vp == nil { - *vp = make(map[uint8][]byte, decInferLen(containerLen, d.maxInitLen(), 25)) - } - if containerLen != 0 { - ft.DecMapUint8BytesL(*vp, containerLen, d) - } - } else if containerLen != 0 { - ft.DecMapUint8BytesL(rv2i(rv).(map[uint8][]byte), containerLen, d) - } - d.mapEnd() -} -func (fastpathDTSimpleBytes) DecMapUint8BytesL(v map[uint8][]byte, containerLen int, d *decoderSimpleBytes) { - if v == nil { - halt.errorInt("cannot decode into nil map[uint8][]byte given stream length: ", int64(containerLen)) - } - var mv []byte - mapGet := !d.h.MapValueReset - hasLen := containerLen >= 0 - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - mk := uint8(chkOvf.UintV(d.d.DecodeUint64(), 8)) - d.mapElemValue() - if mapGet { - mv = v[mk] - } else { - mv = nil - } - v[mk], _ = d.decodeBytesInto(mv, false) - } -} -func (d *decoderSimpleBytes) fastpathDecMapUint8Uint8R(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTSimpleBytes - containerLen := d.mapStart(d.d.ReadMapStart()) - if rv.Kind() == reflect.Ptr { - vp, _ := rv2i(rv).(*map[uint8]uint8) - if *vp == nil { - *vp = make(map[uint8]uint8, decInferLen(containerLen, d.maxInitLen(), 2)) - } - if containerLen != 0 { - ft.DecMapUint8Uint8L(*vp, containerLen, d) - } - } else if containerLen != 0 { - ft.DecMapUint8Uint8L(rv2i(rv).(map[uint8]uint8), containerLen, d) - } - d.mapEnd() -} -func (fastpathDTSimpleBytes) DecMapUint8Uint8L(v map[uint8]uint8, containerLen int, d *decoderSimpleBytes) { - if v == nil { - halt.errorInt("cannot decode into nil map[uint8]uint8 given stream length: ", int64(containerLen)) - } - hasLen := containerLen >= 0 - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - mk := uint8(chkOvf.UintV(d.d.DecodeUint64(), 8)) - d.mapElemValue() - v[mk] = uint8(chkOvf.UintV(d.d.DecodeUint64(), 8)) - } -} -func (d *decoderSimpleBytes) fastpathDecMapUint8Uint64R(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTSimpleBytes - containerLen := d.mapStart(d.d.ReadMapStart()) - if rv.Kind() == reflect.Ptr { - vp, _ := rv2i(rv).(*map[uint8]uint64) - if *vp == nil { - *vp = make(map[uint8]uint64, decInferLen(containerLen, d.maxInitLen(), 9)) - } - if containerLen != 0 { - ft.DecMapUint8Uint64L(*vp, containerLen, d) - } - } else if containerLen != 0 { - ft.DecMapUint8Uint64L(rv2i(rv).(map[uint8]uint64), containerLen, d) - } - d.mapEnd() -} -func (fastpathDTSimpleBytes) DecMapUint8Uint64L(v map[uint8]uint64, containerLen int, d *decoderSimpleBytes) { - if v == nil { - halt.errorInt("cannot decode into nil map[uint8]uint64 given stream length: ", int64(containerLen)) - } - hasLen := containerLen >= 0 - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - mk := uint8(chkOvf.UintV(d.d.DecodeUint64(), 8)) - d.mapElemValue() - v[mk] = d.d.DecodeUint64() - } -} -func (d *decoderSimpleBytes) fastpathDecMapUint8IntR(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTSimpleBytes - containerLen := d.mapStart(d.d.ReadMapStart()) - if rv.Kind() == reflect.Ptr { - vp, _ := rv2i(rv).(*map[uint8]int) - if *vp == nil { - *vp = make(map[uint8]int, decInferLen(containerLen, d.maxInitLen(), 9)) - } - if containerLen != 0 { - ft.DecMapUint8IntL(*vp, containerLen, d) - } - } else if containerLen != 0 { - ft.DecMapUint8IntL(rv2i(rv).(map[uint8]int), containerLen, d) - } - d.mapEnd() -} -func (fastpathDTSimpleBytes) DecMapUint8IntL(v map[uint8]int, containerLen int, d *decoderSimpleBytes) { - if v == nil { - halt.errorInt("cannot decode into nil map[uint8]int given stream length: ", int64(containerLen)) - } - hasLen := containerLen >= 0 - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - mk := uint8(chkOvf.UintV(d.d.DecodeUint64(), 8)) - d.mapElemValue() - v[mk] = int(chkOvf.IntV(d.d.DecodeInt64(), intBitsize)) - } -} -func (d *decoderSimpleBytes) fastpathDecMapUint8Int32R(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTSimpleBytes - containerLen := d.mapStart(d.d.ReadMapStart()) - if rv.Kind() == reflect.Ptr { - vp, _ := rv2i(rv).(*map[uint8]int32) - if *vp == nil { - *vp = make(map[uint8]int32, decInferLen(containerLen, d.maxInitLen(), 5)) - } - if containerLen != 0 { - ft.DecMapUint8Int32L(*vp, containerLen, d) - } - } else if containerLen != 0 { - ft.DecMapUint8Int32L(rv2i(rv).(map[uint8]int32), containerLen, d) - } - d.mapEnd() -} -func (fastpathDTSimpleBytes) DecMapUint8Int32L(v map[uint8]int32, containerLen int, d *decoderSimpleBytes) { - if v == nil { - halt.errorInt("cannot decode into nil map[uint8]int32 given stream length: ", int64(containerLen)) - } - hasLen := containerLen >= 0 - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - mk := uint8(chkOvf.UintV(d.d.DecodeUint64(), 8)) - d.mapElemValue() - v[mk] = int32(chkOvf.IntV(d.d.DecodeInt64(), 32)) - } -} -func (d *decoderSimpleBytes) fastpathDecMapUint8Float64R(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTSimpleBytes - containerLen := d.mapStart(d.d.ReadMapStart()) - if rv.Kind() == reflect.Ptr { - vp, _ := rv2i(rv).(*map[uint8]float64) - if *vp == nil { - *vp = make(map[uint8]float64, decInferLen(containerLen, d.maxInitLen(), 9)) - } - if containerLen != 0 { - ft.DecMapUint8Float64L(*vp, containerLen, d) - } - } else if containerLen != 0 { - ft.DecMapUint8Float64L(rv2i(rv).(map[uint8]float64), containerLen, d) - } - d.mapEnd() -} -func (fastpathDTSimpleBytes) DecMapUint8Float64L(v map[uint8]float64, containerLen int, d *decoderSimpleBytes) { - if v == nil { - halt.errorInt("cannot decode into nil map[uint8]float64 given stream length: ", int64(containerLen)) - } - hasLen := containerLen >= 0 - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - mk := uint8(chkOvf.UintV(d.d.DecodeUint64(), 8)) - d.mapElemValue() - v[mk] = d.d.DecodeFloat64() - } -} -func (d *decoderSimpleBytes) fastpathDecMapUint8BoolR(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTSimpleBytes - containerLen := d.mapStart(d.d.ReadMapStart()) - if rv.Kind() == reflect.Ptr { - vp, _ := rv2i(rv).(*map[uint8]bool) - if *vp == nil { - *vp = make(map[uint8]bool, decInferLen(containerLen, d.maxInitLen(), 2)) - } - if containerLen != 0 { - ft.DecMapUint8BoolL(*vp, containerLen, d) - } - } else if containerLen != 0 { - ft.DecMapUint8BoolL(rv2i(rv).(map[uint8]bool), containerLen, d) - } - d.mapEnd() -} -func (fastpathDTSimpleBytes) DecMapUint8BoolL(v map[uint8]bool, containerLen int, d *decoderSimpleBytes) { - if v == nil { - halt.errorInt("cannot decode into nil map[uint8]bool given stream length: ", int64(containerLen)) - } - hasLen := containerLen >= 0 - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - mk := uint8(chkOvf.UintV(d.d.DecodeUint64(), 8)) - d.mapElemValue() - v[mk] = d.d.DecodeBool() - } -} -func (d *decoderSimpleBytes) fastpathDecMapUint64IntfR(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTSimpleBytes - containerLen := d.mapStart(d.d.ReadMapStart()) - if rv.Kind() == reflect.Ptr { - vp, _ := rv2i(rv).(*map[uint64]interface{}) - if *vp == nil { - *vp = make(map[uint64]interface{}, decInferLen(containerLen, d.maxInitLen(), 24)) - } - if containerLen != 0 { - ft.DecMapUint64IntfL(*vp, containerLen, d) - } - } else if containerLen != 0 { - ft.DecMapUint64IntfL(rv2i(rv).(map[uint64]interface{}), containerLen, d) - } - d.mapEnd() -} -func (fastpathDTSimpleBytes) DecMapUint64IntfL(v map[uint64]interface{}, containerLen int, d *decoderSimpleBytes) { - if v == nil { - halt.errorInt("cannot decode into nil map[uint64]interface{} given stream length: ", int64(containerLen)) - } - var mv interface{} - mapGet := !d.h.MapValueReset && !d.h.InterfaceReset - hasLen := containerLen >= 0 - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - mk := d.d.DecodeUint64() - d.mapElemValue() - if mapGet { - mv = v[mk] - } else { - mv = nil - } - d.decode(&mv) - v[mk] = mv - } -} -func (d *decoderSimpleBytes) fastpathDecMapUint64StringR(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTSimpleBytes - containerLen := d.mapStart(d.d.ReadMapStart()) - if rv.Kind() == reflect.Ptr { - vp, _ := rv2i(rv).(*map[uint64]string) - if *vp == nil { - *vp = make(map[uint64]string, decInferLen(containerLen, d.maxInitLen(), 24)) - } - if containerLen != 0 { - ft.DecMapUint64StringL(*vp, containerLen, d) - } - } else if containerLen != 0 { - ft.DecMapUint64StringL(rv2i(rv).(map[uint64]string), containerLen, d) - } - d.mapEnd() -} -func (fastpathDTSimpleBytes) DecMapUint64StringL(v map[uint64]string, containerLen int, d *decoderSimpleBytes) { - if v == nil { - halt.errorInt("cannot decode into nil map[uint64]string given stream length: ", int64(containerLen)) - } - hasLen := containerLen >= 0 - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - mk := d.d.DecodeUint64() - d.mapElemValue() - v[mk] = d.detach2Str(d.d.DecodeStringAsBytes()) - } -} -func (d *decoderSimpleBytes) fastpathDecMapUint64BytesR(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTSimpleBytes - containerLen := d.mapStart(d.d.ReadMapStart()) - if rv.Kind() == reflect.Ptr { - vp, _ := rv2i(rv).(*map[uint64][]byte) - if *vp == nil { - *vp = make(map[uint64][]byte, decInferLen(containerLen, d.maxInitLen(), 32)) - } - if containerLen != 0 { - ft.DecMapUint64BytesL(*vp, containerLen, d) - } - } else if containerLen != 0 { - ft.DecMapUint64BytesL(rv2i(rv).(map[uint64][]byte), containerLen, d) - } - d.mapEnd() -} -func (fastpathDTSimpleBytes) DecMapUint64BytesL(v map[uint64][]byte, containerLen int, d *decoderSimpleBytes) { - if v == nil { - halt.errorInt("cannot decode into nil map[uint64][]byte given stream length: ", int64(containerLen)) - } - var mv []byte - mapGet := !d.h.MapValueReset - hasLen := containerLen >= 0 - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - mk := d.d.DecodeUint64() - d.mapElemValue() - if mapGet { - mv = v[mk] - } else { - mv = nil - } - v[mk], _ = d.decodeBytesInto(mv, false) - } -} -func (d *decoderSimpleBytes) fastpathDecMapUint64Uint8R(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTSimpleBytes - containerLen := d.mapStart(d.d.ReadMapStart()) - if rv.Kind() == reflect.Ptr { - vp, _ := rv2i(rv).(*map[uint64]uint8) - if *vp == nil { - *vp = make(map[uint64]uint8, decInferLen(containerLen, d.maxInitLen(), 9)) - } - if containerLen != 0 { - ft.DecMapUint64Uint8L(*vp, containerLen, d) - } - } else if containerLen != 0 { - ft.DecMapUint64Uint8L(rv2i(rv).(map[uint64]uint8), containerLen, d) - } - d.mapEnd() -} -func (fastpathDTSimpleBytes) DecMapUint64Uint8L(v map[uint64]uint8, containerLen int, d *decoderSimpleBytes) { - if v == nil { - halt.errorInt("cannot decode into nil map[uint64]uint8 given stream length: ", int64(containerLen)) - } - hasLen := containerLen >= 0 - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - mk := d.d.DecodeUint64() - d.mapElemValue() - v[mk] = uint8(chkOvf.UintV(d.d.DecodeUint64(), 8)) - } -} -func (d *decoderSimpleBytes) fastpathDecMapUint64Uint64R(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTSimpleBytes - containerLen := d.mapStart(d.d.ReadMapStart()) - if rv.Kind() == reflect.Ptr { - vp, _ := rv2i(rv).(*map[uint64]uint64) - if *vp == nil { - *vp = make(map[uint64]uint64, decInferLen(containerLen, d.maxInitLen(), 16)) - } - if containerLen != 0 { - ft.DecMapUint64Uint64L(*vp, containerLen, d) - } - } else if containerLen != 0 { - ft.DecMapUint64Uint64L(rv2i(rv).(map[uint64]uint64), containerLen, d) - } - d.mapEnd() -} -func (fastpathDTSimpleBytes) DecMapUint64Uint64L(v map[uint64]uint64, containerLen int, d *decoderSimpleBytes) { - if v == nil { - halt.errorInt("cannot decode into nil map[uint64]uint64 given stream length: ", int64(containerLen)) - } - hasLen := containerLen >= 0 - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - mk := d.d.DecodeUint64() - d.mapElemValue() - v[mk] = d.d.DecodeUint64() - } -} -func (d *decoderSimpleBytes) fastpathDecMapUint64IntR(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTSimpleBytes - containerLen := d.mapStart(d.d.ReadMapStart()) - if rv.Kind() == reflect.Ptr { - vp, _ := rv2i(rv).(*map[uint64]int) - if *vp == nil { - *vp = make(map[uint64]int, decInferLen(containerLen, d.maxInitLen(), 16)) - } - if containerLen != 0 { - ft.DecMapUint64IntL(*vp, containerLen, d) - } - } else if containerLen != 0 { - ft.DecMapUint64IntL(rv2i(rv).(map[uint64]int), containerLen, d) - } - d.mapEnd() -} -func (fastpathDTSimpleBytes) DecMapUint64IntL(v map[uint64]int, containerLen int, d *decoderSimpleBytes) { - if v == nil { - halt.errorInt("cannot decode into nil map[uint64]int given stream length: ", int64(containerLen)) - } - hasLen := containerLen >= 0 - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - mk := d.d.DecodeUint64() - d.mapElemValue() - v[mk] = int(chkOvf.IntV(d.d.DecodeInt64(), intBitsize)) - } -} -func (d *decoderSimpleBytes) fastpathDecMapUint64Int32R(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTSimpleBytes - containerLen := d.mapStart(d.d.ReadMapStart()) - if rv.Kind() == reflect.Ptr { - vp, _ := rv2i(rv).(*map[uint64]int32) - if *vp == nil { - *vp = make(map[uint64]int32, decInferLen(containerLen, d.maxInitLen(), 12)) - } - if containerLen != 0 { - ft.DecMapUint64Int32L(*vp, containerLen, d) - } - } else if containerLen != 0 { - ft.DecMapUint64Int32L(rv2i(rv).(map[uint64]int32), containerLen, d) - } - d.mapEnd() -} -func (fastpathDTSimpleBytes) DecMapUint64Int32L(v map[uint64]int32, containerLen int, d *decoderSimpleBytes) { - if v == nil { - halt.errorInt("cannot decode into nil map[uint64]int32 given stream length: ", int64(containerLen)) - } - hasLen := containerLen >= 0 - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - mk := d.d.DecodeUint64() - d.mapElemValue() - v[mk] = int32(chkOvf.IntV(d.d.DecodeInt64(), 32)) - } -} -func (d *decoderSimpleBytes) fastpathDecMapUint64Float64R(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTSimpleBytes - containerLen := d.mapStart(d.d.ReadMapStart()) - if rv.Kind() == reflect.Ptr { - vp, _ := rv2i(rv).(*map[uint64]float64) - if *vp == nil { - *vp = make(map[uint64]float64, decInferLen(containerLen, d.maxInitLen(), 16)) - } - if containerLen != 0 { - ft.DecMapUint64Float64L(*vp, containerLen, d) - } - } else if containerLen != 0 { - ft.DecMapUint64Float64L(rv2i(rv).(map[uint64]float64), containerLen, d) - } - d.mapEnd() -} -func (fastpathDTSimpleBytes) DecMapUint64Float64L(v map[uint64]float64, containerLen int, d *decoderSimpleBytes) { - if v == nil { - halt.errorInt("cannot decode into nil map[uint64]float64 given stream length: ", int64(containerLen)) - } - hasLen := containerLen >= 0 - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - mk := d.d.DecodeUint64() - d.mapElemValue() - v[mk] = d.d.DecodeFloat64() - } -} -func (d *decoderSimpleBytes) fastpathDecMapUint64BoolR(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTSimpleBytes - containerLen := d.mapStart(d.d.ReadMapStart()) - if rv.Kind() == reflect.Ptr { - vp, _ := rv2i(rv).(*map[uint64]bool) - if *vp == nil { - *vp = make(map[uint64]bool, decInferLen(containerLen, d.maxInitLen(), 9)) - } - if containerLen != 0 { - ft.DecMapUint64BoolL(*vp, containerLen, d) - } - } else if containerLen != 0 { - ft.DecMapUint64BoolL(rv2i(rv).(map[uint64]bool), containerLen, d) - } - d.mapEnd() -} -func (fastpathDTSimpleBytes) DecMapUint64BoolL(v map[uint64]bool, containerLen int, d *decoderSimpleBytes) { - if v == nil { - halt.errorInt("cannot decode into nil map[uint64]bool given stream length: ", int64(containerLen)) - } - hasLen := containerLen >= 0 - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - mk := d.d.DecodeUint64() - d.mapElemValue() - v[mk] = d.d.DecodeBool() - } -} -func (d *decoderSimpleBytes) fastpathDecMapIntIntfR(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTSimpleBytes - containerLen := d.mapStart(d.d.ReadMapStart()) - if rv.Kind() == reflect.Ptr { - vp, _ := rv2i(rv).(*map[int]interface{}) - if *vp == nil { - *vp = make(map[int]interface{}, decInferLen(containerLen, d.maxInitLen(), 24)) - } - if containerLen != 0 { - ft.DecMapIntIntfL(*vp, containerLen, d) - } - } else if containerLen != 0 { - ft.DecMapIntIntfL(rv2i(rv).(map[int]interface{}), containerLen, d) - } - d.mapEnd() -} -func (fastpathDTSimpleBytes) DecMapIntIntfL(v map[int]interface{}, containerLen int, d *decoderSimpleBytes) { - if v == nil { - halt.errorInt("cannot decode into nil map[int]interface{} given stream length: ", int64(containerLen)) - } - var mv interface{} - mapGet := !d.h.MapValueReset && !d.h.InterfaceReset - hasLen := containerLen >= 0 - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - mk := int(chkOvf.IntV(d.d.DecodeInt64(), intBitsize)) - d.mapElemValue() - if mapGet { - mv = v[mk] - } else { - mv = nil - } - d.decode(&mv) - v[mk] = mv - } -} -func (d *decoderSimpleBytes) fastpathDecMapIntStringR(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTSimpleBytes - containerLen := d.mapStart(d.d.ReadMapStart()) - if rv.Kind() == reflect.Ptr { - vp, _ := rv2i(rv).(*map[int]string) - if *vp == nil { - *vp = make(map[int]string, decInferLen(containerLen, d.maxInitLen(), 24)) - } - if containerLen != 0 { - ft.DecMapIntStringL(*vp, containerLen, d) - } - } else if containerLen != 0 { - ft.DecMapIntStringL(rv2i(rv).(map[int]string), containerLen, d) - } - d.mapEnd() -} -func (fastpathDTSimpleBytes) DecMapIntStringL(v map[int]string, containerLen int, d *decoderSimpleBytes) { - if v == nil { - halt.errorInt("cannot decode into nil map[int]string given stream length: ", int64(containerLen)) - } - hasLen := containerLen >= 0 - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - mk := int(chkOvf.IntV(d.d.DecodeInt64(), intBitsize)) - d.mapElemValue() - v[mk] = d.detach2Str(d.d.DecodeStringAsBytes()) - } -} -func (d *decoderSimpleBytes) fastpathDecMapIntBytesR(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTSimpleBytes - containerLen := d.mapStart(d.d.ReadMapStart()) - if rv.Kind() == reflect.Ptr { - vp, _ := rv2i(rv).(*map[int][]byte) - if *vp == nil { - *vp = make(map[int][]byte, decInferLen(containerLen, d.maxInitLen(), 32)) - } - if containerLen != 0 { - ft.DecMapIntBytesL(*vp, containerLen, d) - } - } else if containerLen != 0 { - ft.DecMapIntBytesL(rv2i(rv).(map[int][]byte), containerLen, d) - } - d.mapEnd() -} -func (fastpathDTSimpleBytes) DecMapIntBytesL(v map[int][]byte, containerLen int, d *decoderSimpleBytes) { - if v == nil { - halt.errorInt("cannot decode into nil map[int][]byte given stream length: ", int64(containerLen)) - } - var mv []byte - mapGet := !d.h.MapValueReset - hasLen := containerLen >= 0 - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - mk := int(chkOvf.IntV(d.d.DecodeInt64(), intBitsize)) - d.mapElemValue() - if mapGet { - mv = v[mk] - } else { - mv = nil - } - v[mk], _ = d.decodeBytesInto(mv, false) - } -} -func (d *decoderSimpleBytes) fastpathDecMapIntUint8R(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTSimpleBytes - containerLen := d.mapStart(d.d.ReadMapStart()) - if rv.Kind() == reflect.Ptr { - vp, _ := rv2i(rv).(*map[int]uint8) - if *vp == nil { - *vp = make(map[int]uint8, decInferLen(containerLen, d.maxInitLen(), 9)) - } - if containerLen != 0 { - ft.DecMapIntUint8L(*vp, containerLen, d) - } - } else if containerLen != 0 { - ft.DecMapIntUint8L(rv2i(rv).(map[int]uint8), containerLen, d) - } - d.mapEnd() -} -func (fastpathDTSimpleBytes) DecMapIntUint8L(v map[int]uint8, containerLen int, d *decoderSimpleBytes) { - if v == nil { - halt.errorInt("cannot decode into nil map[int]uint8 given stream length: ", int64(containerLen)) - } - hasLen := containerLen >= 0 - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - mk := int(chkOvf.IntV(d.d.DecodeInt64(), intBitsize)) - d.mapElemValue() - v[mk] = uint8(chkOvf.UintV(d.d.DecodeUint64(), 8)) - } -} -func (d *decoderSimpleBytes) fastpathDecMapIntUint64R(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTSimpleBytes - containerLen := d.mapStart(d.d.ReadMapStart()) - if rv.Kind() == reflect.Ptr { - vp, _ := rv2i(rv).(*map[int]uint64) - if *vp == nil { - *vp = make(map[int]uint64, decInferLen(containerLen, d.maxInitLen(), 16)) - } - if containerLen != 0 { - ft.DecMapIntUint64L(*vp, containerLen, d) - } - } else if containerLen != 0 { - ft.DecMapIntUint64L(rv2i(rv).(map[int]uint64), containerLen, d) - } - d.mapEnd() -} -func (fastpathDTSimpleBytes) DecMapIntUint64L(v map[int]uint64, containerLen int, d *decoderSimpleBytes) { - if v == nil { - halt.errorInt("cannot decode into nil map[int]uint64 given stream length: ", int64(containerLen)) - } - hasLen := containerLen >= 0 - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - mk := int(chkOvf.IntV(d.d.DecodeInt64(), intBitsize)) - d.mapElemValue() - v[mk] = d.d.DecodeUint64() - } -} -func (d *decoderSimpleBytes) fastpathDecMapIntIntR(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTSimpleBytes - containerLen := d.mapStart(d.d.ReadMapStart()) - if rv.Kind() == reflect.Ptr { - vp, _ := rv2i(rv).(*map[int]int) - if *vp == nil { - *vp = make(map[int]int, decInferLen(containerLen, d.maxInitLen(), 16)) - } - if containerLen != 0 { - ft.DecMapIntIntL(*vp, containerLen, d) - } - } else if containerLen != 0 { - ft.DecMapIntIntL(rv2i(rv).(map[int]int), containerLen, d) - } - d.mapEnd() -} -func (fastpathDTSimpleBytes) DecMapIntIntL(v map[int]int, containerLen int, d *decoderSimpleBytes) { - if v == nil { - halt.errorInt("cannot decode into nil map[int]int given stream length: ", int64(containerLen)) - } - hasLen := containerLen >= 0 - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - mk := int(chkOvf.IntV(d.d.DecodeInt64(), intBitsize)) - d.mapElemValue() - v[mk] = int(chkOvf.IntV(d.d.DecodeInt64(), intBitsize)) - } -} -func (d *decoderSimpleBytes) fastpathDecMapIntInt32R(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTSimpleBytes - containerLen := d.mapStart(d.d.ReadMapStart()) - if rv.Kind() == reflect.Ptr { - vp, _ := rv2i(rv).(*map[int]int32) - if *vp == nil { - *vp = make(map[int]int32, decInferLen(containerLen, d.maxInitLen(), 12)) - } - if containerLen != 0 { - ft.DecMapIntInt32L(*vp, containerLen, d) - } - } else if containerLen != 0 { - ft.DecMapIntInt32L(rv2i(rv).(map[int]int32), containerLen, d) - } - d.mapEnd() -} -func (fastpathDTSimpleBytes) DecMapIntInt32L(v map[int]int32, containerLen int, d *decoderSimpleBytes) { - if v == nil { - halt.errorInt("cannot decode into nil map[int]int32 given stream length: ", int64(containerLen)) - } - hasLen := containerLen >= 0 - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - mk := int(chkOvf.IntV(d.d.DecodeInt64(), intBitsize)) - d.mapElemValue() - v[mk] = int32(chkOvf.IntV(d.d.DecodeInt64(), 32)) - } -} -func (d *decoderSimpleBytes) fastpathDecMapIntFloat64R(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTSimpleBytes - containerLen := d.mapStart(d.d.ReadMapStart()) - if rv.Kind() == reflect.Ptr { - vp, _ := rv2i(rv).(*map[int]float64) - if *vp == nil { - *vp = make(map[int]float64, decInferLen(containerLen, d.maxInitLen(), 16)) - } - if containerLen != 0 { - ft.DecMapIntFloat64L(*vp, containerLen, d) - } - } else if containerLen != 0 { - ft.DecMapIntFloat64L(rv2i(rv).(map[int]float64), containerLen, d) - } - d.mapEnd() -} -func (fastpathDTSimpleBytes) DecMapIntFloat64L(v map[int]float64, containerLen int, d *decoderSimpleBytes) { - if v == nil { - halt.errorInt("cannot decode into nil map[int]float64 given stream length: ", int64(containerLen)) - } - hasLen := containerLen >= 0 - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - mk := int(chkOvf.IntV(d.d.DecodeInt64(), intBitsize)) - d.mapElemValue() - v[mk] = d.d.DecodeFloat64() - } -} -func (d *decoderSimpleBytes) fastpathDecMapIntBoolR(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTSimpleBytes - containerLen := d.mapStart(d.d.ReadMapStart()) - if rv.Kind() == reflect.Ptr { - vp, _ := rv2i(rv).(*map[int]bool) - if *vp == nil { - *vp = make(map[int]bool, decInferLen(containerLen, d.maxInitLen(), 9)) - } - if containerLen != 0 { - ft.DecMapIntBoolL(*vp, containerLen, d) - } - } else if containerLen != 0 { - ft.DecMapIntBoolL(rv2i(rv).(map[int]bool), containerLen, d) - } - d.mapEnd() -} -func (fastpathDTSimpleBytes) DecMapIntBoolL(v map[int]bool, containerLen int, d *decoderSimpleBytes) { - if v == nil { - halt.errorInt("cannot decode into nil map[int]bool given stream length: ", int64(containerLen)) - } - hasLen := containerLen >= 0 - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - mk := int(chkOvf.IntV(d.d.DecodeInt64(), intBitsize)) - d.mapElemValue() - v[mk] = d.d.DecodeBool() - } -} -func (d *decoderSimpleBytes) fastpathDecMapInt32IntfR(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTSimpleBytes - containerLen := d.mapStart(d.d.ReadMapStart()) - if rv.Kind() == reflect.Ptr { - vp, _ := rv2i(rv).(*map[int32]interface{}) - if *vp == nil { - *vp = make(map[int32]interface{}, decInferLen(containerLen, d.maxInitLen(), 20)) - } - if containerLen != 0 { - ft.DecMapInt32IntfL(*vp, containerLen, d) - } - } else if containerLen != 0 { - ft.DecMapInt32IntfL(rv2i(rv).(map[int32]interface{}), containerLen, d) - } - d.mapEnd() -} -func (fastpathDTSimpleBytes) DecMapInt32IntfL(v map[int32]interface{}, containerLen int, d *decoderSimpleBytes) { - if v == nil { - halt.errorInt("cannot decode into nil map[int32]interface{} given stream length: ", int64(containerLen)) - } - var mv interface{} - mapGet := !d.h.MapValueReset && !d.h.InterfaceReset - hasLen := containerLen >= 0 - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - mk := int32(chkOvf.IntV(d.d.DecodeInt64(), 32)) - d.mapElemValue() - if mapGet { - mv = v[mk] - } else { - mv = nil - } - d.decode(&mv) - v[mk] = mv - } -} -func (d *decoderSimpleBytes) fastpathDecMapInt32StringR(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTSimpleBytes - containerLen := d.mapStart(d.d.ReadMapStart()) - if rv.Kind() == reflect.Ptr { - vp, _ := rv2i(rv).(*map[int32]string) - if *vp == nil { - *vp = make(map[int32]string, decInferLen(containerLen, d.maxInitLen(), 20)) - } - if containerLen != 0 { - ft.DecMapInt32StringL(*vp, containerLen, d) - } - } else if containerLen != 0 { - ft.DecMapInt32StringL(rv2i(rv).(map[int32]string), containerLen, d) - } - d.mapEnd() -} -func (fastpathDTSimpleBytes) DecMapInt32StringL(v map[int32]string, containerLen int, d *decoderSimpleBytes) { - if v == nil { - halt.errorInt("cannot decode into nil map[int32]string given stream length: ", int64(containerLen)) - } - hasLen := containerLen >= 0 - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - mk := int32(chkOvf.IntV(d.d.DecodeInt64(), 32)) - d.mapElemValue() - v[mk] = d.detach2Str(d.d.DecodeStringAsBytes()) - } -} -func (d *decoderSimpleBytes) fastpathDecMapInt32BytesR(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTSimpleBytes - containerLen := d.mapStart(d.d.ReadMapStart()) - if rv.Kind() == reflect.Ptr { - vp, _ := rv2i(rv).(*map[int32][]byte) - if *vp == nil { - *vp = make(map[int32][]byte, decInferLen(containerLen, d.maxInitLen(), 28)) - } - if containerLen != 0 { - ft.DecMapInt32BytesL(*vp, containerLen, d) - } - } else if containerLen != 0 { - ft.DecMapInt32BytesL(rv2i(rv).(map[int32][]byte), containerLen, d) - } - d.mapEnd() -} -func (fastpathDTSimpleBytes) DecMapInt32BytesL(v map[int32][]byte, containerLen int, d *decoderSimpleBytes) { - if v == nil { - halt.errorInt("cannot decode into nil map[int32][]byte given stream length: ", int64(containerLen)) - } - var mv []byte - mapGet := !d.h.MapValueReset - hasLen := containerLen >= 0 - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - mk := int32(chkOvf.IntV(d.d.DecodeInt64(), 32)) - d.mapElemValue() - if mapGet { - mv = v[mk] - } else { - mv = nil - } - v[mk], _ = d.decodeBytesInto(mv, false) - } -} -func (d *decoderSimpleBytes) fastpathDecMapInt32Uint8R(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTSimpleBytes - containerLen := d.mapStart(d.d.ReadMapStart()) - if rv.Kind() == reflect.Ptr { - vp, _ := rv2i(rv).(*map[int32]uint8) - if *vp == nil { - *vp = make(map[int32]uint8, decInferLen(containerLen, d.maxInitLen(), 5)) - } - if containerLen != 0 { - ft.DecMapInt32Uint8L(*vp, containerLen, d) - } - } else if containerLen != 0 { - ft.DecMapInt32Uint8L(rv2i(rv).(map[int32]uint8), containerLen, d) - } - d.mapEnd() -} -func (fastpathDTSimpleBytes) DecMapInt32Uint8L(v map[int32]uint8, containerLen int, d *decoderSimpleBytes) { - if v == nil { - halt.errorInt("cannot decode into nil map[int32]uint8 given stream length: ", int64(containerLen)) - } - hasLen := containerLen >= 0 - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - mk := int32(chkOvf.IntV(d.d.DecodeInt64(), 32)) - d.mapElemValue() - v[mk] = uint8(chkOvf.UintV(d.d.DecodeUint64(), 8)) - } -} -func (d *decoderSimpleBytes) fastpathDecMapInt32Uint64R(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTSimpleBytes - containerLen := d.mapStart(d.d.ReadMapStart()) - if rv.Kind() == reflect.Ptr { - vp, _ := rv2i(rv).(*map[int32]uint64) - if *vp == nil { - *vp = make(map[int32]uint64, decInferLen(containerLen, d.maxInitLen(), 12)) - } - if containerLen != 0 { - ft.DecMapInt32Uint64L(*vp, containerLen, d) - } - } else if containerLen != 0 { - ft.DecMapInt32Uint64L(rv2i(rv).(map[int32]uint64), containerLen, d) - } - d.mapEnd() -} -func (fastpathDTSimpleBytes) DecMapInt32Uint64L(v map[int32]uint64, containerLen int, d *decoderSimpleBytes) { - if v == nil { - halt.errorInt("cannot decode into nil map[int32]uint64 given stream length: ", int64(containerLen)) - } - hasLen := containerLen >= 0 - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - mk := int32(chkOvf.IntV(d.d.DecodeInt64(), 32)) - d.mapElemValue() - v[mk] = d.d.DecodeUint64() - } -} -func (d *decoderSimpleBytes) fastpathDecMapInt32IntR(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTSimpleBytes - containerLen := d.mapStart(d.d.ReadMapStart()) - if rv.Kind() == reflect.Ptr { - vp, _ := rv2i(rv).(*map[int32]int) - if *vp == nil { - *vp = make(map[int32]int, decInferLen(containerLen, d.maxInitLen(), 12)) - } - if containerLen != 0 { - ft.DecMapInt32IntL(*vp, containerLen, d) - } - } else if containerLen != 0 { - ft.DecMapInt32IntL(rv2i(rv).(map[int32]int), containerLen, d) - } - d.mapEnd() -} -func (fastpathDTSimpleBytes) DecMapInt32IntL(v map[int32]int, containerLen int, d *decoderSimpleBytes) { - if v == nil { - halt.errorInt("cannot decode into nil map[int32]int given stream length: ", int64(containerLen)) - } - hasLen := containerLen >= 0 - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - mk := int32(chkOvf.IntV(d.d.DecodeInt64(), 32)) - d.mapElemValue() - v[mk] = int(chkOvf.IntV(d.d.DecodeInt64(), intBitsize)) - } -} -func (d *decoderSimpleBytes) fastpathDecMapInt32Int32R(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTSimpleBytes - containerLen := d.mapStart(d.d.ReadMapStart()) - if rv.Kind() == reflect.Ptr { - vp, _ := rv2i(rv).(*map[int32]int32) - if *vp == nil { - *vp = make(map[int32]int32, decInferLen(containerLen, d.maxInitLen(), 8)) - } - if containerLen != 0 { - ft.DecMapInt32Int32L(*vp, containerLen, d) - } - } else if containerLen != 0 { - ft.DecMapInt32Int32L(rv2i(rv).(map[int32]int32), containerLen, d) - } - d.mapEnd() -} -func (fastpathDTSimpleBytes) DecMapInt32Int32L(v map[int32]int32, containerLen int, d *decoderSimpleBytes) { - if v == nil { - halt.errorInt("cannot decode into nil map[int32]int32 given stream length: ", int64(containerLen)) - } - hasLen := containerLen >= 0 - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - mk := int32(chkOvf.IntV(d.d.DecodeInt64(), 32)) - d.mapElemValue() - v[mk] = int32(chkOvf.IntV(d.d.DecodeInt64(), 32)) - } -} -func (d *decoderSimpleBytes) fastpathDecMapInt32Float64R(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTSimpleBytes - containerLen := d.mapStart(d.d.ReadMapStart()) - if rv.Kind() == reflect.Ptr { - vp, _ := rv2i(rv).(*map[int32]float64) - if *vp == nil { - *vp = make(map[int32]float64, decInferLen(containerLen, d.maxInitLen(), 12)) - } - if containerLen != 0 { - ft.DecMapInt32Float64L(*vp, containerLen, d) - } - } else if containerLen != 0 { - ft.DecMapInt32Float64L(rv2i(rv).(map[int32]float64), containerLen, d) - } - d.mapEnd() -} -func (fastpathDTSimpleBytes) DecMapInt32Float64L(v map[int32]float64, containerLen int, d *decoderSimpleBytes) { - if v == nil { - halt.errorInt("cannot decode into nil map[int32]float64 given stream length: ", int64(containerLen)) - } - hasLen := containerLen >= 0 - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - mk := int32(chkOvf.IntV(d.d.DecodeInt64(), 32)) - d.mapElemValue() - v[mk] = d.d.DecodeFloat64() - } -} -func (d *decoderSimpleBytes) fastpathDecMapInt32BoolR(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTSimpleBytes - containerLen := d.mapStart(d.d.ReadMapStart()) - if rv.Kind() == reflect.Ptr { - vp, _ := rv2i(rv).(*map[int32]bool) - if *vp == nil { - *vp = make(map[int32]bool, decInferLen(containerLen, d.maxInitLen(), 5)) - } - if containerLen != 0 { - ft.DecMapInt32BoolL(*vp, containerLen, d) - } - } else if containerLen != 0 { - ft.DecMapInt32BoolL(rv2i(rv).(map[int32]bool), containerLen, d) - } - d.mapEnd() -} -func (fastpathDTSimpleBytes) DecMapInt32BoolL(v map[int32]bool, containerLen int, d *decoderSimpleBytes) { - if v == nil { - halt.errorInt("cannot decode into nil map[int32]bool given stream length: ", int64(containerLen)) - } - hasLen := containerLen >= 0 - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - mk := int32(chkOvf.IntV(d.d.DecodeInt64(), 32)) - d.mapElemValue() - v[mk] = d.d.DecodeBool() - } -} - -type fastpathESimpleIO struct { - rtid uintptr - rt reflect.Type - encfn func(*encoderSimpleIO, *encFnInfo, reflect.Value) -} -type fastpathDSimpleIO struct { - rtid uintptr - rt reflect.Type - decfn func(*decoderSimpleIO, *decFnInfo, reflect.Value) -} -type fastpathEsSimpleIO [56]fastpathESimpleIO -type fastpathDsSimpleIO [56]fastpathDSimpleIO -type fastpathETSimpleIO struct{} -type fastpathDTSimpleIO struct{} - -func (helperEncDriverSimpleIO) fastpathEList() *fastpathEsSimpleIO { - var i uint = 0 - var s fastpathEsSimpleIO - fn := func(v interface{}, fe func(*encoderSimpleIO, *encFnInfo, reflect.Value)) { - xrt := reflect.TypeOf(v) - s[i] = fastpathESimpleIO{rt2id(xrt), xrt, fe} - i++ - } - - fn([]interface{}(nil), (*encoderSimpleIO).fastpathEncSliceIntfR) - fn([]string(nil), (*encoderSimpleIO).fastpathEncSliceStringR) - fn([][]byte(nil), (*encoderSimpleIO).fastpathEncSliceBytesR) - fn([]float32(nil), (*encoderSimpleIO).fastpathEncSliceFloat32R) - fn([]float64(nil), (*encoderSimpleIO).fastpathEncSliceFloat64R) - fn([]uint8(nil), (*encoderSimpleIO).fastpathEncSliceUint8R) - fn([]uint64(nil), (*encoderSimpleIO).fastpathEncSliceUint64R) - fn([]int(nil), (*encoderSimpleIO).fastpathEncSliceIntR) - fn([]int32(nil), (*encoderSimpleIO).fastpathEncSliceInt32R) - fn([]int64(nil), (*encoderSimpleIO).fastpathEncSliceInt64R) - fn([]bool(nil), (*encoderSimpleIO).fastpathEncSliceBoolR) - - fn(map[string]interface{}(nil), (*encoderSimpleIO).fastpathEncMapStringIntfR) - fn(map[string]string(nil), (*encoderSimpleIO).fastpathEncMapStringStringR) - fn(map[string][]byte(nil), (*encoderSimpleIO).fastpathEncMapStringBytesR) - fn(map[string]uint8(nil), (*encoderSimpleIO).fastpathEncMapStringUint8R) - fn(map[string]uint64(nil), (*encoderSimpleIO).fastpathEncMapStringUint64R) - fn(map[string]int(nil), (*encoderSimpleIO).fastpathEncMapStringIntR) - fn(map[string]int32(nil), (*encoderSimpleIO).fastpathEncMapStringInt32R) - fn(map[string]float64(nil), (*encoderSimpleIO).fastpathEncMapStringFloat64R) - fn(map[string]bool(nil), (*encoderSimpleIO).fastpathEncMapStringBoolR) - fn(map[uint8]interface{}(nil), (*encoderSimpleIO).fastpathEncMapUint8IntfR) - fn(map[uint8]string(nil), (*encoderSimpleIO).fastpathEncMapUint8StringR) - fn(map[uint8][]byte(nil), (*encoderSimpleIO).fastpathEncMapUint8BytesR) - fn(map[uint8]uint8(nil), (*encoderSimpleIO).fastpathEncMapUint8Uint8R) - fn(map[uint8]uint64(nil), (*encoderSimpleIO).fastpathEncMapUint8Uint64R) - fn(map[uint8]int(nil), (*encoderSimpleIO).fastpathEncMapUint8IntR) - fn(map[uint8]int32(nil), (*encoderSimpleIO).fastpathEncMapUint8Int32R) - fn(map[uint8]float64(nil), (*encoderSimpleIO).fastpathEncMapUint8Float64R) - fn(map[uint8]bool(nil), (*encoderSimpleIO).fastpathEncMapUint8BoolR) - fn(map[uint64]interface{}(nil), (*encoderSimpleIO).fastpathEncMapUint64IntfR) - fn(map[uint64]string(nil), (*encoderSimpleIO).fastpathEncMapUint64StringR) - fn(map[uint64][]byte(nil), (*encoderSimpleIO).fastpathEncMapUint64BytesR) - fn(map[uint64]uint8(nil), (*encoderSimpleIO).fastpathEncMapUint64Uint8R) - fn(map[uint64]uint64(nil), (*encoderSimpleIO).fastpathEncMapUint64Uint64R) - fn(map[uint64]int(nil), (*encoderSimpleIO).fastpathEncMapUint64IntR) - fn(map[uint64]int32(nil), (*encoderSimpleIO).fastpathEncMapUint64Int32R) - fn(map[uint64]float64(nil), (*encoderSimpleIO).fastpathEncMapUint64Float64R) - fn(map[uint64]bool(nil), (*encoderSimpleIO).fastpathEncMapUint64BoolR) - fn(map[int]interface{}(nil), (*encoderSimpleIO).fastpathEncMapIntIntfR) - fn(map[int]string(nil), (*encoderSimpleIO).fastpathEncMapIntStringR) - fn(map[int][]byte(nil), (*encoderSimpleIO).fastpathEncMapIntBytesR) - fn(map[int]uint8(nil), (*encoderSimpleIO).fastpathEncMapIntUint8R) - fn(map[int]uint64(nil), (*encoderSimpleIO).fastpathEncMapIntUint64R) - fn(map[int]int(nil), (*encoderSimpleIO).fastpathEncMapIntIntR) - fn(map[int]int32(nil), (*encoderSimpleIO).fastpathEncMapIntInt32R) - fn(map[int]float64(nil), (*encoderSimpleIO).fastpathEncMapIntFloat64R) - fn(map[int]bool(nil), (*encoderSimpleIO).fastpathEncMapIntBoolR) - fn(map[int32]interface{}(nil), (*encoderSimpleIO).fastpathEncMapInt32IntfR) - fn(map[int32]string(nil), (*encoderSimpleIO).fastpathEncMapInt32StringR) - fn(map[int32][]byte(nil), (*encoderSimpleIO).fastpathEncMapInt32BytesR) - fn(map[int32]uint8(nil), (*encoderSimpleIO).fastpathEncMapInt32Uint8R) - fn(map[int32]uint64(nil), (*encoderSimpleIO).fastpathEncMapInt32Uint64R) - fn(map[int32]int(nil), (*encoderSimpleIO).fastpathEncMapInt32IntR) - fn(map[int32]int32(nil), (*encoderSimpleIO).fastpathEncMapInt32Int32R) - fn(map[int32]float64(nil), (*encoderSimpleIO).fastpathEncMapInt32Float64R) - fn(map[int32]bool(nil), (*encoderSimpleIO).fastpathEncMapInt32BoolR) - - sort.Slice(s[:], func(i, j int) bool { return s[i].rtid < s[j].rtid }) - return &s -} - -func (helperDecDriverSimpleIO) fastpathDList() *fastpathDsSimpleIO { - var i uint = 0 - var s fastpathDsSimpleIO - fn := func(v interface{}, fd func(*decoderSimpleIO, *decFnInfo, reflect.Value)) { - xrt := reflect.TypeOf(v) - s[i] = fastpathDSimpleIO{rt2id(xrt), xrt, fd} - i++ - } - - fn([]interface{}(nil), (*decoderSimpleIO).fastpathDecSliceIntfR) - fn([]string(nil), (*decoderSimpleIO).fastpathDecSliceStringR) - fn([][]byte(nil), (*decoderSimpleIO).fastpathDecSliceBytesR) - fn([]float32(nil), (*decoderSimpleIO).fastpathDecSliceFloat32R) - fn([]float64(nil), (*decoderSimpleIO).fastpathDecSliceFloat64R) - fn([]uint8(nil), (*decoderSimpleIO).fastpathDecSliceUint8R) - fn([]uint64(nil), (*decoderSimpleIO).fastpathDecSliceUint64R) - fn([]int(nil), (*decoderSimpleIO).fastpathDecSliceIntR) - fn([]int32(nil), (*decoderSimpleIO).fastpathDecSliceInt32R) - fn([]int64(nil), (*decoderSimpleIO).fastpathDecSliceInt64R) - fn([]bool(nil), (*decoderSimpleIO).fastpathDecSliceBoolR) - - fn(map[string]interface{}(nil), (*decoderSimpleIO).fastpathDecMapStringIntfR) - fn(map[string]string(nil), (*decoderSimpleIO).fastpathDecMapStringStringR) - fn(map[string][]byte(nil), (*decoderSimpleIO).fastpathDecMapStringBytesR) - fn(map[string]uint8(nil), (*decoderSimpleIO).fastpathDecMapStringUint8R) - fn(map[string]uint64(nil), (*decoderSimpleIO).fastpathDecMapStringUint64R) - fn(map[string]int(nil), (*decoderSimpleIO).fastpathDecMapStringIntR) - fn(map[string]int32(nil), (*decoderSimpleIO).fastpathDecMapStringInt32R) - fn(map[string]float64(nil), (*decoderSimpleIO).fastpathDecMapStringFloat64R) - fn(map[string]bool(nil), (*decoderSimpleIO).fastpathDecMapStringBoolR) - fn(map[uint8]interface{}(nil), (*decoderSimpleIO).fastpathDecMapUint8IntfR) - fn(map[uint8]string(nil), (*decoderSimpleIO).fastpathDecMapUint8StringR) - fn(map[uint8][]byte(nil), (*decoderSimpleIO).fastpathDecMapUint8BytesR) - fn(map[uint8]uint8(nil), (*decoderSimpleIO).fastpathDecMapUint8Uint8R) - fn(map[uint8]uint64(nil), (*decoderSimpleIO).fastpathDecMapUint8Uint64R) - fn(map[uint8]int(nil), (*decoderSimpleIO).fastpathDecMapUint8IntR) - fn(map[uint8]int32(nil), (*decoderSimpleIO).fastpathDecMapUint8Int32R) - fn(map[uint8]float64(nil), (*decoderSimpleIO).fastpathDecMapUint8Float64R) - fn(map[uint8]bool(nil), (*decoderSimpleIO).fastpathDecMapUint8BoolR) - fn(map[uint64]interface{}(nil), (*decoderSimpleIO).fastpathDecMapUint64IntfR) - fn(map[uint64]string(nil), (*decoderSimpleIO).fastpathDecMapUint64StringR) - fn(map[uint64][]byte(nil), (*decoderSimpleIO).fastpathDecMapUint64BytesR) - fn(map[uint64]uint8(nil), (*decoderSimpleIO).fastpathDecMapUint64Uint8R) - fn(map[uint64]uint64(nil), (*decoderSimpleIO).fastpathDecMapUint64Uint64R) - fn(map[uint64]int(nil), (*decoderSimpleIO).fastpathDecMapUint64IntR) - fn(map[uint64]int32(nil), (*decoderSimpleIO).fastpathDecMapUint64Int32R) - fn(map[uint64]float64(nil), (*decoderSimpleIO).fastpathDecMapUint64Float64R) - fn(map[uint64]bool(nil), (*decoderSimpleIO).fastpathDecMapUint64BoolR) - fn(map[int]interface{}(nil), (*decoderSimpleIO).fastpathDecMapIntIntfR) - fn(map[int]string(nil), (*decoderSimpleIO).fastpathDecMapIntStringR) - fn(map[int][]byte(nil), (*decoderSimpleIO).fastpathDecMapIntBytesR) - fn(map[int]uint8(nil), (*decoderSimpleIO).fastpathDecMapIntUint8R) - fn(map[int]uint64(nil), (*decoderSimpleIO).fastpathDecMapIntUint64R) - fn(map[int]int(nil), (*decoderSimpleIO).fastpathDecMapIntIntR) - fn(map[int]int32(nil), (*decoderSimpleIO).fastpathDecMapIntInt32R) - fn(map[int]float64(nil), (*decoderSimpleIO).fastpathDecMapIntFloat64R) - fn(map[int]bool(nil), (*decoderSimpleIO).fastpathDecMapIntBoolR) - fn(map[int32]interface{}(nil), (*decoderSimpleIO).fastpathDecMapInt32IntfR) - fn(map[int32]string(nil), (*decoderSimpleIO).fastpathDecMapInt32StringR) - fn(map[int32][]byte(nil), (*decoderSimpleIO).fastpathDecMapInt32BytesR) - fn(map[int32]uint8(nil), (*decoderSimpleIO).fastpathDecMapInt32Uint8R) - fn(map[int32]uint64(nil), (*decoderSimpleIO).fastpathDecMapInt32Uint64R) - fn(map[int32]int(nil), (*decoderSimpleIO).fastpathDecMapInt32IntR) - fn(map[int32]int32(nil), (*decoderSimpleIO).fastpathDecMapInt32Int32R) - fn(map[int32]float64(nil), (*decoderSimpleIO).fastpathDecMapInt32Float64R) - fn(map[int32]bool(nil), (*decoderSimpleIO).fastpathDecMapInt32BoolR) - - sort.Slice(s[:], func(i, j int) bool { return s[i].rtid < s[j].rtid }) - return &s -} - -func (helperEncDriverSimpleIO) fastpathEncodeTypeSwitch(iv interface{}, e *encoderSimpleIO) bool { - var ft fastpathETSimpleIO - switch v := iv.(type) { - case []interface{}: - if v == nil { - e.e.writeNilArray() - } else { - ft.EncSliceIntfV(v, e) - } - case []string: - if v == nil { - e.e.writeNilArray() - } else { - ft.EncSliceStringV(v, e) - } - case [][]byte: - if v == nil { - e.e.writeNilArray() - } else { - ft.EncSliceBytesV(v, e) - } - case []float32: - if v == nil { - e.e.writeNilArray() - } else { - ft.EncSliceFloat32V(v, e) - } - case []float64: - if v == nil { - e.e.writeNilArray() - } else { - ft.EncSliceFloat64V(v, e) - } - case []uint8: - if v == nil { - e.e.writeNilArray() - } else { - ft.EncSliceUint8V(v, e) - } - case []uint64: - if v == nil { - e.e.writeNilArray() - } else { - ft.EncSliceUint64V(v, e) - } - case []int: - if v == nil { - e.e.writeNilArray() - } else { - ft.EncSliceIntV(v, e) - } - case []int32: - if v == nil { - e.e.writeNilArray() - } else { - ft.EncSliceInt32V(v, e) - } - case []int64: - if v == nil { - e.e.writeNilArray() - } else { - ft.EncSliceInt64V(v, e) - } - case []bool: - if v == nil { - e.e.writeNilArray() - } else { - ft.EncSliceBoolV(v, e) - } - case map[string]interface{}: - if v == nil { - e.e.writeNilMap() - } else { - ft.EncMapStringIntfV(v, e) - } - case map[string]string: - if v == nil { - e.e.writeNilMap() - } else { - ft.EncMapStringStringV(v, e) - } - case map[string][]byte: - if v == nil { - e.e.writeNilMap() - } else { - ft.EncMapStringBytesV(v, e) - } - case map[string]uint8: - if v == nil { - e.e.writeNilMap() - } else { - ft.EncMapStringUint8V(v, e) - } - case map[string]uint64: - if v == nil { - e.e.writeNilMap() - } else { - ft.EncMapStringUint64V(v, e) - } - case map[string]int: - if v == nil { - e.e.writeNilMap() - } else { - ft.EncMapStringIntV(v, e) - } - case map[string]int32: - if v == nil { - e.e.writeNilMap() - } else { - ft.EncMapStringInt32V(v, e) - } - case map[string]float64: - if v == nil { - e.e.writeNilMap() - } else { - ft.EncMapStringFloat64V(v, e) - } - case map[string]bool: - if v == nil { - e.e.writeNilMap() - } else { - ft.EncMapStringBoolV(v, e) - } - case map[uint8]interface{}: - if v == nil { - e.e.writeNilMap() - } else { - ft.EncMapUint8IntfV(v, e) - } - case map[uint8]string: - if v == nil { - e.e.writeNilMap() - } else { - ft.EncMapUint8StringV(v, e) - } - case map[uint8][]byte: - if v == nil { - e.e.writeNilMap() - } else { - ft.EncMapUint8BytesV(v, e) - } - case map[uint8]uint8: - if v == nil { - e.e.writeNilMap() - } else { - ft.EncMapUint8Uint8V(v, e) - } - case map[uint8]uint64: - if v == nil { - e.e.writeNilMap() - } else { - ft.EncMapUint8Uint64V(v, e) - } - case map[uint8]int: - if v == nil { - e.e.writeNilMap() - } else { - ft.EncMapUint8IntV(v, e) - } - case map[uint8]int32: - if v == nil { - e.e.writeNilMap() - } else { - ft.EncMapUint8Int32V(v, e) - } - case map[uint8]float64: - if v == nil { - e.e.writeNilMap() - } else { - ft.EncMapUint8Float64V(v, e) - } - case map[uint8]bool: - if v == nil { - e.e.writeNilMap() - } else { - ft.EncMapUint8BoolV(v, e) - } - case map[uint64]interface{}: - if v == nil { - e.e.writeNilMap() - } else { - ft.EncMapUint64IntfV(v, e) - } - case map[uint64]string: - if v == nil { - e.e.writeNilMap() - } else { - ft.EncMapUint64StringV(v, e) - } - case map[uint64][]byte: - if v == nil { - e.e.writeNilMap() - } else { - ft.EncMapUint64BytesV(v, e) - } - case map[uint64]uint8: - if v == nil { - e.e.writeNilMap() - } else { - ft.EncMapUint64Uint8V(v, e) - } - case map[uint64]uint64: - if v == nil { - e.e.writeNilMap() - } else { - ft.EncMapUint64Uint64V(v, e) - } - case map[uint64]int: - if v == nil { - e.e.writeNilMap() - } else { - ft.EncMapUint64IntV(v, e) - } - case map[uint64]int32: - if v == nil { - e.e.writeNilMap() - } else { - ft.EncMapUint64Int32V(v, e) - } - case map[uint64]float64: - if v == nil { - e.e.writeNilMap() - } else { - ft.EncMapUint64Float64V(v, e) - } - case map[uint64]bool: - if v == nil { - e.e.writeNilMap() - } else { - ft.EncMapUint64BoolV(v, e) - } - case map[int]interface{}: - if v == nil { - e.e.writeNilMap() - } else { - ft.EncMapIntIntfV(v, e) - } - case map[int]string: - if v == nil { - e.e.writeNilMap() - } else { - ft.EncMapIntStringV(v, e) - } - case map[int][]byte: - if v == nil { - e.e.writeNilMap() - } else { - ft.EncMapIntBytesV(v, e) - } - case map[int]uint8: - if v == nil { - e.e.writeNilMap() - } else { - ft.EncMapIntUint8V(v, e) - } - case map[int]uint64: - if v == nil { - e.e.writeNilMap() - } else { - ft.EncMapIntUint64V(v, e) - } - case map[int]int: - if v == nil { - e.e.writeNilMap() - } else { - ft.EncMapIntIntV(v, e) - } - case map[int]int32: - if v == nil { - e.e.writeNilMap() - } else { - ft.EncMapIntInt32V(v, e) - } - case map[int]float64: - if v == nil { - e.e.writeNilMap() - } else { - ft.EncMapIntFloat64V(v, e) - } - case map[int]bool: - if v == nil { - e.e.writeNilMap() - } else { - ft.EncMapIntBoolV(v, e) - } - case map[int32]interface{}: - if v == nil { - e.e.writeNilMap() - } else { - ft.EncMapInt32IntfV(v, e) - } - case map[int32]string: - if v == nil { - e.e.writeNilMap() - } else { - ft.EncMapInt32StringV(v, e) - } - case map[int32][]byte: - if v == nil { - e.e.writeNilMap() - } else { - ft.EncMapInt32BytesV(v, e) - } - case map[int32]uint8: - if v == nil { - e.e.writeNilMap() - } else { - ft.EncMapInt32Uint8V(v, e) - } - case map[int32]uint64: - if v == nil { - e.e.writeNilMap() - } else { - ft.EncMapInt32Uint64V(v, e) - } - case map[int32]int: - if v == nil { - e.e.writeNilMap() - } else { - ft.EncMapInt32IntV(v, e) - } - case map[int32]int32: - if v == nil { - e.e.writeNilMap() - } else { - ft.EncMapInt32Int32V(v, e) - } - case map[int32]float64: - if v == nil { - e.e.writeNilMap() - } else { - ft.EncMapInt32Float64V(v, e) - } - case map[int32]bool: - if v == nil { - e.e.writeNilMap() - } else { - ft.EncMapInt32BoolV(v, e) - } - default: - _ = v - return false - } - return true -} - -func (e *encoderSimpleIO) fastpathEncSliceIntfR(f *encFnInfo, rv reflect.Value) { - var ft fastpathETSimpleIO - var v []interface{} - if rv.Kind() == reflect.Array { - rvGetSlice4Array(rv, &v) - } else { - v = rv2i(rv).([]interface{}) - } - if f.ti.mbs { - ft.EncAsMapSliceIntfV(v, e) - return - } - ft.EncSliceIntfV(v, e) -} -func (fastpathETSimpleIO) EncSliceIntfV(v []interface{}, e *encoderSimpleIO) { - if len(v) == 0 { - e.c = 0 - e.e.WriteArrayEmpty() - return - } - e.arrayStart(len(v)) - for j := range v { - e.c = containerArrayElem - e.e.WriteArrayElem(j == 0) - if !e.encodeBuiltin(v[j]) { - e.encodeR(reflect.ValueOf(v[j])) - } - } - e.c = 0 - e.e.WriteArrayEnd() -} -func (fastpathETSimpleIO) EncAsMapSliceIntfV(v []interface{}, e *encoderSimpleIO) { - if len(v) == 0 { - e.c = 0 - e.e.WriteMapEmpty() - return - } - e.haltOnMbsOddLen(len(v)) - e.mapStart(len(v) >> 1) - for j := range v { - if j&1 == 0 { - e.c = containerMapKey - e.e.WriteMapElemKey(j == 0) - } else { - e.mapElemValue() - } - if !e.encodeBuiltin(v[j]) { - e.encodeR(reflect.ValueOf(v[j])) - } - } - e.c = 0 - e.e.WriteMapEnd() -} - -func (e *encoderSimpleIO) fastpathEncSliceStringR(f *encFnInfo, rv reflect.Value) { - var ft fastpathETSimpleIO - var v []string - if rv.Kind() == reflect.Array { - rvGetSlice4Array(rv, &v) - } else { - v = rv2i(rv).([]string) - } - if f.ti.mbs { - ft.EncAsMapSliceStringV(v, e) - return - } - ft.EncSliceStringV(v, e) -} -func (fastpathETSimpleIO) EncSliceStringV(v []string, e *encoderSimpleIO) { - if len(v) == 0 { - e.c = 0 - e.e.WriteArrayEmpty() - return - } - e.arrayStart(len(v)) - for j := range v { - e.c = containerArrayElem - e.e.WriteArrayElem(j == 0) - e.e.EncodeString(v[j]) - } - e.c = 0 - e.e.WriteArrayEnd() -} -func (fastpathETSimpleIO) EncAsMapSliceStringV(v []string, e *encoderSimpleIO) { - if len(v) == 0 { - e.c = 0 - e.e.WriteMapEmpty() - return - } - e.haltOnMbsOddLen(len(v)) - e.mapStart(len(v) >> 1) - for j := range v { - if j&1 == 0 { - e.c = containerMapKey - e.e.WriteMapElemKey(j == 0) - } else { - e.mapElemValue() - } - e.e.EncodeString(v[j]) - } - e.c = 0 - e.e.WriteMapEnd() -} - -func (e *encoderSimpleIO) fastpathEncSliceBytesR(f *encFnInfo, rv reflect.Value) { - var ft fastpathETSimpleIO - var v [][]byte - if rv.Kind() == reflect.Array { - rvGetSlice4Array(rv, &v) - } else { - v = rv2i(rv).([][]byte) - } - if f.ti.mbs { - ft.EncAsMapSliceBytesV(v, e) - return - } - ft.EncSliceBytesV(v, e) -} -func (fastpathETSimpleIO) EncSliceBytesV(v [][]byte, e *encoderSimpleIO) { - if len(v) == 0 { - e.c = 0 - e.e.WriteArrayEmpty() - return - } - e.arrayStart(len(v)) - for j := range v { - e.c = containerArrayElem - e.e.WriteArrayElem(j == 0) - e.e.EncodeBytes(v[j]) - } - e.c = 0 - e.e.WriteArrayEnd() -} -func (fastpathETSimpleIO) EncAsMapSliceBytesV(v [][]byte, e *encoderSimpleIO) { - if len(v) == 0 { - e.c = 0 - e.e.WriteMapEmpty() - return - } - e.haltOnMbsOddLen(len(v)) - e.mapStart(len(v) >> 1) - for j := range v { - if j&1 == 0 { - e.c = containerMapKey - e.e.WriteMapElemKey(j == 0) - } else { - e.mapElemValue() - } - e.e.EncodeBytes(v[j]) - } - e.c = 0 - e.e.WriteMapEnd() -} - -func (e *encoderSimpleIO) fastpathEncSliceFloat32R(f *encFnInfo, rv reflect.Value) { - var ft fastpathETSimpleIO - var v []float32 - if rv.Kind() == reflect.Array { - rvGetSlice4Array(rv, &v) - } else { - v = rv2i(rv).([]float32) - } - if f.ti.mbs { - ft.EncAsMapSliceFloat32V(v, e) - return - } - ft.EncSliceFloat32V(v, e) -} -func (fastpathETSimpleIO) EncSliceFloat32V(v []float32, e *encoderSimpleIO) { - if len(v) == 0 { - e.c = 0 - e.e.WriteArrayEmpty() - return - } - e.arrayStart(len(v)) - for j := range v { - e.c = containerArrayElem - e.e.WriteArrayElem(j == 0) - e.e.EncodeFloat32(v[j]) - } - e.c = 0 - e.e.WriteArrayEnd() -} -func (fastpathETSimpleIO) EncAsMapSliceFloat32V(v []float32, e *encoderSimpleIO) { - if len(v) == 0 { - e.c = 0 - e.e.WriteMapEmpty() - return - } - e.haltOnMbsOddLen(len(v)) - e.mapStart(len(v) >> 1) - for j := range v { - if j&1 == 0 { - e.c = containerMapKey - e.e.WriteMapElemKey(j == 0) - } else { - e.mapElemValue() - } - e.e.EncodeFloat32(v[j]) - } - e.c = 0 - e.e.WriteMapEnd() -} - -func (e *encoderSimpleIO) fastpathEncSliceFloat64R(f *encFnInfo, rv reflect.Value) { - var ft fastpathETSimpleIO - var v []float64 - if rv.Kind() == reflect.Array { - rvGetSlice4Array(rv, &v) - } else { - v = rv2i(rv).([]float64) - } - if f.ti.mbs { - ft.EncAsMapSliceFloat64V(v, e) - return - } - ft.EncSliceFloat64V(v, e) -} -func (fastpathETSimpleIO) EncSliceFloat64V(v []float64, e *encoderSimpleIO) { - if len(v) == 0 { - e.c = 0 - e.e.WriteArrayEmpty() - return - } - e.arrayStart(len(v)) - for j := range v { - e.c = containerArrayElem - e.e.WriteArrayElem(j == 0) - e.e.EncodeFloat64(v[j]) - } - e.c = 0 - e.e.WriteArrayEnd() -} -func (fastpathETSimpleIO) EncAsMapSliceFloat64V(v []float64, e *encoderSimpleIO) { - if len(v) == 0 { - e.c = 0 - e.e.WriteMapEmpty() - return - } - e.haltOnMbsOddLen(len(v)) - e.mapStart(len(v) >> 1) - for j := range v { - if j&1 == 0 { - e.c = containerMapKey - e.e.WriteMapElemKey(j == 0) - } else { - e.mapElemValue() - } - e.e.EncodeFloat64(v[j]) - } - e.c = 0 - e.e.WriteMapEnd() -} - -func (e *encoderSimpleIO) fastpathEncSliceUint8R(f *encFnInfo, rv reflect.Value) { - var ft fastpathETSimpleIO - var v []uint8 - if rv.Kind() == reflect.Array { - rvGetSlice4Array(rv, &v) - } else { - v = rv2i(rv).([]uint8) - } - if f.ti.mbs { - ft.EncAsMapSliceUint8V(v, e) - return - } - ft.EncSliceUint8V(v, e) -} -func (fastpathETSimpleIO) EncSliceUint8V(v []uint8, e *encoderSimpleIO) { - e.e.EncodeStringBytesRaw(v) -} -func (fastpathETSimpleIO) EncAsMapSliceUint8V(v []uint8, e *encoderSimpleIO) { - if len(v) == 0 { - e.c = 0 - e.e.WriteMapEmpty() - return - } - e.haltOnMbsOddLen(len(v)) - e.mapStart(len(v) >> 1) - for j := range v { - if j&1 == 0 { - e.c = containerMapKey - e.e.WriteMapElemKey(j == 0) - } else { - e.mapElemValue() - } - e.e.EncodeUint(uint64(v[j])) - } - e.c = 0 - e.e.WriteMapEnd() -} - -func (e *encoderSimpleIO) fastpathEncSliceUint64R(f *encFnInfo, rv reflect.Value) { - var ft fastpathETSimpleIO - var v []uint64 - if rv.Kind() == reflect.Array { - rvGetSlice4Array(rv, &v) - } else { - v = rv2i(rv).([]uint64) - } - if f.ti.mbs { - ft.EncAsMapSliceUint64V(v, e) - return - } - ft.EncSliceUint64V(v, e) -} -func (fastpathETSimpleIO) EncSliceUint64V(v []uint64, e *encoderSimpleIO) { - if len(v) == 0 { - e.c = 0 - e.e.WriteArrayEmpty() - return - } - e.arrayStart(len(v)) - for j := range v { - e.c = containerArrayElem - e.e.WriteArrayElem(j == 0) - e.e.EncodeUint(v[j]) - } - e.c = 0 - e.e.WriteArrayEnd() -} -func (fastpathETSimpleIO) EncAsMapSliceUint64V(v []uint64, e *encoderSimpleIO) { - if len(v) == 0 { - e.c = 0 - e.e.WriteMapEmpty() - return - } - e.haltOnMbsOddLen(len(v)) - e.mapStart(len(v) >> 1) - for j := range v { - if j&1 == 0 { - e.c = containerMapKey - e.e.WriteMapElemKey(j == 0) - } else { - e.mapElemValue() - } - e.e.EncodeUint(v[j]) - } - e.c = 0 - e.e.WriteMapEnd() -} - -func (e *encoderSimpleIO) fastpathEncSliceIntR(f *encFnInfo, rv reflect.Value) { - var ft fastpathETSimpleIO - var v []int - if rv.Kind() == reflect.Array { - rvGetSlice4Array(rv, &v) - } else { - v = rv2i(rv).([]int) - } - if f.ti.mbs { - ft.EncAsMapSliceIntV(v, e) - return - } - ft.EncSliceIntV(v, e) -} -func (fastpathETSimpleIO) EncSliceIntV(v []int, e *encoderSimpleIO) { - if len(v) == 0 { - e.c = 0 - e.e.WriteArrayEmpty() - return - } - e.arrayStart(len(v)) - for j := range v { - e.c = containerArrayElem - e.e.WriteArrayElem(j == 0) - e.e.EncodeInt(int64(v[j])) - } - e.c = 0 - e.e.WriteArrayEnd() -} -func (fastpathETSimpleIO) EncAsMapSliceIntV(v []int, e *encoderSimpleIO) { - if len(v) == 0 { - e.c = 0 - e.e.WriteMapEmpty() - return - } - e.haltOnMbsOddLen(len(v)) - e.mapStart(len(v) >> 1) - for j := range v { - if j&1 == 0 { - e.c = containerMapKey - e.e.WriteMapElemKey(j == 0) - } else { - e.mapElemValue() - } - e.e.EncodeInt(int64(v[j])) - } - e.c = 0 - e.e.WriteMapEnd() -} - -func (e *encoderSimpleIO) fastpathEncSliceInt32R(f *encFnInfo, rv reflect.Value) { - var ft fastpathETSimpleIO - var v []int32 - if rv.Kind() == reflect.Array { - rvGetSlice4Array(rv, &v) - } else { - v = rv2i(rv).([]int32) - } - if f.ti.mbs { - ft.EncAsMapSliceInt32V(v, e) - return - } - ft.EncSliceInt32V(v, e) -} -func (fastpathETSimpleIO) EncSliceInt32V(v []int32, e *encoderSimpleIO) { - if len(v) == 0 { - e.c = 0 - e.e.WriteArrayEmpty() - return - } - e.arrayStart(len(v)) - for j := range v { - e.c = containerArrayElem - e.e.WriteArrayElem(j == 0) - e.e.EncodeInt(int64(v[j])) - } - e.c = 0 - e.e.WriteArrayEnd() -} -func (fastpathETSimpleIO) EncAsMapSliceInt32V(v []int32, e *encoderSimpleIO) { - if len(v) == 0 { - e.c = 0 - e.e.WriteMapEmpty() - return - } - e.haltOnMbsOddLen(len(v)) - e.mapStart(len(v) >> 1) - for j := range v { - if j&1 == 0 { - e.c = containerMapKey - e.e.WriteMapElemKey(j == 0) - } else { - e.mapElemValue() - } - e.e.EncodeInt(int64(v[j])) - } - e.c = 0 - e.e.WriteMapEnd() -} - -func (e *encoderSimpleIO) fastpathEncSliceInt64R(f *encFnInfo, rv reflect.Value) { - var ft fastpathETSimpleIO - var v []int64 - if rv.Kind() == reflect.Array { - rvGetSlice4Array(rv, &v) - } else { - v = rv2i(rv).([]int64) - } - if f.ti.mbs { - ft.EncAsMapSliceInt64V(v, e) - return - } - ft.EncSliceInt64V(v, e) -} -func (fastpathETSimpleIO) EncSliceInt64V(v []int64, e *encoderSimpleIO) { - if len(v) == 0 { - e.c = 0 - e.e.WriteArrayEmpty() - return - } - e.arrayStart(len(v)) - for j := range v { - e.c = containerArrayElem - e.e.WriteArrayElem(j == 0) - e.e.EncodeInt(v[j]) - } - e.c = 0 - e.e.WriteArrayEnd() -} -func (fastpathETSimpleIO) EncAsMapSliceInt64V(v []int64, e *encoderSimpleIO) { - if len(v) == 0 { - e.c = 0 - e.e.WriteMapEmpty() - return - } - e.haltOnMbsOddLen(len(v)) - e.mapStart(len(v) >> 1) - for j := range v { - if j&1 == 0 { - e.c = containerMapKey - e.e.WriteMapElemKey(j == 0) - } else { - e.mapElemValue() - } - e.e.EncodeInt(v[j]) - } - e.c = 0 - e.e.WriteMapEnd() -} - -func (e *encoderSimpleIO) fastpathEncSliceBoolR(f *encFnInfo, rv reflect.Value) { - var ft fastpathETSimpleIO - var v []bool - if rv.Kind() == reflect.Array { - rvGetSlice4Array(rv, &v) - } else { - v = rv2i(rv).([]bool) - } - if f.ti.mbs { - ft.EncAsMapSliceBoolV(v, e) - return - } - ft.EncSliceBoolV(v, e) -} -func (fastpathETSimpleIO) EncSliceBoolV(v []bool, e *encoderSimpleIO) { - if len(v) == 0 { - e.c = 0 - e.e.WriteArrayEmpty() - return - } - e.arrayStart(len(v)) - for j := range v { - e.c = containerArrayElem - e.e.WriteArrayElem(j == 0) - e.e.EncodeBool(v[j]) - } - e.c = 0 - e.e.WriteArrayEnd() -} -func (fastpathETSimpleIO) EncAsMapSliceBoolV(v []bool, e *encoderSimpleIO) { - if len(v) == 0 { - e.c = 0 - e.e.WriteMapEmpty() - return - } - e.haltOnMbsOddLen(len(v)) - e.mapStart(len(v) >> 1) - for j := range v { - if j&1 == 0 { - e.c = containerMapKey - e.e.WriteMapElemKey(j == 0) - } else { - e.mapElemValue() - } - e.e.EncodeBool(v[j]) - } - e.c = 0 - e.e.WriteMapEnd() -} - -func (e *encoderSimpleIO) fastpathEncMapStringIntfR(f *encFnInfo, rv reflect.Value) { - fastpathETSimpleIO{}.EncMapStringIntfV(rv2i(rv).(map[string]interface{}), e) -} -func (fastpathETSimpleIO) EncMapStringIntfV(v map[string]interface{}, e *encoderSimpleIO) { - if len(v) == 0 { - e.e.WriteMapEmpty() - return - } - var i uint - e.mapStart(len(v)) - if e.h.Canonical { - v2 := make([]string, len(v)) - for k := range v { - v2[i] = k - i++ - } - slices.Sort(v2) - for i, k2 := range v2 { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeString(k2) - e.mapElemValue() - if !e.encodeBuiltin(v[k2]) { - e.encodeR(reflect.ValueOf(v[k2])) - } - } - } else { - i = 0 - for k2, v2 := range v { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeString(k2) - e.mapElemValue() - if !e.encodeBuiltin(v2) { - e.encodeR(reflect.ValueOf(v2)) - } - i++ - } - } - e.c = 0 - e.e.WriteMapEnd() -} -func (e *encoderSimpleIO) fastpathEncMapStringStringR(f *encFnInfo, rv reflect.Value) { - fastpathETSimpleIO{}.EncMapStringStringV(rv2i(rv).(map[string]string), e) -} -func (fastpathETSimpleIO) EncMapStringStringV(v map[string]string, e *encoderSimpleIO) { - if len(v) == 0 { - e.e.WriteMapEmpty() - return - } - var i uint - e.mapStart(len(v)) - if e.h.Canonical { - v2 := make([]string, len(v)) - for k := range v { - v2[i] = k - i++ - } - slices.Sort(v2) - for i, k2 := range v2 { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeString(k2) - e.mapElemValue() - e.e.EncodeString(v[k2]) - } - } else { - i = 0 - for k2, v2 := range v { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeString(k2) - e.mapElemValue() - e.e.EncodeString(v2) - i++ - } - } - e.c = 0 - e.e.WriteMapEnd() -} -func (e *encoderSimpleIO) fastpathEncMapStringBytesR(f *encFnInfo, rv reflect.Value) { - fastpathETSimpleIO{}.EncMapStringBytesV(rv2i(rv).(map[string][]byte), e) -} -func (fastpathETSimpleIO) EncMapStringBytesV(v map[string][]byte, e *encoderSimpleIO) { - if len(v) == 0 { - e.e.WriteMapEmpty() - return - } - var i uint - e.mapStart(len(v)) - if e.h.Canonical { - v2 := make([]string, len(v)) - for k := range v { - v2[i] = k - i++ - } - slices.Sort(v2) - for i, k2 := range v2 { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeString(k2) - e.mapElemValue() - e.e.EncodeBytes(v[k2]) - } - } else { - i = 0 - for k2, v2 := range v { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeString(k2) - e.mapElemValue() - e.e.EncodeBytes(v2) - i++ - } - } - e.c = 0 - e.e.WriteMapEnd() -} -func (e *encoderSimpleIO) fastpathEncMapStringUint8R(f *encFnInfo, rv reflect.Value) { - fastpathETSimpleIO{}.EncMapStringUint8V(rv2i(rv).(map[string]uint8), e) -} -func (fastpathETSimpleIO) EncMapStringUint8V(v map[string]uint8, e *encoderSimpleIO) { - if len(v) == 0 { - e.e.WriteMapEmpty() - return - } - var i uint - e.mapStart(len(v)) - if e.h.Canonical { - v2 := make([]string, len(v)) - for k := range v { - v2[i] = k - i++ - } - slices.Sort(v2) - for i, k2 := range v2 { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeString(k2) - e.mapElemValue() - e.e.EncodeUint(uint64(v[k2])) - } - } else { - i = 0 - for k2, v2 := range v { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeString(k2) - e.mapElemValue() - e.e.EncodeUint(uint64(v2)) - i++ - } - } - e.c = 0 - e.e.WriteMapEnd() -} -func (e *encoderSimpleIO) fastpathEncMapStringUint64R(f *encFnInfo, rv reflect.Value) { - fastpathETSimpleIO{}.EncMapStringUint64V(rv2i(rv).(map[string]uint64), e) -} -func (fastpathETSimpleIO) EncMapStringUint64V(v map[string]uint64, e *encoderSimpleIO) { - if len(v) == 0 { - e.e.WriteMapEmpty() - return - } - var i uint - e.mapStart(len(v)) - if e.h.Canonical { - v2 := make([]string, len(v)) - for k := range v { - v2[i] = k - i++ - } - slices.Sort(v2) - for i, k2 := range v2 { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeString(k2) - e.mapElemValue() - e.e.EncodeUint(v[k2]) - } - } else { - i = 0 - for k2, v2 := range v { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeString(k2) - e.mapElemValue() - e.e.EncodeUint(v2) - i++ - } - } - e.c = 0 - e.e.WriteMapEnd() -} -func (e *encoderSimpleIO) fastpathEncMapStringIntR(f *encFnInfo, rv reflect.Value) { - fastpathETSimpleIO{}.EncMapStringIntV(rv2i(rv).(map[string]int), e) -} -func (fastpathETSimpleIO) EncMapStringIntV(v map[string]int, e *encoderSimpleIO) { - if len(v) == 0 { - e.e.WriteMapEmpty() - return - } - var i uint - e.mapStart(len(v)) - if e.h.Canonical { - v2 := make([]string, len(v)) - for k := range v { - v2[i] = k - i++ - } - slices.Sort(v2) - for i, k2 := range v2 { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeString(k2) - e.mapElemValue() - e.e.EncodeInt(int64(v[k2])) - } - } else { - i = 0 - for k2, v2 := range v { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeString(k2) - e.mapElemValue() - e.e.EncodeInt(int64(v2)) - i++ - } - } - e.c = 0 - e.e.WriteMapEnd() -} -func (e *encoderSimpleIO) fastpathEncMapStringInt32R(f *encFnInfo, rv reflect.Value) { - fastpathETSimpleIO{}.EncMapStringInt32V(rv2i(rv).(map[string]int32), e) -} -func (fastpathETSimpleIO) EncMapStringInt32V(v map[string]int32, e *encoderSimpleIO) { - if len(v) == 0 { - e.e.WriteMapEmpty() - return - } - var i uint - e.mapStart(len(v)) - if e.h.Canonical { - v2 := make([]string, len(v)) - for k := range v { - v2[i] = k - i++ - } - slices.Sort(v2) - for i, k2 := range v2 { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeString(k2) - e.mapElemValue() - e.e.EncodeInt(int64(v[k2])) - } - } else { - i = 0 - for k2, v2 := range v { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeString(k2) - e.mapElemValue() - e.e.EncodeInt(int64(v2)) - i++ - } - } - e.c = 0 - e.e.WriteMapEnd() -} -func (e *encoderSimpleIO) fastpathEncMapStringFloat64R(f *encFnInfo, rv reflect.Value) { - fastpathETSimpleIO{}.EncMapStringFloat64V(rv2i(rv).(map[string]float64), e) -} -func (fastpathETSimpleIO) EncMapStringFloat64V(v map[string]float64, e *encoderSimpleIO) { - if len(v) == 0 { - e.e.WriteMapEmpty() - return - } - var i uint - e.mapStart(len(v)) - if e.h.Canonical { - v2 := make([]string, len(v)) - for k := range v { - v2[i] = k - i++ - } - slices.Sort(v2) - for i, k2 := range v2 { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeString(k2) - e.mapElemValue() - e.e.EncodeFloat64(v[k2]) - } - } else { - i = 0 - for k2, v2 := range v { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeString(k2) - e.mapElemValue() - e.e.EncodeFloat64(v2) - i++ - } - } - e.c = 0 - e.e.WriteMapEnd() -} -func (e *encoderSimpleIO) fastpathEncMapStringBoolR(f *encFnInfo, rv reflect.Value) { - fastpathETSimpleIO{}.EncMapStringBoolV(rv2i(rv).(map[string]bool), e) -} -func (fastpathETSimpleIO) EncMapStringBoolV(v map[string]bool, e *encoderSimpleIO) { - if len(v) == 0 { - e.e.WriteMapEmpty() - return - } - var i uint - e.mapStart(len(v)) - if e.h.Canonical { - v2 := make([]string, len(v)) - for k := range v { - v2[i] = k - i++ - } - slices.Sort(v2) - for i, k2 := range v2 { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeString(k2) - e.mapElemValue() - e.e.EncodeBool(v[k2]) - } - } else { - i = 0 - for k2, v2 := range v { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeString(k2) - e.mapElemValue() - e.e.EncodeBool(v2) - i++ - } - } - e.c = 0 - e.e.WriteMapEnd() -} -func (e *encoderSimpleIO) fastpathEncMapUint8IntfR(f *encFnInfo, rv reflect.Value) { - fastpathETSimpleIO{}.EncMapUint8IntfV(rv2i(rv).(map[uint8]interface{}), e) -} -func (fastpathETSimpleIO) EncMapUint8IntfV(v map[uint8]interface{}, e *encoderSimpleIO) { - if len(v) == 0 { - e.e.WriteMapEmpty() - return - } - var i uint - e.mapStart(len(v)) - if e.h.Canonical { - v2 := make([]uint8, len(v)) - for k := range v { - v2[i] = k - i++ - } - slices.Sort(v2) - for i, k2 := range v2 { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeUint(uint64(k2)) - e.mapElemValue() - if !e.encodeBuiltin(v[k2]) { - e.encodeR(reflect.ValueOf(v[k2])) - } - } - } else { - i = 0 - for k2, v2 := range v { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeUint(uint64(k2)) - e.mapElemValue() - if !e.encodeBuiltin(v2) { - e.encodeR(reflect.ValueOf(v2)) - } - i++ - } - } - e.c = 0 - e.e.WriteMapEnd() -} -func (e *encoderSimpleIO) fastpathEncMapUint8StringR(f *encFnInfo, rv reflect.Value) { - fastpathETSimpleIO{}.EncMapUint8StringV(rv2i(rv).(map[uint8]string), e) -} -func (fastpathETSimpleIO) EncMapUint8StringV(v map[uint8]string, e *encoderSimpleIO) { - if len(v) == 0 { - e.e.WriteMapEmpty() - return - } - var i uint - e.mapStart(len(v)) - if e.h.Canonical { - v2 := make([]uint8, len(v)) - for k := range v { - v2[i] = k - i++ - } - slices.Sort(v2) - for i, k2 := range v2 { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeUint(uint64(k2)) - e.mapElemValue() - e.e.EncodeString(v[k2]) - } - } else { - i = 0 - for k2, v2 := range v { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeUint(uint64(k2)) - e.mapElemValue() - e.e.EncodeString(v2) - i++ - } - } - e.c = 0 - e.e.WriteMapEnd() -} -func (e *encoderSimpleIO) fastpathEncMapUint8BytesR(f *encFnInfo, rv reflect.Value) { - fastpathETSimpleIO{}.EncMapUint8BytesV(rv2i(rv).(map[uint8][]byte), e) -} -func (fastpathETSimpleIO) EncMapUint8BytesV(v map[uint8][]byte, e *encoderSimpleIO) { - if len(v) == 0 { - e.e.WriteMapEmpty() - return - } - var i uint - e.mapStart(len(v)) - if e.h.Canonical { - v2 := make([]uint8, len(v)) - for k := range v { - v2[i] = k - i++ - } - slices.Sort(v2) - for i, k2 := range v2 { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeUint(uint64(k2)) - e.mapElemValue() - e.e.EncodeBytes(v[k2]) - } - } else { - i = 0 - for k2, v2 := range v { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeUint(uint64(k2)) - e.mapElemValue() - e.e.EncodeBytes(v2) - i++ - } - } - e.c = 0 - e.e.WriteMapEnd() -} -func (e *encoderSimpleIO) fastpathEncMapUint8Uint8R(f *encFnInfo, rv reflect.Value) { - fastpathETSimpleIO{}.EncMapUint8Uint8V(rv2i(rv).(map[uint8]uint8), e) -} -func (fastpathETSimpleIO) EncMapUint8Uint8V(v map[uint8]uint8, e *encoderSimpleIO) { - if len(v) == 0 { - e.e.WriteMapEmpty() - return - } - var i uint - e.mapStart(len(v)) - if e.h.Canonical { - v2 := make([]uint8, len(v)) - for k := range v { - v2[i] = k - i++ - } - slices.Sort(v2) - for i, k2 := range v2 { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeUint(uint64(k2)) - e.mapElemValue() - e.e.EncodeUint(uint64(v[k2])) - } - } else { - i = 0 - for k2, v2 := range v { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeUint(uint64(k2)) - e.mapElemValue() - e.e.EncodeUint(uint64(v2)) - i++ - } - } - e.c = 0 - e.e.WriteMapEnd() -} -func (e *encoderSimpleIO) fastpathEncMapUint8Uint64R(f *encFnInfo, rv reflect.Value) { - fastpathETSimpleIO{}.EncMapUint8Uint64V(rv2i(rv).(map[uint8]uint64), e) -} -func (fastpathETSimpleIO) EncMapUint8Uint64V(v map[uint8]uint64, e *encoderSimpleIO) { - if len(v) == 0 { - e.e.WriteMapEmpty() - return - } - var i uint - e.mapStart(len(v)) - if e.h.Canonical { - v2 := make([]uint8, len(v)) - for k := range v { - v2[i] = k - i++ - } - slices.Sort(v2) - for i, k2 := range v2 { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeUint(uint64(k2)) - e.mapElemValue() - e.e.EncodeUint(v[k2]) - } - } else { - i = 0 - for k2, v2 := range v { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeUint(uint64(k2)) - e.mapElemValue() - e.e.EncodeUint(v2) - i++ - } - } - e.c = 0 - e.e.WriteMapEnd() -} -func (e *encoderSimpleIO) fastpathEncMapUint8IntR(f *encFnInfo, rv reflect.Value) { - fastpathETSimpleIO{}.EncMapUint8IntV(rv2i(rv).(map[uint8]int), e) -} -func (fastpathETSimpleIO) EncMapUint8IntV(v map[uint8]int, e *encoderSimpleIO) { - if len(v) == 0 { - e.e.WriteMapEmpty() - return - } - var i uint - e.mapStart(len(v)) - if e.h.Canonical { - v2 := make([]uint8, len(v)) - for k := range v { - v2[i] = k - i++ - } - slices.Sort(v2) - for i, k2 := range v2 { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeUint(uint64(k2)) - e.mapElemValue() - e.e.EncodeInt(int64(v[k2])) - } - } else { - i = 0 - for k2, v2 := range v { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeUint(uint64(k2)) - e.mapElemValue() - e.e.EncodeInt(int64(v2)) - i++ - } - } - e.c = 0 - e.e.WriteMapEnd() -} -func (e *encoderSimpleIO) fastpathEncMapUint8Int32R(f *encFnInfo, rv reflect.Value) { - fastpathETSimpleIO{}.EncMapUint8Int32V(rv2i(rv).(map[uint8]int32), e) -} -func (fastpathETSimpleIO) EncMapUint8Int32V(v map[uint8]int32, e *encoderSimpleIO) { - if len(v) == 0 { - e.e.WriteMapEmpty() - return - } - var i uint - e.mapStart(len(v)) - if e.h.Canonical { - v2 := make([]uint8, len(v)) - for k := range v { - v2[i] = k - i++ - } - slices.Sort(v2) - for i, k2 := range v2 { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeUint(uint64(k2)) - e.mapElemValue() - e.e.EncodeInt(int64(v[k2])) - } - } else { - i = 0 - for k2, v2 := range v { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeUint(uint64(k2)) - e.mapElemValue() - e.e.EncodeInt(int64(v2)) - i++ - } - } - e.c = 0 - e.e.WriteMapEnd() -} -func (e *encoderSimpleIO) fastpathEncMapUint8Float64R(f *encFnInfo, rv reflect.Value) { - fastpathETSimpleIO{}.EncMapUint8Float64V(rv2i(rv).(map[uint8]float64), e) -} -func (fastpathETSimpleIO) EncMapUint8Float64V(v map[uint8]float64, e *encoderSimpleIO) { - if len(v) == 0 { - e.e.WriteMapEmpty() - return - } - var i uint - e.mapStart(len(v)) - if e.h.Canonical { - v2 := make([]uint8, len(v)) - for k := range v { - v2[i] = k - i++ - } - slices.Sort(v2) - for i, k2 := range v2 { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeUint(uint64(k2)) - e.mapElemValue() - e.e.EncodeFloat64(v[k2]) - } - } else { - i = 0 - for k2, v2 := range v { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeUint(uint64(k2)) - e.mapElemValue() - e.e.EncodeFloat64(v2) - i++ - } - } - e.c = 0 - e.e.WriteMapEnd() -} -func (e *encoderSimpleIO) fastpathEncMapUint8BoolR(f *encFnInfo, rv reflect.Value) { - fastpathETSimpleIO{}.EncMapUint8BoolV(rv2i(rv).(map[uint8]bool), e) -} -func (fastpathETSimpleIO) EncMapUint8BoolV(v map[uint8]bool, e *encoderSimpleIO) { - if len(v) == 0 { - e.e.WriteMapEmpty() - return - } - var i uint - e.mapStart(len(v)) - if e.h.Canonical { - v2 := make([]uint8, len(v)) - for k := range v { - v2[i] = k - i++ - } - slices.Sort(v2) - for i, k2 := range v2 { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeUint(uint64(k2)) - e.mapElemValue() - e.e.EncodeBool(v[k2]) - } - } else { - i = 0 - for k2, v2 := range v { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeUint(uint64(k2)) - e.mapElemValue() - e.e.EncodeBool(v2) - i++ - } - } - e.c = 0 - e.e.WriteMapEnd() -} -func (e *encoderSimpleIO) fastpathEncMapUint64IntfR(f *encFnInfo, rv reflect.Value) { - fastpathETSimpleIO{}.EncMapUint64IntfV(rv2i(rv).(map[uint64]interface{}), e) -} -func (fastpathETSimpleIO) EncMapUint64IntfV(v map[uint64]interface{}, e *encoderSimpleIO) { - if len(v) == 0 { - e.e.WriteMapEmpty() - return - } - var i uint - e.mapStart(len(v)) - if e.h.Canonical { - v2 := make([]uint64, len(v)) - for k := range v { - v2[i] = k - i++ - } - slices.Sort(v2) - for i, k2 := range v2 { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeUint(k2) - e.mapElemValue() - if !e.encodeBuiltin(v[k2]) { - e.encodeR(reflect.ValueOf(v[k2])) - } - } - } else { - i = 0 - for k2, v2 := range v { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeUint(k2) - e.mapElemValue() - if !e.encodeBuiltin(v2) { - e.encodeR(reflect.ValueOf(v2)) - } - i++ - } - } - e.c = 0 - e.e.WriteMapEnd() -} -func (e *encoderSimpleIO) fastpathEncMapUint64StringR(f *encFnInfo, rv reflect.Value) { - fastpathETSimpleIO{}.EncMapUint64StringV(rv2i(rv).(map[uint64]string), e) -} -func (fastpathETSimpleIO) EncMapUint64StringV(v map[uint64]string, e *encoderSimpleIO) { - if len(v) == 0 { - e.e.WriteMapEmpty() - return - } - var i uint - e.mapStart(len(v)) - if e.h.Canonical { - v2 := make([]uint64, len(v)) - for k := range v { - v2[i] = k - i++ - } - slices.Sort(v2) - for i, k2 := range v2 { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeUint(k2) - e.mapElemValue() - e.e.EncodeString(v[k2]) - } - } else { - i = 0 - for k2, v2 := range v { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeUint(k2) - e.mapElemValue() - e.e.EncodeString(v2) - i++ - } - } - e.c = 0 - e.e.WriteMapEnd() -} -func (e *encoderSimpleIO) fastpathEncMapUint64BytesR(f *encFnInfo, rv reflect.Value) { - fastpathETSimpleIO{}.EncMapUint64BytesV(rv2i(rv).(map[uint64][]byte), e) -} -func (fastpathETSimpleIO) EncMapUint64BytesV(v map[uint64][]byte, e *encoderSimpleIO) { - if len(v) == 0 { - e.e.WriteMapEmpty() - return - } - var i uint - e.mapStart(len(v)) - if e.h.Canonical { - v2 := make([]uint64, len(v)) - for k := range v { - v2[i] = k - i++ - } - slices.Sort(v2) - for i, k2 := range v2 { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeUint(k2) - e.mapElemValue() - e.e.EncodeBytes(v[k2]) - } - } else { - i = 0 - for k2, v2 := range v { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeUint(k2) - e.mapElemValue() - e.e.EncodeBytes(v2) - i++ - } - } - e.c = 0 - e.e.WriteMapEnd() -} -func (e *encoderSimpleIO) fastpathEncMapUint64Uint8R(f *encFnInfo, rv reflect.Value) { - fastpathETSimpleIO{}.EncMapUint64Uint8V(rv2i(rv).(map[uint64]uint8), e) -} -func (fastpathETSimpleIO) EncMapUint64Uint8V(v map[uint64]uint8, e *encoderSimpleIO) { - if len(v) == 0 { - e.e.WriteMapEmpty() - return - } - var i uint - e.mapStart(len(v)) - if e.h.Canonical { - v2 := make([]uint64, len(v)) - for k := range v { - v2[i] = k - i++ - } - slices.Sort(v2) - for i, k2 := range v2 { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeUint(k2) - e.mapElemValue() - e.e.EncodeUint(uint64(v[k2])) - } - } else { - i = 0 - for k2, v2 := range v { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeUint(k2) - e.mapElemValue() - e.e.EncodeUint(uint64(v2)) - i++ - } - } - e.c = 0 - e.e.WriteMapEnd() -} -func (e *encoderSimpleIO) fastpathEncMapUint64Uint64R(f *encFnInfo, rv reflect.Value) { - fastpathETSimpleIO{}.EncMapUint64Uint64V(rv2i(rv).(map[uint64]uint64), e) -} -func (fastpathETSimpleIO) EncMapUint64Uint64V(v map[uint64]uint64, e *encoderSimpleIO) { - if len(v) == 0 { - e.e.WriteMapEmpty() - return - } - var i uint - e.mapStart(len(v)) - if e.h.Canonical { - v2 := make([]uint64, len(v)) - for k := range v { - v2[i] = k - i++ - } - slices.Sort(v2) - for i, k2 := range v2 { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeUint(k2) - e.mapElemValue() - e.e.EncodeUint(v[k2]) - } - } else { - i = 0 - for k2, v2 := range v { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeUint(k2) - e.mapElemValue() - e.e.EncodeUint(v2) - i++ - } - } - e.c = 0 - e.e.WriteMapEnd() -} -func (e *encoderSimpleIO) fastpathEncMapUint64IntR(f *encFnInfo, rv reflect.Value) { - fastpathETSimpleIO{}.EncMapUint64IntV(rv2i(rv).(map[uint64]int), e) -} -func (fastpathETSimpleIO) EncMapUint64IntV(v map[uint64]int, e *encoderSimpleIO) { - if len(v) == 0 { - e.e.WriteMapEmpty() - return - } - var i uint - e.mapStart(len(v)) - if e.h.Canonical { - v2 := make([]uint64, len(v)) - for k := range v { - v2[i] = k - i++ - } - slices.Sort(v2) - for i, k2 := range v2 { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeUint(k2) - e.mapElemValue() - e.e.EncodeInt(int64(v[k2])) - } - } else { - i = 0 - for k2, v2 := range v { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeUint(k2) - e.mapElemValue() - e.e.EncodeInt(int64(v2)) - i++ - } - } - e.c = 0 - e.e.WriteMapEnd() -} -func (e *encoderSimpleIO) fastpathEncMapUint64Int32R(f *encFnInfo, rv reflect.Value) { - fastpathETSimpleIO{}.EncMapUint64Int32V(rv2i(rv).(map[uint64]int32), e) -} -func (fastpathETSimpleIO) EncMapUint64Int32V(v map[uint64]int32, e *encoderSimpleIO) { - if len(v) == 0 { - e.e.WriteMapEmpty() - return - } - var i uint - e.mapStart(len(v)) - if e.h.Canonical { - v2 := make([]uint64, len(v)) - for k := range v { - v2[i] = k - i++ - } - slices.Sort(v2) - for i, k2 := range v2 { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeUint(k2) - e.mapElemValue() - e.e.EncodeInt(int64(v[k2])) - } - } else { - i = 0 - for k2, v2 := range v { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeUint(k2) - e.mapElemValue() - e.e.EncodeInt(int64(v2)) - i++ - } - } - e.c = 0 - e.e.WriteMapEnd() -} -func (e *encoderSimpleIO) fastpathEncMapUint64Float64R(f *encFnInfo, rv reflect.Value) { - fastpathETSimpleIO{}.EncMapUint64Float64V(rv2i(rv).(map[uint64]float64), e) -} -func (fastpathETSimpleIO) EncMapUint64Float64V(v map[uint64]float64, e *encoderSimpleIO) { - if len(v) == 0 { - e.e.WriteMapEmpty() - return - } - var i uint - e.mapStart(len(v)) - if e.h.Canonical { - v2 := make([]uint64, len(v)) - for k := range v { - v2[i] = k - i++ - } - slices.Sort(v2) - for i, k2 := range v2 { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeUint(k2) - e.mapElemValue() - e.e.EncodeFloat64(v[k2]) - } - } else { - i = 0 - for k2, v2 := range v { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeUint(k2) - e.mapElemValue() - e.e.EncodeFloat64(v2) - i++ - } - } - e.c = 0 - e.e.WriteMapEnd() -} -func (e *encoderSimpleIO) fastpathEncMapUint64BoolR(f *encFnInfo, rv reflect.Value) { - fastpathETSimpleIO{}.EncMapUint64BoolV(rv2i(rv).(map[uint64]bool), e) -} -func (fastpathETSimpleIO) EncMapUint64BoolV(v map[uint64]bool, e *encoderSimpleIO) { - if len(v) == 0 { - e.e.WriteMapEmpty() - return - } - var i uint - e.mapStart(len(v)) - if e.h.Canonical { - v2 := make([]uint64, len(v)) - for k := range v { - v2[i] = k - i++ - } - slices.Sort(v2) - for i, k2 := range v2 { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeUint(k2) - e.mapElemValue() - e.e.EncodeBool(v[k2]) - } - } else { - i = 0 - for k2, v2 := range v { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeUint(k2) - e.mapElemValue() - e.e.EncodeBool(v2) - i++ - } - } - e.c = 0 - e.e.WriteMapEnd() -} -func (e *encoderSimpleIO) fastpathEncMapIntIntfR(f *encFnInfo, rv reflect.Value) { - fastpathETSimpleIO{}.EncMapIntIntfV(rv2i(rv).(map[int]interface{}), e) -} -func (fastpathETSimpleIO) EncMapIntIntfV(v map[int]interface{}, e *encoderSimpleIO) { - if len(v) == 0 { - e.e.WriteMapEmpty() - return - } - var i uint - e.mapStart(len(v)) - if e.h.Canonical { - v2 := make([]int, len(v)) - for k := range v { - v2[i] = k - i++ - } - slices.Sort(v2) - for i, k2 := range v2 { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeInt(int64(k2)) - e.mapElemValue() - if !e.encodeBuiltin(v[k2]) { - e.encodeR(reflect.ValueOf(v[k2])) - } - } - } else { - i = 0 - for k2, v2 := range v { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeInt(int64(k2)) - e.mapElemValue() - if !e.encodeBuiltin(v2) { - e.encodeR(reflect.ValueOf(v2)) - } - i++ - } - } - e.c = 0 - e.e.WriteMapEnd() -} -func (e *encoderSimpleIO) fastpathEncMapIntStringR(f *encFnInfo, rv reflect.Value) { - fastpathETSimpleIO{}.EncMapIntStringV(rv2i(rv).(map[int]string), e) -} -func (fastpathETSimpleIO) EncMapIntStringV(v map[int]string, e *encoderSimpleIO) { - if len(v) == 0 { - e.e.WriteMapEmpty() - return - } - var i uint - e.mapStart(len(v)) - if e.h.Canonical { - v2 := make([]int, len(v)) - for k := range v { - v2[i] = k - i++ - } - slices.Sort(v2) - for i, k2 := range v2 { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeInt(int64(k2)) - e.mapElemValue() - e.e.EncodeString(v[k2]) - } - } else { - i = 0 - for k2, v2 := range v { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeInt(int64(k2)) - e.mapElemValue() - e.e.EncodeString(v2) - i++ - } - } - e.c = 0 - e.e.WriteMapEnd() -} -func (e *encoderSimpleIO) fastpathEncMapIntBytesR(f *encFnInfo, rv reflect.Value) { - fastpathETSimpleIO{}.EncMapIntBytesV(rv2i(rv).(map[int][]byte), e) -} -func (fastpathETSimpleIO) EncMapIntBytesV(v map[int][]byte, e *encoderSimpleIO) { - if len(v) == 0 { - e.e.WriteMapEmpty() - return - } - var i uint - e.mapStart(len(v)) - if e.h.Canonical { - v2 := make([]int, len(v)) - for k := range v { - v2[i] = k - i++ - } - slices.Sort(v2) - for i, k2 := range v2 { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeInt(int64(k2)) - e.mapElemValue() - e.e.EncodeBytes(v[k2]) - } - } else { - i = 0 - for k2, v2 := range v { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeInt(int64(k2)) - e.mapElemValue() - e.e.EncodeBytes(v2) - i++ - } - } - e.c = 0 - e.e.WriteMapEnd() -} -func (e *encoderSimpleIO) fastpathEncMapIntUint8R(f *encFnInfo, rv reflect.Value) { - fastpathETSimpleIO{}.EncMapIntUint8V(rv2i(rv).(map[int]uint8), e) -} -func (fastpathETSimpleIO) EncMapIntUint8V(v map[int]uint8, e *encoderSimpleIO) { - if len(v) == 0 { - e.e.WriteMapEmpty() - return - } - var i uint - e.mapStart(len(v)) - if e.h.Canonical { - v2 := make([]int, len(v)) - for k := range v { - v2[i] = k - i++ - } - slices.Sort(v2) - for i, k2 := range v2 { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeInt(int64(k2)) - e.mapElemValue() - e.e.EncodeUint(uint64(v[k2])) - } - } else { - i = 0 - for k2, v2 := range v { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeInt(int64(k2)) - e.mapElemValue() - e.e.EncodeUint(uint64(v2)) - i++ - } - } - e.c = 0 - e.e.WriteMapEnd() -} -func (e *encoderSimpleIO) fastpathEncMapIntUint64R(f *encFnInfo, rv reflect.Value) { - fastpathETSimpleIO{}.EncMapIntUint64V(rv2i(rv).(map[int]uint64), e) -} -func (fastpathETSimpleIO) EncMapIntUint64V(v map[int]uint64, e *encoderSimpleIO) { - if len(v) == 0 { - e.e.WriteMapEmpty() - return - } - var i uint - e.mapStart(len(v)) - if e.h.Canonical { - v2 := make([]int, len(v)) - for k := range v { - v2[i] = k - i++ - } - slices.Sort(v2) - for i, k2 := range v2 { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeInt(int64(k2)) - e.mapElemValue() - e.e.EncodeUint(v[k2]) - } - } else { - i = 0 - for k2, v2 := range v { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeInt(int64(k2)) - e.mapElemValue() - e.e.EncodeUint(v2) - i++ - } - } - e.c = 0 - e.e.WriteMapEnd() -} -func (e *encoderSimpleIO) fastpathEncMapIntIntR(f *encFnInfo, rv reflect.Value) { - fastpathETSimpleIO{}.EncMapIntIntV(rv2i(rv).(map[int]int), e) -} -func (fastpathETSimpleIO) EncMapIntIntV(v map[int]int, e *encoderSimpleIO) { - if len(v) == 0 { - e.e.WriteMapEmpty() - return - } - var i uint - e.mapStart(len(v)) - if e.h.Canonical { - v2 := make([]int, len(v)) - for k := range v { - v2[i] = k - i++ - } - slices.Sort(v2) - for i, k2 := range v2 { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeInt(int64(k2)) - e.mapElemValue() - e.e.EncodeInt(int64(v[k2])) - } - } else { - i = 0 - for k2, v2 := range v { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeInt(int64(k2)) - e.mapElemValue() - e.e.EncodeInt(int64(v2)) - i++ - } - } - e.c = 0 - e.e.WriteMapEnd() -} -func (e *encoderSimpleIO) fastpathEncMapIntInt32R(f *encFnInfo, rv reflect.Value) { - fastpathETSimpleIO{}.EncMapIntInt32V(rv2i(rv).(map[int]int32), e) -} -func (fastpathETSimpleIO) EncMapIntInt32V(v map[int]int32, e *encoderSimpleIO) { - if len(v) == 0 { - e.e.WriteMapEmpty() - return - } - var i uint - e.mapStart(len(v)) - if e.h.Canonical { - v2 := make([]int, len(v)) - for k := range v { - v2[i] = k - i++ - } - slices.Sort(v2) - for i, k2 := range v2 { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeInt(int64(k2)) - e.mapElemValue() - e.e.EncodeInt(int64(v[k2])) - } - } else { - i = 0 - for k2, v2 := range v { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeInt(int64(k2)) - e.mapElemValue() - e.e.EncodeInt(int64(v2)) - i++ - } - } - e.c = 0 - e.e.WriteMapEnd() -} -func (e *encoderSimpleIO) fastpathEncMapIntFloat64R(f *encFnInfo, rv reflect.Value) { - fastpathETSimpleIO{}.EncMapIntFloat64V(rv2i(rv).(map[int]float64), e) -} -func (fastpathETSimpleIO) EncMapIntFloat64V(v map[int]float64, e *encoderSimpleIO) { - if len(v) == 0 { - e.e.WriteMapEmpty() - return - } - var i uint - e.mapStart(len(v)) - if e.h.Canonical { - v2 := make([]int, len(v)) - for k := range v { - v2[i] = k - i++ - } - slices.Sort(v2) - for i, k2 := range v2 { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeInt(int64(k2)) - e.mapElemValue() - e.e.EncodeFloat64(v[k2]) - } - } else { - i = 0 - for k2, v2 := range v { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeInt(int64(k2)) - e.mapElemValue() - e.e.EncodeFloat64(v2) - i++ - } - } - e.c = 0 - e.e.WriteMapEnd() -} -func (e *encoderSimpleIO) fastpathEncMapIntBoolR(f *encFnInfo, rv reflect.Value) { - fastpathETSimpleIO{}.EncMapIntBoolV(rv2i(rv).(map[int]bool), e) -} -func (fastpathETSimpleIO) EncMapIntBoolV(v map[int]bool, e *encoderSimpleIO) { - if len(v) == 0 { - e.e.WriteMapEmpty() - return - } - var i uint - e.mapStart(len(v)) - if e.h.Canonical { - v2 := make([]int, len(v)) - for k := range v { - v2[i] = k - i++ - } - slices.Sort(v2) - for i, k2 := range v2 { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeInt(int64(k2)) - e.mapElemValue() - e.e.EncodeBool(v[k2]) - } - } else { - i = 0 - for k2, v2 := range v { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeInt(int64(k2)) - e.mapElemValue() - e.e.EncodeBool(v2) - i++ - } - } - e.c = 0 - e.e.WriteMapEnd() -} -func (e *encoderSimpleIO) fastpathEncMapInt32IntfR(f *encFnInfo, rv reflect.Value) { - fastpathETSimpleIO{}.EncMapInt32IntfV(rv2i(rv).(map[int32]interface{}), e) -} -func (fastpathETSimpleIO) EncMapInt32IntfV(v map[int32]interface{}, e *encoderSimpleIO) { - if len(v) == 0 { - e.e.WriteMapEmpty() - return - } - var i uint - e.mapStart(len(v)) - if e.h.Canonical { - v2 := make([]int32, len(v)) - for k := range v { - v2[i] = k - i++ - } - slices.Sort(v2) - for i, k2 := range v2 { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeInt(int64(k2)) - e.mapElemValue() - if !e.encodeBuiltin(v[k2]) { - e.encodeR(reflect.ValueOf(v[k2])) - } - } - } else { - i = 0 - for k2, v2 := range v { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeInt(int64(k2)) - e.mapElemValue() - if !e.encodeBuiltin(v2) { - e.encodeR(reflect.ValueOf(v2)) - } - i++ - } - } - e.c = 0 - e.e.WriteMapEnd() -} -func (e *encoderSimpleIO) fastpathEncMapInt32StringR(f *encFnInfo, rv reflect.Value) { - fastpathETSimpleIO{}.EncMapInt32StringV(rv2i(rv).(map[int32]string), e) -} -func (fastpathETSimpleIO) EncMapInt32StringV(v map[int32]string, e *encoderSimpleIO) { - if len(v) == 0 { - e.e.WriteMapEmpty() - return - } - var i uint - e.mapStart(len(v)) - if e.h.Canonical { - v2 := make([]int32, len(v)) - for k := range v { - v2[i] = k - i++ - } - slices.Sort(v2) - for i, k2 := range v2 { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeInt(int64(k2)) - e.mapElemValue() - e.e.EncodeString(v[k2]) - } - } else { - i = 0 - for k2, v2 := range v { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeInt(int64(k2)) - e.mapElemValue() - e.e.EncodeString(v2) - i++ - } - } - e.c = 0 - e.e.WriteMapEnd() -} -func (e *encoderSimpleIO) fastpathEncMapInt32BytesR(f *encFnInfo, rv reflect.Value) { - fastpathETSimpleIO{}.EncMapInt32BytesV(rv2i(rv).(map[int32][]byte), e) -} -func (fastpathETSimpleIO) EncMapInt32BytesV(v map[int32][]byte, e *encoderSimpleIO) { - if len(v) == 0 { - e.e.WriteMapEmpty() - return - } - var i uint - e.mapStart(len(v)) - if e.h.Canonical { - v2 := make([]int32, len(v)) - for k := range v { - v2[i] = k - i++ - } - slices.Sort(v2) - for i, k2 := range v2 { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeInt(int64(k2)) - e.mapElemValue() - e.e.EncodeBytes(v[k2]) - } - } else { - i = 0 - for k2, v2 := range v { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeInt(int64(k2)) - e.mapElemValue() - e.e.EncodeBytes(v2) - i++ - } - } - e.c = 0 - e.e.WriteMapEnd() -} -func (e *encoderSimpleIO) fastpathEncMapInt32Uint8R(f *encFnInfo, rv reflect.Value) { - fastpathETSimpleIO{}.EncMapInt32Uint8V(rv2i(rv).(map[int32]uint8), e) -} -func (fastpathETSimpleIO) EncMapInt32Uint8V(v map[int32]uint8, e *encoderSimpleIO) { - if len(v) == 0 { - e.e.WriteMapEmpty() - return - } - var i uint - e.mapStart(len(v)) - if e.h.Canonical { - v2 := make([]int32, len(v)) - for k := range v { - v2[i] = k - i++ - } - slices.Sort(v2) - for i, k2 := range v2 { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeInt(int64(k2)) - e.mapElemValue() - e.e.EncodeUint(uint64(v[k2])) - } - } else { - i = 0 - for k2, v2 := range v { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeInt(int64(k2)) - e.mapElemValue() - e.e.EncodeUint(uint64(v2)) - i++ - } - } - e.c = 0 - e.e.WriteMapEnd() -} -func (e *encoderSimpleIO) fastpathEncMapInt32Uint64R(f *encFnInfo, rv reflect.Value) { - fastpathETSimpleIO{}.EncMapInt32Uint64V(rv2i(rv).(map[int32]uint64), e) -} -func (fastpathETSimpleIO) EncMapInt32Uint64V(v map[int32]uint64, e *encoderSimpleIO) { - if len(v) == 0 { - e.e.WriteMapEmpty() - return - } - var i uint - e.mapStart(len(v)) - if e.h.Canonical { - v2 := make([]int32, len(v)) - for k := range v { - v2[i] = k - i++ - } - slices.Sort(v2) - for i, k2 := range v2 { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeInt(int64(k2)) - e.mapElemValue() - e.e.EncodeUint(v[k2]) - } - } else { - i = 0 - for k2, v2 := range v { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeInt(int64(k2)) - e.mapElemValue() - e.e.EncodeUint(v2) - i++ - } - } - e.c = 0 - e.e.WriteMapEnd() -} -func (e *encoderSimpleIO) fastpathEncMapInt32IntR(f *encFnInfo, rv reflect.Value) { - fastpathETSimpleIO{}.EncMapInt32IntV(rv2i(rv).(map[int32]int), e) -} -func (fastpathETSimpleIO) EncMapInt32IntV(v map[int32]int, e *encoderSimpleIO) { - if len(v) == 0 { - e.e.WriteMapEmpty() - return - } - var i uint - e.mapStart(len(v)) - if e.h.Canonical { - v2 := make([]int32, len(v)) - for k := range v { - v2[i] = k - i++ - } - slices.Sort(v2) - for i, k2 := range v2 { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeInt(int64(k2)) - e.mapElemValue() - e.e.EncodeInt(int64(v[k2])) - } - } else { - i = 0 - for k2, v2 := range v { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeInt(int64(k2)) - e.mapElemValue() - e.e.EncodeInt(int64(v2)) - i++ - } - } - e.c = 0 - e.e.WriteMapEnd() -} -func (e *encoderSimpleIO) fastpathEncMapInt32Int32R(f *encFnInfo, rv reflect.Value) { - fastpathETSimpleIO{}.EncMapInt32Int32V(rv2i(rv).(map[int32]int32), e) -} -func (fastpathETSimpleIO) EncMapInt32Int32V(v map[int32]int32, e *encoderSimpleIO) { - if len(v) == 0 { - e.e.WriteMapEmpty() - return - } - var i uint - e.mapStart(len(v)) - if e.h.Canonical { - v2 := make([]int32, len(v)) - for k := range v { - v2[i] = k - i++ - } - slices.Sort(v2) - for i, k2 := range v2 { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeInt(int64(k2)) - e.mapElemValue() - e.e.EncodeInt(int64(v[k2])) - } - } else { - i = 0 - for k2, v2 := range v { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeInt(int64(k2)) - e.mapElemValue() - e.e.EncodeInt(int64(v2)) - i++ - } - } - e.c = 0 - e.e.WriteMapEnd() -} -func (e *encoderSimpleIO) fastpathEncMapInt32Float64R(f *encFnInfo, rv reflect.Value) { - fastpathETSimpleIO{}.EncMapInt32Float64V(rv2i(rv).(map[int32]float64), e) -} -func (fastpathETSimpleIO) EncMapInt32Float64V(v map[int32]float64, e *encoderSimpleIO) { - if len(v) == 0 { - e.e.WriteMapEmpty() - return - } - var i uint - e.mapStart(len(v)) - if e.h.Canonical { - v2 := make([]int32, len(v)) - for k := range v { - v2[i] = k - i++ - } - slices.Sort(v2) - for i, k2 := range v2 { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeInt(int64(k2)) - e.mapElemValue() - e.e.EncodeFloat64(v[k2]) - } - } else { - i = 0 - for k2, v2 := range v { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeInt(int64(k2)) - e.mapElemValue() - e.e.EncodeFloat64(v2) - i++ - } - } - e.c = 0 - e.e.WriteMapEnd() -} -func (e *encoderSimpleIO) fastpathEncMapInt32BoolR(f *encFnInfo, rv reflect.Value) { - fastpathETSimpleIO{}.EncMapInt32BoolV(rv2i(rv).(map[int32]bool), e) -} -func (fastpathETSimpleIO) EncMapInt32BoolV(v map[int32]bool, e *encoderSimpleIO) { - if len(v) == 0 { - e.e.WriteMapEmpty() - return - } - var i uint - e.mapStart(len(v)) - if e.h.Canonical { - v2 := make([]int32, len(v)) - for k := range v { - v2[i] = k - i++ - } - slices.Sort(v2) - for i, k2 := range v2 { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeInt(int64(k2)) - e.mapElemValue() - e.e.EncodeBool(v[k2]) - } - } else { - i = 0 - for k2, v2 := range v { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeInt(int64(k2)) - e.mapElemValue() - e.e.EncodeBool(v2) - i++ - } - } - e.c = 0 - e.e.WriteMapEnd() -} - -func (helperDecDriverSimpleIO) fastpathDecodeTypeSwitch(iv interface{}, d *decoderSimpleIO) bool { - var ft fastpathDTSimpleIO - var changed bool - var containerLen int - switch v := iv.(type) { - case []interface{}: - ft.DecSliceIntfN(v, d) - case *[]interface{}: - var v2 []interface{} - if v2, changed = ft.DecSliceIntfY(*v, d); changed { - *v = v2 - } - case []string: - ft.DecSliceStringN(v, d) - case *[]string: - var v2 []string - if v2, changed = ft.DecSliceStringY(*v, d); changed { - *v = v2 - } - case [][]byte: - ft.DecSliceBytesN(v, d) - case *[][]byte: - var v2 [][]byte - if v2, changed = ft.DecSliceBytesY(*v, d); changed { - *v = v2 - } - case []float32: - ft.DecSliceFloat32N(v, d) - case *[]float32: - var v2 []float32 - if v2, changed = ft.DecSliceFloat32Y(*v, d); changed { - *v = v2 - } - case []float64: - ft.DecSliceFloat64N(v, d) - case *[]float64: - var v2 []float64 - if v2, changed = ft.DecSliceFloat64Y(*v, d); changed { - *v = v2 - } - case []uint8: - ft.DecSliceUint8N(v, d) - case *[]uint8: - var v2 []uint8 - if v2, changed = ft.DecSliceUint8Y(*v, d); changed { - *v = v2 - } - case []uint64: - ft.DecSliceUint64N(v, d) - case *[]uint64: - var v2 []uint64 - if v2, changed = ft.DecSliceUint64Y(*v, d); changed { - *v = v2 - } - case []int: - ft.DecSliceIntN(v, d) - case *[]int: - var v2 []int - if v2, changed = ft.DecSliceIntY(*v, d); changed { - *v = v2 - } - case []int32: - ft.DecSliceInt32N(v, d) - case *[]int32: - var v2 []int32 - if v2, changed = ft.DecSliceInt32Y(*v, d); changed { - *v = v2 - } - case []int64: - ft.DecSliceInt64N(v, d) - case *[]int64: - var v2 []int64 - if v2, changed = ft.DecSliceInt64Y(*v, d); changed { - *v = v2 - } - case []bool: - ft.DecSliceBoolN(v, d) - case *[]bool: - var v2 []bool - if v2, changed = ft.DecSliceBoolY(*v, d); changed { - *v = v2 - } - case map[string]interface{}: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen != containerLenNil { - if containerLen != 0 { - ft.DecMapStringIntfL(v, containerLen, d) - } - d.mapEnd() - } - case *map[string]interface{}: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen == containerLenNil { - *v = nil - } else { - if *v == nil { - *v = make(map[string]interface{}, decInferLen(containerLen, d.maxInitLen(), 32)) - } - if containerLen != 0 { - ft.DecMapStringIntfL(*v, containerLen, d) - } - d.mapEnd() - } - case map[string]string: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen != containerLenNil { - if containerLen != 0 { - ft.DecMapStringStringL(v, containerLen, d) - } - d.mapEnd() - } - case *map[string]string: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen == containerLenNil { - *v = nil - } else { - if *v == nil { - *v = make(map[string]string, decInferLen(containerLen, d.maxInitLen(), 32)) - } - if containerLen != 0 { - ft.DecMapStringStringL(*v, containerLen, d) - } - d.mapEnd() - } - case map[string][]byte: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen != containerLenNil { - if containerLen != 0 { - ft.DecMapStringBytesL(v, containerLen, d) - } - d.mapEnd() - } - case *map[string][]byte: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen == containerLenNil { - *v = nil - } else { - if *v == nil { - *v = make(map[string][]byte, decInferLen(containerLen, d.maxInitLen(), 40)) - } - if containerLen != 0 { - ft.DecMapStringBytesL(*v, containerLen, d) - } - d.mapEnd() - } - case map[string]uint8: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen != containerLenNil { - if containerLen != 0 { - ft.DecMapStringUint8L(v, containerLen, d) - } - d.mapEnd() - } - case *map[string]uint8: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen == containerLenNil { - *v = nil - } else { - if *v == nil { - *v = make(map[string]uint8, decInferLen(containerLen, d.maxInitLen(), 17)) - } - if containerLen != 0 { - ft.DecMapStringUint8L(*v, containerLen, d) - } - d.mapEnd() - } - case map[string]uint64: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen != containerLenNil { - if containerLen != 0 { - ft.DecMapStringUint64L(v, containerLen, d) - } - d.mapEnd() - } - case *map[string]uint64: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen == containerLenNil { - *v = nil - } else { - if *v == nil { - *v = make(map[string]uint64, decInferLen(containerLen, d.maxInitLen(), 24)) - } - if containerLen != 0 { - ft.DecMapStringUint64L(*v, containerLen, d) - } - d.mapEnd() - } - case map[string]int: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen != containerLenNil { - if containerLen != 0 { - ft.DecMapStringIntL(v, containerLen, d) - } - d.mapEnd() - } - case *map[string]int: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen == containerLenNil { - *v = nil - } else { - if *v == nil { - *v = make(map[string]int, decInferLen(containerLen, d.maxInitLen(), 24)) - } - if containerLen != 0 { - ft.DecMapStringIntL(*v, containerLen, d) - } - d.mapEnd() - } - case map[string]int32: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen != containerLenNil { - if containerLen != 0 { - ft.DecMapStringInt32L(v, containerLen, d) - } - d.mapEnd() - } - case *map[string]int32: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen == containerLenNil { - *v = nil - } else { - if *v == nil { - *v = make(map[string]int32, decInferLen(containerLen, d.maxInitLen(), 20)) - } - if containerLen != 0 { - ft.DecMapStringInt32L(*v, containerLen, d) - } - d.mapEnd() - } - case map[string]float64: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen != containerLenNil { - if containerLen != 0 { - ft.DecMapStringFloat64L(v, containerLen, d) - } - d.mapEnd() - } - case *map[string]float64: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen == containerLenNil { - *v = nil - } else { - if *v == nil { - *v = make(map[string]float64, decInferLen(containerLen, d.maxInitLen(), 24)) - } - if containerLen != 0 { - ft.DecMapStringFloat64L(*v, containerLen, d) - } - d.mapEnd() - } - case map[string]bool: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen != containerLenNil { - if containerLen != 0 { - ft.DecMapStringBoolL(v, containerLen, d) - } - d.mapEnd() - } - case *map[string]bool: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen == containerLenNil { - *v = nil - } else { - if *v == nil { - *v = make(map[string]bool, decInferLen(containerLen, d.maxInitLen(), 17)) - } - if containerLen != 0 { - ft.DecMapStringBoolL(*v, containerLen, d) - } - d.mapEnd() - } - case map[uint8]interface{}: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen != containerLenNil { - if containerLen != 0 { - ft.DecMapUint8IntfL(v, containerLen, d) - } - d.mapEnd() - } - case *map[uint8]interface{}: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen == containerLenNil { - *v = nil - } else { - if *v == nil { - *v = make(map[uint8]interface{}, decInferLen(containerLen, d.maxInitLen(), 17)) - } - if containerLen != 0 { - ft.DecMapUint8IntfL(*v, containerLen, d) - } - d.mapEnd() - } - case map[uint8]string: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen != containerLenNil { - if containerLen != 0 { - ft.DecMapUint8StringL(v, containerLen, d) - } - d.mapEnd() - } - case *map[uint8]string: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen == containerLenNil { - *v = nil - } else { - if *v == nil { - *v = make(map[uint8]string, decInferLen(containerLen, d.maxInitLen(), 17)) - } - if containerLen != 0 { - ft.DecMapUint8StringL(*v, containerLen, d) - } - d.mapEnd() - } - case map[uint8][]byte: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen != containerLenNil { - if containerLen != 0 { - ft.DecMapUint8BytesL(v, containerLen, d) - } - d.mapEnd() - } - case *map[uint8][]byte: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen == containerLenNil { - *v = nil - } else { - if *v == nil { - *v = make(map[uint8][]byte, decInferLen(containerLen, d.maxInitLen(), 25)) - } - if containerLen != 0 { - ft.DecMapUint8BytesL(*v, containerLen, d) - } - d.mapEnd() - } - case map[uint8]uint8: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen != containerLenNil { - if containerLen != 0 { - ft.DecMapUint8Uint8L(v, containerLen, d) - } - d.mapEnd() - } - case *map[uint8]uint8: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen == containerLenNil { - *v = nil - } else { - if *v == nil { - *v = make(map[uint8]uint8, decInferLen(containerLen, d.maxInitLen(), 2)) - } - if containerLen != 0 { - ft.DecMapUint8Uint8L(*v, containerLen, d) - } - d.mapEnd() - } - case map[uint8]uint64: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen != containerLenNil { - if containerLen != 0 { - ft.DecMapUint8Uint64L(v, containerLen, d) - } - d.mapEnd() - } - case *map[uint8]uint64: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen == containerLenNil { - *v = nil - } else { - if *v == nil { - *v = make(map[uint8]uint64, decInferLen(containerLen, d.maxInitLen(), 9)) - } - if containerLen != 0 { - ft.DecMapUint8Uint64L(*v, containerLen, d) - } - d.mapEnd() - } - case map[uint8]int: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen != containerLenNil { - if containerLen != 0 { - ft.DecMapUint8IntL(v, containerLen, d) - } - d.mapEnd() - } - case *map[uint8]int: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen == containerLenNil { - *v = nil - } else { - if *v == nil { - *v = make(map[uint8]int, decInferLen(containerLen, d.maxInitLen(), 9)) - } - if containerLen != 0 { - ft.DecMapUint8IntL(*v, containerLen, d) - } - d.mapEnd() - } - case map[uint8]int32: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen != containerLenNil { - if containerLen != 0 { - ft.DecMapUint8Int32L(v, containerLen, d) - } - d.mapEnd() - } - case *map[uint8]int32: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen == containerLenNil { - *v = nil - } else { - if *v == nil { - *v = make(map[uint8]int32, decInferLen(containerLen, d.maxInitLen(), 5)) - } - if containerLen != 0 { - ft.DecMapUint8Int32L(*v, containerLen, d) - } - d.mapEnd() - } - case map[uint8]float64: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen != containerLenNil { - if containerLen != 0 { - ft.DecMapUint8Float64L(v, containerLen, d) - } - d.mapEnd() - } - case *map[uint8]float64: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen == containerLenNil { - *v = nil - } else { - if *v == nil { - *v = make(map[uint8]float64, decInferLen(containerLen, d.maxInitLen(), 9)) - } - if containerLen != 0 { - ft.DecMapUint8Float64L(*v, containerLen, d) - } - d.mapEnd() - } - case map[uint8]bool: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen != containerLenNil { - if containerLen != 0 { - ft.DecMapUint8BoolL(v, containerLen, d) - } - d.mapEnd() - } - case *map[uint8]bool: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen == containerLenNil { - *v = nil - } else { - if *v == nil { - *v = make(map[uint8]bool, decInferLen(containerLen, d.maxInitLen(), 2)) - } - if containerLen != 0 { - ft.DecMapUint8BoolL(*v, containerLen, d) - } - d.mapEnd() - } - case map[uint64]interface{}: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen != containerLenNil { - if containerLen != 0 { - ft.DecMapUint64IntfL(v, containerLen, d) - } - d.mapEnd() - } - case *map[uint64]interface{}: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen == containerLenNil { - *v = nil - } else { - if *v == nil { - *v = make(map[uint64]interface{}, decInferLen(containerLen, d.maxInitLen(), 24)) - } - if containerLen != 0 { - ft.DecMapUint64IntfL(*v, containerLen, d) - } - d.mapEnd() - } - case map[uint64]string: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen != containerLenNil { - if containerLen != 0 { - ft.DecMapUint64StringL(v, containerLen, d) - } - d.mapEnd() - } - case *map[uint64]string: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen == containerLenNil { - *v = nil - } else { - if *v == nil { - *v = make(map[uint64]string, decInferLen(containerLen, d.maxInitLen(), 24)) - } - if containerLen != 0 { - ft.DecMapUint64StringL(*v, containerLen, d) - } - d.mapEnd() - } - case map[uint64][]byte: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen != containerLenNil { - if containerLen != 0 { - ft.DecMapUint64BytesL(v, containerLen, d) - } - d.mapEnd() - } - case *map[uint64][]byte: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen == containerLenNil { - *v = nil - } else { - if *v == nil { - *v = make(map[uint64][]byte, decInferLen(containerLen, d.maxInitLen(), 32)) - } - if containerLen != 0 { - ft.DecMapUint64BytesL(*v, containerLen, d) - } - d.mapEnd() - } - case map[uint64]uint8: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen != containerLenNil { - if containerLen != 0 { - ft.DecMapUint64Uint8L(v, containerLen, d) - } - d.mapEnd() - } - case *map[uint64]uint8: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen == containerLenNil { - *v = nil - } else { - if *v == nil { - *v = make(map[uint64]uint8, decInferLen(containerLen, d.maxInitLen(), 9)) - } - if containerLen != 0 { - ft.DecMapUint64Uint8L(*v, containerLen, d) - } - d.mapEnd() - } - case map[uint64]uint64: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen != containerLenNil { - if containerLen != 0 { - ft.DecMapUint64Uint64L(v, containerLen, d) - } - d.mapEnd() - } - case *map[uint64]uint64: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen == containerLenNil { - *v = nil - } else { - if *v == nil { - *v = make(map[uint64]uint64, decInferLen(containerLen, d.maxInitLen(), 16)) - } - if containerLen != 0 { - ft.DecMapUint64Uint64L(*v, containerLen, d) - } - d.mapEnd() - } - case map[uint64]int: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen != containerLenNil { - if containerLen != 0 { - ft.DecMapUint64IntL(v, containerLen, d) - } - d.mapEnd() - } - case *map[uint64]int: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen == containerLenNil { - *v = nil - } else { - if *v == nil { - *v = make(map[uint64]int, decInferLen(containerLen, d.maxInitLen(), 16)) - } - if containerLen != 0 { - ft.DecMapUint64IntL(*v, containerLen, d) - } - d.mapEnd() - } - case map[uint64]int32: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen != containerLenNil { - if containerLen != 0 { - ft.DecMapUint64Int32L(v, containerLen, d) - } - d.mapEnd() - } - case *map[uint64]int32: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen == containerLenNil { - *v = nil - } else { - if *v == nil { - *v = make(map[uint64]int32, decInferLen(containerLen, d.maxInitLen(), 12)) - } - if containerLen != 0 { - ft.DecMapUint64Int32L(*v, containerLen, d) - } - d.mapEnd() - } - case map[uint64]float64: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen != containerLenNil { - if containerLen != 0 { - ft.DecMapUint64Float64L(v, containerLen, d) - } - d.mapEnd() - } - case *map[uint64]float64: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen == containerLenNil { - *v = nil - } else { - if *v == nil { - *v = make(map[uint64]float64, decInferLen(containerLen, d.maxInitLen(), 16)) - } - if containerLen != 0 { - ft.DecMapUint64Float64L(*v, containerLen, d) - } - d.mapEnd() - } - case map[uint64]bool: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen != containerLenNil { - if containerLen != 0 { - ft.DecMapUint64BoolL(v, containerLen, d) - } - d.mapEnd() - } - case *map[uint64]bool: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen == containerLenNil { - *v = nil - } else { - if *v == nil { - *v = make(map[uint64]bool, decInferLen(containerLen, d.maxInitLen(), 9)) - } - if containerLen != 0 { - ft.DecMapUint64BoolL(*v, containerLen, d) - } - d.mapEnd() - } - case map[int]interface{}: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen != containerLenNil { - if containerLen != 0 { - ft.DecMapIntIntfL(v, containerLen, d) - } - d.mapEnd() - } - case *map[int]interface{}: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen == containerLenNil { - *v = nil - } else { - if *v == nil { - *v = make(map[int]interface{}, decInferLen(containerLen, d.maxInitLen(), 24)) - } - if containerLen != 0 { - ft.DecMapIntIntfL(*v, containerLen, d) - } - d.mapEnd() - } - case map[int]string: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen != containerLenNil { - if containerLen != 0 { - ft.DecMapIntStringL(v, containerLen, d) - } - d.mapEnd() - } - case *map[int]string: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen == containerLenNil { - *v = nil - } else { - if *v == nil { - *v = make(map[int]string, decInferLen(containerLen, d.maxInitLen(), 24)) - } - if containerLen != 0 { - ft.DecMapIntStringL(*v, containerLen, d) - } - d.mapEnd() - } - case map[int][]byte: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen != containerLenNil { - if containerLen != 0 { - ft.DecMapIntBytesL(v, containerLen, d) - } - d.mapEnd() - } - case *map[int][]byte: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen == containerLenNil { - *v = nil - } else { - if *v == nil { - *v = make(map[int][]byte, decInferLen(containerLen, d.maxInitLen(), 32)) - } - if containerLen != 0 { - ft.DecMapIntBytesL(*v, containerLen, d) - } - d.mapEnd() - } - case map[int]uint8: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen != containerLenNil { - if containerLen != 0 { - ft.DecMapIntUint8L(v, containerLen, d) - } - d.mapEnd() - } - case *map[int]uint8: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen == containerLenNil { - *v = nil - } else { - if *v == nil { - *v = make(map[int]uint8, decInferLen(containerLen, d.maxInitLen(), 9)) - } - if containerLen != 0 { - ft.DecMapIntUint8L(*v, containerLen, d) - } - d.mapEnd() - } - case map[int]uint64: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen != containerLenNil { - if containerLen != 0 { - ft.DecMapIntUint64L(v, containerLen, d) - } - d.mapEnd() - } - case *map[int]uint64: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen == containerLenNil { - *v = nil - } else { - if *v == nil { - *v = make(map[int]uint64, decInferLen(containerLen, d.maxInitLen(), 16)) - } - if containerLen != 0 { - ft.DecMapIntUint64L(*v, containerLen, d) - } - d.mapEnd() - } - case map[int]int: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen != containerLenNil { - if containerLen != 0 { - ft.DecMapIntIntL(v, containerLen, d) - } - d.mapEnd() - } - case *map[int]int: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen == containerLenNil { - *v = nil - } else { - if *v == nil { - *v = make(map[int]int, decInferLen(containerLen, d.maxInitLen(), 16)) - } - if containerLen != 0 { - ft.DecMapIntIntL(*v, containerLen, d) - } - d.mapEnd() - } - case map[int]int32: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen != containerLenNil { - if containerLen != 0 { - ft.DecMapIntInt32L(v, containerLen, d) - } - d.mapEnd() - } - case *map[int]int32: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen == containerLenNil { - *v = nil - } else { - if *v == nil { - *v = make(map[int]int32, decInferLen(containerLen, d.maxInitLen(), 12)) - } - if containerLen != 0 { - ft.DecMapIntInt32L(*v, containerLen, d) - } - d.mapEnd() - } - case map[int]float64: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen != containerLenNil { - if containerLen != 0 { - ft.DecMapIntFloat64L(v, containerLen, d) - } - d.mapEnd() - } - case *map[int]float64: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen == containerLenNil { - *v = nil - } else { - if *v == nil { - *v = make(map[int]float64, decInferLen(containerLen, d.maxInitLen(), 16)) - } - if containerLen != 0 { - ft.DecMapIntFloat64L(*v, containerLen, d) - } - d.mapEnd() - } - case map[int]bool: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen != containerLenNil { - if containerLen != 0 { - ft.DecMapIntBoolL(v, containerLen, d) - } - d.mapEnd() - } - case *map[int]bool: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen == containerLenNil { - *v = nil - } else { - if *v == nil { - *v = make(map[int]bool, decInferLen(containerLen, d.maxInitLen(), 9)) - } - if containerLen != 0 { - ft.DecMapIntBoolL(*v, containerLen, d) - } - d.mapEnd() - } - case map[int32]interface{}: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen != containerLenNil { - if containerLen != 0 { - ft.DecMapInt32IntfL(v, containerLen, d) - } - d.mapEnd() - } - case *map[int32]interface{}: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen == containerLenNil { - *v = nil - } else { - if *v == nil { - *v = make(map[int32]interface{}, decInferLen(containerLen, d.maxInitLen(), 20)) - } - if containerLen != 0 { - ft.DecMapInt32IntfL(*v, containerLen, d) - } - d.mapEnd() - } - case map[int32]string: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen != containerLenNil { - if containerLen != 0 { - ft.DecMapInt32StringL(v, containerLen, d) - } - d.mapEnd() - } - case *map[int32]string: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen == containerLenNil { - *v = nil - } else { - if *v == nil { - *v = make(map[int32]string, decInferLen(containerLen, d.maxInitLen(), 20)) - } - if containerLen != 0 { - ft.DecMapInt32StringL(*v, containerLen, d) - } - d.mapEnd() - } - case map[int32][]byte: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen != containerLenNil { - if containerLen != 0 { - ft.DecMapInt32BytesL(v, containerLen, d) - } - d.mapEnd() - } - case *map[int32][]byte: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen == containerLenNil { - *v = nil - } else { - if *v == nil { - *v = make(map[int32][]byte, decInferLen(containerLen, d.maxInitLen(), 28)) - } - if containerLen != 0 { - ft.DecMapInt32BytesL(*v, containerLen, d) - } - d.mapEnd() - } - case map[int32]uint8: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen != containerLenNil { - if containerLen != 0 { - ft.DecMapInt32Uint8L(v, containerLen, d) - } - d.mapEnd() - } - case *map[int32]uint8: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen == containerLenNil { - *v = nil - } else { - if *v == nil { - *v = make(map[int32]uint8, decInferLen(containerLen, d.maxInitLen(), 5)) - } - if containerLen != 0 { - ft.DecMapInt32Uint8L(*v, containerLen, d) - } - d.mapEnd() - } - case map[int32]uint64: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen != containerLenNil { - if containerLen != 0 { - ft.DecMapInt32Uint64L(v, containerLen, d) - } - d.mapEnd() - } - case *map[int32]uint64: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen == containerLenNil { - *v = nil - } else { - if *v == nil { - *v = make(map[int32]uint64, decInferLen(containerLen, d.maxInitLen(), 12)) - } - if containerLen != 0 { - ft.DecMapInt32Uint64L(*v, containerLen, d) - } - d.mapEnd() - } - case map[int32]int: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen != containerLenNil { - if containerLen != 0 { - ft.DecMapInt32IntL(v, containerLen, d) - } - d.mapEnd() - } - case *map[int32]int: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen == containerLenNil { - *v = nil - } else { - if *v == nil { - *v = make(map[int32]int, decInferLen(containerLen, d.maxInitLen(), 12)) - } - if containerLen != 0 { - ft.DecMapInt32IntL(*v, containerLen, d) - } - d.mapEnd() - } - case map[int32]int32: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen != containerLenNil { - if containerLen != 0 { - ft.DecMapInt32Int32L(v, containerLen, d) - } - d.mapEnd() - } - case *map[int32]int32: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen == containerLenNil { - *v = nil - } else { - if *v == nil { - *v = make(map[int32]int32, decInferLen(containerLen, d.maxInitLen(), 8)) - } - if containerLen != 0 { - ft.DecMapInt32Int32L(*v, containerLen, d) - } - d.mapEnd() - } - case map[int32]float64: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen != containerLenNil { - if containerLen != 0 { - ft.DecMapInt32Float64L(v, containerLen, d) - } - d.mapEnd() - } - case *map[int32]float64: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen == containerLenNil { - *v = nil - } else { - if *v == nil { - *v = make(map[int32]float64, decInferLen(containerLen, d.maxInitLen(), 12)) - } - if containerLen != 0 { - ft.DecMapInt32Float64L(*v, containerLen, d) - } - d.mapEnd() - } - case map[int32]bool: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen != containerLenNil { - if containerLen != 0 { - ft.DecMapInt32BoolL(v, containerLen, d) - } - d.mapEnd() - } - case *map[int32]bool: - if containerLen = d.mapStart(d.d.ReadMapStart()); containerLen == containerLenNil { - *v = nil - } else { - if *v == nil { - *v = make(map[int32]bool, decInferLen(containerLen, d.maxInitLen(), 5)) - } - if containerLen != 0 { - ft.DecMapInt32BoolL(*v, containerLen, d) - } - d.mapEnd() - } - default: - _ = v - return false - } - return true -} - -func (d *decoderSimpleIO) fastpathDecSliceIntfR(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTSimpleIO - switch rv.Kind() { - case reflect.Ptr: - v := rv2i(rv).(*[]interface{}) - if vv, changed := ft.DecSliceIntfY(*v, d); changed { - *v = vv - } - case reflect.Array: - var v []interface{} - rvGetSlice4Array(rv, &v) - ft.DecSliceIntfN(v, d) - default: - ft.DecSliceIntfN(rv2i(rv).([]interface{}), d) - } -} -func (fastpathDTSimpleIO) DecSliceIntfY(v []interface{}, d *decoderSimpleIO) (v2 []interface{}, changed bool) { - ctyp := d.d.ContainerType() - if ctyp == valueTypeNil { - return nil, v != nil - } - var containerLenS int - isArray := ctyp == valueTypeArray - if isArray { - containerLenS = d.arrayStart(d.d.ReadArrayStart()) - } else if ctyp == valueTypeMap { - containerLenS = d.mapStart(d.d.ReadMapStart()) * 2 - } else { - halt.errorStr2("decoding into a slice, expect map/array - got ", ctyp.String()) - } - hasLen := containerLenS >= 0 - var j int - fnv := func(dst []interface{}) { v, changed = dst, true } - for ; d.containerNext(j, containerLenS, hasLen); j++ { - if j == 0 { - if containerLenS == len(v) { - } else if containerLenS < 0 || containerLenS > cap(v) { - if xlen := int(decInferLen(containerLenS, d.maxInitLen(), 16)); xlen <= cap(v) { - fnv(v[:uint(xlen)]) - } else { - v2 = make([]interface{}, uint(xlen)) - copy(v2, v) - fnv(v2) - } - } else { - fnv(v[:containerLenS]) - } - } - if isArray { - d.arrayElem(j == 0) - } else if j&1 == 0 { - d.mapElemKey(j == 0) - } else { - d.mapElemValue() - } - if j >= len(v) { - fnv(append(v, nil)) - } - d.decode(&v[uint(j)]) - } - if j < len(v) { - fnv(v[:uint(j)]) - } else if j == 0 && v == nil { - fnv([]interface{}{}) - } - if isArray { - d.arrayEnd() - } else { - d.mapEnd() - } - return v, changed -} -func (fastpathDTSimpleIO) DecSliceIntfN(v []interface{}, d *decoderSimpleIO) { - ctyp := d.d.ContainerType() - if ctyp == valueTypeNil { - return - } - var containerLenS int - isArray := ctyp == valueTypeArray - if isArray { - containerLenS = d.arrayStart(d.d.ReadArrayStart()) - } else if ctyp == valueTypeMap { - containerLenS = d.mapStart(d.d.ReadMapStart()) * 2 - } else { - halt.errorStr2("decoding into a slice, expect map/array - got ", ctyp.String()) - } - hasLen := containerLenS >= 0 - for j := 0; d.containerNext(j, containerLenS, hasLen); j++ { - if isArray { - d.arrayElem(j == 0) - } else if j&1 == 0 { - d.mapElemKey(j == 0) - } else { - d.mapElemValue() - } - if j < len(v) { - d.decode(&v[uint(j)]) - } else { - d.arrayCannotExpand(len(v), j+1) - d.swallow() - } - } - if isArray { - d.arrayEnd() - } else { - d.mapEnd() - } -} - -func (d *decoderSimpleIO) fastpathDecSliceStringR(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTSimpleIO - switch rv.Kind() { - case reflect.Ptr: - v := rv2i(rv).(*[]string) - if vv, changed := ft.DecSliceStringY(*v, d); changed { - *v = vv - } - case reflect.Array: - var v []string - rvGetSlice4Array(rv, &v) - ft.DecSliceStringN(v, d) - default: - ft.DecSliceStringN(rv2i(rv).([]string), d) - } -} -func (fastpathDTSimpleIO) DecSliceStringY(v []string, d *decoderSimpleIO) (v2 []string, changed bool) { - ctyp := d.d.ContainerType() - if ctyp == valueTypeNil { - return nil, v != nil - } - var containerLenS int - isArray := ctyp == valueTypeArray - if isArray { - containerLenS = d.arrayStart(d.d.ReadArrayStart()) - } else if ctyp == valueTypeMap { - containerLenS = d.mapStart(d.d.ReadMapStart()) * 2 - } else { - halt.errorStr2("decoding into a slice, expect map/array - got ", ctyp.String()) - } - hasLen := containerLenS >= 0 - var j int - fnv := func(dst []string) { v, changed = dst, true } - for ; d.containerNext(j, containerLenS, hasLen); j++ { - if j == 0 { - if containerLenS == len(v) { - } else if containerLenS < 0 || containerLenS > cap(v) { - if xlen := int(decInferLen(containerLenS, d.maxInitLen(), 16)); xlen <= cap(v) { - fnv(v[:uint(xlen)]) - } else { - v2 = make([]string, uint(xlen)) - copy(v2, v) - fnv(v2) - } - } else { - fnv(v[:containerLenS]) - } - } - if isArray { - d.arrayElem(j == 0) - } else if j&1 == 0 { - d.mapElemKey(j == 0) - } else { - d.mapElemValue() - } - if j >= len(v) { - fnv(append(v, "")) - } - v[uint(j)] = d.detach2Str(d.d.DecodeStringAsBytes()) - } - if j < len(v) { - fnv(v[:uint(j)]) - } else if j == 0 && v == nil { - fnv([]string{}) - } - if isArray { - d.arrayEnd() - } else { - d.mapEnd() - } - return v, changed -} -func (fastpathDTSimpleIO) DecSliceStringN(v []string, d *decoderSimpleIO) { - ctyp := d.d.ContainerType() - if ctyp == valueTypeNil { - return - } - var containerLenS int - isArray := ctyp == valueTypeArray - if isArray { - containerLenS = d.arrayStart(d.d.ReadArrayStart()) - } else if ctyp == valueTypeMap { - containerLenS = d.mapStart(d.d.ReadMapStart()) * 2 - } else { - halt.errorStr2("decoding into a slice, expect map/array - got ", ctyp.String()) - } - hasLen := containerLenS >= 0 - for j := 0; d.containerNext(j, containerLenS, hasLen); j++ { - if isArray { - d.arrayElem(j == 0) - } else if j&1 == 0 { - d.mapElemKey(j == 0) - } else { - d.mapElemValue() - } - if j < len(v) { - v[uint(j)] = d.detach2Str(d.d.DecodeStringAsBytes()) - } else { - d.arrayCannotExpand(len(v), j+1) - d.swallow() - } - } - if isArray { - d.arrayEnd() - } else { - d.mapEnd() - } -} - -func (d *decoderSimpleIO) fastpathDecSliceBytesR(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTSimpleIO - switch rv.Kind() { - case reflect.Ptr: - v := rv2i(rv).(*[][]byte) - if vv, changed := ft.DecSliceBytesY(*v, d); changed { - *v = vv - } - case reflect.Array: - var v [][]byte - rvGetSlice4Array(rv, &v) - ft.DecSliceBytesN(v, d) - default: - ft.DecSliceBytesN(rv2i(rv).([][]byte), d) - } -} -func (fastpathDTSimpleIO) DecSliceBytesY(v [][]byte, d *decoderSimpleIO) (v2 [][]byte, changed bool) { - ctyp := d.d.ContainerType() - if ctyp == valueTypeNil { - return nil, v != nil - } - var containerLenS int - isArray := ctyp == valueTypeArray - if isArray { - containerLenS = d.arrayStart(d.d.ReadArrayStart()) - } else if ctyp == valueTypeMap { - containerLenS = d.mapStart(d.d.ReadMapStart()) * 2 - } else { - halt.errorStr2("decoding into a slice, expect map/array - got ", ctyp.String()) - } - hasLen := containerLenS >= 0 - var j int - fnv := func(dst [][]byte) { v, changed = dst, true } - for ; d.containerNext(j, containerLenS, hasLen); j++ { - if j == 0 { - if containerLenS == len(v) { - } else if containerLenS < 0 || containerLenS > cap(v) { - if xlen := int(decInferLen(containerLenS, d.maxInitLen(), 24)); xlen <= cap(v) { - fnv(v[:uint(xlen)]) - } else { - v2 = make([][]byte, uint(xlen)) - copy(v2, v) - fnv(v2) - } - } else { - fnv(v[:containerLenS]) - } - } - if isArray { - d.arrayElem(j == 0) - } else if j&1 == 0 { - d.mapElemKey(j == 0) - } else { - d.mapElemValue() - } - if j >= len(v) { - fnv(append(v, nil)) - } - v[uint(j)] = bytesOKdbi(d.decodeBytesInto(v[uint(j)], false)) - } - if j < len(v) { - fnv(v[:uint(j)]) - } else if j == 0 && v == nil { - fnv([][]byte{}) - } - if isArray { - d.arrayEnd() - } else { - d.mapEnd() - } - return v, changed -} -func (fastpathDTSimpleIO) DecSliceBytesN(v [][]byte, d *decoderSimpleIO) { - ctyp := d.d.ContainerType() - if ctyp == valueTypeNil { - return - } - var containerLenS int - isArray := ctyp == valueTypeArray - if isArray { - containerLenS = d.arrayStart(d.d.ReadArrayStart()) - } else if ctyp == valueTypeMap { - containerLenS = d.mapStart(d.d.ReadMapStart()) * 2 - } else { - halt.errorStr2("decoding into a slice, expect map/array - got ", ctyp.String()) - } - hasLen := containerLenS >= 0 - for j := 0; d.containerNext(j, containerLenS, hasLen); j++ { - if isArray { - d.arrayElem(j == 0) - } else if j&1 == 0 { - d.mapElemKey(j == 0) - } else { - d.mapElemValue() - } - if j < len(v) { - v[uint(j)] = bytesOKdbi(d.decodeBytesInto(v[uint(j)], false)) - } else { - d.arrayCannotExpand(len(v), j+1) - d.swallow() - } - } - if isArray { - d.arrayEnd() - } else { - d.mapEnd() - } -} - -func (d *decoderSimpleIO) fastpathDecSliceFloat32R(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTSimpleIO - switch rv.Kind() { - case reflect.Ptr: - v := rv2i(rv).(*[]float32) - if vv, changed := ft.DecSliceFloat32Y(*v, d); changed { - *v = vv - } - case reflect.Array: - var v []float32 - rvGetSlice4Array(rv, &v) - ft.DecSliceFloat32N(v, d) - default: - ft.DecSliceFloat32N(rv2i(rv).([]float32), d) - } -} -func (fastpathDTSimpleIO) DecSliceFloat32Y(v []float32, d *decoderSimpleIO) (v2 []float32, changed bool) { - ctyp := d.d.ContainerType() - if ctyp == valueTypeNil { - return nil, v != nil - } - var containerLenS int - isArray := ctyp == valueTypeArray - if isArray { - containerLenS = d.arrayStart(d.d.ReadArrayStart()) - } else if ctyp == valueTypeMap { - containerLenS = d.mapStart(d.d.ReadMapStart()) * 2 - } else { - halt.errorStr2("decoding into a slice, expect map/array - got ", ctyp.String()) - } - hasLen := containerLenS >= 0 - var j int - fnv := func(dst []float32) { v, changed = dst, true } - for ; d.containerNext(j, containerLenS, hasLen); j++ { - if j == 0 { - if containerLenS == len(v) { - } else if containerLenS < 0 || containerLenS > cap(v) { - if xlen := int(decInferLen(containerLenS, d.maxInitLen(), 4)); xlen <= cap(v) { - fnv(v[:uint(xlen)]) - } else { - v2 = make([]float32, uint(xlen)) - copy(v2, v) - fnv(v2) - } - } else { - fnv(v[:containerLenS]) - } - } - if isArray { - d.arrayElem(j == 0) - } else if j&1 == 0 { - d.mapElemKey(j == 0) - } else { - d.mapElemValue() - } - if j >= len(v) { - fnv(append(v, 0)) - } - v[uint(j)] = float32(d.d.DecodeFloat32()) - } - if j < len(v) { - fnv(v[:uint(j)]) - } else if j == 0 && v == nil { - fnv([]float32{}) - } - if isArray { - d.arrayEnd() - } else { - d.mapEnd() - } - return v, changed -} -func (fastpathDTSimpleIO) DecSliceFloat32N(v []float32, d *decoderSimpleIO) { - ctyp := d.d.ContainerType() - if ctyp == valueTypeNil { - return - } - var containerLenS int - isArray := ctyp == valueTypeArray - if isArray { - containerLenS = d.arrayStart(d.d.ReadArrayStart()) - } else if ctyp == valueTypeMap { - containerLenS = d.mapStart(d.d.ReadMapStart()) * 2 - } else { - halt.errorStr2("decoding into a slice, expect map/array - got ", ctyp.String()) - } - hasLen := containerLenS >= 0 - for j := 0; d.containerNext(j, containerLenS, hasLen); j++ { - if isArray { - d.arrayElem(j == 0) - } else if j&1 == 0 { - d.mapElemKey(j == 0) - } else { - d.mapElemValue() - } - if j < len(v) { - v[uint(j)] = float32(d.d.DecodeFloat32()) - } else { - d.arrayCannotExpand(len(v), j+1) - d.swallow() - } - } - if isArray { - d.arrayEnd() - } else { - d.mapEnd() - } -} - -func (d *decoderSimpleIO) fastpathDecSliceFloat64R(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTSimpleIO - switch rv.Kind() { - case reflect.Ptr: - v := rv2i(rv).(*[]float64) - if vv, changed := ft.DecSliceFloat64Y(*v, d); changed { - *v = vv - } - case reflect.Array: - var v []float64 - rvGetSlice4Array(rv, &v) - ft.DecSliceFloat64N(v, d) - default: - ft.DecSliceFloat64N(rv2i(rv).([]float64), d) - } -} -func (fastpathDTSimpleIO) DecSliceFloat64Y(v []float64, d *decoderSimpleIO) (v2 []float64, changed bool) { - ctyp := d.d.ContainerType() - if ctyp == valueTypeNil { - return nil, v != nil - } - var containerLenS int - isArray := ctyp == valueTypeArray - if isArray { - containerLenS = d.arrayStart(d.d.ReadArrayStart()) - } else if ctyp == valueTypeMap { - containerLenS = d.mapStart(d.d.ReadMapStart()) * 2 - } else { - halt.errorStr2("decoding into a slice, expect map/array - got ", ctyp.String()) - } - hasLen := containerLenS >= 0 - var j int - fnv := func(dst []float64) { v, changed = dst, true } - for ; d.containerNext(j, containerLenS, hasLen); j++ { - if j == 0 { - if containerLenS == len(v) { - } else if containerLenS < 0 || containerLenS > cap(v) { - if xlen := int(decInferLen(containerLenS, d.maxInitLen(), 8)); xlen <= cap(v) { - fnv(v[:uint(xlen)]) - } else { - v2 = make([]float64, uint(xlen)) - copy(v2, v) - fnv(v2) - } - } else { - fnv(v[:containerLenS]) - } - } - if isArray { - d.arrayElem(j == 0) - } else if j&1 == 0 { - d.mapElemKey(j == 0) - } else { - d.mapElemValue() - } - if j >= len(v) { - fnv(append(v, 0)) - } - v[uint(j)] = d.d.DecodeFloat64() - } - if j < len(v) { - fnv(v[:uint(j)]) - } else if j == 0 && v == nil { - fnv([]float64{}) - } - if isArray { - d.arrayEnd() - } else { - d.mapEnd() - } - return v, changed -} -func (fastpathDTSimpleIO) DecSliceFloat64N(v []float64, d *decoderSimpleIO) { - ctyp := d.d.ContainerType() - if ctyp == valueTypeNil { - return - } - var containerLenS int - isArray := ctyp == valueTypeArray - if isArray { - containerLenS = d.arrayStart(d.d.ReadArrayStart()) - } else if ctyp == valueTypeMap { - containerLenS = d.mapStart(d.d.ReadMapStart()) * 2 - } else { - halt.errorStr2("decoding into a slice, expect map/array - got ", ctyp.String()) - } - hasLen := containerLenS >= 0 - for j := 0; d.containerNext(j, containerLenS, hasLen); j++ { - if isArray { - d.arrayElem(j == 0) - } else if j&1 == 0 { - d.mapElemKey(j == 0) - } else { - d.mapElemValue() - } - if j < len(v) { - v[uint(j)] = d.d.DecodeFloat64() - } else { - d.arrayCannotExpand(len(v), j+1) - d.swallow() - } - } - if isArray { - d.arrayEnd() - } else { - d.mapEnd() - } -} - -func (d *decoderSimpleIO) fastpathDecSliceUint8R(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTSimpleIO - switch rv.Kind() { - case reflect.Ptr: - v := rv2i(rv).(*[]uint8) - if vv, changed := ft.DecSliceUint8Y(*v, d); changed { - *v = vv - } - case reflect.Array: - var v []uint8 - rvGetSlice4Array(rv, &v) - ft.DecSliceUint8N(v, d) - default: - ft.DecSliceUint8N(rv2i(rv).([]uint8), d) - } -} -func (fastpathDTSimpleIO) DecSliceUint8Y(v []uint8, d *decoderSimpleIO) (v2 []uint8, changed bool) { - ctyp := d.d.ContainerType() - if ctyp == valueTypeNil { - return nil, v != nil - } - if ctyp != valueTypeMap { - var dbi dBytesIntoState - v2, dbi = d.decodeBytesInto(v[:len(v):len(v)], false) - return v2, dbi != dBytesIntoParamOut - } - containerLenS := d.mapStart(d.d.ReadMapStart()) * 2 - hasLen := containerLenS >= 0 - var j int - fnv := func(dst []uint8) { v, changed = dst, true } - for ; d.containerNext(j, containerLenS, hasLen); j++ { - if j == 0 { - if containerLenS == len(v) { - } else if containerLenS < 0 || containerLenS > cap(v) { - if xlen := int(decInferLen(containerLenS, d.maxInitLen(), 1)); xlen <= cap(v) { - fnv(v[:uint(xlen)]) - } else { - v2 = make([]uint8, uint(xlen)) - copy(v2, v) - fnv(v2) - } - } else { - fnv(v[:containerLenS]) - } - } - if j&1 == 0 { - d.mapElemKey(j == 0) - } else { - d.mapElemValue() - } - if j >= len(v) { - fnv(append(v, 0)) - } - v[uint(j)] = uint8(chkOvf.UintV(d.d.DecodeUint64(), 8)) - } - if j < len(v) { - fnv(v[:uint(j)]) - } else if j == 0 && v == nil { - fnv([]uint8{}) - } - d.mapEnd() - return v, changed -} -func (fastpathDTSimpleIO) DecSliceUint8N(v []uint8, d *decoderSimpleIO) { - ctyp := d.d.ContainerType() - if ctyp == valueTypeNil { - return - } - if ctyp != valueTypeMap { - d.decodeBytesInto(v[:len(v):len(v)], true) - return - } - containerLenS := d.mapStart(d.d.ReadMapStart()) * 2 - hasLen := containerLenS >= 0 - for j := 0; d.containerNext(j, containerLenS, hasLen); j++ { - if j&1 == 0 { - d.mapElemKey(j == 0) - } else { - d.mapElemValue() - } - if j < len(v) { - v[uint(j)] = uint8(chkOvf.UintV(d.d.DecodeUint64(), 8)) - } else { - d.arrayCannotExpand(len(v), j+1) - d.swallow() - } - } - d.mapEnd() -} - -func (d *decoderSimpleIO) fastpathDecSliceUint64R(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTSimpleIO - switch rv.Kind() { - case reflect.Ptr: - v := rv2i(rv).(*[]uint64) - if vv, changed := ft.DecSliceUint64Y(*v, d); changed { - *v = vv - } - case reflect.Array: - var v []uint64 - rvGetSlice4Array(rv, &v) - ft.DecSliceUint64N(v, d) - default: - ft.DecSliceUint64N(rv2i(rv).([]uint64), d) - } -} -func (fastpathDTSimpleIO) DecSliceUint64Y(v []uint64, d *decoderSimpleIO) (v2 []uint64, changed bool) { - ctyp := d.d.ContainerType() - if ctyp == valueTypeNil { - return nil, v != nil - } - var containerLenS int - isArray := ctyp == valueTypeArray - if isArray { - containerLenS = d.arrayStart(d.d.ReadArrayStart()) - } else if ctyp == valueTypeMap { - containerLenS = d.mapStart(d.d.ReadMapStart()) * 2 - } else { - halt.errorStr2("decoding into a slice, expect map/array - got ", ctyp.String()) - } - hasLen := containerLenS >= 0 - var j int - fnv := func(dst []uint64) { v, changed = dst, true } - for ; d.containerNext(j, containerLenS, hasLen); j++ { - if j == 0 { - if containerLenS == len(v) { - } else if containerLenS < 0 || containerLenS > cap(v) { - if xlen := int(decInferLen(containerLenS, d.maxInitLen(), 8)); xlen <= cap(v) { - fnv(v[:uint(xlen)]) - } else { - v2 = make([]uint64, uint(xlen)) - copy(v2, v) - fnv(v2) - } - } else { - fnv(v[:containerLenS]) - } - } - if isArray { - d.arrayElem(j == 0) - } else if j&1 == 0 { - d.mapElemKey(j == 0) - } else { - d.mapElemValue() - } - if j >= len(v) { - fnv(append(v, 0)) - } - v[uint(j)] = d.d.DecodeUint64() - } - if j < len(v) { - fnv(v[:uint(j)]) - } else if j == 0 && v == nil { - fnv([]uint64{}) - } - if isArray { - d.arrayEnd() - } else { - d.mapEnd() - } - return v, changed -} -func (fastpathDTSimpleIO) DecSliceUint64N(v []uint64, d *decoderSimpleIO) { - ctyp := d.d.ContainerType() - if ctyp == valueTypeNil { - return - } - var containerLenS int - isArray := ctyp == valueTypeArray - if isArray { - containerLenS = d.arrayStart(d.d.ReadArrayStart()) - } else if ctyp == valueTypeMap { - containerLenS = d.mapStart(d.d.ReadMapStart()) * 2 - } else { - halt.errorStr2("decoding into a slice, expect map/array - got ", ctyp.String()) - } - hasLen := containerLenS >= 0 - for j := 0; d.containerNext(j, containerLenS, hasLen); j++ { - if isArray { - d.arrayElem(j == 0) - } else if j&1 == 0 { - d.mapElemKey(j == 0) - } else { - d.mapElemValue() - } - if j < len(v) { - v[uint(j)] = d.d.DecodeUint64() - } else { - d.arrayCannotExpand(len(v), j+1) - d.swallow() - } - } - if isArray { - d.arrayEnd() - } else { - d.mapEnd() - } -} - -func (d *decoderSimpleIO) fastpathDecSliceIntR(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTSimpleIO - switch rv.Kind() { - case reflect.Ptr: - v := rv2i(rv).(*[]int) - if vv, changed := ft.DecSliceIntY(*v, d); changed { - *v = vv - } - case reflect.Array: - var v []int - rvGetSlice4Array(rv, &v) - ft.DecSliceIntN(v, d) - default: - ft.DecSliceIntN(rv2i(rv).([]int), d) - } -} -func (fastpathDTSimpleIO) DecSliceIntY(v []int, d *decoderSimpleIO) (v2 []int, changed bool) { - ctyp := d.d.ContainerType() - if ctyp == valueTypeNil { - return nil, v != nil - } - var containerLenS int - isArray := ctyp == valueTypeArray - if isArray { - containerLenS = d.arrayStart(d.d.ReadArrayStart()) - } else if ctyp == valueTypeMap { - containerLenS = d.mapStart(d.d.ReadMapStart()) * 2 - } else { - halt.errorStr2("decoding into a slice, expect map/array - got ", ctyp.String()) - } - hasLen := containerLenS >= 0 - var j int - fnv := func(dst []int) { v, changed = dst, true } - for ; d.containerNext(j, containerLenS, hasLen); j++ { - if j == 0 { - if containerLenS == len(v) { - } else if containerLenS < 0 || containerLenS > cap(v) { - if xlen := int(decInferLen(containerLenS, d.maxInitLen(), 8)); xlen <= cap(v) { - fnv(v[:uint(xlen)]) - } else { - v2 = make([]int, uint(xlen)) - copy(v2, v) - fnv(v2) - } - } else { - fnv(v[:containerLenS]) - } - } - if isArray { - d.arrayElem(j == 0) - } else if j&1 == 0 { - d.mapElemKey(j == 0) - } else { - d.mapElemValue() - } - if j >= len(v) { - fnv(append(v, 0)) - } - v[uint(j)] = int(chkOvf.IntV(d.d.DecodeInt64(), intBitsize)) - } - if j < len(v) { - fnv(v[:uint(j)]) - } else if j == 0 && v == nil { - fnv([]int{}) - } - if isArray { - d.arrayEnd() - } else { - d.mapEnd() - } - return v, changed -} -func (fastpathDTSimpleIO) DecSliceIntN(v []int, d *decoderSimpleIO) { - ctyp := d.d.ContainerType() - if ctyp == valueTypeNil { - return - } - var containerLenS int - isArray := ctyp == valueTypeArray - if isArray { - containerLenS = d.arrayStart(d.d.ReadArrayStart()) - } else if ctyp == valueTypeMap { - containerLenS = d.mapStart(d.d.ReadMapStart()) * 2 - } else { - halt.errorStr2("decoding into a slice, expect map/array - got ", ctyp.String()) - } - hasLen := containerLenS >= 0 - for j := 0; d.containerNext(j, containerLenS, hasLen); j++ { - if isArray { - d.arrayElem(j == 0) - } else if j&1 == 0 { - d.mapElemKey(j == 0) - } else { - d.mapElemValue() - } - if j < len(v) { - v[uint(j)] = int(chkOvf.IntV(d.d.DecodeInt64(), intBitsize)) - } else { - d.arrayCannotExpand(len(v), j+1) - d.swallow() - } - } - if isArray { - d.arrayEnd() - } else { - d.mapEnd() - } -} - -func (d *decoderSimpleIO) fastpathDecSliceInt32R(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTSimpleIO - switch rv.Kind() { - case reflect.Ptr: - v := rv2i(rv).(*[]int32) - if vv, changed := ft.DecSliceInt32Y(*v, d); changed { - *v = vv - } - case reflect.Array: - var v []int32 - rvGetSlice4Array(rv, &v) - ft.DecSliceInt32N(v, d) - default: - ft.DecSliceInt32N(rv2i(rv).([]int32), d) - } -} -func (fastpathDTSimpleIO) DecSliceInt32Y(v []int32, d *decoderSimpleIO) (v2 []int32, changed bool) { - ctyp := d.d.ContainerType() - if ctyp == valueTypeNil { - return nil, v != nil - } - var containerLenS int - isArray := ctyp == valueTypeArray - if isArray { - containerLenS = d.arrayStart(d.d.ReadArrayStart()) - } else if ctyp == valueTypeMap { - containerLenS = d.mapStart(d.d.ReadMapStart()) * 2 - } else { - halt.errorStr2("decoding into a slice, expect map/array - got ", ctyp.String()) - } - hasLen := containerLenS >= 0 - var j int - fnv := func(dst []int32) { v, changed = dst, true } - for ; d.containerNext(j, containerLenS, hasLen); j++ { - if j == 0 { - if containerLenS == len(v) { - } else if containerLenS < 0 || containerLenS > cap(v) { - if xlen := int(decInferLen(containerLenS, d.maxInitLen(), 4)); xlen <= cap(v) { - fnv(v[:uint(xlen)]) - } else { - v2 = make([]int32, uint(xlen)) - copy(v2, v) - fnv(v2) - } - } else { - fnv(v[:containerLenS]) - } - } - if isArray { - d.arrayElem(j == 0) - } else if j&1 == 0 { - d.mapElemKey(j == 0) - } else { - d.mapElemValue() - } - if j >= len(v) { - fnv(append(v, 0)) - } - v[uint(j)] = int32(chkOvf.IntV(d.d.DecodeInt64(), 32)) - } - if j < len(v) { - fnv(v[:uint(j)]) - } else if j == 0 && v == nil { - fnv([]int32{}) - } - if isArray { - d.arrayEnd() - } else { - d.mapEnd() - } - return v, changed -} -func (fastpathDTSimpleIO) DecSliceInt32N(v []int32, d *decoderSimpleIO) { - ctyp := d.d.ContainerType() - if ctyp == valueTypeNil { - return - } - var containerLenS int - isArray := ctyp == valueTypeArray - if isArray { - containerLenS = d.arrayStart(d.d.ReadArrayStart()) - } else if ctyp == valueTypeMap { - containerLenS = d.mapStart(d.d.ReadMapStart()) * 2 - } else { - halt.errorStr2("decoding into a slice, expect map/array - got ", ctyp.String()) - } - hasLen := containerLenS >= 0 - for j := 0; d.containerNext(j, containerLenS, hasLen); j++ { - if isArray { - d.arrayElem(j == 0) - } else if j&1 == 0 { - d.mapElemKey(j == 0) - } else { - d.mapElemValue() - } - if j < len(v) { - v[uint(j)] = int32(chkOvf.IntV(d.d.DecodeInt64(), 32)) - } else { - d.arrayCannotExpand(len(v), j+1) - d.swallow() - } - } - if isArray { - d.arrayEnd() - } else { - d.mapEnd() - } -} - -func (d *decoderSimpleIO) fastpathDecSliceInt64R(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTSimpleIO - switch rv.Kind() { - case reflect.Ptr: - v := rv2i(rv).(*[]int64) - if vv, changed := ft.DecSliceInt64Y(*v, d); changed { - *v = vv - } - case reflect.Array: - var v []int64 - rvGetSlice4Array(rv, &v) - ft.DecSliceInt64N(v, d) - default: - ft.DecSliceInt64N(rv2i(rv).([]int64), d) - } -} -func (fastpathDTSimpleIO) DecSliceInt64Y(v []int64, d *decoderSimpleIO) (v2 []int64, changed bool) { - ctyp := d.d.ContainerType() - if ctyp == valueTypeNil { - return nil, v != nil - } - var containerLenS int - isArray := ctyp == valueTypeArray - if isArray { - containerLenS = d.arrayStart(d.d.ReadArrayStart()) - } else if ctyp == valueTypeMap { - containerLenS = d.mapStart(d.d.ReadMapStart()) * 2 - } else { - halt.errorStr2("decoding into a slice, expect map/array - got ", ctyp.String()) - } - hasLen := containerLenS >= 0 - var j int - fnv := func(dst []int64) { v, changed = dst, true } - for ; d.containerNext(j, containerLenS, hasLen); j++ { - if j == 0 { - if containerLenS == len(v) { - } else if containerLenS < 0 || containerLenS > cap(v) { - if xlen := int(decInferLen(containerLenS, d.maxInitLen(), 8)); xlen <= cap(v) { - fnv(v[:uint(xlen)]) - } else { - v2 = make([]int64, uint(xlen)) - copy(v2, v) - fnv(v2) - } - } else { - fnv(v[:containerLenS]) - } - } - if isArray { - d.arrayElem(j == 0) - } else if j&1 == 0 { - d.mapElemKey(j == 0) - } else { - d.mapElemValue() - } - if j >= len(v) { - fnv(append(v, 0)) - } - v[uint(j)] = d.d.DecodeInt64() - } - if j < len(v) { - fnv(v[:uint(j)]) - } else if j == 0 && v == nil { - fnv([]int64{}) - } - if isArray { - d.arrayEnd() - } else { - d.mapEnd() - } - return v, changed -} -func (fastpathDTSimpleIO) DecSliceInt64N(v []int64, d *decoderSimpleIO) { - ctyp := d.d.ContainerType() - if ctyp == valueTypeNil { - return - } - var containerLenS int - isArray := ctyp == valueTypeArray - if isArray { - containerLenS = d.arrayStart(d.d.ReadArrayStart()) - } else if ctyp == valueTypeMap { - containerLenS = d.mapStart(d.d.ReadMapStart()) * 2 - } else { - halt.errorStr2("decoding into a slice, expect map/array - got ", ctyp.String()) - } - hasLen := containerLenS >= 0 - for j := 0; d.containerNext(j, containerLenS, hasLen); j++ { - if isArray { - d.arrayElem(j == 0) - } else if j&1 == 0 { - d.mapElemKey(j == 0) - } else { - d.mapElemValue() - } - if j < len(v) { - v[uint(j)] = d.d.DecodeInt64() - } else { - d.arrayCannotExpand(len(v), j+1) - d.swallow() - } - } - if isArray { - d.arrayEnd() - } else { - d.mapEnd() - } -} - -func (d *decoderSimpleIO) fastpathDecSliceBoolR(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTSimpleIO - switch rv.Kind() { - case reflect.Ptr: - v := rv2i(rv).(*[]bool) - if vv, changed := ft.DecSliceBoolY(*v, d); changed { - *v = vv - } - case reflect.Array: - var v []bool - rvGetSlice4Array(rv, &v) - ft.DecSliceBoolN(v, d) - default: - ft.DecSliceBoolN(rv2i(rv).([]bool), d) - } -} -func (fastpathDTSimpleIO) DecSliceBoolY(v []bool, d *decoderSimpleIO) (v2 []bool, changed bool) { - ctyp := d.d.ContainerType() - if ctyp == valueTypeNil { - return nil, v != nil - } - var containerLenS int - isArray := ctyp == valueTypeArray - if isArray { - containerLenS = d.arrayStart(d.d.ReadArrayStart()) - } else if ctyp == valueTypeMap { - containerLenS = d.mapStart(d.d.ReadMapStart()) * 2 - } else { - halt.errorStr2("decoding into a slice, expect map/array - got ", ctyp.String()) - } - hasLen := containerLenS >= 0 - var j int - fnv := func(dst []bool) { v, changed = dst, true } - for ; d.containerNext(j, containerLenS, hasLen); j++ { - if j == 0 { - if containerLenS == len(v) { - } else if containerLenS < 0 || containerLenS > cap(v) { - if xlen := int(decInferLen(containerLenS, d.maxInitLen(), 1)); xlen <= cap(v) { - fnv(v[:uint(xlen)]) - } else { - v2 = make([]bool, uint(xlen)) - copy(v2, v) - fnv(v2) - } - } else { - fnv(v[:containerLenS]) - } - } - if isArray { - d.arrayElem(j == 0) - } else if j&1 == 0 { - d.mapElemKey(j == 0) - } else { - d.mapElemValue() - } - if j >= len(v) { - fnv(append(v, false)) - } - v[uint(j)] = d.d.DecodeBool() - } - if j < len(v) { - fnv(v[:uint(j)]) - } else if j == 0 && v == nil { - fnv([]bool{}) - } - if isArray { - d.arrayEnd() - } else { - d.mapEnd() - } - return v, changed -} -func (fastpathDTSimpleIO) DecSliceBoolN(v []bool, d *decoderSimpleIO) { - ctyp := d.d.ContainerType() - if ctyp == valueTypeNil { - return - } - var containerLenS int - isArray := ctyp == valueTypeArray - if isArray { - containerLenS = d.arrayStart(d.d.ReadArrayStart()) - } else if ctyp == valueTypeMap { - containerLenS = d.mapStart(d.d.ReadMapStart()) * 2 - } else { - halt.errorStr2("decoding into a slice, expect map/array - got ", ctyp.String()) - } - hasLen := containerLenS >= 0 - for j := 0; d.containerNext(j, containerLenS, hasLen); j++ { - if isArray { - d.arrayElem(j == 0) - } else if j&1 == 0 { - d.mapElemKey(j == 0) - } else { - d.mapElemValue() - } - if j < len(v) { - v[uint(j)] = d.d.DecodeBool() - } else { - d.arrayCannotExpand(len(v), j+1) - d.swallow() - } - } - if isArray { - d.arrayEnd() - } else { - d.mapEnd() - } -} -func (d *decoderSimpleIO) fastpathDecMapStringIntfR(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTSimpleIO - containerLen := d.mapStart(d.d.ReadMapStart()) - if rv.Kind() == reflect.Ptr { - vp, _ := rv2i(rv).(*map[string]interface{}) - if *vp == nil { - *vp = make(map[string]interface{}, decInferLen(containerLen, d.maxInitLen(), 32)) - } - if containerLen != 0 { - ft.DecMapStringIntfL(*vp, containerLen, d) - } - } else if containerLen != 0 { - ft.DecMapStringIntfL(rv2i(rv).(map[string]interface{}), containerLen, d) - } - d.mapEnd() -} -func (fastpathDTSimpleIO) DecMapStringIntfL(v map[string]interface{}, containerLen int, d *decoderSimpleIO) { - if v == nil { - halt.errorInt("cannot decode into nil map[string]interface{} given stream length: ", int64(containerLen)) - } - var mv interface{} - mapGet := !d.h.MapValueReset && !d.h.InterfaceReset - hasLen := containerLen >= 0 - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - mk := d.detach2Str(d.d.DecodeStringAsBytes()) - d.mapElemValue() - if mapGet { - mv = v[mk] - } else { - mv = nil - } - d.decode(&mv) - v[mk] = mv - } -} -func (d *decoderSimpleIO) fastpathDecMapStringStringR(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTSimpleIO - containerLen := d.mapStart(d.d.ReadMapStart()) - if rv.Kind() == reflect.Ptr { - vp, _ := rv2i(rv).(*map[string]string) - if *vp == nil { - *vp = make(map[string]string, decInferLen(containerLen, d.maxInitLen(), 32)) - } - if containerLen != 0 { - ft.DecMapStringStringL(*vp, containerLen, d) - } - } else if containerLen != 0 { - ft.DecMapStringStringL(rv2i(rv).(map[string]string), containerLen, d) - } - d.mapEnd() -} -func (fastpathDTSimpleIO) DecMapStringStringL(v map[string]string, containerLen int, d *decoderSimpleIO) { - if v == nil { - halt.errorInt("cannot decode into nil map[string]string given stream length: ", int64(containerLen)) - } - hasLen := containerLen >= 0 - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - mk := d.detach2Str(d.d.DecodeStringAsBytes()) - d.mapElemValue() - v[mk] = d.detach2Str(d.d.DecodeStringAsBytes()) - } -} -func (d *decoderSimpleIO) fastpathDecMapStringBytesR(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTSimpleIO - containerLen := d.mapStart(d.d.ReadMapStart()) - if rv.Kind() == reflect.Ptr { - vp, _ := rv2i(rv).(*map[string][]byte) - if *vp == nil { - *vp = make(map[string][]byte, decInferLen(containerLen, d.maxInitLen(), 40)) - } - if containerLen != 0 { - ft.DecMapStringBytesL(*vp, containerLen, d) - } - } else if containerLen != 0 { - ft.DecMapStringBytesL(rv2i(rv).(map[string][]byte), containerLen, d) - } - d.mapEnd() -} -func (fastpathDTSimpleIO) DecMapStringBytesL(v map[string][]byte, containerLen int, d *decoderSimpleIO) { - if v == nil { - halt.errorInt("cannot decode into nil map[string][]byte given stream length: ", int64(containerLen)) - } - var mv []byte - mapGet := !d.h.MapValueReset - hasLen := containerLen >= 0 - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - mk := d.detach2Str(d.d.DecodeStringAsBytes()) - d.mapElemValue() - if mapGet { - mv = v[mk] - } else { - mv = nil - } - v[mk], _ = d.decodeBytesInto(mv, false) - } -} -func (d *decoderSimpleIO) fastpathDecMapStringUint8R(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTSimpleIO - containerLen := d.mapStart(d.d.ReadMapStart()) - if rv.Kind() == reflect.Ptr { - vp, _ := rv2i(rv).(*map[string]uint8) - if *vp == nil { - *vp = make(map[string]uint8, decInferLen(containerLen, d.maxInitLen(), 17)) - } - if containerLen != 0 { - ft.DecMapStringUint8L(*vp, containerLen, d) - } - } else if containerLen != 0 { - ft.DecMapStringUint8L(rv2i(rv).(map[string]uint8), containerLen, d) - } - d.mapEnd() -} -func (fastpathDTSimpleIO) DecMapStringUint8L(v map[string]uint8, containerLen int, d *decoderSimpleIO) { - if v == nil { - halt.errorInt("cannot decode into nil map[string]uint8 given stream length: ", int64(containerLen)) - } - hasLen := containerLen >= 0 - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - mk := d.detach2Str(d.d.DecodeStringAsBytes()) - d.mapElemValue() - v[mk] = uint8(chkOvf.UintV(d.d.DecodeUint64(), 8)) - } -} -func (d *decoderSimpleIO) fastpathDecMapStringUint64R(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTSimpleIO - containerLen := d.mapStart(d.d.ReadMapStart()) - if rv.Kind() == reflect.Ptr { - vp, _ := rv2i(rv).(*map[string]uint64) - if *vp == nil { - *vp = make(map[string]uint64, decInferLen(containerLen, d.maxInitLen(), 24)) - } - if containerLen != 0 { - ft.DecMapStringUint64L(*vp, containerLen, d) - } - } else if containerLen != 0 { - ft.DecMapStringUint64L(rv2i(rv).(map[string]uint64), containerLen, d) - } - d.mapEnd() -} -func (fastpathDTSimpleIO) DecMapStringUint64L(v map[string]uint64, containerLen int, d *decoderSimpleIO) { - if v == nil { - halt.errorInt("cannot decode into nil map[string]uint64 given stream length: ", int64(containerLen)) - } - hasLen := containerLen >= 0 - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - mk := d.detach2Str(d.d.DecodeStringAsBytes()) - d.mapElemValue() - v[mk] = d.d.DecodeUint64() - } -} -func (d *decoderSimpleIO) fastpathDecMapStringIntR(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTSimpleIO - containerLen := d.mapStart(d.d.ReadMapStart()) - if rv.Kind() == reflect.Ptr { - vp, _ := rv2i(rv).(*map[string]int) - if *vp == nil { - *vp = make(map[string]int, decInferLen(containerLen, d.maxInitLen(), 24)) - } - if containerLen != 0 { - ft.DecMapStringIntL(*vp, containerLen, d) - } - } else if containerLen != 0 { - ft.DecMapStringIntL(rv2i(rv).(map[string]int), containerLen, d) - } - d.mapEnd() -} -func (fastpathDTSimpleIO) DecMapStringIntL(v map[string]int, containerLen int, d *decoderSimpleIO) { - if v == nil { - halt.errorInt("cannot decode into nil map[string]int given stream length: ", int64(containerLen)) - } - hasLen := containerLen >= 0 - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - mk := d.detach2Str(d.d.DecodeStringAsBytes()) - d.mapElemValue() - v[mk] = int(chkOvf.IntV(d.d.DecodeInt64(), intBitsize)) - } -} -func (d *decoderSimpleIO) fastpathDecMapStringInt32R(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTSimpleIO - containerLen := d.mapStart(d.d.ReadMapStart()) - if rv.Kind() == reflect.Ptr { - vp, _ := rv2i(rv).(*map[string]int32) - if *vp == nil { - *vp = make(map[string]int32, decInferLen(containerLen, d.maxInitLen(), 20)) - } - if containerLen != 0 { - ft.DecMapStringInt32L(*vp, containerLen, d) - } - } else if containerLen != 0 { - ft.DecMapStringInt32L(rv2i(rv).(map[string]int32), containerLen, d) - } - d.mapEnd() -} -func (fastpathDTSimpleIO) DecMapStringInt32L(v map[string]int32, containerLen int, d *decoderSimpleIO) { - if v == nil { - halt.errorInt("cannot decode into nil map[string]int32 given stream length: ", int64(containerLen)) - } - hasLen := containerLen >= 0 - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - mk := d.detach2Str(d.d.DecodeStringAsBytes()) - d.mapElemValue() - v[mk] = int32(chkOvf.IntV(d.d.DecodeInt64(), 32)) - } -} -func (d *decoderSimpleIO) fastpathDecMapStringFloat64R(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTSimpleIO - containerLen := d.mapStart(d.d.ReadMapStart()) - if rv.Kind() == reflect.Ptr { - vp, _ := rv2i(rv).(*map[string]float64) - if *vp == nil { - *vp = make(map[string]float64, decInferLen(containerLen, d.maxInitLen(), 24)) - } - if containerLen != 0 { - ft.DecMapStringFloat64L(*vp, containerLen, d) - } - } else if containerLen != 0 { - ft.DecMapStringFloat64L(rv2i(rv).(map[string]float64), containerLen, d) - } - d.mapEnd() -} -func (fastpathDTSimpleIO) DecMapStringFloat64L(v map[string]float64, containerLen int, d *decoderSimpleIO) { - if v == nil { - halt.errorInt("cannot decode into nil map[string]float64 given stream length: ", int64(containerLen)) - } - hasLen := containerLen >= 0 - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - mk := d.detach2Str(d.d.DecodeStringAsBytes()) - d.mapElemValue() - v[mk] = d.d.DecodeFloat64() - } -} -func (d *decoderSimpleIO) fastpathDecMapStringBoolR(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTSimpleIO - containerLen := d.mapStart(d.d.ReadMapStart()) - if rv.Kind() == reflect.Ptr { - vp, _ := rv2i(rv).(*map[string]bool) - if *vp == nil { - *vp = make(map[string]bool, decInferLen(containerLen, d.maxInitLen(), 17)) - } - if containerLen != 0 { - ft.DecMapStringBoolL(*vp, containerLen, d) - } - } else if containerLen != 0 { - ft.DecMapStringBoolL(rv2i(rv).(map[string]bool), containerLen, d) - } - d.mapEnd() -} -func (fastpathDTSimpleIO) DecMapStringBoolL(v map[string]bool, containerLen int, d *decoderSimpleIO) { - if v == nil { - halt.errorInt("cannot decode into nil map[string]bool given stream length: ", int64(containerLen)) - } - hasLen := containerLen >= 0 - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - mk := d.detach2Str(d.d.DecodeStringAsBytes()) - d.mapElemValue() - v[mk] = d.d.DecodeBool() - } -} -func (d *decoderSimpleIO) fastpathDecMapUint8IntfR(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTSimpleIO - containerLen := d.mapStart(d.d.ReadMapStart()) - if rv.Kind() == reflect.Ptr { - vp, _ := rv2i(rv).(*map[uint8]interface{}) - if *vp == nil { - *vp = make(map[uint8]interface{}, decInferLen(containerLen, d.maxInitLen(), 17)) - } - if containerLen != 0 { - ft.DecMapUint8IntfL(*vp, containerLen, d) - } - } else if containerLen != 0 { - ft.DecMapUint8IntfL(rv2i(rv).(map[uint8]interface{}), containerLen, d) - } - d.mapEnd() -} -func (fastpathDTSimpleIO) DecMapUint8IntfL(v map[uint8]interface{}, containerLen int, d *decoderSimpleIO) { - if v == nil { - halt.errorInt("cannot decode into nil map[uint8]interface{} given stream length: ", int64(containerLen)) - } - var mv interface{} - mapGet := !d.h.MapValueReset && !d.h.InterfaceReset - hasLen := containerLen >= 0 - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - mk := uint8(chkOvf.UintV(d.d.DecodeUint64(), 8)) - d.mapElemValue() - if mapGet { - mv = v[mk] - } else { - mv = nil - } - d.decode(&mv) - v[mk] = mv - } -} -func (d *decoderSimpleIO) fastpathDecMapUint8StringR(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTSimpleIO - containerLen := d.mapStart(d.d.ReadMapStart()) - if rv.Kind() == reflect.Ptr { - vp, _ := rv2i(rv).(*map[uint8]string) - if *vp == nil { - *vp = make(map[uint8]string, decInferLen(containerLen, d.maxInitLen(), 17)) - } - if containerLen != 0 { - ft.DecMapUint8StringL(*vp, containerLen, d) - } - } else if containerLen != 0 { - ft.DecMapUint8StringL(rv2i(rv).(map[uint8]string), containerLen, d) - } - d.mapEnd() -} -func (fastpathDTSimpleIO) DecMapUint8StringL(v map[uint8]string, containerLen int, d *decoderSimpleIO) { - if v == nil { - halt.errorInt("cannot decode into nil map[uint8]string given stream length: ", int64(containerLen)) - } - hasLen := containerLen >= 0 - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - mk := uint8(chkOvf.UintV(d.d.DecodeUint64(), 8)) - d.mapElemValue() - v[mk] = d.detach2Str(d.d.DecodeStringAsBytes()) - } -} -func (d *decoderSimpleIO) fastpathDecMapUint8BytesR(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTSimpleIO - containerLen := d.mapStart(d.d.ReadMapStart()) - if rv.Kind() == reflect.Ptr { - vp, _ := rv2i(rv).(*map[uint8][]byte) - if *vp == nil { - *vp = make(map[uint8][]byte, decInferLen(containerLen, d.maxInitLen(), 25)) - } - if containerLen != 0 { - ft.DecMapUint8BytesL(*vp, containerLen, d) - } - } else if containerLen != 0 { - ft.DecMapUint8BytesL(rv2i(rv).(map[uint8][]byte), containerLen, d) - } - d.mapEnd() -} -func (fastpathDTSimpleIO) DecMapUint8BytesL(v map[uint8][]byte, containerLen int, d *decoderSimpleIO) { - if v == nil { - halt.errorInt("cannot decode into nil map[uint8][]byte given stream length: ", int64(containerLen)) - } - var mv []byte - mapGet := !d.h.MapValueReset - hasLen := containerLen >= 0 - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - mk := uint8(chkOvf.UintV(d.d.DecodeUint64(), 8)) - d.mapElemValue() - if mapGet { - mv = v[mk] - } else { - mv = nil - } - v[mk], _ = d.decodeBytesInto(mv, false) - } -} -func (d *decoderSimpleIO) fastpathDecMapUint8Uint8R(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTSimpleIO - containerLen := d.mapStart(d.d.ReadMapStart()) - if rv.Kind() == reflect.Ptr { - vp, _ := rv2i(rv).(*map[uint8]uint8) - if *vp == nil { - *vp = make(map[uint8]uint8, decInferLen(containerLen, d.maxInitLen(), 2)) - } - if containerLen != 0 { - ft.DecMapUint8Uint8L(*vp, containerLen, d) - } - } else if containerLen != 0 { - ft.DecMapUint8Uint8L(rv2i(rv).(map[uint8]uint8), containerLen, d) - } - d.mapEnd() -} -func (fastpathDTSimpleIO) DecMapUint8Uint8L(v map[uint8]uint8, containerLen int, d *decoderSimpleIO) { - if v == nil { - halt.errorInt("cannot decode into nil map[uint8]uint8 given stream length: ", int64(containerLen)) - } - hasLen := containerLen >= 0 - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - mk := uint8(chkOvf.UintV(d.d.DecodeUint64(), 8)) - d.mapElemValue() - v[mk] = uint8(chkOvf.UintV(d.d.DecodeUint64(), 8)) - } -} -func (d *decoderSimpleIO) fastpathDecMapUint8Uint64R(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTSimpleIO - containerLen := d.mapStart(d.d.ReadMapStart()) - if rv.Kind() == reflect.Ptr { - vp, _ := rv2i(rv).(*map[uint8]uint64) - if *vp == nil { - *vp = make(map[uint8]uint64, decInferLen(containerLen, d.maxInitLen(), 9)) - } - if containerLen != 0 { - ft.DecMapUint8Uint64L(*vp, containerLen, d) - } - } else if containerLen != 0 { - ft.DecMapUint8Uint64L(rv2i(rv).(map[uint8]uint64), containerLen, d) - } - d.mapEnd() -} -func (fastpathDTSimpleIO) DecMapUint8Uint64L(v map[uint8]uint64, containerLen int, d *decoderSimpleIO) { - if v == nil { - halt.errorInt("cannot decode into nil map[uint8]uint64 given stream length: ", int64(containerLen)) - } - hasLen := containerLen >= 0 - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - mk := uint8(chkOvf.UintV(d.d.DecodeUint64(), 8)) - d.mapElemValue() - v[mk] = d.d.DecodeUint64() - } -} -func (d *decoderSimpleIO) fastpathDecMapUint8IntR(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTSimpleIO - containerLen := d.mapStart(d.d.ReadMapStart()) - if rv.Kind() == reflect.Ptr { - vp, _ := rv2i(rv).(*map[uint8]int) - if *vp == nil { - *vp = make(map[uint8]int, decInferLen(containerLen, d.maxInitLen(), 9)) - } - if containerLen != 0 { - ft.DecMapUint8IntL(*vp, containerLen, d) - } - } else if containerLen != 0 { - ft.DecMapUint8IntL(rv2i(rv).(map[uint8]int), containerLen, d) - } - d.mapEnd() -} -func (fastpathDTSimpleIO) DecMapUint8IntL(v map[uint8]int, containerLen int, d *decoderSimpleIO) { - if v == nil { - halt.errorInt("cannot decode into nil map[uint8]int given stream length: ", int64(containerLen)) - } - hasLen := containerLen >= 0 - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - mk := uint8(chkOvf.UintV(d.d.DecodeUint64(), 8)) - d.mapElemValue() - v[mk] = int(chkOvf.IntV(d.d.DecodeInt64(), intBitsize)) - } -} -func (d *decoderSimpleIO) fastpathDecMapUint8Int32R(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTSimpleIO - containerLen := d.mapStart(d.d.ReadMapStart()) - if rv.Kind() == reflect.Ptr { - vp, _ := rv2i(rv).(*map[uint8]int32) - if *vp == nil { - *vp = make(map[uint8]int32, decInferLen(containerLen, d.maxInitLen(), 5)) - } - if containerLen != 0 { - ft.DecMapUint8Int32L(*vp, containerLen, d) - } - } else if containerLen != 0 { - ft.DecMapUint8Int32L(rv2i(rv).(map[uint8]int32), containerLen, d) - } - d.mapEnd() -} -func (fastpathDTSimpleIO) DecMapUint8Int32L(v map[uint8]int32, containerLen int, d *decoderSimpleIO) { - if v == nil { - halt.errorInt("cannot decode into nil map[uint8]int32 given stream length: ", int64(containerLen)) - } - hasLen := containerLen >= 0 - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - mk := uint8(chkOvf.UintV(d.d.DecodeUint64(), 8)) - d.mapElemValue() - v[mk] = int32(chkOvf.IntV(d.d.DecodeInt64(), 32)) - } -} -func (d *decoderSimpleIO) fastpathDecMapUint8Float64R(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTSimpleIO - containerLen := d.mapStart(d.d.ReadMapStart()) - if rv.Kind() == reflect.Ptr { - vp, _ := rv2i(rv).(*map[uint8]float64) - if *vp == nil { - *vp = make(map[uint8]float64, decInferLen(containerLen, d.maxInitLen(), 9)) - } - if containerLen != 0 { - ft.DecMapUint8Float64L(*vp, containerLen, d) - } - } else if containerLen != 0 { - ft.DecMapUint8Float64L(rv2i(rv).(map[uint8]float64), containerLen, d) - } - d.mapEnd() -} -func (fastpathDTSimpleIO) DecMapUint8Float64L(v map[uint8]float64, containerLen int, d *decoderSimpleIO) { - if v == nil { - halt.errorInt("cannot decode into nil map[uint8]float64 given stream length: ", int64(containerLen)) - } - hasLen := containerLen >= 0 - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - mk := uint8(chkOvf.UintV(d.d.DecodeUint64(), 8)) - d.mapElemValue() - v[mk] = d.d.DecodeFloat64() - } -} -func (d *decoderSimpleIO) fastpathDecMapUint8BoolR(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTSimpleIO - containerLen := d.mapStart(d.d.ReadMapStart()) - if rv.Kind() == reflect.Ptr { - vp, _ := rv2i(rv).(*map[uint8]bool) - if *vp == nil { - *vp = make(map[uint8]bool, decInferLen(containerLen, d.maxInitLen(), 2)) - } - if containerLen != 0 { - ft.DecMapUint8BoolL(*vp, containerLen, d) - } - } else if containerLen != 0 { - ft.DecMapUint8BoolL(rv2i(rv).(map[uint8]bool), containerLen, d) - } - d.mapEnd() -} -func (fastpathDTSimpleIO) DecMapUint8BoolL(v map[uint8]bool, containerLen int, d *decoderSimpleIO) { - if v == nil { - halt.errorInt("cannot decode into nil map[uint8]bool given stream length: ", int64(containerLen)) - } - hasLen := containerLen >= 0 - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - mk := uint8(chkOvf.UintV(d.d.DecodeUint64(), 8)) - d.mapElemValue() - v[mk] = d.d.DecodeBool() - } -} -func (d *decoderSimpleIO) fastpathDecMapUint64IntfR(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTSimpleIO - containerLen := d.mapStart(d.d.ReadMapStart()) - if rv.Kind() == reflect.Ptr { - vp, _ := rv2i(rv).(*map[uint64]interface{}) - if *vp == nil { - *vp = make(map[uint64]interface{}, decInferLen(containerLen, d.maxInitLen(), 24)) - } - if containerLen != 0 { - ft.DecMapUint64IntfL(*vp, containerLen, d) - } - } else if containerLen != 0 { - ft.DecMapUint64IntfL(rv2i(rv).(map[uint64]interface{}), containerLen, d) - } - d.mapEnd() -} -func (fastpathDTSimpleIO) DecMapUint64IntfL(v map[uint64]interface{}, containerLen int, d *decoderSimpleIO) { - if v == nil { - halt.errorInt("cannot decode into nil map[uint64]interface{} given stream length: ", int64(containerLen)) - } - var mv interface{} - mapGet := !d.h.MapValueReset && !d.h.InterfaceReset - hasLen := containerLen >= 0 - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - mk := d.d.DecodeUint64() - d.mapElemValue() - if mapGet { - mv = v[mk] - } else { - mv = nil - } - d.decode(&mv) - v[mk] = mv - } -} -func (d *decoderSimpleIO) fastpathDecMapUint64StringR(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTSimpleIO - containerLen := d.mapStart(d.d.ReadMapStart()) - if rv.Kind() == reflect.Ptr { - vp, _ := rv2i(rv).(*map[uint64]string) - if *vp == nil { - *vp = make(map[uint64]string, decInferLen(containerLen, d.maxInitLen(), 24)) - } - if containerLen != 0 { - ft.DecMapUint64StringL(*vp, containerLen, d) - } - } else if containerLen != 0 { - ft.DecMapUint64StringL(rv2i(rv).(map[uint64]string), containerLen, d) - } - d.mapEnd() -} -func (fastpathDTSimpleIO) DecMapUint64StringL(v map[uint64]string, containerLen int, d *decoderSimpleIO) { - if v == nil { - halt.errorInt("cannot decode into nil map[uint64]string given stream length: ", int64(containerLen)) - } - hasLen := containerLen >= 0 - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - mk := d.d.DecodeUint64() - d.mapElemValue() - v[mk] = d.detach2Str(d.d.DecodeStringAsBytes()) - } -} -func (d *decoderSimpleIO) fastpathDecMapUint64BytesR(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTSimpleIO - containerLen := d.mapStart(d.d.ReadMapStart()) - if rv.Kind() == reflect.Ptr { - vp, _ := rv2i(rv).(*map[uint64][]byte) - if *vp == nil { - *vp = make(map[uint64][]byte, decInferLen(containerLen, d.maxInitLen(), 32)) - } - if containerLen != 0 { - ft.DecMapUint64BytesL(*vp, containerLen, d) - } - } else if containerLen != 0 { - ft.DecMapUint64BytesL(rv2i(rv).(map[uint64][]byte), containerLen, d) - } - d.mapEnd() -} -func (fastpathDTSimpleIO) DecMapUint64BytesL(v map[uint64][]byte, containerLen int, d *decoderSimpleIO) { - if v == nil { - halt.errorInt("cannot decode into nil map[uint64][]byte given stream length: ", int64(containerLen)) - } - var mv []byte - mapGet := !d.h.MapValueReset - hasLen := containerLen >= 0 - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - mk := d.d.DecodeUint64() - d.mapElemValue() - if mapGet { - mv = v[mk] - } else { - mv = nil - } - v[mk], _ = d.decodeBytesInto(mv, false) - } -} -func (d *decoderSimpleIO) fastpathDecMapUint64Uint8R(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTSimpleIO - containerLen := d.mapStart(d.d.ReadMapStart()) - if rv.Kind() == reflect.Ptr { - vp, _ := rv2i(rv).(*map[uint64]uint8) - if *vp == nil { - *vp = make(map[uint64]uint8, decInferLen(containerLen, d.maxInitLen(), 9)) - } - if containerLen != 0 { - ft.DecMapUint64Uint8L(*vp, containerLen, d) - } - } else if containerLen != 0 { - ft.DecMapUint64Uint8L(rv2i(rv).(map[uint64]uint8), containerLen, d) - } - d.mapEnd() -} -func (fastpathDTSimpleIO) DecMapUint64Uint8L(v map[uint64]uint8, containerLen int, d *decoderSimpleIO) { - if v == nil { - halt.errorInt("cannot decode into nil map[uint64]uint8 given stream length: ", int64(containerLen)) - } - hasLen := containerLen >= 0 - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - mk := d.d.DecodeUint64() - d.mapElemValue() - v[mk] = uint8(chkOvf.UintV(d.d.DecodeUint64(), 8)) - } -} -func (d *decoderSimpleIO) fastpathDecMapUint64Uint64R(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTSimpleIO - containerLen := d.mapStart(d.d.ReadMapStart()) - if rv.Kind() == reflect.Ptr { - vp, _ := rv2i(rv).(*map[uint64]uint64) - if *vp == nil { - *vp = make(map[uint64]uint64, decInferLen(containerLen, d.maxInitLen(), 16)) - } - if containerLen != 0 { - ft.DecMapUint64Uint64L(*vp, containerLen, d) - } - } else if containerLen != 0 { - ft.DecMapUint64Uint64L(rv2i(rv).(map[uint64]uint64), containerLen, d) - } - d.mapEnd() -} -func (fastpathDTSimpleIO) DecMapUint64Uint64L(v map[uint64]uint64, containerLen int, d *decoderSimpleIO) { - if v == nil { - halt.errorInt("cannot decode into nil map[uint64]uint64 given stream length: ", int64(containerLen)) - } - hasLen := containerLen >= 0 - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - mk := d.d.DecodeUint64() - d.mapElemValue() - v[mk] = d.d.DecodeUint64() - } -} -func (d *decoderSimpleIO) fastpathDecMapUint64IntR(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTSimpleIO - containerLen := d.mapStart(d.d.ReadMapStart()) - if rv.Kind() == reflect.Ptr { - vp, _ := rv2i(rv).(*map[uint64]int) - if *vp == nil { - *vp = make(map[uint64]int, decInferLen(containerLen, d.maxInitLen(), 16)) - } - if containerLen != 0 { - ft.DecMapUint64IntL(*vp, containerLen, d) - } - } else if containerLen != 0 { - ft.DecMapUint64IntL(rv2i(rv).(map[uint64]int), containerLen, d) - } - d.mapEnd() -} -func (fastpathDTSimpleIO) DecMapUint64IntL(v map[uint64]int, containerLen int, d *decoderSimpleIO) { - if v == nil { - halt.errorInt("cannot decode into nil map[uint64]int given stream length: ", int64(containerLen)) - } - hasLen := containerLen >= 0 - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - mk := d.d.DecodeUint64() - d.mapElemValue() - v[mk] = int(chkOvf.IntV(d.d.DecodeInt64(), intBitsize)) - } -} -func (d *decoderSimpleIO) fastpathDecMapUint64Int32R(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTSimpleIO - containerLen := d.mapStart(d.d.ReadMapStart()) - if rv.Kind() == reflect.Ptr { - vp, _ := rv2i(rv).(*map[uint64]int32) - if *vp == nil { - *vp = make(map[uint64]int32, decInferLen(containerLen, d.maxInitLen(), 12)) - } - if containerLen != 0 { - ft.DecMapUint64Int32L(*vp, containerLen, d) - } - } else if containerLen != 0 { - ft.DecMapUint64Int32L(rv2i(rv).(map[uint64]int32), containerLen, d) - } - d.mapEnd() -} -func (fastpathDTSimpleIO) DecMapUint64Int32L(v map[uint64]int32, containerLen int, d *decoderSimpleIO) { - if v == nil { - halt.errorInt("cannot decode into nil map[uint64]int32 given stream length: ", int64(containerLen)) - } - hasLen := containerLen >= 0 - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - mk := d.d.DecodeUint64() - d.mapElemValue() - v[mk] = int32(chkOvf.IntV(d.d.DecodeInt64(), 32)) - } -} -func (d *decoderSimpleIO) fastpathDecMapUint64Float64R(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTSimpleIO - containerLen := d.mapStart(d.d.ReadMapStart()) - if rv.Kind() == reflect.Ptr { - vp, _ := rv2i(rv).(*map[uint64]float64) - if *vp == nil { - *vp = make(map[uint64]float64, decInferLen(containerLen, d.maxInitLen(), 16)) - } - if containerLen != 0 { - ft.DecMapUint64Float64L(*vp, containerLen, d) - } - } else if containerLen != 0 { - ft.DecMapUint64Float64L(rv2i(rv).(map[uint64]float64), containerLen, d) - } - d.mapEnd() -} -func (fastpathDTSimpleIO) DecMapUint64Float64L(v map[uint64]float64, containerLen int, d *decoderSimpleIO) { - if v == nil { - halt.errorInt("cannot decode into nil map[uint64]float64 given stream length: ", int64(containerLen)) - } - hasLen := containerLen >= 0 - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - mk := d.d.DecodeUint64() - d.mapElemValue() - v[mk] = d.d.DecodeFloat64() - } -} -func (d *decoderSimpleIO) fastpathDecMapUint64BoolR(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTSimpleIO - containerLen := d.mapStart(d.d.ReadMapStart()) - if rv.Kind() == reflect.Ptr { - vp, _ := rv2i(rv).(*map[uint64]bool) - if *vp == nil { - *vp = make(map[uint64]bool, decInferLen(containerLen, d.maxInitLen(), 9)) - } - if containerLen != 0 { - ft.DecMapUint64BoolL(*vp, containerLen, d) - } - } else if containerLen != 0 { - ft.DecMapUint64BoolL(rv2i(rv).(map[uint64]bool), containerLen, d) - } - d.mapEnd() -} -func (fastpathDTSimpleIO) DecMapUint64BoolL(v map[uint64]bool, containerLen int, d *decoderSimpleIO) { - if v == nil { - halt.errorInt("cannot decode into nil map[uint64]bool given stream length: ", int64(containerLen)) - } - hasLen := containerLen >= 0 - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - mk := d.d.DecodeUint64() - d.mapElemValue() - v[mk] = d.d.DecodeBool() - } -} -func (d *decoderSimpleIO) fastpathDecMapIntIntfR(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTSimpleIO - containerLen := d.mapStart(d.d.ReadMapStart()) - if rv.Kind() == reflect.Ptr { - vp, _ := rv2i(rv).(*map[int]interface{}) - if *vp == nil { - *vp = make(map[int]interface{}, decInferLen(containerLen, d.maxInitLen(), 24)) - } - if containerLen != 0 { - ft.DecMapIntIntfL(*vp, containerLen, d) - } - } else if containerLen != 0 { - ft.DecMapIntIntfL(rv2i(rv).(map[int]interface{}), containerLen, d) - } - d.mapEnd() -} -func (fastpathDTSimpleIO) DecMapIntIntfL(v map[int]interface{}, containerLen int, d *decoderSimpleIO) { - if v == nil { - halt.errorInt("cannot decode into nil map[int]interface{} given stream length: ", int64(containerLen)) - } - var mv interface{} - mapGet := !d.h.MapValueReset && !d.h.InterfaceReset - hasLen := containerLen >= 0 - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - mk := int(chkOvf.IntV(d.d.DecodeInt64(), intBitsize)) - d.mapElemValue() - if mapGet { - mv = v[mk] - } else { - mv = nil - } - d.decode(&mv) - v[mk] = mv - } -} -func (d *decoderSimpleIO) fastpathDecMapIntStringR(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTSimpleIO - containerLen := d.mapStart(d.d.ReadMapStart()) - if rv.Kind() == reflect.Ptr { - vp, _ := rv2i(rv).(*map[int]string) - if *vp == nil { - *vp = make(map[int]string, decInferLen(containerLen, d.maxInitLen(), 24)) - } - if containerLen != 0 { - ft.DecMapIntStringL(*vp, containerLen, d) - } - } else if containerLen != 0 { - ft.DecMapIntStringL(rv2i(rv).(map[int]string), containerLen, d) - } - d.mapEnd() -} -func (fastpathDTSimpleIO) DecMapIntStringL(v map[int]string, containerLen int, d *decoderSimpleIO) { - if v == nil { - halt.errorInt("cannot decode into nil map[int]string given stream length: ", int64(containerLen)) - } - hasLen := containerLen >= 0 - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - mk := int(chkOvf.IntV(d.d.DecodeInt64(), intBitsize)) - d.mapElemValue() - v[mk] = d.detach2Str(d.d.DecodeStringAsBytes()) - } -} -func (d *decoderSimpleIO) fastpathDecMapIntBytesR(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTSimpleIO - containerLen := d.mapStart(d.d.ReadMapStart()) - if rv.Kind() == reflect.Ptr { - vp, _ := rv2i(rv).(*map[int][]byte) - if *vp == nil { - *vp = make(map[int][]byte, decInferLen(containerLen, d.maxInitLen(), 32)) - } - if containerLen != 0 { - ft.DecMapIntBytesL(*vp, containerLen, d) - } - } else if containerLen != 0 { - ft.DecMapIntBytesL(rv2i(rv).(map[int][]byte), containerLen, d) - } - d.mapEnd() -} -func (fastpathDTSimpleIO) DecMapIntBytesL(v map[int][]byte, containerLen int, d *decoderSimpleIO) { - if v == nil { - halt.errorInt("cannot decode into nil map[int][]byte given stream length: ", int64(containerLen)) - } - var mv []byte - mapGet := !d.h.MapValueReset - hasLen := containerLen >= 0 - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - mk := int(chkOvf.IntV(d.d.DecodeInt64(), intBitsize)) - d.mapElemValue() - if mapGet { - mv = v[mk] - } else { - mv = nil - } - v[mk], _ = d.decodeBytesInto(mv, false) - } -} -func (d *decoderSimpleIO) fastpathDecMapIntUint8R(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTSimpleIO - containerLen := d.mapStart(d.d.ReadMapStart()) - if rv.Kind() == reflect.Ptr { - vp, _ := rv2i(rv).(*map[int]uint8) - if *vp == nil { - *vp = make(map[int]uint8, decInferLen(containerLen, d.maxInitLen(), 9)) - } - if containerLen != 0 { - ft.DecMapIntUint8L(*vp, containerLen, d) - } - } else if containerLen != 0 { - ft.DecMapIntUint8L(rv2i(rv).(map[int]uint8), containerLen, d) - } - d.mapEnd() -} -func (fastpathDTSimpleIO) DecMapIntUint8L(v map[int]uint8, containerLen int, d *decoderSimpleIO) { - if v == nil { - halt.errorInt("cannot decode into nil map[int]uint8 given stream length: ", int64(containerLen)) - } - hasLen := containerLen >= 0 - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - mk := int(chkOvf.IntV(d.d.DecodeInt64(), intBitsize)) - d.mapElemValue() - v[mk] = uint8(chkOvf.UintV(d.d.DecodeUint64(), 8)) - } -} -func (d *decoderSimpleIO) fastpathDecMapIntUint64R(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTSimpleIO - containerLen := d.mapStart(d.d.ReadMapStart()) - if rv.Kind() == reflect.Ptr { - vp, _ := rv2i(rv).(*map[int]uint64) - if *vp == nil { - *vp = make(map[int]uint64, decInferLen(containerLen, d.maxInitLen(), 16)) - } - if containerLen != 0 { - ft.DecMapIntUint64L(*vp, containerLen, d) - } - } else if containerLen != 0 { - ft.DecMapIntUint64L(rv2i(rv).(map[int]uint64), containerLen, d) - } - d.mapEnd() -} -func (fastpathDTSimpleIO) DecMapIntUint64L(v map[int]uint64, containerLen int, d *decoderSimpleIO) { - if v == nil { - halt.errorInt("cannot decode into nil map[int]uint64 given stream length: ", int64(containerLen)) - } - hasLen := containerLen >= 0 - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - mk := int(chkOvf.IntV(d.d.DecodeInt64(), intBitsize)) - d.mapElemValue() - v[mk] = d.d.DecodeUint64() - } -} -func (d *decoderSimpleIO) fastpathDecMapIntIntR(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTSimpleIO - containerLen := d.mapStart(d.d.ReadMapStart()) - if rv.Kind() == reflect.Ptr { - vp, _ := rv2i(rv).(*map[int]int) - if *vp == nil { - *vp = make(map[int]int, decInferLen(containerLen, d.maxInitLen(), 16)) - } - if containerLen != 0 { - ft.DecMapIntIntL(*vp, containerLen, d) - } - } else if containerLen != 0 { - ft.DecMapIntIntL(rv2i(rv).(map[int]int), containerLen, d) - } - d.mapEnd() -} -func (fastpathDTSimpleIO) DecMapIntIntL(v map[int]int, containerLen int, d *decoderSimpleIO) { - if v == nil { - halt.errorInt("cannot decode into nil map[int]int given stream length: ", int64(containerLen)) - } - hasLen := containerLen >= 0 - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - mk := int(chkOvf.IntV(d.d.DecodeInt64(), intBitsize)) - d.mapElemValue() - v[mk] = int(chkOvf.IntV(d.d.DecodeInt64(), intBitsize)) - } -} -func (d *decoderSimpleIO) fastpathDecMapIntInt32R(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTSimpleIO - containerLen := d.mapStart(d.d.ReadMapStart()) - if rv.Kind() == reflect.Ptr { - vp, _ := rv2i(rv).(*map[int]int32) - if *vp == nil { - *vp = make(map[int]int32, decInferLen(containerLen, d.maxInitLen(), 12)) - } - if containerLen != 0 { - ft.DecMapIntInt32L(*vp, containerLen, d) - } - } else if containerLen != 0 { - ft.DecMapIntInt32L(rv2i(rv).(map[int]int32), containerLen, d) - } - d.mapEnd() -} -func (fastpathDTSimpleIO) DecMapIntInt32L(v map[int]int32, containerLen int, d *decoderSimpleIO) { - if v == nil { - halt.errorInt("cannot decode into nil map[int]int32 given stream length: ", int64(containerLen)) - } - hasLen := containerLen >= 0 - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - mk := int(chkOvf.IntV(d.d.DecodeInt64(), intBitsize)) - d.mapElemValue() - v[mk] = int32(chkOvf.IntV(d.d.DecodeInt64(), 32)) - } -} -func (d *decoderSimpleIO) fastpathDecMapIntFloat64R(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTSimpleIO - containerLen := d.mapStart(d.d.ReadMapStart()) - if rv.Kind() == reflect.Ptr { - vp, _ := rv2i(rv).(*map[int]float64) - if *vp == nil { - *vp = make(map[int]float64, decInferLen(containerLen, d.maxInitLen(), 16)) - } - if containerLen != 0 { - ft.DecMapIntFloat64L(*vp, containerLen, d) - } - } else if containerLen != 0 { - ft.DecMapIntFloat64L(rv2i(rv).(map[int]float64), containerLen, d) - } - d.mapEnd() -} -func (fastpathDTSimpleIO) DecMapIntFloat64L(v map[int]float64, containerLen int, d *decoderSimpleIO) { - if v == nil { - halt.errorInt("cannot decode into nil map[int]float64 given stream length: ", int64(containerLen)) - } - hasLen := containerLen >= 0 - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - mk := int(chkOvf.IntV(d.d.DecodeInt64(), intBitsize)) - d.mapElemValue() - v[mk] = d.d.DecodeFloat64() - } -} -func (d *decoderSimpleIO) fastpathDecMapIntBoolR(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTSimpleIO - containerLen := d.mapStart(d.d.ReadMapStart()) - if rv.Kind() == reflect.Ptr { - vp, _ := rv2i(rv).(*map[int]bool) - if *vp == nil { - *vp = make(map[int]bool, decInferLen(containerLen, d.maxInitLen(), 9)) - } - if containerLen != 0 { - ft.DecMapIntBoolL(*vp, containerLen, d) - } - } else if containerLen != 0 { - ft.DecMapIntBoolL(rv2i(rv).(map[int]bool), containerLen, d) - } - d.mapEnd() -} -func (fastpathDTSimpleIO) DecMapIntBoolL(v map[int]bool, containerLen int, d *decoderSimpleIO) { - if v == nil { - halt.errorInt("cannot decode into nil map[int]bool given stream length: ", int64(containerLen)) - } - hasLen := containerLen >= 0 - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - mk := int(chkOvf.IntV(d.d.DecodeInt64(), intBitsize)) - d.mapElemValue() - v[mk] = d.d.DecodeBool() - } -} -func (d *decoderSimpleIO) fastpathDecMapInt32IntfR(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTSimpleIO - containerLen := d.mapStart(d.d.ReadMapStart()) - if rv.Kind() == reflect.Ptr { - vp, _ := rv2i(rv).(*map[int32]interface{}) - if *vp == nil { - *vp = make(map[int32]interface{}, decInferLen(containerLen, d.maxInitLen(), 20)) - } - if containerLen != 0 { - ft.DecMapInt32IntfL(*vp, containerLen, d) - } - } else if containerLen != 0 { - ft.DecMapInt32IntfL(rv2i(rv).(map[int32]interface{}), containerLen, d) - } - d.mapEnd() -} -func (fastpathDTSimpleIO) DecMapInt32IntfL(v map[int32]interface{}, containerLen int, d *decoderSimpleIO) { - if v == nil { - halt.errorInt("cannot decode into nil map[int32]interface{} given stream length: ", int64(containerLen)) - } - var mv interface{} - mapGet := !d.h.MapValueReset && !d.h.InterfaceReset - hasLen := containerLen >= 0 - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - mk := int32(chkOvf.IntV(d.d.DecodeInt64(), 32)) - d.mapElemValue() - if mapGet { - mv = v[mk] - } else { - mv = nil - } - d.decode(&mv) - v[mk] = mv - } -} -func (d *decoderSimpleIO) fastpathDecMapInt32StringR(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTSimpleIO - containerLen := d.mapStart(d.d.ReadMapStart()) - if rv.Kind() == reflect.Ptr { - vp, _ := rv2i(rv).(*map[int32]string) - if *vp == nil { - *vp = make(map[int32]string, decInferLen(containerLen, d.maxInitLen(), 20)) - } - if containerLen != 0 { - ft.DecMapInt32StringL(*vp, containerLen, d) - } - } else if containerLen != 0 { - ft.DecMapInt32StringL(rv2i(rv).(map[int32]string), containerLen, d) - } - d.mapEnd() -} -func (fastpathDTSimpleIO) DecMapInt32StringL(v map[int32]string, containerLen int, d *decoderSimpleIO) { - if v == nil { - halt.errorInt("cannot decode into nil map[int32]string given stream length: ", int64(containerLen)) - } - hasLen := containerLen >= 0 - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - mk := int32(chkOvf.IntV(d.d.DecodeInt64(), 32)) - d.mapElemValue() - v[mk] = d.detach2Str(d.d.DecodeStringAsBytes()) - } -} -func (d *decoderSimpleIO) fastpathDecMapInt32BytesR(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTSimpleIO - containerLen := d.mapStart(d.d.ReadMapStart()) - if rv.Kind() == reflect.Ptr { - vp, _ := rv2i(rv).(*map[int32][]byte) - if *vp == nil { - *vp = make(map[int32][]byte, decInferLen(containerLen, d.maxInitLen(), 28)) - } - if containerLen != 0 { - ft.DecMapInt32BytesL(*vp, containerLen, d) - } - } else if containerLen != 0 { - ft.DecMapInt32BytesL(rv2i(rv).(map[int32][]byte), containerLen, d) - } - d.mapEnd() -} -func (fastpathDTSimpleIO) DecMapInt32BytesL(v map[int32][]byte, containerLen int, d *decoderSimpleIO) { - if v == nil { - halt.errorInt("cannot decode into nil map[int32][]byte given stream length: ", int64(containerLen)) - } - var mv []byte - mapGet := !d.h.MapValueReset - hasLen := containerLen >= 0 - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - mk := int32(chkOvf.IntV(d.d.DecodeInt64(), 32)) - d.mapElemValue() - if mapGet { - mv = v[mk] - } else { - mv = nil - } - v[mk], _ = d.decodeBytesInto(mv, false) - } -} -func (d *decoderSimpleIO) fastpathDecMapInt32Uint8R(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTSimpleIO - containerLen := d.mapStart(d.d.ReadMapStart()) - if rv.Kind() == reflect.Ptr { - vp, _ := rv2i(rv).(*map[int32]uint8) - if *vp == nil { - *vp = make(map[int32]uint8, decInferLen(containerLen, d.maxInitLen(), 5)) - } - if containerLen != 0 { - ft.DecMapInt32Uint8L(*vp, containerLen, d) - } - } else if containerLen != 0 { - ft.DecMapInt32Uint8L(rv2i(rv).(map[int32]uint8), containerLen, d) - } - d.mapEnd() -} -func (fastpathDTSimpleIO) DecMapInt32Uint8L(v map[int32]uint8, containerLen int, d *decoderSimpleIO) { - if v == nil { - halt.errorInt("cannot decode into nil map[int32]uint8 given stream length: ", int64(containerLen)) - } - hasLen := containerLen >= 0 - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - mk := int32(chkOvf.IntV(d.d.DecodeInt64(), 32)) - d.mapElemValue() - v[mk] = uint8(chkOvf.UintV(d.d.DecodeUint64(), 8)) - } -} -func (d *decoderSimpleIO) fastpathDecMapInt32Uint64R(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTSimpleIO - containerLen := d.mapStart(d.d.ReadMapStart()) - if rv.Kind() == reflect.Ptr { - vp, _ := rv2i(rv).(*map[int32]uint64) - if *vp == nil { - *vp = make(map[int32]uint64, decInferLen(containerLen, d.maxInitLen(), 12)) - } - if containerLen != 0 { - ft.DecMapInt32Uint64L(*vp, containerLen, d) - } - } else if containerLen != 0 { - ft.DecMapInt32Uint64L(rv2i(rv).(map[int32]uint64), containerLen, d) - } - d.mapEnd() -} -func (fastpathDTSimpleIO) DecMapInt32Uint64L(v map[int32]uint64, containerLen int, d *decoderSimpleIO) { - if v == nil { - halt.errorInt("cannot decode into nil map[int32]uint64 given stream length: ", int64(containerLen)) - } - hasLen := containerLen >= 0 - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - mk := int32(chkOvf.IntV(d.d.DecodeInt64(), 32)) - d.mapElemValue() - v[mk] = d.d.DecodeUint64() - } -} -func (d *decoderSimpleIO) fastpathDecMapInt32IntR(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTSimpleIO - containerLen := d.mapStart(d.d.ReadMapStart()) - if rv.Kind() == reflect.Ptr { - vp, _ := rv2i(rv).(*map[int32]int) - if *vp == nil { - *vp = make(map[int32]int, decInferLen(containerLen, d.maxInitLen(), 12)) - } - if containerLen != 0 { - ft.DecMapInt32IntL(*vp, containerLen, d) - } - } else if containerLen != 0 { - ft.DecMapInt32IntL(rv2i(rv).(map[int32]int), containerLen, d) - } - d.mapEnd() -} -func (fastpathDTSimpleIO) DecMapInt32IntL(v map[int32]int, containerLen int, d *decoderSimpleIO) { - if v == nil { - halt.errorInt("cannot decode into nil map[int32]int given stream length: ", int64(containerLen)) - } - hasLen := containerLen >= 0 - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - mk := int32(chkOvf.IntV(d.d.DecodeInt64(), 32)) - d.mapElemValue() - v[mk] = int(chkOvf.IntV(d.d.DecodeInt64(), intBitsize)) - } -} -func (d *decoderSimpleIO) fastpathDecMapInt32Int32R(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTSimpleIO - containerLen := d.mapStart(d.d.ReadMapStart()) - if rv.Kind() == reflect.Ptr { - vp, _ := rv2i(rv).(*map[int32]int32) - if *vp == nil { - *vp = make(map[int32]int32, decInferLen(containerLen, d.maxInitLen(), 8)) - } - if containerLen != 0 { - ft.DecMapInt32Int32L(*vp, containerLen, d) - } - } else if containerLen != 0 { - ft.DecMapInt32Int32L(rv2i(rv).(map[int32]int32), containerLen, d) - } - d.mapEnd() -} -func (fastpathDTSimpleIO) DecMapInt32Int32L(v map[int32]int32, containerLen int, d *decoderSimpleIO) { - if v == nil { - halt.errorInt("cannot decode into nil map[int32]int32 given stream length: ", int64(containerLen)) - } - hasLen := containerLen >= 0 - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - mk := int32(chkOvf.IntV(d.d.DecodeInt64(), 32)) - d.mapElemValue() - v[mk] = int32(chkOvf.IntV(d.d.DecodeInt64(), 32)) - } -} -func (d *decoderSimpleIO) fastpathDecMapInt32Float64R(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTSimpleIO - containerLen := d.mapStart(d.d.ReadMapStart()) - if rv.Kind() == reflect.Ptr { - vp, _ := rv2i(rv).(*map[int32]float64) - if *vp == nil { - *vp = make(map[int32]float64, decInferLen(containerLen, d.maxInitLen(), 12)) - } - if containerLen != 0 { - ft.DecMapInt32Float64L(*vp, containerLen, d) - } - } else if containerLen != 0 { - ft.DecMapInt32Float64L(rv2i(rv).(map[int32]float64), containerLen, d) - } - d.mapEnd() -} -func (fastpathDTSimpleIO) DecMapInt32Float64L(v map[int32]float64, containerLen int, d *decoderSimpleIO) { - if v == nil { - halt.errorInt("cannot decode into nil map[int32]float64 given stream length: ", int64(containerLen)) - } - hasLen := containerLen >= 0 - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - mk := int32(chkOvf.IntV(d.d.DecodeInt64(), 32)) - d.mapElemValue() - v[mk] = d.d.DecodeFloat64() - } -} -func (d *decoderSimpleIO) fastpathDecMapInt32BoolR(f *decFnInfo, rv reflect.Value) { - var ft fastpathDTSimpleIO - containerLen := d.mapStart(d.d.ReadMapStart()) - if rv.Kind() == reflect.Ptr { - vp, _ := rv2i(rv).(*map[int32]bool) - if *vp == nil { - *vp = make(map[int32]bool, decInferLen(containerLen, d.maxInitLen(), 5)) - } - if containerLen != 0 { - ft.DecMapInt32BoolL(*vp, containerLen, d) - } - } else if containerLen != 0 { - ft.DecMapInt32BoolL(rv2i(rv).(map[int32]bool), containerLen, d) - } - d.mapEnd() -} -func (fastpathDTSimpleIO) DecMapInt32BoolL(v map[int32]bool, containerLen int, d *decoderSimpleIO) { - if v == nil { - halt.errorInt("cannot decode into nil map[int32]bool given stream length: ", int64(containerLen)) - } - hasLen := containerLen >= 0 - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - mk := int32(chkOvf.IntV(d.d.DecodeInt64(), 32)) - d.mapElemValue() - v[mk] = d.d.DecodeBool() - } -} diff --git a/vendor/github.com/ugorji/go/codec/simple.go b/vendor/github.com/ugorji/go/codec/simple.go deleted file mode 100644 index 64df60f3c..000000000 --- a/vendor/github.com/ugorji/go/codec/simple.go +++ /dev/null @@ -1,749 +0,0 @@ -//go:build notmono || codec.notmono - -// Copyright (c) 2012-2020 Ugorji Nwoke. All rights reserved. -// Use of this source code is governed by a MIT license found in the LICENSE file. - -package codec - -import ( - "io" - "math" - "reflect" - "time" -) - -type simpleEncDriver[T encWriter] struct { - noBuiltInTypes - encDriverNoopContainerWriter - encDriverNoState - encDriverContainerNoTrackerT - encInit2er - - h *SimpleHandle - e *encoderBase - // b [8]byte - w T -} - -func (e *simpleEncDriver[T]) EncodeNil() { - e.w.writen1(simpleVdNil) -} - -func (e *simpleEncDriver[T]) EncodeBool(b bool) { - if e.h.EncZeroValuesAsNil && e.e.c != containerMapKey && !b { - e.EncodeNil() - return - } - if b { - e.w.writen1(simpleVdTrue) - } else { - e.w.writen1(simpleVdFalse) - } -} - -func (e *simpleEncDriver[T]) EncodeFloat32(f float32) { - if e.h.EncZeroValuesAsNil && e.e.c != containerMapKey && f == 0.0 { - e.EncodeNil() - return - } - e.w.writen1(simpleVdFloat32) - e.w.writen4(bigen.PutUint32(math.Float32bits(f))) -} - -func (e *simpleEncDriver[T]) EncodeFloat64(f float64) { - if e.h.EncZeroValuesAsNil && e.e.c != containerMapKey && f == 0.0 { - e.EncodeNil() - return - } - e.w.writen1(simpleVdFloat64) - e.w.writen8(bigen.PutUint64(math.Float64bits(f))) -} - -func (e *simpleEncDriver[T]) EncodeInt(v int64) { - if v < 0 { - e.encUint(uint64(-v), simpleVdNegInt) - } else { - e.encUint(uint64(v), simpleVdPosInt) - } -} - -func (e *simpleEncDriver[T]) EncodeUint(v uint64) { - e.encUint(v, simpleVdPosInt) -} - -func (e *simpleEncDriver[T]) encUint(v uint64, bd uint8) { - if e.h.EncZeroValuesAsNil && e.e.c != containerMapKey && v == 0 { - e.EncodeNil() - return - } - if v <= math.MaxUint8 { - e.w.writen2(bd, uint8(v)) - } else if v <= math.MaxUint16 { - e.w.writen1(bd + 1) - e.w.writen2(bigen.PutUint16(uint16(v))) - } else if v <= math.MaxUint32 { - e.w.writen1(bd + 2) - e.w.writen4(bigen.PutUint32(uint32(v))) - } else { // if v <= math.MaxUint64 { - e.w.writen1(bd + 3) - e.w.writen8(bigen.PutUint64(v)) - } -} - -func (e *simpleEncDriver[T]) encLen(bd byte, length int) { - if length == 0 { - e.w.writen1(bd) - } else if length <= math.MaxUint8 { - e.w.writen1(bd + 1) - e.w.writen1(uint8(length)) - } else if length <= math.MaxUint16 { - e.w.writen1(bd + 2) - e.w.writen2(bigen.PutUint16(uint16(length))) - } else if int64(length) <= math.MaxUint32 { - e.w.writen1(bd + 3) - e.w.writen4(bigen.PutUint32(uint32(length))) - } else { - e.w.writen1(bd + 4) - e.w.writen8(bigen.PutUint64(uint64(length))) - } -} - -func (e *simpleEncDriver[T]) EncodeExt(v interface{}, basetype reflect.Type, xtag uint64, ext Ext) { - var bs0, bs []byte - if ext == SelfExt { - bs0 = e.e.blist.get(1024) - bs = bs0 - sideEncode(e.h, &e.h.sideEncPool, func(se encoderI) { oneOffEncode(se, v, &bs, basetype, true) }) - } else { - bs = ext.WriteExt(v) - } - if bs == nil { - e.writeNilBytes() - goto END - } - e.encodeExtPreamble(uint8(xtag), len(bs)) - e.w.writeb(bs) -END: - if ext == SelfExt { - e.e.blist.put(bs) - if !byteSliceSameData(bs0, bs) { - e.e.blist.put(bs0) - } - } -} - -func (e *simpleEncDriver[T]) EncodeRawExt(re *RawExt) { - e.encodeExtPreamble(uint8(re.Tag), len(re.Data)) - e.w.writeb(re.Data) -} - -func (e *simpleEncDriver[T]) encodeExtPreamble(xtag byte, length int) { - e.encLen(simpleVdExt, length) - e.w.writen1(xtag) -} - -func (e *simpleEncDriver[T]) WriteArrayStart(length int) { - e.encLen(simpleVdArray, length) -} - -func (e *simpleEncDriver[T]) WriteMapStart(length int) { - e.encLen(simpleVdMap, length) -} - -func (e *simpleEncDriver[T]) WriteArrayEmpty() { - // e.WriteArrayStart(0) = e.encLen(simpleVdArray, 0) - e.w.writen1(simpleVdArray) -} - -func (e *simpleEncDriver[T]) WriteMapEmpty() { - // e.WriteMapStart(0) = e.encLen(simpleVdMap, 0) - e.w.writen1(simpleVdMap) -} - -func (e *simpleEncDriver[T]) EncodeString(v string) { - if e.h.EncZeroValuesAsNil && e.e.c != containerMapKey && v == "" { - e.EncodeNil() - return - } - if e.h.StringToRaw { - e.encLen(simpleVdByteArray, len(v)) - } else { - e.encLen(simpleVdString, len(v)) - } - e.w.writestr(v) -} - -func (e *simpleEncDriver[T]) EncodeStringNoEscape4Json(v string) { e.EncodeString(v) } - -func (e *simpleEncDriver[T]) EncodeStringBytesRaw(v []byte) { - // if e.h.EncZeroValuesAsNil && e.c != containerMapKey && v == nil { - e.encLen(simpleVdByteArray, len(v)) - e.w.writeb(v) -} - -func (e *simpleEncDriver[T]) EncodeBytes(v []byte) { - if v == nil { - e.writeNilBytes() - return - } - e.EncodeStringBytesRaw(v) -} - -func (e *simpleEncDriver[T]) encodeNilBytes() { - b := byte(simpleVdNil) - if e.h.NilCollectionToZeroLength { - b = simpleVdArray - } - e.w.writen1(b) -} - -func (e *simpleEncDriver[T]) writeNilOr(v byte) { - if !e.h.NilCollectionToZeroLength { - v = simpleVdNil - } - e.w.writen1(v) -} - -func (e *simpleEncDriver[T]) writeNilArray() { - e.writeNilOr(simpleVdArray) -} - -func (e *simpleEncDriver[T]) writeNilMap() { - e.writeNilOr(simpleVdMap) -} - -func (e *simpleEncDriver[T]) writeNilBytes() { - e.writeNilOr(simpleVdByteArray) -} - -func (e *simpleEncDriver[T]) EncodeTime(t time.Time) { - // if e.h.EncZeroValuesAsNil && e.c != containerMapKey && t.IsZero() { - if t.IsZero() { - e.EncodeNil() - return - } - v, err := t.MarshalBinary() - halt.onerror(err) - e.w.writen2(simpleVdTime, uint8(len(v))) - e.w.writeb(v) -} - -//------------------------------------ - -type simpleDecDriver[T decReader] struct { - h *SimpleHandle - d *decoderBase - r T - - bdAndBdread - // bytes bool - - noBuiltInTypes - // decDriverNoopNumberHelper - decDriverNoopContainerReader - decInit2er - - // ds interface{} // must be *decoder[simpleDecDriverM[bytes...]] -} - -func (d *simpleDecDriver[T]) readNextBd() { - d.bd = d.r.readn1() - d.bdRead = true -} - -func (d *simpleDecDriver[T]) advanceNil() (null bool) { - if !d.bdRead { - d.readNextBd() - } - if d.bd == simpleVdNil { - d.bdRead = false - return true // null = true - } - return -} - -func (d *simpleDecDriver[T]) ContainerType() (vt valueType) { - if !d.bdRead { - d.readNextBd() - } - switch d.bd { - case simpleVdNil: - d.bdRead = false - return valueTypeNil - case simpleVdByteArray, simpleVdByteArray + 1, - simpleVdByteArray + 2, simpleVdByteArray + 3, simpleVdByteArray + 4: - return valueTypeBytes - case simpleVdString, simpleVdString + 1, - simpleVdString + 2, simpleVdString + 3, simpleVdString + 4: - return valueTypeString - case simpleVdArray, simpleVdArray + 1, - simpleVdArray + 2, simpleVdArray + 3, simpleVdArray + 4: - return valueTypeArray - case simpleVdMap, simpleVdMap + 1, - simpleVdMap + 2, simpleVdMap + 3, simpleVdMap + 4: - return valueTypeMap - } - return valueTypeUnset -} - -func (d *simpleDecDriver[T]) TryNil() bool { - return d.advanceNil() -} - -func (d *simpleDecDriver[T]) decFloat() (f float64, ok bool) { - ok = true - switch d.bd { - case simpleVdFloat32: - f = float64(math.Float32frombits(bigen.Uint32(d.r.readn4()))) - case simpleVdFloat64: - f = math.Float64frombits(bigen.Uint64(d.r.readn8())) - default: - ok = false - } - return -} - -func (d *simpleDecDriver[T]) decInteger() (ui uint64, neg, ok bool) { - ok = true - switch d.bd { - case simpleVdPosInt: - ui = uint64(d.r.readn1()) - case simpleVdPosInt + 1: - ui = uint64(bigen.Uint16(d.r.readn2())) - case simpleVdPosInt + 2: - ui = uint64(bigen.Uint32(d.r.readn4())) - case simpleVdPosInt + 3: - ui = uint64(bigen.Uint64(d.r.readn8())) - case simpleVdNegInt: - ui = uint64(d.r.readn1()) - neg = true - case simpleVdNegInt + 1: - ui = uint64(bigen.Uint16(d.r.readn2())) - neg = true - case simpleVdNegInt + 2: - ui = uint64(bigen.Uint32(d.r.readn4())) - neg = true - case simpleVdNegInt + 3: - ui = uint64(bigen.Uint64(d.r.readn8())) - neg = true - default: - ok = false - // halt.errorf("integer only valid from pos/neg integer1..8. Invalid descriptor: %v", d.bd) - } - // DO NOT do this check below, because callers may only want the unsigned value: - // - // if ui > math.MaxInt64 { - // halt.errorf("decIntAny: Integer out of range for signed int64: %v", ui) - // return - // } - return -} - -func (d *simpleDecDriver[T]) DecodeInt64() (i int64) { - if d.advanceNil() { - return - } - v1, v2, v3 := d.decInteger() - i = decNegintPosintFloatNumberHelper{d}.int64(v1, v2, v3, false) - d.bdRead = false - return -} - -func (d *simpleDecDriver[T]) DecodeUint64() (ui uint64) { - if d.advanceNil() { - return - } - ui = decNegintPosintFloatNumberHelper{d}.uint64(d.decInteger()) - d.bdRead = false - return -} - -func (d *simpleDecDriver[T]) DecodeFloat64() (f float64) { - if d.advanceNil() { - return - } - v1, v2 := d.decFloat() - f = decNegintPosintFloatNumberHelper{d}.float64(v1, v2, false) - d.bdRead = false - return -} - -// bool can be decoded from bool only (single byte). -func (d *simpleDecDriver[T]) DecodeBool() (b bool) { - if d.advanceNil() { - return - } - if d.bd == simpleVdFalse { - } else if d.bd == simpleVdTrue { - b = true - } else { - halt.errorf("cannot decode bool - %s: %x", msgBadDesc, d.bd) - } - d.bdRead = false - return -} - -func (d *simpleDecDriver[T]) ReadMapStart() (length int) { - if d.advanceNil() { - return containerLenNil - } - d.bdRead = false - return d.decLen() -} - -func (d *simpleDecDriver[T]) ReadArrayStart() (length int) { - if d.advanceNil() { - return containerLenNil - } - d.bdRead = false - return d.decLen() -} - -func (d *simpleDecDriver[T]) uint2Len(ui uint64) int { - if chkOvf.Uint(ui, intBitsize) { - halt.errorf("overflow integer: %v", ui) - } - return int(ui) -} - -func (d *simpleDecDriver[T]) decLen() int { - switch d.bd & 7 { // d.bd % 8 { - case 0: - return 0 - case 1: - return int(d.r.readn1()) - case 2: - return int(bigen.Uint16(d.r.readn2())) - case 3: - return d.uint2Len(uint64(bigen.Uint32(d.r.readn4()))) - case 4: - return d.uint2Len(bigen.Uint64(d.r.readn8())) - } - halt.errorf("cannot read length: bd%%8 must be in range 0..4. Got: %d", d.bd%8) - return -1 -} - -func (d *simpleDecDriver[T]) DecodeStringAsBytes() ([]byte, dBytesAttachState) { - return d.DecodeBytes() -} - -func (d *simpleDecDriver[T]) DecodeBytes() (bs []byte, state dBytesAttachState) { - if d.advanceNil() { - return - } - var cond bool - // check if an "array" of uint8's (see ContainerType for how to infer if an array) - if d.bd >= simpleVdArray && d.bd <= simpleVdArray+4 { - slen := d.ReadArrayStart() - bs, cond = usableByteSlice(d.d.buf, slen) - for i := 0; i < len(bs); i++ { - bs[i] = uint8(chkOvf.UintV(d.DecodeUint64(), 8)) - } - for i := len(bs); i < slen; i++ { - bs = append(bs, uint8(chkOvf.UintV(d.DecodeUint64(), 8))) - } - if cond { - d.d.buf = bs - } - state = dBytesAttachBuffer - - return - } - - clen := d.decLen() - d.bdRead = false - bs, cond = d.r.readxb(uint(clen)) - state = d.d.attachState(cond) - return -} - -func (d *simpleDecDriver[T]) DecodeTime() (t time.Time) { - if d.advanceNil() { - return - } - if d.bd != simpleVdTime { - halt.errorf("invalid descriptor for time.Time - expect 0x%x, received 0x%x", simpleVdTime, d.bd) - } - d.bdRead = false - clen := uint(d.r.readn1()) - b := d.r.readx(clen) - halt.onerror((&t).UnmarshalBinary(b)) - return -} - -func (d *simpleDecDriver[T]) DecodeExt(rv interface{}, basetype reflect.Type, xtag uint64, ext Ext) { - xbs, _, _, ok := d.decodeExtV(ext != nil, xtag) - if !ok { - return - } - if ext == SelfExt { - sideDecode(d.h, &d.h.sideDecPool, func(sd decoderI) { oneOffDecode(sd, rv, xbs, basetype, true) }) - } else { - ext.ReadExt(rv, xbs) - } -} - -func (d *simpleDecDriver[T]) DecodeRawExt(re *RawExt) { - xbs, realxtag, state, ok := d.decodeExtV(false, 0) - if !ok { - return - } - re.Tag = uint64(realxtag) - re.setData(xbs, state >= dBytesAttachViewZerocopy) -} - -func (d *simpleDecDriver[T]) decodeExtV(verifyTag bool, xtagIn uint64) (xbs []byte, xtag byte, bstate dBytesAttachState, ok bool) { - if xtagIn > 0xff { - halt.errorf("ext: tag must be <= 0xff; got: %v", xtagIn) - } - if d.advanceNil() { - return - } - tag := uint8(xtagIn) - switch d.bd { - case simpleVdExt, simpleVdExt + 1, simpleVdExt + 2, simpleVdExt + 3, simpleVdExt + 4: - l := d.decLen() - xtag = d.r.readn1() - if verifyTag && xtag != tag { - halt.errorf("wrong extension tag. Got %b. Expecting: %v", xtag, tag) - } - xbs, ok = d.r.readxb(uint(l)) - bstate = d.d.attachState(ok) - case simpleVdByteArray, simpleVdByteArray + 1, - simpleVdByteArray + 2, simpleVdByteArray + 3, simpleVdByteArray + 4: - xbs, bstate = d.DecodeBytes() - default: - halt.errorf("ext - %s - expecting extensions/bytearray, got: 0x%x", msgBadDesc, d.bd) - } - d.bdRead = false - ok = true - return -} - -func (d *simpleDecDriver[T]) DecodeNaked() { - if !d.bdRead { - d.readNextBd() - } - - n := d.d.naked() - var decodeFurther bool - - switch d.bd { - case simpleVdNil: - n.v = valueTypeNil - case simpleVdFalse: - n.v = valueTypeBool - n.b = false - case simpleVdTrue: - n.v = valueTypeBool - n.b = true - case simpleVdPosInt, simpleVdPosInt + 1, simpleVdPosInt + 2, simpleVdPosInt + 3: - if d.h.SignedInteger { - n.v = valueTypeInt - n.i = d.DecodeInt64() - } else { - n.v = valueTypeUint - n.u = d.DecodeUint64() - } - case simpleVdNegInt, simpleVdNegInt + 1, simpleVdNegInt + 2, simpleVdNegInt + 3: - n.v = valueTypeInt - n.i = d.DecodeInt64() - case simpleVdFloat32: - n.v = valueTypeFloat - n.f = d.DecodeFloat64() - case simpleVdFloat64: - n.v = valueTypeFloat - n.f = d.DecodeFloat64() - case simpleVdTime: - n.v = valueTypeTime - n.t = d.DecodeTime() - case simpleVdString, simpleVdString + 1, - simpleVdString + 2, simpleVdString + 3, simpleVdString + 4: - n.v = valueTypeString - n.s = d.d.detach2Str(d.DecodeStringAsBytes()) - case simpleVdByteArray, simpleVdByteArray + 1, - simpleVdByteArray + 2, simpleVdByteArray + 3, simpleVdByteArray + 4: - d.d.fauxUnionReadRawBytes(d, false, d.h.RawToString) //, d.h.ZeroCopy) - case simpleVdExt, simpleVdExt + 1, simpleVdExt + 2, simpleVdExt + 3, simpleVdExt + 4: - n.v = valueTypeExt - l := d.decLen() - n.u = uint64(d.r.readn1()) - n.l = d.r.readx(uint(l)) - // MARKER: not necessary to detach for extensions - // var useBuf bool - // n.l, useBuf = d.r.readxb(uint(l)) - // n.a = d.d.attachState(useBuf) - // n.l = d.d.detach2Bytes(n.l, nil, n.a) - case simpleVdArray, simpleVdArray + 1, simpleVdArray + 2, - simpleVdArray + 3, simpleVdArray + 4: - n.v = valueTypeArray - decodeFurther = true - case simpleVdMap, simpleVdMap + 1, simpleVdMap + 2, simpleVdMap + 3, simpleVdMap + 4: - n.v = valueTypeMap - decodeFurther = true - default: - halt.errorf("cannot infer value - %s 0x%x", msgBadDesc, d.bd) - } - - if !decodeFurther { - d.bdRead = false - } -} - -func (d *simpleDecDriver[T]) nextValueBytes() (v []byte) { - if !d.bdRead { - d.readNextBd() - } - d.r.startRecording() - d.nextValueBytesBdReadR() - v = d.r.stopRecording() - d.bdRead = false - return -} - -func (d *simpleDecDriver[T]) nextValueBytesBdReadR() { - c := d.bd - - var length uint - - switch c { - case simpleVdNil, simpleVdFalse, simpleVdTrue, simpleVdString, simpleVdByteArray: - // pass - case simpleVdPosInt, simpleVdNegInt: - d.r.readn1() - case simpleVdPosInt + 1, simpleVdNegInt + 1: - d.r.skip(2) - case simpleVdPosInt + 2, simpleVdNegInt + 2, simpleVdFloat32: - d.r.skip(4) - case simpleVdPosInt + 3, simpleVdNegInt + 3, simpleVdFloat64: - d.r.skip(8) - case simpleVdTime: - c = d.r.readn1() - d.r.skip(uint(c)) - - default: - switch c & 7 { // c % 8 { - case 0: - length = 0 - case 1: - b := d.r.readn1() - length = uint(b) - case 2: - x := d.r.readn2() - length = uint(bigen.Uint16(x)) - case 3: - x := d.r.readn4() - length = uint(bigen.Uint32(x)) - case 4: - x := d.r.readn8() - length = uint(bigen.Uint64(x)) - } - - bExt := c >= simpleVdExt && c <= simpleVdExt+7 - bStr := c >= simpleVdString && c <= simpleVdString+7 - bByteArray := c >= simpleVdByteArray && c <= simpleVdByteArray+7 - bArray := c >= simpleVdArray && c <= simpleVdArray+7 - bMap := c >= simpleVdMap && c <= simpleVdMap+7 - - if !(bExt || bStr || bByteArray || bArray || bMap) { - halt.errorf("cannot infer value - %s 0x%x", msgBadDesc, c) - } - - if bExt { - d.r.readn1() // tag - } - - if length == 0 { - break - } - - if bArray { - for i := uint(0); i < length; i++ { - d.readNextBd() - d.nextValueBytesBdReadR() - } - } else if bMap { - for i := uint(0); i < length; i++ { - d.readNextBd() - d.nextValueBytesBdReadR() - d.readNextBd() - d.nextValueBytesBdReadR() - } - } else { - d.r.skip(length) - } - } - return -} - -// ---- -// -// The following below are similar across all format files (except for the format name). -// -// We keep them together here, so that we can easily copy and compare. - -// ---- - -func (d *simpleEncDriver[T]) init(hh Handle, shared *encoderBase, enc encoderI) (fp interface{}) { - callMake(&d.w) - d.h = hh.(*SimpleHandle) - d.e = shared - if shared.bytes { - fp = simpleFpEncBytes - } else { - fp = simpleFpEncIO - } - // d.w.init() - d.init2(enc) - return -} - -func (e *simpleEncDriver[T]) writeBytesAsis(b []byte) { e.w.writeb(b) } - -func (e *simpleEncDriver[T]) writerEnd() { e.w.end() } - -func (e *simpleEncDriver[T]) resetOutBytes(out *[]byte) { - e.w.resetBytes(*out, out) -} - -func (e *simpleEncDriver[T]) resetOutIO(out io.Writer) { - e.w.resetIO(out, e.h.WriterBufferSize, &e.e.blist) -} - -// ---- - -func (d *simpleDecDriver[T]) init(hh Handle, shared *decoderBase, dec decoderI) (fp interface{}) { - callMake(&d.r) - d.h = hh.(*SimpleHandle) - d.d = shared - if shared.bytes { - fp = simpleFpDecBytes - } else { - fp = simpleFpDecIO - } - // d.r.init() - d.init2(dec) - return -} - -func (d *simpleDecDriver[T]) NumBytesRead() int { - return int(d.r.numread()) -} - -func (d *simpleDecDriver[T]) resetInBytes(in []byte) { - d.r.resetBytes(in) -} - -func (d *simpleDecDriver[T]) resetInIO(r io.Reader) { - d.r.resetIO(r, d.h.ReaderBufferSize, d.h.MaxInitLen, &d.d.blist) -} - -// ---- (custom stanza) - -func (d *simpleDecDriver[T]) descBd() string { - return sprintf("%v (%s)", d.bd, simpledesc(d.bd)) -} - -func (d *simpleDecDriver[T]) DecodeFloat32() (f float32) { - return float32(chkOvf.Float32V(d.DecodeFloat64())) -} diff --git a/vendor/github.com/ugorji/go/codec/simple.mono.generated.go b/vendor/github.com/ugorji/go/codec/simple.mono.generated.go deleted file mode 100644 index ff1b02238..000000000 --- a/vendor/github.com/ugorji/go/codec/simple.mono.generated.go +++ /dev/null @@ -1,7549 +0,0 @@ -//go:build !notmono && !codec.notmono - -// Copyright (c) 2012-2020 Ugorji Nwoke. All rights reserved. -// Use of this source code is governed by a MIT license found in the LICENSE file. - -package codec - -import ( - "encoding" - - "io" - "math" - "reflect" - "slices" - "sort" - "strconv" - "sync" - "time" -) - -type helperEncDriverSimpleBytes struct{} -type encFnSimpleBytes struct { - i encFnInfo - fe func(*encoderSimpleBytes, *encFnInfo, reflect.Value) -} -type encRtidFnSimpleBytes struct { - rtid uintptr - fn *encFnSimpleBytes -} -type encoderSimpleBytes struct { - dh helperEncDriverSimpleBytes - fp *fastpathEsSimpleBytes - e simpleEncDriverBytes - encoderBase -} -type helperDecDriverSimpleBytes struct{} -type decFnSimpleBytes struct { - i decFnInfo - fd func(*decoderSimpleBytes, *decFnInfo, reflect.Value) -} -type decRtidFnSimpleBytes struct { - rtid uintptr - fn *decFnSimpleBytes -} -type decoderSimpleBytes struct { - dh helperDecDriverSimpleBytes - fp *fastpathDsSimpleBytes - d simpleDecDriverBytes - decoderBase -} -type simpleEncDriverBytes struct { - noBuiltInTypes - encDriverNoopContainerWriter - encDriverNoState - encDriverContainerNoTrackerT - encInit2er - - h *SimpleHandle - e *encoderBase - - w bytesEncAppender -} -type simpleDecDriverBytes struct { - h *SimpleHandle - d *decoderBase - r bytesDecReader - - bdAndBdread - - noBuiltInTypes - - decDriverNoopContainerReader - decInit2er -} - -func (e *encoderSimpleBytes) rawExt(_ *encFnInfo, rv reflect.Value) { - if re := rv2i(rv).(*RawExt); re == nil { - e.e.EncodeNil() - } else { - e.e.EncodeRawExt(re) - } -} - -func (e *encoderSimpleBytes) ext(f *encFnInfo, rv reflect.Value) { - e.e.EncodeExt(rv2i(rv), f.ti.rt, f.xfTag, f.xfFn) -} - -func (e *encoderSimpleBytes) selferMarshal(_ *encFnInfo, rv reflect.Value) { - rv2i(rv).(Selfer).CodecEncodeSelf(&Encoder{e}) -} - -func (e *encoderSimpleBytes) binaryMarshal(_ *encFnInfo, rv reflect.Value) { - bs, fnerr := rv2i(rv).(encoding.BinaryMarshaler).MarshalBinary() - e.marshalRaw(bs, fnerr) -} - -func (e *encoderSimpleBytes) textMarshal(_ *encFnInfo, rv reflect.Value) { - bs, fnerr := rv2i(rv).(encoding.TextMarshaler).MarshalText() - e.marshalUtf8(bs, fnerr) -} - -func (e *encoderSimpleBytes) jsonMarshal(_ *encFnInfo, rv reflect.Value) { - bs, fnerr := rv2i(rv).(jsonMarshaler).MarshalJSON() - e.marshalAsis(bs, fnerr) -} - -func (e *encoderSimpleBytes) raw(_ *encFnInfo, rv reflect.Value) { - e.rawBytes(rv2i(rv).(Raw)) -} - -func (e *encoderSimpleBytes) encodeComplex64(v complex64) { - if imag(v) != 0 { - halt.errorf("cannot encode complex number: %v, with imaginary values: %v", any(v), any(imag(v))) - } - e.e.EncodeFloat32(real(v)) -} - -func (e *encoderSimpleBytes) encodeComplex128(v complex128) { - if imag(v) != 0 { - halt.errorf("cannot encode complex number: %v, with imaginary values: %v", any(v), any(imag(v))) - } - e.e.EncodeFloat64(real(v)) -} - -func (e *encoderSimpleBytes) kBool(_ *encFnInfo, rv reflect.Value) { - e.e.EncodeBool(rvGetBool(rv)) -} - -func (e *encoderSimpleBytes) kTime(_ *encFnInfo, rv reflect.Value) { - e.e.EncodeTime(rvGetTime(rv)) -} - -func (e *encoderSimpleBytes) kString(_ *encFnInfo, rv reflect.Value) { - e.e.EncodeString(rvGetString(rv)) -} - -func (e *encoderSimpleBytes) kFloat32(_ *encFnInfo, rv reflect.Value) { - e.e.EncodeFloat32(rvGetFloat32(rv)) -} - -func (e *encoderSimpleBytes) kFloat64(_ *encFnInfo, rv reflect.Value) { - e.e.EncodeFloat64(rvGetFloat64(rv)) -} - -func (e *encoderSimpleBytes) kComplex64(_ *encFnInfo, rv reflect.Value) { - e.encodeComplex64(rvGetComplex64(rv)) -} - -func (e *encoderSimpleBytes) kComplex128(_ *encFnInfo, rv reflect.Value) { - e.encodeComplex128(rvGetComplex128(rv)) -} - -func (e *encoderSimpleBytes) kInt(_ *encFnInfo, rv reflect.Value) { - e.e.EncodeInt(int64(rvGetInt(rv))) -} - -func (e *encoderSimpleBytes) kInt8(_ *encFnInfo, rv reflect.Value) { - e.e.EncodeInt(int64(rvGetInt8(rv))) -} - -func (e *encoderSimpleBytes) kInt16(_ *encFnInfo, rv reflect.Value) { - e.e.EncodeInt(int64(rvGetInt16(rv))) -} - -func (e *encoderSimpleBytes) kInt32(_ *encFnInfo, rv reflect.Value) { - e.e.EncodeInt(int64(rvGetInt32(rv))) -} - -func (e *encoderSimpleBytes) kInt64(_ *encFnInfo, rv reflect.Value) { - e.e.EncodeInt(int64(rvGetInt64(rv))) -} - -func (e *encoderSimpleBytes) kUint(_ *encFnInfo, rv reflect.Value) { - e.e.EncodeUint(uint64(rvGetUint(rv))) -} - -func (e *encoderSimpleBytes) kUint8(_ *encFnInfo, rv reflect.Value) { - e.e.EncodeUint(uint64(rvGetUint8(rv))) -} - -func (e *encoderSimpleBytes) kUint16(_ *encFnInfo, rv reflect.Value) { - e.e.EncodeUint(uint64(rvGetUint16(rv))) -} - -func (e *encoderSimpleBytes) kUint32(_ *encFnInfo, rv reflect.Value) { - e.e.EncodeUint(uint64(rvGetUint32(rv))) -} - -func (e *encoderSimpleBytes) kUint64(_ *encFnInfo, rv reflect.Value) { - e.e.EncodeUint(uint64(rvGetUint64(rv))) -} - -func (e *encoderSimpleBytes) kUintptr(_ *encFnInfo, rv reflect.Value) { - e.e.EncodeUint(uint64(rvGetUintptr(rv))) -} - -func (e *encoderSimpleBytes) kSeqFn(rt reflect.Type) (fn *encFnSimpleBytes) { - - if rt = baseRT(rt); rt.Kind() != reflect.Interface { - fn = e.fn(rt) - } - return -} - -func (e *encoderSimpleBytes) kArrayWMbs(rv reflect.Value, ti *typeInfo, isSlice bool) { - var l int - if isSlice { - l = rvLenSlice(rv) - } else { - l = rv.Len() - } - if l == 0 { - e.e.WriteMapEmpty() - return - } - e.haltOnMbsOddLen(l) - e.mapStart(l >> 1) - - var fn *encFnSimpleBytes - builtin := ti.tielem.flagEncBuiltin - if !builtin { - fn = e.kSeqFn(ti.elem) - } - - j := 0 - e.c = containerMapKey - e.e.WriteMapElemKey(true) - for { - rvv := rvArrayIndex(rv, j, ti, isSlice) - if builtin { - e.encodeIB(rv2i(baseRVRV(rvv))) - } else { - e.encodeValue(rvv, fn) - } - j++ - if j == l { - break - } - if j&1 == 0 { - e.c = containerMapKey - e.e.WriteMapElemKey(false) - } else { - e.mapElemValue() - } - } - e.c = 0 - e.e.WriteMapEnd() - -} - -func (e *encoderSimpleBytes) kArrayW(rv reflect.Value, ti *typeInfo, isSlice bool) { - var l int - if isSlice { - l = rvLenSlice(rv) - } else { - l = rv.Len() - } - if l <= 0 { - e.e.WriteArrayEmpty() - return - } - e.arrayStart(l) - - var fn *encFnSimpleBytes - if !ti.tielem.flagEncBuiltin { - fn = e.kSeqFn(ti.elem) - } - - j := 0 - e.c = containerArrayElem - e.e.WriteArrayElem(true) - builtin := ti.tielem.flagEncBuiltin - for { - rvv := rvArrayIndex(rv, j, ti, isSlice) - if builtin { - e.encodeIB(rv2i(baseRVRV(rvv))) - } else { - e.encodeValue(rvv, fn) - } - j++ - if j == l { - break - } - e.c = containerArrayElem - e.e.WriteArrayElem(false) - } - - e.c = 0 - e.e.WriteArrayEnd() -} - -func (e *encoderSimpleBytes) kChan(f *encFnInfo, rv reflect.Value) { - if f.ti.chandir&uint8(reflect.RecvDir) == 0 { - halt.errorStr("send-only channel cannot be encoded") - } - if !f.ti.mbs && uint8TypId == rt2id(f.ti.elem) { - e.kSliceBytesChan(rv) - return - } - rtslice := reflect.SliceOf(f.ti.elem) - rv = chanToSlice(rv, rtslice, e.h.ChanRecvTimeout) - ti := e.h.getTypeInfo(rt2id(rtslice), rtslice) - if f.ti.mbs { - e.kArrayWMbs(rv, ti, true) - } else { - e.kArrayW(rv, ti, true) - } -} - -func (e *encoderSimpleBytes) kSlice(f *encFnInfo, rv reflect.Value) { - if f.ti.mbs { - e.kArrayWMbs(rv, f.ti, true) - } else if f.ti.rtid == uint8SliceTypId || uint8TypId == rt2id(f.ti.elem) { - - e.e.EncodeBytes(rvGetBytes(rv)) - } else { - e.kArrayW(rv, f.ti, true) - } -} - -func (e *encoderSimpleBytes) kArray(f *encFnInfo, rv reflect.Value) { - if f.ti.mbs { - e.kArrayWMbs(rv, f.ti, false) - } else if handleBytesWithinKArray && uint8TypId == rt2id(f.ti.elem) { - e.e.EncodeStringBytesRaw(rvGetArrayBytes(rv, nil)) - } else { - e.kArrayW(rv, f.ti, false) - } -} - -func (e *encoderSimpleBytes) kSliceBytesChan(rv reflect.Value) { - - bs0 := e.blist.peek(32, true) - bs := bs0 - - irv := rv2i(rv) - ch, ok := irv.(<-chan byte) - if !ok { - ch = irv.(chan byte) - } - -L1: - switch timeout := e.h.ChanRecvTimeout; { - case timeout == 0: - for { - select { - case b := <-ch: - bs = append(bs, b) - default: - break L1 - } - } - case timeout > 0: - tt := time.NewTimer(timeout) - for { - select { - case b := <-ch: - bs = append(bs, b) - case <-tt.C: - - break L1 - } - } - default: - for b := range ch { - bs = append(bs, b) - } - } - - e.e.EncodeBytes(bs) - e.blist.put(bs) - if !byteSliceSameData(bs0, bs) { - e.blist.put(bs0) - } -} - -func (e *encoderSimpleBytes) kStructFieldKey(keyType valueType, encName string) { - - if keyType == valueTypeString { - e.e.EncodeString(encName) - } else if keyType == valueTypeInt { - e.e.EncodeInt(must.Int(strconv.ParseInt(encName, 10, 64))) - } else if keyType == valueTypeUint { - e.e.EncodeUint(must.Uint(strconv.ParseUint(encName, 10, 64))) - } else if keyType == valueTypeFloat { - e.e.EncodeFloat64(must.Float(strconv.ParseFloat(encName, 64))) - } else { - halt.errorStr2("invalid struct key type: ", keyType.String()) - } - -} - -func (e *encoderSimpleBytes) kStructSimple(f *encFnInfo, rv reflect.Value) { - _ = e.e - tisfi := f.ti.sfi.source() - - chkCirRef := e.h.CheckCircularRef - var si *structFieldInfo - var j int - - if f.ti.toArray || e.h.StructToArray { - if len(tisfi) == 0 { - e.e.WriteArrayEmpty() - return - } - e.arrayStart(len(tisfi)) - for j, si = range tisfi { - e.c = containerArrayElem - e.e.WriteArrayElem(j == 0) - if si.encBuiltin { - e.encodeIB(rv2i(si.fieldNoAlloc(rv, true))) - } else { - e.encodeValue(si.fieldNoAlloc(rv, !chkCirRef), nil) - } - } - e.c = 0 - e.e.WriteArrayEnd() - } else { - if len(tisfi) == 0 { - e.e.WriteMapEmpty() - return - } - if e.h.Canonical { - tisfi = f.ti.sfi.sorted() - } - e.mapStart(len(tisfi)) - for j, si = range tisfi { - e.c = containerMapKey - e.e.WriteMapElemKey(j == 0) - e.e.EncodeStringNoEscape4Json(si.encName) - e.mapElemValue() - if si.encBuiltin { - e.encodeIB(rv2i(si.fieldNoAlloc(rv, true))) - } else { - e.encodeValue(si.fieldNoAlloc(rv, !chkCirRef), nil) - } - } - e.c = 0 - e.e.WriteMapEnd() - } -} - -func (e *encoderSimpleBytes) kStruct(f *encFnInfo, rv reflect.Value) { - _ = e.e - ti := f.ti - toMap := !(ti.toArray || e.h.StructToArray) - var mf map[string]interface{} - if ti.flagMissingFielder { - toMap = true - mf = rv2i(rv).(MissingFielder).CodecMissingFields() - } else if ti.flagMissingFielderPtr { - toMap = true - if rv.CanAddr() { - mf = rv2i(rvAddr(rv, ti.ptr)).(MissingFielder).CodecMissingFields() - } else { - mf = rv2i(e.addrRV(rv, ti.rt, ti.ptr)).(MissingFielder).CodecMissingFields() - } - } - newlen := len(mf) - tisfi := ti.sfi.source() - newlen += len(tisfi) - - var fkvs = e.slist.get(newlen)[:newlen] - - recur := e.h.RecursiveEmptyCheck - chkCirRef := e.h.CheckCircularRef - - var xlen int - - var kv sfiRv - var j int - var sf encStructFieldObj - if toMap { - newlen = 0 - if e.h.Canonical { - tisfi = f.ti.sfi.sorted() - } - for _, si := range tisfi { - - if si.omitEmpty { - kv.r = si.fieldNoAlloc(rv, false) - if isEmptyValue(kv.r, e.h.TypeInfos, recur) { - continue - } - } else { - kv.r = si.fieldNoAlloc(rv, si.encBuiltin || !chkCirRef) - } - kv.v = si - fkvs[newlen] = kv - newlen++ - } - - var mf2s []stringIntf - if len(mf) != 0 { - mf2s = make([]stringIntf, 0, len(mf)) - for k, v := range mf { - if k == "" { - continue - } - if ti.infoFieldOmitempty && isEmptyValue(reflect.ValueOf(v), e.h.TypeInfos, recur) { - continue - } - mf2s = append(mf2s, stringIntf{k, v}) - } - } - - xlen = newlen + len(mf2s) - if xlen == 0 { - e.e.WriteMapEmpty() - goto END - } - - e.mapStart(xlen) - - if len(mf2s) != 0 && e.h.Canonical { - mf2w := make([]encStructFieldObj, newlen+len(mf2s)) - for j = 0; j < newlen; j++ { - kv = fkvs[j] - mf2w[j] = encStructFieldObj{kv.v.encName, kv.r, nil, true, - !kv.v.encNameEscape4Json, kv.v.encBuiltin} - } - for _, v := range mf2s { - mf2w[j] = encStructFieldObj{v.v, reflect.Value{}, v.i, false, false, false} - j++ - } - sort.Sort((encStructFieldObjSlice)(mf2w)) - for j, sf = range mf2w { - e.c = containerMapKey - e.e.WriteMapElemKey(j == 0) - if ti.keyType == valueTypeString && sf.noEsc4json { - e.e.EncodeStringNoEscape4Json(sf.key) - } else { - e.kStructFieldKey(ti.keyType, sf.key) - } - e.mapElemValue() - if sf.isRv { - if sf.builtin { - e.encodeIB(rv2i(baseRVRV(sf.rv))) - } else { - e.encodeValue(sf.rv, nil) - } - } else { - if !e.encodeBuiltin(sf.intf) { - e.encodeR(reflect.ValueOf(sf.intf)) - } - - } - } - } else { - keytyp := ti.keyType - for j = 0; j < newlen; j++ { - kv = fkvs[j] - e.c = containerMapKey - e.e.WriteMapElemKey(j == 0) - if ti.keyType == valueTypeString && !kv.v.encNameEscape4Json { - e.e.EncodeStringNoEscape4Json(kv.v.encName) - } else { - e.kStructFieldKey(keytyp, kv.v.encName) - } - e.mapElemValue() - if kv.v.encBuiltin { - e.encodeIB(rv2i(baseRVRV(kv.r))) - } else { - e.encodeValue(kv.r, nil) - } - } - for _, v := range mf2s { - e.c = containerMapKey - e.e.WriteMapElemKey(j == 0) - e.kStructFieldKey(keytyp, v.v) - e.mapElemValue() - if !e.encodeBuiltin(v.i) { - e.encodeR(reflect.ValueOf(v.i)) - } - - j++ - } - } - - e.c = 0 - e.e.WriteMapEnd() - } else { - newlen = len(tisfi) - for i, si := range tisfi { - - if si.omitEmpty { - - kv.r = si.fieldNoAlloc(rv, false) - if isEmptyContainerValue(kv.r, e.h.TypeInfos, recur) { - kv.r = reflect.Value{} - } - } else { - kv.r = si.fieldNoAlloc(rv, si.encBuiltin || !chkCirRef) - } - kv.v = si - fkvs[i] = kv - } - - if newlen == 0 { - e.e.WriteArrayEmpty() - goto END - } - - e.arrayStart(newlen) - for j = 0; j < newlen; j++ { - e.c = containerArrayElem - e.e.WriteArrayElem(j == 0) - kv = fkvs[j] - if !kv.r.IsValid() { - e.e.EncodeNil() - } else if kv.v.encBuiltin { - e.encodeIB(rv2i(baseRVRV(kv.r))) - } else { - e.encodeValue(kv.r, nil) - } - } - e.c = 0 - e.e.WriteArrayEnd() - } - -END: - - e.slist.put(fkvs) -} - -func (e *encoderSimpleBytes) kMap(f *encFnInfo, rv reflect.Value) { - _ = e.e - l := rvLenMap(rv) - if l == 0 { - e.e.WriteMapEmpty() - return - } - e.mapStart(l) - - var keyFn, valFn *encFnSimpleBytes - - ktypeKind := reflect.Kind(f.ti.keykind) - vtypeKind := reflect.Kind(f.ti.elemkind) - - rtval := f.ti.elem - rtvalkind := vtypeKind - for rtvalkind == reflect.Ptr { - rtval = rtval.Elem() - rtvalkind = rtval.Kind() - } - if rtvalkind != reflect.Interface { - valFn = e.fn(rtval) - } - - var rvv = mapAddrLoopvarRV(f.ti.elem, vtypeKind) - - rtkey := f.ti.key - var keyTypeIsString = stringTypId == rt2id(rtkey) - if keyTypeIsString { - keyFn = e.fn(rtkey) - } else { - for rtkey.Kind() == reflect.Ptr { - rtkey = rtkey.Elem() - } - if rtkey.Kind() != reflect.Interface { - keyFn = e.fn(rtkey) - } - } - - if e.h.Canonical { - e.kMapCanonical(f.ti, rv, rvv, keyFn, valFn) - e.c = 0 - e.e.WriteMapEnd() - return - } - - var rvk = mapAddrLoopvarRV(f.ti.key, ktypeKind) - - var it mapIter - mapRange(&it, rv, rvk, rvv, true) - - kbuiltin := f.ti.tikey.flagEncBuiltin - vbuiltin := f.ti.tielem.flagEncBuiltin - for j := 0; it.Next(); j++ { - rv = it.Key() - e.c = containerMapKey - e.e.WriteMapElemKey(j == 0) - if keyTypeIsString { - e.e.EncodeString(rvGetString(rv)) - } else if kbuiltin { - e.encodeIB(rv2i(baseRVRV(rv))) - } else { - e.encodeValue(rv, keyFn) - } - e.mapElemValue() - rv = it.Value() - if vbuiltin { - e.encodeIB(rv2i(baseRVRV(rv))) - } else { - e.encodeValue(it.Value(), valFn) - } - } - it.Done() - - e.c = 0 - e.e.WriteMapEnd() -} - -func (e *encoderSimpleBytes) kMapCanonical(ti *typeInfo, rv, rvv reflect.Value, keyFn, valFn *encFnSimpleBytes) { - _ = e.e - - rtkey := ti.key - rtkeydecl := rtkey.PkgPath() == "" && rtkey.Name() != "" - - mks := rv.MapKeys() - rtkeyKind := rtkey.Kind() - mparams := getMapReqParams(ti) - - switch rtkeyKind { - case reflect.Bool: - - if len(mks) == 2 && mks[0].Bool() { - mks[0], mks[1] = mks[1], mks[0] - } - for i := range mks { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - if rtkeydecl { - e.e.EncodeBool(mks[i].Bool()) - } else { - e.encodeValueNonNil(mks[i], keyFn) - } - e.mapElemValue() - e.encodeValue(mapGet(rv, mks[i], rvv, mparams), valFn) - } - case reflect.String: - mksv := make([]orderedRv[string], len(mks)) - for i, k := range mks { - v := &mksv[i] - v.r = k - v.v = rvGetString(k) - } - slices.SortFunc(mksv, cmpOrderedRv) - for i := range mksv { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - if rtkeydecl { - e.e.EncodeString(mksv[i].v) - } else { - e.encodeValueNonNil(mksv[i].r, keyFn) - } - e.mapElemValue() - e.encodeValue(mapGet(rv, mksv[i].r, rvv, mparams), valFn) - } - case reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64, reflect.Uint, reflect.Uintptr: - mksv := make([]orderedRv[uint64], len(mks)) - for i, k := range mks { - v := &mksv[i] - v.r = k - v.v = k.Uint() - } - slices.SortFunc(mksv, cmpOrderedRv) - for i := range mksv { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - if rtkeydecl { - e.e.EncodeUint(mksv[i].v) - } else { - e.encodeValueNonNil(mksv[i].r, keyFn) - } - e.mapElemValue() - e.encodeValue(mapGet(rv, mksv[i].r, rvv, mparams), valFn) - } - case reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64, reflect.Int: - mksv := make([]orderedRv[int64], len(mks)) - for i, k := range mks { - v := &mksv[i] - v.r = k - v.v = k.Int() - } - slices.SortFunc(mksv, cmpOrderedRv) - for i := range mksv { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - if rtkeydecl { - e.e.EncodeInt(mksv[i].v) - } else { - e.encodeValueNonNil(mksv[i].r, keyFn) - } - e.mapElemValue() - e.encodeValue(mapGet(rv, mksv[i].r, rvv, mparams), valFn) - } - case reflect.Float32: - mksv := make([]orderedRv[float64], len(mks)) - for i, k := range mks { - v := &mksv[i] - v.r = k - v.v = k.Float() - } - slices.SortFunc(mksv, cmpOrderedRv) - for i := range mksv { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - if rtkeydecl { - e.e.EncodeFloat32(float32(mksv[i].v)) - } else { - e.encodeValueNonNil(mksv[i].r, keyFn) - } - e.mapElemValue() - e.encodeValue(mapGet(rv, mksv[i].r, rvv, mparams), valFn) - } - case reflect.Float64: - mksv := make([]orderedRv[float64], len(mks)) - for i, k := range mks { - v := &mksv[i] - v.r = k - v.v = k.Float() - } - slices.SortFunc(mksv, cmpOrderedRv) - for i := range mksv { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - if rtkeydecl { - e.e.EncodeFloat64(mksv[i].v) - } else { - e.encodeValueNonNil(mksv[i].r, keyFn) - } - e.mapElemValue() - e.encodeValue(mapGet(rv, mksv[i].r, rvv, mparams), valFn) - } - default: - if rtkey == timeTyp { - mksv := make([]timeRv, len(mks)) - for i, k := range mks { - v := &mksv[i] - v.r = k - v.v = rv2i(k).(time.Time) - } - slices.SortFunc(mksv, cmpTimeRv) - for i := range mksv { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeTime(mksv[i].v) - e.mapElemValue() - e.encodeValue(mapGet(rv, mksv[i].r, rvv, mparams), valFn) - } - break - } - - bs0 := e.blist.get(len(mks) * 16) - mksv := bs0 - mksbv := make([]bytesRv, len(mks)) - - sideEncode(e.hh, &e.h.sideEncPool, func(se encoderI) { - se.ResetBytes(&mksv) - for i, k := range mks { - v := &mksbv[i] - l := len(mksv) - se.setContainerState(containerMapKey) - se.encodeR(baseRVRV(k)) - se.atEndOfEncode() - se.writerEnd() - v.r = k - v.v = mksv[l:] - } - }) - - slices.SortFunc(mksbv, cmpBytesRv) - for j := range mksbv { - e.c = containerMapKey - e.e.WriteMapElemKey(j == 0) - e.e.writeBytesAsis(mksbv[j].v) - e.mapElemValue() - e.encodeValue(mapGet(rv, mksbv[j].r, rvv, mparams), valFn) - } - e.blist.put(mksv) - if !byteSliceSameData(bs0, mksv) { - e.blist.put(bs0) - } - } -} - -func (e *encoderSimpleBytes) init(h Handle) { - initHandle(h) - callMake(&e.e) - e.hh = h - e.h = h.getBasicHandle() - - e.err = errEncoderNotInitialized - - e.fp = e.e.init(h, &e.encoderBase, e).(*fastpathEsSimpleBytes) - - if e.bytes { - e.rtidFn = &e.h.rtidFnsEncBytes - e.rtidFnNoExt = &e.h.rtidFnsEncNoExtBytes - } else { - e.rtidFn = &e.h.rtidFnsEncIO - e.rtidFnNoExt = &e.h.rtidFnsEncNoExtIO - } - - e.reset() -} - -func (e *encoderSimpleBytes) reset() { - e.e.reset() - if e.ci != nil { - e.ci = e.ci[:0] - } - e.c = 0 - e.calls = 0 - e.seq = 0 - e.err = nil -} - -func (e *encoderSimpleBytes) Encode(v interface{}) (err error) { - - defer panicValToErr(e, callRecoverSentinel, &e.err, &err, debugging) - e.mustEncode(v) - return -} - -func (e *encoderSimpleBytes) MustEncode(v interface{}) { - defer panicValToErr(e, callRecoverSentinel, &e.err, nil, true) - e.mustEncode(v) - return -} - -func (e *encoderSimpleBytes) mustEncode(v interface{}) { - halt.onerror(e.err) - if e.hh == nil { - halt.onerror(errNoFormatHandle) - } - - e.calls++ - if !e.encodeBuiltin(v) { - e.encodeR(reflect.ValueOf(v)) - } - - e.calls-- - if e.calls == 0 { - e.e.atEndOfEncode() - e.e.writerEnd() - } -} - -func (e *encoderSimpleBytes) encodeI(iv interface{}) { - if !e.encodeBuiltin(iv) { - e.encodeR(reflect.ValueOf(iv)) - } -} - -func (e *encoderSimpleBytes) encodeIB(iv interface{}) { - if !e.encodeBuiltin(iv) { - - halt.errorStr("[should not happen] invalid type passed to encodeBuiltin") - } -} - -func (e *encoderSimpleBytes) encodeR(base reflect.Value) { - e.encodeValue(base, nil) -} - -func (e *encoderSimpleBytes) encodeBuiltin(iv interface{}) (ok bool) { - ok = true - switch v := iv.(type) { - case nil: - e.e.EncodeNil() - - case Raw: - e.rawBytes(v) - case string: - e.e.EncodeString(v) - case bool: - e.e.EncodeBool(v) - case int: - e.e.EncodeInt(int64(v)) - case int8: - e.e.EncodeInt(int64(v)) - case int16: - e.e.EncodeInt(int64(v)) - case int32: - e.e.EncodeInt(int64(v)) - case int64: - e.e.EncodeInt(v) - case uint: - e.e.EncodeUint(uint64(v)) - case uint8: - e.e.EncodeUint(uint64(v)) - case uint16: - e.e.EncodeUint(uint64(v)) - case uint32: - e.e.EncodeUint(uint64(v)) - case uint64: - e.e.EncodeUint(v) - case uintptr: - e.e.EncodeUint(uint64(v)) - case float32: - e.e.EncodeFloat32(v) - case float64: - e.e.EncodeFloat64(v) - case complex64: - e.encodeComplex64(v) - case complex128: - e.encodeComplex128(v) - case time.Time: - e.e.EncodeTime(v) - case []byte: - e.e.EncodeBytes(v) - default: - - ok = !skipFastpathTypeSwitchInDirectCall && e.dh.fastpathEncodeTypeSwitch(iv, e) - } - return -} - -func (e *encoderSimpleBytes) encodeValue(rv reflect.Value, fn *encFnSimpleBytes) { - - var ciPushes int - - var rvp reflect.Value - var rvpValid bool - -RV: - switch rv.Kind() { - case reflect.Ptr: - if rvIsNil(rv) { - e.e.EncodeNil() - goto END - } - rvpValid = true - rvp = rv - rv = rv.Elem() - - if e.h.CheckCircularRef && e.ci.canPushElemKind(rv.Kind()) { - e.ci.push(rv2i(rvp)) - ciPushes++ - } - goto RV - case reflect.Interface: - if rvIsNil(rv) { - e.e.EncodeNil() - goto END - } - rvpValid = false - rvp = reflect.Value{} - rv = rv.Elem() - fn = nil - goto RV - case reflect.Map: - if rvIsNil(rv) { - if e.h.NilCollectionToZeroLength { - e.e.WriteMapEmpty() - } else { - e.e.EncodeNil() - } - goto END - } - case reflect.Slice, reflect.Chan: - if rvIsNil(rv) { - if e.h.NilCollectionToZeroLength { - e.e.WriteArrayEmpty() - } else { - e.e.EncodeNil() - } - goto END - } - case reflect.Invalid, reflect.Func: - e.e.EncodeNil() - goto END - } - - if fn == nil { - fn = e.fn(rv.Type()) - } - - if !fn.i.addrE { - - } else if rvpValid { - rv = rvp - } else if rv.CanAddr() { - rv = rvAddr(rv, fn.i.ti.ptr) - } else { - rv = e.addrRV(rv, fn.i.ti.rt, fn.i.ti.ptr) - } - fn.fe(e, &fn.i, rv) - -END: - if ciPushes > 0 { - e.ci.pop(ciPushes) - } -} - -func (e *encoderSimpleBytes) encodeValueNonNil(rv reflect.Value, fn *encFnSimpleBytes) { - - if fn.i.addrE { - if rv.CanAddr() { - rv = rvAddr(rv, fn.i.ti.ptr) - } else { - rv = e.addrRV(rv, fn.i.ti.rt, fn.i.ti.ptr) - } - } - fn.fe(e, &fn.i, rv) -} - -func (e *encoderSimpleBytes) encodeAs(v interface{}, t reflect.Type, ext bool) { - if ext { - e.encodeValue(baseRV(v), e.fn(t)) - } else { - e.encodeValue(baseRV(v), e.fnNoExt(t)) - } -} - -func (e *encoderSimpleBytes) marshalUtf8(bs []byte, fnerr error) { - halt.onerror(fnerr) - if bs == nil { - e.e.EncodeNil() - } else { - e.e.EncodeString(stringView(bs)) - } -} - -func (e *encoderSimpleBytes) marshalAsis(bs []byte, fnerr error) { - halt.onerror(fnerr) - if bs == nil { - e.e.EncodeNil() - } else { - e.e.writeBytesAsis(bs) - } -} - -func (e *encoderSimpleBytes) marshalRaw(bs []byte, fnerr error) { - halt.onerror(fnerr) - e.e.EncodeBytes(bs) -} - -func (e *encoderSimpleBytes) rawBytes(vv Raw) { - v := []byte(vv) - if !e.h.Raw { - halt.errorBytes("Raw values cannot be encoded: ", v) - } - e.e.writeBytesAsis(v) -} - -func (e *encoderSimpleBytes) fn(t reflect.Type) *encFnSimpleBytes { - return e.dh.encFnViaBH(t, e.rtidFn, e.h, e.fp, false) -} - -func (e *encoderSimpleBytes) fnNoExt(t reflect.Type) *encFnSimpleBytes { - return e.dh.encFnViaBH(t, e.rtidFnNoExt, e.h, e.fp, true) -} - -func (e *encoderSimpleBytes) mapStart(length int) { - e.e.WriteMapStart(length) - e.c = containerMapStart -} - -func (e *encoderSimpleBytes) mapElemValue() { - e.e.WriteMapElemValue() - e.c = containerMapValue -} - -func (e *encoderSimpleBytes) arrayStart(length int) { - e.e.WriteArrayStart(length) - e.c = containerArrayStart -} - -func (e *encoderSimpleBytes) writerEnd() { - e.e.writerEnd() -} - -func (e *encoderSimpleBytes) atEndOfEncode() { - e.e.atEndOfEncode() -} - -func (e *encoderSimpleBytes) Reset(w io.Writer) { - if e.bytes { - halt.onerror(errEncNoResetBytesWithWriter) - } - e.reset() - if w == nil { - w = io.Discard - } - e.e.resetOutIO(w) -} - -func (e *encoderSimpleBytes) ResetBytes(out *[]byte) { - if !e.bytes { - halt.onerror(errEncNoResetWriterWithBytes) - } - e.resetBytes(out) -} - -func (e *encoderSimpleBytes) resetBytes(out *[]byte) { - e.reset() - if out == nil { - out = &bytesEncAppenderDefOut - } - e.e.resetOutBytes(out) -} - -func (helperEncDriverSimpleBytes) newEncoderBytes(out *[]byte, h Handle) *encoderSimpleBytes { - var c1 encoderSimpleBytes - c1.bytes = true - c1.init(h) - c1.ResetBytes(out) - return &c1 -} - -func (helperEncDriverSimpleBytes) newEncoderIO(out io.Writer, h Handle) *encoderSimpleBytes { - var c1 encoderSimpleBytes - c1.bytes = false - c1.init(h) - c1.Reset(out) - return &c1 -} - -func (helperEncDriverSimpleBytes) encFnloadFastpathUnderlying(ti *typeInfo, fp *fastpathEsSimpleBytes) (f *fastpathESimpleBytes, u reflect.Type) { - rtid := rt2id(ti.fastpathUnderlying) - idx, ok := fastpathAvIndex(rtid) - if !ok { - return - } - f = &fp[idx] - if uint8(reflect.Array) == ti.kind { - u = reflect.ArrayOf(ti.rt.Len(), ti.elem) - } else { - u = f.rt - } - return -} - -func (helperEncDriverSimpleBytes) encFindRtidFn(s []encRtidFnSimpleBytes, rtid uintptr) (i uint, fn *encFnSimpleBytes) { - - var h uint - var j = uint(len(s)) -LOOP: - if i < j { - h = (i + j) >> 1 - if s[h].rtid < rtid { - i = h + 1 - } else { - j = h - } - goto LOOP - } - if i < uint(len(s)) && s[i].rtid == rtid { - fn = s[i].fn - } - return -} - -func (helperEncDriverSimpleBytes) encFromRtidFnSlice(fns *atomicRtidFnSlice) (s []encRtidFnSimpleBytes) { - if v := fns.load(); v != nil { - s = *(lowLevelToPtr[[]encRtidFnSimpleBytes](v)) - } - return -} - -func (dh helperEncDriverSimpleBytes) encFnViaBH(rt reflect.Type, fns *atomicRtidFnSlice, - x *BasicHandle, fp *fastpathEsSimpleBytes, checkExt bool) (fn *encFnSimpleBytes) { - return dh.encFnVia(rt, fns, x.typeInfos(), &x.mu, x.extHandle, fp, - checkExt, x.CheckCircularRef, x.timeBuiltin, x.binaryHandle, x.jsonHandle) -} - -func (dh helperEncDriverSimpleBytes) encFnVia(rt reflect.Type, fns *atomicRtidFnSlice, - tinfos *TypeInfos, mu *sync.Mutex, exth extHandle, fp *fastpathEsSimpleBytes, - checkExt, checkCircularRef, timeBuiltin, binaryEncoding, json bool) (fn *encFnSimpleBytes) { - rtid := rt2id(rt) - var sp []encRtidFnSimpleBytes = dh.encFromRtidFnSlice(fns) - if sp != nil { - _, fn = dh.encFindRtidFn(sp, rtid) - } - if fn == nil { - fn = dh.encFnViaLoader(rt, rtid, fns, tinfos, mu, exth, fp, checkExt, checkCircularRef, timeBuiltin, binaryEncoding, json) - } - return -} - -func (dh helperEncDriverSimpleBytes) encFnViaLoader(rt reflect.Type, rtid uintptr, fns *atomicRtidFnSlice, - tinfos *TypeInfos, mu *sync.Mutex, exth extHandle, fp *fastpathEsSimpleBytes, - checkExt, checkCircularRef, timeBuiltin, binaryEncoding, json bool) (fn *encFnSimpleBytes) { - - fn = dh.encFnLoad(rt, rtid, tinfos, exth, fp, checkExt, checkCircularRef, timeBuiltin, binaryEncoding, json) - var sp []encRtidFnSimpleBytes - mu.Lock() - sp = dh.encFromRtidFnSlice(fns) - - if sp == nil { - sp = []encRtidFnSimpleBytes{{rtid, fn}} - fns.store(ptrToLowLevel(&sp)) - } else { - idx, fn2 := dh.encFindRtidFn(sp, rtid) - if fn2 == nil { - sp2 := make([]encRtidFnSimpleBytes, len(sp)+1) - copy(sp2[idx+1:], sp[idx:]) - copy(sp2, sp[:idx]) - sp2[idx] = encRtidFnSimpleBytes{rtid, fn} - fns.store(ptrToLowLevel(&sp2)) - } - } - mu.Unlock() - return -} - -func (dh helperEncDriverSimpleBytes) encFnLoad(rt reflect.Type, rtid uintptr, tinfos *TypeInfos, - exth extHandle, fp *fastpathEsSimpleBytes, - checkExt, checkCircularRef, timeBuiltin, binaryEncoding, json bool) (fn *encFnSimpleBytes) { - fn = new(encFnSimpleBytes) - fi := &(fn.i) - ti := tinfos.get(rtid, rt) - fi.ti = ti - rk := reflect.Kind(ti.kind) - - if rtid == timeTypId && timeBuiltin { - fn.fe = (*encoderSimpleBytes).kTime - } else if rtid == rawTypId { - fn.fe = (*encoderSimpleBytes).raw - } else if rtid == rawExtTypId { - fn.fe = (*encoderSimpleBytes).rawExt - fi.addrE = true - } else if xfFn := exth.getExt(rtid, checkExt); xfFn != nil { - fi.xfTag, fi.xfFn = xfFn.tag, xfFn.ext - fn.fe = (*encoderSimpleBytes).ext - if rk == reflect.Struct || rk == reflect.Array { - fi.addrE = true - } - } else if ti.flagSelfer || ti.flagSelferPtr { - fn.fe = (*encoderSimpleBytes).selferMarshal - fi.addrE = ti.flagSelferPtr - } else if supportMarshalInterfaces && binaryEncoding && - (ti.flagBinaryMarshaler || ti.flagBinaryMarshalerPtr) && - (ti.flagBinaryUnmarshaler || ti.flagBinaryUnmarshalerPtr) { - fn.fe = (*encoderSimpleBytes).binaryMarshal - fi.addrE = ti.flagBinaryMarshalerPtr - } else if supportMarshalInterfaces && !binaryEncoding && json && - (ti.flagJsonMarshaler || ti.flagJsonMarshalerPtr) && - (ti.flagJsonUnmarshaler || ti.flagJsonUnmarshalerPtr) { - - fn.fe = (*encoderSimpleBytes).jsonMarshal - fi.addrE = ti.flagJsonMarshalerPtr - } else if supportMarshalInterfaces && !binaryEncoding && - (ti.flagTextMarshaler || ti.flagTextMarshalerPtr) && - (ti.flagTextUnmarshaler || ti.flagTextUnmarshalerPtr) { - fn.fe = (*encoderSimpleBytes).textMarshal - fi.addrE = ti.flagTextMarshalerPtr - } else { - if fastpathEnabled && (rk == reflect.Map || rk == reflect.Slice || rk == reflect.Array) { - - var rtid2 uintptr - if !ti.flagHasPkgPath { - rtid2 = rtid - if rk == reflect.Array { - rtid2 = rt2id(ti.key) - } - if idx, ok := fastpathAvIndex(rtid2); ok { - fn.fe = fp[idx].encfn - } - } else { - - xfe, xrt := dh.encFnloadFastpathUnderlying(ti, fp) - if xfe != nil { - xfnf := xfe.encfn - fn.fe = func(e *encoderSimpleBytes, xf *encFnInfo, xrv reflect.Value) { - xfnf(e, xf, rvConvert(xrv, xrt)) - } - } - } - } - if fn.fe == nil { - switch rk { - case reflect.Bool: - fn.fe = (*encoderSimpleBytes).kBool - case reflect.String: - - fn.fe = (*encoderSimpleBytes).kString - case reflect.Int: - fn.fe = (*encoderSimpleBytes).kInt - case reflect.Int8: - fn.fe = (*encoderSimpleBytes).kInt8 - case reflect.Int16: - fn.fe = (*encoderSimpleBytes).kInt16 - case reflect.Int32: - fn.fe = (*encoderSimpleBytes).kInt32 - case reflect.Int64: - fn.fe = (*encoderSimpleBytes).kInt64 - case reflect.Uint: - fn.fe = (*encoderSimpleBytes).kUint - case reflect.Uint8: - fn.fe = (*encoderSimpleBytes).kUint8 - case reflect.Uint16: - fn.fe = (*encoderSimpleBytes).kUint16 - case reflect.Uint32: - fn.fe = (*encoderSimpleBytes).kUint32 - case reflect.Uint64: - fn.fe = (*encoderSimpleBytes).kUint64 - case reflect.Uintptr: - fn.fe = (*encoderSimpleBytes).kUintptr - case reflect.Float32: - fn.fe = (*encoderSimpleBytes).kFloat32 - case reflect.Float64: - fn.fe = (*encoderSimpleBytes).kFloat64 - case reflect.Complex64: - fn.fe = (*encoderSimpleBytes).kComplex64 - case reflect.Complex128: - fn.fe = (*encoderSimpleBytes).kComplex128 - case reflect.Chan: - fn.fe = (*encoderSimpleBytes).kChan - case reflect.Slice: - fn.fe = (*encoderSimpleBytes).kSlice - case reflect.Array: - fn.fe = (*encoderSimpleBytes).kArray - case reflect.Struct: - if ti.simple { - fn.fe = (*encoderSimpleBytes).kStructSimple - } else { - fn.fe = (*encoderSimpleBytes).kStruct - } - case reflect.Map: - fn.fe = (*encoderSimpleBytes).kMap - case reflect.Interface: - - fn.fe = (*encoderSimpleBytes).kErr - default: - - fn.fe = (*encoderSimpleBytes).kErr - } - } - } - return -} -func (d *decoderSimpleBytes) rawExt(f *decFnInfo, rv reflect.Value) { - d.d.DecodeRawExt(rv2i(rv).(*RawExt)) -} - -func (d *decoderSimpleBytes) ext(f *decFnInfo, rv reflect.Value) { - d.d.DecodeExt(rv2i(rv), f.ti.rt, f.xfTag, f.xfFn) -} - -func (d *decoderSimpleBytes) selferUnmarshal(_ *decFnInfo, rv reflect.Value) { - rv2i(rv).(Selfer).CodecDecodeSelf(&Decoder{d}) -} - -func (d *decoderSimpleBytes) binaryUnmarshal(_ *decFnInfo, rv reflect.Value) { - bm := rv2i(rv).(encoding.BinaryUnmarshaler) - xbs, _ := d.d.DecodeBytes() - fnerr := bm.UnmarshalBinary(xbs) - halt.onerror(fnerr) -} - -func (d *decoderSimpleBytes) textUnmarshal(_ *decFnInfo, rv reflect.Value) { - tm := rv2i(rv).(encoding.TextUnmarshaler) - fnerr := tm.UnmarshalText(bytesOKs(d.d.DecodeStringAsBytes())) - halt.onerror(fnerr) -} - -func (d *decoderSimpleBytes) jsonUnmarshal(_ *decFnInfo, rv reflect.Value) { - d.jsonUnmarshalV(rv2i(rv).(jsonUnmarshaler)) -} - -func (d *decoderSimpleBytes) jsonUnmarshalV(tm jsonUnmarshaler) { - - halt.onerror(tm.UnmarshalJSON(d.d.nextValueBytes())) -} - -func (d *decoderSimpleBytes) kErr(_ *decFnInfo, rv reflect.Value) { - halt.errorf("unsupported decoding kind: %s, for %#v", rv.Kind(), rv) - -} - -func (d *decoderSimpleBytes) raw(_ *decFnInfo, rv reflect.Value) { - rvSetBytes(rv, d.rawBytes()) -} - -func (d *decoderSimpleBytes) kString(_ *decFnInfo, rv reflect.Value) { - rvSetString(rv, d.detach2Str(d.d.DecodeStringAsBytes())) -} - -func (d *decoderSimpleBytes) kBool(_ *decFnInfo, rv reflect.Value) { - rvSetBool(rv, d.d.DecodeBool()) -} - -func (d *decoderSimpleBytes) kTime(_ *decFnInfo, rv reflect.Value) { - rvSetTime(rv, d.d.DecodeTime()) -} - -func (d *decoderSimpleBytes) kFloat32(_ *decFnInfo, rv reflect.Value) { - rvSetFloat32(rv, d.d.DecodeFloat32()) -} - -func (d *decoderSimpleBytes) kFloat64(_ *decFnInfo, rv reflect.Value) { - rvSetFloat64(rv, d.d.DecodeFloat64()) -} - -func (d *decoderSimpleBytes) kComplex64(_ *decFnInfo, rv reflect.Value) { - rvSetComplex64(rv, complex(d.d.DecodeFloat32(), 0)) -} - -func (d *decoderSimpleBytes) kComplex128(_ *decFnInfo, rv reflect.Value) { - rvSetComplex128(rv, complex(d.d.DecodeFloat64(), 0)) -} - -func (d *decoderSimpleBytes) kInt(_ *decFnInfo, rv reflect.Value) { - rvSetInt(rv, int(chkOvf.IntV(d.d.DecodeInt64(), intBitsize))) -} - -func (d *decoderSimpleBytes) kInt8(_ *decFnInfo, rv reflect.Value) { - rvSetInt8(rv, int8(chkOvf.IntV(d.d.DecodeInt64(), 8))) -} - -func (d *decoderSimpleBytes) kInt16(_ *decFnInfo, rv reflect.Value) { - rvSetInt16(rv, int16(chkOvf.IntV(d.d.DecodeInt64(), 16))) -} - -func (d *decoderSimpleBytes) kInt32(_ *decFnInfo, rv reflect.Value) { - rvSetInt32(rv, int32(chkOvf.IntV(d.d.DecodeInt64(), 32))) -} - -func (d *decoderSimpleBytes) kInt64(_ *decFnInfo, rv reflect.Value) { - rvSetInt64(rv, d.d.DecodeInt64()) -} - -func (d *decoderSimpleBytes) kUint(_ *decFnInfo, rv reflect.Value) { - rvSetUint(rv, uint(chkOvf.UintV(d.d.DecodeUint64(), uintBitsize))) -} - -func (d *decoderSimpleBytes) kUintptr(_ *decFnInfo, rv reflect.Value) { - rvSetUintptr(rv, uintptr(chkOvf.UintV(d.d.DecodeUint64(), uintBitsize))) -} - -func (d *decoderSimpleBytes) kUint8(_ *decFnInfo, rv reflect.Value) { - rvSetUint8(rv, uint8(chkOvf.UintV(d.d.DecodeUint64(), 8))) -} - -func (d *decoderSimpleBytes) kUint16(_ *decFnInfo, rv reflect.Value) { - rvSetUint16(rv, uint16(chkOvf.UintV(d.d.DecodeUint64(), 16))) -} - -func (d *decoderSimpleBytes) kUint32(_ *decFnInfo, rv reflect.Value) { - rvSetUint32(rv, uint32(chkOvf.UintV(d.d.DecodeUint64(), 32))) -} - -func (d *decoderSimpleBytes) kUint64(_ *decFnInfo, rv reflect.Value) { - rvSetUint64(rv, d.d.DecodeUint64()) -} - -func (d *decoderSimpleBytes) kInterfaceNaked(f *decFnInfo) (rvn reflect.Value) { - - n := d.naked() - d.d.DecodeNaked() - - if decFailNonEmptyIntf && f.ti.numMeth > 0 { - halt.errorf("cannot decode non-nil codec value into nil %v (%v methods)", f.ti.rt, f.ti.numMeth) - } - - switch n.v { - case valueTypeMap: - mtid := d.mtid - if mtid == 0 { - if d.jsms { - mtid = mapStrIntfTypId - } else { - mtid = mapIntfIntfTypId - } - } - if mtid == mapStrIntfTypId { - var v2 map[string]interface{} - d.decode(&v2) - rvn = rv4iptr(&v2).Elem() - } else if mtid == mapIntfIntfTypId { - var v2 map[interface{}]interface{} - d.decode(&v2) - rvn = rv4iptr(&v2).Elem() - } else if d.mtr { - rvn = reflect.New(d.h.MapType) - d.decode(rv2i(rvn)) - rvn = rvn.Elem() - } else { - - rvn = rvZeroAddrK(d.h.MapType, reflect.Map) - d.decodeValue(rvn, nil) - } - case valueTypeArray: - if d.stid == 0 || d.stid == intfSliceTypId { - var v2 []interface{} - d.decode(&v2) - rvn = rv4iptr(&v2).Elem() - } else if d.str { - rvn = reflect.New(d.h.SliceType) - d.decode(rv2i(rvn)) - rvn = rvn.Elem() - } else { - rvn = rvZeroAddrK(d.h.SliceType, reflect.Slice) - d.decodeValue(rvn, nil) - } - if d.h.PreferArrayOverSlice { - rvn = rvGetArray4Slice(rvn) - } - case valueTypeExt: - tag, bytes := n.u, n.l - bfn := d.h.getExtForTag(tag) - var re = RawExt{Tag: tag} - if bytes == nil { - - if bfn == nil { - d.decode(&re.Value) - rvn = rv4iptr(&re).Elem() - } else if bfn.ext == SelfExt { - rvn = rvZeroAddrK(bfn.rt, bfn.rt.Kind()) - d.decodeValue(rvn, d.fnNoExt(bfn.rt)) - } else { - rvn = reflect.New(bfn.rt) - d.interfaceExtConvertAndDecode(rv2i(rvn), bfn.ext) - rvn = rvn.Elem() - } - } else { - - if bfn == nil { - re.setData(bytes, false) - rvn = rv4iptr(&re).Elem() - } else { - rvn = reflect.New(bfn.rt) - if bfn.ext == SelfExt { - sideDecode(d.hh, &d.h.sideDecPool, func(sd decoderI) { oneOffDecode(sd, rv2i(rvn), bytes, bfn.rt, true) }) - } else { - bfn.ext.ReadExt(rv2i(rvn), bytes) - } - rvn = rvn.Elem() - } - } - - if d.h.PreferPointerForStructOrArray && rvn.CanAddr() { - if rk := rvn.Kind(); rk == reflect.Array || rk == reflect.Struct { - rvn = rvn.Addr() - } - } - case valueTypeNil: - - case valueTypeInt: - rvn = n.ri() - case valueTypeUint: - rvn = n.ru() - case valueTypeFloat: - rvn = n.rf() - case valueTypeBool: - rvn = n.rb() - case valueTypeString, valueTypeSymbol: - rvn = n.rs() - case valueTypeBytes: - rvn = n.rl() - case valueTypeTime: - rvn = n.rt() - default: - halt.errorStr2("kInterfaceNaked: unexpected valueType: ", n.v.String()) - } - return -} - -func (d *decoderSimpleBytes) kInterface(f *decFnInfo, rv reflect.Value) { - - isnilrv := rvIsNil(rv) - - var rvn reflect.Value - - if d.h.InterfaceReset { - - rvn = d.h.intf2impl(f.ti.rtid) - if !rvn.IsValid() { - rvn = d.kInterfaceNaked(f) - if rvn.IsValid() { - rvSetIntf(rv, rvn) - } else if !isnilrv { - decSetNonNilRV2Zero4Intf(rv) - } - return - } - } else if isnilrv { - - rvn = d.h.intf2impl(f.ti.rtid) - if !rvn.IsValid() { - rvn = d.kInterfaceNaked(f) - if rvn.IsValid() { - rvSetIntf(rv, rvn) - } - return - } - } else { - - rvn = rv.Elem() - } - - canDecode, _ := isDecodeable(rvn) - - if !canDecode { - rvn2 := d.oneShotAddrRV(rvn.Type(), rvn.Kind()) - rvSetDirect(rvn2, rvn) - rvn = rvn2 - } - - d.decodeValue(rvn, nil) - rvSetIntf(rv, rvn) -} - -func (d *decoderSimpleBytes) kStructField(si *structFieldInfo, rv reflect.Value) { - if d.d.TryNil() { - rv = si.fieldNoAlloc(rv, true) - if rv.IsValid() { - decSetNonNilRV2Zero(rv) - } - } else if si.decBuiltin { - rv = rvAddr(si.fieldAlloc(rv), si.ptrTyp) - d.decode(rv2i(rv)) - } else { - fn := d.fn(si.baseTyp) - rv = si.fieldAlloc(rv) - if fn.i.addrD { - rv = rvAddr(rv, si.ptrTyp) - } - fn.fd(d, &fn.i, rv) - } -} - -func (d *decoderSimpleBytes) kStructSimple(f *decFnInfo, rv reflect.Value) { - _ = d.d - ctyp := d.d.ContainerType() - ti := f.ti - if ctyp == valueTypeMap { - containerLen := d.mapStart(d.d.ReadMapStart()) - if containerLen == 0 { - d.mapEnd() - return - } - hasLen := containerLen >= 0 - var rvkencname []byte - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - sab, att := d.d.DecodeStringAsBytes() - rvkencname = d.usableStructFieldNameBytes(rvkencname, sab, att) - d.mapElemValue() - if si := ti.siForEncName(rvkencname); si != nil { - d.kStructField(si, rv) - } else { - d.structFieldNotFound(-1, stringView(rvkencname)) - } - } - d.mapEnd() - } else if ctyp == valueTypeArray { - containerLen := d.arrayStart(d.d.ReadArrayStart()) - if containerLen == 0 { - d.arrayEnd() - return - } - - tisfi := ti.sfi.source() - hasLen := containerLen >= 0 - - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.arrayElem(j == 0) - if j < len(tisfi) { - d.kStructField(tisfi[j], rv) - } else { - d.structFieldNotFound(j, "") - } - } - d.arrayEnd() - } else { - halt.onerror(errNeedMapOrArrayDecodeToStruct) - } -} - -func (d *decoderSimpleBytes) kStruct(f *decFnInfo, rv reflect.Value) { - _ = d.d - ctyp := d.d.ContainerType() - ti := f.ti - var mf MissingFielder - if ti.flagMissingFielder { - mf = rv2i(rv).(MissingFielder) - } else if ti.flagMissingFielderPtr { - mf = rv2i(rvAddr(rv, ti.ptr)).(MissingFielder) - } - if ctyp == valueTypeMap { - containerLen := d.mapStart(d.d.ReadMapStart()) - if containerLen == 0 { - d.mapEnd() - return - } - hasLen := containerLen >= 0 - var name2 []byte - var rvkencname []byte - tkt := ti.keyType - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - - if tkt == valueTypeString { - sab, att := d.d.DecodeStringAsBytes() - rvkencname = d.usableStructFieldNameBytes(rvkencname, sab, att) - } else if tkt == valueTypeInt { - rvkencname = strconv.AppendInt(d.b[:0], d.d.DecodeInt64(), 10) - } else if tkt == valueTypeUint { - rvkencname = strconv.AppendUint(d.b[:0], d.d.DecodeUint64(), 10) - } else if tkt == valueTypeFloat { - rvkencname = strconv.AppendFloat(d.b[:0], d.d.DecodeFloat64(), 'f', -1, 64) - } else { - halt.errorStr2("invalid struct key type: ", ti.keyType.String()) - } - - d.mapElemValue() - if si := ti.siForEncName(rvkencname); si != nil { - d.kStructField(si, rv) - } else if mf != nil { - - name2 = append(name2[:0], rvkencname...) - var f interface{} - d.decode(&f) - if !mf.CodecMissingField(name2, f) && d.h.ErrorIfNoField { - halt.errorStr2("no matching struct field when decoding stream map with key: ", stringView(name2)) - } - } else { - d.structFieldNotFound(-1, stringView(rvkencname)) - } - } - d.mapEnd() - } else if ctyp == valueTypeArray { - containerLen := d.arrayStart(d.d.ReadArrayStart()) - if containerLen == 0 { - d.arrayEnd() - return - } - - tisfi := ti.sfi.source() - hasLen := containerLen >= 0 - - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.arrayElem(j == 0) - if j < len(tisfi) { - d.kStructField(tisfi[j], rv) - } else { - d.structFieldNotFound(j, "") - } - } - - d.arrayEnd() - } else { - halt.onerror(errNeedMapOrArrayDecodeToStruct) - } -} - -func (d *decoderSimpleBytes) kSlice(f *decFnInfo, rv reflect.Value) { - _ = d.d - - ti := f.ti - rvCanset := rv.CanSet() - - ctyp := d.d.ContainerType() - if ctyp == valueTypeBytes || ctyp == valueTypeString { - - if !(ti.rtid == uint8SliceTypId || ti.elemkind == uint8(reflect.Uint8)) { - halt.errorf("bytes/string in stream must decode into slice/array of bytes, not %v", ti.rt) - } - rvbs := rvGetBytes(rv) - if rvCanset { - bs2, bst := d.decodeBytesInto(rvbs, false) - if bst != dBytesIntoParamOut { - rvSetBytes(rv, bs2) - } - } else { - - d.decodeBytesInto(rvbs[:len(rvbs):len(rvbs)], true) - } - return - } - - var containerLenS int - isArray := ctyp == valueTypeArray - if isArray { - containerLenS = d.arrayStart(d.d.ReadArrayStart()) - } else if ctyp == valueTypeMap { - containerLenS = d.mapStart(d.d.ReadMapStart()) * 2 - } else { - halt.errorStr2("decoding into a slice, expect map/array - got ", ctyp.String()) - } - - if containerLenS == 0 { - if rvCanset { - if rvIsNil(rv) { - rvSetDirect(rv, rvSliceZeroCap(ti.rt)) - } else { - rvSetSliceLen(rv, 0) - } - } - if isArray { - d.arrayEnd() - } else { - d.mapEnd() - } - return - } - - rtelem0Mut := !scalarBitset.isset(ti.elemkind) - rtelem := ti.elem - - for k := reflect.Kind(ti.elemkind); k == reflect.Ptr; k = rtelem.Kind() { - rtelem = rtelem.Elem() - } - - var fn *decFnSimpleBytes - - var rvChanged bool - - var rv0 = rv - var rv9 reflect.Value - - rvlen := rvLenSlice(rv) - rvcap := rvCapSlice(rv) - maxInitLen := d.maxInitLen() - hasLen := containerLenS >= 0 - if hasLen { - if containerLenS > rvcap { - oldRvlenGtZero := rvlen > 0 - rvlen1 := int(decInferLen(containerLenS, maxInitLen, uint(ti.elemsize))) - if rvlen1 == rvlen { - } else if rvlen1 <= rvcap { - if rvCanset { - rvlen = rvlen1 - rvSetSliceLen(rv, rvlen) - } - } else if rvCanset { - rvlen = rvlen1 - rv, rvCanset = rvMakeSlice(rv, f.ti, rvlen, rvlen) - rvcap = rvlen - rvChanged = !rvCanset - } else { - halt.errorStr("cannot decode into non-settable slice") - } - if rvChanged && oldRvlenGtZero && rtelem0Mut { - rvCopySlice(rv, rv0, rtelem) - } - } else if containerLenS != rvlen { - if rvCanset { - rvlen = containerLenS - rvSetSliceLen(rv, rvlen) - } - } - } - - var elemReset = d.h.SliceElementReset - - var rtelemIsPtr bool - var rtelemElem reflect.Type - builtin := ti.tielem.flagDecBuiltin - if builtin { - rtelemIsPtr = ti.elemkind == uint8(reflect.Ptr) - if rtelemIsPtr { - rtelemElem = ti.elem.Elem() - } - } - - var j int - for ; d.containerNext(j, containerLenS, hasLen); j++ { - if j == 0 { - if rvIsNil(rv) { - if rvCanset { - rvlen = int(decInferLen(containerLenS, maxInitLen, uint(ti.elemsize))) - rv, rvCanset = rvMakeSlice(rv, f.ti, rvlen, rvlen) - rvcap = rvlen - rvChanged = !rvCanset - } else { - halt.errorStr("cannot decode into non-settable slice") - } - } - if fn == nil { - fn = d.fn(rtelem) - } - } - - if ctyp == valueTypeArray { - d.arrayElem(j == 0) - } else if j&1 == 0 { - d.mapElemKey(j == 0) - } else { - d.mapElemValue() - } - - if j >= rvlen { - - if rvlen < rvcap { - rvlen = rvcap - if rvCanset { - rvSetSliceLen(rv, rvlen) - } else if rvChanged { - rv = rvSlice(rv, rvlen) - } else { - halt.onerror(errExpandSliceCannotChange) - } - } else { - if !(rvCanset || rvChanged) { - halt.onerror(errExpandSliceCannotChange) - } - rv, rvcap, rvCanset = rvGrowSlice(rv, f.ti, rvcap, 1) - - rvlen = rvcap - rvChanged = !rvCanset - } - } - - rv9 = rvArrayIndex(rv, j, f.ti, true) - if elemReset { - rvSetZero(rv9) - } - if d.d.TryNil() { - rvSetZero(rv9) - } else if builtin { - if rtelemIsPtr { - if rvIsNil(rv9) { - rvSetDirect(rv9, reflect.New(rtelemElem)) - } - d.decode(rv2i(rv9)) - } else { - d.decode(rv2i(rvAddr(rv9, ti.tielem.ptr))) - } - } else { - d.decodeValueNoCheckNil(rv9, fn) - } - } - if j < rvlen { - if rvCanset { - rvSetSliceLen(rv, j) - } else if rvChanged { - rv = rvSlice(rv, j) - } - - } else if j == 0 && rvIsNil(rv) { - if rvCanset { - rv = rvSliceZeroCap(ti.rt) - rvCanset = false - rvChanged = true - } - } - if isArray { - d.arrayEnd() - } else { - d.mapEnd() - } - - if rvChanged { - rvSetDirect(rv0, rv) - } -} - -func (d *decoderSimpleBytes) kArray(f *decFnInfo, rv reflect.Value) { - _ = d.d - - ti := f.ti - ctyp := d.d.ContainerType() - if handleBytesWithinKArray && (ctyp == valueTypeBytes || ctyp == valueTypeString) { - - if ti.elemkind != uint8(reflect.Uint8) { - halt.errorf("bytes/string in stream can decode into array of bytes, but not %v", ti.rt) - } - rvbs := rvGetArrayBytes(rv, nil) - d.decodeBytesInto(rvbs, true) - return - } - - var containerLenS int - isArray := ctyp == valueTypeArray - if isArray { - containerLenS = d.arrayStart(d.d.ReadArrayStart()) - } else if ctyp == valueTypeMap { - containerLenS = d.mapStart(d.d.ReadMapStart()) * 2 - } else { - halt.errorStr2("decoding into a slice, expect map/array - got ", ctyp.String()) - } - - if containerLenS == 0 { - if isArray { - d.arrayEnd() - } else { - d.mapEnd() - } - return - } - - rtelem := ti.elem - for k := reflect.Kind(ti.elemkind); k == reflect.Ptr; k = rtelem.Kind() { - rtelem = rtelem.Elem() - } - - var rv9 reflect.Value - - rvlen := rv.Len() - hasLen := containerLenS >= 0 - if hasLen && containerLenS > rvlen { - halt.errorf("cannot decode into array with length: %v, less than container length: %v", any(rvlen), any(containerLenS)) - } - - var elemReset = d.h.SliceElementReset - - var rtelemIsPtr bool - var rtelemElem reflect.Type - var fn *decFnSimpleBytes - builtin := ti.tielem.flagDecBuiltin - if builtin { - rtelemIsPtr = ti.elemkind == uint8(reflect.Ptr) - if rtelemIsPtr { - rtelemElem = ti.elem.Elem() - } - } else { - fn = d.fn(rtelem) - } - - for j := 0; d.containerNext(j, containerLenS, hasLen); j++ { - if ctyp == valueTypeArray { - d.arrayElem(j == 0) - } else if j&1 == 0 { - d.mapElemKey(j == 0) - } else { - d.mapElemValue() - } - - if j >= rvlen { - d.arrayCannotExpand(rvlen, j+1) - d.swallow() - continue - } - - rv9 = rvArrayIndex(rv, j, f.ti, false) - if elemReset { - rvSetZero(rv9) - } - if d.d.TryNil() { - rvSetZero(rv9) - } else if builtin { - if rtelemIsPtr { - if rvIsNil(rv9) { - rvSetDirect(rv9, reflect.New(rtelemElem)) - } - d.decode(rv2i(rv9)) - } else { - d.decode(rv2i(rvAddr(rv9, ti.tielem.ptr))) - } - } else { - d.decodeValueNoCheckNil(rv9, fn) - } - } - if isArray { - d.arrayEnd() - } else { - d.mapEnd() - } -} - -func (d *decoderSimpleBytes) kChan(f *decFnInfo, rv reflect.Value) { - _ = d.d - - ti := f.ti - if ti.chandir&uint8(reflect.SendDir) == 0 { - halt.errorStr("receive-only channel cannot be decoded") - } - ctyp := d.d.ContainerType() - if ctyp == valueTypeBytes || ctyp == valueTypeString { - - if !(ti.rtid == uint8SliceTypId || ti.elemkind == uint8(reflect.Uint8)) { - halt.errorf("bytes/string in stream must decode into slice/array of bytes, not %v", ti.rt) - } - bs2, _ := d.d.DecodeBytes() - irv := rv2i(rv) - ch, ok := irv.(chan<- byte) - if !ok { - ch = irv.(chan byte) - } - for _, b := range bs2 { - ch <- b - } - return - } - - var rvCanset = rv.CanSet() - - var containerLenS int - isArray := ctyp == valueTypeArray - if isArray { - containerLenS = d.arrayStart(d.d.ReadArrayStart()) - } else if ctyp == valueTypeMap { - containerLenS = d.mapStart(d.d.ReadMapStart()) * 2 - } else { - halt.errorStr2("decoding into a slice, expect map/array - got ", ctyp.String()) - } - - if containerLenS == 0 { - if rvCanset && rvIsNil(rv) { - rvSetDirect(rv, reflect.MakeChan(ti.rt, 0)) - } - if isArray { - d.arrayEnd() - } else { - d.mapEnd() - } - return - } - - rtelem := ti.elem - useTransient := decUseTransient && ti.elemkind != byte(reflect.Ptr) && ti.tielem.flagCanTransient - - for k := reflect.Kind(ti.elemkind); k == reflect.Ptr; k = rtelem.Kind() { - rtelem = rtelem.Elem() - } - - var fn *decFnSimpleBytes - - var rvChanged bool - var rv0 = rv - var rv9 reflect.Value - - var rvlen int - hasLen := containerLenS >= 0 - maxInitLen := d.maxInitLen() - - for j := 0; d.containerNext(j, containerLenS, hasLen); j++ { - if j == 0 { - if rvIsNil(rv) { - if hasLen { - rvlen = int(decInferLen(containerLenS, maxInitLen, uint(ti.elemsize))) - } else { - rvlen = decDefChanCap - } - if rvCanset { - rv = reflect.MakeChan(ti.rt, rvlen) - rvChanged = true - } else { - halt.errorStr("cannot decode into non-settable chan") - } - } - if fn == nil { - fn = d.fn(rtelem) - } - } - - if ctyp == valueTypeArray { - d.arrayElem(j == 0) - } else if j&1 == 0 { - d.mapElemKey(j == 0) - } else { - d.mapElemValue() - } - - if rv9.IsValid() { - rvSetZero(rv9) - } else if useTransient { - rv9 = d.perType.TransientAddrK(ti.elem, reflect.Kind(ti.elemkind)) - } else { - rv9 = rvZeroAddrK(ti.elem, reflect.Kind(ti.elemkind)) - } - if !d.d.TryNil() { - d.decodeValueNoCheckNil(rv9, fn) - } - rv.Send(rv9) - } - if isArray { - d.arrayEnd() - } else { - d.mapEnd() - } - - if rvChanged { - rvSetDirect(rv0, rv) - } - -} - -func (d *decoderSimpleBytes) kMap(f *decFnInfo, rv reflect.Value) { - _ = d.d - containerLen := d.mapStart(d.d.ReadMapStart()) - ti := f.ti - if rvIsNil(rv) { - rvlen := int(decInferLen(containerLen, d.maxInitLen(), uint(ti.keysize+ti.elemsize))) - rvSetDirect(rv, makeMapReflect(ti.rt, rvlen)) - } - - if containerLen == 0 { - d.mapEnd() - return - } - - ktype, vtype := ti.key, ti.elem - ktypeId := rt2id(ktype) - vtypeKind := reflect.Kind(ti.elemkind) - ktypeKind := reflect.Kind(ti.keykind) - mparams := getMapReqParams(ti) - - vtypePtr := vtypeKind == reflect.Ptr - ktypePtr := ktypeKind == reflect.Ptr - - vTransient := decUseTransient && !vtypePtr && ti.tielem.flagCanTransient - - kTransient := vTransient && !ktypePtr && ti.tikey.flagCanTransient - - var vtypeElem reflect.Type - - var keyFn, valFn *decFnSimpleBytes - var ktypeLo, vtypeLo = ktype, vtype - - if ktypeKind == reflect.Ptr { - for ktypeLo = ktype.Elem(); ktypeLo.Kind() == reflect.Ptr; ktypeLo = ktypeLo.Elem() { - } - } - - if vtypePtr { - vtypeElem = vtype.Elem() - for vtypeLo = vtypeElem; vtypeLo.Kind() == reflect.Ptr; vtypeLo = vtypeLo.Elem() { - } - } - - rvkMut := !scalarBitset.isset(ti.keykind) - rvvMut := !scalarBitset.isset(ti.elemkind) - rvvCanNil := isnilBitset.isset(ti.elemkind) - - var rvk, rvkn, rvv, rvvn, rvva, rvvz reflect.Value - - var doMapGet, doMapSet bool - - if !d.h.MapValueReset { - if rvvMut && (vtypeKind != reflect.Interface || !d.h.InterfaceReset) { - doMapGet = true - rvva = mapAddrLoopvarRV(vtype, vtypeKind) - } - } - - ktypeIsString := ktypeId == stringTypId - ktypeIsIntf := ktypeId == intfTypId - hasLen := containerLen >= 0 - - var kstr2bs []byte - var kstr string - - var mapKeyStringSharesBytesBuf bool - var att dBytesAttachState - - var vElem, kElem reflect.Type - kbuiltin := ti.tikey.flagDecBuiltin && ti.keykind != uint8(reflect.Slice) - vbuiltin := ti.tielem.flagDecBuiltin - if kbuiltin && ktypePtr { - kElem = ti.key.Elem() - } - if vbuiltin && vtypePtr { - vElem = ti.elem.Elem() - } - - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - mapKeyStringSharesBytesBuf = false - kstr = "" - if j == 0 { - - if kTransient { - rvk = d.perType.TransientAddr2K(ktype, ktypeKind) - } else { - rvk = rvZeroAddrK(ktype, ktypeKind) - } - if !rvkMut { - rvkn = rvk - } - if !rvvMut { - if vTransient { - rvvn = d.perType.TransientAddrK(vtype, vtypeKind) - } else { - rvvn = rvZeroAddrK(vtype, vtypeKind) - } - } - if !ktypeIsString && keyFn == nil { - keyFn = d.fn(ktypeLo) - } - if valFn == nil { - valFn = d.fn(vtypeLo) - } - } else if rvkMut { - rvSetZero(rvk) - } else { - rvk = rvkn - } - - d.mapElemKey(j == 0) - - if d.d.TryNil() { - rvSetZero(rvk) - } else if ktypeIsString { - kstr2bs, att = d.d.DecodeStringAsBytes() - kstr, mapKeyStringSharesBytesBuf = d.bytes2Str(kstr2bs, att) - rvSetString(rvk, kstr) - } else { - if kbuiltin { - if ktypePtr { - if rvIsNil(rvk) { - rvSetDirect(rvk, reflect.New(kElem)) - } - d.decode(rv2i(rvk)) - } else { - d.decode(rv2i(rvAddr(rvk, ti.tikey.ptr))) - } - } else { - d.decodeValueNoCheckNil(rvk, keyFn) - } - - if ktypeIsIntf { - if rvk2 := rvk.Elem(); rvk2.IsValid() && rvk2.Type() == uint8SliceTyp { - kstr2bs = rvGetBytes(rvk2) - kstr, mapKeyStringSharesBytesBuf = d.bytes2Str(kstr2bs, dBytesAttachView) - rvSetIntf(rvk, rv4istr(kstr)) - } - - } - } - - if mapKeyStringSharesBytesBuf && d.bufio { - if ktypeIsString { - rvSetString(rvk, d.detach2Str(kstr2bs, att)) - } else { - rvSetIntf(rvk, rv4istr(d.detach2Str(kstr2bs, att))) - } - mapKeyStringSharesBytesBuf = false - } - - d.mapElemValue() - - if d.d.TryNil() { - if mapKeyStringSharesBytesBuf { - if ktypeIsString { - rvSetString(rvk, d.detach2Str(kstr2bs, att)) - } else { - rvSetIntf(rvk, rv4istr(d.detach2Str(kstr2bs, att))) - } - } - - if !rvvz.IsValid() { - rvvz = rvZeroK(vtype, vtypeKind) - } - mapSet(rv, rvk, rvvz, mparams) - continue - } - - doMapSet = true - - if !rvvMut { - rvv = rvvn - } else if !doMapGet { - goto NEW_RVV - } else { - rvv = mapGet(rv, rvk, rvva, mparams) - if !rvv.IsValid() || (rvvCanNil && rvIsNil(rvv)) { - goto NEW_RVV - } - switch vtypeKind { - case reflect.Ptr, reflect.Map: - doMapSet = false - case reflect.Interface: - - rvvn = rvv.Elem() - if k := rvvn.Kind(); (k == reflect.Ptr || k == reflect.Map) && !rvIsNil(rvvn) { - d.decodeValueNoCheckNil(rvvn, nil) - continue - } - - rvvn = rvZeroAddrK(vtype, vtypeKind) - rvSetIntf(rvvn, rvv) - rvv = rvvn - default: - - if vTransient { - rvvn = d.perType.TransientAddrK(vtype, vtypeKind) - } else { - rvvn = rvZeroAddrK(vtype, vtypeKind) - } - rvSetDirect(rvvn, rvv) - rvv = rvvn - } - } - goto DECODE_VALUE_NO_CHECK_NIL - - NEW_RVV: - if vtypePtr { - rvv = reflect.New(vtypeElem) - } else if vTransient { - rvv = d.perType.TransientAddrK(vtype, vtypeKind) - } else { - rvv = rvZeroAddrK(vtype, vtypeKind) - } - - DECODE_VALUE_NO_CHECK_NIL: - if doMapSet && mapKeyStringSharesBytesBuf { - if ktypeIsString { - rvSetString(rvk, d.detach2Str(kstr2bs, att)) - } else { - rvSetIntf(rvk, rv4istr(d.detach2Str(kstr2bs, att))) - } - } - if vbuiltin { - if vtypePtr { - if rvIsNil(rvv) { - rvSetDirect(rvv, reflect.New(vElem)) - } - d.decode(rv2i(rvv)) - } else { - d.decode(rv2i(rvAddr(rvv, ti.tielem.ptr))) - } - } else { - d.decodeValueNoCheckNil(rvv, valFn) - } - if doMapSet { - mapSet(rv, rvk, rvv, mparams) - } - } - - d.mapEnd() -} - -func (d *decoderSimpleBytes) init(h Handle) { - initHandle(h) - callMake(&d.d) - d.hh = h - d.h = h.getBasicHandle() - - d.err = errDecoderNotInitialized - - if d.h.InternString && d.is == nil { - d.is.init() - } - - d.fp = d.d.init(h, &d.decoderBase, d).(*fastpathDsSimpleBytes) - - if d.bytes { - d.rtidFn = &d.h.rtidFnsDecBytes - d.rtidFnNoExt = &d.h.rtidFnsDecNoExtBytes - } else { - d.bufio = d.h.ReaderBufferSize > 0 - d.rtidFn = &d.h.rtidFnsDecIO - d.rtidFnNoExt = &d.h.rtidFnsDecNoExtIO - } - - d.reset() - -} - -func (d *decoderSimpleBytes) reset() { - d.d.reset() - d.err = nil - d.c = 0 - d.depth = 0 - d.calls = 0 - - d.maxdepth = decDefMaxDepth - if d.h.MaxDepth > 0 { - d.maxdepth = d.h.MaxDepth - } - d.mtid = 0 - d.stid = 0 - d.mtr = false - d.str = false - if d.h.MapType != nil { - d.mtid = rt2id(d.h.MapType) - _, d.mtr = fastpathAvIndex(d.mtid) - } - if d.h.SliceType != nil { - d.stid = rt2id(d.h.SliceType) - _, d.str = fastpathAvIndex(d.stid) - } -} - -func (d *decoderSimpleBytes) Reset(r io.Reader) { - if d.bytes { - halt.onerror(errDecNoResetBytesWithReader) - } - d.reset() - if r == nil { - r = &eofReader - } - d.d.resetInIO(r) -} - -func (d *decoderSimpleBytes) ResetBytes(in []byte) { - if !d.bytes { - halt.onerror(errDecNoResetReaderWithBytes) - } - d.resetBytes(in) -} - -func (d *decoderSimpleBytes) resetBytes(in []byte) { - d.reset() - if in == nil { - in = zeroByteSlice - } - d.d.resetInBytes(in) -} - -func (d *decoderSimpleBytes) ResetString(s string) { - d.ResetBytes(bytesView(s)) -} - -func (d *decoderSimpleBytes) Decode(v interface{}) (err error) { - - defer panicValToErr(d, callRecoverSentinel, &d.err, &err, debugging) - d.mustDecode(v) - return -} - -func (d *decoderSimpleBytes) MustDecode(v interface{}) { - defer panicValToErr(d, callRecoverSentinel, &d.err, nil, true) - d.mustDecode(v) - return -} - -func (d *decoderSimpleBytes) mustDecode(v interface{}) { - halt.onerror(d.err) - if d.hh == nil { - halt.onerror(errNoFormatHandle) - } - - d.calls++ - d.decode(v) - d.calls-- -} - -func (d *decoderSimpleBytes) Release() {} - -func (d *decoderSimpleBytes) swallow() { - d.d.nextValueBytes() -} - -func (d *decoderSimpleBytes) nextValueBytes() []byte { - return d.d.nextValueBytes() -} - -func (d *decoderSimpleBytes) decode(iv interface{}) { - _ = d.d - - rv, ok := isNil(iv, true) - if ok { - halt.onerror(errCannotDecodeIntoNil) - } - - switch v := iv.(type) { - - case *string: - *v = d.detach2Str(d.d.DecodeStringAsBytes()) - case *bool: - *v = d.d.DecodeBool() - case *int: - *v = int(chkOvf.IntV(d.d.DecodeInt64(), intBitsize)) - case *int8: - *v = int8(chkOvf.IntV(d.d.DecodeInt64(), 8)) - case *int16: - *v = int16(chkOvf.IntV(d.d.DecodeInt64(), 16)) - case *int32: - *v = int32(chkOvf.IntV(d.d.DecodeInt64(), 32)) - case *int64: - *v = d.d.DecodeInt64() - case *uint: - *v = uint(chkOvf.UintV(d.d.DecodeUint64(), uintBitsize)) - case *uint8: - *v = uint8(chkOvf.UintV(d.d.DecodeUint64(), 8)) - case *uint16: - *v = uint16(chkOvf.UintV(d.d.DecodeUint64(), 16)) - case *uint32: - *v = uint32(chkOvf.UintV(d.d.DecodeUint64(), 32)) - case *uint64: - *v = d.d.DecodeUint64() - case *uintptr: - *v = uintptr(chkOvf.UintV(d.d.DecodeUint64(), uintBitsize)) - case *float32: - *v = d.d.DecodeFloat32() - case *float64: - *v = d.d.DecodeFloat64() - case *complex64: - *v = complex(d.d.DecodeFloat32(), 0) - case *complex128: - *v = complex(d.d.DecodeFloat64(), 0) - case *[]byte: - *v, _ = d.decodeBytesInto(*v, false) - case []byte: - - d.decodeBytesInto(v[:len(v):len(v)], true) - case *time.Time: - *v = d.d.DecodeTime() - case *Raw: - *v = d.rawBytes() - - case *interface{}: - d.decodeValue(rv4iptr(v), nil) - - case reflect.Value: - if ok, _ = isDecodeable(v); !ok { - d.haltAsNotDecodeable(v) - } - d.decodeValue(v, nil) - - default: - - if skipFastpathTypeSwitchInDirectCall || !d.dh.fastpathDecodeTypeSwitch(iv, d) { - if !rv.IsValid() { - rv = reflect.ValueOf(iv) - } - if ok, _ = isDecodeable(rv); !ok { - d.haltAsNotDecodeable(rv) - } - d.decodeValue(rv, nil) - } - } -} - -func (d *decoderSimpleBytes) decodeValue(rv reflect.Value, fn *decFnSimpleBytes) { - if d.d.TryNil() { - decSetNonNilRV2Zero(rv) - } else { - d.decodeValueNoCheckNil(rv, fn) - } -} - -func (d *decoderSimpleBytes) decodeValueNoCheckNil(rv reflect.Value, fn *decFnSimpleBytes) { - - var rvp reflect.Value - var rvpValid bool -PTR: - if rv.Kind() == reflect.Ptr { - rvpValid = true - if rvIsNil(rv) { - rvSetDirect(rv, reflect.New(rv.Type().Elem())) - } - rvp = rv - rv = rv.Elem() - goto PTR - } - - if fn == nil { - fn = d.fn(rv.Type()) - } - if fn.i.addrD { - if rvpValid { - rv = rvp - } else if rv.CanAddr() { - rv = rvAddr(rv, fn.i.ti.ptr) - } else if fn.i.addrDf { - halt.errorStr("cannot decode into a non-pointer value") - } - } - fn.fd(d, &fn.i, rv) -} - -func (d *decoderSimpleBytes) decodeAs(v interface{}, t reflect.Type, ext bool) { - if ext { - d.decodeValue(baseRV(v), d.fn(t)) - } else { - d.decodeValue(baseRV(v), d.fnNoExt(t)) - } -} - -func (d *decoderSimpleBytes) structFieldNotFound(index int, rvkencname string) { - - if d.h.ErrorIfNoField { - if index >= 0 { - halt.errorInt("no matching struct field found when decoding stream array at index ", int64(index)) - } else if rvkencname != "" { - halt.errorStr2("no matching struct field found when decoding stream map with key ", rvkencname) - } - } - d.swallow() -} - -func (d *decoderSimpleBytes) decodeBytesInto(out []byte, mustFit bool) (v []byte, state dBytesIntoState) { - v, att := d.d.DecodeBytes() - if cap(v) == 0 || (att >= dBytesAttachViewZerocopy && !mustFit) { - - return - } - if len(v) == 0 { - v = zeroByteSlice - return - } - if len(out) == len(v) { - state = dBytesIntoParamOut - } else if cap(out) >= len(v) { - out = out[:len(v)] - state = dBytesIntoParamOutSlice - } else if mustFit { - halt.errorf("bytes capacity insufficient for decoded bytes: got/expected: %d/%d", len(v), len(out)) - } else { - out = make([]byte, len(v)) - state = dBytesIntoNew - } - copy(out, v) - v = out - return -} - -func (d *decoderSimpleBytes) rawBytes() (v []byte) { - - v = d.d.nextValueBytes() - if d.bytes && !d.h.ZeroCopy { - vv := make([]byte, len(v)) - copy(vv, v) - v = vv - } - return -} - -func (d *decoderSimpleBytes) wrapErr(v error, err *error) { - *err = wrapCodecErr(v, d.hh.Name(), d.d.NumBytesRead(), false) -} - -func (d *decoderSimpleBytes) NumBytesRead() int { - return d.d.NumBytesRead() -} - -func (d *decoderSimpleBytes) containerNext(j, containerLen int, hasLen bool) bool { - - if hasLen { - return j < containerLen - } - return !d.d.CheckBreak() -} - -func (d *decoderSimpleBytes) mapElemKey(firstTime bool) { - d.d.ReadMapElemKey(firstTime) - d.c = containerMapKey -} - -func (d *decoderSimpleBytes) mapElemValue() { - d.d.ReadMapElemValue() - d.c = containerMapValue -} - -func (d *decoderSimpleBytes) mapEnd() { - d.d.ReadMapEnd() - d.depthDecr() - d.c = 0 -} - -func (d *decoderSimpleBytes) arrayElem(firstTime bool) { - d.d.ReadArrayElem(firstTime) - d.c = containerArrayElem -} - -func (d *decoderSimpleBytes) arrayEnd() { - d.d.ReadArrayEnd() - d.depthDecr() - d.c = 0 -} - -func (d *decoderSimpleBytes) interfaceExtConvertAndDecode(v interface{}, ext InterfaceExt) { - - var vv interface{} - d.decode(&vv) - ext.UpdateExt(v, vv) - -} - -func (d *decoderSimpleBytes) fn(t reflect.Type) *decFnSimpleBytes { - return d.dh.decFnViaBH(t, d.rtidFn, d.h, d.fp, false) -} - -func (d *decoderSimpleBytes) fnNoExt(t reflect.Type) *decFnSimpleBytes { - return d.dh.decFnViaBH(t, d.rtidFnNoExt, d.h, d.fp, true) -} - -func (helperDecDriverSimpleBytes) newDecoderBytes(in []byte, h Handle) *decoderSimpleBytes { - var c1 decoderSimpleBytes - c1.bytes = true - c1.init(h) - c1.ResetBytes(in) - return &c1 -} - -func (helperDecDriverSimpleBytes) newDecoderIO(in io.Reader, h Handle) *decoderSimpleBytes { - var c1 decoderSimpleBytes - c1.init(h) - c1.Reset(in) - return &c1 -} - -func (helperDecDriverSimpleBytes) decFnloadFastpathUnderlying(ti *typeInfo, fp *fastpathDsSimpleBytes) (f *fastpathDSimpleBytes, u reflect.Type) { - rtid := rt2id(ti.fastpathUnderlying) - idx, ok := fastpathAvIndex(rtid) - if !ok { - return - } - f = &fp[idx] - if uint8(reflect.Array) == ti.kind { - u = reflect.ArrayOf(ti.rt.Len(), ti.elem) - } else { - u = f.rt - } - return -} - -func (helperDecDriverSimpleBytes) decFindRtidFn(s []decRtidFnSimpleBytes, rtid uintptr) (i uint, fn *decFnSimpleBytes) { - - var h uint - var j = uint(len(s)) -LOOP: - if i < j { - h = (i + j) >> 1 - if s[h].rtid < rtid { - i = h + 1 - } else { - j = h - } - goto LOOP - } - if i < uint(len(s)) && s[i].rtid == rtid { - fn = s[i].fn - } - return -} - -func (helperDecDriverSimpleBytes) decFromRtidFnSlice(fns *atomicRtidFnSlice) (s []decRtidFnSimpleBytes) { - if v := fns.load(); v != nil { - s = *(lowLevelToPtr[[]decRtidFnSimpleBytes](v)) - } - return -} - -func (dh helperDecDriverSimpleBytes) decFnViaBH(rt reflect.Type, fns *atomicRtidFnSlice, x *BasicHandle, fp *fastpathDsSimpleBytes, - checkExt bool) (fn *decFnSimpleBytes) { - return dh.decFnVia(rt, fns, x.typeInfos(), &x.mu, x.extHandle, fp, - checkExt, x.CheckCircularRef, x.timeBuiltin, x.binaryHandle, x.jsonHandle) -} - -func (dh helperDecDriverSimpleBytes) decFnVia(rt reflect.Type, fns *atomicRtidFnSlice, - tinfos *TypeInfos, mu *sync.Mutex, exth extHandle, fp *fastpathDsSimpleBytes, - checkExt, checkCircularRef, timeBuiltin, binaryEncoding, json bool) (fn *decFnSimpleBytes) { - rtid := rt2id(rt) - var sp []decRtidFnSimpleBytes = dh.decFromRtidFnSlice(fns) - if sp != nil { - _, fn = dh.decFindRtidFn(sp, rtid) - } - if fn == nil { - fn = dh.decFnViaLoader(rt, rtid, fns, tinfos, mu, exth, fp, checkExt, checkCircularRef, timeBuiltin, binaryEncoding, json) - } - return -} - -func (dh helperDecDriverSimpleBytes) decFnViaLoader(rt reflect.Type, rtid uintptr, fns *atomicRtidFnSlice, - tinfos *TypeInfos, mu *sync.Mutex, exth extHandle, fp *fastpathDsSimpleBytes, - checkExt, checkCircularRef, timeBuiltin, binaryEncoding, json bool) (fn *decFnSimpleBytes) { - - fn = dh.decFnLoad(rt, rtid, tinfos, exth, fp, checkExt, checkCircularRef, timeBuiltin, binaryEncoding, json) - var sp []decRtidFnSimpleBytes - mu.Lock() - sp = dh.decFromRtidFnSlice(fns) - - if sp == nil { - sp = []decRtidFnSimpleBytes{{rtid, fn}} - fns.store(ptrToLowLevel(&sp)) - } else { - idx, fn2 := dh.decFindRtidFn(sp, rtid) - if fn2 == nil { - sp2 := make([]decRtidFnSimpleBytes, len(sp)+1) - copy(sp2[idx+1:], sp[idx:]) - copy(sp2, sp[:idx]) - sp2[idx] = decRtidFnSimpleBytes{rtid, fn} - fns.store(ptrToLowLevel(&sp2)) - } - } - mu.Unlock() - return -} - -func (dh helperDecDriverSimpleBytes) decFnLoad(rt reflect.Type, rtid uintptr, tinfos *TypeInfos, - exth extHandle, fp *fastpathDsSimpleBytes, - checkExt, checkCircularRef, timeBuiltin, binaryEncoding, json bool) (fn *decFnSimpleBytes) { - fn = new(decFnSimpleBytes) - fi := &(fn.i) - ti := tinfos.get(rtid, rt) - fi.ti = ti - rk := reflect.Kind(ti.kind) - - fi.addrDf = true - - if rtid == timeTypId && timeBuiltin { - fn.fd = (*decoderSimpleBytes).kTime - } else if rtid == rawTypId { - fn.fd = (*decoderSimpleBytes).raw - } else if rtid == rawExtTypId { - fn.fd = (*decoderSimpleBytes).rawExt - fi.addrD = true - } else if xfFn := exth.getExt(rtid, checkExt); xfFn != nil { - fi.xfTag, fi.xfFn = xfFn.tag, xfFn.ext - fn.fd = (*decoderSimpleBytes).ext - fi.addrD = true - } else if ti.flagSelfer || ti.flagSelferPtr { - fn.fd = (*decoderSimpleBytes).selferUnmarshal - fi.addrD = ti.flagSelferPtr - } else if supportMarshalInterfaces && binaryEncoding && - (ti.flagBinaryMarshaler || ti.flagBinaryMarshalerPtr) && - (ti.flagBinaryUnmarshaler || ti.flagBinaryUnmarshalerPtr) { - fn.fd = (*decoderSimpleBytes).binaryUnmarshal - fi.addrD = ti.flagBinaryUnmarshalerPtr - } else if supportMarshalInterfaces && !binaryEncoding && json && - (ti.flagJsonMarshaler || ti.flagJsonMarshalerPtr) && - (ti.flagJsonUnmarshaler || ti.flagJsonUnmarshalerPtr) { - - fn.fd = (*decoderSimpleBytes).jsonUnmarshal - fi.addrD = ti.flagJsonUnmarshalerPtr - } else if supportMarshalInterfaces && !binaryEncoding && - (ti.flagTextMarshaler || ti.flagTextMarshalerPtr) && - (ti.flagTextUnmarshaler || ti.flagTextUnmarshalerPtr) { - fn.fd = (*decoderSimpleBytes).textUnmarshal - fi.addrD = ti.flagTextUnmarshalerPtr - } else { - if fastpathEnabled && (rk == reflect.Map || rk == reflect.Slice || rk == reflect.Array) { - var rtid2 uintptr - if !ti.flagHasPkgPath { - rtid2 = rtid - if rk == reflect.Array { - rtid2 = rt2id(ti.key) - } - if idx, ok := fastpathAvIndex(rtid2); ok { - fn.fd = fp[idx].decfn - fi.addrD = true - fi.addrDf = false - if rk == reflect.Array { - fi.addrD = false - } - } - } else { - - xfe, xrt := dh.decFnloadFastpathUnderlying(ti, fp) - if xfe != nil { - xfnf2 := xfe.decfn - if rk == reflect.Array { - fi.addrD = false - fn.fd = func(d *decoderSimpleBytes, xf *decFnInfo, xrv reflect.Value) { - xfnf2(d, xf, rvConvert(xrv, xrt)) - } - } else { - fi.addrD = true - fi.addrDf = false - xptr2rt := reflect.PointerTo(xrt) - fn.fd = func(d *decoderSimpleBytes, xf *decFnInfo, xrv reflect.Value) { - if xrv.Kind() == reflect.Ptr { - xfnf2(d, xf, rvConvert(xrv, xptr2rt)) - } else { - xfnf2(d, xf, rvConvert(xrv, xrt)) - } - } - } - } - } - } - if fn.fd == nil { - switch rk { - case reflect.Bool: - fn.fd = (*decoderSimpleBytes).kBool - case reflect.String: - fn.fd = (*decoderSimpleBytes).kString - case reflect.Int: - fn.fd = (*decoderSimpleBytes).kInt - case reflect.Int8: - fn.fd = (*decoderSimpleBytes).kInt8 - case reflect.Int16: - fn.fd = (*decoderSimpleBytes).kInt16 - case reflect.Int32: - fn.fd = (*decoderSimpleBytes).kInt32 - case reflect.Int64: - fn.fd = (*decoderSimpleBytes).kInt64 - case reflect.Uint: - fn.fd = (*decoderSimpleBytes).kUint - case reflect.Uint8: - fn.fd = (*decoderSimpleBytes).kUint8 - case reflect.Uint16: - fn.fd = (*decoderSimpleBytes).kUint16 - case reflect.Uint32: - fn.fd = (*decoderSimpleBytes).kUint32 - case reflect.Uint64: - fn.fd = (*decoderSimpleBytes).kUint64 - case reflect.Uintptr: - fn.fd = (*decoderSimpleBytes).kUintptr - case reflect.Float32: - fn.fd = (*decoderSimpleBytes).kFloat32 - case reflect.Float64: - fn.fd = (*decoderSimpleBytes).kFloat64 - case reflect.Complex64: - fn.fd = (*decoderSimpleBytes).kComplex64 - case reflect.Complex128: - fn.fd = (*decoderSimpleBytes).kComplex128 - case reflect.Chan: - fn.fd = (*decoderSimpleBytes).kChan - case reflect.Slice: - fn.fd = (*decoderSimpleBytes).kSlice - case reflect.Array: - fi.addrD = false - fn.fd = (*decoderSimpleBytes).kArray - case reflect.Struct: - if ti.simple { - fn.fd = (*decoderSimpleBytes).kStructSimple - } else { - fn.fd = (*decoderSimpleBytes).kStruct - } - case reflect.Map: - fn.fd = (*decoderSimpleBytes).kMap - case reflect.Interface: - - fn.fd = (*decoderSimpleBytes).kInterface - default: - - fn.fd = (*decoderSimpleBytes).kErr - } - } - } - return -} -func (e *simpleEncDriverBytes) EncodeNil() { - e.w.writen1(simpleVdNil) -} - -func (e *simpleEncDriverBytes) EncodeBool(b bool) { - if e.h.EncZeroValuesAsNil && e.e.c != containerMapKey && !b { - e.EncodeNil() - return - } - if b { - e.w.writen1(simpleVdTrue) - } else { - e.w.writen1(simpleVdFalse) - } -} - -func (e *simpleEncDriverBytes) EncodeFloat32(f float32) { - if e.h.EncZeroValuesAsNil && e.e.c != containerMapKey && f == 0.0 { - e.EncodeNil() - return - } - e.w.writen1(simpleVdFloat32) - e.w.writen4(bigen.PutUint32(math.Float32bits(f))) -} - -func (e *simpleEncDriverBytes) EncodeFloat64(f float64) { - if e.h.EncZeroValuesAsNil && e.e.c != containerMapKey && f == 0.0 { - e.EncodeNil() - return - } - e.w.writen1(simpleVdFloat64) - e.w.writen8(bigen.PutUint64(math.Float64bits(f))) -} - -func (e *simpleEncDriverBytes) EncodeInt(v int64) { - if v < 0 { - e.encUint(uint64(-v), simpleVdNegInt) - } else { - e.encUint(uint64(v), simpleVdPosInt) - } -} - -func (e *simpleEncDriverBytes) EncodeUint(v uint64) { - e.encUint(v, simpleVdPosInt) -} - -func (e *simpleEncDriverBytes) encUint(v uint64, bd uint8) { - if e.h.EncZeroValuesAsNil && e.e.c != containerMapKey && v == 0 { - e.EncodeNil() - return - } - if v <= math.MaxUint8 { - e.w.writen2(bd, uint8(v)) - } else if v <= math.MaxUint16 { - e.w.writen1(bd + 1) - e.w.writen2(bigen.PutUint16(uint16(v))) - } else if v <= math.MaxUint32 { - e.w.writen1(bd + 2) - e.w.writen4(bigen.PutUint32(uint32(v))) - } else { - e.w.writen1(bd + 3) - e.w.writen8(bigen.PutUint64(v)) - } -} - -func (e *simpleEncDriverBytes) encLen(bd byte, length int) { - if length == 0 { - e.w.writen1(bd) - } else if length <= math.MaxUint8 { - e.w.writen1(bd + 1) - e.w.writen1(uint8(length)) - } else if length <= math.MaxUint16 { - e.w.writen1(bd + 2) - e.w.writen2(bigen.PutUint16(uint16(length))) - } else if int64(length) <= math.MaxUint32 { - e.w.writen1(bd + 3) - e.w.writen4(bigen.PutUint32(uint32(length))) - } else { - e.w.writen1(bd + 4) - e.w.writen8(bigen.PutUint64(uint64(length))) - } -} - -func (e *simpleEncDriverBytes) EncodeExt(v interface{}, basetype reflect.Type, xtag uint64, ext Ext) { - var bs0, bs []byte - if ext == SelfExt { - bs0 = e.e.blist.get(1024) - bs = bs0 - sideEncode(e.h, &e.h.sideEncPool, func(se encoderI) { oneOffEncode(se, v, &bs, basetype, true) }) - } else { - bs = ext.WriteExt(v) - } - if bs == nil { - e.writeNilBytes() - goto END - } - e.encodeExtPreamble(uint8(xtag), len(bs)) - e.w.writeb(bs) -END: - if ext == SelfExt { - e.e.blist.put(bs) - if !byteSliceSameData(bs0, bs) { - e.e.blist.put(bs0) - } - } -} - -func (e *simpleEncDriverBytes) EncodeRawExt(re *RawExt) { - e.encodeExtPreamble(uint8(re.Tag), len(re.Data)) - e.w.writeb(re.Data) -} - -func (e *simpleEncDriverBytes) encodeExtPreamble(xtag byte, length int) { - e.encLen(simpleVdExt, length) - e.w.writen1(xtag) -} - -func (e *simpleEncDriverBytes) WriteArrayStart(length int) { - e.encLen(simpleVdArray, length) -} - -func (e *simpleEncDriverBytes) WriteMapStart(length int) { - e.encLen(simpleVdMap, length) -} - -func (e *simpleEncDriverBytes) WriteArrayEmpty() { - - e.w.writen1(simpleVdArray) -} - -func (e *simpleEncDriverBytes) WriteMapEmpty() { - - e.w.writen1(simpleVdMap) -} - -func (e *simpleEncDriverBytes) EncodeString(v string) { - if e.h.EncZeroValuesAsNil && e.e.c != containerMapKey && v == "" { - e.EncodeNil() - return - } - if e.h.StringToRaw { - e.encLen(simpleVdByteArray, len(v)) - } else { - e.encLen(simpleVdString, len(v)) - } - e.w.writestr(v) -} - -func (e *simpleEncDriverBytes) EncodeStringNoEscape4Json(v string) { e.EncodeString(v) } - -func (e *simpleEncDriverBytes) EncodeStringBytesRaw(v []byte) { - - e.encLen(simpleVdByteArray, len(v)) - e.w.writeb(v) -} - -func (e *simpleEncDriverBytes) EncodeBytes(v []byte) { - if v == nil { - e.writeNilBytes() - return - } - e.EncodeStringBytesRaw(v) -} - -func (e *simpleEncDriverBytes) encodeNilBytes() { - b := byte(simpleVdNil) - if e.h.NilCollectionToZeroLength { - b = simpleVdArray - } - e.w.writen1(b) -} - -func (e *simpleEncDriverBytes) writeNilOr(v byte) { - if !e.h.NilCollectionToZeroLength { - v = simpleVdNil - } - e.w.writen1(v) -} - -func (e *simpleEncDriverBytes) writeNilArray() { - e.writeNilOr(simpleVdArray) -} - -func (e *simpleEncDriverBytes) writeNilMap() { - e.writeNilOr(simpleVdMap) -} - -func (e *simpleEncDriverBytes) writeNilBytes() { - e.writeNilOr(simpleVdByteArray) -} - -func (e *simpleEncDriverBytes) EncodeTime(t time.Time) { - - if t.IsZero() { - e.EncodeNil() - return - } - v, err := t.MarshalBinary() - halt.onerror(err) - e.w.writen2(simpleVdTime, uint8(len(v))) - e.w.writeb(v) -} - -func (d *simpleDecDriverBytes) readNextBd() { - d.bd = d.r.readn1() - d.bdRead = true -} - -func (d *simpleDecDriverBytes) advanceNil() (null bool) { - if !d.bdRead { - d.readNextBd() - } - if d.bd == simpleVdNil { - d.bdRead = false - return true - } - return -} - -func (d *simpleDecDriverBytes) ContainerType() (vt valueType) { - if !d.bdRead { - d.readNextBd() - } - switch d.bd { - case simpleVdNil: - d.bdRead = false - return valueTypeNil - case simpleVdByteArray, simpleVdByteArray + 1, - simpleVdByteArray + 2, simpleVdByteArray + 3, simpleVdByteArray + 4: - return valueTypeBytes - case simpleVdString, simpleVdString + 1, - simpleVdString + 2, simpleVdString + 3, simpleVdString + 4: - return valueTypeString - case simpleVdArray, simpleVdArray + 1, - simpleVdArray + 2, simpleVdArray + 3, simpleVdArray + 4: - return valueTypeArray - case simpleVdMap, simpleVdMap + 1, - simpleVdMap + 2, simpleVdMap + 3, simpleVdMap + 4: - return valueTypeMap - } - return valueTypeUnset -} - -func (d *simpleDecDriverBytes) TryNil() bool { - return d.advanceNil() -} - -func (d *simpleDecDriverBytes) decFloat() (f float64, ok bool) { - ok = true - switch d.bd { - case simpleVdFloat32: - f = float64(math.Float32frombits(bigen.Uint32(d.r.readn4()))) - case simpleVdFloat64: - f = math.Float64frombits(bigen.Uint64(d.r.readn8())) - default: - ok = false - } - return -} - -func (d *simpleDecDriverBytes) decInteger() (ui uint64, neg, ok bool) { - ok = true - switch d.bd { - case simpleVdPosInt: - ui = uint64(d.r.readn1()) - case simpleVdPosInt + 1: - ui = uint64(bigen.Uint16(d.r.readn2())) - case simpleVdPosInt + 2: - ui = uint64(bigen.Uint32(d.r.readn4())) - case simpleVdPosInt + 3: - ui = uint64(bigen.Uint64(d.r.readn8())) - case simpleVdNegInt: - ui = uint64(d.r.readn1()) - neg = true - case simpleVdNegInt + 1: - ui = uint64(bigen.Uint16(d.r.readn2())) - neg = true - case simpleVdNegInt + 2: - ui = uint64(bigen.Uint32(d.r.readn4())) - neg = true - case simpleVdNegInt + 3: - ui = uint64(bigen.Uint64(d.r.readn8())) - neg = true - default: - ok = false - - } - - return -} - -func (d *simpleDecDriverBytes) DecodeInt64() (i int64) { - if d.advanceNil() { - return - } - v1, v2, v3 := d.decInteger() - i = decNegintPosintFloatNumberHelper{d}.int64(v1, v2, v3, false) - d.bdRead = false - return -} - -func (d *simpleDecDriverBytes) DecodeUint64() (ui uint64) { - if d.advanceNil() { - return - } - ui = decNegintPosintFloatNumberHelper{d}.uint64(d.decInteger()) - d.bdRead = false - return -} - -func (d *simpleDecDriverBytes) DecodeFloat64() (f float64) { - if d.advanceNil() { - return - } - v1, v2 := d.decFloat() - f = decNegintPosintFloatNumberHelper{d}.float64(v1, v2, false) - d.bdRead = false - return -} - -func (d *simpleDecDriverBytes) DecodeBool() (b bool) { - if d.advanceNil() { - return - } - if d.bd == simpleVdFalse { - } else if d.bd == simpleVdTrue { - b = true - } else { - halt.errorf("cannot decode bool - %s: %x", msgBadDesc, d.bd) - } - d.bdRead = false - return -} - -func (d *simpleDecDriverBytes) ReadMapStart() (length int) { - if d.advanceNil() { - return containerLenNil - } - d.bdRead = false - return d.decLen() -} - -func (d *simpleDecDriverBytes) ReadArrayStart() (length int) { - if d.advanceNil() { - return containerLenNil - } - d.bdRead = false - return d.decLen() -} - -func (d *simpleDecDriverBytes) uint2Len(ui uint64) int { - if chkOvf.Uint(ui, intBitsize) { - halt.errorf("overflow integer: %v", ui) - } - return int(ui) -} - -func (d *simpleDecDriverBytes) decLen() int { - switch d.bd & 7 { - case 0: - return 0 - case 1: - return int(d.r.readn1()) - case 2: - return int(bigen.Uint16(d.r.readn2())) - case 3: - return d.uint2Len(uint64(bigen.Uint32(d.r.readn4()))) - case 4: - return d.uint2Len(bigen.Uint64(d.r.readn8())) - } - halt.errorf("cannot read length: bd%%8 must be in range 0..4. Got: %d", d.bd%8) - return -1 -} - -func (d *simpleDecDriverBytes) DecodeStringAsBytes() ([]byte, dBytesAttachState) { - return d.DecodeBytes() -} - -func (d *simpleDecDriverBytes) DecodeBytes() (bs []byte, state dBytesAttachState) { - if d.advanceNil() { - return - } - var cond bool - - if d.bd >= simpleVdArray && d.bd <= simpleVdArray+4 { - slen := d.ReadArrayStart() - bs, cond = usableByteSlice(d.d.buf, slen) - for i := 0; i < len(bs); i++ { - bs[i] = uint8(chkOvf.UintV(d.DecodeUint64(), 8)) - } - for i := len(bs); i < slen; i++ { - bs = append(bs, uint8(chkOvf.UintV(d.DecodeUint64(), 8))) - } - if cond { - d.d.buf = bs - } - state = dBytesAttachBuffer - - return - } - - clen := d.decLen() - d.bdRead = false - bs, cond = d.r.readxb(uint(clen)) - state = d.d.attachState(cond) - return -} - -func (d *simpleDecDriverBytes) DecodeTime() (t time.Time) { - if d.advanceNil() { - return - } - if d.bd != simpleVdTime { - halt.errorf("invalid descriptor for time.Time - expect 0x%x, received 0x%x", simpleVdTime, d.bd) - } - d.bdRead = false - clen := uint(d.r.readn1()) - b := d.r.readx(clen) - halt.onerror((&t).UnmarshalBinary(b)) - return -} - -func (d *simpleDecDriverBytes) DecodeExt(rv interface{}, basetype reflect.Type, xtag uint64, ext Ext) { - xbs, _, _, ok := d.decodeExtV(ext != nil, xtag) - if !ok { - return - } - if ext == SelfExt { - sideDecode(d.h, &d.h.sideDecPool, func(sd decoderI) { oneOffDecode(sd, rv, xbs, basetype, true) }) - } else { - ext.ReadExt(rv, xbs) - } -} - -func (d *simpleDecDriverBytes) DecodeRawExt(re *RawExt) { - xbs, realxtag, state, ok := d.decodeExtV(false, 0) - if !ok { - return - } - re.Tag = uint64(realxtag) - re.setData(xbs, state >= dBytesAttachViewZerocopy) -} - -func (d *simpleDecDriverBytes) decodeExtV(verifyTag bool, xtagIn uint64) (xbs []byte, xtag byte, bstate dBytesAttachState, ok bool) { - if xtagIn > 0xff { - halt.errorf("ext: tag must be <= 0xff; got: %v", xtagIn) - } - if d.advanceNil() { - return - } - tag := uint8(xtagIn) - switch d.bd { - case simpleVdExt, simpleVdExt + 1, simpleVdExt + 2, simpleVdExt + 3, simpleVdExt + 4: - l := d.decLen() - xtag = d.r.readn1() - if verifyTag && xtag != tag { - halt.errorf("wrong extension tag. Got %b. Expecting: %v", xtag, tag) - } - xbs, ok = d.r.readxb(uint(l)) - bstate = d.d.attachState(ok) - case simpleVdByteArray, simpleVdByteArray + 1, - simpleVdByteArray + 2, simpleVdByteArray + 3, simpleVdByteArray + 4: - xbs, bstate = d.DecodeBytes() - default: - halt.errorf("ext - %s - expecting extensions/bytearray, got: 0x%x", msgBadDesc, d.bd) - } - d.bdRead = false - ok = true - return -} - -func (d *simpleDecDriverBytes) DecodeNaked() { - if !d.bdRead { - d.readNextBd() - } - - n := d.d.naked() - var decodeFurther bool - - switch d.bd { - case simpleVdNil: - n.v = valueTypeNil - case simpleVdFalse: - n.v = valueTypeBool - n.b = false - case simpleVdTrue: - n.v = valueTypeBool - n.b = true - case simpleVdPosInt, simpleVdPosInt + 1, simpleVdPosInt + 2, simpleVdPosInt + 3: - if d.h.SignedInteger { - n.v = valueTypeInt - n.i = d.DecodeInt64() - } else { - n.v = valueTypeUint - n.u = d.DecodeUint64() - } - case simpleVdNegInt, simpleVdNegInt + 1, simpleVdNegInt + 2, simpleVdNegInt + 3: - n.v = valueTypeInt - n.i = d.DecodeInt64() - case simpleVdFloat32: - n.v = valueTypeFloat - n.f = d.DecodeFloat64() - case simpleVdFloat64: - n.v = valueTypeFloat - n.f = d.DecodeFloat64() - case simpleVdTime: - n.v = valueTypeTime - n.t = d.DecodeTime() - case simpleVdString, simpleVdString + 1, - simpleVdString + 2, simpleVdString + 3, simpleVdString + 4: - n.v = valueTypeString - n.s = d.d.detach2Str(d.DecodeStringAsBytes()) - case simpleVdByteArray, simpleVdByteArray + 1, - simpleVdByteArray + 2, simpleVdByteArray + 3, simpleVdByteArray + 4: - d.d.fauxUnionReadRawBytes(d, false, d.h.RawToString) - case simpleVdExt, simpleVdExt + 1, simpleVdExt + 2, simpleVdExt + 3, simpleVdExt + 4: - n.v = valueTypeExt - l := d.decLen() - n.u = uint64(d.r.readn1()) - n.l = d.r.readx(uint(l)) - - case simpleVdArray, simpleVdArray + 1, simpleVdArray + 2, - simpleVdArray + 3, simpleVdArray + 4: - n.v = valueTypeArray - decodeFurther = true - case simpleVdMap, simpleVdMap + 1, simpleVdMap + 2, simpleVdMap + 3, simpleVdMap + 4: - n.v = valueTypeMap - decodeFurther = true - default: - halt.errorf("cannot infer value - %s 0x%x", msgBadDesc, d.bd) - } - - if !decodeFurther { - d.bdRead = false - } -} - -func (d *simpleDecDriverBytes) nextValueBytes() (v []byte) { - if !d.bdRead { - d.readNextBd() - } - d.r.startRecording() - d.nextValueBytesBdReadR() - v = d.r.stopRecording() - d.bdRead = false - return -} - -func (d *simpleDecDriverBytes) nextValueBytesBdReadR() { - c := d.bd - - var length uint - - switch c { - case simpleVdNil, simpleVdFalse, simpleVdTrue, simpleVdString, simpleVdByteArray: - - case simpleVdPosInt, simpleVdNegInt: - d.r.readn1() - case simpleVdPosInt + 1, simpleVdNegInt + 1: - d.r.skip(2) - case simpleVdPosInt + 2, simpleVdNegInt + 2, simpleVdFloat32: - d.r.skip(4) - case simpleVdPosInt + 3, simpleVdNegInt + 3, simpleVdFloat64: - d.r.skip(8) - case simpleVdTime: - c = d.r.readn1() - d.r.skip(uint(c)) - - default: - switch c & 7 { - case 0: - length = 0 - case 1: - b := d.r.readn1() - length = uint(b) - case 2: - x := d.r.readn2() - length = uint(bigen.Uint16(x)) - case 3: - x := d.r.readn4() - length = uint(bigen.Uint32(x)) - case 4: - x := d.r.readn8() - length = uint(bigen.Uint64(x)) - } - - bExt := c >= simpleVdExt && c <= simpleVdExt+7 - bStr := c >= simpleVdString && c <= simpleVdString+7 - bByteArray := c >= simpleVdByteArray && c <= simpleVdByteArray+7 - bArray := c >= simpleVdArray && c <= simpleVdArray+7 - bMap := c >= simpleVdMap && c <= simpleVdMap+7 - - if !(bExt || bStr || bByteArray || bArray || bMap) { - halt.errorf("cannot infer value - %s 0x%x", msgBadDesc, c) - } - - if bExt { - d.r.readn1() - } - - if length == 0 { - break - } - - if bArray { - for i := uint(0); i < length; i++ { - d.readNextBd() - d.nextValueBytesBdReadR() - } - } else if bMap { - for i := uint(0); i < length; i++ { - d.readNextBd() - d.nextValueBytesBdReadR() - d.readNextBd() - d.nextValueBytesBdReadR() - } - } else { - d.r.skip(length) - } - } - return -} - -func (d *simpleEncDriverBytes) init(hh Handle, shared *encoderBase, enc encoderI) (fp interface{}) { - callMake(&d.w) - d.h = hh.(*SimpleHandle) - d.e = shared - if shared.bytes { - fp = simpleFpEncBytes - } else { - fp = simpleFpEncIO - } - - d.init2(enc) - return -} - -func (e *simpleEncDriverBytes) writeBytesAsis(b []byte) { e.w.writeb(b) } - -func (e *simpleEncDriverBytes) writerEnd() { e.w.end() } - -func (e *simpleEncDriverBytes) resetOutBytes(out *[]byte) { - e.w.resetBytes(*out, out) -} - -func (e *simpleEncDriverBytes) resetOutIO(out io.Writer) { - e.w.resetIO(out, e.h.WriterBufferSize, &e.e.blist) -} - -func (d *simpleDecDriverBytes) init(hh Handle, shared *decoderBase, dec decoderI) (fp interface{}) { - callMake(&d.r) - d.h = hh.(*SimpleHandle) - d.d = shared - if shared.bytes { - fp = simpleFpDecBytes - } else { - fp = simpleFpDecIO - } - - d.init2(dec) - return -} - -func (d *simpleDecDriverBytes) NumBytesRead() int { - return int(d.r.numread()) -} - -func (d *simpleDecDriverBytes) resetInBytes(in []byte) { - d.r.resetBytes(in) -} - -func (d *simpleDecDriverBytes) resetInIO(r io.Reader) { - d.r.resetIO(r, d.h.ReaderBufferSize, d.h.MaxInitLen, &d.d.blist) -} - -func (d *simpleDecDriverBytes) descBd() string { - return sprintf("%v (%s)", d.bd, simpledesc(d.bd)) -} - -func (d *simpleDecDriverBytes) DecodeFloat32() (f float32) { - return float32(chkOvf.Float32V(d.DecodeFloat64())) -} - -type helperEncDriverSimpleIO struct{} -type encFnSimpleIO struct { - i encFnInfo - fe func(*encoderSimpleIO, *encFnInfo, reflect.Value) -} -type encRtidFnSimpleIO struct { - rtid uintptr - fn *encFnSimpleIO -} -type encoderSimpleIO struct { - dh helperEncDriverSimpleIO - fp *fastpathEsSimpleIO - e simpleEncDriverIO - encoderBase -} -type helperDecDriverSimpleIO struct{} -type decFnSimpleIO struct { - i decFnInfo - fd func(*decoderSimpleIO, *decFnInfo, reflect.Value) -} -type decRtidFnSimpleIO struct { - rtid uintptr - fn *decFnSimpleIO -} -type decoderSimpleIO struct { - dh helperDecDriverSimpleIO - fp *fastpathDsSimpleIO - d simpleDecDriverIO - decoderBase -} -type simpleEncDriverIO struct { - noBuiltInTypes - encDriverNoopContainerWriter - encDriverNoState - encDriverContainerNoTrackerT - encInit2er - - h *SimpleHandle - e *encoderBase - - w bufioEncWriter -} -type simpleDecDriverIO struct { - h *SimpleHandle - d *decoderBase - r ioDecReader - - bdAndBdread - - noBuiltInTypes - - decDriverNoopContainerReader - decInit2er -} - -func (e *encoderSimpleIO) rawExt(_ *encFnInfo, rv reflect.Value) { - if re := rv2i(rv).(*RawExt); re == nil { - e.e.EncodeNil() - } else { - e.e.EncodeRawExt(re) - } -} - -func (e *encoderSimpleIO) ext(f *encFnInfo, rv reflect.Value) { - e.e.EncodeExt(rv2i(rv), f.ti.rt, f.xfTag, f.xfFn) -} - -func (e *encoderSimpleIO) selferMarshal(_ *encFnInfo, rv reflect.Value) { - rv2i(rv).(Selfer).CodecEncodeSelf(&Encoder{e}) -} - -func (e *encoderSimpleIO) binaryMarshal(_ *encFnInfo, rv reflect.Value) { - bs, fnerr := rv2i(rv).(encoding.BinaryMarshaler).MarshalBinary() - e.marshalRaw(bs, fnerr) -} - -func (e *encoderSimpleIO) textMarshal(_ *encFnInfo, rv reflect.Value) { - bs, fnerr := rv2i(rv).(encoding.TextMarshaler).MarshalText() - e.marshalUtf8(bs, fnerr) -} - -func (e *encoderSimpleIO) jsonMarshal(_ *encFnInfo, rv reflect.Value) { - bs, fnerr := rv2i(rv).(jsonMarshaler).MarshalJSON() - e.marshalAsis(bs, fnerr) -} - -func (e *encoderSimpleIO) raw(_ *encFnInfo, rv reflect.Value) { - e.rawBytes(rv2i(rv).(Raw)) -} - -func (e *encoderSimpleIO) encodeComplex64(v complex64) { - if imag(v) != 0 { - halt.errorf("cannot encode complex number: %v, with imaginary values: %v", any(v), any(imag(v))) - } - e.e.EncodeFloat32(real(v)) -} - -func (e *encoderSimpleIO) encodeComplex128(v complex128) { - if imag(v) != 0 { - halt.errorf("cannot encode complex number: %v, with imaginary values: %v", any(v), any(imag(v))) - } - e.e.EncodeFloat64(real(v)) -} - -func (e *encoderSimpleIO) kBool(_ *encFnInfo, rv reflect.Value) { - e.e.EncodeBool(rvGetBool(rv)) -} - -func (e *encoderSimpleIO) kTime(_ *encFnInfo, rv reflect.Value) { - e.e.EncodeTime(rvGetTime(rv)) -} - -func (e *encoderSimpleIO) kString(_ *encFnInfo, rv reflect.Value) { - e.e.EncodeString(rvGetString(rv)) -} - -func (e *encoderSimpleIO) kFloat32(_ *encFnInfo, rv reflect.Value) { - e.e.EncodeFloat32(rvGetFloat32(rv)) -} - -func (e *encoderSimpleIO) kFloat64(_ *encFnInfo, rv reflect.Value) { - e.e.EncodeFloat64(rvGetFloat64(rv)) -} - -func (e *encoderSimpleIO) kComplex64(_ *encFnInfo, rv reflect.Value) { - e.encodeComplex64(rvGetComplex64(rv)) -} - -func (e *encoderSimpleIO) kComplex128(_ *encFnInfo, rv reflect.Value) { - e.encodeComplex128(rvGetComplex128(rv)) -} - -func (e *encoderSimpleIO) kInt(_ *encFnInfo, rv reflect.Value) { - e.e.EncodeInt(int64(rvGetInt(rv))) -} - -func (e *encoderSimpleIO) kInt8(_ *encFnInfo, rv reflect.Value) { - e.e.EncodeInt(int64(rvGetInt8(rv))) -} - -func (e *encoderSimpleIO) kInt16(_ *encFnInfo, rv reflect.Value) { - e.e.EncodeInt(int64(rvGetInt16(rv))) -} - -func (e *encoderSimpleIO) kInt32(_ *encFnInfo, rv reflect.Value) { - e.e.EncodeInt(int64(rvGetInt32(rv))) -} - -func (e *encoderSimpleIO) kInt64(_ *encFnInfo, rv reflect.Value) { - e.e.EncodeInt(int64(rvGetInt64(rv))) -} - -func (e *encoderSimpleIO) kUint(_ *encFnInfo, rv reflect.Value) { - e.e.EncodeUint(uint64(rvGetUint(rv))) -} - -func (e *encoderSimpleIO) kUint8(_ *encFnInfo, rv reflect.Value) { - e.e.EncodeUint(uint64(rvGetUint8(rv))) -} - -func (e *encoderSimpleIO) kUint16(_ *encFnInfo, rv reflect.Value) { - e.e.EncodeUint(uint64(rvGetUint16(rv))) -} - -func (e *encoderSimpleIO) kUint32(_ *encFnInfo, rv reflect.Value) { - e.e.EncodeUint(uint64(rvGetUint32(rv))) -} - -func (e *encoderSimpleIO) kUint64(_ *encFnInfo, rv reflect.Value) { - e.e.EncodeUint(uint64(rvGetUint64(rv))) -} - -func (e *encoderSimpleIO) kUintptr(_ *encFnInfo, rv reflect.Value) { - e.e.EncodeUint(uint64(rvGetUintptr(rv))) -} - -func (e *encoderSimpleIO) kSeqFn(rt reflect.Type) (fn *encFnSimpleIO) { - - if rt = baseRT(rt); rt.Kind() != reflect.Interface { - fn = e.fn(rt) - } - return -} - -func (e *encoderSimpleIO) kArrayWMbs(rv reflect.Value, ti *typeInfo, isSlice bool) { - var l int - if isSlice { - l = rvLenSlice(rv) - } else { - l = rv.Len() - } - if l == 0 { - e.e.WriteMapEmpty() - return - } - e.haltOnMbsOddLen(l) - e.mapStart(l >> 1) - - var fn *encFnSimpleIO - builtin := ti.tielem.flagEncBuiltin - if !builtin { - fn = e.kSeqFn(ti.elem) - } - - j := 0 - e.c = containerMapKey - e.e.WriteMapElemKey(true) - for { - rvv := rvArrayIndex(rv, j, ti, isSlice) - if builtin { - e.encodeIB(rv2i(baseRVRV(rvv))) - } else { - e.encodeValue(rvv, fn) - } - j++ - if j == l { - break - } - if j&1 == 0 { - e.c = containerMapKey - e.e.WriteMapElemKey(false) - } else { - e.mapElemValue() - } - } - e.c = 0 - e.e.WriteMapEnd() - -} - -func (e *encoderSimpleIO) kArrayW(rv reflect.Value, ti *typeInfo, isSlice bool) { - var l int - if isSlice { - l = rvLenSlice(rv) - } else { - l = rv.Len() - } - if l <= 0 { - e.e.WriteArrayEmpty() - return - } - e.arrayStart(l) - - var fn *encFnSimpleIO - if !ti.tielem.flagEncBuiltin { - fn = e.kSeqFn(ti.elem) - } - - j := 0 - e.c = containerArrayElem - e.e.WriteArrayElem(true) - builtin := ti.tielem.flagEncBuiltin - for { - rvv := rvArrayIndex(rv, j, ti, isSlice) - if builtin { - e.encodeIB(rv2i(baseRVRV(rvv))) - } else { - e.encodeValue(rvv, fn) - } - j++ - if j == l { - break - } - e.c = containerArrayElem - e.e.WriteArrayElem(false) - } - - e.c = 0 - e.e.WriteArrayEnd() -} - -func (e *encoderSimpleIO) kChan(f *encFnInfo, rv reflect.Value) { - if f.ti.chandir&uint8(reflect.RecvDir) == 0 { - halt.errorStr("send-only channel cannot be encoded") - } - if !f.ti.mbs && uint8TypId == rt2id(f.ti.elem) { - e.kSliceBytesChan(rv) - return - } - rtslice := reflect.SliceOf(f.ti.elem) - rv = chanToSlice(rv, rtslice, e.h.ChanRecvTimeout) - ti := e.h.getTypeInfo(rt2id(rtslice), rtslice) - if f.ti.mbs { - e.kArrayWMbs(rv, ti, true) - } else { - e.kArrayW(rv, ti, true) - } -} - -func (e *encoderSimpleIO) kSlice(f *encFnInfo, rv reflect.Value) { - if f.ti.mbs { - e.kArrayWMbs(rv, f.ti, true) - } else if f.ti.rtid == uint8SliceTypId || uint8TypId == rt2id(f.ti.elem) { - - e.e.EncodeBytes(rvGetBytes(rv)) - } else { - e.kArrayW(rv, f.ti, true) - } -} - -func (e *encoderSimpleIO) kArray(f *encFnInfo, rv reflect.Value) { - if f.ti.mbs { - e.kArrayWMbs(rv, f.ti, false) - } else if handleBytesWithinKArray && uint8TypId == rt2id(f.ti.elem) { - e.e.EncodeStringBytesRaw(rvGetArrayBytes(rv, nil)) - } else { - e.kArrayW(rv, f.ti, false) - } -} - -func (e *encoderSimpleIO) kSliceBytesChan(rv reflect.Value) { - - bs0 := e.blist.peek(32, true) - bs := bs0 - - irv := rv2i(rv) - ch, ok := irv.(<-chan byte) - if !ok { - ch = irv.(chan byte) - } - -L1: - switch timeout := e.h.ChanRecvTimeout; { - case timeout == 0: - for { - select { - case b := <-ch: - bs = append(bs, b) - default: - break L1 - } - } - case timeout > 0: - tt := time.NewTimer(timeout) - for { - select { - case b := <-ch: - bs = append(bs, b) - case <-tt.C: - - break L1 - } - } - default: - for b := range ch { - bs = append(bs, b) - } - } - - e.e.EncodeBytes(bs) - e.blist.put(bs) - if !byteSliceSameData(bs0, bs) { - e.blist.put(bs0) - } -} - -func (e *encoderSimpleIO) kStructFieldKey(keyType valueType, encName string) { - - if keyType == valueTypeString { - e.e.EncodeString(encName) - } else if keyType == valueTypeInt { - e.e.EncodeInt(must.Int(strconv.ParseInt(encName, 10, 64))) - } else if keyType == valueTypeUint { - e.e.EncodeUint(must.Uint(strconv.ParseUint(encName, 10, 64))) - } else if keyType == valueTypeFloat { - e.e.EncodeFloat64(must.Float(strconv.ParseFloat(encName, 64))) - } else { - halt.errorStr2("invalid struct key type: ", keyType.String()) - } - -} - -func (e *encoderSimpleIO) kStructSimple(f *encFnInfo, rv reflect.Value) { - _ = e.e - tisfi := f.ti.sfi.source() - - chkCirRef := e.h.CheckCircularRef - var si *structFieldInfo - var j int - - if f.ti.toArray || e.h.StructToArray { - if len(tisfi) == 0 { - e.e.WriteArrayEmpty() - return - } - e.arrayStart(len(tisfi)) - for j, si = range tisfi { - e.c = containerArrayElem - e.e.WriteArrayElem(j == 0) - if si.encBuiltin { - e.encodeIB(rv2i(si.fieldNoAlloc(rv, true))) - } else { - e.encodeValue(si.fieldNoAlloc(rv, !chkCirRef), nil) - } - } - e.c = 0 - e.e.WriteArrayEnd() - } else { - if len(tisfi) == 0 { - e.e.WriteMapEmpty() - return - } - if e.h.Canonical { - tisfi = f.ti.sfi.sorted() - } - e.mapStart(len(tisfi)) - for j, si = range tisfi { - e.c = containerMapKey - e.e.WriteMapElemKey(j == 0) - e.e.EncodeStringNoEscape4Json(si.encName) - e.mapElemValue() - if si.encBuiltin { - e.encodeIB(rv2i(si.fieldNoAlloc(rv, true))) - } else { - e.encodeValue(si.fieldNoAlloc(rv, !chkCirRef), nil) - } - } - e.c = 0 - e.e.WriteMapEnd() - } -} - -func (e *encoderSimpleIO) kStruct(f *encFnInfo, rv reflect.Value) { - _ = e.e - ti := f.ti - toMap := !(ti.toArray || e.h.StructToArray) - var mf map[string]interface{} - if ti.flagMissingFielder { - toMap = true - mf = rv2i(rv).(MissingFielder).CodecMissingFields() - } else if ti.flagMissingFielderPtr { - toMap = true - if rv.CanAddr() { - mf = rv2i(rvAddr(rv, ti.ptr)).(MissingFielder).CodecMissingFields() - } else { - mf = rv2i(e.addrRV(rv, ti.rt, ti.ptr)).(MissingFielder).CodecMissingFields() - } - } - newlen := len(mf) - tisfi := ti.sfi.source() - newlen += len(tisfi) - - var fkvs = e.slist.get(newlen)[:newlen] - - recur := e.h.RecursiveEmptyCheck - chkCirRef := e.h.CheckCircularRef - - var xlen int - - var kv sfiRv - var j int - var sf encStructFieldObj - if toMap { - newlen = 0 - if e.h.Canonical { - tisfi = f.ti.sfi.sorted() - } - for _, si := range tisfi { - - if si.omitEmpty { - kv.r = si.fieldNoAlloc(rv, false) - if isEmptyValue(kv.r, e.h.TypeInfos, recur) { - continue - } - } else { - kv.r = si.fieldNoAlloc(rv, si.encBuiltin || !chkCirRef) - } - kv.v = si - fkvs[newlen] = kv - newlen++ - } - - var mf2s []stringIntf - if len(mf) != 0 { - mf2s = make([]stringIntf, 0, len(mf)) - for k, v := range mf { - if k == "" { - continue - } - if ti.infoFieldOmitempty && isEmptyValue(reflect.ValueOf(v), e.h.TypeInfos, recur) { - continue - } - mf2s = append(mf2s, stringIntf{k, v}) - } - } - - xlen = newlen + len(mf2s) - if xlen == 0 { - e.e.WriteMapEmpty() - goto END - } - - e.mapStart(xlen) - - if len(mf2s) != 0 && e.h.Canonical { - mf2w := make([]encStructFieldObj, newlen+len(mf2s)) - for j = 0; j < newlen; j++ { - kv = fkvs[j] - mf2w[j] = encStructFieldObj{kv.v.encName, kv.r, nil, true, - !kv.v.encNameEscape4Json, kv.v.encBuiltin} - } - for _, v := range mf2s { - mf2w[j] = encStructFieldObj{v.v, reflect.Value{}, v.i, false, false, false} - j++ - } - sort.Sort((encStructFieldObjSlice)(mf2w)) - for j, sf = range mf2w { - e.c = containerMapKey - e.e.WriteMapElemKey(j == 0) - if ti.keyType == valueTypeString && sf.noEsc4json { - e.e.EncodeStringNoEscape4Json(sf.key) - } else { - e.kStructFieldKey(ti.keyType, sf.key) - } - e.mapElemValue() - if sf.isRv { - if sf.builtin { - e.encodeIB(rv2i(baseRVRV(sf.rv))) - } else { - e.encodeValue(sf.rv, nil) - } - } else { - if !e.encodeBuiltin(sf.intf) { - e.encodeR(reflect.ValueOf(sf.intf)) - } - - } - } - } else { - keytyp := ti.keyType - for j = 0; j < newlen; j++ { - kv = fkvs[j] - e.c = containerMapKey - e.e.WriteMapElemKey(j == 0) - if ti.keyType == valueTypeString && !kv.v.encNameEscape4Json { - e.e.EncodeStringNoEscape4Json(kv.v.encName) - } else { - e.kStructFieldKey(keytyp, kv.v.encName) - } - e.mapElemValue() - if kv.v.encBuiltin { - e.encodeIB(rv2i(baseRVRV(kv.r))) - } else { - e.encodeValue(kv.r, nil) - } - } - for _, v := range mf2s { - e.c = containerMapKey - e.e.WriteMapElemKey(j == 0) - e.kStructFieldKey(keytyp, v.v) - e.mapElemValue() - if !e.encodeBuiltin(v.i) { - e.encodeR(reflect.ValueOf(v.i)) - } - - j++ - } - } - - e.c = 0 - e.e.WriteMapEnd() - } else { - newlen = len(tisfi) - for i, si := range tisfi { - - if si.omitEmpty { - - kv.r = si.fieldNoAlloc(rv, false) - if isEmptyContainerValue(kv.r, e.h.TypeInfos, recur) { - kv.r = reflect.Value{} - } - } else { - kv.r = si.fieldNoAlloc(rv, si.encBuiltin || !chkCirRef) - } - kv.v = si - fkvs[i] = kv - } - - if newlen == 0 { - e.e.WriteArrayEmpty() - goto END - } - - e.arrayStart(newlen) - for j = 0; j < newlen; j++ { - e.c = containerArrayElem - e.e.WriteArrayElem(j == 0) - kv = fkvs[j] - if !kv.r.IsValid() { - e.e.EncodeNil() - } else if kv.v.encBuiltin { - e.encodeIB(rv2i(baseRVRV(kv.r))) - } else { - e.encodeValue(kv.r, nil) - } - } - e.c = 0 - e.e.WriteArrayEnd() - } - -END: - - e.slist.put(fkvs) -} - -func (e *encoderSimpleIO) kMap(f *encFnInfo, rv reflect.Value) { - _ = e.e - l := rvLenMap(rv) - if l == 0 { - e.e.WriteMapEmpty() - return - } - e.mapStart(l) - - var keyFn, valFn *encFnSimpleIO - - ktypeKind := reflect.Kind(f.ti.keykind) - vtypeKind := reflect.Kind(f.ti.elemkind) - - rtval := f.ti.elem - rtvalkind := vtypeKind - for rtvalkind == reflect.Ptr { - rtval = rtval.Elem() - rtvalkind = rtval.Kind() - } - if rtvalkind != reflect.Interface { - valFn = e.fn(rtval) - } - - var rvv = mapAddrLoopvarRV(f.ti.elem, vtypeKind) - - rtkey := f.ti.key - var keyTypeIsString = stringTypId == rt2id(rtkey) - if keyTypeIsString { - keyFn = e.fn(rtkey) - } else { - for rtkey.Kind() == reflect.Ptr { - rtkey = rtkey.Elem() - } - if rtkey.Kind() != reflect.Interface { - keyFn = e.fn(rtkey) - } - } - - if e.h.Canonical { - e.kMapCanonical(f.ti, rv, rvv, keyFn, valFn) - e.c = 0 - e.e.WriteMapEnd() - return - } - - var rvk = mapAddrLoopvarRV(f.ti.key, ktypeKind) - - var it mapIter - mapRange(&it, rv, rvk, rvv, true) - - kbuiltin := f.ti.tikey.flagEncBuiltin - vbuiltin := f.ti.tielem.flagEncBuiltin - for j := 0; it.Next(); j++ { - rv = it.Key() - e.c = containerMapKey - e.e.WriteMapElemKey(j == 0) - if keyTypeIsString { - e.e.EncodeString(rvGetString(rv)) - } else if kbuiltin { - e.encodeIB(rv2i(baseRVRV(rv))) - } else { - e.encodeValue(rv, keyFn) - } - e.mapElemValue() - rv = it.Value() - if vbuiltin { - e.encodeIB(rv2i(baseRVRV(rv))) - } else { - e.encodeValue(it.Value(), valFn) - } - } - it.Done() - - e.c = 0 - e.e.WriteMapEnd() -} - -func (e *encoderSimpleIO) kMapCanonical(ti *typeInfo, rv, rvv reflect.Value, keyFn, valFn *encFnSimpleIO) { - _ = e.e - - rtkey := ti.key - rtkeydecl := rtkey.PkgPath() == "" && rtkey.Name() != "" - - mks := rv.MapKeys() - rtkeyKind := rtkey.Kind() - mparams := getMapReqParams(ti) - - switch rtkeyKind { - case reflect.Bool: - - if len(mks) == 2 && mks[0].Bool() { - mks[0], mks[1] = mks[1], mks[0] - } - for i := range mks { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - if rtkeydecl { - e.e.EncodeBool(mks[i].Bool()) - } else { - e.encodeValueNonNil(mks[i], keyFn) - } - e.mapElemValue() - e.encodeValue(mapGet(rv, mks[i], rvv, mparams), valFn) - } - case reflect.String: - mksv := make([]orderedRv[string], len(mks)) - for i, k := range mks { - v := &mksv[i] - v.r = k - v.v = rvGetString(k) - } - slices.SortFunc(mksv, cmpOrderedRv) - for i := range mksv { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - if rtkeydecl { - e.e.EncodeString(mksv[i].v) - } else { - e.encodeValueNonNil(mksv[i].r, keyFn) - } - e.mapElemValue() - e.encodeValue(mapGet(rv, mksv[i].r, rvv, mparams), valFn) - } - case reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64, reflect.Uint, reflect.Uintptr: - mksv := make([]orderedRv[uint64], len(mks)) - for i, k := range mks { - v := &mksv[i] - v.r = k - v.v = k.Uint() - } - slices.SortFunc(mksv, cmpOrderedRv) - for i := range mksv { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - if rtkeydecl { - e.e.EncodeUint(mksv[i].v) - } else { - e.encodeValueNonNil(mksv[i].r, keyFn) - } - e.mapElemValue() - e.encodeValue(mapGet(rv, mksv[i].r, rvv, mparams), valFn) - } - case reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64, reflect.Int: - mksv := make([]orderedRv[int64], len(mks)) - for i, k := range mks { - v := &mksv[i] - v.r = k - v.v = k.Int() - } - slices.SortFunc(mksv, cmpOrderedRv) - for i := range mksv { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - if rtkeydecl { - e.e.EncodeInt(mksv[i].v) - } else { - e.encodeValueNonNil(mksv[i].r, keyFn) - } - e.mapElemValue() - e.encodeValue(mapGet(rv, mksv[i].r, rvv, mparams), valFn) - } - case reflect.Float32: - mksv := make([]orderedRv[float64], len(mks)) - for i, k := range mks { - v := &mksv[i] - v.r = k - v.v = k.Float() - } - slices.SortFunc(mksv, cmpOrderedRv) - for i := range mksv { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - if rtkeydecl { - e.e.EncodeFloat32(float32(mksv[i].v)) - } else { - e.encodeValueNonNil(mksv[i].r, keyFn) - } - e.mapElemValue() - e.encodeValue(mapGet(rv, mksv[i].r, rvv, mparams), valFn) - } - case reflect.Float64: - mksv := make([]orderedRv[float64], len(mks)) - for i, k := range mks { - v := &mksv[i] - v.r = k - v.v = k.Float() - } - slices.SortFunc(mksv, cmpOrderedRv) - for i := range mksv { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - if rtkeydecl { - e.e.EncodeFloat64(mksv[i].v) - } else { - e.encodeValueNonNil(mksv[i].r, keyFn) - } - e.mapElemValue() - e.encodeValue(mapGet(rv, mksv[i].r, rvv, mparams), valFn) - } - default: - if rtkey == timeTyp { - mksv := make([]timeRv, len(mks)) - for i, k := range mks { - v := &mksv[i] - v.r = k - v.v = rv2i(k).(time.Time) - } - slices.SortFunc(mksv, cmpTimeRv) - for i := range mksv { - e.c = containerMapKey - e.e.WriteMapElemKey(i == 0) - e.e.EncodeTime(mksv[i].v) - e.mapElemValue() - e.encodeValue(mapGet(rv, mksv[i].r, rvv, mparams), valFn) - } - break - } - - bs0 := e.blist.get(len(mks) * 16) - mksv := bs0 - mksbv := make([]bytesRv, len(mks)) - - sideEncode(e.hh, &e.h.sideEncPool, func(se encoderI) { - se.ResetBytes(&mksv) - for i, k := range mks { - v := &mksbv[i] - l := len(mksv) - se.setContainerState(containerMapKey) - se.encodeR(baseRVRV(k)) - se.atEndOfEncode() - se.writerEnd() - v.r = k - v.v = mksv[l:] - } - }) - - slices.SortFunc(mksbv, cmpBytesRv) - for j := range mksbv { - e.c = containerMapKey - e.e.WriteMapElemKey(j == 0) - e.e.writeBytesAsis(mksbv[j].v) - e.mapElemValue() - e.encodeValue(mapGet(rv, mksbv[j].r, rvv, mparams), valFn) - } - e.blist.put(mksv) - if !byteSliceSameData(bs0, mksv) { - e.blist.put(bs0) - } - } -} - -func (e *encoderSimpleIO) init(h Handle) { - initHandle(h) - callMake(&e.e) - e.hh = h - e.h = h.getBasicHandle() - - e.err = errEncoderNotInitialized - - e.fp = e.e.init(h, &e.encoderBase, e).(*fastpathEsSimpleIO) - - if e.bytes { - e.rtidFn = &e.h.rtidFnsEncBytes - e.rtidFnNoExt = &e.h.rtidFnsEncNoExtBytes - } else { - e.rtidFn = &e.h.rtidFnsEncIO - e.rtidFnNoExt = &e.h.rtidFnsEncNoExtIO - } - - e.reset() -} - -func (e *encoderSimpleIO) reset() { - e.e.reset() - if e.ci != nil { - e.ci = e.ci[:0] - } - e.c = 0 - e.calls = 0 - e.seq = 0 - e.err = nil -} - -func (e *encoderSimpleIO) Encode(v interface{}) (err error) { - - defer panicValToErr(e, callRecoverSentinel, &e.err, &err, debugging) - e.mustEncode(v) - return -} - -func (e *encoderSimpleIO) MustEncode(v interface{}) { - defer panicValToErr(e, callRecoverSentinel, &e.err, nil, true) - e.mustEncode(v) - return -} - -func (e *encoderSimpleIO) mustEncode(v interface{}) { - halt.onerror(e.err) - if e.hh == nil { - halt.onerror(errNoFormatHandle) - } - - e.calls++ - if !e.encodeBuiltin(v) { - e.encodeR(reflect.ValueOf(v)) - } - - e.calls-- - if e.calls == 0 { - e.e.atEndOfEncode() - e.e.writerEnd() - } -} - -func (e *encoderSimpleIO) encodeI(iv interface{}) { - if !e.encodeBuiltin(iv) { - e.encodeR(reflect.ValueOf(iv)) - } -} - -func (e *encoderSimpleIO) encodeIB(iv interface{}) { - if !e.encodeBuiltin(iv) { - - halt.errorStr("[should not happen] invalid type passed to encodeBuiltin") - } -} - -func (e *encoderSimpleIO) encodeR(base reflect.Value) { - e.encodeValue(base, nil) -} - -func (e *encoderSimpleIO) encodeBuiltin(iv interface{}) (ok bool) { - ok = true - switch v := iv.(type) { - case nil: - e.e.EncodeNil() - - case Raw: - e.rawBytes(v) - case string: - e.e.EncodeString(v) - case bool: - e.e.EncodeBool(v) - case int: - e.e.EncodeInt(int64(v)) - case int8: - e.e.EncodeInt(int64(v)) - case int16: - e.e.EncodeInt(int64(v)) - case int32: - e.e.EncodeInt(int64(v)) - case int64: - e.e.EncodeInt(v) - case uint: - e.e.EncodeUint(uint64(v)) - case uint8: - e.e.EncodeUint(uint64(v)) - case uint16: - e.e.EncodeUint(uint64(v)) - case uint32: - e.e.EncodeUint(uint64(v)) - case uint64: - e.e.EncodeUint(v) - case uintptr: - e.e.EncodeUint(uint64(v)) - case float32: - e.e.EncodeFloat32(v) - case float64: - e.e.EncodeFloat64(v) - case complex64: - e.encodeComplex64(v) - case complex128: - e.encodeComplex128(v) - case time.Time: - e.e.EncodeTime(v) - case []byte: - e.e.EncodeBytes(v) - default: - - ok = !skipFastpathTypeSwitchInDirectCall && e.dh.fastpathEncodeTypeSwitch(iv, e) - } - return -} - -func (e *encoderSimpleIO) encodeValue(rv reflect.Value, fn *encFnSimpleIO) { - - var ciPushes int - - var rvp reflect.Value - var rvpValid bool - -RV: - switch rv.Kind() { - case reflect.Ptr: - if rvIsNil(rv) { - e.e.EncodeNil() - goto END - } - rvpValid = true - rvp = rv - rv = rv.Elem() - - if e.h.CheckCircularRef && e.ci.canPushElemKind(rv.Kind()) { - e.ci.push(rv2i(rvp)) - ciPushes++ - } - goto RV - case reflect.Interface: - if rvIsNil(rv) { - e.e.EncodeNil() - goto END - } - rvpValid = false - rvp = reflect.Value{} - rv = rv.Elem() - fn = nil - goto RV - case reflect.Map: - if rvIsNil(rv) { - if e.h.NilCollectionToZeroLength { - e.e.WriteMapEmpty() - } else { - e.e.EncodeNil() - } - goto END - } - case reflect.Slice, reflect.Chan: - if rvIsNil(rv) { - if e.h.NilCollectionToZeroLength { - e.e.WriteArrayEmpty() - } else { - e.e.EncodeNil() - } - goto END - } - case reflect.Invalid, reflect.Func: - e.e.EncodeNil() - goto END - } - - if fn == nil { - fn = e.fn(rv.Type()) - } - - if !fn.i.addrE { - - } else if rvpValid { - rv = rvp - } else if rv.CanAddr() { - rv = rvAddr(rv, fn.i.ti.ptr) - } else { - rv = e.addrRV(rv, fn.i.ti.rt, fn.i.ti.ptr) - } - fn.fe(e, &fn.i, rv) - -END: - if ciPushes > 0 { - e.ci.pop(ciPushes) - } -} - -func (e *encoderSimpleIO) encodeValueNonNil(rv reflect.Value, fn *encFnSimpleIO) { - - if fn.i.addrE { - if rv.CanAddr() { - rv = rvAddr(rv, fn.i.ti.ptr) - } else { - rv = e.addrRV(rv, fn.i.ti.rt, fn.i.ti.ptr) - } - } - fn.fe(e, &fn.i, rv) -} - -func (e *encoderSimpleIO) encodeAs(v interface{}, t reflect.Type, ext bool) { - if ext { - e.encodeValue(baseRV(v), e.fn(t)) - } else { - e.encodeValue(baseRV(v), e.fnNoExt(t)) - } -} - -func (e *encoderSimpleIO) marshalUtf8(bs []byte, fnerr error) { - halt.onerror(fnerr) - if bs == nil { - e.e.EncodeNil() - } else { - e.e.EncodeString(stringView(bs)) - } -} - -func (e *encoderSimpleIO) marshalAsis(bs []byte, fnerr error) { - halt.onerror(fnerr) - if bs == nil { - e.e.EncodeNil() - } else { - e.e.writeBytesAsis(bs) - } -} - -func (e *encoderSimpleIO) marshalRaw(bs []byte, fnerr error) { - halt.onerror(fnerr) - e.e.EncodeBytes(bs) -} - -func (e *encoderSimpleIO) rawBytes(vv Raw) { - v := []byte(vv) - if !e.h.Raw { - halt.errorBytes("Raw values cannot be encoded: ", v) - } - e.e.writeBytesAsis(v) -} - -func (e *encoderSimpleIO) fn(t reflect.Type) *encFnSimpleIO { - return e.dh.encFnViaBH(t, e.rtidFn, e.h, e.fp, false) -} - -func (e *encoderSimpleIO) fnNoExt(t reflect.Type) *encFnSimpleIO { - return e.dh.encFnViaBH(t, e.rtidFnNoExt, e.h, e.fp, true) -} - -func (e *encoderSimpleIO) mapStart(length int) { - e.e.WriteMapStart(length) - e.c = containerMapStart -} - -func (e *encoderSimpleIO) mapElemValue() { - e.e.WriteMapElemValue() - e.c = containerMapValue -} - -func (e *encoderSimpleIO) arrayStart(length int) { - e.e.WriteArrayStart(length) - e.c = containerArrayStart -} - -func (e *encoderSimpleIO) writerEnd() { - e.e.writerEnd() -} - -func (e *encoderSimpleIO) atEndOfEncode() { - e.e.atEndOfEncode() -} - -func (e *encoderSimpleIO) Reset(w io.Writer) { - if e.bytes { - halt.onerror(errEncNoResetBytesWithWriter) - } - e.reset() - if w == nil { - w = io.Discard - } - e.e.resetOutIO(w) -} - -func (e *encoderSimpleIO) ResetBytes(out *[]byte) { - if !e.bytes { - halt.onerror(errEncNoResetWriterWithBytes) - } - e.resetBytes(out) -} - -func (e *encoderSimpleIO) resetBytes(out *[]byte) { - e.reset() - if out == nil { - out = &bytesEncAppenderDefOut - } - e.e.resetOutBytes(out) -} - -func (helperEncDriverSimpleIO) newEncoderBytes(out *[]byte, h Handle) *encoderSimpleIO { - var c1 encoderSimpleIO - c1.bytes = true - c1.init(h) - c1.ResetBytes(out) - return &c1 -} - -func (helperEncDriverSimpleIO) newEncoderIO(out io.Writer, h Handle) *encoderSimpleIO { - var c1 encoderSimpleIO - c1.bytes = false - c1.init(h) - c1.Reset(out) - return &c1 -} - -func (helperEncDriverSimpleIO) encFnloadFastpathUnderlying(ti *typeInfo, fp *fastpathEsSimpleIO) (f *fastpathESimpleIO, u reflect.Type) { - rtid := rt2id(ti.fastpathUnderlying) - idx, ok := fastpathAvIndex(rtid) - if !ok { - return - } - f = &fp[idx] - if uint8(reflect.Array) == ti.kind { - u = reflect.ArrayOf(ti.rt.Len(), ti.elem) - } else { - u = f.rt - } - return -} - -func (helperEncDriverSimpleIO) encFindRtidFn(s []encRtidFnSimpleIO, rtid uintptr) (i uint, fn *encFnSimpleIO) { - - var h uint - var j = uint(len(s)) -LOOP: - if i < j { - h = (i + j) >> 1 - if s[h].rtid < rtid { - i = h + 1 - } else { - j = h - } - goto LOOP - } - if i < uint(len(s)) && s[i].rtid == rtid { - fn = s[i].fn - } - return -} - -func (helperEncDriverSimpleIO) encFromRtidFnSlice(fns *atomicRtidFnSlice) (s []encRtidFnSimpleIO) { - if v := fns.load(); v != nil { - s = *(lowLevelToPtr[[]encRtidFnSimpleIO](v)) - } - return -} - -func (dh helperEncDriverSimpleIO) encFnViaBH(rt reflect.Type, fns *atomicRtidFnSlice, - x *BasicHandle, fp *fastpathEsSimpleIO, checkExt bool) (fn *encFnSimpleIO) { - return dh.encFnVia(rt, fns, x.typeInfos(), &x.mu, x.extHandle, fp, - checkExt, x.CheckCircularRef, x.timeBuiltin, x.binaryHandle, x.jsonHandle) -} - -func (dh helperEncDriverSimpleIO) encFnVia(rt reflect.Type, fns *atomicRtidFnSlice, - tinfos *TypeInfos, mu *sync.Mutex, exth extHandle, fp *fastpathEsSimpleIO, - checkExt, checkCircularRef, timeBuiltin, binaryEncoding, json bool) (fn *encFnSimpleIO) { - rtid := rt2id(rt) - var sp []encRtidFnSimpleIO = dh.encFromRtidFnSlice(fns) - if sp != nil { - _, fn = dh.encFindRtidFn(sp, rtid) - } - if fn == nil { - fn = dh.encFnViaLoader(rt, rtid, fns, tinfos, mu, exth, fp, checkExt, checkCircularRef, timeBuiltin, binaryEncoding, json) - } - return -} - -func (dh helperEncDriverSimpleIO) encFnViaLoader(rt reflect.Type, rtid uintptr, fns *atomicRtidFnSlice, - tinfos *TypeInfos, mu *sync.Mutex, exth extHandle, fp *fastpathEsSimpleIO, - checkExt, checkCircularRef, timeBuiltin, binaryEncoding, json bool) (fn *encFnSimpleIO) { - - fn = dh.encFnLoad(rt, rtid, tinfos, exth, fp, checkExt, checkCircularRef, timeBuiltin, binaryEncoding, json) - var sp []encRtidFnSimpleIO - mu.Lock() - sp = dh.encFromRtidFnSlice(fns) - - if sp == nil { - sp = []encRtidFnSimpleIO{{rtid, fn}} - fns.store(ptrToLowLevel(&sp)) - } else { - idx, fn2 := dh.encFindRtidFn(sp, rtid) - if fn2 == nil { - sp2 := make([]encRtidFnSimpleIO, len(sp)+1) - copy(sp2[idx+1:], sp[idx:]) - copy(sp2, sp[:idx]) - sp2[idx] = encRtidFnSimpleIO{rtid, fn} - fns.store(ptrToLowLevel(&sp2)) - } - } - mu.Unlock() - return -} - -func (dh helperEncDriverSimpleIO) encFnLoad(rt reflect.Type, rtid uintptr, tinfos *TypeInfos, - exth extHandle, fp *fastpathEsSimpleIO, - checkExt, checkCircularRef, timeBuiltin, binaryEncoding, json bool) (fn *encFnSimpleIO) { - fn = new(encFnSimpleIO) - fi := &(fn.i) - ti := tinfos.get(rtid, rt) - fi.ti = ti - rk := reflect.Kind(ti.kind) - - if rtid == timeTypId && timeBuiltin { - fn.fe = (*encoderSimpleIO).kTime - } else if rtid == rawTypId { - fn.fe = (*encoderSimpleIO).raw - } else if rtid == rawExtTypId { - fn.fe = (*encoderSimpleIO).rawExt - fi.addrE = true - } else if xfFn := exth.getExt(rtid, checkExt); xfFn != nil { - fi.xfTag, fi.xfFn = xfFn.tag, xfFn.ext - fn.fe = (*encoderSimpleIO).ext - if rk == reflect.Struct || rk == reflect.Array { - fi.addrE = true - } - } else if ti.flagSelfer || ti.flagSelferPtr { - fn.fe = (*encoderSimpleIO).selferMarshal - fi.addrE = ti.flagSelferPtr - } else if supportMarshalInterfaces && binaryEncoding && - (ti.flagBinaryMarshaler || ti.flagBinaryMarshalerPtr) && - (ti.flagBinaryUnmarshaler || ti.flagBinaryUnmarshalerPtr) { - fn.fe = (*encoderSimpleIO).binaryMarshal - fi.addrE = ti.flagBinaryMarshalerPtr - } else if supportMarshalInterfaces && !binaryEncoding && json && - (ti.flagJsonMarshaler || ti.flagJsonMarshalerPtr) && - (ti.flagJsonUnmarshaler || ti.flagJsonUnmarshalerPtr) { - - fn.fe = (*encoderSimpleIO).jsonMarshal - fi.addrE = ti.flagJsonMarshalerPtr - } else if supportMarshalInterfaces && !binaryEncoding && - (ti.flagTextMarshaler || ti.flagTextMarshalerPtr) && - (ti.flagTextUnmarshaler || ti.flagTextUnmarshalerPtr) { - fn.fe = (*encoderSimpleIO).textMarshal - fi.addrE = ti.flagTextMarshalerPtr - } else { - if fastpathEnabled && (rk == reflect.Map || rk == reflect.Slice || rk == reflect.Array) { - - var rtid2 uintptr - if !ti.flagHasPkgPath { - rtid2 = rtid - if rk == reflect.Array { - rtid2 = rt2id(ti.key) - } - if idx, ok := fastpathAvIndex(rtid2); ok { - fn.fe = fp[idx].encfn - } - } else { - - xfe, xrt := dh.encFnloadFastpathUnderlying(ti, fp) - if xfe != nil { - xfnf := xfe.encfn - fn.fe = func(e *encoderSimpleIO, xf *encFnInfo, xrv reflect.Value) { - xfnf(e, xf, rvConvert(xrv, xrt)) - } - } - } - } - if fn.fe == nil { - switch rk { - case reflect.Bool: - fn.fe = (*encoderSimpleIO).kBool - case reflect.String: - - fn.fe = (*encoderSimpleIO).kString - case reflect.Int: - fn.fe = (*encoderSimpleIO).kInt - case reflect.Int8: - fn.fe = (*encoderSimpleIO).kInt8 - case reflect.Int16: - fn.fe = (*encoderSimpleIO).kInt16 - case reflect.Int32: - fn.fe = (*encoderSimpleIO).kInt32 - case reflect.Int64: - fn.fe = (*encoderSimpleIO).kInt64 - case reflect.Uint: - fn.fe = (*encoderSimpleIO).kUint - case reflect.Uint8: - fn.fe = (*encoderSimpleIO).kUint8 - case reflect.Uint16: - fn.fe = (*encoderSimpleIO).kUint16 - case reflect.Uint32: - fn.fe = (*encoderSimpleIO).kUint32 - case reflect.Uint64: - fn.fe = (*encoderSimpleIO).kUint64 - case reflect.Uintptr: - fn.fe = (*encoderSimpleIO).kUintptr - case reflect.Float32: - fn.fe = (*encoderSimpleIO).kFloat32 - case reflect.Float64: - fn.fe = (*encoderSimpleIO).kFloat64 - case reflect.Complex64: - fn.fe = (*encoderSimpleIO).kComplex64 - case reflect.Complex128: - fn.fe = (*encoderSimpleIO).kComplex128 - case reflect.Chan: - fn.fe = (*encoderSimpleIO).kChan - case reflect.Slice: - fn.fe = (*encoderSimpleIO).kSlice - case reflect.Array: - fn.fe = (*encoderSimpleIO).kArray - case reflect.Struct: - if ti.simple { - fn.fe = (*encoderSimpleIO).kStructSimple - } else { - fn.fe = (*encoderSimpleIO).kStruct - } - case reflect.Map: - fn.fe = (*encoderSimpleIO).kMap - case reflect.Interface: - - fn.fe = (*encoderSimpleIO).kErr - default: - - fn.fe = (*encoderSimpleIO).kErr - } - } - } - return -} -func (d *decoderSimpleIO) rawExt(f *decFnInfo, rv reflect.Value) { - d.d.DecodeRawExt(rv2i(rv).(*RawExt)) -} - -func (d *decoderSimpleIO) ext(f *decFnInfo, rv reflect.Value) { - d.d.DecodeExt(rv2i(rv), f.ti.rt, f.xfTag, f.xfFn) -} - -func (d *decoderSimpleIO) selferUnmarshal(_ *decFnInfo, rv reflect.Value) { - rv2i(rv).(Selfer).CodecDecodeSelf(&Decoder{d}) -} - -func (d *decoderSimpleIO) binaryUnmarshal(_ *decFnInfo, rv reflect.Value) { - bm := rv2i(rv).(encoding.BinaryUnmarshaler) - xbs, _ := d.d.DecodeBytes() - fnerr := bm.UnmarshalBinary(xbs) - halt.onerror(fnerr) -} - -func (d *decoderSimpleIO) textUnmarshal(_ *decFnInfo, rv reflect.Value) { - tm := rv2i(rv).(encoding.TextUnmarshaler) - fnerr := tm.UnmarshalText(bytesOKs(d.d.DecodeStringAsBytes())) - halt.onerror(fnerr) -} - -func (d *decoderSimpleIO) jsonUnmarshal(_ *decFnInfo, rv reflect.Value) { - d.jsonUnmarshalV(rv2i(rv).(jsonUnmarshaler)) -} - -func (d *decoderSimpleIO) jsonUnmarshalV(tm jsonUnmarshaler) { - - halt.onerror(tm.UnmarshalJSON(d.d.nextValueBytes())) -} - -func (d *decoderSimpleIO) kErr(_ *decFnInfo, rv reflect.Value) { - halt.errorf("unsupported decoding kind: %s, for %#v", rv.Kind(), rv) - -} - -func (d *decoderSimpleIO) raw(_ *decFnInfo, rv reflect.Value) { - rvSetBytes(rv, d.rawBytes()) -} - -func (d *decoderSimpleIO) kString(_ *decFnInfo, rv reflect.Value) { - rvSetString(rv, d.detach2Str(d.d.DecodeStringAsBytes())) -} - -func (d *decoderSimpleIO) kBool(_ *decFnInfo, rv reflect.Value) { - rvSetBool(rv, d.d.DecodeBool()) -} - -func (d *decoderSimpleIO) kTime(_ *decFnInfo, rv reflect.Value) { - rvSetTime(rv, d.d.DecodeTime()) -} - -func (d *decoderSimpleIO) kFloat32(_ *decFnInfo, rv reflect.Value) { - rvSetFloat32(rv, d.d.DecodeFloat32()) -} - -func (d *decoderSimpleIO) kFloat64(_ *decFnInfo, rv reflect.Value) { - rvSetFloat64(rv, d.d.DecodeFloat64()) -} - -func (d *decoderSimpleIO) kComplex64(_ *decFnInfo, rv reflect.Value) { - rvSetComplex64(rv, complex(d.d.DecodeFloat32(), 0)) -} - -func (d *decoderSimpleIO) kComplex128(_ *decFnInfo, rv reflect.Value) { - rvSetComplex128(rv, complex(d.d.DecodeFloat64(), 0)) -} - -func (d *decoderSimpleIO) kInt(_ *decFnInfo, rv reflect.Value) { - rvSetInt(rv, int(chkOvf.IntV(d.d.DecodeInt64(), intBitsize))) -} - -func (d *decoderSimpleIO) kInt8(_ *decFnInfo, rv reflect.Value) { - rvSetInt8(rv, int8(chkOvf.IntV(d.d.DecodeInt64(), 8))) -} - -func (d *decoderSimpleIO) kInt16(_ *decFnInfo, rv reflect.Value) { - rvSetInt16(rv, int16(chkOvf.IntV(d.d.DecodeInt64(), 16))) -} - -func (d *decoderSimpleIO) kInt32(_ *decFnInfo, rv reflect.Value) { - rvSetInt32(rv, int32(chkOvf.IntV(d.d.DecodeInt64(), 32))) -} - -func (d *decoderSimpleIO) kInt64(_ *decFnInfo, rv reflect.Value) { - rvSetInt64(rv, d.d.DecodeInt64()) -} - -func (d *decoderSimpleIO) kUint(_ *decFnInfo, rv reflect.Value) { - rvSetUint(rv, uint(chkOvf.UintV(d.d.DecodeUint64(), uintBitsize))) -} - -func (d *decoderSimpleIO) kUintptr(_ *decFnInfo, rv reflect.Value) { - rvSetUintptr(rv, uintptr(chkOvf.UintV(d.d.DecodeUint64(), uintBitsize))) -} - -func (d *decoderSimpleIO) kUint8(_ *decFnInfo, rv reflect.Value) { - rvSetUint8(rv, uint8(chkOvf.UintV(d.d.DecodeUint64(), 8))) -} - -func (d *decoderSimpleIO) kUint16(_ *decFnInfo, rv reflect.Value) { - rvSetUint16(rv, uint16(chkOvf.UintV(d.d.DecodeUint64(), 16))) -} - -func (d *decoderSimpleIO) kUint32(_ *decFnInfo, rv reflect.Value) { - rvSetUint32(rv, uint32(chkOvf.UintV(d.d.DecodeUint64(), 32))) -} - -func (d *decoderSimpleIO) kUint64(_ *decFnInfo, rv reflect.Value) { - rvSetUint64(rv, d.d.DecodeUint64()) -} - -func (d *decoderSimpleIO) kInterfaceNaked(f *decFnInfo) (rvn reflect.Value) { - - n := d.naked() - d.d.DecodeNaked() - - if decFailNonEmptyIntf && f.ti.numMeth > 0 { - halt.errorf("cannot decode non-nil codec value into nil %v (%v methods)", f.ti.rt, f.ti.numMeth) - } - - switch n.v { - case valueTypeMap: - mtid := d.mtid - if mtid == 0 { - if d.jsms { - mtid = mapStrIntfTypId - } else { - mtid = mapIntfIntfTypId - } - } - if mtid == mapStrIntfTypId { - var v2 map[string]interface{} - d.decode(&v2) - rvn = rv4iptr(&v2).Elem() - } else if mtid == mapIntfIntfTypId { - var v2 map[interface{}]interface{} - d.decode(&v2) - rvn = rv4iptr(&v2).Elem() - } else if d.mtr { - rvn = reflect.New(d.h.MapType) - d.decode(rv2i(rvn)) - rvn = rvn.Elem() - } else { - - rvn = rvZeroAddrK(d.h.MapType, reflect.Map) - d.decodeValue(rvn, nil) - } - case valueTypeArray: - if d.stid == 0 || d.stid == intfSliceTypId { - var v2 []interface{} - d.decode(&v2) - rvn = rv4iptr(&v2).Elem() - } else if d.str { - rvn = reflect.New(d.h.SliceType) - d.decode(rv2i(rvn)) - rvn = rvn.Elem() - } else { - rvn = rvZeroAddrK(d.h.SliceType, reflect.Slice) - d.decodeValue(rvn, nil) - } - if d.h.PreferArrayOverSlice { - rvn = rvGetArray4Slice(rvn) - } - case valueTypeExt: - tag, bytes := n.u, n.l - bfn := d.h.getExtForTag(tag) - var re = RawExt{Tag: tag} - if bytes == nil { - - if bfn == nil { - d.decode(&re.Value) - rvn = rv4iptr(&re).Elem() - } else if bfn.ext == SelfExt { - rvn = rvZeroAddrK(bfn.rt, bfn.rt.Kind()) - d.decodeValue(rvn, d.fnNoExt(bfn.rt)) - } else { - rvn = reflect.New(bfn.rt) - d.interfaceExtConvertAndDecode(rv2i(rvn), bfn.ext) - rvn = rvn.Elem() - } - } else { - - if bfn == nil { - re.setData(bytes, false) - rvn = rv4iptr(&re).Elem() - } else { - rvn = reflect.New(bfn.rt) - if bfn.ext == SelfExt { - sideDecode(d.hh, &d.h.sideDecPool, func(sd decoderI) { oneOffDecode(sd, rv2i(rvn), bytes, bfn.rt, true) }) - } else { - bfn.ext.ReadExt(rv2i(rvn), bytes) - } - rvn = rvn.Elem() - } - } - - if d.h.PreferPointerForStructOrArray && rvn.CanAddr() { - if rk := rvn.Kind(); rk == reflect.Array || rk == reflect.Struct { - rvn = rvn.Addr() - } - } - case valueTypeNil: - - case valueTypeInt: - rvn = n.ri() - case valueTypeUint: - rvn = n.ru() - case valueTypeFloat: - rvn = n.rf() - case valueTypeBool: - rvn = n.rb() - case valueTypeString, valueTypeSymbol: - rvn = n.rs() - case valueTypeBytes: - rvn = n.rl() - case valueTypeTime: - rvn = n.rt() - default: - halt.errorStr2("kInterfaceNaked: unexpected valueType: ", n.v.String()) - } - return -} - -func (d *decoderSimpleIO) kInterface(f *decFnInfo, rv reflect.Value) { - - isnilrv := rvIsNil(rv) - - var rvn reflect.Value - - if d.h.InterfaceReset { - - rvn = d.h.intf2impl(f.ti.rtid) - if !rvn.IsValid() { - rvn = d.kInterfaceNaked(f) - if rvn.IsValid() { - rvSetIntf(rv, rvn) - } else if !isnilrv { - decSetNonNilRV2Zero4Intf(rv) - } - return - } - } else if isnilrv { - - rvn = d.h.intf2impl(f.ti.rtid) - if !rvn.IsValid() { - rvn = d.kInterfaceNaked(f) - if rvn.IsValid() { - rvSetIntf(rv, rvn) - } - return - } - } else { - - rvn = rv.Elem() - } - - canDecode, _ := isDecodeable(rvn) - - if !canDecode { - rvn2 := d.oneShotAddrRV(rvn.Type(), rvn.Kind()) - rvSetDirect(rvn2, rvn) - rvn = rvn2 - } - - d.decodeValue(rvn, nil) - rvSetIntf(rv, rvn) -} - -func (d *decoderSimpleIO) kStructField(si *structFieldInfo, rv reflect.Value) { - if d.d.TryNil() { - rv = si.fieldNoAlloc(rv, true) - if rv.IsValid() { - decSetNonNilRV2Zero(rv) - } - } else if si.decBuiltin { - rv = rvAddr(si.fieldAlloc(rv), si.ptrTyp) - d.decode(rv2i(rv)) - } else { - fn := d.fn(si.baseTyp) - rv = si.fieldAlloc(rv) - if fn.i.addrD { - rv = rvAddr(rv, si.ptrTyp) - } - fn.fd(d, &fn.i, rv) - } -} - -func (d *decoderSimpleIO) kStructSimple(f *decFnInfo, rv reflect.Value) { - _ = d.d - ctyp := d.d.ContainerType() - ti := f.ti - if ctyp == valueTypeMap { - containerLen := d.mapStart(d.d.ReadMapStart()) - if containerLen == 0 { - d.mapEnd() - return - } - hasLen := containerLen >= 0 - var rvkencname []byte - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - sab, att := d.d.DecodeStringAsBytes() - rvkencname = d.usableStructFieldNameBytes(rvkencname, sab, att) - d.mapElemValue() - if si := ti.siForEncName(rvkencname); si != nil { - d.kStructField(si, rv) - } else { - d.structFieldNotFound(-1, stringView(rvkencname)) - } - } - d.mapEnd() - } else if ctyp == valueTypeArray { - containerLen := d.arrayStart(d.d.ReadArrayStart()) - if containerLen == 0 { - d.arrayEnd() - return - } - - tisfi := ti.sfi.source() - hasLen := containerLen >= 0 - - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.arrayElem(j == 0) - if j < len(tisfi) { - d.kStructField(tisfi[j], rv) - } else { - d.structFieldNotFound(j, "") - } - } - d.arrayEnd() - } else { - halt.onerror(errNeedMapOrArrayDecodeToStruct) - } -} - -func (d *decoderSimpleIO) kStruct(f *decFnInfo, rv reflect.Value) { - _ = d.d - ctyp := d.d.ContainerType() - ti := f.ti - var mf MissingFielder - if ti.flagMissingFielder { - mf = rv2i(rv).(MissingFielder) - } else if ti.flagMissingFielderPtr { - mf = rv2i(rvAddr(rv, ti.ptr)).(MissingFielder) - } - if ctyp == valueTypeMap { - containerLen := d.mapStart(d.d.ReadMapStart()) - if containerLen == 0 { - d.mapEnd() - return - } - hasLen := containerLen >= 0 - var name2 []byte - var rvkencname []byte - tkt := ti.keyType - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.mapElemKey(j == 0) - - if tkt == valueTypeString { - sab, att := d.d.DecodeStringAsBytes() - rvkencname = d.usableStructFieldNameBytes(rvkencname, sab, att) - } else if tkt == valueTypeInt { - rvkencname = strconv.AppendInt(d.b[:0], d.d.DecodeInt64(), 10) - } else if tkt == valueTypeUint { - rvkencname = strconv.AppendUint(d.b[:0], d.d.DecodeUint64(), 10) - } else if tkt == valueTypeFloat { - rvkencname = strconv.AppendFloat(d.b[:0], d.d.DecodeFloat64(), 'f', -1, 64) - } else { - halt.errorStr2("invalid struct key type: ", ti.keyType.String()) - } - - d.mapElemValue() - if si := ti.siForEncName(rvkencname); si != nil { - d.kStructField(si, rv) - } else if mf != nil { - - name2 = append(name2[:0], rvkencname...) - var f interface{} - d.decode(&f) - if !mf.CodecMissingField(name2, f) && d.h.ErrorIfNoField { - halt.errorStr2("no matching struct field when decoding stream map with key: ", stringView(name2)) - } - } else { - d.structFieldNotFound(-1, stringView(rvkencname)) - } - } - d.mapEnd() - } else if ctyp == valueTypeArray { - containerLen := d.arrayStart(d.d.ReadArrayStart()) - if containerLen == 0 { - d.arrayEnd() - return - } - - tisfi := ti.sfi.source() - hasLen := containerLen >= 0 - - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - d.arrayElem(j == 0) - if j < len(tisfi) { - d.kStructField(tisfi[j], rv) - } else { - d.structFieldNotFound(j, "") - } - } - - d.arrayEnd() - } else { - halt.onerror(errNeedMapOrArrayDecodeToStruct) - } -} - -func (d *decoderSimpleIO) kSlice(f *decFnInfo, rv reflect.Value) { - _ = d.d - - ti := f.ti - rvCanset := rv.CanSet() - - ctyp := d.d.ContainerType() - if ctyp == valueTypeBytes || ctyp == valueTypeString { - - if !(ti.rtid == uint8SliceTypId || ti.elemkind == uint8(reflect.Uint8)) { - halt.errorf("bytes/string in stream must decode into slice/array of bytes, not %v", ti.rt) - } - rvbs := rvGetBytes(rv) - if rvCanset { - bs2, bst := d.decodeBytesInto(rvbs, false) - if bst != dBytesIntoParamOut { - rvSetBytes(rv, bs2) - } - } else { - - d.decodeBytesInto(rvbs[:len(rvbs):len(rvbs)], true) - } - return - } - - var containerLenS int - isArray := ctyp == valueTypeArray - if isArray { - containerLenS = d.arrayStart(d.d.ReadArrayStart()) - } else if ctyp == valueTypeMap { - containerLenS = d.mapStart(d.d.ReadMapStart()) * 2 - } else { - halt.errorStr2("decoding into a slice, expect map/array - got ", ctyp.String()) - } - - if containerLenS == 0 { - if rvCanset { - if rvIsNil(rv) { - rvSetDirect(rv, rvSliceZeroCap(ti.rt)) - } else { - rvSetSliceLen(rv, 0) - } - } - if isArray { - d.arrayEnd() - } else { - d.mapEnd() - } - return - } - - rtelem0Mut := !scalarBitset.isset(ti.elemkind) - rtelem := ti.elem - - for k := reflect.Kind(ti.elemkind); k == reflect.Ptr; k = rtelem.Kind() { - rtelem = rtelem.Elem() - } - - var fn *decFnSimpleIO - - var rvChanged bool - - var rv0 = rv - var rv9 reflect.Value - - rvlen := rvLenSlice(rv) - rvcap := rvCapSlice(rv) - maxInitLen := d.maxInitLen() - hasLen := containerLenS >= 0 - if hasLen { - if containerLenS > rvcap { - oldRvlenGtZero := rvlen > 0 - rvlen1 := int(decInferLen(containerLenS, maxInitLen, uint(ti.elemsize))) - if rvlen1 == rvlen { - } else if rvlen1 <= rvcap { - if rvCanset { - rvlen = rvlen1 - rvSetSliceLen(rv, rvlen) - } - } else if rvCanset { - rvlen = rvlen1 - rv, rvCanset = rvMakeSlice(rv, f.ti, rvlen, rvlen) - rvcap = rvlen - rvChanged = !rvCanset - } else { - halt.errorStr("cannot decode into non-settable slice") - } - if rvChanged && oldRvlenGtZero && rtelem0Mut { - rvCopySlice(rv, rv0, rtelem) - } - } else if containerLenS != rvlen { - if rvCanset { - rvlen = containerLenS - rvSetSliceLen(rv, rvlen) - } - } - } - - var elemReset = d.h.SliceElementReset - - var rtelemIsPtr bool - var rtelemElem reflect.Type - builtin := ti.tielem.flagDecBuiltin - if builtin { - rtelemIsPtr = ti.elemkind == uint8(reflect.Ptr) - if rtelemIsPtr { - rtelemElem = ti.elem.Elem() - } - } - - var j int - for ; d.containerNext(j, containerLenS, hasLen); j++ { - if j == 0 { - if rvIsNil(rv) { - if rvCanset { - rvlen = int(decInferLen(containerLenS, maxInitLen, uint(ti.elemsize))) - rv, rvCanset = rvMakeSlice(rv, f.ti, rvlen, rvlen) - rvcap = rvlen - rvChanged = !rvCanset - } else { - halt.errorStr("cannot decode into non-settable slice") - } - } - if fn == nil { - fn = d.fn(rtelem) - } - } - - if ctyp == valueTypeArray { - d.arrayElem(j == 0) - } else if j&1 == 0 { - d.mapElemKey(j == 0) - } else { - d.mapElemValue() - } - - if j >= rvlen { - - if rvlen < rvcap { - rvlen = rvcap - if rvCanset { - rvSetSliceLen(rv, rvlen) - } else if rvChanged { - rv = rvSlice(rv, rvlen) - } else { - halt.onerror(errExpandSliceCannotChange) - } - } else { - if !(rvCanset || rvChanged) { - halt.onerror(errExpandSliceCannotChange) - } - rv, rvcap, rvCanset = rvGrowSlice(rv, f.ti, rvcap, 1) - - rvlen = rvcap - rvChanged = !rvCanset - } - } - - rv9 = rvArrayIndex(rv, j, f.ti, true) - if elemReset { - rvSetZero(rv9) - } - if d.d.TryNil() { - rvSetZero(rv9) - } else if builtin { - if rtelemIsPtr { - if rvIsNil(rv9) { - rvSetDirect(rv9, reflect.New(rtelemElem)) - } - d.decode(rv2i(rv9)) - } else { - d.decode(rv2i(rvAddr(rv9, ti.tielem.ptr))) - } - } else { - d.decodeValueNoCheckNil(rv9, fn) - } - } - if j < rvlen { - if rvCanset { - rvSetSliceLen(rv, j) - } else if rvChanged { - rv = rvSlice(rv, j) - } - - } else if j == 0 && rvIsNil(rv) { - if rvCanset { - rv = rvSliceZeroCap(ti.rt) - rvCanset = false - rvChanged = true - } - } - if isArray { - d.arrayEnd() - } else { - d.mapEnd() - } - - if rvChanged { - rvSetDirect(rv0, rv) - } -} - -func (d *decoderSimpleIO) kArray(f *decFnInfo, rv reflect.Value) { - _ = d.d - - ti := f.ti - ctyp := d.d.ContainerType() - if handleBytesWithinKArray && (ctyp == valueTypeBytes || ctyp == valueTypeString) { - - if ti.elemkind != uint8(reflect.Uint8) { - halt.errorf("bytes/string in stream can decode into array of bytes, but not %v", ti.rt) - } - rvbs := rvGetArrayBytes(rv, nil) - d.decodeBytesInto(rvbs, true) - return - } - - var containerLenS int - isArray := ctyp == valueTypeArray - if isArray { - containerLenS = d.arrayStart(d.d.ReadArrayStart()) - } else if ctyp == valueTypeMap { - containerLenS = d.mapStart(d.d.ReadMapStart()) * 2 - } else { - halt.errorStr2("decoding into a slice, expect map/array - got ", ctyp.String()) - } - - if containerLenS == 0 { - if isArray { - d.arrayEnd() - } else { - d.mapEnd() - } - return - } - - rtelem := ti.elem - for k := reflect.Kind(ti.elemkind); k == reflect.Ptr; k = rtelem.Kind() { - rtelem = rtelem.Elem() - } - - var rv9 reflect.Value - - rvlen := rv.Len() - hasLen := containerLenS >= 0 - if hasLen && containerLenS > rvlen { - halt.errorf("cannot decode into array with length: %v, less than container length: %v", any(rvlen), any(containerLenS)) - } - - var elemReset = d.h.SliceElementReset - - var rtelemIsPtr bool - var rtelemElem reflect.Type - var fn *decFnSimpleIO - builtin := ti.tielem.flagDecBuiltin - if builtin { - rtelemIsPtr = ti.elemkind == uint8(reflect.Ptr) - if rtelemIsPtr { - rtelemElem = ti.elem.Elem() - } - } else { - fn = d.fn(rtelem) - } - - for j := 0; d.containerNext(j, containerLenS, hasLen); j++ { - if ctyp == valueTypeArray { - d.arrayElem(j == 0) - } else if j&1 == 0 { - d.mapElemKey(j == 0) - } else { - d.mapElemValue() - } - - if j >= rvlen { - d.arrayCannotExpand(rvlen, j+1) - d.swallow() - continue - } - - rv9 = rvArrayIndex(rv, j, f.ti, false) - if elemReset { - rvSetZero(rv9) - } - if d.d.TryNil() { - rvSetZero(rv9) - } else if builtin { - if rtelemIsPtr { - if rvIsNil(rv9) { - rvSetDirect(rv9, reflect.New(rtelemElem)) - } - d.decode(rv2i(rv9)) - } else { - d.decode(rv2i(rvAddr(rv9, ti.tielem.ptr))) - } - } else { - d.decodeValueNoCheckNil(rv9, fn) - } - } - if isArray { - d.arrayEnd() - } else { - d.mapEnd() - } -} - -func (d *decoderSimpleIO) kChan(f *decFnInfo, rv reflect.Value) { - _ = d.d - - ti := f.ti - if ti.chandir&uint8(reflect.SendDir) == 0 { - halt.errorStr("receive-only channel cannot be decoded") - } - ctyp := d.d.ContainerType() - if ctyp == valueTypeBytes || ctyp == valueTypeString { - - if !(ti.rtid == uint8SliceTypId || ti.elemkind == uint8(reflect.Uint8)) { - halt.errorf("bytes/string in stream must decode into slice/array of bytes, not %v", ti.rt) - } - bs2, _ := d.d.DecodeBytes() - irv := rv2i(rv) - ch, ok := irv.(chan<- byte) - if !ok { - ch = irv.(chan byte) - } - for _, b := range bs2 { - ch <- b - } - return - } - - var rvCanset = rv.CanSet() - - var containerLenS int - isArray := ctyp == valueTypeArray - if isArray { - containerLenS = d.arrayStart(d.d.ReadArrayStart()) - } else if ctyp == valueTypeMap { - containerLenS = d.mapStart(d.d.ReadMapStart()) * 2 - } else { - halt.errorStr2("decoding into a slice, expect map/array - got ", ctyp.String()) - } - - if containerLenS == 0 { - if rvCanset && rvIsNil(rv) { - rvSetDirect(rv, reflect.MakeChan(ti.rt, 0)) - } - if isArray { - d.arrayEnd() - } else { - d.mapEnd() - } - return - } - - rtelem := ti.elem - useTransient := decUseTransient && ti.elemkind != byte(reflect.Ptr) && ti.tielem.flagCanTransient - - for k := reflect.Kind(ti.elemkind); k == reflect.Ptr; k = rtelem.Kind() { - rtelem = rtelem.Elem() - } - - var fn *decFnSimpleIO - - var rvChanged bool - var rv0 = rv - var rv9 reflect.Value - - var rvlen int - hasLen := containerLenS >= 0 - maxInitLen := d.maxInitLen() - - for j := 0; d.containerNext(j, containerLenS, hasLen); j++ { - if j == 0 { - if rvIsNil(rv) { - if hasLen { - rvlen = int(decInferLen(containerLenS, maxInitLen, uint(ti.elemsize))) - } else { - rvlen = decDefChanCap - } - if rvCanset { - rv = reflect.MakeChan(ti.rt, rvlen) - rvChanged = true - } else { - halt.errorStr("cannot decode into non-settable chan") - } - } - if fn == nil { - fn = d.fn(rtelem) - } - } - - if ctyp == valueTypeArray { - d.arrayElem(j == 0) - } else if j&1 == 0 { - d.mapElemKey(j == 0) - } else { - d.mapElemValue() - } - - if rv9.IsValid() { - rvSetZero(rv9) - } else if useTransient { - rv9 = d.perType.TransientAddrK(ti.elem, reflect.Kind(ti.elemkind)) - } else { - rv9 = rvZeroAddrK(ti.elem, reflect.Kind(ti.elemkind)) - } - if !d.d.TryNil() { - d.decodeValueNoCheckNil(rv9, fn) - } - rv.Send(rv9) - } - if isArray { - d.arrayEnd() - } else { - d.mapEnd() - } - - if rvChanged { - rvSetDirect(rv0, rv) - } - -} - -func (d *decoderSimpleIO) kMap(f *decFnInfo, rv reflect.Value) { - _ = d.d - containerLen := d.mapStart(d.d.ReadMapStart()) - ti := f.ti - if rvIsNil(rv) { - rvlen := int(decInferLen(containerLen, d.maxInitLen(), uint(ti.keysize+ti.elemsize))) - rvSetDirect(rv, makeMapReflect(ti.rt, rvlen)) - } - - if containerLen == 0 { - d.mapEnd() - return - } - - ktype, vtype := ti.key, ti.elem - ktypeId := rt2id(ktype) - vtypeKind := reflect.Kind(ti.elemkind) - ktypeKind := reflect.Kind(ti.keykind) - mparams := getMapReqParams(ti) - - vtypePtr := vtypeKind == reflect.Ptr - ktypePtr := ktypeKind == reflect.Ptr - - vTransient := decUseTransient && !vtypePtr && ti.tielem.flagCanTransient - - kTransient := vTransient && !ktypePtr && ti.tikey.flagCanTransient - - var vtypeElem reflect.Type - - var keyFn, valFn *decFnSimpleIO - var ktypeLo, vtypeLo = ktype, vtype - - if ktypeKind == reflect.Ptr { - for ktypeLo = ktype.Elem(); ktypeLo.Kind() == reflect.Ptr; ktypeLo = ktypeLo.Elem() { - } - } - - if vtypePtr { - vtypeElem = vtype.Elem() - for vtypeLo = vtypeElem; vtypeLo.Kind() == reflect.Ptr; vtypeLo = vtypeLo.Elem() { - } - } - - rvkMut := !scalarBitset.isset(ti.keykind) - rvvMut := !scalarBitset.isset(ti.elemkind) - rvvCanNil := isnilBitset.isset(ti.elemkind) - - var rvk, rvkn, rvv, rvvn, rvva, rvvz reflect.Value - - var doMapGet, doMapSet bool - - if !d.h.MapValueReset { - if rvvMut && (vtypeKind != reflect.Interface || !d.h.InterfaceReset) { - doMapGet = true - rvva = mapAddrLoopvarRV(vtype, vtypeKind) - } - } - - ktypeIsString := ktypeId == stringTypId - ktypeIsIntf := ktypeId == intfTypId - hasLen := containerLen >= 0 - - var kstr2bs []byte - var kstr string - - var mapKeyStringSharesBytesBuf bool - var att dBytesAttachState - - var vElem, kElem reflect.Type - kbuiltin := ti.tikey.flagDecBuiltin && ti.keykind != uint8(reflect.Slice) - vbuiltin := ti.tielem.flagDecBuiltin - if kbuiltin && ktypePtr { - kElem = ti.key.Elem() - } - if vbuiltin && vtypePtr { - vElem = ti.elem.Elem() - } - - for j := 0; d.containerNext(j, containerLen, hasLen); j++ { - mapKeyStringSharesBytesBuf = false - kstr = "" - if j == 0 { - - if kTransient { - rvk = d.perType.TransientAddr2K(ktype, ktypeKind) - } else { - rvk = rvZeroAddrK(ktype, ktypeKind) - } - if !rvkMut { - rvkn = rvk - } - if !rvvMut { - if vTransient { - rvvn = d.perType.TransientAddrK(vtype, vtypeKind) - } else { - rvvn = rvZeroAddrK(vtype, vtypeKind) - } - } - if !ktypeIsString && keyFn == nil { - keyFn = d.fn(ktypeLo) - } - if valFn == nil { - valFn = d.fn(vtypeLo) - } - } else if rvkMut { - rvSetZero(rvk) - } else { - rvk = rvkn - } - - d.mapElemKey(j == 0) - - if d.d.TryNil() { - rvSetZero(rvk) - } else if ktypeIsString { - kstr2bs, att = d.d.DecodeStringAsBytes() - kstr, mapKeyStringSharesBytesBuf = d.bytes2Str(kstr2bs, att) - rvSetString(rvk, kstr) - } else { - if kbuiltin { - if ktypePtr { - if rvIsNil(rvk) { - rvSetDirect(rvk, reflect.New(kElem)) - } - d.decode(rv2i(rvk)) - } else { - d.decode(rv2i(rvAddr(rvk, ti.tikey.ptr))) - } - } else { - d.decodeValueNoCheckNil(rvk, keyFn) - } - - if ktypeIsIntf { - if rvk2 := rvk.Elem(); rvk2.IsValid() && rvk2.Type() == uint8SliceTyp { - kstr2bs = rvGetBytes(rvk2) - kstr, mapKeyStringSharesBytesBuf = d.bytes2Str(kstr2bs, dBytesAttachView) - rvSetIntf(rvk, rv4istr(kstr)) - } - - } - } - - if mapKeyStringSharesBytesBuf && d.bufio { - if ktypeIsString { - rvSetString(rvk, d.detach2Str(kstr2bs, att)) - } else { - rvSetIntf(rvk, rv4istr(d.detach2Str(kstr2bs, att))) - } - mapKeyStringSharesBytesBuf = false - } - - d.mapElemValue() - - if d.d.TryNil() { - if mapKeyStringSharesBytesBuf { - if ktypeIsString { - rvSetString(rvk, d.detach2Str(kstr2bs, att)) - } else { - rvSetIntf(rvk, rv4istr(d.detach2Str(kstr2bs, att))) - } - } - - if !rvvz.IsValid() { - rvvz = rvZeroK(vtype, vtypeKind) - } - mapSet(rv, rvk, rvvz, mparams) - continue - } - - doMapSet = true - - if !rvvMut { - rvv = rvvn - } else if !doMapGet { - goto NEW_RVV - } else { - rvv = mapGet(rv, rvk, rvva, mparams) - if !rvv.IsValid() || (rvvCanNil && rvIsNil(rvv)) { - goto NEW_RVV - } - switch vtypeKind { - case reflect.Ptr, reflect.Map: - doMapSet = false - case reflect.Interface: - - rvvn = rvv.Elem() - if k := rvvn.Kind(); (k == reflect.Ptr || k == reflect.Map) && !rvIsNil(rvvn) { - d.decodeValueNoCheckNil(rvvn, nil) - continue - } - - rvvn = rvZeroAddrK(vtype, vtypeKind) - rvSetIntf(rvvn, rvv) - rvv = rvvn - default: - - if vTransient { - rvvn = d.perType.TransientAddrK(vtype, vtypeKind) - } else { - rvvn = rvZeroAddrK(vtype, vtypeKind) - } - rvSetDirect(rvvn, rvv) - rvv = rvvn - } - } - goto DECODE_VALUE_NO_CHECK_NIL - - NEW_RVV: - if vtypePtr { - rvv = reflect.New(vtypeElem) - } else if vTransient { - rvv = d.perType.TransientAddrK(vtype, vtypeKind) - } else { - rvv = rvZeroAddrK(vtype, vtypeKind) - } - - DECODE_VALUE_NO_CHECK_NIL: - if doMapSet && mapKeyStringSharesBytesBuf { - if ktypeIsString { - rvSetString(rvk, d.detach2Str(kstr2bs, att)) - } else { - rvSetIntf(rvk, rv4istr(d.detach2Str(kstr2bs, att))) - } - } - if vbuiltin { - if vtypePtr { - if rvIsNil(rvv) { - rvSetDirect(rvv, reflect.New(vElem)) - } - d.decode(rv2i(rvv)) - } else { - d.decode(rv2i(rvAddr(rvv, ti.tielem.ptr))) - } - } else { - d.decodeValueNoCheckNil(rvv, valFn) - } - if doMapSet { - mapSet(rv, rvk, rvv, mparams) - } - } - - d.mapEnd() -} - -func (d *decoderSimpleIO) init(h Handle) { - initHandle(h) - callMake(&d.d) - d.hh = h - d.h = h.getBasicHandle() - - d.err = errDecoderNotInitialized - - if d.h.InternString && d.is == nil { - d.is.init() - } - - d.fp = d.d.init(h, &d.decoderBase, d).(*fastpathDsSimpleIO) - - if d.bytes { - d.rtidFn = &d.h.rtidFnsDecBytes - d.rtidFnNoExt = &d.h.rtidFnsDecNoExtBytes - } else { - d.bufio = d.h.ReaderBufferSize > 0 - d.rtidFn = &d.h.rtidFnsDecIO - d.rtidFnNoExt = &d.h.rtidFnsDecNoExtIO - } - - d.reset() - -} - -func (d *decoderSimpleIO) reset() { - d.d.reset() - d.err = nil - d.c = 0 - d.depth = 0 - d.calls = 0 - - d.maxdepth = decDefMaxDepth - if d.h.MaxDepth > 0 { - d.maxdepth = d.h.MaxDepth - } - d.mtid = 0 - d.stid = 0 - d.mtr = false - d.str = false - if d.h.MapType != nil { - d.mtid = rt2id(d.h.MapType) - _, d.mtr = fastpathAvIndex(d.mtid) - } - if d.h.SliceType != nil { - d.stid = rt2id(d.h.SliceType) - _, d.str = fastpathAvIndex(d.stid) - } -} - -func (d *decoderSimpleIO) Reset(r io.Reader) { - if d.bytes { - halt.onerror(errDecNoResetBytesWithReader) - } - d.reset() - if r == nil { - r = &eofReader - } - d.d.resetInIO(r) -} - -func (d *decoderSimpleIO) ResetBytes(in []byte) { - if !d.bytes { - halt.onerror(errDecNoResetReaderWithBytes) - } - d.resetBytes(in) -} - -func (d *decoderSimpleIO) resetBytes(in []byte) { - d.reset() - if in == nil { - in = zeroByteSlice - } - d.d.resetInBytes(in) -} - -func (d *decoderSimpleIO) ResetString(s string) { - d.ResetBytes(bytesView(s)) -} - -func (d *decoderSimpleIO) Decode(v interface{}) (err error) { - - defer panicValToErr(d, callRecoverSentinel, &d.err, &err, debugging) - d.mustDecode(v) - return -} - -func (d *decoderSimpleIO) MustDecode(v interface{}) { - defer panicValToErr(d, callRecoverSentinel, &d.err, nil, true) - d.mustDecode(v) - return -} - -func (d *decoderSimpleIO) mustDecode(v interface{}) { - halt.onerror(d.err) - if d.hh == nil { - halt.onerror(errNoFormatHandle) - } - - d.calls++ - d.decode(v) - d.calls-- -} - -func (d *decoderSimpleIO) Release() {} - -func (d *decoderSimpleIO) swallow() { - d.d.nextValueBytes() -} - -func (d *decoderSimpleIO) nextValueBytes() []byte { - return d.d.nextValueBytes() -} - -func (d *decoderSimpleIO) decode(iv interface{}) { - _ = d.d - - rv, ok := isNil(iv, true) - if ok { - halt.onerror(errCannotDecodeIntoNil) - } - - switch v := iv.(type) { - - case *string: - *v = d.detach2Str(d.d.DecodeStringAsBytes()) - case *bool: - *v = d.d.DecodeBool() - case *int: - *v = int(chkOvf.IntV(d.d.DecodeInt64(), intBitsize)) - case *int8: - *v = int8(chkOvf.IntV(d.d.DecodeInt64(), 8)) - case *int16: - *v = int16(chkOvf.IntV(d.d.DecodeInt64(), 16)) - case *int32: - *v = int32(chkOvf.IntV(d.d.DecodeInt64(), 32)) - case *int64: - *v = d.d.DecodeInt64() - case *uint: - *v = uint(chkOvf.UintV(d.d.DecodeUint64(), uintBitsize)) - case *uint8: - *v = uint8(chkOvf.UintV(d.d.DecodeUint64(), 8)) - case *uint16: - *v = uint16(chkOvf.UintV(d.d.DecodeUint64(), 16)) - case *uint32: - *v = uint32(chkOvf.UintV(d.d.DecodeUint64(), 32)) - case *uint64: - *v = d.d.DecodeUint64() - case *uintptr: - *v = uintptr(chkOvf.UintV(d.d.DecodeUint64(), uintBitsize)) - case *float32: - *v = d.d.DecodeFloat32() - case *float64: - *v = d.d.DecodeFloat64() - case *complex64: - *v = complex(d.d.DecodeFloat32(), 0) - case *complex128: - *v = complex(d.d.DecodeFloat64(), 0) - case *[]byte: - *v, _ = d.decodeBytesInto(*v, false) - case []byte: - - d.decodeBytesInto(v[:len(v):len(v)], true) - case *time.Time: - *v = d.d.DecodeTime() - case *Raw: - *v = d.rawBytes() - - case *interface{}: - d.decodeValue(rv4iptr(v), nil) - - case reflect.Value: - if ok, _ = isDecodeable(v); !ok { - d.haltAsNotDecodeable(v) - } - d.decodeValue(v, nil) - - default: - - if skipFastpathTypeSwitchInDirectCall || !d.dh.fastpathDecodeTypeSwitch(iv, d) { - if !rv.IsValid() { - rv = reflect.ValueOf(iv) - } - if ok, _ = isDecodeable(rv); !ok { - d.haltAsNotDecodeable(rv) - } - d.decodeValue(rv, nil) - } - } -} - -func (d *decoderSimpleIO) decodeValue(rv reflect.Value, fn *decFnSimpleIO) { - if d.d.TryNil() { - decSetNonNilRV2Zero(rv) - } else { - d.decodeValueNoCheckNil(rv, fn) - } -} - -func (d *decoderSimpleIO) decodeValueNoCheckNil(rv reflect.Value, fn *decFnSimpleIO) { - - var rvp reflect.Value - var rvpValid bool -PTR: - if rv.Kind() == reflect.Ptr { - rvpValid = true - if rvIsNil(rv) { - rvSetDirect(rv, reflect.New(rv.Type().Elem())) - } - rvp = rv - rv = rv.Elem() - goto PTR - } - - if fn == nil { - fn = d.fn(rv.Type()) - } - if fn.i.addrD { - if rvpValid { - rv = rvp - } else if rv.CanAddr() { - rv = rvAddr(rv, fn.i.ti.ptr) - } else if fn.i.addrDf { - halt.errorStr("cannot decode into a non-pointer value") - } - } - fn.fd(d, &fn.i, rv) -} - -func (d *decoderSimpleIO) decodeAs(v interface{}, t reflect.Type, ext bool) { - if ext { - d.decodeValue(baseRV(v), d.fn(t)) - } else { - d.decodeValue(baseRV(v), d.fnNoExt(t)) - } -} - -func (d *decoderSimpleIO) structFieldNotFound(index int, rvkencname string) { - - if d.h.ErrorIfNoField { - if index >= 0 { - halt.errorInt("no matching struct field found when decoding stream array at index ", int64(index)) - } else if rvkencname != "" { - halt.errorStr2("no matching struct field found when decoding stream map with key ", rvkencname) - } - } - d.swallow() -} - -func (d *decoderSimpleIO) decodeBytesInto(out []byte, mustFit bool) (v []byte, state dBytesIntoState) { - v, att := d.d.DecodeBytes() - if cap(v) == 0 || (att >= dBytesAttachViewZerocopy && !mustFit) { - - return - } - if len(v) == 0 { - v = zeroByteSlice - return - } - if len(out) == len(v) { - state = dBytesIntoParamOut - } else if cap(out) >= len(v) { - out = out[:len(v)] - state = dBytesIntoParamOutSlice - } else if mustFit { - halt.errorf("bytes capacity insufficient for decoded bytes: got/expected: %d/%d", len(v), len(out)) - } else { - out = make([]byte, len(v)) - state = dBytesIntoNew - } - copy(out, v) - v = out - return -} - -func (d *decoderSimpleIO) rawBytes() (v []byte) { - - v = d.d.nextValueBytes() - if d.bytes && !d.h.ZeroCopy { - vv := make([]byte, len(v)) - copy(vv, v) - v = vv - } - return -} - -func (d *decoderSimpleIO) wrapErr(v error, err *error) { - *err = wrapCodecErr(v, d.hh.Name(), d.d.NumBytesRead(), false) -} - -func (d *decoderSimpleIO) NumBytesRead() int { - return d.d.NumBytesRead() -} - -func (d *decoderSimpleIO) containerNext(j, containerLen int, hasLen bool) bool { - - if hasLen { - return j < containerLen - } - return !d.d.CheckBreak() -} - -func (d *decoderSimpleIO) mapElemKey(firstTime bool) { - d.d.ReadMapElemKey(firstTime) - d.c = containerMapKey -} - -func (d *decoderSimpleIO) mapElemValue() { - d.d.ReadMapElemValue() - d.c = containerMapValue -} - -func (d *decoderSimpleIO) mapEnd() { - d.d.ReadMapEnd() - d.depthDecr() - d.c = 0 -} - -func (d *decoderSimpleIO) arrayElem(firstTime bool) { - d.d.ReadArrayElem(firstTime) - d.c = containerArrayElem -} - -func (d *decoderSimpleIO) arrayEnd() { - d.d.ReadArrayEnd() - d.depthDecr() - d.c = 0 -} - -func (d *decoderSimpleIO) interfaceExtConvertAndDecode(v interface{}, ext InterfaceExt) { - - var vv interface{} - d.decode(&vv) - ext.UpdateExt(v, vv) - -} - -func (d *decoderSimpleIO) fn(t reflect.Type) *decFnSimpleIO { - return d.dh.decFnViaBH(t, d.rtidFn, d.h, d.fp, false) -} - -func (d *decoderSimpleIO) fnNoExt(t reflect.Type) *decFnSimpleIO { - return d.dh.decFnViaBH(t, d.rtidFnNoExt, d.h, d.fp, true) -} - -func (helperDecDriverSimpleIO) newDecoderBytes(in []byte, h Handle) *decoderSimpleIO { - var c1 decoderSimpleIO - c1.bytes = true - c1.init(h) - c1.ResetBytes(in) - return &c1 -} - -func (helperDecDriverSimpleIO) newDecoderIO(in io.Reader, h Handle) *decoderSimpleIO { - var c1 decoderSimpleIO - c1.init(h) - c1.Reset(in) - return &c1 -} - -func (helperDecDriverSimpleIO) decFnloadFastpathUnderlying(ti *typeInfo, fp *fastpathDsSimpleIO) (f *fastpathDSimpleIO, u reflect.Type) { - rtid := rt2id(ti.fastpathUnderlying) - idx, ok := fastpathAvIndex(rtid) - if !ok { - return - } - f = &fp[idx] - if uint8(reflect.Array) == ti.kind { - u = reflect.ArrayOf(ti.rt.Len(), ti.elem) - } else { - u = f.rt - } - return -} - -func (helperDecDriverSimpleIO) decFindRtidFn(s []decRtidFnSimpleIO, rtid uintptr) (i uint, fn *decFnSimpleIO) { - - var h uint - var j = uint(len(s)) -LOOP: - if i < j { - h = (i + j) >> 1 - if s[h].rtid < rtid { - i = h + 1 - } else { - j = h - } - goto LOOP - } - if i < uint(len(s)) && s[i].rtid == rtid { - fn = s[i].fn - } - return -} - -func (helperDecDriverSimpleIO) decFromRtidFnSlice(fns *atomicRtidFnSlice) (s []decRtidFnSimpleIO) { - if v := fns.load(); v != nil { - s = *(lowLevelToPtr[[]decRtidFnSimpleIO](v)) - } - return -} - -func (dh helperDecDriverSimpleIO) decFnViaBH(rt reflect.Type, fns *atomicRtidFnSlice, x *BasicHandle, fp *fastpathDsSimpleIO, - checkExt bool) (fn *decFnSimpleIO) { - return dh.decFnVia(rt, fns, x.typeInfos(), &x.mu, x.extHandle, fp, - checkExt, x.CheckCircularRef, x.timeBuiltin, x.binaryHandle, x.jsonHandle) -} - -func (dh helperDecDriverSimpleIO) decFnVia(rt reflect.Type, fns *atomicRtidFnSlice, - tinfos *TypeInfos, mu *sync.Mutex, exth extHandle, fp *fastpathDsSimpleIO, - checkExt, checkCircularRef, timeBuiltin, binaryEncoding, json bool) (fn *decFnSimpleIO) { - rtid := rt2id(rt) - var sp []decRtidFnSimpleIO = dh.decFromRtidFnSlice(fns) - if sp != nil { - _, fn = dh.decFindRtidFn(sp, rtid) - } - if fn == nil { - fn = dh.decFnViaLoader(rt, rtid, fns, tinfos, mu, exth, fp, checkExt, checkCircularRef, timeBuiltin, binaryEncoding, json) - } - return -} - -func (dh helperDecDriverSimpleIO) decFnViaLoader(rt reflect.Type, rtid uintptr, fns *atomicRtidFnSlice, - tinfos *TypeInfos, mu *sync.Mutex, exth extHandle, fp *fastpathDsSimpleIO, - checkExt, checkCircularRef, timeBuiltin, binaryEncoding, json bool) (fn *decFnSimpleIO) { - - fn = dh.decFnLoad(rt, rtid, tinfos, exth, fp, checkExt, checkCircularRef, timeBuiltin, binaryEncoding, json) - var sp []decRtidFnSimpleIO - mu.Lock() - sp = dh.decFromRtidFnSlice(fns) - - if sp == nil { - sp = []decRtidFnSimpleIO{{rtid, fn}} - fns.store(ptrToLowLevel(&sp)) - } else { - idx, fn2 := dh.decFindRtidFn(sp, rtid) - if fn2 == nil { - sp2 := make([]decRtidFnSimpleIO, len(sp)+1) - copy(sp2[idx+1:], sp[idx:]) - copy(sp2, sp[:idx]) - sp2[idx] = decRtidFnSimpleIO{rtid, fn} - fns.store(ptrToLowLevel(&sp2)) - } - } - mu.Unlock() - return -} - -func (dh helperDecDriverSimpleIO) decFnLoad(rt reflect.Type, rtid uintptr, tinfos *TypeInfos, - exth extHandle, fp *fastpathDsSimpleIO, - checkExt, checkCircularRef, timeBuiltin, binaryEncoding, json bool) (fn *decFnSimpleIO) { - fn = new(decFnSimpleIO) - fi := &(fn.i) - ti := tinfos.get(rtid, rt) - fi.ti = ti - rk := reflect.Kind(ti.kind) - - fi.addrDf = true - - if rtid == timeTypId && timeBuiltin { - fn.fd = (*decoderSimpleIO).kTime - } else if rtid == rawTypId { - fn.fd = (*decoderSimpleIO).raw - } else if rtid == rawExtTypId { - fn.fd = (*decoderSimpleIO).rawExt - fi.addrD = true - } else if xfFn := exth.getExt(rtid, checkExt); xfFn != nil { - fi.xfTag, fi.xfFn = xfFn.tag, xfFn.ext - fn.fd = (*decoderSimpleIO).ext - fi.addrD = true - } else if ti.flagSelfer || ti.flagSelferPtr { - fn.fd = (*decoderSimpleIO).selferUnmarshal - fi.addrD = ti.flagSelferPtr - } else if supportMarshalInterfaces && binaryEncoding && - (ti.flagBinaryMarshaler || ti.flagBinaryMarshalerPtr) && - (ti.flagBinaryUnmarshaler || ti.flagBinaryUnmarshalerPtr) { - fn.fd = (*decoderSimpleIO).binaryUnmarshal - fi.addrD = ti.flagBinaryUnmarshalerPtr - } else if supportMarshalInterfaces && !binaryEncoding && json && - (ti.flagJsonMarshaler || ti.flagJsonMarshalerPtr) && - (ti.flagJsonUnmarshaler || ti.flagJsonUnmarshalerPtr) { - - fn.fd = (*decoderSimpleIO).jsonUnmarshal - fi.addrD = ti.flagJsonUnmarshalerPtr - } else if supportMarshalInterfaces && !binaryEncoding && - (ti.flagTextMarshaler || ti.flagTextMarshalerPtr) && - (ti.flagTextUnmarshaler || ti.flagTextUnmarshalerPtr) { - fn.fd = (*decoderSimpleIO).textUnmarshal - fi.addrD = ti.flagTextUnmarshalerPtr - } else { - if fastpathEnabled && (rk == reflect.Map || rk == reflect.Slice || rk == reflect.Array) { - var rtid2 uintptr - if !ti.flagHasPkgPath { - rtid2 = rtid - if rk == reflect.Array { - rtid2 = rt2id(ti.key) - } - if idx, ok := fastpathAvIndex(rtid2); ok { - fn.fd = fp[idx].decfn - fi.addrD = true - fi.addrDf = false - if rk == reflect.Array { - fi.addrD = false - } - } - } else { - - xfe, xrt := dh.decFnloadFastpathUnderlying(ti, fp) - if xfe != nil { - xfnf2 := xfe.decfn - if rk == reflect.Array { - fi.addrD = false - fn.fd = func(d *decoderSimpleIO, xf *decFnInfo, xrv reflect.Value) { - xfnf2(d, xf, rvConvert(xrv, xrt)) - } - } else { - fi.addrD = true - fi.addrDf = false - xptr2rt := reflect.PointerTo(xrt) - fn.fd = func(d *decoderSimpleIO, xf *decFnInfo, xrv reflect.Value) { - if xrv.Kind() == reflect.Ptr { - xfnf2(d, xf, rvConvert(xrv, xptr2rt)) - } else { - xfnf2(d, xf, rvConvert(xrv, xrt)) - } - } - } - } - } - } - if fn.fd == nil { - switch rk { - case reflect.Bool: - fn.fd = (*decoderSimpleIO).kBool - case reflect.String: - fn.fd = (*decoderSimpleIO).kString - case reflect.Int: - fn.fd = (*decoderSimpleIO).kInt - case reflect.Int8: - fn.fd = (*decoderSimpleIO).kInt8 - case reflect.Int16: - fn.fd = (*decoderSimpleIO).kInt16 - case reflect.Int32: - fn.fd = (*decoderSimpleIO).kInt32 - case reflect.Int64: - fn.fd = (*decoderSimpleIO).kInt64 - case reflect.Uint: - fn.fd = (*decoderSimpleIO).kUint - case reflect.Uint8: - fn.fd = (*decoderSimpleIO).kUint8 - case reflect.Uint16: - fn.fd = (*decoderSimpleIO).kUint16 - case reflect.Uint32: - fn.fd = (*decoderSimpleIO).kUint32 - case reflect.Uint64: - fn.fd = (*decoderSimpleIO).kUint64 - case reflect.Uintptr: - fn.fd = (*decoderSimpleIO).kUintptr - case reflect.Float32: - fn.fd = (*decoderSimpleIO).kFloat32 - case reflect.Float64: - fn.fd = (*decoderSimpleIO).kFloat64 - case reflect.Complex64: - fn.fd = (*decoderSimpleIO).kComplex64 - case reflect.Complex128: - fn.fd = (*decoderSimpleIO).kComplex128 - case reflect.Chan: - fn.fd = (*decoderSimpleIO).kChan - case reflect.Slice: - fn.fd = (*decoderSimpleIO).kSlice - case reflect.Array: - fi.addrD = false - fn.fd = (*decoderSimpleIO).kArray - case reflect.Struct: - if ti.simple { - fn.fd = (*decoderSimpleIO).kStructSimple - } else { - fn.fd = (*decoderSimpleIO).kStruct - } - case reflect.Map: - fn.fd = (*decoderSimpleIO).kMap - case reflect.Interface: - - fn.fd = (*decoderSimpleIO).kInterface - default: - - fn.fd = (*decoderSimpleIO).kErr - } - } - } - return -} -func (e *simpleEncDriverIO) EncodeNil() { - e.w.writen1(simpleVdNil) -} - -func (e *simpleEncDriverIO) EncodeBool(b bool) { - if e.h.EncZeroValuesAsNil && e.e.c != containerMapKey && !b { - e.EncodeNil() - return - } - if b { - e.w.writen1(simpleVdTrue) - } else { - e.w.writen1(simpleVdFalse) - } -} - -func (e *simpleEncDriverIO) EncodeFloat32(f float32) { - if e.h.EncZeroValuesAsNil && e.e.c != containerMapKey && f == 0.0 { - e.EncodeNil() - return - } - e.w.writen1(simpleVdFloat32) - e.w.writen4(bigen.PutUint32(math.Float32bits(f))) -} - -func (e *simpleEncDriverIO) EncodeFloat64(f float64) { - if e.h.EncZeroValuesAsNil && e.e.c != containerMapKey && f == 0.0 { - e.EncodeNil() - return - } - e.w.writen1(simpleVdFloat64) - e.w.writen8(bigen.PutUint64(math.Float64bits(f))) -} - -func (e *simpleEncDriverIO) EncodeInt(v int64) { - if v < 0 { - e.encUint(uint64(-v), simpleVdNegInt) - } else { - e.encUint(uint64(v), simpleVdPosInt) - } -} - -func (e *simpleEncDriverIO) EncodeUint(v uint64) { - e.encUint(v, simpleVdPosInt) -} - -func (e *simpleEncDriverIO) encUint(v uint64, bd uint8) { - if e.h.EncZeroValuesAsNil && e.e.c != containerMapKey && v == 0 { - e.EncodeNil() - return - } - if v <= math.MaxUint8 { - e.w.writen2(bd, uint8(v)) - } else if v <= math.MaxUint16 { - e.w.writen1(bd + 1) - e.w.writen2(bigen.PutUint16(uint16(v))) - } else if v <= math.MaxUint32 { - e.w.writen1(bd + 2) - e.w.writen4(bigen.PutUint32(uint32(v))) - } else { - e.w.writen1(bd + 3) - e.w.writen8(bigen.PutUint64(v)) - } -} - -func (e *simpleEncDriverIO) encLen(bd byte, length int) { - if length == 0 { - e.w.writen1(bd) - } else if length <= math.MaxUint8 { - e.w.writen1(bd + 1) - e.w.writen1(uint8(length)) - } else if length <= math.MaxUint16 { - e.w.writen1(bd + 2) - e.w.writen2(bigen.PutUint16(uint16(length))) - } else if int64(length) <= math.MaxUint32 { - e.w.writen1(bd + 3) - e.w.writen4(bigen.PutUint32(uint32(length))) - } else { - e.w.writen1(bd + 4) - e.w.writen8(bigen.PutUint64(uint64(length))) - } -} - -func (e *simpleEncDriverIO) EncodeExt(v interface{}, basetype reflect.Type, xtag uint64, ext Ext) { - var bs0, bs []byte - if ext == SelfExt { - bs0 = e.e.blist.get(1024) - bs = bs0 - sideEncode(e.h, &e.h.sideEncPool, func(se encoderI) { oneOffEncode(se, v, &bs, basetype, true) }) - } else { - bs = ext.WriteExt(v) - } - if bs == nil { - e.writeNilBytes() - goto END - } - e.encodeExtPreamble(uint8(xtag), len(bs)) - e.w.writeb(bs) -END: - if ext == SelfExt { - e.e.blist.put(bs) - if !byteSliceSameData(bs0, bs) { - e.e.blist.put(bs0) - } - } -} - -func (e *simpleEncDriverIO) EncodeRawExt(re *RawExt) { - e.encodeExtPreamble(uint8(re.Tag), len(re.Data)) - e.w.writeb(re.Data) -} - -func (e *simpleEncDriverIO) encodeExtPreamble(xtag byte, length int) { - e.encLen(simpleVdExt, length) - e.w.writen1(xtag) -} - -func (e *simpleEncDriverIO) WriteArrayStart(length int) { - e.encLen(simpleVdArray, length) -} - -func (e *simpleEncDriverIO) WriteMapStart(length int) { - e.encLen(simpleVdMap, length) -} - -func (e *simpleEncDriverIO) WriteArrayEmpty() { - - e.w.writen1(simpleVdArray) -} - -func (e *simpleEncDriverIO) WriteMapEmpty() { - - e.w.writen1(simpleVdMap) -} - -func (e *simpleEncDriverIO) EncodeString(v string) { - if e.h.EncZeroValuesAsNil && e.e.c != containerMapKey && v == "" { - e.EncodeNil() - return - } - if e.h.StringToRaw { - e.encLen(simpleVdByteArray, len(v)) - } else { - e.encLen(simpleVdString, len(v)) - } - e.w.writestr(v) -} - -func (e *simpleEncDriverIO) EncodeStringNoEscape4Json(v string) { e.EncodeString(v) } - -func (e *simpleEncDriverIO) EncodeStringBytesRaw(v []byte) { - - e.encLen(simpleVdByteArray, len(v)) - e.w.writeb(v) -} - -func (e *simpleEncDriverIO) EncodeBytes(v []byte) { - if v == nil { - e.writeNilBytes() - return - } - e.EncodeStringBytesRaw(v) -} - -func (e *simpleEncDriverIO) encodeNilBytes() { - b := byte(simpleVdNil) - if e.h.NilCollectionToZeroLength { - b = simpleVdArray - } - e.w.writen1(b) -} - -func (e *simpleEncDriverIO) writeNilOr(v byte) { - if !e.h.NilCollectionToZeroLength { - v = simpleVdNil - } - e.w.writen1(v) -} - -func (e *simpleEncDriverIO) writeNilArray() { - e.writeNilOr(simpleVdArray) -} - -func (e *simpleEncDriverIO) writeNilMap() { - e.writeNilOr(simpleVdMap) -} - -func (e *simpleEncDriverIO) writeNilBytes() { - e.writeNilOr(simpleVdByteArray) -} - -func (e *simpleEncDriverIO) EncodeTime(t time.Time) { - - if t.IsZero() { - e.EncodeNil() - return - } - v, err := t.MarshalBinary() - halt.onerror(err) - e.w.writen2(simpleVdTime, uint8(len(v))) - e.w.writeb(v) -} - -func (d *simpleDecDriverIO) readNextBd() { - d.bd = d.r.readn1() - d.bdRead = true -} - -func (d *simpleDecDriverIO) advanceNil() (null bool) { - if !d.bdRead { - d.readNextBd() - } - if d.bd == simpleVdNil { - d.bdRead = false - return true - } - return -} - -func (d *simpleDecDriverIO) ContainerType() (vt valueType) { - if !d.bdRead { - d.readNextBd() - } - switch d.bd { - case simpleVdNil: - d.bdRead = false - return valueTypeNil - case simpleVdByteArray, simpleVdByteArray + 1, - simpleVdByteArray + 2, simpleVdByteArray + 3, simpleVdByteArray + 4: - return valueTypeBytes - case simpleVdString, simpleVdString + 1, - simpleVdString + 2, simpleVdString + 3, simpleVdString + 4: - return valueTypeString - case simpleVdArray, simpleVdArray + 1, - simpleVdArray + 2, simpleVdArray + 3, simpleVdArray + 4: - return valueTypeArray - case simpleVdMap, simpleVdMap + 1, - simpleVdMap + 2, simpleVdMap + 3, simpleVdMap + 4: - return valueTypeMap - } - return valueTypeUnset -} - -func (d *simpleDecDriverIO) TryNil() bool { - return d.advanceNil() -} - -func (d *simpleDecDriverIO) decFloat() (f float64, ok bool) { - ok = true - switch d.bd { - case simpleVdFloat32: - f = float64(math.Float32frombits(bigen.Uint32(d.r.readn4()))) - case simpleVdFloat64: - f = math.Float64frombits(bigen.Uint64(d.r.readn8())) - default: - ok = false - } - return -} - -func (d *simpleDecDriverIO) decInteger() (ui uint64, neg, ok bool) { - ok = true - switch d.bd { - case simpleVdPosInt: - ui = uint64(d.r.readn1()) - case simpleVdPosInt + 1: - ui = uint64(bigen.Uint16(d.r.readn2())) - case simpleVdPosInt + 2: - ui = uint64(bigen.Uint32(d.r.readn4())) - case simpleVdPosInt + 3: - ui = uint64(bigen.Uint64(d.r.readn8())) - case simpleVdNegInt: - ui = uint64(d.r.readn1()) - neg = true - case simpleVdNegInt + 1: - ui = uint64(bigen.Uint16(d.r.readn2())) - neg = true - case simpleVdNegInt + 2: - ui = uint64(bigen.Uint32(d.r.readn4())) - neg = true - case simpleVdNegInt + 3: - ui = uint64(bigen.Uint64(d.r.readn8())) - neg = true - default: - ok = false - - } - - return -} - -func (d *simpleDecDriverIO) DecodeInt64() (i int64) { - if d.advanceNil() { - return - } - v1, v2, v3 := d.decInteger() - i = decNegintPosintFloatNumberHelper{d}.int64(v1, v2, v3, false) - d.bdRead = false - return -} - -func (d *simpleDecDriverIO) DecodeUint64() (ui uint64) { - if d.advanceNil() { - return - } - ui = decNegintPosintFloatNumberHelper{d}.uint64(d.decInteger()) - d.bdRead = false - return -} - -func (d *simpleDecDriverIO) DecodeFloat64() (f float64) { - if d.advanceNil() { - return - } - v1, v2 := d.decFloat() - f = decNegintPosintFloatNumberHelper{d}.float64(v1, v2, false) - d.bdRead = false - return -} - -func (d *simpleDecDriverIO) DecodeBool() (b bool) { - if d.advanceNil() { - return - } - if d.bd == simpleVdFalse { - } else if d.bd == simpleVdTrue { - b = true - } else { - halt.errorf("cannot decode bool - %s: %x", msgBadDesc, d.bd) - } - d.bdRead = false - return -} - -func (d *simpleDecDriverIO) ReadMapStart() (length int) { - if d.advanceNil() { - return containerLenNil - } - d.bdRead = false - return d.decLen() -} - -func (d *simpleDecDriverIO) ReadArrayStart() (length int) { - if d.advanceNil() { - return containerLenNil - } - d.bdRead = false - return d.decLen() -} - -func (d *simpleDecDriverIO) uint2Len(ui uint64) int { - if chkOvf.Uint(ui, intBitsize) { - halt.errorf("overflow integer: %v", ui) - } - return int(ui) -} - -func (d *simpleDecDriverIO) decLen() int { - switch d.bd & 7 { - case 0: - return 0 - case 1: - return int(d.r.readn1()) - case 2: - return int(bigen.Uint16(d.r.readn2())) - case 3: - return d.uint2Len(uint64(bigen.Uint32(d.r.readn4()))) - case 4: - return d.uint2Len(bigen.Uint64(d.r.readn8())) - } - halt.errorf("cannot read length: bd%%8 must be in range 0..4. Got: %d", d.bd%8) - return -1 -} - -func (d *simpleDecDriverIO) DecodeStringAsBytes() ([]byte, dBytesAttachState) { - return d.DecodeBytes() -} - -func (d *simpleDecDriverIO) DecodeBytes() (bs []byte, state dBytesAttachState) { - if d.advanceNil() { - return - } - var cond bool - - if d.bd >= simpleVdArray && d.bd <= simpleVdArray+4 { - slen := d.ReadArrayStart() - bs, cond = usableByteSlice(d.d.buf, slen) - for i := 0; i < len(bs); i++ { - bs[i] = uint8(chkOvf.UintV(d.DecodeUint64(), 8)) - } - for i := len(bs); i < slen; i++ { - bs = append(bs, uint8(chkOvf.UintV(d.DecodeUint64(), 8))) - } - if cond { - d.d.buf = bs - } - state = dBytesAttachBuffer - - return - } - - clen := d.decLen() - d.bdRead = false - bs, cond = d.r.readxb(uint(clen)) - state = d.d.attachState(cond) - return -} - -func (d *simpleDecDriverIO) DecodeTime() (t time.Time) { - if d.advanceNil() { - return - } - if d.bd != simpleVdTime { - halt.errorf("invalid descriptor for time.Time - expect 0x%x, received 0x%x", simpleVdTime, d.bd) - } - d.bdRead = false - clen := uint(d.r.readn1()) - b := d.r.readx(clen) - halt.onerror((&t).UnmarshalBinary(b)) - return -} - -func (d *simpleDecDriverIO) DecodeExt(rv interface{}, basetype reflect.Type, xtag uint64, ext Ext) { - xbs, _, _, ok := d.decodeExtV(ext != nil, xtag) - if !ok { - return - } - if ext == SelfExt { - sideDecode(d.h, &d.h.sideDecPool, func(sd decoderI) { oneOffDecode(sd, rv, xbs, basetype, true) }) - } else { - ext.ReadExt(rv, xbs) - } -} - -func (d *simpleDecDriverIO) DecodeRawExt(re *RawExt) { - xbs, realxtag, state, ok := d.decodeExtV(false, 0) - if !ok { - return - } - re.Tag = uint64(realxtag) - re.setData(xbs, state >= dBytesAttachViewZerocopy) -} - -func (d *simpleDecDriverIO) decodeExtV(verifyTag bool, xtagIn uint64) (xbs []byte, xtag byte, bstate dBytesAttachState, ok bool) { - if xtagIn > 0xff { - halt.errorf("ext: tag must be <= 0xff; got: %v", xtagIn) - } - if d.advanceNil() { - return - } - tag := uint8(xtagIn) - switch d.bd { - case simpleVdExt, simpleVdExt + 1, simpleVdExt + 2, simpleVdExt + 3, simpleVdExt + 4: - l := d.decLen() - xtag = d.r.readn1() - if verifyTag && xtag != tag { - halt.errorf("wrong extension tag. Got %b. Expecting: %v", xtag, tag) - } - xbs, ok = d.r.readxb(uint(l)) - bstate = d.d.attachState(ok) - case simpleVdByteArray, simpleVdByteArray + 1, - simpleVdByteArray + 2, simpleVdByteArray + 3, simpleVdByteArray + 4: - xbs, bstate = d.DecodeBytes() - default: - halt.errorf("ext - %s - expecting extensions/bytearray, got: 0x%x", msgBadDesc, d.bd) - } - d.bdRead = false - ok = true - return -} - -func (d *simpleDecDriverIO) DecodeNaked() { - if !d.bdRead { - d.readNextBd() - } - - n := d.d.naked() - var decodeFurther bool - - switch d.bd { - case simpleVdNil: - n.v = valueTypeNil - case simpleVdFalse: - n.v = valueTypeBool - n.b = false - case simpleVdTrue: - n.v = valueTypeBool - n.b = true - case simpleVdPosInt, simpleVdPosInt + 1, simpleVdPosInt + 2, simpleVdPosInt + 3: - if d.h.SignedInteger { - n.v = valueTypeInt - n.i = d.DecodeInt64() - } else { - n.v = valueTypeUint - n.u = d.DecodeUint64() - } - case simpleVdNegInt, simpleVdNegInt + 1, simpleVdNegInt + 2, simpleVdNegInt + 3: - n.v = valueTypeInt - n.i = d.DecodeInt64() - case simpleVdFloat32: - n.v = valueTypeFloat - n.f = d.DecodeFloat64() - case simpleVdFloat64: - n.v = valueTypeFloat - n.f = d.DecodeFloat64() - case simpleVdTime: - n.v = valueTypeTime - n.t = d.DecodeTime() - case simpleVdString, simpleVdString + 1, - simpleVdString + 2, simpleVdString + 3, simpleVdString + 4: - n.v = valueTypeString - n.s = d.d.detach2Str(d.DecodeStringAsBytes()) - case simpleVdByteArray, simpleVdByteArray + 1, - simpleVdByteArray + 2, simpleVdByteArray + 3, simpleVdByteArray + 4: - d.d.fauxUnionReadRawBytes(d, false, d.h.RawToString) - case simpleVdExt, simpleVdExt + 1, simpleVdExt + 2, simpleVdExt + 3, simpleVdExt + 4: - n.v = valueTypeExt - l := d.decLen() - n.u = uint64(d.r.readn1()) - n.l = d.r.readx(uint(l)) - - case simpleVdArray, simpleVdArray + 1, simpleVdArray + 2, - simpleVdArray + 3, simpleVdArray + 4: - n.v = valueTypeArray - decodeFurther = true - case simpleVdMap, simpleVdMap + 1, simpleVdMap + 2, simpleVdMap + 3, simpleVdMap + 4: - n.v = valueTypeMap - decodeFurther = true - default: - halt.errorf("cannot infer value - %s 0x%x", msgBadDesc, d.bd) - } - - if !decodeFurther { - d.bdRead = false - } -} - -func (d *simpleDecDriverIO) nextValueBytes() (v []byte) { - if !d.bdRead { - d.readNextBd() - } - d.r.startRecording() - d.nextValueBytesBdReadR() - v = d.r.stopRecording() - d.bdRead = false - return -} - -func (d *simpleDecDriverIO) nextValueBytesBdReadR() { - c := d.bd - - var length uint - - switch c { - case simpleVdNil, simpleVdFalse, simpleVdTrue, simpleVdString, simpleVdByteArray: - - case simpleVdPosInt, simpleVdNegInt: - d.r.readn1() - case simpleVdPosInt + 1, simpleVdNegInt + 1: - d.r.skip(2) - case simpleVdPosInt + 2, simpleVdNegInt + 2, simpleVdFloat32: - d.r.skip(4) - case simpleVdPosInt + 3, simpleVdNegInt + 3, simpleVdFloat64: - d.r.skip(8) - case simpleVdTime: - c = d.r.readn1() - d.r.skip(uint(c)) - - default: - switch c & 7 { - case 0: - length = 0 - case 1: - b := d.r.readn1() - length = uint(b) - case 2: - x := d.r.readn2() - length = uint(bigen.Uint16(x)) - case 3: - x := d.r.readn4() - length = uint(bigen.Uint32(x)) - case 4: - x := d.r.readn8() - length = uint(bigen.Uint64(x)) - } - - bExt := c >= simpleVdExt && c <= simpleVdExt+7 - bStr := c >= simpleVdString && c <= simpleVdString+7 - bByteArray := c >= simpleVdByteArray && c <= simpleVdByteArray+7 - bArray := c >= simpleVdArray && c <= simpleVdArray+7 - bMap := c >= simpleVdMap && c <= simpleVdMap+7 - - if !(bExt || bStr || bByteArray || bArray || bMap) { - halt.errorf("cannot infer value - %s 0x%x", msgBadDesc, c) - } - - if bExt { - d.r.readn1() - } - - if length == 0 { - break - } - - if bArray { - for i := uint(0); i < length; i++ { - d.readNextBd() - d.nextValueBytesBdReadR() - } - } else if bMap { - for i := uint(0); i < length; i++ { - d.readNextBd() - d.nextValueBytesBdReadR() - d.readNextBd() - d.nextValueBytesBdReadR() - } - } else { - d.r.skip(length) - } - } - return -} - -func (d *simpleEncDriverIO) init(hh Handle, shared *encoderBase, enc encoderI) (fp interface{}) { - callMake(&d.w) - d.h = hh.(*SimpleHandle) - d.e = shared - if shared.bytes { - fp = simpleFpEncBytes - } else { - fp = simpleFpEncIO - } - - d.init2(enc) - return -} - -func (e *simpleEncDriverIO) writeBytesAsis(b []byte) { e.w.writeb(b) } - -func (e *simpleEncDriverIO) writerEnd() { e.w.end() } - -func (e *simpleEncDriverIO) resetOutBytes(out *[]byte) { - e.w.resetBytes(*out, out) -} - -func (e *simpleEncDriverIO) resetOutIO(out io.Writer) { - e.w.resetIO(out, e.h.WriterBufferSize, &e.e.blist) -} - -func (d *simpleDecDriverIO) init(hh Handle, shared *decoderBase, dec decoderI) (fp interface{}) { - callMake(&d.r) - d.h = hh.(*SimpleHandle) - d.d = shared - if shared.bytes { - fp = simpleFpDecBytes - } else { - fp = simpleFpDecIO - } - - d.init2(dec) - return -} - -func (d *simpleDecDriverIO) NumBytesRead() int { - return int(d.r.numread()) -} - -func (d *simpleDecDriverIO) resetInBytes(in []byte) { - d.r.resetBytes(in) -} - -func (d *simpleDecDriverIO) resetInIO(r io.Reader) { - d.r.resetIO(r, d.h.ReaderBufferSize, d.h.MaxInitLen, &d.d.blist) -} - -func (d *simpleDecDriverIO) descBd() string { - return sprintf("%v (%s)", d.bd, simpledesc(d.bd)) -} - -func (d *simpleDecDriverIO) DecodeFloat32() (f float32) { - return float32(chkOvf.Float32V(d.DecodeFloat64())) -} diff --git a/vendor/github.com/ugorji/go/codec/simple.notfastpath.mono.generated.go b/vendor/github.com/ugorji/go/codec/simple.notfastpath.mono.generated.go deleted file mode 100644 index 04edb7438..000000000 --- a/vendor/github.com/ugorji/go/codec/simple.notfastpath.mono.generated.go +++ /dev/null @@ -1,52 +0,0 @@ -//go:build !notmono && !codec.notmono && (notfastpath || codec.notfastpath) - -// Copyright (c) 2012-2020 Ugorji Nwoke. All rights reserved. -// Use of this source code is governed by a MIT license found in the LICENSE file. - -package codec - -import ( - "reflect" -) - -type fastpathESimpleBytes struct { - rt reflect.Type - encfn func(*encoderSimpleBytes, *encFnInfo, reflect.Value) -} -type fastpathDSimpleBytes struct { - rt reflect.Type - decfn func(*decoderSimpleBytes, *decFnInfo, reflect.Value) -} -type fastpathEsSimpleBytes [0]fastpathESimpleBytes -type fastpathDsSimpleBytes [0]fastpathDSimpleBytes - -func (helperEncDriverSimpleBytes) fastpathEncodeTypeSwitch(iv interface{}, e *encoderSimpleBytes) bool { - return false -} -func (helperDecDriverSimpleBytes) fastpathDecodeTypeSwitch(iv interface{}, d *decoderSimpleBytes) bool { - return false -} - -func (helperEncDriverSimpleBytes) fastpathEList() (v *fastpathEsSimpleBytes) { return } -func (helperDecDriverSimpleBytes) fastpathDList() (v *fastpathDsSimpleBytes) { return } - -type fastpathESimpleIO struct { - rt reflect.Type - encfn func(*encoderSimpleIO, *encFnInfo, reflect.Value) -} -type fastpathDSimpleIO struct { - rt reflect.Type - decfn func(*decoderSimpleIO, *decFnInfo, reflect.Value) -} -type fastpathEsSimpleIO [0]fastpathESimpleIO -type fastpathDsSimpleIO [0]fastpathDSimpleIO - -func (helperEncDriverSimpleIO) fastpathEncodeTypeSwitch(iv interface{}, e *encoderSimpleIO) bool { - return false -} -func (helperDecDriverSimpleIO) fastpathDecodeTypeSwitch(iv interface{}, d *decoderSimpleIO) bool { - return false -} - -func (helperEncDriverSimpleIO) fastpathEList() (v *fastpathEsSimpleIO) { return } -func (helperDecDriverSimpleIO) fastpathDList() (v *fastpathDsSimpleIO) { return } diff --git a/vendor/github.com/ugorji/go/codec/test-cbor-goldens.json b/vendor/github.com/ugorji/go/codec/test-cbor-goldens.json deleted file mode 100644 index 902858671..000000000 --- a/vendor/github.com/ugorji/go/codec/test-cbor-goldens.json +++ /dev/null @@ -1,639 +0,0 @@ -[ - { - "cbor": "AA==", - "hex": "00", - "roundtrip": true, - "decoded": 0 - }, - { - "cbor": "AQ==", - "hex": "01", - "roundtrip": true, - "decoded": 1 - }, - { - "cbor": "Cg==", - "hex": "0a", - "roundtrip": true, - "decoded": 10 - }, - { - "cbor": "Fw==", - "hex": "17", - "roundtrip": true, - "decoded": 23 - }, - { - "cbor": "GBg=", - "hex": "1818", - "roundtrip": true, - "decoded": 24 - }, - { - "cbor": "GBk=", - "hex": "1819", - "roundtrip": true, - "decoded": 25 - }, - { - "cbor": "GGQ=", - "hex": "1864", - "roundtrip": true, - "decoded": 100 - }, - { - "cbor": "GQPo", - "hex": "1903e8", - "roundtrip": true, - "decoded": 1000 - }, - { - "cbor": "GgAPQkA=", - "hex": "1a000f4240", - "roundtrip": true, - "decoded": 1000000 - }, - { - "cbor": "GwAAAOjUpRAA", - "hex": "1b000000e8d4a51000", - "roundtrip": true, - "decoded": 1000000000000 - }, - { - "cbor": "G///////////", - "hex": "1bffffffffffffffff", - "roundtrip": true, - "decoded": 18446744073709551615 - }, - { - "cbor": "wkkBAAAAAAAAAAA=", - "hex": "c249010000000000000000", - "roundtrip": true, - "decoded": 18446744073709551616 - }, - { - "cbor": "O///////////", - "hex": "3bffffffffffffffff", - "roundtrip": true, - "decoded": -18446744073709551616, - "skip": true - }, - { - "cbor": "w0kBAAAAAAAAAAA=", - "hex": "c349010000000000000000", - "roundtrip": true, - "decoded": -18446744073709551617 - }, - { - "cbor": "IA==", - "hex": "20", - "roundtrip": true, - "decoded": -1 - }, - { - "cbor": "KQ==", - "hex": "29", - "roundtrip": true, - "decoded": -10 - }, - { - "cbor": "OGM=", - "hex": "3863", - "roundtrip": true, - "decoded": -100 - }, - { - "cbor": "OQPn", - "hex": "3903e7", - "roundtrip": true, - "decoded": -1000 - }, - { - "cbor": "+QAA", - "hex": "f90000", - "roundtrip": true, - "decoded": 0.0 - }, - { - "cbor": "+YAA", - "hex": "f98000", - "roundtrip": true, - "decoded": -0.0 - }, - { - "cbor": "+TwA", - "hex": "f93c00", - "roundtrip": true, - "decoded": 1.0 - }, - { - "cbor": "+z/xmZmZmZma", - "hex": "fb3ff199999999999a", - "roundtrip": true, - "decoded": 1.1 - }, - { - "cbor": "+T4A", - "hex": "f93e00", - "roundtrip": true, - "decoded": 1.5 - }, - { - "cbor": "+Xv/", - "hex": "f97bff", - "roundtrip": true, - "decoded": 65504.0 - }, - { - "cbor": "+kfDUAA=", - "hex": "fa47c35000", - "roundtrip": true, - "decoded": 100000.0 - }, - { - "cbor": "+n9///8=", - "hex": "fa7f7fffff", - "roundtrip": true, - "decoded": 3.4028234663852886e+38 - }, - { - "cbor": "+3435DyIAHWc", - "hex": "fb7e37e43c8800759c", - "roundtrip": true, - "decoded": 1.0e+300 - }, - { - "cbor": "+QAB", - "hex": "f90001", - "roundtrip": true, - "decoded": 5.960464477539063e-08 - }, - { - "cbor": "+QQA", - "hex": "f90400", - "roundtrip": true, - "decoded": 6.103515625e-05 - }, - { - "cbor": "+cQA", - "hex": "f9c400", - "roundtrip": true, - "decoded": -4.0 - }, - { - "cbor": "+8AQZmZmZmZm", - "hex": "fbc010666666666666", - "roundtrip": true, - "decoded": -4.1 - }, - { - "cbor": "+XwA", - "hex": "f97c00", - "roundtrip": true, - "diagnostic": "Infinity" - }, - { - "cbor": "+X4A", - "hex": "f97e00", - "roundtrip": true, - "diagnostic": "NaN" - }, - { - "cbor": "+fwA", - "hex": "f9fc00", - "roundtrip": true, - "diagnostic": "-Infinity" - }, - { - "cbor": "+n+AAAA=", - "hex": "fa7f800000", - "roundtrip": false, - "diagnostic": "Infinity" - }, - { - "cbor": "+n/AAAA=", - "hex": "fa7fc00000", - "roundtrip": false, - "diagnostic": "NaN" - }, - { - "cbor": "+v+AAAA=", - "hex": "faff800000", - "roundtrip": false, - "diagnostic": "-Infinity" - }, - { - "cbor": "+3/wAAAAAAAA", - "hex": "fb7ff0000000000000", - "roundtrip": false, - "diagnostic": "Infinity" - }, - { - "cbor": "+3/4AAAAAAAA", - "hex": "fb7ff8000000000000", - "roundtrip": false, - "diagnostic": "NaN" - }, - { - "cbor": "+//wAAAAAAAA", - "hex": "fbfff0000000000000", - "roundtrip": false, - "diagnostic": "-Infinity" - }, - { - "cbor": "9A==", - "hex": "f4", - "roundtrip": true, - "decoded": false - }, - { - "cbor": "9Q==", - "hex": "f5", - "roundtrip": true, - "decoded": true - }, - { - "cbor": "9g==", - "hex": "f6", - "roundtrip": true, - "decoded": null - }, - { - "cbor": "9w==", - "hex": "f7", - "roundtrip": true, - "diagnostic": "undefined" - }, - { - "cbor": "8A==", - "hex": "f0", - "roundtrip": true, - "diagnostic": "simple(16)" - }, - { - "cbor": "+Bg=", - "hex": "f818", - "roundtrip": true, - "diagnostic": "simple(24)" - }, - { - "cbor": "+P8=", - "hex": "f8ff", - "roundtrip": true, - "diagnostic": "simple(255)" - }, - { - "cbor": "wHQyMDEzLTAzLTIxVDIwOjA0OjAwWg==", - "hex": "c074323031332d30332d32315432303a30343a30305a", - "roundtrip": true, - "diagnostic": "0(\"2013-03-21T20:04:00Z\")" - }, - { - "cbor": "wRpRS2ew", - "hex": "c11a514b67b0", - "roundtrip": true, - "diagnostic": "1(1363896240)" - }, - { - "cbor": "wftB1FLZ7CAAAA==", - "hex": "c1fb41d452d9ec200000", - "roundtrip": true, - "diagnostic": "1(1363896240.5)" - }, - { - "cbor": "10QBAgME", - "hex": "d74401020304", - "roundtrip": true, - "diagnostic": "23(h'01020304')" - }, - { - "cbor": "2BhFZElFVEY=", - "hex": "d818456449455446", - "roundtrip": true, - "diagnostic": "24(h'6449455446')" - }, - { - "cbor": "2CB2aHR0cDovL3d3dy5leGFtcGxlLmNvbQ==", - "hex": "d82076687474703a2f2f7777772e6578616d706c652e636f6d", - "roundtrip": true, - "diagnostic": "32(\"http://www.example.com\")" - }, - { - "cbor": "QA==", - "hex": "40", - "roundtrip": true, - "diagnostic": "h''" - }, - { - "cbor": "RAECAwQ=", - "hex": "4401020304", - "roundtrip": true, - "diagnostic": "h'01020304'" - }, - { - "cbor": "YA==", - "hex": "60", - "roundtrip": true, - "decoded": "" - }, - { - "cbor": "YWE=", - "hex": "6161", - "roundtrip": true, - "decoded": "a" - }, - { - "cbor": "ZElFVEY=", - "hex": "6449455446", - "roundtrip": true, - "decoded": "IETF" - }, - { - "cbor": "YiJc", - "hex": "62225c", - "roundtrip": true, - "decoded": "\"\\" - }, - { - "cbor": "YsO8", - "hex": "62c3bc", - "roundtrip": true, - "decoded": "ü" - }, - { - "cbor": "Y+awtA==", - "hex": "63e6b0b4", - "roundtrip": true, - "decoded": "水" - }, - { - "cbor": "ZPCQhZE=", - "hex": "64f0908591", - "roundtrip": true, - "decoded": "𐅑" - }, - { - "cbor": "gA==", - "hex": "80", - "roundtrip": true, - "decoded": [ - - ] - }, - { - "cbor": "gwECAw==", - "hex": "83010203", - "roundtrip": true, - "decoded": [ - 1, - 2, - 3 - ] - }, - { - "cbor": "gwGCAgOCBAU=", - "hex": "8301820203820405", - "roundtrip": true, - "decoded": [ - 1, - [ - 2, - 3 - ], - [ - 4, - 5 - ] - ] - }, - { - "cbor": "mBkBAgMEBQYHCAkKCwwNDg8QERITFBUWFxgYGBk=", - "hex": "98190102030405060708090a0b0c0d0e0f101112131415161718181819", - "roundtrip": true, - "decoded": [ - 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 - ] - }, - { - "cbor": "oA==", - "hex": "a0", - "roundtrip": true, - "decoded": { - } - }, - { - "cbor": "ogECAwQ=", - "hex": "a201020304", - "roundtrip": true, - "skip": true, - "diagnostic": "{1: 2, 3: 4}" - }, - { - "cbor": "omFhAWFiggID", - "hex": "a26161016162820203", - "roundtrip": true, - "decoded": { - "a": 1, - "b": [ - 2, - 3 - ] - } - }, - { - "cbor": "gmFhoWFiYWM=", - "hex": "826161a161626163", - "roundtrip": true, - "decoded": [ - "a", - { - "b": "c" - } - ] - }, - { - "cbor": "pWFhYUFhYmFCYWNhQ2FkYURhZWFF", - "hex": "a56161614161626142616361436164614461656145", - "roundtrip": true, - "decoded": { - "a": "A", - "b": "B", - "c": "C", - "d": "D", - "e": "E" - } - }, - { - "cbor": "X0IBAkMDBAX/", - "hex": "5f42010243030405ff", - "roundtrip": false, - "skip": true, - "diagnostic": "(_ h'0102', h'030405')" - }, - { - "cbor": "f2VzdHJlYWRtaW5n/w==", - "hex": "7f657374726561646d696e67ff", - "roundtrip": false, - "decoded": "streaming" - }, - { - "cbor": "n/8=", - "hex": "9fff", - "roundtrip": false, - "decoded": [ - - ] - }, - { - "cbor": "nwGCAgOfBAX//w==", - "hex": "9f018202039f0405ffff", - "roundtrip": false, - "decoded": [ - 1, - [ - 2, - 3 - ], - [ - 4, - 5 - ] - ] - }, - { - "cbor": "nwGCAgOCBAX/", - "hex": "9f01820203820405ff", - "roundtrip": false, - "decoded": [ - 1, - [ - 2, - 3 - ], - [ - 4, - 5 - ] - ] - }, - { - "cbor": "gwGCAgOfBAX/", - "hex": "83018202039f0405ff", - "roundtrip": false, - "decoded": [ - 1, - [ - 2, - 3 - ], - [ - 4, - 5 - ] - ] - }, - { - "cbor": "gwGfAgP/ggQF", - "hex": "83019f0203ff820405", - "roundtrip": false, - "decoded": [ - 1, - [ - 2, - 3 - ], - [ - 4, - 5 - ] - ] - }, - { - "cbor": "nwECAwQFBgcICQoLDA0ODxAREhMUFRYXGBgYGf8=", - "hex": "9f0102030405060708090a0b0c0d0e0f101112131415161718181819ff", - "roundtrip": false, - "decoded": [ - 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 - ] - }, - { - "cbor": "v2FhAWFinwID//8=", - "hex": "bf61610161629f0203ffff", - "roundtrip": false, - "decoded": { - "a": 1, - "b": [ - 2, - 3 - ] - } - }, - { - "cbor": "gmFhv2FiYWP/", - "hex": "826161bf61626163ff", - "roundtrip": false, - "decoded": [ - "a", - { - "b": "c" - } - ] - }, - { - "cbor": "v2NGdW71Y0FtdCH/", - "hex": "bf6346756ef563416d7421ff", - "roundtrip": false, - "decoded": { - "Fun": true, - "Amt": -2 - } - } -] diff --git a/vendor/github.com/ugorji/go/codec/test.py b/vendor/github.com/ugorji/go/codec/test.py deleted file mode 100644 index f00ff5946..000000000 --- a/vendor/github.com/ugorji/go/codec/test.py +++ /dev/null @@ -1,138 +0,0 @@ -#!/usr/bin/env python - -# This will create golden files in a directory passed to it. -# A Test calls this internally to create the golden files -# So it can process them (so we don't have to checkin the files). - -# Ensure msgpack-python and cbor are installed first, using: -# sudo apt install python-dev (may not be necessary) -# sudo apt install python-pip # or python3-pip -# pip install --user msgpack-python msgpack-rpc-python cbor - -# Ensure all "string" keys are utf strings (else encoded as bytes) - -from __future__ import print_function -import cbor, msgpack, msgpackrpc, sys, os, threading - -mylocaladdr="127.0.0.1" # localhost.localdomain localhost 127.0.0.1 - -def get_test_data_list(): - # get list with all primitive types, and a combo type - l0 = [ - -8, - -1616, - -32323232, - -6464646464646464, - 192, - 1616, - 32323232, - 6464646464646464, - 192, - -3232.0, - -6464646464.0, - 3232.0, - 6464.0, - 6464646464.0, - 160.0, - 1616.0, - False, - True, - u"null", - None, - u"some&day>some 0 - if stopTimeSec > 0: - def myStopRpcServer(): - server.stop() - t = threading.Timer(stopTimeSec, myStopRpcServer) - t.start() - server.start() - -def doRpcClientToPythonSvc(port): - address = msgpackrpc.Address(mylocaladdr, port) - client = msgpackrpc.Client(address, unpack_encoding='utf-8') - print(client.call("Echo123", "A1", "B2", "C3")) - print(client.call("EchoStruct", {"A" :"Aa", "B":"Bb", "C":"Cc"})) - -# def doCheckSocket(port): -# print(">>>> port: ", port, " <<<<<") -# sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) -# result = sock.connect_ex(('127.0.0.1', port)) -# if result == 0: -# print("\t>>>> Port is open") -# else: -# print("\t>>>> Port is not open") -# sock.close() - -def doRpcClientToGoSvc(port): - # doCheckSocket(port) - address = msgpackrpc.Address(mylocaladdr, port) - client = msgpackrpc.Client(address, unpack_encoding='utf-8') - print(client.call("TestRpcInt.Echo123", ["A1", "B2", "C3"])) - print(client.call("TestRpcInt.EchoStruct", {"A" :"Aa", "B":"Bb", "C":"Cc"})) - -def doMain(args): - if len(args) == 2 and args[0] == "testdata": - build_test_data(args[1]) - elif len(args) == 3 and args[0] == "rpc-server": - doRpcServer(int(args[1]), int(args[2])) - elif len(args) == 2 and args[0] == "rpc-client-python-service": - doRpcClientToPythonSvc(int(args[1])) - elif len(args) == 2 and args[0] == "rpc-client-go-service": - doRpcClientToGoSvc(int(args[1])) - else: - print("Usage: test.py " + - "[testdata|rpc-server|rpc-client-python-service|rpc-client-go-service] ...") - -if __name__ == "__main__": - doMain(sys.argv[1:]) diff --git a/vendor/github.com/ugorji/go/codec/writer.go b/vendor/github.com/ugorji/go/codec/writer.go deleted file mode 100644 index fcfce6109..000000000 --- a/vendor/github.com/ugorji/go/codec/writer.go +++ /dev/null @@ -1,239 +0,0 @@ -// Copyright (c) 2012-2020 Ugorji Nwoke. All rights reserved. -// Use of this source code is governed by a MIT license found in the LICENSE file. - -package codec - -import ( - "io" -) - -const maxConsecutiveEmptyWrites = 16 // 2 is sufficient, 16 is enough, 64 is optimal - -// encWriter abstracts writing to a byte array or to an io.Writer. -type encWriterI interface { - writeb([]byte) - writestr(string) - writeqstr(string) // write string wrapped in quotes ie "..." - writen1(byte) - - // add convenience functions for writing 2,4 - writen2(byte, byte) - writen4([4]byte) - writen8([8]byte) - - // isBytes() bool - end() - - resetIO(w io.Writer, bufsize int, blist *bytesFreeList) - resetBytes(in []byte, out *[]byte) -} - -// --------------------------------------------- - -type bufioEncWriter struct { - w io.Writer - - buf []byte - - n int - - b [16]byte // scratch buffer and padding (cache-aligned) -} - -// MARKER: use setByteAt/byteAt to elide the bounds-checks -// when we are sure that we don't go beyond the bounds. - -func (z *bufioEncWriter) resetBytes(in []byte, out *[]byte) { - halt.errorStr("resetBytes is unsupported by bufioEncWriter") -} - -func (z *bufioEncWriter) resetIO(w io.Writer, bufsize int, blist *bytesFreeList) { - z.w = w - z.n = 0 - // use minimum bufsize of 16, matching the array z.b and accomodating writen methods (where n <= 8) - bufsize = max(16, bufsize) // max(byteBufSize, bufsize) - if cap(z.buf) < bufsize { - if len(z.buf) > 0 && &z.buf[0] != &z.b[0] { - blist.put(z.buf) - } - if len(z.b) > bufsize { - z.buf = z.b[:] - } else { - z.buf = blist.get(bufsize) - } - } - z.buf = z.buf[:cap(z.buf)] -} - -func (z *bufioEncWriter) flushErr() (err error) { - var n int - for i := maxConsecutiveEmptyReads; i > 0; i-- { - n, err = z.w.Write(z.buf[:z.n]) - z.n -= n - if z.n == 0 || err != nil { - return - } - // at this point: z.n > 0 && err == nil - if n > 0 { - copy(z.buf, z.buf[n:z.n+n]) - } - } - return io.ErrShortWrite // OR io.ErrNoProgress: not enough (or no) data written -} - -func (z *bufioEncWriter) flush() { - halt.onerror(z.flushErr()) -} - -func (z *bufioEncWriter) writeb(s []byte) { -LOOP: - a := len(z.buf) - z.n - if len(s) > a { - z.n += copy(z.buf[z.n:], s[:a]) - s = s[a:] - z.flush() - goto LOOP - } - z.n += copy(z.buf[z.n:], s) -} - -func (z *bufioEncWriter) writestr(s string) { - // z.writeb(bytesView(s)) // inlined below -LOOP: - a := len(z.buf) - z.n - if len(s) > a { - z.n += copy(z.buf[z.n:], s[:a]) - s = s[a:] - z.flush() - goto LOOP - } - z.n += copy(z.buf[z.n:], s) -} - -func (z *bufioEncWriter) writeqstr(s string) { - // z.writen1('"') - // z.writestr(s) - // z.writen1('"') - - if z.n+len(s)+2 > len(z.buf) { - z.flush() - } - setByteAt(z.buf, uint(z.n), '"') - // z.buf[z.n] = '"' - z.n++ -LOOP: - a := len(z.buf) - z.n - if len(s)+1 > a { - z.n += copy(z.buf[z.n:], s[:a]) - s = s[a:] - z.flush() - goto LOOP - } - z.n += copy(z.buf[z.n:], s) - setByteAt(z.buf, uint(z.n), '"') - // z.buf[z.n] = '"' - z.n++ -} - -func (z *bufioEncWriter) writen1(b1 byte) { - if 1 > len(z.buf)-z.n { - z.flush() - } - setByteAt(z.buf, uint(z.n), b1) - // z.buf[z.n] = b1 - z.n++ -} - -func (z *bufioEncWriter) writen2(b1, b2 byte) { - if 2 > len(z.buf)-z.n { - z.flush() - } - setByteAt(z.buf, uint(z.n+1), b2) - setByteAt(z.buf, uint(z.n), b1) - // z.buf[z.n+1] = b2 - // z.buf[z.n] = b1 - z.n += 2 -} - -func (z *bufioEncWriter) writen4(b [4]byte) { - if 4 > len(z.buf)-z.n { - z.flush() - } - // setByteAt(z.buf, uint(z.n+3), b4) - // setByteAt(z.buf, uint(z.n+2), b3) - // setByteAt(z.buf, uint(z.n+1), b2) - // setByteAt(z.buf, uint(z.n), b1) - copy(z.buf[z.n:], b[:]) - z.n += 4 -} - -func (z *bufioEncWriter) writen8(b [8]byte) { - if 8 > len(z.buf)-z.n { - z.flush() - } - copy(z.buf[z.n:], b[:]) - z.n += 8 -} - -func (z *bufioEncWriter) endErr() (err error) { - if z.n > 0 { - err = z.flushErr() - } - return -} - -func (z *bufioEncWriter) end() { - halt.onerror(z.endErr()) -} - -// --------------------------------------------- - -var bytesEncAppenderDefOut = []byte{} - -// bytesEncAppender implements encWriter and can write to an byte slice. -type bytesEncAppender struct { - b []byte - out *[]byte -} - -func (z *bytesEncAppender) writeb(s []byte) { - z.b = append(z.b, s...) -} -func (z *bytesEncAppender) writestr(s string) { - z.b = append(z.b, s...) -} -func (z *bytesEncAppender) writeqstr(s string) { - z.b = append(append(append(z.b, '"'), s...), '"') - // z.b = append(z.b, '"') - // z.b = append(z.b, s...) - // z.b = append(z.b, '"') -} -func (z *bytesEncAppender) writen1(b1 byte) { - z.b = append(z.b, b1) -} -func (z *bytesEncAppender) writen2(b1, b2 byte) { - z.b = append(z.b, b1, b2) -} - -func (z *bytesEncAppender) writen4(b [4]byte) { - z.b = append(z.b, b[:]...) - // z.b = append(z.b, b1, b2, b3, b4) // prevents inlining encWr.writen4 -} - -func (z *bytesEncAppender) writen8(b [8]byte) { - z.b = append(z.b, b[:]...) - // z.b = append(z.b, b[0], b[1], b[2], b[3], b[4], b[5], b[6], b[7]) -} - -func (z *bytesEncAppender) end() { - *(z.out) = z.b -} - -func (z *bytesEncAppender) resetBytes(in []byte, out *[]byte) { - z.b = in[:0] - z.out = out -} - -func (z *bytesEncAppender) resetIO(w io.Writer, bufsize int, blist *bytesFreeList) { - halt.errorStr("resetIO is unsupported by bytesEncAppender") -} -- cgit v1.3