pax_global_header00006660000000000000000000000064143525532610014520gustar00rootroot0000000000000052 comment=e4956d885eacfb85d148a061a9a4ffe406feefaf go-1.2.8/000077500000000000000000000000001435255326100121355ustar00rootroot00000000000000go-1.2.8/.github/000077500000000000000000000000001435255326100134755ustar00rootroot00000000000000go-1.2.8/.github/workflows/000077500000000000000000000000001435255326100155325ustar00rootroot00000000000000go-1.2.8/.github/workflows/test.yml000066400000000000000000000053171435255326100172420ustar00rootroot00000000000000name: Build and Test go-codec on: workflow_dispatch: {} push: branches: [ master ] paths: [ '**.go' ] pull_request: branches: [ master ] paths: [ '**.go' ] jobs: tests: strategy: fail-fast: false matrix: go: [ '1.19', '1.17', '1.11', '1.20.0-rc.1' ] arch: [ amd64 ] os: [ ubuntu-latest ] include: - go: '1.19' arch: '386' os: ubuntu-latest runs-on: ${{ matrix.os }} env: GO111MODULE: 'on' COVER_GO_VERSION: '1.19' GOARCH: ${{ matrix.arch }} name: go ${{ matrix.go }} on ${{ matrix.arch }} steps: - uses: actions/checkout@v3 - uses: actions/setup-go@v3 with: go-version: ${{ matrix.go }} - name: Run tests shell: bash run: | cd codec go mod edit -droprequire github.com/ugorji/go t=( "" "safe" "notfastpath" "codecgen" ) for i in "${t[@]}"; do go test "-tags=alltests ${i}" "-run=Suite" "-coverprofile=coverage.${{ matrix.go }}.${{ matrix.arch }}.${i}.txt"; done - uses: codecov/codecov-action@v3 if: matrix.go == env.COVER_GO_VERSION with: directory: ./codec # No need to go get, as github knows its working out of this folder. # # Most of our code is the same since go1.12; before that we selectively compile files using build constraints. # # We test against the following go releases # - latest production release # - 2 releases before that # - an archive version (go 1.11) # - and a beta/rc of development release (so github can just download an archive of it and use) # # Pre-release versions must use semver e.g. as of 20221220, it's '1.20.0-rc.1' # TODO: add this back once we resolve the issue with go-codec failing on development branch. # # We test amd64 on all releases, and i386 (32-bit) on last production release. # # We previously had each tag be its own matrix, but that exploded the number of runs. # Instead, since the environment is consistent, we just use a bash script to run through all # the tags for that run. # # Finally, we do a go mod edit -droprequire github.com/ugorji/go to circumvent the "missing go.sum entry" error. # We put a requirements cycle with github.com/ugorji/go to allow folks requiring .../ugorji/go in 2019 to work ok. # Now, everyone should have updated to a go-codec version >= 1.17 or preferably >= 1.2.0. # Now is a good time to remove that requirements cycle. # # # # # --- SCRATCH --- # coverage: # if: ${{ always() }} # needs: [ tests] # steps: # - uses: codecov/codecov-action@v3 # directory: ./codec # # steps: # - uses: actions/checkout@v3 # with: # fetch-depth: 0 # required for new-from-rev option in .golangci.yml go-1.2.8/FAQ.md000066400000000000000000000067671435255326100131060ustar00rootroot00000000000000# FAQ ## Managing Binary Size This package adds about `900K` to any binary that depends on it. Prior to 2019-05-16, this package could add about `2MB` to the size of your binaries. We have now trimmed that by 60%, and the package contributes less than `1MB`. This compares favorably to other packages like `json-iterator/go` `(1MB)`. Of that `900Kb`, about `200Kb` is from an *optional* auto-generated file: `fast-path.generated.go` that includes static generated implementations providing much faster encoding and decoding of slices and maps containing built-in numeric, boolean, string and interface{} types. Furthermore, you can bypass including `fast-path.generated.go` in your binary, by building (or running tests and benchmarks) with the tag: `codec.notfastpath`. go install -tags codec.notfastpath go build -tags codec.notfastpath go test -tags codec.notfastpath With the tag `codec.notfastpath`, we trim that size to about `700Kb`. Please be aware of the following: - At least in our representative microbenchmarks for json (for example), passing `codec.notfastpath` tag causes a clear performance loss (about 10%). *YMMV*. - These values were got from building the test binary that gives > 90% code coverage, and running `go tool nm` on it to see how much space these library symbols took. We consider that your use will touch much less of the library and you can be sure that it will add less than 1MB to your binary. ## Resolving Module Issues Prior to v1.1.5, `go-codec` unknowingly introduced some headaches for its users while introducing module support. We tried to make `github.com/ugorji/go/codec` a module. At that time, multi-repository module support was weak, so we reverted and made `github.com/ugorji/go/` the module. However, folks previously used go-codec in module mode before it formally supported modules. Eventually, different established packages had go.mod files contain various real and pseudo versions of go-codec which causes `go` to barf with `ambiguous import` error. To resolve this, from v1.1.5 and up, we use a requirements cycle between modules `github.com/ugorji/go/codec` and `github.com/ugorji/go/`, tagging them with parallel consistent tags (`codec/vX.Y.Z and vX.Y.Z`) to the same commit. Fixing `ambiguous import` failure is now as simple as running ``` go get -u github.com/ugorji/go/codec@latest ``` ### Removing requirements cycle in v1.2.8 Unfortunately, due to the requirements cycle noted above, we cannot create a valid `go.sum` until after the git version tags have been created. This is why a `go.sum` has not been distributed with these 2 modules above. To fix that, starting with codec `v1.2.8`, we will remove the requirements cycle. `github.com/ugorji/go/` will require `github.com/ugorji/go/codec` but not vice versa. It has been over 3 years since we released `v1.1.7` (in July 2019) with the requirements cycle to accomodate folks with an older version of the `github.com/ugorji/go` module. We believe most folks now depend either directly on the newer `github.com/ugorji/go/codec` module, or on a newer `github.com/ugorji/go` module. ## Running on GCCGO You can use [gccgo](https://gcc.gnu.org/onlinedocs/gccgo/) [1](https://golang.org/doc/install/gccgo) to build your applications that depend on this library. This is fully tested. There's a caveat for contributors to the library. If you are contributing to the library, you will need to run `./build.sh -m` at some point. This has a failure on gccgo. Consequently, contributors must use the `gc` compiler. go-1.2.8/LICENSE000066400000000000000000000021221435255326100131370ustar00rootroot00000000000000The 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. go-1.2.8/README.md000066400000000000000000000042121435255326100134130ustar00rootroot00000000000000[![Sourcegraph](https://sourcegraph.com/github.com/ugorji/go/-/badge.svg?v=4)](https://sourcegraph.com/github.com/ugorji/go/-/tree/codec?badge) [![Build and Test go-codec](https://github.com/ugorji/go/actions/workflows/test.yml/badge.svg)](https://github.com/ugorji/go/actions/workflows/test.yml) [![codecov](https://codecov.io/gh/ugorji/go/branch/master/graph/badge.svg?v=4)](https://codecov.io/gh/ugorji/go) [![Go Reference](https://pkg.go.dev/badge/github.com/ugorji/go/codec.svg)](https://pkg.go.dev/github.com/ugorji/go/codec) [![rcard](https://goreportcard.com/badge/github.com/ugorji/go/codec?v=4)](https://goreportcard.com/report/github.com/ugorji/go/codec) [![License](http://img.shields.io/badge/license-mit-blue.svg?style=flat-square)](https://raw.githubusercontent.com/ugorji/go/master/LICENSE) # go-codec This repository contains the `go-codec` library, the `codecgen` tool and benchmarks for comparing against other libraries. This is a High Performance, Feature-Rich Idiomatic Go 1.4+ codec/encoding library for binary and text formats: binc, msgpack, cbor, json and simple. It fully supports the legacy `GOPATH` and the new `go modules` modes. ## Code Organization and Module Support This repository consists of 4 modules: - `github.com/ugorji/go/codec` [README](codec/README.md) - `github.com/ugorji/go/codec/codecgen` (requires `github.com/ugorji/go/codec`) [README](codec/codecgen/README.md) - `github.com/ugorji/go/codec/bench` (requires `github.com/ugorji/go/codec`) [README](codec/bench/README.md) - `github.com/ugorji/go` (requires `github.com/ugorji/go/codec`) For encoding and decoding, the `github.com/ugorji/go/codec` module is sufficient. To install: ``` go get github.com/ugorji/go/codec ``` The other modules exist for specific uses, and all require `github.com/ugorji/go/codec` - `github.com/ugorji/go/codec/codecgen` generates high performance static encoders/decoders for given types - `github.com/ugorji/go/codec/bench` benchmarks codec against other popular go libraries - `github.com/ugorji/go` is here for [historical compatibility reasons, as modules was initially introduced only at repo root](https://github.com/ugorji/go/issues/299) go-1.2.8/codec/000077500000000000000000000000001435255326100132125ustar00rootroot00000000000000go-1.2.8/codec/0_importpath.go000066400000000000000000000005511435255326100161500ustar00rootroot00000000000000// 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. go-1.2.8/codec/README.md000066400000000000000000000237331435255326100145010ustar00rootroot00000000000000# 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 # 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 ``` # 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 = 25 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 ``` go-1.2.8/codec/bench/000077500000000000000000000000001435255326100142715ustar00rootroot00000000000000go-1.2.8/codec/bench/.gitignore000066400000000000000000000000211435255326100162520ustar00rootroot00000000000000*_generated_*.* go-1.2.8/codec/bench/README.md000066400000000000000000000201371435255326100155530ustar00rootroot00000000000000# go-codec-bench This is a comparison of different binary and text encodings. We compare the codecs provided by github.com/ugorji/go/codec package, against other libraries: [github.com/ugorji/go/codec](http://github.com/ugorji/go) provides: - msgpack: [http://github.com/msgpack/msgpack] - binc: [http://github.com/ugorji/binc] - cbor: [http://cbor.io] [http://tools.ietf.org/html/rfc7049] - simple: - json: [http://json.org] [http://tools.ietf.org/html/rfc7159] Other codecs compared include: - [github.com/vmihailenco/msgpack/v4](https://pkg.go.dev/github.com/vmihailenco/msgpack/v4) - [github.com/globalsign/mgo/bson](https://pkg.go.dev/github.com/globalsign/mgo/bson) - [go.mongodb.org/mongo-driver/bson](https://pkg.go.dev/go.mongodb.org/mongo-driver/bson) - [github.com/davecgh/go-xdr/xdr2](https://pkg.go.dev/github.com/davecgh/go-xdr/xdr2) - [github.com/Sereal/Sereal/Go/sereal](https://pkg.go.dev/github.com/Sereal/Sereal/Go/sereal) - [bitbucket.org/bodhisnarkva/cbor/go](https://pkg.go.dev/bitbucket.org/bodhisnarkva/cbor/go) - [github.com/tinylib/msgp](https://pkg.go.dev/github.com/tinylib/msgp) - [github.com/pquerna/ffjson/ffjson](https://pkg.go.dev/github.com/pquerna/ffjson/ffjson) - [github.com/json-iterator/go](https://pkg.go.dev/github.com/json-iterator/go) - [github.com/mailru/easyjson](https://pkg.go.dev/github.com/mailru/easyjson) - [github.com/fxamacker/cbor/v2](https://pkg.go.dev/github.com/fxamacker/cbor/v2) # Data The data being serialized is a `TestStruc` randomly generated values. See [values_test.go](values_test.go) for the definition of the TestStruc. # Run Benchmarks See [bench.sh](bench.sh) for how to download the external libraries which we benchmark against, generate the files for the types when needed, and run the suite of tests. The 3 suite of benchmarks are - CodecSuite - XSuite - CodecXSuite ``` # Note that `bench.sh` may be in the codec sub-directory, and should be run from there. # download the code and all its dependencies ./bench.sh -d # code-generate files needed for benchmarks against ffjson, easyjson, msgp, etc ./bench.sh -c # run the full suite of tests (not including external formats) ./bench.sh -s # Below, see how to just run some specific suite of tests, knowing the right tags and flags ... # See bench.sh for different iterations # Run suite of tests in default mode (selectively using unsafe in specific areas) go test -tags "alltests x" -bench "CodecXSuite" -benchmem # Run suite of tests in safe mode (no usage of unsafe) go test -tags "alltests x codec.safe" -bench "CodecXSuite" -benchmem # Run suite of tests in codecgen mode, including all tests which are generated (msgp, ffjson, etc) go test -tags "alltests x generated" -bench "CodecXGenSuite" -benchmem ``` # Issues The following issues are seen currently (11/20/2014): - _code.google.com/p/cbor/go_ fails on encoding and decoding the test struct - _github.com/davecgh/go-xdr/xdr2_ fails on encoding and decoding the test struct - _github.com/Sereal/Sereal/Go/sereal_ fails on decoding the serialized test struct # Representative Benchmark Results Please see the [benchmarking blog post for detailed representative results](http://ugorji.net/blog/benchmarking-serialization-in-go). A snapshot of some results on my Core-i5 2018 Dell Inspiron laptop is below. **Note: errors are truncated, and lines re-arranged, for readability**. What you should notice: - Results get better with codecgen, resulting in about 50% performance improvement. Users should carefully weigh the performance improvements against the usability and binary-size increases, as performance is already extremely good without the codecgen path. See [bench.out.txt](bench.out.txt) for representative result from running `bench.sh` as below, as of 2020-11-11. ```sh ./bench.sh -z > bench.out.txt ``` *snippet of benchmark output, running without codecgen (2021-02-04)* *note that the first 5 are from codes (and the following are from other libraries (as named).* ``` BenchmarkCodecXSuite/options-false.../ Benchmark__Msgpack____Encode-8 17764 67504 ns/op 24 B/op 1 allocs/op Benchmark__Binc_______Encode-8 16442 72011 ns/op 24 B/op 1 allocs/op Benchmark__Simple_____Encode-8 17060 69965 ns/op 24 B/op 1 allocs/op Benchmark__Cbor_______Encode-8 16450 70783 ns/op 24 B/op 1 allocs/op Benchmark__Json_______Encode-8 7303 145232 ns/op 24 B/op 1 allocs/op Benchmark__Std_Json___Encode-8 5308 229397 ns/op 79216 B/op 556 allocs/op Benchmark__Gob________Encode-8 7278 165572 ns/op 174169 B/op 683 allocs/op Benchmark__JsonIter___Encode-8 7950 154060 ns/op 54437 B/op 80 allocs/op Benchmark__Bson_______Encode-8 3780 305520 ns/op 242263 B/op 1181 allocs/op Benchmark__Mgobson____Encode-8 3040 397415 ns/op 300345 B/op 1877 allocs/op Benchmark__VMsgpack___Encode-8 5572 218910 ns/op 164607 B/op 360 allocs/op Benchmark__Fxcbor_____Encode-8 10000 114321 ns/op 51947 B/op 400 allocs/op Benchmark__Sereal_____Encode-8 3063 350328 ns/op 277718 B/op 3388 allocs/op Benchmark__Msgpack____Decode-8 8372 144322 ns/op 37412 B/op 315 allocs/op Benchmark__Binc_______Decode-8 8487 141145 ns/op 37413 B/op 315 allocs/op Benchmark__Simple_____Decode-8 8542 139446 ns/op 37413 B/op 315 allocs/op Benchmark__Cbor_______Decode-8 7989 154240 ns/op 37414 B/op 315 allocs/op Benchmark__Json_______Decode-8 2880 416769 ns/op 71880 B/op 592 allocs/op Benchmark__Std_Json___Decode-8 1207 988487 ns/op 137146 B/op 3113 allocs/op Benchmark__Gob________Decode-8 4083 300238 ns/op 159394 B/op 2329 allocs/op Benchmark__JsonIter___Decode-8 2607 476016 ns/op 132690 B/op 2654 allocs/op Benchmark__Bson_______Decode-8 2418 508113 ns/op 190987 B/op 4544 allocs/op Benchmark__Mgobson____Decode-8 2217 543875 ns/op 168741 B/op 6776 allocs/op Benchmark__VMsgpack___Decode-8 3133 391164 ns/op 100126 B/op 2030 allocs/op Benchmark__Fxcbor_____Decode-8 4645 251379 ns/op 72515 B/op 1395 allocs/op ``` * snippet of bench.out.txt, running with codecgen (2021-02-04) * ``` BenchmarkCodecXGenSuite/options-false.../ Benchmark__Msgpack____Encode-8 26810 45254 ns/op 24 B/op 1 allocs/op Benchmark__Binc_______Encode-8 25396 48931 ns/op 24 B/op 1 allocs/op Benchmark__Simple_____Encode-8 28516 46036 ns/op 24 B/op 1 allocs/op Benchmark__Cbor_______Encode-8 26923 44930 ns/op 24 B/op 1 allocs/op Benchmark__Json_______Encode-8 9980 124222 ns/op 24 B/op 1 allocs/op Benchmark__Msgp_______Encode-8 36180 33802 ns/op 0 B/op 0 allocs/op Benchmark__Easyjson___Encode-8 10000 114262 ns/op 50690 B/op 12 allocs/op Benchmark__Ffjson_____Encode-8 4051 299364 ns/op 128399 B/op 1121 allocs/op Benchmark__Msgpack____Decode-8 13057 94631 ns/op 35909 B/op 308 allocs/op Benchmark__Binc_______Decode-8 12678 91177 ns/op 35909 B/op 308 allocs/op Benchmark__Simple_____Decode-8 13144 90958 ns/op 35910 B/op 308 allocs/op Benchmark__Cbor_______Decode-8 10000 102062 ns/op 35911 B/op 308 allocs/op Benchmark__Json_______Decode-8 3019 365442 ns/op 70469 B/op 589 allocs/op Benchmark__Msgp_______Decode-8 14877 79750 ns/op 68788 B/op 969 allocs/op Benchmark__Easyjson___Decode-8 3150 389608 ns/op 70531 B/op 475 allocs/op Benchmark__Ffjson_____Decode-8 2758 435859 ns/op 95178 B/op 1290 allocs/op ``` go-1.2.8/codec/bench/bench.out.txt000066400000000000000000002363131435255326100167270ustar00rootroot00000000000000**** STATS **** ==== X Baseline ==== BENCHMARK INIT: 2022-12-26 19:05:36.126397762 -0500 EST m=+0.001237032 Benchmark: Struct recursive Depth: 1 ApproxDeepSize Of benchmark Struct: 107152 bytes Benchmark One-Pass Run (with Unscientific Encode/Decode times): msgpack: len: 38710 bytes, encode: 336.207µs, decode: 234.974µs, encoded == decoded binc: len: 38390 bytes, encode: 191.692µs, decode: 201.232µs, encoded == decoded simple: len: 40395 bytes, encode: 176.289µs, decode: 184.418µs, encoded == decoded cbor: len: 38478 bytes, encode: 143.978µs, decode: 199.2µs, encoded == decoded json: len: 47260 bytes, encode: 291.458µs, decode: 577.407µs, encoded == decoded std-json: len: 46976 bytes, encode: 455.482µs, decode: 1.164698ms, encoded == decoded gob: len: 36532 bytes, encode: 445.418µs, decode: 349.403µs, encoded != decoded: Not Match std-xml: **** Error encoding benchTs: xml: unsupported type: map[string]int json-iter: len: 46984 bytes, encode: 968.007µs, decode: 1.059126ms, encoded == decoded v-msgpack: len: 44626 bytes, encode: 326.035µs, decode: 400.431µs, encoded == decoded bson: len: 52606 bytes, encode: 479.369µs, decode: 617.707µs, encoded == decoded mgobson: len: 52811 bytes, encode: 536.839µs, decode: 539.929µs, encoded != decoded: Not Match fxcbor: len: 38466 bytes, encode: 231.586µs, decode: 358.314µs, encoded == decoded gcbor: **** Error decoding into new TestStruc: can't read map into **codec.stringUint64T xdr: **** Error encoding benchTs: xdr:encode: type 'invalid' is not valid sereal: len: 28457 bytes, encode: 354.798µs, decode: 214.67µs, encoded != decoded: Not Match ==== X Generated ==== BENCHMARK INIT: 2022-12-26 19:05:36.770533315 -0500 EST m=+0.000872072 Benchmark: Struct recursive Depth: 1 ApproxDeepSize Of benchmark Struct: 107152 bytes Benchmark One-Pass Run (with Unscientific Encode/Decode times): msgpack: len: 38710 bytes, encode: 199.275µs, decode: 170.94µs, encoded == decoded binc: len: 38390 bytes, encode: 131.112µs, decode: 115.163µs, encoded == decoded simple: len: 40395 bytes, encode: 136.599µs, decode: 108.759µs, encoded == decoded cbor: len: 38478 bytes, encode: 163.792µs, decode: 128.882µs, encoded == decoded json: len: 47260 bytes, encode: 270.705µs, decode: 505.497µs, encoded == decoded msgp: len: 38682 bytes, encode: 79.771µs, decode: 104.569µs, encoded != decoded: Not Match (recovered) panic: runtime error: invalid memory address or nil pointer dereference --- FAIL: TestBenchInit (0.01s) FAIL exit status 1 FAIL ugorji.net/codec/bench 0.009s **** SUITE **** >>>> bench TAGS: 'alltests x ' SUITE: BenchmarkCodecXSuite >>>> Skipping - these cannot (en|de)code TestStruc - encode (xml, gcbor, xdr), decode (xml, gcbor, xdr, sereal) BenchmarkCodecXSuite/options-false.../Benchmark__Msgpack____Encode-8 19969 60187 ns/op 24 B/op 1 allocs/op BenchmarkCodecXSuite/options-false.../Benchmark__Binc_______Encode-8 17902 65145 ns/op 24 B/op 1 allocs/op BenchmarkCodecXSuite/options-false.../Benchmark__Simple_____Encode-8 19468 62203 ns/op 24 B/op 1 allocs/op BenchmarkCodecXSuite/options-false.../Benchmark__Cbor_______Encode-8 19868 61470 ns/op 24 B/op 1 allocs/op BenchmarkCodecXSuite/options-false.../Benchmark__Json_______Encode-8 8479 138817 ns/op 24 B/op 1 allocs/op BenchmarkCodecXSuite/options-false.../Benchmark__Std_Json___Encode-8 6270 201652 ns/op 75488 B/op 480 allocs/op BenchmarkCodecXSuite/options-false.../Benchmark__Gob________Encode-8 8047 139332 ns/op 167667 B/op 615 allocs/op BenchmarkCodecXSuite/options-false.../Benchmark__JsonIter___Encode-8 6106 168563 ns/op 55455 B/op 122 allocs/op BenchmarkCodecXSuite/options-false.../Benchmark__Bson_______Encode-8 4699 261999 ns/op 86780 B/op 1125 allocs/op BenchmarkCodecXSuite/options-false.../Benchmark__Mgobson____Encode-8 2660 450150 ns/op 293699 B/op 1816 allocs/op BenchmarkCodecXSuite/options-false.../Benchmark__VMsgpack___Encode-8 5164 229845 ns/op 140472 B/op 326 allocs/op BenchmarkCodecXSuite/options-false.../Benchmark__Fxcbor_____Encode-8 8436 137680 ns/op 47395 B/op 332 allocs/op BenchmarkCodecXSuite/options-false.../Benchmark__Sereal_____Encode-8 3175 356654 ns/op 265597 B/op 3354 allocs/op BenchmarkCodecXSuite/options-false.../Benchmark__Msgpack____Decode-8 8634 139815 ns/op 37412 B/op 315 allocs/op BenchmarkCodecXSuite/options-false.../Benchmark__Binc_______Decode-8 8535 136635 ns/op 37414 B/op 315 allocs/op BenchmarkCodecXSuite/options-false.../Benchmark__Simple_____Decode-8 8208 133534 ns/op 37414 B/op 315 allocs/op BenchmarkCodecXSuite/options-false.../Benchmark__Cbor_______Decode-8 6883 150556 ns/op 37413 B/op 315 allocs/op BenchmarkCodecXSuite/options-false.../Benchmark__Json_______Decode-8 2696 434490 ns/op 72174 B/op 503 allocs/op BenchmarkCodecXSuite/options-false.../Benchmark__Std_Json___Decode-8 1269 936643 ns/op 137167 B/op 3114 allocs/op BenchmarkCodecXSuite/options-false.../Benchmark__Gob________Decode-8 4477 296013 ns/op 162651 B/op 2425 allocs/op BenchmarkCodecXSuite/options-false.../Benchmark__JsonIter___Decode-8 2006 533983 ns/op 131761 B/op 2658 allocs/op BenchmarkCodecXSuite/options-false.../Benchmark__Bson_______Decode-8 2558 487206 ns/op 193613 B/op 4560 allocs/op BenchmarkCodecXSuite/options-false.../Benchmark__Mgobson____Decode-8 2154 549209 ns/op 168874 B/op 6792 allocs/op BenchmarkCodecXSuite/options-false.../Benchmark__VMsgpack___Decode-8 3432 368810 ns/op 100359 B/op 2038 allocs/op BenchmarkCodecXSuite/options-false.../Benchmark__Fxcbor_____Decode-8 5398 227716 ns/op 72502 B/op 1395 allocs/op BenchmarkCodecXSuite/use-bufio-!bytes/Benchmark__Msgpack____Encode-8 15321 73999 ns/op 72 B/op 2 allocs/op BenchmarkCodecXSuite/use-bufio-!bytes/Benchmark__Binc_______Encode-8 14571 78860 ns/op 72 B/op 2 allocs/op BenchmarkCodecXSuite/use-bufio-!bytes/Benchmark__Simple_____Encode-8 14968 82660 ns/op 72 B/op 2 allocs/op BenchmarkCodecXSuite/use-bufio-!bytes/Benchmark__Cbor_______Encode-8 15507 78199 ns/op 72 B/op 2 allocs/op BenchmarkCodecXSuite/use-bufio-!bytes/Benchmark__Json_______Encode-8 7416 164077 ns/op 72 B/op 2 allocs/op BenchmarkCodecXSuite/use-bufio-!bytes/Benchmark__Std_Json___Encode-8 6409 179490 ns/op 26388 B/op 480 allocs/op BenchmarkCodecXSuite/use-bufio-!bytes/Benchmark__Gob________Encode-8 8544 135682 ns/op 167665 B/op 615 allocs/op BenchmarkCodecXSuite/use-bufio-!bytes/Benchmark__JsonIter___Encode-8 5931 199333 ns/op 217602 B/op 139 allocs/op BenchmarkCodecXSuite/use-bufio-!bytes/Benchmark__Bson_______Encode-8 4743 276483 ns/op 86740 B/op 1125 allocs/op BenchmarkCodecXSuite/use-bufio-!bytes/Benchmark__Mgobson____Encode-8 2901 407359 ns/op 293694 B/op 1816 allocs/op BenchmarkCodecXSuite/use-bufio-!bytes/Benchmark__VMsgpack___Encode-8 8908 133356 ns/op 10800 B/op 319 allocs/op BenchmarkCodecXSuite/use-bufio-!bytes/Benchmark__Fxcbor_____Encode-8 12721 94381 ns/op 80237 B/op 340 allocs/op BenchmarkCodecXSuite/use-bufio-!bytes/Benchmark__Sereal_____Encode-8 3954 302995 ns/op 265554 B/op 3354 allocs/op BenchmarkCodecXSuite/use-bufio-!bytes/Benchmark__Msgpack____Decode-8 5457 231922 ns/op 84347 B/op 2133 allocs/op BenchmarkCodecXSuite/use-bufio-!bytes/Benchmark__Binc_______Decode-8 5509 225362 ns/op 82670 B/op 1666 allocs/op BenchmarkCodecXSuite/use-bufio-!bytes/Benchmark__Simple_____Decode-8 4705 240669 ns/op 83399 B/op 1753 allocs/op BenchmarkCodecXSuite/use-bufio-!bytes/Benchmark__Cbor_______Decode-8 4914 230622 ns/op 83383 B/op 1754 allocs/op BenchmarkCodecXSuite/use-bufio-!bytes/Benchmark__Json_______Decode-8 1977 582973 ns/op 91468 B/op 1185 allocs/op BenchmarkCodecXSuite/use-bufio-!bytes/Benchmark__Std_Json___Decode-8 1196 1029490 ns/op 266541 B/op 3126 allocs/op BenchmarkCodecXSuite/use-bufio-!bytes/Benchmark__Gob________Decode-8 4422 269219 ns/op 162669 B/op 2425 allocs/op BenchmarkCodecXSuite/use-bufio-!bytes/Benchmark__JsonIter___Decode-8 2308 520842 ns/op 136129 B/op 2811 allocs/op BenchmarkCodecXSuite/use-bufio-!bytes/Benchmark__Bson_______Decode-8 2682 452116 ns/op 193673 B/op 4560 allocs/op BenchmarkCodecXSuite/use-bufio-!bytes/Benchmark__Mgobson____Decode-8 2348 532243 ns/op 168855 B/op 6792 allocs/op BenchmarkCodecXSuite/use-bufio-!bytes/Benchmark__VMsgpack___Decode-8 3434 344111 ns/op 101427 B/op 2042 allocs/op BenchmarkCodecXSuite/use-bufio-!bytes/Benchmark__Fxcbor_____Decode-8 3871 317456 ns/op 201564 B/op 1403 allocs/op BenchmarkCodecXSuite/reset-enc-dec.../Benchmark__Msgpack____Encode-8 19696 61331 ns/op 24 B/op 1 allocs/op BenchmarkCodecXSuite/reset-enc-dec.../Benchmark__Binc_______Encode-8 18160 66327 ns/op 24 B/op 1 allocs/op BenchmarkCodecXSuite/reset-enc-dec.../Benchmark__Simple_____Encode-8 18836 65908 ns/op 24 B/op 1 allocs/op BenchmarkCodecXSuite/reset-enc-dec.../Benchmark__Cbor_______Encode-8 18788 64262 ns/op 24 B/op 1 allocs/op BenchmarkCodecXSuite/reset-enc-dec.../Benchmark__Json_______Encode-8 8210 142310 ns/op 24 B/op 1 allocs/op BenchmarkCodecXSuite/reset-enc-dec.../Benchmark__Std_Json___Encode-8 6276 192753 ns/op 75491 B/op 480 allocs/op BenchmarkCodecXSuite/reset-enc-dec.../Benchmark__Gob________Encode-8 7956 139066 ns/op 167668 B/op 615 allocs/op BenchmarkCodecXSuite/reset-enc-dec.../Benchmark__JsonIter___Encode-8 7510 168066 ns/op 55478 B/op 122 allocs/op BenchmarkCodecXSuite/reset-enc-dec.../Benchmark__Bson_______Encode-8 4388 280433 ns/op 86744 B/op 1125 allocs/op BenchmarkCodecXSuite/reset-enc-dec.../Benchmark__Mgobson____Encode-8 2907 404926 ns/op 293695 B/op 1816 allocs/op BenchmarkCodecXSuite/reset-enc-dec.../Benchmark__VMsgpack___Encode-8 6088 189920 ns/op 140475 B/op 326 allocs/op BenchmarkCodecXSuite/reset-enc-dec.../Benchmark__Fxcbor_____Encode-8 10000 100908 ns/op 47606 B/op 332 allocs/op BenchmarkCodecXSuite/reset-enc-dec.../Benchmark__Sereal_____Encode-8 3895 303861 ns/op 265406 B/op 3354 allocs/op BenchmarkCodecXSuite/reset-enc-dec.../Benchmark__Msgpack____Decode-8 8755 136425 ns/op 37412 B/op 315 allocs/op BenchmarkCodecXSuite/reset-enc-dec.../Benchmark__Binc_______Decode-8 8374 136804 ns/op 37415 B/op 315 allocs/op BenchmarkCodecXSuite/reset-enc-dec.../Benchmark__Simple_____Decode-8 8868 133037 ns/op 37413 B/op 315 allocs/op BenchmarkCodecXSuite/reset-enc-dec.../Benchmark__Cbor_______Decode-8 8144 158490 ns/op 37414 B/op 315 allocs/op BenchmarkCodecXSuite/reset-enc-dec.../Benchmark__Json_______Decode-8 2704 439930 ns/op 72191 B/op 503 allocs/op BenchmarkCodecXSuite/reset-enc-dec.../Benchmark__Std_Json___Decode-8 1257 945132 ns/op 137158 B/op 3114 allocs/op BenchmarkCodecXSuite/reset-enc-dec.../Benchmark__Gob________Decode-8 4324 272214 ns/op 162645 B/op 2425 allocs/op BenchmarkCodecXSuite/reset-enc-dec.../Benchmark__JsonIter___Decode-8 2220 509397 ns/op 131750 B/op 2658 allocs/op BenchmarkCodecXSuite/reset-enc-dec.../Benchmark__Bson_______Decode-8 2450 455303 ns/op 193633 B/op 4560 allocs/op BenchmarkCodecXSuite/reset-enc-dec.../Benchmark__Mgobson____Decode-8 2535 518916 ns/op 168874 B/op 6792 allocs/op BenchmarkCodecXSuite/reset-enc-dec.../Benchmark__VMsgpack___Decode-8 2950 345167 ns/op 100373 B/op 2038 allocs/op BenchmarkCodecXSuite/reset-enc-dec.../Benchmark__Fxcbor_____Decode-8 5368 223671 ns/op 72502 B/op 1395 allocs/op >>>> bench TAGS: 'alltests x codec.safe' SUITE: BenchmarkCodecXSuite >>>> Skipping - these cannot (en|de)code TestStruc - encode (xml, gcbor, xdr), decode (xml, gcbor, xdr, sereal) BenchmarkCodecXSuite/options-false.../Benchmark__Msgpack____Encode-8 12834 94111 ns/op 10048 B/op 375 allocs/op BenchmarkCodecXSuite/options-false.../Benchmark__Binc_______Encode-8 12320 97540 ns/op 10048 B/op 375 allocs/op BenchmarkCodecXSuite/options-false.../Benchmark__Simple_____Encode-8 12633 94796 ns/op 10048 B/op 375 allocs/op BenchmarkCodecXSuite/options-false.../Benchmark__Cbor_______Encode-8 12376 97228 ns/op 10560 B/op 383 allocs/op BenchmarkCodecXSuite/options-false.../Benchmark__Json_______Encode-8 6630 183864 ns/op 10048 B/op 375 allocs/op BenchmarkCodecXSuite/options-false.../Benchmark__Std_Json___Encode-8 6175 211785 ns/op 75467 B/op 480 allocs/op BenchmarkCodecXSuite/options-false.../Benchmark__Gob________Encode-8 7707 140062 ns/op 167667 B/op 615 allocs/op BenchmarkCodecXSuite/options-false.../Benchmark__JsonIter___Encode-8 8404 154330 ns/op 55420 B/op 122 allocs/op BenchmarkCodecXSuite/options-false.../Benchmark__Bson_______Encode-8 4356 303658 ns/op 86836 B/op 1125 allocs/op BenchmarkCodecXSuite/options-false.../Benchmark__Mgobson____Encode-8 2762 386733 ns/op 293697 B/op 1816 allocs/op BenchmarkCodecXSuite/options-false.../Benchmark__VMsgpack___Encode-8 7219 161186 ns/op 140471 B/op 326 allocs/op BenchmarkCodecXSuite/options-false.../Benchmark__Fxcbor_____Encode-8 13002 90863 ns/op 47510 B/op 332 allocs/op BenchmarkCodecXSuite/options-false.../Benchmark__Sereal_____Encode-8 3376 306681 ns/op 271347 B/op 3353 allocs/op BenchmarkCodecXSuite/options-false.../Benchmark__Msgpack____Decode-8 6349 196928 ns/op 70748 B/op 1074 allocs/op BenchmarkCodecXSuite/options-false.../Benchmark__Binc_______Decode-8 6520 205724 ns/op 70765 B/op 1074 allocs/op BenchmarkCodecXSuite/options-false.../Benchmark__Simple_____Decode-8 5271 196213 ns/op 70751 B/op 1074 allocs/op BenchmarkCodecXSuite/options-false.../Benchmark__Cbor_______Decode-8 5154 208153 ns/op 70767 B/op 1074 allocs/op BenchmarkCodecXSuite/options-false.../Benchmark__Json_______Decode-8 2383 504359 ns/op 94575 B/op 1239 allocs/op BenchmarkCodecXSuite/options-false.../Benchmark__Std_Json___Decode-8 1258 939858 ns/op 137150 B/op 3114 allocs/op BenchmarkCodecXSuite/options-false.../Benchmark__Gob________Decode-8 4420 278367 ns/op 162664 B/op 2425 allocs/op BenchmarkCodecXSuite/options-false.../Benchmark__JsonIter___Decode-8 2379 518073 ns/op 131758 B/op 2658 allocs/op BenchmarkCodecXSuite/options-false.../Benchmark__Bson_______Decode-8 2582 475408 ns/op 193634 B/op 4560 allocs/op BenchmarkCodecXSuite/options-false.../Benchmark__Mgobson____Decode-8 2577 513887 ns/op 168888 B/op 6792 allocs/op BenchmarkCodecXSuite/options-false.../Benchmark__VMsgpack___Decode-8 3747 329438 ns/op 100363 B/op 2038 allocs/op BenchmarkCodecXSuite/options-false.../Benchmark__Fxcbor_____Decode-8 4945 223480 ns/op 72488 B/op 1395 allocs/op BenchmarkCodecXSuite/use-bufio-!bytes/Benchmark__Msgpack____Encode-8 10000 108569 ns/op 10096 B/op 376 allocs/op BenchmarkCodecXSuite/use-bufio-!bytes/Benchmark__Binc_______Encode-8 10000 111579 ns/op 10096 B/op 376 allocs/op BenchmarkCodecXSuite/use-bufio-!bytes/Benchmark__Simple_____Encode-8 10000 112287 ns/op 10096 B/op 376 allocs/op BenchmarkCodecXSuite/use-bufio-!bytes/Benchmark__Cbor_______Encode-8 10000 110123 ns/op 10608 B/op 384 allocs/op BenchmarkCodecXSuite/use-bufio-!bytes/Benchmark__Json_______Encode-8 5924 202015 ns/op 10096 B/op 376 allocs/op BenchmarkCodecXSuite/use-bufio-!bytes/Benchmark__Std_Json___Encode-8 6422 182701 ns/op 26367 B/op 480 allocs/op BenchmarkCodecXSuite/use-bufio-!bytes/Benchmark__Gob________Encode-8 8742 136384 ns/op 167666 B/op 615 allocs/op BenchmarkCodecXSuite/use-bufio-!bytes/Benchmark__JsonIter___Encode-8 6531 184177 ns/op 217602 B/op 139 allocs/op BenchmarkCodecXSuite/use-bufio-!bytes/Benchmark__Bson_______Encode-8 4551 263847 ns/op 86788 B/op 1125 allocs/op BenchmarkCodecXSuite/use-bufio-!bytes/Benchmark__Mgobson____Encode-8 3168 372409 ns/op 293699 B/op 1816 allocs/op BenchmarkCodecXSuite/use-bufio-!bytes/Benchmark__VMsgpack___Encode-8 8019 138535 ns/op 10800 B/op 319 allocs/op BenchmarkCodecXSuite/use-bufio-!bytes/Benchmark__Fxcbor_____Encode-8 12829 93843 ns/op 80188 B/op 340 allocs/op BenchmarkCodecXSuite/use-bufio-!bytes/Benchmark__Sereal_____Encode-8 3949 302703 ns/op 270916 B/op 3353 allocs/op BenchmarkCodecXSuite/use-bufio-!bytes/Benchmark__Msgpack____Decode-8 4917 259640 ns/op 87374 B/op 2271 allocs/op BenchmarkCodecXSuite/use-bufio-!bytes/Benchmark__Binc_______Decode-8 4448 294621 ns/op 85741 B/op 1807 allocs/op BenchmarkCodecXSuite/use-bufio-!bytes/Benchmark__Simple_____Decode-8 4111 279382 ns/op 86524 B/op 1895 allocs/op BenchmarkCodecXSuite/use-bufio-!bytes/Benchmark__Cbor_______Decode-8 4136 264182 ns/op 86510 B/op 1895 allocs/op BenchmarkCodecXSuite/use-bufio-!bytes/Benchmark__Json_______Decode-8 1860 619793 ns/op 95013 B/op 1337 allocs/op BenchmarkCodecXSuite/use-bufio-!bytes/Benchmark__Std_Json___Decode-8 1155 1004769 ns/op 266534 B/op 3126 allocs/op BenchmarkCodecXSuite/use-bufio-!bytes/Benchmark__Gob________Decode-8 4042 270296 ns/op 162663 B/op 2425 allocs/op BenchmarkCodecXSuite/use-bufio-!bytes/Benchmark__JsonIter___Decode-8 2313 531253 ns/op 136031 B/op 2807 allocs/op BenchmarkCodecXSuite/use-bufio-!bytes/Benchmark__Bson_______Decode-8 2594 462648 ns/op 193640 B/op 4560 allocs/op BenchmarkCodecXSuite/use-bufio-!bytes/Benchmark__Mgobson____Decode-8 2564 495949 ns/op 168885 B/op 6792 allocs/op BenchmarkCodecXSuite/use-bufio-!bytes/Benchmark__VMsgpack___Decode-8 3458 357635 ns/op 101451 B/op 2042 allocs/op BenchmarkCodecXSuite/use-bufio-!bytes/Benchmark__Fxcbor_____Decode-8 3253 357505 ns/op 201588 B/op 1403 allocs/op BenchmarkCodecXSuite/reset-enc-dec.../Benchmark__Msgpack____Encode-8 12632 94242 ns/op 10048 B/op 375 allocs/op BenchmarkCodecXSuite/reset-enc-dec.../Benchmark__Binc_______Encode-8 12104 98586 ns/op 10048 B/op 375 allocs/op BenchmarkCodecXSuite/reset-enc-dec.../Benchmark__Simple_____Encode-8 12489 95634 ns/op 10048 B/op 375 allocs/op BenchmarkCodecXSuite/reset-enc-dec.../Benchmark__Cbor_______Encode-8 12315 96947 ns/op 10560 B/op 383 allocs/op BenchmarkCodecXSuite/reset-enc-dec.../Benchmark__Json_______Encode-8 6446 188931 ns/op 10048 B/op 375 allocs/op BenchmarkCodecXSuite/reset-enc-dec.../Benchmark__Std_Json___Encode-8 6175 201648 ns/op 75492 B/op 480 allocs/op BenchmarkCodecXSuite/reset-enc-dec.../Benchmark__Gob________Encode-8 8583 136985 ns/op 167669 B/op 615 allocs/op BenchmarkCodecXSuite/reset-enc-dec.../Benchmark__JsonIter___Encode-8 8209 144402 ns/op 55448 B/op 122 allocs/op BenchmarkCodecXSuite/reset-enc-dec.../Benchmark__Bson_______Encode-8 4552 265986 ns/op 86927 B/op 1125 allocs/op BenchmarkCodecXSuite/reset-enc-dec.../Benchmark__Mgobson____Encode-8 3416 346078 ns/op 293697 B/op 1816 allocs/op BenchmarkCodecXSuite/reset-enc-dec.../Benchmark__VMsgpack___Encode-8 7081 164445 ns/op 140475 B/op 326 allocs/op BenchmarkCodecXSuite/reset-enc-dec.../Benchmark__Fxcbor_____Encode-8 14076 89788 ns/op 47581 B/op 332 allocs/op BenchmarkCodecXSuite/reset-enc-dec.../Benchmark__Sereal_____Encode-8 3901 303522 ns/op 270692 B/op 3353 allocs/op BenchmarkCodecXSuite/reset-enc-dec.../Benchmark__Msgpack____Decode-8 6378 191068 ns/op 70751 B/op 1074 allocs/op BenchmarkCodecXSuite/reset-enc-dec.../Benchmark__Binc_______Decode-8 6494 192095 ns/op 70766 B/op 1074 allocs/op BenchmarkCodecXSuite/reset-enc-dec.../Benchmark__Simple_____Decode-8 6061 198095 ns/op 70766 B/op 1074 allocs/op BenchmarkCodecXSuite/reset-enc-dec.../Benchmark__Cbor_______Decode-8 6084 230823 ns/op 70767 B/op 1074 allocs/op BenchmarkCodecXSuite/reset-enc-dec.../Benchmark__Json_______Decode-8 2054 508500 ns/op 94573 B/op 1239 allocs/op BenchmarkCodecXSuite/reset-enc-dec.../Benchmark__Std_Json___Decode-8 1249 944182 ns/op 137168 B/op 3114 allocs/op BenchmarkCodecXSuite/reset-enc-dec.../Benchmark__Gob________Decode-8 4381 291493 ns/op 162681 B/op 2425 allocs/op BenchmarkCodecXSuite/reset-enc-dec.../Benchmark__JsonIter___Decode-8 2373 499123 ns/op 131763 B/op 2658 allocs/op BenchmarkCodecXSuite/reset-enc-dec.../Benchmark__Bson_______Decode-8 2580 472188 ns/op 193610 B/op 4560 allocs/op BenchmarkCodecXSuite/reset-enc-dec.../Benchmark__Mgobson____Decode-8 2344 565605 ns/op 168876 B/op 6792 allocs/op BenchmarkCodecXSuite/reset-enc-dec.../Benchmark__VMsgpack___Decode-8 3646 322762 ns/op 100368 B/op 2038 allocs/op BenchmarkCodecXSuite/reset-enc-dec.../Benchmark__Fxcbor_____Decode-8 4962 233407 ns/op 72505 B/op 1395 allocs/op >>>> bench TAGS: 'alltests x codec.notfastpath' SUITE: BenchmarkCodecXSuite >>>> Skipping - these cannot (en|de)code TestStruc - encode (xml, gcbor, xdr), decode (xml, gcbor, xdr, sereal) BenchmarkCodecXSuite/options-false.../Benchmark__Msgpack____Encode-8 15454 76280 ns/op 24 B/op 1 allocs/op BenchmarkCodecXSuite/options-false.../Benchmark__Binc_______Encode-8 14907 80395 ns/op 24 B/op 1 allocs/op BenchmarkCodecXSuite/options-false.../Benchmark__Simple_____Encode-8 14944 81478 ns/op 24 B/op 1 allocs/op BenchmarkCodecXSuite/options-false.../Benchmark__Cbor_______Encode-8 15718 77047 ns/op 24 B/op 1 allocs/op BenchmarkCodecXSuite/options-false.../Benchmark__Json_______Encode-8 7600 161650 ns/op 24 B/op 1 allocs/op BenchmarkCodecXSuite/options-false.../Benchmark__Std_Json___Encode-8 6276 213839 ns/op 75467 B/op 480 allocs/op BenchmarkCodecXSuite/options-false.../Benchmark__Gob________Encode-8 6856 166040 ns/op 167670 B/op 615 allocs/op BenchmarkCodecXSuite/options-false.../Benchmark__JsonIter___Encode-8 7795 182085 ns/op 55420 B/op 122 allocs/op BenchmarkCodecXSuite/options-false.../Benchmark__Bson_______Encode-8 4683 259696 ns/op 86735 B/op 1125 allocs/op BenchmarkCodecXSuite/options-false.../Benchmark__Mgobson____Encode-8 3393 388325 ns/op 293668 B/op 1816 allocs/op BenchmarkCodecXSuite/options-false.../Benchmark__VMsgpack___Encode-8 6283 160829 ns/op 140472 B/op 326 allocs/op BenchmarkCodecXSuite/options-false.../Benchmark__Fxcbor_____Encode-8 12361 108434 ns/op 47465 B/op 332 allocs/op BenchmarkCodecXSuite/options-false.../Benchmark__Sereal_____Encode-8 2466 480784 ns/op 269094 B/op 3354 allocs/op BenchmarkCodecXSuite/options-false.../Benchmark__Msgpack____Decode-8 7144 175039 ns/op 37991 B/op 351 allocs/op BenchmarkCodecXSuite/options-false.../Benchmark__Binc_______Decode-8 6921 159663 ns/op 37988 B/op 351 allocs/op BenchmarkCodecXSuite/options-false.../Benchmark__Simple_____Decode-8 7080 172738 ns/op 37990 B/op 351 allocs/op BenchmarkCodecXSuite/options-false.../Benchmark__Cbor_______Decode-8 5962 181144 ns/op 37990 B/op 351 allocs/op BenchmarkCodecXSuite/options-false.../Benchmark__Json_______Decode-8 2510 473101 ns/op 76601 B/op 551 allocs/op BenchmarkCodecXSuite/options-false.../Benchmark__Std_Json___Decode-8 1263 943667 ns/op 137149 B/op 3114 allocs/op BenchmarkCodecXSuite/options-false.../Benchmark__Gob________Decode-8 4363 285688 ns/op 162650 B/op 2425 allocs/op BenchmarkCodecXSuite/options-false.../Benchmark__JsonIter___Decode-8 2323 527315 ns/op 131743 B/op 2658 allocs/op BenchmarkCodecXSuite/options-false.../Benchmark__Bson_______Decode-8 2073 513619 ns/op 193616 B/op 4560 allocs/op BenchmarkCodecXSuite/options-false.../Benchmark__Mgobson____Decode-8 2577 483888 ns/op 168901 B/op 6792 allocs/op BenchmarkCodecXSuite/options-false.../Benchmark__VMsgpack___Decode-8 3116 355090 ns/op 100388 B/op 2038 allocs/op BenchmarkCodecXSuite/options-false.../Benchmark__Fxcbor_____Decode-8 5359 236135 ns/op 72499 B/op 1395 allocs/op BenchmarkCodecXSuite/use-bufio-!bytes/Benchmark__Msgpack____Encode-8 12853 93495 ns/op 72 B/op 2 allocs/op BenchmarkCodecXSuite/use-bufio-!bytes/Benchmark__Binc_______Encode-8 12290 91879 ns/op 72 B/op 2 allocs/op BenchmarkCodecXSuite/use-bufio-!bytes/Benchmark__Simple_____Encode-8 13041 96125 ns/op 72 B/op 2 allocs/op BenchmarkCodecXSuite/use-bufio-!bytes/Benchmark__Cbor_______Encode-8 13086 89673 ns/op 72 B/op 2 allocs/op BenchmarkCodecXSuite/use-bufio-!bytes/Benchmark__Json_______Encode-8 6796 194535 ns/op 72 B/op 2 allocs/op BenchmarkCodecXSuite/use-bufio-!bytes/Benchmark__Std_Json___Encode-8 6446 180438 ns/op 26387 B/op 480 allocs/op BenchmarkCodecXSuite/use-bufio-!bytes/Benchmark__Gob________Encode-8 8556 136520 ns/op 167666 B/op 615 allocs/op BenchmarkCodecXSuite/use-bufio-!bytes/Benchmark__JsonIter___Encode-8 6334 184130 ns/op 217602 B/op 139 allocs/op BenchmarkCodecXSuite/use-bufio-!bytes/Benchmark__Bson_______Encode-8 4702 294549 ns/op 86697 B/op 1125 allocs/op BenchmarkCodecXSuite/use-bufio-!bytes/Benchmark__Mgobson____Encode-8 3433 344699 ns/op 293698 B/op 1816 allocs/op BenchmarkCodecXSuite/use-bufio-!bytes/Benchmark__VMsgpack___Encode-8 8986 134353 ns/op 10800 B/op 319 allocs/op BenchmarkCodecXSuite/use-bufio-!bytes/Benchmark__Fxcbor_____Encode-8 12733 94147 ns/op 80246 B/op 340 allocs/op BenchmarkCodecXSuite/use-bufio-!bytes/Benchmark__Sereal_____Encode-8 3913 303829 ns/op 269526 B/op 3354 allocs/op BenchmarkCodecXSuite/use-bufio-!bytes/Benchmark__Msgpack____Decode-8 4774 256161 ns/op 86539 B/op 2227 allocs/op BenchmarkCodecXSuite/use-bufio-!bytes/Benchmark__Binc_______Decode-8 4134 257878 ns/op 84927 B/op 1769 allocs/op BenchmarkCodecXSuite/use-bufio-!bytes/Benchmark__Simple_____Decode-8 4394 254985 ns/op 85751 B/op 1849 allocs/op BenchmarkCodecXSuite/use-bufio-!bytes/Benchmark__Cbor_______Decode-8 4614 276240 ns/op 85845 B/op 1852 allocs/op BenchmarkCodecXSuite/use-bufio-!bytes/Benchmark__Json_______Decode-8 1776 627768 ns/op 96892 B/op 1285 allocs/op BenchmarkCodecXSuite/use-bufio-!bytes/Benchmark__Std_Json___Decode-8 1197 998248 ns/op 266546 B/op 3126 allocs/op BenchmarkCodecXSuite/use-bufio-!bytes/Benchmark__Gob________Decode-8 4394 271945 ns/op 162618 B/op 2425 allocs/op BenchmarkCodecXSuite/use-bufio-!bytes/Benchmark__JsonIter___Decode-8 2181 528894 ns/op 135762 B/op 2801 allocs/op BenchmarkCodecXSuite/use-bufio-!bytes/Benchmark__Bson_______Decode-8 2434 517011 ns/op 193601 B/op 4560 allocs/op BenchmarkCodecXSuite/use-bufio-!bytes/Benchmark__Mgobson____Decode-8 2179 499919 ns/op 168894 B/op 6792 allocs/op BenchmarkCodecXSuite/use-bufio-!bytes/Benchmark__VMsgpack___Decode-8 3523 358472 ns/op 101440 B/op 2042 allocs/op BenchmarkCodecXSuite/use-bufio-!bytes/Benchmark__Fxcbor_____Decode-8 3896 291021 ns/op 201593 B/op 1403 allocs/op BenchmarkCodecXSuite/reset-enc-dec.../Benchmark__Msgpack____Encode-8 15482 76219 ns/op 24 B/op 1 allocs/op BenchmarkCodecXSuite/reset-enc-dec.../Benchmark__Binc_______Encode-8 14254 84882 ns/op 24 B/op 1 allocs/op BenchmarkCodecXSuite/reset-enc-dec.../Benchmark__Simple_____Encode-8 15619 80982 ns/op 24 B/op 1 allocs/op BenchmarkCodecXSuite/reset-enc-dec.../Benchmark__Cbor_______Encode-8 15442 81289 ns/op 24 B/op 1 allocs/op BenchmarkCodecXSuite/reset-enc-dec.../Benchmark__Json_______Encode-8 7664 172050 ns/op 24 B/op 1 allocs/op BenchmarkCodecXSuite/reset-enc-dec.../Benchmark__Std_Json___Encode-8 6276 202840 ns/op 75491 B/op 480 allocs/op BenchmarkCodecXSuite/reset-enc-dec.../Benchmark__Gob________Encode-8 8486 137177 ns/op 167669 B/op 615 allocs/op BenchmarkCodecXSuite/reset-enc-dec.../Benchmark__JsonIter___Encode-8 8176 144208 ns/op 55422 B/op 122 allocs/op BenchmarkCodecXSuite/reset-enc-dec.../Benchmark__Bson_______Encode-8 4718 259246 ns/op 86830 B/op 1125 allocs/op BenchmarkCodecXSuite/reset-enc-dec.../Benchmark__Mgobson____Encode-8 3390 350226 ns/op 293707 B/op 1816 allocs/op BenchmarkCodecXSuite/reset-enc-dec.../Benchmark__VMsgpack___Encode-8 6954 164195 ns/op 140475 B/op 326 allocs/op BenchmarkCodecXSuite/reset-enc-dec.../Benchmark__Fxcbor_____Encode-8 13603 91147 ns/op 47514 B/op 332 allocs/op BenchmarkCodecXSuite/reset-enc-dec.../Benchmark__Sereal_____Encode-8 2676 437055 ns/op 268812 B/op 3354 allocs/op BenchmarkCodecXSuite/reset-enc-dec.../Benchmark__Msgpack____Decode-8 5149 196316 ns/op 37991 B/op 351 allocs/op BenchmarkCodecXSuite/reset-enc-dec.../Benchmark__Binc_______Decode-8 6375 189666 ns/op 37989 B/op 351 allocs/op BenchmarkCodecXSuite/reset-enc-dec.../Benchmark__Simple_____Decode-8 5740 184705 ns/op 37989 B/op 351 allocs/op BenchmarkCodecXSuite/reset-enc-dec.../Benchmark__Cbor_______Decode-8 5943 196839 ns/op 37988 B/op 351 allocs/op BenchmarkCodecXSuite/reset-enc-dec.../Benchmark__Json_______Decode-8 2210 516000 ns/op 76591 B/op 551 allocs/op BenchmarkCodecXSuite/reset-enc-dec.../Benchmark__Std_Json___Decode-8 1167 987757 ns/op 137157 B/op 3114 allocs/op BenchmarkCodecXSuite/reset-enc-dec.../Benchmark__Gob________Decode-8 4388 315726 ns/op 162634 B/op 2425 allocs/op BenchmarkCodecXSuite/reset-enc-dec.../Benchmark__JsonIter___Decode-8 2109 545242 ns/op 131705 B/op 2658 allocs/op BenchmarkCodecXSuite/reset-enc-dec.../Benchmark__Bson_______Decode-8 2251 549066 ns/op 193627 B/op 4560 allocs/op BenchmarkCodecXSuite/reset-enc-dec.../Benchmark__Mgobson____Decode-8 2546 496461 ns/op 168891 B/op 6792 allocs/op BenchmarkCodecXSuite/reset-enc-dec.../Benchmark__VMsgpack___Decode-8 3333 309413 ns/op 100352 B/op 2038 allocs/op BenchmarkCodecXSuite/reset-enc-dec.../Benchmark__Fxcbor_____Decode-8 5421 258428 ns/op 72468 B/op 1395 allocs/op >>>> bench TAGS: 'alltests x codec.notfastpath codec.safe' SUITE: BenchmarkCodecXSuite >>>> Skipping - these cannot (en|de)code TestStruc - encode (xml, gcbor, xdr), decode (xml, gcbor, xdr, sereal) BenchmarkCodecXSuite/options-false.../Benchmark__Msgpack____Encode-8 9883 108437 ns/op 10712 B/op 366 allocs/op BenchmarkCodecXSuite/options-false.../Benchmark__Binc_______Encode-8 10000 114234 ns/op 10712 B/op 366 allocs/op BenchmarkCodecXSuite/options-false.../Benchmark__Simple_____Encode-8 10000 107351 ns/op 10712 B/op 366 allocs/op BenchmarkCodecXSuite/options-false.../Benchmark__Cbor_______Encode-8 9830 109704 ns/op 11224 B/op 374 allocs/op BenchmarkCodecXSuite/options-false.../Benchmark__Json_______Encode-8 5888 202876 ns/op 10712 B/op 366 allocs/op BenchmarkCodecXSuite/options-false.../Benchmark__Std_Json___Encode-8 6051 204219 ns/op 75467 B/op 480 allocs/op BenchmarkCodecXSuite/options-false.../Benchmark__Gob________Encode-8 8463 145946 ns/op 167668 B/op 615 allocs/op BenchmarkCodecXSuite/options-false.../Benchmark__JsonIter___Encode-8 6733 161411 ns/op 55420 B/op 122 allocs/op BenchmarkCodecXSuite/options-false.../Benchmark__Bson_______Encode-8 4473 273579 ns/op 86784 B/op 1125 allocs/op BenchmarkCodecXSuite/options-false.../Benchmark__Mgobson____Encode-8 3494 379893 ns/op 293683 B/op 1816 allocs/op BenchmarkCodecXSuite/options-false.../Benchmark__VMsgpack___Encode-8 6744 186400 ns/op 140472 B/op 326 allocs/op BenchmarkCodecXSuite/options-false.../Benchmark__Fxcbor_____Encode-8 10000 120598 ns/op 47444 B/op 332 allocs/op BenchmarkCodecXSuite/options-false.../Benchmark__Sereal_____Encode-8 3315 368438 ns/op 266138 B/op 3353 allocs/op BenchmarkCodecXSuite/options-false.../Benchmark__Msgpack____Decode-8 5094 244518 ns/op 69695 B/op 1030 allocs/op BenchmarkCodecXSuite/options-false.../Benchmark__Binc_______Decode-8 5104 256413 ns/op 69696 B/op 1030 allocs/op BenchmarkCodecXSuite/options-false.../Benchmark__Simple_____Decode-8 4987 229591 ns/op 69682 B/op 1030 allocs/op BenchmarkCodecXSuite/options-false.../Benchmark__Cbor_______Decode-8 4316 256472 ns/op 69693 B/op 1030 allocs/op BenchmarkCodecXSuite/options-false.../Benchmark__Json_______Decode-8 1989 564774 ns/op 97977 B/op 1331 allocs/op BenchmarkCodecXSuite/options-false.../Benchmark__Std_Json___Decode-8 1261 942241 ns/op 137178 B/op 3114 allocs/op BenchmarkCodecXSuite/options-false.../Benchmark__Gob________Decode-8 4381 267174 ns/op 162664 B/op 2425 allocs/op BenchmarkCodecXSuite/options-false.../Benchmark__JsonIter___Decode-8 2376 494911 ns/op 131750 B/op 2658 allocs/op BenchmarkCodecXSuite/options-false.../Benchmark__Bson_______Decode-8 2508 503460 ns/op 193612 B/op 4560 allocs/op BenchmarkCodecXSuite/options-false.../Benchmark__Mgobson____Decode-8 2337 498277 ns/op 168878 B/op 6792 allocs/op BenchmarkCodecXSuite/options-false.../Benchmark__VMsgpack___Decode-8 3838 330730 ns/op 100353 B/op 2038 allocs/op BenchmarkCodecXSuite/options-false.../Benchmark__Fxcbor_____Decode-8 4962 221714 ns/op 72520 B/op 1395 allocs/op BenchmarkCodecXSuite/use-bufio-!bytes/Benchmark__Msgpack____Encode-8 9919 120702 ns/op 10760 B/op 367 allocs/op BenchmarkCodecXSuite/use-bufio-!bytes/Benchmark__Binc_______Encode-8 9500 127594 ns/op 10760 B/op 367 allocs/op BenchmarkCodecXSuite/use-bufio-!bytes/Benchmark__Simple_____Encode-8 9272 123738 ns/op 10760 B/op 367 allocs/op BenchmarkCodecXSuite/use-bufio-!bytes/Benchmark__Cbor_______Encode-8 9682 124639 ns/op 11272 B/op 375 allocs/op BenchmarkCodecXSuite/use-bufio-!bytes/Benchmark__Json_______Encode-8 5498 224704 ns/op 10760 B/op 367 allocs/op BenchmarkCodecXSuite/use-bufio-!bytes/Benchmark__Std_Json___Encode-8 6240 184163 ns/op 26389 B/op 480 allocs/op BenchmarkCodecXSuite/use-bufio-!bytes/Benchmark__Gob________Encode-8 8535 138109 ns/op 167667 B/op 615 allocs/op BenchmarkCodecXSuite/use-bufio-!bytes/Benchmark__JsonIter___Encode-8 6249 189216 ns/op 217602 B/op 139 allocs/op BenchmarkCodecXSuite/use-bufio-!bytes/Benchmark__Bson_______Encode-8 4406 291079 ns/op 86791 B/op 1125 allocs/op BenchmarkCodecXSuite/use-bufio-!bytes/Benchmark__Mgobson____Encode-8 3328 351823 ns/op 293690 B/op 1816 allocs/op BenchmarkCodecXSuite/use-bufio-!bytes/Benchmark__VMsgpack___Encode-8 8840 137235 ns/op 10800 B/op 319 allocs/op BenchmarkCodecXSuite/use-bufio-!bytes/Benchmark__Fxcbor_____Encode-8 12704 96113 ns/op 80193 B/op 340 allocs/op BenchmarkCodecXSuite/use-bufio-!bytes/Benchmark__Sereal_____Encode-8 3831 312404 ns/op 266637 B/op 3353 allocs/op BenchmarkCodecXSuite/use-bufio-!bytes/Benchmark__Msgpack____Decode-8 4214 296739 ns/op 86322 B/op 2227 allocs/op BenchmarkCodecXSuite/use-bufio-!bytes/Benchmark__Binc_______Decode-8 4418 288931 ns/op 84697 B/op 1763 allocs/op BenchmarkCodecXSuite/use-bufio-!bytes/Benchmark__Simple_____Decode-8 4044 295855 ns/op 85485 B/op 1851 allocs/op BenchmarkCodecXSuite/use-bufio-!bytes/Benchmark__Cbor_______Decode-8 3416 316448 ns/op 85484 B/op 1851 allocs/op BenchmarkCodecXSuite/use-bufio-!bytes/Benchmark__Json_______Decode-8 1741 681858 ns/op 98438 B/op 1429 allocs/op BenchmarkCodecXSuite/use-bufio-!bytes/Benchmark__Std_Json___Decode-8 1204 1002442 ns/op 266539 B/op 3126 allocs/op BenchmarkCodecXSuite/use-bufio-!bytes/Benchmark__Gob________Decode-8 4057 293932 ns/op 162654 B/op 2425 allocs/op BenchmarkCodecXSuite/use-bufio-!bytes/Benchmark__JsonIter___Decode-8 2120 532318 ns/op 136440 B/op 2819 allocs/op BenchmarkCodecXSuite/use-bufio-!bytes/Benchmark__Bson_______Decode-8 2475 506253 ns/op 193663 B/op 4560 allocs/op BenchmarkCodecXSuite/use-bufio-!bytes/Benchmark__Mgobson____Decode-8 2406 492343 ns/op 168878 B/op 6792 allocs/op BenchmarkCodecXSuite/use-bufio-!bytes/Benchmark__VMsgpack___Decode-8 3877 311956 ns/op 101463 B/op 2042 allocs/op BenchmarkCodecXSuite/use-bufio-!bytes/Benchmark__Fxcbor_____Decode-8 3498 310457 ns/op 201573 B/op 1403 allocs/op BenchmarkCodecXSuite/reset-enc-dec.../Benchmark__Msgpack____Encode-8 10000 108591 ns/op 10712 B/op 366 allocs/op BenchmarkCodecXSuite/reset-enc-dec.../Benchmark__Binc_______Encode-8 10000 114393 ns/op 10712 B/op 366 allocs/op BenchmarkCodecXSuite/reset-enc-dec.../Benchmark__Simple_____Encode-8 10000 108579 ns/op 10712 B/op 366 allocs/op BenchmarkCodecXSuite/reset-enc-dec.../Benchmark__Cbor_______Encode-8 10000 111696 ns/op 11224 B/op 374 allocs/op BenchmarkCodecXSuite/reset-enc-dec.../Benchmark__Json_______Encode-8 5847 201171 ns/op 10712 B/op 366 allocs/op BenchmarkCodecXSuite/reset-enc-dec.../Benchmark__Std_Json___Encode-8 6195 196741 ns/op 75491 B/op 480 allocs/op BenchmarkCodecXSuite/reset-enc-dec.../Benchmark__Gob________Encode-8 8281 145463 ns/op 167666 B/op 615 allocs/op BenchmarkCodecXSuite/reset-enc-dec.../Benchmark__JsonIter___Encode-8 7755 146515 ns/op 55449 B/op 122 allocs/op BenchmarkCodecXSuite/reset-enc-dec.../Benchmark__Bson_______Encode-8 4338 291147 ns/op 86841 B/op 1125 allocs/op BenchmarkCodecXSuite/reset-enc-dec.../Benchmark__Mgobson____Encode-8 3324 372316 ns/op 293697 B/op 1816 allocs/op BenchmarkCodecXSuite/reset-enc-dec.../Benchmark__VMsgpack___Encode-8 6849 168739 ns/op 140475 B/op 326 allocs/op BenchmarkCodecXSuite/reset-enc-dec.../Benchmark__Fxcbor_____Encode-8 13225 89219 ns/op 47642 B/op 332 allocs/op BenchmarkCodecXSuite/reset-enc-dec.../Benchmark__Sereal_____Encode-8 3776 315202 ns/op 266297 B/op 3353 allocs/op BenchmarkCodecXSuite/reset-enc-dec.../Benchmark__Msgpack____Decode-8 5275 239807 ns/op 69697 B/op 1030 allocs/op BenchmarkCodecXSuite/reset-enc-dec.../Benchmark__Binc_______Decode-8 4657 228079 ns/op 69659 B/op 1030 allocs/op BenchmarkCodecXSuite/reset-enc-dec.../Benchmark__Simple_____Decode-8 4981 226507 ns/op 69660 B/op 1030 allocs/op BenchmarkCodecXSuite/reset-enc-dec.../Benchmark__Cbor_______Decode-8 5104 247091 ns/op 69659 B/op 1030 allocs/op BenchmarkCodecXSuite/reset-enc-dec.../Benchmark__Json_______Decode-8 2096 573747 ns/op 97978 B/op 1331 allocs/op BenchmarkCodecXSuite/reset-enc-dec.../Benchmark__Std_Json___Decode-8 1257 951246 ns/op 137139 B/op 3114 allocs/op BenchmarkCodecXSuite/reset-enc-dec.../Benchmark__Gob________Decode-8 4356 271424 ns/op 162622 B/op 2425 allocs/op BenchmarkCodecXSuite/reset-enc-dec.../Benchmark__JsonIter___Decode-8 2434 494367 ns/op 131747 B/op 2658 allocs/op BenchmarkCodecXSuite/reset-enc-dec.../Benchmark__Bson_______Decode-8 2484 485385 ns/op 193556 B/op 4560 allocs/op BenchmarkCodecXSuite/reset-enc-dec.../Benchmark__Mgobson____Decode-8 2451 478894 ns/op 168890 B/op 6792 allocs/op BenchmarkCodecXSuite/reset-enc-dec.../Benchmark__VMsgpack___Decode-8 3891 307443 ns/op 100372 B/op 2038 allocs/op BenchmarkCodecXSuite/reset-enc-dec.../Benchmark__Fxcbor_____Decode-8 5320 232175 ns/op 72473 B/op 1395 allocs/op >>>> bench TAGS: 'alltests x codecgen' SUITE: BenchmarkCodecXSuite >>>> Skipping - these cannot (en|de)code TestStruc - encode (xml, gcbor, xdr), decode (xml, gcbor, xdr, sereal) BenchmarkCodecXSuite/options-false.../Benchmark__Msgpack____Encode-8 34477 34360 ns/op 1432 B/op 2 allocs/op BenchmarkCodecXSuite/options-false.../Benchmark__Binc_______Encode-8 31664 37760 ns/op 1432 B/op 2 allocs/op BenchmarkCodecXSuite/options-false.../Benchmark__Simple_____Encode-8 33848 35438 ns/op 1432 B/op 2 allocs/op BenchmarkCodecXSuite/options-false.../Benchmark__Cbor_______Encode-8 32484 35391 ns/op 1432 B/op 2 allocs/op BenchmarkCodecXSuite/options-false.../Benchmark__Json_______Encode-8 10000 120819 ns/op 1432 B/op 2 allocs/op BenchmarkCodecXSuite/options-false.../Benchmark__Std_Json___Encode-8 5974 214840 ns/op 75488 B/op 480 allocs/op BenchmarkCodecXSuite/options-false.../Benchmark__Gob________Encode-8 8082 133433 ns/op 167668 B/op 615 allocs/op BenchmarkCodecXSuite/options-false.../Benchmark__JsonIter___Encode-8 8313 151389 ns/op 55420 B/op 122 allocs/op BenchmarkCodecXSuite/options-false.../Benchmark__Bson_______Encode-8 3920 286357 ns/op 86797 B/op 1125 allocs/op BenchmarkCodecXSuite/options-false.../Benchmark__Mgobson____Encode-8 3074 444581 ns/op 293687 B/op 1816 allocs/op BenchmarkCodecXSuite/options-false.../Benchmark__VMsgpack___Encode-8 4990 217977 ns/op 140471 B/op 326 allocs/op BenchmarkCodecXSuite/options-false.../Benchmark__Fxcbor_____Encode-8 13380 93145 ns/op 47565 B/op 332 allocs/op BenchmarkCodecXSuite/options-false.../Benchmark__Sereal_____Encode-8 3205 327895 ns/op 263329 B/op 3353 allocs/op BenchmarkCodecXSuite/options-false.../Benchmark__Msgpack____Decode-8 15018 91187 ns/op 35910 B/op 308 allocs/op BenchmarkCodecXSuite/options-false.../Benchmark__Binc_______Decode-8 14968 91743 ns/op 35910 B/op 308 allocs/op BenchmarkCodecXSuite/options-false.../Benchmark__Simple_____Decode-8 14266 81169 ns/op 35909 B/op 308 allocs/op BenchmarkCodecXSuite/options-false.../Benchmark__Cbor_______Decode-8 10000 107021 ns/op 35909 B/op 308 allocs/op BenchmarkCodecXSuite/options-false.../Benchmark__Json_______Decode-8 3105 377373 ns/op 70127 B/op 500 allocs/op BenchmarkCodecXSuite/options-false.../Benchmark__Std_Json___Decode-8 1251 956359 ns/op 137162 B/op 3114 allocs/op BenchmarkCodecXSuite/options-false.../Benchmark__Gob________Decode-8 4476 303039 ns/op 162616 B/op 2425 allocs/op BenchmarkCodecXSuite/options-false.../Benchmark__JsonIter___Decode-8 2059 521461 ns/op 131756 B/op 2658 allocs/op BenchmarkCodecXSuite/options-false.../Benchmark__Bson_______Decode-8 2618 551916 ns/op 193605 B/op 4560 allocs/op BenchmarkCodecXSuite/options-false.../Benchmark__Mgobson____Decode-8 2034 534694 ns/op 168834 B/op 6792 allocs/op BenchmarkCodecXSuite/options-false.../Benchmark__VMsgpack___Decode-8 3004 339429 ns/op 100373 B/op 2038 allocs/op BenchmarkCodecXSuite/options-false.../Benchmark__Fxcbor_____Decode-8 5318 232874 ns/op 72521 B/op 1395 allocs/op BenchmarkCodecXSuite/use-bufio-!bytes/Benchmark__Msgpack____Encode-8 25972 45710 ns/op 1480 B/op 3 allocs/op BenchmarkCodecXSuite/use-bufio-!bytes/Benchmark__Binc_______Encode-8 23487 49888 ns/op 1480 B/op 3 allocs/op BenchmarkCodecXSuite/use-bufio-!bytes/Benchmark__Simple_____Encode-8 24619 48182 ns/op 1480 B/op 3 allocs/op BenchmarkCodecXSuite/use-bufio-!bytes/Benchmark__Cbor_______Encode-8 25773 46076 ns/op 1480 B/op 3 allocs/op BenchmarkCodecXSuite/use-bufio-!bytes/Benchmark__Json_______Encode-8 9152 135753 ns/op 1480 B/op 3 allocs/op BenchmarkCodecXSuite/use-bufio-!bytes/Benchmark__Std_Json___Encode-8 6285 180660 ns/op 26346 B/op 480 allocs/op BenchmarkCodecXSuite/use-bufio-!bytes/Benchmark__Gob________Encode-8 8396 138363 ns/op 167666 B/op 615 allocs/op BenchmarkCodecXSuite/use-bufio-!bytes/Benchmark__JsonIter___Encode-8 5937 187972 ns/op 217602 B/op 139 allocs/op BenchmarkCodecXSuite/use-bufio-!bytes/Benchmark__Bson_______Encode-8 4738 284969 ns/op 86739 B/op 1125 allocs/op BenchmarkCodecXSuite/use-bufio-!bytes/Benchmark__Mgobson____Encode-8 3320 347472 ns/op 293711 B/op 1816 allocs/op BenchmarkCodecXSuite/use-bufio-!bytes/Benchmark__VMsgpack___Encode-8 9111 135578 ns/op 10800 B/op 319 allocs/op BenchmarkCodecXSuite/use-bufio-!bytes/Benchmark__Fxcbor_____Encode-8 12730 94083 ns/op 80212 B/op 340 allocs/op BenchmarkCodecXSuite/use-bufio-!bytes/Benchmark__Sereal_____Encode-8 3916 302860 ns/op 263095 B/op 3353 allocs/op BenchmarkCodecXSuite/use-bufio-!bytes/Benchmark__Msgpack____Decode-8 7728 152489 ns/op 82229 B/op 2111 allocs/op BenchmarkCodecXSuite/use-bufio-!bytes/Benchmark__Binc_______Decode-8 8085 153221 ns/op 80596 B/op 1647 allocs/op BenchmarkCodecXSuite/use-bufio-!bytes/Benchmark__Simple_____Decode-8 7796 160121 ns/op 81366 B/op 1735 allocs/op BenchmarkCodecXSuite/use-bufio-!bytes/Benchmark__Cbor_______Decode-8 6381 181599 ns/op 81353 B/op 1735 allocs/op BenchmarkCodecXSuite/use-bufio-!bytes/Benchmark__Json_______Decode-8 2006 526210 ns/op 88845 B/op 1168 allocs/op BenchmarkCodecXSuite/use-bufio-!bytes/Benchmark__Std_Json___Decode-8 1183 1027795 ns/op 266526 B/op 3126 allocs/op BenchmarkCodecXSuite/use-bufio-!bytes/Benchmark__Gob________Decode-8 4377 270572 ns/op 162671 B/op 2425 allocs/op BenchmarkCodecXSuite/use-bufio-!bytes/Benchmark__JsonIter___Decode-8 2314 515856 ns/op 136134 B/op 2815 allocs/op BenchmarkCodecXSuite/use-bufio-!bytes/Benchmark__Bson_______Decode-8 2612 468236 ns/op 193618 B/op 4560 allocs/op BenchmarkCodecXSuite/use-bufio-!bytes/Benchmark__Mgobson____Decode-8 2277 480097 ns/op 168896 B/op 6792 allocs/op BenchmarkCodecXSuite/use-bufio-!bytes/Benchmark__VMsgpack___Decode-8 3870 319900 ns/op 101430 B/op 2042 allocs/op BenchmarkCodecXSuite/use-bufio-!bytes/Benchmark__Fxcbor_____Decode-8 3758 306030 ns/op 201604 B/op 1403 allocs/op BenchmarkCodecXSuite/reset-enc-dec.../Benchmark__Msgpack____Encode-8 34213 34683 ns/op 1432 B/op 2 allocs/op BenchmarkCodecXSuite/reset-enc-dec.../Benchmark__Binc_______Encode-8 31346 37931 ns/op 1432 B/op 2 allocs/op BenchmarkCodecXSuite/reset-enc-dec.../Benchmark__Simple_____Encode-8 33396 35840 ns/op 1432 B/op 2 allocs/op BenchmarkCodecXSuite/reset-enc-dec.../Benchmark__Cbor_______Encode-8 33025 34897 ns/op 1432 B/op 2 allocs/op BenchmarkCodecXSuite/reset-enc-dec.../Benchmark__Json_______Encode-8 10000 122281 ns/op 1432 B/op 2 allocs/op BenchmarkCodecXSuite/reset-enc-dec.../Benchmark__Std_Json___Encode-8 5960 191223 ns/op 75470 B/op 480 allocs/op BenchmarkCodecXSuite/reset-enc-dec.../Benchmark__Gob________Encode-8 7736 146419 ns/op 167668 B/op 615 allocs/op BenchmarkCodecXSuite/reset-enc-dec.../Benchmark__JsonIter___Encode-8 7614 155628 ns/op 55422 B/op 122 allocs/op BenchmarkCodecXSuite/reset-enc-dec.../Benchmark__Bson_______Encode-8 4735 253840 ns/op 86695 B/op 1125 allocs/op BenchmarkCodecXSuite/reset-enc-dec.../Benchmark__Mgobson____Encode-8 3433 349359 ns/op 293702 B/op 1816 allocs/op BenchmarkCodecXSuite/reset-enc-dec.../Benchmark__VMsgpack___Encode-8 7141 166642 ns/op 140474 B/op 326 allocs/op BenchmarkCodecXSuite/reset-enc-dec.../Benchmark__Fxcbor_____Encode-8 13284 95055 ns/op 47638 B/op 332 allocs/op BenchmarkCodecXSuite/reset-enc-dec.../Benchmark__Sereal_____Encode-8 3507 338510 ns/op 262917 B/op 3353 allocs/op BenchmarkCodecXSuite/reset-enc-dec.../Benchmark__Msgpack____Decode-8 14209 78393 ns/op 35910 B/op 308 allocs/op BenchmarkCodecXSuite/reset-enc-dec.../Benchmark__Binc_______Decode-8 16040 79580 ns/op 35910 B/op 308 allocs/op BenchmarkCodecXSuite/reset-enc-dec.../Benchmark__Simple_____Decode-8 14482 89659 ns/op 35910 B/op 308 allocs/op BenchmarkCodecXSuite/reset-enc-dec.../Benchmark__Cbor_______Decode-8 13407 88520 ns/op 35909 B/op 308 allocs/op BenchmarkCodecXSuite/reset-enc-dec.../Benchmark__Json_______Decode-8 3010 381823 ns/op 70152 B/op 500 allocs/op BenchmarkCodecXSuite/reset-enc-dec.../Benchmark__Std_Json___Decode-8 1248 967175 ns/op 137139 B/op 3114 allocs/op BenchmarkCodecXSuite/reset-enc-dec.../Benchmark__Gob________Decode-8 4366 271556 ns/op 162637 B/op 2425 allocs/op BenchmarkCodecXSuite/reset-enc-dec.../Benchmark__JsonIter___Decode-8 2413 516669 ns/op 131786 B/op 2658 allocs/op BenchmarkCodecXSuite/reset-enc-dec.../Benchmark__Bson_______Decode-8 2624 487164 ns/op 193640 B/op 4560 allocs/op BenchmarkCodecXSuite/reset-enc-dec.../Benchmark__Mgobson____Decode-8 2152 491332 ns/op 168880 B/op 6792 allocs/op BenchmarkCodecXSuite/reset-enc-dec.../Benchmark__VMsgpack___Decode-8 3672 311630 ns/op 100324 B/op 2038 allocs/op BenchmarkCodecXSuite/reset-enc-dec.../Benchmark__Fxcbor_____Decode-8 5361 226635 ns/op 72487 B/op 1395 allocs/op >>>> bench TAGS: 'alltests x codecgen codec.safe' SUITE: BenchmarkCodecXSuite >>>> Skipping - these cannot (en|de)code TestStruc - encode (xml, gcbor, xdr), decode (xml, gcbor, xdr, sereal) BenchmarkCodecXSuite/options-false.../Benchmark__Msgpack____Encode-8 32658 37129 ns/op 1432 B/op 2 allocs/op BenchmarkCodecXSuite/options-false.../Benchmark__Binc_______Encode-8 28774 41154 ns/op 1432 B/op 2 allocs/op BenchmarkCodecXSuite/options-false.../Benchmark__Simple_____Encode-8 31305 39108 ns/op 1432 B/op 2 allocs/op BenchmarkCodecXSuite/options-false.../Benchmark__Cbor_______Encode-8 31215 38273 ns/op 1944 B/op 10 allocs/op BenchmarkCodecXSuite/options-false.../Benchmark__Json_______Encode-8 9530 127683 ns/op 1432 B/op 2 allocs/op BenchmarkCodecXSuite/options-false.../Benchmark__Std_Json___Encode-8 6114 202140 ns/op 75488 B/op 480 allocs/op BenchmarkCodecXSuite/options-false.../Benchmark__Gob________Encode-8 8848 136535 ns/op 167667 B/op 615 allocs/op BenchmarkCodecXSuite/options-false.../Benchmark__JsonIter___Encode-8 7996 173695 ns/op 55420 B/op 122 allocs/op BenchmarkCodecXSuite/options-false.../Benchmark__Bson_______Encode-8 4744 270318 ns/op 86778 B/op 1125 allocs/op BenchmarkCodecXSuite/options-false.../Benchmark__Mgobson____Encode-8 2932 460819 ns/op 293688 B/op 1816 allocs/op BenchmarkCodecXSuite/options-false.../Benchmark__VMsgpack___Encode-8 4059 267342 ns/op 140471 B/op 326 allocs/op BenchmarkCodecXSuite/options-false.../Benchmark__Fxcbor_____Encode-8 7647 133765 ns/op 47393 B/op 332 allocs/op BenchmarkCodecXSuite/options-false.../Benchmark__Sereal_____Encode-8 2601 422422 ns/op 263641 B/op 3353 allocs/op BenchmarkCodecXSuite/options-false.../Benchmark__Msgpack____Decode-8 10000 101182 ns/op 65574 B/op 914 allocs/op BenchmarkCodecXSuite/options-false.../Benchmark__Binc_______Decode-8 10000 104989 ns/op 65588 B/op 914 allocs/op BenchmarkCodecXSuite/options-false.../Benchmark__Simple_____Decode-8 10000 126144 ns/op 65605 B/op 914 allocs/op BenchmarkCodecXSuite/options-false.../Benchmark__Cbor_______Decode-8 7404 146597 ns/op 65589 B/op 914 allocs/op BenchmarkCodecXSuite/options-false.../Benchmark__Json_______Decode-8 2958 401627 ns/op 88402 B/op 1070 allocs/op BenchmarkCodecXSuite/options-false.../Benchmark__Std_Json___Decode-8 1224 954786 ns/op 137157 B/op 3114 allocs/op BenchmarkCodecXSuite/options-false.../Benchmark__Gob________Decode-8 4429 279146 ns/op 162652 B/op 2425 allocs/op BenchmarkCodecXSuite/options-false.../Benchmark__JsonIter___Decode-8 2266 536779 ns/op 131752 B/op 2658 allocs/op BenchmarkCodecXSuite/options-false.../Benchmark__Bson_______Decode-8 2448 475623 ns/op 193654 B/op 4560 allocs/op BenchmarkCodecXSuite/options-false.../Benchmark__Mgobson____Decode-8 2547 478656 ns/op 168877 B/op 6792 allocs/op BenchmarkCodecXSuite/options-false.../Benchmark__VMsgpack___Decode-8 3838 353797 ns/op 100369 B/op 2038 allocs/op BenchmarkCodecXSuite/options-false.../Benchmark__Fxcbor_____Decode-8 4408 239448 ns/op 72489 B/op 1395 allocs/op BenchmarkCodecXSuite/use-bufio-!bytes/Benchmark__Msgpack____Encode-8 23998 49642 ns/op 1480 B/op 3 allocs/op BenchmarkCodecXSuite/use-bufio-!bytes/Benchmark__Binc_______Encode-8 22365 52271 ns/op 1480 B/op 3 allocs/op BenchmarkCodecXSuite/use-bufio-!bytes/Benchmark__Simple_____Encode-8 22660 53420 ns/op 1480 B/op 3 allocs/op BenchmarkCodecXSuite/use-bufio-!bytes/Benchmark__Cbor_______Encode-8 23766 51167 ns/op 1992 B/op 11 allocs/op BenchmarkCodecXSuite/use-bufio-!bytes/Benchmark__Json_______Encode-8 8918 141143 ns/op 1480 B/op 3 allocs/op BenchmarkCodecXSuite/use-bufio-!bytes/Benchmark__Std_Json___Encode-8 6290 184020 ns/op 26430 B/op 480 allocs/op BenchmarkCodecXSuite/use-bufio-!bytes/Benchmark__Gob________Encode-8 8457 137976 ns/op 167668 B/op 615 allocs/op BenchmarkCodecXSuite/use-bufio-!bytes/Benchmark__JsonIter___Encode-8 6133 188037 ns/op 217603 B/op 139 allocs/op BenchmarkCodecXSuite/use-bufio-!bytes/Benchmark__Bson_______Encode-8 4731 255900 ns/op 86739 B/op 1125 allocs/op BenchmarkCodecXSuite/use-bufio-!bytes/Benchmark__Mgobson____Encode-8 3362 352169 ns/op 293681 B/op 1816 allocs/op BenchmarkCodecXSuite/use-bufio-!bytes/Benchmark__VMsgpack___Encode-8 9079 134982 ns/op 10800 B/op 319 allocs/op BenchmarkCodecXSuite/use-bufio-!bytes/Benchmark__Fxcbor_____Encode-8 12764 93876 ns/op 80200 B/op 340 allocs/op BenchmarkCodecXSuite/use-bufio-!bytes/Benchmark__Sereal_____Encode-8 3973 305172 ns/op 264823 B/op 3353 allocs/op BenchmarkCodecXSuite/use-bufio-!bytes/Benchmark__Msgpack____Decode-8 7526 160686 ns/op 82218 B/op 2111 allocs/op BenchmarkCodecXSuite/use-bufio-!bytes/Benchmark__Binc_______Decode-8 7455 153863 ns/op 80565 B/op 1647 allocs/op BenchmarkCodecXSuite/use-bufio-!bytes/Benchmark__Simple_____Decode-8 7275 177514 ns/op 81335 B/op 1735 allocs/op BenchmarkCodecXSuite/use-bufio-!bytes/Benchmark__Cbor_______Decode-8 5823 185603 ns/op 81364 B/op 1735 allocs/op BenchmarkCodecXSuite/use-bufio-!bytes/Benchmark__Json_______Decode-8 2283 525861 ns/op 88826 B/op 1168 allocs/op BenchmarkCodecXSuite/use-bufio-!bytes/Benchmark__Std_Json___Decode-8 1142 1072411 ns/op 266535 B/op 3126 allocs/op BenchmarkCodecXSuite/use-bufio-!bytes/Benchmark__Gob________Decode-8 4333 272245 ns/op 162644 B/op 2425 allocs/op BenchmarkCodecXSuite/use-bufio-!bytes/Benchmark__JsonIter___Decode-8 2306 540881 ns/op 136223 B/op 2811 allocs/op BenchmarkCodecXSuite/use-bufio-!bytes/Benchmark__Bson_______Decode-8 2570 463482 ns/op 193602 B/op 4560 allocs/op BenchmarkCodecXSuite/use-bufio-!bytes/Benchmark__Mgobson____Decode-8 2528 483677 ns/op 168885 B/op 6792 allocs/op BenchmarkCodecXSuite/use-bufio-!bytes/Benchmark__VMsgpack___Decode-8 3249 327183 ns/op 101420 B/op 2042 allocs/op BenchmarkCodecXSuite/use-bufio-!bytes/Benchmark__Fxcbor_____Decode-8 4124 295128 ns/op 201559 B/op 1403 allocs/op BenchmarkCodecXSuite/reset-enc-dec.../Benchmark__Msgpack____Encode-8 32580 37188 ns/op 1432 B/op 2 allocs/op BenchmarkCodecXSuite/reset-enc-dec.../Benchmark__Binc_______Encode-8 29103 40551 ns/op 1432 B/op 2 allocs/op BenchmarkCodecXSuite/reset-enc-dec.../Benchmark__Simple_____Encode-8 30482 39875 ns/op 1432 B/op 2 allocs/op BenchmarkCodecXSuite/reset-enc-dec.../Benchmark__Cbor_______Encode-8 30403 39068 ns/op 1944 B/op 10 allocs/op BenchmarkCodecXSuite/reset-enc-dec.../Benchmark__Json_______Encode-8 10000 126524 ns/op 1432 B/op 2 allocs/op BenchmarkCodecXSuite/reset-enc-dec.../Benchmark__Std_Json___Encode-8 6096 198377 ns/op 75513 B/op 480 allocs/op BenchmarkCodecXSuite/reset-enc-dec.../Benchmark__Gob________Encode-8 8324 145111 ns/op 167670 B/op 615 allocs/op BenchmarkCodecXSuite/reset-enc-dec.../Benchmark__JsonIter___Encode-8 7530 149018 ns/op 55422 B/op 122 allocs/op BenchmarkCodecXSuite/reset-enc-dec.../Benchmark__Bson_______Encode-8 4717 259381 ns/op 86829 B/op 1125 allocs/op BenchmarkCodecXSuite/reset-enc-dec.../Benchmark__Mgobson____Encode-8 3274 362606 ns/op 293700 B/op 1816 allocs/op BenchmarkCodecXSuite/reset-enc-dec.../Benchmark__VMsgpack___Encode-8 6955 167080 ns/op 140474 B/op 326 allocs/op BenchmarkCodecXSuite/reset-enc-dec.../Benchmark__Fxcbor_____Encode-8 13752 91848 ns/op 47549 B/op 332 allocs/op BenchmarkCodecXSuite/reset-enc-dec.../Benchmark__Sereal_____Encode-8 3717 312290 ns/op 264546 B/op 3353 allocs/op BenchmarkCodecXSuite/reset-enc-dec.../Benchmark__Msgpack____Decode-8 10000 104066 ns/op 65575 B/op 914 allocs/op BenchmarkCodecXSuite/reset-enc-dec.../Benchmark__Binc_______Decode-8 10000 100378 ns/op 65590 B/op 914 allocs/op BenchmarkCodecXSuite/reset-enc-dec.../Benchmark__Simple_____Decode-8 10000 101073 ns/op 65591 B/op 914 allocs/op BenchmarkCodecXSuite/reset-enc-dec.../Benchmark__Cbor_______Decode-8 10000 113818 ns/op 65622 B/op 914 allocs/op BenchmarkCodecXSuite/reset-enc-dec.../Benchmark__Json_______Decode-8 2875 411440 ns/op 88439 B/op 1070 allocs/op BenchmarkCodecXSuite/reset-enc-dec.../Benchmark__Std_Json___Decode-8 1240 960236 ns/op 137153 B/op 3114 allocs/op BenchmarkCodecXSuite/reset-enc-dec.../Benchmark__Gob________Decode-8 4306 272699 ns/op 162681 B/op 2425 allocs/op BenchmarkCodecXSuite/reset-enc-dec.../Benchmark__JsonIter___Decode-8 2402 502481 ns/op 131769 B/op 2658 allocs/op BenchmarkCodecXSuite/reset-enc-dec.../Benchmark__Bson_______Decode-8 2617 476165 ns/op 193660 B/op 4560 allocs/op BenchmarkCodecXSuite/reset-enc-dec.../Benchmark__Mgobson____Decode-8 2236 499718 ns/op 168886 B/op 6792 allocs/op BenchmarkCodecXSuite/reset-enc-dec.../Benchmark__VMsgpack___Decode-8 3456 315938 ns/op 100387 B/op 2038 allocs/op BenchmarkCodecXSuite/reset-enc-dec.../Benchmark__Fxcbor_____Decode-8 5220 221078 ns/op 72517 B/op 1395 allocs/op **** SUITE (WITH CODECGEN) **** >>>> bench TAGS: 'alltests x generated' SUITE: BenchmarkCodecXGenSuite BenchmarkCodecXGenSuite/options-false.../Benchmark__Msgpack____Encode-8 33787 35155 ns/op 1432 B/op 2 allocs/op BenchmarkCodecXGenSuite/options-false.../Benchmark__Binc_______Encode-8 30926 39664 ns/op 1432 B/op 2 allocs/op BenchmarkCodecXGenSuite/options-false.../Benchmark__Simple_____Encode-8 33387 36137 ns/op 1432 B/op 2 allocs/op BenchmarkCodecXGenSuite/options-false.../Benchmark__Cbor_______Encode-8 32556 36069 ns/op 1432 B/op 2 allocs/op BenchmarkCodecXGenSuite/options-false.../Benchmark__Json_______Encode-8 10000 122467 ns/op 1432 B/op 2 allocs/op BenchmarkCodecXGenSuite/options-false.../Benchmark__Msgp_______Encode-8 39901 30244 ns/op 0 B/op 0 allocs/op --- FAIL: BenchmarkCodecXGenSuite/options-false.../Benchmark__Easyjson___Encode bench_test.go:157: (recovered) panic: runtime error: invalid memory address or nil pointer dereference --- FAIL: BenchmarkCodecXGenSuite/options-false.../Benchmark__Ffjson_____Encode bench_test.go:157: (recovered) panic: ffjson: generated code fails to compile; checked 2022-12-26 BenchmarkCodecXGenSuite/options-false.../Benchmark__Msgpack____Decode-8 13839 89673 ns/op 35912 B/op 308 allocs/op BenchmarkCodecXGenSuite/options-false.../Benchmark__Binc_______Decode-8 14828 86035 ns/op 35910 B/op 308 allocs/op BenchmarkCodecXGenSuite/options-false.../Benchmark__Simple_____Decode-8 14379 95569 ns/op 35909 B/op 308 allocs/op BenchmarkCodecXGenSuite/options-false.../Benchmark__Cbor_______Decode-8 12830 98724 ns/op 35908 B/op 308 allocs/op BenchmarkCodecXGenSuite/options-false.../Benchmark__Json_______Decode-8 3204 373741 ns/op 70136 B/op 500 allocs/op BenchmarkCodecXGenSuite/options-false.../Benchmark__Msgp_______Decode-8 20080 64681 ns/op 68806 B/op 969 allocs/op --- FAIL: BenchmarkCodecXGenSuite/options-false.../Benchmark__Easyjson___Decode bench_test.go:157: (recovered) panic: runtime error: invalid memory address or nil pointer dereference --- FAIL: BenchmarkCodecXGenSuite/options-false.../Benchmark__Ffjson_____Decode bench_test.go:157: (recovered) panic: ffjson: generated code fails to compile; checked 2022-12-26 --- FAIL: BenchmarkCodecXGenSuite/options-false... BenchmarkCodecXGenSuite/use-bufio-!bytes/Benchmark__Msgpack____Encode-8 25766 46142 ns/op 1480 B/op 3 allocs/op BenchmarkCodecXGenSuite/use-bufio-!bytes/Benchmark__Binc_______Encode-8 24139 49950 ns/op 1480 B/op 3 allocs/op BenchmarkCodecXGenSuite/use-bufio-!bytes/Benchmark__Simple_____Encode-8 23992 49387 ns/op 1480 B/op 3 allocs/op BenchmarkCodecXGenSuite/use-bufio-!bytes/Benchmark__Cbor_______Encode-8 25672 47866 ns/op 1480 B/op 3 allocs/op BenchmarkCodecXGenSuite/use-bufio-!bytes/Benchmark__Json_______Encode-8 9127 137419 ns/op 1480 B/op 3 allocs/op BenchmarkCodecXGenSuite/use-bufio-!bytes/Benchmark__Msgp_______Encode-8 48080 25269 ns/op 2144 B/op 3 allocs/op --- FAIL: BenchmarkCodecXGenSuite/use-bufio-!bytes/Benchmark__Easyjson___Encode bench_test.go:157: (recovered) panic: runtime error: invalid memory address or nil pointer dereference --- FAIL: BenchmarkCodecXGenSuite/use-bufio-!bytes/Benchmark__Ffjson_____Encode bench_test.go:157: (recovered) panic: ffjson: generated code fails to compile; checked 2022-12-26 BenchmarkCodecXGenSuite/use-bufio-!bytes/Benchmark__Msgpack____Decode-8 7882 174799 ns/op 82181 B/op 2111 allocs/op BenchmarkCodecXGenSuite/use-bufio-!bytes/Benchmark__Binc_______Decode-8 5932 190610 ns/op 80565 B/op 1647 allocs/op BenchmarkCodecXGenSuite/use-bufio-!bytes/Benchmark__Simple_____Decode-8 5925 204050 ns/op 81332 B/op 1735 allocs/op BenchmarkCodecXGenSuite/use-bufio-!bytes/Benchmark__Cbor_______Decode-8 5714 179404 ns/op 81333 B/op 1735 allocs/op BenchmarkCodecXGenSuite/use-bufio-!bytes/Benchmark__Json_______Decode-8 2170 514760 ns/op 88850 B/op 1168 allocs/op --- FAIL: BenchmarkCodecXGenSuite/use-bufio-!bytes/Benchmark__Msgp_______Decode bench_test.go:256: Error decoding into new TestStruc: msgp: unexpected EOF at AMSS/44444444444444444444444444444444 at AnonInTestStruc at TestStrucCommon at Its/0 --- FAIL: BenchmarkCodecXGenSuite/use-bufio-!bytes/Benchmark__Easyjson___Decode bench_test.go:157: (recovered) panic: runtime error: invalid memory address or nil pointer dereference --- FAIL: BenchmarkCodecXGenSuite/use-bufio-!bytes/Benchmark__Ffjson_____Decode bench_test.go:157: (recovered) panic: ffjson: generated code fails to compile; checked 2022-12-26 --- FAIL: BenchmarkCodecXGenSuite/use-bufio-!bytes BenchmarkCodecXGenSuite/reset-enc-dec.../Benchmark__Msgpack____Encode-8 35875 33784 ns/op 1432 B/op 2 allocs/op BenchmarkCodecXGenSuite/reset-enc-dec.../Benchmark__Binc_______Encode-8 32260 37453 ns/op 1432 B/op 2 allocs/op BenchmarkCodecXGenSuite/reset-enc-dec.../Benchmark__Simple_____Encode-8 32720 35256 ns/op 1432 B/op 2 allocs/op BenchmarkCodecXGenSuite/reset-enc-dec.../Benchmark__Cbor_______Encode-8 33968 36282 ns/op 1432 B/op 2 allocs/op BenchmarkCodecXGenSuite/reset-enc-dec.../Benchmark__Json_______Encode-8 10000 120041 ns/op 1432 B/op 2 allocs/op BenchmarkCodecXGenSuite/reset-enc-dec.../Benchmark__Msgp_______Encode-8 40132 31348 ns/op 0 B/op 0 allocs/op --- FAIL: BenchmarkCodecXGenSuite/reset-enc-dec.../Benchmark__Easyjson___Encode bench_test.go:157: (recovered) panic: runtime error: invalid memory address or nil pointer dereference --- FAIL: BenchmarkCodecXGenSuite/reset-enc-dec.../Benchmark__Ffjson_____Encode bench_test.go:157: (recovered) panic: ffjson: generated code fails to compile; checked 2022-12-26 BenchmarkCodecXGenSuite/reset-enc-dec.../Benchmark__Msgpack____Decode-8 13647 92636 ns/op 35907 B/op 308 allocs/op BenchmarkCodecXGenSuite/reset-enc-dec.../Benchmark__Binc_______Decode-8 15865 102600 ns/op 35909 B/op 308 allocs/op BenchmarkCodecXGenSuite/reset-enc-dec.../Benchmark__Simple_____Decode-8 15568 82765 ns/op 35909 B/op 308 allocs/op BenchmarkCodecXGenSuite/reset-enc-dec.../Benchmark__Cbor_______Decode-8 10000 105619 ns/op 35908 B/op 308 allocs/op BenchmarkCodecXGenSuite/reset-enc-dec.../Benchmark__Json_______Decode-8 3010 377078 ns/op 70143 B/op 500 allocs/op BenchmarkCodecXGenSuite/reset-enc-dec.../Benchmark__Msgp_______Decode-8 18451 60923 ns/op 68791 B/op 969 allocs/op --- FAIL: BenchmarkCodecXGenSuite/reset-enc-dec.../Benchmark__Easyjson___Decode bench_test.go:157: (recovered) panic: runtime error: invalid memory address or nil pointer dereference --- FAIL: BenchmarkCodecXGenSuite/reset-enc-dec.../Benchmark__Ffjson_____Decode bench_test.go:157: (recovered) panic: ffjson: generated code fails to compile; checked 2022-12-26 --- FAIL: BenchmarkCodecXGenSuite/reset-enc-dec... --- FAIL: BenchmarkCodecXGenSuite FAIL exit status 1 FAIL ugorji.net/codec/bench 61.801s >>>> bench TAGS: 'alltests x generated codec.safe' SUITE: BenchmarkCodecXGenSuite BenchmarkCodecXGenSuite/options-false.../Benchmark__Msgpack____Encode-8 32551 36405 ns/op 1432 B/op 2 allocs/op BenchmarkCodecXGenSuite/options-false.../Benchmark__Binc_______Encode-8 28915 40946 ns/op 1432 B/op 2 allocs/op BenchmarkCodecXGenSuite/options-false.../Benchmark__Simple_____Encode-8 31665 38605 ns/op 1432 B/op 2 allocs/op BenchmarkCodecXGenSuite/options-false.../Benchmark__Cbor_______Encode-8 31347 38534 ns/op 1944 B/op 10 allocs/op BenchmarkCodecXGenSuite/options-false.../Benchmark__Json_______Encode-8 10000 122334 ns/op 1432 B/op 2 allocs/op BenchmarkCodecXGenSuite/options-false.../Benchmark__Msgp_______Encode-8 40556 29784 ns/op 0 B/op 0 allocs/op --- FAIL: BenchmarkCodecXGenSuite/options-false.../Benchmark__Easyjson___Encode bench_test.go:157: (recovered) panic: runtime error: invalid memory address or nil pointer dereference --- FAIL: BenchmarkCodecXGenSuite/options-false.../Benchmark__Ffjson_____Encode bench_test.go:157: (recovered) panic: ffjson: generated code fails to compile; checked 2022-12-26 BenchmarkCodecXGenSuite/options-false.../Benchmark__Msgpack____Decode-8 10000 106636 ns/op 65574 B/op 914 allocs/op BenchmarkCodecXGenSuite/options-false.../Benchmark__Binc_______Decode-8 10000 135140 ns/op 65592 B/op 914 allocs/op BenchmarkCodecXGenSuite/options-false.../Benchmark__Simple_____Decode-8 8061 160768 ns/op 65573 B/op 914 allocs/op BenchmarkCodecXGenSuite/options-false.../Benchmark__Cbor_______Decode-8 8736 125433 ns/op 65591 B/op 914 allocs/op BenchmarkCodecXGenSuite/options-false.../Benchmark__Json_______Decode-8 2922 402979 ns/op 88389 B/op 1070 allocs/op BenchmarkCodecXGenSuite/options-false.../Benchmark__Msgp_______Decode-8 16476 110613 ns/op 68790 B/op 969 allocs/op --- FAIL: BenchmarkCodecXGenSuite/options-false.../Benchmark__Easyjson___Decode bench_test.go:157: (recovered) panic: runtime error: invalid memory address or nil pointer dereference --- FAIL: BenchmarkCodecXGenSuite/options-false.../Benchmark__Ffjson_____Decode bench_test.go:157: (recovered) panic: ffjson: generated code fails to compile; checked 2022-12-26 --- FAIL: BenchmarkCodecXGenSuite/options-false... BenchmarkCodecXGenSuite/use-bufio-!bytes/Benchmark__Msgpack____Encode-8 23539 48481 ns/op 1480 B/op 3 allocs/op BenchmarkCodecXGenSuite/use-bufio-!bytes/Benchmark__Binc_______Encode-8 23234 51968 ns/op 1480 B/op 3 allocs/op BenchmarkCodecXGenSuite/use-bufio-!bytes/Benchmark__Simple_____Encode-8 22603 53069 ns/op 1480 B/op 3 allocs/op BenchmarkCodecXGenSuite/use-bufio-!bytes/Benchmark__Cbor_______Encode-8 23943 51051 ns/op 1992 B/op 11 allocs/op BenchmarkCodecXGenSuite/use-bufio-!bytes/Benchmark__Json_______Encode-8 9042 139039 ns/op 1480 B/op 3 allocs/op BenchmarkCodecXGenSuite/use-bufio-!bytes/Benchmark__Msgp_______Encode-8 46621 24882 ns/op 2144 B/op 3 allocs/op --- FAIL: BenchmarkCodecXGenSuite/use-bufio-!bytes/Benchmark__Easyjson___Encode bench_test.go:157: (recovered) panic: runtime error: invalid memory address or nil pointer dereference --- FAIL: BenchmarkCodecXGenSuite/use-bufio-!bytes/Benchmark__Ffjson_____Encode bench_test.go:157: (recovered) panic: ffjson: generated code fails to compile; checked 2022-12-26 BenchmarkCodecXGenSuite/use-bufio-!bytes/Benchmark__Msgpack____Decode-8 7808 198101 ns/op 82211 B/op 2111 allocs/op BenchmarkCodecXGenSuite/use-bufio-!bytes/Benchmark__Binc_______Decode-8 6502 182862 ns/op 80600 B/op 1647 allocs/op BenchmarkCodecXGenSuite/use-bufio-!bytes/Benchmark__Simple_____Decode-8 4888 215871 ns/op 81351 B/op 1735 allocs/op BenchmarkCodecXGenSuite/use-bufio-!bytes/Benchmark__Cbor_______Decode-8 6163 172675 ns/op 81349 B/op 1735 allocs/op BenchmarkCodecXGenSuite/use-bufio-!bytes/Benchmark__Json_______Decode-8 2224 514729 ns/op 88839 B/op 1168 allocs/op --- FAIL: BenchmarkCodecXGenSuite/use-bufio-!bytes/Benchmark__Msgp_______Decode bench_test.go:256: Error decoding into new TestStruc: msgp: unexpected EOF at AMSU64 at AnonInTestStruc at TestStrucCommon at Its/0 --- FAIL: BenchmarkCodecXGenSuite/use-bufio-!bytes/Benchmark__Easyjson___Decode bench_test.go:157: (recovered) panic: runtime error: invalid memory address or nil pointer dereference --- FAIL: BenchmarkCodecXGenSuite/use-bufio-!bytes/Benchmark__Ffjson_____Decode bench_test.go:157: (recovered) panic: ffjson: generated code fails to compile; checked 2022-12-26 --- FAIL: BenchmarkCodecXGenSuite/use-bufio-!bytes BenchmarkCodecXGenSuite/reset-enc-dec.../Benchmark__Msgpack____Encode-8 33350 35982 ns/op 1432 B/op 2 allocs/op BenchmarkCodecXGenSuite/reset-enc-dec.../Benchmark__Binc_______Encode-8 29067 40218 ns/op 1432 B/op 2 allocs/op BenchmarkCodecXGenSuite/reset-enc-dec.../Benchmark__Simple_____Encode-8 31323 38055 ns/op 1432 B/op 2 allocs/op BenchmarkCodecXGenSuite/reset-enc-dec.../Benchmark__Cbor_______Encode-8 31336 38444 ns/op 1944 B/op 10 allocs/op BenchmarkCodecXGenSuite/reset-enc-dec.../Benchmark__Json_______Encode-8 10000 122869 ns/op 1432 B/op 2 allocs/op BenchmarkCodecXGenSuite/reset-enc-dec.../Benchmark__Msgp_______Encode-8 40695 30494 ns/op 0 B/op 0 allocs/op --- FAIL: BenchmarkCodecXGenSuite/reset-enc-dec.../Benchmark__Easyjson___Encode bench_test.go:157: (recovered) panic: runtime error: invalid memory address or nil pointer dereference --- FAIL: BenchmarkCodecXGenSuite/reset-enc-dec.../Benchmark__Ffjson_____Encode bench_test.go:157: (recovered) panic: ffjson: generated code fails to compile; checked 2022-12-26 BenchmarkCodecXGenSuite/reset-enc-dec.../Benchmark__Msgpack____Decode-8 12193 105568 ns/op 65556 B/op 914 allocs/op BenchmarkCodecXGenSuite/reset-enc-dec.../Benchmark__Binc_______Decode-8 9168 123893 ns/op 65573 B/op 914 allocs/op BenchmarkCodecXGenSuite/reset-enc-dec.../Benchmark__Simple_____Decode-8 10000 122703 ns/op 65559 B/op 914 allocs/op BenchmarkCodecXGenSuite/reset-enc-dec.../Benchmark__Cbor_______Decode-8 8788 119293 ns/op 65555 B/op 914 allocs/op BenchmarkCodecXGenSuite/reset-enc-dec.../Benchmark__Json_______Decode-8 2863 411083 ns/op 88405 B/op 1070 allocs/op BenchmarkCodecXGenSuite/reset-enc-dec.../Benchmark__Msgp_______Decode-8 19698 66355 ns/op 68806 B/op 969 allocs/op --- FAIL: BenchmarkCodecXGenSuite/reset-enc-dec.../Benchmark__Easyjson___Decode bench_test.go:157: (recovered) panic: runtime error: invalid memory address or nil pointer dereference --- FAIL: BenchmarkCodecXGenSuite/reset-enc-dec.../Benchmark__Ffjson_____Decode bench_test.go:157: (recovered) panic: ffjson: generated code fails to compile; checked 2022-12-26 --- FAIL: BenchmarkCodecXGenSuite/reset-enc-dec... --- FAIL: BenchmarkCodecXGenSuite FAIL exit status 1 FAIL ugorji.net/codec/bench 54.412s go-1.2.8/codec/bench/bench.sh000077500000000000000000000260251435255326100157140ustar00rootroot00000000000000#!/bin/bash # download the code and all its dependencies _go_get() { # Note: keep "github.com/ugorji/go/codec" in quotes, as script pushing to github will replace it appropriately ${go[@]} get -u \ "github.com/ugorji/go/codec" "github.com/ugorji/go/codec"/codecgen \ github.com/tinylib/msgp/msgp github.com/tinylib/msgp \ github.com/pquerna/ffjson/ffjson github.com/pquerna/ffjson \ github.com/Sereal/Sereal/Go/sereal \ bitbucket.org/bodhisnarkva/cbor/go \ github.com/davecgh/go-xdr/xdr2 \ gopkg.in/mgo.v2/bson \ gopkg.in/vmihailenco/msgpack.v2 \ github.com/json-iterator/go \ go.mongodb.org/mongo-driver/bson \ github.com/mailru/easyjson/... } # add generated tag to the top of each file _prependbt() { local tag="${3:-generated}" cat > ${2} <> ${2} rm -f ${1} } _sed_in_file() { case "$(uname -s)" in Darwin*) sed -i '' "$@";; *) sed -i "$@";; esac } # To run the full suite of benchmarks, including executing against the external frameworks # listed above, you MUST first run code generation for the frameworks that support it. # # If you want to run the benchmarks against code generated values. # Then first generate the code generated values from values_test.go named typed. # we cannot normally read a _test.go file, so temporarily copy it into a readable file. _gen() { local zsfx="_generated_test.go" # local z=`pwd` # z=${z%%/src/*} # Note: ensure you run the codecgen for this codebase # NOTE: MARKER: ffjson has been generating bad uncompilable code, so ignore it for now cp values_test.go v.go && echo "codecgen ..." && codecgen -nx -ta=false -rt codecgen -t 'codecgen generated' -o values_codecgen${zsfx} -d 19780 v.go && echo "msgp ... " && msgp -unexported -tests=false -o=m9.go -file=v.go && _prependbt m9.go values_msgp${zsfx} && echo "easyjson ... " && easyjson -all -no_std_marshalers -omit_empty -output_filename e9.go v.go && _prependbt e9.go values_easyjson${zsfx} && echo "ffjson ... " && ffjson -force-regenerate -reset-fields -w f9.go v.go && _prependbt f9.go values_ffjson${zsfx} ignore && _sed_in_file -e 's+ MarshalJSON(+ _MarshalJSON(+g' values_ffjson${zsfx} && _sed_in_file -e 's+ UnmarshalJSON(+ _UnmarshalJSON(+g' values_ffjson${zsfx} && rm -f easyjson-bootstrap*.go ffjson-inception* && rm -f v.go && echo "... DONE" } # run the full suite of tests # # Basically, its a sequence of # ${go[@]} test -tags "alltests x codec.safe codecgen generated" -bench "CodecSuite or AllSuite or XSuite" -benchmem # _suite_tests() { if [[ "${do_x}" = "1" ]]; then printf "\n==== X Baseline ====\n" ${go[@]} test "${zargs[@]}" -tags x -v "$@" else printf "\n==== Baseline ====\n" ${go[@]} test "${zargs[@]}" -v "$@" fi if [[ "${do_x}" = "1" ]]; then printf "\n==== X Generated ====\n" ${go[@]} test "${zargs[@]}" -tags "x generated" -v "$@" else printf "\n==== Generated ====\n" ${go[@]} test "${zargs[@]}" -tags "generated" -v "$@" fi } _suite_tests_strip_file_line() { # sed -e 's/^\([^a-zA-Z0-9]\+\)[a-zA-Z0-9_]\+\.go:[0-9]\+:/\1/' sed -e 's/[a-zA-Z0-9_]*.go:[0-9]*://g' } _suite_any() { local x="$1" local g="$2" local b="$3" shift 3 local a=( "" "codec.safe" "codec.notfastpath" "codec.notfastpath codec.safe" "codecgen" "codecgen codec.safe") if [[ "$g" = "g" ]]; then a=( "generated" "generated codec.safe"); fi for i in "${a[@]}"; do echo ">>>> bench TAGS: 'alltests $x $i' SUITE: $b" ${go[@]} test "${zargs[@]}" -tags "alltests $x $i" -bench "$b" -benchmem "$@" done } # _suite() { # local t="alltests x" # local a=( "" "codec.safe" "codec.notfastpath" "codec.notfastpath codec.safe" "codecgen" "codecgen codec.safe") # for i in "${a[@]}" # do # echo ">>>> bench TAGS: '$t $i' SUITE: BenchmarkCodecXSuite" # ${go[@]} test "${zargs[@]}" -tags "$t $i" -bench BenchmarkCodecXSuite -benchmem "$@" # done # } # _suite_gen() { # local t="alltests x" # local b=( "generated" "generated codec.safe") # for i in "${b[@]}" # do # echo ">>>> bench TAGS: '$t $i' SUITE: BenchmarkCodecXGenSuite" # ${go[@]} test "${zargs[@]}" -tags "$t $i" -bench BenchmarkCodecXGenSuite -benchmem "$@" # done # } # _suite_json() { # local t="alltests x" # local a=( "" "codec.safe" "codec.notfastpath" "codec.notfastpath codec.safe" "codecgen" "codecgen codec.safe") # for i in "${a[@]}" # do # echo ">>>> bench TAGS: '$t $i' SUITE: BenchmarkCodecQuickAllJsonSuite" # ${go[@]} test "${zargs[@]}" -tags "$t $i" -bench BenchmarkCodecQuickAllJsonSuite -benchmem "$@" # done # } # _suite_very_quick_json() { # # Quickly get numbers for json, stdjson, jsoniter and json (codecgen)" # echo ">>>> very quick json bench" # ${go[@]} test "${zargs[@]}" -tags "alltests x" -bench "__(Json|Std_Json|JsonIter)__" -benchmem "$@" # echo # ${go[@]} test "${zargs[@]}" -tags "alltests codecgen" -bench "__Json____" -benchmem "$@" # } # _suite_very_quick_json_via_suite() { # # Quickly get numbers for json, stdjson, jsoniter and json (codecgen)" # echo ">>>> very quick json bench" # local prefix="BenchmarkCodecVeryQuickAllJsonSuite/json-all-bd1......../" # ${go[@]} test "${zargs[@]}" -tags "alltests x" -bench BenchmarkCodecVeryQuickAllJsonSuite -benchmem "$@" | # sed -e "s+^$prefix++" # echo "---- CODECGEN RESULTS ----" # ${go[@]} test "${zargs[@]}" -tags "x generated" -bench "__(Json|Easyjson)__" -benchmem "$@" # } _suite_very_quick_json_non_suite() { # Quickly get numbers for json, stdjson, jsoniter and json (codecgen)" local t="${1:-x}" shift echo ">>>> very quick json bench" # local tags=( "x" "x generated" ) local tags=("${t}" "${t} generated" "${t} codec.safe" "${t} generated codec.safe" "${t} codec.notfastpath") local js=( En De ) for t in "${tags[@]}"; do echo "---- tags: ${t} ----" local b="Json" if [[ "${t}" =~ x && ! "${t}" =~ safe && ! "${t}" =~ notfastpath ]]; then b="Json|Std_Json|JsonIter" if [[ "${t}" =~ generated ]]; then b="Json|Easyjson"; fi fi for j in "${js[@]}"; do ${go[@]} test "${zargs[@]}" -tags "${t}" -bench "__(${b})__.*${j}" -benchmem "$@" [[ "${b}" != Json ]] && echo # echo if more than 1 line is printed done done } _suite_very_quick_benchmark() { local a="${1:-Json}" # Json Cbor Msgpack Simple # case "$1" in # Json|Cbor|Msgpack|Simple|Binc) a="${1}"; shift ;; # esac local b="${2}" local c="${3}" local t="${4:-4s}" # 4s 1x shift 4 ${go[@]} test "${zargs[@]}" -tags "alltests ${c}" -bench "__${a}__.*${b}" -benchmem -benchtime "${t}" "$@" } _suite_trim_output() { grep -v -E "^(goos:|goarch:|pkg:|cpu:|PASS|ok|=== RUN|--- PASS)" } _bench_dot_out_dot_txt() { printf "**** STATS ****\n\n" ./bench.sh -tx # (stats) printf "**** SUITE ****\n\n" ./bench.sh -sx # (not codecgen) printf "**** SUITE (WITH CODECGEN) ****\n\n" ./bench.sh -sgx # (codecgen) } _suite_debugging() { _suite_very_quick_benchmark "$@" # local cg="n" # n = no codecgen, c = codecgen; options are c, n, cn # local js=( De ) # or: ( _ ) ( En ) ( De ) ( En De ) # for j in ${js[@]}; do # if [[ ${cg} =~ "c" ]]; then # echo "---- codecgen ----" # ${go[@]} test "${zargs[@]}" -tags "generated" -bench "__(Json)__.*${j}" -benchtime 2s -benchmem "$@" # fi # if [[ ${cg} =~ "n" ]]; then # echo "---- no codecgen ----" # ${go[@]} test "${zargs[@]}" -tags "" -bench "__(Json)__.*${j}" -benchtime 2s -benchmem "$@" # fi # echo # done } _usage() { printf "usage: bench.sh -[dcbsgjqpz] for \n" printf "\t-d download\n" printf "\t-c code-generate\n" printf "\t-tx tests (show stats for each format and whether encoded == decoded); if x, do external also\n" printf "\t-sgx run test suite for codec; if g, use generated files; if x, do external also\n" printf "\t-jq run test suite for [json, json-quick]\n" printf "\t-p run test suite with profiles: defaults to json: [format/prefix] [suffix] [tags] [benchtime]\n" printf "\t-z run tests for bench.out.txt\n" printf "\t-f [pprof file] run pprof\n" printf "\t-y run debugging suite (during development only): [format/prefix] [suffix] [tags] [benchtime]\n" } _main() { if [[ "$1" == "" || "$1" == "-h" || "$1" == "-?" ]]; then _usage return 1 fi # export GODEBUG=asyncpreemptoff=1 # TODO remove local go=( "${MYGOCMD:-go}" ) local zargs=("-count" "1" "-tr") local args=() local do_x="0" local do_g="0" while getopts "dcbsjqptxklgzfy" flag do case "$flag" in d|c|b|s|j|q|p|t|x|k|l|g|z|f|y) args+=( "$flag" ) ;; *) _usage; return 1 ;; esac done shift "$((OPTIND-1))" [[ " ${args[*]} " == *"x"* ]] && do_x="1" [[ " ${args[*]} " == *"g"* ]] && do_g="1" [[ " ${args[*]} " == *"k"* ]] && zargs+=("-gcflags" "all=-B") [[ " ${args[*]} " == *"l"* ]] && zargs+=("-gcflags" "all=-l=4") [[ " ${args[*]} " == *"d"* ]] && _go_get "$@" [[ " ${args[*]} " == *"c"* ]] && _gen "$@" [[ " ${args[*]} " == *"s"* && "${do_x}" == 0 && "${do_g}" == 0 ]] && _suite_any - - BenchmarkCodecSuite "$@" | _suite_trim_output [[ " ${args[*]} " == *"s"* && "${do_x}" == 0 && "${do_g}" == 1 ]] && _suite_any - g BenchmarkCodecSuite "$@" | _suite_trim_output [[ " ${args[*]} " == *"s"* && "${do_x}" == 1 && "${do_g}" == 0 ]] && _suite_any x - BenchmarkCodecXSuite "$@" | _suite_trim_output [[ " ${args[*]} " == *"s"* && "${do_x}" == 1 && "${do_g}" == 1 ]] && _suite_any x g BenchmarkCodecXGenSuite "$@" | _suite_trim_output [[ " ${args[*]} " == *"j"* ]] && _suite_any x - BenchmarkCodecQuickAllJsonSuite "$@" | _suite_trim_output # These are some very specific suites # [[ " ${args[*]} " == *"q"* ]] && _suite_very_quick_json_via_suite "$@" | _suite_trim_output [[ " ${args[*]} " == *"q"* ]] && _suite_very_quick_json_non_suite "$@" | _suite_trim_output # These are just helpers (not really running benchmark suites) [[ " ${args[*]} " == *"t"* ]] && _suite_tests "$@" | _suite_trim_output | _suite_tests_strip_file_line [[ " ${args[*]} " == *"p"* ]] && zargs+=("-cpuprofile" "cpu.out" "-memprofile" "mem.out" "-memprofilerate" "1") && _suite_very_quick_benchmark "$@" | _suite_trim_output [[ " ${args[*]} " == *"f"* ]] && ${go[@]} tool pprof bench.test ${1:-mem.out} [[ " ${args[*]} " == *"z"* ]] && _bench_dot_out_dot_txt [[ " ${args[*]} " == *"y"* ]] && _suite_debugging "$@" | _suite_trim_output true # shift $((OPTIND-1)) } if [ "." = `dirname $0` ] then _main "$@" else echo "bench.sh must be run from the directory it resides in" _usage fi go-1.2.8/codec/bench/bench_test.go000066400000000000000000000170471435255326100167470ustar00rootroot00000000000000// 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 // bench_test is the "helper" file for all benchmarking tests. // // There are also benchmarks which depend on just codec and the stdlib, // and benchmarks which depend on external libraries. // It is an explicit goal that you can run benchmarks without external // dependencies (which is why the 'x' build tag was explicitly introduced). // // There are 2 ways of running tests: // - generated // - not generated // // Consequently, we have 4 groups: // - codec_bench (gen, !gen) // - stdlib_bench (!gen only) // - x_bench (!gen only) // - x_bench_gen (gen only) // // We also have 4 matching suite files. // - z_all_bench (rename later to z_all_codec_bench???) // - z_all_stdlib_bench // - z_all_x_bench // - z_all_x_bench_gen // // Finally, we have a single test (TestBenchInit) that // will log information about whether each format can // encode or not, how long to encode (unscientifically), // and the encode size. // // This test MUST be run always, as it calls init() internally import ( "reflect" "runtime" "testing" "time" ) // Sample way to run: // go test -bi -bv -bd=1 -benchmem -bench=. const ( benchUnscientificRes = true benchVerify = true benchRecover = true benchShowJsonOnError = true ) var ( benchTs *TestStruc approxSize int benchCheckers []benchChecker ) type benchEncFn func(interface{}, []byte) ([]byte, error) type benchDecFn func([]byte, interface{}) error type benchIntfFn func() interface{} type benchChecker struct { name string encodefn benchEncFn decodefn benchDecFn } func init() { testPreInitFns = append(testPreInitFns, benchPreInit) // testPostInitFns = append(testPostInitFns, codecbenchPostInit) } func benchPreInit() { benchTs = newTestStruc(testDepth, testNumRepeatString, true, !testSkipIntf, testMapStringKeyOnly) approxSize = approxDataSize(reflect.ValueOf(benchTs)) * 2 // multiply by 1.5 or 2 to appease msgp, and prevent alloc // bytesLen := 1024 * 4 * (testDepth + 1) * (testDepth + 1) // if bytesLen < approxSize { // bytesLen = approxSize // } if !testBenchmarkNoConfig { // benchmark comparisons use zerocopy (easyjson, json-iterator, etc). // use zerocopy for the benchmarks, for best performance, and better comparison to others. testJsonH.ZeroCopy = true testCborH.ZeroCopy = true testMsgpackH.ZeroCopy = true testSimpleH.ZeroCopy = true testBincH.ZeroCopy = true // std-lib encoging/json does the following, which we will do for codec in these benchmarks. // - sets into a map without getting what's there first. // - sets into an interface value regardless of what was in there // - sets slice to zero len first, then appends (equivalent to ignoring slice contents) testJsonH.MapValueReset = true testJsonH.InterfaceReset = true testJsonH.SliceElementReset = true } } func benchReinit() { benchCheckers = nil } func benchmarkDivider() { // logTv(nil, "-------------------------------\n") println() } // func Test0(t *testing.T) { // testOnce.Do(testInitAll) // } func TestBenchInit(t *testing.T) { testOnce.Do(testInitAll) if !testing.Verbose() { return } // t.Logf("..............................................") t.Logf("BENCHMARK INIT: %v", time.Now()) // t.Logf("To run full benchmark comparing encodings, use: \"go test -bench=.\"") t.Logf("Benchmark: ") t.Logf("\tStruct recursive Depth: %d", testDepth) if approxSize > 0 { t.Logf("\tApproxDeepSize Of benchmark Struct: %d bytes", approxSize) } if benchUnscientificRes { t.Logf("Benchmark One-Pass Run (with Unscientific Encode/Decode times): ") } else { t.Logf("Benchmark One-Pass Run:") } for _, bc := range benchCheckers { doBenchCheck(t, bc.name, bc.encodefn, bc.decodefn) } if testVerbose { t.Logf("..............................................") t.Logf("<<<<====>>>> depth: %v, ts: %#v\n", testDepth, benchTs) } runtime.GC() time.Sleep(100 * time.Millisecond) } var vBenchTs = TestStruc{} func fnBenchNewTs() interface{} { vBenchTs = TestStruc{} return &vBenchTs // return new(TestStruc) } // const benchCheckDoDeepEqual = false func benchRecoverPanic(t *testing.B) { if benchRecover { if r := recover(); r != nil { t.Logf("(recovered) panic: %v\n", r) t.FailNow() } } } func benchRecoverPanicT(t *testing.T) { if benchRecover { if r := recover(); r != nil { t.Logf("(recovered) panic: %v\n", r) t.FailNow() } } } func doBenchCheck(t *testing.T, name string, encfn benchEncFn, decfn benchDecFn) { // if benchUnscientificRes { // t.Logf("-------------- %s ----------------", name) // } defer benchRecoverPanicT(t) runtime.GC() tnow := time.Now() buf, err := encfn(benchTs, nil) if err != nil { t.Logf("\t%10s: **** Error encoding benchTs: %v", name, err) return } encDur := time.Since(tnow) encLen := len(buf) runtime.GC() if !benchUnscientificRes { t.Logf("\t%10s: len: %d bytes\n", name, encLen) return } tnow = time.Now() var ts2 TestStruc if err = decfn(buf, &ts2); err != nil { t.Logf("\t%10s: **** Error decoding into new TestStruc: %v", name, err) return } decDur := time.Since(tnow) // if benchCheckDoDeepEqual { if benchVerify { err = deepEqual(benchTs, &ts2) if err == nil { t.Logf("\t%10s: len: %d bytes,\t encode: %v,\t decode: %v,\tencoded == decoded", name, encLen, encDur, decDur) } else { t.Logf("\t%10s: len: %d bytes,\t encode: %v,\t decode: %v,\tencoded != decoded: %v", name, encLen, encDur, decDur, err) } } else { t.Logf("\t%10s: len: %d bytes,\t encode: %v,\t decode: %v", name, encLen, encDur, decDur) } return } func fnBenchmarkEncode(b *testing.B, encName string, ts interface{}, encfn benchEncFn) { defer benchRecoverPanic(b) testOnce.Do(testInitAll) // ignore method params: ts, and work on benchTs directly ts = benchTs var err error bs := make([]byte, 0, approxSize) // do initial warm up by running encode one time if bs, err = encfn(ts, bs); err != nil { b.Logf("Error encoding benchTs: %s: %v", encName, err) b.FailNow() } runtime.GC() b.ResetTimer() for i := 0; i < b.N; i++ { if _, err = encfn(ts, bs); err != nil { b.Logf("Error encoding benchTs: %s: %v", encName, err) b.FailNow() } } } func fnBenchmarkDecode(b *testing.B, encName string, ts interface{}, encfn benchEncFn, decfn benchDecFn, newfn benchIntfFn, ) { defer benchRecoverPanic(b) testOnce.Do(testInitAll) // ignore method params: ts and newfn, and work on benchTs and TestStruc directly ts = benchTs buf := make([]byte, 0, approxSize) buf, err := encfn(ts, buf) if err != nil { b.Logf("Error encoding benchTs: %s: %v", encName, err) b.FailNow() } // do initial warm up by running decode one time locTs := new(TestStruc) ts = locTs // ts = newfn() if err = decfn(buf, ts); err != nil { b.Logf("Error decoding into new TestStruc: %s: %v", encName, err) b.FailNow() } // if false && benchVerify { // do not do benchVerify during decode // // ts2 := newfn() // ts1 := ts.(*TestStruc) // ts2 := new(TestStruc) // if err = decfn(buf, ts2); err != nil { // failT(b, "BenchVerify: Error decoding benchTs: %s: %v", encName, err) // } // if err = deepEqual(ts1, ts2); err != nil { // failT(b, "BenchVerify: Error comparing benchTs: %s: %v", encName, err) // } // } runtime.GC() b.ResetTimer() for i := 0; i < b.N; i++ { *locTs = TestStruc{} // ts = newfn() if err = decfn(buf, ts); err != nil { b.Logf("Error decoding into new TestStruc: %s: %v", encName, err) b.FailNow() } } } go-1.2.8/codec/bench/codec_bench_test.go000066400000000000000000000071341435255326100201000ustar00rootroot00000000000000// 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 ( "testing" ) func init() { testPreInitFns = append(testPreInitFns, codecBenchPreInit) // testPostInitFns = append(testPostInitFns, codecbenchPostInit) } func codecBenchPreInit() { benchCheckers = append(benchCheckers, benchChecker{"msgpack", fnMsgpackEncodeFn, fnMsgpackDecodeFn}, benchChecker{"binc", fnBincEncodeFn, fnBincDecodeFn}, benchChecker{"simple", fnSimpleEncodeFn, fnSimpleDecodeFn}, benchChecker{"cbor", fnCborEncodeFn, fnCborDecodeFn}, benchChecker{"json", fnJsonEncodeFn, fnJsonDecodeFn}, ) } // ------------ tests below func fnMsgpackEncodeFn(ts interface{}, bsIn []byte) (bs []byte, err error) { return testSharedCodecEncode(ts, bsIn, fnBenchmarkByteBuf, testMsgpackH, &testMsgpackH.BasicHandle, true) } func fnMsgpackDecodeFn(buf []byte, ts interface{}) error { return testSharedCodecDecode(buf, ts, testMsgpackH, &testMsgpackH.BasicHandle, true) } func fnBincEncodeFn(ts interface{}, bsIn []byte) (bs []byte, err error) { return testSharedCodecEncode(ts, bsIn, fnBenchmarkByteBuf, testBincH, &testBincH.BasicHandle, true) } func fnBincDecodeFn(buf []byte, ts interface{}) error { return testSharedCodecDecode(buf, ts, testBincH, &testBincH.BasicHandle, true) } func fnSimpleEncodeFn(ts interface{}, bsIn []byte) (bs []byte, err error) { return testSharedCodecEncode(ts, bsIn, fnBenchmarkByteBuf, testSimpleH, &testSimpleH.BasicHandle, true) } func fnSimpleDecodeFn(buf []byte, ts interface{}) error { return testSharedCodecDecode(buf, ts, testSimpleH, &testSimpleH.BasicHandle, true) } func fnCborEncodeFn(ts interface{}, bsIn []byte) (bs []byte, err error) { return testSharedCodecEncode(ts, bsIn, fnBenchmarkByteBuf, testCborH, &testCborH.BasicHandle, true) } func fnCborDecodeFn(buf []byte, ts interface{}) error { return testSharedCodecDecode(buf, ts, testCborH, &testCborH.BasicHandle, true) } func fnJsonEncodeFn(ts interface{}, bsIn []byte) (bs []byte, err error) { return testSharedCodecEncode(ts, bsIn, fnBenchmarkByteBuf, testJsonH, &testJsonH.BasicHandle, true) } func fnJsonDecodeFn(buf []byte, ts interface{}) error { return testSharedCodecDecode(buf, ts, testJsonH, &testJsonH.BasicHandle, true) } // ----------- ENCODE ------------------ func Benchmark__Msgpack____Encode(b *testing.B) { fnBenchmarkEncode(b, "msgpack", benchTs, fnMsgpackEncodeFn) } func Benchmark__Binc_______Encode(b *testing.B) { fnBenchmarkEncode(b, "binc", benchTs, fnBincEncodeFn) } func Benchmark__Simple_____Encode(b *testing.B) { fnBenchmarkEncode(b, "simple", benchTs, fnSimpleEncodeFn) } func Benchmark__Cbor_______Encode(b *testing.B) { fnBenchmarkEncode(b, "cbor", benchTs, fnCborEncodeFn) } func Benchmark__Json_______Encode(b *testing.B) { fnBenchmarkEncode(b, "json", benchTs, fnJsonEncodeFn) } // ----------- DECODE ------------------ func Benchmark__Msgpack____Decode(b *testing.B) { fnBenchmarkDecode(b, "msgpack", benchTs, fnMsgpackEncodeFn, fnMsgpackDecodeFn, fnBenchNewTs) } func Benchmark__Binc_______Decode(b *testing.B) { fnBenchmarkDecode(b, "binc", benchTs, fnBincEncodeFn, fnBincDecodeFn, fnBenchNewTs) } func Benchmark__Simple_____Decode(b *testing.B) { fnBenchmarkDecode(b, "simple", benchTs, fnSimpleEncodeFn, fnSimpleDecodeFn, fnBenchNewTs) } func Benchmark__Cbor_______Decode(b *testing.B) { fnBenchmarkDecode(b, "cbor", benchTs, fnCborEncodeFn, fnCborDecodeFn, fnBenchNewTs) } func Benchmark__Json_______Decode(b *testing.B) { fnBenchmarkDecode(b, "json", benchTs, fnJsonEncodeFn, fnJsonDecodeFn, fnBenchNewTs) } go-1.2.8/codec/bench/doc.go000066400000000000000000000006261435255326100153710ustar00rootroot00000000000000// 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. Here, we have the benchmark files comparing against other encoding libraries. See README.md for more details. */ package codec go-1.2.8/codec/bench/go.mod000066400000000000000000000001221435255326100153720ustar00rootroot00000000000000module github.com/ugorji/go/codec/bench require github.com/ugorji/go/codec v1.2.8 go-1.2.8/codec/bench/go.sum000077500000000000000000000262311435255326100154330ustar00rootroot00000000000000bitbucket.org/bodhisnarkva/cbor v0.0.0-20170201010848-113f42203c94 h1:mIPAugcfnbnaazg3ttUVbHbJaY+e3aUf4Wr7lONml5I= bitbucket.org/bodhisnarkva/cbor v0.0.0-20170201010848-113f42203c94/go.mod h1:pl6BcNYTFXkbj1OCW5EIJkgrzmmEFwU6oaelsR/9pMQ= github.com/DataDog/zstd v1.5.2 h1:vUG4lAyuPCXO0TLbXvPv7EB7cNK1QV/luu55UHLrrn8= github.com/DataDog/zstd v1.5.2/go.mod h1:g4AWEaM3yOg3HYfnJ3YIawPnVdXJh9QME85blwSAmyw= github.com/Sereal/Sereal v0.0.0-20221130110801-16a4f76670cd h1:rP6LH3aVJTIxgTA3q79sSfnt8DvOlt17IRAklRBN+xo= github.com/Sereal/Sereal v0.0.0-20221130110801-16a4f76670cd/go.mod h1:D0JMgToj/WdxCgd30Kc1UcA9E+WdZoJqeVOuYW7iTBM= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-xdr v0.0.0-20161123171359-e6a2ba005892 h1:qg9VbHo1TlL0KDM0vYvBG9EY0X0Yku5WYIPoFWt8f6o= github.com/davecgh/go-xdr v0.0.0-20161123171359-e6a2ba005892/go.mod h1:CTDl0pzVzE5DEzZhPfvhY/9sPFMQIxaJ9VAMs9AagrE= github.com/fxamacker/cbor/v2 v2.4.0 h1:ri0ArlOR+5XunOP8CRUowT0pSJOwhW098ZCUyskZD88= github.com/fxamacker/cbor/v2 v2.4.0/go.mod h1:TA1xS00nchWmaBnEIxPSE5oHLuJBAVvqrtAnWBwBCVo= github.com/globalsign/mgo v0.0.0-20181015135952-eeefdecb41b8 h1:DujepqpGd1hyOd7aW59XpK7Qymp8iy83xq74fLr21is= github.com/globalsign/mgo v0.0.0-20181015135952-eeefdecb41b8/go.mod h1:xkRDCp4j0OGD1HRkm4kmhM+pmpv3AKq5SU7GMg4oO/Q= github.com/golang/protobuf v1.3.1/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= github.com/golang/protobuf v1.3.4 h1:87PNWwrRvUSnqS4dlcBU/ftvOIBep4sYuBLlh6rX2wk= github.com/golang/protobuf v1.3.4/go.mod h1:vzj43D7+SQXF/4pzW/hwtAqwc6iTitCiVSaWz5lYuqw= github.com/golang/snappy v0.0.1 h1:Qgr9rKW7uDUkrbSmQeiDsGa8SjGyCOGtuasMWwvp2P4= github.com/golang/snappy v0.0.1/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q= github.com/google/go-cmp v0.5.2 h1:X2ev0eStA3AbceY54o37/0PQ/UWqKEiiO2dKL5OPaFM= github.com/google/go-cmp v0.5.2/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg= github.com/josharian/intern v1.0.0 h1:vlS4z54oSdjm0bgjRigI+G1HpF+tI+9rE5LLzOg8HmY= github.com/josharian/intern v1.0.0/go.mod h1:5DoeVV0s6jJacbCEi61lwdGj/aVlrQvzHFFd8Hwg//Y= github.com/json-iterator/go v1.1.12 h1:PV8peI4a0ysnczrg+LtxykD8LfKY9ML6u2jnxaEnrnM= github.com/json-iterator/go v1.1.12/go.mod h1:e30LSqwooZae/UwlEbR2852Gd8hjQvJoHmT4TnhNGBo= github.com/klauspost/compress v1.13.6/go.mod h1:/3/Vjq9QcHkK5uEr5lBEmyoZ1iFhe47etQ6QUkpK6sk= github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI= github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE= github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= github.com/mailru/easyjson v0.7.7 h1:UGYAvKxe3sBsEDzO8ZeWOSlIQfWFlxbzLZe7hwFURr0= github.com/mailru/easyjson v0.7.7/go.mod h1:xzfreul335JAWq5oZzymOObrkdz5UnU4kGfJJLY9Nlc= github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421 h1:ZqeYNhU3OHLH3mGKHDcjJRFFRrJa6eAM5H+CtDdOsPc= github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q= github.com/modern-go/reflect2 v1.0.2 h1:xBagoLtFs94CBntxluKeaWgTMpvLxC4ur3nMaC9Gz0M= github.com/modern-go/reflect2 v1.0.2/go.mod h1:yWuevngMOJpCy52FWWMvUC8ws7m/LJsjYzDa0/r8luk= github.com/montanaflynn/stats v0.0.0-20171201202039-1bf9dbcd8cbe/go.mod h1:wL8QJuTMNUDYhXwkmfOly8iTdp5TEcJFWZD2D7SIkUc= github.com/philhofer/fwd v1.1.2-0.20210722190033-5c56ac6d0bb9 h1:6ob53CVz+ja2i7easAStApZJlh7sxyq3Cm7g1Di6iqA= github.com/philhofer/fwd v1.1.2-0.20210722190033-5c56ac6d0bb9/go.mod h1:gk3iGcWd9+svBvR0sR+KPcfE+RNWozjowpeBVG3ZVNU= github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/pquerna/ffjson v0.0.0-20190930134022-aa0246cd15f7 h1:xoIK0ctDddBMnc74udxJYBqlo9Ylnsp1waqjLsnef20= github.com/pquerna/ffjson v0.0.0-20190930134022-aa0246cd15f7/go.mod h1:YARuvh7BUWHNhzDq2OM5tzR2RiCcN2D7sapiKyCel/M= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= github.com/stretchr/testify v1.6.1 h1:hDPOHmpOpP40lSULcqw7IrRb/u7w6RpDC9399XyoNd0= github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/tidwall/pretty v1.0.0 h1:HsD+QiTn7sK6flMKIvNmpqz1qrpP3Ps6jOKIKMooyg4= github.com/tidwall/pretty v1.0.0/go.mod h1:XNkn88O1ChpSDQmQeStsy+sBenx6DDtFZJxhVysOjyk= github.com/tinylib/msgp v1.1.7 h1:Kj2VeYxkc21FqEoaX1KTbFFJFvp9r4uym3yh5lJanEI= github.com/tinylib/msgp v1.1.7/go.mod h1:XDkD8qXRy3XrZ5PmIaj5nQ11ktAb/gCMoE8Ra9wQpEA= github.com/ugorji/go v1.2.7 h1:qYhyWUUd6WbiM+C6JZAUkIJt/1WrjzNHY9+KCIjVqTo= github.com/ugorji/go v1.2.7/go.mod h1:nF9osbDWLy6bDVv/Rtoh6QgnvNDpmCalQV5urGCCS6M= github.com/ugorji/go/codec v1.2.7 h1:YPXUKf7fYbp/y8xloBqZOw2qaVggbfwMlI8WM3wZUJ0= github.com/ugorji/go/codec v1.2.7/go.mod h1:WGN1fab3R1fzQlVQTkfxVtIBhWDRqOviHU95kRgeqEY= github.com/vmihailenco/msgpack/v4 v4.3.12 h1:07s4sz9IReOgdikxLTKNbBdqDMLsjPKXwvCazn8G65U= github.com/vmihailenco/msgpack/v4 v4.3.12/go.mod h1:gborTTJjAo/GWTqqRjrLCn9pgNN+NXzzngzBKDPIqw4= github.com/vmihailenco/tagparser v0.1.1 h1:quXMXlA39OCbd2wAdTsGDlK9RkOk6Wuw+x37wVyIuWY= github.com/vmihailenco/tagparser v0.1.1/go.mod h1:OeAg3pn3UbLjkWt+rN9oFYB6u/cQgqMEUPoW2WPyhdI= github.com/x448/float16 v0.8.4 h1:qLwI1I70+NjRFUR3zs1JPUCgaCXSh3SW62uAKT1mSBM= github.com/x448/float16 v0.8.4/go.mod h1:14CWIYCyZA/cWjXOioeEpHeN/83MdbZDRQHoFcYsOfg= github.com/xdg-go/pbkdf2 v1.0.0/go.mod h1:jrpuAogTd400dnrH08LKmI/xc1MbPOebTwRqcT5RDeI= github.com/xdg-go/scram v1.1.1/go.mod h1:RaEWvsqvNKKvBPvcKeFjrG2cJqOkHTiyTpzz23ni57g= github.com/xdg-go/stringprep v1.0.3/go.mod h1:W3f5j4i+9rC0kuIEJL0ky1VpHXQU3ocBgklLGvcBnW8= github.com/youmark/pkcs8 v0.0.0-20181117223130-1be2e3e5546d/go.mod h1:rHwXgn7JulP+udvsHwJoVG1YGAP6VLg4y9I5dyZdqmA= github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY= go.mongodb.org/mongo-driver v1.11.1 h1:QP0znIRTuL0jf1oBQoAoM0C6ZJfBK4kx0Uumtv1A7w8= go.mongodb.org/mongo-driver v1.11.1/go.mod h1:s7p5vEtfbeR1gYi6pnj3c3/urpbLv2T5Sfd6Rp2HBB8= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= golang.org/x/crypto v0.0.0-20220622213112-05595931fe9d/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4= golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4= golang.org/x/mod v0.7.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs= golang.org/x/net v0.0.0-20190603091049-60506f45cf65/go.mod h1:HSz+uSET+XFnRR8LxR5pz3Of3rY3CfYBVs4xY44aLks= golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= golang.org/x/net v0.0.0-20200301022130-244492dfa37a/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c= golang.org/x/net v0.3.0 h1:VWL6FNY2bEEmsGVKabSlHu5Irp34xmMRoqb/9lF9lxk= golang.org/x/net v0.3.0/go.mod h1:MBQ8lrhLObU/6UmLb4fmbmk5OcyYmqtbGd/9yIeKjEE= golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20210220032951-036812b2e83c/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.1.0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.3.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= golang.org/x/term v0.3.0/go.mod h1:q750SLmJuPmVoN1blW3UFBPREJfb1KmY3vwxfr+nFDA= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk= golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ= golang.org/x/text v0.5.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8= golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc= golang.org/x/tools v0.4.0/go.mod h1:UE5sM2OK9E/d67R0ANs2xJizIymRP5gJU295PvKXxjQ= golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20220907171357-04be3eba64a2 h1:H2TDz8ibqkAF6YGhCdN3jS9O0/s90v0rJh3X/OLHEUk= golang.org/x/xerrors v0.0.0-20220907171357-04be3eba64a2/go.mod h1:K8+ghG5WaK9qNqU5K3HdILfMLy1f3aNYFI/wnl100a8= google.golang.org/appengine v1.6.5 h1:tycE03LOZYQNhDpS27tcQdAzLCVMaj7QT2SXxebnpCM= google.golang.org/appengine v1.6.5/go.mod h1:8WjMMxjGQR8xUklV/ARdw2HLXBOI7O7uCIDZVag1xfc= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 h1:qIbj1fsPNlZgppZ+VLlY7N33q108Sa+fhmuc+sWQYwY= gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= go-1.2.8/codec/bench/shared_test.go000066400000000000000000000220421435255326100171250ustar00rootroot00000000000000// 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 // This file sets up the variables used, including testInitFns. // Each file should add initialization that should be performed // after flags are parsed. // // init is a multi-step process: // - setup vars (handled by init functions in each file) // - parse flags // - setup derived vars (handled by pre-init registered functions - registered in init function) // - post init (handled by post-init registered functions - registered in init function) // This way, no one has to manage carefully control the initialization // using file names, etc. // // Tests which require external dependencies need the -tag=x parameter. // They should be run as: // go test -tags=x -run=. // Benchmarks should also take this parameter, to include the sereal, xdr, etc. // To run against codecgen, etc, make sure you pass extra parameters. // Example usage: // go test "-tags=x codecgen" -bench=. // // To fully test everything: // go test -tags=x -benchtime=100ms -tv -bg -bi -brw -bu -v -run=. -bench=. // Handling flags // codec_test.go will define a set of global flags for testing, including: // - Use Reset // - Use IO reader/writer (vs direct bytes) // - Set Canonical // - Set InternStrings // - Use Symbols // // This way, we can test them all by running same set of tests with a different // set of flags. // // Following this, all the benchmarks will utilize flags set by codec_test.go // and will not redefine these "global" flags. import ( "bytes" "flag" "io" "io/ioutil" "log" "sync" ) import . "github.com/ugorji/go/codec" type testHED struct { H Handle E *Encoder D *Decoder } type ioReaderWrapper struct { r io.Reader } func (x ioReaderWrapper) Read(p []byte) (n int, err error) { return x.r.Read(p) } type ioWriterWrapper struct { w io.Writer } func (x ioWriterWrapper) Write(p []byte) (n int, err error) { return x.w.Write(p) } var ( // testNoopH = NoopHandle(8) testMsgpackH = &MsgpackHandle{} testBincH = &BincHandle{} testSimpleH = &SimpleHandle{} testCborH = &CborHandle{} testJsonH = &JsonHandle{} testHandles []Handle testPreInitFns []func() testPostInitFns []func() testOnce sync.Once testHEDs []testHED ) // flag variables used by tests (and bench) var ( testVerbose bool //depth of 0 maps to ~400bytes json-encoded string, 1 maps to ~1400 bytes, etc //For depth>1, we likely trigger stack growth for encoders, making benchmarking unreliable. testDepth int testMaxInitLen int testUseReset bool testUseParallel bool testSkipIntf bool testUseIoEncDec int testUseIoWrapper bool testNumRepeatString int testRpcBufsize int testMapStringKeyOnly bool testBenchmarkNoConfig bool ) // variables that are not flags, but which can configure the handles var ( testEncodeOptions EncodeOptions testDecodeOptions DecodeOptions testRPCOptions RPCOptions ) func init() { log.SetOutput(ioutil.Discard) // don't allow things log to standard out/err testHEDs = make([]testHED, 0, 32) testHandles = append(testHandles, // testNoopH, testMsgpackH, testBincH, testSimpleH, testCborH, testJsonH) // JSON should do HTMLCharsAsIs by default testJsonH.HTMLCharsAsIs = true // testJsonH.InternString = true testInitFlags() benchInitFlags() } func testInitFlags() { var bIgnore bool // delete(testDecOpts.ExtFuncs, timeTyp) flag.BoolVar(&testVerbose, "tv", false, "Text Extra Verbose Logging if -v if set") flag.IntVar(&testUseIoEncDec, "ti", -1, "Use IO Reader/Writer for Marshal/Unmarshal ie >= 0") flag.BoolVar(&testUseIoWrapper, "tiw", false, "Wrap the IO Reader/Writer with a base pass-through reader/writer") flag.BoolVar(&testSkipIntf, "tf", false, "Skip Interfaces") flag.BoolVar(&testUseReset, "tr", false, "Use Reset") flag.BoolVar(&testUseParallel, "tp", false, "Run tests in parallel") flag.IntVar(&testNumRepeatString, "trs", 8, "Create string variables by repeating a string N times") flag.BoolVar(&bIgnore, "tm", true, "(Deprecated) Use Must(En|De)code") flag.IntVar(&testMaxInitLen, "tx", 0, "Max Init Len") flag.IntVar(&testDepth, "tsd", 0, "Test Struc Depth") flag.BoolVar(&testMapStringKeyOnly, "tsk", false, "use maps with string keys only") } func benchInitFlags() { flag.BoolVar(&testBenchmarkNoConfig, "bnc", false, "benchmarks: do not make configuration changes for fair benchmarking") // flags reproduced here for compatibility (duplicate some in testInitFlags) flag.BoolVar(&testMapStringKeyOnly, "bs", false, "benchmarks: use maps with string keys only") flag.IntVar(&testDepth, "bd", 1, "Benchmarks: Test Struc Depth") } func testHEDGet(h Handle) *testHED { for i := range testHEDs { v := &testHEDs[i] if v.H == h { return v } } testHEDs = append(testHEDs, testHED{h, NewEncoder(nil, h), NewDecoder(nil, h)}) return &testHEDs[len(testHEDs)-1] } func testReinit() { testOnce = sync.Once{} testHEDs = nil } func testInitAll() { // only parse it once. if !flag.Parsed() { flag.Parse() } for _, f := range testPreInitFns { f() } for _, f := range testPostInitFns { f() } } func testSharedCodecEncode(ts interface{}, bsIn []byte, fn func([]byte) *bytes.Buffer, h Handle, bh *BasicHandle, useMust bool) (bs []byte, err error) { // bs = make([]byte, 0, approxSize) var e *Encoder var buf *bytes.Buffer if testUseReset && !testUseParallel { e = testHEDGet(h).E } else { e = NewEncoder(nil, h) } var oldWriteBufferSize int if testUseIoEncDec >= 0 { buf = fn(bsIn) // set the encode options for using a buffer oldWriteBufferSize = bh.WriterBufferSize bh.WriterBufferSize = testUseIoEncDec if testUseIoWrapper { e.Reset(ioWriterWrapper{buf}) } else { e.Reset(buf) } } else { bs = bsIn e.ResetBytes(&bs) } if useMust { e.MustEncode(ts) } else { err = e.Encode(ts) } if testUseIoEncDec >= 0 { bs = buf.Bytes() bh.WriterBufferSize = oldWriteBufferSize } return } func testSharedCodecDecoder(bs []byte, h Handle, bh *BasicHandle) (d *Decoder, oldReadBufferSize int) { // var buf *bytes.Reader if testUseReset && !testUseParallel { d = testHEDGet(h).D } else { d = NewDecoder(nil, h) } if testUseIoEncDec >= 0 { buf := bytes.NewReader(bs) oldReadBufferSize = bh.ReaderBufferSize bh.ReaderBufferSize = testUseIoEncDec if testUseIoWrapper { d.Reset(ioReaderWrapper{buf}) } else { d.Reset(buf) } } else { d.ResetBytes(bs) } return } func testSharedCodecDecoderAfter(d *Decoder, oldReadBufferSize int, bh *BasicHandle) { if testUseIoEncDec >= 0 { bh.ReaderBufferSize = oldReadBufferSize } } func testSharedCodecDecode(bs []byte, ts interface{}, h Handle, bh *BasicHandle, useMust bool) (err error) { d, oldReadBufferSize := testSharedCodecDecoder(bs, h, bh) if useMust { d.MustDecode(ts) } else { err = d.Decode(ts) } testSharedCodecDecoderAfter(d, oldReadBufferSize, bh) return } // // --- functions below are used by both benchmarks and tests // // log message only when testVerbose = true (ie go test ... -- -tv). // // // // These are for intormational messages that do not necessarily // // help with diagnosing a failure, or which are too large. // func logTv(x interface{}, format string, args ...interface{}) { // if !testVerbose { // return // } // if t, ok := x.(testing.TB); ok { // only available from go 1.9 // t.Helper() // } // logT(x, format, args...) // } // // logT logs messages when running as go test -v // // // // Use it for diagnostics messages that help diagnost failure, // // and when the output is not too long ie shorter than like 100 characters. // // // // In general, any logT followed by failT should call this. // func logT(x interface{}, format string, args ...interface{}) { // if x == nil { // if len(format) == 0 || format[len(format)-1] != '\n' { // format = format + "\n" // } // fmt.Printf(format, args...) // return // } // if t, ok := x.(testing.TB); ok { // only available from go 1.9 // t.Helper() // t.Logf(format, args...) // } // } // func failTv(x testing.TB, args ...interface{}) { // x.Helper() // if testVerbose { // failTMsg(x, args...) // } // x.FailNow() // } // func failT(x testing.TB, args ...interface{}) { // x.Helper() // failTMsg(x, args...) // x.FailNow() // } // func failTMsg(x testing.TB, args ...interface{}) { // x.Helper() // if len(args) > 0 { // if format, ok := args[0].(string); ok { // logT(x, format, args[1:]...) // } else if len(args) == 1 { // logT(x, "%v", args[0]) // } else { // logT(x, "%v", args) // } // } // } // --- functions below are used only by benchmarks alone func fnBenchmarkByteBuf(bsIn []byte) (buf *bytes.Buffer) { // var buf bytes.Buffer // buf.Grow(approxSize) buf = bytes.NewBuffer(bsIn) buf.Truncate(0) return } // func benchFnCodecEncode(ts interface{}, bsIn []byte, h Handle) (bs []byte, err error) { // return testCodecEncode(ts, bsIn, fnBenchmarkByteBuf, h) // } // func benchFnCodecDecode(bs []byte, ts interface{}, h Handle) (err error) { // return testCodecDecode(bs, ts, h) // } go-1.2.8/codec/bench/stdlib_bench_test.go000066400000000000000000000047501435255326100203050ustar00rootroot00000000000000//go:build !generated // +build !generated // 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 ( "bytes" "encoding/gob" "encoding/json" "encoding/xml" "testing" ) func init() { testPreInitFns = append(testPreInitFns, stdlibBenchPreInit) // testPostInitFns = append(testPostInitFns, codecbenchPostInit) } func stdlibBenchPreInit() { benchCheckers = append(benchCheckers, benchChecker{"std-json", fnStdJsonEncodeFn, fnStdJsonDecodeFn}, benchChecker{"gob", fnGobEncodeFn, fnGobDecodeFn}, benchChecker{"std-xml", fnStdXmlEncodeFn, fnStdXmlDecodeFn}, ) } // ------------ tests below func fnGobEncodeFn(ts interface{}, bsIn []byte) ([]byte, error) { buf := fnBenchmarkByteBuf(bsIn) err := gob.NewEncoder(buf).Encode(ts) return buf.Bytes(), err } func fnGobDecodeFn(buf []byte, ts interface{}) error { return gob.NewDecoder(bytes.NewReader(buf)).Decode(ts) } func fnStdXmlEncodeFn(ts interface{}, bsIn []byte) ([]byte, error) { buf := fnBenchmarkByteBuf(bsIn) err := xml.NewEncoder(buf).Encode(ts) return buf.Bytes(), err } func fnStdXmlDecodeFn(buf []byte, ts interface{}) error { return xml.NewDecoder(bytes.NewReader(buf)).Decode(ts) } func fnStdJsonEncodeFn(ts interface{}, bsIn []byte) ([]byte, error) { if testUseIoEncDec >= 0 { buf := fnBenchmarkByteBuf(bsIn) err := json.NewEncoder(buf).Encode(ts) return buf.Bytes(), err } return json.Marshal(ts) } func fnStdJsonDecodeFn(buf []byte, ts interface{}) error { if testUseIoEncDec >= 0 { return json.NewDecoder(bytes.NewReader(buf)).Decode(ts) } return json.Unmarshal(buf, ts) } // ----------- ENCODE ------------------ func Benchmark__Std_Json___Encode(b *testing.B) { fnBenchmarkEncode(b, "std-json", benchTs, fnStdJsonEncodeFn) } func Benchmark__Gob________Encode(b *testing.B) { fnBenchmarkEncode(b, "gob", benchTs, fnGobEncodeFn) } func Benchmark__Std_Xml____Encode(b *testing.B) { fnBenchmarkEncode(b, "std-xml", benchTs, fnStdXmlEncodeFn) } // ----------- DECODE ------------------ func Benchmark__Std_Json___Decode(b *testing.B) { fnBenchmarkDecode(b, "std-json", benchTs, fnStdJsonEncodeFn, fnStdJsonDecodeFn, fnBenchNewTs) } func Benchmark__Gob________Decode(b *testing.B) { fnBenchmarkDecode(b, "gob", benchTs, fnGobEncodeFn, fnGobDecodeFn, fnBenchNewTs) } func Benchmark__Std_Xml____Decode(b *testing.B) { fnBenchmarkDecode(b, "std-xml", benchTs, fnStdXmlEncodeFn, fnStdXmlDecodeFn, fnBenchNewTs) } go-1.2.8/codec/bench/values_test.go000077700000000000000000000000001435255326100222512../values_test.goustar00rootroot00000000000000go-1.2.8/codec/bench/x_bench_gen_test.go000066400000000000000000000101011435255326100201070ustar00rootroot00000000000000//go:build x && generated // +build x,generated // 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 ( "bytes" "errors" "fmt" "testing" "github.com/mailru/easyjson" "github.com/pquerna/ffjson/ffjson" "github.com/tinylib/msgp/msgp" ) /* To update all these, use: go get -u github.com/tinylib/msgp/msgp github.com/tinylib/msgp \ github.com/pquerna/ffjson/ffjson github.com/pquerna/ffjson \ github.com/mailru/easyjson/... Known Issues with external libraries: - msgp io.R/W support doesn't work. It throws error - ffjson: generated code fails to compile as of latest commit checked on 2022-12-26 */ // benchXGenSkipFFJSON triggers whether we throw a panic based // on whether ffjson generated code compiles. // // MARKER: change if ffjson is updated and compiles successfully const benchXGenSkipFFJSON = true func init() { testPreInitFns = append(testPreInitFns, benchXGenPreInit) } func benchXGenPreInit() { benchCheckers = append(benchCheckers, benchChecker{"msgp", fnMsgpEncodeFn, fnMsgpDecodeFn}, benchChecker{"easyjson", fnEasyjsonEncodeFn, fnEasyjsonDecodeFn}, benchChecker{"ffjson", fnFfjsonEncodeFn, fnFfjsonDecodeFn}, ) } func fnEasyjsonEncodeFn(ts interface{}, bsIn []byte) ([]byte, error) { ts2, ok := ts.(easyjson.Marshaler) if !ok || ts2 == nil { return nil, errors.New("easyjson: input is not a easyjson.Marshaler") } if testUseIoEncDec >= 0 { buf := bytes.NewBuffer(bsIn[:0]) // new(bytes.Buffer) _, err := easyjson.MarshalToWriter(ts2, buf) return buf.Bytes(), err } return easyjson.Marshal(ts2) // return ts.(json.Marshaler).MarshalJSON() } func fnEasyjsonDecodeFn(buf []byte, ts interface{}) error { ts2, ok := ts.(easyjson.Unmarshaler) if !ok { return errors.New("easyjson: input is not a easyjson.Unmarshaler") } if testUseIoEncDec >= 0 { return easyjson.UnmarshalFromReader(bytes.NewReader(buf), ts2) } return easyjson.Unmarshal(buf, ts2) // return ts.(json.Unmarshaler).UnmarshalJSON(buf) } func fnFfjsonEncodeFn(ts interface{}, bsIn []byte) ([]byte, error) { if benchXGenSkipFFJSON { panic(errors.New("ffjson: generated code fails to compile; checked 2022-12-26")) } return ffjson.Marshal(ts) // return ts.(json.Marshaler).MarshalJSON() } func fnFfjsonDecodeFn(buf []byte, ts interface{}) error { if benchXGenSkipFFJSON { panic(errors.New("ffjson: generated code fails to compile; checked 2022-12-26")) } return ffjson.Unmarshal(buf, ts) // return ts.(json.Unmarshaler).UnmarshalJSON(buf) } func fnMsgpEncodeFn(ts interface{}, bsIn []byte) ([]byte, error) { if _, ok := ts.(msgp.Encodable); !ok { return nil, fmt.Errorf("msgp: input of type %T is not a msgp.Encodable", ts) } if testUseIoEncDec >= 0 { buf := fnBenchmarkByteBuf(bsIn) err := ts.(msgp.Encodable).EncodeMsg(msgp.NewWriter(buf)) return buf.Bytes(), err } return ts.(msgp.Marshaler).MarshalMsg(bsIn[:0]) // msgp appends to slice. } func fnMsgpDecodeFn(buf []byte, ts interface{}) (err error) { if _, ok := ts.(msgp.Decodable); !ok { return fmt.Errorf("msgp: input of type %T is not a msgp.Decodable", ts) } if testUseIoEncDec >= 0 { err = ts.(msgp.Decodable).DecodeMsg(msgp.NewReader(bytes.NewReader(buf))) return } _, err = ts.(msgp.Unmarshaler).UnmarshalMsg(buf) return } func Benchmark__Msgp_______Encode(b *testing.B) { fnBenchmarkEncode(b, "msgp", benchTs, fnMsgpEncodeFn) } func Benchmark__Msgp_______Decode(b *testing.B) { fnBenchmarkDecode(b, "msgp", benchTs, fnMsgpEncodeFn, fnMsgpDecodeFn, fnBenchNewTs) } func Benchmark__Easyjson___Encode(b *testing.B) { fnBenchmarkEncode(b, "easyjson", benchTs, fnEasyjsonEncodeFn) } func Benchmark__Easyjson___Decode(b *testing.B) { fnBenchmarkDecode(b, "easyjson", benchTs, fnEasyjsonEncodeFn, fnEasyjsonDecodeFn, fnBenchNewTs) } func Benchmark__Ffjson_____Encode(b *testing.B) { fnBenchmarkEncode(b, "ffjson", benchTs, fnFfjsonEncodeFn) } func Benchmark__Ffjson_____Decode(b *testing.B) { fnBenchmarkDecode(b, "ffjson", benchTs, fnFfjsonEncodeFn, fnFfjsonDecodeFn, fnBenchNewTs) } go-1.2.8/codec/bench/x_bench_test.go000066400000000000000000000147051435255326100172740ustar00rootroot00000000000000//go:build x && !generated // +build x,!generated // 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 ( "bytes" "testing" gcbor "bitbucket.org/bodhisnarkva/cbor/go" "github.com/Sereal/Sereal/Go/sereal" xdr "github.com/davecgh/go-xdr/xdr2" fxcbor "github.com/fxamacker/cbor/v2" mgobson "github.com/globalsign/mgo/bson" jsoniter "github.com/json-iterator/go" vmsgpack "github.com/vmihailenco/msgpack/v4" "go.mongodb.org/mongo-driver/bson" ) /* To update all these, use: go get -u github.com/tinylib/msgp/msgp github.com/tinylib/msgp \ github.com/pquerna/ffjson/ffjson github.com/pquerna/ffjson \ github.com/Sereal/Sereal/Go/sereal \ bitbucket.org/bodhisnarkva/cbor/go \ github.com/davecgh/go-xdr/xdr2 \ github.com/globalsign/mgo/bson \ github.com/vmihailenco/msgpack/v4 / github.com/json-iterator/go \ github.com/fxamacker/cbor/v2 \ github.com/mailru/easyjson/... Known Issues with external libraries: - msgp io.R/W support doesn't work. It throws error */ func init() { testPreInitFns = append(testPreInitFns, benchXPreInit) _ = bson.NewDecoder } func benchXPreInit() { benchCheckers = append(benchCheckers, benchChecker{"json-iter", fnJsonIterEncodeFn, fnJsonIterDecodeFn}, benchChecker{"v-msgpack", fnVMsgpackEncodeFn, fnVMsgpackDecodeFn}, benchChecker{"bson", fnBsonEncodeFn, fnBsonDecodeFn}, benchChecker{"mgobson", fnMgobsonEncodeFn, fnMgobsonDecodeFn}, benchChecker{"fxcbor", fnFxcborEncodeFn, fnFxcborDecodeFn}, // place codecs with issues at the end, so as not to make results too ugly benchChecker{"gcbor", fnGcborEncodeFn, fnGcborDecodeFn}, // this logs fat ugly message, but we log.SetOutput(ioutil.Discard) benchChecker{"xdr", fnXdrEncodeFn, fnXdrDecodeFn}, benchChecker{"sereal", fnSerealEncodeFn, fnSerealDecodeFn}, ) } func fnVMsgpackEncodeFn(ts interface{}, bsIn []byte) ([]byte, error) { if testUseIoEncDec >= 0 { buf := bytes.NewBuffer(bsIn[:0]) // new(bytes.Buffer) err := vmsgpack.NewEncoder(buf).Encode(ts) return buf.Bytes(), err } return vmsgpack.Marshal(ts) } func fnVMsgpackDecodeFn(buf []byte, ts interface{}) error { if testUseIoEncDec >= 0 { return vmsgpack.NewDecoder(bytes.NewReader(buf)).Decode(ts) } return vmsgpack.Unmarshal(buf, ts) } func fnBsonEncodeFn(ts interface{}, bsIn []byte) ([]byte, error) { return bson.Marshal(ts) } func fnBsonDecodeFn(buf []byte, ts interface{}) error { return bson.Unmarshal(buf, ts) } func fnMgobsonEncodeFn(ts interface{}, bsIn []byte) ([]byte, error) { return mgobson.Marshal(ts) } func fnMgobsonDecodeFn(buf []byte, ts interface{}) error { return mgobson.Unmarshal(buf, ts) } func fnJsonIterEncodeFn(ts interface{}, bsIn []byte) ([]byte, error) { if testUseIoEncDec >= 0 { buf := bytes.NewBuffer(bsIn[:0]) // new(bytes.Buffer) err := jsoniter.NewEncoder(buf).Encode(ts) return buf.Bytes(), err } return jsoniter.Marshal(ts) } func fnJsonIterDecodeFn(buf []byte, ts interface{}) error { if testUseIoEncDec >= 0 { return jsoniter.NewDecoder(bytes.NewReader(buf)).Decode(ts) } return jsoniter.Unmarshal(buf, ts) } func fnFxcborEncodeFn(ts interface{}, bsIn []byte) ([]byte, error) { if testUseIoEncDec >= 0 { buf := bytes.NewBuffer(bsIn[:0]) err := fxcbor.NewEncoder(buf).Encode(ts) return buf.Bytes(), err } return fxcbor.Marshal(ts) } func fnFxcborDecodeFn(buf []byte, ts interface{}) error { if testUseIoEncDec >= 0 { return fxcbor.NewDecoder(bytes.NewReader(buf)).Decode(ts) } return fxcbor.Unmarshal(buf, ts) } func fnXdrEncodeFn(ts interface{}, bsIn []byte) ([]byte, error) { buf := fnBenchmarkByteBuf(bsIn) i, err := xdr.Marshal(buf, ts) return buf.Bytes()[:i], err } func fnXdrDecodeFn(buf []byte, ts interface{}) error { _, err := xdr.Unmarshal(bytes.NewReader(buf), ts) return err } func fnSerealEncodeFn(ts interface{}, bsIn []byte) ([]byte, error) { return sereal.Marshal(ts) } func fnSerealDecodeFn(buf []byte, ts interface{}) error { return sereal.Unmarshal(buf, ts) } func fnGcborEncodeFn(ts interface{}, bsIn []byte) (bs []byte, err error) { buf := fnBenchmarkByteBuf(bsIn) err = gcbor.NewEncoder(buf).Encode(ts) return buf.Bytes(), err } func fnGcborDecodeFn(buf []byte, ts interface{}) error { return gcbor.NewDecoder(bytes.NewReader(buf)).Decode(ts) } func Benchmark__JsonIter___Encode(b *testing.B) { fnBenchmarkEncode(b, "jsoniter", benchTs, fnJsonIterEncodeFn) } func Benchmark__JsonIter___Decode(b *testing.B) { fnBenchmarkDecode(b, "jsoniter", benchTs, fnJsonIterEncodeFn, fnJsonIterDecodeFn, fnBenchNewTs) } func Benchmark__Fxcbor_____Encode(b *testing.B) { fnBenchmarkEncode(b, "fxcbor", benchTs, fnFxcborEncodeFn) } func Benchmark__Fxcbor_____Decode(b *testing.B) { fnBenchmarkDecode(b, "fxcbor", benchTs, fnFxcborEncodeFn, fnFxcborDecodeFn, fnBenchNewTs) } // Place codecs with issues at the bottom, so as not to make results look too ugly. func Benchmark__Mgobson____Encode(b *testing.B) { fnBenchmarkEncode(b, "mgobson", benchTs, fnMgobsonEncodeFn) } func Benchmark__Mgobson____Decode(b *testing.B) { fnBenchmarkDecode(b, "mgobson", benchTs, fnMgobsonEncodeFn, fnMgobsonDecodeFn, fnBenchNewTs) } func Benchmark__Bson_______Encode(b *testing.B) { fnBenchmarkEncode(b, "bson", benchTs, fnBsonEncodeFn) } func Benchmark__Bson_______Decode(b *testing.B) { fnBenchmarkDecode(b, "bson", benchTs, fnBsonEncodeFn, fnBsonDecodeFn, fnBenchNewTs) } func Benchmark__VMsgpack___Encode(b *testing.B) { fnBenchmarkEncode(b, "v-msgpack", benchTs, fnVMsgpackEncodeFn) } func Benchmark__VMsgpack___Decode(b *testing.B) { fnBenchmarkDecode(b, "v-msgpack", benchTs, fnVMsgpackEncodeFn, fnVMsgpackDecodeFn, fnBenchNewTs) } func Benchmark__Gcbor______Encode(b *testing.B) { fnBenchmarkEncode(b, "gcbor", benchTs, fnGcborEncodeFn) } func Benchmark__Gcbor______Decode(b *testing.B) { fnBenchmarkDecode(b, "gcbor", benchTs, fnGcborEncodeFn, fnGcborDecodeFn, fnBenchNewTs) } func Benchmark__Xdr________Encode(b *testing.B) { fnBenchmarkEncode(b, "xdr", benchTs, fnXdrEncodeFn) } func Benchmark__Xdr________Decode(b *testing.B) { fnBenchmarkDecode(b, "xdr", benchTs, fnXdrEncodeFn, fnXdrDecodeFn, fnBenchNewTs) } func Benchmark__Sereal_____Encode(b *testing.B) { fnBenchmarkEncode(b, "sereal", benchTs, fnSerealEncodeFn) } func Benchmark__Sereal_____Decode(b *testing.B) { fnBenchmarkDecode(b, "sereal", benchTs, fnSerealEncodeFn, fnSerealDecodeFn, fnBenchNewTs) } go-1.2.8/codec/bench/z_all_bench_test.go000066400000000000000000000130661435255326100201250ustar00rootroot00000000000000//go:build alltests && go1.7 // +build alltests,go1.7 // 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 // see notes in z_all_test.go import ( "strconv" "sync" "testing" "time" ) var benchmarkGroupOnce sync.Once var benchmarkGroupSave struct { testUseIoEncDec int testUseReset bool testDepth int testMapStringKeyOnly bool } func benchmarkGroupInitAll() { testInitAll() // calls flag.Parse benchmarkGroupSave.testUseIoEncDec = testUseIoEncDec benchmarkGroupSave.testUseReset = testUseReset benchmarkGroupSave.testDepth = testDepth benchmarkGroupSave.testMapStringKeyOnly = testMapStringKeyOnly } func benchmarkGroupReset() { testUseIoEncDec = benchmarkGroupSave.testUseIoEncDec testUseReset = benchmarkGroupSave.testUseReset testDepth = benchmarkGroupSave.testDepth testMapStringKeyOnly = benchmarkGroupSave.testMapStringKeyOnly } func benchmarkOneFn(fns []func(*testing.B)) func(*testing.B) { switch len(fns) { case 0: return nil case 1: return fns[0] default: return func(t *testing.B) { for _, f := range fns { f(t) } } } } func benchmarkSuiteNoop(b *testing.B) { testOnce.Do(testInitAll) b.ResetTimer() for i := 0; i < b.N; i++ { time.Sleep(10 * time.Millisecond) } } func benchmarkSuite(t *testing.B, fns ...func(t *testing.B)) { benchmarkGroupOnce.Do(benchmarkGroupInitAll) f := benchmarkOneFn(fns) // find . -name "*_test.go" | xargs grep -e 'flag.' | cut -d '&' -f 2 | cut -d ',' -f 1 | grep -e '^bench' testReinit() // so flag.Parse() is called first, and never called again benchReinit() benchmarkGroupReset() testReinit() benchReinit() t.Run("options-false...", f) benchmarkGroupReset() testUseIoEncDec = 1024 testReinit() benchReinit() t.Run("use-bufio-!bytes", f) benchmarkGroupReset() testUseReset = true testReinit() benchReinit() t.Run("reset-enc-dec...", f) benchmarkGroupReset() } func benchmarkVeryQuickSuite(t *testing.B, name string, fns ...func(t *testing.B)) { benchmarkDivider() benchmarkGroupOnce.Do(benchmarkGroupInitAll) benchmarkGroupReset() // bd=1 2 | ti=-1, 1024 | testUseIoEncDec = -1 // testDepth = depth testReinit() benchReinit() t.Run(name+"-bd"+strconv.Itoa(testDepth)+"........", benchmarkOneFn(fns)) benchmarkGroupReset() } func benchmarkQuickSuite(t *testing.B, name string, fns ...func(t *testing.B)) { benchmarkVeryQuickSuite(t, name, fns...) // encoded size of TestStruc is between 20K and 30K for bd=1 // consider buffer=1024 * 16 * testDepth testUseIoEncDec = 1024 // (value of defEncByteBufSize): use smaller buffer, and more flushes - it's ok. // testDepth = depth testReinit() benchReinit() t.Run(name+"-bd"+strconv.Itoa(testDepth)+"-buf"+strconv.Itoa(testUseIoEncDec), benchmarkOneFn(fns)) testUseIoEncDec = 0 // testDepth = depth testReinit() benchReinit() t.Run(name+"-bd"+strconv.Itoa(testDepth)+"-io.....", benchmarkOneFn(fns)) benchmarkGroupReset() } /* z='bench_test.go' find . -name "$z" | xargs grep -e '^func Benchmark.*Encode' | \ cut -d '(' -f 1 | cut -d ' ' -f 2 | \ while read f; do echo "t.Run(\"$f\", $f)"; done && echo && find . -name "$z" | xargs grep -e '^func Benchmark.*Decode' | \ cut -d '(' -f 1 | cut -d ' ' -f 2 | \ while read f; do echo "t.Run(\"$f\", $f)"; done */ func benchmarkCodecGroup(t *testing.B) { benchmarkDivider() t.Run("Benchmark__Msgpack____Encode", Benchmark__Msgpack____Encode) t.Run("Benchmark__Binc_______Encode", Benchmark__Binc_______Encode) t.Run("Benchmark__Simple_____Encode", Benchmark__Simple_____Encode) t.Run("Benchmark__Cbor_______Encode", Benchmark__Cbor_______Encode) t.Run("Benchmark__Json_______Encode", Benchmark__Json_______Encode) benchmarkDivider() t.Run("Benchmark__Msgpack____Decode", Benchmark__Msgpack____Decode) t.Run("Benchmark__Binc_______Decode", Benchmark__Binc_______Decode) t.Run("Benchmark__Simple_____Decode", Benchmark__Simple_____Decode) t.Run("Benchmark__Cbor_______Decode", Benchmark__Cbor_______Decode) t.Run("Benchmark__Json_______Decode", Benchmark__Json_______Decode) } func BenchmarkCodecSuite(t *testing.B) { benchmarkSuite(t, benchmarkCodecGroup) } func benchmarkJsonEncodeGroup(t *testing.B) { t.Run("Benchmark__Json_______Encode", Benchmark__Json_______Encode) } func benchmarkJsonDecodeGroup(t *testing.B) { t.Run("Benchmark__Json_______Decode", Benchmark__Json_______Decode) } func benchmarkCborEncodeGroup(t *testing.B) { t.Run("Benchmark__Cbor_______Encode", Benchmark__Cbor_______Encode) } func benchmarkCborDecodeGroup(t *testing.B) { t.Run("Benchmark__Cbor_______Decode", Benchmark__Cbor_______Decode) } func BenchmarkCodecQuickSuite(t *testing.B) { benchmarkQuickSuite(t, "cbor", benchmarkCborEncodeGroup) benchmarkQuickSuite(t, "cbor", benchmarkCborDecodeGroup) benchmarkQuickSuite(t, "json", benchmarkJsonEncodeGroup) benchmarkQuickSuite(t, "json", benchmarkJsonDecodeGroup) // depths := [...]int{1, 4} // for _, d := range depths { // benchmarkQuickSuite(t, d, benchmarkJsonEncodeGroup) // benchmarkQuickSuite(t, d, benchmarkJsonDecodeGroup) // } // benchmarkQuickSuite(t, 1, benchmarkJsonEncodeGroup) // benchmarkQuickSuite(t, 4, benchmarkJsonEncodeGroup) // benchmarkQuickSuite(t, 1, benchmarkJsonDecodeGroup) // benchmarkQuickSuite(t, 4, benchmarkJsonDecodeGroup) // benchmarkQuickSuite(t, 1, benchmarkJsonEncodeGroup, benchmarkJsonDecodeGroup) // benchmarkQuickSuite(t, 4, benchmarkJsonEncodeGroup, benchmarkJsonDecodeGroup) // benchmarkQuickSuite(t, benchmarkJsonEncodeGroup) // benchmarkQuickSuite(t, benchmarkJsonDecodeGroup) } go-1.2.8/codec/bench/z_all_stdlib_bench_test.go000066400000000000000000000015201435255326100214560ustar00rootroot00000000000000//go:build alltests && go1.7 && !generated // +build alltests,go1.7,!generated // 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 "testing" func benchmarkStdlibGroup(t *testing.B) { benchmarkDivider() t.Run("Benchmark__Std_Json___Encode", Benchmark__Std_Json___Encode) t.Run("Benchmark__Gob________Encode", Benchmark__Gob________Encode) // t.Run("Benchmark__Std_Xml____Encode", Benchmark__Std_Xml____Encode) benchmarkDivider() t.Run("Benchmark__Std_Json___Decode", Benchmark__Std_Json___Decode) t.Run("Benchmark__Gob________Decode", Benchmark__Gob________Decode) // t.Run("Benchmark__Std_Xml____Decode", Benchmark__Std_Xml____Decode) } func BenchmarkStdlibSuite(t *testing.B) { benchmarkSuite(t, benchmarkStdlibGroup) } go-1.2.8/codec/bench/z_all_x_bench_gen_test.go000066400000000000000000000030601435255326100212760ustar00rootroot00000000000000//go:build alltests && go1.7 && x && generated // +build alltests,go1.7,x,generated // 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 // see notes in z_all_bench_test.go import "testing" func benchmarkCodecXGenGroup(t *testing.B) { benchmarkDivider() t.Run("Benchmark__Msgpack____Encode", Benchmark__Msgpack____Encode) t.Run("Benchmark__Binc_______Encode", Benchmark__Binc_______Encode) t.Run("Benchmark__Simple_____Encode", Benchmark__Simple_____Encode) t.Run("Benchmark__Cbor_______Encode", Benchmark__Cbor_______Encode) t.Run("Benchmark__Json_______Encode", Benchmark__Json_______Encode) t.Run("Benchmark__Msgp_______Encode", Benchmark__Msgp_______Encode) t.Run("Benchmark__Easyjson___Encode", Benchmark__Easyjson___Encode) t.Run("Benchmark__Ffjson_____Encode", Benchmark__Ffjson_____Encode) benchmarkDivider() t.Run("Benchmark__Msgpack____Decode", Benchmark__Msgpack____Decode) t.Run("Benchmark__Binc_______Decode", Benchmark__Binc_______Decode) t.Run("Benchmark__Simple_____Decode", Benchmark__Simple_____Decode) t.Run("Benchmark__Cbor_______Decode", Benchmark__Cbor_______Decode) t.Run("Benchmark__Json_______Decode", Benchmark__Json_______Decode) t.Run("Benchmark__Msgp_______Decode", Benchmark__Msgp_______Decode) t.Run("Benchmark__Easyjson___Decode", Benchmark__Easyjson___Decode) t.Run("Benchmark__Ffjson_____Decode", Benchmark__Ffjson_____Decode) } func BenchmarkCodecXGenSuite(t *testing.B) { benchmarkSuite(t, benchmarkCodecXGenGroup) } go-1.2.8/codec/bench/z_all_x_bench_test.go000066400000000000000000000137741435255326100204620ustar00rootroot00000000000000//go:build alltests && go1.7 && x && !generated // +build alltests,go1.7,x,!generated // 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 // see notes in z_all_bench_test.go import "testing" // Note: The following cannot parse TestStruc effectively, // even with changes to remove arrays and minimize integer size to fit into int64 space. // // So we exclude them, listed below: // encode: gcbor, xdr // decode: gcbor, vmsgpack, xdr, sereal func benchmarkXGroup(t *testing.B) { benchmarkDivider() t.Run("Benchmark__JsonIter___Encode", Benchmark__JsonIter___Encode) t.Run("Benchmark__Fxcbor_____Encode", Benchmark__Fxcbor_____Encode) t.Run("Benchmark__Bson_______Encode", Benchmark__Bson_______Encode) t.Run("Benchmark__Mgobson____Encode", Benchmark__Mgobson____Encode) t.Run("Benchmark__VMsgpack___Encode", Benchmark__VMsgpack___Encode) // t.Run("Benchmark__Gcbor______Encode", Benchmark__Gcbor______Encode) // t.Run("Benchmark__Xdr________Encode", Benchmark__Xdr________Encode) t.Run("Benchmark__Sereal_____Encode", Benchmark__Sereal_____Encode) benchmarkDivider() t.Run("Benchmark__JsonIter___Decode", Benchmark__JsonIter___Decode) t.Run("Benchmark__Fxcbor_____Decode", Benchmark__Fxcbor_____Decode) t.Run("Benchmark__Bson_______Decode", Benchmark__Bson_______Decode) t.Run("Benchmark__Mgobson____Decode", Benchmark__Mgobson____Decode) t.Run("Benchmark__VMsgpack___Decode", Benchmark__VMsgpack___Decode) // t.Run("Benchmark__Gcbor______Decode", Benchmark__Gcbor______Decode) // t.Run("Benchmark__Xdr________Decode", Benchmark__Xdr________Decode) // t.Run("Benchmark__Sereal_____Decode", Benchmark__Sereal_____Decode) } func benchmarkCodecXGroup(t *testing.B) { benchmarkDivider() t.Run("Benchmark__Msgpack____Encode", Benchmark__Msgpack____Encode) t.Run("Benchmark__Binc_______Encode", Benchmark__Binc_______Encode) t.Run("Benchmark__Simple_____Encode", Benchmark__Simple_____Encode) t.Run("Benchmark__Cbor_______Encode", Benchmark__Cbor_______Encode) t.Run("Benchmark__Json_______Encode", Benchmark__Json_______Encode) t.Run("Benchmark__Std_Json___Encode", Benchmark__Std_Json___Encode) t.Run("Benchmark__Gob________Encode", Benchmark__Gob________Encode) // t.Run("Benchmark__Std_Xml____Encode", Benchmark__Std_Xml____Encode) t.Run("Benchmark__JsonIter___Encode", Benchmark__JsonIter___Encode) t.Run("Benchmark__Bson_______Encode", Benchmark__Bson_______Encode) t.Run("Benchmark__Mgobson____Encode", Benchmark__Mgobson____Encode) t.Run("Benchmark__VMsgpack___Encode", Benchmark__VMsgpack___Encode) t.Run("Benchmark__Fxcbor_____Encode", Benchmark__Fxcbor_____Encode) // t.Run("Benchmark__Gcbor______Encode", Benchmark__Gcbor______Encode) // t.Run("Benchmark__Xdr________Encode", Benchmark__Xdr________Encode) t.Run("Benchmark__Sereal_____Encode", Benchmark__Sereal_____Encode) benchmarkDivider() t.Run("Benchmark__Msgpack____Decode", Benchmark__Msgpack____Decode) t.Run("Benchmark__Binc_______Decode", Benchmark__Binc_______Decode) t.Run("Benchmark__Simple_____Decode", Benchmark__Simple_____Decode) t.Run("Benchmark__Cbor_______Decode", Benchmark__Cbor_______Decode) t.Run("Benchmark__Json_______Decode", Benchmark__Json_______Decode) t.Run("Benchmark__Std_Json___Decode", Benchmark__Std_Json___Decode) t.Run("Benchmark__Gob________Decode", Benchmark__Gob________Decode) // t.Run("Benchmark__Std_Xml____Decode", Benchmark__Std_Xml____Decode) t.Run("Benchmark__JsonIter___Decode", Benchmark__JsonIter___Decode) t.Run("Benchmark__Bson_______Decode", Benchmark__Bson_______Decode) t.Run("Benchmark__Mgobson____Decode", Benchmark__Mgobson____Decode) t.Run("Benchmark__VMsgpack___Decode", Benchmark__VMsgpack___Decode) t.Run("Benchmark__Fxcbor_____Decode", Benchmark__Fxcbor_____Decode) // t.Run("Benchmark__Gcbor______Decode", Benchmark__Gcbor______Decode) // t.Run("Benchmark__Xdr________Decode", Benchmark__Xdr________Decode) // t.Run("Benchmark__Sereal_____Decode", Benchmark__Sereal_____Decode) } var benchmarkXSkipMsg = `>>>> Skipping - these cannot (en|de)code TestStruc - encode (xml, gcbor, xdr), decode (xml, gcbor, xdr, sereal)` func BenchmarkXSuite(t *testing.B) { println(benchmarkXSkipMsg) benchmarkSuite(t, benchmarkXGroup) } func BenchmarkCodecXSuite(t *testing.B) { println(benchmarkXSkipMsg) benchmarkSuite(t, benchmarkCodecXGroup) } func benchmarkAllJsonEncodeGroup(t *testing.B) { benchmarkDivider() t.Run("Benchmark__Json_______Encode", Benchmark__Json_______Encode) t.Run("Benchmark__Std_Json___Encode", Benchmark__Std_Json___Encode) t.Run("Benchmark__JsonIter___Encode", Benchmark__JsonIter___Encode) } func benchmarkAllJsonDecodeGroup(t *testing.B) { benchmarkDivider() t.Run("Benchmark__Json_______Decode", Benchmark__Json_______Decode) t.Run("Benchmark__Std_Json___Decode", Benchmark__Std_Json___Decode) t.Run("Benchmark__JsonIter___Decode", Benchmark__JsonIter___Decode) } func BenchmarkCodecVeryQuickAllJsonSuite(t *testing.B) { benchmarkVeryQuickSuite(t, "json-all", benchmarkAllJsonEncodeGroup, benchmarkAllJsonDecodeGroup) } func BenchmarkCodecQuickAllJsonSuite(t *testing.B) { benchmarkQuickSuite(t, "json-all", benchmarkAllJsonEncodeGroup, benchmarkAllJsonDecodeGroup) // benchmarkQuickSuite(t, "json-all", benchmarkAllJsonEncodeGroup) // benchmarkQuickSuite(t, "json-all", benchmarkAllJsonDecodeGroup) // depths := [...]int{1, 4} // for _, d := range depths { // benchmarkQuickSuite(t, d, benchmarkAllJsonEncodeGroup) // benchmarkQuickSuite(t, d, benchmarkAllJsonDecodeGroup) // } // benchmarkQuickSuite(t, 1, benchmarkAllJsonEncodeGroup) // benchmarkQuickSuite(t, 4, benchmarkAllJsonEncodeGroup) // benchmarkQuickSuite(t, 1, benchmarkAllJsonDecodeGroup) // benchmarkQuickSuite(t, 4, benchmarkAllJsonDecodeGroup) // benchmarkQuickSuite(t, 1, benchmarkAllJsonEncodeGroup, benchmarkAllJsonDecodeGroup) // benchmarkQuickSuite(t, 4, benchmarkAllJsonEncodeGroup, benchmarkAllJsonDecodeGroup) // benchmarkQuickSuite(t, benchmarkAllJsonEncodeGroup) // benchmarkQuickSuite(t, benchmarkAllJsonDecodeGroup) } go-1.2.8/codec/binc.go000066400000000000000000000770121435255326100144630ustar00rootroot00000000000000// 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" "reflect" "time" "unicode/utf8" ) // 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) captureState() interface{} { return e.m } func (e *bincEncState) resetState() { e.m = nil } func (e *bincEncState) reset() { e.resetState() } func (e *bincEncState) restoreState(v interface{}) { e.m = v.(map[string]uint16) } type bincEncDriver struct { noBuiltInTypes encDriverNoopContainerWriter h *BincHandle bincEncState e Encoder } func (e *bincEncDriver) encoder() *Encoder { return &e.e } func (e *bincEncDriver) EncodeNil() { e.e.encWr.writen1(bincBdNil) } func (e *bincEncDriver) EncodeTime(t time.Time) { if t.IsZero() { e.EncodeNil() } else { bs := bincEncodeTime(t) e.e.encWr.writen1(bincVdTimestamp<<4 | uint8(len(bs))) e.e.encWr.writeb(bs) } } func (e *bincEncDriver) EncodeBool(b bool) { if b { e.e.encWr.writen1(bincVdSpecial<<4 | bincSpTrue) } else { e.e.encWr.writen1(bincVdSpecial<<4 | bincSpFalse) } } func (e *bincEncDriver) encSpFloat(f float64) (done bool) { if f == 0 { e.e.encWr.writen1(bincVdSpecial<<4 | bincSpZeroFloat) } else if math.IsNaN(float64(f)) { e.e.encWr.writen1(bincVdSpecial<<4 | bincSpNan) } else if math.IsInf(float64(f), +1) { e.e.encWr.writen1(bincVdSpecial<<4 | bincSpPosInf) } else if math.IsInf(float64(f), -1) { e.e.encWr.writen1(bincVdSpecial<<4 | bincSpNegInf) } else { return } return true } func (e *bincEncDriver) EncodeFloat32(f float32) { if !e.encSpFloat(float64(f)) { e.e.encWr.writen1(bincVdFloat<<4 | bincFlBin32) bigen.writeUint32(e.e.w(), math.Float32bits(f)) } } func (e *bincEncDriver) 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.e.encWr.writen1(bincVdFloat<<4 | 0x8 | bincFlBin64) e.e.encWr.writen1(byte(i)) e.e.encWr.writeb(b[:i]) return } } e.e.encWr.writen1(bincVdFloat<<4 | bincFlBin64) e.e.encWr.writen8(b) } func (e *bincEncDriver) encIntegerPrune32(bd byte, pos bool, v uint64) { b := bigen.PutUint32(uint32(v)) if bincDoPrune { i := byte(pruneSignExt(b[:], pos)) e.e.encWr.writen1(bd | 3 - i) e.e.encWr.writeb(b[i:]) } else { e.e.encWr.writen1(bd | 3) e.e.encWr.writen4(b) } } func (e *bincEncDriver) encIntegerPrune64(bd byte, pos bool, v uint64) { b := bigen.PutUint64(v) if bincDoPrune { i := byte(pruneSignExt(b[:], pos)) e.e.encWr.writen1(bd | 7 - i) e.e.encWr.writeb(b[i:]) } else { e.e.encWr.writen1(bd | 7) e.e.encWr.writen8(b) } } func (e *bincEncDriver) EncodeInt(v int64) { if v >= 0 { e.encUint(bincVdPosInt<<4, true, uint64(v)) } else if v == -1 { e.e.encWr.writen1(bincVdSpecial<<4 | bincSpNegOne) } else { e.encUint(bincVdNegInt<<4, false, uint64(-v)) } } func (e *bincEncDriver) EncodeUint(v uint64) { e.encUint(bincVdPosInt<<4, true, v) } func (e *bincEncDriver) encUint(bd byte, pos bool, v uint64) { if v == 0 { e.e.encWr.writen1(bincVdSpecial<<4 | bincSpZero) } else if pos && v >= 1 && v <= 16 { e.e.encWr.writen1(bincVdSmallInt<<4 | byte(v-1)) } else if v <= math.MaxUint8 { e.e.encWr.writen2(bd|0x0, byte(v)) } else if v <= math.MaxUint16 { e.e.encWr.writen1(bd | 0x01) bigen.writeUint16(e.e.w(), uint16(v)) } else if v <= math.MaxUint32 { e.encIntegerPrune32(bd, pos, v) } else { e.encIntegerPrune64(bd, pos, v) } } func (e *bincEncDriver) 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 e.e.sideEncode(v, basetype, &bs) } else { bs = ext.WriteExt(v) } if bs == nil { e.EncodeNil() goto END } e.encodeExtPreamble(uint8(xtag), len(bs)) e.e.encWr.writeb(bs) END: if ext == SelfExt { e.e.blist.put(bs) if !byteSliceSameData(bs0, bs) { e.e.blist.put(bs0) } } } func (e *bincEncDriver) EncodeRawExt(re *RawExt) { e.encodeExtPreamble(uint8(re.Tag), len(re.Data)) e.e.encWr.writeb(re.Data) } func (e *bincEncDriver) encodeExtPreamble(xtag byte, length int) { e.encLen(bincVdCustomExt<<4, uint64(length)) e.e.encWr.writen1(xtag) } func (e *bincEncDriver) WriteArrayStart(length int) { e.encLen(bincVdArray<<4, uint64(length)) } func (e *bincEncDriver) WriteMapStart(length int) { e.encLen(bincVdMap<<4, uint64(length)) } func (e *bincEncDriver) 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.e.encWr.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.e.encWr.writen2(bincVdSymbol<<4, byte(ui)) } else { e.e.encWr.writen1(bincVdSymbol<<4 | 0x8) bigen.writeUint16(e.e.w(), 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.e.encWr.writen2(bincVdSymbol<<4|0x0|0x4|lenprec, byte(ui)) } else { e.e.encWr.writen1(bincVdSymbol<<4 | 0x8 | 0x4 | lenprec) bigen.writeUint16(e.e.w(), ui) } if lenprec == 0 { e.e.encWr.writen1(byte(l)) } else if lenprec == 1 { bigen.writeUint16(e.e.w(), uint16(l)) } else if lenprec == 2 { bigen.writeUint32(e.e.w(), uint32(l)) } else { bigen.writeUint64(e.e.w(), uint64(l)) } e.e.encWr.writestr(v) } } func (e *bincEncDriver) EncodeString(v string) { if e.h.StringToRaw { e.encLen(bincVdByteArray<<4, uint64(len(v))) if len(v) > 0 { e.e.encWr.writestr(v) } return } e.EncodeStringEnc(cUTF8, v) } func (e *bincEncDriver) 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.e.encWr.writestr(v) } } func (e *bincEncDriver) EncodeStringBytesRaw(v []byte) { if v == nil { e.EncodeNil() return } e.encLen(bincVdByteArray<<4, uint64(len(v))) if len(v) > 0 { e.e.encWr.writeb(v) } } func (e *bincEncDriver) 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) encLen(bd byte, l uint64) { if l < 12 { e.e.encWr.writen1(bd | uint8(l+4)) } else { e.encLenNumber(bd, l) } } func (e *bincEncDriver) encLenNumber(bd byte, v uint64) { if v <= math.MaxUint8 { e.e.encWr.writen2(bd, byte(v)) } else if v <= math.MaxUint16 { e.e.encWr.writen1(bd | 0x01) bigen.writeUint16(e.e.w(), uint16(v)) } else if v <= math.MaxUint32 { e.e.encWr.writen1(bd | 0x02) bigen.writeUint32(e.e.w(), uint32(v)) } else { e.e.encWr.writen1(bd | 0x03) bigen.writeUint64(e.e.w(), uint64(v)) } } //------------------------------------ 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) } type bincDecDriver struct { decDriverNoopContainerReader decDriverNoopNumberHelper noBuiltInTypes h *BincHandle bincDecState d Decoder } func (d *bincDecDriver) decoder() *Decoder { return &d.d } func (d *bincDecDriver) descBd() string { return sprintf("%v (%s)", d.bd, bincdescbd(d.bd)) } func (d *bincDecDriver) readNextBd() { d.bd = d.d.decRd.readn1() d.vd = d.bd >> 4 d.vs = d.bd & 0x0f d.bdRead = true } func (d *bincDecDriver) advanceNil() (null bool) { if !d.bdRead { d.readNextBd() } if d.bd == bincBdNil { d.bdRead = false return true // null = true } return } func (d *bincDecDriver) TryNil() bool { return d.advanceNil() } func (d *bincDecDriver) 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) DecodeTime() (t time.Time) { if d.advanceNil() { return } if d.vd != bincVdTimestamp { d.d.errorf("cannot decode time - %s %x-%x/%s", msgBadDesc, d.vd, d.vs, bincdesc(d.vd, d.vs)) } t, err := bincDecodeTime(d.d.decRd.readx(uint(d.vs))) halt.onerror(err) d.bdRead = false return } func (d *bincDecDriver) decFloatPruned(maxlen uint8) { l := d.d.decRd.readn1() if l > maxlen { d.d.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.d.decRd.readb(d.d.b[0:l]) } func (d *bincDecDriver) decFloatPre32() (b [4]byte) { if d.vs&0x8 == 0 { b = d.d.decRd.readn4() } else { d.decFloatPruned(4) copy(b[:], d.d.b[:]) } return } func (d *bincDecDriver) decFloatPre64() (b [8]byte) { if d.vs&0x8 == 0 { b = d.d.decRd.readn8() } else { d.decFloatPruned(8) copy(b[:], d.d.b[:]) } return } func (d *bincDecDriver) 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 d.d.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) decUint() (v uint64) { switch d.vs { case 0: v = uint64(d.d.decRd.readn1()) case 1: v = uint64(bigen.Uint16(d.d.decRd.readn2())) case 2: v = uint64(bigen.Uint32(d.d.decRd.readn3())) case 3: v = uint64(bigen.Uint32(d.d.decRd.readn4())) case 4, 5, 6: var b [8]byte lim := 7 - d.vs bs := d.d.b[lim:8] d.d.decRd.readb(bs) copy(b[lim:], bs) v = bigen.Uint64(b) case 7: v = bigen.Uint64(d.d.decRd.readn8()) default: d.d.errorf("unsigned integers with greater than 64 bits of precision not supported: d.vs: %v %x", d.vs, d.vs) } return } func (d *bincDecDriver) uintBytes() (bs []byte) { switch d.vs { case 0: bs = d.d.b[:1] bs[0] = d.d.decRd.readn1() case 1: bs = d.d.b[:2] d.d.decRd.readb(bs) case 2: bs = d.d.b[:3] d.d.decRd.readb(bs) case 3: bs = d.d.b[:4] d.d.decRd.readb(bs) case 4, 5, 6: lim := 7 - d.vs bs = d.d.b[lim:8] d.d.decRd.readb(bs) case 7: bs = d.d.b[:8] d.d.decRd.readb(bs) default: d.d.errorf("unsigned integers with greater than 64 bits of precision not supported: d.vs: %v %x", d.vs, d.vs) } return } func (d *bincDecDriver) 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 // d.d.errorf("integer decode has invalid special value %x-%x/%s", d.vd, d.vs, bincdesc(d.vd, d.vs)) } } else { ok = false // d.d.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) 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 // d.d.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) DecodeInt64() (i int64) { if d.advanceNil() { return } i = decNegintPosintFloatNumberHelper{&d.d}.int64(d.decInteger()) d.bdRead = false return } func (d *bincDecDriver) DecodeUint64() (ui uint64) { if d.advanceNil() { return } ui = decNegintPosintFloatNumberHelper{&d.d}.uint64(d.decInteger()) d.bdRead = false return } func (d *bincDecDriver) DecodeFloat64() (f float64) { if d.advanceNil() { return } f = decNegintPosintFloatNumberHelper{&d.d}.float64(d.decFloat()) d.bdRead = false return } func (d *bincDecDriver) DecodeBool() (b bool) { if d.advanceNil() { return } if d.bd == (bincVdSpecial | bincSpFalse) { // b = false } else if d.bd == (bincVdSpecial | bincSpTrue) { b = true } else { d.d.errorf("bool - %s %x-%x/%s", msgBadDesc, d.vd, d.vs, bincdesc(d.vd, d.vs)) } d.bdRead = false return } func (d *bincDecDriver) ReadMapStart() (length int) { if d.advanceNil() { return containerLenNil } if d.vd != bincVdMap { d.d.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) ReadArrayStart() (length int) { if d.advanceNil() { return containerLenNil } if d.vd != bincVdArray { d.d.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) decLen() int { if d.vs > 3 { return int(d.vs - 4) } return int(d.decLenNumber()) } func (d *bincDecDriver) decLenNumber() (v uint64) { if x := d.vs; x == 0 { v = uint64(d.d.decRd.readn1()) } else if x == 1 { v = uint64(bigen.Uint16(d.d.decRd.readn2())) } else if x == 2 { v = uint64(bigen.Uint32(d.d.decRd.readn4())) } else { v = bigen.Uint64(d.d.decRd.readn8()) } return } // func (d *bincDecDriver) decStringBytes(bs []byte, zerocopy bool) (bs2 []byte) { func (d *bincDecDriver) DecodeStringAsBytes() (bs2 []byte) { d.d.decByteState = decByteStateNone if d.advanceNil() { return } var slen = -1 switch d.vd { case bincVdString, bincVdByteArray: slen = d.decLen() if d.d.bytes { d.d.decByteState = decByteStateZerocopy bs2 = d.d.decRd.rb.readx(uint(slen)) } else { d.d.decByteState = decByteStateReuseBuf bs2 = decByteSlice(d.d.r(), slen, d.d.h.MaxInitLen, d.d.b[:]) } 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.d.decRd.readn1()) } else { symbol = uint16(bigen.Uint16(d.d.decRd.readn2())) } if d.s == nil { d.s = make(map[uint16][]byte, 16) } if vs&0x4 == 0 { bs2 = d.s[symbol] } else { switch vs & 0x3 { case 0: slen = int(d.d.decRd.readn1()) case 1: slen = int(bigen.Uint16(d.d.decRd.readn2())) case 2: slen = int(bigen.Uint32(d.d.decRd.readn4())) case 3: slen = int(bigen.Uint64(d.d.decRd.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. bs2 = decByteSlice(d.d.r(), slen, d.d.h.MaxInitLen, nil) d.s[symbol] = bs2 } default: d.d.errorf("string/bytes - %s %x-%x/%s", msgBadDesc, d.vd, d.vs, bincdesc(d.vd, d.vs)) } if d.h.ValidateUnicode && !utf8.Valid(bs2) { d.d.errorf("DecodeStringAsBytes: invalid UTF-8: %s", bs2) } d.bdRead = false return } func (d *bincDecDriver) DecodeBytes(bs []byte) (bsOut []byte) { d.d.decByteState = decByteStateNone if d.advanceNil() { return } if d.vd == bincVdArray { if bs == nil { bs = d.d.b[:] d.d.decByteState = decByteStateReuseBuf } slen := d.ReadArrayStart() var changed bool if bs, changed = usableByteSlice(bs, slen); changed { d.d.decByteState = decByteStateNone } 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))) } return bs } var clen int if d.vd == bincVdString || d.vd == bincVdByteArray { clen = d.decLen() } else { d.d.errorf("bytes - %s %x-%x/%s", msgBadDesc, d.vd, d.vs, bincdesc(d.vd, d.vs)) } d.bdRead = false if d.d.zerocopy() { d.d.decByteState = decByteStateZerocopy return d.d.decRd.rb.readx(uint(clen)) } if bs == nil { bs = d.d.b[:] d.d.decByteState = decByteStateReuseBuf } return decByteSlice(d.d.r(), clen, d.d.h.MaxInitLen, bs) } func (d *bincDecDriver) DecodeExt(rv interface{}, basetype reflect.Type, xtag uint64, ext Ext) { if xtag > 0xff { d.d.errorf("ext: tag must be <= 0xff; got: %v", xtag) } if d.advanceNil() { return } xbs, realxtag1, zerocopy := d.decodeExtV(ext != nil, uint8(xtag)) realxtag := uint64(realxtag1) if ext == nil { re := rv.(*RawExt) re.Tag = realxtag re.setData(xbs, zerocopy) } else if ext == SelfExt { d.d.sideDecode(rv, basetype, xbs) } else { ext.ReadExt(rv, xbs) } } func (d *bincDecDriver) decodeExtV(verifyTag bool, tag byte) (xbs []byte, xtag byte, zerocopy bool) { if d.vd == bincVdCustomExt { l := d.decLen() xtag = d.d.decRd.readn1() if verifyTag && xtag != tag { d.d.errorf("wrong extension tag - got %b, expecting: %v", xtag, tag) } if d.d.bytes { xbs = d.d.decRd.rb.readx(uint(l)) zerocopy = true } else { xbs = decByteSlice(d.d.r(), l, d.d.h.MaxInitLen, d.d.b[:]) } } else if d.vd == bincVdByteArray { xbs = d.DecodeBytes(nil) } else { d.d.errorf("ext expects extensions or byte array - %s %x-%x/%s", msgBadDesc, d.vd, d.vs, bincdesc(d.vd, d.vs)) } d.bdRead = false return } func (d *bincDecDriver) 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: d.d.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.stringZC(d.DecodeStringAsBytes()) case bincVdByteArray: d.d.fauxUnionReadRawBytes(false) case bincVdSymbol: n.v = valueTypeSymbol n.s = d.d.stringZC(d.DecodeStringAsBytes()) case bincVdTimestamp: n.v = valueTypeTime tt, err := bincDecodeTime(d.d.decRd.readx(uint(d.vs))) halt.onerror(err) n.t = tt case bincVdCustomExt: n.v = valueTypeExt l := d.decLen() n.u = uint64(d.d.decRd.readn1()) if d.d.bytes { n.l = d.d.decRd.rb.readx(uint(l)) } else { n.l = decByteSlice(d.d.r(), l, d.d.h.MaxInitLen, d.d.b[:]) } case bincVdArray: n.v = valueTypeArray decodeFurther = true case bincVdMap: n.v = valueTypeMap decodeFurther = true default: d.d.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) nextValueBytes(v0 []byte) (v []byte) { if !d.bdRead { d.readNextBd() } v = v0 var h = decNextValueBytesHelper{d: &d.d} var cursor = d.d.rb.c - 1 h.append1(&v, d.bd) v = d.nextValueBytesBdReadR(v) d.bdRead = false h.bytesRdV(&v, cursor) return } func (d *bincDecDriver) nextValueBytesR(v0 []byte) (v []byte) { d.readNextBd() v = v0 var h = decNextValueBytesHelper{d: &d.d} h.append1(&v, d.bd) return d.nextValueBytesBdReadR(v) } func (d *bincDecDriver) nextValueBytesBdReadR(v0 []byte) (v []byte) { v = v0 var h = decNextValueBytesHelper{d: &d.d} fnLen := func(vs byte) uint { switch vs { case 0: x := d.d.decRd.readn1() h.append1(&v, x) return uint(x) case 1: x := d.d.decRd.readn2() h.appendN(&v, x[:]...) return uint(bigen.Uint16(x)) case 2: x := d.d.decRd.readn4() h.appendN(&v, x[:]...) return uint(bigen.Uint32(x)) case 3: x := d.d.decRd.readn8() h.appendN(&v, x[:]...) 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: d.d.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: bs := d.uintBytes() h.appendN(&v, bs...) case bincVdFloat: fn := func(xlen byte) { if d.vs&0x8 != 0 { xlen = d.d.decRd.readn1() h.append1(&v, xlen) if xlen > 8 { d.d.errorf("cannot read float - at most 8 bytes used to represent float - received %v bytes", xlen) } } d.d.decRd.readb(d.d.b[:xlen]) h.appendN(&v, d.d.b[:xlen]...) } switch d.vs & 0x7 { case bincFlBin32: fn(4) case bincFlBin64: fn(8) default: d.d.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) h.appendN(&v, d.d.decRd.readx(clen)...) case bincVdSymbol: if d.vs&0x8 == 0 { h.append1(&v, d.d.decRd.readn1()) } else { h.appendN(&v, d.d.decRd.rb.readx(2)...) } if d.vs&0x4 != 0 { clen = fnLen(d.vs & 0x3) h.appendN(&v, d.d.decRd.readx(clen)...) } case bincVdTimestamp: h.appendN(&v, d.d.decRd.readx(uint(d.vs))...) case bincVdCustomExt: clen = fnLen(d.vs) h.append1(&v, d.d.decRd.readn1()) // tag h.appendN(&v, d.d.decRd.readx(clen)...) case bincVdArray: clen = fnLen(d.vs) for i := uint(0); i < clen; i++ { v = d.nextValueBytesR(v) } case bincVdMap: clen = fnLen(d.vs) for i := uint(0); i < clen; i++ { v = d.nextValueBytesR(v) v = d.nextValueBytesR(v) } default: d.d.errorf("cannot infer value - %s %x-%x/%s", msgBadDesc, d.vd, d.vs, bincdesc(d.vd, d.vs)) } return } //------------------------------------ // 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 { BasicHandle binaryEncodingType // noElemSeparators // 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) } func (h *BincHandle) newEncDriver() encDriver { var e = &bincEncDriver{h: h} e.e.e = e e.e.init(h) e.reset() return e } func (h *BincHandle) newDecDriver() decDriver { d := &bincDecDriver{h: h} d.d.d = d d.d.init(h) d.reset() return d } // var timeDigits = [...]byte{'0', '1', '2', '3', '4', '5', '6', '7', '8', '9'} // 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 bincEncodeTime(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) btmp := bigen.PutUint16(z) // clear dst flags bs[i] = btmp[0] & 0x3f bs[i+1] = btmp[1] i = i + 2 } bs[0] = bd return bs[0:i] } // bincDecodeTime decodes a []byte into a time.Time. func bincDecodeTime(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 } var _ decDriver = (*bincDecDriver)(nil) var _ encDriver = (*bincEncDriver)(nil) go-1.2.8/codec/build.sh000077500000000000000000000276031435255326100146600ustar00rootroot00000000000000#!/bin/bash # Run all the different permutations of all the tests and other things # This helps ensure that nothing gets broken. _tests() { local vet="" # TODO: make it off local gover=$( ${gocmd} version | cut -f 3 -d ' ' ) [[ $( ${gocmd} version ) == *"gccgo"* ]] && zcover=0 [[ $( ${gocmd} version ) == *"gollvm"* ]] && zcover=0 case $gover in go1.[7-9]*|go1.1[0-9]*|go2.*|devel*) true ;; *) return 1 esac # note that codecgen requires fastpath, so you cannot do "codecgen codec.notfastpath" # we test the following permutations wnich all execute different code paths as below. echo "TestCodecSuite: (fastpath/unsafe), (!fastpath/unsafe), (fastpath/!unsafe), (!fastpath/!unsafe), (codecgen/unsafe)" local echo=1 local nc=2 # count local cpus="1,$(nproc)" # if using the race detector, then set nc to if [[ " ${zargs[@]} " =~ "-race" ]]; then cpus="$(nproc)" fi local a=( "" "codec.notfastpath" "codec.safe" "codec.notfastpath codec.safe" "codecgen" ) local b=() local c=() for i in "${a[@]}" do local i2=${i:-default} [[ "$zwait" == "1" ]] && echo ">>>> TAGS: 'alltests $i'; RUN: 'TestCodecSuite'" [[ "$zcover" == "1" ]] && c=( -coverprofile "${i2// /-}.cov.out" ) true && ${gocmd} vet -printfuncs "errorf" "$@" && if [[ "$echo" == 1 ]]; then set -o xtrace; fi && ${gocmd} test ${zargs[*]} ${ztestargs[*]} -vet "$vet" -tags "alltests $i" -count $nc -cpu $cpus -run "TestCodecSuite" "${c[@]}" "$@" & if [[ "$echo" == 1 ]]; then set +o xtrace; fi b+=("${i2// /-}.cov.out") [[ "$zwait" == "1" ]] && wait # if [[ "$?" != 0 ]]; then return 1; fi done if [[ "$zextra" == "1" ]]; then [[ "$zwait" == "1" ]] && echo ">>>> TAGS: 'codec.notfastpath x'; RUN: 'Test.*X$'" [[ "$zcover" == "1" ]] && c=( -coverprofile "x.cov.out" ) ${gocmd} test ${zargs[*]} ${ztestargs[*]} -vet "$vet" -tags "codec.notfastpath x" -count $nc -run 'Test.*X$' "${c[@]}" & b+=("x.cov.out") [[ "$zwait" == "1" ]] && wait fi wait # go tool cover is not supported for gccgo, gollvm, other non-standard go compilers [[ "$zcover" == "1" ]] && command -v gocovmerge && gocovmerge "${b[@]}" > __merge.cov.out && ${gocmd} tool cover -html=__merge.cov.out } # is a generation needed? _ng() { local a="$1" if [[ ! -e "$a" ]]; then echo 1; return; fi for i in `ls -1 *.go.tmpl gen.go values_test.go` do if [[ "$a" -ot "$i" ]]; then echo 1; return; fi done } _prependbt() { cat > ${2} <> ${2} rm -f ${1} } # _build generates fast-path.go and gen-helper.go. _build() { if ! [[ "${zforce}" || $(_ng "fast-path.generated.go") || $(_ng "gen-helper.generated.go") || $(_ng "gen.generated.go") ]]; then return 0; fi if [ "${zbak}" ]; then _zts=`date '+%m%d%Y_%H%M%S'` _gg=".generated.go" [ -e "gen-helper${_gg}" ] && mv gen-helper${_gg} gen-helper${_gg}__${_zts}.bak [ -e "fast-path${_gg}" ] && mv fast-path${_gg} fast-path${_gg}__${_zts}.bak [ -e "gen${_gg}" ] && mv gen${_gg} gen${_gg}__${_zts}.bak fi rm -f gen-helper.generated.go fast-path.generated.go gen.generated.go \ *safe.generated.go *_generated_test.go *.generated_ffjson_expose.go cat > gen.generated.go <> gen.generated.go < gen-dec-map.go.tmpl cat >> gen.generated.go <> gen.generated.go < gen-dec-array.go.tmpl cat >> gen.generated.go <> gen.generated.go < gen-enc-chan.go.tmpl cat >> gen.generated.go < gen-from-tmpl.codec.generated.go < gen-from-tmpl.sort-slice-stubs.generated.go <> gen-from-tmpl.sort-slice-stubs.generated.go < bench/shared_test.go # explicitly return 0 if this passes, else return 1 local btags="codec.notfastpath codec.safe codecgen.exec" rm -f sort-slice.generated.go fast-path.generated.go gen-helper.generated.go mammoth_generated_test.go mammoth2_generated_test.go cat > gen-from-tmpl.sort-slice.generated.go < gen-from-tmpl.generated.go < $f <>$f if [[ "$i" != "master" ]]; then i="release-branch.go$i"; fi (false || (echo "===== BUILDING GO SDK for branch: $i ... =====" && cd $GOROOT && git checkout -f $i && git reset --hard && git clean -f . && cd src && ./make.bash >>$f 2>&1 && sleep 1 ) ) && echo "===== GO SDK BUILD DONE =====" && _prebuild && echo "===== PREBUILD DONE with exit: $? =====" && _tests "$@" if [[ "$?" != 0 ]]; then return 1; fi done zforce=${makeforce} echo "++++++++ RELEASE TEST SUITES ALL PASSED ++++++++" } _usage() { # hidden args: # -pf [p=prebuild (f=force)] cat < [t=tests (e=extra, s=short, o=cover, w=wait), m=make, n=inlining diagnostics, l=mid-stack inlining, d=race detector] -v -> v=verbose 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 ":cetmnrgpfvldsowkxyzb:" flag do case "x$flag" in 'xo') zcover=1 ;; 'xe') zextra=1 ;; 'xw') zwait=1 ;; 'xf') zforce=1 ;; 'xs') ztestargs+=("-short") ;; 'xv') zverbose+=(1) ;; 'xl') zargs+=("-gcflags"); zargs+=("-l=4") ;; 'xn') zargs+=("-gcflags"); zargs+=("-m=2") ;; 'xd') zargs+=("-race") ;; 'xb') x='b'; 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 "$@" ;; 'xx') _analyze_checks "$@" ;; 'xy') _analyze_debug_types "$@" ;; 'xz') _analyze_do_inlining_and_more "$@" ;; 'xk') _go_compiler_validation_suite ;; 'xb') _bench "$@" ;; esac # unset zforce zargs zbenchflags } [ "." = `dirname $0` ] && _main "$@" go-1.2.8/codec/cbor.go000066400000000000000000000521451435255326100144750ustar00rootroot00000000000000// 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" "reflect" "time" "unicode/utf8" ) // 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 } // ------------------- type cborEncDriver struct { noBuiltInTypes encDriverNoState encDriverNoopContainerWriter h *CborHandle e Encoder } func (e *cborEncDriver) encoder() *Encoder { return &e.e } func (e *cborEncDriver) EncodeNil() { e.e.encWr.writen1(cborBdNil) } func (e *cborEncDriver) EncodeBool(b bool) { if b { e.e.encWr.writen1(cborBdTrue) } else { e.e.encWr.writen1(cborBdFalse) } } func (e *cborEncDriver) EncodeFloat32(f float32) { b := math.Float32bits(f) if e.h.OptimumSize { if h := floatToHalfFloatBits(b); halfFloatToFloatBits(h) == b { e.e.encWr.writen1(cborBdFloat16) bigen.writeUint16(e.e.w(), h) return } } e.e.encWr.writen1(cborBdFloat32) bigen.writeUint32(e.e.w(), b) } func (e *cborEncDriver) EncodeFloat64(f float64) { if e.h.OptimumSize { if f32 := float32(f); float64(f32) == f { e.EncodeFloat32(f32) return } } e.e.encWr.writen1(cborBdFloat64) bigen.writeUint64(e.e.w(), math.Float64bits(f)) } func (e *cborEncDriver) encUint(v uint64, bd byte) { if v <= 0x17 { e.e.encWr.writen1(byte(v) + bd) } else if v <= math.MaxUint8 { e.e.encWr.writen2(bd+0x18, uint8(v)) } else if v <= math.MaxUint16 { e.e.encWr.writen1(bd + 0x19) bigen.writeUint16(e.e.w(), uint16(v)) } else if v <= math.MaxUint32 { e.e.encWr.writen1(bd + 0x1a) bigen.writeUint32(e.e.w(), uint32(v)) } else { // if v <= math.MaxUint64 { e.e.encWr.writen1(bd + 0x1b) bigen.writeUint64(e.e.w(), v) } } func (e *cborEncDriver) EncodeInt(v int64) { if v < 0 { e.encUint(uint64(-1-v), cborBaseNegInt) } else { e.encUint(uint64(v), cborBaseUint) } } func (e *cborEncDriver) EncodeUint(v uint64) { e.encUint(v, cborBaseUint) } func (e *cborEncDriver) encLen(bd byte, length int) { e.encUint(uint64(length), bd) } func (e *cborEncDriver) EncodeTime(t time.Time) { if t.IsZero() { e.EncodeNil() } else if e.h.TimeRFC3339 { e.encUint(0, cborBaseTag) e.encStringBytesS(cborBaseString, t.Format(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) EncodeExt(rv interface{}, basetype reflect.Type, xtag uint64, ext Ext) { e.encUint(uint64(xtag), cborBaseTag) if ext == SelfExt { e.e.encodeValue(baseRV(rv), e.h.fnNoExt(basetype)) } else if v := ext.ConvertExt(rv); v == nil { e.EncodeNil() } else { e.e.encode(v) } } func (e *cborEncDriver) EncodeRawExt(re *RawExt) { e.encUint(uint64(re.Tag), cborBaseTag) // only encodes re.Value (never re.Data) if re.Value != nil { e.e.encode(re.Value) } else { e.EncodeNil() } } func (e *cborEncDriver) WriteArrayStart(length int) { if e.h.IndefiniteLength { e.e.encWr.writen1(cborBdIndefiniteArray) } else { e.encLen(cborBaseArray, length) } } func (e *cborEncDriver) WriteMapStart(length int) { if e.h.IndefiniteLength { e.e.encWr.writen1(cborBdIndefiniteMap) } else { e.encLen(cborBaseMap, length) } } func (e *cborEncDriver) WriteMapEnd() { if e.h.IndefiniteLength { e.e.encWr.writen1(cborBdBreak) } } func (e *cborEncDriver) WriteArrayEnd() { if e.h.IndefiniteLength { e.e.encWr.writen1(cborBdBreak) } } func (e *cborEncDriver) EncodeString(v string) { bb := cborBaseString if e.h.StringToRaw { bb = cborBaseBytes } e.encStringBytesS(bb, v) } func (e *cborEncDriver) EncodeStringBytesRaw(v []byte) { if v == nil { e.EncodeNil() } else { e.encStringBytesS(cborBaseBytes, stringView(v)) } } func (e *cborEncDriver) encStringBytesS(bb byte, v string) { if e.h.IndefiniteLength { if bb == cborBaseBytes { e.e.encWr.writen1(cborBdIndefiniteBytes) } else { e.e.encWr.writen1(cborBdIndefiniteString) } var vlen uint = uint(len(v)) blen := vlen / 4 if blen == 0 { blen = 64 } else if blen > 1024 { blen = 1024 } for i := uint(0); i < vlen; { var v2 string i2 := i + blen if i2 >= i && i2 < vlen { v2 = v[i:i2] } else { v2 = v[i:] } e.encLen(bb, len(v2)) e.e.encWr.writestr(v2) i = i2 } e.e.encWr.writen1(cborBdBreak) } else { e.encLen(bb, len(v)) e.e.encWr.writestr(v) } } // ---------------------- type cborDecDriver struct { decDriverNoopContainerReader decDriverNoopNumberHelper h *CborHandle bdAndBdread st bool // skip tags _ bool // found nil noBuiltInTypes d Decoder } func (d *cborDecDriver) decoder() *Decoder { return &d.d } func (d *cborDecDriver) descBd() string { return sprintf("%v (%s)", d.bd, cbordesc(d.bd)) } func (d *cborDecDriver) readNextBd() { d.bd = d.d.decRd.readn1() d.bdRead = true } func (d *cborDecDriver) 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) 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) skipTags() { for d.bd>>5 == cborMajorTag { d.decUint() d.bd = d.d.decRd.readn1() } } func (d *cborDecDriver) ContainerType() (vt valueType) { if !d.bdRead { d.readNextBd() } if d.st { 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) CheckBreak() (v bool) { if !d.bdRead { d.readNextBd() } if d.bd == cborBdBreak { d.bdRead = false v = true } return } func (d *cborDecDriver) decUint() (ui uint64) { v := d.bd & 0x1f if v <= 0x17 { ui = uint64(v) } else if v == 0x18 { ui = uint64(d.d.decRd.readn1()) } else if v == 0x19 { ui = uint64(bigen.Uint16(d.d.decRd.readn2())) } else if v == 0x1a { ui = uint64(bigen.Uint32(d.d.decRd.readn4())) } else if v == 0x1b { ui = uint64(bigen.Uint64(d.d.decRd.readn8())) } else { d.d.errorf("invalid descriptor decoding uint: %x/%s", d.bd, cbordesc(d.bd)) } return } func (d *cborDecDriver) decLen() int { return int(d.decUint()) } func (d *cborDecDriver) decAppendIndefiniteBytes(bs []byte) []byte { d.bdRead = false for !d.CheckBreak() { if major := d.bd >> 5; major != cborMajorBytes && major != cborMajorString { d.d.errorf("invalid indefinite string/bytes %x (%s); got major %v, expected %v or %v", d.bd, cbordesc(d.bd), major, cborMajorBytes, cborMajorString) } n := uint(d.decLen()) oldLen := uint(len(bs)) newLen := oldLen + n if newLen > uint(cap(bs)) { bs2 := make([]byte, newLen, 2*uint(cap(bs))+n) copy(bs2, bs) bs = bs2 } else { bs = bs[:newLen] } d.d.decRd.readb(bs[oldLen:newLen]) d.bdRead = false } d.bdRead = false return bs } func (d *cborDecDriver) decFloat() (f float64, ok bool) { ok = true switch d.bd { case cborBdFloat16: f = float64(math.Float32frombits(halfFloatToFloatBits(bigen.Uint16(d.d.decRd.readn2())))) case cborBdFloat32: f = float64(math.Float32frombits(bigen.Uint32(d.d.decRd.readn4()))) case cborBdFloat64: f = math.Float64frombits(bigen.Uint64(d.d.decRd.readn8())) default: ok = false } return } func (d *cborDecDriver) 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) DecodeInt64() (i int64) { if d.advanceNil() { return } if d.st { d.skipTags() } i = decNegintPosintFloatNumberHelper{&d.d}.int64(d.decInteger()) d.bdRead = false return } func (d *cborDecDriver) DecodeUint64() (ui uint64) { if d.advanceNil() { return } if d.st { d.skipTags() } ui = decNegintPosintFloatNumberHelper{&d.d}.uint64(d.decInteger()) d.bdRead = false return } func (d *cborDecDriver) DecodeFloat64() (f float64) { if d.advanceNil() { return } if d.st { d.skipTags() } f = decNegintPosintFloatNumberHelper{&d.d}.float64(d.decFloat()) d.bdRead = false return } // bool can be decoded from bool only (single byte). func (d *cborDecDriver) DecodeBool() (b bool) { if d.advanceNil() { return } if d.st { d.skipTags() } if d.bd == cborBdTrue { b = true } else if d.bd == cborBdFalse { } else { d.d.errorf("not bool - %s %x/%s", msgBadDesc, d.bd, cbordesc(d.bd)) } d.bdRead = false return } func (d *cborDecDriver) ReadMapStart() (length int) { if d.advanceNil() { return containerLenNil } if d.st { d.skipTags() } d.bdRead = false if d.bd == cborBdIndefiniteMap { return containerLenUnknown } if d.bd>>5 != cborMajorMap { d.d.errorf("error reading map; got major type: %x, expected %x/%s", d.bd>>5, cborMajorMap, cbordesc(d.bd)) } return d.decLen() } func (d *cborDecDriver) ReadArrayStart() (length int) { if d.advanceNil() { return containerLenNil } if d.st { d.skipTags() } d.bdRead = false if d.bd == cborBdIndefiniteArray { return containerLenUnknown } if d.bd>>5 != cborMajorArray { d.d.errorf("invalid array; got major type: %x, expect: %x/%s", d.bd>>5, cborMajorArray, cbordesc(d.bd)) } return d.decLen() } func (d *cborDecDriver) DecodeBytes(bs []byte) (bsOut []byte) { d.d.decByteState = decByteStateNone if d.advanceNil() { return } if d.st { d.skipTags() } if d.bd == cborBdIndefiniteBytes || d.bd == cborBdIndefiniteString { d.bdRead = false if bs == nil { d.d.decByteState = decByteStateReuseBuf return d.decAppendIndefiniteBytes(d.d.b[:0]) } return d.decAppendIndefiniteBytes(bs[:0]) } if d.bd == cborBdIndefiniteArray { d.bdRead = false if bs == nil { d.d.decByteState = decByteStateReuseBuf bs = d.d.b[:0] } else { bs = bs[:0] } for !d.CheckBreak() { bs = append(bs, uint8(chkOvf.UintV(d.DecodeUint64(), 8))) } return bs } if d.bd>>5 == cborMajorArray { d.bdRead = false if bs == nil { d.d.decByteState = decByteStateReuseBuf bs = d.d.b[:] } slen := d.decLen() var changed bool if bs, changed = usableByteSlice(bs, slen); changed { d.d.decByteState = decByteStateNone } 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))) } return bs } clen := d.decLen() d.bdRead = false if d.d.zerocopy() { d.d.decByteState = decByteStateZerocopy return d.d.decRd.rb.readx(uint(clen)) } if bs == nil { d.d.decByteState = decByteStateReuseBuf bs = d.d.b[:] } return decByteSlice(d.d.r(), clen, d.h.MaxInitLen, bs) } func (d *cborDecDriver) DecodeStringAsBytes() (s []byte) { s = d.DecodeBytes(nil) if d.h.ValidateUnicode && !utf8.Valid(s) { d.d.errorf("DecodeStringAsBytes: invalid UTF-8: %s", s) } return } func (d *cborDecDriver) DecodeTime() (t time.Time) { if d.advanceNil() { return } if d.bd>>5 != cborMajorTag { d.d.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) decodeTime(xtag uint64) (t time.Time) { switch xtag { case 0: var err error t, err = time.Parse(time.RFC3339, stringView(d.DecodeStringAsBytes())) d.d.onerror(err) case 1: f1, f2 := math.Modf(d.DecodeFloat64()) t = time.Unix(int64(f1), int64(f2*1e9)) default: d.d.errorf("invalid tag for time.Time - expecting 0 or 1, got 0x%x", xtag) } t = t.UTC().Round(time.Microsecond) return } func (d *cborDecDriver) DecodeExt(rv interface{}, basetype reflect.Type, xtag uint64, ext Ext) { if d.advanceNil() { return } if d.bd>>5 != cborMajorTag { d.d.errorf("error reading tag; expected major type: %x, got: %x", cborMajorTag, d.bd>>5) } realxtag := d.decUint() d.bdRead = false if ext == nil { re := rv.(*RawExt) re.Tag = realxtag d.d.decode(&re.Value) } else if xtag != realxtag { d.d.errorf("Wrong extension tag. Got %b. Expecting: %v", realxtag, xtag) } else if ext == SelfExt { d.d.decodeValue(baseRV(rv), d.h.fnNoExt(basetype)) } else { d.d.interfaceExtConvertAndDecode(rv, ext) } d.bdRead = false } func (d *cborDecDriver) 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(false) case cborMajorString: n.v = valueTypeString n.s = d.d.stringZC(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() n.l = nil if n.u == 0 || n.u == 1 { d.bdRead = false n.v = valueTypeTime n.t = d.decodeTime(n.u) } else if d.st && 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: d.d.errorf("decodeNaked: Unrecognized d.bd: 0x%x", d.bd) } default: // should never happen d.d.errorf("decodeNaked: Unrecognized d.bd: 0x%x", d.bd) } if !decodeFurther { d.bdRead = false } } func (d *cborDecDriver) 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.d.decRd.readx(1) ui = uint64(v[0]) case 0x19: v = d.d.decRd.readx(2) ui = uint64(bigenstd.Uint16(v)) case 0x1a: v = d.d.decRd.readx(4) ui = uint64(bigenstd.Uint32(v)) case 0x1b: v = d.d.decRd.readx(8) ui = uint64(bigenstd.Uint64(v)) default: if vv > 0x1b { d.d.errorf("invalid descriptor decoding uint: %x/%s", d.bd, cbordesc(d.bd)) } ui = uint64(vv) } return } func (d *cborDecDriver) nextValueBytes(v0 []byte) (v []byte) { if !d.bdRead { d.readNextBd() } v = v0 var h = decNextValueBytesHelper{d: &d.d} var cursor = d.d.rb.c - 1 h.append1(&v, d.bd) v = d.nextValueBytesBdReadR(v) d.bdRead = false h.bytesRdV(&v, cursor) return } func (d *cborDecDriver) nextValueBytesR(v0 []byte) (v []byte) { d.readNextBd() v = v0 var h = decNextValueBytesHelper{d: &d.d} h.append1(&v, d.bd) return d.nextValueBytesBdReadR(v) } func (d *cborDecDriver) nextValueBytesBdReadR(v0 []byte) (v []byte) { v = v0 var h = decNextValueBytesHelper{d: &d.d} var bs []byte var ui uint64 switch d.bd >> 5 { case cborMajorUint, cborMajorNegInt: bs, _ = d.uintBytes() h.appendN(&v, bs...) case cborMajorString, cborMajorBytes: if d.bd == cborBdIndefiniteBytes || d.bd == cborBdIndefiniteString { for { d.readNextBd() h.append1(&v, d.bd) if d.bd == cborBdBreak { break } bs, ui = d.uintBytes() h.appendN(&v, bs...) h.appendN(&v, d.d.decRd.readx(uint(ui))...) } } else { bs, ui = d.uintBytes() h.appendN(&v, bs...) h.appendN(&v, d.d.decRd.readx(uint(ui))...) } case cborMajorArray: if d.bd == cborBdIndefiniteArray { for { d.readNextBd() h.append1(&v, d.bd) if d.bd == cborBdBreak { break } v = d.nextValueBytesBdReadR(v) } } else { bs, ui = d.uintBytes() h.appendN(&v, bs...) for i := uint64(0); i < ui; i++ { v = d.nextValueBytesR(v) } } case cborMajorMap: if d.bd == cborBdIndefiniteMap { for { d.readNextBd() h.append1(&v, d.bd) if d.bd == cborBdBreak { break } v = d.nextValueBytesBdReadR(v) v = d.nextValueBytesR(v) } } else { bs, ui = d.uintBytes() h.appendN(&v, bs...) for i := uint64(0); i < ui; i++ { v = d.nextValueBytesR(v) v = d.nextValueBytesR(v) } } case cborMajorTag: bs, _ = d.uintBytes() h.appendN(&v, bs...) v = d.nextValueBytesR(v) case cborMajorSimpleOrFloat: switch d.bd { case cborBdNil, cborBdUndefined, cborBdFalse, cborBdTrue: // pass case cborBdFloat16: h.appendN(&v, d.d.decRd.readx(2)...) case cborBdFloat32: h.appendN(&v, d.d.decRd.readx(4)...) case cborBdFloat64: h.appendN(&v, d.d.decRd.readx(8)...) default: d.d.errorf("nextValueBytes: Unrecognized d.bd: 0x%x", d.bd) } default: // should never happen d.d.errorf("nextValueBytes: Unrecognized d.bd: 0x%x", d.bd) } 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 // 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) } func (h *CborHandle) newEncDriver() encDriver { var e = &cborEncDriver{h: h} e.e.e = e e.e.init(h) e.reset() return e } func (h *CborHandle) newDecDriver() decDriver { d := &cborDecDriver{h: h, st: h.SkipUnexpectedTags} d.d.d = d d.d.cbor = true d.d.init(h) d.reset() return d } func (d *cborDecDriver) reset() { d.bdAndBdread.reset() d.st = d.h.SkipUnexpectedTags } var _ decDriver = (*cborDecDriver)(nil) var _ encDriver = (*cborEncDriver)(nil) go-1.2.8/codec/cbor_test.go000066400000000000000000000244701435255326100155340ustar00rootroot00000000000000// 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 ( "bufio" "bytes" "encoding/hex" "math" "os" "reflect" "regexp" "strings" "testing" ) func TestCborIndefiniteLength(t *testing.T) { var h Handle = testCborH defer testSetup(t, &h)() bh := testBasicHandle(h) defer func(oldMapType reflect.Type) { bh.MapType = oldMapType }(bh.MapType) bh.MapType = testMapStrIntfTyp // var ( // M1 map[string][]byte // M2 map[uint64]bool // L1 []interface{} // S1 []string // B1 []byte // ) var v, vv interface{} // define it (v), encode it using indefinite lengths, decode it (vv), compare v to vv v = map[string]interface{}{ "one-byte-key": []byte{1, 2, 3, 4, 5, 6}, "two-string-key": "two-value", "three-list-key": []interface{}{true, false, uint64(1), int64(-1)}, } var buf bytes.Buffer // buf.Reset() e := NewEncoder(&buf, h) buf.WriteByte(cborBdIndefiniteMap) //---- buf.WriteByte(cborBdIndefiniteString) e.MustEncode("one-") e.MustEncode("byte-") e.MustEncode("key") buf.WriteByte(cborBdBreak) buf.WriteByte(cborBdIndefiniteBytes) e.MustEncode([]byte{1, 2, 3}) e.MustEncode([]byte{4, 5, 6}) buf.WriteByte(cborBdBreak) //---- buf.WriteByte(cborBdIndefiniteString) e.MustEncode("two-") e.MustEncode("string-") e.MustEncode("key") buf.WriteByte(cborBdBreak) buf.WriteByte(cborBdIndefiniteString) e.MustEncode([]byte("two-")) // encode as bytes, to check robustness of code e.MustEncode([]byte("value")) buf.WriteByte(cborBdBreak) //---- buf.WriteByte(cborBdIndefiniteString) e.MustEncode("three-") e.MustEncode("list-") e.MustEncode("key") buf.WriteByte(cborBdBreak) buf.WriteByte(cborBdIndefiniteArray) e.MustEncode(true) e.MustEncode(false) e.MustEncode(uint64(1)) e.MustEncode(int64(-1)) buf.WriteByte(cborBdBreak) buf.WriteByte(cborBdBreak) // close map NewDecoderBytes(buf.Bytes(), h).MustDecode(&vv) if err := deepEqual(v, vv); err != nil { t.Logf("-------- Before and After marshal do not match: Error: %v", err) if testVerbose { t.Logf(" ....... GOLDEN: (%T) %#v", v, v) t.Logf(" ....... DECODED: (%T) %#v", vv, vv) } t.FailNow() } } type testCborGolden struct { Base64 string `codec:"cbor"` Hex string `codec:"hex"` Roundtrip bool `codec:"roundtrip"` Decoded interface{} `codec:"decoded"` Diagnostic string `codec:"diagnostic"` Skip bool `codec:"skip"` } // Some tests are skipped because they include numbers outside the range of int64/uint64 func TestCborGoldens(t *testing.T) { var h Handle = testCborH defer testSetup(t, &h)() bh := testBasicHandle(h) defer func(oldMapType reflect.Type) { bh.MapType = oldMapType }(bh.MapType) bh.MapType = testMapStrIntfTyp // decode test-cbor-goldens.json into a list of []*testCborGolden // for each one, // - decode hex into []byte bs // - decode bs into interface{} v // - compare both using deepequal // - for any miss, record it var gs []*testCborGolden f, err := os.Open("test-cbor-goldens.json") if err != nil { t.Logf("error opening test-cbor-goldens.json: %v", err) t.FailNow() } defer f.Close() jh := new(JsonHandle) jh.MapType = testMapStrIntfTyp // d := NewDecoder(f, jh) d := NewDecoder(bufio.NewReader(f), jh) // err = d.Decode(&gs) d.MustDecode(&gs) if err != nil { t.Logf("error json decoding test-cbor-goldens.json: %v", err) t.FailNow() } tagregex := regexp.MustCompile(`[\d]+\(.+?\)`) hexregex := regexp.MustCompile(`h'([0-9a-fA-F]*)'`) for i, g := range gs { // fmt.Printf("%v, skip: %v, isTag: %v, %s\n", i, g.Skip, tagregex.MatchString(g.Diagnostic), g.Diagnostic) // skip tags or simple or those with prefix, as we can't verify them. if g.Skip || strings.HasPrefix(g.Diagnostic, "simple(") || tagregex.MatchString(g.Diagnostic) { // fmt.Printf("%v: skipped\n", i) if testVerbose { t.Logf("[%v] skipping because skip=true OR unsupported simple value or Tag Value", i) } continue } // println("++++++++++++", i, "g.Diagnostic", g.Diagnostic) if hexregex.MatchString(g.Diagnostic) { // println(i, "g.Diagnostic matched hex") if s2 := g.Diagnostic[2 : len(g.Diagnostic)-1]; s2 == "" { g.Decoded = zeroByteSlice } else if bs2, err2 := hex.DecodeString(s2); err2 == nil { g.Decoded = bs2 } // fmt.Printf("%v: hex: %v\n", i, g.Decoded) } bs, err := hex.DecodeString(g.Hex) if err != nil { t.Logf("[%v] error hex decoding %s [%v]: %v", i, g.Hex, g.Hex, err) t.FailNow() } var v interface{} NewDecoderBytes(bs, h).MustDecode(&v) if _, ok := v.(RawExt); ok { continue } // check the diagnostics to compare switch g.Diagnostic { case "Infinity": b := math.IsInf(v.(float64), 1) testCborError(t, i, math.Inf(1), v, nil, &b) case "-Infinity": b := math.IsInf(v.(float64), -1) testCborError(t, i, math.Inf(-1), v, nil, &b) case "NaN": // println(i, "checking NaN") b := math.IsNaN(v.(float64)) testCborError(t, i, math.NaN(), v, nil, &b) case "undefined": b := v == nil testCborError(t, i, nil, v, nil, &b) default: v0 := g.Decoded // testCborCoerceJsonNumber(reflect.ValueOf(&v0)) testCborError(t, i, v0, v, deepEqual(v0, v), nil) } } } func testCborError(t *testing.T, i int, v0, v1 interface{}, err error, equal *bool) { if err == nil && equal == nil { // fmt.Printf("%v testCborError passed (err and equal nil)\n", i) return } if err != nil { t.Logf("[%v] deepEqual error: %v", i, err) if testVerbose { t.Logf(" ....... GOLDEN: (%T) %#v", v0, v0) t.Logf(" ....... DECODED: (%T) %#v", v1, v1) } t.FailNow() } if equal != nil && !*equal { t.Logf("[%v] values not equal", i) if testVerbose { t.Logf(" ....... GOLDEN: (%T) %#v", v0, v0) t.Logf(" ....... DECODED: (%T) %#v", v1, v1) } t.FailNow() } // fmt.Printf("%v testCborError passed (checks passed)\n", i) } func TestCborHalfFloat(t *testing.T) { var h Handle = testCborH defer testSetup(t, &h)() m := map[uint16]float64{ // using examples from // https://en.wikipedia.org/wiki/Half-precision_floating-point_format 0x3c00: 1, 0x3c01: 1 + math.Pow(2, -10), 0xc000: -2, 0x7bff: 65504, 0x0400: math.Pow(2, -14), 0x03ff: math.Pow(2, -14) - math.Pow(2, -24), 0x0001: math.Pow(2, -24), 0x0000: 0, 0x8000: -0.0, } var ba [3]byte ba[0] = cborBdFloat16 var res float64 for k, v := range m { res = 0 bigenstd.PutUint16(ba[1:], k) testUnmarshalErr(&res, ba[:3], h, t, "-") if res == v { if testVerbose { t.Logf("equal floats: from %x %b, %v", k, k, v) } } else { t.Logf("unequal floats: from %x %b, %v != %v", k, k, res, v) t.FailNow() } } } func TestCborSkipTags(t *testing.T) { defer testSetup(t, nil)() type Tcbortags struct { A string M map[string]interface{} // A []interface{} } var b8 [8]byte var w bytesEncAppender w.b = []byte{} // To make it easier, // - use tags between math.MaxUint8 and math.MaxUint16 (incl SelfDesc) // - use 1 char strings for key names // - use 3-6 char strings for map keys // - use integers that fit in 2 bytes (between 0x20 and 0xff) var tags = [...]uint64{math.MaxUint8 * 2, math.MaxUint8 * 8, 55799, math.MaxUint16 / 2} var tagIdx int var doAddTag bool addTagFn8To16 := func() { if !doAddTag { return } // writes a tag between MaxUint8 and MaxUint16 (culled from cborEncDriver.encUint) w.writen1(cborBaseTag + 0x19) // bigenHelper.writeUint16 bigenstd.PutUint16(b8[:2], uint16(tags[tagIdx%len(tags)])) w.writeb(b8[:2]) tagIdx++ } var v Tcbortags v.A = "cbor" v.M = make(map[string]interface{}) v.M["111"] = uint64(111) v.M["111.11"] = 111.11 v.M["true"] = true // v.A = append(v.A, 222, 22.22, "true") // make stream manually (interspacing tags around it) // WriteMapStart - e.encLen(cborBaseMap, length) - encUint(length, bd) // EncodeStringEnc - e.encStringBytesS(cborBaseString, v) fnEncode := func() { w.b = w.b[:0] addTagFn8To16() // write v (Tcbortags, with 3 fields = map with 3 entries) w.writen1(2 + cborBaseMap) // 3 fields = 3 entries // write v.A var s = "A" w.writen1(byte(len(s)) + cborBaseString) w.writestr(s) w.writen1(byte(len(v.A)) + cborBaseString) w.writestr(v.A) //w.writen1(0) addTagFn8To16() s = "M" w.writen1(byte(len(s)) + cborBaseString) w.writestr(s) addTagFn8To16() w.writen1(byte(len(v.M)) + cborBaseMap) addTagFn8To16() s = "111" w.writen1(byte(len(s)) + cborBaseString) w.writestr(s) w.writen2(cborBaseUint+0x18, uint8(111)) addTagFn8To16() s = "111.11" w.writen1(byte(len(s)) + cborBaseString) w.writestr(s) w.writen1(cborBdFloat64) bigenstd.PutUint64(b8[:8], math.Float64bits(111.11)) w.writeb(b8[:8]) addTagFn8To16() s = "true" w.writen1(byte(len(s)) + cborBaseString) w.writestr(s) w.writen1(cborBdTrue) } var h CborHandle h.SkipUnexpectedTags = true h.Canonical = true var gold []byte NewEncoderBytes(&gold, &h).MustEncode(v) // xdebug2f("encoded: gold: %v", gold) // w.b is the encoded bytes var v2 Tcbortags doAddTag = false fnEncode() // xdebug2f("manual: no-tags: %v", w.b) testDeepEqualErr(gold, w.b, t, "cbor-skip-tags--bytes---") NewDecoderBytes(w.b, &h).MustDecode(&v2) testDeepEqualErr(v, v2, t, "cbor-skip-tags--no-tags-") var v3 Tcbortags doAddTag = true fnEncode() // xdebug2f("manual: has-tags: %v", w.b) NewDecoderBytes(w.b, &h).MustDecode(&v3) testDeepEqualErr(v, v2, t, "cbor-skip-tags--has-tags") // Github 300 - tests naked path { expected := []interface{}{"x", uint64(0x0)} toDecode := []byte{0x82, 0x61, 0x78, 0x00} var raw interface{} NewDecoderBytes(toDecode, &h).MustDecode(&raw) testDeepEqualErr(expected, raw, t, "cbor-skip-tags--gh-300---no-skips") toDecode = []byte{0xd9, 0xd9, 0xf7, 0x82, 0x61, 0x78, 0x00} raw = nil NewDecoderBytes(toDecode, &h).MustDecode(&raw) testDeepEqualErr(expected, raw, t, "cbor-skip-tags--gh-300--has-skips") } } func TestCborMalformed(t *testing.T) { if !testRecoverPanicToErr { t.Skip(testSkipIfNotRecoverPanicToErrMsg) } var h Handle = testCborH defer testSetup(t, &h)() var bad = [][]byte{ []byte("\x9b\x00\x00000000"), []byte("\x9b\x00\x00\x81112233"), } var out interface{} for _, v := range bad { out = nil err := testUnmarshal(&out, v, h) if err == nil { t.Logf("missing expected error decoding malformed cbor") t.FailNow() } } } go-1.2.8/codec/codec_test.go000066400000000000000000004321201435255326100156570ustar00rootroot00000000000000// 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 // NAMING CONVENTION FOR TESTS // // function and variable/const names here fit a simple naming convention // // - each test is a doTestXXX(...). TestXXX calls doTestXXX. // - testXXX are helper functions. // - doTestXXX are test functions that take an extra arg of a handle. // - testXXX variables and constants are only used in tests. // - shared functions/vars/consts are testShared... // - fnBenchmarkXX and fnTestXXX can be used as needed. // // - each TestXXX must only call testSetup once. // - each test with a prefix __doTest is a dependent helper function, // which MUST not call testSetup itself. // doTestXXX or TestXXX may call it. // if we are testing in parallel, // then we don't want to share much state: testBytesFreeList, etc. import ( "bufio" "bytes" "encoding/gob" "errors" "fmt" "io" "io/ioutil" "math" "math/rand" "net" "net/rpc" "os" "os/exec" "path/filepath" "reflect" "strconv" "strings" "sync/atomic" "testing" "time" ) func init() { testPreInitFns = append(testPreInitFns, testInit) } const testRecoverPanicToErr = !debugging // tests which check for errors will fail if testRecoverPanicToErr=false (debugging=true). // Consequently, skip them. var testSkipIfNotRecoverPanicToErrMsg = "tests checks for errors, and testRecoverPanicToErr=false" func testPanicToErr(h errDecorator, err *error) { // Note: This method MUST be called directly from defer i.e. defer testPanicToErr ... // else it seems the recover is not fully handled if x := recover(); x != nil { panicValToErr(h, x, err) } } var testBytesFreeList bytesFreelist type testCustomStringT string // make these mapbyslice type testMbsT []interface{} type testMbsArr0T [0]interface{} type testMbsArr4T [4]interface{} type testMbsArr5T [5]interface{} type testMbsCustStrT []testCustomStringT func (testMbsT) MapBySlice() {} func (*testMbsArr0T) MapBySlice() {} func (*testMbsArr4T) MapBySlice() {} func (testMbsArr5T) MapBySlice() {} func (testMbsCustStrT) MapBySlice() {} // type testSelferRecur struct{} // func (s *testSelferRecur) CodecEncodeSelf(e *Encoder) { // e.MustEncode(s) // } // func (s *testSelferRecur) CodecDecodeSelf(d *Decoder) { // d.MustDecode(s) // } type testIntfMapI interface { GetIntfMapV() string } type testIntfMapT1 struct { IntfMapV string } func (x *testIntfMapT1) GetIntfMapV() string { return x.IntfMapV } type testIntfMapT2 struct { IntfMapV string } func (x testIntfMapT2) GetIntfMapV() string { return x.IntfMapV } type testMissingFieldsMap struct { m map[string]interface{} } func (mf *testMissingFieldsMap) CodecMissingField(field []byte, value interface{}) bool { if mf.m == nil { mf.m = map[string]interface{}{} } (mf.m)[string(field)] = value return true } func (mf *testMissingFieldsMap) CodecMissingFields() map[string]interface{} { return mf.m } var _ MissingFielder = (*testMissingFieldsMap)(nil) var testErrWriterErr = errors.New("testErrWriterErr") type testErrWriter struct{} func (x *testErrWriter) Write(p []byte) (int, error) { return 0, testErrWriterErr } // ---- type testVerifyFlag uint8 const ( _ testVerifyFlag = 1 << iota testVerifyMapTypeSame testVerifyMapTypeStrIntf testVerifyMapTypeIntfIntf // testVerifySliceIntf testVerifyForPython testVerifyDoNil testVerifyTimeAsInteger ) func (f testVerifyFlag) isset(v testVerifyFlag) bool { return f&v == v } // const testSkipRPCTests = false var ( testTableNumPrimitives int testTableIdxTime int testTableNumMaps int // set this when running using bufio, etc testSkipRPCTests = false testSkipRPCTestsMsg = "testSkipRPCTests=true" ) var ( skipVerifyVal interface{} = &(struct{}{}) testMapStrIntfTyp = reflect.TypeOf(map[string]interface{}(nil)) // 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. timeLoc = time.FixedZone("", -8*60*60) // UTC-08:00 //time.UTC-8 timeToCompare1 = time.Date(2012, 2, 2, 2, 2, 2, 2000, timeLoc).UTC() timeToCompare2 = time.Date(1900, 2, 2, 2, 2, 2, 2000, timeLoc).UTC() timeToCompare3 = time.Unix(0, 270).UTC() // use value that must be encoded as uint64 for nanoseconds (for cbor/msgpack comparison) //timeToCompare4 = time.Time{}.UTC() // does not work well with simple cbor time encoding (overflow) timeToCompare4 = time.Unix(-2013855848, 4223).UTC() table []interface{} // main items we encode // will encode a float32 as float64, or large int as uint testRpcServer = rpc.NewServer() testRpcInt = new(TestRpcInt) ) func init() { testRpcServer.Register(testRpcInt) } var wrapInt64Typ = reflect.TypeOf(wrapInt64(0)) var wrapBytesTyp = reflect.TypeOf(wrapBytes(nil)) var testUintToBytesTyp = reflect.TypeOf(testUintToBytes(0)) var testSelfExtTyp = reflect.TypeOf((*TestSelfExtImpl)(nil)).Elem() var testSelfExt2Typ = reflect.TypeOf((*TestSelfExtImpl2)(nil)).Elem() func testByteBuf(in []byte) *bytes.Buffer { return bytes.NewBuffer(in) } type TestABC struct { A, B, C string } func (x *TestABC) MarshalBinary() ([]byte, error) { return []byte(fmt.Sprintf("%s %s %s", x.A, x.B, x.C)), nil } func (x *TestABC) MarshalText() ([]byte, error) { return []byte(fmt.Sprintf("%s %s %s", x.A, x.B, x.C)), nil } func (x *TestABC) MarshalJSON() ([]byte, error) { return []byte(fmt.Sprintf(`"%s %s %s"`, x.A, x.B, x.C)), nil } func (x *TestABC) UnmarshalBinary(data []byte) (err error) { ss := strings.Split(string(data), " ") x.A, x.B, x.C = ss[0], ss[1], ss[2] return } func (x *TestABC) UnmarshalText(data []byte) (err error) { return x.UnmarshalBinary(data) } func (x *TestABC) UnmarshalJSON(data []byte) (err error) { return x.UnmarshalBinary(data[1 : len(data)-1]) } type TestABC2 struct { A, B, C string } func (x TestABC2) MarshalText() ([]byte, error) { return []byte(fmt.Sprintf("%s %s %s", x.A, x.B, x.C)), nil } func (x *TestABC2) UnmarshalText(data []byte) (err error) { ss := strings.Split(string(data), " ") x.A, x.B, x.C = ss[0], ss[1], ss[2] return // _, err = fmt.Sscanf(string(data), "%s %s %s", &x.A, &x.B, &x.C) } type TestSimplish struct { Ii int Ss string Ar [2]*TestSimplish Sl []*TestSimplish Mm map[string]*TestSimplish } type TestRpcABC struct { A, B, C string } type TestRpcInt struct { i int64 } func (r *TestRpcInt) Update(n int, res *int) error { atomic.StoreInt64(&r.i, int64(n)) *res = n return nil } func (r *TestRpcInt) Square(ignore int, res *int) error { i := int(atomic.LoadInt64(&r.i)) *res = i * i return nil } func (r *TestRpcInt) Mult(n int, res *int) error { *res = int(atomic.LoadInt64(&r.i)) * n return nil } func (r *TestRpcInt) EchoStruct(arg TestRpcABC, res *string) error { *res = fmt.Sprintf("%#v", arg) return nil } func (r *TestRpcInt) Echo123(args []string, res *string) error { *res = fmt.Sprintf("%#v", args) return nil } type TestRawValue struct { R Raw I int } // ---- type testUnixNanoTimeExt struct { // keep timestamp here, so that do not incur interface-conversion costs // ts int64 } func (x *testUnixNanoTimeExt) WriteExt(v interface{}) []byte { v2 := v.(*time.Time) bs := make([]byte, 8) bigenstd.PutUint64(bs, uint64(v2.UnixNano())) return bs } func (x *testUnixNanoTimeExt) ReadExt(v interface{}, bs []byte) { v2 := v.(*time.Time) ui := bigenstd.Uint64(bs) *v2 = time.Unix(0, int64(ui)).UTC() } type testUnixNanoTimeInterfaceExt struct{} func (x testUnixNanoTimeInterfaceExt) ConvertExt(v interface{}) interface{} { v2 := v.(*time.Time) // structs are encoded by passing the ptr return v2.UTC().UnixNano() } func (x testUnixNanoTimeInterfaceExt) UpdateExt(dest interface{}, v interface{}) { tt := dest.(*time.Time) *tt = time.Unix(0, v.(int64)).UTC() // switch v2 := v.(type) { // case int64: // *tt = time.Unix(0, v2).UTC() // case uint64: // *tt = time.Unix(0, int64(v2)).UTC() // //case float64: // //case string: // default: // panic(fmt.Errorf("unsupported format for time conversion: expecting int64/uint64; got %T", v)) // } } // ---- type wrapInt64Ext int64 func (x *wrapInt64Ext) WriteExt(v interface{}) []byte { v2 := uint64(int64(v.(wrapInt64))) bs := make([]byte, 8) bigenstd.PutUint64(bs, v2) return bs } func (x *wrapInt64Ext) ReadExt(v interface{}, bs []byte) { v2 := v.(*wrapInt64) ui := bigenstd.Uint64(bs) *v2 = wrapInt64(int64(ui)) } func (x *wrapInt64Ext) ConvertExt(v interface{}) interface{} { return int64(v.(wrapInt64)) } func (x *wrapInt64Ext) UpdateExt(dest interface{}, v interface{}) { v2 := dest.(*wrapInt64) *v2 = wrapInt64(v.(int64)) } // ---- type wrapBytesExt struct{} func (x *wrapBytesExt) WriteExt(v interface{}) []byte { return ([]byte)(v.(wrapBytes)) } func (x *wrapBytesExt) ReadExt(v interface{}, bs []byte) { v2 := v.(*wrapBytes) *v2 = wrapBytes(bs) } func (x *wrapBytesExt) ConvertExt(v interface{}) interface{} { return ([]byte)(v.(wrapBytes)) } func (x *wrapBytesExt) UpdateExt(dest interface{}, v interface{}) { v2 := dest.(*wrapBytes) // some formats (e.g. json) cannot nakedly determine []byte from string, so expect both switch v3 := v.(type) { case []byte: *v2 = wrapBytes(v3) case string: *v2 = wrapBytes([]byte(v3)) default: panic(errors.New("UpdateExt for wrapBytesExt expects string or []byte")) } // *v2 = wrapBytes(v.([]byte)) } // ---- // timeExt is an extension handler for time.Time, that uses binc model for encoding/decoding time. // we used binc model, as that is the only custom time representation that we designed ourselves. type timeBytesExt struct{} func (x timeBytesExt) WriteExt(v interface{}) (bs []byte) { return bincEncodeTime(*(v.(*time.Time))) // return bincEncodeTime(v.(time.Time)) // switch v2 := v.(type) { // case time.Time: // bs = bincEncodeTime(v2) // case *time.Time: // bs = bincEncodeTime(*v2) // default: // panic(fmt.Errorf("unsupported format for time conversion: expecting time.Time; got %T", v2)) // } // return } func (x timeBytesExt) ReadExt(v interface{}, bs []byte) { tt, err := bincDecodeTime(bs) if err != nil { panic(err) } *(v.(*time.Time)) = tt } type timeInterfaceExt struct{} func (x timeInterfaceExt) ConvertExt(v interface{}) interface{} { return timeBytesExt{}.WriteExt(v) } func (x timeInterfaceExt) UpdateExt(v interface{}, src interface{}) { timeBytesExt{}.ReadExt(v, src.([]byte)) } // ---- type testUintToBytesExt struct{} func (x testUintToBytesExt) WriteExt(v interface{}) (bs []byte) { z := uint32(v.(testUintToBytes)) if z == 0 { return nil } return make([]byte, z) } func (x testUintToBytesExt) ReadExt(v interface{}, bs []byte) { *(v.(*testUintToBytes)) = testUintToBytes(len(bs)) } func (x testUintToBytesExt) ConvertExt(v interface{}) interface{} { return x.WriteExt(v) } func (x testUintToBytesExt) UpdateExt(v interface{}, src interface{}) { x.ReadExt(v, src.([]byte)) } // ---- func testSetupNoop() {} func testSetup(t *testing.T, h *Handle) (fn func()) { return testSetupWithChecks(t, h, true) } // testSetup will ensure testInitAll is run, and then // return a function that should be deferred to run at the end // of the test. // // This function can track how much time a test took, // or recover from panic's and fail the test appropriately. func testSetupWithChecks(t *testing.T, h *Handle, allowParallel bool) (fn func()) { testOnce.Do(testInitAll) if allowParallel && testUseParallel { t.Parallel() if h != nil { *h = testHandleCopy(*h) } } // in case an error is seen, recover it here. if testRecoverPanicToErr { fnRecoverPanic := func() { if x := recover(); x != nil { var err error panicValToErr(errDecoratorDef{}, x, &err) t.Logf("recovered error: %v", err) t.FailNow() } } fn = fnRecoverPanic } if fn == nil { fn = testSetupNoop } return } func testBasicHandle(h Handle) *BasicHandle { return h.getBasicHandle() } func testCodecEncode(ts interface{}, bsIn []byte, fn func([]byte) *bytes.Buffer, h Handle, useMust bool) (bs []byte, err error) { return testSharedCodecEncode(ts, bsIn, fn, h, testBasicHandle(h), useMust) } func testCodecDecode(bs []byte, ts interface{}, h Handle, useMust bool) (err error) { return testSharedCodecDecode(bs, ts, h, testBasicHandle(h), useMust) } func testCheckErr(t *testing.T, err error) { if err != nil { t.Logf("err: %v", err) t.FailNow() } } func testCheckEqual(t *testing.T, v1 interface{}, v2 interface{}, desc string) { t.Helper() if err := deepEqual(v1, v2); err != nil { t.Logf("Not Equal: %s: %v", desc, err) if testVerbose { t.Logf("\tv1: %v, v2: %v", v1, v2) } t.FailNow() } } func testInit() { gob.Register(new(TestStrucFlex)) for _, v := range testHandles { bh := testBasicHandle(v) bh.clearInited() // so it is reinitialized next time around // pre-fill them first bh.EncodeOptions = testEncodeOptions bh.DecodeOptions = testDecodeOptions bh.RPCOptions = testRPCOptions // bh.InterfaceReset = true // bh.PreferArrayOverSlice = true // modify from flag'ish things bh.MaxInitLen = testMaxInitLen } var tTimeExt timeBytesExt var tBytesExt wrapBytesExt var tI64Ext wrapInt64Ext var tUintToBytesExt testUintToBytesExt // create legacy functions suitable for deprecated AddExt functionality, // and use on some places for testSimpleH e.g. for time.Time and wrapInt64 var ( myExtEncFn = func(x BytesExt, rv reflect.Value) (bs []byte, err error) { defer testPanicToErr(errDecoratorDef{}, &err) bs = x.WriteExt(rv.Interface()) return } myExtDecFn = func(x BytesExt, rv reflect.Value, bs []byte) (err error) { defer testPanicToErr(errDecoratorDef{}, &err) x.ReadExt(rv.Interface(), bs) return } timeExtEncFn = func(rv reflect.Value) (bs []byte, err error) { return myExtEncFn(tTimeExt, rv) } timeExtDecFn = func(rv reflect.Value, bs []byte) (err error) { return myExtDecFn(tTimeExt, rv, bs) } wrapInt64ExtEncFn = func(rv reflect.Value) (bs []byte, err error) { return myExtEncFn(&tI64Ext, rv) } wrapInt64ExtDecFn = func(rv reflect.Value, bs []byte) (err error) { return myExtDecFn(&tI64Ext, rv, bs) } ) chkErr := func(err error) { if err != nil { panic(err) } } // time.Time is a native type, so extensions will have no effect. // However, we add these here to ensure nothing happens. chkErr(testSimpleH.AddExt(timeTyp, 1, timeExtEncFn, timeExtDecFn)) // testBincH.SetBytesExt(timeTyp, 1, timeExt{}) // time is builtin for binc chkErr(testMsgpackH.SetBytesExt(timeTyp, 1, timeBytesExt{})) chkErr(testCborH.SetInterfaceExt(timeTyp, 1, testUnixNanoTimeInterfaceExt{})) // testJsonH.SetInterfaceExt(timeTyp, 1, &testUnixNanoTimeExt{}) // Add extensions for the testSelfExt chkErr(testSimpleH.SetBytesExt(testSelfExtTyp, 78, SelfExt)) chkErr(testMsgpackH.SetBytesExt(testSelfExtTyp, 78, SelfExt)) chkErr(testBincH.SetBytesExt(testSelfExtTyp, 78, SelfExt)) chkErr(testJsonH.SetInterfaceExt(testSelfExtTyp, 78, SelfExt)) chkErr(testCborH.SetInterfaceExt(testSelfExtTyp, 78, SelfExt)) chkErr(testSimpleH.SetBytesExt(testSelfExt2Typ, 79, SelfExt)) chkErr(testMsgpackH.SetBytesExt(testSelfExt2Typ, 79, SelfExt)) chkErr(testBincH.SetBytesExt(testSelfExt2Typ, 79, SelfExt)) chkErr(testJsonH.SetInterfaceExt(testSelfExt2Typ, 79, SelfExt)) chkErr(testCborH.SetInterfaceExt(testSelfExt2Typ, 79, SelfExt)) // Now, add extensions for the type wrapInt64 and wrapBytes, // so we can execute the Encode/Decode Ext paths. chkErr(testSimpleH.SetBytesExt(wrapBytesTyp, 32, &tBytesExt)) chkErr(testMsgpackH.SetBytesExt(wrapBytesTyp, 32, &tBytesExt)) chkErr(testBincH.SetBytesExt(wrapBytesTyp, 32, &tBytesExt)) chkErr(testJsonH.SetInterfaceExt(wrapBytesTyp, 32, &tBytesExt)) chkErr(testCborH.SetInterfaceExt(wrapBytesTyp, 32, &tBytesExt)) chkErr(testSimpleH.SetBytesExt(testUintToBytesTyp, 33, &tUintToBytesExt)) chkErr(testMsgpackH.SetBytesExt(testUintToBytesTyp, 33, &tUintToBytesExt)) chkErr(testBincH.SetBytesExt(testUintToBytesTyp, 33, &tUintToBytesExt)) chkErr(testJsonH.SetInterfaceExt(testUintToBytesTyp, 33, &tUintToBytesExt)) chkErr(testCborH.SetInterfaceExt(testUintToBytesTyp, 33, &tUintToBytesExt)) chkErr(testSimpleH.AddExt(wrapInt64Typ, 16, wrapInt64ExtEncFn, wrapInt64ExtDecFn)) // chkErr(testSimpleH.SetBytesExt(wrapInt64Typ, 16, &tI64Ext)) chkErr(testMsgpackH.SetBytesExt(wrapInt64Typ, 16, &tI64Ext)) chkErr(testBincH.SetBytesExt(wrapInt64Typ, 16, &tI64Ext)) chkErr(testJsonH.SetInterfaceExt(wrapInt64Typ, 16, &tI64Ext)) chkErr(testCborH.SetInterfaceExt(wrapInt64Typ, 16, &tI64Ext)) // primitives MUST be an even number, so it can be used as a mapBySlice also. primitives := []interface{}{ int8(-8), int16(-1616), int32(-32323232), int64(-6464646464646464), uint8(192), uint16(1616), uint32(32323232), uint64(6464646464646464), byte(192), float32(-3232.0), float64(-6464646464.0), float32(3232.0), float64(6464.0), float64(6464646464.0), complex64(complex(160.0, 0)), complex128(complex(1616, 0)), false, true, "null", nil, "some&day>some lp { // testTableNumPrimitives+1 is the mapBySlice av[i] = skipVerifyVal continue } av[i] = testVerifyVal(v, f, h) } // only do the python verify up to the maps, skipping the last 2 maps. av = av[:testTableNumPrimitives+2+testTableNumMaps-2] case f.isset(testVerifyDoNil): for i, v := range table { if i > lp { av[i] = skipVerifyVal continue } av[i] = testVerifyVal(v, f, h) } default: for i, v := range table { if i == lp { av[i] = skipVerifyVal continue } //av[i] = testVerifyVal(v, testVerifyMapTypeSame) switch v.(type) { case []interface{}: av[i] = testVerifyVal(v, f, h) case testMbsT: av[i] = testVerifyVal(v, f, h) case map[string]interface{}: av[i] = testVerifyVal(v, f, h) case map[interface{}]interface{}: av[i] = testVerifyVal(v, f, h) case time.Time: av[i] = testVerifyVal(v, f, h) default: av[i] = v } } } return } func testVerifyValInt(v int64, isMsgp bool) (v2 interface{}) { if isMsgp { if v >= 0 && v <= 127 { v2 = uint64(v) } else { v2 = int64(v) } } else if v >= 0 { v2 = uint64(v) } else { v2 = int64(v) } return } func testVerifyVal(v interface{}, f testVerifyFlag, h Handle) (v2 interface{}) { //for python msgpack, // - all positive integers are unsigned 64-bit ints // - all floats are float64 _, isMsgp := h.(*MsgpackHandle) _, isCbor := h.(*CborHandle) switch iv := v.(type) { case int8: v2 = testVerifyValInt(int64(iv), isMsgp) // fmt.Printf(">>>> is msgp: %v, v: %T, %v ==> v2: %T, %v\n", isMsgp, v, v, v2, v2) case int16: v2 = testVerifyValInt(int64(iv), isMsgp) case int32: v2 = testVerifyValInt(int64(iv), isMsgp) case int64: v2 = testVerifyValInt(int64(iv), isMsgp) case uint8: v2 = uint64(iv) case uint16: v2 = uint64(iv) case uint32: v2 = uint64(iv) case uint64: v2 = uint64(iv) case float32: v2 = float64(iv) case float64: v2 = float64(iv) case complex64: v2 = float64(float32(real(iv))) case complex128: v2 = float64(real(iv)) case []interface{}: m2 := make([]interface{}, len(iv)) for j, vj := range iv { m2[j] = testVerifyVal(vj, f, h) } v2 = m2 case testMbsT: m2 := make([]interface{}, len(iv)) for j, vj := range iv { m2[j] = testVerifyVal(vj, f, h) } v2 = testMbsT(m2) case map[string]bool: switch { case f.isset(testVerifyMapTypeSame): m2 := make(map[string]bool) for kj, kv := range iv { m2[kj] = kv } v2 = m2 case f.isset(testVerifyMapTypeStrIntf): m2 := make(map[string]interface{}) for kj, kv := range iv { m2[kj] = kv } v2 = m2 case f.isset(testVerifyMapTypeIntfIntf): m2 := make(map[interface{}]interface{}) for kj, kv := range iv { m2[kj] = kv } v2 = m2 } case map[string]interface{}: switch { case f.isset(testVerifyMapTypeSame): m2 := make(map[string]interface{}) for kj, kv := range iv { m2[kj] = testVerifyVal(kv, f, h) } v2 = m2 case f.isset(testVerifyMapTypeStrIntf): m2 := make(map[string]interface{}) for kj, kv := range iv { m2[kj] = testVerifyVal(kv, f, h) } v2 = m2 case f.isset(testVerifyMapTypeIntfIntf): m2 := make(map[interface{}]interface{}) for kj, kv := range iv { m2[kj] = testVerifyVal(kv, f, h) } v2 = m2 } case map[interface{}]interface{}: m2 := make(map[interface{}]interface{}) for kj, kv := range iv { m2[testVerifyVal(kj, f, h)] = testVerifyVal(kv, f, h) } v2 = m2 case time.Time: switch { case f.isset(testVerifyTimeAsInteger): if iv2 := iv.UnixNano(); iv2 >= 0 { v2 = uint64(iv2) } else { v2 = int64(iv2) } case isMsgp: v2 = iv.UTC() case isCbor: // fmt.Printf("%%%% cbor verifier\n") v2 = iv.UTC().Round(time.Microsecond) default: v2 = v } default: v2 = v } return } func testReleaseBytes(bs []byte) { if !testUseParallel { testBytesFreeList.put(bs) } } func testGetBytes() (bs []byte) { if !testUseParallel { bs = testBytesFreeList.get(64) } return } func testHandleCopy(h Handle) (h2 Handle) { switch v := h.(type) { case *JsonHandle: v2 := *v h2 = &v2 case *CborHandle: v2 := *v h2 = &v2 case *MsgpackHandle: v2 := *v h2 = &v2 case *SimpleHandle: v2 := *v h2 = &v2 case *BincHandle: v2 := *v h2 = &v2 } return } func testMarshal(v interface{}, h Handle) (bs []byte, err error) { // return testCodecEncode(v, nil, testByteBuf, h) return testCodecEncode(v, testGetBytes(), testByteBuf, h, false) } func testUnmarshal(v interface{}, data []byte, h Handle) (err error) { return testCodecDecode(data, v, h, false) } func testMarshalErr(v interface{}, h Handle, t *testing.T, name string) (bs []byte) { t.Helper() bs, err := testCodecEncode(v, testGetBytes(), testByteBuf, h, true) if err != nil { t.Logf("%s: marshal failed: %v", name, err) if testVerbose { t.Logf("Error encoding %s: %v, Err: %v", name, v, err) } t.FailNow() } return } func testUnmarshalErr(v interface{}, data []byte, h Handle, t *testing.T, name string) { t.Helper() err := testCodecDecode(data, v, h, true) if err != nil { t.Logf("%s: unmarshal failed: %v", name, err) if testVerbose { t.Logf("Error Decoding into %s: %v, Err: %v", name, v, err) } t.FailNow() } } func testDeepEqualErr(v1, v2 interface{}, t *testing.T, name string) { t.Helper() if err := deepEqual(v1, v2); err == nil { if testVerbose { t.Logf("%s: values equal", name) } } else { t.Logf("%s: values not equal: %v", name, err) if testVerbose { t.Logf("%s: values not equal: %v. 1: %#v, 2: %#v", name, err, v1, v2) } t.FailNow() } } func testReadWriteCloser(c io.ReadWriteCloser) io.ReadWriteCloser { if testRpcBufsize <= 0 && rand.Int63()%2 == 0 { return c } return struct { io.Closer *bufio.Reader *bufio.Writer }{c, bufio.NewReaderSize(c, testRpcBufsize), bufio.NewWriterSize(c, testRpcBufsize)} } // testCodecTableOne allows us test for different variations based on arguments passed. func testCodecTableOne(t *testing.T, testNil bool, h Handle, vs []interface{}, vsVerify []interface{}) { //if testNil, then just test for when a pointer to a nil interface{} is passed. It should work. //Current setup allows us test (at least manually) the nil interface or typed interface. if testVerbose { t.Logf("================ TestNil: %v: %v entries ================\n", testNil, len(vs)) } if mh, ok := h.(*MsgpackHandle); ok { defer func(a, b bool) { mh.RawToString = a mh.PositiveIntUnsigned = b }(mh.RawToString, mh.PositiveIntUnsigned) mh.RawToString = true mh.PositiveIntUnsigned = false } bh := testBasicHandle(h) for i, v0 := range vs { if testVerbose { t.Logf("..............................................") t.Logf(" Testing: #%d:, %T, %#v\n", i, v0, v0) } // if a TestStrucFlex and we are doing a testNil, // ensure the fields which are not encodeable are set to nil appropriately // i.e. TestStrucFlex.{MstrUi64TSelf, mapMsu2wss} var mapMstrUi64TSelf map[stringUint64T]*stringUint64T var mapMsu2wss map[stringUint64T]wrapStringSlice // TestStrucFlex.{Msp2ss, Mip2ss} have pointer keys. // When we encode and the decode back into the same value, // the length of this map will effectively double, because // each pointer has equal underlying value, but are separate entries in the map. // // Best way to compare is to store them, and then compare them later if needed. var mapMsp2ss map[*string][]string var mapMip2ss map[*uint64][]string tsflex, _ := v0.(*TestStrucFlex) if tsflex != nil { mapMstrUi64TSelf = tsflex.MstrUi64TSelf mapMsu2wss = tsflex.Msu2wss mapMsp2ss = tsflex.Msp2ss mapMip2ss = tsflex.Mip2ss if testNil { tsflex.MstrUi64TSelf = nil tsflex.Msu2wss = nil } } b0 := testMarshalErr(v0, h, t, "v0") var b1 = b0 if len(b0) > 1024 { b1 = b0[:1024] } bytesorstr := "string" if h.isBinary() { bytesorstr = "bytes" if len(b0) > 256 { b1 = b0[:256] } } if testVerbose { t.Logf(" Encoded %s: type: %T, len/cap: %v/%v, %v, %s\n", bytesorstr, v0, len(b0), cap(b0), b1, "...") } // TestStrucFlex has many fields which will encode differently if SignedInteger - so skip if _, ok := v0.(*TestStrucFlex); ok && bh.SignedInteger { continue } var v1 interface{} var err error if tsflex != nil { if testNil { tsflex.MstrUi64TSelf = mapMstrUi64TSelf tsflex.Msu2wss = mapMsu2wss } tsflex.Msp2ss = nil tsflex.Mip2ss = nil } if testNil { err = testUnmarshal(&v1, b0, h) } else if v0 != nil { v0rt := reflect.TypeOf(v0) // ptr if v0rt.Kind() == reflect.Ptr { err = testUnmarshal(v0, b0, h) v1 = v0 } else { rv1 := reflect.New(v0rt) err = testUnmarshal(rv1.Interface(), b0, h) v1 = rv1.Elem().Interface() // v1 = reflect.Indirect(reflect.ValueOf(v1)).Interface() } } if tsflex != nil { // MARKER: consider compare tsflex.{Msp2ss, Mip2ss} to map{Msp2ss, Mip2ss} _, _ = mapMsp2ss, mapMip2ss } if testVerbose { t.Logf(" v1 returned: %T, %v %#v", v1, v1, v1) } // if v1 != nil { // t.Logf(" v1 returned: %T, %#v", v1, v1) // //we always indirect, because ptr to typed value may be passed (if not testNil) // v1 = reflect.Indirect(reflect.ValueOf(v1)).Interface() // } if err != nil { t.Logf("-------- Error: %v", err) if testVerbose { t.Logf("-------- Partial return: %v", v1) } t.FailNow() } v0check := vsVerify[i] if v0check == skipVerifyVal || bh.SignedInteger { if testVerbose { t.Logf(" Nil Check skipped: Decoded: %T, %#v\n", v1, v1) } continue } if err = deepEqual(v0check, v1); err == nil { if testVerbose { t.Logf("++++++++ Before and After marshal matched\n") } } else { // t.Logf("-------- Before and After marshal do not match: Error: %v"+ // " ====> GOLDEN: (%T) %#v, DECODED: (%T) %#v\n", err, v0check, v0check, v1, v1) t.Logf("-------- FAIL: Before and After marshal do not match: Error: %v", err) if testVerbose { t.Logf(" ....... GOLDEN: (%T) %v %#v", v0check, v0check, v0check) t.Logf(" ....... DECODED: (%T) %v %#v", v1, v1, v1) } t.FailNow() } testReleaseBytes(b0) } } func doTestCodecTableOne(t *testing.T, h Handle) { // since this test modifies maps (and slices?), it should not be run in parallel, // else we may get "concurrent modification/range/set" errors. defer testSetupWithChecks(t, &h, false)() numPrim, numMap, idxTime, idxMap := testTableNumPrimitives, testTableNumMaps, testTableIdxTime, testTableNumPrimitives+2 tableVerify := testTableVerify(testVerifyMapTypeSame, h) tableTestNilVerify := testTableVerify(testVerifyDoNil|testVerifyMapTypeStrIntf, h) switch v := h.(type) { case *MsgpackHandle: oldWriteExt := v.WriteExt v.WriteExt = true testCodecTableOne(t, false, h, table, tableVerify) v.WriteExt = oldWriteExt case *JsonHandle: //skip []interface{} containing time.Time, as it encodes as a number, but cannot decode back to time.Time. //As there is no real support for extension tags in json, this must be skipped. testCodecTableOne(t, false, h, table[:numPrim], tableVerify[:numPrim]) testCodecTableOne(t, false, h, table[idxMap:], tableVerify[idxMap:]) default: testCodecTableOne(t, false, h, table, tableVerify) } // func TestMsgpackAll(t *testing.T) { // //skip []interface{} containing time.Time // testCodecTableOne(t, false, h, table[:numPrim], tableVerify[:numPrim]) // testCodecTableOne(t, false, h, table[numPrim+1:], tableVerify[numPrim+1:]) // func TestMsgpackNilStringMap(t *testing.T) { var oldMapType reflect.Type v := testBasicHandle(h) oldMapType, v.MapType = v.MapType, testMapStrIntfTyp // defer func() { v.MapType = oldMapType }() //skip time.Time, []interface{} containing time.Time, last map, and newStruc testCodecTableOne(t, true, h, table[:idxTime], tableTestNilVerify[:idxTime]) testCodecTableOne(t, true, h, table[idxMap:idxMap+numMap-1], tableTestNilVerify[idxMap:idxMap+numMap-1]) // failing one for msgpack v.MapType = oldMapType // func TestMsgpackNilIntf(t *testing.T) { //do last map and newStruc idx2 := idxMap + numMap - 1 testCodecTableOne(t, true, h, table[idx2:], tableTestNilVerify[idx2:]) //testCodecTableOne(t, true, h, table[17:18], tableTestNilVerify[17:18]) // do we need this? } func doTestCodecMiscOne(t *testing.T, h Handle) { defer testSetup(t, &h)() var err error bh := testBasicHandle(h) b := testMarshalErr(32, h, t, "32") // Cannot do this nil one, because faster type assertion decoding will panic // var i *int32 // if err = testUnmarshal(b, i, nil); err == nil { // t.Logf("------- Expecting error because we cannot unmarshal to int32 nil ptr") // t.FailNow() // } var i2 int32 testUnmarshalErr(&i2, b, h, t, "int32-ptr") if i2 != int32(32) { t.Logf("------- didn't unmarshal to 32: Received: %d", i2) t.FailNow() } // func TestMsgpackDecodePtr(t *testing.T) { ts := newTestStrucFlex(testDepth, testNumRepeatString, false, !testSkipIntf, testMapStringKeyOnly) testReleaseBytes(b) b = testMarshalErr(ts, h, t, "pointer-to-struct") if len(b) < 40 { t.Logf("------- Size must be > 40. Size: %d", len(b)) t.FailNow() } var b1 = b if len(b1) > 256 { b1 = b1[:256] } if testVerbose { if h.isBinary() { t.Logf("------- b: size: %v, value: %v", len(b), b1) } else { t.Logf("------- b: size: %v, value: %s", len(b), b1) } } // ts2 := testEmptyTestStrucFlex() var ts2 = new(TestStrucFlex) // we initialize and start draining the chan, so that we can decode into it without it blocking due to no consumer ts2.Chstr = make(chan string, teststrucflexChanCap) go func() { for range ts2.Chstr { } }() // drain it testUnmarshalErr(ts2, b, h, t, "pointer-to-struct") if ts2.I64 != math.MaxInt64*2/3 { t.Logf("------- Unmarshal wrong. Expect I64 = 64. Got: %v", ts2.I64) t.FailNow() } close(ts2.Chstr) testReleaseBytes(b) // Note: These will not work with SliceElementReset or InterfaceReset=true, so handle that. defer func(a, b bool) { bh.SliceElementReset = a bh.InterfaceReset = b }(bh.SliceElementReset, bh.InterfaceReset) bh.SliceElementReset = false bh.InterfaceReset = false m := map[string]int{"A": 2, "B": 3} p := []interface{}{m} bs := testMarshalErr(p, h, t, "p") m2 := map[string]int{} p2 := []interface{}{m2} testUnmarshalErr(&p2, bs, h, t, "&p2") if m2["A"] != 2 || m2["B"] != 3 { t.Logf("FAIL: m2 not as expected: expecting: %v, got: %v", m, m2) t.FailNow() } testCheckEqual(t, p, p2, "p=p2") testCheckEqual(t, m, m2, "m=m2") if err = deepEqual(p, p2); err == nil { if testVerbose { t.Logf("p and p2 match") } } else { t.Logf("Not Equal: %v. p: %v, p2: %v", err, p, p2) t.FailNow() } if err = deepEqual(m, m2); err == nil { if testVerbose { t.Logf("m and m2 match") } } else { t.Logf("Not Equal: %v. m: %v, m2: %v", err, m, m2) t.FailNow() } testReleaseBytes(bs) // func TestMsgpackDecodeStructSubset(t *testing.T) { // test that we can decode a subset of the stream mm := map[string]interface{}{"A": 5, "B": 99, "C": 333} bs = testMarshalErr(mm, h, t, "mm") type ttt struct { A uint8 C int32 } var t2 ttt testUnmarshalErr(&t2, bs, h, t, "t2") t3 := ttt{5, 333} testCheckEqual(t, t2, t3, "t2=t3") testReleaseBytes(bs) // println(">>>>>") // test simple arrays, non-addressable arrays, slices type tarr struct { A int64 B [3]int64 C []byte D [3]byte } var tarr0 = tarr{1, [3]int64{2, 3, 4}, []byte{4, 5, 6}, [3]byte{7, 8, 9}} // test both pointer and non-pointer (value) for _, tarr1 := range []interface{}{tarr0, &tarr0} { bs = testMarshalErr(tarr1, h, t, "tarr1") if _, ok := h.(*JsonHandle); ok { if testVerbose { t.Logf("Marshal as: %s", bs) } } var tarr2 tarr testUnmarshalErr(&tarr2, bs, h, t, "tarr2") testCheckEqual(t, tarr0, tarr2, "tarr0=tarr2") testReleaseBytes(bs) } // test byte array, even if empty (msgpack only) if _, ok := h.(*MsgpackHandle); ok { type ystruct struct { Anarray []byte } var ya = ystruct{} testUnmarshalErr(&ya, []byte{0x91, 0x90}, h, t, "ya") } var tt1, tt2 time.Time tt2 = time.Now() bs = testMarshalErr(tt1, h, t, "zero-time-enc") testUnmarshalErr(&tt2, bs, h, t, "zero-time-dec") testDeepEqualErr(tt1, tt2, t, "zero-time-eq") testReleaseBytes(bs) // test encoding a slice of byte (but not []byte) and decoding into a []byte var sw = []wrapUint8{'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J'} var bw []byte // ("ABCDEFGHIJ") bs = testMarshalErr(sw, h, t, "wrap-bytes-enc") testUnmarshalErr(&bw, bs, h, t, "wrap-bytes-dec") testDeepEqualErr(bw, []byte("ABCDEFGHIJ"), t, "wrap-bytes-eq") testReleaseBytes(bs) } func doTestCodecEmbeddedPointer(t *testing.T, h Handle) { defer testSetup(t, &h)() type Z int type A struct { AnInt int } type B struct { *Z *A MoreInt int } var z Z = 4 x1 := &B{&z, &A{5}, 6} bs := testMarshalErr(x1, h, t, "x1") var x2 = new(B) testUnmarshalErr(x2, bs, h, t, "x2") testCheckEqual(t, x1, x2, "x1=x2") testReleaseBytes(bs) } func testCodecUnderlyingType(t *testing.T, h Handle) { defer testSetup(t, &h)() // Manual Test. // Run by hand, with accompanying printf.statements in fast-path.go // to ensure that the fast functions are called. type T1 map[string]string v := T1{"1": "1s", "2": "2s"} var bs []byte var err error NewEncoderBytes(&bs, h).MustEncode(v) if err != nil { t.Logf("Error during encode: %v", err) t.FailNow() } var v2 T1 NewDecoderBytes(bs, h).MustDecode(&v2) if err != nil { t.Logf("Error during decode: %v", err) t.FailNow() } } func doTestCodecChan(t *testing.T, h Handle) { defer testSetup(t, &h)() // - send a slice []*int64 (sl1) into an chan (ch1) with cap > len(s1) // - encode ch1 as a stream array // - decode a chan (ch2), with cap > len(s1) from the stream array // - receive from ch2 into slice sl2 // - compare sl1 and sl2 { if testVerbose { t.Logf("*int64") } sl1 := make([]*int64, 4) for i := range sl1 { var j int64 = int64(i) sl1[i] = &j } ch1 := make(chan *int64, 4) for _, j := range sl1 { ch1 <- j } var bs []byte NewEncoderBytes(&bs, h).MustEncode(ch1) ch2 := make(chan *int64, 8) NewDecoderBytes(bs, h).MustDecode(&ch2) close(ch2) var sl2 []*int64 for j := range ch2 { sl2 = append(sl2, j) } if err := deepEqual(sl1, sl2); err != nil { t.Logf("FAIL: Not Match: %v; len: %v, %v", err, len(sl1), len(sl2)) if testVerbose { t.Logf("sl1: %#v, sl2: %#v", sl1, sl2) } t.FailNow() } } { if testVerbose { t.Logf("testBytesT []byte - input []byte") } type testBytesT []byte sl1 := make([]testBytesT, 4) for i := range sl1 { var j = []byte(strings.Repeat(strconv.FormatInt(int64(i), 10), i)) sl1[i] = j } ch1 := make(chan testBytesT, 4) for _, j := range sl1 { ch1 <- j } var bs []byte NewEncoderBytes(&bs, h).MustEncode(ch1) ch2 := make(chan testBytesT, 8) NewDecoderBytes(bs, h).MustDecode(&ch2) close(ch2) var sl2 []testBytesT for j := range ch2 { // t.Logf(">>>> from chan: is nil? %v, %v", j == nil, j) sl2 = append(sl2, j) } if err := deepEqual(sl1, sl2); err != nil { t.Logf("FAIL: Not Match: %v; len: %v, %v", err, len(sl1), len(sl2)) if testVerbose { t.Logf("sl1: %#v, sl2: %#v", sl1, sl2) } t.FailNow() } } { if testVerbose { t.Logf("testBytesT byte - input string/testBytesT") } type testBytesT byte sl1 := make([]testBytesT, 4) for i := range sl1 { var j = strconv.FormatInt(int64(i), 10)[0] sl1[i] = testBytesT(j) } ch1 := make(chan testBytesT, 4) for _, j := range sl1 { ch1 <- j } var bs []byte NewEncoderBytes(&bs, h).MustEncode(ch1) ch2 := make(chan testBytesT, 8) NewDecoderBytes(bs, h).MustDecode(&ch2) close(ch2) var sl2 []testBytesT for j := range ch2 { sl2 = append(sl2, j) } if err := deepEqual(sl1, sl2); err != nil { t.Logf("FAIL: Not Match: %v; len: %v, %v", err, len(sl1), len(sl2)) t.FailNow() } } { if testVerbose { t.Logf("*[]byte") } sl1 := make([]byte, 4) for i := range sl1 { var j = strconv.FormatInt(int64(i), 10)[0] sl1[i] = byte(j) } ch1 := make(chan byte, 4) for _, j := range sl1 { ch1 <- j } var bs []byte NewEncoderBytes(&bs, h).MustEncode(ch1) ch2 := make(chan byte, 8) NewDecoderBytes(bs, h).MustDecode(&ch2) close(ch2) var sl2 []byte for j := range ch2 { sl2 = append(sl2, j) } if err := deepEqual(sl1, sl2); err != nil { t.Logf("FAIL: Not Match: %v; len: %v, %v", err, len(sl1), len(sl2)) t.FailNow() } } } func doTestCodecRpcOne(t *testing.T, rr Rpc, h Handle, doRequest bool, exitSleepMs time.Duration) (port int) { defer testSetup(t, &h)() if testSkipRPCTests { t.Skip(testSkipRPCTestsMsg) } if !testRecoverPanicToErr { t.Skip(testSkipIfNotRecoverPanicToErrMsg) } if mh, ok := h.(*MsgpackHandle); ok && mh.SliceElementReset { t.Skipf("skipping ... MsgpackRpcSpec does not handle SliceElementReset - needs investigation") } if jsonH, ok := h.(*JsonHandle); ok && !jsonH.TermWhitespace { jsonH.TermWhitespace = true defer func() { jsonH.TermWhitespace = false }() } // srv := rpc.NewServer() // srv.Register(testRpcInt) srv := testRpcServer ln, err := net.Listen("tcp", "127.0.0.1:0") // listen on ipv4 localhost testCheckErr(t, err) port = (ln.Addr().(*net.TCPAddr)).Port if testVerbose { t.Logf("connFn: addr: %v, network: %v, port: %v", ln.Addr(), ln.Addr().Network(), port) } // var opts *DecoderOptions // opts := testDecOpts // opts.MapType = mapStrIntfTyp serverExitChan := make(chan bool, 1) var serverExitFlag uint64 serverFn := func() { var conns []net.Conn var svrcodecs []rpc.ServerCodec defer func() { for i := range conns { svrcodecs[i].Close() conns[i].Close() } ln.Close() serverExitChan <- true }() for { conn1, err1 := ln.Accept() if atomic.LoadUint64(&serverExitFlag) == 1 { if conn1 != nil { conn1.Close() } break } if err1 != nil { // fmt.Printf("accept err1: %v\n", err1) if testVerbose { t.Logf("rpc error accepting connection: %v", err1) } continue } if conn1 != nil { sc := rr.ServerCodec(testReadWriteCloser(conn1), h) conns = append(conns, conn1) svrcodecs = append(svrcodecs, sc) go srv.ServeCodec(sc) } } } connFn := func() (bs net.Conn) { bs, err2 := net.Dial(ln.Addr().Network(), ln.Addr().String()) testCheckErr(t, err2) return } exitFn := func() { if atomic.LoadUint64(&serverExitFlag) == 1 { return } atomic.StoreUint64(&serverExitFlag, 1) bs := connFn() defer bs.Close() <-serverExitChan // atomic.StoreUint64(&serverExitFlag, 0) // serverExitChan <- true } go serverFn() // runtime.Gosched() if exitSleepMs == 0 { defer exitFn() } else { go func() { time.Sleep(exitSleepMs) exitFn() }() } if doRequest { func() { bs := connFn() defer bs.Close() cc := rr.ClientCodec(testReadWriteCloser(bs), h) defer cc.Close() cl := rpc.NewClientWithCodec(cc) defer cl.Close() var up, sq, mult int var rstr string testCheckErr(t, cl.Call("TestRpcInt.Update", 5, &up)) testCheckEqual(t, atomic.LoadInt64(&testRpcInt.i), int64(5), "testRpcInt.i=5") testCheckEqual(t, up, 5, "up=5") testCheckErr(t, cl.Call("TestRpcInt.Square", 1, &sq)) testCheckEqual(t, sq, 25, "sq=25") testCheckErr(t, cl.Call("TestRpcInt.Mult", 20, &mult)) testCheckEqual(t, mult, 100, "mult=100") testCheckErr(t, cl.Call("TestRpcInt.EchoStruct", TestRpcABC{"Aa", "Bb", "Cc"}, &rstr)) testCheckEqual(t, rstr, fmt.Sprintf("%#v", TestRpcABC{"Aa", "Bb", "Cc"}), "rstr=") testCheckErr(t, cl.Call("TestRpcInt.Echo123", []string{"A1", "B2", "C3"}, &rstr)) testCheckEqual(t, rstr, fmt.Sprintf("%#v", []string{"A1", "B2", "C3"}), "rstr=") }() } return } func doTestMapEncodeForCanonical(t *testing.T, h Handle) { defer testSetup(t, &h)() // println("doTestMapEncodeForCanonical") v1 := map[stringUint64T]interface{}{ stringUint64T{"a", 1}: 1, stringUint64T{"b", 2}: "hello", stringUint64T{"c", 3}: map[string]interface{}{ "c/a": 1, "c/b": "world", "c/c": []int{1, 2, 3, 4}, "c/d": map[string]interface{}{ "c/d/a": "fdisajfoidsajfopdjsaopfjdsapofda", "c/d/b": "fdsafjdposakfodpsakfopdsakfpodsakfpodksaopfkdsopafkdopsa", "c/d/c": "poir02 ir30qif4p03qir0pogjfpoaerfgjp ofke[padfk[ewapf kdp[afep[aw", "c/d/d": "fdsopafkd[sa f-32qor-=4qeof -afo-erfo r-eafo 4e- o r4-qwo ag", "c/d/e": "kfep[a sfkr0[paf[a foe-[wq ewpfao-q ro3-q ro-4qof4-qor 3-e orfkropzjbvoisdb", "c/d/f": "", }, "c/e": map[int]string{ 1: "1", 22: "22", 333: "333", 4444: "4444", 55555: "55555", }, "c/f": map[string]int{ "1": 1, "22": 22, "333": 333, "4444": 4444, "55555": 55555, }, "c/g": map[bool]int{ false: 0, true: 1, }, "c/t": map[time.Time]int64{ time.Date(2019, 1, 1, 0, 0, 0, 0, time.UTC): time.Date(2019, 1, 1, 0, 0, 0, 0, time.UTC).UnixNano(), time.Date(2018, 1, 1, 0, 0, 0, 0, time.UTC): time.Date(2018, 1, 1, 0, 0, 0, 0, time.UTC).UnixNano(), time.Date(2017, 1, 1, 0, 0, 0, 0, time.UTC): time.Date(2017, 1, 1, 0, 0, 0, 0, time.UTC).UnixNano(), }, }, } var v2 map[stringUint64T]interface{} var b1, b2, b3 []byte // encode v1 into b1, decode b1 into v2, encode v2 into b2, and compare b1 and b2. // OR // encode v1 into b1, decode b1 into v2, encode v2 into b2 and b3, and compare b2 and b3. // e.g. when doing cbor indefinite, we may haveto use out-of-band encoding // where each key is encoded as an indefinite length string, which makes it not the same // order as the strings were lexicographically ordered before. var cborIndef bool if ch, ok := h.(*CborHandle); ok { cborIndef = ch.IndefiniteLength } // if ch, ok := h.(*BincHandle); ok && ch.AsSymbols != 2 { // defer func(u uint8) { ch.AsSymbols = u }(ch.AsSymbols) // ch.AsSymbols = 2 // } bh := testBasicHandle(h) defer func(c, si bool) { bh.Canonical = c bh.SignedInteger = si }(bh.Canonical, bh.SignedInteger) bh.Canonical = true // bh.SignedInteger = true e1 := NewEncoderBytes(&b1, h) e1.MustEncode(v1) d1 := NewDecoderBytes(b1, h) d1.MustDecode(&v2) // testDeepEqualErr(v1, v2, t, "huh?") e2 := NewEncoderBytes(&b2, h) e2.MustEncode(v2) var b1t, b2t = b1, b2 if cborIndef { e2 = NewEncoderBytes(&b3, h) e2.MustEncode(v2) b1t, b2t = b2, b3 } if !bytes.Equal(b1t, b2t) { t.Logf("Unequal bytes of length: %v vs %v", len(b1t), len(b2t)) if testVerbose { t.Logf("Unequal bytes: \n\t%v \n\tVS \n\t%v", b1t, b2t) } t.FailNow() } } func doTestStdEncIntf(t *testing.T, h Handle) { defer testSetup(t, &h)() args := [][2]interface{}{ {&TestABC{"A", "BB", "CCC"}, new(TestABC)}, {&TestABC2{"AAA", "BB", "C"}, new(TestABC2)}, } for _, a := range args { var b []byte e := NewEncoderBytes(&b, h) e.MustEncode(a[0]) d := NewDecoderBytes(b, h) d.MustDecode(a[1]) if err := deepEqual(a[0], a[1]); err == nil { if testVerbose { t.Logf("++++ Objects match") } } else { t.Logf("---- FAIL: Objects do not match: y0: %v, y1: %v, err: %v", a[0], a[1], err) t.FailNow() } } } func doTestEncCircularRef(t *testing.T, h Handle) { if !testRecoverPanicToErr { t.Skip(testSkipIfNotRecoverPanicToErrMsg) } defer testSetup(t, &h)() type T1 struct { S string B bool T interface{} } type T2 struct { S string T *T1 } type T3 struct { S string T *T2 } t1 := T1{"t1", true, nil} t2 := T2{"t2", &t1} t3 := T3{"t3", &t2} t1.T = &t3 var bs []byte var err error bh := testBasicHandle(h) if !bh.CheckCircularRef { bh.CheckCircularRef = true defer func() { bh.CheckCircularRef = false }() } err = NewEncoderBytes(&bs, h).Encode(&t3) if err == nil || !strings.Contains(err.Error(), "circular reference found") { t.Logf("expect circular reference error, got: %v", err) t.FailNow() } if x := err.Error(); strings.Contains(x, "circular") || strings.Contains(x, "cyclic") { if testVerbose { t.Logf("error detected as expected: %v", x) } } else { t.Logf("FAIL: error detected was not as expected: %v", x) t.FailNow() } } // TestAnonCycleT{1,2,3} types are used to test anonymous cycles. // They are top-level, so that they can have circular references. type ( TestAnonCycleT1 struct { S string TestAnonCycleT2 } TestAnonCycleT2 struct { S2 string TestAnonCycleT3 } TestAnonCycleT3 struct { *TestAnonCycleT1 } ) func doTestAnonCycle(t *testing.T, h Handle) { defer testSetup(t, &h)() var x TestAnonCycleT1 x.S = "hello" x.TestAnonCycleT2.S2 = "hello.2" x.TestAnonCycleT2.TestAnonCycleT3.TestAnonCycleT1 = &x // just check that you can get typeInfo for T1 rt := reflect.TypeOf((*TestAnonCycleT1)(nil)).Elem() rtid := rt2id(rt) pti := testBasicHandle(h).getTypeInfo(rtid, rt) if testVerbose { t.Logf("[%s] pti: %v", h.Name(), pti) } } func doTestAllErrWriter(t *testing.T, hh ...Handle) { if !testRecoverPanicToErr { t.Skip(testSkipIfNotRecoverPanicToErrMsg) } defer testSetup(t, nil)() for _, h := range hh { if testUseParallel { h = testHandleCopy(h) } __doTestErrWriter(t, h) } } func __doTestErrWriter(t *testing.T, h Handle) { name := h.Name() var ew testErrWriter w := bufio.NewWriterSize(&ew, 4) enc := NewEncoder(w, h) for i := 0; i < 4; i++ { err := enc.Encode("ugorji") if ev, ok := err.(*codecError); ok { err = ev.Cause() } if err != testErrWriterErr { t.Logf("%s: expecting err: %v, received: %v", name, testErrWriterErr, err) t.FailNow() } } } func __doTestJsonLargeInteger(t *testing.T, v interface{}, ias uint8, jh *JsonHandle) { if testVerbose { t.Logf("Running TestJsonLargeInteger: v: %#v, ias: %c", v, ias) } oldIAS := jh.IntegerAsString defer func() { jh.IntegerAsString = oldIAS }() jh.IntegerAsString = ias var vu uint var vi int var vb bool var b []byte e := NewEncoderBytes(&b, jh) e.MustEncode(v) e.MustEncode(true) d := NewDecoderBytes(b, jh) // below, we validate that the json string or number was encoded, // then decode, and validate that the correct value was decoded. fnStrChk := func() { // check that output started with '"', and ended with '"true' // if !(len(b) >= 7 && b[0] == '"' && string(b[len(b)-7:]) == `" true `) { if !(len(b) >= 5 && b[0] == '"' && string(b[len(b)-5:]) == `"true`) { t.Logf("Expecting a JSON string, got: '%s'", b) t.FailNow() } } switch ias { case 'L': switch v2 := v.(type) { case int: v2n := int64(v2) // done to work with 32-bit OS if v2n > 1<<53 || (v2n < 0 && -v2n > 1<<53) { fnStrChk() } case uint: v2n := uint64(v2) // done to work with 32-bit OS if v2n > 1<<53 { fnStrChk() } } case 'A': fnStrChk() default: // check that output doesn't contain " at all for _, i := range b { if i == '"' { t.Logf("Expecting a JSON Number without quotation: got: %s", b) t.FailNow() } } } switch v2 := v.(type) { case int: d.MustDecode(&vi) d.MustDecode(&vb) // check that vb = true, and vi == v2 if !(vb && vi == v2) { t.Logf("Expecting equal values from %s: got golden: %v, decoded: %v", b, v2, vi) t.FailNow() } case uint: d.MustDecode(&vu) d.MustDecode(&vb) // check that vb = true, and vi == v2 if !(vb && vu == v2) { t.Logf("Expecting equal values from %s: got golden: %v, decoded: %v", b, v2, vu) t.FailNow() } } } func doTestRawValue(t *testing.T, h Handle) { defer testSetup(t, &h)() bh := testBasicHandle(h) if !bh.Raw { bh.Raw = true defer func() { bh.Raw = false }() } var i, i2 int var v, v2 TestRawValue var bs, bs2 []byte i = 1234 //1234567890 v = TestRawValue{I: i} e := NewEncoderBytes(&bs, h) e.MustEncode(v.I) if testVerbose { t.Logf(">>> raw: %v, %s\n", bs, bs) } v.R = Raw(bs) e.ResetBytes(&bs2) e.MustEncode(v) if testVerbose { t.Logf(">>> bs2: %v, %s\n", bs2, bs2) } d := NewDecoderBytes(bs2, h) d.MustDecode(&v2) d.ResetBytes(v2.R) if testVerbose { t.Logf(">>> v2.R: %v, %s\n", ([]byte)(v2.R), ([]byte)(v2.R)) } d.MustDecode(&i2) if testVerbose { t.Logf(">>> Encoded %v, decoded %v\n", i, i2) } // t.Logf("Encoded %v, decoded %v", i, i2) if i != i2 { t.Logf("Error: encoded %v, decoded %v", i, i2) t.FailNow() } } // Comprehensive testing that generates data encoded from python handle (cbor, msgpack), // and validates that our code can read and write it out accordingly. // We keep this unexported here, and put actual test in ext_dep_test.go. // This way, it can be excluded by excluding file completely. func doTestPythonGenStreams(t *testing.T, h Handle) { defer testSetup(t, &h)() // time0 := time.Now() // defer func() { xdebugf("python-gen-streams: %s: took: %v", h.Name(), time.Since(time0)) }() name := h.Name() if testVerbose { t.Logf("TestPythonGenStreams-%v", name) } tmpdir, err := ioutil.TempDir("", "golang-"+name+"-test") if err != nil { t.Logf("-------- Unable to create temp directory\n") t.FailNow() } defer os.RemoveAll(tmpdir) if testVerbose { t.Logf("tmpdir: %v", tmpdir) } cmd := exec.Command("python", "test.py", "testdata", tmpdir) //cmd.Stdin = strings.NewReader("some input") //cmd.Stdout = &out var cmdout []byte if cmdout, err = cmd.CombinedOutput(); err != nil { t.Logf("-------- Error running test.py testdata. Err: %v", err) t.Logf(" %v", string(cmdout)) t.FailNow() } bh := testBasicHandle(h) defer func(tt reflect.Type) { bh.MapType = tt }(bh.MapType) defer func(b bool) { bh.RawToString = b }(bh.RawToString) // msgpack python needs Raw converted to string bh.RawToString = true oldMapType := bh.MapType tablePythonVerify := testTableVerify(testVerifyForPython|testVerifyTimeAsInteger|testVerifyMapTypeStrIntf, h) for i, v := range tablePythonVerify { // if v == uint64(0) && h is a *MsgpackHandle: v = int64(0) bh.MapType = oldMapType //load up the golden file based on number //decode it //compare to in-mem object //encode it again //compare to output stream if testVerbose { t.Logf("..............................................") t.Logf(" Testing: #%d: %T, %#v\n", i, v, v) } var bss []byte bss, err = ioutil.ReadFile(filepath.Join(tmpdir, strconv.Itoa(i)+"."+name+".golden")) if err != nil { t.Logf("-------- Error reading golden file: %d. Err: %v", i, err) t.FailNow() continue } bh.MapType = testMapStrIntfTyp var v1 interface{} if err = testUnmarshal(&v1, bss, h); err != nil { t.Logf("-------- Error decoding stream: %d: Err: %v", i, err) t.FailNow() continue } if v == skipVerifyVal { continue } //no need to indirect, because we pass a nil ptr, so we already have the value //if v1 != nil { v1 = reflect.Indirect(reflect.ValueOf(v1)).Interface() } if err = deepEqual(v, v1); err == nil { if testVerbose { t.Logf("++++++++ Objects match: %T, %v", v, v) } } else { t.Logf("-------- FAIL: Objects do not match: %v. Source: %T. Decoded: %T", err, v, v1) if testVerbose { t.Logf("-------- GOLDEN: %#v", v) // t.Logf("-------- DECODED: %#v <====> %#v", v1, reflect.Indirect(reflect.ValueOf(v1)).Interface()) t.Logf("-------- DECODED: %#v <====> %#v", v1, reflect.Indirect(reflect.ValueOf(v1)).Interface()) } t.FailNow() } bsb, err := testMarshal(v1, h) if err != nil { t.Logf("Error encoding to stream: %d: Err: %v", i, err) t.FailNow() continue } if err = deepEqual(bsb, bss); err == nil { if testVerbose { t.Logf("++++++++ Bytes match") } } else { xs := "--------" if reflect.ValueOf(v).Kind() == reflect.Map { xs = " " if testVerbose { t.Logf("%s FAIL - bytes do not match, but it's a map (ok - dependent on ordering): %v", xs, err) } } else { t.Logf("%s FAIL - bytes do not match and is not a map (bad): %v", xs, err) t.FailNow() } if testVerbose { t.Logf("%s FROM_FILE: %4d] %v", xs, len(bss), bss) t.Logf("%s ENCODED: %4d] %v", xs, len(bsb), bsb) } } testReleaseBytes(bsb) } bh.MapType = oldMapType } // To test MsgpackSpecRpc, we test 3 scenarios: // - Go Client to Go RPC Service (contained within TestMsgpackRpcSpec) // - Go client to Python RPC Service (contained within doTestMsgpackRpcSpecGoClientToPythonSvc) // - Python Client to Go RPC Service (contained within doTestMsgpackRpcSpecPythonClientToGoSvc) // // This allows us test the different calling conventions // - Go Service requires only one argument // - Python Service allows multiple arguments func doTestMsgpackRpcSpecGoClientToPythonSvc(t *testing.T, h Handle) { if testSkipRPCTests { t.Skip(testSkipRPCTestsMsg) } defer testSetup(t, &h)() // openPorts are between 6700 and 6800 r := rand.New(rand.NewSource(time.Now().UnixNano())) openPort := strconv.FormatInt(6700+r.Int63n(99), 10) // openPort := "6792" cmd := exec.Command("python", "test.py", "rpc-server", openPort, "4") testCheckErr(t, cmd.Start()) bs, err2 := net.Dial("tcp", ":"+openPort) maxSleepTime := 500 * time.Millisecond iterSleepTime := 5 * time.Millisecond for i := 0; i < int(maxSleepTime/iterSleepTime) && err2 != nil; i++ { time.Sleep(iterSleepTime) // time for python rpc server to start bs, err2 = net.Dial("tcp", ":"+openPort) } testCheckErr(t, err2) cc := MsgpackSpecRpc.ClientCodec(testReadWriteCloser(bs), h) cl := rpc.NewClientWithCodec(cc) defer cl.Close() var rstr string testCheckErr(t, cl.Call("EchoStruct", TestRpcABC{"Aa", "Bb", "Cc"}, &rstr)) //testCheckEqual(t, rstr, "{'A': 'Aa', 'B': 'Bb', 'C': 'Cc'}") var mArgs MsgpackSpecRpcMultiArgs = []interface{}{"A1", "B2", "C3"} testCheckErr(t, cl.Call("Echo123", mArgs, &rstr)) testCheckEqual(t, rstr, "1:A1 2:B2 3:C3", "rstr=") cmd.Process.Kill() } func doTestMsgpackRpcSpecPythonClientToGoSvc(t *testing.T, h Handle) { if testSkipRPCTests { t.Skip(testSkipRPCTestsMsg) } defer testSetup(t, &h)() // seems 10ms is not enough for test run; set high to 1 second, and client will close when done exitSleepDur := 1000 * time.Millisecond port := doTestCodecRpcOne(t, MsgpackSpecRpc, h, false, exitSleepDur) cmd := exec.Command("python", "test.py", "rpc-client-go-service", strconv.Itoa(port)) var cmdout []byte var err error if cmdout, err = cmd.CombinedOutput(); err != nil { t.Logf("-------- Error running test.py rpc-client-go-service. Err: %v", err) t.Logf(" %v", string(cmdout)) t.FailNow() } testCheckEqual(t, string(cmdout), fmt.Sprintf("%#v\n%#v\n", []string{"A1", "B2", "C3"}, TestRpcABC{"Aa", "Bb", "Cc"}), "cmdout=") } func doTestSwallowAndZero(t *testing.T, h Handle) { defer testSetup(t, &h)() v1 := newTestStrucFlex(testDepth, testNumRepeatString, false, false, testMapStringKeyOnly) var b1 []byte e1 := NewEncoderBytes(&b1, h) e1.MustEncode(v1) d1 := NewDecoderBytes(b1, h) d1.swallow() if d1.r().numread() != uint(len(b1)) { t.Logf("swallow didn't consume all encoded bytes: %v out of %v", d1.r().numread(), len(b1)) t.FailNow() } setZero(v1) testDeepEqualErr(v1, &TestStrucFlex{}, t, "filled-and-zeroed") } func doTestRawExt(t *testing.T, h Handle) { defer testSetup(t, &h)() var b []byte var v RawExt // interface{} _, isJson := h.(*JsonHandle) _, isCbor := h.(*CborHandle) bh := testBasicHandle(h) // isValuer := isJson || isCbor // _ = isValuer for _, r := range []RawExt{ {Tag: 99, Value: "9999", Data: []byte("9999")}, } { e := NewEncoderBytes(&b, h) e.MustEncode(&r) // fmt.Printf(">>>> rawext: isnil? %v, %d - %v\n", b == nil, len(b), b) d := NewDecoderBytes(b, h) d.MustDecode(&v) var r2 = r switch { case isJson: r2.Tag = 0 r2.Data = nil case isCbor: r2.Data = nil default: r2.Value = nil } testDeepEqualErr(v, r2, t, "rawext-default") // switch h.(type) { // case *JsonHandle: // testDeepEqualErr(r.Value, v, t, "rawext-json") // default: // var r2 = r // if isValuer { // r2.Data = nil // } else { // r2.Value = nil // } // testDeepEqualErr(v, r2, t, "rawext-default") // } } // Add testing for Raw also if b != nil { b = b[:0] } oldRawMode := bh.Raw defer func() { bh.Raw = oldRawMode }() bh.Raw = true var v2 Raw for _, s := range []string{ "goodbye", "hello", } { e := NewEncoderBytes(&b, h) e.MustEncode(&s) // fmt.Printf(">>>> rawext: isnil? %v, %d - %v\n", b == nil, len(b), b) var r Raw = make([]byte, len(b)) copy(r, b) d := NewDecoderBytes(b, h) d.MustDecode(&v2) testDeepEqualErr(v2, r, t, "raw-default") } } // func doTestTimeExt(t *testing.T, h Handle) { // var t = time.Now() // // add time ext to the handle // } func doTestMapStructKey(t *testing.T, h Handle) { defer testSetup(t, &h)() var b []byte var v interface{} // map[stringUint64T]wrapUint64Slice // interface{} bh := testBasicHandle(h) m := map[stringUint64T]wrapUint64Slice{ stringUint64T{"55555", 55555}: []wrapUint64{12345}, stringUint64T{"333", 333}: []wrapUint64{123}, } oldCanonical := bh.Canonical oldMapType := bh.MapType defer func() { bh.Canonical = oldCanonical bh.MapType = oldMapType }() bh.MapType = reflect.TypeOf((*map[stringUint64T]wrapUint64Slice)(nil)).Elem() for _, bv := range [2]bool{true, false} { b, v = nil, nil bh.Canonical = bv e := NewEncoderBytes(&b, h) e.MustEncode(m) d := NewDecoderBytes(b, h) d.MustDecode(&v) testDeepEqualErr(v, m, t, "map-structkey") } } func doTestDecodeNilMapValue(t *testing.T, h Handle) { defer testSetup(t, &h)() type Struct struct { Field map[uint16]map[uint32]struct{} } bh := testBasicHandle(h) defer func(t reflect.Type) { bh.MapType = t }(bh.MapType) // this test expects that nil doesn't result in deleting entries _, isJsonHandle := h.(*JsonHandle) toEncode := Struct{Field: map[uint16]map[uint32]struct{}{ 1: nil, }} bs := testMarshalErr(toEncode, h, t, "-") if isJsonHandle && testVerbose { t.Logf("json encoded: %s\n", bs) } var decoded Struct testUnmarshalErr(&decoded, bs, h, t, "-") if !reflect.DeepEqual(decoded, toEncode) { t.Logf("Decoded value %#v != %#v", decoded, toEncode) t.FailNow() } testReleaseBytes(bs) __doTestDecodeNilMapEntryValue(t, h) } func __doTestDecodeNilMapEntryValue(t *testing.T, h Handle) { type Entry struct{} type Entries struct { Map map[string]*Entry } c := Entries{ Map: map[string]*Entry{ "nil": nil, "empty": &Entry{}, }, } bs, err := testMarshal(&c, h) if err != nil { t.Logf("failed to encode: %v", err) t.FailNow() } var f Entries err = testUnmarshal(&f, bs, h) if err != nil { t.Logf("failed to decode: %v", err) t.FailNow() } if !reflect.DeepEqual(c, f) { t.Logf("roundtrip encoding doesn't match\nexpected: %v\nfound: %v\n\n"+ "empty value: %#+v\nnil value: %#+v", c, f, f.Map["empty"], f.Map["nil"]) t.FailNow() } testReleaseBytes(bs) } func doTestEmbeddedFieldPrecedence(t *testing.T, h Handle) { defer testSetup(t, &h)() type Embedded struct { Field byte } type Struct struct { Field byte Embedded } toEncode := Struct{ Field: 1, Embedded: Embedded{Field: 2}, } _, isJsonHandle := h.(*JsonHandle) handle := testBasicHandle(h) oldMapType := handle.MapType defer func() { handle.MapType = oldMapType }() handle.MapType = reflect.TypeOf(map[interface{}]interface{}(nil)) bs, err := testMarshal(toEncode, h) if err != nil { t.Logf("Error encoding: %v, Err: %v", toEncode, err) t.FailNow() } var decoded Struct err = testUnmarshal(&decoded, bs, h) if err != nil { t.Logf("Error decoding: %v", err) t.FailNow() } if decoded.Field != toEncode.Field { t.Logf("Decoded result %v != %v", decoded.Field, toEncode.Field) // hex to look at what was encoded if isJsonHandle { t.Logf("JSON encoded as: %s", bs) // hex to look at what was encoded } t.FailNow() } testReleaseBytes(bs) } func doTestLargeContainerLen(t *testing.T, h Handle) { defer testSetup(t, &h)() // This test can take a while if run multiple times in a loop, as it creates // large maps/slices. Use t.Short() appropriately to limit its execution time. // Note that this test does not make sense for formats which do not pre-record // the length, like json, or cbor with indefinite length. if _, ok := h.(*JsonHandle); ok { t.Skipf("skipping as json doesn't support prefixed lengths") } if c, ok := h.(*CborHandle); ok && c.IndefiniteLength { t.Skipf("skipping as cbor Indefinite Length doesn't use prefixed lengths") } bh := testBasicHandle(h) var sizes []int // sizes = []int{ // 0, 1, // math.MaxInt8, math.MaxInt8 + 4, math.MaxInt8 - 4, // math.MaxInt16, math.MaxInt16 + 4, math.MaxInt16 - 4, // math.MaxInt32, math.MaxInt32 - 4, // // math.MaxInt32 + 4, // bombs on 32-bit // // math.MaxInt64, math.MaxInt64 - 4, // bombs on 32-bit // math.MaxUint8, math.MaxUint8 + 4, math.MaxUint8 - 4, // math.MaxUint16, math.MaxUint16 + 4, math.MaxUint16 - 4, // // math.MaxUint32, math.MaxUint32 + 4, math.MaxUint32 - 4, // bombs on 32-bit // } sizes = []int{ // ensure in ascending order (as creating mm below requires it) 0, 1, math.MaxInt8 + 4, math.MaxUint8 + 4, } if !testing.Short() { sizes = append(sizes, math.MaxUint16+4) // math.MaxInt16+4, math.MaxUint16+4 } m := make(map[int][]struct{}) for _, i := range sizes { m[i] = make([]struct{}, i) } bs := testMarshalErr(m, h, t, "-slices") var m2 = make(map[int][]struct{}) testUnmarshalErr(m2, bs, h, t, "-slices") testDeepEqualErr(m, m2, t, "-slices") d, x := testSharedCodecDecoder(bs, h, bh) bs2 := d.d.nextValueBytes([]byte{}) testSharedCodecDecoderAfter(d, x, bh) testDeepEqualErr(bs, bs2, t, "nextvaluebytes-slices") // if len(bs2) != 0 || len(bs2) != len(bs) { } testReleaseBytes(bs) // requires sizes to be in ascending order mm := make(map[int]struct{}) for _, i := range sizes { for j := len(mm); j < i; j++ { mm[j] = struct{}{} } bs = testMarshalErr(mm, h, t, "-map") var mm2 = make(map[int]struct{}) testUnmarshalErr(mm2, bs, h, t, "-map") testDeepEqualErr(mm, mm2, t, "-map") d, x = testSharedCodecDecoder(bs, h, bh) bs2 = d.d.nextValueBytes([]byte{}) testSharedCodecDecoderAfter(d, x, bh) testDeepEqualErr(bs, bs2, t, "nextvaluebytes-map") testReleaseBytes(bs) } // do same tests for large strings (encoded as symbols or not) // skip if 32-bit or not using unsafe mode if safeMode || (32<<(^uint(0)>>63)) < 64 { return } // now, want to do tests for large strings, which // could be encoded as symbols. // to do this, we create a simple one-field struct, // use use flags to switch from symbols to non-symbols hbinc, okbinc := h.(*BincHandle) if okbinc { oldAsSymbols := hbinc.AsSymbols defer func() { hbinc.AsSymbols = oldAsSymbols }() } inOutLen := math.MaxUint16 * 3 / 2 if testing.Short() { inOutLen = math.MaxUint8 * 2 // math.MaxUint16 / 16 } var out = make([]byte, 0, inOutLen) var in []byte = make([]byte, inOutLen) for i := range in { in[i] = 'A' } e := NewEncoder(nil, h) sizes = []int{ 0, 1, 4, 8, 12, 16, 28, 32, 36, math.MaxInt8 - 4, math.MaxInt8, math.MaxInt8 + 4, math.MaxUint8, math.MaxUint8 + 4, math.MaxUint8 - 4, } if !testing.Short() { sizes = append(sizes, math.MaxInt16-4, math.MaxInt16, math.MaxInt16+4, math.MaxUint16, math.MaxUint16+4, math.MaxUint16-4) } for _, i := range sizes { var m1, m2 map[string]bool m1 = make(map[string]bool, 1) // var s1 = stringView(in[:i]) var s1 = string(in[:i]) // fmt.Printf("testcontainerlen: large string: i: %v, |%s|\n", i, s1) m1[s1] = true if okbinc { hbinc.AsSymbols = 2 } out = out[:0] e.ResetBytes(&out) e.MustEncode(m1) // bs, _ = testMarshalErr(m1, h, t, "-") m2 = make(map[string]bool, 1) testUnmarshalErr(m2, out, h, t, "no-symbols-string") testDeepEqualErr(m1, m2, t, "no-symbols-string") d, x = testSharedCodecDecoder(out, h, bh) bs2 = d.d.nextValueBytes([]byte{}) testSharedCodecDecoderAfter(d, x, bh) testDeepEqualErr(out, bs2, t, "nextvaluebytes-no-symbols-string") if okbinc { // now, do as symbols hbinc.AsSymbols = 1 out = out[:0] e.ResetBytes(&out) e.MustEncode(m1) // bs, _ = testMarshalErr(m1, h, t, "-") m2 = make(map[string]bool, 1) testUnmarshalErr(m2, out, h, t, "symbols-string") testDeepEqualErr(m1, m2, t, "symbols-string") d, x = testSharedCodecDecoder(out, h, bh) bs2 = d.d.nextValueBytes([]byte{}) testSharedCodecDecoderAfter(d, x, bh) testDeepEqualErr(out, bs2, t, "nextvaluebytes-symbols-string") hbinc.AsSymbols = 2 } } // test out extensions with large output var xl, xl2 testUintToBytes xl = testUintToBytes(inOutLen) bs = testMarshalErr(xl, h, t, "-large-extension-bytes") testUnmarshalErr(&xl2, bs, h, t, "-large-extension-bytes") testDeepEqualErr(xl, xl2, t, "-large-extension-bytes") d, x = testSharedCodecDecoder(bs, h, bh) bs2 = d.d.nextValueBytes([]byte{}) testSharedCodecDecoderAfter(d, x, bh) testDeepEqualErr(bs, bs2, t, "nextvaluebytes-large-extension-bytes") xl = testUintToBytes(0) // so it's WriteExt returns nil bs = testMarshalErr(xl, h, t, "-large-extension-bytes") testUnmarshalErr(&xl2, bs, h, t, "-large-extension-bytes") testDeepEqualErr(xl, xl2, t, "-large-extension-bytes") } func testRandomFillRV(v reflect.Value) { fneg := func() int64 { i := rand.Intn(1) if i == 1 { return 1 } return -1 } if v.Type() == timeTyp { v.Set(reflect.ValueOf(timeToCompare1)) return } switch v.Kind() { case reflect.Invalid: case reflect.Ptr: if v.IsNil() { v.Set(reflect.New(v.Type().Elem())) } testRandomFillRV(v.Elem()) case reflect.Interface: if v.IsNil() { v.Set(reflect.ValueOf("nothing")) } else { testRandomFillRV(v.Elem()) } case reflect.Struct: for i, n := 0, v.NumField(); i < n; i++ { testRandomFillRV(v.Field(i)) } case reflect.Slice: if v.IsNil() { v.Set(reflect.MakeSlice(v.Type(), 4, 4)) } fallthrough case reflect.Array: for i, n := 0, v.Len(); i < n; i++ { testRandomFillRV(v.Index(i)) } case reflect.Map: if v.IsNil() { v.Set(reflect.MakeMap(v.Type())) } if v.Len() == 0 { kt, vt := v.Type().Key(), v.Type().Elem() for i := 0; i < 4; i++ { k0 := reflect.New(kt).Elem() v0 := reflect.New(vt).Elem() testRandomFillRV(k0) testRandomFillRV(v0) v.SetMapIndex(k0, v0) } } else { for _, k := range v.MapKeys() { testRandomFillRV(v.MapIndex(k)) } } case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64: v.SetInt(fneg() * rand.Int63n(127)) case reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64, reflect.Uintptr: v.SetUint(uint64(rand.Int63n(255))) case reflect.Bool: v.SetBool(fneg() == 1) case reflect.Float32, reflect.Float64: v.SetFloat(float64(fneg()) * float64(rand.Float32())) case reflect.Complex64, reflect.Complex128: v.SetComplex(complex(float64(fneg())*float64(rand.Float32()), 0)) case reflect.String: // ensure this string can test the extent of json string decoding v.SetString(strings.Repeat(strconv.FormatInt(rand.Int63n(99), 10), rand.Intn(8)) + "- ABC \x41=\x42 \u2318 - \r \b \f - \u2028 and \u2029 .") default: panic(fmt.Errorf("testRandomFillRV: unsupported type: %v", v.Kind())) } } func doTestTime(t *testing.T, h Handle) { defer testSetup(t, &h)() name := h.Name() // test time which uses the time.go implementation (ie Binc) var tt, tt2 time.Time // time in 1990 tt = time.Unix(20*366*24*60*60, 1000*900).In(time.FixedZone("UGO", -5*60*60)) // fmt.Printf("time tt: %v\n", tt) b := testMarshalErr(tt, h, t, "time-"+name) testUnmarshalErr(&tt2, b, h, t, "time-"+name) // per go documentation, test time with .Equal not == if !tt2.Equal(tt) { t.Logf("%s: values not equal: 1: %v, 2: %v", name, tt2, tt) t.FailNow() } // testDeepEqualErr(tt.UTC(), tt2, t, "time-"+name) testReleaseBytes(b) } func doTestUintToInt(t *testing.T, h Handle) { defer testSetup(t, &h)() name := h.Name() var golden = [...]int64{ 0, 1, 22, 333, 4444, 55555, 666666, // msgpack ones 24, 128, // standard ones math.MaxUint8, math.MaxUint8 + 4, math.MaxUint8 - 4, math.MaxUint16, math.MaxUint16 + 4, math.MaxUint16 - 4, math.MaxUint32, math.MaxUint32 + 4, math.MaxUint32 - 4, math.MaxInt8, math.MaxInt8 + 4, math.MaxInt8 - 4, math.MaxInt16, math.MaxInt16 + 4, math.MaxInt16 - 4, math.MaxInt32, math.MaxInt32 + 4, math.MaxInt32 - 4, math.MaxInt64, math.MaxInt64 - 4, } var i int64 var ui, ui2 uint64 var fi float64 var b []byte for _, v := range golden { i = v ui = 0 b = testMarshalErr(i, h, t, "int2uint-"+name) testUnmarshalErr(&ui, b, h, t, "int2uint-"+name) if ui != uint64(i) { t.Logf("%s: values not equal: %v, %v", name, ui, uint64(i)) t.FailNow() } testReleaseBytes(b) ui = uint64(i) i = 0 b = testMarshalErr(ui, h, t, "uint2int-"+name) testUnmarshalErr(&i, b, h, t, "uint2int-"+name) if i != int64(ui) { t.Logf("%s: values not equal: %v, %v", name, i, int64(ui)) t.FailNow() } testReleaseBytes(b) if v == math.MaxInt64 { ui = uint64(-(v - 1)) } else { ui = uint64(-v) } b = testMarshalErr(ui, h, t, "negint2uint-"+name) testUnmarshalErr(&ui2, b, h, t, "negint2uint-"+name) if ui2 != ui { t.Logf("%s: values not equal: %v, %v", name, ui2, ui) t.FailNow() } testReleaseBytes(b) fi = 0 b = testMarshalErr(i, h, t, "int2float-"+name) testUnmarshalErr(&fi, b, h, t, "int2float-"+name) testReleaseBytes(b) if fi != float64(i) { t.Logf("%s: values not equal: %v, %v", name, fi, float64(i)) t.FailNow() } } } func doTestDifferentMapOrSliceType(t *testing.T, h Handle) { if !testRecoverPanicToErr { t.Skip(testSkipIfNotRecoverPanicToErrMsg) } 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() // - maptype, slicetype: diff from map[string]intf, map[intf]intf or []intf, etc // include map[interface{}]string where some keys are []byte. // To test, take a sequence of []byte and string, and decode into []string and []interface. // Also, decode into map[string]string, map[string]interface{}, map[interface{}]string bh := testBasicHandle(h) defer func(oldM, oldS reflect.Type) { bh.MapType, bh.SliceType = oldM, oldS }(bh.MapType, bh.SliceType) // test for arrays first fnArr := func() { defer func(b1, b2 bool) { bh.StringToRaw, _ = b1, b2 }(bh.StringToRaw, false) bh.StringToRaw = false vi := []interface{}{ "hello 1", float64(111.0), "hello 3", float64(333.0), "hello 5", } var mi, mi2 map[string]float64 mi = make(map[string]float64) mi[vi[0].(string)] = vi[1].(float64) mi[vi[2].(string)] = vi[3].(float64) var v4a, v4a2 testMbsArr4T copy(v4a[:], vi) b := testMarshalErr(v4a, h, t, "-") testUnmarshalErr(&mi2, b, h, t, "-") testDeepEqualErr(mi2, mi, t, "-") testUnmarshalErr(&v4a2, b, h, t, "-") testDeepEqualErr(v4a2, v4a, t, "-") testReleaseBytes(b) var v0a, v0a2 testMbsArr0T copy(v0a[:], vi) mi2 = nil b = testMarshalErr(v0a, h, t, "-") testUnmarshalErr(&mi2, b, h, t, "-") testDeepEqualErr(mi2, map[string]float64{}, t, "-") testUnmarshalErr(&v0a2, b, h, t, "-") testDeepEqualErr(v0a2, v0a, t, "-") testReleaseBytes(b) { var v5a testMbsArr5T copy(v5a[:], vi) b, err := testMarshal(v5a, h) testReleaseBytes(b) if err == nil || !strings.Contains(err.Error(), "mapBySlice requires even slice length") { t.Logf("mapBySlice for odd length array fail: expected mapBySlice error, got: %v", err) t.FailNow() } } } fnArr() var b []byte var vi = []interface{}{ "hello 1", []byte("hello 2"), "hello 3", []byte("hello 4"), "hello 5", } var vs []string var v2i, v2s testMbsT var v2ss testMbsCustStrT // encode it as a map or as a slice for i, v := range vi { vv, ok := v.(string) if !ok { vv = string(v.([]byte)) } vs = append(vs, vv) v2i = append(v2i, v, strconv.FormatInt(int64(i+1), 10)) v2s = append(v2s, vv, strconv.FormatInt(int64(i+1), 10)) v2ss = append(v2ss, testCustomStringT(vv), testCustomStringT(strconv.FormatInt(int64(i+1), 10))) } var v2d interface{} // encode vs as a list, and decode into a list and compare var goldSliceS = []string{"hello 1", "hello 2", "hello 3", "hello 4", "hello 5"} var goldSliceI = []interface{}{"hello 1", "hello 2", "hello 3", "hello 4", "hello 5"} var goldSlice = []interface{}{goldSliceS, goldSliceI} for j, g := range goldSlice { bh.SliceType = reflect.TypeOf(g) name := fmt.Sprintf("slice-%s-%v", name, j+1) b = testMarshalErr(vs, h, t, name) v2d = nil // v2d = reflect.New(bh.SliceType).Elem().Interface() testUnmarshalErr(&v2d, b, h, t, name) testDeepEqualErr(v2d, goldSlice[j], t, name) testReleaseBytes(b) } // to ensure that we do not use fast-path for map[intf]string, use a custom string type (for goldMapIS). // this will allow us to test out the path that sees a []byte where a map has an interface{} type, // and convert it to a string for the decoded map key. // encode v2i as a map, and decode into a map and compare var goldMapSS = map[string]string{"hello 1": "1", "hello 2": "2", "hello 3": "3", "hello 4": "4", "hello 5": "5"} var goldMapSI = map[string]interface{}{"hello 1": "1", "hello 2": "2", "hello 3": "3", "hello 4": "4", "hello 5": "5"} var goldMapIS = map[interface{}]testCustomStringT{"hello 1": "1", "hello 2": "2", "hello 3": "3", "hello 4": "4", "hello 5": "5"} var goldMap = []interface{}{goldMapSS, goldMapSI, goldMapIS} for j, g := range goldMap { bh.MapType = reflect.TypeOf(g) name := fmt.Sprintf("map-%s-%v", name, j+1) // for formats that clearly differentiate binary from string, use v2i // else use the v2s (with all strings, no []byte) v2d = nil // v2d = reflect.New(bh.MapType).Elem().Interface() switch h.(type) { case *MsgpackHandle, *BincHandle, *CborHandle: b = testMarshalErr(v2i, h, t, name) testUnmarshalErr(&v2d, b, h, t, name) testDeepEqualErr(v2d, goldMap[j], t, name) testReleaseBytes(b) default: b = testMarshalErr(v2s, h, t, name) testUnmarshalErr(&v2d, b, h, t, name) testDeepEqualErr(v2d, goldMap[j], t, name) testReleaseBytes(b) b = testMarshalErr(v2ss, h, t, name) v2d = nil testUnmarshalErr(&v2d, b, h, t, name) testDeepEqualErr(v2d, goldMap[j], t, name) testReleaseBytes(b) } } // encode []byte and decode into one with len < cap. // get the slices > decDefSliceCap*2, so things like json can go much higher { var bs1 = []byte("abcdefghijklmnopqrstuvwxyz") b := testMarshalErr(bs1, h, t, "enc-bytes") var bs2 = make([]byte, 32, 32) testUnmarshalErr(bs2, b, h, t, "dec-bytes") testDeepEqualErr(bs1, bs2[:len(bs1)], t, "cmp-enc-dec-bytes") testUnmarshalErr(&bs2, b, h, t, "dec-bytes-2") testDeepEqualErr(bs1, bs2, t, "cmp-enc-dec-bytes-2") bs2 = bs2[:2:4] testUnmarshalErr(&bs2, b, h, t, "dec-bytes-2") testDeepEqualErr(bs1, bs2, t, "cmp-enc-dec-bytes-2") bs2 = nil testUnmarshalErr(&bs2, b, h, t, "dec-bytes-2") testDeepEqualErr(bs1, bs2, t, "cmp-enc-dec-bytes-2") bs1 = []byte{} b = testMarshalErr(bs1, h, t, "enc-bytes") bs2 = nil testUnmarshalErr(&bs2, b, h, t, "dec-bytes-2") testDeepEqualErr(bs1, bs2, t, "cmp-enc-dec-bytes-2") type Ti32 int32 v1 := []Ti32{ 9, 99, 999, 9999, 99999, 999999, 9, 99, 999, 9999, 99999, 999999, 9, 99, 999, 9999, 99999, 999999, } b = testMarshalErr(v1, h, t, "enc-Ti32") v2 := make([]Ti32, 20, 20) testUnmarshalErr(v2, b, h, t, "dec-Ti32") testDeepEqualErr(v1, v2[:len(v1)], t, "cmp-enc-dec-Ti32") testUnmarshalErr(&v2, b, h, t, "dec-Ti32-2") testDeepEqualErr(v1, v2, t, "cmp-enc-dec-Ti32-2") v2 = v2[:1:3] testUnmarshalErr(&v2, b, h, t, "dec-Ti32-2") testDeepEqualErr(v1, v2, t, "cmp-enc-dec-Ti32-2") v2 = nil testUnmarshalErr(&v2, b, h, t, "dec-Ti32-2") testDeepEqualErr(v1, v2, t, "cmp-enc-dec-Ti32-2") v1 = []Ti32{} b = testMarshalErr(v1, h, t, "enc-Ti32") v2 = nil testUnmarshalErr(&v2, b, h, t, "dec-Ti32-2") testDeepEqualErr(v1, v2, t, "cmp-enc-dec-Ti32-2") } } func doTestScalars(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 } // for each scalar: // - encode its ptr // - encode it (non-ptr) // - check that bytes are same // - make a copy (using reflect) // - check that same // - set zero on it // - check that its equal to 0 value // - decode into new // - compare to original bh := testBasicHandle(h) if !bh.Canonical { bh.Canonical = true defer func() { bh.Canonical = false }() } var bzero = testMarshalErr(nil, h, t, "nil-enc") vi := []interface{}{ 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), bool(false), time.Time{}, string(""), []byte(nil), } for _, v := range fastpathAv { vi = append(vi, reflect.Zero(v.rt).Interface()) } for _, v := range vi { rv := reflect.New(reflect.TypeOf(v)).Elem() testRandomFillRV(rv) v = rv.Interface() rv2 := reflect.New(rv.Type()) rv2.Elem().Set(rv) vp := rv2.Interface() var tname string switch rv.Kind() { case reflect.Map: tname = "map[" + rv.Type().Key().Name() + "]" + rv.Type().Elem().Name() case reflect.Slice: tname = "[]" + rv.Type().Elem().Name() default: tname = rv.Type().Name() } var b, b1, b2 []byte b1 = testMarshalErr(v, h, t, tname+"-enc") // store b1 into b, as b1 slice is reused for next marshal b = make([]byte, len(b1)) copy(b, b1) b2 = testMarshalErr(vp, h, t, tname+"-enc-ptr") testDeepEqualErr(b1, b2, t, tname+"-enc-eq") // decode the nil value into rv2, and test that it is the zero value setZero(vp) testDeepEqualErr(rv2.Elem().Interface(), reflect.Zero(rv.Type()).Interface(), t, tname+"-enc-eq-zero-ref") testUnmarshalErr(vp, b, h, t, tname+"-dec") testDeepEqualErr(rv2.Elem().Interface(), v, t, tname+"-dec-eq") // test that we can decode an encoded nil into it testUnmarshalErr(vp, bzero, h, t, tname+"-dec-from-enc-nil") testDeepEqualErr(rv2.Elem().Interface(), reflect.Zero(rv.Type()).Interface(), t, tname+"-dec-from-enc-nil") testReleaseBytes(b1) testReleaseBytes(b2) } // test setZero for *Raw and reflect.Value var r0 Raw var r = Raw([]byte("hello")) setZero(&r) testDeepEqualErr(r, r0, t, "raw-zeroed") r = Raw([]byte("hello")) var rv = reflect.ValueOf(&r) setZero(rv) // note: we cannot test reflect.Value's because they might point to different pointers // and reflect.DeepEqual doesn't honor that. // testDeepEqualErr(rv, reflect.ValueOf(&r0), t, "raw-reflect-zeroed") testDeepEqualErr(rv.Interface(), &r0, t, "raw-reflect-zeroed") testReleaseBytes(bzero) } func doTestIntfMapping(t *testing.T, h Handle) { defer testSetup(t, &h)() name := h.Name() rti := reflect.TypeOf((*testIntfMapI)(nil)).Elem() defer func() { testBasicHandle(h).Intf2Impl(rti, nil) }() type T9 struct { I testIntfMapI } for i, v := range []testIntfMapI{ // Use a valid string to test some extents of json string decoding &testIntfMapT1{"ABC \x41=\x42 \u2318 - \r \b \f - \u2028 and \u2029 ."}, testIntfMapT2{"DEF"}, } { if err := testBasicHandle(h).Intf2Impl(rti, reflect.TypeOf(v)); err != nil { t.Logf("Error mapping %v to %T", rti, v) t.FailNow() } var v1, v2 T9 v1 = T9{v} b := testMarshalErr(v1, h, t, name+"-enc-"+strconv.Itoa(i)) testUnmarshalErr(&v2, b, h, t, name+"-dec-"+strconv.Itoa(i)) testDeepEqualErr(v1, v2, t, name+"-dec-eq-"+strconv.Itoa(i)) testReleaseBytes(b) } } func doTestOmitempty(t *testing.T, h Handle) { defer testSetup(t, &h)() name := h.Name() if testBasicHandle(h).StructToArray { t.Skipf("skipping OmitEmpty test when StructToArray=true") } type T1 struct { A int `codec:"a"` B *int `codec:"b,omitempty"` C int `codec:"c,omitempty"` } type T2 struct { A int `codec:"a"` } var v1 T1 var v2 T2 b1 := testMarshalErr(v1, h, t, name+"-omitempty") b2 := testMarshalErr(v2, h, t, name+"-no-omitempty-trunc") testDeepEqualErr(b1, b2, t, name+"-omitempty-cmp") testReleaseBytes(b1) testReleaseBytes(b2) } func doTestMissingFields(t *testing.T, h Handle) { defer testSetup(t, &h)() name := h.Name() if codecgen { t.Skipf("skipping Missing Fields tests as it is not honored by codecgen") } if testBasicHandle(h).StructToArray { t.Skipf("skipping Missing Fields test when StructToArray=true") } // encode missingFielderT2, decode into missingFielderT1, encode it out again, decode into new missingFielderT2, compare v1 := missingFielderT2{S: "true seven eight", B: true, F: 777.0, I: -888} b1 := testMarshalErr(v1, h, t, name+"-missing-enc-2") var v2 missingFielderT1 testUnmarshalErr(&v2, b1, h, t, name+"-missing-dec-1") b2 := testMarshalErr(&v2, h, t, name+"-missing-enc-1") var v3 missingFielderT2 testUnmarshalErr(&v3, b2, h, t, name+"-missing-dec-2") testDeepEqualErr(v1, v3, t, name+"-missing-cmp-2") testReleaseBytes(b1) testReleaseBytes(b2) v4 := missingFielderT11{s1: "s111", S2: "S222"} b1 = testMarshalErr(v4, h, t, name+"-missing-enc-11") var m4 map[string]string testUnmarshalErr(&m4, b1, h, t, name+"-missing-dec-11") testDeepEqualErr(m4, map[string]string{"s1": "s111", "S2": "S222"}, t, name+"-missing-cmp-11") testReleaseBytes(b1) // test canonical interaction - with structs having some missing fields and some regular fields bh := testBasicHandle(h) defer func(c bool) { bh.Canonical = c }(bh.Canonical) bh.Canonical = true b1 = nil var s1 = struct { A int B int C int }{1, 2, 3} NewEncoderBytes(&b1, h).MustEncode(&s1) var s2 = struct { C int testMissingFieldsMap }{C: 3} s2.testMissingFieldsMap = testMissingFieldsMap{ m: map[string]interface{}{ "A": 1, "B": 2, }, } for i := 0; i < 16; i++ { b2 = nil NewEncoderBytes(&b2, h).MustEncode(&s2) if !bytes.Equal(b1, b2) { t.Fatalf("bytes differed:'%s' vs '%s'", b1, b2) } } } func doTestMaxDepth(t *testing.T, h Handle) { if !testRecoverPanicToErr { t.Skip(testSkipIfNotRecoverPanicToErrMsg) } defer testSetup(t, &h)() name := h.Name() type T struct { I interface{} // value to encode M int16 // maxdepth S bool // use swallow (decode into typed struct with only A1) E interface{} // error to find } type T1 struct { A1 *T1 } var table []T var sfunc = func(n int) (s [1]interface{}, s1 *[1]interface{}) { s1 = &s for i := 0; i < n; i++ { var s0 [1]interface{} s1[0] = &s0 s1 = &s0 } return // var s []interface{} // s = append(s, []interface{}) // s[0] = append(s[0], []interface{}) // s[0][0] = append(s[0][0], []interface{}) // s[0][0][0] = append(s[0][0][0], []interface{}) // s[0][0][0][0] = append(s[0][0][0][0], []interface{}) // return s } var mfunc = func(n int) (m map[string]interface{}, mlast map[string]interface{}) { m = make(map[string]interface{}) mlast = make(map[string]interface{}) m["A0"] = mlast for i := 1; i < n; i++ { m0 := make(map[string]interface{}) mlast["A"+strconv.FormatInt(int64(i), 10)] = m0 mlast = m0 } return } s, s1 := sfunc(5) m, _ := mfunc(5) m99, _ := mfunc(99) s1[0] = m table = append(table, T{s, 0, false, nil}) table = append(table, T{s, 256, false, nil}) table = append(table, T{s, 7, false, errMaxDepthExceeded}) table = append(table, T{s, 15, false, nil}) table = append(table, T{m99, 15, true, errMaxDepthExceeded}) table = append(table, T{m99, 215, true, nil}) defer func(n int16) { testBasicHandle(h).MaxDepth = n }(testBasicHandle(h).MaxDepth) for i, v := range table { testBasicHandle(h).MaxDepth = v.M b1 := testMarshalErr(v.I, h, t, name+"-maxdepth-enc"+strconv.FormatInt(int64(i), 10)) var err error v.S = false // MARKER: 20200925: swallow doesn't track depth anymore if v.S { var v2 T1 err = testUnmarshal(&v2, b1, h) } else { var v2 interface{} err = testUnmarshal(&v2, b1, h) } var err0 interface{} = err if err1, ok := err.(*codecError); ok { err0 = err1.err } if err0 != v.E { t.Logf("Unexpected error testing max depth for depth %d: expected %v, received %v", v.M, v.E, err) t.FailNow() } // decode into something that just triggers swallow testReleaseBytes(b1) } } func doTestMultipleEncDec(t *testing.T, h Handle) { defer testSetup(t, &h)() name := h.Name() // encode a string multiple times. // decode it multiple times. // ensure we get the value each time var s1 = "ugorji" var s2 = "nwoke" var s11, s21 string var buf bytes.Buffer e := NewEncoder(&buf, h) e.MustEncode(s1) e.MustEncode(s2) d := NewDecoder(&buf, h) d.MustDecode(&s11) d.MustDecode(&s21) testDeepEqualErr(s1, s11, t, name+"-multiple-encode") testDeepEqualErr(s2, s21, t, name+"-multiple-encode") } func doTestSelfExt(t *testing.T, h Handle) { defer testSetup(t, &h)() name := h.Name() var ts TestSelfExtImpl ts.S = "ugorji" ts.I = 5678 ts.B = true var ts2 TestSelfExtImpl bs := testMarshalErr(&ts, h, t, name) testUnmarshalErr(&ts2, bs, h, t, name) testDeepEqualErr(&ts, &ts2, t, name) testReleaseBytes(bs) } func doTestBytesEncodedAsArray(t *testing.T, h Handle) { defer testSetup(t, &h)() name := h.Name() // Need to test edge case where bytes are encoded as an array // (not using optimized []byte native format) // encode []int8 (or int32 or any numeric type) with all positive numbers // decode it into []byte var in = make([]int32, 128) var un = make([]uint8, 128) for i := range in { in[i] = int32(i) un[i] = uint8(i) } var out []byte bs := testMarshalErr(&in, h, t, name) testUnmarshalErr(&out, bs, h, t, name) testDeepEqualErr(un, out, t, name) testReleaseBytes(bs) } func doTestStrucEncDec(t *testing.T, h Handle) { defer testSetup(t, &h)() name := h.Name() { var ts1 = newTestStruc(2, testNumRepeatString, false, !testSkipIntf, testMapStringKeyOnly) var ts2 TestStruc bs := testMarshalErr(ts1, h, t, name) testUnmarshalErr(&ts2, bs, h, t, name) testDeepEqualErr(ts1, &ts2, t, name) testReleaseBytes(bs) } // Note: We cannot use TestStrucFlex because it has omitempty values, // Meaning that sometimes, encoded and decoded will not be same. // { // var ts1 = newTestStrucFlex(2, testNumRepeatString, false, !testSkipIntf, testMapStringKeyOnly) // var ts2 TestStrucFlex // bs := testMarshalErr(ts1, h, t, name) // fmt.Printf("\n\n%s\n\n", bs) // testUnmarshalErr(&ts2, bs, h, t, name) // testDeepEqualErr(ts1, &ts2, t, name) // } } func doTestStructKeyType(t *testing.T, h Handle) { defer testSetup(t, &h)() name := h.Name() mh, mok := h.(*MsgpackHandle) bch, bcok := h.(*BincHandle) bh := testBasicHandle(h) s2a := bh.StructToArray bh.StructToArray = false ir := bh.InterfaceReset bh.InterfaceReset = false var mfx bool if mok { mfx = mh.NoFixedNum mh.NoFixedNum = false } var bcsym uint8 if bcok { bcsym = bch.AsSymbols bch.AsSymbols = 2 // MARKER: should be 0 but binc symbols do not work well } defer func() { bh.StructToArray = s2a bh.InterfaceReset = ir if mok { mh.NoFixedNum = mfx } if bcok { bch.AsSymbols = bcsym } }() var bs1, bs2 []byte var m = make(map[interface{}]interface{}) fn := func(v interface{}) { v1 := reflect.New(reflect.TypeOf(v)).Elem().Interface() bs1 = testMarshalErr(v, h, t, "") testUnmarshalErr(&v1, bs1, h, t, "") testDeepEqualErr(v, v1, t, name+"") bs2 = testMarshalErr(m, h, t, "") // if _, ok := h.(*JsonHandle); ok { // xdebugf("bs1: %s, bs2: %s", bs1, bs2) // } // if bcok { // xdebug2f("-------------") // xdebugf("v: %#v, m: %#v", v, m) // xdebugf("bs1: %v", bs1) // xdebugf("bs2: %v", bs2) // xdebugf("bs1==bs2: %v", bytes.Equal(bs1, bs2)) // testDeepEqualErr(bs1, bs2, t, name+"") // xdebug2f("-------------") // return // } testDeepEqualErr(bs1, bs2, t, name+"") testReleaseBytes(bs1) testReleaseBytes(bs2) } fnclr := func() { for k := range m { delete(m, k) } } m["F"] = 90 fn(&testStrucKeyTypeT0{F: 90}) fnclr() m["FFFF"] = 100 fn(&testStrucKeyTypeT1{F: 100}) fnclr() m[int64(-1)] = 200 fn(&testStrucKeyTypeT2{F: 200}) fnclr() m[int64(1)] = 300 fn(&testStrucKeyTypeT3{F: 300}) fnclr() m[float64(2.5)] = 400 fn(&testStrucKeyTypeT4{F: 400}) fnclr() } func doTestRawToStringToRawEtc(t *testing.T, h Handle) { defer testSetup(t, &h)() // name := h.Name() // Tests: // - RawToString // - StringToRaw // - MapValueReset // - DeleteOnMapValue (skipped - no longer supported) bh := testBasicHandle(h) r2s := bh.RawToString s2r := bh.StringToRaw can := bh.Canonical mvr := bh.MapValueReset mh, mok := h.(*MsgpackHandle) _, jok := h.(*JsonHandle) defer func() { bh.RawToString = r2s bh.StringToRaw = s2r bh.Canonical = can bh.MapValueReset = mvr }() bh.Canonical = false var bs1, bs2 []byte // encode: StringToRaw // decode: RawToString // compare encoded v1 to encoded v2, while setting StringToRaw to b fne := func(v1, v2 interface{}, b bool) { bh.StringToRaw = b bs1 = testMarshalErr(v1, h, t, "") // bs1 = []byte(string(bs1)) bs2 = testMarshalErr(v2, h, t, "") testDeepEqualErr(bs1, bs2, t, "") testReleaseBytes(bs1) testReleaseBytes(bs2) } // encoded v1, decode naked and compare to v2 fnd := func(v1, v2 interface{}, bs2r, br2s, bwext bool) { bh.RawToString = br2s bh.StringToRaw = bs2r if mok { mh.RawToString = bwext } bs1 = testMarshalErr(v1, h, t, "") var vn interface{} testUnmarshalErr(&vn, bs1, h, t, "") testDeepEqualErr(vn, v2, t, "") testReleaseBytes(bs1) } sv0 := "value" bv0 := []byte(sv0) sv1 := sv0 bv1 := []byte(sv1) m1 := map[string]*string{"key": &sv1} m2 := map[string]*[]byte{"key": &bv1} // m3 := map[[3]byte]string{[3]byte{'k', 'e', 'y'}: sv0} m4 := map[[3]byte][]byte{[3]byte{'k', 'e', 'y'}: bv0} m5 := map[string][]byte{"key": bv0} // m6 := map[string]string{"key": sv0} m7 := map[interface{}]interface{}{"key": sv0} m8 := map[interface{}]interface{}{"key": bv0} // StringToRaw=true fne(m1, m4, true) // StringToRaw=false // compare encoded m2 to encoded m5 fne(m2, m5, false) // json doesn't work well with StringToRaw and RawToString // when dealing with interfaces, because it cannot decipher // that a string should be treated as base64. if jok { goto MAP_VALUE_RESET } // if msgpack, always set WriteExt = RawToString // StringToRaw=true (RawToString=true) // encoded m1, decode naked and compare to m5 fnd(m2, m7, true, true, true) // StringToRaw=true (RawToString=false) // encoded m1, decode naked and compare to m6 fnd(m1, m8, true, false, false) // StringToRaw=false, RawToString=true // encode m1, decode naked, and compare to m6 fnd(m2, m7, false, true, true) MAP_VALUE_RESET: // set MapValueReset, and then decode i sv2 := "value-new" m9 := map[string]*string{"key": &sv2} bs1 = testMarshalErr(m1, h, t, "") bh.MapValueReset = false testUnmarshalErr(&m9, bs1, h, t, "") // if !(m9["key"] == m1["key"] testDeepEqualErr(sv2, "value", t, "") testDeepEqualErr(&sv2, m9["key"], t, "") sv2 = "value-new" m9["key"] = &sv2 bh.MapValueReset = true testUnmarshalErr(&m9, bs1, h, t, "") testDeepEqualErr(sv2, "value-new", t, "") testDeepEqualErr("value", *(m9["key"]), t, "") // t1 = struct { // key string // }{ key: sv0 } // t2 := struct { // key []byte // }{ key: bv1 } testReleaseBytes(bs1) } // ----------------- func doTestJsonDecodeNonStringScalarInStringContext(t *testing.T, h Handle) { defer testSetup(t, &h)() var b = `{"s.true": "true", "b.true": true, "s.false": "false", "b.false": false, "s.10": "10", "i.10": 10, "i.-10": -10}` var golden = map[string]string{"s.true": "true", "b.true": "true", "s.false": "false", "b.false": "false", "s.10": "10", "i.10": "10", "i.-10": "-10"} var m map[string]string d := NewDecoderBytes([]byte(b), h) d.MustDecode(&m) if err := deepEqual(golden, m); err == nil { if testVerbose { t.Logf("++++ match: decoded: %#v", m) } } else { t.Logf("---- mismatch: %v ==> golden: %#v, decoded: %#v", err, golden, m) t.FailNow() } jh := h.(*JsonHandle) oldMapKeyAsString := jh.MapKeyAsString oldPreferFloat := jh.PreferFloat oldSignedInteger := jh.SignedInteger oldHTMLCharAsIs := jh.HTMLCharsAsIs oldMapType := jh.MapType defer func() { jh.MapKeyAsString = oldMapKeyAsString jh.PreferFloat = oldPreferFloat jh.SignedInteger = oldSignedInteger jh.HTMLCharsAsIs = oldHTMLCharAsIs jh.MapType = oldMapType }() jh.MapType = mapIntfIntfTyp jh.HTMLCharsAsIs = false jh.MapKeyAsString = true jh.PreferFloat = false jh.SignedInteger = false // Also test out decoding string values into naked interface b = `{"true": true, "false": false, "null": null, "7700000000000000000": 7700000000000000000}` const num = 7700000000000000000 // 77 var golden2 = map[interface{}]interface{}{ true: true, false: false, nil: nil, // uint64(num):uint64(num), } fn := func() { d.ResetBytes([]byte(b)) var mf interface{} d.MustDecode(&mf) if err := deepEqual(golden2, mf); err != nil { t.Logf("---- mismatch: %v ==> golden: %#v, decoded: %#v", err, golden2, mf) t.FailNow() } } golden2[uint64(num)] = uint64(num) fn() delete(golden2, uint64(num)) jh.SignedInteger = true golden2[int64(num)] = int64(num) fn() delete(golden2, int64(num)) jh.SignedInteger = false jh.PreferFloat = true golden2[float64(num)] = float64(num) fn() delete(golden2, float64(num)) jh.PreferFloat = false } func doTestJsonEncodeIndent(t *testing.T, h Handle) { defer testSetup(t, &h)() v := TestSimplish{ Ii: -794, Ss: `A Man is after the new line after new line and tab `, } v2 := v v.Mm = make(map[string]*TestSimplish) for i := 0; i < len(v.Ar); i++ { v3 := v2 v3.Ii += (i * 4) v3.Ss = fmt.Sprintf("%d - %s", v3.Ii, v3.Ss) if i%2 == 0 { v.Ar[i] = &v3 } // v3 = v2 v.Sl = append(v.Sl, &v3) v.Mm[strconv.FormatInt(int64(i), 10)] = &v3 } jh := h.(*JsonHandle) oldcan := jh.Canonical oldIndent := jh.Indent oldS2A := jh.StructToArray defer func() { jh.Canonical = oldcan jh.Indent = oldIndent jh.StructToArray = oldS2A }() jh.Canonical = true jh.Indent = -1 jh.StructToArray = false var bs []byte NewEncoderBytes(&bs, jh).MustEncode(&v) txt1Tab := string(bs) bs = nil jh.Indent = 120 NewEncoderBytes(&bs, jh).MustEncode(&v) txtSpaces := string(bs) // fmt.Printf("\n-----------\n%s\n------------\n%s\n-------------\n", txt1Tab, txtSpaces) goldenResultTab := `{ "Ar": [ { "Ar": [ null, null ], "Ii": -794, "Mm": null, "Sl": null, "Ss": "-794 - A Man is\nafter the new line\n\tafter new line and tab\n" }, null ], "Ii": -794, "Mm": { "0": { "Ar": [ null, null ], "Ii": -794, "Mm": null, "Sl": null, "Ss": "-794 - A Man is\nafter the new line\n\tafter new line and tab\n" }, "1": { "Ar": [ null, null ], "Ii": -790, "Mm": null, "Sl": null, "Ss": "-790 - A Man is\nafter the new line\n\tafter new line and tab\n" } }, "Sl": [ { "Ar": [ null, null ], "Ii": -794, "Mm": null, "Sl": null, "Ss": "-794 - A Man is\nafter the new line\n\tafter new line and tab\n" }, { "Ar": [ null, null ], "Ii": -790, "Mm": null, "Sl": null, "Ss": "-790 - A Man is\nafter the new line\n\tafter new line and tab\n" } ], "Ss": "A Man is\nafter the new line\n\tafter new line and tab\n" }` if txt1Tab != goldenResultTab { t.Logf("decoded indented with tabs != expected: \nexpected: %s\nencoded: %s", goldenResultTab, txt1Tab) t.FailNow() } if txtSpaces != strings.Replace(goldenResultTab, "\t", strings.Repeat(" ", 120), -1) { t.Logf("decoded indented with spaces != expected: \nexpected: %s\nencoded: %s", goldenResultTab, txtSpaces) t.FailNow() } } func __doTestBufioDecReader(t *testing.T, bufsize int) { bufsizehalf := (bufsize + 1) / 2 // try to read 85 bytes in chunks of 7 at a time. var s = strings.Repeat("01234'56789 ", 5) // fmt.Printf("s: %s\n", s) var r = strings.NewReader(s) var br bufioDecReader var blist bytesFreelist br.reset(r, bufsize, &blist) b, err := ioutil.ReadAll(br.r) if err != nil { panic(err) } var s2 = string(b) // fmt.Printf("s==s2: %v, len(s): %v, len(b): %v, len(s2): %v\n", s == s2, len(s), len(b), len(s2)) if s != s2 { t.Logf("not equal: \ns: %s\ns2: %s", s, s2) t.FailNow() } // Now, test search functions for skip, readTo and readUntil // readUntil ', readTo ', skip whitespace. 3 times in a loop, each time compare the token and/or outs // readUntil: see: 56789 var out []byte var token byte br.reset(strings.NewReader(s), bufsizehalf, &blist) // println() for _, v2 := range [...]string{ `01234'`, `56789 01234'`, `56789 01234'`, `56789 01234'`, } { out = br.readUntil('\'') testDeepEqualErr(string(out), v2[:len(v2)-1], t, "-") // fmt.Printf("readUntil: out: `%s`\n", out) } br.reset(strings.NewReader(s), bufsizehalf, &blist) // println() // 20200915: readTo is not longer available // for range [4]struct{}{} { // out = br.readTo(&numCharBitset) // testDeepEqualErr(string(out), `01234`, t, "-") // // fmt.Printf("readTo: out: `%s`\n", out) // out = br.readUntil('\'', true) // testDeepEqualErr(string(out), "'", t, "-") // // fmt.Printf("readUntil: out: `%s`\n", out) // out = br.readTo(&numCharBitset) // testDeepEqualErr(string(out), `56789`, t, "-") // // fmt.Printf("readTo: out: `%s`\n", out) // out = br.readUntil('0', true) // testDeepEqualErr(string(out), ` 0`, t, "-") // // fmt.Printf("readUntil: out: `%s`\n", out) // br.unreadn1() // } br.reset(strings.NewReader(s), bufsizehalf, &blist) for range [4]struct{}{} { token = br.skipWhitespace() // br.skip(&whitespaceCharBitset) testDeepEqualErr(token, byte('0'), t, "-") out = br.readUntil(' ') testDeepEqualErr(string(out), `1234'56789`, t, "-") } } func doTestPreferArrayOverSlice(t *testing.T, h Handle) { defer testSetup(t, &h)() // encode a slice, decode it with PreferArrayOverSlice // if codecgen, skip the test (as codecgen doesn't work with PreferArrayOverSlice) if codecgen { t.Skip("skipping ... prefer array over slice is not supported in codecgen mode") } bh := testBasicHandle(h) paos := bh.PreferArrayOverSlice styp := bh.SliceType defer func() { bh.PreferArrayOverSlice = paos bh.SliceType = styp }() bh.PreferArrayOverSlice = true bh.SliceType = reflect.TypeOf(([]bool)(nil)) s2 := [4]bool{true, false, true, false} s := s2[:] var v interface{} bs := testMarshalErr(s, h, t, t.Name()) testUnmarshalErr(&v, bs, h, t, t.Name()) testDeepEqualErr(s2, v, t, t.Name()) testReleaseBytes(bs) } func doTestZeroCopyBytes(t *testing.T, h Handle) { defer testSetup(t, &h)() // jsonhandle and cborhandle with indefiniteLength do not support inline bytes, so skip them. if _, ok := h.(*JsonHandle); ok { t.Skipf("skipping ... zero copy bytes not supported by json handle") } if ch, ok := h.(*CborHandle); ok && ch.IndefiniteLength { t.Skipf("skipping ... zero copy bytes not supported by cbor handle with IndefiniteLength=true") } bh := testBasicHandle(h) zc := bh.ZeroCopy defer func() { bh.ZeroCopy = zc }() bh.ZeroCopy = true s := []byte("hello") var v []byte bs := testMarshalErr(s, h, t, t.Name()) // Note: this test only works for decoding from []byte, so cannot use testUnmarshalErr NewDecoderBytes(bs, h).MustDecode(&v) // testUnmarshalErr(&v, bs, h, t, t.Name()) // validate that bs and s points into the bs stream for i := range bs { if &bs[i] == &v[0] { return } } // if not match, then a failure happened. if len(bs) > 0 && len(v) > 0 { t.Logf("%s: ZeroCopy=true, but decoded (%p) is not slice of input: (%p)", h.Name(), &v[0], &bs[0]) } else { t.Logf("%s: ZeroCopy=true, but decoded OR input slice is empty: %v, %v", h.Name(), v, bs) } testReleaseBytes(bs) t.FailNow() } func doTestNextValueBytes(t *testing.T, h Handle) { defer testSetup(t, &h)() bh := testBasicHandle(h) // - encode uint, int, float, bool, struct, map, slice, string - all separated by nil // - use nextvaluebytes to grab he's got each one, and decode it, and compare var inputs = []interface{}{ uint64(7777), int64(9999), float64(12.25), true, false, map[string]uint64{"1": 1, "22": 22, "333": 333, "4444": 4444}, []string{"1", "22", "333", "4444"}, // use *TestStruc, not *TestStrucFlex, as *TestStrucFlex is harder to compare with deep equal // Remember: *TestStruc was separated for this reason, affording comparing against other libraries newTestStruc(testDepth, testNumRepeatString, false, false, true), "1223334444", } var out []byte for i, v := range inputs { _ = i bs := testMarshalErr(v, h, t, "nextvaluebytes") out = append(out, bs...) bs2 := testMarshalErr(nil, h, t, "nextvaluebytes") out = append(out, bs2...) testReleaseBytes(bs) testReleaseBytes(bs2) } // out = append(out, []byte("----")...) var valueBytes = make([][]byte, len(inputs)*2) d, oldReadBufferSize := testSharedCodecDecoder(out, h, testBasicHandle(h)) for i := 0; i < len(inputs)*2; i++ { valueBytes[i] = d.d.nextValueBytes([]byte{}) // bs := d.d.nextValueBytes([]byte{}) // valueBytes[i] = make([]byte, len(bs)) // copy(valueBytes[i], bs) } if testUseIoEncDec >= 0 { bh.ReaderBufferSize = oldReadBufferSize } defer func(b bool) { bh.InterfaceReset = b }(bh.InterfaceReset) bh.InterfaceReset = false var result interface{} for i := 0; i < len(inputs); i++ { // result = reflect.New(reflect.TypeOf(inputs[i])).Elem().Interface() result = reflect.Zero(reflect.TypeOf(inputs[i])).Interface() testUnmarshalErr(&result, valueBytes[i*2], h, t, "nextvaluebytes") testDeepEqualErr(inputs[i], result, t, "nextvaluebytes-1") result = nil testUnmarshalErr(&result, valueBytes[(i*2)+1], h, t, "nextvaluebytes") testDeepEqualErr(nil, result, t, "nextvaluebytes-2") } } func doTestNumbers(t *testing.T, h Handle) { defer testSetup(t, &h)() __doTestIntegers(t, h) __doTestFloats(t, h) __doTestIntegerFloatConversions(t, h) } func __doTestIntegers(t *testing.T, h Handle) { // handle SignedInteger=true|false // decode into an interface{} bh := testBasicHandle(h) oldSignedInteger := bh.SignedInteger var oldPreferFloat bool var oldNoFixedNum bool jh, jok := h.(*JsonHandle) mh, mok := h.(*MsgpackHandle) if jok { oldPreferFloat = jh.PreferFloat } if mok { oldNoFixedNum = mh.NoFixedNum mh.NoFixedNum = true } defer func() { bh.SignedInteger = oldSignedInteger if jok { jh.PreferFloat = oldPreferFloat } if mok { mh.NoFixedNum = oldNoFixedNum } }() // var vi int64 // var ui uint64 var ii interface{} for _, v := range testUintsToParse { if jok { jh.PreferFloat = false } b := testMarshalErr(v, h, t, "test-integers") ii = nil bh.SignedInteger = true testUnmarshalErr(&ii, b, h, t, "test-integers") testDeepEqualErr(ii, int64(v), t, "test-integers-signed") ii = nil bh.SignedInteger = false testUnmarshalErr(&ii, b, h, t, "test-integers") testDeepEqualErr(ii, uint64(v), t, "test-integers-unsigned") ii = nil if jok { jh.PreferFloat = true testUnmarshalErr(&ii, b, h, t, "test-integers") testDeepEqualErr(ii, float64(v), t, "test-integers-float") } testReleaseBytes(b) } } var testUintsToParse = []uint64{ // Note: use large integers, as some formats store small integers in an agnostic // way, where its not clear if signed or unsigned. 2, 2048, 1<<63 - 4, 1800000000e-2, 18000000e+2, 4.56e+4, // tests float32 exact parsing 4.56e+16, } var testFloatsToParse = []float64{ 3, math.NaN(), math.Inf(1), math.Inf(-1), 4.56e+4, // tests float32 exact parsing 4.56e+18, // float32 parsing - exp > 10 4.56e+10, 4.56e+30, 1.01234567890123456789e+30, 1.32e+5, 1.32e-5, 0e+01234567890123456789, 1.7976931348623157e308, -1.7976931348623157e+308, 1e308, 1e-308, 1.694649e-317, // 1e-4294967296, 2.2250738585072012e-308, 4.630813248087435e+307, 1.00000000000000011102230246251565404236316680908203125, 1.00000000000000033306690738754696212708950042724609375, } func __doTestFloats(t *testing.T, h Handle) { _, jok := h.(*JsonHandle) f64s := testFloatsToParse const unusedVal = 9999 // use this as a marker // marshall it, unmarshal it, compare to original // Note: JSON encodes NaN, inf, -inf as null, which is decoded as zero value (ie 0). for _, f64 := range f64s { { f := f64 var w float64 = unusedVal b := testMarshalErr(f, h, t, "test-floats-enc") testUnmarshalErr(&w, b, h, t, "test-floats-dec") // we only check json for float64, as it doesn't differentiate if (jok && (math.IsNaN(f64) || math.IsInf(f64, 0)) && w != 0) || (!jok && w != f && !math.IsNaN(float64(f))) { t.Logf("error testing float64: %v, decoded as: %v", f, w) t.FailNow() } var wi interface{} testUnmarshalErr(&wi, b, h, t, "test-floats-dec") if (jok && (math.IsNaN(f64) || math.IsInf(f64, 0)) && wi != nil) || (!jok && wi.(float64) != f && !math.IsNaN(float64(f))) { t.Logf("error testing float64: %v, decoded as: %v", f, wi) t.FailNow() } testReleaseBytes(b) } { f := float32(f64) var w float32 = unusedVal b := testMarshalErr(f, h, t, "test-floats-enc") // xdebug2f("test float: of %v, encoded as: %s", f, b) testUnmarshalErr(&w, b, h, t, "test-floats-dec") if (jok && (math.IsNaN(f64) || math.IsInf(f64, 0)) && w != 0) || (!jok && w != f && !math.IsNaN(float64(f))) { t.Logf("error testing float32: %v, decoded as: %v", f, w) t.FailNow() } testReleaseBytes(b) } } } func __doTestIntegerFloatConversions(t *testing.T, h Handle) { if !testRecoverPanicToErr { t.Skip(testSkipIfNotRecoverPanicToErrMsg) } type tI struct{ N int } type tU struct{ N uint } type tF struct{ N float64 } type elem struct { in interface{} out interface{} err string } tests := []elem{ // good {tI{5}, tF{5.0}, ""}, {tU{5}, tF{5.0}, ""}, {tF{5.0}, tU{5}, ""}, {tF{5.0}, tI{5}, ""}, {tF{-5.0}, tI{-5}, ""}, // test negative number into unsigned integer {tI{-5}, tU{5}, "error"}, {tF{-5.0}, tU{5}, "error"}, // test fractional float into integer {tF{-5.7}, tU{5}, "error"}, {tF{-5.7}, tI{5}, "error"}, } for _, v := range tests { r := reflect.New(reflect.TypeOf(v.out)) b := testMarshalErr(v.in, h, t, "") err := testUnmarshal(r.Interface(), b, h) if v.err == "" { testDeepEqualErr(err, nil, t, "") testDeepEqualErr(r.Elem().Interface(), v.out, t, "") } else if err == nil { t.Logf("expecting an error but didn't receive any, with in: %v, out: %v, expecting err matching: %v", v.in, v.out, v.err) t.FailNow() } } } func doTestStructFieldInfoToArray(t *testing.T, h Handle) { if !testRecoverPanicToErr { t.Skip(testSkipIfNotRecoverPanicToErrMsg) } defer testSetup(t, &h)() bh := testBasicHandle(h) defer func(b bool) { bh.CheckCircularRef = b }(bh.CheckCircularRef) bh.CheckCircularRef = true var vs = Sstructsmall{A: 99} var vb = Sstructbig{ A: 77, B: true, c: "ccc 3 ccc", Ssmallptr: &vs, Ssmall: vs, } vb.Sptr = &vb vba := SstructbigToArray{ A: vb.A, B: vb.B, c: vb.c, Ssmallptr: vb.Ssmallptr, Ssmall: vb.Ssmall, Sptr: vb.Sptr, } var b []byte var err error if !codecgen { // codecgen doesn't support CheckCircularRef, and these types are codecgen'ed b, err = testMarshal(&vba, h) testReleaseBytes(b) if err == nil || !strings.Contains(err.Error(), "circular reference found") { t.Logf("expect circular reference error, got: %v", err) t.FailNow() } } vb2 := vb vb.Sptr = nil // so we stop having the circular reference error vba.Sptr = &vb2 var ss []interface{} // bh.CheckCircularRef = false b = testMarshalErr(&vba, h, t, "-") testUnmarshalErr(&ss, b, h, t, "-") testDeepEqualErr(ss[1], true, t, "-") testReleaseBytes(b) } func doTestDesc(t *testing.T, h Handle, m map[byte]string) { defer testSetup(t, &h)() for k, v := range m { if s := h.desc(k); s != v { t.Logf("error describing descriptor: '%q' i.e. 0x%x, expected '%s', got '%s'", k, k, v, s) t.FailNow() } } } func TestBufioDecReader(t *testing.T) { doTestBufioDecReader(t) } func doTestBufioDecReader(t *testing.T) { defer testSetup(t, nil)() __doTestBufioDecReader(t, 13) __doTestBufioDecReader(t, 3) __doTestBufioDecReader(t, 5) __doTestBufioDecReader(t, 127) } func TestAtomic(t *testing.T) { defer testSetup(t, nil)() // load, store, load, confirm if true { var a atomicTypeInfoSlice l := a.load() if l != nil { t.Logf("atomic fail: %T, expected load return nil, received: %v", a, l) t.FailNow() } l = append(l, rtid2ti{}) a.store(l) l = a.load() if len(l) != 1 { t.Logf("atomic fail: %T, expected load to have length 1, received: %d", a, len(l)) t.FailNow() } } if true { var a atomicRtidFnSlice l := a.load() if l != nil { t.Logf("atomic fail: %T, expected load return nil, received: %v", a, l) t.FailNow() } l = append(l, codecRtidFn{}) a.store(l) l = a.load() if len(l) != 1 { t.Logf("atomic fail: %T, expected load to have length 1, received: %d", a, len(l)) t.FailNow() } } if true { var a atomicClsErr l := a.load() if l.err != nil { t.Logf("atomic fail: %T, expected load return clsErr = nil, received: %v", a, l.err) t.FailNow() } l.err = io.EOF a.store(l) l = a.load() if l.err != io.EOF { t.Logf("atomic fail: %T, expected clsErr = io.EOF, received: %v", a, l.err) t.FailNow() } } } // ----------- func doTestJsonLargeInteger(t *testing.T, h Handle) { if !testRecoverPanicToErr { t.Skip(testSkipIfNotRecoverPanicToErrMsg) } defer testSetup(t, &h)() jh := h.(*JsonHandle) for _, i := range []uint8{'L', 'A', 0} { for _, j := range []interface{}{ int64(1 << 60), -int64(1 << 60), 0, 1 << 20, -(1 << 20), uint64(1 << 60), uint(0), uint(1 << 20), int64(1840000e-2), uint64(1840000e+2), } { __doTestJsonLargeInteger(t, j, i, jh) } } oldIAS := jh.IntegerAsString defer func() { jh.IntegerAsString = oldIAS }() jh.IntegerAsString = 0 type tt struct { s string canI, canUi bool i int64 ui uint64 } var i int64 var ui uint64 var err error var d *Decoder = NewDecoderBytes(nil, jh) for _, v := range []tt{ {"0", true, true, 0, 0}, {"0000", true, true, 0, 0}, {"0.00e+2", true, true, 0, 0}, {"000e-2", true, true, 0, 0}, {"0.00e-2", true, true, 0, 0}, {"9223372036854775807", true, true, math.MaxInt64, math.MaxInt64}, // maxint64 {"92233720368547758.07e+2", true, true, math.MaxInt64, math.MaxInt64}, // maxint64 {"922337203685477580700e-2", true, true, math.MaxInt64, math.MaxInt64}, // maxint64 {"9223372.036854775807E+12", true, true, math.MaxInt64, math.MaxInt64}, // maxint64 {"9223372036854775807000000000000E-12", true, true, math.MaxInt64, math.MaxInt64}, // maxint64 {"0.9223372036854775807E+19", true, true, math.MaxInt64, math.MaxInt64}, // maxint64 {"92233720368547758070000000000000000000E-19", true, true, math.MaxInt64, math.MaxInt64}, // maxint64 {"0.000009223372036854775807E+24", true, true, math.MaxInt64, math.MaxInt64}, // maxint64 {"9223372036854775807000000000000000000000000E-24", true, true, math.MaxInt64, math.MaxInt64}, // maxint64 {"-9223372036854775808", true, false, math.MinInt64, 0}, // minint64 {"-92233720368547758.08e+2", true, false, math.MinInt64, 0}, // minint64 {"-922337203685477580800E-2", true, false, math.MinInt64, 0}, // minint64 {"-9223372.036854775808e+12", true, false, math.MinInt64, 0}, // minint64 {"-9223372036854775808000000000000E-12", true, false, math.MinInt64, 0}, // minint64 {"-0.9223372036854775808e+19", true, false, math.MinInt64, 0}, // minint64 {"-92233720368547758080000000000000000000E-19", true, false, math.MinInt64, 0}, // minint64 {"-0.000009223372036854775808e+24", true, false, math.MinInt64, 0}, // minint64 {"-9223372036854775808000000000000000000000000E-24", true, false, math.MinInt64, 0}, // minint64 {"18446744073709551615", false, true, 0, math.MaxUint64}, // maxuint64 {"18446744.073709551615E+12", false, true, 0, math.MaxUint64}, // maxuint64 {"18446744073709551615000000000000E-12", false, true, 0, math.MaxUint64}, // maxuint64 {"0.000018446744073709551615E+24", false, true, 0, math.MaxUint64}, // maxuint64 {"18446744073709551615000000000000000000000000E-24", false, true, 0, math.MaxUint64}, // maxuint64 // Add test for limit of uint64 where last digit is 0 {"18446744073709551610", false, true, 0, math.MaxUint64 - 5}, // maxuint64 {"18446744.073709551610E+12", false, true, 0, math.MaxUint64 - 5}, // maxuint64 {"18446744073709551610000000000000E-12", false, true, 0, math.MaxUint64 - 5}, // maxuint64 {"0.000018446744073709551610E+24", false, true, 0, math.MaxUint64 - 5}, // maxuint64 {"18446744073709551610000000000000000000000000E-24", false, true, 0, math.MaxUint64 - 5}, // maxuint64 // {"", true, true}, } { if v.s == "" { continue } d.ResetBytes([]byte(v.s)) err = d.Decode(&ui) if (v.canUi && err != nil) || (!v.canUi && err == nil) || (v.canUi && err == nil && v.ui != ui) { t.Logf("Failing to decode %s (as unsigned): %v", v.s, err) t.FailNow() } d.ResetBytes([]byte(v.s)) err = d.Decode(&i) if (v.canI && err != nil) || (!v.canI && err == nil) || (v.canI && err == nil && v.i != i) { t.Logf("Failing to decode %s (as signed): %v", v.s, err) t.FailNow() } } } func doTestJsonInvalidUnicode(t *testing.T, h Handle) { if !testRecoverPanicToErr { t.Skip(testSkipIfNotRecoverPanicToErrMsg) } defer testSetup(t, &h)() // t.Skipf("new json implementation does not handle bad unicode robustly") jh := h.(*JsonHandle) var err error // ---- test unmarshal --- var m = map[string]string{ `"\udc49\u0430abc"`: "\uFFFDabc", `"\udc49\u0430"`: "\uFFFD", `"\udc49abc"`: "\uFFFDabc", `"\udc49"`: "\uFFFD", `"\udZ49\u0430abc"`: "\uFFFD\u0430abc", `"\udcG9\u0430"`: "\uFFFD\u0430", `"\uHc49abc"`: "\uFFFDabc", `"\uKc49"`: "\uFFFD", } for k, v := range m { // call testUnmarshal directly, so we can check for EOF // testUnmarshalErr(&s, []byte(k), jh, t, "-") var s string err = testUnmarshal(&s, []byte(k), jh) if err != nil { if err == io.EOF { continue } t.Logf("%s: unmarshal failed: %v", "-", err) t.FailNow() } if s != v { t.Logf("unmarshal: not equal: %q, %q", v, s) t.FailNow() } } // test some valid edge cases m = map[string]string{ `"az\uD834\udD1E"`: "az𝄞", `"n\ud834\uDD1en"`: "n\U0001D11En", // "\uf09d849e", // "\UD834DD1E" // U+1DD1E g clef `"a\\\"\/\"\b\f\n\r\"\tz"`: "a\\\"/\"\b\f\n\r\"\tz", } for k, v := range m { var s string err = testUnmarshal(&s, []byte(k), jh) if err != nil { t.Logf("%s: unmarshal failed: %v", "-", err) t.FailNow() } if s != v { t.Logf("unmarshal: not equal: %q, %q", v, s) t.FailNow() } } // ---- test marshal --- var b = []byte{'"', 0xef, 0xbf, 0xbd} // this is " and unicode.ReplacementChar (as bytes) var m2 = map[string][]byte{ string([]byte{0xef, 0xbf, 0xbd}): append(b, '"'), string([]byte{0xef, 0xbf, 0xbd, 0x0, 0x0}): append(b, `\u0000\u0000"`...), "a\\\"/\"\b\f\n\r\"\tz": []byte(`"a\\\"/\"\b\f\n\r\"\tz"`), // our encoder doesn't support encoding using only ascii ... so need to use the utf-8 version // "n\U0001D11En": []byte(`"n\uD834\uDD1En"`), // "az𝄞": []byte(`"az\uD834\uDD1E"`), "n\U0001D11En": []byte(`"n𝄞n"`), "az𝄞": []byte(`"az𝄞"`), string([]byte{129, 129}): []byte(`"\uFFFD\uFFFD"`), } for k, v := range m2 { b, err = testMarshal(k, jh) if err != nil { t.Logf("%s: marshal failed: %v", "-", err) t.FailNow() } if !bytes.Equal(b, v) { t.Logf("marshal: not equal: %q, %q", v, b) t.FailNow() } testReleaseBytes(b) } } func doTestJsonNumberParsing(t *testing.T, h Handle) { defer testSetup(t, &h)() parseInt64_reader := func(r readFloatResult) (v int64, fail bool) { u, fail := parseUint64_reader(r) if fail { return } if r.neg { v = -int64(u) } else { v = int64(u) } return } for _, f64 := range testFloatsToParse { // using large prec might make a non-exact float ..., while small prec might make lose some precision. // However, we can do a check, and only check if the (u)int64 and float64 can be converted to one another // without losing any precision. Then we can use any precision for the tests. var precs = [...]int{32, -1} var r readFloatResult var fail bool var fs uint64 var fsi int64 var fint, ffrac float64 _ = ffrac var bv []byte for _, prec := range precs { f := f64 if math.IsNaN(f64) || math.IsInf(f64, 0) { goto F32 } bv = strconv.AppendFloat(nil, f, 'E', prec, 64) if fs, err := parseFloat64_custom(bv); err != nil || fs != f { t.Logf("float64 -> float64 error (prec: %v) parsing '%s', got %v, expected %v: %v", prec, bv, fs, f, err) t.FailNow() } // try decoding it a uint64 or int64 fint, ffrac = math.Modf(f) // xdebug2f(">> fint: %v (ffrac: %v) as uint64: %v as float64: %v", fint, ffrac, uint64(fint), float64(uint64(fint))) bv = strconv.AppendFloat(bv[:0], fint, 'E', prec, 64) if f < 0 || fint != float64(uint64(fint)) { goto F64i } r = readFloat(bv, fi64u) fail = !r.ok if r.ok { fs, fail = parseUint64_reader(r) } if fail || fs != uint64(fint) { t.Logf("float64 -> uint64 error (prec: %v, fail: %v) parsing '%s', got %v, expected %v", prec, fail, bv, fs, uint64(fint)) t.FailNow() } F64i: if fint != float64(int64(fint)) { goto F32 } r = readFloat(bv, fi64u) fail = !r.ok if r.ok { fsi, fail = parseInt64_reader(r) } if fail || fsi != int64(fint) { t.Logf("float64 -> int64 error (prec: %v, fail: %v) parsing '%s', got %v, expected %v", prec, fail, bv, fsi, int64(fint)) t.FailNow() } F32: f32 := float32(f64) f64n := float64(f32) if !(math.IsNaN(f64n) || math.IsInf(f64n, 0)) { bv := strconv.AppendFloat(nil, f64n, 'E', prec, 32) if fs, err := parseFloat32_custom(bv); err != nil || fs != f32 { t.Logf("float32 -> float32 error (prec: %v) parsing '%s', got %v, expected %v: %v", prec, bv, fs, f32, err) t.FailNow() } } } } for _, v := range testUintsToParse { const prec int = 32 // test with precisions of 32 so formatting doesn't truncate what doesn't fit into float v = uint64(float64(v)) // use a value that when converted back and forth, remains the same bv := strconv.AppendFloat(nil, float64(v), 'E', prec, 64) r := readFloat(bv, fi64u) if r.ok { if fs, fail := parseUint64_reader(r); fail || fs != v { t.Logf("uint64 -> uint64 error (prec: %v, fail: %v) parsing '%s', got %v, expected %v", prec, fail, bv, fs, v) t.FailNow() } } else { t.Logf("uint64 -> uint64 not ok (prec: %v) parsing '%s', expected %v", prec, bv, v) t.FailNow() } vi := int64(v) bv = strconv.AppendFloat(nil, float64(vi), 'E', prec, 64) r = readFloat(bv, fi64u) if r.ok { if fs, fail := parseInt64_reader(r); fail || fs != vi { t.Logf("int64 -> int64 error (prec: %v, fail: %v) parsing '%s', got %v, expected %v", prec, fail, bv, fs, vi) t.FailNow() } } else { t.Logf("int64 -> int64 not ok (prec: %v) parsing '%s', expected %v", prec, bv, vi) t.FailNow() } } { var f64 float64 = 64.0 var f32 float32 = 32.0 var i int = 11 var u64 uint64 = 128 for _, s := range []string{`""`, `null`} { b := []byte(s) testUnmarshalErr(&f64, b, h, t, "") testDeepEqualErr(f64, float64(0), t, "") testUnmarshalErr(&f32, b, h, t, "") testDeepEqualErr(f32, float32(0), t, "") testUnmarshalErr(&i, b, h, t, "") testDeepEqualErr(i, int(0), t, "") testUnmarshalErr(&u64, b, h, t, "") testDeepEqualErr(u64, uint64(0), t, "") testUnmarshalErr(&u64, b, h, t, "") testDeepEqualErr(u64, uint64(0), t, "") } } } func doTestMsgpackDecodeMapAndExtSizeMismatch(t *testing.T, h Handle) { if !testRecoverPanicToErr { t.Skip(testSkipIfNotRecoverPanicToErrMsg) } defer testSetup(t, &h)() fn := func(t *testing.T, b []byte, v interface{}) { if err := NewDecoderBytes(b, h).Decode(v); err != io.EOF && err != io.ErrUnexpectedEOF { t.Fatalf("expected EOF or ErrUnexpectedEOF, got %v", err) } } // a map claiming to have 0x10eeeeee KV pairs, but only has 1. var b = []byte{0xdf, 0x10, 0xee, 0xee, 0xee, 0x1, 0xa1, 0x1} var m1 map[int]string var m2 map[int][]byte fn(t, b, &m1) fn(t, b, &m2) // an extension claiming to have 0x7fffffff bytes, but only has 1. b = []byte{0xc9, 0x7f, 0xff, 0xff, 0xff, 0xda, 0x1} var a interface{} fn(t, b, &a) // b = []byte{0x00} // var s testSelferRecur // fn(t, b, &s) } func TestMapRangeIndex(t *testing.T) { defer testSetup(t, nil)() // t.Skip() type T struct { I int S string B bool M map[int]T } t1 := T{I: 1, B: true, S: "11", M: map[int]T{11: T{I: 11}}} t2 := T{I: 1, B: true, S: "12", M: map[int]T{12: T{I: 12}}} // ------ var m1 = map[string]*T{ "11": &t1, "12": &t2, } var m1c = make(map[string]T) for k, v := range m1 { m1c[k] = *v } fnrv := func(r1, r2 reflect.Value) reflect.Value { if r1.IsValid() { return r1 } return r2 } // var vx reflect.Value mt := reflect.TypeOf(m1) rvk := mapAddrLoopvarRV(mt.Key(), mt.Key().Kind()) rvv := mapAddrLoopvarRV(mt.Elem(), mt.Elem().Kind()) var it mapIter mapRange(&it, reflect.ValueOf(m1), rvk, rvv, true) for it.Next() { k := fnrv(it.Key(), rvk).Interface().(string) v := fnrv(it.Value(), rvv).Interface().(*T) testDeepEqualErr(m1[k], v, t, "map-key-eq-it-key") if _, ok := m1c[k]; ok { delete(m1c, k) } else { t.Logf("unexpected key in map: %v", k) t.FailNow() } } it.Done() testDeepEqualErr(len(m1c), 0, t, "all-keys-not-consumed") // ------ var m2 = map[*T]T{ &t1: t1, &t2: t2, } var m2c = make(map[*T]*T) for k := range m2 { m2c[k] = k } mt = reflect.TypeOf(m2) rvk = mapAddrLoopvarRV(mt.Key(), mt.Key().Kind()) rvv = mapAddrLoopvarRV(mt.Elem(), mt.Elem().Kind()) it = mapIter{} // zero it out first, before calling mapRange mapRange(&it, reflect.ValueOf(m2), rvk, rvv, true) for it.Next() { k := fnrv(it.Key(), rvk).Interface().(*T) v := fnrv(it.Value(), rvv).Interface().(T) testDeepEqualErr(m2[k], v, t, "map-key-eq-it-key") if _, ok := m2c[k]; ok { delete(m2c, k) } else { t.Logf("unexpected key in map: %v", k) t.FailNow() } } it.Done() testDeepEqualErr(len(m2c), 0, t, "all-keys-not-consumed") // ---- test mapGet fnTestMapIndex := func(mi ...interface{}) { for _, m0 := range mi { m := reflect.ValueOf(m0) mkt := m.Type().Key() mvt := m.Type().Elem() kfast := mapKeyFastKindFor(mkt.Kind()) rvv := mapAddrLoopvarRV(mvt, mvt.Kind()) visindirect := mapStoresElemIndirect(mvt.Size()) visref := refBitset.isset(byte(mvt.Kind())) for _, k := range m.MapKeys() { mg := mapGet(m, k, rvv, kfast, visindirect, visref).Interface() testDeepEqualErr(m.MapIndex(k).Interface(), mg, t, "map-index-eq") } } } fnTestMapIndex(m1, m1c, m2, m2c) // var s string = "hello" // var tt = &T{I: 3} // ttTyp := reflect.TypeOf(tt) // _, _ = tt, ttTyp // mv := reflect.ValueOf(m) // it := mapRange(mv, reflect.ValueOf(&s).Elem(), reflect.ValueOf(&tt).Elem(), true) //ok // it := mapRange(mv, reflect.New(reflect.TypeOf(s)).Elem(), reflect.New(reflect.TypeOf(T{})).Elem(), true) // ok // it := mapRange(mv, reflect.New(reflect.TypeOf(s)).Elem(), reflect.New(ttTyp.Elem()), true) // !ok // it := mapRange(mv, reflect.New(reflect.TypeOf(s)).Elem(), reflect.New(reflect.TypeOf(T{})), true) !ok // it := mapRange(mv, reflect.New(reflect.TypeOf(s)).Elem(), reflect.New(reflect.TypeOf(T{})).Elem(), true) // ok // fmt.Printf("key: %#v\n", it.Key()) // fmt.Printf("exp: %#v\n", mv.MapIndex(it.Key())) // fmt.Printf("val: %#v\n", it.Value()) // testDeepEqualErr(mv.MapIndex(it.Key()), it.Value().Interface() } // ---------- func TestBincCodecsTable(t *testing.T) { doTestCodecTableOne(t, testBincH) } func TestBincCodecsMisc(t *testing.T) { doTestCodecMiscOne(t, testBincH) } func TestBincCodecsEmbeddedPointer(t *testing.T) { doTestCodecEmbeddedPointer(t, testBincH) } func TestBincStdEncIntf(t *testing.T) { doTestStdEncIntf(t, testBincH) } func TestSimpleCodecsTable(t *testing.T) { doTestCodecTableOne(t, testSimpleH) } func TestSimpleCodecsMisc(t *testing.T) { doTestCodecMiscOne(t, testSimpleH) } func TestSimpleCodecsEmbeddedPointer(t *testing.T) { doTestCodecEmbeddedPointer(t, testSimpleH) } func TestSimpleStdEncIntf(t *testing.T) { doTestStdEncIntf(t, testSimpleH) } func TestMsgpackCodecsTable(t *testing.T) { doTestCodecTableOne(t, testMsgpackH) } func TestMsgpackCodecsMisc(t *testing.T) { doTestCodecMiscOne(t, testMsgpackH) } func TestMsgpackCodecsEmbeddedPointer(t *testing.T) { doTestCodecEmbeddedPointer(t, testMsgpackH) } func TestMsgpackStdEncIntf(t *testing.T) { doTestStdEncIntf(t, testMsgpackH) } func TestCborCodecsTable(t *testing.T) { doTestCodecTableOne(t, testCborH) } func TestCborCodecsMisc(t *testing.T) { doTestCodecMiscOne(t, testCborH) } func TestCborCodecsEmbeddedPointer(t *testing.T) { doTestCodecEmbeddedPointer(t, testCborH) } func TestCborCodecChan(t *testing.T) { doTestCodecChan(t, testCborH) } func TestCborStdEncIntf(t *testing.T) { doTestStdEncIntf(t, testCborH) } func TestJsonCodecsTable(t *testing.T) { doTestCodecTableOne(t, testJsonH) } func TestJsonCodecsMisc(t *testing.T) { doTestCodecMiscOne(t, testJsonH) } func TestJsonCodecsEmbeddedPointer(t *testing.T) { doTestCodecEmbeddedPointer(t, testJsonH) } func TestJsonCodecChan(t *testing.T) { doTestCodecChan(t, testJsonH) } func TestJsonStdEncIntf(t *testing.T) { doTestStdEncIntf(t, testJsonH) } // ----- Raw --------- func TestJsonRaw(t *testing.T) { doTestRawValue(t, testJsonH) } func TestBincRaw(t *testing.T) { doTestRawValue(t, testBincH) } func TestMsgpackRaw(t *testing.T) { doTestRawValue(t, testMsgpackH) } func TestSimpleRaw(t *testing.T) { doTestRawValue(t, testSimpleH) } func TestCborRaw(t *testing.T) { doTestRawValue(t, testCborH) } // ----- ALL (framework based) ----- func TestAllEncCircularRef(t *testing.T) { doTestEncCircularRef(t, testCborH) } func TestAllAnonCycle(t *testing.T) { doTestAnonCycle(t, testCborH) } func TestAllErrWriter(t *testing.T) { doTestAllErrWriter(t, testCborH, testJsonH) } // ----- RPC custom ----- func TestMsgpackRpcSpec(t *testing.T) { doTestCodecRpcOne(t, MsgpackSpecRpc, testMsgpackH, true, 0) } // ----- RPC ----- func TestBincRpcGo(t *testing.T) { doTestCodecRpcOne(t, GoRpc, testBincH, true, 0) } func TestSimpleRpcGo(t *testing.T) { doTestCodecRpcOne(t, GoRpc, testSimpleH, true, 0) } func TestMsgpackRpcGo(t *testing.T) { doTestCodecRpcOne(t, GoRpc, testMsgpackH, true, 0) } func TestCborRpcGo(t *testing.T) { doTestCodecRpcOne(t, GoRpc, testCborH, true, 0) } func TestJsonRpcGo(t *testing.T) { doTestCodecRpcOne(t, GoRpc, testJsonH, true, 0) } // ----- OTHERS ----- func TestBincMapEncodeForCanonical(t *testing.T) { t.Skipf("skipping ... needs investigation") // MARKER: testing fails??? Need to research doTestMapEncodeForCanonical(t, testBincH) } func TestSimpleMapEncodeForCanonical(t *testing.T) { doTestMapEncodeForCanonical(t, testSimpleH) } func TestMsgpackMapEncodeForCanonical(t *testing.T) { doTestMapEncodeForCanonical(t, testMsgpackH) } func TestCborMapEncodeForCanonical(t *testing.T) { doTestMapEncodeForCanonical(t, testCborH) } func TestJsonMapEncodeForCanonical(t *testing.T) { doTestMapEncodeForCanonical(t, testJsonH) } func TestBincUnderlyingType(t *testing.T) { testCodecUnderlyingType(t, testBincH) } func TestJsonSwallowAndZero(t *testing.T) { doTestSwallowAndZero(t, testJsonH) } func TestCborSwallowAndZero(t *testing.T) { doTestSwallowAndZero(t, testCborH) } func TestMsgpackSwallowAndZero(t *testing.T) { doTestSwallowAndZero(t, testMsgpackH) } func TestBincSwallowAndZero(t *testing.T) { doTestSwallowAndZero(t, testBincH) } func TestSimpleSwallowAndZero(t *testing.T) { doTestSwallowAndZero(t, testSimpleH) } func TestJsonRawExt(t *testing.T) { doTestRawExt(t, testJsonH) } func TestCborRawExt(t *testing.T) { doTestRawExt(t, testCborH) } func TestMsgpackRawExt(t *testing.T) { doTestRawExt(t, testMsgpackH) } func TestBincRawExt(t *testing.T) { doTestRawExt(t, testBincH) } func TestSimpleRawExt(t *testing.T) { doTestRawExt(t, testSimpleH) } func TestJsonMapStructKey(t *testing.T) { doTestMapStructKey(t, testJsonH) } func TestCborMapStructKey(t *testing.T) { doTestMapStructKey(t, testCborH) } func TestMsgpackMapStructKey(t *testing.T) { doTestMapStructKey(t, testMsgpackH) } func TestBincMapStructKey(t *testing.T) { doTestMapStructKey(t, testBincH) } func TestSimpleMapStructKey(t *testing.T) { doTestMapStructKey(t, testSimpleH) } func TestJsonDecodeNilMapValue(t *testing.T) { doTestDecodeNilMapValue(t, testJsonH) } func TestCborDecodeNilMapValue(t *testing.T) { doTestDecodeNilMapValue(t, testCborH) } func TestMsgpackDecodeNilMapValue(t *testing.T) { doTestDecodeNilMapValue(t, testMsgpackH) } func TestBincDecodeNilMapValue(t *testing.T) { doTestDecodeNilMapValue(t, testBincH) } func TestSimpleDecodeNilMapValue(t *testing.T) { doTestDecodeNilMapValue(t, testSimpleH) } func TestJsonEmbeddedFieldPrecedence(t *testing.T) { doTestEmbeddedFieldPrecedence(t, testJsonH) } func TestCborEmbeddedFieldPrecedence(t *testing.T) { doTestEmbeddedFieldPrecedence(t, testCborH) } func TestMsgpackEmbeddedFieldPrecedence(t *testing.T) { doTestEmbeddedFieldPrecedence(t, testMsgpackH) } func TestBincEmbeddedFieldPrecedence(t *testing.T) { doTestEmbeddedFieldPrecedence(t, testBincH) } func TestSimpleEmbeddedFieldPrecedence(t *testing.T) { doTestEmbeddedFieldPrecedence(t, testSimpleH) } func TestJsonLargeContainerLen(t *testing.T) { doTestLargeContainerLen(t, testJsonH) } func TestCborLargeContainerLen(t *testing.T) { doTestLargeContainerLen(t, testCborH) } func TestMsgpackLargeContainerLen(t *testing.T) { doTestLargeContainerLen(t, testMsgpackH) } func TestBincLargeContainerLen(t *testing.T) { doTestLargeContainerLen(t, testBincH) } func TestSimpleLargeContainerLen(t *testing.T) { doTestLargeContainerLen(t, testSimpleH) } func TestJsonTime(t *testing.T) { doTestTime(t, testJsonH) } func TestCborTime(t *testing.T) { doTestTime(t, testCborH) } func TestMsgpackTime(t *testing.T) { doTestTime(t, testMsgpackH) } func TestBincTime(t *testing.T) { doTestTime(t, testBincH) } func TestSimpleTime(t *testing.T) { doTestTime(t, testSimpleH) } func TestJsonUintToInt(t *testing.T) { doTestUintToInt(t, testJsonH) } func TestCborUintToInt(t *testing.T) { doTestUintToInt(t, testCborH) } func TestMsgpackUintToInt(t *testing.T) { doTestUintToInt(t, testMsgpackH) } func TestBincUintToInt(t *testing.T) { doTestUintToInt(t, testBincH) } func TestSimpleUintToInt(t *testing.T) { doTestUintToInt(t, testSimpleH) } func TestJsonDifferentMapOrSliceType(t *testing.T) { doTestDifferentMapOrSliceType(t, testJsonH) } func TestCborDifferentMapOrSliceType(t *testing.T) { doTestDifferentMapOrSliceType(t, testCborH) } func TestMsgpackDifferentMapOrSliceType(t *testing.T) { doTestDifferentMapOrSliceType(t, testMsgpackH) } func TestBincDifferentMapOrSliceType(t *testing.T) { doTestDifferentMapOrSliceType(t, testBincH) } func TestSimpleDifferentMapOrSliceType(t *testing.T) { doTestDifferentMapOrSliceType(t, testSimpleH) } func TestJsonScalars(t *testing.T) { doTestScalars(t, testJsonH) } func TestCborScalars(t *testing.T) { doTestScalars(t, testCborH) } func TestMsgpackScalars(t *testing.T) { doTestScalars(t, testMsgpackH) } func TestBincScalars(t *testing.T) { doTestScalars(t, testBincH) } func TestSimpleScalars(t *testing.T) { doTestScalars(t, testSimpleH) } func TestJsonOmitempty(t *testing.T) { doTestOmitempty(t, testJsonH) } func TestCborOmitempty(t *testing.T) { doTestOmitempty(t, testCborH) } func TestMsgpackOmitempty(t *testing.T) { doTestOmitempty(t, testMsgpackH) } func TestBincOmitempty(t *testing.T) { doTestOmitempty(t, testBincH) } func TestSimpleOmitempty(t *testing.T) { doTestOmitempty(t, testSimpleH) } func TestJsonIntfMapping(t *testing.T) { doTestIntfMapping(t, testJsonH) } func TestCborIntfMapping(t *testing.T) { doTestIntfMapping(t, testCborH) } func TestMsgpackIntfMapping(t *testing.T) { doTestIntfMapping(t, testMsgpackH) } func TestBincIntfMapping(t *testing.T) { doTestIntfMapping(t, testBincH) } func TestSimpleIntfMapping(t *testing.T) { doTestIntfMapping(t, testSimpleH) } func TestJsonMissingFields(t *testing.T) { doTestMissingFields(t, testJsonH) } func TestCborMissingFields(t *testing.T) { doTestMissingFields(t, testCborH) } func TestMsgpackMissingFields(t *testing.T) { doTestMissingFields(t, testMsgpackH) } func TestBincMissingFields(t *testing.T) { doTestMissingFields(t, testBincH) } func TestSimpleMissingFields(t *testing.T) { doTestMissingFields(t, testSimpleH) } func TestJsonMaxDepth(t *testing.T) { doTestMaxDepth(t, testJsonH) } func TestCborMaxDepth(t *testing.T) { doTestMaxDepth(t, testCborH) } func TestMsgpackMaxDepth(t *testing.T) { doTestMaxDepth(t, testMsgpackH) } func TestBincMaxDepth(t *testing.T) { doTestMaxDepth(t, testBincH) } func TestSimpleMaxDepth(t *testing.T) { doTestMaxDepth(t, testSimpleH) } func TestJsonSelfExt(t *testing.T) { doTestSelfExt(t, testJsonH) } func TestCborSelfExt(t *testing.T) { doTestSelfExt(t, testCborH) } func TestMsgpackSelfExt(t *testing.T) { doTestSelfExt(t, testMsgpackH) } func TestBincSelfExt(t *testing.T) { doTestSelfExt(t, testBincH) } func TestSimpleSelfExt(t *testing.T) { doTestSelfExt(t, testSimpleH) } func TestJsonBytesEncodedAsArray(t *testing.T) { doTestBytesEncodedAsArray(t, testJsonH) } func TestCborBytesEncodedAsArray(t *testing.T) { doTestBytesEncodedAsArray(t, testCborH) } func TestMsgpackBytesEncodedAsArray(t *testing.T) { doTestBytesEncodedAsArray(t, testMsgpackH) } func TestBincBytesEncodedAsArray(t *testing.T) { doTestBytesEncodedAsArray(t, testBincH) } func TestSimpleBytesEncodedAsArray(t *testing.T) { doTestBytesEncodedAsArray(t, testSimpleH) } func TestJsonStrucEncDec(t *testing.T) { doTestStrucEncDec(t, testJsonH) } func TestCborStrucEncDec(t *testing.T) { doTestStrucEncDec(t, testCborH) } func TestMsgpackStrucEncDec(t *testing.T) { doTestStrucEncDec(t, testMsgpackH) } func TestBincStrucEncDec(t *testing.T) { doTestStrucEncDec(t, testBincH) } func TestSimpleStrucEncDec(t *testing.T) { doTestStrucEncDec(t, testSimpleH) } func TestJsonRawToStringToRawEtc(t *testing.T) { doTestRawToStringToRawEtc(t, testJsonH) } func TestCborRawToStringToRawEtc(t *testing.T) { doTestRawToStringToRawEtc(t, testCborH) } func TestMsgpackRawToStringToRawEtc(t *testing.T) { doTestRawToStringToRawEtc(t, testMsgpackH) } func TestBincRawToStringToRawEtc(t *testing.T) { doTestRawToStringToRawEtc(t, testBincH) } func TestSimpleRawToStringToRawEtc(t *testing.T) { doTestRawToStringToRawEtc(t, testSimpleH) } func TestJsonStructKeyType(t *testing.T) { doTestStructKeyType(t, testJsonH) } func TestCborStructKeyType(t *testing.T) { doTestStructKeyType(t, testCborH) } func TestMsgpackStructKeyType(t *testing.T) { doTestStructKeyType(t, testMsgpackH) } func TestBincStructKeyType(t *testing.T) { doTestStructKeyType(t, testBincH) } func TestSimpleStructKeyType(t *testing.T) { doTestStructKeyType(t, testSimpleH) } func TestJsonPreferArrayOverSlice(t *testing.T) { doTestPreferArrayOverSlice(t, testJsonH) } func TestCborPreferArrayOverSlice(t *testing.T) { doTestPreferArrayOverSlice(t, testCborH) } func TestMsgpackPreferArrayOverSlice(t *testing.T) { doTestPreferArrayOverSlice(t, testMsgpackH) } func TestBincPreferArrayOverSlice(t *testing.T) { doTestPreferArrayOverSlice(t, testBincH) } func TestSimplePreferArrayOverSlice(t *testing.T) { doTestPreferArrayOverSlice(t, testSimpleH) } func TestJsonZeroCopyBytes(t *testing.T) { doTestZeroCopyBytes(t, testJsonH) } func TestCborZeroCopyBytes(t *testing.T) { doTestZeroCopyBytes(t, testCborH) } func TestMsgpackZeroCopyBytes(t *testing.T) { doTestZeroCopyBytes(t, testMsgpackH) } func TestBincZeroCopyBytes(t *testing.T) { doTestZeroCopyBytes(t, testBincH) } func TestSimpleZeroCopyBytes(t *testing.T) { doTestZeroCopyBytes(t, testSimpleH) } func TestJsonNextValueBytes(t *testing.T) { doTestNextValueBytes(t, testJsonH) } func TestCborNextValueBytes(t *testing.T) { // x := testCborH.IndefiniteLength // defer func() { testCborH.IndefiniteLength = x }() // xdebugf(">>>>> TestCborNextValueBytes: IndefiniteLength = false") // testCborH.IndefiniteLength = false // doTestNextValueBytes(t, testCborH) // xdebugf(">>>>> TestCborNextValueBytes: IndefiniteLength = true") // testCborH.IndefiniteLength = true doTestNextValueBytes(t, testCborH) } func TestMsgpackNextValueBytes(t *testing.T) { doTestNextValueBytes(t, testMsgpackH) } func TestBincNextValueBytes(t *testing.T) { doTestNextValueBytes(t, testBincH) } func TestSimpleNextValueBytes(t *testing.T) { doTestNextValueBytes(t, testSimpleH) } func TestJsonNumbers(t *testing.T) { doTestNumbers(t, testJsonH) } func TestCborNumbers(t *testing.T) { doTestNumbers(t, testCborH) } func TestMsgpackNumbers(t *testing.T) { doTestNumbers(t, testMsgpackH) } func TestBincNumbers(t *testing.T) { doTestNumbers(t, testBincH) } func TestSimpleNumbers(t *testing.T) { doTestNumbers(t, testSimpleH) } func TestJsonDesc(t *testing.T) { doTestDesc(t, testJsonH, map[byte]string{'"': `"`, '{': `{`, '}': `}`, '[': `[`, ']': `]`}) } func TestCborDesc(t *testing.T) { m := make(map[byte]string) for k, v := range cbordescMajorNames { // if k == cborMajorSimpleOrFloat { m[k<<5] = "nil" } m[k<<5] = v } for k, v := range cbordescSimpleNames { m[k] = v } delete(m, cborMajorSimpleOrFloat<<5) doTestDesc(t, testCborH, m) } func TestMsgpackDesc(t *testing.T) { m := make(map[byte]string) for k, v := range mpdescNames { m[k] = v } m[mpPosFixNumMin] = "int" m[mpFixStrMin] = "string|bytes" m[mpFixArrayMin] = "array" m[mpFixMapMin] = "map" m[mpFixExt1] = "ext" doTestDesc(t, testMsgpackH, m) } func TestBincDesc(t *testing.T) { m := make(map[byte]string) for k, v := range bincdescVdNames { m[k<<4] = v } for k, v := range bincdescSpecialVsNames { m[k] = v } delete(m, bincVdSpecial<<4) doTestDesc(t, testBincH, m) } func TestSimpleDesc(t *testing.T) { doTestDesc(t, testSimpleH, simpledescNames) } func TestJsonStructFieldInfoToArray(t *testing.T) { doTestStructFieldInfoToArray(t, testJsonH) } func TestCborStructFieldInfoToArray(t *testing.T) { doTestStructFieldInfoToArray(t, testCborH) } func TestMsgpackStructFieldInfoToArray(t *testing.T) { doTestStructFieldInfoToArray(t, testMsgpackH) } func TestBincStructFieldInfoToArray(t *testing.T) { doTestStructFieldInfoToArray(t, testBincH) } func TestSimpleStructFieldInfoToArray(t *testing.T) { doTestStructFieldInfoToArray(t, testSimpleH) } // -------- func TestMultipleEncDec(t *testing.T) { doTestMultipleEncDec(t, testJsonH) } func TestJsonEncodeIndent(t *testing.T) { doTestJsonEncodeIndent(t, testJsonH) } func TestJsonDecodeNonStringScalarInStringContext(t *testing.T) { doTestJsonDecodeNonStringScalarInStringContext(t, testJsonH) } func TestJsonLargeInteger(t *testing.T) { doTestJsonLargeInteger(t, testJsonH) } func TestJsonInvalidUnicode(t *testing.T) { doTestJsonInvalidUnicode(t, testJsonH) } func TestJsonNumberParsing(t *testing.T) { doTestJsonNumberParsing(t, testJsonH) } func TestMsgpackDecodeMapAndExtSizeMismatch(t *testing.T) { doTestMsgpackDecodeMapAndExtSizeMismatch(t, testMsgpackH) } go-1.2.8/codec/codecgen.go000066400000000000000000000007771435255326100153230ustar00rootroot00000000000000// 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 codecgen || generated // +build codecgen generated package codec // this file sets the codecgen variable to true // when the build tag codecgen is set. // // some tests depend on knowing whether in the context of codecgen or not. // For example, some tests should be skipped during codecgen e.g. missing fields tests. func init() { codecgen = true } go-1.2.8/codec/codecgen/000077500000000000000000000000001435255326100147615ustar00rootroot00000000000000go-1.2.8/codec/codecgen/README.md000066400000000000000000000037561435255326100162530ustar00rootroot00000000000000# codecgen tool Generate is given a list of *.go files to parse, and an output file (fout), codecgen will create an output file __file.go__ which contains `codec.Selfer` implementations for the named types found in the files parsed. Using codecgen is very straightforward. **Download and install the tool** `go get -u github.com/ugorji/go/codec/codecgen` **Run the tool on your files** The command line format is: `codecgen [options] (-o outfile) (infile ...)` ```sh % codecgen -? Usage of codecgen: -c="github.com/ugorji/go/codec": codec path -o="": out file -d="": random identifier for use in generated code (help reduce changes when files are regenerated) -nx=false: do not support extensions (use when you know no extensions are used) -r=".*": regex for type name to match -nr="": regex for type name to exclude -rt="": tags for go run -st="codec,json": struct tag keys to introspect -t="": build tag to put in file -u=false: Use unsafe, e.g. to avoid unnecessary allocation on []byte->string -x=false: keep temp file % codecgen -o values_codecgen.go values.go values2.go moretypedefs.go ``` **Limitations** codecgen caveats: - Canonical option. If Canonical=true, codecgen'ed code will delegate encoding maps to reflection-based code. This is due to the runtime work needed to marshal a map in canonical mode. - CheckCircularRef option. When encoding a struct, a circular reference can lead to a stack overflow. If CheckCircularRef=true, codecgen'ed code will delegate encoding structs to reflection-based code. - MissingFielder implementation. If a type implements MissingFielder, a Selfer is not generated (with a warning message). Statically reproducing the runtime work needed to extract the missing fields and marshal them along with the struct fields, while handling the Canonical=true special case, was onerous to implement. **More Information** Please see the [blog article](http://ugorji.net/blog/go-codecgen) for more information on how to use the tool. go-1.2.8/codec/codecgen/gen.go000066400000000000000000000364751435255326100161000ustar00rootroot00000000000000// 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. // codecgen generates static implementations of the encoder and decoder functions // for a given type, bypassing reflection, and giving some performance benefits in terms of // wall and cpu time, and memory usage. // // Benchmarks (as of Dec 2018) show that codecgen gives about // // - for binary formats (cbor, etc): 25% on encoding and 30% on decoding to/from []byte // - for text formats (json, etc): 15% on encoding and 25% on decoding to/from []byte // // Note that (as of Dec 2018) codecgen completely ignores // // - MissingFielder interface // (if you types implements it, codecgen ignores that) // - decode option PreferArrayOverSlice // (we cannot dynamically create non-static arrays without reflection) // // In explicit package terms: codecgen generates codec.Selfer implementations for a set of types. package main import ( "bufio" "bytes" "errors" "flag" "fmt" "go/ast" "go/parser" "go/token" "math/rand" "os" "os/exec" "path/filepath" "regexp" "runtime/debug" "strconv" "strings" "text/template" "time" ) // MARKER: keep in sync with ../gen.go (genVersion) and ../go.mod (module version) const ( codecgenModuleVersion = `1.2.7` // default version - overridden if available via go.mod minimumCodecVersion = `1.2.7` genVersion = 25 ) const genCodecPkg = "codec1978" // MARKER: keep in sync with ../gen.go const genFrunMainTmpl = `// +build ignore // Code generated - temporary main package for codecgen - DO NOT EDIT. package main {{ if .Types }}import "{{ .ImportPath }}"{{ end }} func main() { {{ $.PackageName }}.CodecGenTempWrite{{ .RandString }}() } ` // const genFrunPkgTmpl = `// +build codecgen const genFrunPkgTmpl = ` // Code generated - temporary package for codecgen - DO NOT EDIT. package {{ $.PackageName }} import ( {{ if not .CodecPkgFiles }}{{ .CodecPkgName }} "{{ .CodecImportPath }}"{{ end }} "os" "reflect" "bytes" "strings" "go/format" "fmt" ) func codecGenBoolPtr(b bool) *bool { return &b } func CodecGenTempWrite{{ .RandString }}() { os.Remove("{{ .OutFile }}") fout, err := os.Create("{{ .OutFile }}") if err != nil { panic(err) } defer fout.Close() var bJO, bS2A, bOE *bool _, _, _ = bJO, bS2A, bOE {{ if .JsonOnly }}bJO = codecGenBoolPtr({{ boolvar .JsonOnly }}){{end}} {{ if .StructToArrayAlways }}bS2A = codecGenBoolPtr({{ boolvar .StructToArrayAlways }}){{end}} {{ if .OmitEmptyAlways }}bOE = codecGenBoolPtr({{ boolvar .OmitEmptyAlways }}){{end}} var typs []reflect.Type var typ reflect.Type var numfields int {{ range $index, $element := .Types }} var t{{ $index }} {{ . }} typ = reflect.TypeOf(t{{ $index }}) typs = append(typs, typ) if typ.Kind() == reflect.Struct { numfields += typ.NumField() } else { numfields += 1 } {{ end }} // println("initializing {{ .OutFile }}, buf size: {{ .AllFilesSize }}*16", // {{ .AllFilesSize }}*16, "num fields: ", numfields) var out = bytes.NewBuffer(make([]byte, 0, numfields*1024)) // {{ .AllFilesSize }}*16 var warnings = {{ if not .CodecPkgFiles }}{{ .CodecPkgName }}.{{ end }}Gen(out, "{{ .BuildTag }}", "{{ .PackageName }}", "{{ .RandString }}", {{ .NoExtensions }}, bJO, bS2A, bOE, {{ if not .CodecPkgFiles }}{{ .CodecPkgName }}.{{ end }}NewTypeInfos(strings.Split("{{ .StructTags }}", ",")), typs...) for _, warning := range warnings { fmt.Fprintf(os.Stderr, "warning: %s\n", warning) } bout, err := format.Source(out.Bytes()) // println("... lengths: before formatting: ", len(out.Bytes()), ", after formatting", len(bout)) if err != nil { fout.Write(out.Bytes()) panic(err) } fout.Write(bout) } ` var genFuncs template.FuncMap func init() { genFuncs = make(template.FuncMap) genFuncs["boolvar"] = func(x *bool) bool { return *x } } type regexFlagValue struct { v *regexp.Regexp } func (v *regexFlagValue) Set(s string) (err error) { // fmt.Printf("calling regexFlagValue.Set with %s\n", s) v.v, err = regexp.Compile(s) return } func (v *regexFlagValue) Get() interface{} { return v.v } func (v *regexFlagValue) String() string { return fmt.Sprintf("%v", v.v) } // boolFlagValue can be set to true or false, or unset as nil (default) type boolFlagValue struct { v *bool } func (v *boolFlagValue) Set(s string) (err error) { // fmt.Printf("calling boolFlagValue.Set with %s\n", s) b, err := strconv.ParseBool(s) if err == nil { v.v = &b } return } func (v *boolFlagValue) Get() interface{} { return v.v } func (v *boolFlagValue) String() string { return fmt.Sprintf("%#v", v.v) } type mainCfg struct { CodecPkgName string CodecImportPath string ImportPath string OutFile string PackageName string RandString string BuildTag string StructTags string Types []string AllFilesSize int64 CodecPkgFiles bool NoExtensions bool JsonOnly *bool StructToArrayAlways *bool OmitEmptyAlways *bool uid int64 goRunTags string regexName *regexp.Regexp notRegexName *regexp.Regexp keepTempFile bool // !deleteTempFile } // mainGen is given a list of *.go files to parse, and an output file (fout). // // It finds all types T in the files, and it creates 2 tmp files (frun). // - main package file passed to 'go run' // - package level file which calls *genRunner.Selfer to write Selfer impls for each T. // // We use a package level file so that it can reference unexported types in the package being worked on. // Tool then executes: "go run __frun__" which creates fout. // fout contains Codec(En|De)codeSelf implementations for every type T. func mainGen(tv *mainCfg, infiles ...string) (err error) { // For each file, grab AST, find each type, and write a call to it. if len(infiles) == 0 { return } if tv.CodecImportPath == "" { return errors.New("codec package path cannot be blank") } if tv.OutFile == "" { return errors.New("outfile cannot be blank") } if tv.regexName == nil { tv.regexName = regexp.MustCompile(".*") } if tv.notRegexName == nil { tv.notRegexName = regexp.MustCompile("^$") } if tv.uid < 0 { tv.uid = -tv.uid } else if tv.uid == 0 { rr := rand.New(rand.NewSource(time.Now().UnixNano())) tv.uid = 101 + rr.Int63n(9777) } // We have to parse dir for package, before opening the temp file for writing (else ImportDir fails). // Also, ImportDir(...) must take an absolute path. lastdir := filepath.Dir(tv.OutFile) absdir, err := filepath.Abs(lastdir) if err != nil { return } importPath, err := pkgPath(absdir) if err != nil { return } tv.CodecPkgName = genCodecPkg tv.RandString = strconv.FormatInt(tv.uid, 10) tv.ImportPath = importPath if tv.ImportPath == tv.CodecImportPath { tv.CodecPkgFiles = true tv.CodecPkgName = "codec" } else { // HACK: always handle vendoring. It should be typically on in go 1.6, 1.7 tv.ImportPath = genStripVendor(tv.ImportPath) } astfiles := make([]*ast.File, len(infiles)) var fi os.FileInfo for i, infile := range infiles { if filepath.Dir(infile) != lastdir { err = errors.New("all input files must all be in same directory as output file") return } if fi, err = os.Stat(infile); err != nil { return } tv.AllFilesSize += fi.Size() fset := token.NewFileSet() astfiles[i], err = parser.ParseFile(fset, infile, nil, 0) if err != nil { return } if i == 0 { tv.PackageName = astfiles[i].Name.Name if tv.PackageName == "main" { // codecgen cannot be run on types in the 'main' package. // A temporary 'main' package must be created, and should reference the fully built // package containing the types. // Also, the temporary main package will conflict with the main package which already has a main method. err = errors.New("codecgen cannot be run on types in the 'main' package") return } } } // keep track of types with selfer methods // selferMethods := []string{"CodecEncodeSelf", "CodecDecodeSelf"} selferEncTyps := make(map[string]bool) selferDecTyps := make(map[string]bool) for _, f := range astfiles { for _, d := range f.Decls { // if fd, ok := d.(*ast.FuncDecl); ok && fd.Recv != nil && fd.Recv.NumFields() == 1 { if fd, ok := d.(*ast.FuncDecl); ok && fd.Recv != nil && len(fd.Recv.List) == 1 { recvType := fd.Recv.List[0].Type if ptr, ok := recvType.(*ast.StarExpr); ok { recvType = ptr.X } if id, ok := recvType.(*ast.Ident); ok { switch fd.Name.Name { case "CodecEncodeSelf": selferEncTyps[id.Name] = true case "CodecDecodeSelf": selferDecTyps[id.Name] = true } } } } } // now find types for _, f := range astfiles { for _, d := range f.Decls { if gd, ok := d.(*ast.GenDecl); ok { for _, dd := range gd.Specs { if td, ok := dd.(*ast.TypeSpec); ok { // if len(td.Name.Name) == 0 || td.Name.Name[0] > 'Z' || td.Name.Name[0] < 'A' { if len(td.Name.Name) == 0 { continue } // only generate for: // struct: StructType // primitives (numbers, bool, string): Ident // map: MapType // slice, array: ArrayType // chan: ChanType // do not generate: // FuncType, InterfaceType, StarExpr (ptr), etc // // We generate for all these types (not just structs), because they may be a field // in another struct which doesn't have codecgen run on it, and it will be nice // to take advantage of the fact that the type is a Selfer. switch td.Type.(type) { case *ast.StructType, *ast.Ident, *ast.MapType, *ast.ArrayType, *ast.ChanType: // only add to tv.Types iff // - it matches per the -r parameter // - it doesn't match per the -nr parameter // - it doesn't have any of the Selfer methods in the file if tv.regexName.FindStringIndex(td.Name.Name) != nil && tv.notRegexName.FindStringIndex(td.Name.Name) == nil && !td.Assign.IsValid() && // skip type aliases e.g. type A = B !selferEncTyps[td.Name.Name] && !selferDecTyps[td.Name.Name] { tv.Types = append(tv.Types, td.Name.Name) } } } } } } } if len(tv.Types) == 0 { return } // we cannot use ioutil.TempFile, because we cannot guarantee the file suffix (.go). // Also, we cannot create file in temp directory, // because go run will not work (as it needs to see the types here). // Consequently, create the temp file in the current directory, and remove when done. // frun, err = ioutil.TempFile("", "codecgen-") // frunName := filepath.Join(os.TempDir(), "codecgen-"+strconv.FormatInt(time.Now().UnixNano(), 10)+".go") frunMainName := filepath.Join(lastdir, "codecgen-main-"+tv.RandString+".generated.go") frunPkgName := filepath.Join(lastdir, "codecgen-pkg-"+tv.RandString+".generated.go") // var frunMain, frunPkg *os.File if _, err = gen1(frunMainName, genFrunMainTmpl, &tv); err != nil { return } if _, err = gen1(frunPkgName, genFrunPkgTmpl, &tv); err != nil { return } // remove outfile, so "go run ..." will not think that types in outfile already exist. os.Remove(tv.OutFile) // execute go run // MARKER: it must be run with codec.safe tag, so that we don't use wrong optimizations that only make sense at runtime. // e.g. compositeUnderlyingType will cause generated code to have bad conversions for defined composite types. cmd := exec.Command("go", "run", "-tags", "codecgen.exec codec.safe "+tv.goRunTags, frunMainName) //, frunPkg.Name()) cmd.Dir = lastdir var buf bytes.Buffer cmd.Stdout = &buf cmd.Stderr = &buf if err = cmd.Run(); err != nil { err = fmt.Errorf("error running 'go run %s': %v, console: %s", frunMainName, err, buf.Bytes()) return } os.Stdout.Write(buf.Bytes()) // only delete these files if codecgen ran successfully. // if unsuccessful, these files are here for diagnosis. if !tv.keepTempFile { os.Remove(frunMainName) os.Remove(frunPkgName) } return } func gen1(frunName, tmplStr string, tv interface{}) (frun *os.File, err error) { os.Remove(frunName) if frun, err = os.Create(frunName); err != nil { return } defer frun.Close() t := template.New("").Funcs(genFuncs) if t, err = t.Parse(tmplStr); err != nil { return } bw := bufio.NewWriter(frun) if err = t.Execute(bw, tv); err != nil { bw.Flush() return } if err = bw.Flush(); err != nil { return } return } // MARKER: keep in sync with ../gen.go func genStripVendor(s string) string { // HACK: Misbehaviour occurs in go 1.5. May have to re-visit this later. // if s contains /vendor/ OR startsWith vendor/, then return everything after it. const vendorStart = "vendor/" const vendorInline = "/vendor/" if i := strings.LastIndex(s, vendorInline); i >= 0 { s = s[i+len(vendorInline):] } else if strings.HasPrefix(s, vendorStart) { s = s[len(vendorStart):] } return s } func main() { var unusedBool bool var printVersion bool var g mainCfg var r1, r2 regexFlagValue var b1, b2, b3 boolFlagValue flag.BoolVar(&printVersion, "version", false, "show version information") flag.StringVar(&g.OutFile, "o", "", "`output file` that contains generated type") flag.StringVar(&g.CodecImportPath, "c", genCodecPath, "`codec import path` useful when building against a mirror or fork") flag.StringVar(&g.BuildTag, "t", "", "`build tag` to put into generated file") flag.Var(&r1, "r", "`regex` for type names to match - defaults to '.*' (all)") flag.Var(&r2, "nr", "`regex` for type names to exclude - defaults to the '^$' (none)") flag.Var(&b1, "j", "if set to `true or false`, generated file supports 'json only' or omits json specific optimizations") flag.Var(&b2, "ta", "if set to `true or false`, support 'to_array' always or never, regardless of Handle or struct tags") flag.Var(&b3, "oe", "if set to `true or false`, 'omit empty' always or never, regardless of struct tags") flag.StringVar(&g.goRunTags, "rt", "", "`runtime tags` for go run to select which files to use during codecgen execution") flag.StringVar(&g.StructTags, "st", "codec,json", "`struct tag keys` to introspect") flag.BoolVar(&g.keepTempFile, "x", false, "set to `true or false` to 'keep' temp file created during codecgen execution - for debugging sessions") flag.BoolVar(&unusedBool, "u", false, "set to `true or false` to 'allow unsafe' use. **Deprecated and Ignored: kept for backwards compatibility**") flag.Int64Var(&g.uid, "d", 0, "`random integer identifier` for use in generated code, to prevent excessive churn") flag.BoolVar(&g.NoExtensions, "nx", false, "set to `true or false` to elide/ignore checking for extensions (if you do not use extensions)") flag.Parse() if printVersion { var modVersion string = codecgenModuleVersion if bi, ok := debug.ReadBuildInfo(); ok { if modVersion = bi.Main.Version; len(modVersion) > 0 && modVersion[0] == 'v' { modVersion = modVersion[1:] } } fmt.Printf("codecgen v%s (internal version %d) works with %s library v%s +\n", modVersion, genVersion, genCodecPath, minimumCodecVersion) return } g.JsonOnly = b1.v g.StructToArrayAlways = b2.v g.OmitEmptyAlways = b3.v g.regexName = r1.v g.notRegexName = r2.v // fmt.Printf("jsonOnly: %v, StructToArrayAlways: %v, OmitEmptyAlways: %v\n", g.JsonOnly, g.StructToArrayAlways, g.OmitEmptyAlways) err := mainGen(&g, flag.Args()...) // err := mainGen(*o, *t, *c, *d, *rt, *st, // regexp.MustCompile(*r), regexp.MustCompile(*nr), !*x, *nx, flag.Args()...) if err != nil { fmt.Fprintf(os.Stderr, "codecgen error: %v\n", err) os.Exit(1) } } go-1.2.8/codec/codecgen/go.mod000066400000000000000000000001671435255326100160730ustar00rootroot00000000000000module github.com/ugorji/go/codec/codecgen require github.com/ugorji/go/codec v1.2.8 require golang.org/x/tools latest go-1.2.8/codec/codecgen/go.mod.go000066400000000000000000000004441435255326100164750ustar00rootroot00000000000000// 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 go.mod.ignore // +build go.mod.ignore package main import _ "github.com/ugorji/go/codec" // ensures the go.mod keeps this dependency go-1.2.8/codec/codecgen/go.sum000077500000000000000000000067231435255326100161270ustar00rootroot00000000000000github.com/ugorji/go v1.2.7 h1:qYhyWUUd6WbiM+C6JZAUkIJt/1WrjzNHY9+KCIjVqTo= github.com/ugorji/go v1.2.7/go.mod h1:nF9osbDWLy6bDVv/Rtoh6QgnvNDpmCalQV5urGCCS6M= github.com/ugorji/go/codec v1.2.7 h1:YPXUKf7fYbp/y8xloBqZOw2qaVggbfwMlI8WM3wZUJ0= github.com/ugorji/go/codec v1.2.7/go.mod h1:WGN1fab3R1fzQlVQTkfxVtIBhWDRqOviHU95kRgeqEY= github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4= golang.org/x/mod v0.7.0 h1:LapD9S96VoQRhi/GrNTqeBJFrUjs5UHCAtTlgwA5oZA= golang.org/x/mod v0.7.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs= golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c= golang.org/x/net v0.3.0/go.mod h1:MBQ8lrhLObU/6UmLb4fmbmk5OcyYmqtbGd/9yIeKjEE= golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.1.0 h1:wsuoTGHzEhffawBOhz5CYhcrV4IdKZbEyZjBMuTp12o= golang.org/x/sync v0.1.0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.3.0 h1:w8ZOecv6NaNa/zC8944JTU3vz4u6Lagfk4RPQxv92NQ= golang.org/x/sys v0.3.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= golang.org/x/term v0.3.0/go.mod h1:q750SLmJuPmVoN1blW3UFBPREJfb1KmY3vwxfr+nFDA= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ= golang.org/x/text v0.5.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8= golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc= golang.org/x/tools v0.4.0 h1:7mTAgkunk3fr4GAloyyCasadO6h9zSsQZbwvcaIciV4= golang.org/x/tools v0.4.0/go.mod h1:UE5sM2OK9E/d67R0ANs2xJizIymRP5gJU295PvKXxjQ= golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= go-1.2.8/codec/codecgen/goversion_pkgpath_gte_go112.go000066400000000000000000000010321435255326100226050ustar00rootroot00000000000000// 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.12 // +build go1.12 package main import ( "fmt" "golang.org/x/tools/go/packages" ) func pkgPath(dir string) (string, error) { pkgs, err := packages.Load(&packages.Config{Dir: dir}, ".") if err != nil { return "", err } if len(pkgs) != 1 { return "", fmt.Errorf("Could not read package (%d package found)", len(pkgs)) } pkg := pkgs[0] return pkg.PkgPath, nil } go-1.2.8/codec/codecgen/goversion_pkgpath_lt_go112.go000066400000000000000000000006111435255326100224470ustar00rootroot00000000000000// 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.12 // +build !go1.12 package main import ( "go/build" ) func pkgPath(dir string) (string, error) { pkg, err := build.Default.ImportDir(dir, build.AllowBinary) if err != nil { return "", err } return pkg.ImportPath, nil } go-1.2.8/codec/codecgen/z.go000066400000000000000000000003221435255326100155560ustar00rootroot00000000000000// 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 main const genCodecPath = "github.com/ugorji/go/codec" go-1.2.8/codec/decimal.go000066400000000000000000000261261435255326100151460ustar00rootroot00000000000000// 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" ) // 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) { 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 } 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 } 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++ } // we considered punting early if string has length > maxMantDigits, but this 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 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 } go-1.2.8/codec/decode.go000066400000000000000000002047221435255326100147730ustar00rootroot00000000000000// 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" "errors" "io" "math" "reflect" "strconv" "time" ) const msgBadDesc = "unrecognized descriptor byte" const ( decDefMaxDepth = 1024 // maximum depth decDefChanCap = 64 // should be large, as cap cannot be expanded decScratchByteArrayLen = (8 + 2 + 2) * 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 that we should not 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") ) // decByteState tracks where the []byte returned by the last call // to DecodeBytes or DecodeStringAsByte came from type decByteState uint8 const ( decByteStateNone decByteState = iota decByteStateZerocopy // view into []byte that we are decoding from decByteStateReuseBuf // view into transient buffer used internally by decDriver // decByteStateNewAlloc ) type decNotDecodeableReason uint8 const ( decNotDecodeableReasonUnknown decNotDecodeableReason = iota decNotDecodeableReasonBadKind decNotDecodeableReasonNonAddrValue decNotDecodeableReasonNilReference ) type decDriver 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) 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) // DecodeBytes returns the bytes representing a binary value. // It will return a view into scratch buffer or input []byte (if applicable). // // All implementations must honor the contract below: // if ZeroCopy and applicable, return a view into input []byte we are decoding from // else if in == nil, return a view into scratch buffer // else append decoded value to in[:0] and return that // (this can be simulated by passing []byte{} as in parameter) // // Implementations must also update Decoder.decByteState on each call to // DecodeBytes or DecodeStringAsBytes. Some callers may check that and work appropriately. // // Note: DecodeBytes may decode past the length of the passed byte slice, up to the cap. // Consequently, it is ok to pass a zero-len slice to DecodeBytes, as the returned // byte slice will have the appropriate length. DecodeBytes(in []byte) (out []byte) // DecodeBytes(bs []byte, isstring, zerocopy bool) (bsOut []byte) // DecodeExt will decode into a *RawExt or into an extension. DecodeExt(v interface{}, basetype reflect.Type, xtag uint64, ext Ext) // decodeExt(verifyTag bool, tag byte) (xtag byte, xbs []byte) 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 ReadArrayEnd() // 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 ReadMapEnd() reset() // atEndOfDecode() // nextValueBytes will return the bytes representing the next value in the stream. // // if start is nil, then treat it as a request to discard the next set of bytes, // and the return response does not matter. // Typically, this means that the returned []byte is nil/empty/undefined. // // Optimize for decoding from a []byte, where the nextValueBytes will just be a sub-slice // of the input slice. Callers that need to use this to not be a view into the input bytes // should handle it appropriately. nextValueBytes(start []byte) []byte // descBd will describe the token descriptor that signifies what type was decoded descBd() string decoder() *Decoder driverStateManager decNegintPosintFloatNumber } type decDriverContainerTracker interface { ReadArrayElem() ReadMapElemKey() ReadMapElemValue() } 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) ReadArrayEnd() {} func (x decDriverNoopContainerReader) ReadMapStart() (v int) { panic("ReadMapStart unsupported") } func (x decDriverNoopContainerReader) ReadMapEnd() {} func (x decDriverNoopContainerReader) CheckBreak() (v bool) { return } // 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 } // ---------------------------------------- func (d *Decoder) rawExt(f *codecFnInfo, rv reflect.Value) { d.d.DecodeExt(rv2i(rv), f.ti.rt, 0, nil) } func (d *Decoder) ext(f *codecFnInfo, rv reflect.Value) { d.d.DecodeExt(rv2i(rv), f.ti.rt, f.xfTag, f.xfFn) } func (d *Decoder) selferUnmarshal(f *codecFnInfo, rv reflect.Value) { rv2i(rv).(Selfer).CodecDecodeSelf(d) } func (d *Decoder) binaryUnmarshal(f *codecFnInfo, rv reflect.Value) { bm := rv2i(rv).(encoding.BinaryUnmarshaler) xbs := d.d.DecodeBytes(nil) fnerr := bm.UnmarshalBinary(xbs) d.onerror(fnerr) } func (d *Decoder) textUnmarshal(f *codecFnInfo, rv reflect.Value) { tm := rv2i(rv).(encoding.TextUnmarshaler) fnerr := tm.UnmarshalText(d.d.DecodeStringAsBytes()) d.onerror(fnerr) } func (d *Decoder) jsonUnmarshal(f *codecFnInfo, rv reflect.Value) { d.jsonUnmarshalV(rv2i(rv).(jsonUnmarshaler)) } func (d *Decoder) jsonUnmarshalV(tm jsonUnmarshaler) { // grab the bytes to be read, as UnmarshalJSON needs the full JSON so as to unmarshal it itself. var bs0 = []byte{} if !d.bytes { bs0 = d.blist.get(256) } bs := d.d.nextValueBytes(bs0) fnerr := tm.UnmarshalJSON(bs) if !d.bytes { d.blist.put(bs) if !byteSliceSameData(bs0, bs) { d.blist.put(bs0) } } d.onerror(fnerr) } func (d *Decoder) kErr(f *codecFnInfo, rv reflect.Value) { d.errorf("no decoding function defined for kind %v", rv.Kind()) } func (d *Decoder) raw(f *codecFnInfo, rv reflect.Value) { rvSetBytes(rv, d.rawBytes()) } func (d *Decoder) kString(f *codecFnInfo, rv reflect.Value) { rvSetString(rv, d.stringZC(d.d.DecodeStringAsBytes())) } func (d *Decoder) kBool(f *codecFnInfo, rv reflect.Value) { rvSetBool(rv, d.d.DecodeBool()) } func (d *Decoder) kTime(f *codecFnInfo, rv reflect.Value) { rvSetTime(rv, d.d.DecodeTime()) } func (d *Decoder) kFloat32(f *codecFnInfo, rv reflect.Value) { rvSetFloat32(rv, d.decodeFloat32()) } func (d *Decoder) kFloat64(f *codecFnInfo, rv reflect.Value) { rvSetFloat64(rv, d.d.DecodeFloat64()) } func (d *Decoder) kComplex64(f *codecFnInfo, rv reflect.Value) { rvSetComplex64(rv, complex(d.decodeFloat32(), 0)) } func (d *Decoder) kComplex128(f *codecFnInfo, rv reflect.Value) { rvSetComplex128(rv, complex(d.d.DecodeFloat64(), 0)) } func (d *Decoder) kInt(f *codecFnInfo, rv reflect.Value) { rvSetInt(rv, int(chkOvf.IntV(d.d.DecodeInt64(), intBitsize))) } func (d *Decoder) kInt8(f *codecFnInfo, rv reflect.Value) { rvSetInt8(rv, int8(chkOvf.IntV(d.d.DecodeInt64(), 8))) } func (d *Decoder) kInt16(f *codecFnInfo, rv reflect.Value) { rvSetInt16(rv, int16(chkOvf.IntV(d.d.DecodeInt64(), 16))) } func (d *Decoder) kInt32(f *codecFnInfo, rv reflect.Value) { rvSetInt32(rv, int32(chkOvf.IntV(d.d.DecodeInt64(), 32))) } func (d *Decoder) kInt64(f *codecFnInfo, rv reflect.Value) { rvSetInt64(rv, d.d.DecodeInt64()) } func (d *Decoder) kUint(f *codecFnInfo, rv reflect.Value) { rvSetUint(rv, uint(chkOvf.UintV(d.d.DecodeUint64(), uintBitsize))) } func (d *Decoder) kUintptr(f *codecFnInfo, rv reflect.Value) { rvSetUintptr(rv, uintptr(chkOvf.UintV(d.d.DecodeUint64(), uintBitsize))) } func (d *Decoder) kUint8(f *codecFnInfo, rv reflect.Value) { rvSetUint8(rv, uint8(chkOvf.UintV(d.d.DecodeUint64(), 8))) } func (d *Decoder) kUint16(f *codecFnInfo, rv reflect.Value) { rvSetUint16(rv, uint16(chkOvf.UintV(d.d.DecodeUint64(), 16))) } func (d *Decoder) kUint32(f *codecFnInfo, rv reflect.Value) { rvSetUint32(rv, uint32(chkOvf.UintV(d.d.DecodeUint64(), 32))) } func (d *Decoder) kUint64(f *codecFnInfo, rv reflect.Value) { rvSetUint64(rv, d.d.DecodeUint64()) } func (d *Decoder) kInterfaceNaked(f *codecFnInfo) (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 { d.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 { // 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 { 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 reflectArrayOfSupported && 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 { // it is one of the InterfaceExt ones: json and cbor. // most likely cbor, as json decoding never reveals valueTypeExt (no tagging support) 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.h.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 { d.sideDecode(rv2i(rvn), bfn.rt, bytes) } 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.errorf("kInterfaceNaked: unexpected valueType: %d", n.v) } return } func (d *Decoder) kInterface(f *codecFnInfo, 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(rvType(rvn), rvn.Kind()) rvSetDirect(rvn2, rvn) rvn = rvn2 } d.decodeValue(rvn, nil) rvSetIntf(rv, rvn) } func decStructFieldKeyNotString(dd decDriver, keyType valueType, b *[decScratchByteArrayLen]byte) (rvkencname []byte) { if keyType == valueTypeInt { rvkencname = strconv.AppendInt(b[:0], dd.DecodeInt64(), 10) } else if keyType == valueTypeUint { rvkencname = strconv.AppendUint(b[:0], dd.DecodeUint64(), 10) } else if keyType == valueTypeFloat { rvkencname = strconv.AppendFloat(b[:0], dd.DecodeFloat64(), 'f', -1, 64) } else { halt.errorf("invalid struct key type: %v", keyType) } return } func (d *Decoder) kStructField(si *structFieldInfo, rv reflect.Value) { if d.d.TryNil() { if rv = si.path.field(rv); rv.IsValid() { decSetNonNilRV2Zero(rv) } return } d.decodeValueNoCheckNil(si.path.fieldAlloc(rv), nil) } func (d *Decoder) kStruct(f *codecFnInfo, rv reflect.Value) { 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 if mf != nil { var namearr2 [16]byte name2 = namearr2[:0] } var rvkencname []byte for j := 0; d.containerNext(j, containerLen, hasLen); j++ { d.mapElemKey() if ti.keyType == valueTypeString { rvkencname = d.d.DecodeStringAsBytes() } else { rvkencname = decStructFieldKeyNotString(d.d, ti.keyType, &d.b) } 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 { d.errorf("no matching struct field when decoding stream map with key: %s ", 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. hasLen := containerLen >= 0 var checkbreak bool tisfi := ti.sfi.source() for j, si := range tisfi { if hasLen { if j == containerLen { break } } else if d.checkBreak() { checkbreak = true break } d.arrayElem() d.kStructField(si, rv) } var proceed bool if hasLen { proceed = containerLen > len(tisfi) } else { proceed = !checkbreak } // if (hasLen && containerLen > len(tisfi)) || (!hasLen && !checkbreak) { if proceed { // read remaining values and throw away for j := len(tisfi); ; j++ { if !d.containerNext(j, containerLen, hasLen) { break } d.arrayElem() d.structFieldNotFound(j, "") } } d.arrayEnd() } else { d.onerror(errNeedMapOrArrayDecodeToStruct) } } func (d *Decoder) kSlice(f *codecFnInfo, rv reflect.Value) { // 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)) { d.errorf("bytes/string in stream must decode into slice/array of bytes, not %v", ti.rt) } rvbs := rvGetBytes(rv) if !rvCanset { // not addressable byte slice, so do not decode into it past the length rvbs = rvbs[:len(rvbs):len(rvbs)] } bs2 := d.decodeBytesInto(rvbs) // if !(len(bs2) == len(rvbs) && byteSliceSameData(rvbs, bs2)) { if !(len(bs2) > 0 && len(bs2) == len(rvbs) && &bs2[0] == &rvbs[0]) { if rvCanset { rvSetBytes(rv, bs2) } else if len(rvbs) > 0 && len(bs2) > 0 { copy(rvbs, bs2) } } return } slh, containerLenS := d.decSliceHelperStart() // only expects valueType(Array|Map) - never Nil // 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) } } slh.End() 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 *codecFn var rvChanged bool var rv0 = rv var rv9 reflect.Value rvlen := rvLenSlice(rv) rvcap := rvCapSlice(rv) hasLen := containerLenS > 0 if hasLen { if containerLenS > rvcap { oldRvlenGtZero := rvlen > 0 rvlen1 := decInferLen(containerLenS, d.h.MaxInitLen, int(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 d.errorf("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 var j int for ; d.containerNext(j, containerLenS, hasLen); j++ { if j == 0 { if rvIsNil(rv) { // means hasLen = false if rvCanset { rvlen = decInferLen(containerLenS, d.h.MaxInitLen, int(ti.elemsize)) rv, rvCanset = rvMakeSlice(rv, f.ti, rvlen, rvlen) rvcap = rvlen rvChanged = !rvCanset } else { d.errorf("cannot decode into non-settable slice") } } if fn == nil { fn = d.h.fn(rtelem) } } // if indefinite, etc, then expand the slice if necessary if j >= rvlen { slh.ElemContainerState(j) // 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 { d.onerror(errExpandSliceCannotChange) } } else { if !(rvCanset || rvChanged) { d.onerror(errExpandSliceCannotChange) } rv, rvcap, rvCanset = rvGrowSlice(rv, f.ti, rvcap, 1) rvlen = rvcap rvChanged = !rvCanset } } else { slh.ElemContainerState(j) } rv9 = rvSliceIndex(rv, j, f.ti) if elemReset { rvSetZero(rv9) } d.decodeValue(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 } } slh.End() if rvChanged { // infers rvCanset=true, so it can be reset rvSetDirect(rv0, rv) } } func (d *Decoder) kArray(f *codecFnInfo, rv reflect.Value) { // An array can be set from a map or array in stream. 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 f.ti.elemkind != uint8(reflect.Uint8) { d.errorf("bytes/string in stream can decode into array of bytes, but not %v", f.ti.rt) } rvbs := rvGetArrayBytes(rv, nil) bs2 := d.decodeBytesInto(rvbs) if !byteSliceSameData(rvbs, bs2) && len(rvbs) > 0 && len(bs2) > 0 { copy(rvbs, bs2) } return } slh, containerLenS := d.decSliceHelperStart() // only expects valueType(Array|Map) - never Nil // an array can never return a nil slice. so no need to check f.array here. if containerLenS == 0 { slh.End() return } rtelem := f.ti.elem for k := reflect.Kind(f.ti.elemkind); k == reflect.Ptr; k = rtelem.Kind() { rtelem = rtelem.Elem() } var fn *codecFn var rv9 reflect.Value rvlen := rv.Len() // same as cap hasLen := containerLenS > 0 if hasLen && containerLenS > rvlen { d.errorf("cannot decode into array with length: %v, less than container length: %v", rvlen, containerLenS) } // consider creating new element once, and just decoding into it. var elemReset = d.h.SliceElementReset for j := 0; d.containerNext(j, containerLenS, hasLen); j++ { // note that you cannot expand the array if indefinite and we go past array length if j >= rvlen { slh.arrayCannotExpand(hasLen, rvlen, j, containerLenS) return } slh.ElemContainerState(j) rv9 = rvArrayIndex(rv, j, f.ti) if elemReset { rvSetZero(rv9) } if fn == nil { fn = d.h.fn(rtelem) } d.decodeValue(rv9, fn) } slh.End() } func (d *Decoder) kChan(f *codecFnInfo, rv reflect.Value) { // 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 { d.errorf("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)) { d.errorf("bytes/string in stream must decode into slice/array of bytes, not %v", ti.rt) } bs2 := d.d.DecodeBytes(nil) 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 - nil handled above) slh, containerLenS := d.decSliceHelperStart() // 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)) } slh.End() 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 *codecFn var rvChanged bool var rv0 = rv var rv9 reflect.Value var rvlen int // = rv.Len() hasLen := containerLenS > 0 for j := 0; d.containerNext(j, containerLenS, hasLen); j++ { if j == 0 { if rvIsNil(rv) { if hasLen { rvlen = decInferLen(containerLenS, d.h.MaxInitLen, int(ti.elemsize)) } else { rvlen = decDefChanCap } if rvCanset { rv = reflect.MakeChan(ti.rt, rvlen) rvChanged = true } else { d.errorf("cannot decode into non-settable chan") } } if fn == nil { fn = d.h.fn(rtelem) } } slh.ElemContainerState(j) if rv9.IsValid() { rvSetZero(rv9) } else if decUseTransient && 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) } slh.End() if rvChanged { // infers rvCanset=true, so it can be reset rvSetDirect(rv0, rv) } } func (d *Decoder) kMap(f *codecFnInfo, rv reflect.Value) { containerLen := d.mapStart(d.d.ReadMapStart()) ti := f.ti if rvIsNil(rv) { rvlen := decInferLen(containerLen, d.h.MaxInitLen, int(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) 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 kTransient := decUseTransient && !ktypePtr && ti.tikey.flagCanTransient var vtypeElem reflect.Type var keyFn, valFn *codecFn 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 // kstrbs is used locally for the key bytes, so we can reduce allocation. // When we read keys, we copy to this local bytes array, and use a stringView for lookup. // We only convert it into a true string if we have to do a set on the map. // Since kstr2bs will usually escape to the heap, declaring a [64]byte array may be wasteful. // It is only valuable if we are sure that it is declared on the stack. // var kstrarr [64]byte // most keys are less than 32 bytes, and even more less than 64 // var kstrbs = kstrarr[:0] var kstrbs []byte var kstr2bs []byte var s string var callFnRvk bool fnRvk2 := func() (s string) { callFnRvk = false if len(kstr2bs) < 2 { return string(kstr2bs) } return d.mapKeyString(&callFnRvk, &kstrbs, &kstr2bs) } // Use a possibly transient (map) value (and key), to reduce allocation for j := 0; d.containerNext(j, containerLen, hasLen); j++ { callFnRvk = false 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 decUseTransient && vTransient && kTransient { rvk = d.perType.TransientAddr2K(ktype, ktypeKind) } else { rvk = rvZeroAddrK(ktype, ktypeKind) } if !rvkMut { rvkn = rvk } if !rvvMut { if decUseTransient && vTransient { rvvn = d.perType.TransientAddrK(vtype, vtypeKind) } else { rvvn = rvZeroAddrK(vtype, vtypeKind) } } if !ktypeIsString && keyFn == nil { keyFn = d.h.fn(ktypeLo) } if valFn == nil { valFn = d.h.fn(vtypeLo) } } else if rvkMut { rvSetZero(rvk) } else { rvk = rvkn } d.mapElemKey() if ktypeIsString { kstr2bs = d.d.DecodeStringAsBytes() rvSetString(rvk, fnRvk2()) } else { d.decByteState = decByteStateNone d.decodeValue(rvk, keyFn) // special case if interface wrapping a byte slice if ktypeIsIntf { if rvk2 := rvk.Elem(); rvk2.IsValid() && rvType(rvk2) == uint8SliceTyp { kstr2bs = rvGetBytes(rvk2) rvSetIntf(rvk, rv4istr(fnRvk2())) } // NOTE: consider failing early if map/slice/func } } d.mapElemValue() if d.d.TryNil() { // since a map, we have to set zero value if needed if !rvvz.IsValid() { rvvz = rvZeroK(vtype, vtypeKind) } if callFnRvk { s = d.string(kstr2bs) if ktypeIsString { rvSetString(rvk, s) } else { // ktypeIsIntf rvSetIntf(rvk, rv4istr(s)) } } mapSet(rv, rvk, rvvz, kfast, visindirect, visref) 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, kfast, visindirect, visref) 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 decUseTransient && 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 decUseTransient && vTransient { rvv = d.perType.TransientAddrK(vtype, vtypeKind) } else { rvv = rvZeroAddrK(vtype, vtypeKind) } DECODE_VALUE_NO_CHECK_NIL: d.decodeValueNoCheckNil(rvv, valFn) if doMapSet { if callFnRvk { s = d.string(kstr2bs) if ktypeIsString { rvSetString(rvk, s) } else { // ktypeIsIntf rvSetIntf(rvk, rv4istr(s)) } } mapSet(rv, rvk, rvv, kfast, visindirect, visref) } } d.mapEnd() } // 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 struct { panicHdl d decDriver // cache the mapTypeId and sliceTypeId for faster comparisons mtid uintptr stid uintptr h *BasicHandle blist bytesFreelist // ---- cpu cache line boundary? decRd // ---- cpu cache line boundary? n fauxUnion hh Handle err error perType decPerType // used for interning strings is internerMap // ---- 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 // 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. b [decScratchByteArrayLen]byte } // 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 { d := h.newDecDriver().decoder() if r != nil { d.Reset(r) } return d } // NewDecoderBytes returns a Decoder which efficiently decodes directly // from a byte slice with zero copying. func NewDecoderBytes(in []byte, h Handle) *Decoder { d := h.newDecDriver().decoder() if in != nil { d.ResetBytes(in) } return d } // 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 (d *Decoder) r() *decRd { return &d.decRd } func (d *Decoder) init(h Handle) { initHandle(h) d.bytes = true d.err = errDecoderNotInitialized d.h = h.getBasicHandle() d.hh = h d.be = h.isBinary() if d.h.InternString && d.is == nil { d.is.init() } // NOTE: do not initialize d.n here. It is lazily initialized in d.naked() } func (d *Decoder) resetCommon() { d.d.reset() d.err = nil d.c = 0 d.decByteState = decByteStateNone 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) != -1 } if d.h.SliceType != nil { d.stid = rt2id(d.h.SliceType) d.str = fastpathAvIndex(d.stid) != -1 } } // Reset the Decoder with a new Reader to decode from, // clearing all state from last run(s). func (d *Decoder) Reset(r io.Reader) { if r == nil { r = &eofReader } d.bytes = false if d.h.ReaderBufferSize > 0 { if d.bi == nil { d.bi = new(bufioDecReader) } d.bi.reset(r, d.h.ReaderBufferSize, &d.blist) d.bufio = true d.decReader = d.bi } else { if d.ri == nil { d.ri = new(ioDecReader) } d.ri.reset(r, &d.blist) d.bufio = false d.decReader = d.ri } d.resetCommon() } // ResetBytes resets the Decoder with a new []byte to decode from, // clearing all state from last run(s). func (d *Decoder) ResetBytes(in []byte) { if in == nil { in = []byte{} } d.bufio = false d.bytes = true d.decReader = &d.rb d.rb.reset(in) d.resetCommon() } // 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) ResetString(s string) { d.ResetBytes(bytesView(s)) } func (d *Decoder) naked() *fauxUnion { return &d.n } // 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. func (d *Decoder) 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 if !debugging { defer func() { if x := recover(); x != nil { panicValToErr(d, x, &d.err) err = d.err } }() } 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. func (d *Decoder) 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 releases shared (pooled) resources. // // It is important to call Release() when done with a Decoder, so those resources // are released instantly for use by subsequently created Decoders. // // By default, Release() is automatically called unless the option ExplicitRelease is set. // // Deprecated: Release is a no-op as pooled resources are not used with an Decoder. // This method is kept for compatibility reasons only. func (d *Decoder) Release() { } func (d *Decoder) swallow() { d.d.nextValueBytes(nil) } func (d *Decoder) swallowErr() (err error) { if !debugging { defer func() { if x := recover(); x != nil { panicValToErr(d, x, &err) } }() } d.swallow() return } func setZero(iv interface{}) { if iv == nil { return } rv, ok := isNil(iv) if ok { 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 *Decoder) decode(iv interface{}) { // a switch with only concrete types can be optimized. // consequently, we deal with nil and interfaces outside the switch. if iv == nil { d.onerror(errCannotDecodeIntoNil) } switch v := iv.(type) { // case nil: // case Selfer: case reflect.Value: if x, _ := isDecodeable(v); !x { d.haltAsNotDecodeable(v) } d.decodeValue(v, nil) case *string: *v = d.stringZC(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 *float32: *v = d.decodeFloat32() case *float64: *v = d.d.DecodeFloat64() case *complex64: *v = complex(d.decodeFloat32(), 0) case *complex128: *v = complex(d.d.DecodeFloat64(), 0) case *[]byte: *v = d.decodeBytesInto(*v) case []byte: // not addressable byte slice, so do not decode into it past the length b := d.decodeBytesInto(v[:len(v):len(v)]) if !(len(b) > 0 && len(b) == len(v) && &b[0] == &v[0]) { // not same slice copy(v, b) } case *time.Time: *v = d.d.DecodeTime() case *Raw: *v = d.rawBytes() case *interface{}: d.decodeValue(rv4iptr(v), nil) default: // we can't check non-predefined types, as they might be a Selfer or extension. if skipFastpathTypeSwitchInDirectCall || !fastpathDecodeTypeSwitch(iv, d) { v := reflect.ValueOf(iv) if x, _ := isDecodeable(v); !x { d.haltAsNotDecodeable(v) } d.decodeValue(v, 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) decodeValue(rv reflect.Value, fn *codecFn) { if d.d.TryNil() { decSetNonNilRV2Zero(rv) return } d.decodeValueNoCheckNil(rv, fn) } func (d *Decoder) decodeValueNoCheckNil(rv reflect.Value, fn *codecFn) { // 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(rvType(rv).Elem())) } rvp = rv rv = rv.Elem() goto PTR } if fn == nil { fn = d.h.fn(rvType(rv)) } if fn.i.addrD { if rvpValid { rv = rvp } else if rv.CanAddr() { rv = rvAddr(rv, fn.i.ti.ptr) } else if fn.i.addrDf { d.errorf("cannot decode into a non-pointer value") } } fn.fd(d, &fn.i, rv) } func (d *Decoder) structFieldNotFound(index int, rvkencname string) { // Note: rvkencname is used only if there is an error, to pass into d.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 { d.errorf("no matching struct field found when decoding stream array at index %v", index) } else if rvkencname != "" { d.errorf("no matching struct field found when decoding stream map with key " + rvkencname) } } d.swallow() } func (d *Decoder) arrayCannotExpand(sliceLen, streamLen int) { if d.h.ErrorIfNoArrayExpand { d.errorf("cannot expand array len during decode from %v to %v", sliceLen, streamLen) } } func (d *Decoder) haltAsNotDecodeable(rv reflect.Value) { if !rv.IsValid() { d.onerror(errCannotDecodeIntoNil) } // check if an interface can be retrieved, before grabbing an interface if !rv.CanInterface() { d.errorf("cannot decode into a value without an interface: %v", rv) } d.errorf("cannot decode into value of kind: %v, %#v", rv.Kind(), rv2i(rv)) } func (d *Decoder) depthIncr() { d.depth++ if d.depth >= d.maxdepth { d.onerror(errMaxDepthExceeded) } } func (d *Decoder) depthDecr() { d.depth-- } // Possibly get an interned version of a string, iff InternString=true and decoding a map key. // // This should mostly be used for map keys, where the key type is string. // This is because keys of a map/struct are typically reused across many objects. func (d *Decoder) string(v []byte) (s string) { if d.is == nil || d.c != containerMapKey || len(v) < 2 || len(v) > internMaxStrLen { return string(v) } return d.is.string(v) } func (d *Decoder) zerocopy() bool { return d.bytes && d.h.ZeroCopy } // 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) decodeBytesInto(in []byte) (v []byte) { if in == nil { in = []byte{} } return d.d.DecodeBytes(in) } func (d *Decoder) 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([]byte{}) if d.bytes && !d.h.ZeroCopy { v0 := v v = make([]byte, len(v)) copy(v, v0) } return } func (d *Decoder) wrapErr(v error, err *error) { *err = wrapCodecErr(v, d.hh.Name(), d.NumBytesRead(), false) } // NumBytesRead returns the number of bytes read func (d *Decoder) NumBytesRead() int { return int(d.r().numread()) } // decodeFloat32 will delegate to an appropriate DecodeFloat32 implementation (if exists), // else if will call DecodeFloat64 and ensure the value doesn't overflow. // // Note that we return float64 to reduce unnecessary conversions func (d *Decoder) decodeFloat32() float32 { if d.js { return d.jsondriver().DecodeFloat32() // custom implementation for 32-bit } return float32(chkOvf.Float32V(d.d.DecodeFloat64())) } // ---- 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. func (d *Decoder) containerNext(j, containerLen int, hasLen bool) bool { // return (hasLen && j < containerLen) || !(hasLen || slh.d.checkBreak()) if hasLen { return j < containerLen } return !d.checkBreak() } func (d *Decoder) mapStart(v int) int { if v != containerLenNil { d.depthIncr() d.c = containerMapStart } return v } func (d *Decoder) mapElemKey() { if d.js { d.jsondriver().ReadMapElemKey() } d.c = containerMapKey } func (d *Decoder) mapElemValue() { if d.js { d.jsondriver().ReadMapElemValue() } d.c = containerMapValue } func (d *Decoder) mapEnd() { d.d.ReadMapEnd() d.depthDecr() d.c = 0 } func (d *Decoder) arrayStart(v int) int { if v != containerLenNil { d.depthIncr() d.c = containerArrayStart } return v } func (d *Decoder) arrayElem() { if d.js { d.jsondriver().ReadArrayElem() } d.c = containerArrayElem } func (d *Decoder) arrayEnd() { d.d.ReadArrayEnd() d.depthDecr() d.c = 0 } func (d *Decoder) interfaceExtConvertAndDecode(v interface{}, ext InterfaceExt) { // var v interface{} = ext.ConvertExt(rv) // d.d.decode(&v) // ext.UpdateExt(rv, v) // assume v is a pointer: // - if struct|array, pass as is to ConvertExt // - else make it non-addressable and pass to ConvertExt // - make return value from ConvertExt addressable // - decode into it // - return the interface for passing into UpdateExt. // - interface should be a pointer if struct|array, else a value var s interface{} rv := reflect.ValueOf(v) rv2 := rv.Elem() rvk := rv2.Kind() if rvk == reflect.Struct || rvk == reflect.Array { s = ext.ConvertExt(v) } else { s = ext.ConvertExt(rv2i(rv2)) } rv = reflect.ValueOf(s) // We cannot use isDecodeable here, as the value converted may be nil, // or it may not be nil but is not addressable and thus we cannot extend it, etc. // Instead, we just ensure that the value is addressable. if !rv.CanAddr() { rvk = rv.Kind() rv2 = d.oneShotAddrRV(rvType(rv), rvk) if rvk == reflect.Interface { rvSetIntf(rv2, rv) } else { rvSetDirect(rv2, rv) } rv = rv2 } d.decodeValue(rv, nil) ext.UpdateExt(v, rv2i(rv)) } func (d *Decoder) sideDecode(v interface{}, basetype reflect.Type, bs []byte) { // NewDecoderBytes(bs, d.hh).decodeValue(baseRV(v), d.h.fnNoExt(basetype)) defer func(rb bytesDecReader, bytes bool, c containerState, dbs decByteState, depth int16, r decReader, state interface{}) { d.rb = rb d.bytes = bytes d.c = c d.decByteState = dbs d.depth = depth d.decReader = r d.d.restoreState(state) }(d.rb, d.bytes, d.c, d.decByteState, d.depth, d.decReader, d.d.captureState()) // d.rb.reset(in) d.rb = bytesDecReader{bs[:len(bs):len(bs)], 0} d.bytes = true d.decReader = &d.rb d.d.resetState() d.c = 0 d.decByteState = decByteStateNone d.depth = 0 // must call using fnNoExt d.decodeValue(baseRV(v), d.h.fnNoExt(basetype)) } func (d *Decoder) fauxUnionReadRawBytes(asString bool) { if asString || d.h.RawToString { d.n.v = valueTypeString // fauxUnion is only used within DecodeNaked calls; consequently, we should try to intern. d.n.s = d.stringZC(d.d.DecodeBytes(nil)) } else { d.n.v = valueTypeBytes d.n.l = d.d.DecodeBytes([]byte{}) } } func (d *Decoder) oneShotAddrRV(rvt reflect.Type, rvk reflect.Kind) reflect.Value { if decUseTransient && (numBoolStrSliceBitset.isset(byte(rvk)) || ((rvk == reflect.Struct || rvk == reflect.Array) && d.h.getTypeInfo(rt2id(rvt), rvt).flagCanTransient)) { return d.perType.TransientAddrK(rvt, rvk) } return rvZeroAddrK(rvt, rvk) } // -------------------------------------------------- // decSliceHelper assists when decoding into a slice, from a map or an array in the stream. // A slice can be set from a map or array in stream. This supports the MapBySlice interface. // // Note: if IsNil, do not call ElemContainerState. type decSliceHelper struct { d *Decoder ct valueType Array bool IsNil bool } func (d *Decoder) decSliceHelperStart() (x decSliceHelper, clen int) { x.ct = d.d.ContainerType() x.d = d switch x.ct { case valueTypeNil: x.IsNil = true case valueTypeArray: x.Array = true clen = d.arrayStart(d.d.ReadArrayStart()) case valueTypeMap: clen = d.mapStart(d.d.ReadMapStart()) clen += clen default: d.errorf("only encoded map or array can be decoded into a slice (%d)", x.ct) } return } func (x decSliceHelper) End() { if x.IsNil { } else if x.Array { x.d.arrayEnd() } else { x.d.mapEnd() } } func (x decSliceHelper) ElemContainerState(index int) { // Note: if isnil, clen=0, so we never call into ElemContainerState if x.Array { x.d.arrayElem() } else if index&1 == 0 { // index%2 == 0 { x.d.mapElemKey() } else { x.d.mapElemValue() } } func (x decSliceHelper) arrayCannotExpand(hasLen bool, lenv, j, containerLenS int) { x.d.arrayCannotExpand(lenv, j+1) // drain completely and return x.ElemContainerState(j) x.d.swallow() j++ for ; x.d.containerNext(j, containerLenS, hasLen); j++ { x.ElemContainerState(j) x.d.swallow() } x.End() } // decNextValueBytesHelper helps with NextValueBytes calls. // // Typical usage: // - each Handle's decDriver will implement a high level nextValueBytes, // which will track the current cursor, delegate to a nextValueBytesR // method, and then potentially call bytesRdV at the end. // // See simple.go for typical usage model. type decNextValueBytesHelper struct { d *Decoder } func (x decNextValueBytesHelper) append1(v *[]byte, b byte) { if *v != nil && !x.d.bytes { *v = append(*v, b) } } func (x decNextValueBytesHelper) appendN(v *[]byte, b ...byte) { if *v != nil && !x.d.bytes { *v = append(*v, b...) } } func (x decNextValueBytesHelper) bytesRdV(v *[]byte, startpos uint) { if x.d.bytes { *v = x.d.rb.b[startpos:x.d.rb.c] } } // 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 *Decoder } func (x decNegintPosintFloatNumberHelper) uint64(ui uint64, neg, ok bool) uint64 { if ok && !neg { return ui } return x.uint64TryFloat(ok) } func (x decNegintPosintFloatNumberHelper) uint64TryFloat(ok bool) (ui uint64) { if ok { // neg = true x.d.errorf("assigning negative signed value to unsigned type") } f, ok := x.d.d.decFloat() if ok && f >= 0 && noFrac64(math.Float64bits(f)) { ui = uint64(f) } else { x.d.errorf("invalid number loading uint64, with descriptor: %v", x.d.d.descBd()) } return ui } func decNegintPosintFloatNumberHelperInt64v(ui uint64, neg, incrIfNeg bool) (i int64) { if neg && incrIfNeg { ui++ } i = chkOvf.SignedIntV(ui) if neg { i = -i } return } func (x decNegintPosintFloatNumberHelper) int64(ui uint64, neg, ok bool) (i int64) { if ok { return decNegintPosintFloatNumberHelperInt64v(ui, neg, x.d.cbor) } // return x.int64TryFloat() // } // func (x decNegintPosintFloatNumberHelper) int64TryFloat() (i int64) { f, ok := x.d.d.decFloat() if ok && noFrac64(math.Float64bits(f)) { i = int64(f) } else { x.d.errorf("invalid number loading uint64, with descriptor: %v", x.d.d.descBd()) } return } func (x decNegintPosintFloatNumberHelper) float64(f float64, ok bool) float64 { if ok { return f } return x.float64TryInteger() } func (x decNegintPosintFloatNumberHelper) float64TryInteger() float64 { ui, neg, ok := x.d.d.decInteger() if !ok { x.d.errorf("invalid descriptor for float: %v", x.d.d.descBd()) } return float64(decNegintPosintFloatNumberHelperInt64v(ui, neg, x.d.cbor)) } // 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 } func decByteSlice(r *decRd, clen, maxInitLen int, bs []byte) (bsOut []byte) { if clen == 0 { return zeroByteSlice } if len(bs) == clen { bsOut = bs r.readb(bsOut) } else if cap(bs) >= clen { bsOut = bs[:clen] r.readb(bsOut) } else { var len2 int for len2 < clen { len3 := decInferLen(clen-len2, maxInitLen, 1) bs3 := bsOut bsOut = make([]byte, len2+len3) copy(bsOut, bs3) r.readb(bsOut[len2:]) len2 += len3 } } 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, maxlen, unit int) int { // 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 = 256 * 1024 // 256Kb 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 clen = 64 / unit if clen > minLenIfUnset { return clen } return minLenIfUnset } if unit <= 0 { return clen } if maxlen <= 0 { maxlen = maxMem / unit } if clen < maxlen { return clen } return maxlen } go-1.2.8/codec/doc.go000066400000000000000000000212431435255326100143100ustar00rootroot00000000000000// 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: 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 # 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 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 go-1.2.8/codec/encode.go000066400000000000000000001203561435255326100150050ustar00rootroot00000000000000// 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" "errors" "io" "reflect" "sort" "strconv" "time" ) // defEncByteBufSize is the default size of []byte used // for bufio buffer or []byte (when nil passed) const defEncByteBufSize = 1 << 10 // 4:16, 6:64, 8:256, 10:1024 var errEncoderNotInitialized = errors.New("Encoder not initialized") // encDriver abstracts the actual codec (binc vs msgpack, etc) type encDriver interface { EncodeNil() EncodeInt(i int64) EncodeUint(i uint64) EncodeBool(b bool) EncodeFloat32(f float32) EncodeFloat64(f float64) EncodeRawExt(re *RawExt) EncodeExt(v interface{}, basetype reflect.Type, xtag uint64, ext Ext) // EncodeString using cUTF8, honor'ing StringToRaw flag EncodeString(v string) EncodeStringBytesRaw(v []byte) EncodeTime(time.Time) WriteArrayStart(length int) WriteArrayEnd() WriteMapStart(length int) WriteMapEnd() // reset will reset current encoding runtime state, and cached information from the handle reset() encoder() *Encoder driverStateManager } type encDriverContainerTracker interface { WriteArrayElem() WriteMapElemKey() WriteMapElemValue() } type encDriverNoState struct{} func (encDriverNoState) captureState() interface{} { return nil } func (encDriverNoState) reset() {} func (encDriverNoState) resetState() {} func (encDriverNoState) restoreState(v interface{}) {} type encDriverNoopContainerWriter struct{} func (encDriverNoopContainerWriter) WriteArrayStart(length int) {} func (encDriverNoopContainerWriter) WriteArrayEnd() {} func (encDriverNoopContainerWriter) WriteMapStart(length int) {} func (encDriverNoopContainerWriter) WriteMapEnd() {} // 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{} ascii bool isRv 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 } // 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 } // --------------------------------------------- func (e *Encoder) rawExt(f *codecFnInfo, rv reflect.Value) { e.e.EncodeRawExt(rv2i(rv).(*RawExt)) } func (e *Encoder) ext(f *codecFnInfo, rv reflect.Value) { e.e.EncodeExt(rv2i(rv), f.ti.rt, f.xfTag, f.xfFn) } func (e *Encoder) selferMarshal(f *codecFnInfo, rv reflect.Value) { rv2i(rv).(Selfer).CodecEncodeSelf(e) } func (e *Encoder) binaryMarshal(f *codecFnInfo, rv reflect.Value) { bs, fnerr := rv2i(rv).(encoding.BinaryMarshaler).MarshalBinary() e.marshalRaw(bs, fnerr) } func (e *Encoder) textMarshal(f *codecFnInfo, rv reflect.Value) { bs, fnerr := rv2i(rv).(encoding.TextMarshaler).MarshalText() e.marshalUtf8(bs, fnerr) } func (e *Encoder) jsonMarshal(f *codecFnInfo, rv reflect.Value) { bs, fnerr := rv2i(rv).(jsonMarshaler).MarshalJSON() e.marshalAsis(bs, fnerr) } func (e *Encoder) raw(f *codecFnInfo, rv reflect.Value) { e.rawBytes(rv2i(rv).(Raw)) } func (e *Encoder) encodeComplex64(v complex64) { if imag(v) != 0 { e.errorf("cannot encode complex number: %v, with imaginary values: %v", v, imag(v)) } e.e.EncodeFloat32(real(v)) } func (e *Encoder) encodeComplex128(v complex128) { if imag(v) != 0 { e.errorf("cannot encode complex number: %v, with imaginary values: %v", v, imag(v)) } e.e.EncodeFloat64(real(v)) } func (e *Encoder) kBool(f *codecFnInfo, rv reflect.Value) { e.e.EncodeBool(rvGetBool(rv)) } func (e *Encoder) kTime(f *codecFnInfo, rv reflect.Value) { e.e.EncodeTime(rvGetTime(rv)) } func (e *Encoder) kString(f *codecFnInfo, rv reflect.Value) { e.e.EncodeString(rvGetString(rv)) } func (e *Encoder) kFloat32(f *codecFnInfo, rv reflect.Value) { e.e.EncodeFloat32(rvGetFloat32(rv)) } func (e *Encoder) kFloat64(f *codecFnInfo, rv reflect.Value) { e.e.EncodeFloat64(rvGetFloat64(rv)) } func (e *Encoder) kComplex64(f *codecFnInfo, rv reflect.Value) { e.encodeComplex64(rvGetComplex64(rv)) } func (e *Encoder) kComplex128(f *codecFnInfo, rv reflect.Value) { e.encodeComplex128(rvGetComplex128(rv)) } func (e *Encoder) kInt(f *codecFnInfo, rv reflect.Value) { e.e.EncodeInt(int64(rvGetInt(rv))) } func (e *Encoder) kInt8(f *codecFnInfo, rv reflect.Value) { e.e.EncodeInt(int64(rvGetInt8(rv))) } func (e *Encoder) kInt16(f *codecFnInfo, rv reflect.Value) { e.e.EncodeInt(int64(rvGetInt16(rv))) } func (e *Encoder) kInt32(f *codecFnInfo, rv reflect.Value) { e.e.EncodeInt(int64(rvGetInt32(rv))) } func (e *Encoder) kInt64(f *codecFnInfo, rv reflect.Value) { e.e.EncodeInt(int64(rvGetInt64(rv))) } func (e *Encoder) kUint(f *codecFnInfo, rv reflect.Value) { e.e.EncodeUint(uint64(rvGetUint(rv))) } func (e *Encoder) kUint8(f *codecFnInfo, rv reflect.Value) { e.e.EncodeUint(uint64(rvGetUint8(rv))) } func (e *Encoder) kUint16(f *codecFnInfo, rv reflect.Value) { e.e.EncodeUint(uint64(rvGetUint16(rv))) } func (e *Encoder) kUint32(f *codecFnInfo, rv reflect.Value) { e.e.EncodeUint(uint64(rvGetUint32(rv))) } func (e *Encoder) kUint64(f *codecFnInfo, rv reflect.Value) { e.e.EncodeUint(uint64(rvGetUint64(rv))) } func (e *Encoder) kUintptr(f *codecFnInfo, rv reflect.Value) { e.e.EncodeUint(uint64(rvGetUintptr(rv))) } func (e *Encoder) kErr(f *codecFnInfo, rv reflect.Value) { e.errorf("unsupported kind %s, for %#v", rv.Kind(), 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 } func (e *Encoder) kSeqFn(rtelem reflect.Type) (fn *codecFn) { for rtelem.Kind() == reflect.Ptr { rtelem = rtelem.Elem() } // 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 rtelem.Kind() != reflect.Interface { fn = e.h.fn(rtelem) } return } func (e *Encoder) kSliceWMbs(rv reflect.Value, ti *typeInfo) { var l = rvLenSlice(rv) if l == 0 { e.mapStart(0) } else { e.haltOnMbsOddLen(l) e.mapStart(l >> 1) // e.mapStart(l / 2) fn := e.kSeqFn(ti.elem) for j := 0; j < l; j++ { if j&1 == 0 { // j%2 == 0 { e.mapElemKey() } else { e.mapElemValue() } e.encodeValue(rvSliceIndex(rv, j, ti), fn) } } e.mapEnd() } func (e *Encoder) kSliceW(rv reflect.Value, ti *typeInfo) { var l = rvLenSlice(rv) e.arrayStart(l) if l > 0 { fn := e.kSeqFn(ti.elem) for j := 0; j < l; j++ { e.arrayElem() e.encodeValue(rvSliceIndex(rv, j, ti), fn) } } e.arrayEnd() } func (e *Encoder) kArrayWMbs(rv reflect.Value, ti *typeInfo) { var l = rv.Len() if l == 0 { e.mapStart(0) } else { e.haltOnMbsOddLen(l) e.mapStart(l >> 1) // e.mapStart(l / 2) fn := e.kSeqFn(ti.elem) for j := 0; j < l; j++ { if j&1 == 0 { // j%2 == 0 { e.mapElemKey() } else { e.mapElemValue() } e.encodeValue(rv.Index(j), fn) } } e.mapEnd() } func (e *Encoder) kArrayW(rv reflect.Value, ti *typeInfo) { var l = rv.Len() e.arrayStart(l) if l > 0 { fn := e.kSeqFn(ti.elem) for j := 0; j < l; j++ { e.arrayElem() e.encodeValue(rv.Index(j), fn) } } e.arrayEnd() } func (e *Encoder) kChan(f *codecFnInfo, rv reflect.Value) { if f.ti.chandir&uint8(reflect.RecvDir) == 0 { e.errorf("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.kSliceWMbs(rv, ti) } else { e.kSliceW(rv, ti) } } func (e *Encoder) kSlice(f *codecFnInfo, rv reflect.Value) { if f.ti.mbs { e.kSliceWMbs(rv, f.ti) } else if f.ti.rtid == uint8SliceTypId || uint8TypId == rt2id(f.ti.elem) { e.e.EncodeStringBytesRaw(rvGetBytes(rv)) } else { e.kSliceW(rv, f.ti) } } func (e *Encoder) kArray(f *codecFnInfo, rv reflect.Value) { if f.ti.mbs { e.kArrayWMbs(rv, f.ti) } else if handleBytesWithinKArray && uint8TypId == rt2id(f.ti.elem) { e.e.EncodeStringBytesRaw(rvGetArrayBytes(rv, []byte{})) } else { e.kArrayW(rv, f.ti) } } func (e *Encoder) 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.EncodeStringBytesRaw(bs) e.blist.put(bs) if !byteSliceSameData(bs0, bs) { e.blist.put(bs0) } } func (e *Encoder) kStructSfi(f *codecFnInfo) []*structFieldInfo { if e.h.Canonical { return f.ti.sfi.sorted() } return f.ti.sfi.source() } func (e *Encoder) kStructNoOmitempty(f *codecFnInfo, rv reflect.Value) { var tisfi []*structFieldInfo if f.ti.toArray || e.h.StructToArray { // toArray tisfi = f.ti.sfi.source() e.arrayStart(len(tisfi)) for _, si := range tisfi { e.arrayElem() e.encodeValue(si.path.field(rv), nil) } e.arrayEnd() } else { tisfi = e.kStructSfi(f) e.mapStart(len(tisfi)) keytyp := f.ti.keyType for _, si := range tisfi { e.mapElemKey() e.kStructFieldKey(keytyp, si.path.encNameAsciiAlphaNum, si.encName) e.mapElemValue() e.encodeValue(si.path.field(rv), nil) } e.mapEnd() } } func (e *Encoder) kStructFieldKey(keyType valueType, encNameAsciiAlphaNum bool, encName string) { encStructFieldKey(encName, e.e, e.w(), keyType, encNameAsciiAlphaNum, e.js) } func (e *Encoder) kStruct(f *codecFnInfo, rv reflect.Value) { var newlen int ti := f.ti toMap := !(ti.toArray || e.h.StructToArray) var mf map[string]interface{} if ti.flagMissingFielder { mf = rv2i(rv).(MissingFielder).CodecMissingFields() toMap = true newlen += len(mf) } else if ti.flagMissingFielderPtr { rv2 := e.addrRV(rv, ti.rt, ti.ptr) mf = rv2i(rv2).(MissingFielder).CodecMissingFields() toMap = true newlen += len(mf) } tisfi := ti.sfi.source() newlen += len(tisfi) var fkvs = e.slist.get(newlen)[:newlen] recur := e.h.RecursiveEmptyCheck var kv sfiRv var j int if toMap { newlen = 0 for _, si := range e.kStructSfi(f) { kv.r = si.path.field(rv) if si.path.omitEmpty && isEmptyValue(kv.r, e.h.TypeInfos, recur) { continue } 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}) } } e.mapStart(newlen + len(mf2s)) // 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, kv.v.path.encNameAsciiAlphaNum, true} } for _, v := range mf2s { mf2w[j] = encStructFieldObj{v.v, reflect.Value{}, v.i, false, false} j++ } sort.Sort((encStructFieldObjSlice)(mf2w)) for _, v := range mf2w { e.mapElemKey() e.kStructFieldKey(ti.keyType, v.ascii, v.key) e.mapElemValue() if v.isRv { e.encodeValue(v.rv, nil) } else { e.encode(v.intf) } } } else { keytyp := ti.keyType for j = 0; j < newlen; j++ { kv = fkvs[j] e.mapElemKey() e.kStructFieldKey(keytyp, kv.v.path.encNameAsciiAlphaNum, kv.v.encName) e.mapElemValue() e.encodeValue(kv.r, nil) } for _, v := range mf2s { e.mapElemKey() e.kStructFieldKey(keytyp, false, v.v) e.mapElemValue() e.encode(v.i) } } e.mapEnd() } else { newlen = len(tisfi) for i, si := range tisfi { // use unsorted array (to match sequence in struct) kv.r = si.path.field(rv) // use the zero value. // if a reference or struct, set to nil (so you do not output too much) if si.path.omitEmpty && isEmptyValue(kv.r, e.h.TypeInfos, recur) { switch kv.r.Kind() { case reflect.Struct, reflect.Interface, reflect.Ptr, reflect.Array, reflect.Map, reflect.Slice: kv.r = reflect.Value{} //encode as nil } } fkvs[i] = kv } // encode it all e.arrayStart(newlen) for j = 0; j < newlen; j++ { e.arrayElem() e.encodeValue(fkvs[j].r, nil) } e.arrayEnd() } // 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) kMap(f *codecFnInfo, rv reflect.Value) { l := rvLenMap(rv) e.mapStart(l) if l == 0 { e.mapEnd() return } // 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 *codecFn 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.h.fn(rtval) } var rvv = mapAddrLoopvarRV(f.ti.elem, vtypeKind) rtkey := f.ti.key var keyTypeIsString = stringTypId == rt2id(rtkey) // rtkeyid if keyTypeIsString { keyFn = e.h.fn(rtkey) } else { for rtkey.Kind() == reflect.Ptr { rtkey = rtkey.Elem() } if rtkey.Kind() != reflect.Interface { keyFn = e.h.fn(rtkey) } } if e.h.Canonical { e.kMapCanonical(f.ti, rv, rvv, keyFn, valFn) e.mapEnd() return } var rvk = mapAddrLoopvarRV(f.ti.key, ktypeKind) var it mapIter mapRange(&it, rv, rvk, rvv, true) for it.Next() { e.mapElemKey() if keyTypeIsString { e.e.EncodeString(it.Key().String()) } else { e.encodeValue(it.Key(), keyFn) } e.mapElemValue() e.encodeValue(it.Value(), valFn) } it.Done() e.mapEnd() } func (e *Encoder) kMapCanonical(ti *typeInfo, rv, rvv reflect.Value, keyFn, valFn *codecFn) { // 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() 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.mapElemKey() if rtkeydecl { e.e.EncodeBool(mks[i].Bool()) } else { e.encodeValueNonNil(mks[i], keyFn) } e.mapElemValue() e.encodeValue(mapGet(rv, mks[i], rvv, kfast, visindirect, visref), valFn) } case reflect.String: mksv := make([]stringRv, len(mks)) for i, k := range mks { v := &mksv[i] v.r = k v.v = k.String() } sort.Sort(stringRvSlice(mksv)) for i := range mksv { e.mapElemKey() 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, kfast, visindirect, visref), valFn) } case reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64, reflect.Uint, reflect.Uintptr: mksv := make([]uint64Rv, len(mks)) for i, k := range mks { v := &mksv[i] v.r = k v.v = k.Uint() } sort.Sort(uint64RvSlice(mksv)) for i := range mksv { e.mapElemKey() 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, kfast, visindirect, visref), valFn) } case reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64, reflect.Int: mksv := make([]int64Rv, len(mks)) for i, k := range mks { v := &mksv[i] v.r = k v.v = k.Int() } sort.Sort(int64RvSlice(mksv)) for i := range mksv { e.mapElemKey() 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, kfast, visindirect, visref), valFn) } case reflect.Float32: mksv := make([]float64Rv, len(mks)) for i, k := range mks { v := &mksv[i] v.r = k v.v = k.Float() } sort.Sort(float64RvSlice(mksv)) for i := range mksv { e.mapElemKey() 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, kfast, visindirect, visref), valFn) } case reflect.Float64: mksv := make([]float64Rv, len(mks)) for i, k := range mks { v := &mksv[i] v.r = k v.v = k.Float() } sort.Sort(float64RvSlice(mksv)) for i := range mksv { e.mapElemKey() 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, kfast, visindirect, visref), 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) } sort.Sort(timeRvSlice(mksv)) for i := range mksv { e.mapElemKey() e.e.EncodeTime(mksv[i].v) e.mapElemValue() e.encodeValue(mapGet(rv, mksv[i].r, rvv, kfast, visindirect, visref), 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)) func() { // replicate sideEncode logic defer func(wb bytesEncAppender, bytes bool, c containerState, state interface{}) { e.wb = wb e.bytes = bytes e.c = c e.e.restoreState(state) }(e.wb, e.bytes, e.c, e.e.captureState()) // e2 := NewEncoderBytes(&mksv, e.hh) e.wb = bytesEncAppender{mksv[:0], &mksv} e.bytes = true e.c = 0 e.e.resetState() for i, k := range mks { v := &mksbv[i] l := len(mksv) e.encodeValue(k, nil) e.atEndOfEncode() e.w().end() v.r = k v.v = mksv[l:] } }() sort.Sort(bytesRvSlice(mksbv)) for j := range mksbv { e.mapElemKey() e.encWr.writeb(mksbv[j].v) e.mapElemValue() e.encodeValue(mapGet(rv, mksbv[j].r, rvv, kfast, visindirect, visref), valFn) } e.blist.put(mksv) if !byteSliceSameData(bs0, mksv) { e.blist.put(bs0) } } } // 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 struct { panicHdl e encDriver h *BasicHandle // hopefully, reduce derefencing cost by laying the encWriter inside the Encoder encWr // ---- cpu cache line boundary hh Handle blist bytesFreelist err error // ---- cpu cache line boundary // ---- writable fields during execution --- *try* to keep in sep cache line // ci 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. ci []interface{} // []uintptr perType encPerType slist sfiRvFreelist } // 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 { e := h.newEncDriver().encoder() if w != nil { e.Reset(w) } return e } // 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 { e := h.newEncDriver().encoder() if out != nil { e.ResetBytes(out) } return e } func (e *Encoder) init(h Handle) { initHandle(h) e.err = errEncoderNotInitialized e.bytes = true e.hh = h e.h = h.getBasicHandle() e.be = e.hh.isBinary() } func (e *Encoder) w() *encWr { return &e.encWr } func (e *Encoder) resetCommon() { e.e.reset() if e.ci != nil { e.ci = e.ci[:0] } e.c = 0 e.calls = 0 e.seq = 0 e.err = nil } // 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) Reset(w io.Writer) { e.bytes = false if e.wf == nil { e.wf = new(bufioEncWriter) } e.wf.reset(w, e.h.WriterBufferSize, &e.blist) e.resetCommon() } // ResetBytes resets the Encoder with a new destination output []byte. func (e *Encoder) ResetBytes(out *[]byte) { e.bytes = true e.wb.reset(encInBytes(out), out) e.resetCommon() } // 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. func (e *Encoder) 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 if !debugging { defer func() { // if error occurred during encoding, return that error; // else if error occurred on end'ing (i.e. during flush), return that error. if x := recover(); x != nil { panicValToErr(e, x, &e.err) err = e.err } }() } 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. func (e *Encoder) MustEncode(v interface{}) { halt.onerror(e.err) if e.hh == nil { halt.onerror(errNoFormatHandle) } e.calls++ e.encode(v) e.calls-- if e.calls == 0 { e.atEndOfEncode() e.w().end() } } // Release releases shared (pooled) resources. // // It is important to call Release() when done with an Encoder, so those resources // are released instantly for use by subsequently created Encoders. // // Deprecated: Release is a no-op as pooled resources are not used with an Encoder. // This method is kept for compatibility reasons only. func (e *Encoder) Release() { } func (e *Encoder) encode(iv interface{}) { // MARKER: a switch with only concrete types can be optimized. // consequently, we deal with nil and interfaces outside the switch. if iv == nil { e.e.EncodeNil() return } rv, ok := isNil(iv) if ok { e.e.EncodeNil() return } switch v := iv.(type) { // case nil: // case Selfer: case Raw: e.rawBytes(v) case reflect.Value: e.encodeValue(v, nil) 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.EncodeStringBytesRaw(v) 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: if *v == nil { e.e.EncodeNil() } else { e.e.EncodeStringBytesRaw(*v) } default: // we can't check non-predefined types, as they might be a Selfer or extension. if skipFastpathTypeSwitchInDirectCall || !fastpathEncodeTypeSwitch(iv, e) { e.encodeValue(rv, nil) } } } // 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) encodeValue(rv reflect.Value, fn *codecFn) { // if a valid fn is passed, it MUST BE for the dereferenced type of rv // MARKER: We check if value is nil here, so that the kXXX method do not have to. var sptr interface{} var rvp reflect.Value var rvpValid bool TOP: switch rv.Kind() { case reflect.Ptr: if rvIsNil(rv) { e.e.EncodeNil() return } rvpValid = true rvp = rv rv = rv.Elem() goto TOP case reflect.Interface: if rvIsNil(rv) { e.e.EncodeNil() return } rvpValid = false rvp = reflect.Value{} rv = rv.Elem() goto TOP case reflect.Struct: if rvpValid && e.h.CheckCircularRef { sptr = rv2i(rvp) for _, vv := range e.ci { if eq4i(sptr, vv) { // error if sptr already seen e.errorf("circular reference found: %p, %T", sptr, sptr) } } e.ci = append(e.ci, sptr) } case reflect.Slice, reflect.Map, reflect.Chan: if rvIsNil(rv) { e.e.EncodeNil() return } case reflect.Invalid, reflect.Func: e.e.EncodeNil() return } if fn == nil { fn = e.h.fn(rvType(rv)) } if !fn.i.addrE { // typically, addrE = false, so check it first // keep rv same } else if rvpValid { rv = rvp } else { rv = e.addrRV(rv, fn.i.ti.rt, fn.i.ti.ptr) } fn.fe(e, &fn.i, rv) if sptr != nil { // remove sptr e.ci = e.ci[:len(e.ci)-1] } } // encodeValueNonNil can encode a number, bool, or string // OR non-nil values of kind map, slice and chan. func (e *Encoder) encodeValueNonNil(rv reflect.Value, fn *codecFn) { if fn == nil { fn = e.h.fn(rvType(rv)) } if fn.i.addrE { // typically, addrE = false, so check it first rv = e.addrRV(rv, fn.i.ti.rt, fn.i.ti.ptr) } fn.fe(e, &fn.i, rv) } // addrRV returns a addressable value which may be readonly func (e *Encoder) 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 *Encoder) marshalUtf8(bs []byte, fnerr error) { e.onerror(fnerr) if bs == nil { e.e.EncodeNil() } else { e.e.EncodeString(stringView(bs)) } } func (e *Encoder) marshalAsis(bs []byte, fnerr error) { e.onerror(fnerr) if bs == nil { e.e.EncodeNil() } else { e.encWr.writeb(bs) // e.asis(bs) } } func (e *Encoder) marshalRaw(bs []byte, fnerr error) { e.onerror(fnerr) if bs == nil { e.e.EncodeNil() } else { e.e.EncodeStringBytesRaw(bs) } } func (e *Encoder) rawBytes(vv Raw) { v := []byte(vv) if !e.h.Raw { e.errorf("Raw values cannot be encoded: %v", v) } e.encWr.writeb(v) } func (e *Encoder) wrapErr(v error, err *error) { *err = wrapCodecErr(v, e.hh.Name(), 0, true) } // ---- container tracker methods // Note: We update the .c after calling the callback. // This way, the callback can know what the last status was. func (e *Encoder) mapStart(length int) { e.e.WriteMapStart(length) e.c = containerMapStart } func (e *Encoder) mapElemKey() { if e.js { e.jsondriver().WriteMapElemKey() } e.c = containerMapKey } func (e *Encoder) mapElemValue() { if e.js { e.jsondriver().WriteMapElemValue() } e.c = containerMapValue } func (e *Encoder) mapEnd() { e.e.WriteMapEnd() e.c = 0 } func (e *Encoder) arrayStart(length int) { e.e.WriteArrayStart(length) e.c = containerArrayStart } func (e *Encoder) arrayElem() { if e.js { e.jsondriver().WriteArrayElem() } e.c = containerArrayElem } func (e *Encoder) arrayEnd() { e.e.WriteArrayEnd() e.c = 0 } // ---------- func (e *Encoder) haltOnMbsOddLen(length int) { if length&1 != 0 { // similar to &1==1 or %2 == 1 e.errorf("mapBySlice requires even slice length, but got %v", length) } } func (e *Encoder) atEndOfEncode() { // e.e.atEndOfEncode() if e.js { e.jsondriver().atEndOfEncode() } } func (e *Encoder) sideEncode(v interface{}, basetype reflect.Type, bs *[]byte) { // rv := baseRV(v) // e2 := NewEncoderBytes(bs, e.hh) // e2.encodeValue(rv, e2.h.fnNoExt(basetype)) // e2.atEndOfEncode() // e2.w().end() defer func(wb bytesEncAppender, bytes bool, c containerState, state interface{}) { e.wb = wb e.bytes = bytes e.c = c e.e.restoreState(state) }(e.wb, e.bytes, e.c, e.e.captureState()) e.wb = bytesEncAppender{encInBytes(bs)[:0], bs} e.bytes = true e.c = 0 e.e.resetState() // must call using fnNoExt rv := baseRV(v) e.encodeValue(rv, e.h.fnNoExt(basetype)) e.atEndOfEncode() e.w().end() } func encInBytes(out *[]byte) (in []byte) { in = *out if in == nil { in = make([]byte, defEncByteBufSize) } return } func encStructFieldKey(encName string, ee encDriver, w *encWr, keyType valueType, encNameAsciiAlphaNum bool, js bool) { // use if-else-if, not switch (which compiles to binary-search) // since keyType is typically valueTypeString, branch prediction is pretty good. if keyType == valueTypeString { if js && encNameAsciiAlphaNum { // keyType == valueTypeString w.writeqstr(encName) } else { // keyType == valueTypeString ee.EncodeString(encName) } } else if keyType == valueTypeInt { ee.EncodeInt(must.Int(strconv.ParseInt(encName, 10, 64))) } else if keyType == valueTypeUint { ee.EncodeUint(must.Uint(strconv.ParseUint(encName, 10, 64))) } else if keyType == valueTypeFloat { ee.EncodeFloat64(must.Float(strconv.ParseFloat(encName, 64))) } else { halt.errorf("invalid struct key type: %v", keyType) } } go-1.2.8/codec/fast-path.generated.go000066400000000000000000004670311435255326100174000ustar00rootroot00000000000000//go:build !notfastpath && !codec.notfastpath // +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 fast-path.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" "sort" ) const fastpathEnabled = true type fastpathT struct{} var fastpathTV fastpathT type fastpathE struct { rt reflect.Type encfn func(*Encoder, *codecFnInfo, reflect.Value) decfn func(*Decoder, *codecFnInfo, reflect.Value) } type fastpathA [56]fastpathE type fastpathARtid [56]uintptr var fastpathAv fastpathA var fastpathAvRtid fastpathARtid type fastpathAslice struct{} func (fastpathAslice) Len() int { return 56 } func (fastpathAslice) Less(i, j int) bool { return fastpathAvRtid[uint(i)] < fastpathAvRtid[uint(j)] } func (fastpathAslice) Swap(i, j int) { fastpathAvRtid[uint(i)], fastpathAvRtid[uint(j)] = fastpathAvRtid[uint(j)], fastpathAvRtid[uint(i)] fastpathAv[uint(i)], fastpathAv[uint(j)] = fastpathAv[uint(j)], fastpathAv[uint(i)] } func fastpathAvIndex(rtid uintptr) int { // use binary search to grab the index (adapted from sort/search.go) // Note: we use goto (instead of for loop) so this can be inlined. // h, i, j := 0, 0, 56 var h, i uint var j uint = 56 LOOP: if i < j { h = (i + j) >> 1 // avoid overflow when computing h // h = i + (j-i)/2 if fastpathAvRtid[h] < rtid { i = h + 1 } else { j = h } goto LOOP } if i < 56 && fastpathAvRtid[i] == rtid { return int(i) } return -1 } // due to possible initialization loop error, make fastpath in an init() func init() { var i uint = 0 fn := func(v interface{}, fe func(*Encoder, *codecFnInfo, reflect.Value), fd func(*Decoder, *codecFnInfo, reflect.Value)) { xrt := reflect.TypeOf(v) xptr := rt2id(xrt) fastpathAvRtid[i] = xptr fastpathAv[i] = fastpathE{xrt, fe, fd} i++ } fn([]interface{}(nil), (*Encoder).fastpathEncSliceIntfR, (*Decoder).fastpathDecSliceIntfR) fn([]string(nil), (*Encoder).fastpathEncSliceStringR, (*Decoder).fastpathDecSliceStringR) fn([][]byte(nil), (*Encoder).fastpathEncSliceBytesR, (*Decoder).fastpathDecSliceBytesR) fn([]float32(nil), (*Encoder).fastpathEncSliceFloat32R, (*Decoder).fastpathDecSliceFloat32R) fn([]float64(nil), (*Encoder).fastpathEncSliceFloat64R, (*Decoder).fastpathDecSliceFloat64R) fn([]uint8(nil), (*Encoder).fastpathEncSliceUint8R, (*Decoder).fastpathDecSliceUint8R) fn([]uint64(nil), (*Encoder).fastpathEncSliceUint64R, (*Decoder).fastpathDecSliceUint64R) fn([]int(nil), (*Encoder).fastpathEncSliceIntR, (*Decoder).fastpathDecSliceIntR) fn([]int32(nil), (*Encoder).fastpathEncSliceInt32R, (*Decoder).fastpathDecSliceInt32R) fn([]int64(nil), (*Encoder).fastpathEncSliceInt64R, (*Decoder).fastpathDecSliceInt64R) fn([]bool(nil), (*Encoder).fastpathEncSliceBoolR, (*Decoder).fastpathDecSliceBoolR) fn(map[string]interface{}(nil), (*Encoder).fastpathEncMapStringIntfR, (*Decoder).fastpathDecMapStringIntfR) fn(map[string]string(nil), (*Encoder).fastpathEncMapStringStringR, (*Decoder).fastpathDecMapStringStringR) fn(map[string][]byte(nil), (*Encoder).fastpathEncMapStringBytesR, (*Decoder).fastpathDecMapStringBytesR) fn(map[string]uint8(nil), (*Encoder).fastpathEncMapStringUint8R, (*Decoder).fastpathDecMapStringUint8R) fn(map[string]uint64(nil), (*Encoder).fastpathEncMapStringUint64R, (*Decoder).fastpathDecMapStringUint64R) fn(map[string]int(nil), (*Encoder).fastpathEncMapStringIntR, (*Decoder).fastpathDecMapStringIntR) fn(map[string]int32(nil), (*Encoder).fastpathEncMapStringInt32R, (*Decoder).fastpathDecMapStringInt32R) fn(map[string]float64(nil), (*Encoder).fastpathEncMapStringFloat64R, (*Decoder).fastpathDecMapStringFloat64R) fn(map[string]bool(nil), (*Encoder).fastpathEncMapStringBoolR, (*Decoder).fastpathDecMapStringBoolR) fn(map[uint8]interface{}(nil), (*Encoder).fastpathEncMapUint8IntfR, (*Decoder).fastpathDecMapUint8IntfR) fn(map[uint8]string(nil), (*Encoder).fastpathEncMapUint8StringR, (*Decoder).fastpathDecMapUint8StringR) fn(map[uint8][]byte(nil), (*Encoder).fastpathEncMapUint8BytesR, (*Decoder).fastpathDecMapUint8BytesR) fn(map[uint8]uint8(nil), (*Encoder).fastpathEncMapUint8Uint8R, (*Decoder).fastpathDecMapUint8Uint8R) fn(map[uint8]uint64(nil), (*Encoder).fastpathEncMapUint8Uint64R, (*Decoder).fastpathDecMapUint8Uint64R) fn(map[uint8]int(nil), (*Encoder).fastpathEncMapUint8IntR, (*Decoder).fastpathDecMapUint8IntR) fn(map[uint8]int32(nil), (*Encoder).fastpathEncMapUint8Int32R, (*Decoder).fastpathDecMapUint8Int32R) fn(map[uint8]float64(nil), (*Encoder).fastpathEncMapUint8Float64R, (*Decoder).fastpathDecMapUint8Float64R) fn(map[uint8]bool(nil), (*Encoder).fastpathEncMapUint8BoolR, (*Decoder).fastpathDecMapUint8BoolR) fn(map[uint64]interface{}(nil), (*Encoder).fastpathEncMapUint64IntfR, (*Decoder).fastpathDecMapUint64IntfR) fn(map[uint64]string(nil), (*Encoder).fastpathEncMapUint64StringR, (*Decoder).fastpathDecMapUint64StringR) fn(map[uint64][]byte(nil), (*Encoder).fastpathEncMapUint64BytesR, (*Decoder).fastpathDecMapUint64BytesR) fn(map[uint64]uint8(nil), (*Encoder).fastpathEncMapUint64Uint8R, (*Decoder).fastpathDecMapUint64Uint8R) fn(map[uint64]uint64(nil), (*Encoder).fastpathEncMapUint64Uint64R, (*Decoder).fastpathDecMapUint64Uint64R) fn(map[uint64]int(nil), (*Encoder).fastpathEncMapUint64IntR, (*Decoder).fastpathDecMapUint64IntR) fn(map[uint64]int32(nil), (*Encoder).fastpathEncMapUint64Int32R, (*Decoder).fastpathDecMapUint64Int32R) fn(map[uint64]float64(nil), (*Encoder).fastpathEncMapUint64Float64R, (*Decoder).fastpathDecMapUint64Float64R) fn(map[uint64]bool(nil), (*Encoder).fastpathEncMapUint64BoolR, (*Decoder).fastpathDecMapUint64BoolR) fn(map[int]interface{}(nil), (*Encoder).fastpathEncMapIntIntfR, (*Decoder).fastpathDecMapIntIntfR) fn(map[int]string(nil), (*Encoder).fastpathEncMapIntStringR, (*Decoder).fastpathDecMapIntStringR) fn(map[int][]byte(nil), (*Encoder).fastpathEncMapIntBytesR, (*Decoder).fastpathDecMapIntBytesR) fn(map[int]uint8(nil), (*Encoder).fastpathEncMapIntUint8R, (*Decoder).fastpathDecMapIntUint8R) fn(map[int]uint64(nil), (*Encoder).fastpathEncMapIntUint64R, (*Decoder).fastpathDecMapIntUint64R) fn(map[int]int(nil), (*Encoder).fastpathEncMapIntIntR, (*Decoder).fastpathDecMapIntIntR) fn(map[int]int32(nil), (*Encoder).fastpathEncMapIntInt32R, (*Decoder).fastpathDecMapIntInt32R) fn(map[int]float64(nil), (*Encoder).fastpathEncMapIntFloat64R, (*Decoder).fastpathDecMapIntFloat64R) fn(map[int]bool(nil), (*Encoder).fastpathEncMapIntBoolR, (*Decoder).fastpathDecMapIntBoolR) fn(map[int32]interface{}(nil), (*Encoder).fastpathEncMapInt32IntfR, (*Decoder).fastpathDecMapInt32IntfR) fn(map[int32]string(nil), (*Encoder).fastpathEncMapInt32StringR, (*Decoder).fastpathDecMapInt32StringR) fn(map[int32][]byte(nil), (*Encoder).fastpathEncMapInt32BytesR, (*Decoder).fastpathDecMapInt32BytesR) fn(map[int32]uint8(nil), (*Encoder).fastpathEncMapInt32Uint8R, (*Decoder).fastpathDecMapInt32Uint8R) fn(map[int32]uint64(nil), (*Encoder).fastpathEncMapInt32Uint64R, (*Decoder).fastpathDecMapInt32Uint64R) fn(map[int32]int(nil), (*Encoder).fastpathEncMapInt32IntR, (*Decoder).fastpathDecMapInt32IntR) fn(map[int32]int32(nil), (*Encoder).fastpathEncMapInt32Int32R, (*Decoder).fastpathDecMapInt32Int32R) fn(map[int32]float64(nil), (*Encoder).fastpathEncMapInt32Float64R, (*Decoder).fastpathDecMapInt32Float64R) fn(map[int32]bool(nil), (*Encoder).fastpathEncMapInt32BoolR, (*Decoder).fastpathDecMapInt32BoolR) sort.Sort(fastpathAslice{}) } // -- encode // -- -- fast path type switch func fastpathEncodeTypeSwitch(iv interface{}, e *Encoder) bool { switch v := iv.(type) { case []interface{}: fastpathTV.EncSliceIntfV(v, e) case *[]interface{}: if *v == nil { e.e.EncodeNil() } else { fastpathTV.EncSliceIntfV(*v, e) } case []string: fastpathTV.EncSliceStringV(v, e) case *[]string: if *v == nil { e.e.EncodeNil() } else { fastpathTV.EncSliceStringV(*v, e) } case [][]byte: fastpathTV.EncSliceBytesV(v, e) case *[][]byte: if *v == nil { e.e.EncodeNil() } else { fastpathTV.EncSliceBytesV(*v, e) } case []float32: fastpathTV.EncSliceFloat32V(v, e) case *[]float32: if *v == nil { e.e.EncodeNil() } else { fastpathTV.EncSliceFloat32V(*v, e) } case []float64: fastpathTV.EncSliceFloat64V(v, e) case *[]float64: if *v == nil { e.e.EncodeNil() } else { fastpathTV.EncSliceFloat64V(*v, e) } case []uint8: fastpathTV.EncSliceUint8V(v, e) case *[]uint8: if *v == nil { e.e.EncodeNil() } else { fastpathTV.EncSliceUint8V(*v, e) } case []uint64: fastpathTV.EncSliceUint64V(v, e) case *[]uint64: if *v == nil { e.e.EncodeNil() } else { fastpathTV.EncSliceUint64V(*v, e) } case []int: fastpathTV.EncSliceIntV(v, e) case *[]int: if *v == nil { e.e.EncodeNil() } else { fastpathTV.EncSliceIntV(*v, e) } case []int32: fastpathTV.EncSliceInt32V(v, e) case *[]int32: if *v == nil { e.e.EncodeNil() } else { fastpathTV.EncSliceInt32V(*v, e) } case []int64: fastpathTV.EncSliceInt64V(v, e) case *[]int64: if *v == nil { e.e.EncodeNil() } else { fastpathTV.EncSliceInt64V(*v, e) } case []bool: fastpathTV.EncSliceBoolV(v, e) case *[]bool: if *v == nil { e.e.EncodeNil() } else { fastpathTV.EncSliceBoolV(*v, e) } case map[string]interface{}: fastpathTV.EncMapStringIntfV(v, e) case *map[string]interface{}: if *v == nil { e.e.EncodeNil() } else { fastpathTV.EncMapStringIntfV(*v, e) } case map[string]string: fastpathTV.EncMapStringStringV(v, e) case *map[string]string: if *v == nil { e.e.EncodeNil() } else { fastpathTV.EncMapStringStringV(*v, e) } case map[string][]byte: fastpathTV.EncMapStringBytesV(v, e) case *map[string][]byte: if *v == nil { e.e.EncodeNil() } else { fastpathTV.EncMapStringBytesV(*v, e) } case map[string]uint8: fastpathTV.EncMapStringUint8V(v, e) case *map[string]uint8: if *v == nil { e.e.EncodeNil() } else { fastpathTV.EncMapStringUint8V(*v, e) } case map[string]uint64: fastpathTV.EncMapStringUint64V(v, e) case *map[string]uint64: if *v == nil { e.e.EncodeNil() } else { fastpathTV.EncMapStringUint64V(*v, e) } case map[string]int: fastpathTV.EncMapStringIntV(v, e) case *map[string]int: if *v == nil { e.e.EncodeNil() } else { fastpathTV.EncMapStringIntV(*v, e) } case map[string]int32: fastpathTV.EncMapStringInt32V(v, e) case *map[string]int32: if *v == nil { e.e.EncodeNil() } else { fastpathTV.EncMapStringInt32V(*v, e) } case map[string]float64: fastpathTV.EncMapStringFloat64V(v, e) case *map[string]float64: if *v == nil { e.e.EncodeNil() } else { fastpathTV.EncMapStringFloat64V(*v, e) } case map[string]bool: fastpathTV.EncMapStringBoolV(v, e) case *map[string]bool: if *v == nil { e.e.EncodeNil() } else { fastpathTV.EncMapStringBoolV(*v, e) } case map[uint8]interface{}: fastpathTV.EncMapUint8IntfV(v, e) case *map[uint8]interface{}: if *v == nil { e.e.EncodeNil() } else { fastpathTV.EncMapUint8IntfV(*v, e) } case map[uint8]string: fastpathTV.EncMapUint8StringV(v, e) case *map[uint8]string: if *v == nil { e.e.EncodeNil() } else { fastpathTV.EncMapUint8StringV(*v, e) } case map[uint8][]byte: fastpathTV.EncMapUint8BytesV(v, e) case *map[uint8][]byte: if *v == nil { e.e.EncodeNil() } else { fastpathTV.EncMapUint8BytesV(*v, e) } case map[uint8]uint8: fastpathTV.EncMapUint8Uint8V(v, e) case *map[uint8]uint8: if *v == nil { e.e.EncodeNil() } else { fastpathTV.EncMapUint8Uint8V(*v, e) } case map[uint8]uint64: fastpathTV.EncMapUint8Uint64V(v, e) case *map[uint8]uint64: if *v == nil { e.e.EncodeNil() } else { fastpathTV.EncMapUint8Uint64V(*v, e) } case map[uint8]int: fastpathTV.EncMapUint8IntV(v, e) case *map[uint8]int: if *v == nil { e.e.EncodeNil() } else { fastpathTV.EncMapUint8IntV(*v, e) } case map[uint8]int32: fastpathTV.EncMapUint8Int32V(v, e) case *map[uint8]int32: if *v == nil { e.e.EncodeNil() } else { fastpathTV.EncMapUint8Int32V(*v, e) } case map[uint8]float64: fastpathTV.EncMapUint8Float64V(v, e) case *map[uint8]float64: if *v == nil { e.e.EncodeNil() } else { fastpathTV.EncMapUint8Float64V(*v, e) } case map[uint8]bool: fastpathTV.EncMapUint8BoolV(v, e) case *map[uint8]bool: if *v == nil { e.e.EncodeNil() } else { fastpathTV.EncMapUint8BoolV(*v, e) } case map[uint64]interface{}: fastpathTV.EncMapUint64IntfV(v, e) case *map[uint64]interface{}: if *v == nil { e.e.EncodeNil() } else { fastpathTV.EncMapUint64IntfV(*v, e) } case map[uint64]string: fastpathTV.EncMapUint64StringV(v, e) case *map[uint64]string: if *v == nil { e.e.EncodeNil() } else { fastpathTV.EncMapUint64StringV(*v, e) } case map[uint64][]byte: fastpathTV.EncMapUint64BytesV(v, e) case *map[uint64][]byte: if *v == nil { e.e.EncodeNil() } else { fastpathTV.EncMapUint64BytesV(*v, e) } case map[uint64]uint8: fastpathTV.EncMapUint64Uint8V(v, e) case *map[uint64]uint8: if *v == nil { e.e.EncodeNil() } else { fastpathTV.EncMapUint64Uint8V(*v, e) } case map[uint64]uint64: fastpathTV.EncMapUint64Uint64V(v, e) case *map[uint64]uint64: if *v == nil { e.e.EncodeNil() } else { fastpathTV.EncMapUint64Uint64V(*v, e) } case map[uint64]int: fastpathTV.EncMapUint64IntV(v, e) case *map[uint64]int: if *v == nil { e.e.EncodeNil() } else { fastpathTV.EncMapUint64IntV(*v, e) } case map[uint64]int32: fastpathTV.EncMapUint64Int32V(v, e) case *map[uint64]int32: if *v == nil { e.e.EncodeNil() } else { fastpathTV.EncMapUint64Int32V(*v, e) } case map[uint64]float64: fastpathTV.EncMapUint64Float64V(v, e) case *map[uint64]float64: if *v == nil { e.e.EncodeNil() } else { fastpathTV.EncMapUint64Float64V(*v, e) } case map[uint64]bool: fastpathTV.EncMapUint64BoolV(v, e) case *map[uint64]bool: if *v == nil { e.e.EncodeNil() } else { fastpathTV.EncMapUint64BoolV(*v, e) } case map[int]interface{}: fastpathTV.EncMapIntIntfV(v, e) case *map[int]interface{}: if *v == nil { e.e.EncodeNil() } else { fastpathTV.EncMapIntIntfV(*v, e) } case map[int]string: fastpathTV.EncMapIntStringV(v, e) case *map[int]string: if *v == nil { e.e.EncodeNil() } else { fastpathTV.EncMapIntStringV(*v, e) } case map[int][]byte: fastpathTV.EncMapIntBytesV(v, e) case *map[int][]byte: if *v == nil { e.e.EncodeNil() } else { fastpathTV.EncMapIntBytesV(*v, e) } case map[int]uint8: fastpathTV.EncMapIntUint8V(v, e) case *map[int]uint8: if *v == nil { e.e.EncodeNil() } else { fastpathTV.EncMapIntUint8V(*v, e) } case map[int]uint64: fastpathTV.EncMapIntUint64V(v, e) case *map[int]uint64: if *v == nil { e.e.EncodeNil() } else { fastpathTV.EncMapIntUint64V(*v, e) } case map[int]int: fastpathTV.EncMapIntIntV(v, e) case *map[int]int: if *v == nil { e.e.EncodeNil() } else { fastpathTV.EncMapIntIntV(*v, e) } case map[int]int32: fastpathTV.EncMapIntInt32V(v, e) case *map[int]int32: if *v == nil { e.e.EncodeNil() } else { fastpathTV.EncMapIntInt32V(*v, e) } case map[int]float64: fastpathTV.EncMapIntFloat64V(v, e) case *map[int]float64: if *v == nil { e.e.EncodeNil() } else { fastpathTV.EncMapIntFloat64V(*v, e) } case map[int]bool: fastpathTV.EncMapIntBoolV(v, e) case *map[int]bool: if *v == nil { e.e.EncodeNil() } else { fastpathTV.EncMapIntBoolV(*v, e) } case map[int32]interface{}: fastpathTV.EncMapInt32IntfV(v, e) case *map[int32]interface{}: if *v == nil { e.e.EncodeNil() } else { fastpathTV.EncMapInt32IntfV(*v, e) } case map[int32]string: fastpathTV.EncMapInt32StringV(v, e) case *map[int32]string: if *v == nil { e.e.EncodeNil() } else { fastpathTV.EncMapInt32StringV(*v, e) } case map[int32][]byte: fastpathTV.EncMapInt32BytesV(v, e) case *map[int32][]byte: if *v == nil { e.e.EncodeNil() } else { fastpathTV.EncMapInt32BytesV(*v, e) } case map[int32]uint8: fastpathTV.EncMapInt32Uint8V(v, e) case *map[int32]uint8: if *v == nil { e.e.EncodeNil() } else { fastpathTV.EncMapInt32Uint8V(*v, e) } case map[int32]uint64: fastpathTV.EncMapInt32Uint64V(v, e) case *map[int32]uint64: if *v == nil { e.e.EncodeNil() } else { fastpathTV.EncMapInt32Uint64V(*v, e) } case map[int32]int: fastpathTV.EncMapInt32IntV(v, e) case *map[int32]int: if *v == nil { e.e.EncodeNil() } else { fastpathTV.EncMapInt32IntV(*v, e) } case map[int32]int32: fastpathTV.EncMapInt32Int32V(v, e) case *map[int32]int32: if *v == nil { e.e.EncodeNil() } else { fastpathTV.EncMapInt32Int32V(*v, e) } case map[int32]float64: fastpathTV.EncMapInt32Float64V(v, e) case *map[int32]float64: if *v == nil { e.e.EncodeNil() } else { fastpathTV.EncMapInt32Float64V(*v, e) } case map[int32]bool: fastpathTV.EncMapInt32BoolV(v, e) case *map[int32]bool: if *v == nil { e.e.EncodeNil() } else { fastpathTV.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) fastpathEncSliceIntfR(f *codecFnInfo, rv reflect.Value) { var v []interface{} if rv.Kind() == reflect.Array { rvGetSlice4Array(rv, &v) } else { v = rv2i(rv).([]interface{}) } if f.ti.mbs { fastpathTV.EncAsMapSliceIntfV(v, e) } else { fastpathTV.EncSliceIntfV(v, e) } } func (fastpathT) EncSliceIntfV(v []interface{}, e *Encoder) { e.arrayStart(len(v)) for j := range v { e.arrayElem() e.encode(v[j]) } e.arrayEnd() } func (fastpathT) EncAsMapSliceIntfV(v []interface{}, e *Encoder) { 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.mapElemKey() } else { e.mapElemValue() } e.encode(v[j]) } e.mapEnd() } func (e *Encoder) fastpathEncSliceStringR(f *codecFnInfo, rv reflect.Value) { var v []string if rv.Kind() == reflect.Array { rvGetSlice4Array(rv, &v) } else { v = rv2i(rv).([]string) } if f.ti.mbs { fastpathTV.EncAsMapSliceStringV(v, e) } else { fastpathTV.EncSliceStringV(v, e) } } func (fastpathT) EncSliceStringV(v []string, e *Encoder) { e.arrayStart(len(v)) for j := range v { e.arrayElem() e.e.EncodeString(v[j]) } e.arrayEnd() } func (fastpathT) EncAsMapSliceStringV(v []string, e *Encoder) { 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.mapElemKey() } else { e.mapElemValue() } e.e.EncodeString(v[j]) } e.mapEnd() } func (e *Encoder) fastpathEncSliceBytesR(f *codecFnInfo, rv reflect.Value) { var v [][]byte if rv.Kind() == reflect.Array { rvGetSlice4Array(rv, &v) } else { v = rv2i(rv).([][]byte) } if f.ti.mbs { fastpathTV.EncAsMapSliceBytesV(v, e) } else { fastpathTV.EncSliceBytesV(v, e) } } func (fastpathT) EncSliceBytesV(v [][]byte, e *Encoder) { e.arrayStart(len(v)) for j := range v { e.arrayElem() e.e.EncodeStringBytesRaw(v[j]) } e.arrayEnd() } func (fastpathT) EncAsMapSliceBytesV(v [][]byte, e *Encoder) { 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.mapElemKey() } else { e.mapElemValue() } e.e.EncodeStringBytesRaw(v[j]) } e.mapEnd() } func (e *Encoder) fastpathEncSliceFloat32R(f *codecFnInfo, rv reflect.Value) { var v []float32 if rv.Kind() == reflect.Array { rvGetSlice4Array(rv, &v) } else { v = rv2i(rv).([]float32) } if f.ti.mbs { fastpathTV.EncAsMapSliceFloat32V(v, e) } else { fastpathTV.EncSliceFloat32V(v, e) } } func (fastpathT) EncSliceFloat32V(v []float32, e *Encoder) { e.arrayStart(len(v)) for j := range v { e.arrayElem() e.e.EncodeFloat32(v[j]) } e.arrayEnd() } func (fastpathT) EncAsMapSliceFloat32V(v []float32, e *Encoder) { 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.mapElemKey() } else { e.mapElemValue() } e.e.EncodeFloat32(v[j]) } e.mapEnd() } func (e *Encoder) fastpathEncSliceFloat64R(f *codecFnInfo, rv reflect.Value) { var v []float64 if rv.Kind() == reflect.Array { rvGetSlice4Array(rv, &v) } else { v = rv2i(rv).([]float64) } if f.ti.mbs { fastpathTV.EncAsMapSliceFloat64V(v, e) } else { fastpathTV.EncSliceFloat64V(v, e) } } func (fastpathT) EncSliceFloat64V(v []float64, e *Encoder) { e.arrayStart(len(v)) for j := range v { e.arrayElem() e.e.EncodeFloat64(v[j]) } e.arrayEnd() } func (fastpathT) EncAsMapSliceFloat64V(v []float64, e *Encoder) { 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.mapElemKey() } else { e.mapElemValue() } e.e.EncodeFloat64(v[j]) } e.mapEnd() } func (e *Encoder) fastpathEncSliceUint8R(f *codecFnInfo, rv reflect.Value) { var v []uint8 if rv.Kind() == reflect.Array { rvGetSlice4Array(rv, &v) } else { v = rv2i(rv).([]uint8) } if f.ti.mbs { fastpathTV.EncAsMapSliceUint8V(v, e) } else { fastpathTV.EncSliceUint8V(v, e) } } func (fastpathT) EncSliceUint8V(v []uint8, e *Encoder) { e.e.EncodeStringBytesRaw(v) } func (fastpathT) EncAsMapSliceUint8V(v []uint8, e *Encoder) { 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.mapElemKey() } else { e.mapElemValue() } e.e.EncodeUint(uint64(v[j])) } e.mapEnd() } func (e *Encoder) fastpathEncSliceUint64R(f *codecFnInfo, rv reflect.Value) { var v []uint64 if rv.Kind() == reflect.Array { rvGetSlice4Array(rv, &v) } else { v = rv2i(rv).([]uint64) } if f.ti.mbs { fastpathTV.EncAsMapSliceUint64V(v, e) } else { fastpathTV.EncSliceUint64V(v, e) } } func (fastpathT) EncSliceUint64V(v []uint64, e *Encoder) { e.arrayStart(len(v)) for j := range v { e.arrayElem() e.e.EncodeUint(v[j]) } e.arrayEnd() } func (fastpathT) EncAsMapSliceUint64V(v []uint64, e *Encoder) { 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.mapElemKey() } else { e.mapElemValue() } e.e.EncodeUint(v[j]) } e.mapEnd() } func (e *Encoder) fastpathEncSliceIntR(f *codecFnInfo, rv reflect.Value) { var v []int if rv.Kind() == reflect.Array { rvGetSlice4Array(rv, &v) } else { v = rv2i(rv).([]int) } if f.ti.mbs { fastpathTV.EncAsMapSliceIntV(v, e) } else { fastpathTV.EncSliceIntV(v, e) } } func (fastpathT) EncSliceIntV(v []int, e *Encoder) { e.arrayStart(len(v)) for j := range v { e.arrayElem() e.e.EncodeInt(int64(v[j])) } e.arrayEnd() } func (fastpathT) EncAsMapSliceIntV(v []int, e *Encoder) { 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.mapElemKey() } else { e.mapElemValue() } e.e.EncodeInt(int64(v[j])) } e.mapEnd() } func (e *Encoder) fastpathEncSliceInt32R(f *codecFnInfo, rv reflect.Value) { var v []int32 if rv.Kind() == reflect.Array { rvGetSlice4Array(rv, &v) } else { v = rv2i(rv).([]int32) } if f.ti.mbs { fastpathTV.EncAsMapSliceInt32V(v, e) } else { fastpathTV.EncSliceInt32V(v, e) } } func (fastpathT) EncSliceInt32V(v []int32, e *Encoder) { e.arrayStart(len(v)) for j := range v { e.arrayElem() e.e.EncodeInt(int64(v[j])) } e.arrayEnd() } func (fastpathT) EncAsMapSliceInt32V(v []int32, e *Encoder) { 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.mapElemKey() } else { e.mapElemValue() } e.e.EncodeInt(int64(v[j])) } e.mapEnd() } func (e *Encoder) fastpathEncSliceInt64R(f *codecFnInfo, rv reflect.Value) { var v []int64 if rv.Kind() == reflect.Array { rvGetSlice4Array(rv, &v) } else { v = rv2i(rv).([]int64) } if f.ti.mbs { fastpathTV.EncAsMapSliceInt64V(v, e) } else { fastpathTV.EncSliceInt64V(v, e) } } func (fastpathT) EncSliceInt64V(v []int64, e *Encoder) { e.arrayStart(len(v)) for j := range v { e.arrayElem() e.e.EncodeInt(v[j]) } e.arrayEnd() } func (fastpathT) EncAsMapSliceInt64V(v []int64, e *Encoder) { 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.mapElemKey() } else { e.mapElemValue() } e.e.EncodeInt(v[j]) } e.mapEnd() } func (e *Encoder) fastpathEncSliceBoolR(f *codecFnInfo, rv reflect.Value) { var v []bool if rv.Kind() == reflect.Array { rvGetSlice4Array(rv, &v) } else { v = rv2i(rv).([]bool) } if f.ti.mbs { fastpathTV.EncAsMapSliceBoolV(v, e) } else { fastpathTV.EncSliceBoolV(v, e) } } func (fastpathT) EncSliceBoolV(v []bool, e *Encoder) { e.arrayStart(len(v)) for j := range v { e.arrayElem() e.e.EncodeBool(v[j]) } e.arrayEnd() } func (fastpathT) EncAsMapSliceBoolV(v []bool, e *Encoder) { 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.mapElemKey() } else { e.mapElemValue() } e.e.EncodeBool(v[j]) } e.mapEnd() } func (e *Encoder) fastpathEncMapStringIntfR(f *codecFnInfo, rv reflect.Value) { fastpathTV.EncMapStringIntfV(rv2i(rv).(map[string]interface{}), e) } func (fastpathT) EncMapStringIntfV(v map[string]interface{}, e *Encoder) { e.mapStart(len(v)) if e.h.Canonical { v2 := make([]string, len(v)) var i uint for k := range v { v2[i] = k i++ } sort.Sort(stringSlice(v2)) for _, k2 := range v2 { e.mapElemKey() e.e.EncodeString(k2) e.mapElemValue() e.encode(v[k2]) } } else { for k2, v2 := range v { e.mapElemKey() e.e.EncodeString(k2) e.mapElemValue() e.encode(v2) } } e.mapEnd() } func (e *Encoder) fastpathEncMapStringStringR(f *codecFnInfo, rv reflect.Value) { fastpathTV.EncMapStringStringV(rv2i(rv).(map[string]string), e) } func (fastpathT) EncMapStringStringV(v map[string]string, e *Encoder) { e.mapStart(len(v)) if e.h.Canonical { v2 := make([]string, len(v)) var i uint for k := range v { v2[i] = k i++ } sort.Sort(stringSlice(v2)) for _, k2 := range v2 { e.mapElemKey() e.e.EncodeString(k2) e.mapElemValue() e.e.EncodeString(v[k2]) } } else { for k2, v2 := range v { e.mapElemKey() e.e.EncodeString(k2) e.mapElemValue() e.e.EncodeString(v2) } } e.mapEnd() } func (e *Encoder) fastpathEncMapStringBytesR(f *codecFnInfo, rv reflect.Value) { fastpathTV.EncMapStringBytesV(rv2i(rv).(map[string][]byte), e) } func (fastpathT) EncMapStringBytesV(v map[string][]byte, e *Encoder) { e.mapStart(len(v)) if e.h.Canonical { v2 := make([]string, len(v)) var i uint for k := range v { v2[i] = k i++ } sort.Sort(stringSlice(v2)) for _, k2 := range v2 { e.mapElemKey() e.e.EncodeString(k2) e.mapElemValue() e.e.EncodeStringBytesRaw(v[k2]) } } else { for k2, v2 := range v { e.mapElemKey() e.e.EncodeString(k2) e.mapElemValue() e.e.EncodeStringBytesRaw(v2) } } e.mapEnd() } func (e *Encoder) fastpathEncMapStringUint8R(f *codecFnInfo, rv reflect.Value) { fastpathTV.EncMapStringUint8V(rv2i(rv).(map[string]uint8), e) } func (fastpathT) EncMapStringUint8V(v map[string]uint8, e *Encoder) { e.mapStart(len(v)) if e.h.Canonical { v2 := make([]string, len(v)) var i uint for k := range v { v2[i] = k i++ } sort.Sort(stringSlice(v2)) for _, k2 := range v2 { e.mapElemKey() e.e.EncodeString(k2) e.mapElemValue() e.e.EncodeUint(uint64(v[k2])) } } else { for k2, v2 := range v { e.mapElemKey() e.e.EncodeString(k2) e.mapElemValue() e.e.EncodeUint(uint64(v2)) } } e.mapEnd() } func (e *Encoder) fastpathEncMapStringUint64R(f *codecFnInfo, rv reflect.Value) { fastpathTV.EncMapStringUint64V(rv2i(rv).(map[string]uint64), e) } func (fastpathT) EncMapStringUint64V(v map[string]uint64, e *Encoder) { e.mapStart(len(v)) if e.h.Canonical { v2 := make([]string, len(v)) var i uint for k := range v { v2[i] = k i++ } sort.Sort(stringSlice(v2)) for _, k2 := range v2 { e.mapElemKey() e.e.EncodeString(k2) e.mapElemValue() e.e.EncodeUint(v[k2]) } } else { for k2, v2 := range v { e.mapElemKey() e.e.EncodeString(k2) e.mapElemValue() e.e.EncodeUint(v2) } } e.mapEnd() } func (e *Encoder) fastpathEncMapStringIntR(f *codecFnInfo, rv reflect.Value) { fastpathTV.EncMapStringIntV(rv2i(rv).(map[string]int), e) } func (fastpathT) EncMapStringIntV(v map[string]int, e *Encoder) { e.mapStart(len(v)) if e.h.Canonical { v2 := make([]string, len(v)) var i uint for k := range v { v2[i] = k i++ } sort.Sort(stringSlice(v2)) for _, k2 := range v2 { e.mapElemKey() e.e.EncodeString(k2) e.mapElemValue() e.e.EncodeInt(int64(v[k2])) } } else { for k2, v2 := range v { e.mapElemKey() e.e.EncodeString(k2) e.mapElemValue() e.e.EncodeInt(int64(v2)) } } e.mapEnd() } func (e *Encoder) fastpathEncMapStringInt32R(f *codecFnInfo, rv reflect.Value) { fastpathTV.EncMapStringInt32V(rv2i(rv).(map[string]int32), e) } func (fastpathT) EncMapStringInt32V(v map[string]int32, e *Encoder) { e.mapStart(len(v)) if e.h.Canonical { v2 := make([]string, len(v)) var i uint for k := range v { v2[i] = k i++ } sort.Sort(stringSlice(v2)) for _, k2 := range v2 { e.mapElemKey() e.e.EncodeString(k2) e.mapElemValue() e.e.EncodeInt(int64(v[k2])) } } else { for k2, v2 := range v { e.mapElemKey() e.e.EncodeString(k2) e.mapElemValue() e.e.EncodeInt(int64(v2)) } } e.mapEnd() } func (e *Encoder) fastpathEncMapStringFloat64R(f *codecFnInfo, rv reflect.Value) { fastpathTV.EncMapStringFloat64V(rv2i(rv).(map[string]float64), e) } func (fastpathT) EncMapStringFloat64V(v map[string]float64, e *Encoder) { e.mapStart(len(v)) if e.h.Canonical { v2 := make([]string, len(v)) var i uint for k := range v { v2[i] = k i++ } sort.Sort(stringSlice(v2)) for _, k2 := range v2 { e.mapElemKey() e.e.EncodeString(k2) e.mapElemValue() e.e.EncodeFloat64(v[k2]) } } else { for k2, v2 := range v { e.mapElemKey() e.e.EncodeString(k2) e.mapElemValue() e.e.EncodeFloat64(v2) } } e.mapEnd() } func (e *Encoder) fastpathEncMapStringBoolR(f *codecFnInfo, rv reflect.Value) { fastpathTV.EncMapStringBoolV(rv2i(rv).(map[string]bool), e) } func (fastpathT) EncMapStringBoolV(v map[string]bool, e *Encoder) { e.mapStart(len(v)) if e.h.Canonical { v2 := make([]string, len(v)) var i uint for k := range v { v2[i] = k i++ } sort.Sort(stringSlice(v2)) for _, k2 := range v2 { e.mapElemKey() e.e.EncodeString(k2) e.mapElemValue() e.e.EncodeBool(v[k2]) } } else { for k2, v2 := range v { e.mapElemKey() e.e.EncodeString(k2) e.mapElemValue() e.e.EncodeBool(v2) } } e.mapEnd() } func (e *Encoder) fastpathEncMapUint8IntfR(f *codecFnInfo, rv reflect.Value) { fastpathTV.EncMapUint8IntfV(rv2i(rv).(map[uint8]interface{}), e) } func (fastpathT) EncMapUint8IntfV(v map[uint8]interface{}, e *Encoder) { e.mapStart(len(v)) if e.h.Canonical { v2 := make([]uint8, len(v)) var i uint for k := range v { v2[i] = k i++ } sort.Sort(uint8Slice(v2)) for _, k2 := range v2 { e.mapElemKey() e.e.EncodeUint(uint64(k2)) e.mapElemValue() e.encode(v[k2]) } } else { for k2, v2 := range v { e.mapElemKey() e.e.EncodeUint(uint64(k2)) e.mapElemValue() e.encode(v2) } } e.mapEnd() } func (e *Encoder) fastpathEncMapUint8StringR(f *codecFnInfo, rv reflect.Value) { fastpathTV.EncMapUint8StringV(rv2i(rv).(map[uint8]string), e) } func (fastpathT) EncMapUint8StringV(v map[uint8]string, e *Encoder) { e.mapStart(len(v)) if e.h.Canonical { v2 := make([]uint8, len(v)) var i uint for k := range v { v2[i] = k i++ } sort.Sort(uint8Slice(v2)) for _, k2 := range v2 { e.mapElemKey() e.e.EncodeUint(uint64(k2)) e.mapElemValue() e.e.EncodeString(v[k2]) } } else { for k2, v2 := range v { e.mapElemKey() e.e.EncodeUint(uint64(k2)) e.mapElemValue() e.e.EncodeString(v2) } } e.mapEnd() } func (e *Encoder) fastpathEncMapUint8BytesR(f *codecFnInfo, rv reflect.Value) { fastpathTV.EncMapUint8BytesV(rv2i(rv).(map[uint8][]byte), e) } func (fastpathT) EncMapUint8BytesV(v map[uint8][]byte, e *Encoder) { e.mapStart(len(v)) if e.h.Canonical { v2 := make([]uint8, len(v)) var i uint for k := range v { v2[i] = k i++ } sort.Sort(uint8Slice(v2)) for _, k2 := range v2 { e.mapElemKey() e.e.EncodeUint(uint64(k2)) e.mapElemValue() e.e.EncodeStringBytesRaw(v[k2]) } } else { for k2, v2 := range v { e.mapElemKey() e.e.EncodeUint(uint64(k2)) e.mapElemValue() e.e.EncodeStringBytesRaw(v2) } } e.mapEnd() } func (e *Encoder) fastpathEncMapUint8Uint8R(f *codecFnInfo, rv reflect.Value) { fastpathTV.EncMapUint8Uint8V(rv2i(rv).(map[uint8]uint8), e) } func (fastpathT) EncMapUint8Uint8V(v map[uint8]uint8, e *Encoder) { e.mapStart(len(v)) if e.h.Canonical { v2 := make([]uint8, len(v)) var i uint for k := range v { v2[i] = k i++ } sort.Sort(uint8Slice(v2)) for _, k2 := range v2 { e.mapElemKey() e.e.EncodeUint(uint64(k2)) e.mapElemValue() e.e.EncodeUint(uint64(v[k2])) } } else { for k2, v2 := range v { e.mapElemKey() e.e.EncodeUint(uint64(k2)) e.mapElemValue() e.e.EncodeUint(uint64(v2)) } } e.mapEnd() } func (e *Encoder) fastpathEncMapUint8Uint64R(f *codecFnInfo, rv reflect.Value) { fastpathTV.EncMapUint8Uint64V(rv2i(rv).(map[uint8]uint64), e) } func (fastpathT) EncMapUint8Uint64V(v map[uint8]uint64, e *Encoder) { e.mapStart(len(v)) if e.h.Canonical { v2 := make([]uint8, len(v)) var i uint for k := range v { v2[i] = k i++ } sort.Sort(uint8Slice(v2)) for _, k2 := range v2 { e.mapElemKey() e.e.EncodeUint(uint64(k2)) e.mapElemValue() e.e.EncodeUint(v[k2]) } } else { for k2, v2 := range v { e.mapElemKey() e.e.EncodeUint(uint64(k2)) e.mapElemValue() e.e.EncodeUint(v2) } } e.mapEnd() } func (e *Encoder) fastpathEncMapUint8IntR(f *codecFnInfo, rv reflect.Value) { fastpathTV.EncMapUint8IntV(rv2i(rv).(map[uint8]int), e) } func (fastpathT) EncMapUint8IntV(v map[uint8]int, e *Encoder) { e.mapStart(len(v)) if e.h.Canonical { v2 := make([]uint8, len(v)) var i uint for k := range v { v2[i] = k i++ } sort.Sort(uint8Slice(v2)) for _, k2 := range v2 { e.mapElemKey() e.e.EncodeUint(uint64(k2)) e.mapElemValue() e.e.EncodeInt(int64(v[k2])) } } else { for k2, v2 := range v { e.mapElemKey() e.e.EncodeUint(uint64(k2)) e.mapElemValue() e.e.EncodeInt(int64(v2)) } } e.mapEnd() } func (e *Encoder) fastpathEncMapUint8Int32R(f *codecFnInfo, rv reflect.Value) { fastpathTV.EncMapUint8Int32V(rv2i(rv).(map[uint8]int32), e) } func (fastpathT) EncMapUint8Int32V(v map[uint8]int32, e *Encoder) { e.mapStart(len(v)) if e.h.Canonical { v2 := make([]uint8, len(v)) var i uint for k := range v { v2[i] = k i++ } sort.Sort(uint8Slice(v2)) for _, k2 := range v2 { e.mapElemKey() e.e.EncodeUint(uint64(k2)) e.mapElemValue() e.e.EncodeInt(int64(v[k2])) } } else { for k2, v2 := range v { e.mapElemKey() e.e.EncodeUint(uint64(k2)) e.mapElemValue() e.e.EncodeInt(int64(v2)) } } e.mapEnd() } func (e *Encoder) fastpathEncMapUint8Float64R(f *codecFnInfo, rv reflect.Value) { fastpathTV.EncMapUint8Float64V(rv2i(rv).(map[uint8]float64), e) } func (fastpathT) EncMapUint8Float64V(v map[uint8]float64, e *Encoder) { e.mapStart(len(v)) if e.h.Canonical { v2 := make([]uint8, len(v)) var i uint for k := range v { v2[i] = k i++ } sort.Sort(uint8Slice(v2)) for _, k2 := range v2 { e.mapElemKey() e.e.EncodeUint(uint64(k2)) e.mapElemValue() e.e.EncodeFloat64(v[k2]) } } else { for k2, v2 := range v { e.mapElemKey() e.e.EncodeUint(uint64(k2)) e.mapElemValue() e.e.EncodeFloat64(v2) } } e.mapEnd() } func (e *Encoder) fastpathEncMapUint8BoolR(f *codecFnInfo, rv reflect.Value) { fastpathTV.EncMapUint8BoolV(rv2i(rv).(map[uint8]bool), e) } func (fastpathT) EncMapUint8BoolV(v map[uint8]bool, e *Encoder) { e.mapStart(len(v)) if e.h.Canonical { v2 := make([]uint8, len(v)) var i uint for k := range v { v2[i] = k i++ } sort.Sort(uint8Slice(v2)) for _, k2 := range v2 { e.mapElemKey() e.e.EncodeUint(uint64(k2)) e.mapElemValue() e.e.EncodeBool(v[k2]) } } else { for k2, v2 := range v { e.mapElemKey() e.e.EncodeUint(uint64(k2)) e.mapElemValue() e.e.EncodeBool(v2) } } e.mapEnd() } func (e *Encoder) fastpathEncMapUint64IntfR(f *codecFnInfo, rv reflect.Value) { fastpathTV.EncMapUint64IntfV(rv2i(rv).(map[uint64]interface{}), e) } func (fastpathT) EncMapUint64IntfV(v map[uint64]interface{}, e *Encoder) { e.mapStart(len(v)) if e.h.Canonical { v2 := make([]uint64, len(v)) var i uint for k := range v { v2[i] = k i++ } sort.Sort(uint64Slice(v2)) for _, k2 := range v2 { e.mapElemKey() e.e.EncodeUint(k2) e.mapElemValue() e.encode(v[k2]) } } else { for k2, v2 := range v { e.mapElemKey() e.e.EncodeUint(k2) e.mapElemValue() e.encode(v2) } } e.mapEnd() } func (e *Encoder) fastpathEncMapUint64StringR(f *codecFnInfo, rv reflect.Value) { fastpathTV.EncMapUint64StringV(rv2i(rv).(map[uint64]string), e) } func (fastpathT) EncMapUint64StringV(v map[uint64]string, e *Encoder) { e.mapStart(len(v)) if e.h.Canonical { v2 := make([]uint64, len(v)) var i uint for k := range v { v2[i] = k i++ } sort.Sort(uint64Slice(v2)) for _, k2 := range v2 { e.mapElemKey() e.e.EncodeUint(k2) e.mapElemValue() e.e.EncodeString(v[k2]) } } else { for k2, v2 := range v { e.mapElemKey() e.e.EncodeUint(k2) e.mapElemValue() e.e.EncodeString(v2) } } e.mapEnd() } func (e *Encoder) fastpathEncMapUint64BytesR(f *codecFnInfo, rv reflect.Value) { fastpathTV.EncMapUint64BytesV(rv2i(rv).(map[uint64][]byte), e) } func (fastpathT) EncMapUint64BytesV(v map[uint64][]byte, e *Encoder) { e.mapStart(len(v)) if e.h.Canonical { v2 := make([]uint64, len(v)) var i uint for k := range v { v2[i] = k i++ } sort.Sort(uint64Slice(v2)) for _, k2 := range v2 { e.mapElemKey() e.e.EncodeUint(k2) e.mapElemValue() e.e.EncodeStringBytesRaw(v[k2]) } } else { for k2, v2 := range v { e.mapElemKey() e.e.EncodeUint(k2) e.mapElemValue() e.e.EncodeStringBytesRaw(v2) } } e.mapEnd() } func (e *Encoder) fastpathEncMapUint64Uint8R(f *codecFnInfo, rv reflect.Value) { fastpathTV.EncMapUint64Uint8V(rv2i(rv).(map[uint64]uint8), e) } func (fastpathT) EncMapUint64Uint8V(v map[uint64]uint8, e *Encoder) { e.mapStart(len(v)) if e.h.Canonical { v2 := make([]uint64, len(v)) var i uint for k := range v { v2[i] = k i++ } sort.Sort(uint64Slice(v2)) for _, k2 := range v2 { e.mapElemKey() e.e.EncodeUint(k2) e.mapElemValue() e.e.EncodeUint(uint64(v[k2])) } } else { for k2, v2 := range v { e.mapElemKey() e.e.EncodeUint(k2) e.mapElemValue() e.e.EncodeUint(uint64(v2)) } } e.mapEnd() } func (e *Encoder) fastpathEncMapUint64Uint64R(f *codecFnInfo, rv reflect.Value) { fastpathTV.EncMapUint64Uint64V(rv2i(rv).(map[uint64]uint64), e) } func (fastpathT) EncMapUint64Uint64V(v map[uint64]uint64, e *Encoder) { e.mapStart(len(v)) if e.h.Canonical { v2 := make([]uint64, len(v)) var i uint for k := range v { v2[i] = k i++ } sort.Sort(uint64Slice(v2)) for _, k2 := range v2 { e.mapElemKey() e.e.EncodeUint(k2) e.mapElemValue() e.e.EncodeUint(v[k2]) } } else { for k2, v2 := range v { e.mapElemKey() e.e.EncodeUint(k2) e.mapElemValue() e.e.EncodeUint(v2) } } e.mapEnd() } func (e *Encoder) fastpathEncMapUint64IntR(f *codecFnInfo, rv reflect.Value) { fastpathTV.EncMapUint64IntV(rv2i(rv).(map[uint64]int), e) } func (fastpathT) EncMapUint64IntV(v map[uint64]int, e *Encoder) { e.mapStart(len(v)) if e.h.Canonical { v2 := make([]uint64, len(v)) var i uint for k := range v { v2[i] = k i++ } sort.Sort(uint64Slice(v2)) for _, k2 := range v2 { e.mapElemKey() e.e.EncodeUint(k2) e.mapElemValue() e.e.EncodeInt(int64(v[k2])) } } else { for k2, v2 := range v { e.mapElemKey() e.e.EncodeUint(k2) e.mapElemValue() e.e.EncodeInt(int64(v2)) } } e.mapEnd() } func (e *Encoder) fastpathEncMapUint64Int32R(f *codecFnInfo, rv reflect.Value) { fastpathTV.EncMapUint64Int32V(rv2i(rv).(map[uint64]int32), e) } func (fastpathT) EncMapUint64Int32V(v map[uint64]int32, e *Encoder) { e.mapStart(len(v)) if e.h.Canonical { v2 := make([]uint64, len(v)) var i uint for k := range v { v2[i] = k i++ } sort.Sort(uint64Slice(v2)) for _, k2 := range v2 { e.mapElemKey() e.e.EncodeUint(k2) e.mapElemValue() e.e.EncodeInt(int64(v[k2])) } } else { for k2, v2 := range v { e.mapElemKey() e.e.EncodeUint(k2) e.mapElemValue() e.e.EncodeInt(int64(v2)) } } e.mapEnd() } func (e *Encoder) fastpathEncMapUint64Float64R(f *codecFnInfo, rv reflect.Value) { fastpathTV.EncMapUint64Float64V(rv2i(rv).(map[uint64]float64), e) } func (fastpathT) EncMapUint64Float64V(v map[uint64]float64, e *Encoder) { e.mapStart(len(v)) if e.h.Canonical { v2 := make([]uint64, len(v)) var i uint for k := range v { v2[i] = k i++ } sort.Sort(uint64Slice(v2)) for _, k2 := range v2 { e.mapElemKey() e.e.EncodeUint(k2) e.mapElemValue() e.e.EncodeFloat64(v[k2]) } } else { for k2, v2 := range v { e.mapElemKey() e.e.EncodeUint(k2) e.mapElemValue() e.e.EncodeFloat64(v2) } } e.mapEnd() } func (e *Encoder) fastpathEncMapUint64BoolR(f *codecFnInfo, rv reflect.Value) { fastpathTV.EncMapUint64BoolV(rv2i(rv).(map[uint64]bool), e) } func (fastpathT) EncMapUint64BoolV(v map[uint64]bool, e *Encoder) { e.mapStart(len(v)) if e.h.Canonical { v2 := make([]uint64, len(v)) var i uint for k := range v { v2[i] = k i++ } sort.Sort(uint64Slice(v2)) for _, k2 := range v2 { e.mapElemKey() e.e.EncodeUint(k2) e.mapElemValue() e.e.EncodeBool(v[k2]) } } else { for k2, v2 := range v { e.mapElemKey() e.e.EncodeUint(k2) e.mapElemValue() e.e.EncodeBool(v2) } } e.mapEnd() } func (e *Encoder) fastpathEncMapIntIntfR(f *codecFnInfo, rv reflect.Value) { fastpathTV.EncMapIntIntfV(rv2i(rv).(map[int]interface{}), e) } func (fastpathT) EncMapIntIntfV(v map[int]interface{}, e *Encoder) { e.mapStart(len(v)) if e.h.Canonical { v2 := make([]int, len(v)) var i uint for k := range v { v2[i] = k i++ } sort.Sort(intSlice(v2)) for _, k2 := range v2 { e.mapElemKey() e.e.EncodeInt(int64(k2)) e.mapElemValue() e.encode(v[k2]) } } else { for k2, v2 := range v { e.mapElemKey() e.e.EncodeInt(int64(k2)) e.mapElemValue() e.encode(v2) } } e.mapEnd() } func (e *Encoder) fastpathEncMapIntStringR(f *codecFnInfo, rv reflect.Value) { fastpathTV.EncMapIntStringV(rv2i(rv).(map[int]string), e) } func (fastpathT) EncMapIntStringV(v map[int]string, e *Encoder) { e.mapStart(len(v)) if e.h.Canonical { v2 := make([]int, len(v)) var i uint for k := range v { v2[i] = k i++ } sort.Sort(intSlice(v2)) for _, k2 := range v2 { e.mapElemKey() e.e.EncodeInt(int64(k2)) e.mapElemValue() e.e.EncodeString(v[k2]) } } else { for k2, v2 := range v { e.mapElemKey() e.e.EncodeInt(int64(k2)) e.mapElemValue() e.e.EncodeString(v2) } } e.mapEnd() } func (e *Encoder) fastpathEncMapIntBytesR(f *codecFnInfo, rv reflect.Value) { fastpathTV.EncMapIntBytesV(rv2i(rv).(map[int][]byte), e) } func (fastpathT) EncMapIntBytesV(v map[int][]byte, e *Encoder) { e.mapStart(len(v)) if e.h.Canonical { v2 := make([]int, len(v)) var i uint for k := range v { v2[i] = k i++ } sort.Sort(intSlice(v2)) for _, k2 := range v2 { e.mapElemKey() e.e.EncodeInt(int64(k2)) e.mapElemValue() e.e.EncodeStringBytesRaw(v[k2]) } } else { for k2, v2 := range v { e.mapElemKey() e.e.EncodeInt(int64(k2)) e.mapElemValue() e.e.EncodeStringBytesRaw(v2) } } e.mapEnd() } func (e *Encoder) fastpathEncMapIntUint8R(f *codecFnInfo, rv reflect.Value) { fastpathTV.EncMapIntUint8V(rv2i(rv).(map[int]uint8), e) } func (fastpathT) EncMapIntUint8V(v map[int]uint8, e *Encoder) { e.mapStart(len(v)) if e.h.Canonical { v2 := make([]int, len(v)) var i uint for k := range v { v2[i] = k i++ } sort.Sort(intSlice(v2)) for _, k2 := range v2 { e.mapElemKey() e.e.EncodeInt(int64(k2)) e.mapElemValue() e.e.EncodeUint(uint64(v[k2])) } } else { for k2, v2 := range v { e.mapElemKey() e.e.EncodeInt(int64(k2)) e.mapElemValue() e.e.EncodeUint(uint64(v2)) } } e.mapEnd() } func (e *Encoder) fastpathEncMapIntUint64R(f *codecFnInfo, rv reflect.Value) { fastpathTV.EncMapIntUint64V(rv2i(rv).(map[int]uint64), e) } func (fastpathT) EncMapIntUint64V(v map[int]uint64, e *Encoder) { e.mapStart(len(v)) if e.h.Canonical { v2 := make([]int, len(v)) var i uint for k := range v { v2[i] = k i++ } sort.Sort(intSlice(v2)) for _, k2 := range v2 { e.mapElemKey() e.e.EncodeInt(int64(k2)) e.mapElemValue() e.e.EncodeUint(v[k2]) } } else { for k2, v2 := range v { e.mapElemKey() e.e.EncodeInt(int64(k2)) e.mapElemValue() e.e.EncodeUint(v2) } } e.mapEnd() } func (e *Encoder) fastpathEncMapIntIntR(f *codecFnInfo, rv reflect.Value) { fastpathTV.EncMapIntIntV(rv2i(rv).(map[int]int), e) } func (fastpathT) EncMapIntIntV(v map[int]int, e *Encoder) { e.mapStart(len(v)) if e.h.Canonical { v2 := make([]int, len(v)) var i uint for k := range v { v2[i] = k i++ } sort.Sort(intSlice(v2)) for _, k2 := range v2 { e.mapElemKey() e.e.EncodeInt(int64(k2)) e.mapElemValue() e.e.EncodeInt(int64(v[k2])) } } else { for k2, v2 := range v { e.mapElemKey() e.e.EncodeInt(int64(k2)) e.mapElemValue() e.e.EncodeInt(int64(v2)) } } e.mapEnd() } func (e *Encoder) fastpathEncMapIntInt32R(f *codecFnInfo, rv reflect.Value) { fastpathTV.EncMapIntInt32V(rv2i(rv).(map[int]int32), e) } func (fastpathT) EncMapIntInt32V(v map[int]int32, e *Encoder) { e.mapStart(len(v)) if e.h.Canonical { v2 := make([]int, len(v)) var i uint for k := range v { v2[i] = k i++ } sort.Sort(intSlice(v2)) for _, k2 := range v2 { e.mapElemKey() e.e.EncodeInt(int64(k2)) e.mapElemValue() e.e.EncodeInt(int64(v[k2])) } } else { for k2, v2 := range v { e.mapElemKey() e.e.EncodeInt(int64(k2)) e.mapElemValue() e.e.EncodeInt(int64(v2)) } } e.mapEnd() } func (e *Encoder) fastpathEncMapIntFloat64R(f *codecFnInfo, rv reflect.Value) { fastpathTV.EncMapIntFloat64V(rv2i(rv).(map[int]float64), e) } func (fastpathT) EncMapIntFloat64V(v map[int]float64, e *Encoder) { e.mapStart(len(v)) if e.h.Canonical { v2 := make([]int, len(v)) var i uint for k := range v { v2[i] = k i++ } sort.Sort(intSlice(v2)) for _, k2 := range v2 { e.mapElemKey() e.e.EncodeInt(int64(k2)) e.mapElemValue() e.e.EncodeFloat64(v[k2]) } } else { for k2, v2 := range v { e.mapElemKey() e.e.EncodeInt(int64(k2)) e.mapElemValue() e.e.EncodeFloat64(v2) } } e.mapEnd() } func (e *Encoder) fastpathEncMapIntBoolR(f *codecFnInfo, rv reflect.Value) { fastpathTV.EncMapIntBoolV(rv2i(rv).(map[int]bool), e) } func (fastpathT) EncMapIntBoolV(v map[int]bool, e *Encoder) { e.mapStart(len(v)) if e.h.Canonical { v2 := make([]int, len(v)) var i uint for k := range v { v2[i] = k i++ } sort.Sort(intSlice(v2)) for _, k2 := range v2 { e.mapElemKey() e.e.EncodeInt(int64(k2)) e.mapElemValue() e.e.EncodeBool(v[k2]) } } else { for k2, v2 := range v { e.mapElemKey() e.e.EncodeInt(int64(k2)) e.mapElemValue() e.e.EncodeBool(v2) } } e.mapEnd() } func (e *Encoder) fastpathEncMapInt32IntfR(f *codecFnInfo, rv reflect.Value) { fastpathTV.EncMapInt32IntfV(rv2i(rv).(map[int32]interface{}), e) } func (fastpathT) EncMapInt32IntfV(v map[int32]interface{}, e *Encoder) { e.mapStart(len(v)) if e.h.Canonical { v2 := make([]int32, len(v)) var i uint for k := range v { v2[i] = k i++ } sort.Sort(int32Slice(v2)) for _, k2 := range v2 { e.mapElemKey() e.e.EncodeInt(int64(k2)) e.mapElemValue() e.encode(v[k2]) } } else { for k2, v2 := range v { e.mapElemKey() e.e.EncodeInt(int64(k2)) e.mapElemValue() e.encode(v2) } } e.mapEnd() } func (e *Encoder) fastpathEncMapInt32StringR(f *codecFnInfo, rv reflect.Value) { fastpathTV.EncMapInt32StringV(rv2i(rv).(map[int32]string), e) } func (fastpathT) EncMapInt32StringV(v map[int32]string, e *Encoder) { e.mapStart(len(v)) if e.h.Canonical { v2 := make([]int32, len(v)) var i uint for k := range v { v2[i] = k i++ } sort.Sort(int32Slice(v2)) for _, k2 := range v2 { e.mapElemKey() e.e.EncodeInt(int64(k2)) e.mapElemValue() e.e.EncodeString(v[k2]) } } else { for k2, v2 := range v { e.mapElemKey() e.e.EncodeInt(int64(k2)) e.mapElemValue() e.e.EncodeString(v2) } } e.mapEnd() } func (e *Encoder) fastpathEncMapInt32BytesR(f *codecFnInfo, rv reflect.Value) { fastpathTV.EncMapInt32BytesV(rv2i(rv).(map[int32][]byte), e) } func (fastpathT) EncMapInt32BytesV(v map[int32][]byte, e *Encoder) { e.mapStart(len(v)) if e.h.Canonical { v2 := make([]int32, len(v)) var i uint for k := range v { v2[i] = k i++ } sort.Sort(int32Slice(v2)) for _, k2 := range v2 { e.mapElemKey() e.e.EncodeInt(int64(k2)) e.mapElemValue() e.e.EncodeStringBytesRaw(v[k2]) } } else { for k2, v2 := range v { e.mapElemKey() e.e.EncodeInt(int64(k2)) e.mapElemValue() e.e.EncodeStringBytesRaw(v2) } } e.mapEnd() } func (e *Encoder) fastpathEncMapInt32Uint8R(f *codecFnInfo, rv reflect.Value) { fastpathTV.EncMapInt32Uint8V(rv2i(rv).(map[int32]uint8), e) } func (fastpathT) EncMapInt32Uint8V(v map[int32]uint8, e *Encoder) { e.mapStart(len(v)) if e.h.Canonical { v2 := make([]int32, len(v)) var i uint for k := range v { v2[i] = k i++ } sort.Sort(int32Slice(v2)) for _, k2 := range v2 { e.mapElemKey() e.e.EncodeInt(int64(k2)) e.mapElemValue() e.e.EncodeUint(uint64(v[k2])) } } else { for k2, v2 := range v { e.mapElemKey() e.e.EncodeInt(int64(k2)) e.mapElemValue() e.e.EncodeUint(uint64(v2)) } } e.mapEnd() } func (e *Encoder) fastpathEncMapInt32Uint64R(f *codecFnInfo, rv reflect.Value) { fastpathTV.EncMapInt32Uint64V(rv2i(rv).(map[int32]uint64), e) } func (fastpathT) EncMapInt32Uint64V(v map[int32]uint64, e *Encoder) { e.mapStart(len(v)) if e.h.Canonical { v2 := make([]int32, len(v)) var i uint for k := range v { v2[i] = k i++ } sort.Sort(int32Slice(v2)) for _, k2 := range v2 { e.mapElemKey() e.e.EncodeInt(int64(k2)) e.mapElemValue() e.e.EncodeUint(v[k2]) } } else { for k2, v2 := range v { e.mapElemKey() e.e.EncodeInt(int64(k2)) e.mapElemValue() e.e.EncodeUint(v2) } } e.mapEnd() } func (e *Encoder) fastpathEncMapInt32IntR(f *codecFnInfo, rv reflect.Value) { fastpathTV.EncMapInt32IntV(rv2i(rv).(map[int32]int), e) } func (fastpathT) EncMapInt32IntV(v map[int32]int, e *Encoder) { e.mapStart(len(v)) if e.h.Canonical { v2 := make([]int32, len(v)) var i uint for k := range v { v2[i] = k i++ } sort.Sort(int32Slice(v2)) for _, k2 := range v2 { e.mapElemKey() e.e.EncodeInt(int64(k2)) e.mapElemValue() e.e.EncodeInt(int64(v[k2])) } } else { for k2, v2 := range v { e.mapElemKey() e.e.EncodeInt(int64(k2)) e.mapElemValue() e.e.EncodeInt(int64(v2)) } } e.mapEnd() } func (e *Encoder) fastpathEncMapInt32Int32R(f *codecFnInfo, rv reflect.Value) { fastpathTV.EncMapInt32Int32V(rv2i(rv).(map[int32]int32), e) } func (fastpathT) EncMapInt32Int32V(v map[int32]int32, e *Encoder) { e.mapStart(len(v)) if e.h.Canonical { v2 := make([]int32, len(v)) var i uint for k := range v { v2[i] = k i++ } sort.Sort(int32Slice(v2)) for _, k2 := range v2 { e.mapElemKey() e.e.EncodeInt(int64(k2)) e.mapElemValue() e.e.EncodeInt(int64(v[k2])) } } else { for k2, v2 := range v { e.mapElemKey() e.e.EncodeInt(int64(k2)) e.mapElemValue() e.e.EncodeInt(int64(v2)) } } e.mapEnd() } func (e *Encoder) fastpathEncMapInt32Float64R(f *codecFnInfo, rv reflect.Value) { fastpathTV.EncMapInt32Float64V(rv2i(rv).(map[int32]float64), e) } func (fastpathT) EncMapInt32Float64V(v map[int32]float64, e *Encoder) { e.mapStart(len(v)) if e.h.Canonical { v2 := make([]int32, len(v)) var i uint for k := range v { v2[i] = k i++ } sort.Sort(int32Slice(v2)) for _, k2 := range v2 { e.mapElemKey() e.e.EncodeInt(int64(k2)) e.mapElemValue() e.e.EncodeFloat64(v[k2]) } } else { for k2, v2 := range v { e.mapElemKey() e.e.EncodeInt(int64(k2)) e.mapElemValue() e.e.EncodeFloat64(v2) } } e.mapEnd() } func (e *Encoder) fastpathEncMapInt32BoolR(f *codecFnInfo, rv reflect.Value) { fastpathTV.EncMapInt32BoolV(rv2i(rv).(map[int32]bool), e) } func (fastpathT) EncMapInt32BoolV(v map[int32]bool, e *Encoder) { e.mapStart(len(v)) if e.h.Canonical { v2 := make([]int32, len(v)) var i uint for k := range v { v2[i] = k i++ } sort.Sort(int32Slice(v2)) for _, k2 := range v2 { e.mapElemKey() e.e.EncodeInt(int64(k2)) e.mapElemValue() e.e.EncodeBool(v[k2]) } } else { for k2, v2 := range v { e.mapElemKey() e.e.EncodeInt(int64(k2)) e.mapElemValue() e.e.EncodeBool(v2) } } e.mapEnd() } // -- decode // -- -- fast path type switch func fastpathDecodeTypeSwitch(iv interface{}, d *Decoder) bool { var changed bool var containerLen int switch v := iv.(type) { case []interface{}: fastpathTV.DecSliceIntfN(v, d) case *[]interface{}: var v2 []interface{} if v2, changed = fastpathTV.DecSliceIntfY(*v, d); changed { *v = v2 } case []string: fastpathTV.DecSliceStringN(v, d) case *[]string: var v2 []string if v2, changed = fastpathTV.DecSliceStringY(*v, d); changed { *v = v2 } case [][]byte: fastpathTV.DecSliceBytesN(v, d) case *[][]byte: var v2 [][]byte if v2, changed = fastpathTV.DecSliceBytesY(*v, d); changed { *v = v2 } case []float32: fastpathTV.DecSliceFloat32N(v, d) case *[]float32: var v2 []float32 if v2, changed = fastpathTV.DecSliceFloat32Y(*v, d); changed { *v = v2 } case []float64: fastpathTV.DecSliceFloat64N(v, d) case *[]float64: var v2 []float64 if v2, changed = fastpathTV.DecSliceFloat64Y(*v, d); changed { *v = v2 } case []uint8: fastpathTV.DecSliceUint8N(v, d) case *[]uint8: var v2 []uint8 if v2, changed = fastpathTV.DecSliceUint8Y(*v, d); changed { *v = v2 } case []uint64: fastpathTV.DecSliceUint64N(v, d) case *[]uint64: var v2 []uint64 if v2, changed = fastpathTV.DecSliceUint64Y(*v, d); changed { *v = v2 } case []int: fastpathTV.DecSliceIntN(v, d) case *[]int: var v2 []int if v2, changed = fastpathTV.DecSliceIntY(*v, d); changed { *v = v2 } case []int32: fastpathTV.DecSliceInt32N(v, d) case *[]int32: var v2 []int32 if v2, changed = fastpathTV.DecSliceInt32Y(*v, d); changed { *v = v2 } case []int64: fastpathTV.DecSliceInt64N(v, d) case *[]int64: var v2 []int64 if v2, changed = fastpathTV.DecSliceInt64Y(*v, d); changed { *v = v2 } case []bool: fastpathTV.DecSliceBoolN(v, d) case *[]bool: var v2 []bool if v2, changed = fastpathTV.DecSliceBoolY(*v, d); changed { *v = v2 } case map[string]interface{}: containerLen = d.mapStart(d.d.ReadMapStart()) if containerLen != containerLenNil { if containerLen != 0 { fastpathTV.DecMapStringIntfL(v, containerLen, d) } d.mapEnd() } case *map[string]interface{}: fastpathTV.DecMapStringIntfX(v, d) case map[string]string: containerLen = d.mapStart(d.d.ReadMapStart()) if containerLen != containerLenNil { if containerLen != 0 { fastpathTV.DecMapStringStringL(v, containerLen, d) } d.mapEnd() } case *map[string]string: fastpathTV.DecMapStringStringX(v, d) case map[string][]byte: containerLen = d.mapStart(d.d.ReadMapStart()) if containerLen != containerLenNil { if containerLen != 0 { fastpathTV.DecMapStringBytesL(v, containerLen, d) } d.mapEnd() } case *map[string][]byte: fastpathTV.DecMapStringBytesX(v, d) case map[string]uint8: containerLen = d.mapStart(d.d.ReadMapStart()) if containerLen != containerLenNil { if containerLen != 0 { fastpathTV.DecMapStringUint8L(v, containerLen, d) } d.mapEnd() } case *map[string]uint8: fastpathTV.DecMapStringUint8X(v, d) case map[string]uint64: containerLen = d.mapStart(d.d.ReadMapStart()) if containerLen != containerLenNil { if containerLen != 0 { fastpathTV.DecMapStringUint64L(v, containerLen, d) } d.mapEnd() } case *map[string]uint64: fastpathTV.DecMapStringUint64X(v, d) case map[string]int: containerLen = d.mapStart(d.d.ReadMapStart()) if containerLen != containerLenNil { if containerLen != 0 { fastpathTV.DecMapStringIntL(v, containerLen, d) } d.mapEnd() } case *map[string]int: fastpathTV.DecMapStringIntX(v, d) case map[string]int32: containerLen = d.mapStart(d.d.ReadMapStart()) if containerLen != containerLenNil { if containerLen != 0 { fastpathTV.DecMapStringInt32L(v, containerLen, d) } d.mapEnd() } case *map[string]int32: fastpathTV.DecMapStringInt32X(v, d) case map[string]float64: containerLen = d.mapStart(d.d.ReadMapStart()) if containerLen != containerLenNil { if containerLen != 0 { fastpathTV.DecMapStringFloat64L(v, containerLen, d) } d.mapEnd() } case *map[string]float64: fastpathTV.DecMapStringFloat64X(v, d) case map[string]bool: containerLen = d.mapStart(d.d.ReadMapStart()) if containerLen != containerLenNil { if containerLen != 0 { fastpathTV.DecMapStringBoolL(v, containerLen, d) } d.mapEnd() } case *map[string]bool: fastpathTV.DecMapStringBoolX(v, d) case map[uint8]interface{}: containerLen = d.mapStart(d.d.ReadMapStart()) if containerLen != containerLenNil { if containerLen != 0 { fastpathTV.DecMapUint8IntfL(v, containerLen, d) } d.mapEnd() } case *map[uint8]interface{}: fastpathTV.DecMapUint8IntfX(v, d) case map[uint8]string: containerLen = d.mapStart(d.d.ReadMapStart()) if containerLen != containerLenNil { if containerLen != 0 { fastpathTV.DecMapUint8StringL(v, containerLen, d) } d.mapEnd() } case *map[uint8]string: fastpathTV.DecMapUint8StringX(v, d) case map[uint8][]byte: containerLen = d.mapStart(d.d.ReadMapStart()) if containerLen != containerLenNil { if containerLen != 0 { fastpathTV.DecMapUint8BytesL(v, containerLen, d) } d.mapEnd() } case *map[uint8][]byte: fastpathTV.DecMapUint8BytesX(v, d) case map[uint8]uint8: containerLen = d.mapStart(d.d.ReadMapStart()) if containerLen != containerLenNil { if containerLen != 0 { fastpathTV.DecMapUint8Uint8L(v, containerLen, d) } d.mapEnd() } case *map[uint8]uint8: fastpathTV.DecMapUint8Uint8X(v, d) case map[uint8]uint64: containerLen = d.mapStart(d.d.ReadMapStart()) if containerLen != containerLenNil { if containerLen != 0 { fastpathTV.DecMapUint8Uint64L(v, containerLen, d) } d.mapEnd() } case *map[uint8]uint64: fastpathTV.DecMapUint8Uint64X(v, d) case map[uint8]int: containerLen = d.mapStart(d.d.ReadMapStart()) if containerLen != containerLenNil { if containerLen != 0 { fastpathTV.DecMapUint8IntL(v, containerLen, d) } d.mapEnd() } case *map[uint8]int: fastpathTV.DecMapUint8IntX(v, d) case map[uint8]int32: containerLen = d.mapStart(d.d.ReadMapStart()) if containerLen != containerLenNil { if containerLen != 0 { fastpathTV.DecMapUint8Int32L(v, containerLen, d) } d.mapEnd() } case *map[uint8]int32: fastpathTV.DecMapUint8Int32X(v, d) case map[uint8]float64: containerLen = d.mapStart(d.d.ReadMapStart()) if containerLen != containerLenNil { if containerLen != 0 { fastpathTV.DecMapUint8Float64L(v, containerLen, d) } d.mapEnd() } case *map[uint8]float64: fastpathTV.DecMapUint8Float64X(v, d) case map[uint8]bool: containerLen = d.mapStart(d.d.ReadMapStart()) if containerLen != containerLenNil { if containerLen != 0 { fastpathTV.DecMapUint8BoolL(v, containerLen, d) } d.mapEnd() } case *map[uint8]bool: fastpathTV.DecMapUint8BoolX(v, d) case map[uint64]interface{}: containerLen = d.mapStart(d.d.ReadMapStart()) if containerLen != containerLenNil { if containerLen != 0 { fastpathTV.DecMapUint64IntfL(v, containerLen, d) } d.mapEnd() } case *map[uint64]interface{}: fastpathTV.DecMapUint64IntfX(v, d) case map[uint64]string: containerLen = d.mapStart(d.d.ReadMapStart()) if containerLen != containerLenNil { if containerLen != 0 { fastpathTV.DecMapUint64StringL(v, containerLen, d) } d.mapEnd() } case *map[uint64]string: fastpathTV.DecMapUint64StringX(v, d) case map[uint64][]byte: containerLen = d.mapStart(d.d.ReadMapStart()) if containerLen != containerLenNil { if containerLen != 0 { fastpathTV.DecMapUint64BytesL(v, containerLen, d) } d.mapEnd() } case *map[uint64][]byte: fastpathTV.DecMapUint64BytesX(v, d) case map[uint64]uint8: containerLen = d.mapStart(d.d.ReadMapStart()) if containerLen != containerLenNil { if containerLen != 0 { fastpathTV.DecMapUint64Uint8L(v, containerLen, d) } d.mapEnd() } case *map[uint64]uint8: fastpathTV.DecMapUint64Uint8X(v, d) case map[uint64]uint64: containerLen = d.mapStart(d.d.ReadMapStart()) if containerLen != containerLenNil { if containerLen != 0 { fastpathTV.DecMapUint64Uint64L(v, containerLen, d) } d.mapEnd() } case *map[uint64]uint64: fastpathTV.DecMapUint64Uint64X(v, d) case map[uint64]int: containerLen = d.mapStart(d.d.ReadMapStart()) if containerLen != containerLenNil { if containerLen != 0 { fastpathTV.DecMapUint64IntL(v, containerLen, d) } d.mapEnd() } case *map[uint64]int: fastpathTV.DecMapUint64IntX(v, d) case map[uint64]int32: containerLen = d.mapStart(d.d.ReadMapStart()) if containerLen != containerLenNil { if containerLen != 0 { fastpathTV.DecMapUint64Int32L(v, containerLen, d) } d.mapEnd() } case *map[uint64]int32: fastpathTV.DecMapUint64Int32X(v, d) case map[uint64]float64: containerLen = d.mapStart(d.d.ReadMapStart()) if containerLen != containerLenNil { if containerLen != 0 { fastpathTV.DecMapUint64Float64L(v, containerLen, d) } d.mapEnd() } case *map[uint64]float64: fastpathTV.DecMapUint64Float64X(v, d) case map[uint64]bool: containerLen = d.mapStart(d.d.ReadMapStart()) if containerLen != containerLenNil { if containerLen != 0 { fastpathTV.DecMapUint64BoolL(v, containerLen, d) } d.mapEnd() } case *map[uint64]bool: fastpathTV.DecMapUint64BoolX(v, d) case map[int]interface{}: containerLen = d.mapStart(d.d.ReadMapStart()) if containerLen != containerLenNil { if containerLen != 0 { fastpathTV.DecMapIntIntfL(v, containerLen, d) } d.mapEnd() } case *map[int]interface{}: fastpathTV.DecMapIntIntfX(v, d) case map[int]string: containerLen = d.mapStart(d.d.ReadMapStart()) if containerLen != containerLenNil { if containerLen != 0 { fastpathTV.DecMapIntStringL(v, containerLen, d) } d.mapEnd() } case *map[int]string: fastpathTV.DecMapIntStringX(v, d) case map[int][]byte: containerLen = d.mapStart(d.d.ReadMapStart()) if containerLen != containerLenNil { if containerLen != 0 { fastpathTV.DecMapIntBytesL(v, containerLen, d) } d.mapEnd() } case *map[int][]byte: fastpathTV.DecMapIntBytesX(v, d) case map[int]uint8: containerLen = d.mapStart(d.d.ReadMapStart()) if containerLen != containerLenNil { if containerLen != 0 { fastpathTV.DecMapIntUint8L(v, containerLen, d) } d.mapEnd() } case *map[int]uint8: fastpathTV.DecMapIntUint8X(v, d) case map[int]uint64: containerLen = d.mapStart(d.d.ReadMapStart()) if containerLen != containerLenNil { if containerLen != 0 { fastpathTV.DecMapIntUint64L(v, containerLen, d) } d.mapEnd() } case *map[int]uint64: fastpathTV.DecMapIntUint64X(v, d) case map[int]int: containerLen = d.mapStart(d.d.ReadMapStart()) if containerLen != containerLenNil { if containerLen != 0 { fastpathTV.DecMapIntIntL(v, containerLen, d) } d.mapEnd() } case *map[int]int: fastpathTV.DecMapIntIntX(v, d) case map[int]int32: containerLen = d.mapStart(d.d.ReadMapStart()) if containerLen != containerLenNil { if containerLen != 0 { fastpathTV.DecMapIntInt32L(v, containerLen, d) } d.mapEnd() } case *map[int]int32: fastpathTV.DecMapIntInt32X(v, d) case map[int]float64: containerLen = d.mapStart(d.d.ReadMapStart()) if containerLen != containerLenNil { if containerLen != 0 { fastpathTV.DecMapIntFloat64L(v, containerLen, d) } d.mapEnd() } case *map[int]float64: fastpathTV.DecMapIntFloat64X(v, d) case map[int]bool: containerLen = d.mapStart(d.d.ReadMapStart()) if containerLen != containerLenNil { if containerLen != 0 { fastpathTV.DecMapIntBoolL(v, containerLen, d) } d.mapEnd() } case *map[int]bool: fastpathTV.DecMapIntBoolX(v, d) case map[int32]interface{}: containerLen = d.mapStart(d.d.ReadMapStart()) if containerLen != containerLenNil { if containerLen != 0 { fastpathTV.DecMapInt32IntfL(v, containerLen, d) } d.mapEnd() } case *map[int32]interface{}: fastpathTV.DecMapInt32IntfX(v, d) case map[int32]string: containerLen = d.mapStart(d.d.ReadMapStart()) if containerLen != containerLenNil { if containerLen != 0 { fastpathTV.DecMapInt32StringL(v, containerLen, d) } d.mapEnd() } case *map[int32]string: fastpathTV.DecMapInt32StringX(v, d) case map[int32][]byte: containerLen = d.mapStart(d.d.ReadMapStart()) if containerLen != containerLenNil { if containerLen != 0 { fastpathTV.DecMapInt32BytesL(v, containerLen, d) } d.mapEnd() } case *map[int32][]byte: fastpathTV.DecMapInt32BytesX(v, d) case map[int32]uint8: containerLen = d.mapStart(d.d.ReadMapStart()) if containerLen != containerLenNil { if containerLen != 0 { fastpathTV.DecMapInt32Uint8L(v, containerLen, d) } d.mapEnd() } case *map[int32]uint8: fastpathTV.DecMapInt32Uint8X(v, d) case map[int32]uint64: containerLen = d.mapStart(d.d.ReadMapStart()) if containerLen != containerLenNil { if containerLen != 0 { fastpathTV.DecMapInt32Uint64L(v, containerLen, d) } d.mapEnd() } case *map[int32]uint64: fastpathTV.DecMapInt32Uint64X(v, d) case map[int32]int: containerLen = d.mapStart(d.d.ReadMapStart()) if containerLen != containerLenNil { if containerLen != 0 { fastpathTV.DecMapInt32IntL(v, containerLen, d) } d.mapEnd() } case *map[int32]int: fastpathTV.DecMapInt32IntX(v, d) case map[int32]int32: containerLen = d.mapStart(d.d.ReadMapStart()) if containerLen != containerLenNil { if containerLen != 0 { fastpathTV.DecMapInt32Int32L(v, containerLen, d) } d.mapEnd() } case *map[int32]int32: fastpathTV.DecMapInt32Int32X(v, d) case map[int32]float64: containerLen = d.mapStart(d.d.ReadMapStart()) if containerLen != containerLenNil { if containerLen != 0 { fastpathTV.DecMapInt32Float64L(v, containerLen, d) } d.mapEnd() } case *map[int32]float64: fastpathTV.DecMapInt32Float64X(v, d) case map[int32]bool: containerLen = d.mapStart(d.d.ReadMapStart()) if containerLen != containerLenNil { if containerLen != 0 { fastpathTV.DecMapInt32BoolL(v, containerLen, d) } d.mapEnd() } case *map[int32]bool: fastpathTV.DecMapInt32BoolX(v, d) default: _ = v // workaround https://github.com/golang/go/issues/12927 seen in go1.4 return false } return true } 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 } // -- -- fast path functions func (d *Decoder) fastpathDecSliceIntfR(f *codecFnInfo, rv reflect.Value) { var v []interface{} switch rv.Kind() { case reflect.Ptr: vp := rv2i(rv).(*[]interface{}) var changed bool if v, changed = fastpathTV.DecSliceIntfY(*vp, d); changed { *vp = v } case reflect.Array: rvGetSlice4Array(rv, &v) fastpathTV.DecSliceIntfN(v, d) default: fastpathTV.DecSliceIntfN(rv2i(rv).([]interface{}), d) } } func (f fastpathT) DecSliceIntfX(vp *[]interface{}, d *Decoder) { if v, changed := f.DecSliceIntfY(*vp, d); changed { *vp = v } } func (fastpathT) DecSliceIntfY(v []interface{}, d *Decoder) (v2 []interface{}, changed bool) { slh, containerLenS := d.decSliceHelperStart() if slh.IsNil { if v == nil { return } return nil, true } if containerLenS == 0 { if v == nil { v = []interface{}{} } else if len(v) != 0 { v = v[:0] } slh.End() return v, true } hasLen := containerLenS > 0 var xlen int if hasLen { if containerLenS > cap(v) { xlen = decInferLen(containerLenS, d.h.MaxInitLen, 16) if xlen <= cap(v) { v = v[:uint(xlen)] } else { v = make([]interface{}, uint(xlen)) } changed = true } else if containerLenS != len(v) { v = v[:containerLenS] changed = true } } var j int for j = 0; (hasLen && j < containerLenS) || !(hasLen || d.checkBreak()); j++ { if j == 0 && len(v) == 0 { // means hasLen == false xlen = decInferLen(containerLenS, d.h.MaxInitLen, 16) v = make([]interface{}, uint(xlen)) changed = true } if j >= len(v) { v = append(v, nil) changed = true } slh.ElemContainerState(j) d.decode(&v[uint(j)]) } if j < len(v) { v = v[:uint(j)] changed = true } else if j == 0 && v == nil { v = []interface{}{} changed = true } slh.End() return v, changed } func (fastpathT) DecSliceIntfN(v []interface{}, d *Decoder) { slh, containerLenS := d.decSliceHelperStart() if slh.IsNil { return } if containerLenS == 0 { slh.End() return } hasLen := containerLenS > 0 for j := 0; (hasLen && j < containerLenS) || !(hasLen || d.checkBreak()); j++ { if j >= len(v) { slh.arrayCannotExpand(hasLen, len(v), j, containerLenS) return } slh.ElemContainerState(j) d.decode(&v[uint(j)]) } slh.End() } func (d *Decoder) fastpathDecSliceStringR(f *codecFnInfo, rv reflect.Value) { var v []string switch rv.Kind() { case reflect.Ptr: vp := rv2i(rv).(*[]string) var changed bool if v, changed = fastpathTV.DecSliceStringY(*vp, d); changed { *vp = v } case reflect.Array: rvGetSlice4Array(rv, &v) fastpathTV.DecSliceStringN(v, d) default: fastpathTV.DecSliceStringN(rv2i(rv).([]string), d) } } func (f fastpathT) DecSliceStringX(vp *[]string, d *Decoder) { if v, changed := f.DecSliceStringY(*vp, d); changed { *vp = v } } func (fastpathT) DecSliceStringY(v []string, d *Decoder) (v2 []string, changed bool) { slh, containerLenS := d.decSliceHelperStart() if slh.IsNil { if v == nil { return } return nil, true } if containerLenS == 0 { if v == nil { v = []string{} } else if len(v) != 0 { v = v[:0] } slh.End() return v, true } hasLen := containerLenS > 0 var xlen int if hasLen { if containerLenS > cap(v) { xlen = decInferLen(containerLenS, d.h.MaxInitLen, 16) if xlen <= cap(v) { v = v[:uint(xlen)] } else { v = make([]string, uint(xlen)) } changed = true } else if containerLenS != len(v) { v = v[:containerLenS] changed = true } } var j int for j = 0; (hasLen && j < containerLenS) || !(hasLen || d.checkBreak()); j++ { if j == 0 && len(v) == 0 { // means hasLen == false xlen = decInferLen(containerLenS, d.h.MaxInitLen, 16) v = make([]string, uint(xlen)) changed = true } if j >= len(v) { v = append(v, "") changed = true } slh.ElemContainerState(j) v[uint(j)] = d.stringZC(d.d.DecodeStringAsBytes()) } if j < len(v) { v = v[:uint(j)] changed = true } else if j == 0 && v == nil { v = []string{} changed = true } slh.End() return v, changed } func (fastpathT) DecSliceStringN(v []string, d *Decoder) { slh, containerLenS := d.decSliceHelperStart() if slh.IsNil { return } if containerLenS == 0 { slh.End() return } hasLen := containerLenS > 0 for j := 0; (hasLen && j < containerLenS) || !(hasLen || d.checkBreak()); j++ { if j >= len(v) { slh.arrayCannotExpand(hasLen, len(v), j, containerLenS) return } slh.ElemContainerState(j) v[uint(j)] = d.stringZC(d.d.DecodeStringAsBytes()) } slh.End() } func (d *Decoder) fastpathDecSliceBytesR(f *codecFnInfo, rv reflect.Value) { var v [][]byte switch rv.Kind() { case reflect.Ptr: vp := rv2i(rv).(*[][]byte) var changed bool if v, changed = fastpathTV.DecSliceBytesY(*vp, d); changed { *vp = v } case reflect.Array: rvGetSlice4Array(rv, &v) fastpathTV.DecSliceBytesN(v, d) default: fastpathTV.DecSliceBytesN(rv2i(rv).([][]byte), d) } } func (f fastpathT) DecSliceBytesX(vp *[][]byte, d *Decoder) { if v, changed := f.DecSliceBytesY(*vp, d); changed { *vp = v } } func (fastpathT) DecSliceBytesY(v [][]byte, d *Decoder) (v2 [][]byte, changed bool) { slh, containerLenS := d.decSliceHelperStart() if slh.IsNil { if v == nil { return } return nil, true } if containerLenS == 0 { if v == nil { v = [][]byte{} } else if len(v) != 0 { v = v[:0] } slh.End() return v, true } hasLen := containerLenS > 0 var xlen int if hasLen { if containerLenS > cap(v) { xlen = decInferLen(containerLenS, d.h.MaxInitLen, 24) if xlen <= cap(v) { v = v[:uint(xlen)] } else { v = make([][]byte, uint(xlen)) } changed = true } else if containerLenS != len(v) { v = v[:containerLenS] changed = true } } var j int for j = 0; (hasLen && j < containerLenS) || !(hasLen || d.checkBreak()); j++ { if j == 0 && len(v) == 0 { // means hasLen == false xlen = decInferLen(containerLenS, d.h.MaxInitLen, 24) v = make([][]byte, uint(xlen)) changed = true } if j >= len(v) { v = append(v, nil) changed = true } slh.ElemContainerState(j) v[uint(j)] = d.d.DecodeBytes([]byte{}) } if j < len(v) { v = v[:uint(j)] changed = true } else if j == 0 && v == nil { v = [][]byte{} changed = true } slh.End() return v, changed } func (fastpathT) DecSliceBytesN(v [][]byte, d *Decoder) { slh, containerLenS := d.decSliceHelperStart() if slh.IsNil { return } if containerLenS == 0 { slh.End() return } hasLen := containerLenS > 0 for j := 0; (hasLen && j < containerLenS) || !(hasLen || d.checkBreak()); j++ { if j >= len(v) { slh.arrayCannotExpand(hasLen, len(v), j, containerLenS) return } slh.ElemContainerState(j) v[uint(j)] = d.d.DecodeBytes([]byte{}) } slh.End() } func (d *Decoder) fastpathDecSliceFloat32R(f *codecFnInfo, rv reflect.Value) { var v []float32 switch rv.Kind() { case reflect.Ptr: vp := rv2i(rv).(*[]float32) var changed bool if v, changed = fastpathTV.DecSliceFloat32Y(*vp, d); changed { *vp = v } case reflect.Array: rvGetSlice4Array(rv, &v) fastpathTV.DecSliceFloat32N(v, d) default: fastpathTV.DecSliceFloat32N(rv2i(rv).([]float32), d) } } func (f fastpathT) DecSliceFloat32X(vp *[]float32, d *Decoder) { if v, changed := f.DecSliceFloat32Y(*vp, d); changed { *vp = v } } func (fastpathT) DecSliceFloat32Y(v []float32, d *Decoder) (v2 []float32, changed bool) { slh, containerLenS := d.decSliceHelperStart() if slh.IsNil { if v == nil { return } return nil, true } if containerLenS == 0 { if v == nil { v = []float32{} } else if len(v) != 0 { v = v[:0] } slh.End() return v, true } hasLen := containerLenS > 0 var xlen int if hasLen { if containerLenS > cap(v) { xlen = decInferLen(containerLenS, d.h.MaxInitLen, 4) if xlen <= cap(v) { v = v[:uint(xlen)] } else { v = make([]float32, uint(xlen)) } changed = true } else if containerLenS != len(v) { v = v[:containerLenS] changed = true } } var j int for j = 0; (hasLen && j < containerLenS) || !(hasLen || d.checkBreak()); j++ { if j == 0 && len(v) == 0 { // means hasLen == false xlen = decInferLen(containerLenS, d.h.MaxInitLen, 4) v = make([]float32, uint(xlen)) changed = true } if j >= len(v) { v = append(v, 0) changed = true } slh.ElemContainerState(j) v[uint(j)] = float32(d.decodeFloat32()) } if j < len(v) { v = v[:uint(j)] changed = true } else if j == 0 && v == nil { v = []float32{} changed = true } slh.End() return v, changed } func (fastpathT) DecSliceFloat32N(v []float32, d *Decoder) { slh, containerLenS := d.decSliceHelperStart() if slh.IsNil { return } if containerLenS == 0 { slh.End() return } hasLen := containerLenS > 0 for j := 0; (hasLen && j < containerLenS) || !(hasLen || d.checkBreak()); j++ { if j >= len(v) { slh.arrayCannotExpand(hasLen, len(v), j, containerLenS) return } slh.ElemContainerState(j) v[uint(j)] = float32(d.decodeFloat32()) } slh.End() } func (d *Decoder) fastpathDecSliceFloat64R(f *codecFnInfo, rv reflect.Value) { var v []float64 switch rv.Kind() { case reflect.Ptr: vp := rv2i(rv).(*[]float64) var changed bool if v, changed = fastpathTV.DecSliceFloat64Y(*vp, d); changed { *vp = v } case reflect.Array: rvGetSlice4Array(rv, &v) fastpathTV.DecSliceFloat64N(v, d) default: fastpathTV.DecSliceFloat64N(rv2i(rv).([]float64), d) } } func (f fastpathT) DecSliceFloat64X(vp *[]float64, d *Decoder) { if v, changed := f.DecSliceFloat64Y(*vp, d); changed { *vp = v } } func (fastpathT) DecSliceFloat64Y(v []float64, d *Decoder) (v2 []float64, changed bool) { slh, containerLenS := d.decSliceHelperStart() if slh.IsNil { if v == nil { return } return nil, true } if containerLenS == 0 { if v == nil { v = []float64{} } else if len(v) != 0 { v = v[:0] } slh.End() return v, true } hasLen := containerLenS > 0 var xlen int if hasLen { if containerLenS > cap(v) { xlen = decInferLen(containerLenS, d.h.MaxInitLen, 8) if xlen <= cap(v) { v = v[:uint(xlen)] } else { v = make([]float64, uint(xlen)) } changed = true } else if containerLenS != len(v) { v = v[:containerLenS] changed = true } } var j int for j = 0; (hasLen && j < containerLenS) || !(hasLen || d.checkBreak()); j++ { if j == 0 && len(v) == 0 { // means hasLen == false xlen = decInferLen(containerLenS, d.h.MaxInitLen, 8) v = make([]float64, uint(xlen)) changed = true } if j >= len(v) { v = append(v, 0) changed = true } slh.ElemContainerState(j) v[uint(j)] = d.d.DecodeFloat64() } if j < len(v) { v = v[:uint(j)] changed = true } else if j == 0 && v == nil { v = []float64{} changed = true } slh.End() return v, changed } func (fastpathT) DecSliceFloat64N(v []float64, d *Decoder) { slh, containerLenS := d.decSliceHelperStart() if slh.IsNil { return } if containerLenS == 0 { slh.End() return } hasLen := containerLenS > 0 for j := 0; (hasLen && j < containerLenS) || !(hasLen || d.checkBreak()); j++ { if j >= len(v) { slh.arrayCannotExpand(hasLen, len(v), j, containerLenS) return } slh.ElemContainerState(j) v[uint(j)] = d.d.DecodeFloat64() } slh.End() } func (d *Decoder) fastpathDecSliceUint8R(f *codecFnInfo, rv reflect.Value) { var v []uint8 switch rv.Kind() { case reflect.Ptr: vp := rv2i(rv).(*[]uint8) var changed bool if v, changed = fastpathTV.DecSliceUint8Y(*vp, d); changed { *vp = v } case reflect.Array: rvGetSlice4Array(rv, &v) fastpathTV.DecSliceUint8N(v, d) default: fastpathTV.DecSliceUint8N(rv2i(rv).([]uint8), d) } } func (f fastpathT) DecSliceUint8X(vp *[]uint8, d *Decoder) { if v, changed := f.DecSliceUint8Y(*vp, d); changed { *vp = v } } func (fastpathT) DecSliceUint8Y(v []uint8, d *Decoder) (v2 []uint8, changed bool) { switch d.d.ContainerType() { case valueTypeNil, valueTypeMap: break default: v2 = d.decodeBytesInto(v[:len(v):len(v)]) changed = !(len(v2) > 0 && len(v2) == len(v) && &v2[0] == &v[0]) // not same slice return } slh, containerLenS := d.decSliceHelperStart() if slh.IsNil { if v == nil { return } return nil, true } if containerLenS == 0 { if v == nil { v = []uint8{} } else if len(v) != 0 { v = v[:0] } slh.End() return v, true } hasLen := containerLenS > 0 var xlen int if hasLen { if containerLenS > cap(v) { xlen = decInferLen(containerLenS, d.h.MaxInitLen, 1) if xlen <= cap(v) { v = v[:uint(xlen)] } else { v = make([]uint8, uint(xlen)) } changed = true } else if containerLenS != len(v) { v = v[:containerLenS] changed = true } } var j int for j = 0; (hasLen && j < containerLenS) || !(hasLen || d.checkBreak()); j++ { if j == 0 && len(v) == 0 { // means hasLen == false xlen = decInferLen(containerLenS, d.h.MaxInitLen, 1) v = make([]uint8, uint(xlen)) changed = true } if j >= len(v) { v = append(v, 0) changed = true } slh.ElemContainerState(j) v[uint(j)] = uint8(chkOvf.UintV(d.d.DecodeUint64(), 8)) } if j < len(v) { v = v[:uint(j)] changed = true } else if j == 0 && v == nil { v = []uint8{} changed = true } slh.End() return v, changed } func (fastpathT) DecSliceUint8N(v []uint8, d *Decoder) { switch d.d.ContainerType() { case valueTypeNil, valueTypeMap: break default: v2 := d.decodeBytesInto(v[:len(v):len(v)]) if !(len(v2) > 0 && len(v2) == len(v) && &v2[0] == &v[0]) { // not same slice copy(v, v2) } return } slh, containerLenS := d.decSliceHelperStart() if slh.IsNil { return } if containerLenS == 0 { slh.End() return } hasLen := containerLenS > 0 for j := 0; (hasLen && j < containerLenS) || !(hasLen || d.checkBreak()); j++ { if j >= len(v) { slh.arrayCannotExpand(hasLen, len(v), j, containerLenS) return } slh.ElemContainerState(j) v[uint(j)] = uint8(chkOvf.UintV(d.d.DecodeUint64(), 8)) } slh.End() } func (d *Decoder) fastpathDecSliceUint64R(f *codecFnInfo, rv reflect.Value) { var v []uint64 switch rv.Kind() { case reflect.Ptr: vp := rv2i(rv).(*[]uint64) var changed bool if v, changed = fastpathTV.DecSliceUint64Y(*vp, d); changed { *vp = v } case reflect.Array: rvGetSlice4Array(rv, &v) fastpathTV.DecSliceUint64N(v, d) default: fastpathTV.DecSliceUint64N(rv2i(rv).([]uint64), d) } } func (f fastpathT) DecSliceUint64X(vp *[]uint64, d *Decoder) { if v, changed := f.DecSliceUint64Y(*vp, d); changed { *vp = v } } func (fastpathT) DecSliceUint64Y(v []uint64, d *Decoder) (v2 []uint64, changed bool) { slh, containerLenS := d.decSliceHelperStart() if slh.IsNil { if v == nil { return } return nil, true } if containerLenS == 0 { if v == nil { v = []uint64{} } else if len(v) != 0 { v = v[:0] } slh.End() return v, true } hasLen := containerLenS > 0 var xlen int if hasLen { if containerLenS > cap(v) { xlen = decInferLen(containerLenS, d.h.MaxInitLen, 8) if xlen <= cap(v) { v = v[:uint(xlen)] } else { v = make([]uint64, uint(xlen)) } changed = true } else if containerLenS != len(v) { v = v[:containerLenS] changed = true } } var j int for j = 0; (hasLen && j < containerLenS) || !(hasLen || d.checkBreak()); j++ { if j == 0 && len(v) == 0 { // means hasLen == false xlen = decInferLen(containerLenS, d.h.MaxInitLen, 8) v = make([]uint64, uint(xlen)) changed = true } if j >= len(v) { v = append(v, 0) changed = true } slh.ElemContainerState(j) v[uint(j)] = d.d.DecodeUint64() } if j < len(v) { v = v[:uint(j)] changed = true } else if j == 0 && v == nil { v = []uint64{} changed = true } slh.End() return v, changed } func (fastpathT) DecSliceUint64N(v []uint64, d *Decoder) { slh, containerLenS := d.decSliceHelperStart() if slh.IsNil { return } if containerLenS == 0 { slh.End() return } hasLen := containerLenS > 0 for j := 0; (hasLen && j < containerLenS) || !(hasLen || d.checkBreak()); j++ { if j >= len(v) { slh.arrayCannotExpand(hasLen, len(v), j, containerLenS) return } slh.ElemContainerState(j) v[uint(j)] = d.d.DecodeUint64() } slh.End() } func (d *Decoder) fastpathDecSliceIntR(f *codecFnInfo, rv reflect.Value) { var v []int switch rv.Kind() { case reflect.Ptr: vp := rv2i(rv).(*[]int) var changed bool if v, changed = fastpathTV.DecSliceIntY(*vp, d); changed { *vp = v } case reflect.Array: rvGetSlice4Array(rv, &v) fastpathTV.DecSliceIntN(v, d) default: fastpathTV.DecSliceIntN(rv2i(rv).([]int), d) } } func (f fastpathT) DecSliceIntX(vp *[]int, d *Decoder) { if v, changed := f.DecSliceIntY(*vp, d); changed { *vp = v } } func (fastpathT) DecSliceIntY(v []int, d *Decoder) (v2 []int, changed bool) { slh, containerLenS := d.decSliceHelperStart() if slh.IsNil { if v == nil { return } return nil, true } if containerLenS == 0 { if v == nil { v = []int{} } else if len(v) != 0 { v = v[:0] } slh.End() return v, true } hasLen := containerLenS > 0 var xlen int if hasLen { if containerLenS > cap(v) { xlen = decInferLen(containerLenS, d.h.MaxInitLen, 8) if xlen <= cap(v) { v = v[:uint(xlen)] } else { v = make([]int, uint(xlen)) } changed = true } else if containerLenS != len(v) { v = v[:containerLenS] changed = true } } var j int for j = 0; (hasLen && j < containerLenS) || !(hasLen || d.checkBreak()); j++ { if j == 0 && len(v) == 0 { // means hasLen == false xlen = decInferLen(containerLenS, d.h.MaxInitLen, 8) v = make([]int, uint(xlen)) changed = true } if j >= len(v) { v = append(v, 0) changed = true } slh.ElemContainerState(j) v[uint(j)] = int(chkOvf.IntV(d.d.DecodeInt64(), intBitsize)) } if j < len(v) { v = v[:uint(j)] changed = true } else if j == 0 && v == nil { v = []int{} changed = true } slh.End() return v, changed } func (fastpathT) DecSliceIntN(v []int, d *Decoder) { slh, containerLenS := d.decSliceHelperStart() if slh.IsNil { return } if containerLenS == 0 { slh.End() return } hasLen := containerLenS > 0 for j := 0; (hasLen && j < containerLenS) || !(hasLen || d.checkBreak()); j++ { if j >= len(v) { slh.arrayCannotExpand(hasLen, len(v), j, containerLenS) return } slh.ElemContainerState(j) v[uint(j)] = int(chkOvf.IntV(d.d.DecodeInt64(), intBitsize)) } slh.End() } func (d *Decoder) fastpathDecSliceInt32R(f *codecFnInfo, rv reflect.Value) { var v []int32 switch rv.Kind() { case reflect.Ptr: vp := rv2i(rv).(*[]int32) var changed bool if v, changed = fastpathTV.DecSliceInt32Y(*vp, d); changed { *vp = v } case reflect.Array: rvGetSlice4Array(rv, &v) fastpathTV.DecSliceInt32N(v, d) default: fastpathTV.DecSliceInt32N(rv2i(rv).([]int32), d) } } func (f fastpathT) DecSliceInt32X(vp *[]int32, d *Decoder) { if v, changed := f.DecSliceInt32Y(*vp, d); changed { *vp = v } } func (fastpathT) DecSliceInt32Y(v []int32, d *Decoder) (v2 []int32, changed bool) { slh, containerLenS := d.decSliceHelperStart() if slh.IsNil { if v == nil { return } return nil, true } if containerLenS == 0 { if v == nil { v = []int32{} } else if len(v) != 0 { v = v[:0] } slh.End() return v, true } hasLen := containerLenS > 0 var xlen int if hasLen { if containerLenS > cap(v) { xlen = decInferLen(containerLenS, d.h.MaxInitLen, 4) if xlen <= cap(v) { v = v[:uint(xlen)] } else { v = make([]int32, uint(xlen)) } changed = true } else if containerLenS != len(v) { v = v[:containerLenS] changed = true } } var j int for j = 0; (hasLen && j < containerLenS) || !(hasLen || d.checkBreak()); j++ { if j == 0 && len(v) == 0 { // means hasLen == false xlen = decInferLen(containerLenS, d.h.MaxInitLen, 4) v = make([]int32, uint(xlen)) changed = true } if j >= len(v) { v = append(v, 0) changed = true } slh.ElemContainerState(j) v[uint(j)] = int32(chkOvf.IntV(d.d.DecodeInt64(), 32)) } if j < len(v) { v = v[:uint(j)] changed = true } else if j == 0 && v == nil { v = []int32{} changed = true } slh.End() return v, changed } func (fastpathT) DecSliceInt32N(v []int32, d *Decoder) { slh, containerLenS := d.decSliceHelperStart() if slh.IsNil { return } if containerLenS == 0 { slh.End() return } hasLen := containerLenS > 0 for j := 0; (hasLen && j < containerLenS) || !(hasLen || d.checkBreak()); j++ { if j >= len(v) { slh.arrayCannotExpand(hasLen, len(v), j, containerLenS) return } slh.ElemContainerState(j) v[uint(j)] = int32(chkOvf.IntV(d.d.DecodeInt64(), 32)) } slh.End() } func (d *Decoder) fastpathDecSliceInt64R(f *codecFnInfo, rv reflect.Value) { var v []int64 switch rv.Kind() { case reflect.Ptr: vp := rv2i(rv).(*[]int64) var changed bool if v, changed = fastpathTV.DecSliceInt64Y(*vp, d); changed { *vp = v } case reflect.Array: rvGetSlice4Array(rv, &v) fastpathTV.DecSliceInt64N(v, d) default: fastpathTV.DecSliceInt64N(rv2i(rv).([]int64), d) } } func (f fastpathT) DecSliceInt64X(vp *[]int64, d *Decoder) { if v, changed := f.DecSliceInt64Y(*vp, d); changed { *vp = v } } func (fastpathT) DecSliceInt64Y(v []int64, d *Decoder) (v2 []int64, changed bool) { slh, containerLenS := d.decSliceHelperStart() if slh.IsNil { if v == nil { return } return nil, true } if containerLenS == 0 { if v == nil { v = []int64{} } else if len(v) != 0 { v = v[:0] } slh.End() return v, true } hasLen := containerLenS > 0 var xlen int if hasLen { if containerLenS > cap(v) { xlen = decInferLen(containerLenS, d.h.MaxInitLen, 8) if xlen <= cap(v) { v = v[:uint(xlen)] } else { v = make([]int64, uint(xlen)) } changed = true } else if containerLenS != len(v) { v = v[:containerLenS] changed = true } } var j int for j = 0; (hasLen && j < containerLenS) || !(hasLen || d.checkBreak()); j++ { if j == 0 && len(v) == 0 { // means hasLen == false xlen = decInferLen(containerLenS, d.h.MaxInitLen, 8) v = make([]int64, uint(xlen)) changed = true } if j >= len(v) { v = append(v, 0) changed = true } slh.ElemContainerState(j) v[uint(j)] = d.d.DecodeInt64() } if j < len(v) { v = v[:uint(j)] changed = true } else if j == 0 && v == nil { v = []int64{} changed = true } slh.End() return v, changed } func (fastpathT) DecSliceInt64N(v []int64, d *Decoder) { slh, containerLenS := d.decSliceHelperStart() if slh.IsNil { return } if containerLenS == 0 { slh.End() return } hasLen := containerLenS > 0 for j := 0; (hasLen && j < containerLenS) || !(hasLen || d.checkBreak()); j++ { if j >= len(v) { slh.arrayCannotExpand(hasLen, len(v), j, containerLenS) return } slh.ElemContainerState(j) v[uint(j)] = d.d.DecodeInt64() } slh.End() } func (d *Decoder) fastpathDecSliceBoolR(f *codecFnInfo, rv reflect.Value) { var v []bool switch rv.Kind() { case reflect.Ptr: vp := rv2i(rv).(*[]bool) var changed bool if v, changed = fastpathTV.DecSliceBoolY(*vp, d); changed { *vp = v } case reflect.Array: rvGetSlice4Array(rv, &v) fastpathTV.DecSliceBoolN(v, d) default: fastpathTV.DecSliceBoolN(rv2i(rv).([]bool), d) } } func (f fastpathT) DecSliceBoolX(vp *[]bool, d *Decoder) { if v, changed := f.DecSliceBoolY(*vp, d); changed { *vp = v } } func (fastpathT) DecSliceBoolY(v []bool, d *Decoder) (v2 []bool, changed bool) { slh, containerLenS := d.decSliceHelperStart() if slh.IsNil { if v == nil { return } return nil, true } if containerLenS == 0 { if v == nil { v = []bool{} } else if len(v) != 0 { v = v[:0] } slh.End() return v, true } hasLen := containerLenS > 0 var xlen int if hasLen { if containerLenS > cap(v) { xlen = decInferLen(containerLenS, d.h.MaxInitLen, 1) if xlen <= cap(v) { v = v[:uint(xlen)] } else { v = make([]bool, uint(xlen)) } changed = true } else if containerLenS != len(v) { v = v[:containerLenS] changed = true } } var j int for j = 0; (hasLen && j < containerLenS) || !(hasLen || d.checkBreak()); j++ { if j == 0 && len(v) == 0 { // means hasLen == false xlen = decInferLen(containerLenS, d.h.MaxInitLen, 1) v = make([]bool, uint(xlen)) changed = true } if j >= len(v) { v = append(v, false) changed = true } slh.ElemContainerState(j) v[uint(j)] = d.d.DecodeBool() } if j < len(v) { v = v[:uint(j)] changed = true } else if j == 0 && v == nil { v = []bool{} changed = true } slh.End() return v, changed } func (fastpathT) DecSliceBoolN(v []bool, d *Decoder) { slh, containerLenS := d.decSliceHelperStart() if slh.IsNil { return } if containerLenS == 0 { slh.End() return } hasLen := containerLenS > 0 for j := 0; (hasLen && j < containerLenS) || !(hasLen || d.checkBreak()); j++ { if j >= len(v) { slh.arrayCannotExpand(hasLen, len(v), j, containerLenS) return } slh.ElemContainerState(j) v[uint(j)] = d.d.DecodeBool() } slh.End() } func (d *Decoder) fastpathDecMapStringIntfR(f *codecFnInfo, rv reflect.Value) { 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.h.MaxInitLen, 32)) } if containerLen != 0 { fastpathTV.DecMapStringIntfL(*vp, containerLen, d) } } else if containerLen != 0 { fastpathTV.DecMapStringIntfL(rv2i(rv).(map[string]interface{}), containerLen, d) } d.mapEnd() } func (f fastpathT) DecMapStringIntfX(vp *map[string]interface{}, d *Decoder) { containerLen := d.mapStart(d.d.ReadMapStart()) if containerLen == containerLenNil { *vp = nil } else { if *vp == nil { *vp = make(map[string]interface{}, decInferLen(containerLen, d.h.MaxInitLen, 32)) } if containerLen != 0 { f.DecMapStringIntfL(*vp, containerLen, d) } d.mapEnd() } } func (fastpathT) DecMapStringIntfL(v map[string]interface{}, containerLen int, d *Decoder) { if v == nil { d.errorf("cannot decode into nil map[string]interface{} given stream length: %v", containerLen) return } mapGet := v != nil && !d.h.MapValueReset && !d.h.InterfaceReset var mk string var mv interface{} hasLen := containerLen > 0 for j := 0; (hasLen && j < containerLen) || !(hasLen || d.checkBreak()); j++ { d.mapElemKey() mk = d.stringZC(d.d.DecodeStringAsBytes()) d.mapElemValue() if mapGet { mv = v[mk] } else { mv = nil } d.decode(&mv) v[mk] = mv } } func (d *Decoder) fastpathDecMapStringStringR(f *codecFnInfo, rv reflect.Value) { 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.h.MaxInitLen, 32)) } if containerLen != 0 { fastpathTV.DecMapStringStringL(*vp, containerLen, d) } } else if containerLen != 0 { fastpathTV.DecMapStringStringL(rv2i(rv).(map[string]string), containerLen, d) } d.mapEnd() } func (f fastpathT) DecMapStringStringX(vp *map[string]string, d *Decoder) { containerLen := d.mapStart(d.d.ReadMapStart()) if containerLen == containerLenNil { *vp = nil } else { if *vp == nil { *vp = make(map[string]string, decInferLen(containerLen, d.h.MaxInitLen, 32)) } if containerLen != 0 { f.DecMapStringStringL(*vp, containerLen, d) } d.mapEnd() } } func (fastpathT) DecMapStringStringL(v map[string]string, containerLen int, d *Decoder) { if v == nil { d.errorf("cannot decode into nil map[string]string given stream length: %v", containerLen) return } var mk string var mv string hasLen := containerLen > 0 for j := 0; (hasLen && j < containerLen) || !(hasLen || d.checkBreak()); j++ { d.mapElemKey() mk = d.stringZC(d.d.DecodeStringAsBytes()) d.mapElemValue() mv = d.stringZC(d.d.DecodeStringAsBytes()) v[mk] = mv } } func (d *Decoder) fastpathDecMapStringBytesR(f *codecFnInfo, rv reflect.Value) { 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.h.MaxInitLen, 40)) } if containerLen != 0 { fastpathTV.DecMapStringBytesL(*vp, containerLen, d) } } else if containerLen != 0 { fastpathTV.DecMapStringBytesL(rv2i(rv).(map[string][]byte), containerLen, d) } d.mapEnd() } func (f fastpathT) DecMapStringBytesX(vp *map[string][]byte, d *Decoder) { containerLen := d.mapStart(d.d.ReadMapStart()) if containerLen == containerLenNil { *vp = nil } else { if *vp == nil { *vp = make(map[string][]byte, decInferLen(containerLen, d.h.MaxInitLen, 40)) } if containerLen != 0 { f.DecMapStringBytesL(*vp, containerLen, d) } d.mapEnd() } } func (fastpathT) DecMapStringBytesL(v map[string][]byte, containerLen int, d *Decoder) { if v == nil { d.errorf("cannot decode into nil map[string][]byte given stream length: %v", containerLen) return } mapGet := v != nil && !d.h.MapValueReset var mk string var mv []byte hasLen := containerLen > 0 for j := 0; (hasLen && j < containerLen) || !(hasLen || d.checkBreak()); j++ { d.mapElemKey() mk = d.stringZC(d.d.DecodeStringAsBytes()) d.mapElemValue() if mapGet { mv = v[mk] } else { mv = nil } mv = d.decodeBytesInto(mv) v[mk] = mv } } func (d *Decoder) fastpathDecMapStringUint8R(f *codecFnInfo, rv reflect.Value) { 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.h.MaxInitLen, 17)) } if containerLen != 0 { fastpathTV.DecMapStringUint8L(*vp, containerLen, d) } } else if containerLen != 0 { fastpathTV.DecMapStringUint8L(rv2i(rv).(map[string]uint8), containerLen, d) } d.mapEnd() } func (f fastpathT) DecMapStringUint8X(vp *map[string]uint8, d *Decoder) { containerLen := d.mapStart(d.d.ReadMapStart()) if containerLen == containerLenNil { *vp = nil } else { if *vp == nil { *vp = make(map[string]uint8, decInferLen(containerLen, d.h.MaxInitLen, 17)) } if containerLen != 0 { f.DecMapStringUint8L(*vp, containerLen, d) } d.mapEnd() } } func (fastpathT) DecMapStringUint8L(v map[string]uint8, containerLen int, d *Decoder) { if v == nil { d.errorf("cannot decode into nil map[string]uint8 given stream length: %v", containerLen) return } var mk string var mv uint8 hasLen := containerLen > 0 for j := 0; (hasLen && j < containerLen) || !(hasLen || d.checkBreak()); j++ { d.mapElemKey() mk = d.stringZC(d.d.DecodeStringAsBytes()) d.mapElemValue() mv = uint8(chkOvf.UintV(d.d.DecodeUint64(), 8)) v[mk] = mv } } func (d *Decoder) fastpathDecMapStringUint64R(f *codecFnInfo, rv reflect.Value) { 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.h.MaxInitLen, 24)) } if containerLen != 0 { fastpathTV.DecMapStringUint64L(*vp, containerLen, d) } } else if containerLen != 0 { fastpathTV.DecMapStringUint64L(rv2i(rv).(map[string]uint64), containerLen, d) } d.mapEnd() } func (f fastpathT) DecMapStringUint64X(vp *map[string]uint64, d *Decoder) { containerLen := d.mapStart(d.d.ReadMapStart()) if containerLen == containerLenNil { *vp = nil } else { if *vp == nil { *vp = make(map[string]uint64, decInferLen(containerLen, d.h.MaxInitLen, 24)) } if containerLen != 0 { f.DecMapStringUint64L(*vp, containerLen, d) } d.mapEnd() } } func (fastpathT) DecMapStringUint64L(v map[string]uint64, containerLen int, d *Decoder) { if v == nil { d.errorf("cannot decode into nil map[string]uint64 given stream length: %v", containerLen) return } var mk string var mv uint64 hasLen := containerLen > 0 for j := 0; (hasLen && j < containerLen) || !(hasLen || d.checkBreak()); j++ { d.mapElemKey() mk = d.stringZC(d.d.DecodeStringAsBytes()) d.mapElemValue() mv = d.d.DecodeUint64() v[mk] = mv } } func (d *Decoder) fastpathDecMapStringIntR(f *codecFnInfo, rv reflect.Value) { 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.h.MaxInitLen, 24)) } if containerLen != 0 { fastpathTV.DecMapStringIntL(*vp, containerLen, d) } } else if containerLen != 0 { fastpathTV.DecMapStringIntL(rv2i(rv).(map[string]int), containerLen, d) } d.mapEnd() } func (f fastpathT) DecMapStringIntX(vp *map[string]int, d *Decoder) { containerLen := d.mapStart(d.d.ReadMapStart()) if containerLen == containerLenNil { *vp = nil } else { if *vp == nil { *vp = make(map[string]int, decInferLen(containerLen, d.h.MaxInitLen, 24)) } if containerLen != 0 { f.DecMapStringIntL(*vp, containerLen, d) } d.mapEnd() } } func (fastpathT) DecMapStringIntL(v map[string]int, containerLen int, d *Decoder) { if v == nil { d.errorf("cannot decode into nil map[string]int given stream length: %v", containerLen) return } var mk string var mv int hasLen := containerLen > 0 for j := 0; (hasLen && j < containerLen) || !(hasLen || d.checkBreak()); j++ { d.mapElemKey() mk = d.stringZC(d.d.DecodeStringAsBytes()) d.mapElemValue() mv = int(chkOvf.IntV(d.d.DecodeInt64(), intBitsize)) v[mk] = mv } } func (d *Decoder) fastpathDecMapStringInt32R(f *codecFnInfo, rv reflect.Value) { 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.h.MaxInitLen, 20)) } if containerLen != 0 { fastpathTV.DecMapStringInt32L(*vp, containerLen, d) } } else if containerLen != 0 { fastpathTV.DecMapStringInt32L(rv2i(rv).(map[string]int32), containerLen, d) } d.mapEnd() } func (f fastpathT) DecMapStringInt32X(vp *map[string]int32, d *Decoder) { containerLen := d.mapStart(d.d.ReadMapStart()) if containerLen == containerLenNil { *vp = nil } else { if *vp == nil { *vp = make(map[string]int32, decInferLen(containerLen, d.h.MaxInitLen, 20)) } if containerLen != 0 { f.DecMapStringInt32L(*vp, containerLen, d) } d.mapEnd() } } func (fastpathT) DecMapStringInt32L(v map[string]int32, containerLen int, d *Decoder) { if v == nil { d.errorf("cannot decode into nil map[string]int32 given stream length: %v", containerLen) return } var mk string var mv int32 hasLen := containerLen > 0 for j := 0; (hasLen && j < containerLen) || !(hasLen || d.checkBreak()); j++ { d.mapElemKey() mk = d.stringZC(d.d.DecodeStringAsBytes()) d.mapElemValue() mv = int32(chkOvf.IntV(d.d.DecodeInt64(), 32)) v[mk] = mv } } func (d *Decoder) fastpathDecMapStringFloat64R(f *codecFnInfo, rv reflect.Value) { 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.h.MaxInitLen, 24)) } if containerLen != 0 { fastpathTV.DecMapStringFloat64L(*vp, containerLen, d) } } else if containerLen != 0 { fastpathTV.DecMapStringFloat64L(rv2i(rv).(map[string]float64), containerLen, d) } d.mapEnd() } func (f fastpathT) DecMapStringFloat64X(vp *map[string]float64, d *Decoder) { containerLen := d.mapStart(d.d.ReadMapStart()) if containerLen == containerLenNil { *vp = nil } else { if *vp == nil { *vp = make(map[string]float64, decInferLen(containerLen, d.h.MaxInitLen, 24)) } if containerLen != 0 { f.DecMapStringFloat64L(*vp, containerLen, d) } d.mapEnd() } } func (fastpathT) DecMapStringFloat64L(v map[string]float64, containerLen int, d *Decoder) { if v == nil { d.errorf("cannot decode into nil map[string]float64 given stream length: %v", containerLen) return } var mk string var mv float64 hasLen := containerLen > 0 for j := 0; (hasLen && j < containerLen) || !(hasLen || d.checkBreak()); j++ { d.mapElemKey() mk = d.stringZC(d.d.DecodeStringAsBytes()) d.mapElemValue() mv = d.d.DecodeFloat64() v[mk] = mv } } func (d *Decoder) fastpathDecMapStringBoolR(f *codecFnInfo, rv reflect.Value) { 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.h.MaxInitLen, 17)) } if containerLen != 0 { fastpathTV.DecMapStringBoolL(*vp, containerLen, d) } } else if containerLen != 0 { fastpathTV.DecMapStringBoolL(rv2i(rv).(map[string]bool), containerLen, d) } d.mapEnd() } func (f fastpathT) DecMapStringBoolX(vp *map[string]bool, d *Decoder) { containerLen := d.mapStart(d.d.ReadMapStart()) if containerLen == containerLenNil { *vp = nil } else { if *vp == nil { *vp = make(map[string]bool, decInferLen(containerLen, d.h.MaxInitLen, 17)) } if containerLen != 0 { f.DecMapStringBoolL(*vp, containerLen, d) } d.mapEnd() } } func (fastpathT) DecMapStringBoolL(v map[string]bool, containerLen int, d *Decoder) { if v == nil { d.errorf("cannot decode into nil map[string]bool given stream length: %v", containerLen) return } var mk string var mv bool hasLen := containerLen > 0 for j := 0; (hasLen && j < containerLen) || !(hasLen || d.checkBreak()); j++ { d.mapElemKey() mk = d.stringZC(d.d.DecodeStringAsBytes()) d.mapElemValue() mv = d.d.DecodeBool() v[mk] = mv } } func (d *Decoder) fastpathDecMapUint8IntfR(f *codecFnInfo, rv reflect.Value) { 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.h.MaxInitLen, 17)) } if containerLen != 0 { fastpathTV.DecMapUint8IntfL(*vp, containerLen, d) } } else if containerLen != 0 { fastpathTV.DecMapUint8IntfL(rv2i(rv).(map[uint8]interface{}), containerLen, d) } d.mapEnd() } func (f fastpathT) DecMapUint8IntfX(vp *map[uint8]interface{}, d *Decoder) { containerLen := d.mapStart(d.d.ReadMapStart()) if containerLen == containerLenNil { *vp = nil } else { if *vp == nil { *vp = make(map[uint8]interface{}, decInferLen(containerLen, d.h.MaxInitLen, 17)) } if containerLen != 0 { f.DecMapUint8IntfL(*vp, containerLen, d) } d.mapEnd() } } func (fastpathT) DecMapUint8IntfL(v map[uint8]interface{}, containerLen int, d *Decoder) { if v == nil { d.errorf("cannot decode into nil map[uint8]interface{} given stream length: %v", containerLen) return } mapGet := v != nil && !d.h.MapValueReset && !d.h.InterfaceReset var mk uint8 var mv interface{} hasLen := containerLen > 0 for j := 0; (hasLen && j < containerLen) || !(hasLen || d.checkBreak()); j++ { d.mapElemKey() 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) fastpathDecMapUint8StringR(f *codecFnInfo, rv reflect.Value) { 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.h.MaxInitLen, 17)) } if containerLen != 0 { fastpathTV.DecMapUint8StringL(*vp, containerLen, d) } } else if containerLen != 0 { fastpathTV.DecMapUint8StringL(rv2i(rv).(map[uint8]string), containerLen, d) } d.mapEnd() } func (f fastpathT) DecMapUint8StringX(vp *map[uint8]string, d *Decoder) { containerLen := d.mapStart(d.d.ReadMapStart()) if containerLen == containerLenNil { *vp = nil } else { if *vp == nil { *vp = make(map[uint8]string, decInferLen(containerLen, d.h.MaxInitLen, 17)) } if containerLen != 0 { f.DecMapUint8StringL(*vp, containerLen, d) } d.mapEnd() } } func (fastpathT) DecMapUint8StringL(v map[uint8]string, containerLen int, d *Decoder) { if v == nil { d.errorf("cannot decode into nil map[uint8]string given stream length: %v", containerLen) return } var mk uint8 var mv string hasLen := containerLen > 0 for j := 0; (hasLen && j < containerLen) || !(hasLen || d.checkBreak()); j++ { d.mapElemKey() mk = uint8(chkOvf.UintV(d.d.DecodeUint64(), 8)) d.mapElemValue() mv = d.stringZC(d.d.DecodeStringAsBytes()) v[mk] = mv } } func (d *Decoder) fastpathDecMapUint8BytesR(f *codecFnInfo, rv reflect.Value) { 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.h.MaxInitLen, 25)) } if containerLen != 0 { fastpathTV.DecMapUint8BytesL(*vp, containerLen, d) } } else if containerLen != 0 { fastpathTV.DecMapUint8BytesL(rv2i(rv).(map[uint8][]byte), containerLen, d) } d.mapEnd() } func (f fastpathT) DecMapUint8BytesX(vp *map[uint8][]byte, d *Decoder) { containerLen := d.mapStart(d.d.ReadMapStart()) if containerLen == containerLenNil { *vp = nil } else { if *vp == nil { *vp = make(map[uint8][]byte, decInferLen(containerLen, d.h.MaxInitLen, 25)) } if containerLen != 0 { f.DecMapUint8BytesL(*vp, containerLen, d) } d.mapEnd() } } func (fastpathT) DecMapUint8BytesL(v map[uint8][]byte, containerLen int, d *Decoder) { if v == nil { d.errorf("cannot decode into nil map[uint8][]byte given stream length: %v", containerLen) return } mapGet := v != nil && !d.h.MapValueReset var mk uint8 var mv []byte hasLen := containerLen > 0 for j := 0; (hasLen && j < containerLen) || !(hasLen || d.checkBreak()); j++ { d.mapElemKey() mk = uint8(chkOvf.UintV(d.d.DecodeUint64(), 8)) d.mapElemValue() if mapGet { mv = v[mk] } else { mv = nil } mv = d.decodeBytesInto(mv) v[mk] = mv } } func (d *Decoder) fastpathDecMapUint8Uint8R(f *codecFnInfo, rv reflect.Value) { 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.h.MaxInitLen, 2)) } if containerLen != 0 { fastpathTV.DecMapUint8Uint8L(*vp, containerLen, d) } } else if containerLen != 0 { fastpathTV.DecMapUint8Uint8L(rv2i(rv).(map[uint8]uint8), containerLen, d) } d.mapEnd() } func (f fastpathT) DecMapUint8Uint8X(vp *map[uint8]uint8, d *Decoder) { containerLen := d.mapStart(d.d.ReadMapStart()) if containerLen == containerLenNil { *vp = nil } else { if *vp == nil { *vp = make(map[uint8]uint8, decInferLen(containerLen, d.h.MaxInitLen, 2)) } if containerLen != 0 { f.DecMapUint8Uint8L(*vp, containerLen, d) } d.mapEnd() } } func (fastpathT) DecMapUint8Uint8L(v map[uint8]uint8, containerLen int, d *Decoder) { if v == nil { d.errorf("cannot decode into nil map[uint8]uint8 given stream length: %v", containerLen) return } var mk uint8 var mv uint8 hasLen := containerLen > 0 for j := 0; (hasLen && j < containerLen) || !(hasLen || d.checkBreak()); j++ { d.mapElemKey() mk = uint8(chkOvf.UintV(d.d.DecodeUint64(), 8)) d.mapElemValue() mv = uint8(chkOvf.UintV(d.d.DecodeUint64(), 8)) v[mk] = mv } } func (d *Decoder) fastpathDecMapUint8Uint64R(f *codecFnInfo, rv reflect.Value) { 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.h.MaxInitLen, 9)) } if containerLen != 0 { fastpathTV.DecMapUint8Uint64L(*vp, containerLen, d) } } else if containerLen != 0 { fastpathTV.DecMapUint8Uint64L(rv2i(rv).(map[uint8]uint64), containerLen, d) } d.mapEnd() } func (f fastpathT) DecMapUint8Uint64X(vp *map[uint8]uint64, d *Decoder) { containerLen := d.mapStart(d.d.ReadMapStart()) if containerLen == containerLenNil { *vp = nil } else { if *vp == nil { *vp = make(map[uint8]uint64, decInferLen(containerLen, d.h.MaxInitLen, 9)) } if containerLen != 0 { f.DecMapUint8Uint64L(*vp, containerLen, d) } d.mapEnd() } } func (fastpathT) DecMapUint8Uint64L(v map[uint8]uint64, containerLen int, d *Decoder) { if v == nil { d.errorf("cannot decode into nil map[uint8]uint64 given stream length: %v", containerLen) return } var mk uint8 var mv uint64 hasLen := containerLen > 0 for j := 0; (hasLen && j < containerLen) || !(hasLen || d.checkBreak()); j++ { d.mapElemKey() mk = uint8(chkOvf.UintV(d.d.DecodeUint64(), 8)) d.mapElemValue() mv = d.d.DecodeUint64() v[mk] = mv } } func (d *Decoder) fastpathDecMapUint8IntR(f *codecFnInfo, rv reflect.Value) { 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.h.MaxInitLen, 9)) } if containerLen != 0 { fastpathTV.DecMapUint8IntL(*vp, containerLen, d) } } else if containerLen != 0 { fastpathTV.DecMapUint8IntL(rv2i(rv).(map[uint8]int), containerLen, d) } d.mapEnd() } func (f fastpathT) DecMapUint8IntX(vp *map[uint8]int, d *Decoder) { containerLen := d.mapStart(d.d.ReadMapStart()) if containerLen == containerLenNil { *vp = nil } else { if *vp == nil { *vp = make(map[uint8]int, decInferLen(containerLen, d.h.MaxInitLen, 9)) } if containerLen != 0 { f.DecMapUint8IntL(*vp, containerLen, d) } d.mapEnd() } } func (fastpathT) DecMapUint8IntL(v map[uint8]int, containerLen int, d *Decoder) { if v == nil { d.errorf("cannot decode into nil map[uint8]int given stream length: %v", containerLen) return } var mk uint8 var mv int hasLen := containerLen > 0 for j := 0; (hasLen && j < containerLen) || !(hasLen || d.checkBreak()); j++ { d.mapElemKey() mk = uint8(chkOvf.UintV(d.d.DecodeUint64(), 8)) d.mapElemValue() mv = int(chkOvf.IntV(d.d.DecodeInt64(), intBitsize)) v[mk] = mv } } func (d *Decoder) fastpathDecMapUint8Int32R(f *codecFnInfo, rv reflect.Value) { 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.h.MaxInitLen, 5)) } if containerLen != 0 { fastpathTV.DecMapUint8Int32L(*vp, containerLen, d) } } else if containerLen != 0 { fastpathTV.DecMapUint8Int32L(rv2i(rv).(map[uint8]int32), containerLen, d) } d.mapEnd() } func (f fastpathT) DecMapUint8Int32X(vp *map[uint8]int32, d *Decoder) { containerLen := d.mapStart(d.d.ReadMapStart()) if containerLen == containerLenNil { *vp = nil } else { if *vp == nil { *vp = make(map[uint8]int32, decInferLen(containerLen, d.h.MaxInitLen, 5)) } if containerLen != 0 { f.DecMapUint8Int32L(*vp, containerLen, d) } d.mapEnd() } } func (fastpathT) DecMapUint8Int32L(v map[uint8]int32, containerLen int, d *Decoder) { if v == nil { d.errorf("cannot decode into nil map[uint8]int32 given stream length: %v", containerLen) return } var mk uint8 var mv int32 hasLen := containerLen > 0 for j := 0; (hasLen && j < containerLen) || !(hasLen || d.checkBreak()); j++ { d.mapElemKey() mk = uint8(chkOvf.UintV(d.d.DecodeUint64(), 8)) d.mapElemValue() mv = int32(chkOvf.IntV(d.d.DecodeInt64(), 32)) v[mk] = mv } } func (d *Decoder) fastpathDecMapUint8Float64R(f *codecFnInfo, rv reflect.Value) { 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.h.MaxInitLen, 9)) } if containerLen != 0 { fastpathTV.DecMapUint8Float64L(*vp, containerLen, d) } } else if containerLen != 0 { fastpathTV.DecMapUint8Float64L(rv2i(rv).(map[uint8]float64), containerLen, d) } d.mapEnd() } func (f fastpathT) DecMapUint8Float64X(vp *map[uint8]float64, d *Decoder) { containerLen := d.mapStart(d.d.ReadMapStart()) if containerLen == containerLenNil { *vp = nil } else { if *vp == nil { *vp = make(map[uint8]float64, decInferLen(containerLen, d.h.MaxInitLen, 9)) } if containerLen != 0 { f.DecMapUint8Float64L(*vp, containerLen, d) } d.mapEnd() } } func (fastpathT) DecMapUint8Float64L(v map[uint8]float64, containerLen int, d *Decoder) { if v == nil { d.errorf("cannot decode into nil map[uint8]float64 given stream length: %v", containerLen) return } var mk uint8 var mv float64 hasLen := containerLen > 0 for j := 0; (hasLen && j < containerLen) || !(hasLen || d.checkBreak()); j++ { d.mapElemKey() mk = uint8(chkOvf.UintV(d.d.DecodeUint64(), 8)) d.mapElemValue() mv = d.d.DecodeFloat64() v[mk] = mv } } func (d *Decoder) fastpathDecMapUint8BoolR(f *codecFnInfo, rv reflect.Value) { 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.h.MaxInitLen, 2)) } if containerLen != 0 { fastpathTV.DecMapUint8BoolL(*vp, containerLen, d) } } else if containerLen != 0 { fastpathTV.DecMapUint8BoolL(rv2i(rv).(map[uint8]bool), containerLen, d) } d.mapEnd() } func (f fastpathT) DecMapUint8BoolX(vp *map[uint8]bool, d *Decoder) { containerLen := d.mapStart(d.d.ReadMapStart()) if containerLen == containerLenNil { *vp = nil } else { if *vp == nil { *vp = make(map[uint8]bool, decInferLen(containerLen, d.h.MaxInitLen, 2)) } if containerLen != 0 { f.DecMapUint8BoolL(*vp, containerLen, d) } d.mapEnd() } } func (fastpathT) DecMapUint8BoolL(v map[uint8]bool, containerLen int, d *Decoder) { if v == nil { d.errorf("cannot decode into nil map[uint8]bool given stream length: %v", containerLen) return } var mk uint8 var mv bool hasLen := containerLen > 0 for j := 0; (hasLen && j < containerLen) || !(hasLen || d.checkBreak()); j++ { d.mapElemKey() mk = uint8(chkOvf.UintV(d.d.DecodeUint64(), 8)) d.mapElemValue() mv = d.d.DecodeBool() v[mk] = mv } } func (d *Decoder) fastpathDecMapUint64IntfR(f *codecFnInfo, rv reflect.Value) { 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.h.MaxInitLen, 24)) } if containerLen != 0 { fastpathTV.DecMapUint64IntfL(*vp, containerLen, d) } } else if containerLen != 0 { fastpathTV.DecMapUint64IntfL(rv2i(rv).(map[uint64]interface{}), containerLen, d) } d.mapEnd() } func (f fastpathT) DecMapUint64IntfX(vp *map[uint64]interface{}, d *Decoder) { containerLen := d.mapStart(d.d.ReadMapStart()) if containerLen == containerLenNil { *vp = nil } else { if *vp == nil { *vp = make(map[uint64]interface{}, decInferLen(containerLen, d.h.MaxInitLen, 24)) } if containerLen != 0 { f.DecMapUint64IntfL(*vp, containerLen, d) } d.mapEnd() } } func (fastpathT) DecMapUint64IntfL(v map[uint64]interface{}, containerLen int, d *Decoder) { if v == nil { d.errorf("cannot decode into nil map[uint64]interface{} given stream length: %v", containerLen) return } mapGet := v != nil && !d.h.MapValueReset && !d.h.InterfaceReset var mk uint64 var mv interface{} hasLen := containerLen > 0 for j := 0; (hasLen && j < containerLen) || !(hasLen || d.checkBreak()); j++ { d.mapElemKey() mk = d.d.DecodeUint64() d.mapElemValue() if mapGet { mv = v[mk] } else { mv = nil } d.decode(&mv) v[mk] = mv } } func (d *Decoder) fastpathDecMapUint64StringR(f *codecFnInfo, rv reflect.Value) { 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.h.MaxInitLen, 24)) } if containerLen != 0 { fastpathTV.DecMapUint64StringL(*vp, containerLen, d) } } else if containerLen != 0 { fastpathTV.DecMapUint64StringL(rv2i(rv).(map[uint64]string), containerLen, d) } d.mapEnd() } func (f fastpathT) DecMapUint64StringX(vp *map[uint64]string, d *Decoder) { containerLen := d.mapStart(d.d.ReadMapStart()) if containerLen == containerLenNil { *vp = nil } else { if *vp == nil { *vp = make(map[uint64]string, decInferLen(containerLen, d.h.MaxInitLen, 24)) } if containerLen != 0 { f.DecMapUint64StringL(*vp, containerLen, d) } d.mapEnd() } } func (fastpathT) DecMapUint64StringL(v map[uint64]string, containerLen int, d *Decoder) { if v == nil { d.errorf("cannot decode into nil map[uint64]string given stream length: %v", containerLen) return } var mk uint64 var mv string hasLen := containerLen > 0 for j := 0; (hasLen && j < containerLen) || !(hasLen || d.checkBreak()); j++ { d.mapElemKey() mk = d.d.DecodeUint64() d.mapElemValue() mv = d.stringZC(d.d.DecodeStringAsBytes()) v[mk] = mv } } func (d *Decoder) fastpathDecMapUint64BytesR(f *codecFnInfo, rv reflect.Value) { 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.h.MaxInitLen, 32)) } if containerLen != 0 { fastpathTV.DecMapUint64BytesL(*vp, containerLen, d) } } else if containerLen != 0 { fastpathTV.DecMapUint64BytesL(rv2i(rv).(map[uint64][]byte), containerLen, d) } d.mapEnd() } func (f fastpathT) DecMapUint64BytesX(vp *map[uint64][]byte, d *Decoder) { containerLen := d.mapStart(d.d.ReadMapStart()) if containerLen == containerLenNil { *vp = nil } else { if *vp == nil { *vp = make(map[uint64][]byte, decInferLen(containerLen, d.h.MaxInitLen, 32)) } if containerLen != 0 { f.DecMapUint64BytesL(*vp, containerLen, d) } d.mapEnd() } } func (fastpathT) DecMapUint64BytesL(v map[uint64][]byte, containerLen int, d *Decoder) { if v == nil { d.errorf("cannot decode into nil map[uint64][]byte given stream length: %v", containerLen) return } mapGet := v != nil && !d.h.MapValueReset var mk uint64 var mv []byte hasLen := containerLen > 0 for j := 0; (hasLen && j < containerLen) || !(hasLen || d.checkBreak()); j++ { d.mapElemKey() mk = d.d.DecodeUint64() d.mapElemValue() if mapGet { mv = v[mk] } else { mv = nil } mv = d.decodeBytesInto(mv) v[mk] = mv } } func (d *Decoder) fastpathDecMapUint64Uint8R(f *codecFnInfo, rv reflect.Value) { 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.h.MaxInitLen, 9)) } if containerLen != 0 { fastpathTV.DecMapUint64Uint8L(*vp, containerLen, d) } } else if containerLen != 0 { fastpathTV.DecMapUint64Uint8L(rv2i(rv).(map[uint64]uint8), containerLen, d) } d.mapEnd() } func (f fastpathT) DecMapUint64Uint8X(vp *map[uint64]uint8, d *Decoder) { containerLen := d.mapStart(d.d.ReadMapStart()) if containerLen == containerLenNil { *vp = nil } else { if *vp == nil { *vp = make(map[uint64]uint8, decInferLen(containerLen, d.h.MaxInitLen, 9)) } if containerLen != 0 { f.DecMapUint64Uint8L(*vp, containerLen, d) } d.mapEnd() } } func (fastpathT) DecMapUint64Uint8L(v map[uint64]uint8, containerLen int, d *Decoder) { if v == nil { d.errorf("cannot decode into nil map[uint64]uint8 given stream length: %v", containerLen) return } var mk uint64 var mv uint8 hasLen := containerLen > 0 for j := 0; (hasLen && j < containerLen) || !(hasLen || d.checkBreak()); j++ { d.mapElemKey() mk = d.d.DecodeUint64() d.mapElemValue() mv = uint8(chkOvf.UintV(d.d.DecodeUint64(), 8)) v[mk] = mv } } func (d *Decoder) fastpathDecMapUint64Uint64R(f *codecFnInfo, rv reflect.Value) { 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.h.MaxInitLen, 16)) } if containerLen != 0 { fastpathTV.DecMapUint64Uint64L(*vp, containerLen, d) } } else if containerLen != 0 { fastpathTV.DecMapUint64Uint64L(rv2i(rv).(map[uint64]uint64), containerLen, d) } d.mapEnd() } func (f fastpathT) DecMapUint64Uint64X(vp *map[uint64]uint64, d *Decoder) { containerLen := d.mapStart(d.d.ReadMapStart()) if containerLen == containerLenNil { *vp = nil } else { if *vp == nil { *vp = make(map[uint64]uint64, decInferLen(containerLen, d.h.MaxInitLen, 16)) } if containerLen != 0 { f.DecMapUint64Uint64L(*vp, containerLen, d) } d.mapEnd() } } func (fastpathT) DecMapUint64Uint64L(v map[uint64]uint64, containerLen int, d *Decoder) { if v == nil { d.errorf("cannot decode into nil map[uint64]uint64 given stream length: %v", containerLen) return } var mk uint64 var mv uint64 hasLen := containerLen > 0 for j := 0; (hasLen && j < containerLen) || !(hasLen || d.checkBreak()); j++ { d.mapElemKey() mk = d.d.DecodeUint64() d.mapElemValue() mv = d.d.DecodeUint64() v[mk] = mv } } func (d *Decoder) fastpathDecMapUint64IntR(f *codecFnInfo, rv reflect.Value) { 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.h.MaxInitLen, 16)) } if containerLen != 0 { fastpathTV.DecMapUint64IntL(*vp, containerLen, d) } } else if containerLen != 0 { fastpathTV.DecMapUint64IntL(rv2i(rv).(map[uint64]int), containerLen, d) } d.mapEnd() } func (f fastpathT) DecMapUint64IntX(vp *map[uint64]int, d *Decoder) { containerLen := d.mapStart(d.d.ReadMapStart()) if containerLen == containerLenNil { *vp = nil } else { if *vp == nil { *vp = make(map[uint64]int, decInferLen(containerLen, d.h.MaxInitLen, 16)) } if containerLen != 0 { f.DecMapUint64IntL(*vp, containerLen, d) } d.mapEnd() } } func (fastpathT) DecMapUint64IntL(v map[uint64]int, containerLen int, d *Decoder) { if v == nil { d.errorf("cannot decode into nil map[uint64]int given stream length: %v", containerLen) return } var mk uint64 var mv int hasLen := containerLen > 0 for j := 0; (hasLen && j < containerLen) || !(hasLen || d.checkBreak()); j++ { d.mapElemKey() mk = d.d.DecodeUint64() d.mapElemValue() mv = int(chkOvf.IntV(d.d.DecodeInt64(), intBitsize)) v[mk] = mv } } func (d *Decoder) fastpathDecMapUint64Int32R(f *codecFnInfo, rv reflect.Value) { 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.h.MaxInitLen, 12)) } if containerLen != 0 { fastpathTV.DecMapUint64Int32L(*vp, containerLen, d) } } else if containerLen != 0 { fastpathTV.DecMapUint64Int32L(rv2i(rv).(map[uint64]int32), containerLen, d) } d.mapEnd() } func (f fastpathT) DecMapUint64Int32X(vp *map[uint64]int32, d *Decoder) { containerLen := d.mapStart(d.d.ReadMapStart()) if containerLen == containerLenNil { *vp = nil } else { if *vp == nil { *vp = make(map[uint64]int32, decInferLen(containerLen, d.h.MaxInitLen, 12)) } if containerLen != 0 { f.DecMapUint64Int32L(*vp, containerLen, d) } d.mapEnd() } } func (fastpathT) DecMapUint64Int32L(v map[uint64]int32, containerLen int, d *Decoder) { if v == nil { d.errorf("cannot decode into nil map[uint64]int32 given stream length: %v", containerLen) return } var mk uint64 var mv int32 hasLen := containerLen > 0 for j := 0; (hasLen && j < containerLen) || !(hasLen || d.checkBreak()); j++ { d.mapElemKey() mk = d.d.DecodeUint64() d.mapElemValue() mv = int32(chkOvf.IntV(d.d.DecodeInt64(), 32)) v[mk] = mv } } func (d *Decoder) fastpathDecMapUint64Float64R(f *codecFnInfo, rv reflect.Value) { 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.h.MaxInitLen, 16)) } if containerLen != 0 { fastpathTV.DecMapUint64Float64L(*vp, containerLen, d) } } else if containerLen != 0 { fastpathTV.DecMapUint64Float64L(rv2i(rv).(map[uint64]float64), containerLen, d) } d.mapEnd() } func (f fastpathT) DecMapUint64Float64X(vp *map[uint64]float64, d *Decoder) { containerLen := d.mapStart(d.d.ReadMapStart()) if containerLen == containerLenNil { *vp = nil } else { if *vp == nil { *vp = make(map[uint64]float64, decInferLen(containerLen, d.h.MaxInitLen, 16)) } if containerLen != 0 { f.DecMapUint64Float64L(*vp, containerLen, d) } d.mapEnd() } } func (fastpathT) DecMapUint64Float64L(v map[uint64]float64, containerLen int, d *Decoder) { if v == nil { d.errorf("cannot decode into nil map[uint64]float64 given stream length: %v", containerLen) return } var mk uint64 var mv float64 hasLen := containerLen > 0 for j := 0; (hasLen && j < containerLen) || !(hasLen || d.checkBreak()); j++ { d.mapElemKey() mk = d.d.DecodeUint64() d.mapElemValue() mv = d.d.DecodeFloat64() v[mk] = mv } } func (d *Decoder) fastpathDecMapUint64BoolR(f *codecFnInfo, rv reflect.Value) { 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.h.MaxInitLen, 9)) } if containerLen != 0 { fastpathTV.DecMapUint64BoolL(*vp, containerLen, d) } } else if containerLen != 0 { fastpathTV.DecMapUint64BoolL(rv2i(rv).(map[uint64]bool), containerLen, d) } d.mapEnd() } func (f fastpathT) DecMapUint64BoolX(vp *map[uint64]bool, d *Decoder) { containerLen := d.mapStart(d.d.ReadMapStart()) if containerLen == containerLenNil { *vp = nil } else { if *vp == nil { *vp = make(map[uint64]bool, decInferLen(containerLen, d.h.MaxInitLen, 9)) } if containerLen != 0 { f.DecMapUint64BoolL(*vp, containerLen, d) } d.mapEnd() } } func (fastpathT) DecMapUint64BoolL(v map[uint64]bool, containerLen int, d *Decoder) { if v == nil { d.errorf("cannot decode into nil map[uint64]bool given stream length: %v", containerLen) return } var mk uint64 var mv bool hasLen := containerLen > 0 for j := 0; (hasLen && j < containerLen) || !(hasLen || d.checkBreak()); j++ { d.mapElemKey() mk = d.d.DecodeUint64() d.mapElemValue() mv = d.d.DecodeBool() v[mk] = mv } } func (d *Decoder) fastpathDecMapIntIntfR(f *codecFnInfo, rv reflect.Value) { 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.h.MaxInitLen, 24)) } if containerLen != 0 { fastpathTV.DecMapIntIntfL(*vp, containerLen, d) } } else if containerLen != 0 { fastpathTV.DecMapIntIntfL(rv2i(rv).(map[int]interface{}), containerLen, d) } d.mapEnd() } func (f fastpathT) DecMapIntIntfX(vp *map[int]interface{}, d *Decoder) { containerLen := d.mapStart(d.d.ReadMapStart()) if containerLen == containerLenNil { *vp = nil } else { if *vp == nil { *vp = make(map[int]interface{}, decInferLen(containerLen, d.h.MaxInitLen, 24)) } if containerLen != 0 { f.DecMapIntIntfL(*vp, containerLen, d) } d.mapEnd() } } func (fastpathT) DecMapIntIntfL(v map[int]interface{}, containerLen int, d *Decoder) { if v == nil { d.errorf("cannot decode into nil map[int]interface{} given stream length: %v", containerLen) return } mapGet := v != nil && !d.h.MapValueReset && !d.h.InterfaceReset var mk int var mv interface{} hasLen := containerLen > 0 for j := 0; (hasLen && j < containerLen) || !(hasLen || d.checkBreak()); j++ { d.mapElemKey() 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) fastpathDecMapIntStringR(f *codecFnInfo, rv reflect.Value) { 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.h.MaxInitLen, 24)) } if containerLen != 0 { fastpathTV.DecMapIntStringL(*vp, containerLen, d) } } else if containerLen != 0 { fastpathTV.DecMapIntStringL(rv2i(rv).(map[int]string), containerLen, d) } d.mapEnd() } func (f fastpathT) DecMapIntStringX(vp *map[int]string, d *Decoder) { containerLen := d.mapStart(d.d.ReadMapStart()) if containerLen == containerLenNil { *vp = nil } else { if *vp == nil { *vp = make(map[int]string, decInferLen(containerLen, d.h.MaxInitLen, 24)) } if containerLen != 0 { f.DecMapIntStringL(*vp, containerLen, d) } d.mapEnd() } } func (fastpathT) DecMapIntStringL(v map[int]string, containerLen int, d *Decoder) { if v == nil { d.errorf("cannot decode into nil map[int]string given stream length: %v", containerLen) return } var mk int var mv string hasLen := containerLen > 0 for j := 0; (hasLen && j < containerLen) || !(hasLen || d.checkBreak()); j++ { d.mapElemKey() mk = int(chkOvf.IntV(d.d.DecodeInt64(), intBitsize)) d.mapElemValue() mv = d.stringZC(d.d.DecodeStringAsBytes()) v[mk] = mv } } func (d *Decoder) fastpathDecMapIntBytesR(f *codecFnInfo, rv reflect.Value) { 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.h.MaxInitLen, 32)) } if containerLen != 0 { fastpathTV.DecMapIntBytesL(*vp, containerLen, d) } } else if containerLen != 0 { fastpathTV.DecMapIntBytesL(rv2i(rv).(map[int][]byte), containerLen, d) } d.mapEnd() } func (f fastpathT) DecMapIntBytesX(vp *map[int][]byte, d *Decoder) { containerLen := d.mapStart(d.d.ReadMapStart()) if containerLen == containerLenNil { *vp = nil } else { if *vp == nil { *vp = make(map[int][]byte, decInferLen(containerLen, d.h.MaxInitLen, 32)) } if containerLen != 0 { f.DecMapIntBytesL(*vp, containerLen, d) } d.mapEnd() } } func (fastpathT) DecMapIntBytesL(v map[int][]byte, containerLen int, d *Decoder) { if v == nil { d.errorf("cannot decode into nil map[int][]byte given stream length: %v", containerLen) return } mapGet := v != nil && !d.h.MapValueReset var mk int var mv []byte hasLen := containerLen > 0 for j := 0; (hasLen && j < containerLen) || !(hasLen || d.checkBreak()); j++ { d.mapElemKey() mk = int(chkOvf.IntV(d.d.DecodeInt64(), intBitsize)) d.mapElemValue() if mapGet { mv = v[mk] } else { mv = nil } mv = d.decodeBytesInto(mv) v[mk] = mv } } func (d *Decoder) fastpathDecMapIntUint8R(f *codecFnInfo, rv reflect.Value) { 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.h.MaxInitLen, 9)) } if containerLen != 0 { fastpathTV.DecMapIntUint8L(*vp, containerLen, d) } } else if containerLen != 0 { fastpathTV.DecMapIntUint8L(rv2i(rv).(map[int]uint8), containerLen, d) } d.mapEnd() } func (f fastpathT) DecMapIntUint8X(vp *map[int]uint8, d *Decoder) { containerLen := d.mapStart(d.d.ReadMapStart()) if containerLen == containerLenNil { *vp = nil } else { if *vp == nil { *vp = make(map[int]uint8, decInferLen(containerLen, d.h.MaxInitLen, 9)) } if containerLen != 0 { f.DecMapIntUint8L(*vp, containerLen, d) } d.mapEnd() } } func (fastpathT) DecMapIntUint8L(v map[int]uint8, containerLen int, d *Decoder) { if v == nil { d.errorf("cannot decode into nil map[int]uint8 given stream length: %v", containerLen) return } var mk int var mv uint8 hasLen := containerLen > 0 for j := 0; (hasLen && j < containerLen) || !(hasLen || d.checkBreak()); j++ { d.mapElemKey() mk = int(chkOvf.IntV(d.d.DecodeInt64(), intBitsize)) d.mapElemValue() mv = uint8(chkOvf.UintV(d.d.DecodeUint64(), 8)) v[mk] = mv } } func (d *Decoder) fastpathDecMapIntUint64R(f *codecFnInfo, rv reflect.Value) { 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.h.MaxInitLen, 16)) } if containerLen != 0 { fastpathTV.DecMapIntUint64L(*vp, containerLen, d) } } else if containerLen != 0 { fastpathTV.DecMapIntUint64L(rv2i(rv).(map[int]uint64), containerLen, d) } d.mapEnd() } func (f fastpathT) DecMapIntUint64X(vp *map[int]uint64, d *Decoder) { containerLen := d.mapStart(d.d.ReadMapStart()) if containerLen == containerLenNil { *vp = nil } else { if *vp == nil { *vp = make(map[int]uint64, decInferLen(containerLen, d.h.MaxInitLen, 16)) } if containerLen != 0 { f.DecMapIntUint64L(*vp, containerLen, d) } d.mapEnd() } } func (fastpathT) DecMapIntUint64L(v map[int]uint64, containerLen int, d *Decoder) { if v == nil { d.errorf("cannot decode into nil map[int]uint64 given stream length: %v", containerLen) return } var mk int var mv uint64 hasLen := containerLen > 0 for j := 0; (hasLen && j < containerLen) || !(hasLen || d.checkBreak()); j++ { d.mapElemKey() mk = int(chkOvf.IntV(d.d.DecodeInt64(), intBitsize)) d.mapElemValue() mv = d.d.DecodeUint64() v[mk] = mv } } func (d *Decoder) fastpathDecMapIntIntR(f *codecFnInfo, rv reflect.Value) { 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.h.MaxInitLen, 16)) } if containerLen != 0 { fastpathTV.DecMapIntIntL(*vp, containerLen, d) } } else if containerLen != 0 { fastpathTV.DecMapIntIntL(rv2i(rv).(map[int]int), containerLen, d) } d.mapEnd() } func (f fastpathT) DecMapIntIntX(vp *map[int]int, d *Decoder) { containerLen := d.mapStart(d.d.ReadMapStart()) if containerLen == containerLenNil { *vp = nil } else { if *vp == nil { *vp = make(map[int]int, decInferLen(containerLen, d.h.MaxInitLen, 16)) } if containerLen != 0 { f.DecMapIntIntL(*vp, containerLen, d) } d.mapEnd() } } func (fastpathT) DecMapIntIntL(v map[int]int, containerLen int, d *Decoder) { if v == nil { d.errorf("cannot decode into nil map[int]int given stream length: %v", containerLen) return } var mk int var mv int hasLen := containerLen > 0 for j := 0; (hasLen && j < containerLen) || !(hasLen || d.checkBreak()); j++ { d.mapElemKey() mk = int(chkOvf.IntV(d.d.DecodeInt64(), intBitsize)) d.mapElemValue() mv = int(chkOvf.IntV(d.d.DecodeInt64(), intBitsize)) v[mk] = mv } } func (d *Decoder) fastpathDecMapIntInt32R(f *codecFnInfo, rv reflect.Value) { 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.h.MaxInitLen, 12)) } if containerLen != 0 { fastpathTV.DecMapIntInt32L(*vp, containerLen, d) } } else if containerLen != 0 { fastpathTV.DecMapIntInt32L(rv2i(rv).(map[int]int32), containerLen, d) } d.mapEnd() } func (f fastpathT) DecMapIntInt32X(vp *map[int]int32, d *Decoder) { containerLen := d.mapStart(d.d.ReadMapStart()) if containerLen == containerLenNil { *vp = nil } else { if *vp == nil { *vp = make(map[int]int32, decInferLen(containerLen, d.h.MaxInitLen, 12)) } if containerLen != 0 { f.DecMapIntInt32L(*vp, containerLen, d) } d.mapEnd() } } func (fastpathT) DecMapIntInt32L(v map[int]int32, containerLen int, d *Decoder) { if v == nil { d.errorf("cannot decode into nil map[int]int32 given stream length: %v", containerLen) return } var mk int var mv int32 hasLen := containerLen > 0 for j := 0; (hasLen && j < containerLen) || !(hasLen || d.checkBreak()); j++ { d.mapElemKey() mk = int(chkOvf.IntV(d.d.DecodeInt64(), intBitsize)) d.mapElemValue() mv = int32(chkOvf.IntV(d.d.DecodeInt64(), 32)) v[mk] = mv } } func (d *Decoder) fastpathDecMapIntFloat64R(f *codecFnInfo, rv reflect.Value) { 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.h.MaxInitLen, 16)) } if containerLen != 0 { fastpathTV.DecMapIntFloat64L(*vp, containerLen, d) } } else if containerLen != 0 { fastpathTV.DecMapIntFloat64L(rv2i(rv).(map[int]float64), containerLen, d) } d.mapEnd() } func (f fastpathT) DecMapIntFloat64X(vp *map[int]float64, d *Decoder) { containerLen := d.mapStart(d.d.ReadMapStart()) if containerLen == containerLenNil { *vp = nil } else { if *vp == nil { *vp = make(map[int]float64, decInferLen(containerLen, d.h.MaxInitLen, 16)) } if containerLen != 0 { f.DecMapIntFloat64L(*vp, containerLen, d) } d.mapEnd() } } func (fastpathT) DecMapIntFloat64L(v map[int]float64, containerLen int, d *Decoder) { if v == nil { d.errorf("cannot decode into nil map[int]float64 given stream length: %v", containerLen) return } var mk int var mv float64 hasLen := containerLen > 0 for j := 0; (hasLen && j < containerLen) || !(hasLen || d.checkBreak()); j++ { d.mapElemKey() mk = int(chkOvf.IntV(d.d.DecodeInt64(), intBitsize)) d.mapElemValue() mv = d.d.DecodeFloat64() v[mk] = mv } } func (d *Decoder) fastpathDecMapIntBoolR(f *codecFnInfo, rv reflect.Value) { 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.h.MaxInitLen, 9)) } if containerLen != 0 { fastpathTV.DecMapIntBoolL(*vp, containerLen, d) } } else if containerLen != 0 { fastpathTV.DecMapIntBoolL(rv2i(rv).(map[int]bool), containerLen, d) } d.mapEnd() } func (f fastpathT) DecMapIntBoolX(vp *map[int]bool, d *Decoder) { containerLen := d.mapStart(d.d.ReadMapStart()) if containerLen == containerLenNil { *vp = nil } else { if *vp == nil { *vp = make(map[int]bool, decInferLen(containerLen, d.h.MaxInitLen, 9)) } if containerLen != 0 { f.DecMapIntBoolL(*vp, containerLen, d) } d.mapEnd() } } func (fastpathT) DecMapIntBoolL(v map[int]bool, containerLen int, d *Decoder) { if v == nil { d.errorf("cannot decode into nil map[int]bool given stream length: %v", containerLen) return } var mk int var mv bool hasLen := containerLen > 0 for j := 0; (hasLen && j < containerLen) || !(hasLen || d.checkBreak()); j++ { d.mapElemKey() mk = int(chkOvf.IntV(d.d.DecodeInt64(), intBitsize)) d.mapElemValue() mv = d.d.DecodeBool() v[mk] = mv } } func (d *Decoder) fastpathDecMapInt32IntfR(f *codecFnInfo, rv reflect.Value) { 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.h.MaxInitLen, 20)) } if containerLen != 0 { fastpathTV.DecMapInt32IntfL(*vp, containerLen, d) } } else if containerLen != 0 { fastpathTV.DecMapInt32IntfL(rv2i(rv).(map[int32]interface{}), containerLen, d) } d.mapEnd() } func (f fastpathT) DecMapInt32IntfX(vp *map[int32]interface{}, d *Decoder) { containerLen := d.mapStart(d.d.ReadMapStart()) if containerLen == containerLenNil { *vp = nil } else { if *vp == nil { *vp = make(map[int32]interface{}, decInferLen(containerLen, d.h.MaxInitLen, 20)) } if containerLen != 0 { f.DecMapInt32IntfL(*vp, containerLen, d) } d.mapEnd() } } func (fastpathT) DecMapInt32IntfL(v map[int32]interface{}, containerLen int, d *Decoder) { if v == nil { d.errorf("cannot decode into nil map[int32]interface{} given stream length: %v", containerLen) return } mapGet := v != nil && !d.h.MapValueReset && !d.h.InterfaceReset var mk int32 var mv interface{} hasLen := containerLen > 0 for j := 0; (hasLen && j < containerLen) || !(hasLen || d.checkBreak()); j++ { d.mapElemKey() 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) fastpathDecMapInt32StringR(f *codecFnInfo, rv reflect.Value) { 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.h.MaxInitLen, 20)) } if containerLen != 0 { fastpathTV.DecMapInt32StringL(*vp, containerLen, d) } } else if containerLen != 0 { fastpathTV.DecMapInt32StringL(rv2i(rv).(map[int32]string), containerLen, d) } d.mapEnd() } func (f fastpathT) DecMapInt32StringX(vp *map[int32]string, d *Decoder) { containerLen := d.mapStart(d.d.ReadMapStart()) if containerLen == containerLenNil { *vp = nil } else { if *vp == nil { *vp = make(map[int32]string, decInferLen(containerLen, d.h.MaxInitLen, 20)) } if containerLen != 0 { f.DecMapInt32StringL(*vp, containerLen, d) } d.mapEnd() } } func (fastpathT) DecMapInt32StringL(v map[int32]string, containerLen int, d *Decoder) { if v == nil { d.errorf("cannot decode into nil map[int32]string given stream length: %v", containerLen) return } var mk int32 var mv string hasLen := containerLen > 0 for j := 0; (hasLen && j < containerLen) || !(hasLen || d.checkBreak()); j++ { d.mapElemKey() mk = int32(chkOvf.IntV(d.d.DecodeInt64(), 32)) d.mapElemValue() mv = d.stringZC(d.d.DecodeStringAsBytes()) v[mk] = mv } } func (d *Decoder) fastpathDecMapInt32BytesR(f *codecFnInfo, rv reflect.Value) { 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.h.MaxInitLen, 28)) } if containerLen != 0 { fastpathTV.DecMapInt32BytesL(*vp, containerLen, d) } } else if containerLen != 0 { fastpathTV.DecMapInt32BytesL(rv2i(rv).(map[int32][]byte), containerLen, d) } d.mapEnd() } func (f fastpathT) DecMapInt32BytesX(vp *map[int32][]byte, d *Decoder) { containerLen := d.mapStart(d.d.ReadMapStart()) if containerLen == containerLenNil { *vp = nil } else { if *vp == nil { *vp = make(map[int32][]byte, decInferLen(containerLen, d.h.MaxInitLen, 28)) } if containerLen != 0 { f.DecMapInt32BytesL(*vp, containerLen, d) } d.mapEnd() } } func (fastpathT) DecMapInt32BytesL(v map[int32][]byte, containerLen int, d *Decoder) { if v == nil { d.errorf("cannot decode into nil map[int32][]byte given stream length: %v", containerLen) return } mapGet := v != nil && !d.h.MapValueReset var mk int32 var mv []byte hasLen := containerLen > 0 for j := 0; (hasLen && j < containerLen) || !(hasLen || d.checkBreak()); j++ { d.mapElemKey() mk = int32(chkOvf.IntV(d.d.DecodeInt64(), 32)) d.mapElemValue() if mapGet { mv = v[mk] } else { mv = nil } mv = d.decodeBytesInto(mv) v[mk] = mv } } func (d *Decoder) fastpathDecMapInt32Uint8R(f *codecFnInfo, rv reflect.Value) { 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.h.MaxInitLen, 5)) } if containerLen != 0 { fastpathTV.DecMapInt32Uint8L(*vp, containerLen, d) } } else if containerLen != 0 { fastpathTV.DecMapInt32Uint8L(rv2i(rv).(map[int32]uint8), containerLen, d) } d.mapEnd() } func (f fastpathT) DecMapInt32Uint8X(vp *map[int32]uint8, d *Decoder) { containerLen := d.mapStart(d.d.ReadMapStart()) if containerLen == containerLenNil { *vp = nil } else { if *vp == nil { *vp = make(map[int32]uint8, decInferLen(containerLen, d.h.MaxInitLen, 5)) } if containerLen != 0 { f.DecMapInt32Uint8L(*vp, containerLen, d) } d.mapEnd() } } func (fastpathT) DecMapInt32Uint8L(v map[int32]uint8, containerLen int, d *Decoder) { if v == nil { d.errorf("cannot decode into nil map[int32]uint8 given stream length: %v", containerLen) return } var mk int32 var mv uint8 hasLen := containerLen > 0 for j := 0; (hasLen && j < containerLen) || !(hasLen || d.checkBreak()); j++ { d.mapElemKey() mk = int32(chkOvf.IntV(d.d.DecodeInt64(), 32)) d.mapElemValue() mv = uint8(chkOvf.UintV(d.d.DecodeUint64(), 8)) v[mk] = mv } } func (d *Decoder) fastpathDecMapInt32Uint64R(f *codecFnInfo, rv reflect.Value) { 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.h.MaxInitLen, 12)) } if containerLen != 0 { fastpathTV.DecMapInt32Uint64L(*vp, containerLen, d) } } else if containerLen != 0 { fastpathTV.DecMapInt32Uint64L(rv2i(rv).(map[int32]uint64), containerLen, d) } d.mapEnd() } func (f fastpathT) DecMapInt32Uint64X(vp *map[int32]uint64, d *Decoder) { containerLen := d.mapStart(d.d.ReadMapStart()) if containerLen == containerLenNil { *vp = nil } else { if *vp == nil { *vp = make(map[int32]uint64, decInferLen(containerLen, d.h.MaxInitLen, 12)) } if containerLen != 0 { f.DecMapInt32Uint64L(*vp, containerLen, d) } d.mapEnd() } } func (fastpathT) DecMapInt32Uint64L(v map[int32]uint64, containerLen int, d *Decoder) { if v == nil { d.errorf("cannot decode into nil map[int32]uint64 given stream length: %v", containerLen) return } var mk int32 var mv uint64 hasLen := containerLen > 0 for j := 0; (hasLen && j < containerLen) || !(hasLen || d.checkBreak()); j++ { d.mapElemKey() mk = int32(chkOvf.IntV(d.d.DecodeInt64(), 32)) d.mapElemValue() mv = d.d.DecodeUint64() v[mk] = mv } } func (d *Decoder) fastpathDecMapInt32IntR(f *codecFnInfo, rv reflect.Value) { 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.h.MaxInitLen, 12)) } if containerLen != 0 { fastpathTV.DecMapInt32IntL(*vp, containerLen, d) } } else if containerLen != 0 { fastpathTV.DecMapInt32IntL(rv2i(rv).(map[int32]int), containerLen, d) } d.mapEnd() } func (f fastpathT) DecMapInt32IntX(vp *map[int32]int, d *Decoder) { containerLen := d.mapStart(d.d.ReadMapStart()) if containerLen == containerLenNil { *vp = nil } else { if *vp == nil { *vp = make(map[int32]int, decInferLen(containerLen, d.h.MaxInitLen, 12)) } if containerLen != 0 { f.DecMapInt32IntL(*vp, containerLen, d) } d.mapEnd() } } func (fastpathT) DecMapInt32IntL(v map[int32]int, containerLen int, d *Decoder) { if v == nil { d.errorf("cannot decode into nil map[int32]int given stream length: %v", containerLen) return } var mk int32 var mv int hasLen := containerLen > 0 for j := 0; (hasLen && j < containerLen) || !(hasLen || d.checkBreak()); j++ { d.mapElemKey() mk = int32(chkOvf.IntV(d.d.DecodeInt64(), 32)) d.mapElemValue() mv = int(chkOvf.IntV(d.d.DecodeInt64(), intBitsize)) v[mk] = mv } } func (d *Decoder) fastpathDecMapInt32Int32R(f *codecFnInfo, rv reflect.Value) { 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.h.MaxInitLen, 8)) } if containerLen != 0 { fastpathTV.DecMapInt32Int32L(*vp, containerLen, d) } } else if containerLen != 0 { fastpathTV.DecMapInt32Int32L(rv2i(rv).(map[int32]int32), containerLen, d) } d.mapEnd() } func (f fastpathT) DecMapInt32Int32X(vp *map[int32]int32, d *Decoder) { containerLen := d.mapStart(d.d.ReadMapStart()) if containerLen == containerLenNil { *vp = nil } else { if *vp == nil { *vp = make(map[int32]int32, decInferLen(containerLen, d.h.MaxInitLen, 8)) } if containerLen != 0 { f.DecMapInt32Int32L(*vp, containerLen, d) } d.mapEnd() } } func (fastpathT) DecMapInt32Int32L(v map[int32]int32, containerLen int, d *Decoder) { if v == nil { d.errorf("cannot decode into nil map[int32]int32 given stream length: %v", containerLen) return } var mk int32 var mv int32 hasLen := containerLen > 0 for j := 0; (hasLen && j < containerLen) || !(hasLen || d.checkBreak()); j++ { d.mapElemKey() mk = int32(chkOvf.IntV(d.d.DecodeInt64(), 32)) d.mapElemValue() mv = int32(chkOvf.IntV(d.d.DecodeInt64(), 32)) v[mk] = mv } } func (d *Decoder) fastpathDecMapInt32Float64R(f *codecFnInfo, rv reflect.Value) { 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.h.MaxInitLen, 12)) } if containerLen != 0 { fastpathTV.DecMapInt32Float64L(*vp, containerLen, d) } } else if containerLen != 0 { fastpathTV.DecMapInt32Float64L(rv2i(rv).(map[int32]float64), containerLen, d) } d.mapEnd() } func (f fastpathT) DecMapInt32Float64X(vp *map[int32]float64, d *Decoder) { containerLen := d.mapStart(d.d.ReadMapStart()) if containerLen == containerLenNil { *vp = nil } else { if *vp == nil { *vp = make(map[int32]float64, decInferLen(containerLen, d.h.MaxInitLen, 12)) } if containerLen != 0 { f.DecMapInt32Float64L(*vp, containerLen, d) } d.mapEnd() } } func (fastpathT) DecMapInt32Float64L(v map[int32]float64, containerLen int, d *Decoder) { if v == nil { d.errorf("cannot decode into nil map[int32]float64 given stream length: %v", containerLen) return } var mk int32 var mv float64 hasLen := containerLen > 0 for j := 0; (hasLen && j < containerLen) || !(hasLen || d.checkBreak()); j++ { d.mapElemKey() mk = int32(chkOvf.IntV(d.d.DecodeInt64(), 32)) d.mapElemValue() mv = d.d.DecodeFloat64() v[mk] = mv } } func (d *Decoder) fastpathDecMapInt32BoolR(f *codecFnInfo, rv reflect.Value) { 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.h.MaxInitLen, 5)) } if containerLen != 0 { fastpathTV.DecMapInt32BoolL(*vp, containerLen, d) } } else if containerLen != 0 { fastpathTV.DecMapInt32BoolL(rv2i(rv).(map[int32]bool), containerLen, d) } d.mapEnd() } func (f fastpathT) DecMapInt32BoolX(vp *map[int32]bool, d *Decoder) { containerLen := d.mapStart(d.d.ReadMapStart()) if containerLen == containerLenNil { *vp = nil } else { if *vp == nil { *vp = make(map[int32]bool, decInferLen(containerLen, d.h.MaxInitLen, 5)) } if containerLen != 0 { f.DecMapInt32BoolL(*vp, containerLen, d) } d.mapEnd() } } func (fastpathT) DecMapInt32BoolL(v map[int32]bool, containerLen int, d *Decoder) { if v == nil { d.errorf("cannot decode into nil map[int32]bool given stream length: %v", containerLen) return } var mk int32 var mv bool hasLen := containerLen > 0 for j := 0; (hasLen && j < containerLen) || !(hasLen || d.checkBreak()); j++ { d.mapElemKey() mk = int32(chkOvf.IntV(d.d.DecodeInt64(), 32)) d.mapElemValue() mv = d.d.DecodeBool() v[mk] = mv } } go-1.2.8/codec/fast-path.go.tmpl000066400000000000000000000413631435255326100164120ustar00rootroot00000000000000// +build !notfastpath // +build !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 fast-path.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. // {{/* fastpathEncMapStringUint64R (called by fastpath...switch) EncMapStringUint64V (called by codecgen) fastpathEncSliceBoolR: (called by fastpath...switch) (checks f.ti.mbs and calls one of them below) EncSliceBoolV (also called by codecgen) EncAsMapSliceBoolV (delegate when mapbyslice=true) fastpathDecSliceIntfR (called by fastpath...switch) (calls Y or N below depending on if it can be updated) DecSliceIntfX (called by codecgen) (calls Y below) DecSliceIntfY (delegate when slice CAN be updated) DecSliceIntfN (delegate when slice CANNOT be updated e.g. from array or non-addressable slice) fastpathDecMap...R (called by fastpath...switch) (calls L or X? below) DecMap...X (called by codecgen) DecMap...L (delegated to by both above) */ -}} import ( "reflect" "sort" ) const fastpathEnabled = true {{/* const fastpathMapBySliceErrMsg = "mapBySlice requires even slice length, but got %v" */ -}} type fastpathT struct {} var fastpathTV fastpathT type fastpathE struct { {{/* rtid uintptr */ -}} rt reflect.Type encfn func(*Encoder, *codecFnInfo, reflect.Value) decfn func(*Decoder, *codecFnInfo, reflect.Value) } type fastpathA [{{ .FastpathLen }}]fastpathE type fastpathARtid [{{ .FastpathLen }}]uintptr var fastpathAv fastpathA var fastpathAvRtid fastpathARtid type fastpathAslice struct{} func (fastpathAslice) Len() int { return {{ .FastpathLen }} } func (fastpathAslice) Less(i, j int) bool { return fastpathAvRtid[uint(i)] < fastpathAvRtid[uint(j)] } func (fastpathAslice) Swap(i, j int) { fastpathAvRtid[uint(i)], fastpathAvRtid[uint(j)] = fastpathAvRtid[uint(j)], fastpathAvRtid[uint(i)] fastpathAv[uint(i)], fastpathAv[uint(j)] = fastpathAv[uint(j)], fastpathAv[uint(i)] } func fastpathAvIndex(rtid uintptr) int { // use binary search to grab the index (adapted from sort/search.go) // Note: we use goto (instead of for loop) so this can be inlined. // h, i, j := 0, 0, {{ .FastpathLen }} var h, i uint var j uint = {{ .FastpathLen }} LOOP: if i < j { h = (i + j) >> 1 // avoid overflow when computing h // h = i + (j-i)/2 if fastpathAvRtid[h] < rtid { i = h + 1 } else { j = h } goto LOOP } if i < {{ .FastpathLen }} && fastpathAvRtid[i] == rtid { return int(i) } return -1 } // due to possible initialization loop error, make fastpath in an init() func init() { var i uint = 0 fn := func(v interface{}, fe func(*Encoder, *codecFnInfo, reflect.Value), fd func(*Decoder, *codecFnInfo, reflect.Value)) { xrt := reflect.TypeOf(v) xptr := rt2id(xrt) fastpathAvRtid[i] = xptr fastpathAv[i] = fastpathE{xrt, fe, fd} i++ } {{/* do not register []byte in fast-path */}} {{range .Values}}{{if not .Primitive}}{{if not .MapKey -}} fn([]{{ .Elem }}(nil), (*Encoder).{{ .MethodNamePfx "fastpathEnc" false }}R, (*Decoder).{{ .MethodNamePfx "fastpathDec" false }}R) {{end}}{{end}}{{end}} {{range .Values}}{{if not .Primitive}}{{if .MapKey -}} fn(map[{{ .MapKey }}]{{ .Elem }}(nil), (*Encoder).{{ .MethodNamePfx "fastpathEnc" false }}R, (*Decoder).{{ .MethodNamePfx "fastpathDec" false }}R) {{end}}{{end}}{{end}} sort.Sort(fastpathAslice{}) } // -- encode // -- -- fast path type switch func fastpathEncodeTypeSwitch(iv interface{}, e *Encoder) bool { switch v := iv.(type) { {{range .Values}}{{if not .Primitive}}{{if not .MapKey -}} case []{{ .Elem }}: fastpathTV.{{ .MethodNamePfx "Enc" false }}V(v, e) case *[]{{ .Elem }}: if *v == nil { e.e.EncodeNil() } else { fastpathTV.{{ .MethodNamePfx "Enc" false }}V(*v, e) } {{end}}{{end}}{{end -}} {{range .Values}}{{if not .Primitive}}{{if .MapKey -}} case map[{{ .MapKey }}]{{ .Elem }}: fastpathTV.{{ .MethodNamePfx "Enc" false }}V(v, e) case *map[{{ .MapKey }}]{{ .Elem }}: if *v == nil { e.e.EncodeNil() } else { fastpathTV.{{ .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) {{ .MethodNamePfx "fastpathEnc" false }}R(f *codecFnInfo, rv reflect.Value) { var v []{{ .Elem }} if rv.Kind() == reflect.Array { rvGetSlice4Array(rv, &v) } else { v = rv2i(rv).([]{{ .Elem }}) } if f.ti.mbs { fastpathTV.{{ .MethodNamePfx "EncAsMap" false }}V(v, e) } else { fastpathTV.{{ .MethodNamePfx "Enc" false }}V(v, e) } } func (fastpathT) {{ .MethodNamePfx "Enc" false }}V(v []{{ .Elem }}, e *Encoder) { {{/* if v == nil { e.e.EncodeNil(); return } */ -}} {{ if eq .Elem "uint8" "byte" -}} e.e.EncodeStringBytesRaw(v) {{ else -}} e.arrayStart(len(v)) for j := range v { e.arrayElem() {{ encmd .Elem "v[j]"}} } e.arrayEnd() {{ end -}} } func (fastpathT) {{ .MethodNamePfx "EncAsMap" false }}V(v []{{ .Elem }}, e *Encoder) { {{/* if v == nil { e.e.EncodeNil() } else */ -}} e.haltOnMbsOddLen(len(v)) {{/* if len(v)&1 != 0 { // similar to &1==1 or %2 == 1 e.errorf(fastpathMapBySliceErrMsg, 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.mapElemKey() } else { e.mapElemValue() } {{ encmd .Elem "v[j]"}} } e.mapEnd() } {{end}}{{end}}{{end -}} {{range .Values}}{{if not .Primitive}}{{if .MapKey -}} func (e *Encoder) {{ .MethodNamePfx "fastpathEnc" false }}R(f *codecFnInfo, rv reflect.Value) { fastpathTV.{{ .MethodNamePfx "Enc" false }}V(rv2i(rv).(map[{{ .MapKey }}]{{ .Elem }}), e) } func (fastpathT) {{ .MethodNamePfx "Enc" false }}V(v map[{{ .MapKey }}]{{ .Elem }}, e *Encoder) { {{/* if v == nil { e.e.EncodeNil(); return } */ -}} 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 i, 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++ } sort.Sort(bytesIntfSlice(v2)) for j := range v2 { e.mapElemKey() e.asis(v2[j].v) e.mapElemValue() e.encode(v[v2[j].i]) } {{else}}{{ $x := sorttype .MapKey true}}v2 := make([]{{ $x }}, len(v)) var i uint for k := range v { v2[i] = {{if eq $x .MapKey}}k{{else}}{{ $x }}(k){{end}} i++ } sort.Sort({{ sorttype .MapKey false}}(v2)) for _, k2 := range v2 { e.mapElemKey() {{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 { for k2, v2 := range v { e.mapElemKey() {{if eq .MapKey "string"}} e.e.EncodeString(k2) {{else}}{{ encmd .MapKey "k2"}}{{end}} e.mapElemValue() {{ encmd .Elem "v2"}} } } e.mapEnd() } {{end}}{{end}}{{end -}} // -- decode // -- -- fast path type switch func fastpathDecodeTypeSwitch(iv interface{}, d *Decoder) bool { var changed bool var containerLen int switch v := iv.(type) { {{range .Values}}{{if not .Primitive}}{{if not .MapKey -}} case []{{ .Elem }}: fastpathTV.{{ .MethodNamePfx "Dec" false }}N(v, d) case *[]{{ .Elem }}: var v2 []{{ .Elem }} if v2, changed = fastpathTV.{{ .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 }}: containerLen = d.mapStart(d.d.ReadMapStart()) if containerLen != containerLenNil { if containerLen != 0 { fastpathTV.{{ .MethodNamePfx "Dec" false }}L(v, containerLen, d) } d.mapEnd() } case *map[{{ .MapKey }}]{{ .Elem }}: {{/* containerLen = d.mapStart(d.d.ReadMapStart()) if containerLen == 0 { d.mapEnd() } else if containerLen == containerLenNil { *v = nil } else { if *v == nil { *v = make(map[{{ .MapKey }}]{{ .Elem }}, decInferLen(containerLen, d.h.MaxInitLen, {{ .Size }})) } fastpathTV.{{ .MethodNamePfx "Dec" false }}L(*v, containerLen, d) } // consider delegating fully to X - encoding *map is uncommon, so ok to pay small function call cost */ -}} fastpathTV.{{ .MethodNamePfx "Dec" false }}X(v, d) {{end}}{{end}}{{end -}} default: _ = v // workaround https://github.com/golang/go/issues/12927 seen in go1.4 return false } return true } 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 } // -- -- 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) {{ .MethodNamePfx "fastpathDec" false }}R(f *codecFnInfo, rv reflect.Value) { {{/* // seqTypeArray=true means that we are not getting a pointer, so no need to check that. if f.seq != seqTypeArray && rv.Kind() == reflect.Ptr { */ -}} var v []{{ .Elem }} switch rv.Kind() { case reflect.Ptr: vp := rv2i(rv).(*[]{{ .Elem }}) var changed bool if v, changed = fastpathTV.{{ .MethodNamePfx "Dec" false }}Y(*vp, d); changed { *vp = v } case reflect.Array: rvGetSlice4Array(rv, &v) fastpathTV.{{ .MethodNamePfx "Dec" false }}N(v, d) default: fastpathTV.{{ .MethodNamePfx "Dec" false }}N(rv2i(rv).([]{{ .Elem }}), d) } } func (f fastpathT) {{ .MethodNamePfx "Dec" false }}X(vp *[]{{ .Elem }}, d *Decoder) { if v, changed := f.{{ .MethodNamePfx "Dec" false }}Y(*vp, d); changed { *vp = v } } func (fastpathT) {{ .MethodNamePfx "Dec" false }}Y(v []{{ .Elem }}, d *Decoder) (v2 []{{ .Elem }}, changed bool) { {{ if eq .Elem "uint8" "byte" -}} switch d.d.ContainerType() { case valueTypeNil, valueTypeMap: break default: v2 = d.decodeBytesInto(v[:len(v):len(v)]) changed = !(len(v2) > 0 && len(v2) == len(v) && &v2[0] == &v[0]) // not same slice return } {{ end -}} slh, containerLenS := d.decSliceHelperStart() if slh.IsNil { if v == nil { return } return nil, true } if containerLenS == 0 { if v == nil { v = []{{ .Elem }}{} } else if len(v) != 0 { v = v[:0] } slh.End() return v, true } hasLen := containerLenS > 0 var xlen int if hasLen { if containerLenS > cap(v) { xlen = decInferLen(containerLenS, d.h.MaxInitLen, {{ .Size }}) if xlen <= cap(v) { v = v[:uint(xlen)] } else { v = make([]{{ .Elem }}, uint(xlen)) } changed = true } else if containerLenS != len(v) { v = v[:containerLenS] changed = true } } var j int for j = 0; (hasLen && j < containerLenS) || !(hasLen || d.checkBreak()); j++ { if j == 0 && len(v) == 0 { // means hasLen == false xlen = decInferLen(containerLenS, d.h.MaxInitLen, {{ .Size }}) {{/* xlen = decDefSliceCap */}} v = make([]{{ .Elem }}, uint(xlen)) changed = true } {{/* // if indefinite, etc, then expand the slice if necessary */ -}} if j >= len(v) { v = append(v, {{ zerocmd .Elem }}) changed = true } slh.ElemContainerState(j) {{ if eq .Elem "interface{}" }}d.decode(&v[uint(j)]){{ else }}v[uint(j)] = {{ decmd .Elem false }}{{ end }} } if j < len(v) { v = v[:uint(j)] changed = true } else if j == 0 && v == nil { v = []{{ .Elem }}{} changed = true } slh.End() return v, changed } func (fastpathT) {{ .MethodNamePfx "Dec" false }}N(v []{{ .Elem }}, d *Decoder) { {{ if eq .Elem "uint8" "byte" -}} switch d.d.ContainerType() { case valueTypeNil, valueTypeMap: break default: v2 := d.decodeBytesInto(v[:len(v):len(v)]) if !(len(v2) > 0 && len(v2) == len(v) && &v2[0] == &v[0]) { // not same slice copy(v, v2) } return } {{ end -}} slh, containerLenS := d.decSliceHelperStart() if slh.IsNil { return } if containerLenS == 0 { slh.End() return } hasLen := containerLenS > 0 for j := 0; (hasLen && j < containerLenS) || !(hasLen || d.checkBreak()); j++ { {{/* // if indefinite, etc, then expand the slice if necessary */ -}} if j >= len(v) { slh.arrayCannotExpand(hasLen, len(v), j, containerLenS) return } slh.ElemContainerState(j) {{ if eq .Elem "interface{}" -}} d.decode(&v[uint(j)]) {{- else -}} v[uint(j)] = {{ decmd .Elem false }} {{- end }} } slh.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{}) Also, these methods are called by decodeValue directly, after handling a TryNil. Consequently, there's no need to check for containerLenNil here. */ -}} func (d *Decoder) {{ .MethodNamePfx "fastpathDec" false }}R(f *codecFnInfo, rv reflect.Value) { containerLen := d.mapStart(d.d.ReadMapStart()) {{/* if containerLen == containerLenNil { if rv.Kind() == reflect.Ptr { *(rv2i(rv).(*map[{{ .MapKey }}]{{ .Elem }})) = nil } return } */ -}} if rv.Kind() == reflect.Ptr { vp, _ := rv2i(rv).(*map[{{ .MapKey }}]{{ .Elem }}) if *vp == nil { *vp = make(map[{{ .MapKey }}]{{ .Elem }}, decInferLen(containerLen, d.h.MaxInitLen, {{ .Size }})) } if containerLen != 0 { fastpathTV.{{ .MethodNamePfx "Dec" false }}L(*vp, containerLen, d) } } else if containerLen != 0 { fastpathTV.{{ .MethodNamePfx "Dec" false }}L(rv2i(rv).(map[{{ .MapKey }}]{{ .Elem }}), containerLen, d) } d.mapEnd() } func (f fastpathT) {{ .MethodNamePfx "Dec" false }}X(vp *map[{{ .MapKey }}]{{ .Elem }}, d *Decoder) { containerLen := d.mapStart(d.d.ReadMapStart()) if containerLen == containerLenNil { *vp = nil } else { if *vp == nil { *vp = make(map[{{ .MapKey }}]{{ .Elem }}, decInferLen(containerLen, d.h.MaxInitLen, {{ .Size }})) } if containerLen != 0 { f.{{ .MethodNamePfx "Dec" false }}L(*vp, containerLen, d) } d.mapEnd() } } func (fastpathT) {{ .MethodNamePfx "Dec" false }}L(v map[{{ .MapKey }}]{{ .Elem }}, containerLen int, d *Decoder) { {{/* No need to check if containerLen == containerLenNil, as that is checked by R and L above */ -}} if v == nil { d.errorf("cannot decode into nil map[{{ .MapKey }}]{{ .Elem }} given stream length: %v", containerLen) {{/* d.swallowMapContents(containerLen) */ -}} return } {{if eq .Elem "interface{}" }}mapGet := v != nil && !d.h.MapValueReset && !d.h.InterfaceReset {{else if eq .Elem "bytes" "[]byte" }}mapGet := v != nil && !d.h.MapValueReset {{end -}} var mk {{ .MapKey }} var mv {{ .Elem }} hasLen := containerLen > 0 for j := 0; (hasLen && j < containerLen) || !(hasLen || d.checkBreak()); j++ { d.mapElemKey() {{ if eq .MapKey "interface{}" }}mk = nil d.decode(&mk) if bv, bok := mk.([]byte); bok { mk = d.stringZC(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) {{ else if eq .Elem "[]byte" "bytes" -}} mv = d.decodeBytesInto(mv) {{ else -}} mv = {{ decmd .Elem false }} {{ end -}} v[mk] = mv } } {{end}}{{end}}{{end}} go-1.2.8/codec/fast-path.not.go000066400000000000000000000025561435255326100162370ustar00rootroot00000000000000// 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 // +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 fastpathDecodeTypeSwitch(iv interface{}, d *Decoder) bool { return false } func fastpathEncodeTypeSwitch(iv interface{}, e *Encoder) bool { return false } // 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 } type fastpathT struct{} type fastpathE struct { rtid uintptr rt reflect.Type encfn func(*Encoder, *codecFnInfo, reflect.Value) decfn func(*Decoder, *codecFnInfo, reflect.Value) } type fastpathA [0]fastpathE func fastpathAvIndex(rtid uintptr) int { return -1 } var fastpathAv fastpathA var fastpathTV fastpathT go-1.2.8/codec/gen-dec-array.go.tmpl000066400000000000000000000056021435255326100171350ustar00rootroot00000000000000{{var "v"}} := {{if not isArray}}*{{end}}{{ .Varname }} {{var "h"}}, {{var "l"}} := z.DecSliceHelperStart() {{/* // helper, containerLenS */}} {{if not isArray -}} var {{var "c"}} bool {{/* // changed */}} _ = {{var "c"}} if {{var "h"}}.IsNil { if {{var "v"}} != nil { {{var "v"}} = nil {{var "c"}} = true } } else {{end -}} if {{var "l"}} == 0 { {{if isSlice -}} if {{var "v"}} == nil { {{var "v"}} = []{{ .Typ }}{} {{var "c"}} = true } else if len({{var "v"}}) != 0 { {{var "v"}} = {{var "v"}}[:0] {{var "c"}} = true } {{else if isChan }}if {{var "v"}} == nil { {{var "v"}} = make({{ .CTyp }}, 0) {{var "c"}} = true } {{end -}} } else { {{var "hl"}} := {{var "l"}} > 0 var {{var "rl"}} int _ = {{var "rl"}} {{if isSlice }} if {{var "hl"}} { if {{var "l"}} > cap({{var "v"}}) { {{var "rl"}} = z.DecInferLen({{var "l"}}, z.DecBasicHandle().MaxInitLen, {{ .Size }}) if {{var "rl"}} <= cap({{var "v"}}) { {{var "v"}} = {{var "v"}}[:{{var "rl"}}] } else { {{var "v"}} = make([]{{ .Typ }}, {{var "rl"}}) } {{var "c"}} = true } else if {{var "l"}} != len({{var "v"}}) { {{var "v"}} = {{var "v"}}[:{{var "l"}}] {{var "c"}} = true } } {{end -}} var {{var "j"}} int {{/* // var {{var "dn"}} bool */ -}} for {{var "j"}} = 0; ({{var "hl"}} && {{var "j"}} < {{var "l"}}) || !({{var "hl"}} || z.DecCheckBreak()); {{var "j"}}++ { // bounds-check-elimination {{if not isArray}} if {{var "j"}} == 0 && {{var "v"}} == nil { if {{var "hl"}} { {{var "rl"}} = z.DecInferLen({{var "l"}}, z.DecBasicHandle().MaxInitLen, {{ .Size }}) } else { {{var "rl"}} = {{if isSlice}}8{{else if isChan}}64{{end}} } {{var "v"}} = make({{if isSlice}}[]{{ .Typ }}{{else if isChan}}{{.CTyp}}{{end}}, {{var "rl"}}) {{var "c"}} = true } {{end -}} {{var "h"}}.ElemContainerState({{var "j"}}) {{/* {{var "dn"}} = r.TryDecodeAsNil() */}}{{/* commented out, as decLineVar handles this already each time */ -}} {{if isChan}}{{ $x := printf "%[1]vvcx%[2]v" .TempVar .Rand }}var {{$x}} {{ .Typ }} {{ decLineVar $x -}} {{var "v"}} <- {{ $x }} {{else}}{{/* // if indefinite, etc, then expand the slice if necessary */ -}} var {{var "db"}} bool if {{var "j"}} >= len({{var "v"}}) { {{if isSlice }} {{var "v"}} = append({{var "v"}}, {{ zero }}) {{var "c"}} = true {{else}} z.DecArrayCannotExpand(len(v), {{var "j"}}+1); {{var "db"}} = true {{end -}} } if {{var "db"}} { z.DecSwallow() } else { {{ $x := printf "%[1]vv%[2]v[%[1]vj%[2]v]" .TempVar .Rand }}{{ decLineVar $x -}} } {{end -}} } {{if isSlice}} if {{var "j"}} < len({{var "v"}}) { {{var "v"}} = {{var "v"}}[:{{var "j"}}] {{var "c"}} = true } else if {{var "j"}} == 0 && {{var "v"}} == nil { {{var "v"}} = []{{ .Typ }}{} {{var "c"}} = true } {{end -}} } {{var "h"}}.End() {{if not isArray }}if {{var "c"}} { *{{ .Varname }} = {{var "v"}} } {{end -}} go-1.2.8/codec/gen-dec-map.go.tmpl000066400000000000000000000040761435255326100166000ustar00rootroot00000000000000{{var "v"}} := *{{ .Varname }} {{var "l"}} := z.DecReadMapStart() if {{var "l"}} == codecSelferDecContainerLenNil{{xs}} { *{{ .Varname }} = nil } else { if {{var "v"}} == nil { {{var "rl"}} := z.DecInferLen({{var "l"}}, z.DecBasicHandle().MaxInitLen, {{ .Size }}) {{var "v"}} = make(map[{{ .KTyp }}]{{ .Typ }}, {{var "rl"}}) *{{ .Varname }} = {{var "v"}} } {{ $mk := var "mk" -}} var {{ $mk }} {{ .KTyp }} var {{var "mv"}} {{ .Typ }} var {{var "mg"}}, {{var "mdn"}} {{if decElemKindPtr}}, {{var "ms"}}, {{var "mok"}}{{end}} bool if z.DecBasicHandle().MapValueReset { {{if decElemKindPtr}}{{var "mg"}} = true {{else if decElemKindIntf}}if !z.DecBasicHandle().InterfaceReset { {{var "mg"}} = true } {{else if not decElemKindImmutable}}{{var "mg"}} = true {{end}} } if {{var "l"}} != 0 { {{var "hl"}} := {{var "l"}} > 0 for {{var "j"}} := 0; ({{var "hl"}} && {{var "j"}} < {{var "l"}}) || !({{var "hl"}} || z.DecCheckBreak()); {{var "j"}}++ { z.DecReadMapElemKey() {{ if eq .KTyp "string" -}} {{ decLineVarK $mk -}}{{- /* decLineVarKStrZC $mk */ -}} {{ else -}} {{ decLineVarK $mk -}} {{ end -}} {{ if eq .KTyp "interface{}" }}{{/* // special case if a byte array. */ -}} if {{var "bv"}}, {{var "bok"}} := {{var "mk"}}.([]byte); {{var "bok"}} { {{var "mk"}} = z.DecStringZC({{var "bv"}}) } {{ end -}} {{if decElemKindPtr -}} {{var "ms"}} = true {{end -}} if {{var "mg"}} { {{if decElemKindPtr -}} {{var "mv"}}, {{var "mok"}} = {{var "v"}}[{{ $mk }}] if {{var "mok"}} { {{var "ms"}} = false } {{else -}} {{var "mv"}} = {{var "v"}}[{{ $mk }}] {{end -}} } {{if not decElemKindImmutable}}else { {{var "mv"}} = {{decElemZero}} }{{end}} z.DecReadMapElemValue() {{var "mdn"}} = false {{ $x := printf "%vmv%v" .TempVar .Rand }}{{ $y := printf "%vmdn%v" .TempVar .Rand }}{{ decLineVar $x $y -}} if {{var "mdn"}} { {{var "v"}}[{{ $mk }}] = {{decElemZero}} } else {{if decElemKindPtr}} if {{var "ms"}} {{end}} { {{var "v"}}[{{ $mk }}] = {{var "mv"}} } } } // else len==0: leave as-is (do not clear map entries) z.DecReadMapEnd() } go-1.2.8/codec/gen-enc-chan.go.tmpl000066400000000000000000000012071435255326100167370ustar00rootroot00000000000000{{.Label}}: switch timeout{{.Sfx}} := z.EncBasicHandle().ChanRecvTimeout; { case timeout{{.Sfx}} == 0: // only consume available for { select { case b{{.Sfx}} := <-{{.Chan}}: {{ .Slice }} = append({{.Slice}}, b{{.Sfx}}) default: break {{.Label}} } } case timeout{{.Sfx}} > 0: // consume until timeout tt{{.Sfx}} := time.NewTimer(timeout{{.Sfx}}) for { select { case b{{.Sfx}} := <-{{.Chan}}: {{.Slice}} = append({{.Slice}}, b{{.Sfx}}) case <-tt{{.Sfx}}.C: // close(tt.C) break {{.Label}} } } default: // consume until close for b{{.Sfx}} := range {{.Chan}} { {{.Slice}} = append({{.Slice}}, b{{.Sfx}}) } } go-1.2.8/codec/gen-helper.generated.go000066400000000000000000000244231435255326100175310ustar00rootroot00000000000000// comment this out // + build ignore // 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 gen-helper.go.tmpl - DO NOT EDIT. package codec import ( "encoding" "reflect" ) // GenVersion is the current version of codecgen. const GenVersion = 25 // This file is used to generate helper code for codecgen. // The values here i.e. genHelper(En|De)coder are not to be used directly by // library users. They WILL change continuously and without notice. // GenHelperEncoder is exported so that it can be used externally by codecgen. // // Library users: DO NOT USE IT DIRECTLY or INDIRECTLY. IT WILL CHANGE CONTINOUSLY WITHOUT NOTICE. func GenHelper() (g genHelper) { return } type genHelper struct{} func (genHelper) Encoder(e *Encoder) (ge genHelperEncoder, ee genHelperEncDriver) { ge = genHelperEncoder{e: e} ee = genHelperEncDriver{encDriver: e.e} return } func (genHelper) Decoder(d *Decoder) (gd genHelperDecoder, dd genHelperDecDriver) { gd = genHelperDecoder{d: d} dd = genHelperDecDriver{decDriver: d.d} return } type genHelperEncDriver struct { encDriver } type genHelperDecDriver struct { decDriver } // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE* type genHelperEncoder struct { M mustHdl F fastpathT e *Encoder } // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE* type genHelperDecoder struct { C checkOverflow F fastpathT d *Decoder } // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE* func (f genHelperEncoder) EncBasicHandle() *BasicHandle { return f.e.h } // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE* func (f genHelperEncoder) EncBinary() bool { return f.e.be // f.e.hh.isBinaryEncoding() } // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE* func (f genHelperEncoder) IsJSONHandle() bool { return f.e.js } // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE* func (f genHelperEncoder) EncFallback(iv interface{}) { // f.e.encodeI(iv, false, false) f.e.encodeValue(reflect.ValueOf(iv), nil) } // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE* func (f genHelperEncoder) EncTextMarshal(iv encoding.TextMarshaler) { bs, fnerr := iv.MarshalText() f.e.marshalUtf8(bs, fnerr) } // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE* func (f genHelperEncoder) EncJSONMarshal(iv jsonMarshaler) { bs, fnerr := iv.MarshalJSON() f.e.marshalAsis(bs, fnerr) } // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE* func (f genHelperEncoder) EncBinaryMarshal(iv encoding.BinaryMarshaler) { bs, fnerr := iv.MarshalBinary() f.e.marshalRaw(bs, fnerr) } // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE* func (f genHelperEncoder) EncRaw(iv Raw) { f.e.rawBytes(iv) } // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE* func (f genHelperEncoder) Extension(v interface{}) (xfn *extTypeTagFn) { return f.e.h.getExtForI(v) } // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE* func (f genHelperEncoder) EncExtension(v interface{}, xfFn *extTypeTagFn) { f.e.e.EncodeExt(v, xfFn.rt, xfFn.tag, xfFn.ext) } // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE* func (f genHelperEncoder) WriteStr(s string) { f.e.w().writestr(s) } // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE* func (f genHelperEncoder) EncWriteMapStart(length int) { f.e.mapStart(length) } // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE* func (f genHelperEncoder) EncWriteMapEnd() { f.e.mapEnd() } // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE* func (f genHelperEncoder) EncWriteArrayStart(length int) { f.e.arrayStart(length) } // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE* func (f genHelperEncoder) EncWriteArrayEnd() { f.e.arrayEnd() } // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE* func (f genHelperEncoder) EncWriteArrayElem() { f.e.arrayElem() } // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE* func (f genHelperEncoder) EncWriteMapElemKey() { f.e.mapElemKey() } // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE* func (f genHelperEncoder) EncWriteMapElemValue() { f.e.mapElemValue() } // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE* func (f genHelperEncoder) EncEncodeComplex64(v complex64) { f.e.encodeComplex64(v) } // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE* func (f genHelperEncoder) EncEncodeComplex128(v complex128) { f.e.encodeComplex128(v) } // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE* func (f genHelperEncoder) EncEncode(v interface{}) { f.e.encode(v) } // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE* func (f genHelperEncoder) EncFnGivenAddr(v interface{}) *codecFn { return f.e.h.fn(reflect.TypeOf(v).Elem()) } // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE* func (f genHelperEncoder) EncEncodeNumBoolStrKindGivenAddr(v interface{}, encFn *codecFn) { f.e.encodeValueNonNil(reflect.ValueOf(v).Elem(), encFn) } // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE* func (f genHelperEncoder) EncEncodeMapNonNil(v interface{}) { if skipFastpathTypeSwitchInDirectCall || !fastpathEncodeTypeSwitch(v, f.e) { f.e.encodeValueNonNil(reflect.ValueOf(v), nil) } } // ---------------- DECODER FOLLOWS ----------------- // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE* func (f genHelperDecoder) DecBasicHandle() *BasicHandle { return f.d.h } // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE* func (f genHelperDecoder) DecBinary() bool { return f.d.be // f.d.hh.isBinaryEncoding() } // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE* func (f genHelperDecoder) DecSwallow() { f.d.swallow() } // // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE* // func (f genHelperDecoder) DecScratchBuffer() []byte { // return f.d.b[:] // } // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE* func (f genHelperDecoder) DecScratchArrayBuffer() *[decScratchByteArrayLen]byte { return &f.d.b } // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE* func (f genHelperDecoder) DecFallback(iv interface{}, chkPtr bool) { rv := reflect.ValueOf(iv) if chkPtr { if x, _ := isDecodeable(rv); !x { f.d.haltAsNotDecodeable(rv) } } f.d.decodeValue(rv, nil) } // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE* func (f genHelperDecoder) DecSliceHelperStart() (decSliceHelper, int) { return f.d.decSliceHelperStart() } // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE* func (f genHelperDecoder) DecStructFieldNotFound(index int, name string) { f.d.structFieldNotFound(index, name) } // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE* func (f genHelperDecoder) DecArrayCannotExpand(sliceLen, streamLen int) { f.d.arrayCannotExpand(sliceLen, streamLen) } // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE* func (f genHelperDecoder) DecTextUnmarshal(tm encoding.TextUnmarshaler) { halt.onerror(tm.UnmarshalText(f.d.d.DecodeStringAsBytes())) } // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE* func (f genHelperDecoder) DecJSONUnmarshal(tm jsonUnmarshaler) { f.d.jsonUnmarshalV(tm) } // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE* func (f genHelperDecoder) DecBinaryUnmarshal(bm encoding.BinaryUnmarshaler) { halt.onerror(bm.UnmarshalBinary(f.d.d.DecodeBytes(nil))) } // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE* func (f genHelperDecoder) DecRaw() []byte { return f.d.rawBytes() } // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE* func (f genHelperDecoder) IsJSONHandle() bool { return f.d.js } // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE* func (f genHelperDecoder) Extension(v interface{}) (xfn *extTypeTagFn) { return f.d.h.getExtForI(v) } // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE* func (f genHelperDecoder) DecExtension(v interface{}, xfFn *extTypeTagFn) { f.d.d.DecodeExt(v, xfFn.rt, xfFn.tag, xfFn.ext) } // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE* func (f genHelperDecoder) DecInferLen(clen, maxlen, unit int) (rvlen int) { return decInferLen(clen, maxlen, unit) } // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE* func (f genHelperDecoder) DecReadMapStart() int { return f.d.mapStart(f.d.d.ReadMapStart()) } // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE* func (f genHelperDecoder) DecReadMapEnd() { f.d.mapEnd() } // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE* func (f genHelperDecoder) DecReadArrayStart() int { return f.d.arrayStart(f.d.d.ReadArrayStart()) } // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE* func (f genHelperDecoder) DecReadArrayEnd() { f.d.arrayEnd() } // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE* func (f genHelperDecoder) DecReadArrayElem() { f.d.arrayElem() } // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE* func (f genHelperDecoder) DecReadMapElemKey() { f.d.mapElemKey() } // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE* func (f genHelperDecoder) DecReadMapElemValue() { f.d.mapElemValue() } // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE* func (f genHelperDecoder) DecDecodeFloat32() float32 { return f.d.decodeFloat32() } // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE* func (f genHelperDecoder) DecCheckBreak() bool { return f.d.checkBreak() } // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE* func (f genHelperDecoder) DecStringZC(v []byte) string { return f.d.stringZC(v) } // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE* func (f genHelperDecoder) DecodeBytesInto(v []byte) []byte { return f.d.decodeBytesInto(v) } go-1.2.8/codec/gen-helper.go.tmpl000066400000000000000000000253641435255326100165540ustar00rootroot00000000000000// comment this out // + build ignore // 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 gen-helper.go.tmpl - DO NOT EDIT. package codec import ( "encoding" "reflect" ) // GenVersion is the current version of codecgen. const GenVersion = {{ .Version }} // This file is used to generate helper code for codecgen. // The values here i.e. genHelper(En|De)coder are not to be used directly by // library users. They WILL change continuously and without notice. {{/* // To help enforce this, we create an unexported type with exported members. // The only way to get the type is via the one exported type that we control (somewhat). // // When static codecs are created for types, they will use this value // to perform encoding or decoding of primitives or known slice or map types. */ -}} // GenHelperEncoder is exported so that it can be used externally by codecgen. // // Library users: DO NOT USE IT DIRECTLY or INDIRECTLY. IT WILL CHANGE CONTINOUSLY WITHOUT NOTICE. func GenHelper() (g genHelper) { return } type genHelper struct {} func (genHelper) Encoder(e *Encoder) (ge genHelperEncoder, ee genHelperEncDriver) { ge = genHelperEncoder{e: e} ee = genHelperEncDriver{encDriver: e.e} return } func (genHelper) Decoder(d *Decoder) (gd genHelperDecoder, dd genHelperDecDriver) { gd = genHelperDecoder{d: d} dd = genHelperDecDriver{decDriver: d.d} return } type genHelperEncDriver struct { encDriver } type genHelperDecDriver struct { decDriver } // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE* type genHelperEncoder struct { M mustHdl F fastpathT e *Encoder } // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE* type genHelperDecoder struct { C checkOverflow F fastpathT d *Decoder } // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE* func (f genHelperEncoder) EncBasicHandle() *BasicHandle { return f.e.h } // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE* func (f genHelperEncoder) EncBinary() bool { return f.e.be // f.e.hh.isBinaryEncoding() } // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE* func (f genHelperEncoder) IsJSONHandle() bool { return f.e.js } // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE* func (f genHelperEncoder) EncFallback(iv interface{}) { // f.e.encodeI(iv, false, false) f.e.encodeValue(reflect.ValueOf(iv), nil) } // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE* func (f genHelperEncoder) EncTextMarshal(iv encoding.TextMarshaler) { bs, fnerr := iv.MarshalText() f.e.marshalUtf8(bs, fnerr) } // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE* func (f genHelperEncoder) EncJSONMarshal(iv jsonMarshaler) { bs, fnerr := iv.MarshalJSON() f.e.marshalAsis(bs, fnerr) } // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE* func (f genHelperEncoder) EncBinaryMarshal(iv encoding.BinaryMarshaler) { bs, fnerr := iv.MarshalBinary() f.e.marshalRaw(bs, fnerr) } // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE* func (f genHelperEncoder) EncRaw(iv Raw) { f.e.rawBytes(iv) } // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE* func (f genHelperEncoder) Extension(v interface{}) (xfn *extTypeTagFn) { return f.e.h.getExtForI(v) } // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE* func (f genHelperEncoder) EncExtension(v interface{}, xfFn *extTypeTagFn) { f.e.e.EncodeExt(v, xfFn.rt, xfFn.tag, xfFn.ext) } // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE* func (f genHelperEncoder) WriteStr(s string) { f.e.w().writestr(s) } // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE* func (f genHelperEncoder) EncWriteMapStart(length int) { f.e.mapStart(length) } // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE* func (f genHelperEncoder) EncWriteMapEnd() { f.e.mapEnd() } // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE* func (f genHelperEncoder) EncWriteArrayStart(length int) { f.e.arrayStart(length) } // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE* func (f genHelperEncoder) EncWriteArrayEnd() { f.e.arrayEnd() } // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE* func (f genHelperEncoder) EncWriteArrayElem() { f.e.arrayElem() } // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE* func (f genHelperEncoder) EncWriteMapElemKey() { f.e.mapElemKey() } // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE* func (f genHelperEncoder) EncWriteMapElemValue() { f.e.mapElemValue() } // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE* func (f genHelperEncoder) EncEncodeComplex64(v complex64) { f.e.encodeComplex64(v) } // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE* func (f genHelperEncoder) EncEncodeComplex128(v complex128) { f.e.encodeComplex128(v) } // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE* func (f genHelperEncoder) EncEncode(v interface{}) { f.e.encode(v) } // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE* func (f genHelperEncoder) EncFnGivenAddr(v interface{}) *codecFn { return f.e.h.fn(reflect.TypeOf(v).Elem()) } // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE* func (f genHelperEncoder) EncEncodeNumBoolStrKindGivenAddr(v interface{}, encFn *codecFn) { f.e.encodeValueNonNil(reflect.ValueOf(v).Elem(), encFn) } // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE* func (f genHelperEncoder) EncEncodeMapNonNil(v interface{}) { if skipFastpathTypeSwitchInDirectCall || !fastpathEncodeTypeSwitch(v, f.e) { f.e.encodeValueNonNil(reflect.ValueOf(v), nil) } } // ---------------- DECODER FOLLOWS ----------------- // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE* func (f genHelperDecoder) DecBasicHandle() *BasicHandle { return f.d.h } // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE* func (f genHelperDecoder) DecBinary() bool { return f.d.be // f.d.hh.isBinaryEncoding() } // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE* func (f genHelperDecoder) DecSwallow() { f.d.swallow() } // // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE* // func (f genHelperDecoder) DecScratchBuffer() []byte { // return f.d.b[:] // } // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE* func (f genHelperDecoder) DecScratchArrayBuffer() *[decScratchByteArrayLen]byte { return &f.d.b } // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE* func (f genHelperDecoder) DecFallback(iv interface{}, chkPtr bool) { rv := reflect.ValueOf(iv) if chkPtr { if x, _ := isDecodeable(rv); !x { f.d.haltAsNotDecodeable(rv) } } f.d.decodeValue(rv, nil) } // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE* func (f genHelperDecoder) DecSliceHelperStart() (decSliceHelper, int) { return f.d.decSliceHelperStart() } // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE* func (f genHelperDecoder) DecStructFieldNotFound(index int, name string) { f.d.structFieldNotFound(index, name) } // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE* func (f genHelperDecoder) DecArrayCannotExpand(sliceLen, streamLen int) { f.d.arrayCannotExpand(sliceLen, streamLen) } // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE* func (f genHelperDecoder) DecTextUnmarshal(tm encoding.TextUnmarshaler) { halt.onerror(tm.UnmarshalText(f.d.d.DecodeStringAsBytes())) } // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE* func (f genHelperDecoder) DecJSONUnmarshal(tm jsonUnmarshaler) { f.d.jsonUnmarshalV(tm) } // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE* func (f genHelperDecoder) DecBinaryUnmarshal(bm encoding.BinaryUnmarshaler) { halt.onerror(bm.UnmarshalBinary(f.d.d.DecodeBytes(nil))) } // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE* func (f genHelperDecoder) DecRaw() []byte { return f.d.rawBytes() } // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE* func (f genHelperDecoder) IsJSONHandle() bool { return f.d.js } {{/* // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE* func (f genHelperDecoder) I2Rtid(v interface{}) uintptr { return i2rtid(v) } */ -}} // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE* func (f genHelperDecoder) Extension(v interface{}) (xfn *extTypeTagFn) { return f.d.h.getExtForI(v) } // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE* func (f genHelperDecoder) DecExtension(v interface{}, xfFn *extTypeTagFn) { f.d.d.DecodeExt(v, xfFn.rt, xfFn.tag, xfFn.ext) } // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE* func (f genHelperDecoder) DecInferLen(clen, maxlen, unit int) (rvlen int) { return decInferLen(clen, maxlen, unit) } // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE* func (f genHelperDecoder) DecReadMapStart() int { return f.d.mapStart(f.d.d.ReadMapStart()) } // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE* func (f genHelperDecoder) DecReadMapEnd() { f.d.mapEnd() } // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE* func (f genHelperDecoder) DecReadArrayStart() int { return f.d.arrayStart(f.d.d.ReadArrayStart()) } // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE* func (f genHelperDecoder) DecReadArrayEnd() { f.d.arrayEnd() } // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE* func (f genHelperDecoder) DecReadArrayElem() { f.d.arrayElem() } // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE* func (f genHelperDecoder) DecReadMapElemKey() { f.d.mapElemKey() } // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE* func (f genHelperDecoder) DecReadMapElemValue() { f.d.mapElemValue() } // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE* func (f genHelperDecoder) DecDecodeFloat32() float32 { return f.d.decodeFloat32() } // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE* func (f genHelperDecoder) DecCheckBreak() bool { return f.d.checkBreak() } // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE* func (f genHelperDecoder) DecStringZC(v []byte) string { return f.d.stringZC(v) } // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE* func (f genHelperDecoder) DecodeBytesInto(v []byte) []byte { return f.d.decodeBytesInto(v) } go-1.2.8/codec/gen.generated.go000066400000000000000000000136411435255326100162540ustar00rootroot00000000000000// +build codecgen.exec // 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 // DO NOT EDIT. THIS FILE IS AUTO-GENERATED FROM gen-dec-(map|array).go.tmpl const genDecMapTmpl = ` {{var "v"}} := *{{ .Varname }} {{var "l"}} := z.DecReadMapStart() if {{var "l"}} == codecSelferDecContainerLenNil{{xs}} { *{{ .Varname }} = nil } else { if {{var "v"}} == nil { {{var "rl"}} := z.DecInferLen({{var "l"}}, z.DecBasicHandle().MaxInitLen, {{ .Size }}) {{var "v"}} = make(map[{{ .KTyp }}]{{ .Typ }}, {{var "rl"}}) *{{ .Varname }} = {{var "v"}} } {{ $mk := var "mk" -}} var {{ $mk }} {{ .KTyp }} var {{var "mv"}} {{ .Typ }} var {{var "mg"}}, {{var "mdn"}} {{if decElemKindPtr}}, {{var "ms"}}, {{var "mok"}}{{end}} bool if z.DecBasicHandle().MapValueReset { {{if decElemKindPtr}}{{var "mg"}} = true {{else if decElemKindIntf}}if !z.DecBasicHandle().InterfaceReset { {{var "mg"}} = true } {{else if not decElemKindImmutable}}{{var "mg"}} = true {{end}} } if {{var "l"}} != 0 { {{var "hl"}} := {{var "l"}} > 0 for {{var "j"}} := 0; ({{var "hl"}} && {{var "j"}} < {{var "l"}}) || !({{var "hl"}} || z.DecCheckBreak()); {{var "j"}}++ { z.DecReadMapElemKey() {{ if eq .KTyp "string" -}} {{ decLineVarK $mk -}}{{- /* decLineVarKStrZC $mk */ -}} {{ else -}} {{ decLineVarK $mk -}} {{ end -}} {{ if eq .KTyp "interface{}" }}{{/* // special case if a byte array. */ -}} if {{var "bv"}}, {{var "bok"}} := {{var "mk"}}.([]byte); {{var "bok"}} { {{var "mk"}} = z.DecStringZC({{var "bv"}}) } {{ end -}} {{if decElemKindPtr -}} {{var "ms"}} = true {{end -}} if {{var "mg"}} { {{if decElemKindPtr -}} {{var "mv"}}, {{var "mok"}} = {{var "v"}}[{{ $mk }}] if {{var "mok"}} { {{var "ms"}} = false } {{else -}} {{var "mv"}} = {{var "v"}}[{{ $mk }}] {{end -}} } {{if not decElemKindImmutable}}else { {{var "mv"}} = {{decElemZero}} }{{end}} z.DecReadMapElemValue() {{var "mdn"}} = false {{ $x := printf "%vmv%v" .TempVar .Rand }}{{ $y := printf "%vmdn%v" .TempVar .Rand }}{{ decLineVar $x $y -}} if {{var "mdn"}} { {{var "v"}}[{{ $mk }}] = {{decElemZero}} } else {{if decElemKindPtr}} if {{var "ms"}} {{end}} { {{var "v"}}[{{ $mk }}] = {{var "mv"}} } } } // else len==0: leave as-is (do not clear map entries) z.DecReadMapEnd() } ` const genDecListTmpl = ` {{var "v"}} := {{if not isArray}}*{{end}}{{ .Varname }} {{var "h"}}, {{var "l"}} := z.DecSliceHelperStart() {{/* // helper, containerLenS */}} {{if not isArray -}} var {{var "c"}} bool {{/* // changed */}} _ = {{var "c"}} if {{var "h"}}.IsNil { if {{var "v"}} != nil { {{var "v"}} = nil {{var "c"}} = true } } else {{end -}} if {{var "l"}} == 0 { {{if isSlice -}} if {{var "v"}} == nil { {{var "v"}} = []{{ .Typ }}{} {{var "c"}} = true } else if len({{var "v"}}) != 0 { {{var "v"}} = {{var "v"}}[:0] {{var "c"}} = true } {{else if isChan }}if {{var "v"}} == nil { {{var "v"}} = make({{ .CTyp }}, 0) {{var "c"}} = true } {{end -}} } else { {{var "hl"}} := {{var "l"}} > 0 var {{var "rl"}} int _ = {{var "rl"}} {{if isSlice }} if {{var "hl"}} { if {{var "l"}} > cap({{var "v"}}) { {{var "rl"}} = z.DecInferLen({{var "l"}}, z.DecBasicHandle().MaxInitLen, {{ .Size }}) if {{var "rl"}} <= cap({{var "v"}}) { {{var "v"}} = {{var "v"}}[:{{var "rl"}}] } else { {{var "v"}} = make([]{{ .Typ }}, {{var "rl"}}) } {{var "c"}} = true } else if {{var "l"}} != len({{var "v"}}) { {{var "v"}} = {{var "v"}}[:{{var "l"}}] {{var "c"}} = true } } {{end -}} var {{var "j"}} int {{/* // var {{var "dn"}} bool */ -}} for {{var "j"}} = 0; ({{var "hl"}} && {{var "j"}} < {{var "l"}}) || !({{var "hl"}} || z.DecCheckBreak()); {{var "j"}}++ { // bounds-check-elimination {{if not isArray}} if {{var "j"}} == 0 && {{var "v"}} == nil { if {{var "hl"}} { {{var "rl"}} = z.DecInferLen({{var "l"}}, z.DecBasicHandle().MaxInitLen, {{ .Size }}) } else { {{var "rl"}} = {{if isSlice}}8{{else if isChan}}64{{end}} } {{var "v"}} = make({{if isSlice}}[]{{ .Typ }}{{else if isChan}}{{.CTyp}}{{end}}, {{var "rl"}}) {{var "c"}} = true } {{end -}} {{var "h"}}.ElemContainerState({{var "j"}}) {{/* {{var "dn"}} = r.TryDecodeAsNil() */}}{{/* commented out, as decLineVar handles this already each time */ -}} {{if isChan}}{{ $x := printf "%[1]vvcx%[2]v" .TempVar .Rand }}var {{$x}} {{ .Typ }} {{ decLineVar $x -}} {{var "v"}} <- {{ $x }} {{else}}{{/* // if indefinite, etc, then expand the slice if necessary */ -}} var {{var "db"}} bool if {{var "j"}} >= len({{var "v"}}) { {{if isSlice }} {{var "v"}} = append({{var "v"}}, {{ zero }}) {{var "c"}} = true {{else}} z.DecArrayCannotExpand(len(v), {{var "j"}}+1); {{var "db"}} = true {{end -}} } if {{var "db"}} { z.DecSwallow() } else { {{ $x := printf "%[1]vv%[2]v[%[1]vj%[2]v]" .TempVar .Rand }}{{ decLineVar $x -}} } {{end -}} } {{if isSlice}} if {{var "j"}} < len({{var "v"}}) { {{var "v"}} = {{var "v"}}[:{{var "j"}}] {{var "c"}} = true } else if {{var "j"}} == 0 && {{var "v"}} == nil { {{var "v"}} = []{{ .Typ }}{} {{var "c"}} = true } {{end -}} } {{var "h"}}.End() {{if not isArray }}if {{var "c"}} { *{{ .Varname }} = {{var "v"}} } {{end -}} ` const genEncChanTmpl = ` {{.Label}}: switch timeout{{.Sfx}} := z.EncBasicHandle().ChanRecvTimeout; { case timeout{{.Sfx}} == 0: // only consume available for { select { case b{{.Sfx}} := <-{{.Chan}}: {{ .Slice }} = append({{.Slice}}, b{{.Sfx}}) default: break {{.Label}} } } case timeout{{.Sfx}} > 0: // consume until timeout tt{{.Sfx}} := time.NewTimer(timeout{{.Sfx}}) for { select { case b{{.Sfx}} := <-{{.Chan}}: {{.Slice}} = append({{.Slice}}, b{{.Sfx}}) case <-tt{{.Sfx}}.C: // close(tt.C) break {{.Label}} } } default: // consume until close for b{{.Sfx}} := range {{.Chan}} { {{.Slice}} = append({{.Slice}}, b{{.Sfx}}) } } ` go-1.2.8/codec/gen.go000066400000000000000000002575301435255326100143260ustar00rootroot00000000000000// 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 codecgen.exec // +build codecgen.exec package codec import ( "bytes" "encoding/base64" "errors" "fmt" "go/format" "io" "io/ioutil" "math/rand" "os" "reflect" "regexp" "sort" "strconv" "strings" "sync" "text/template" "time" // "ugorji.net/zz" "unicode" "unicode/utf8" ) // --------------------------------------------------- // codecgen supports the full cycle of reflection-based codec: // - RawExt // - Raw // - Extensions // - (Binary|Text|JSON)(Unm|M)arshal // - generic by-kind // // This means that, for dynamic things, we MUST use reflection to at least get the reflect.Type. // In those areas, we try to only do reflection or interface-conversion when NECESSARY: // - Extensions, only if Extensions are configured. // // However, note following codecgen caveats: // - Canonical option. // If Canonical=true, codecgen'ed code may delegate encoding maps to reflection-based code. // This is due to the runtime work needed to marshal a map in canonical mode. // However, if map key is a pre-defined/builtin numeric or string type, codecgen // will try to write it out itself // - CheckCircularRef option. // When encoding a struct, a circular reference can lead to a stack overflow. // If CheckCircularRef=true, codecgen'ed code will delegate encoding structs to reflection-based code. // - MissingFielder implementation. // If a type implements MissingFielder, a Selfer is not generated (with a warning message). // Statically reproducing the runtime work needed to extract the missing fields and marshal them // along with the struct fields, while handling the Canonical=true special case, was onerous to implement. // // During encode/decode, Selfer takes precedence. // A type implementing Selfer will know how to encode/decode itself statically. // // The following field types are supported: // array: [n]T // slice: []T // map: map[K]V // primitive: [u]int[n], float(32|64), bool, string // struct // // --------------------------------------------------- // Note that a Selfer cannot call (e|d).(En|De)code on itself, // as this will cause a circular reference, as (En|De)code will call Selfer methods. // Any type that implements Selfer must implement completely and not fallback to (En|De)code. // // In addition, code in this file manages the generation of fast-path implementations of // encode/decode of slices/maps of primitive keys/values. // // Users MUST re-generate their implementations whenever the code shape changes. // The generated code will panic if it was generated with a version older than the supporting library. // --------------------------------------------------- // // codec framework is very feature rich. // When encoding or decoding into an interface, it depends on the runtime type of the interface. // The type of the interface may be a named type, an extension, etc. // Consequently, we fallback to runtime codec for encoding/decoding interfaces. // In addition, we fallback for any value which cannot be guaranteed at runtime. // This allows us support ANY value, including any named types, specifically those which // do not implement our interfaces (e.g. Selfer). // // This explains some slowness compared to other code generation codecs (e.g. msgp). // This reduction in speed is only seen when your refers to interfaces, // e.g. type T struct { A interface{}; B []interface{}; C map[string]interface{} } // // codecgen will panic if the file was generated with an old version of the library in use. // // Note: // It was a conscious decision to have gen.go always explicitly call EncodeNil or TryDecodeAsNil. // This way, there isn't a function call overhead just to see that we should not enter a block of code. // // Note: // codecgen-generated code depends on the variables defined by fast-path.generated.go. // consequently, you cannot run with tags "codecgen codec.notfastpath". // // Note: // genInternalXXX functions are used for generating fast-path and other internally generated // files, and not for use in codecgen. // Size of a struct or value is not portable across machines, especially across 32-bit vs 64-bit // operating systems. This is due to types like int, uintptr, pointers, (and derived types like slice), etc // which use the natural word size on those machines, which may be 4 bytes (on 32-bit) or 8 bytes (on 64-bit). // // Within decInferLen calls, we may generate an explicit size of the entry. // We do this because decInferLen values are expected to be approximate, // and serve as a good hint on the size of the elements or key+value entry. // // Since development is done on 64-bit machines, the sizes will be roughly correctly // on 64-bit OS, and slightly larger than expected on 32-bit OS. // This is ok. // // For reference, look for 'Size' in fast-path.go.tmpl, gen-dec-(array|map).go.tmpl and gen.go (this file). // GenVersion is the current version of codecgen. // // MARKER: Increment this value each time codecgen changes fundamentally. // Also update codecgen/gen.go (minimumCodecVersion, genVersion, etc). // Fundamental changes are: // - helper methods change (signature change, new ones added, some removed, etc) // - codecgen command line changes // // v1: Initial Version // v2: - // v3: Changes for Kubernetes: // // changes in signature of some unpublished helper methods and codecgen cmdline arguments. // // v4: Removed separator support from (en|de)cDriver, and refactored codec(gen) // v5: changes to support faster json decoding. Let encoder/decoder maintain state of collections. // v6: removed unsafe from gen, and now uses codecgen.exec tag // v7: - // v8: current - we now maintain compatibility with old generated code. // v9: skipped // v10: modified encDriver and decDriver interfaces. // v11: remove deprecated methods of encDriver and decDriver. // v12: removed deprecated methods from genHelper and changed container tracking logic // v13: 20190603 removed DecodeString - use DecodeStringAsBytes instead // v14: 20190611 refactored nil handling: TryDecodeAsNil -> selective TryNil, etc // v15: 20190626 encDriver.EncodeString handles StringToRaw flag inside handle // v16: 20190629 refactoring for v1.1.6 // v17: 20200911 reduce number of types for which we generate fast path functions (v1.1.8) // v18: 20201004 changed definition of genHelper...Extension (to take interface{}) and eliminated I2Rtid method // v19: 20201115 updated codecgen cmdline flags and optimized output // v20: 20201120 refactored GenHelper to one exported function // v21: 20210104 refactored generated code to honor ZeroCopy=true for more efficiency // v22: 20210118 fixed issue in generated code when encoding a type which is also a codec.Selfer // v23: 20210203 changed slice/map types for which we generate fast-path functions // v24: 20210226 robust handling for Canonical|CheckCircularRef flags and MissingFielder implementations // v25: 20210406 pass base reflect.Type to side(En|De)code and (En|De)codeExt calls const genVersion = 25 const ( genCodecPkg = "codec1978" // MARKER: keep in sync with codecgen/gen.go genTempVarPfx = "yy" genTopLevelVarName = "x" // ignore canBeNil parameter, and always set to true. // This is because nil can appear anywhere, so we should always check. genAnythingCanBeNil = true // if genUseOneFunctionForDecStructMap, make a single codecDecodeSelferFromMap function; // else make codecDecodeSelferFromMap{LenPrefix,CheckBreak} so that conditionals // are not executed a lot. // // From testing, it didn't make much difference in runtime, so keep as true (one function only) genUseOneFunctionForDecStructMap = true // genStructCanonical configures whether we generate 2 paths based on Canonical flag // when encoding struct fields. genStructCanonical = true // genFastpathCanonical configures whether we support Canonical in fast path. // The savings is not much. // // MARKER: This MUST ALWAYS BE TRUE. fast-path.go.tmp doesn't handle it being false. genFastpathCanonical = true // genFastpathTrimTypes configures whether we trim uncommon fastpath types. genFastpathTrimTypes = true // genDecStructArrayInlineLoopCheck configures whether we create a next function // for each iteration in the loop and call it, or just inline it. // // with inlining, we get better performance but about 10% larger files. genDecStructArrayInlineLoopCheck = true ) type genStructMapStyle uint8 type genStringDecAsBytes string type genStringDecZC string var genStringDecAsBytesTyp = reflect.TypeOf(genStringDecAsBytes("")) var genStringDecZCTyp = reflect.TypeOf(genStringDecZC("")) var genFormats = []string{"Json", "Cbor", "Msgpack", "Binc", "Simple"} const ( genStructMapStyleConsolidated genStructMapStyle = iota genStructMapStyleLenPrefix genStructMapStyleCheckBreak ) var ( errGenAllTypesSamePkg = errors.New("All types must be in the same package") errGenExpectArrayOrMap = errors.New("unexpected type - expecting array/map/slice") errGenUnexpectedTypeFastpath = errors.New("fast-path: unexpected type - requires map or slice") genBase64enc = base64.NewEncoding("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789__") genQNameRegex = regexp.MustCompile(`[A-Za-z_.]+`) ) type genBuf struct { buf []byte } func (x *genBuf) sIf(b bool, s, t string) *genBuf { if b { x.buf = append(x.buf, s...) } else { x.buf = append(x.buf, t...) } return x } func (x *genBuf) s(s string) *genBuf { x.buf = append(x.buf, s...); return x } func (x *genBuf) b(s []byte) *genBuf { x.buf = append(x.buf, s...); return x } func (x *genBuf) v() string { return string(x.buf) } func (x *genBuf) f(s string, args ...interface{}) { x.s(fmt.Sprintf(s, args...)) } func (x *genBuf) reset() { if x.buf != nil { x.buf = x.buf[:0] } } // genRunner holds some state used during a Gen run. type genRunner struct { w io.Writer // output c uint64 // counter used for generating varsfx f uint64 // counter used for saying false t []reflect.Type // list of types to run selfer on tc reflect.Type // currently running selfer on this type te map[uintptr]bool // types for which the encoder has been created td map[uintptr]bool // types for which the decoder has been created tz map[uintptr]bool // types for which GenIsZero has been created cp string // codec import path im map[string]reflect.Type // imports to add imn map[string]string // package names of imports to add imc uint64 // counter for import numbers is map[reflect.Type]struct{} // types seen during import search bp string // base PkgPath, for which we are generating for cpfx string // codec package prefix ty map[reflect.Type]struct{} // types for which GenIsZero *should* be created tm map[reflect.Type]struct{} // types for which enc/dec must be generated ts []reflect.Type // types for which enc/dec must be generated xs string // top level variable/constant suffix hn string // fn helper type name ti *TypeInfos // rr *rand.Rand // random generator for file-specific types jsonOnlyWhen, toArrayWhen, omitEmptyWhen *bool nx bool // no extensions } type genIfClause struct { hasIf bool } func (g *genIfClause) end(x *genRunner) { if g.hasIf { x.line("}") } } func (g *genIfClause) c(last bool) (v string) { if last { if g.hasIf { v = " } else { " } } else if g.hasIf { v = " } else if " } else { v = "if " g.hasIf = true } return } // Gen will write a complete go file containing Selfer implementations for each // type passed. All the types must be in the same package. // // Library users: DO NOT USE IT DIRECTLY. IT WILL CHANGE CONTINUOUSLY WITHOUT NOTICE. func Gen(w io.Writer, buildTags, pkgName, uid string, noExtensions bool, jsonOnlyWhen, toArrayWhen, omitEmptyWhen *bool, ti *TypeInfos, types ...reflect.Type) (warnings []string) { // All types passed to this method do not have a codec.Selfer method implemented directly. // codecgen already checks the AST and skips any types that define the codec.Selfer methods. // Consequently, there's no need to check and trim them if they implement codec.Selfer if len(types) == 0 { return } x := genRunner{ w: w, t: types, te: make(map[uintptr]bool), td: make(map[uintptr]bool), tz: make(map[uintptr]bool), im: make(map[string]reflect.Type), imn: make(map[string]string), is: make(map[reflect.Type]struct{}), tm: make(map[reflect.Type]struct{}), ty: make(map[reflect.Type]struct{}), ts: []reflect.Type{}, bp: genImportPath(types[0]), xs: uid, ti: ti, jsonOnlyWhen: jsonOnlyWhen, toArrayWhen: toArrayWhen, omitEmptyWhen: omitEmptyWhen, nx: noExtensions, } if x.ti == nil { x.ti = defTypeInfos } if x.xs == "" { rr := rand.New(rand.NewSource(time.Now().UnixNano())) x.xs = strconv.FormatInt(rr.Int63n(9999), 10) } // gather imports first: x.cp = genImportPath(reflect.TypeOf(x)) x.imn[x.cp] = genCodecPkg // iterate, check if all in same package, and remove any missingfielders for i := 0; i < len(x.t); { t := x.t[i] // xdebugf("###########: PkgPath: '%v', Name: '%s'\n", genImportPath(t), t.Name()) if genImportPath(t) != x.bp { halt.onerror(errGenAllTypesSamePkg) } ti1 := x.ti.get(rt2id(t), t) if ti1.flagMissingFielder || ti1.flagMissingFielderPtr { // output diagnostic message - that nothing generated for this type warnings = append(warnings, fmt.Sprintf("type: '%v' not generated; implements codec.MissingFielder", t)) copy(x.t[i:], x.t[i+1:]) x.t = x.t[:len(x.t)-1] continue } x.genRefPkgs(t) i++ } x.line("// +build go1.6") if buildTags != "" { x.line("// +build " + buildTags) } x.line(` // Code generated by codecgen - DO NOT EDIT. `) x.line("package " + pkgName) x.line("") x.line("import (") if x.cp != x.bp { x.cpfx = genCodecPkg + "." x.linef("%s \"%s\"", genCodecPkg, x.cp) } // use a sorted set of im keys, so that we can get consistent output imKeys := make([]string, 0, len(x.im)) for k := range x.im { imKeys = append(imKeys, k) } sort.Strings(imKeys) for _, k := range imKeys { // for k, _ := range x.im { if k == x.imn[k] { x.linef("\"%s\"", k) } else { x.linef("%s \"%s\"", x.imn[k], k) } } // add required packages for _, k := range [...]string{"runtime", "errors", "strconv", "sort"} { // "reflect", "fmt" if _, ok := x.im[k]; !ok { x.line("\"" + k + "\"") } } x.line(")") x.line("") x.line("const (") x.linef("// ----- content types ----") x.linef("codecSelferCcUTF8%s = %v", x.xs, int64(cUTF8)) x.linef("codecSelferCcRAW%s = %v", x.xs, int64(cRAW)) x.linef("// ----- value types used ----") for _, vt := range [...]valueType{ valueTypeArray, valueTypeMap, valueTypeString, valueTypeInt, valueTypeUint, valueTypeFloat, valueTypeNil, } { x.linef("codecSelferValueType%s%s = %v", vt.String(), x.xs, int64(vt)) } x.linef("codecSelferBitsize%s = uint8(32 << (^uint(0) >> 63))", x.xs) x.linef("codecSelferDecContainerLenNil%s = %d", x.xs, int64(containerLenNil)) x.line(")") x.line("var (") x.line("errCodecSelferOnlyMapOrArrayEncodeToStruct" + x.xs + " = " + "errors.New(`only encoded map or array can be decoded into a struct`)") x.line("_ sort.Interface = nil") x.line(")") x.line("") x.hn = "codecSelfer" + x.xs x.line("type " + x.hn + " struct{}") x.line("") x.linef("func %sFalse() bool { return false }", x.hn) x.linef("func %sTrue() bool { return true }", x.hn) x.line("") // add types for sorting canonical for _, s := range []string{"string", "uint64", "int64", "float64"} { x.linef("type %s%sSlice []%s", x.hn, s, s) x.linef("func (p %s%sSlice) Len() int { return len(p) }", x.hn, s) x.linef("func (p %s%sSlice) Swap(i, j int) { p[uint(i)], p[uint(j)] = p[uint(j)], p[uint(i)] }", x.hn, s) x.linef("func (p %s%sSlice) Less(i, j int) bool { return p[uint(i)] < p[uint(j)] }", x.hn, s) } x.line("") x.varsfxreset() x.line("func init() {") x.linef("if %sGenVersion != %v {", x.cpfx, genVersion) x.line("_, file, _, _ := runtime.Caller(0)") x.linef("ver := strconv.FormatInt(int64(%sGenVersion), 10)", x.cpfx) x.outf(`panic(errors.New("codecgen version mismatch: current: %v, need " + ver + ". Re-generate file: " + file))`, genVersion) x.linef("}") if len(imKeys) > 0 { x.line("if false { // reference the types, but skip this branch at build/run time") for _, k := range imKeys { t := x.im[k] x.linef("var _ %s.%s", x.imn[k], t.Name()) } x.line("} ") // close if false } x.line("}") // close init x.line("") // generate rest of type info for _, t := range x.t { x.tc = t x.linef("func (%s) codecSelferViaCodecgen() {}", x.genTypeName(t)) x.selfer(true) x.selfer(false) x.tryGenIsZero(t) } for _, t := range x.ts { rtid := rt2id(t) // generate enc functions for all these slice/map types. x.varsfxreset() x.linef("func (x %s) enc%s(v %s%s, e *%sEncoder) {", x.hn, x.genMethodNameT(t), x.arr2str(t, "*"), x.genTypeName(t), x.cpfx) x.genRequiredMethodVars(true) switch t.Kind() { case reflect.Array, reflect.Slice, reflect.Chan: x.encListFallback("v", t) case reflect.Map: x.encMapFallback("v", t) default: halt.onerror(errGenExpectArrayOrMap) } x.line("}") x.line("") // generate dec functions for all these slice/map types. x.varsfxreset() x.linef("func (x %s) dec%s(v *%s, d *%sDecoder) {", x.hn, x.genMethodNameT(t), x.genTypeName(t), x.cpfx) x.genRequiredMethodVars(false) switch t.Kind() { case reflect.Array, reflect.Slice, reflect.Chan: x.decListFallback("v", rtid, t) case reflect.Map: x.decMapFallback("v", rtid, t) default: halt.onerror(errGenExpectArrayOrMap) } x.line("}") x.line("") } for t := range x.ty { x.tryGenIsZero(t) x.line("") } x.line("") return } func (x *genRunner) checkForSelfer(t reflect.Type, varname string) bool { // return varname != genTopLevelVarName && t != x.tc // the only time we checkForSelfer is if we are not at the TOP of the generated code. return varname != genTopLevelVarName } func (x *genRunner) arr2str(t reflect.Type, s string) string { if t.Kind() == reflect.Array { return s } return "" } func (x *genRunner) genRequiredMethodVars(encode bool) { x.line("var h " + x.hn) if encode { x.line("z, r := " + x.cpfx + "GenHelper().Encoder(e)") } else { x.line("z, r := " + x.cpfx + "GenHelper().Decoder(d)") } x.line("_, _, _ = h, z, r") } func (x *genRunner) genRefPkgs(t reflect.Type) { if _, ok := x.is[t]; ok { return } x.is[t] = struct{}{} tpkg, tname := genImportPath(t), t.Name() if tpkg != "" && tpkg != x.bp && tpkg != x.cp && tname != "" && tname[0] >= 'A' && tname[0] <= 'Z' { if _, ok := x.im[tpkg]; !ok { x.im[tpkg] = t if idx := strings.LastIndex(tpkg, "/"); idx < 0 { x.imn[tpkg] = tpkg } else { x.imc++ x.imn[tpkg] = "pkg" + strconv.FormatUint(x.imc, 10) + "_" + genGoIdentifier(tpkg[idx+1:], false) } } } switch t.Kind() { case reflect.Array, reflect.Slice, reflect.Ptr, reflect.Chan: x.genRefPkgs(t.Elem()) case reflect.Map: x.genRefPkgs(t.Elem()) x.genRefPkgs(t.Key()) case reflect.Struct: for i := 0; i < t.NumField(); i++ { if fname := t.Field(i).Name; fname != "" && fname[0] >= 'A' && fname[0] <= 'Z' { x.genRefPkgs(t.Field(i).Type) } } } } // sayFalse will either say "false" or use a function call that returns false. func (x *genRunner) sayFalse() string { x.f++ if x.f%2 == 0 { return x.hn + "False()" } return "false" } // sayFalse will either say "true" or use a function call that returns true. func (x *genRunner) sayTrue() string { x.f++ if x.f%2 == 0 { return x.hn + "True()" } return "true" } func (x *genRunner) varsfx() string { x.c++ return strconv.FormatUint(x.c, 10) } func (x *genRunner) varsfxreset() { x.c = 0 } func (x *genRunner) out(s string) { _, err := io.WriteString(x.w, s) genCheckErr(err) } func (x *genRunner) outf(s string, params ...interface{}) { _, err := fmt.Fprintf(x.w, s, params...) genCheckErr(err) } func (x *genRunner) line(s string) { x.out(s) if len(s) == 0 || s[len(s)-1] != '\n' { x.out("\n") } } func (x *genRunner) lineIf(s string) { if s != "" { x.line(s) } } func (x *genRunner) linef(s string, params ...interface{}) { x.outf(s, params...) if len(s) == 0 || s[len(s)-1] != '\n' { x.out("\n") } } func (x *genRunner) genTypeName(t reflect.Type) (n string) { // if the type has a PkgPath, which doesn't match the current package, // then include it. // We cannot depend on t.String() because it includes current package, // or t.PkgPath because it includes full import path, // var ptrPfx string for t.Kind() == reflect.Ptr { ptrPfx += "*" t = t.Elem() } if tn := t.Name(); tn != "" { return ptrPfx + x.genTypeNamePrim(t) } switch t.Kind() { case reflect.Map: return ptrPfx + "map[" + x.genTypeName(t.Key()) + "]" + x.genTypeName(t.Elem()) case reflect.Slice: return ptrPfx + "[]" + x.genTypeName(t.Elem()) case reflect.Array: return ptrPfx + "[" + strconv.FormatInt(int64(t.Len()), 10) + "]" + x.genTypeName(t.Elem()) case reflect.Chan: return ptrPfx + t.ChanDir().String() + " " + x.genTypeName(t.Elem()) default: if t == intfTyp { return ptrPfx + "interface{}" } else { return ptrPfx + x.genTypeNamePrim(t) } } } func (x *genRunner) genTypeNamePrim(t reflect.Type) (n string) { if t.Name() == "" { return t.String() } else if genImportPath(t) == "" || genImportPath(t) == genImportPath(x.tc) { return t.Name() } else { return x.imn[genImportPath(t)] + "." + t.Name() // return t.String() // best way to get the package name inclusive } } func (x *genRunner) genZeroValueR(t reflect.Type) string { // if t is a named type, w switch t.Kind() { case reflect.Ptr, reflect.Interface, reflect.Chan, reflect.Func, reflect.Slice, reflect.Map, reflect.Invalid: return "nil" case reflect.Bool: return "false" case reflect.String: return `""` case reflect.Struct, reflect.Array: return x.genTypeName(t) + "{}" default: // all numbers return "0" } } func (x *genRunner) genMethodNameT(t reflect.Type) (s string) { return genMethodNameT(t, x.tc) } func (x *genRunner) tryGenIsZero(t reflect.Type) (done bool) { if t.Kind() != reflect.Struct || t.Implements(isCodecEmptyerTyp) { return } rtid := rt2id(t) if _, ok := x.tz[rtid]; ok { delete(x.ty, t) return } x.tz[rtid] = true delete(x.ty, t) ti := x.ti.get(rtid, t) tisfi := ti.sfi.source() // always use sequence from file. decStruct expects same thing. varname := genTopLevelVarName x.linef("func (%s *%s) IsCodecEmpty() bool {", varname, x.genTypeName(t)) anonSeen := make(map[reflect.Type]bool) var omitline genBuf for _, si := range tisfi { if si.path.parent != nil { root := si.path.root() if anonSeen[root.typ] { continue } anonSeen[root.typ] = true } t2 := genOmitEmptyLinePreChecks(varname, t, si, &omitline, true) // if Ptr, we already checked if nil above if t2.Type.Kind() != reflect.Ptr { x.doEncOmitEmptyLine(t2, varname, &omitline) omitline.s(" || ") } } omitline.s(" false") x.linef("return !(%s)", omitline.v()) x.line("}") x.line("") return true } func (x *genRunner) selfer(encode bool) { t := x.tc // ti := x.ti.get(rt2id(t), t) t0 := t // always make decode use a pointer receiver, // and structs/arrays always use a ptr receiver (encode|decode) isptr := !encode || t.Kind() == reflect.Array || (t.Kind() == reflect.Struct && t != timeTyp) x.varsfxreset() fnSigPfx := "func (" + genTopLevelVarName + " " if isptr { fnSigPfx += "*" } fnSigPfx += x.genTypeName(t) x.out(fnSigPfx) if isptr { t = reflect.PtrTo(t) } if encode { x.line(") CodecEncodeSelf(e *" + x.cpfx + "Encoder) {") x.genRequiredMethodVars(true) if t0.Kind() == reflect.Struct { x.linef("if z.EncBasicHandle().CheckCircularRef { z.EncEncode(%s); return }", genTopLevelVarName) } x.encVar(genTopLevelVarName, t) } else { x.line(") CodecDecodeSelf(d *" + x.cpfx + "Decoder) {") x.genRequiredMethodVars(false) // do not use decVar, as there is no need to check TryDecodeAsNil // or way to elegantly handle that, and also setting it to a // non-nil value doesn't affect the pointer passed. // x.decVar(genTopLevelVarName, t, false) x.dec(genTopLevelVarName, t0, true) } x.line("}") x.line("") if encode || t0.Kind() != reflect.Struct { return } // write is containerMap if genUseOneFunctionForDecStructMap { x.out(fnSigPfx) x.line(") codecDecodeSelfFromMap(l int, d *" + x.cpfx + "Decoder) {") x.genRequiredMethodVars(false) x.decStructMap(genTopLevelVarName, "l", rt2id(t0), t0, genStructMapStyleConsolidated) x.line("}") x.line("") } else { x.out(fnSigPfx) x.line(") codecDecodeSelfFromMapLenPrefix(l int, d *" + x.cpfx + "Decoder) {") x.genRequiredMethodVars(false) x.decStructMap(genTopLevelVarName, "l", rt2id(t0), t0, genStructMapStyleLenPrefix) x.line("}") x.line("") x.out(fnSigPfx) x.line(") codecDecodeSelfFromMapCheckBreak(l int, d *" + x.cpfx + "Decoder) {") x.genRequiredMethodVars(false) x.decStructMap(genTopLevelVarName, "l", rt2id(t0), t0, genStructMapStyleCheckBreak) x.line("}") x.line("") } // write containerArray x.out(fnSigPfx) x.line(") codecDecodeSelfFromArray(l int, d *" + x.cpfx + "Decoder) {") x.genRequiredMethodVars(false) x.decStructArray(genTopLevelVarName, "l", "return", rt2id(t0), t0) x.line("}") x.line("") } // used for chan, array, slice, map func (x *genRunner) xtraSM(varname string, t reflect.Type, ti *typeInfo, encode, isptr bool) { var ptrPfx, addrPfx string if isptr { ptrPfx = "*" } else { addrPfx = "&" } if encode { x.linef("h.enc%s((%s%s)(%s), e)", x.genMethodNameT(t), ptrPfx, x.genTypeName(t), varname) } else { x.linef("h.dec%s((*%s)(%s%s), d)", x.genMethodNameT(t), x.genTypeName(t), addrPfx, varname) } x.registerXtraT(t, ti) } func (x *genRunner) registerXtraT(t reflect.Type, ti *typeInfo) { // recursively register the types tk := t.Kind() if tk == reflect.Ptr { x.registerXtraT(t.Elem(), nil) return } if _, ok := x.tm[t]; ok { return } switch tk { case reflect.Chan, reflect.Slice, reflect.Array, reflect.Map: default: return } // only register the type if it will not default to a fast-path if ti == nil { ti = x.ti.get(rt2id(t), t) } if _, rtidu := genFastpathUnderlying(t, ti.rtid, ti); fastpathAvIndex(rtidu) != -1 { return } x.tm[t] = struct{}{} x.ts = append(x.ts, t) // check if this refers to any xtra types eg. a slice of array: add the array x.registerXtraT(t.Elem(), nil) if tk == reflect.Map { x.registerXtraT(t.Key(), nil) } } // encVar will encode a variable. // The parameter, t, is the reflect.Type of the variable itself func (x *genRunner) encVar(varname string, t reflect.Type) { var checkNil bool // case reflect.Ptr, reflect.Interface, reflect.Slice, reflect.Map, reflect.Chan: // do not include checkNil for slice and maps, as we already checkNil below it switch t.Kind() { case reflect.Ptr, reflect.Interface, reflect.Chan: checkNil = true } x.encVarChkNil(varname, t, checkNil) } func (x *genRunner) encVarChkNil(varname string, t reflect.Type, checkNil bool) { if checkNil { x.linef("if %s == nil { r.EncodeNil() } else {", varname) } switch t.Kind() { case reflect.Ptr: telem := t.Elem() tek := telem.Kind() if tek == reflect.Array || (tek == reflect.Struct && telem != timeTyp) { x.enc(varname, genNonPtr(t), true) break } i := x.varsfx() x.line(genTempVarPfx + i + " := *" + varname) x.enc(genTempVarPfx+i, genNonPtr(t), false) case reflect.Struct, reflect.Array: if t == timeTyp { x.enc(varname, t, false) break } i := x.varsfx() x.line(genTempVarPfx + i + " := &" + varname) x.enc(genTempVarPfx+i, t, true) default: x.enc(varname, t, false) } if checkNil { x.line("}") } } // enc will encode a variable (varname) of type t, where t represents T. // if t is !time.Time and t is of kind reflect.Struct or reflect.Array, varname is of type *T // (to prevent copying), // else t is of type T func (x *genRunner) enc(varname string, t reflect.Type, isptr bool) { rtid := rt2id(t) ti2 := x.ti.get(rtid, t) // We call CodecEncodeSelf if one of the following are honored: // - the type already implements Selfer, call that // - the type has a Selfer implementation just created, use that // - the type is in the list of the ones we will generate for, but it is not currently being generated mi := x.varsfx() // tptr := reflect.PtrTo(t) // tk := t.Kind() // check if // - type is time.Time, RawExt, Raw // - the type implements (Text|JSON|Binary)(Unm|M)arshal var hasIf genIfClause defer hasIf.end(x) // end if block (if necessary) var ptrPfx, addrPfx string if isptr { ptrPfx = "*" } else { addrPfx = "&" } if t == timeTyp { x.linef("%s z.EncBasicHandle().TimeBuiltin() { r.EncodeTime(%s%s)", hasIf.c(false), ptrPfx, varname) // return } if t == rawTyp { x.linef("%s z.EncRaw(%s%s)", hasIf.c(true), ptrPfx, varname) return } if t == rawExtTyp { x.linef("%s r.EncodeRawExt(%s%s)", hasIf.c(true), addrPfx, varname) return } // only check for extensions if extensions are configured, // and the type is named, and has a packagePath, // and this is not the CodecEncodeSelf or CodecDecodeSelf method (i.e. it is not a Selfer) if !x.nx && varname != genTopLevelVarName && t != genStringDecAsBytesTyp && t != genStringDecZCTyp && genImportPath(t) != "" && t.Name() != "" { yy := fmt.Sprintf("%sxt%s", genTempVarPfx, mi) x.linef("%s %s := z.Extension(%s); %s != nil { z.EncExtension(%s, %s) ", hasIf.c(false), yy, varname, yy, varname, yy) } if x.checkForSelfer(t, varname) { if ti2.flagSelfer { x.linef("%s %s.CodecEncodeSelf(e)", hasIf.c(true), varname) return } if ti2.flagSelferPtr { if isptr { x.linef("%s %s.CodecEncodeSelf(e)", hasIf.c(true), varname) } else { x.linef("%s %ssf%s := &%s", hasIf.c(true), genTempVarPfx, mi, varname) x.linef("%ssf%s.CodecEncodeSelf(e)", genTempVarPfx, mi) } return } if _, ok := x.te[rtid]; ok { x.linef("%s %s.CodecEncodeSelf(e)", hasIf.c(true), varname) return } } inlist := false for _, t0 := range x.t { if t == t0 { inlist = true if x.checkForSelfer(t, varname) { x.linef("%s %s.CodecEncodeSelf(e)", hasIf.c(true), varname) return } break } } var rtidAdded bool if t == x.tc { x.te[rtid] = true rtidAdded = true } if ti2.flagBinaryMarshaler { x.linef("%s z.EncBinary() { z.EncBinaryMarshal(%s%v) ", hasIf.c(false), ptrPfx, varname) } else if ti2.flagBinaryMarshalerPtr { x.linef("%s z.EncBinary() { z.EncBinaryMarshal(%s%v) ", hasIf.c(false), addrPfx, varname) } if ti2.flagJsonMarshaler { x.linef("%s !z.EncBinary() && z.IsJSONHandle() { z.EncJSONMarshal(%s%v) ", hasIf.c(false), ptrPfx, varname) } else if ti2.flagJsonMarshalerPtr { x.linef("%s !z.EncBinary() && z.IsJSONHandle() { z.EncJSONMarshal(%s%v) ", hasIf.c(false), addrPfx, varname) } else if ti2.flagTextMarshaler { x.linef("%s !z.EncBinary() { z.EncTextMarshal(%s%v) ", hasIf.c(false), ptrPfx, varname) } else if ti2.flagTextMarshalerPtr { x.linef("%s !z.EncBinary() { z.EncTextMarshal(%s%v) ", hasIf.c(false), addrPfx, varname) } x.lineIf(hasIf.c(true)) switch t.Kind() { case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64: x.line("r.EncodeInt(int64(" + varname + "))") case reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64, reflect.Uintptr: x.line("r.EncodeUint(uint64(" + varname + "))") case reflect.Float32: x.line("r.EncodeFloat32(float32(" + varname + "))") case reflect.Float64: x.line("r.EncodeFloat64(float64(" + varname + "))") case reflect.Complex64: x.linef("z.EncEncodeComplex64(complex64(%s))", varname) case reflect.Complex128: x.linef("z.EncEncodeComplex128(complex128(%s))", varname) case reflect.Bool: x.line("r.EncodeBool(bool(" + varname + "))") case reflect.String: x.linef("r.EncodeString(string(%s))", varname) case reflect.Chan: x.xtraSM(varname, t, ti2, true, false) // x.encListFallback(varname, rtid, t) case reflect.Array: _, rtidu := genFastpathUnderlying(t, rtid, ti2) if fastpathAvIndex(rtidu) != -1 { g := x.newFastpathGenV(ti2.key) x.linef("z.F.%sV((%s)(%s[:]), e)", g.MethodNamePfx("Enc", false), x.genTypeName(ti2.key), varname) } else { x.xtraSM(varname, t, ti2, true, true) } case reflect.Slice: // if nil, call dedicated function // if a []byte, call dedicated function // if a known fastpath slice, call dedicated function // else write encode function in-line. // - if elements are primitives or Selfers, call dedicated function on each member. // - else call Encoder.encode(XXX) on it. x.linef("if %s == nil { r.EncodeNil() } else {", varname) if rtid == uint8SliceTypId { x.line("r.EncodeStringBytesRaw([]byte(" + varname + "))") } else { tu, rtidu := genFastpathUnderlying(t, rtid, ti2) if fastpathAvIndex(rtidu) != -1 { g := x.newFastpathGenV(tu) if rtid == rtidu { x.linef("z.F.%sV(%s, e)", g.MethodNamePfx("Enc", false), varname) } else { x.linef("z.F.%sV((%s)(%s), e)", g.MethodNamePfx("Enc", false), x.genTypeName(tu), varname) } } else { x.xtraSM(varname, t, ti2, true, false) } } x.linef("} // end block: if %s slice == nil", varname) case reflect.Map: // if nil, call dedicated function // if a known fastpath map, call dedicated function // else write encode function in-line. // - if elements are primitives or Selfers, call dedicated function on each member. // - else call Encoder.encode(XXX) on it. x.linef("if %s == nil { r.EncodeNil() } else {", varname) tu, rtidu := genFastpathUnderlying(t, rtid, ti2) if fastpathAvIndex(rtidu) != -1 { g := x.newFastpathGenV(tu) if rtid == rtidu { x.linef("z.F.%sV(%s, e)", g.MethodNamePfx("Enc", false), varname) } else { x.linef("z.F.%sV((%s)(%s), e)", g.MethodNamePfx("Enc", false), x.genTypeName(tu), varname) } } else { x.xtraSM(varname, t, ti2, true, false) } x.linef("} // end block: if %s map == nil", varname) case reflect.Struct: if !inlist { delete(x.te, rtid) x.line("z.EncFallback(" + varname + ")") break } x.encStruct(varname, rtid, t) default: if rtidAdded { delete(x.te, rtid) } x.line("z.EncFallback(" + varname + ")") } } func (x *genRunner) encZero(t reflect.Type) { switch t.Kind() { case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64: x.line("r.EncodeInt(0)") case reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64, reflect.Uintptr: x.line("r.EncodeUint(0)") case reflect.Float32: x.line("r.EncodeFloat32(0)") case reflect.Float64: x.line("r.EncodeFloat64(0)") case reflect.Complex64: x.line("z.EncEncodeComplex64(0)") case reflect.Complex128: x.line("z.EncEncodeComplex128(0)") case reflect.Bool: x.line("r.EncodeBool(false)") case reflect.String: x.linef(`r.EncodeString("")`) default: x.line("r.EncodeNil()") } } func genOmitEmptyLinePreChecks(varname string, t reflect.Type, si *structFieldInfo, omitline *genBuf, oneLevel bool) (t2 reflect.StructField) { // xdebug2f("calling genOmitEmptyLinePreChecks on: %v", t) t2typ := t varname3 := varname // go through the loop, record the t2 field explicitly, // and gather the omit line if embedded in pointers. fullpath := si.path.fullpath() for i, path := range fullpath { for t2typ.Kind() == reflect.Ptr { t2typ = t2typ.Elem() } t2 = t2typ.Field(int(path.index)) t2typ = t2.Type varname3 = varname3 + "." + t2.Name // do not include actual field in the omit line. // that is done subsequently (right after - below). if i+1 < len(fullpath) && t2typ.Kind() == reflect.Ptr { omitline.s(varname3).s(" != nil && ") } if oneLevel { break } } return } func (x *genRunner) doEncOmitEmptyLine(t2 reflect.StructField, varname string, buf *genBuf) { x.f = 0 x.encOmitEmptyLine(t2, varname, buf) } func (x *genRunner) encOmitEmptyLine(t2 reflect.StructField, varname string, buf *genBuf) { // xdebugf("calling encOmitEmptyLine on: %v", t2.Type) // smartly check omitEmpty on a struct type, as it may contain uncomparable map/slice/etc. // also, for maps/slices, check if len ! 0 (not if == zero value) varname2 := varname + "." + t2.Name switch t2.Type.Kind() { case reflect.Struct: rtid2 := rt2id(t2.Type) ti2 := x.ti.get(rtid2, t2.Type) // xdebugf(">>>> structfield: omitempty: type: %s, field: %s\n", t2.Type.Name(), t2.Name) if ti2.rtid == timeTypId { buf.s("!(").s(varname2).s(".IsZero())") break } if ti2.flagIsZeroerPtr || ti2.flagIsZeroer { buf.s("!(").s(varname2).s(".IsZero())") break } if t2.Type.Implements(isCodecEmptyerTyp) { buf.s("!(").s(varname2).s(".IsCodecEmpty())") break } _, ok := x.tz[rtid2] if ok { buf.s("!(").s(varname2).s(".IsCodecEmpty())") break } // if we *should* create a IsCodecEmpty for it, but haven't yet, add it here // _, ok = x.ty[rtid2] if genImportPath(t2.Type) == x.bp { x.ty[t2.Type] = struct{}{} buf.s("!(").s(varname2).s(".IsCodecEmpty())") break } if ti2.flagComparable { buf.s(varname2).s(" != ").s(x.genZeroValueR(t2.Type)) break } // buf.s("(") buf.s(x.sayFalse()) // buf.s("false") var wrote bool for i, n := 0, t2.Type.NumField(); i < n; i++ { f := t2.Type.Field(i) if f.PkgPath != "" { // unexported continue } buf.s(" || ") x.encOmitEmptyLine(f, varname2, buf) wrote = true } if !wrote { buf.s(" || ").s(x.sayTrue()) } //buf.s(")") case reflect.Bool: buf.s("bool(").s(varname2).s(")") case reflect.Map, reflect.Slice, reflect.Chan: buf.s("len(").s(varname2).s(") != 0") case reflect.Array: tlen := t2.Type.Len() if tlen == 0 { buf.s(x.sayFalse()) } else if t2.Type.Comparable() { buf.s(varname2).s(" != ").s(x.genZeroValueR(t2.Type)) } else { // then we cannot even compare the individual values // TODO use playground to check if you can compare to a // zero value of an array, even if array not comparable. buf.s(x.sayTrue()) } default: buf.s(varname2).s(" != ").s(x.genZeroValueR(t2.Type)) } } func (x *genRunner) encStruct(varname string, rtid uintptr, t reflect.Type) { // Use knowledge from structfieldinfo (mbs, encodable fields. Ignore omitempty. ) // replicate code in kStruct i.e. for each field, deref type to non-pointer, and call x.enc on it // if t === type currently running selfer on, do for all ti := x.ti.get(rtid, t) i := x.varsfx() // sepVarname := genTempVarPfx + "sep" + i numfieldsvar := genTempVarPfx + "q" + i ti2arrayvar := genTempVarPfx + "r" + i struct2arrvar := genTempVarPfx + "2arr" + i tisfi := ti.sfi.source() // always use sequence from file. decStruct expects same thing. type genFQN struct { i string fqname string nilLine genBuf nilVar string canNil bool sf reflect.StructField } genFQNs := make([]genFQN, len(tisfi)) si2Pos := make(map[*structFieldInfo]int) // stores position in sorted structFieldInfos for j, si := range tisfi { si2Pos[si] = j q := &genFQNs[j] q.i = x.varsfx() q.nilVar = genTempVarPfx + "n" + q.i q.canNil = false q.fqname = varname { t2typ := t fullpath := si.path.fullpath() for _, path := range fullpath { for t2typ.Kind() == reflect.Ptr { t2typ = t2typ.Elem() } q.sf = t2typ.Field(int(path.index)) t2typ = q.sf.Type q.fqname += "." + q.sf.Name if t2typ.Kind() == reflect.Ptr { if !q.canNil { q.nilLine.f("%s == nil", q.fqname) q.canNil = true } else { q.nilLine.f(" || %s == nil", q.fqname) } } } } } // x.line(sepVarname + " := !z.EncBinary()") x.linef("%s := z.EncBasicHandle().StructToArray", struct2arrvar) // x.linef("_, _ = %s, %s", sepVarname, struct2arrvar) x.linef("_ = %s", struct2arrvar) x.linef("const %s bool = %v // struct tag has 'toArray'", ti2arrayvar, ti.toArray) for j := range genFQNs { q := &genFQNs[j] if q.canNil { x.linef("var %s bool = %s", q.nilVar, q.nilLine.v()) } } // var nn int // due to omitEmpty, we need to calculate the // number of non-empty things we write out first. // This is required as we need to pre-determine the size of the container, // to support length-prefixing. omitEmptySometimes := x.omitEmptyWhen == nil omitEmptyAlways := (x.omitEmptyWhen != nil && *(x.omitEmptyWhen)) // omitEmptyNever := (x.omitEmptyWhen != nil && !*(x.omitEmptyWhen)) toArraySometimes := x.toArrayWhen == nil toArrayAlways := (x.toArrayWhen != nil && *(x.toArrayWhen)) toArrayNever := (x.toArrayWhen != nil && !(*(x.toArrayWhen))) if (omitEmptySometimes && ti.anyOmitEmpty) || omitEmptyAlways { x.linef("var %s = [%v]bool{ // should field at this index be written?", numfieldsvar, len(tisfi)) for _, si := range tisfi { if omitEmptySometimes && !si.path.omitEmpty { x.linef("true, // %s", si.encName) // si.fieldName) continue } var omitline genBuf t2 := genOmitEmptyLinePreChecks(varname, t, si, &omitline, false) x.doEncOmitEmptyLine(t2, varname, &omitline) x.linef("%s, // %s", omitline.v(), si.encName) // si.fieldName) } x.line("}") x.linef("_ = %s", numfieldsvar) } if toArraySometimes { x.linef("if %s || %s {", ti2arrayvar, struct2arrvar) // if ti.toArray } if toArraySometimes || toArrayAlways { x.linef("z.EncWriteArrayStart(%d)", len(tisfi)) for j, si := range tisfi { doOmitEmptyCheck := (omitEmptySometimes && si.path.omitEmpty) || omitEmptyAlways q := &genFQNs[j] // if the type of the field is a Selfer, or one of the ones if q.canNil { x.linef("if %s { z.EncWriteArrayElem(); r.EncodeNil() } else { ", q.nilVar) } x.linef("z.EncWriteArrayElem()") if doOmitEmptyCheck { x.linef("if %s[%v] {", numfieldsvar, j) } x.encVarChkNil(q.fqname, q.sf.Type, false) if doOmitEmptyCheck { x.linef("} else {") x.encZero(q.sf.Type) x.linef("}") } if q.canNil { x.line("}") } } x.line("z.EncWriteArrayEnd()") } if toArraySometimes { x.linef("} else {") // if not ti.toArray } if toArraySometimes || toArrayNever { if (omitEmptySometimes && ti.anyOmitEmpty) || omitEmptyAlways { x.linef("var %snn%s int", genTempVarPfx, i) x.linef("for _, b := range %s { if b { %snn%s++ } }", numfieldsvar, genTempVarPfx, i) x.linef("z.EncWriteMapStart(%snn%s)", genTempVarPfx, i) x.linef("%snn%s = %v", genTempVarPfx, i, 0) } else { x.linef("z.EncWriteMapStart(%d)", len(tisfi)) } fn := func(tisfi []*structFieldInfo) { // tisfi here may be source or sorted, so use the src position stored elsewhere for _, si := range tisfi { pos := si2Pos[si] q := &genFQNs[pos] doOmitEmptyCheck := (omitEmptySometimes && si.path.omitEmpty) || omitEmptyAlways if doOmitEmptyCheck { x.linef("if %s[%v] {", numfieldsvar, pos) } x.linef("z.EncWriteMapElemKey()") // emulate EncStructFieldKey switch ti.keyType { case valueTypeInt: x.linef("r.EncodeInt(z.M.Int(strconv.ParseInt(`%s`, 10, 64)))", si.encName) case valueTypeUint: x.linef("r.EncodeUint(z.M.Uint(strconv.ParseUint(`%s`, 10, 64)))", si.encName) case valueTypeFloat: x.linef("r.EncodeFloat64(z.M.Float(strconv.ParseFloat(`%s`, 64)))", si.encName) default: // string if x.jsonOnlyWhen == nil { if si.path.encNameAsciiAlphaNum { x.linef(`if z.IsJSONHandle() { z.WriteStr("\"%s\"") } else { `, si.encName) } x.linef("r.EncodeString(`%s`)", si.encName) if si.path.encNameAsciiAlphaNum { x.linef("}") } } else if *(x.jsonOnlyWhen) { if si.path.encNameAsciiAlphaNum { x.linef(`z.WriteStr("\"%s\"")`, si.encName) } else { x.linef("r.EncodeString(`%s`)", si.encName) } } else { x.linef("r.EncodeString(`%s`)", si.encName) } } x.line("z.EncWriteMapElemValue()") if q.canNil { x.line("if " + q.nilVar + " { r.EncodeNil() } else { ") x.encVarChkNil(q.fqname, q.sf.Type, false) x.line("}") } else { x.encVarChkNil(q.fqname, q.sf.Type, false) } if doOmitEmptyCheck { x.line("}") } } } if genStructCanonical { x.linef("if z.EncBasicHandle().Canonical {") // if Canonical block fn(ti.sfi.sorted()) x.linef("} else {") // else !Canonical block fn(ti.sfi.source()) x.linef("}") // end if Canonical block } else { fn(tisfi) } x.line("z.EncWriteMapEnd()") } if toArraySometimes { x.linef("} ") // end if/else ti.toArray } } func (x *genRunner) encListFallback(varname string, t reflect.Type) { x.linef("if %s == nil { r.EncodeNil(); return }", varname) elemBytes := t.Elem().Kind() == reflect.Uint8 if t.AssignableTo(uint8SliceTyp) { x.linef("r.EncodeStringBytesRaw([]byte(%s))", varname) return } if t.Kind() == reflect.Array && elemBytes { x.linef("r.EncodeStringBytesRaw(((*[%d]byte)(%s))[:])", t.Len(), varname) return } i := x.varsfx() if t.Kind() == reflect.Chan { type ts struct { Label, Chan, Slice, Sfx string } tm, err := template.New("").Parse(genEncChanTmpl) genCheckErr(err) x.linef("if %s == nil { r.EncodeNil() } else { ", varname) x.linef("var sch%s []%s", i, x.genTypeName(t.Elem())) err = tm.Execute(x.w, &ts{"Lsch" + i, varname, "sch" + i, i}) genCheckErr(err) if elemBytes { x.linef("r.EncodeStringBytesRaw([]byte(%s))", "sch"+i) x.line("}") return } varname = "sch" + i } x.line("z.EncWriteArrayStart(len(" + varname + "))") // x.linef("for _, %sv%s := range %s {", genTempVarPfx, i, varname) // x.linef("z.EncWriteArrayElem()") // x.encVar(genTempVarPfx+"v"+i, t.Elem()) // x.line("}") x.linef("for %sv%s := range %s {", genTempVarPfx, i, varname) x.linef("z.EncWriteArrayElem()") x.encVar(fmt.Sprintf("%s[%sv%s]", varname, genTempVarPfx, i), t.Elem()) x.line("}") x.line("z.EncWriteArrayEnd()") if t.Kind() == reflect.Chan { x.line("}") } } func (x *genRunner) encMapFallback(varname string, t reflect.Type) { x.linef("if %s == nil { r.EncodeNil()", varname) x.line("} else if z.EncBasicHandle().Canonical {") // Solve for easy case accomodated by sort package without reflection i.e. // map keys of type: float, int, string (pre-defined/builtin types). // // To do this, we will get the keys into an array of uint64|float64|string, // sort them, then write them out, and grab the value and encode it appropriately tkey := t.Key() tkind := tkey.Kind() // tkeybase := tkey // for tkeybase.Kind() == reflect.Ptr { // tkeybase = tkeybase.Elem() // } // tikey := x.ti.get(rt2id(tkeybase), tkeybase) // pre-defined types have a name and no pkgpath and appropriate kind predeclared := tkey.PkgPath() == "" && tkey.Name() != "" canonSortKind := reflect.Invalid switch tkind { case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64: canonSortKind = reflect.Int64 case reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64: canonSortKind = reflect.Uint64 case reflect.Float32, reflect.Float64: canonSortKind = reflect.Float64 case reflect.String: canonSortKind = reflect.String } var i string = x.varsfx() fnCanonNumBoolStrKind := func() { if !predeclared { x.linef("var %svv%s %s", genTempVarPfx, i, x.genTypeName(tkey)) x.linef("%sencfn%s := z.EncFnGivenAddr(&%svv%s)", genTempVarPfx, i, genTempVarPfx, i) } // get the type, get the slice type its mapped to, and complete the code x.linef("%ss%s := make([]%s, 0, len(%s))", genTempVarPfx, i, canonSortKind, varname) x.linef("for k, _ := range %s {", varname) x.linef(" %ss%s = append(%ss%s, %s(k))", genTempVarPfx, i, genTempVarPfx, i, canonSortKind) x.linef("}") x.linef("sort.Sort(%s%sSlice(%ss%s))", x.hn, canonSortKind, genTempVarPfx, i) x.linef("z.EncWriteMapStart(len(%s))", varname) x.linef("for _, %sv%s := range %ss%s {", genTempVarPfx, i, genTempVarPfx, i) x.linef(" z.EncWriteMapElemKey()") if predeclared { switch tkind { case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32: x.linef("r.EncodeInt(int64(%sv%s))", genTempVarPfx, i) case reflect.Int64: x.linef("r.EncodeInt(%sv%s)", genTempVarPfx, i) case reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uintptr: x.linef("r.EncodeUint(%sv%s)", genTempVarPfx, i) case reflect.Uint64: x.linef("r.EncodeUint(uint64(%sv%s))", genTempVarPfx, i) case reflect.Float32: x.linef("r.EncodeFloat32(float32(%sv%s))", genTempVarPfx, i) case reflect.Float64: x.linef("r.EncodeFloat64(%sv%s)", genTempVarPfx, i) case reflect.String: x.linef("r.EncodeString(%sv%s)", genTempVarPfx, i) } } else { x.linef("%svv%s = %s(%sv%s)", genTempVarPfx, i, x.genTypeName(tkey), genTempVarPfx, i) x.linef("z.EncEncodeNumBoolStrKindGivenAddr(&%svv%s, %sencfn%s)", genTempVarPfx, i, genTempVarPfx, i) } x.linef(" z.EncWriteMapElemValue()") vname := genTempVarPfx + "e" + i if predeclared { x.linef("%s := %s[%s(%sv%s)]", vname, varname, x.genTypeName(tkey), genTempVarPfx, i) } else { x.linef("%s := %s[%svv%s]", vname, varname, genTempVarPfx, i) } x.encVar(vname, t.Elem()) x.linef("}") x.line("z.EncWriteMapEnd()") } // if canonSortKind != reflect.Invalid && !tikey.flagMarshalInterface { // if predeclared { // fnCanonNumBoolStrKind() // } else { // // handle if an extension // x.linef("if z.Extension(%s(%s)) != nil { z.EncEncodeMapNonNil(%s) } else {", // x.genTypeName(tkey), x.genZeroValueR(tkey), varname) // fnCanonNumBoolStrKind() // x.line("}") // } // } else { // x.linef("z.EncEncodeMapNonNil(%s)", varname) // } if canonSortKind != reflect.Invalid { fnCanonNumBoolStrKind() } else { x.linef("z.EncEncodeMapNonNil(%s)", varname) } x.line("} else {") x.linef("z.EncWriteMapStart(len(%s))", varname) x.linef("for %sk%s, %sv%s := range %s {", genTempVarPfx, i, genTempVarPfx, i, varname) x.linef("z.EncWriteMapElemKey()") x.encVar(genTempVarPfx+"k"+i, t.Key()) x.line("z.EncWriteMapElemValue()") x.encVar(genTempVarPfx+"v"+i, t.Elem()) x.line("}") x.line("z.EncWriteMapEnd()") x.line("}") } func (x *genRunner) decVarInitPtr(varname, nilvar string, t reflect.Type, si *structFieldInfo, newbuf, nilbuf *genBuf) (varname3 string, t2 reflect.StructField) { //we must accommodate anonymous fields, where the embedded field is a nil pointer in the value. // t2 = t.FieldByIndex(si.is) varname3 = varname t2typ := t t2kind := t2typ.Kind() var nilbufed bool if si != nil { fullpath := si.path.fullpath() for _, path := range fullpath { // only one-level pointers can be seen in a type if t2typ.Kind() == reflect.Ptr { t2typ = t2typ.Elem() } t2 = t2typ.Field(int(path.index)) t2typ = t2.Type varname3 = varname3 + "." + t2.Name t2kind = t2typ.Kind() if t2kind != reflect.Ptr { continue } if newbuf != nil { if len(newbuf.buf) > 0 { newbuf.s("\n") } newbuf.f("if %s == nil { %s = new(%s) }", varname3, varname3, x.genTypeName(t2typ.Elem())) } if nilbuf != nil { if !nilbufed { nilbuf.s("if ").s(varname3).s(" != nil") nilbufed = true } else { nilbuf.s(" && ").s(varname3).s(" != nil") } } } } if nilbuf != nil { if nilbufed { nilbuf.s(" { ").s("// remove the if-true\n") } if nilvar != "" { nilbuf.s(nilvar).s(" = true") } else if tk := t2typ.Kind(); tk == reflect.Ptr { if strings.IndexByte(varname3, '.') != -1 || strings.IndexByte(varname3, '[') != -1 { nilbuf.s(varname3).s(" = nil") } else { nilbuf.s("*").s(varname3).s(" = ").s(x.genZeroValueR(t2typ.Elem())) } } else { nilbuf.s(varname3).s(" = ").s(x.genZeroValueR(t2typ)) } if nilbufed { nilbuf.s("}") } } return } // decVar takes a variable called varname, of type t func (x *genRunner) decVarMain(varname, rand string, t reflect.Type, checkNotNil bool) { // We only encode as nil if a nillable value. // This removes some of the wasted checks for TryDecodeAsNil. // We need to think about this more, to see what happens if omitempty, etc // cause a nil value to be stored when something is expected. // This could happen when decoding from a struct encoded as an array. // For that, decVar should be called with canNil=true, to force true as its value. var varname2 string if t.Kind() != reflect.Ptr { if t.PkgPath() != "" || !x.decTryAssignPrimitive(varname, t, false) { x.dec(varname, t, false) } } else { if checkNotNil { x.linef("if %s == nil { %s = new(%s) }", varname, varname, x.genTypeName(t.Elem())) } // Ensure we set underlying ptr to a non-nil value (so we can deref to it later). // There's a chance of a **T in here which is nil. var ptrPfx string for t = t.Elem(); t.Kind() == reflect.Ptr; t = t.Elem() { ptrPfx += "*" if checkNotNil { x.linef("if %s%s == nil { %s%s = new(%s)}", ptrPfx, varname, ptrPfx, varname, x.genTypeName(t)) } } // Should we create temp var if a slice/map indexing? No. dec(...) can now handle it. if ptrPfx == "" { x.dec(varname, t, true) } else { varname2 = genTempVarPfx + "z" + rand x.line(varname2 + " := " + ptrPfx + varname) x.dec(varname2, t, true) } } } // decVar takes a variable called varname, of type t func (x *genRunner) decVar(varname, nilvar string, t reflect.Type, canBeNil, checkNotNil bool) { // We only encode as nil if a nillable value. // This removes some of the wasted checks for TryDecodeAsNil. // We need to think about this more, to see what happens if omitempty, etc // cause a nil value to be stored when something is expected. // This could happen when decoding from a struct encoded as an array. // For that, decVar should be called with canNil=true, to force true as its value. i := x.varsfx() if t.Kind() == reflect.Ptr { var buf genBuf x.decVarInitPtr(varname, nilvar, t, nil, nil, &buf) x.linef("if r.TryNil() { %s } else {", buf.buf) x.decVarMain(varname, i, t, checkNotNil) x.line("} ") } else { x.decVarMain(varname, i, t, checkNotNil) } } // dec will decode a variable (varname) of type t or ptrTo(t) if isptr==true. func (x *genRunner) dec(varname string, t reflect.Type, isptr bool) { // assumptions: // - the varname is to a pointer already. No need to take address of it // - t is always a baseType T (not a *T, etc). rtid := rt2id(t) ti2 := x.ti.get(rtid, t) // check if // - type is time.Time, Raw, RawExt // - the type implements (Text|JSON|Binary)(Unm|M)arshal mi := x.varsfx() var hasIf genIfClause defer hasIf.end(x) var ptrPfx, addrPfx string if isptr { ptrPfx = "*" } else { addrPfx = "&" } if t == timeTyp { x.linef("%s z.DecBasicHandle().TimeBuiltin() { %s%v = r.DecodeTime()", hasIf.c(false), ptrPfx, varname) // return } if t == rawTyp { x.linef("%s %s%v = z.DecRaw()", hasIf.c(true), ptrPfx, varname) return } if t == rawExtTyp { x.linef("%s r.DecodeExt(%s%v, 0, nil)", hasIf.c(true), addrPfx, varname) return } // only check for extensions if extensions are configured, // and the type is named, and has a packagePath, // and this is not the CodecEncodeSelf or CodecDecodeSelf method (i.e. it is not a Selfer) // xdebugf("genRunner.dec: varname: %v, t: %v, genImportPath: %v, t.Name: %v", varname, t, genImportPath(t), t.Name()) if !x.nx && varname != genTopLevelVarName && t != genStringDecAsBytesTyp && t != genStringDecZCTyp && genImportPath(t) != "" && t.Name() != "" { // first check if extensions are configued, before doing the interface conversion yy := fmt.Sprintf("%sxt%s", genTempVarPfx, mi) x.linef("%s %s := z.Extension(%s); %s != nil { z.DecExtension(%s%s, %s) ", hasIf.c(false), yy, varname, yy, addrPfx, varname, yy) } if x.checkForSelfer(t, varname) { if ti2.flagSelfer { x.linef("%s %s.CodecDecodeSelf(d)", hasIf.c(true), varname) return } if ti2.flagSelferPtr { x.linef("%s %s.CodecDecodeSelf(d)", hasIf.c(true), varname) return } if _, ok := x.td[rtid]; ok { x.linef("%s %s.CodecDecodeSelf(d)", hasIf.c(true), varname) return } } inlist := false for _, t0 := range x.t { if t == t0 { inlist = true if x.checkForSelfer(t, varname) { x.linef("%s %s.CodecDecodeSelf(d)", hasIf.c(true), varname) return } break } } var rtidAdded bool if t == x.tc { x.td[rtid] = true rtidAdded = true } if ti2.flagBinaryUnmarshaler { x.linef("%s z.DecBinary() { z.DecBinaryUnmarshal(%s%v) ", hasIf.c(false), ptrPfx, varname) } else if ti2.flagBinaryUnmarshalerPtr { x.linef("%s z.DecBinary() { z.DecBinaryUnmarshal(%s%v) ", hasIf.c(false), addrPfx, varname) } if ti2.flagJsonUnmarshaler { x.linef("%s !z.DecBinary() && z.IsJSONHandle() { z.DecJSONUnmarshal(%s%v)", hasIf.c(false), ptrPfx, varname) } else if ti2.flagJsonUnmarshalerPtr { x.linef("%s !z.DecBinary() && z.IsJSONHandle() { z.DecJSONUnmarshal(%s%v)", hasIf.c(false), addrPfx, varname) } else if ti2.flagTextUnmarshaler { x.linef("%s !z.DecBinary() { z.DecTextUnmarshal(%s%v)", hasIf.c(false), ptrPfx, varname) } else if ti2.flagTextUnmarshalerPtr { x.linef("%s !z.DecBinary() { z.DecTextUnmarshal(%s%v)", hasIf.c(false), addrPfx, varname) } x.lineIf(hasIf.c(true)) if x.decTryAssignPrimitive(varname, t, isptr) { return } switch t.Kind() { case reflect.Chan: x.xtraSM(varname, t, ti2, false, isptr) case reflect.Array: _, rtidu := genFastpathUnderlying(t, rtid, ti2) if fastpathAvIndex(rtidu) != -1 { g := x.newFastpathGenV(ti2.key) x.linef("z.F.%sN((%s)(%s[:]), d)", g.MethodNamePfx("Dec", false), x.genTypeName(ti2.key), varname) } else { x.xtraSM(varname, t, ti2, false, isptr) } case reflect.Slice: // if a []byte, call dedicated function // if a known fastpath slice, call dedicated function // else write encode function in-line. // - if elements are primitives or Selfers, call dedicated function on each member. // - else call Encoder.encode(XXX) on it. if rtid == uint8SliceTypId { x.linef("%s%s = z.DecodeBytesInto(%s(%s[]byte)(%s))", ptrPfx, varname, ptrPfx, ptrPfx, varname) } else { tu, rtidu := genFastpathUnderlying(t, rtid, ti2) if fastpathAvIndex(rtidu) != -1 { g := x.newFastpathGenV(tu) if rtid == rtidu { x.linef("z.F.%sX(%s%s, d)", g.MethodNamePfx("Dec", false), addrPfx, varname) } else { x.linef("z.F.%sX((*%s)(%s%s), d)", g.MethodNamePfx("Dec", false), x.genTypeName(tu), addrPfx, varname) } } else { x.xtraSM(varname, t, ti2, false, isptr) // x.decListFallback(varname, rtid, false, t) } } case reflect.Map: // if a known fastpath map, call dedicated function // else write encode function in-line. // - if elements are primitives or Selfers, call dedicated function on each member. // - else call Encoder.encode(XXX) on it. tu, rtidu := genFastpathUnderlying(t, rtid, ti2) if fastpathAvIndex(rtidu) != -1 { g := x.newFastpathGenV(tu) if rtid == rtidu { x.linef("z.F.%sX(%s%s, d)", g.MethodNamePfx("Dec", false), addrPfx, varname) } else { x.linef("z.F.%sX((*%s)(%s%s), d)", g.MethodNamePfx("Dec", false), x.genTypeName(tu), addrPfx, varname) } } else { x.xtraSM(varname, t, ti2, false, isptr) } case reflect.Struct: if inlist { // no need to create temp variable if isptr, or x.F or x[F] if isptr || strings.IndexByte(varname, '.') != -1 || strings.IndexByte(varname, '[') != -1 { x.decStruct(varname, rtid, t) } else { varname2 := genTempVarPfx + "j" + mi x.line(varname2 + " := &" + varname) x.decStruct(varname2, rtid, t) } } else { // delete(x.td, rtid) x.line("z.DecFallback(" + addrPfx + varname + ", false)") } default: if rtidAdded { delete(x.te, rtid) } x.line("z.DecFallback(" + addrPfx + varname + ", true)") } } func (x *genRunner) decTryAssignPrimitive(varname string, t reflect.Type, isptr bool) (done bool) { // This should only be used for exact primitives (ie un-named types). // Named types may be implementations of Selfer, Unmarshaler, etc. // They should be handled by dec(...) var ptr string if isptr { ptr = "*" } switch t.Kind() { case reflect.Int: x.linef("%s%s = (%s)(z.C.IntV(r.DecodeInt64(), codecSelferBitsize%s))", ptr, varname, x.genTypeName(t), x.xs) case reflect.Int8: x.linef("%s%s = (%s)(z.C.IntV(r.DecodeInt64(), 8))", ptr, varname, x.genTypeName(t)) case reflect.Int16: x.linef("%s%s = (%s)(z.C.IntV(r.DecodeInt64(), 16))", ptr, varname, x.genTypeName(t)) case reflect.Int32: x.linef("%s%s = (%s)(z.C.IntV(r.DecodeInt64(), 32))", ptr, varname, x.genTypeName(t)) case reflect.Int64: x.linef("%s%s = (%s)(r.DecodeInt64())", ptr, varname, x.genTypeName(t)) case reflect.Uint: x.linef("%s%s = (%s)(z.C.UintV(r.DecodeUint64(), codecSelferBitsize%s))", ptr, varname, x.genTypeName(t), x.xs) case reflect.Uint8: x.linef("%s%s = (%s)(z.C.UintV(r.DecodeUint64(), 8))", ptr, varname, x.genTypeName(t)) case reflect.Uint16: x.linef("%s%s = (%s)(z.C.UintV(r.DecodeUint64(), 16))", ptr, varname, x.genTypeName(t)) case reflect.Uint32: x.linef("%s%s = (%s)(z.C.UintV(r.DecodeUint64(), 32))", ptr, varname, x.genTypeName(t)) case reflect.Uint64: x.linef("%s%s = (%s)(r.DecodeUint64())", ptr, varname, x.genTypeName(t)) case reflect.Uintptr: x.linef("%s%s = (%s)(z.C.UintV(r.DecodeUint64(), codecSelferBitsize%s))", ptr, varname, x.genTypeName(t), x.xs) case reflect.Float32: x.linef("%s%s = (%s)(z.DecDecodeFloat32())", ptr, varname, x.genTypeName(t)) case reflect.Float64: x.linef("%s%s = (%s)(r.DecodeFloat64())", ptr, varname, x.genTypeName(t)) case reflect.Complex64: x.linef("%s%s = (%s)(complex(z.DecDecodeFloat32(), 0))", ptr, varname, x.genTypeName(t)) case reflect.Complex128: x.linef("%s%s = (%s)(complex(r.DecodeFloat64(), 0))", ptr, varname, x.genTypeName(t)) case reflect.Bool: x.linef("%s%s = (%s)(r.DecodeBool())", ptr, varname, x.genTypeName(t)) case reflect.String: if t == genStringDecAsBytesTyp { x.linef("%s%s = r.DecodeStringAsBytes()", ptr, varname) } else if t == genStringDecZCTyp { x.linef("%s%s = (string)(z.DecStringZC(r.DecodeStringAsBytes()))", ptr, varname) } else { x.linef("%s%s = (%s)(z.DecStringZC(r.DecodeStringAsBytes()))", ptr, varname, x.genTypeName(t)) } default: return false } return true } func (x *genRunner) decListFallback(varname string, rtid uintptr, t reflect.Type) { if t.AssignableTo(uint8SliceTyp) { x.line("*" + varname + " = z.DecodeBytesInto(*((*[]byte)(" + varname + ")))") return } if t.Kind() == reflect.Array && t.Elem().Kind() == reflect.Uint8 { x.linef("r.DecodeBytes( ((*[%d]byte)(%s))[:])", t.Len(), varname) return } type tstruc struct { TempVar string Sfx string Rand string Varname string CTyp string Typ string Immutable bool Size int } telem := t.Elem() ts := tstruc{genTempVarPfx, x.xs, x.varsfx(), varname, x.genTypeName(t), x.genTypeName(telem), genIsImmutable(telem), int(telem.Size())} funcs := make(template.FuncMap) funcs["decLineVar"] = func(varname string) string { x.decVar(varname, "", telem, false, true) return "" } funcs["var"] = func(s string) string { return ts.TempVar + s + ts.Rand } funcs["xs"] = func() string { return ts.Sfx } funcs["zero"] = func() string { return x.genZeroValueR(telem) } funcs["isArray"] = func() bool { return t.Kind() == reflect.Array } funcs["isSlice"] = func() bool { return t.Kind() == reflect.Slice } funcs["isChan"] = func() bool { return t.Kind() == reflect.Chan } tm, err := template.New("").Funcs(funcs).Parse(genDecListTmpl) genCheckErr(err) genCheckErr(tm.Execute(x.w, &ts)) } func (x *genRunner) decMapFallback(varname string, rtid uintptr, t reflect.Type) { type tstruc struct { TempVar string Sfx string Rand string Varname string KTyp string Typ string Size int } telem := t.Elem() tkey := t.Key() ts := tstruc{ genTempVarPfx, x.xs, x.varsfx(), varname, x.genTypeName(tkey), x.genTypeName(telem), int(telem.Size() + tkey.Size()), } funcs := make(template.FuncMap) funcs["decElemZero"] = func() string { return x.genZeroValueR(telem) } funcs["decElemKindImmutable"] = func() bool { return genIsImmutable(telem) } funcs["decElemKindPtr"] = func() bool { return telem.Kind() == reflect.Ptr } funcs["decElemKindIntf"] = func() bool { return telem.Kind() == reflect.Interface } funcs["decLineVarKStrBytes"] = func(varname string) string { x.decVar(varname, "", genStringDecAsBytesTyp, false, true) return "" } funcs["decLineVarKStrZC"] = func(varname string) string { x.decVar(varname, "", genStringDecZCTyp, false, true) return "" } funcs["decLineVarK"] = func(varname string) string { x.decVar(varname, "", tkey, false, true) return "" } funcs["decLineVar"] = func(varname, decodedNilVarname string) string { x.decVar(varname, decodedNilVarname, telem, false, true) return "" } funcs["var"] = func(s string) string { return ts.TempVar + s + ts.Rand } funcs["xs"] = func() string { return ts.Sfx } tm, err := template.New("").Funcs(funcs).Parse(genDecMapTmpl) genCheckErr(err) genCheckErr(tm.Execute(x.w, &ts)) } func (x *genRunner) decStructMapSwitch(kName string, varname string, rtid uintptr, t reflect.Type) { ti := x.ti.get(rtid, t) tisfi := ti.sfi.source() // always use sequence from file. decStruct expects same thing. x.line("switch string(" + kName + ") {") var newbuf, nilbuf genBuf for _, si := range tisfi { x.line("case \"" + si.encName + "\":") newbuf.reset() nilbuf.reset() varname3, t2 := x.decVarInitPtr(varname, "", t, si, &newbuf, &nilbuf) if len(newbuf.buf) > 0 { x.linef("if r.TryNil() { %s } else { %s", nilbuf.buf, newbuf.buf) } x.decVarMain(varname3, x.varsfx(), t2.Type, false) if len(newbuf.buf) > 0 { x.line("}") } } x.line("default:") // pass the slice here, so that the string will not escape, and maybe save allocation x.linef("z.DecStructFieldNotFound(-1, string(%s))", kName) x.linef("} // end switch %s", kName) } func (x *genRunner) decStructMap(varname, lenvarname string, rtid uintptr, t reflect.Type, style genStructMapStyle) { tpfx := genTempVarPfx ti := x.ti.get(rtid, t) i := x.varsfx() kName := tpfx + "s" + i switch style { case genStructMapStyleLenPrefix: x.linef("for %sj%s := 0; %sj%s < %s; %sj%s++ {", tpfx, i, tpfx, i, lenvarname, tpfx, i) case genStructMapStyleCheckBreak: x.linef("for %sj%s := 0; !z.DecCheckBreak(); %sj%s++ {", tpfx, i, tpfx, i) default: // 0, otherwise. x.linef("var %shl%s bool = %s >= 0", tpfx, i, lenvarname) // has length x.linef("for %sj%s := 0; ; %sj%s++ {", tpfx, i, tpfx, i) x.linef("if %shl%s { if %sj%s >= %s { break }", tpfx, i, tpfx, i, lenvarname) x.line("} else { if z.DecCheckBreak() { break }; }") } x.line("z.DecReadMapElemKey()") // emulate decstructfieldkey switch ti.keyType { case valueTypeInt: x.linef("%s := strconv.AppendInt(z.DecScratchArrayBuffer()[:0], r.DecodeInt64(), 10)", kName) case valueTypeUint: x.linef("%s := strconv.AppendUint(z.DecScratchArrayBuffer()[:0], r.DecodeUint64(), 10)", kName) case valueTypeFloat: x.linef("%s := strconv.AppendFloat(z.DecScratchArrayBuffer()[:0], r.DecodeFloat64(), 'f', -1, 64)", kName) default: // string x.linef("%s := r.DecodeStringAsBytes()", kName) } x.line("z.DecReadMapElemValue()") x.decStructMapSwitch(kName, varname, rtid, t) x.line("} // end for " + tpfx + "j" + i) } func (x *genRunner) decStructArray(varname, lenvarname, breakString string, rtid uintptr, t reflect.Type) { tpfx := genTempVarPfx i := x.varsfx() ti := x.ti.get(rtid, t) tisfi := ti.sfi.source() // always use sequence from file. decStruct expects same thing. x.linef("var %sj%s int", tpfx, i) x.linef("var %sb%s bool", tpfx, i) // break x.linef("var %shl%s bool = %s >= 0", tpfx, i, lenvarname) // has length if !genDecStructArrayInlineLoopCheck { x.linef("var %sfn%s = func() bool { ", tpfx, i) x.linef("%sj%s++; if %shl%s { %sb%s = %sj%s > %s } else { %sb%s = z.DecCheckBreak() };", tpfx, i, tpfx, i, tpfx, i, tpfx, i, lenvarname, tpfx, i) x.linef("if %sb%s { z.DecReadArrayEnd(); return true }; return false", tpfx, i) x.linef("} // end func %sfn%s", tpfx, i) } var newbuf, nilbuf genBuf for _, si := range tisfi { if genDecStructArrayInlineLoopCheck { x.linef("%sj%s++; if %shl%s { %sb%s = %sj%s > %s } else { %sb%s = z.DecCheckBreak() }", tpfx, i, tpfx, i, tpfx, i, tpfx, i, lenvarname, tpfx, i) x.linef("if %sb%s { z.DecReadArrayEnd(); %s }", tpfx, i, breakString) } else { x.linef("if %sfn%s() { %s }", tpfx, i, breakString) } x.line("z.DecReadArrayElem()") newbuf.reset() nilbuf.reset() varname3, t2 := x.decVarInitPtr(varname, "", t, si, &newbuf, &nilbuf) if len(newbuf.buf) > 0 { x.linef("if r.TryNil() { %s } else { %s", nilbuf.buf, newbuf.buf) } x.decVarMain(varname3, x.varsfx(), t2.Type, false) if len(newbuf.buf) > 0 { x.line("}") } } // read remaining values and throw away. x.line("for {") x.linef("%sj%s++; if %shl%s { %sb%s = %sj%s > %s } else { %sb%s = z.DecCheckBreak() }", tpfx, i, tpfx, i, tpfx, i, tpfx, i, lenvarname, tpfx, i) x.linef("if %sb%s { break }", tpfx, i) x.line("z.DecReadArrayElem()") x.linef(`z.DecStructFieldNotFound(%sj%s - 1, "")`, tpfx, i) x.line("}") } func (x *genRunner) decStruct(varname string, rtid uintptr, t reflect.Type) { // varname MUST be a ptr, or a struct field or a slice element. i := x.varsfx() x.linef("%sct%s := r.ContainerType()", genTempVarPfx, i) x.linef("if %sct%s == codecSelferValueTypeNil%s {", genTempVarPfx, i, x.xs) x.linef("*(%s) = %s{}", varname, x.genTypeName(t)) x.linef("} else if %sct%s == codecSelferValueTypeMap%s {", genTempVarPfx, i, x.xs) x.line(genTempVarPfx + "l" + i + " := z.DecReadMapStart()") x.linef("if %sl%s == 0 {", genTempVarPfx, i) if genUseOneFunctionForDecStructMap { x.line("} else { ") x.linef("%s.codecDecodeSelfFromMap(%sl%s, d)", varname, genTempVarPfx, i) } else { x.line("} else if " + genTempVarPfx + "l" + i + " > 0 { ") x.line(varname + ".codecDecodeSelfFromMapLenPrefix(" + genTempVarPfx + "l" + i + ", d)") x.line("} else {") x.line(varname + ".codecDecodeSelfFromMapCheckBreak(" + genTempVarPfx + "l" + i + ", d)") } x.line("}") x.line("z.DecReadMapEnd()") // else if container is array x.linef("} else if %sct%s == codecSelferValueTypeArray%s {", genTempVarPfx, i, x.xs) x.line(genTempVarPfx + "l" + i + " := z.DecReadArrayStart()") x.linef("if %sl%s != 0 {", genTempVarPfx, i) x.linef("%s.codecDecodeSelfFromArray(%sl%s, d)", varname, genTempVarPfx, i) x.line("}") x.line("z.DecReadArrayEnd()") // else panic x.line("} else { ") x.line("panic(errCodecSelferOnlyMapOrArrayEncodeToStruct" + x.xs + ")") x.line("} ") } // -------- type fastpathGenV struct { // fastpathGenV is either a primitive (Primitive != "") or a map (MapKey != "") or a slice MapKey string Elem string Primitive string Size int NoCanonical bool } func (x *genRunner) newFastpathGenV(t reflect.Type) (v fastpathGenV) { v.NoCanonical = !genFastpathCanonical switch t.Kind() { case reflect.Slice, reflect.Array: te := t.Elem() v.Elem = x.genTypeName(te) v.Size = int(te.Size()) case reflect.Map: te := t.Elem() tk := t.Key() v.Elem = x.genTypeName(te) v.MapKey = x.genTypeName(tk) v.Size = int(te.Size() + tk.Size()) default: halt.onerror(errGenUnexpectedTypeFastpath) } return } func (x *fastpathGenV) 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) } // genImportPath returns import path of a non-predeclared named typed, or an empty string otherwise. // // This handles the misbehaviour that occurs when 1.5-style vendoring is enabled, // where PkgPath returns the full path, including the vendoring pre-fix that should have been stripped. // We strip it here. func genImportPath(t reflect.Type) (s string) { s = t.PkgPath() if genCheckVendor { // HACK: always handle vendoring. It should be typically on in go 1.6, 1.7 s = genStripVendor(s) } return } // A go identifier is (letter|_)[letter|number|_]* func genGoIdentifier(s string, checkFirstChar bool) string { b := make([]byte, 0, len(s)) t := make([]byte, 4) var n int for i, r := range s { if checkFirstChar && i == 0 && !unicode.IsLetter(r) { b = append(b, '_') } // r must be unicode_letter, unicode_digit or _ if unicode.IsLetter(r) || unicode.IsDigit(r) { n = utf8.EncodeRune(t, r) b = append(b, t[:n]...) } else { b = append(b, '_') } } return string(b) } func genNonPtr(t reflect.Type) reflect.Type { for t.Kind() == reflect.Ptr { t = t.Elem() } return t } func genFastpathUnderlying(t reflect.Type, rtid uintptr, ti *typeInfo) (tu reflect.Type, rtidu uintptr) { tu = t rtidu = rtid if ti.flagHasPkgPath { tu = ti.fastpathUnderlying rtidu = rt2id(tu) } return } 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:] } } func genMethodNameT(t reflect.Type, tRef reflect.Type) (n string) { var ptrPfx string for t.Kind() == reflect.Ptr { ptrPfx += "Ptrto" t = t.Elem() } tstr := t.String() if tn := t.Name(); tn != "" { if tRef != nil && genImportPath(t) == genImportPath(tRef) { return ptrPfx + tn } else { if genQNameRegex.MatchString(tstr) { return ptrPfx + strings.Replace(tstr, ".", "_", 1000) } else { return ptrPfx + genCustomTypeName(tstr) } } } switch t.Kind() { case reflect.Map: return ptrPfx + "Map" + genMethodNameT(t.Key(), tRef) + genMethodNameT(t.Elem(), tRef) case reflect.Slice: return ptrPfx + "Slice" + genMethodNameT(t.Elem(), tRef) case reflect.Array: return ptrPfx + "Array" + strconv.FormatInt(int64(t.Len()), 10) + genMethodNameT(t.Elem(), tRef) case reflect.Chan: var cx string switch t.ChanDir() { case reflect.SendDir: cx = "ChanSend" case reflect.RecvDir: cx = "ChanRecv" default: cx = "Chan" } return ptrPfx + cx + genMethodNameT(t.Elem(), tRef) default: if t == intfTyp { return ptrPfx + "Interface" } else { if tRef != nil && genImportPath(t) == genImportPath(tRef) { if t.Name() != "" { return ptrPfx + t.Name() } else { return ptrPfx + genCustomTypeName(tstr) } } else { // best way to get the package name inclusive // return ptrPfx + strings.Replace(tstr, ".", "_", 1000) // return ptrPfx + genBase64enc.EncodeToString([]byte(tstr)) if t.Name() != "" && genQNameRegex.MatchString(tstr) { return ptrPfx + strings.Replace(tstr, ".", "_", 1000) } else { return ptrPfx + genCustomTypeName(tstr) } } } } } // genCustomNameForType base64encodes the t.String() value in such a way // that it can be used within a function name. func genCustomTypeName(tstr string) string { len2 := genBase64enc.EncodedLen(len(tstr)) bufx := make([]byte, len2) genBase64enc.Encode(bufx, []byte(tstr)) for i := len2 - 1; i >= 0; i-- { if bufx[i] == '=' { len2-- } else { break } } return string(bufx[:len2]) } func genIsImmutable(t reflect.Type) (v bool) { return scalarBitset.isset(byte(t.Kind())) } type genInternal struct { Version int Values []fastpathGenV Formats []string } func (x genInternal) FastpathLen() (l int) { for _, v := range x.Values { // if v.Primitive == "" && !(v.MapKey == "" && v.Elem == "uint8") { if v.Primitive == "" { l++ } } return } func genInternalZeroValue(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 genInternalNonZeroValueIdx [6]uint64 var genInternalNonZeroValueStrs = [...][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 genInternalNonZeroValue(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 } genInternalNonZeroValueIdx[i]++ idx := genInternalNonZeroValueIdx[i] slen := uint64(len(genInternalNonZeroValueStrs)) return genInternalNonZeroValueStrs[idx%slen][i] // return string, to remove ambiguity } // Note: used for fastpath only func genInternalEncCommandAsString(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 "e.e.EncodeStringBytesRaw(" + 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 "e.encode(" + vname + ")" } } // Note: used for fastpath only func genInternalDecCommandAsString(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.stringZC(d.d.DecodeStringAsBytes())" case "[]byte", "[]uint8", "bytes": return "d.d.DecodeBytes([]byte{})" case "float32": return "float32(d.decodeFloat32())" case "float64": return "d.d.DecodeFloat64()" case "complex64": return "complex(d.decodeFloat32(), 0)" case "complex128": return "complex(d.d.DecodeFloat64(), 0)" case "bool": return "d.d.DecodeBool()" default: halt.onerror(errors.New("gen internal: unknown type for decode: " + s)) } return "" } // func genInternalSortType(s string, elem bool) string { // for _, v := range [...]string{ // "int", // "uint", // "float", // "bool", // "string", // "bytes", "[]uint8", "[]byte", // } { // if v == "[]byte" || v == "[]uint8" { // v = "bytes" // } // if strings.HasPrefix(s, v) { // if v == "int" || v == "uint" || v == "float" { // v += "64" // } // if elem { // return v // } // return v + "Slice" // } // } // halt.onerror(errors.New("sorttype: unexpected type: " + s)) // } func genInternalSortType(s string, elem bool) string { if elem { return s } return s + "Slice" } // MARKER: keep in sync with codecgen/gen.go func genStripVendor(s string) string { // HACK: Misbehaviour occurs in go 1.5. May have to re-visit this later. // if s contains /vendor/ OR startsWith vendor/, then return everything after it. const vendorStart = "vendor/" const vendorInline = "/vendor/" if i := strings.LastIndex(s, vendorInline); i >= 0 { s = s[i+len(vendorInline):] } else if strings.HasPrefix(s, vendorStart) { s = s[len(vendorStart):] } return s } // var genInternalMu sync.Mutex var genInternalV = genInternal{Version: genVersion} var genInternalTmplFuncs template.FuncMap var genInternalOnce sync.Once func genInternalInit() { 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 fast-paths for commonly used types. // Consequently, things like int8, uint16, uint, etc are commented out. slicetypes = genInternalFastpathSliceTypes() mapkeytypes = genInternalFastpathMapKeyTypes() mapvaltypes = genInternalFastpathMapValueTypes() } // var mapkeytypes [len(&types) - 1]string // skip bool // copy(mapkeytypes[:], types[:]) // var mb []byte // mb = append(mb, '|') // for _, s := range mapkeytypes { // mb = append(mb, s...) // mb = append(mb, '|') // } // var mapkeytypestr = string(mb) var gt = genInternal{Version: genVersion, Formats: genFormats} // For each slice or map type, there must be a (symmetrical) Encode and Decode fast-path function for _, s := range primitivetypes { gt.Values = append(gt.Values, fastpathGenV{Primitive: s, Size: typesizes[s], NoCanonical: !genFastpathCanonical}) } for _, s := range slicetypes { // if s != "uint8" { // do not generate fast path for slice of bytes. Treat specially already. // gt.Values = append(gt.Values, fastpathGenV{Elem: s, Size: typesizes[s]}) // } gt.Values = append(gt.Values, fastpathGenV{Elem: s, Size: typesizes[s], NoCanonical: !genFastpathCanonical}) } for _, s := range mapkeytypes { // if _, ok := typesizes[s]; !ok { // if strings.Contains(mapkeytypestr, "|"+s+"|") { // gt.Values = append(gt.Values, fastpathGenV{MapKey: s, Elem: s, Size: 2 * typesizes[s]}) // } for _, ms := range mapvaltypes { gt.Values = append(gt.Values, fastpathGenV{MapKey: s, Elem: ms, Size: typesizes[s] + typesizes[ms], NoCanonical: !genFastpathCanonical}) } } funcs := make(template.FuncMap) // funcs["haspfx"] = strings.HasPrefix funcs["encmd"] = genInternalEncCommandAsString funcs["decmd"] = genInternalDecCommandAsString funcs["zerocmd"] = genInternalZeroValue funcs["nonzerocmd"] = genInternalNonZeroValue funcs["hasprefix"] = strings.HasPrefix funcs["sorttype"] = genInternalSortType genInternalV = gt genInternalTmplFuncs = funcs } // genInternalGoFile is used to generate source files from templates. func genInternalGoFile(r io.Reader, w io.Writer) (err error) { genInternalOnce.Do(genInternalInit) gt := genInternalV t := template.New("").Funcs(genInternalTmplFuncs) tmplstr, err := ioutil.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 genInternalFastpathSliceTypes() []string { return []string{ "interface{}", "string", "[]byte", "float32", "float64", // "uint", // "uint8", // no need for fastpath of []uint8, as it is handled specially "uint8", // keep fast-path, so it doesn't have to go through reflection // "uint16", // "uint32", "uint64", // "uintptr", "int", // "int8", // "int16", "int32", // rune "int64", "bool", } } func genInternalFastpathMapKeyTypes() []string { return []string{ // "interface{}", "string", // "[]byte", // "float32", // "float64", // "uint", "uint8", // byte // "uint16", // "uint32", "uint64", // used for keys // "uintptr", "int", // default number key // "int8", // "int16", "int32", // rune // "int64", // "bool", } } func genInternalFastpathMapValueTypes() []string { return []string{ "interface{}", "string", "[]byte", // "uint", "uint8", // byte // "uint16", // "uint32", "uint64", // used for keys, etc // "uintptr", "int", // default number //"int8", // "int16", "int32", // rune (mostly used for unicode) // "int64", // "float32", "float64", "bool", } } // sort-slice ... // generates sort implementations for // various slice types and combination slice+reflect.Value types. // // The combination slice+reflect.Value types are used // during canonical encode, and the others are used during fast-path // encoding of map keys. // genInternalSortableTypes returns the types // that are used for fast-path canonical's encoding of maps. // // For now, we only support the highest sizes for // int64, uint64, float64, bool, string, bytes. func genInternalSortableTypes() []string { return genInternalFastpathMapKeyTypes() } // genInternalSortablePlusTypes returns the types // that are used for reflection-based canonical's encoding of maps. // // For now, we only support the highest sizes for // int64, uint64, float64, string, bytes. func genInternalSortablePlusTypes() []string { return []string{ "string", "float64", "uint64", // "uintptr", "int64", // "bool", "time", "bytes", } } func genTypeForShortName(s string) string { switch s { case "time": return "time.Time" case "bytes": return "[]byte" } return s } func genArgs(args ...interface{}) map[string]interface{} { m := make(map[string]interface{}, len(args)/2) for i := 0; i < len(args); { m[args[i].(string)] = args[i+1] i += 2 } return m } func genEndsWith(s0 string, sn ...string) bool { for _, s := range sn { if strings.HasSuffix(s0, s) { return true } } return false } func genCheckErr(err error) { halt.onerror(err) } func genRunSortTmpl2Go(fnameIn, fnameOut string) { var err error funcs := make(template.FuncMap) funcs["sortables"] = genInternalSortableTypes funcs["sortablesplus"] = genInternalSortablePlusTypes funcs["tshort"] = genTypeForShortName funcs["endswith"] = genEndsWith funcs["args"] = genArgs t := template.New("").Funcs(funcs) fin, err := os.Open(fnameIn) genCheckErr(err) defer fin.Close() fout, err := os.Create(fnameOut) genCheckErr(err) defer fout.Close() tmplstr, err := ioutil.ReadAll(fin) genCheckErr(err) t, err = t.Parse(string(tmplstr)) genCheckErr(err) var out bytes.Buffer err = t.Execute(&out, 0) genCheckErr(err) bout, err := format.Source(out.Bytes()) if err != nil { fout.Write(out.Bytes()) // write out if error, so we can still see. } genCheckErr(err) // write out if error, as much as possible, so we can still see. _, err = fout.Write(bout) genCheckErr(err) } func genRunTmpl2Go(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 = genInternalGoFile(fin, fout) genCheckErr(err) } // --- some methods here for other types, which are only used in codecgen // depth returns number of valid nodes in the hierachy func (path *structFieldInfoPathNode) root() *structFieldInfoPathNode { TOP: if path.parent != nil { path = path.parent goto TOP } return path } func (path *structFieldInfoPathNode) fullpath() (p []*structFieldInfoPathNode) { // this method is mostly called by a command-line tool - it's not optimized, and that's ok. // it shouldn't be used in typical runtime use - as it does unnecessary allocation. d := path.depth() p = make([]*structFieldInfoPathNode, d) for d--; d >= 0; d-- { p[d] = path path = path.parent } return } go-1.2.8/codec/go.mod000066400000000000000000000000531435255326100143160ustar00rootroot00000000000000module github.com/ugorji/go/codec go 1.11 go-1.2.8/codec/go.sum000066400000000000000000000000001435255326100143330ustar00rootroot00000000000000go-1.2.8/codec/goversion_arrayof_gte_go15.go000066400000000000000000000005431435255326100207730ustar00rootroot00000000000000// 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.5 // +build go1.5 package codec import "reflect" const reflectArrayOfSupported = true func reflectArrayOf(count int, elem reflect.Type) reflect.Type { return reflect.ArrayOf(count, elem) } go-1.2.8/codec/goversion_arrayof_lt_go15.go000066400000000000000000000007131435255326100206320ustar00rootroot00000000000000// 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.5 // +build !go1.5 package codec import ( "errors" "reflect" ) const reflectArrayOfSupported = false var errNoReflectArrayOf = errors.New("codec: reflect.ArrayOf unsupported by this go version") func reflectArrayOf(count int, elem reflect.Type) reflect.Type { panic(errNoReflectArrayOf) } go-1.2.8/codec/goversion_fmt_time_gte_go15.go000066400000000000000000000004541435255326100211350ustar00rootroot00000000000000// 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.5 // +build go1.5 package codec import "time" func fmtTime(t time.Time, fmt string, b []byte) []byte { return t.AppendFormat(b, fmt) } go-1.2.8/codec/goversion_fmt_time_lt_go15.go000066400000000000000000000005111435255326100207670ustar00rootroot00000000000000// 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.5 // +build !go1.5 package codec import "time" func fmtTime(t time.Time, fmt string, b []byte) []byte { s := t.Format(fmt) b = b[:len(s)] copy(b, s) return b } go-1.2.8/codec/goversion_growslice_unsafe_gte_go120.go000066400000000000000000000007111435255326100227410ustar00rootroot00000000000000// 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.20 && !safe && !codec.safe && !appengine // +build go1.20,!safe,!codec.safe,!appengine package codec import ( _ "reflect" // needed for go linkname(s) "unsafe" ) //go:linkname growslice reflect.growslice //go:noescape func growslice(typ unsafe.Pointer, old unsafeSlice, cap int) unsafeSlice go-1.2.8/codec/goversion_growslice_unsafe_lt_go120.go000066400000000000000000000007321435255326100226040ustar00rootroot00000000000000// 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 && !go1.20 && !safe && !codec.safe && !appengine // +build go1.9,!go1.20,!safe,!codec.safe,!appengine package codec import ( _ "runtime" // needed for go linkname(s) "unsafe" ) //go:linkname growslice runtime.growslice //go:noescape func growslice(typ unsafe.Pointer, old unsafeSlice, cap int) unsafeSlice go-1.2.8/codec/goversion_makemap_lt_go110.go000066400000000000000000000004641435255326100206610ustar00rootroot00000000000000// 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.10 // +build !go1.10 package codec import "reflect" func makeMapReflect(t reflect.Type, size int) reflect.Value { return reflect.MakeMap(t) } go-1.2.8/codec/goversion_makemap_not_unsafe_gte_go110.go000066400000000000000000000006111435255326100232340ustar00rootroot00000000000000// 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.10 && (safe || codec.safe || appengine) // +build go1.10 // +build safe codec.safe appengine package codec import "reflect" func makeMapReflect(t reflect.Type, size int) reflect.Value { return reflect.MakeMapWithSize(t, size) } go-1.2.8/codec/goversion_makemap_unsafe_gte_go110.go000066400000000000000000000012511435255326100223550ustar00rootroot00000000000000// 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.10 && !safe && !codec.safe && !appengine // +build go1.10,!safe,!codec.safe,!appengine package codec import ( "reflect" "unsafe" ) 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 } //go:linkname makemap runtime.makemap //go:noescape func makemap(typ unsafe.Pointer, size int, h unsafe.Pointer) unsafe.Pointer go-1.2.8/codec/goversion_maprange_gte_go112.go000066400000000000000000000013641435255326100212020ustar00rootroot00000000000000// 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.12 && (safe || codec.safe || appengine) // +build go1.12 // +build safe codec.safe appengine package codec import "reflect" 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, } } go-1.2.8/codec/goversion_maprange_lt_go112.go000066400000000000000000000015051435255326100210370ustar00rootroot00000000000000// 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.7 && !go1.12 && (safe || codec.safe || appengine) // +build go1.7 // +build !go1.12 // +build safe codec.safe appengine package codec import "reflect" type mapIter struct { m reflect.Value keys []reflect.Value j int values bool } func (t *mapIter) Next() (r bool) { t.j++ return t.j < len(t.keys) } func (t *mapIter) Key() reflect.Value { return t.keys[t.j] } func (t *mapIter) Value() (r reflect.Value) { if t.values { return t.m.MapIndex(t.keys[t.j]) } return } func (t *mapIter) Done() {} func mapRange(t *mapIter, m, k, v reflect.Value, values bool) { *t = mapIter{ m: m, keys: m.MapKeys(), values: values, j: -1, } } go-1.2.8/codec/goversion_unexportedembeddedptr_gte_go110.go000066400000000000000000000003611435255326100237770ustar00rootroot00000000000000// 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.10 // +build go1.10 package codec const allowSetUnexportedEmbeddedPtr = false go-1.2.8/codec/goversion_unexportedembeddedptr_lt_go110.go000066400000000000000000000003621435255326100236400ustar00rootroot00000000000000// 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.10 // +build !go1.10 package codec const allowSetUnexportedEmbeddedPtr = true go-1.2.8/codec/goversion_unsupported_lt_go14.go000066400000000000000000000011511435255326100215530ustar00rootroot00000000000000// 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.4 // +build !go1.4 package codec import "errors" // This codec package will only work for go1.4 and above. // This is for the following reasons: // - go 1.4 was released in 2014 // - go runtime is written fully in go // - interface only holds pointers // - reflect.Value is stabilized as 3 words var errCodecSupportedOnlyFromGo14 = errors.New("codec: go 1.3 and below are not supported") func init() { panic(errCodecSupportedOnlyFromGo14) } go-1.2.8/codec/goversion_vendor_eq_go15.go000066400000000000000000000004371435255326100204550ustar00rootroot00000000000000// 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.5 && !go1.6 // +build go1.5,!go1.6 package codec import "os" var genCheckVendor = os.Getenv("GO15VENDOREXPERIMENT") == "1" go-1.2.8/codec/goversion_vendor_eq_go16.go000066400000000000000000000004371435255326100204560ustar00rootroot00000000000000// 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.6 && !go1.7 // +build go1.6,!go1.7 package codec import "os" var genCheckVendor = os.Getenv("GO15VENDOREXPERIMENT") != "0" go-1.2.8/codec/goversion_vendor_gte_go17.go000066400000000000000000000003371435255326100206300ustar00rootroot00000000000000// 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.7 // +build go1.7 package codec const genCheckVendor = true go-1.2.8/codec/goversion_vendor_lt_go15.go000066400000000000000000000003401435255326100204600ustar00rootroot00000000000000// 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.5 // +build !go1.5 package codec var genCheckVendor = false go-1.2.8/codec/helper.go000066400000000000000000002530641435255326100150320ustar00rootroot00000000000000// 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.EOF. // 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 ( "encoding" "encoding/binary" "errors" "fmt" "io" "math" "reflect" "runtime" "sort" "strconv" "strings" "sync" "sync/atomic" "time" "unicode/utf8" ) // 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. const debugging = false const ( // 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 // bytesFreeListNoCache is used for debugging, when we want to skip using a cache of []byte. bytesFreeListNoCache = false // 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 // 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 ) const cpu32Bit = ^uint(0)>>32 == 0 type rkind byte const ( rkindPtr = rkind(reflect.Ptr) rkindString = rkind(reflect.String) rkindChan = rkind(reflect.Chan) ) type mapKeyFastKind uint8 const ( mapKeyFastKind32 = iota + 1 mapKeyFastKind32ptr mapKeyFastKind64 mapKeyFastKind64ptr mapKeyFastKindStr ) 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 // 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 mapKeyFastKindVals [32]mapKeyFastKind // 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 ) 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 pool4tiload = sync.Pool{ New: func() interface{} { return &typeInfoLoad{ etypes: make([]uintptr, 0, 4), sfis: make([]structFieldInfo, 0, 4), sfiNames: make(map[string]uint16, 4), } }, } 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) 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') { 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) } } } // driverStateManager supports the runtime state of an (enc|dec)Driver. // // During a side(En|De)code call, we can capture the state, reset it, // and then restore it later to continue the primary encoding/decoding. type driverStateManager interface { resetState() captureState() interface{} restoreState(state interface{}) } type bdAndBdread struct { bdRead bool bd byte } func (x bdAndBdread) captureState() interface{} { return x } func (x *bdAndBdread) resetState() { x.bd, x.bdRead = 0, false } func (x *bdAndBdread) reset() { x.resetState() } func (x *bdAndBdread) restoreState(v interface{}) { *x = v.(bdAndBdread) } 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 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 (x *typeInfoLoad) reset() { x.etypes = x.etypes[:0] x.sfis = x.sfis[:0] 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 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 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() isSelferViaCodecgenerTyp = reflect.TypeOf((*isSelferViaCodecgener)(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) } type isSelferViaCodecgener interface { codecSelferViaCodecgen() } // 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() } // 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 { // these are used during runtime. // At init time, they should have nothing in them. rtidFns atomicRtidFnSlice rtidFnsNoExt atomicRtidFnSlice // 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 mu sync.Mutex jsonHandle bool binaryHandle bool // timeBuiltin is initialized from TimeNotBuiltin, and used internally. // 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 configures whether Release() is implicitly called after an encode or // decode call. // // If you will hold onto an Encoder or Decoder for re-use, by calling Reset(...) // on it or calling (Must)Encode repeatedly into a given []byte or io.Writer, // then you do not want it to be implicitly closed after each Encode/Decode call. // Doing so will unnecessarily return resources to the shared pool, only for you to // grab them right after again to do another Encode/Decode call. // // Instead, you configure ExplicitRelease=true, and you explicitly call Release() when // you are truly done. // // As an alternative, you can explicitly set a finalizer - so its resources // are returned to the shared pool before it is garbage-collected. Do it as below: // runtime.SetFinalizer(e, (*Encoder).Release) // runtime.SetFinalizer(d, (*Decoder).Release) // // Deprecated: This is not longer used as pools are only used for long-lived objects // which are shared across goroutines. // Setting this value has no effect. It is maintained for backward compatibility. ExplicitRelease bool // ---- cache line inited uint32 // holds if inited, and also handle flags (binary encoding, json handler, etc) } // 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 { x.initHandle(hh) } } func (x *BasicHandle) basicInit() { x.rtidFns.store(nil) x.rtidFnsNoExt.store(nil) 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) } // TimeBuiltin returns whether time.Time OOTB support is used, // based on the initial configuration of TimeNotBuiltin func (x *basicHandleRuntimeState) TimeBuiltin() bool { return x.timeBuiltin } func (x *basicHandleRuntimeState) isJs() bool { return x.jsonHandle } func (x *basicHandleRuntimeState) isBe() bool { return x.binaryHandle } 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 } // initHandle 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 (x *BasicHandle) initHandle(hh Handle) { handleInitMu.Lock() defer handleInitMu.Unlock() // use defer, as halt may panic below if x.inited == 0 { if x.basicHandleRuntimeState == nil { x.basicHandleRuntimeState = new(basicHandleRuntimeState) } x.jsonHandle = hh.isJson() x.binaryHandle = hh.isBinary() // 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.basicInit() hh.init() atomic.StoreUint32(&x.inited, 1) } } func (x *BasicHandle) getBasicHandle() *BasicHandle { return x } func (x *BasicHandle) typeInfos() *TypeInfos { if x.TypeInfos != nil { return x.TypeInfos } return defTypeInfos } func (x *BasicHandle) getTypeInfo(rtid uintptr, rt reflect.Type) (pti *typeInfo) { return x.typeInfos().get(rtid, rt) } func findRtidFn(s []codecRtidFn, rtid uintptr) (i uint, fn *codecFn) { // binary search. adapted from sort/search.go. // Note: we use goto (instead of for loop) so this can be inlined. // h, i, j := 0, 0, len(s) 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 (x *BasicHandle) fn(rt reflect.Type) (fn *codecFn) { return x.fnVia(rt, x.typeInfos(), &x.rtidFns, x.CheckCircularRef, true) } func (x *BasicHandle) fnNoExt(rt reflect.Type) (fn *codecFn) { return x.fnVia(rt, x.typeInfos(), &x.rtidFnsNoExt, x.CheckCircularRef, false) } func (x *basicHandleRuntimeState) fnVia(rt reflect.Type, tinfos *TypeInfos, fs *atomicRtidFnSlice, checkCircularRef, checkExt bool) (fn *codecFn) { rtid := rt2id(rt) sp := fs.load() if sp != nil { if _, fn = findRtidFn(sp, rtid); fn != nil { return } } fn = x.fnLoad(rt, rtid, tinfos, checkCircularRef, checkExt) x.mu.Lock() sp = fs.load() // 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 { sp = []codecRtidFn{{rtid, fn}} fs.store(sp) } else { idx, fn2 := findRtidFn(sp, rtid) if fn2 == nil { sp2 := make([]codecRtidFn, len(sp)+1) copy(sp2[idx+1:], sp[idx:]) copy(sp2, sp[:idx]) sp2[idx] = codecRtidFn{rtid, fn} fs.store(sp2) } } x.mu.Unlock() return } func fnloadFastpathUnderlying(ti *typeInfo) (f *fastpathE, u reflect.Type) { var rtid uintptr var idx int rtid = rt2id(ti.fastpathUnderlying) idx = fastpathAvIndex(rtid) if idx == -1 { return } f = &fastpathAv[idx] if uint8(reflect.Array) == ti.kind { u = reflectArrayOf(ti.rt.Len(), ti.elem) } else { u = f.rt } return } func (x *basicHandleRuntimeState) fnLoad(rt reflect.Type, rtid uintptr, tinfos *TypeInfos, checkCircularRef, checkExt bool) (fn *codecFn) { fn = new(codecFn) 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 // fi.addrEf = true if rtid == timeTypId && x.timeBuiltin { fn.fe = (*Encoder).kTime fn.fd = (*Decoder).kTime } else if rtid == rawTypId { fn.fe = (*Encoder).raw fn.fd = (*Decoder).raw } else if rtid == rawExtTypId { fn.fe = (*Encoder).rawExt fn.fd = (*Decoder).rawExt fi.addrD = true fi.addrE = true } else if xfFn := x.getExt(rtid, checkExt); xfFn != nil { fi.xfTag, fi.xfFn = xfFn.tag, xfFn.ext fn.fe = (*Encoder).ext fn.fd = (*Decoder).ext fi.addrD = true if rk == reflect.Struct || rk == reflect.Array { fi.addrE = true } } else if (ti.flagSelfer || ti.flagSelferPtr) && !(checkCircularRef && ti.flagSelferViaCodecgen && ti.kind == byte(reflect.Struct)) { // do not use Selfer generated by codecgen if it is a struct and CheckCircularRef=true fn.fe = (*Encoder).selferMarshal fn.fd = (*Decoder).selferUnmarshal fi.addrD = ti.flagSelferPtr fi.addrE = ti.flagSelferPtr } else if supportMarshalInterfaces && x.isBe() && (ti.flagBinaryMarshaler || ti.flagBinaryMarshalerPtr) && (ti.flagBinaryUnmarshaler || ti.flagBinaryUnmarshalerPtr) { fn.fe = (*Encoder).binaryMarshal fn.fd = (*Decoder).binaryUnmarshal fi.addrD = ti.flagBinaryUnmarshalerPtr fi.addrE = ti.flagBinaryMarshalerPtr } else if supportMarshalInterfaces && !x.isBe() && x.isJs() && (ti.flagJsonMarshaler || ti.flagJsonMarshalerPtr) && (ti.flagJsonUnmarshaler || ti.flagJsonUnmarshalerPtr) { //If JSON, we should check JSONMarshal before textMarshal fn.fe = (*Encoder).jsonMarshal fn.fd = (*Decoder).jsonUnmarshal fi.addrD = ti.flagJsonUnmarshalerPtr fi.addrE = ti.flagJsonMarshalerPtr } else if supportMarshalInterfaces && !x.isBe() && (ti.flagTextMarshaler || ti.flagTextMarshalerPtr) && (ti.flagTextUnmarshaler || ti.flagTextUnmarshalerPtr) { fn.fe = (*Encoder).textMarshal fn.fd = (*Decoder).textUnmarshal fi.addrD = ti.flagTextUnmarshalerPtr 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 := fastpathAvIndex(rtid2); idx != -1 { fn.fe = fastpathAv[idx].encfn fn.fd = fastpathAv[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 := fnloadFastpathUnderlying(ti) if xfe != nil { xfnf := xfe.encfn xfnf2 := xfe.decfn if rk == reflect.Array { fi.addrD = false // decode directly into array value (slice made from it) fn.fd = func(d *Decoder, xf *codecFnInfo, 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.PtrTo(xrt) fn.fd = func(d *Decoder, xf *codecFnInfo, xrv reflect.Value) { if xrv.Kind() == reflect.Ptr { xfnf2(d, xf, rvConvert(xrv, xptr2rt)) } else { xfnf2(d, xf, rvConvert(xrv, xrt)) } } } fn.fe = func(e *Encoder, xf *codecFnInfo, xrv reflect.Value) { xfnf(e, xf, rvConvert(xrv, xrt)) } } } } if fn.fe == nil && fn.fd == nil { switch rk { case reflect.Bool: fn.fe = (*Encoder).kBool fn.fd = (*Decoder).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).kStringToRaw // } else { // fn.fe = (*Encoder).kStringEnc // } fn.fe = (*Encoder).kString fn.fd = (*Decoder).kString case reflect.Int: fn.fd = (*Decoder).kInt fn.fe = (*Encoder).kInt case reflect.Int8: fn.fe = (*Encoder).kInt8 fn.fd = (*Decoder).kInt8 case reflect.Int16: fn.fe = (*Encoder).kInt16 fn.fd = (*Decoder).kInt16 case reflect.Int32: fn.fe = (*Encoder).kInt32 fn.fd = (*Decoder).kInt32 case reflect.Int64: fn.fe = (*Encoder).kInt64 fn.fd = (*Decoder).kInt64 case reflect.Uint: fn.fd = (*Decoder).kUint fn.fe = (*Encoder).kUint case reflect.Uint8: fn.fe = (*Encoder).kUint8 fn.fd = (*Decoder).kUint8 case reflect.Uint16: fn.fe = (*Encoder).kUint16 fn.fd = (*Decoder).kUint16 case reflect.Uint32: fn.fe = (*Encoder).kUint32 fn.fd = (*Decoder).kUint32 case reflect.Uint64: fn.fe = (*Encoder).kUint64 fn.fd = (*Decoder).kUint64 case reflect.Uintptr: fn.fe = (*Encoder).kUintptr fn.fd = (*Decoder).kUintptr case reflect.Float32: fn.fe = (*Encoder).kFloat32 fn.fd = (*Decoder).kFloat32 case reflect.Float64: fn.fe = (*Encoder).kFloat64 fn.fd = (*Decoder).kFloat64 case reflect.Complex64: fn.fe = (*Encoder).kComplex64 fn.fd = (*Decoder).kComplex64 case reflect.Complex128: fn.fe = (*Encoder).kComplex128 fn.fd = (*Decoder).kComplex128 case reflect.Chan: fn.fe = (*Encoder).kChan fn.fd = (*Decoder).kChan case reflect.Slice: fn.fe = (*Encoder).kSlice fn.fd = (*Decoder).kSlice case reflect.Array: fi.addrD = false // decode directly into array value (slice made from it) fn.fe = (*Encoder).kArray fn.fd = (*Decoder).kArray case reflect.Struct: if ti.anyOmitEmpty || ti.flagMissingFielder || ti.flagMissingFielderPtr { fn.fe = (*Encoder).kStruct } else { fn.fe = (*Encoder).kStructNoOmitempty } fn.fd = (*Decoder).kStruct case reflect.Map: fn.fe = (*Encoder).kMap fn.fd = (*Decoder).kMap case reflect.Interface: // encode: reflect.Interface are handled already by preEncodeValue fn.fd = (*Decoder).kInterface fn.fe = (*Encoder).kErr default: // reflect.Ptr and reflect.Interface are handled already by preEncodeValue fn.fe = (*Encoder).kErr fn.fd = (*Decoder).kErr } } } return } // 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 newEncDriver() encDriver newDecDriver() decDriver 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() } // 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. // // Only one of Data or Value is nil. // If Data is nil, then the content of the RawExt is in the 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 } func (binaryEncodingType) isJson() bool { return false } type textEncodingType struct{} func (textEncodingType) isBinary() bool { return false } func (textEncodingType) isJson() 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) (b [2]byte) { return [...]byte{ 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 } func (z bigenHelper) writeUint16(w *encWr, v uint16) { x := z.PutUint16(v) w.writen2(x[0], x[1]) } func (z bigenHelper) writeUint32(w *encWr, v uint32) { w.writen4(z.PutUint32(v)) } func (z bigenHelper) writeUint64(w *encWr, v uint64) { w.writen8(z.PutUint64(v)) } 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. // // Deprecated: Use SetBytesExt or SetInterfaceExt on the Handle instead. func (x *BasicHandle) SetExt(rt reflect.Type, tag uint64, ext Ext) (err error) { if x.isInited() { return errHandleInited } if x.basicHandleRuntimeState == nil { x.basicHandleRuntimeState = new(basicHandleRuntimeState) } 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 } // 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 offset uint16 index uint16 kind uint8 numderef uint8 // encNameAsciiAlphaNum and omitEmpty should be in structFieldInfo, // but are kept here for tighter packaging. encNameAsciiAlphaNum bool // the encName only contains ascii alphabet and numbers omitEmpty bool typ reflect.Type } // 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 } // field returns the field of the struct. func (path *structFieldInfoPathNode) field(v reflect.Value) (rv2 reflect.Value) { if parent := path.parent; parent != nil { v = parent.field(v) for j, k := uint8(0), parent.numderef; j < k; j++ { if rvIsNil(v) { return } v = v.Elem() } } return path.rvField(v) } // fieldAlloc returns the field of the struct. // It allocates if a nil value was seen while searching. func (path *structFieldInfoPathNode) fieldAlloc(v reflect.Value) (rv2 reflect.Value) { if parent := path.parent; parent != nil { v = parent.fieldAlloc(v) for j, k := uint8(0), parent.numderef; j < k; j++ { if rvIsNil(v) { rvSetDirect(v, reflect.New(rvType(v).Elem())) } v = v.Elem() } } return path.rvField(v) } type structFieldInfo struct { encName string // encode name // encNameHash uintptr // fieldName string // currently unused // encNameAsciiAlphaNum and omitEmpty should be here, // but are stored in structFieldInfoPathNode for tighter packaging. path structFieldInfoPathNode } 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 (si *structFieldInfo) parseTag(stag string) { if stag == "" { return } for i, s := range strings.Split(stag, ",") { if i == 0 { if s != "" { si.encName = s } } else { switch s { case "omitempty": si.path.omitEmpty = true } } } } 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 anyOmitEmpty bool // true if a struct, and any of the fields are tagged "omitempty" 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 sfi4Name map[string]*structFieldInfo // map. used for finding sfi given a name *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? flagSelferViaCodecgen bool // 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 infoFieldOmitempty bool sfi structFieldInfos } func (ti *typeInfo) siForEncName(name []byte) (si *structFieldInfo) { return ti.sfi4Name[string(name)] } func (ti *typeInfo) resolve(x []structFieldInfo, ss map[string]uint16) (n int) { n = len(x) for i := range x { ui := uint16(i) xn := x[i].encName j, ok := ss[xn] if ok { i2clear := ui // index to be cleared if x[i].path.depth() < x[j].path.depth() { // this one is shallower ss[xn] = ui i2clear = j } if x[i2clear].encName != "" { x[i2clear].encName = "" n-- } } else { ss[xn] = ui } } return } func (ti *typeInfo) init(x []structFieldInfo, n int) { var anyOmitEmpty bool // 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 { if x[i].encName == "" { continue } if !anyOmitEmpty && x[i].path.omitEmpty { anyOmitEmpty = true } w[n] = x[i] y[n] = &w[n] m[x[i].encName] = &w[n] 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), n) } copy(z, y) sort.Sort(sfiSortedByEncName(z)) ti.anyOmitEmpty = anyOmitEmpty ti.sfi.load(y, z) ti.sfi4Name = m } // Handling flagCanTransient // // We support transient optimization if the kind of the type is // a number, bool, string, or slice (of number/bool). // In addition, we also support if the kind is struct or array, // and the type does not contain any pointers recursively). // // Noteworthy that 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 transientBitsetFlags() *bitset32 { if transientValueHasStringSlice { return &numBoolStrSliceBitset } return &numBoolBitset } func isCanTransient(t reflect.Type, k reflect.Kind) (v bool) { var bs = transientBitsetFlags() if bs.isset(byte(k)) { v = true } else if k == reflect.Slice { elem := t.Elem() v = numBoolBitset.isset(byte(elem.Kind())) } else if k == reflect.Array { elem := t.Elem() v = isCanTransient(elem, elem.Kind()) } else if k == reflect.Struct { v = true for j, jlen := 0, t.NumField(); j < jlen; j++ { f := t.Field(j) if !isCanTransient(f.Type, f.Type.Kind()) { v = false return } } } else { v = false } return } func (ti *typeInfo) doSetFlagCanTransient() { if transientSizeMax > 0 { ti.flagCanTransient = ti.size <= transientSizeMax } else { ti.flagCanTransient = true } if ti.flagCanTransient { if !transientBitsetFlags().isset(ti.kind) { ti.flagCanTransient = isCanTransient(ti.rt, reflect.Kind(ti.kind)) } } } 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 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, 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.PtrTo(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() != "", } // 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) b1, b2 = implIntf(rt, isSelferViaCodecgenerTyp) ti.flagSelferViaCodecgen = b1 || b2 ti.flagMarshalInterface = ti.flagSelfer || ti.flagSelferPtr || ti.flagSelferViaCodecgen || 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.doSetFlagCanTransient() 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 } pp, pi := &pool4tiload, pool4tiload.Get() pv := pi.(*typeInfoLoad) pv.reset() pv.etypes = append(pv.etypes, ti.rtid) x.rget(rt, rtid, nil, pv, omitEmpty) n := ti.resolve(pv.sfis, pv.sfiNames) ti.init(pv.sfis, n) pp.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() sp := x.infos.load() // 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, rtid uintptr, path *structFieldInfoPathNode, pv *typeInfoLoad, omitEmpty 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 si structFieldInfo var numderef uint8 = 0 for xft := f.Type; xft.Kind() == reflect.Ptr; xft = xft.Elem() { numderef++ } var parsed bool // 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 ft := f.Type isPtr := ft.Kind() == reflect.Ptr for ft.Kind() == reflect.Ptr { ft = ft.Elem() } 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) || (!allowSetUnexportedEmbeddedPtr && isUnexported && isPtr) { continue } doInline := stag == "" if !doInline { si.parseTag(stag) parsed = true doInline = si.encName == "" // si.isZero() } if doInline && isStruct { // if etypes contains this, don't call rget again (as fields are already seen here) ftid := rt2id(ft) // 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, typ: f.Type, offset: uint16(f.Offset), index: j, kind: uint8(fkind), numderef: numderef, } x.rget(ft, ftid, path2, pv, omitEmpty) } continue } } // after the anonymous dance: if an unexported field, skip if isUnexported || f.Name == "" { // f.Name cannot be "", but defensively handle it continue } si.path = structFieldInfoPathNode{ parent: path, typ: f.Type, offset: uint16(f.Offset), index: j, kind: uint8(fkind), numderef: numderef, // set asciiAlphaNum to true (default); checked and may be set to false below encNameAsciiAlphaNum: true, // note: omitEmpty might have been set in an earlier parseTag call, etc - so carry it forward omitEmpty: si.path.omitEmpty, } if !parsed { si.encName = f.Name si.parseTag(stag) parsed = true } else if si.encName == "" { si.encName = f.Name } // si.encNameHash = maxUintptr() // hashShortString(bytesView(si.encName)) if omitEmpty { si.path.omitEmpty = true } for i := len(si.encName) - 1; i >= 0; i-- { // bounds-check elimination if !asciiAlphaNumBitset.isset(si.encName[i]) { si.path.encNameAsciiAlphaNum = false break } } pv.sfis = append(pv.sfis, si) } } 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.PtrTo(rt).Implements(iTyp) } return } func isSliceBoundsError(s string) bool { return strings.Contains(s, "index out of range") || strings.Contains(s, "slice bounds out of range") } func sprintf(format string, v ...interface{}) string { return fmt.Sprintf(format, v...) } func panicValToErr(h errDecorator, v interface{}, err *error) { if v == *err { return } switch xerr := v.(type) { case nil: case runtime.Error: d, dok := h.(*Decoder) if dok && d.bytes && isSliceBoundsError(xerr.Error()) { *err = io.EOF } else { h.wrapErr(xerr, err) } case error: switch xerr { case nil: case io.EOF, io.ErrUnexpectedEOF, errEncoderNotInitialized, errDecoderNotInitialized: // treat as special (bubble up) *err = xerr default: h.wrapErr(xerr, err) } default: // we don't expect this to happen (as this library always panics with an error) h.wrapErr(fmt.Errorf("%v", v), err) } } func usableByteSlice(bs []byte, slen int) (out []byte, changed bool) { const maxCap = 1024 * 1024 * 64 // 64MB const skipMaxCap = false // allow to test if slen <= 0 { return []byte{}, true } if slen <= cap(bs) { return bs[:slen], false } // slen > cap(bs) ... handle memory overload appropriately if skipMaxCap || slen <= maxCap { return make([]byte, slen), true } return make([]byte, maxCap), true } func mapKeyFastKindFor(k reflect.Kind) mapKeyFastKind { return mapKeyFastKindVals[k&31] } // ---- type codecFnInfo struct { ti *typeInfo xfFn Ext xfTag uint64 addrD bool addrDf bool // force: if addrD, then decode function MUST take a ptr addrE bool // addrEf bool // force: if addrE, then encode function MUST take a ptr } // codecFn 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 codecFn struct { i codecFnInfo fe func(*Encoder, *codecFnInfo, reflect.Value) fd func(*Decoder, *codecFnInfo, reflect.Value) // _ [1]uint64 // padding (cache-aligned) } type codecRtidFn struct { rtid uintptr fn *codecFn } 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) { // 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 } // ---- // 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.errorf("float32 overflow: %v", v) } return v } func (x checkOverflow) UintV(v uint64, bitsize uint8) uint64 { if x.Uint(v, bitsize) { halt.errorf("uint64 overflow: %v", v) } return v } func (x checkOverflow) IntV(v int64, bitsize uint8) int64 { if x.Int(v, bitsize) { halt.errorf("int64 overflow: %v", v) } return v } func (x checkOverflow) SignedIntV(v uint64) int64 { if x.SignedInt(v) { halt.errorf("uint64 to int64 overflow: %v", 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) } // ----------------------- 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] } // ------------ type panicHdl struct{} // errorv will panic if err is defined (not nil) func (panicHdl) onerror(err error) { if err != nil { panic(err) } } // 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. // //go:noinline func (panicHdl) errorf(format string, params ...interface{}) { if format == "" { panic(errPanicUndefined) } if len(params) == 0 { panic(errors.New(format)) } panic(fmt.Errorf(format, params...)) } // ---------------------------------------------------- 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 ofthe 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 byteSliceAddr(v0) != byteSliceAddr(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 bytesFreeListNoCache { 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 bytesFreeListNoCache { return make([]byte, 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([]byte, 0, freelistCapacity(length)) } func (x *bytesFreelist) put(v []byte) { if bytesFreeListNoCache || cap(v) == 0 { 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 } } } 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.checkPutGet(v, length) } func (x *bytesFreelist) checkPutGet(v []byte, length int) []byte { // checkPutGet broken out into its own function, so check is inlineable in general case const useSeparateCalls = false if useSeparateCalls { x.put(v) return x.get(length) } if bytesFreeListNoCache { 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] 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) { 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 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 } go-1.2.8/codec/helper.s000066400000000000000000000000001435255326100146430ustar00rootroot00000000000000go-1.2.8/codec/helper_internal.go000066400000000000000000000073351435255326100167240ustar00rootroot00000000000000// 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 // maxArrayLen is the size of uint, which determines // the maximum length of any array. const maxArrayLen = 1<<((32<<(^uint(0)>>63))-1) - 1 // All non-std package dependencies live in this file, // so porting to different environment is easy (just update functions). 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 } // 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 } go-1.2.8/codec/helper_not_unsafe.go000066400000000000000000000353521435255326100172510ustar00rootroot00000000000000// 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 // +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 const transientSizeMax = 0 const transientValueHasStringSlice = true 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 okBytes3(b []byte) (v [4]byte) { copy(v[1:], b) return } func okBytes4(b []byte) (v [4]byte) { copy(v[:], b) return } func okBytes8(b []byte) (v [8]byte) { copy(v[:], b) return } func isNil(v interface{}) (rv reflect.Value, isnil bool) { rv = reflect.ValueOf(v) if isnilBitset.isset(byte(rv.Kind())) { isnil = rv.IsNil() } return } 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 rv4i(i interface{}) reflect.Value { return reflect.ValueOf(i) } // func rv4iK(i interface{}, kind byte, isref bool) reflect.Value { return reflect.ValueOf(i) } func rv2i(rv reflect.Value) interface{} { return rv.Interface() } func rvAddr(rv reflect.Value, ptrType reflect.Type) reflect.Value { return rv.Addr() } 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() } // -------------------------- 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 := rvType(v) 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.path.field(v) if sfv.IsValid() && !isEmptyValue(sfv, tinfos, recursive) { return false } } return true } // -------------------------- 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 struct { perType } type encPerType struct { 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 structFieldInfos struct { c []*structFieldInfo s []*structFieldInfo } func (x *structFieldInfos) load(source, sorted []*structFieldInfo) { x.c = source x.s = sorted } func (x *structFieldInfos) sorted() (v []*structFieldInfo) { return x.s } func (x *structFieldInfos) source() (v []*structFieldInfo) { return x.c } type atomicClsErr struct { v atomic.Value } func (x *atomicClsErr) load() (e clsErr) { if i := x.v.Load(); i != nil { e = i.(clsErr) } return } func (x *atomicClsErr) store(p clsErr) { x.v.Store(p) } // -------------------------- type atomicTypeInfoSlice struct { v atomic.Value } func (x *atomicTypeInfoSlice) load() (e []rtid2ti) { if i := x.v.Load(); i != nil { e = i.([]rtid2ti) } return } func (x *atomicTypeInfoSlice) store(p []rtid2ti) { x.v.Store(p) } // -------------------------- type atomicRtidFnSlice struct { v atomic.Value } func (x *atomicRtidFnSlice) load() (e []codecRtidFn) { if i := x.v.Load(); i != nil { e = i.([]codecRtidFn) } return } func (x *atomicRtidFnSlice) store(p []codecRtidFn) { x.v.Store(p) } // -------------------------- 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 rvSliceIndex(rv reflect.Value, i int, ti *typeInfo) 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(reflectArrayOf(rvLenSlice(rv), rvType(rv).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() } // func rvLenArray(rv reflect.Value) int { return rv.Len() } // ------------ map range and map indexing ---------- func mapStoresElemIndirect(elemsize uintptr) bool { return false } func mapSet(m, k, v reflect.Value, keyFastKind mapKeyFastKind, _, _ bool) { m.SetMapIndex(k, v) } func mapGet(m, k, v reflect.Value, keyFastKind mapKeyFastKind, _, _ bool) (vv reflect.Value) { return m.MapIndex(k) } // func mapDelete(m, k reflect.Value) { // m.SetMapIndex(k, reflect.Value{}) // } func mapAddrLoopvarRV(t reflect.Type, k reflect.Kind) (r reflect.Value) { return // reflect.New(t).Elem() } // ---------- ENCODER optimized --------------- func (e *Encoder) jsondriver() *jsonEncDriver { return e.e.(*jsonEncDriver) } // ---------- DECODER optimized --------------- func (d *Decoder) checkBreak() bool { return d.d.CheckBreak() } func (d *Decoder) jsondriver() *jsonDecDriver { return d.d.(*jsonDecDriver) } func (d *Decoder) stringZC(v []byte) (s string) { return d.string(v) } func (d *Decoder) mapKeyString(callFnRvk *bool, kstrbs, kstr2bs *[]byte) string { return d.string(*kstr2bs) } // ---------- structFieldInfo optimized --------------- func (n *structFieldInfoPathNode) rvField(v reflect.Value) reflect.Value { return v.Field(int(n.index)) } // ---------- others --------------- go-1.2.8/codec/helper_not_unsafe_not_gc.go000066400000000000000000000010431435255326100205700ustar00rootroot00000000000000// 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 || !gc // +build !go1.9 safe codec.safe appengine !gc package codec import "reflect" // This files contains safe versions of the code where the unsafe versions are not supported // in either gccgo or gollvm. // // - rvType: // reflect.toType is not supported in gccgo, gollvm. func rvType(rv reflect.Value) reflect.Type { return rv.Type() } go-1.2.8/codec/helper_test.go000066400000000000000000000026031435255326100160600ustar00rootroot00000000000000// 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 // All non-std package dependencies related to testing live in this file, // so porting to different environment is easy (just update functions). import ( "errors" "reflect" ) // --- these functions are used by both benchmarks and tests var errDeepEqualNotMatch = errors.New("Not Match") func deepEqual(v1, v2 interface{}) (err error) { if !reflect.DeepEqual(v1, v2) { err = errDeepEqualNotMatch } return } func approxDataSize(rv reflect.Value) (sum int) { switch rk := rv.Kind(); rk { case reflect.Invalid: case reflect.Ptr, reflect.Interface: sum += int(rv.Type().Size()) sum += approxDataSize(rv.Elem()) case reflect.Slice: sum += int(rv.Type().Size()) for j := 0; j < rv.Len(); j++ { sum += approxDataSize(rv.Index(j)) } case reflect.String: sum += int(rv.Type().Size()) sum += rv.Len() case reflect.Map: sum += int(rv.Type().Size()) for _, mk := range rv.MapKeys() { sum += approxDataSize(mk) sum += approxDataSize(rv.MapIndex(mk)) } case reflect.Struct: //struct size already includes the full data size. //sum += int(rv.Type().Size()) for j := 0; j < rv.NumField(); j++ { sum += approxDataSize(rv.Field(j)) } default: //pure value types sum += int(rv.Type().Size()) } return } go-1.2.8/codec/helper_unsafe.go000066400000000000000000001164301435255326100163660ustar00rootroot00000000000000// 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 // +build !safe,!codec.safe,!appengine,go1.9 // minimum of go 1.9 is needed, as that is the minimum for all features and linked functions we need // - typedmemclr was introduced in go 1.8 // - mapassign_fastXXX was introduced in go 1.9 // 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 // - IsNil // MARKER: Some functions here will not be hit during code coverage runs due to optimizations, e.g. // - rvCopySlice: decode calls it if rvGrowSlice didn't set the new slice into the pointer to the orig slice. // however, helper_unsafe sets it, so there's no need to call rvCopySlice later // - rvSlice: same as above // - rvGetArray4Bytes: only called within kArray for []byte, but that is now handled // within the fast-path directly 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 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) } x.arr = [transientSizeMax]byte{} // memclr return unsafe.Pointer(&x.arr) } type perType struct { elems [2]unsafePerTypeElem } type decPerType struct { 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) } // 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 } // MARKER: okBytesN functions will copy N bytes into the top slots of the return array. // These functions expect that the bounds are valid, and have been checked before this is called. // copy(...) does a number of checks which are unnecessary in this situation when in bounds. func okBytes3(b []byte) (v [4]byte) { *(*[3]byte)(unsafe.Pointer(&v[1])) = *((*[3]byte)(((*unsafeSlice)(unsafe.Pointer(&b))).Data)) return } func okBytes4(b []byte) [4]byte { return *((*[4]byte)(((*unsafeSlice)(unsafe.Pointer(&b))).Data)) } func okBytes8(b []byte) [8]byte { return *((*[8]byte)(((*unsafeSlice)(unsafe.Pointer(&b))).Data)) } // isNil says whether the value v is nil. // This applies to references like map/ptr/unsafepointer/chan/func, // and non-reference values like interface/slice. func isNil(v interface{}) (rv reflect.Value, isnil bool) { var ui = (*unsafeIntf)(unsafe.Pointer(&v)) isnil = ui.ptr == nil if !isnil { rv, isnil = unsafeIsNilIntfOrSlice(ui, v) } return } func unsafeIsNilIntfOrSlice(ui *unsafeIntf, v interface{}) (rv reflect.Value, isnil bool) { rv = reflect.ValueOf(v) // reflect.ValueOf is currently not inline'able - so call it directly tk := rv.Kind() isnil = (tk == reflect.Interface || tk == reflect.Slice) && *(*unsafe.Pointer)(ui.ptr) == nil return } // return the pointer for a reference (map/chan/func/pointer/unsafe.Pointer). // true references (map, func, chan, ptr - NOT slice) may be double-referenced? as flagIndir // // Assumes that v is a reference (map/func/chan/ptr/func) 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{}) { // We tap into implememtation details from // the source go stdlib reflect/value.go, and trims the implementation. // // e.g. // - a map/ptr is a reference, thus flagIndir is not set on it // - an int/slice is not a reference, thus flagIndir is set on it 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 } func rvIsNil(rv reflect.Value) bool { urv := (*unsafeReflectValue)(unsafe.Pointer(&rv)) if urv.flag&unsafeFlagIndir != 0 { return *(*unsafe.Pointer)(urv.ptr) == nil } return 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(rvType(v)) } 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 } // -------------------------- type structFieldInfos struct { c unsafe.Pointer // source s unsafe.Pointer // sorted length int } func (x *structFieldInfos) load(source, sorted []*structFieldInfo) { s := (*unsafeSlice)(unsafe.Pointer(&sorted)) x.s = s.Data x.length = s.Len s = (*unsafeSlice)(unsafe.Pointer(&source)) x.c = s.Data } func (x *structFieldInfos) sorted() (v []*structFieldInfo) { *(*unsafeSlice)(unsafe.Pointer(&v)) = unsafeSlice{x.s, x.length, x.length} // s := (*unsafeSlice)(unsafe.Pointer(&v)) // s.Data = x.sorted0 // s.Len = x.length // s.Cap = s.Len return } func (x *structFieldInfos) source() (v []*structFieldInfo) { *(*unsafeSlice)(unsafe.Pointer(&v)) = unsafeSlice{x.c, x.length, x.length} return } // atomicXXX is expected to be 2 words (for symmetry with atomic.Value) // // 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. // // Note: with atomic.(Load|Store)Pointer, we MUST work with an unsafe.Pointer directly. // ---------------------- type atomicTypeInfoSlice struct { v unsafe.Pointer // *[]rtid2ti } func (x *atomicTypeInfoSlice) load() (s []rtid2ti) { x2 := atomic.LoadPointer(&x.v) if x2 != nil { s = *(*[]rtid2ti)(x2) } return } func (x *atomicTypeInfoSlice) store(p []rtid2ti) { atomic.StorePointer(&x.v, unsafe.Pointer(&p)) } // MARKER: in safe mode, atomicXXX are atomic.Value, which contains an interface{}. // This is 2 words. // consider padding atomicXXX here with a uintptr, so they fit into 2 words also. // -------------------------- type atomicRtidFnSlice struct { v unsafe.Pointer // *[]codecRtidFn } func (x *atomicRtidFnSlice) load() (s []codecRtidFn) { x2 := atomic.LoadPointer(&x.v) if x2 != nil { s = *(*[]codecRtidFn)(x2) } return } func (x *atomicRtidFnSlice) store(p []codecRtidFn) { atomic.StorePointer(&x.v, unsafe.Pointer(&p)) } // -------------------------- type atomicClsErr struct { v unsafe.Pointer // *clsErr } func (x *atomicClsErr) load() (e clsErr) { x2 := (*clsErr)(atomic.LoadPointer(&x.v)) if x2 != nil { e = *x2 } return } func (x *atomicClsErr) store(p clsErr) { atomic.StorePointer(&x.v, unsafe.Pointer(&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) { urv := (*unsafeReflectValue)(unsafe.Pointer(&rv)) *(*[]byte)(urv.ptr) = v } func rvSetString(rv reflect.Value, v string) { urv := (*unsafeReflectValue)(unsafe.Pointer(&rv)) *(*string)(urv.ptr) = v } func rvSetBool(rv reflect.Value, v bool) { urv := (*unsafeReflectValue)(unsafe.Pointer(&rv)) *(*bool)(urv.ptr) = v } func rvSetTime(rv reflect.Value, v time.Time) { urv := (*unsafeReflectValue)(unsafe.Pointer(&rv)) *(*time.Time)(urv.ptr) = v } func rvSetFloat32(rv reflect.Value, v float32) { urv := (*unsafeReflectValue)(unsafe.Pointer(&rv)) *(*float32)(urv.ptr) = v } func rvSetFloat64(rv reflect.Value, v float64) { urv := (*unsafeReflectValue)(unsafe.Pointer(&rv)) *(*float64)(urv.ptr) = v } func rvSetComplex64(rv reflect.Value, v complex64) { urv := (*unsafeReflectValue)(unsafe.Pointer(&rv)) *(*complex64)(urv.ptr) = v } func rvSetComplex128(rv reflect.Value, v complex128) { urv := (*unsafeReflectValue)(unsafe.Pointer(&rv)) *(*complex128)(urv.ptr) = v } func rvSetInt(rv reflect.Value, v int) { urv := (*unsafeReflectValue)(unsafe.Pointer(&rv)) *(*int)(urv.ptr) = v } func rvSetInt8(rv reflect.Value, v int8) { urv := (*unsafeReflectValue)(unsafe.Pointer(&rv)) *(*int8)(urv.ptr) = v } func rvSetInt16(rv reflect.Value, v int16) { urv := (*unsafeReflectValue)(unsafe.Pointer(&rv)) *(*int16)(urv.ptr) = v } func rvSetInt32(rv reflect.Value, v int32) { urv := (*unsafeReflectValue)(unsafe.Pointer(&rv)) *(*int32)(urv.ptr) = v } func rvSetInt64(rv reflect.Value, v int64) { urv := (*unsafeReflectValue)(unsafe.Pointer(&rv)) *(*int64)(urv.ptr) = v } func rvSetUint(rv reflect.Value, v uint) { urv := (*unsafeReflectValue)(unsafe.Pointer(&rv)) *(*uint)(urv.ptr) = v } func rvSetUintptr(rv reflect.Value, v uintptr) { urv := (*unsafeReflectValue)(unsafe.Pointer(&rv)) *(*uintptr)(urv.ptr) = v } func rvSetUint8(rv reflect.Value, v uint8) { urv := (*unsafeReflectValue)(unsafe.Pointer(&rv)) *(*uint8)(urv.ptr) = v } func rvSetUint16(rv reflect.Value, v uint16) { urv := (*unsafeReflectValue)(unsafe.Pointer(&rv)) *(*uint16)(urv.ptr) = v } func rvSetUint32(rv reflect.Value, v uint32) { urv := (*unsafeReflectValue)(unsafe.Pointer(&rv)) *(*uint32)(urv.ptr) = v } func rvSetUint64(rv reflect.Value, v uint64) { urv := (*unsafeReflectValue)(unsafe.Pointer(&rv)) *(*uint64)(urv.ptr) = 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 { if urv.ptr != unsafeZeroAddr { typedmemclr(urv.typ, urv.ptr) } } else { typedmemmove(urv.typ, urv.ptr, uv.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)) var x []struct{} ux := (*unsafeSlice)(unsafe.Pointer(&x)) *ux = *(*unsafeSlice)(urv.ptr) 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 rvSliceIndex(rv reflect.Value, i int, ti *typeInfo) (v reflect.Value) { urv := (*unsafeReflectValue)(unsafe.Pointer(&rv)) uv := (*unsafeReflectValue)(unsafe.Pointer(&v)) uv.ptr = unsafe.Pointer(uintptr(((*unsafeSlice)(urv.ptr)).Data) + 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 } func rvArrayIndex(rv reflect.Value, i int, ti *typeInfo) (v reflect.Value) { urv := (*unsafeReflectValue)(unsafe.Pointer(&rv)) uv := (*unsafeReflectValue)(unsafe.Pointer(&v)) uv.ptr = unsafe.Pointer(uintptr(urv.ptr) + uintptr(int(ti.elemsize)*i)) uv.typ = ((*unsafeIntf)(unsafe.Pointer(&ti.elem))).ptr uv.flag = uintptr(ti.elemkind) | unsafeFlagIndir | unsafeFlagAddr return } // if scratch is nil, then return a writable view (assuming canAddr=true) func rvGetArrayBytes(rv reflect.Value, scratch []byte) (bs []byte) { urv := (*unsafeReflectValue)(unsafe.Pointer(&rv)) bx := (*unsafeSlice)(unsafe.Pointer(&bs)) 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 := reflectArrayOf(rvLenSlice(rv), rvType(rv).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 rvGetBool(rv reflect.Value) bool { v := (*unsafeReflectValue)(unsafe.Pointer(&rv)) return *(*bool)(v.ptr) } func rvGetBytes(rv reflect.Value) []byte { v := (*unsafeReflectValue)(unsafe.Pointer(&rv)) return *(*[]byte)(v.ptr) } func rvGetTime(rv reflect.Value) time.Time { v := (*unsafeReflectValue)(unsafe.Pointer(&rv)) return *(*time.Time)(v.ptr) } func rvGetString(rv reflect.Value) string { v := (*unsafeReflectValue)(unsafe.Pointer(&rv)) return *(*string)(v.ptr) } func rvGetFloat64(rv reflect.Value) float64 { v := (*unsafeReflectValue)(unsafe.Pointer(&rv)) return *(*float64)(v.ptr) } func rvGetFloat32(rv reflect.Value) float32 { v := (*unsafeReflectValue)(unsafe.Pointer(&rv)) return *(*float32)(v.ptr) } func rvGetComplex64(rv reflect.Value) complex64 { v := (*unsafeReflectValue)(unsafe.Pointer(&rv)) return *(*complex64)(v.ptr) } func rvGetComplex128(rv reflect.Value) complex128 { v := (*unsafeReflectValue)(unsafe.Pointer(&rv)) return *(*complex128)(v.ptr) } func rvGetInt(rv reflect.Value) int { v := (*unsafeReflectValue)(unsafe.Pointer(&rv)) return *(*int)(v.ptr) } func rvGetInt8(rv reflect.Value) int8 { v := (*unsafeReflectValue)(unsafe.Pointer(&rv)) return *(*int8)(v.ptr) } func rvGetInt16(rv reflect.Value) int16 { v := (*unsafeReflectValue)(unsafe.Pointer(&rv)) return *(*int16)(v.ptr) } func rvGetInt32(rv reflect.Value) int32 { v := (*unsafeReflectValue)(unsafe.Pointer(&rv)) return *(*int32)(v.ptr) } func rvGetInt64(rv reflect.Value) int64 { v := (*unsafeReflectValue)(unsafe.Pointer(&rv)) return *(*int64)(v.ptr) } func rvGetUint(rv reflect.Value) uint { v := (*unsafeReflectValue)(unsafe.Pointer(&rv)) return *(*uint)(v.ptr) } func rvGetUint8(rv reflect.Value) uint8 { v := (*unsafeReflectValue)(unsafe.Pointer(&rv)) return *(*uint8)(v.ptr) } func rvGetUint16(rv reflect.Value) uint16 { v := (*unsafeReflectValue)(unsafe.Pointer(&rv)) return *(*uint16)(v.ptr) } func rvGetUint32(rv reflect.Value) uint32 { v := (*unsafeReflectValue)(unsafe.Pointer(&rv)) return *(*uint32)(v.ptr) } func rvGetUint64(rv reflect.Value) uint64 { v := (*unsafeReflectValue)(unsafe.Pointer(&rv)) return *(*uint64)(v.ptr) } func rvGetUintptr(rv reflect.Value) uintptr { v := (*unsafeReflectValue)(unsafe.Pointer(&rv)) return *(*uintptr)(v.ptr) } 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+ has runtime/hashmap.go or runtime/map.go which has a // hIter struct with the first 2 values being key and value // of the current iteration. // // This *hIter is passed to mapiterinit, mapiternext, mapiterkey, mapiterelem. // We bypass the reflect wrapper functions and just use the *hIter directly. // // Though *hIter has many fields, we only care about the first 2. // // We directly embed this in unsafeMapIter below // // hiter is typically about 12 words, but we just fill up unsafeMapIter to 32 words, // so it fills multiple cache lines and can give some extra space to accomodate small growth. type unsafeMapIter struct { mtyp, mptr unsafe.Pointer k, v reflect.Value kisref bool visref bool mapvalues bool done bool started bool _ [3]byte // padding it struct { key unsafe.Pointer value unsafe.Pointer _ [20]uintptr // padding for other fields (to make up 32 words for enclosing struct) } } 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 { (*unsafeReflectValue)(unsafe.Pointer(&t.k)).ptr = t.it.key } else { k := (*unsafeReflectValue)(unsafe.Pointer(&t.k)) typedmemmove(k.typ, k.ptr, t.it.key) } if t.mapvalues { if helperUnsafeDirectAssignMapEntry || t.visref { (*unsafeReflectValue)(unsafe.Pointer(&t.v)).ptr = t.it.value } else { v := (*unsafeReflectValue)(unsafe.Pointer(&t.v)) typedmemmove(v.typ, v.ptr, t.it.value) } } return true } func (t *unsafeMapIter) Key() (r reflect.Value) { return t.k } func (t *unsafeMapIter) Value() (r reflect.Value) { return 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 = k t.kisref = refBitset.isset(byte(k.Kind())) if mapvalues { t.v = v t.visref = refBitset.isset(byte(v.Kind())) } else { t.v = reflect.Value{} } } // 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 } // func mapDelete(m, k reflect.Value) { // var urv = (*unsafeReflectValue)(unsafe.Pointer(&k)) // var kptr = unsafeMapKVPtr(urv) // urv = (*unsafeReflectValue)(unsafe.Pointer(&m)) // mapdelete(urv.typ, rv2ptr(urv), kptr) // } // 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 } // ---------- ENCODER optimized --------------- func (e *Encoder) jsondriver() *jsonEncDriver { return (*jsonEncDriver)((*unsafeIntf)(unsafe.Pointer(&e.e)).ptr) } func (d *Decoder) zerocopystate() bool { return d.decByteState == decByteStateZerocopy && d.h.ZeroCopy } func (d *Decoder) stringZC(v []byte) (s string) { if d.zerocopystate() { return stringView(v) } return d.string(v) } func (d *Decoder) mapKeyString(callFnRvk *bool, kstrbs, kstr2bs *[]byte) string { if !d.zerocopystate() { *callFnRvk = true if d.decByteState == decByteStateReuseBuf { *kstrbs = append((*kstrbs)[:0], (*kstr2bs)...) *kstr2bs = *kstrbs } } return stringView(*kstr2bs) } // ---------- DECODER optimized --------------- func (d *Decoder) checkBreak() bool { // MARKER: jsonDecDriver.CheckBreak() costs over 80, and this isn't inlined. // Consequently, there's no benefit in incurring the cost of this // wrapping function checkBreak. // // It is faster to just call the interface method directly. // if d.js { // return d.jsondriver().CheckBreak() // } // if d.cbor { // return d.cbordriver().CheckBreak() // } return d.d.CheckBreak() } func (d *Decoder) jsondriver() *jsonDecDriver { return (*jsonDecDriver)((*unsafeIntf)(unsafe.Pointer(&d.d)).ptr) } // ---------- structFieldInfo optimized --------------- func (n *structFieldInfoPathNode) 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)) 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 mapdelete runtime.mapdelete //go:noescape func mapdelete(typ unsafe.Pointer, m 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) // 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) go-1.2.8/codec/helper_unsafe_compiler_gc.go000066400000000000000000000125541435255326100207330ustar00rootroot00000000000000// 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 // +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 ) func unsafeGrowslice(typ unsafe.Pointer, old unsafeSlice, cap, incr int) (v unsafeSlice) { return growslice(typ, old, cap+incr) } func rvType(rv reflect.Value) reflect.Type { return rvPtrToType(((*unsafeReflectValue)(unsafe.Pointer(&rv))).typ) // 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, keyFastKind mapKeyFastKind, valIsIndirect, valIsRef bool) { 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 valIsIndirect { vvptr = mapassign(urv.typ, mptr, kptr) typedmemmove(vtyp, vvptr, vptr) // reflect_mapassign(urv.typ, mptr, kptr, vptr) return } switch keyFastKind { 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 keyFastKind != 0 && valIsIndirect { // vvptr = *(*unsafe.Pointer)(vvptr) // } typedmemmove(vtyp, vvptr, vptr) } func mapGet(m, k, v reflect.Value, keyFastKind mapKeyFastKind, valIsIndirect, valIsRef bool) (_ 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 keyFastKind { 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 keyFastKind != 0 && valIsIndirect { urv.ptr = *(*unsafe.Pointer)(vvptr) } else if helperUnsafeDirectAssignMapEntry || valIsRef { urv.ptr = vvptr } else { typedmemmove(urv.typ, urv.ptr, vvptr) } return v } //go:linkname unsafeZeroArr runtime.zeroVal var unsafeZeroArr [1024]byte //go:linkname rvPtrToType reflect.toType //go:noescape func rvPtrToType(typ unsafe.Pointer) reflect.Type //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-1.2.8/codec/helper_unsafe_compiler_not_gc.go000066400000000000000000000044501435255326100216070ustar00rootroot00000000000000// 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 // +build !safe,!codec.safe,!appengine,go1.9,!gc package codec import ( "reflect" _ "runtime" // needed for go linkname(s) "unsafe" ) var unsafeZeroArr [1024]byte // 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 } // func unsafeNew(t reflect.Type, typ unsafe.Pointer) unsafe.Pointer { // rv := reflect.New(t) // return ((*unsafeReflectValue)(unsafe.Pointer(&rv))).ptr // } // 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 mapStoresElemIndirect(elemsize uintptr) bool { return false } func mapSet(m, k, v reflect.Value, _ mapKeyFastKind, _, valIsRef bool) { 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, _ mapKeyFastKind, _, valIsRef bool) (_ 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 || valIsRef { urv.ptr = vvptr } else { typedmemmove(urv.typ, urv.ptr, vvptr) } return v } go-1.2.8/codec/json.go000066400000000000000000001076701435255326100145250ustar00rootroot00000000000000// 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 ( "bytes" "encoding/base64" "math" "reflect" "strconv" "time" "unicode" "unicode/utf16" "unicode/utf8" ) //-------------------------------- var jsonLiterals = [...]byte{ '"', 't', 'r', 'u', 'e', '"', '"', 'f', 'a', 'l', 's', 'e', '"', '"', 'n', 'u', 'l', 'l', '"', } const ( jsonLitTrueQ = 0 jsonLitTrue = 1 jsonLitFalseQ = 6 jsonLitFalse = 7 jsonLitNullQ = 13 jsonLitNull = 14 ) var ( // jsonLiteralTrueQ = jsonLiterals[jsonLitTrueQ : jsonLitTrueQ+6] // jsonLiteralFalseQ = jsonLiterals[jsonLitFalseQ : jsonLitFalseQ+7] // jsonLiteralNullQ = jsonLiterals[jsonLitNullQ : jsonLitNullQ+6] jsonLiteralTrue = jsonLiterals[jsonLitTrue : jsonLitTrue+4] jsonLiteralFalse = jsonLiterals[jsonLitFalse : jsonLitFalse+5] jsonLiteralNull = jsonLiterals[jsonLitNull : jsonLitNull+4] // these are used, after consuming the first char jsonLiteral4True = jsonLiterals[jsonLitTrue+1 : jsonLitTrue+4] jsonLiteral4False = jsonLiterals[jsonLitFalse+1 : jsonLitFalse+5] jsonLiteral4Null = jsonLiterals[jsonLitNull+1 : jsonLitNull+4] ) 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 // jsonManualInlineDecRdInHotZones controls whether we manually inline some decReader calls. // // encode performance is at par with libraries that just iterate over bytes directly, // because encWr (with inlined bytesEncAppender calls) is inlined. // Conversely, decode performance suffers because decRd (with inlined bytesDecReader calls) // isn't inlinable. // // To improve decode performamnce from json: // - readn1 is only called for \u // - consequently, to optimize json decoding, we specifically need inlining // for bytes use-case of some other decReader methods: // - jsonReadAsisChars, skipWhitespace (advance) and jsonReadNum // - AND THEN readn3, readn4 (for ull, rue and alse). // - (readn1 is only called when a char is escaped). // - without inlining, we still pay the cost of a method invocationK, and this dominates time // - To mitigate, we manually inline in hot zones // *excluding places where used sparingly (e.g. nextValueBytes, and other atypical cases)*. // - jsonReadAsisChars *only* called in: appendStringAsBytes // - advance called: everywhere // - jsonReadNum: decNumBytes, DecodeNaked // - From running go test (our anecdotal findings): // - calling jsonReadAsisChars in appendStringAsBytes: 23431 // - calling jsonReadNum in decNumBytes: 15251 // - calling jsonReadNum in DecodeNaked: 612 // Consequently, we manually inline jsonReadAsisChars (in appendStringAsBytes) // and jsonReadNum (in decNumbytes) jsonManualInlineDecRdInHotZones = true jsonSpacesOrTabsLen = 128 // jsonAlwaysReturnInternString = false ) var ( // jsonTabs and jsonSpaces are used as caches for indents jsonTabs, jsonSpaces [jsonSpacesOrTabsLen]byte jsonCharHtmlSafeSet bitset256 jsonCharSafeSet bitset256 ) func init() { var i byte for i = 0; i < jsonSpacesOrTabsLen; i++ { jsonSpaces[i] = ' ' jsonTabs[i] = '\t' } // populate the safe values as true: note: ASCII control characters are (0-31) // jsonCharSafeSet: all true except (0-31) " \ // jsonCharHtmlSafeSet: all true except (0-31) " \ < > & for i = 32; i < utf8.RuneSelf; i++ { switch i { case '"', '\\': case '<', '>', '&': jsonCharSafeSet.set(i) // = true default: jsonCharSafeSet.set(i) jsonCharHtmlSafeSet.set(i) } } } // ---------------- type jsonEncState struct { di int8 // indent per: if negative, use tabs d bool // indenting? dl uint16 // indent level } func (x jsonEncState) captureState() interface{} { return x } func (x *jsonEncState) restoreState(v interface{}) { *x = v.(jsonEncState) } type jsonEncDriver struct { noBuiltInTypes h *JsonHandle // se interfaceExtWrapper // ---- cpu cache line boundary? jsonEncState ks bool // map key as string is byte // integer as string typical bool rawext bool // rawext configured on the handle s *bitset256 // safe set for characters (taking h.HTMLAsIs into consideration) // 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 [56]byte e Encoder } func (e *jsonEncDriver) encoder() *Encoder { return &e.e } func (e *jsonEncDriver) writeIndent() { e.e.encWr.writen1('\n') x := int(e.di) * int(e.dl) if e.di < 0 { x = -x for x > jsonSpacesOrTabsLen { e.e.encWr.writeb(jsonTabs[:]) x -= jsonSpacesOrTabsLen } e.e.encWr.writeb(jsonTabs[:x]) } else { for x > jsonSpacesOrTabsLen { e.e.encWr.writeb(jsonSpaces[:]) x -= jsonSpacesOrTabsLen } e.e.encWr.writeb(jsonSpaces[:x]) } } func (e *jsonEncDriver) WriteArrayElem() { if e.e.c != containerArrayStart { e.e.encWr.writen1(',') } if e.d { e.writeIndent() } } func (e *jsonEncDriver) WriteMapElemKey() { if e.e.c != containerMapStart { e.e.encWr.writen1(',') } if e.d { e.writeIndent() } } func (e *jsonEncDriver) WriteMapElemValue() { if e.d { e.e.encWr.writen2(':', ' ') } else { e.e.encWr.writen1(':') } } func (e *jsonEncDriver) EncodeNil() { // We always encode nil as just null (never in quotes) // This allows us to easily decode if a nil in the json stream // ie if initial token is n. // e.e.encWr.writeb(jsonLiteralNull) e.e.encWr.writen4([4]byte{'n', 'u', 'l', 'l'}) } func (e *jsonEncDriver) 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() } else { e.b[0] = '"' b := fmtTime(t, time.RFC3339Nano, e.b[1:1]) e.b[len(b)+1] = '"' e.e.encWr.writeb(e.b[:len(b)+2]) } } func (e *jsonEncDriver) EncodeExt(rv interface{}, basetype reflect.Type, xtag uint64, ext Ext) { if ext == SelfExt { e.e.encodeValue(baseRV(rv), e.h.fnNoExt(basetype)) } else if v := ext.ConvertExt(rv); v == nil { e.EncodeNil() } else { e.e.encode(v) } } func (e *jsonEncDriver) EncodeRawExt(re *RawExt) { // only encodes re.Value (never re.Data) if re.Value == nil { e.EncodeNil() } else { e.e.encode(re.Value) } } func (e *jsonEncDriver) EncodeBool(b bool) { // Use writen with an array instead of writeb with a slice // i.e. in place of e.e.encWr.writeb(jsonLiteralTrueQ) // OR jsonLiteralTrue, jsonLiteralFalse, jsonLiteralFalseQ, etc if e.ks && e.e.c == containerMapKey { if b { e.e.encWr.writen4([4]byte{'"', 't', 'r', 'u'}) e.e.encWr.writen2('e', '"') } else { e.e.encWr.writen4([4]byte{'"', 'f', 'a', 'l'}) e.e.encWr.writen2('s', 'e') e.e.encWr.writen1('"') } } else { if b { e.e.encWr.writen4([4]byte{'t', 'r', 'u', 'e'}) } else { e.e.encWr.writen4([4]byte{'f', 'a', 'l', 's'}) e.e.encWr.writen1('e') } } } func (e *jsonEncDriver) 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.e.encWr.writeb(e.b[:blen]) } else { e.e.encWr.writeb(strconv.AppendFloat(e.b[:0], f, fmt, int(prec), int(bitsize))) } } func (e *jsonEncDriver) 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) 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) encodeUint(neg bool, quotes bool, u uint64) { // copied mostly from std library: strconv // this should only be called on 64bit OS. const smallsString = "00010203040506070809" + "10111213141516171819" + "20212223242526272829" + "30313233343536373839" + "40414243444546474849" + "50515253545556575859" + "60616263646566676869" + "70717273747576777879" + "80818283848586878889" + "90919293949596979899" // typically, 19 or 20 bytes sufficient for decimal encoding a uint64 // var a [24]byte var a = e.b[0:24] var i = uint8(len(a)) if quotes { i-- a[i] = '"' } // u guaranteed to fit into a uint (as we are not 32bit OS) var is uint var us = uint(u) for us >= 100 { is = us % 100 * 2 us /= 100 i -= 2 a[i+1] = smallsString[is+1] a[i+0] = smallsString[is+0] } // us < 100 is = us * 2 i-- a[i] = smallsString[is+1] if us >= 10 { i-- a[i] = smallsString[is] } if neg { i-- a[i] = '-' } if quotes { i-- a[i] = '"' } e.e.encWr.writeb(a[i:]) } func (e *jsonEncDriver) 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.e.encWr.writeb(e.b[:blen]) } else { e.e.encWr.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) 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.e.encWr.writeb(e.b[:blen]) } else { e.e.encWr.writeb(strconv.AppendUint(e.b[:0], v, 10)) } return } e.encodeUint(false, quotes, v) } func (e *jsonEncDriver) EncodeString(v string) { if e.h.StringToRaw { e.EncodeStringBytesRaw(bytesView(v)) return } e.quoteStr(v) } func (e *jsonEncDriver) EncodeStringBytesRaw(v []byte) { // if encoding raw bytes and RawBytesExt is configured, use it to encode if v == nil { e.EncodeNil() return } if e.rawext { iv := e.h.RawBytesExt.ConvertExt(v) if iv == nil { e.EncodeNil() } else { e.e.encode(iv) } return } slen := base64.StdEncoding.EncodedLen(len(v)) + 2 // bs := e.e.blist.check(*e.buf, n)[:slen] // *e.buf = bs bs := e.e.blist.peek(slen, false)[:slen] bs[0] = '"' base64.StdEncoding.Encode(bs[1:], v) bs[len(bs)-1] = '"' e.e.encWr.writeb(bs) } // 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) WriteArrayStart(length int) { if e.d { e.dl++ } e.e.encWr.writen1('[') } func (e *jsonEncDriver) WriteArrayEnd() { if e.d { e.dl-- e.writeIndent() } e.e.encWr.writen1(']') } func (e *jsonEncDriver) WriteMapStart(length int) { if e.d { e.dl++ } e.e.encWr.writen1('{') } func (e *jsonEncDriver) WriteMapEnd() { if e.d { e.dl-- if e.e.c != containerMapStart { e.writeIndent() } } e.e.encWr.writen1('}') } func (e *jsonEncDriver) quoteStr(s string) { // adapted from std pkg encoding/json const hex = "0123456789abcdef" w := e.e.w() 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 assumining 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) { if e.s.isset(s[i]) { i++ continue } // b := s[i] if s[i] < utf8.RuneSelf { if start < i { w.writestr(s[start:i]) } switch s[i] { case '\\', '"': w.writen2('\\', s[i]) case '\n': w.writen2('\\', 'n') case '\r': w.writen2('\\', 'r') case '\b': w.writen2('\\', 'b') case '\f': w.writen2('\\', 'f') case '\t': w.writen2('\\', 't') default: w.writestr(`\u00`) w.writen2(hex[s[i]>>4], hex[s[i]&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 { w.writestr(s[start:i]) } 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 { w.writestr(s[start:i]) } w.writestr(`\u202`) w.writen1(hex[c&0xF]) i += uint(size) start = i continue } i += uint(size) } if start < uint(len(s)) { w.writestr(s[start:]) } w.writen1('"') } func (e *jsonEncDriver) 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.e.encWr.writen1(c) } } // ---------- type jsonDecState struct { rawext bool // rawext configured on the handle 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 // scratch buffer used for base64 decoding (DecodeBytes in reuseBuf mode), // or reading doubleQuoted string (DecodeStringAsBytes, DecodeNaked) buf *[]byte } func (x jsonDecState) captureState() interface{} { return x } func (x *jsonDecState) restoreState(v interface{}) { *x = v.(jsonDecState) } type jsonDecDriver struct { noBuiltInTypes decDriverNoopNumberHelper h *JsonHandle jsonDecState // se interfaceExtWrapper // ---- cpu cache line boundary? d Decoder } func (d *jsonDecDriver) descBd() (s string) { panic("descBd unsupported") } func (d *jsonDecDriver) decoder() *Decoder { return &d.d } func (d *jsonDecDriver) ReadMapStart() int { d.advance() if d.tok == 'n' { d.readLit4Null(d.d.decRd.readn3()) return containerLenNil } if d.tok != '{' { d.d.errorf("read map - expect char '%c' but got char '%c'", '{', d.tok) } d.tok = 0 return containerLenUnknown } func (d *jsonDecDriver) ReadArrayStart() int { d.advance() if d.tok == 'n' { d.readLit4Null(d.d.decRd.readn3()) return containerLenNil } if d.tok != '[' { d.d.errorf("read array - expect char '%c' but got char '%c'", '[', d.tok) } d.tok = 0 return containerLenUnknown } func (d *jsonDecDriver) CheckBreak() bool { d.advance() return d.tok == '}' || d.tok == ']' } func (d *jsonDecDriver) ReadArrayElem() { const xc uint8 = ',' if d.d.c != containerArrayStart { d.advance() if d.tok != xc { d.readDelimError(xc) } d.tok = 0 } } func (d *jsonDecDriver) ReadArrayEnd() { const xc uint8 = ']' d.advance() if d.tok != xc { d.readDelimError(xc) } d.tok = 0 } func (d *jsonDecDriver) ReadMapElemKey() { const xc uint8 = ',' if d.d.c != containerMapStart { d.advance() if d.tok != xc { d.readDelimError(xc) } d.tok = 0 } } func (d *jsonDecDriver) ReadMapElemValue() { const xc uint8 = ':' d.advance() if d.tok != xc { d.readDelimError(xc) } d.tok = 0 } func (d *jsonDecDriver) ReadMapEnd() { const xc uint8 = '}' d.advance() if d.tok != xc { d.readDelimError(xc) } d.tok = 0 } func (d *jsonDecDriver) readDelimError(xc uint8) { d.d.errorf("read json delimiter - expect char '%c' but got char '%c'", xc, d.tok) } // MARKER: readLit4XXX takes the readn(3|4) 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) readLit4True(bs [4]byte) { // bs := d.d.decRd.readn3() d.tok = 0 if jsonValidateSymbols && bs != [...]byte{0, 'r', 'u', 'e'} { // !Equal jsonLiteral4True // d.d.errorf("expecting %s: got %s", jsonLiteral4True, bs[:]) d.d.errorf("expecting true: got t%s", bs) } } func (d *jsonDecDriver) readLit4False(bs [4]byte) { // bs := d.d.decRd.readn4() d.tok = 0 if jsonValidateSymbols && bs != [4]byte{'a', 'l', 's', 'e'} { // !Equal jsonLiteral4False // d.d.errorf("expecting %s: got %s", jsonLiteral4False, bs) d.d.errorf("expecting false: got f%s", bs) } } func (d *jsonDecDriver) readLit4Null(bs [4]byte) { // bs := d.d.decRd.readn3() // readx(3) d.tok = 0 if jsonValidateSymbols && bs != [...]byte{0, 'u', 'l', 'l'} { // !Equal jsonLiteral4Null // d.d.errorf("expecting %s: got %s", jsonLiteral4Null, bs[:]) d.d.errorf("expecting null: got n%s", bs) } } func (d *jsonDecDriver) advance() { if d.tok == 0 { d.tok = d.d.decRd.skipWhitespace() // skip(&whitespaceCharBitset) } } func (d *jsonDecDriver) nextValueBytes(v []byte) []byte { v, cursor := d.nextValueBytesR(v) decNextValueBytesHelper{d: &d.d}.bytesRdV(&v, cursor) return v } func (d *jsonDecDriver) nextValueBytesR(v0 []byte) (v []byte, cursor uint) { v = v0 var h = decNextValueBytesHelper{d: &d.d} dr := &d.d.decRd consumeString := func() { TOP: bs := dr.jsonReadAsisChars() h.appendN(&v, bs...) if bs[len(bs)-1] != '"' { // last char is '\', so consume next one and try again h.append1(&v, dr.readn1()) goto TOP } } d.advance() // ignore leading whitespace cursor = d.d.rb.c - 1 // cursor starts just before non-whitespace token switch d.tok { default: h.appendN(&v, dr.jsonReadNum()...) case 'n': d.readLit4Null(d.d.decRd.readn3()) h.appendN(&v, jsonLiteralNull...) case 'f': d.readLit4False(d.d.decRd.readn4()) h.appendN(&v, jsonLiteralFalse...) case 't': d.readLit4True(d.d.decRd.readn3()) h.appendN(&v, jsonLiteralTrue...) case '"': h.append1(&v, '"') consumeString() case '{', '[': var elem struct{} var stack []struct{} stack = append(stack, elem) h.append1(&v, d.tok) for len(stack) != 0 { c := dr.readn1() h.append1(&v, c) switch c { case '"': consumeString() case '{', '[': stack = append(stack, elem) case '}', ']': stack = stack[:len(stack)-1] } } } d.tok = 0 return } func (d *jsonDecDriver) TryNil() bool { d.advance() // we shouldn't try to see if quoted "null" was here, right? // only the plain string: `null` denotes a nil (ie not quotes) if d.tok == 'n' { d.readLit4Null(d.d.decRd.readn3()) return true } return false } func (d *jsonDecDriver) DecodeBool() (v bool) { d.advance() if d.tok == 'n' { d.readLit4Null(d.d.decRd.readn3()) return } fquot := d.d.c == containerMapKey && d.tok == '"' if fquot { d.tok = d.d.decRd.readn1() } switch d.tok { case 'f': d.readLit4False(d.d.decRd.readn4()) // v = false case 't': d.readLit4True(d.d.decRd.readn3()) v = true default: d.d.errorf("decode bool: got first char %c", d.tok) // v = false // "unreachable" } if fquot { d.d.decRd.readn1() } return } func (d *jsonDecDriver) DecodeTime() (t time.Time) { // read string, and pass the string into json.unmarshal d.advance() if d.tok == 'n' { d.readLit4Null(d.d.decRd.readn3()) return } d.ensureReadingString() bs := d.readUnescapedString() t, err := time.Parse(time.RFC3339, stringView(bs)) d.d.onerror(err) return } func (d *jsonDecDriver) 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.readLit4Null(d.d.decRd.readn3()) return valueTypeNil } else if d.tok == '"' { return valueTypeString } return valueTypeUnset } func (d *jsonDecDriver) decNumBytes() (bs []byte) { d.advance() dr := &d.d.decRd if d.tok == '"' { bs = dr.readUntil('"') } else if d.tok == 'n' { d.readLit4Null(d.d.decRd.readn3()) } else { if jsonManualInlineDecRdInHotZones { if dr.bytes { bs = dr.rb.jsonReadNum() } else if dr.bufio { bs = dr.bi.jsonReadNum() } else { bs = dr.ri.jsonReadNum() } } else { bs = dr.jsonReadNum() } } d.tok = 0 return } func (d *jsonDecDriver) DecodeUint64() (u uint64) { b := d.decNumBytes() u, neg, ok := parseInteger_bytes(b) if neg { d.d.errorf("negative number cannot be decoded as uint64") } if !ok { d.d.onerror(strconvParseErr(b, "ParseUint")) } return } func (d *jsonDecDriver) DecodeInt64() (v int64) { b := d.decNumBytes() u, neg, ok := parseInteger_bytes(b) if !ok { d.d.onerror(strconvParseErr(b, "ParseInt")) } if chkOvf.Uint2Int(u, neg) { d.d.errorf("overflow decoding number from %s", b) } if neg { v = -int64(u) } else { v = int64(u) } return } func (d *jsonDecDriver) DecodeFloat64() (f float64) { var err error bs := d.decNumBytes() if len(bs) == 0 { return } f, err = parseFloat64(bs) d.d.onerror(err) return } func (d *jsonDecDriver) DecodeFloat32() (f float32) { var err error bs := d.decNumBytes() if len(bs) == 0 { return } f, err = parseFloat32(bs) d.d.onerror(err) return } func (d *jsonDecDriver) DecodeExt(rv interface{}, basetype reflect.Type, xtag uint64, ext Ext) { d.advance() if d.tok == 'n' { d.readLit4Null(d.d.decRd.readn3()) return } if ext == nil { re := rv.(*RawExt) re.Tag = xtag d.d.decode(&re.Value) } else if ext == SelfExt { d.d.decodeValue(baseRV(rv), d.h.fnNoExt(basetype)) } else { d.d.interfaceExtConvertAndDecode(rv, ext) } } func (d *jsonDecDriver) decBytesFromArray(bs []byte) []byte { if bs == nil { bs = []byte{} } else { bs = bs[:0] } d.tok = 0 bs = append(bs, uint8(d.DecodeUint64())) d.tok = d.d.decRd.skipWhitespace() // skip(&whitespaceCharBitset) for d.tok != ']' { if d.tok != ',' { d.d.errorf("read array element - expect char '%c' but got char '%c'", ',', d.tok) } d.tok = 0 bs = append(bs, uint8(chkOvf.UintV(d.DecodeUint64(), 8))) d.tok = d.d.decRd.skipWhitespace() // skip(&whitespaceCharBitset) } d.tok = 0 return bs } func (d *jsonDecDriver) DecodeBytes(bs []byte) (bsOut []byte) { d.d.decByteState = decByteStateNone d.advance() if d.tok == 'n' { d.readLit4Null(d.d.decRd.readn3()) return nil } // if decoding into raw bytes, and the RawBytesExt is configured, use it to decode. if d.rawext { bsOut = bs d.d.interfaceExtConvertAndDecode(&bsOut, d.h.RawBytesExt) return } // check if an "array" of uint8's (see ContainerType for how to infer if an array) if d.tok == '[' { // bsOut, _ = fastpathTV.DecSliceUint8V(bs, true, d.d) if bs == nil { d.d.decByteState = decByteStateReuseBuf bs = d.d.b[:] } return d.decBytesFromArray(bs) } // 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() slen := base64.StdEncoding.DecodedLen(len(bs1)) if slen == 0 { bsOut = []byte{} } else if slen <= cap(bs) { bsOut = bs[:slen] } else if bs == nil { d.d.decByteState = decByteStateReuseBuf bsOut = d.d.blist.check(*d.buf, slen)[:slen] *d.buf = bsOut } else { bsOut = make([]byte, slen) } slen2, err := base64.StdEncoding.Decode(bsOut, bs1) if err != nil { d.d.errorf("error decoding base64 binary '%s': %v", bs1, err) } if slen != slen2 { bsOut = bsOut[:slen2] } return } func (d *jsonDecDriver) DecodeStringAsBytes() (s []byte) { d.d.decByteState = decByteStateNone d.advance() // common case if d.tok == '"' { return d.dblQuoteStringAsBytes() } // handle non-string scalar: null, true, false or a number switch d.tok { case 'n': d.readLit4Null(d.d.decRd.readn3()) return nil // []byte{} case 'f': d.readLit4False(d.d.decRd.readn4()) return jsonLiteralFalse case 't': d.readLit4True(d.d.decRd.readn3()) return jsonLiteralTrue } // try to parse a valid number d.tok = 0 return d.d.decRd.jsonReadNum() } func (d *jsonDecDriver) ensureReadingString() { if d.tok != '"' { d.d.errorf("expecting string starting with '\"'; got '%c'", d.tok) } } func (d *jsonDecDriver) readUnescapedString() (bs []byte) { // d.ensureReadingString() bs = d.d.decRd.readUntil('"') d.tok = 0 return } func (d *jsonDecDriver) dblQuoteStringAsBytes() (buf []byte) { checkUtf8 := d.h.ValidateUnicode d.d.decByteState = decByteStateNone // use a local buf variable, so we don't do pointer chasing within loop buf = (*d.buf)[:0] dr := &d.d.decRd d.tok = 0 var bs []byte var c byte var firstTime bool = true for { if firstTime { firstTime = false if dr.bytes { bs = dr.rb.jsonReadAsisChars() if bs[len(bs)-1] == '"' { d.d.decByteState = decByteStateZerocopy return bs[:len(bs)-1] } goto APPEND } } if jsonManualInlineDecRdInHotZones { if dr.bytes { bs = dr.rb.jsonReadAsisChars() } else if dr.bufio { bs = dr.bi.jsonReadAsisChars() } else { bs = dr.ri.jsonReadAsisChars() } } else { bs = dr.jsonReadAsisChars() } APPEND: buf = append(buf, bs[:len(bs)-1]...) c = bs[len(bs)-1] if c == '"' { break } // c is now '\' c = dr.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.d.errorf("invalid UTF-8 character found after: %s", buf) } buf = append(buf, d.bstr[:utf8.EncodeRune(d.bstr[:], rr)]...) default: *d.buf = buf d.d.errorf("unsupported escaped value: %c", c) } } *d.buf = buf d.d.decByteState = decByteStateReuseBuf return } func (d *jsonDecDriver) appendStringAsBytesSlashU() (r rune) { var rr uint32 var csu [2]byte var cs [4]byte = d.d.decRd.readn4() if rr = jsonSlashURune(cs); rr == unicode.ReplacementChar { return unicode.ReplacementChar } r = rune(rr) if utf16.IsSurrogate(r) { csu = d.d.decRd.readn2() cs = d.d.decRd.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 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 (d *jsonDecDriver) nakedNum(z *fauxUnion, bs []byte) (err error) { // Note: nakedNum is NEVER called with a zero-length []byte if d.h.PreferFloat { z.v = valueTypeFloat z.f, err = parseFloat64(bs) } else { err = parseNumber(bs, z, d.h.SignedInteger) } return } func (d *jsonDecDriver) DecodeNaked() { z := d.d.naked() d.advance() var bs []byte switch d.tok { case 'n': d.readLit4Null(d.d.decRd.readn3()) z.v = valueTypeNil case 'f': d.readLit4False(d.d.decRd.readn4()) z.v = valueTypeBool z.b = false case 't': d.readLit4True(d.d.decRd.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 nil, bool or number first bs = d.dblQuoteStringAsBytes() if len(bs) > 0 && d.d.c == containerMapKey && d.h.MapKeyAsString { if bytes.Equal(bs, jsonLiteralNull) { z.v = valueTypeNil } else if bytes.Equal(bs, jsonLiteralTrue) { z.v = valueTypeBool z.b = true } else if bytes.Equal(bs, jsonLiteralFalse) { z.v = valueTypeBool z.b = false } else { // check if a number: float, int or uint if err := d.nakedNum(z, bs); err != nil { z.v = valueTypeString z.s = d.d.stringZC(bs) } } } else { z.v = valueTypeString z.s = d.d.stringZC(bs) } default: // number bs = d.d.decRd.jsonReadNum() d.tok = 0 if len(bs) == 0 { d.d.errorf("decode number from empty string") } if err := d.nakedNum(z, bs); err != nil { d.d.errorf("decode number from %s: %v", bs, err) } } } //---------------------- // 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 . 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 } 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 string(bd) } func (h *JsonHandle) typical() bool { return h.Indent == 0 && !h.MapKeyAsString && h.IntegerAsString != 'A' && h.IntegerAsString != 'L' } func (h *JsonHandle) newEncDriver() encDriver { var e = &jsonEncDriver{h: h} // var x []byte // e.buf = &x e.e.e = e e.e.js = true e.e.init(h) e.reset() return e } func (h *JsonHandle) newDecDriver() decDriver { var d = &jsonDecDriver{h: h} var x []byte d.buf = &x d.d.d = d d.d.js = true d.d.jsms = h.MapKeyAsString d.d.init(h) d.reset() return d } func (e *jsonEncDriver) resetState() { e.dl = 0 } func (e *jsonEncDriver) reset() { 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 = &jsonCharSafeSet } else { e.s = &jsonCharHtmlSafeSet } e.rawext = e.h.RawBytesExt != nil e.di = int8(e.h.Indent) e.d = e.h.Indent != 0 e.ks = e.h.MapKeyAsString e.is = e.h.IntegerAsString } func (d *jsonDecDriver) resetState() { *d.buf = d.d.blist.check(*d.buf, 256) d.tok = 0 } func (d *jsonDecDriver) reset() { d.resetState() d.rawext = d.h.RawBytesExt != nil } 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 _ decDriverContainerTracker = (*jsonDecDriver)(nil) var _ encDriverContainerTracker = (*jsonEncDriver)(nil) var _ decDriver = (*jsonDecDriver)(nil) var _ encDriver = (*jsonEncDriver)(nil) go-1.2.8/codec/mammoth-test.go.tmpl000066400000000000000000000235161435255326100171420ustar00rootroot00000000000000// 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.notmammoth // +build codec.notmammoth // 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 fast-path // 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}} } {{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}}") testDeepEqualErr(v{{$i}}v1, v{{$i}}v2, 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 testDeepEqualErr(v{{$i}}v1, v{{$i}}v2, 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") testDeepEqualErr(v{{$i}}v1, v{{$i}}v2, 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 testDeepEqualErr(v{{$i}}va[:len(v{{$i}}v2)], v{{$i}}v2, 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") testDeepEqualErr(v{{$i}}v1, v{{$i}}v2, 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") testDeepEqualErr(v{{$i}}v1, v{{$i}}v2, 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") testDeepEqualErr(v{{$i}}v1, v{{$i}}v2, 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") testDeepEqualErr(v{{$i}}v1, v{{$i}}va[:len(v{{$i}}v1)], 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") testDeepEqualErr(v{{$i}}v1, v{{$i}}va[:len(v{{$i}}v1)], 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") testDeepEqualErr(v{{$i}}v3, v{{$i}}v4, 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") testDeepEqualErr(v{{$i}}v3, v{{$i}}v4, 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 { 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}}") testDeepEqualErr(v{{$i}}v1, v{{$i}}v2, t, "equal-map-v{{$i}}") if v == nil { v{{$i}}v2 = nil } else { 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 testDeepEqualErr(v{{$i}}v1, v{{$i}}v2, 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") testDeepEqualErr(v{{$i}}v1, v{{$i}}v2, 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") testDeepEqualErr(v{{$i}}v1, v{{$i}}v2, 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") testDeepEqualErr(v{{$i}}v3, v{{$i}}v4, 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) testDeepEqualErr(&m, &m2, 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) testDeepEqualErr(&mm, &mm2, 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}} go-1.2.8/codec/mammoth2-test.go.tmpl000066400000000000000000000060421435255326100172170ustar00rootroot00000000000000// +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 mammoth2-test.go.tmpl - DO NOT EDIT. package codec // Increase codecoverage by covering all the codecgen paths, in fast-path and gen-helper.go.... // // Note: even though this is built based on fast-path and gen-helper, we will run these tests // in all modes, including notfastpath, etc. // // Add test file for creating a mammoth generated file as _mammoth_generated.go // - generate a second mammoth files in a different file: mammoth2_generated_test.go // mammoth-test.go.tmpl will do this // - run codecgen on it, into mammoth2_codecgen_generated_test.go (no build tags) // - as part of TestMammoth, run it also // - this will cover all the codecgen, gen-helper, etc in one full run // - check in mammoth* files into github also // // 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) // import "encoding/binary" import "fmt" type TestMammoth2 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 }} {{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}} } // ----------- 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 TestMammoth2 T testMammoth2Text B testMammoth2Binary J testMammoth2Json C testMammoth2Basic M map[testMammoth2Basic]TestMammoth2 L []TestMammoth2 A [4]int64 Tcomplex128 complex128 Tcomplex64 complex64 Tbytes []uint8 Tpbytes *[]uint8 } go-1.2.8/codec/mammoth2_codecgen_generated_test.go000066400000000000000000007045311435255326100222030ustar00rootroot00000000000000//go:build go1.6 && ((codecgen && !codec.notfastpath && !codec.notmammoth) || (generated && !codec.notfastpath && !codec.notmammoth)) // +build go1.6 // +build codecgen,!codec.notfastpath,!codec.notmammoth generated,!codec.notfastpath,!codec.notmammoth // Code generated by codecgen - DO NOT EDIT. package codec import ( "errors" "runtime" "sort" "strconv" ) const ( // ----- content types ---- codecSelferCcUTF819781 = 1 codecSelferCcRAW19781 = 255 // ----- value types used ---- codecSelferValueTypeArray19781 = 10 codecSelferValueTypeMap19781 = 9 codecSelferValueTypeString19781 = 6 codecSelferValueTypeInt19781 = 2 codecSelferValueTypeUint19781 = 3 codecSelferValueTypeFloat19781 = 4 codecSelferValueTypeNil19781 = 1 codecSelferBitsize19781 = uint8(32 << (^uint(0) >> 63)) codecSelferDecContainerLenNil19781 = -2147483648 ) var ( errCodecSelferOnlyMapOrArrayEncodeToStruct19781 = errors.New(`only encoded map or array can be decoded into a struct`) _ sort.Interface = nil ) type codecSelfer19781 struct{} func codecSelfer19781False() bool { return false } func codecSelfer19781True() bool { return true } type codecSelfer19781stringSlice []string func (p codecSelfer19781stringSlice) Len() int { return len(p) } func (p codecSelfer19781stringSlice) Swap(i, j int) { p[uint(i)], p[uint(j)] = p[uint(j)], p[uint(i)] } func (p codecSelfer19781stringSlice) Less(i, j int) bool { return p[uint(i)] < p[uint(j)] } type codecSelfer19781uint64Slice []uint64 func (p codecSelfer19781uint64Slice) Len() int { return len(p) } func (p codecSelfer19781uint64Slice) Swap(i, j int) { p[uint(i)], p[uint(j)] = p[uint(j)], p[uint(i)] } func (p codecSelfer19781uint64Slice) Less(i, j int) bool { return p[uint(i)] < p[uint(j)] } type codecSelfer19781int64Slice []int64 func (p codecSelfer19781int64Slice) Len() int { return len(p) } func (p codecSelfer19781int64Slice) Swap(i, j int) { p[uint(i)], p[uint(j)] = p[uint(j)], p[uint(i)] } func (p codecSelfer19781int64Slice) Less(i, j int) bool { return p[uint(i)] < p[uint(j)] } type codecSelfer19781float64Slice []float64 func (p codecSelfer19781float64Slice) Len() int { return len(p) } func (p codecSelfer19781float64Slice) Swap(i, j int) { p[uint(i)], p[uint(j)] = p[uint(j)], p[uint(i)] } func (p codecSelfer19781float64Slice) Less(i, j int) bool { return p[uint(i)] < p[uint(j)] } func init() { if GenVersion != 25 { _, file, _, _ := runtime.Caller(0) ver := strconv.FormatInt(int64(GenVersion), 10) panic(errors.New("codecgen version mismatch: current: 25, need " + ver + ". Re-generate file: " + file)) } } func (TestMammoth2) codecSelferViaCodecgen() {} func (x *TestMammoth2) CodecEncodeSelf(e *Encoder) { var h codecSelfer19781 z, r := GenHelper().Encoder(e) _, _, _ = h, z, r if z.EncBasicHandle().CheckCircularRef { z.EncEncode(x) return } if x == nil { r.EncodeNil() } else { yy2arr2 := z.EncBasicHandle().StructToArray _ = yy2arr2 const yyr2 bool = false // struct tag has 'toArray' var yyn4 bool = x.FptrIntf == nil var yyn6 bool = x.FptrString == nil var yyn8 bool = x.FptrBytes == nil var yyn10 bool = x.FptrFloat32 == nil var yyn12 bool = x.FptrFloat64 == nil var yyn14 bool = x.FptrUint == nil var yyn16 bool = x.FptrUint8 == nil var yyn18 bool = x.FptrUint16 == nil var yyn20 bool = x.FptrUint32 == nil var yyn22 bool = x.FptrUint64 == nil var yyn24 bool = x.FptrUintptr == nil var yyn26 bool = x.FptrInt == nil var yyn28 bool = x.FptrInt8 == nil var yyn30 bool = x.FptrInt16 == nil var yyn32 bool = x.FptrInt32 == nil var yyn34 bool = x.FptrInt64 == nil var yyn36 bool = x.FptrBool == nil var yyn38 bool = x.FptrSliceIntf == nil var yyn40 bool = x.FptrSliceString == nil var yyn42 bool = x.FptrSliceBytes == nil var yyn44 bool = x.FptrSliceFloat32 == nil var yyn46 bool = x.FptrSliceFloat64 == nil var yyn48 bool = x.FptrSliceUint8 == nil var yyn50 bool = x.FptrSliceUint64 == nil var yyn52 bool = x.FptrSliceInt == nil var yyn54 bool = x.FptrSliceInt32 == nil var yyn56 bool = x.FptrSliceInt64 == nil var yyn58 bool = x.FptrSliceBool == nil var yyn60 bool = x.FptrMapStringIntf == nil var yyn62 bool = x.FptrMapStringString == nil var yyn64 bool = x.FptrMapStringBytes == nil var yyn66 bool = x.FptrMapStringUint8 == nil var yyn68 bool = x.FptrMapStringUint64 == nil var yyn70 bool = x.FptrMapStringInt == nil var yyn72 bool = x.FptrMapStringInt32 == nil var yyn74 bool = x.FptrMapStringFloat64 == nil var yyn76 bool = x.FptrMapStringBool == nil var yyn78 bool = x.FptrMapUint8Intf == nil var yyn80 bool = x.FptrMapUint8String == nil var yyn82 bool = x.FptrMapUint8Bytes == nil var yyn84 bool = x.FptrMapUint8Uint8 == nil var yyn86 bool = x.FptrMapUint8Uint64 == nil var yyn88 bool = x.FptrMapUint8Int == nil var yyn90 bool = x.FptrMapUint8Int32 == nil var yyn92 bool = x.FptrMapUint8Float64 == nil var yyn94 bool = x.FptrMapUint8Bool == nil var yyn96 bool = x.FptrMapUint64Intf == nil var yyn98 bool = x.FptrMapUint64String == nil var yyn100 bool = x.FptrMapUint64Bytes == nil var yyn102 bool = x.FptrMapUint64Uint8 == nil var yyn104 bool = x.FptrMapUint64Uint64 == nil var yyn106 bool = x.FptrMapUint64Int == nil var yyn108 bool = x.FptrMapUint64Int32 == nil var yyn110 bool = x.FptrMapUint64Float64 == nil var yyn112 bool = x.FptrMapUint64Bool == nil var yyn114 bool = x.FptrMapIntIntf == nil var yyn116 bool = x.FptrMapIntString == nil var yyn118 bool = x.FptrMapIntBytes == nil var yyn120 bool = x.FptrMapIntUint8 == nil var yyn122 bool = x.FptrMapIntUint64 == nil var yyn124 bool = x.FptrMapIntInt == nil var yyn126 bool = x.FptrMapIntInt32 == nil var yyn128 bool = x.FptrMapIntFloat64 == nil var yyn130 bool = x.FptrMapIntBool == nil var yyn132 bool = x.FptrMapInt32Intf == nil var yyn134 bool = x.FptrMapInt32String == nil var yyn136 bool = x.FptrMapInt32Bytes == nil var yyn138 bool = x.FptrMapInt32Uint8 == nil var yyn140 bool = x.FptrMapInt32Uint64 == nil var yyn142 bool = x.FptrMapInt32Int == nil var yyn144 bool = x.FptrMapInt32Int32 == nil var yyn146 bool = x.FptrMapInt32Float64 == nil var yyn148 bool = x.FptrMapInt32Bool == nil if yyr2 || yy2arr2 { z.EncWriteArrayStart(146) z.EncWriteArrayElem() z.EncFallback(x.FIntf) if yyn4 { z.EncWriteArrayElem() r.EncodeNil() } else { z.EncWriteArrayElem() yy150 := *x.FptrIntf z.EncFallback(yy150) } z.EncWriteArrayElem() r.EncodeString(string(x.FString)) if yyn6 { z.EncWriteArrayElem() r.EncodeNil() } else { z.EncWriteArrayElem() yy153 := *x.FptrString r.EncodeString(string(yy153)) } z.EncWriteArrayElem() if x.FBytes == nil { r.EncodeNil() } else { r.EncodeStringBytesRaw([]byte(x.FBytes)) } // end block: if x.FBytes slice == nil if yyn8 { z.EncWriteArrayElem() r.EncodeNil() } else { z.EncWriteArrayElem() yy156 := *x.FptrBytes if yy156 == nil { r.EncodeNil() } else { r.EncodeStringBytesRaw([]byte(yy156)) } // end block: if yy156 slice == nil } z.EncWriteArrayElem() r.EncodeFloat32(float32(x.FFloat32)) if yyn10 { z.EncWriteArrayElem() r.EncodeNil() } else { z.EncWriteArrayElem() yy159 := *x.FptrFloat32 r.EncodeFloat32(float32(yy159)) } z.EncWriteArrayElem() r.EncodeFloat64(float64(x.FFloat64)) if yyn12 { z.EncWriteArrayElem() r.EncodeNil() } else { z.EncWriteArrayElem() yy162 := *x.FptrFloat64 r.EncodeFloat64(float64(yy162)) } z.EncWriteArrayElem() r.EncodeUint(uint64(x.FUint)) if yyn14 { z.EncWriteArrayElem() r.EncodeNil() } else { z.EncWriteArrayElem() yy165 := *x.FptrUint r.EncodeUint(uint64(yy165)) } z.EncWriteArrayElem() r.EncodeUint(uint64(x.FUint8)) if yyn16 { z.EncWriteArrayElem() r.EncodeNil() } else { z.EncWriteArrayElem() yy168 := *x.FptrUint8 r.EncodeUint(uint64(yy168)) } z.EncWriteArrayElem() r.EncodeUint(uint64(x.FUint16)) if yyn18 { z.EncWriteArrayElem() r.EncodeNil() } else { z.EncWriteArrayElem() yy171 := *x.FptrUint16 r.EncodeUint(uint64(yy171)) } z.EncWriteArrayElem() r.EncodeUint(uint64(x.FUint32)) if yyn20 { z.EncWriteArrayElem() r.EncodeNil() } else { z.EncWriteArrayElem() yy174 := *x.FptrUint32 r.EncodeUint(uint64(yy174)) } z.EncWriteArrayElem() r.EncodeUint(uint64(x.FUint64)) if yyn22 { z.EncWriteArrayElem() r.EncodeNil() } else { z.EncWriteArrayElem() yy177 := *x.FptrUint64 r.EncodeUint(uint64(yy177)) } z.EncWriteArrayElem() r.EncodeUint(uint64(x.FUintptr)) if yyn24 { z.EncWriteArrayElem() r.EncodeNil() } else { z.EncWriteArrayElem() yy180 := *x.FptrUintptr r.EncodeUint(uint64(yy180)) } z.EncWriteArrayElem() r.EncodeInt(int64(x.FInt)) if yyn26 { z.EncWriteArrayElem() r.EncodeNil() } else { z.EncWriteArrayElem() yy183 := *x.FptrInt r.EncodeInt(int64(yy183)) } z.EncWriteArrayElem() r.EncodeInt(int64(x.FInt8)) if yyn28 { z.EncWriteArrayElem() r.EncodeNil() } else { z.EncWriteArrayElem() yy186 := *x.FptrInt8 r.EncodeInt(int64(yy186)) } z.EncWriteArrayElem() r.EncodeInt(int64(x.FInt16)) if yyn30 { z.EncWriteArrayElem() r.EncodeNil() } else { z.EncWriteArrayElem() yy189 := *x.FptrInt16 r.EncodeInt(int64(yy189)) } z.EncWriteArrayElem() r.EncodeInt(int64(x.FInt32)) if yyn32 { z.EncWriteArrayElem() r.EncodeNil() } else { z.EncWriteArrayElem() yy192 := *x.FptrInt32 r.EncodeInt(int64(yy192)) } z.EncWriteArrayElem() r.EncodeInt(int64(x.FInt64)) if yyn34 { z.EncWriteArrayElem() r.EncodeNil() } else { z.EncWriteArrayElem() yy195 := *x.FptrInt64 r.EncodeInt(int64(yy195)) } z.EncWriteArrayElem() r.EncodeBool(bool(x.FBool)) if yyn36 { z.EncWriteArrayElem() r.EncodeNil() } else { z.EncWriteArrayElem() yy198 := *x.FptrBool r.EncodeBool(bool(yy198)) } z.EncWriteArrayElem() if x.FSliceIntf == nil { r.EncodeNil() } else { z.F.EncSliceIntfV(x.FSliceIntf, e) } // end block: if x.FSliceIntf slice == nil if yyn38 { z.EncWriteArrayElem() r.EncodeNil() } else { z.EncWriteArrayElem() yy201 := *x.FptrSliceIntf if yy201 == nil { r.EncodeNil() } else { z.F.EncSliceIntfV(yy201, e) } // end block: if yy201 slice == nil } z.EncWriteArrayElem() if x.FSliceString == nil { r.EncodeNil() } else { z.F.EncSliceStringV(x.FSliceString, e) } // end block: if x.FSliceString slice == nil if yyn40 { z.EncWriteArrayElem() r.EncodeNil() } else { z.EncWriteArrayElem() yy204 := *x.FptrSliceString if yy204 == nil { r.EncodeNil() } else { z.F.EncSliceStringV(yy204, e) } // end block: if yy204 slice == nil } z.EncWriteArrayElem() if x.FSliceBytes == nil { r.EncodeNil() } else { z.F.EncSliceBytesV(x.FSliceBytes, e) } // end block: if x.FSliceBytes slice == nil if yyn42 { z.EncWriteArrayElem() r.EncodeNil() } else { z.EncWriteArrayElem() yy207 := *x.FptrSliceBytes if yy207 == nil { r.EncodeNil() } else { z.F.EncSliceBytesV(yy207, e) } // end block: if yy207 slice == nil } z.EncWriteArrayElem() if x.FSliceFloat32 == nil { r.EncodeNil() } else { z.F.EncSliceFloat32V(x.FSliceFloat32, e) } // end block: if x.FSliceFloat32 slice == nil if yyn44 { z.EncWriteArrayElem() r.EncodeNil() } else { z.EncWriteArrayElem() yy210 := *x.FptrSliceFloat32 if yy210 == nil { r.EncodeNil() } else { z.F.EncSliceFloat32V(yy210, e) } // end block: if yy210 slice == nil } z.EncWriteArrayElem() if x.FSliceFloat64 == nil { r.EncodeNil() } else { z.F.EncSliceFloat64V(x.FSliceFloat64, e) } // end block: if x.FSliceFloat64 slice == nil if yyn46 { z.EncWriteArrayElem() r.EncodeNil() } else { z.EncWriteArrayElem() yy213 := *x.FptrSliceFloat64 if yy213 == nil { r.EncodeNil() } else { z.F.EncSliceFloat64V(yy213, e) } // end block: if yy213 slice == nil } z.EncWriteArrayElem() if x.FSliceUint8 == nil { r.EncodeNil() } else { r.EncodeStringBytesRaw([]byte(x.FSliceUint8)) } // end block: if x.FSliceUint8 slice == nil if yyn48 { z.EncWriteArrayElem() r.EncodeNil() } else { z.EncWriteArrayElem() yy216 := *x.FptrSliceUint8 if yy216 == nil { r.EncodeNil() } else { r.EncodeStringBytesRaw([]byte(yy216)) } // end block: if yy216 slice == nil } z.EncWriteArrayElem() if x.FSliceUint64 == nil { r.EncodeNil() } else { z.F.EncSliceUint64V(x.FSliceUint64, e) } // end block: if x.FSliceUint64 slice == nil if yyn50 { z.EncWriteArrayElem() r.EncodeNil() } else { z.EncWriteArrayElem() yy219 := *x.FptrSliceUint64 if yy219 == nil { r.EncodeNil() } else { z.F.EncSliceUint64V(yy219, e) } // end block: if yy219 slice == nil } z.EncWriteArrayElem() if x.FSliceInt == nil { r.EncodeNil() } else { z.F.EncSliceIntV(x.FSliceInt, e) } // end block: if x.FSliceInt slice == nil if yyn52 { z.EncWriteArrayElem() r.EncodeNil() } else { z.EncWriteArrayElem() yy222 := *x.FptrSliceInt if yy222 == nil { r.EncodeNil() } else { z.F.EncSliceIntV(yy222, e) } // end block: if yy222 slice == nil } z.EncWriteArrayElem() if x.FSliceInt32 == nil { r.EncodeNil() } else { z.F.EncSliceInt32V(x.FSliceInt32, e) } // end block: if x.FSliceInt32 slice == nil if yyn54 { z.EncWriteArrayElem() r.EncodeNil() } else { z.EncWriteArrayElem() yy225 := *x.FptrSliceInt32 if yy225 == nil { r.EncodeNil() } else { z.F.EncSliceInt32V(yy225, e) } // end block: if yy225 slice == nil } z.EncWriteArrayElem() if x.FSliceInt64 == nil { r.EncodeNil() } else { z.F.EncSliceInt64V(x.FSliceInt64, e) } // end block: if x.FSliceInt64 slice == nil if yyn56 { z.EncWriteArrayElem() r.EncodeNil() } else { z.EncWriteArrayElem() yy228 := *x.FptrSliceInt64 if yy228 == nil { r.EncodeNil() } else { z.F.EncSliceInt64V(yy228, e) } // end block: if yy228 slice == nil } z.EncWriteArrayElem() if x.FSliceBool == nil { r.EncodeNil() } else { z.F.EncSliceBoolV(x.FSliceBool, e) } // end block: if x.FSliceBool slice == nil if yyn58 { z.EncWriteArrayElem() r.EncodeNil() } else { z.EncWriteArrayElem() yy231 := *x.FptrSliceBool if yy231 == nil { r.EncodeNil() } else { z.F.EncSliceBoolV(yy231, e) } // end block: if yy231 slice == nil } z.EncWriteArrayElem() if x.FMapStringIntf == nil { r.EncodeNil() } else { z.F.EncMapStringIntfV(x.FMapStringIntf, e) } // end block: if x.FMapStringIntf map == nil if yyn60 { z.EncWriteArrayElem() r.EncodeNil() } else { z.EncWriteArrayElem() yy234 := *x.FptrMapStringIntf if yy234 == nil { r.EncodeNil() } else { z.F.EncMapStringIntfV(yy234, e) } // end block: if yy234 map == nil } z.EncWriteArrayElem() if x.FMapStringString == nil { r.EncodeNil() } else { z.F.EncMapStringStringV(x.FMapStringString, e) } // end block: if x.FMapStringString map == nil if yyn62 { z.EncWriteArrayElem() r.EncodeNil() } else { z.EncWriteArrayElem() yy237 := *x.FptrMapStringString if yy237 == nil { r.EncodeNil() } else { z.F.EncMapStringStringV(yy237, e) } // end block: if yy237 map == nil } z.EncWriteArrayElem() if x.FMapStringBytes == nil { r.EncodeNil() } else { z.F.EncMapStringBytesV(x.FMapStringBytes, e) } // end block: if x.FMapStringBytes map == nil if yyn64 { z.EncWriteArrayElem() r.EncodeNil() } else { z.EncWriteArrayElem() yy240 := *x.FptrMapStringBytes if yy240 == nil { r.EncodeNil() } else { z.F.EncMapStringBytesV(yy240, e) } // end block: if yy240 map == nil } z.EncWriteArrayElem() if x.FMapStringUint8 == nil { r.EncodeNil() } else { z.F.EncMapStringUint8V(x.FMapStringUint8, e) } // end block: if x.FMapStringUint8 map == nil if yyn66 { z.EncWriteArrayElem() r.EncodeNil() } else { z.EncWriteArrayElem() yy243 := *x.FptrMapStringUint8 if yy243 == nil { r.EncodeNil() } else { z.F.EncMapStringUint8V(yy243, e) } // end block: if yy243 map == nil } z.EncWriteArrayElem() if x.FMapStringUint64 == nil { r.EncodeNil() } else { z.F.EncMapStringUint64V(x.FMapStringUint64, e) } // end block: if x.FMapStringUint64 map == nil if yyn68 { z.EncWriteArrayElem() r.EncodeNil() } else { z.EncWriteArrayElem() yy246 := *x.FptrMapStringUint64 if yy246 == nil { r.EncodeNil() } else { z.F.EncMapStringUint64V(yy246, e) } // end block: if yy246 map == nil } z.EncWriteArrayElem() if x.FMapStringInt == nil { r.EncodeNil() } else { z.F.EncMapStringIntV(x.FMapStringInt, e) } // end block: if x.FMapStringInt map == nil if yyn70 { z.EncWriteArrayElem() r.EncodeNil() } else { z.EncWriteArrayElem() yy249 := *x.FptrMapStringInt if yy249 == nil { r.EncodeNil() } else { z.F.EncMapStringIntV(yy249, e) } // end block: if yy249 map == nil } z.EncWriteArrayElem() if x.FMapStringInt32 == nil { r.EncodeNil() } else { z.F.EncMapStringInt32V(x.FMapStringInt32, e) } // end block: if x.FMapStringInt32 map == nil if yyn72 { z.EncWriteArrayElem() r.EncodeNil() } else { z.EncWriteArrayElem() yy252 := *x.FptrMapStringInt32 if yy252 == nil { r.EncodeNil() } else { z.F.EncMapStringInt32V(yy252, e) } // end block: if yy252 map == nil } z.EncWriteArrayElem() if x.FMapStringFloat64 == nil { r.EncodeNil() } else { z.F.EncMapStringFloat64V(x.FMapStringFloat64, e) } // end block: if x.FMapStringFloat64 map == nil if yyn74 { z.EncWriteArrayElem() r.EncodeNil() } else { z.EncWriteArrayElem() yy255 := *x.FptrMapStringFloat64 if yy255 == nil { r.EncodeNil() } else { z.F.EncMapStringFloat64V(yy255, e) } // end block: if yy255 map == nil } z.EncWriteArrayElem() if x.FMapStringBool == nil { r.EncodeNil() } else { z.F.EncMapStringBoolV(x.FMapStringBool, e) } // end block: if x.FMapStringBool map == nil if yyn76 { z.EncWriteArrayElem() r.EncodeNil() } else { z.EncWriteArrayElem() yy258 := *x.FptrMapStringBool if yy258 == nil { r.EncodeNil() } else { z.F.EncMapStringBoolV(yy258, e) } // end block: if yy258 map == nil } z.EncWriteArrayElem() if x.FMapUint8Intf == nil { r.EncodeNil() } else { z.F.EncMapUint8IntfV(x.FMapUint8Intf, e) } // end block: if x.FMapUint8Intf map == nil if yyn78 { z.EncWriteArrayElem() r.EncodeNil() } else { z.EncWriteArrayElem() yy261 := *x.FptrMapUint8Intf if yy261 == nil { r.EncodeNil() } else { z.F.EncMapUint8IntfV(yy261, e) } // end block: if yy261 map == nil } z.EncWriteArrayElem() if x.FMapUint8String == nil { r.EncodeNil() } else { z.F.EncMapUint8StringV(x.FMapUint8String, e) } // end block: if x.FMapUint8String map == nil if yyn80 { z.EncWriteArrayElem() r.EncodeNil() } else { z.EncWriteArrayElem() yy264 := *x.FptrMapUint8String if yy264 == nil { r.EncodeNil() } else { z.F.EncMapUint8StringV(yy264, e) } // end block: if yy264 map == nil } z.EncWriteArrayElem() if x.FMapUint8Bytes == nil { r.EncodeNil() } else { z.F.EncMapUint8BytesV(x.FMapUint8Bytes, e) } // end block: if x.FMapUint8Bytes map == nil if yyn82 { z.EncWriteArrayElem() r.EncodeNil() } else { z.EncWriteArrayElem() yy267 := *x.FptrMapUint8Bytes if yy267 == nil { r.EncodeNil() } else { z.F.EncMapUint8BytesV(yy267, e) } // end block: if yy267 map == nil } z.EncWriteArrayElem() if x.FMapUint8Uint8 == nil { r.EncodeNil() } else { z.F.EncMapUint8Uint8V(x.FMapUint8Uint8, e) } // end block: if x.FMapUint8Uint8 map == nil if yyn84 { z.EncWriteArrayElem() r.EncodeNil() } else { z.EncWriteArrayElem() yy270 := *x.FptrMapUint8Uint8 if yy270 == nil { r.EncodeNil() } else { z.F.EncMapUint8Uint8V(yy270, e) } // end block: if yy270 map == nil } z.EncWriteArrayElem() if x.FMapUint8Uint64 == nil { r.EncodeNil() } else { z.F.EncMapUint8Uint64V(x.FMapUint8Uint64, e) } // end block: if x.FMapUint8Uint64 map == nil if yyn86 { z.EncWriteArrayElem() r.EncodeNil() } else { z.EncWriteArrayElem() yy273 := *x.FptrMapUint8Uint64 if yy273 == nil { r.EncodeNil() } else { z.F.EncMapUint8Uint64V(yy273, e) } // end block: if yy273 map == nil } z.EncWriteArrayElem() if x.FMapUint8Int == nil { r.EncodeNil() } else { z.F.EncMapUint8IntV(x.FMapUint8Int, e) } // end block: if x.FMapUint8Int map == nil if yyn88 { z.EncWriteArrayElem() r.EncodeNil() } else { z.EncWriteArrayElem() yy276 := *x.FptrMapUint8Int if yy276 == nil { r.EncodeNil() } else { z.F.EncMapUint8IntV(yy276, e) } // end block: if yy276 map == nil } z.EncWriteArrayElem() if x.FMapUint8Int32 == nil { r.EncodeNil() } else { z.F.EncMapUint8Int32V(x.FMapUint8Int32, e) } // end block: if x.FMapUint8Int32 map == nil if yyn90 { z.EncWriteArrayElem() r.EncodeNil() } else { z.EncWriteArrayElem() yy279 := *x.FptrMapUint8Int32 if yy279 == nil { r.EncodeNil() } else { z.F.EncMapUint8Int32V(yy279, e) } // end block: if yy279 map == nil } z.EncWriteArrayElem() if x.FMapUint8Float64 == nil { r.EncodeNil() } else { z.F.EncMapUint8Float64V(x.FMapUint8Float64, e) } // end block: if x.FMapUint8Float64 map == nil if yyn92 { z.EncWriteArrayElem() r.EncodeNil() } else { z.EncWriteArrayElem() yy282 := *x.FptrMapUint8Float64 if yy282 == nil { r.EncodeNil() } else { z.F.EncMapUint8Float64V(yy282, e) } // end block: if yy282 map == nil } z.EncWriteArrayElem() if x.FMapUint8Bool == nil { r.EncodeNil() } else { z.F.EncMapUint8BoolV(x.FMapUint8Bool, e) } // end block: if x.FMapUint8Bool map == nil if yyn94 { z.EncWriteArrayElem() r.EncodeNil() } else { z.EncWriteArrayElem() yy285 := *x.FptrMapUint8Bool if yy285 == nil { r.EncodeNil() } else { z.F.EncMapUint8BoolV(yy285, e) } // end block: if yy285 map == nil } z.EncWriteArrayElem() if x.FMapUint64Intf == nil { r.EncodeNil() } else { z.F.EncMapUint64IntfV(x.FMapUint64Intf, e) } // end block: if x.FMapUint64Intf map == nil if yyn96 { z.EncWriteArrayElem() r.EncodeNil() } else { z.EncWriteArrayElem() yy288 := *x.FptrMapUint64Intf if yy288 == nil { r.EncodeNil() } else { z.F.EncMapUint64IntfV(yy288, e) } // end block: if yy288 map == nil } z.EncWriteArrayElem() if x.FMapUint64String == nil { r.EncodeNil() } else { z.F.EncMapUint64StringV(x.FMapUint64String, e) } // end block: if x.FMapUint64String map == nil if yyn98 { z.EncWriteArrayElem() r.EncodeNil() } else { z.EncWriteArrayElem() yy291 := *x.FptrMapUint64String if yy291 == nil { r.EncodeNil() } else { z.F.EncMapUint64StringV(yy291, e) } // end block: if yy291 map == nil } z.EncWriteArrayElem() if x.FMapUint64Bytes == nil { r.EncodeNil() } else { z.F.EncMapUint64BytesV(x.FMapUint64Bytes, e) } // end block: if x.FMapUint64Bytes map == nil if yyn100 { z.EncWriteArrayElem() r.EncodeNil() } else { z.EncWriteArrayElem() yy294 := *x.FptrMapUint64Bytes if yy294 == nil { r.EncodeNil() } else { z.F.EncMapUint64BytesV(yy294, e) } // end block: if yy294 map == nil } z.EncWriteArrayElem() if x.FMapUint64Uint8 == nil { r.EncodeNil() } else { z.F.EncMapUint64Uint8V(x.FMapUint64Uint8, e) } // end block: if x.FMapUint64Uint8 map == nil if yyn102 { z.EncWriteArrayElem() r.EncodeNil() } else { z.EncWriteArrayElem() yy297 := *x.FptrMapUint64Uint8 if yy297 == nil { r.EncodeNil() } else { z.F.EncMapUint64Uint8V(yy297, e) } // end block: if yy297 map == nil } z.EncWriteArrayElem() if x.FMapUint64Uint64 == nil { r.EncodeNil() } else { z.F.EncMapUint64Uint64V(x.FMapUint64Uint64, e) } // end block: if x.FMapUint64Uint64 map == nil if yyn104 { z.EncWriteArrayElem() r.EncodeNil() } else { z.EncWriteArrayElem() yy300 := *x.FptrMapUint64Uint64 if yy300 == nil { r.EncodeNil() } else { z.F.EncMapUint64Uint64V(yy300, e) } // end block: if yy300 map == nil } z.EncWriteArrayElem() if x.FMapUint64Int == nil { r.EncodeNil() } else { z.F.EncMapUint64IntV(x.FMapUint64Int, e) } // end block: if x.FMapUint64Int map == nil if yyn106 { z.EncWriteArrayElem() r.EncodeNil() } else { z.EncWriteArrayElem() yy303 := *x.FptrMapUint64Int if yy303 == nil { r.EncodeNil() } else { z.F.EncMapUint64IntV(yy303, e) } // end block: if yy303 map == nil } z.EncWriteArrayElem() if x.FMapUint64Int32 == nil { r.EncodeNil() } else { z.F.EncMapUint64Int32V(x.FMapUint64Int32, e) } // end block: if x.FMapUint64Int32 map == nil if yyn108 { z.EncWriteArrayElem() r.EncodeNil() } else { z.EncWriteArrayElem() yy306 := *x.FptrMapUint64Int32 if yy306 == nil { r.EncodeNil() } else { z.F.EncMapUint64Int32V(yy306, e) } // end block: if yy306 map == nil } z.EncWriteArrayElem() if x.FMapUint64Float64 == nil { r.EncodeNil() } else { z.F.EncMapUint64Float64V(x.FMapUint64Float64, e) } // end block: if x.FMapUint64Float64 map == nil if yyn110 { z.EncWriteArrayElem() r.EncodeNil() } else { z.EncWriteArrayElem() yy309 := *x.FptrMapUint64Float64 if yy309 == nil { r.EncodeNil() } else { z.F.EncMapUint64Float64V(yy309, e) } // end block: if yy309 map == nil } z.EncWriteArrayElem() if x.FMapUint64Bool == nil { r.EncodeNil() } else { z.F.EncMapUint64BoolV(x.FMapUint64Bool, e) } // end block: if x.FMapUint64Bool map == nil if yyn112 { z.EncWriteArrayElem() r.EncodeNil() } else { z.EncWriteArrayElem() yy312 := *x.FptrMapUint64Bool if yy312 == nil { r.EncodeNil() } else { z.F.EncMapUint64BoolV(yy312, e) } // end block: if yy312 map == nil } z.EncWriteArrayElem() if x.FMapIntIntf == nil { r.EncodeNil() } else { z.F.EncMapIntIntfV(x.FMapIntIntf, e) } // end block: if x.FMapIntIntf map == nil if yyn114 { z.EncWriteArrayElem() r.EncodeNil() } else { z.EncWriteArrayElem() yy315 := *x.FptrMapIntIntf if yy315 == nil { r.EncodeNil() } else { z.F.EncMapIntIntfV(yy315, e) } // end block: if yy315 map == nil } z.EncWriteArrayElem() if x.FMapIntString == nil { r.EncodeNil() } else { z.F.EncMapIntStringV(x.FMapIntString, e) } // end block: if x.FMapIntString map == nil if yyn116 { z.EncWriteArrayElem() r.EncodeNil() } else { z.EncWriteArrayElem() yy318 := *x.FptrMapIntString if yy318 == nil { r.EncodeNil() } else { z.F.EncMapIntStringV(yy318, e) } // end block: if yy318 map == nil } z.EncWriteArrayElem() if x.FMapIntBytes == nil { r.EncodeNil() } else { z.F.EncMapIntBytesV(x.FMapIntBytes, e) } // end block: if x.FMapIntBytes map == nil if yyn118 { z.EncWriteArrayElem() r.EncodeNil() } else { z.EncWriteArrayElem() yy321 := *x.FptrMapIntBytes if yy321 == nil { r.EncodeNil() } else { z.F.EncMapIntBytesV(yy321, e) } // end block: if yy321 map == nil } z.EncWriteArrayElem() if x.FMapIntUint8 == nil { r.EncodeNil() } else { z.F.EncMapIntUint8V(x.FMapIntUint8, e) } // end block: if x.FMapIntUint8 map == nil if yyn120 { z.EncWriteArrayElem() r.EncodeNil() } else { z.EncWriteArrayElem() yy324 := *x.FptrMapIntUint8 if yy324 == nil { r.EncodeNil() } else { z.F.EncMapIntUint8V(yy324, e) } // end block: if yy324 map == nil } z.EncWriteArrayElem() if x.FMapIntUint64 == nil { r.EncodeNil() } else { z.F.EncMapIntUint64V(x.FMapIntUint64, e) } // end block: if x.FMapIntUint64 map == nil if yyn122 { z.EncWriteArrayElem() r.EncodeNil() } else { z.EncWriteArrayElem() yy327 := *x.FptrMapIntUint64 if yy327 == nil { r.EncodeNil() } else { z.F.EncMapIntUint64V(yy327, e) } // end block: if yy327 map == nil } z.EncWriteArrayElem() if x.FMapIntInt == nil { r.EncodeNil() } else { z.F.EncMapIntIntV(x.FMapIntInt, e) } // end block: if x.FMapIntInt map == nil if yyn124 { z.EncWriteArrayElem() r.EncodeNil() } else { z.EncWriteArrayElem() yy330 := *x.FptrMapIntInt if yy330 == nil { r.EncodeNil() } else { z.F.EncMapIntIntV(yy330, e) } // end block: if yy330 map == nil } z.EncWriteArrayElem() if x.FMapIntInt32 == nil { r.EncodeNil() } else { z.F.EncMapIntInt32V(x.FMapIntInt32, e) } // end block: if x.FMapIntInt32 map == nil if yyn126 { z.EncWriteArrayElem() r.EncodeNil() } else { z.EncWriteArrayElem() yy333 := *x.FptrMapIntInt32 if yy333 == nil { r.EncodeNil() } else { z.F.EncMapIntInt32V(yy333, e) } // end block: if yy333 map == nil } z.EncWriteArrayElem() if x.FMapIntFloat64 == nil { r.EncodeNil() } else { z.F.EncMapIntFloat64V(x.FMapIntFloat64, e) } // end block: if x.FMapIntFloat64 map == nil if yyn128 { z.EncWriteArrayElem() r.EncodeNil() } else { z.EncWriteArrayElem() yy336 := *x.FptrMapIntFloat64 if yy336 == nil { r.EncodeNil() } else { z.F.EncMapIntFloat64V(yy336, e) } // end block: if yy336 map == nil } z.EncWriteArrayElem() if x.FMapIntBool == nil { r.EncodeNil() } else { z.F.EncMapIntBoolV(x.FMapIntBool, e) } // end block: if x.FMapIntBool map == nil if yyn130 { z.EncWriteArrayElem() r.EncodeNil() } else { z.EncWriteArrayElem() yy339 := *x.FptrMapIntBool if yy339 == nil { r.EncodeNil() } else { z.F.EncMapIntBoolV(yy339, e) } // end block: if yy339 map == nil } z.EncWriteArrayElem() if x.FMapInt32Intf == nil { r.EncodeNil() } else { z.F.EncMapInt32IntfV(x.FMapInt32Intf, e) } // end block: if x.FMapInt32Intf map == nil if yyn132 { z.EncWriteArrayElem() r.EncodeNil() } else { z.EncWriteArrayElem() yy342 := *x.FptrMapInt32Intf if yy342 == nil { r.EncodeNil() } else { z.F.EncMapInt32IntfV(yy342, e) } // end block: if yy342 map == nil } z.EncWriteArrayElem() if x.FMapInt32String == nil { r.EncodeNil() } else { z.F.EncMapInt32StringV(x.FMapInt32String, e) } // end block: if x.FMapInt32String map == nil if yyn134 { z.EncWriteArrayElem() r.EncodeNil() } else { z.EncWriteArrayElem() yy345 := *x.FptrMapInt32String if yy345 == nil { r.EncodeNil() } else { z.F.EncMapInt32StringV(yy345, e) } // end block: if yy345 map == nil } z.EncWriteArrayElem() if x.FMapInt32Bytes == nil { r.EncodeNil() } else { z.F.EncMapInt32BytesV(x.FMapInt32Bytes, e) } // end block: if x.FMapInt32Bytes map == nil if yyn136 { z.EncWriteArrayElem() r.EncodeNil() } else { z.EncWriteArrayElem() yy348 := *x.FptrMapInt32Bytes if yy348 == nil { r.EncodeNil() } else { z.F.EncMapInt32BytesV(yy348, e) } // end block: if yy348 map == nil } z.EncWriteArrayElem() if x.FMapInt32Uint8 == nil { r.EncodeNil() } else { z.F.EncMapInt32Uint8V(x.FMapInt32Uint8, e) } // end block: if x.FMapInt32Uint8 map == nil if yyn138 { z.EncWriteArrayElem() r.EncodeNil() } else { z.EncWriteArrayElem() yy351 := *x.FptrMapInt32Uint8 if yy351 == nil { r.EncodeNil() } else { z.F.EncMapInt32Uint8V(yy351, e) } // end block: if yy351 map == nil } z.EncWriteArrayElem() if x.FMapInt32Uint64 == nil { r.EncodeNil() } else { z.F.EncMapInt32Uint64V(x.FMapInt32Uint64, e) } // end block: if x.FMapInt32Uint64 map == nil if yyn140 { z.EncWriteArrayElem() r.EncodeNil() } else { z.EncWriteArrayElem() yy354 := *x.FptrMapInt32Uint64 if yy354 == nil { r.EncodeNil() } else { z.F.EncMapInt32Uint64V(yy354, e) } // end block: if yy354 map == nil } z.EncWriteArrayElem() if x.FMapInt32Int == nil { r.EncodeNil() } else { z.F.EncMapInt32IntV(x.FMapInt32Int, e) } // end block: if x.FMapInt32Int map == nil if yyn142 { z.EncWriteArrayElem() r.EncodeNil() } else { z.EncWriteArrayElem() yy357 := *x.FptrMapInt32Int if yy357 == nil { r.EncodeNil() } else { z.F.EncMapInt32IntV(yy357, e) } // end block: if yy357 map == nil } z.EncWriteArrayElem() if x.FMapInt32Int32 == nil { r.EncodeNil() } else { z.F.EncMapInt32Int32V(x.FMapInt32Int32, e) } // end block: if x.FMapInt32Int32 map == nil if yyn144 { z.EncWriteArrayElem() r.EncodeNil() } else { z.EncWriteArrayElem() yy360 := *x.FptrMapInt32Int32 if yy360 == nil { r.EncodeNil() } else { z.F.EncMapInt32Int32V(yy360, e) } // end block: if yy360 map == nil } z.EncWriteArrayElem() if x.FMapInt32Float64 == nil { r.EncodeNil() } else { z.F.EncMapInt32Float64V(x.FMapInt32Float64, e) } // end block: if x.FMapInt32Float64 map == nil if yyn146 { z.EncWriteArrayElem() r.EncodeNil() } else { z.EncWriteArrayElem() yy363 := *x.FptrMapInt32Float64 if yy363 == nil { r.EncodeNil() } else { z.F.EncMapInt32Float64V(yy363, e) } // end block: if yy363 map == nil } z.EncWriteArrayElem() if x.FMapInt32Bool == nil { r.EncodeNil() } else { z.F.EncMapInt32BoolV(x.FMapInt32Bool, e) } // end block: if x.FMapInt32Bool map == nil if yyn148 { z.EncWriteArrayElem() r.EncodeNil() } else { z.EncWriteArrayElem() yy366 := *x.FptrMapInt32Bool if yy366 == nil { r.EncodeNil() } else { z.F.EncMapInt32BoolV(yy366, e) } // end block: if yy366 map == nil } z.EncWriteArrayEnd() } else { z.EncWriteMapStart(146) if z.EncBasicHandle().Canonical { z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"FBool\"") } else { r.EncodeString(`FBool`) } z.EncWriteMapElemValue() r.EncodeBool(bool(x.FBool)) z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"FBytes\"") } else { r.EncodeString(`FBytes`) } z.EncWriteMapElemValue() if x.FBytes == nil { r.EncodeNil() } else { r.EncodeStringBytesRaw([]byte(x.FBytes)) } // end block: if x.FBytes slice == nil z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"FFloat32\"") } else { r.EncodeString(`FFloat32`) } z.EncWriteMapElemValue() r.EncodeFloat32(float32(x.FFloat32)) z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"FFloat64\"") } else { r.EncodeString(`FFloat64`) } z.EncWriteMapElemValue() r.EncodeFloat64(float64(x.FFloat64)) z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"FInt\"") } else { r.EncodeString(`FInt`) } z.EncWriteMapElemValue() r.EncodeInt(int64(x.FInt)) z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"FInt16\"") } else { r.EncodeString(`FInt16`) } z.EncWriteMapElemValue() r.EncodeInt(int64(x.FInt16)) z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"FInt32\"") } else { r.EncodeString(`FInt32`) } z.EncWriteMapElemValue() r.EncodeInt(int64(x.FInt32)) z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"FInt64\"") } else { r.EncodeString(`FInt64`) } z.EncWriteMapElemValue() r.EncodeInt(int64(x.FInt64)) z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"FInt8\"") } else { r.EncodeString(`FInt8`) } z.EncWriteMapElemValue() r.EncodeInt(int64(x.FInt8)) z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"FIntf\"") } else { r.EncodeString(`FIntf`) } z.EncWriteMapElemValue() z.EncFallback(x.FIntf) z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"FMapInt32Bool\"") } else { r.EncodeString(`FMapInt32Bool`) } z.EncWriteMapElemValue() if x.FMapInt32Bool == nil { r.EncodeNil() } else { z.F.EncMapInt32BoolV(x.FMapInt32Bool, e) } // end block: if x.FMapInt32Bool map == nil z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"FMapInt32Bytes\"") } else { r.EncodeString(`FMapInt32Bytes`) } z.EncWriteMapElemValue() if x.FMapInt32Bytes == nil { r.EncodeNil() } else { z.F.EncMapInt32BytesV(x.FMapInt32Bytes, e) } // end block: if x.FMapInt32Bytes map == nil z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"FMapInt32Float64\"") } else { r.EncodeString(`FMapInt32Float64`) } z.EncWriteMapElemValue() if x.FMapInt32Float64 == nil { r.EncodeNil() } else { z.F.EncMapInt32Float64V(x.FMapInt32Float64, e) } // end block: if x.FMapInt32Float64 map == nil z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"FMapInt32Int\"") } else { r.EncodeString(`FMapInt32Int`) } z.EncWriteMapElemValue() if x.FMapInt32Int == nil { r.EncodeNil() } else { z.F.EncMapInt32IntV(x.FMapInt32Int, e) } // end block: if x.FMapInt32Int map == nil z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"FMapInt32Int32\"") } else { r.EncodeString(`FMapInt32Int32`) } z.EncWriteMapElemValue() if x.FMapInt32Int32 == nil { r.EncodeNil() } else { z.F.EncMapInt32Int32V(x.FMapInt32Int32, e) } // end block: if x.FMapInt32Int32 map == nil z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"FMapInt32Intf\"") } else { r.EncodeString(`FMapInt32Intf`) } z.EncWriteMapElemValue() if x.FMapInt32Intf == nil { r.EncodeNil() } else { z.F.EncMapInt32IntfV(x.FMapInt32Intf, e) } // end block: if x.FMapInt32Intf map == nil z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"FMapInt32String\"") } else { r.EncodeString(`FMapInt32String`) } z.EncWriteMapElemValue() if x.FMapInt32String == nil { r.EncodeNil() } else { z.F.EncMapInt32StringV(x.FMapInt32String, e) } // end block: if x.FMapInt32String map == nil z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"FMapInt32Uint64\"") } else { r.EncodeString(`FMapInt32Uint64`) } z.EncWriteMapElemValue() if x.FMapInt32Uint64 == nil { r.EncodeNil() } else { z.F.EncMapInt32Uint64V(x.FMapInt32Uint64, e) } // end block: if x.FMapInt32Uint64 map == nil z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"FMapInt32Uint8\"") } else { r.EncodeString(`FMapInt32Uint8`) } z.EncWriteMapElemValue() if x.FMapInt32Uint8 == nil { r.EncodeNil() } else { z.F.EncMapInt32Uint8V(x.FMapInt32Uint8, e) } // end block: if x.FMapInt32Uint8 map == nil z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"FMapIntBool\"") } else { r.EncodeString(`FMapIntBool`) } z.EncWriteMapElemValue() if x.FMapIntBool == nil { r.EncodeNil() } else { z.F.EncMapIntBoolV(x.FMapIntBool, e) } // end block: if x.FMapIntBool map == nil z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"FMapIntBytes\"") } else { r.EncodeString(`FMapIntBytes`) } z.EncWriteMapElemValue() if x.FMapIntBytes == nil { r.EncodeNil() } else { z.F.EncMapIntBytesV(x.FMapIntBytes, e) } // end block: if x.FMapIntBytes map == nil z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"FMapIntFloat64\"") } else { r.EncodeString(`FMapIntFloat64`) } z.EncWriteMapElemValue() if x.FMapIntFloat64 == nil { r.EncodeNil() } else { z.F.EncMapIntFloat64V(x.FMapIntFloat64, e) } // end block: if x.FMapIntFloat64 map == nil z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"FMapIntInt\"") } else { r.EncodeString(`FMapIntInt`) } z.EncWriteMapElemValue() if x.FMapIntInt == nil { r.EncodeNil() } else { z.F.EncMapIntIntV(x.FMapIntInt, e) } // end block: if x.FMapIntInt map == nil z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"FMapIntInt32\"") } else { r.EncodeString(`FMapIntInt32`) } z.EncWriteMapElemValue() if x.FMapIntInt32 == nil { r.EncodeNil() } else { z.F.EncMapIntInt32V(x.FMapIntInt32, e) } // end block: if x.FMapIntInt32 map == nil z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"FMapIntIntf\"") } else { r.EncodeString(`FMapIntIntf`) } z.EncWriteMapElemValue() if x.FMapIntIntf == nil { r.EncodeNil() } else { z.F.EncMapIntIntfV(x.FMapIntIntf, e) } // end block: if x.FMapIntIntf map == nil z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"FMapIntString\"") } else { r.EncodeString(`FMapIntString`) } z.EncWriteMapElemValue() if x.FMapIntString == nil { r.EncodeNil() } else { z.F.EncMapIntStringV(x.FMapIntString, e) } // end block: if x.FMapIntString map == nil z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"FMapIntUint64\"") } else { r.EncodeString(`FMapIntUint64`) } z.EncWriteMapElemValue() if x.FMapIntUint64 == nil { r.EncodeNil() } else { z.F.EncMapIntUint64V(x.FMapIntUint64, e) } // end block: if x.FMapIntUint64 map == nil z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"FMapIntUint8\"") } else { r.EncodeString(`FMapIntUint8`) } z.EncWriteMapElemValue() if x.FMapIntUint8 == nil { r.EncodeNil() } else { z.F.EncMapIntUint8V(x.FMapIntUint8, e) } // end block: if x.FMapIntUint8 map == nil z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"FMapStringBool\"") } else { r.EncodeString(`FMapStringBool`) } z.EncWriteMapElemValue() if x.FMapStringBool == nil { r.EncodeNil() } else { z.F.EncMapStringBoolV(x.FMapStringBool, e) } // end block: if x.FMapStringBool map == nil z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"FMapStringBytes\"") } else { r.EncodeString(`FMapStringBytes`) } z.EncWriteMapElemValue() if x.FMapStringBytes == nil { r.EncodeNil() } else { z.F.EncMapStringBytesV(x.FMapStringBytes, e) } // end block: if x.FMapStringBytes map == nil z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"FMapStringFloat64\"") } else { r.EncodeString(`FMapStringFloat64`) } z.EncWriteMapElemValue() if x.FMapStringFloat64 == nil { r.EncodeNil() } else { z.F.EncMapStringFloat64V(x.FMapStringFloat64, e) } // end block: if x.FMapStringFloat64 map == nil z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"FMapStringInt\"") } else { r.EncodeString(`FMapStringInt`) } z.EncWriteMapElemValue() if x.FMapStringInt == nil { r.EncodeNil() } else { z.F.EncMapStringIntV(x.FMapStringInt, e) } // end block: if x.FMapStringInt map == nil z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"FMapStringInt32\"") } else { r.EncodeString(`FMapStringInt32`) } z.EncWriteMapElemValue() if x.FMapStringInt32 == nil { r.EncodeNil() } else { z.F.EncMapStringInt32V(x.FMapStringInt32, e) } // end block: if x.FMapStringInt32 map == nil z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"FMapStringIntf\"") } else { r.EncodeString(`FMapStringIntf`) } z.EncWriteMapElemValue() if x.FMapStringIntf == nil { r.EncodeNil() } else { z.F.EncMapStringIntfV(x.FMapStringIntf, e) } // end block: if x.FMapStringIntf map == nil z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"FMapStringString\"") } else { r.EncodeString(`FMapStringString`) } z.EncWriteMapElemValue() if x.FMapStringString == nil { r.EncodeNil() } else { z.F.EncMapStringStringV(x.FMapStringString, e) } // end block: if x.FMapStringString map == nil z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"FMapStringUint64\"") } else { r.EncodeString(`FMapStringUint64`) } z.EncWriteMapElemValue() if x.FMapStringUint64 == nil { r.EncodeNil() } else { z.F.EncMapStringUint64V(x.FMapStringUint64, e) } // end block: if x.FMapStringUint64 map == nil z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"FMapStringUint8\"") } else { r.EncodeString(`FMapStringUint8`) } z.EncWriteMapElemValue() if x.FMapStringUint8 == nil { r.EncodeNil() } else { z.F.EncMapStringUint8V(x.FMapStringUint8, e) } // end block: if x.FMapStringUint8 map == nil z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"FMapUint64Bool\"") } else { r.EncodeString(`FMapUint64Bool`) } z.EncWriteMapElemValue() if x.FMapUint64Bool == nil { r.EncodeNil() } else { z.F.EncMapUint64BoolV(x.FMapUint64Bool, e) } // end block: if x.FMapUint64Bool map == nil z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"FMapUint64Bytes\"") } else { r.EncodeString(`FMapUint64Bytes`) } z.EncWriteMapElemValue() if x.FMapUint64Bytes == nil { r.EncodeNil() } else { z.F.EncMapUint64BytesV(x.FMapUint64Bytes, e) } // end block: if x.FMapUint64Bytes map == nil z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"FMapUint64Float64\"") } else { r.EncodeString(`FMapUint64Float64`) } z.EncWriteMapElemValue() if x.FMapUint64Float64 == nil { r.EncodeNil() } else { z.F.EncMapUint64Float64V(x.FMapUint64Float64, e) } // end block: if x.FMapUint64Float64 map == nil z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"FMapUint64Int\"") } else { r.EncodeString(`FMapUint64Int`) } z.EncWriteMapElemValue() if x.FMapUint64Int == nil { r.EncodeNil() } else { z.F.EncMapUint64IntV(x.FMapUint64Int, e) } // end block: if x.FMapUint64Int map == nil z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"FMapUint64Int32\"") } else { r.EncodeString(`FMapUint64Int32`) } z.EncWriteMapElemValue() if x.FMapUint64Int32 == nil { r.EncodeNil() } else { z.F.EncMapUint64Int32V(x.FMapUint64Int32, e) } // end block: if x.FMapUint64Int32 map == nil z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"FMapUint64Intf\"") } else { r.EncodeString(`FMapUint64Intf`) } z.EncWriteMapElemValue() if x.FMapUint64Intf == nil { r.EncodeNil() } else { z.F.EncMapUint64IntfV(x.FMapUint64Intf, e) } // end block: if x.FMapUint64Intf map == nil z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"FMapUint64String\"") } else { r.EncodeString(`FMapUint64String`) } z.EncWriteMapElemValue() if x.FMapUint64String == nil { r.EncodeNil() } else { z.F.EncMapUint64StringV(x.FMapUint64String, e) } // end block: if x.FMapUint64String map == nil z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"FMapUint64Uint64\"") } else { r.EncodeString(`FMapUint64Uint64`) } z.EncWriteMapElemValue() if x.FMapUint64Uint64 == nil { r.EncodeNil() } else { z.F.EncMapUint64Uint64V(x.FMapUint64Uint64, e) } // end block: if x.FMapUint64Uint64 map == nil z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"FMapUint64Uint8\"") } else { r.EncodeString(`FMapUint64Uint8`) } z.EncWriteMapElemValue() if x.FMapUint64Uint8 == nil { r.EncodeNil() } else { z.F.EncMapUint64Uint8V(x.FMapUint64Uint8, e) } // end block: if x.FMapUint64Uint8 map == nil z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"FMapUint8Bool\"") } else { r.EncodeString(`FMapUint8Bool`) } z.EncWriteMapElemValue() if x.FMapUint8Bool == nil { r.EncodeNil() } else { z.F.EncMapUint8BoolV(x.FMapUint8Bool, e) } // end block: if x.FMapUint8Bool map == nil z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"FMapUint8Bytes\"") } else { r.EncodeString(`FMapUint8Bytes`) } z.EncWriteMapElemValue() if x.FMapUint8Bytes == nil { r.EncodeNil() } else { z.F.EncMapUint8BytesV(x.FMapUint8Bytes, e) } // end block: if x.FMapUint8Bytes map == nil z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"FMapUint8Float64\"") } else { r.EncodeString(`FMapUint8Float64`) } z.EncWriteMapElemValue() if x.FMapUint8Float64 == nil { r.EncodeNil() } else { z.F.EncMapUint8Float64V(x.FMapUint8Float64, e) } // end block: if x.FMapUint8Float64 map == nil z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"FMapUint8Int\"") } else { r.EncodeString(`FMapUint8Int`) } z.EncWriteMapElemValue() if x.FMapUint8Int == nil { r.EncodeNil() } else { z.F.EncMapUint8IntV(x.FMapUint8Int, e) } // end block: if x.FMapUint8Int map == nil z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"FMapUint8Int32\"") } else { r.EncodeString(`FMapUint8Int32`) } z.EncWriteMapElemValue() if x.FMapUint8Int32 == nil { r.EncodeNil() } else { z.F.EncMapUint8Int32V(x.FMapUint8Int32, e) } // end block: if x.FMapUint8Int32 map == nil z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"FMapUint8Intf\"") } else { r.EncodeString(`FMapUint8Intf`) } z.EncWriteMapElemValue() if x.FMapUint8Intf == nil { r.EncodeNil() } else { z.F.EncMapUint8IntfV(x.FMapUint8Intf, e) } // end block: if x.FMapUint8Intf map == nil z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"FMapUint8String\"") } else { r.EncodeString(`FMapUint8String`) } z.EncWriteMapElemValue() if x.FMapUint8String == nil { r.EncodeNil() } else { z.F.EncMapUint8StringV(x.FMapUint8String, e) } // end block: if x.FMapUint8String map == nil z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"FMapUint8Uint64\"") } else { r.EncodeString(`FMapUint8Uint64`) } z.EncWriteMapElemValue() if x.FMapUint8Uint64 == nil { r.EncodeNil() } else { z.F.EncMapUint8Uint64V(x.FMapUint8Uint64, e) } // end block: if x.FMapUint8Uint64 map == nil z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"FMapUint8Uint8\"") } else { r.EncodeString(`FMapUint8Uint8`) } z.EncWriteMapElemValue() if x.FMapUint8Uint8 == nil { r.EncodeNil() } else { z.F.EncMapUint8Uint8V(x.FMapUint8Uint8, e) } // end block: if x.FMapUint8Uint8 map == nil z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"FSliceBool\"") } else { r.EncodeString(`FSliceBool`) } z.EncWriteMapElemValue() if x.FSliceBool == nil { r.EncodeNil() } else { z.F.EncSliceBoolV(x.FSliceBool, e) } // end block: if x.FSliceBool slice == nil z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"FSliceBytes\"") } else { r.EncodeString(`FSliceBytes`) } z.EncWriteMapElemValue() if x.FSliceBytes == nil { r.EncodeNil() } else { z.F.EncSliceBytesV(x.FSliceBytes, e) } // end block: if x.FSliceBytes slice == nil z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"FSliceFloat32\"") } else { r.EncodeString(`FSliceFloat32`) } z.EncWriteMapElemValue() if x.FSliceFloat32 == nil { r.EncodeNil() } else { z.F.EncSliceFloat32V(x.FSliceFloat32, e) } // end block: if x.FSliceFloat32 slice == nil z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"FSliceFloat64\"") } else { r.EncodeString(`FSliceFloat64`) } z.EncWriteMapElemValue() if x.FSliceFloat64 == nil { r.EncodeNil() } else { z.F.EncSliceFloat64V(x.FSliceFloat64, e) } // end block: if x.FSliceFloat64 slice == nil z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"FSliceInt\"") } else { r.EncodeString(`FSliceInt`) } z.EncWriteMapElemValue() if x.FSliceInt == nil { r.EncodeNil() } else { z.F.EncSliceIntV(x.FSliceInt, e) } // end block: if x.FSliceInt slice == nil z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"FSliceInt32\"") } else { r.EncodeString(`FSliceInt32`) } z.EncWriteMapElemValue() if x.FSliceInt32 == nil { r.EncodeNil() } else { z.F.EncSliceInt32V(x.FSliceInt32, e) } // end block: if x.FSliceInt32 slice == nil z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"FSliceInt64\"") } else { r.EncodeString(`FSliceInt64`) } z.EncWriteMapElemValue() if x.FSliceInt64 == nil { r.EncodeNil() } else { z.F.EncSliceInt64V(x.FSliceInt64, e) } // end block: if x.FSliceInt64 slice == nil z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"FSliceIntf\"") } else { r.EncodeString(`FSliceIntf`) } z.EncWriteMapElemValue() if x.FSliceIntf == nil { r.EncodeNil() } else { z.F.EncSliceIntfV(x.FSliceIntf, e) } // end block: if x.FSliceIntf slice == nil z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"FSliceString\"") } else { r.EncodeString(`FSliceString`) } z.EncWriteMapElemValue() if x.FSliceString == nil { r.EncodeNil() } else { z.F.EncSliceStringV(x.FSliceString, e) } // end block: if x.FSliceString slice == nil z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"FSliceUint64\"") } else { r.EncodeString(`FSliceUint64`) } z.EncWriteMapElemValue() if x.FSliceUint64 == nil { r.EncodeNil() } else { z.F.EncSliceUint64V(x.FSliceUint64, e) } // end block: if x.FSliceUint64 slice == nil z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"FSliceUint8\"") } else { r.EncodeString(`FSliceUint8`) } z.EncWriteMapElemValue() if x.FSliceUint8 == nil { r.EncodeNil() } else { r.EncodeStringBytesRaw([]byte(x.FSliceUint8)) } // end block: if x.FSliceUint8 slice == nil z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"FString\"") } else { r.EncodeString(`FString`) } z.EncWriteMapElemValue() r.EncodeString(string(x.FString)) z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"FUint\"") } else { r.EncodeString(`FUint`) } z.EncWriteMapElemValue() r.EncodeUint(uint64(x.FUint)) z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"FUint16\"") } else { r.EncodeString(`FUint16`) } z.EncWriteMapElemValue() r.EncodeUint(uint64(x.FUint16)) z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"FUint32\"") } else { r.EncodeString(`FUint32`) } z.EncWriteMapElemValue() r.EncodeUint(uint64(x.FUint32)) z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"FUint64\"") } else { r.EncodeString(`FUint64`) } z.EncWriteMapElemValue() r.EncodeUint(uint64(x.FUint64)) z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"FUint8\"") } else { r.EncodeString(`FUint8`) } z.EncWriteMapElemValue() r.EncodeUint(uint64(x.FUint8)) z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"FUintptr\"") } else { r.EncodeString(`FUintptr`) } z.EncWriteMapElemValue() r.EncodeUint(uint64(x.FUintptr)) z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"FptrBool\"") } else { r.EncodeString(`FptrBool`) } z.EncWriteMapElemValue() if yyn36 { r.EncodeNil() } else { yy441 := *x.FptrBool r.EncodeBool(bool(yy441)) } z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"FptrBytes\"") } else { r.EncodeString(`FptrBytes`) } z.EncWriteMapElemValue() if yyn8 { r.EncodeNil() } else { yy443 := *x.FptrBytes if yy443 == nil { r.EncodeNil() } else { r.EncodeStringBytesRaw([]byte(yy443)) } // end block: if yy443 slice == nil } z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"FptrFloat32\"") } else { r.EncodeString(`FptrFloat32`) } z.EncWriteMapElemValue() if yyn10 { r.EncodeNil() } else { yy445 := *x.FptrFloat32 r.EncodeFloat32(float32(yy445)) } z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"FptrFloat64\"") } else { r.EncodeString(`FptrFloat64`) } z.EncWriteMapElemValue() if yyn12 { r.EncodeNil() } else { yy447 := *x.FptrFloat64 r.EncodeFloat64(float64(yy447)) } z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"FptrInt\"") } else { r.EncodeString(`FptrInt`) } z.EncWriteMapElemValue() if yyn26 { r.EncodeNil() } else { yy449 := *x.FptrInt r.EncodeInt(int64(yy449)) } z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"FptrInt16\"") } else { r.EncodeString(`FptrInt16`) } z.EncWriteMapElemValue() if yyn30 { r.EncodeNil() } else { yy451 := *x.FptrInt16 r.EncodeInt(int64(yy451)) } z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"FptrInt32\"") } else { r.EncodeString(`FptrInt32`) } z.EncWriteMapElemValue() if yyn32 { r.EncodeNil() } else { yy453 := *x.FptrInt32 r.EncodeInt(int64(yy453)) } z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"FptrInt64\"") } else { r.EncodeString(`FptrInt64`) } z.EncWriteMapElemValue() if yyn34 { r.EncodeNil() } else { yy455 := *x.FptrInt64 r.EncodeInt(int64(yy455)) } z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"FptrInt8\"") } else { r.EncodeString(`FptrInt8`) } z.EncWriteMapElemValue() if yyn28 { r.EncodeNil() } else { yy457 := *x.FptrInt8 r.EncodeInt(int64(yy457)) } z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"FptrIntf\"") } else { r.EncodeString(`FptrIntf`) } z.EncWriteMapElemValue() if yyn4 { r.EncodeNil() } else { yy459 := *x.FptrIntf z.EncFallback(yy459) } z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"FptrMapInt32Bool\"") } else { r.EncodeString(`FptrMapInt32Bool`) } z.EncWriteMapElemValue() if yyn148 { r.EncodeNil() } else { yy461 := *x.FptrMapInt32Bool if yy461 == nil { r.EncodeNil() } else { z.F.EncMapInt32BoolV(yy461, e) } // end block: if yy461 map == nil } z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"FptrMapInt32Bytes\"") } else { r.EncodeString(`FptrMapInt32Bytes`) } z.EncWriteMapElemValue() if yyn136 { r.EncodeNil() } else { yy463 := *x.FptrMapInt32Bytes if yy463 == nil { r.EncodeNil() } else { z.F.EncMapInt32BytesV(yy463, e) } // end block: if yy463 map == nil } z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"FptrMapInt32Float64\"") } else { r.EncodeString(`FptrMapInt32Float64`) } z.EncWriteMapElemValue() if yyn146 { r.EncodeNil() } else { yy465 := *x.FptrMapInt32Float64 if yy465 == nil { r.EncodeNil() } else { z.F.EncMapInt32Float64V(yy465, e) } // end block: if yy465 map == nil } z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"FptrMapInt32Int\"") } else { r.EncodeString(`FptrMapInt32Int`) } z.EncWriteMapElemValue() if yyn142 { r.EncodeNil() } else { yy467 := *x.FptrMapInt32Int if yy467 == nil { r.EncodeNil() } else { z.F.EncMapInt32IntV(yy467, e) } // end block: if yy467 map == nil } z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"FptrMapInt32Int32\"") } else { r.EncodeString(`FptrMapInt32Int32`) } z.EncWriteMapElemValue() if yyn144 { r.EncodeNil() } else { yy469 := *x.FptrMapInt32Int32 if yy469 == nil { r.EncodeNil() } else { z.F.EncMapInt32Int32V(yy469, e) } // end block: if yy469 map == nil } z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"FptrMapInt32Intf\"") } else { r.EncodeString(`FptrMapInt32Intf`) } z.EncWriteMapElemValue() if yyn132 { r.EncodeNil() } else { yy471 := *x.FptrMapInt32Intf if yy471 == nil { r.EncodeNil() } else { z.F.EncMapInt32IntfV(yy471, e) } // end block: if yy471 map == nil } z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"FptrMapInt32String\"") } else { r.EncodeString(`FptrMapInt32String`) } z.EncWriteMapElemValue() if yyn134 { r.EncodeNil() } else { yy473 := *x.FptrMapInt32String if yy473 == nil { r.EncodeNil() } else { z.F.EncMapInt32StringV(yy473, e) } // end block: if yy473 map == nil } z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"FptrMapInt32Uint64\"") } else { r.EncodeString(`FptrMapInt32Uint64`) } z.EncWriteMapElemValue() if yyn140 { r.EncodeNil() } else { yy475 := *x.FptrMapInt32Uint64 if yy475 == nil { r.EncodeNil() } else { z.F.EncMapInt32Uint64V(yy475, e) } // end block: if yy475 map == nil } z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"FptrMapInt32Uint8\"") } else { r.EncodeString(`FptrMapInt32Uint8`) } z.EncWriteMapElemValue() if yyn138 { r.EncodeNil() } else { yy477 := *x.FptrMapInt32Uint8 if yy477 == nil { r.EncodeNil() } else { z.F.EncMapInt32Uint8V(yy477, e) } // end block: if yy477 map == nil } z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"FptrMapIntBool\"") } else { r.EncodeString(`FptrMapIntBool`) } z.EncWriteMapElemValue() if yyn130 { r.EncodeNil() } else { yy479 := *x.FptrMapIntBool if yy479 == nil { r.EncodeNil() } else { z.F.EncMapIntBoolV(yy479, e) } // end block: if yy479 map == nil } z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"FptrMapIntBytes\"") } else { r.EncodeString(`FptrMapIntBytes`) } z.EncWriteMapElemValue() if yyn118 { r.EncodeNil() } else { yy481 := *x.FptrMapIntBytes if yy481 == nil { r.EncodeNil() } else { z.F.EncMapIntBytesV(yy481, e) } // end block: if yy481 map == nil } z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"FptrMapIntFloat64\"") } else { r.EncodeString(`FptrMapIntFloat64`) } z.EncWriteMapElemValue() if yyn128 { r.EncodeNil() } else { yy483 := *x.FptrMapIntFloat64 if yy483 == nil { r.EncodeNil() } else { z.F.EncMapIntFloat64V(yy483, e) } // end block: if yy483 map == nil } z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"FptrMapIntInt\"") } else { r.EncodeString(`FptrMapIntInt`) } z.EncWriteMapElemValue() if yyn124 { r.EncodeNil() } else { yy485 := *x.FptrMapIntInt if yy485 == nil { r.EncodeNil() } else { z.F.EncMapIntIntV(yy485, e) } // end block: if yy485 map == nil } z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"FptrMapIntInt32\"") } else { r.EncodeString(`FptrMapIntInt32`) } z.EncWriteMapElemValue() if yyn126 { r.EncodeNil() } else { yy487 := *x.FptrMapIntInt32 if yy487 == nil { r.EncodeNil() } else { z.F.EncMapIntInt32V(yy487, e) } // end block: if yy487 map == nil } z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"FptrMapIntIntf\"") } else { r.EncodeString(`FptrMapIntIntf`) } z.EncWriteMapElemValue() if yyn114 { r.EncodeNil() } else { yy489 := *x.FptrMapIntIntf if yy489 == nil { r.EncodeNil() } else { z.F.EncMapIntIntfV(yy489, e) } // end block: if yy489 map == nil } z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"FptrMapIntString\"") } else { r.EncodeString(`FptrMapIntString`) } z.EncWriteMapElemValue() if yyn116 { r.EncodeNil() } else { yy491 := *x.FptrMapIntString if yy491 == nil { r.EncodeNil() } else { z.F.EncMapIntStringV(yy491, e) } // end block: if yy491 map == nil } z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"FptrMapIntUint64\"") } else { r.EncodeString(`FptrMapIntUint64`) } z.EncWriteMapElemValue() if yyn122 { r.EncodeNil() } else { yy493 := *x.FptrMapIntUint64 if yy493 == nil { r.EncodeNil() } else { z.F.EncMapIntUint64V(yy493, e) } // end block: if yy493 map == nil } z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"FptrMapIntUint8\"") } else { r.EncodeString(`FptrMapIntUint8`) } z.EncWriteMapElemValue() if yyn120 { r.EncodeNil() } else { yy495 := *x.FptrMapIntUint8 if yy495 == nil { r.EncodeNil() } else { z.F.EncMapIntUint8V(yy495, e) } // end block: if yy495 map == nil } z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"FptrMapStringBool\"") } else { r.EncodeString(`FptrMapStringBool`) } z.EncWriteMapElemValue() if yyn76 { r.EncodeNil() } else { yy497 := *x.FptrMapStringBool if yy497 == nil { r.EncodeNil() } else { z.F.EncMapStringBoolV(yy497, e) } // end block: if yy497 map == nil } z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"FptrMapStringBytes\"") } else { r.EncodeString(`FptrMapStringBytes`) } z.EncWriteMapElemValue() if yyn64 { r.EncodeNil() } else { yy499 := *x.FptrMapStringBytes if yy499 == nil { r.EncodeNil() } else { z.F.EncMapStringBytesV(yy499, e) } // end block: if yy499 map == nil } z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"FptrMapStringFloat64\"") } else { r.EncodeString(`FptrMapStringFloat64`) } z.EncWriteMapElemValue() if yyn74 { r.EncodeNil() } else { yy501 := *x.FptrMapStringFloat64 if yy501 == nil { r.EncodeNil() } else { z.F.EncMapStringFloat64V(yy501, e) } // end block: if yy501 map == nil } z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"FptrMapStringInt\"") } else { r.EncodeString(`FptrMapStringInt`) } z.EncWriteMapElemValue() if yyn70 { r.EncodeNil() } else { yy503 := *x.FptrMapStringInt if yy503 == nil { r.EncodeNil() } else { z.F.EncMapStringIntV(yy503, e) } // end block: if yy503 map == nil } z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"FptrMapStringInt32\"") } else { r.EncodeString(`FptrMapStringInt32`) } z.EncWriteMapElemValue() if yyn72 { r.EncodeNil() } else { yy505 := *x.FptrMapStringInt32 if yy505 == nil { r.EncodeNil() } else { z.F.EncMapStringInt32V(yy505, e) } // end block: if yy505 map == nil } z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"FptrMapStringIntf\"") } else { r.EncodeString(`FptrMapStringIntf`) } z.EncWriteMapElemValue() if yyn60 { r.EncodeNil() } else { yy507 := *x.FptrMapStringIntf if yy507 == nil { r.EncodeNil() } else { z.F.EncMapStringIntfV(yy507, e) } // end block: if yy507 map == nil } z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"FptrMapStringString\"") } else { r.EncodeString(`FptrMapStringString`) } z.EncWriteMapElemValue() if yyn62 { r.EncodeNil() } else { yy509 := *x.FptrMapStringString if yy509 == nil { r.EncodeNil() } else { z.F.EncMapStringStringV(yy509, e) } // end block: if yy509 map == nil } z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"FptrMapStringUint64\"") } else { r.EncodeString(`FptrMapStringUint64`) } z.EncWriteMapElemValue() if yyn68 { r.EncodeNil() } else { yy511 := *x.FptrMapStringUint64 if yy511 == nil { r.EncodeNil() } else { z.F.EncMapStringUint64V(yy511, e) } // end block: if yy511 map == nil } z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"FptrMapStringUint8\"") } else { r.EncodeString(`FptrMapStringUint8`) } z.EncWriteMapElemValue() if yyn66 { r.EncodeNil() } else { yy513 := *x.FptrMapStringUint8 if yy513 == nil { r.EncodeNil() } else { z.F.EncMapStringUint8V(yy513, e) } // end block: if yy513 map == nil } z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"FptrMapUint64Bool\"") } else { r.EncodeString(`FptrMapUint64Bool`) } z.EncWriteMapElemValue() if yyn112 { r.EncodeNil() } else { yy515 := *x.FptrMapUint64Bool if yy515 == nil { r.EncodeNil() } else { z.F.EncMapUint64BoolV(yy515, e) } // end block: if yy515 map == nil } z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"FptrMapUint64Bytes\"") } else { r.EncodeString(`FptrMapUint64Bytes`) } z.EncWriteMapElemValue() if yyn100 { r.EncodeNil() } else { yy517 := *x.FptrMapUint64Bytes if yy517 == nil { r.EncodeNil() } else { z.F.EncMapUint64BytesV(yy517, e) } // end block: if yy517 map == nil } z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"FptrMapUint64Float64\"") } else { r.EncodeString(`FptrMapUint64Float64`) } z.EncWriteMapElemValue() if yyn110 { r.EncodeNil() } else { yy519 := *x.FptrMapUint64Float64 if yy519 == nil { r.EncodeNil() } else { z.F.EncMapUint64Float64V(yy519, e) } // end block: if yy519 map == nil } z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"FptrMapUint64Int\"") } else { r.EncodeString(`FptrMapUint64Int`) } z.EncWriteMapElemValue() if yyn106 { r.EncodeNil() } else { yy521 := *x.FptrMapUint64Int if yy521 == nil { r.EncodeNil() } else { z.F.EncMapUint64IntV(yy521, e) } // end block: if yy521 map == nil } z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"FptrMapUint64Int32\"") } else { r.EncodeString(`FptrMapUint64Int32`) } z.EncWriteMapElemValue() if yyn108 { r.EncodeNil() } else { yy523 := *x.FptrMapUint64Int32 if yy523 == nil { r.EncodeNil() } else { z.F.EncMapUint64Int32V(yy523, e) } // end block: if yy523 map == nil } z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"FptrMapUint64Intf\"") } else { r.EncodeString(`FptrMapUint64Intf`) } z.EncWriteMapElemValue() if yyn96 { r.EncodeNil() } else { yy525 := *x.FptrMapUint64Intf if yy525 == nil { r.EncodeNil() } else { z.F.EncMapUint64IntfV(yy525, e) } // end block: if yy525 map == nil } z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"FptrMapUint64String\"") } else { r.EncodeString(`FptrMapUint64String`) } z.EncWriteMapElemValue() if yyn98 { r.EncodeNil() } else { yy527 := *x.FptrMapUint64String if yy527 == nil { r.EncodeNil() } else { z.F.EncMapUint64StringV(yy527, e) } // end block: if yy527 map == nil } z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"FptrMapUint64Uint64\"") } else { r.EncodeString(`FptrMapUint64Uint64`) } z.EncWriteMapElemValue() if yyn104 { r.EncodeNil() } else { yy529 := *x.FptrMapUint64Uint64 if yy529 == nil { r.EncodeNil() } else { z.F.EncMapUint64Uint64V(yy529, e) } // end block: if yy529 map == nil } z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"FptrMapUint64Uint8\"") } else { r.EncodeString(`FptrMapUint64Uint8`) } z.EncWriteMapElemValue() if yyn102 { r.EncodeNil() } else { yy531 := *x.FptrMapUint64Uint8 if yy531 == nil { r.EncodeNil() } else { z.F.EncMapUint64Uint8V(yy531, e) } // end block: if yy531 map == nil } z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"FptrMapUint8Bool\"") } else { r.EncodeString(`FptrMapUint8Bool`) } z.EncWriteMapElemValue() if yyn94 { r.EncodeNil() } else { yy533 := *x.FptrMapUint8Bool if yy533 == nil { r.EncodeNil() } else { z.F.EncMapUint8BoolV(yy533, e) } // end block: if yy533 map == nil } z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"FptrMapUint8Bytes\"") } else { r.EncodeString(`FptrMapUint8Bytes`) } z.EncWriteMapElemValue() if yyn82 { r.EncodeNil() } else { yy535 := *x.FptrMapUint8Bytes if yy535 == nil { r.EncodeNil() } else { z.F.EncMapUint8BytesV(yy535, e) } // end block: if yy535 map == nil } z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"FptrMapUint8Float64\"") } else { r.EncodeString(`FptrMapUint8Float64`) } z.EncWriteMapElemValue() if yyn92 { r.EncodeNil() } else { yy537 := *x.FptrMapUint8Float64 if yy537 == nil { r.EncodeNil() } else { z.F.EncMapUint8Float64V(yy537, e) } // end block: if yy537 map == nil } z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"FptrMapUint8Int\"") } else { r.EncodeString(`FptrMapUint8Int`) } z.EncWriteMapElemValue() if yyn88 { r.EncodeNil() } else { yy539 := *x.FptrMapUint8Int if yy539 == nil { r.EncodeNil() } else { z.F.EncMapUint8IntV(yy539, e) } // end block: if yy539 map == nil } z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"FptrMapUint8Int32\"") } else { r.EncodeString(`FptrMapUint8Int32`) } z.EncWriteMapElemValue() if yyn90 { r.EncodeNil() } else { yy541 := *x.FptrMapUint8Int32 if yy541 == nil { r.EncodeNil() } else { z.F.EncMapUint8Int32V(yy541, e) } // end block: if yy541 map == nil } z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"FptrMapUint8Intf\"") } else { r.EncodeString(`FptrMapUint8Intf`) } z.EncWriteMapElemValue() if yyn78 { r.EncodeNil() } else { yy543 := *x.FptrMapUint8Intf if yy543 == nil { r.EncodeNil() } else { z.F.EncMapUint8IntfV(yy543, e) } // end block: if yy543 map == nil } z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"FptrMapUint8String\"") } else { r.EncodeString(`FptrMapUint8String`) } z.EncWriteMapElemValue() if yyn80 { r.EncodeNil() } else { yy545 := *x.FptrMapUint8String if yy545 == nil { r.EncodeNil() } else { z.F.EncMapUint8StringV(yy545, e) } // end block: if yy545 map == nil } z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"FptrMapUint8Uint64\"") } else { r.EncodeString(`FptrMapUint8Uint64`) } z.EncWriteMapElemValue() if yyn86 { r.EncodeNil() } else { yy547 := *x.FptrMapUint8Uint64 if yy547 == nil { r.EncodeNil() } else { z.F.EncMapUint8Uint64V(yy547, e) } // end block: if yy547 map == nil } z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"FptrMapUint8Uint8\"") } else { r.EncodeString(`FptrMapUint8Uint8`) } z.EncWriteMapElemValue() if yyn84 { r.EncodeNil() } else { yy549 := *x.FptrMapUint8Uint8 if yy549 == nil { r.EncodeNil() } else { z.F.EncMapUint8Uint8V(yy549, e) } // end block: if yy549 map == nil } z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"FptrSliceBool\"") } else { r.EncodeString(`FptrSliceBool`) } z.EncWriteMapElemValue() if yyn58 { r.EncodeNil() } else { yy551 := *x.FptrSliceBool if yy551 == nil { r.EncodeNil() } else { z.F.EncSliceBoolV(yy551, e) } // end block: if yy551 slice == nil } z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"FptrSliceBytes\"") } else { r.EncodeString(`FptrSliceBytes`) } z.EncWriteMapElemValue() if yyn42 { r.EncodeNil() } else { yy553 := *x.FptrSliceBytes if yy553 == nil { r.EncodeNil() } else { z.F.EncSliceBytesV(yy553, e) } // end block: if yy553 slice == nil } z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"FptrSliceFloat32\"") } else { r.EncodeString(`FptrSliceFloat32`) } z.EncWriteMapElemValue() if yyn44 { r.EncodeNil() } else { yy555 := *x.FptrSliceFloat32 if yy555 == nil { r.EncodeNil() } else { z.F.EncSliceFloat32V(yy555, e) } // end block: if yy555 slice == nil } z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"FptrSliceFloat64\"") } else { r.EncodeString(`FptrSliceFloat64`) } z.EncWriteMapElemValue() if yyn46 { r.EncodeNil() } else { yy557 := *x.FptrSliceFloat64 if yy557 == nil { r.EncodeNil() } else { z.F.EncSliceFloat64V(yy557, e) } // end block: if yy557 slice == nil } z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"FptrSliceInt\"") } else { r.EncodeString(`FptrSliceInt`) } z.EncWriteMapElemValue() if yyn52 { r.EncodeNil() } else { yy559 := *x.FptrSliceInt if yy559 == nil { r.EncodeNil() } else { z.F.EncSliceIntV(yy559, e) } // end block: if yy559 slice == nil } z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"FptrSliceInt32\"") } else { r.EncodeString(`FptrSliceInt32`) } z.EncWriteMapElemValue() if yyn54 { r.EncodeNil() } else { yy561 := *x.FptrSliceInt32 if yy561 == nil { r.EncodeNil() } else { z.F.EncSliceInt32V(yy561, e) } // end block: if yy561 slice == nil } z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"FptrSliceInt64\"") } else { r.EncodeString(`FptrSliceInt64`) } z.EncWriteMapElemValue() if yyn56 { r.EncodeNil() } else { yy563 := *x.FptrSliceInt64 if yy563 == nil { r.EncodeNil() } else { z.F.EncSliceInt64V(yy563, e) } // end block: if yy563 slice == nil } z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"FptrSliceIntf\"") } else { r.EncodeString(`FptrSliceIntf`) } z.EncWriteMapElemValue() if yyn38 { r.EncodeNil() } else { yy565 := *x.FptrSliceIntf if yy565 == nil { r.EncodeNil() } else { z.F.EncSliceIntfV(yy565, e) } // end block: if yy565 slice == nil } z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"FptrSliceString\"") } else { r.EncodeString(`FptrSliceString`) } z.EncWriteMapElemValue() if yyn40 { r.EncodeNil() } else { yy567 := *x.FptrSliceString if yy567 == nil { r.EncodeNil() } else { z.F.EncSliceStringV(yy567, e) } // end block: if yy567 slice == nil } z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"FptrSliceUint64\"") } else { r.EncodeString(`FptrSliceUint64`) } z.EncWriteMapElemValue() if yyn50 { r.EncodeNil() } else { yy569 := *x.FptrSliceUint64 if yy569 == nil { r.EncodeNil() } else { z.F.EncSliceUint64V(yy569, e) } // end block: if yy569 slice == nil } z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"FptrSliceUint8\"") } else { r.EncodeString(`FptrSliceUint8`) } z.EncWriteMapElemValue() if yyn48 { r.EncodeNil() } else { yy571 := *x.FptrSliceUint8 if yy571 == nil { r.EncodeNil() } else { r.EncodeStringBytesRaw([]byte(yy571)) } // end block: if yy571 slice == nil } z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"FptrString\"") } else { r.EncodeString(`FptrString`) } z.EncWriteMapElemValue() if yyn6 { r.EncodeNil() } else { yy573 := *x.FptrString r.EncodeString(string(yy573)) } z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"FptrUint\"") } else { r.EncodeString(`FptrUint`) } z.EncWriteMapElemValue() if yyn14 { r.EncodeNil() } else { yy575 := *x.FptrUint r.EncodeUint(uint64(yy575)) } z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"FptrUint16\"") } else { r.EncodeString(`FptrUint16`) } z.EncWriteMapElemValue() if yyn18 { r.EncodeNil() } else { yy577 := *x.FptrUint16 r.EncodeUint(uint64(yy577)) } z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"FptrUint32\"") } else { r.EncodeString(`FptrUint32`) } z.EncWriteMapElemValue() if yyn20 { r.EncodeNil() } else { yy579 := *x.FptrUint32 r.EncodeUint(uint64(yy579)) } z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"FptrUint64\"") } else { r.EncodeString(`FptrUint64`) } z.EncWriteMapElemValue() if yyn22 { r.EncodeNil() } else { yy581 := *x.FptrUint64 r.EncodeUint(uint64(yy581)) } z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"FptrUint8\"") } else { r.EncodeString(`FptrUint8`) } z.EncWriteMapElemValue() if yyn16 { r.EncodeNil() } else { yy583 := *x.FptrUint8 r.EncodeUint(uint64(yy583)) } z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"FptrUintptr\"") } else { r.EncodeString(`FptrUintptr`) } z.EncWriteMapElemValue() if yyn24 { r.EncodeNil() } else { yy585 := *x.FptrUintptr r.EncodeUint(uint64(yy585)) } } else { z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"FIntf\"") } else { r.EncodeString(`FIntf`) } z.EncWriteMapElemValue() z.EncFallback(x.FIntf) z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"FptrIntf\"") } else { r.EncodeString(`FptrIntf`) } z.EncWriteMapElemValue() if yyn4 { r.EncodeNil() } else { yy588 := *x.FptrIntf z.EncFallback(yy588) } z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"FString\"") } else { r.EncodeString(`FString`) } z.EncWriteMapElemValue() r.EncodeString(string(x.FString)) z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"FptrString\"") } else { r.EncodeString(`FptrString`) } z.EncWriteMapElemValue() if yyn6 { r.EncodeNil() } else { yy591 := *x.FptrString r.EncodeString(string(yy591)) } z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"FBytes\"") } else { r.EncodeString(`FBytes`) } z.EncWriteMapElemValue() if x.FBytes == nil { r.EncodeNil() } else { r.EncodeStringBytesRaw([]byte(x.FBytes)) } // end block: if x.FBytes slice == nil z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"FptrBytes\"") } else { r.EncodeString(`FptrBytes`) } z.EncWriteMapElemValue() if yyn8 { r.EncodeNil() } else { yy594 := *x.FptrBytes if yy594 == nil { r.EncodeNil() } else { r.EncodeStringBytesRaw([]byte(yy594)) } // end block: if yy594 slice == nil } z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"FFloat32\"") } else { r.EncodeString(`FFloat32`) } z.EncWriteMapElemValue() r.EncodeFloat32(float32(x.FFloat32)) z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"FptrFloat32\"") } else { r.EncodeString(`FptrFloat32`) } z.EncWriteMapElemValue() if yyn10 { r.EncodeNil() } else { yy597 := *x.FptrFloat32 r.EncodeFloat32(float32(yy597)) } z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"FFloat64\"") } else { r.EncodeString(`FFloat64`) } z.EncWriteMapElemValue() r.EncodeFloat64(float64(x.FFloat64)) z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"FptrFloat64\"") } else { r.EncodeString(`FptrFloat64`) } z.EncWriteMapElemValue() if yyn12 { r.EncodeNil() } else { yy600 := *x.FptrFloat64 r.EncodeFloat64(float64(yy600)) } z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"FUint\"") } else { r.EncodeString(`FUint`) } z.EncWriteMapElemValue() r.EncodeUint(uint64(x.FUint)) z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"FptrUint\"") } else { r.EncodeString(`FptrUint`) } z.EncWriteMapElemValue() if yyn14 { r.EncodeNil() } else { yy603 := *x.FptrUint r.EncodeUint(uint64(yy603)) } z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"FUint8\"") } else { r.EncodeString(`FUint8`) } z.EncWriteMapElemValue() r.EncodeUint(uint64(x.FUint8)) z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"FptrUint8\"") } else { r.EncodeString(`FptrUint8`) } z.EncWriteMapElemValue() if yyn16 { r.EncodeNil() } else { yy606 := *x.FptrUint8 r.EncodeUint(uint64(yy606)) } z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"FUint16\"") } else { r.EncodeString(`FUint16`) } z.EncWriteMapElemValue() r.EncodeUint(uint64(x.FUint16)) z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"FptrUint16\"") } else { r.EncodeString(`FptrUint16`) } z.EncWriteMapElemValue() if yyn18 { r.EncodeNil() } else { yy609 := *x.FptrUint16 r.EncodeUint(uint64(yy609)) } z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"FUint32\"") } else { r.EncodeString(`FUint32`) } z.EncWriteMapElemValue() r.EncodeUint(uint64(x.FUint32)) z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"FptrUint32\"") } else { r.EncodeString(`FptrUint32`) } z.EncWriteMapElemValue() if yyn20 { r.EncodeNil() } else { yy612 := *x.FptrUint32 r.EncodeUint(uint64(yy612)) } z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"FUint64\"") } else { r.EncodeString(`FUint64`) } z.EncWriteMapElemValue() r.EncodeUint(uint64(x.FUint64)) z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"FptrUint64\"") } else { r.EncodeString(`FptrUint64`) } z.EncWriteMapElemValue() if yyn22 { r.EncodeNil() } else { yy615 := *x.FptrUint64 r.EncodeUint(uint64(yy615)) } z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"FUintptr\"") } else { r.EncodeString(`FUintptr`) } z.EncWriteMapElemValue() r.EncodeUint(uint64(x.FUintptr)) z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"FptrUintptr\"") } else { r.EncodeString(`FptrUintptr`) } z.EncWriteMapElemValue() if yyn24 { r.EncodeNil() } else { yy618 := *x.FptrUintptr r.EncodeUint(uint64(yy618)) } z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"FInt\"") } else { r.EncodeString(`FInt`) } z.EncWriteMapElemValue() r.EncodeInt(int64(x.FInt)) z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"FptrInt\"") } else { r.EncodeString(`FptrInt`) } z.EncWriteMapElemValue() if yyn26 { r.EncodeNil() } else { yy621 := *x.FptrInt r.EncodeInt(int64(yy621)) } z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"FInt8\"") } else { r.EncodeString(`FInt8`) } z.EncWriteMapElemValue() r.EncodeInt(int64(x.FInt8)) z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"FptrInt8\"") } else { r.EncodeString(`FptrInt8`) } z.EncWriteMapElemValue() if yyn28 { r.EncodeNil() } else { yy624 := *x.FptrInt8 r.EncodeInt(int64(yy624)) } z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"FInt16\"") } else { r.EncodeString(`FInt16`) } z.EncWriteMapElemValue() r.EncodeInt(int64(x.FInt16)) z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"FptrInt16\"") } else { r.EncodeString(`FptrInt16`) } z.EncWriteMapElemValue() if yyn30 { r.EncodeNil() } else { yy627 := *x.FptrInt16 r.EncodeInt(int64(yy627)) } z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"FInt32\"") } else { r.EncodeString(`FInt32`) } z.EncWriteMapElemValue() r.EncodeInt(int64(x.FInt32)) z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"FptrInt32\"") } else { r.EncodeString(`FptrInt32`) } z.EncWriteMapElemValue() if yyn32 { r.EncodeNil() } else { yy630 := *x.FptrInt32 r.EncodeInt(int64(yy630)) } z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"FInt64\"") } else { r.EncodeString(`FInt64`) } z.EncWriteMapElemValue() r.EncodeInt(int64(x.FInt64)) z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"FptrInt64\"") } else { r.EncodeString(`FptrInt64`) } z.EncWriteMapElemValue() if yyn34 { r.EncodeNil() } else { yy633 := *x.FptrInt64 r.EncodeInt(int64(yy633)) } z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"FBool\"") } else { r.EncodeString(`FBool`) } z.EncWriteMapElemValue() r.EncodeBool(bool(x.FBool)) z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"FptrBool\"") } else { r.EncodeString(`FptrBool`) } z.EncWriteMapElemValue() if yyn36 { r.EncodeNil() } else { yy636 := *x.FptrBool r.EncodeBool(bool(yy636)) } z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"FSliceIntf\"") } else { r.EncodeString(`FSliceIntf`) } z.EncWriteMapElemValue() if x.FSliceIntf == nil { r.EncodeNil() } else { z.F.EncSliceIntfV(x.FSliceIntf, e) } // end block: if x.FSliceIntf slice == nil z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"FptrSliceIntf\"") } else { r.EncodeString(`FptrSliceIntf`) } z.EncWriteMapElemValue() if yyn38 { r.EncodeNil() } else { yy639 := *x.FptrSliceIntf if yy639 == nil { r.EncodeNil() } else { z.F.EncSliceIntfV(yy639, e) } // end block: if yy639 slice == nil } z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"FSliceString\"") } else { r.EncodeString(`FSliceString`) } z.EncWriteMapElemValue() if x.FSliceString == nil { r.EncodeNil() } else { z.F.EncSliceStringV(x.FSliceString, e) } // end block: if x.FSliceString slice == nil z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"FptrSliceString\"") } else { r.EncodeString(`FptrSliceString`) } z.EncWriteMapElemValue() if yyn40 { r.EncodeNil() } else { yy642 := *x.FptrSliceString if yy642 == nil { r.EncodeNil() } else { z.F.EncSliceStringV(yy642, e) } // end block: if yy642 slice == nil } z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"FSliceBytes\"") } else { r.EncodeString(`FSliceBytes`) } z.EncWriteMapElemValue() if x.FSliceBytes == nil { r.EncodeNil() } else { z.F.EncSliceBytesV(x.FSliceBytes, e) } // end block: if x.FSliceBytes slice == nil z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"FptrSliceBytes\"") } else { r.EncodeString(`FptrSliceBytes`) } z.EncWriteMapElemValue() if yyn42 { r.EncodeNil() } else { yy645 := *x.FptrSliceBytes if yy645 == nil { r.EncodeNil() } else { z.F.EncSliceBytesV(yy645, e) } // end block: if yy645 slice == nil } z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"FSliceFloat32\"") } else { r.EncodeString(`FSliceFloat32`) } z.EncWriteMapElemValue() if x.FSliceFloat32 == nil { r.EncodeNil() } else { z.F.EncSliceFloat32V(x.FSliceFloat32, e) } // end block: if x.FSliceFloat32 slice == nil z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"FptrSliceFloat32\"") } else { r.EncodeString(`FptrSliceFloat32`) } z.EncWriteMapElemValue() if yyn44 { r.EncodeNil() } else { yy648 := *x.FptrSliceFloat32 if yy648 == nil { r.EncodeNil() } else { z.F.EncSliceFloat32V(yy648, e) } // end block: if yy648 slice == nil } z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"FSliceFloat64\"") } else { r.EncodeString(`FSliceFloat64`) } z.EncWriteMapElemValue() if x.FSliceFloat64 == nil { r.EncodeNil() } else { z.F.EncSliceFloat64V(x.FSliceFloat64, e) } // end block: if x.FSliceFloat64 slice == nil z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"FptrSliceFloat64\"") } else { r.EncodeString(`FptrSliceFloat64`) } z.EncWriteMapElemValue() if yyn46 { r.EncodeNil() } else { yy651 := *x.FptrSliceFloat64 if yy651 == nil { r.EncodeNil() } else { z.F.EncSliceFloat64V(yy651, e) } // end block: if yy651 slice == nil } z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"FSliceUint8\"") } else { r.EncodeString(`FSliceUint8`) } z.EncWriteMapElemValue() if x.FSliceUint8 == nil { r.EncodeNil() } else { r.EncodeStringBytesRaw([]byte(x.FSliceUint8)) } // end block: if x.FSliceUint8 slice == nil z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"FptrSliceUint8\"") } else { r.EncodeString(`FptrSliceUint8`) } z.EncWriteMapElemValue() if yyn48 { r.EncodeNil() } else { yy654 := *x.FptrSliceUint8 if yy654 == nil { r.EncodeNil() } else { r.EncodeStringBytesRaw([]byte(yy654)) } // end block: if yy654 slice == nil } z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"FSliceUint64\"") } else { r.EncodeString(`FSliceUint64`) } z.EncWriteMapElemValue() if x.FSliceUint64 == nil { r.EncodeNil() } else { z.F.EncSliceUint64V(x.FSliceUint64, e) } // end block: if x.FSliceUint64 slice == nil z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"FptrSliceUint64\"") } else { r.EncodeString(`FptrSliceUint64`) } z.EncWriteMapElemValue() if yyn50 { r.EncodeNil() } else { yy657 := *x.FptrSliceUint64 if yy657 == nil { r.EncodeNil() } else { z.F.EncSliceUint64V(yy657, e) } // end block: if yy657 slice == nil } z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"FSliceInt\"") } else { r.EncodeString(`FSliceInt`) } z.EncWriteMapElemValue() if x.FSliceInt == nil { r.EncodeNil() } else { z.F.EncSliceIntV(x.FSliceInt, e) } // end block: if x.FSliceInt slice == nil z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"FptrSliceInt\"") } else { r.EncodeString(`FptrSliceInt`) } z.EncWriteMapElemValue() if yyn52 { r.EncodeNil() } else { yy660 := *x.FptrSliceInt if yy660 == nil { r.EncodeNil() } else { z.F.EncSliceIntV(yy660, e) } // end block: if yy660 slice == nil } z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"FSliceInt32\"") } else { r.EncodeString(`FSliceInt32`) } z.EncWriteMapElemValue() if x.FSliceInt32 == nil { r.EncodeNil() } else { z.F.EncSliceInt32V(x.FSliceInt32, e) } // end block: if x.FSliceInt32 slice == nil z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"FptrSliceInt32\"") } else { r.EncodeString(`FptrSliceInt32`) } z.EncWriteMapElemValue() if yyn54 { r.EncodeNil() } else { yy663 := *x.FptrSliceInt32 if yy663 == nil { r.EncodeNil() } else { z.F.EncSliceInt32V(yy663, e) } // end block: if yy663 slice == nil } z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"FSliceInt64\"") } else { r.EncodeString(`FSliceInt64`) } z.EncWriteMapElemValue() if x.FSliceInt64 == nil { r.EncodeNil() } else { z.F.EncSliceInt64V(x.FSliceInt64, e) } // end block: if x.FSliceInt64 slice == nil z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"FptrSliceInt64\"") } else { r.EncodeString(`FptrSliceInt64`) } z.EncWriteMapElemValue() if yyn56 { r.EncodeNil() } else { yy666 := *x.FptrSliceInt64 if yy666 == nil { r.EncodeNil() } else { z.F.EncSliceInt64V(yy666, e) } // end block: if yy666 slice == nil } z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"FSliceBool\"") } else { r.EncodeString(`FSliceBool`) } z.EncWriteMapElemValue() if x.FSliceBool == nil { r.EncodeNil() } else { z.F.EncSliceBoolV(x.FSliceBool, e) } // end block: if x.FSliceBool slice == nil z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"FptrSliceBool\"") } else { r.EncodeString(`FptrSliceBool`) } z.EncWriteMapElemValue() if yyn58 { r.EncodeNil() } else { yy669 := *x.FptrSliceBool if yy669 == nil { r.EncodeNil() } else { z.F.EncSliceBoolV(yy669, e) } // end block: if yy669 slice == nil } z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"FMapStringIntf\"") } else { r.EncodeString(`FMapStringIntf`) } z.EncWriteMapElemValue() if x.FMapStringIntf == nil { r.EncodeNil() } else { z.F.EncMapStringIntfV(x.FMapStringIntf, e) } // end block: if x.FMapStringIntf map == nil z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"FptrMapStringIntf\"") } else { r.EncodeString(`FptrMapStringIntf`) } z.EncWriteMapElemValue() if yyn60 { r.EncodeNil() } else { yy672 := *x.FptrMapStringIntf if yy672 == nil { r.EncodeNil() } else { z.F.EncMapStringIntfV(yy672, e) } // end block: if yy672 map == nil } z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"FMapStringString\"") } else { r.EncodeString(`FMapStringString`) } z.EncWriteMapElemValue() if x.FMapStringString == nil { r.EncodeNil() } else { z.F.EncMapStringStringV(x.FMapStringString, e) } // end block: if x.FMapStringString map == nil z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"FptrMapStringString\"") } else { r.EncodeString(`FptrMapStringString`) } z.EncWriteMapElemValue() if yyn62 { r.EncodeNil() } else { yy675 := *x.FptrMapStringString if yy675 == nil { r.EncodeNil() } else { z.F.EncMapStringStringV(yy675, e) } // end block: if yy675 map == nil } z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"FMapStringBytes\"") } else { r.EncodeString(`FMapStringBytes`) } z.EncWriteMapElemValue() if x.FMapStringBytes == nil { r.EncodeNil() } else { z.F.EncMapStringBytesV(x.FMapStringBytes, e) } // end block: if x.FMapStringBytes map == nil z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"FptrMapStringBytes\"") } else { r.EncodeString(`FptrMapStringBytes`) } z.EncWriteMapElemValue() if yyn64 { r.EncodeNil() } else { yy678 := *x.FptrMapStringBytes if yy678 == nil { r.EncodeNil() } else { z.F.EncMapStringBytesV(yy678, e) } // end block: if yy678 map == nil } z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"FMapStringUint8\"") } else { r.EncodeString(`FMapStringUint8`) } z.EncWriteMapElemValue() if x.FMapStringUint8 == nil { r.EncodeNil() } else { z.F.EncMapStringUint8V(x.FMapStringUint8, e) } // end block: if x.FMapStringUint8 map == nil z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"FptrMapStringUint8\"") } else { r.EncodeString(`FptrMapStringUint8`) } z.EncWriteMapElemValue() if yyn66 { r.EncodeNil() } else { yy681 := *x.FptrMapStringUint8 if yy681 == nil { r.EncodeNil() } else { z.F.EncMapStringUint8V(yy681, e) } // end block: if yy681 map == nil } z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"FMapStringUint64\"") } else { r.EncodeString(`FMapStringUint64`) } z.EncWriteMapElemValue() if x.FMapStringUint64 == nil { r.EncodeNil() } else { z.F.EncMapStringUint64V(x.FMapStringUint64, e) } // end block: if x.FMapStringUint64 map == nil z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"FptrMapStringUint64\"") } else { r.EncodeString(`FptrMapStringUint64`) } z.EncWriteMapElemValue() if yyn68 { r.EncodeNil() } else { yy684 := *x.FptrMapStringUint64 if yy684 == nil { r.EncodeNil() } else { z.F.EncMapStringUint64V(yy684, e) } // end block: if yy684 map == nil } z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"FMapStringInt\"") } else { r.EncodeString(`FMapStringInt`) } z.EncWriteMapElemValue() if x.FMapStringInt == nil { r.EncodeNil() } else { z.F.EncMapStringIntV(x.FMapStringInt, e) } // end block: if x.FMapStringInt map == nil z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"FptrMapStringInt\"") } else { r.EncodeString(`FptrMapStringInt`) } z.EncWriteMapElemValue() if yyn70 { r.EncodeNil() } else { yy687 := *x.FptrMapStringInt if yy687 == nil { r.EncodeNil() } else { z.F.EncMapStringIntV(yy687, e) } // end block: if yy687 map == nil } z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"FMapStringInt32\"") } else { r.EncodeString(`FMapStringInt32`) } z.EncWriteMapElemValue() if x.FMapStringInt32 == nil { r.EncodeNil() } else { z.F.EncMapStringInt32V(x.FMapStringInt32, e) } // end block: if x.FMapStringInt32 map == nil z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"FptrMapStringInt32\"") } else { r.EncodeString(`FptrMapStringInt32`) } z.EncWriteMapElemValue() if yyn72 { r.EncodeNil() } else { yy690 := *x.FptrMapStringInt32 if yy690 == nil { r.EncodeNil() } else { z.F.EncMapStringInt32V(yy690, e) } // end block: if yy690 map == nil } z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"FMapStringFloat64\"") } else { r.EncodeString(`FMapStringFloat64`) } z.EncWriteMapElemValue() if x.FMapStringFloat64 == nil { r.EncodeNil() } else { z.F.EncMapStringFloat64V(x.FMapStringFloat64, e) } // end block: if x.FMapStringFloat64 map == nil z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"FptrMapStringFloat64\"") } else { r.EncodeString(`FptrMapStringFloat64`) } z.EncWriteMapElemValue() if yyn74 { r.EncodeNil() } else { yy693 := *x.FptrMapStringFloat64 if yy693 == nil { r.EncodeNil() } else { z.F.EncMapStringFloat64V(yy693, e) } // end block: if yy693 map == nil } z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"FMapStringBool\"") } else { r.EncodeString(`FMapStringBool`) } z.EncWriteMapElemValue() if x.FMapStringBool == nil { r.EncodeNil() } else { z.F.EncMapStringBoolV(x.FMapStringBool, e) } // end block: if x.FMapStringBool map == nil z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"FptrMapStringBool\"") } else { r.EncodeString(`FptrMapStringBool`) } z.EncWriteMapElemValue() if yyn76 { r.EncodeNil() } else { yy696 := *x.FptrMapStringBool if yy696 == nil { r.EncodeNil() } else { z.F.EncMapStringBoolV(yy696, e) } // end block: if yy696 map == nil } z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"FMapUint8Intf\"") } else { r.EncodeString(`FMapUint8Intf`) } z.EncWriteMapElemValue() if x.FMapUint8Intf == nil { r.EncodeNil() } else { z.F.EncMapUint8IntfV(x.FMapUint8Intf, e) } // end block: if x.FMapUint8Intf map == nil z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"FptrMapUint8Intf\"") } else { r.EncodeString(`FptrMapUint8Intf`) } z.EncWriteMapElemValue() if yyn78 { r.EncodeNil() } else { yy699 := *x.FptrMapUint8Intf if yy699 == nil { r.EncodeNil() } else { z.F.EncMapUint8IntfV(yy699, e) } // end block: if yy699 map == nil } z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"FMapUint8String\"") } else { r.EncodeString(`FMapUint8String`) } z.EncWriteMapElemValue() if x.FMapUint8String == nil { r.EncodeNil() } else { z.F.EncMapUint8StringV(x.FMapUint8String, e) } // end block: if x.FMapUint8String map == nil z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"FptrMapUint8String\"") } else { r.EncodeString(`FptrMapUint8String`) } z.EncWriteMapElemValue() if yyn80 { r.EncodeNil() } else { yy702 := *x.FptrMapUint8String if yy702 == nil { r.EncodeNil() } else { z.F.EncMapUint8StringV(yy702, e) } // end block: if yy702 map == nil } z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"FMapUint8Bytes\"") } else { r.EncodeString(`FMapUint8Bytes`) } z.EncWriteMapElemValue() if x.FMapUint8Bytes == nil { r.EncodeNil() } else { z.F.EncMapUint8BytesV(x.FMapUint8Bytes, e) } // end block: if x.FMapUint8Bytes map == nil z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"FptrMapUint8Bytes\"") } else { r.EncodeString(`FptrMapUint8Bytes`) } z.EncWriteMapElemValue() if yyn82 { r.EncodeNil() } else { yy705 := *x.FptrMapUint8Bytes if yy705 == nil { r.EncodeNil() } else { z.F.EncMapUint8BytesV(yy705, e) } // end block: if yy705 map == nil } z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"FMapUint8Uint8\"") } else { r.EncodeString(`FMapUint8Uint8`) } z.EncWriteMapElemValue() if x.FMapUint8Uint8 == nil { r.EncodeNil() } else { z.F.EncMapUint8Uint8V(x.FMapUint8Uint8, e) } // end block: if x.FMapUint8Uint8 map == nil z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"FptrMapUint8Uint8\"") } else { r.EncodeString(`FptrMapUint8Uint8`) } z.EncWriteMapElemValue() if yyn84 { r.EncodeNil() } else { yy708 := *x.FptrMapUint8Uint8 if yy708 == nil { r.EncodeNil() } else { z.F.EncMapUint8Uint8V(yy708, e) } // end block: if yy708 map == nil } z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"FMapUint8Uint64\"") } else { r.EncodeString(`FMapUint8Uint64`) } z.EncWriteMapElemValue() if x.FMapUint8Uint64 == nil { r.EncodeNil() } else { z.F.EncMapUint8Uint64V(x.FMapUint8Uint64, e) } // end block: if x.FMapUint8Uint64 map == nil z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"FptrMapUint8Uint64\"") } else { r.EncodeString(`FptrMapUint8Uint64`) } z.EncWriteMapElemValue() if yyn86 { r.EncodeNil() } else { yy711 := *x.FptrMapUint8Uint64 if yy711 == nil { r.EncodeNil() } else { z.F.EncMapUint8Uint64V(yy711, e) } // end block: if yy711 map == nil } z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"FMapUint8Int\"") } else { r.EncodeString(`FMapUint8Int`) } z.EncWriteMapElemValue() if x.FMapUint8Int == nil { r.EncodeNil() } else { z.F.EncMapUint8IntV(x.FMapUint8Int, e) } // end block: if x.FMapUint8Int map == nil z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"FptrMapUint8Int\"") } else { r.EncodeString(`FptrMapUint8Int`) } z.EncWriteMapElemValue() if yyn88 { r.EncodeNil() } else { yy714 := *x.FptrMapUint8Int if yy714 == nil { r.EncodeNil() } else { z.F.EncMapUint8IntV(yy714, e) } // end block: if yy714 map == nil } z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"FMapUint8Int32\"") } else { r.EncodeString(`FMapUint8Int32`) } z.EncWriteMapElemValue() if x.FMapUint8Int32 == nil { r.EncodeNil() } else { z.F.EncMapUint8Int32V(x.FMapUint8Int32, e) } // end block: if x.FMapUint8Int32 map == nil z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"FptrMapUint8Int32\"") } else { r.EncodeString(`FptrMapUint8Int32`) } z.EncWriteMapElemValue() if yyn90 { r.EncodeNil() } else { yy717 := *x.FptrMapUint8Int32 if yy717 == nil { r.EncodeNil() } else { z.F.EncMapUint8Int32V(yy717, e) } // end block: if yy717 map == nil } z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"FMapUint8Float64\"") } else { r.EncodeString(`FMapUint8Float64`) } z.EncWriteMapElemValue() if x.FMapUint8Float64 == nil { r.EncodeNil() } else { z.F.EncMapUint8Float64V(x.FMapUint8Float64, e) } // end block: if x.FMapUint8Float64 map == nil z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"FptrMapUint8Float64\"") } else { r.EncodeString(`FptrMapUint8Float64`) } z.EncWriteMapElemValue() if yyn92 { r.EncodeNil() } else { yy720 := *x.FptrMapUint8Float64 if yy720 == nil { r.EncodeNil() } else { z.F.EncMapUint8Float64V(yy720, e) } // end block: if yy720 map == nil } z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"FMapUint8Bool\"") } else { r.EncodeString(`FMapUint8Bool`) } z.EncWriteMapElemValue() if x.FMapUint8Bool == nil { r.EncodeNil() } else { z.F.EncMapUint8BoolV(x.FMapUint8Bool, e) } // end block: if x.FMapUint8Bool map == nil z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"FptrMapUint8Bool\"") } else { r.EncodeString(`FptrMapUint8Bool`) } z.EncWriteMapElemValue() if yyn94 { r.EncodeNil() } else { yy723 := *x.FptrMapUint8Bool if yy723 == nil { r.EncodeNil() } else { z.F.EncMapUint8BoolV(yy723, e) } // end block: if yy723 map == nil } z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"FMapUint64Intf\"") } else { r.EncodeString(`FMapUint64Intf`) } z.EncWriteMapElemValue() if x.FMapUint64Intf == nil { r.EncodeNil() } else { z.F.EncMapUint64IntfV(x.FMapUint64Intf, e) } // end block: if x.FMapUint64Intf map == nil z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"FptrMapUint64Intf\"") } else { r.EncodeString(`FptrMapUint64Intf`) } z.EncWriteMapElemValue() if yyn96 { r.EncodeNil() } else { yy726 := *x.FptrMapUint64Intf if yy726 == nil { r.EncodeNil() } else { z.F.EncMapUint64IntfV(yy726, e) } // end block: if yy726 map == nil } z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"FMapUint64String\"") } else { r.EncodeString(`FMapUint64String`) } z.EncWriteMapElemValue() if x.FMapUint64String == nil { r.EncodeNil() } else { z.F.EncMapUint64StringV(x.FMapUint64String, e) } // end block: if x.FMapUint64String map == nil z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"FptrMapUint64String\"") } else { r.EncodeString(`FptrMapUint64String`) } z.EncWriteMapElemValue() if yyn98 { r.EncodeNil() } else { yy729 := *x.FptrMapUint64String if yy729 == nil { r.EncodeNil() } else { z.F.EncMapUint64StringV(yy729, e) } // end block: if yy729 map == nil } z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"FMapUint64Bytes\"") } else { r.EncodeString(`FMapUint64Bytes`) } z.EncWriteMapElemValue() if x.FMapUint64Bytes == nil { r.EncodeNil() } else { z.F.EncMapUint64BytesV(x.FMapUint64Bytes, e) } // end block: if x.FMapUint64Bytes map == nil z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"FptrMapUint64Bytes\"") } else { r.EncodeString(`FptrMapUint64Bytes`) } z.EncWriteMapElemValue() if yyn100 { r.EncodeNil() } else { yy732 := *x.FptrMapUint64Bytes if yy732 == nil { r.EncodeNil() } else { z.F.EncMapUint64BytesV(yy732, e) } // end block: if yy732 map == nil } z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"FMapUint64Uint8\"") } else { r.EncodeString(`FMapUint64Uint8`) } z.EncWriteMapElemValue() if x.FMapUint64Uint8 == nil { r.EncodeNil() } else { z.F.EncMapUint64Uint8V(x.FMapUint64Uint8, e) } // end block: if x.FMapUint64Uint8 map == nil z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"FptrMapUint64Uint8\"") } else { r.EncodeString(`FptrMapUint64Uint8`) } z.EncWriteMapElemValue() if yyn102 { r.EncodeNil() } else { yy735 := *x.FptrMapUint64Uint8 if yy735 == nil { r.EncodeNil() } else { z.F.EncMapUint64Uint8V(yy735, e) } // end block: if yy735 map == nil } z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"FMapUint64Uint64\"") } else { r.EncodeString(`FMapUint64Uint64`) } z.EncWriteMapElemValue() if x.FMapUint64Uint64 == nil { r.EncodeNil() } else { z.F.EncMapUint64Uint64V(x.FMapUint64Uint64, e) } // end block: if x.FMapUint64Uint64 map == nil z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"FptrMapUint64Uint64\"") } else { r.EncodeString(`FptrMapUint64Uint64`) } z.EncWriteMapElemValue() if yyn104 { r.EncodeNil() } else { yy738 := *x.FptrMapUint64Uint64 if yy738 == nil { r.EncodeNil() } else { z.F.EncMapUint64Uint64V(yy738, e) } // end block: if yy738 map == nil } z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"FMapUint64Int\"") } else { r.EncodeString(`FMapUint64Int`) } z.EncWriteMapElemValue() if x.FMapUint64Int == nil { r.EncodeNil() } else { z.F.EncMapUint64IntV(x.FMapUint64Int, e) } // end block: if x.FMapUint64Int map == nil z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"FptrMapUint64Int\"") } else { r.EncodeString(`FptrMapUint64Int`) } z.EncWriteMapElemValue() if yyn106 { r.EncodeNil() } else { yy741 := *x.FptrMapUint64Int if yy741 == nil { r.EncodeNil() } else { z.F.EncMapUint64IntV(yy741, e) } // end block: if yy741 map == nil } z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"FMapUint64Int32\"") } else { r.EncodeString(`FMapUint64Int32`) } z.EncWriteMapElemValue() if x.FMapUint64Int32 == nil { r.EncodeNil() } else { z.F.EncMapUint64Int32V(x.FMapUint64Int32, e) } // end block: if x.FMapUint64Int32 map == nil z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"FptrMapUint64Int32\"") } else { r.EncodeString(`FptrMapUint64Int32`) } z.EncWriteMapElemValue() if yyn108 { r.EncodeNil() } else { yy744 := *x.FptrMapUint64Int32 if yy744 == nil { r.EncodeNil() } else { z.F.EncMapUint64Int32V(yy744, e) } // end block: if yy744 map == nil } z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"FMapUint64Float64\"") } else { r.EncodeString(`FMapUint64Float64`) } z.EncWriteMapElemValue() if x.FMapUint64Float64 == nil { r.EncodeNil() } else { z.F.EncMapUint64Float64V(x.FMapUint64Float64, e) } // end block: if x.FMapUint64Float64 map == nil z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"FptrMapUint64Float64\"") } else { r.EncodeString(`FptrMapUint64Float64`) } z.EncWriteMapElemValue() if yyn110 { r.EncodeNil() } else { yy747 := *x.FptrMapUint64Float64 if yy747 == nil { r.EncodeNil() } else { z.F.EncMapUint64Float64V(yy747, e) } // end block: if yy747 map == nil } z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"FMapUint64Bool\"") } else { r.EncodeString(`FMapUint64Bool`) } z.EncWriteMapElemValue() if x.FMapUint64Bool == nil { r.EncodeNil() } else { z.F.EncMapUint64BoolV(x.FMapUint64Bool, e) } // end block: if x.FMapUint64Bool map == nil z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"FptrMapUint64Bool\"") } else { r.EncodeString(`FptrMapUint64Bool`) } z.EncWriteMapElemValue() if yyn112 { r.EncodeNil() } else { yy750 := *x.FptrMapUint64Bool if yy750 == nil { r.EncodeNil() } else { z.F.EncMapUint64BoolV(yy750, e) } // end block: if yy750 map == nil } z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"FMapIntIntf\"") } else { r.EncodeString(`FMapIntIntf`) } z.EncWriteMapElemValue() if x.FMapIntIntf == nil { r.EncodeNil() } else { z.F.EncMapIntIntfV(x.FMapIntIntf, e) } // end block: if x.FMapIntIntf map == nil z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"FptrMapIntIntf\"") } else { r.EncodeString(`FptrMapIntIntf`) } z.EncWriteMapElemValue() if yyn114 { r.EncodeNil() } else { yy753 := *x.FptrMapIntIntf if yy753 == nil { r.EncodeNil() } else { z.F.EncMapIntIntfV(yy753, e) } // end block: if yy753 map == nil } z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"FMapIntString\"") } else { r.EncodeString(`FMapIntString`) } z.EncWriteMapElemValue() if x.FMapIntString == nil { r.EncodeNil() } else { z.F.EncMapIntStringV(x.FMapIntString, e) } // end block: if x.FMapIntString map == nil z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"FptrMapIntString\"") } else { r.EncodeString(`FptrMapIntString`) } z.EncWriteMapElemValue() if yyn116 { r.EncodeNil() } else { yy756 := *x.FptrMapIntString if yy756 == nil { r.EncodeNil() } else { z.F.EncMapIntStringV(yy756, e) } // end block: if yy756 map == nil } z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"FMapIntBytes\"") } else { r.EncodeString(`FMapIntBytes`) } z.EncWriteMapElemValue() if x.FMapIntBytes == nil { r.EncodeNil() } else { z.F.EncMapIntBytesV(x.FMapIntBytes, e) } // end block: if x.FMapIntBytes map == nil z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"FptrMapIntBytes\"") } else { r.EncodeString(`FptrMapIntBytes`) } z.EncWriteMapElemValue() if yyn118 { r.EncodeNil() } else { yy759 := *x.FptrMapIntBytes if yy759 == nil { r.EncodeNil() } else { z.F.EncMapIntBytesV(yy759, e) } // end block: if yy759 map == nil } z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"FMapIntUint8\"") } else { r.EncodeString(`FMapIntUint8`) } z.EncWriteMapElemValue() if x.FMapIntUint8 == nil { r.EncodeNil() } else { z.F.EncMapIntUint8V(x.FMapIntUint8, e) } // end block: if x.FMapIntUint8 map == nil z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"FptrMapIntUint8\"") } else { r.EncodeString(`FptrMapIntUint8`) } z.EncWriteMapElemValue() if yyn120 { r.EncodeNil() } else { yy762 := *x.FptrMapIntUint8 if yy762 == nil { r.EncodeNil() } else { z.F.EncMapIntUint8V(yy762, e) } // end block: if yy762 map == nil } z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"FMapIntUint64\"") } else { r.EncodeString(`FMapIntUint64`) } z.EncWriteMapElemValue() if x.FMapIntUint64 == nil { r.EncodeNil() } else { z.F.EncMapIntUint64V(x.FMapIntUint64, e) } // end block: if x.FMapIntUint64 map == nil z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"FptrMapIntUint64\"") } else { r.EncodeString(`FptrMapIntUint64`) } z.EncWriteMapElemValue() if yyn122 { r.EncodeNil() } else { yy765 := *x.FptrMapIntUint64 if yy765 == nil { r.EncodeNil() } else { z.F.EncMapIntUint64V(yy765, e) } // end block: if yy765 map == nil } z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"FMapIntInt\"") } else { r.EncodeString(`FMapIntInt`) } z.EncWriteMapElemValue() if x.FMapIntInt == nil { r.EncodeNil() } else { z.F.EncMapIntIntV(x.FMapIntInt, e) } // end block: if x.FMapIntInt map == nil z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"FptrMapIntInt\"") } else { r.EncodeString(`FptrMapIntInt`) } z.EncWriteMapElemValue() if yyn124 { r.EncodeNil() } else { yy768 := *x.FptrMapIntInt if yy768 == nil { r.EncodeNil() } else { z.F.EncMapIntIntV(yy768, e) } // end block: if yy768 map == nil } z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"FMapIntInt32\"") } else { r.EncodeString(`FMapIntInt32`) } z.EncWriteMapElemValue() if x.FMapIntInt32 == nil { r.EncodeNil() } else { z.F.EncMapIntInt32V(x.FMapIntInt32, e) } // end block: if x.FMapIntInt32 map == nil z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"FptrMapIntInt32\"") } else { r.EncodeString(`FptrMapIntInt32`) } z.EncWriteMapElemValue() if yyn126 { r.EncodeNil() } else { yy771 := *x.FptrMapIntInt32 if yy771 == nil { r.EncodeNil() } else { z.F.EncMapIntInt32V(yy771, e) } // end block: if yy771 map == nil } z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"FMapIntFloat64\"") } else { r.EncodeString(`FMapIntFloat64`) } z.EncWriteMapElemValue() if x.FMapIntFloat64 == nil { r.EncodeNil() } else { z.F.EncMapIntFloat64V(x.FMapIntFloat64, e) } // end block: if x.FMapIntFloat64 map == nil z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"FptrMapIntFloat64\"") } else { r.EncodeString(`FptrMapIntFloat64`) } z.EncWriteMapElemValue() if yyn128 { r.EncodeNil() } else { yy774 := *x.FptrMapIntFloat64 if yy774 == nil { r.EncodeNil() } else { z.F.EncMapIntFloat64V(yy774, e) } // end block: if yy774 map == nil } z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"FMapIntBool\"") } else { r.EncodeString(`FMapIntBool`) } z.EncWriteMapElemValue() if x.FMapIntBool == nil { r.EncodeNil() } else { z.F.EncMapIntBoolV(x.FMapIntBool, e) } // end block: if x.FMapIntBool map == nil z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"FptrMapIntBool\"") } else { r.EncodeString(`FptrMapIntBool`) } z.EncWriteMapElemValue() if yyn130 { r.EncodeNil() } else { yy777 := *x.FptrMapIntBool if yy777 == nil { r.EncodeNil() } else { z.F.EncMapIntBoolV(yy777, e) } // end block: if yy777 map == nil } z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"FMapInt32Intf\"") } else { r.EncodeString(`FMapInt32Intf`) } z.EncWriteMapElemValue() if x.FMapInt32Intf == nil { r.EncodeNil() } else { z.F.EncMapInt32IntfV(x.FMapInt32Intf, e) } // end block: if x.FMapInt32Intf map == nil z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"FptrMapInt32Intf\"") } else { r.EncodeString(`FptrMapInt32Intf`) } z.EncWriteMapElemValue() if yyn132 { r.EncodeNil() } else { yy780 := *x.FptrMapInt32Intf if yy780 == nil { r.EncodeNil() } else { z.F.EncMapInt32IntfV(yy780, e) } // end block: if yy780 map == nil } z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"FMapInt32String\"") } else { r.EncodeString(`FMapInt32String`) } z.EncWriteMapElemValue() if x.FMapInt32String == nil { r.EncodeNil() } else { z.F.EncMapInt32StringV(x.FMapInt32String, e) } // end block: if x.FMapInt32String map == nil z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"FptrMapInt32String\"") } else { r.EncodeString(`FptrMapInt32String`) } z.EncWriteMapElemValue() if yyn134 { r.EncodeNil() } else { yy783 := *x.FptrMapInt32String if yy783 == nil { r.EncodeNil() } else { z.F.EncMapInt32StringV(yy783, e) } // end block: if yy783 map == nil } z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"FMapInt32Bytes\"") } else { r.EncodeString(`FMapInt32Bytes`) } z.EncWriteMapElemValue() if x.FMapInt32Bytes == nil { r.EncodeNil() } else { z.F.EncMapInt32BytesV(x.FMapInt32Bytes, e) } // end block: if x.FMapInt32Bytes map == nil z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"FptrMapInt32Bytes\"") } else { r.EncodeString(`FptrMapInt32Bytes`) } z.EncWriteMapElemValue() if yyn136 { r.EncodeNil() } else { yy786 := *x.FptrMapInt32Bytes if yy786 == nil { r.EncodeNil() } else { z.F.EncMapInt32BytesV(yy786, e) } // end block: if yy786 map == nil } z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"FMapInt32Uint8\"") } else { r.EncodeString(`FMapInt32Uint8`) } z.EncWriteMapElemValue() if x.FMapInt32Uint8 == nil { r.EncodeNil() } else { z.F.EncMapInt32Uint8V(x.FMapInt32Uint8, e) } // end block: if x.FMapInt32Uint8 map == nil z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"FptrMapInt32Uint8\"") } else { r.EncodeString(`FptrMapInt32Uint8`) } z.EncWriteMapElemValue() if yyn138 { r.EncodeNil() } else { yy789 := *x.FptrMapInt32Uint8 if yy789 == nil { r.EncodeNil() } else { z.F.EncMapInt32Uint8V(yy789, e) } // end block: if yy789 map == nil } z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"FMapInt32Uint64\"") } else { r.EncodeString(`FMapInt32Uint64`) } z.EncWriteMapElemValue() if x.FMapInt32Uint64 == nil { r.EncodeNil() } else { z.F.EncMapInt32Uint64V(x.FMapInt32Uint64, e) } // end block: if x.FMapInt32Uint64 map == nil z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"FptrMapInt32Uint64\"") } else { r.EncodeString(`FptrMapInt32Uint64`) } z.EncWriteMapElemValue() if yyn140 { r.EncodeNil() } else { yy792 := *x.FptrMapInt32Uint64 if yy792 == nil { r.EncodeNil() } else { z.F.EncMapInt32Uint64V(yy792, e) } // end block: if yy792 map == nil } z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"FMapInt32Int\"") } else { r.EncodeString(`FMapInt32Int`) } z.EncWriteMapElemValue() if x.FMapInt32Int == nil { r.EncodeNil() } else { z.F.EncMapInt32IntV(x.FMapInt32Int, e) } // end block: if x.FMapInt32Int map == nil z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"FptrMapInt32Int\"") } else { r.EncodeString(`FptrMapInt32Int`) } z.EncWriteMapElemValue() if yyn142 { r.EncodeNil() } else { yy795 := *x.FptrMapInt32Int if yy795 == nil { r.EncodeNil() } else { z.F.EncMapInt32IntV(yy795, e) } // end block: if yy795 map == nil } z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"FMapInt32Int32\"") } else { r.EncodeString(`FMapInt32Int32`) } z.EncWriteMapElemValue() if x.FMapInt32Int32 == nil { r.EncodeNil() } else { z.F.EncMapInt32Int32V(x.FMapInt32Int32, e) } // end block: if x.FMapInt32Int32 map == nil z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"FptrMapInt32Int32\"") } else { r.EncodeString(`FptrMapInt32Int32`) } z.EncWriteMapElemValue() if yyn144 { r.EncodeNil() } else { yy798 := *x.FptrMapInt32Int32 if yy798 == nil { r.EncodeNil() } else { z.F.EncMapInt32Int32V(yy798, e) } // end block: if yy798 map == nil } z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"FMapInt32Float64\"") } else { r.EncodeString(`FMapInt32Float64`) } z.EncWriteMapElemValue() if x.FMapInt32Float64 == nil { r.EncodeNil() } else { z.F.EncMapInt32Float64V(x.FMapInt32Float64, e) } // end block: if x.FMapInt32Float64 map == nil z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"FptrMapInt32Float64\"") } else { r.EncodeString(`FptrMapInt32Float64`) } z.EncWriteMapElemValue() if yyn146 { r.EncodeNil() } else { yy801 := *x.FptrMapInt32Float64 if yy801 == nil { r.EncodeNil() } else { z.F.EncMapInt32Float64V(yy801, e) } // end block: if yy801 map == nil } z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"FMapInt32Bool\"") } else { r.EncodeString(`FMapInt32Bool`) } z.EncWriteMapElemValue() if x.FMapInt32Bool == nil { r.EncodeNil() } else { z.F.EncMapInt32BoolV(x.FMapInt32Bool, e) } // end block: if x.FMapInt32Bool map == nil z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"FptrMapInt32Bool\"") } else { r.EncodeString(`FptrMapInt32Bool`) } z.EncWriteMapElemValue() if yyn148 { r.EncodeNil() } else { yy804 := *x.FptrMapInt32Bool if yy804 == nil { r.EncodeNil() } else { z.F.EncMapInt32BoolV(yy804, e) } // end block: if yy804 map == nil } } z.EncWriteMapEnd() } } } func (x *TestMammoth2) CodecDecodeSelf(d *Decoder) { var h codecSelfer19781 z, r := GenHelper().Decoder(d) _, _, _ = h, z, r yyct2 := r.ContainerType() if yyct2 == codecSelferValueTypeNil19781 { *(x) = TestMammoth2{} } else if yyct2 == codecSelferValueTypeMap19781 { yyl2 := z.DecReadMapStart() if yyl2 == 0 { } else { x.codecDecodeSelfFromMap(yyl2, d) } z.DecReadMapEnd() } else if yyct2 == codecSelferValueTypeArray19781 { yyl2 := z.DecReadArrayStart() if yyl2 != 0 { x.codecDecodeSelfFromArray(yyl2, d) } z.DecReadArrayEnd() } else { panic(errCodecSelferOnlyMapOrArrayEncodeToStruct19781) } } func (x *TestMammoth2) codecDecodeSelfFromMap(l int, d *Decoder) { var h codecSelfer19781 z, r := GenHelper().Decoder(d) _, _, _ = h, z, r var yyhl3 bool = l >= 0 for yyj3 := 0; ; yyj3++ { if yyhl3 { if yyj3 >= l { break } } else { if z.DecCheckBreak() { break } } z.DecReadMapElemKey() yys3 := r.DecodeStringAsBytes() z.DecReadMapElemValue() switch string(yys3) { case "FIntf": z.DecFallback(&x.FIntf, true) case "FptrIntf": if r.TryNil() { if x.FptrIntf != nil { // remove the if-true x.FptrIntf = nil } } else { if x.FptrIntf == nil { x.FptrIntf = new(interface{}) } z.DecFallback(x.FptrIntf, true) } case "FString": x.FString = (string)(z.DecStringZC(r.DecodeStringAsBytes())) case "FptrString": if r.TryNil() { if x.FptrString != nil { // remove the if-true x.FptrString = nil } } else { if x.FptrString == nil { x.FptrString = new(string) } *x.FptrString = (string)(z.DecStringZC(r.DecodeStringAsBytes())) } case "FBytes": x.FBytes = z.DecodeBytesInto(([]byte)(x.FBytes)) case "FptrBytes": if r.TryNil() { if x.FptrBytes != nil { // remove the if-true x.FptrBytes = nil } } else { if x.FptrBytes == nil { x.FptrBytes = new([]uint8) } *x.FptrBytes = z.DecodeBytesInto(*(*[]byte)(x.FptrBytes)) } case "FFloat32": x.FFloat32 = (float32)(z.DecDecodeFloat32()) case "FptrFloat32": if r.TryNil() { if x.FptrFloat32 != nil { // remove the if-true x.FptrFloat32 = nil } } else { if x.FptrFloat32 == nil { x.FptrFloat32 = new(float32) } *x.FptrFloat32 = (float32)(z.DecDecodeFloat32()) } case "FFloat64": x.FFloat64 = (float64)(r.DecodeFloat64()) case "FptrFloat64": if r.TryNil() { if x.FptrFloat64 != nil { // remove the if-true x.FptrFloat64 = nil } } else { if x.FptrFloat64 == nil { x.FptrFloat64 = new(float64) } *x.FptrFloat64 = (float64)(r.DecodeFloat64()) } case "FUint": x.FUint = (uint)(z.C.UintV(r.DecodeUint64(), codecSelferBitsize19781)) case "FptrUint": if r.TryNil() { if x.FptrUint != nil { // remove the if-true x.FptrUint = nil } } else { if x.FptrUint == nil { x.FptrUint = new(uint) } *x.FptrUint = (uint)(z.C.UintV(r.DecodeUint64(), codecSelferBitsize19781)) } case "FUint8": x.FUint8 = (uint8)(z.C.UintV(r.DecodeUint64(), 8)) case "FptrUint8": if r.TryNil() { if x.FptrUint8 != nil { // remove the if-true x.FptrUint8 = nil } } else { if x.FptrUint8 == nil { x.FptrUint8 = new(uint8) } *x.FptrUint8 = (uint8)(z.C.UintV(r.DecodeUint64(), 8)) } case "FUint16": x.FUint16 = (uint16)(z.C.UintV(r.DecodeUint64(), 16)) case "FptrUint16": if r.TryNil() { if x.FptrUint16 != nil { // remove the if-true x.FptrUint16 = nil } } else { if x.FptrUint16 == nil { x.FptrUint16 = new(uint16) } *x.FptrUint16 = (uint16)(z.C.UintV(r.DecodeUint64(), 16)) } case "FUint32": x.FUint32 = (uint32)(z.C.UintV(r.DecodeUint64(), 32)) case "FptrUint32": if r.TryNil() { if x.FptrUint32 != nil { // remove the if-true x.FptrUint32 = nil } } else { if x.FptrUint32 == nil { x.FptrUint32 = new(uint32) } *x.FptrUint32 = (uint32)(z.C.UintV(r.DecodeUint64(), 32)) } case "FUint64": x.FUint64 = (uint64)(r.DecodeUint64()) case "FptrUint64": if r.TryNil() { if x.FptrUint64 != nil { // remove the if-true x.FptrUint64 = nil } } else { if x.FptrUint64 == nil { x.FptrUint64 = new(uint64) } *x.FptrUint64 = (uint64)(r.DecodeUint64()) } case "FUintptr": x.FUintptr = (uintptr)(z.C.UintV(r.DecodeUint64(), codecSelferBitsize19781)) case "FptrUintptr": if r.TryNil() { if x.FptrUintptr != nil { // remove the if-true x.FptrUintptr = nil } } else { if x.FptrUintptr == nil { x.FptrUintptr = new(uintptr) } *x.FptrUintptr = (uintptr)(z.C.UintV(r.DecodeUint64(), codecSelferBitsize19781)) } case "FInt": x.FInt = (int)(z.C.IntV(r.DecodeInt64(), codecSelferBitsize19781)) case "FptrInt": if r.TryNil() { if x.FptrInt != nil { // remove the if-true x.FptrInt = nil } } else { if x.FptrInt == nil { x.FptrInt = new(int) } *x.FptrInt = (int)(z.C.IntV(r.DecodeInt64(), codecSelferBitsize19781)) } case "FInt8": x.FInt8 = (int8)(z.C.IntV(r.DecodeInt64(), 8)) case "FptrInt8": if r.TryNil() { if x.FptrInt8 != nil { // remove the if-true x.FptrInt8 = nil } } else { if x.FptrInt8 == nil { x.FptrInt8 = new(int8) } *x.FptrInt8 = (int8)(z.C.IntV(r.DecodeInt64(), 8)) } case "FInt16": x.FInt16 = (int16)(z.C.IntV(r.DecodeInt64(), 16)) case "FptrInt16": if r.TryNil() { if x.FptrInt16 != nil { // remove the if-true x.FptrInt16 = nil } } else { if x.FptrInt16 == nil { x.FptrInt16 = new(int16) } *x.FptrInt16 = (int16)(z.C.IntV(r.DecodeInt64(), 16)) } case "FInt32": x.FInt32 = (int32)(z.C.IntV(r.DecodeInt64(), 32)) case "FptrInt32": if r.TryNil() { if x.FptrInt32 != nil { // remove the if-true x.FptrInt32 = nil } } else { if x.FptrInt32 == nil { x.FptrInt32 = new(int32) } *x.FptrInt32 = (int32)(z.C.IntV(r.DecodeInt64(), 32)) } case "FInt64": x.FInt64 = (int64)(r.DecodeInt64()) case "FptrInt64": if r.TryNil() { if x.FptrInt64 != nil { // remove the if-true x.FptrInt64 = nil } } else { if x.FptrInt64 == nil { x.FptrInt64 = new(int64) } *x.FptrInt64 = (int64)(r.DecodeInt64()) } case "FBool": x.FBool = (bool)(r.DecodeBool()) case "FptrBool": if r.TryNil() { if x.FptrBool != nil { // remove the if-true x.FptrBool = nil } } else { if x.FptrBool == nil { x.FptrBool = new(bool) } *x.FptrBool = (bool)(r.DecodeBool()) } case "FSliceIntf": z.F.DecSliceIntfX(&x.FSliceIntf, d) case "FptrSliceIntf": if r.TryNil() { if x.FptrSliceIntf != nil { // remove the if-true x.FptrSliceIntf = nil } } else { if x.FptrSliceIntf == nil { x.FptrSliceIntf = new([]interface{}) } z.F.DecSliceIntfX(x.FptrSliceIntf, d) } case "FSliceString": z.F.DecSliceStringX(&x.FSliceString, d) case "FptrSliceString": if r.TryNil() { if x.FptrSliceString != nil { // remove the if-true x.FptrSliceString = nil } } else { if x.FptrSliceString == nil { x.FptrSliceString = new([]string) } z.F.DecSliceStringX(x.FptrSliceString, d) } case "FSliceBytes": z.F.DecSliceBytesX(&x.FSliceBytes, d) case "FptrSliceBytes": if r.TryNil() { if x.FptrSliceBytes != nil { // remove the if-true x.FptrSliceBytes = nil } } else { if x.FptrSliceBytes == nil { x.FptrSliceBytes = new([][]uint8) } z.F.DecSliceBytesX(x.FptrSliceBytes, d) } case "FSliceFloat32": z.F.DecSliceFloat32X(&x.FSliceFloat32, d) case "FptrSliceFloat32": if r.TryNil() { if x.FptrSliceFloat32 != nil { // remove the if-true x.FptrSliceFloat32 = nil } } else { if x.FptrSliceFloat32 == nil { x.FptrSliceFloat32 = new([]float32) } z.F.DecSliceFloat32X(x.FptrSliceFloat32, d) } case "FSliceFloat64": z.F.DecSliceFloat64X(&x.FSliceFloat64, d) case "FptrSliceFloat64": if r.TryNil() { if x.FptrSliceFloat64 != nil { // remove the if-true x.FptrSliceFloat64 = nil } } else { if x.FptrSliceFloat64 == nil { x.FptrSliceFloat64 = new([]float64) } z.F.DecSliceFloat64X(x.FptrSliceFloat64, d) } case "FSliceUint8": x.FSliceUint8 = z.DecodeBytesInto(([]byte)(x.FSliceUint8)) case "FptrSliceUint8": if r.TryNil() { if x.FptrSliceUint8 != nil { // remove the if-true x.FptrSliceUint8 = nil } } else { if x.FptrSliceUint8 == nil { x.FptrSliceUint8 = new([]uint8) } *x.FptrSliceUint8 = z.DecodeBytesInto(*(*[]byte)(x.FptrSliceUint8)) } case "FSliceUint64": z.F.DecSliceUint64X(&x.FSliceUint64, d) case "FptrSliceUint64": if r.TryNil() { if x.FptrSliceUint64 != nil { // remove the if-true x.FptrSliceUint64 = nil } } else { if x.FptrSliceUint64 == nil { x.FptrSliceUint64 = new([]uint64) } z.F.DecSliceUint64X(x.FptrSliceUint64, d) } case "FSliceInt": z.F.DecSliceIntX(&x.FSliceInt, d) case "FptrSliceInt": if r.TryNil() { if x.FptrSliceInt != nil { // remove the if-true x.FptrSliceInt = nil } } else { if x.FptrSliceInt == nil { x.FptrSliceInt = new([]int) } z.F.DecSliceIntX(x.FptrSliceInt, d) } case "FSliceInt32": z.F.DecSliceInt32X(&x.FSliceInt32, d) case "FptrSliceInt32": if r.TryNil() { if x.FptrSliceInt32 != nil { // remove the if-true x.FptrSliceInt32 = nil } } else { if x.FptrSliceInt32 == nil { x.FptrSliceInt32 = new([]int32) } z.F.DecSliceInt32X(x.FptrSliceInt32, d) } case "FSliceInt64": z.F.DecSliceInt64X(&x.FSliceInt64, d) case "FptrSliceInt64": if r.TryNil() { if x.FptrSliceInt64 != nil { // remove the if-true x.FptrSliceInt64 = nil } } else { if x.FptrSliceInt64 == nil { x.FptrSliceInt64 = new([]int64) } z.F.DecSliceInt64X(x.FptrSliceInt64, d) } case "FSliceBool": z.F.DecSliceBoolX(&x.FSliceBool, d) case "FptrSliceBool": if r.TryNil() { if x.FptrSliceBool != nil { // remove the if-true x.FptrSliceBool = nil } } else { if x.FptrSliceBool == nil { x.FptrSliceBool = new([]bool) } z.F.DecSliceBoolX(x.FptrSliceBool, d) } case "FMapStringIntf": z.F.DecMapStringIntfX(&x.FMapStringIntf, d) case "FptrMapStringIntf": if r.TryNil() { if x.FptrMapStringIntf != nil { // remove the if-true x.FptrMapStringIntf = nil } } else { if x.FptrMapStringIntf == nil { x.FptrMapStringIntf = new(map[string]interface{}) } z.F.DecMapStringIntfX(x.FptrMapStringIntf, d) } case "FMapStringString": z.F.DecMapStringStringX(&x.FMapStringString, d) case "FptrMapStringString": if r.TryNil() { if x.FptrMapStringString != nil { // remove the if-true x.FptrMapStringString = nil } } else { if x.FptrMapStringString == nil { x.FptrMapStringString = new(map[string]string) } z.F.DecMapStringStringX(x.FptrMapStringString, d) } case "FMapStringBytes": z.F.DecMapStringBytesX(&x.FMapStringBytes, d) case "FptrMapStringBytes": if r.TryNil() { if x.FptrMapStringBytes != nil { // remove the if-true x.FptrMapStringBytes = nil } } else { if x.FptrMapStringBytes == nil { x.FptrMapStringBytes = new(map[string][]uint8) } z.F.DecMapStringBytesX(x.FptrMapStringBytes, d) } case "FMapStringUint8": z.F.DecMapStringUint8X(&x.FMapStringUint8, d) case "FptrMapStringUint8": if r.TryNil() { if x.FptrMapStringUint8 != nil { // remove the if-true x.FptrMapStringUint8 = nil } } else { if x.FptrMapStringUint8 == nil { x.FptrMapStringUint8 = new(map[string]uint8) } z.F.DecMapStringUint8X(x.FptrMapStringUint8, d) } case "FMapStringUint64": z.F.DecMapStringUint64X(&x.FMapStringUint64, d) case "FptrMapStringUint64": if r.TryNil() { if x.FptrMapStringUint64 != nil { // remove the if-true x.FptrMapStringUint64 = nil } } else { if x.FptrMapStringUint64 == nil { x.FptrMapStringUint64 = new(map[string]uint64) } z.F.DecMapStringUint64X(x.FptrMapStringUint64, d) } case "FMapStringInt": z.F.DecMapStringIntX(&x.FMapStringInt, d) case "FptrMapStringInt": if r.TryNil() { if x.FptrMapStringInt != nil { // remove the if-true x.FptrMapStringInt = nil } } else { if x.FptrMapStringInt == nil { x.FptrMapStringInt = new(map[string]int) } z.F.DecMapStringIntX(x.FptrMapStringInt, d) } case "FMapStringInt32": z.F.DecMapStringInt32X(&x.FMapStringInt32, d) case "FptrMapStringInt32": if r.TryNil() { if x.FptrMapStringInt32 != nil { // remove the if-true x.FptrMapStringInt32 = nil } } else { if x.FptrMapStringInt32 == nil { x.FptrMapStringInt32 = new(map[string]int32) } z.F.DecMapStringInt32X(x.FptrMapStringInt32, d) } case "FMapStringFloat64": z.F.DecMapStringFloat64X(&x.FMapStringFloat64, d) case "FptrMapStringFloat64": if r.TryNil() { if x.FptrMapStringFloat64 != nil { // remove the if-true x.FptrMapStringFloat64 = nil } } else { if x.FptrMapStringFloat64 == nil { x.FptrMapStringFloat64 = new(map[string]float64) } z.F.DecMapStringFloat64X(x.FptrMapStringFloat64, d) } case "FMapStringBool": z.F.DecMapStringBoolX(&x.FMapStringBool, d) case "FptrMapStringBool": if r.TryNil() { if x.FptrMapStringBool != nil { // remove the if-true x.FptrMapStringBool = nil } } else { if x.FptrMapStringBool == nil { x.FptrMapStringBool = new(map[string]bool) } z.F.DecMapStringBoolX(x.FptrMapStringBool, d) } case "FMapUint8Intf": z.F.DecMapUint8IntfX(&x.FMapUint8Intf, d) case "FptrMapUint8Intf": if r.TryNil() { if x.FptrMapUint8Intf != nil { // remove the if-true x.FptrMapUint8Intf = nil } } else { if x.FptrMapUint8Intf == nil { x.FptrMapUint8Intf = new(map[uint8]interface{}) } z.F.DecMapUint8IntfX(x.FptrMapUint8Intf, d) } case "FMapUint8String": z.F.DecMapUint8StringX(&x.FMapUint8String, d) case "FptrMapUint8String": if r.TryNil() { if x.FptrMapUint8String != nil { // remove the if-true x.FptrMapUint8String = nil } } else { if x.FptrMapUint8String == nil { x.FptrMapUint8String = new(map[uint8]string) } z.F.DecMapUint8StringX(x.FptrMapUint8String, d) } case "FMapUint8Bytes": z.F.DecMapUint8BytesX(&x.FMapUint8Bytes, d) case "FptrMapUint8Bytes": if r.TryNil() { if x.FptrMapUint8Bytes != nil { // remove the if-true x.FptrMapUint8Bytes = nil } } else { if x.FptrMapUint8Bytes == nil { x.FptrMapUint8Bytes = new(map[uint8][]uint8) } z.F.DecMapUint8BytesX(x.FptrMapUint8Bytes, d) } case "FMapUint8Uint8": z.F.DecMapUint8Uint8X(&x.FMapUint8Uint8, d) case "FptrMapUint8Uint8": if r.TryNil() { if x.FptrMapUint8Uint8 != nil { // remove the if-true x.FptrMapUint8Uint8 = nil } } else { if x.FptrMapUint8Uint8 == nil { x.FptrMapUint8Uint8 = new(map[uint8]uint8) } z.F.DecMapUint8Uint8X(x.FptrMapUint8Uint8, d) } case "FMapUint8Uint64": z.F.DecMapUint8Uint64X(&x.FMapUint8Uint64, d) case "FptrMapUint8Uint64": if r.TryNil() { if x.FptrMapUint8Uint64 != nil { // remove the if-true x.FptrMapUint8Uint64 = nil } } else { if x.FptrMapUint8Uint64 == nil { x.FptrMapUint8Uint64 = new(map[uint8]uint64) } z.F.DecMapUint8Uint64X(x.FptrMapUint8Uint64, d) } case "FMapUint8Int": z.F.DecMapUint8IntX(&x.FMapUint8Int, d) case "FptrMapUint8Int": if r.TryNil() { if x.FptrMapUint8Int != nil { // remove the if-true x.FptrMapUint8Int = nil } } else { if x.FptrMapUint8Int == nil { x.FptrMapUint8Int = new(map[uint8]int) } z.F.DecMapUint8IntX(x.FptrMapUint8Int, d) } case "FMapUint8Int32": z.F.DecMapUint8Int32X(&x.FMapUint8Int32, d) case "FptrMapUint8Int32": if r.TryNil() { if x.FptrMapUint8Int32 != nil { // remove the if-true x.FptrMapUint8Int32 = nil } } else { if x.FptrMapUint8Int32 == nil { x.FptrMapUint8Int32 = new(map[uint8]int32) } z.F.DecMapUint8Int32X(x.FptrMapUint8Int32, d) } case "FMapUint8Float64": z.F.DecMapUint8Float64X(&x.FMapUint8Float64, d) case "FptrMapUint8Float64": if r.TryNil() { if x.FptrMapUint8Float64 != nil { // remove the if-true x.FptrMapUint8Float64 = nil } } else { if x.FptrMapUint8Float64 == nil { x.FptrMapUint8Float64 = new(map[uint8]float64) } z.F.DecMapUint8Float64X(x.FptrMapUint8Float64, d) } case "FMapUint8Bool": z.F.DecMapUint8BoolX(&x.FMapUint8Bool, d) case "FptrMapUint8Bool": if r.TryNil() { if x.FptrMapUint8Bool != nil { // remove the if-true x.FptrMapUint8Bool = nil } } else { if x.FptrMapUint8Bool == nil { x.FptrMapUint8Bool = new(map[uint8]bool) } z.F.DecMapUint8BoolX(x.FptrMapUint8Bool, d) } case "FMapUint64Intf": z.F.DecMapUint64IntfX(&x.FMapUint64Intf, d) case "FptrMapUint64Intf": if r.TryNil() { if x.FptrMapUint64Intf != nil { // remove the if-true x.FptrMapUint64Intf = nil } } else { if x.FptrMapUint64Intf == nil { x.FptrMapUint64Intf = new(map[uint64]interface{}) } z.F.DecMapUint64IntfX(x.FptrMapUint64Intf, d) } case "FMapUint64String": z.F.DecMapUint64StringX(&x.FMapUint64String, d) case "FptrMapUint64String": if r.TryNil() { if x.FptrMapUint64String != nil { // remove the if-true x.FptrMapUint64String = nil } } else { if x.FptrMapUint64String == nil { x.FptrMapUint64String = new(map[uint64]string) } z.F.DecMapUint64StringX(x.FptrMapUint64String, d) } case "FMapUint64Bytes": z.F.DecMapUint64BytesX(&x.FMapUint64Bytes, d) case "FptrMapUint64Bytes": if r.TryNil() { if x.FptrMapUint64Bytes != nil { // remove the if-true x.FptrMapUint64Bytes = nil } } else { if x.FptrMapUint64Bytes == nil { x.FptrMapUint64Bytes = new(map[uint64][]uint8) } z.F.DecMapUint64BytesX(x.FptrMapUint64Bytes, d) } case "FMapUint64Uint8": z.F.DecMapUint64Uint8X(&x.FMapUint64Uint8, d) case "FptrMapUint64Uint8": if r.TryNil() { if x.FptrMapUint64Uint8 != nil { // remove the if-true x.FptrMapUint64Uint8 = nil } } else { if x.FptrMapUint64Uint8 == nil { x.FptrMapUint64Uint8 = new(map[uint64]uint8) } z.F.DecMapUint64Uint8X(x.FptrMapUint64Uint8, d) } case "FMapUint64Uint64": z.F.DecMapUint64Uint64X(&x.FMapUint64Uint64, d) case "FptrMapUint64Uint64": if r.TryNil() { if x.FptrMapUint64Uint64 != nil { // remove the if-true x.FptrMapUint64Uint64 = nil } } else { if x.FptrMapUint64Uint64 == nil { x.FptrMapUint64Uint64 = new(map[uint64]uint64) } z.F.DecMapUint64Uint64X(x.FptrMapUint64Uint64, d) } case "FMapUint64Int": z.F.DecMapUint64IntX(&x.FMapUint64Int, d) case "FptrMapUint64Int": if r.TryNil() { if x.FptrMapUint64Int != nil { // remove the if-true x.FptrMapUint64Int = nil } } else { if x.FptrMapUint64Int == nil { x.FptrMapUint64Int = new(map[uint64]int) } z.F.DecMapUint64IntX(x.FptrMapUint64Int, d) } case "FMapUint64Int32": z.F.DecMapUint64Int32X(&x.FMapUint64Int32, d) case "FptrMapUint64Int32": if r.TryNil() { if x.FptrMapUint64Int32 != nil { // remove the if-true x.FptrMapUint64Int32 = nil } } else { if x.FptrMapUint64Int32 == nil { x.FptrMapUint64Int32 = new(map[uint64]int32) } z.F.DecMapUint64Int32X(x.FptrMapUint64Int32, d) } case "FMapUint64Float64": z.F.DecMapUint64Float64X(&x.FMapUint64Float64, d) case "FptrMapUint64Float64": if r.TryNil() { if x.FptrMapUint64Float64 != nil { // remove the if-true x.FptrMapUint64Float64 = nil } } else { if x.FptrMapUint64Float64 == nil { x.FptrMapUint64Float64 = new(map[uint64]float64) } z.F.DecMapUint64Float64X(x.FptrMapUint64Float64, d) } case "FMapUint64Bool": z.F.DecMapUint64BoolX(&x.FMapUint64Bool, d) case "FptrMapUint64Bool": if r.TryNil() { if x.FptrMapUint64Bool != nil { // remove the if-true x.FptrMapUint64Bool = nil } } else { if x.FptrMapUint64Bool == nil { x.FptrMapUint64Bool = new(map[uint64]bool) } z.F.DecMapUint64BoolX(x.FptrMapUint64Bool, d) } case "FMapIntIntf": z.F.DecMapIntIntfX(&x.FMapIntIntf, d) case "FptrMapIntIntf": if r.TryNil() { if x.FptrMapIntIntf != nil { // remove the if-true x.FptrMapIntIntf = nil } } else { if x.FptrMapIntIntf == nil { x.FptrMapIntIntf = new(map[int]interface{}) } z.F.DecMapIntIntfX(x.FptrMapIntIntf, d) } case "FMapIntString": z.F.DecMapIntStringX(&x.FMapIntString, d) case "FptrMapIntString": if r.TryNil() { if x.FptrMapIntString != nil { // remove the if-true x.FptrMapIntString = nil } } else { if x.FptrMapIntString == nil { x.FptrMapIntString = new(map[int]string) } z.F.DecMapIntStringX(x.FptrMapIntString, d) } case "FMapIntBytes": z.F.DecMapIntBytesX(&x.FMapIntBytes, d) case "FptrMapIntBytes": if r.TryNil() { if x.FptrMapIntBytes != nil { // remove the if-true x.FptrMapIntBytes = nil } } else { if x.FptrMapIntBytes == nil { x.FptrMapIntBytes = new(map[int][]uint8) } z.F.DecMapIntBytesX(x.FptrMapIntBytes, d) } case "FMapIntUint8": z.F.DecMapIntUint8X(&x.FMapIntUint8, d) case "FptrMapIntUint8": if r.TryNil() { if x.FptrMapIntUint8 != nil { // remove the if-true x.FptrMapIntUint8 = nil } } else { if x.FptrMapIntUint8 == nil { x.FptrMapIntUint8 = new(map[int]uint8) } z.F.DecMapIntUint8X(x.FptrMapIntUint8, d) } case "FMapIntUint64": z.F.DecMapIntUint64X(&x.FMapIntUint64, d) case "FptrMapIntUint64": if r.TryNil() { if x.FptrMapIntUint64 != nil { // remove the if-true x.FptrMapIntUint64 = nil } } else { if x.FptrMapIntUint64 == nil { x.FptrMapIntUint64 = new(map[int]uint64) } z.F.DecMapIntUint64X(x.FptrMapIntUint64, d) } case "FMapIntInt": z.F.DecMapIntIntX(&x.FMapIntInt, d) case "FptrMapIntInt": if r.TryNil() { if x.FptrMapIntInt != nil { // remove the if-true x.FptrMapIntInt = nil } } else { if x.FptrMapIntInt == nil { x.FptrMapIntInt = new(map[int]int) } z.F.DecMapIntIntX(x.FptrMapIntInt, d) } case "FMapIntInt32": z.F.DecMapIntInt32X(&x.FMapIntInt32, d) case "FptrMapIntInt32": if r.TryNil() { if x.FptrMapIntInt32 != nil { // remove the if-true x.FptrMapIntInt32 = nil } } else { if x.FptrMapIntInt32 == nil { x.FptrMapIntInt32 = new(map[int]int32) } z.F.DecMapIntInt32X(x.FptrMapIntInt32, d) } case "FMapIntFloat64": z.F.DecMapIntFloat64X(&x.FMapIntFloat64, d) case "FptrMapIntFloat64": if r.TryNil() { if x.FptrMapIntFloat64 != nil { // remove the if-true x.FptrMapIntFloat64 = nil } } else { if x.FptrMapIntFloat64 == nil { x.FptrMapIntFloat64 = new(map[int]float64) } z.F.DecMapIntFloat64X(x.FptrMapIntFloat64, d) } case "FMapIntBool": z.F.DecMapIntBoolX(&x.FMapIntBool, d) case "FptrMapIntBool": if r.TryNil() { if x.FptrMapIntBool != nil { // remove the if-true x.FptrMapIntBool = nil } } else { if x.FptrMapIntBool == nil { x.FptrMapIntBool = new(map[int]bool) } z.F.DecMapIntBoolX(x.FptrMapIntBool, d) } case "FMapInt32Intf": z.F.DecMapInt32IntfX(&x.FMapInt32Intf, d) case "FptrMapInt32Intf": if r.TryNil() { if x.FptrMapInt32Intf != nil { // remove the if-true x.FptrMapInt32Intf = nil } } else { if x.FptrMapInt32Intf == nil { x.FptrMapInt32Intf = new(map[int32]interface{}) } z.F.DecMapInt32IntfX(x.FptrMapInt32Intf, d) } case "FMapInt32String": z.F.DecMapInt32StringX(&x.FMapInt32String, d) case "FptrMapInt32String": if r.TryNil() { if x.FptrMapInt32String != nil { // remove the if-true x.FptrMapInt32String = nil } } else { if x.FptrMapInt32String == nil { x.FptrMapInt32String = new(map[int32]string) } z.F.DecMapInt32StringX(x.FptrMapInt32String, d) } case "FMapInt32Bytes": z.F.DecMapInt32BytesX(&x.FMapInt32Bytes, d) case "FptrMapInt32Bytes": if r.TryNil() { if x.FptrMapInt32Bytes != nil { // remove the if-true x.FptrMapInt32Bytes = nil } } else { if x.FptrMapInt32Bytes == nil { x.FptrMapInt32Bytes = new(map[int32][]uint8) } z.F.DecMapInt32BytesX(x.FptrMapInt32Bytes, d) } case "FMapInt32Uint8": z.F.DecMapInt32Uint8X(&x.FMapInt32Uint8, d) case "FptrMapInt32Uint8": if r.TryNil() { if x.FptrMapInt32Uint8 != nil { // remove the if-true x.FptrMapInt32Uint8 = nil } } else { if x.FptrMapInt32Uint8 == nil { x.FptrMapInt32Uint8 = new(map[int32]uint8) } z.F.DecMapInt32Uint8X(x.FptrMapInt32Uint8, d) } case "FMapInt32Uint64": z.F.DecMapInt32Uint64X(&x.FMapInt32Uint64, d) case "FptrMapInt32Uint64": if r.TryNil() { if x.FptrMapInt32Uint64 != nil { // remove the if-true x.FptrMapInt32Uint64 = nil } } else { if x.FptrMapInt32Uint64 == nil { x.FptrMapInt32Uint64 = new(map[int32]uint64) } z.F.DecMapInt32Uint64X(x.FptrMapInt32Uint64, d) } case "FMapInt32Int": z.F.DecMapInt32IntX(&x.FMapInt32Int, d) case "FptrMapInt32Int": if r.TryNil() { if x.FptrMapInt32Int != nil { // remove the if-true x.FptrMapInt32Int = nil } } else { if x.FptrMapInt32Int == nil { x.FptrMapInt32Int = new(map[int32]int) } z.F.DecMapInt32IntX(x.FptrMapInt32Int, d) } case "FMapInt32Int32": z.F.DecMapInt32Int32X(&x.FMapInt32Int32, d) case "FptrMapInt32Int32": if r.TryNil() { if x.FptrMapInt32Int32 != nil { // remove the if-true x.FptrMapInt32Int32 = nil } } else { if x.FptrMapInt32Int32 == nil { x.FptrMapInt32Int32 = new(map[int32]int32) } z.F.DecMapInt32Int32X(x.FptrMapInt32Int32, d) } case "FMapInt32Float64": z.F.DecMapInt32Float64X(&x.FMapInt32Float64, d) case "FptrMapInt32Float64": if r.TryNil() { if x.FptrMapInt32Float64 != nil { // remove the if-true x.FptrMapInt32Float64 = nil } } else { if x.FptrMapInt32Float64 == nil { x.FptrMapInt32Float64 = new(map[int32]float64) } z.F.DecMapInt32Float64X(x.FptrMapInt32Float64, d) } case "FMapInt32Bool": z.F.DecMapInt32BoolX(&x.FMapInt32Bool, d) case "FptrMapInt32Bool": if r.TryNil() { if x.FptrMapInt32Bool != nil { // remove the if-true x.FptrMapInt32Bool = nil } } else { if x.FptrMapInt32Bool == nil { x.FptrMapInt32Bool = new(map[int32]bool) } z.F.DecMapInt32BoolX(x.FptrMapInt32Bool, d) } default: z.DecStructFieldNotFound(-1, string(yys3)) } // end switch yys3 } // end for yyj3 } func (x *TestMammoth2) codecDecodeSelfFromArray(l int, d *Decoder) { var h codecSelfer19781 z, r := GenHelper().Decoder(d) _, _, _ = h, z, r var yyj281 int var yyb281 bool var yyhl281 bool = l >= 0 yyj281++ if yyhl281 { yyb281 = yyj281 > l } else { yyb281 = z.DecCheckBreak() } if yyb281 { z.DecReadArrayEnd() return } z.DecReadArrayElem() z.DecFallback(&x.FIntf, true) yyj281++ if yyhl281 { yyb281 = yyj281 > l } else { yyb281 = z.DecCheckBreak() } if yyb281 { z.DecReadArrayEnd() return } z.DecReadArrayElem() if r.TryNil() { if x.FptrIntf != nil { // remove the if-true x.FptrIntf = nil } } else { if x.FptrIntf == nil { x.FptrIntf = new(interface{}) } z.DecFallback(x.FptrIntf, true) } yyj281++ if yyhl281 { yyb281 = yyj281 > l } else { yyb281 = z.DecCheckBreak() } if yyb281 { z.DecReadArrayEnd() return } z.DecReadArrayElem() x.FString = (string)(z.DecStringZC(r.DecodeStringAsBytes())) yyj281++ if yyhl281 { yyb281 = yyj281 > l } else { yyb281 = z.DecCheckBreak() } if yyb281 { z.DecReadArrayEnd() return } z.DecReadArrayElem() if r.TryNil() { if x.FptrString != nil { // remove the if-true x.FptrString = nil } } else { if x.FptrString == nil { x.FptrString = new(string) } *x.FptrString = (string)(z.DecStringZC(r.DecodeStringAsBytes())) } yyj281++ if yyhl281 { yyb281 = yyj281 > l } else { yyb281 = z.DecCheckBreak() } if yyb281 { z.DecReadArrayEnd() return } z.DecReadArrayElem() x.FBytes = z.DecodeBytesInto(([]byte)(x.FBytes)) yyj281++ if yyhl281 { yyb281 = yyj281 > l } else { yyb281 = z.DecCheckBreak() } if yyb281 { z.DecReadArrayEnd() return } z.DecReadArrayElem() if r.TryNil() { if x.FptrBytes != nil { // remove the if-true x.FptrBytes = nil } } else { if x.FptrBytes == nil { x.FptrBytes = new([]uint8) } *x.FptrBytes = z.DecodeBytesInto(*(*[]byte)(x.FptrBytes)) } yyj281++ if yyhl281 { yyb281 = yyj281 > l } else { yyb281 = z.DecCheckBreak() } if yyb281 { z.DecReadArrayEnd() return } z.DecReadArrayElem() x.FFloat32 = (float32)(z.DecDecodeFloat32()) yyj281++ if yyhl281 { yyb281 = yyj281 > l } else { yyb281 = z.DecCheckBreak() } if yyb281 { z.DecReadArrayEnd() return } z.DecReadArrayElem() if r.TryNil() { if x.FptrFloat32 != nil { // remove the if-true x.FptrFloat32 = nil } } else { if x.FptrFloat32 == nil { x.FptrFloat32 = new(float32) } *x.FptrFloat32 = (float32)(z.DecDecodeFloat32()) } yyj281++ if yyhl281 { yyb281 = yyj281 > l } else { yyb281 = z.DecCheckBreak() } if yyb281 { z.DecReadArrayEnd() return } z.DecReadArrayElem() x.FFloat64 = (float64)(r.DecodeFloat64()) yyj281++ if yyhl281 { yyb281 = yyj281 > l } else { yyb281 = z.DecCheckBreak() } if yyb281 { z.DecReadArrayEnd() return } z.DecReadArrayElem() if r.TryNil() { if x.FptrFloat64 != nil { // remove the if-true x.FptrFloat64 = nil } } else { if x.FptrFloat64 == nil { x.FptrFloat64 = new(float64) } *x.FptrFloat64 = (float64)(r.DecodeFloat64()) } yyj281++ if yyhl281 { yyb281 = yyj281 > l } else { yyb281 = z.DecCheckBreak() } if yyb281 { z.DecReadArrayEnd() return } z.DecReadArrayElem() x.FUint = (uint)(z.C.UintV(r.DecodeUint64(), codecSelferBitsize19781)) yyj281++ if yyhl281 { yyb281 = yyj281 > l } else { yyb281 = z.DecCheckBreak() } if yyb281 { z.DecReadArrayEnd() return } z.DecReadArrayElem() if r.TryNil() { if x.FptrUint != nil { // remove the if-true x.FptrUint = nil } } else { if x.FptrUint == nil { x.FptrUint = new(uint) } *x.FptrUint = (uint)(z.C.UintV(r.DecodeUint64(), codecSelferBitsize19781)) } yyj281++ if yyhl281 { yyb281 = yyj281 > l } else { yyb281 = z.DecCheckBreak() } if yyb281 { z.DecReadArrayEnd() return } z.DecReadArrayElem() x.FUint8 = (uint8)(z.C.UintV(r.DecodeUint64(), 8)) yyj281++ if yyhl281 { yyb281 = yyj281 > l } else { yyb281 = z.DecCheckBreak() } if yyb281 { z.DecReadArrayEnd() return } z.DecReadArrayElem() if r.TryNil() { if x.FptrUint8 != nil { // remove the if-true x.FptrUint8 = nil } } else { if x.FptrUint8 == nil { x.FptrUint8 = new(uint8) } *x.FptrUint8 = (uint8)(z.C.UintV(r.DecodeUint64(), 8)) } yyj281++ if yyhl281 { yyb281 = yyj281 > l } else { yyb281 = z.DecCheckBreak() } if yyb281 { z.DecReadArrayEnd() return } z.DecReadArrayElem() x.FUint16 = (uint16)(z.C.UintV(r.DecodeUint64(), 16)) yyj281++ if yyhl281 { yyb281 = yyj281 > l } else { yyb281 = z.DecCheckBreak() } if yyb281 { z.DecReadArrayEnd() return } z.DecReadArrayElem() if r.TryNil() { if x.FptrUint16 != nil { // remove the if-true x.FptrUint16 = nil } } else { if x.FptrUint16 == nil { x.FptrUint16 = new(uint16) } *x.FptrUint16 = (uint16)(z.C.UintV(r.DecodeUint64(), 16)) } yyj281++ if yyhl281 { yyb281 = yyj281 > l } else { yyb281 = z.DecCheckBreak() } if yyb281 { z.DecReadArrayEnd() return } z.DecReadArrayElem() x.FUint32 = (uint32)(z.C.UintV(r.DecodeUint64(), 32)) yyj281++ if yyhl281 { yyb281 = yyj281 > l } else { yyb281 = z.DecCheckBreak() } if yyb281 { z.DecReadArrayEnd() return } z.DecReadArrayElem() if r.TryNil() { if x.FptrUint32 != nil { // remove the if-true x.FptrUint32 = nil } } else { if x.FptrUint32 == nil { x.FptrUint32 = new(uint32) } *x.FptrUint32 = (uint32)(z.C.UintV(r.DecodeUint64(), 32)) } yyj281++ if yyhl281 { yyb281 = yyj281 > l } else { yyb281 = z.DecCheckBreak() } if yyb281 { z.DecReadArrayEnd() return } z.DecReadArrayElem() x.FUint64 = (uint64)(r.DecodeUint64()) yyj281++ if yyhl281 { yyb281 = yyj281 > l } else { yyb281 = z.DecCheckBreak() } if yyb281 { z.DecReadArrayEnd() return } z.DecReadArrayElem() if r.TryNil() { if x.FptrUint64 != nil { // remove the if-true x.FptrUint64 = nil } } else { if x.FptrUint64 == nil { x.FptrUint64 = new(uint64) } *x.FptrUint64 = (uint64)(r.DecodeUint64()) } yyj281++ if yyhl281 { yyb281 = yyj281 > l } else { yyb281 = z.DecCheckBreak() } if yyb281 { z.DecReadArrayEnd() return } z.DecReadArrayElem() x.FUintptr = (uintptr)(z.C.UintV(r.DecodeUint64(), codecSelferBitsize19781)) yyj281++ if yyhl281 { yyb281 = yyj281 > l } else { yyb281 = z.DecCheckBreak() } if yyb281 { z.DecReadArrayEnd() return } z.DecReadArrayElem() if r.TryNil() { if x.FptrUintptr != nil { // remove the if-true x.FptrUintptr = nil } } else { if x.FptrUintptr == nil { x.FptrUintptr = new(uintptr) } *x.FptrUintptr = (uintptr)(z.C.UintV(r.DecodeUint64(), codecSelferBitsize19781)) } yyj281++ if yyhl281 { yyb281 = yyj281 > l } else { yyb281 = z.DecCheckBreak() } if yyb281 { z.DecReadArrayEnd() return } z.DecReadArrayElem() x.FInt = (int)(z.C.IntV(r.DecodeInt64(), codecSelferBitsize19781)) yyj281++ if yyhl281 { yyb281 = yyj281 > l } else { yyb281 = z.DecCheckBreak() } if yyb281 { z.DecReadArrayEnd() return } z.DecReadArrayElem() if r.TryNil() { if x.FptrInt != nil { // remove the if-true x.FptrInt = nil } } else { if x.FptrInt == nil { x.FptrInt = new(int) } *x.FptrInt = (int)(z.C.IntV(r.DecodeInt64(), codecSelferBitsize19781)) } yyj281++ if yyhl281 { yyb281 = yyj281 > l } else { yyb281 = z.DecCheckBreak() } if yyb281 { z.DecReadArrayEnd() return } z.DecReadArrayElem() x.FInt8 = (int8)(z.C.IntV(r.DecodeInt64(), 8)) yyj281++ if yyhl281 { yyb281 = yyj281 > l } else { yyb281 = z.DecCheckBreak() } if yyb281 { z.DecReadArrayEnd() return } z.DecReadArrayElem() if r.TryNil() { if x.FptrInt8 != nil { // remove the if-true x.FptrInt8 = nil } } else { if x.FptrInt8 == nil { x.FptrInt8 = new(int8) } *x.FptrInt8 = (int8)(z.C.IntV(r.DecodeInt64(), 8)) } yyj281++ if yyhl281 { yyb281 = yyj281 > l } else { yyb281 = z.DecCheckBreak() } if yyb281 { z.DecReadArrayEnd() return } z.DecReadArrayElem() x.FInt16 = (int16)(z.C.IntV(r.DecodeInt64(), 16)) yyj281++ if yyhl281 { yyb281 = yyj281 > l } else { yyb281 = z.DecCheckBreak() } if yyb281 { z.DecReadArrayEnd() return } z.DecReadArrayElem() if r.TryNil() { if x.FptrInt16 != nil { // remove the if-true x.FptrInt16 = nil } } else { if x.FptrInt16 == nil { x.FptrInt16 = new(int16) } *x.FptrInt16 = (int16)(z.C.IntV(r.DecodeInt64(), 16)) } yyj281++ if yyhl281 { yyb281 = yyj281 > l } else { yyb281 = z.DecCheckBreak() } if yyb281 { z.DecReadArrayEnd() return } z.DecReadArrayElem() x.FInt32 = (int32)(z.C.IntV(r.DecodeInt64(), 32)) yyj281++ if yyhl281 { yyb281 = yyj281 > l } else { yyb281 = z.DecCheckBreak() } if yyb281 { z.DecReadArrayEnd() return } z.DecReadArrayElem() if r.TryNil() { if x.FptrInt32 != nil { // remove the if-true x.FptrInt32 = nil } } else { if x.FptrInt32 == nil { x.FptrInt32 = new(int32) } *x.FptrInt32 = (int32)(z.C.IntV(r.DecodeInt64(), 32)) } yyj281++ if yyhl281 { yyb281 = yyj281 > l } else { yyb281 = z.DecCheckBreak() } if yyb281 { z.DecReadArrayEnd() return } z.DecReadArrayElem() x.FInt64 = (int64)(r.DecodeInt64()) yyj281++ if yyhl281 { yyb281 = yyj281 > l } else { yyb281 = z.DecCheckBreak() } if yyb281 { z.DecReadArrayEnd() return } z.DecReadArrayElem() if r.TryNil() { if x.FptrInt64 != nil { // remove the if-true x.FptrInt64 = nil } } else { if x.FptrInt64 == nil { x.FptrInt64 = new(int64) } *x.FptrInt64 = (int64)(r.DecodeInt64()) } yyj281++ if yyhl281 { yyb281 = yyj281 > l } else { yyb281 = z.DecCheckBreak() } if yyb281 { z.DecReadArrayEnd() return } z.DecReadArrayElem() x.FBool = (bool)(r.DecodeBool()) yyj281++ if yyhl281 { yyb281 = yyj281 > l } else { yyb281 = z.DecCheckBreak() } if yyb281 { z.DecReadArrayEnd() return } z.DecReadArrayElem() if r.TryNil() { if x.FptrBool != nil { // remove the if-true x.FptrBool = nil } } else { if x.FptrBool == nil { x.FptrBool = new(bool) } *x.FptrBool = (bool)(r.DecodeBool()) } yyj281++ if yyhl281 { yyb281 = yyj281 > l } else { yyb281 = z.DecCheckBreak() } if yyb281 { z.DecReadArrayEnd() return } z.DecReadArrayElem() z.F.DecSliceIntfX(&x.FSliceIntf, d) yyj281++ if yyhl281 { yyb281 = yyj281 > l } else { yyb281 = z.DecCheckBreak() } if yyb281 { z.DecReadArrayEnd() return } z.DecReadArrayElem() if r.TryNil() { if x.FptrSliceIntf != nil { // remove the if-true x.FptrSliceIntf = nil } } else { if x.FptrSliceIntf == nil { x.FptrSliceIntf = new([]interface{}) } z.F.DecSliceIntfX(x.FptrSliceIntf, d) } yyj281++ if yyhl281 { yyb281 = yyj281 > l } else { yyb281 = z.DecCheckBreak() } if yyb281 { z.DecReadArrayEnd() return } z.DecReadArrayElem() z.F.DecSliceStringX(&x.FSliceString, d) yyj281++ if yyhl281 { yyb281 = yyj281 > l } else { yyb281 = z.DecCheckBreak() } if yyb281 { z.DecReadArrayEnd() return } z.DecReadArrayElem() if r.TryNil() { if x.FptrSliceString != nil { // remove the if-true x.FptrSliceString = nil } } else { if x.FptrSliceString == nil { x.FptrSliceString = new([]string) } z.F.DecSliceStringX(x.FptrSliceString, d) } yyj281++ if yyhl281 { yyb281 = yyj281 > l } else { yyb281 = z.DecCheckBreak() } if yyb281 { z.DecReadArrayEnd() return } z.DecReadArrayElem() z.F.DecSliceBytesX(&x.FSliceBytes, d) yyj281++ if yyhl281 { yyb281 = yyj281 > l } else { yyb281 = z.DecCheckBreak() } if yyb281 { z.DecReadArrayEnd() return } z.DecReadArrayElem() if r.TryNil() { if x.FptrSliceBytes != nil { // remove the if-true x.FptrSliceBytes = nil } } else { if x.FptrSliceBytes == nil { x.FptrSliceBytes = new([][]uint8) } z.F.DecSliceBytesX(x.FptrSliceBytes, d) } yyj281++ if yyhl281 { yyb281 = yyj281 > l } else { yyb281 = z.DecCheckBreak() } if yyb281 { z.DecReadArrayEnd() return } z.DecReadArrayElem() z.F.DecSliceFloat32X(&x.FSliceFloat32, d) yyj281++ if yyhl281 { yyb281 = yyj281 > l } else { yyb281 = z.DecCheckBreak() } if yyb281 { z.DecReadArrayEnd() return } z.DecReadArrayElem() if r.TryNil() { if x.FptrSliceFloat32 != nil { // remove the if-true x.FptrSliceFloat32 = nil } } else { if x.FptrSliceFloat32 == nil { x.FptrSliceFloat32 = new([]float32) } z.F.DecSliceFloat32X(x.FptrSliceFloat32, d) } yyj281++ if yyhl281 { yyb281 = yyj281 > l } else { yyb281 = z.DecCheckBreak() } if yyb281 { z.DecReadArrayEnd() return } z.DecReadArrayElem() z.F.DecSliceFloat64X(&x.FSliceFloat64, d) yyj281++ if yyhl281 { yyb281 = yyj281 > l } else { yyb281 = z.DecCheckBreak() } if yyb281 { z.DecReadArrayEnd() return } z.DecReadArrayElem() if r.TryNil() { if x.FptrSliceFloat64 != nil { // remove the if-true x.FptrSliceFloat64 = nil } } else { if x.FptrSliceFloat64 == nil { x.FptrSliceFloat64 = new([]float64) } z.F.DecSliceFloat64X(x.FptrSliceFloat64, d) } yyj281++ if yyhl281 { yyb281 = yyj281 > l } else { yyb281 = z.DecCheckBreak() } if yyb281 { z.DecReadArrayEnd() return } z.DecReadArrayElem() x.FSliceUint8 = z.DecodeBytesInto(([]byte)(x.FSliceUint8)) yyj281++ if yyhl281 { yyb281 = yyj281 > l } else { yyb281 = z.DecCheckBreak() } if yyb281 { z.DecReadArrayEnd() return } z.DecReadArrayElem() if r.TryNil() { if x.FptrSliceUint8 != nil { // remove the if-true x.FptrSliceUint8 = nil } } else { if x.FptrSliceUint8 == nil { x.FptrSliceUint8 = new([]uint8) } *x.FptrSliceUint8 = z.DecodeBytesInto(*(*[]byte)(x.FptrSliceUint8)) } yyj281++ if yyhl281 { yyb281 = yyj281 > l } else { yyb281 = z.DecCheckBreak() } if yyb281 { z.DecReadArrayEnd() return } z.DecReadArrayElem() z.F.DecSliceUint64X(&x.FSliceUint64, d) yyj281++ if yyhl281 { yyb281 = yyj281 > l } else { yyb281 = z.DecCheckBreak() } if yyb281 { z.DecReadArrayEnd() return } z.DecReadArrayElem() if r.TryNil() { if x.FptrSliceUint64 != nil { // remove the if-true x.FptrSliceUint64 = nil } } else { if x.FptrSliceUint64 == nil { x.FptrSliceUint64 = new([]uint64) } z.F.DecSliceUint64X(x.FptrSliceUint64, d) } yyj281++ if yyhl281 { yyb281 = yyj281 > l } else { yyb281 = z.DecCheckBreak() } if yyb281 { z.DecReadArrayEnd() return } z.DecReadArrayElem() z.F.DecSliceIntX(&x.FSliceInt, d) yyj281++ if yyhl281 { yyb281 = yyj281 > l } else { yyb281 = z.DecCheckBreak() } if yyb281 { z.DecReadArrayEnd() return } z.DecReadArrayElem() if r.TryNil() { if x.FptrSliceInt != nil { // remove the if-true x.FptrSliceInt = nil } } else { if x.FptrSliceInt == nil { x.FptrSliceInt = new([]int) } z.F.DecSliceIntX(x.FptrSliceInt, d) } yyj281++ if yyhl281 { yyb281 = yyj281 > l } else { yyb281 = z.DecCheckBreak() } if yyb281 { z.DecReadArrayEnd() return } z.DecReadArrayElem() z.F.DecSliceInt32X(&x.FSliceInt32, d) yyj281++ if yyhl281 { yyb281 = yyj281 > l } else { yyb281 = z.DecCheckBreak() } if yyb281 { z.DecReadArrayEnd() return } z.DecReadArrayElem() if r.TryNil() { if x.FptrSliceInt32 != nil { // remove the if-true x.FptrSliceInt32 = nil } } else { if x.FptrSliceInt32 == nil { x.FptrSliceInt32 = new([]int32) } z.F.DecSliceInt32X(x.FptrSliceInt32, d) } yyj281++ if yyhl281 { yyb281 = yyj281 > l } else { yyb281 = z.DecCheckBreak() } if yyb281 { z.DecReadArrayEnd() return } z.DecReadArrayElem() z.F.DecSliceInt64X(&x.FSliceInt64, d) yyj281++ if yyhl281 { yyb281 = yyj281 > l } else { yyb281 = z.DecCheckBreak() } if yyb281 { z.DecReadArrayEnd() return } z.DecReadArrayElem() if r.TryNil() { if x.FptrSliceInt64 != nil { // remove the if-true x.FptrSliceInt64 = nil } } else { if x.FptrSliceInt64 == nil { x.FptrSliceInt64 = new([]int64) } z.F.DecSliceInt64X(x.FptrSliceInt64, d) } yyj281++ if yyhl281 { yyb281 = yyj281 > l } else { yyb281 = z.DecCheckBreak() } if yyb281 { z.DecReadArrayEnd() return } z.DecReadArrayElem() z.F.DecSliceBoolX(&x.FSliceBool, d) yyj281++ if yyhl281 { yyb281 = yyj281 > l } else { yyb281 = z.DecCheckBreak() } if yyb281 { z.DecReadArrayEnd() return } z.DecReadArrayElem() if r.TryNil() { if x.FptrSliceBool != nil { // remove the if-true x.FptrSliceBool = nil } } else { if x.FptrSliceBool == nil { x.FptrSliceBool = new([]bool) } z.F.DecSliceBoolX(x.FptrSliceBool, d) } yyj281++ if yyhl281 { yyb281 = yyj281 > l } else { yyb281 = z.DecCheckBreak() } if yyb281 { z.DecReadArrayEnd() return } z.DecReadArrayElem() z.F.DecMapStringIntfX(&x.FMapStringIntf, d) yyj281++ if yyhl281 { yyb281 = yyj281 > l } else { yyb281 = z.DecCheckBreak() } if yyb281 { z.DecReadArrayEnd() return } z.DecReadArrayElem() if r.TryNil() { if x.FptrMapStringIntf != nil { // remove the if-true x.FptrMapStringIntf = nil } } else { if x.FptrMapStringIntf == nil { x.FptrMapStringIntf = new(map[string]interface{}) } z.F.DecMapStringIntfX(x.FptrMapStringIntf, d) } yyj281++ if yyhl281 { yyb281 = yyj281 > l } else { yyb281 = z.DecCheckBreak() } if yyb281 { z.DecReadArrayEnd() return } z.DecReadArrayElem() z.F.DecMapStringStringX(&x.FMapStringString, d) yyj281++ if yyhl281 { yyb281 = yyj281 > l } else { yyb281 = z.DecCheckBreak() } if yyb281 { z.DecReadArrayEnd() return } z.DecReadArrayElem() if r.TryNil() { if x.FptrMapStringString != nil { // remove the if-true x.FptrMapStringString = nil } } else { if x.FptrMapStringString == nil { x.FptrMapStringString = new(map[string]string) } z.F.DecMapStringStringX(x.FptrMapStringString, d) } yyj281++ if yyhl281 { yyb281 = yyj281 > l } else { yyb281 = z.DecCheckBreak() } if yyb281 { z.DecReadArrayEnd() return } z.DecReadArrayElem() z.F.DecMapStringBytesX(&x.FMapStringBytes, d) yyj281++ if yyhl281 { yyb281 = yyj281 > l } else { yyb281 = z.DecCheckBreak() } if yyb281 { z.DecReadArrayEnd() return } z.DecReadArrayElem() if r.TryNil() { if x.FptrMapStringBytes != nil { // remove the if-true x.FptrMapStringBytes = nil } } else { if x.FptrMapStringBytes == nil { x.FptrMapStringBytes = new(map[string][]uint8) } z.F.DecMapStringBytesX(x.FptrMapStringBytes, d) } yyj281++ if yyhl281 { yyb281 = yyj281 > l } else { yyb281 = z.DecCheckBreak() } if yyb281 { z.DecReadArrayEnd() return } z.DecReadArrayElem() z.F.DecMapStringUint8X(&x.FMapStringUint8, d) yyj281++ if yyhl281 { yyb281 = yyj281 > l } else { yyb281 = z.DecCheckBreak() } if yyb281 { z.DecReadArrayEnd() return } z.DecReadArrayElem() if r.TryNil() { if x.FptrMapStringUint8 != nil { // remove the if-true x.FptrMapStringUint8 = nil } } else { if x.FptrMapStringUint8 == nil { x.FptrMapStringUint8 = new(map[string]uint8) } z.F.DecMapStringUint8X(x.FptrMapStringUint8, d) } yyj281++ if yyhl281 { yyb281 = yyj281 > l } else { yyb281 = z.DecCheckBreak() } if yyb281 { z.DecReadArrayEnd() return } z.DecReadArrayElem() z.F.DecMapStringUint64X(&x.FMapStringUint64, d) yyj281++ if yyhl281 { yyb281 = yyj281 > l } else { yyb281 = z.DecCheckBreak() } if yyb281 { z.DecReadArrayEnd() return } z.DecReadArrayElem() if r.TryNil() { if x.FptrMapStringUint64 != nil { // remove the if-true x.FptrMapStringUint64 = nil } } else { if x.FptrMapStringUint64 == nil { x.FptrMapStringUint64 = new(map[string]uint64) } z.F.DecMapStringUint64X(x.FptrMapStringUint64, d) } yyj281++ if yyhl281 { yyb281 = yyj281 > l } else { yyb281 = z.DecCheckBreak() } if yyb281 { z.DecReadArrayEnd() return } z.DecReadArrayElem() z.F.DecMapStringIntX(&x.FMapStringInt, d) yyj281++ if yyhl281 { yyb281 = yyj281 > l } else { yyb281 = z.DecCheckBreak() } if yyb281 { z.DecReadArrayEnd() return } z.DecReadArrayElem() if r.TryNil() { if x.FptrMapStringInt != nil { // remove the if-true x.FptrMapStringInt = nil } } else { if x.FptrMapStringInt == nil { x.FptrMapStringInt = new(map[string]int) } z.F.DecMapStringIntX(x.FptrMapStringInt, d) } yyj281++ if yyhl281 { yyb281 = yyj281 > l } else { yyb281 = z.DecCheckBreak() } if yyb281 { z.DecReadArrayEnd() return } z.DecReadArrayElem() z.F.DecMapStringInt32X(&x.FMapStringInt32, d) yyj281++ if yyhl281 { yyb281 = yyj281 > l } else { yyb281 = z.DecCheckBreak() } if yyb281 { z.DecReadArrayEnd() return } z.DecReadArrayElem() if r.TryNil() { if x.FptrMapStringInt32 != nil { // remove the if-true x.FptrMapStringInt32 = nil } } else { if x.FptrMapStringInt32 == nil { x.FptrMapStringInt32 = new(map[string]int32) } z.F.DecMapStringInt32X(x.FptrMapStringInt32, d) } yyj281++ if yyhl281 { yyb281 = yyj281 > l } else { yyb281 = z.DecCheckBreak() } if yyb281 { z.DecReadArrayEnd() return } z.DecReadArrayElem() z.F.DecMapStringFloat64X(&x.FMapStringFloat64, d) yyj281++ if yyhl281 { yyb281 = yyj281 > l } else { yyb281 = z.DecCheckBreak() } if yyb281 { z.DecReadArrayEnd() return } z.DecReadArrayElem() if r.TryNil() { if x.FptrMapStringFloat64 != nil { // remove the if-true x.FptrMapStringFloat64 = nil } } else { if x.FptrMapStringFloat64 == nil { x.FptrMapStringFloat64 = new(map[string]float64) } z.F.DecMapStringFloat64X(x.FptrMapStringFloat64, d) } yyj281++ if yyhl281 { yyb281 = yyj281 > l } else { yyb281 = z.DecCheckBreak() } if yyb281 { z.DecReadArrayEnd() return } z.DecReadArrayElem() z.F.DecMapStringBoolX(&x.FMapStringBool, d) yyj281++ if yyhl281 { yyb281 = yyj281 > l } else { yyb281 = z.DecCheckBreak() } if yyb281 { z.DecReadArrayEnd() return } z.DecReadArrayElem() if r.TryNil() { if x.FptrMapStringBool != nil { // remove the if-true x.FptrMapStringBool = nil } } else { if x.FptrMapStringBool == nil { x.FptrMapStringBool = new(map[string]bool) } z.F.DecMapStringBoolX(x.FptrMapStringBool, d) } yyj281++ if yyhl281 { yyb281 = yyj281 > l } else { yyb281 = z.DecCheckBreak() } if yyb281 { z.DecReadArrayEnd() return } z.DecReadArrayElem() z.F.DecMapUint8IntfX(&x.FMapUint8Intf, d) yyj281++ if yyhl281 { yyb281 = yyj281 > l } else { yyb281 = z.DecCheckBreak() } if yyb281 { z.DecReadArrayEnd() return } z.DecReadArrayElem() if r.TryNil() { if x.FptrMapUint8Intf != nil { // remove the if-true x.FptrMapUint8Intf = nil } } else { if x.FptrMapUint8Intf == nil { x.FptrMapUint8Intf = new(map[uint8]interface{}) } z.F.DecMapUint8IntfX(x.FptrMapUint8Intf, d) } yyj281++ if yyhl281 { yyb281 = yyj281 > l } else { yyb281 = z.DecCheckBreak() } if yyb281 { z.DecReadArrayEnd() return } z.DecReadArrayElem() z.F.DecMapUint8StringX(&x.FMapUint8String, d) yyj281++ if yyhl281 { yyb281 = yyj281 > l } else { yyb281 = z.DecCheckBreak() } if yyb281 { z.DecReadArrayEnd() return } z.DecReadArrayElem() if r.TryNil() { if x.FptrMapUint8String != nil { // remove the if-true x.FptrMapUint8String = nil } } else { if x.FptrMapUint8String == nil { x.FptrMapUint8String = new(map[uint8]string) } z.F.DecMapUint8StringX(x.FptrMapUint8String, d) } yyj281++ if yyhl281 { yyb281 = yyj281 > l } else { yyb281 = z.DecCheckBreak() } if yyb281 { z.DecReadArrayEnd() return } z.DecReadArrayElem() z.F.DecMapUint8BytesX(&x.FMapUint8Bytes, d) yyj281++ if yyhl281 { yyb281 = yyj281 > l } else { yyb281 = z.DecCheckBreak() } if yyb281 { z.DecReadArrayEnd() return } z.DecReadArrayElem() if r.TryNil() { if x.FptrMapUint8Bytes != nil { // remove the if-true x.FptrMapUint8Bytes = nil } } else { if x.FptrMapUint8Bytes == nil { x.FptrMapUint8Bytes = new(map[uint8][]uint8) } z.F.DecMapUint8BytesX(x.FptrMapUint8Bytes, d) } yyj281++ if yyhl281 { yyb281 = yyj281 > l } else { yyb281 = z.DecCheckBreak() } if yyb281 { z.DecReadArrayEnd() return } z.DecReadArrayElem() z.F.DecMapUint8Uint8X(&x.FMapUint8Uint8, d) yyj281++ if yyhl281 { yyb281 = yyj281 > l } else { yyb281 = z.DecCheckBreak() } if yyb281 { z.DecReadArrayEnd() return } z.DecReadArrayElem() if r.TryNil() { if x.FptrMapUint8Uint8 != nil { // remove the if-true x.FptrMapUint8Uint8 = nil } } else { if x.FptrMapUint8Uint8 == nil { x.FptrMapUint8Uint8 = new(map[uint8]uint8) } z.F.DecMapUint8Uint8X(x.FptrMapUint8Uint8, d) } yyj281++ if yyhl281 { yyb281 = yyj281 > l } else { yyb281 = z.DecCheckBreak() } if yyb281 { z.DecReadArrayEnd() return } z.DecReadArrayElem() z.F.DecMapUint8Uint64X(&x.FMapUint8Uint64, d) yyj281++ if yyhl281 { yyb281 = yyj281 > l } else { yyb281 = z.DecCheckBreak() } if yyb281 { z.DecReadArrayEnd() return } z.DecReadArrayElem() if r.TryNil() { if x.FptrMapUint8Uint64 != nil { // remove the if-true x.FptrMapUint8Uint64 = nil } } else { if x.FptrMapUint8Uint64 == nil { x.FptrMapUint8Uint64 = new(map[uint8]uint64) } z.F.DecMapUint8Uint64X(x.FptrMapUint8Uint64, d) } yyj281++ if yyhl281 { yyb281 = yyj281 > l } else { yyb281 = z.DecCheckBreak() } if yyb281 { z.DecReadArrayEnd() return } z.DecReadArrayElem() z.F.DecMapUint8IntX(&x.FMapUint8Int, d) yyj281++ if yyhl281 { yyb281 = yyj281 > l } else { yyb281 = z.DecCheckBreak() } if yyb281 { z.DecReadArrayEnd() return } z.DecReadArrayElem() if r.TryNil() { if x.FptrMapUint8Int != nil { // remove the if-true x.FptrMapUint8Int = nil } } else { if x.FptrMapUint8Int == nil { x.FptrMapUint8Int = new(map[uint8]int) } z.F.DecMapUint8IntX(x.FptrMapUint8Int, d) } yyj281++ if yyhl281 { yyb281 = yyj281 > l } else { yyb281 = z.DecCheckBreak() } if yyb281 { z.DecReadArrayEnd() return } z.DecReadArrayElem() z.F.DecMapUint8Int32X(&x.FMapUint8Int32, d) yyj281++ if yyhl281 { yyb281 = yyj281 > l } else { yyb281 = z.DecCheckBreak() } if yyb281 { z.DecReadArrayEnd() return } z.DecReadArrayElem() if r.TryNil() { if x.FptrMapUint8Int32 != nil { // remove the if-true x.FptrMapUint8Int32 = nil } } else { if x.FptrMapUint8Int32 == nil { x.FptrMapUint8Int32 = new(map[uint8]int32) } z.F.DecMapUint8Int32X(x.FptrMapUint8Int32, d) } yyj281++ if yyhl281 { yyb281 = yyj281 > l } else { yyb281 = z.DecCheckBreak() } if yyb281 { z.DecReadArrayEnd() return } z.DecReadArrayElem() z.F.DecMapUint8Float64X(&x.FMapUint8Float64, d) yyj281++ if yyhl281 { yyb281 = yyj281 > l } else { yyb281 = z.DecCheckBreak() } if yyb281 { z.DecReadArrayEnd() return } z.DecReadArrayElem() if r.TryNil() { if x.FptrMapUint8Float64 != nil { // remove the if-true x.FptrMapUint8Float64 = nil } } else { if x.FptrMapUint8Float64 == nil { x.FptrMapUint8Float64 = new(map[uint8]float64) } z.F.DecMapUint8Float64X(x.FptrMapUint8Float64, d) } yyj281++ if yyhl281 { yyb281 = yyj281 > l } else { yyb281 = z.DecCheckBreak() } if yyb281 { z.DecReadArrayEnd() return } z.DecReadArrayElem() z.F.DecMapUint8BoolX(&x.FMapUint8Bool, d) yyj281++ if yyhl281 { yyb281 = yyj281 > l } else { yyb281 = z.DecCheckBreak() } if yyb281 { z.DecReadArrayEnd() return } z.DecReadArrayElem() if r.TryNil() { if x.FptrMapUint8Bool != nil { // remove the if-true x.FptrMapUint8Bool = nil } } else { if x.FptrMapUint8Bool == nil { x.FptrMapUint8Bool = new(map[uint8]bool) } z.F.DecMapUint8BoolX(x.FptrMapUint8Bool, d) } yyj281++ if yyhl281 { yyb281 = yyj281 > l } else { yyb281 = z.DecCheckBreak() } if yyb281 { z.DecReadArrayEnd() return } z.DecReadArrayElem() z.F.DecMapUint64IntfX(&x.FMapUint64Intf, d) yyj281++ if yyhl281 { yyb281 = yyj281 > l } else { yyb281 = z.DecCheckBreak() } if yyb281 { z.DecReadArrayEnd() return } z.DecReadArrayElem() if r.TryNil() { if x.FptrMapUint64Intf != nil { // remove the if-true x.FptrMapUint64Intf = nil } } else { if x.FptrMapUint64Intf == nil { x.FptrMapUint64Intf = new(map[uint64]interface{}) } z.F.DecMapUint64IntfX(x.FptrMapUint64Intf, d) } yyj281++ if yyhl281 { yyb281 = yyj281 > l } else { yyb281 = z.DecCheckBreak() } if yyb281 { z.DecReadArrayEnd() return } z.DecReadArrayElem() z.F.DecMapUint64StringX(&x.FMapUint64String, d) yyj281++ if yyhl281 { yyb281 = yyj281 > l } else { yyb281 = z.DecCheckBreak() } if yyb281 { z.DecReadArrayEnd() return } z.DecReadArrayElem() if r.TryNil() { if x.FptrMapUint64String != nil { // remove the if-true x.FptrMapUint64String = nil } } else { if x.FptrMapUint64String == nil { x.FptrMapUint64String = new(map[uint64]string) } z.F.DecMapUint64StringX(x.FptrMapUint64String, d) } yyj281++ if yyhl281 { yyb281 = yyj281 > l } else { yyb281 = z.DecCheckBreak() } if yyb281 { z.DecReadArrayEnd() return } z.DecReadArrayElem() z.F.DecMapUint64BytesX(&x.FMapUint64Bytes, d) yyj281++ if yyhl281 { yyb281 = yyj281 > l } else { yyb281 = z.DecCheckBreak() } if yyb281 { z.DecReadArrayEnd() return } z.DecReadArrayElem() if r.TryNil() { if x.FptrMapUint64Bytes != nil { // remove the if-true x.FptrMapUint64Bytes = nil } } else { if x.FptrMapUint64Bytes == nil { x.FptrMapUint64Bytes = new(map[uint64][]uint8) } z.F.DecMapUint64BytesX(x.FptrMapUint64Bytes, d) } yyj281++ if yyhl281 { yyb281 = yyj281 > l } else { yyb281 = z.DecCheckBreak() } if yyb281 { z.DecReadArrayEnd() return } z.DecReadArrayElem() z.F.DecMapUint64Uint8X(&x.FMapUint64Uint8, d) yyj281++ if yyhl281 { yyb281 = yyj281 > l } else { yyb281 = z.DecCheckBreak() } if yyb281 { z.DecReadArrayEnd() return } z.DecReadArrayElem() if r.TryNil() { if x.FptrMapUint64Uint8 != nil { // remove the if-true x.FptrMapUint64Uint8 = nil } } else { if x.FptrMapUint64Uint8 == nil { x.FptrMapUint64Uint8 = new(map[uint64]uint8) } z.F.DecMapUint64Uint8X(x.FptrMapUint64Uint8, d) } yyj281++ if yyhl281 { yyb281 = yyj281 > l } else { yyb281 = z.DecCheckBreak() } if yyb281 { z.DecReadArrayEnd() return } z.DecReadArrayElem() z.F.DecMapUint64Uint64X(&x.FMapUint64Uint64, d) yyj281++ if yyhl281 { yyb281 = yyj281 > l } else { yyb281 = z.DecCheckBreak() } if yyb281 { z.DecReadArrayEnd() return } z.DecReadArrayElem() if r.TryNil() { if x.FptrMapUint64Uint64 != nil { // remove the if-true x.FptrMapUint64Uint64 = nil } } else { if x.FptrMapUint64Uint64 == nil { x.FptrMapUint64Uint64 = new(map[uint64]uint64) } z.F.DecMapUint64Uint64X(x.FptrMapUint64Uint64, d) } yyj281++ if yyhl281 { yyb281 = yyj281 > l } else { yyb281 = z.DecCheckBreak() } if yyb281 { z.DecReadArrayEnd() return } z.DecReadArrayElem() z.F.DecMapUint64IntX(&x.FMapUint64Int, d) yyj281++ if yyhl281 { yyb281 = yyj281 > l } else { yyb281 = z.DecCheckBreak() } if yyb281 { z.DecReadArrayEnd() return } z.DecReadArrayElem() if r.TryNil() { if x.FptrMapUint64Int != nil { // remove the if-true x.FptrMapUint64Int = nil } } else { if x.FptrMapUint64Int == nil { x.FptrMapUint64Int = new(map[uint64]int) } z.F.DecMapUint64IntX(x.FptrMapUint64Int, d) } yyj281++ if yyhl281 { yyb281 = yyj281 > l } else { yyb281 = z.DecCheckBreak() } if yyb281 { z.DecReadArrayEnd() return } z.DecReadArrayElem() z.F.DecMapUint64Int32X(&x.FMapUint64Int32, d) yyj281++ if yyhl281 { yyb281 = yyj281 > l } else { yyb281 = z.DecCheckBreak() } if yyb281 { z.DecReadArrayEnd() return } z.DecReadArrayElem() if r.TryNil() { if x.FptrMapUint64Int32 != nil { // remove the if-true x.FptrMapUint64Int32 = nil } } else { if x.FptrMapUint64Int32 == nil { x.FptrMapUint64Int32 = new(map[uint64]int32) } z.F.DecMapUint64Int32X(x.FptrMapUint64Int32, d) } yyj281++ if yyhl281 { yyb281 = yyj281 > l } else { yyb281 = z.DecCheckBreak() } if yyb281 { z.DecReadArrayEnd() return } z.DecReadArrayElem() z.F.DecMapUint64Float64X(&x.FMapUint64Float64, d) yyj281++ if yyhl281 { yyb281 = yyj281 > l } else { yyb281 = z.DecCheckBreak() } if yyb281 { z.DecReadArrayEnd() return } z.DecReadArrayElem() if r.TryNil() { if x.FptrMapUint64Float64 != nil { // remove the if-true x.FptrMapUint64Float64 = nil } } else { if x.FptrMapUint64Float64 == nil { x.FptrMapUint64Float64 = new(map[uint64]float64) } z.F.DecMapUint64Float64X(x.FptrMapUint64Float64, d) } yyj281++ if yyhl281 { yyb281 = yyj281 > l } else { yyb281 = z.DecCheckBreak() } if yyb281 { z.DecReadArrayEnd() return } z.DecReadArrayElem() z.F.DecMapUint64BoolX(&x.FMapUint64Bool, d) yyj281++ if yyhl281 { yyb281 = yyj281 > l } else { yyb281 = z.DecCheckBreak() } if yyb281 { z.DecReadArrayEnd() return } z.DecReadArrayElem() if r.TryNil() { if x.FptrMapUint64Bool != nil { // remove the if-true x.FptrMapUint64Bool = nil } } else { if x.FptrMapUint64Bool == nil { x.FptrMapUint64Bool = new(map[uint64]bool) } z.F.DecMapUint64BoolX(x.FptrMapUint64Bool, d) } yyj281++ if yyhl281 { yyb281 = yyj281 > l } else { yyb281 = z.DecCheckBreak() } if yyb281 { z.DecReadArrayEnd() return } z.DecReadArrayElem() z.F.DecMapIntIntfX(&x.FMapIntIntf, d) yyj281++ if yyhl281 { yyb281 = yyj281 > l } else { yyb281 = z.DecCheckBreak() } if yyb281 { z.DecReadArrayEnd() return } z.DecReadArrayElem() if r.TryNil() { if x.FptrMapIntIntf != nil { // remove the if-true x.FptrMapIntIntf = nil } } else { if x.FptrMapIntIntf == nil { x.FptrMapIntIntf = new(map[int]interface{}) } z.F.DecMapIntIntfX(x.FptrMapIntIntf, d) } yyj281++ if yyhl281 { yyb281 = yyj281 > l } else { yyb281 = z.DecCheckBreak() } if yyb281 { z.DecReadArrayEnd() return } z.DecReadArrayElem() z.F.DecMapIntStringX(&x.FMapIntString, d) yyj281++ if yyhl281 { yyb281 = yyj281 > l } else { yyb281 = z.DecCheckBreak() } if yyb281 { z.DecReadArrayEnd() return } z.DecReadArrayElem() if r.TryNil() { if x.FptrMapIntString != nil { // remove the if-true x.FptrMapIntString = nil } } else { if x.FptrMapIntString == nil { x.FptrMapIntString = new(map[int]string) } z.F.DecMapIntStringX(x.FptrMapIntString, d) } yyj281++ if yyhl281 { yyb281 = yyj281 > l } else { yyb281 = z.DecCheckBreak() } if yyb281 { z.DecReadArrayEnd() return } z.DecReadArrayElem() z.F.DecMapIntBytesX(&x.FMapIntBytes, d) yyj281++ if yyhl281 { yyb281 = yyj281 > l } else { yyb281 = z.DecCheckBreak() } if yyb281 { z.DecReadArrayEnd() return } z.DecReadArrayElem() if r.TryNil() { if x.FptrMapIntBytes != nil { // remove the if-true x.FptrMapIntBytes = nil } } else { if x.FptrMapIntBytes == nil { x.FptrMapIntBytes = new(map[int][]uint8) } z.F.DecMapIntBytesX(x.FptrMapIntBytes, d) } yyj281++ if yyhl281 { yyb281 = yyj281 > l } else { yyb281 = z.DecCheckBreak() } if yyb281 { z.DecReadArrayEnd() return } z.DecReadArrayElem() z.F.DecMapIntUint8X(&x.FMapIntUint8, d) yyj281++ if yyhl281 { yyb281 = yyj281 > l } else { yyb281 = z.DecCheckBreak() } if yyb281 { z.DecReadArrayEnd() return } z.DecReadArrayElem() if r.TryNil() { if x.FptrMapIntUint8 != nil { // remove the if-true x.FptrMapIntUint8 = nil } } else { if x.FptrMapIntUint8 == nil { x.FptrMapIntUint8 = new(map[int]uint8) } z.F.DecMapIntUint8X(x.FptrMapIntUint8, d) } yyj281++ if yyhl281 { yyb281 = yyj281 > l } else { yyb281 = z.DecCheckBreak() } if yyb281 { z.DecReadArrayEnd() return } z.DecReadArrayElem() z.F.DecMapIntUint64X(&x.FMapIntUint64, d) yyj281++ if yyhl281 { yyb281 = yyj281 > l } else { yyb281 = z.DecCheckBreak() } if yyb281 { z.DecReadArrayEnd() return } z.DecReadArrayElem() if r.TryNil() { if x.FptrMapIntUint64 != nil { // remove the if-true x.FptrMapIntUint64 = nil } } else { if x.FptrMapIntUint64 == nil { x.FptrMapIntUint64 = new(map[int]uint64) } z.F.DecMapIntUint64X(x.FptrMapIntUint64, d) } yyj281++ if yyhl281 { yyb281 = yyj281 > l } else { yyb281 = z.DecCheckBreak() } if yyb281 { z.DecReadArrayEnd() return } z.DecReadArrayElem() z.F.DecMapIntIntX(&x.FMapIntInt, d) yyj281++ if yyhl281 { yyb281 = yyj281 > l } else { yyb281 = z.DecCheckBreak() } if yyb281 { z.DecReadArrayEnd() return } z.DecReadArrayElem() if r.TryNil() { if x.FptrMapIntInt != nil { // remove the if-true x.FptrMapIntInt = nil } } else { if x.FptrMapIntInt == nil { x.FptrMapIntInt = new(map[int]int) } z.F.DecMapIntIntX(x.FptrMapIntInt, d) } yyj281++ if yyhl281 { yyb281 = yyj281 > l } else { yyb281 = z.DecCheckBreak() } if yyb281 { z.DecReadArrayEnd() return } z.DecReadArrayElem() z.F.DecMapIntInt32X(&x.FMapIntInt32, d) yyj281++ if yyhl281 { yyb281 = yyj281 > l } else { yyb281 = z.DecCheckBreak() } if yyb281 { z.DecReadArrayEnd() return } z.DecReadArrayElem() if r.TryNil() { if x.FptrMapIntInt32 != nil { // remove the if-true x.FptrMapIntInt32 = nil } } else { if x.FptrMapIntInt32 == nil { x.FptrMapIntInt32 = new(map[int]int32) } z.F.DecMapIntInt32X(x.FptrMapIntInt32, d) } yyj281++ if yyhl281 { yyb281 = yyj281 > l } else { yyb281 = z.DecCheckBreak() } if yyb281 { z.DecReadArrayEnd() return } z.DecReadArrayElem() z.F.DecMapIntFloat64X(&x.FMapIntFloat64, d) yyj281++ if yyhl281 { yyb281 = yyj281 > l } else { yyb281 = z.DecCheckBreak() } if yyb281 { z.DecReadArrayEnd() return } z.DecReadArrayElem() if r.TryNil() { if x.FptrMapIntFloat64 != nil { // remove the if-true x.FptrMapIntFloat64 = nil } } else { if x.FptrMapIntFloat64 == nil { x.FptrMapIntFloat64 = new(map[int]float64) } z.F.DecMapIntFloat64X(x.FptrMapIntFloat64, d) } yyj281++ if yyhl281 { yyb281 = yyj281 > l } else { yyb281 = z.DecCheckBreak() } if yyb281 { z.DecReadArrayEnd() return } z.DecReadArrayElem() z.F.DecMapIntBoolX(&x.FMapIntBool, d) yyj281++ if yyhl281 { yyb281 = yyj281 > l } else { yyb281 = z.DecCheckBreak() } if yyb281 { z.DecReadArrayEnd() return } z.DecReadArrayElem() if r.TryNil() { if x.FptrMapIntBool != nil { // remove the if-true x.FptrMapIntBool = nil } } else { if x.FptrMapIntBool == nil { x.FptrMapIntBool = new(map[int]bool) } z.F.DecMapIntBoolX(x.FptrMapIntBool, d) } yyj281++ if yyhl281 { yyb281 = yyj281 > l } else { yyb281 = z.DecCheckBreak() } if yyb281 { z.DecReadArrayEnd() return } z.DecReadArrayElem() z.F.DecMapInt32IntfX(&x.FMapInt32Intf, d) yyj281++ if yyhl281 { yyb281 = yyj281 > l } else { yyb281 = z.DecCheckBreak() } if yyb281 { z.DecReadArrayEnd() return } z.DecReadArrayElem() if r.TryNil() { if x.FptrMapInt32Intf != nil { // remove the if-true x.FptrMapInt32Intf = nil } } else { if x.FptrMapInt32Intf == nil { x.FptrMapInt32Intf = new(map[int32]interface{}) } z.F.DecMapInt32IntfX(x.FptrMapInt32Intf, d) } yyj281++ if yyhl281 { yyb281 = yyj281 > l } else { yyb281 = z.DecCheckBreak() } if yyb281 { z.DecReadArrayEnd() return } z.DecReadArrayElem() z.F.DecMapInt32StringX(&x.FMapInt32String, d) yyj281++ if yyhl281 { yyb281 = yyj281 > l } else { yyb281 = z.DecCheckBreak() } if yyb281 { z.DecReadArrayEnd() return } z.DecReadArrayElem() if r.TryNil() { if x.FptrMapInt32String != nil { // remove the if-true x.FptrMapInt32String = nil } } else { if x.FptrMapInt32String == nil { x.FptrMapInt32String = new(map[int32]string) } z.F.DecMapInt32StringX(x.FptrMapInt32String, d) } yyj281++ if yyhl281 { yyb281 = yyj281 > l } else { yyb281 = z.DecCheckBreak() } if yyb281 { z.DecReadArrayEnd() return } z.DecReadArrayElem() z.F.DecMapInt32BytesX(&x.FMapInt32Bytes, d) yyj281++ if yyhl281 { yyb281 = yyj281 > l } else { yyb281 = z.DecCheckBreak() } if yyb281 { z.DecReadArrayEnd() return } z.DecReadArrayElem() if r.TryNil() { if x.FptrMapInt32Bytes != nil { // remove the if-true x.FptrMapInt32Bytes = nil } } else { if x.FptrMapInt32Bytes == nil { x.FptrMapInt32Bytes = new(map[int32][]uint8) } z.F.DecMapInt32BytesX(x.FptrMapInt32Bytes, d) } yyj281++ if yyhl281 { yyb281 = yyj281 > l } else { yyb281 = z.DecCheckBreak() } if yyb281 { z.DecReadArrayEnd() return } z.DecReadArrayElem() z.F.DecMapInt32Uint8X(&x.FMapInt32Uint8, d) yyj281++ if yyhl281 { yyb281 = yyj281 > l } else { yyb281 = z.DecCheckBreak() } if yyb281 { z.DecReadArrayEnd() return } z.DecReadArrayElem() if r.TryNil() { if x.FptrMapInt32Uint8 != nil { // remove the if-true x.FptrMapInt32Uint8 = nil } } else { if x.FptrMapInt32Uint8 == nil { x.FptrMapInt32Uint8 = new(map[int32]uint8) } z.F.DecMapInt32Uint8X(x.FptrMapInt32Uint8, d) } yyj281++ if yyhl281 { yyb281 = yyj281 > l } else { yyb281 = z.DecCheckBreak() } if yyb281 { z.DecReadArrayEnd() return } z.DecReadArrayElem() z.F.DecMapInt32Uint64X(&x.FMapInt32Uint64, d) yyj281++ if yyhl281 { yyb281 = yyj281 > l } else { yyb281 = z.DecCheckBreak() } if yyb281 { z.DecReadArrayEnd() return } z.DecReadArrayElem() if r.TryNil() { if x.FptrMapInt32Uint64 != nil { // remove the if-true x.FptrMapInt32Uint64 = nil } } else { if x.FptrMapInt32Uint64 == nil { x.FptrMapInt32Uint64 = new(map[int32]uint64) } z.F.DecMapInt32Uint64X(x.FptrMapInt32Uint64, d) } yyj281++ if yyhl281 { yyb281 = yyj281 > l } else { yyb281 = z.DecCheckBreak() } if yyb281 { z.DecReadArrayEnd() return } z.DecReadArrayElem() z.F.DecMapInt32IntX(&x.FMapInt32Int, d) yyj281++ if yyhl281 { yyb281 = yyj281 > l } else { yyb281 = z.DecCheckBreak() } if yyb281 { z.DecReadArrayEnd() return } z.DecReadArrayElem() if r.TryNil() { if x.FptrMapInt32Int != nil { // remove the if-true x.FptrMapInt32Int = nil } } else { if x.FptrMapInt32Int == nil { x.FptrMapInt32Int = new(map[int32]int) } z.F.DecMapInt32IntX(x.FptrMapInt32Int, d) } yyj281++ if yyhl281 { yyb281 = yyj281 > l } else { yyb281 = z.DecCheckBreak() } if yyb281 { z.DecReadArrayEnd() return } z.DecReadArrayElem() z.F.DecMapInt32Int32X(&x.FMapInt32Int32, d) yyj281++ if yyhl281 { yyb281 = yyj281 > l } else { yyb281 = z.DecCheckBreak() } if yyb281 { z.DecReadArrayEnd() return } z.DecReadArrayElem() if r.TryNil() { if x.FptrMapInt32Int32 != nil { // remove the if-true x.FptrMapInt32Int32 = nil } } else { if x.FptrMapInt32Int32 == nil { x.FptrMapInt32Int32 = new(map[int32]int32) } z.F.DecMapInt32Int32X(x.FptrMapInt32Int32, d) } yyj281++ if yyhl281 { yyb281 = yyj281 > l } else { yyb281 = z.DecCheckBreak() } if yyb281 { z.DecReadArrayEnd() return } z.DecReadArrayElem() z.F.DecMapInt32Float64X(&x.FMapInt32Float64, d) yyj281++ if yyhl281 { yyb281 = yyj281 > l } else { yyb281 = z.DecCheckBreak() } if yyb281 { z.DecReadArrayEnd() return } z.DecReadArrayElem() if r.TryNil() { if x.FptrMapInt32Float64 != nil { // remove the if-true x.FptrMapInt32Float64 = nil } } else { if x.FptrMapInt32Float64 == nil { x.FptrMapInt32Float64 = new(map[int32]float64) } z.F.DecMapInt32Float64X(x.FptrMapInt32Float64, d) } yyj281++ if yyhl281 { yyb281 = yyj281 > l } else { yyb281 = z.DecCheckBreak() } if yyb281 { z.DecReadArrayEnd() return } z.DecReadArrayElem() z.F.DecMapInt32BoolX(&x.FMapInt32Bool, d) yyj281++ if yyhl281 { yyb281 = yyj281 > l } else { yyb281 = z.DecCheckBreak() } if yyb281 { z.DecReadArrayEnd() return } z.DecReadArrayElem() if r.TryNil() { if x.FptrMapInt32Bool != nil { // remove the if-true x.FptrMapInt32Bool = nil } } else { if x.FptrMapInt32Bool == nil { x.FptrMapInt32Bool = new(map[int32]bool) } z.F.DecMapInt32BoolX(x.FptrMapInt32Bool, d) } for { yyj281++ if yyhl281 { yyb281 = yyj281 > l } else { yyb281 = z.DecCheckBreak() } if yyb281 { break } z.DecReadArrayElem() z.DecStructFieldNotFound(yyj281-1, "") } } func (x *TestMammoth2) IsCodecEmpty() bool { return !(x.FIntf != nil || x.FString != "" || len(x.FBytes) != 0 || x.FFloat32 != 0 || x.FFloat64 != 0 || x.FUint != 0 || x.FUint8 != 0 || x.FUint16 != 0 || x.FUint32 != 0 || x.FUint64 != 0 || x.FUintptr != 0 || x.FInt != 0 || x.FInt8 != 0 || x.FInt16 != 0 || x.FInt32 != 0 || x.FInt64 != 0 || bool(x.FBool) || len(x.FSliceIntf) != 0 || len(x.FSliceString) != 0 || len(x.FSliceBytes) != 0 || len(x.FSliceFloat32) != 0 || len(x.FSliceFloat64) != 0 || len(x.FSliceUint8) != 0 || len(x.FSliceUint64) != 0 || len(x.FSliceInt) != 0 || len(x.FSliceInt32) != 0 || len(x.FSliceInt64) != 0 || len(x.FSliceBool) != 0 || len(x.FMapStringIntf) != 0 || len(x.FMapStringString) != 0 || len(x.FMapStringBytes) != 0 || len(x.FMapStringUint8) != 0 || len(x.FMapStringUint64) != 0 || len(x.FMapStringInt) != 0 || len(x.FMapStringInt32) != 0 || len(x.FMapStringFloat64) != 0 || len(x.FMapStringBool) != 0 || len(x.FMapUint8Intf) != 0 || len(x.FMapUint8String) != 0 || len(x.FMapUint8Bytes) != 0 || len(x.FMapUint8Uint8) != 0 || len(x.FMapUint8Uint64) != 0 || len(x.FMapUint8Int) != 0 || len(x.FMapUint8Int32) != 0 || len(x.FMapUint8Float64) != 0 || len(x.FMapUint8Bool) != 0 || len(x.FMapUint64Intf) != 0 || len(x.FMapUint64String) != 0 || len(x.FMapUint64Bytes) != 0 || len(x.FMapUint64Uint8) != 0 || len(x.FMapUint64Uint64) != 0 || len(x.FMapUint64Int) != 0 || len(x.FMapUint64Int32) != 0 || len(x.FMapUint64Float64) != 0 || len(x.FMapUint64Bool) != 0 || len(x.FMapIntIntf) != 0 || len(x.FMapIntString) != 0 || len(x.FMapIntBytes) != 0 || len(x.FMapIntUint8) != 0 || len(x.FMapIntUint64) != 0 || len(x.FMapIntInt) != 0 || len(x.FMapIntInt32) != 0 || len(x.FMapIntFloat64) != 0 || len(x.FMapIntBool) != 0 || len(x.FMapInt32Intf) != 0 || len(x.FMapInt32String) != 0 || len(x.FMapInt32Bytes) != 0 || len(x.FMapInt32Uint8) != 0 || len(x.FMapInt32Uint64) != 0 || len(x.FMapInt32Int) != 0 || len(x.FMapInt32Int32) != 0 || len(x.FMapInt32Float64) != 0 || len(x.FMapInt32Bool) != 0 || false) } func (testMammoth2Binary) codecSelferViaCodecgen() {} func (x testMammoth2Binary) CodecEncodeSelf(e *Encoder) { var h codecSelfer19781 z, r := GenHelper().Encoder(e) _, _, _ = h, z, r if z.EncBinary() { z.EncBinaryMarshal(x) } else { r.EncodeUint(uint64(x)) } } func (x *testMammoth2Binary) CodecDecodeSelf(d *Decoder) { var h codecSelfer19781 z, r := GenHelper().Decoder(d) _, _, _ = h, z, r if z.DecBinary() { z.DecBinaryUnmarshal(x) } else { *x = (testMammoth2Binary)(r.DecodeUint64()) } } func (testMammoth2Text) codecSelferViaCodecgen() {} func (x testMammoth2Text) CodecEncodeSelf(e *Encoder) { var h codecSelfer19781 z, r := GenHelper().Encoder(e) _, _, _ = h, z, r if !z.EncBinary() { z.EncTextMarshal(x) } else { r.EncodeUint(uint64(x)) } } func (x *testMammoth2Text) CodecDecodeSelf(d *Decoder) { var h codecSelfer19781 z, r := GenHelper().Decoder(d) _, _, _ = h, z, r if !z.DecBinary() { z.DecTextUnmarshal(x) } else { *x = (testMammoth2Text)(r.DecodeUint64()) } } func (testMammoth2Json) codecSelferViaCodecgen() {} func (x testMammoth2Json) CodecEncodeSelf(e *Encoder) { var h codecSelfer19781 z, r := GenHelper().Encoder(e) _, _, _ = h, z, r if !z.EncBinary() && z.IsJSONHandle() { z.EncJSONMarshal(x) } else { r.EncodeUint(uint64(x)) } } func (x *testMammoth2Json) CodecDecodeSelf(d *Decoder) { var h codecSelfer19781 z, r := GenHelper().Decoder(d) _, _, _ = h, z, r if !z.DecBinary() && z.IsJSONHandle() { z.DecJSONUnmarshal(x) } else { *x = (testMammoth2Json)(r.DecodeUint64()) } } func (testMammoth2Basic) codecSelferViaCodecgen() {} func (x *testMammoth2Basic) CodecEncodeSelf(e *Encoder) { var h codecSelfer19781 z, r := GenHelper().Encoder(e) _, _, _ = h, z, r if x == nil { r.EncodeNil() } else { z.F.EncSliceUint64V(([]uint64)(x[:]), e) } } func (x *testMammoth2Basic) CodecDecodeSelf(d *Decoder) { var h codecSelfer19781 z, r := GenHelper().Decoder(d) _, _, _ = h, z, r z.F.DecSliceUint64N(([]uint64)(x[:]), d) } func (TestMammoth2Wrapper) codecSelferViaCodecgen() {} func (x *TestMammoth2Wrapper) CodecEncodeSelf(e *Encoder) { var h codecSelfer19781 z, r := GenHelper().Encoder(e) _, _, _ = h, z, r if z.EncBasicHandle().CheckCircularRef { z.EncEncode(x) return } if x == nil { r.EncodeNil() } else { yy2arr2 := z.EncBasicHandle().StructToArray _ = yy2arr2 const yyr2 bool = false // struct tag has 'toArray' var yyn14 bool = x.Tpbytes == nil if yyr2 || yy2arr2 { z.EncWriteArrayStart(12) z.EncWriteArrayElem() yy15 := &x.V if yyxt16 := z.Extension(yy15); yyxt16 != nil { z.EncExtension(yy15, yyxt16) } else { yy15.CodecEncodeSelf(e) } z.EncWriteArrayElem() if yyxt17 := z.Extension(x.T); yyxt17 != nil { z.EncExtension(x.T, yyxt17) } else { x.T.CodecEncodeSelf(e) } z.EncWriteArrayElem() if yyxt18 := z.Extension(x.B); yyxt18 != nil { z.EncExtension(x.B, yyxt18) } else { x.B.CodecEncodeSelf(e) } z.EncWriteArrayElem() if yyxt19 := z.Extension(x.J); yyxt19 != nil { z.EncExtension(x.J, yyxt19) } else { x.J.CodecEncodeSelf(e) } z.EncWriteArrayElem() yy20 := &x.C if yyxt21 := z.Extension(yy20); yyxt21 != nil { z.EncExtension(yy20, yyxt21) } else { yy20.CodecEncodeSelf(e) } z.EncWriteArrayElem() if x.M == nil { r.EncodeNil() } else { h.encMaptestMammoth2BasicTestMammoth2((map[testMammoth2Basic]TestMammoth2)(x.M), e) } // end block: if x.M map == nil z.EncWriteArrayElem() if x.L == nil { r.EncodeNil() } else { h.encSliceTestMammoth2(([]TestMammoth2)(x.L), e) } // end block: if x.L slice == nil z.EncWriteArrayElem() yy24 := &x.A h.encArray4int64((*[4]int64)(yy24), e) z.EncWriteArrayElem() z.EncEncodeComplex128(complex128(x.Tcomplex128)) z.EncWriteArrayElem() z.EncEncodeComplex64(complex64(x.Tcomplex64)) z.EncWriteArrayElem() if x.Tbytes == nil { r.EncodeNil() } else { r.EncodeStringBytesRaw([]byte(x.Tbytes)) } // end block: if x.Tbytes slice == nil if yyn14 { z.EncWriteArrayElem() r.EncodeNil() } else { z.EncWriteArrayElem() yy29 := *x.Tpbytes if yy29 == nil { r.EncodeNil() } else { r.EncodeStringBytesRaw([]byte(yy29)) } // end block: if yy29 slice == nil } z.EncWriteArrayEnd() } else { z.EncWriteMapStart(12) if z.EncBasicHandle().Canonical { z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"A\"") } else { r.EncodeString(`A`) } z.EncWriteMapElemValue() yy31 := &x.A h.encArray4int64((*[4]int64)(yy31), e) z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"B\"") } else { r.EncodeString(`B`) } z.EncWriteMapElemValue() if yyxt33 := z.Extension(x.B); yyxt33 != nil { z.EncExtension(x.B, yyxt33) } else { x.B.CodecEncodeSelf(e) } z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"C\"") } else { r.EncodeString(`C`) } z.EncWriteMapElemValue() yy34 := &x.C if yyxt35 := z.Extension(yy34); yyxt35 != nil { z.EncExtension(yy34, yyxt35) } else { yy34.CodecEncodeSelf(e) } z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"J\"") } else { r.EncodeString(`J`) } z.EncWriteMapElemValue() if yyxt36 := z.Extension(x.J); yyxt36 != nil { z.EncExtension(x.J, yyxt36) } else { x.J.CodecEncodeSelf(e) } z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"L\"") } else { r.EncodeString(`L`) } z.EncWriteMapElemValue() if x.L == nil { r.EncodeNil() } else { h.encSliceTestMammoth2(([]TestMammoth2)(x.L), e) } // end block: if x.L slice == nil z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"M\"") } else { r.EncodeString(`M`) } z.EncWriteMapElemValue() if x.M == nil { r.EncodeNil() } else { h.encMaptestMammoth2BasicTestMammoth2((map[testMammoth2Basic]TestMammoth2)(x.M), e) } // end block: if x.M map == nil z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"T\"") } else { r.EncodeString(`T`) } z.EncWriteMapElemValue() if yyxt39 := z.Extension(x.T); yyxt39 != nil { z.EncExtension(x.T, yyxt39) } else { x.T.CodecEncodeSelf(e) } z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"Tbytes\"") } else { r.EncodeString(`Tbytes`) } z.EncWriteMapElemValue() if x.Tbytes == nil { r.EncodeNil() } else { r.EncodeStringBytesRaw([]byte(x.Tbytes)) } // end block: if x.Tbytes slice == nil z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"Tcomplex128\"") } else { r.EncodeString(`Tcomplex128`) } z.EncWriteMapElemValue() z.EncEncodeComplex128(complex128(x.Tcomplex128)) z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"Tcomplex64\"") } else { r.EncodeString(`Tcomplex64`) } z.EncWriteMapElemValue() z.EncEncodeComplex64(complex64(x.Tcomplex64)) z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"Tpbytes\"") } else { r.EncodeString(`Tpbytes`) } z.EncWriteMapElemValue() if yyn14 { r.EncodeNil() } else { yy43 := *x.Tpbytes if yy43 == nil { r.EncodeNil() } else { r.EncodeStringBytesRaw([]byte(yy43)) } // end block: if yy43 slice == nil } z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"V\"") } else { r.EncodeString(`V`) } z.EncWriteMapElemValue() yy45 := &x.V if yyxt46 := z.Extension(yy45); yyxt46 != nil { z.EncExtension(yy45, yyxt46) } else { yy45.CodecEncodeSelf(e) } } else { z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"V\"") } else { r.EncodeString(`V`) } z.EncWriteMapElemValue() yy47 := &x.V if yyxt48 := z.Extension(yy47); yyxt48 != nil { z.EncExtension(yy47, yyxt48) } else { yy47.CodecEncodeSelf(e) } z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"T\"") } else { r.EncodeString(`T`) } z.EncWriteMapElemValue() if yyxt49 := z.Extension(x.T); yyxt49 != nil { z.EncExtension(x.T, yyxt49) } else { x.T.CodecEncodeSelf(e) } z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"B\"") } else { r.EncodeString(`B`) } z.EncWriteMapElemValue() if yyxt50 := z.Extension(x.B); yyxt50 != nil { z.EncExtension(x.B, yyxt50) } else { x.B.CodecEncodeSelf(e) } z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"J\"") } else { r.EncodeString(`J`) } z.EncWriteMapElemValue() if yyxt51 := z.Extension(x.J); yyxt51 != nil { z.EncExtension(x.J, yyxt51) } else { x.J.CodecEncodeSelf(e) } z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"C\"") } else { r.EncodeString(`C`) } z.EncWriteMapElemValue() yy52 := &x.C if yyxt53 := z.Extension(yy52); yyxt53 != nil { z.EncExtension(yy52, yyxt53) } else { yy52.CodecEncodeSelf(e) } z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"M\"") } else { r.EncodeString(`M`) } z.EncWriteMapElemValue() if x.M == nil { r.EncodeNil() } else { h.encMaptestMammoth2BasicTestMammoth2((map[testMammoth2Basic]TestMammoth2)(x.M), e) } // end block: if x.M map == nil z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"L\"") } else { r.EncodeString(`L`) } z.EncWriteMapElemValue() if x.L == nil { r.EncodeNil() } else { h.encSliceTestMammoth2(([]TestMammoth2)(x.L), e) } // end block: if x.L slice == nil z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"A\"") } else { r.EncodeString(`A`) } z.EncWriteMapElemValue() yy56 := &x.A h.encArray4int64((*[4]int64)(yy56), e) z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"Tcomplex128\"") } else { r.EncodeString(`Tcomplex128`) } z.EncWriteMapElemValue() z.EncEncodeComplex128(complex128(x.Tcomplex128)) z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"Tcomplex64\"") } else { r.EncodeString(`Tcomplex64`) } z.EncWriteMapElemValue() z.EncEncodeComplex64(complex64(x.Tcomplex64)) z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"Tbytes\"") } else { r.EncodeString(`Tbytes`) } z.EncWriteMapElemValue() if x.Tbytes == nil { r.EncodeNil() } else { r.EncodeStringBytesRaw([]byte(x.Tbytes)) } // end block: if x.Tbytes slice == nil z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"Tpbytes\"") } else { r.EncodeString(`Tpbytes`) } z.EncWriteMapElemValue() if yyn14 { r.EncodeNil() } else { yy61 := *x.Tpbytes if yy61 == nil { r.EncodeNil() } else { r.EncodeStringBytesRaw([]byte(yy61)) } // end block: if yy61 slice == nil } } z.EncWriteMapEnd() } } } func (x *TestMammoth2Wrapper) CodecDecodeSelf(d *Decoder) { var h codecSelfer19781 z, r := GenHelper().Decoder(d) _, _, _ = h, z, r yyct2 := r.ContainerType() if yyct2 == codecSelferValueTypeNil19781 { *(x) = TestMammoth2Wrapper{} } else if yyct2 == codecSelferValueTypeMap19781 { yyl2 := z.DecReadMapStart() if yyl2 == 0 { } else { x.codecDecodeSelfFromMap(yyl2, d) } z.DecReadMapEnd() } else if yyct2 == codecSelferValueTypeArray19781 { yyl2 := z.DecReadArrayStart() if yyl2 != 0 { x.codecDecodeSelfFromArray(yyl2, d) } z.DecReadArrayEnd() } else { panic(errCodecSelferOnlyMapOrArrayEncodeToStruct19781) } } func (x *TestMammoth2Wrapper) codecDecodeSelfFromMap(l int, d *Decoder) { var h codecSelfer19781 z, r := GenHelper().Decoder(d) _, _, _ = h, z, r var yyhl3 bool = l >= 0 for yyj3 := 0; ; yyj3++ { if yyhl3 { if yyj3 >= l { break } } else { if z.DecCheckBreak() { break } } z.DecReadMapElemKey() yys3 := r.DecodeStringAsBytes() z.DecReadMapElemValue() switch string(yys3) { case "V": if yyxt5 := z.Extension(x.V); yyxt5 != nil { z.DecExtension(&x.V, yyxt5) } else { x.V.CodecDecodeSelf(d) } case "T": if yyxt7 := z.Extension(x.T); yyxt7 != nil { z.DecExtension(&x.T, yyxt7) } else { x.T.CodecDecodeSelf(d) } case "B": if yyxt9 := z.Extension(x.B); yyxt9 != nil { z.DecExtension(&x.B, yyxt9) } else { x.B.CodecDecodeSelf(d) } case "J": if yyxt11 := z.Extension(x.J); yyxt11 != nil { z.DecExtension(&x.J, yyxt11) } else { x.J.CodecDecodeSelf(d) } case "C": if yyxt13 := z.Extension(x.C); yyxt13 != nil { z.DecExtension(&x.C, yyxt13) } else { x.C.CodecDecodeSelf(d) } case "M": h.decMaptestMammoth2BasicTestMammoth2((*map[testMammoth2Basic]TestMammoth2)(&x.M), d) case "L": h.decSliceTestMammoth2((*[]TestMammoth2)(&x.L), d) case "A": h.decArray4int64((*[4]int64)(&x.A), d) case "Tcomplex128": x.Tcomplex128 = (complex128)(complex(r.DecodeFloat64(), 0)) case "Tcomplex64": x.Tcomplex64 = (complex64)(complex(z.DecDecodeFloat32(), 0)) case "Tbytes": x.Tbytes = z.DecodeBytesInto(([]byte)(x.Tbytes)) case "Tpbytes": if r.TryNil() { if x.Tpbytes != nil { // remove the if-true x.Tpbytes = nil } } else { if x.Tpbytes == nil { x.Tpbytes = new([]uint8) } *x.Tpbytes = z.DecodeBytesInto(*(*[]byte)(x.Tpbytes)) } default: z.DecStructFieldNotFound(-1, string(yys3)) } // end switch yys3 } // end for yyj3 } func (x *TestMammoth2Wrapper) codecDecodeSelfFromArray(l int, d *Decoder) { var h codecSelfer19781 z, r := GenHelper().Decoder(d) _, _, _ = h, z, r var yyj26 int var yyb26 bool var yyhl26 bool = l >= 0 yyj26++ if yyhl26 { yyb26 = yyj26 > l } else { yyb26 = z.DecCheckBreak() } if yyb26 { z.DecReadArrayEnd() return } z.DecReadArrayElem() if yyxt28 := z.Extension(x.V); yyxt28 != nil { z.DecExtension(&x.V, yyxt28) } else { x.V.CodecDecodeSelf(d) } yyj26++ if yyhl26 { yyb26 = yyj26 > l } else { yyb26 = z.DecCheckBreak() } if yyb26 { z.DecReadArrayEnd() return } z.DecReadArrayElem() if yyxt30 := z.Extension(x.T); yyxt30 != nil { z.DecExtension(&x.T, yyxt30) } else { x.T.CodecDecodeSelf(d) } yyj26++ if yyhl26 { yyb26 = yyj26 > l } else { yyb26 = z.DecCheckBreak() } if yyb26 { z.DecReadArrayEnd() return } z.DecReadArrayElem() if yyxt32 := z.Extension(x.B); yyxt32 != nil { z.DecExtension(&x.B, yyxt32) } else { x.B.CodecDecodeSelf(d) } yyj26++ if yyhl26 { yyb26 = yyj26 > l } else { yyb26 = z.DecCheckBreak() } if yyb26 { z.DecReadArrayEnd() return } z.DecReadArrayElem() if yyxt34 := z.Extension(x.J); yyxt34 != nil { z.DecExtension(&x.J, yyxt34) } else { x.J.CodecDecodeSelf(d) } yyj26++ if yyhl26 { yyb26 = yyj26 > l } else { yyb26 = z.DecCheckBreak() } if yyb26 { z.DecReadArrayEnd() return } z.DecReadArrayElem() if yyxt36 := z.Extension(x.C); yyxt36 != nil { z.DecExtension(&x.C, yyxt36) } else { x.C.CodecDecodeSelf(d) } yyj26++ if yyhl26 { yyb26 = yyj26 > l } else { yyb26 = z.DecCheckBreak() } if yyb26 { z.DecReadArrayEnd() return } z.DecReadArrayElem() h.decMaptestMammoth2BasicTestMammoth2((*map[testMammoth2Basic]TestMammoth2)(&x.M), d) yyj26++ if yyhl26 { yyb26 = yyj26 > l } else { yyb26 = z.DecCheckBreak() } if yyb26 { z.DecReadArrayEnd() return } z.DecReadArrayElem() h.decSliceTestMammoth2((*[]TestMammoth2)(&x.L), d) yyj26++ if yyhl26 { yyb26 = yyj26 > l } else { yyb26 = z.DecCheckBreak() } if yyb26 { z.DecReadArrayEnd() return } z.DecReadArrayElem() h.decArray4int64((*[4]int64)(&x.A), d) yyj26++ if yyhl26 { yyb26 = yyj26 > l } else { yyb26 = z.DecCheckBreak() } if yyb26 { z.DecReadArrayEnd() return } z.DecReadArrayElem() x.Tcomplex128 = (complex128)(complex(r.DecodeFloat64(), 0)) yyj26++ if yyhl26 { yyb26 = yyj26 > l } else { yyb26 = z.DecCheckBreak() } if yyb26 { z.DecReadArrayEnd() return } z.DecReadArrayElem() x.Tcomplex64 = (complex64)(complex(z.DecDecodeFloat32(), 0)) yyj26++ if yyhl26 { yyb26 = yyj26 > l } else { yyb26 = z.DecCheckBreak() } if yyb26 { z.DecReadArrayEnd() return } z.DecReadArrayElem() x.Tbytes = z.DecodeBytesInto(([]byte)(x.Tbytes)) yyj26++ if yyhl26 { yyb26 = yyj26 > l } else { yyb26 = z.DecCheckBreak() } if yyb26 { z.DecReadArrayEnd() return } z.DecReadArrayElem() if r.TryNil() { if x.Tpbytes != nil { // remove the if-true x.Tpbytes = nil } } else { if x.Tpbytes == nil { x.Tpbytes = new([]uint8) } *x.Tpbytes = z.DecodeBytesInto(*(*[]byte)(x.Tpbytes)) } for { yyj26++ if yyhl26 { yyb26 = yyj26 > l } else { yyb26 = z.DecCheckBreak() } if yyb26 { break } z.DecReadArrayElem() z.DecStructFieldNotFound(yyj26-1, "") } } func (x *TestMammoth2Wrapper) IsCodecEmpty() bool { return !(!(x.V.IsCodecEmpty()) || x.T != 0 || x.B != 0 || x.J != 0 || x.C != testMammoth2Basic{} || len(x.M) != 0 || len(x.L) != 0 || x.A != [4]int64{} || x.Tcomplex128 != 0 || x.Tcomplex64 != 0 || len(x.Tbytes) != 0 || false) } func (x codecSelfer19781) encMaptestMammoth2BasicTestMammoth2(v map[testMammoth2Basic]TestMammoth2, e *Encoder) { var h codecSelfer19781 z, r := GenHelper().Encoder(e) _, _, _ = h, z, r if v == nil { r.EncodeNil() } else if z.EncBasicHandle().Canonical { z.EncEncodeMapNonNil(v) } else { z.EncWriteMapStart(len(v)) for yyk1, yyv1 := range v { z.EncWriteMapElemKey() yy2 := &yyk1 if yyxt3 := z.Extension(yy2); yyxt3 != nil { z.EncExtension(yy2, yyxt3) } else { yy2.CodecEncodeSelf(e) } z.EncWriteMapElemValue() yy4 := &yyv1 if yyxt5 := z.Extension(yy4); yyxt5 != nil { z.EncExtension(yy4, yyxt5) } else { yy4.CodecEncodeSelf(e) } } z.EncWriteMapEnd() } } func (x codecSelfer19781) decMaptestMammoth2BasicTestMammoth2(v *map[testMammoth2Basic]TestMammoth2, d *Decoder) { var h codecSelfer19781 z, r := GenHelper().Decoder(d) _, _, _ = h, z, r yyv1 := *v yyl1 := z.DecReadMapStart() if yyl1 == codecSelferDecContainerLenNil19781 { *v = nil } else { if yyv1 == nil { yyrl1 := z.DecInferLen(yyl1, z.DecBasicHandle().MaxInitLen, 1408) yyv1 = make(map[testMammoth2Basic]TestMammoth2, yyrl1) *v = yyv1 } var yymk1 testMammoth2Basic var yymv1 TestMammoth2 var yymg1, yymdn1 bool if z.DecBasicHandle().MapValueReset { yymg1 = true } if yyl1 != 0 { yyhl1 := yyl1 > 0 for yyj1 := 0; (yyhl1 && yyj1 < yyl1) || !(yyhl1 || z.DecCheckBreak()); yyj1++ { z.DecReadMapElemKey() if yyxt3 := z.Extension(yymk1); yyxt3 != nil { z.DecExtension(&yymk1, yyxt3) } else { yymk1.CodecDecodeSelf(d) } if yymg1 { yymv1 = yyv1[yymk1] } else { yymv1 = TestMammoth2{} } z.DecReadMapElemValue() yymdn1 = false if yyxt5 := z.Extension(yymv1); yyxt5 != nil { z.DecExtension(&yymv1, yyxt5) } else { yymv1.CodecDecodeSelf(d) } if yymdn1 { yyv1[yymk1] = TestMammoth2{} } else { yyv1[yymk1] = yymv1 } } } // else len==0: leave as-is (do not clear map entries) z.DecReadMapEnd() } } func (x codecSelfer19781) encSliceTestMammoth2(v []TestMammoth2, e *Encoder) { var h codecSelfer19781 z, r := GenHelper().Encoder(e) _, _, _ = h, z, r if v == nil { r.EncodeNil() return } z.EncWriteArrayStart(len(v)) for yyv1 := range v { z.EncWriteArrayElem() yy2 := &v[yyv1] if yyxt3 := z.Extension(yy2); yyxt3 != nil { z.EncExtension(yy2, yyxt3) } else { yy2.CodecEncodeSelf(e) } } z.EncWriteArrayEnd() } func (x codecSelfer19781) decSliceTestMammoth2(v *[]TestMammoth2, d *Decoder) { var h codecSelfer19781 z, r := GenHelper().Decoder(d) _, _, _ = h, z, r yyv1 := *v yyh1, yyl1 := z.DecSliceHelperStart() var yyc1 bool _ = yyc1 if yyh1.IsNil { if yyv1 != nil { yyv1 = nil yyc1 = true } } else if yyl1 == 0 { if yyv1 == nil { yyv1 = []TestMammoth2{} yyc1 = true } else if len(yyv1) != 0 { yyv1 = yyv1[:0] yyc1 = true } } else { yyhl1 := yyl1 > 0 var yyrl1 int _ = yyrl1 if yyhl1 { if yyl1 > cap(yyv1) { yyrl1 = z.DecInferLen(yyl1, z.DecBasicHandle().MaxInitLen, 1376) if yyrl1 <= cap(yyv1) { yyv1 = yyv1[:yyrl1] } else { yyv1 = make([]TestMammoth2, yyrl1) } yyc1 = true } else if yyl1 != len(yyv1) { yyv1 = yyv1[:yyl1] yyc1 = true } } var yyj1 int for yyj1 = 0; (yyhl1 && yyj1 < yyl1) || !(yyhl1 || z.DecCheckBreak()); yyj1++ { // bounds-check-elimination if yyj1 == 0 && yyv1 == nil { if yyhl1 { yyrl1 = z.DecInferLen(yyl1, z.DecBasicHandle().MaxInitLen, 1376) } else { yyrl1 = 8 } yyv1 = make([]TestMammoth2, yyrl1) yyc1 = true } yyh1.ElemContainerState(yyj1) var yydb1 bool if yyj1 >= len(yyv1) { yyv1 = append(yyv1, TestMammoth2{}) yyc1 = true } if yydb1 { z.DecSwallow() } else { if yyxt3 := z.Extension(yyv1[yyj1]); yyxt3 != nil { z.DecExtension(&yyv1[yyj1], yyxt3) } else { yyv1[yyj1].CodecDecodeSelf(d) } } } if yyj1 < len(yyv1) { yyv1 = yyv1[:yyj1] yyc1 = true } else if yyj1 == 0 && yyv1 == nil { yyv1 = []TestMammoth2{} yyc1 = true } } yyh1.End() if yyc1 { *v = yyv1 } } func (x codecSelfer19781) encArray4int64(v *[4]int64, e *Encoder) { var h codecSelfer19781 z, r := GenHelper().Encoder(e) _, _, _ = h, z, r if v == nil { r.EncodeNil() return } z.EncWriteArrayStart(len(v)) for yyv1 := range v { z.EncWriteArrayElem() r.EncodeInt(int64(v[yyv1])) } z.EncWriteArrayEnd() } func (x codecSelfer19781) decArray4int64(v *[4]int64, d *Decoder) { var h codecSelfer19781 z, r := GenHelper().Decoder(d) _, _, _ = h, z, r yyv1 := v yyh1, yyl1 := z.DecSliceHelperStart() if yyl1 == 0 { } else { yyhl1 := yyl1 > 0 var yyrl1 int _ = yyrl1 var yyj1 int for yyj1 = 0; (yyhl1 && yyj1 < yyl1) || !(yyhl1 || z.DecCheckBreak()); yyj1++ { // bounds-check-elimination yyh1.ElemContainerState(yyj1) var yydb1 bool if yyj1 >= len(yyv1) { z.DecArrayCannotExpand(len(v), yyj1+1) yydb1 = true } if yydb1 { z.DecSwallow() } else { yyv1[yyj1] = (int64)(r.DecodeInt64()) } } } yyh1.End() } go-1.2.8/codec/mammoth2_generated_test.go000066400000000000000000000164141435255326100203500ustar00rootroot00000000000000//go:build !codec.notmammoth // +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 mammoth2-test.go.tmpl - DO NOT EDIT. package codec // Increase codecoverage by covering all the codecgen paths, in fast-path and gen-helper.go.... // // Note: even though this is built based on fast-path and gen-helper, we will run these tests // in all modes, including notfastpath, etc. // // Add test file for creating a mammoth generated file as _mammoth_generated.go // - generate a second mammoth files in a different file: mammoth2_generated_test.go // mammoth-test.go.tmpl will do this // - run codecgen on it, into mammoth2_codecgen_generated_test.go (no build tags) // - as part of TestMammoth, run it also // - this will cover all the codecgen, gen-helper, etc in one full run // - check in mammoth* files into github also // // 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) // import "encoding/binary" import "fmt" type TestMammoth2 struct { FIntf interface{} FptrIntf *interface{} FString string FptrString *string FBytes []byte FptrBytes *[]byte FFloat32 float32 FptrFloat32 *float32 FFloat64 float64 FptrFloat64 *float64 FUint uint FptrUint *uint FUint8 uint8 FptrUint8 *uint8 FUint16 uint16 FptrUint16 *uint16 FUint32 uint32 FptrUint32 *uint32 FUint64 uint64 FptrUint64 *uint64 FUintptr uintptr FptrUintptr *uintptr FInt int FptrInt *int FInt8 int8 FptrInt8 *int8 FInt16 int16 FptrInt16 *int16 FInt32 int32 FptrInt32 *int32 FInt64 int64 FptrInt64 *int64 FBool bool FptrBool *bool FSliceIntf []interface{} FptrSliceIntf *[]interface{} FSliceString []string FptrSliceString *[]string FSliceBytes [][]byte FptrSliceBytes *[][]byte FSliceFloat32 []float32 FptrSliceFloat32 *[]float32 FSliceFloat64 []float64 FptrSliceFloat64 *[]float64 FSliceUint8 []uint8 FptrSliceUint8 *[]uint8 FSliceUint64 []uint64 FptrSliceUint64 *[]uint64 FSliceInt []int FptrSliceInt *[]int FSliceInt32 []int32 FptrSliceInt32 *[]int32 FSliceInt64 []int64 FptrSliceInt64 *[]int64 FSliceBool []bool FptrSliceBool *[]bool FMapStringIntf map[string]interface{} FptrMapStringIntf *map[string]interface{} FMapStringString map[string]string FptrMapStringString *map[string]string FMapStringBytes map[string][]byte FptrMapStringBytes *map[string][]byte FMapStringUint8 map[string]uint8 FptrMapStringUint8 *map[string]uint8 FMapStringUint64 map[string]uint64 FptrMapStringUint64 *map[string]uint64 FMapStringInt map[string]int FptrMapStringInt *map[string]int FMapStringInt32 map[string]int32 FptrMapStringInt32 *map[string]int32 FMapStringFloat64 map[string]float64 FptrMapStringFloat64 *map[string]float64 FMapStringBool map[string]bool FptrMapStringBool *map[string]bool FMapUint8Intf map[uint8]interface{} FptrMapUint8Intf *map[uint8]interface{} FMapUint8String map[uint8]string FptrMapUint8String *map[uint8]string FMapUint8Bytes map[uint8][]byte FptrMapUint8Bytes *map[uint8][]byte FMapUint8Uint8 map[uint8]uint8 FptrMapUint8Uint8 *map[uint8]uint8 FMapUint8Uint64 map[uint8]uint64 FptrMapUint8Uint64 *map[uint8]uint64 FMapUint8Int map[uint8]int FptrMapUint8Int *map[uint8]int FMapUint8Int32 map[uint8]int32 FptrMapUint8Int32 *map[uint8]int32 FMapUint8Float64 map[uint8]float64 FptrMapUint8Float64 *map[uint8]float64 FMapUint8Bool map[uint8]bool FptrMapUint8Bool *map[uint8]bool FMapUint64Intf map[uint64]interface{} FptrMapUint64Intf *map[uint64]interface{} FMapUint64String map[uint64]string FptrMapUint64String *map[uint64]string FMapUint64Bytes map[uint64][]byte FptrMapUint64Bytes *map[uint64][]byte FMapUint64Uint8 map[uint64]uint8 FptrMapUint64Uint8 *map[uint64]uint8 FMapUint64Uint64 map[uint64]uint64 FptrMapUint64Uint64 *map[uint64]uint64 FMapUint64Int map[uint64]int FptrMapUint64Int *map[uint64]int FMapUint64Int32 map[uint64]int32 FptrMapUint64Int32 *map[uint64]int32 FMapUint64Float64 map[uint64]float64 FptrMapUint64Float64 *map[uint64]float64 FMapUint64Bool map[uint64]bool FptrMapUint64Bool *map[uint64]bool FMapIntIntf map[int]interface{} FptrMapIntIntf *map[int]interface{} FMapIntString map[int]string FptrMapIntString *map[int]string FMapIntBytes map[int][]byte FptrMapIntBytes *map[int][]byte FMapIntUint8 map[int]uint8 FptrMapIntUint8 *map[int]uint8 FMapIntUint64 map[int]uint64 FptrMapIntUint64 *map[int]uint64 FMapIntInt map[int]int FptrMapIntInt *map[int]int FMapIntInt32 map[int]int32 FptrMapIntInt32 *map[int]int32 FMapIntFloat64 map[int]float64 FptrMapIntFloat64 *map[int]float64 FMapIntBool map[int]bool FptrMapIntBool *map[int]bool FMapInt32Intf map[int32]interface{} FptrMapInt32Intf *map[int32]interface{} FMapInt32String map[int32]string FptrMapInt32String *map[int32]string FMapInt32Bytes map[int32][]byte FptrMapInt32Bytes *map[int32][]byte FMapInt32Uint8 map[int32]uint8 FptrMapInt32Uint8 *map[int32]uint8 FMapInt32Uint64 map[int32]uint64 FptrMapInt32Uint64 *map[int32]uint64 FMapInt32Int map[int32]int FptrMapInt32Int *map[int32]int FMapInt32Int32 map[int32]int32 FptrMapInt32Int32 *map[int32]int32 FMapInt32Float64 map[int32]float64 FptrMapInt32Float64 *map[int32]float64 FMapInt32Bool map[int32]bool FptrMapInt32Bool *map[int32]bool } // ----------- 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 TestMammoth2 T testMammoth2Text B testMammoth2Binary J testMammoth2Json C testMammoth2Basic M map[testMammoth2Basic]TestMammoth2 L []TestMammoth2 A [4]int64 Tcomplex128 complex128 Tcomplex64 complex64 Tbytes []uint8 Tpbytes *[]uint8 } go-1.2.8/codec/mammoth_generated_test.go000066400000000000000000003613551435255326100202750ustar00rootroot00000000000000// 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.notmammoth // +build !codec.notmammoth // 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 fast-path // 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 { FIntf interface{} FptrIntf *interface{} FString string FptrString *string FBytes []byte FptrBytes *[]byte FFloat32 float32 FptrFloat32 *float32 FFloat64 float64 FptrFloat64 *float64 FUint uint FptrUint *uint FUint8 uint8 FptrUint8 *uint8 FUint16 uint16 FptrUint16 *uint16 FUint32 uint32 FptrUint32 *uint32 FUint64 uint64 FptrUint64 *uint64 FUintptr uintptr FptrUintptr *uintptr FInt int FptrInt *int FInt8 int8 FptrInt8 *int8 FInt16 int16 FptrInt16 *int16 FInt32 int32 FptrInt32 *int32 FInt64 int64 FptrInt64 *int64 FBool bool FptrBool *bool FSliceIntf []interface{} FptrSliceIntf *[]interface{} Farr4SliceIntf [4]interface{} FSliceString []string FptrSliceString *[]string Farr4SliceString [4]string FSliceBytes [][]byte FptrSliceBytes *[][]byte Farr4SliceBytes [4][]byte FSliceFloat32 []float32 FptrSliceFloat32 *[]float32 Farr4SliceFloat32 [4]float32 FSliceFloat64 []float64 FptrSliceFloat64 *[]float64 Farr4SliceFloat64 [4]float64 FSliceUint8 []uint8 FptrSliceUint8 *[]uint8 Farr4SliceUint8 [4]uint8 FSliceUint64 []uint64 FptrSliceUint64 *[]uint64 Farr4SliceUint64 [4]uint64 FSliceInt []int FptrSliceInt *[]int Farr4SliceInt [4]int FSliceInt32 []int32 FptrSliceInt32 *[]int32 Farr4SliceInt32 [4]int32 FSliceInt64 []int64 FptrSliceInt64 *[]int64 Farr4SliceInt64 [4]int64 FSliceBool []bool FptrSliceBool *[]bool Farr4SliceBool [4]bool FMapStringIntf map[string]interface{} FptrMapStringIntf *map[string]interface{} FMapStringString map[string]string FptrMapStringString *map[string]string FMapStringBytes map[string][]byte FptrMapStringBytes *map[string][]byte FMapStringUint8 map[string]uint8 FptrMapStringUint8 *map[string]uint8 FMapStringUint64 map[string]uint64 FptrMapStringUint64 *map[string]uint64 FMapStringInt map[string]int FptrMapStringInt *map[string]int FMapStringInt32 map[string]int32 FptrMapStringInt32 *map[string]int32 FMapStringFloat64 map[string]float64 FptrMapStringFloat64 *map[string]float64 FMapStringBool map[string]bool FptrMapStringBool *map[string]bool FMapUint8Intf map[uint8]interface{} FptrMapUint8Intf *map[uint8]interface{} FMapUint8String map[uint8]string FptrMapUint8String *map[uint8]string FMapUint8Bytes map[uint8][]byte FptrMapUint8Bytes *map[uint8][]byte FMapUint8Uint8 map[uint8]uint8 FptrMapUint8Uint8 *map[uint8]uint8 FMapUint8Uint64 map[uint8]uint64 FptrMapUint8Uint64 *map[uint8]uint64 FMapUint8Int map[uint8]int FptrMapUint8Int *map[uint8]int FMapUint8Int32 map[uint8]int32 FptrMapUint8Int32 *map[uint8]int32 FMapUint8Float64 map[uint8]float64 FptrMapUint8Float64 *map[uint8]float64 FMapUint8Bool map[uint8]bool FptrMapUint8Bool *map[uint8]bool FMapUint64Intf map[uint64]interface{} FptrMapUint64Intf *map[uint64]interface{} FMapUint64String map[uint64]string FptrMapUint64String *map[uint64]string FMapUint64Bytes map[uint64][]byte FptrMapUint64Bytes *map[uint64][]byte FMapUint64Uint8 map[uint64]uint8 FptrMapUint64Uint8 *map[uint64]uint8 FMapUint64Uint64 map[uint64]uint64 FptrMapUint64Uint64 *map[uint64]uint64 FMapUint64Int map[uint64]int FptrMapUint64Int *map[uint64]int FMapUint64Int32 map[uint64]int32 FptrMapUint64Int32 *map[uint64]int32 FMapUint64Float64 map[uint64]float64 FptrMapUint64Float64 *map[uint64]float64 FMapUint64Bool map[uint64]bool FptrMapUint64Bool *map[uint64]bool FMapIntIntf map[int]interface{} FptrMapIntIntf *map[int]interface{} FMapIntString map[int]string FptrMapIntString *map[int]string FMapIntBytes map[int][]byte FptrMapIntBytes *map[int][]byte FMapIntUint8 map[int]uint8 FptrMapIntUint8 *map[int]uint8 FMapIntUint64 map[int]uint64 FptrMapIntUint64 *map[int]uint64 FMapIntInt map[int]int FptrMapIntInt *map[int]int FMapIntInt32 map[int]int32 FptrMapIntInt32 *map[int]int32 FMapIntFloat64 map[int]float64 FptrMapIntFloat64 *map[int]float64 FMapIntBool map[int]bool FptrMapIntBool *map[int]bool FMapInt32Intf map[int32]interface{} FptrMapInt32Intf *map[int32]interface{} FMapInt32String map[int32]string FptrMapInt32String *map[int32]string FMapInt32Bytes map[int32][]byte FptrMapInt32Bytes *map[int32][]byte FMapInt32Uint8 map[int32]uint8 FptrMapInt32Uint8 *map[int32]uint8 FMapInt32Uint64 map[int32]uint64 FptrMapInt32Uint64 *map[int32]uint64 FMapInt32Int map[int32]int FptrMapInt32Int *map[int32]int FMapInt32Int32 map[int32]int32 FptrMapInt32Int32 *map[int32]int32 FMapInt32Float64 map[int32]float64 FptrMapInt32Float64 *map[int32]float64 FMapInt32Bool map[int32]bool FptrMapInt32Bool *map[int32]bool } type typMbsSliceIntf []interface{} func (_ typMbsSliceIntf) MapBySlice() {} type typMbsSliceString []string func (_ typMbsSliceString) MapBySlice() {} type typMbsSliceBytes [][]byte func (_ typMbsSliceBytes) MapBySlice() {} type typMbsSliceFloat32 []float32 func (_ typMbsSliceFloat32) MapBySlice() {} type typMbsSliceFloat64 []float64 func (_ typMbsSliceFloat64) MapBySlice() {} type typMbsSliceUint8 []uint8 func (_ typMbsSliceUint8) MapBySlice() {} type typMbsSliceUint64 []uint64 func (_ typMbsSliceUint64) MapBySlice() {} type typMbsSliceInt []int func (_ typMbsSliceInt) MapBySlice() {} type typMbsSliceInt32 []int32 func (_ typMbsSliceInt32) MapBySlice() {} type typMbsSliceInt64 []int64 func (_ typMbsSliceInt64) MapBySlice() {} type typMbsSliceBool []bool func (_ typMbsSliceBool) MapBySlice() {} type typMapMapStringIntf map[string]interface{} type typMapMapStringString map[string]string type typMapMapStringBytes map[string][]byte type typMapMapStringUint8 map[string]uint8 type typMapMapStringUint64 map[string]uint64 type typMapMapStringInt map[string]int type typMapMapStringInt32 map[string]int32 type typMapMapStringFloat64 map[string]float64 type typMapMapStringBool map[string]bool type typMapMapUint8Intf map[uint8]interface{} type typMapMapUint8String map[uint8]string type typMapMapUint8Bytes map[uint8][]byte type typMapMapUint8Uint8 map[uint8]uint8 type typMapMapUint8Uint64 map[uint8]uint64 type typMapMapUint8Int map[uint8]int type typMapMapUint8Int32 map[uint8]int32 type typMapMapUint8Float64 map[uint8]float64 type typMapMapUint8Bool map[uint8]bool type typMapMapUint64Intf map[uint64]interface{} type typMapMapUint64String map[uint64]string type typMapMapUint64Bytes map[uint64][]byte type typMapMapUint64Uint8 map[uint64]uint8 type typMapMapUint64Uint64 map[uint64]uint64 type typMapMapUint64Int map[uint64]int type typMapMapUint64Int32 map[uint64]int32 type typMapMapUint64Float64 map[uint64]float64 type typMapMapUint64Bool map[uint64]bool type typMapMapIntIntf map[int]interface{} type typMapMapIntString map[int]string type typMapMapIntBytes map[int][]byte type typMapMapIntUint8 map[int]uint8 type typMapMapIntUint64 map[int]uint64 type typMapMapIntInt map[int]int type typMapMapIntInt32 map[int]int32 type typMapMapIntFloat64 map[int]float64 type typMapMapIntBool map[int]bool type typMapMapInt32Intf map[int32]interface{} type typMapMapInt32String map[int32]string type typMapMapInt32Bytes map[int32][]byte type typMapMapInt32Uint8 map[int32]uint8 type typMapMapInt32Uint64 map[int32]uint64 type typMapMapInt32Int map[int32]int type typMapMapInt32Int32 map[int32]int32 type typMapMapInt32Float64 map[int32]float64 type typMapMapInt32Bool map[int32]bool func __doTestMammothSlices(t *testing.T, h Handle) { var v17va [8]interface{} for _, v := range [][]interface{}{nil, {}, {"string-is-an-interface-2", nil, nil, "string-is-an-interface-3"}} { var v17v1, v17v2 []interface{} var bs17 []byte v17v1 = v bs17 = testMarshalErr(v17v1, h, t, "enc-slice-v17") if v == nil { v17v2 = make([]interface{}, 2) testUnmarshalErr(v17v2, bs17, h, t, "dec-slice-v17") testDeepEqualErr(v17v2[0], v17v2[1], t, "equal-slice-v17") // should not change testDeepEqualErr(len(v17v2), 2, t, "equal-slice-v17") // should not change v17v2 = make([]interface{}, 2) testUnmarshalErr(reflect.ValueOf(v17v2), bs17, h, t, "dec-slice-v17-noaddr") // non-addressable value testDeepEqualErr(v17v2[0], v17v2[1], t, "equal-slice-v17-noaddr") // should not change testDeepEqualErr(len(v17v2), 2, t, "equal-slice-v17") // should not change } else { v17v2 = make([]interface{}, len(v)) testUnmarshalErr(v17v2, bs17, h, t, "dec-slice-v17") testDeepEqualErr(v17v1, v17v2, t, "equal-slice-v17") v17v2 = make([]interface{}, len(v)) testUnmarshalErr(reflect.ValueOf(v17v2), bs17, h, t, "dec-slice-v17-noaddr") // non-addressable value testDeepEqualErr(v17v1, v17v2, t, "equal-slice-v17-noaddr") } testReleaseBytes(bs17) // ... bs17 = testMarshalErr(&v17v1, h, t, "enc-slice-v17-p") v17v2 = nil testUnmarshalErr(&v17v2, bs17, h, t, "dec-slice-v17-p") testDeepEqualErr(v17v1, v17v2, t, "equal-slice-v17-p") v17va = [8]interface{}{} // clear the array testUnmarshalErr(&v17va, bs17, h, t, "dec-array-v17-p-1") if v17v1 == nil && v17v2 == nil { v17v2 = []interface{}{} } // so we can compare to zero len slice below testDeepEqualErr(v17va[:len(v17v2)], v17v2, t, "equal-array-v17-p-1") v17va = [8]interface{}{} // clear the array v17v2 = v17va[:1:1] testUnmarshalErr(&v17v2, bs17, h, t, "dec-slice-v17-p-1") testDeepEqualErr(v17v1, v17v2, t, "equal-slice-v17-p-1") v17va = [8]interface{}{} // clear the array v17v2 = v17va[:len(v17v1):len(v17v1)] testUnmarshalErr(&v17v2, bs17, h, t, "dec-slice-v17-p-len") testDeepEqualErr(v17v1, v17v2, t, "equal-slice-v17-p-len") v17va = [8]interface{}{} // clear the array v17v2 = v17va[:] testUnmarshalErr(&v17v2, bs17, h, t, "dec-slice-v17-p-cap") testDeepEqualErr(v17v1, v17v2, t, "equal-slice-v17-p-cap") if len(v17v1) > 1 { v17va = [8]interface{}{} // clear the array testUnmarshalErr((&v17va)[:len(v17v1)], bs17, h, t, "dec-slice-v17-p-len-noaddr") testDeepEqualErr(v17v1, v17va[:len(v17v1)], t, "equal-slice-v17-p-len-noaddr") v17va = [8]interface{}{} // clear the array testUnmarshalErr((&v17va)[:], bs17, h, t, "dec-slice-v17-p-cap-noaddr") testDeepEqualErr(v17v1, v17va[:len(v17v1)], t, "equal-slice-v17-p-cap-noaddr") } testReleaseBytes(bs17) // ... var v17v3, v17v4 typMbsSliceIntf v17v2 = nil if v != nil { v17v2 = make([]interface{}, len(v)) } v17v3 = typMbsSliceIntf(v17v1) v17v4 = typMbsSliceIntf(v17v2) if v != nil { bs17 = testMarshalErr(v17v3, h, t, "enc-slice-v17-custom") testUnmarshalErr(v17v4, bs17, h, t, "dec-slice-v17-custom") testDeepEqualErr(v17v3, v17v4, t, "equal-slice-v17-custom") testReleaseBytes(bs17) } bs17 = testMarshalErr(&v17v3, h, t, "enc-slice-v17-custom-p") v17v2 = nil v17v4 = typMbsSliceIntf(v17v2) testUnmarshalErr(&v17v4, bs17, h, t, "dec-slice-v17-custom-p") testDeepEqualErr(v17v3, v17v4, t, "equal-slice-v17-custom-p") testReleaseBytes(bs17) } var v18va [8]string for _, v := range [][]string{nil, {}, {"some-string-2", "", "", "some-string-3"}} { var v18v1, v18v2 []string var bs18 []byte v18v1 = v bs18 = testMarshalErr(v18v1, h, t, "enc-slice-v18") if v == nil { v18v2 = make([]string, 2) testUnmarshalErr(v18v2, bs18, h, t, "dec-slice-v18") testDeepEqualErr(v18v2[0], v18v2[1], t, "equal-slice-v18") // should not change testDeepEqualErr(len(v18v2), 2, t, "equal-slice-v18") // should not change v18v2 = make([]string, 2) testUnmarshalErr(reflect.ValueOf(v18v2), bs18, h, t, "dec-slice-v18-noaddr") // non-addressable value testDeepEqualErr(v18v2[0], v18v2[1], t, "equal-slice-v18-noaddr") // should not change testDeepEqualErr(len(v18v2), 2, t, "equal-slice-v18") // should not change } else { v18v2 = make([]string, len(v)) testUnmarshalErr(v18v2, bs18, h, t, "dec-slice-v18") testDeepEqualErr(v18v1, v18v2, t, "equal-slice-v18") v18v2 = make([]string, len(v)) testUnmarshalErr(reflect.ValueOf(v18v2), bs18, h, t, "dec-slice-v18-noaddr") // non-addressable value testDeepEqualErr(v18v1, v18v2, t, "equal-slice-v18-noaddr") } testReleaseBytes(bs18) // ... bs18 = testMarshalErr(&v18v1, h, t, "enc-slice-v18-p") v18v2 = nil testUnmarshalErr(&v18v2, bs18, h, t, "dec-slice-v18-p") testDeepEqualErr(v18v1, v18v2, t, "equal-slice-v18-p") v18va = [8]string{} // clear the array testUnmarshalErr(&v18va, bs18, h, t, "dec-array-v18-p-1") if v18v1 == nil && v18v2 == nil { v18v2 = []string{} } // so we can compare to zero len slice below testDeepEqualErr(v18va[:len(v18v2)], v18v2, t, "equal-array-v18-p-1") v18va = [8]string{} // clear the array v18v2 = v18va[:1:1] testUnmarshalErr(&v18v2, bs18, h, t, "dec-slice-v18-p-1") testDeepEqualErr(v18v1, v18v2, t, "equal-slice-v18-p-1") v18va = [8]string{} // clear the array v18v2 = v18va[:len(v18v1):len(v18v1)] testUnmarshalErr(&v18v2, bs18, h, t, "dec-slice-v18-p-len") testDeepEqualErr(v18v1, v18v2, t, "equal-slice-v18-p-len") v18va = [8]string{} // clear the array v18v2 = v18va[:] testUnmarshalErr(&v18v2, bs18, h, t, "dec-slice-v18-p-cap") testDeepEqualErr(v18v1, v18v2, t, "equal-slice-v18-p-cap") if len(v18v1) > 1 { v18va = [8]string{} // clear the array testUnmarshalErr((&v18va)[:len(v18v1)], bs18, h, t, "dec-slice-v18-p-len-noaddr") testDeepEqualErr(v18v1, v18va[:len(v18v1)], t, "equal-slice-v18-p-len-noaddr") v18va = [8]string{} // clear the array testUnmarshalErr((&v18va)[:], bs18, h, t, "dec-slice-v18-p-cap-noaddr") testDeepEqualErr(v18v1, v18va[:len(v18v1)], t, "equal-slice-v18-p-cap-noaddr") } testReleaseBytes(bs18) // ... var v18v3, v18v4 typMbsSliceString v18v2 = nil if v != nil { v18v2 = make([]string, len(v)) } v18v3 = typMbsSliceString(v18v1) v18v4 = typMbsSliceString(v18v2) if v != nil { bs18 = testMarshalErr(v18v3, h, t, "enc-slice-v18-custom") testUnmarshalErr(v18v4, bs18, h, t, "dec-slice-v18-custom") testDeepEqualErr(v18v3, v18v4, t, "equal-slice-v18-custom") testReleaseBytes(bs18) } bs18 = testMarshalErr(&v18v3, h, t, "enc-slice-v18-custom-p") v18v2 = nil v18v4 = typMbsSliceString(v18v2) testUnmarshalErr(&v18v4, bs18, h, t, "dec-slice-v18-custom-p") testDeepEqualErr(v18v3, v18v4, t, "equal-slice-v18-custom-p") testReleaseBytes(bs18) } var v19va [8][]byte for _, v := range [][][]byte{nil, {}, {[]byte("some-string-2"), nil, nil, []byte("some-string-3")}} { var v19v1, v19v2 [][]byte var bs19 []byte v19v1 = v bs19 = testMarshalErr(v19v1, h, t, "enc-slice-v19") if v == nil { v19v2 = make([][]byte, 2) testUnmarshalErr(v19v2, bs19, h, t, "dec-slice-v19") testDeepEqualErr(v19v2[0], v19v2[1], t, "equal-slice-v19") // should not change testDeepEqualErr(len(v19v2), 2, t, "equal-slice-v19") // should not change v19v2 = make([][]byte, 2) testUnmarshalErr(reflect.ValueOf(v19v2), bs19, h, t, "dec-slice-v19-noaddr") // non-addressable value testDeepEqualErr(v19v2[0], v19v2[1], t, "equal-slice-v19-noaddr") // should not change testDeepEqualErr(len(v19v2), 2, t, "equal-slice-v19") // should not change } else { v19v2 = make([][]byte, len(v)) testUnmarshalErr(v19v2, bs19, h, t, "dec-slice-v19") testDeepEqualErr(v19v1, v19v2, t, "equal-slice-v19") v19v2 = make([][]byte, len(v)) testUnmarshalErr(reflect.ValueOf(v19v2), bs19, h, t, "dec-slice-v19-noaddr") // non-addressable value testDeepEqualErr(v19v1, v19v2, t, "equal-slice-v19-noaddr") } testReleaseBytes(bs19) // ... bs19 = testMarshalErr(&v19v1, h, t, "enc-slice-v19-p") v19v2 = nil testUnmarshalErr(&v19v2, bs19, h, t, "dec-slice-v19-p") testDeepEqualErr(v19v1, v19v2, t, "equal-slice-v19-p") v19va = [8][]byte{} // clear the array testUnmarshalErr(&v19va, bs19, h, t, "dec-array-v19-p-1") if v19v1 == nil && v19v2 == nil { v19v2 = [][]byte{} } // so we can compare to zero len slice below testDeepEqualErr(v19va[:len(v19v2)], v19v2, t, "equal-array-v19-p-1") v19va = [8][]byte{} // clear the array v19v2 = v19va[:1:1] testUnmarshalErr(&v19v2, bs19, h, t, "dec-slice-v19-p-1") testDeepEqualErr(v19v1, v19v2, t, "equal-slice-v19-p-1") v19va = [8][]byte{} // clear the array v19v2 = v19va[:len(v19v1):len(v19v1)] testUnmarshalErr(&v19v2, bs19, h, t, "dec-slice-v19-p-len") testDeepEqualErr(v19v1, v19v2, t, "equal-slice-v19-p-len") v19va = [8][]byte{} // clear the array v19v2 = v19va[:] testUnmarshalErr(&v19v2, bs19, h, t, "dec-slice-v19-p-cap") testDeepEqualErr(v19v1, v19v2, t, "equal-slice-v19-p-cap") if len(v19v1) > 1 { v19va = [8][]byte{} // clear the array testUnmarshalErr((&v19va)[:len(v19v1)], bs19, h, t, "dec-slice-v19-p-len-noaddr") testDeepEqualErr(v19v1, v19va[:len(v19v1)], t, "equal-slice-v19-p-len-noaddr") v19va = [8][]byte{} // clear the array testUnmarshalErr((&v19va)[:], bs19, h, t, "dec-slice-v19-p-cap-noaddr") testDeepEqualErr(v19v1, v19va[:len(v19v1)], t, "equal-slice-v19-p-cap-noaddr") } testReleaseBytes(bs19) // ... var v19v3, v19v4 typMbsSliceBytes v19v2 = nil if v != nil { v19v2 = make([][]byte, len(v)) } v19v3 = typMbsSliceBytes(v19v1) v19v4 = typMbsSliceBytes(v19v2) if v != nil { bs19 = testMarshalErr(v19v3, h, t, "enc-slice-v19-custom") testUnmarshalErr(v19v4, bs19, h, t, "dec-slice-v19-custom") testDeepEqualErr(v19v3, v19v4, t, "equal-slice-v19-custom") testReleaseBytes(bs19) } bs19 = testMarshalErr(&v19v3, h, t, "enc-slice-v19-custom-p") v19v2 = nil v19v4 = typMbsSliceBytes(v19v2) testUnmarshalErr(&v19v4, bs19, h, t, "dec-slice-v19-custom-p") testDeepEqualErr(v19v3, v19v4, t, "equal-slice-v19-custom-p") testReleaseBytes(bs19) } var v20va [8]float32 for _, v := range [][]float32{nil, {}, {22.2, 0, 0, 33.3e3}} { var v20v1, v20v2 []float32 var bs20 []byte v20v1 = v bs20 = testMarshalErr(v20v1, h, t, "enc-slice-v20") if v == nil { v20v2 = make([]float32, 2) testUnmarshalErr(v20v2, bs20, h, t, "dec-slice-v20") testDeepEqualErr(v20v2[0], v20v2[1], t, "equal-slice-v20") // should not change testDeepEqualErr(len(v20v2), 2, t, "equal-slice-v20") // should not change v20v2 = make([]float32, 2) testUnmarshalErr(reflect.ValueOf(v20v2), bs20, h, t, "dec-slice-v20-noaddr") // non-addressable value testDeepEqualErr(v20v2[0], v20v2[1], t, "equal-slice-v20-noaddr") // should not change testDeepEqualErr(len(v20v2), 2, t, "equal-slice-v20") // should not change } else { v20v2 = make([]float32, len(v)) testUnmarshalErr(v20v2, bs20, h, t, "dec-slice-v20") testDeepEqualErr(v20v1, v20v2, t, "equal-slice-v20") v20v2 = make([]float32, len(v)) testUnmarshalErr(reflect.ValueOf(v20v2), bs20, h, t, "dec-slice-v20-noaddr") // non-addressable value testDeepEqualErr(v20v1, v20v2, t, "equal-slice-v20-noaddr") } testReleaseBytes(bs20) // ... bs20 = testMarshalErr(&v20v1, h, t, "enc-slice-v20-p") v20v2 = nil testUnmarshalErr(&v20v2, bs20, h, t, "dec-slice-v20-p") testDeepEqualErr(v20v1, v20v2, t, "equal-slice-v20-p") v20va = [8]float32{} // clear the array testUnmarshalErr(&v20va, bs20, h, t, "dec-array-v20-p-1") if v20v1 == nil && v20v2 == nil { v20v2 = []float32{} } // so we can compare to zero len slice below testDeepEqualErr(v20va[:len(v20v2)], v20v2, t, "equal-array-v20-p-1") v20va = [8]float32{} // clear the array v20v2 = v20va[:1:1] testUnmarshalErr(&v20v2, bs20, h, t, "dec-slice-v20-p-1") testDeepEqualErr(v20v1, v20v2, t, "equal-slice-v20-p-1") v20va = [8]float32{} // clear the array v20v2 = v20va[:len(v20v1):len(v20v1)] testUnmarshalErr(&v20v2, bs20, h, t, "dec-slice-v20-p-len") testDeepEqualErr(v20v1, v20v2, t, "equal-slice-v20-p-len") v20va = [8]float32{} // clear the array v20v2 = v20va[:] testUnmarshalErr(&v20v2, bs20, h, t, "dec-slice-v20-p-cap") testDeepEqualErr(v20v1, v20v2, t, "equal-slice-v20-p-cap") if len(v20v1) > 1 { v20va = [8]float32{} // clear the array testUnmarshalErr((&v20va)[:len(v20v1)], bs20, h, t, "dec-slice-v20-p-len-noaddr") testDeepEqualErr(v20v1, v20va[:len(v20v1)], t, "equal-slice-v20-p-len-noaddr") v20va = [8]float32{} // clear the array testUnmarshalErr((&v20va)[:], bs20, h, t, "dec-slice-v20-p-cap-noaddr") testDeepEqualErr(v20v1, v20va[:len(v20v1)], t, "equal-slice-v20-p-cap-noaddr") } testReleaseBytes(bs20) // ... var v20v3, v20v4 typMbsSliceFloat32 v20v2 = nil if v != nil { v20v2 = make([]float32, len(v)) } v20v3 = typMbsSliceFloat32(v20v1) v20v4 = typMbsSliceFloat32(v20v2) if v != nil { bs20 = testMarshalErr(v20v3, h, t, "enc-slice-v20-custom") testUnmarshalErr(v20v4, bs20, h, t, "dec-slice-v20-custom") testDeepEqualErr(v20v3, v20v4, t, "equal-slice-v20-custom") testReleaseBytes(bs20) } bs20 = testMarshalErr(&v20v3, h, t, "enc-slice-v20-custom-p") v20v2 = nil v20v4 = typMbsSliceFloat32(v20v2) testUnmarshalErr(&v20v4, bs20, h, t, "dec-slice-v20-custom-p") testDeepEqualErr(v20v3, v20v4, t, "equal-slice-v20-custom-p") testReleaseBytes(bs20) } var v21va [8]float64 for _, v := range [][]float64{nil, {}, {11.1, 0, 0, 22.2}} { var v21v1, v21v2 []float64 var bs21 []byte v21v1 = v bs21 = testMarshalErr(v21v1, h, t, "enc-slice-v21") if v == nil { v21v2 = make([]float64, 2) testUnmarshalErr(v21v2, bs21, h, t, "dec-slice-v21") testDeepEqualErr(v21v2[0], v21v2[1], t, "equal-slice-v21") // should not change testDeepEqualErr(len(v21v2), 2, t, "equal-slice-v21") // should not change v21v2 = make([]float64, 2) testUnmarshalErr(reflect.ValueOf(v21v2), bs21, h, t, "dec-slice-v21-noaddr") // non-addressable value testDeepEqualErr(v21v2[0], v21v2[1], t, "equal-slice-v21-noaddr") // should not change testDeepEqualErr(len(v21v2), 2, t, "equal-slice-v21") // should not change } else { v21v2 = make([]float64, len(v)) testUnmarshalErr(v21v2, bs21, h, t, "dec-slice-v21") testDeepEqualErr(v21v1, v21v2, t, "equal-slice-v21") v21v2 = make([]float64, len(v)) testUnmarshalErr(reflect.ValueOf(v21v2), bs21, h, t, "dec-slice-v21-noaddr") // non-addressable value testDeepEqualErr(v21v1, v21v2, t, "equal-slice-v21-noaddr") } testReleaseBytes(bs21) // ... bs21 = testMarshalErr(&v21v1, h, t, "enc-slice-v21-p") v21v2 = nil testUnmarshalErr(&v21v2, bs21, h, t, "dec-slice-v21-p") testDeepEqualErr(v21v1, v21v2, t, "equal-slice-v21-p") v21va = [8]float64{} // clear the array testUnmarshalErr(&v21va, bs21, h, t, "dec-array-v21-p-1") if v21v1 == nil && v21v2 == nil { v21v2 = []float64{} } // so we can compare to zero len slice below testDeepEqualErr(v21va[:len(v21v2)], v21v2, t, "equal-array-v21-p-1") v21va = [8]float64{} // clear the array v21v2 = v21va[:1:1] testUnmarshalErr(&v21v2, bs21, h, t, "dec-slice-v21-p-1") testDeepEqualErr(v21v1, v21v2, t, "equal-slice-v21-p-1") v21va = [8]float64{} // clear the array v21v2 = v21va[:len(v21v1):len(v21v1)] testUnmarshalErr(&v21v2, bs21, h, t, "dec-slice-v21-p-len") testDeepEqualErr(v21v1, v21v2, t, "equal-slice-v21-p-len") v21va = [8]float64{} // clear the array v21v2 = v21va[:] testUnmarshalErr(&v21v2, bs21, h, t, "dec-slice-v21-p-cap") testDeepEqualErr(v21v1, v21v2, t, "equal-slice-v21-p-cap") if len(v21v1) > 1 { v21va = [8]float64{} // clear the array testUnmarshalErr((&v21va)[:len(v21v1)], bs21, h, t, "dec-slice-v21-p-len-noaddr") testDeepEqualErr(v21v1, v21va[:len(v21v1)], t, "equal-slice-v21-p-len-noaddr") v21va = [8]float64{} // clear the array testUnmarshalErr((&v21va)[:], bs21, h, t, "dec-slice-v21-p-cap-noaddr") testDeepEqualErr(v21v1, v21va[:len(v21v1)], t, "equal-slice-v21-p-cap-noaddr") } testReleaseBytes(bs21) // ... var v21v3, v21v4 typMbsSliceFloat64 v21v2 = nil if v != nil { v21v2 = make([]float64, len(v)) } v21v3 = typMbsSliceFloat64(v21v1) v21v4 = typMbsSliceFloat64(v21v2) if v != nil { bs21 = testMarshalErr(v21v3, h, t, "enc-slice-v21-custom") testUnmarshalErr(v21v4, bs21, h, t, "dec-slice-v21-custom") testDeepEqualErr(v21v3, v21v4, t, "equal-slice-v21-custom") testReleaseBytes(bs21) } bs21 = testMarshalErr(&v21v3, h, t, "enc-slice-v21-custom-p") v21v2 = nil v21v4 = typMbsSliceFloat64(v21v2) testUnmarshalErr(&v21v4, bs21, h, t, "dec-slice-v21-custom-p") testDeepEqualErr(v21v3, v21v4, t, "equal-slice-v21-custom-p") testReleaseBytes(bs21) } var v22va [8]uint8 for _, v := range [][]uint8{nil, {}, {77, 0, 0, 127}} { var v22v1, v22v2 []uint8 var bs22 []byte v22v1 = v bs22 = testMarshalErr(v22v1, h, t, "enc-slice-v22") if v == nil { v22v2 = make([]uint8, 2) testUnmarshalErr(v22v2, bs22, h, t, "dec-slice-v22") testDeepEqualErr(v22v2[0], v22v2[1], t, "equal-slice-v22") // should not change testDeepEqualErr(len(v22v2), 2, t, "equal-slice-v22") // should not change v22v2 = make([]uint8, 2) testUnmarshalErr(reflect.ValueOf(v22v2), bs22, h, t, "dec-slice-v22-noaddr") // non-addressable value testDeepEqualErr(v22v2[0], v22v2[1], t, "equal-slice-v22-noaddr") // should not change testDeepEqualErr(len(v22v2), 2, t, "equal-slice-v22") // should not change } else { v22v2 = make([]uint8, len(v)) testUnmarshalErr(v22v2, bs22, h, t, "dec-slice-v22") testDeepEqualErr(v22v1, v22v2, t, "equal-slice-v22") v22v2 = make([]uint8, len(v)) testUnmarshalErr(reflect.ValueOf(v22v2), bs22, h, t, "dec-slice-v22-noaddr") // non-addressable value testDeepEqualErr(v22v1, v22v2, t, "equal-slice-v22-noaddr") } testReleaseBytes(bs22) // ... bs22 = testMarshalErr(&v22v1, h, t, "enc-slice-v22-p") v22v2 = nil testUnmarshalErr(&v22v2, bs22, h, t, "dec-slice-v22-p") testDeepEqualErr(v22v1, v22v2, t, "equal-slice-v22-p") v22va = [8]uint8{} // clear the array testUnmarshalErr(&v22va, bs22, h, t, "dec-array-v22-p-1") if v22v1 == nil && v22v2 == nil { v22v2 = []uint8{} } // so we can compare to zero len slice below testDeepEqualErr(v22va[:len(v22v2)], v22v2, t, "equal-array-v22-p-1") v22va = [8]uint8{} // clear the array v22v2 = v22va[:1:1] testUnmarshalErr(&v22v2, bs22, h, t, "dec-slice-v22-p-1") testDeepEqualErr(v22v1, v22v2, t, "equal-slice-v22-p-1") v22va = [8]uint8{} // clear the array v22v2 = v22va[:len(v22v1):len(v22v1)] testUnmarshalErr(&v22v2, bs22, h, t, "dec-slice-v22-p-len") testDeepEqualErr(v22v1, v22v2, t, "equal-slice-v22-p-len") v22va = [8]uint8{} // clear the array v22v2 = v22va[:] testUnmarshalErr(&v22v2, bs22, h, t, "dec-slice-v22-p-cap") testDeepEqualErr(v22v1, v22v2, t, "equal-slice-v22-p-cap") if len(v22v1) > 1 { v22va = [8]uint8{} // clear the array testUnmarshalErr((&v22va)[:len(v22v1)], bs22, h, t, "dec-slice-v22-p-len-noaddr") testDeepEqualErr(v22v1, v22va[:len(v22v1)], t, "equal-slice-v22-p-len-noaddr") v22va = [8]uint8{} // clear the array testUnmarshalErr((&v22va)[:], bs22, h, t, "dec-slice-v22-p-cap-noaddr") testDeepEqualErr(v22v1, v22va[:len(v22v1)], t, "equal-slice-v22-p-cap-noaddr") } testReleaseBytes(bs22) // ... var v22v3, v22v4 typMbsSliceUint8 v22v2 = nil if v != nil { v22v2 = make([]uint8, len(v)) } v22v3 = typMbsSliceUint8(v22v1) v22v4 = typMbsSliceUint8(v22v2) if v != nil { bs22 = testMarshalErr(v22v3, h, t, "enc-slice-v22-custom") testUnmarshalErr(v22v4, bs22, h, t, "dec-slice-v22-custom") testDeepEqualErr(v22v3, v22v4, t, "equal-slice-v22-custom") testReleaseBytes(bs22) } bs22 = testMarshalErr(&v22v3, h, t, "enc-slice-v22-custom-p") v22v2 = nil v22v4 = typMbsSliceUint8(v22v2) testUnmarshalErr(&v22v4, bs22, h, t, "dec-slice-v22-custom-p") testDeepEqualErr(v22v3, v22v4, t, "equal-slice-v22-custom-p") testReleaseBytes(bs22) } var v23va [8]uint64 for _, v := range [][]uint64{nil, {}, {111, 0, 0, 77}} { var v23v1, v23v2 []uint64 var bs23 []byte v23v1 = v bs23 = testMarshalErr(v23v1, h, t, "enc-slice-v23") if v == nil { v23v2 = make([]uint64, 2) testUnmarshalErr(v23v2, bs23, h, t, "dec-slice-v23") testDeepEqualErr(v23v2[0], v23v2[1], t, "equal-slice-v23") // should not change testDeepEqualErr(len(v23v2), 2, t, "equal-slice-v23") // should not change v23v2 = make([]uint64, 2) testUnmarshalErr(reflect.ValueOf(v23v2), bs23, h, t, "dec-slice-v23-noaddr") // non-addressable value testDeepEqualErr(v23v2[0], v23v2[1], t, "equal-slice-v23-noaddr") // should not change testDeepEqualErr(len(v23v2), 2, t, "equal-slice-v23") // should not change } else { v23v2 = make([]uint64, len(v)) testUnmarshalErr(v23v2, bs23, h, t, "dec-slice-v23") testDeepEqualErr(v23v1, v23v2, t, "equal-slice-v23") v23v2 = make([]uint64, len(v)) testUnmarshalErr(reflect.ValueOf(v23v2), bs23, h, t, "dec-slice-v23-noaddr") // non-addressable value testDeepEqualErr(v23v1, v23v2, t, "equal-slice-v23-noaddr") } testReleaseBytes(bs23) // ... bs23 = testMarshalErr(&v23v1, h, t, "enc-slice-v23-p") v23v2 = nil testUnmarshalErr(&v23v2, bs23, h, t, "dec-slice-v23-p") testDeepEqualErr(v23v1, v23v2, t, "equal-slice-v23-p") v23va = [8]uint64{} // clear the array testUnmarshalErr(&v23va, bs23, h, t, "dec-array-v23-p-1") if v23v1 == nil && v23v2 == nil { v23v2 = []uint64{} } // so we can compare to zero len slice below testDeepEqualErr(v23va[:len(v23v2)], v23v2, t, "equal-array-v23-p-1") v23va = [8]uint64{} // clear the array v23v2 = v23va[:1:1] testUnmarshalErr(&v23v2, bs23, h, t, "dec-slice-v23-p-1") testDeepEqualErr(v23v1, v23v2, t, "equal-slice-v23-p-1") v23va = [8]uint64{} // clear the array v23v2 = v23va[:len(v23v1):len(v23v1)] testUnmarshalErr(&v23v2, bs23, h, t, "dec-slice-v23-p-len") testDeepEqualErr(v23v1, v23v2, t, "equal-slice-v23-p-len") v23va = [8]uint64{} // clear the array v23v2 = v23va[:] testUnmarshalErr(&v23v2, bs23, h, t, "dec-slice-v23-p-cap") testDeepEqualErr(v23v1, v23v2, t, "equal-slice-v23-p-cap") if len(v23v1) > 1 { v23va = [8]uint64{} // clear the array testUnmarshalErr((&v23va)[:len(v23v1)], bs23, h, t, "dec-slice-v23-p-len-noaddr") testDeepEqualErr(v23v1, v23va[:len(v23v1)], t, "equal-slice-v23-p-len-noaddr") v23va = [8]uint64{} // clear the array testUnmarshalErr((&v23va)[:], bs23, h, t, "dec-slice-v23-p-cap-noaddr") testDeepEqualErr(v23v1, v23va[:len(v23v1)], t, "equal-slice-v23-p-cap-noaddr") } testReleaseBytes(bs23) // ... var v23v3, v23v4 typMbsSliceUint64 v23v2 = nil if v != nil { v23v2 = make([]uint64, len(v)) } v23v3 = typMbsSliceUint64(v23v1) v23v4 = typMbsSliceUint64(v23v2) if v != nil { bs23 = testMarshalErr(v23v3, h, t, "enc-slice-v23-custom") testUnmarshalErr(v23v4, bs23, h, t, "dec-slice-v23-custom") testDeepEqualErr(v23v3, v23v4, t, "equal-slice-v23-custom") testReleaseBytes(bs23) } bs23 = testMarshalErr(&v23v3, h, t, "enc-slice-v23-custom-p") v23v2 = nil v23v4 = typMbsSliceUint64(v23v2) testUnmarshalErr(&v23v4, bs23, h, t, "dec-slice-v23-custom-p") testDeepEqualErr(v23v3, v23v4, t, "equal-slice-v23-custom-p") testReleaseBytes(bs23) } var v24va [8]int for _, v := range [][]int{nil, {}, {127, 0, 0, 111}} { var v24v1, v24v2 []int var bs24 []byte v24v1 = v bs24 = testMarshalErr(v24v1, h, t, "enc-slice-v24") if v == nil { v24v2 = make([]int, 2) testUnmarshalErr(v24v2, bs24, h, t, "dec-slice-v24") testDeepEqualErr(v24v2[0], v24v2[1], t, "equal-slice-v24") // should not change testDeepEqualErr(len(v24v2), 2, t, "equal-slice-v24") // should not change v24v2 = make([]int, 2) testUnmarshalErr(reflect.ValueOf(v24v2), bs24, h, t, "dec-slice-v24-noaddr") // non-addressable value testDeepEqualErr(v24v2[0], v24v2[1], t, "equal-slice-v24-noaddr") // should not change testDeepEqualErr(len(v24v2), 2, t, "equal-slice-v24") // should not change } else { v24v2 = make([]int, len(v)) testUnmarshalErr(v24v2, bs24, h, t, "dec-slice-v24") testDeepEqualErr(v24v1, v24v2, t, "equal-slice-v24") v24v2 = make([]int, len(v)) testUnmarshalErr(reflect.ValueOf(v24v2), bs24, h, t, "dec-slice-v24-noaddr") // non-addressable value testDeepEqualErr(v24v1, v24v2, t, "equal-slice-v24-noaddr") } testReleaseBytes(bs24) // ... bs24 = testMarshalErr(&v24v1, h, t, "enc-slice-v24-p") v24v2 = nil testUnmarshalErr(&v24v2, bs24, h, t, "dec-slice-v24-p") testDeepEqualErr(v24v1, v24v2, t, "equal-slice-v24-p") v24va = [8]int{} // clear the array testUnmarshalErr(&v24va, bs24, h, t, "dec-array-v24-p-1") if v24v1 == nil && v24v2 == nil { v24v2 = []int{} } // so we can compare to zero len slice below testDeepEqualErr(v24va[:len(v24v2)], v24v2, t, "equal-array-v24-p-1") v24va = [8]int{} // clear the array v24v2 = v24va[:1:1] testUnmarshalErr(&v24v2, bs24, h, t, "dec-slice-v24-p-1") testDeepEqualErr(v24v1, v24v2, t, "equal-slice-v24-p-1") v24va = [8]int{} // clear the array v24v2 = v24va[:len(v24v1):len(v24v1)] testUnmarshalErr(&v24v2, bs24, h, t, "dec-slice-v24-p-len") testDeepEqualErr(v24v1, v24v2, t, "equal-slice-v24-p-len") v24va = [8]int{} // clear the array v24v2 = v24va[:] testUnmarshalErr(&v24v2, bs24, h, t, "dec-slice-v24-p-cap") testDeepEqualErr(v24v1, v24v2, t, "equal-slice-v24-p-cap") if len(v24v1) > 1 { v24va = [8]int{} // clear the array testUnmarshalErr((&v24va)[:len(v24v1)], bs24, h, t, "dec-slice-v24-p-len-noaddr") testDeepEqualErr(v24v1, v24va[:len(v24v1)], t, "equal-slice-v24-p-len-noaddr") v24va = [8]int{} // clear the array testUnmarshalErr((&v24va)[:], bs24, h, t, "dec-slice-v24-p-cap-noaddr") testDeepEqualErr(v24v1, v24va[:len(v24v1)], t, "equal-slice-v24-p-cap-noaddr") } testReleaseBytes(bs24) // ... var v24v3, v24v4 typMbsSliceInt v24v2 = nil if v != nil { v24v2 = make([]int, len(v)) } v24v3 = typMbsSliceInt(v24v1) v24v4 = typMbsSliceInt(v24v2) if v != nil { bs24 = testMarshalErr(v24v3, h, t, "enc-slice-v24-custom") testUnmarshalErr(v24v4, bs24, h, t, "dec-slice-v24-custom") testDeepEqualErr(v24v3, v24v4, t, "equal-slice-v24-custom") testReleaseBytes(bs24) } bs24 = testMarshalErr(&v24v3, h, t, "enc-slice-v24-custom-p") v24v2 = nil v24v4 = typMbsSliceInt(v24v2) testUnmarshalErr(&v24v4, bs24, h, t, "dec-slice-v24-custom-p") testDeepEqualErr(v24v3, v24v4, t, "equal-slice-v24-custom-p") testReleaseBytes(bs24) } var v25va [8]int32 for _, v := range [][]int32{nil, {}, {77, 0, 0, 127}} { var v25v1, v25v2 []int32 var bs25 []byte v25v1 = v bs25 = testMarshalErr(v25v1, h, t, "enc-slice-v25") if v == nil { v25v2 = make([]int32, 2) testUnmarshalErr(v25v2, bs25, h, t, "dec-slice-v25") testDeepEqualErr(v25v2[0], v25v2[1], t, "equal-slice-v25") // should not change testDeepEqualErr(len(v25v2), 2, t, "equal-slice-v25") // should not change v25v2 = make([]int32, 2) testUnmarshalErr(reflect.ValueOf(v25v2), bs25, h, t, "dec-slice-v25-noaddr") // non-addressable value testDeepEqualErr(v25v2[0], v25v2[1], t, "equal-slice-v25-noaddr") // should not change testDeepEqualErr(len(v25v2), 2, t, "equal-slice-v25") // should not change } else { v25v2 = make([]int32, len(v)) testUnmarshalErr(v25v2, bs25, h, t, "dec-slice-v25") testDeepEqualErr(v25v1, v25v2, t, "equal-slice-v25") v25v2 = make([]int32, len(v)) testUnmarshalErr(reflect.ValueOf(v25v2), bs25, h, t, "dec-slice-v25-noaddr") // non-addressable value testDeepEqualErr(v25v1, v25v2, t, "equal-slice-v25-noaddr") } testReleaseBytes(bs25) // ... bs25 = testMarshalErr(&v25v1, h, t, "enc-slice-v25-p") v25v2 = nil testUnmarshalErr(&v25v2, bs25, h, t, "dec-slice-v25-p") testDeepEqualErr(v25v1, v25v2, t, "equal-slice-v25-p") v25va = [8]int32{} // clear the array testUnmarshalErr(&v25va, bs25, h, t, "dec-array-v25-p-1") if v25v1 == nil && v25v2 == nil { v25v2 = []int32{} } // so we can compare to zero len slice below testDeepEqualErr(v25va[:len(v25v2)], v25v2, t, "equal-array-v25-p-1") v25va = [8]int32{} // clear the array v25v2 = v25va[:1:1] testUnmarshalErr(&v25v2, bs25, h, t, "dec-slice-v25-p-1") testDeepEqualErr(v25v1, v25v2, t, "equal-slice-v25-p-1") v25va = [8]int32{} // clear the array v25v2 = v25va[:len(v25v1):len(v25v1)] testUnmarshalErr(&v25v2, bs25, h, t, "dec-slice-v25-p-len") testDeepEqualErr(v25v1, v25v2, t, "equal-slice-v25-p-len") v25va = [8]int32{} // clear the array v25v2 = v25va[:] testUnmarshalErr(&v25v2, bs25, h, t, "dec-slice-v25-p-cap") testDeepEqualErr(v25v1, v25v2, t, "equal-slice-v25-p-cap") if len(v25v1) > 1 { v25va = [8]int32{} // clear the array testUnmarshalErr((&v25va)[:len(v25v1)], bs25, h, t, "dec-slice-v25-p-len-noaddr") testDeepEqualErr(v25v1, v25va[:len(v25v1)], t, "equal-slice-v25-p-len-noaddr") v25va = [8]int32{} // clear the array testUnmarshalErr((&v25va)[:], bs25, h, t, "dec-slice-v25-p-cap-noaddr") testDeepEqualErr(v25v1, v25va[:len(v25v1)], t, "equal-slice-v25-p-cap-noaddr") } testReleaseBytes(bs25) // ... var v25v3, v25v4 typMbsSliceInt32 v25v2 = nil if v != nil { v25v2 = make([]int32, len(v)) } v25v3 = typMbsSliceInt32(v25v1) v25v4 = typMbsSliceInt32(v25v2) if v != nil { bs25 = testMarshalErr(v25v3, h, t, "enc-slice-v25-custom") testUnmarshalErr(v25v4, bs25, h, t, "dec-slice-v25-custom") testDeepEqualErr(v25v3, v25v4, t, "equal-slice-v25-custom") testReleaseBytes(bs25) } bs25 = testMarshalErr(&v25v3, h, t, "enc-slice-v25-custom-p") v25v2 = nil v25v4 = typMbsSliceInt32(v25v2) testUnmarshalErr(&v25v4, bs25, h, t, "dec-slice-v25-custom-p") testDeepEqualErr(v25v3, v25v4, t, "equal-slice-v25-custom-p") testReleaseBytes(bs25) } var v26va [8]int64 for _, v := range [][]int64{nil, {}, {111, 0, 0, 77}} { var v26v1, v26v2 []int64 var bs26 []byte v26v1 = v bs26 = testMarshalErr(v26v1, h, t, "enc-slice-v26") if v == nil { v26v2 = make([]int64, 2) testUnmarshalErr(v26v2, bs26, h, t, "dec-slice-v26") testDeepEqualErr(v26v2[0], v26v2[1], t, "equal-slice-v26") // should not change testDeepEqualErr(len(v26v2), 2, t, "equal-slice-v26") // should not change v26v2 = make([]int64, 2) testUnmarshalErr(reflect.ValueOf(v26v2), bs26, h, t, "dec-slice-v26-noaddr") // non-addressable value testDeepEqualErr(v26v2[0], v26v2[1], t, "equal-slice-v26-noaddr") // should not change testDeepEqualErr(len(v26v2), 2, t, "equal-slice-v26") // should not change } else { v26v2 = make([]int64, len(v)) testUnmarshalErr(v26v2, bs26, h, t, "dec-slice-v26") testDeepEqualErr(v26v1, v26v2, t, "equal-slice-v26") v26v2 = make([]int64, len(v)) testUnmarshalErr(reflect.ValueOf(v26v2), bs26, h, t, "dec-slice-v26-noaddr") // non-addressable value testDeepEqualErr(v26v1, v26v2, t, "equal-slice-v26-noaddr") } testReleaseBytes(bs26) // ... bs26 = testMarshalErr(&v26v1, h, t, "enc-slice-v26-p") v26v2 = nil testUnmarshalErr(&v26v2, bs26, h, t, "dec-slice-v26-p") testDeepEqualErr(v26v1, v26v2, t, "equal-slice-v26-p") v26va = [8]int64{} // clear the array testUnmarshalErr(&v26va, bs26, h, t, "dec-array-v26-p-1") if v26v1 == nil && v26v2 == nil { v26v2 = []int64{} } // so we can compare to zero len slice below testDeepEqualErr(v26va[:len(v26v2)], v26v2, t, "equal-array-v26-p-1") v26va = [8]int64{} // clear the array v26v2 = v26va[:1:1] testUnmarshalErr(&v26v2, bs26, h, t, "dec-slice-v26-p-1") testDeepEqualErr(v26v1, v26v2, t, "equal-slice-v26-p-1") v26va = [8]int64{} // clear the array v26v2 = v26va[:len(v26v1):len(v26v1)] testUnmarshalErr(&v26v2, bs26, h, t, "dec-slice-v26-p-len") testDeepEqualErr(v26v1, v26v2, t, "equal-slice-v26-p-len") v26va = [8]int64{} // clear the array v26v2 = v26va[:] testUnmarshalErr(&v26v2, bs26, h, t, "dec-slice-v26-p-cap") testDeepEqualErr(v26v1, v26v2, t, "equal-slice-v26-p-cap") if len(v26v1) > 1 { v26va = [8]int64{} // clear the array testUnmarshalErr((&v26va)[:len(v26v1)], bs26, h, t, "dec-slice-v26-p-len-noaddr") testDeepEqualErr(v26v1, v26va[:len(v26v1)], t, "equal-slice-v26-p-len-noaddr") v26va = [8]int64{} // clear the array testUnmarshalErr((&v26va)[:], bs26, h, t, "dec-slice-v26-p-cap-noaddr") testDeepEqualErr(v26v1, v26va[:len(v26v1)], t, "equal-slice-v26-p-cap-noaddr") } testReleaseBytes(bs26) // ... var v26v3, v26v4 typMbsSliceInt64 v26v2 = nil if v != nil { v26v2 = make([]int64, len(v)) } v26v3 = typMbsSliceInt64(v26v1) v26v4 = typMbsSliceInt64(v26v2) if v != nil { bs26 = testMarshalErr(v26v3, h, t, "enc-slice-v26-custom") testUnmarshalErr(v26v4, bs26, h, t, "dec-slice-v26-custom") testDeepEqualErr(v26v3, v26v4, t, "equal-slice-v26-custom") testReleaseBytes(bs26) } bs26 = testMarshalErr(&v26v3, h, t, "enc-slice-v26-custom-p") v26v2 = nil v26v4 = typMbsSliceInt64(v26v2) testUnmarshalErr(&v26v4, bs26, h, t, "dec-slice-v26-custom-p") testDeepEqualErr(v26v3, v26v4, t, "equal-slice-v26-custom-p") testReleaseBytes(bs26) } var v27va [8]bool for _, v := range [][]bool{nil, {}, {false, false, false, true}} { var v27v1, v27v2 []bool var bs27 []byte v27v1 = v bs27 = testMarshalErr(v27v1, h, t, "enc-slice-v27") if v == nil { v27v2 = make([]bool, 2) testUnmarshalErr(v27v2, bs27, h, t, "dec-slice-v27") testDeepEqualErr(v27v2[0], v27v2[1], t, "equal-slice-v27") // should not change testDeepEqualErr(len(v27v2), 2, t, "equal-slice-v27") // should not change v27v2 = make([]bool, 2) testUnmarshalErr(reflect.ValueOf(v27v2), bs27, h, t, "dec-slice-v27-noaddr") // non-addressable value testDeepEqualErr(v27v2[0], v27v2[1], t, "equal-slice-v27-noaddr") // should not change testDeepEqualErr(len(v27v2), 2, t, "equal-slice-v27") // should not change } else { v27v2 = make([]bool, len(v)) testUnmarshalErr(v27v2, bs27, h, t, "dec-slice-v27") testDeepEqualErr(v27v1, v27v2, t, "equal-slice-v27") v27v2 = make([]bool, len(v)) testUnmarshalErr(reflect.ValueOf(v27v2), bs27, h, t, "dec-slice-v27-noaddr") // non-addressable value testDeepEqualErr(v27v1, v27v2, t, "equal-slice-v27-noaddr") } testReleaseBytes(bs27) // ... bs27 = testMarshalErr(&v27v1, h, t, "enc-slice-v27-p") v27v2 = nil testUnmarshalErr(&v27v2, bs27, h, t, "dec-slice-v27-p") testDeepEqualErr(v27v1, v27v2, t, "equal-slice-v27-p") v27va = [8]bool{} // clear the array testUnmarshalErr(&v27va, bs27, h, t, "dec-array-v27-p-1") if v27v1 == nil && v27v2 == nil { v27v2 = []bool{} } // so we can compare to zero len slice below testDeepEqualErr(v27va[:len(v27v2)], v27v2, t, "equal-array-v27-p-1") v27va = [8]bool{} // clear the array v27v2 = v27va[:1:1] testUnmarshalErr(&v27v2, bs27, h, t, "dec-slice-v27-p-1") testDeepEqualErr(v27v1, v27v2, t, "equal-slice-v27-p-1") v27va = [8]bool{} // clear the array v27v2 = v27va[:len(v27v1):len(v27v1)] testUnmarshalErr(&v27v2, bs27, h, t, "dec-slice-v27-p-len") testDeepEqualErr(v27v1, v27v2, t, "equal-slice-v27-p-len") v27va = [8]bool{} // clear the array v27v2 = v27va[:] testUnmarshalErr(&v27v2, bs27, h, t, "dec-slice-v27-p-cap") testDeepEqualErr(v27v1, v27v2, t, "equal-slice-v27-p-cap") if len(v27v1) > 1 { v27va = [8]bool{} // clear the array testUnmarshalErr((&v27va)[:len(v27v1)], bs27, h, t, "dec-slice-v27-p-len-noaddr") testDeepEqualErr(v27v1, v27va[:len(v27v1)], t, "equal-slice-v27-p-len-noaddr") v27va = [8]bool{} // clear the array testUnmarshalErr((&v27va)[:], bs27, h, t, "dec-slice-v27-p-cap-noaddr") testDeepEqualErr(v27v1, v27va[:len(v27v1)], t, "equal-slice-v27-p-cap-noaddr") } testReleaseBytes(bs27) // ... var v27v3, v27v4 typMbsSliceBool v27v2 = nil if v != nil { v27v2 = make([]bool, len(v)) } v27v3 = typMbsSliceBool(v27v1) v27v4 = typMbsSliceBool(v27v2) if v != nil { bs27 = testMarshalErr(v27v3, h, t, "enc-slice-v27-custom") testUnmarshalErr(v27v4, bs27, h, t, "dec-slice-v27-custom") testDeepEqualErr(v27v3, v27v4, t, "equal-slice-v27-custom") testReleaseBytes(bs27) } bs27 = testMarshalErr(&v27v3, h, t, "enc-slice-v27-custom-p") v27v2 = nil v27v4 = typMbsSliceBool(v27v2) testUnmarshalErr(&v27v4, bs27, h, t, "dec-slice-v27-custom-p") testDeepEqualErr(v27v3, v27v4, t, "equal-slice-v27-custom-p") testReleaseBytes(bs27) } } func __doTestMammothMaps(t *testing.T, h Handle) { for _, v := range []map[string]interface{}{nil, {}, {"some-string-1": nil, "some-string-2": "string-is-an-interface-1"}} { // fmt.Printf(">>>> running mammoth map v28: %v\n", v) var v28v1, v28v2 map[string]interface{} var bs28 []byte v28v1 = v bs28 = testMarshalErr(v28v1, h, t, "enc-map-v28") if v != nil { if v == nil { v28v2 = nil } else { v28v2 = make(map[string]interface{}, len(v)) } // reset map testUnmarshalErr(v28v2, bs28, h, t, "dec-map-v28") testDeepEqualErr(v28v1, v28v2, t, "equal-map-v28") if v == nil { v28v2 = nil } else { v28v2 = make(map[string]interface{}, len(v)) } // reset map testUnmarshalErr(reflect.ValueOf(v28v2), bs28, h, t, "dec-map-v28-noaddr") // decode into non-addressable map value testDeepEqualErr(v28v1, v28v2, t, "equal-map-v28-noaddr") } if v == nil { v28v2 = nil } else { v28v2 = make(map[string]interface{}, len(v)) } // reset map testUnmarshalErr(&v28v2, bs28, h, t, "dec-map-v28-p-len") testDeepEqualErr(v28v1, v28v2, t, "equal-map-v28-p-len") testReleaseBytes(bs28) bs28 = testMarshalErr(&v28v1, h, t, "enc-map-v28-p") v28v2 = nil testUnmarshalErr(&v28v2, bs28, h, t, "dec-map-v28-p-nil") testDeepEqualErr(v28v1, v28v2, t, "equal-map-v28-p-nil") testReleaseBytes(bs28) // ... if v == nil { v28v2 = nil } else { v28v2 = make(map[string]interface{}, len(v)) } // reset map var v28v3, v28v4 typMapMapStringIntf v28v3 = typMapMapStringIntf(v28v1) v28v4 = typMapMapStringIntf(v28v2) if v != nil { bs28 = testMarshalErr(v28v3, h, t, "enc-map-v28-custom") testUnmarshalErr(v28v4, bs28, h, t, "dec-map-v28-p-len") testDeepEqualErr(v28v3, v28v4, t, "equal-map-v28-p-len") testReleaseBytes(bs28) } } for _, v := range []map[string]string{nil, {}, {"some-string-3": "", "some-string-1": "some-string-2"}} { // fmt.Printf(">>>> running mammoth map v29: %v\n", v) var v29v1, v29v2 map[string]string var bs29 []byte v29v1 = v bs29 = testMarshalErr(v29v1, h, t, "enc-map-v29") if v != nil { if v == nil { v29v2 = nil } else { v29v2 = make(map[string]string, len(v)) } // reset map testUnmarshalErr(v29v2, bs29, h, t, "dec-map-v29") testDeepEqualErr(v29v1, v29v2, t, "equal-map-v29") if v == nil { v29v2 = nil } else { v29v2 = make(map[string]string, len(v)) } // reset map testUnmarshalErr(reflect.ValueOf(v29v2), bs29, h, t, "dec-map-v29-noaddr") // decode into non-addressable map value testDeepEqualErr(v29v1, v29v2, t, "equal-map-v29-noaddr") } if v == nil { v29v2 = nil } else { v29v2 = make(map[string]string, len(v)) } // reset map testUnmarshalErr(&v29v2, bs29, h, t, "dec-map-v29-p-len") testDeepEqualErr(v29v1, v29v2, t, "equal-map-v29-p-len") testReleaseBytes(bs29) bs29 = testMarshalErr(&v29v1, h, t, "enc-map-v29-p") v29v2 = nil testUnmarshalErr(&v29v2, bs29, h, t, "dec-map-v29-p-nil") testDeepEqualErr(v29v1, v29v2, t, "equal-map-v29-p-nil") testReleaseBytes(bs29) // ... if v == nil { v29v2 = nil } else { v29v2 = make(map[string]string, len(v)) } // reset map var v29v3, v29v4 typMapMapStringString v29v3 = typMapMapStringString(v29v1) v29v4 = typMapMapStringString(v29v2) if v != nil { bs29 = testMarshalErr(v29v3, h, t, "enc-map-v29-custom") testUnmarshalErr(v29v4, bs29, h, t, "dec-map-v29-p-len") testDeepEqualErr(v29v3, v29v4, t, "equal-map-v29-p-len") testReleaseBytes(bs29) } } for _, v := range []map[string][]byte{nil, {}, {"some-string-3": nil, "some-string-1": []byte("some-string-1")}} { // fmt.Printf(">>>> running mammoth map v30: %v\n", v) var v30v1, v30v2 map[string][]byte var bs30 []byte v30v1 = v bs30 = testMarshalErr(v30v1, h, t, "enc-map-v30") if v != nil { if v == nil { v30v2 = nil } else { v30v2 = make(map[string][]byte, len(v)) } // reset map testUnmarshalErr(v30v2, bs30, h, t, "dec-map-v30") testDeepEqualErr(v30v1, v30v2, t, "equal-map-v30") if v == nil { v30v2 = nil } else { v30v2 = make(map[string][]byte, len(v)) } // reset map testUnmarshalErr(reflect.ValueOf(v30v2), bs30, h, t, "dec-map-v30-noaddr") // decode into non-addressable map value testDeepEqualErr(v30v1, v30v2, t, "equal-map-v30-noaddr") } if v == nil { v30v2 = nil } else { v30v2 = make(map[string][]byte, len(v)) } // reset map testUnmarshalErr(&v30v2, bs30, h, t, "dec-map-v30-p-len") testDeepEqualErr(v30v1, v30v2, t, "equal-map-v30-p-len") testReleaseBytes(bs30) bs30 = testMarshalErr(&v30v1, h, t, "enc-map-v30-p") v30v2 = nil testUnmarshalErr(&v30v2, bs30, h, t, "dec-map-v30-p-nil") testDeepEqualErr(v30v1, v30v2, t, "equal-map-v30-p-nil") testReleaseBytes(bs30) // ... if v == nil { v30v2 = nil } else { v30v2 = make(map[string][]byte, len(v)) } // reset map var v30v3, v30v4 typMapMapStringBytes v30v3 = typMapMapStringBytes(v30v1) v30v4 = typMapMapStringBytes(v30v2) if v != nil { bs30 = testMarshalErr(v30v3, h, t, "enc-map-v30-custom") testUnmarshalErr(v30v4, bs30, h, t, "dec-map-v30-p-len") testDeepEqualErr(v30v3, v30v4, t, "equal-map-v30-p-len") testReleaseBytes(bs30) } } for _, v := range []map[string]uint8{nil, {}, {"some-string-2": 0, "some-string-3": 127}} { // fmt.Printf(">>>> running mammoth map v31: %v\n", v) var v31v1, v31v2 map[string]uint8 var bs31 []byte v31v1 = v bs31 = testMarshalErr(v31v1, h, t, "enc-map-v31") if v != nil { if v == nil { v31v2 = nil } else { v31v2 = make(map[string]uint8, len(v)) } // reset map testUnmarshalErr(v31v2, bs31, h, t, "dec-map-v31") testDeepEqualErr(v31v1, v31v2, t, "equal-map-v31") if v == nil { v31v2 = nil } else { v31v2 = make(map[string]uint8, len(v)) } // reset map testUnmarshalErr(reflect.ValueOf(v31v2), bs31, h, t, "dec-map-v31-noaddr") // decode into non-addressable map value testDeepEqualErr(v31v1, v31v2, t, "equal-map-v31-noaddr") } if v == nil { v31v2 = nil } else { v31v2 = make(map[string]uint8, len(v)) } // reset map testUnmarshalErr(&v31v2, bs31, h, t, "dec-map-v31-p-len") testDeepEqualErr(v31v1, v31v2, t, "equal-map-v31-p-len") testReleaseBytes(bs31) bs31 = testMarshalErr(&v31v1, h, t, "enc-map-v31-p") v31v2 = nil testUnmarshalErr(&v31v2, bs31, h, t, "dec-map-v31-p-nil") testDeepEqualErr(v31v1, v31v2, t, "equal-map-v31-p-nil") testReleaseBytes(bs31) // ... if v == nil { v31v2 = nil } else { v31v2 = make(map[string]uint8, len(v)) } // reset map var v31v3, v31v4 typMapMapStringUint8 v31v3 = typMapMapStringUint8(v31v1) v31v4 = typMapMapStringUint8(v31v2) if v != nil { bs31 = testMarshalErr(v31v3, h, t, "enc-map-v31-custom") testUnmarshalErr(v31v4, bs31, h, t, "dec-map-v31-p-len") testDeepEqualErr(v31v3, v31v4, t, "equal-map-v31-p-len") testReleaseBytes(bs31) } } for _, v := range []map[string]uint64{nil, {}, {"some-string-1": 0, "some-string-2": 111}} { // fmt.Printf(">>>> running mammoth map v32: %v\n", v) var v32v1, v32v2 map[string]uint64 var bs32 []byte v32v1 = v bs32 = testMarshalErr(v32v1, h, t, "enc-map-v32") if v != nil { if v == nil { v32v2 = nil } else { v32v2 = make(map[string]uint64, len(v)) } // reset map testUnmarshalErr(v32v2, bs32, h, t, "dec-map-v32") testDeepEqualErr(v32v1, v32v2, t, "equal-map-v32") if v == nil { v32v2 = nil } else { v32v2 = make(map[string]uint64, len(v)) } // reset map testUnmarshalErr(reflect.ValueOf(v32v2), bs32, h, t, "dec-map-v32-noaddr") // decode into non-addressable map value testDeepEqualErr(v32v1, v32v2, t, "equal-map-v32-noaddr") } if v == nil { v32v2 = nil } else { v32v2 = make(map[string]uint64, len(v)) } // reset map testUnmarshalErr(&v32v2, bs32, h, t, "dec-map-v32-p-len") testDeepEqualErr(v32v1, v32v2, t, "equal-map-v32-p-len") testReleaseBytes(bs32) bs32 = testMarshalErr(&v32v1, h, t, "enc-map-v32-p") v32v2 = nil testUnmarshalErr(&v32v2, bs32, h, t, "dec-map-v32-p-nil") testDeepEqualErr(v32v1, v32v2, t, "equal-map-v32-p-nil") testReleaseBytes(bs32) // ... if v == nil { v32v2 = nil } else { v32v2 = make(map[string]uint64, len(v)) } // reset map var v32v3, v32v4 typMapMapStringUint64 v32v3 = typMapMapStringUint64(v32v1) v32v4 = typMapMapStringUint64(v32v2) if v != nil { bs32 = testMarshalErr(v32v3, h, t, "enc-map-v32-custom") testUnmarshalErr(v32v4, bs32, h, t, "dec-map-v32-p-len") testDeepEqualErr(v32v3, v32v4, t, "equal-map-v32-p-len") testReleaseBytes(bs32) } } for _, v := range []map[string]int{nil, {}, {"some-string-3": 0, "some-string-1": 77}} { // fmt.Printf(">>>> running mammoth map v33: %v\n", v) var v33v1, v33v2 map[string]int var bs33 []byte v33v1 = v bs33 = testMarshalErr(v33v1, h, t, "enc-map-v33") if v != nil { if v == nil { v33v2 = nil } else { v33v2 = make(map[string]int, len(v)) } // reset map testUnmarshalErr(v33v2, bs33, h, t, "dec-map-v33") testDeepEqualErr(v33v1, v33v2, t, "equal-map-v33") if v == nil { v33v2 = nil } else { v33v2 = make(map[string]int, len(v)) } // reset map testUnmarshalErr(reflect.ValueOf(v33v2), bs33, h, t, "dec-map-v33-noaddr") // decode into non-addressable map value testDeepEqualErr(v33v1, v33v2, t, "equal-map-v33-noaddr") } if v == nil { v33v2 = nil } else { v33v2 = make(map[string]int, len(v)) } // reset map testUnmarshalErr(&v33v2, bs33, h, t, "dec-map-v33-p-len") testDeepEqualErr(v33v1, v33v2, t, "equal-map-v33-p-len") testReleaseBytes(bs33) bs33 = testMarshalErr(&v33v1, h, t, "enc-map-v33-p") v33v2 = nil testUnmarshalErr(&v33v2, bs33, h, t, "dec-map-v33-p-nil") testDeepEqualErr(v33v1, v33v2, t, "equal-map-v33-p-nil") testReleaseBytes(bs33) // ... if v == nil { v33v2 = nil } else { v33v2 = make(map[string]int, len(v)) } // reset map var v33v3, v33v4 typMapMapStringInt v33v3 = typMapMapStringInt(v33v1) v33v4 = typMapMapStringInt(v33v2) if v != nil { bs33 = testMarshalErr(v33v3, h, t, "enc-map-v33-custom") testUnmarshalErr(v33v4, bs33, h, t, "dec-map-v33-p-len") testDeepEqualErr(v33v3, v33v4, t, "equal-map-v33-p-len") testReleaseBytes(bs33) } } for _, v := range []map[string]int32{nil, {}, {"some-string-2": 0, "some-string-3": 127}} { // fmt.Printf(">>>> running mammoth map v34: %v\n", v) var v34v1, v34v2 map[string]int32 var bs34 []byte v34v1 = v bs34 = testMarshalErr(v34v1, h, t, "enc-map-v34") if v != nil { if v == nil { v34v2 = nil } else { v34v2 = make(map[string]int32, len(v)) } // reset map testUnmarshalErr(v34v2, bs34, h, t, "dec-map-v34") testDeepEqualErr(v34v1, v34v2, t, "equal-map-v34") if v == nil { v34v2 = nil } else { v34v2 = make(map[string]int32, len(v)) } // reset map testUnmarshalErr(reflect.ValueOf(v34v2), bs34, h, t, "dec-map-v34-noaddr") // decode into non-addressable map value testDeepEqualErr(v34v1, v34v2, t, "equal-map-v34-noaddr") } if v == nil { v34v2 = nil } else { v34v2 = make(map[string]int32, len(v)) } // reset map testUnmarshalErr(&v34v2, bs34, h, t, "dec-map-v34-p-len") testDeepEqualErr(v34v1, v34v2, t, "equal-map-v34-p-len") testReleaseBytes(bs34) bs34 = testMarshalErr(&v34v1, h, t, "enc-map-v34-p") v34v2 = nil testUnmarshalErr(&v34v2, bs34, h, t, "dec-map-v34-p-nil") testDeepEqualErr(v34v1, v34v2, t, "equal-map-v34-p-nil") testReleaseBytes(bs34) // ... if v == nil { v34v2 = nil } else { v34v2 = make(map[string]int32, len(v)) } // reset map var v34v3, v34v4 typMapMapStringInt32 v34v3 = typMapMapStringInt32(v34v1) v34v4 = typMapMapStringInt32(v34v2) if v != nil { bs34 = testMarshalErr(v34v3, h, t, "enc-map-v34-custom") testUnmarshalErr(v34v4, bs34, h, t, "dec-map-v34-p-len") testDeepEqualErr(v34v3, v34v4, t, "equal-map-v34-p-len") testReleaseBytes(bs34) } } for _, v := range []map[string]float64{nil, {}, {"some-string-1": 0, "some-string-2": 33.3e3}} { // fmt.Printf(">>>> running mammoth map v35: %v\n", v) var v35v1, v35v2 map[string]float64 var bs35 []byte v35v1 = v bs35 = testMarshalErr(v35v1, h, t, "enc-map-v35") if v != nil { if v == nil { v35v2 = nil } else { v35v2 = make(map[string]float64, len(v)) } // reset map testUnmarshalErr(v35v2, bs35, h, t, "dec-map-v35") testDeepEqualErr(v35v1, v35v2, t, "equal-map-v35") if v == nil { v35v2 = nil } else { v35v2 = make(map[string]float64, len(v)) } // reset map testUnmarshalErr(reflect.ValueOf(v35v2), bs35, h, t, "dec-map-v35-noaddr") // decode into non-addressable map value testDeepEqualErr(v35v1, v35v2, t, "equal-map-v35-noaddr") } if v == nil { v35v2 = nil } else { v35v2 = make(map[string]float64, len(v)) } // reset map testUnmarshalErr(&v35v2, bs35, h, t, "dec-map-v35-p-len") testDeepEqualErr(v35v1, v35v2, t, "equal-map-v35-p-len") testReleaseBytes(bs35) bs35 = testMarshalErr(&v35v1, h, t, "enc-map-v35-p") v35v2 = nil testUnmarshalErr(&v35v2, bs35, h, t, "dec-map-v35-p-nil") testDeepEqualErr(v35v1, v35v2, t, "equal-map-v35-p-nil") testReleaseBytes(bs35) // ... if v == nil { v35v2 = nil } else { v35v2 = make(map[string]float64, len(v)) } // reset map var v35v3, v35v4 typMapMapStringFloat64 v35v3 = typMapMapStringFloat64(v35v1) v35v4 = typMapMapStringFloat64(v35v2) if v != nil { bs35 = testMarshalErr(v35v3, h, t, "enc-map-v35-custom") testUnmarshalErr(v35v4, bs35, h, t, "dec-map-v35-p-len") testDeepEqualErr(v35v3, v35v4, t, "equal-map-v35-p-len") testReleaseBytes(bs35) } } for _, v := range []map[string]bool{nil, {}, {"some-string-3": false, "some-string-1": true}} { // fmt.Printf(">>>> running mammoth map v36: %v\n", v) var v36v1, v36v2 map[string]bool var bs36 []byte v36v1 = v bs36 = testMarshalErr(v36v1, h, t, "enc-map-v36") if v != nil { if v == nil { v36v2 = nil } else { v36v2 = make(map[string]bool, len(v)) } // reset map testUnmarshalErr(v36v2, bs36, h, t, "dec-map-v36") testDeepEqualErr(v36v1, v36v2, t, "equal-map-v36") if v == nil { v36v2 = nil } else { v36v2 = make(map[string]bool, len(v)) } // reset map testUnmarshalErr(reflect.ValueOf(v36v2), bs36, h, t, "dec-map-v36-noaddr") // decode into non-addressable map value testDeepEqualErr(v36v1, v36v2, t, "equal-map-v36-noaddr") } if v == nil { v36v2 = nil } else { v36v2 = make(map[string]bool, len(v)) } // reset map testUnmarshalErr(&v36v2, bs36, h, t, "dec-map-v36-p-len") testDeepEqualErr(v36v1, v36v2, t, "equal-map-v36-p-len") testReleaseBytes(bs36) bs36 = testMarshalErr(&v36v1, h, t, "enc-map-v36-p") v36v2 = nil testUnmarshalErr(&v36v2, bs36, h, t, "dec-map-v36-p-nil") testDeepEqualErr(v36v1, v36v2, t, "equal-map-v36-p-nil") testReleaseBytes(bs36) // ... if v == nil { v36v2 = nil } else { v36v2 = make(map[string]bool, len(v)) } // reset map var v36v3, v36v4 typMapMapStringBool v36v3 = typMapMapStringBool(v36v1) v36v4 = typMapMapStringBool(v36v2) if v != nil { bs36 = testMarshalErr(v36v3, h, t, "enc-map-v36-custom") testUnmarshalErr(v36v4, bs36, h, t, "dec-map-v36-p-len") testDeepEqualErr(v36v3, v36v4, t, "equal-map-v36-p-len") testReleaseBytes(bs36) } } for _, v := range []map[uint8]interface{}{nil, {}, {111: nil, 77: "string-is-an-interface-2"}} { // fmt.Printf(">>>> running mammoth map v37: %v\n", v) var v37v1, v37v2 map[uint8]interface{} var bs37 []byte v37v1 = v bs37 = testMarshalErr(v37v1, h, t, "enc-map-v37") if v != nil { if v == nil { v37v2 = nil } else { v37v2 = make(map[uint8]interface{}, len(v)) } // reset map testUnmarshalErr(v37v2, bs37, h, t, "dec-map-v37") testDeepEqualErr(v37v1, v37v2, t, "equal-map-v37") if v == nil { v37v2 = nil } else { v37v2 = make(map[uint8]interface{}, len(v)) } // reset map testUnmarshalErr(reflect.ValueOf(v37v2), bs37, h, t, "dec-map-v37-noaddr") // decode into non-addressable map value testDeepEqualErr(v37v1, v37v2, t, "equal-map-v37-noaddr") } if v == nil { v37v2 = nil } else { v37v2 = make(map[uint8]interface{}, len(v)) } // reset map testUnmarshalErr(&v37v2, bs37, h, t, "dec-map-v37-p-len") testDeepEqualErr(v37v1, v37v2, t, "equal-map-v37-p-len") testReleaseBytes(bs37) bs37 = testMarshalErr(&v37v1, h, t, "enc-map-v37-p") v37v2 = nil testUnmarshalErr(&v37v2, bs37, h, t, "dec-map-v37-p-nil") testDeepEqualErr(v37v1, v37v2, t, "equal-map-v37-p-nil") testReleaseBytes(bs37) // ... if v == nil { v37v2 = nil } else { v37v2 = make(map[uint8]interface{}, len(v)) } // reset map var v37v3, v37v4 typMapMapUint8Intf v37v3 = typMapMapUint8Intf(v37v1) v37v4 = typMapMapUint8Intf(v37v2) if v != nil { bs37 = testMarshalErr(v37v3, h, t, "enc-map-v37-custom") testUnmarshalErr(v37v4, bs37, h, t, "dec-map-v37-p-len") testDeepEqualErr(v37v3, v37v4, t, "equal-map-v37-p-len") testReleaseBytes(bs37) } } for _, v := range []map[uint8]string{nil, {}, {127: "", 111: "some-string-2"}} { // fmt.Printf(">>>> running mammoth map v38: %v\n", v) var v38v1, v38v2 map[uint8]string var bs38 []byte v38v1 = v bs38 = testMarshalErr(v38v1, h, t, "enc-map-v38") if v != nil { if v == nil { v38v2 = nil } else { v38v2 = make(map[uint8]string, len(v)) } // reset map testUnmarshalErr(v38v2, bs38, h, t, "dec-map-v38") testDeepEqualErr(v38v1, v38v2, t, "equal-map-v38") if v == nil { v38v2 = nil } else { v38v2 = make(map[uint8]string, len(v)) } // reset map testUnmarshalErr(reflect.ValueOf(v38v2), bs38, h, t, "dec-map-v38-noaddr") // decode into non-addressable map value testDeepEqualErr(v38v1, v38v2, t, "equal-map-v38-noaddr") } if v == nil { v38v2 = nil } else { v38v2 = make(map[uint8]string, len(v)) } // reset map testUnmarshalErr(&v38v2, bs38, h, t, "dec-map-v38-p-len") testDeepEqualErr(v38v1, v38v2, t, "equal-map-v38-p-len") testReleaseBytes(bs38) bs38 = testMarshalErr(&v38v1, h, t, "enc-map-v38-p") v38v2 = nil testUnmarshalErr(&v38v2, bs38, h, t, "dec-map-v38-p-nil") testDeepEqualErr(v38v1, v38v2, t, "equal-map-v38-p-nil") testReleaseBytes(bs38) // ... if v == nil { v38v2 = nil } else { v38v2 = make(map[uint8]string, len(v)) } // reset map var v38v3, v38v4 typMapMapUint8String v38v3 = typMapMapUint8String(v38v1) v38v4 = typMapMapUint8String(v38v2) if v != nil { bs38 = testMarshalErr(v38v3, h, t, "enc-map-v38-custom") testUnmarshalErr(v38v4, bs38, h, t, "dec-map-v38-p-len") testDeepEqualErr(v38v3, v38v4, t, "equal-map-v38-p-len") testReleaseBytes(bs38) } } for _, v := range []map[uint8][]byte{nil, {}, {77: nil, 127: []byte("some-string-2")}} { // fmt.Printf(">>>> running mammoth map v39: %v\n", v) var v39v1, v39v2 map[uint8][]byte var bs39 []byte v39v1 = v bs39 = testMarshalErr(v39v1, h, t, "enc-map-v39") if v != nil { if v == nil { v39v2 = nil } else { v39v2 = make(map[uint8][]byte, len(v)) } // reset map testUnmarshalErr(v39v2, bs39, h, t, "dec-map-v39") testDeepEqualErr(v39v1, v39v2, t, "equal-map-v39") if v == nil { v39v2 = nil } else { v39v2 = make(map[uint8][]byte, len(v)) } // reset map testUnmarshalErr(reflect.ValueOf(v39v2), bs39, h, t, "dec-map-v39-noaddr") // decode into non-addressable map value testDeepEqualErr(v39v1, v39v2, t, "equal-map-v39-noaddr") } if v == nil { v39v2 = nil } else { v39v2 = make(map[uint8][]byte, len(v)) } // reset map testUnmarshalErr(&v39v2, bs39, h, t, "dec-map-v39-p-len") testDeepEqualErr(v39v1, v39v2, t, "equal-map-v39-p-len") testReleaseBytes(bs39) bs39 = testMarshalErr(&v39v1, h, t, "enc-map-v39-p") v39v2 = nil testUnmarshalErr(&v39v2, bs39, h, t, "dec-map-v39-p-nil") testDeepEqualErr(v39v1, v39v2, t, "equal-map-v39-p-nil") testReleaseBytes(bs39) // ... if v == nil { v39v2 = nil } else { v39v2 = make(map[uint8][]byte, len(v)) } // reset map var v39v3, v39v4 typMapMapUint8Bytes v39v3 = typMapMapUint8Bytes(v39v1) v39v4 = typMapMapUint8Bytes(v39v2) if v != nil { bs39 = testMarshalErr(v39v3, h, t, "enc-map-v39-custom") testUnmarshalErr(v39v4, bs39, h, t, "dec-map-v39-p-len") testDeepEqualErr(v39v3, v39v4, t, "equal-map-v39-p-len") testReleaseBytes(bs39) } } for _, v := range []map[uint8]uint8{nil, {}, {111: 0, 77: 127}} { // fmt.Printf(">>>> running mammoth map v40: %v\n", v) var v40v1, v40v2 map[uint8]uint8 var bs40 []byte v40v1 = v bs40 = testMarshalErr(v40v1, h, t, "enc-map-v40") if v != nil { if v == nil { v40v2 = nil } else { v40v2 = make(map[uint8]uint8, len(v)) } // reset map testUnmarshalErr(v40v2, bs40, h, t, "dec-map-v40") testDeepEqualErr(v40v1, v40v2, t, "equal-map-v40") if v == nil { v40v2 = nil } else { v40v2 = make(map[uint8]uint8, len(v)) } // reset map testUnmarshalErr(reflect.ValueOf(v40v2), bs40, h, t, "dec-map-v40-noaddr") // decode into non-addressable map value testDeepEqualErr(v40v1, v40v2, t, "equal-map-v40-noaddr") } if v == nil { v40v2 = nil } else { v40v2 = make(map[uint8]uint8, len(v)) } // reset map testUnmarshalErr(&v40v2, bs40, h, t, "dec-map-v40-p-len") testDeepEqualErr(v40v1, v40v2, t, "equal-map-v40-p-len") testReleaseBytes(bs40) bs40 = testMarshalErr(&v40v1, h, t, "enc-map-v40-p") v40v2 = nil testUnmarshalErr(&v40v2, bs40, h, t, "dec-map-v40-p-nil") testDeepEqualErr(v40v1, v40v2, t, "equal-map-v40-p-nil") testReleaseBytes(bs40) // ... if v == nil { v40v2 = nil } else { v40v2 = make(map[uint8]uint8, len(v)) } // reset map var v40v3, v40v4 typMapMapUint8Uint8 v40v3 = typMapMapUint8Uint8(v40v1) v40v4 = typMapMapUint8Uint8(v40v2) if v != nil { bs40 = testMarshalErr(v40v3, h, t, "enc-map-v40-custom") testUnmarshalErr(v40v4, bs40, h, t, "dec-map-v40-p-len") testDeepEqualErr(v40v3, v40v4, t, "equal-map-v40-p-len") testReleaseBytes(bs40) } } for _, v := range []map[uint8]uint64{nil, {}, {111: 0, 77: 127}} { // fmt.Printf(">>>> running mammoth map v41: %v\n", v) var v41v1, v41v2 map[uint8]uint64 var bs41 []byte v41v1 = v bs41 = testMarshalErr(v41v1, h, t, "enc-map-v41") if v != nil { if v == nil { v41v2 = nil } else { v41v2 = make(map[uint8]uint64, len(v)) } // reset map testUnmarshalErr(v41v2, bs41, h, t, "dec-map-v41") testDeepEqualErr(v41v1, v41v2, t, "equal-map-v41") if v == nil { v41v2 = nil } else { v41v2 = make(map[uint8]uint64, len(v)) } // reset map testUnmarshalErr(reflect.ValueOf(v41v2), bs41, h, t, "dec-map-v41-noaddr") // decode into non-addressable map value testDeepEqualErr(v41v1, v41v2, t, "equal-map-v41-noaddr") } if v == nil { v41v2 = nil } else { v41v2 = make(map[uint8]uint64, len(v)) } // reset map testUnmarshalErr(&v41v2, bs41, h, t, "dec-map-v41-p-len") testDeepEqualErr(v41v1, v41v2, t, "equal-map-v41-p-len") testReleaseBytes(bs41) bs41 = testMarshalErr(&v41v1, h, t, "enc-map-v41-p") v41v2 = nil testUnmarshalErr(&v41v2, bs41, h, t, "dec-map-v41-p-nil") testDeepEqualErr(v41v1, v41v2, t, "equal-map-v41-p-nil") testReleaseBytes(bs41) // ... if v == nil { v41v2 = nil } else { v41v2 = make(map[uint8]uint64, len(v)) } // reset map var v41v3, v41v4 typMapMapUint8Uint64 v41v3 = typMapMapUint8Uint64(v41v1) v41v4 = typMapMapUint8Uint64(v41v2) if v != nil { bs41 = testMarshalErr(v41v3, h, t, "enc-map-v41-custom") testUnmarshalErr(v41v4, bs41, h, t, "dec-map-v41-p-len") testDeepEqualErr(v41v3, v41v4, t, "equal-map-v41-p-len") testReleaseBytes(bs41) } } for _, v := range []map[uint8]int{nil, {}, {111: 0, 77: 127}} { // fmt.Printf(">>>> running mammoth map v42: %v\n", v) var v42v1, v42v2 map[uint8]int var bs42 []byte v42v1 = v bs42 = testMarshalErr(v42v1, h, t, "enc-map-v42") if v != nil { if v == nil { v42v2 = nil } else { v42v2 = make(map[uint8]int, len(v)) } // reset map testUnmarshalErr(v42v2, bs42, h, t, "dec-map-v42") testDeepEqualErr(v42v1, v42v2, t, "equal-map-v42") if v == nil { v42v2 = nil } else { v42v2 = make(map[uint8]int, len(v)) } // reset map testUnmarshalErr(reflect.ValueOf(v42v2), bs42, h, t, "dec-map-v42-noaddr") // decode into non-addressable map value testDeepEqualErr(v42v1, v42v2, t, "equal-map-v42-noaddr") } if v == nil { v42v2 = nil } else { v42v2 = make(map[uint8]int, len(v)) } // reset map testUnmarshalErr(&v42v2, bs42, h, t, "dec-map-v42-p-len") testDeepEqualErr(v42v1, v42v2, t, "equal-map-v42-p-len") testReleaseBytes(bs42) bs42 = testMarshalErr(&v42v1, h, t, "enc-map-v42-p") v42v2 = nil testUnmarshalErr(&v42v2, bs42, h, t, "dec-map-v42-p-nil") testDeepEqualErr(v42v1, v42v2, t, "equal-map-v42-p-nil") testReleaseBytes(bs42) // ... if v == nil { v42v2 = nil } else { v42v2 = make(map[uint8]int, len(v)) } // reset map var v42v3, v42v4 typMapMapUint8Int v42v3 = typMapMapUint8Int(v42v1) v42v4 = typMapMapUint8Int(v42v2) if v != nil { bs42 = testMarshalErr(v42v3, h, t, "enc-map-v42-custom") testUnmarshalErr(v42v4, bs42, h, t, "dec-map-v42-p-len") testDeepEqualErr(v42v3, v42v4, t, "equal-map-v42-p-len") testReleaseBytes(bs42) } } for _, v := range []map[uint8]int32{nil, {}, {111: 0, 77: 127}} { // fmt.Printf(">>>> running mammoth map v43: %v\n", v) var v43v1, v43v2 map[uint8]int32 var bs43 []byte v43v1 = v bs43 = testMarshalErr(v43v1, h, t, "enc-map-v43") if v != nil { if v == nil { v43v2 = nil } else { v43v2 = make(map[uint8]int32, len(v)) } // reset map testUnmarshalErr(v43v2, bs43, h, t, "dec-map-v43") testDeepEqualErr(v43v1, v43v2, t, "equal-map-v43") if v == nil { v43v2 = nil } else { v43v2 = make(map[uint8]int32, len(v)) } // reset map testUnmarshalErr(reflect.ValueOf(v43v2), bs43, h, t, "dec-map-v43-noaddr") // decode into non-addressable map value testDeepEqualErr(v43v1, v43v2, t, "equal-map-v43-noaddr") } if v == nil { v43v2 = nil } else { v43v2 = make(map[uint8]int32, len(v)) } // reset map testUnmarshalErr(&v43v2, bs43, h, t, "dec-map-v43-p-len") testDeepEqualErr(v43v1, v43v2, t, "equal-map-v43-p-len") testReleaseBytes(bs43) bs43 = testMarshalErr(&v43v1, h, t, "enc-map-v43-p") v43v2 = nil testUnmarshalErr(&v43v2, bs43, h, t, "dec-map-v43-p-nil") testDeepEqualErr(v43v1, v43v2, t, "equal-map-v43-p-nil") testReleaseBytes(bs43) // ... if v == nil { v43v2 = nil } else { v43v2 = make(map[uint8]int32, len(v)) } // reset map var v43v3, v43v4 typMapMapUint8Int32 v43v3 = typMapMapUint8Int32(v43v1) v43v4 = typMapMapUint8Int32(v43v2) if v != nil { bs43 = testMarshalErr(v43v3, h, t, "enc-map-v43-custom") testUnmarshalErr(v43v4, bs43, h, t, "dec-map-v43-p-len") testDeepEqualErr(v43v3, v43v4, t, "equal-map-v43-p-len") testReleaseBytes(bs43) } } for _, v := range []map[uint8]float64{nil, {}, {111: 0, 77: 11.1}} { // fmt.Printf(">>>> running mammoth map v44: %v\n", v) var v44v1, v44v2 map[uint8]float64 var bs44 []byte v44v1 = v bs44 = testMarshalErr(v44v1, h, t, "enc-map-v44") if v != nil { if v == nil { v44v2 = nil } else { v44v2 = make(map[uint8]float64, len(v)) } // reset map testUnmarshalErr(v44v2, bs44, h, t, "dec-map-v44") testDeepEqualErr(v44v1, v44v2, t, "equal-map-v44") if v == nil { v44v2 = nil } else { v44v2 = make(map[uint8]float64, len(v)) } // reset map testUnmarshalErr(reflect.ValueOf(v44v2), bs44, h, t, "dec-map-v44-noaddr") // decode into non-addressable map value testDeepEqualErr(v44v1, v44v2, t, "equal-map-v44-noaddr") } if v == nil { v44v2 = nil } else { v44v2 = make(map[uint8]float64, len(v)) } // reset map testUnmarshalErr(&v44v2, bs44, h, t, "dec-map-v44-p-len") testDeepEqualErr(v44v1, v44v2, t, "equal-map-v44-p-len") testReleaseBytes(bs44) bs44 = testMarshalErr(&v44v1, h, t, "enc-map-v44-p") v44v2 = nil testUnmarshalErr(&v44v2, bs44, h, t, "dec-map-v44-p-nil") testDeepEqualErr(v44v1, v44v2, t, "equal-map-v44-p-nil") testReleaseBytes(bs44) // ... if v == nil { v44v2 = nil } else { v44v2 = make(map[uint8]float64, len(v)) } // reset map var v44v3, v44v4 typMapMapUint8Float64 v44v3 = typMapMapUint8Float64(v44v1) v44v4 = typMapMapUint8Float64(v44v2) if v != nil { bs44 = testMarshalErr(v44v3, h, t, "enc-map-v44-custom") testUnmarshalErr(v44v4, bs44, h, t, "dec-map-v44-p-len") testDeepEqualErr(v44v3, v44v4, t, "equal-map-v44-p-len") testReleaseBytes(bs44) } } for _, v := range []map[uint8]bool{nil, {}, {127: false, 111: false}} { // fmt.Printf(">>>> running mammoth map v45: %v\n", v) var v45v1, v45v2 map[uint8]bool var bs45 []byte v45v1 = v bs45 = testMarshalErr(v45v1, h, t, "enc-map-v45") if v != nil { if v == nil { v45v2 = nil } else { v45v2 = make(map[uint8]bool, len(v)) } // reset map testUnmarshalErr(v45v2, bs45, h, t, "dec-map-v45") testDeepEqualErr(v45v1, v45v2, t, "equal-map-v45") if v == nil { v45v2 = nil } else { v45v2 = make(map[uint8]bool, len(v)) } // reset map testUnmarshalErr(reflect.ValueOf(v45v2), bs45, h, t, "dec-map-v45-noaddr") // decode into non-addressable map value testDeepEqualErr(v45v1, v45v2, t, "equal-map-v45-noaddr") } if v == nil { v45v2 = nil } else { v45v2 = make(map[uint8]bool, len(v)) } // reset map testUnmarshalErr(&v45v2, bs45, h, t, "dec-map-v45-p-len") testDeepEqualErr(v45v1, v45v2, t, "equal-map-v45-p-len") testReleaseBytes(bs45) bs45 = testMarshalErr(&v45v1, h, t, "enc-map-v45-p") v45v2 = nil testUnmarshalErr(&v45v2, bs45, h, t, "dec-map-v45-p-nil") testDeepEqualErr(v45v1, v45v2, t, "equal-map-v45-p-nil") testReleaseBytes(bs45) // ... if v == nil { v45v2 = nil } else { v45v2 = make(map[uint8]bool, len(v)) } // reset map var v45v3, v45v4 typMapMapUint8Bool v45v3 = typMapMapUint8Bool(v45v1) v45v4 = typMapMapUint8Bool(v45v2) if v != nil { bs45 = testMarshalErr(v45v3, h, t, "enc-map-v45-custom") testUnmarshalErr(v45v4, bs45, h, t, "dec-map-v45-p-len") testDeepEqualErr(v45v3, v45v4, t, "equal-map-v45-p-len") testReleaseBytes(bs45) } } for _, v := range []map[uint64]interface{}{nil, {}, {77: nil, 127: "string-is-an-interface-3"}} { // fmt.Printf(">>>> running mammoth map v46: %v\n", v) var v46v1, v46v2 map[uint64]interface{} var bs46 []byte v46v1 = v bs46 = testMarshalErr(v46v1, h, t, "enc-map-v46") if v != nil { if v == nil { v46v2 = nil } else { v46v2 = make(map[uint64]interface{}, len(v)) } // reset map testUnmarshalErr(v46v2, bs46, h, t, "dec-map-v46") testDeepEqualErr(v46v1, v46v2, t, "equal-map-v46") if v == nil { v46v2 = nil } else { v46v2 = make(map[uint64]interface{}, len(v)) } // reset map testUnmarshalErr(reflect.ValueOf(v46v2), bs46, h, t, "dec-map-v46-noaddr") // decode into non-addressable map value testDeepEqualErr(v46v1, v46v2, t, "equal-map-v46-noaddr") } if v == nil { v46v2 = nil } else { v46v2 = make(map[uint64]interface{}, len(v)) } // reset map testUnmarshalErr(&v46v2, bs46, h, t, "dec-map-v46-p-len") testDeepEqualErr(v46v1, v46v2, t, "equal-map-v46-p-len") testReleaseBytes(bs46) bs46 = testMarshalErr(&v46v1, h, t, "enc-map-v46-p") v46v2 = nil testUnmarshalErr(&v46v2, bs46, h, t, "dec-map-v46-p-nil") testDeepEqualErr(v46v1, v46v2, t, "equal-map-v46-p-nil") testReleaseBytes(bs46) // ... if v == nil { v46v2 = nil } else { v46v2 = make(map[uint64]interface{}, len(v)) } // reset map var v46v3, v46v4 typMapMapUint64Intf v46v3 = typMapMapUint64Intf(v46v1) v46v4 = typMapMapUint64Intf(v46v2) if v != nil { bs46 = testMarshalErr(v46v3, h, t, "enc-map-v46-custom") testUnmarshalErr(v46v4, bs46, h, t, "dec-map-v46-p-len") testDeepEqualErr(v46v3, v46v4, t, "equal-map-v46-p-len") testReleaseBytes(bs46) } } for _, v := range []map[uint64]string{nil, {}, {111: "", 77: "some-string-3"}} { // fmt.Printf(">>>> running mammoth map v47: %v\n", v) var v47v1, v47v2 map[uint64]string var bs47 []byte v47v1 = v bs47 = testMarshalErr(v47v1, h, t, "enc-map-v47") if v != nil { if v == nil { v47v2 = nil } else { v47v2 = make(map[uint64]string, len(v)) } // reset map testUnmarshalErr(v47v2, bs47, h, t, "dec-map-v47") testDeepEqualErr(v47v1, v47v2, t, "equal-map-v47") if v == nil { v47v2 = nil } else { v47v2 = make(map[uint64]string, len(v)) } // reset map testUnmarshalErr(reflect.ValueOf(v47v2), bs47, h, t, "dec-map-v47-noaddr") // decode into non-addressable map value testDeepEqualErr(v47v1, v47v2, t, "equal-map-v47-noaddr") } if v == nil { v47v2 = nil } else { v47v2 = make(map[uint64]string, len(v)) } // reset map testUnmarshalErr(&v47v2, bs47, h, t, "dec-map-v47-p-len") testDeepEqualErr(v47v1, v47v2, t, "equal-map-v47-p-len") testReleaseBytes(bs47) bs47 = testMarshalErr(&v47v1, h, t, "enc-map-v47-p") v47v2 = nil testUnmarshalErr(&v47v2, bs47, h, t, "dec-map-v47-p-nil") testDeepEqualErr(v47v1, v47v2, t, "equal-map-v47-p-nil") testReleaseBytes(bs47) // ... if v == nil { v47v2 = nil } else { v47v2 = make(map[uint64]string, len(v)) } // reset map var v47v3, v47v4 typMapMapUint64String v47v3 = typMapMapUint64String(v47v1) v47v4 = typMapMapUint64String(v47v2) if v != nil { bs47 = testMarshalErr(v47v3, h, t, "enc-map-v47-custom") testUnmarshalErr(v47v4, bs47, h, t, "dec-map-v47-p-len") testDeepEqualErr(v47v3, v47v4, t, "equal-map-v47-p-len") testReleaseBytes(bs47) } } for _, v := range []map[uint64][]byte{nil, {}, {127: nil, 111: []byte("some-string-3")}} { // fmt.Printf(">>>> running mammoth map v48: %v\n", v) var v48v1, v48v2 map[uint64][]byte var bs48 []byte v48v1 = v bs48 = testMarshalErr(v48v1, h, t, "enc-map-v48") if v != nil { if v == nil { v48v2 = nil } else { v48v2 = make(map[uint64][]byte, len(v)) } // reset map testUnmarshalErr(v48v2, bs48, h, t, "dec-map-v48") testDeepEqualErr(v48v1, v48v2, t, "equal-map-v48") if v == nil { v48v2 = nil } else { v48v2 = make(map[uint64][]byte, len(v)) } // reset map testUnmarshalErr(reflect.ValueOf(v48v2), bs48, h, t, "dec-map-v48-noaddr") // decode into non-addressable map value testDeepEqualErr(v48v1, v48v2, t, "equal-map-v48-noaddr") } if v == nil { v48v2 = nil } else { v48v2 = make(map[uint64][]byte, len(v)) } // reset map testUnmarshalErr(&v48v2, bs48, h, t, "dec-map-v48-p-len") testDeepEqualErr(v48v1, v48v2, t, "equal-map-v48-p-len") testReleaseBytes(bs48) bs48 = testMarshalErr(&v48v1, h, t, "enc-map-v48-p") v48v2 = nil testUnmarshalErr(&v48v2, bs48, h, t, "dec-map-v48-p-nil") testDeepEqualErr(v48v1, v48v2, t, "equal-map-v48-p-nil") testReleaseBytes(bs48) // ... if v == nil { v48v2 = nil } else { v48v2 = make(map[uint64][]byte, len(v)) } // reset map var v48v3, v48v4 typMapMapUint64Bytes v48v3 = typMapMapUint64Bytes(v48v1) v48v4 = typMapMapUint64Bytes(v48v2) if v != nil { bs48 = testMarshalErr(v48v3, h, t, "enc-map-v48-custom") testUnmarshalErr(v48v4, bs48, h, t, "dec-map-v48-p-len") testDeepEqualErr(v48v3, v48v4, t, "equal-map-v48-p-len") testReleaseBytes(bs48) } } for _, v := range []map[uint64]uint8{nil, {}, {77: 0, 127: 111}} { // fmt.Printf(">>>> running mammoth map v49: %v\n", v) var v49v1, v49v2 map[uint64]uint8 var bs49 []byte v49v1 = v bs49 = testMarshalErr(v49v1, h, t, "enc-map-v49") if v != nil { if v == nil { v49v2 = nil } else { v49v2 = make(map[uint64]uint8, len(v)) } // reset map testUnmarshalErr(v49v2, bs49, h, t, "dec-map-v49") testDeepEqualErr(v49v1, v49v2, t, "equal-map-v49") if v == nil { v49v2 = nil } else { v49v2 = make(map[uint64]uint8, len(v)) } // reset map testUnmarshalErr(reflect.ValueOf(v49v2), bs49, h, t, "dec-map-v49-noaddr") // decode into non-addressable map value testDeepEqualErr(v49v1, v49v2, t, "equal-map-v49-noaddr") } if v == nil { v49v2 = nil } else { v49v2 = make(map[uint64]uint8, len(v)) } // reset map testUnmarshalErr(&v49v2, bs49, h, t, "dec-map-v49-p-len") testDeepEqualErr(v49v1, v49v2, t, "equal-map-v49-p-len") testReleaseBytes(bs49) bs49 = testMarshalErr(&v49v1, h, t, "enc-map-v49-p") v49v2 = nil testUnmarshalErr(&v49v2, bs49, h, t, "dec-map-v49-p-nil") testDeepEqualErr(v49v1, v49v2, t, "equal-map-v49-p-nil") testReleaseBytes(bs49) // ... if v == nil { v49v2 = nil } else { v49v2 = make(map[uint64]uint8, len(v)) } // reset map var v49v3, v49v4 typMapMapUint64Uint8 v49v3 = typMapMapUint64Uint8(v49v1) v49v4 = typMapMapUint64Uint8(v49v2) if v != nil { bs49 = testMarshalErr(v49v3, h, t, "enc-map-v49-custom") testUnmarshalErr(v49v4, bs49, h, t, "dec-map-v49-p-len") testDeepEqualErr(v49v3, v49v4, t, "equal-map-v49-p-len") testReleaseBytes(bs49) } } for _, v := range []map[uint64]uint64{nil, {}, {77: 0, 127: 111}} { // fmt.Printf(">>>> running mammoth map v50: %v\n", v) var v50v1, v50v2 map[uint64]uint64 var bs50 []byte v50v1 = v bs50 = testMarshalErr(v50v1, h, t, "enc-map-v50") if v != nil { if v == nil { v50v2 = nil } else { v50v2 = make(map[uint64]uint64, len(v)) } // reset map testUnmarshalErr(v50v2, bs50, h, t, "dec-map-v50") testDeepEqualErr(v50v1, v50v2, t, "equal-map-v50") if v == nil { v50v2 = nil } else { v50v2 = make(map[uint64]uint64, len(v)) } // reset map testUnmarshalErr(reflect.ValueOf(v50v2), bs50, h, t, "dec-map-v50-noaddr") // decode into non-addressable map value testDeepEqualErr(v50v1, v50v2, t, "equal-map-v50-noaddr") } if v == nil { v50v2 = nil } else { v50v2 = make(map[uint64]uint64, len(v)) } // reset map testUnmarshalErr(&v50v2, bs50, h, t, "dec-map-v50-p-len") testDeepEqualErr(v50v1, v50v2, t, "equal-map-v50-p-len") testReleaseBytes(bs50) bs50 = testMarshalErr(&v50v1, h, t, "enc-map-v50-p") v50v2 = nil testUnmarshalErr(&v50v2, bs50, h, t, "dec-map-v50-p-nil") testDeepEqualErr(v50v1, v50v2, t, "equal-map-v50-p-nil") testReleaseBytes(bs50) // ... if v == nil { v50v2 = nil } else { v50v2 = make(map[uint64]uint64, len(v)) } // reset map var v50v3, v50v4 typMapMapUint64Uint64 v50v3 = typMapMapUint64Uint64(v50v1) v50v4 = typMapMapUint64Uint64(v50v2) if v != nil { bs50 = testMarshalErr(v50v3, h, t, "enc-map-v50-custom") testUnmarshalErr(v50v4, bs50, h, t, "dec-map-v50-p-len") testDeepEqualErr(v50v3, v50v4, t, "equal-map-v50-p-len") testReleaseBytes(bs50) } } for _, v := range []map[uint64]int{nil, {}, {77: 0, 127: 111}} { // fmt.Printf(">>>> running mammoth map v51: %v\n", v) var v51v1, v51v2 map[uint64]int var bs51 []byte v51v1 = v bs51 = testMarshalErr(v51v1, h, t, "enc-map-v51") if v != nil { if v == nil { v51v2 = nil } else { v51v2 = make(map[uint64]int, len(v)) } // reset map testUnmarshalErr(v51v2, bs51, h, t, "dec-map-v51") testDeepEqualErr(v51v1, v51v2, t, "equal-map-v51") if v == nil { v51v2 = nil } else { v51v2 = make(map[uint64]int, len(v)) } // reset map testUnmarshalErr(reflect.ValueOf(v51v2), bs51, h, t, "dec-map-v51-noaddr") // decode into non-addressable map value testDeepEqualErr(v51v1, v51v2, t, "equal-map-v51-noaddr") } if v == nil { v51v2 = nil } else { v51v2 = make(map[uint64]int, len(v)) } // reset map testUnmarshalErr(&v51v2, bs51, h, t, "dec-map-v51-p-len") testDeepEqualErr(v51v1, v51v2, t, "equal-map-v51-p-len") testReleaseBytes(bs51) bs51 = testMarshalErr(&v51v1, h, t, "enc-map-v51-p") v51v2 = nil testUnmarshalErr(&v51v2, bs51, h, t, "dec-map-v51-p-nil") testDeepEqualErr(v51v1, v51v2, t, "equal-map-v51-p-nil") testReleaseBytes(bs51) // ... if v == nil { v51v2 = nil } else { v51v2 = make(map[uint64]int, len(v)) } // reset map var v51v3, v51v4 typMapMapUint64Int v51v3 = typMapMapUint64Int(v51v1) v51v4 = typMapMapUint64Int(v51v2) if v != nil { bs51 = testMarshalErr(v51v3, h, t, "enc-map-v51-custom") testUnmarshalErr(v51v4, bs51, h, t, "dec-map-v51-p-len") testDeepEqualErr(v51v3, v51v4, t, "equal-map-v51-p-len") testReleaseBytes(bs51) } } for _, v := range []map[uint64]int32{nil, {}, {77: 0, 127: 111}} { // fmt.Printf(">>>> running mammoth map v52: %v\n", v) var v52v1, v52v2 map[uint64]int32 var bs52 []byte v52v1 = v bs52 = testMarshalErr(v52v1, h, t, "enc-map-v52") if v != nil { if v == nil { v52v2 = nil } else { v52v2 = make(map[uint64]int32, len(v)) } // reset map testUnmarshalErr(v52v2, bs52, h, t, "dec-map-v52") testDeepEqualErr(v52v1, v52v2, t, "equal-map-v52") if v == nil { v52v2 = nil } else { v52v2 = make(map[uint64]int32, len(v)) } // reset map testUnmarshalErr(reflect.ValueOf(v52v2), bs52, h, t, "dec-map-v52-noaddr") // decode into non-addressable map value testDeepEqualErr(v52v1, v52v2, t, "equal-map-v52-noaddr") } if v == nil { v52v2 = nil } else { v52v2 = make(map[uint64]int32, len(v)) } // reset map testUnmarshalErr(&v52v2, bs52, h, t, "dec-map-v52-p-len") testDeepEqualErr(v52v1, v52v2, t, "equal-map-v52-p-len") testReleaseBytes(bs52) bs52 = testMarshalErr(&v52v1, h, t, "enc-map-v52-p") v52v2 = nil testUnmarshalErr(&v52v2, bs52, h, t, "dec-map-v52-p-nil") testDeepEqualErr(v52v1, v52v2, t, "equal-map-v52-p-nil") testReleaseBytes(bs52) // ... if v == nil { v52v2 = nil } else { v52v2 = make(map[uint64]int32, len(v)) } // reset map var v52v3, v52v4 typMapMapUint64Int32 v52v3 = typMapMapUint64Int32(v52v1) v52v4 = typMapMapUint64Int32(v52v2) if v != nil { bs52 = testMarshalErr(v52v3, h, t, "enc-map-v52-custom") testUnmarshalErr(v52v4, bs52, h, t, "dec-map-v52-p-len") testDeepEqualErr(v52v3, v52v4, t, "equal-map-v52-p-len") testReleaseBytes(bs52) } } for _, v := range []map[uint64]float64{nil, {}, {77: 0, 127: 22.2}} { // fmt.Printf(">>>> running mammoth map v53: %v\n", v) var v53v1, v53v2 map[uint64]float64 var bs53 []byte v53v1 = v bs53 = testMarshalErr(v53v1, h, t, "enc-map-v53") if v != nil { if v == nil { v53v2 = nil } else { v53v2 = make(map[uint64]float64, len(v)) } // reset map testUnmarshalErr(v53v2, bs53, h, t, "dec-map-v53") testDeepEqualErr(v53v1, v53v2, t, "equal-map-v53") if v == nil { v53v2 = nil } else { v53v2 = make(map[uint64]float64, len(v)) } // reset map testUnmarshalErr(reflect.ValueOf(v53v2), bs53, h, t, "dec-map-v53-noaddr") // decode into non-addressable map value testDeepEqualErr(v53v1, v53v2, t, "equal-map-v53-noaddr") } if v == nil { v53v2 = nil } else { v53v2 = make(map[uint64]float64, len(v)) } // reset map testUnmarshalErr(&v53v2, bs53, h, t, "dec-map-v53-p-len") testDeepEqualErr(v53v1, v53v2, t, "equal-map-v53-p-len") testReleaseBytes(bs53) bs53 = testMarshalErr(&v53v1, h, t, "enc-map-v53-p") v53v2 = nil testUnmarshalErr(&v53v2, bs53, h, t, "dec-map-v53-p-nil") testDeepEqualErr(v53v1, v53v2, t, "equal-map-v53-p-nil") testReleaseBytes(bs53) // ... if v == nil { v53v2 = nil } else { v53v2 = make(map[uint64]float64, len(v)) } // reset map var v53v3, v53v4 typMapMapUint64Float64 v53v3 = typMapMapUint64Float64(v53v1) v53v4 = typMapMapUint64Float64(v53v2) if v != nil { bs53 = testMarshalErr(v53v3, h, t, "enc-map-v53-custom") testUnmarshalErr(v53v4, bs53, h, t, "dec-map-v53-p-len") testDeepEqualErr(v53v3, v53v4, t, "equal-map-v53-p-len") testReleaseBytes(bs53) } } for _, v := range []map[uint64]bool{nil, {}, {111: false, 77: true}} { // fmt.Printf(">>>> running mammoth map v54: %v\n", v) var v54v1, v54v2 map[uint64]bool var bs54 []byte v54v1 = v bs54 = testMarshalErr(v54v1, h, t, "enc-map-v54") if v != nil { if v == nil { v54v2 = nil } else { v54v2 = make(map[uint64]bool, len(v)) } // reset map testUnmarshalErr(v54v2, bs54, h, t, "dec-map-v54") testDeepEqualErr(v54v1, v54v2, t, "equal-map-v54") if v == nil { v54v2 = nil } else { v54v2 = make(map[uint64]bool, len(v)) } // reset map testUnmarshalErr(reflect.ValueOf(v54v2), bs54, h, t, "dec-map-v54-noaddr") // decode into non-addressable map value testDeepEqualErr(v54v1, v54v2, t, "equal-map-v54-noaddr") } if v == nil { v54v2 = nil } else { v54v2 = make(map[uint64]bool, len(v)) } // reset map testUnmarshalErr(&v54v2, bs54, h, t, "dec-map-v54-p-len") testDeepEqualErr(v54v1, v54v2, t, "equal-map-v54-p-len") testReleaseBytes(bs54) bs54 = testMarshalErr(&v54v1, h, t, "enc-map-v54-p") v54v2 = nil testUnmarshalErr(&v54v2, bs54, h, t, "dec-map-v54-p-nil") testDeepEqualErr(v54v1, v54v2, t, "equal-map-v54-p-nil") testReleaseBytes(bs54) // ... if v == nil { v54v2 = nil } else { v54v2 = make(map[uint64]bool, len(v)) } // reset map var v54v3, v54v4 typMapMapUint64Bool v54v3 = typMapMapUint64Bool(v54v1) v54v4 = typMapMapUint64Bool(v54v2) if v != nil { bs54 = testMarshalErr(v54v3, h, t, "enc-map-v54-custom") testUnmarshalErr(v54v4, bs54, h, t, "dec-map-v54-p-len") testDeepEqualErr(v54v3, v54v4, t, "equal-map-v54-p-len") testReleaseBytes(bs54) } } for _, v := range []map[int]interface{}{nil, {}, {127: nil, 111: "string-is-an-interface-1"}} { // fmt.Printf(">>>> running mammoth map v55: %v\n", v) var v55v1, v55v2 map[int]interface{} var bs55 []byte v55v1 = v bs55 = testMarshalErr(v55v1, h, t, "enc-map-v55") if v != nil { if v == nil { v55v2 = nil } else { v55v2 = make(map[int]interface{}, len(v)) } // reset map testUnmarshalErr(v55v2, bs55, h, t, "dec-map-v55") testDeepEqualErr(v55v1, v55v2, t, "equal-map-v55") if v == nil { v55v2 = nil } else { v55v2 = make(map[int]interface{}, len(v)) } // reset map testUnmarshalErr(reflect.ValueOf(v55v2), bs55, h, t, "dec-map-v55-noaddr") // decode into non-addressable map value testDeepEqualErr(v55v1, v55v2, t, "equal-map-v55-noaddr") } if v == nil { v55v2 = nil } else { v55v2 = make(map[int]interface{}, len(v)) } // reset map testUnmarshalErr(&v55v2, bs55, h, t, "dec-map-v55-p-len") testDeepEqualErr(v55v1, v55v2, t, "equal-map-v55-p-len") testReleaseBytes(bs55) bs55 = testMarshalErr(&v55v1, h, t, "enc-map-v55-p") v55v2 = nil testUnmarshalErr(&v55v2, bs55, h, t, "dec-map-v55-p-nil") testDeepEqualErr(v55v1, v55v2, t, "equal-map-v55-p-nil") testReleaseBytes(bs55) // ... if v == nil { v55v2 = nil } else { v55v2 = make(map[int]interface{}, len(v)) } // reset map var v55v3, v55v4 typMapMapIntIntf v55v3 = typMapMapIntIntf(v55v1) v55v4 = typMapMapIntIntf(v55v2) if v != nil { bs55 = testMarshalErr(v55v3, h, t, "enc-map-v55-custom") testUnmarshalErr(v55v4, bs55, h, t, "dec-map-v55-p-len") testDeepEqualErr(v55v3, v55v4, t, "equal-map-v55-p-len") testReleaseBytes(bs55) } } for _, v := range []map[int]string{nil, {}, {77: "", 127: "some-string-1"}} { // fmt.Printf(">>>> running mammoth map v56: %v\n", v) var v56v1, v56v2 map[int]string var bs56 []byte v56v1 = v bs56 = testMarshalErr(v56v1, h, t, "enc-map-v56") if v != nil { if v == nil { v56v2 = nil } else { v56v2 = make(map[int]string, len(v)) } // reset map testUnmarshalErr(v56v2, bs56, h, t, "dec-map-v56") testDeepEqualErr(v56v1, v56v2, t, "equal-map-v56") if v == nil { v56v2 = nil } else { v56v2 = make(map[int]string, len(v)) } // reset map testUnmarshalErr(reflect.ValueOf(v56v2), bs56, h, t, "dec-map-v56-noaddr") // decode into non-addressable map value testDeepEqualErr(v56v1, v56v2, t, "equal-map-v56-noaddr") } if v == nil { v56v2 = nil } else { v56v2 = make(map[int]string, len(v)) } // reset map testUnmarshalErr(&v56v2, bs56, h, t, "dec-map-v56-p-len") testDeepEqualErr(v56v1, v56v2, t, "equal-map-v56-p-len") testReleaseBytes(bs56) bs56 = testMarshalErr(&v56v1, h, t, "enc-map-v56-p") v56v2 = nil testUnmarshalErr(&v56v2, bs56, h, t, "dec-map-v56-p-nil") testDeepEqualErr(v56v1, v56v2, t, "equal-map-v56-p-nil") testReleaseBytes(bs56) // ... if v == nil { v56v2 = nil } else { v56v2 = make(map[int]string, len(v)) } // reset map var v56v3, v56v4 typMapMapIntString v56v3 = typMapMapIntString(v56v1) v56v4 = typMapMapIntString(v56v2) if v != nil { bs56 = testMarshalErr(v56v3, h, t, "enc-map-v56-custom") testUnmarshalErr(v56v4, bs56, h, t, "dec-map-v56-p-len") testDeepEqualErr(v56v3, v56v4, t, "equal-map-v56-p-len") testReleaseBytes(bs56) } } for _, v := range []map[int][]byte{nil, {}, {111: nil, 77: []byte("some-string-1")}} { // fmt.Printf(">>>> running mammoth map v57: %v\n", v) var v57v1, v57v2 map[int][]byte var bs57 []byte v57v1 = v bs57 = testMarshalErr(v57v1, h, t, "enc-map-v57") if v != nil { if v == nil { v57v2 = nil } else { v57v2 = make(map[int][]byte, len(v)) } // reset map testUnmarshalErr(v57v2, bs57, h, t, "dec-map-v57") testDeepEqualErr(v57v1, v57v2, t, "equal-map-v57") if v == nil { v57v2 = nil } else { v57v2 = make(map[int][]byte, len(v)) } // reset map testUnmarshalErr(reflect.ValueOf(v57v2), bs57, h, t, "dec-map-v57-noaddr") // decode into non-addressable map value testDeepEqualErr(v57v1, v57v2, t, "equal-map-v57-noaddr") } if v == nil { v57v2 = nil } else { v57v2 = make(map[int][]byte, len(v)) } // reset map testUnmarshalErr(&v57v2, bs57, h, t, "dec-map-v57-p-len") testDeepEqualErr(v57v1, v57v2, t, "equal-map-v57-p-len") testReleaseBytes(bs57) bs57 = testMarshalErr(&v57v1, h, t, "enc-map-v57-p") v57v2 = nil testUnmarshalErr(&v57v2, bs57, h, t, "dec-map-v57-p-nil") testDeepEqualErr(v57v1, v57v2, t, "equal-map-v57-p-nil") testReleaseBytes(bs57) // ... if v == nil { v57v2 = nil } else { v57v2 = make(map[int][]byte, len(v)) } // reset map var v57v3, v57v4 typMapMapIntBytes v57v3 = typMapMapIntBytes(v57v1) v57v4 = typMapMapIntBytes(v57v2) if v != nil { bs57 = testMarshalErr(v57v3, h, t, "enc-map-v57-custom") testUnmarshalErr(v57v4, bs57, h, t, "dec-map-v57-p-len") testDeepEqualErr(v57v3, v57v4, t, "equal-map-v57-p-len") testReleaseBytes(bs57) } } for _, v := range []map[int]uint8{nil, {}, {127: 0, 111: 77}} { // fmt.Printf(">>>> running mammoth map v58: %v\n", v) var v58v1, v58v2 map[int]uint8 var bs58 []byte v58v1 = v bs58 = testMarshalErr(v58v1, h, t, "enc-map-v58") if v != nil { if v == nil { v58v2 = nil } else { v58v2 = make(map[int]uint8, len(v)) } // reset map testUnmarshalErr(v58v2, bs58, h, t, "dec-map-v58") testDeepEqualErr(v58v1, v58v2, t, "equal-map-v58") if v == nil { v58v2 = nil } else { v58v2 = make(map[int]uint8, len(v)) } // reset map testUnmarshalErr(reflect.ValueOf(v58v2), bs58, h, t, "dec-map-v58-noaddr") // decode into non-addressable map value testDeepEqualErr(v58v1, v58v2, t, "equal-map-v58-noaddr") } if v == nil { v58v2 = nil } else { v58v2 = make(map[int]uint8, len(v)) } // reset map testUnmarshalErr(&v58v2, bs58, h, t, "dec-map-v58-p-len") testDeepEqualErr(v58v1, v58v2, t, "equal-map-v58-p-len") testReleaseBytes(bs58) bs58 = testMarshalErr(&v58v1, h, t, "enc-map-v58-p") v58v2 = nil testUnmarshalErr(&v58v2, bs58, h, t, "dec-map-v58-p-nil") testDeepEqualErr(v58v1, v58v2, t, "equal-map-v58-p-nil") testReleaseBytes(bs58) // ... if v == nil { v58v2 = nil } else { v58v2 = make(map[int]uint8, len(v)) } // reset map var v58v3, v58v4 typMapMapIntUint8 v58v3 = typMapMapIntUint8(v58v1) v58v4 = typMapMapIntUint8(v58v2) if v != nil { bs58 = testMarshalErr(v58v3, h, t, "enc-map-v58-custom") testUnmarshalErr(v58v4, bs58, h, t, "dec-map-v58-p-len") testDeepEqualErr(v58v3, v58v4, t, "equal-map-v58-p-len") testReleaseBytes(bs58) } } for _, v := range []map[int]uint64{nil, {}, {127: 0, 111: 77}} { // fmt.Printf(">>>> running mammoth map v59: %v\n", v) var v59v1, v59v2 map[int]uint64 var bs59 []byte v59v1 = v bs59 = testMarshalErr(v59v1, h, t, "enc-map-v59") if v != nil { if v == nil { v59v2 = nil } else { v59v2 = make(map[int]uint64, len(v)) } // reset map testUnmarshalErr(v59v2, bs59, h, t, "dec-map-v59") testDeepEqualErr(v59v1, v59v2, t, "equal-map-v59") if v == nil { v59v2 = nil } else { v59v2 = make(map[int]uint64, len(v)) } // reset map testUnmarshalErr(reflect.ValueOf(v59v2), bs59, h, t, "dec-map-v59-noaddr") // decode into non-addressable map value testDeepEqualErr(v59v1, v59v2, t, "equal-map-v59-noaddr") } if v == nil { v59v2 = nil } else { v59v2 = make(map[int]uint64, len(v)) } // reset map testUnmarshalErr(&v59v2, bs59, h, t, "dec-map-v59-p-len") testDeepEqualErr(v59v1, v59v2, t, "equal-map-v59-p-len") testReleaseBytes(bs59) bs59 = testMarshalErr(&v59v1, h, t, "enc-map-v59-p") v59v2 = nil testUnmarshalErr(&v59v2, bs59, h, t, "dec-map-v59-p-nil") testDeepEqualErr(v59v1, v59v2, t, "equal-map-v59-p-nil") testReleaseBytes(bs59) // ... if v == nil { v59v2 = nil } else { v59v2 = make(map[int]uint64, len(v)) } // reset map var v59v3, v59v4 typMapMapIntUint64 v59v3 = typMapMapIntUint64(v59v1) v59v4 = typMapMapIntUint64(v59v2) if v != nil { bs59 = testMarshalErr(v59v3, h, t, "enc-map-v59-custom") testUnmarshalErr(v59v4, bs59, h, t, "dec-map-v59-p-len") testDeepEqualErr(v59v3, v59v4, t, "equal-map-v59-p-len") testReleaseBytes(bs59) } } for _, v := range []map[int]int{nil, {}, {127: 0, 111: 77}} { // fmt.Printf(">>>> running mammoth map v60: %v\n", v) var v60v1, v60v2 map[int]int var bs60 []byte v60v1 = v bs60 = testMarshalErr(v60v1, h, t, "enc-map-v60") if v != nil { if v == nil { v60v2 = nil } else { v60v2 = make(map[int]int, len(v)) } // reset map testUnmarshalErr(v60v2, bs60, h, t, "dec-map-v60") testDeepEqualErr(v60v1, v60v2, t, "equal-map-v60") if v == nil { v60v2 = nil } else { v60v2 = make(map[int]int, len(v)) } // reset map testUnmarshalErr(reflect.ValueOf(v60v2), bs60, h, t, "dec-map-v60-noaddr") // decode into non-addressable map value testDeepEqualErr(v60v1, v60v2, t, "equal-map-v60-noaddr") } if v == nil { v60v2 = nil } else { v60v2 = make(map[int]int, len(v)) } // reset map testUnmarshalErr(&v60v2, bs60, h, t, "dec-map-v60-p-len") testDeepEqualErr(v60v1, v60v2, t, "equal-map-v60-p-len") testReleaseBytes(bs60) bs60 = testMarshalErr(&v60v1, h, t, "enc-map-v60-p") v60v2 = nil testUnmarshalErr(&v60v2, bs60, h, t, "dec-map-v60-p-nil") testDeepEqualErr(v60v1, v60v2, t, "equal-map-v60-p-nil") testReleaseBytes(bs60) // ... if v == nil { v60v2 = nil } else { v60v2 = make(map[int]int, len(v)) } // reset map var v60v3, v60v4 typMapMapIntInt v60v3 = typMapMapIntInt(v60v1) v60v4 = typMapMapIntInt(v60v2) if v != nil { bs60 = testMarshalErr(v60v3, h, t, "enc-map-v60-custom") testUnmarshalErr(v60v4, bs60, h, t, "dec-map-v60-p-len") testDeepEqualErr(v60v3, v60v4, t, "equal-map-v60-p-len") testReleaseBytes(bs60) } } for _, v := range []map[int]int32{nil, {}, {127: 0, 111: 77}} { // fmt.Printf(">>>> running mammoth map v61: %v\n", v) var v61v1, v61v2 map[int]int32 var bs61 []byte v61v1 = v bs61 = testMarshalErr(v61v1, h, t, "enc-map-v61") if v != nil { if v == nil { v61v2 = nil } else { v61v2 = make(map[int]int32, len(v)) } // reset map testUnmarshalErr(v61v2, bs61, h, t, "dec-map-v61") testDeepEqualErr(v61v1, v61v2, t, "equal-map-v61") if v == nil { v61v2 = nil } else { v61v2 = make(map[int]int32, len(v)) } // reset map testUnmarshalErr(reflect.ValueOf(v61v2), bs61, h, t, "dec-map-v61-noaddr") // decode into non-addressable map value testDeepEqualErr(v61v1, v61v2, t, "equal-map-v61-noaddr") } if v == nil { v61v2 = nil } else { v61v2 = make(map[int]int32, len(v)) } // reset map testUnmarshalErr(&v61v2, bs61, h, t, "dec-map-v61-p-len") testDeepEqualErr(v61v1, v61v2, t, "equal-map-v61-p-len") testReleaseBytes(bs61) bs61 = testMarshalErr(&v61v1, h, t, "enc-map-v61-p") v61v2 = nil testUnmarshalErr(&v61v2, bs61, h, t, "dec-map-v61-p-nil") testDeepEqualErr(v61v1, v61v2, t, "equal-map-v61-p-nil") testReleaseBytes(bs61) // ... if v == nil { v61v2 = nil } else { v61v2 = make(map[int]int32, len(v)) } // reset map var v61v3, v61v4 typMapMapIntInt32 v61v3 = typMapMapIntInt32(v61v1) v61v4 = typMapMapIntInt32(v61v2) if v != nil { bs61 = testMarshalErr(v61v3, h, t, "enc-map-v61-custom") testUnmarshalErr(v61v4, bs61, h, t, "dec-map-v61-p-len") testDeepEqualErr(v61v3, v61v4, t, "equal-map-v61-p-len") testReleaseBytes(bs61) } } for _, v := range []map[int]float64{nil, {}, {127: 0, 111: 33.3e3}} { // fmt.Printf(">>>> running mammoth map v62: %v\n", v) var v62v1, v62v2 map[int]float64 var bs62 []byte v62v1 = v bs62 = testMarshalErr(v62v1, h, t, "enc-map-v62") if v != nil { if v == nil { v62v2 = nil } else { v62v2 = make(map[int]float64, len(v)) } // reset map testUnmarshalErr(v62v2, bs62, h, t, "dec-map-v62") testDeepEqualErr(v62v1, v62v2, t, "equal-map-v62") if v == nil { v62v2 = nil } else { v62v2 = make(map[int]float64, len(v)) } // reset map testUnmarshalErr(reflect.ValueOf(v62v2), bs62, h, t, "dec-map-v62-noaddr") // decode into non-addressable map value testDeepEqualErr(v62v1, v62v2, t, "equal-map-v62-noaddr") } if v == nil { v62v2 = nil } else { v62v2 = make(map[int]float64, len(v)) } // reset map testUnmarshalErr(&v62v2, bs62, h, t, "dec-map-v62-p-len") testDeepEqualErr(v62v1, v62v2, t, "equal-map-v62-p-len") testReleaseBytes(bs62) bs62 = testMarshalErr(&v62v1, h, t, "enc-map-v62-p") v62v2 = nil testUnmarshalErr(&v62v2, bs62, h, t, "dec-map-v62-p-nil") testDeepEqualErr(v62v1, v62v2, t, "equal-map-v62-p-nil") testReleaseBytes(bs62) // ... if v == nil { v62v2 = nil } else { v62v2 = make(map[int]float64, len(v)) } // reset map var v62v3, v62v4 typMapMapIntFloat64 v62v3 = typMapMapIntFloat64(v62v1) v62v4 = typMapMapIntFloat64(v62v2) if v != nil { bs62 = testMarshalErr(v62v3, h, t, "enc-map-v62-custom") testUnmarshalErr(v62v4, bs62, h, t, "dec-map-v62-p-len") testDeepEqualErr(v62v3, v62v4, t, "equal-map-v62-p-len") testReleaseBytes(bs62) } } for _, v := range []map[int]bool{nil, {}, {77: false, 127: true}} { // fmt.Printf(">>>> running mammoth map v63: %v\n", v) var v63v1, v63v2 map[int]bool var bs63 []byte v63v1 = v bs63 = testMarshalErr(v63v1, h, t, "enc-map-v63") if v != nil { if v == nil { v63v2 = nil } else { v63v2 = make(map[int]bool, len(v)) } // reset map testUnmarshalErr(v63v2, bs63, h, t, "dec-map-v63") testDeepEqualErr(v63v1, v63v2, t, "equal-map-v63") if v == nil { v63v2 = nil } else { v63v2 = make(map[int]bool, len(v)) } // reset map testUnmarshalErr(reflect.ValueOf(v63v2), bs63, h, t, "dec-map-v63-noaddr") // decode into non-addressable map value testDeepEqualErr(v63v1, v63v2, t, "equal-map-v63-noaddr") } if v == nil { v63v2 = nil } else { v63v2 = make(map[int]bool, len(v)) } // reset map testUnmarshalErr(&v63v2, bs63, h, t, "dec-map-v63-p-len") testDeepEqualErr(v63v1, v63v2, t, "equal-map-v63-p-len") testReleaseBytes(bs63) bs63 = testMarshalErr(&v63v1, h, t, "enc-map-v63-p") v63v2 = nil testUnmarshalErr(&v63v2, bs63, h, t, "dec-map-v63-p-nil") testDeepEqualErr(v63v1, v63v2, t, "equal-map-v63-p-nil") testReleaseBytes(bs63) // ... if v == nil { v63v2 = nil } else { v63v2 = make(map[int]bool, len(v)) } // reset map var v63v3, v63v4 typMapMapIntBool v63v3 = typMapMapIntBool(v63v1) v63v4 = typMapMapIntBool(v63v2) if v != nil { bs63 = testMarshalErr(v63v3, h, t, "enc-map-v63-custom") testUnmarshalErr(v63v4, bs63, h, t, "dec-map-v63-p-len") testDeepEqualErr(v63v3, v63v4, t, "equal-map-v63-p-len") testReleaseBytes(bs63) } } for _, v := range []map[int32]interface{}{nil, {}, {111: nil, 77: "string-is-an-interface-2"}} { // fmt.Printf(">>>> running mammoth map v64: %v\n", v) var v64v1, v64v2 map[int32]interface{} var bs64 []byte v64v1 = v bs64 = testMarshalErr(v64v1, h, t, "enc-map-v64") if v != nil { if v == nil { v64v2 = nil } else { v64v2 = make(map[int32]interface{}, len(v)) } // reset map testUnmarshalErr(v64v2, bs64, h, t, "dec-map-v64") testDeepEqualErr(v64v1, v64v2, t, "equal-map-v64") if v == nil { v64v2 = nil } else { v64v2 = make(map[int32]interface{}, len(v)) } // reset map testUnmarshalErr(reflect.ValueOf(v64v2), bs64, h, t, "dec-map-v64-noaddr") // decode into non-addressable map value testDeepEqualErr(v64v1, v64v2, t, "equal-map-v64-noaddr") } if v == nil { v64v2 = nil } else { v64v2 = make(map[int32]interface{}, len(v)) } // reset map testUnmarshalErr(&v64v2, bs64, h, t, "dec-map-v64-p-len") testDeepEqualErr(v64v1, v64v2, t, "equal-map-v64-p-len") testReleaseBytes(bs64) bs64 = testMarshalErr(&v64v1, h, t, "enc-map-v64-p") v64v2 = nil testUnmarshalErr(&v64v2, bs64, h, t, "dec-map-v64-p-nil") testDeepEqualErr(v64v1, v64v2, t, "equal-map-v64-p-nil") testReleaseBytes(bs64) // ... if v == nil { v64v2 = nil } else { v64v2 = make(map[int32]interface{}, len(v)) } // reset map var v64v3, v64v4 typMapMapInt32Intf v64v3 = typMapMapInt32Intf(v64v1) v64v4 = typMapMapInt32Intf(v64v2) if v != nil { bs64 = testMarshalErr(v64v3, h, t, "enc-map-v64-custom") testUnmarshalErr(v64v4, bs64, h, t, "dec-map-v64-p-len") testDeepEqualErr(v64v3, v64v4, t, "equal-map-v64-p-len") testReleaseBytes(bs64) } } for _, v := range []map[int32]string{nil, {}, {127: "", 111: "some-string-2"}} { // fmt.Printf(">>>> running mammoth map v65: %v\n", v) var v65v1, v65v2 map[int32]string var bs65 []byte v65v1 = v bs65 = testMarshalErr(v65v1, h, t, "enc-map-v65") if v != nil { if v == nil { v65v2 = nil } else { v65v2 = make(map[int32]string, len(v)) } // reset map testUnmarshalErr(v65v2, bs65, h, t, "dec-map-v65") testDeepEqualErr(v65v1, v65v2, t, "equal-map-v65") if v == nil { v65v2 = nil } else { v65v2 = make(map[int32]string, len(v)) } // reset map testUnmarshalErr(reflect.ValueOf(v65v2), bs65, h, t, "dec-map-v65-noaddr") // decode into non-addressable map value testDeepEqualErr(v65v1, v65v2, t, "equal-map-v65-noaddr") } if v == nil { v65v2 = nil } else { v65v2 = make(map[int32]string, len(v)) } // reset map testUnmarshalErr(&v65v2, bs65, h, t, "dec-map-v65-p-len") testDeepEqualErr(v65v1, v65v2, t, "equal-map-v65-p-len") testReleaseBytes(bs65) bs65 = testMarshalErr(&v65v1, h, t, "enc-map-v65-p") v65v2 = nil testUnmarshalErr(&v65v2, bs65, h, t, "dec-map-v65-p-nil") testDeepEqualErr(v65v1, v65v2, t, "equal-map-v65-p-nil") testReleaseBytes(bs65) // ... if v == nil { v65v2 = nil } else { v65v2 = make(map[int32]string, len(v)) } // reset map var v65v3, v65v4 typMapMapInt32String v65v3 = typMapMapInt32String(v65v1) v65v4 = typMapMapInt32String(v65v2) if v != nil { bs65 = testMarshalErr(v65v3, h, t, "enc-map-v65-custom") testUnmarshalErr(v65v4, bs65, h, t, "dec-map-v65-p-len") testDeepEqualErr(v65v3, v65v4, t, "equal-map-v65-p-len") testReleaseBytes(bs65) } } for _, v := range []map[int32][]byte{nil, {}, {77: nil, 127: []byte("some-string-2")}} { // fmt.Printf(">>>> running mammoth map v66: %v\n", v) var v66v1, v66v2 map[int32][]byte var bs66 []byte v66v1 = v bs66 = testMarshalErr(v66v1, h, t, "enc-map-v66") if v != nil { if v == nil { v66v2 = nil } else { v66v2 = make(map[int32][]byte, len(v)) } // reset map testUnmarshalErr(v66v2, bs66, h, t, "dec-map-v66") testDeepEqualErr(v66v1, v66v2, t, "equal-map-v66") if v == nil { v66v2 = nil } else { v66v2 = make(map[int32][]byte, len(v)) } // reset map testUnmarshalErr(reflect.ValueOf(v66v2), bs66, h, t, "dec-map-v66-noaddr") // decode into non-addressable map value testDeepEqualErr(v66v1, v66v2, t, "equal-map-v66-noaddr") } if v == nil { v66v2 = nil } else { v66v2 = make(map[int32][]byte, len(v)) } // reset map testUnmarshalErr(&v66v2, bs66, h, t, "dec-map-v66-p-len") testDeepEqualErr(v66v1, v66v2, t, "equal-map-v66-p-len") testReleaseBytes(bs66) bs66 = testMarshalErr(&v66v1, h, t, "enc-map-v66-p") v66v2 = nil testUnmarshalErr(&v66v2, bs66, h, t, "dec-map-v66-p-nil") testDeepEqualErr(v66v1, v66v2, t, "equal-map-v66-p-nil") testReleaseBytes(bs66) // ... if v == nil { v66v2 = nil } else { v66v2 = make(map[int32][]byte, len(v)) } // reset map var v66v3, v66v4 typMapMapInt32Bytes v66v3 = typMapMapInt32Bytes(v66v1) v66v4 = typMapMapInt32Bytes(v66v2) if v != nil { bs66 = testMarshalErr(v66v3, h, t, "enc-map-v66-custom") testUnmarshalErr(v66v4, bs66, h, t, "dec-map-v66-p-len") testDeepEqualErr(v66v3, v66v4, t, "equal-map-v66-p-len") testReleaseBytes(bs66) } } for _, v := range []map[int32]uint8{nil, {}, {111: 0, 77: 127}} { // fmt.Printf(">>>> running mammoth map v67: %v\n", v) var v67v1, v67v2 map[int32]uint8 var bs67 []byte v67v1 = v bs67 = testMarshalErr(v67v1, h, t, "enc-map-v67") if v != nil { if v == nil { v67v2 = nil } else { v67v2 = make(map[int32]uint8, len(v)) } // reset map testUnmarshalErr(v67v2, bs67, h, t, "dec-map-v67") testDeepEqualErr(v67v1, v67v2, t, "equal-map-v67") if v == nil { v67v2 = nil } else { v67v2 = make(map[int32]uint8, len(v)) } // reset map testUnmarshalErr(reflect.ValueOf(v67v2), bs67, h, t, "dec-map-v67-noaddr") // decode into non-addressable map value testDeepEqualErr(v67v1, v67v2, t, "equal-map-v67-noaddr") } if v == nil { v67v2 = nil } else { v67v2 = make(map[int32]uint8, len(v)) } // reset map testUnmarshalErr(&v67v2, bs67, h, t, "dec-map-v67-p-len") testDeepEqualErr(v67v1, v67v2, t, "equal-map-v67-p-len") testReleaseBytes(bs67) bs67 = testMarshalErr(&v67v1, h, t, "enc-map-v67-p") v67v2 = nil testUnmarshalErr(&v67v2, bs67, h, t, "dec-map-v67-p-nil") testDeepEqualErr(v67v1, v67v2, t, "equal-map-v67-p-nil") testReleaseBytes(bs67) // ... if v == nil { v67v2 = nil } else { v67v2 = make(map[int32]uint8, len(v)) } // reset map var v67v3, v67v4 typMapMapInt32Uint8 v67v3 = typMapMapInt32Uint8(v67v1) v67v4 = typMapMapInt32Uint8(v67v2) if v != nil { bs67 = testMarshalErr(v67v3, h, t, "enc-map-v67-custom") testUnmarshalErr(v67v4, bs67, h, t, "dec-map-v67-p-len") testDeepEqualErr(v67v3, v67v4, t, "equal-map-v67-p-len") testReleaseBytes(bs67) } } for _, v := range []map[int32]uint64{nil, {}, {111: 0, 77: 127}} { // fmt.Printf(">>>> running mammoth map v68: %v\n", v) var v68v1, v68v2 map[int32]uint64 var bs68 []byte v68v1 = v bs68 = testMarshalErr(v68v1, h, t, "enc-map-v68") if v != nil { if v == nil { v68v2 = nil } else { v68v2 = make(map[int32]uint64, len(v)) } // reset map testUnmarshalErr(v68v2, bs68, h, t, "dec-map-v68") testDeepEqualErr(v68v1, v68v2, t, "equal-map-v68") if v == nil { v68v2 = nil } else { v68v2 = make(map[int32]uint64, len(v)) } // reset map testUnmarshalErr(reflect.ValueOf(v68v2), bs68, h, t, "dec-map-v68-noaddr") // decode into non-addressable map value testDeepEqualErr(v68v1, v68v2, t, "equal-map-v68-noaddr") } if v == nil { v68v2 = nil } else { v68v2 = make(map[int32]uint64, len(v)) } // reset map testUnmarshalErr(&v68v2, bs68, h, t, "dec-map-v68-p-len") testDeepEqualErr(v68v1, v68v2, t, "equal-map-v68-p-len") testReleaseBytes(bs68) bs68 = testMarshalErr(&v68v1, h, t, "enc-map-v68-p") v68v2 = nil testUnmarshalErr(&v68v2, bs68, h, t, "dec-map-v68-p-nil") testDeepEqualErr(v68v1, v68v2, t, "equal-map-v68-p-nil") testReleaseBytes(bs68) // ... if v == nil { v68v2 = nil } else { v68v2 = make(map[int32]uint64, len(v)) } // reset map var v68v3, v68v4 typMapMapInt32Uint64 v68v3 = typMapMapInt32Uint64(v68v1) v68v4 = typMapMapInt32Uint64(v68v2) if v != nil { bs68 = testMarshalErr(v68v3, h, t, "enc-map-v68-custom") testUnmarshalErr(v68v4, bs68, h, t, "dec-map-v68-p-len") testDeepEqualErr(v68v3, v68v4, t, "equal-map-v68-p-len") testReleaseBytes(bs68) } } for _, v := range []map[int32]int{nil, {}, {111: 0, 77: 127}} { // fmt.Printf(">>>> running mammoth map v69: %v\n", v) var v69v1, v69v2 map[int32]int var bs69 []byte v69v1 = v bs69 = testMarshalErr(v69v1, h, t, "enc-map-v69") if v != nil { if v == nil { v69v2 = nil } else { v69v2 = make(map[int32]int, len(v)) } // reset map testUnmarshalErr(v69v2, bs69, h, t, "dec-map-v69") testDeepEqualErr(v69v1, v69v2, t, "equal-map-v69") if v == nil { v69v2 = nil } else { v69v2 = make(map[int32]int, len(v)) } // reset map testUnmarshalErr(reflect.ValueOf(v69v2), bs69, h, t, "dec-map-v69-noaddr") // decode into non-addressable map value testDeepEqualErr(v69v1, v69v2, t, "equal-map-v69-noaddr") } if v == nil { v69v2 = nil } else { v69v2 = make(map[int32]int, len(v)) } // reset map testUnmarshalErr(&v69v2, bs69, h, t, "dec-map-v69-p-len") testDeepEqualErr(v69v1, v69v2, t, "equal-map-v69-p-len") testReleaseBytes(bs69) bs69 = testMarshalErr(&v69v1, h, t, "enc-map-v69-p") v69v2 = nil testUnmarshalErr(&v69v2, bs69, h, t, "dec-map-v69-p-nil") testDeepEqualErr(v69v1, v69v2, t, "equal-map-v69-p-nil") testReleaseBytes(bs69) // ... if v == nil { v69v2 = nil } else { v69v2 = make(map[int32]int, len(v)) } // reset map var v69v3, v69v4 typMapMapInt32Int v69v3 = typMapMapInt32Int(v69v1) v69v4 = typMapMapInt32Int(v69v2) if v != nil { bs69 = testMarshalErr(v69v3, h, t, "enc-map-v69-custom") testUnmarshalErr(v69v4, bs69, h, t, "dec-map-v69-p-len") testDeepEqualErr(v69v3, v69v4, t, "equal-map-v69-p-len") testReleaseBytes(bs69) } } for _, v := range []map[int32]int32{nil, {}, {111: 0, 77: 127}} { // fmt.Printf(">>>> running mammoth map v70: %v\n", v) var v70v1, v70v2 map[int32]int32 var bs70 []byte v70v1 = v bs70 = testMarshalErr(v70v1, h, t, "enc-map-v70") if v != nil { if v == nil { v70v2 = nil } else { v70v2 = make(map[int32]int32, len(v)) } // reset map testUnmarshalErr(v70v2, bs70, h, t, "dec-map-v70") testDeepEqualErr(v70v1, v70v2, t, "equal-map-v70") if v == nil { v70v2 = nil } else { v70v2 = make(map[int32]int32, len(v)) } // reset map testUnmarshalErr(reflect.ValueOf(v70v2), bs70, h, t, "dec-map-v70-noaddr") // decode into non-addressable map value testDeepEqualErr(v70v1, v70v2, t, "equal-map-v70-noaddr") } if v == nil { v70v2 = nil } else { v70v2 = make(map[int32]int32, len(v)) } // reset map testUnmarshalErr(&v70v2, bs70, h, t, "dec-map-v70-p-len") testDeepEqualErr(v70v1, v70v2, t, "equal-map-v70-p-len") testReleaseBytes(bs70) bs70 = testMarshalErr(&v70v1, h, t, "enc-map-v70-p") v70v2 = nil testUnmarshalErr(&v70v2, bs70, h, t, "dec-map-v70-p-nil") testDeepEqualErr(v70v1, v70v2, t, "equal-map-v70-p-nil") testReleaseBytes(bs70) // ... if v == nil { v70v2 = nil } else { v70v2 = make(map[int32]int32, len(v)) } // reset map var v70v3, v70v4 typMapMapInt32Int32 v70v3 = typMapMapInt32Int32(v70v1) v70v4 = typMapMapInt32Int32(v70v2) if v != nil { bs70 = testMarshalErr(v70v3, h, t, "enc-map-v70-custom") testUnmarshalErr(v70v4, bs70, h, t, "dec-map-v70-p-len") testDeepEqualErr(v70v3, v70v4, t, "equal-map-v70-p-len") testReleaseBytes(bs70) } } for _, v := range []map[int32]float64{nil, {}, {111: 0, 77: 11.1}} { // fmt.Printf(">>>> running mammoth map v71: %v\n", v) var v71v1, v71v2 map[int32]float64 var bs71 []byte v71v1 = v bs71 = testMarshalErr(v71v1, h, t, "enc-map-v71") if v != nil { if v == nil { v71v2 = nil } else { v71v2 = make(map[int32]float64, len(v)) } // reset map testUnmarshalErr(v71v2, bs71, h, t, "dec-map-v71") testDeepEqualErr(v71v1, v71v2, t, "equal-map-v71") if v == nil { v71v2 = nil } else { v71v2 = make(map[int32]float64, len(v)) } // reset map testUnmarshalErr(reflect.ValueOf(v71v2), bs71, h, t, "dec-map-v71-noaddr") // decode into non-addressable map value testDeepEqualErr(v71v1, v71v2, t, "equal-map-v71-noaddr") } if v == nil { v71v2 = nil } else { v71v2 = make(map[int32]float64, len(v)) } // reset map testUnmarshalErr(&v71v2, bs71, h, t, "dec-map-v71-p-len") testDeepEqualErr(v71v1, v71v2, t, "equal-map-v71-p-len") testReleaseBytes(bs71) bs71 = testMarshalErr(&v71v1, h, t, "enc-map-v71-p") v71v2 = nil testUnmarshalErr(&v71v2, bs71, h, t, "dec-map-v71-p-nil") testDeepEqualErr(v71v1, v71v2, t, "equal-map-v71-p-nil") testReleaseBytes(bs71) // ... if v == nil { v71v2 = nil } else { v71v2 = make(map[int32]float64, len(v)) } // reset map var v71v3, v71v4 typMapMapInt32Float64 v71v3 = typMapMapInt32Float64(v71v1) v71v4 = typMapMapInt32Float64(v71v2) if v != nil { bs71 = testMarshalErr(v71v3, h, t, "enc-map-v71-custom") testUnmarshalErr(v71v4, bs71, h, t, "dec-map-v71-p-len") testDeepEqualErr(v71v3, v71v4, t, "equal-map-v71-p-len") testReleaseBytes(bs71) } } for _, v := range []map[int32]bool{nil, {}, {127: false, 111: false}} { // fmt.Printf(">>>> running mammoth map v72: %v\n", v) var v72v1, v72v2 map[int32]bool var bs72 []byte v72v1 = v bs72 = testMarshalErr(v72v1, h, t, "enc-map-v72") if v != nil { if v == nil { v72v2 = nil } else { v72v2 = make(map[int32]bool, len(v)) } // reset map testUnmarshalErr(v72v2, bs72, h, t, "dec-map-v72") testDeepEqualErr(v72v1, v72v2, t, "equal-map-v72") if v == nil { v72v2 = nil } else { v72v2 = make(map[int32]bool, len(v)) } // reset map testUnmarshalErr(reflect.ValueOf(v72v2), bs72, h, t, "dec-map-v72-noaddr") // decode into non-addressable map value testDeepEqualErr(v72v1, v72v2, t, "equal-map-v72-noaddr") } if v == nil { v72v2 = nil } else { v72v2 = make(map[int32]bool, len(v)) } // reset map testUnmarshalErr(&v72v2, bs72, h, t, "dec-map-v72-p-len") testDeepEqualErr(v72v1, v72v2, t, "equal-map-v72-p-len") testReleaseBytes(bs72) bs72 = testMarshalErr(&v72v1, h, t, "enc-map-v72-p") v72v2 = nil testUnmarshalErr(&v72v2, bs72, h, t, "dec-map-v72-p-nil") testDeepEqualErr(v72v1, v72v2, t, "equal-map-v72-p-nil") testReleaseBytes(bs72) // ... if v == nil { v72v2 = nil } else { v72v2 = make(map[int32]bool, len(v)) } // reset map var v72v3, v72v4 typMapMapInt32Bool v72v3 = typMapMapInt32Bool(v72v1) v72v4 = typMapMapInt32Bool(v72v2) if v != nil { bs72 = testMarshalErr(v72v3, h, t, "enc-map-v72-custom") testUnmarshalErr(v72v4, bs72, h, t, "dec-map-v72-p-len") testDeepEqualErr(v72v3, v72v4, t, "equal-map-v72-p-len") testReleaseBytes(bs72) } } } 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) testDeepEqualErr(&m, &m2, 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) testDeepEqualErr(&mm, &mm2, t, "mammoth2-"+name) // testMammoth2(t, name, h) testReleaseBytes(b) } func TestJsonMammoth(t *testing.T) { doTestMammoth(t, testJsonH) } func TestCborMammoth(t *testing.T) { doTestMammoth(t, testCborH) } func TestMsgpackMammoth(t *testing.T) { doTestMammoth(t, testMsgpackH) } func TestBincMammoth(t *testing.T) { doTestMammoth(t, testBincH) } func TestSimpleMammoth(t *testing.T) { doTestMammoth(t, testSimpleH) } func TestJsonMammothMapsAndSlices(t *testing.T) { doTestMammothMapsAndSlices(t, testJsonH) } func TestCborMammothMapsAndSlices(t *testing.T) { doTestMammothMapsAndSlices(t, testCborH) } func TestMsgpackMammothMapsAndSlices(t *testing.T) { doTestMammothMapsAndSlices(t, testMsgpackH) } func TestBincMammothMapsAndSlices(t *testing.T) { doTestMammothMapsAndSlices(t, testBincH) } func TestSimpleMammothMapsAndSlices(t *testing.T) { doTestMammothMapsAndSlices(t, testSimpleH) } go-1.2.8/codec/msgpack.go000066400000000000000000000766441435255326100152070ustar00rootroot00000000000000// 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 ( "fmt" "io" "math" "net/rpc" "reflect" "time" "unicode/utf8" ) 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, } ) //--------------------------------------------- type msgpackEncDriver struct { noBuiltInTypes encDriverNoopContainerWriter encDriverNoState h *MsgpackHandle // x [8]byte e Encoder } func (e *msgpackEncDriver) encoder() *Encoder { return &e.e } func (e *msgpackEncDriver) EncodeNil() { e.e.encWr.writen1(mpNil) } func (e *msgpackEncDriver) EncodeInt(i int64) { if e.h.PositiveIntUnsigned && i >= 0 { e.EncodeUint(uint64(i)) } else if i > math.MaxInt8 { if i <= math.MaxInt16 { e.e.encWr.writen1(mpInt16) bigen.writeUint16(e.e.w(), uint16(i)) } else if i <= math.MaxInt32 { e.e.encWr.writen1(mpInt32) bigen.writeUint32(e.e.w(), uint32(i)) } else { e.e.encWr.writen1(mpInt64) bigen.writeUint64(e.e.w(), uint64(i)) } } else if i >= -32 { if e.h.NoFixedNum { e.e.encWr.writen2(mpInt8, byte(i)) } else { e.e.encWr.writen1(byte(i)) } } else if i >= math.MinInt8 { e.e.encWr.writen2(mpInt8, byte(i)) } else if i >= math.MinInt16 { e.e.encWr.writen1(mpInt16) bigen.writeUint16(e.e.w(), uint16(i)) } else if i >= math.MinInt32 { e.e.encWr.writen1(mpInt32) bigen.writeUint32(e.e.w(), uint32(i)) } else { e.e.encWr.writen1(mpInt64) bigen.writeUint64(e.e.w(), uint64(i)) } } func (e *msgpackEncDriver) EncodeUint(i uint64) { if i <= math.MaxInt8 { if e.h.NoFixedNum { e.e.encWr.writen2(mpUint8, byte(i)) } else { e.e.encWr.writen1(byte(i)) } } else if i <= math.MaxUint8 { e.e.encWr.writen2(mpUint8, byte(i)) } else if i <= math.MaxUint16 { e.e.encWr.writen1(mpUint16) bigen.writeUint16(e.e.w(), uint16(i)) } else if i <= math.MaxUint32 { e.e.encWr.writen1(mpUint32) bigen.writeUint32(e.e.w(), uint32(i)) } else { e.e.encWr.writen1(mpUint64) bigen.writeUint64(e.e.w(), uint64(i)) } } func (e *msgpackEncDriver) EncodeBool(b bool) { if b { e.e.encWr.writen1(mpTrue) } else { e.e.encWr.writen1(mpFalse) } } func (e *msgpackEncDriver) EncodeFloat32(f float32) { e.e.encWr.writen1(mpFloat) bigen.writeUint32(e.e.w(), math.Float32bits(f)) } func (e *msgpackEncDriver) EncodeFloat64(f float64) { e.e.encWr.writen1(mpDouble) bigen.writeUint64(e.e.w(), math.Float64bits(f)) } func (e *msgpackEncDriver) 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: bigen.writeUint32(e.e.w(), uint32(data64)) case 8: bigen.writeUint64(e.e.w(), data64) case 12: bigen.writeUint32(e.e.w(), uint32(nsec)) bigen.writeUint64(e.e.w(), uint64(sec)) } } func (e *msgpackEncDriver) 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 e.e.sideEncode(v, basetype, &bs) } else { bs = ext.WriteExt(v) } if bs == nil { e.EncodeNil() goto END } if e.h.WriteExt { e.encodeExtPreamble(uint8(xtag), len(bs)) e.e.encWr.writeb(bs) } else { e.EncodeStringBytesRaw(bs) } END: if ext == SelfExt { e.e.blist.put(bs) if !byteSliceSameData(bs0, bs) { e.e.blist.put(bs0) } } } func (e *msgpackEncDriver) EncodeRawExt(re *RawExt) { e.encodeExtPreamble(uint8(re.Tag), len(re.Data)) e.e.encWr.writeb(re.Data) } func (e *msgpackEncDriver) encodeExtPreamble(xtag byte, l int) { if l == 1 { e.e.encWr.writen2(mpFixExt1, xtag) } else if l == 2 { e.e.encWr.writen2(mpFixExt2, xtag) } else if l == 4 { e.e.encWr.writen2(mpFixExt4, xtag) } else if l == 8 { e.e.encWr.writen2(mpFixExt8, xtag) } else if l == 16 { e.e.encWr.writen2(mpFixExt16, xtag) } else if l < 256 { e.e.encWr.writen2(mpExt8, byte(l)) e.e.encWr.writen1(xtag) } else if l < 65536 { e.e.encWr.writen1(mpExt16) bigen.writeUint16(e.e.w(), uint16(l)) e.e.encWr.writen1(xtag) } else { e.e.encWr.writen1(mpExt32) bigen.writeUint32(e.e.w(), uint32(l)) e.e.encWr.writen1(xtag) } } func (e *msgpackEncDriver) WriteArrayStart(length int) { e.writeContainerLen(msgpackContainerList, length) } func (e *msgpackEncDriver) WriteMapStart(length int) { e.writeContainerLen(msgpackContainerMap, length) } func (e *msgpackEncDriver) 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.e.encWr.writestr(s) } } func (e *msgpackEncDriver) EncodeStringBytesRaw(bs []byte) { if bs == nil { e.EncodeNil() return } if e.h.WriteExt { e.writeContainerLen(msgpackContainerBin, len(bs)) } else { e.writeContainerLen(msgpackContainerRawLegacy, len(bs)) } if len(bs) > 0 { e.e.encWr.writeb(bs) } } func (e *msgpackEncDriver) writeContainerLen(ct msgpackContainerType, l int) { if ct.fixCutoff > 0 && l < int(ct.fixCutoff) { e.e.encWr.writen1(ct.bFixMin | byte(l)) } else if ct.b8 > 0 && l < 256 { e.e.encWr.writen2(ct.b8, uint8(l)) } else if l < 65536 { e.e.encWr.writen1(ct.b16) bigen.writeUint16(e.e.w(), uint16(l)) } else { e.e.encWr.writen1(ct.b32) bigen.writeUint32(e.e.w(), uint32(l)) } } //--------------------------------------------- type msgpackDecDriver struct { decDriverNoopContainerReader decDriverNoopNumberHelper h *MsgpackHandle bdAndBdread _ bool noBuiltInTypes d Decoder } func (d *msgpackDecDriver) decoder() *Decoder { return &d.d } // 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) 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.d.decRd.readn4()))) case mpDouble: n.v = valueTypeFloat n.f = math.Float64frombits(bigen.Uint64(d.d.decRd.readn8())) case mpUint8: n.v = valueTypeUint n.u = uint64(d.d.decRd.readn1()) case mpUint16: n.v = valueTypeUint n.u = uint64(bigen.Uint16(d.d.decRd.readn2())) case mpUint32: n.v = valueTypeUint n.u = uint64(bigen.Uint32(d.d.decRd.readn4())) case mpUint64: n.v = valueTypeUint n.u = uint64(bigen.Uint64(d.d.decRd.readn8())) case mpInt8: n.v = valueTypeInt n.i = int64(int8(d.d.decRd.readn1())) case mpInt16: n.v = valueTypeInt n.i = int64(int16(bigen.Uint16(d.d.decRd.readn2()))) case mpInt32: n.v = valueTypeInt n.i = int64(int32(bigen.Uint32(d.d.decRd.readn4()))) case mpInt64: n.v = valueTypeInt n.i = int64(int64(bigen.Uint64(d.d.decRd.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.h.WriteExt) // 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(false) 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.d.decRd.readn1()) if n.u == uint64(mpTimeExtTagU) { n.v = valueTypeTime n.t = d.decodeTime(clen) } else if d.d.bytes { n.l = d.d.decRd.rb.readx(uint(clen)) } else { n.l = decByteSlice(d.d.r(), clen, d.d.h.MaxInitLen, d.d.b[:]) } default: d.d.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) nextValueBytes(v0 []byte) (v []byte) { if !d.bdRead { d.readNextBd() } v = v0 var h = decNextValueBytesHelper{d: &d.d} var cursor = d.d.rb.c - 1 h.append1(&v, d.bd) v = d.nextValueBytesBdReadR(v) d.bdRead = false h.bytesRdV(&v, cursor) return } func (d *msgpackDecDriver) nextValueBytesR(v0 []byte) (v []byte) { d.readNextBd() v = v0 var h = decNextValueBytesHelper{d: &d.d} h.append1(&v, d.bd) return d.nextValueBytesBdReadR(v) } func (d *msgpackDecDriver) nextValueBytesBdReadR(v0 []byte) (v []byte) { v = v0 var h = decNextValueBytesHelper{d: &d.d} bd := d.bd var clen uint switch bd { case mpNil, mpFalse, mpTrue: // pass case mpUint8, mpInt8: h.append1(&v, d.d.decRd.readn1()) case mpUint16, mpInt16: h.appendN(&v, d.d.decRd.readx(2)...) case mpFloat, mpUint32, mpInt32: h.appendN(&v, d.d.decRd.readx(4)...) case mpDouble, mpUint64, mpInt64: h.appendN(&v, d.d.decRd.readx(8)...) case mpStr8, mpBin8: clen = uint(d.d.decRd.readn1()) h.append1(&v, byte(clen)) h.appendN(&v, d.d.decRd.readx(clen)...) case mpStr16, mpBin16: x := d.d.decRd.readn2() h.appendN(&v, x[:]...) clen = uint(bigen.Uint16(x)) h.appendN(&v, d.d.decRd.readx(clen)...) case mpStr32, mpBin32: x := d.d.decRd.readn4() h.appendN(&v, x[:]...) clen = uint(bigen.Uint32(x)) h.appendN(&v, d.d.decRd.readx(clen)...) case mpFixExt1: h.append1(&v, d.d.decRd.readn1()) // tag h.append1(&v, d.d.decRd.readn1()) case mpFixExt2: h.append1(&v, d.d.decRd.readn1()) // tag h.appendN(&v, d.d.decRd.readx(2)...) case mpFixExt4: h.append1(&v, d.d.decRd.readn1()) // tag h.appendN(&v, d.d.decRd.readx(4)...) case mpFixExt8: h.append1(&v, d.d.decRd.readn1()) // tag h.appendN(&v, d.d.decRd.readx(8)...) case mpFixExt16: h.append1(&v, d.d.decRd.readn1()) // tag h.appendN(&v, d.d.decRd.readx(16)...) case mpExt8: clen = uint(d.d.decRd.readn1()) h.append1(&v, uint8(clen)) h.append1(&v, d.d.decRd.readn1()) // tag h.appendN(&v, d.d.decRd.readx(clen)...) case mpExt16: x := d.d.decRd.readn2() clen = uint(bigen.Uint16(x)) h.appendN(&v, x[:]...) h.append1(&v, d.d.decRd.readn1()) // tag h.appendN(&v, d.d.decRd.readx(clen)...) case mpExt32: x := d.d.decRd.readn4() clen = uint(bigen.Uint32(x)) h.appendN(&v, x[:]...) h.append1(&v, d.d.decRd.readn1()) // tag h.appendN(&v, d.d.decRd.readx(clen)...) case mpArray16: x := d.d.decRd.readn2() clen = uint(bigen.Uint16(x)) h.appendN(&v, x[:]...) for i := uint(0); i < clen; i++ { v = d.nextValueBytesR(v) } case mpArray32: x := d.d.decRd.readn4() clen = uint(bigen.Uint32(x)) h.appendN(&v, x[:]...) for i := uint(0); i < clen; i++ { v = d.nextValueBytesR(v) } case mpMap16: x := d.d.decRd.readn2() clen = uint(bigen.Uint16(x)) h.appendN(&v, x[:]...) for i := uint(0); i < clen; i++ { v = d.nextValueBytesR(v) v = d.nextValueBytesR(v) } case mpMap32: x := d.d.decRd.readn4() clen = uint(bigen.Uint32(x)) h.appendN(&v, x[:]...) for i := uint(0); i < clen; i++ { v = d.nextValueBytesR(v) v = d.nextValueBytesR(v) } default: switch { case bd >= mpPosFixNumMin && bd <= mpPosFixNumMax: // pass case bd >= mpNegFixNumMin && bd <= mpNegFixNumMax: // pass case bd >= mpFixStrMin && bd <= mpFixStrMax: clen = uint(mpFixStrMin ^ bd) h.appendN(&v, d.d.decRd.readx(clen)...) case bd >= mpFixArrayMin && bd <= mpFixArrayMax: clen = uint(mpFixArrayMin ^ bd) for i := uint(0); i < clen; i++ { v = d.nextValueBytesR(v) } case bd >= mpFixMapMin && bd <= mpFixMapMax: clen = uint(mpFixMapMin ^ bd) for i := uint(0); i < clen; i++ { v = d.nextValueBytesR(v) v = d.nextValueBytesR(v) } default: d.d.errorf("nextValueBytes: cannot infer value: %s: Ox%x/%d/%s", msgBadDesc, bd, bd, mpdesc(bd)) } } return } func (d *msgpackDecDriver) decFloat4Int32() (f float32) { fbits := bigen.Uint32(d.d.decRd.readn4()) f = math.Float32frombits(fbits) if !noFrac32(fbits) { d.d.errorf("assigning integer value from float32 with a fraction: %v", f) } return } func (d *msgpackDecDriver) decFloat4Int64() (f float64) { fbits := bigen.Uint64(d.d.decRd.readn8()) f = math.Float64frombits(fbits) if !noFrac64(fbits) { d.d.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) DecodeInt64() (i int64) { if d.advanceNil() { return } switch d.bd { case mpUint8: i = int64(uint64(d.d.decRd.readn1())) case mpUint16: i = int64(uint64(bigen.Uint16(d.d.decRd.readn2()))) case mpUint32: i = int64(uint64(bigen.Uint32(d.d.decRd.readn4()))) case mpUint64: i = int64(bigen.Uint64(d.d.decRd.readn8())) case mpInt8: i = int64(int8(d.d.decRd.readn1())) case mpInt16: i = int64(int16(bigen.Uint16(d.d.decRd.readn2()))) case mpInt32: i = int64(int32(bigen.Uint32(d.d.decRd.readn4()))) case mpInt64: i = int64(bigen.Uint64(d.d.decRd.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: d.d.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) DecodeUint64() (ui uint64) { if d.advanceNil() { return } switch d.bd { case mpUint8: ui = uint64(d.d.decRd.readn1()) case mpUint16: ui = uint64(bigen.Uint16(d.d.decRd.readn2())) case mpUint32: ui = uint64(bigen.Uint32(d.d.decRd.readn4())) case mpUint64: ui = bigen.Uint64(d.d.decRd.readn8()) case mpInt8: if i := int64(int8(d.d.decRd.readn1())); i >= 0 { ui = uint64(i) } else { d.d.errorf("assigning negative signed value: %v, to unsigned type", i) } case mpInt16: if i := int64(int16(bigen.Uint16(d.d.decRd.readn2()))); i >= 0 { ui = uint64(i) } else { d.d.errorf("assigning negative signed value: %v, to unsigned type", i) } case mpInt32: if i := int64(int32(bigen.Uint32(d.d.decRd.readn4()))); i >= 0 { ui = uint64(i) } else { d.d.errorf("assigning negative signed value: %v, to unsigned type", i) } case mpInt64: if i := int64(bigen.Uint64(d.d.decRd.readn8())); i >= 0 { ui = uint64(i) } else { d.d.errorf("assigning negative signed value: %v, to unsigned type", i) } case mpFloat: if f := d.decFloat4Int32(); f >= 0 { ui = uint64(f) } else { d.d.errorf("assigning negative float value: %v, to unsigned type", f) } case mpDouble: if f := d.decFloat4Int64(); f >= 0 { ui = uint64(f) } else { d.d.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: d.d.errorf("assigning negative signed value: %v, to unsigned type", int(d.bd)) default: d.d.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) DecodeFloat64() (f float64) { if d.advanceNil() { return } if d.bd == mpFloat { f = float64(math.Float32frombits(bigen.Uint32(d.d.decRd.readn4()))) } else if d.bd == mpDouble { f = math.Float64frombits(bigen.Uint64(d.d.decRd.readn8())) } else { f = float64(d.DecodeInt64()) } d.bdRead = false return } // bool can be decoded from bool, fixnum 0 or 1. func (d *msgpackDecDriver) 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 { d.d.errorf("cannot decode bool: %s: %x/%s", msgBadDesc, d.bd, mpdesc(d.bd)) } d.bdRead = false return } func (d *msgpackDecDriver) DecodeBytes(bs []byte) (bsOut []byte) { d.d.decByteState = decByteStateNone 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 if bd == mpArray16 || bd == mpArray32 || (bd >= mpFixArrayMin && bd <= mpFixArrayMax) { // check if an "array" of uint8's if bs == nil { d.d.decByteState = decByteStateReuseBuf bs = d.d.b[:] } // bsOut, _ = fastpathTV.DecSliceUint8V(bs, true, d.d) slen := d.ReadArrayStart() var changed bool if bs, changed = usableByteSlice(bs, slen); changed { d.d.decByteState = decByteStateNone } 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))) } return bs } else { d.d.errorf("invalid byte descriptor for decoding bytes, got: 0x%x", d.bd) } d.bdRead = false if d.d.zerocopy() { d.d.decByteState = decByteStateZerocopy return d.d.decRd.rb.readx(uint(clen)) } if bs == nil { d.d.decByteState = decByteStateReuseBuf bs = d.d.b[:] } return decByteSlice(d.d.r(), clen, d.h.MaxInitLen, bs) } func (d *msgpackDecDriver) DecodeStringAsBytes() (s []byte) { s = d.DecodeBytes(nil) if d.h.ValidateUnicode && !utf8.Valid(s) { d.d.errorf("DecodeStringAsBytes: invalid UTF-8: %s", s) } return } func (d *msgpackDecDriver) descBd() string { return sprintf("%v (%s)", d.bd, mpdesc(d.bd)) } func (d *msgpackDecDriver) readNextBd() { d.bd = d.d.decRd.readn1() d.bdRead = true } func (d *msgpackDecDriver) advanceNil() (null bool) { if !d.bdRead { d.readNextBd() } if d.bd == mpNil { d.bdRead = false return true // null = true } return } func (d *msgpackDecDriver) TryNil() (v bool) { return d.advanceNil() } func (d *msgpackDecDriver) 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) readContainerLen(ct msgpackContainerType) (clen int) { bd := d.bd if bd == ct.b8 { clen = int(d.d.decRd.readn1()) } else if bd == ct.b16 { clen = int(bigen.Uint16(d.d.decRd.readn2())) } else if bd == ct.b32 { clen = int(bigen.Uint32(d.d.decRd.readn4())) } else if (ct.bFixMin & bd) == ct.bFixMin { clen = int(ct.bFixMin ^ bd) } else { d.d.errorf("cannot read container length: %s: hex: %x, decimal: %d", msgBadDesc, bd, bd) } d.bdRead = false return } func (d *msgpackDecDriver) ReadMapStart() int { if d.advanceNil() { return containerLenNil } return d.readContainerLen(msgpackContainerMap) } func (d *msgpackDecDriver) ReadArrayStart() int { if d.advanceNil() { return containerLenNil } return d.readContainerLen(msgpackContainerList) } func (d *msgpackDecDriver) 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.d.decRd.readn1()) case mpExt16: clen = int(bigen.Uint16(d.d.decRd.readn2())) case mpExt32: clen = int(bigen.Uint32(d.d.decRd.readn4())) default: d.d.errorf("decoding ext bytes: found unexpected byte: %x", d.bd) } return } func (d *msgpackDecDriver) 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.d.decRd.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.d.decRd.readn1() == mpTimeExtTagU { clen = 12 } else { d.d.errorf("invalid stream for decoding time as extension: got 0x%x, 0x%x", d.bd, b2) } } return d.decodeTime(clen) } func (d *msgpackDecDriver) decodeTime(clen int) (t time.Time) { d.bdRead = false switch clen { case 4: t = time.Unix(int64(bigen.Uint32(d.d.decRd.readn4())), 0).UTC() case 8: tv := bigen.Uint64(d.d.decRd.readn8()) t = time.Unix(int64(tv&0x00000003ffffffff), int64(tv>>34)).UTC() case 12: nsec := bigen.Uint32(d.d.decRd.readn4()) sec := bigen.Uint64(d.d.decRd.readn8()) t = time.Unix(int64(sec), int64(nsec)).UTC() default: d.d.errorf("invalid length of bytes for decoding time - expecting 4 or 8 or 12, got %d", clen) } return } func (d *msgpackDecDriver) DecodeExt(rv interface{}, basetype reflect.Type, xtag uint64, ext Ext) { if xtag > 0xff { d.d.errorf("ext: tag must be <= 0xff; got: %v", xtag) } if d.advanceNil() { return } xbs, realxtag1, zerocopy := d.decodeExtV(ext != nil, uint8(xtag)) realxtag := uint64(realxtag1) if ext == nil { re := rv.(*RawExt) re.Tag = realxtag re.setData(xbs, zerocopy) } else if ext == SelfExt { d.d.sideDecode(rv, basetype, xbs) } else { ext.ReadExt(rv, xbs) } } func (d *msgpackDecDriver) decodeExtV(verifyTag bool, tag byte) (xbs []byte, xtag byte, zerocopy bool) { xbd := d.bd if xbd == mpBin8 || xbd == mpBin16 || xbd == mpBin32 { xbs = d.DecodeBytes(nil) } else if xbd == mpStr8 || xbd == mpStr16 || xbd == mpStr32 || (xbd >= mpFixStrMin && xbd <= mpFixStrMax) { xbs = d.DecodeStringAsBytes() } else { clen := d.readExtLen() xtag = d.d.decRd.readn1() if verifyTag && xtag != tag { d.d.errorf("wrong extension tag - got %b, expecting %v", xtag, tag) } if d.d.bytes { xbs = d.d.decRd.rb.readx(uint(clen)) zerocopy = true } else { xbs = decByteSlice(d.d.r(), clen, d.d.h.MaxInitLen, d.d.b[:]) } } d.bdRead = false return } //-------------------------------------------------- // MsgpackHandle is a Handle for the Msgpack Schema-Free Encoding Format. type MsgpackHandle struct { binaryEncodingType 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) } func (h *MsgpackHandle) newEncDriver() encDriver { var e = &msgpackEncDriver{h: h} e.e.e = e e.e.init(h) e.reset() return e } func (h *MsgpackHandle) newDecDriver() decDriver { d := &msgpackDecDriver{h: h} d.d.d = d d.d.init(h) d.reset() return d } //-------------------------------------------------- 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 cls := c.cls.load(); cls.closed { return io.EOF } // 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)} } var _ decDriver = (*msgpackDecDriver)(nil) var _ encDriver = (*msgpackEncDriver)(nil) go-1.2.8/codec/py_test.go000066400000000000000000000017621435255326100152360ustar00rootroot00000000000000// 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 x // +build x package codec // These tests are used to verify msgpack and cbor implementations against their python libraries. // If you have the library installed, you can enable the tests back by running: go test -tags=x . // Look at test.py for how to setup your environment. // // Also, name all tests here with suffix X, so that we can filter to run only these // using: go test -tags x -run '.*X$' import ( "testing" ) func TestMsgpackPythonGenStreamsX(t *testing.T) { doTestPythonGenStreams(t, testMsgpackH) } func TestCborPythonGenStreamsX(t *testing.T) { doTestPythonGenStreams(t, testCborH) } func TestMsgpackRpcSpecGoClientToPythonSvcX(t *testing.T) { doTestMsgpackRpcSpecGoClientToPythonSvc(t, testMsgpackH) } func TestMsgpackRpcSpecPythonClientToGoSvcX(t *testing.T) { doTestMsgpackRpcSpecPythonClientToGoSvc(t, testMsgpackH) } go-1.2.8/codec/reader.go000066400000000000000000000410561435255326100150110ustar00rootroot00000000000000// 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" // decReader abstracts the reading source, allowing implementations that can // read from an io.Reader or directly off a byte slice with zero-copying. type decReader interface { // readx will return a view of the []byte if decoding from a []byte, OR // read into the implementation scratch buffer if possible i.e. n < len(scratchbuf), OR // create a new []byte and read into that readx(n uint) []byte readb([]byte) readn1() byte readn2() [2]byte // readn3 will read 3 bytes into the top-most elements of a 4-byte array readn3() [4]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 include last read byte in first element of slice, // and continue numeric characters until it sees a non-numeric char // or EOF. If it sees a non-numeric character, it will unread that. jsonReadNum() []byte // jsonReadAsisChars will read json plain characters (anything but " or \) // and return a slice terminated by a non-json asis character. jsonReadAsisChars() []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, only stopping once it matches the 'stop' byte (which it excludes). readUntil(stop byte) (out []byte) } // ------------------------------------------------ type unreadByteStatus uint8 // unreadByteStatus goes from // undefined (when initialized) -- (read) --> canUnread -- (unread) --> canRead ... const ( unreadByteUndefined unreadByteStatus = iota unreadByteCanRead unreadByteCanUnread ) // -------------------- type ioDecReaderCommon struct { r io.Reader // the reader passed in n uint // num read l byte // last byte ls unreadByteStatus // last byte status b [6]byte // tiny buffer for reading single bytes blist *bytesFreelist bufr []byte // buffer for readTo/readUntil } func (z *ioDecReaderCommon) reset(r io.Reader, blist *bytesFreelist) { z.blist = blist z.r = r z.ls = unreadByteUndefined z.l, z.n = 0, 0 z.bufr = z.blist.check(z.bufr, 256) } func (z *ioDecReaderCommon) numread() uint { return z.n } // ------------------------------------------ // ioDecReader is a decReader that reads off an io.Reader. // // It also has a fallback implementation of ByteScanner if needed. type ioDecReader struct { ioDecReaderCommon br io.ByteScanner x [64 + 48]byte // for: get struct field name, swallow valueTypeBytes, etc } func (z *ioDecReader) reset(r io.Reader, blist *bytesFreelist) { z.ioDecReaderCommon.reset(r, blist) z.br, _ = r.(io.ByteScanner) } func (z *ioDecReader) Read(p []byte) (n int, err error) { if len(p) == 0 { return } var firstByte bool if z.ls == unreadByteCanRead { z.ls = unreadByteCanUnread p[0] = z.l if len(p) == 1 { n = 1 return } firstByte = true p = p[1:] } n, err = z.r.Read(p) if n > 0 { if err == io.EOF && n == len(p) { err = nil // read was successful, so postpone EOF (till next time) } z.l = p[n-1] z.ls = unreadByteCanUnread } if firstByte { n++ } return } func (z *ioDecReader) ReadByte() (c byte, err error) { if z.br != nil { c, err = z.br.ReadByte() if err == nil { z.l = c z.ls = unreadByteCanUnread } return } n, err := z.Read(z.b[:1]) if n == 1 { c = z.b[0] if err == io.EOF { err = nil // read was successful, so postpone EOF (till next time) } } return } func (z *ioDecReader) UnreadByte() (err error) { if z.br != nil { err = z.br.UnreadByte() if err == nil { z.ls = unreadByteCanRead } return } switch z.ls { case unreadByteCanUnread: z.ls = unreadByteCanRead case unreadByteCanRead: err = errDecUnreadByteLastByteNotRead case unreadByteUndefined: err = errDecUnreadByteNothingToRead default: err = errDecUnreadByteUnknown } return } func (z *ioDecReader) readn2() (bs [2]byte) { z.readb(bs[:]) return } func (z *ioDecReader) readn3() (bs [4]byte) { z.readb(bs[1:]) return } func (z *ioDecReader) readn4() (bs [4]byte) { z.readb(bs[:]) return } func (z *ioDecReader) readn8() (bs [8]byte) { z.readb(bs[:]) return } func (z *ioDecReader) readx(n uint) (bs []byte) { if n == 0 { return } if n < uint(len(z.x)) { bs = z.x[:n] } else { bs = make([]byte, n) } _, err := readFull(z.r, bs) halt.onerror(err) z.n += uint(len(bs)) return } func (z *ioDecReader) readb(bs []byte) { if len(bs) == 0 { return } _, err := readFull(z.r, bs) halt.onerror(err) z.n += uint(len(bs)) } func (z *ioDecReader) readn1() (b uint8) { b, err := z.ReadByte() halt.onerror(err) z.n++ return } func (z *ioDecReader) readn1eof() (b uint8, eof bool) { b, err := z.ReadByte() if err == nil { z.n++ } else if err == io.EOF { eof = true } else { halt.onerror(err) } return } func (z *ioDecReader) jsonReadNum() (bs []byte) { z.unreadn1() z.bufr = z.bufr[:0] LOOP: i, eof := z.readn1eof() if eof { return z.bufr } if isNumberChar(i) { z.bufr = append(z.bufr, i) goto LOOP } z.unreadn1() return z.bufr } func (z *ioDecReader) jsonReadAsisChars() (bs []byte) { z.bufr = z.bufr[:0] LOOP: i := z.readn1() z.bufr = append(z.bufr, i) if i == '"' || i == '\\' { return z.bufr } goto LOOP } func (z *ioDecReader) skipWhitespace() (token byte) { LOOP: token = z.readn1() if isWhitespaceChar(token) { goto LOOP } return } func (z *ioDecReader) readUntil(stop byte) []byte { z.bufr = z.bufr[:0] LOOP: token := z.readn1() z.bufr = append(z.bufr, token) if token == stop { return z.bufr[:len(z.bufr)-1] } goto LOOP } func (z *ioDecReader) unreadn1() { err := z.UnreadByte() halt.onerror(err) z.n-- } // ------------------------------------ type bufioDecReader struct { ioDecReaderCommon c uint // cursor buf []byte } func (z *bufioDecReader) reset(r io.Reader, bufsize int, blist *bytesFreelist) { z.ioDecReaderCommon.reset(r, blist) z.c = 0 if cap(z.buf) < bufsize { z.buf = blist.get(bufsize) } else { z.buf = z.buf[:0] } } func (z *bufioDecReader) readb(p []byte) { var n = uint(copy(p, z.buf[z.c:])) z.n += n z.c += n if len(p) != int(n) { z.readbFill(p, n, true, false) } } func readbFillHandleErr(err error, must, eof bool) (isEOF bool) { if err == io.EOF { isEOF = true } if must && !(eof && isEOF) { halt.onerror(err) } return } func (z *bufioDecReader) readbFill(p0 []byte, n uint, must, eof bool) (isEOF bool, err error) { // at this point, there's nothing in z.buf to read (z.buf is fully consumed) var p []byte if p0 != nil { p = p0[n:] } var n2 uint if len(p) > cap(z.buf) { n2, err = readFull(z.r, p) if err != nil { isEOF = readbFillHandleErr(err, must, eof) return } n += n2 z.n += n2 // always keep last byte in z.buf z.buf = z.buf[:1] z.buf[0] = p[len(p)-1] z.c = 1 return } // z.c is now 0, and len(p) <= cap(z.buf) var n1 int LOOP: // for len(p) > 0 && z.err == nil { z.buf = z.buf[0:cap(z.buf)] n1, err = z.r.Read(z.buf) n2 = uint(n1) if n2 == 0 && err != nil { isEOF = readbFillHandleErr(err, must, eof) return } err = nil z.buf = z.buf[:n2] z.c = 0 if len(p) > 0 { n2 = uint(copy(p, z.buf)) z.c = n2 n += n2 z.n += n2 p = p[n2:] if len(p) > 0 { goto LOOP } if z.c == 0 { z.buf = z.buf[:1] z.buf[0] = p[len(p)-1] z.c = 1 } } return } func (z *bufioDecReader) readn1() (b byte) { if z.c >= uint(len(z.buf)) { z.readbFill(nil, 0, true, false) } b = z.buf[z.c] z.c++ z.n++ return } func (z *bufioDecReader) readn1eof() (b byte, eof bool) { if z.c >= uint(len(z.buf)) { eof, _ = z.readbFill(nil, 0, true, true) if eof { return } } b = z.buf[z.c] z.c++ z.n++ return } func (z *bufioDecReader) unreadn1() { if z.c == 0 { halt.onerror(errDecUnreadByteNothingToRead) } z.c-- z.n-- } func (z *bufioDecReader) readn2() (bs [2]byte) { z.readb(bs[:]) return } func (z *bufioDecReader) readn3() (bs [4]byte) { z.readb(bs[1:]) return } func (z *bufioDecReader) readn4() (bs [4]byte) { z.readb(bs[:]) return } func (z *bufioDecReader) readn8() (bs [8]byte) { z.readb(bs[:]) return } func (z *bufioDecReader) readx(n uint) (bs []byte) { if n == 0 { // return } else if z.c+n <= uint(len(z.buf)) { bs = z.buf[z.c : z.c+n] z.n += n z.c += n } else { bs = make([]byte, n) // n no longer used - can reuse n = uint(copy(bs, z.buf[z.c:])) z.n += n z.c += n z.readbFill(bs, n, true, false) } return } func (z *bufioDecReader) jsonReadNum() (bs []byte) { z.unreadn1() z.bufr = z.bufr[:0] LOOP: i, eof := z.readn1eof() if eof { return z.bufr } if isNumberChar(i) { z.bufr = append(z.bufr, i) goto LOOP } z.unreadn1() return z.bufr } func (z *bufioDecReader) jsonReadAsisChars() (bs []byte) { z.bufr = z.bufr[:0] LOOP: i := z.readn1() z.bufr = append(z.bufr, i) if i == '"' || i == '\\' { return z.bufr } goto LOOP } func (z *bufioDecReader) skipWhitespace() (token byte) { i := z.c LOOP: if i < uint(len(z.buf)) { // inline z.skipLoopFn(i) and refactor, so cost is within inline budget token = z.buf[i] i++ if isWhitespaceChar(token) { goto LOOP } z.n += i - 2 - z.c z.c = i return } return z.skipFillWhitespace() } func (z *bufioDecReader) skipFillWhitespace() (token byte) { z.n += uint(len(z.buf)) - z.c var i, n2 int var err error for { z.c = 0 z.buf = z.buf[0:cap(z.buf)] n2, err = z.r.Read(z.buf) if n2 == 0 { halt.onerror(err) } z.buf = z.buf[:n2] for i, token = range z.buf { if !isWhitespaceChar(token) { z.n += (uint(i) - z.c) - 1 z.loopFn(uint(i + 1)) return } } z.n += uint(n2) } } func (z *bufioDecReader) loopFn(i uint) { z.c = i } func (z *bufioDecReader) readUntil(stop byte) (out []byte) { i := z.c LOOP: if i < uint(len(z.buf)) { if z.buf[i] == stop { z.n += (i - z.c) - 1 i++ out = z.buf[z.c:i] z.c = i goto FINISH } i++ goto LOOP } out = z.readUntilFill(stop) FINISH: return out[:len(out)-1] } func (z *bufioDecReader) readUntilFill(stop byte) []byte { z.bufr = z.bufr[:0] z.n += uint(len(z.buf)) - z.c z.bufr = append(z.bufr, z.buf[z.c:]...) for { z.c = 0 z.buf = z.buf[0:cap(z.buf)] n1, err := z.r.Read(z.buf) if n1 == 0 { halt.onerror(err) } n2 := uint(n1) z.buf = z.buf[:n2] for i, token := range z.buf { if token == stop { z.n += (uint(i) - z.c) - 1 z.bufr = append(z.bufr, z.buf[z.c:i+1]...) z.loopFn(uint(i + 1)) return z.bufr } } z.bufr = append(z.bufr, z.buf...) z.n += n2 } } // ------------------------------------ // 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.EOF. // instead, we let it bubble up to the exported Encode/Decode method // and recover it as an io.EOF. // // see panicValToErr(...) function in helper.go. type bytesDecReader struct { b []byte // data c uint // cursor } func (z *bytesDecReader) reset(in []byte) { 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) { x := z.c + n bs = z.b[z.c:x] z.c = x return } func (z *bytesDecReader) readb(bs []byte) { copy(bs, z.readx(uint(len(bs)))) } // MARKER: do not use this - as it calls into memmove (as the size of data to move is unknown) // func (z *bytesDecReader) readnn(bs []byte, n uint) { // x := z.c // copy(bs, z.b[x:x+n]) // z.c += n // } // func (z *bytesDecReader) readn(num uint8) (bs [8]byte) { // x := z.c + uint(num) // copy(bs[:], z.b[z.c:x]) // slice z.b completely, so we get bounds error if past // z.c = x // return // } // func (z *bytesDecReader) readn1() uint8 { // z.c++ // return z.b[z.c-1] // } func (z *bytesDecReader) readn1() (v uint8) { v = z.b[z.c] z.c++ return } // MARKER: for readn{2,3,4,8}, ensure you slice z.b completely so we get bounds error if past end. func (z *bytesDecReader) readn2() (bs [2]byte) { // copy(bs[:], z.b[z.c:z.c+2]) bs[1] = z.b[z.c+1] bs[0] = z.b[z.c] z.c += 2 return } func (z *bytesDecReader) readn3() (bs [4]byte) { // copy(bs[1:], z.b[z.c:z.c+3]) bs = okBytes3(z.b[z.c : z.c+3]) z.c += 3 return } func (z *bytesDecReader) readn4() (bs [4]byte) { // copy(bs[:], z.b[z.c:z.c+4]) bs = okBytes4(z.b[z.c : z.c+4]) z.c += 4 return } func (z *bytesDecReader) readn8() (bs [8]byte) { // copy(bs[:], z.b[z.c:z.c+8]) bs = okBytes8(z.b[z.c : z.c+8]) z.c += 8 return } func (z *bytesDecReader) jsonReadNum() []byte { z.c-- i := z.c LOOP: if i < uint(len(z.b)) && isNumberChar(z.b[i]) { i++ goto LOOP } z.c, i = i, z.c return z.b[i:z.c] } func (z *bytesDecReader) jsonReadAsisChars() []byte { i := z.c LOOP: token := z.b[i] i++ if token == '"' || token == '\\' { z.c, i = i, z.c return z.b[i:z.c] } goto LOOP } func (z *bytesDecReader) skipWhitespace() (token byte) { i := z.c LOOP: token = z.b[i] if isWhitespaceChar(token) { i++ goto LOOP } z.c = i + 1 return } func (z *bytesDecReader) readUntil(stop byte) (out []byte) { i := z.c LOOP: if z.b[i] == stop { out = z.b[z.c:i] z.c = i + 1 return } i++ goto LOOP } // -------------- type decRd struct { mtr bool // is maptype a known type? str bool // is slicetype a known type? be bool // is binary encoding js bool // is json handle jsms bool // is json handle, and MapKeyAsString cbor bool // is cbor handle bytes bool // is bytes reader bufio bool // is this a bufioDecReader? rb bytesDecReader ri *ioDecReader bi *bufioDecReader decReader } // From out benchmarking, we see the following in terms of performance: // // - interface calls // - branch that can inline what it calls // // the if/else-if/else block is expensive to inline. // Each node of this construct costs a lot and dominates the budget. // Best to only do an if fast-path else block (so fast-path is inlined). // This is irrespective of inlineExtraCallCost set in $GOROOT/src/cmd/compile/internal/gc/inl.go // // In decRd methods below, we delegate all IO functions into their own methods. // This allows for the inlining of the common path when z.bytes=true. // Go 1.12+ supports inlining methods with up to 1 inlined function (or 2 if no other constructs). // // However, up through Go 1.13, decRd's readXXX, skip and unreadXXX methods are not inlined. // Consequently, there is no benefit to do the xxxIO methods for decRd at this time. // Instead, we have a if/else-if/else block so that IO calls do not have to jump through // a second unnecessary function call. // // If golang inlining gets better and bytesDecReader methods can be inlined, // then we can revert to using these 2 functions so the bytesDecReader // methods are inlined and the IO paths call out to a function. // // decRd is designed to embed a decReader, and then re-implement some of the decReader // methods using a conditional branch. We only override the ones that have a bytes version // that is small enough to be inlined. We use ./run.sh -z to check. // Right now, only numread and readn1 can be inlined. func (z *decRd) numread() uint { if z.bytes { return z.rb.numread() } else if z.bufio { return z.bi.numread() } else { return z.ri.numread() } } func (z *decRd) readn1() (v uint8) { if z.bytes { // MARKER: manually inline, else this function is not inlined. // Keep in sync with bytesDecReader.readn1 // return z.rb.readn1() v = z.rb.b[z.rb.c] z.rb.c++ } else { v = z.readn1IO() } return } func (z *decRd) readn1IO() uint8 { if z.bufio { return z.bi.readn1() } return z.ri.readn1() } type devNullReader struct{} func (devNullReader) Read(p []byte) (int, error) { return 0, io.EOF } func (devNullReader) Close() error { return nil } func readFull(r io.Reader, bs []byte) (n uint, err error) { var nn int for n < uint(len(bs)) && err == nil { nn, err = r.Read(bs[n:]) if nn > 0 { if err == io.EOF { // leave EOF for next time err = nil } n += uint(nn) } } // do not do this below - it serves no purpose // if n != len(bs) && err == io.EOF { err = io.ErrUnexpectedEOF } return } var _ decReader = (*decRd)(nil) go-1.2.8/codec/register_ext.go000066400000000000000000000025431435255326100162510ustar00rootroot00000000000000// 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" // This file exists, so that the files for specific formats do not all import reflect. // This just helps us ensure that reflect package is isolated to a few files. // SetInterfaceExt sets an extension func (h *JsonHandle) SetInterfaceExt(rt reflect.Type, tag uint64, ext InterfaceExt) (err error) { return h.SetExt(rt, tag, makeExt(ext)) } // SetInterfaceExt sets an extension func (h *CborHandle) SetInterfaceExt(rt reflect.Type, tag uint64, ext InterfaceExt) (err error) { return h.SetExt(rt, tag, makeExt(ext)) } // SetBytesExt sets an extension func (h *MsgpackHandle) SetBytesExt(rt reflect.Type, tag uint64, ext BytesExt) (err error) { return h.SetExt(rt, tag, makeExt(ext)) } // SetBytesExt sets an extension func (h *SimpleHandle) SetBytesExt(rt reflect.Type, tag uint64, ext BytesExt) (err error) { return h.SetExt(rt, tag, makeExt(ext)) } // SetBytesExt sets an extension func (h *BincHandle) SetBytesExt(rt reflect.Type, tag uint64, ext BytesExt) (err error) { return h.SetExt(rt, tag, makeExt(ext)) } // func (h *XMLHandle) SetInterfaceExt(rt reflect.Type, tag uint64, ext InterfaceExt) (err error) { // return h.SetExt(rt, tag, &interfaceExtWrapper{InterfaceExt: ext}) // } go-1.2.8/codec/rpc.go000066400000000000000000000133071435255326100143310ustar00rootroot00000000000000// 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 ( "bufio" "errors" "io" "net/rpc" ) 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. RPCNoBuffer bool } // rpcCodec defines the struct members and common methods. type rpcCodec struct { c io.Closer r io.Reader w io.Writer f ioFlusher dec *Decoder enc *Encoder h Handle cls atomicClsErr } func newRPCCodec(conn io.ReadWriteCloser, h Handle) rpcCodec { return newRPCCodec2(conn, conn, conn, h) } func newRPCCodec2(r io.Reader, w io.Writer, c io.Closer, h Handle) rpcCodec { bh := h.getBasicHandle() // if the writer can flush, ensure we leverage it, else // we may hang waiting on read if write isn't flushed. // var f ioFlusher f, ok := w.(ioFlusher) if !bh.RPCNoBuffer { if bh.WriterBufferSize <= 0 { if !ok { // a flusher means there's already a buffer bw := bufio.NewWriter(w) f, w = bw, bw } } if bh.ReaderBufferSize <= 0 { if _, ok = w.(ioBuffered); !ok { r = bufio.NewReader(r) } } } return rpcCodec{ c: c, w: w, r: r, f: f, h: h, enc: NewEncoder(w, h), dec: NewDecoder(r, h), } } 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 { //If nil is passed in, we should read and discard if obj == nil { // return c.dec.Decode(&obj) err = c.dec.swallowErr() } else { err = c.dec.Decode(obj) } } return } func (c *rpcCodec) Close() (err error) { if c.c != nil { cls := c.cls.load() if !cls.closed { cls.err = c.c.Close() cls.closed = true 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.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)} } go-1.2.8/codec/shared_test.go000066400000000000000000000221051435255326100160460ustar00rootroot00000000000000// 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 // This file sets up the variables used, including testInitFns. // Each file should add initialization that should be performed // after flags are parsed. // // init is a multi-step process: // - setup vars (handled by init functions in each file) // - parse flags // - setup derived vars (handled by pre-init registered functions - registered in init function) // - post init (handled by post-init registered functions - registered in init function) // This way, no one has to manage carefully control the initialization // using file names, etc. // // Tests which require external dependencies need the -tag=x parameter. // They should be run as: // go test -tags=x -run=. // Benchmarks should also take this parameter, to include the sereal, xdr, etc. // To run against codecgen, etc, make sure you pass extra parameters. // Example usage: // go test "-tags=x codecgen" -bench=. // // To fully test everything: // go test -tags=x -benchtime=100ms -tv -bg -bi -brw -bu -v -run=. -bench=. // Handling flags // codec_test.go will define a set of global flags for testing, including: // - Use Reset // - Use IO reader/writer (vs direct bytes) // - Set Canonical // - Set InternStrings // - Use Symbols // // This way, we can test them all by running same set of tests with a different // set of flags. // // Following this, all the benchmarks will utilize flags set by codec_test.go // and will not redefine these "global" flags. import ( "bytes" "flag" "io" "io/ioutil" "log" "sync" ) // __DO_NOT_REMOVE__NEEDED_FOR_REPLACING__IMPORT_PATH__FOR_CODEC_BENCH__ type testHED struct { H Handle E *Encoder D *Decoder } type ioReaderWrapper struct { r io.Reader } func (x ioReaderWrapper) Read(p []byte) (n int, err error) { return x.r.Read(p) } type ioWriterWrapper struct { w io.Writer } func (x ioWriterWrapper) Write(p []byte) (n int, err error) { return x.w.Write(p) } var ( // testNoopH = NoopHandle(8) testMsgpackH = &MsgpackHandle{} testBincH = &BincHandle{} testSimpleH = &SimpleHandle{} testCborH = &CborHandle{} testJsonH = &JsonHandle{} testHandles []Handle testPreInitFns []func() testPostInitFns []func() testOnce sync.Once testHEDs []testHED ) // flag variables used by tests (and bench) var ( testVerbose bool //depth of 0 maps to ~400bytes json-encoded string, 1 maps to ~1400 bytes, etc //For depth>1, we likely trigger stack growth for encoders, making benchmarking unreliable. testDepth int testMaxInitLen int testUseReset bool testUseParallel bool testSkipIntf bool testUseIoEncDec int testUseIoWrapper bool testNumRepeatString int testRpcBufsize int testMapStringKeyOnly bool testBenchmarkNoConfig bool ) // variables that are not flags, but which can configure the handles var ( testEncodeOptions EncodeOptions testDecodeOptions DecodeOptions testRPCOptions RPCOptions ) func init() { log.SetOutput(ioutil.Discard) // don't allow things log to standard out/err testHEDs = make([]testHED, 0, 32) testHandles = append(testHandles, // testNoopH, testMsgpackH, testBincH, testSimpleH, testCborH, testJsonH) // JSON should do HTMLCharsAsIs by default testJsonH.HTMLCharsAsIs = true // testJsonH.InternString = true testInitFlags() benchInitFlags() } func testInitFlags() { var bIgnore bool // delete(testDecOpts.ExtFuncs, timeTyp) flag.BoolVar(&testVerbose, "tv", false, "Text Extra Verbose Logging if -v if set") flag.IntVar(&testUseIoEncDec, "ti", -1, "Use IO Reader/Writer for Marshal/Unmarshal ie >= 0") flag.BoolVar(&testUseIoWrapper, "tiw", false, "Wrap the IO Reader/Writer with a base pass-through reader/writer") flag.BoolVar(&testSkipIntf, "tf", false, "Skip Interfaces") flag.BoolVar(&testUseReset, "tr", false, "Use Reset") flag.BoolVar(&testUseParallel, "tp", false, "Run tests in parallel") flag.IntVar(&testNumRepeatString, "trs", 8, "Create string variables by repeating a string N times") flag.BoolVar(&bIgnore, "tm", true, "(Deprecated) Use Must(En|De)code") flag.IntVar(&testMaxInitLen, "tx", 0, "Max Init Len") flag.IntVar(&testDepth, "tsd", 0, "Test Struc Depth") flag.BoolVar(&testMapStringKeyOnly, "tsk", false, "use maps with string keys only") } func benchInitFlags() { flag.BoolVar(&testBenchmarkNoConfig, "bnc", false, "benchmarks: do not make configuration changes for fair benchmarking") // flags reproduced here for compatibility (duplicate some in testInitFlags) flag.BoolVar(&testMapStringKeyOnly, "bs", false, "benchmarks: use maps with string keys only") flag.IntVar(&testDepth, "bd", 1, "Benchmarks: Test Struc Depth") } func testHEDGet(h Handle) *testHED { for i := range testHEDs { v := &testHEDs[i] if v.H == h { return v } } testHEDs = append(testHEDs, testHED{h, NewEncoder(nil, h), NewDecoder(nil, h)}) return &testHEDs[len(testHEDs)-1] } func testReinit() { testOnce = sync.Once{} testHEDs = nil } func testInitAll() { // only parse it once. if !flag.Parsed() { flag.Parse() } for _, f := range testPreInitFns { f() } for _, f := range testPostInitFns { f() } } func testSharedCodecEncode(ts interface{}, bsIn []byte, fn func([]byte) *bytes.Buffer, h Handle, bh *BasicHandle, useMust bool) (bs []byte, err error) { // bs = make([]byte, 0, approxSize) var e *Encoder var buf *bytes.Buffer if testUseReset && !testUseParallel { e = testHEDGet(h).E } else { e = NewEncoder(nil, h) } var oldWriteBufferSize int if testUseIoEncDec >= 0 { buf = fn(bsIn) // set the encode options for using a buffer oldWriteBufferSize = bh.WriterBufferSize bh.WriterBufferSize = testUseIoEncDec if testUseIoWrapper { e.Reset(ioWriterWrapper{buf}) } else { e.Reset(buf) } } else { bs = bsIn e.ResetBytes(&bs) } if useMust { e.MustEncode(ts) } else { err = e.Encode(ts) } if testUseIoEncDec >= 0 { bs = buf.Bytes() bh.WriterBufferSize = oldWriteBufferSize } return } func testSharedCodecDecoder(bs []byte, h Handle, bh *BasicHandle) (d *Decoder, oldReadBufferSize int) { // var buf *bytes.Reader if testUseReset && !testUseParallel { d = testHEDGet(h).D } else { d = NewDecoder(nil, h) } if testUseIoEncDec >= 0 { buf := bytes.NewReader(bs) oldReadBufferSize = bh.ReaderBufferSize bh.ReaderBufferSize = testUseIoEncDec if testUseIoWrapper { d.Reset(ioReaderWrapper{buf}) } else { d.Reset(buf) } } else { d.ResetBytes(bs) } return } func testSharedCodecDecoderAfter(d *Decoder, oldReadBufferSize int, bh *BasicHandle) { if testUseIoEncDec >= 0 { bh.ReaderBufferSize = oldReadBufferSize } } func testSharedCodecDecode(bs []byte, ts interface{}, h Handle, bh *BasicHandle, useMust bool) (err error) { d, oldReadBufferSize := testSharedCodecDecoder(bs, h, bh) if useMust { d.MustDecode(ts) } else { err = d.Decode(ts) } testSharedCodecDecoderAfter(d, oldReadBufferSize, bh) return } // // --- functions below are used by both benchmarks and tests // // log message only when testVerbose = true (ie go test ... -- -tv). // // // // These are for intormational messages that do not necessarily // // help with diagnosing a failure, or which are too large. // func logTv(x interface{}, format string, args ...interface{}) { // if !testVerbose { // return // } // if t, ok := x.(testing.TB); ok { // only available from go 1.9 // t.Helper() // } // logT(x, format, args...) // } // // logT logs messages when running as go test -v // // // // Use it for diagnostics messages that help diagnost failure, // // and when the output is not too long ie shorter than like 100 characters. // // // // In general, any logT followed by failT should call this. // func logT(x interface{}, format string, args ...interface{}) { // if x == nil { // if len(format) == 0 || format[len(format)-1] != '\n' { // format = format + "\n" // } // fmt.Printf(format, args...) // return // } // if t, ok := x.(testing.TB); ok { // only available from go 1.9 // t.Helper() // t.Logf(format, args...) // } // } // func failTv(x testing.TB, args ...interface{}) { // x.Helper() // if testVerbose { // failTMsg(x, args...) // } // x.FailNow() // } // func failT(x testing.TB, args ...interface{}) { // x.Helper() // failTMsg(x, args...) // x.FailNow() // } // func failTMsg(x testing.TB, args ...interface{}) { // x.Helper() // if len(args) > 0 { // if format, ok := args[0].(string); ok { // logT(x, format, args[1:]...) // } else if len(args) == 1 { // logT(x, "%v", args[0]) // } else { // logT(x, "%v", args) // } // } // } // --- functions below are used only by benchmarks alone func fnBenchmarkByteBuf(bsIn []byte) (buf *bytes.Buffer) { // var buf bytes.Buffer // buf.Grow(approxSize) buf = bytes.NewBuffer(bsIn) buf.Truncate(0) return } // func benchFnCodecEncode(ts interface{}, bsIn []byte, h Handle) (bs []byte, err error) { // return testCodecEncode(ts, bsIn, fnBenchmarkByteBuf, h) // } // func benchFnCodecDecode(bs []byte, ts interface{}, h Handle) (err error) { // return testCodecDecode(bs, ts, h) // } go-1.2.8/codec/simple.go000066400000000000000000000437541435255326100150470ustar00rootroot00000000000000// 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" "reflect" "time" ) 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 4 (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 } type simpleEncDriver struct { noBuiltInTypes encDriverNoopContainerWriter encDriverNoState h *SimpleHandle // b [8]byte e Encoder } func (e *simpleEncDriver) encoder() *Encoder { return &e.e } func (e *simpleEncDriver) EncodeNil() { e.e.encWr.writen1(simpleVdNil) } func (e *simpleEncDriver) EncodeBool(b bool) { if e.h.EncZeroValuesAsNil && e.e.c != containerMapKey && !b { e.EncodeNil() return } if b { e.e.encWr.writen1(simpleVdTrue) } else { e.e.encWr.writen1(simpleVdFalse) } } func (e *simpleEncDriver) EncodeFloat32(f float32) { if e.h.EncZeroValuesAsNil && e.e.c != containerMapKey && f == 0.0 { e.EncodeNil() return } e.e.encWr.writen1(simpleVdFloat32) bigen.writeUint32(e.e.w(), math.Float32bits(f)) } func (e *simpleEncDriver) EncodeFloat64(f float64) { if e.h.EncZeroValuesAsNil && e.e.c != containerMapKey && f == 0.0 { e.EncodeNil() return } e.e.encWr.writen1(simpleVdFloat64) bigen.writeUint64(e.e.w(), math.Float64bits(f)) } func (e *simpleEncDriver) EncodeInt(v int64) { if v < 0 { e.encUint(uint64(-v), simpleVdNegInt) } else { e.encUint(uint64(v), simpleVdPosInt) } } func (e *simpleEncDriver) EncodeUint(v uint64) { e.encUint(v, simpleVdPosInt) } func (e *simpleEncDriver) encUint(v uint64, bd uint8) { if e.h.EncZeroValuesAsNil && e.e.c != containerMapKey && v == 0 { e.EncodeNil() return } if v <= math.MaxUint8 { e.e.encWr.writen2(bd, uint8(v)) } else if v <= math.MaxUint16 { e.e.encWr.writen1(bd + 1) bigen.writeUint16(e.e.w(), uint16(v)) } else if v <= math.MaxUint32 { e.e.encWr.writen1(bd + 2) bigen.writeUint32(e.e.w(), uint32(v)) } else { // if v <= math.MaxUint64 { e.e.encWr.writen1(bd + 3) bigen.writeUint64(e.e.w(), v) } } func (e *simpleEncDriver) encLen(bd byte, length int) { if length == 0 { e.e.encWr.writen1(bd) } else if length <= math.MaxUint8 { e.e.encWr.writen1(bd + 1) e.e.encWr.writen1(uint8(length)) } else if length <= math.MaxUint16 { e.e.encWr.writen1(bd + 2) bigen.writeUint16(e.e.w(), uint16(length)) } else if int64(length) <= math.MaxUint32 { e.e.encWr.writen1(bd + 3) bigen.writeUint32(e.e.w(), uint32(length)) } else { e.e.encWr.writen1(bd + 4) bigen.writeUint64(e.e.w(), uint64(length)) } } func (e *simpleEncDriver) 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 e.e.sideEncode(v, basetype, &bs) } else { bs = ext.WriteExt(v) } if bs == nil { e.EncodeNil() goto END } e.encodeExtPreamble(uint8(xtag), len(bs)) e.e.encWr.writeb(bs) END: if ext == SelfExt { e.e.blist.put(bs) if !byteSliceSameData(bs0, bs) { e.e.blist.put(bs0) } } } func (e *simpleEncDriver) EncodeRawExt(re *RawExt) { e.encodeExtPreamble(uint8(re.Tag), len(re.Data)) e.e.encWr.writeb(re.Data) } func (e *simpleEncDriver) encodeExtPreamble(xtag byte, length int) { e.encLen(simpleVdExt, length) e.e.encWr.writen1(xtag) } func (e *simpleEncDriver) WriteArrayStart(length int) { e.encLen(simpleVdArray, length) } func (e *simpleEncDriver) WriteMapStart(length int) { e.encLen(simpleVdMap, length) } func (e *simpleEncDriver) 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.e.encWr.writestr(v) } func (e *simpleEncDriver) EncodeStringBytesRaw(v []byte) { // if e.h.EncZeroValuesAsNil && e.c != containerMapKey && v == nil { if v == nil { e.EncodeNil() return } e.encLen(simpleVdByteArray, len(v)) e.e.encWr.writeb(v) } func (e *simpleEncDriver) EncodeTime(t time.Time) { // if e.h.EncZeroValuesAsNil && e.c != containerMapKey && t.IsZero() { if t.IsZero() { e.EncodeNil() return } v, err := t.MarshalBinary() e.e.onerror(err) e.e.encWr.writen2(simpleVdTime, uint8(len(v))) e.e.encWr.writeb(v) } //------------------------------------ type simpleDecDriver struct { h *SimpleHandle bdAndBdread _ bool noBuiltInTypes decDriverNoopContainerReader decDriverNoopNumberHelper d Decoder } func (d *simpleDecDriver) decoder() *Decoder { return &d.d } func (d *simpleDecDriver) descBd() string { return sprintf("%v (%s)", d.bd, simpledesc(d.bd)) } func (d *simpleDecDriver) readNextBd() { d.bd = d.d.decRd.readn1() d.bdRead = true } func (d *simpleDecDriver) advanceNil() (null bool) { if !d.bdRead { d.readNextBd() } if d.bd == simpleVdNil { d.bdRead = false return true // null = true } return } func (d *simpleDecDriver) 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) TryNil() bool { return d.advanceNil() } func (d *simpleDecDriver) decFloat() (f float64, ok bool) { ok = true switch d.bd { case simpleVdFloat32: f = float64(math.Float32frombits(bigen.Uint32(d.d.decRd.readn4()))) case simpleVdFloat64: f = math.Float64frombits(bigen.Uint64(d.d.decRd.readn8())) default: ok = false } return } func (d *simpleDecDriver) decInteger() (ui uint64, neg, ok bool) { ok = true switch d.bd { case simpleVdPosInt: ui = uint64(d.d.decRd.readn1()) case simpleVdPosInt + 1: ui = uint64(bigen.Uint16(d.d.decRd.readn2())) case simpleVdPosInt + 2: ui = uint64(bigen.Uint32(d.d.decRd.readn4())) case simpleVdPosInt + 3: ui = uint64(bigen.Uint64(d.d.decRd.readn8())) case simpleVdNegInt: ui = uint64(d.d.decRd.readn1()) neg = true case simpleVdNegInt + 1: ui = uint64(bigen.Uint16(d.d.decRd.readn2())) neg = true case simpleVdNegInt + 2: ui = uint64(bigen.Uint32(d.d.decRd.readn4())) neg = true case simpleVdNegInt + 3: ui = uint64(bigen.Uint64(d.d.decRd.readn8())) neg = true default: ok = false // d.d.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 { // d.d.errorf("decIntAny: Integer out of range for signed int64: %v", ui) // return // } return } func (d *simpleDecDriver) DecodeInt64() (i int64) { if d.advanceNil() { return } i = decNegintPosintFloatNumberHelper{&d.d}.int64(d.decInteger()) d.bdRead = false return } func (d *simpleDecDriver) DecodeUint64() (ui uint64) { if d.advanceNil() { return } ui = decNegintPosintFloatNumberHelper{&d.d}.uint64(d.decInteger()) d.bdRead = false return } func (d *simpleDecDriver) DecodeFloat64() (f float64) { if d.advanceNil() { return } f = decNegintPosintFloatNumberHelper{&d.d}.float64(d.decFloat()) d.bdRead = false return } // bool can be decoded from bool only (single byte). func (d *simpleDecDriver) DecodeBool() (b bool) { if d.advanceNil() { return } if d.bd == simpleVdFalse { } else if d.bd == simpleVdTrue { b = true } else { d.d.errorf("cannot decode bool - %s: %x", msgBadDesc, d.bd) } d.bdRead = false return } func (d *simpleDecDriver) ReadMapStart() (length int) { if d.advanceNil() { return containerLenNil } d.bdRead = false return d.decLen() } func (d *simpleDecDriver) ReadArrayStart() (length int) { if d.advanceNil() { return containerLenNil } d.bdRead = false return d.decLen() } func (d *simpleDecDriver) uint2Len(ui uint64) int { if chkOvf.Uint(ui, intBitsize) { d.d.errorf("overflow integer: %v", ui) } return int(ui) } func (d *simpleDecDriver) decLen() int { switch d.bd & 7 { // d.bd % 8 { case 0: return 0 case 1: return int(d.d.decRd.readn1()) case 2: return int(bigen.Uint16(d.d.decRd.readn2())) case 3: return d.uint2Len(uint64(bigen.Uint32(d.d.decRd.readn4()))) case 4: return d.uint2Len(bigen.Uint64(d.d.decRd.readn8())) } d.d.errorf("cannot read length: bd%%8 must be in range 0..4. Got: %d", d.bd%8) return -1 } func (d *simpleDecDriver) DecodeStringAsBytes() (s []byte) { return d.DecodeBytes(nil) } func (d *simpleDecDriver) DecodeBytes(bs []byte) (bsOut []byte) { d.d.decByteState = decByteStateNone if d.advanceNil() { return } // check if an "array" of uint8's (see ContainerType for how to infer if an array) if d.bd >= simpleVdArray && d.bd <= simpleVdMap+4 { if bs == nil { d.d.decByteState = decByteStateReuseBuf bs = d.d.b[:] } slen := d.ReadArrayStart() var changed bool if bs, changed = usableByteSlice(bs, slen); changed { d.d.decByteState = decByteStateNone } 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))) } return bs } clen := d.decLen() d.bdRead = false if d.d.zerocopy() { d.d.decByteState = decByteStateZerocopy return d.d.decRd.rb.readx(uint(clen)) } if bs == nil { d.d.decByteState = decByteStateReuseBuf bs = d.d.b[:] } return decByteSlice(d.d.r(), clen, d.d.h.MaxInitLen, bs) } func (d *simpleDecDriver) DecodeTime() (t time.Time) { if d.advanceNil() { return } if d.bd != simpleVdTime { d.d.errorf("invalid descriptor for time.Time - expect 0x%x, received 0x%x", simpleVdTime, d.bd) } d.bdRead = false clen := uint(d.d.decRd.readn1()) b := d.d.decRd.readx(clen) d.d.onerror((&t).UnmarshalBinary(b)) return } func (d *simpleDecDriver) DecodeExt(rv interface{}, basetype reflect.Type, xtag uint64, ext Ext) { if xtag > 0xff { d.d.errorf("ext: tag must be <= 0xff; got: %v", xtag) } if d.advanceNil() { return } xbs, realxtag1, zerocopy := d.decodeExtV(ext != nil, uint8(xtag)) realxtag := uint64(realxtag1) if ext == nil { re := rv.(*RawExt) re.Tag = realxtag re.setData(xbs, zerocopy) } else if ext == SelfExt { d.d.sideDecode(rv, basetype, xbs) } else { ext.ReadExt(rv, xbs) } } func (d *simpleDecDriver) decodeExtV(verifyTag bool, tag byte) (xbs []byte, xtag byte, zerocopy bool) { switch d.bd { case simpleVdExt, simpleVdExt + 1, simpleVdExt + 2, simpleVdExt + 3, simpleVdExt + 4: l := d.decLen() xtag = d.d.decRd.readn1() if verifyTag && xtag != tag { d.d.errorf("wrong extension tag. Got %b. Expecting: %v", xtag, tag) } if d.d.bytes { xbs = d.d.decRd.rb.readx(uint(l)) zerocopy = true } else { xbs = decByteSlice(d.d.r(), l, d.d.h.MaxInitLen, d.d.b[:]) } case simpleVdByteArray, simpleVdByteArray + 1, simpleVdByteArray + 2, simpleVdByteArray + 3, simpleVdByteArray + 4: xbs = d.DecodeBytes(nil) default: d.d.errorf("ext - %s - expecting extensions/bytearray, got: 0x%x", msgBadDesc, d.bd) } d.bdRead = false return } func (d *simpleDecDriver) 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.stringZC(d.DecodeStringAsBytes()) case simpleVdByteArray, simpleVdByteArray + 1, simpleVdByteArray + 2, simpleVdByteArray + 3, simpleVdByteArray + 4: d.d.fauxUnionReadRawBytes(false) case simpleVdExt, simpleVdExt + 1, simpleVdExt + 2, simpleVdExt + 3, simpleVdExt + 4: n.v = valueTypeExt l := d.decLen() n.u = uint64(d.d.decRd.readn1()) if d.d.bytes { n.l = d.d.decRd.rb.readx(uint(l)) } else { n.l = decByteSlice(d.d.r(), l, d.d.h.MaxInitLen, d.d.b[:]) } 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: d.d.errorf("cannot infer value - %s 0x%x", msgBadDesc, d.bd) } if !decodeFurther { d.bdRead = false } } func (d *simpleDecDriver) nextValueBytes(v0 []byte) (v []byte) { if !d.bdRead { d.readNextBd() } v = v0 var h = decNextValueBytesHelper{d: &d.d} var cursor = d.d.rb.c - 1 h.append1(&v, d.bd) v = d.nextValueBytesBdReadR(v) d.bdRead = false h.bytesRdV(&v, cursor) return } func (d *simpleDecDriver) nextValueBytesR(v0 []byte) (v []byte) { d.readNextBd() v = v0 var h = decNextValueBytesHelper{d: &d.d} h.append1(&v, d.bd) return d.nextValueBytesBdReadR(v) } func (d *simpleDecDriver) nextValueBytesBdReadR(v0 []byte) (v []byte) { v = v0 var h = decNextValueBytesHelper{d: &d.d} c := d.bd var length uint switch c { case simpleVdNil, simpleVdFalse, simpleVdTrue, simpleVdString, simpleVdByteArray: // pass case simpleVdPosInt, simpleVdNegInt: h.append1(&v, d.d.decRd.readn1()) case simpleVdPosInt + 1, simpleVdNegInt + 1: h.appendN(&v, d.d.decRd.readx(2)...) case simpleVdPosInt + 2, simpleVdNegInt + 2, simpleVdFloat32: h.appendN(&v, d.d.decRd.readx(4)...) case simpleVdPosInt + 3, simpleVdNegInt + 3, simpleVdFloat64: h.appendN(&v, d.d.decRd.readx(8)...) case simpleVdTime: c = d.d.decRd.readn1() h.append1(&v, c) h.appendN(&v, d.d.decRd.readx(uint(c))...) default: switch c & 7 { // c % 8 { case 0: length = 0 case 1: b := d.d.decRd.readn1() length = uint(b) h.append1(&v, b) case 2: x := d.d.decRd.readn2() length = uint(bigen.Uint16(x)) h.appendN(&v, x[:]...) case 3: x := d.d.decRd.readn4() length = uint(bigen.Uint32(x)) h.appendN(&v, x[:]...) case 4: x := d.d.decRd.readn8() length = uint(bigen.Uint64(x)) h.appendN(&v, 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) { d.d.errorf("cannot infer value - %s 0x%x", msgBadDesc, c) } if bExt { h.append1(&v, d.d.decRd.readn1()) // tag } if length == 0 { break } if bArray { for i := uint(0); i < length; i++ { v = d.nextValueBytesR(v) } } else if bMap { for i := uint(0); i < length; i++ { v = d.nextValueBytesR(v) v = d.nextValueBytesR(v) } } else { h.appendN(&v, d.d.decRd.readx(length)...) } } 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 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) } func (h *SimpleHandle) newEncDriver() encDriver { var e = &simpleEncDriver{h: h} e.e.e = e e.e.init(h) e.reset() return e } func (h *SimpleHandle) newDecDriver() decDriver { d := &simpleDecDriver{h: h} d.d.d = d d.d.init(h) d.reset() return d } var _ decDriver = (*simpleDecDriver)(nil) var _ encDriver = (*simpleEncDriver)(nil) go-1.2.8/codec/sort-slice.generated.go000066400000000000000000000077441435255326100175760ustar00rootroot00000000000000// 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 sort-slice.go.tmpl - DO NOT EDIT. package codec import ( "bytes" "reflect" "time" ) type stringSlice []string func (p stringSlice) Len() int { return len(p) } func (p stringSlice) Swap(i, j int) { p[uint(i)], p[uint(j)] = p[uint(j)], p[uint(i)] } func (p stringSlice) Less(i, j int) bool { return p[uint(i)] < p[uint(j)] } type uint8Slice []uint8 func (p uint8Slice) Len() int { return len(p) } func (p uint8Slice) Swap(i, j int) { p[uint(i)], p[uint(j)] = p[uint(j)], p[uint(i)] } func (p uint8Slice) Less(i, j int) bool { return p[uint(i)] < p[uint(j)] } type uint64Slice []uint64 func (p uint64Slice) Len() int { return len(p) } func (p uint64Slice) Swap(i, j int) { p[uint(i)], p[uint(j)] = p[uint(j)], p[uint(i)] } func (p uint64Slice) Less(i, j int) bool { return p[uint(i)] < p[uint(j)] } type intSlice []int func (p intSlice) Len() int { return len(p) } func (p intSlice) Swap(i, j int) { p[uint(i)], p[uint(j)] = p[uint(j)], p[uint(i)] } func (p intSlice) Less(i, j int) bool { return p[uint(i)] < p[uint(j)] } type int32Slice []int32 func (p int32Slice) Len() int { return len(p) } func (p int32Slice) Swap(i, j int) { p[uint(i)], p[uint(j)] = p[uint(j)], p[uint(i)] } func (p int32Slice) Less(i, j int) bool { return p[uint(i)] < p[uint(j)] } type stringRv struct { v string r reflect.Value } type stringRvSlice []stringRv func (p stringRvSlice) Len() int { return len(p) } func (p stringRvSlice) Swap(i, j int) { p[uint(i)], p[uint(j)] = p[uint(j)], p[uint(i)] } func (p stringRvSlice) Less(i, j int) bool { return p[uint(i)].v < p[uint(j)].v } type stringIntf struct { v string i interface{} } type stringIntfSlice []stringIntf func (p stringIntfSlice) Len() int { return len(p) } func (p stringIntfSlice) Swap(i, j int) { p[uint(i)], p[uint(j)] = p[uint(j)], p[uint(i)] } func (p stringIntfSlice) Less(i, j int) bool { return p[uint(i)].v < p[uint(j)].v } type float64Rv struct { v float64 r reflect.Value } type float64RvSlice []float64Rv func (p float64RvSlice) Len() int { return len(p) } func (p float64RvSlice) Swap(i, j int) { p[uint(i)], p[uint(j)] = p[uint(j)], p[uint(i)] } func (p float64RvSlice) Less(i, j int) bool { return p[uint(i)].v < p[uint(j)].v || isNaN64(p[uint(i)].v) && !isNaN64(p[uint(j)].v) } type uint64Rv struct { v uint64 r reflect.Value } type uint64RvSlice []uint64Rv func (p uint64RvSlice) Len() int { return len(p) } func (p uint64RvSlice) Swap(i, j int) { p[uint(i)], p[uint(j)] = p[uint(j)], p[uint(i)] } func (p uint64RvSlice) Less(i, j int) bool { return p[uint(i)].v < p[uint(j)].v } type int64Rv struct { v int64 r reflect.Value } type int64RvSlice []int64Rv func (p int64RvSlice) Len() int { return len(p) } func (p int64RvSlice) Swap(i, j int) { p[uint(i)], p[uint(j)] = p[uint(j)], p[uint(i)] } func (p int64RvSlice) Less(i, j int) bool { return p[uint(i)].v < p[uint(j)].v } type timeRv struct { v time.Time r reflect.Value } type timeRvSlice []timeRv func (p timeRvSlice) Len() int { return len(p) } func (p timeRvSlice) Swap(i, j int) { p[uint(i)], p[uint(j)] = p[uint(j)], p[uint(i)] } func (p timeRvSlice) Less(i, j int) bool { return p[uint(i)].v.Before(p[uint(j)].v) } type bytesRv struct { v []byte r reflect.Value } type bytesRvSlice []bytesRv func (p bytesRvSlice) Len() int { return len(p) } func (p bytesRvSlice) Swap(i, j int) { p[uint(i)], p[uint(j)] = p[uint(j)], p[uint(i)] } func (p bytesRvSlice) Less(i, j int) bool { return bytes.Compare(p[uint(i)].v, p[uint(j)].v) == -1 } type bytesIntf struct { v []byte i interface{} } type bytesIntfSlice []bytesIntf func (p bytesIntfSlice) Len() int { return len(p) } func (p bytesIntfSlice) Swap(i, j int) { p[uint(i)], p[uint(j)] = p[uint(j)], p[uint(i)] } func (p bytesIntfSlice) Less(i, j int) bool { return bytes.Compare(p[uint(i)].v, p[uint(j)].v) == -1 } go-1.2.8/codec/sort-slice.go.tmpl000066400000000000000000000037231435255326100166050ustar00rootroot00000000000000// 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 sort-slice.go.tmpl - DO NOT EDIT. {{/* xxxSlice xxxIntf xxxIntfSlice xxxRv xxxRvSlice I'm now going to create them for - sortables - sortablesplus With the parameters passed in sortables or sortablesplus, 'time, 'bytes' are special, and correspond to time.Time and []byte respectively. */}} package codec import ( "time" "reflect" "bytes" ) {{/* func init() { _ = time.Unix } */}} {{define "T"}} func (p {{ .Type }}) Len() int { return len(p) } func (p {{ .Type }}) Swap(i, j int) { p[uint(i)], p[uint(j)] = p[uint(j)], p[uint(i)] } func (p {{ .Type }}) Less(i, j int) bool { {{ if eq .Kind "bool" }} return !p[uint(i)]{{.V}} && p[uint(j)]{{.V}} {{ else if eq .Kind "float32" }} return p[uint(i)]{{.V}} < p[uint(j)]{{.V}} || isNaN32(p[uint(i)]{{.V}}) && !isNaN32(p[uint(j)]{{.V}}) {{ else if eq .Kind "float64" }} return p[uint(i)]{{.V}} < p[uint(j)]{{.V}} || isNaN64(p[uint(i)]{{.V}}) && !isNaN64(p[uint(j)]{{.V}}) {{ else if eq .Kind "time" }} return p[uint(i)]{{.V}}.Before(p[uint(j)]{{.V}}) {{ else if eq .Kind "bytes" }} return bytes.Compare(p[uint(i)]{{.V}}, p[uint(j)]{{.V}}) == -1 {{ else }} return p[uint(i)]{{.V}} < p[uint(j)]{{.V}} {{ end -}} } {{end}} {{range $i, $v := sortables }}{{ $t := tshort $v }} type {{ $v }}Slice []{{ $t }} {{template "T" args "Kind" $v "Type" (print $v "Slice") "V" ""}} {{end}} {{range $i, $v := sortablesplus }}{{ $t := tshort $v }} type {{ $v }}Rv struct { v {{ $t }} r reflect.Value } type {{ $v }}RvSlice []{{ $v }}Rv {{template "T" args "Kind" $v "Type" (print $v "RvSlice") "V" ".v"}} {{if eq $v "bytes" "string" -}} type {{ $v }}Intf struct { v {{ $t }} i interface{} } type {{ $v }}IntfSlice []{{ $v }}Intf {{template "T" args "Kind" $v "Type" (print $v "IntfSlice") "V" ".v"}} {{end}} {{end}} go-1.2.8/codec/test-cbor-goldens.json000066400000000000000000000242111435255326100174400ustar00rootroot00000000000000[ { "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 } } ] go-1.2.8/codec/test.py000077500000000000000000000107001435255326100145440ustar00rootroot00000000000000#!/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:]) go-1.2.8/codec/values_codecgen_generated_test.go000066400000000000000000016764511435255326100217700ustar00rootroot00000000000000//go:build go1.6 && (codecgen || generated) // +build go1.6 // +build codecgen generated // Code generated by codecgen - DO NOT EDIT. package codec import ( "errors" "runtime" "sort" "strconv" "time" ) const ( // ----- content types ---- codecSelferCcUTF819780 = 1 codecSelferCcRAW19780 = 255 // ----- value types used ---- codecSelferValueTypeArray19780 = 10 codecSelferValueTypeMap19780 = 9 codecSelferValueTypeString19780 = 6 codecSelferValueTypeInt19780 = 2 codecSelferValueTypeUint19780 = 3 codecSelferValueTypeFloat19780 = 4 codecSelferValueTypeNil19780 = 1 codecSelferBitsize19780 = uint8(32 << (^uint(0) >> 63)) codecSelferDecContainerLenNil19780 = -2147483648 ) var ( errCodecSelferOnlyMapOrArrayEncodeToStruct19780 = errors.New(`only encoded map or array can be decoded into a struct`) _ sort.Interface = nil ) type codecSelfer19780 struct{} func codecSelfer19780False() bool { return false } func codecSelfer19780True() bool { return true } type codecSelfer19780stringSlice []string func (p codecSelfer19780stringSlice) Len() int { return len(p) } func (p codecSelfer19780stringSlice) Swap(i, j int) { p[uint(i)], p[uint(j)] = p[uint(j)], p[uint(i)] } func (p codecSelfer19780stringSlice) Less(i, j int) bool { return p[uint(i)] < p[uint(j)] } type codecSelfer19780uint64Slice []uint64 func (p codecSelfer19780uint64Slice) Len() int { return len(p) } func (p codecSelfer19780uint64Slice) Swap(i, j int) { p[uint(i)], p[uint(j)] = p[uint(j)], p[uint(i)] } func (p codecSelfer19780uint64Slice) Less(i, j int) bool { return p[uint(i)] < p[uint(j)] } type codecSelfer19780int64Slice []int64 func (p codecSelfer19780int64Slice) Len() int { return len(p) } func (p codecSelfer19780int64Slice) Swap(i, j int) { p[uint(i)], p[uint(j)] = p[uint(j)], p[uint(i)] } func (p codecSelfer19780int64Slice) Less(i, j int) bool { return p[uint(i)] < p[uint(j)] } type codecSelfer19780float64Slice []float64 func (p codecSelfer19780float64Slice) Len() int { return len(p) } func (p codecSelfer19780float64Slice) Swap(i, j int) { p[uint(i)], p[uint(j)] = p[uint(j)], p[uint(i)] } func (p codecSelfer19780float64Slice) Less(i, j int) bool { return p[uint(i)] < p[uint(j)] } func init() { if GenVersion != 25 { _, file, _, _ := runtime.Caller(0) ver := strconv.FormatInt(int64(GenVersion), 10) panic(errors.New("codecgen version mismatch: current: 25, need " + ver + ". Re-generate file: " + file)) } if false { // reference the types, but skip this branch at build/run time var _ time.Time } } func (wrapSliceUint64) codecSelferViaCodecgen() {} func (x wrapSliceUint64) CodecEncodeSelf(e *Encoder) { var h codecSelfer19780 z, r := GenHelper().Encoder(e) _, _, _ = h, z, r if x == nil { r.EncodeNil() } else { z.F.EncSliceUint64V(([]uint64)(x), e) } // end block: if x slice == nil } func (x *wrapSliceUint64) CodecDecodeSelf(d *Decoder) { var h codecSelfer19780 z, r := GenHelper().Decoder(d) _, _, _ = h, z, r z.F.DecSliceUint64X((*[]uint64)(x), d) } func (wrapSliceString) codecSelferViaCodecgen() {} func (x wrapSliceString) CodecEncodeSelf(e *Encoder) { var h codecSelfer19780 z, r := GenHelper().Encoder(e) _, _, _ = h, z, r if x == nil { r.EncodeNil() } else { z.F.EncSliceStringV(([]string)(x), e) } // end block: if x slice == nil } func (x *wrapSliceString) CodecDecodeSelf(d *Decoder) { var h codecSelfer19780 z, r := GenHelper().Decoder(d) _, _, _ = h, z, r z.F.DecSliceStringX((*[]string)(x), d) } func (wrapUint64) codecSelferViaCodecgen() {} func (x wrapUint64) CodecEncodeSelf(e *Encoder) { var h codecSelfer19780 z, r := GenHelper().Encoder(e) _, _, _ = h, z, r r.EncodeUint(uint64(x)) } func (x *wrapUint64) CodecDecodeSelf(d *Decoder) { var h codecSelfer19780 z, r := GenHelper().Decoder(d) _, _, _ = h, z, r *x = (wrapUint64)(r.DecodeUint64()) } func (wrapString) codecSelferViaCodecgen() {} func (x wrapString) CodecEncodeSelf(e *Encoder) { var h codecSelfer19780 z, r := GenHelper().Encoder(e) _, _, _ = h, z, r r.EncodeString(string(x)) } func (x *wrapString) CodecDecodeSelf(d *Decoder) { var h codecSelfer19780 z, r := GenHelper().Decoder(d) _, _, _ = h, z, r *x = (wrapString)(z.DecStringZC(r.DecodeStringAsBytes())) } func (wrapUint64Slice) codecSelferViaCodecgen() {} func (x wrapUint64Slice) CodecEncodeSelf(e *Encoder) { var h codecSelfer19780 z, r := GenHelper().Encoder(e) _, _, _ = h, z, r if x == nil { r.EncodeNil() } else { h.encwrapUint64Slice((wrapUint64Slice)(x), e) } // end block: if x slice == nil } func (x *wrapUint64Slice) CodecDecodeSelf(d *Decoder) { var h codecSelfer19780 z, r := GenHelper().Decoder(d) _, _, _ = h, z, r h.decwrapUint64Slice((*wrapUint64Slice)(x), d) } func (wrapStringSlice) codecSelferViaCodecgen() {} func (x wrapStringSlice) CodecEncodeSelf(e *Encoder) { var h codecSelfer19780 z, r := GenHelper().Encoder(e) _, _, _ = h, z, r if x == nil { r.EncodeNil() } else { h.encwrapStringSlice((wrapStringSlice)(x), e) } // end block: if x slice == nil } func (x *wrapStringSlice) CodecDecodeSelf(d *Decoder) { var h codecSelfer19780 z, r := GenHelper().Decoder(d) _, _, _ = h, z, r h.decwrapStringSlice((*wrapStringSlice)(x), d) } func (stringUint64T) codecSelferViaCodecgen() {} func (x *stringUint64T) CodecEncodeSelf(e *Encoder) { var h codecSelfer19780 z, r := GenHelper().Encoder(e) _, _, _ = h, z, r if z.EncBasicHandle().CheckCircularRef { z.EncEncode(x) return } if x == nil { r.EncodeNil() } else { yy2arr2 := z.EncBasicHandle().StructToArray _ = yy2arr2 const yyr2 bool = false // struct tag has 'toArray' if yyr2 || yy2arr2 { z.EncWriteArrayStart(2) z.EncWriteArrayElem() r.EncodeString(string(x.S)) z.EncWriteArrayElem() r.EncodeUint(uint64(x.U)) z.EncWriteArrayEnd() } else { z.EncWriteMapStart(2) if z.EncBasicHandle().Canonical { z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"S\"") } else { r.EncodeString(`S`) } z.EncWriteMapElemValue() r.EncodeString(string(x.S)) z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"U\"") } else { r.EncodeString(`U`) } z.EncWriteMapElemValue() r.EncodeUint(uint64(x.U)) } else { z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"S\"") } else { r.EncodeString(`S`) } z.EncWriteMapElemValue() r.EncodeString(string(x.S)) z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"U\"") } else { r.EncodeString(`U`) } z.EncWriteMapElemValue() r.EncodeUint(uint64(x.U)) } z.EncWriteMapEnd() } } } func (x *stringUint64T) CodecDecodeSelf(d *Decoder) { var h codecSelfer19780 z, r := GenHelper().Decoder(d) _, _, _ = h, z, r yyct2 := r.ContainerType() if yyct2 == codecSelferValueTypeNil19780 { *(x) = stringUint64T{} } else if yyct2 == codecSelferValueTypeMap19780 { yyl2 := z.DecReadMapStart() if yyl2 == 0 { } else { x.codecDecodeSelfFromMap(yyl2, d) } z.DecReadMapEnd() } else if yyct2 == codecSelferValueTypeArray19780 { yyl2 := z.DecReadArrayStart() if yyl2 != 0 { x.codecDecodeSelfFromArray(yyl2, d) } z.DecReadArrayEnd() } else { panic(errCodecSelferOnlyMapOrArrayEncodeToStruct19780) } } func (x *stringUint64T) codecDecodeSelfFromMap(l int, d *Decoder) { var h codecSelfer19780 z, r := GenHelper().Decoder(d) _, _, _ = h, z, r var yyhl3 bool = l >= 0 for yyj3 := 0; ; yyj3++ { if yyhl3 { if yyj3 >= l { break } } else { if z.DecCheckBreak() { break } } z.DecReadMapElemKey() yys3 := r.DecodeStringAsBytes() z.DecReadMapElemValue() switch string(yys3) { case "S": x.S = (string)(z.DecStringZC(r.DecodeStringAsBytes())) case "U": x.U = (uint64)(r.DecodeUint64()) default: z.DecStructFieldNotFound(-1, string(yys3)) } // end switch yys3 } // end for yyj3 } func (x *stringUint64T) codecDecodeSelfFromArray(l int, d *Decoder) { var h codecSelfer19780 z, r := GenHelper().Decoder(d) _, _, _ = h, z, r var yyj6 int var yyb6 bool var yyhl6 bool = l >= 0 yyj6++ if yyhl6 { yyb6 = yyj6 > l } else { yyb6 = z.DecCheckBreak() } if yyb6 { z.DecReadArrayEnd() return } z.DecReadArrayElem() x.S = (string)(z.DecStringZC(r.DecodeStringAsBytes())) yyj6++ if yyhl6 { yyb6 = yyj6 > l } else { yyb6 = z.DecCheckBreak() } if yyb6 { z.DecReadArrayEnd() return } z.DecReadArrayElem() x.U = (uint64)(r.DecodeUint64()) for { yyj6++ if yyhl6 { yyb6 = yyj6 > l } else { yyb6 = z.DecCheckBreak() } if yyb6 { break } z.DecReadArrayElem() z.DecStructFieldNotFound(yyj6-1, "") } } func (x *stringUint64T) IsCodecEmpty() bool { return !(x.S != "" || x.U != 0 || false) } func (AnonInTestStrucSlim) codecSelferViaCodecgen() {} func (x *AnonInTestStrucSlim) CodecEncodeSelf(e *Encoder) { var h codecSelfer19780 z, r := GenHelper().Encoder(e) _, _, _ = h, z, r if z.EncBasicHandle().CheckCircularRef { z.EncEncode(x) return } if x == nil { r.EncodeNil() } else { yy2arr2 := z.EncBasicHandle().StructToArray _ = yy2arr2 const yyr2 bool = false // struct tag has 'toArray' var yyn4 bool = x.P == nil if yyr2 || yy2arr2 { z.EncWriteArrayStart(2) z.EncWriteArrayElem() r.EncodeString(string(x.S)) if yyn4 { z.EncWriteArrayElem() r.EncodeNil() } else { z.EncWriteArrayElem() yy6 := *x.P r.EncodeString(string(yy6)) } z.EncWriteArrayEnd() } else { z.EncWriteMapStart(2) if z.EncBasicHandle().Canonical { z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"P\"") } else { r.EncodeString(`P`) } z.EncWriteMapElemValue() if yyn4 { r.EncodeNil() } else { yy8 := *x.P r.EncodeString(string(yy8)) } z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"S\"") } else { r.EncodeString(`S`) } z.EncWriteMapElemValue() r.EncodeString(string(x.S)) } else { z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"S\"") } else { r.EncodeString(`S`) } z.EncWriteMapElemValue() r.EncodeString(string(x.S)) z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"P\"") } else { r.EncodeString(`P`) } z.EncWriteMapElemValue() if yyn4 { r.EncodeNil() } else { yy12 := *x.P r.EncodeString(string(yy12)) } } z.EncWriteMapEnd() } } } func (x *AnonInTestStrucSlim) CodecDecodeSelf(d *Decoder) { var h codecSelfer19780 z, r := GenHelper().Decoder(d) _, _, _ = h, z, r yyct2 := r.ContainerType() if yyct2 == codecSelferValueTypeNil19780 { *(x) = AnonInTestStrucSlim{} } else if yyct2 == codecSelferValueTypeMap19780 { yyl2 := z.DecReadMapStart() if yyl2 == 0 { } else { x.codecDecodeSelfFromMap(yyl2, d) } z.DecReadMapEnd() } else if yyct2 == codecSelferValueTypeArray19780 { yyl2 := z.DecReadArrayStart() if yyl2 != 0 { x.codecDecodeSelfFromArray(yyl2, d) } z.DecReadArrayEnd() } else { panic(errCodecSelferOnlyMapOrArrayEncodeToStruct19780) } } func (x *AnonInTestStrucSlim) codecDecodeSelfFromMap(l int, d *Decoder) { var h codecSelfer19780 z, r := GenHelper().Decoder(d) _, _, _ = h, z, r var yyhl3 bool = l >= 0 for yyj3 := 0; ; yyj3++ { if yyhl3 { if yyj3 >= l { break } } else { if z.DecCheckBreak() { break } } z.DecReadMapElemKey() yys3 := r.DecodeStringAsBytes() z.DecReadMapElemValue() switch string(yys3) { case "S": x.S = (string)(z.DecStringZC(r.DecodeStringAsBytes())) case "P": if r.TryNil() { if x.P != nil { // remove the if-true x.P = nil } } else { if x.P == nil { x.P = new(string) } *x.P = (string)(z.DecStringZC(r.DecodeStringAsBytes())) } default: z.DecStructFieldNotFound(-1, string(yys3)) } // end switch yys3 } // end for yyj3 } func (x *AnonInTestStrucSlim) codecDecodeSelfFromArray(l int, d *Decoder) { var h codecSelfer19780 z, r := GenHelper().Decoder(d) _, _, _ = h, z, r var yyj7 int var yyb7 bool var yyhl7 bool = l >= 0 yyj7++ if yyhl7 { yyb7 = yyj7 > l } else { yyb7 = z.DecCheckBreak() } if yyb7 { z.DecReadArrayEnd() return } z.DecReadArrayElem() x.S = (string)(z.DecStringZC(r.DecodeStringAsBytes())) yyj7++ if yyhl7 { yyb7 = yyj7 > l } else { yyb7 = z.DecCheckBreak() } if yyb7 { z.DecReadArrayEnd() return } z.DecReadArrayElem() if r.TryNil() { if x.P != nil { // remove the if-true x.P = nil } } else { if x.P == nil { x.P = new(string) } *x.P = (string)(z.DecStringZC(r.DecodeStringAsBytes())) } for { yyj7++ if yyhl7 { yyb7 = yyj7 > l } else { yyb7 = z.DecCheckBreak() } if yyb7 { break } z.DecReadArrayElem() z.DecStructFieldNotFound(yyj7-1, "") } } func (x *AnonInTestStrucSlim) IsCodecEmpty() bool { return !(x.S != "" || false) } func (AnonInTestStruc) codecSelferViaCodecgen() {} func (x *AnonInTestStruc) CodecEncodeSelf(e *Encoder) { var h codecSelfer19780 z, r := GenHelper().Encoder(e) _, _, _ = h, z, r if z.EncBasicHandle().CheckCircularRef { z.EncEncode(x) return } if x == nil { r.EncodeNil() } else { yy2arr2 := z.EncBasicHandle().StructToArray _ = yy2arr2 const yyr2 bool = false // struct tag has 'toArray' if yyr2 || yy2arr2 { z.EncWriteArrayStart(17) z.EncWriteArrayElem() r.EncodeString(string(x.AS)) z.EncWriteArrayElem() r.EncodeInt(int64(x.AI64)) z.EncWriteArrayElem() r.EncodeInt(int64(x.AI16)) z.EncWriteArrayElem() r.EncodeUint(uint64(x.AUi64)) z.EncWriteArrayElem() if x.ASslice == nil { r.EncodeNil() } else { z.F.EncSliceStringV(x.ASslice, e) } // end block: if x.ASslice slice == nil z.EncWriteArrayElem() if x.AI64slice == nil { r.EncodeNil() } else { z.F.EncSliceInt64V(x.AI64slice, e) } // end block: if x.AI64slice slice == nil z.EncWriteArrayElem() if x.AUi64slice == nil { r.EncodeNil() } else { z.F.EncSliceUint64V(x.AUi64slice, e) } // end block: if x.AUi64slice slice == nil z.EncWriteArrayElem() if x.AF64slice == nil { r.EncodeNil() } else { z.F.EncSliceFloat64V(x.AF64slice, e) } // end block: if x.AF64slice slice == nil z.EncWriteArrayElem() if x.AF32slice == nil { r.EncodeNil() } else { z.F.EncSliceFloat32V(x.AF32slice, e) } // end block: if x.AF32slice slice == nil z.EncWriteArrayElem() if x.AMSS == nil { r.EncodeNil() } else { z.F.EncMapStringStringV(x.AMSS, e) } // end block: if x.AMSS map == nil z.EncWriteArrayElem() if x.AMSU64 == nil { r.EncodeNil() } else { z.F.EncMapStringUint64V(x.AMSU64, e) } // end block: if x.AMSU64 map == nil z.EncWriteArrayElem() yy31 := &x.AI64arr8 h.encArray8int64((*[8]int64)(yy31), e) z.EncWriteArrayElem() yy33 := &x.AI64arr0 h.encArray0int64((*[0]int64)(yy33), e) z.EncWriteArrayElem() if x.AI64slice0 == nil { r.EncodeNil() } else { z.F.EncSliceInt64V(x.AI64slice0, e) } // end block: if x.AI64slice0 slice == nil z.EncWriteArrayElem() if x.AUi64sliceN == nil { r.EncodeNil() } else { z.F.EncSliceUint64V(x.AUi64sliceN, e) } // end block: if x.AUi64sliceN slice == nil z.EncWriteArrayElem() if x.AMSU64N == nil { r.EncodeNil() } else { z.F.EncMapStringUint64V(x.AMSU64N, e) } // end block: if x.AMSU64N map == nil z.EncWriteArrayElem() if x.AMSU64E == nil { r.EncodeNil() } else { z.F.EncMapStringUint64V(x.AMSU64E, e) } // end block: if x.AMSU64E map == nil z.EncWriteArrayEnd() } else { z.EncWriteMapStart(17) if z.EncBasicHandle().Canonical { z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"AF32slice\"") } else { r.EncodeString(`AF32slice`) } z.EncWriteMapElemValue() if x.AF32slice == nil { r.EncodeNil() } else { z.F.EncSliceFloat32V(x.AF32slice, e) } // end block: if x.AF32slice slice == nil z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"AF64slice\"") } else { r.EncodeString(`AF64slice`) } z.EncWriteMapElemValue() if x.AF64slice == nil { r.EncodeNil() } else { z.F.EncSliceFloat64V(x.AF64slice, e) } // end block: if x.AF64slice slice == nil z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"AI16\"") } else { r.EncodeString(`AI16`) } z.EncWriteMapElemValue() r.EncodeInt(int64(x.AI16)) z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"AI64\"") } else { r.EncodeString(`AI64`) } z.EncWriteMapElemValue() r.EncodeInt(int64(x.AI64)) z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"AI64arr0\"") } else { r.EncodeString(`AI64arr0`) } z.EncWriteMapElemValue() yy43 := &x.AI64arr0 h.encArray0int64((*[0]int64)(yy43), e) z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"AI64arr8\"") } else { r.EncodeString(`AI64arr8`) } z.EncWriteMapElemValue() yy45 := &x.AI64arr8 h.encArray8int64((*[8]int64)(yy45), e) z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"AI64slice\"") } else { r.EncodeString(`AI64slice`) } z.EncWriteMapElemValue() if x.AI64slice == nil { r.EncodeNil() } else { z.F.EncSliceInt64V(x.AI64slice, e) } // end block: if x.AI64slice slice == nil z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"AI64slice0\"") } else { r.EncodeString(`AI64slice0`) } z.EncWriteMapElemValue() if x.AI64slice0 == nil { r.EncodeNil() } else { z.F.EncSliceInt64V(x.AI64slice0, e) } // end block: if x.AI64slice0 slice == nil z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"AMSS\"") } else { r.EncodeString(`AMSS`) } z.EncWriteMapElemValue() if x.AMSS == nil { r.EncodeNil() } else { z.F.EncMapStringStringV(x.AMSS, e) } // end block: if x.AMSS map == nil z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"AMSU64\"") } else { r.EncodeString(`AMSU64`) } z.EncWriteMapElemValue() if x.AMSU64 == nil { r.EncodeNil() } else { z.F.EncMapStringUint64V(x.AMSU64, e) } // end block: if x.AMSU64 map == nil z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"AMSU64E\"") } else { r.EncodeString(`AMSU64E`) } z.EncWriteMapElemValue() if x.AMSU64E == nil { r.EncodeNil() } else { z.F.EncMapStringUint64V(x.AMSU64E, e) } // end block: if x.AMSU64E map == nil z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"AMSU64N\"") } else { r.EncodeString(`AMSU64N`) } z.EncWriteMapElemValue() if x.AMSU64N == nil { r.EncodeNil() } else { z.F.EncMapStringUint64V(x.AMSU64N, e) } // end block: if x.AMSU64N map == nil z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"AS\"") } else { r.EncodeString(`AS`) } z.EncWriteMapElemValue() r.EncodeString(string(x.AS)) z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"ASslice\"") } else { r.EncodeString(`ASslice`) } z.EncWriteMapElemValue() if x.ASslice == nil { r.EncodeNil() } else { z.F.EncSliceStringV(x.ASslice, e) } // end block: if x.ASslice slice == nil z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"AUi64\"") } else { r.EncodeString(`AUi64`) } z.EncWriteMapElemValue() r.EncodeUint(uint64(x.AUi64)) z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"AUi64slice\"") } else { r.EncodeString(`AUi64slice`) } z.EncWriteMapElemValue() if x.AUi64slice == nil { r.EncodeNil() } else { z.F.EncSliceUint64V(x.AUi64slice, e) } // end block: if x.AUi64slice slice == nil z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"AUi64sliceN\"") } else { r.EncodeString(`AUi64sliceN`) } z.EncWriteMapElemValue() if x.AUi64sliceN == nil { r.EncodeNil() } else { z.F.EncSliceUint64V(x.AUi64sliceN, e) } // end block: if x.AUi64sliceN slice == nil } else { z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"AS\"") } else { r.EncodeString(`AS`) } z.EncWriteMapElemValue() r.EncodeString(string(x.AS)) z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"AI64\"") } else { r.EncodeString(`AI64`) } z.EncWriteMapElemValue() r.EncodeInt(int64(x.AI64)) z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"AI16\"") } else { r.EncodeString(`AI16`) } z.EncWriteMapElemValue() r.EncodeInt(int64(x.AI16)) z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"AUi64\"") } else { r.EncodeString(`AUi64`) } z.EncWriteMapElemValue() r.EncodeUint(uint64(x.AUi64)) z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"ASslice\"") } else { r.EncodeString(`ASslice`) } z.EncWriteMapElemValue() if x.ASslice == nil { r.EncodeNil() } else { z.F.EncSliceStringV(x.ASslice, e) } // end block: if x.ASslice slice == nil z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"AI64slice\"") } else { r.EncodeString(`AI64slice`) } z.EncWriteMapElemValue() if x.AI64slice == nil { r.EncodeNil() } else { z.F.EncSliceInt64V(x.AI64slice, e) } // end block: if x.AI64slice slice == nil z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"AUi64slice\"") } else { r.EncodeString(`AUi64slice`) } z.EncWriteMapElemValue() if x.AUi64slice == nil { r.EncodeNil() } else { z.F.EncSliceUint64V(x.AUi64slice, e) } // end block: if x.AUi64slice slice == nil z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"AF64slice\"") } else { r.EncodeString(`AF64slice`) } z.EncWriteMapElemValue() if x.AF64slice == nil { r.EncodeNil() } else { z.F.EncSliceFloat64V(x.AF64slice, e) } // end block: if x.AF64slice slice == nil z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"AF32slice\"") } else { r.EncodeString(`AF32slice`) } z.EncWriteMapElemValue() if x.AF32slice == nil { r.EncodeNil() } else { z.F.EncSliceFloat32V(x.AF32slice, e) } // end block: if x.AF32slice slice == nil z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"AMSS\"") } else { r.EncodeString(`AMSS`) } z.EncWriteMapElemValue() if x.AMSS == nil { r.EncodeNil() } else { z.F.EncMapStringStringV(x.AMSS, e) } // end block: if x.AMSS map == nil z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"AMSU64\"") } else { r.EncodeString(`AMSU64`) } z.EncWriteMapElemValue() if x.AMSU64 == nil { r.EncodeNil() } else { z.F.EncMapStringUint64V(x.AMSU64, e) } // end block: if x.AMSU64 map == nil z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"AI64arr8\"") } else { r.EncodeString(`AI64arr8`) } z.EncWriteMapElemValue() yy69 := &x.AI64arr8 h.encArray8int64((*[8]int64)(yy69), e) z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"AI64arr0\"") } else { r.EncodeString(`AI64arr0`) } z.EncWriteMapElemValue() yy71 := &x.AI64arr0 h.encArray0int64((*[0]int64)(yy71), e) z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"AI64slice0\"") } else { r.EncodeString(`AI64slice0`) } z.EncWriteMapElemValue() if x.AI64slice0 == nil { r.EncodeNil() } else { z.F.EncSliceInt64V(x.AI64slice0, e) } // end block: if x.AI64slice0 slice == nil z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"AUi64sliceN\"") } else { r.EncodeString(`AUi64sliceN`) } z.EncWriteMapElemValue() if x.AUi64sliceN == nil { r.EncodeNil() } else { z.F.EncSliceUint64V(x.AUi64sliceN, e) } // end block: if x.AUi64sliceN slice == nil z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"AMSU64N\"") } else { r.EncodeString(`AMSU64N`) } z.EncWriteMapElemValue() if x.AMSU64N == nil { r.EncodeNil() } else { z.F.EncMapStringUint64V(x.AMSU64N, e) } // end block: if x.AMSU64N map == nil z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"AMSU64E\"") } else { r.EncodeString(`AMSU64E`) } z.EncWriteMapElemValue() if x.AMSU64E == nil { r.EncodeNil() } else { z.F.EncMapStringUint64V(x.AMSU64E, e) } // end block: if x.AMSU64E map == nil } z.EncWriteMapEnd() } } } func (x *AnonInTestStruc) CodecDecodeSelf(d *Decoder) { var h codecSelfer19780 z, r := GenHelper().Decoder(d) _, _, _ = h, z, r yyct2 := r.ContainerType() if yyct2 == codecSelferValueTypeNil19780 { *(x) = AnonInTestStruc{} } else if yyct2 == codecSelferValueTypeMap19780 { yyl2 := z.DecReadMapStart() if yyl2 == 0 { } else { x.codecDecodeSelfFromMap(yyl2, d) } z.DecReadMapEnd() } else if yyct2 == codecSelferValueTypeArray19780 { yyl2 := z.DecReadArrayStart() if yyl2 != 0 { x.codecDecodeSelfFromArray(yyl2, d) } z.DecReadArrayEnd() } else { panic(errCodecSelferOnlyMapOrArrayEncodeToStruct19780) } } func (x *AnonInTestStruc) codecDecodeSelfFromMap(l int, d *Decoder) { var h codecSelfer19780 z, r := GenHelper().Decoder(d) _, _, _ = h, z, r var yyhl3 bool = l >= 0 for yyj3 := 0; ; yyj3++ { if yyhl3 { if yyj3 >= l { break } } else { if z.DecCheckBreak() { break } } z.DecReadMapElemKey() yys3 := r.DecodeStringAsBytes() z.DecReadMapElemValue() switch string(yys3) { case "AS": x.AS = (string)(z.DecStringZC(r.DecodeStringAsBytes())) case "AI64": x.AI64 = (int64)(r.DecodeInt64()) case "AI16": x.AI16 = (int16)(z.C.IntV(r.DecodeInt64(), 16)) case "AUi64": x.AUi64 = (uint64)(r.DecodeUint64()) case "ASslice": z.F.DecSliceStringX(&x.ASslice, d) case "AI64slice": z.F.DecSliceInt64X(&x.AI64slice, d) case "AUi64slice": z.F.DecSliceUint64X(&x.AUi64slice, d) case "AF64slice": z.F.DecSliceFloat64X(&x.AF64slice, d) case "AF32slice": z.F.DecSliceFloat32X(&x.AF32slice, d) case "AMSS": z.F.DecMapStringStringX(&x.AMSS, d) case "AMSU64": z.F.DecMapStringUint64X(&x.AMSU64, d) case "AI64arr8": h.decArray8int64((*[8]int64)(&x.AI64arr8), d) case "AI64arr0": h.decArray0int64((*[0]int64)(&x.AI64arr0), d) case "AI64slice0": z.F.DecSliceInt64X(&x.AI64slice0, d) case "AUi64sliceN": z.F.DecSliceUint64X(&x.AUi64sliceN, d) case "AMSU64N": z.F.DecMapStringUint64X(&x.AMSU64N, d) case "AMSU64E": z.F.DecMapStringUint64X(&x.AMSU64E, d) default: z.DecStructFieldNotFound(-1, string(yys3)) } // end switch yys3 } // end for yyj3 } func (x *AnonInTestStruc) codecDecodeSelfFromArray(l int, d *Decoder) { var h codecSelfer19780 z, r := GenHelper().Decoder(d) _, _, _ = h, z, r var yyj34 int var yyb34 bool var yyhl34 bool = l >= 0 yyj34++ if yyhl34 { yyb34 = yyj34 > l } else { yyb34 = z.DecCheckBreak() } if yyb34 { z.DecReadArrayEnd() return } z.DecReadArrayElem() x.AS = (string)(z.DecStringZC(r.DecodeStringAsBytes())) yyj34++ if yyhl34 { yyb34 = yyj34 > l } else { yyb34 = z.DecCheckBreak() } if yyb34 { z.DecReadArrayEnd() return } z.DecReadArrayElem() x.AI64 = (int64)(r.DecodeInt64()) yyj34++ if yyhl34 { yyb34 = yyj34 > l } else { yyb34 = z.DecCheckBreak() } if yyb34 { z.DecReadArrayEnd() return } z.DecReadArrayElem() x.AI16 = (int16)(z.C.IntV(r.DecodeInt64(), 16)) yyj34++ if yyhl34 { yyb34 = yyj34 > l } else { yyb34 = z.DecCheckBreak() } if yyb34 { z.DecReadArrayEnd() return } z.DecReadArrayElem() x.AUi64 = (uint64)(r.DecodeUint64()) yyj34++ if yyhl34 { yyb34 = yyj34 > l } else { yyb34 = z.DecCheckBreak() } if yyb34 { z.DecReadArrayEnd() return } z.DecReadArrayElem() z.F.DecSliceStringX(&x.ASslice, d) yyj34++ if yyhl34 { yyb34 = yyj34 > l } else { yyb34 = z.DecCheckBreak() } if yyb34 { z.DecReadArrayEnd() return } z.DecReadArrayElem() z.F.DecSliceInt64X(&x.AI64slice, d) yyj34++ if yyhl34 { yyb34 = yyj34 > l } else { yyb34 = z.DecCheckBreak() } if yyb34 { z.DecReadArrayEnd() return } z.DecReadArrayElem() z.F.DecSliceUint64X(&x.AUi64slice, d) yyj34++ if yyhl34 { yyb34 = yyj34 > l } else { yyb34 = z.DecCheckBreak() } if yyb34 { z.DecReadArrayEnd() return } z.DecReadArrayElem() z.F.DecSliceFloat64X(&x.AF64slice, d) yyj34++ if yyhl34 { yyb34 = yyj34 > l } else { yyb34 = z.DecCheckBreak() } if yyb34 { z.DecReadArrayEnd() return } z.DecReadArrayElem() z.F.DecSliceFloat32X(&x.AF32slice, d) yyj34++ if yyhl34 { yyb34 = yyj34 > l } else { yyb34 = z.DecCheckBreak() } if yyb34 { z.DecReadArrayEnd() return } z.DecReadArrayElem() z.F.DecMapStringStringX(&x.AMSS, d) yyj34++ if yyhl34 { yyb34 = yyj34 > l } else { yyb34 = z.DecCheckBreak() } if yyb34 { z.DecReadArrayEnd() return } z.DecReadArrayElem() z.F.DecMapStringUint64X(&x.AMSU64, d) yyj34++ if yyhl34 { yyb34 = yyj34 > l } else { yyb34 = z.DecCheckBreak() } if yyb34 { z.DecReadArrayEnd() return } z.DecReadArrayElem() h.decArray8int64((*[8]int64)(&x.AI64arr8), d) yyj34++ if yyhl34 { yyb34 = yyj34 > l } else { yyb34 = z.DecCheckBreak() } if yyb34 { z.DecReadArrayEnd() return } z.DecReadArrayElem() h.decArray0int64((*[0]int64)(&x.AI64arr0), d) yyj34++ if yyhl34 { yyb34 = yyj34 > l } else { yyb34 = z.DecCheckBreak() } if yyb34 { z.DecReadArrayEnd() return } z.DecReadArrayElem() z.F.DecSliceInt64X(&x.AI64slice0, d) yyj34++ if yyhl34 { yyb34 = yyj34 > l } else { yyb34 = z.DecCheckBreak() } if yyb34 { z.DecReadArrayEnd() return } z.DecReadArrayElem() z.F.DecSliceUint64X(&x.AUi64sliceN, d) yyj34++ if yyhl34 { yyb34 = yyj34 > l } else { yyb34 = z.DecCheckBreak() } if yyb34 { z.DecReadArrayEnd() return } z.DecReadArrayElem() z.F.DecMapStringUint64X(&x.AMSU64N, d) yyj34++ if yyhl34 { yyb34 = yyj34 > l } else { yyb34 = z.DecCheckBreak() } if yyb34 { z.DecReadArrayEnd() return } z.DecReadArrayElem() z.F.DecMapStringUint64X(&x.AMSU64E, d) for { yyj34++ if yyhl34 { yyb34 = yyj34 > l } else { yyb34 = z.DecCheckBreak() } if yyb34 { break } z.DecReadArrayElem() z.DecStructFieldNotFound(yyj34-1, "") } } func (x *AnonInTestStruc) IsCodecEmpty() bool { return !(x.AS != "" || x.AI64 != 0 || x.AI16 != 0 || x.AUi64 != 0 || len(x.ASslice) != 0 || len(x.AI64slice) != 0 || len(x.AUi64slice) != 0 || len(x.AF64slice) != 0 || len(x.AF32slice) != 0 || len(x.AMSS) != 0 || len(x.AMSU64) != 0 || x.AI64arr8 != [8]int64{} || false || len(x.AI64slice0) != 0 || len(x.AUi64sliceN) != 0 || len(x.AMSU64N) != 0 || len(x.AMSU64E) != 0 || false) } func (testSimpleFields) codecSelferViaCodecgen() {} func (x *testSimpleFields) CodecEncodeSelf(e *Encoder) { var h codecSelfer19780 z, r := GenHelper().Encoder(e) _, _, _ = h, z, r if z.EncBasicHandle().CheckCircularRef { z.EncEncode(x) return } if x == nil { r.EncodeNil() } else { yy2arr2 := z.EncBasicHandle().StructToArray _ = yy2arr2 const yyr2 bool = false // struct tag has 'toArray' if yyr2 || yy2arr2 { z.EncWriteArrayStart(17) z.EncWriteArrayElem() r.EncodeString(string(x.S)) z.EncWriteArrayElem() r.EncodeInt(int64(x.I64)) z.EncWriteArrayElem() r.EncodeInt(int64(x.I8)) z.EncWriteArrayElem() r.EncodeUint(uint64(x.Ui64)) z.EncWriteArrayElem() r.EncodeUint(uint64(x.Ui8)) z.EncWriteArrayElem() r.EncodeFloat64(float64(x.F64)) z.EncWriteArrayElem() r.EncodeFloat32(float32(x.F32)) z.EncWriteArrayElem() r.EncodeBool(bool(x.B)) z.EncWriteArrayElem() if x.Sslice == nil { r.EncodeNil() } else { z.F.EncSliceStringV(x.Sslice, e) } // end block: if x.Sslice slice == nil z.EncWriteArrayElem() if x.I32slice == nil { r.EncodeNil() } else { z.F.EncSliceInt32V(x.I32slice, e) } // end block: if x.I32slice slice == nil z.EncWriteArrayElem() if x.Ui64slice == nil { r.EncodeNil() } else { z.F.EncSliceUint64V(x.Ui64slice, e) } // end block: if x.Ui64slice slice == nil z.EncWriteArrayElem() if x.Ui8slice == nil { r.EncodeNil() } else { r.EncodeStringBytesRaw([]byte(x.Ui8slice)) } // end block: if x.Ui8slice slice == nil z.EncWriteArrayElem() if x.Bslice == nil { r.EncodeNil() } else { z.F.EncSliceBoolV(x.Bslice, e) } // end block: if x.Bslice slice == nil z.EncWriteArrayElem() if x.Iptrslice == nil { r.EncodeNil() } else { h.encSlicePtrtoint64(([]*int64)(x.Iptrslice), e) } // end block: if x.Iptrslice slice == nil z.EncWriteArrayElem() if yyxt34 := z.Extension(x.WrapSliceInt64); yyxt34 != nil { z.EncExtension(x.WrapSliceInt64, yyxt34) } else { x.WrapSliceInt64.CodecEncodeSelf(e) } z.EncWriteArrayElem() if yyxt35 := z.Extension(x.WrapSliceString); yyxt35 != nil { z.EncExtension(x.WrapSliceString, yyxt35) } else { x.WrapSliceString.CodecEncodeSelf(e) } z.EncWriteArrayElem() if x.Msint == nil { r.EncodeNil() } else { z.F.EncMapStringIntV(x.Msint, e) } // end block: if x.Msint map == nil z.EncWriteArrayEnd() } else { z.EncWriteMapStart(17) if z.EncBasicHandle().Canonical { z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"B\"") } else { r.EncodeString(`B`) } z.EncWriteMapElemValue() r.EncodeBool(bool(x.B)) z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"Bslice\"") } else { r.EncodeString(`Bslice`) } z.EncWriteMapElemValue() if x.Bslice == nil { r.EncodeNil() } else { z.F.EncSliceBoolV(x.Bslice, e) } // end block: if x.Bslice slice == nil z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"F32\"") } else { r.EncodeString(`F32`) } z.EncWriteMapElemValue() r.EncodeFloat32(float32(x.F32)) z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"F64\"") } else { r.EncodeString(`F64`) } z.EncWriteMapElemValue() r.EncodeFloat64(float64(x.F64)) z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"I32slice\"") } else { r.EncodeString(`I32slice`) } z.EncWriteMapElemValue() if x.I32slice == nil { r.EncodeNil() } else { z.F.EncSliceInt32V(x.I32slice, e) } // end block: if x.I32slice slice == nil z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"I64\"") } else { r.EncodeString(`I64`) } z.EncWriteMapElemValue() r.EncodeInt(int64(x.I64)) z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"I8\"") } else { r.EncodeString(`I8`) } z.EncWriteMapElemValue() r.EncodeInt(int64(x.I8)) z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"Iptrslice\"") } else { r.EncodeString(`Iptrslice`) } z.EncWriteMapElemValue() if x.Iptrslice == nil { r.EncodeNil() } else { h.encSlicePtrtoint64(([]*int64)(x.Iptrslice), e) } // end block: if x.Iptrslice slice == nil z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"Msint\"") } else { r.EncodeString(`Msint`) } z.EncWriteMapElemValue() if x.Msint == nil { r.EncodeNil() } else { z.F.EncMapStringIntV(x.Msint, e) } // end block: if x.Msint map == nil z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"S\"") } else { r.EncodeString(`S`) } z.EncWriteMapElemValue() r.EncodeString(string(x.S)) z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"Sslice\"") } else { r.EncodeString(`Sslice`) } z.EncWriteMapElemValue() if x.Sslice == nil { r.EncodeNil() } else { z.F.EncSliceStringV(x.Sslice, e) } // end block: if x.Sslice slice == nil z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"Ui64\"") } else { r.EncodeString(`Ui64`) } z.EncWriteMapElemValue() r.EncodeUint(uint64(x.Ui64)) z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"Ui64slice\"") } else { r.EncodeString(`Ui64slice`) } z.EncWriteMapElemValue() if x.Ui64slice == nil { r.EncodeNil() } else { z.F.EncSliceUint64V(x.Ui64slice, e) } // end block: if x.Ui64slice slice == nil z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"Ui8\"") } else { r.EncodeString(`Ui8`) } z.EncWriteMapElemValue() r.EncodeUint(uint64(x.Ui8)) z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"Ui8slice\"") } else { r.EncodeString(`Ui8slice`) } z.EncWriteMapElemValue() if x.Ui8slice == nil { r.EncodeNil() } else { r.EncodeStringBytesRaw([]byte(x.Ui8slice)) } // end block: if x.Ui8slice slice == nil z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"WrapSliceInt64\"") } else { r.EncodeString(`WrapSliceInt64`) } z.EncWriteMapElemValue() if yyxt52 := z.Extension(x.WrapSliceInt64); yyxt52 != nil { z.EncExtension(x.WrapSliceInt64, yyxt52) } else { x.WrapSliceInt64.CodecEncodeSelf(e) } z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"WrapSliceString\"") } else { r.EncodeString(`WrapSliceString`) } z.EncWriteMapElemValue() if yyxt53 := z.Extension(x.WrapSliceString); yyxt53 != nil { z.EncExtension(x.WrapSliceString, yyxt53) } else { x.WrapSliceString.CodecEncodeSelf(e) } } else { z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"S\"") } else { r.EncodeString(`S`) } z.EncWriteMapElemValue() r.EncodeString(string(x.S)) z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"I64\"") } else { r.EncodeString(`I64`) } z.EncWriteMapElemValue() r.EncodeInt(int64(x.I64)) z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"I8\"") } else { r.EncodeString(`I8`) } z.EncWriteMapElemValue() r.EncodeInt(int64(x.I8)) z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"Ui64\"") } else { r.EncodeString(`Ui64`) } z.EncWriteMapElemValue() r.EncodeUint(uint64(x.Ui64)) z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"Ui8\"") } else { r.EncodeString(`Ui8`) } z.EncWriteMapElemValue() r.EncodeUint(uint64(x.Ui8)) z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"F64\"") } else { r.EncodeString(`F64`) } z.EncWriteMapElemValue() r.EncodeFloat64(float64(x.F64)) z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"F32\"") } else { r.EncodeString(`F32`) } z.EncWriteMapElemValue() r.EncodeFloat32(float32(x.F32)) z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"B\"") } else { r.EncodeString(`B`) } z.EncWriteMapElemValue() r.EncodeBool(bool(x.B)) z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"Sslice\"") } else { r.EncodeString(`Sslice`) } z.EncWriteMapElemValue() if x.Sslice == nil { r.EncodeNil() } else { z.F.EncSliceStringV(x.Sslice, e) } // end block: if x.Sslice slice == nil z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"I32slice\"") } else { r.EncodeString(`I32slice`) } z.EncWriteMapElemValue() if x.I32slice == nil { r.EncodeNil() } else { z.F.EncSliceInt32V(x.I32slice, e) } // end block: if x.I32slice slice == nil z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"Ui64slice\"") } else { r.EncodeString(`Ui64slice`) } z.EncWriteMapElemValue() if x.Ui64slice == nil { r.EncodeNil() } else { z.F.EncSliceUint64V(x.Ui64slice, e) } // end block: if x.Ui64slice slice == nil z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"Ui8slice\"") } else { r.EncodeString(`Ui8slice`) } z.EncWriteMapElemValue() if x.Ui8slice == nil { r.EncodeNil() } else { r.EncodeStringBytesRaw([]byte(x.Ui8slice)) } // end block: if x.Ui8slice slice == nil z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"Bslice\"") } else { r.EncodeString(`Bslice`) } z.EncWriteMapElemValue() if x.Bslice == nil { r.EncodeNil() } else { z.F.EncSliceBoolV(x.Bslice, e) } // end block: if x.Bslice slice == nil z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"Iptrslice\"") } else { r.EncodeString(`Iptrslice`) } z.EncWriteMapElemValue() if x.Iptrslice == nil { r.EncodeNil() } else { h.encSlicePtrtoint64(([]*int64)(x.Iptrslice), e) } // end block: if x.Iptrslice slice == nil z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"WrapSliceInt64\"") } else { r.EncodeString(`WrapSliceInt64`) } z.EncWriteMapElemValue() if yyxt68 := z.Extension(x.WrapSliceInt64); yyxt68 != nil { z.EncExtension(x.WrapSliceInt64, yyxt68) } else { x.WrapSliceInt64.CodecEncodeSelf(e) } z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"WrapSliceString\"") } else { r.EncodeString(`WrapSliceString`) } z.EncWriteMapElemValue() if yyxt69 := z.Extension(x.WrapSliceString); yyxt69 != nil { z.EncExtension(x.WrapSliceString, yyxt69) } else { x.WrapSliceString.CodecEncodeSelf(e) } z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"Msint\"") } else { r.EncodeString(`Msint`) } z.EncWriteMapElemValue() if x.Msint == nil { r.EncodeNil() } else { z.F.EncMapStringIntV(x.Msint, e) } // end block: if x.Msint map == nil } z.EncWriteMapEnd() } } } func (x *testSimpleFields) CodecDecodeSelf(d *Decoder) { var h codecSelfer19780 z, r := GenHelper().Decoder(d) _, _, _ = h, z, r yyct2 := r.ContainerType() if yyct2 == codecSelferValueTypeNil19780 { *(x) = testSimpleFields{} } else if yyct2 == codecSelferValueTypeMap19780 { yyl2 := z.DecReadMapStart() if yyl2 == 0 { } else { x.codecDecodeSelfFromMap(yyl2, d) } z.DecReadMapEnd() } else if yyct2 == codecSelferValueTypeArray19780 { yyl2 := z.DecReadArrayStart() if yyl2 != 0 { x.codecDecodeSelfFromArray(yyl2, d) } z.DecReadArrayEnd() } else { panic(errCodecSelferOnlyMapOrArrayEncodeToStruct19780) } } func (x *testSimpleFields) codecDecodeSelfFromMap(l int, d *Decoder) { var h codecSelfer19780 z, r := GenHelper().Decoder(d) _, _, _ = h, z, r var yyhl3 bool = l >= 0 for yyj3 := 0; ; yyj3++ { if yyhl3 { if yyj3 >= l { break } } else { if z.DecCheckBreak() { break } } z.DecReadMapElemKey() yys3 := r.DecodeStringAsBytes() z.DecReadMapElemValue() switch string(yys3) { case "S": x.S = (string)(z.DecStringZC(r.DecodeStringAsBytes())) case "I64": x.I64 = (int64)(r.DecodeInt64()) case "I8": x.I8 = (int8)(z.C.IntV(r.DecodeInt64(), 8)) case "Ui64": x.Ui64 = (uint64)(r.DecodeUint64()) case "Ui8": x.Ui8 = (uint8)(z.C.UintV(r.DecodeUint64(), 8)) case "F64": x.F64 = (float64)(r.DecodeFloat64()) case "F32": x.F32 = (float32)(z.DecDecodeFloat32()) case "B": x.B = (bool)(r.DecodeBool()) case "Sslice": z.F.DecSliceStringX(&x.Sslice, d) case "I32slice": z.F.DecSliceInt32X(&x.I32slice, d) case "Ui64slice": z.F.DecSliceUint64X(&x.Ui64slice, d) case "Ui8slice": x.Ui8slice = z.DecodeBytesInto(([]byte)(x.Ui8slice)) case "Bslice": z.F.DecSliceBoolX(&x.Bslice, d) case "Iptrslice": h.decSlicePtrtoint64((*[]*int64)(&x.Iptrslice), d) case "WrapSliceInt64": if yyxt25 := z.Extension(x.WrapSliceInt64); yyxt25 != nil { z.DecExtension(&x.WrapSliceInt64, yyxt25) } else { x.WrapSliceInt64.CodecDecodeSelf(d) } case "WrapSliceString": if yyxt27 := z.Extension(x.WrapSliceString); yyxt27 != nil { z.DecExtension(&x.WrapSliceString, yyxt27) } else { x.WrapSliceString.CodecDecodeSelf(d) } case "Msint": z.F.DecMapStringIntX(&x.Msint, d) default: z.DecStructFieldNotFound(-1, string(yys3)) } // end switch yys3 } // end for yyj3 } func (x *testSimpleFields) codecDecodeSelfFromArray(l int, d *Decoder) { var h codecSelfer19780 z, r := GenHelper().Decoder(d) _, _, _ = h, z, r var yyj30 int var yyb30 bool var yyhl30 bool = l >= 0 yyj30++ if yyhl30 { yyb30 = yyj30 > l } else { yyb30 = z.DecCheckBreak() } if yyb30 { z.DecReadArrayEnd() return } z.DecReadArrayElem() x.S = (string)(z.DecStringZC(r.DecodeStringAsBytes())) yyj30++ if yyhl30 { yyb30 = yyj30 > l } else { yyb30 = z.DecCheckBreak() } if yyb30 { z.DecReadArrayEnd() return } z.DecReadArrayElem() x.I64 = (int64)(r.DecodeInt64()) yyj30++ if yyhl30 { yyb30 = yyj30 > l } else { yyb30 = z.DecCheckBreak() } if yyb30 { z.DecReadArrayEnd() return } z.DecReadArrayElem() x.I8 = (int8)(z.C.IntV(r.DecodeInt64(), 8)) yyj30++ if yyhl30 { yyb30 = yyj30 > l } else { yyb30 = z.DecCheckBreak() } if yyb30 { z.DecReadArrayEnd() return } z.DecReadArrayElem() x.Ui64 = (uint64)(r.DecodeUint64()) yyj30++ if yyhl30 { yyb30 = yyj30 > l } else { yyb30 = z.DecCheckBreak() } if yyb30 { z.DecReadArrayEnd() return } z.DecReadArrayElem() x.Ui8 = (uint8)(z.C.UintV(r.DecodeUint64(), 8)) yyj30++ if yyhl30 { yyb30 = yyj30 > l } else { yyb30 = z.DecCheckBreak() } if yyb30 { z.DecReadArrayEnd() return } z.DecReadArrayElem() x.F64 = (float64)(r.DecodeFloat64()) yyj30++ if yyhl30 { yyb30 = yyj30 > l } else { yyb30 = z.DecCheckBreak() } if yyb30 { z.DecReadArrayEnd() return } z.DecReadArrayElem() x.F32 = (float32)(z.DecDecodeFloat32()) yyj30++ if yyhl30 { yyb30 = yyj30 > l } else { yyb30 = z.DecCheckBreak() } if yyb30 { z.DecReadArrayEnd() return } z.DecReadArrayElem() x.B = (bool)(r.DecodeBool()) yyj30++ if yyhl30 { yyb30 = yyj30 > l } else { yyb30 = z.DecCheckBreak() } if yyb30 { z.DecReadArrayEnd() return } z.DecReadArrayElem() z.F.DecSliceStringX(&x.Sslice, d) yyj30++ if yyhl30 { yyb30 = yyj30 > l } else { yyb30 = z.DecCheckBreak() } if yyb30 { z.DecReadArrayEnd() return } z.DecReadArrayElem() z.F.DecSliceInt32X(&x.I32slice, d) yyj30++ if yyhl30 { yyb30 = yyj30 > l } else { yyb30 = z.DecCheckBreak() } if yyb30 { z.DecReadArrayEnd() return } z.DecReadArrayElem() z.F.DecSliceUint64X(&x.Ui64slice, d) yyj30++ if yyhl30 { yyb30 = yyj30 > l } else { yyb30 = z.DecCheckBreak() } if yyb30 { z.DecReadArrayEnd() return } z.DecReadArrayElem() x.Ui8slice = z.DecodeBytesInto(([]byte)(x.Ui8slice)) yyj30++ if yyhl30 { yyb30 = yyj30 > l } else { yyb30 = z.DecCheckBreak() } if yyb30 { z.DecReadArrayEnd() return } z.DecReadArrayElem() z.F.DecSliceBoolX(&x.Bslice, d) yyj30++ if yyhl30 { yyb30 = yyj30 > l } else { yyb30 = z.DecCheckBreak() } if yyb30 { z.DecReadArrayEnd() return } z.DecReadArrayElem() h.decSlicePtrtoint64((*[]*int64)(&x.Iptrslice), d) yyj30++ if yyhl30 { yyb30 = yyj30 > l } else { yyb30 = z.DecCheckBreak() } if yyb30 { z.DecReadArrayEnd() return } z.DecReadArrayElem() if yyxt52 := z.Extension(x.WrapSliceInt64); yyxt52 != nil { z.DecExtension(&x.WrapSliceInt64, yyxt52) } else { x.WrapSliceInt64.CodecDecodeSelf(d) } yyj30++ if yyhl30 { yyb30 = yyj30 > l } else { yyb30 = z.DecCheckBreak() } if yyb30 { z.DecReadArrayEnd() return } z.DecReadArrayElem() if yyxt54 := z.Extension(x.WrapSliceString); yyxt54 != nil { z.DecExtension(&x.WrapSliceString, yyxt54) } else { x.WrapSliceString.CodecDecodeSelf(d) } yyj30++ if yyhl30 { yyb30 = yyj30 > l } else { yyb30 = z.DecCheckBreak() } if yyb30 { z.DecReadArrayEnd() return } z.DecReadArrayElem() z.F.DecMapStringIntX(&x.Msint, d) for { yyj30++ if yyhl30 { yyb30 = yyj30 > l } else { yyb30 = z.DecCheckBreak() } if yyb30 { break } z.DecReadArrayElem() z.DecStructFieldNotFound(yyj30-1, "") } } func (x *testSimpleFields) IsCodecEmpty() bool { return !(x.S != "" || x.I64 != 0 || x.I8 != 0 || x.Ui64 != 0 || x.Ui8 != 0 || x.F64 != 0 || x.F32 != 0 || bool(x.B) || len(x.Sslice) != 0 || len(x.I32slice) != 0 || len(x.Ui64slice) != 0 || len(x.Ui8slice) != 0 || len(x.Bslice) != 0 || len(x.Iptrslice) != 0 || len(x.WrapSliceInt64) != 0 || len(x.WrapSliceString) != 0 || len(x.Msint) != 0 || false) } func (TestStrucCommon) codecSelferViaCodecgen() {} func (x *TestStrucCommon) CodecEncodeSelf(e *Encoder) { var h codecSelfer19780 z, r := GenHelper().Encoder(e) _, _, _ = h, z, r if z.EncBasicHandle().CheckCircularRef { z.EncEncode(x) return } if x == nil { r.EncodeNil() } else { yy2arr2 := z.EncBasicHandle().StructToArray _ = yy2arr2 const yyr2 bool = false // struct tag has 'toArray' var yyn54 bool = x.AnonInTestStrucSlim == nil || x.AnonInTestStrucSlim.P == nil var yyn55 bool = x.NotAnonSlim == nil var yyn58 bool = x.Nint64 == nil if yyr2 || yy2arr2 { z.EncWriteArrayStart(56) z.EncWriteArrayElem() r.EncodeString(string(x.S)) z.EncWriteArrayElem() r.EncodeInt(int64(x.I64)) z.EncWriteArrayElem() r.EncodeInt(int64(x.I32)) z.EncWriteArrayElem() r.EncodeInt(int64(x.I16)) z.EncWriteArrayElem() r.EncodeInt(int64(x.I8)) z.EncWriteArrayElem() r.EncodeInt(int64(x.I64n)) z.EncWriteArrayElem() r.EncodeInt(int64(x.I32n)) z.EncWriteArrayElem() r.EncodeInt(int64(x.I16n)) z.EncWriteArrayElem() r.EncodeInt(int64(x.I8n)) z.EncWriteArrayElem() r.EncodeUint(uint64(x.Ui64)) z.EncWriteArrayElem() r.EncodeUint(uint64(x.Ui32)) z.EncWriteArrayElem() r.EncodeUint(uint64(x.Ui16)) z.EncWriteArrayElem() r.EncodeUint(uint64(x.Ui8)) z.EncWriteArrayElem() r.EncodeFloat64(float64(x.F64)) z.EncWriteArrayElem() r.EncodeFloat32(float32(x.F32)) z.EncWriteArrayElem() r.EncodeBool(bool(x.B)) z.EncWriteArrayElem() r.EncodeUint(uint64(x.By)) z.EncWriteArrayElem() if x.Sslice == nil { r.EncodeNil() } else { z.F.EncSliceStringV(x.Sslice, e) } // end block: if x.Sslice slice == nil z.EncWriteArrayElem() if x.I64slice == nil { r.EncodeNil() } else { z.F.EncSliceInt64V(x.I64slice, e) } // end block: if x.I64slice slice == nil z.EncWriteArrayElem() if x.I32slice == nil { r.EncodeNil() } else { z.F.EncSliceInt32V(x.I32slice, e) } // end block: if x.I32slice slice == nil z.EncWriteArrayElem() if x.Ui64slice == nil { r.EncodeNil() } else { z.F.EncSliceUint64V(x.Ui64slice, e) } // end block: if x.Ui64slice slice == nil z.EncWriteArrayElem() if x.Ui8slice == nil { r.EncodeNil() } else { r.EncodeStringBytesRaw([]byte(x.Ui8slice)) } // end block: if x.Ui8slice slice == nil z.EncWriteArrayElem() if x.Bslice == nil { r.EncodeNil() } else { z.F.EncSliceBoolV(x.Bslice, e) } // end block: if x.Bslice slice == nil z.EncWriteArrayElem() if x.Byslice == nil { r.EncodeNil() } else { r.EncodeStringBytesRaw([]byte(x.Byslice)) } // end block: if x.Byslice slice == nil z.EncWriteArrayElem() if x.BytesSlice == nil { r.EncodeNil() } else { z.F.EncSliceBytesV(x.BytesSlice, e) } // end block: if x.BytesSlice slice == nil z.EncWriteArrayElem() if x.Iptrslice == nil { r.EncodeNil() } else { h.encSlicePtrtoint64(([]*int64)(x.Iptrslice), e) } // end block: if x.Iptrslice slice == nil z.EncWriteArrayElem() if yyxt85 := z.Extension(x.WrapSliceInt64); yyxt85 != nil { z.EncExtension(x.WrapSliceInt64, yyxt85) } else { x.WrapSliceInt64.CodecEncodeSelf(e) } z.EncWriteArrayElem() if yyxt86 := z.Extension(x.WrapSliceString); yyxt86 != nil { z.EncExtension(x.WrapSliceString, yyxt86) } else { x.WrapSliceString.CodecEncodeSelf(e) } z.EncWriteArrayElem() if x.Msint == nil { r.EncodeNil() } else { z.F.EncMapStringIntV(x.Msint, e) } // end block: if x.Msint map == nil z.EncWriteArrayElem() if x.Msbytes == nil { r.EncodeNil() } else { z.F.EncMapStringBytesV(x.Msbytes, e) } // end block: if x.Msbytes map == nil z.EncWriteArrayElem() yy89 := &x.Simplef if yyxt90 := z.Extension(yy89); yyxt90 != nil { z.EncExtension(yy89, yyxt90) } else { yy89.CodecEncodeSelf(e) } z.EncWriteArrayElem() if x.SstrUi64T == nil { r.EncodeNil() } else { h.encSlicestringUint64T(([]stringUint64T)(x.SstrUi64T), e) } // end block: if x.SstrUi64T slice == nil z.EncWriteArrayElem() if x.MstrUi64T == nil { r.EncodeNil() } else { h.encMapstringPtrtostringUint64T((map[string]*stringUint64T)(x.MstrUi64T), e) } // end block: if x.MstrUi64T map == nil z.EncWriteArrayElem() r.EncodeString(string(x.AnonInTestStruc.AS)) z.EncWriteArrayElem() r.EncodeInt(int64(x.AnonInTestStruc.AI64)) z.EncWriteArrayElem() r.EncodeInt(int64(x.AnonInTestStruc.AI16)) z.EncWriteArrayElem() r.EncodeUint(uint64(x.AnonInTestStruc.AUi64)) z.EncWriteArrayElem() if x.AnonInTestStruc.ASslice == nil { r.EncodeNil() } else { z.F.EncSliceStringV(x.AnonInTestStruc.ASslice, e) } // end block: if x.AnonInTestStruc.ASslice slice == nil z.EncWriteArrayElem() if x.AnonInTestStruc.AI64slice == nil { r.EncodeNil() } else { z.F.EncSliceInt64V(x.AnonInTestStruc.AI64slice, e) } // end block: if x.AnonInTestStruc.AI64slice slice == nil z.EncWriteArrayElem() if x.AnonInTestStruc.AUi64slice == nil { r.EncodeNil() } else { z.F.EncSliceUint64V(x.AnonInTestStruc.AUi64slice, e) } // end block: if x.AnonInTestStruc.AUi64slice slice == nil z.EncWriteArrayElem() if x.AnonInTestStruc.AF64slice == nil { r.EncodeNil() } else { z.F.EncSliceFloat64V(x.AnonInTestStruc.AF64slice, e) } // end block: if x.AnonInTestStruc.AF64slice slice == nil z.EncWriteArrayElem() if x.AnonInTestStruc.AF32slice == nil { r.EncodeNil() } else { z.F.EncSliceFloat32V(x.AnonInTestStruc.AF32slice, e) } // end block: if x.AnonInTestStruc.AF32slice slice == nil z.EncWriteArrayElem() if x.AnonInTestStruc.AMSS == nil { r.EncodeNil() } else { z.F.EncMapStringStringV(x.AnonInTestStruc.AMSS, e) } // end block: if x.AnonInTestStruc.AMSS map == nil z.EncWriteArrayElem() if x.AnonInTestStruc.AMSU64 == nil { r.EncodeNil() } else { z.F.EncMapStringUint64V(x.AnonInTestStruc.AMSU64, e) } // end block: if x.AnonInTestStruc.AMSU64 map == nil z.EncWriteArrayElem() yy104 := &x.AnonInTestStruc.AI64arr8 h.encArray8int64((*[8]int64)(yy104), e) z.EncWriteArrayElem() yy106 := &x.AnonInTestStruc.AI64arr0 h.encArray0int64((*[0]int64)(yy106), e) z.EncWriteArrayElem() if x.AnonInTestStruc.AI64slice0 == nil { r.EncodeNil() } else { z.F.EncSliceInt64V(x.AnonInTestStruc.AI64slice0, e) } // end block: if x.AnonInTestStruc.AI64slice0 slice == nil z.EncWriteArrayElem() if x.AnonInTestStruc.AUi64sliceN == nil { r.EncodeNil() } else { z.F.EncSliceUint64V(x.AnonInTestStruc.AUi64sliceN, e) } // end block: if x.AnonInTestStruc.AUi64sliceN slice == nil z.EncWriteArrayElem() if x.AnonInTestStruc.AMSU64N == nil { r.EncodeNil() } else { z.F.EncMapStringUint64V(x.AnonInTestStruc.AMSU64N, e) } // end block: if x.AnonInTestStruc.AMSU64N map == nil z.EncWriteArrayElem() if x.AnonInTestStruc.AMSU64E == nil { r.EncodeNil() } else { z.F.EncMapStringUint64V(x.AnonInTestStruc.AMSU64E, e) } // end block: if x.AnonInTestStruc.AMSU64E map == nil z.EncWriteArrayElem() yy112 := &x.NotAnon if yyxt113 := z.Extension(yy112); yyxt113 != nil { z.EncExtension(yy112, yyxt113) } else { yy112.CodecEncodeSelf(e) } if yyn54 { z.EncWriteArrayElem() r.EncodeNil() } else { z.EncWriteArrayElem() yy114 := *x.AnonInTestStrucSlim.P r.EncodeString(string(yy114)) } if yyn55 { z.EncWriteArrayElem() r.EncodeNil() } else { z.EncWriteArrayElem() if yyxt116 := z.Extension(x.NotAnonSlim); yyxt116 != nil { z.EncExtension(x.NotAnonSlim, yyxt116) } else { x.NotAnonSlim.CodecEncodeSelf(e) } } z.EncWriteArrayElem() if x.Nmap == nil { r.EncodeNil() } else { z.F.EncMapStringBoolV(x.Nmap, e) } // end block: if x.Nmap map == nil z.EncWriteArrayElem() if x.Nslice == nil { r.EncodeNil() } else { r.EncodeStringBytesRaw([]byte(x.Nslice)) } // end block: if x.Nslice slice == nil if yyn58 { z.EncWriteArrayElem() r.EncodeNil() } else { z.EncWriteArrayElem() yy119 := *x.Nint64 r.EncodeInt(int64(yy119)) } z.EncWriteArrayEnd() } else { z.EncWriteMapStart(56) if z.EncBasicHandle().Canonical { z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"AF32slice\"") } else { r.EncodeString(`AF32slice`) } z.EncWriteMapElemValue() if x.AnonInTestStruc.AF32slice == nil { r.EncodeNil() } else { z.F.EncSliceFloat32V(x.AnonInTestStruc.AF32slice, e) } // end block: if x.AnonInTestStruc.AF32slice slice == nil z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"AF64slice\"") } else { r.EncodeString(`AF64slice`) } z.EncWriteMapElemValue() if x.AnonInTestStruc.AF64slice == nil { r.EncodeNil() } else { z.F.EncSliceFloat64V(x.AnonInTestStruc.AF64slice, e) } // end block: if x.AnonInTestStruc.AF64slice slice == nil z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"AI16\"") } else { r.EncodeString(`AI16`) } z.EncWriteMapElemValue() r.EncodeInt(int64(x.AnonInTestStruc.AI16)) z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"AI64\"") } else { r.EncodeString(`AI64`) } z.EncWriteMapElemValue() r.EncodeInt(int64(x.AnonInTestStruc.AI64)) z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"AI64arr0\"") } else { r.EncodeString(`AI64arr0`) } z.EncWriteMapElemValue() yy125 := &x.AnonInTestStruc.AI64arr0 h.encArray0int64((*[0]int64)(yy125), e) z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"AI64arr8\"") } else { r.EncodeString(`AI64arr8`) } z.EncWriteMapElemValue() yy127 := &x.AnonInTestStruc.AI64arr8 h.encArray8int64((*[8]int64)(yy127), e) z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"AI64slice\"") } else { r.EncodeString(`AI64slice`) } z.EncWriteMapElemValue() if x.AnonInTestStruc.AI64slice == nil { r.EncodeNil() } else { z.F.EncSliceInt64V(x.AnonInTestStruc.AI64slice, e) } // end block: if x.AnonInTestStruc.AI64slice slice == nil z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"AI64slice0\"") } else { r.EncodeString(`AI64slice0`) } z.EncWriteMapElemValue() if x.AnonInTestStruc.AI64slice0 == nil { r.EncodeNil() } else { z.F.EncSliceInt64V(x.AnonInTestStruc.AI64slice0, e) } // end block: if x.AnonInTestStruc.AI64slice0 slice == nil z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"AMSS\"") } else { r.EncodeString(`AMSS`) } z.EncWriteMapElemValue() if x.AnonInTestStruc.AMSS == nil { r.EncodeNil() } else { z.F.EncMapStringStringV(x.AnonInTestStruc.AMSS, e) } // end block: if x.AnonInTestStruc.AMSS map == nil z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"AMSU64\"") } else { r.EncodeString(`AMSU64`) } z.EncWriteMapElemValue() if x.AnonInTestStruc.AMSU64 == nil { r.EncodeNil() } else { z.F.EncMapStringUint64V(x.AnonInTestStruc.AMSU64, e) } // end block: if x.AnonInTestStruc.AMSU64 map == nil z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"AMSU64E\"") } else { r.EncodeString(`AMSU64E`) } z.EncWriteMapElemValue() if x.AnonInTestStruc.AMSU64E == nil { r.EncodeNil() } else { z.F.EncMapStringUint64V(x.AnonInTestStruc.AMSU64E, e) } // end block: if x.AnonInTestStruc.AMSU64E map == nil z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"AMSU64N\"") } else { r.EncodeString(`AMSU64N`) } z.EncWriteMapElemValue() if x.AnonInTestStruc.AMSU64N == nil { r.EncodeNil() } else { z.F.EncMapStringUint64V(x.AnonInTestStruc.AMSU64N, e) } // end block: if x.AnonInTestStruc.AMSU64N map == nil z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"AS\"") } else { r.EncodeString(`AS`) } z.EncWriteMapElemValue() r.EncodeString(string(x.AnonInTestStruc.AS)) z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"ASslice\"") } else { r.EncodeString(`ASslice`) } z.EncWriteMapElemValue() if x.AnonInTestStruc.ASslice == nil { r.EncodeNil() } else { z.F.EncSliceStringV(x.AnonInTestStruc.ASslice, e) } // end block: if x.AnonInTestStruc.ASslice slice == nil z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"AUi64\"") } else { r.EncodeString(`AUi64`) } z.EncWriteMapElemValue() r.EncodeUint(uint64(x.AnonInTestStruc.AUi64)) z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"AUi64slice\"") } else { r.EncodeString(`AUi64slice`) } z.EncWriteMapElemValue() if x.AnonInTestStruc.AUi64slice == nil { r.EncodeNil() } else { z.F.EncSliceUint64V(x.AnonInTestStruc.AUi64slice, e) } // end block: if x.AnonInTestStruc.AUi64slice slice == nil z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"AUi64sliceN\"") } else { r.EncodeString(`AUi64sliceN`) } z.EncWriteMapElemValue() if x.AnonInTestStruc.AUi64sliceN == nil { r.EncodeNil() } else { z.F.EncSliceUint64V(x.AnonInTestStruc.AUi64sliceN, e) } // end block: if x.AnonInTestStruc.AUi64sliceN slice == nil z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"B\"") } else { r.EncodeString(`B`) } z.EncWriteMapElemValue() r.EncodeBool(bool(x.B)) z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"Bslice\"") } else { r.EncodeString(`Bslice`) } z.EncWriteMapElemValue() if x.Bslice == nil { r.EncodeNil() } else { z.F.EncSliceBoolV(x.Bslice, e) } // end block: if x.Bslice slice == nil z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"By\"") } else { r.EncodeString(`By`) } z.EncWriteMapElemValue() r.EncodeUint(uint64(x.By)) z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"Byslice\"") } else { r.EncodeString(`Byslice`) } z.EncWriteMapElemValue() if x.Byslice == nil { r.EncodeNil() } else { r.EncodeStringBytesRaw([]byte(x.Byslice)) } // end block: if x.Byslice slice == nil z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"BytesSlice\"") } else { r.EncodeString(`BytesSlice`) } z.EncWriteMapElemValue() if x.BytesSlice == nil { r.EncodeNil() } else { z.F.EncSliceBytesV(x.BytesSlice, e) } // end block: if x.BytesSlice slice == nil z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"F32\"") } else { r.EncodeString(`F32`) } z.EncWriteMapElemValue() r.EncodeFloat32(float32(x.F32)) z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"F64\"") } else { r.EncodeString(`F64`) } z.EncWriteMapElemValue() r.EncodeFloat64(float64(x.F64)) z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"I16\"") } else { r.EncodeString(`I16`) } z.EncWriteMapElemValue() r.EncodeInt(int64(x.I16)) z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"I16n\"") } else { r.EncodeString(`I16n`) } z.EncWriteMapElemValue() r.EncodeInt(int64(x.I16n)) z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"I32\"") } else { r.EncodeString(`I32`) } z.EncWriteMapElemValue() r.EncodeInt(int64(x.I32)) z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"I32n\"") } else { r.EncodeString(`I32n`) } z.EncWriteMapElemValue() r.EncodeInt(int64(x.I32n)) z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"I32slice\"") } else { r.EncodeString(`I32slice`) } z.EncWriteMapElemValue() if x.I32slice == nil { r.EncodeNil() } else { z.F.EncSliceInt32V(x.I32slice, e) } // end block: if x.I32slice slice == nil z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"I64\"") } else { r.EncodeString(`I64`) } z.EncWriteMapElemValue() r.EncodeInt(int64(x.I64)) z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"I64n\"") } else { r.EncodeString(`I64n`) } z.EncWriteMapElemValue() r.EncodeInt(int64(x.I64n)) z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"I64slice\"") } else { r.EncodeString(`I64slice`) } z.EncWriteMapElemValue() if x.I64slice == nil { r.EncodeNil() } else { z.F.EncSliceInt64V(x.I64slice, e) } // end block: if x.I64slice slice == nil z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"I8\"") } else { r.EncodeString(`I8`) } z.EncWriteMapElemValue() r.EncodeInt(int64(x.I8)) z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"I8n\"") } else { r.EncodeString(`I8n`) } z.EncWriteMapElemValue() r.EncodeInt(int64(x.I8n)) z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"Iptrslice\"") } else { r.EncodeString(`Iptrslice`) } z.EncWriteMapElemValue() if x.Iptrslice == nil { r.EncodeNil() } else { h.encSlicePtrtoint64(([]*int64)(x.Iptrslice), e) } // end block: if x.Iptrslice slice == nil z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"Msbytes\"") } else { r.EncodeString(`Msbytes`) } z.EncWriteMapElemValue() if x.Msbytes == nil { r.EncodeNil() } else { z.F.EncMapStringBytesV(x.Msbytes, e) } // end block: if x.Msbytes map == nil z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"Msint\"") } else { r.EncodeString(`Msint`) } z.EncWriteMapElemValue() if x.Msint == nil { r.EncodeNil() } else { z.F.EncMapStringIntV(x.Msint, e) } // end block: if x.Msint map == nil z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"MstrUi64T\"") } else { r.EncodeString(`MstrUi64T`) } z.EncWriteMapElemValue() if x.MstrUi64T == nil { r.EncodeNil() } else { h.encMapstringPtrtostringUint64T((map[string]*stringUint64T)(x.MstrUi64T), e) } // end block: if x.MstrUi64T map == nil z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"Nint64\"") } else { r.EncodeString(`Nint64`) } z.EncWriteMapElemValue() if yyn58 { r.EncodeNil() } else { yy161 := *x.Nint64 r.EncodeInt(int64(yy161)) } z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"Nmap\"") } else { r.EncodeString(`Nmap`) } z.EncWriteMapElemValue() if x.Nmap == nil { r.EncodeNil() } else { z.F.EncMapStringBoolV(x.Nmap, e) } // end block: if x.Nmap map == nil z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"NotAnon\"") } else { r.EncodeString(`NotAnon`) } z.EncWriteMapElemValue() yy164 := &x.NotAnon if yyxt165 := z.Extension(yy164); yyxt165 != nil { z.EncExtension(yy164, yyxt165) } else { yy164.CodecEncodeSelf(e) } z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"NotAnonSlim\"") } else { r.EncodeString(`NotAnonSlim`) } z.EncWriteMapElemValue() if yyn55 { r.EncodeNil() } else { if yyxt166 := z.Extension(x.NotAnonSlim); yyxt166 != nil { z.EncExtension(x.NotAnonSlim, yyxt166) } else { x.NotAnonSlim.CodecEncodeSelf(e) } } z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"Nslice\"") } else { r.EncodeString(`Nslice`) } z.EncWriteMapElemValue() if x.Nslice == nil { r.EncodeNil() } else { r.EncodeStringBytesRaw([]byte(x.Nslice)) } // end block: if x.Nslice slice == nil z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"P\"") } else { r.EncodeString(`P`) } z.EncWriteMapElemValue() if yyn54 { r.EncodeNil() } else { yy168 := *x.AnonInTestStrucSlim.P r.EncodeString(string(yy168)) } z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"S\"") } else { r.EncodeString(`S`) } z.EncWriteMapElemValue() r.EncodeString(string(x.S)) z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"Simplef\"") } else { r.EncodeString(`Simplef`) } z.EncWriteMapElemValue() yy171 := &x.Simplef if yyxt172 := z.Extension(yy171); yyxt172 != nil { z.EncExtension(yy171, yyxt172) } else { yy171.CodecEncodeSelf(e) } z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"Sslice\"") } else { r.EncodeString(`Sslice`) } z.EncWriteMapElemValue() if x.Sslice == nil { r.EncodeNil() } else { z.F.EncSliceStringV(x.Sslice, e) } // end block: if x.Sslice slice == nil z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"SstrUi64T\"") } else { r.EncodeString(`SstrUi64T`) } z.EncWriteMapElemValue() if x.SstrUi64T == nil { r.EncodeNil() } else { h.encSlicestringUint64T(([]stringUint64T)(x.SstrUi64T), e) } // end block: if x.SstrUi64T slice == nil z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"Ui16\"") } else { r.EncodeString(`Ui16`) } z.EncWriteMapElemValue() r.EncodeUint(uint64(x.Ui16)) z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"Ui32\"") } else { r.EncodeString(`Ui32`) } z.EncWriteMapElemValue() r.EncodeUint(uint64(x.Ui32)) z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"Ui64\"") } else { r.EncodeString(`Ui64`) } z.EncWriteMapElemValue() r.EncodeUint(uint64(x.Ui64)) z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"Ui64slice\"") } else { r.EncodeString(`Ui64slice`) } z.EncWriteMapElemValue() if x.Ui64slice == nil { r.EncodeNil() } else { z.F.EncSliceUint64V(x.Ui64slice, e) } // end block: if x.Ui64slice slice == nil z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"Ui8\"") } else { r.EncodeString(`Ui8`) } z.EncWriteMapElemValue() r.EncodeUint(uint64(x.Ui8)) z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"Ui8slice\"") } else { r.EncodeString(`Ui8slice`) } z.EncWriteMapElemValue() if x.Ui8slice == nil { r.EncodeNil() } else { r.EncodeStringBytesRaw([]byte(x.Ui8slice)) } // end block: if x.Ui8slice slice == nil z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"WrapSliceInt64\"") } else { r.EncodeString(`WrapSliceInt64`) } z.EncWriteMapElemValue() if yyxt181 := z.Extension(x.WrapSliceInt64); yyxt181 != nil { z.EncExtension(x.WrapSliceInt64, yyxt181) } else { x.WrapSliceInt64.CodecEncodeSelf(e) } z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"WrapSliceString\"") } else { r.EncodeString(`WrapSliceString`) } z.EncWriteMapElemValue() if yyxt182 := z.Extension(x.WrapSliceString); yyxt182 != nil { z.EncExtension(x.WrapSliceString, yyxt182) } else { x.WrapSliceString.CodecEncodeSelf(e) } } else { z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"S\"") } else { r.EncodeString(`S`) } z.EncWriteMapElemValue() r.EncodeString(string(x.S)) z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"I64\"") } else { r.EncodeString(`I64`) } z.EncWriteMapElemValue() r.EncodeInt(int64(x.I64)) z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"I32\"") } else { r.EncodeString(`I32`) } z.EncWriteMapElemValue() r.EncodeInt(int64(x.I32)) z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"I16\"") } else { r.EncodeString(`I16`) } z.EncWriteMapElemValue() r.EncodeInt(int64(x.I16)) z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"I8\"") } else { r.EncodeString(`I8`) } z.EncWriteMapElemValue() r.EncodeInt(int64(x.I8)) z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"I64n\"") } else { r.EncodeString(`I64n`) } z.EncWriteMapElemValue() r.EncodeInt(int64(x.I64n)) z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"I32n\"") } else { r.EncodeString(`I32n`) } z.EncWriteMapElemValue() r.EncodeInt(int64(x.I32n)) z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"I16n\"") } else { r.EncodeString(`I16n`) } z.EncWriteMapElemValue() r.EncodeInt(int64(x.I16n)) z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"I8n\"") } else { r.EncodeString(`I8n`) } z.EncWriteMapElemValue() r.EncodeInt(int64(x.I8n)) z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"Ui64\"") } else { r.EncodeString(`Ui64`) } z.EncWriteMapElemValue() r.EncodeUint(uint64(x.Ui64)) z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"Ui32\"") } else { r.EncodeString(`Ui32`) } z.EncWriteMapElemValue() r.EncodeUint(uint64(x.Ui32)) z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"Ui16\"") } else { r.EncodeString(`Ui16`) } z.EncWriteMapElemValue() r.EncodeUint(uint64(x.Ui16)) z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"Ui8\"") } else { r.EncodeString(`Ui8`) } z.EncWriteMapElemValue() r.EncodeUint(uint64(x.Ui8)) z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"F64\"") } else { r.EncodeString(`F64`) } z.EncWriteMapElemValue() r.EncodeFloat64(float64(x.F64)) z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"F32\"") } else { r.EncodeString(`F32`) } z.EncWriteMapElemValue() r.EncodeFloat32(float32(x.F32)) z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"B\"") } else { r.EncodeString(`B`) } z.EncWriteMapElemValue() r.EncodeBool(bool(x.B)) z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"By\"") } else { r.EncodeString(`By`) } z.EncWriteMapElemValue() r.EncodeUint(uint64(x.By)) z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"Sslice\"") } else { r.EncodeString(`Sslice`) } z.EncWriteMapElemValue() if x.Sslice == nil { r.EncodeNil() } else { z.F.EncSliceStringV(x.Sslice, e) } // end block: if x.Sslice slice == nil z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"I64slice\"") } else { r.EncodeString(`I64slice`) } z.EncWriteMapElemValue() if x.I64slice == nil { r.EncodeNil() } else { z.F.EncSliceInt64V(x.I64slice, e) } // end block: if x.I64slice slice == nil z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"I32slice\"") } else { r.EncodeString(`I32slice`) } z.EncWriteMapElemValue() if x.I32slice == nil { r.EncodeNil() } else { z.F.EncSliceInt32V(x.I32slice, e) } // end block: if x.I32slice slice == nil z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"Ui64slice\"") } else { r.EncodeString(`Ui64slice`) } z.EncWriteMapElemValue() if x.Ui64slice == nil { r.EncodeNil() } else { z.F.EncSliceUint64V(x.Ui64slice, e) } // end block: if x.Ui64slice slice == nil z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"Ui8slice\"") } else { r.EncodeString(`Ui8slice`) } z.EncWriteMapElemValue() if x.Ui8slice == nil { r.EncodeNil() } else { r.EncodeStringBytesRaw([]byte(x.Ui8slice)) } // end block: if x.Ui8slice slice == nil z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"Bslice\"") } else { r.EncodeString(`Bslice`) } z.EncWriteMapElemValue() if x.Bslice == nil { r.EncodeNil() } else { z.F.EncSliceBoolV(x.Bslice, e) } // end block: if x.Bslice slice == nil z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"Byslice\"") } else { r.EncodeString(`Byslice`) } z.EncWriteMapElemValue() if x.Byslice == nil { r.EncodeNil() } else { r.EncodeStringBytesRaw([]byte(x.Byslice)) } // end block: if x.Byslice slice == nil z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"BytesSlice\"") } else { r.EncodeString(`BytesSlice`) } z.EncWriteMapElemValue() if x.BytesSlice == nil { r.EncodeNil() } else { z.F.EncSliceBytesV(x.BytesSlice, e) } // end block: if x.BytesSlice slice == nil z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"Iptrslice\"") } else { r.EncodeString(`Iptrslice`) } z.EncWriteMapElemValue() if x.Iptrslice == nil { r.EncodeNil() } else { h.encSlicePtrtoint64(([]*int64)(x.Iptrslice), e) } // end block: if x.Iptrslice slice == nil z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"WrapSliceInt64\"") } else { r.EncodeString(`WrapSliceInt64`) } z.EncWriteMapElemValue() if yyxt209 := z.Extension(x.WrapSliceInt64); yyxt209 != nil { z.EncExtension(x.WrapSliceInt64, yyxt209) } else { x.WrapSliceInt64.CodecEncodeSelf(e) } z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"WrapSliceString\"") } else { r.EncodeString(`WrapSliceString`) } z.EncWriteMapElemValue() if yyxt210 := z.Extension(x.WrapSliceString); yyxt210 != nil { z.EncExtension(x.WrapSliceString, yyxt210) } else { x.WrapSliceString.CodecEncodeSelf(e) } z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"Msint\"") } else { r.EncodeString(`Msint`) } z.EncWriteMapElemValue() if x.Msint == nil { r.EncodeNil() } else { z.F.EncMapStringIntV(x.Msint, e) } // end block: if x.Msint map == nil z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"Msbytes\"") } else { r.EncodeString(`Msbytes`) } z.EncWriteMapElemValue() if x.Msbytes == nil { r.EncodeNil() } else { z.F.EncMapStringBytesV(x.Msbytes, e) } // end block: if x.Msbytes map == nil z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"Simplef\"") } else { r.EncodeString(`Simplef`) } z.EncWriteMapElemValue() yy213 := &x.Simplef if yyxt214 := z.Extension(yy213); yyxt214 != nil { z.EncExtension(yy213, yyxt214) } else { yy213.CodecEncodeSelf(e) } z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"SstrUi64T\"") } else { r.EncodeString(`SstrUi64T`) } z.EncWriteMapElemValue() if x.SstrUi64T == nil { r.EncodeNil() } else { h.encSlicestringUint64T(([]stringUint64T)(x.SstrUi64T), e) } // end block: if x.SstrUi64T slice == nil z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"MstrUi64T\"") } else { r.EncodeString(`MstrUi64T`) } z.EncWriteMapElemValue() if x.MstrUi64T == nil { r.EncodeNil() } else { h.encMapstringPtrtostringUint64T((map[string]*stringUint64T)(x.MstrUi64T), e) } // end block: if x.MstrUi64T map == nil z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"AS\"") } else { r.EncodeString(`AS`) } z.EncWriteMapElemValue() r.EncodeString(string(x.AnonInTestStruc.AS)) z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"AI64\"") } else { r.EncodeString(`AI64`) } z.EncWriteMapElemValue() r.EncodeInt(int64(x.AnonInTestStruc.AI64)) z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"AI16\"") } else { r.EncodeString(`AI16`) } z.EncWriteMapElemValue() r.EncodeInt(int64(x.AnonInTestStruc.AI16)) z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"AUi64\"") } else { r.EncodeString(`AUi64`) } z.EncWriteMapElemValue() r.EncodeUint(uint64(x.AnonInTestStruc.AUi64)) z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"ASslice\"") } else { r.EncodeString(`ASslice`) } z.EncWriteMapElemValue() if x.AnonInTestStruc.ASslice == nil { r.EncodeNil() } else { z.F.EncSliceStringV(x.AnonInTestStruc.ASslice, e) } // end block: if x.AnonInTestStruc.ASslice slice == nil z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"AI64slice\"") } else { r.EncodeString(`AI64slice`) } z.EncWriteMapElemValue() if x.AnonInTestStruc.AI64slice == nil { r.EncodeNil() } else { z.F.EncSliceInt64V(x.AnonInTestStruc.AI64slice, e) } // end block: if x.AnonInTestStruc.AI64slice slice == nil z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"AUi64slice\"") } else { r.EncodeString(`AUi64slice`) } z.EncWriteMapElemValue() if x.AnonInTestStruc.AUi64slice == nil { r.EncodeNil() } else { z.F.EncSliceUint64V(x.AnonInTestStruc.AUi64slice, e) } // end block: if x.AnonInTestStruc.AUi64slice slice == nil z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"AF64slice\"") } else { r.EncodeString(`AF64slice`) } z.EncWriteMapElemValue() if x.AnonInTestStruc.AF64slice == nil { r.EncodeNil() } else { z.F.EncSliceFloat64V(x.AnonInTestStruc.AF64slice, e) } // end block: if x.AnonInTestStruc.AF64slice slice == nil z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"AF32slice\"") } else { r.EncodeString(`AF32slice`) } z.EncWriteMapElemValue() if x.AnonInTestStruc.AF32slice == nil { r.EncodeNil() } else { z.F.EncSliceFloat32V(x.AnonInTestStruc.AF32slice, e) } // end block: if x.AnonInTestStruc.AF32slice slice == nil z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"AMSS\"") } else { r.EncodeString(`AMSS`) } z.EncWriteMapElemValue() if x.AnonInTestStruc.AMSS == nil { r.EncodeNil() } else { z.F.EncMapStringStringV(x.AnonInTestStruc.AMSS, e) } // end block: if x.AnonInTestStruc.AMSS map == nil z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"AMSU64\"") } else { r.EncodeString(`AMSU64`) } z.EncWriteMapElemValue() if x.AnonInTestStruc.AMSU64 == nil { r.EncodeNil() } else { z.F.EncMapStringUint64V(x.AnonInTestStruc.AMSU64, e) } // end block: if x.AnonInTestStruc.AMSU64 map == nil z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"AI64arr8\"") } else { r.EncodeString(`AI64arr8`) } z.EncWriteMapElemValue() yy228 := &x.AnonInTestStruc.AI64arr8 h.encArray8int64((*[8]int64)(yy228), e) z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"AI64arr0\"") } else { r.EncodeString(`AI64arr0`) } z.EncWriteMapElemValue() yy230 := &x.AnonInTestStruc.AI64arr0 h.encArray0int64((*[0]int64)(yy230), e) z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"AI64slice0\"") } else { r.EncodeString(`AI64slice0`) } z.EncWriteMapElemValue() if x.AnonInTestStruc.AI64slice0 == nil { r.EncodeNil() } else { z.F.EncSliceInt64V(x.AnonInTestStruc.AI64slice0, e) } // end block: if x.AnonInTestStruc.AI64slice0 slice == nil z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"AUi64sliceN\"") } else { r.EncodeString(`AUi64sliceN`) } z.EncWriteMapElemValue() if x.AnonInTestStruc.AUi64sliceN == nil { r.EncodeNil() } else { z.F.EncSliceUint64V(x.AnonInTestStruc.AUi64sliceN, e) } // end block: if x.AnonInTestStruc.AUi64sliceN slice == nil z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"AMSU64N\"") } else { r.EncodeString(`AMSU64N`) } z.EncWriteMapElemValue() if x.AnonInTestStruc.AMSU64N == nil { r.EncodeNil() } else { z.F.EncMapStringUint64V(x.AnonInTestStruc.AMSU64N, e) } // end block: if x.AnonInTestStruc.AMSU64N map == nil z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"AMSU64E\"") } else { r.EncodeString(`AMSU64E`) } z.EncWriteMapElemValue() if x.AnonInTestStruc.AMSU64E == nil { r.EncodeNil() } else { z.F.EncMapStringUint64V(x.AnonInTestStruc.AMSU64E, e) } // end block: if x.AnonInTestStruc.AMSU64E map == nil z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"NotAnon\"") } else { r.EncodeString(`NotAnon`) } z.EncWriteMapElemValue() yy236 := &x.NotAnon if yyxt237 := z.Extension(yy236); yyxt237 != nil { z.EncExtension(yy236, yyxt237) } else { yy236.CodecEncodeSelf(e) } z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"P\"") } else { r.EncodeString(`P`) } z.EncWriteMapElemValue() if yyn54 { r.EncodeNil() } else { yy238 := *x.AnonInTestStrucSlim.P r.EncodeString(string(yy238)) } z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"NotAnonSlim\"") } else { r.EncodeString(`NotAnonSlim`) } z.EncWriteMapElemValue() if yyn55 { r.EncodeNil() } else { if yyxt240 := z.Extension(x.NotAnonSlim); yyxt240 != nil { z.EncExtension(x.NotAnonSlim, yyxt240) } else { x.NotAnonSlim.CodecEncodeSelf(e) } } z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"Nmap\"") } else { r.EncodeString(`Nmap`) } z.EncWriteMapElemValue() if x.Nmap == nil { r.EncodeNil() } else { z.F.EncMapStringBoolV(x.Nmap, e) } // end block: if x.Nmap map == nil z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"Nslice\"") } else { r.EncodeString(`Nslice`) } z.EncWriteMapElemValue() if x.Nslice == nil { r.EncodeNil() } else { r.EncodeStringBytesRaw([]byte(x.Nslice)) } // end block: if x.Nslice slice == nil z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"Nint64\"") } else { r.EncodeString(`Nint64`) } z.EncWriteMapElemValue() if yyn58 { r.EncodeNil() } else { yy243 := *x.Nint64 r.EncodeInt(int64(yy243)) } } z.EncWriteMapEnd() } } } func (x *TestStrucCommon) CodecDecodeSelf(d *Decoder) { var h codecSelfer19780 z, r := GenHelper().Decoder(d) _, _, _ = h, z, r yyct2 := r.ContainerType() if yyct2 == codecSelferValueTypeNil19780 { *(x) = TestStrucCommon{} } else if yyct2 == codecSelferValueTypeMap19780 { yyl2 := z.DecReadMapStart() if yyl2 == 0 { } else { x.codecDecodeSelfFromMap(yyl2, d) } z.DecReadMapEnd() } else if yyct2 == codecSelferValueTypeArray19780 { yyl2 := z.DecReadArrayStart() if yyl2 != 0 { x.codecDecodeSelfFromArray(yyl2, d) } z.DecReadArrayEnd() } else { panic(errCodecSelferOnlyMapOrArrayEncodeToStruct19780) } } func (x *TestStrucCommon) codecDecodeSelfFromMap(l int, d *Decoder) { var h codecSelfer19780 z, r := GenHelper().Decoder(d) _, _, _ = h, z, r var yyhl3 bool = l >= 0 for yyj3 := 0; ; yyj3++ { if yyhl3 { if yyj3 >= l { break } } else { if z.DecCheckBreak() { break } } z.DecReadMapElemKey() yys3 := r.DecodeStringAsBytes() z.DecReadMapElemValue() switch string(yys3) { case "S": x.S = (string)(z.DecStringZC(r.DecodeStringAsBytes())) case "I64": x.I64 = (int64)(r.DecodeInt64()) case "I32": x.I32 = (int32)(z.C.IntV(r.DecodeInt64(), 32)) case "I16": x.I16 = (int16)(z.C.IntV(r.DecodeInt64(), 16)) case "I8": x.I8 = (int8)(z.C.IntV(r.DecodeInt64(), 8)) case "I64n": x.I64n = (int64)(r.DecodeInt64()) case "I32n": x.I32n = (int32)(z.C.IntV(r.DecodeInt64(), 32)) case "I16n": x.I16n = (int16)(z.C.IntV(r.DecodeInt64(), 16)) case "I8n": x.I8n = (int8)(z.C.IntV(r.DecodeInt64(), 8)) case "Ui64": x.Ui64 = (uint64)(r.DecodeUint64()) case "Ui32": x.Ui32 = (uint32)(z.C.UintV(r.DecodeUint64(), 32)) case "Ui16": x.Ui16 = (uint16)(z.C.UintV(r.DecodeUint64(), 16)) case "Ui8": x.Ui8 = (uint8)(z.C.UintV(r.DecodeUint64(), 8)) case "F64": x.F64 = (float64)(r.DecodeFloat64()) case "F32": x.F32 = (float32)(z.DecDecodeFloat32()) case "B": x.B = (bool)(r.DecodeBool()) case "By": x.By = (uint8)(z.C.UintV(r.DecodeUint64(), 8)) case "Sslice": z.F.DecSliceStringX(&x.Sslice, d) case "I64slice": z.F.DecSliceInt64X(&x.I64slice, d) case "I32slice": z.F.DecSliceInt32X(&x.I32slice, d) case "Ui64slice": z.F.DecSliceUint64X(&x.Ui64slice, d) case "Ui8slice": x.Ui8slice = z.DecodeBytesInto(([]byte)(x.Ui8slice)) case "Bslice": z.F.DecSliceBoolX(&x.Bslice, d) case "Byslice": x.Byslice = z.DecodeBytesInto(([]byte)(x.Byslice)) case "BytesSlice": z.F.DecSliceBytesX(&x.BytesSlice, d) case "Iptrslice": h.decSlicePtrtoint64((*[]*int64)(&x.Iptrslice), d) case "WrapSliceInt64": if yyxt40 := z.Extension(x.WrapSliceInt64); yyxt40 != nil { z.DecExtension(&x.WrapSliceInt64, yyxt40) } else { x.WrapSliceInt64.CodecDecodeSelf(d) } case "WrapSliceString": if yyxt42 := z.Extension(x.WrapSliceString); yyxt42 != nil { z.DecExtension(&x.WrapSliceString, yyxt42) } else { x.WrapSliceString.CodecDecodeSelf(d) } case "Msint": z.F.DecMapStringIntX(&x.Msint, d) case "Msbytes": z.F.DecMapStringBytesX(&x.Msbytes, d) case "Simplef": if yyxt48 := z.Extension(x.Simplef); yyxt48 != nil { z.DecExtension(&x.Simplef, yyxt48) } else { x.Simplef.CodecDecodeSelf(d) } case "SstrUi64T": h.decSlicestringUint64T((*[]stringUint64T)(&x.SstrUi64T), d) case "MstrUi64T": h.decMapstringPtrtostringUint64T((*map[string]*stringUint64T)(&x.MstrUi64T), d) case "AS": x.AnonInTestStruc.AS = (string)(z.DecStringZC(r.DecodeStringAsBytes())) case "AI64": x.AnonInTestStruc.AI64 = (int64)(r.DecodeInt64()) case "AI16": x.AnonInTestStruc.AI16 = (int16)(z.C.IntV(r.DecodeInt64(), 16)) case "AUi64": x.AnonInTestStruc.AUi64 = (uint64)(r.DecodeUint64()) case "ASslice": z.F.DecSliceStringX(&x.AnonInTestStruc.ASslice, d) case "AI64slice": z.F.DecSliceInt64X(&x.AnonInTestStruc.AI64slice, d) case "AUi64slice": z.F.DecSliceUint64X(&x.AnonInTestStruc.AUi64slice, d) case "AF64slice": z.F.DecSliceFloat64X(&x.AnonInTestStruc.AF64slice, d) case "AF32slice": z.F.DecSliceFloat32X(&x.AnonInTestStruc.AF32slice, d) case "AMSS": z.F.DecMapStringStringX(&x.AnonInTestStruc.AMSS, d) case "AMSU64": z.F.DecMapStringUint64X(&x.AnonInTestStruc.AMSU64, d) case "AI64arr8": h.decArray8int64((*[8]int64)(&x.AnonInTestStruc.AI64arr8), d) case "AI64arr0": h.decArray0int64((*[0]int64)(&x.AnonInTestStruc.AI64arr0), d) case "AI64slice0": z.F.DecSliceInt64X(&x.AnonInTestStruc.AI64slice0, d) case "AUi64sliceN": z.F.DecSliceUint64X(&x.AnonInTestStruc.AUi64sliceN, d) case "AMSU64N": z.F.DecMapStringUint64X(&x.AnonInTestStruc.AMSU64N, d) case "AMSU64E": z.F.DecMapStringUint64X(&x.AnonInTestStruc.AMSU64E, d) case "NotAnon": if yyxt84 := z.Extension(x.NotAnon); yyxt84 != nil { z.DecExtension(&x.NotAnon, yyxt84) } else { x.NotAnon.CodecDecodeSelf(d) } case "P": if r.TryNil() { if x.AnonInTestStrucSlim != nil && x.AnonInTestStrucSlim.P != nil { // remove the if-true x.AnonInTestStrucSlim.P = nil } } else { if x.AnonInTestStrucSlim == nil { x.AnonInTestStrucSlim = new(AnonInTestStrucSlim) } if x.AnonInTestStrucSlim.P == nil { x.AnonInTestStrucSlim.P = new(string) } *x.AnonInTestStrucSlim.P = (string)(z.DecStringZC(r.DecodeStringAsBytes())) } case "NotAnonSlim": if r.TryNil() { if x.NotAnonSlim != nil { // remove the if-true x.NotAnonSlim = nil } } else { if x.NotAnonSlim == nil { x.NotAnonSlim = new(AnonInTestStrucSlim) } if yyxt88 := z.Extension(x.NotAnonSlim); yyxt88 != nil { z.DecExtension(x.NotAnonSlim, yyxt88) } else { x.NotAnonSlim.CodecDecodeSelf(d) } } case "Nmap": z.F.DecMapStringBoolX(&x.Nmap, d) case "Nslice": x.Nslice = z.DecodeBytesInto(([]byte)(x.Nslice)) case "Nint64": if r.TryNil() { if x.Nint64 != nil { // remove the if-true x.Nint64 = nil } } else { if x.Nint64 == nil { x.Nint64 = new(int64) } *x.Nint64 = (int64)(r.DecodeInt64()) } default: z.DecStructFieldNotFound(-1, string(yys3)) } // end switch yys3 } // end for yyj3 } func (x *TestStrucCommon) codecDecodeSelfFromArray(l int, d *Decoder) { var h codecSelfer19780 z, r := GenHelper().Decoder(d) _, _, _ = h, z, r var yyj95 int var yyb95 bool var yyhl95 bool = l >= 0 yyj95++ if yyhl95 { yyb95 = yyj95 > l } else { yyb95 = z.DecCheckBreak() } if yyb95 { z.DecReadArrayEnd() return } z.DecReadArrayElem() x.S = (string)(z.DecStringZC(r.DecodeStringAsBytes())) yyj95++ if yyhl95 { yyb95 = yyj95 > l } else { yyb95 = z.DecCheckBreak() } if yyb95 { z.DecReadArrayEnd() return } z.DecReadArrayElem() x.I64 = (int64)(r.DecodeInt64()) yyj95++ if yyhl95 { yyb95 = yyj95 > l } else { yyb95 = z.DecCheckBreak() } if yyb95 { z.DecReadArrayEnd() return } z.DecReadArrayElem() x.I32 = (int32)(z.C.IntV(r.DecodeInt64(), 32)) yyj95++ if yyhl95 { yyb95 = yyj95 > l } else { yyb95 = z.DecCheckBreak() } if yyb95 { z.DecReadArrayEnd() return } z.DecReadArrayElem() x.I16 = (int16)(z.C.IntV(r.DecodeInt64(), 16)) yyj95++ if yyhl95 { yyb95 = yyj95 > l } else { yyb95 = z.DecCheckBreak() } if yyb95 { z.DecReadArrayEnd() return } z.DecReadArrayElem() x.I8 = (int8)(z.C.IntV(r.DecodeInt64(), 8)) yyj95++ if yyhl95 { yyb95 = yyj95 > l } else { yyb95 = z.DecCheckBreak() } if yyb95 { z.DecReadArrayEnd() return } z.DecReadArrayElem() x.I64n = (int64)(r.DecodeInt64()) yyj95++ if yyhl95 { yyb95 = yyj95 > l } else { yyb95 = z.DecCheckBreak() } if yyb95 { z.DecReadArrayEnd() return } z.DecReadArrayElem() x.I32n = (int32)(z.C.IntV(r.DecodeInt64(), 32)) yyj95++ if yyhl95 { yyb95 = yyj95 > l } else { yyb95 = z.DecCheckBreak() } if yyb95 { z.DecReadArrayEnd() return } z.DecReadArrayElem() x.I16n = (int16)(z.C.IntV(r.DecodeInt64(), 16)) yyj95++ if yyhl95 { yyb95 = yyj95 > l } else { yyb95 = z.DecCheckBreak() } if yyb95 { z.DecReadArrayEnd() return } z.DecReadArrayElem() x.I8n = (int8)(z.C.IntV(r.DecodeInt64(), 8)) yyj95++ if yyhl95 { yyb95 = yyj95 > l } else { yyb95 = z.DecCheckBreak() } if yyb95 { z.DecReadArrayEnd() return } z.DecReadArrayElem() x.Ui64 = (uint64)(r.DecodeUint64()) yyj95++ if yyhl95 { yyb95 = yyj95 > l } else { yyb95 = z.DecCheckBreak() } if yyb95 { z.DecReadArrayEnd() return } z.DecReadArrayElem() x.Ui32 = (uint32)(z.C.UintV(r.DecodeUint64(), 32)) yyj95++ if yyhl95 { yyb95 = yyj95 > l } else { yyb95 = z.DecCheckBreak() } if yyb95 { z.DecReadArrayEnd() return } z.DecReadArrayElem() x.Ui16 = (uint16)(z.C.UintV(r.DecodeUint64(), 16)) yyj95++ if yyhl95 { yyb95 = yyj95 > l } else { yyb95 = z.DecCheckBreak() } if yyb95 { z.DecReadArrayEnd() return } z.DecReadArrayElem() x.Ui8 = (uint8)(z.C.UintV(r.DecodeUint64(), 8)) yyj95++ if yyhl95 { yyb95 = yyj95 > l } else { yyb95 = z.DecCheckBreak() } if yyb95 { z.DecReadArrayEnd() return } z.DecReadArrayElem() x.F64 = (float64)(r.DecodeFloat64()) yyj95++ if yyhl95 { yyb95 = yyj95 > l } else { yyb95 = z.DecCheckBreak() } if yyb95 { z.DecReadArrayEnd() return } z.DecReadArrayElem() x.F32 = (float32)(z.DecDecodeFloat32()) yyj95++ if yyhl95 { yyb95 = yyj95 > l } else { yyb95 = z.DecCheckBreak() } if yyb95 { z.DecReadArrayEnd() return } z.DecReadArrayElem() x.B = (bool)(r.DecodeBool()) yyj95++ if yyhl95 { yyb95 = yyj95 > l } else { yyb95 = z.DecCheckBreak() } if yyb95 { z.DecReadArrayEnd() return } z.DecReadArrayElem() x.By = (uint8)(z.C.UintV(r.DecodeUint64(), 8)) yyj95++ if yyhl95 { yyb95 = yyj95 > l } else { yyb95 = z.DecCheckBreak() } if yyb95 { z.DecReadArrayEnd() return } z.DecReadArrayElem() z.F.DecSliceStringX(&x.Sslice, d) yyj95++ if yyhl95 { yyb95 = yyj95 > l } else { yyb95 = z.DecCheckBreak() } if yyb95 { z.DecReadArrayEnd() return } z.DecReadArrayElem() z.F.DecSliceInt64X(&x.I64slice, d) yyj95++ if yyhl95 { yyb95 = yyj95 > l } else { yyb95 = z.DecCheckBreak() } if yyb95 { z.DecReadArrayEnd() return } z.DecReadArrayElem() z.F.DecSliceInt32X(&x.I32slice, d) yyj95++ if yyhl95 { yyb95 = yyj95 > l } else { yyb95 = z.DecCheckBreak() } if yyb95 { z.DecReadArrayEnd() return } z.DecReadArrayElem() z.F.DecSliceUint64X(&x.Ui64slice, d) yyj95++ if yyhl95 { yyb95 = yyj95 > l } else { yyb95 = z.DecCheckBreak() } if yyb95 { z.DecReadArrayEnd() return } z.DecReadArrayElem() x.Ui8slice = z.DecodeBytesInto(([]byte)(x.Ui8slice)) yyj95++ if yyhl95 { yyb95 = yyj95 > l } else { yyb95 = z.DecCheckBreak() } if yyb95 { z.DecReadArrayEnd() return } z.DecReadArrayElem() z.F.DecSliceBoolX(&x.Bslice, d) yyj95++ if yyhl95 { yyb95 = yyj95 > l } else { yyb95 = z.DecCheckBreak() } if yyb95 { z.DecReadArrayEnd() return } z.DecReadArrayElem() x.Byslice = z.DecodeBytesInto(([]byte)(x.Byslice)) yyj95++ if yyhl95 { yyb95 = yyj95 > l } else { yyb95 = z.DecCheckBreak() } if yyb95 { z.DecReadArrayEnd() return } z.DecReadArrayElem() z.F.DecSliceBytesX(&x.BytesSlice, d) yyj95++ if yyhl95 { yyb95 = yyj95 > l } else { yyb95 = z.DecCheckBreak() } if yyb95 { z.DecReadArrayEnd() return } z.DecReadArrayElem() h.decSlicePtrtoint64((*[]*int64)(&x.Iptrslice), d) yyj95++ if yyhl95 { yyb95 = yyj95 > l } else { yyb95 = z.DecCheckBreak() } if yyb95 { z.DecReadArrayEnd() return } z.DecReadArrayElem() if yyxt132 := z.Extension(x.WrapSliceInt64); yyxt132 != nil { z.DecExtension(&x.WrapSliceInt64, yyxt132) } else { x.WrapSliceInt64.CodecDecodeSelf(d) } yyj95++ if yyhl95 { yyb95 = yyj95 > l } else { yyb95 = z.DecCheckBreak() } if yyb95 { z.DecReadArrayEnd() return } z.DecReadArrayElem() if yyxt134 := z.Extension(x.WrapSliceString); yyxt134 != nil { z.DecExtension(&x.WrapSliceString, yyxt134) } else { x.WrapSliceString.CodecDecodeSelf(d) } yyj95++ if yyhl95 { yyb95 = yyj95 > l } else { yyb95 = z.DecCheckBreak() } if yyb95 { z.DecReadArrayEnd() return } z.DecReadArrayElem() z.F.DecMapStringIntX(&x.Msint, d) yyj95++ if yyhl95 { yyb95 = yyj95 > l } else { yyb95 = z.DecCheckBreak() } if yyb95 { z.DecReadArrayEnd() return } z.DecReadArrayElem() z.F.DecMapStringBytesX(&x.Msbytes, d) yyj95++ if yyhl95 { yyb95 = yyj95 > l } else { yyb95 = z.DecCheckBreak() } if yyb95 { z.DecReadArrayEnd() return } z.DecReadArrayElem() if yyxt140 := z.Extension(x.Simplef); yyxt140 != nil { z.DecExtension(&x.Simplef, yyxt140) } else { x.Simplef.CodecDecodeSelf(d) } yyj95++ if yyhl95 { yyb95 = yyj95 > l } else { yyb95 = z.DecCheckBreak() } if yyb95 { z.DecReadArrayEnd() return } z.DecReadArrayElem() h.decSlicestringUint64T((*[]stringUint64T)(&x.SstrUi64T), d) yyj95++ if yyhl95 { yyb95 = yyj95 > l } else { yyb95 = z.DecCheckBreak() } if yyb95 { z.DecReadArrayEnd() return } z.DecReadArrayElem() h.decMapstringPtrtostringUint64T((*map[string]*stringUint64T)(&x.MstrUi64T), d) yyj95++ if yyhl95 { yyb95 = yyj95 > l } else { yyb95 = z.DecCheckBreak() } if yyb95 { z.DecReadArrayEnd() return } z.DecReadArrayElem() x.AnonInTestStruc.AS = (string)(z.DecStringZC(r.DecodeStringAsBytes())) yyj95++ if yyhl95 { yyb95 = yyj95 > l } else { yyb95 = z.DecCheckBreak() } if yyb95 { z.DecReadArrayEnd() return } z.DecReadArrayElem() x.AnonInTestStruc.AI64 = (int64)(r.DecodeInt64()) yyj95++ if yyhl95 { yyb95 = yyj95 > l } else { yyb95 = z.DecCheckBreak() } if yyb95 { z.DecReadArrayEnd() return } z.DecReadArrayElem() x.AnonInTestStruc.AI16 = (int16)(z.C.IntV(r.DecodeInt64(), 16)) yyj95++ if yyhl95 { yyb95 = yyj95 > l } else { yyb95 = z.DecCheckBreak() } if yyb95 { z.DecReadArrayEnd() return } z.DecReadArrayElem() x.AnonInTestStruc.AUi64 = (uint64)(r.DecodeUint64()) yyj95++ if yyhl95 { yyb95 = yyj95 > l } else { yyb95 = z.DecCheckBreak() } if yyb95 { z.DecReadArrayEnd() return } z.DecReadArrayElem() z.F.DecSliceStringX(&x.AnonInTestStruc.ASslice, d) yyj95++ if yyhl95 { yyb95 = yyj95 > l } else { yyb95 = z.DecCheckBreak() } if yyb95 { z.DecReadArrayEnd() return } z.DecReadArrayElem() z.F.DecSliceInt64X(&x.AnonInTestStruc.AI64slice, d) yyj95++ if yyhl95 { yyb95 = yyj95 > l } else { yyb95 = z.DecCheckBreak() } if yyb95 { z.DecReadArrayEnd() return } z.DecReadArrayElem() z.F.DecSliceUint64X(&x.AnonInTestStruc.AUi64slice, d) yyj95++ if yyhl95 { yyb95 = yyj95 > l } else { yyb95 = z.DecCheckBreak() } if yyb95 { z.DecReadArrayEnd() return } z.DecReadArrayElem() z.F.DecSliceFloat64X(&x.AnonInTestStruc.AF64slice, d) yyj95++ if yyhl95 { yyb95 = yyj95 > l } else { yyb95 = z.DecCheckBreak() } if yyb95 { z.DecReadArrayEnd() return } z.DecReadArrayElem() z.F.DecSliceFloat32X(&x.AnonInTestStruc.AF32slice, d) yyj95++ if yyhl95 { yyb95 = yyj95 > l } else { yyb95 = z.DecCheckBreak() } if yyb95 { z.DecReadArrayEnd() return } z.DecReadArrayElem() z.F.DecMapStringStringX(&x.AnonInTestStruc.AMSS, d) yyj95++ if yyhl95 { yyb95 = yyj95 > l } else { yyb95 = z.DecCheckBreak() } if yyb95 { z.DecReadArrayEnd() return } z.DecReadArrayElem() z.F.DecMapStringUint64X(&x.AnonInTestStruc.AMSU64, d) yyj95++ if yyhl95 { yyb95 = yyj95 > l } else { yyb95 = z.DecCheckBreak() } if yyb95 { z.DecReadArrayEnd() return } z.DecReadArrayElem() h.decArray8int64((*[8]int64)(&x.AnonInTestStruc.AI64arr8), d) yyj95++ if yyhl95 { yyb95 = yyj95 > l } else { yyb95 = z.DecCheckBreak() } if yyb95 { z.DecReadArrayEnd() return } z.DecReadArrayElem() h.decArray0int64((*[0]int64)(&x.AnonInTestStruc.AI64arr0), d) yyj95++ if yyhl95 { yyb95 = yyj95 > l } else { yyb95 = z.DecCheckBreak() } if yyb95 { z.DecReadArrayEnd() return } z.DecReadArrayElem() z.F.DecSliceInt64X(&x.AnonInTestStruc.AI64slice0, d) yyj95++ if yyhl95 { yyb95 = yyj95 > l } else { yyb95 = z.DecCheckBreak() } if yyb95 { z.DecReadArrayEnd() return } z.DecReadArrayElem() z.F.DecSliceUint64X(&x.AnonInTestStruc.AUi64sliceN, d) yyj95++ if yyhl95 { yyb95 = yyj95 > l } else { yyb95 = z.DecCheckBreak() } if yyb95 { z.DecReadArrayEnd() return } z.DecReadArrayElem() z.F.DecMapStringUint64X(&x.AnonInTestStruc.AMSU64N, d) yyj95++ if yyhl95 { yyb95 = yyj95 > l } else { yyb95 = z.DecCheckBreak() } if yyb95 { z.DecReadArrayEnd() return } z.DecReadArrayElem() z.F.DecMapStringUint64X(&x.AnonInTestStruc.AMSU64E, d) yyj95++ if yyhl95 { yyb95 = yyj95 > l } else { yyb95 = z.DecCheckBreak() } if yyb95 { z.DecReadArrayEnd() return } z.DecReadArrayElem() if yyxt176 := z.Extension(x.NotAnon); yyxt176 != nil { z.DecExtension(&x.NotAnon, yyxt176) } else { x.NotAnon.CodecDecodeSelf(d) } yyj95++ if yyhl95 { yyb95 = yyj95 > l } else { yyb95 = z.DecCheckBreak() } if yyb95 { z.DecReadArrayEnd() return } z.DecReadArrayElem() if r.TryNil() { if x.AnonInTestStrucSlim != nil && x.AnonInTestStrucSlim.P != nil { // remove the if-true x.AnonInTestStrucSlim.P = nil } } else { if x.AnonInTestStrucSlim == nil { x.AnonInTestStrucSlim = new(AnonInTestStrucSlim) } if x.AnonInTestStrucSlim.P == nil { x.AnonInTestStrucSlim.P = new(string) } *x.AnonInTestStrucSlim.P = (string)(z.DecStringZC(r.DecodeStringAsBytes())) } yyj95++ if yyhl95 { yyb95 = yyj95 > l } else { yyb95 = z.DecCheckBreak() } if yyb95 { z.DecReadArrayEnd() return } z.DecReadArrayElem() if r.TryNil() { if x.NotAnonSlim != nil { // remove the if-true x.NotAnonSlim = nil } } else { if x.NotAnonSlim == nil { x.NotAnonSlim = new(AnonInTestStrucSlim) } if yyxt180 := z.Extension(x.NotAnonSlim); yyxt180 != nil { z.DecExtension(x.NotAnonSlim, yyxt180) } else { x.NotAnonSlim.CodecDecodeSelf(d) } } yyj95++ if yyhl95 { yyb95 = yyj95 > l } else { yyb95 = z.DecCheckBreak() } if yyb95 { z.DecReadArrayEnd() return } z.DecReadArrayElem() z.F.DecMapStringBoolX(&x.Nmap, d) yyj95++ if yyhl95 { yyb95 = yyj95 > l } else { yyb95 = z.DecCheckBreak() } if yyb95 { z.DecReadArrayEnd() return } z.DecReadArrayElem() x.Nslice = z.DecodeBytesInto(([]byte)(x.Nslice)) yyj95++ if yyhl95 { yyb95 = yyj95 > l } else { yyb95 = z.DecCheckBreak() } if yyb95 { z.DecReadArrayEnd() return } z.DecReadArrayElem() if r.TryNil() { if x.Nint64 != nil { // remove the if-true x.Nint64 = nil } } else { if x.Nint64 == nil { x.Nint64 = new(int64) } *x.Nint64 = (int64)(r.DecodeInt64()) } for { yyj95++ if yyhl95 { yyb95 = yyj95 > l } else { yyb95 = z.DecCheckBreak() } if yyb95 { break } z.DecReadArrayElem() z.DecStructFieldNotFound(yyj95-1, "") } } func (x *TestStrucCommon) IsCodecEmpty() bool { return !(x.S != "" || x.I64 != 0 || x.I32 != 0 || x.I16 != 0 || x.I8 != 0 || x.I64n != 0 || x.I32n != 0 || x.I16n != 0 || x.I8n != 0 || x.Ui64 != 0 || x.Ui32 != 0 || x.Ui16 != 0 || x.Ui8 != 0 || x.F64 != 0 || x.F32 != 0 || bool(x.B) || x.By != 0 || len(x.Sslice) != 0 || len(x.I64slice) != 0 || len(x.I32slice) != 0 || len(x.Ui64slice) != 0 || len(x.Ui8slice) != 0 || len(x.Bslice) != 0 || len(x.Byslice) != 0 || len(x.BytesSlice) != 0 || len(x.Iptrslice) != 0 || len(x.WrapSliceInt64) != 0 || len(x.WrapSliceString) != 0 || len(x.Msint) != 0 || len(x.Msbytes) != 0 || !(x.Simplef.IsCodecEmpty()) || len(x.SstrUi64T) != 0 || len(x.MstrUi64T) != 0 || !(x.AnonInTestStruc.IsCodecEmpty()) || !(x.NotAnon.IsCodecEmpty()) || x.AnonInTestStrucSlim != nil && len(x.Nmap) != 0 || len(x.Nslice) != 0 || false) } func (TestStruc) codecSelferViaCodecgen() {} func (x *TestStruc) CodecEncodeSelf(e *Encoder) { var h codecSelfer19780 z, r := GenHelper().Encoder(e) _, _, _ = h, z, r if z.EncBasicHandle().CheckCircularRef { z.EncEncode(x) return } if x == nil { r.EncodeNil() } else { yy2arr2 := z.EncBasicHandle().StructToArray _ = yy2arr2 const yyr2 bool = false // struct tag has 'toArray' var yyn54 bool = x.TestStrucCommon.AnonInTestStrucSlim == nil || x.TestStrucCommon.AnonInTestStrucSlim.P == nil var yyn55 bool = x.TestStrucCommon.NotAnonSlim == nil var yyn58 bool = x.TestStrucCommon.Nint64 == nil var yyn62 bool = x.Nteststruc == nil if yyr2 || yy2arr2 { z.EncWriteArrayStart(60) z.EncWriteArrayElem() r.EncodeString(string(x.TestStrucCommon.S)) z.EncWriteArrayElem() r.EncodeInt(int64(x.TestStrucCommon.I64)) z.EncWriteArrayElem() r.EncodeInt(int64(x.TestStrucCommon.I32)) z.EncWriteArrayElem() r.EncodeInt(int64(x.TestStrucCommon.I16)) z.EncWriteArrayElem() r.EncodeInt(int64(x.TestStrucCommon.I8)) z.EncWriteArrayElem() r.EncodeInt(int64(x.TestStrucCommon.I64n)) z.EncWriteArrayElem() r.EncodeInt(int64(x.TestStrucCommon.I32n)) z.EncWriteArrayElem() r.EncodeInt(int64(x.TestStrucCommon.I16n)) z.EncWriteArrayElem() r.EncodeInt(int64(x.TestStrucCommon.I8n)) z.EncWriteArrayElem() r.EncodeUint(uint64(x.TestStrucCommon.Ui64)) z.EncWriteArrayElem() r.EncodeUint(uint64(x.TestStrucCommon.Ui32)) z.EncWriteArrayElem() r.EncodeUint(uint64(x.TestStrucCommon.Ui16)) z.EncWriteArrayElem() r.EncodeUint(uint64(x.TestStrucCommon.Ui8)) z.EncWriteArrayElem() r.EncodeFloat64(float64(x.TestStrucCommon.F64)) z.EncWriteArrayElem() r.EncodeFloat32(float32(x.TestStrucCommon.F32)) z.EncWriteArrayElem() r.EncodeBool(bool(x.TestStrucCommon.B)) z.EncWriteArrayElem() r.EncodeUint(uint64(x.TestStrucCommon.By)) z.EncWriteArrayElem() if x.TestStrucCommon.Sslice == nil { r.EncodeNil() } else { z.F.EncSliceStringV(x.TestStrucCommon.Sslice, e) } // end block: if x.TestStrucCommon.Sslice slice == nil z.EncWriteArrayElem() if x.TestStrucCommon.I64slice == nil { r.EncodeNil() } else { z.F.EncSliceInt64V(x.TestStrucCommon.I64slice, e) } // end block: if x.TestStrucCommon.I64slice slice == nil z.EncWriteArrayElem() if x.TestStrucCommon.I32slice == nil { r.EncodeNil() } else { z.F.EncSliceInt32V(x.TestStrucCommon.I32slice, e) } // end block: if x.TestStrucCommon.I32slice slice == nil z.EncWriteArrayElem() if x.TestStrucCommon.Ui64slice == nil { r.EncodeNil() } else { z.F.EncSliceUint64V(x.TestStrucCommon.Ui64slice, e) } // end block: if x.TestStrucCommon.Ui64slice slice == nil z.EncWriteArrayElem() if x.TestStrucCommon.Ui8slice == nil { r.EncodeNil() } else { r.EncodeStringBytesRaw([]byte(x.TestStrucCommon.Ui8slice)) } // end block: if x.TestStrucCommon.Ui8slice slice == nil z.EncWriteArrayElem() if x.TestStrucCommon.Bslice == nil { r.EncodeNil() } else { z.F.EncSliceBoolV(x.TestStrucCommon.Bslice, e) } // end block: if x.TestStrucCommon.Bslice slice == nil z.EncWriteArrayElem() if x.TestStrucCommon.Byslice == nil { r.EncodeNil() } else { r.EncodeStringBytesRaw([]byte(x.TestStrucCommon.Byslice)) } // end block: if x.TestStrucCommon.Byslice slice == nil z.EncWriteArrayElem() if x.TestStrucCommon.BytesSlice == nil { r.EncodeNil() } else { z.F.EncSliceBytesV(x.TestStrucCommon.BytesSlice, e) } // end block: if x.TestStrucCommon.BytesSlice slice == nil z.EncWriteArrayElem() if x.TestStrucCommon.Iptrslice == nil { r.EncodeNil() } else { h.encSlicePtrtoint64(([]*int64)(x.TestStrucCommon.Iptrslice), e) } // end block: if x.TestStrucCommon.Iptrslice slice == nil z.EncWriteArrayElem() if yyxt89 := z.Extension(x.TestStrucCommon.WrapSliceInt64); yyxt89 != nil { z.EncExtension(x.TestStrucCommon.WrapSliceInt64, yyxt89) } else { x.TestStrucCommon.WrapSliceInt64.CodecEncodeSelf(e) } z.EncWriteArrayElem() if yyxt90 := z.Extension(x.TestStrucCommon.WrapSliceString); yyxt90 != nil { z.EncExtension(x.TestStrucCommon.WrapSliceString, yyxt90) } else { x.TestStrucCommon.WrapSliceString.CodecEncodeSelf(e) } z.EncWriteArrayElem() if x.TestStrucCommon.Msint == nil { r.EncodeNil() } else { z.F.EncMapStringIntV(x.TestStrucCommon.Msint, e) } // end block: if x.TestStrucCommon.Msint map == nil z.EncWriteArrayElem() if x.TestStrucCommon.Msbytes == nil { r.EncodeNil() } else { z.F.EncMapStringBytesV(x.TestStrucCommon.Msbytes, e) } // end block: if x.TestStrucCommon.Msbytes map == nil z.EncWriteArrayElem() yy93 := &x.TestStrucCommon.Simplef if yyxt94 := z.Extension(yy93); yyxt94 != nil { z.EncExtension(yy93, yyxt94) } else { yy93.CodecEncodeSelf(e) } z.EncWriteArrayElem() if x.TestStrucCommon.SstrUi64T == nil { r.EncodeNil() } else { h.encSlicestringUint64T(([]stringUint64T)(x.TestStrucCommon.SstrUi64T), e) } // end block: if x.TestStrucCommon.SstrUi64T slice == nil z.EncWriteArrayElem() if x.TestStrucCommon.MstrUi64T == nil { r.EncodeNil() } else { h.encMapstringPtrtostringUint64T((map[string]*stringUint64T)(x.TestStrucCommon.MstrUi64T), e) } // end block: if x.TestStrucCommon.MstrUi64T map == nil z.EncWriteArrayElem() r.EncodeString(string(x.TestStrucCommon.AnonInTestStruc.AS)) z.EncWriteArrayElem() r.EncodeInt(int64(x.TestStrucCommon.AnonInTestStruc.AI64)) z.EncWriteArrayElem() r.EncodeInt(int64(x.TestStrucCommon.AnonInTestStruc.AI16)) z.EncWriteArrayElem() r.EncodeUint(uint64(x.TestStrucCommon.AnonInTestStruc.AUi64)) z.EncWriteArrayElem() if x.TestStrucCommon.AnonInTestStruc.ASslice == nil { r.EncodeNil() } else { z.F.EncSliceStringV(x.TestStrucCommon.AnonInTestStruc.ASslice, e) } // end block: if x.TestStrucCommon.AnonInTestStruc.ASslice slice == nil z.EncWriteArrayElem() if x.TestStrucCommon.AnonInTestStruc.AI64slice == nil { r.EncodeNil() } else { z.F.EncSliceInt64V(x.TestStrucCommon.AnonInTestStruc.AI64slice, e) } // end block: if x.TestStrucCommon.AnonInTestStruc.AI64slice slice == nil z.EncWriteArrayElem() if x.TestStrucCommon.AnonInTestStruc.AUi64slice == nil { r.EncodeNil() } else { z.F.EncSliceUint64V(x.TestStrucCommon.AnonInTestStruc.AUi64slice, e) } // end block: if x.TestStrucCommon.AnonInTestStruc.AUi64slice slice == nil z.EncWriteArrayElem() if x.TestStrucCommon.AnonInTestStruc.AF64slice == nil { r.EncodeNil() } else { z.F.EncSliceFloat64V(x.TestStrucCommon.AnonInTestStruc.AF64slice, e) } // end block: if x.TestStrucCommon.AnonInTestStruc.AF64slice slice == nil z.EncWriteArrayElem() if x.TestStrucCommon.AnonInTestStruc.AF32slice == nil { r.EncodeNil() } else { z.F.EncSliceFloat32V(x.TestStrucCommon.AnonInTestStruc.AF32slice, e) } // end block: if x.TestStrucCommon.AnonInTestStruc.AF32slice slice == nil z.EncWriteArrayElem() if x.TestStrucCommon.AnonInTestStruc.AMSS == nil { r.EncodeNil() } else { z.F.EncMapStringStringV(x.TestStrucCommon.AnonInTestStruc.AMSS, e) } // end block: if x.TestStrucCommon.AnonInTestStruc.AMSS map == nil z.EncWriteArrayElem() if x.TestStrucCommon.AnonInTestStruc.AMSU64 == nil { r.EncodeNil() } else { z.F.EncMapStringUint64V(x.TestStrucCommon.AnonInTestStruc.AMSU64, e) } // end block: if x.TestStrucCommon.AnonInTestStruc.AMSU64 map == nil z.EncWriteArrayElem() yy108 := &x.TestStrucCommon.AnonInTestStruc.AI64arr8 h.encArray8int64((*[8]int64)(yy108), e) z.EncWriteArrayElem() yy110 := &x.TestStrucCommon.AnonInTestStruc.AI64arr0 h.encArray0int64((*[0]int64)(yy110), e) z.EncWriteArrayElem() if x.TestStrucCommon.AnonInTestStruc.AI64slice0 == nil { r.EncodeNil() } else { z.F.EncSliceInt64V(x.TestStrucCommon.AnonInTestStruc.AI64slice0, e) } // end block: if x.TestStrucCommon.AnonInTestStruc.AI64slice0 slice == nil z.EncWriteArrayElem() if x.TestStrucCommon.AnonInTestStruc.AUi64sliceN == nil { r.EncodeNil() } else { z.F.EncSliceUint64V(x.TestStrucCommon.AnonInTestStruc.AUi64sliceN, e) } // end block: if x.TestStrucCommon.AnonInTestStruc.AUi64sliceN slice == nil z.EncWriteArrayElem() if x.TestStrucCommon.AnonInTestStruc.AMSU64N == nil { r.EncodeNil() } else { z.F.EncMapStringUint64V(x.TestStrucCommon.AnonInTestStruc.AMSU64N, e) } // end block: if x.TestStrucCommon.AnonInTestStruc.AMSU64N map == nil z.EncWriteArrayElem() if x.TestStrucCommon.AnonInTestStruc.AMSU64E == nil { r.EncodeNil() } else { z.F.EncMapStringUint64V(x.TestStrucCommon.AnonInTestStruc.AMSU64E, e) } // end block: if x.TestStrucCommon.AnonInTestStruc.AMSU64E map == nil z.EncWriteArrayElem() yy116 := &x.TestStrucCommon.NotAnon if yyxt117 := z.Extension(yy116); yyxt117 != nil { z.EncExtension(yy116, yyxt117) } else { yy116.CodecEncodeSelf(e) } if yyn54 { z.EncWriteArrayElem() r.EncodeNil() } else { z.EncWriteArrayElem() yy118 := *x.TestStrucCommon.AnonInTestStrucSlim.P r.EncodeString(string(yy118)) } if yyn55 { z.EncWriteArrayElem() r.EncodeNil() } else { z.EncWriteArrayElem() if yyxt120 := z.Extension(x.TestStrucCommon.NotAnonSlim); yyxt120 != nil { z.EncExtension(x.TestStrucCommon.NotAnonSlim, yyxt120) } else { x.TestStrucCommon.NotAnonSlim.CodecEncodeSelf(e) } } z.EncWriteArrayElem() if x.TestStrucCommon.Nmap == nil { r.EncodeNil() } else { z.F.EncMapStringBoolV(x.TestStrucCommon.Nmap, e) } // end block: if x.TestStrucCommon.Nmap map == nil z.EncWriteArrayElem() if x.TestStrucCommon.Nslice == nil { r.EncodeNil() } else { r.EncodeStringBytesRaw([]byte(x.TestStrucCommon.Nslice)) } // end block: if x.TestStrucCommon.Nslice slice == nil if yyn58 { z.EncWriteArrayElem() r.EncodeNil() } else { z.EncWriteArrayElem() yy123 := *x.TestStrucCommon.Nint64 r.EncodeInt(int64(yy123)) } z.EncWriteArrayElem() if x.Mtsptr == nil { r.EncodeNil() } else { h.encMapstringPtrtoTestStruc((map[string]*TestStruc)(x.Mtsptr), e) } // end block: if x.Mtsptr map == nil z.EncWriteArrayElem() if x.Mts == nil { r.EncodeNil() } else { h.encMapstringTestStruc((map[string]TestStruc)(x.Mts), e) } // end block: if x.Mts map == nil z.EncWriteArrayElem() if x.Its == nil { r.EncodeNil() } else { h.encSlicePtrtoTestStruc(([]*TestStruc)(x.Its), e) } // end block: if x.Its slice == nil if yyn62 { z.EncWriteArrayElem() r.EncodeNil() } else { z.EncWriteArrayElem() if yyxt128 := z.Extension(x.Nteststruc); yyxt128 != nil { z.EncExtension(x.Nteststruc, yyxt128) } else { x.Nteststruc.CodecEncodeSelf(e) } } z.EncWriteArrayEnd() } else { z.EncWriteMapStart(60) if z.EncBasicHandle().Canonical { z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"AF32slice\"") } else { r.EncodeString(`AF32slice`) } z.EncWriteMapElemValue() if x.TestStrucCommon.AnonInTestStruc.AF32slice == nil { r.EncodeNil() } else { z.F.EncSliceFloat32V(x.TestStrucCommon.AnonInTestStruc.AF32slice, e) } // end block: if x.TestStrucCommon.AnonInTestStruc.AF32slice slice == nil z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"AF64slice\"") } else { r.EncodeString(`AF64slice`) } z.EncWriteMapElemValue() if x.TestStrucCommon.AnonInTestStruc.AF64slice == nil { r.EncodeNil() } else { z.F.EncSliceFloat64V(x.TestStrucCommon.AnonInTestStruc.AF64slice, e) } // end block: if x.TestStrucCommon.AnonInTestStruc.AF64slice slice == nil z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"AI16\"") } else { r.EncodeString(`AI16`) } z.EncWriteMapElemValue() r.EncodeInt(int64(x.TestStrucCommon.AnonInTestStruc.AI16)) z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"AI64\"") } else { r.EncodeString(`AI64`) } z.EncWriteMapElemValue() r.EncodeInt(int64(x.TestStrucCommon.AnonInTestStruc.AI64)) z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"AI64arr0\"") } else { r.EncodeString(`AI64arr0`) } z.EncWriteMapElemValue() yy133 := &x.TestStrucCommon.AnonInTestStruc.AI64arr0 h.encArray0int64((*[0]int64)(yy133), e) z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"AI64arr8\"") } else { r.EncodeString(`AI64arr8`) } z.EncWriteMapElemValue() yy135 := &x.TestStrucCommon.AnonInTestStruc.AI64arr8 h.encArray8int64((*[8]int64)(yy135), e) z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"AI64slice\"") } else { r.EncodeString(`AI64slice`) } z.EncWriteMapElemValue() if x.TestStrucCommon.AnonInTestStruc.AI64slice == nil { r.EncodeNil() } else { z.F.EncSliceInt64V(x.TestStrucCommon.AnonInTestStruc.AI64slice, e) } // end block: if x.TestStrucCommon.AnonInTestStruc.AI64slice slice == nil z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"AI64slice0\"") } else { r.EncodeString(`AI64slice0`) } z.EncWriteMapElemValue() if x.TestStrucCommon.AnonInTestStruc.AI64slice0 == nil { r.EncodeNil() } else { z.F.EncSliceInt64V(x.TestStrucCommon.AnonInTestStruc.AI64slice0, e) } // end block: if x.TestStrucCommon.AnonInTestStruc.AI64slice0 slice == nil z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"AMSS\"") } else { r.EncodeString(`AMSS`) } z.EncWriteMapElemValue() if x.TestStrucCommon.AnonInTestStruc.AMSS == nil { r.EncodeNil() } else { z.F.EncMapStringStringV(x.TestStrucCommon.AnonInTestStruc.AMSS, e) } // end block: if x.TestStrucCommon.AnonInTestStruc.AMSS map == nil z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"AMSU64\"") } else { r.EncodeString(`AMSU64`) } z.EncWriteMapElemValue() if x.TestStrucCommon.AnonInTestStruc.AMSU64 == nil { r.EncodeNil() } else { z.F.EncMapStringUint64V(x.TestStrucCommon.AnonInTestStruc.AMSU64, e) } // end block: if x.TestStrucCommon.AnonInTestStruc.AMSU64 map == nil z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"AMSU64E\"") } else { r.EncodeString(`AMSU64E`) } z.EncWriteMapElemValue() if x.TestStrucCommon.AnonInTestStruc.AMSU64E == nil { r.EncodeNil() } else { z.F.EncMapStringUint64V(x.TestStrucCommon.AnonInTestStruc.AMSU64E, e) } // end block: if x.TestStrucCommon.AnonInTestStruc.AMSU64E map == nil z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"AMSU64N\"") } else { r.EncodeString(`AMSU64N`) } z.EncWriteMapElemValue() if x.TestStrucCommon.AnonInTestStruc.AMSU64N == nil { r.EncodeNil() } else { z.F.EncMapStringUint64V(x.TestStrucCommon.AnonInTestStruc.AMSU64N, e) } // end block: if x.TestStrucCommon.AnonInTestStruc.AMSU64N map == nil z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"AS\"") } else { r.EncodeString(`AS`) } z.EncWriteMapElemValue() r.EncodeString(string(x.TestStrucCommon.AnonInTestStruc.AS)) z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"ASslice\"") } else { r.EncodeString(`ASslice`) } z.EncWriteMapElemValue() if x.TestStrucCommon.AnonInTestStruc.ASslice == nil { r.EncodeNil() } else { z.F.EncSliceStringV(x.TestStrucCommon.AnonInTestStruc.ASslice, e) } // end block: if x.TestStrucCommon.AnonInTestStruc.ASslice slice == nil z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"AUi64\"") } else { r.EncodeString(`AUi64`) } z.EncWriteMapElemValue() r.EncodeUint(uint64(x.TestStrucCommon.AnonInTestStruc.AUi64)) z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"AUi64slice\"") } else { r.EncodeString(`AUi64slice`) } z.EncWriteMapElemValue() if x.TestStrucCommon.AnonInTestStruc.AUi64slice == nil { r.EncodeNil() } else { z.F.EncSliceUint64V(x.TestStrucCommon.AnonInTestStruc.AUi64slice, e) } // end block: if x.TestStrucCommon.AnonInTestStruc.AUi64slice slice == nil z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"AUi64sliceN\"") } else { r.EncodeString(`AUi64sliceN`) } z.EncWriteMapElemValue() if x.TestStrucCommon.AnonInTestStruc.AUi64sliceN == nil { r.EncodeNil() } else { z.F.EncSliceUint64V(x.TestStrucCommon.AnonInTestStruc.AUi64sliceN, e) } // end block: if x.TestStrucCommon.AnonInTestStruc.AUi64sliceN slice == nil z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"B\"") } else { r.EncodeString(`B`) } z.EncWriteMapElemValue() r.EncodeBool(bool(x.TestStrucCommon.B)) z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"Bslice\"") } else { r.EncodeString(`Bslice`) } z.EncWriteMapElemValue() if x.TestStrucCommon.Bslice == nil { r.EncodeNil() } else { z.F.EncSliceBoolV(x.TestStrucCommon.Bslice, e) } // end block: if x.TestStrucCommon.Bslice slice == nil z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"By\"") } else { r.EncodeString(`By`) } z.EncWriteMapElemValue() r.EncodeUint(uint64(x.TestStrucCommon.By)) z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"Byslice\"") } else { r.EncodeString(`Byslice`) } z.EncWriteMapElemValue() if x.TestStrucCommon.Byslice == nil { r.EncodeNil() } else { r.EncodeStringBytesRaw([]byte(x.TestStrucCommon.Byslice)) } // end block: if x.TestStrucCommon.Byslice slice == nil z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"BytesSlice\"") } else { r.EncodeString(`BytesSlice`) } z.EncWriteMapElemValue() if x.TestStrucCommon.BytesSlice == nil { r.EncodeNil() } else { z.F.EncSliceBytesV(x.TestStrucCommon.BytesSlice, e) } // end block: if x.TestStrucCommon.BytesSlice slice == nil z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"F32\"") } else { r.EncodeString(`F32`) } z.EncWriteMapElemValue() r.EncodeFloat32(float32(x.TestStrucCommon.F32)) z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"F64\"") } else { r.EncodeString(`F64`) } z.EncWriteMapElemValue() r.EncodeFloat64(float64(x.TestStrucCommon.F64)) z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"I16\"") } else { r.EncodeString(`I16`) } z.EncWriteMapElemValue() r.EncodeInt(int64(x.TestStrucCommon.I16)) z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"I16n\"") } else { r.EncodeString(`I16n`) } z.EncWriteMapElemValue() r.EncodeInt(int64(x.TestStrucCommon.I16n)) z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"I32\"") } else { r.EncodeString(`I32`) } z.EncWriteMapElemValue() r.EncodeInt(int64(x.TestStrucCommon.I32)) z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"I32n\"") } else { r.EncodeString(`I32n`) } z.EncWriteMapElemValue() r.EncodeInt(int64(x.TestStrucCommon.I32n)) z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"I32slice\"") } else { r.EncodeString(`I32slice`) } z.EncWriteMapElemValue() if x.TestStrucCommon.I32slice == nil { r.EncodeNil() } else { z.F.EncSliceInt32V(x.TestStrucCommon.I32slice, e) } // end block: if x.TestStrucCommon.I32slice slice == nil z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"I64\"") } else { r.EncodeString(`I64`) } z.EncWriteMapElemValue() r.EncodeInt(int64(x.TestStrucCommon.I64)) z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"I64n\"") } else { r.EncodeString(`I64n`) } z.EncWriteMapElemValue() r.EncodeInt(int64(x.TestStrucCommon.I64n)) z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"I64slice\"") } else { r.EncodeString(`I64slice`) } z.EncWriteMapElemValue() if x.TestStrucCommon.I64slice == nil { r.EncodeNil() } else { z.F.EncSliceInt64V(x.TestStrucCommon.I64slice, e) } // end block: if x.TestStrucCommon.I64slice slice == nil z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"I8\"") } else { r.EncodeString(`I8`) } z.EncWriteMapElemValue() r.EncodeInt(int64(x.TestStrucCommon.I8)) z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"I8n\"") } else { r.EncodeString(`I8n`) } z.EncWriteMapElemValue() r.EncodeInt(int64(x.TestStrucCommon.I8n)) z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"Iptrslice\"") } else { r.EncodeString(`Iptrslice`) } z.EncWriteMapElemValue() if x.TestStrucCommon.Iptrslice == nil { r.EncodeNil() } else { h.encSlicePtrtoint64(([]*int64)(x.TestStrucCommon.Iptrslice), e) } // end block: if x.TestStrucCommon.Iptrslice slice == nil z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"Its\"") } else { r.EncodeString(`Its`) } z.EncWriteMapElemValue() if x.Its == nil { r.EncodeNil() } else { h.encSlicePtrtoTestStruc(([]*TestStruc)(x.Its), e) } // end block: if x.Its slice == nil z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"Msbytes\"") } else { r.EncodeString(`Msbytes`) } z.EncWriteMapElemValue() if x.TestStrucCommon.Msbytes == nil { r.EncodeNil() } else { z.F.EncMapStringBytesV(x.TestStrucCommon.Msbytes, e) } // end block: if x.TestStrucCommon.Msbytes map == nil z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"Msint\"") } else { r.EncodeString(`Msint`) } z.EncWriteMapElemValue() if x.TestStrucCommon.Msint == nil { r.EncodeNil() } else { z.F.EncMapStringIntV(x.TestStrucCommon.Msint, e) } // end block: if x.TestStrucCommon.Msint map == nil z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"MstrUi64T\"") } else { r.EncodeString(`MstrUi64T`) } z.EncWriteMapElemValue() if x.TestStrucCommon.MstrUi64T == nil { r.EncodeNil() } else { h.encMapstringPtrtostringUint64T((map[string]*stringUint64T)(x.TestStrucCommon.MstrUi64T), e) } // end block: if x.TestStrucCommon.MstrUi64T map == nil z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"Mts\"") } else { r.EncodeString(`Mts`) } z.EncWriteMapElemValue() if x.Mts == nil { r.EncodeNil() } else { h.encMapstringTestStruc((map[string]TestStruc)(x.Mts), e) } // end block: if x.Mts map == nil z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"Mtsptr\"") } else { r.EncodeString(`Mtsptr`) } z.EncWriteMapElemValue() if x.Mtsptr == nil { r.EncodeNil() } else { h.encMapstringPtrtoTestStruc((map[string]*TestStruc)(x.Mtsptr), e) } // end block: if x.Mtsptr map == nil z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"Nint64\"") } else { r.EncodeString(`Nint64`) } z.EncWriteMapElemValue() if yyn58 { r.EncodeNil() } else { yy172 := *x.TestStrucCommon.Nint64 r.EncodeInt(int64(yy172)) } z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"Nmap\"") } else { r.EncodeString(`Nmap`) } z.EncWriteMapElemValue() if x.TestStrucCommon.Nmap == nil { r.EncodeNil() } else { z.F.EncMapStringBoolV(x.TestStrucCommon.Nmap, e) } // end block: if x.TestStrucCommon.Nmap map == nil z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"NotAnon\"") } else { r.EncodeString(`NotAnon`) } z.EncWriteMapElemValue() yy175 := &x.TestStrucCommon.NotAnon if yyxt176 := z.Extension(yy175); yyxt176 != nil { z.EncExtension(yy175, yyxt176) } else { yy175.CodecEncodeSelf(e) } z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"NotAnonSlim\"") } else { r.EncodeString(`NotAnonSlim`) } z.EncWriteMapElemValue() if yyn55 { r.EncodeNil() } else { if yyxt177 := z.Extension(x.TestStrucCommon.NotAnonSlim); yyxt177 != nil { z.EncExtension(x.TestStrucCommon.NotAnonSlim, yyxt177) } else { x.TestStrucCommon.NotAnonSlim.CodecEncodeSelf(e) } } z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"Nslice\"") } else { r.EncodeString(`Nslice`) } z.EncWriteMapElemValue() if x.TestStrucCommon.Nslice == nil { r.EncodeNil() } else { r.EncodeStringBytesRaw([]byte(x.TestStrucCommon.Nslice)) } // end block: if x.TestStrucCommon.Nslice slice == nil z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"Nteststruc\"") } else { r.EncodeString(`Nteststruc`) } z.EncWriteMapElemValue() if yyn62 { r.EncodeNil() } else { if yyxt179 := z.Extension(x.Nteststruc); yyxt179 != nil { z.EncExtension(x.Nteststruc, yyxt179) } else { x.Nteststruc.CodecEncodeSelf(e) } } z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"P\"") } else { r.EncodeString(`P`) } z.EncWriteMapElemValue() if yyn54 { r.EncodeNil() } else { yy180 := *x.TestStrucCommon.AnonInTestStrucSlim.P r.EncodeString(string(yy180)) } z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"S\"") } else { r.EncodeString(`S`) } z.EncWriteMapElemValue() r.EncodeString(string(x.TestStrucCommon.S)) z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"Simplef\"") } else { r.EncodeString(`Simplef`) } z.EncWriteMapElemValue() yy183 := &x.TestStrucCommon.Simplef if yyxt184 := z.Extension(yy183); yyxt184 != nil { z.EncExtension(yy183, yyxt184) } else { yy183.CodecEncodeSelf(e) } z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"Sslice\"") } else { r.EncodeString(`Sslice`) } z.EncWriteMapElemValue() if x.TestStrucCommon.Sslice == nil { r.EncodeNil() } else { z.F.EncSliceStringV(x.TestStrucCommon.Sslice, e) } // end block: if x.TestStrucCommon.Sslice slice == nil z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"SstrUi64T\"") } else { r.EncodeString(`SstrUi64T`) } z.EncWriteMapElemValue() if x.TestStrucCommon.SstrUi64T == nil { r.EncodeNil() } else { h.encSlicestringUint64T(([]stringUint64T)(x.TestStrucCommon.SstrUi64T), e) } // end block: if x.TestStrucCommon.SstrUi64T slice == nil z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"Ui16\"") } else { r.EncodeString(`Ui16`) } z.EncWriteMapElemValue() r.EncodeUint(uint64(x.TestStrucCommon.Ui16)) z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"Ui32\"") } else { r.EncodeString(`Ui32`) } z.EncWriteMapElemValue() r.EncodeUint(uint64(x.TestStrucCommon.Ui32)) z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"Ui64\"") } else { r.EncodeString(`Ui64`) } z.EncWriteMapElemValue() r.EncodeUint(uint64(x.TestStrucCommon.Ui64)) z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"Ui64slice\"") } else { r.EncodeString(`Ui64slice`) } z.EncWriteMapElemValue() if x.TestStrucCommon.Ui64slice == nil { r.EncodeNil() } else { z.F.EncSliceUint64V(x.TestStrucCommon.Ui64slice, e) } // end block: if x.TestStrucCommon.Ui64slice slice == nil z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"Ui8\"") } else { r.EncodeString(`Ui8`) } z.EncWriteMapElemValue() r.EncodeUint(uint64(x.TestStrucCommon.Ui8)) z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"Ui8slice\"") } else { r.EncodeString(`Ui8slice`) } z.EncWriteMapElemValue() if x.TestStrucCommon.Ui8slice == nil { r.EncodeNil() } else { r.EncodeStringBytesRaw([]byte(x.TestStrucCommon.Ui8slice)) } // end block: if x.TestStrucCommon.Ui8slice slice == nil z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"WrapSliceInt64\"") } else { r.EncodeString(`WrapSliceInt64`) } z.EncWriteMapElemValue() if yyxt193 := z.Extension(x.TestStrucCommon.WrapSliceInt64); yyxt193 != nil { z.EncExtension(x.TestStrucCommon.WrapSliceInt64, yyxt193) } else { x.TestStrucCommon.WrapSliceInt64.CodecEncodeSelf(e) } z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"WrapSliceString\"") } else { r.EncodeString(`WrapSliceString`) } z.EncWriteMapElemValue() if yyxt194 := z.Extension(x.TestStrucCommon.WrapSliceString); yyxt194 != nil { z.EncExtension(x.TestStrucCommon.WrapSliceString, yyxt194) } else { x.TestStrucCommon.WrapSliceString.CodecEncodeSelf(e) } } else { z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"S\"") } else { r.EncodeString(`S`) } z.EncWriteMapElemValue() r.EncodeString(string(x.TestStrucCommon.S)) z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"I64\"") } else { r.EncodeString(`I64`) } z.EncWriteMapElemValue() r.EncodeInt(int64(x.TestStrucCommon.I64)) z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"I32\"") } else { r.EncodeString(`I32`) } z.EncWriteMapElemValue() r.EncodeInt(int64(x.TestStrucCommon.I32)) z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"I16\"") } else { r.EncodeString(`I16`) } z.EncWriteMapElemValue() r.EncodeInt(int64(x.TestStrucCommon.I16)) z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"I8\"") } else { r.EncodeString(`I8`) } z.EncWriteMapElemValue() r.EncodeInt(int64(x.TestStrucCommon.I8)) z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"I64n\"") } else { r.EncodeString(`I64n`) } z.EncWriteMapElemValue() r.EncodeInt(int64(x.TestStrucCommon.I64n)) z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"I32n\"") } else { r.EncodeString(`I32n`) } z.EncWriteMapElemValue() r.EncodeInt(int64(x.TestStrucCommon.I32n)) z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"I16n\"") } else { r.EncodeString(`I16n`) } z.EncWriteMapElemValue() r.EncodeInt(int64(x.TestStrucCommon.I16n)) z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"I8n\"") } else { r.EncodeString(`I8n`) } z.EncWriteMapElemValue() r.EncodeInt(int64(x.TestStrucCommon.I8n)) z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"Ui64\"") } else { r.EncodeString(`Ui64`) } z.EncWriteMapElemValue() r.EncodeUint(uint64(x.TestStrucCommon.Ui64)) z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"Ui32\"") } else { r.EncodeString(`Ui32`) } z.EncWriteMapElemValue() r.EncodeUint(uint64(x.TestStrucCommon.Ui32)) z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"Ui16\"") } else { r.EncodeString(`Ui16`) } z.EncWriteMapElemValue() r.EncodeUint(uint64(x.TestStrucCommon.Ui16)) z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"Ui8\"") } else { r.EncodeString(`Ui8`) } z.EncWriteMapElemValue() r.EncodeUint(uint64(x.TestStrucCommon.Ui8)) z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"F64\"") } else { r.EncodeString(`F64`) } z.EncWriteMapElemValue() r.EncodeFloat64(float64(x.TestStrucCommon.F64)) z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"F32\"") } else { r.EncodeString(`F32`) } z.EncWriteMapElemValue() r.EncodeFloat32(float32(x.TestStrucCommon.F32)) z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"B\"") } else { r.EncodeString(`B`) } z.EncWriteMapElemValue() r.EncodeBool(bool(x.TestStrucCommon.B)) z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"By\"") } else { r.EncodeString(`By`) } z.EncWriteMapElemValue() r.EncodeUint(uint64(x.TestStrucCommon.By)) z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"Sslice\"") } else { r.EncodeString(`Sslice`) } z.EncWriteMapElemValue() if x.TestStrucCommon.Sslice == nil { r.EncodeNil() } else { z.F.EncSliceStringV(x.TestStrucCommon.Sslice, e) } // end block: if x.TestStrucCommon.Sslice slice == nil z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"I64slice\"") } else { r.EncodeString(`I64slice`) } z.EncWriteMapElemValue() if x.TestStrucCommon.I64slice == nil { r.EncodeNil() } else { z.F.EncSliceInt64V(x.TestStrucCommon.I64slice, e) } // end block: if x.TestStrucCommon.I64slice slice == nil z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"I32slice\"") } else { r.EncodeString(`I32slice`) } z.EncWriteMapElemValue() if x.TestStrucCommon.I32slice == nil { r.EncodeNil() } else { z.F.EncSliceInt32V(x.TestStrucCommon.I32slice, e) } // end block: if x.TestStrucCommon.I32slice slice == nil z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"Ui64slice\"") } else { r.EncodeString(`Ui64slice`) } z.EncWriteMapElemValue() if x.TestStrucCommon.Ui64slice == nil { r.EncodeNil() } else { z.F.EncSliceUint64V(x.TestStrucCommon.Ui64slice, e) } // end block: if x.TestStrucCommon.Ui64slice slice == nil z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"Ui8slice\"") } else { r.EncodeString(`Ui8slice`) } z.EncWriteMapElemValue() if x.TestStrucCommon.Ui8slice == nil { r.EncodeNil() } else { r.EncodeStringBytesRaw([]byte(x.TestStrucCommon.Ui8slice)) } // end block: if x.TestStrucCommon.Ui8slice slice == nil z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"Bslice\"") } else { r.EncodeString(`Bslice`) } z.EncWriteMapElemValue() if x.TestStrucCommon.Bslice == nil { r.EncodeNil() } else { z.F.EncSliceBoolV(x.TestStrucCommon.Bslice, e) } // end block: if x.TestStrucCommon.Bslice slice == nil z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"Byslice\"") } else { r.EncodeString(`Byslice`) } z.EncWriteMapElemValue() if x.TestStrucCommon.Byslice == nil { r.EncodeNil() } else { r.EncodeStringBytesRaw([]byte(x.TestStrucCommon.Byslice)) } // end block: if x.TestStrucCommon.Byslice slice == nil z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"BytesSlice\"") } else { r.EncodeString(`BytesSlice`) } z.EncWriteMapElemValue() if x.TestStrucCommon.BytesSlice == nil { r.EncodeNil() } else { z.F.EncSliceBytesV(x.TestStrucCommon.BytesSlice, e) } // end block: if x.TestStrucCommon.BytesSlice slice == nil z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"Iptrslice\"") } else { r.EncodeString(`Iptrslice`) } z.EncWriteMapElemValue() if x.TestStrucCommon.Iptrslice == nil { r.EncodeNil() } else { h.encSlicePtrtoint64(([]*int64)(x.TestStrucCommon.Iptrslice), e) } // end block: if x.TestStrucCommon.Iptrslice slice == nil z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"WrapSliceInt64\"") } else { r.EncodeString(`WrapSliceInt64`) } z.EncWriteMapElemValue() if yyxt221 := z.Extension(x.TestStrucCommon.WrapSliceInt64); yyxt221 != nil { z.EncExtension(x.TestStrucCommon.WrapSliceInt64, yyxt221) } else { x.TestStrucCommon.WrapSliceInt64.CodecEncodeSelf(e) } z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"WrapSliceString\"") } else { r.EncodeString(`WrapSliceString`) } z.EncWriteMapElemValue() if yyxt222 := z.Extension(x.TestStrucCommon.WrapSliceString); yyxt222 != nil { z.EncExtension(x.TestStrucCommon.WrapSliceString, yyxt222) } else { x.TestStrucCommon.WrapSliceString.CodecEncodeSelf(e) } z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"Msint\"") } else { r.EncodeString(`Msint`) } z.EncWriteMapElemValue() if x.TestStrucCommon.Msint == nil { r.EncodeNil() } else { z.F.EncMapStringIntV(x.TestStrucCommon.Msint, e) } // end block: if x.TestStrucCommon.Msint map == nil z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"Msbytes\"") } else { r.EncodeString(`Msbytes`) } z.EncWriteMapElemValue() if x.TestStrucCommon.Msbytes == nil { r.EncodeNil() } else { z.F.EncMapStringBytesV(x.TestStrucCommon.Msbytes, e) } // end block: if x.TestStrucCommon.Msbytes map == nil z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"Simplef\"") } else { r.EncodeString(`Simplef`) } z.EncWriteMapElemValue() yy225 := &x.TestStrucCommon.Simplef if yyxt226 := z.Extension(yy225); yyxt226 != nil { z.EncExtension(yy225, yyxt226) } else { yy225.CodecEncodeSelf(e) } z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"SstrUi64T\"") } else { r.EncodeString(`SstrUi64T`) } z.EncWriteMapElemValue() if x.TestStrucCommon.SstrUi64T == nil { r.EncodeNil() } else { h.encSlicestringUint64T(([]stringUint64T)(x.TestStrucCommon.SstrUi64T), e) } // end block: if x.TestStrucCommon.SstrUi64T slice == nil z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"MstrUi64T\"") } else { r.EncodeString(`MstrUi64T`) } z.EncWriteMapElemValue() if x.TestStrucCommon.MstrUi64T == nil { r.EncodeNil() } else { h.encMapstringPtrtostringUint64T((map[string]*stringUint64T)(x.TestStrucCommon.MstrUi64T), e) } // end block: if x.TestStrucCommon.MstrUi64T map == nil z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"AS\"") } else { r.EncodeString(`AS`) } z.EncWriteMapElemValue() r.EncodeString(string(x.TestStrucCommon.AnonInTestStruc.AS)) z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"AI64\"") } else { r.EncodeString(`AI64`) } z.EncWriteMapElemValue() r.EncodeInt(int64(x.TestStrucCommon.AnonInTestStruc.AI64)) z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"AI16\"") } else { r.EncodeString(`AI16`) } z.EncWriteMapElemValue() r.EncodeInt(int64(x.TestStrucCommon.AnonInTestStruc.AI16)) z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"AUi64\"") } else { r.EncodeString(`AUi64`) } z.EncWriteMapElemValue() r.EncodeUint(uint64(x.TestStrucCommon.AnonInTestStruc.AUi64)) z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"ASslice\"") } else { r.EncodeString(`ASslice`) } z.EncWriteMapElemValue() if x.TestStrucCommon.AnonInTestStruc.ASslice == nil { r.EncodeNil() } else { z.F.EncSliceStringV(x.TestStrucCommon.AnonInTestStruc.ASslice, e) } // end block: if x.TestStrucCommon.AnonInTestStruc.ASslice slice == nil z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"AI64slice\"") } else { r.EncodeString(`AI64slice`) } z.EncWriteMapElemValue() if x.TestStrucCommon.AnonInTestStruc.AI64slice == nil { r.EncodeNil() } else { z.F.EncSliceInt64V(x.TestStrucCommon.AnonInTestStruc.AI64slice, e) } // end block: if x.TestStrucCommon.AnonInTestStruc.AI64slice slice == nil z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"AUi64slice\"") } else { r.EncodeString(`AUi64slice`) } z.EncWriteMapElemValue() if x.TestStrucCommon.AnonInTestStruc.AUi64slice == nil { r.EncodeNil() } else { z.F.EncSliceUint64V(x.TestStrucCommon.AnonInTestStruc.AUi64slice, e) } // end block: if x.TestStrucCommon.AnonInTestStruc.AUi64slice slice == nil z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"AF64slice\"") } else { r.EncodeString(`AF64slice`) } z.EncWriteMapElemValue() if x.TestStrucCommon.AnonInTestStruc.AF64slice == nil { r.EncodeNil() } else { z.F.EncSliceFloat64V(x.TestStrucCommon.AnonInTestStruc.AF64slice, e) } // end block: if x.TestStrucCommon.AnonInTestStruc.AF64slice slice == nil z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"AF32slice\"") } else { r.EncodeString(`AF32slice`) } z.EncWriteMapElemValue() if x.TestStrucCommon.AnonInTestStruc.AF32slice == nil { r.EncodeNil() } else { z.F.EncSliceFloat32V(x.TestStrucCommon.AnonInTestStruc.AF32slice, e) } // end block: if x.TestStrucCommon.AnonInTestStruc.AF32slice slice == nil z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"AMSS\"") } else { r.EncodeString(`AMSS`) } z.EncWriteMapElemValue() if x.TestStrucCommon.AnonInTestStruc.AMSS == nil { r.EncodeNil() } else { z.F.EncMapStringStringV(x.TestStrucCommon.AnonInTestStruc.AMSS, e) } // end block: if x.TestStrucCommon.AnonInTestStruc.AMSS map == nil z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"AMSU64\"") } else { r.EncodeString(`AMSU64`) } z.EncWriteMapElemValue() if x.TestStrucCommon.AnonInTestStruc.AMSU64 == nil { r.EncodeNil() } else { z.F.EncMapStringUint64V(x.TestStrucCommon.AnonInTestStruc.AMSU64, e) } // end block: if x.TestStrucCommon.AnonInTestStruc.AMSU64 map == nil z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"AI64arr8\"") } else { r.EncodeString(`AI64arr8`) } z.EncWriteMapElemValue() yy240 := &x.TestStrucCommon.AnonInTestStruc.AI64arr8 h.encArray8int64((*[8]int64)(yy240), e) z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"AI64arr0\"") } else { r.EncodeString(`AI64arr0`) } z.EncWriteMapElemValue() yy242 := &x.TestStrucCommon.AnonInTestStruc.AI64arr0 h.encArray0int64((*[0]int64)(yy242), e) z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"AI64slice0\"") } else { r.EncodeString(`AI64slice0`) } z.EncWriteMapElemValue() if x.TestStrucCommon.AnonInTestStruc.AI64slice0 == nil { r.EncodeNil() } else { z.F.EncSliceInt64V(x.TestStrucCommon.AnonInTestStruc.AI64slice0, e) } // end block: if x.TestStrucCommon.AnonInTestStruc.AI64slice0 slice == nil z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"AUi64sliceN\"") } else { r.EncodeString(`AUi64sliceN`) } z.EncWriteMapElemValue() if x.TestStrucCommon.AnonInTestStruc.AUi64sliceN == nil { r.EncodeNil() } else { z.F.EncSliceUint64V(x.TestStrucCommon.AnonInTestStruc.AUi64sliceN, e) } // end block: if x.TestStrucCommon.AnonInTestStruc.AUi64sliceN slice == nil z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"AMSU64N\"") } else { r.EncodeString(`AMSU64N`) } z.EncWriteMapElemValue() if x.TestStrucCommon.AnonInTestStruc.AMSU64N == nil { r.EncodeNil() } else { z.F.EncMapStringUint64V(x.TestStrucCommon.AnonInTestStruc.AMSU64N, e) } // end block: if x.TestStrucCommon.AnonInTestStruc.AMSU64N map == nil z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"AMSU64E\"") } else { r.EncodeString(`AMSU64E`) } z.EncWriteMapElemValue() if x.TestStrucCommon.AnonInTestStruc.AMSU64E == nil { r.EncodeNil() } else { z.F.EncMapStringUint64V(x.TestStrucCommon.AnonInTestStruc.AMSU64E, e) } // end block: if x.TestStrucCommon.AnonInTestStruc.AMSU64E map == nil z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"NotAnon\"") } else { r.EncodeString(`NotAnon`) } z.EncWriteMapElemValue() yy248 := &x.TestStrucCommon.NotAnon if yyxt249 := z.Extension(yy248); yyxt249 != nil { z.EncExtension(yy248, yyxt249) } else { yy248.CodecEncodeSelf(e) } z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"P\"") } else { r.EncodeString(`P`) } z.EncWriteMapElemValue() if yyn54 { r.EncodeNil() } else { yy250 := *x.TestStrucCommon.AnonInTestStrucSlim.P r.EncodeString(string(yy250)) } z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"NotAnonSlim\"") } else { r.EncodeString(`NotAnonSlim`) } z.EncWriteMapElemValue() if yyn55 { r.EncodeNil() } else { if yyxt252 := z.Extension(x.TestStrucCommon.NotAnonSlim); yyxt252 != nil { z.EncExtension(x.TestStrucCommon.NotAnonSlim, yyxt252) } else { x.TestStrucCommon.NotAnonSlim.CodecEncodeSelf(e) } } z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"Nmap\"") } else { r.EncodeString(`Nmap`) } z.EncWriteMapElemValue() if x.TestStrucCommon.Nmap == nil { r.EncodeNil() } else { z.F.EncMapStringBoolV(x.TestStrucCommon.Nmap, e) } // end block: if x.TestStrucCommon.Nmap map == nil z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"Nslice\"") } else { r.EncodeString(`Nslice`) } z.EncWriteMapElemValue() if x.TestStrucCommon.Nslice == nil { r.EncodeNil() } else { r.EncodeStringBytesRaw([]byte(x.TestStrucCommon.Nslice)) } // end block: if x.TestStrucCommon.Nslice slice == nil z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"Nint64\"") } else { r.EncodeString(`Nint64`) } z.EncWriteMapElemValue() if yyn58 { r.EncodeNil() } else { yy255 := *x.TestStrucCommon.Nint64 r.EncodeInt(int64(yy255)) } z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"Mtsptr\"") } else { r.EncodeString(`Mtsptr`) } z.EncWriteMapElemValue() if x.Mtsptr == nil { r.EncodeNil() } else { h.encMapstringPtrtoTestStruc((map[string]*TestStruc)(x.Mtsptr), e) } // end block: if x.Mtsptr map == nil z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"Mts\"") } else { r.EncodeString(`Mts`) } z.EncWriteMapElemValue() if x.Mts == nil { r.EncodeNil() } else { h.encMapstringTestStruc((map[string]TestStruc)(x.Mts), e) } // end block: if x.Mts map == nil z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"Its\"") } else { r.EncodeString(`Its`) } z.EncWriteMapElemValue() if x.Its == nil { r.EncodeNil() } else { h.encSlicePtrtoTestStruc(([]*TestStruc)(x.Its), e) } // end block: if x.Its slice == nil z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"Nteststruc\"") } else { r.EncodeString(`Nteststruc`) } z.EncWriteMapElemValue() if yyn62 { r.EncodeNil() } else { if yyxt260 := z.Extension(x.Nteststruc); yyxt260 != nil { z.EncExtension(x.Nteststruc, yyxt260) } else { x.Nteststruc.CodecEncodeSelf(e) } } } z.EncWriteMapEnd() } } } func (x *TestStruc) CodecDecodeSelf(d *Decoder) { var h codecSelfer19780 z, r := GenHelper().Decoder(d) _, _, _ = h, z, r yyct2 := r.ContainerType() if yyct2 == codecSelferValueTypeNil19780 { *(x) = TestStruc{} } else if yyct2 == codecSelferValueTypeMap19780 { yyl2 := z.DecReadMapStart() if yyl2 == 0 { } else { x.codecDecodeSelfFromMap(yyl2, d) } z.DecReadMapEnd() } else if yyct2 == codecSelferValueTypeArray19780 { yyl2 := z.DecReadArrayStart() if yyl2 != 0 { x.codecDecodeSelfFromArray(yyl2, d) } z.DecReadArrayEnd() } else { panic(errCodecSelferOnlyMapOrArrayEncodeToStruct19780) } } func (x *TestStruc) codecDecodeSelfFromMap(l int, d *Decoder) { var h codecSelfer19780 z, r := GenHelper().Decoder(d) _, _, _ = h, z, r var yyhl3 bool = l >= 0 for yyj3 := 0; ; yyj3++ { if yyhl3 { if yyj3 >= l { break } } else { if z.DecCheckBreak() { break } } z.DecReadMapElemKey() yys3 := r.DecodeStringAsBytes() z.DecReadMapElemValue() switch string(yys3) { case "S": x.TestStrucCommon.S = (string)(z.DecStringZC(r.DecodeStringAsBytes())) case "I64": x.TestStrucCommon.I64 = (int64)(r.DecodeInt64()) case "I32": x.TestStrucCommon.I32 = (int32)(z.C.IntV(r.DecodeInt64(), 32)) case "I16": x.TestStrucCommon.I16 = (int16)(z.C.IntV(r.DecodeInt64(), 16)) case "I8": x.TestStrucCommon.I8 = (int8)(z.C.IntV(r.DecodeInt64(), 8)) case "I64n": x.TestStrucCommon.I64n = (int64)(r.DecodeInt64()) case "I32n": x.TestStrucCommon.I32n = (int32)(z.C.IntV(r.DecodeInt64(), 32)) case "I16n": x.TestStrucCommon.I16n = (int16)(z.C.IntV(r.DecodeInt64(), 16)) case "I8n": x.TestStrucCommon.I8n = (int8)(z.C.IntV(r.DecodeInt64(), 8)) case "Ui64": x.TestStrucCommon.Ui64 = (uint64)(r.DecodeUint64()) case "Ui32": x.TestStrucCommon.Ui32 = (uint32)(z.C.UintV(r.DecodeUint64(), 32)) case "Ui16": x.TestStrucCommon.Ui16 = (uint16)(z.C.UintV(r.DecodeUint64(), 16)) case "Ui8": x.TestStrucCommon.Ui8 = (uint8)(z.C.UintV(r.DecodeUint64(), 8)) case "F64": x.TestStrucCommon.F64 = (float64)(r.DecodeFloat64()) case "F32": x.TestStrucCommon.F32 = (float32)(z.DecDecodeFloat32()) case "B": x.TestStrucCommon.B = (bool)(r.DecodeBool()) case "By": x.TestStrucCommon.By = (uint8)(z.C.UintV(r.DecodeUint64(), 8)) case "Sslice": z.F.DecSliceStringX(&x.TestStrucCommon.Sslice, d) case "I64slice": z.F.DecSliceInt64X(&x.TestStrucCommon.I64slice, d) case "I32slice": z.F.DecSliceInt32X(&x.TestStrucCommon.I32slice, d) case "Ui64slice": z.F.DecSliceUint64X(&x.TestStrucCommon.Ui64slice, d) case "Ui8slice": x.TestStrucCommon.Ui8slice = z.DecodeBytesInto(([]byte)(x.TestStrucCommon.Ui8slice)) case "Bslice": z.F.DecSliceBoolX(&x.TestStrucCommon.Bslice, d) case "Byslice": x.TestStrucCommon.Byslice = z.DecodeBytesInto(([]byte)(x.TestStrucCommon.Byslice)) case "BytesSlice": z.F.DecSliceBytesX(&x.TestStrucCommon.BytesSlice, d) case "Iptrslice": h.decSlicePtrtoint64((*[]*int64)(&x.TestStrucCommon.Iptrslice), d) case "WrapSliceInt64": if yyxt40 := z.Extension(x.TestStrucCommon.WrapSliceInt64); yyxt40 != nil { z.DecExtension(&x.TestStrucCommon.WrapSliceInt64, yyxt40) } else { x.TestStrucCommon.WrapSliceInt64.CodecDecodeSelf(d) } case "WrapSliceString": if yyxt42 := z.Extension(x.TestStrucCommon.WrapSliceString); yyxt42 != nil { z.DecExtension(&x.TestStrucCommon.WrapSliceString, yyxt42) } else { x.TestStrucCommon.WrapSliceString.CodecDecodeSelf(d) } case "Msint": z.F.DecMapStringIntX(&x.TestStrucCommon.Msint, d) case "Msbytes": z.F.DecMapStringBytesX(&x.TestStrucCommon.Msbytes, d) case "Simplef": if yyxt48 := z.Extension(x.TestStrucCommon.Simplef); yyxt48 != nil { z.DecExtension(&x.TestStrucCommon.Simplef, yyxt48) } else { x.TestStrucCommon.Simplef.CodecDecodeSelf(d) } case "SstrUi64T": h.decSlicestringUint64T((*[]stringUint64T)(&x.TestStrucCommon.SstrUi64T), d) case "MstrUi64T": h.decMapstringPtrtostringUint64T((*map[string]*stringUint64T)(&x.TestStrucCommon.MstrUi64T), d) case "AS": x.TestStrucCommon.AnonInTestStruc.AS = (string)(z.DecStringZC(r.DecodeStringAsBytes())) case "AI64": x.TestStrucCommon.AnonInTestStruc.AI64 = (int64)(r.DecodeInt64()) case "AI16": x.TestStrucCommon.AnonInTestStruc.AI16 = (int16)(z.C.IntV(r.DecodeInt64(), 16)) case "AUi64": x.TestStrucCommon.AnonInTestStruc.AUi64 = (uint64)(r.DecodeUint64()) case "ASslice": z.F.DecSliceStringX(&x.TestStrucCommon.AnonInTestStruc.ASslice, d) case "AI64slice": z.F.DecSliceInt64X(&x.TestStrucCommon.AnonInTestStruc.AI64slice, d) case "AUi64slice": z.F.DecSliceUint64X(&x.TestStrucCommon.AnonInTestStruc.AUi64slice, d) case "AF64slice": z.F.DecSliceFloat64X(&x.TestStrucCommon.AnonInTestStruc.AF64slice, d) case "AF32slice": z.F.DecSliceFloat32X(&x.TestStrucCommon.AnonInTestStruc.AF32slice, d) case "AMSS": z.F.DecMapStringStringX(&x.TestStrucCommon.AnonInTestStruc.AMSS, d) case "AMSU64": z.F.DecMapStringUint64X(&x.TestStrucCommon.AnonInTestStruc.AMSU64, d) case "AI64arr8": h.decArray8int64((*[8]int64)(&x.TestStrucCommon.AnonInTestStruc.AI64arr8), d) case "AI64arr0": h.decArray0int64((*[0]int64)(&x.TestStrucCommon.AnonInTestStruc.AI64arr0), d) case "AI64slice0": z.F.DecSliceInt64X(&x.TestStrucCommon.AnonInTestStruc.AI64slice0, d) case "AUi64sliceN": z.F.DecSliceUint64X(&x.TestStrucCommon.AnonInTestStruc.AUi64sliceN, d) case "AMSU64N": z.F.DecMapStringUint64X(&x.TestStrucCommon.AnonInTestStruc.AMSU64N, d) case "AMSU64E": z.F.DecMapStringUint64X(&x.TestStrucCommon.AnonInTestStruc.AMSU64E, d) case "NotAnon": if yyxt84 := z.Extension(x.TestStrucCommon.NotAnon); yyxt84 != nil { z.DecExtension(&x.TestStrucCommon.NotAnon, yyxt84) } else { x.TestStrucCommon.NotAnon.CodecDecodeSelf(d) } case "P": if r.TryNil() { if x.TestStrucCommon.AnonInTestStrucSlim != nil && x.TestStrucCommon.AnonInTestStrucSlim.P != nil { // remove the if-true x.TestStrucCommon.AnonInTestStrucSlim.P = nil } } else { if x.TestStrucCommon.AnonInTestStrucSlim == nil { x.TestStrucCommon.AnonInTestStrucSlim = new(AnonInTestStrucSlim) } if x.TestStrucCommon.AnonInTestStrucSlim.P == nil { x.TestStrucCommon.AnonInTestStrucSlim.P = new(string) } *x.TestStrucCommon.AnonInTestStrucSlim.P = (string)(z.DecStringZC(r.DecodeStringAsBytes())) } case "NotAnonSlim": if r.TryNil() { if x.TestStrucCommon.NotAnonSlim != nil { // remove the if-true x.TestStrucCommon.NotAnonSlim = nil } } else { if x.TestStrucCommon.NotAnonSlim == nil { x.TestStrucCommon.NotAnonSlim = new(AnonInTestStrucSlim) } if yyxt88 := z.Extension(x.TestStrucCommon.NotAnonSlim); yyxt88 != nil { z.DecExtension(x.TestStrucCommon.NotAnonSlim, yyxt88) } else { x.TestStrucCommon.NotAnonSlim.CodecDecodeSelf(d) } } case "Nmap": z.F.DecMapStringBoolX(&x.TestStrucCommon.Nmap, d) case "Nslice": x.TestStrucCommon.Nslice = z.DecodeBytesInto(([]byte)(x.TestStrucCommon.Nslice)) case "Nint64": if r.TryNil() { if x.TestStrucCommon.Nint64 != nil { // remove the if-true x.TestStrucCommon.Nint64 = nil } } else { if x.TestStrucCommon.Nint64 == nil { x.TestStrucCommon.Nint64 = new(int64) } *x.TestStrucCommon.Nint64 = (int64)(r.DecodeInt64()) } case "Mtsptr": h.decMapstringPtrtoTestStruc((*map[string]*TestStruc)(&x.Mtsptr), d) case "Mts": h.decMapstringTestStruc((*map[string]TestStruc)(&x.Mts), d) case "Its": h.decSlicePtrtoTestStruc((*[]*TestStruc)(&x.Its), d) case "Nteststruc": if r.TryNil() { if x.Nteststruc != nil { // remove the if-true x.Nteststruc = nil } } else { if x.Nteststruc == nil { x.Nteststruc = new(TestStruc) } if yyxt102 := z.Extension(x.Nteststruc); yyxt102 != nil { z.DecExtension(x.Nteststruc, yyxt102) } else { x.Nteststruc.CodecDecodeSelf(d) } } default: z.DecStructFieldNotFound(-1, string(yys3)) } // end switch yys3 } // end for yyj3 } func (x *TestStruc) codecDecodeSelfFromArray(l int, d *Decoder) { var h codecSelfer19780 z, r := GenHelper().Decoder(d) _, _, _ = h, z, r var yyj103 int var yyb103 bool var yyhl103 bool = l >= 0 yyj103++ if yyhl103 { yyb103 = yyj103 > l } else { yyb103 = z.DecCheckBreak() } if yyb103 { z.DecReadArrayEnd() return } z.DecReadArrayElem() x.TestStrucCommon.S = (string)(z.DecStringZC(r.DecodeStringAsBytes())) yyj103++ if yyhl103 { yyb103 = yyj103 > l } else { yyb103 = z.DecCheckBreak() } if yyb103 { z.DecReadArrayEnd() return } z.DecReadArrayElem() x.TestStrucCommon.I64 = (int64)(r.DecodeInt64()) yyj103++ if yyhl103 { yyb103 = yyj103 > l } else { yyb103 = z.DecCheckBreak() } if yyb103 { z.DecReadArrayEnd() return } z.DecReadArrayElem() x.TestStrucCommon.I32 = (int32)(z.C.IntV(r.DecodeInt64(), 32)) yyj103++ if yyhl103 { yyb103 = yyj103 > l } else { yyb103 = z.DecCheckBreak() } if yyb103 { z.DecReadArrayEnd() return } z.DecReadArrayElem() x.TestStrucCommon.I16 = (int16)(z.C.IntV(r.DecodeInt64(), 16)) yyj103++ if yyhl103 { yyb103 = yyj103 > l } else { yyb103 = z.DecCheckBreak() } if yyb103 { z.DecReadArrayEnd() return } z.DecReadArrayElem() x.TestStrucCommon.I8 = (int8)(z.C.IntV(r.DecodeInt64(), 8)) yyj103++ if yyhl103 { yyb103 = yyj103 > l } else { yyb103 = z.DecCheckBreak() } if yyb103 { z.DecReadArrayEnd() return } z.DecReadArrayElem() x.TestStrucCommon.I64n = (int64)(r.DecodeInt64()) yyj103++ if yyhl103 { yyb103 = yyj103 > l } else { yyb103 = z.DecCheckBreak() } if yyb103 { z.DecReadArrayEnd() return } z.DecReadArrayElem() x.TestStrucCommon.I32n = (int32)(z.C.IntV(r.DecodeInt64(), 32)) yyj103++ if yyhl103 { yyb103 = yyj103 > l } else { yyb103 = z.DecCheckBreak() } if yyb103 { z.DecReadArrayEnd() return } z.DecReadArrayElem() x.TestStrucCommon.I16n = (int16)(z.C.IntV(r.DecodeInt64(), 16)) yyj103++ if yyhl103 { yyb103 = yyj103 > l } else { yyb103 = z.DecCheckBreak() } if yyb103 { z.DecReadArrayEnd() return } z.DecReadArrayElem() x.TestStrucCommon.I8n = (int8)(z.C.IntV(r.DecodeInt64(), 8)) yyj103++ if yyhl103 { yyb103 = yyj103 > l } else { yyb103 = z.DecCheckBreak() } if yyb103 { z.DecReadArrayEnd() return } z.DecReadArrayElem() x.TestStrucCommon.Ui64 = (uint64)(r.DecodeUint64()) yyj103++ if yyhl103 { yyb103 = yyj103 > l } else { yyb103 = z.DecCheckBreak() } if yyb103 { z.DecReadArrayEnd() return } z.DecReadArrayElem() x.TestStrucCommon.Ui32 = (uint32)(z.C.UintV(r.DecodeUint64(), 32)) yyj103++ if yyhl103 { yyb103 = yyj103 > l } else { yyb103 = z.DecCheckBreak() } if yyb103 { z.DecReadArrayEnd() return } z.DecReadArrayElem() x.TestStrucCommon.Ui16 = (uint16)(z.C.UintV(r.DecodeUint64(), 16)) yyj103++ if yyhl103 { yyb103 = yyj103 > l } else { yyb103 = z.DecCheckBreak() } if yyb103 { z.DecReadArrayEnd() return } z.DecReadArrayElem() x.TestStrucCommon.Ui8 = (uint8)(z.C.UintV(r.DecodeUint64(), 8)) yyj103++ if yyhl103 { yyb103 = yyj103 > l } else { yyb103 = z.DecCheckBreak() } if yyb103 { z.DecReadArrayEnd() return } z.DecReadArrayElem() x.TestStrucCommon.F64 = (float64)(r.DecodeFloat64()) yyj103++ if yyhl103 { yyb103 = yyj103 > l } else { yyb103 = z.DecCheckBreak() } if yyb103 { z.DecReadArrayEnd() return } z.DecReadArrayElem() x.TestStrucCommon.F32 = (float32)(z.DecDecodeFloat32()) yyj103++ if yyhl103 { yyb103 = yyj103 > l } else { yyb103 = z.DecCheckBreak() } if yyb103 { z.DecReadArrayEnd() return } z.DecReadArrayElem() x.TestStrucCommon.B = (bool)(r.DecodeBool()) yyj103++ if yyhl103 { yyb103 = yyj103 > l } else { yyb103 = z.DecCheckBreak() } if yyb103 { z.DecReadArrayEnd() return } z.DecReadArrayElem() x.TestStrucCommon.By = (uint8)(z.C.UintV(r.DecodeUint64(), 8)) yyj103++ if yyhl103 { yyb103 = yyj103 > l } else { yyb103 = z.DecCheckBreak() } if yyb103 { z.DecReadArrayEnd() return } z.DecReadArrayElem() z.F.DecSliceStringX(&x.TestStrucCommon.Sslice, d) yyj103++ if yyhl103 { yyb103 = yyj103 > l } else { yyb103 = z.DecCheckBreak() } if yyb103 { z.DecReadArrayEnd() return } z.DecReadArrayElem() z.F.DecSliceInt64X(&x.TestStrucCommon.I64slice, d) yyj103++ if yyhl103 { yyb103 = yyj103 > l } else { yyb103 = z.DecCheckBreak() } if yyb103 { z.DecReadArrayEnd() return } z.DecReadArrayElem() z.F.DecSliceInt32X(&x.TestStrucCommon.I32slice, d) yyj103++ if yyhl103 { yyb103 = yyj103 > l } else { yyb103 = z.DecCheckBreak() } if yyb103 { z.DecReadArrayEnd() return } z.DecReadArrayElem() z.F.DecSliceUint64X(&x.TestStrucCommon.Ui64slice, d) yyj103++ if yyhl103 { yyb103 = yyj103 > l } else { yyb103 = z.DecCheckBreak() } if yyb103 { z.DecReadArrayEnd() return } z.DecReadArrayElem() x.TestStrucCommon.Ui8slice = z.DecodeBytesInto(([]byte)(x.TestStrucCommon.Ui8slice)) yyj103++ if yyhl103 { yyb103 = yyj103 > l } else { yyb103 = z.DecCheckBreak() } if yyb103 { z.DecReadArrayEnd() return } z.DecReadArrayElem() z.F.DecSliceBoolX(&x.TestStrucCommon.Bslice, d) yyj103++ if yyhl103 { yyb103 = yyj103 > l } else { yyb103 = z.DecCheckBreak() } if yyb103 { z.DecReadArrayEnd() return } z.DecReadArrayElem() x.TestStrucCommon.Byslice = z.DecodeBytesInto(([]byte)(x.TestStrucCommon.Byslice)) yyj103++ if yyhl103 { yyb103 = yyj103 > l } else { yyb103 = z.DecCheckBreak() } if yyb103 { z.DecReadArrayEnd() return } z.DecReadArrayElem() z.F.DecSliceBytesX(&x.TestStrucCommon.BytesSlice, d) yyj103++ if yyhl103 { yyb103 = yyj103 > l } else { yyb103 = z.DecCheckBreak() } if yyb103 { z.DecReadArrayEnd() return } z.DecReadArrayElem() h.decSlicePtrtoint64((*[]*int64)(&x.TestStrucCommon.Iptrslice), d) yyj103++ if yyhl103 { yyb103 = yyj103 > l } else { yyb103 = z.DecCheckBreak() } if yyb103 { z.DecReadArrayEnd() return } z.DecReadArrayElem() if yyxt140 := z.Extension(x.TestStrucCommon.WrapSliceInt64); yyxt140 != nil { z.DecExtension(&x.TestStrucCommon.WrapSliceInt64, yyxt140) } else { x.TestStrucCommon.WrapSliceInt64.CodecDecodeSelf(d) } yyj103++ if yyhl103 { yyb103 = yyj103 > l } else { yyb103 = z.DecCheckBreak() } if yyb103 { z.DecReadArrayEnd() return } z.DecReadArrayElem() if yyxt142 := z.Extension(x.TestStrucCommon.WrapSliceString); yyxt142 != nil { z.DecExtension(&x.TestStrucCommon.WrapSliceString, yyxt142) } else { x.TestStrucCommon.WrapSliceString.CodecDecodeSelf(d) } yyj103++ if yyhl103 { yyb103 = yyj103 > l } else { yyb103 = z.DecCheckBreak() } if yyb103 { z.DecReadArrayEnd() return } z.DecReadArrayElem() z.F.DecMapStringIntX(&x.TestStrucCommon.Msint, d) yyj103++ if yyhl103 { yyb103 = yyj103 > l } else { yyb103 = z.DecCheckBreak() } if yyb103 { z.DecReadArrayEnd() return } z.DecReadArrayElem() z.F.DecMapStringBytesX(&x.TestStrucCommon.Msbytes, d) yyj103++ if yyhl103 { yyb103 = yyj103 > l } else { yyb103 = z.DecCheckBreak() } if yyb103 { z.DecReadArrayEnd() return } z.DecReadArrayElem() if yyxt148 := z.Extension(x.TestStrucCommon.Simplef); yyxt148 != nil { z.DecExtension(&x.TestStrucCommon.Simplef, yyxt148) } else { x.TestStrucCommon.Simplef.CodecDecodeSelf(d) } yyj103++ if yyhl103 { yyb103 = yyj103 > l } else { yyb103 = z.DecCheckBreak() } if yyb103 { z.DecReadArrayEnd() return } z.DecReadArrayElem() h.decSlicestringUint64T((*[]stringUint64T)(&x.TestStrucCommon.SstrUi64T), d) yyj103++ if yyhl103 { yyb103 = yyj103 > l } else { yyb103 = z.DecCheckBreak() } if yyb103 { z.DecReadArrayEnd() return } z.DecReadArrayElem() h.decMapstringPtrtostringUint64T((*map[string]*stringUint64T)(&x.TestStrucCommon.MstrUi64T), d) yyj103++ if yyhl103 { yyb103 = yyj103 > l } else { yyb103 = z.DecCheckBreak() } if yyb103 { z.DecReadArrayEnd() return } z.DecReadArrayElem() x.TestStrucCommon.AnonInTestStruc.AS = (string)(z.DecStringZC(r.DecodeStringAsBytes())) yyj103++ if yyhl103 { yyb103 = yyj103 > l } else { yyb103 = z.DecCheckBreak() } if yyb103 { z.DecReadArrayEnd() return } z.DecReadArrayElem() x.TestStrucCommon.AnonInTestStruc.AI64 = (int64)(r.DecodeInt64()) yyj103++ if yyhl103 { yyb103 = yyj103 > l } else { yyb103 = z.DecCheckBreak() } if yyb103 { z.DecReadArrayEnd() return } z.DecReadArrayElem() x.TestStrucCommon.AnonInTestStruc.AI16 = (int16)(z.C.IntV(r.DecodeInt64(), 16)) yyj103++ if yyhl103 { yyb103 = yyj103 > l } else { yyb103 = z.DecCheckBreak() } if yyb103 { z.DecReadArrayEnd() return } z.DecReadArrayElem() x.TestStrucCommon.AnonInTestStruc.AUi64 = (uint64)(r.DecodeUint64()) yyj103++ if yyhl103 { yyb103 = yyj103 > l } else { yyb103 = z.DecCheckBreak() } if yyb103 { z.DecReadArrayEnd() return } z.DecReadArrayElem() z.F.DecSliceStringX(&x.TestStrucCommon.AnonInTestStruc.ASslice, d) yyj103++ if yyhl103 { yyb103 = yyj103 > l } else { yyb103 = z.DecCheckBreak() } if yyb103 { z.DecReadArrayEnd() return } z.DecReadArrayElem() z.F.DecSliceInt64X(&x.TestStrucCommon.AnonInTestStruc.AI64slice, d) yyj103++ if yyhl103 { yyb103 = yyj103 > l } else { yyb103 = z.DecCheckBreak() } if yyb103 { z.DecReadArrayEnd() return } z.DecReadArrayElem() z.F.DecSliceUint64X(&x.TestStrucCommon.AnonInTestStruc.AUi64slice, d) yyj103++ if yyhl103 { yyb103 = yyj103 > l } else { yyb103 = z.DecCheckBreak() } if yyb103 { z.DecReadArrayEnd() return } z.DecReadArrayElem() z.F.DecSliceFloat64X(&x.TestStrucCommon.AnonInTestStruc.AF64slice, d) yyj103++ if yyhl103 { yyb103 = yyj103 > l } else { yyb103 = z.DecCheckBreak() } if yyb103 { z.DecReadArrayEnd() return } z.DecReadArrayElem() z.F.DecSliceFloat32X(&x.TestStrucCommon.AnonInTestStruc.AF32slice, d) yyj103++ if yyhl103 { yyb103 = yyj103 > l } else { yyb103 = z.DecCheckBreak() } if yyb103 { z.DecReadArrayEnd() return } z.DecReadArrayElem() z.F.DecMapStringStringX(&x.TestStrucCommon.AnonInTestStruc.AMSS, d) yyj103++ if yyhl103 { yyb103 = yyj103 > l } else { yyb103 = z.DecCheckBreak() } if yyb103 { z.DecReadArrayEnd() return } z.DecReadArrayElem() z.F.DecMapStringUint64X(&x.TestStrucCommon.AnonInTestStruc.AMSU64, d) yyj103++ if yyhl103 { yyb103 = yyj103 > l } else { yyb103 = z.DecCheckBreak() } if yyb103 { z.DecReadArrayEnd() return } z.DecReadArrayElem() h.decArray8int64((*[8]int64)(&x.TestStrucCommon.AnonInTestStruc.AI64arr8), d) yyj103++ if yyhl103 { yyb103 = yyj103 > l } else { yyb103 = z.DecCheckBreak() } if yyb103 { z.DecReadArrayEnd() return } z.DecReadArrayElem() h.decArray0int64((*[0]int64)(&x.TestStrucCommon.AnonInTestStruc.AI64arr0), d) yyj103++ if yyhl103 { yyb103 = yyj103 > l } else { yyb103 = z.DecCheckBreak() } if yyb103 { z.DecReadArrayEnd() return } z.DecReadArrayElem() z.F.DecSliceInt64X(&x.TestStrucCommon.AnonInTestStruc.AI64slice0, d) yyj103++ if yyhl103 { yyb103 = yyj103 > l } else { yyb103 = z.DecCheckBreak() } if yyb103 { z.DecReadArrayEnd() return } z.DecReadArrayElem() z.F.DecSliceUint64X(&x.TestStrucCommon.AnonInTestStruc.AUi64sliceN, d) yyj103++ if yyhl103 { yyb103 = yyj103 > l } else { yyb103 = z.DecCheckBreak() } if yyb103 { z.DecReadArrayEnd() return } z.DecReadArrayElem() z.F.DecMapStringUint64X(&x.TestStrucCommon.AnonInTestStruc.AMSU64N, d) yyj103++ if yyhl103 { yyb103 = yyj103 > l } else { yyb103 = z.DecCheckBreak() } if yyb103 { z.DecReadArrayEnd() return } z.DecReadArrayElem() z.F.DecMapStringUint64X(&x.TestStrucCommon.AnonInTestStruc.AMSU64E, d) yyj103++ if yyhl103 { yyb103 = yyj103 > l } else { yyb103 = z.DecCheckBreak() } if yyb103 { z.DecReadArrayEnd() return } z.DecReadArrayElem() if yyxt184 := z.Extension(x.TestStrucCommon.NotAnon); yyxt184 != nil { z.DecExtension(&x.TestStrucCommon.NotAnon, yyxt184) } else { x.TestStrucCommon.NotAnon.CodecDecodeSelf(d) } yyj103++ if yyhl103 { yyb103 = yyj103 > l } else { yyb103 = z.DecCheckBreak() } if yyb103 { z.DecReadArrayEnd() return } z.DecReadArrayElem() if r.TryNil() { if x.TestStrucCommon.AnonInTestStrucSlim != nil && x.TestStrucCommon.AnonInTestStrucSlim.P != nil { // remove the if-true x.TestStrucCommon.AnonInTestStrucSlim.P = nil } } else { if x.TestStrucCommon.AnonInTestStrucSlim == nil { x.TestStrucCommon.AnonInTestStrucSlim = new(AnonInTestStrucSlim) } if x.TestStrucCommon.AnonInTestStrucSlim.P == nil { x.TestStrucCommon.AnonInTestStrucSlim.P = new(string) } *x.TestStrucCommon.AnonInTestStrucSlim.P = (string)(z.DecStringZC(r.DecodeStringAsBytes())) } yyj103++ if yyhl103 { yyb103 = yyj103 > l } else { yyb103 = z.DecCheckBreak() } if yyb103 { z.DecReadArrayEnd() return } z.DecReadArrayElem() if r.TryNil() { if x.TestStrucCommon.NotAnonSlim != nil { // remove the if-true x.TestStrucCommon.NotAnonSlim = nil } } else { if x.TestStrucCommon.NotAnonSlim == nil { x.TestStrucCommon.NotAnonSlim = new(AnonInTestStrucSlim) } if yyxt188 := z.Extension(x.TestStrucCommon.NotAnonSlim); yyxt188 != nil { z.DecExtension(x.TestStrucCommon.NotAnonSlim, yyxt188) } else { x.TestStrucCommon.NotAnonSlim.CodecDecodeSelf(d) } } yyj103++ if yyhl103 { yyb103 = yyj103 > l } else { yyb103 = z.DecCheckBreak() } if yyb103 { z.DecReadArrayEnd() return } z.DecReadArrayElem() z.F.DecMapStringBoolX(&x.TestStrucCommon.Nmap, d) yyj103++ if yyhl103 { yyb103 = yyj103 > l } else { yyb103 = z.DecCheckBreak() } if yyb103 { z.DecReadArrayEnd() return } z.DecReadArrayElem() x.TestStrucCommon.Nslice = z.DecodeBytesInto(([]byte)(x.TestStrucCommon.Nslice)) yyj103++ if yyhl103 { yyb103 = yyj103 > l } else { yyb103 = z.DecCheckBreak() } if yyb103 { z.DecReadArrayEnd() return } z.DecReadArrayElem() if r.TryNil() { if x.TestStrucCommon.Nint64 != nil { // remove the if-true x.TestStrucCommon.Nint64 = nil } } else { if x.TestStrucCommon.Nint64 == nil { x.TestStrucCommon.Nint64 = new(int64) } *x.TestStrucCommon.Nint64 = (int64)(r.DecodeInt64()) } yyj103++ if yyhl103 { yyb103 = yyj103 > l } else { yyb103 = z.DecCheckBreak() } if yyb103 { z.DecReadArrayEnd() return } z.DecReadArrayElem() h.decMapstringPtrtoTestStruc((*map[string]*TestStruc)(&x.Mtsptr), d) yyj103++ if yyhl103 { yyb103 = yyj103 > l } else { yyb103 = z.DecCheckBreak() } if yyb103 { z.DecReadArrayEnd() return } z.DecReadArrayElem() h.decMapstringTestStruc((*map[string]TestStruc)(&x.Mts), d) yyj103++ if yyhl103 { yyb103 = yyj103 > l } else { yyb103 = z.DecCheckBreak() } if yyb103 { z.DecReadArrayEnd() return } z.DecReadArrayElem() h.decSlicePtrtoTestStruc((*[]*TestStruc)(&x.Its), d) yyj103++ if yyhl103 { yyb103 = yyj103 > l } else { yyb103 = z.DecCheckBreak() } if yyb103 { z.DecReadArrayEnd() return } z.DecReadArrayElem() if r.TryNil() { if x.Nteststruc != nil { // remove the if-true x.Nteststruc = nil } } else { if x.Nteststruc == nil { x.Nteststruc = new(TestStruc) } if yyxt202 := z.Extension(x.Nteststruc); yyxt202 != nil { z.DecExtension(x.Nteststruc, yyxt202) } else { x.Nteststruc.CodecDecodeSelf(d) } } for { yyj103++ if yyhl103 { yyb103 = yyj103 > l } else { yyb103 = z.DecCheckBreak() } if yyb103 { break } z.DecReadArrayElem() z.DecStructFieldNotFound(yyj103-1, "") } } func (x *TestStruc) IsCodecEmpty() bool { return !(!(x.TestStrucCommon.IsCodecEmpty()) || len(x.Mtsptr) != 0 || len(x.Mts) != 0 || len(x.Its) != 0 || false) } func (codecgenA) codecSelferViaCodecgen() {} func (x *codecgenA) CodecEncodeSelf(e *Encoder) { var h codecSelfer19780 z, r := GenHelper().Encoder(e) _, _, _ = h, z, r if z.EncBasicHandle().CheckCircularRef { z.EncEncode(x) return } if x == nil { r.EncodeNil() } else { yy2arr2 := z.EncBasicHandle().StructToArray _ = yy2arr2 const yyr2 bool = false // struct tag has 'toArray' if yyr2 || yy2arr2 { z.EncWriteArrayStart(1) z.EncWriteArrayElem() if x.ZZ == nil { r.EncodeNil() } else { r.EncodeStringBytesRaw([]byte(x.ZZ)) } // end block: if x.ZZ slice == nil z.EncWriteArrayEnd() } else { z.EncWriteMapStart(1) if z.EncBasicHandle().Canonical { z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"ZZ\"") } else { r.EncodeString(`ZZ`) } z.EncWriteMapElemValue() if x.ZZ == nil { r.EncodeNil() } else { r.EncodeStringBytesRaw([]byte(x.ZZ)) } // end block: if x.ZZ slice == nil } else { z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"ZZ\"") } else { r.EncodeString(`ZZ`) } z.EncWriteMapElemValue() if x.ZZ == nil { r.EncodeNil() } else { r.EncodeStringBytesRaw([]byte(x.ZZ)) } // end block: if x.ZZ slice == nil } z.EncWriteMapEnd() } } } func (x *codecgenA) CodecDecodeSelf(d *Decoder) { var h codecSelfer19780 z, r := GenHelper().Decoder(d) _, _, _ = h, z, r yyct2 := r.ContainerType() if yyct2 == codecSelferValueTypeNil19780 { *(x) = codecgenA{} } else if yyct2 == codecSelferValueTypeMap19780 { yyl2 := z.DecReadMapStart() if yyl2 == 0 { } else { x.codecDecodeSelfFromMap(yyl2, d) } z.DecReadMapEnd() } else if yyct2 == codecSelferValueTypeArray19780 { yyl2 := z.DecReadArrayStart() if yyl2 != 0 { x.codecDecodeSelfFromArray(yyl2, d) } z.DecReadArrayEnd() } else { panic(errCodecSelferOnlyMapOrArrayEncodeToStruct19780) } } func (x *codecgenA) codecDecodeSelfFromMap(l int, d *Decoder) { var h codecSelfer19780 z, r := GenHelper().Decoder(d) _, _, _ = h, z, r var yyhl3 bool = l >= 0 for yyj3 := 0; ; yyj3++ { if yyhl3 { if yyj3 >= l { break } } else { if z.DecCheckBreak() { break } } z.DecReadMapElemKey() yys3 := r.DecodeStringAsBytes() z.DecReadMapElemValue() switch string(yys3) { case "ZZ": x.ZZ = z.DecodeBytesInto(([]byte)(x.ZZ)) default: z.DecStructFieldNotFound(-1, string(yys3)) } // end switch yys3 } // end for yyj3 } func (x *codecgenA) codecDecodeSelfFromArray(l int, d *Decoder) { var h codecSelfer19780 z, r := GenHelper().Decoder(d) _, _, _ = h, z, r var yyj6 int var yyb6 bool var yyhl6 bool = l >= 0 yyj6++ if yyhl6 { yyb6 = yyj6 > l } else { yyb6 = z.DecCheckBreak() } if yyb6 { z.DecReadArrayEnd() return } z.DecReadArrayElem() x.ZZ = z.DecodeBytesInto(([]byte)(x.ZZ)) for { yyj6++ if yyhl6 { yyb6 = yyj6 > l } else { yyb6 = z.DecCheckBreak() } if yyb6 { break } z.DecReadArrayElem() z.DecStructFieldNotFound(yyj6-1, "") } } func (x *codecgenA) IsCodecEmpty() bool { return !(len(x.ZZ) != 0 || false) } func (codecgenB) codecSelferViaCodecgen() {} func (x *codecgenB) CodecEncodeSelf(e *Encoder) { var h codecSelfer19780 z, r := GenHelper().Encoder(e) _, _, _ = h, z, r if z.EncBasicHandle().CheckCircularRef { z.EncEncode(x) return } if x == nil { r.EncodeNil() } else { yy2arr2 := z.EncBasicHandle().StructToArray _ = yy2arr2 const yyr2 bool = false // struct tag has 'toArray' if yyr2 || yy2arr2 { z.EncWriteArrayStart(1) z.EncWriteArrayElem() yy4 := &x.AA if yyxt5 := z.Extension(yy4); yyxt5 != nil { z.EncExtension(yy4, yyxt5) } else { yy4.CodecEncodeSelf(e) } z.EncWriteArrayEnd() } else { z.EncWriteMapStart(1) if z.EncBasicHandle().Canonical { z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"AA\"") } else { r.EncodeString(`AA`) } z.EncWriteMapElemValue() yy6 := &x.AA if yyxt7 := z.Extension(yy6); yyxt7 != nil { z.EncExtension(yy6, yyxt7) } else { yy6.CodecEncodeSelf(e) } } else { z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"AA\"") } else { r.EncodeString(`AA`) } z.EncWriteMapElemValue() yy8 := &x.AA if yyxt9 := z.Extension(yy8); yyxt9 != nil { z.EncExtension(yy8, yyxt9) } else { yy8.CodecEncodeSelf(e) } } z.EncWriteMapEnd() } } } func (x *codecgenB) CodecDecodeSelf(d *Decoder) { var h codecSelfer19780 z, r := GenHelper().Decoder(d) _, _, _ = h, z, r yyct2 := r.ContainerType() if yyct2 == codecSelferValueTypeNil19780 { *(x) = codecgenB{} } else if yyct2 == codecSelferValueTypeMap19780 { yyl2 := z.DecReadMapStart() if yyl2 == 0 { } else { x.codecDecodeSelfFromMap(yyl2, d) } z.DecReadMapEnd() } else if yyct2 == codecSelferValueTypeArray19780 { yyl2 := z.DecReadArrayStart() if yyl2 != 0 { x.codecDecodeSelfFromArray(yyl2, d) } z.DecReadArrayEnd() } else { panic(errCodecSelferOnlyMapOrArrayEncodeToStruct19780) } } func (x *codecgenB) codecDecodeSelfFromMap(l int, d *Decoder) { var h codecSelfer19780 z, r := GenHelper().Decoder(d) _, _, _ = h, z, r var yyhl3 bool = l >= 0 for yyj3 := 0; ; yyj3++ { if yyhl3 { if yyj3 >= l { break } } else { if z.DecCheckBreak() { break } } z.DecReadMapElemKey() yys3 := r.DecodeStringAsBytes() z.DecReadMapElemValue() switch string(yys3) { case "AA": if yyxt5 := z.Extension(x.AA); yyxt5 != nil { z.DecExtension(&x.AA, yyxt5) } else { x.AA.CodecDecodeSelf(d) } default: z.DecStructFieldNotFound(-1, string(yys3)) } // end switch yys3 } // end for yyj3 } func (x *codecgenB) codecDecodeSelfFromArray(l int, d *Decoder) { var h codecSelfer19780 z, r := GenHelper().Decoder(d) _, _, _ = h, z, r var yyj6 int var yyb6 bool var yyhl6 bool = l >= 0 yyj6++ if yyhl6 { yyb6 = yyj6 > l } else { yyb6 = z.DecCheckBreak() } if yyb6 { z.DecReadArrayEnd() return } z.DecReadArrayElem() if yyxt8 := z.Extension(x.AA); yyxt8 != nil { z.DecExtension(&x.AA, yyxt8) } else { x.AA.CodecDecodeSelf(d) } for { yyj6++ if yyhl6 { yyb6 = yyj6 > l } else { yyb6 = z.DecCheckBreak() } if yyb6 { break } z.DecReadArrayElem() z.DecStructFieldNotFound(yyj6-1, "") } } func (x *codecgenB) IsCodecEmpty() bool { return !(!(x.AA.IsCodecEmpty()) || false) } func (codecgenC) codecSelferViaCodecgen() {} func (x *codecgenC) CodecEncodeSelf(e *Encoder) { var h codecSelfer19780 z, r := GenHelper().Encoder(e) _, _, _ = h, z, r if z.EncBasicHandle().CheckCircularRef { z.EncEncode(x) return } if x == nil { r.EncodeNil() } else { yy2arr2 := z.EncBasicHandle().StructToArray _ = yy2arr2 const yyr2 bool = false // struct tag has 'toArray' var yyq2 = [1]bool{ // should field at this index be written? !(x.BB.IsCodecEmpty()), // BB } _ = yyq2 if yyr2 || yy2arr2 { z.EncWriteArrayStart(1) z.EncWriteArrayElem() if yyq2[0] { yy4 := &x.BB if yyxt5 := z.Extension(yy4); yyxt5 != nil { z.EncExtension(yy4, yyxt5) } else { yy4.CodecEncodeSelf(e) } } else { r.EncodeNil() } z.EncWriteArrayEnd() } else { var yynn2 int for _, b := range yyq2 { if b { yynn2++ } } z.EncWriteMapStart(yynn2) yynn2 = 0 if z.EncBasicHandle().Canonical { if yyq2[0] { z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"BB\"") } else { r.EncodeString(`BB`) } z.EncWriteMapElemValue() yy6 := &x.BB if yyxt7 := z.Extension(yy6); yyxt7 != nil { z.EncExtension(yy6, yyxt7) } else { yy6.CodecEncodeSelf(e) } } } else { if yyq2[0] { z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"BB\"") } else { r.EncodeString(`BB`) } z.EncWriteMapElemValue() yy8 := &x.BB if yyxt9 := z.Extension(yy8); yyxt9 != nil { z.EncExtension(yy8, yyxt9) } else { yy8.CodecEncodeSelf(e) } } } z.EncWriteMapEnd() } } } func (x *codecgenC) CodecDecodeSelf(d *Decoder) { var h codecSelfer19780 z, r := GenHelper().Decoder(d) _, _, _ = h, z, r yyct2 := r.ContainerType() if yyct2 == codecSelferValueTypeNil19780 { *(x) = codecgenC{} } else if yyct2 == codecSelferValueTypeMap19780 { yyl2 := z.DecReadMapStart() if yyl2 == 0 { } else { x.codecDecodeSelfFromMap(yyl2, d) } z.DecReadMapEnd() } else if yyct2 == codecSelferValueTypeArray19780 { yyl2 := z.DecReadArrayStart() if yyl2 != 0 { x.codecDecodeSelfFromArray(yyl2, d) } z.DecReadArrayEnd() } else { panic(errCodecSelferOnlyMapOrArrayEncodeToStruct19780) } } func (x *codecgenC) codecDecodeSelfFromMap(l int, d *Decoder) { var h codecSelfer19780 z, r := GenHelper().Decoder(d) _, _, _ = h, z, r var yyhl3 bool = l >= 0 for yyj3 := 0; ; yyj3++ { if yyhl3 { if yyj3 >= l { break } } else { if z.DecCheckBreak() { break } } z.DecReadMapElemKey() yys3 := r.DecodeStringAsBytes() z.DecReadMapElemValue() switch string(yys3) { case "BB": if yyxt5 := z.Extension(x.BB); yyxt5 != nil { z.DecExtension(&x.BB, yyxt5) } else { x.BB.CodecDecodeSelf(d) } default: z.DecStructFieldNotFound(-1, string(yys3)) } // end switch yys3 } // end for yyj3 } func (x *codecgenC) codecDecodeSelfFromArray(l int, d *Decoder) { var h codecSelfer19780 z, r := GenHelper().Decoder(d) _, _, _ = h, z, r var yyj6 int var yyb6 bool var yyhl6 bool = l >= 0 yyj6++ if yyhl6 { yyb6 = yyj6 > l } else { yyb6 = z.DecCheckBreak() } if yyb6 { z.DecReadArrayEnd() return } z.DecReadArrayElem() if yyxt8 := z.Extension(x.BB); yyxt8 != nil { z.DecExtension(&x.BB, yyxt8) } else { x.BB.CodecDecodeSelf(d) } for { yyj6++ if yyhl6 { yyb6 = yyj6 > l } else { yyb6 = z.DecCheckBreak() } if yyb6 { break } z.DecReadArrayElem() z.DecStructFieldNotFound(yyj6-1, "") } } func (x *codecgenC) IsCodecEmpty() bool { return !(!(x.BB.IsCodecEmpty()) || false) } func (TestCodecgenG) codecSelferViaCodecgen() {} func (x *TestCodecgenG) CodecEncodeSelf(e *Encoder) { var h codecSelfer19780 z, r := GenHelper().Encoder(e) _, _, _ = h, z, r if z.EncBasicHandle().CheckCircularRef { z.EncEncode(x) return } if x == nil { r.EncodeNil() } else { yy2arr2 := z.EncBasicHandle().StructToArray _ = yy2arr2 const yyr2 bool = false // struct tag has 'toArray' if yyr2 || yy2arr2 { z.EncWriteArrayStart(1) z.EncWriteArrayElem() r.EncodeInt(int64(x.TestCodecgenG)) z.EncWriteArrayEnd() } else { z.EncWriteMapStart(1) if z.EncBasicHandle().Canonical { z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"TestCodecgenG\"") } else { r.EncodeString(`TestCodecgenG`) } z.EncWriteMapElemValue() r.EncodeInt(int64(x.TestCodecgenG)) } else { z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"TestCodecgenG\"") } else { r.EncodeString(`TestCodecgenG`) } z.EncWriteMapElemValue() r.EncodeInt(int64(x.TestCodecgenG)) } z.EncWriteMapEnd() } } } func (x *TestCodecgenG) CodecDecodeSelf(d *Decoder) { var h codecSelfer19780 z, r := GenHelper().Decoder(d) _, _, _ = h, z, r yyct2 := r.ContainerType() if yyct2 == codecSelferValueTypeNil19780 { *(x) = TestCodecgenG{} } else if yyct2 == codecSelferValueTypeMap19780 { yyl2 := z.DecReadMapStart() if yyl2 == 0 { } else { x.codecDecodeSelfFromMap(yyl2, d) } z.DecReadMapEnd() } else if yyct2 == codecSelferValueTypeArray19780 { yyl2 := z.DecReadArrayStart() if yyl2 != 0 { x.codecDecodeSelfFromArray(yyl2, d) } z.DecReadArrayEnd() } else { panic(errCodecSelferOnlyMapOrArrayEncodeToStruct19780) } } func (x *TestCodecgenG) codecDecodeSelfFromMap(l int, d *Decoder) { var h codecSelfer19780 z, r := GenHelper().Decoder(d) _, _, _ = h, z, r var yyhl3 bool = l >= 0 for yyj3 := 0; ; yyj3++ { if yyhl3 { if yyj3 >= l { break } } else { if z.DecCheckBreak() { break } } z.DecReadMapElemKey() yys3 := r.DecodeStringAsBytes() z.DecReadMapElemValue() switch string(yys3) { case "TestCodecgenG": x.TestCodecgenG = (int)(z.C.IntV(r.DecodeInt64(), codecSelferBitsize19780)) default: z.DecStructFieldNotFound(-1, string(yys3)) } // end switch yys3 } // end for yyj3 } func (x *TestCodecgenG) codecDecodeSelfFromArray(l int, d *Decoder) { var h codecSelfer19780 z, r := GenHelper().Decoder(d) _, _, _ = h, z, r var yyj5 int var yyb5 bool var yyhl5 bool = l >= 0 yyj5++ if yyhl5 { yyb5 = yyj5 > l } else { yyb5 = z.DecCheckBreak() } if yyb5 { z.DecReadArrayEnd() return } z.DecReadArrayElem() x.TestCodecgenG = (int)(z.C.IntV(r.DecodeInt64(), codecSelferBitsize19780)) for { yyj5++ if yyhl5 { yyb5 = yyj5 > l } else { yyb5 = z.DecCheckBreak() } if yyb5 { break } z.DecReadArrayElem() z.DecStructFieldNotFound(yyj5-1, "") } } func (x *TestCodecgenG) IsCodecEmpty() bool { return !(x.TestCodecgenG != 0 || false) } func (codecgenH) codecSelferViaCodecgen() {} func (x *codecgenH) CodecEncodeSelf(e *Encoder) { var h codecSelfer19780 z, r := GenHelper().Encoder(e) _, _, _ = h, z, r if z.EncBasicHandle().CheckCircularRef { z.EncEncode(x) return } if x == nil { r.EncodeNil() } else { yy2arr2 := z.EncBasicHandle().StructToArray _ = yy2arr2 const yyr2 bool = false // struct tag has 'toArray' if yyr2 || yy2arr2 { z.EncWriteArrayStart(1) z.EncWriteArrayElem() r.EncodeInt(int64(x.TestCodecgenG.TestCodecgenG)) z.EncWriteArrayEnd() } else { z.EncWriteMapStart(1) if z.EncBasicHandle().Canonical { z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"TestCodecgenG\"") } else { r.EncodeString(`TestCodecgenG`) } z.EncWriteMapElemValue() r.EncodeInt(int64(x.TestCodecgenG.TestCodecgenG)) } else { z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"TestCodecgenG\"") } else { r.EncodeString(`TestCodecgenG`) } z.EncWriteMapElemValue() r.EncodeInt(int64(x.TestCodecgenG.TestCodecgenG)) } z.EncWriteMapEnd() } } } func (x *codecgenH) CodecDecodeSelf(d *Decoder) { var h codecSelfer19780 z, r := GenHelper().Decoder(d) _, _, _ = h, z, r yyct2 := r.ContainerType() if yyct2 == codecSelferValueTypeNil19780 { *(x) = codecgenH{} } else if yyct2 == codecSelferValueTypeMap19780 { yyl2 := z.DecReadMapStart() if yyl2 == 0 { } else { x.codecDecodeSelfFromMap(yyl2, d) } z.DecReadMapEnd() } else if yyct2 == codecSelferValueTypeArray19780 { yyl2 := z.DecReadArrayStart() if yyl2 != 0 { x.codecDecodeSelfFromArray(yyl2, d) } z.DecReadArrayEnd() } else { panic(errCodecSelferOnlyMapOrArrayEncodeToStruct19780) } } func (x *codecgenH) codecDecodeSelfFromMap(l int, d *Decoder) { var h codecSelfer19780 z, r := GenHelper().Decoder(d) _, _, _ = h, z, r var yyhl3 bool = l >= 0 for yyj3 := 0; ; yyj3++ { if yyhl3 { if yyj3 >= l { break } } else { if z.DecCheckBreak() { break } } z.DecReadMapElemKey() yys3 := r.DecodeStringAsBytes() z.DecReadMapElemValue() switch string(yys3) { case "TestCodecgenG": x.TestCodecgenG.TestCodecgenG = (int)(z.C.IntV(r.DecodeInt64(), codecSelferBitsize19780)) default: z.DecStructFieldNotFound(-1, string(yys3)) } // end switch yys3 } // end for yyj3 } func (x *codecgenH) codecDecodeSelfFromArray(l int, d *Decoder) { var h codecSelfer19780 z, r := GenHelper().Decoder(d) _, _, _ = h, z, r var yyj5 int var yyb5 bool var yyhl5 bool = l >= 0 yyj5++ if yyhl5 { yyb5 = yyj5 > l } else { yyb5 = z.DecCheckBreak() } if yyb5 { z.DecReadArrayEnd() return } z.DecReadArrayElem() x.TestCodecgenG.TestCodecgenG = (int)(z.C.IntV(r.DecodeInt64(), codecSelferBitsize19780)) for { yyj5++ if yyhl5 { yyb5 = yyj5 > l } else { yyb5 = z.DecCheckBreak() } if yyb5 { break } z.DecReadArrayElem() z.DecStructFieldNotFound(yyj5-1, "") } } func (x *codecgenH) IsCodecEmpty() bool { return !(!(x.TestCodecgenG.IsCodecEmpty()) || false) } func (codecgenI) codecSelferViaCodecgen() {} func (x *codecgenI) CodecEncodeSelf(e *Encoder) { var h codecSelfer19780 z, r := GenHelper().Encoder(e) _, _, _ = h, z, r if z.EncBasicHandle().CheckCircularRef { z.EncEncode(x) return } if x == nil { r.EncodeNil() } else { yy2arr2 := z.EncBasicHandle().StructToArray _ = yy2arr2 const yyr2 bool = false // struct tag has 'toArray' if yyr2 || yy2arr2 { z.EncWriteArrayStart(1) z.EncWriteArrayElem() r.EncodeInt(int64(x.codecgenH.TestCodecgenG.TestCodecgenG)) z.EncWriteArrayEnd() } else { z.EncWriteMapStart(1) if z.EncBasicHandle().Canonical { z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"TestCodecgenG\"") } else { r.EncodeString(`TestCodecgenG`) } z.EncWriteMapElemValue() r.EncodeInt(int64(x.codecgenH.TestCodecgenG.TestCodecgenG)) } else { z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"TestCodecgenG\"") } else { r.EncodeString(`TestCodecgenG`) } z.EncWriteMapElemValue() r.EncodeInt(int64(x.codecgenH.TestCodecgenG.TestCodecgenG)) } z.EncWriteMapEnd() } } } func (x *codecgenI) CodecDecodeSelf(d *Decoder) { var h codecSelfer19780 z, r := GenHelper().Decoder(d) _, _, _ = h, z, r yyct2 := r.ContainerType() if yyct2 == codecSelferValueTypeNil19780 { *(x) = codecgenI{} } else if yyct2 == codecSelferValueTypeMap19780 { yyl2 := z.DecReadMapStart() if yyl2 == 0 { } else { x.codecDecodeSelfFromMap(yyl2, d) } z.DecReadMapEnd() } else if yyct2 == codecSelferValueTypeArray19780 { yyl2 := z.DecReadArrayStart() if yyl2 != 0 { x.codecDecodeSelfFromArray(yyl2, d) } z.DecReadArrayEnd() } else { panic(errCodecSelferOnlyMapOrArrayEncodeToStruct19780) } } func (x *codecgenI) codecDecodeSelfFromMap(l int, d *Decoder) { var h codecSelfer19780 z, r := GenHelper().Decoder(d) _, _, _ = h, z, r var yyhl3 bool = l >= 0 for yyj3 := 0; ; yyj3++ { if yyhl3 { if yyj3 >= l { break } } else { if z.DecCheckBreak() { break } } z.DecReadMapElemKey() yys3 := r.DecodeStringAsBytes() z.DecReadMapElemValue() switch string(yys3) { case "TestCodecgenG": x.codecgenH.TestCodecgenG.TestCodecgenG = (int)(z.C.IntV(r.DecodeInt64(), codecSelferBitsize19780)) default: z.DecStructFieldNotFound(-1, string(yys3)) } // end switch yys3 } // end for yyj3 } func (x *codecgenI) codecDecodeSelfFromArray(l int, d *Decoder) { var h codecSelfer19780 z, r := GenHelper().Decoder(d) _, _, _ = h, z, r var yyj5 int var yyb5 bool var yyhl5 bool = l >= 0 yyj5++ if yyhl5 { yyb5 = yyj5 > l } else { yyb5 = z.DecCheckBreak() } if yyb5 { z.DecReadArrayEnd() return } z.DecReadArrayElem() x.codecgenH.TestCodecgenG.TestCodecgenG = (int)(z.C.IntV(r.DecodeInt64(), codecSelferBitsize19780)) for { yyj5++ if yyhl5 { yyb5 = yyj5 > l } else { yyb5 = z.DecCheckBreak() } if yyb5 { break } z.DecReadArrayElem() z.DecStructFieldNotFound(yyj5-1, "") } } func (x *codecgenI) IsCodecEmpty() bool { return !(!(x.codecgenH.IsCodecEmpty()) || false) } func (codecgenK) codecSelferViaCodecgen() {} func (x *codecgenK) CodecEncodeSelf(e *Encoder) { var h codecSelfer19780 z, r := GenHelper().Encoder(e) _, _, _ = h, z, r if z.EncBasicHandle().CheckCircularRef { z.EncEncode(x) return } if x == nil { r.EncodeNil() } else { yy2arr2 := z.EncBasicHandle().StructToArray _ = yy2arr2 const yyr2 bool = false // struct tag has 'toArray' if yyr2 || yy2arr2 { z.EncWriteArrayStart(2) z.EncWriteArrayElem() r.EncodeInt(int64(x.X)) z.EncWriteArrayElem() r.EncodeString(string(x.Y)) z.EncWriteArrayEnd() } else { z.EncWriteMapStart(2) if z.EncBasicHandle().Canonical { z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"X\"") } else { r.EncodeString(`X`) } z.EncWriteMapElemValue() r.EncodeInt(int64(x.X)) z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"Y\"") } else { r.EncodeString(`Y`) } z.EncWriteMapElemValue() r.EncodeString(string(x.Y)) } else { z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"X\"") } else { r.EncodeString(`X`) } z.EncWriteMapElemValue() r.EncodeInt(int64(x.X)) z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"Y\"") } else { r.EncodeString(`Y`) } z.EncWriteMapElemValue() r.EncodeString(string(x.Y)) } z.EncWriteMapEnd() } } } func (x *codecgenK) CodecDecodeSelf(d *Decoder) { var h codecSelfer19780 z, r := GenHelper().Decoder(d) _, _, _ = h, z, r yyct2 := r.ContainerType() if yyct2 == codecSelferValueTypeNil19780 { *(x) = codecgenK{} } else if yyct2 == codecSelferValueTypeMap19780 { yyl2 := z.DecReadMapStart() if yyl2 == 0 { } else { x.codecDecodeSelfFromMap(yyl2, d) } z.DecReadMapEnd() } else if yyct2 == codecSelferValueTypeArray19780 { yyl2 := z.DecReadArrayStart() if yyl2 != 0 { x.codecDecodeSelfFromArray(yyl2, d) } z.DecReadArrayEnd() } else { panic(errCodecSelferOnlyMapOrArrayEncodeToStruct19780) } } func (x *codecgenK) codecDecodeSelfFromMap(l int, d *Decoder) { var h codecSelfer19780 z, r := GenHelper().Decoder(d) _, _, _ = h, z, r var yyhl3 bool = l >= 0 for yyj3 := 0; ; yyj3++ { if yyhl3 { if yyj3 >= l { break } } else { if z.DecCheckBreak() { break } } z.DecReadMapElemKey() yys3 := r.DecodeStringAsBytes() z.DecReadMapElemValue() switch string(yys3) { case "X": x.X = (int)(z.C.IntV(r.DecodeInt64(), codecSelferBitsize19780)) case "Y": x.Y = (string)(z.DecStringZC(r.DecodeStringAsBytes())) default: z.DecStructFieldNotFound(-1, string(yys3)) } // end switch yys3 } // end for yyj3 } func (x *codecgenK) codecDecodeSelfFromArray(l int, d *Decoder) { var h codecSelfer19780 z, r := GenHelper().Decoder(d) _, _, _ = h, z, r var yyj6 int var yyb6 bool var yyhl6 bool = l >= 0 yyj6++ if yyhl6 { yyb6 = yyj6 > l } else { yyb6 = z.DecCheckBreak() } if yyb6 { z.DecReadArrayEnd() return } z.DecReadArrayElem() x.X = (int)(z.C.IntV(r.DecodeInt64(), codecSelferBitsize19780)) yyj6++ if yyhl6 { yyb6 = yyj6 > l } else { yyb6 = z.DecCheckBreak() } if yyb6 { z.DecReadArrayEnd() return } z.DecReadArrayElem() x.Y = (string)(z.DecStringZC(r.DecodeStringAsBytes())) for { yyj6++ if yyhl6 { yyb6 = yyj6 > l } else { yyb6 = z.DecCheckBreak() } if yyb6 { break } z.DecReadArrayElem() z.DecStructFieldNotFound(yyj6-1, "") } } func (x *codecgenK) IsCodecEmpty() bool { return !(x.X != 0 || x.Y != "" || false) } func (codecgenL) codecSelferViaCodecgen() {} func (x *codecgenL) CodecEncodeSelf(e *Encoder) { var h codecSelfer19780 z, r := GenHelper().Encoder(e) _, _, _ = h, z, r if z.EncBasicHandle().CheckCircularRef { z.EncEncode(x) return } if x == nil { r.EncodeNil() } else { yy2arr2 := z.EncBasicHandle().StructToArray _ = yy2arr2 const yyr2 bool = false // struct tag has 'toArray' if yyr2 || yy2arr2 { z.EncWriteArrayStart(2) z.EncWriteArrayElem() r.EncodeInt(int64(x.X)) z.EncWriteArrayElem() r.EncodeUint(uint64(x.Y)) z.EncWriteArrayEnd() } else { z.EncWriteMapStart(2) if z.EncBasicHandle().Canonical { z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"X\"") } else { r.EncodeString(`X`) } z.EncWriteMapElemValue() r.EncodeInt(int64(x.X)) z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"Y\"") } else { r.EncodeString(`Y`) } z.EncWriteMapElemValue() r.EncodeUint(uint64(x.Y)) } else { z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"X\"") } else { r.EncodeString(`X`) } z.EncWriteMapElemValue() r.EncodeInt(int64(x.X)) z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"Y\"") } else { r.EncodeString(`Y`) } z.EncWriteMapElemValue() r.EncodeUint(uint64(x.Y)) } z.EncWriteMapEnd() } } } func (x *codecgenL) CodecDecodeSelf(d *Decoder) { var h codecSelfer19780 z, r := GenHelper().Decoder(d) _, _, _ = h, z, r yyct2 := r.ContainerType() if yyct2 == codecSelferValueTypeNil19780 { *(x) = codecgenL{} } else if yyct2 == codecSelferValueTypeMap19780 { yyl2 := z.DecReadMapStart() if yyl2 == 0 { } else { x.codecDecodeSelfFromMap(yyl2, d) } z.DecReadMapEnd() } else if yyct2 == codecSelferValueTypeArray19780 { yyl2 := z.DecReadArrayStart() if yyl2 != 0 { x.codecDecodeSelfFromArray(yyl2, d) } z.DecReadArrayEnd() } else { panic(errCodecSelferOnlyMapOrArrayEncodeToStruct19780) } } func (x *codecgenL) codecDecodeSelfFromMap(l int, d *Decoder) { var h codecSelfer19780 z, r := GenHelper().Decoder(d) _, _, _ = h, z, r var yyhl3 bool = l >= 0 for yyj3 := 0; ; yyj3++ { if yyhl3 { if yyj3 >= l { break } } else { if z.DecCheckBreak() { break } } z.DecReadMapElemKey() yys3 := r.DecodeStringAsBytes() z.DecReadMapElemValue() switch string(yys3) { case "X": x.X = (int)(z.C.IntV(r.DecodeInt64(), codecSelferBitsize19780)) case "Y": x.Y = (uint32)(z.C.UintV(r.DecodeUint64(), 32)) default: z.DecStructFieldNotFound(-1, string(yys3)) } // end switch yys3 } // end for yyj3 } func (x *codecgenL) codecDecodeSelfFromArray(l int, d *Decoder) { var h codecSelfer19780 z, r := GenHelper().Decoder(d) _, _, _ = h, z, r var yyj6 int var yyb6 bool var yyhl6 bool = l >= 0 yyj6++ if yyhl6 { yyb6 = yyj6 > l } else { yyb6 = z.DecCheckBreak() } if yyb6 { z.DecReadArrayEnd() return } z.DecReadArrayElem() x.X = (int)(z.C.IntV(r.DecodeInt64(), codecSelferBitsize19780)) yyj6++ if yyhl6 { yyb6 = yyj6 > l } else { yyb6 = z.DecCheckBreak() } if yyb6 { z.DecReadArrayEnd() return } z.DecReadArrayElem() x.Y = (uint32)(z.C.UintV(r.DecodeUint64(), 32)) for { yyj6++ if yyhl6 { yyb6 = yyj6 > l } else { yyb6 = z.DecCheckBreak() } if yyb6 { break } z.DecReadArrayElem() z.DecStructFieldNotFound(yyj6-1, "") } } func (x *codecgenL) IsCodecEmpty() bool { return !(x.X != 0 || x.Y != 0 || false) } func (codecgenM) codecSelferViaCodecgen() {} func (x *codecgenM) CodecEncodeSelf(e *Encoder) { var h codecSelfer19780 z, r := GenHelper().Encoder(e) _, _, _ = h, z, r if z.EncBasicHandle().CheckCircularRef { z.EncEncode(x) return } if x == nil { r.EncodeNil() } else { yy2arr2 := z.EncBasicHandle().StructToArray _ = yy2arr2 const yyr2 bool = false // struct tag has 'toArray' if yyr2 || yy2arr2 { z.EncWriteArrayStart(2) z.EncWriteArrayElem() r.EncodeInt(int64(x.codecgenK.X)) z.EncWriteArrayElem() r.EncodeString(string(x.codecgenK.Y)) z.EncWriteArrayEnd() } else { z.EncWriteMapStart(2) if z.EncBasicHandle().Canonical { z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"X\"") } else { r.EncodeString(`X`) } z.EncWriteMapElemValue() r.EncodeInt(int64(x.codecgenK.X)) z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"Y\"") } else { r.EncodeString(`Y`) } z.EncWriteMapElemValue() r.EncodeString(string(x.codecgenK.Y)) } else { z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"X\"") } else { r.EncodeString(`X`) } z.EncWriteMapElemValue() r.EncodeInt(int64(x.codecgenK.X)) z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"Y\"") } else { r.EncodeString(`Y`) } z.EncWriteMapElemValue() r.EncodeString(string(x.codecgenK.Y)) } z.EncWriteMapEnd() } } } func (x *codecgenM) CodecDecodeSelf(d *Decoder) { var h codecSelfer19780 z, r := GenHelper().Decoder(d) _, _, _ = h, z, r yyct2 := r.ContainerType() if yyct2 == codecSelferValueTypeNil19780 { *(x) = codecgenM{} } else if yyct2 == codecSelferValueTypeMap19780 { yyl2 := z.DecReadMapStart() if yyl2 == 0 { } else { x.codecDecodeSelfFromMap(yyl2, d) } z.DecReadMapEnd() } else if yyct2 == codecSelferValueTypeArray19780 { yyl2 := z.DecReadArrayStart() if yyl2 != 0 { x.codecDecodeSelfFromArray(yyl2, d) } z.DecReadArrayEnd() } else { panic(errCodecSelferOnlyMapOrArrayEncodeToStruct19780) } } func (x *codecgenM) codecDecodeSelfFromMap(l int, d *Decoder) { var h codecSelfer19780 z, r := GenHelper().Decoder(d) _, _, _ = h, z, r var yyhl3 bool = l >= 0 for yyj3 := 0; ; yyj3++ { if yyhl3 { if yyj3 >= l { break } } else { if z.DecCheckBreak() { break } } z.DecReadMapElemKey() yys3 := r.DecodeStringAsBytes() z.DecReadMapElemValue() switch string(yys3) { case "X": x.codecgenK.X = (int)(z.C.IntV(r.DecodeInt64(), codecSelferBitsize19780)) case "Y": x.codecgenK.Y = (string)(z.DecStringZC(r.DecodeStringAsBytes())) default: z.DecStructFieldNotFound(-1, string(yys3)) } // end switch yys3 } // end for yyj3 } func (x *codecgenM) codecDecodeSelfFromArray(l int, d *Decoder) { var h codecSelfer19780 z, r := GenHelper().Decoder(d) _, _, _ = h, z, r var yyj6 int var yyb6 bool var yyhl6 bool = l >= 0 yyj6++ if yyhl6 { yyb6 = yyj6 > l } else { yyb6 = z.DecCheckBreak() } if yyb6 { z.DecReadArrayEnd() return } z.DecReadArrayElem() x.codecgenK.X = (int)(z.C.IntV(r.DecodeInt64(), codecSelferBitsize19780)) yyj6++ if yyhl6 { yyb6 = yyj6 > l } else { yyb6 = z.DecCheckBreak() } if yyb6 { z.DecReadArrayEnd() return } z.DecReadArrayElem() x.codecgenK.Y = (string)(z.DecStringZC(r.DecodeStringAsBytes())) for { yyj6++ if yyhl6 { yyb6 = yyj6 > l } else { yyb6 = z.DecCheckBreak() } if yyb6 { break } z.DecReadArrayElem() z.DecStructFieldNotFound(yyj6-1, "") } } func (x *codecgenM) IsCodecEmpty() bool { return !(!(x.codecgenK.IsCodecEmpty()) || false) } func (testStrucKeyTypeT0) codecSelferViaCodecgen() {} func (x *testStrucKeyTypeT0) CodecEncodeSelf(e *Encoder) { var h codecSelfer19780 z, r := GenHelper().Encoder(e) _, _, _ = h, z, r if z.EncBasicHandle().CheckCircularRef { z.EncEncode(x) return } if x == nil { r.EncodeNil() } else { yy2arr2 := z.EncBasicHandle().StructToArray _ = yy2arr2 const yyr2 bool = false // struct tag has 'toArray' if yyr2 || yy2arr2 { z.EncWriteArrayStart(1) z.EncWriteArrayElem() r.EncodeInt(int64(x.F)) z.EncWriteArrayEnd() } else { z.EncWriteMapStart(1) if z.EncBasicHandle().Canonical { z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"F\"") } else { r.EncodeString(`F`) } z.EncWriteMapElemValue() r.EncodeInt(int64(x.F)) } else { z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"F\"") } else { r.EncodeString(`F`) } z.EncWriteMapElemValue() r.EncodeInt(int64(x.F)) } z.EncWriteMapEnd() } } } func (x *testStrucKeyTypeT0) CodecDecodeSelf(d *Decoder) { var h codecSelfer19780 z, r := GenHelper().Decoder(d) _, _, _ = h, z, r yyct2 := r.ContainerType() if yyct2 == codecSelferValueTypeNil19780 { *(x) = testStrucKeyTypeT0{} } else if yyct2 == codecSelferValueTypeMap19780 { yyl2 := z.DecReadMapStart() if yyl2 == 0 { } else { x.codecDecodeSelfFromMap(yyl2, d) } z.DecReadMapEnd() } else if yyct2 == codecSelferValueTypeArray19780 { yyl2 := z.DecReadArrayStart() if yyl2 != 0 { x.codecDecodeSelfFromArray(yyl2, d) } z.DecReadArrayEnd() } else { panic(errCodecSelferOnlyMapOrArrayEncodeToStruct19780) } } func (x *testStrucKeyTypeT0) codecDecodeSelfFromMap(l int, d *Decoder) { var h codecSelfer19780 z, r := GenHelper().Decoder(d) _, _, _ = h, z, r var yyhl3 bool = l >= 0 for yyj3 := 0; ; yyj3++ { if yyhl3 { if yyj3 >= l { break } } else { if z.DecCheckBreak() { break } } z.DecReadMapElemKey() yys3 := r.DecodeStringAsBytes() z.DecReadMapElemValue() switch string(yys3) { case "F": x.F = (int)(z.C.IntV(r.DecodeInt64(), codecSelferBitsize19780)) default: z.DecStructFieldNotFound(-1, string(yys3)) } // end switch yys3 } // end for yyj3 } func (x *testStrucKeyTypeT0) codecDecodeSelfFromArray(l int, d *Decoder) { var h codecSelfer19780 z, r := GenHelper().Decoder(d) _, _, _ = h, z, r var yyj5 int var yyb5 bool var yyhl5 bool = l >= 0 yyj5++ if yyhl5 { yyb5 = yyj5 > l } else { yyb5 = z.DecCheckBreak() } if yyb5 { z.DecReadArrayEnd() return } z.DecReadArrayElem() x.F = (int)(z.C.IntV(r.DecodeInt64(), codecSelferBitsize19780)) for { yyj5++ if yyhl5 { yyb5 = yyj5 > l } else { yyb5 = z.DecCheckBreak() } if yyb5 { break } z.DecReadArrayElem() z.DecStructFieldNotFound(yyj5-1, "") } } func (x *testStrucKeyTypeT0) IsCodecEmpty() bool { return !(x.F != 0 || false) } func (testStrucKeyTypeT1) codecSelferViaCodecgen() {} func (x *testStrucKeyTypeT1) CodecEncodeSelf(e *Encoder) { var h codecSelfer19780 z, r := GenHelper().Encoder(e) _, _, _ = h, z, r if z.EncBasicHandle().CheckCircularRef { z.EncEncode(x) return } if x == nil { r.EncodeNil() } else { yy2arr2 := z.EncBasicHandle().StructToArray _ = yy2arr2 const yyr2 bool = false // struct tag has 'toArray' if yyr2 || yy2arr2 { z.EncWriteArrayStart(1) z.EncWriteArrayElem() r.EncodeInt(int64(x.F)) z.EncWriteArrayEnd() } else { z.EncWriteMapStart(1) if z.EncBasicHandle().Canonical { z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"FFFF\"") } else { r.EncodeString(`FFFF`) } z.EncWriteMapElemValue() r.EncodeInt(int64(x.F)) } else { z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"FFFF\"") } else { r.EncodeString(`FFFF`) } z.EncWriteMapElemValue() r.EncodeInt(int64(x.F)) } z.EncWriteMapEnd() } } } func (x *testStrucKeyTypeT1) CodecDecodeSelf(d *Decoder) { var h codecSelfer19780 z, r := GenHelper().Decoder(d) _, _, _ = h, z, r yyct2 := r.ContainerType() if yyct2 == codecSelferValueTypeNil19780 { *(x) = testStrucKeyTypeT1{} } else if yyct2 == codecSelferValueTypeMap19780 { yyl2 := z.DecReadMapStart() if yyl2 == 0 { } else { x.codecDecodeSelfFromMap(yyl2, d) } z.DecReadMapEnd() } else if yyct2 == codecSelferValueTypeArray19780 { yyl2 := z.DecReadArrayStart() if yyl2 != 0 { x.codecDecodeSelfFromArray(yyl2, d) } z.DecReadArrayEnd() } else { panic(errCodecSelferOnlyMapOrArrayEncodeToStruct19780) } } func (x *testStrucKeyTypeT1) codecDecodeSelfFromMap(l int, d *Decoder) { var h codecSelfer19780 z, r := GenHelper().Decoder(d) _, _, _ = h, z, r var yyhl3 bool = l >= 0 for yyj3 := 0; ; yyj3++ { if yyhl3 { if yyj3 >= l { break } } else { if z.DecCheckBreak() { break } } z.DecReadMapElemKey() yys3 := r.DecodeStringAsBytes() z.DecReadMapElemValue() switch string(yys3) { case "FFFF": x.F = (int)(z.C.IntV(r.DecodeInt64(), codecSelferBitsize19780)) default: z.DecStructFieldNotFound(-1, string(yys3)) } // end switch yys3 } // end for yyj3 } func (x *testStrucKeyTypeT1) codecDecodeSelfFromArray(l int, d *Decoder) { var h codecSelfer19780 z, r := GenHelper().Decoder(d) _, _, _ = h, z, r var yyj5 int var yyb5 bool var yyhl5 bool = l >= 0 yyj5++ if yyhl5 { yyb5 = yyj5 > l } else { yyb5 = z.DecCheckBreak() } if yyb5 { z.DecReadArrayEnd() return } z.DecReadArrayElem() x.F = (int)(z.C.IntV(r.DecodeInt64(), codecSelferBitsize19780)) for { yyj5++ if yyhl5 { yyb5 = yyj5 > l } else { yyb5 = z.DecCheckBreak() } if yyb5 { break } z.DecReadArrayElem() z.DecStructFieldNotFound(yyj5-1, "") } } func (x *testStrucKeyTypeT1) IsCodecEmpty() bool { return !(x.F != 0 || false) } func (testStrucKeyTypeT2) codecSelferViaCodecgen() {} func (x *testStrucKeyTypeT2) CodecEncodeSelf(e *Encoder) { var h codecSelfer19780 z, r := GenHelper().Encoder(e) _, _, _ = h, z, r if z.EncBasicHandle().CheckCircularRef { z.EncEncode(x) return } if x == nil { r.EncodeNil() } else { yy2arr2 := z.EncBasicHandle().StructToArray _ = yy2arr2 const yyr2 bool = false // struct tag has 'toArray' if yyr2 || yy2arr2 { z.EncWriteArrayStart(1) z.EncWriteArrayElem() r.EncodeInt(int64(x.F)) z.EncWriteArrayEnd() } else { z.EncWriteMapStart(1) if z.EncBasicHandle().Canonical { z.EncWriteMapElemKey() r.EncodeInt(z.M.Int(strconv.ParseInt(`-1`, 10, 64))) z.EncWriteMapElemValue() r.EncodeInt(int64(x.F)) } else { z.EncWriteMapElemKey() r.EncodeInt(z.M.Int(strconv.ParseInt(`-1`, 10, 64))) z.EncWriteMapElemValue() r.EncodeInt(int64(x.F)) } z.EncWriteMapEnd() } } } func (x *testStrucKeyTypeT2) CodecDecodeSelf(d *Decoder) { var h codecSelfer19780 z, r := GenHelper().Decoder(d) _, _, _ = h, z, r yyct2 := r.ContainerType() if yyct2 == codecSelferValueTypeNil19780 { *(x) = testStrucKeyTypeT2{} } else if yyct2 == codecSelferValueTypeMap19780 { yyl2 := z.DecReadMapStart() if yyl2 == 0 { } else { x.codecDecodeSelfFromMap(yyl2, d) } z.DecReadMapEnd() } else if yyct2 == codecSelferValueTypeArray19780 { yyl2 := z.DecReadArrayStart() if yyl2 != 0 { x.codecDecodeSelfFromArray(yyl2, d) } z.DecReadArrayEnd() } else { panic(errCodecSelferOnlyMapOrArrayEncodeToStruct19780) } } func (x *testStrucKeyTypeT2) codecDecodeSelfFromMap(l int, d *Decoder) { var h codecSelfer19780 z, r := GenHelper().Decoder(d) _, _, _ = h, z, r var yyhl3 bool = l >= 0 for yyj3 := 0; ; yyj3++ { if yyhl3 { if yyj3 >= l { break } } else { if z.DecCheckBreak() { break } } z.DecReadMapElemKey() yys3 := strconv.AppendInt(z.DecScratchArrayBuffer()[:0], r.DecodeInt64(), 10) z.DecReadMapElemValue() switch string(yys3) { case "-1": x.F = (int)(z.C.IntV(r.DecodeInt64(), codecSelferBitsize19780)) default: z.DecStructFieldNotFound(-1, string(yys3)) } // end switch yys3 } // end for yyj3 } func (x *testStrucKeyTypeT2) codecDecodeSelfFromArray(l int, d *Decoder) { var h codecSelfer19780 z, r := GenHelper().Decoder(d) _, _, _ = h, z, r var yyj5 int var yyb5 bool var yyhl5 bool = l >= 0 yyj5++ if yyhl5 { yyb5 = yyj5 > l } else { yyb5 = z.DecCheckBreak() } if yyb5 { z.DecReadArrayEnd() return } z.DecReadArrayElem() x.F = (int)(z.C.IntV(r.DecodeInt64(), codecSelferBitsize19780)) for { yyj5++ if yyhl5 { yyb5 = yyj5 > l } else { yyb5 = z.DecCheckBreak() } if yyb5 { break } z.DecReadArrayElem() z.DecStructFieldNotFound(yyj5-1, "") } } func (x *testStrucKeyTypeT2) IsCodecEmpty() bool { return !(x.F != 0 || false) } func (testStrucKeyTypeT3) codecSelferViaCodecgen() {} func (x *testStrucKeyTypeT3) CodecEncodeSelf(e *Encoder) { var h codecSelfer19780 z, r := GenHelper().Encoder(e) _, _, _ = h, z, r if z.EncBasicHandle().CheckCircularRef { z.EncEncode(x) return } if x == nil { r.EncodeNil() } else { yy2arr2 := z.EncBasicHandle().StructToArray _ = yy2arr2 const yyr2 bool = false // struct tag has 'toArray' if yyr2 || yy2arr2 { z.EncWriteArrayStart(1) z.EncWriteArrayElem() r.EncodeInt(int64(x.F)) z.EncWriteArrayEnd() } else { z.EncWriteMapStart(1) if z.EncBasicHandle().Canonical { z.EncWriteMapElemKey() r.EncodeUint(z.M.Uint(strconv.ParseUint(`1`, 10, 64))) z.EncWriteMapElemValue() r.EncodeInt(int64(x.F)) } else { z.EncWriteMapElemKey() r.EncodeUint(z.M.Uint(strconv.ParseUint(`1`, 10, 64))) z.EncWriteMapElemValue() r.EncodeInt(int64(x.F)) } z.EncWriteMapEnd() } } } func (x *testStrucKeyTypeT3) CodecDecodeSelf(d *Decoder) { var h codecSelfer19780 z, r := GenHelper().Decoder(d) _, _, _ = h, z, r yyct2 := r.ContainerType() if yyct2 == codecSelferValueTypeNil19780 { *(x) = testStrucKeyTypeT3{} } else if yyct2 == codecSelferValueTypeMap19780 { yyl2 := z.DecReadMapStart() if yyl2 == 0 { } else { x.codecDecodeSelfFromMap(yyl2, d) } z.DecReadMapEnd() } else if yyct2 == codecSelferValueTypeArray19780 { yyl2 := z.DecReadArrayStart() if yyl2 != 0 { x.codecDecodeSelfFromArray(yyl2, d) } z.DecReadArrayEnd() } else { panic(errCodecSelferOnlyMapOrArrayEncodeToStruct19780) } } func (x *testStrucKeyTypeT3) codecDecodeSelfFromMap(l int, d *Decoder) { var h codecSelfer19780 z, r := GenHelper().Decoder(d) _, _, _ = h, z, r var yyhl3 bool = l >= 0 for yyj3 := 0; ; yyj3++ { if yyhl3 { if yyj3 >= l { break } } else { if z.DecCheckBreak() { break } } z.DecReadMapElemKey() yys3 := strconv.AppendUint(z.DecScratchArrayBuffer()[:0], r.DecodeUint64(), 10) z.DecReadMapElemValue() switch string(yys3) { case "1": x.F = (int)(z.C.IntV(r.DecodeInt64(), codecSelferBitsize19780)) default: z.DecStructFieldNotFound(-1, string(yys3)) } // end switch yys3 } // end for yyj3 } func (x *testStrucKeyTypeT3) codecDecodeSelfFromArray(l int, d *Decoder) { var h codecSelfer19780 z, r := GenHelper().Decoder(d) _, _, _ = h, z, r var yyj5 int var yyb5 bool var yyhl5 bool = l >= 0 yyj5++ if yyhl5 { yyb5 = yyj5 > l } else { yyb5 = z.DecCheckBreak() } if yyb5 { z.DecReadArrayEnd() return } z.DecReadArrayElem() x.F = (int)(z.C.IntV(r.DecodeInt64(), codecSelferBitsize19780)) for { yyj5++ if yyhl5 { yyb5 = yyj5 > l } else { yyb5 = z.DecCheckBreak() } if yyb5 { break } z.DecReadArrayElem() z.DecStructFieldNotFound(yyj5-1, "") } } func (x *testStrucKeyTypeT3) IsCodecEmpty() bool { return !(x.F != 0 || false) } func (testStrucKeyTypeT4) codecSelferViaCodecgen() {} func (x *testStrucKeyTypeT4) CodecEncodeSelf(e *Encoder) { var h codecSelfer19780 z, r := GenHelper().Encoder(e) _, _, _ = h, z, r if z.EncBasicHandle().CheckCircularRef { z.EncEncode(x) return } if x == nil { r.EncodeNil() } else { yy2arr2 := z.EncBasicHandle().StructToArray _ = yy2arr2 const yyr2 bool = false // struct tag has 'toArray' if yyr2 || yy2arr2 { z.EncWriteArrayStart(1) z.EncWriteArrayElem() r.EncodeInt(int64(x.F)) z.EncWriteArrayEnd() } else { z.EncWriteMapStart(1) if z.EncBasicHandle().Canonical { z.EncWriteMapElemKey() r.EncodeFloat64(z.M.Float(strconv.ParseFloat(`2.5`, 64))) z.EncWriteMapElemValue() r.EncodeInt(int64(x.F)) } else { z.EncWriteMapElemKey() r.EncodeFloat64(z.M.Float(strconv.ParseFloat(`2.5`, 64))) z.EncWriteMapElemValue() r.EncodeInt(int64(x.F)) } z.EncWriteMapEnd() } } } func (x *testStrucKeyTypeT4) CodecDecodeSelf(d *Decoder) { var h codecSelfer19780 z, r := GenHelper().Decoder(d) _, _, _ = h, z, r yyct2 := r.ContainerType() if yyct2 == codecSelferValueTypeNil19780 { *(x) = testStrucKeyTypeT4{} } else if yyct2 == codecSelferValueTypeMap19780 { yyl2 := z.DecReadMapStart() if yyl2 == 0 { } else { x.codecDecodeSelfFromMap(yyl2, d) } z.DecReadMapEnd() } else if yyct2 == codecSelferValueTypeArray19780 { yyl2 := z.DecReadArrayStart() if yyl2 != 0 { x.codecDecodeSelfFromArray(yyl2, d) } z.DecReadArrayEnd() } else { panic(errCodecSelferOnlyMapOrArrayEncodeToStruct19780) } } func (x *testStrucKeyTypeT4) codecDecodeSelfFromMap(l int, d *Decoder) { var h codecSelfer19780 z, r := GenHelper().Decoder(d) _, _, _ = h, z, r var yyhl3 bool = l >= 0 for yyj3 := 0; ; yyj3++ { if yyhl3 { if yyj3 >= l { break } } else { if z.DecCheckBreak() { break } } z.DecReadMapElemKey() yys3 := strconv.AppendFloat(z.DecScratchArrayBuffer()[:0], r.DecodeFloat64(), 'f', -1, 64) z.DecReadMapElemValue() switch string(yys3) { case "2.5": x.F = (int)(z.C.IntV(r.DecodeInt64(), codecSelferBitsize19780)) default: z.DecStructFieldNotFound(-1, string(yys3)) } // end switch yys3 } // end for yyj3 } func (x *testStrucKeyTypeT4) codecDecodeSelfFromArray(l int, d *Decoder) { var h codecSelfer19780 z, r := GenHelper().Decoder(d) _, _, _ = h, z, r var yyj5 int var yyb5 bool var yyhl5 bool = l >= 0 yyj5++ if yyhl5 { yyb5 = yyj5 > l } else { yyb5 = z.DecCheckBreak() } if yyb5 { z.DecReadArrayEnd() return } z.DecReadArrayElem() x.F = (int)(z.C.IntV(r.DecodeInt64(), codecSelferBitsize19780)) for { yyj5++ if yyhl5 { yyb5 = yyj5 > l } else { yyb5 = z.DecCheckBreak() } if yyb5 { break } z.DecReadArrayElem() z.DecStructFieldNotFound(yyj5-1, "") } } func (x *testStrucKeyTypeT4) IsCodecEmpty() bool { return !(x.F != 0 || false) } func (Bbool) codecSelferViaCodecgen() {} func (x Bbool) CodecEncodeSelf(e *Encoder) { var h codecSelfer19780 z, r := GenHelper().Encoder(e) _, _, _ = h, z, r r.EncodeBool(bool(x)) } func (x *Bbool) CodecDecodeSelf(d *Decoder) { var h codecSelfer19780 z, r := GenHelper().Decoder(d) _, _, _ = h, z, r *x = (Bbool)(r.DecodeBool()) } func (Aarray) codecSelferViaCodecgen() {} func (x *Aarray) CodecEncodeSelf(e *Encoder) { var h codecSelfer19780 z, r := GenHelper().Encoder(e) _, _, _ = h, z, r if x == nil { r.EncodeNil() } else { z.F.EncSliceStringV(([]string)(x[:]), e) } } func (x *Aarray) CodecDecodeSelf(d *Decoder) { var h codecSelfer19780 z, r := GenHelper().Decoder(d) _, _, _ = h, z, r z.F.DecSliceStringN(([]string)(x[:]), d) } func (Sstring) codecSelferViaCodecgen() {} func (x Sstring) CodecEncodeSelf(e *Encoder) { var h codecSelfer19780 z, r := GenHelper().Encoder(e) _, _, _ = h, z, r r.EncodeString(string(x)) } func (x *Sstring) CodecDecodeSelf(d *Decoder) { var h codecSelfer19780 z, r := GenHelper().Decoder(d) _, _, _ = h, z, r *x = (Sstring)(z.DecStringZC(r.DecodeStringAsBytes())) } func (Sstructsmall) codecSelferViaCodecgen() {} func (x *Sstructsmall) CodecEncodeSelf(e *Encoder) { var h codecSelfer19780 z, r := GenHelper().Encoder(e) _, _, _ = h, z, r if z.EncBasicHandle().CheckCircularRef { z.EncEncode(x) return } if x == nil { r.EncodeNil() } else { yy2arr2 := z.EncBasicHandle().StructToArray _ = yy2arr2 const yyr2 bool = false // struct tag has 'toArray' if yyr2 || yy2arr2 { z.EncWriteArrayStart(1) z.EncWriteArrayElem() r.EncodeInt(int64(x.A)) z.EncWriteArrayEnd() } else { z.EncWriteMapStart(1) if z.EncBasicHandle().Canonical { z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"A\"") } else { r.EncodeString(`A`) } z.EncWriteMapElemValue() r.EncodeInt(int64(x.A)) } else { z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"A\"") } else { r.EncodeString(`A`) } z.EncWriteMapElemValue() r.EncodeInt(int64(x.A)) } z.EncWriteMapEnd() } } } func (x *Sstructsmall) CodecDecodeSelf(d *Decoder) { var h codecSelfer19780 z, r := GenHelper().Decoder(d) _, _, _ = h, z, r yyct2 := r.ContainerType() if yyct2 == codecSelferValueTypeNil19780 { *(x) = Sstructsmall{} } else if yyct2 == codecSelferValueTypeMap19780 { yyl2 := z.DecReadMapStart() if yyl2 == 0 { } else { x.codecDecodeSelfFromMap(yyl2, d) } z.DecReadMapEnd() } else if yyct2 == codecSelferValueTypeArray19780 { yyl2 := z.DecReadArrayStart() if yyl2 != 0 { x.codecDecodeSelfFromArray(yyl2, d) } z.DecReadArrayEnd() } else { panic(errCodecSelferOnlyMapOrArrayEncodeToStruct19780) } } func (x *Sstructsmall) codecDecodeSelfFromMap(l int, d *Decoder) { var h codecSelfer19780 z, r := GenHelper().Decoder(d) _, _, _ = h, z, r var yyhl3 bool = l >= 0 for yyj3 := 0; ; yyj3++ { if yyhl3 { if yyj3 >= l { break } } else { if z.DecCheckBreak() { break } } z.DecReadMapElemKey() yys3 := r.DecodeStringAsBytes() z.DecReadMapElemValue() switch string(yys3) { case "A": x.A = (int)(z.C.IntV(r.DecodeInt64(), codecSelferBitsize19780)) default: z.DecStructFieldNotFound(-1, string(yys3)) } // end switch yys3 } // end for yyj3 } func (x *Sstructsmall) codecDecodeSelfFromArray(l int, d *Decoder) { var h codecSelfer19780 z, r := GenHelper().Decoder(d) _, _, _ = h, z, r var yyj5 int var yyb5 bool var yyhl5 bool = l >= 0 yyj5++ if yyhl5 { yyb5 = yyj5 > l } else { yyb5 = z.DecCheckBreak() } if yyb5 { z.DecReadArrayEnd() return } z.DecReadArrayElem() x.A = (int)(z.C.IntV(r.DecodeInt64(), codecSelferBitsize19780)) for { yyj5++ if yyhl5 { yyb5 = yyj5 > l } else { yyb5 = z.DecCheckBreak() } if yyb5 { break } z.DecReadArrayElem() z.DecStructFieldNotFound(yyj5-1, "") } } func (x *Sstructsmall) IsCodecEmpty() bool { return !(x.A != 0 || false) } func (Sstructbig) codecSelferViaCodecgen() {} func (x *Sstructbig) CodecEncodeSelf(e *Encoder) { var h codecSelfer19780 z, r := GenHelper().Encoder(e) _, _, _ = h, z, r if z.EncBasicHandle().CheckCircularRef { z.EncEncode(x) return } if x == nil { r.EncodeNil() } else { yy2arr2 := z.EncBasicHandle().StructToArray _ = yy2arr2 const yyr2 bool = false // struct tag has 'toArray' var yyn5 bool = x.Ssmallptr == nil var yyn7 bool = x.Sptr == nil if yyr2 || yy2arr2 { z.EncWriteArrayStart(5) z.EncWriteArrayElem() r.EncodeInt(int64(x.A)) z.EncWriteArrayElem() r.EncodeBool(bool(x.B)) if yyn5 { z.EncWriteArrayElem() r.EncodeNil() } else { z.EncWriteArrayElem() if yyxt10 := z.Extension(x.Ssmallptr); yyxt10 != nil { z.EncExtension(x.Ssmallptr, yyxt10) } else { x.Ssmallptr.CodecEncodeSelf(e) } } z.EncWriteArrayElem() yy11 := &x.Ssmall if yyxt12 := z.Extension(yy11); yyxt12 != nil { z.EncExtension(yy11, yyxt12) } else { yy11.CodecEncodeSelf(e) } if yyn7 { z.EncWriteArrayElem() r.EncodeNil() } else { z.EncWriteArrayElem() if yyxt13 := z.Extension(x.Sptr); yyxt13 != nil { z.EncExtension(x.Sptr, yyxt13) } else { x.Sptr.CodecEncodeSelf(e) } } z.EncWriteArrayEnd() } else { z.EncWriteMapStart(5) if z.EncBasicHandle().Canonical { z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"A\"") } else { r.EncodeString(`A`) } z.EncWriteMapElemValue() r.EncodeInt(int64(x.A)) z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"B\"") } else { r.EncodeString(`B`) } z.EncWriteMapElemValue() r.EncodeBool(bool(x.B)) z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"Sptr\"") } else { r.EncodeString(`Sptr`) } z.EncWriteMapElemValue() if yyn7 { r.EncodeNil() } else { if yyxt16 := z.Extension(x.Sptr); yyxt16 != nil { z.EncExtension(x.Sptr, yyxt16) } else { x.Sptr.CodecEncodeSelf(e) } } z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"Ssmall\"") } else { r.EncodeString(`Ssmall`) } z.EncWriteMapElemValue() yy17 := &x.Ssmall if yyxt18 := z.Extension(yy17); yyxt18 != nil { z.EncExtension(yy17, yyxt18) } else { yy17.CodecEncodeSelf(e) } z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"Ssmallptr\"") } else { r.EncodeString(`Ssmallptr`) } z.EncWriteMapElemValue() if yyn5 { r.EncodeNil() } else { if yyxt19 := z.Extension(x.Ssmallptr); yyxt19 != nil { z.EncExtension(x.Ssmallptr, yyxt19) } else { x.Ssmallptr.CodecEncodeSelf(e) } } } else { z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"A\"") } else { r.EncodeString(`A`) } z.EncWriteMapElemValue() r.EncodeInt(int64(x.A)) z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"B\"") } else { r.EncodeString(`B`) } z.EncWriteMapElemValue() r.EncodeBool(bool(x.B)) z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"Ssmallptr\"") } else { r.EncodeString(`Ssmallptr`) } z.EncWriteMapElemValue() if yyn5 { r.EncodeNil() } else { if yyxt22 := z.Extension(x.Ssmallptr); yyxt22 != nil { z.EncExtension(x.Ssmallptr, yyxt22) } else { x.Ssmallptr.CodecEncodeSelf(e) } } z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"Ssmall\"") } else { r.EncodeString(`Ssmall`) } z.EncWriteMapElemValue() yy23 := &x.Ssmall if yyxt24 := z.Extension(yy23); yyxt24 != nil { z.EncExtension(yy23, yyxt24) } else { yy23.CodecEncodeSelf(e) } z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"Sptr\"") } else { r.EncodeString(`Sptr`) } z.EncWriteMapElemValue() if yyn7 { r.EncodeNil() } else { if yyxt25 := z.Extension(x.Sptr); yyxt25 != nil { z.EncExtension(x.Sptr, yyxt25) } else { x.Sptr.CodecEncodeSelf(e) } } } z.EncWriteMapEnd() } } } func (x *Sstructbig) CodecDecodeSelf(d *Decoder) { var h codecSelfer19780 z, r := GenHelper().Decoder(d) _, _, _ = h, z, r yyct2 := r.ContainerType() if yyct2 == codecSelferValueTypeNil19780 { *(x) = Sstructbig{} } else if yyct2 == codecSelferValueTypeMap19780 { yyl2 := z.DecReadMapStart() if yyl2 == 0 { } else { x.codecDecodeSelfFromMap(yyl2, d) } z.DecReadMapEnd() } else if yyct2 == codecSelferValueTypeArray19780 { yyl2 := z.DecReadArrayStart() if yyl2 != 0 { x.codecDecodeSelfFromArray(yyl2, d) } z.DecReadArrayEnd() } else { panic(errCodecSelferOnlyMapOrArrayEncodeToStruct19780) } } func (x *Sstructbig) codecDecodeSelfFromMap(l int, d *Decoder) { var h codecSelfer19780 z, r := GenHelper().Decoder(d) _, _, _ = h, z, r var yyhl3 bool = l >= 0 for yyj3 := 0; ; yyj3++ { if yyhl3 { if yyj3 >= l { break } } else { if z.DecCheckBreak() { break } } z.DecReadMapElemKey() yys3 := r.DecodeStringAsBytes() z.DecReadMapElemValue() switch string(yys3) { case "A": x.A = (int)(z.C.IntV(r.DecodeInt64(), codecSelferBitsize19780)) case "B": x.B = (bool)(r.DecodeBool()) case "Ssmallptr": if r.TryNil() { if x.Ssmallptr != nil { // remove the if-true x.Ssmallptr = nil } } else { if x.Ssmallptr == nil { x.Ssmallptr = new(Sstructsmall) } if yyxt7 := z.Extension(x.Ssmallptr); yyxt7 != nil { z.DecExtension(x.Ssmallptr, yyxt7) } else { x.Ssmallptr.CodecDecodeSelf(d) } } case "Ssmall": if yyxt9 := z.Extension(x.Ssmall); yyxt9 != nil { z.DecExtension(&x.Ssmall, yyxt9) } else { x.Ssmall.CodecDecodeSelf(d) } case "Sptr": if r.TryNil() { if x.Sptr != nil { // remove the if-true x.Sptr = nil } } else { if x.Sptr == nil { x.Sptr = new(Sstructbig) } if yyxt11 := z.Extension(x.Sptr); yyxt11 != nil { z.DecExtension(x.Sptr, yyxt11) } else { x.Sptr.CodecDecodeSelf(d) } } default: z.DecStructFieldNotFound(-1, string(yys3)) } // end switch yys3 } // end for yyj3 } func (x *Sstructbig) codecDecodeSelfFromArray(l int, d *Decoder) { var h codecSelfer19780 z, r := GenHelper().Decoder(d) _, _, _ = h, z, r var yyj12 int var yyb12 bool var yyhl12 bool = l >= 0 yyj12++ if yyhl12 { yyb12 = yyj12 > l } else { yyb12 = z.DecCheckBreak() } if yyb12 { z.DecReadArrayEnd() return } z.DecReadArrayElem() x.A = (int)(z.C.IntV(r.DecodeInt64(), codecSelferBitsize19780)) yyj12++ if yyhl12 { yyb12 = yyj12 > l } else { yyb12 = z.DecCheckBreak() } if yyb12 { z.DecReadArrayEnd() return } z.DecReadArrayElem() x.B = (bool)(r.DecodeBool()) yyj12++ if yyhl12 { yyb12 = yyj12 > l } else { yyb12 = z.DecCheckBreak() } if yyb12 { z.DecReadArrayEnd() return } z.DecReadArrayElem() if r.TryNil() { if x.Ssmallptr != nil { // remove the if-true x.Ssmallptr = nil } } else { if x.Ssmallptr == nil { x.Ssmallptr = new(Sstructsmall) } if yyxt16 := z.Extension(x.Ssmallptr); yyxt16 != nil { z.DecExtension(x.Ssmallptr, yyxt16) } else { x.Ssmallptr.CodecDecodeSelf(d) } } yyj12++ if yyhl12 { yyb12 = yyj12 > l } else { yyb12 = z.DecCheckBreak() } if yyb12 { z.DecReadArrayEnd() return } z.DecReadArrayElem() if yyxt18 := z.Extension(x.Ssmall); yyxt18 != nil { z.DecExtension(&x.Ssmall, yyxt18) } else { x.Ssmall.CodecDecodeSelf(d) } yyj12++ if yyhl12 { yyb12 = yyj12 > l } else { yyb12 = z.DecCheckBreak() } if yyb12 { z.DecReadArrayEnd() return } z.DecReadArrayElem() if r.TryNil() { if x.Sptr != nil { // remove the if-true x.Sptr = nil } } else { if x.Sptr == nil { x.Sptr = new(Sstructbig) } if yyxt20 := z.Extension(x.Sptr); yyxt20 != nil { z.DecExtension(x.Sptr, yyxt20) } else { x.Sptr.CodecDecodeSelf(d) } } for { yyj12++ if yyhl12 { yyb12 = yyj12 > l } else { yyb12 = z.DecCheckBreak() } if yyb12 { break } z.DecReadArrayElem() z.DecStructFieldNotFound(yyj12-1, "") } } func (x *Sstructbig) IsCodecEmpty() bool { return !(x.A != 0 || bool(x.B) || !(x.Ssmall.IsCodecEmpty()) || false) } func (SstructbigToArray) codecSelferViaCodecgen() {} func (x *SstructbigToArray) CodecEncodeSelf(e *Encoder) { var h codecSelfer19780 z, r := GenHelper().Encoder(e) _, _, _ = h, z, r if z.EncBasicHandle().CheckCircularRef { z.EncEncode(x) return } if x == nil { r.EncodeNil() } else { yy2arr2 := z.EncBasicHandle().StructToArray _ = yy2arr2 const yyr2 bool = true // struct tag has 'toArray' var yyn5 bool = x.Ssmallptr == nil var yyn7 bool = x.Sptr == nil if yyr2 || yy2arr2 { z.EncWriteArrayStart(5) z.EncWriteArrayElem() r.EncodeInt(int64(x.A)) z.EncWriteArrayElem() r.EncodeBool(bool(x.B)) if yyn5 { z.EncWriteArrayElem() r.EncodeNil() } else { z.EncWriteArrayElem() if yyxt10 := z.Extension(x.Ssmallptr); yyxt10 != nil { z.EncExtension(x.Ssmallptr, yyxt10) } else { x.Ssmallptr.CodecEncodeSelf(e) } } z.EncWriteArrayElem() yy11 := &x.Ssmall if yyxt12 := z.Extension(yy11); yyxt12 != nil { z.EncExtension(yy11, yyxt12) } else { yy11.CodecEncodeSelf(e) } if yyn7 { z.EncWriteArrayElem() r.EncodeNil() } else { z.EncWriteArrayElem() if yyxt13 := z.Extension(x.Sptr); yyxt13 != nil { z.EncExtension(x.Sptr, yyxt13) } else { x.Sptr.CodecEncodeSelf(e) } } z.EncWriteArrayEnd() } else { z.EncWriteMapStart(5) if z.EncBasicHandle().Canonical { z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"A\"") } else { r.EncodeString(`A`) } z.EncWriteMapElemValue() r.EncodeInt(int64(x.A)) z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"B\"") } else { r.EncodeString(`B`) } z.EncWriteMapElemValue() r.EncodeBool(bool(x.B)) z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"Sptr\"") } else { r.EncodeString(`Sptr`) } z.EncWriteMapElemValue() if yyn7 { r.EncodeNil() } else { if yyxt16 := z.Extension(x.Sptr); yyxt16 != nil { z.EncExtension(x.Sptr, yyxt16) } else { x.Sptr.CodecEncodeSelf(e) } } z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"Ssmall\"") } else { r.EncodeString(`Ssmall`) } z.EncWriteMapElemValue() yy17 := &x.Ssmall if yyxt18 := z.Extension(yy17); yyxt18 != nil { z.EncExtension(yy17, yyxt18) } else { yy17.CodecEncodeSelf(e) } z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"Ssmallptr\"") } else { r.EncodeString(`Ssmallptr`) } z.EncWriteMapElemValue() if yyn5 { r.EncodeNil() } else { if yyxt19 := z.Extension(x.Ssmallptr); yyxt19 != nil { z.EncExtension(x.Ssmallptr, yyxt19) } else { x.Ssmallptr.CodecEncodeSelf(e) } } } else { z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"A\"") } else { r.EncodeString(`A`) } z.EncWriteMapElemValue() r.EncodeInt(int64(x.A)) z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"B\"") } else { r.EncodeString(`B`) } z.EncWriteMapElemValue() r.EncodeBool(bool(x.B)) z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"Ssmallptr\"") } else { r.EncodeString(`Ssmallptr`) } z.EncWriteMapElemValue() if yyn5 { r.EncodeNil() } else { if yyxt22 := z.Extension(x.Ssmallptr); yyxt22 != nil { z.EncExtension(x.Ssmallptr, yyxt22) } else { x.Ssmallptr.CodecEncodeSelf(e) } } z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"Ssmall\"") } else { r.EncodeString(`Ssmall`) } z.EncWriteMapElemValue() yy23 := &x.Ssmall if yyxt24 := z.Extension(yy23); yyxt24 != nil { z.EncExtension(yy23, yyxt24) } else { yy23.CodecEncodeSelf(e) } z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"Sptr\"") } else { r.EncodeString(`Sptr`) } z.EncWriteMapElemValue() if yyn7 { r.EncodeNil() } else { if yyxt25 := z.Extension(x.Sptr); yyxt25 != nil { z.EncExtension(x.Sptr, yyxt25) } else { x.Sptr.CodecEncodeSelf(e) } } } z.EncWriteMapEnd() } } } func (x *SstructbigToArray) CodecDecodeSelf(d *Decoder) { var h codecSelfer19780 z, r := GenHelper().Decoder(d) _, _, _ = h, z, r yyct2 := r.ContainerType() if yyct2 == codecSelferValueTypeNil19780 { *(x) = SstructbigToArray{} } else if yyct2 == codecSelferValueTypeMap19780 { yyl2 := z.DecReadMapStart() if yyl2 == 0 { } else { x.codecDecodeSelfFromMap(yyl2, d) } z.DecReadMapEnd() } else if yyct2 == codecSelferValueTypeArray19780 { yyl2 := z.DecReadArrayStart() if yyl2 != 0 { x.codecDecodeSelfFromArray(yyl2, d) } z.DecReadArrayEnd() } else { panic(errCodecSelferOnlyMapOrArrayEncodeToStruct19780) } } func (x *SstructbigToArray) codecDecodeSelfFromMap(l int, d *Decoder) { var h codecSelfer19780 z, r := GenHelper().Decoder(d) _, _, _ = h, z, r var yyhl3 bool = l >= 0 for yyj3 := 0; ; yyj3++ { if yyhl3 { if yyj3 >= l { break } } else { if z.DecCheckBreak() { break } } z.DecReadMapElemKey() yys3 := r.DecodeStringAsBytes() z.DecReadMapElemValue() switch string(yys3) { case "A": x.A = (int)(z.C.IntV(r.DecodeInt64(), codecSelferBitsize19780)) case "B": x.B = (bool)(r.DecodeBool()) case "Ssmallptr": if r.TryNil() { if x.Ssmallptr != nil { // remove the if-true x.Ssmallptr = nil } } else { if x.Ssmallptr == nil { x.Ssmallptr = new(Sstructsmall) } if yyxt7 := z.Extension(x.Ssmallptr); yyxt7 != nil { z.DecExtension(x.Ssmallptr, yyxt7) } else { x.Ssmallptr.CodecDecodeSelf(d) } } case "Ssmall": if yyxt9 := z.Extension(x.Ssmall); yyxt9 != nil { z.DecExtension(&x.Ssmall, yyxt9) } else { x.Ssmall.CodecDecodeSelf(d) } case "Sptr": if r.TryNil() { if x.Sptr != nil { // remove the if-true x.Sptr = nil } } else { if x.Sptr == nil { x.Sptr = new(Sstructbig) } if yyxt11 := z.Extension(x.Sptr); yyxt11 != nil { z.DecExtension(x.Sptr, yyxt11) } else { x.Sptr.CodecDecodeSelf(d) } } default: z.DecStructFieldNotFound(-1, string(yys3)) } // end switch yys3 } // end for yyj3 } func (x *SstructbigToArray) codecDecodeSelfFromArray(l int, d *Decoder) { var h codecSelfer19780 z, r := GenHelper().Decoder(d) _, _, _ = h, z, r var yyj12 int var yyb12 bool var yyhl12 bool = l >= 0 yyj12++ if yyhl12 { yyb12 = yyj12 > l } else { yyb12 = z.DecCheckBreak() } if yyb12 { z.DecReadArrayEnd() return } z.DecReadArrayElem() x.A = (int)(z.C.IntV(r.DecodeInt64(), codecSelferBitsize19780)) yyj12++ if yyhl12 { yyb12 = yyj12 > l } else { yyb12 = z.DecCheckBreak() } if yyb12 { z.DecReadArrayEnd() return } z.DecReadArrayElem() x.B = (bool)(r.DecodeBool()) yyj12++ if yyhl12 { yyb12 = yyj12 > l } else { yyb12 = z.DecCheckBreak() } if yyb12 { z.DecReadArrayEnd() return } z.DecReadArrayElem() if r.TryNil() { if x.Ssmallptr != nil { // remove the if-true x.Ssmallptr = nil } } else { if x.Ssmallptr == nil { x.Ssmallptr = new(Sstructsmall) } if yyxt16 := z.Extension(x.Ssmallptr); yyxt16 != nil { z.DecExtension(x.Ssmallptr, yyxt16) } else { x.Ssmallptr.CodecDecodeSelf(d) } } yyj12++ if yyhl12 { yyb12 = yyj12 > l } else { yyb12 = z.DecCheckBreak() } if yyb12 { z.DecReadArrayEnd() return } z.DecReadArrayElem() if yyxt18 := z.Extension(x.Ssmall); yyxt18 != nil { z.DecExtension(&x.Ssmall, yyxt18) } else { x.Ssmall.CodecDecodeSelf(d) } yyj12++ if yyhl12 { yyb12 = yyj12 > l } else { yyb12 = z.DecCheckBreak() } if yyb12 { z.DecReadArrayEnd() return } z.DecReadArrayElem() if r.TryNil() { if x.Sptr != nil { // remove the if-true x.Sptr = nil } } else { if x.Sptr == nil { x.Sptr = new(Sstructbig) } if yyxt20 := z.Extension(x.Sptr); yyxt20 != nil { z.DecExtension(x.Sptr, yyxt20) } else { x.Sptr.CodecDecodeSelf(d) } } for { yyj12++ if yyhl12 { yyb12 = yyj12 > l } else { yyb12 = z.DecCheckBreak() } if yyb12 { break } z.DecReadArrayElem() z.DecStructFieldNotFound(yyj12-1, "") } } func (x *SstructbigToArray) IsCodecEmpty() bool { return !(x.A != 0 || bool(x.B) || !(x.Ssmall.IsCodecEmpty()) || false) } func (tLowerFirstLetter) codecSelferViaCodecgen() {} func (x *tLowerFirstLetter) CodecEncodeSelf(e *Encoder) { var h codecSelfer19780 z, r := GenHelper().Encoder(e) _, _, _ = h, z, r if z.EncBasicHandle().CheckCircularRef { z.EncEncode(x) return } if x == nil { r.EncodeNil() } else { yy2arr2 := z.EncBasicHandle().StructToArray _ = yy2arr2 const yyr2 bool = false // struct tag has 'toArray' if yyr2 || yy2arr2 { z.EncWriteArrayStart(2) z.EncWriteArrayElem() r.EncodeInt(int64(x.I)) z.EncWriteArrayElem() r.EncodeString(string(x.S)) z.EncWriteArrayEnd() } else { z.EncWriteMapStart(2) if z.EncBasicHandle().Canonical { z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"I\"") } else { r.EncodeString(`I`) } z.EncWriteMapElemValue() r.EncodeInt(int64(x.I)) z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"S\"") } else { r.EncodeString(`S`) } z.EncWriteMapElemValue() r.EncodeString(string(x.S)) } else { z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"I\"") } else { r.EncodeString(`I`) } z.EncWriteMapElemValue() r.EncodeInt(int64(x.I)) z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"S\"") } else { r.EncodeString(`S`) } z.EncWriteMapElemValue() r.EncodeString(string(x.S)) } z.EncWriteMapEnd() } } } func (x *tLowerFirstLetter) CodecDecodeSelf(d *Decoder) { var h codecSelfer19780 z, r := GenHelper().Decoder(d) _, _, _ = h, z, r yyct2 := r.ContainerType() if yyct2 == codecSelferValueTypeNil19780 { *(x) = tLowerFirstLetter{} } else if yyct2 == codecSelferValueTypeMap19780 { yyl2 := z.DecReadMapStart() if yyl2 == 0 { } else { x.codecDecodeSelfFromMap(yyl2, d) } z.DecReadMapEnd() } else if yyct2 == codecSelferValueTypeArray19780 { yyl2 := z.DecReadArrayStart() if yyl2 != 0 { x.codecDecodeSelfFromArray(yyl2, d) } z.DecReadArrayEnd() } else { panic(errCodecSelferOnlyMapOrArrayEncodeToStruct19780) } } func (x *tLowerFirstLetter) codecDecodeSelfFromMap(l int, d *Decoder) { var h codecSelfer19780 z, r := GenHelper().Decoder(d) _, _, _ = h, z, r var yyhl3 bool = l >= 0 for yyj3 := 0; ; yyj3++ { if yyhl3 { if yyj3 >= l { break } } else { if z.DecCheckBreak() { break } } z.DecReadMapElemKey() yys3 := r.DecodeStringAsBytes() z.DecReadMapElemValue() switch string(yys3) { case "I": x.I = (int)(z.C.IntV(r.DecodeInt64(), codecSelferBitsize19780)) case "S": x.S = (string)(z.DecStringZC(r.DecodeStringAsBytes())) default: z.DecStructFieldNotFound(-1, string(yys3)) } // end switch yys3 } // end for yyj3 } func (x *tLowerFirstLetter) codecDecodeSelfFromArray(l int, d *Decoder) { var h codecSelfer19780 z, r := GenHelper().Decoder(d) _, _, _ = h, z, r var yyj6 int var yyb6 bool var yyhl6 bool = l >= 0 yyj6++ if yyhl6 { yyb6 = yyj6 > l } else { yyb6 = z.DecCheckBreak() } if yyb6 { z.DecReadArrayEnd() return } z.DecReadArrayElem() x.I = (int)(z.C.IntV(r.DecodeInt64(), codecSelferBitsize19780)) yyj6++ if yyhl6 { yyb6 = yyj6 > l } else { yyb6 = z.DecCheckBreak() } if yyb6 { z.DecReadArrayEnd() return } z.DecReadArrayElem() x.S = (string)(z.DecStringZC(r.DecodeStringAsBytes())) for { yyj6++ if yyhl6 { yyb6 = yyj6 > l } else { yyb6 = z.DecCheckBreak() } if yyb6 { break } z.DecReadArrayElem() z.DecStructFieldNotFound(yyj6-1, "") } } func (x *tLowerFirstLetter) IsCodecEmpty() bool { return !(x.I != 0 || x.S != "" || false) } func (wrapInt64) codecSelferViaCodecgen() {} func (x wrapInt64) CodecEncodeSelf(e *Encoder) { var h codecSelfer19780 z, r := GenHelper().Encoder(e) _, _, _ = h, z, r r.EncodeInt(int64(x)) } func (x *wrapInt64) CodecDecodeSelf(d *Decoder) { var h codecSelfer19780 z, r := GenHelper().Decoder(d) _, _, _ = h, z, r *x = (wrapInt64)(r.DecodeInt64()) } func (wrapUint8) codecSelferViaCodecgen() {} func (x wrapUint8) CodecEncodeSelf(e *Encoder) { var h codecSelfer19780 z, r := GenHelper().Encoder(e) _, _, _ = h, z, r r.EncodeUint(uint64(x)) } func (x *wrapUint8) CodecDecodeSelf(d *Decoder) { var h codecSelfer19780 z, r := GenHelper().Decoder(d) _, _, _ = h, z, r *x = (wrapUint8)(z.C.UintV(r.DecodeUint64(), 8)) } func (wrapBytes) codecSelferViaCodecgen() {} func (x wrapBytes) CodecEncodeSelf(e *Encoder) { var h codecSelfer19780 z, r := GenHelper().Encoder(e) _, _, _ = h, z, r if x == nil { r.EncodeNil() } else { z.F.EncSliceUint8V(([]uint8)(x), e) } // end block: if x slice == nil } func (x *wrapBytes) CodecDecodeSelf(d *Decoder) { var h codecSelfer19780 z, r := GenHelper().Decoder(d) _, _, _ = h, z, r z.F.DecSliceUint8X((*[]uint8)(x), d) } func (testMarshalAsJSON) codecSelferViaCodecgen() {} func (x testMarshalAsJSON) CodecEncodeSelf(e *Encoder) { var h codecSelfer19780 z, r := GenHelper().Encoder(e) _, _, _ = h, z, r if !z.EncBinary() && z.IsJSONHandle() { z.EncJSONMarshal(x) } else { r.EncodeBool(bool(x)) } } func (x *testMarshalAsJSON) CodecDecodeSelf(d *Decoder) { var h codecSelfer19780 z, r := GenHelper().Decoder(d) _, _, _ = h, z, r if !z.DecBinary() && z.IsJSONHandle() { z.DecJSONUnmarshal(x) } else { *x = (testMarshalAsJSON)(r.DecodeBool()) } } func (testMarshalAsBinary) codecSelferViaCodecgen() {} func (x testMarshalAsBinary) CodecEncodeSelf(e *Encoder) { var h codecSelfer19780 z, r := GenHelper().Encoder(e) _, _, _ = h, z, r if z.EncBinary() { z.EncBinaryMarshal(x) } else { if x == nil { r.EncodeNil() } else { z.F.EncSliceUint8V(([]uint8)(x), e) } // end block: if x slice == nil } } func (x *testMarshalAsBinary) CodecDecodeSelf(d *Decoder) { var h codecSelfer19780 z, r := GenHelper().Decoder(d) _, _, _ = h, z, r if z.DecBinary() { z.DecBinaryUnmarshal(x) } else { z.F.DecSliceUint8X((*[]uint8)(x), d) } } func (testMarshalAsText) codecSelferViaCodecgen() {} func (x testMarshalAsText) CodecEncodeSelf(e *Encoder) { var h codecSelfer19780 z, r := GenHelper().Encoder(e) _, _, _ = h, z, r if !z.EncBinary() { z.EncTextMarshal(x) } else { r.EncodeString(string(x)) } } func (x *testMarshalAsText) CodecDecodeSelf(d *Decoder) { var h codecSelfer19780 z, r := GenHelper().Decoder(d) _, _, _ = h, z, r if !z.DecBinary() { z.DecTextUnmarshal(x) } else { *x = (testMarshalAsText)(z.DecStringZC(r.DecodeStringAsBytes())) } } func (testUintToBytes) codecSelferViaCodecgen() {} func (x testUintToBytes) CodecEncodeSelf(e *Encoder) { var h codecSelfer19780 z, r := GenHelper().Encoder(e) _, _, _ = h, z, r r.EncodeUint(uint64(x)) } func (x *testUintToBytes) CodecDecodeSelf(d *Decoder) { var h codecSelfer19780 z, r := GenHelper().Decoder(d) _, _, _ = h, z, r *x = (testUintToBytes)(z.C.UintV(r.DecodeUint64(), 32)) } func (AnonInTestStrucIntf) codecSelferViaCodecgen() {} func (x *AnonInTestStrucIntf) CodecEncodeSelf(e *Encoder) { var h codecSelfer19780 z, r := GenHelper().Encoder(e) _, _, _ = h, z, r if z.EncBasicHandle().CheckCircularRef { z.EncEncode(x) return } if x == nil { r.EncodeNil() } else { yy2arr2 := z.EncBasicHandle().StructToArray _ = yy2arr2 const yyr2 bool = false // struct tag has 'toArray' var yyn7 bool = x.Tptr == nil if yyr2 || yy2arr2 { z.EncWriteArrayStart(5) z.EncWriteArrayElem() if x.Islice == nil { r.EncodeNil() } else { z.F.EncSliceIntfV(x.Islice, e) } // end block: if x.Islice slice == nil z.EncWriteArrayElem() if x.Ms == nil { r.EncodeNil() } else { z.F.EncMapStringIntfV(x.Ms, e) } // end block: if x.Ms map == nil z.EncWriteArrayElem() z.EncFallback(x.Nintf) z.EncWriteArrayElem() if z.EncBasicHandle().TimeBuiltin() { r.EncodeTime(x.T) } else if yyxt11 := z.Extension(x.T); yyxt11 != nil { z.EncExtension(x.T, yyxt11) } else if z.EncBinary() { z.EncBinaryMarshal(x.T) } else if !z.EncBinary() && z.IsJSONHandle() { z.EncJSONMarshal(x.T) } else { z.EncFallback(x.T) } if yyn7 { z.EncWriteArrayElem() r.EncodeNil() } else { z.EncWriteArrayElem() yy12 := *x.Tptr if z.EncBasicHandle().TimeBuiltin() { r.EncodeTime(yy12) } else if yyxt13 := z.Extension(yy12); yyxt13 != nil { z.EncExtension(yy12, yyxt13) } else if z.EncBinary() { z.EncBinaryMarshal(yy12) } else if !z.EncBinary() && z.IsJSONHandle() { z.EncJSONMarshal(yy12) } else { z.EncFallback(yy12) } } z.EncWriteArrayEnd() } else { z.EncWriteMapStart(5) if z.EncBasicHandle().Canonical { z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"Islice\"") } else { r.EncodeString(`Islice`) } z.EncWriteMapElemValue() if x.Islice == nil { r.EncodeNil() } else { z.F.EncSliceIntfV(x.Islice, e) } // end block: if x.Islice slice == nil z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"Ms\"") } else { r.EncodeString(`Ms`) } z.EncWriteMapElemValue() if x.Ms == nil { r.EncodeNil() } else { z.F.EncMapStringIntfV(x.Ms, e) } // end block: if x.Ms map == nil z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"Nintf\"") } else { r.EncodeString(`Nintf`) } z.EncWriteMapElemValue() z.EncFallback(x.Nintf) z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"T\"") } else { r.EncodeString(`T`) } z.EncWriteMapElemValue() if z.EncBasicHandle().TimeBuiltin() { r.EncodeTime(x.T) } else if yyxt17 := z.Extension(x.T); yyxt17 != nil { z.EncExtension(x.T, yyxt17) } else if z.EncBinary() { z.EncBinaryMarshal(x.T) } else if !z.EncBinary() && z.IsJSONHandle() { z.EncJSONMarshal(x.T) } else { z.EncFallback(x.T) } z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"Tptr\"") } else { r.EncodeString(`Tptr`) } z.EncWriteMapElemValue() if yyn7 { r.EncodeNil() } else { yy18 := *x.Tptr if z.EncBasicHandle().TimeBuiltin() { r.EncodeTime(yy18) } else if yyxt19 := z.Extension(yy18); yyxt19 != nil { z.EncExtension(yy18, yyxt19) } else if z.EncBinary() { z.EncBinaryMarshal(yy18) } else if !z.EncBinary() && z.IsJSONHandle() { z.EncJSONMarshal(yy18) } else { z.EncFallback(yy18) } } } else { z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"Islice\"") } else { r.EncodeString(`Islice`) } z.EncWriteMapElemValue() if x.Islice == nil { r.EncodeNil() } else { z.F.EncSliceIntfV(x.Islice, e) } // end block: if x.Islice slice == nil z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"Ms\"") } else { r.EncodeString(`Ms`) } z.EncWriteMapElemValue() if x.Ms == nil { r.EncodeNil() } else { z.F.EncMapStringIntfV(x.Ms, e) } // end block: if x.Ms map == nil z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"Nintf\"") } else { r.EncodeString(`Nintf`) } z.EncWriteMapElemValue() z.EncFallback(x.Nintf) z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"T\"") } else { r.EncodeString(`T`) } z.EncWriteMapElemValue() if z.EncBasicHandle().TimeBuiltin() { r.EncodeTime(x.T) } else if yyxt23 := z.Extension(x.T); yyxt23 != nil { z.EncExtension(x.T, yyxt23) } else if z.EncBinary() { z.EncBinaryMarshal(x.T) } else if !z.EncBinary() && z.IsJSONHandle() { z.EncJSONMarshal(x.T) } else { z.EncFallback(x.T) } z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"Tptr\"") } else { r.EncodeString(`Tptr`) } z.EncWriteMapElemValue() if yyn7 { r.EncodeNil() } else { yy24 := *x.Tptr if z.EncBasicHandle().TimeBuiltin() { r.EncodeTime(yy24) } else if yyxt25 := z.Extension(yy24); yyxt25 != nil { z.EncExtension(yy24, yyxt25) } else if z.EncBinary() { z.EncBinaryMarshal(yy24) } else if !z.EncBinary() && z.IsJSONHandle() { z.EncJSONMarshal(yy24) } else { z.EncFallback(yy24) } } } z.EncWriteMapEnd() } } } func (x *AnonInTestStrucIntf) CodecDecodeSelf(d *Decoder) { var h codecSelfer19780 z, r := GenHelper().Decoder(d) _, _, _ = h, z, r yyct2 := r.ContainerType() if yyct2 == codecSelferValueTypeNil19780 { *(x) = AnonInTestStrucIntf{} } else if yyct2 == codecSelferValueTypeMap19780 { yyl2 := z.DecReadMapStart() if yyl2 == 0 { } else { x.codecDecodeSelfFromMap(yyl2, d) } z.DecReadMapEnd() } else if yyct2 == codecSelferValueTypeArray19780 { yyl2 := z.DecReadArrayStart() if yyl2 != 0 { x.codecDecodeSelfFromArray(yyl2, d) } z.DecReadArrayEnd() } else { panic(errCodecSelferOnlyMapOrArrayEncodeToStruct19780) } } func (x *AnonInTestStrucIntf) codecDecodeSelfFromMap(l int, d *Decoder) { var h codecSelfer19780 z, r := GenHelper().Decoder(d) _, _, _ = h, z, r var yyhl3 bool = l >= 0 for yyj3 := 0; ; yyj3++ { if yyhl3 { if yyj3 >= l { break } } else { if z.DecCheckBreak() { break } } z.DecReadMapElemKey() yys3 := r.DecodeStringAsBytes() z.DecReadMapElemValue() switch string(yys3) { case "Islice": z.F.DecSliceIntfX(&x.Islice, d) case "Ms": z.F.DecMapStringIntfX(&x.Ms, d) case "Nintf": z.DecFallback(&x.Nintf, true) case "T": if z.DecBasicHandle().TimeBuiltin() { x.T = r.DecodeTime() } else if yyxt11 := z.Extension(x.T); yyxt11 != nil { z.DecExtension(&x.T, yyxt11) } else if z.DecBinary() { z.DecBinaryUnmarshal(&x.T) } else if !z.DecBinary() && z.IsJSONHandle() { z.DecJSONUnmarshal(&x.T) } else { z.DecFallback(&x.T, false) } case "Tptr": if r.TryNil() { if x.Tptr != nil { // remove the if-true x.Tptr = nil } } else { if x.Tptr == nil { x.Tptr = new(time.Time) } if z.DecBasicHandle().TimeBuiltin() { *x.Tptr = r.DecodeTime() } else if yyxt13 := z.Extension(x.Tptr); yyxt13 != nil { z.DecExtension(x.Tptr, yyxt13) } else if z.DecBinary() { z.DecBinaryUnmarshal(x.Tptr) } else if !z.DecBinary() && z.IsJSONHandle() { z.DecJSONUnmarshal(x.Tptr) } else { z.DecFallback(x.Tptr, false) } } default: z.DecStructFieldNotFound(-1, string(yys3)) } // end switch yys3 } // end for yyj3 } func (x *AnonInTestStrucIntf) codecDecodeSelfFromArray(l int, d *Decoder) { var h codecSelfer19780 z, r := GenHelper().Decoder(d) _, _, _ = h, z, r var yyj14 int var yyb14 bool var yyhl14 bool = l >= 0 yyj14++ if yyhl14 { yyb14 = yyj14 > l } else { yyb14 = z.DecCheckBreak() } if yyb14 { z.DecReadArrayEnd() return } z.DecReadArrayElem() z.F.DecSliceIntfX(&x.Islice, d) yyj14++ if yyhl14 { yyb14 = yyj14 > l } else { yyb14 = z.DecCheckBreak() } if yyb14 { z.DecReadArrayEnd() return } z.DecReadArrayElem() z.F.DecMapStringIntfX(&x.Ms, d) yyj14++ if yyhl14 { yyb14 = yyj14 > l } else { yyb14 = z.DecCheckBreak() } if yyb14 { z.DecReadArrayEnd() return } z.DecReadArrayElem() z.DecFallback(&x.Nintf, true) yyj14++ if yyhl14 { yyb14 = yyj14 > l } else { yyb14 = z.DecCheckBreak() } if yyb14 { z.DecReadArrayEnd() return } z.DecReadArrayElem() if z.DecBasicHandle().TimeBuiltin() { x.T = r.DecodeTime() } else if yyxt22 := z.Extension(x.T); yyxt22 != nil { z.DecExtension(&x.T, yyxt22) } else if z.DecBinary() { z.DecBinaryUnmarshal(&x.T) } else if !z.DecBinary() && z.IsJSONHandle() { z.DecJSONUnmarshal(&x.T) } else { z.DecFallback(&x.T, false) } yyj14++ if yyhl14 { yyb14 = yyj14 > l } else { yyb14 = z.DecCheckBreak() } if yyb14 { z.DecReadArrayEnd() return } z.DecReadArrayElem() if r.TryNil() { if x.Tptr != nil { // remove the if-true x.Tptr = nil } } else { if x.Tptr == nil { x.Tptr = new(time.Time) } if z.DecBasicHandle().TimeBuiltin() { *x.Tptr = r.DecodeTime() } else if yyxt24 := z.Extension(x.Tptr); yyxt24 != nil { z.DecExtension(x.Tptr, yyxt24) } else if z.DecBinary() { z.DecBinaryUnmarshal(x.Tptr) } else if !z.DecBinary() && z.IsJSONHandle() { z.DecJSONUnmarshal(x.Tptr) } else { z.DecFallback(x.Tptr, false) } } for { yyj14++ if yyhl14 { yyb14 = yyj14 > l } else { yyb14 = z.DecCheckBreak() } if yyb14 { break } z.DecReadArrayElem() z.DecStructFieldNotFound(yyj14-1, "") } } func (x *AnonInTestStrucIntf) IsCodecEmpty() bool { return !(len(x.Islice) != 0 || len(x.Ms) != 0 || x.Nintf != nil || !(x.T.IsZero()) || false) } func (missingFielderT2) codecSelferViaCodecgen() {} func (x *missingFielderT2) CodecEncodeSelf(e *Encoder) { var h codecSelfer19780 z, r := GenHelper().Encoder(e) _, _, _ = h, z, r if z.EncBasicHandle().CheckCircularRef { z.EncEncode(x) return } if x == nil { r.EncodeNil() } else { yy2arr2 := z.EncBasicHandle().StructToArray _ = yy2arr2 const yyr2 bool = false // struct tag has 'toArray' if yyr2 || yy2arr2 { z.EncWriteArrayStart(4) z.EncWriteArrayElem() r.EncodeString(string(x.S)) z.EncWriteArrayElem() r.EncodeBool(bool(x.B)) z.EncWriteArrayElem() r.EncodeFloat64(float64(x.F)) z.EncWriteArrayElem() r.EncodeInt(int64(x.I)) z.EncWriteArrayEnd() } else { z.EncWriteMapStart(4) if z.EncBasicHandle().Canonical { z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"B\"") } else { r.EncodeString(`B`) } z.EncWriteMapElemValue() r.EncodeBool(bool(x.B)) z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"F\"") } else { r.EncodeString(`F`) } z.EncWriteMapElemValue() r.EncodeFloat64(float64(x.F)) z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"I\"") } else { r.EncodeString(`I`) } z.EncWriteMapElemValue() r.EncodeInt(int64(x.I)) z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"S\"") } else { r.EncodeString(`S`) } z.EncWriteMapElemValue() r.EncodeString(string(x.S)) } else { z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"S\"") } else { r.EncodeString(`S`) } z.EncWriteMapElemValue() r.EncodeString(string(x.S)) z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"B\"") } else { r.EncodeString(`B`) } z.EncWriteMapElemValue() r.EncodeBool(bool(x.B)) z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"F\"") } else { r.EncodeString(`F`) } z.EncWriteMapElemValue() r.EncodeFloat64(float64(x.F)) z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"I\"") } else { r.EncodeString(`I`) } z.EncWriteMapElemValue() r.EncodeInt(int64(x.I)) } z.EncWriteMapEnd() } } } func (x *missingFielderT2) CodecDecodeSelf(d *Decoder) { var h codecSelfer19780 z, r := GenHelper().Decoder(d) _, _, _ = h, z, r yyct2 := r.ContainerType() if yyct2 == codecSelferValueTypeNil19780 { *(x) = missingFielderT2{} } else if yyct2 == codecSelferValueTypeMap19780 { yyl2 := z.DecReadMapStart() if yyl2 == 0 { } else { x.codecDecodeSelfFromMap(yyl2, d) } z.DecReadMapEnd() } else if yyct2 == codecSelferValueTypeArray19780 { yyl2 := z.DecReadArrayStart() if yyl2 != 0 { x.codecDecodeSelfFromArray(yyl2, d) } z.DecReadArrayEnd() } else { panic(errCodecSelferOnlyMapOrArrayEncodeToStruct19780) } } func (x *missingFielderT2) codecDecodeSelfFromMap(l int, d *Decoder) { var h codecSelfer19780 z, r := GenHelper().Decoder(d) _, _, _ = h, z, r var yyhl3 bool = l >= 0 for yyj3 := 0; ; yyj3++ { if yyhl3 { if yyj3 >= l { break } } else { if z.DecCheckBreak() { break } } z.DecReadMapElemKey() yys3 := r.DecodeStringAsBytes() z.DecReadMapElemValue() switch string(yys3) { case "S": x.S = (string)(z.DecStringZC(r.DecodeStringAsBytes())) case "B": x.B = (bool)(r.DecodeBool()) case "F": x.F = (float64)(r.DecodeFloat64()) case "I": x.I = (int64)(r.DecodeInt64()) default: z.DecStructFieldNotFound(-1, string(yys3)) } // end switch yys3 } // end for yyj3 } func (x *missingFielderT2) codecDecodeSelfFromArray(l int, d *Decoder) { var h codecSelfer19780 z, r := GenHelper().Decoder(d) _, _, _ = h, z, r var yyj8 int var yyb8 bool var yyhl8 bool = l >= 0 yyj8++ if yyhl8 { yyb8 = yyj8 > l } else { yyb8 = z.DecCheckBreak() } if yyb8 { z.DecReadArrayEnd() return } z.DecReadArrayElem() x.S = (string)(z.DecStringZC(r.DecodeStringAsBytes())) yyj8++ if yyhl8 { yyb8 = yyj8 > l } else { yyb8 = z.DecCheckBreak() } if yyb8 { z.DecReadArrayEnd() return } z.DecReadArrayElem() x.B = (bool)(r.DecodeBool()) yyj8++ if yyhl8 { yyb8 = yyj8 > l } else { yyb8 = z.DecCheckBreak() } if yyb8 { z.DecReadArrayEnd() return } z.DecReadArrayElem() x.F = (float64)(r.DecodeFloat64()) yyj8++ if yyhl8 { yyb8 = yyj8 > l } else { yyb8 = z.DecCheckBreak() } if yyb8 { z.DecReadArrayEnd() return } z.DecReadArrayElem() x.I = (int64)(r.DecodeInt64()) for { yyj8++ if yyhl8 { yyb8 = yyj8 > l } else { yyb8 = z.DecCheckBreak() } if yyb8 { break } z.DecReadArrayElem() z.DecStructFieldNotFound(yyj8-1, "") } } func (x *missingFielderT2) IsCodecEmpty() bool { return !(x.S != "" || bool(x.B) || x.F != 0 || x.I != 0 || false) } func (testSelfExtHelper) codecSelferViaCodecgen() {} func (x *testSelfExtHelper) CodecEncodeSelf(e *Encoder) { var h codecSelfer19780 z, r := GenHelper().Encoder(e) _, _, _ = h, z, r if z.EncBasicHandle().CheckCircularRef { z.EncEncode(x) return } if x == nil { r.EncodeNil() } else { yy2arr2 := z.EncBasicHandle().StructToArray _ = yy2arr2 const yyr2 bool = false // struct tag has 'toArray' if yyr2 || yy2arr2 { z.EncWriteArrayStart(3) z.EncWriteArrayElem() r.EncodeString(string(x.S)) z.EncWriteArrayElem() r.EncodeInt(int64(x.I)) z.EncWriteArrayElem() r.EncodeBool(bool(x.B)) z.EncWriteArrayEnd() } else { z.EncWriteMapStart(3) if z.EncBasicHandle().Canonical { z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"B\"") } else { r.EncodeString(`B`) } z.EncWriteMapElemValue() r.EncodeBool(bool(x.B)) z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"I\"") } else { r.EncodeString(`I`) } z.EncWriteMapElemValue() r.EncodeInt(int64(x.I)) z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"S\"") } else { r.EncodeString(`S`) } z.EncWriteMapElemValue() r.EncodeString(string(x.S)) } else { z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"S\"") } else { r.EncodeString(`S`) } z.EncWriteMapElemValue() r.EncodeString(string(x.S)) z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"I\"") } else { r.EncodeString(`I`) } z.EncWriteMapElemValue() r.EncodeInt(int64(x.I)) z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"B\"") } else { r.EncodeString(`B`) } z.EncWriteMapElemValue() r.EncodeBool(bool(x.B)) } z.EncWriteMapEnd() } } } func (x *testSelfExtHelper) CodecDecodeSelf(d *Decoder) { var h codecSelfer19780 z, r := GenHelper().Decoder(d) _, _, _ = h, z, r yyct2 := r.ContainerType() if yyct2 == codecSelferValueTypeNil19780 { *(x) = testSelfExtHelper{} } else if yyct2 == codecSelferValueTypeMap19780 { yyl2 := z.DecReadMapStart() if yyl2 == 0 { } else { x.codecDecodeSelfFromMap(yyl2, d) } z.DecReadMapEnd() } else if yyct2 == codecSelferValueTypeArray19780 { yyl2 := z.DecReadArrayStart() if yyl2 != 0 { x.codecDecodeSelfFromArray(yyl2, d) } z.DecReadArrayEnd() } else { panic(errCodecSelferOnlyMapOrArrayEncodeToStruct19780) } } func (x *testSelfExtHelper) codecDecodeSelfFromMap(l int, d *Decoder) { var h codecSelfer19780 z, r := GenHelper().Decoder(d) _, _, _ = h, z, r var yyhl3 bool = l >= 0 for yyj3 := 0; ; yyj3++ { if yyhl3 { if yyj3 >= l { break } } else { if z.DecCheckBreak() { break } } z.DecReadMapElemKey() yys3 := r.DecodeStringAsBytes() z.DecReadMapElemValue() switch string(yys3) { case "S": x.S = (string)(z.DecStringZC(r.DecodeStringAsBytes())) case "I": x.I = (int64)(r.DecodeInt64()) case "B": x.B = (bool)(r.DecodeBool()) default: z.DecStructFieldNotFound(-1, string(yys3)) } // end switch yys3 } // end for yyj3 } func (x *testSelfExtHelper) codecDecodeSelfFromArray(l int, d *Decoder) { var h codecSelfer19780 z, r := GenHelper().Decoder(d) _, _, _ = h, z, r var yyj7 int var yyb7 bool var yyhl7 bool = l >= 0 yyj7++ if yyhl7 { yyb7 = yyj7 > l } else { yyb7 = z.DecCheckBreak() } if yyb7 { z.DecReadArrayEnd() return } z.DecReadArrayElem() x.S = (string)(z.DecStringZC(r.DecodeStringAsBytes())) yyj7++ if yyhl7 { yyb7 = yyj7 > l } else { yyb7 = z.DecCheckBreak() } if yyb7 { z.DecReadArrayEnd() return } z.DecReadArrayElem() x.I = (int64)(r.DecodeInt64()) yyj7++ if yyhl7 { yyb7 = yyj7 > l } else { yyb7 = z.DecCheckBreak() } if yyb7 { z.DecReadArrayEnd() return } z.DecReadArrayElem() x.B = (bool)(r.DecodeBool()) for { yyj7++ if yyhl7 { yyb7 = yyj7 > l } else { yyb7 = z.DecCheckBreak() } if yyb7 { break } z.DecReadArrayElem() z.DecStructFieldNotFound(yyj7-1, "") } } func (x *testSelfExtHelper) IsCodecEmpty() bool { return !(x.S != "" || x.I != 0 || bool(x.B) || false) } func (TestSelfExtImpl) codecSelferViaCodecgen() {} func (x *TestSelfExtImpl) CodecEncodeSelf(e *Encoder) { var h codecSelfer19780 z, r := GenHelper().Encoder(e) _, _, _ = h, z, r if z.EncBasicHandle().CheckCircularRef { z.EncEncode(x) return } if x == nil { r.EncodeNil() } else { yy2arr2 := z.EncBasicHandle().StructToArray _ = yy2arr2 const yyr2 bool = false // struct tag has 'toArray' if yyr2 || yy2arr2 { z.EncWriteArrayStart(3) z.EncWriteArrayElem() r.EncodeString(string(x.testSelfExtHelper.S)) z.EncWriteArrayElem() r.EncodeInt(int64(x.testSelfExtHelper.I)) z.EncWriteArrayElem() r.EncodeBool(bool(x.testSelfExtHelper.B)) z.EncWriteArrayEnd() } else { z.EncWriteMapStart(3) if z.EncBasicHandle().Canonical { z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"B\"") } else { r.EncodeString(`B`) } z.EncWriteMapElemValue() r.EncodeBool(bool(x.testSelfExtHelper.B)) z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"I\"") } else { r.EncodeString(`I`) } z.EncWriteMapElemValue() r.EncodeInt(int64(x.testSelfExtHelper.I)) z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"S\"") } else { r.EncodeString(`S`) } z.EncWriteMapElemValue() r.EncodeString(string(x.testSelfExtHelper.S)) } else { z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"S\"") } else { r.EncodeString(`S`) } z.EncWriteMapElemValue() r.EncodeString(string(x.testSelfExtHelper.S)) z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"I\"") } else { r.EncodeString(`I`) } z.EncWriteMapElemValue() r.EncodeInt(int64(x.testSelfExtHelper.I)) z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"B\"") } else { r.EncodeString(`B`) } z.EncWriteMapElemValue() r.EncodeBool(bool(x.testSelfExtHelper.B)) } z.EncWriteMapEnd() } } } func (x *TestSelfExtImpl) CodecDecodeSelf(d *Decoder) { var h codecSelfer19780 z, r := GenHelper().Decoder(d) _, _, _ = h, z, r yyct2 := r.ContainerType() if yyct2 == codecSelferValueTypeNil19780 { *(x) = TestSelfExtImpl{} } else if yyct2 == codecSelferValueTypeMap19780 { yyl2 := z.DecReadMapStart() if yyl2 == 0 { } else { x.codecDecodeSelfFromMap(yyl2, d) } z.DecReadMapEnd() } else if yyct2 == codecSelferValueTypeArray19780 { yyl2 := z.DecReadArrayStart() if yyl2 != 0 { x.codecDecodeSelfFromArray(yyl2, d) } z.DecReadArrayEnd() } else { panic(errCodecSelferOnlyMapOrArrayEncodeToStruct19780) } } func (x *TestSelfExtImpl) codecDecodeSelfFromMap(l int, d *Decoder) { var h codecSelfer19780 z, r := GenHelper().Decoder(d) _, _, _ = h, z, r var yyhl3 bool = l >= 0 for yyj3 := 0; ; yyj3++ { if yyhl3 { if yyj3 >= l { break } } else { if z.DecCheckBreak() { break } } z.DecReadMapElemKey() yys3 := r.DecodeStringAsBytes() z.DecReadMapElemValue() switch string(yys3) { case "S": x.testSelfExtHelper.S = (string)(z.DecStringZC(r.DecodeStringAsBytes())) case "I": x.testSelfExtHelper.I = (int64)(r.DecodeInt64()) case "B": x.testSelfExtHelper.B = (bool)(r.DecodeBool()) default: z.DecStructFieldNotFound(-1, string(yys3)) } // end switch yys3 } // end for yyj3 } func (x *TestSelfExtImpl) codecDecodeSelfFromArray(l int, d *Decoder) { var h codecSelfer19780 z, r := GenHelper().Decoder(d) _, _, _ = h, z, r var yyj7 int var yyb7 bool var yyhl7 bool = l >= 0 yyj7++ if yyhl7 { yyb7 = yyj7 > l } else { yyb7 = z.DecCheckBreak() } if yyb7 { z.DecReadArrayEnd() return } z.DecReadArrayElem() x.testSelfExtHelper.S = (string)(z.DecStringZC(r.DecodeStringAsBytes())) yyj7++ if yyhl7 { yyb7 = yyj7 > l } else { yyb7 = z.DecCheckBreak() } if yyb7 { z.DecReadArrayEnd() return } z.DecReadArrayElem() x.testSelfExtHelper.I = (int64)(r.DecodeInt64()) yyj7++ if yyhl7 { yyb7 = yyj7 > l } else { yyb7 = z.DecCheckBreak() } if yyb7 { z.DecReadArrayEnd() return } z.DecReadArrayElem() x.testSelfExtHelper.B = (bool)(r.DecodeBool()) for { yyj7++ if yyhl7 { yyb7 = yyj7 > l } else { yyb7 = z.DecCheckBreak() } if yyb7 { break } z.DecReadArrayElem() z.DecStructFieldNotFound(yyj7-1, "") } } func (x *TestSelfExtImpl) IsCodecEmpty() bool { return !(!(x.testSelfExtHelper.IsCodecEmpty()) || false) } func (TestSelfExtImpl2) codecSelferViaCodecgen() {} func (x *TestSelfExtImpl2) CodecEncodeSelf(e *Encoder) { var h codecSelfer19780 z, r := GenHelper().Encoder(e) _, _, _ = h, z, r if z.EncBasicHandle().CheckCircularRef { z.EncEncode(x) return } if x == nil { r.EncodeNil() } else { yy2arr2 := z.EncBasicHandle().StructToArray _ = yy2arr2 const yyr2 bool = false // struct tag has 'toArray' if yyr2 || yy2arr2 { z.EncWriteArrayStart(2) z.EncWriteArrayElem() r.EncodeString(string(x.M)) z.EncWriteArrayElem() r.EncodeBool(bool(x.O)) z.EncWriteArrayEnd() } else { z.EncWriteMapStart(2) if z.EncBasicHandle().Canonical { z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"M\"") } else { r.EncodeString(`M`) } z.EncWriteMapElemValue() r.EncodeString(string(x.M)) z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"O\"") } else { r.EncodeString(`O`) } z.EncWriteMapElemValue() r.EncodeBool(bool(x.O)) } else { z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"M\"") } else { r.EncodeString(`M`) } z.EncWriteMapElemValue() r.EncodeString(string(x.M)) z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"O\"") } else { r.EncodeString(`O`) } z.EncWriteMapElemValue() r.EncodeBool(bool(x.O)) } z.EncWriteMapEnd() } } } func (x *TestSelfExtImpl2) CodecDecodeSelf(d *Decoder) { var h codecSelfer19780 z, r := GenHelper().Decoder(d) _, _, _ = h, z, r yyct2 := r.ContainerType() if yyct2 == codecSelferValueTypeNil19780 { *(x) = TestSelfExtImpl2{} } else if yyct2 == codecSelferValueTypeMap19780 { yyl2 := z.DecReadMapStart() if yyl2 == 0 { } else { x.codecDecodeSelfFromMap(yyl2, d) } z.DecReadMapEnd() } else if yyct2 == codecSelferValueTypeArray19780 { yyl2 := z.DecReadArrayStart() if yyl2 != 0 { x.codecDecodeSelfFromArray(yyl2, d) } z.DecReadArrayEnd() } else { panic(errCodecSelferOnlyMapOrArrayEncodeToStruct19780) } } func (x *TestSelfExtImpl2) codecDecodeSelfFromMap(l int, d *Decoder) { var h codecSelfer19780 z, r := GenHelper().Decoder(d) _, _, _ = h, z, r var yyhl3 bool = l >= 0 for yyj3 := 0; ; yyj3++ { if yyhl3 { if yyj3 >= l { break } } else { if z.DecCheckBreak() { break } } z.DecReadMapElemKey() yys3 := r.DecodeStringAsBytes() z.DecReadMapElemValue() switch string(yys3) { case "M": x.M = (string)(z.DecStringZC(r.DecodeStringAsBytes())) case "O": x.O = (bool)(r.DecodeBool()) default: z.DecStructFieldNotFound(-1, string(yys3)) } // end switch yys3 } // end for yyj3 } func (x *TestSelfExtImpl2) codecDecodeSelfFromArray(l int, d *Decoder) { var h codecSelfer19780 z, r := GenHelper().Decoder(d) _, _, _ = h, z, r var yyj6 int var yyb6 bool var yyhl6 bool = l >= 0 yyj6++ if yyhl6 { yyb6 = yyj6 > l } else { yyb6 = z.DecCheckBreak() } if yyb6 { z.DecReadArrayEnd() return } z.DecReadArrayElem() x.M = (string)(z.DecStringZC(r.DecodeStringAsBytes())) yyj6++ if yyhl6 { yyb6 = yyj6 > l } else { yyb6 = z.DecCheckBreak() } if yyb6 { z.DecReadArrayEnd() return } z.DecReadArrayElem() x.O = (bool)(r.DecodeBool()) for { yyj6++ if yyhl6 { yyb6 = yyj6 > l } else { yyb6 = z.DecCheckBreak() } if yyb6 { break } z.DecReadArrayElem() z.DecStructFieldNotFound(yyj6-1, "") } } func (x *TestSelfExtImpl2) IsCodecEmpty() bool { return !(x.M != "" || bool(x.O) || false) } func (TestTwoNakedInterfaces) codecSelferViaCodecgen() {} func (x *TestTwoNakedInterfaces) CodecEncodeSelf(e *Encoder) { var h codecSelfer19780 z, r := GenHelper().Encoder(e) _, _, _ = h, z, r if z.EncBasicHandle().CheckCircularRef { z.EncEncode(x) return } if x == nil { r.EncodeNil() } else { yy2arr2 := z.EncBasicHandle().StructToArray _ = yy2arr2 const yyr2 bool = false // struct tag has 'toArray' if yyr2 || yy2arr2 { z.EncWriteArrayStart(2) z.EncWriteArrayElem() z.EncFallback(x.A) z.EncWriteArrayElem() z.EncFallback(x.B) z.EncWriteArrayEnd() } else { z.EncWriteMapStart(2) if z.EncBasicHandle().Canonical { z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"A\"") } else { r.EncodeString(`A`) } z.EncWriteMapElemValue() z.EncFallback(x.A) z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"B\"") } else { r.EncodeString(`B`) } z.EncWriteMapElemValue() z.EncFallback(x.B) } else { z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"A\"") } else { r.EncodeString(`A`) } z.EncWriteMapElemValue() z.EncFallback(x.A) z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"B\"") } else { r.EncodeString(`B`) } z.EncWriteMapElemValue() z.EncFallback(x.B) } z.EncWriteMapEnd() } } } func (x *TestTwoNakedInterfaces) CodecDecodeSelf(d *Decoder) { var h codecSelfer19780 z, r := GenHelper().Decoder(d) _, _, _ = h, z, r yyct2 := r.ContainerType() if yyct2 == codecSelferValueTypeNil19780 { *(x) = TestTwoNakedInterfaces{} } else if yyct2 == codecSelferValueTypeMap19780 { yyl2 := z.DecReadMapStart() if yyl2 == 0 { } else { x.codecDecodeSelfFromMap(yyl2, d) } z.DecReadMapEnd() } else if yyct2 == codecSelferValueTypeArray19780 { yyl2 := z.DecReadArrayStart() if yyl2 != 0 { x.codecDecodeSelfFromArray(yyl2, d) } z.DecReadArrayEnd() } else { panic(errCodecSelferOnlyMapOrArrayEncodeToStruct19780) } } func (x *TestTwoNakedInterfaces) codecDecodeSelfFromMap(l int, d *Decoder) { var h codecSelfer19780 z, r := GenHelper().Decoder(d) _, _, _ = h, z, r var yyhl3 bool = l >= 0 for yyj3 := 0; ; yyj3++ { if yyhl3 { if yyj3 >= l { break } } else { if z.DecCheckBreak() { break } } z.DecReadMapElemKey() yys3 := r.DecodeStringAsBytes() z.DecReadMapElemValue() switch string(yys3) { case "A": z.DecFallback(&x.A, true) case "B": z.DecFallback(&x.B, true) default: z.DecStructFieldNotFound(-1, string(yys3)) } // end switch yys3 } // end for yyj3 } func (x *TestTwoNakedInterfaces) codecDecodeSelfFromArray(l int, d *Decoder) { var h codecSelfer19780 z, r := GenHelper().Decoder(d) _, _, _ = h, z, r var yyj8 int var yyb8 bool var yyhl8 bool = l >= 0 yyj8++ if yyhl8 { yyb8 = yyj8 > l } else { yyb8 = z.DecCheckBreak() } if yyb8 { z.DecReadArrayEnd() return } z.DecReadArrayElem() z.DecFallback(&x.A, true) yyj8++ if yyhl8 { yyb8 = yyj8 > l } else { yyb8 = z.DecCheckBreak() } if yyb8 { z.DecReadArrayEnd() return } z.DecReadArrayElem() z.DecFallback(&x.B, true) for { yyj8++ if yyhl8 { yyb8 = yyj8 > l } else { yyb8 = z.DecCheckBreak() } if yyb8 { break } z.DecReadArrayElem() z.DecStructFieldNotFound(yyj8-1, "") } } func (x *TestTwoNakedInterfaces) IsCodecEmpty() bool { return !(x.A != nil || x.B != nil || false) } func (TestStrucFlex) codecSelferViaCodecgen() {} func (x *TestStrucFlex) CodecEncodeSelf(e *Encoder) { var h codecSelfer19780 z, r := GenHelper().Encoder(e) _, _, _ = h, z, r if z.EncBasicHandle().CheckCircularRef { z.EncEncode(x) return } if x == nil { r.EncodeNil() } else { yy2arr2 := z.EncBasicHandle().StructToArray _ = yy2arr2 const yyr2 bool = false // struct tag has 'toArray' var yyn54 bool = x.TestStrucCommon.AnonInTestStrucSlim == nil || x.TestStrucCommon.AnonInTestStrucSlim.P == nil var yyn55 bool = x.TestStrucCommon.NotAnonSlim == nil var yyn58 bool = x.TestStrucCommon.Nint64 == nil var yyn81 bool = x.Ttimeptr == nil var yyn82 bool = x.AnonInTestStrucIntf == nil var yyn83 bool = x.AnonInTestStrucIntf == nil var yyn84 bool = x.AnonInTestStrucIntf == nil var yyn85 bool = x.AnonInTestStrucIntf == nil var yyn86 bool = x.AnonInTestStrucIntf == nil || x.AnonInTestStrucIntf.Tptr == nil var yyn91 bool = x.Nteststruc == nil var yyq2 = [95]bool{ // should field at this index be written? x.S != "", // S x.I64 != 0, // I64 x.I32 != 0, // I32 x.I16 != 0, // I16 x.I8 != 0, // I8 x.I64n != 0, // I64n x.I32n != 0, // I32n x.I16n != 0, // I16n x.I8n != 0, // I8n x.Ui64 != 0, // Ui64 x.Ui32 != 0, // Ui32 x.Ui16 != 0, // Ui16 x.Ui8 != 0, // Ui8 x.F64 != 0, // F64 x.F32 != 0, // F32 bool(x.B), // B x.By != 0, // By len(x.Sslice) != 0, // Sslice len(x.I64slice) != 0, // I64slice len(x.I32slice) != 0, // I32slice len(x.Ui64slice) != 0, // Ui64slice len(x.Ui8slice) != 0, // Ui8slice len(x.Bslice) != 0, // Bslice len(x.Byslice) != 0, // Byslice len(x.BytesSlice) != 0, // BytesSlice len(x.Iptrslice) != 0, // Iptrslice len(x.WrapSliceInt64) != 0, // WrapSliceInt64 len(x.WrapSliceString) != 0, // WrapSliceString len(x.Msint) != 0, // Msint len(x.Msbytes) != 0, // Msbytes !(x.Simplef.IsCodecEmpty()), // Simplef len(x.SstrUi64T) != 0, // SstrUi64T len(x.MstrUi64T) != 0, // MstrUi64T x.AS != "", // AS x.AI64 != 0, // AI64 x.AI16 != 0, // AI16 x.AUi64 != 0, // AUi64 len(x.ASslice) != 0, // ASslice len(x.AI64slice) != 0, // AI64slice len(x.AUi64slice) != 0, // AUi64slice len(x.AF64slice) != 0, // AF64slice len(x.AF32slice) != 0, // AF32slice len(x.AMSS) != 0, // AMSS len(x.AMSU64) != 0, // AMSU64 x.AI64arr8 != [8]int64{}, // AI64arr8 false, // AI64arr0 len(x.AI64slice0) != 0, // AI64slice0 len(x.AUi64sliceN) != 0, // AUi64sliceN len(x.AMSU64N) != 0, // AMSU64N len(x.AMSU64E) != 0, // AMSU64E !(x.NotAnon.IsCodecEmpty()), // NotAnon x.TestStrucCommon.AnonInTestStrucSlim != nil && x.P != nil, // P x.NotAnonSlim != nil, // NotAnonSlim len(x.Nmap) != 0, // Nmap len(x.Nslice) != 0, // Nslice x.Nint64 != nil, // Nint64 len(x.Chstr) != 0, // Chstr len(x.Mis) != 0, // Mis len(x.Mbu64) != 0, // Mbu64 len(x.Mu8e) != 0, // Mu8e len(x.Mu8u64) != 0, // Mu8u64 len(x.Msp2ss) != 0, // Msp2ss len(x.Mip2ss) != 0, // Mip2ss len(x.Ms2misu) != 0, // Ms2misu len(x.Miwu64s) != 0, // Miwu64s len(x.Mfwss) != 0, // Mfwss len(x.Mf32wss) != 0, // Mf32wss len(x.Mui2wss) != 0, // Mui2wss len(x.Msu2wss) != 0, // Msu2wss x.Ci64 != 0, // Ci64 len(x.Swrapbytes) != 0, // Swrapbytes len(x.Swrapuint8) != 0, // Swrapuint8 x.ArrStrUi64T != [4]stringUint64T{}, // ArrStrUi64T x.Ui64array != [4]uint64{}, // Ui64array len(x.Ui64slicearray) != 0, // Ui64slicearray len(x.SintfAarray) != 0, // SintfAarray len(x.MstrUi64TSelf) != 0, // MstrUi64TSelf !(x.Ttime.IsZero()), // Ttime x.Ttimeptr != nil, // Ttimeptr x.AnonInTestStrucIntf != nil && len(x.Islice) != 0, // Islice x.AnonInTestStrucIntf != nil && len(x.Ms) != 0, // Ms x.AnonInTestStrucIntf != nil && x.Nintf != nil, // Nintf x.AnonInTestStrucIntf != nil && !(x.T.IsZero()), // T x.AnonInTestStrucIntf != nil && x.Tptr != nil, // Tptr len(x.Msu) != 0, // Msu len(x.Mtsptr) != 0, // Mtsptr len(x.Mts) != 0, // Mts len(x.Its) != 0, // Its x.Nteststruc != nil, // Nteststruc bool(x.MarJ), // MarJ x.MarT != "", // MarT len(x.MarB) != 0, // MarB x.XuintToBytes != 0, // XuintToBytes x.Cmplx64 != 0, // Cmplx64 x.Cmplx128 != 0, // Cmplx128 } _ = yyq2 if yyr2 || yy2arr2 { z.EncWriteArrayStart(95) z.EncWriteArrayElem() if yyq2[0] { r.EncodeString(string(x.TestStrucCommon.S)) } else { r.EncodeString("") } z.EncWriteArrayElem() if yyq2[1] { r.EncodeInt(int64(x.TestStrucCommon.I64)) } else { r.EncodeInt(0) } z.EncWriteArrayElem() if yyq2[2] { r.EncodeInt(int64(x.TestStrucCommon.I32)) } else { r.EncodeInt(0) } z.EncWriteArrayElem() if yyq2[3] { r.EncodeInt(int64(x.TestStrucCommon.I16)) } else { r.EncodeInt(0) } z.EncWriteArrayElem() if yyq2[4] { r.EncodeInt(int64(x.TestStrucCommon.I8)) } else { r.EncodeInt(0) } z.EncWriteArrayElem() if yyq2[5] { r.EncodeInt(int64(x.TestStrucCommon.I64n)) } else { r.EncodeInt(0) } z.EncWriteArrayElem() if yyq2[6] { r.EncodeInt(int64(x.TestStrucCommon.I32n)) } else { r.EncodeInt(0) } z.EncWriteArrayElem() if yyq2[7] { r.EncodeInt(int64(x.TestStrucCommon.I16n)) } else { r.EncodeInt(0) } z.EncWriteArrayElem() if yyq2[8] { r.EncodeInt(int64(x.TestStrucCommon.I8n)) } else { r.EncodeInt(0) } z.EncWriteArrayElem() if yyq2[9] { r.EncodeUint(uint64(x.TestStrucCommon.Ui64)) } else { r.EncodeUint(0) } z.EncWriteArrayElem() if yyq2[10] { r.EncodeUint(uint64(x.TestStrucCommon.Ui32)) } else { r.EncodeUint(0) } z.EncWriteArrayElem() if yyq2[11] { r.EncodeUint(uint64(x.TestStrucCommon.Ui16)) } else { r.EncodeUint(0) } z.EncWriteArrayElem() if yyq2[12] { r.EncodeUint(uint64(x.TestStrucCommon.Ui8)) } else { r.EncodeUint(0) } z.EncWriteArrayElem() if yyq2[13] { r.EncodeFloat64(float64(x.TestStrucCommon.F64)) } else { r.EncodeFloat64(0) } z.EncWriteArrayElem() if yyq2[14] { r.EncodeFloat32(float32(x.TestStrucCommon.F32)) } else { r.EncodeFloat32(0) } z.EncWriteArrayElem() if yyq2[15] { r.EncodeBool(bool(x.TestStrucCommon.B)) } else { r.EncodeBool(false) } z.EncWriteArrayElem() if yyq2[16] { r.EncodeUint(uint64(x.TestStrucCommon.By)) } else { r.EncodeUint(0) } z.EncWriteArrayElem() if yyq2[17] { if x.TestStrucCommon.Sslice == nil { r.EncodeNil() } else { z.F.EncSliceStringV(x.TestStrucCommon.Sslice, e) } // end block: if x.TestStrucCommon.Sslice slice == nil } else { r.EncodeNil() } z.EncWriteArrayElem() if yyq2[18] { if x.TestStrucCommon.I64slice == nil { r.EncodeNil() } else { z.F.EncSliceInt64V(x.TestStrucCommon.I64slice, e) } // end block: if x.TestStrucCommon.I64slice slice == nil } else { r.EncodeNil() } z.EncWriteArrayElem() if yyq2[19] { if x.TestStrucCommon.I32slice == nil { r.EncodeNil() } else { z.F.EncSliceInt32V(x.TestStrucCommon.I32slice, e) } // end block: if x.TestStrucCommon.I32slice slice == nil } else { r.EncodeNil() } z.EncWriteArrayElem() if yyq2[20] { if x.TestStrucCommon.Ui64slice == nil { r.EncodeNil() } else { z.F.EncSliceUint64V(x.TestStrucCommon.Ui64slice, e) } // end block: if x.TestStrucCommon.Ui64slice slice == nil } else { r.EncodeNil() } z.EncWriteArrayElem() if yyq2[21] { if x.TestStrucCommon.Ui8slice == nil { r.EncodeNil() } else { r.EncodeStringBytesRaw([]byte(x.TestStrucCommon.Ui8slice)) } // end block: if x.TestStrucCommon.Ui8slice slice == nil } else { r.EncodeNil() } z.EncWriteArrayElem() if yyq2[22] { if x.TestStrucCommon.Bslice == nil { r.EncodeNil() } else { z.F.EncSliceBoolV(x.TestStrucCommon.Bslice, e) } // end block: if x.TestStrucCommon.Bslice slice == nil } else { r.EncodeNil() } z.EncWriteArrayElem() if yyq2[23] { if x.TestStrucCommon.Byslice == nil { r.EncodeNil() } else { r.EncodeStringBytesRaw([]byte(x.TestStrucCommon.Byslice)) } // end block: if x.TestStrucCommon.Byslice slice == nil } else { r.EncodeNil() } z.EncWriteArrayElem() if yyq2[24] { if x.TestStrucCommon.BytesSlice == nil { r.EncodeNil() } else { z.F.EncSliceBytesV(x.TestStrucCommon.BytesSlice, e) } // end block: if x.TestStrucCommon.BytesSlice slice == nil } else { r.EncodeNil() } z.EncWriteArrayElem() if yyq2[25] { if x.TestStrucCommon.Iptrslice == nil { r.EncodeNil() } else { h.encSlicePtrtoint64(([]*int64)(x.TestStrucCommon.Iptrslice), e) } // end block: if x.TestStrucCommon.Iptrslice slice == nil } else { r.EncodeNil() } z.EncWriteArrayElem() if yyq2[26] { if yyxt124 := z.Extension(x.TestStrucCommon.WrapSliceInt64); yyxt124 != nil { z.EncExtension(x.TestStrucCommon.WrapSliceInt64, yyxt124) } else { x.TestStrucCommon.WrapSliceInt64.CodecEncodeSelf(e) } } else { r.EncodeNil() } z.EncWriteArrayElem() if yyq2[27] { if yyxt125 := z.Extension(x.TestStrucCommon.WrapSliceString); yyxt125 != nil { z.EncExtension(x.TestStrucCommon.WrapSliceString, yyxt125) } else { x.TestStrucCommon.WrapSliceString.CodecEncodeSelf(e) } } else { r.EncodeNil() } z.EncWriteArrayElem() if yyq2[28] { if x.TestStrucCommon.Msint == nil { r.EncodeNil() } else { z.F.EncMapStringIntV(x.TestStrucCommon.Msint, e) } // end block: if x.TestStrucCommon.Msint map == nil } else { r.EncodeNil() } z.EncWriteArrayElem() if yyq2[29] { if x.TestStrucCommon.Msbytes == nil { r.EncodeNil() } else { z.F.EncMapStringBytesV(x.TestStrucCommon.Msbytes, e) } // end block: if x.TestStrucCommon.Msbytes map == nil } else { r.EncodeNil() } z.EncWriteArrayElem() if yyq2[30] { yy128 := &x.TestStrucCommon.Simplef if yyxt129 := z.Extension(yy128); yyxt129 != nil { z.EncExtension(yy128, yyxt129) } else { yy128.CodecEncodeSelf(e) } } else { r.EncodeNil() } z.EncWriteArrayElem() if yyq2[31] { if x.TestStrucCommon.SstrUi64T == nil { r.EncodeNil() } else { h.encSlicestringUint64T(([]stringUint64T)(x.TestStrucCommon.SstrUi64T), e) } // end block: if x.TestStrucCommon.SstrUi64T slice == nil } else { r.EncodeNil() } z.EncWriteArrayElem() if yyq2[32] { if x.TestStrucCommon.MstrUi64T == nil { r.EncodeNil() } else { h.encMapstringPtrtostringUint64T((map[string]*stringUint64T)(x.TestStrucCommon.MstrUi64T), e) } // end block: if x.TestStrucCommon.MstrUi64T map == nil } else { r.EncodeNil() } z.EncWriteArrayElem() if yyq2[33] { r.EncodeString(string(x.TestStrucCommon.AnonInTestStruc.AS)) } else { r.EncodeString("") } z.EncWriteArrayElem() if yyq2[34] { r.EncodeInt(int64(x.TestStrucCommon.AnonInTestStruc.AI64)) } else { r.EncodeInt(0) } z.EncWriteArrayElem() if yyq2[35] { r.EncodeInt(int64(x.TestStrucCommon.AnonInTestStruc.AI16)) } else { r.EncodeInt(0) } z.EncWriteArrayElem() if yyq2[36] { r.EncodeUint(uint64(x.TestStrucCommon.AnonInTestStruc.AUi64)) } else { r.EncodeUint(0) } z.EncWriteArrayElem() if yyq2[37] { if x.TestStrucCommon.AnonInTestStruc.ASslice == nil { r.EncodeNil() } else { z.F.EncSliceStringV(x.TestStrucCommon.AnonInTestStruc.ASslice, e) } // end block: if x.TestStrucCommon.AnonInTestStruc.ASslice slice == nil } else { r.EncodeNil() } z.EncWriteArrayElem() if yyq2[38] { if x.TestStrucCommon.AnonInTestStruc.AI64slice == nil { r.EncodeNil() } else { z.F.EncSliceInt64V(x.TestStrucCommon.AnonInTestStruc.AI64slice, e) } // end block: if x.TestStrucCommon.AnonInTestStruc.AI64slice slice == nil } else { r.EncodeNil() } z.EncWriteArrayElem() if yyq2[39] { if x.TestStrucCommon.AnonInTestStruc.AUi64slice == nil { r.EncodeNil() } else { z.F.EncSliceUint64V(x.TestStrucCommon.AnonInTestStruc.AUi64slice, e) } // end block: if x.TestStrucCommon.AnonInTestStruc.AUi64slice slice == nil } else { r.EncodeNil() } z.EncWriteArrayElem() if yyq2[40] { if x.TestStrucCommon.AnonInTestStruc.AF64slice == nil { r.EncodeNil() } else { z.F.EncSliceFloat64V(x.TestStrucCommon.AnonInTestStruc.AF64slice, e) } // end block: if x.TestStrucCommon.AnonInTestStruc.AF64slice slice == nil } else { r.EncodeNil() } z.EncWriteArrayElem() if yyq2[41] { if x.TestStrucCommon.AnonInTestStruc.AF32slice == nil { r.EncodeNil() } else { z.F.EncSliceFloat32V(x.TestStrucCommon.AnonInTestStruc.AF32slice, e) } // end block: if x.TestStrucCommon.AnonInTestStruc.AF32slice slice == nil } else { r.EncodeNil() } z.EncWriteArrayElem() if yyq2[42] { if x.TestStrucCommon.AnonInTestStruc.AMSS == nil { r.EncodeNil() } else { z.F.EncMapStringStringV(x.TestStrucCommon.AnonInTestStruc.AMSS, e) } // end block: if x.TestStrucCommon.AnonInTestStruc.AMSS map == nil } else { r.EncodeNil() } z.EncWriteArrayElem() if yyq2[43] { if x.TestStrucCommon.AnonInTestStruc.AMSU64 == nil { r.EncodeNil() } else { z.F.EncMapStringUint64V(x.TestStrucCommon.AnonInTestStruc.AMSU64, e) } // end block: if x.TestStrucCommon.AnonInTestStruc.AMSU64 map == nil } else { r.EncodeNil() } z.EncWriteArrayElem() if yyq2[44] { yy143 := &x.TestStrucCommon.AnonInTestStruc.AI64arr8 h.encArray8int64((*[8]int64)(yy143), e) } else { r.EncodeNil() } z.EncWriteArrayElem() if yyq2[45] { yy145 := &x.TestStrucCommon.AnonInTestStruc.AI64arr0 h.encArray0int64((*[0]int64)(yy145), e) } else { r.EncodeNil() } z.EncWriteArrayElem() if yyq2[46] { if x.TestStrucCommon.AnonInTestStruc.AI64slice0 == nil { r.EncodeNil() } else { z.F.EncSliceInt64V(x.TestStrucCommon.AnonInTestStruc.AI64slice0, e) } // end block: if x.TestStrucCommon.AnonInTestStruc.AI64slice0 slice == nil } else { r.EncodeNil() } z.EncWriteArrayElem() if yyq2[47] { if x.TestStrucCommon.AnonInTestStruc.AUi64sliceN == nil { r.EncodeNil() } else { z.F.EncSliceUint64V(x.TestStrucCommon.AnonInTestStruc.AUi64sliceN, e) } // end block: if x.TestStrucCommon.AnonInTestStruc.AUi64sliceN slice == nil } else { r.EncodeNil() } z.EncWriteArrayElem() if yyq2[48] { if x.TestStrucCommon.AnonInTestStruc.AMSU64N == nil { r.EncodeNil() } else { z.F.EncMapStringUint64V(x.TestStrucCommon.AnonInTestStruc.AMSU64N, e) } // end block: if x.TestStrucCommon.AnonInTestStruc.AMSU64N map == nil } else { r.EncodeNil() } z.EncWriteArrayElem() if yyq2[49] { if x.TestStrucCommon.AnonInTestStruc.AMSU64E == nil { r.EncodeNil() } else { z.F.EncMapStringUint64V(x.TestStrucCommon.AnonInTestStruc.AMSU64E, e) } // end block: if x.TestStrucCommon.AnonInTestStruc.AMSU64E map == nil } else { r.EncodeNil() } z.EncWriteArrayElem() if yyq2[50] { yy151 := &x.TestStrucCommon.NotAnon if yyxt152 := z.Extension(yy151); yyxt152 != nil { z.EncExtension(yy151, yyxt152) } else { yy151.CodecEncodeSelf(e) } } else { r.EncodeNil() } if yyn54 { z.EncWriteArrayElem() r.EncodeNil() } else { z.EncWriteArrayElem() if yyq2[51] { yy153 := *x.TestStrucCommon.AnonInTestStrucSlim.P r.EncodeString(string(yy153)) } else { r.EncodeNil() } } if yyn55 { z.EncWriteArrayElem() r.EncodeNil() } else { z.EncWriteArrayElem() if yyq2[52] { if yyxt155 := z.Extension(x.TestStrucCommon.NotAnonSlim); yyxt155 != nil { z.EncExtension(x.TestStrucCommon.NotAnonSlim, yyxt155) } else { x.TestStrucCommon.NotAnonSlim.CodecEncodeSelf(e) } } else { r.EncodeNil() } } z.EncWriteArrayElem() if yyq2[53] { if x.TestStrucCommon.Nmap == nil { r.EncodeNil() } else { z.F.EncMapStringBoolV(x.TestStrucCommon.Nmap, e) } // end block: if x.TestStrucCommon.Nmap map == nil } else { r.EncodeNil() } z.EncWriteArrayElem() if yyq2[54] { if x.TestStrucCommon.Nslice == nil { r.EncodeNil() } else { r.EncodeStringBytesRaw([]byte(x.TestStrucCommon.Nslice)) } // end block: if x.TestStrucCommon.Nslice slice == nil } else { r.EncodeNil() } if yyn58 { z.EncWriteArrayElem() r.EncodeNil() } else { z.EncWriteArrayElem() if yyq2[55] { yy158 := *x.TestStrucCommon.Nint64 r.EncodeInt(int64(yy158)) } else { r.EncodeNil() } } z.EncWriteArrayElem() if yyq2[56] { h.encChanstring((chan string)(x.Chstr), e) } else { r.EncodeNil() } z.EncWriteArrayElem() if yyq2[57] { if x.Mis == nil { r.EncodeNil() } else { z.F.EncMapIntStringV(x.Mis, e) } // end block: if x.Mis map == nil } else { r.EncodeNil() } z.EncWriteArrayElem() if yyq2[58] { if x.Mbu64 == nil { r.EncodeNil() } else { h.encMapboolc3RydWN0IHt9((map[bool]struct{})(x.Mbu64), e) } // end block: if x.Mbu64 map == nil } else { r.EncodeNil() } z.EncWriteArrayElem() if yyq2[59] { if x.Mu8e == nil { r.EncodeNil() } else { h.encMapuint8c3RydWN0IHt9((map[uint8]struct{})(x.Mu8e), e) } // end block: if x.Mu8e map == nil } else { r.EncodeNil() } z.EncWriteArrayElem() if yyq2[60] { if x.Mu8u64 == nil { r.EncodeNil() } else { h.encMapuint8stringUint64T((map[uint8]stringUint64T)(x.Mu8u64), e) } // end block: if x.Mu8u64 map == nil } else { r.EncodeNil() } z.EncWriteArrayElem() if yyq2[61] { if x.Msp2ss == nil { r.EncodeNil() } else { h.encMapPtrtostringSlicestring((map[*string][]string)(x.Msp2ss), e) } // end block: if x.Msp2ss map == nil } else { r.EncodeNil() } z.EncWriteArrayElem() if yyq2[62] { if x.Mip2ss == nil { r.EncodeNil() } else { h.encMapPtrtouint64Slicestring((map[*uint64][]string)(x.Mip2ss), e) } // end block: if x.Mip2ss map == nil } else { r.EncodeNil() } z.EncWriteArrayElem() if yyq2[63] { if x.Ms2misu == nil { r.EncodeNil() } else { h.encMapstringMapuint64stringUint64T((map[string]map[uint64]stringUint64T)(x.Ms2misu), e) } // end block: if x.Ms2misu map == nil } else { r.EncodeNil() } z.EncWriteArrayElem() if yyq2[64] { if x.Miwu64s == nil { r.EncodeNil() } else { h.encMapintwrapUint64Slice((map[int]wrapUint64Slice)(x.Miwu64s), e) } // end block: if x.Miwu64s map == nil } else { r.EncodeNil() } z.EncWriteArrayElem() if yyq2[65] { if x.Mfwss == nil { r.EncodeNil() } else { h.encMapfloat64wrapStringSlice((map[float64]wrapStringSlice)(x.Mfwss), e) } // end block: if x.Mfwss map == nil } else { r.EncodeNil() } z.EncWriteArrayElem() if yyq2[66] { if x.Mf32wss == nil { r.EncodeNil() } else { h.encMapfloat32wrapStringSlice((map[float32]wrapStringSlice)(x.Mf32wss), e) } // end block: if x.Mf32wss map == nil } else { r.EncodeNil() } z.EncWriteArrayElem() if yyq2[67] { if x.Mui2wss == nil { r.EncodeNil() } else { h.encMapuint64wrapStringSlice((map[uint64]wrapStringSlice)(x.Mui2wss), e) } // end block: if x.Mui2wss map == nil } else { r.EncodeNil() } z.EncWriteArrayElem() if yyq2[68] { if x.Msu2wss == nil { r.EncodeNil() } else { h.encMapstringUint64TwrapStringSlice((map[stringUint64T]wrapStringSlice)(x.Msu2wss), e) } // end block: if x.Msu2wss map == nil } else { r.EncodeNil() } z.EncWriteArrayElem() if yyq2[69] { if yyxt173 := z.Extension(x.Ci64); yyxt173 != nil { z.EncExtension(x.Ci64, yyxt173) } else { x.Ci64.CodecEncodeSelf(e) } } else { r.EncodeInt(0) } z.EncWriteArrayElem() if yyq2[70] { if x.Swrapbytes == nil { r.EncodeNil() } else { h.encSlicewrapBytes(([]wrapBytes)(x.Swrapbytes), e) } // end block: if x.Swrapbytes slice == nil } else { r.EncodeNil() } z.EncWriteArrayElem() if yyq2[71] { if x.Swrapuint8 == nil { r.EncodeNil() } else { h.encSlicewrapUint8(([]wrapUint8)(x.Swrapuint8), e) } // end block: if x.Swrapuint8 slice == nil } else { r.EncodeNil() } z.EncWriteArrayElem() if yyq2[72] { yy176 := &x.ArrStrUi64T h.encArray4stringUint64T((*[4]stringUint64T)(yy176), e) } else { r.EncodeNil() } z.EncWriteArrayElem() if yyq2[73] { yy178 := &x.Ui64array h.encArray4uint64((*[4]uint64)(yy178), e) } else { r.EncodeNil() } z.EncWriteArrayElem() if yyq2[74] { if x.Ui64slicearray == nil { r.EncodeNil() } else { h.encSlicePtrtoArray4uint64(([]*[4]uint64)(x.Ui64slicearray), e) } // end block: if x.Ui64slicearray slice == nil } else { r.EncodeNil() } z.EncWriteArrayElem() if yyq2[75] { if x.SintfAarray == nil { r.EncodeNil() } else { z.F.EncSliceIntfV(x.SintfAarray, e) } // end block: if x.SintfAarray slice == nil } else { r.EncodeNil() } z.EncWriteArrayElem() if yyq2[76] { if x.MstrUi64TSelf == nil { r.EncodeNil() } else { h.encMapstringUint64TPtrtostringUint64T((map[stringUint64T]*stringUint64T)(x.MstrUi64TSelf), e) } // end block: if x.MstrUi64TSelf map == nil } else { r.EncodeNil() } z.EncWriteArrayElem() if yyq2[77] { if z.EncBasicHandle().TimeBuiltin() { r.EncodeTime(x.Ttime) } else if yyxt183 := z.Extension(x.Ttime); yyxt183 != nil { z.EncExtension(x.Ttime, yyxt183) } else if z.EncBinary() { z.EncBinaryMarshal(x.Ttime) } else if !z.EncBinary() && z.IsJSONHandle() { z.EncJSONMarshal(x.Ttime) } else { z.EncFallback(x.Ttime) } } else { r.EncodeNil() } if yyn81 { z.EncWriteArrayElem() r.EncodeNil() } else { z.EncWriteArrayElem() if yyq2[78] { yy184 := *x.Ttimeptr if z.EncBasicHandle().TimeBuiltin() { r.EncodeTime(yy184) } else if yyxt185 := z.Extension(yy184); yyxt185 != nil { z.EncExtension(yy184, yyxt185) } else if z.EncBinary() { z.EncBinaryMarshal(yy184) } else if !z.EncBinary() && z.IsJSONHandle() { z.EncJSONMarshal(yy184) } else { z.EncFallback(yy184) } } else { r.EncodeNil() } } if yyn82 { z.EncWriteArrayElem() r.EncodeNil() } else { z.EncWriteArrayElem() if yyq2[79] { if x.AnonInTestStrucIntf.Islice == nil { r.EncodeNil() } else { z.F.EncSliceIntfV(x.AnonInTestStrucIntf.Islice, e) } // end block: if x.AnonInTestStrucIntf.Islice slice == nil } else { r.EncodeNil() } } if yyn83 { z.EncWriteArrayElem() r.EncodeNil() } else { z.EncWriteArrayElem() if yyq2[80] { if x.AnonInTestStrucIntf.Ms == nil { r.EncodeNil() } else { z.F.EncMapStringIntfV(x.AnonInTestStrucIntf.Ms, e) } // end block: if x.AnonInTestStrucIntf.Ms map == nil } else { r.EncodeNil() } } if yyn84 { z.EncWriteArrayElem() r.EncodeNil() } else { z.EncWriteArrayElem() if yyq2[81] { z.EncFallback(x.AnonInTestStrucIntf.Nintf) } else { r.EncodeNil() } } if yyn85 { z.EncWriteArrayElem() r.EncodeNil() } else { z.EncWriteArrayElem() if yyq2[82] { if z.EncBasicHandle().TimeBuiltin() { r.EncodeTime(x.AnonInTestStrucIntf.T) } else if yyxt189 := z.Extension(x.AnonInTestStrucIntf.T); yyxt189 != nil { z.EncExtension(x.AnonInTestStrucIntf.T, yyxt189) } else if z.EncBinary() { z.EncBinaryMarshal(x.AnonInTestStrucIntf.T) } else if !z.EncBinary() && z.IsJSONHandle() { z.EncJSONMarshal(x.AnonInTestStrucIntf.T) } else { z.EncFallback(x.AnonInTestStrucIntf.T) } } else { r.EncodeNil() } } if yyn86 { z.EncWriteArrayElem() r.EncodeNil() } else { z.EncWriteArrayElem() if yyq2[83] { yy190 := *x.AnonInTestStrucIntf.Tptr if z.EncBasicHandle().TimeBuiltin() { r.EncodeTime(yy190) } else if yyxt191 := z.Extension(yy190); yyxt191 != nil { z.EncExtension(yy190, yyxt191) } else if z.EncBinary() { z.EncBinaryMarshal(yy190) } else if !z.EncBinary() && z.IsJSONHandle() { z.EncJSONMarshal(yy190) } else { z.EncFallback(yy190) } } else { r.EncodeNil() } } z.EncWriteArrayElem() if yyq2[84] { if x.Msu == nil { r.EncodeNil() } else { h.encMapwrapStringInterface((map[wrapString]interface{})(x.Msu), e) } // end block: if x.Msu map == nil } else { r.EncodeNil() } z.EncWriteArrayElem() if yyq2[85] { if x.Mtsptr == nil { r.EncodeNil() } else { h.encMapstringPtrtoTestStrucFlex((map[string]*TestStrucFlex)(x.Mtsptr), e) } // end block: if x.Mtsptr map == nil } else { r.EncodeNil() } z.EncWriteArrayElem() if yyq2[86] { if x.Mts == nil { r.EncodeNil() } else { h.encMapstringTestStrucFlex((map[string]TestStrucFlex)(x.Mts), e) } // end block: if x.Mts map == nil } else { r.EncodeNil() } z.EncWriteArrayElem() if yyq2[87] { if x.Its == nil { r.EncodeNil() } else { h.encSlicePtrtoTestStrucFlex(([]*TestStrucFlex)(x.Its), e) } // end block: if x.Its slice == nil } else { r.EncodeNil() } if yyn91 { z.EncWriteArrayElem() r.EncodeNil() } else { z.EncWriteArrayElem() if yyq2[88] { if yyxt196 := z.Extension(x.Nteststruc); yyxt196 != nil { z.EncExtension(x.Nteststruc, yyxt196) } else { x.Nteststruc.CodecEncodeSelf(e) } } else { r.EncodeNil() } } z.EncWriteArrayElem() if yyq2[89] { if yyxt197 := z.Extension(x.MarJ); yyxt197 != nil { z.EncExtension(x.MarJ, yyxt197) } else { x.MarJ.CodecEncodeSelf(e) } } else { r.EncodeBool(false) } z.EncWriteArrayElem() if yyq2[90] { if yyxt198 := z.Extension(x.MarT); yyxt198 != nil { z.EncExtension(x.MarT, yyxt198) } else { x.MarT.CodecEncodeSelf(e) } } else { r.EncodeString("") } z.EncWriteArrayElem() if yyq2[91] { if yyxt199 := z.Extension(x.MarB); yyxt199 != nil { z.EncExtension(x.MarB, yyxt199) } else { x.MarB.CodecEncodeSelf(e) } } else { r.EncodeNil() } z.EncWriteArrayElem() if yyq2[92] { if yyxt200 := z.Extension(x.XuintToBytes); yyxt200 != nil { z.EncExtension(x.XuintToBytes, yyxt200) } else { x.XuintToBytes.CodecEncodeSelf(e) } } else { r.EncodeUint(0) } z.EncWriteArrayElem() if yyq2[93] { z.EncEncodeComplex64(complex64(x.Cmplx64)) } else { z.EncEncodeComplex64(0) } z.EncWriteArrayElem() if yyq2[94] { z.EncEncodeComplex128(complex128(x.Cmplx128)) } else { z.EncEncodeComplex128(0) } z.EncWriteArrayEnd() } else { var yynn2 int for _, b := range yyq2 { if b { yynn2++ } } z.EncWriteMapStart(yynn2) yynn2 = 0 if z.EncBasicHandle().Canonical { if yyq2[41] { z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"AF32slice\"") } else { r.EncodeString(`AF32slice`) } z.EncWriteMapElemValue() if x.TestStrucCommon.AnonInTestStruc.AF32slice == nil { r.EncodeNil() } else { z.F.EncSliceFloat32V(x.TestStrucCommon.AnonInTestStruc.AF32slice, e) } // end block: if x.TestStrucCommon.AnonInTestStruc.AF32slice slice == nil } if yyq2[40] { z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"AF64slice\"") } else { r.EncodeString(`AF64slice`) } z.EncWriteMapElemValue() if x.TestStrucCommon.AnonInTestStruc.AF64slice == nil { r.EncodeNil() } else { z.F.EncSliceFloat64V(x.TestStrucCommon.AnonInTestStruc.AF64slice, e) } // end block: if x.TestStrucCommon.AnonInTestStruc.AF64slice slice == nil } if yyq2[35] { z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"AI16\"") } else { r.EncodeString(`AI16`) } z.EncWriteMapElemValue() r.EncodeInt(int64(x.TestStrucCommon.AnonInTestStruc.AI16)) } if yyq2[34] { z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"AI64\"") } else { r.EncodeString(`AI64`) } z.EncWriteMapElemValue() r.EncodeInt(int64(x.TestStrucCommon.AnonInTestStruc.AI64)) } if yyq2[45] { z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"AI64arr0\"") } else { r.EncodeString(`AI64arr0`) } z.EncWriteMapElemValue() yy207 := &x.TestStrucCommon.AnonInTestStruc.AI64arr0 h.encArray0int64((*[0]int64)(yy207), e) } if yyq2[44] { z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"AI64arr8\"") } else { r.EncodeString(`AI64arr8`) } z.EncWriteMapElemValue() yy209 := &x.TestStrucCommon.AnonInTestStruc.AI64arr8 h.encArray8int64((*[8]int64)(yy209), e) } if yyq2[38] { z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"AI64slice\"") } else { r.EncodeString(`AI64slice`) } z.EncWriteMapElemValue() if x.TestStrucCommon.AnonInTestStruc.AI64slice == nil { r.EncodeNil() } else { z.F.EncSliceInt64V(x.TestStrucCommon.AnonInTestStruc.AI64slice, e) } // end block: if x.TestStrucCommon.AnonInTestStruc.AI64slice slice == nil } if yyq2[46] { z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"AI64slice0\"") } else { r.EncodeString(`AI64slice0`) } z.EncWriteMapElemValue() if x.TestStrucCommon.AnonInTestStruc.AI64slice0 == nil { r.EncodeNil() } else { z.F.EncSliceInt64V(x.TestStrucCommon.AnonInTestStruc.AI64slice0, e) } // end block: if x.TestStrucCommon.AnonInTestStruc.AI64slice0 slice == nil } if yyq2[42] { z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"AMSS\"") } else { r.EncodeString(`AMSS`) } z.EncWriteMapElemValue() if x.TestStrucCommon.AnonInTestStruc.AMSS == nil { r.EncodeNil() } else { z.F.EncMapStringStringV(x.TestStrucCommon.AnonInTestStruc.AMSS, e) } // end block: if x.TestStrucCommon.AnonInTestStruc.AMSS map == nil } if yyq2[43] { z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"AMSU64\"") } else { r.EncodeString(`AMSU64`) } z.EncWriteMapElemValue() if x.TestStrucCommon.AnonInTestStruc.AMSU64 == nil { r.EncodeNil() } else { z.F.EncMapStringUint64V(x.TestStrucCommon.AnonInTestStruc.AMSU64, e) } // end block: if x.TestStrucCommon.AnonInTestStruc.AMSU64 map == nil } if yyq2[49] { z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"AMSU64E\"") } else { r.EncodeString(`AMSU64E`) } z.EncWriteMapElemValue() if x.TestStrucCommon.AnonInTestStruc.AMSU64E == nil { r.EncodeNil() } else { z.F.EncMapStringUint64V(x.TestStrucCommon.AnonInTestStruc.AMSU64E, e) } // end block: if x.TestStrucCommon.AnonInTestStruc.AMSU64E map == nil } if yyq2[48] { z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"AMSU64N\"") } else { r.EncodeString(`AMSU64N`) } z.EncWriteMapElemValue() if x.TestStrucCommon.AnonInTestStruc.AMSU64N == nil { r.EncodeNil() } else { z.F.EncMapStringUint64V(x.TestStrucCommon.AnonInTestStruc.AMSU64N, e) } // end block: if x.TestStrucCommon.AnonInTestStruc.AMSU64N map == nil } if yyq2[33] { z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"AS\"") } else { r.EncodeString(`AS`) } z.EncWriteMapElemValue() r.EncodeString(string(x.TestStrucCommon.AnonInTestStruc.AS)) } if yyq2[37] { z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"ASslice\"") } else { r.EncodeString(`ASslice`) } z.EncWriteMapElemValue() if x.TestStrucCommon.AnonInTestStruc.ASslice == nil { r.EncodeNil() } else { z.F.EncSliceStringV(x.TestStrucCommon.AnonInTestStruc.ASslice, e) } // end block: if x.TestStrucCommon.AnonInTestStruc.ASslice slice == nil } if yyq2[36] { z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"AUi64\"") } else { r.EncodeString(`AUi64`) } z.EncWriteMapElemValue() r.EncodeUint(uint64(x.TestStrucCommon.AnonInTestStruc.AUi64)) } if yyq2[39] { z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"AUi64slice\"") } else { r.EncodeString(`AUi64slice`) } z.EncWriteMapElemValue() if x.TestStrucCommon.AnonInTestStruc.AUi64slice == nil { r.EncodeNil() } else { z.F.EncSliceUint64V(x.TestStrucCommon.AnonInTestStruc.AUi64slice, e) } // end block: if x.TestStrucCommon.AnonInTestStruc.AUi64slice slice == nil } if yyq2[47] { z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"AUi64sliceN\"") } else { r.EncodeString(`AUi64sliceN`) } z.EncWriteMapElemValue() if x.TestStrucCommon.AnonInTestStruc.AUi64sliceN == nil { r.EncodeNil() } else { z.F.EncSliceUint64V(x.TestStrucCommon.AnonInTestStruc.AUi64sliceN, e) } // end block: if x.TestStrucCommon.AnonInTestStruc.AUi64sliceN slice == nil } if yyq2[72] { z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"ArrStrUi64T\"") } else { r.EncodeString(`ArrStrUi64T`) } z.EncWriteMapElemValue() yy222 := &x.ArrStrUi64T h.encArray4stringUint64T((*[4]stringUint64T)(yy222), e) } if yyq2[15] { z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"B\"") } else { r.EncodeString(`B`) } z.EncWriteMapElemValue() r.EncodeBool(bool(x.TestStrucCommon.B)) } if yyq2[22] { z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"Bslice\"") } else { r.EncodeString(`Bslice`) } z.EncWriteMapElemValue() if x.TestStrucCommon.Bslice == nil { r.EncodeNil() } else { z.F.EncSliceBoolV(x.TestStrucCommon.Bslice, e) } // end block: if x.TestStrucCommon.Bslice slice == nil } if yyq2[16] { z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"By\"") } else { r.EncodeString(`By`) } z.EncWriteMapElemValue() r.EncodeUint(uint64(x.TestStrucCommon.By)) } if yyq2[23] { z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"Byslice\"") } else { r.EncodeString(`Byslice`) } z.EncWriteMapElemValue() if x.TestStrucCommon.Byslice == nil { r.EncodeNil() } else { r.EncodeStringBytesRaw([]byte(x.TestStrucCommon.Byslice)) } // end block: if x.TestStrucCommon.Byslice slice == nil } if yyq2[24] { z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"BytesSlice\"") } else { r.EncodeString(`BytesSlice`) } z.EncWriteMapElemValue() if x.TestStrucCommon.BytesSlice == nil { r.EncodeNil() } else { z.F.EncSliceBytesV(x.TestStrucCommon.BytesSlice, e) } // end block: if x.TestStrucCommon.BytesSlice slice == nil } if yyq2[56] { z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"Chstr\"") } else { r.EncodeString(`Chstr`) } z.EncWriteMapElemValue() h.encChanstring((chan string)(x.Chstr), e) } if yyq2[69] { z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"Ci64\"") } else { r.EncodeString(`Ci64`) } z.EncWriteMapElemValue() if yyxt230 := z.Extension(x.Ci64); yyxt230 != nil { z.EncExtension(x.Ci64, yyxt230) } else { x.Ci64.CodecEncodeSelf(e) } } if yyq2[94] { z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"Cmplx128\"") } else { r.EncodeString(`Cmplx128`) } z.EncWriteMapElemValue() z.EncEncodeComplex128(complex128(x.Cmplx128)) } if yyq2[93] { z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"Cmplx64\"") } else { r.EncodeString(`Cmplx64`) } z.EncWriteMapElemValue() z.EncEncodeComplex64(complex64(x.Cmplx64)) } if yyq2[14] { z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"F32\"") } else { r.EncodeString(`F32`) } z.EncWriteMapElemValue() r.EncodeFloat32(float32(x.TestStrucCommon.F32)) } if yyq2[13] { z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"F64\"") } else { r.EncodeString(`F64`) } z.EncWriteMapElemValue() r.EncodeFloat64(float64(x.TestStrucCommon.F64)) } if yyq2[3] { z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"I16\"") } else { r.EncodeString(`I16`) } z.EncWriteMapElemValue() r.EncodeInt(int64(x.TestStrucCommon.I16)) } if yyq2[7] { z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"I16n\"") } else { r.EncodeString(`I16n`) } z.EncWriteMapElemValue() r.EncodeInt(int64(x.TestStrucCommon.I16n)) } if yyq2[2] { z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"I32\"") } else { r.EncodeString(`I32`) } z.EncWriteMapElemValue() r.EncodeInt(int64(x.TestStrucCommon.I32)) } if yyq2[6] { z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"I32n\"") } else { r.EncodeString(`I32n`) } z.EncWriteMapElemValue() r.EncodeInt(int64(x.TestStrucCommon.I32n)) } if yyq2[19] { z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"I32slice\"") } else { r.EncodeString(`I32slice`) } z.EncWriteMapElemValue() if x.TestStrucCommon.I32slice == nil { r.EncodeNil() } else { z.F.EncSliceInt32V(x.TestStrucCommon.I32slice, e) } // end block: if x.TestStrucCommon.I32slice slice == nil } if yyq2[1] { z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"I64\"") } else { r.EncodeString(`I64`) } z.EncWriteMapElemValue() r.EncodeInt(int64(x.TestStrucCommon.I64)) } if yyq2[5] { z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"I64n\"") } else { r.EncodeString(`I64n`) } z.EncWriteMapElemValue() r.EncodeInt(int64(x.TestStrucCommon.I64n)) } if yyq2[18] { z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"I64slice\"") } else { r.EncodeString(`I64slice`) } z.EncWriteMapElemValue() if x.TestStrucCommon.I64slice == nil { r.EncodeNil() } else { z.F.EncSliceInt64V(x.TestStrucCommon.I64slice, e) } // end block: if x.TestStrucCommon.I64slice slice == nil } if yyq2[4] { z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"I8\"") } else { r.EncodeString(`I8`) } z.EncWriteMapElemValue() r.EncodeInt(int64(x.TestStrucCommon.I8)) } if yyq2[8] { z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"I8n\"") } else { r.EncodeString(`I8n`) } z.EncWriteMapElemValue() r.EncodeInt(int64(x.TestStrucCommon.I8n)) } if yyq2[25] { z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"Iptrslice\"") } else { r.EncodeString(`Iptrslice`) } z.EncWriteMapElemValue() if x.TestStrucCommon.Iptrslice == nil { r.EncodeNil() } else { h.encSlicePtrtoint64(([]*int64)(x.TestStrucCommon.Iptrslice), e) } // end block: if x.TestStrucCommon.Iptrslice slice == nil } if yyq2[79] { z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"Islice\"") } else { r.EncodeString(`Islice`) } z.EncWriteMapElemValue() if yyn82 { r.EncodeNil() } else { if x.AnonInTestStrucIntf.Islice == nil { r.EncodeNil() } else { z.F.EncSliceIntfV(x.AnonInTestStrucIntf.Islice, e) } // end block: if x.AnonInTestStrucIntf.Islice slice == nil } } if yyq2[87] { z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"Its\"") } else { r.EncodeString(`Its`) } z.EncWriteMapElemValue() if x.Its == nil { r.EncodeNil() } else { h.encSlicePtrtoTestStrucFlex(([]*TestStrucFlex)(x.Its), e) } // end block: if x.Its slice == nil } if yyq2[91] { z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"MarB\"") } else { r.EncodeString(`MarB`) } z.EncWriteMapElemValue() if yyxt248 := z.Extension(x.MarB); yyxt248 != nil { z.EncExtension(x.MarB, yyxt248) } else { x.MarB.CodecEncodeSelf(e) } } if yyq2[89] { z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"MarJ\"") } else { r.EncodeString(`MarJ`) } z.EncWriteMapElemValue() if yyxt249 := z.Extension(x.MarJ); yyxt249 != nil { z.EncExtension(x.MarJ, yyxt249) } else { x.MarJ.CodecEncodeSelf(e) } } if yyq2[90] { z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"MarT\"") } else { r.EncodeString(`MarT`) } z.EncWriteMapElemValue() if yyxt250 := z.Extension(x.MarT); yyxt250 != nil { z.EncExtension(x.MarT, yyxt250) } else { x.MarT.CodecEncodeSelf(e) } } if yyq2[58] { z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"Mbu64\"") } else { r.EncodeString(`Mbu64`) } z.EncWriteMapElemValue() if x.Mbu64 == nil { r.EncodeNil() } else { h.encMapboolc3RydWN0IHt9((map[bool]struct{})(x.Mbu64), e) } // end block: if x.Mbu64 map == nil } if yyq2[66] { z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"Mf32wss\"") } else { r.EncodeString(`Mf32wss`) } z.EncWriteMapElemValue() if x.Mf32wss == nil { r.EncodeNil() } else { h.encMapfloat32wrapStringSlice((map[float32]wrapStringSlice)(x.Mf32wss), e) } // end block: if x.Mf32wss map == nil } if yyq2[65] { z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"Mfwss\"") } else { r.EncodeString(`Mfwss`) } z.EncWriteMapElemValue() if x.Mfwss == nil { r.EncodeNil() } else { h.encMapfloat64wrapStringSlice((map[float64]wrapStringSlice)(x.Mfwss), e) } // end block: if x.Mfwss map == nil } if yyq2[62] { z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"Mip2ss\"") } else { r.EncodeString(`Mip2ss`) } z.EncWriteMapElemValue() if x.Mip2ss == nil { r.EncodeNil() } else { h.encMapPtrtouint64Slicestring((map[*uint64][]string)(x.Mip2ss), e) } // end block: if x.Mip2ss map == nil } if yyq2[57] { z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"Mis\"") } else { r.EncodeString(`Mis`) } z.EncWriteMapElemValue() if x.Mis == nil { r.EncodeNil() } else { z.F.EncMapIntStringV(x.Mis, e) } // end block: if x.Mis map == nil } if yyq2[64] { z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"Miwu64s\"") } else { r.EncodeString(`Miwu64s`) } z.EncWriteMapElemValue() if x.Miwu64s == nil { r.EncodeNil() } else { h.encMapintwrapUint64Slice((map[int]wrapUint64Slice)(x.Miwu64s), e) } // end block: if x.Miwu64s map == nil } if yyq2[80] { z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"Ms\"") } else { r.EncodeString(`Ms`) } z.EncWriteMapElemValue() if yyn83 { r.EncodeNil() } else { if x.AnonInTestStrucIntf.Ms == nil { r.EncodeNil() } else { z.F.EncMapStringIntfV(x.AnonInTestStrucIntf.Ms, e) } // end block: if x.AnonInTestStrucIntf.Ms map == nil } } if yyq2[63] { z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"Ms2misu\"") } else { r.EncodeString(`Ms2misu`) } z.EncWriteMapElemValue() if x.Ms2misu == nil { r.EncodeNil() } else { h.encMapstringMapuint64stringUint64T((map[string]map[uint64]stringUint64T)(x.Ms2misu), e) } // end block: if x.Ms2misu map == nil } if yyq2[29] { z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"Msbytes\"") } else { r.EncodeString(`Msbytes`) } z.EncWriteMapElemValue() if x.TestStrucCommon.Msbytes == nil { r.EncodeNil() } else { z.F.EncMapStringBytesV(x.TestStrucCommon.Msbytes, e) } // end block: if x.TestStrucCommon.Msbytes map == nil } if yyq2[28] { z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"Msint\"") } else { r.EncodeString(`Msint`) } z.EncWriteMapElemValue() if x.TestStrucCommon.Msint == nil { r.EncodeNil() } else { z.F.EncMapStringIntV(x.TestStrucCommon.Msint, e) } // end block: if x.TestStrucCommon.Msint map == nil } if yyq2[61] { z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"Msp2ss\"") } else { r.EncodeString(`Msp2ss`) } z.EncWriteMapElemValue() if x.Msp2ss == nil { r.EncodeNil() } else { h.encMapPtrtostringSlicestring((map[*string][]string)(x.Msp2ss), e) } // end block: if x.Msp2ss map == nil } if yyq2[32] { z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"MstrUi64T\"") } else { r.EncodeString(`MstrUi64T`) } z.EncWriteMapElemValue() if x.TestStrucCommon.MstrUi64T == nil { r.EncodeNil() } else { h.encMapstringPtrtostringUint64T((map[string]*stringUint64T)(x.TestStrucCommon.MstrUi64T), e) } // end block: if x.TestStrucCommon.MstrUi64T map == nil } if yyq2[76] { z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"MstrUi64TSelf\"") } else { r.EncodeString(`MstrUi64TSelf`) } z.EncWriteMapElemValue() if x.MstrUi64TSelf == nil { r.EncodeNil() } else { h.encMapstringUint64TPtrtostringUint64T((map[stringUint64T]*stringUint64T)(x.MstrUi64TSelf), e) } // end block: if x.MstrUi64TSelf map == nil } if yyq2[84] { z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"Msu\"") } else { r.EncodeString(`Msu`) } z.EncWriteMapElemValue() if x.Msu == nil { r.EncodeNil() } else { h.encMapwrapStringInterface((map[wrapString]interface{})(x.Msu), e) } // end block: if x.Msu map == nil } if yyq2[68] { z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"Msu2wss\"") } else { r.EncodeString(`Msu2wss`) } z.EncWriteMapElemValue() if x.Msu2wss == nil { r.EncodeNil() } else { h.encMapstringUint64TwrapStringSlice((map[stringUint64T]wrapStringSlice)(x.Msu2wss), e) } // end block: if x.Msu2wss map == nil } if yyq2[86] { z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"Mts\"") } else { r.EncodeString(`Mts`) } z.EncWriteMapElemValue() if x.Mts == nil { r.EncodeNil() } else { h.encMapstringTestStrucFlex((map[string]TestStrucFlex)(x.Mts), e) } // end block: if x.Mts map == nil } if yyq2[85] { z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"Mtsptr\"") } else { r.EncodeString(`Mtsptr`) } z.EncWriteMapElemValue() if x.Mtsptr == nil { r.EncodeNil() } else { h.encMapstringPtrtoTestStrucFlex((map[string]*TestStrucFlex)(x.Mtsptr), e) } // end block: if x.Mtsptr map == nil } if yyq2[59] { z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"Mu8e\"") } else { r.EncodeString(`Mu8e`) } z.EncWriteMapElemValue() if x.Mu8e == nil { r.EncodeNil() } else { h.encMapuint8c3RydWN0IHt9((map[uint8]struct{})(x.Mu8e), e) } // end block: if x.Mu8e map == nil } if yyq2[60] { z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"Mu8u64\"") } else { r.EncodeString(`Mu8u64`) } z.EncWriteMapElemValue() if x.Mu8u64 == nil { r.EncodeNil() } else { h.encMapuint8stringUint64T((map[uint8]stringUint64T)(x.Mu8u64), e) } // end block: if x.Mu8u64 map == nil } if yyq2[67] { z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"Mui2wss\"") } else { r.EncodeString(`Mui2wss`) } z.EncWriteMapElemValue() if x.Mui2wss == nil { r.EncodeNil() } else { h.encMapuint64wrapStringSlice((map[uint64]wrapStringSlice)(x.Mui2wss), e) } // end block: if x.Mui2wss map == nil } if yyq2[55] { z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"Nint64\"") } else { r.EncodeString(`Nint64`) } z.EncWriteMapElemValue() if yyn58 { r.EncodeNil() } else { yy271 := *x.TestStrucCommon.Nint64 r.EncodeInt(int64(yy271)) } } if yyq2[81] { z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"Nintf\"") } else { r.EncodeString(`Nintf`) } z.EncWriteMapElemValue() if yyn84 { r.EncodeNil() } else { z.EncFallback(x.AnonInTestStrucIntf.Nintf) } } if yyq2[53] { z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"Nmap\"") } else { r.EncodeString(`Nmap`) } z.EncWriteMapElemValue() if x.TestStrucCommon.Nmap == nil { r.EncodeNil() } else { z.F.EncMapStringBoolV(x.TestStrucCommon.Nmap, e) } // end block: if x.TestStrucCommon.Nmap map == nil } if yyq2[50] { z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"NotAnon\"") } else { r.EncodeString(`NotAnon`) } z.EncWriteMapElemValue() yy275 := &x.TestStrucCommon.NotAnon if yyxt276 := z.Extension(yy275); yyxt276 != nil { z.EncExtension(yy275, yyxt276) } else { yy275.CodecEncodeSelf(e) } } if yyq2[52] { z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"NotAnonSlim\"") } else { r.EncodeString(`NotAnonSlim`) } z.EncWriteMapElemValue() if yyn55 { r.EncodeNil() } else { if yyxt277 := z.Extension(x.TestStrucCommon.NotAnonSlim); yyxt277 != nil { z.EncExtension(x.TestStrucCommon.NotAnonSlim, yyxt277) } else { x.TestStrucCommon.NotAnonSlim.CodecEncodeSelf(e) } } } if yyq2[54] { z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"Nslice\"") } else { r.EncodeString(`Nslice`) } z.EncWriteMapElemValue() if x.TestStrucCommon.Nslice == nil { r.EncodeNil() } else { r.EncodeStringBytesRaw([]byte(x.TestStrucCommon.Nslice)) } // end block: if x.TestStrucCommon.Nslice slice == nil } if yyq2[88] { z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"Nteststruc\"") } else { r.EncodeString(`Nteststruc`) } z.EncWriteMapElemValue() if yyn91 { r.EncodeNil() } else { if yyxt279 := z.Extension(x.Nteststruc); yyxt279 != nil { z.EncExtension(x.Nteststruc, yyxt279) } else { x.Nteststruc.CodecEncodeSelf(e) } } } if yyq2[51] { z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"P\"") } else { r.EncodeString(`P`) } z.EncWriteMapElemValue() if yyn54 { r.EncodeNil() } else { yy280 := *x.TestStrucCommon.AnonInTestStrucSlim.P r.EncodeString(string(yy280)) } } if yyq2[0] { z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"S\"") } else { r.EncodeString(`S`) } z.EncWriteMapElemValue() r.EncodeString(string(x.TestStrucCommon.S)) } if yyq2[30] { z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"Simplef\"") } else { r.EncodeString(`Simplef`) } z.EncWriteMapElemValue() yy283 := &x.TestStrucCommon.Simplef if yyxt284 := z.Extension(yy283); yyxt284 != nil { z.EncExtension(yy283, yyxt284) } else { yy283.CodecEncodeSelf(e) } } if yyq2[75] { z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"SintfAarray\"") } else { r.EncodeString(`SintfAarray`) } z.EncWriteMapElemValue() if x.SintfAarray == nil { r.EncodeNil() } else { z.F.EncSliceIntfV(x.SintfAarray, e) } // end block: if x.SintfAarray slice == nil } if yyq2[17] { z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"Sslice\"") } else { r.EncodeString(`Sslice`) } z.EncWriteMapElemValue() if x.TestStrucCommon.Sslice == nil { r.EncodeNil() } else { z.F.EncSliceStringV(x.TestStrucCommon.Sslice, e) } // end block: if x.TestStrucCommon.Sslice slice == nil } if yyq2[31] { z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"SstrUi64T\"") } else { r.EncodeString(`SstrUi64T`) } z.EncWriteMapElemValue() if x.TestStrucCommon.SstrUi64T == nil { r.EncodeNil() } else { h.encSlicestringUint64T(([]stringUint64T)(x.TestStrucCommon.SstrUi64T), e) } // end block: if x.TestStrucCommon.SstrUi64T slice == nil } if yyq2[70] { z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"Swrapbytes\"") } else { r.EncodeString(`Swrapbytes`) } z.EncWriteMapElemValue() if x.Swrapbytes == nil { r.EncodeNil() } else { h.encSlicewrapBytes(([]wrapBytes)(x.Swrapbytes), e) } // end block: if x.Swrapbytes slice == nil } if yyq2[71] { z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"Swrapuint8\"") } else { r.EncodeString(`Swrapuint8`) } z.EncWriteMapElemValue() if x.Swrapuint8 == nil { r.EncodeNil() } else { h.encSlicewrapUint8(([]wrapUint8)(x.Swrapuint8), e) } // end block: if x.Swrapuint8 slice == nil } if yyq2[82] { z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"T\"") } else { r.EncodeString(`T`) } z.EncWriteMapElemValue() if yyn85 { r.EncodeNil() } else { if z.EncBasicHandle().TimeBuiltin() { r.EncodeTime(x.AnonInTestStrucIntf.T) } else if yyxt290 := z.Extension(x.AnonInTestStrucIntf.T); yyxt290 != nil { z.EncExtension(x.AnonInTestStrucIntf.T, yyxt290) } else if z.EncBinary() { z.EncBinaryMarshal(x.AnonInTestStrucIntf.T) } else if !z.EncBinary() && z.IsJSONHandle() { z.EncJSONMarshal(x.AnonInTestStrucIntf.T) } else { z.EncFallback(x.AnonInTestStrucIntf.T) } } } if yyq2[83] { z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"Tptr\"") } else { r.EncodeString(`Tptr`) } z.EncWriteMapElemValue() if yyn86 { r.EncodeNil() } else { yy291 := *x.AnonInTestStrucIntf.Tptr if z.EncBasicHandle().TimeBuiltin() { r.EncodeTime(yy291) } else if yyxt292 := z.Extension(yy291); yyxt292 != nil { z.EncExtension(yy291, yyxt292) } else if z.EncBinary() { z.EncBinaryMarshal(yy291) } else if !z.EncBinary() && z.IsJSONHandle() { z.EncJSONMarshal(yy291) } else { z.EncFallback(yy291) } } } if yyq2[77] { z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"Ttime\"") } else { r.EncodeString(`Ttime`) } z.EncWriteMapElemValue() if z.EncBasicHandle().TimeBuiltin() { r.EncodeTime(x.Ttime) } else if yyxt293 := z.Extension(x.Ttime); yyxt293 != nil { z.EncExtension(x.Ttime, yyxt293) } else if z.EncBinary() { z.EncBinaryMarshal(x.Ttime) } else if !z.EncBinary() && z.IsJSONHandle() { z.EncJSONMarshal(x.Ttime) } else { z.EncFallback(x.Ttime) } } if yyq2[78] { z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"Ttimeptr\"") } else { r.EncodeString(`Ttimeptr`) } z.EncWriteMapElemValue() if yyn81 { r.EncodeNil() } else { yy294 := *x.Ttimeptr if z.EncBasicHandle().TimeBuiltin() { r.EncodeTime(yy294) } else if yyxt295 := z.Extension(yy294); yyxt295 != nil { z.EncExtension(yy294, yyxt295) } else if z.EncBinary() { z.EncBinaryMarshal(yy294) } else if !z.EncBinary() && z.IsJSONHandle() { z.EncJSONMarshal(yy294) } else { z.EncFallback(yy294) } } } if yyq2[11] { z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"Ui16\"") } else { r.EncodeString(`Ui16`) } z.EncWriteMapElemValue() r.EncodeUint(uint64(x.TestStrucCommon.Ui16)) } if yyq2[10] { z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"Ui32\"") } else { r.EncodeString(`Ui32`) } z.EncWriteMapElemValue() r.EncodeUint(uint64(x.TestStrucCommon.Ui32)) } if yyq2[9] { z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"Ui64\"") } else { r.EncodeString(`Ui64`) } z.EncWriteMapElemValue() r.EncodeUint(uint64(x.TestStrucCommon.Ui64)) } if yyq2[73] { z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"Ui64array\"") } else { r.EncodeString(`Ui64array`) } z.EncWriteMapElemValue() yy299 := &x.Ui64array h.encArray4uint64((*[4]uint64)(yy299), e) } if yyq2[20] { z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"Ui64slice\"") } else { r.EncodeString(`Ui64slice`) } z.EncWriteMapElemValue() if x.TestStrucCommon.Ui64slice == nil { r.EncodeNil() } else { z.F.EncSliceUint64V(x.TestStrucCommon.Ui64slice, e) } // end block: if x.TestStrucCommon.Ui64slice slice == nil } if yyq2[74] { z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"Ui64slicearray\"") } else { r.EncodeString(`Ui64slicearray`) } z.EncWriteMapElemValue() if x.Ui64slicearray == nil { r.EncodeNil() } else { h.encSlicePtrtoArray4uint64(([]*[4]uint64)(x.Ui64slicearray), e) } // end block: if x.Ui64slicearray slice == nil } if yyq2[12] { z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"Ui8\"") } else { r.EncodeString(`Ui8`) } z.EncWriteMapElemValue() r.EncodeUint(uint64(x.TestStrucCommon.Ui8)) } if yyq2[21] { z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"Ui8slice\"") } else { r.EncodeString(`Ui8slice`) } z.EncWriteMapElemValue() if x.TestStrucCommon.Ui8slice == nil { r.EncodeNil() } else { r.EncodeStringBytesRaw([]byte(x.TestStrucCommon.Ui8slice)) } // end block: if x.TestStrucCommon.Ui8slice slice == nil } if yyq2[26] { z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"WrapSliceInt64\"") } else { r.EncodeString(`WrapSliceInt64`) } z.EncWriteMapElemValue() if yyxt305 := z.Extension(x.TestStrucCommon.WrapSliceInt64); yyxt305 != nil { z.EncExtension(x.TestStrucCommon.WrapSliceInt64, yyxt305) } else { x.TestStrucCommon.WrapSliceInt64.CodecEncodeSelf(e) } } if yyq2[27] { z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"WrapSliceString\"") } else { r.EncodeString(`WrapSliceString`) } z.EncWriteMapElemValue() if yyxt306 := z.Extension(x.TestStrucCommon.WrapSliceString); yyxt306 != nil { z.EncExtension(x.TestStrucCommon.WrapSliceString, yyxt306) } else { x.TestStrucCommon.WrapSliceString.CodecEncodeSelf(e) } } if yyq2[92] { z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"XuintToBytes\"") } else { r.EncodeString(`XuintToBytes`) } z.EncWriteMapElemValue() if yyxt307 := z.Extension(x.XuintToBytes); yyxt307 != nil { z.EncExtension(x.XuintToBytes, yyxt307) } else { x.XuintToBytes.CodecEncodeSelf(e) } } } else { if yyq2[0] { z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"S\"") } else { r.EncodeString(`S`) } z.EncWriteMapElemValue() r.EncodeString(string(x.TestStrucCommon.S)) } if yyq2[1] { z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"I64\"") } else { r.EncodeString(`I64`) } z.EncWriteMapElemValue() r.EncodeInt(int64(x.TestStrucCommon.I64)) } if yyq2[2] { z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"I32\"") } else { r.EncodeString(`I32`) } z.EncWriteMapElemValue() r.EncodeInt(int64(x.TestStrucCommon.I32)) } if yyq2[3] { z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"I16\"") } else { r.EncodeString(`I16`) } z.EncWriteMapElemValue() r.EncodeInt(int64(x.TestStrucCommon.I16)) } if yyq2[4] { z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"I8\"") } else { r.EncodeString(`I8`) } z.EncWriteMapElemValue() r.EncodeInt(int64(x.TestStrucCommon.I8)) } if yyq2[5] { z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"I64n\"") } else { r.EncodeString(`I64n`) } z.EncWriteMapElemValue() r.EncodeInt(int64(x.TestStrucCommon.I64n)) } if yyq2[6] { z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"I32n\"") } else { r.EncodeString(`I32n`) } z.EncWriteMapElemValue() r.EncodeInt(int64(x.TestStrucCommon.I32n)) } if yyq2[7] { z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"I16n\"") } else { r.EncodeString(`I16n`) } z.EncWriteMapElemValue() r.EncodeInt(int64(x.TestStrucCommon.I16n)) } if yyq2[8] { z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"I8n\"") } else { r.EncodeString(`I8n`) } z.EncWriteMapElemValue() r.EncodeInt(int64(x.TestStrucCommon.I8n)) } if yyq2[9] { z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"Ui64\"") } else { r.EncodeString(`Ui64`) } z.EncWriteMapElemValue() r.EncodeUint(uint64(x.TestStrucCommon.Ui64)) } if yyq2[10] { z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"Ui32\"") } else { r.EncodeString(`Ui32`) } z.EncWriteMapElemValue() r.EncodeUint(uint64(x.TestStrucCommon.Ui32)) } if yyq2[11] { z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"Ui16\"") } else { r.EncodeString(`Ui16`) } z.EncWriteMapElemValue() r.EncodeUint(uint64(x.TestStrucCommon.Ui16)) } if yyq2[12] { z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"Ui8\"") } else { r.EncodeString(`Ui8`) } z.EncWriteMapElemValue() r.EncodeUint(uint64(x.TestStrucCommon.Ui8)) } if yyq2[13] { z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"F64\"") } else { r.EncodeString(`F64`) } z.EncWriteMapElemValue() r.EncodeFloat64(float64(x.TestStrucCommon.F64)) } if yyq2[14] { z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"F32\"") } else { r.EncodeString(`F32`) } z.EncWriteMapElemValue() r.EncodeFloat32(float32(x.TestStrucCommon.F32)) } if yyq2[15] { z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"B\"") } else { r.EncodeString(`B`) } z.EncWriteMapElemValue() r.EncodeBool(bool(x.TestStrucCommon.B)) } if yyq2[16] { z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"By\"") } else { r.EncodeString(`By`) } z.EncWriteMapElemValue() r.EncodeUint(uint64(x.TestStrucCommon.By)) } if yyq2[17] { z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"Sslice\"") } else { r.EncodeString(`Sslice`) } z.EncWriteMapElemValue() if x.TestStrucCommon.Sslice == nil { r.EncodeNil() } else { z.F.EncSliceStringV(x.TestStrucCommon.Sslice, e) } // end block: if x.TestStrucCommon.Sslice slice == nil } if yyq2[18] { z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"I64slice\"") } else { r.EncodeString(`I64slice`) } z.EncWriteMapElemValue() if x.TestStrucCommon.I64slice == nil { r.EncodeNil() } else { z.F.EncSliceInt64V(x.TestStrucCommon.I64slice, e) } // end block: if x.TestStrucCommon.I64slice slice == nil } if yyq2[19] { z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"I32slice\"") } else { r.EncodeString(`I32slice`) } z.EncWriteMapElemValue() if x.TestStrucCommon.I32slice == nil { r.EncodeNil() } else { z.F.EncSliceInt32V(x.TestStrucCommon.I32slice, e) } // end block: if x.TestStrucCommon.I32slice slice == nil } if yyq2[20] { z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"Ui64slice\"") } else { r.EncodeString(`Ui64slice`) } z.EncWriteMapElemValue() if x.TestStrucCommon.Ui64slice == nil { r.EncodeNil() } else { z.F.EncSliceUint64V(x.TestStrucCommon.Ui64slice, e) } // end block: if x.TestStrucCommon.Ui64slice slice == nil } if yyq2[21] { z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"Ui8slice\"") } else { r.EncodeString(`Ui8slice`) } z.EncWriteMapElemValue() if x.TestStrucCommon.Ui8slice == nil { r.EncodeNil() } else { r.EncodeStringBytesRaw([]byte(x.TestStrucCommon.Ui8slice)) } // end block: if x.TestStrucCommon.Ui8slice slice == nil } if yyq2[22] { z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"Bslice\"") } else { r.EncodeString(`Bslice`) } z.EncWriteMapElemValue() if x.TestStrucCommon.Bslice == nil { r.EncodeNil() } else { z.F.EncSliceBoolV(x.TestStrucCommon.Bslice, e) } // end block: if x.TestStrucCommon.Bslice slice == nil } if yyq2[23] { z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"Byslice\"") } else { r.EncodeString(`Byslice`) } z.EncWriteMapElemValue() if x.TestStrucCommon.Byslice == nil { r.EncodeNil() } else { r.EncodeStringBytesRaw([]byte(x.TestStrucCommon.Byslice)) } // end block: if x.TestStrucCommon.Byslice slice == nil } if yyq2[24] { z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"BytesSlice\"") } else { r.EncodeString(`BytesSlice`) } z.EncWriteMapElemValue() if x.TestStrucCommon.BytesSlice == nil { r.EncodeNil() } else { z.F.EncSliceBytesV(x.TestStrucCommon.BytesSlice, e) } // end block: if x.TestStrucCommon.BytesSlice slice == nil } if yyq2[25] { z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"Iptrslice\"") } else { r.EncodeString(`Iptrslice`) } z.EncWriteMapElemValue() if x.TestStrucCommon.Iptrslice == nil { r.EncodeNil() } else { h.encSlicePtrtoint64(([]*int64)(x.TestStrucCommon.Iptrslice), e) } // end block: if x.TestStrucCommon.Iptrslice slice == nil } if yyq2[26] { z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"WrapSliceInt64\"") } else { r.EncodeString(`WrapSliceInt64`) } z.EncWriteMapElemValue() if yyxt334 := z.Extension(x.TestStrucCommon.WrapSliceInt64); yyxt334 != nil { z.EncExtension(x.TestStrucCommon.WrapSliceInt64, yyxt334) } else { x.TestStrucCommon.WrapSliceInt64.CodecEncodeSelf(e) } } if yyq2[27] { z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"WrapSliceString\"") } else { r.EncodeString(`WrapSliceString`) } z.EncWriteMapElemValue() if yyxt335 := z.Extension(x.TestStrucCommon.WrapSliceString); yyxt335 != nil { z.EncExtension(x.TestStrucCommon.WrapSliceString, yyxt335) } else { x.TestStrucCommon.WrapSliceString.CodecEncodeSelf(e) } } if yyq2[28] { z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"Msint\"") } else { r.EncodeString(`Msint`) } z.EncWriteMapElemValue() if x.TestStrucCommon.Msint == nil { r.EncodeNil() } else { z.F.EncMapStringIntV(x.TestStrucCommon.Msint, e) } // end block: if x.TestStrucCommon.Msint map == nil } if yyq2[29] { z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"Msbytes\"") } else { r.EncodeString(`Msbytes`) } z.EncWriteMapElemValue() if x.TestStrucCommon.Msbytes == nil { r.EncodeNil() } else { z.F.EncMapStringBytesV(x.TestStrucCommon.Msbytes, e) } // end block: if x.TestStrucCommon.Msbytes map == nil } if yyq2[30] { z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"Simplef\"") } else { r.EncodeString(`Simplef`) } z.EncWriteMapElemValue() yy338 := &x.TestStrucCommon.Simplef if yyxt339 := z.Extension(yy338); yyxt339 != nil { z.EncExtension(yy338, yyxt339) } else { yy338.CodecEncodeSelf(e) } } if yyq2[31] { z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"SstrUi64T\"") } else { r.EncodeString(`SstrUi64T`) } z.EncWriteMapElemValue() if x.TestStrucCommon.SstrUi64T == nil { r.EncodeNil() } else { h.encSlicestringUint64T(([]stringUint64T)(x.TestStrucCommon.SstrUi64T), e) } // end block: if x.TestStrucCommon.SstrUi64T slice == nil } if yyq2[32] { z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"MstrUi64T\"") } else { r.EncodeString(`MstrUi64T`) } z.EncWriteMapElemValue() if x.TestStrucCommon.MstrUi64T == nil { r.EncodeNil() } else { h.encMapstringPtrtostringUint64T((map[string]*stringUint64T)(x.TestStrucCommon.MstrUi64T), e) } // end block: if x.TestStrucCommon.MstrUi64T map == nil } if yyq2[33] { z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"AS\"") } else { r.EncodeString(`AS`) } z.EncWriteMapElemValue() r.EncodeString(string(x.TestStrucCommon.AnonInTestStruc.AS)) } if yyq2[34] { z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"AI64\"") } else { r.EncodeString(`AI64`) } z.EncWriteMapElemValue() r.EncodeInt(int64(x.TestStrucCommon.AnonInTestStruc.AI64)) } if yyq2[35] { z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"AI16\"") } else { r.EncodeString(`AI16`) } z.EncWriteMapElemValue() r.EncodeInt(int64(x.TestStrucCommon.AnonInTestStruc.AI16)) } if yyq2[36] { z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"AUi64\"") } else { r.EncodeString(`AUi64`) } z.EncWriteMapElemValue() r.EncodeUint(uint64(x.TestStrucCommon.AnonInTestStruc.AUi64)) } if yyq2[37] { z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"ASslice\"") } else { r.EncodeString(`ASslice`) } z.EncWriteMapElemValue() if x.TestStrucCommon.AnonInTestStruc.ASslice == nil { r.EncodeNil() } else { z.F.EncSliceStringV(x.TestStrucCommon.AnonInTestStruc.ASslice, e) } // end block: if x.TestStrucCommon.AnonInTestStruc.ASslice slice == nil } if yyq2[38] { z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"AI64slice\"") } else { r.EncodeString(`AI64slice`) } z.EncWriteMapElemValue() if x.TestStrucCommon.AnonInTestStruc.AI64slice == nil { r.EncodeNil() } else { z.F.EncSliceInt64V(x.TestStrucCommon.AnonInTestStruc.AI64slice, e) } // end block: if x.TestStrucCommon.AnonInTestStruc.AI64slice slice == nil } if yyq2[39] { z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"AUi64slice\"") } else { r.EncodeString(`AUi64slice`) } z.EncWriteMapElemValue() if x.TestStrucCommon.AnonInTestStruc.AUi64slice == nil { r.EncodeNil() } else { z.F.EncSliceUint64V(x.TestStrucCommon.AnonInTestStruc.AUi64slice, e) } // end block: if x.TestStrucCommon.AnonInTestStruc.AUi64slice slice == nil } if yyq2[40] { z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"AF64slice\"") } else { r.EncodeString(`AF64slice`) } z.EncWriteMapElemValue() if x.TestStrucCommon.AnonInTestStruc.AF64slice == nil { r.EncodeNil() } else { z.F.EncSliceFloat64V(x.TestStrucCommon.AnonInTestStruc.AF64slice, e) } // end block: if x.TestStrucCommon.AnonInTestStruc.AF64slice slice == nil } if yyq2[41] { z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"AF32slice\"") } else { r.EncodeString(`AF32slice`) } z.EncWriteMapElemValue() if x.TestStrucCommon.AnonInTestStruc.AF32slice == nil { r.EncodeNil() } else { z.F.EncSliceFloat32V(x.TestStrucCommon.AnonInTestStruc.AF32slice, e) } // end block: if x.TestStrucCommon.AnonInTestStruc.AF32slice slice == nil } if yyq2[42] { z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"AMSS\"") } else { r.EncodeString(`AMSS`) } z.EncWriteMapElemValue() if x.TestStrucCommon.AnonInTestStruc.AMSS == nil { r.EncodeNil() } else { z.F.EncMapStringStringV(x.TestStrucCommon.AnonInTestStruc.AMSS, e) } // end block: if x.TestStrucCommon.AnonInTestStruc.AMSS map == nil } if yyq2[43] { z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"AMSU64\"") } else { r.EncodeString(`AMSU64`) } z.EncWriteMapElemValue() if x.TestStrucCommon.AnonInTestStruc.AMSU64 == nil { r.EncodeNil() } else { z.F.EncMapStringUint64V(x.TestStrucCommon.AnonInTestStruc.AMSU64, e) } // end block: if x.TestStrucCommon.AnonInTestStruc.AMSU64 map == nil } if yyq2[44] { z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"AI64arr8\"") } else { r.EncodeString(`AI64arr8`) } z.EncWriteMapElemValue() yy353 := &x.TestStrucCommon.AnonInTestStruc.AI64arr8 h.encArray8int64((*[8]int64)(yy353), e) } if yyq2[45] { z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"AI64arr0\"") } else { r.EncodeString(`AI64arr0`) } z.EncWriteMapElemValue() yy355 := &x.TestStrucCommon.AnonInTestStruc.AI64arr0 h.encArray0int64((*[0]int64)(yy355), e) } if yyq2[46] { z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"AI64slice0\"") } else { r.EncodeString(`AI64slice0`) } z.EncWriteMapElemValue() if x.TestStrucCommon.AnonInTestStruc.AI64slice0 == nil { r.EncodeNil() } else { z.F.EncSliceInt64V(x.TestStrucCommon.AnonInTestStruc.AI64slice0, e) } // end block: if x.TestStrucCommon.AnonInTestStruc.AI64slice0 slice == nil } if yyq2[47] { z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"AUi64sliceN\"") } else { r.EncodeString(`AUi64sliceN`) } z.EncWriteMapElemValue() if x.TestStrucCommon.AnonInTestStruc.AUi64sliceN == nil { r.EncodeNil() } else { z.F.EncSliceUint64V(x.TestStrucCommon.AnonInTestStruc.AUi64sliceN, e) } // end block: if x.TestStrucCommon.AnonInTestStruc.AUi64sliceN slice == nil } if yyq2[48] { z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"AMSU64N\"") } else { r.EncodeString(`AMSU64N`) } z.EncWriteMapElemValue() if x.TestStrucCommon.AnonInTestStruc.AMSU64N == nil { r.EncodeNil() } else { z.F.EncMapStringUint64V(x.TestStrucCommon.AnonInTestStruc.AMSU64N, e) } // end block: if x.TestStrucCommon.AnonInTestStruc.AMSU64N map == nil } if yyq2[49] { z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"AMSU64E\"") } else { r.EncodeString(`AMSU64E`) } z.EncWriteMapElemValue() if x.TestStrucCommon.AnonInTestStruc.AMSU64E == nil { r.EncodeNil() } else { z.F.EncMapStringUint64V(x.TestStrucCommon.AnonInTestStruc.AMSU64E, e) } // end block: if x.TestStrucCommon.AnonInTestStruc.AMSU64E map == nil } if yyq2[50] { z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"NotAnon\"") } else { r.EncodeString(`NotAnon`) } z.EncWriteMapElemValue() yy361 := &x.TestStrucCommon.NotAnon if yyxt362 := z.Extension(yy361); yyxt362 != nil { z.EncExtension(yy361, yyxt362) } else { yy361.CodecEncodeSelf(e) } } if yyq2[51] { z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"P\"") } else { r.EncodeString(`P`) } z.EncWriteMapElemValue() if yyn54 { r.EncodeNil() } else { yy363 := *x.TestStrucCommon.AnonInTestStrucSlim.P r.EncodeString(string(yy363)) } } if yyq2[52] { z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"NotAnonSlim\"") } else { r.EncodeString(`NotAnonSlim`) } z.EncWriteMapElemValue() if yyn55 { r.EncodeNil() } else { if yyxt365 := z.Extension(x.TestStrucCommon.NotAnonSlim); yyxt365 != nil { z.EncExtension(x.TestStrucCommon.NotAnonSlim, yyxt365) } else { x.TestStrucCommon.NotAnonSlim.CodecEncodeSelf(e) } } } if yyq2[53] { z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"Nmap\"") } else { r.EncodeString(`Nmap`) } z.EncWriteMapElemValue() if x.TestStrucCommon.Nmap == nil { r.EncodeNil() } else { z.F.EncMapStringBoolV(x.TestStrucCommon.Nmap, e) } // end block: if x.TestStrucCommon.Nmap map == nil } if yyq2[54] { z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"Nslice\"") } else { r.EncodeString(`Nslice`) } z.EncWriteMapElemValue() if x.TestStrucCommon.Nslice == nil { r.EncodeNil() } else { r.EncodeStringBytesRaw([]byte(x.TestStrucCommon.Nslice)) } // end block: if x.TestStrucCommon.Nslice slice == nil } if yyq2[55] { z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"Nint64\"") } else { r.EncodeString(`Nint64`) } z.EncWriteMapElemValue() if yyn58 { r.EncodeNil() } else { yy368 := *x.TestStrucCommon.Nint64 r.EncodeInt(int64(yy368)) } } if yyq2[56] { z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"Chstr\"") } else { r.EncodeString(`Chstr`) } z.EncWriteMapElemValue() h.encChanstring((chan string)(x.Chstr), e) } if yyq2[57] { z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"Mis\"") } else { r.EncodeString(`Mis`) } z.EncWriteMapElemValue() if x.Mis == nil { r.EncodeNil() } else { z.F.EncMapIntStringV(x.Mis, e) } // end block: if x.Mis map == nil } if yyq2[58] { z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"Mbu64\"") } else { r.EncodeString(`Mbu64`) } z.EncWriteMapElemValue() if x.Mbu64 == nil { r.EncodeNil() } else { h.encMapboolc3RydWN0IHt9((map[bool]struct{})(x.Mbu64), e) } // end block: if x.Mbu64 map == nil } if yyq2[59] { z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"Mu8e\"") } else { r.EncodeString(`Mu8e`) } z.EncWriteMapElemValue() if x.Mu8e == nil { r.EncodeNil() } else { h.encMapuint8c3RydWN0IHt9((map[uint8]struct{})(x.Mu8e), e) } // end block: if x.Mu8e map == nil } if yyq2[60] { z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"Mu8u64\"") } else { r.EncodeString(`Mu8u64`) } z.EncWriteMapElemValue() if x.Mu8u64 == nil { r.EncodeNil() } else { h.encMapuint8stringUint64T((map[uint8]stringUint64T)(x.Mu8u64), e) } // end block: if x.Mu8u64 map == nil } if yyq2[61] { z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"Msp2ss\"") } else { r.EncodeString(`Msp2ss`) } z.EncWriteMapElemValue() if x.Msp2ss == nil { r.EncodeNil() } else { h.encMapPtrtostringSlicestring((map[*string][]string)(x.Msp2ss), e) } // end block: if x.Msp2ss map == nil } if yyq2[62] { z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"Mip2ss\"") } else { r.EncodeString(`Mip2ss`) } z.EncWriteMapElemValue() if x.Mip2ss == nil { r.EncodeNil() } else { h.encMapPtrtouint64Slicestring((map[*uint64][]string)(x.Mip2ss), e) } // end block: if x.Mip2ss map == nil } if yyq2[63] { z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"Ms2misu\"") } else { r.EncodeString(`Ms2misu`) } z.EncWriteMapElemValue() if x.Ms2misu == nil { r.EncodeNil() } else { h.encMapstringMapuint64stringUint64T((map[string]map[uint64]stringUint64T)(x.Ms2misu), e) } // end block: if x.Ms2misu map == nil } if yyq2[64] { z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"Miwu64s\"") } else { r.EncodeString(`Miwu64s`) } z.EncWriteMapElemValue() if x.Miwu64s == nil { r.EncodeNil() } else { h.encMapintwrapUint64Slice((map[int]wrapUint64Slice)(x.Miwu64s), e) } // end block: if x.Miwu64s map == nil } if yyq2[65] { z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"Mfwss\"") } else { r.EncodeString(`Mfwss`) } z.EncWriteMapElemValue() if x.Mfwss == nil { r.EncodeNil() } else { h.encMapfloat64wrapStringSlice((map[float64]wrapStringSlice)(x.Mfwss), e) } // end block: if x.Mfwss map == nil } if yyq2[66] { z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"Mf32wss\"") } else { r.EncodeString(`Mf32wss`) } z.EncWriteMapElemValue() if x.Mf32wss == nil { r.EncodeNil() } else { h.encMapfloat32wrapStringSlice((map[float32]wrapStringSlice)(x.Mf32wss), e) } // end block: if x.Mf32wss map == nil } if yyq2[67] { z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"Mui2wss\"") } else { r.EncodeString(`Mui2wss`) } z.EncWriteMapElemValue() if x.Mui2wss == nil { r.EncodeNil() } else { h.encMapuint64wrapStringSlice((map[uint64]wrapStringSlice)(x.Mui2wss), e) } // end block: if x.Mui2wss map == nil } if yyq2[68] { z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"Msu2wss\"") } else { r.EncodeString(`Msu2wss`) } z.EncWriteMapElemValue() if x.Msu2wss == nil { r.EncodeNil() } else { h.encMapstringUint64TwrapStringSlice((map[stringUint64T]wrapStringSlice)(x.Msu2wss), e) } // end block: if x.Msu2wss map == nil } if yyq2[69] { z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"Ci64\"") } else { r.EncodeString(`Ci64`) } z.EncWriteMapElemValue() if yyxt383 := z.Extension(x.Ci64); yyxt383 != nil { z.EncExtension(x.Ci64, yyxt383) } else { x.Ci64.CodecEncodeSelf(e) } } if yyq2[70] { z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"Swrapbytes\"") } else { r.EncodeString(`Swrapbytes`) } z.EncWriteMapElemValue() if x.Swrapbytes == nil { r.EncodeNil() } else { h.encSlicewrapBytes(([]wrapBytes)(x.Swrapbytes), e) } // end block: if x.Swrapbytes slice == nil } if yyq2[71] { z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"Swrapuint8\"") } else { r.EncodeString(`Swrapuint8`) } z.EncWriteMapElemValue() if x.Swrapuint8 == nil { r.EncodeNil() } else { h.encSlicewrapUint8(([]wrapUint8)(x.Swrapuint8), e) } // end block: if x.Swrapuint8 slice == nil } if yyq2[72] { z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"ArrStrUi64T\"") } else { r.EncodeString(`ArrStrUi64T`) } z.EncWriteMapElemValue() yy386 := &x.ArrStrUi64T h.encArray4stringUint64T((*[4]stringUint64T)(yy386), e) } if yyq2[73] { z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"Ui64array\"") } else { r.EncodeString(`Ui64array`) } z.EncWriteMapElemValue() yy388 := &x.Ui64array h.encArray4uint64((*[4]uint64)(yy388), e) } if yyq2[74] { z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"Ui64slicearray\"") } else { r.EncodeString(`Ui64slicearray`) } z.EncWriteMapElemValue() if x.Ui64slicearray == nil { r.EncodeNil() } else { h.encSlicePtrtoArray4uint64(([]*[4]uint64)(x.Ui64slicearray), e) } // end block: if x.Ui64slicearray slice == nil } if yyq2[75] { z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"SintfAarray\"") } else { r.EncodeString(`SintfAarray`) } z.EncWriteMapElemValue() if x.SintfAarray == nil { r.EncodeNil() } else { z.F.EncSliceIntfV(x.SintfAarray, e) } // end block: if x.SintfAarray slice == nil } if yyq2[76] { z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"MstrUi64TSelf\"") } else { r.EncodeString(`MstrUi64TSelf`) } z.EncWriteMapElemValue() if x.MstrUi64TSelf == nil { r.EncodeNil() } else { h.encMapstringUint64TPtrtostringUint64T((map[stringUint64T]*stringUint64T)(x.MstrUi64TSelf), e) } // end block: if x.MstrUi64TSelf map == nil } if yyq2[77] { z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"Ttime\"") } else { r.EncodeString(`Ttime`) } z.EncWriteMapElemValue() if z.EncBasicHandle().TimeBuiltin() { r.EncodeTime(x.Ttime) } else if yyxt393 := z.Extension(x.Ttime); yyxt393 != nil { z.EncExtension(x.Ttime, yyxt393) } else if z.EncBinary() { z.EncBinaryMarshal(x.Ttime) } else if !z.EncBinary() && z.IsJSONHandle() { z.EncJSONMarshal(x.Ttime) } else { z.EncFallback(x.Ttime) } } if yyq2[78] { z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"Ttimeptr\"") } else { r.EncodeString(`Ttimeptr`) } z.EncWriteMapElemValue() if yyn81 { r.EncodeNil() } else { yy394 := *x.Ttimeptr if z.EncBasicHandle().TimeBuiltin() { r.EncodeTime(yy394) } else if yyxt395 := z.Extension(yy394); yyxt395 != nil { z.EncExtension(yy394, yyxt395) } else if z.EncBinary() { z.EncBinaryMarshal(yy394) } else if !z.EncBinary() && z.IsJSONHandle() { z.EncJSONMarshal(yy394) } else { z.EncFallback(yy394) } } } if yyq2[79] { z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"Islice\"") } else { r.EncodeString(`Islice`) } z.EncWriteMapElemValue() if yyn82 { r.EncodeNil() } else { if x.AnonInTestStrucIntf.Islice == nil { r.EncodeNil() } else { z.F.EncSliceIntfV(x.AnonInTestStrucIntf.Islice, e) } // end block: if x.AnonInTestStrucIntf.Islice slice == nil } } if yyq2[80] { z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"Ms\"") } else { r.EncodeString(`Ms`) } z.EncWriteMapElemValue() if yyn83 { r.EncodeNil() } else { if x.AnonInTestStrucIntf.Ms == nil { r.EncodeNil() } else { z.F.EncMapStringIntfV(x.AnonInTestStrucIntf.Ms, e) } // end block: if x.AnonInTestStrucIntf.Ms map == nil } } if yyq2[81] { z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"Nintf\"") } else { r.EncodeString(`Nintf`) } z.EncWriteMapElemValue() if yyn84 { r.EncodeNil() } else { z.EncFallback(x.AnonInTestStrucIntf.Nintf) } } if yyq2[82] { z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"T\"") } else { r.EncodeString(`T`) } z.EncWriteMapElemValue() if yyn85 { r.EncodeNil() } else { if z.EncBasicHandle().TimeBuiltin() { r.EncodeTime(x.AnonInTestStrucIntf.T) } else if yyxt399 := z.Extension(x.AnonInTestStrucIntf.T); yyxt399 != nil { z.EncExtension(x.AnonInTestStrucIntf.T, yyxt399) } else if z.EncBinary() { z.EncBinaryMarshal(x.AnonInTestStrucIntf.T) } else if !z.EncBinary() && z.IsJSONHandle() { z.EncJSONMarshal(x.AnonInTestStrucIntf.T) } else { z.EncFallback(x.AnonInTestStrucIntf.T) } } } if yyq2[83] { z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"Tptr\"") } else { r.EncodeString(`Tptr`) } z.EncWriteMapElemValue() if yyn86 { r.EncodeNil() } else { yy400 := *x.AnonInTestStrucIntf.Tptr if z.EncBasicHandle().TimeBuiltin() { r.EncodeTime(yy400) } else if yyxt401 := z.Extension(yy400); yyxt401 != nil { z.EncExtension(yy400, yyxt401) } else if z.EncBinary() { z.EncBinaryMarshal(yy400) } else if !z.EncBinary() && z.IsJSONHandle() { z.EncJSONMarshal(yy400) } else { z.EncFallback(yy400) } } } if yyq2[84] { z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"Msu\"") } else { r.EncodeString(`Msu`) } z.EncWriteMapElemValue() if x.Msu == nil { r.EncodeNil() } else { h.encMapwrapStringInterface((map[wrapString]interface{})(x.Msu), e) } // end block: if x.Msu map == nil } if yyq2[85] { z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"Mtsptr\"") } else { r.EncodeString(`Mtsptr`) } z.EncWriteMapElemValue() if x.Mtsptr == nil { r.EncodeNil() } else { h.encMapstringPtrtoTestStrucFlex((map[string]*TestStrucFlex)(x.Mtsptr), e) } // end block: if x.Mtsptr map == nil } if yyq2[86] { z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"Mts\"") } else { r.EncodeString(`Mts`) } z.EncWriteMapElemValue() if x.Mts == nil { r.EncodeNil() } else { h.encMapstringTestStrucFlex((map[string]TestStrucFlex)(x.Mts), e) } // end block: if x.Mts map == nil } if yyq2[87] { z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"Its\"") } else { r.EncodeString(`Its`) } z.EncWriteMapElemValue() if x.Its == nil { r.EncodeNil() } else { h.encSlicePtrtoTestStrucFlex(([]*TestStrucFlex)(x.Its), e) } // end block: if x.Its slice == nil } if yyq2[88] { z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"Nteststruc\"") } else { r.EncodeString(`Nteststruc`) } z.EncWriteMapElemValue() if yyn91 { r.EncodeNil() } else { if yyxt406 := z.Extension(x.Nteststruc); yyxt406 != nil { z.EncExtension(x.Nteststruc, yyxt406) } else { x.Nteststruc.CodecEncodeSelf(e) } } } if yyq2[89] { z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"MarJ\"") } else { r.EncodeString(`MarJ`) } z.EncWriteMapElemValue() if yyxt407 := z.Extension(x.MarJ); yyxt407 != nil { z.EncExtension(x.MarJ, yyxt407) } else { x.MarJ.CodecEncodeSelf(e) } } if yyq2[90] { z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"MarT\"") } else { r.EncodeString(`MarT`) } z.EncWriteMapElemValue() if yyxt408 := z.Extension(x.MarT); yyxt408 != nil { z.EncExtension(x.MarT, yyxt408) } else { x.MarT.CodecEncodeSelf(e) } } if yyq2[91] { z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"MarB\"") } else { r.EncodeString(`MarB`) } z.EncWriteMapElemValue() if yyxt409 := z.Extension(x.MarB); yyxt409 != nil { z.EncExtension(x.MarB, yyxt409) } else { x.MarB.CodecEncodeSelf(e) } } if yyq2[92] { z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"XuintToBytes\"") } else { r.EncodeString(`XuintToBytes`) } z.EncWriteMapElemValue() if yyxt410 := z.Extension(x.XuintToBytes); yyxt410 != nil { z.EncExtension(x.XuintToBytes, yyxt410) } else { x.XuintToBytes.CodecEncodeSelf(e) } } if yyq2[93] { z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"Cmplx64\"") } else { r.EncodeString(`Cmplx64`) } z.EncWriteMapElemValue() z.EncEncodeComplex64(complex64(x.Cmplx64)) } if yyq2[94] { z.EncWriteMapElemKey() if z.IsJSONHandle() { z.WriteStr("\"Cmplx128\"") } else { r.EncodeString(`Cmplx128`) } z.EncWriteMapElemValue() z.EncEncodeComplex128(complex128(x.Cmplx128)) } } z.EncWriteMapEnd() } } } func (x *TestStrucFlex) CodecDecodeSelf(d *Decoder) { var h codecSelfer19780 z, r := GenHelper().Decoder(d) _, _, _ = h, z, r yyct2 := r.ContainerType() if yyct2 == codecSelferValueTypeNil19780 { *(x) = TestStrucFlex{} } else if yyct2 == codecSelferValueTypeMap19780 { yyl2 := z.DecReadMapStart() if yyl2 == 0 { } else { x.codecDecodeSelfFromMap(yyl2, d) } z.DecReadMapEnd() } else if yyct2 == codecSelferValueTypeArray19780 { yyl2 := z.DecReadArrayStart() if yyl2 != 0 { x.codecDecodeSelfFromArray(yyl2, d) } z.DecReadArrayEnd() } else { panic(errCodecSelferOnlyMapOrArrayEncodeToStruct19780) } } func (x *TestStrucFlex) codecDecodeSelfFromMap(l int, d *Decoder) { var h codecSelfer19780 z, r := GenHelper().Decoder(d) _, _, _ = h, z, r var yyhl3 bool = l >= 0 for yyj3 := 0; ; yyj3++ { if yyhl3 { if yyj3 >= l { break } } else { if z.DecCheckBreak() { break } } z.DecReadMapElemKey() yys3 := r.DecodeStringAsBytes() z.DecReadMapElemValue() switch string(yys3) { case "S": x.TestStrucCommon.S = (string)(z.DecStringZC(r.DecodeStringAsBytes())) case "I64": x.TestStrucCommon.I64 = (int64)(r.DecodeInt64()) case "I32": x.TestStrucCommon.I32 = (int32)(z.C.IntV(r.DecodeInt64(), 32)) case "I16": x.TestStrucCommon.I16 = (int16)(z.C.IntV(r.DecodeInt64(), 16)) case "I8": x.TestStrucCommon.I8 = (int8)(z.C.IntV(r.DecodeInt64(), 8)) case "I64n": x.TestStrucCommon.I64n = (int64)(r.DecodeInt64()) case "I32n": x.TestStrucCommon.I32n = (int32)(z.C.IntV(r.DecodeInt64(), 32)) case "I16n": x.TestStrucCommon.I16n = (int16)(z.C.IntV(r.DecodeInt64(), 16)) case "I8n": x.TestStrucCommon.I8n = (int8)(z.C.IntV(r.DecodeInt64(), 8)) case "Ui64": x.TestStrucCommon.Ui64 = (uint64)(r.DecodeUint64()) case "Ui32": x.TestStrucCommon.Ui32 = (uint32)(z.C.UintV(r.DecodeUint64(), 32)) case "Ui16": x.TestStrucCommon.Ui16 = (uint16)(z.C.UintV(r.DecodeUint64(), 16)) case "Ui8": x.TestStrucCommon.Ui8 = (uint8)(z.C.UintV(r.DecodeUint64(), 8)) case "F64": x.TestStrucCommon.F64 = (float64)(r.DecodeFloat64()) case "F32": x.TestStrucCommon.F32 = (float32)(z.DecDecodeFloat32()) case "B": x.TestStrucCommon.B = (bool)(r.DecodeBool()) case "By": x.TestStrucCommon.By = (uint8)(z.C.UintV(r.DecodeUint64(), 8)) case "Sslice": z.F.DecSliceStringX(&x.TestStrucCommon.Sslice, d) case "I64slice": z.F.DecSliceInt64X(&x.TestStrucCommon.I64slice, d) case "I32slice": z.F.DecSliceInt32X(&x.TestStrucCommon.I32slice, d) case "Ui64slice": z.F.DecSliceUint64X(&x.TestStrucCommon.Ui64slice, d) case "Ui8slice": x.TestStrucCommon.Ui8slice = z.DecodeBytesInto(([]byte)(x.TestStrucCommon.Ui8slice)) case "Bslice": z.F.DecSliceBoolX(&x.TestStrucCommon.Bslice, d) case "Byslice": x.TestStrucCommon.Byslice = z.DecodeBytesInto(([]byte)(x.TestStrucCommon.Byslice)) case "BytesSlice": z.F.DecSliceBytesX(&x.TestStrucCommon.BytesSlice, d) case "Iptrslice": h.decSlicePtrtoint64((*[]*int64)(&x.TestStrucCommon.Iptrslice), d) case "WrapSliceInt64": if yyxt40 := z.Extension(x.TestStrucCommon.WrapSliceInt64); yyxt40 != nil { z.DecExtension(&x.TestStrucCommon.WrapSliceInt64, yyxt40) } else { x.TestStrucCommon.WrapSliceInt64.CodecDecodeSelf(d) } case "WrapSliceString": if yyxt42 := z.Extension(x.TestStrucCommon.WrapSliceString); yyxt42 != nil { z.DecExtension(&x.TestStrucCommon.WrapSliceString, yyxt42) } else { x.TestStrucCommon.WrapSliceString.CodecDecodeSelf(d) } case "Msint": z.F.DecMapStringIntX(&x.TestStrucCommon.Msint, d) case "Msbytes": z.F.DecMapStringBytesX(&x.TestStrucCommon.Msbytes, d) case "Simplef": if yyxt48 := z.Extension(x.TestStrucCommon.Simplef); yyxt48 != nil { z.DecExtension(&x.TestStrucCommon.Simplef, yyxt48) } else { x.TestStrucCommon.Simplef.CodecDecodeSelf(d) } case "SstrUi64T": h.decSlicestringUint64T((*[]stringUint64T)(&x.TestStrucCommon.SstrUi64T), d) case "MstrUi64T": h.decMapstringPtrtostringUint64T((*map[string]*stringUint64T)(&x.TestStrucCommon.MstrUi64T), d) case "AS": x.TestStrucCommon.AnonInTestStruc.AS = (string)(z.DecStringZC(r.DecodeStringAsBytes())) case "AI64": x.TestStrucCommon.AnonInTestStruc.AI64 = (int64)(r.DecodeInt64()) case "AI16": x.TestStrucCommon.AnonInTestStruc.AI16 = (int16)(z.C.IntV(r.DecodeInt64(), 16)) case "AUi64": x.TestStrucCommon.AnonInTestStruc.AUi64 = (uint64)(r.DecodeUint64()) case "ASslice": z.F.DecSliceStringX(&x.TestStrucCommon.AnonInTestStruc.ASslice, d) case "AI64slice": z.F.DecSliceInt64X(&x.TestStrucCommon.AnonInTestStruc.AI64slice, d) case "AUi64slice": z.F.DecSliceUint64X(&x.TestStrucCommon.AnonInTestStruc.AUi64slice, d) case "AF64slice": z.F.DecSliceFloat64X(&x.TestStrucCommon.AnonInTestStruc.AF64slice, d) case "AF32slice": z.F.DecSliceFloat32X(&x.TestStrucCommon.AnonInTestStruc.AF32slice, d) case "AMSS": z.F.DecMapStringStringX(&x.TestStrucCommon.AnonInTestStruc.AMSS, d) case "AMSU64": z.F.DecMapStringUint64X(&x.TestStrucCommon.AnonInTestStruc.AMSU64, d) case "AI64arr8": h.decArray8int64((*[8]int64)(&x.TestStrucCommon.AnonInTestStruc.AI64arr8), d) case "AI64arr0": h.decArray0int64((*[0]int64)(&x.TestStrucCommon.AnonInTestStruc.AI64arr0), d) case "AI64slice0": z.F.DecSliceInt64X(&x.TestStrucCommon.AnonInTestStruc.AI64slice0, d) case "AUi64sliceN": z.F.DecSliceUint64X(&x.TestStrucCommon.AnonInTestStruc.AUi64sliceN, d) case "AMSU64N": z.F.DecMapStringUint64X(&x.TestStrucCommon.AnonInTestStruc.AMSU64N, d) case "AMSU64E": z.F.DecMapStringUint64X(&x.TestStrucCommon.AnonInTestStruc.AMSU64E, d) case "NotAnon": if yyxt84 := z.Extension(x.TestStrucCommon.NotAnon); yyxt84 != nil { z.DecExtension(&x.TestStrucCommon.NotAnon, yyxt84) } else { x.TestStrucCommon.NotAnon.CodecDecodeSelf(d) } case "P": if r.TryNil() { if x.TestStrucCommon.AnonInTestStrucSlim != nil && x.TestStrucCommon.AnonInTestStrucSlim.P != nil { // remove the if-true x.TestStrucCommon.AnonInTestStrucSlim.P = nil } } else { if x.TestStrucCommon.AnonInTestStrucSlim == nil { x.TestStrucCommon.AnonInTestStrucSlim = new(AnonInTestStrucSlim) } if x.TestStrucCommon.AnonInTestStrucSlim.P == nil { x.TestStrucCommon.AnonInTestStrucSlim.P = new(string) } *x.TestStrucCommon.AnonInTestStrucSlim.P = (string)(z.DecStringZC(r.DecodeStringAsBytes())) } case "NotAnonSlim": if r.TryNil() { if x.TestStrucCommon.NotAnonSlim != nil { // remove the if-true x.TestStrucCommon.NotAnonSlim = nil } } else { if x.TestStrucCommon.NotAnonSlim == nil { x.TestStrucCommon.NotAnonSlim = new(AnonInTestStrucSlim) } if yyxt88 := z.Extension(x.TestStrucCommon.NotAnonSlim); yyxt88 != nil { z.DecExtension(x.TestStrucCommon.NotAnonSlim, yyxt88) } else { x.TestStrucCommon.NotAnonSlim.CodecDecodeSelf(d) } } case "Nmap": z.F.DecMapStringBoolX(&x.TestStrucCommon.Nmap, d) case "Nslice": x.TestStrucCommon.Nslice = z.DecodeBytesInto(([]byte)(x.TestStrucCommon.Nslice)) case "Nint64": if r.TryNil() { if x.TestStrucCommon.Nint64 != nil { // remove the if-true x.TestStrucCommon.Nint64 = nil } } else { if x.TestStrucCommon.Nint64 == nil { x.TestStrucCommon.Nint64 = new(int64) } *x.TestStrucCommon.Nint64 = (int64)(r.DecodeInt64()) } case "Chstr": h.decChanstring((*chan string)(&x.Chstr), d) case "Mis": z.F.DecMapIntStringX(&x.Mis, d) case "Mbu64": h.decMapboolc3RydWN0IHt9((*map[bool]struct{})(&x.Mbu64), d) case "Mu8e": h.decMapuint8c3RydWN0IHt9((*map[uint8]struct{})(&x.Mu8e), d) case "Mu8u64": h.decMapuint8stringUint64T((*map[uint8]stringUint64T)(&x.Mu8u64), d) case "Msp2ss": h.decMapPtrtostringSlicestring((*map[*string][]string)(&x.Msp2ss), d) case "Mip2ss": h.decMapPtrtouint64Slicestring((*map[*uint64][]string)(&x.Mip2ss), d) case "Ms2misu": h.decMapstringMapuint64stringUint64T((*map[string]map[uint64]stringUint64T)(&x.Ms2misu), d) case "Miwu64s": h.decMapintwrapUint64Slice((*map[int]wrapUint64Slice)(&x.Miwu64s), d) case "Mfwss": h.decMapfloat64wrapStringSlice((*map[float64]wrapStringSlice)(&x.Mfwss), d) case "Mf32wss": h.decMapfloat32wrapStringSlice((*map[float32]wrapStringSlice)(&x.Mf32wss), d) case "Mui2wss": h.decMapuint64wrapStringSlice((*map[uint64]wrapStringSlice)(&x.Mui2wss), d) case "Msu2wss": h.decMapstringUint64TwrapStringSlice((*map[stringUint64T]wrapStringSlice)(&x.Msu2wss), d) case "Ci64": if yyxt122 := z.Extension(x.Ci64); yyxt122 != nil { z.DecExtension(&x.Ci64, yyxt122) } else { x.Ci64.CodecDecodeSelf(d) } case "Swrapbytes": h.decSlicewrapBytes((*[]wrapBytes)(&x.Swrapbytes), d) case "Swrapuint8": h.decSlicewrapUint8((*[]wrapUint8)(&x.Swrapuint8), d) case "ArrStrUi64T": h.decArray4stringUint64T((*[4]stringUint64T)(&x.ArrStrUi64T), d) case "Ui64array": h.decArray4uint64((*[4]uint64)(&x.Ui64array), d) case "Ui64slicearray": h.decSlicePtrtoArray4uint64((*[]*[4]uint64)(&x.Ui64slicearray), d) case "SintfAarray": z.F.DecSliceIntfX(&x.SintfAarray, d) case "MstrUi64TSelf": h.decMapstringUint64TPtrtostringUint64T((*map[stringUint64T]*stringUint64T)(&x.MstrUi64TSelf), d) case "Ttime": if z.DecBasicHandle().TimeBuiltin() { x.Ttime = r.DecodeTime() } else if yyxt138 := z.Extension(x.Ttime); yyxt138 != nil { z.DecExtension(&x.Ttime, yyxt138) } else if z.DecBinary() { z.DecBinaryUnmarshal(&x.Ttime) } else if !z.DecBinary() && z.IsJSONHandle() { z.DecJSONUnmarshal(&x.Ttime) } else { z.DecFallback(&x.Ttime, false) } case "Ttimeptr": if r.TryNil() { if x.Ttimeptr != nil { // remove the if-true x.Ttimeptr = nil } } else { if x.Ttimeptr == nil { x.Ttimeptr = new(time.Time) } if z.DecBasicHandle().TimeBuiltin() { *x.Ttimeptr = r.DecodeTime() } else if yyxt140 := z.Extension(x.Ttimeptr); yyxt140 != nil { z.DecExtension(x.Ttimeptr, yyxt140) } else if z.DecBinary() { z.DecBinaryUnmarshal(x.Ttimeptr) } else if !z.DecBinary() && z.IsJSONHandle() { z.DecJSONUnmarshal(x.Ttimeptr) } else { z.DecFallback(x.Ttimeptr, false) } } case "Islice": if r.TryNil() { if x.AnonInTestStrucIntf != nil { // remove the if-true x.AnonInTestStrucIntf.Islice = nil } } else { if x.AnonInTestStrucIntf == nil { x.AnonInTestStrucIntf = new(AnonInTestStrucIntf) } z.F.DecSliceIntfX(&x.AnonInTestStrucIntf.Islice, d) } case "Ms": if r.TryNil() { if x.AnonInTestStrucIntf != nil { // remove the if-true x.AnonInTestStrucIntf.Ms = nil } } else { if x.AnonInTestStrucIntf == nil { x.AnonInTestStrucIntf = new(AnonInTestStrucIntf) } z.F.DecMapStringIntfX(&x.AnonInTestStrucIntf.Ms, d) } case "Nintf": if r.TryNil() { if x.AnonInTestStrucIntf != nil { // remove the if-true x.AnonInTestStrucIntf.Nintf = nil } } else { if x.AnonInTestStrucIntf == nil { x.AnonInTestStrucIntf = new(AnonInTestStrucIntf) } z.DecFallback(&x.AnonInTestStrucIntf.Nintf, true) } case "T": if r.TryNil() { if x.AnonInTestStrucIntf != nil { // remove the if-true x.AnonInTestStrucIntf.T = time.Time{} } } else { if x.AnonInTestStrucIntf == nil { x.AnonInTestStrucIntf = new(AnonInTestStrucIntf) } if z.DecBasicHandle().TimeBuiltin() { x.AnonInTestStrucIntf.T = r.DecodeTime() } else if yyxt148 := z.Extension(x.AnonInTestStrucIntf.T); yyxt148 != nil { z.DecExtension(&x.AnonInTestStrucIntf.T, yyxt148) } else if z.DecBinary() { z.DecBinaryUnmarshal(&x.AnonInTestStrucIntf.T) } else if !z.DecBinary() && z.IsJSONHandle() { z.DecJSONUnmarshal(&x.AnonInTestStrucIntf.T) } else { z.DecFallback(&x.AnonInTestStrucIntf.T, false) } } case "Tptr": if r.TryNil() { if x.AnonInTestStrucIntf != nil && x.AnonInTestStrucIntf.Tptr != nil { // remove the if-true x.AnonInTestStrucIntf.Tptr = nil } } else { if x.AnonInTestStrucIntf == nil { x.AnonInTestStrucIntf = new(AnonInTestStrucIntf) } if x.AnonInTestStrucIntf.Tptr == nil { x.AnonInTestStrucIntf.Tptr = new(time.Time) } if z.DecBasicHandle().TimeBuiltin() { *x.AnonInTestStrucIntf.Tptr = r.DecodeTime() } else if yyxt150 := z.Extension(x.AnonInTestStrucIntf.Tptr); yyxt150 != nil { z.DecExtension(x.AnonInTestStrucIntf.Tptr, yyxt150) } else if z.DecBinary() { z.DecBinaryUnmarshal(x.AnonInTestStrucIntf.Tptr) } else if !z.DecBinary() && z.IsJSONHandle() { z.DecJSONUnmarshal(x.AnonInTestStrucIntf.Tptr) } else { z.DecFallback(x.AnonInTestStrucIntf.Tptr, false) } } case "Msu": h.decMapwrapStringInterface((*map[wrapString]interface{})(&x.Msu), d) case "Mtsptr": h.decMapstringPtrtoTestStrucFlex((*map[string]*TestStrucFlex)(&x.Mtsptr), d) case "Mts": h.decMapstringTestStrucFlex((*map[string]TestStrucFlex)(&x.Mts), d) case "Its": h.decSlicePtrtoTestStrucFlex((*[]*TestStrucFlex)(&x.Its), d) case "Nteststruc": if r.TryNil() { if x.Nteststruc != nil { // remove the if-true x.Nteststruc = nil } } else { if x.Nteststruc == nil { x.Nteststruc = new(TestStrucFlex) } if yyxt160 := z.Extension(x.Nteststruc); yyxt160 != nil { z.DecExtension(x.Nteststruc, yyxt160) } else { x.Nteststruc.CodecDecodeSelf(d) } } case "MarJ": if yyxt162 := z.Extension(x.MarJ); yyxt162 != nil { z.DecExtension(&x.MarJ, yyxt162) } else { x.MarJ.CodecDecodeSelf(d) } case "MarT": if yyxt164 := z.Extension(x.MarT); yyxt164 != nil { z.DecExtension(&x.MarT, yyxt164) } else { x.MarT.CodecDecodeSelf(d) } case "MarB": if yyxt166 := z.Extension(x.MarB); yyxt166 != nil { z.DecExtension(&x.MarB, yyxt166) } else { x.MarB.CodecDecodeSelf(d) } case "XuintToBytes": if yyxt168 := z.Extension(x.XuintToBytes); yyxt168 != nil { z.DecExtension(&x.XuintToBytes, yyxt168) } else { x.XuintToBytes.CodecDecodeSelf(d) } case "Cmplx64": x.Cmplx64 = (complex64)(complex(z.DecDecodeFloat32(), 0)) case "Cmplx128": x.Cmplx128 = (complex128)(complex(r.DecodeFloat64(), 0)) default: z.DecStructFieldNotFound(-1, string(yys3)) } // end switch yys3 } // end for yyj3 } func (x *TestStrucFlex) codecDecodeSelfFromArray(l int, d *Decoder) { var h codecSelfer19780 z, r := GenHelper().Decoder(d) _, _, _ = h, z, r var yyj171 int var yyb171 bool var yyhl171 bool = l >= 0 yyj171++ if yyhl171 { yyb171 = yyj171 > l } else { yyb171 = z.DecCheckBreak() } if yyb171 { z.DecReadArrayEnd() return } z.DecReadArrayElem() x.TestStrucCommon.S = (string)(z.DecStringZC(r.DecodeStringAsBytes())) yyj171++ if yyhl171 { yyb171 = yyj171 > l } else { yyb171 = z.DecCheckBreak() } if yyb171 { z.DecReadArrayEnd() return } z.DecReadArrayElem() x.TestStrucCommon.I64 = (int64)(r.DecodeInt64()) yyj171++ if yyhl171 { yyb171 = yyj171 > l } else { yyb171 = z.DecCheckBreak() } if yyb171 { z.DecReadArrayEnd() return } z.DecReadArrayElem() x.TestStrucCommon.I32 = (int32)(z.C.IntV(r.DecodeInt64(), 32)) yyj171++ if yyhl171 { yyb171 = yyj171 > l } else { yyb171 = z.DecCheckBreak() } if yyb171 { z.DecReadArrayEnd() return } z.DecReadArrayElem() x.TestStrucCommon.I16 = (int16)(z.C.IntV(r.DecodeInt64(), 16)) yyj171++ if yyhl171 { yyb171 = yyj171 > l } else { yyb171 = z.DecCheckBreak() } if yyb171 { z.DecReadArrayEnd() return } z.DecReadArrayElem() x.TestStrucCommon.I8 = (int8)(z.C.IntV(r.DecodeInt64(), 8)) yyj171++ if yyhl171 { yyb171 = yyj171 > l } else { yyb171 = z.DecCheckBreak() } if yyb171 { z.DecReadArrayEnd() return } z.DecReadArrayElem() x.TestStrucCommon.I64n = (int64)(r.DecodeInt64()) yyj171++ if yyhl171 { yyb171 = yyj171 > l } else { yyb171 = z.DecCheckBreak() } if yyb171 { z.DecReadArrayEnd() return } z.DecReadArrayElem() x.TestStrucCommon.I32n = (int32)(z.C.IntV(r.DecodeInt64(), 32)) yyj171++ if yyhl171 { yyb171 = yyj171 > l } else { yyb171 = z.DecCheckBreak() } if yyb171 { z.DecReadArrayEnd() return } z.DecReadArrayElem() x.TestStrucCommon.I16n = (int16)(z.C.IntV(r.DecodeInt64(), 16)) yyj171++ if yyhl171 { yyb171 = yyj171 > l } else { yyb171 = z.DecCheckBreak() } if yyb171 { z.DecReadArrayEnd() return } z.DecReadArrayElem() x.TestStrucCommon.I8n = (int8)(z.C.IntV(r.DecodeInt64(), 8)) yyj171++ if yyhl171 { yyb171 = yyj171 > l } else { yyb171 = z.DecCheckBreak() } if yyb171 { z.DecReadArrayEnd() return } z.DecReadArrayElem() x.TestStrucCommon.Ui64 = (uint64)(r.DecodeUint64()) yyj171++ if yyhl171 { yyb171 = yyj171 > l } else { yyb171 = z.DecCheckBreak() } if yyb171 { z.DecReadArrayEnd() return } z.DecReadArrayElem() x.TestStrucCommon.Ui32 = (uint32)(z.C.UintV(r.DecodeUint64(), 32)) yyj171++ if yyhl171 { yyb171 = yyj171 > l } else { yyb171 = z.DecCheckBreak() } if yyb171 { z.DecReadArrayEnd() return } z.DecReadArrayElem() x.TestStrucCommon.Ui16 = (uint16)(z.C.UintV(r.DecodeUint64(), 16)) yyj171++ if yyhl171 { yyb171 = yyj171 > l } else { yyb171 = z.DecCheckBreak() } if yyb171 { z.DecReadArrayEnd() return } z.DecReadArrayElem() x.TestStrucCommon.Ui8 = (uint8)(z.C.UintV(r.DecodeUint64(), 8)) yyj171++ if yyhl171 { yyb171 = yyj171 > l } else { yyb171 = z.DecCheckBreak() } if yyb171 { z.DecReadArrayEnd() return } z.DecReadArrayElem() x.TestStrucCommon.F64 = (float64)(r.DecodeFloat64()) yyj171++ if yyhl171 { yyb171 = yyj171 > l } else { yyb171 = z.DecCheckBreak() } if yyb171 { z.DecReadArrayEnd() return } z.DecReadArrayElem() x.TestStrucCommon.F32 = (float32)(z.DecDecodeFloat32()) yyj171++ if yyhl171 { yyb171 = yyj171 > l } else { yyb171 = z.DecCheckBreak() } if yyb171 { z.DecReadArrayEnd() return } z.DecReadArrayElem() x.TestStrucCommon.B = (bool)(r.DecodeBool()) yyj171++ if yyhl171 { yyb171 = yyj171 > l } else { yyb171 = z.DecCheckBreak() } if yyb171 { z.DecReadArrayEnd() return } z.DecReadArrayElem() x.TestStrucCommon.By = (uint8)(z.C.UintV(r.DecodeUint64(), 8)) yyj171++ if yyhl171 { yyb171 = yyj171 > l } else { yyb171 = z.DecCheckBreak() } if yyb171 { z.DecReadArrayEnd() return } z.DecReadArrayElem() z.F.DecSliceStringX(&x.TestStrucCommon.Sslice, d) yyj171++ if yyhl171 { yyb171 = yyj171 > l } else { yyb171 = z.DecCheckBreak() } if yyb171 { z.DecReadArrayEnd() return } z.DecReadArrayElem() z.F.DecSliceInt64X(&x.TestStrucCommon.I64slice, d) yyj171++ if yyhl171 { yyb171 = yyj171 > l } else { yyb171 = z.DecCheckBreak() } if yyb171 { z.DecReadArrayEnd() return } z.DecReadArrayElem() z.F.DecSliceInt32X(&x.TestStrucCommon.I32slice, d) yyj171++ if yyhl171 { yyb171 = yyj171 > l } else { yyb171 = z.DecCheckBreak() } if yyb171 { z.DecReadArrayEnd() return } z.DecReadArrayElem() z.F.DecSliceUint64X(&x.TestStrucCommon.Ui64slice, d) yyj171++ if yyhl171 { yyb171 = yyj171 > l } else { yyb171 = z.DecCheckBreak() } if yyb171 { z.DecReadArrayEnd() return } z.DecReadArrayElem() x.TestStrucCommon.Ui8slice = z.DecodeBytesInto(([]byte)(x.TestStrucCommon.Ui8slice)) yyj171++ if yyhl171 { yyb171 = yyj171 > l } else { yyb171 = z.DecCheckBreak() } if yyb171 { z.DecReadArrayEnd() return } z.DecReadArrayElem() z.F.DecSliceBoolX(&x.TestStrucCommon.Bslice, d) yyj171++ if yyhl171 { yyb171 = yyj171 > l } else { yyb171 = z.DecCheckBreak() } if yyb171 { z.DecReadArrayEnd() return } z.DecReadArrayElem() x.TestStrucCommon.Byslice = z.DecodeBytesInto(([]byte)(x.TestStrucCommon.Byslice)) yyj171++ if yyhl171 { yyb171 = yyj171 > l } else { yyb171 = z.DecCheckBreak() } if yyb171 { z.DecReadArrayEnd() return } z.DecReadArrayElem() z.F.DecSliceBytesX(&x.TestStrucCommon.BytesSlice, d) yyj171++ if yyhl171 { yyb171 = yyj171 > l } else { yyb171 = z.DecCheckBreak() } if yyb171 { z.DecReadArrayEnd() return } z.DecReadArrayElem() h.decSlicePtrtoint64((*[]*int64)(&x.TestStrucCommon.Iptrslice), d) yyj171++ if yyhl171 { yyb171 = yyj171 > l } else { yyb171 = z.DecCheckBreak() } if yyb171 { z.DecReadArrayEnd() return } z.DecReadArrayElem() if yyxt208 := z.Extension(x.TestStrucCommon.WrapSliceInt64); yyxt208 != nil { z.DecExtension(&x.TestStrucCommon.WrapSliceInt64, yyxt208) } else { x.TestStrucCommon.WrapSliceInt64.CodecDecodeSelf(d) } yyj171++ if yyhl171 { yyb171 = yyj171 > l } else { yyb171 = z.DecCheckBreak() } if yyb171 { z.DecReadArrayEnd() return } z.DecReadArrayElem() if yyxt210 := z.Extension(x.TestStrucCommon.WrapSliceString); yyxt210 != nil { z.DecExtension(&x.TestStrucCommon.WrapSliceString, yyxt210) } else { x.TestStrucCommon.WrapSliceString.CodecDecodeSelf(d) } yyj171++ if yyhl171 { yyb171 = yyj171 > l } else { yyb171 = z.DecCheckBreak() } if yyb171 { z.DecReadArrayEnd() return } z.DecReadArrayElem() z.F.DecMapStringIntX(&x.TestStrucCommon.Msint, d) yyj171++ if yyhl171 { yyb171 = yyj171 > l } else { yyb171 = z.DecCheckBreak() } if yyb171 { z.DecReadArrayEnd() return } z.DecReadArrayElem() z.F.DecMapStringBytesX(&x.TestStrucCommon.Msbytes, d) yyj171++ if yyhl171 { yyb171 = yyj171 > l } else { yyb171 = z.DecCheckBreak() } if yyb171 { z.DecReadArrayEnd() return } z.DecReadArrayElem() if yyxt216 := z.Extension(x.TestStrucCommon.Simplef); yyxt216 != nil { z.DecExtension(&x.TestStrucCommon.Simplef, yyxt216) } else { x.TestStrucCommon.Simplef.CodecDecodeSelf(d) } yyj171++ if yyhl171 { yyb171 = yyj171 > l } else { yyb171 = z.DecCheckBreak() } if yyb171 { z.DecReadArrayEnd() return } z.DecReadArrayElem() h.decSlicestringUint64T((*[]stringUint64T)(&x.TestStrucCommon.SstrUi64T), d) yyj171++ if yyhl171 { yyb171 = yyj171 > l } else { yyb171 = z.DecCheckBreak() } if yyb171 { z.DecReadArrayEnd() return } z.DecReadArrayElem() h.decMapstringPtrtostringUint64T((*map[string]*stringUint64T)(&x.TestStrucCommon.MstrUi64T), d) yyj171++ if yyhl171 { yyb171 = yyj171 > l } else { yyb171 = z.DecCheckBreak() } if yyb171 { z.DecReadArrayEnd() return } z.DecReadArrayElem() x.TestStrucCommon.AnonInTestStruc.AS = (string)(z.DecStringZC(r.DecodeStringAsBytes())) yyj171++ if yyhl171 { yyb171 = yyj171 > l } else { yyb171 = z.DecCheckBreak() } if yyb171 { z.DecReadArrayEnd() return } z.DecReadArrayElem() x.TestStrucCommon.AnonInTestStruc.AI64 = (int64)(r.DecodeInt64()) yyj171++ if yyhl171 { yyb171 = yyj171 > l } else { yyb171 = z.DecCheckBreak() } if yyb171 { z.DecReadArrayEnd() return } z.DecReadArrayElem() x.TestStrucCommon.AnonInTestStruc.AI16 = (int16)(z.C.IntV(r.DecodeInt64(), 16)) yyj171++ if yyhl171 { yyb171 = yyj171 > l } else { yyb171 = z.DecCheckBreak() } if yyb171 { z.DecReadArrayEnd() return } z.DecReadArrayElem() x.TestStrucCommon.AnonInTestStruc.AUi64 = (uint64)(r.DecodeUint64()) yyj171++ if yyhl171 { yyb171 = yyj171 > l } else { yyb171 = z.DecCheckBreak() } if yyb171 { z.DecReadArrayEnd() return } z.DecReadArrayElem() z.F.DecSliceStringX(&x.TestStrucCommon.AnonInTestStruc.ASslice, d) yyj171++ if yyhl171 { yyb171 = yyj171 > l } else { yyb171 = z.DecCheckBreak() } if yyb171 { z.DecReadArrayEnd() return } z.DecReadArrayElem() z.F.DecSliceInt64X(&x.TestStrucCommon.AnonInTestStruc.AI64slice, d) yyj171++ if yyhl171 { yyb171 = yyj171 > l } else { yyb171 = z.DecCheckBreak() } if yyb171 { z.DecReadArrayEnd() return } z.DecReadArrayElem() z.F.DecSliceUint64X(&x.TestStrucCommon.AnonInTestStruc.AUi64slice, d) yyj171++ if yyhl171 { yyb171 = yyj171 > l } else { yyb171 = z.DecCheckBreak() } if yyb171 { z.DecReadArrayEnd() return } z.DecReadArrayElem() z.F.DecSliceFloat64X(&x.TestStrucCommon.AnonInTestStruc.AF64slice, d) yyj171++ if yyhl171 { yyb171 = yyj171 > l } else { yyb171 = z.DecCheckBreak() } if yyb171 { z.DecReadArrayEnd() return } z.DecReadArrayElem() z.F.DecSliceFloat32X(&x.TestStrucCommon.AnonInTestStruc.AF32slice, d) yyj171++ if yyhl171 { yyb171 = yyj171 > l } else { yyb171 = z.DecCheckBreak() } if yyb171 { z.DecReadArrayEnd() return } z.DecReadArrayElem() z.F.DecMapStringStringX(&x.TestStrucCommon.AnonInTestStruc.AMSS, d) yyj171++ if yyhl171 { yyb171 = yyj171 > l } else { yyb171 = z.DecCheckBreak() } if yyb171 { z.DecReadArrayEnd() return } z.DecReadArrayElem() z.F.DecMapStringUint64X(&x.TestStrucCommon.AnonInTestStruc.AMSU64, d) yyj171++ if yyhl171 { yyb171 = yyj171 > l } else { yyb171 = z.DecCheckBreak() } if yyb171 { z.DecReadArrayEnd() return } z.DecReadArrayElem() h.decArray8int64((*[8]int64)(&x.TestStrucCommon.AnonInTestStruc.AI64arr8), d) yyj171++ if yyhl171 { yyb171 = yyj171 > l } else { yyb171 = z.DecCheckBreak() } if yyb171 { z.DecReadArrayEnd() return } z.DecReadArrayElem() h.decArray0int64((*[0]int64)(&x.TestStrucCommon.AnonInTestStruc.AI64arr0), d) yyj171++ if yyhl171 { yyb171 = yyj171 > l } else { yyb171 = z.DecCheckBreak() } if yyb171 { z.DecReadArrayEnd() return } z.DecReadArrayElem() z.F.DecSliceInt64X(&x.TestStrucCommon.AnonInTestStruc.AI64slice0, d) yyj171++ if yyhl171 { yyb171 = yyj171 > l } else { yyb171 = z.DecCheckBreak() } if yyb171 { z.DecReadArrayEnd() return } z.DecReadArrayElem() z.F.DecSliceUint64X(&x.TestStrucCommon.AnonInTestStruc.AUi64sliceN, d) yyj171++ if yyhl171 { yyb171 = yyj171 > l } else { yyb171 = z.DecCheckBreak() } if yyb171 { z.DecReadArrayEnd() return } z.DecReadArrayElem() z.F.DecMapStringUint64X(&x.TestStrucCommon.AnonInTestStruc.AMSU64N, d) yyj171++ if yyhl171 { yyb171 = yyj171 > l } else { yyb171 = z.DecCheckBreak() } if yyb171 { z.DecReadArrayEnd() return } z.DecReadArrayElem() z.F.DecMapStringUint64X(&x.TestStrucCommon.AnonInTestStruc.AMSU64E, d) yyj171++ if yyhl171 { yyb171 = yyj171 > l } else { yyb171 = z.DecCheckBreak() } if yyb171 { z.DecReadArrayEnd() return } z.DecReadArrayElem() if yyxt252 := z.Extension(x.TestStrucCommon.NotAnon); yyxt252 != nil { z.DecExtension(&x.TestStrucCommon.NotAnon, yyxt252) } else { x.TestStrucCommon.NotAnon.CodecDecodeSelf(d) } yyj171++ if yyhl171 { yyb171 = yyj171 > l } else { yyb171 = z.DecCheckBreak() } if yyb171 { z.DecReadArrayEnd() return } z.DecReadArrayElem() if r.TryNil() { if x.TestStrucCommon.AnonInTestStrucSlim != nil && x.TestStrucCommon.AnonInTestStrucSlim.P != nil { // remove the if-true x.TestStrucCommon.AnonInTestStrucSlim.P = nil } } else { if x.TestStrucCommon.AnonInTestStrucSlim == nil { x.TestStrucCommon.AnonInTestStrucSlim = new(AnonInTestStrucSlim) } if x.TestStrucCommon.AnonInTestStrucSlim.P == nil { x.TestStrucCommon.AnonInTestStrucSlim.P = new(string) } *x.TestStrucCommon.AnonInTestStrucSlim.P = (string)(z.DecStringZC(r.DecodeStringAsBytes())) } yyj171++ if yyhl171 { yyb171 = yyj171 > l } else { yyb171 = z.DecCheckBreak() } if yyb171 { z.DecReadArrayEnd() return } z.DecReadArrayElem() if r.TryNil() { if x.TestStrucCommon.NotAnonSlim != nil { // remove the if-true x.TestStrucCommon.NotAnonSlim = nil } } else { if x.TestStrucCommon.NotAnonSlim == nil { x.TestStrucCommon.NotAnonSlim = new(AnonInTestStrucSlim) } if yyxt256 := z.Extension(x.TestStrucCommon.NotAnonSlim); yyxt256 != nil { z.DecExtension(x.TestStrucCommon.NotAnonSlim, yyxt256) } else { x.TestStrucCommon.NotAnonSlim.CodecDecodeSelf(d) } } yyj171++ if yyhl171 { yyb171 = yyj171 > l } else { yyb171 = z.DecCheckBreak() } if yyb171 { z.DecReadArrayEnd() return } z.DecReadArrayElem() z.F.DecMapStringBoolX(&x.TestStrucCommon.Nmap, d) yyj171++ if yyhl171 { yyb171 = yyj171 > l } else { yyb171 = z.DecCheckBreak() } if yyb171 { z.DecReadArrayEnd() return } z.DecReadArrayElem() x.TestStrucCommon.Nslice = z.DecodeBytesInto(([]byte)(x.TestStrucCommon.Nslice)) yyj171++ if yyhl171 { yyb171 = yyj171 > l } else { yyb171 = z.DecCheckBreak() } if yyb171 { z.DecReadArrayEnd() return } z.DecReadArrayElem() if r.TryNil() { if x.TestStrucCommon.Nint64 != nil { // remove the if-true x.TestStrucCommon.Nint64 = nil } } else { if x.TestStrucCommon.Nint64 == nil { x.TestStrucCommon.Nint64 = new(int64) } *x.TestStrucCommon.Nint64 = (int64)(r.DecodeInt64()) } yyj171++ if yyhl171 { yyb171 = yyj171 > l } else { yyb171 = z.DecCheckBreak() } if yyb171 { z.DecReadArrayEnd() return } z.DecReadArrayElem() h.decChanstring((*chan string)(&x.Chstr), d) yyj171++ if yyhl171 { yyb171 = yyj171 > l } else { yyb171 = z.DecCheckBreak() } if yyb171 { z.DecReadArrayEnd() return } z.DecReadArrayElem() z.F.DecMapIntStringX(&x.Mis, d) yyj171++ if yyhl171 { yyb171 = yyj171 > l } else { yyb171 = z.DecCheckBreak() } if yyb171 { z.DecReadArrayEnd() return } z.DecReadArrayElem() h.decMapboolc3RydWN0IHt9((*map[bool]struct{})(&x.Mbu64), d) yyj171++ if yyhl171 { yyb171 = yyj171 > l } else { yyb171 = z.DecCheckBreak() } if yyb171 { z.DecReadArrayEnd() return } z.DecReadArrayElem() h.decMapuint8c3RydWN0IHt9((*map[uint8]struct{})(&x.Mu8e), d) yyj171++ if yyhl171 { yyb171 = yyj171 > l } else { yyb171 = z.DecCheckBreak() } if yyb171 { z.DecReadArrayEnd() return } z.DecReadArrayElem() h.decMapuint8stringUint64T((*map[uint8]stringUint64T)(&x.Mu8u64), d) yyj171++ if yyhl171 { yyb171 = yyj171 > l } else { yyb171 = z.DecCheckBreak() } if yyb171 { z.DecReadArrayEnd() return } z.DecReadArrayElem() h.decMapPtrtostringSlicestring((*map[*string][]string)(&x.Msp2ss), d) yyj171++ if yyhl171 { yyb171 = yyj171 > l } else { yyb171 = z.DecCheckBreak() } if yyb171 { z.DecReadArrayEnd() return } z.DecReadArrayElem() h.decMapPtrtouint64Slicestring((*map[*uint64][]string)(&x.Mip2ss), d) yyj171++ if yyhl171 { yyb171 = yyj171 > l } else { yyb171 = z.DecCheckBreak() } if yyb171 { z.DecReadArrayEnd() return } z.DecReadArrayElem() h.decMapstringMapuint64stringUint64T((*map[string]map[uint64]stringUint64T)(&x.Ms2misu), d) yyj171++ if yyhl171 { yyb171 = yyj171 > l } else { yyb171 = z.DecCheckBreak() } if yyb171 { z.DecReadArrayEnd() return } z.DecReadArrayElem() h.decMapintwrapUint64Slice((*map[int]wrapUint64Slice)(&x.Miwu64s), d) yyj171++ if yyhl171 { yyb171 = yyj171 > l } else { yyb171 = z.DecCheckBreak() } if yyb171 { z.DecReadArrayEnd() return } z.DecReadArrayElem() h.decMapfloat64wrapStringSlice((*map[float64]wrapStringSlice)(&x.Mfwss), d) yyj171++ if yyhl171 { yyb171 = yyj171 > l } else { yyb171 = z.DecCheckBreak() } if yyb171 { z.DecReadArrayEnd() return } z.DecReadArrayElem() h.decMapfloat32wrapStringSlice((*map[float32]wrapStringSlice)(&x.Mf32wss), d) yyj171++ if yyhl171 { yyb171 = yyj171 > l } else { yyb171 = z.DecCheckBreak() } if yyb171 { z.DecReadArrayEnd() return } z.DecReadArrayElem() h.decMapuint64wrapStringSlice((*map[uint64]wrapStringSlice)(&x.Mui2wss), d) yyj171++ if yyhl171 { yyb171 = yyj171 > l } else { yyb171 = z.DecCheckBreak() } if yyb171 { z.DecReadArrayEnd() return } z.DecReadArrayElem() h.decMapstringUint64TwrapStringSlice((*map[stringUint64T]wrapStringSlice)(&x.Msu2wss), d) yyj171++ if yyhl171 { yyb171 = yyj171 > l } else { yyb171 = z.DecCheckBreak() } if yyb171 { z.DecReadArrayEnd() return } z.DecReadArrayElem() if yyxt290 := z.Extension(x.Ci64); yyxt290 != nil { z.DecExtension(&x.Ci64, yyxt290) } else { x.Ci64.CodecDecodeSelf(d) } yyj171++ if yyhl171 { yyb171 = yyj171 > l } else { yyb171 = z.DecCheckBreak() } if yyb171 { z.DecReadArrayEnd() return } z.DecReadArrayElem() h.decSlicewrapBytes((*[]wrapBytes)(&x.Swrapbytes), d) yyj171++ if yyhl171 { yyb171 = yyj171 > l } else { yyb171 = z.DecCheckBreak() } if yyb171 { z.DecReadArrayEnd() return } z.DecReadArrayElem() h.decSlicewrapUint8((*[]wrapUint8)(&x.Swrapuint8), d) yyj171++ if yyhl171 { yyb171 = yyj171 > l } else { yyb171 = z.DecCheckBreak() } if yyb171 { z.DecReadArrayEnd() return } z.DecReadArrayElem() h.decArray4stringUint64T((*[4]stringUint64T)(&x.ArrStrUi64T), d) yyj171++ if yyhl171 { yyb171 = yyj171 > l } else { yyb171 = z.DecCheckBreak() } if yyb171 { z.DecReadArrayEnd() return } z.DecReadArrayElem() h.decArray4uint64((*[4]uint64)(&x.Ui64array), d) yyj171++ if yyhl171 { yyb171 = yyj171 > l } else { yyb171 = z.DecCheckBreak() } if yyb171 { z.DecReadArrayEnd() return } z.DecReadArrayElem() h.decSlicePtrtoArray4uint64((*[]*[4]uint64)(&x.Ui64slicearray), d) yyj171++ if yyhl171 { yyb171 = yyj171 > l } else { yyb171 = z.DecCheckBreak() } if yyb171 { z.DecReadArrayEnd() return } z.DecReadArrayElem() z.F.DecSliceIntfX(&x.SintfAarray, d) yyj171++ if yyhl171 { yyb171 = yyj171 > l } else { yyb171 = z.DecCheckBreak() } if yyb171 { z.DecReadArrayEnd() return } z.DecReadArrayElem() h.decMapstringUint64TPtrtostringUint64T((*map[stringUint64T]*stringUint64T)(&x.MstrUi64TSelf), d) yyj171++ if yyhl171 { yyb171 = yyj171 > l } else { yyb171 = z.DecCheckBreak() } if yyb171 { z.DecReadArrayEnd() return } z.DecReadArrayElem() if z.DecBasicHandle().TimeBuiltin() { x.Ttime = r.DecodeTime() } else if yyxt306 := z.Extension(x.Ttime); yyxt306 != nil { z.DecExtension(&x.Ttime, yyxt306) } else if z.DecBinary() { z.DecBinaryUnmarshal(&x.Ttime) } else if !z.DecBinary() && z.IsJSONHandle() { z.DecJSONUnmarshal(&x.Ttime) } else { z.DecFallback(&x.Ttime, false) } yyj171++ if yyhl171 { yyb171 = yyj171 > l } else { yyb171 = z.DecCheckBreak() } if yyb171 { z.DecReadArrayEnd() return } z.DecReadArrayElem() if r.TryNil() { if x.Ttimeptr != nil { // remove the if-true x.Ttimeptr = nil } } else { if x.Ttimeptr == nil { x.Ttimeptr = new(time.Time) } if z.DecBasicHandle().TimeBuiltin() { *x.Ttimeptr = r.DecodeTime() } else if yyxt308 := z.Extension(x.Ttimeptr); yyxt308 != nil { z.DecExtension(x.Ttimeptr, yyxt308) } else if z.DecBinary() { z.DecBinaryUnmarshal(x.Ttimeptr) } else if !z.DecBinary() && z.IsJSONHandle() { z.DecJSONUnmarshal(x.Ttimeptr) } else { z.DecFallback(x.Ttimeptr, false) } } yyj171++ if yyhl171 { yyb171 = yyj171 > l } else { yyb171 = z.DecCheckBreak() } if yyb171 { z.DecReadArrayEnd() return } z.DecReadArrayElem() if r.TryNil() { if x.AnonInTestStrucIntf != nil { // remove the if-true x.AnonInTestStrucIntf.Islice = nil } } else { if x.AnonInTestStrucIntf == nil { x.AnonInTestStrucIntf = new(AnonInTestStrucIntf) } z.F.DecSliceIntfX(&x.AnonInTestStrucIntf.Islice, d) } yyj171++ if yyhl171 { yyb171 = yyj171 > l } else { yyb171 = z.DecCheckBreak() } if yyb171 { z.DecReadArrayEnd() return } z.DecReadArrayElem() if r.TryNil() { if x.AnonInTestStrucIntf != nil { // remove the if-true x.AnonInTestStrucIntf.Ms = nil } } else { if x.AnonInTestStrucIntf == nil { x.AnonInTestStrucIntf = new(AnonInTestStrucIntf) } z.F.DecMapStringIntfX(&x.AnonInTestStrucIntf.Ms, d) } yyj171++ if yyhl171 { yyb171 = yyj171 > l } else { yyb171 = z.DecCheckBreak() } if yyb171 { z.DecReadArrayEnd() return } z.DecReadArrayElem() if r.TryNil() { if x.AnonInTestStrucIntf != nil { // remove the if-true x.AnonInTestStrucIntf.Nintf = nil } } else { if x.AnonInTestStrucIntf == nil { x.AnonInTestStrucIntf = new(AnonInTestStrucIntf) } z.DecFallback(&x.AnonInTestStrucIntf.Nintf, true) } yyj171++ if yyhl171 { yyb171 = yyj171 > l } else { yyb171 = z.DecCheckBreak() } if yyb171 { z.DecReadArrayEnd() return } z.DecReadArrayElem() if r.TryNil() { if x.AnonInTestStrucIntf != nil { // remove the if-true x.AnonInTestStrucIntf.T = time.Time{} } } else { if x.AnonInTestStrucIntf == nil { x.AnonInTestStrucIntf = new(AnonInTestStrucIntf) } if z.DecBasicHandle().TimeBuiltin() { x.AnonInTestStrucIntf.T = r.DecodeTime() } else if yyxt316 := z.Extension(x.AnonInTestStrucIntf.T); yyxt316 != nil { z.DecExtension(&x.AnonInTestStrucIntf.T, yyxt316) } else if z.DecBinary() { z.DecBinaryUnmarshal(&x.AnonInTestStrucIntf.T) } else if !z.DecBinary() && z.IsJSONHandle() { z.DecJSONUnmarshal(&x.AnonInTestStrucIntf.T) } else { z.DecFallback(&x.AnonInTestStrucIntf.T, false) } } yyj171++ if yyhl171 { yyb171 = yyj171 > l } else { yyb171 = z.DecCheckBreak() } if yyb171 { z.DecReadArrayEnd() return } z.DecReadArrayElem() if r.TryNil() { if x.AnonInTestStrucIntf != nil && x.AnonInTestStrucIntf.Tptr != nil { // remove the if-true x.AnonInTestStrucIntf.Tptr = nil } } else { if x.AnonInTestStrucIntf == nil { x.AnonInTestStrucIntf = new(AnonInTestStrucIntf) } if x.AnonInTestStrucIntf.Tptr == nil { x.AnonInTestStrucIntf.Tptr = new(time.Time) } if z.DecBasicHandle().TimeBuiltin() { *x.AnonInTestStrucIntf.Tptr = r.DecodeTime() } else if yyxt318 := z.Extension(x.AnonInTestStrucIntf.Tptr); yyxt318 != nil { z.DecExtension(x.AnonInTestStrucIntf.Tptr, yyxt318) } else if z.DecBinary() { z.DecBinaryUnmarshal(x.AnonInTestStrucIntf.Tptr) } else if !z.DecBinary() && z.IsJSONHandle() { z.DecJSONUnmarshal(x.AnonInTestStrucIntf.Tptr) } else { z.DecFallback(x.AnonInTestStrucIntf.Tptr, false) } } yyj171++ if yyhl171 { yyb171 = yyj171 > l } else { yyb171 = z.DecCheckBreak() } if yyb171 { z.DecReadArrayEnd() return } z.DecReadArrayElem() h.decMapwrapStringInterface((*map[wrapString]interface{})(&x.Msu), d) yyj171++ if yyhl171 { yyb171 = yyj171 > l } else { yyb171 = z.DecCheckBreak() } if yyb171 { z.DecReadArrayEnd() return } z.DecReadArrayElem() h.decMapstringPtrtoTestStrucFlex((*map[string]*TestStrucFlex)(&x.Mtsptr), d) yyj171++ if yyhl171 { yyb171 = yyj171 > l } else { yyb171 = z.DecCheckBreak() } if yyb171 { z.DecReadArrayEnd() return } z.DecReadArrayElem() h.decMapstringTestStrucFlex((*map[string]TestStrucFlex)(&x.Mts), d) yyj171++ if yyhl171 { yyb171 = yyj171 > l } else { yyb171 = z.DecCheckBreak() } if yyb171 { z.DecReadArrayEnd() return } z.DecReadArrayElem() h.decSlicePtrtoTestStrucFlex((*[]*TestStrucFlex)(&x.Its), d) yyj171++ if yyhl171 { yyb171 = yyj171 > l } else { yyb171 = z.DecCheckBreak() } if yyb171 { z.DecReadArrayEnd() return } z.DecReadArrayElem() if r.TryNil() { if x.Nteststruc != nil { // remove the if-true x.Nteststruc = nil } } else { if x.Nteststruc == nil { x.Nteststruc = new(TestStrucFlex) } if yyxt328 := z.Extension(x.Nteststruc); yyxt328 != nil { z.DecExtension(x.Nteststruc, yyxt328) } else { x.Nteststruc.CodecDecodeSelf(d) } } yyj171++ if yyhl171 { yyb171 = yyj171 > l } else { yyb171 = z.DecCheckBreak() } if yyb171 { z.DecReadArrayEnd() return } z.DecReadArrayElem() if yyxt330 := z.Extension(x.MarJ); yyxt330 != nil { z.DecExtension(&x.MarJ, yyxt330) } else { x.MarJ.CodecDecodeSelf(d) } yyj171++ if yyhl171 { yyb171 = yyj171 > l } else { yyb171 = z.DecCheckBreak() } if yyb171 { z.DecReadArrayEnd() return } z.DecReadArrayElem() if yyxt332 := z.Extension(x.MarT); yyxt332 != nil { z.DecExtension(&x.MarT, yyxt332) } else { x.MarT.CodecDecodeSelf(d) } yyj171++ if yyhl171 { yyb171 = yyj171 > l } else { yyb171 = z.DecCheckBreak() } if yyb171 { z.DecReadArrayEnd() return } z.DecReadArrayElem() if yyxt334 := z.Extension(x.MarB); yyxt334 != nil { z.DecExtension(&x.MarB, yyxt334) } else { x.MarB.CodecDecodeSelf(d) } yyj171++ if yyhl171 { yyb171 = yyj171 > l } else { yyb171 = z.DecCheckBreak() } if yyb171 { z.DecReadArrayEnd() return } z.DecReadArrayElem() if yyxt336 := z.Extension(x.XuintToBytes); yyxt336 != nil { z.DecExtension(&x.XuintToBytes, yyxt336) } else { x.XuintToBytes.CodecDecodeSelf(d) } yyj171++ if yyhl171 { yyb171 = yyj171 > l } else { yyb171 = z.DecCheckBreak() } if yyb171 { z.DecReadArrayEnd() return } z.DecReadArrayElem() x.Cmplx64 = (complex64)(complex(z.DecDecodeFloat32(), 0)) yyj171++ if yyhl171 { yyb171 = yyj171 > l } else { yyb171 = z.DecCheckBreak() } if yyb171 { z.DecReadArrayEnd() return } z.DecReadArrayElem() x.Cmplx128 = (complex128)(complex(r.DecodeFloat64(), 0)) for { yyj171++ if yyhl171 { yyb171 = yyj171 > l } else { yyb171 = z.DecCheckBreak() } if yyb171 { break } z.DecReadArrayElem() z.DecStructFieldNotFound(yyj171-1, "") } } func (x *TestStrucFlex) IsCodecEmpty() bool { return !(!(x.TestStrucCommon.IsCodecEmpty()) || len(x.Chstr) != 0 || len(x.Mis) != 0 || len(x.Mbu64) != 0 || len(x.Mu8e) != 0 || len(x.Mu8u64) != 0 || len(x.Msp2ss) != 0 || len(x.Mip2ss) != 0 || len(x.Ms2misu) != 0 || len(x.Miwu64s) != 0 || len(x.Mfwss) != 0 || len(x.Mf32wss) != 0 || len(x.Mui2wss) != 0 || len(x.Msu2wss) != 0 || x.Ci64 != 0 || len(x.Swrapbytes) != 0 || len(x.Swrapuint8) != 0 || x.ArrStrUi64T != [4]stringUint64T{} || x.Ui64array != [4]uint64{} || len(x.Ui64slicearray) != 0 || len(x.SintfAarray) != 0 || len(x.MstrUi64TSelf) != 0 || !(x.Ttime.IsZero()) || x.AnonInTestStrucIntf != nil && len(x.Msu) != 0 || len(x.Mtsptr) != 0 || len(x.Mts) != 0 || len(x.Its) != 0 || bool(x.MarJ) || x.MarT != "" || len(x.MarB) != 0 || x.XuintToBytes != 0 || x.Cmplx64 != 0 || x.Cmplx128 != 0 || false) } func (x codecSelfer19780) encwrapUint64Slice(v wrapUint64Slice, e *Encoder) { var h codecSelfer19780 z, r := GenHelper().Encoder(e) _, _, _ = h, z, r if v == nil { r.EncodeNil() return } z.EncWriteArrayStart(len(v)) for yyv1 := range v { z.EncWriteArrayElem() if yyxt2 := z.Extension(v[yyv1]); yyxt2 != nil { z.EncExtension(v[yyv1], yyxt2) } else { v[yyv1].CodecEncodeSelf(e) } } z.EncWriteArrayEnd() } func (x codecSelfer19780) decwrapUint64Slice(v *wrapUint64Slice, d *Decoder) { var h codecSelfer19780 z, r := GenHelper().Decoder(d) _, _, _ = h, z, r yyv1 := *v yyh1, yyl1 := z.DecSliceHelperStart() var yyc1 bool _ = yyc1 if yyh1.IsNil { if yyv1 != nil { yyv1 = nil yyc1 = true } } else if yyl1 == 0 { if yyv1 == nil { yyv1 = []wrapUint64{} yyc1 = true } else if len(yyv1) != 0 { yyv1 = yyv1[:0] yyc1 = true } } else { yyhl1 := yyl1 > 0 var yyrl1 int _ = yyrl1 if yyhl1 { if yyl1 > cap(yyv1) { yyrl1 = z.DecInferLen(yyl1, z.DecBasicHandle().MaxInitLen, 8) if yyrl1 <= cap(yyv1) { yyv1 = yyv1[:yyrl1] } else { yyv1 = make([]wrapUint64, yyrl1) } yyc1 = true } else if yyl1 != len(yyv1) { yyv1 = yyv1[:yyl1] yyc1 = true } } var yyj1 int for yyj1 = 0; (yyhl1 && yyj1 < yyl1) || !(yyhl1 || z.DecCheckBreak()); yyj1++ { // bounds-check-elimination if yyj1 == 0 && yyv1 == nil { if yyhl1 { yyrl1 = z.DecInferLen(yyl1, z.DecBasicHandle().MaxInitLen, 8) } else { yyrl1 = 8 } yyv1 = make([]wrapUint64, yyrl1) yyc1 = true } yyh1.ElemContainerState(yyj1) var yydb1 bool if yyj1 >= len(yyv1) { yyv1 = append(yyv1, 0) yyc1 = true } if yydb1 { z.DecSwallow() } else { if yyxt3 := z.Extension(yyv1[yyj1]); yyxt3 != nil { z.DecExtension(&yyv1[yyj1], yyxt3) } else { yyv1[yyj1].CodecDecodeSelf(d) } } } if yyj1 < len(yyv1) { yyv1 = yyv1[:yyj1] yyc1 = true } else if yyj1 == 0 && yyv1 == nil { yyv1 = []wrapUint64{} yyc1 = true } } yyh1.End() if yyc1 { *v = yyv1 } } func (x codecSelfer19780) encwrapStringSlice(v wrapStringSlice, e *Encoder) { var h codecSelfer19780 z, r := GenHelper().Encoder(e) _, _, _ = h, z, r if v == nil { r.EncodeNil() return } z.EncWriteArrayStart(len(v)) for yyv1 := range v { z.EncWriteArrayElem() if yyxt2 := z.Extension(v[yyv1]); yyxt2 != nil { z.EncExtension(v[yyv1], yyxt2) } else { v[yyv1].CodecEncodeSelf(e) } } z.EncWriteArrayEnd() } func (x codecSelfer19780) decwrapStringSlice(v *wrapStringSlice, d *Decoder) { var h codecSelfer19780 z, r := GenHelper().Decoder(d) _, _, _ = h, z, r yyv1 := *v yyh1, yyl1 := z.DecSliceHelperStart() var yyc1 bool _ = yyc1 if yyh1.IsNil { if yyv1 != nil { yyv1 = nil yyc1 = true } } else if yyl1 == 0 { if yyv1 == nil { yyv1 = []wrapString{} yyc1 = true } else if len(yyv1) != 0 { yyv1 = yyv1[:0] yyc1 = true } } else { yyhl1 := yyl1 > 0 var yyrl1 int _ = yyrl1 if yyhl1 { if yyl1 > cap(yyv1) { yyrl1 = z.DecInferLen(yyl1, z.DecBasicHandle().MaxInitLen, 16) if yyrl1 <= cap(yyv1) { yyv1 = yyv1[:yyrl1] } else { yyv1 = make([]wrapString, yyrl1) } yyc1 = true } else if yyl1 != len(yyv1) { yyv1 = yyv1[:yyl1] yyc1 = true } } var yyj1 int for yyj1 = 0; (yyhl1 && yyj1 < yyl1) || !(yyhl1 || z.DecCheckBreak()); yyj1++ { // bounds-check-elimination if yyj1 == 0 && yyv1 == nil { if yyhl1 { yyrl1 = z.DecInferLen(yyl1, z.DecBasicHandle().MaxInitLen, 16) } else { yyrl1 = 8 } yyv1 = make([]wrapString, yyrl1) yyc1 = true } yyh1.ElemContainerState(yyj1) var yydb1 bool if yyj1 >= len(yyv1) { yyv1 = append(yyv1, "") yyc1 = true } if yydb1 { z.DecSwallow() } else { if yyxt3 := z.Extension(yyv1[yyj1]); yyxt3 != nil { z.DecExtension(&yyv1[yyj1], yyxt3) } else { yyv1[yyj1].CodecDecodeSelf(d) } } } if yyj1 < len(yyv1) { yyv1 = yyv1[:yyj1] yyc1 = true } else if yyj1 == 0 && yyv1 == nil { yyv1 = []wrapString{} yyc1 = true } } yyh1.End() if yyc1 { *v = yyv1 } } func (x codecSelfer19780) encArray8int64(v *[8]int64, e *Encoder) { var h codecSelfer19780 z, r := GenHelper().Encoder(e) _, _, _ = h, z, r if v == nil { r.EncodeNil() return } z.EncWriteArrayStart(len(v)) for yyv1 := range v { z.EncWriteArrayElem() r.EncodeInt(int64(v[yyv1])) } z.EncWriteArrayEnd() } func (x codecSelfer19780) decArray8int64(v *[8]int64, d *Decoder) { var h codecSelfer19780 z, r := GenHelper().Decoder(d) _, _, _ = h, z, r yyv1 := v yyh1, yyl1 := z.DecSliceHelperStart() if yyl1 == 0 { } else { yyhl1 := yyl1 > 0 var yyrl1 int _ = yyrl1 var yyj1 int for yyj1 = 0; (yyhl1 && yyj1 < yyl1) || !(yyhl1 || z.DecCheckBreak()); yyj1++ { // bounds-check-elimination yyh1.ElemContainerState(yyj1) var yydb1 bool if yyj1 >= len(yyv1) { z.DecArrayCannotExpand(len(v), yyj1+1) yydb1 = true } if yydb1 { z.DecSwallow() } else { yyv1[yyj1] = (int64)(r.DecodeInt64()) } } } yyh1.End() } func (x codecSelfer19780) encArray0int64(v *[0]int64, e *Encoder) { var h codecSelfer19780 z, r := GenHelper().Encoder(e) _, _, _ = h, z, r if v == nil { r.EncodeNil() return } z.EncWriteArrayStart(len(v)) for yyv1 := range v { z.EncWriteArrayElem() r.EncodeInt(int64(v[yyv1])) } z.EncWriteArrayEnd() } func (x codecSelfer19780) decArray0int64(v *[0]int64, d *Decoder) { var h codecSelfer19780 z, r := GenHelper().Decoder(d) _, _, _ = h, z, r yyv1 := v yyh1, yyl1 := z.DecSliceHelperStart() if yyl1 == 0 { } else { yyhl1 := yyl1 > 0 var yyrl1 int _ = yyrl1 var yyj1 int for yyj1 = 0; (yyhl1 && yyj1 < yyl1) || !(yyhl1 || z.DecCheckBreak()); yyj1++ { // bounds-check-elimination yyh1.ElemContainerState(yyj1) var yydb1 bool if yyj1 >= len(yyv1) { z.DecArrayCannotExpand(len(v), yyj1+1) yydb1 = true } if yydb1 { z.DecSwallow() } else { yyv1[yyj1] = (int64)(r.DecodeInt64()) } } } yyh1.End() } func (x codecSelfer19780) encSlicePtrtoint64(v []*int64, e *Encoder) { var h codecSelfer19780 z, r := GenHelper().Encoder(e) _, _, _ = h, z, r if v == nil { r.EncodeNil() return } z.EncWriteArrayStart(len(v)) for yyv1 := range v { z.EncWriteArrayElem() if v[yyv1] == nil { r.EncodeNil() } else { yy2 := *v[yyv1] r.EncodeInt(int64(yy2)) } } z.EncWriteArrayEnd() } func (x codecSelfer19780) decSlicePtrtoint64(v *[]*int64, d *Decoder) { var h codecSelfer19780 z, r := GenHelper().Decoder(d) _, _, _ = h, z, r yyv1 := *v yyh1, yyl1 := z.DecSliceHelperStart() var yyc1 bool _ = yyc1 if yyh1.IsNil { if yyv1 != nil { yyv1 = nil yyc1 = true } } else if yyl1 == 0 { if yyv1 == nil { yyv1 = []*int64{} yyc1 = true } else if len(yyv1) != 0 { yyv1 = yyv1[:0] yyc1 = true } } else { yyhl1 := yyl1 > 0 var yyrl1 int _ = yyrl1 if yyhl1 { if yyl1 > cap(yyv1) { yyrl1 = z.DecInferLen(yyl1, z.DecBasicHandle().MaxInitLen, 8) if yyrl1 <= cap(yyv1) { yyv1 = yyv1[:yyrl1] } else { yyv1 = make([]*int64, yyrl1) } yyc1 = true } else if yyl1 != len(yyv1) { yyv1 = yyv1[:yyl1] yyc1 = true } } var yyj1 int for yyj1 = 0; (yyhl1 && yyj1 < yyl1) || !(yyhl1 || z.DecCheckBreak()); yyj1++ { // bounds-check-elimination if yyj1 == 0 && yyv1 == nil { if yyhl1 { yyrl1 = z.DecInferLen(yyl1, z.DecBasicHandle().MaxInitLen, 8) } else { yyrl1 = 8 } yyv1 = make([]*int64, yyrl1) yyc1 = true } yyh1.ElemContainerState(yyj1) var yydb1 bool if yyj1 >= len(yyv1) { yyv1 = append(yyv1, nil) yyc1 = true } if yydb1 { z.DecSwallow() } else { if r.TryNil() { yyv1[yyj1] = nil } else { if yyv1[yyj1] == nil { yyv1[yyj1] = new(int64) } *yyv1[yyj1] = (int64)(r.DecodeInt64()) } } } if yyj1 < len(yyv1) { yyv1 = yyv1[:yyj1] yyc1 = true } else if yyj1 == 0 && yyv1 == nil { yyv1 = []*int64{} yyc1 = true } } yyh1.End() if yyc1 { *v = yyv1 } } func (x codecSelfer19780) encSlicestringUint64T(v []stringUint64T, e *Encoder) { var h codecSelfer19780 z, r := GenHelper().Encoder(e) _, _, _ = h, z, r if v == nil { r.EncodeNil() return } z.EncWriteArrayStart(len(v)) for yyv1 := range v { z.EncWriteArrayElem() yy2 := &v[yyv1] if yyxt3 := z.Extension(yy2); yyxt3 != nil { z.EncExtension(yy2, yyxt3) } else { yy2.CodecEncodeSelf(e) } } z.EncWriteArrayEnd() } func (x codecSelfer19780) decSlicestringUint64T(v *[]stringUint64T, d *Decoder) { var h codecSelfer19780 z, r := GenHelper().Decoder(d) _, _, _ = h, z, r yyv1 := *v yyh1, yyl1 := z.DecSliceHelperStart() var yyc1 bool _ = yyc1 if yyh1.IsNil { if yyv1 != nil { yyv1 = nil yyc1 = true } } else if yyl1 == 0 { if yyv1 == nil { yyv1 = []stringUint64T{} yyc1 = true } else if len(yyv1) != 0 { yyv1 = yyv1[:0] yyc1 = true } } else { yyhl1 := yyl1 > 0 var yyrl1 int _ = yyrl1 if yyhl1 { if yyl1 > cap(yyv1) { yyrl1 = z.DecInferLen(yyl1, z.DecBasicHandle().MaxInitLen, 24) if yyrl1 <= cap(yyv1) { yyv1 = yyv1[:yyrl1] } else { yyv1 = make([]stringUint64T, yyrl1) } yyc1 = true } else if yyl1 != len(yyv1) { yyv1 = yyv1[:yyl1] yyc1 = true } } var yyj1 int for yyj1 = 0; (yyhl1 && yyj1 < yyl1) || !(yyhl1 || z.DecCheckBreak()); yyj1++ { // bounds-check-elimination if yyj1 == 0 && yyv1 == nil { if yyhl1 { yyrl1 = z.DecInferLen(yyl1, z.DecBasicHandle().MaxInitLen, 24) } else { yyrl1 = 8 } yyv1 = make([]stringUint64T, yyrl1) yyc1 = true } yyh1.ElemContainerState(yyj1) var yydb1 bool if yyj1 >= len(yyv1) { yyv1 = append(yyv1, stringUint64T{}) yyc1 = true } if yydb1 { z.DecSwallow() } else { if yyxt3 := z.Extension(yyv1[yyj1]); yyxt3 != nil { z.DecExtension(&yyv1[yyj1], yyxt3) } else { yyv1[yyj1].CodecDecodeSelf(d) } } } if yyj1 < len(yyv1) { yyv1 = yyv1[:yyj1] yyc1 = true } else if yyj1 == 0 && yyv1 == nil { yyv1 = []stringUint64T{} yyc1 = true } } yyh1.End() if yyc1 { *v = yyv1 } } func (x codecSelfer19780) encMapstringPtrtostringUint64T(v map[string]*stringUint64T, e *Encoder) { var h codecSelfer19780 z, r := GenHelper().Encoder(e) _, _, _ = h, z, r if v == nil { r.EncodeNil() } else if z.EncBasicHandle().Canonical { yys1 := make([]string, 0, len(v)) for k, _ := range v { yys1 = append(yys1, string(k)) } sort.Sort(codecSelfer19780stringSlice(yys1)) z.EncWriteMapStart(len(v)) for _, yyv1 := range yys1 { z.EncWriteMapElemKey() r.EncodeString(yyv1) z.EncWriteMapElemValue() yye1 := v[string(yyv1)] if yye1 == nil { r.EncodeNil() } else { if yyxt2 := z.Extension(yye1); yyxt2 != nil { z.EncExtension(yye1, yyxt2) } else { yye1.CodecEncodeSelf(e) } } } z.EncWriteMapEnd() } else { z.EncWriteMapStart(len(v)) for yyk1, yyv1 := range v { z.EncWriteMapElemKey() r.EncodeString(string(yyk1)) z.EncWriteMapElemValue() if yyv1 == nil { r.EncodeNil() } else { if yyxt4 := z.Extension(yyv1); yyxt4 != nil { z.EncExtension(yyv1, yyxt4) } else { yyv1.CodecEncodeSelf(e) } } } z.EncWriteMapEnd() } } func (x codecSelfer19780) decMapstringPtrtostringUint64T(v *map[string]*stringUint64T, d *Decoder) { var h codecSelfer19780 z, r := GenHelper().Decoder(d) _, _, _ = h, z, r yyv1 := *v yyl1 := z.DecReadMapStart() if yyl1 == codecSelferDecContainerLenNil19780 { *v = nil } else { if yyv1 == nil { yyrl1 := z.DecInferLen(yyl1, z.DecBasicHandle().MaxInitLen, 24) yyv1 = make(map[string]*stringUint64T, yyrl1) *v = yyv1 } var yymk1 string var yymv1 *stringUint64T var yymg1, yymdn1, yyms1, yymok1 bool if z.DecBasicHandle().MapValueReset { yymg1 = true } if yyl1 != 0 { yyhl1 := yyl1 > 0 for yyj1 := 0; (yyhl1 && yyj1 < yyl1) || !(yyhl1 || z.DecCheckBreak()); yyj1++ { z.DecReadMapElemKey() yymk1 = (string)(z.DecStringZC(r.DecodeStringAsBytes())) yyms1 = true if yymg1 { yymv1, yymok1 = yyv1[yymk1] if yymok1 { yyms1 = false } } else { yymv1 = nil } z.DecReadMapElemValue() yymdn1 = false if r.TryNil() { yymdn1 = true } else { if yymv1 == nil { yymv1 = new(stringUint64T) } if yyxt4 := z.Extension(yymv1); yyxt4 != nil { z.DecExtension(yymv1, yyxt4) } else { yymv1.CodecDecodeSelf(d) } } if yymdn1 { yyv1[yymk1] = nil } else if yyms1 { yyv1[yymk1] = yymv1 } } } // else len==0: leave as-is (do not clear map entries) z.DecReadMapEnd() } } func (x codecSelfer19780) encMapstringPtrtoTestStruc(v map[string]*TestStruc, e *Encoder) { var h codecSelfer19780 z, r := GenHelper().Encoder(e) _, _, _ = h, z, r if v == nil { r.EncodeNil() } else if z.EncBasicHandle().Canonical { yys1 := make([]string, 0, len(v)) for k, _ := range v { yys1 = append(yys1, string(k)) } sort.Sort(codecSelfer19780stringSlice(yys1)) z.EncWriteMapStart(len(v)) for _, yyv1 := range yys1 { z.EncWriteMapElemKey() r.EncodeString(yyv1) z.EncWriteMapElemValue() yye1 := v[string(yyv1)] if yye1 == nil { r.EncodeNil() } else { if yyxt2 := z.Extension(yye1); yyxt2 != nil { z.EncExtension(yye1, yyxt2) } else { yye1.CodecEncodeSelf(e) } } } z.EncWriteMapEnd() } else { z.EncWriteMapStart(len(v)) for yyk1, yyv1 := range v { z.EncWriteMapElemKey() r.EncodeString(string(yyk1)) z.EncWriteMapElemValue() if yyv1 == nil { r.EncodeNil() } else { if yyxt4 := z.Extension(yyv1); yyxt4 != nil { z.EncExtension(yyv1, yyxt4) } else { yyv1.CodecEncodeSelf(e) } } } z.EncWriteMapEnd() } } func (x codecSelfer19780) decMapstringPtrtoTestStruc(v *map[string]*TestStruc, d *Decoder) { var h codecSelfer19780 z, r := GenHelper().Decoder(d) _, _, _ = h, z, r yyv1 := *v yyl1 := z.DecReadMapStart() if yyl1 == codecSelferDecContainerLenNil19780 { *v = nil } else { if yyv1 == nil { yyrl1 := z.DecInferLen(yyl1, z.DecBasicHandle().MaxInitLen, 24) yyv1 = make(map[string]*TestStruc, yyrl1) *v = yyv1 } var yymk1 string var yymv1 *TestStruc var yymg1, yymdn1, yyms1, yymok1 bool if z.DecBasicHandle().MapValueReset { yymg1 = true } if yyl1 != 0 { yyhl1 := yyl1 > 0 for yyj1 := 0; (yyhl1 && yyj1 < yyl1) || !(yyhl1 || z.DecCheckBreak()); yyj1++ { z.DecReadMapElemKey() yymk1 = (string)(z.DecStringZC(r.DecodeStringAsBytes())) yyms1 = true if yymg1 { yymv1, yymok1 = yyv1[yymk1] if yymok1 { yyms1 = false } } else { yymv1 = nil } z.DecReadMapElemValue() yymdn1 = false if r.TryNil() { yymdn1 = true } else { if yymv1 == nil { yymv1 = new(TestStruc) } if yyxt4 := z.Extension(yymv1); yyxt4 != nil { z.DecExtension(yymv1, yyxt4) } else { yymv1.CodecDecodeSelf(d) } } if yymdn1 { yyv1[yymk1] = nil } else if yyms1 { yyv1[yymk1] = yymv1 } } } // else len==0: leave as-is (do not clear map entries) z.DecReadMapEnd() } } func (x codecSelfer19780) encMapstringTestStruc(v map[string]TestStruc, e *Encoder) { var h codecSelfer19780 z, r := GenHelper().Encoder(e) _, _, _ = h, z, r if v == nil { r.EncodeNil() } else if z.EncBasicHandle().Canonical { yys1 := make([]string, 0, len(v)) for k, _ := range v { yys1 = append(yys1, string(k)) } sort.Sort(codecSelfer19780stringSlice(yys1)) z.EncWriteMapStart(len(v)) for _, yyv1 := range yys1 { z.EncWriteMapElemKey() r.EncodeString(yyv1) z.EncWriteMapElemValue() yye1 := v[string(yyv1)] yy2 := &yye1 if yyxt3 := z.Extension(yy2); yyxt3 != nil { z.EncExtension(yy2, yyxt3) } else { yy2.CodecEncodeSelf(e) } } z.EncWriteMapEnd() } else { z.EncWriteMapStart(len(v)) for yyk1, yyv1 := range v { z.EncWriteMapElemKey() r.EncodeString(string(yyk1)) z.EncWriteMapElemValue() yy5 := &yyv1 if yyxt6 := z.Extension(yy5); yyxt6 != nil { z.EncExtension(yy5, yyxt6) } else { yy5.CodecEncodeSelf(e) } } z.EncWriteMapEnd() } } func (x codecSelfer19780) decMapstringTestStruc(v *map[string]TestStruc, d *Decoder) { var h codecSelfer19780 z, r := GenHelper().Decoder(d) _, _, _ = h, z, r yyv1 := *v yyl1 := z.DecReadMapStart() if yyl1 == codecSelferDecContainerLenNil19780 { *v = nil } else { if yyv1 == nil { yyrl1 := z.DecInferLen(yyl1, z.DecBasicHandle().MaxInitLen, 1384) yyv1 = make(map[string]TestStruc, yyrl1) *v = yyv1 } var yymk1 string var yymv1 TestStruc var yymg1, yymdn1 bool if z.DecBasicHandle().MapValueReset { yymg1 = true } if yyl1 != 0 { yyhl1 := yyl1 > 0 for yyj1 := 0; (yyhl1 && yyj1 < yyl1) || !(yyhl1 || z.DecCheckBreak()); yyj1++ { z.DecReadMapElemKey() yymk1 = (string)(z.DecStringZC(r.DecodeStringAsBytes())) if yymg1 { yymv1 = yyv1[yymk1] } else { yymv1 = TestStruc{} } z.DecReadMapElemValue() yymdn1 = false if yyxt4 := z.Extension(yymv1); yyxt4 != nil { z.DecExtension(&yymv1, yyxt4) } else { yymv1.CodecDecodeSelf(d) } if yymdn1 { yyv1[yymk1] = TestStruc{} } else { yyv1[yymk1] = yymv1 } } } // else len==0: leave as-is (do not clear map entries) z.DecReadMapEnd() } } func (x codecSelfer19780) encSlicePtrtoTestStruc(v []*TestStruc, e *Encoder) { var h codecSelfer19780 z, r := GenHelper().Encoder(e) _, _, _ = h, z, r if v == nil { r.EncodeNil() return } z.EncWriteArrayStart(len(v)) for yyv1 := range v { z.EncWriteArrayElem() if v[yyv1] == nil { r.EncodeNil() } else { if yyxt2 := z.Extension(v[yyv1]); yyxt2 != nil { z.EncExtension(v[yyv1], yyxt2) } else { v[yyv1].CodecEncodeSelf(e) } } } z.EncWriteArrayEnd() } func (x codecSelfer19780) decSlicePtrtoTestStruc(v *[]*TestStruc, d *Decoder) { var h codecSelfer19780 z, r := GenHelper().Decoder(d) _, _, _ = h, z, r yyv1 := *v yyh1, yyl1 := z.DecSliceHelperStart() var yyc1 bool _ = yyc1 if yyh1.IsNil { if yyv1 != nil { yyv1 = nil yyc1 = true } } else if yyl1 == 0 { if yyv1 == nil { yyv1 = []*TestStruc{} yyc1 = true } else if len(yyv1) != 0 { yyv1 = yyv1[:0] yyc1 = true } } else { yyhl1 := yyl1 > 0 var yyrl1 int _ = yyrl1 if yyhl1 { if yyl1 > cap(yyv1) { yyrl1 = z.DecInferLen(yyl1, z.DecBasicHandle().MaxInitLen, 8) if yyrl1 <= cap(yyv1) { yyv1 = yyv1[:yyrl1] } else { yyv1 = make([]*TestStruc, yyrl1) } yyc1 = true } else if yyl1 != len(yyv1) { yyv1 = yyv1[:yyl1] yyc1 = true } } var yyj1 int for yyj1 = 0; (yyhl1 && yyj1 < yyl1) || !(yyhl1 || z.DecCheckBreak()); yyj1++ { // bounds-check-elimination if yyj1 == 0 && yyv1 == nil { if yyhl1 { yyrl1 = z.DecInferLen(yyl1, z.DecBasicHandle().MaxInitLen, 8) } else { yyrl1 = 8 } yyv1 = make([]*TestStruc, yyrl1) yyc1 = true } yyh1.ElemContainerState(yyj1) var yydb1 bool if yyj1 >= len(yyv1) { yyv1 = append(yyv1, nil) yyc1 = true } if yydb1 { z.DecSwallow() } else { if r.TryNil() { yyv1[yyj1] = nil } else { if yyv1[yyj1] == nil { yyv1[yyj1] = new(TestStruc) } if yyxt3 := z.Extension(yyv1[yyj1]); yyxt3 != nil { z.DecExtension(yyv1[yyj1], yyxt3) } else { yyv1[yyj1].CodecDecodeSelf(d) } } } } if yyj1 < len(yyv1) { yyv1 = yyv1[:yyj1] yyc1 = true } else if yyj1 == 0 && yyv1 == nil { yyv1 = []*TestStruc{} yyc1 = true } } yyh1.End() if yyc1 { *v = yyv1 } } func (x codecSelfer19780) encChanstring(v chan string, e *Encoder) { var h codecSelfer19780 z, r := GenHelper().Encoder(e) _, _, _ = h, z, r if v == nil { r.EncodeNil() return } if v == nil { r.EncodeNil() } else { var sch1 []string Lsch1: switch timeout1 := z.EncBasicHandle().ChanRecvTimeout; { case timeout1 == 0: // only consume available for { select { case b1 := <-v: sch1 = append(sch1, b1) default: break Lsch1 } } case timeout1 > 0: // consume until timeout tt1 := time.NewTimer(timeout1) for { select { case b1 := <-v: sch1 = append(sch1, b1) case <-tt1.C: // close(tt.C) break Lsch1 } } default: // consume until close for b1 := range v { sch1 = append(sch1, b1) } } z.EncWriteArrayStart(len(sch1)) for yyv1 := range sch1 { z.EncWriteArrayElem() r.EncodeString(string(sch1[yyv1])) } z.EncWriteArrayEnd() } } func (x codecSelfer19780) decChanstring(v *chan string, d *Decoder) { var h codecSelfer19780 z, r := GenHelper().Decoder(d) _, _, _ = h, z, r yyv1 := *v yyh1, yyl1 := z.DecSliceHelperStart() var yyc1 bool _ = yyc1 if yyh1.IsNil { if yyv1 != nil { yyv1 = nil yyc1 = true } } else if yyl1 == 0 { if yyv1 == nil { yyv1 = make(chan string, 0) yyc1 = true } } else { yyhl1 := yyl1 > 0 var yyrl1 int _ = yyrl1 var yyj1 int for yyj1 = 0; (yyhl1 && yyj1 < yyl1) || !(yyhl1 || z.DecCheckBreak()); yyj1++ { // bounds-check-elimination if yyj1 == 0 && yyv1 == nil { if yyhl1 { yyrl1 = z.DecInferLen(yyl1, z.DecBasicHandle().MaxInitLen, 16) } else { yyrl1 = 64 } yyv1 = make(chan string, yyrl1) yyc1 = true } yyh1.ElemContainerState(yyj1) var yyvcx1 string yyvcx1 = (string)(z.DecStringZC(r.DecodeStringAsBytes())) yyv1 <- yyvcx1 } } yyh1.End() if yyc1 { *v = yyv1 } } func (x codecSelfer19780) encMapboolc3RydWN0IHt9(v map[bool]struct{}, e *Encoder) { var h codecSelfer19780 z, r := GenHelper().Encoder(e) _, _, _ = h, z, r if v == nil { r.EncodeNil() } else if z.EncBasicHandle().Canonical { z.EncEncodeMapNonNil(v) } else { z.EncWriteMapStart(len(v)) for yyk1, yyv1 := range v { z.EncWriteMapElemKey() r.EncodeBool(bool(yyk1)) z.EncWriteMapElemValue() yy3 := &yyv1 z.EncFallback(yy3) } z.EncWriteMapEnd() } } func (x codecSelfer19780) decMapboolc3RydWN0IHt9(v *map[bool]struct{}, d *Decoder) { var h codecSelfer19780 z, r := GenHelper().Decoder(d) _, _, _ = h, z, r yyv1 := *v yyl1 := z.DecReadMapStart() if yyl1 == codecSelferDecContainerLenNil19780 { *v = nil } else { if yyv1 == nil { yyrl1 := z.DecInferLen(yyl1, z.DecBasicHandle().MaxInitLen, 1) yyv1 = make(map[bool]struct{}, yyrl1) *v = yyv1 } var yymk1 bool var yymv1 struct{} var yymg1, yymdn1 bool if z.DecBasicHandle().MapValueReset { yymg1 = true } if yyl1 != 0 { yyhl1 := yyl1 > 0 for yyj1 := 0; (yyhl1 && yyj1 < yyl1) || !(yyhl1 || z.DecCheckBreak()); yyj1++ { z.DecReadMapElemKey() yymk1 = (bool)(r.DecodeBool()) if yymg1 { yymv1 = yyv1[yymk1] } else { yymv1 = struct{}{} } z.DecReadMapElemValue() yymdn1 = false z.DecFallback(&yymv1, false) if yymdn1 { yyv1[yymk1] = struct{}{} } else { yyv1[yymk1] = yymv1 } } } // else len==0: leave as-is (do not clear map entries) z.DecReadMapEnd() } } func (x codecSelfer19780) encMapuint8c3RydWN0IHt9(v map[uint8]struct{}, e *Encoder) { var h codecSelfer19780 z, r := GenHelper().Encoder(e) _, _, _ = h, z, r if v == nil { r.EncodeNil() } else if z.EncBasicHandle().Canonical { yys1 := make([]uint64, 0, len(v)) for k, _ := range v { yys1 = append(yys1, uint64(k)) } sort.Sort(codecSelfer19780uint64Slice(yys1)) z.EncWriteMapStart(len(v)) for _, yyv1 := range yys1 { z.EncWriteMapElemKey() r.EncodeUint(yyv1) z.EncWriteMapElemValue() yye1 := v[uint8(yyv1)] yy2 := &yye1 z.EncFallback(yy2) } z.EncWriteMapEnd() } else { z.EncWriteMapStart(len(v)) for yyk1, yyv1 := range v { z.EncWriteMapElemKey() r.EncodeUint(uint64(yyk1)) z.EncWriteMapElemValue() yy5 := &yyv1 z.EncFallback(yy5) } z.EncWriteMapEnd() } } func (x codecSelfer19780) decMapuint8c3RydWN0IHt9(v *map[uint8]struct{}, d *Decoder) { var h codecSelfer19780 z, r := GenHelper().Decoder(d) _, _, _ = h, z, r yyv1 := *v yyl1 := z.DecReadMapStart() if yyl1 == codecSelferDecContainerLenNil19780 { *v = nil } else { if yyv1 == nil { yyrl1 := z.DecInferLen(yyl1, z.DecBasicHandle().MaxInitLen, 1) yyv1 = make(map[uint8]struct{}, yyrl1) *v = yyv1 } var yymk1 uint8 var yymv1 struct{} var yymg1, yymdn1 bool if z.DecBasicHandle().MapValueReset { yymg1 = true } if yyl1 != 0 { yyhl1 := yyl1 > 0 for yyj1 := 0; (yyhl1 && yyj1 < yyl1) || !(yyhl1 || z.DecCheckBreak()); yyj1++ { z.DecReadMapElemKey() yymk1 = (uint8)(z.C.UintV(r.DecodeUint64(), 8)) if yymg1 { yymv1 = yyv1[yymk1] } else { yymv1 = struct{}{} } z.DecReadMapElemValue() yymdn1 = false z.DecFallback(&yymv1, false) if yymdn1 { yyv1[yymk1] = struct{}{} } else { yyv1[yymk1] = yymv1 } } } // else len==0: leave as-is (do not clear map entries) z.DecReadMapEnd() } } func (x codecSelfer19780) encMapuint8stringUint64T(v map[uint8]stringUint64T, e *Encoder) { var h codecSelfer19780 z, r := GenHelper().Encoder(e) _, _, _ = h, z, r if v == nil { r.EncodeNil() } else if z.EncBasicHandle().Canonical { yys1 := make([]uint64, 0, len(v)) for k, _ := range v { yys1 = append(yys1, uint64(k)) } sort.Sort(codecSelfer19780uint64Slice(yys1)) z.EncWriteMapStart(len(v)) for _, yyv1 := range yys1 { z.EncWriteMapElemKey() r.EncodeUint(yyv1) z.EncWriteMapElemValue() yye1 := v[uint8(yyv1)] yy2 := &yye1 if yyxt3 := z.Extension(yy2); yyxt3 != nil { z.EncExtension(yy2, yyxt3) } else { yy2.CodecEncodeSelf(e) } } z.EncWriteMapEnd() } else { z.EncWriteMapStart(len(v)) for yyk1, yyv1 := range v { z.EncWriteMapElemKey() r.EncodeUint(uint64(yyk1)) z.EncWriteMapElemValue() yy5 := &yyv1 if yyxt6 := z.Extension(yy5); yyxt6 != nil { z.EncExtension(yy5, yyxt6) } else { yy5.CodecEncodeSelf(e) } } z.EncWriteMapEnd() } } func (x codecSelfer19780) decMapuint8stringUint64T(v *map[uint8]stringUint64T, d *Decoder) { var h codecSelfer19780 z, r := GenHelper().Decoder(d) _, _, _ = h, z, r yyv1 := *v yyl1 := z.DecReadMapStart() if yyl1 == codecSelferDecContainerLenNil19780 { *v = nil } else { if yyv1 == nil { yyrl1 := z.DecInferLen(yyl1, z.DecBasicHandle().MaxInitLen, 25) yyv1 = make(map[uint8]stringUint64T, yyrl1) *v = yyv1 } var yymk1 uint8 var yymv1 stringUint64T var yymg1, yymdn1 bool if z.DecBasicHandle().MapValueReset { yymg1 = true } if yyl1 != 0 { yyhl1 := yyl1 > 0 for yyj1 := 0; (yyhl1 && yyj1 < yyl1) || !(yyhl1 || z.DecCheckBreak()); yyj1++ { z.DecReadMapElemKey() yymk1 = (uint8)(z.C.UintV(r.DecodeUint64(), 8)) if yymg1 { yymv1 = yyv1[yymk1] } else { yymv1 = stringUint64T{} } z.DecReadMapElemValue() yymdn1 = false if yyxt4 := z.Extension(yymv1); yyxt4 != nil { z.DecExtension(&yymv1, yyxt4) } else { yymv1.CodecDecodeSelf(d) } if yymdn1 { yyv1[yymk1] = stringUint64T{} } else { yyv1[yymk1] = yymv1 } } } // else len==0: leave as-is (do not clear map entries) z.DecReadMapEnd() } } func (x codecSelfer19780) encMapPtrtostringSlicestring(v map[*string][]string, e *Encoder) { var h codecSelfer19780 z, r := GenHelper().Encoder(e) _, _, _ = h, z, r if v == nil { r.EncodeNil() } else if z.EncBasicHandle().Canonical { z.EncEncodeMapNonNil(v) } else { z.EncWriteMapStart(len(v)) for yyk1, yyv1 := range v { z.EncWriteMapElemKey() if yyk1 == nil { r.EncodeNil() } else { yy2 := *yyk1 r.EncodeString(string(yy2)) } z.EncWriteMapElemValue() if yyv1 == nil { r.EncodeNil() } else { z.F.EncSliceStringV(yyv1, e) } // end block: if yyv1 slice == nil } z.EncWriteMapEnd() } } func (x codecSelfer19780) decMapPtrtostringSlicestring(v *map[*string][]string, d *Decoder) { var h codecSelfer19780 z, r := GenHelper().Decoder(d) _, _, _ = h, z, r yyv1 := *v yyl1 := z.DecReadMapStart() if yyl1 == codecSelferDecContainerLenNil19780 { *v = nil } else { if yyv1 == nil { yyrl1 := z.DecInferLen(yyl1, z.DecBasicHandle().MaxInitLen, 32) yyv1 = make(map[*string][]string, yyrl1) *v = yyv1 } var yymk1 *string var yymv1 []string var yymg1, yymdn1 bool if z.DecBasicHandle().MapValueReset { yymg1 = true } if yyl1 != 0 { yyhl1 := yyl1 > 0 for yyj1 := 0; (yyhl1 && yyj1 < yyl1) || !(yyhl1 || z.DecCheckBreak()); yyj1++ { z.DecReadMapElemKey() if r.TryNil() { *yymk1 = "" } else { if yymk1 == nil { yymk1 = new(string) } *yymk1 = (string)(z.DecStringZC(r.DecodeStringAsBytes())) } if yymg1 { yymv1 = yyv1[yymk1] } else { yymv1 = nil } z.DecReadMapElemValue() yymdn1 = false z.F.DecSliceStringX(&yymv1, d) if yymdn1 { yyv1[yymk1] = nil } else { yyv1[yymk1] = yymv1 } } } // else len==0: leave as-is (do not clear map entries) z.DecReadMapEnd() } } func (x codecSelfer19780) encMapPtrtouint64Slicestring(v map[*uint64][]string, e *Encoder) { var h codecSelfer19780 z, r := GenHelper().Encoder(e) _, _, _ = h, z, r if v == nil { r.EncodeNil() } else if z.EncBasicHandle().Canonical { z.EncEncodeMapNonNil(v) } else { z.EncWriteMapStart(len(v)) for yyk1, yyv1 := range v { z.EncWriteMapElemKey() if yyk1 == nil { r.EncodeNil() } else { yy2 := *yyk1 r.EncodeUint(uint64(yy2)) } z.EncWriteMapElemValue() if yyv1 == nil { r.EncodeNil() } else { z.F.EncSliceStringV(yyv1, e) } // end block: if yyv1 slice == nil } z.EncWriteMapEnd() } } func (x codecSelfer19780) decMapPtrtouint64Slicestring(v *map[*uint64][]string, d *Decoder) { var h codecSelfer19780 z, r := GenHelper().Decoder(d) _, _, _ = h, z, r yyv1 := *v yyl1 := z.DecReadMapStart() if yyl1 == codecSelferDecContainerLenNil19780 { *v = nil } else { if yyv1 == nil { yyrl1 := z.DecInferLen(yyl1, z.DecBasicHandle().MaxInitLen, 32) yyv1 = make(map[*uint64][]string, yyrl1) *v = yyv1 } var yymk1 *uint64 var yymv1 []string var yymg1, yymdn1 bool if z.DecBasicHandle().MapValueReset { yymg1 = true } if yyl1 != 0 { yyhl1 := yyl1 > 0 for yyj1 := 0; (yyhl1 && yyj1 < yyl1) || !(yyhl1 || z.DecCheckBreak()); yyj1++ { z.DecReadMapElemKey() if r.TryNil() { *yymk1 = 0 } else { if yymk1 == nil { yymk1 = new(uint64) } *yymk1 = (uint64)(r.DecodeUint64()) } if yymg1 { yymv1 = yyv1[yymk1] } else { yymv1 = nil } z.DecReadMapElemValue() yymdn1 = false z.F.DecSliceStringX(&yymv1, d) if yymdn1 { yyv1[yymk1] = nil } else { yyv1[yymk1] = yymv1 } } } // else len==0: leave as-is (do not clear map entries) z.DecReadMapEnd() } } func (x codecSelfer19780) encMapstringMapuint64stringUint64T(v map[string]map[uint64]stringUint64T, e *Encoder) { var h codecSelfer19780 z, r := GenHelper().Encoder(e) _, _, _ = h, z, r if v == nil { r.EncodeNil() } else if z.EncBasicHandle().Canonical { yys1 := make([]string, 0, len(v)) for k, _ := range v { yys1 = append(yys1, string(k)) } sort.Sort(codecSelfer19780stringSlice(yys1)) z.EncWriteMapStart(len(v)) for _, yyv1 := range yys1 { z.EncWriteMapElemKey() r.EncodeString(yyv1) z.EncWriteMapElemValue() yye1 := v[string(yyv1)] if yye1 == nil { r.EncodeNil() } else { h.encMapuint64stringUint64T((map[uint64]stringUint64T)(yye1), e) } // end block: if yye1 map == nil } z.EncWriteMapEnd() } else { z.EncWriteMapStart(len(v)) for yyk1, yyv1 := range v { z.EncWriteMapElemKey() r.EncodeString(string(yyk1)) z.EncWriteMapElemValue() if yyv1 == nil { r.EncodeNil() } else { h.encMapuint64stringUint64T((map[uint64]stringUint64T)(yyv1), e) } // end block: if yyv1 map == nil } z.EncWriteMapEnd() } } func (x codecSelfer19780) decMapstringMapuint64stringUint64T(v *map[string]map[uint64]stringUint64T, d *Decoder) { var h codecSelfer19780 z, r := GenHelper().Decoder(d) _, _, _ = h, z, r yyv1 := *v yyl1 := z.DecReadMapStart() if yyl1 == codecSelferDecContainerLenNil19780 { *v = nil } else { if yyv1 == nil { yyrl1 := z.DecInferLen(yyl1, z.DecBasicHandle().MaxInitLen, 24) yyv1 = make(map[string]map[uint64]stringUint64T, yyrl1) *v = yyv1 } var yymk1 string var yymv1 map[uint64]stringUint64T var yymg1, yymdn1 bool if z.DecBasicHandle().MapValueReset { yymg1 = true } if yyl1 != 0 { yyhl1 := yyl1 > 0 for yyj1 := 0; (yyhl1 && yyj1 < yyl1) || !(yyhl1 || z.DecCheckBreak()); yyj1++ { z.DecReadMapElemKey() yymk1 = (string)(z.DecStringZC(r.DecodeStringAsBytes())) if yymg1 { yymv1 = yyv1[yymk1] } else { yymv1 = nil } z.DecReadMapElemValue() yymdn1 = false h.decMapuint64stringUint64T((*map[uint64]stringUint64T)(&yymv1), d) if yymdn1 { yyv1[yymk1] = nil } else { yyv1[yymk1] = yymv1 } } } // else len==0: leave as-is (do not clear map entries) z.DecReadMapEnd() } } func (x codecSelfer19780) encMapuint64stringUint64T(v map[uint64]stringUint64T, e *Encoder) { var h codecSelfer19780 z, r := GenHelper().Encoder(e) _, _, _ = h, z, r if v == nil { r.EncodeNil() } else if z.EncBasicHandle().Canonical { yys1 := make([]uint64, 0, len(v)) for k, _ := range v { yys1 = append(yys1, uint64(k)) } sort.Sort(codecSelfer19780uint64Slice(yys1)) z.EncWriteMapStart(len(v)) for _, yyv1 := range yys1 { z.EncWriteMapElemKey() r.EncodeUint(uint64(yyv1)) z.EncWriteMapElemValue() yye1 := v[uint64(yyv1)] yy2 := &yye1 if yyxt3 := z.Extension(yy2); yyxt3 != nil { z.EncExtension(yy2, yyxt3) } else { yy2.CodecEncodeSelf(e) } } z.EncWriteMapEnd() } else { z.EncWriteMapStart(len(v)) for yyk1, yyv1 := range v { z.EncWriteMapElemKey() r.EncodeUint(uint64(yyk1)) z.EncWriteMapElemValue() yy5 := &yyv1 if yyxt6 := z.Extension(yy5); yyxt6 != nil { z.EncExtension(yy5, yyxt6) } else { yy5.CodecEncodeSelf(e) } } z.EncWriteMapEnd() } } func (x codecSelfer19780) decMapuint64stringUint64T(v *map[uint64]stringUint64T, d *Decoder) { var h codecSelfer19780 z, r := GenHelper().Decoder(d) _, _, _ = h, z, r yyv1 := *v yyl1 := z.DecReadMapStart() if yyl1 == codecSelferDecContainerLenNil19780 { *v = nil } else { if yyv1 == nil { yyrl1 := z.DecInferLen(yyl1, z.DecBasicHandle().MaxInitLen, 32) yyv1 = make(map[uint64]stringUint64T, yyrl1) *v = yyv1 } var yymk1 uint64 var yymv1 stringUint64T var yymg1, yymdn1 bool if z.DecBasicHandle().MapValueReset { yymg1 = true } if yyl1 != 0 { yyhl1 := yyl1 > 0 for yyj1 := 0; (yyhl1 && yyj1 < yyl1) || !(yyhl1 || z.DecCheckBreak()); yyj1++ { z.DecReadMapElemKey() yymk1 = (uint64)(r.DecodeUint64()) if yymg1 { yymv1 = yyv1[yymk1] } else { yymv1 = stringUint64T{} } z.DecReadMapElemValue() yymdn1 = false if yyxt4 := z.Extension(yymv1); yyxt4 != nil { z.DecExtension(&yymv1, yyxt4) } else { yymv1.CodecDecodeSelf(d) } if yymdn1 { yyv1[yymk1] = stringUint64T{} } else { yyv1[yymk1] = yymv1 } } } // else len==0: leave as-is (do not clear map entries) z.DecReadMapEnd() } } func (x codecSelfer19780) encMapintwrapUint64Slice(v map[int]wrapUint64Slice, e *Encoder) { var h codecSelfer19780 z, r := GenHelper().Encoder(e) _, _, _ = h, z, r if v == nil { r.EncodeNil() } else if z.EncBasicHandle().Canonical { yys1 := make([]int64, 0, len(v)) for k, _ := range v { yys1 = append(yys1, int64(k)) } sort.Sort(codecSelfer19780int64Slice(yys1)) z.EncWriteMapStart(len(v)) for _, yyv1 := range yys1 { z.EncWriteMapElemKey() r.EncodeInt(int64(yyv1)) z.EncWriteMapElemValue() yye1 := v[int(yyv1)] if yyxt2 := z.Extension(yye1); yyxt2 != nil { z.EncExtension(yye1, yyxt2) } else { yye1.CodecEncodeSelf(e) } } z.EncWriteMapEnd() } else { z.EncWriteMapStart(len(v)) for yyk1, yyv1 := range v { z.EncWriteMapElemKey() r.EncodeInt(int64(yyk1)) z.EncWriteMapElemValue() if yyxt4 := z.Extension(yyv1); yyxt4 != nil { z.EncExtension(yyv1, yyxt4) } else { yyv1.CodecEncodeSelf(e) } } z.EncWriteMapEnd() } } func (x codecSelfer19780) decMapintwrapUint64Slice(v *map[int]wrapUint64Slice, d *Decoder) { var h codecSelfer19780 z, r := GenHelper().Decoder(d) _, _, _ = h, z, r yyv1 := *v yyl1 := z.DecReadMapStart() if yyl1 == codecSelferDecContainerLenNil19780 { *v = nil } else { if yyv1 == nil { yyrl1 := z.DecInferLen(yyl1, z.DecBasicHandle().MaxInitLen, 32) yyv1 = make(map[int]wrapUint64Slice, yyrl1) *v = yyv1 } var yymk1 int var yymv1 wrapUint64Slice var yymg1, yymdn1 bool if z.DecBasicHandle().MapValueReset { yymg1 = true } if yyl1 != 0 { yyhl1 := yyl1 > 0 for yyj1 := 0; (yyhl1 && yyj1 < yyl1) || !(yyhl1 || z.DecCheckBreak()); yyj1++ { z.DecReadMapElemKey() yymk1 = (int)(z.C.IntV(r.DecodeInt64(), codecSelferBitsize19780)) if yymg1 { yymv1 = yyv1[yymk1] } else { yymv1 = nil } z.DecReadMapElemValue() yymdn1 = false if yyxt4 := z.Extension(yymv1); yyxt4 != nil { z.DecExtension(&yymv1, yyxt4) } else { yymv1.CodecDecodeSelf(d) } if yymdn1 { yyv1[yymk1] = nil } else { yyv1[yymk1] = yymv1 } } } // else len==0: leave as-is (do not clear map entries) z.DecReadMapEnd() } } func (x codecSelfer19780) encMapfloat64wrapStringSlice(v map[float64]wrapStringSlice, e *Encoder) { var h codecSelfer19780 z, r := GenHelper().Encoder(e) _, _, _ = h, z, r if v == nil { r.EncodeNil() } else if z.EncBasicHandle().Canonical { yys1 := make([]float64, 0, len(v)) for k, _ := range v { yys1 = append(yys1, float64(k)) } sort.Sort(codecSelfer19780float64Slice(yys1)) z.EncWriteMapStart(len(v)) for _, yyv1 := range yys1 { z.EncWriteMapElemKey() r.EncodeFloat64(yyv1) z.EncWriteMapElemValue() yye1 := v[float64(yyv1)] if yyxt2 := z.Extension(yye1); yyxt2 != nil { z.EncExtension(yye1, yyxt2) } else { yye1.CodecEncodeSelf(e) } } z.EncWriteMapEnd() } else { z.EncWriteMapStart(len(v)) for yyk1, yyv1 := range v { z.EncWriteMapElemKey() r.EncodeFloat64(float64(yyk1)) z.EncWriteMapElemValue() if yyxt4 := z.Extension(yyv1); yyxt4 != nil { z.EncExtension(yyv1, yyxt4) } else { yyv1.CodecEncodeSelf(e) } } z.EncWriteMapEnd() } } func (x codecSelfer19780) decMapfloat64wrapStringSlice(v *map[float64]wrapStringSlice, d *Decoder) { var h codecSelfer19780 z, r := GenHelper().Decoder(d) _, _, _ = h, z, r yyv1 := *v yyl1 := z.DecReadMapStart() if yyl1 == codecSelferDecContainerLenNil19780 { *v = nil } else { if yyv1 == nil { yyrl1 := z.DecInferLen(yyl1, z.DecBasicHandle().MaxInitLen, 32) yyv1 = make(map[float64]wrapStringSlice, yyrl1) *v = yyv1 } var yymk1 float64 var yymv1 wrapStringSlice var yymg1, yymdn1 bool if z.DecBasicHandle().MapValueReset { yymg1 = true } if yyl1 != 0 { yyhl1 := yyl1 > 0 for yyj1 := 0; (yyhl1 && yyj1 < yyl1) || !(yyhl1 || z.DecCheckBreak()); yyj1++ { z.DecReadMapElemKey() yymk1 = (float64)(r.DecodeFloat64()) if yymg1 { yymv1 = yyv1[yymk1] } else { yymv1 = nil } z.DecReadMapElemValue() yymdn1 = false if yyxt4 := z.Extension(yymv1); yyxt4 != nil { z.DecExtension(&yymv1, yyxt4) } else { yymv1.CodecDecodeSelf(d) } if yymdn1 { yyv1[yymk1] = nil } else { yyv1[yymk1] = yymv1 } } } // else len==0: leave as-is (do not clear map entries) z.DecReadMapEnd() } } func (x codecSelfer19780) encMapfloat32wrapStringSlice(v map[float32]wrapStringSlice, e *Encoder) { var h codecSelfer19780 z, r := GenHelper().Encoder(e) _, _, _ = h, z, r if v == nil { r.EncodeNil() } else if z.EncBasicHandle().Canonical { yys1 := make([]float64, 0, len(v)) for k, _ := range v { yys1 = append(yys1, float64(k)) } sort.Sort(codecSelfer19780float64Slice(yys1)) z.EncWriteMapStart(len(v)) for _, yyv1 := range yys1 { z.EncWriteMapElemKey() r.EncodeFloat32(float32(yyv1)) z.EncWriteMapElemValue() yye1 := v[float32(yyv1)] if yyxt2 := z.Extension(yye1); yyxt2 != nil { z.EncExtension(yye1, yyxt2) } else { yye1.CodecEncodeSelf(e) } } z.EncWriteMapEnd() } else { z.EncWriteMapStart(len(v)) for yyk1, yyv1 := range v { z.EncWriteMapElemKey() r.EncodeFloat32(float32(yyk1)) z.EncWriteMapElemValue() if yyxt4 := z.Extension(yyv1); yyxt4 != nil { z.EncExtension(yyv1, yyxt4) } else { yyv1.CodecEncodeSelf(e) } } z.EncWriteMapEnd() } } func (x codecSelfer19780) decMapfloat32wrapStringSlice(v *map[float32]wrapStringSlice, d *Decoder) { var h codecSelfer19780 z, r := GenHelper().Decoder(d) _, _, _ = h, z, r yyv1 := *v yyl1 := z.DecReadMapStart() if yyl1 == codecSelferDecContainerLenNil19780 { *v = nil } else { if yyv1 == nil { yyrl1 := z.DecInferLen(yyl1, z.DecBasicHandle().MaxInitLen, 28) yyv1 = make(map[float32]wrapStringSlice, yyrl1) *v = yyv1 } var yymk1 float32 var yymv1 wrapStringSlice var yymg1, yymdn1 bool if z.DecBasicHandle().MapValueReset { yymg1 = true } if yyl1 != 0 { yyhl1 := yyl1 > 0 for yyj1 := 0; (yyhl1 && yyj1 < yyl1) || !(yyhl1 || z.DecCheckBreak()); yyj1++ { z.DecReadMapElemKey() yymk1 = (float32)(z.DecDecodeFloat32()) if yymg1 { yymv1 = yyv1[yymk1] } else { yymv1 = nil } z.DecReadMapElemValue() yymdn1 = false if yyxt4 := z.Extension(yymv1); yyxt4 != nil { z.DecExtension(&yymv1, yyxt4) } else { yymv1.CodecDecodeSelf(d) } if yymdn1 { yyv1[yymk1] = nil } else { yyv1[yymk1] = yymv1 } } } // else len==0: leave as-is (do not clear map entries) z.DecReadMapEnd() } } func (x codecSelfer19780) encMapuint64wrapStringSlice(v map[uint64]wrapStringSlice, e *Encoder) { var h codecSelfer19780 z, r := GenHelper().Encoder(e) _, _, _ = h, z, r if v == nil { r.EncodeNil() } else if z.EncBasicHandle().Canonical { yys1 := make([]uint64, 0, len(v)) for k, _ := range v { yys1 = append(yys1, uint64(k)) } sort.Sort(codecSelfer19780uint64Slice(yys1)) z.EncWriteMapStart(len(v)) for _, yyv1 := range yys1 { z.EncWriteMapElemKey() r.EncodeUint(uint64(yyv1)) z.EncWriteMapElemValue() yye1 := v[uint64(yyv1)] if yyxt2 := z.Extension(yye1); yyxt2 != nil { z.EncExtension(yye1, yyxt2) } else { yye1.CodecEncodeSelf(e) } } z.EncWriteMapEnd() } else { z.EncWriteMapStart(len(v)) for yyk1, yyv1 := range v { z.EncWriteMapElemKey() r.EncodeUint(uint64(yyk1)) z.EncWriteMapElemValue() if yyxt4 := z.Extension(yyv1); yyxt4 != nil { z.EncExtension(yyv1, yyxt4) } else { yyv1.CodecEncodeSelf(e) } } z.EncWriteMapEnd() } } func (x codecSelfer19780) decMapuint64wrapStringSlice(v *map[uint64]wrapStringSlice, d *Decoder) { var h codecSelfer19780 z, r := GenHelper().Decoder(d) _, _, _ = h, z, r yyv1 := *v yyl1 := z.DecReadMapStart() if yyl1 == codecSelferDecContainerLenNil19780 { *v = nil } else { if yyv1 == nil { yyrl1 := z.DecInferLen(yyl1, z.DecBasicHandle().MaxInitLen, 32) yyv1 = make(map[uint64]wrapStringSlice, yyrl1) *v = yyv1 } var yymk1 uint64 var yymv1 wrapStringSlice var yymg1, yymdn1 bool if z.DecBasicHandle().MapValueReset { yymg1 = true } if yyl1 != 0 { yyhl1 := yyl1 > 0 for yyj1 := 0; (yyhl1 && yyj1 < yyl1) || !(yyhl1 || z.DecCheckBreak()); yyj1++ { z.DecReadMapElemKey() yymk1 = (uint64)(r.DecodeUint64()) if yymg1 { yymv1 = yyv1[yymk1] } else { yymv1 = nil } z.DecReadMapElemValue() yymdn1 = false if yyxt4 := z.Extension(yymv1); yyxt4 != nil { z.DecExtension(&yymv1, yyxt4) } else { yymv1.CodecDecodeSelf(d) } if yymdn1 { yyv1[yymk1] = nil } else { yyv1[yymk1] = yymv1 } } } // else len==0: leave as-is (do not clear map entries) z.DecReadMapEnd() } } func (x codecSelfer19780) encMapstringUint64TwrapStringSlice(v map[stringUint64T]wrapStringSlice, e *Encoder) { var h codecSelfer19780 z, r := GenHelper().Encoder(e) _, _, _ = h, z, r if v == nil { r.EncodeNil() } else if z.EncBasicHandle().Canonical { z.EncEncodeMapNonNil(v) } else { z.EncWriteMapStart(len(v)) for yyk1, yyv1 := range v { z.EncWriteMapElemKey() yy2 := &yyk1 if yyxt3 := z.Extension(yy2); yyxt3 != nil { z.EncExtension(yy2, yyxt3) } else { yy2.CodecEncodeSelf(e) } z.EncWriteMapElemValue() if yyxt4 := z.Extension(yyv1); yyxt4 != nil { z.EncExtension(yyv1, yyxt4) } else { yyv1.CodecEncodeSelf(e) } } z.EncWriteMapEnd() } } func (x codecSelfer19780) decMapstringUint64TwrapStringSlice(v *map[stringUint64T]wrapStringSlice, d *Decoder) { var h codecSelfer19780 z, r := GenHelper().Decoder(d) _, _, _ = h, z, r yyv1 := *v yyl1 := z.DecReadMapStart() if yyl1 == codecSelferDecContainerLenNil19780 { *v = nil } else { if yyv1 == nil { yyrl1 := z.DecInferLen(yyl1, z.DecBasicHandle().MaxInitLen, 48) yyv1 = make(map[stringUint64T]wrapStringSlice, yyrl1) *v = yyv1 } var yymk1 stringUint64T var yymv1 wrapStringSlice var yymg1, yymdn1 bool if z.DecBasicHandle().MapValueReset { yymg1 = true } if yyl1 != 0 { yyhl1 := yyl1 > 0 for yyj1 := 0; (yyhl1 && yyj1 < yyl1) || !(yyhl1 || z.DecCheckBreak()); yyj1++ { z.DecReadMapElemKey() if yyxt3 := z.Extension(yymk1); yyxt3 != nil { z.DecExtension(&yymk1, yyxt3) } else { yymk1.CodecDecodeSelf(d) } if yymg1 { yymv1 = yyv1[yymk1] } else { yymv1 = nil } z.DecReadMapElemValue() yymdn1 = false if yyxt5 := z.Extension(yymv1); yyxt5 != nil { z.DecExtension(&yymv1, yyxt5) } else { yymv1.CodecDecodeSelf(d) } if yymdn1 { yyv1[yymk1] = nil } else { yyv1[yymk1] = yymv1 } } } // else len==0: leave as-is (do not clear map entries) z.DecReadMapEnd() } } func (x codecSelfer19780) encSlicewrapBytes(v []wrapBytes, e *Encoder) { var h codecSelfer19780 z, r := GenHelper().Encoder(e) _, _, _ = h, z, r if v == nil { r.EncodeNil() return } z.EncWriteArrayStart(len(v)) for yyv1 := range v { z.EncWriteArrayElem() if yyxt2 := z.Extension(v[yyv1]); yyxt2 != nil { z.EncExtension(v[yyv1], yyxt2) } else { v[yyv1].CodecEncodeSelf(e) } } z.EncWriteArrayEnd() } func (x codecSelfer19780) decSlicewrapBytes(v *[]wrapBytes, d *Decoder) { var h codecSelfer19780 z, r := GenHelper().Decoder(d) _, _, _ = h, z, r yyv1 := *v yyh1, yyl1 := z.DecSliceHelperStart() var yyc1 bool _ = yyc1 if yyh1.IsNil { if yyv1 != nil { yyv1 = nil yyc1 = true } } else if yyl1 == 0 { if yyv1 == nil { yyv1 = []wrapBytes{} yyc1 = true } else if len(yyv1) != 0 { yyv1 = yyv1[:0] yyc1 = true } } else { yyhl1 := yyl1 > 0 var yyrl1 int _ = yyrl1 if yyhl1 { if yyl1 > cap(yyv1) { yyrl1 = z.DecInferLen(yyl1, z.DecBasicHandle().MaxInitLen, 24) if yyrl1 <= cap(yyv1) { yyv1 = yyv1[:yyrl1] } else { yyv1 = make([]wrapBytes, yyrl1) } yyc1 = true } else if yyl1 != len(yyv1) { yyv1 = yyv1[:yyl1] yyc1 = true } } var yyj1 int for yyj1 = 0; (yyhl1 && yyj1 < yyl1) || !(yyhl1 || z.DecCheckBreak()); yyj1++ { // bounds-check-elimination if yyj1 == 0 && yyv1 == nil { if yyhl1 { yyrl1 = z.DecInferLen(yyl1, z.DecBasicHandle().MaxInitLen, 24) } else { yyrl1 = 8 } yyv1 = make([]wrapBytes, yyrl1) yyc1 = true } yyh1.ElemContainerState(yyj1) var yydb1 bool if yyj1 >= len(yyv1) { yyv1 = append(yyv1, nil) yyc1 = true } if yydb1 { z.DecSwallow() } else { if yyxt3 := z.Extension(yyv1[yyj1]); yyxt3 != nil { z.DecExtension(&yyv1[yyj1], yyxt3) } else { yyv1[yyj1].CodecDecodeSelf(d) } } } if yyj1 < len(yyv1) { yyv1 = yyv1[:yyj1] yyc1 = true } else if yyj1 == 0 && yyv1 == nil { yyv1 = []wrapBytes{} yyc1 = true } } yyh1.End() if yyc1 { *v = yyv1 } } func (x codecSelfer19780) encSlicewrapUint8(v []wrapUint8, e *Encoder) { var h codecSelfer19780 z, r := GenHelper().Encoder(e) _, _, _ = h, z, r if v == nil { r.EncodeNil() return } z.EncWriteArrayStart(len(v)) for yyv1 := range v { z.EncWriteArrayElem() if yyxt2 := z.Extension(v[yyv1]); yyxt2 != nil { z.EncExtension(v[yyv1], yyxt2) } else { v[yyv1].CodecEncodeSelf(e) } } z.EncWriteArrayEnd() } func (x codecSelfer19780) decSlicewrapUint8(v *[]wrapUint8, d *Decoder) { var h codecSelfer19780 z, r := GenHelper().Decoder(d) _, _, _ = h, z, r yyv1 := *v yyh1, yyl1 := z.DecSliceHelperStart() var yyc1 bool _ = yyc1 if yyh1.IsNil { if yyv1 != nil { yyv1 = nil yyc1 = true } } else if yyl1 == 0 { if yyv1 == nil { yyv1 = []wrapUint8{} yyc1 = true } else if len(yyv1) != 0 { yyv1 = yyv1[:0] yyc1 = true } } else { yyhl1 := yyl1 > 0 var yyrl1 int _ = yyrl1 if yyhl1 { if yyl1 > cap(yyv1) { yyrl1 = z.DecInferLen(yyl1, z.DecBasicHandle().MaxInitLen, 1) if yyrl1 <= cap(yyv1) { yyv1 = yyv1[:yyrl1] } else { yyv1 = make([]wrapUint8, yyrl1) } yyc1 = true } else if yyl1 != len(yyv1) { yyv1 = yyv1[:yyl1] yyc1 = true } } var yyj1 int for yyj1 = 0; (yyhl1 && yyj1 < yyl1) || !(yyhl1 || z.DecCheckBreak()); yyj1++ { // bounds-check-elimination if yyj1 == 0 && yyv1 == nil { if yyhl1 { yyrl1 = z.DecInferLen(yyl1, z.DecBasicHandle().MaxInitLen, 1) } else { yyrl1 = 8 } yyv1 = make([]wrapUint8, yyrl1) yyc1 = true } yyh1.ElemContainerState(yyj1) var yydb1 bool if yyj1 >= len(yyv1) { yyv1 = append(yyv1, 0) yyc1 = true } if yydb1 { z.DecSwallow() } else { if yyxt3 := z.Extension(yyv1[yyj1]); yyxt3 != nil { z.DecExtension(&yyv1[yyj1], yyxt3) } else { yyv1[yyj1].CodecDecodeSelf(d) } } } if yyj1 < len(yyv1) { yyv1 = yyv1[:yyj1] yyc1 = true } else if yyj1 == 0 && yyv1 == nil { yyv1 = []wrapUint8{} yyc1 = true } } yyh1.End() if yyc1 { *v = yyv1 } } func (x codecSelfer19780) encArray4stringUint64T(v *[4]stringUint64T, e *Encoder) { var h codecSelfer19780 z, r := GenHelper().Encoder(e) _, _, _ = h, z, r if v == nil { r.EncodeNil() return } z.EncWriteArrayStart(len(v)) for yyv1 := range v { z.EncWriteArrayElem() yy2 := &v[yyv1] if yyxt3 := z.Extension(yy2); yyxt3 != nil { z.EncExtension(yy2, yyxt3) } else { yy2.CodecEncodeSelf(e) } } z.EncWriteArrayEnd() } func (x codecSelfer19780) decArray4stringUint64T(v *[4]stringUint64T, d *Decoder) { var h codecSelfer19780 z, r := GenHelper().Decoder(d) _, _, _ = h, z, r yyv1 := v yyh1, yyl1 := z.DecSliceHelperStart() if yyl1 == 0 { } else { yyhl1 := yyl1 > 0 var yyrl1 int _ = yyrl1 var yyj1 int for yyj1 = 0; (yyhl1 && yyj1 < yyl1) || !(yyhl1 || z.DecCheckBreak()); yyj1++ { // bounds-check-elimination yyh1.ElemContainerState(yyj1) var yydb1 bool if yyj1 >= len(yyv1) { z.DecArrayCannotExpand(len(v), yyj1+1) yydb1 = true } if yydb1 { z.DecSwallow() } else { if yyxt3 := z.Extension(yyv1[yyj1]); yyxt3 != nil { z.DecExtension(&yyv1[yyj1], yyxt3) } else { yyv1[yyj1].CodecDecodeSelf(d) } } } } yyh1.End() } func (x codecSelfer19780) encArray4uint64(v *[4]uint64, e *Encoder) { var h codecSelfer19780 z, r := GenHelper().Encoder(e) _, _, _ = h, z, r if v == nil { r.EncodeNil() return } z.EncWriteArrayStart(len(v)) for yyv1 := range v { z.EncWriteArrayElem() r.EncodeUint(uint64(v[yyv1])) } z.EncWriteArrayEnd() } func (x codecSelfer19780) decArray4uint64(v *[4]uint64, d *Decoder) { var h codecSelfer19780 z, r := GenHelper().Decoder(d) _, _, _ = h, z, r yyv1 := v yyh1, yyl1 := z.DecSliceHelperStart() if yyl1 == 0 { } else { yyhl1 := yyl1 > 0 var yyrl1 int _ = yyrl1 var yyj1 int for yyj1 = 0; (yyhl1 && yyj1 < yyl1) || !(yyhl1 || z.DecCheckBreak()); yyj1++ { // bounds-check-elimination yyh1.ElemContainerState(yyj1) var yydb1 bool if yyj1 >= len(yyv1) { z.DecArrayCannotExpand(len(v), yyj1+1) yydb1 = true } if yydb1 { z.DecSwallow() } else { yyv1[yyj1] = (uint64)(r.DecodeUint64()) } } } yyh1.End() } func (x codecSelfer19780) encSlicePtrtoArray4uint64(v []*[4]uint64, e *Encoder) { var h codecSelfer19780 z, r := GenHelper().Encoder(e) _, _, _ = h, z, r if v == nil { r.EncodeNil() return } z.EncWriteArrayStart(len(v)) for yyv1 := range v { z.EncWriteArrayElem() if v[yyv1] == nil { r.EncodeNil() } else { h.encArray4uint64((*[4]uint64)(v[yyv1]), e) } } z.EncWriteArrayEnd() } func (x codecSelfer19780) decSlicePtrtoArray4uint64(v *[]*[4]uint64, d *Decoder) { var h codecSelfer19780 z, r := GenHelper().Decoder(d) _, _, _ = h, z, r yyv1 := *v yyh1, yyl1 := z.DecSliceHelperStart() var yyc1 bool _ = yyc1 if yyh1.IsNil { if yyv1 != nil { yyv1 = nil yyc1 = true } } else if yyl1 == 0 { if yyv1 == nil { yyv1 = []*[4]uint64{} yyc1 = true } else if len(yyv1) != 0 { yyv1 = yyv1[:0] yyc1 = true } } else { yyhl1 := yyl1 > 0 var yyrl1 int _ = yyrl1 if yyhl1 { if yyl1 > cap(yyv1) { yyrl1 = z.DecInferLen(yyl1, z.DecBasicHandle().MaxInitLen, 8) if yyrl1 <= cap(yyv1) { yyv1 = yyv1[:yyrl1] } else { yyv1 = make([]*[4]uint64, yyrl1) } yyc1 = true } else if yyl1 != len(yyv1) { yyv1 = yyv1[:yyl1] yyc1 = true } } var yyj1 int for yyj1 = 0; (yyhl1 && yyj1 < yyl1) || !(yyhl1 || z.DecCheckBreak()); yyj1++ { // bounds-check-elimination if yyj1 == 0 && yyv1 == nil { if yyhl1 { yyrl1 = z.DecInferLen(yyl1, z.DecBasicHandle().MaxInitLen, 8) } else { yyrl1 = 8 } yyv1 = make([]*[4]uint64, yyrl1) yyc1 = true } yyh1.ElemContainerState(yyj1) var yydb1 bool if yyj1 >= len(yyv1) { yyv1 = append(yyv1, nil) yyc1 = true } if yydb1 { z.DecSwallow() } else { if r.TryNil() { yyv1[yyj1] = nil } else { if yyv1[yyj1] == nil { yyv1[yyj1] = new([4]uint64) } h.decArray4uint64((*[4]uint64)(yyv1[yyj1]), d) } } } if yyj1 < len(yyv1) { yyv1 = yyv1[:yyj1] yyc1 = true } else if yyj1 == 0 && yyv1 == nil { yyv1 = []*[4]uint64{} yyc1 = true } } yyh1.End() if yyc1 { *v = yyv1 } } func (x codecSelfer19780) encMapstringUint64TPtrtostringUint64T(v map[stringUint64T]*stringUint64T, e *Encoder) { var h codecSelfer19780 z, r := GenHelper().Encoder(e) _, _, _ = h, z, r if v == nil { r.EncodeNil() } else if z.EncBasicHandle().Canonical { z.EncEncodeMapNonNil(v) } else { z.EncWriteMapStart(len(v)) for yyk1, yyv1 := range v { z.EncWriteMapElemKey() yy2 := &yyk1 if yyxt3 := z.Extension(yy2); yyxt3 != nil { z.EncExtension(yy2, yyxt3) } else { yy2.CodecEncodeSelf(e) } z.EncWriteMapElemValue() if yyv1 == nil { r.EncodeNil() } else { if yyxt4 := z.Extension(yyv1); yyxt4 != nil { z.EncExtension(yyv1, yyxt4) } else { yyv1.CodecEncodeSelf(e) } } } z.EncWriteMapEnd() } } func (x codecSelfer19780) decMapstringUint64TPtrtostringUint64T(v *map[stringUint64T]*stringUint64T, d *Decoder) { var h codecSelfer19780 z, r := GenHelper().Decoder(d) _, _, _ = h, z, r yyv1 := *v yyl1 := z.DecReadMapStart() if yyl1 == codecSelferDecContainerLenNil19780 { *v = nil } else { if yyv1 == nil { yyrl1 := z.DecInferLen(yyl1, z.DecBasicHandle().MaxInitLen, 32) yyv1 = make(map[stringUint64T]*stringUint64T, yyrl1) *v = yyv1 } var yymk1 stringUint64T var yymv1 *stringUint64T var yymg1, yymdn1, yyms1, yymok1 bool if z.DecBasicHandle().MapValueReset { yymg1 = true } if yyl1 != 0 { yyhl1 := yyl1 > 0 for yyj1 := 0; (yyhl1 && yyj1 < yyl1) || !(yyhl1 || z.DecCheckBreak()); yyj1++ { z.DecReadMapElemKey() if yyxt3 := z.Extension(yymk1); yyxt3 != nil { z.DecExtension(&yymk1, yyxt3) } else { yymk1.CodecDecodeSelf(d) } yyms1 = true if yymg1 { yymv1, yymok1 = yyv1[yymk1] if yymok1 { yyms1 = false } } else { yymv1 = nil } z.DecReadMapElemValue() yymdn1 = false if r.TryNil() { yymdn1 = true } else { if yymv1 == nil { yymv1 = new(stringUint64T) } if yyxt5 := z.Extension(yymv1); yyxt5 != nil { z.DecExtension(yymv1, yyxt5) } else { yymv1.CodecDecodeSelf(d) } } if yymdn1 { yyv1[yymk1] = nil } else if yyms1 { yyv1[yymk1] = yymv1 } } } // else len==0: leave as-is (do not clear map entries) z.DecReadMapEnd() } } func (x codecSelfer19780) encMapwrapStringInterface(v map[wrapString]interface{}, e *Encoder) { var h codecSelfer19780 z, r := GenHelper().Encoder(e) _, _, _ = h, z, r if v == nil { r.EncodeNil() } else if z.EncBasicHandle().Canonical { var yyvv1 wrapString yyencfn1 := z.EncFnGivenAddr(&yyvv1) yys1 := make([]string, 0, len(v)) for k, _ := range v { yys1 = append(yys1, string(k)) } sort.Sort(codecSelfer19780stringSlice(yys1)) z.EncWriteMapStart(len(v)) for _, yyv1 := range yys1 { z.EncWriteMapElemKey() yyvv1 = wrapString(yyv1) z.EncEncodeNumBoolStrKindGivenAddr(&yyvv1, yyencfn1) z.EncWriteMapElemValue() yye1 := v[yyvv1] if yye1 == nil { r.EncodeNil() } else { z.EncFallback(yye1) } } z.EncWriteMapEnd() } else { z.EncWriteMapStart(len(v)) for yyk1, yyv1 := range v { z.EncWriteMapElemKey() if yyxt3 := z.Extension(yyk1); yyxt3 != nil { z.EncExtension(yyk1, yyxt3) } else { yyk1.CodecEncodeSelf(e) } z.EncWriteMapElemValue() if yyv1 == nil { r.EncodeNil() } else { z.EncFallback(yyv1) } } z.EncWriteMapEnd() } } func (x codecSelfer19780) decMapwrapStringInterface(v *map[wrapString]interface{}, d *Decoder) { var h codecSelfer19780 z, r := GenHelper().Decoder(d) _, _, _ = h, z, r yyv1 := *v yyl1 := z.DecReadMapStart() if yyl1 == codecSelferDecContainerLenNil19780 { *v = nil } else { if yyv1 == nil { yyrl1 := z.DecInferLen(yyl1, z.DecBasicHandle().MaxInitLen, 32) yyv1 = make(map[wrapString]interface{}, yyrl1) *v = yyv1 } var yymk1 wrapString var yymv1 interface{} var yymg1, yymdn1 bool if z.DecBasicHandle().MapValueReset { if !z.DecBasicHandle().InterfaceReset { yymg1 = true } } if yyl1 != 0 { yyhl1 := yyl1 > 0 for yyj1 := 0; (yyhl1 && yyj1 < yyl1) || !(yyhl1 || z.DecCheckBreak()); yyj1++ { z.DecReadMapElemKey() if yyxt3 := z.Extension(yymk1); yyxt3 != nil { z.DecExtension(&yymk1, yyxt3) } else { yymk1.CodecDecodeSelf(d) } if yymg1 { yymv1 = yyv1[yymk1] } else { yymv1 = nil } z.DecReadMapElemValue() yymdn1 = false z.DecFallback(&yymv1, true) if yymdn1 { yyv1[yymk1] = nil } else { yyv1[yymk1] = yymv1 } } } // else len==0: leave as-is (do not clear map entries) z.DecReadMapEnd() } } func (x codecSelfer19780) encMapstringPtrtoTestStrucFlex(v map[string]*TestStrucFlex, e *Encoder) { var h codecSelfer19780 z, r := GenHelper().Encoder(e) _, _, _ = h, z, r if v == nil { r.EncodeNil() } else if z.EncBasicHandle().Canonical { yys1 := make([]string, 0, len(v)) for k, _ := range v { yys1 = append(yys1, string(k)) } sort.Sort(codecSelfer19780stringSlice(yys1)) z.EncWriteMapStart(len(v)) for _, yyv1 := range yys1 { z.EncWriteMapElemKey() r.EncodeString(yyv1) z.EncWriteMapElemValue() yye1 := v[string(yyv1)] if yye1 == nil { r.EncodeNil() } else { if yyxt2 := z.Extension(yye1); yyxt2 != nil { z.EncExtension(yye1, yyxt2) } else { yye1.CodecEncodeSelf(e) } } } z.EncWriteMapEnd() } else { z.EncWriteMapStart(len(v)) for yyk1, yyv1 := range v { z.EncWriteMapElemKey() r.EncodeString(string(yyk1)) z.EncWriteMapElemValue() if yyv1 == nil { r.EncodeNil() } else { if yyxt4 := z.Extension(yyv1); yyxt4 != nil { z.EncExtension(yyv1, yyxt4) } else { yyv1.CodecEncodeSelf(e) } } } z.EncWriteMapEnd() } } func (x codecSelfer19780) decMapstringPtrtoTestStrucFlex(v *map[string]*TestStrucFlex, d *Decoder) { var h codecSelfer19780 z, r := GenHelper().Decoder(d) _, _, _ = h, z, r yyv1 := *v yyl1 := z.DecReadMapStart() if yyl1 == codecSelferDecContainerLenNil19780 { *v = nil } else { if yyv1 == nil { yyrl1 := z.DecInferLen(yyl1, z.DecBasicHandle().MaxInitLen, 24) yyv1 = make(map[string]*TestStrucFlex, yyrl1) *v = yyv1 } var yymk1 string var yymv1 *TestStrucFlex var yymg1, yymdn1, yyms1, yymok1 bool if z.DecBasicHandle().MapValueReset { yymg1 = true } if yyl1 != 0 { yyhl1 := yyl1 > 0 for yyj1 := 0; (yyhl1 && yyj1 < yyl1) || !(yyhl1 || z.DecCheckBreak()); yyj1++ { z.DecReadMapElemKey() yymk1 = (string)(z.DecStringZC(r.DecodeStringAsBytes())) yyms1 = true if yymg1 { yymv1, yymok1 = yyv1[yymk1] if yymok1 { yyms1 = false } } else { yymv1 = nil } z.DecReadMapElemValue() yymdn1 = false if r.TryNil() { yymdn1 = true } else { if yymv1 == nil { yymv1 = new(TestStrucFlex) } if yyxt4 := z.Extension(yymv1); yyxt4 != nil { z.DecExtension(yymv1, yyxt4) } else { yymv1.CodecDecodeSelf(d) } } if yymdn1 { yyv1[yymk1] = nil } else if yyms1 { yyv1[yymk1] = yymv1 } } } // else len==0: leave as-is (do not clear map entries) z.DecReadMapEnd() } } func (x codecSelfer19780) encMapstringTestStrucFlex(v map[string]TestStrucFlex, e *Encoder) { var h codecSelfer19780 z, r := GenHelper().Encoder(e) _, _, _ = h, z, r if v == nil { r.EncodeNil() } else if z.EncBasicHandle().Canonical { yys1 := make([]string, 0, len(v)) for k, _ := range v { yys1 = append(yys1, string(k)) } sort.Sort(codecSelfer19780stringSlice(yys1)) z.EncWriteMapStart(len(v)) for _, yyv1 := range yys1 { z.EncWriteMapElemKey() r.EncodeString(yyv1) z.EncWriteMapElemValue() yye1 := v[string(yyv1)] yy2 := &yye1 if yyxt3 := z.Extension(yy2); yyxt3 != nil { z.EncExtension(yy2, yyxt3) } else { yy2.CodecEncodeSelf(e) } } z.EncWriteMapEnd() } else { z.EncWriteMapStart(len(v)) for yyk1, yyv1 := range v { z.EncWriteMapElemKey() r.EncodeString(string(yyk1)) z.EncWriteMapElemValue() yy5 := &yyv1 if yyxt6 := z.Extension(yy5); yyxt6 != nil { z.EncExtension(yy5, yyxt6) } else { yy5.CodecEncodeSelf(e) } } z.EncWriteMapEnd() } } func (x codecSelfer19780) decMapstringTestStrucFlex(v *map[string]TestStrucFlex, d *Decoder) { var h codecSelfer19780 z, r := GenHelper().Decoder(d) _, _, _ = h, z, r yyv1 := *v yyl1 := z.DecReadMapStart() if yyl1 == codecSelferDecContainerLenNil19780 { *v = nil } else { if yyv1 == nil { yyrl1 := z.DecInferLen(yyl1, z.DecBasicHandle().MaxInitLen, 1880) yyv1 = make(map[string]TestStrucFlex, yyrl1) *v = yyv1 } var yymk1 string var yymv1 TestStrucFlex var yymg1, yymdn1 bool if z.DecBasicHandle().MapValueReset { yymg1 = true } if yyl1 != 0 { yyhl1 := yyl1 > 0 for yyj1 := 0; (yyhl1 && yyj1 < yyl1) || !(yyhl1 || z.DecCheckBreak()); yyj1++ { z.DecReadMapElemKey() yymk1 = (string)(z.DecStringZC(r.DecodeStringAsBytes())) if yymg1 { yymv1 = yyv1[yymk1] } else { yymv1 = TestStrucFlex{} } z.DecReadMapElemValue() yymdn1 = false if yyxt4 := z.Extension(yymv1); yyxt4 != nil { z.DecExtension(&yymv1, yyxt4) } else { yymv1.CodecDecodeSelf(d) } if yymdn1 { yyv1[yymk1] = TestStrucFlex{} } else { yyv1[yymk1] = yymv1 } } } // else len==0: leave as-is (do not clear map entries) z.DecReadMapEnd() } } func (x codecSelfer19780) encSlicePtrtoTestStrucFlex(v []*TestStrucFlex, e *Encoder) { var h codecSelfer19780 z, r := GenHelper().Encoder(e) _, _, _ = h, z, r if v == nil { r.EncodeNil() return } z.EncWriteArrayStart(len(v)) for yyv1 := range v { z.EncWriteArrayElem() if v[yyv1] == nil { r.EncodeNil() } else { if yyxt2 := z.Extension(v[yyv1]); yyxt2 != nil { z.EncExtension(v[yyv1], yyxt2) } else { v[yyv1].CodecEncodeSelf(e) } } } z.EncWriteArrayEnd() } func (x codecSelfer19780) decSlicePtrtoTestStrucFlex(v *[]*TestStrucFlex, d *Decoder) { var h codecSelfer19780 z, r := GenHelper().Decoder(d) _, _, _ = h, z, r yyv1 := *v yyh1, yyl1 := z.DecSliceHelperStart() var yyc1 bool _ = yyc1 if yyh1.IsNil { if yyv1 != nil { yyv1 = nil yyc1 = true } } else if yyl1 == 0 { if yyv1 == nil { yyv1 = []*TestStrucFlex{} yyc1 = true } else if len(yyv1) != 0 { yyv1 = yyv1[:0] yyc1 = true } } else { yyhl1 := yyl1 > 0 var yyrl1 int _ = yyrl1 if yyhl1 { if yyl1 > cap(yyv1) { yyrl1 = z.DecInferLen(yyl1, z.DecBasicHandle().MaxInitLen, 8) if yyrl1 <= cap(yyv1) { yyv1 = yyv1[:yyrl1] } else { yyv1 = make([]*TestStrucFlex, yyrl1) } yyc1 = true } else if yyl1 != len(yyv1) { yyv1 = yyv1[:yyl1] yyc1 = true } } var yyj1 int for yyj1 = 0; (yyhl1 && yyj1 < yyl1) || !(yyhl1 || z.DecCheckBreak()); yyj1++ { // bounds-check-elimination if yyj1 == 0 && yyv1 == nil { if yyhl1 { yyrl1 = z.DecInferLen(yyl1, z.DecBasicHandle().MaxInitLen, 8) } else { yyrl1 = 8 } yyv1 = make([]*TestStrucFlex, yyrl1) yyc1 = true } yyh1.ElemContainerState(yyj1) var yydb1 bool if yyj1 >= len(yyv1) { yyv1 = append(yyv1, nil) yyc1 = true } if yydb1 { z.DecSwallow() } else { if r.TryNil() { yyv1[yyj1] = nil } else { if yyv1[yyj1] == nil { yyv1[yyj1] = new(TestStrucFlex) } if yyxt3 := z.Extension(yyv1[yyj1]); yyxt3 != nil { z.DecExtension(yyv1[yyj1], yyxt3) } else { yyv1[yyj1].CodecDecodeSelf(d) } } } } if yyj1 < len(yyv1) { yyv1 = yyv1[:yyj1] yyc1 = true } else if yyj1 == 0 && yyv1 == nil { yyv1 = []*TestStrucFlex{} yyc1 = true } } yyh1.End() if yyc1 { *v = yyv1 } } go-1.2.8/codec/values_flex_test.go000066400000000000000000000252671435255326100171310ustar00rootroot00000000000000// comment this out // // + build testing // 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" "strconv" "strings" "time" ) const teststrucflexChanCap = 64 // This file contains values used by tests alone. // This is where we may try out different things, // that other engines may not support or may barf upon // e.g. custom extensions for wrapped types, maps with non-string keys, etc. // some funky types to test codecgen type codecgenA struct { ZZ []byte } type codecgenB struct { AA codecgenA } type codecgenC struct { _struct struct{} `codec:",omitempty"` BB codecgenB } type TestCodecgenG struct { TestCodecgenG int } type codecgenH struct { TestCodecgenG } type codecgenI struct { codecgenH } type codecgenK struct { X int Y string } type codecgenL struct { X int Y uint32 } type codecgenM struct { codecgenK codecgenL } // some types to test struct keytype type testStrucKeyTypeT0 struct { _struct struct{} F int } type testStrucKeyTypeT1 struct { _struct struct{} `codec:",string"` F int `codec:"FFFF"` } type testStrucKeyTypeT2 struct { _struct struct{} `codec:",int"` F int `codec:"-1"` } type testStrucKeyTypeT3 struct { _struct struct{} `codec:",uint"` F int `codec:"1"` } type testStrucKeyTypeT4 struct { _struct struct{} `codec:",float"` F int `codec:"2.5"` } // Some unused types just stored here type Bbool bool type Aarray [1]string type Sstring string type Sstructsmall struct { A int } type Sstructbig struct { _struct struct{} A int B bool c string // Sval Sstruct Ssmallptr *Sstructsmall Ssmall Sstructsmall Sptr *Sstructbig } type SstructbigToArray struct { _struct struct{} `codec:",toarray"` A int B bool c string // Sval Sstruct Ssmallptr *Sstructsmall Ssmall Sstructsmall Sptr *Sstructbig } // small struct for testing that codecgen works for unexported types type tLowerFirstLetter struct { I int u uint64 S string b []byte } // Some wrapped types which are used as extensions type wrapInt64 int64 type wrapUint8 uint8 type wrapBytes []byte // some types that define how to marshal themselves type testMarshalAsJSON bool type testMarshalAsBinary []byte type testMarshalAsText string // some types used for extensions type testUintToBytes uint32 func (x testMarshalAsJSON) MarshalJSON() (data []byte, err error) { if x { data = []byte("true") } else { data = []byte("false") } return } func (x *testMarshalAsJSON) UnmarshalJSON(data []byte) (err error) { switch string(data) { case "true": *x = true case "false": *x = false default: err = fmt.Errorf("testMarshalAsJSON failed to decode as bool: %s", data) } return } func (x testMarshalAsBinary) MarshalBinary() (data []byte, err error) { data = []byte(x) return } func (x *testMarshalAsBinary) UnmarshalBinary(data []byte) (err error) { *x = data return } func (x testMarshalAsText) MarshalText() (text []byte, err error) { text = []byte(x) return } func (x *testMarshalAsText) UnmarshalText(text []byte) (err error) { *x = testMarshalAsText(string(text)) return } type AnonInTestStrucIntf struct { Islice []interface{} Ms map[string]interface{} Nintf interface{} //don't set this, so we can test for nil T time.Time Tptr *time.Time } type missingFielderT1 struct { S string B bool f float64 i int64 } func (t *missingFielderT1) CodecMissingField(field []byte, value interface{}) bool { switch string(field) { case "F": t.f = value.(float64) case "I": t.i = value.(int64) default: return false } return true } func (t *missingFielderT1) CodecMissingFields() map[string]interface{} { return map[string]interface{}{"F": t.f, "I": t.i} } type missingFielderT11 struct { s1 string S2 string } func (t *missingFielderT11) CodecMissingField(field []byte, value interface{}) bool { if "s1" == string(field) { t.s1 = value.(string) return true } return false } // missingFielderT11 implements CodecMissingFields on the value (not pointer) func (t missingFielderT11) CodecMissingFields() map[string]interface{} { return map[string]interface{}{"s1": t.s1} } type missingFielderT2 struct { S string B bool F float64 I int64 } type testSelfExtHelper struct { S string I int64 B bool } type TestSelfExtImpl struct { testSelfExtHelper } type TestSelfExtImpl2 struct { M string O bool } type TestTwoNakedInterfaces struct { A interface{} B interface{} } var testWRepeated512 wrapBytes var testStrucTime = time.Date(2012, 2, 2, 2, 2, 2, 2000, time.UTC).UTC() func init() { var testARepeated512 [512]byte for i := range testARepeated512 { testARepeated512[i] = 'A' } testWRepeated512 = wrapBytes(testARepeated512[:]) } type TestStrucFlex struct { _struct struct{} `codec:",omitempty"` //set omitempty for every field TestStrucCommon Chstr chan string Mis map[int]string Mbu64 map[bool]struct{} Mu8e map[byte]struct{} Mu8u64 map[byte]stringUint64T Msp2ss map[*string][]string Mip2ss map[*uint64][]string Ms2misu map[string]map[uint64]stringUint64T Miwu64s map[int]wrapUint64Slice Mfwss map[float64]wrapStringSlice Mf32wss map[float32]wrapStringSlice Mui2wss map[uint64]wrapStringSlice // DecodeNaked bombs because stringUint64T is decoded as a map, // and a map cannot be the key type of a map. // Ensure this is set to nil if decoding into a nil interface{}. Msu2wss map[stringUint64T]wrapStringSlice Ci64 wrapInt64 Swrapbytes []wrapBytes Swrapuint8 []wrapUint8 ArrStrUi64T [4]stringUint64T Ui64array [4]uint64 Ui64slicearray []*[4]uint64 SintfAarray []interface{} // Ensure this is set to nil if decoding into a nil interface{}. MstrUi64TSelf map[stringUint64T]*stringUint64T Ttime time.Time Ttimeptr *time.Time // make this a ptr, so that it could be set or not. // for comparison (e.g. with msgp), give it a struct tag (so it is not inlined), // make this one omitempty (so it is excluded if nil). *AnonInTestStrucIntf `json:",omitempty"` M map[interface{}]interface{} `json:"-"` Msu map[wrapString]interface{} Mtsptr map[string]*TestStrucFlex Mts map[string]TestStrucFlex Its []*TestStrucFlex Nteststruc *TestStrucFlex MarJ testMarshalAsJSON MarT testMarshalAsText MarB testMarshalAsBinary XuintToBytes testUintToBytes Ffunc func() error // expect this to be skipped/ignored Bboolignore bool `codec:"-"` // expect this to be skipped/ignored Cmplx64 complex64 Cmplx128 complex128 } func newTestStrucFlex(depth, n int, bench, useInterface, useStringKeyOnly bool) (ts *TestStrucFlex) { ts = &TestStrucFlex{ Chstr: make(chan string, teststrucflexChanCap), Miwu64s: map[int]wrapUint64Slice{ 5: []wrapUint64{1, 2, 3, 4, 5}, 3: []wrapUint64{1, 2, 3}, }, Mf32wss: map[float32]wrapStringSlice{ 5.0: []wrapString{"1.0", "2.0", "3.0", "4.0", "5.0"}, 3.0: []wrapString{"1.0", "2.0", "3.0"}, }, Mui2wss: map[uint64]wrapStringSlice{ 5: []wrapString{"1.0", "2.0", "3.0", "4.0", "5.0"}, 3: []wrapString{"1.0", "2.0", "3.0"}, }, Mfwss: map[float64]wrapStringSlice{ 5.0: []wrapString{"1.0", "2.0", "3.0", "4.0", "5.0"}, 3.0: []wrapString{"1.0", "2.0", "3.0"}, }, // DecodeNaked bombs here, because the stringUint64T is decoded as a map, // and a map cannot be the key type of a map. // Ensure this is set to nil if decoding into a nil interface{}. Msu2wss: map[stringUint64T]wrapStringSlice{ stringUint64T{"5", 5}: []wrapString{"1", "2", "3", "4", "5"}, stringUint64T{"3", 3}: []wrapString{"1", "2", "3"}, }, Mis: map[int]string{ 1: "one", 22: "twenty two", -44: "minus forty four", }, Ms2misu: map[string]map[uint64]stringUint64T{ "1": {1: {"11", 11}}, "22": {1: {"2222", 2222}}, "333": {1: {"333333", 333333}}, }, Mbu64: map[bool]struct{}{false: {}, true: {}}, Mu8e: map[byte]struct{}{1: {}, 2: {}, 3: {}, 4: {}}, Mu8u64: make(map[byte]stringUint64T), Mip2ss: make(map[*uint64][]string), Msp2ss: make(map[*string][]string), M: make(map[interface{}]interface{}), Msu: make(map[wrapString]interface{}), Ci64: -22, Swrapbytes: []wrapBytes{ // lengths of 1, 2, 4, 8, 16, 32, 64, 128, 256, testWRepeated512[:1], testWRepeated512[:2], testWRepeated512[:4], testWRepeated512[:8], testWRepeated512[:16], testWRepeated512[:32], testWRepeated512[:64], testWRepeated512[:128], testWRepeated512[:256], testWRepeated512[:512], }, Swrapuint8: []wrapUint8{ 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', }, Ui64array: [4]uint64{4, 16, 64, 256}, ArrStrUi64T: [4]stringUint64T{{"4", 4}, {"3", 3}, {"2", 2}, {"1", 1}}, SintfAarray: []interface{}{Aarray{"s"}}, MstrUi64TSelf: make(map[stringUint64T]*stringUint64T, numStrUi64T), Ttime: testStrucTime, Ttimeptr: &testStrucTime, MarJ: true, MarT: "hello string", MarB: []byte("hello bytes"), XuintToBytes: 16, Cmplx64: complex(16, 0), Cmplx128: complex(1616, 0), } var strslice []string for i := uint64(0); i < numStrUi64T; i++ { s := strings.Repeat(strconv.FormatUint(i, 10), 4) ss := stringUint64T{S: s, U: i} strslice = append(strslice, s) // Ensure this is set to nil if decoding into a nil interface{}. ts.MstrUi64TSelf[ss] = &ss ts.Mu8u64[s[0]] = ss ts.Mip2ss[&i] = strslice ts.Msp2ss[&s] = strslice // add some other values of maps and pointers into M ts.M[s] = strslice // cannot use this, as converting stringUint64T to interface{} returns map, // DecodeNaked does this, causing "hash of unhashable value" as some maps cannot be map keys // ts.M[ss] = &ss ts.Msu[wrapString(s)] = &ss s = s + "-map" ss.S = s ts.M[s] = map[string]string{s: s} ts.Msu[wrapString(s)] = map[string]string{s: s} } numChanSend := cap(ts.Chstr) / 4 // 8 for i := 0; i < numChanSend; i++ { ts.Chstr <- strings.Repeat("A", i+1) } ts.Ui64slicearray = []*[4]uint64{&ts.Ui64array, &ts.Ui64array} if useInterface { ts.AnonInTestStrucIntf = &AnonInTestStrucIntf{ Islice: []interface{}{strRpt(n, "true"), true, strRpt(n, "no"), false, uint64(288), float64(0.4)}, Ms: map[string]interface{}{ strRpt(n, "true"): strRpt(n, "true"), strRpt(n, "int64(9)"): false, }, T: testStrucTime, Tptr: &testStrucTime, } } populateTestStrucCommon(&ts.TestStrucCommon, n, bench, useInterface, useStringKeyOnly) if depth > 0 { depth-- if ts.Mtsptr == nil { ts.Mtsptr = make(map[string]*TestStrucFlex) } if ts.Mts == nil { ts.Mts = make(map[string]TestStrucFlex) } ts.Mtsptr["0"] = newTestStrucFlex(depth, n, bench, useInterface, useStringKeyOnly) ts.Mts["0"] = *(ts.Mtsptr["0"]) ts.Its = append(ts.Its, ts.Mtsptr["0"]) } return } go-1.2.8/codec/values_test.go000066400000000000000000000272471435255326100161130ustar00rootroot00000000000000// comment this out // + build testing // 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 // This file contains values used by tests and benchmarks. // The benchmarks will test performance against other libraries // (encoding/json, json-iterator, bson, gob, etc). // Consequently, we only use values that will parse well in all engines, // and only leverage features that work across multiple libraries for a truer comparison. // For example, // - JSON/BSON do not like maps with keys that are not strings, // so we only use maps with string keys here. // - _struct options are not honored by other libraries, // so we don't use them in this file. import ( "math" "strconv" "strings" ) // func init() { // rt := reflect.TypeOf((*TestStruc)(nil)).Elem() // defTypeInfos.get(rt2id(rt), rt) // } const numStrUi64T = 32 // use 8, prefer 32, test with 1024 type wrapSliceUint64 []uint64 type wrapSliceString []string type wrapUint64 uint64 type wrapString string type wrapUint64Slice []wrapUint64 type wrapStringSlice []wrapString // some other types type stringUint64T struct { S string U uint64 } type AnonInTestStrucSlim struct { S string P *string } type AnonInTestStruc struct { AS string AI64 int64 AI16 int16 AUi64 uint64 ASslice []string AI64slice []int64 AUi64slice []uint64 AF64slice []float64 AF32slice []float32 AMSS map[string]string // AMI32U32 map[int32]uint32 // AMU32F64 map[uint32]float64 // json/bson do not like it AMSU64 map[string]uint64 AI64arr8 [8]int64 // use these to test 0-len or nil slices/maps/arrays AI64arr0 [0]int64 AI64slice0 []int64 AUi64sliceN []uint64 AMSU64N map[string]uint64 AMSU64E map[string]uint64 } // testSimpleFields is a sub-set of TestStrucCommon type testSimpleFields struct { S string I64 int64 I8 int8 Ui64 uint64 Ui8 uint8 F64 float64 F32 float32 B bool Sslice []string I32slice []int32 Ui64slice []uint64 Ui8slice []uint8 Bslice []bool Iptrslice []*int64 WrapSliceInt64 wrapSliceUint64 WrapSliceString wrapSliceString Msint map[string]int } type TestStrucCommon struct { S string I64 int64 I32 int32 I16 int16 I8 int8 I64n int64 I32n int32 I16n int16 I8n int8 Ui64 uint64 Ui32 uint32 Ui16 uint16 Ui8 uint8 F64 float64 F32 float32 B bool By uint8 // byte: msgp doesn't like byte Sslice []string I64slice []int64 I32slice []int32 Ui64slice []uint64 Ui8slice []uint8 Bslice []bool Byslice []byte BytesSlice [][]byte Iptrslice []*int64 WrapSliceInt64 wrapSliceUint64 WrapSliceString wrapSliceString Msint map[string]int Msbytes map[string][]byte Simplef testSimpleFields SstrUi64T []stringUint64T MstrUi64T map[string]*stringUint64T AnonInTestStruc NotAnon AnonInTestStruc *AnonInTestStrucSlim NotAnonSlim *AnonInTestStrucSlim // R Raw // Testing Raw must be explicitly turned on, so use standalone test // Rext RawExt // Testing RawExt is tricky, so use standalone test Nmap map[string]bool //don't set this, so we can test for nil Nslice []byte //don't set this, so we can test for nil Nint64 *int64 //don't set this, so we can test for nil } type TestStruc struct { // _struct struct{} `json:",omitempty"` //set omitempty for every field TestStrucCommon Mtsptr map[string]*TestStruc Mts map[string]TestStruc Its []*TestStruc Nteststruc *TestStruc } func populateTestStrucCommon(ts *TestStrucCommon, n int, bench, useInterface, useStringKeyOnly bool) { var i64a, i64b, i64c, i64d int64 = 64, 6464, 646464, 64646464 // if bench, do not use uint64 values > math.MaxInt64, as bson, etc cannot decode them var a = AnonInTestStruc{ // There's more leeway in altering this. AS: strRpt(n, "A-String"), AI64: -64646464, AI16: 1616, AUi64: 64646464, // (U+1D11E)G-clef character may be represented in json as "\uD834\uDD1E". // single reverse solidus character may be represented in json as "\u005C". // include these in ASslice below. ASslice: []string{ strRpt(n, "Aone"), strRpt(n, "Atwo"), strRpt(n, "Athree"), strRpt(n, "Afour.reverse_solidus.\u005c"), strRpt(n, "Afive.Gclef.\U0001d11E\"ugorji\"done.")}, AI64slice: []int64{ 0, 1, -1, -22, 333, -4444, 55555, -666666, // msgpack ones -48, -32, -24, -8, 32, 127, 192, 255, // standard ones 0, -1, 1, math.MaxInt8, math.MaxInt8 + 4, math.MaxInt8 - 4, math.MaxInt16, math.MaxInt16 + 4, math.MaxInt16 - 4, math.MaxInt32, math.MaxInt32 + 4, math.MaxInt32 - 4, math.MaxInt64, math.MaxInt64 - 4, math.MinInt8, math.MinInt8 + 4, math.MinInt8 - 4, math.MinInt16, math.MinInt16 + 4, math.MinInt16 - 4, math.MinInt32, math.MinInt32 + 4, math.MinInt32 - 4, math.MinInt64, math.MinInt64 + 4, }, AUi64slice: []uint64{ 0, 1, 22, 333, 4444, 55555, 666666, // standard ones math.MaxUint8, math.MaxUint8 + 4, math.MaxUint8 - 4, math.MaxUint16, math.MaxUint16 + 4, math.MaxUint16 - 4, math.MaxUint32, math.MaxUint32 + 4, math.MaxUint32 - 4, }, AMSU64: map[string]uint64{ strRpt(n, "1"): 1, strRpt(n, "22"): 2, strRpt(n, "333"): 3, strRpt(n, "4444"): 4, }, AMSS: map[string]string{ strRpt(n, "1"): strRpt(n, "1"), strRpt(n, "22"): strRpt(n, "22"), strRpt(n, "333"): strRpt(n, "333"), strRpt(n, "4444"): strRpt(n, "4444"), }, AI64arr8: [...]int64{1, 8, 2, 7, 3, 6, 4, 5}, // Note: +/- inf, NaN, and other non-representable numbers should not be explicitly tested here AF64slice: []float64{ 11.11e-11, -11.11e+11, 2.222e+12, -2.222e-12, -555.55e-5, 555.55e+5, 666.66e-6, -666.66e+6, 7777.7777e-7, -7777.7777e-7, -8888.8888e+8, 8888.8888e+8, -99999.9999e+9, 99999.9999e+9, // these below are hairy enough to need strconv.ParseFloat 33.33e-33, -33.33e+33, 44.44e+44, -44.44e-44, // standard ones 0, -1, 1, // math.Inf(1), math.Inf(-1), math.Pi, math.Phi, math.E, math.MaxFloat64, math.SmallestNonzeroFloat64, }, AF32slice: []float32{ 11.11e-1, -11.11e+1, 2.222e+2, -2.222e-2, -55.55e-5, 55.55e+5, 66.66e-6, -66.66e+6, 777.777e-7, -777.777e-7, -8.88e+8, 8.88e-8, -99999.9999e+9, 99999.9999e+9, // these below are hairy enough to need strconv.ParseFloat 33.33e-33, -33.33e+33, // standard ones 0, -1, 1, // math.Float32frombits(0x7FF00000), math.Float32frombits(0xFFF00000), //+inf and -inf math.MaxFloat32, math.SmallestNonzeroFloat32, }, AI64slice0: []int64{}, AUi64sliceN: nil, AMSU64N: nil, AMSU64E: map[string]uint64{}, } if !bench { a.AUi64slice = append(a.AUi64slice, math.MaxUint64, math.MaxUint64-4) } *ts = TestStrucCommon{ S: strRpt(n, `some really really cool names that are nigerian and american like "ugorji melody nwoke" - get it? `), // set the numbers close to the limits I8: math.MaxInt8 * 2 / 3, // 8, I8n: math.MinInt8 * 2 / 3, // 8, I16: math.MaxInt16 * 2 / 3, // 16, I16n: math.MinInt16 * 2 / 3, // 16, I32: math.MaxInt32 * 2 / 3, // 32, I32n: math.MinInt32 * 2 / 3, // 32, I64: math.MaxInt64 * 2 / 3, // 64, I64n: math.MinInt64 * 2 / 3, // 64, Ui64: math.MaxUint64 * 2 / 3, // 64 Ui32: math.MaxUint32 * 2 / 3, // 32 Ui16: math.MaxUint16 * 2 / 3, // 16 Ui8: math.MaxUint8 * 2 / 3, // 8 F32: 3.402823e+38, // max representable float32 without losing precision F64: 3.40281991833838838338e+53, B: true, By: 5, Sslice: []string{strRpt(n, "one"), strRpt(n, "two"), strRpt(n, "three")}, I64slice: []int64{1111, 2222, 3333}, I32slice: []int32{44, 55, 66}, Ui64slice: []uint64{12121212, 34343434, 56565656}, Ui8slice: []uint8{210, 211, 212}, Bslice: []bool{true, false, true, false}, Byslice: []byte{13, 14, 15}, BytesSlice: [][]byte{ []byte(strRpt(n, "one")), []byte(strRpt(n, "two")), []byte(strRpt(n, "\"three\"")), }, Msint: map[string]int{ strRpt(n, "one"): 1, strRpt(n, "two"): 2, strRpt(n, "\"three\""): 3, }, Msbytes: map[string][]byte{ strRpt(n, "one"): []byte(strRpt(n, "one")), strRpt(n, "two"): []byte(strRpt(n, "two")), strRpt(n, "\"three\""): []byte(strRpt(n, "\"three\"")), }, WrapSliceInt64: []uint64{4, 16, 64, 256}, WrapSliceString: []string{strRpt(n, "4"), strRpt(n, "16"), strRpt(n, "64"), strRpt(n, "256")}, // R: Raw([]byte("goodbye")), // Rext: RawExt{ 120, []byte("hello"), }, // MARKER: don't set this - it's hard to test // make Simplef same as top-level // MARKER: should this have slightly different values??? Simplef: testSimpleFields{ S: strRpt(n, `some really really cool names that are nigerian and american like "ugorji melody nwoke" - get it? `), // set the numbers close to the limits I8: math.MaxInt8 * 2 / 3, // 8, I64: math.MaxInt64 * 2 / 3, // 64, Ui64: math.MaxUint64 * 2 / 3, // 64 Ui8: math.MaxUint8 * 2 / 3, // 8 F32: 3.402823e+38, // max representable float32 without losing precision F64: 3.40281991833838838338e+53, B: true, Sslice: []string{strRpt(n, "one"), strRpt(n, "two"), strRpt(n, "three")}, I32slice: []int32{44, 55, 66}, Ui64slice: []uint64{12121212, 34343434, 56565656}, Ui8slice: []uint8{210, 211, 212}, Bslice: []bool{true, false, true, false}, Msint: map[string]int{ strRpt(n, "one"): 1, strRpt(n, "two"): 2, strRpt(n, "\"three\""): 3, }, WrapSliceInt64: []uint64{4, 16, 64, 256}, WrapSliceString: []string{strRpt(n, "4"), strRpt(n, "16"), strRpt(n, "64"), strRpt(n, "256")}, }, SstrUi64T: make([]stringUint64T, numStrUi64T), // {{"1", 1}, {"2", 2}, {"3", 3}, {"4", 4}}, MstrUi64T: make(map[string]*stringUint64T, numStrUi64T), AnonInTestStruc: a, NotAnon: a, } for i := uint64(0); i < numStrUi64T; i++ { ss := strings.Repeat(strconv.FormatUint(i, 10), int(i)) // 4) ts.SstrUi64T[i] = stringUint64T{S: ss, U: i} ts.MstrUi64T[ss] = &ts.SstrUi64T[i] } if bench { ts.Ui64 = math.MaxInt64 * 2 / 3 ts.Simplef.Ui64 = ts.Ui64 } //For benchmarks, some things will not work. if !bench { //json and bson require string keys in maps //ts.M = map[interface{}]interface{}{ // true: "true", // int8(9): false, //} //gob cannot encode nil in element in array (encodeArray: nil element) ts.Iptrslice = []*int64{nil, &i64a, nil, &i64b, nil, &i64c, nil, &i64d, nil} // ts.Iptrslice = nil } if !useStringKeyOnly { var _ byte = 0 // so this empty branch doesn't flag a warning // ts.AnonInTestStruc.AMU32F64 = map[uint32]float64{1: 1, 2: 2, 3: 3} // Json/Bson barf } } func newTestStruc(depth, n int, bench, useInterface, useStringKeyOnly bool) (ts *TestStruc) { ts = &TestStruc{} populateTestStrucCommon(&ts.TestStrucCommon, n, bench, useInterface, useStringKeyOnly) if depth > 0 { depth-- if ts.Mtsptr == nil { ts.Mtsptr = make(map[string]*TestStruc) } if ts.Mts == nil { ts.Mts = make(map[string]TestStruc) } ts.Mtsptr[strRpt(n, "0")] = newTestStruc(depth, n, bench, useInterface, useStringKeyOnly) ts.Mts[strRpt(n, "0")] = *(ts.Mtsptr[strRpt(n, "0")]) ts.Its = append(ts.Its, ts.Mtsptr[strRpt(n, "0")]) } return } var testStrRptMap = make(map[int]map[string]string) func strRpt(n int, s string) string { if false { // fmt.Printf(">>>> calling strings.Repeat on n: %d, key: %s\n", n, s) return strings.Repeat(s, n) } m1, ok := testStrRptMap[n] if !ok { // fmt.Printf(">>>> making new map for n: %v\n", n) m1 = make(map[string]string) testStrRptMap[n] = m1 } v1, ok := m1[s] if !ok { // fmt.Printf(">>>> creating new entry for key: %s\n", s) v1 = strings.Repeat(s, n) m1[s] = v1 } return v1 } // func wstrRpt(n int, s string) wrapBytes { // return wrapBytes(bytes.Repeat([]byte(s), n)) // } go-1.2.8/codec/writer.go000066400000000000000000000127251435255326100150640ustar00rootroot00000000000000// 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" // encWriter abstracts writing to a byte array or to an io.Writer. type encWriter 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) end() } // --------------------------------------------- type bufioEncWriter struct { w io.Writer buf []byte n int b [16]byte // scratch buffer and padding (cache-aligned) } func (z *bufioEncWriter) reset(w io.Writer, bufsize int, blist *bytesFreelist) { z.w = w z.n = 0 if bufsize <= 0 { bufsize = defEncByteBufSize } // bufsize must be >= 8, to accomodate writen methods (where n <= 8) if bufsize <= 8 { bufsize = 8 } 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) { n, err := z.w.Write(z.buf[:z.n]) z.n -= n if z.n > 0 { if err == nil { err = io.ErrShortWrite } if n > 0 { copy(z.buf, z.buf[n:z.n+n]) } } return err } 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() } 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) z.buf[z.n] = '"' z.n++ } func (z *bufioEncWriter) writen1(b1 byte) { if 1 > len(z.buf)-z.n { z.flush() } z.buf[z.n] = b1 z.n++ } func (z *bufioEncWriter) writen2(b1, b2 byte) { if 2 > len(z.buf)-z.n { z.flush() } 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() } 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 } // --------------------------------------------- // 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, b[0], b[1], b[2], b[3]) // 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]) // prevents inlining encWr.writen4 } func (z *bytesEncAppender) endErr() error { *(z.out) = z.b return nil } func (z *bytesEncAppender) reset(in []byte, out *[]byte) { z.b = in[:0] z.out = out } // -------------------------------------------------- type encWr struct { bytes bool // encoding to []byte js bool // is json encoder? be bool // is binary encoder? c containerState calls uint16 seq uint16 // sequencer (e.g. used by binc for symbols, etc) wb bytesEncAppender wf *bufioEncWriter } // MARKER: manually inline bytesEncAppender.writenx/writeqstr methods, // as calling them causes encWr.writenx/writeqstr methods to not be inlined (cost > 80). // // i.e. e.g. instead of writing z.wb.writen2(b1, b2), use z.wb.b = append(z.wb.b, b1, b2) func (z *encWr) writeb(s []byte) { if z.bytes { z.wb.writeb(s) } else { z.wf.writeb(s) } } func (z *encWr) writeqstr(s string) { if z.bytes { // MARKER: z.wb.writeqstr(s) z.wb.b = append(append(append(z.wb.b, '"'), s...), '"') } else { z.wf.writeqstr(s) } } func (z *encWr) writestr(s string) { if z.bytes { z.wb.writestr(s) } else { z.wf.writestr(s) } } func (z *encWr) writen1(b1 byte) { if z.bytes { z.wb.writen1(b1) } else { z.wf.writen1(b1) } } func (z *encWr) writen2(b1, b2 byte) { if z.bytes { // MARKER: z.wb.writen2(b1, b2) z.wb.b = append(z.wb.b, b1, b2) } else { z.wf.writen2(b1, b2) } } func (z *encWr) writen4(b [4]byte) { if z.bytes { z.wb.writen4(b) } else { z.wf.writen4(b) } } func (z *encWr) writen8(b [8]byte) { if z.bytes { z.wb.writen8(b) } else { z.wf.writen8(b) } } func (z *encWr) endErr() error { if z.bytes { return z.wb.endErr() } return z.wf.endErr() } func (z *encWr) end() { halt.onerror(z.endErr()) } var _ encWriter = (*encWr)(nil) go-1.2.8/codec/xml.go000066400000000000000000000433401435255326100143450ustar00rootroot00000000000000// 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 ignore // +build ignore package codec /* A strict Non-validating namespace-aware XML 1.0 parser and (en|de)coder. We are attempting this due to perceived issues with encoding/xml: - Complicated. It tried to do too much, and is not as simple to use as json. - Due to over-engineering, reflection is over-used AND performance suffers: java is 6X faster:http://fabsk.eu/blog/category/informatique/dev/golang/ even PYTHON performs better: http://outgoing.typepad.com/outgoing/2014/07/exploring-golang.html codec framework will offer the following benefits - VASTLY improved performance (when using reflection-mode or codecgen) - simplicity and consistency: with the rest of the supported formats - all other benefits of codec framework (streaming, codegeneration, etc) codec is not a drop-in replacement for encoding/xml. It is a replacement, based on the simplicity and performance of codec. Look at it like JAXB for Go. Challenges: - Need to output XML preamble, with all namespaces at the right location in the output. - Each "end" block is dynamic, so we need to maintain a context-aware stack - How to decide when to use an attribute VS an element - How to handle chardata, attr, comment EXPLICITLY. - Should it output fragments? e.g. encoding a bool should just output true OR false, which is not well-formed XML. Extend the struct tag. See representative example: type X struct { ID uint8 `codec:"http://ugorji.net/x-namespace xid id,omitempty,toarray,attr,cdata"` // format: [namespace-uri ][namespace-prefix ]local-name, ... } Based on this, we encode - fields as elements, BUT encode as attributes if struct tag contains ",attr" and is a scalar (bool, number or string) - text as entity-escaped text, BUT encode as CDATA if struct tag contains ",cdata". To handle namespaces: - XMLHandle is denoted as being namespace-aware. Consequently, we WILL use the ns:name pair to encode and decode if defined, else use the plain name. - *Encoder and *Decoder know whether the Handle "prefers" namespaces. - add *Encoder.getEncName(*structFieldInfo). No one calls *structFieldInfo.indexForEncName directly anymore - OR better yet: indexForEncName is namespace-aware, and helper.go is all namespace-aware indexForEncName takes a parameter of the form namespace:local-name OR local-name - add *Decoder.getStructFieldInfo(encName string) // encName here is either like abc, or h1:nsabc by being a method on *Decoder, or maybe a method on the Handle itself. No one accesses .encName anymore - let encode.go and decode.go use these (for consistency) - only problem exists for gen.go, where we create a big switch on encName. Now, we also have to add a switch on strings.endsWith(kName, encNsName) - gen.go will need to have many more methods, and then double-on the 2 switch loops like: switch k { case "abc" : x.abc() case "def" : x.def() default { switch { case !nsAware: panic(...) case strings.endsWith(":abc"): x.abc() case strings.endsWith(":def"): x.def() default: panic(...) } } } The structure below accommodates this: type typeInfo struct { sfi []*structFieldInfo // sorted by encName sfins // sorted by namespace sfia // sorted, to have those with attributes at the top. Needed to write XML appropriately. sfip // unsorted } type structFieldInfo struct { encName nsEncName ns string attr bool cdata bool } indexForEncName is now an internal helper function that takes a sorted array (one of ti.sfins or ti.sfi). It is only used by *Encoder.getStructFieldInfo(...) There will be a separate parser from the builder. The parser will have a method: next() xmlToken method. It has lookahead support, so you can pop multiple tokens, make a determination, and push them back in the order popped. This will be needed to determine whether we are "nakedly" decoding a container or not. The stack will be implemented using a slice and push/pop happens at the [0] element. xmlToken has fields: - type uint8: 0 | ElementStart | ElementEnd | AttrKey | AttrVal | Text - value string - ns string SEE: http://www.xml.com/pub/a/98/10/guide0.html?page=3#ENTDECL The following are skipped when parsing: - External Entities (from external file) - Notation Declaration e.g. - Entity Declarations & References - XML Declaration (assume UTF-8) - XML Directive i.e. - Other Declarations: Notation, etc. - Comment - Processing Instruction - schema / DTD for validation: We are not a VALIDATING parser. Validation is done elsewhere. However, some parts of the DTD internal subset are used (SEE BELOW). For Attribute List Declarations e.g. We considered using the ATTLIST to get "default" value, but not to validate the contents. (VETOED) The following XML features are supported - Namespace - Element - Attribute - cdata - Unicode escape The following DTD (when as an internal sub-set) features are supported: - Internal Entities e.g. AND entities for the set: [<>&"'] - Parameter entities e.g. At decode time, a structure containing the following is kept - namespace mapping - default attribute values - all internal entities (<>&"' and others written in the document) When decode starts, it parses XML namespace declarations and creates a map in the xmlDecDriver. While parsing, that map continuously gets updated. The only problem happens when a namespace declaration happens on the node that it defines. e.g. To handle this, each Element must be fully parsed at a time, even if it amounts to multiple tokens which are returned one at a time on request. xmlns is a special attribute name. - It is used to define namespaces, including the default - It is never returned as an AttrKey or AttrVal. *We may decide later to allow user to use it e.g. you want to parse the xmlns mappings into a field.* Number, bool, null, mapKey, etc can all be decoded from any xmlToken. This accommodates map[int]string for example. It should be possible to create a schema from the types, or vice versa (generate types from schema with appropriate tags). This is however out-of-scope from this parsing project. We should write all namespace information at the first point that it is referenced in the tree, and use the mapping for all child nodes and attributes. This means that state is maintained at a point in the tree. This also means that calls to Decode or MustDecode will reset some state. When decoding, it is important to keep track of entity references and default attribute values. It seems these can only be stored in the DTD components. We should honor them when decoding. Configuration for XMLHandle will look like this: XMLHandle DefaultNS string // Encoding: NS map[string]string // ns URI to key, used for encoding // Decoding: in case ENTITY declared in external schema or dtd, store info needed here Entities map[string]string // map of entity rep to character During encode, if a namespace mapping is not defined for a namespace found on a struct, then we create a mapping for it using nsN (where N is 1..1000000, and doesn't conflict with any other namespace mapping). Note that different fields in a struct can have different namespaces. However, all fields will default to the namespace on the _struct field (if defined). An XML document is a name, a map of attributes and a list of children. Consequently, we cannot "DecodeNaked" into a map[string]interface{} (for example). We have to "DecodeNaked" into something that resembles XML data. To support DecodeNaked (decode into nil interface{}), we have to define some "supporting" types: type Name struct { // Preferred. Less allocations due to conversions. Local string Space string } type Element struct { Name Name Attrs map[Name]string Children []interface{} // each child is either *Element or string } Only two "supporting" types are exposed for XML: Name and Element. // ------------------ We considered 'type Name string' where Name is like "Space Local" (space-separated). We decided against it, because each creation of a name would lead to double allocation (first convert []byte to string, then concatenate them into a string). The benefit is that it is faster to read Attrs from a map. But given that Element is a value object, we want to eschew methods and have public exposed variables. We also considered the following, where xml types were not value objects, and we used intelligent accessor methods to extract information and for performance. *** WE DECIDED AGAINST THIS. *** type Attr struct { Name Name Value string } // Element is a ValueObject: There are no accessor methods. // Make element self-contained. type Element struct { Name Name attrsMap map[string]string // where key is "Space Local" attrs []Attr childrenT []string childrenE []Element childrenI []int // each child is a index into T or E. } func (x *Element) child(i) interface{} // returns string or *Element // ------------------ Per XML spec and our default handling, white space is always treated as insignificant between elements, except in a text node. The xml:space='preserve' attribute is ignored. **Note: there is no xml: namespace. The xml: attributes were defined before namespaces.** **So treat them as just "directives" that should be interpreted to mean something**. On encoding, we support indenting aka prettifying markup in the same way we support it for json. A document or element can only be encoded/decoded from/to a struct. In this mode: - struct name maps to element name (or tag-info from _struct field) - fields are mapped to child elements or attributes A map is either encoded as attributes on current element, or as a set of child elements. Maps are encoded as attributes iff their keys and values are primitives (number, bool, string). A list is encoded as a set of child elements. Primitives (number, bool, string) are encoded as an element, attribute or text depending on the context. Extensions must encode themselves as a text string. Encoding is tough, specifically when encoding mappings, because we need to encode as either attribute or element. To do this, we need to default to encoding as attributes, and then let Encoder inform the Handle when to start encoding as nodes. i.e. Encoder does something like: h.EncodeMapStart() h.Encode(), h.Encode(), ... h.EncodeMapNotAttrSignal() // this is not a bool, because it's a signal h.Encode(), h.Encode(), ... h.EncodeEnd() Only XMLHandle understands this, and will set itself to start encoding as elements. This support extends to maps. For example, if a struct field is a map, and it has the struct tag signifying it should be attr, then all its fields are encoded as attributes. e.g. type X struct { M map[string]int `codec:"m,attr"` // encode keys as attributes named } Question: - if encoding a map, what if map keys have spaces in them??? Then they cannot be attributes or child elements. Error. Options to consider adding later: - For attribute values, normalize by trimming beginning and ending white space, and converting every white space sequence to a single space. - ATTLIST restrictions are enforced. e.g. default value of xml:space, skipping xml:XYZ style attributes, etc. - Consider supporting NON-STRICT mode (e.g. to handle HTML parsing). Some elements e.g. br, hr, etc need not close and should be auto-closed ... (see http://www.w3.org/TR/html4/loose.dtd) An expansive set of entities are pre-defined. - Have easy way to create a HTML parser: add a HTML() method to XMLHandle, that will set Strict=false, specify AutoClose, and add HTML Entities to the list. - Support validating element/attribute XMLName before writing it. Keep this behind a flag, which is set to false by default (for performance). type XMLHandle struct { CheckName bool } Misc: ROADMAP (1 weeks): - build encoder (1 day) - build decoder (based off xmlParser) (1 day) - implement xmlParser (2 days). Look at encoding/xml for inspiration. - integrate and TEST (1 days) - write article and post it (1 day) // ---------- MORE NOTES FROM 2017-11-30 ------------ when parsing - parse the attributes first - then parse the nodes basically: - if encoding a field: we use the field name for the wrapper - if encoding a non-field, then just use the element type name map[string]string ==> abcval... or val... OR val1val2... <- PREFERED []string ==> v1v2... string v1 ==> v1 bool true ==> true float 1.0 ==> 1.0 ... F1 map[string]string ==> abcval... OR val... OR val... <- PREFERED F2 []string ==> v1v2... F3 bool ==> true ... - a scalar is encoded as: (value) of type T ==> (value) of field F ==> - A kv-pair is encoded as: (key,value) ==> OR (key,value) of field F ==> OR - A map or struct is just a list of kv-pairs - A list is encoded as sequences of same node e.g. value21 value22 - we may have to singularize the field name, when entering into xml, and pluralize them when encoding. - bi-directional encode->decode->encode is not a MUST. even encoding/xml cannot decode correctly what was encoded: see https://play.golang.org/p/224V_nyhMS func main() { fmt.Println("Hello, playground") v := []interface{}{"hello", 1, true, nil, time.Now()} s, err := xml.Marshal(v) fmt.Printf("err: %v, \ns: %s\n", err, s) var v2 []interface{} err = xml.Unmarshal(s, &v2) fmt.Printf("err: %v, \nv2: %v\n", err, v2) type T struct { V []interface{} } v3 := T{V: v} s, err = xml.Marshal(v3) fmt.Printf("err: %v, \ns: %s\n", err, s) var v4 T err = xml.Unmarshal(s, &v4) fmt.Printf("err: %v, \nv4: %v\n", err, v4) } Output: err: , s: hello1true err: , v2: [] err: , s: hello1true2009-11-10T23:00:00Z err: , v4: {[ ]} - */ // ----------- PARSER ------------------- type xmlTokenType uint8 const ( _ xmlTokenType = iota << 1 xmlTokenElemStart xmlTokenElemEnd xmlTokenAttrKey xmlTokenAttrVal xmlTokenText ) type xmlToken struct { Type xmlTokenType Value string Namespace string // blank for AttrVal and Text } type xmlParser struct { r decReader toks []xmlToken // list of tokens. ptr int // ptr into the toks slice done bool // nothing else to parse. r now returns EOF. } func (x *xmlParser) next() (t *xmlToken) { // once x.done, or x.ptr == len(x.toks) == 0, then return nil (to signify finish) if !x.done && len(x.toks) == 0 { x.nextTag() } // parses one element at a time (into possible many tokens) if x.ptr < len(x.toks) { t = &(x.toks[x.ptr]) x.ptr++ if x.ptr == len(x.toks) { x.ptr = 0 x.toks = x.toks[:0] } } return } // nextTag will parses the next element and fill up toks. // It set done flag if/once EOF is reached. func (x *xmlParser) nextTag() { // ... } // ----------- ENCODER ------------------- type xmlEncDriver struct { e *Encoder w encWriter h *XMLHandle b [64]byte // scratch bs []byte // scratch // s jsonStack noBuiltInTypes } // ----------- DECODER ------------------- type xmlDecDriver struct { d *Decoder h *XMLHandle r decReader // *bytesDecReader decReader ct valueType // container type. one of unset, array or map. bstr [8]byte // scratch used for string \UXXX parsing b [64]byte // scratch // wsSkipped bool // whitespace skipped // s jsonStack noBuiltInTypes } // DecodeNaked will decode into an XMLNode // XMLName is a value object representing a namespace-aware NAME type XMLName struct { Local string Space string } // XMLNode represents a "union" of the different types of XML Nodes. // Only one of fields (Text or *Element) is set. type XMLNode struct { Element *Element Text string } // XMLElement is a value object representing an fully-parsed XML element. type XMLElement struct { Name Name Attrs map[XMLName]string // Children is a list of child nodes, each being a *XMLElement or string Children []XMLNode } // ----------- HANDLE ------------------- type XMLHandle struct { BasicHandle textEncodingType DefaultNS string NS map[string]string // ns URI to key, for encoding Entities map[string]string // entity representation to string, for encoding. } func (h *XMLHandle) newEncDriver(e *Encoder) encDriver { return &xmlEncDriver{e: e, w: e.w, h: h} } func (h *XMLHandle) newDecDriver(d *Decoder) decDriver { // d := xmlDecDriver{r: r.(*bytesDecReader), h: h} hd := xmlDecDriver{d: d, r: d.r, h: h} hd.n.bytes = d.b[:] return &hd } var _ decDriver = (*xmlDecDriver)(nil) var _ encDriver = (*xmlEncDriver)(nil) go-1.2.8/codec/z_all_test.go000066400000000000000000000453731435255326100157150ustar00rootroot00000000000000// 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 alltests && go1.9 // +build alltests,go1.9 package codec // Run this using: // go test -tags=alltests -run=Suite -coverprofile=cov.out // go tool cover -html=cov.out // // Because build tags are a build time parameter, we will have to test out the // different tags separately. // Tags: x codecgen codec.safe codec.notfastpath appengine // // These tags should be added to alltests, e.g. // go test '-tags=alltests x codecgen' -run=Suite -coverprofile=cov.out // // To run all tests before submitting code, run: // a=( "" "codec.safe" "codecgen" "codec.notfastpath" "codecgen codec.notfastpath" "codecgen codec.safe" "codec.safe codec.notfastpath" ) // for i in "${a[@]}"; do echo ">>>> TAGS: $i"; go test "-tags=alltests $i" -run=Suite; done // // This suite of tests requires support for subtests and suites, // and conseqneutly will only run on go1.7 and above. // find . -name "codec_test.go" | xargs grep -e '^func Test' | \ // cut -d '(' -f 1 | cut -d ' ' -f 2 | \ // while read f; do echo "t.Run(\"$f\", $f)"; done import ( "testing" "time" ) // func TestMain(m *testing.M) { // println("calling TestMain") // // set some parameters // exitcode := m.Run() // os.Exit(exitcode) // } type testTimeTracker struct { t time.Time } func (tt *testTimeTracker) Elapsed() (d time.Duration) { if !tt.t.IsZero() { d = time.Since(tt.t) } tt.t = time.Now() return } func testGroupResetFlags() { testRpcBufsize = 2048 testUseIoEncDec = -1 testUseReset = false testUseParallel = false testMaxInitLen = 0 testUseIoWrapper = false testNumRepeatString = 8 testDepth = 0 testDecodeOptions = DecodeOptions{} testEncodeOptions = EncodeOptions{} testJsonH.Indent = 0 // -1? testJsonH.HTMLCharsAsIs = false testJsonH.MapKeyAsString = false testJsonH.PreferFloat = false testCborH.IndefiniteLength = false testCborH.TimeRFC3339 = false testCborH.SkipUnexpectedTags = false testBincH.AsSymbols = 0 // 2? AsSymbolNone testMsgpackH.WriteExt = false testMsgpackH.NoFixedNum = false testMsgpackH.PositiveIntUnsigned = false testSimpleH.EncZeroValuesAsNil = false } func testCodecGroup(t *testing.T) { // testJsonGroup(t) testBincGroup(t) testCborGroup(t) testMsgpackGroup(t) testSimpleGroup(t) // testSimpleMammothGroup(t) // testRpcGroup(t) testNonHandlesGroup(t) testCodecGroupV(t) // } func testCodecGroupV(t *testing.T) { testJsonGroupV(t) testBincGroupV(t) testCborGroupV(t) testMsgpackGroupV(t) testSimpleGroupV(t) } func testJsonGroup(t *testing.T) { t.Run("TestJsonCodecsEmbeddedPointer", TestJsonCodecsEmbeddedPointer) t.Run("TestJsonCodecChan", TestJsonCodecChan) t.Run("TestJsonStdEncIntf", TestJsonStdEncIntf) t.Run("TestJsonMammoth", TestJsonMammoth) t.Run("TestJsonRaw", TestJsonRaw) t.Run("TestJsonRpcGo", TestJsonRpcGo) t.Run("TestJsonLargeInteger", TestJsonLargeInteger) t.Run("TestJsonDecodeNonStringScalarInStringContext", TestJsonDecodeNonStringScalarInStringContext) t.Run("TestJsonEncodeIndent", TestJsonEncodeIndent) t.Run("TestJsonRawExt", TestJsonRawExt) t.Run("TestJsonMapStructKey", TestJsonMapStructKey) t.Run("TestJsonDecodeNilMapValue", TestJsonDecodeNilMapValue) t.Run("TestJsonEmbeddedFieldPrecedence", TestJsonEmbeddedFieldPrecedence) t.Run("TestJsonLargeContainerLen", TestJsonLargeContainerLen) t.Run("TestJsonMammothMapsAndSlices", TestJsonMammothMapsAndSlices) t.Run("TestJsonTime", TestJsonTime) t.Run("TestJsonUintToInt", TestJsonUintToInt) t.Run("TestJsonDifferentMapOrSliceType", TestJsonDifferentMapOrSliceType) t.Run("TestJsonScalars", TestJsonScalars) t.Run("TestJsonOmitempty", TestJsonOmitempty) t.Run("TestJsonIntfMapping", TestJsonIntfMapping) t.Run("TestJsonMissingFields", TestJsonMissingFields) t.Run("TestJsonMaxDepth", TestJsonMaxDepth) t.Run("TestJsonSelfExt", TestJsonSelfExt) t.Run("TestJsonBytesEncodedAsArray", TestJsonBytesEncodedAsArray) t.Run("TestJsonMapEncodeForCanonical", TestJsonMapEncodeForCanonical) t.Run("TestJsonRawToStringToRawEtc", TestJsonRawToStringToRawEtc) t.Run("TestJsonStructKeyType", TestJsonStructKeyType) t.Run("TestJsonPreferArrayOverSlice", TestJsonPreferArrayOverSlice) t.Run("TestJsonZeroCopyBytes", TestJsonZeroCopyBytes) t.Run("TestJsonNumbers", TestJsonNumbers) t.Run("TestJsonDesc", TestJsonDesc) t.Run("TestJsonStructFieldInfoToArray", TestJsonStructFieldInfoToArray) t.Run("TestJsonInvalidUnicode", TestJsonInvalidUnicode) t.Run("TestJsonNumberParsing", TestJsonNumberParsing) } func testJsonGroupV(t *testing.T) { t.Run("TestJsonCodecsTable", TestJsonCodecsTable) t.Run("TestJsonCodecsMisc", TestJsonCodecsMisc) t.Run("TestJsonSwallowAndZero", TestJsonSwallowAndZero) t.Run("TestJsonNextValueBytes", TestJsonNextValueBytes) t.Run("TestJsonStrucEncDec", TestJsonStrucEncDec) } func testBincGroup(t *testing.T) { t.Run("TestBincCodecsEmbeddedPointer", TestBincCodecsEmbeddedPointer) t.Run("TestBincStdEncIntf", TestBincStdEncIntf) t.Run("TestBincMammoth", TestBincMammoth) t.Run("TestBincRaw", TestBincRaw) t.Run("TestBincRpcGo", TestBincRpcGo) t.Run("TestBincUnderlyingType", TestBincUnderlyingType) t.Run("TestBincRawExt", TestBincRawExt) t.Run("TestBincMapStructKey", TestBincMapStructKey) t.Run("TestBincDecodeNilMapValue", TestBincDecodeNilMapValue) t.Run("TestBincEmbeddedFieldPrecedence", TestBincEmbeddedFieldPrecedence) t.Run("TestBincLargeContainerLen", TestBincLargeContainerLen) t.Run("TestBincMammothMapsAndSlices", TestBincMammothMapsAndSlices) t.Run("TestBincTime", TestBincTime) t.Run("TestBincUintToInt", TestBincUintToInt) t.Run("TestBincDifferentMapOrSliceType", TestBincDifferentMapOrSliceType) t.Run("TestBincScalars", TestBincScalars) t.Run("TestBincOmitempty", TestBincOmitempty) t.Run("TestBincIntfMapping", TestBincIntfMapping) t.Run("TestBincMissingFields", TestBincMissingFields) t.Run("TestBincMaxDepth", TestBincMaxDepth) t.Run("TestBincSelfExt", TestBincSelfExt) t.Run("TestBincBytesEncodedAsArray", TestBincBytesEncodedAsArray) t.Run("TestBincMapEncodeForCanonical", TestBincMapEncodeForCanonical) t.Run("TestBincRawToStringToRawEtc", TestBincRawToStringToRawEtc) t.Run("TestBincStructKeyType", TestBincStructKeyType) t.Run("TestBincPreferArrayOverSlice", TestBincPreferArrayOverSlice) t.Run("TestBincZeroCopyBytes", TestBincZeroCopyBytes) t.Run("TestBincNumbers", TestBincNumbers) t.Run("TestBincDesc", TestBincDesc) t.Run("TestBincStructFieldInfoToArray", TestBincStructFieldInfoToArray) } func testBincGroupV(t *testing.T) { t.Run("TestBincCodecsTable", TestBincCodecsTable) t.Run("TestBincCodecsMisc", TestBincCodecsMisc) t.Run("TestBincSwallowAndZero", TestBincSwallowAndZero) t.Run("TestBincNextValueBytes", TestBincNextValueBytes) t.Run("TestBincStrucEncDec", TestBincStrucEncDec) } func testCborGroup(t *testing.T) { t.Run("TestCborCodecsEmbeddedPointer", TestCborCodecsEmbeddedPointer) t.Run("TestCborCodecChan", TestCborCodecChan) t.Run("TestCborStdEncIntf", TestCborStdEncIntf) t.Run("TestCborMammoth", TestCborMammoth) t.Run("TestCborRaw", TestCborRaw) t.Run("TestCborRpcGo", TestCborRpcGo) t.Run("TestCborRawExt", TestCborRawExt) t.Run("TestCborMapStructKey", TestCborMapStructKey) t.Run("TestCborDecodeNilMapValue", TestCborDecodeNilMapValue) t.Run("TestCborEmbeddedFieldPrecedence", TestCborEmbeddedFieldPrecedence) t.Run("TestCborLargeContainerLen", TestCborLargeContainerLen) t.Run("TestCborMammothMapsAndSlices", TestCborMammothMapsAndSlices) t.Run("TestCborTime", TestCborTime) t.Run("TestCborUintToInt", TestCborUintToInt) t.Run("TestCborDifferentMapOrSliceType", TestCborDifferentMapOrSliceType) t.Run("TestCborScalars", TestCborScalars) t.Run("TestCborOmitempty", TestCborOmitempty) t.Run("TestCborIntfMapping", TestCborIntfMapping) t.Run("TestCborMissingFields", TestCborMissingFields) t.Run("TestCborMaxDepth", TestCborMaxDepth) t.Run("TestCborSelfExt", TestCborSelfExt) t.Run("TestCborBytesEncodedAsArray", TestCborBytesEncodedAsArray) t.Run("TestCborMapEncodeForCanonical", TestCborMapEncodeForCanonical) t.Run("TestCborRawToStringToRawEtc", TestCborRawToStringToRawEtc) t.Run("TestCborStructKeyType", TestCborStructKeyType) t.Run("TestCborPreferArrayOverSlice", TestCborPreferArrayOverSlice) t.Run("TestCborZeroCopyBytes", TestCborZeroCopyBytes) t.Run("TestCborNumbers", TestCborNumbers) t.Run("TestCborDesc", TestCborDesc) t.Run("TestCborStructFieldInfoToArray", TestCborStructFieldInfoToArray) t.Run("TestCborHalfFloat", TestCborHalfFloat) t.Run("TestCborSkipTags", TestCborSkipTags) } func testCborGroupV(t *testing.T) { t.Run("TestCborCodecsTable", TestCborCodecsTable) t.Run("TestCborCodecsMisc", TestCborCodecsMisc) t.Run("TestCborSwallowAndZero", TestCborSwallowAndZero) t.Run("TestCborNextValueBytes", TestCborNextValueBytes) t.Run("TestCborStrucEncDec", TestCborStrucEncDec) } func testMsgpackGroup(t *testing.T) { t.Run("TestMsgpackCodecsEmbeddedPointer", TestMsgpackCodecsEmbeddedPointer) t.Run("TestMsgpackStdEncIntf", TestMsgpackStdEncIntf) t.Run("TestMsgpackMammoth", TestMsgpackMammoth) t.Run("TestMsgpackRaw", TestMsgpackRaw) t.Run("TestMsgpackRpcGo", TestMsgpackRpcGo) t.Run("TestMsgpackRpcSpec", TestMsgpackRpcSpec) t.Run("TestMsgpackRawExt", TestMsgpackRawExt) t.Run("TestMsgpackMapStructKey", TestMsgpackMapStructKey) t.Run("TestMsgpackDecodeNilMapValue", TestMsgpackDecodeNilMapValue) t.Run("TestMsgpackEmbeddedFieldPrecedence", TestMsgpackEmbeddedFieldPrecedence) t.Run("TestMsgpackLargeContainerLen", TestMsgpackLargeContainerLen) t.Run("TestMsgpackMammothMapsAndSlices", TestMsgpackMammothMapsAndSlices) t.Run("TestMsgpackTime", TestMsgpackTime) t.Run("TestMsgpackUintToInt", TestMsgpackUintToInt) t.Run("TestMsgpackDifferentMapOrSliceType", TestMsgpackDifferentMapOrSliceType) t.Run("TestMsgpackScalars", TestMsgpackScalars) t.Run("TestMsgpackOmitempty", TestMsgpackOmitempty) t.Run("TestMsgpackIntfMapping", TestMsgpackIntfMapping) t.Run("TestMsgpackMissingFields", TestMsgpackMissingFields) t.Run("TestMsgpackMaxDepth", TestMsgpackMaxDepth) t.Run("TestMsgpackSelfExt", TestMsgpackSelfExt) t.Run("TestMsgpackBytesEncodedAsArray", TestMsgpackBytesEncodedAsArray) t.Run("TestMsgpackMapEncodeForCanonical", TestMsgpackMapEncodeForCanonical) t.Run("TestMsgpackRawToStringToRawEtc", TestMsgpackRawToStringToRawEtc) t.Run("TestMsgpackStructKeyType", TestMsgpackStructKeyType) t.Run("TestMsgpackPreferArrayOverSlice", TestMsgpackPreferArrayOverSlice) t.Run("TestMsgpackZeroCopyBytes", TestMsgpackZeroCopyBytes) t.Run("TestMsgpackNumbers", TestMsgpackNumbers) t.Run("TestMsgpackDesc", TestMsgpackDesc) t.Run("TestMsgpackStructFieldInfoToArray", TestMsgpackStructFieldInfoToArray) t.Run("TestMsgpackDecodeMapAndExtSizeMismatch", TestMsgpackDecodeMapAndExtSizeMismatch) } func testMsgpackGroupV(t *testing.T) { t.Run("TestMsgpackCodecsTable", TestMsgpackCodecsTable) t.Run("TestMsgpackCodecsMisc", TestMsgpackCodecsMisc) t.Run("TestMsgpackSwallowAndZero", TestMsgpackSwallowAndZero) t.Run("TestMsgpackNextValueBytes", TestMsgpackNextValueBytes) t.Run("TestMsgpackStrucEncDec", TestMsgpackStrucEncDec) } func testSimpleGroup(t *testing.T) { t.Run("TestSimpleCodecsEmbeddedPointer", TestSimpleCodecsEmbeddedPointer) t.Run("TestSimpleStdEncIntf", TestSimpleStdEncIntf) t.Run("TestSimpleMammoth", TestSimpleMammoth) t.Run("TestSimpleRaw", TestSimpleRaw) t.Run("TestSimpleRpcGo", TestSimpleRpcGo) t.Run("TestSimpleRawExt", TestSimpleRawExt) t.Run("TestSimpleMapStructKey", TestSimpleMapStructKey) t.Run("TestSimpleDecodeNilMapValue", TestSimpleDecodeNilMapValue) t.Run("TestSimpleEmbeddedFieldPrecedence", TestSimpleEmbeddedFieldPrecedence) t.Run("TestSimpleLargeContainerLen", TestSimpleLargeContainerLen) t.Run("TestSimpleMammothMapsAndSlices", TestSimpleMammothMapsAndSlices) t.Run("TestSimpleTime", TestSimpleTime) t.Run("TestSimpleUintToInt", TestSimpleUintToInt) t.Run("TestSimpleDifferentMapOrSliceType", TestSimpleDifferentMapOrSliceType) t.Run("TestSimpleScalars", TestSimpleScalars) t.Run("TestSimpleOmitempty", TestSimpleOmitempty) t.Run("TestSimpleIntfMapping", TestSimpleIntfMapping) t.Run("TestSimpleMissingFields", TestSimpleMissingFields) t.Run("TestSimpleMaxDepth", TestSimpleMaxDepth) t.Run("TestSimpleSelfExt", TestSimpleSelfExt) t.Run("TestSimpleBytesEncodedAsArray", TestSimpleBytesEncodedAsArray) t.Run("TestSimpleMapEncodeForCanonical", TestSimpleMapEncodeForCanonical) t.Run("TestSimpleRawToStringToRawEtc", TestSimpleRawToStringToRawEtc) t.Run("TestSimpleStructKeyType", TestSimpleStructKeyType) t.Run("TestSimplePreferArrayOverSlice", TestSimplePreferArrayOverSlice) t.Run("TestSimpleZeroCopyBytes", TestSimpleZeroCopyBytes) t.Run("TestSimpleNumbers", TestSimpleNumbers) t.Run("TestSimpleDesc", TestSimpleDesc) t.Run("TestSimpleStructFieldInfoToArray", TestSimpleStructFieldInfoToArray) } func testSimpleGroupV(t *testing.T) { t.Run("TestSimpleCodecsTable", TestSimpleCodecsTable) t.Run("TestSimpleCodecsMisc", TestSimpleCodecsMisc) t.Run("TestSimpleSwallowAndZero", TestSimpleSwallowAndZero) t.Run("TestSimpleNextValueBytes", TestSimpleNextValueBytes) t.Run("TestSimpleStrucEncDec", TestSimpleStrucEncDec) } func testSimpleMammothGroup(t *testing.T) { t.Run("TestSimpleMammothMapsAndSlices", TestSimpleMammothMapsAndSlices) } func testRpcGroup(t *testing.T) { t.Run("TestBincRpcGo", TestBincRpcGo) t.Run("TestSimpleRpcGo", TestSimpleRpcGo) t.Run("TestMsgpackRpcGo", TestMsgpackRpcGo) t.Run("TestCborRpcGo", TestCborRpcGo) t.Run("TestJsonRpcGo", TestJsonRpcGo) t.Run("TestMsgpackRpcSpec", TestMsgpackRpcSpec) } func testNonHandlesGroup(t *testing.T) { // grep "func Test" codec_test.go | grep -v -E '(Cbor|Json|Simple|Msgpack|Binc)' t.Run("TestBufioDecReader", TestBufioDecReader) t.Run("TestAtomic", TestAtomic) t.Run("TestAllEncCircularRef", TestAllEncCircularRef) t.Run("TestAllAnonCycle", TestAllAnonCycle) t.Run("TestMultipleEncDec", TestMultipleEncDec) t.Run("TestAllErrWriter", TestAllErrWriter) t.Run("TestMapRangeIndex", TestMapRangeIndex) } func TestCodecSuite(t *testing.T) { var tt testTimeTracker tt.Elapsed() fnRun := func(s string, f func(t *testing.T)) { t.Run(s, f) // xdebugf("%s: %v", s, tt.Elapsed()) } testGroupResetFlags() testReinit() // so flag.Parse() is called first, and never called again fnRun("optionsFalse", testCodecGroup) testUseIoEncDec = 0 testUseReset = true testUseParallel = true testDecodeOptions.ZeroCopy = true testDecodeOptions.InternString = true testDecodeOptions.MapValueReset = true // testDecodeOptions.ErrorIfNoField = true // error, as expected fields not there // testDecodeOptions.ErrorIfNoArrayExpand = true // no error, but no error case either // testDecodeOptions.PreferArrayOverSlice = true // error??? because slice != array. testDecodeOptions.SignedInteger = true // error as deepEqual compares int64 to uint64 testDecodeOptions.SliceElementReset = true testDecodeOptions.InterfaceReset = true testDecodeOptions.RawToString = true testDecodeOptions.PreferPointerForStructOrArray = true testEncodeOptions.StructToArray = true testEncodeOptions.Canonical = true testEncodeOptions.CheckCircularRef = true testEncodeOptions.RecursiveEmptyCheck = true testEncodeOptions.OptimumSize = true // testEncodeOptions.Raw = true // testEncodeOptions.StringToRaw = true testJsonH.HTMLCharsAsIs = true // testJsonH.MapKeyAsString = true // testJsonH.PreferFloat = true testCborH.IndefiniteLength = true testCborH.TimeRFC3339 = true testCborH.SkipUnexpectedTags = true testMsgpackH.WriteExt = true testMsgpackH.NoFixedNum = true testMsgpackH.PositiveIntUnsigned = true // testSimpleH.EncZeroValuesAsNil = true testReinit() fnRun("optionsTrue", testCodecGroup) testGroupResetFlags() // --- testDepth = 4 if testing.Short() { testDepth = 2 } testReinit() fnRun("optionsTrue-deepstruct", testCodecGroupV) testDepth = 0 // --- // testEncodeOptions.AsSymbols = AsSymbolAll testUseIoWrapper = true testReinit() fnRun("optionsTrue-ioWrapper", testCodecGroupV) testUseIoWrapper = false // testUseIoEncDec = -1 // --- // make buffer small enough so that we have to re-fill multiple times // and also such that writing a quoted struct name e.g. "LongFieldNameXYZ" // will require a re-fill, and test out bufioEncWriter.writeqstr well. // Due to last requirement, we prefer 16 to 128. testSkipRPCTests = true testUseIoEncDec = 16 // testDecodeOptions.ReaderBufferSize = 128 // testEncodeOptions.WriterBufferSize = 128 testReinit() fnRun("optionsTrue-bufio", testCodecGroupV) // testDecodeOptions.ReaderBufferSize = 0 // testEncodeOptions.WriterBufferSize = 0 testSkipRPCTests = false testUseIoEncDec = -1 // --- testNumRepeatString = 32 testReinit() fnRun("optionsTrue-largestrings", testCodecGroupV) testNumRepeatString = 8 testGroupResetFlags() // --- fnJsonReset := func(ml int, d int8, hca, mkas bool) func() { return func() { testMaxInitLen = ml testJsonH.Indent = d testJsonH.HTMLCharsAsIs = hca testJsonH.MapKeyAsString = mkas } }(testMaxInitLen, testJsonH.Indent, testJsonH.HTMLCharsAsIs, testJsonH.MapKeyAsString) testMaxInitLen = 10 testJsonH.MapKeyAsString = true testJsonH.Indent = 8 testJsonH.HTMLCharsAsIs = true testReinit() fnRun("json-spaces-htmlcharsasis-initLen10", testJsonGroup) testJsonH.Indent = -1 testJsonH.HTMLCharsAsIs = false testReinit() fnRun("json-tabs-initLen10", testJsonGroup) fnJsonReset() // --- oldSymbols := testBincH.AsSymbols testBincH.AsSymbols = 2 // AsSymbolNone testReinit() fnRun("binc-no-symbols", testBincGroup) testBincH.AsSymbols = 1 // AsSymbolAll testReinit() fnRun("binc-all-symbols", testBincGroup) testBincH.AsSymbols = oldSymbols // --- oldEncZeroValuesAsNil := testSimpleH.EncZeroValuesAsNil testSimpleH.EncZeroValuesAsNil = !testSimpleH.EncZeroValuesAsNil testReinit() fnRun("simple-enczeroasnil", testSimpleMammothGroup) // testSimpleGroup testSimpleH.EncZeroValuesAsNil = oldEncZeroValuesAsNil // --- testUseIoEncDec = 16 testRPCOptions.RPCNoBuffer = false testReinit() testRpcBufsize = 0 fnRun("rpc-buf-0", testRpcGroup) testRpcBufsize = 0 fnRun("rpc-buf-00", testRpcGroup) testRpcBufsize = 0 fnRun("rpc-buf-000", testRpcGroup) testRpcBufsize = 16 fnRun("rpc-buf-16", testRpcGroup) testRpcBufsize = 2048 fnRun("rpc-buf-2048", testRpcGroup) testRPCOptions.RPCNoBuffer = true testRpcBufsize = 0 fnRun("rpc-buf-0-rpcNoBuffer", testRpcGroup) testRpcBufsize = 0 fnRun("rpc-buf-00-rpcNoBuffer", testRpcGroup) testRpcBufsize = 2048 fnRun("rpc-buf-2048-rpcNoBuffer", testRpcGroup) testGroupResetFlags() } // func TestCodecSuite(t *testing.T) { // testReinit() // so flag.Parse() is called first, and never called again // testDecodeOptions, testEncodeOptions = DecodeOptions{}, EncodeOptions{} // testGroupResetFlags() // testReinit() // t.Run("optionsFalse", func(t *testing.T) { // t.Run("TestJsonMammothMapsAndSlices", TestJsonMammothMapsAndSlices) // }) // } go-1.2.8/doc.go000066400000000000000000000004001435255326100132230ustar00rootroot00000000000000// 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 ugorji import _ "github.com/ugorji/go/codec" // PlaceHolder file, so this can be seen as a module. go-1.2.8/go.mod000066400000000000000000000001201435255326100132340ustar00rootroot00000000000000module github.com/ugorji/go go 1.11 require github.com/ugorji/go/codec v1.2.8 go-1.2.8/go.sum000066400000000000000000000000001435255326100132560ustar00rootroot00000000000000go-1.2.8/msgpack.org.md000066400000000000000000000024321435255326100146730ustar00rootroot00000000000000**MessagePack and [Binc](http://github.com/ugorji/binc) Codec for [Go](http://golang.org) Language.** *A High Performance, Feature-Rich, Idiomatic encode/decode and rpc library*. To install: go get github.com/ugorji/go/codec Source: [http://github.com/ugorji/go] Online documentation: [http://godoc.org/github.com/ugorji/go/codec] Typical usage: ```go // create and use decoder/encoder var ( v interface{} // value to decode/encode into r io.Reader w io.Writer b []byte mh codec.MsgpackHandle ) dec = codec.NewDecoder(r, &mh) dec = codec.NewDecoderBytes(b, &mh) err = dec.Decode(&v) enc = codec.NewEncoder(w, &mh) enc = codec.NewEncoderBytes(&b, &mh) 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) ```