replace zxq.co/ripple/hanayo
This commit is contained in:
11
vendor/github.com/ugorji/go/.travis.yml
generated
vendored
Normal file
11
vendor/github.com/ugorji/go/.travis.yml
generated
vendored
Normal file
@@ -0,0 +1,11 @@
|
||||
language: go
|
||||
sudo: false
|
||||
go:
|
||||
- 1.7.x # go testing suite support, which we use, was introduced in go 1.7
|
||||
- 1.8.x
|
||||
- 1.9.x
|
||||
- tip
|
||||
script:
|
||||
- go test -tags "alltests" -run Suite -coverprofile coverage.txt github.com/ugorji/go/codec
|
||||
after_success:
|
||||
- bash <(curl -s https://codecov.io/bash)
|
22
vendor/github.com/ugorji/go/LICENSE
generated
vendored
Normal file
22
vendor/github.com/ugorji/go/LICENSE
generated
vendored
Normal file
@@ -0,0 +1,22 @@
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2012-2015 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.
|
27
vendor/github.com/ugorji/go/README.md
generated
vendored
Normal file
27
vendor/github.com/ugorji/go/README.md
generated
vendored
Normal file
@@ -0,0 +1,27 @@
|
||||
[](https://sourcegraph.com/github.com/ugorji/go/-/blob/codec)
|
||||
[](https://travis-ci.org/ugorji/go)
|
||||
[](https://codecov.io/gh/ugorji/go)
|
||||
[](http://godoc.org/github.com/ugorji/go/codec)
|
||||
[](https://goreportcard.com/report/github.com/ugorji/go/codec)
|
||||
[](https://raw.githubusercontent.com/ugorji/go/master/LICENSE)
|
||||
|
||||
# go/codec
|
||||
|
||||
This repository contains the `go-codec` library,
|
||||
a High Performance and Feature-Rich Idiomatic encode/decode and rpc library for
|
||||
|
||||
- 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
|
||||
|
||||
For more information:
|
||||
|
||||
- [see the codec/Readme for quick usage information](https://github.com/ugorji/go/tree/master/codec#readme)
|
||||
- [view the API on godoc](http://godoc.org/github.com/ugorji/go/codec)
|
||||
- [read the detailed usage/how-to primer](http://ugorji.net/blog/go-codec-primer)
|
||||
|
||||
Install using:
|
||||
|
||||
go get github.com/ugorji/go/codec
|
||||
|
264
vendor/github.com/ugorji/go/codec/0doc.go
generated
vendored
Normal file
264
vendor/github.com/ugorji/go/codec/0doc.go
generated
vendored
Normal file
@@ -0,0 +1,264 @@
|
||||
// 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 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:
|
||||
|
||||
To install:
|
||||
|
||||
go get github.com/ugorji/go/codec
|
||||
|
||||
This package will carefully use '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=safe ...'. Note that unsafe is only supported for the last 3
|
||||
go sdk versions e.g. current go release is go 1.9, so we support unsafe use only from
|
||||
go 1.7+ . This is because supporting unsafe requires knowledge of implementation details.
|
||||
|
||||
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 go1.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% mode exists where 'unsafe' is not used at all.
|
||||
- Lock-free (sans mutex) concurrency for scaling to 100's of cores
|
||||
- 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 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.
|
||||
- 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
|
||||
- For messagepack, 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.
|
||||
|
||||
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 type a codec.Selfer?
|
||||
- is there an extension registered for the type?
|
||||
- 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?
|
||||
- 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 'safe' to run tests or build in safe mode. e.g.
|
||||
|
||||
go test -tags safe -run Json
|
||||
go test -tags "alltests safe" -run Suite
|
||||
|
||||
Running Benchmarks
|
||||
|
||||
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
|
||||
|
||||
// TODO:
|
||||
// - In Go 1.10, when mid-stack inlining is enabled,
|
||||
// we should use committed functions for writeXXX and readXXX calls.
|
||||
// This involves uncommenting the methods for decReaderSwitch and encWriterSwitch
|
||||
// and using those (decReaderSwitch and encWriterSwitch) in all handles
|
||||
// instead of encWriter and decReader.
|
||||
// The benefit is that, for the (En|De)coder over []byte, the encWriter/decReader
|
||||
// will be inlined, giving a performance bump for that typical case.
|
||||
// However, it will only be inlined if mid-stack inlining is enabled,
|
||||
// as we call panic to raise errors, and panic currently prevents inlining.
|
||||
//
|
||||
// PUNTED:
|
||||
// - To make Handle comparable, make extHandle in BasicHandle a non-embedded pointer,
|
||||
// and use overlay methods on *BasicHandle to call through to extHandle after initializing
|
||||
// the "xh *extHandle" to point to a real slice.
|
||||
//
|
||||
// BEFORE EACH RELEASE:
|
||||
// - Look through and fix padding for each type, to eliminate false sharing
|
||||
// - critical shared objects that are read many times
|
||||
// TypeInfos
|
||||
// - pooled objects:
|
||||
// decNaked, decNakedContainers, codecFner, typeInfoLoadArray,
|
||||
// - small objects allocated independently, that we read/use much across threads:
|
||||
// codecFn, typeInfo
|
||||
// - Objects allocated independently and used a lot
|
||||
// Decoder, Encoder,
|
||||
// xxxHandle, xxxEncDriver, xxxDecDriver (xxx = json, msgpack, cbor, binc, simple)
|
||||
// - In all above, arrange values modified together to be close to each other.
|
||||
//
|
||||
// For all of these, either ensure that they occupy full cache lines,
|
||||
// or ensure that the things just past the cache line boundary are hardly read/written
|
||||
// e.g. JsonHandle.RawBytesExt - which is copied into json(En|De)cDriver at init
|
||||
//
|
||||
// Occupying full cache lines means they occupy 8*N words (where N is an integer).
|
||||
// Check this out by running: ./run.sh -z
|
||||
// - look at those tagged ****, meaning they are not occupying full cache lines
|
||||
// - look at those tagged <<<<, meaning they are larger than 32 words (something to watch)
|
||||
// - Run "golint -min_confidence 0.81"
|
206
vendor/github.com/ugorji/go/codec/README.md
generated
vendored
Normal file
206
vendor/github.com/ugorji/go/codec/README.md
generated
vendored
Normal file
@@ -0,0 +1,206 @@
|
||||
# Codec
|
||||
|
||||
High Performance, Feature-Rich Idiomatic Go 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:
|
||||
|
||||
To install:
|
||||
|
||||
go get github.com/ugorji/go/codec
|
||||
|
||||
This package will carefully use '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=safe ...'. Note that unsafe is only supported for the last 3
|
||||
go sdk versions e.g. current go release is go 1.9, so we support unsafe use only from
|
||||
go 1.7+ . This is because supporting unsafe requires knowledge of implementation details.
|
||||
|
||||
Online documentation: http://godoc.org/github.com/ugorji/go/codec
|
||||
Detailed Usage/How-to Primer: 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 go1.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% mode exists where 'unsafe' is not used at all.
|
||||
- Lock-free (sans mutex) concurrency for scaling to 100's of cores
|
||||
- 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 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.
|
||||
- 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.
|
||||
- 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
|
||||
- For messagepack, 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.
|
||||
|
||||
## 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 type a codec.Selfer?
|
||||
- is there an extension registered for the type?
|
||||
- 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?
|
||||
- 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
|
||||
|
||||
Typical 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 'safe' to run tests or build in safe mode. e.g.
|
||||
|
||||
go test -tags safe -run Json
|
||||
go test -tags "alltests safe" -run Suite
|
||||
|
||||
## Running Benchmarks
|
||||
|
||||
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.
|
1124
vendor/github.com/ugorji/go/codec/binc.go
generated
vendored
Normal file
1124
vendor/github.com/ugorji/go/codec/binc.go
generated
vendored
Normal file
File diff suppressed because it is too large
Load Diff
716
vendor/github.com/ugorji/go/codec/cbor.go
generated
vendored
Normal file
716
vendor/github.com/ugorji/go/codec/cbor.go
generated
vendored
Normal file
@@ -0,0 +1,716 @@
|
||||
// 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 (
|
||||
"math"
|
||||
"reflect"
|
||||
"time"
|
||||
)
|
||||
|
||||
const (
|
||||
cborMajorUint byte = iota
|
||||
cborMajorNegInt
|
||||
cborMajorBytes
|
||||
cborMajorText
|
||||
cborMajorArray
|
||||
cborMajorMap
|
||||
cborMajorTag
|
||||
cborMajorOther
|
||||
)
|
||||
|
||||
const (
|
||||
cborBdFalse byte = 0xf4 + iota
|
||||
cborBdTrue
|
||||
cborBdNil
|
||||
cborBdUndefined
|
||||
cborBdExt
|
||||
cborBdFloat16
|
||||
cborBdFloat32
|
||||
cborBdFloat64
|
||||
)
|
||||
|
||||
const (
|
||||
cborBdIndefiniteBytes byte = 0x5f
|
||||
cborBdIndefiniteString = 0x7f
|
||||
cborBdIndefiniteArray = 0x9f
|
||||
cborBdIndefiniteMap = 0xbf
|
||||
cborBdBreak = 0xff
|
||||
)
|
||||
|
||||
// These define some in-stream descriptors for
|
||||
// manual encoding e.g. when doing explicit indefinite-length
|
||||
const (
|
||||
CborStreamBytes byte = 0x5f
|
||||
CborStreamString = 0x7f
|
||||
CborStreamArray = 0x9f
|
||||
CborStreamMap = 0xbf
|
||||
CborStreamBreak = 0xff
|
||||
)
|
||||
|
||||
const (
|
||||
cborBaseUint byte = 0x00
|
||||
cborBaseNegInt = 0x20
|
||||
cborBaseBytes = 0x40
|
||||
cborBaseString = 0x60
|
||||
cborBaseArray = 0x80
|
||||
cborBaseMap = 0xa0
|
||||
cborBaseTag = 0xc0
|
||||
cborBaseSimple = 0xe0
|
||||
)
|
||||
|
||||
// -------------------
|
||||
|
||||
type cborEncDriver struct {
|
||||
noBuiltInTypes
|
||||
encDriverNoopContainerWriter
|
||||
// encNoSeparator
|
||||
e *Encoder
|
||||
w encWriter
|
||||
h *CborHandle
|
||||
x [8]byte
|
||||
_ [3]uint64 // padding
|
||||
}
|
||||
|
||||
func (e *cborEncDriver) EncodeNil() {
|
||||
e.w.writen1(cborBdNil)
|
||||
}
|
||||
|
||||
func (e *cborEncDriver) EncodeBool(b bool) {
|
||||
if b {
|
||||
e.w.writen1(cborBdTrue)
|
||||
} else {
|
||||
e.w.writen1(cborBdFalse)
|
||||
}
|
||||
}
|
||||
|
||||
func (e *cborEncDriver) EncodeFloat32(f float32) {
|
||||
e.w.writen1(cborBdFloat32)
|
||||
bigenHelper{e.x[:4], e.w}.writeUint32(math.Float32bits(f))
|
||||
}
|
||||
|
||||
func (e *cborEncDriver) EncodeFloat64(f float64) {
|
||||
e.w.writen1(cborBdFloat64)
|
||||
bigenHelper{e.x[:8], e.w}.writeUint64(math.Float64bits(f))
|
||||
}
|
||||
|
||||
func (e *cborEncDriver) encUint(v uint64, bd byte) {
|
||||
if v <= 0x17 {
|
||||
e.w.writen1(byte(v) + bd)
|
||||
} else if v <= math.MaxUint8 {
|
||||
e.w.writen2(bd+0x18, uint8(v))
|
||||
} else if v <= math.MaxUint16 {
|
||||
e.w.writen1(bd + 0x19)
|
||||
bigenHelper{e.x[:2], e.w}.writeUint16(uint16(v))
|
||||
} else if v <= math.MaxUint32 {
|
||||
e.w.writen1(bd + 0x1a)
|
||||
bigenHelper{e.x[:4], e.w}.writeUint32(uint32(v))
|
||||
} else { // if v <= math.MaxUint64 {
|
||||
e.w.writen1(bd + 0x1b)
|
||||
bigenHelper{e.x[:8], e.w}.writeUint64(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.EncodeString(cUTF8, 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{}, xtag uint64, ext Ext, en *Encoder) {
|
||||
e.encUint(uint64(xtag), cborBaseTag)
|
||||
if v := ext.ConvertExt(rv); v == nil {
|
||||
e.EncodeNil()
|
||||
} else {
|
||||
en.encode(v)
|
||||
}
|
||||
}
|
||||
|
||||
func (e *cborEncDriver) EncodeRawExt(re *RawExt, en *Encoder) {
|
||||
e.encUint(uint64(re.Tag), cborBaseTag)
|
||||
if false && re.Data != nil {
|
||||
en.encode(re.Data)
|
||||
} else if re.Value != nil {
|
||||
en.encode(re.Value)
|
||||
} else {
|
||||
e.EncodeNil()
|
||||
}
|
||||
}
|
||||
|
||||
func (e *cborEncDriver) WriteArrayStart(length int) {
|
||||
if e.h.IndefiniteLength {
|
||||
e.w.writen1(cborBdIndefiniteArray)
|
||||
} else {
|
||||
e.encLen(cborBaseArray, length)
|
||||
}
|
||||
}
|
||||
|
||||
func (e *cborEncDriver) WriteMapStart(length int) {
|
||||
if e.h.IndefiniteLength {
|
||||
e.w.writen1(cborBdIndefiniteMap)
|
||||
} else {
|
||||
e.encLen(cborBaseMap, length)
|
||||
}
|
||||
}
|
||||
|
||||
func (e *cborEncDriver) WriteMapEnd() {
|
||||
if e.h.IndefiniteLength {
|
||||
e.w.writen1(cborBdBreak)
|
||||
}
|
||||
}
|
||||
|
||||
func (e *cborEncDriver) WriteArrayEnd() {
|
||||
if e.h.IndefiniteLength {
|
||||
e.w.writen1(cborBdBreak)
|
||||
}
|
||||
}
|
||||
|
||||
func (e *cborEncDriver) EncodeString(c charEncoding, v string) {
|
||||
e.encStringBytesS(cborBaseString, v)
|
||||
}
|
||||
|
||||
func (e *cborEncDriver) EncodeStringBytes(c charEncoding, v []byte) {
|
||||
if v == nil {
|
||||
e.EncodeNil()
|
||||
} else if c == cRAW {
|
||||
e.encStringBytesS(cborBaseBytes, stringView(v))
|
||||
} else {
|
||||
e.encStringBytesS(cborBaseString, stringView(v))
|
||||
}
|
||||
}
|
||||
|
||||
func (e *cborEncDriver) encStringBytesS(bb byte, v string) {
|
||||
if e.h.IndefiniteLength {
|
||||
if bb == cborBaseBytes {
|
||||
e.w.writen1(cborBdIndefiniteBytes)
|
||||
} else {
|
||||
e.w.writen1(cborBdIndefiniteString)
|
||||
}
|
||||
blen := len(v) / 4
|
||||
if blen == 0 {
|
||||
blen = 64
|
||||
} else if blen > 1024 {
|
||||
blen = 1024
|
||||
}
|
||||
for i := 0; i < len(v); {
|
||||
var v2 string
|
||||
i2 := i + blen
|
||||
if i2 < len(v) {
|
||||
v2 = v[i:i2]
|
||||
} else {
|
||||
v2 = v[i:]
|
||||
}
|
||||
e.encLen(bb, len(v2))
|
||||
e.w.writestr(v2)
|
||||
i = i2
|
||||
}
|
||||
e.w.writen1(cborBdBreak)
|
||||
} else {
|
||||
e.encLen(bb, len(v))
|
||||
e.w.writestr(v)
|
||||
}
|
||||
}
|
||||
|
||||
// ----------------------
|
||||
|
||||
type cborDecDriver struct {
|
||||
d *Decoder
|
||||
h *CborHandle
|
||||
r decReader
|
||||
// b [scratchByteArrayLen]byte
|
||||
br bool // bytes reader
|
||||
bdRead bool
|
||||
bd byte
|
||||
noBuiltInTypes
|
||||
// decNoSeparator
|
||||
decDriverNoopContainerReader
|
||||
_ [3]uint64 // padding
|
||||
}
|
||||
|
||||
func (d *cborDecDriver) readNextBd() {
|
||||
d.bd = d.r.readn1()
|
||||
d.bdRead = true
|
||||
}
|
||||
|
||||
func (d *cborDecDriver) uncacheRead() {
|
||||
if d.bdRead {
|
||||
d.r.unreadn1()
|
||||
d.bdRead = false
|
||||
}
|
||||
}
|
||||
|
||||
func (d *cborDecDriver) ContainerType() (vt valueType) {
|
||||
if !d.bdRead {
|
||||
d.readNextBd()
|
||||
}
|
||||
if d.bd == cborBdNil {
|
||||
return valueTypeNil
|
||||
} else if d.bd == cborBdIndefiniteBytes || (d.bd >= cborBaseBytes && d.bd < cborBaseString) {
|
||||
return valueTypeBytes
|
||||
} else if d.bd == cborBdIndefiniteString || (d.bd >= cborBaseString && d.bd < cborBaseArray) {
|
||||
return valueTypeString
|
||||
} else if d.bd == cborBdIndefiniteArray || (d.bd >= cborBaseArray && d.bd < cborBaseMap) {
|
||||
return valueTypeArray
|
||||
} else if d.bd == cborBdIndefiniteMap || (d.bd >= cborBaseMap && d.bd < cborBaseTag) {
|
||||
return valueTypeMap
|
||||
}
|
||||
// else {
|
||||
// d.d.errorf("isContainerType: unsupported parameter: %v", vt)
|
||||
// }
|
||||
return valueTypeUnset
|
||||
}
|
||||
|
||||
func (d *cborDecDriver) TryDecodeAsNil() bool {
|
||||
if !d.bdRead {
|
||||
d.readNextBd()
|
||||
}
|
||||
// treat Nil and Undefined as nil values
|
||||
if d.bd == cborBdNil || d.bd == cborBdUndefined {
|
||||
d.bdRead = false
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func (d *cborDecDriver) CheckBreak() bool {
|
||||
if !d.bdRead {
|
||||
d.readNextBd()
|
||||
}
|
||||
if d.bd == cborBdBreak {
|
||||
d.bdRead = false
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func (d *cborDecDriver) decUint() (ui uint64) {
|
||||
v := d.bd & 0x1f
|
||||
if v <= 0x17 {
|
||||
ui = uint64(v)
|
||||
} else {
|
||||
if v == 0x18 {
|
||||
ui = uint64(d.r.readn1())
|
||||
} else if v == 0x19 {
|
||||
ui = uint64(bigen.Uint16(d.r.readx(2)))
|
||||
} else if v == 0x1a {
|
||||
ui = uint64(bigen.Uint32(d.r.readx(4)))
|
||||
} else if v == 0x1b {
|
||||
ui = uint64(bigen.Uint64(d.r.readx(8)))
|
||||
} else {
|
||||
d.d.errorf("decUint: Invalid descriptor: %v", d.bd)
|
||||
return
|
||||
}
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func (d *cborDecDriver) decCheckInteger() (neg bool) {
|
||||
if !d.bdRead {
|
||||
d.readNextBd()
|
||||
}
|
||||
major := d.bd >> 5
|
||||
if major == cborMajorUint {
|
||||
} else if major == cborMajorNegInt {
|
||||
neg = true
|
||||
} else {
|
||||
d.d.errorf("invalid major: %v (bd: %v)", major, d.bd)
|
||||
return
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func (d *cborDecDriver) DecodeInt64() (i int64) {
|
||||
neg := d.decCheckInteger()
|
||||
ui := d.decUint()
|
||||
// check if this number can be converted to an int without overflow
|
||||
if neg {
|
||||
i = -(chkOvf.SignedIntV(ui + 1))
|
||||
} else {
|
||||
i = chkOvf.SignedIntV(ui)
|
||||
}
|
||||
d.bdRead = false
|
||||
return
|
||||
}
|
||||
|
||||
func (d *cborDecDriver) DecodeUint64() (ui uint64) {
|
||||
if d.decCheckInteger() {
|
||||
d.d.errorf("Assigning negative signed value to unsigned type")
|
||||
return
|
||||
}
|
||||
ui = d.decUint()
|
||||
d.bdRead = false
|
||||
return
|
||||
}
|
||||
|
||||
func (d *cborDecDriver) DecodeFloat64() (f float64) {
|
||||
if !d.bdRead {
|
||||
d.readNextBd()
|
||||
}
|
||||
if bd := d.bd; bd == cborBdFloat16 {
|
||||
f = float64(math.Float32frombits(halfFloatToFloatBits(bigen.Uint16(d.r.readx(2)))))
|
||||
} else if bd == cborBdFloat32 {
|
||||
f = float64(math.Float32frombits(bigen.Uint32(d.r.readx(4))))
|
||||
} else if bd == cborBdFloat64 {
|
||||
f = math.Float64frombits(bigen.Uint64(d.r.readx(8)))
|
||||
} else if bd >= cborBaseUint && bd < cborBaseBytes {
|
||||
f = float64(d.DecodeInt64())
|
||||
} else {
|
||||
d.d.errorf("Float only valid from float16/32/64: Invalid descriptor: %v", bd)
|
||||
return
|
||||
}
|
||||
d.bdRead = false
|
||||
return
|
||||
}
|
||||
|
||||
// bool can be decoded from bool only (single byte).
|
||||
func (d *cborDecDriver) DecodeBool() (b bool) {
|
||||
if !d.bdRead {
|
||||
d.readNextBd()
|
||||
}
|
||||
if bd := d.bd; bd == cborBdTrue {
|
||||
b = true
|
||||
} else if bd == cborBdFalse {
|
||||
} else {
|
||||
d.d.errorf("Invalid single-byte value for bool: %s: %x", msgBadDesc, d.bd)
|
||||
return
|
||||
}
|
||||
d.bdRead = false
|
||||
return
|
||||
}
|
||||
|
||||
func (d *cborDecDriver) ReadMapStart() (length int) {
|
||||
if !d.bdRead {
|
||||
d.readNextBd()
|
||||
}
|
||||
d.bdRead = false
|
||||
if d.bd == cborBdIndefiniteMap {
|
||||
return -1
|
||||
}
|
||||
return d.decLen()
|
||||
}
|
||||
|
||||
func (d *cborDecDriver) ReadArrayStart() (length int) {
|
||||
if !d.bdRead {
|
||||
d.readNextBd()
|
||||
}
|
||||
d.bdRead = false
|
||||
if d.bd == cborBdIndefiniteArray {
|
||||
return -1
|
||||
}
|
||||
return d.decLen()
|
||||
}
|
||||
|
||||
func (d *cborDecDriver) decLen() int {
|
||||
return int(d.decUint())
|
||||
}
|
||||
|
||||
func (d *cborDecDriver) decAppendIndefiniteBytes(bs []byte) []byte {
|
||||
d.bdRead = false
|
||||
for {
|
||||
if d.CheckBreak() {
|
||||
break
|
||||
}
|
||||
if major := d.bd >> 5; major != cborMajorBytes && major != cborMajorText {
|
||||
d.d.errorf("expect bytes/string major type in indefinite string/bytes;"+
|
||||
" got: %v, byte: %v", major, d.bd)
|
||||
return nil
|
||||
}
|
||||
n := d.decLen()
|
||||
oldLen := len(bs)
|
||||
newLen := oldLen + n
|
||||
if newLen > cap(bs) {
|
||||
bs2 := make([]byte, newLen, 2*cap(bs)+n)
|
||||
copy(bs2, bs)
|
||||
bs = bs2
|
||||
} else {
|
||||
bs = bs[:newLen]
|
||||
}
|
||||
d.r.readb(bs[oldLen:newLen])
|
||||
// bs = append(bs, d.r.readn()...)
|
||||
d.bdRead = false
|
||||
}
|
||||
d.bdRead = false
|
||||
return bs
|
||||
}
|
||||
|
||||
func (d *cborDecDriver) DecodeBytes(bs []byte, zerocopy bool) (bsOut []byte) {
|
||||
if !d.bdRead {
|
||||
d.readNextBd()
|
||||
}
|
||||
if d.bd == cborBdNil || d.bd == cborBdUndefined {
|
||||
d.bdRead = false
|
||||
return nil
|
||||
}
|
||||
if d.bd == cborBdIndefiniteBytes || d.bd == cborBdIndefiniteString {
|
||||
d.bdRead = false
|
||||
if bs == nil {
|
||||
if zerocopy {
|
||||
return d.decAppendIndefiniteBytes(d.d.b[:0])
|
||||
}
|
||||
return d.decAppendIndefiniteBytes(zeroByteSlice)
|
||||
}
|
||||
return d.decAppendIndefiniteBytes(bs[:0])
|
||||
}
|
||||
// check if an "array" of uint8's (see ContainerType for how to infer if an array)
|
||||
if d.bd == cborBdIndefiniteArray || (d.bd >= cborBaseArray && d.bd < cborBaseMap) {
|
||||
bsOut, _ = fastpathTV.DecSliceUint8V(bs, true, d.d)
|
||||
return
|
||||
}
|
||||
clen := d.decLen()
|
||||
d.bdRead = false
|
||||
if zerocopy {
|
||||
if d.br {
|
||||
return d.r.readx(clen)
|
||||
} else if len(bs) == 0 {
|
||||
bs = d.d.b[:]
|
||||
}
|
||||
}
|
||||
return decByteSlice(d.r, clen, d.h.MaxInitLen, bs)
|
||||
}
|
||||
|
||||
func (d *cborDecDriver) DecodeString() (s string) {
|
||||
return string(d.DecodeBytes(d.d.b[:], true))
|
||||
}
|
||||
|
||||
func (d *cborDecDriver) DecodeStringAsBytes() (s []byte) {
|
||||
return d.DecodeBytes(d.d.b[:], true)
|
||||
}
|
||||
|
||||
func (d *cborDecDriver) DecodeTime() (t time.Time) {
|
||||
if !d.bdRead {
|
||||
d.readNextBd()
|
||||
}
|
||||
if d.bd == cborBdNil || d.bd == cborBdUndefined {
|
||||
d.bdRead = false
|
||||
return
|
||||
}
|
||||
xtag := d.decUint()
|
||||
d.bdRead = false
|
||||
return d.decodeTime(xtag)
|
||||
}
|
||||
|
||||
func (d *cborDecDriver) decodeTime(xtag uint64) (t time.Time) {
|
||||
if !d.bdRead {
|
||||
d.readNextBd()
|
||||
}
|
||||
switch xtag {
|
||||
case 0:
|
||||
var err error
|
||||
if t, err = time.Parse(time.RFC3339, stringView(d.DecodeStringAsBytes())); err != nil {
|
||||
d.d.errorv(err)
|
||||
}
|
||||
case 1:
|
||||
// decode an int64 or a float, and infer time.Time from there.
|
||||
// for floats, round to microseconds, as that is what is guaranteed to fit well.
|
||||
switch {
|
||||
case d.bd == cborBdFloat16, d.bd == cborBdFloat32:
|
||||
f1, f2 := math.Modf(d.DecodeFloat64())
|
||||
t = time.Unix(int64(f1), int64(f2*1e9))
|
||||
case d.bd == cborBdFloat64:
|
||||
f1, f2 := math.Modf(d.DecodeFloat64())
|
||||
t = time.Unix(int64(f1), int64(f2*1e9))
|
||||
case d.bd >= cborBaseUint && d.bd < cborBaseNegInt,
|
||||
d.bd >= cborBaseNegInt && d.bd < cborBaseBytes:
|
||||
t = time.Unix(d.DecodeInt64(), 0)
|
||||
default:
|
||||
d.d.errorf("time.Time can only be decoded from a number (or RFC3339 string)")
|
||||
}
|
||||
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{}, xtag uint64, ext Ext) (realxtag uint64) {
|
||||
if !d.bdRead {
|
||||
d.readNextBd()
|
||||
}
|
||||
u := d.decUint()
|
||||
d.bdRead = false
|
||||
realxtag = u
|
||||
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)
|
||||
return
|
||||
} else {
|
||||
var v interface{}
|
||||
d.d.decode(&v)
|
||||
ext.UpdateExt(rv, v)
|
||||
}
|
||||
d.bdRead = false
|
||||
return
|
||||
}
|
||||
|
||||
func (d *cborDecDriver) DecodeNaked() {
|
||||
if !d.bdRead {
|
||||
d.readNextBd()
|
||||
}
|
||||
|
||||
n := d.d.n
|
||||
var decodeFurther bool
|
||||
|
||||
switch d.bd {
|
||||
case cborBdNil:
|
||||
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()
|
||||
case cborBdIndefiniteBytes:
|
||||
n.v = valueTypeBytes
|
||||
n.l = d.DecodeBytes(nil, false)
|
||||
case cborBdIndefiniteString:
|
||||
n.v = valueTypeString
|
||||
n.s = d.DecodeString()
|
||||
case cborBdIndefiniteArray:
|
||||
n.v = valueTypeArray
|
||||
decodeFurther = true
|
||||
case cborBdIndefiniteMap:
|
||||
n.v = valueTypeMap
|
||||
decodeFurther = true
|
||||
default:
|
||||
switch {
|
||||
case d.bd >= cborBaseUint && d.bd < cborBaseNegInt:
|
||||
if d.h.SignedInteger {
|
||||
n.v = valueTypeInt
|
||||
n.i = d.DecodeInt64()
|
||||
} else {
|
||||
n.v = valueTypeUint
|
||||
n.u = d.DecodeUint64()
|
||||
}
|
||||
case d.bd >= cborBaseNegInt && d.bd < cborBaseBytes:
|
||||
n.v = valueTypeInt
|
||||
n.i = d.DecodeInt64()
|
||||
case d.bd >= cborBaseBytes && d.bd < cborBaseString:
|
||||
n.v = valueTypeBytes
|
||||
n.l = d.DecodeBytes(nil, false)
|
||||
case d.bd >= cborBaseString && d.bd < cborBaseArray:
|
||||
n.v = valueTypeString
|
||||
n.s = d.DecodeString()
|
||||
case d.bd >= cborBaseArray && d.bd < cborBaseMap:
|
||||
n.v = valueTypeArray
|
||||
decodeFurther = true
|
||||
case d.bd >= cborBaseMap && d.bd < cborBaseTag:
|
||||
n.v = valueTypeMap
|
||||
decodeFurther = true
|
||||
case d.bd >= cborBaseTag && d.bd < cborBaseSimple:
|
||||
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)
|
||||
}
|
||||
// d.bdRead = false
|
||||
// d.d.decode(&re.Value) // handled by decode itself.
|
||||
// decodeFurther = true
|
||||
default:
|
||||
d.d.errorf("decodeNaked: Unrecognized d.bd: 0x%x", d.bd)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
if !decodeFurther {
|
||||
d.bdRead = false
|
||||
}
|
||||
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
|
||||
|
||||
_ [1]uint64 // padding
|
||||
}
|
||||
|
||||
// Name returns the name of the handle: cbor
|
||||
func (h *CborHandle) Name() string { return "cbor" }
|
||||
|
||||
// SetInterfaceExt sets an extension
|
||||
func (h *CborHandle) SetInterfaceExt(rt reflect.Type, tag uint64, ext InterfaceExt) (err error) {
|
||||
return h.SetExt(rt, tag, &extWrapper{bytesExtFailer{}, ext})
|
||||
}
|
||||
|
||||
func (h *CborHandle) newEncDriver(e *Encoder) encDriver {
|
||||
return &cborEncDriver{e: e, w: e.w, h: h}
|
||||
}
|
||||
|
||||
func (h *CborHandle) newDecDriver(d *Decoder) decDriver {
|
||||
return &cborDecDriver{d: d, h: h, r: d.r, br: d.bytes}
|
||||
}
|
||||
|
||||
func (e *cborEncDriver) reset() {
|
||||
e.w = e.e.w
|
||||
}
|
||||
|
||||
func (d *cborDecDriver) reset() {
|
||||
d.r, d.br = d.d.r, d.d.bytes
|
||||
d.bd, d.bdRead = 0, false
|
||||
}
|
||||
|
||||
var _ decDriver = (*cborDecDriver)(nil)
|
||||
var _ encDriver = (*cborEncDriver)(nil)
|
230
vendor/github.com/ugorji/go/codec/cbor_test.go
generated
vendored
Normal file
230
vendor/github.com/ugorji/go/codec/cbor_test.go
generated
vendored
Normal file
@@ -0,0 +1,230 @@
|
||||
// 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 (
|
||||
"bufio"
|
||||
"bytes"
|
||||
"encoding/hex"
|
||||
"math"
|
||||
"os"
|
||||
"regexp"
|
||||
"strings"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestCborIndefiniteLength(t *testing.T) {
|
||||
oldMapType := testCborH.MapType
|
||||
defer func() {
|
||||
testCborH.MapType = oldMapType
|
||||
}()
|
||||
testCborH.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, testCborH)
|
||||
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(), testCborH).MustDecode(&vv)
|
||||
if err := deepEqual(v, vv); err != nil {
|
||||
logT(t, "-------- Before and After marshal do not match: Error: %v", err)
|
||||
logT(t, " ....... GOLDEN: (%T) %#v", v, v)
|
||||
logT(t, " ....... DECODED: (%T) %#v", vv, vv)
|
||||
failT(t)
|
||||
}
|
||||
}
|
||||
|
||||
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) {
|
||||
oldMapType := testCborH.MapType
|
||||
defer func() {
|
||||
testCborH.MapType = oldMapType
|
||||
}()
|
||||
testCborH.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 {
|
||||
logT(t, "error opening test-cbor-goldens.json: %v", err)
|
||||
failT(t)
|
||||
}
|
||||
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 {
|
||||
logT(t, "error json decoding test-cbor-goldens.json: %v", err)
|
||||
failT(t)
|
||||
}
|
||||
|
||||
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)
|
||||
logT(t, "[%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 {
|
||||
logT(t, "[%v] error hex decoding %s [%v]: %v", i, g.Hex, err)
|
||||
failT(t)
|
||||
}
|
||||
var v interface{}
|
||||
NewDecoderBytes(bs, testCborH).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 {
|
||||
logT(t, "[%v] deepEqual error: %v", i, err)
|
||||
logT(t, " ....... GOLDEN: (%T) %#v", v0, v0)
|
||||
logT(t, " ....... DECODED: (%T) %#v", v1, v1)
|
||||
failT(t)
|
||||
}
|
||||
if equal != nil && !*equal {
|
||||
logT(t, "[%v] values not equal", i)
|
||||
logT(t, " ....... GOLDEN: (%T) %#v", v0, v0)
|
||||
logT(t, " ....... DECODED: (%T) %#v", v1, v1)
|
||||
failT(t)
|
||||
}
|
||||
// fmt.Printf("%v testCborError passed (checks passed)\n", i)
|
||||
}
|
||||
|
||||
func TestCborHalfFloat(t *testing.T) {
|
||||
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
|
||||
bigen.PutUint16(ba[1:], k)
|
||||
testUnmarshalErr(&res, ba[:3], testCborH, t, "-")
|
||||
if res == v {
|
||||
logT(t, "equal floats: from %x %b, %v", k, k, v)
|
||||
} else {
|
||||
failT(t, "unequal floats: from %x %b, %v != %v", k, k, res, v)
|
||||
}
|
||||
}
|
||||
}
|
2967
vendor/github.com/ugorji/go/codec/codec_test.go
generated
vendored
Normal file
2967
vendor/github.com/ugorji/go/codec/codec_test.go
generated
vendored
Normal file
File diff suppressed because it is too large
Load Diff
37
vendor/github.com/ugorji/go/codec/codecgen/README.md
generated
vendored
Normal file
37
vendor/github.com/ugorji/go/codec/codecgen/README.md
generated
vendored
Normal file
@@ -0,0 +1,37 @@
|
||||
# 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
|
||||
-r=".*": regex for type name to match
|
||||
-nr="": regex for type name to exclude
|
||||
-rt="": tags for go run
|
||||
-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
|
||||
```
|
||||
|
||||
Please see the [blog article](http://ugorji.net/blog/go-codecgen)
|
||||
for more information on how to use the tool.
|
||||
|
360
vendor/github.com/ugorji/go/codec/codecgen/gen.go
generated
vendored
Normal file
360
vendor/github.com/ugorji/go/codec/codecgen/gen.go
generated
vendored
Normal file
@@ -0,0 +1,360 @@
|
||||
// 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.
|
||||
|
||||
// codecgen generates codec.Selfer implementations for a set of types.
|
||||
package main
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"bytes"
|
||||
"errors"
|
||||
"flag"
|
||||
"fmt"
|
||||
"go/ast"
|
||||
"go/build"
|
||||
"go/parser"
|
||||
"go/token"
|
||||
"math/rand"
|
||||
"os"
|
||||
"os/exec"
|
||||
"path/filepath"
|
||||
"regexp"
|
||||
"strconv"
|
||||
"strings"
|
||||
"text/template"
|
||||
"time"
|
||||
)
|
||||
|
||||
const genCodecPkg = "codec1978" // keep this in sync with codec.genCodecPkg
|
||||
|
||||
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"
|
||||
)
|
||||
|
||||
func CodecGenTempWrite{{ .RandString }}() {
|
||||
os.Remove("{{ .OutFile }}")
|
||||
fout, err := os.Create("{{ .OutFile }}")
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
defer fout.Close()
|
||||
|
||||
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
|
||||
{{ if not .CodecPkgFiles }}{{ .CodecPkgName }}.{{ end }}Gen(out,
|
||||
"{{ .BuildTag }}", "{{ .PackageName }}", "{{ .RandString }}", {{ .NoExtensions }},
|
||||
{{ if not .CodecPkgFiles }}{{ .CodecPkgName }}.{{ end }}NewTypeInfos(strings.Split("{{ .StructTags }}", ",")),
|
||||
typs...)
|
||||
|
||||
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)
|
||||
}
|
||||
|
||||
`
|
||||
|
||||
// Generate 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 Generate(outfile, buildTag, codecPkgPath string,
|
||||
uid int64,
|
||||
goRunTag string, st string,
|
||||
regexName, notRegexName *regexp.Regexp,
|
||||
deleteTempFile, noExtensions bool,
|
||||
infiles ...string) (err error) {
|
||||
// For each file, grab AST, find each type, and write a call to it.
|
||||
if len(infiles) == 0 {
|
||||
return
|
||||
}
|
||||
if outfile == "" || codecPkgPath == "" {
|
||||
err = errors.New("outfile and codec package path cannot be blank")
|
||||
return
|
||||
}
|
||||
if uid < 0 {
|
||||
uid = -uid
|
||||
} else if uid == 0 {
|
||||
rr := rand.New(rand.NewSource(time.Now().UnixNano()))
|
||||
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(outfile)
|
||||
absdir, err := filepath.Abs(lastdir)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
pkg, err := build.Default.ImportDir(absdir, build.AllowBinary)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
type tmplT 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
|
||||
}
|
||||
tv := tmplT{
|
||||
CodecPkgName: genCodecPkg,
|
||||
OutFile: outfile,
|
||||
CodecImportPath: codecPkgPath,
|
||||
BuildTag: buildTag,
|
||||
RandString: strconv.FormatInt(uid, 10),
|
||||
StructTags: st,
|
||||
NoExtensions: noExtensions,
|
||||
}
|
||||
tv.ImportPath = pkg.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 = stripVendor(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("in files must all be in same directory as outfile")
|
||||
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 regexName.FindStringIndex(td.Name.Name) != nil &&
|
||||
notRegexName.FindStringIndex(td.Name.Name) == nil &&
|
||||
!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 := "codecgen-main-" + tv.RandString + ".generated.go"
|
||||
frunPkgName := "codecgen-pkg-" + tv.RandString + ".generated.go"
|
||||
if deleteTempFile {
|
||||
defer os.Remove(frunMainName)
|
||||
defer os.Remove(frunPkgName)
|
||||
}
|
||||
// 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(outfile)
|
||||
|
||||
// execute go run frun
|
||||
cmd := exec.Command("go", "run", "-tags", "codecgen.exec safe "+goRunTag, frunMainName) //, frunPkg.Name())
|
||||
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())
|
||||
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("")
|
||||
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
|
||||
}
|
||||
|
||||
// copied from ../gen.go (keep in sync).
|
||||
func stripVendor(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() {
|
||||
o := flag.String("o", "", "out file")
|
||||
c := flag.String("c", genCodecPath, "codec path")
|
||||
t := flag.String("t", "", "build tag to put in file")
|
||||
r := flag.String("r", ".*", "regex for type name to match")
|
||||
nr := flag.String("nr", "^$", "regex for type name to exclude")
|
||||
rt := flag.String("rt", "", "tags for go run")
|
||||
st := flag.String("st", "codec,json", "struct tag keys to introspect")
|
||||
x := flag.Bool("x", false, "keep temp file")
|
||||
_ = flag.Bool("u", false, "Allow unsafe use. ***IGNORED*** - kept for backwards compatibility: ")
|
||||
d := flag.Int64("d", 0, "random identifier for use in generated code")
|
||||
nx := flag.Bool("nx", false, "do not support extensions - support of extensions may cause extra allocation")
|
||||
|
||||
flag.Parse()
|
||||
err := Generate(*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)
|
||||
}
|
||||
}
|
3
vendor/github.com/ugorji/go/codec/codecgen/z.go
generated
vendored
Normal file
3
vendor/github.com/ugorji/go/codec/codecgen/z.go
generated
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
package main
|
||||
|
||||
const genCodecPath = "github.com/ugorji/go/codec"
|
2538
vendor/github.com/ugorji/go/codec/decode.go
generated
vendored
Normal file
2538
vendor/github.com/ugorji/go/codec/decode.go
generated
vendored
Normal file
File diff suppressed because it is too large
Load Diff
1295
vendor/github.com/ugorji/go/codec/encode.go
generated
vendored
Normal file
1295
vendor/github.com/ugorji/go/codec/encode.go
generated
vendored
Normal file
File diff suppressed because it is too large
Load Diff
34522
vendor/github.com/ugorji/go/codec/fast-path.generated.go
generated
vendored
Normal file
34522
vendor/github.com/ugorji/go/codec/fast-path.generated.go
generated
vendored
Normal file
File diff suppressed because it is too large
Load Diff
544
vendor/github.com/ugorji/go/codec/fast-path.go.tmpl
generated
vendored
Normal file
544
vendor/github.com/ugorji/go/codec/fast-path.go.tmpl
generated
vendored
Normal file
@@ -0,0 +1,544 @@
|
||||
// +build !notfastpath
|
||||
|
||||
// Copyright (c) 2012-2015 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 then 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,
|
||||
// - map of all builtin types to string or interface value
|
||||
// - symmetrical maps of all builtin types (e.g. str-str, uint8-uint8)
|
||||
// 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 {
|
||||
rtid uintptr
|
||||
rt reflect.Type
|
||||
encfn func(*Encoder, *codecFnInfo, reflect.Value)
|
||||
decfn func(*Decoder, *codecFnInfo, reflect.Value)
|
||||
}
|
||||
|
||||
type fastpathA [{{ .FastpathLen }}]fastpathE
|
||||
|
||||
func (x *fastpathA) index(rtid uintptr) int {
|
||||
// use binary search to grab the index (adapted from sort/search.go)
|
||||
h, i, j := 0, 0, {{ .FastpathLen }} // len(x)
|
||||
for i < j {
|
||||
h = i + (j-i)/2
|
||||
if x[h].rtid < rtid {
|
||||
i = h + 1
|
||||
} else {
|
||||
j = h
|
||||
}
|
||||
}
|
||||
if i < {{ .FastpathLen }} && x[i].rtid == rtid {
|
||||
return i
|
||||
}
|
||||
return -1
|
||||
}
|
||||
|
||||
type fastpathAslice []fastpathE
|
||||
|
||||
func (x fastpathAslice) Len() int { return len(x) }
|
||||
func (x fastpathAslice) Less(i, j int) bool { return x[i].rtid < x[j].rtid }
|
||||
func (x fastpathAslice) Swap(i, j int) { x[i], x[j] = x[j], x[i] }
|
||||
|
||||
var fastpathAV fastpathA
|
||||
|
||||
// due to possible initialization loop error, make fastpath in an init()
|
||||
func init() {
|
||||
i := 0
|
||||
fn := func(v interface{},
|
||||
fe func(*Encoder, *codecFnInfo, reflect.Value),
|
||||
fd func(*Decoder, *codecFnInfo, reflect.Value)) (f fastpathE) {
|
||||
xrt := reflect.TypeOf(v)
|
||||
xptr := rt2id(xrt)
|
||||
fastpathAV[i] = fastpathE{xptr, xrt, fe, fd}
|
||||
i++
|
||||
return
|
||||
}
|
||||
{{/* do not register []uint8 in fast-path */}}
|
||||
{{range .Values}}{{if not .Primitive}}{{if not .MapKey }}{{if ne .Elem "uint8"}}
|
||||
fn([]{{ .Elem }}(nil), (*Encoder).{{ .MethodNamePfx "fastpathEnc" false }}R, (*Decoder).{{ .MethodNamePfx "fastpathDec" false }}R){{end}}{{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(fastpathAV[:]))
|
||||
}
|
||||
|
||||
// -- encode
|
||||
|
||||
// -- -- fast path type switch
|
||||
func fastpathEncodeTypeSwitch(iv interface{}, e *Encoder) bool {
|
||||
switch v := iv.(type) {
|
||||
|
||||
{{range .Values}}{{if not .Primitive}}{{if not .MapKey }}{{if ne .Elem "uint8"}}
|
||||
case []{{ .Elem }}:
|
||||
fastpathTV.{{ .MethodNamePfx "Enc" false }}V(v, e)
|
||||
case *[]{{ .Elem }}:
|
||||
fastpathTV.{{ .MethodNamePfx "Enc" false }}V(*v, e){{/*
|
||||
*/}}{{end}}{{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 }}:
|
||||
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
|
||||
}
|
||||
|
||||
{{/*
|
||||
**** removing this block, as they are never called directly ****
|
||||
|
||||
|
||||
|
||||
**** removing this block, as they are never called directly ****
|
||||
|
||||
|
||||
|
||||
func fastpathEncodeTypeSwitchSlice(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 }}:
|
||||
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
|
||||
}
|
||||
|
||||
func fastpathEncodeTypeSwitchMap(iv interface{}, e *Encoder) bool {
|
||||
switch v := iv.(type) {
|
||||
{{range .Values}}{{if not .Primitive}}{{if .MapKey }}
|
||||
case map[{{ .MapKey }}]{{ .Elem }}:
|
||||
fastpathTV.{{ .MethodNamePfx "Enc" false }}V(v, e)
|
||||
case *map[{{ .MapKey }}]{{ .Elem }}:
|
||||
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
|
||||
}
|
||||
|
||||
|
||||
|
||||
**** removing this block, as they are never called directly ****
|
||||
|
||||
|
||||
|
||||
**** removing this block, as they are never called directly ****
|
||||
*/}}
|
||||
|
||||
// -- -- fast path functions
|
||||
{{range .Values}}{{if not .Primitive}}{{if not .MapKey }}
|
||||
func (e *Encoder) {{ .MethodNamePfx "fastpathEnc" false }}R(f *codecFnInfo, rv reflect.Value) {
|
||||
if f.ti.mbs {
|
||||
fastpathTV.{{ .MethodNamePfx "EncAsMap" false }}V(rv2i(rv).([]{{ .Elem }}), e)
|
||||
} else {
|
||||
fastpathTV.{{ .MethodNamePfx "Enc" false }}V(rv2i(rv).([]{{ .Elem }}), e)
|
||||
}
|
||||
}
|
||||
func (_ fastpathT) {{ .MethodNamePfx "Enc" false }}V(v []{{ .Elem }}, e *Encoder) {
|
||||
if v == nil { e.e.EncodeNil(); return }
|
||||
ee, esep := e.e, e.hh.hasElemSeparators()
|
||||
ee.WriteArrayStart(len(v))
|
||||
if esep {
|
||||
for _, v2 := range v {
|
||||
ee.WriteArrayElem()
|
||||
{{ encmd .Elem "v2"}}
|
||||
}
|
||||
} else {
|
||||
for _, v2 := range v {
|
||||
{{ encmd .Elem "v2"}}
|
||||
}
|
||||
} {{/*
|
||||
for _, v2 := range v {
|
||||
if esep { ee.WriteArrayElem() }
|
||||
{{ encmd .Elem "v2"}}
|
||||
} */}}
|
||||
ee.WriteArrayEnd()
|
||||
}
|
||||
func (_ fastpathT) {{ .MethodNamePfx "EncAsMap" false }}V(v []{{ .Elem }}, e *Encoder) {
|
||||
ee, esep := e.e, e.hh.hasElemSeparators()
|
||||
if len(v)%2 == 1 {
|
||||
e.errorf("mapBySlice requires even slice length, but got %v", len(v))
|
||||
return
|
||||
}
|
||||
ee.WriteMapStart(len(v) / 2)
|
||||
if esep {
|
||||
for j, v2 := range v {
|
||||
if j%2 == 0 {
|
||||
ee.WriteMapElemKey()
|
||||
} else {
|
||||
ee.WriteMapElemValue()
|
||||
}
|
||||
{{ encmd .Elem "v2"}}
|
||||
}
|
||||
} else {
|
||||
for _, v2 := range v {
|
||||
{{ encmd .Elem "v2"}}
|
||||
}
|
||||
} {{/*
|
||||
for j, v2 := range v {
|
||||
if esep {
|
||||
if j%2 == 0 {
|
||||
ee.WriteMapElemKey()
|
||||
} else {
|
||||
ee.WriteMapElemValue()
|
||||
}
|
||||
}
|
||||
{{ encmd .Elem "v2"}}
|
||||
} */}}
|
||||
ee.WriteMapEnd()
|
||||
}
|
||||
{{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 }
|
||||
ee, esep := e.e, e.hh.hasElemSeparators()
|
||||
ee.WriteMapStart(len(v))
|
||||
if e.h.Canonical {
|
||||
{{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([]bytesI, len(v))
|
||||
var i, l int
|
||||
var vp *bytesI {{/* put loop variables outside. seems currently needed for better perf */}}
|
||||
for k2, _ := range v {
|
||||
l = len(mksv)
|
||||
e2.MustEncode(k2)
|
||||
vp = &v2[i]
|
||||
vp.v = mksv[l:]
|
||||
vp.i = k2
|
||||
i++
|
||||
}
|
||||
sort.Sort(bytesISlice(v2))
|
||||
if esep {
|
||||
for j := range v2 {
|
||||
ee.WriteMapElemKey()
|
||||
e.asis(v2[j].v)
|
||||
ee.WriteMapElemValue()
|
||||
e.encode(v[v2[j].i])
|
||||
}
|
||||
} else {
|
||||
for j := range v2 {
|
||||
e.asis(v2[j].v)
|
||||
e.encode(v[v2[j].i])
|
||||
}
|
||||
} {{/*
|
||||
for j := range v2 {
|
||||
if esep { ee.WriteMapElemKey() }
|
||||
e.asis(v2[j].v)
|
||||
if esep { ee.WriteMapElemValue() }
|
||||
e.encode(v[v2[j].i])
|
||||
} */}} {{else}}{{ $x := sorttype .MapKey true}}v2 := make([]{{ $x }}, len(v))
|
||||
var i int
|
||||
for k, _ := range v {
|
||||
v2[i] = {{ $x }}(k)
|
||||
i++
|
||||
}
|
||||
sort.Sort({{ sorttype .MapKey false}}(v2))
|
||||
if esep {
|
||||
for _, k2 := range v2 {
|
||||
ee.WriteMapElemKey()
|
||||
{{if eq .MapKey "string"}}ee.EncodeString(cUTF8, k2){{else}}{{ $y := printf "%s(k2)" .MapKey }}{{ encmd .MapKey $y }}{{end}}
|
||||
ee.WriteMapElemValue()
|
||||
{{ $y := printf "v[%s(k2)]" .MapKey }}{{ encmd .Elem $y }}
|
||||
}
|
||||
} else {
|
||||
for _, k2 := range v2 {
|
||||
{{if eq .MapKey "string"}}ee.EncodeString(cUTF8, k2){{else}}{{ $y := printf "%s(k2)" .MapKey }}{{ encmd .MapKey $y }}{{end}}
|
||||
{{ $y := printf "v[%s(k2)]" .MapKey }}{{ encmd .Elem $y }}
|
||||
}
|
||||
} {{/*
|
||||
for _, k2 := range v2 {
|
||||
if esep { ee.WriteMapElemKey() }
|
||||
{{if eq .MapKey "string"}}ee.EncodeString(cUTF8, k2){{else}}{{ $y := printf "%s(k2)" .MapKey }}{{ encmd .MapKey $y }}{{end}}
|
||||
if esep { ee.WriteMapElemValue() }
|
||||
{{ $y := printf "v[%s(k2)]" .MapKey }}{{ encmd .Elem $y }}
|
||||
} */}} {{end}}
|
||||
} else {
|
||||
if esep {
|
||||
for k2, v2 := range v {
|
||||
ee.WriteMapElemKey()
|
||||
{{if eq .MapKey "string"}}ee.EncodeString(cUTF8, k2){{else}}{{ encmd .MapKey "k2"}}{{end}}
|
||||
ee.WriteMapElemValue()
|
||||
{{ encmd .Elem "v2"}}
|
||||
}
|
||||
} else {
|
||||
for k2, v2 := range v {
|
||||
{{if eq .MapKey "string"}}ee.EncodeString(cUTF8, k2){{else}}{{ encmd .MapKey "k2"}}{{end}}
|
||||
{{ encmd .Elem "v2"}}
|
||||
}
|
||||
} {{/*
|
||||
for k2, v2 := range v {
|
||||
if esep { ee.WriteMapElemKey() }
|
||||
{{if eq .MapKey "string"}}ee.EncodeString(cUTF8, k2){{else}}{{ encmd .MapKey "k2"}}{{end}}
|
||||
if esep { ee.WriteMapElemValue() }
|
||||
{{ encmd .Elem "v2"}}
|
||||
} */}}
|
||||
}
|
||||
ee.WriteMapEnd()
|
||||
}
|
||||
{{end}}{{end}}{{end}}
|
||||
|
||||
// -- decode
|
||||
|
||||
// -- -- fast path type switch
|
||||
func fastpathDecodeTypeSwitch(iv interface{}, d *Decoder) bool {
|
||||
var changed bool
|
||||
switch v := iv.(type) {
|
||||
{{range .Values}}{{if not .Primitive}}{{if not .MapKey }}{{if ne .Elem "uint8"}}
|
||||
case []{{ .Elem }}:
|
||||
var v2 []{{ .Elem }}
|
||||
v2, changed = fastpathTV.{{ .MethodNamePfx "Dec" false }}V(v, false, d)
|
||||
if changed && len(v) > 0 && len(v2) > 0 && !(len(v2) == len(v) && &v2[0] == &v[0]) {
|
||||
copy(v, v2)
|
||||
}
|
||||
case *[]{{ .Elem }}:
|
||||
var v2 []{{ .Elem }}
|
||||
v2, changed = fastpathTV.{{ .MethodNamePfx "Dec" false }}V(*v, true, d)
|
||||
if changed {
|
||||
*v = v2
|
||||
}{{/*
|
||||
*/}}{{end}}{{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 }}:
|
||||
fastpathTV.{{ .MethodNamePfx "Dec" false }}V(v, false, d)
|
||||
case *map[{{ .MapKey }}]{{ .Elem }}:
|
||||
var v2 map[{{ .MapKey }}]{{ .Elem }}
|
||||
v2, changed = fastpathTV.{{ .MethodNamePfx "Dec" false }}V(*v, true, d)
|
||||
if changed {
|
||||
*v = v2
|
||||
}{{/*
|
||||
*/}}{{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) {
|
||||
if array := f.seq == seqTypeArray; !array && rv.Kind() == reflect.Ptr {
|
||||
vp := rv2i(rv).(*[]{{ .Elem }})
|
||||
v, changed := fastpathTV.{{ .MethodNamePfx "Dec" false }}V(*vp, !array, d)
|
||||
if changed { *vp = v }
|
||||
} else {
|
||||
v := rv2i(rv).([]{{ .Elem }})
|
||||
v2, changed := fastpathTV.{{ .MethodNamePfx "Dec" false }}V(v, !array, d)
|
||||
if changed && len(v) > 0 && len(v2) > 0 && !(len(v2) == len(v) && &v2[0] == &v[0]) {
|
||||
copy(v, v2)
|
||||
}
|
||||
}
|
||||
}
|
||||
func (f fastpathT) {{ .MethodNamePfx "Dec" false }}X(vp *[]{{ .Elem }}, d *Decoder) {
|
||||
v, changed := f.{{ .MethodNamePfx "Dec" false }}V(*vp, true, d)
|
||||
if changed { *vp = v }
|
||||
}
|
||||
func (_ fastpathT) {{ .MethodNamePfx "Dec" false }}V(v []{{ .Elem }}, canChange bool, d *Decoder) (_ []{{ .Elem }}, changed bool) {
|
||||
dd := d.d{{/*
|
||||
// if dd.isContainerType(valueTypeNil) { dd.TryDecodeAsNil()
|
||||
*/}}
|
||||
slh, containerLenS := d.decSliceHelperStart()
|
||||
if containerLenS == 0 {
|
||||
if canChange {
|
||||
if v == nil { v = []{{ .Elem }}{} } else if len(v) != 0 { v = v[:0] }
|
||||
changed = true
|
||||
}
|
||||
slh.End()
|
||||
return v, changed
|
||||
}
|
||||
hasLen := containerLenS > 0
|
||||
var xlen int
|
||||
if hasLen && canChange {
|
||||
if containerLenS > cap(v) {
|
||||
xlen = decInferLen(containerLenS, d.h.MaxInitLen, {{ .Size }})
|
||||
if xlen <= cap(v) {
|
||||
v = v[:xlen]
|
||||
} else {
|
||||
v = make([]{{ .Elem }}, xlen)
|
||||
}
|
||||
changed = true
|
||||
} else if containerLenS != len(v) {
|
||||
v = v[:containerLenS]
|
||||
changed = true
|
||||
}
|
||||
}
|
||||
j := 0
|
||||
for ; (hasLen && j < containerLenS) || !(hasLen || dd.CheckBreak()); j++ {
|
||||
if j == 0 && len(v) == 0 && canChange {
|
||||
if hasLen {
|
||||
xlen = decInferLen(containerLenS, d.h.MaxInitLen, {{ .Size }})
|
||||
} else {
|
||||
xlen = 8
|
||||
}
|
||||
v = make([]{{ .Elem }}, xlen)
|
||||
changed = true
|
||||
}
|
||||
// if indefinite, etc, then expand the slice if necessary
|
||||
var decodeIntoBlank bool
|
||||
if j >= len(v) {
|
||||
if canChange {
|
||||
v = append(v, {{ zerocmd .Elem }})
|
||||
changed = true
|
||||
} else {
|
||||
d.arrayCannotExpand(len(v), j+1)
|
||||
decodeIntoBlank = true
|
||||
}
|
||||
}
|
||||
slh.ElemContainerState(j)
|
||||
if decodeIntoBlank {
|
||||
d.swallow()
|
||||
} else if dd.TryDecodeAsNil() {
|
||||
v[j] = {{ zerocmd .Elem }}
|
||||
} else {
|
||||
{{ if eq .Elem "interface{}" }}d.decode(&v[j]){{ else }}v[j] = {{ decmd .Elem }}{{ end }}
|
||||
}
|
||||
}
|
||||
if canChange {
|
||||
if j < len(v) {
|
||||
v = v[:j]
|
||||
changed = true
|
||||
} else if j == 0 && v == nil {
|
||||
v = make([]{{ .Elem }}, 0)
|
||||
changed = true
|
||||
}
|
||||
}
|
||||
slh.End()
|
||||
return v, changed
|
||||
}
|
||||
{{end}}{{end}}{{end}}
|
||||
|
||||
{{range .Values}}{{if not .Primitive}}{{if .MapKey }}
|
||||
{{/*
|
||||
Maps can change if they are
|
||||
- addressable (from a ptr)
|
||||
- settable (e.g. contained in an interface{})
|
||||
*/}}
|
||||
func (d *Decoder) {{ .MethodNamePfx "fastpathDec" false }}R(f *codecFnInfo, rv reflect.Value) {
|
||||
if rv.Kind() == reflect.Ptr {
|
||||
vp := rv2i(rv).(*map[{{ .MapKey }}]{{ .Elem }})
|
||||
v, changed := fastpathTV.{{ .MethodNamePfx "Dec" false }}V(*vp, true, d);
|
||||
if changed { *vp = v }
|
||||
} else {
|
||||
fastpathTV.{{ .MethodNamePfx "Dec" false }}V(rv2i(rv).(map[{{ .MapKey }}]{{ .Elem }}), false, d)
|
||||
}
|
||||
}
|
||||
func (f fastpathT) {{ .MethodNamePfx "Dec" false }}X(vp *map[{{ .MapKey }}]{{ .Elem }}, d *Decoder) {
|
||||
v, changed := f.{{ .MethodNamePfx "Dec" false }}V(*vp, true, d)
|
||||
if changed { *vp = v }
|
||||
}
|
||||
func (_ fastpathT) {{ .MethodNamePfx "Dec" false }}V(v map[{{ .MapKey }}]{{ .Elem }}, canChange bool,
|
||||
d *Decoder) (_ map[{{ .MapKey }}]{{ .Elem }}, changed bool) {
|
||||
dd, esep := d.d, d.hh.hasElemSeparators(){{/*
|
||||
// if dd.isContainerType(valueTypeNil) {dd.TryDecodeAsNil()
|
||||
*/}}
|
||||
containerLen := dd.ReadMapStart()
|
||||
if canChange && v == nil {
|
||||
xlen := decInferLen(containerLen, d.h.MaxInitLen, {{ .Size }})
|
||||
v = make(map[{{ .MapKey }}]{{ .Elem }}, xlen)
|
||||
changed = true
|
||||
}
|
||||
if containerLen == 0 {
|
||||
dd.ReadMapEnd()
|
||||
return v, changed
|
||||
}
|
||||
{{ if eq .Elem "interface{}" }}mapGet := v != nil && !d.h.MapValueReset && !d.h.InterfaceReset
|
||||
{{end}}var mk {{ .MapKey }}
|
||||
var mv {{ .Elem }}
|
||||
hasLen := containerLen > 0
|
||||
for j := 0; (hasLen && j < containerLen) || !(hasLen || dd.CheckBreak()); j++ {
|
||||
if esep { dd.ReadMapElemKey() }
|
||||
{{ if eq .MapKey "interface{}" }}mk = nil
|
||||
d.decode(&mk)
|
||||
if bv, bok := mk.([]byte); bok {
|
||||
mk = d.string(bv) {{/* // maps cannot have []byte as key. switch to string. */}}
|
||||
}{{ else }}mk = {{ decmd .MapKey }}{{ end }}
|
||||
if esep { dd.ReadMapElemValue() }
|
||||
if dd.TryDecodeAsNil() {
|
||||
if v == nil {} else if d.h.DeleteOnNilMapValue { delete(v, mk) } else { v[mk] = {{ zerocmd .Elem }} }
|
||||
continue
|
||||
}
|
||||
{{ if eq .Elem "interface{}" }}if mapGet { mv = v[mk] } else { mv = nil }
|
||||
d.decode(&mv){{ else }}mv = {{ decmd .Elem }}{{ end }}
|
||||
if v != nil { v[mk] = mv }
|
||||
}
|
||||
dd.ReadMapEnd()
|
||||
return v, changed
|
||||
}
|
||||
{{end}}{{end}}{{end}}
|
47
vendor/github.com/ugorji/go/codec/fast-path.not.go
generated
vendored
Normal file
47
vendor/github.com/ugorji/go/codec/fast-path.not.go
generated
vendored
Normal file
@@ -0,0 +1,47 @@
|
||||
// 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.
|
||||
|
||||
// +build 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 (x fastpathA) index(rtid uintptr) int { return -1 }
|
||||
|
||||
func (_ fastpathT) DecSliceUint8V(v []uint8, canChange bool, d *Decoder) (_ []uint8, changed bool) {
|
||||
fn := d.cfer().get(uint8SliceTyp, true, true)
|
||||
d.kSlice(&fn.i, reflect.ValueOf(&v).Elem())
|
||||
return v, true
|
||||
}
|
||||
|
||||
var fastpathAV fastpathA
|
||||
var fastpathTV fastpathT
|
||||
|
||||
// ----
|
||||
type TestMammoth2Wrapper struct{} // to allow testMammoth work in notfastpath mode
|
77
vendor/github.com/ugorji/go/codec/gen-dec-array.go.tmpl
generated
vendored
Normal file
77
vendor/github.com/ugorji/go/codec/gen-dec-array.go.tmpl
generated
vendored
Normal file
@@ -0,0 +1,77 @@
|
||||
{{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"}}{{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
|
||||
} {{end}} {{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 "hl"}} && {{var "j"}} < {{var "l"}}) || !({{var "hl"}} || r.CheckBreak()); {{var "j"}}++ {
|
||||
{{if not isArray}} if {{var "j"}} == 0 && len({{var "v"}}) == 0 {
|
||||
if {{var "hl"}} {
|
||||
{{var "rl"}} = z.DecInferLen({{var "l"}}, z.DecBasicHandle().MaxInitLen, {{ .Size }})
|
||||
} else {
|
||||
{{var "rl"}} = 8
|
||||
}
|
||||
{{var "v"}} = make([]{{ .Typ }}, {{var "rl"}})
|
||||
{{var "c"}} = true
|
||||
}{{end}}
|
||||
{{var "h"}}.ElemContainerState({{var "j"}})
|
||||
{{/* {{var "dn"}} = r.TryDecodeAsNil() */}}
|
||||
{{if isChan}}{{ $x := printf "%[1]vv%[2]v" .TempVar .Rand }}var {{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"}} = make([]{{ .Typ }}, 0)
|
||||
{{var "c"}} = true
|
||||
} {{end}}
|
||||
}
|
||||
{{var "h"}}.End()
|
||||
{{if not isArray }}if {{var "c"}} {
|
||||
*{{ .Varname }} = {{var "v"}}
|
||||
}{{end}}
|
||||
|
42
vendor/github.com/ugorji/go/codec/gen-dec-map.go.tmpl
generated
vendored
Normal file
42
vendor/github.com/ugorji/go/codec/gen-dec-map.go.tmpl
generated
vendored
Normal file
@@ -0,0 +1,42 @@
|
||||
{{var "v"}} := *{{ .Varname }}
|
||||
{{var "l"}} := r.ReadMapStart()
|
||||
{{var "bh"}} := z.DecBasicHandle()
|
||||
if {{var "v"}} == nil {
|
||||
{{var "rl"}} := z.DecInferLen({{var "l"}}, {{var "bh"}}.MaxInitLen, {{ .Size }})
|
||||
{{var "v"}} = make(map[{{ .KTyp }}]{{ .Typ }}, {{var "rl"}})
|
||||
*{{ .Varname }} = {{var "v"}}
|
||||
}
|
||||
var {{var "mk"}} {{ .KTyp }}
|
||||
var {{var "mv"}} {{ .Typ }}
|
||||
var {{var "mg"}}, {{var "mdn"}} {{if decElemKindPtr}}, {{var "ms"}}, {{var "mok"}}{{end}} bool
|
||||
if {{var "bh"}}.MapValueReset {
|
||||
{{if decElemKindPtr}}{{var "mg"}} = true
|
||||
{{else if decElemKindIntf}}if !{{var "bh"}}.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"}} || r.CheckBreak()); {{var "j"}}++ {
|
||||
r.ReadMapElemKey() {{/* z.DecSendContainerState(codecSelfer_containerMapKey{{ .Sfx }}) */}}
|
||||
{{ $x := printf "%vmk%v" .TempVar .Rand }}{{ decLineVarK $x }}
|
||||
{{ if eq .KTyp "interface{}" }}{{/* // special case if a byte array. */}}if {{var "bv"}}, {{var "bok"}} := {{var "mk"}}.([]byte); {{var "bok"}} {
|
||||
{{var "mk"}} = string({{var "bv"}})
|
||||
}{{ end }}{{if decElemKindPtr}}
|
||||
{{var "ms"}} = true{{end}}
|
||||
if {{var "mg"}} {
|
||||
{{if decElemKindPtr}}{{var "mv"}}, {{var "mok"}} = {{var "v"}}[{{var "mk"}}]
|
||||
if {{var "mok"}} {
|
||||
{{var "ms"}} = false
|
||||
} {{else}}{{var "mv"}} = {{var "v"}}[{{var "mk"}}] {{end}}
|
||||
} {{if not decElemKindImmutable}}else { {{var "mv"}} = {{decElemZero}} }{{end}}
|
||||
r.ReadMapElemValue() {{/* z.DecSendContainerState(codecSelfer_containerMapValue{{ .Sfx }}) */}}
|
||||
{{var "mdn"}} = false
|
||||
{{ $x := printf "%vmv%v" .TempVar .Rand }}{{ $y := printf "%vmdn%v" .TempVar .Rand }}{{ decLineVar $x $y }}
|
||||
if {{var "mdn"}} {
|
||||
if {{ var "bh" }}.DeleteOnNilMapValue { delete({{var "v"}}, {{var "mk"}}) } else { {{var "v"}}[{{var "mk"}}] = {{decElemZero}} }
|
||||
} else if {{if decElemKindPtr}} {{var "ms"}} && {{end}} {{var "v"}} != nil {
|
||||
{{var "v"}}[{{var "mk"}}] = {{var "mv"}}
|
||||
}
|
||||
}
|
||||
} // else len==0: TODO: Should we clear map entries?
|
||||
r.ReadMapEnd() {{/* z.DecSendContainerState(codecSelfer_containerMapEnd{{ .Sfx }}) */}}
|
335
vendor/github.com/ugorji/go/codec/gen-helper.generated.go
generated
vendored
Normal file
335
vendor/github.com/ugorji/go/codec/gen-helper.generated.go
generated
vendored
Normal file
@@ -0,0 +1,335 @@
|
||||
/* // +build ignore */
|
||||
|
||||
// Copyright (c) 2012-2015 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 = 8
|
||||
|
||||
// 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. IT WILL CHANGE CONTINOUSLY WITHOUT NOTICE.
|
||||
func GenHelperEncoder(e *Encoder) (ge genHelperEncoder, ee genHelperEncDriver) {
|
||||
ge = genHelperEncoder{e: e}
|
||||
ee = genHelperEncDriver{encDriver: e.e}
|
||||
return
|
||||
}
|
||||
|
||||
// GenHelperDecoder is exported so that it can be used externally by codecgen.
|
||||
//
|
||||
// Library users: DO NOT USE IT DIRECTLY. IT WILL CHANGE CONTINOUSLY WITHOUT NOTICE.
|
||||
func GenHelperDecoder(d *Decoder) (gd genHelperDecoder, dd genHelperDecDriver) {
|
||||
gd = genHelperDecoder{d: d}
|
||||
dd = genHelperDecDriver{decDriver: d.d}
|
||||
return
|
||||
}
|
||||
|
||||
type genHelperEncDriver struct {
|
||||
encDriver
|
||||
}
|
||||
|
||||
func (x genHelperEncDriver) EncodeBuiltin(rt uintptr, v interface{}) {}
|
||||
func (x genHelperEncDriver) EncStructFieldKey(keyType valueType, s string) {
|
||||
encStructFieldKey(x.encDriver, keyType, s)
|
||||
}
|
||||
func (x genHelperEncDriver) EncodeSymbol(s string) {
|
||||
x.encDriver.EncodeString(cUTF8, s)
|
||||
}
|
||||
|
||||
type genHelperDecDriver struct {
|
||||
decDriver
|
||||
C checkOverflow
|
||||
}
|
||||
|
||||
func (x genHelperDecDriver) DecodeBuiltin(rt uintptr, v interface{}) {}
|
||||
func (x genHelperDecDriver) DecStructFieldKey(keyType valueType, buf *[decScratchByteArrayLen]byte) []byte {
|
||||
return decStructFieldKey(x.decDriver, keyType, buf)
|
||||
}
|
||||
func (x genHelperDecDriver) DecodeInt(bitsize uint8) (i int64) {
|
||||
return x.C.IntV(x.decDriver.DecodeInt64(), bitsize)
|
||||
}
|
||||
func (x genHelperDecDriver) DecodeUint(bitsize uint8) (ui uint64) {
|
||||
return x.C.UintV(x.decDriver.DecodeUint64(), bitsize)
|
||||
}
|
||||
func (x genHelperDecDriver) DecodeFloat(chkOverflow32 bool) (f float64) {
|
||||
f = x.DecodeFloat64()
|
||||
if chkOverflow32 && chkOvf.Float32(f) {
|
||||
panicv.errorf("float32 overflow: %v", f)
|
||||
}
|
||||
return
|
||||
}
|
||||
func (x genHelperDecDriver) DecodeFloat32As64() (f float64) {
|
||||
f = x.DecodeFloat64()
|
||||
if chkOvf.Float32(f) {
|
||||
panicv.errorf("float32 overflow: %v", f)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
|
||||
type genHelperEncoder struct {
|
||||
M must
|
||||
e *Encoder
|
||||
F fastpathT
|
||||
}
|
||||
|
||||
// FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
|
||||
type genHelperDecoder struct {
|
||||
C checkOverflow
|
||||
d *Decoder
|
||||
F fastpathT
|
||||
}
|
||||
|
||||
// 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{}) {
|
||||
// println(">>>>>>>>> EncFallback")
|
||||
// f.e.encodeI(iv, false, false)
|
||||
f.e.encodeValue(reflect.ValueOf(iv), nil, false)
|
||||
}
|
||||
|
||||
// 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.marshal(bs, fnerr, false, cUTF8)
|
||||
}
|
||||
|
||||
// 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.marshal(bs, fnerr, true, cUTF8)
|
||||
}
|
||||
|
||||
// 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.marshal(bs, fnerr, false, cRAW)
|
||||
}
|
||||
|
||||
// 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*
|
||||
//
|
||||
// Deprecated: builtin no longer supported - so we make this method a no-op,
|
||||
// but leave in-place so that old generated files continue to work without regeneration.
|
||||
func (f genHelperEncoder) TimeRtidIfBinc() (v uintptr) { return }
|
||||
|
||||
// func (f genHelperEncoder) TimeRtidIfBinc() uintptr {
|
||||
// if _, ok := f.e.hh.(*BincHandle); ok {
|
||||
// return timeTypId
|
||||
// }
|
||||
// }
|
||||
|
||||
// FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
|
||||
func (f genHelperEncoder) I2Rtid(v interface{}) uintptr {
|
||||
return i2rtid(v)
|
||||
}
|
||||
|
||||
// FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
|
||||
func (f genHelperEncoder) Extension(rtid uintptr) (xfn *extTypeTagFn) {
|
||||
return f.e.h.getExt(rtid)
|
||||
}
|
||||
|
||||
// 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.tag, xfFn.ext, f.e)
|
||||
}
|
||||
|
||||
// FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
|
||||
//
|
||||
// Deprecated: No longer used,
|
||||
// but leave in-place so that old generated files continue to work without regeneration.
|
||||
func (f genHelperEncoder) HasExtensions() bool {
|
||||
return len(f.e.h.extHandle) != 0
|
||||
}
|
||||
|
||||
// FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
|
||||
//
|
||||
// Deprecated: No longer used,
|
||||
// but leave in-place so that old generated files continue to work without regeneration.
|
||||
func (f genHelperEncoder) EncExt(v interface{}) (r bool) {
|
||||
if xfFn := f.e.h.getExt(i2rtid(v)); xfFn != nil {
|
||||
f.e.e.EncodeExt(v, xfFn.tag, xfFn.ext, f.e)
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
// ---------------- 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) {
|
||||
// println(">>>>>>>>> DecFallback")
|
||||
rv := reflect.ValueOf(iv)
|
||||
if chkPtr {
|
||||
rv = f.d.ensureDecodeable(rv)
|
||||
}
|
||||
f.d.decodeValue(rv, nil, false)
|
||||
// f.d.decodeValueFallback(rv)
|
||||
}
|
||||
|
||||
// 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) {
|
||||
fnerr := tm.UnmarshalText(f.d.d.DecodeStringAsBytes())
|
||||
if fnerr != nil {
|
||||
panic(fnerr)
|
||||
}
|
||||
}
|
||||
|
||||
// FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
|
||||
func (f genHelperDecoder) DecJSONUnmarshal(tm jsonUnmarshaler) {
|
||||
// bs := f.dd.DecodeStringAsBytes()
|
||||
// grab the bytes to be read, as UnmarshalJSON needs the full JSON so as to unmarshal it itself.
|
||||
fnerr := tm.UnmarshalJSON(f.d.nextValueBytes())
|
||||
if fnerr != nil {
|
||||
panic(fnerr)
|
||||
}
|
||||
}
|
||||
|
||||
// FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
|
||||
func (f genHelperDecoder) DecBinaryUnmarshal(bm encoding.BinaryUnmarshaler) {
|
||||
fnerr := bm.UnmarshalBinary(f.d.d.DecodeBytes(nil, true))
|
||||
if fnerr != nil {
|
||||
panic(fnerr)
|
||||
}
|
||||
}
|
||||
|
||||
// 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*
|
||||
//
|
||||
// Deprecated: builtin no longer supported - so we make this method a no-op,
|
||||
// but leave in-place so that old generated files continue to work without regeneration.
|
||||
func (f genHelperDecoder) TimeRtidIfBinc() (v uintptr) { return }
|
||||
|
||||
// func (f genHelperDecoder) TimeRtidIfBinc() uintptr {
|
||||
// // Note: builtin is no longer supported - so make this a no-op
|
||||
// if _, ok := f.d.hh.(*BincHandle); ok {
|
||||
// return timeTypId
|
||||
// }
|
||||
// return 0
|
||||
// }
|
||||
|
||||
// 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(rtid uintptr) (xfn *extTypeTagFn) {
|
||||
return f.d.h.getExt(rtid)
|
||||
}
|
||||
|
||||
// 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.tag, xfFn.ext)
|
||||
}
|
||||
|
||||
// FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
|
||||
//
|
||||
// Deprecated: No longer used,
|
||||
// but leave in-place so that old generated files continue to work without regeneration.
|
||||
func (f genHelperDecoder) HasExtensions() bool {
|
||||
return len(f.d.h.extHandle) != 0
|
||||
}
|
||||
|
||||
// FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
|
||||
//
|
||||
// Deprecated: No longer used,
|
||||
// but leave in-place so that old generated files continue to work without regeneration.
|
||||
func (f genHelperDecoder) DecExt(v interface{}) (r bool) {
|
||||
if xfFn := f.d.h.getExt(i2rtid(v)); xfFn != nil {
|
||||
f.d.d.DecodeExt(v, xfFn.tag, xfFn.ext)
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
// 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*
|
||||
//
|
||||
// Deprecated: no longer used,
|
||||
// but leave in-place so that old generated files continue to work without regeneration.
|
||||
func (f genHelperDecoder) StringView(v []byte) string { return stringView(v) }
|
302
vendor/github.com/ugorji/go/codec/gen-helper.go.tmpl
generated
vendored
Normal file
302
vendor/github.com/ugorji/go/codec/gen-helper.go.tmpl
generated
vendored
Normal file
@@ -0,0 +1,302 @@
|
||||
/* // +build ignore */
|
||||
|
||||
// Copyright (c) 2012-2015 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. IT WILL CHANGE CONTINOUSLY WITHOUT NOTICE.
|
||||
func GenHelperEncoder(e *Encoder) (ge genHelperEncoder, ee genHelperEncDriver) {
|
||||
ge = genHelperEncoder{e: e}
|
||||
ee = genHelperEncDriver{encDriver: e.e}
|
||||
return
|
||||
}
|
||||
|
||||
// GenHelperDecoder is exported so that it can be used externally by codecgen.
|
||||
//
|
||||
// Library users: DO NOT USE IT DIRECTLY. IT WILL CHANGE CONTINOUSLY WITHOUT NOTICE.
|
||||
func GenHelperDecoder(d *Decoder) (gd genHelperDecoder, dd genHelperDecDriver) {
|
||||
gd = genHelperDecoder{d: d}
|
||||
dd = genHelperDecDriver{decDriver: d.d}
|
||||
return
|
||||
}
|
||||
|
||||
type genHelperEncDriver struct {
|
||||
encDriver
|
||||
}
|
||||
|
||||
func (x genHelperEncDriver) EncodeBuiltin(rt uintptr, v interface{}) {}
|
||||
func (x genHelperEncDriver) EncStructFieldKey(keyType valueType, s string) {
|
||||
encStructFieldKey(x.encDriver, keyType, s)
|
||||
}
|
||||
func (x genHelperEncDriver) EncodeSymbol(s string) {
|
||||
x.encDriver.EncodeString(cUTF8, s)
|
||||
}
|
||||
|
||||
type genHelperDecDriver struct {
|
||||
decDriver
|
||||
C checkOverflow
|
||||
}
|
||||
|
||||
func (x genHelperDecDriver) DecodeBuiltin(rt uintptr, v interface{}) {}
|
||||
func (x genHelperDecDriver) DecStructFieldKey(keyType valueType, buf *[decScratchByteArrayLen]byte) []byte {
|
||||
return decStructFieldKey(x.decDriver, keyType, buf)
|
||||
}
|
||||
func (x genHelperDecDriver) DecodeInt(bitsize uint8) (i int64) {
|
||||
return x.C.IntV(x.decDriver.DecodeInt64(), bitsize)
|
||||
}
|
||||
func (x genHelperDecDriver) DecodeUint(bitsize uint8) (ui uint64) {
|
||||
return x.C.UintV(x.decDriver.DecodeUint64(), bitsize)
|
||||
}
|
||||
func (x genHelperDecDriver) DecodeFloat(chkOverflow32 bool) (f float64) {
|
||||
f = x.DecodeFloat64()
|
||||
if chkOverflow32 && chkOvf.Float32(f) {
|
||||
panicv.errorf("float32 overflow: %v", f)
|
||||
}
|
||||
return
|
||||
}
|
||||
func (x genHelperDecDriver) DecodeFloat32As64() (f float64) {
|
||||
f = x.DecodeFloat64()
|
||||
if chkOvf.Float32(f) {
|
||||
panicv.errorf("float32 overflow: %v", f)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
|
||||
type genHelperEncoder struct {
|
||||
M must
|
||||
e *Encoder
|
||||
F fastpathT
|
||||
}
|
||||
|
||||
// FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
|
||||
type genHelperDecoder struct {
|
||||
C checkOverflow
|
||||
d *Decoder
|
||||
F fastpathT
|
||||
}
|
||||
|
||||
// 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{}) {
|
||||
// println(">>>>>>>>> EncFallback")
|
||||
// f.e.encodeI(iv, false, false)
|
||||
f.e.encodeValue(reflect.ValueOf(iv), nil, false)
|
||||
}
|
||||
// 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.marshal(bs, fnerr, false, cUTF8)
|
||||
}
|
||||
// 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.marshal(bs, fnerr, true, cUTF8)
|
||||
}
|
||||
// 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.marshal(bs, fnerr, false, cRAW)
|
||||
}
|
||||
// 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*
|
||||
//
|
||||
// Deprecated: builtin no longer supported - so we make this method a no-op,
|
||||
// but leave in-place so that old generated files continue to work without regeneration.
|
||||
func (f genHelperEncoder) TimeRtidIfBinc() (v uintptr) { return }
|
||||
// func (f genHelperEncoder) TimeRtidIfBinc() uintptr {
|
||||
// if _, ok := f.e.hh.(*BincHandle); ok {
|
||||
// return timeTypId
|
||||
// }
|
||||
// }
|
||||
|
||||
// FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
|
||||
func (f genHelperEncoder) I2Rtid(v interface{}) uintptr {
|
||||
return i2rtid(v)
|
||||
}
|
||||
// FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
|
||||
func (f genHelperEncoder) Extension(rtid uintptr) (xfn *extTypeTagFn) {
|
||||
return f.e.h.getExt(rtid)
|
||||
}
|
||||
// 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.tag, xfFn.ext, f.e)
|
||||
}
|
||||
// FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
|
||||
//
|
||||
// Deprecated: No longer used,
|
||||
// but leave in-place so that old generated files continue to work without regeneration.
|
||||
func (f genHelperEncoder) HasExtensions() bool {
|
||||
return len(f.e.h.extHandle) != 0
|
||||
}
|
||||
// FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
|
||||
//
|
||||
// Deprecated: No longer used,
|
||||
// but leave in-place so that old generated files continue to work without regeneration.
|
||||
func (f genHelperEncoder) EncExt(v interface{}) (r bool) {
|
||||
if xfFn := f.e.h.getExt(i2rtid(v)); xfFn != nil {
|
||||
f.e.e.EncodeExt(v, xfFn.tag, xfFn.ext, f.e)
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
// ---------------- 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) {
|
||||
// println(">>>>>>>>> DecFallback")
|
||||
rv := reflect.ValueOf(iv)
|
||||
if chkPtr {
|
||||
rv = f.d.ensureDecodeable(rv)
|
||||
}
|
||||
f.d.decodeValue(rv, nil, false)
|
||||
// f.d.decodeValueFallback(rv)
|
||||
}
|
||||
// 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) {
|
||||
fnerr := tm.UnmarshalText(f.d.d.DecodeStringAsBytes())
|
||||
if fnerr != nil {
|
||||
panic(fnerr)
|
||||
}
|
||||
}
|
||||
// FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
|
||||
func (f genHelperDecoder) DecJSONUnmarshal(tm jsonUnmarshaler) {
|
||||
// bs := f.dd.DecodeStringAsBytes()
|
||||
// grab the bytes to be read, as UnmarshalJSON needs the full JSON so as to unmarshal it itself.
|
||||
fnerr := tm.UnmarshalJSON(f.d.nextValueBytes())
|
||||
if fnerr != nil {
|
||||
panic(fnerr)
|
||||
}
|
||||
}
|
||||
// FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
|
||||
func (f genHelperDecoder) DecBinaryUnmarshal(bm encoding.BinaryUnmarshaler) {
|
||||
fnerr := bm.UnmarshalBinary(f.d.d.DecodeBytes(nil, true))
|
||||
if fnerr != nil {
|
||||
panic(fnerr)
|
||||
}
|
||||
}
|
||||
// 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*
|
||||
//
|
||||
// Deprecated: builtin no longer supported - so we make this method a no-op,
|
||||
// but leave in-place so that old generated files continue to work without regeneration.
|
||||
func (f genHelperDecoder) TimeRtidIfBinc() (v uintptr) { return }
|
||||
// func (f genHelperDecoder) TimeRtidIfBinc() uintptr {
|
||||
// // Note: builtin is no longer supported - so make this a no-op
|
||||
// if _, ok := f.d.hh.(*BincHandle); ok {
|
||||
// return timeTypId
|
||||
// }
|
||||
// return 0
|
||||
// }
|
||||
|
||||
// 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(rtid uintptr) (xfn *extTypeTagFn) {
|
||||
return f.d.h.getExt(rtid)
|
||||
}
|
||||
// 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.tag, xfFn.ext)
|
||||
}
|
||||
// FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
|
||||
//
|
||||
// Deprecated: No longer used,
|
||||
// but leave in-place so that old generated files continue to work without regeneration.
|
||||
func (f genHelperDecoder) HasExtensions() bool {
|
||||
return len(f.d.h.extHandle) != 0
|
||||
}
|
||||
// FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
|
||||
//
|
||||
// Deprecated: No longer used,
|
||||
// but leave in-place so that old generated files continue to work without regeneration.
|
||||
func (f genHelperDecoder) DecExt(v interface{}) (r bool) {
|
||||
if xfFn := f.d.h.getExt(i2rtid(v)); xfFn != nil {
|
||||
f.d.d.DecodeExt(v, xfFn.tag, xfFn.ext)
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
// 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*
|
||||
//
|
||||
// Deprecated: no longer used,
|
||||
// but leave in-place so that old generated files continue to work without regeneration.
|
||||
func (f genHelperDecoder) StringView(v []byte) string { return stringView(v) }
|
||||
|
133
vendor/github.com/ugorji/go/codec/gen.generated.go
generated
vendored
Normal file
133
vendor/github.com/ugorji/go/codec/gen.generated.go
generated
vendored
Normal file
@@ -0,0 +1,133 @@
|
||||
// +build codecgen.exec
|
||||
|
||||
// Copyright (c) 2012-2015 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"}} := r.ReadMapStart()
|
||||
{{var "bh"}} := z.DecBasicHandle()
|
||||
if {{var "v"}} == nil {
|
||||
{{var "rl"}} := z.DecInferLen({{var "l"}}, {{var "bh"}}.MaxInitLen, {{ .Size }})
|
||||
{{var "v"}} = make(map[{{ .KTyp }}]{{ .Typ }}, {{var "rl"}})
|
||||
*{{ .Varname }} = {{var "v"}}
|
||||
}
|
||||
var {{var "mk"}} {{ .KTyp }}
|
||||
var {{var "mv"}} {{ .Typ }}
|
||||
var {{var "mg"}}, {{var "mdn"}} {{if decElemKindPtr}}, {{var "ms"}}, {{var "mok"}}{{end}} bool
|
||||
if {{var "bh"}}.MapValueReset {
|
||||
{{if decElemKindPtr}}{{var "mg"}} = true
|
||||
{{else if decElemKindIntf}}if !{{var "bh"}}.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"}} || r.CheckBreak()); {{var "j"}}++ {
|
||||
r.ReadMapElemKey() {{/* z.DecSendContainerState(codecSelfer_containerMapKey{{ .Sfx }}) */}}
|
||||
{{ $x := printf "%vmk%v" .TempVar .Rand }}{{ decLineVarK $x }}
|
||||
{{ if eq .KTyp "interface{}" }}{{/* // special case if a byte array. */}}if {{var "bv"}}, {{var "bok"}} := {{var "mk"}}.([]byte); {{var "bok"}} {
|
||||
{{var "mk"}} = string({{var "bv"}})
|
||||
}{{ end }}{{if decElemKindPtr}}
|
||||
{{var "ms"}} = true{{end}}
|
||||
if {{var "mg"}} {
|
||||
{{if decElemKindPtr}}{{var "mv"}}, {{var "mok"}} = {{var "v"}}[{{var "mk"}}]
|
||||
if {{var "mok"}} {
|
||||
{{var "ms"}} = false
|
||||
} {{else}}{{var "mv"}} = {{var "v"}}[{{var "mk"}}] {{end}}
|
||||
} {{if not decElemKindImmutable}}else { {{var "mv"}} = {{decElemZero}} }{{end}}
|
||||
r.ReadMapElemValue() {{/* z.DecSendContainerState(codecSelfer_containerMapValue{{ .Sfx }}) */}}
|
||||
{{var "mdn"}} = false
|
||||
{{ $x := printf "%vmv%v" .TempVar .Rand }}{{ $y := printf "%vmdn%v" .TempVar .Rand }}{{ decLineVar $x $y }}
|
||||
if {{var "mdn"}} {
|
||||
if {{ var "bh" }}.DeleteOnNilMapValue { delete({{var "v"}}, {{var "mk"}}) } else { {{var "v"}}[{{var "mk"}}] = {{decElemZero}} }
|
||||
} else if {{if decElemKindPtr}} {{var "ms"}} && {{end}} {{var "v"}} != nil {
|
||||
{{var "v"}}[{{var "mk"}}] = {{var "mv"}}
|
||||
}
|
||||
}
|
||||
} // else len==0: TODO: Should we clear map entries?
|
||||
r.ReadMapEnd() {{/* z.DecSendContainerState(codecSelfer_containerMapEnd{{ .Sfx }}) */}}
|
||||
`
|
||||
|
||||
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"}}{{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
|
||||
} {{end}} {{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 "hl"}} && {{var "j"}} < {{var "l"}}) || !({{var "hl"}} || r.CheckBreak()); {{var "j"}}++ {
|
||||
{{if not isArray}} if {{var "j"}} == 0 && len({{var "v"}}) == 0 {
|
||||
if {{var "hl"}} {
|
||||
{{var "rl"}} = z.DecInferLen({{var "l"}}, z.DecBasicHandle().MaxInitLen, {{ .Size }})
|
||||
} else {
|
||||
{{var "rl"}} = 8
|
||||
}
|
||||
{{var "v"}} = make([]{{ .Typ }}, {{var "rl"}})
|
||||
{{var "c"}} = true
|
||||
}{{end}}
|
||||
{{var "h"}}.ElemContainerState({{var "j"}})
|
||||
{{/* {{var "dn"}} = r.TryDecodeAsNil() */}}
|
||||
{{if isChan}}{{ $x := printf "%[1]vv%[2]v" .TempVar .Rand }}var {{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"}} = make([]{{ .Typ }}, 0)
|
||||
{{var "c"}} = true
|
||||
} {{end}}
|
||||
}
|
||||
{{var "h"}}.End()
|
||||
{{if not isArray }}if {{var "c"}} {
|
||||
*{{ .Varname }} = {{var "v"}}
|
||||
}{{end}}
|
||||
|
||||
`
|
2119
vendor/github.com/ugorji/go/codec/gen.go
generated
vendored
Normal file
2119
vendor/github.com/ugorji/go/codec/gen.go
generated
vendored
Normal file
File diff suppressed because it is too large
Load Diff
14
vendor/github.com/ugorji/go/codec/goversion_arrayof_gte_go15.go
generated
vendored
Normal file
14
vendor/github.com/ugorji/go/codec/goversion_arrayof_gte_go15.go
generated
vendored
Normal file
@@ -0,0 +1,14 @@
|
||||
// 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.
|
||||
|
||||
// +build go1.5
|
||||
|
||||
package codec
|
||||
|
||||
import "reflect"
|
||||
|
||||
const reflectArrayOfSupported = true
|
||||
|
||||
func reflectArrayOf(count int, elem reflect.Type) reflect.Type {
|
||||
return reflect.ArrayOf(count, elem)
|
||||
}
|
14
vendor/github.com/ugorji/go/codec/goversion_arrayof_lt_go15.go
generated
vendored
Normal file
14
vendor/github.com/ugorji/go/codec/goversion_arrayof_lt_go15.go
generated
vendored
Normal file
@@ -0,0 +1,14 @@
|
||||
// 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.
|
||||
|
||||
// +build !go1.5
|
||||
|
||||
package codec
|
||||
|
||||
import "reflect"
|
||||
|
||||
const reflectArrayOfSupported = false
|
||||
|
||||
func reflectArrayOf(count int, elem reflect.Type) reflect.Type {
|
||||
panic("codec: reflect.ArrayOf unsupported in this go version")
|
||||
}
|
15
vendor/github.com/ugorji/go/codec/goversion_makemap_gte_go19.go
generated
vendored
Normal file
15
vendor/github.com/ugorji/go/codec/goversion_makemap_gte_go19.go
generated
vendored
Normal file
@@ -0,0 +1,15 @@
|
||||
// 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.
|
||||
|
||||
// +build go1.9
|
||||
|
||||
package codec
|
||||
|
||||
import "reflect"
|
||||
|
||||
func makeMapReflect(t reflect.Type, size int) reflect.Value {
|
||||
if size < 0 {
|
||||
return reflect.MakeMapWithSize(t, 4)
|
||||
}
|
||||
return reflect.MakeMapWithSize(t, size)
|
||||
}
|
12
vendor/github.com/ugorji/go/codec/goversion_makemap_lt_go19.go
generated
vendored
Normal file
12
vendor/github.com/ugorji/go/codec/goversion_makemap_lt_go19.go
generated
vendored
Normal file
@@ -0,0 +1,12 @@
|
||||
// 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.
|
||||
|
||||
// +build !go1.9
|
||||
|
||||
package codec
|
||||
|
||||
import "reflect"
|
||||
|
||||
func makeMapReflect(t reflect.Type, size int) reflect.Value {
|
||||
return reflect.MakeMap(t)
|
||||
}
|
8
vendor/github.com/ugorji/go/codec/goversion_unexportedembeddedptr_gte_go110.go
generated
vendored
Normal file
8
vendor/github.com/ugorji/go/codec/goversion_unexportedembeddedptr_gte_go110.go
generated
vendored
Normal file
@@ -0,0 +1,8 @@
|
||||
// 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.
|
||||
|
||||
// +build go1.10
|
||||
|
||||
package codec
|
||||
|
||||
const allowSetUnexportedEmbeddedPtr = false
|
8
vendor/github.com/ugorji/go/codec/goversion_unexportedembeddedptr_lt_go110.go
generated
vendored
Normal file
8
vendor/github.com/ugorji/go/codec/goversion_unexportedembeddedptr_lt_go110.go
generated
vendored
Normal file
@@ -0,0 +1,8 @@
|
||||
// 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.
|
||||
|
||||
// +build !go1.10
|
||||
|
||||
package codec
|
||||
|
||||
const allowSetUnexportedEmbeddedPtr = true
|
17
vendor/github.com/ugorji/go/codec/goversion_unsupported_lt_go14.go
generated
vendored
Normal file
17
vendor/github.com/ugorji/go/codec/goversion_unsupported_lt_go14.go
generated
vendored
Normal file
@@ -0,0 +1,17 @@
|
||||
// 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.
|
||||
|
||||
// +build !go1.4
|
||||
|
||||
package codec
|
||||
|
||||
// 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
|
||||
|
||||
func init() {
|
||||
panic("codec: go 1.3 and below are not supported")
|
||||
}
|
10
vendor/github.com/ugorji/go/codec/goversion_vendor_eq_go15.go
generated
vendored
Normal file
10
vendor/github.com/ugorji/go/codec/goversion_vendor_eq_go15.go
generated
vendored
Normal file
@@ -0,0 +1,10 @@
|
||||
// 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.
|
||||
|
||||
// +build go1.5,!go1.6
|
||||
|
||||
package codec
|
||||
|
||||
import "os"
|
||||
|
||||
var genCheckVendor = os.Getenv("GO15VENDOREXPERIMENT") == "1"
|
10
vendor/github.com/ugorji/go/codec/goversion_vendor_eq_go16.go
generated
vendored
Normal file
10
vendor/github.com/ugorji/go/codec/goversion_vendor_eq_go16.go
generated
vendored
Normal file
@@ -0,0 +1,10 @@
|
||||
// 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.
|
||||
|
||||
// +build go1.6,!go1.7
|
||||
|
||||
package codec
|
||||
|
||||
import "os"
|
||||
|
||||
var genCheckVendor = os.Getenv("GO15VENDOREXPERIMENT") != "0"
|
8
vendor/github.com/ugorji/go/codec/goversion_vendor_gte_go17.go
generated
vendored
Normal file
8
vendor/github.com/ugorji/go/codec/goversion_vendor_gte_go17.go
generated
vendored
Normal file
@@ -0,0 +1,8 @@
|
||||
// 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.
|
||||
|
||||
// +build go1.7
|
||||
|
||||
package codec
|
||||
|
||||
const genCheckVendor = true
|
8
vendor/github.com/ugorji/go/codec/goversion_vendor_lt_go15.go
generated
vendored
Normal file
8
vendor/github.com/ugorji/go/codec/goversion_vendor_lt_go15.go
generated
vendored
Normal file
@@ -0,0 +1,8 @@
|
||||
// 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.
|
||||
|
||||
// +build !go1.5
|
||||
|
||||
package codec
|
||||
|
||||
var genCheckVendor = false
|
2417
vendor/github.com/ugorji/go/codec/helper.go
generated
vendored
Normal file
2417
vendor/github.com/ugorji/go/codec/helper.go
generated
vendored
Normal file
File diff suppressed because it is too large
Load Diff
121
vendor/github.com/ugorji/go/codec/helper_internal.go
generated
vendored
Normal file
121
vendor/github.com/ugorji/go/codec/helper_internal.go
generated
vendored
Normal file
@@ -0,0 +1,121 @@
|
||||
// Copyright (c) 2012-2015 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 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
|
||||
}
|
||||
|
||||
// validate that this function is correct ...
|
||||
// culled from OGRE (Object-Oriented Graphics Rendering Engine)
|
||||
// function: halfToFloatI (http://stderr.org/doc/ogre-doc/api/OgreBitwise_8h-source.html)
|
||||
func halfFloatToFloatBits(yy uint16) (d uint32) {
|
||||
y := uint32(yy)
|
||||
s := (y >> 15) & 0x01
|
||||
e := (y >> 10) & 0x1f
|
||||
m := y & 0x03ff
|
||||
|
||||
if e == 0 {
|
||||
if m == 0 { // plu or minus 0
|
||||
return s << 31
|
||||
}
|
||||
// Denormalized number -- renormalize it
|
||||
for (m & 0x00000400) == 0 {
|
||||
m <<= 1
|
||||
e -= 1
|
||||
}
|
||||
e += 1
|
||||
const zz uint32 = 0x0400
|
||||
m &= ^zz
|
||||
} 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) | (e << 23) | m
|
||||
}
|
||||
|
||||
// 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 int) (newCap int) {
|
||||
// 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 3 thresholds:
|
||||
// t1: if cap <= t1, newcap = 2x
|
||||
// t2: if cap <= t2, newcap = 1.75x
|
||||
// t3: if cap <= t3, newcap = 1.5x
|
||||
// else newcap = 1.25x
|
||||
//
|
||||
// t1, t2, t3 >= 1024 always.
|
||||
// i.e. if unit size >= 16, then always do 2x or 1.25x (ie t1, t2, t3 are all same)
|
||||
//
|
||||
// With this, appending for bytes increase by:
|
||||
// 100% up to 4K
|
||||
// 75% up to 8K
|
||||
// 50% up to 16K
|
||||
// 25% beyond that
|
||||
|
||||
// unit can be 0 e.g. for struct{}{}; handle that appropriately
|
||||
var t1, t2, t3 int // thresholds
|
||||
if unit <= 1 {
|
||||
t1, t2, t3 = 4*1024, 8*1024, 16*1024
|
||||
} else if unit < 16 {
|
||||
t3 = 16 / unit * 1024
|
||||
t1 = t3 * 1 / 4
|
||||
t2 = t3 * 2 / 4
|
||||
} else {
|
||||
t1, t2, t3 = 1024, 1024, 1024
|
||||
}
|
||||
|
||||
var x int // temporary variable
|
||||
|
||||
// x is multiplier here: one of 5, 6, 7 or 8; incr of 25%, 50%, 75% or 100% respectively
|
||||
if oldCap <= t1 { // [0,t1]
|
||||
x = 8
|
||||
} else if oldCap > t3 { // (t3,infinity]
|
||||
x = 5
|
||||
} else if oldCap <= t2 { // (t1,t2]
|
||||
x = 7
|
||||
} else { // (t2,t3]
|
||||
x = 6
|
||||
}
|
||||
newCap = x * oldCap / 4
|
||||
|
||||
if num > 0 {
|
||||
newCap += num
|
||||
}
|
||||
|
||||
// ensure newCap is a multiple of 64 (if it is > 64) or 16.
|
||||
if newCap > 64 {
|
||||
if x = newCap % 64; x != 0 {
|
||||
x = newCap / 64
|
||||
newCap = 64 * (x + 1)
|
||||
}
|
||||
} else {
|
||||
if x = newCap % 16; x != 0 {
|
||||
x = newCap / 16
|
||||
newCap = 16 * (x + 1)
|
||||
}
|
||||
}
|
||||
return
|
||||
}
|
272
vendor/github.com/ugorji/go/codec/helper_not_unsafe.go
generated
vendored
Normal file
272
vendor/github.com/ugorji/go/codec/helper_not_unsafe.go
generated
vendored
Normal file
@@ -0,0 +1,272 @@
|
||||
// +build !go1.7 safe appengine
|
||||
|
||||
// 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 (
|
||||
"reflect"
|
||||
"sync/atomic"
|
||||
"time"
|
||||
)
|
||||
|
||||
const safeMode = true
|
||||
|
||||
// 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.
|
||||
//
|
||||
// Usage: Always maintain a reference to v while result of this call is in use,
|
||||
// and call keepAlive4BytesView(v) at point where done with view.
|
||||
func stringView(v []byte) string {
|
||||
return string(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.
|
||||
//
|
||||
// Usage: Always maintain a reference to v while result of this call is in use,
|
||||
// and call keepAlive4BytesView(v) at point where done with view.
|
||||
func bytesView(v string) []byte {
|
||||
return []byte(v)
|
||||
}
|
||||
|
||||
func definitelyNil(v interface{}) bool {
|
||||
// this is a best-effort option.
|
||||
// We just return false, so we don't unnecessarily incur the cost of reflection this early.
|
||||
return false
|
||||
}
|
||||
|
||||
func rv2i(rv reflect.Value) interface{} {
|
||||
return rv.Interface()
|
||||
}
|
||||
|
||||
func rt2id(rt reflect.Type) uintptr {
|
||||
return reflect.ValueOf(rt).Pointer()
|
||||
}
|
||||
|
||||
func rv2rtid(rv reflect.Value) uintptr {
|
||||
return reflect.ValueOf(rv.Type()).Pointer()
|
||||
}
|
||||
|
||||
func i2rtid(i interface{}) uintptr {
|
||||
return reflect.ValueOf(reflect.TypeOf(i)).Pointer()
|
||||
}
|
||||
|
||||
// --------------------------
|
||||
|
||||
func isEmptyValue(v reflect.Value, tinfos *TypeInfos, deref, checkStruct bool) bool {
|
||||
switch v.Kind() {
|
||||
case reflect.Invalid:
|
||||
return true
|
||||
case reflect.Array, reflect.Map, reflect.Slice, reflect.String:
|
||||
return 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.Float32, reflect.Float64:
|
||||
return v.Float() == 0
|
||||
case reflect.Interface, reflect.Ptr:
|
||||
if deref {
|
||||
if v.IsNil() {
|
||||
return true
|
||||
}
|
||||
return isEmptyValue(v.Elem(), tinfos, deref, checkStruct)
|
||||
}
|
||||
return v.IsNil()
|
||||
case reflect.Struct:
|
||||
return isEmptyStruct(v, tinfos, deref, checkStruct)
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
// --------------------------
|
||||
// type ptrToRvMap struct{}
|
||||
|
||||
// func (*ptrToRvMap) init() {}
|
||||
// func (*ptrToRvMap) get(i interface{}) reflect.Value {
|
||||
// return reflect.ValueOf(i).Elem()
|
||||
// }
|
||||
|
||||
// --------------------------
|
||||
type atomicTypeInfoSlice struct { // expected to be 2 words
|
||||
v atomic.Value
|
||||
}
|
||||
|
||||
func (x *atomicTypeInfoSlice) load() []rtid2ti {
|
||||
i := x.v.Load()
|
||||
if i == nil {
|
||||
return nil
|
||||
}
|
||||
return i.([]rtid2ti)
|
||||
}
|
||||
|
||||
func (x *atomicTypeInfoSlice) store(p []rtid2ti) {
|
||||
x.v.Store(p)
|
||||
}
|
||||
|
||||
// --------------------------
|
||||
func (d *Decoder) raw(f *codecFnInfo, rv reflect.Value) {
|
||||
rv.SetBytes(d.rawBytes())
|
||||
}
|
||||
|
||||
func (d *Decoder) kString(f *codecFnInfo, rv reflect.Value) {
|
||||
rv.SetString(d.d.DecodeString())
|
||||
}
|
||||
|
||||
func (d *Decoder) kBool(f *codecFnInfo, rv reflect.Value) {
|
||||
rv.SetBool(d.d.DecodeBool())
|
||||
}
|
||||
|
||||
func (d *Decoder) kTime(f *codecFnInfo, rv reflect.Value) {
|
||||
rv.Set(reflect.ValueOf(d.d.DecodeTime()))
|
||||
}
|
||||
|
||||
func (d *Decoder) kFloat32(f *codecFnInfo, rv reflect.Value) {
|
||||
fv := d.d.DecodeFloat64()
|
||||
if chkOvf.Float32(fv) {
|
||||
d.errorf("float32 overflow: %v", fv)
|
||||
}
|
||||
rv.SetFloat(fv)
|
||||
}
|
||||
|
||||
func (d *Decoder) kFloat64(f *codecFnInfo, rv reflect.Value) {
|
||||
rv.SetFloat(d.d.DecodeFloat64())
|
||||
}
|
||||
|
||||
func (d *Decoder) kInt(f *codecFnInfo, rv reflect.Value) {
|
||||
rv.SetInt(chkOvf.IntV(d.d.DecodeInt64(), intBitsize))
|
||||
}
|
||||
|
||||
func (d *Decoder) kInt8(f *codecFnInfo, rv reflect.Value) {
|
||||
rv.SetInt(chkOvf.IntV(d.d.DecodeInt64(), 8))
|
||||
}
|
||||
|
||||
func (d *Decoder) kInt16(f *codecFnInfo, rv reflect.Value) {
|
||||
rv.SetInt(chkOvf.IntV(d.d.DecodeInt64(), 16))
|
||||
}
|
||||
|
||||
func (d *Decoder) kInt32(f *codecFnInfo, rv reflect.Value) {
|
||||
rv.SetInt(chkOvf.IntV(d.d.DecodeInt64(), 32))
|
||||
}
|
||||
|
||||
func (d *Decoder) kInt64(f *codecFnInfo, rv reflect.Value) {
|
||||
rv.SetInt(d.d.DecodeInt64())
|
||||
}
|
||||
|
||||
func (d *Decoder) kUint(f *codecFnInfo, rv reflect.Value) {
|
||||
rv.SetUint(chkOvf.UintV(d.d.DecodeUint64(), uintBitsize))
|
||||
}
|
||||
|
||||
func (d *Decoder) kUintptr(f *codecFnInfo, rv reflect.Value) {
|
||||
rv.SetUint(chkOvf.UintV(d.d.DecodeUint64(), uintBitsize))
|
||||
}
|
||||
|
||||
func (d *Decoder) kUint8(f *codecFnInfo, rv reflect.Value) {
|
||||
rv.SetUint(chkOvf.UintV(d.d.DecodeUint64(), 8))
|
||||
}
|
||||
|
||||
func (d *Decoder) kUint16(f *codecFnInfo, rv reflect.Value) {
|
||||
rv.SetUint(chkOvf.UintV(d.d.DecodeUint64(), 16))
|
||||
}
|
||||
|
||||
func (d *Decoder) kUint32(f *codecFnInfo, rv reflect.Value) {
|
||||
rv.SetUint(chkOvf.UintV(d.d.DecodeUint64(), 32))
|
||||
}
|
||||
|
||||
func (d *Decoder) kUint64(f *codecFnInfo, rv reflect.Value) {
|
||||
rv.SetUint(d.d.DecodeUint64())
|
||||
}
|
||||
|
||||
// ----------------
|
||||
|
||||
func (e *Encoder) kBool(f *codecFnInfo, rv reflect.Value) {
|
||||
e.e.EncodeBool(rv.Bool())
|
||||
}
|
||||
|
||||
func (e *Encoder) kTime(f *codecFnInfo, rv reflect.Value) {
|
||||
e.e.EncodeTime(rv2i(rv).(time.Time))
|
||||
}
|
||||
|
||||
func (e *Encoder) kString(f *codecFnInfo, rv reflect.Value) {
|
||||
e.e.EncodeString(cUTF8, rv.String())
|
||||
}
|
||||
|
||||
func (e *Encoder) kFloat64(f *codecFnInfo, rv reflect.Value) {
|
||||
e.e.EncodeFloat64(rv.Float())
|
||||
}
|
||||
|
||||
func (e *Encoder) kFloat32(f *codecFnInfo, rv reflect.Value) {
|
||||
e.e.EncodeFloat32(float32(rv.Float()))
|
||||
}
|
||||
|
||||
func (e *Encoder) kInt(f *codecFnInfo, rv reflect.Value) {
|
||||
e.e.EncodeInt(rv.Int())
|
||||
}
|
||||
|
||||
func (e *Encoder) kInt8(f *codecFnInfo, rv reflect.Value) {
|
||||
e.e.EncodeInt(rv.Int())
|
||||
}
|
||||
|
||||
func (e *Encoder) kInt16(f *codecFnInfo, rv reflect.Value) {
|
||||
e.e.EncodeInt(rv.Int())
|
||||
}
|
||||
|
||||
func (e *Encoder) kInt32(f *codecFnInfo, rv reflect.Value) {
|
||||
e.e.EncodeInt(rv.Int())
|
||||
}
|
||||
|
||||
func (e *Encoder) kInt64(f *codecFnInfo, rv reflect.Value) {
|
||||
e.e.EncodeInt(rv.Int())
|
||||
}
|
||||
|
||||
func (e *Encoder) kUint(f *codecFnInfo, rv reflect.Value) {
|
||||
e.e.EncodeUint(rv.Uint())
|
||||
}
|
||||
|
||||
func (e *Encoder) kUint8(f *codecFnInfo, rv reflect.Value) {
|
||||
e.e.EncodeUint(rv.Uint())
|
||||
}
|
||||
|
||||
func (e *Encoder) kUint16(f *codecFnInfo, rv reflect.Value) {
|
||||
e.e.EncodeUint(rv.Uint())
|
||||
}
|
||||
|
||||
func (e *Encoder) kUint32(f *codecFnInfo, rv reflect.Value) {
|
||||
e.e.EncodeUint(rv.Uint())
|
||||
}
|
||||
|
||||
func (e *Encoder) kUint64(f *codecFnInfo, rv reflect.Value) {
|
||||
e.e.EncodeUint(rv.Uint())
|
||||
}
|
||||
|
||||
func (e *Encoder) kUintptr(f *codecFnInfo, rv reflect.Value) {
|
||||
e.e.EncodeUint(rv.Uint())
|
||||
}
|
||||
|
||||
// // keepAlive4BytesView maintains a reference to the input parameter for bytesView.
|
||||
// //
|
||||
// // Usage: call this at point where done with the bytes view.
|
||||
// func keepAlive4BytesView(v string) {}
|
||||
|
||||
// // keepAlive4BytesView maintains a reference to the input parameter for stringView.
|
||||
// //
|
||||
// // Usage: call this at point where done with the string view.
|
||||
// func keepAlive4StringView(v []byte) {}
|
||||
|
||||
// func definitelyNil(v interface{}) bool {
|
||||
// rv := reflect.ValueOf(v)
|
||||
// switch rv.Kind() {
|
||||
// case reflect.Invalid:
|
||||
// return true
|
||||
// case reflect.Ptr, reflect.Interface, reflect.Chan, reflect.Slice, reflect.Map, reflect.Func:
|
||||
// return rv.IsNil()
|
||||
// default:
|
||||
// return false
|
||||
// }
|
||||
// }
|
54
vendor/github.com/ugorji/go/codec/helper_test.go
generated
vendored
Normal file
54
vendor/github.com/ugorji/go/codec/helper_test.go
generated
vendored
Normal file
@@ -0,0 +1,54 @@
|
||||
// Copyright (c) 2012-2015 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
|
||||
|
||||
func deepEqual(v1, v2 interface{}) (err error) {
|
||||
if !reflect.DeepEqual(v1, v2) {
|
||||
err = errors.New("Not Match")
|
||||
}
|
||||
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
|
||||
}
|
632
vendor/github.com/ugorji/go/codec/helper_unsafe.go
generated
vendored
Normal file
632
vendor/github.com/ugorji/go/codec/helper_unsafe.go
generated
vendored
Normal file
@@ -0,0 +1,632 @@
|
||||
// +build !safe
|
||||
// +build !appengine
|
||||
// +build go1.7
|
||||
|
||||
// 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 (
|
||||
"reflect"
|
||||
"sync/atomic"
|
||||
"time"
|
||||
"unsafe"
|
||||
)
|
||||
|
||||
// This file has unsafe variants of some helper methods.
|
||||
// NOTE: See helper_not_unsafe.go for the usage information.
|
||||
|
||||
// var zeroRTv [4]uintptr
|
||||
|
||||
const safeMode = false
|
||||
const unsafeFlagIndir = 1 << 7 // keep in sync with GO_ROOT/src/reflect/value.go
|
||||
|
||||
type unsafeString struct {
|
||||
Data unsafe.Pointer
|
||||
Len int
|
||||
}
|
||||
|
||||
type unsafeSlice struct {
|
||||
Data unsafe.Pointer
|
||||
Len int
|
||||
Cap int
|
||||
}
|
||||
|
||||
type unsafeIntf struct {
|
||||
typ unsafe.Pointer
|
||||
word unsafe.Pointer
|
||||
}
|
||||
|
||||
type unsafeReflectValue struct {
|
||||
typ unsafe.Pointer
|
||||
ptr unsafe.Pointer
|
||||
flag uintptr
|
||||
}
|
||||
|
||||
func stringView(v []byte) string {
|
||||
if len(v) == 0 {
|
||||
return ""
|
||||
}
|
||||
bx := (*unsafeSlice)(unsafe.Pointer(&v))
|
||||
return *(*string)(unsafe.Pointer(&unsafeString{bx.Data, bx.Len}))
|
||||
}
|
||||
|
||||
func bytesView(v string) []byte {
|
||||
if len(v) == 0 {
|
||||
return zeroByteSlice
|
||||
}
|
||||
sx := (*unsafeString)(unsafe.Pointer(&v))
|
||||
return *(*[]byte)(unsafe.Pointer(&unsafeSlice{sx.Data, sx.Len, sx.Len}))
|
||||
}
|
||||
|
||||
func definitelyNil(v interface{}) bool {
|
||||
// There is no global way of checking if an interface is nil.
|
||||
// For true references (map, ptr, func, chan), you can just look
|
||||
// at the word of the interface. However, for slices, you have to dereference
|
||||
// the word, and get a pointer to the 3-word interface value.
|
||||
//
|
||||
// However, the following are cheap calls
|
||||
// - TypeOf(interface): cheap 2-line call.
|
||||
// - ValueOf(interface{}): expensive
|
||||
// - type.Kind: cheap call through an interface
|
||||
// - Value.Type(): cheap call
|
||||
// except it's a method value (e.g. r.Read, which implies that it is a Func)
|
||||
|
||||
return ((*unsafeIntf)(unsafe.Pointer(&v))).word == nil
|
||||
}
|
||||
|
||||
func rv2i(rv reflect.Value) interface{} {
|
||||
// TODO: consider a more generally-known optimization for reflect.Value ==> Interface
|
||||
//
|
||||
// Currently, we use this fragile method that taps into implememtation details from
|
||||
// the source go stdlib reflect/value.go, and trims the implementation.
|
||||
|
||||
urv := (*unsafeReflectValue)(unsafe.Pointer(&rv))
|
||||
// true references (map, func, chan, ptr - NOT slice) may be double-referenced as flagIndir
|
||||
var ptr unsafe.Pointer
|
||||
if refBitset.isset(byte(urv.flag&(1<<5-1))) && urv.flag&unsafeFlagIndir != 0 {
|
||||
ptr = *(*unsafe.Pointer)(urv.ptr)
|
||||
} else {
|
||||
ptr = urv.ptr
|
||||
}
|
||||
return *(*interface{})(unsafe.Pointer(&unsafeIntf{typ: urv.typ, word: ptr}))
|
||||
}
|
||||
|
||||
func rt2id(rt reflect.Type) uintptr {
|
||||
return uintptr(((*unsafeIntf)(unsafe.Pointer(&rt))).word)
|
||||
}
|
||||
|
||||
func rv2rtid(rv reflect.Value) uintptr {
|
||||
return uintptr((*unsafeReflectValue)(unsafe.Pointer(&rv)).typ)
|
||||
}
|
||||
|
||||
func i2rtid(i interface{}) uintptr {
|
||||
return uintptr(((*unsafeIntf)(unsafe.Pointer(&i))).typ)
|
||||
}
|
||||
|
||||
// --------------------------
|
||||
|
||||
func isEmptyValue(v reflect.Value, tinfos *TypeInfos, deref, checkStruct bool) bool {
|
||||
urv := (*unsafeReflectValue)(unsafe.Pointer(&v))
|
||||
if urv.flag == 0 {
|
||||
return 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.Interface:
|
||||
isnil := urv.ptr == nil || *(*unsafe.Pointer)(urv.ptr) == nil
|
||||
if deref {
|
||||
if isnil {
|
||||
return true
|
||||
}
|
||||
return isEmptyValue(v.Elem(), tinfos, deref, checkStruct)
|
||||
}
|
||||
return isnil
|
||||
case reflect.Ptr:
|
||||
isnil := urv.ptr == nil
|
||||
if deref {
|
||||
if isnil {
|
||||
return true
|
||||
}
|
||||
return isEmptyValue(v.Elem(), tinfos, deref, checkStruct)
|
||||
}
|
||||
return isnil
|
||||
case reflect.Struct:
|
||||
return isEmptyStruct(v, tinfos, deref, checkStruct)
|
||||
case reflect.Map, reflect.Array, reflect.Chan:
|
||||
return v.Len() == 0
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
// --------------------------
|
||||
|
||||
type atomicTypeInfoSlice struct { // expected to be 2 words
|
||||
v unsafe.Pointer // data array - Pointer (not uintptr) to maintain GC reference
|
||||
l int64 // length of the data array
|
||||
}
|
||||
|
||||
func (x *atomicTypeInfoSlice) load() []rtid2ti {
|
||||
l := int(atomic.LoadInt64(&x.l))
|
||||
if l == 0 {
|
||||
return nil
|
||||
}
|
||||
return *(*[]rtid2ti)(unsafe.Pointer(&unsafeSlice{Data: atomic.LoadPointer(&x.v), Len: l, Cap: l}))
|
||||
// return (*[]rtid2ti)(atomic.LoadPointer(&x.v))
|
||||
}
|
||||
|
||||
func (x *atomicTypeInfoSlice) store(p []rtid2ti) {
|
||||
s := (*unsafeSlice)(unsafe.Pointer(&p))
|
||||
atomic.StorePointer(&x.v, s.Data)
|
||||
atomic.StoreInt64(&x.l, int64(s.Len))
|
||||
// atomic.StorePointer(&x.v, unsafe.Pointer(p))
|
||||
}
|
||||
|
||||
// --------------------------
|
||||
func (d *Decoder) raw(f *codecFnInfo, rv reflect.Value) {
|
||||
urv := (*unsafeReflectValue)(unsafe.Pointer(&rv))
|
||||
*(*[]byte)(urv.ptr) = d.rawBytes()
|
||||
}
|
||||
|
||||
func (d *Decoder) kString(f *codecFnInfo, rv reflect.Value) {
|
||||
urv := (*unsafeReflectValue)(unsafe.Pointer(&rv))
|
||||
*(*string)(urv.ptr) = d.d.DecodeString()
|
||||
}
|
||||
|
||||
func (d *Decoder) kBool(f *codecFnInfo, rv reflect.Value) {
|
||||
urv := (*unsafeReflectValue)(unsafe.Pointer(&rv))
|
||||
*(*bool)(urv.ptr) = d.d.DecodeBool()
|
||||
}
|
||||
|
||||
func (d *Decoder) kTime(f *codecFnInfo, rv reflect.Value) {
|
||||
urv := (*unsafeReflectValue)(unsafe.Pointer(&rv))
|
||||
*(*time.Time)(urv.ptr) = d.d.DecodeTime()
|
||||
}
|
||||
|
||||
func (d *Decoder) kFloat32(f *codecFnInfo, rv reflect.Value) {
|
||||
fv := d.d.DecodeFloat64()
|
||||
if chkOvf.Float32(fv) {
|
||||
d.errorf("float32 overflow: %v", fv)
|
||||
}
|
||||
urv := (*unsafeReflectValue)(unsafe.Pointer(&rv))
|
||||
*(*float32)(urv.ptr) = float32(fv)
|
||||
}
|
||||
|
||||
func (d *Decoder) kFloat64(f *codecFnInfo, rv reflect.Value) {
|
||||
urv := (*unsafeReflectValue)(unsafe.Pointer(&rv))
|
||||
*(*float64)(urv.ptr) = d.d.DecodeFloat64()
|
||||
}
|
||||
|
||||
func (d *Decoder) kInt(f *codecFnInfo, rv reflect.Value) {
|
||||
urv := (*unsafeReflectValue)(unsafe.Pointer(&rv))
|
||||
*(*int)(urv.ptr) = int(chkOvf.IntV(d.d.DecodeInt64(), intBitsize))
|
||||
}
|
||||
|
||||
func (d *Decoder) kInt8(f *codecFnInfo, rv reflect.Value) {
|
||||
urv := (*unsafeReflectValue)(unsafe.Pointer(&rv))
|
||||
*(*int8)(urv.ptr) = int8(chkOvf.IntV(d.d.DecodeInt64(), 8))
|
||||
}
|
||||
|
||||
func (d *Decoder) kInt16(f *codecFnInfo, rv reflect.Value) {
|
||||
urv := (*unsafeReflectValue)(unsafe.Pointer(&rv))
|
||||
*(*int16)(urv.ptr) = int16(chkOvf.IntV(d.d.DecodeInt64(), 16))
|
||||
}
|
||||
|
||||
func (d *Decoder) kInt32(f *codecFnInfo, rv reflect.Value) {
|
||||
urv := (*unsafeReflectValue)(unsafe.Pointer(&rv))
|
||||
*(*int32)(urv.ptr) = int32(chkOvf.IntV(d.d.DecodeInt64(), 32))
|
||||
}
|
||||
|
||||
func (d *Decoder) kInt64(f *codecFnInfo, rv reflect.Value) {
|
||||
urv := (*unsafeReflectValue)(unsafe.Pointer(&rv))
|
||||
*(*int64)(urv.ptr) = d.d.DecodeInt64()
|
||||
}
|
||||
|
||||
func (d *Decoder) kUint(f *codecFnInfo, rv reflect.Value) {
|
||||
urv := (*unsafeReflectValue)(unsafe.Pointer(&rv))
|
||||
*(*uint)(urv.ptr) = uint(chkOvf.UintV(d.d.DecodeUint64(), uintBitsize))
|
||||
}
|
||||
|
||||
func (d *Decoder) kUintptr(f *codecFnInfo, rv reflect.Value) {
|
||||
urv := (*unsafeReflectValue)(unsafe.Pointer(&rv))
|
||||
*(*uintptr)(urv.ptr) = uintptr(chkOvf.UintV(d.d.DecodeUint64(), uintBitsize))
|
||||
}
|
||||
|
||||
func (d *Decoder) kUint8(f *codecFnInfo, rv reflect.Value) {
|
||||
urv := (*unsafeReflectValue)(unsafe.Pointer(&rv))
|
||||
*(*uint8)(urv.ptr) = uint8(chkOvf.UintV(d.d.DecodeUint64(), 8))
|
||||
}
|
||||
|
||||
func (d *Decoder) kUint16(f *codecFnInfo, rv reflect.Value) {
|
||||
urv := (*unsafeReflectValue)(unsafe.Pointer(&rv))
|
||||
*(*uint16)(urv.ptr) = uint16(chkOvf.UintV(d.d.DecodeUint64(), 16))
|
||||
}
|
||||
|
||||
func (d *Decoder) kUint32(f *codecFnInfo, rv reflect.Value) {
|
||||
urv := (*unsafeReflectValue)(unsafe.Pointer(&rv))
|
||||
*(*uint32)(urv.ptr) = uint32(chkOvf.UintV(d.d.DecodeUint64(), 32))
|
||||
}
|
||||
|
||||
func (d *Decoder) kUint64(f *codecFnInfo, rv reflect.Value) {
|
||||
urv := (*unsafeReflectValue)(unsafe.Pointer(&rv))
|
||||
*(*uint64)(urv.ptr) = d.d.DecodeUint64()
|
||||
}
|
||||
|
||||
// ------------
|
||||
|
||||
func (e *Encoder) kBool(f *codecFnInfo, rv reflect.Value) {
|
||||
v := (*unsafeReflectValue)(unsafe.Pointer(&rv))
|
||||
e.e.EncodeBool(*(*bool)(v.ptr))
|
||||
}
|
||||
|
||||
func (e *Encoder) kTime(f *codecFnInfo, rv reflect.Value) {
|
||||
v := (*unsafeReflectValue)(unsafe.Pointer(&rv))
|
||||
e.e.EncodeTime(*(*time.Time)(v.ptr))
|
||||
}
|
||||
|
||||
func (e *Encoder) kString(f *codecFnInfo, rv reflect.Value) {
|
||||
v := (*unsafeReflectValue)(unsafe.Pointer(&rv))
|
||||
e.e.EncodeString(cUTF8, *(*string)(v.ptr))
|
||||
}
|
||||
|
||||
func (e *Encoder) kFloat64(f *codecFnInfo, rv reflect.Value) {
|
||||
v := (*unsafeReflectValue)(unsafe.Pointer(&rv))
|
||||
e.e.EncodeFloat64(*(*float64)(v.ptr))
|
||||
}
|
||||
|
||||
func (e *Encoder) kFloat32(f *codecFnInfo, rv reflect.Value) {
|
||||
v := (*unsafeReflectValue)(unsafe.Pointer(&rv))
|
||||
e.e.EncodeFloat32(*(*float32)(v.ptr))
|
||||
}
|
||||
|
||||
func (e *Encoder) kInt(f *codecFnInfo, rv reflect.Value) {
|
||||
v := (*unsafeReflectValue)(unsafe.Pointer(&rv))
|
||||
e.e.EncodeInt(int64(*(*int)(v.ptr)))
|
||||
}
|
||||
|
||||
func (e *Encoder) kInt8(f *codecFnInfo, rv reflect.Value) {
|
||||
v := (*unsafeReflectValue)(unsafe.Pointer(&rv))
|
||||
e.e.EncodeInt(int64(*(*int8)(v.ptr)))
|
||||
}
|
||||
|
||||
func (e *Encoder) kInt16(f *codecFnInfo, rv reflect.Value) {
|
||||
v := (*unsafeReflectValue)(unsafe.Pointer(&rv))
|
||||
e.e.EncodeInt(int64(*(*int16)(v.ptr)))
|
||||
}
|
||||
|
||||
func (e *Encoder) kInt32(f *codecFnInfo, rv reflect.Value) {
|
||||
v := (*unsafeReflectValue)(unsafe.Pointer(&rv))
|
||||
e.e.EncodeInt(int64(*(*int32)(v.ptr)))
|
||||
}
|
||||
|
||||
func (e *Encoder) kInt64(f *codecFnInfo, rv reflect.Value) {
|
||||
v := (*unsafeReflectValue)(unsafe.Pointer(&rv))
|
||||
e.e.EncodeInt(int64(*(*int64)(v.ptr)))
|
||||
}
|
||||
|
||||
func (e *Encoder) kUint(f *codecFnInfo, rv reflect.Value) {
|
||||
v := (*unsafeReflectValue)(unsafe.Pointer(&rv))
|
||||
e.e.EncodeUint(uint64(*(*uint)(v.ptr)))
|
||||
}
|
||||
|
||||
func (e *Encoder) kUint8(f *codecFnInfo, rv reflect.Value) {
|
||||
v := (*unsafeReflectValue)(unsafe.Pointer(&rv))
|
||||
e.e.EncodeUint(uint64(*(*uint8)(v.ptr)))
|
||||
}
|
||||
|
||||
func (e *Encoder) kUint16(f *codecFnInfo, rv reflect.Value) {
|
||||
v := (*unsafeReflectValue)(unsafe.Pointer(&rv))
|
||||
e.e.EncodeUint(uint64(*(*uint16)(v.ptr)))
|
||||
}
|
||||
|
||||
func (e *Encoder) kUint32(f *codecFnInfo, rv reflect.Value) {
|
||||
v := (*unsafeReflectValue)(unsafe.Pointer(&rv))
|
||||
e.e.EncodeUint(uint64(*(*uint32)(v.ptr)))
|
||||
}
|
||||
|
||||
func (e *Encoder) kUint64(f *codecFnInfo, rv reflect.Value) {
|
||||
v := (*unsafeReflectValue)(unsafe.Pointer(&rv))
|
||||
e.e.EncodeUint(uint64(*(*uint64)(v.ptr)))
|
||||
}
|
||||
|
||||
func (e *Encoder) kUintptr(f *codecFnInfo, rv reflect.Value) {
|
||||
v := (*unsafeReflectValue)(unsafe.Pointer(&rv))
|
||||
e.e.EncodeUint(uint64(*(*uintptr)(v.ptr)))
|
||||
}
|
||||
|
||||
// ------------
|
||||
|
||||
// func (d *Decoder) raw(f *codecFnInfo, rv reflect.Value) {
|
||||
// urv := (*unsafeReflectValue)(unsafe.Pointer(&rv))
|
||||
// // if urv.flag&unsafeFlagIndir != 0 {
|
||||
// // urv.ptr = *(*unsafe.Pointer)(urv.ptr)
|
||||
// // }
|
||||
// *(*[]byte)(urv.ptr) = d.rawBytes()
|
||||
// }
|
||||
|
||||
// func rv0t(rt reflect.Type) reflect.Value {
|
||||
// ut := (*unsafeIntf)(unsafe.Pointer(&rt))
|
||||
// // we need to determine whether ifaceIndir, and then whether to just pass 0 as the ptr
|
||||
// uv := unsafeReflectValue{ut.word, &zeroRTv, flag(rt.Kind())}
|
||||
// return *(*reflect.Value)(unsafe.Pointer(&uv})
|
||||
// }
|
||||
|
||||
// func rv2i(rv reflect.Value) interface{} {
|
||||
// urv := (*unsafeReflectValue)(unsafe.Pointer(&rv))
|
||||
// // true references (map, func, chan, ptr - NOT slice) may be double-referenced as flagIndir
|
||||
// var ptr unsafe.Pointer
|
||||
// // kk := reflect.Kind(urv.flag & (1<<5 - 1))
|
||||
// // if (kk == reflect.Map || kk == reflect.Ptr || kk == reflect.Chan || kk == reflect.Func) && urv.flag&unsafeFlagIndir != 0 {
|
||||
// if refBitset.isset(byte(urv.flag&(1<<5-1))) && urv.flag&unsafeFlagIndir != 0 {
|
||||
// ptr = *(*unsafe.Pointer)(urv.ptr)
|
||||
// } else {
|
||||
// ptr = urv.ptr
|
||||
// }
|
||||
// return *(*interface{})(unsafe.Pointer(&unsafeIntf{typ: urv.typ, word: ptr}))
|
||||
// // return *(*interface{})(unsafe.Pointer(&unsafeIntf{word: *(*unsafe.Pointer)(urv.ptr), typ: urv.typ}))
|
||||
// // return *(*interface{})(unsafe.Pointer(&unsafeIntf{word: urv.ptr, typ: urv.typ}))
|
||||
// }
|
||||
|
||||
// func definitelyNil(v interface{}) bool {
|
||||
// var ui *unsafeIntf = (*unsafeIntf)(unsafe.Pointer(&v))
|
||||
// if ui.word == nil {
|
||||
// return true
|
||||
// }
|
||||
// var tk = reflect.TypeOf(v).Kind()
|
||||
// return (tk == reflect.Interface || tk == reflect.Slice) && *(*unsafe.Pointer)(ui.word) == nil
|
||||
// fmt.Printf(">>>> definitely nil: isnil: %v, TYPE: \t%T, word: %v, *word: %v, type: %v, nil: %v\n",
|
||||
// v == nil, v, word, *((*unsafe.Pointer)(word)), ui.typ, nil)
|
||||
// }
|
||||
|
||||
// func keepAlive4BytesView(v string) {
|
||||
// runtime.KeepAlive(v)
|
||||
// }
|
||||
|
||||
// func keepAlive4StringView(v []byte) {
|
||||
// runtime.KeepAlive(v)
|
||||
// }
|
||||
|
||||
// func rt2id(rt reflect.Type) uintptr {
|
||||
// return uintptr(((*unsafeIntf)(unsafe.Pointer(&rt))).word)
|
||||
// // var i interface{} = rt
|
||||
// // // ui := (*unsafeIntf)(unsafe.Pointer(&i))
|
||||
// // return ((*unsafeIntf)(unsafe.Pointer(&i))).word
|
||||
// }
|
||||
|
||||
// func rv2i(rv reflect.Value) interface{} {
|
||||
// urv := (*unsafeReflectValue)(unsafe.Pointer(&rv))
|
||||
// // non-reference type: already indir
|
||||
// // reference type: depend on flagIndir property ('cos maybe was double-referenced)
|
||||
// // const (unsafeRvFlagKindMask = 1<<5 - 1 , unsafeRvFlagIndir = 1 << 7 )
|
||||
// // rvk := reflect.Kind(urv.flag & (1<<5 - 1))
|
||||
// // if (rvk == reflect.Chan ||
|
||||
// // rvk == reflect.Func ||
|
||||
// // rvk == reflect.Interface ||
|
||||
// // rvk == reflect.Map ||
|
||||
// // rvk == reflect.Ptr ||
|
||||
// // rvk == reflect.UnsafePointer) && urv.flag&(1<<8) != 0 {
|
||||
// // fmt.Printf(">>>>> ---- double indirect reference: %v, %v\n", rvk, rv.Type())
|
||||
// // return *(*interface{})(unsafe.Pointer(&unsafeIntf{word: *(*unsafe.Pointer)(urv.ptr), typ: urv.typ}))
|
||||
// // }
|
||||
// if urv.flag&(1<<5-1) == uintptr(reflect.Map) && urv.flag&(1<<7) != 0 {
|
||||
// // fmt.Printf(">>>>> ---- double indirect reference: %v, %v\n", rvk, rv.Type())
|
||||
// return *(*interface{})(unsafe.Pointer(&unsafeIntf{word: *(*unsafe.Pointer)(urv.ptr), typ: urv.typ}))
|
||||
// }
|
||||
// // fmt.Printf(">>>>> ++++ direct reference: %v, %v\n", rvk, rv.Type())
|
||||
// return *(*interface{})(unsafe.Pointer(&unsafeIntf{word: urv.ptr, typ: urv.typ}))
|
||||
// }
|
||||
|
||||
// const (
|
||||
// unsafeRvFlagKindMask = 1<<5 - 1
|
||||
// unsafeRvKindDirectIface = 1 << 5
|
||||
// unsafeRvFlagIndir = 1 << 7
|
||||
// unsafeRvFlagAddr = 1 << 8
|
||||
// unsafeRvFlagMethod = 1 << 9
|
||||
|
||||
// _USE_RV_INTERFACE bool = false
|
||||
// _UNSAFE_RV_DEBUG = true
|
||||
// )
|
||||
|
||||
// type unsafeRtype struct {
|
||||
// _ [2]uintptr
|
||||
// _ uint32
|
||||
// _ uint8
|
||||
// _ uint8
|
||||
// _ uint8
|
||||
// kind uint8
|
||||
// _ [2]uintptr
|
||||
// _ int32
|
||||
// }
|
||||
|
||||
// func _rv2i(rv reflect.Value) interface{} {
|
||||
// // Note: From use,
|
||||
// // - it's never an interface
|
||||
// // - the only calls here are for ifaceIndir types.
|
||||
// // (though that conditional is wrong)
|
||||
// // To know for sure, we need the value of t.kind (which is not exposed).
|
||||
// //
|
||||
// // Need to validate the path: type is indirect ==> only value is indirect ==> default (value is direct)
|
||||
// // - Type indirect, Value indirect: ==> numbers, boolean, slice, struct, array, string
|
||||
// // - Type Direct, Value indirect: ==> map???
|
||||
// // - Type Direct, Value direct: ==> pointers, unsafe.Pointer, func, chan, map
|
||||
// //
|
||||
// // TRANSLATES TO:
|
||||
// // if typeIndirect { } else if valueIndirect { } else { }
|
||||
// //
|
||||
// // Since we don't deal with funcs, then "flagNethod" is unset, and can be ignored.
|
||||
|
||||
// if _USE_RV_INTERFACE {
|
||||
// return rv.Interface()
|
||||
// }
|
||||
// urv := (*unsafeReflectValue)(unsafe.Pointer(&rv))
|
||||
|
||||
// // if urv.flag&unsafeRvFlagMethod != 0 || urv.flag&unsafeRvFlagKindMask == uintptr(reflect.Interface) {
|
||||
// // println("***** IS flag method or interface: delegating to rv.Interface()")
|
||||
// // return rv.Interface()
|
||||
// // }
|
||||
|
||||
// // if urv.flag&unsafeRvFlagKindMask == uintptr(reflect.Interface) {
|
||||
// // println("***** IS Interface: delegate to rv.Interface")
|
||||
// // return rv.Interface()
|
||||
// // }
|
||||
// // if urv.flag&unsafeRvFlagKindMask&unsafeRvKindDirectIface == 0 {
|
||||
// // if urv.flag&unsafeRvFlagAddr == 0 {
|
||||
// // println("***** IS ifaceIndir typ")
|
||||
// // // ui := unsafeIntf{word: urv.ptr, typ: urv.typ}
|
||||
// // // return *(*interface{})(unsafe.Pointer(&ui))
|
||||
// // // return *(*interface{})(unsafe.Pointer(&unsafeIntf{word: urv.ptr, typ: urv.typ}))
|
||||
// // }
|
||||
// // } else if urv.flag&unsafeRvFlagIndir != 0 {
|
||||
// // println("***** IS flagindir")
|
||||
// // // return *(*interface{})(unsafe.Pointer(&unsafeIntf{word: *(*unsafe.Pointer)(urv.ptr), typ: urv.typ}))
|
||||
// // } else {
|
||||
// // println("***** NOT flagindir")
|
||||
// // return *(*interface{})(unsafe.Pointer(&unsafeIntf{word: urv.ptr, typ: urv.typ}))
|
||||
// // }
|
||||
// // println("***** default: delegate to rv.Interface")
|
||||
|
||||
// urt := (*unsafeRtype)(unsafe.Pointer(urv.typ))
|
||||
// if _UNSAFE_RV_DEBUG {
|
||||
// fmt.Printf(">>>> start: %v: ", rv.Type())
|
||||
// fmt.Printf("%v - %v\n", *urv, *urt)
|
||||
// }
|
||||
// if urt.kind&unsafeRvKindDirectIface == 0 {
|
||||
// if _UNSAFE_RV_DEBUG {
|
||||
// fmt.Printf("**** +ifaceIndir type: %v\n", rv.Type())
|
||||
// }
|
||||
// // println("***** IS ifaceIndir typ")
|
||||
// // if true || urv.flag&unsafeRvFlagAddr == 0 {
|
||||
// // // println(" ***** IS NOT addr")
|
||||
// return *(*interface{})(unsafe.Pointer(&unsafeIntf{word: urv.ptr, typ: urv.typ}))
|
||||
// // }
|
||||
// } else if urv.flag&unsafeRvFlagIndir != 0 {
|
||||
// if _UNSAFE_RV_DEBUG {
|
||||
// fmt.Printf("**** +flagIndir type: %v\n", rv.Type())
|
||||
// }
|
||||
// // println("***** IS flagindir")
|
||||
// return *(*interface{})(unsafe.Pointer(&unsafeIntf{word: *(*unsafe.Pointer)(urv.ptr), typ: urv.typ}))
|
||||
// } else {
|
||||
// if _UNSAFE_RV_DEBUG {
|
||||
// fmt.Printf("**** -flagIndir type: %v\n", rv.Type())
|
||||
// }
|
||||
// // println("***** NOT flagindir")
|
||||
// return *(*interface{})(unsafe.Pointer(&unsafeIntf{word: urv.ptr, typ: urv.typ}))
|
||||
// }
|
||||
// // println("***** default: delegating to rv.Interface()")
|
||||
// // return rv.Interface()
|
||||
// }
|
||||
|
||||
// var staticM0 = make(map[string]uint64)
|
||||
// var staticI0 = (int32)(-5)
|
||||
|
||||
// func staticRv2iTest() {
|
||||
// i0 := (int32)(-5)
|
||||
// m0 := make(map[string]uint16)
|
||||
// m0["1"] = 1
|
||||
// for _, i := range []interface{}{
|
||||
// (int)(7),
|
||||
// (uint)(8),
|
||||
// (int16)(-9),
|
||||
// (uint16)(19),
|
||||
// (uintptr)(77),
|
||||
// (bool)(true),
|
||||
// float32(-32.7),
|
||||
// float64(64.9),
|
||||
// complex(float32(19), 5),
|
||||
// complex(float64(-32), 7),
|
||||
// [4]uint64{1, 2, 3, 4},
|
||||
// (chan<- int)(nil), // chan,
|
||||
// rv2i, // func
|
||||
// io.Writer(ioutil.Discard),
|
||||
// make(map[string]uint),
|
||||
// (map[string]uint)(nil),
|
||||
// staticM0,
|
||||
// m0,
|
||||
// &m0,
|
||||
// i0,
|
||||
// &i0,
|
||||
// &staticI0,
|
||||
// &staticM0,
|
||||
// []uint32{6, 7, 8},
|
||||
// "abc",
|
||||
// Raw{},
|
||||
// RawExt{},
|
||||
// &Raw{},
|
||||
// &RawExt{},
|
||||
// unsafe.Pointer(&i0),
|
||||
// } {
|
||||
// i2 := rv2i(reflect.ValueOf(i))
|
||||
// eq := reflect.DeepEqual(i, i2)
|
||||
// fmt.Printf(">>>> %v == %v? %v\n", i, i2, eq)
|
||||
// }
|
||||
// // os.Exit(0)
|
||||
// }
|
||||
|
||||
// func init() {
|
||||
// staticRv2iTest()
|
||||
// }
|
||||
|
||||
// func rv2i(rv reflect.Value) interface{} {
|
||||
// if _USE_RV_INTERFACE || rv.Kind() == reflect.Interface || rv.CanAddr() {
|
||||
// return rv.Interface()
|
||||
// }
|
||||
// // var i interface{}
|
||||
// // ui := (*unsafeIntf)(unsafe.Pointer(&i))
|
||||
// var ui unsafeIntf
|
||||
// urv := (*unsafeReflectValue)(unsafe.Pointer(&rv))
|
||||
// // fmt.Printf("urv: flag: %b, typ: %b, ptr: %b\n", urv.flag, uintptr(urv.typ), uintptr(urv.ptr))
|
||||
// if (urv.flag&unsafeRvFlagKindMask)&unsafeRvKindDirectIface == 0 {
|
||||
// if urv.flag&unsafeRvFlagAddr != 0 {
|
||||
// println("***** indirect and addressable! Needs typed move - delegate to rv.Interface()")
|
||||
// return rv.Interface()
|
||||
// }
|
||||
// println("****** indirect type/kind")
|
||||
// ui.word = urv.ptr
|
||||
// } else if urv.flag&unsafeRvFlagIndir != 0 {
|
||||
// println("****** unsafe rv flag indir")
|
||||
// ui.word = *(*unsafe.Pointer)(urv.ptr)
|
||||
// } else {
|
||||
// println("****** default: assign prt to word directly")
|
||||
// ui.word = urv.ptr
|
||||
// }
|
||||
// // ui.word = urv.ptr
|
||||
// ui.typ = urv.typ
|
||||
// // fmt.Printf("(pointers) ui.typ: %p, word: %p\n", ui.typ, ui.word)
|
||||
// // fmt.Printf("(binary) ui.typ: %b, word: %b\n", uintptr(ui.typ), uintptr(ui.word))
|
||||
// return *(*interface{})(unsafe.Pointer(&ui))
|
||||
// // return i
|
||||
// }
|
1422
vendor/github.com/ugorji/go/codec/json.go
generated
vendored
Normal file
1422
vendor/github.com/ugorji/go/codec/json.go
generated
vendored
Normal file
File diff suppressed because it is too large
Load Diff
154
vendor/github.com/ugorji/go/codec/mammoth-test.go.tmpl
generated
vendored
Normal file
154
vendor/github.com/ugorji/go/codec/mammoth-test.go.tmpl
generated
vendored
Normal file
@@ -0,0 +1,154 @@
|
||||
// Copyright (c) 2012-2015 Ugorji Nwoke. All rights reserved.
|
||||
// Use of this source code is governed by a MIT license found in the LICENSE file.
|
||||
|
||||
// Code generated from mammoth-test.go.tmpl - DO NOT EDIT.
|
||||
|
||||
package codec
|
||||
|
||||
import "testing"
|
||||
import "fmt"
|
||||
import "reflect"
|
||||
|
||||
// TestMammoth has all the different paths optimized in 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 }}
|
||||
{{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 }}
|
||||
v{{$i}}v1 = v
|
||||
bs{{$i}} := testMarshalErr(v{{$i}}v1, h, t, "enc-slice-v{{$i}}")
|
||||
if v == nil { v{{$i}}v2 = nil } 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}}")
|
||||
if v == nil { v{{$i}}v2 = nil } else { 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")
|
||||
// ...
|
||||
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
|
||||
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")
|
||||
}
|
||||
// ...
|
||||
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)
|
||||
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")
|
||||
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")
|
||||
}
|
||||
{{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 }}
|
||||
v{{$i}}v1 = v
|
||||
bs{{$i}} := testMarshalErr(v{{$i}}v1, h, t, "enc-map-v{{$i}}")
|
||||
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")
|
||||
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")
|
||||
// ...
|
||||
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)
|
||||
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")
|
||||
}
|
||||
{{end}}{{end}}{{end}}
|
||||
|
||||
}
|
||||
|
||||
func doTestMammothMapsAndSlices(t *testing.T, h Handle) {
|
||||
doTestMammothSlices(t, h)
|
||||
doTestMammothMaps(t, h)
|
||||
}
|
94
vendor/github.com/ugorji/go/codec/mammoth2-test.go.tmpl
generated
vendored
Normal file
94
vendor/github.com/ugorji/go/codec/mammoth2-test.go.tmpl
generated
vendored
Normal file
@@ -0,0 +1,94 @@
|
||||
// +build !notfastpath
|
||||
|
||||
// Copyright (c) 2012-2015 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....
|
||||
//
|
||||
// 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
|
||||
// - then
|
||||
//
|
||||
// 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)
|
||||
bigen.PutUint64(data, uint64(x))
|
||||
return
|
||||
}
|
||||
func (x *testMammoth2Binary) UnmarshalBinary(data []byte) (err error) {
|
||||
*x = testMammoth2Binary(bigen.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
|
||||
}
|
38478
vendor/github.com/ugorji/go/codec/mammoth2_codecgen_generated_test.go
generated
vendored
Normal file
38478
vendor/github.com/ugorji/go/codec/mammoth2_codecgen_generated_test.go
generated
vendored
Normal file
File diff suppressed because it is too large
Load Diff
658
vendor/github.com/ugorji/go/codec/mammoth2_generated_test.go
generated
vendored
Normal file
658
vendor/github.com/ugorji/go/codec/mammoth2_generated_test.go
generated
vendored
Normal file
@@ -0,0 +1,658 @@
|
||||
// +build !notfastpath
|
||||
|
||||
// Copyright (c) 2012-2015 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....
|
||||
//
|
||||
// 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
|
||||
// - then
|
||||
//
|
||||
// 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
|
||||
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
|
||||
FSliceFloat32 []float32
|
||||
FptrSliceFloat32 *[]float32
|
||||
FSliceFloat64 []float64
|
||||
FptrSliceFloat64 *[]float64
|
||||
FSliceUint []uint
|
||||
FptrSliceUint *[]uint
|
||||
FSliceUint8 []uint8
|
||||
FptrSliceUint8 *[]uint8
|
||||
FSliceUint16 []uint16
|
||||
FptrSliceUint16 *[]uint16
|
||||
FSliceUint32 []uint32
|
||||
FptrSliceUint32 *[]uint32
|
||||
FSliceUint64 []uint64
|
||||
FptrSliceUint64 *[]uint64
|
||||
FSliceUintptr []uintptr
|
||||
FptrSliceUintptr *[]uintptr
|
||||
FSliceInt []int
|
||||
FptrSliceInt *[]int
|
||||
FSliceInt8 []int8
|
||||
FptrSliceInt8 *[]int8
|
||||
FSliceInt16 []int16
|
||||
FptrSliceInt16 *[]int16
|
||||
FSliceInt32 []int32
|
||||
FptrSliceInt32 *[]int32
|
||||
FSliceInt64 []int64
|
||||
FptrSliceInt64 *[]int64
|
||||
FSliceBool []bool
|
||||
FptrSliceBool *[]bool
|
||||
|
||||
FMapIntfIntf map[interface{}]interface{}
|
||||
FptrMapIntfIntf *map[interface{}]interface{}
|
||||
FMapIntfString map[interface{}]string
|
||||
FptrMapIntfString *map[interface{}]string
|
||||
FMapIntfUint map[interface{}]uint
|
||||
FptrMapIntfUint *map[interface{}]uint
|
||||
FMapIntfUint8 map[interface{}]uint8
|
||||
FptrMapIntfUint8 *map[interface{}]uint8
|
||||
FMapIntfUint16 map[interface{}]uint16
|
||||
FptrMapIntfUint16 *map[interface{}]uint16
|
||||
FMapIntfUint32 map[interface{}]uint32
|
||||
FptrMapIntfUint32 *map[interface{}]uint32
|
||||
FMapIntfUint64 map[interface{}]uint64
|
||||
FptrMapIntfUint64 *map[interface{}]uint64
|
||||
FMapIntfUintptr map[interface{}]uintptr
|
||||
FptrMapIntfUintptr *map[interface{}]uintptr
|
||||
FMapIntfInt map[interface{}]int
|
||||
FptrMapIntfInt *map[interface{}]int
|
||||
FMapIntfInt8 map[interface{}]int8
|
||||
FptrMapIntfInt8 *map[interface{}]int8
|
||||
FMapIntfInt16 map[interface{}]int16
|
||||
FptrMapIntfInt16 *map[interface{}]int16
|
||||
FMapIntfInt32 map[interface{}]int32
|
||||
FptrMapIntfInt32 *map[interface{}]int32
|
||||
FMapIntfInt64 map[interface{}]int64
|
||||
FptrMapIntfInt64 *map[interface{}]int64
|
||||
FMapIntfFloat32 map[interface{}]float32
|
||||
FptrMapIntfFloat32 *map[interface{}]float32
|
||||
FMapIntfFloat64 map[interface{}]float64
|
||||
FptrMapIntfFloat64 *map[interface{}]float64
|
||||
FMapIntfBool map[interface{}]bool
|
||||
FptrMapIntfBool *map[interface{}]bool
|
||||
FMapStringIntf map[string]interface{}
|
||||
FptrMapStringIntf *map[string]interface{}
|
||||
FMapStringString map[string]string
|
||||
FptrMapStringString *map[string]string
|
||||
FMapStringUint map[string]uint
|
||||
FptrMapStringUint *map[string]uint
|
||||
FMapStringUint8 map[string]uint8
|
||||
FptrMapStringUint8 *map[string]uint8
|
||||
FMapStringUint16 map[string]uint16
|
||||
FptrMapStringUint16 *map[string]uint16
|
||||
FMapStringUint32 map[string]uint32
|
||||
FptrMapStringUint32 *map[string]uint32
|
||||
FMapStringUint64 map[string]uint64
|
||||
FptrMapStringUint64 *map[string]uint64
|
||||
FMapStringUintptr map[string]uintptr
|
||||
FptrMapStringUintptr *map[string]uintptr
|
||||
FMapStringInt map[string]int
|
||||
FptrMapStringInt *map[string]int
|
||||
FMapStringInt8 map[string]int8
|
||||
FptrMapStringInt8 *map[string]int8
|
||||
FMapStringInt16 map[string]int16
|
||||
FptrMapStringInt16 *map[string]int16
|
||||
FMapStringInt32 map[string]int32
|
||||
FptrMapStringInt32 *map[string]int32
|
||||
FMapStringInt64 map[string]int64
|
||||
FptrMapStringInt64 *map[string]int64
|
||||
FMapStringFloat32 map[string]float32
|
||||
FptrMapStringFloat32 *map[string]float32
|
||||
FMapStringFloat64 map[string]float64
|
||||
FptrMapStringFloat64 *map[string]float64
|
||||
FMapStringBool map[string]bool
|
||||
FptrMapStringBool *map[string]bool
|
||||
FMapFloat32Intf map[float32]interface{}
|
||||
FptrMapFloat32Intf *map[float32]interface{}
|
||||
FMapFloat32String map[float32]string
|
||||
FptrMapFloat32String *map[float32]string
|
||||
FMapFloat32Uint map[float32]uint
|
||||
FptrMapFloat32Uint *map[float32]uint
|
||||
FMapFloat32Uint8 map[float32]uint8
|
||||
FptrMapFloat32Uint8 *map[float32]uint8
|
||||
FMapFloat32Uint16 map[float32]uint16
|
||||
FptrMapFloat32Uint16 *map[float32]uint16
|
||||
FMapFloat32Uint32 map[float32]uint32
|
||||
FptrMapFloat32Uint32 *map[float32]uint32
|
||||
FMapFloat32Uint64 map[float32]uint64
|
||||
FptrMapFloat32Uint64 *map[float32]uint64
|
||||
FMapFloat32Uintptr map[float32]uintptr
|
||||
FptrMapFloat32Uintptr *map[float32]uintptr
|
||||
FMapFloat32Int map[float32]int
|
||||
FptrMapFloat32Int *map[float32]int
|
||||
FMapFloat32Int8 map[float32]int8
|
||||
FptrMapFloat32Int8 *map[float32]int8
|
||||
FMapFloat32Int16 map[float32]int16
|
||||
FptrMapFloat32Int16 *map[float32]int16
|
||||
FMapFloat32Int32 map[float32]int32
|
||||
FptrMapFloat32Int32 *map[float32]int32
|
||||
FMapFloat32Int64 map[float32]int64
|
||||
FptrMapFloat32Int64 *map[float32]int64
|
||||
FMapFloat32Float32 map[float32]float32
|
||||
FptrMapFloat32Float32 *map[float32]float32
|
||||
FMapFloat32Float64 map[float32]float64
|
||||
FptrMapFloat32Float64 *map[float32]float64
|
||||
FMapFloat32Bool map[float32]bool
|
||||
FptrMapFloat32Bool *map[float32]bool
|
||||
FMapFloat64Intf map[float64]interface{}
|
||||
FptrMapFloat64Intf *map[float64]interface{}
|
||||
FMapFloat64String map[float64]string
|
||||
FptrMapFloat64String *map[float64]string
|
||||
FMapFloat64Uint map[float64]uint
|
||||
FptrMapFloat64Uint *map[float64]uint
|
||||
FMapFloat64Uint8 map[float64]uint8
|
||||
FptrMapFloat64Uint8 *map[float64]uint8
|
||||
FMapFloat64Uint16 map[float64]uint16
|
||||
FptrMapFloat64Uint16 *map[float64]uint16
|
||||
FMapFloat64Uint32 map[float64]uint32
|
||||
FptrMapFloat64Uint32 *map[float64]uint32
|
||||
FMapFloat64Uint64 map[float64]uint64
|
||||
FptrMapFloat64Uint64 *map[float64]uint64
|
||||
FMapFloat64Uintptr map[float64]uintptr
|
||||
FptrMapFloat64Uintptr *map[float64]uintptr
|
||||
FMapFloat64Int map[float64]int
|
||||
FptrMapFloat64Int *map[float64]int
|
||||
FMapFloat64Int8 map[float64]int8
|
||||
FptrMapFloat64Int8 *map[float64]int8
|
||||
FMapFloat64Int16 map[float64]int16
|
||||
FptrMapFloat64Int16 *map[float64]int16
|
||||
FMapFloat64Int32 map[float64]int32
|
||||
FptrMapFloat64Int32 *map[float64]int32
|
||||
FMapFloat64Int64 map[float64]int64
|
||||
FptrMapFloat64Int64 *map[float64]int64
|
||||
FMapFloat64Float32 map[float64]float32
|
||||
FptrMapFloat64Float32 *map[float64]float32
|
||||
FMapFloat64Float64 map[float64]float64
|
||||
FptrMapFloat64Float64 *map[float64]float64
|
||||
FMapFloat64Bool map[float64]bool
|
||||
FptrMapFloat64Bool *map[float64]bool
|
||||
FMapUintIntf map[uint]interface{}
|
||||
FptrMapUintIntf *map[uint]interface{}
|
||||
FMapUintString map[uint]string
|
||||
FptrMapUintString *map[uint]string
|
||||
FMapUintUint map[uint]uint
|
||||
FptrMapUintUint *map[uint]uint
|
||||
FMapUintUint8 map[uint]uint8
|
||||
FptrMapUintUint8 *map[uint]uint8
|
||||
FMapUintUint16 map[uint]uint16
|
||||
FptrMapUintUint16 *map[uint]uint16
|
||||
FMapUintUint32 map[uint]uint32
|
||||
FptrMapUintUint32 *map[uint]uint32
|
||||
FMapUintUint64 map[uint]uint64
|
||||
FptrMapUintUint64 *map[uint]uint64
|
||||
FMapUintUintptr map[uint]uintptr
|
||||
FptrMapUintUintptr *map[uint]uintptr
|
||||
FMapUintInt map[uint]int
|
||||
FptrMapUintInt *map[uint]int
|
||||
FMapUintInt8 map[uint]int8
|
||||
FptrMapUintInt8 *map[uint]int8
|
||||
FMapUintInt16 map[uint]int16
|
||||
FptrMapUintInt16 *map[uint]int16
|
||||
FMapUintInt32 map[uint]int32
|
||||
FptrMapUintInt32 *map[uint]int32
|
||||
FMapUintInt64 map[uint]int64
|
||||
FptrMapUintInt64 *map[uint]int64
|
||||
FMapUintFloat32 map[uint]float32
|
||||
FptrMapUintFloat32 *map[uint]float32
|
||||
FMapUintFloat64 map[uint]float64
|
||||
FptrMapUintFloat64 *map[uint]float64
|
||||
FMapUintBool map[uint]bool
|
||||
FptrMapUintBool *map[uint]bool
|
||||
FMapUint8Intf map[uint8]interface{}
|
||||
FptrMapUint8Intf *map[uint8]interface{}
|
||||
FMapUint8String map[uint8]string
|
||||
FptrMapUint8String *map[uint8]string
|
||||
FMapUint8Uint map[uint8]uint
|
||||
FptrMapUint8Uint *map[uint8]uint
|
||||
FMapUint8Uint8 map[uint8]uint8
|
||||
FptrMapUint8Uint8 *map[uint8]uint8
|
||||
FMapUint8Uint16 map[uint8]uint16
|
||||
FptrMapUint8Uint16 *map[uint8]uint16
|
||||
FMapUint8Uint32 map[uint8]uint32
|
||||
FptrMapUint8Uint32 *map[uint8]uint32
|
||||
FMapUint8Uint64 map[uint8]uint64
|
||||
FptrMapUint8Uint64 *map[uint8]uint64
|
||||
FMapUint8Uintptr map[uint8]uintptr
|
||||
FptrMapUint8Uintptr *map[uint8]uintptr
|
||||
FMapUint8Int map[uint8]int
|
||||
FptrMapUint8Int *map[uint8]int
|
||||
FMapUint8Int8 map[uint8]int8
|
||||
FptrMapUint8Int8 *map[uint8]int8
|
||||
FMapUint8Int16 map[uint8]int16
|
||||
FptrMapUint8Int16 *map[uint8]int16
|
||||
FMapUint8Int32 map[uint8]int32
|
||||
FptrMapUint8Int32 *map[uint8]int32
|
||||
FMapUint8Int64 map[uint8]int64
|
||||
FptrMapUint8Int64 *map[uint8]int64
|
||||
FMapUint8Float32 map[uint8]float32
|
||||
FptrMapUint8Float32 *map[uint8]float32
|
||||
FMapUint8Float64 map[uint8]float64
|
||||
FptrMapUint8Float64 *map[uint8]float64
|
||||
FMapUint8Bool map[uint8]bool
|
||||
FptrMapUint8Bool *map[uint8]bool
|
||||
FMapUint16Intf map[uint16]interface{}
|
||||
FptrMapUint16Intf *map[uint16]interface{}
|
||||
FMapUint16String map[uint16]string
|
||||
FptrMapUint16String *map[uint16]string
|
||||
FMapUint16Uint map[uint16]uint
|
||||
FptrMapUint16Uint *map[uint16]uint
|
||||
FMapUint16Uint8 map[uint16]uint8
|
||||
FptrMapUint16Uint8 *map[uint16]uint8
|
||||
FMapUint16Uint16 map[uint16]uint16
|
||||
FptrMapUint16Uint16 *map[uint16]uint16
|
||||
FMapUint16Uint32 map[uint16]uint32
|
||||
FptrMapUint16Uint32 *map[uint16]uint32
|
||||
FMapUint16Uint64 map[uint16]uint64
|
||||
FptrMapUint16Uint64 *map[uint16]uint64
|
||||
FMapUint16Uintptr map[uint16]uintptr
|
||||
FptrMapUint16Uintptr *map[uint16]uintptr
|
||||
FMapUint16Int map[uint16]int
|
||||
FptrMapUint16Int *map[uint16]int
|
||||
FMapUint16Int8 map[uint16]int8
|
||||
FptrMapUint16Int8 *map[uint16]int8
|
||||
FMapUint16Int16 map[uint16]int16
|
||||
FptrMapUint16Int16 *map[uint16]int16
|
||||
FMapUint16Int32 map[uint16]int32
|
||||
FptrMapUint16Int32 *map[uint16]int32
|
||||
FMapUint16Int64 map[uint16]int64
|
||||
FptrMapUint16Int64 *map[uint16]int64
|
||||
FMapUint16Float32 map[uint16]float32
|
||||
FptrMapUint16Float32 *map[uint16]float32
|
||||
FMapUint16Float64 map[uint16]float64
|
||||
FptrMapUint16Float64 *map[uint16]float64
|
||||
FMapUint16Bool map[uint16]bool
|
||||
FptrMapUint16Bool *map[uint16]bool
|
||||
FMapUint32Intf map[uint32]interface{}
|
||||
FptrMapUint32Intf *map[uint32]interface{}
|
||||
FMapUint32String map[uint32]string
|
||||
FptrMapUint32String *map[uint32]string
|
||||
FMapUint32Uint map[uint32]uint
|
||||
FptrMapUint32Uint *map[uint32]uint
|
||||
FMapUint32Uint8 map[uint32]uint8
|
||||
FptrMapUint32Uint8 *map[uint32]uint8
|
||||
FMapUint32Uint16 map[uint32]uint16
|
||||
FptrMapUint32Uint16 *map[uint32]uint16
|
||||
FMapUint32Uint32 map[uint32]uint32
|
||||
FptrMapUint32Uint32 *map[uint32]uint32
|
||||
FMapUint32Uint64 map[uint32]uint64
|
||||
FptrMapUint32Uint64 *map[uint32]uint64
|
||||
FMapUint32Uintptr map[uint32]uintptr
|
||||
FptrMapUint32Uintptr *map[uint32]uintptr
|
||||
FMapUint32Int map[uint32]int
|
||||
FptrMapUint32Int *map[uint32]int
|
||||
FMapUint32Int8 map[uint32]int8
|
||||
FptrMapUint32Int8 *map[uint32]int8
|
||||
FMapUint32Int16 map[uint32]int16
|
||||
FptrMapUint32Int16 *map[uint32]int16
|
||||
FMapUint32Int32 map[uint32]int32
|
||||
FptrMapUint32Int32 *map[uint32]int32
|
||||
FMapUint32Int64 map[uint32]int64
|
||||
FptrMapUint32Int64 *map[uint32]int64
|
||||
FMapUint32Float32 map[uint32]float32
|
||||
FptrMapUint32Float32 *map[uint32]float32
|
||||
FMapUint32Float64 map[uint32]float64
|
||||
FptrMapUint32Float64 *map[uint32]float64
|
||||
FMapUint32Bool map[uint32]bool
|
||||
FptrMapUint32Bool *map[uint32]bool
|
||||
FMapUint64Intf map[uint64]interface{}
|
||||
FptrMapUint64Intf *map[uint64]interface{}
|
||||
FMapUint64String map[uint64]string
|
||||
FptrMapUint64String *map[uint64]string
|
||||
FMapUint64Uint map[uint64]uint
|
||||
FptrMapUint64Uint *map[uint64]uint
|
||||
FMapUint64Uint8 map[uint64]uint8
|
||||
FptrMapUint64Uint8 *map[uint64]uint8
|
||||
FMapUint64Uint16 map[uint64]uint16
|
||||
FptrMapUint64Uint16 *map[uint64]uint16
|
||||
FMapUint64Uint32 map[uint64]uint32
|
||||
FptrMapUint64Uint32 *map[uint64]uint32
|
||||
FMapUint64Uint64 map[uint64]uint64
|
||||
FptrMapUint64Uint64 *map[uint64]uint64
|
||||
FMapUint64Uintptr map[uint64]uintptr
|
||||
FptrMapUint64Uintptr *map[uint64]uintptr
|
||||
FMapUint64Int map[uint64]int
|
||||
FptrMapUint64Int *map[uint64]int
|
||||
FMapUint64Int8 map[uint64]int8
|
||||
FptrMapUint64Int8 *map[uint64]int8
|
||||
FMapUint64Int16 map[uint64]int16
|
||||
FptrMapUint64Int16 *map[uint64]int16
|
||||
FMapUint64Int32 map[uint64]int32
|
||||
FptrMapUint64Int32 *map[uint64]int32
|
||||
FMapUint64Int64 map[uint64]int64
|
||||
FptrMapUint64Int64 *map[uint64]int64
|
||||
FMapUint64Float32 map[uint64]float32
|
||||
FptrMapUint64Float32 *map[uint64]float32
|
||||
FMapUint64Float64 map[uint64]float64
|
||||
FptrMapUint64Float64 *map[uint64]float64
|
||||
FMapUint64Bool map[uint64]bool
|
||||
FptrMapUint64Bool *map[uint64]bool
|
||||
FMapUintptrIntf map[uintptr]interface{}
|
||||
FptrMapUintptrIntf *map[uintptr]interface{}
|
||||
FMapUintptrString map[uintptr]string
|
||||
FptrMapUintptrString *map[uintptr]string
|
||||
FMapUintptrUint map[uintptr]uint
|
||||
FptrMapUintptrUint *map[uintptr]uint
|
||||
FMapUintptrUint8 map[uintptr]uint8
|
||||
FptrMapUintptrUint8 *map[uintptr]uint8
|
||||
FMapUintptrUint16 map[uintptr]uint16
|
||||
FptrMapUintptrUint16 *map[uintptr]uint16
|
||||
FMapUintptrUint32 map[uintptr]uint32
|
||||
FptrMapUintptrUint32 *map[uintptr]uint32
|
||||
FMapUintptrUint64 map[uintptr]uint64
|
||||
FptrMapUintptrUint64 *map[uintptr]uint64
|
||||
FMapUintptrUintptr map[uintptr]uintptr
|
||||
FptrMapUintptrUintptr *map[uintptr]uintptr
|
||||
FMapUintptrInt map[uintptr]int
|
||||
FptrMapUintptrInt *map[uintptr]int
|
||||
FMapUintptrInt8 map[uintptr]int8
|
||||
FptrMapUintptrInt8 *map[uintptr]int8
|
||||
FMapUintptrInt16 map[uintptr]int16
|
||||
FptrMapUintptrInt16 *map[uintptr]int16
|
||||
FMapUintptrInt32 map[uintptr]int32
|
||||
FptrMapUintptrInt32 *map[uintptr]int32
|
||||
FMapUintptrInt64 map[uintptr]int64
|
||||
FptrMapUintptrInt64 *map[uintptr]int64
|
||||
FMapUintptrFloat32 map[uintptr]float32
|
||||
FptrMapUintptrFloat32 *map[uintptr]float32
|
||||
FMapUintptrFloat64 map[uintptr]float64
|
||||
FptrMapUintptrFloat64 *map[uintptr]float64
|
||||
FMapUintptrBool map[uintptr]bool
|
||||
FptrMapUintptrBool *map[uintptr]bool
|
||||
FMapIntIntf map[int]interface{}
|
||||
FptrMapIntIntf *map[int]interface{}
|
||||
FMapIntString map[int]string
|
||||
FptrMapIntString *map[int]string
|
||||
FMapIntUint map[int]uint
|
||||
FptrMapIntUint *map[int]uint
|
||||
FMapIntUint8 map[int]uint8
|
||||
FptrMapIntUint8 *map[int]uint8
|
||||
FMapIntUint16 map[int]uint16
|
||||
FptrMapIntUint16 *map[int]uint16
|
||||
FMapIntUint32 map[int]uint32
|
||||
FptrMapIntUint32 *map[int]uint32
|
||||
FMapIntUint64 map[int]uint64
|
||||
FptrMapIntUint64 *map[int]uint64
|
||||
FMapIntUintptr map[int]uintptr
|
||||
FptrMapIntUintptr *map[int]uintptr
|
||||
FMapIntInt map[int]int
|
||||
FptrMapIntInt *map[int]int
|
||||
FMapIntInt8 map[int]int8
|
||||
FptrMapIntInt8 *map[int]int8
|
||||
FMapIntInt16 map[int]int16
|
||||
FptrMapIntInt16 *map[int]int16
|
||||
FMapIntInt32 map[int]int32
|
||||
FptrMapIntInt32 *map[int]int32
|
||||
FMapIntInt64 map[int]int64
|
||||
FptrMapIntInt64 *map[int]int64
|
||||
FMapIntFloat32 map[int]float32
|
||||
FptrMapIntFloat32 *map[int]float32
|
||||
FMapIntFloat64 map[int]float64
|
||||
FptrMapIntFloat64 *map[int]float64
|
||||
FMapIntBool map[int]bool
|
||||
FptrMapIntBool *map[int]bool
|
||||
FMapInt8Intf map[int8]interface{}
|
||||
FptrMapInt8Intf *map[int8]interface{}
|
||||
FMapInt8String map[int8]string
|
||||
FptrMapInt8String *map[int8]string
|
||||
FMapInt8Uint map[int8]uint
|
||||
FptrMapInt8Uint *map[int8]uint
|
||||
FMapInt8Uint8 map[int8]uint8
|
||||
FptrMapInt8Uint8 *map[int8]uint8
|
||||
FMapInt8Uint16 map[int8]uint16
|
||||
FptrMapInt8Uint16 *map[int8]uint16
|
||||
FMapInt8Uint32 map[int8]uint32
|
||||
FptrMapInt8Uint32 *map[int8]uint32
|
||||
FMapInt8Uint64 map[int8]uint64
|
||||
FptrMapInt8Uint64 *map[int8]uint64
|
||||
FMapInt8Uintptr map[int8]uintptr
|
||||
FptrMapInt8Uintptr *map[int8]uintptr
|
||||
FMapInt8Int map[int8]int
|
||||
FptrMapInt8Int *map[int8]int
|
||||
FMapInt8Int8 map[int8]int8
|
||||
FptrMapInt8Int8 *map[int8]int8
|
||||
FMapInt8Int16 map[int8]int16
|
||||
FptrMapInt8Int16 *map[int8]int16
|
||||
FMapInt8Int32 map[int8]int32
|
||||
FptrMapInt8Int32 *map[int8]int32
|
||||
FMapInt8Int64 map[int8]int64
|
||||
FptrMapInt8Int64 *map[int8]int64
|
||||
FMapInt8Float32 map[int8]float32
|
||||
FptrMapInt8Float32 *map[int8]float32
|
||||
FMapInt8Float64 map[int8]float64
|
||||
FptrMapInt8Float64 *map[int8]float64
|
||||
FMapInt8Bool map[int8]bool
|
||||
FptrMapInt8Bool *map[int8]bool
|
||||
FMapInt16Intf map[int16]interface{}
|
||||
FptrMapInt16Intf *map[int16]interface{}
|
||||
FMapInt16String map[int16]string
|
||||
FptrMapInt16String *map[int16]string
|
||||
FMapInt16Uint map[int16]uint
|
||||
FptrMapInt16Uint *map[int16]uint
|
||||
FMapInt16Uint8 map[int16]uint8
|
||||
FptrMapInt16Uint8 *map[int16]uint8
|
||||
FMapInt16Uint16 map[int16]uint16
|
||||
FptrMapInt16Uint16 *map[int16]uint16
|
||||
FMapInt16Uint32 map[int16]uint32
|
||||
FptrMapInt16Uint32 *map[int16]uint32
|
||||
FMapInt16Uint64 map[int16]uint64
|
||||
FptrMapInt16Uint64 *map[int16]uint64
|
||||
FMapInt16Uintptr map[int16]uintptr
|
||||
FptrMapInt16Uintptr *map[int16]uintptr
|
||||
FMapInt16Int map[int16]int
|
||||
FptrMapInt16Int *map[int16]int
|
||||
FMapInt16Int8 map[int16]int8
|
||||
FptrMapInt16Int8 *map[int16]int8
|
||||
FMapInt16Int16 map[int16]int16
|
||||
FptrMapInt16Int16 *map[int16]int16
|
||||
FMapInt16Int32 map[int16]int32
|
||||
FptrMapInt16Int32 *map[int16]int32
|
||||
FMapInt16Int64 map[int16]int64
|
||||
FptrMapInt16Int64 *map[int16]int64
|
||||
FMapInt16Float32 map[int16]float32
|
||||
FptrMapInt16Float32 *map[int16]float32
|
||||
FMapInt16Float64 map[int16]float64
|
||||
FptrMapInt16Float64 *map[int16]float64
|
||||
FMapInt16Bool map[int16]bool
|
||||
FptrMapInt16Bool *map[int16]bool
|
||||
FMapInt32Intf map[int32]interface{}
|
||||
FptrMapInt32Intf *map[int32]interface{}
|
||||
FMapInt32String map[int32]string
|
||||
FptrMapInt32String *map[int32]string
|
||||
FMapInt32Uint map[int32]uint
|
||||
FptrMapInt32Uint *map[int32]uint
|
||||
FMapInt32Uint8 map[int32]uint8
|
||||
FptrMapInt32Uint8 *map[int32]uint8
|
||||
FMapInt32Uint16 map[int32]uint16
|
||||
FptrMapInt32Uint16 *map[int32]uint16
|
||||
FMapInt32Uint32 map[int32]uint32
|
||||
FptrMapInt32Uint32 *map[int32]uint32
|
||||
FMapInt32Uint64 map[int32]uint64
|
||||
FptrMapInt32Uint64 *map[int32]uint64
|
||||
FMapInt32Uintptr map[int32]uintptr
|
||||
FptrMapInt32Uintptr *map[int32]uintptr
|
||||
FMapInt32Int map[int32]int
|
||||
FptrMapInt32Int *map[int32]int
|
||||
FMapInt32Int8 map[int32]int8
|
||||
FptrMapInt32Int8 *map[int32]int8
|
||||
FMapInt32Int16 map[int32]int16
|
||||
FptrMapInt32Int16 *map[int32]int16
|
||||
FMapInt32Int32 map[int32]int32
|
||||
FptrMapInt32Int32 *map[int32]int32
|
||||
FMapInt32Int64 map[int32]int64
|
||||
FptrMapInt32Int64 *map[int32]int64
|
||||
FMapInt32Float32 map[int32]float32
|
||||
FptrMapInt32Float32 *map[int32]float32
|
||||
FMapInt32Float64 map[int32]float64
|
||||
FptrMapInt32Float64 *map[int32]float64
|
||||
FMapInt32Bool map[int32]bool
|
||||
FptrMapInt32Bool *map[int32]bool
|
||||
FMapInt64Intf map[int64]interface{}
|
||||
FptrMapInt64Intf *map[int64]interface{}
|
||||
FMapInt64String map[int64]string
|
||||
FptrMapInt64String *map[int64]string
|
||||
FMapInt64Uint map[int64]uint
|
||||
FptrMapInt64Uint *map[int64]uint
|
||||
FMapInt64Uint8 map[int64]uint8
|
||||
FptrMapInt64Uint8 *map[int64]uint8
|
||||
FMapInt64Uint16 map[int64]uint16
|
||||
FptrMapInt64Uint16 *map[int64]uint16
|
||||
FMapInt64Uint32 map[int64]uint32
|
||||
FptrMapInt64Uint32 *map[int64]uint32
|
||||
FMapInt64Uint64 map[int64]uint64
|
||||
FptrMapInt64Uint64 *map[int64]uint64
|
||||
FMapInt64Uintptr map[int64]uintptr
|
||||
FptrMapInt64Uintptr *map[int64]uintptr
|
||||
FMapInt64Int map[int64]int
|
||||
FptrMapInt64Int *map[int64]int
|
||||
FMapInt64Int8 map[int64]int8
|
||||
FptrMapInt64Int8 *map[int64]int8
|
||||
FMapInt64Int16 map[int64]int16
|
||||
FptrMapInt64Int16 *map[int64]int16
|
||||
FMapInt64Int32 map[int64]int32
|
||||
FptrMapInt64Int32 *map[int64]int32
|
||||
FMapInt64Int64 map[int64]int64
|
||||
FptrMapInt64Int64 *map[int64]int64
|
||||
FMapInt64Float32 map[int64]float32
|
||||
FptrMapInt64Float32 *map[int64]float32
|
||||
FMapInt64Float64 map[int64]float64
|
||||
FptrMapInt64Float64 *map[int64]float64
|
||||
FMapInt64Bool map[int64]bool
|
||||
FptrMapInt64Bool *map[int64]bool
|
||||
FMapBoolIntf map[bool]interface{}
|
||||
FptrMapBoolIntf *map[bool]interface{}
|
||||
FMapBoolString map[bool]string
|
||||
FptrMapBoolString *map[bool]string
|
||||
FMapBoolUint map[bool]uint
|
||||
FptrMapBoolUint *map[bool]uint
|
||||
FMapBoolUint8 map[bool]uint8
|
||||
FptrMapBoolUint8 *map[bool]uint8
|
||||
FMapBoolUint16 map[bool]uint16
|
||||
FptrMapBoolUint16 *map[bool]uint16
|
||||
FMapBoolUint32 map[bool]uint32
|
||||
FptrMapBoolUint32 *map[bool]uint32
|
||||
FMapBoolUint64 map[bool]uint64
|
||||
FptrMapBoolUint64 *map[bool]uint64
|
||||
FMapBoolUintptr map[bool]uintptr
|
||||
FptrMapBoolUintptr *map[bool]uintptr
|
||||
FMapBoolInt map[bool]int
|
||||
FptrMapBoolInt *map[bool]int
|
||||
FMapBoolInt8 map[bool]int8
|
||||
FptrMapBoolInt8 *map[bool]int8
|
||||
FMapBoolInt16 map[bool]int16
|
||||
FptrMapBoolInt16 *map[bool]int16
|
||||
FMapBoolInt32 map[bool]int32
|
||||
FptrMapBoolInt32 *map[bool]int32
|
||||
FMapBoolInt64 map[bool]int64
|
||||
FptrMapBoolInt64 *map[bool]int64
|
||||
FMapBoolFloat32 map[bool]float32
|
||||
FptrMapBoolFloat32 *map[bool]float32
|
||||
FMapBoolFloat64 map[bool]float64
|
||||
FptrMapBoolFloat64 *map[bool]float64
|
||||
FMapBoolBool map[bool]bool
|
||||
FptrMapBoolBool *map[bool]bool
|
||||
}
|
||||
|
||||
// -----------
|
||||
|
||||
type testMammoth2Binary uint64
|
||||
|
||||
func (x testMammoth2Binary) MarshalBinary() (data []byte, err error) {
|
||||
data = make([]byte, 8)
|
||||
bigen.PutUint64(data, uint64(x))
|
||||
return
|
||||
}
|
||||
func (x *testMammoth2Binary) UnmarshalBinary(data []byte) (err error) {
|
||||
*x = testMammoth2Binary(bigen.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
|
||||
}
|
13188
vendor/github.com/ugorji/go/codec/mammoth_generated_test.go
generated
vendored
Normal file
13188
vendor/github.com/ugorji/go/codec/mammoth_generated_test.go
generated
vendored
Normal file
File diff suppressed because it is too large
Load Diff
1012
vendor/github.com/ugorji/go/codec/msgpack.go
generated
vendored
Normal file
1012
vendor/github.com/ugorji/go/codec/msgpack.go
generated
vendored
Normal file
File diff suppressed because it is too large
Load Diff
219
vendor/github.com/ugorji/go/codec/noop.go
generated
vendored
Normal file
219
vendor/github.com/ugorji/go/codec/noop.go
generated
vendored
Normal file
@@ -0,0 +1,219 @@
|
||||
// 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.
|
||||
|
||||
// +build ignore
|
||||
|
||||
package codec
|
||||
|
||||
import (
|
||||
"math/rand"
|
||||
"time"
|
||||
)
|
||||
|
||||
// NoopHandle returns a no-op handle. It basically does nothing.
|
||||
// It is only useful for benchmarking, as it gives an idea of the
|
||||
// overhead from the codec framework.
|
||||
//
|
||||
// LIBRARY USERS: *** DO NOT USE ***
|
||||
func NoopHandle(slen int) *noopHandle {
|
||||
h := noopHandle{}
|
||||
h.rand = rand.New(rand.NewSource(time.Now().UnixNano()))
|
||||
h.B = make([][]byte, slen)
|
||||
h.S = make([]string, slen)
|
||||
for i := 0; i < len(h.S); i++ {
|
||||
b := make([]byte, i+1)
|
||||
for j := 0; j < len(b); j++ {
|
||||
b[j] = 'a' + byte(i)
|
||||
}
|
||||
h.B[i] = b
|
||||
h.S[i] = string(b)
|
||||
}
|
||||
return &h
|
||||
}
|
||||
|
||||
// noopHandle does nothing.
|
||||
// It is used to simulate the overhead of the codec framework.
|
||||
type noopHandle struct {
|
||||
BasicHandle
|
||||
binaryEncodingType
|
||||
noopDrv // noopDrv is unexported here, so we can get a copy of it when needed.
|
||||
}
|
||||
|
||||
type noopDrv struct {
|
||||
d *Decoder
|
||||
e *Encoder
|
||||
i int
|
||||
S []string
|
||||
B [][]byte
|
||||
mks []bool // stack. if map (true), else if array (false)
|
||||
mk bool // top of stack. what container are we on? map or array?
|
||||
ct valueType // last response for IsContainerType.
|
||||
cb int // counter for ContainerType
|
||||
rand *rand.Rand
|
||||
}
|
||||
|
||||
func (h *noopDrv) r(v int) int { return h.rand.Intn(v) }
|
||||
func (h *noopDrv) m(v int) int { h.i++; return h.i % v }
|
||||
|
||||
func (h *noopDrv) newEncDriver(e *Encoder) encDriver { h.e = e; return h }
|
||||
func (h *noopDrv) newDecDriver(d *Decoder) decDriver { h.d = d; return h }
|
||||
|
||||
func (h *noopDrv) reset() {}
|
||||
func (h *noopDrv) uncacheRead() {}
|
||||
|
||||
// --- encDriver
|
||||
|
||||
// stack functions (for map and array)
|
||||
func (h *noopDrv) start(b bool) {
|
||||
// println("start", len(h.mks)+1)
|
||||
h.mks = append(h.mks, b)
|
||||
h.mk = b
|
||||
}
|
||||
func (h *noopDrv) end() {
|
||||
// println("end: ", len(h.mks)-1)
|
||||
h.mks = h.mks[:len(h.mks)-1]
|
||||
if len(h.mks) > 0 {
|
||||
h.mk = h.mks[len(h.mks)-1]
|
||||
} else {
|
||||
h.mk = false
|
||||
}
|
||||
}
|
||||
|
||||
func (h *noopDrv) EncodeBuiltin(rt uintptr, v interface{}) {}
|
||||
func (h *noopDrv) EncodeNil() {}
|
||||
func (h *noopDrv) EncodeInt(i int64) {}
|
||||
func (h *noopDrv) EncodeUint(i uint64) {}
|
||||
func (h *noopDrv) EncodeBool(b bool) {}
|
||||
func (h *noopDrv) EncodeFloat32(f float32) {}
|
||||
func (h *noopDrv) EncodeFloat64(f float64) {}
|
||||
func (h *noopDrv) EncodeRawExt(re *RawExt, e *Encoder) {}
|
||||
func (h *noopDrv) EncodeArrayStart(length int) { h.start(true) }
|
||||
func (h *noopDrv) EncodeMapStart(length int) { h.start(false) }
|
||||
func (h *noopDrv) EncodeEnd() { h.end() }
|
||||
|
||||
func (h *noopDrv) EncodeString(c charEncoding, v string) {}
|
||||
|
||||
// func (h *noopDrv) EncodeSymbol(v string) {}
|
||||
func (h *noopDrv) EncodeStringBytes(c charEncoding, v []byte) {}
|
||||
|
||||
func (h *noopDrv) EncodeExt(rv interface{}, xtag uint64, ext Ext, e *Encoder) {}
|
||||
|
||||
// ---- decDriver
|
||||
func (h *noopDrv) initReadNext() {}
|
||||
func (h *noopDrv) CheckBreak() bool { return false }
|
||||
func (h *noopDrv) IsBuiltinType(rt uintptr) bool { return false }
|
||||
func (h *noopDrv) DecodeBuiltin(rt uintptr, v interface{}) {}
|
||||
func (h *noopDrv) DecodeInt(bitsize uint8) (i int64) { return int64(h.m(15)) }
|
||||
func (h *noopDrv) DecodeUint(bitsize uint8) (ui uint64) { return uint64(h.m(35)) }
|
||||
func (h *noopDrv) DecodeFloat(chkOverflow32 bool) (f float64) { return float64(h.m(95)) }
|
||||
func (h *noopDrv) DecodeBool() (b bool) { return h.m(2) == 0 }
|
||||
func (h *noopDrv) DecodeString() (s string) { return h.S[h.m(8)] }
|
||||
func (h *noopDrv) DecodeStringAsBytes() []byte { return h.DecodeBytes(nil, true) }
|
||||
|
||||
func (h *noopDrv) DecodeBytes(bs []byte, zerocopy bool) []byte { return h.B[h.m(len(h.B))] }
|
||||
|
||||
func (h *noopDrv) ReadEnd() { h.end() }
|
||||
|
||||
// toggle map/slice
|
||||
func (h *noopDrv) ReadMapStart() int { h.start(true); return h.m(10) }
|
||||
func (h *noopDrv) ReadArrayStart() int { h.start(false); return h.m(10) }
|
||||
|
||||
func (h *noopDrv) ContainerType() (vt valueType) {
|
||||
// return h.m(2) == 0
|
||||
// handle kStruct, which will bomb is it calls this and
|
||||
// doesn't get back a map or array.
|
||||
// consequently, if the return value is not map or array,
|
||||
// reset it to one of them based on h.m(7) % 2
|
||||
// for kstruct: at least one out of every 2 times,
|
||||
// return one of valueTypeMap or Array (else kstruct bombs)
|
||||
// however, every 10th time it is called, we just return something else.
|
||||
var vals = [...]valueType{valueTypeArray, valueTypeMap}
|
||||
// ------------ TAKE ------------
|
||||
// if h.cb%2 == 0 {
|
||||
// if h.ct == valueTypeMap || h.ct == valueTypeArray {
|
||||
// } else {
|
||||
// h.ct = vals[h.m(2)]
|
||||
// }
|
||||
// } else if h.cb%5 == 0 {
|
||||
// h.ct = valueType(h.m(8))
|
||||
// } else {
|
||||
// h.ct = vals[h.m(2)]
|
||||
// }
|
||||
// ------------ TAKE ------------
|
||||
// if h.cb%16 == 0 {
|
||||
// h.ct = valueType(h.cb % 8)
|
||||
// } else {
|
||||
// h.ct = vals[h.cb%2]
|
||||
// }
|
||||
h.ct = vals[h.cb%2]
|
||||
h.cb++
|
||||
return h.ct
|
||||
|
||||
// if h.ct == valueTypeNil || h.ct == valueTypeString || h.ct == valueTypeBytes {
|
||||
// return h.ct
|
||||
// }
|
||||
// return valueTypeUnset
|
||||
// TODO: may need to tweak this so it works.
|
||||
// if h.ct == valueTypeMap && vt == valueTypeArray ||
|
||||
// h.ct == valueTypeArray && vt == valueTypeMap {
|
||||
// h.cb = !h.cb
|
||||
// h.ct = vt
|
||||
// return h.cb
|
||||
// }
|
||||
// // go in a loop and check it.
|
||||
// h.ct = vt
|
||||
// h.cb = h.m(7) == 0
|
||||
// return h.cb
|
||||
}
|
||||
func (h *noopDrv) TryDecodeAsNil() bool {
|
||||
if h.mk {
|
||||
return false
|
||||
} else {
|
||||
return h.m(8) == 0
|
||||
}
|
||||
}
|
||||
func (h *noopDrv) DecodeExt(rv interface{}, xtag uint64, ext Ext) uint64 {
|
||||
return 0
|
||||
}
|
||||
|
||||
func (h *noopDrv) DecodeNaked() {
|
||||
// use h.r (random) not h.m() because h.m() could cause the same value to be given.
|
||||
var sk int
|
||||
if h.mk {
|
||||
// if mapkey, do not support values of nil OR bytes, array, map or rawext
|
||||
sk = h.r(7) + 1
|
||||
} else {
|
||||
sk = h.r(12)
|
||||
}
|
||||
n := &h.d.n
|
||||
switch sk {
|
||||
case 0:
|
||||
n.v = valueTypeNil
|
||||
case 1:
|
||||
n.v, n.b = valueTypeBool, false
|
||||
case 2:
|
||||
n.v, n.b = valueTypeBool, true
|
||||
case 3:
|
||||
n.v, n.i = valueTypeInt, h.DecodeInt(64)
|
||||
case 4:
|
||||
n.v, n.u = valueTypeUint, h.DecodeUint(64)
|
||||
case 5:
|
||||
n.v, n.f = valueTypeFloat, h.DecodeFloat(true)
|
||||
case 6:
|
||||
n.v, n.f = valueTypeFloat, h.DecodeFloat(false)
|
||||
case 7:
|
||||
n.v, n.s = valueTypeString, h.DecodeString()
|
||||
case 8:
|
||||
n.v, n.l = valueTypeBytes, h.B[h.m(len(h.B))]
|
||||
case 9:
|
||||
n.v = valueTypeArray
|
||||
case 10:
|
||||
n.v = valueTypeMap
|
||||
default:
|
||||
n.v = valueTypeExt
|
||||
n.u = h.DecodeUint(64)
|
||||
n.l = h.B[h.m(len(h.B))]
|
||||
}
|
||||
h.ct = n.v
|
||||
return
|
||||
}
|
30
vendor/github.com/ugorji/go/codec/py_test.go
generated
vendored
Normal file
30
vendor/github.com/ugorji/go/codec/py_test.go
generated
vendored
Normal file
@@ -0,0 +1,30 @@
|
||||
// +build x
|
||||
|
||||
// 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
|
||||
|
||||
// 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.
|
||||
|
||||
import (
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestMsgpackPythonGenStreams(t *testing.T) {
|
||||
doTestPythonGenStreams(t, "msgpack", testMsgpackH)
|
||||
}
|
||||
|
||||
func TestCborPythonGenStreams(t *testing.T) {
|
||||
doTestPythonGenStreams(t, "cbor", testCborH)
|
||||
}
|
||||
|
||||
func TestMsgpackRpcSpecGoClientToPythonSvc(t *testing.T) {
|
||||
doTestMsgpackRpcSpecGoClientToPythonSvc(t)
|
||||
}
|
||||
|
||||
func TestMsgpackRpcSpecPythonClientToGoSvc(t *testing.T) {
|
||||
doTestMsgpackRpcSpecPythonClientToGoSvc(t)
|
||||
}
|
241
vendor/github.com/ugorji/go/codec/rpc.go
generated
vendored
Normal file
241
vendor/github.com/ugorji/go/codec/rpc.go
generated
vendored
Normal file
@@ -0,0 +1,241 @@
|
||||
// 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 (
|
||||
"bufio"
|
||||
"errors"
|
||||
"io"
|
||||
"net/rpc"
|
||||
"sync"
|
||||
)
|
||||
|
||||
// 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
|
||||
// bw *bufio.Writer
|
||||
// br *bufio.Reader
|
||||
mu sync.Mutex
|
||||
h Handle
|
||||
|
||||
cls bool
|
||||
clsmu sync.RWMutex
|
||||
clsErr error
|
||||
}
|
||||
|
||||
func newRPCCodec(conn io.ReadWriteCloser, h Handle) rpcCodec {
|
||||
// return newRPCCodec2(bufio.NewReader(conn), bufio.NewWriter(conn), conn, h)
|
||||
return newRPCCodec2(conn, conn, conn, h)
|
||||
}
|
||||
|
||||
func newRPCCodec2(r io.Reader, w io.Writer, c io.Closer, h Handle) rpcCodec {
|
||||
// defensive: ensure that jsonH has TermWhitespace turned on.
|
||||
if jsonH, ok := h.(*JsonHandle); ok && !jsonH.TermWhitespace {
|
||||
panic(errors.New("rpc requires a JsonHandle with TermWhitespace set to true"))
|
||||
}
|
||||
// always ensure that we use a flusher, and always flush what was written to the connection.
|
||||
// we lose nothing by using a buffered writer internally.
|
||||
f, ok := w.(ioFlusher)
|
||||
bh := h.getBasicHandle()
|
||||
if !bh.RPCNoBuffer {
|
||||
if bh.WriterBufferSize <= 0 {
|
||||
if !ok {
|
||||
bw := bufio.NewWriter(w)
|
||||
f, w = bw, bw
|
||||
}
|
||||
}
|
||||
if bh.ReaderBufferSize <= 0 {
|
||||
if _, ok = w.(ioPeeker); !ok {
|
||||
if _, ok = w.(ioBuffered); !ok {
|
||||
br := bufio.NewReader(r)
|
||||
r = br
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return rpcCodec{
|
||||
c: c,
|
||||
w: w,
|
||||
r: r,
|
||||
f: f,
|
||||
h: h,
|
||||
enc: NewEncoder(w, h),
|
||||
dec: NewDecoder(r, h),
|
||||
}
|
||||
}
|
||||
|
||||
func (c *rpcCodec) write(obj1, obj2 interface{}, writeObj2 bool) (err error) {
|
||||
if c.isClosed() {
|
||||
return c.clsErr
|
||||
}
|
||||
err = c.enc.Encode(obj1)
|
||||
if err == nil {
|
||||
if writeObj2 {
|
||||
err = c.enc.Encode(obj2)
|
||||
}
|
||||
// if err == nil && c.f != nil {
|
||||
// err = c.f.Flush()
|
||||
// }
|
||||
}
|
||||
if c.f != nil {
|
||||
if err == nil {
|
||||
err = c.f.Flush()
|
||||
} else {
|
||||
c.f.Flush()
|
||||
}
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func (c *rpcCodec) swallow(err *error) {
|
||||
defer panicToErr(c.dec, err)
|
||||
c.dec.swallow()
|
||||
}
|
||||
|
||||
func (c *rpcCodec) read(obj interface{}) (err error) {
|
||||
if c.isClosed() {
|
||||
return c.clsErr
|
||||
}
|
||||
//If nil is passed in, we should read and discard
|
||||
if obj == nil {
|
||||
// var obj2 interface{}
|
||||
// return c.dec.Decode(&obj2)
|
||||
c.swallow(&err)
|
||||
return
|
||||
}
|
||||
return c.dec.Decode(obj)
|
||||
}
|
||||
|
||||
func (c *rpcCodec) isClosed() (b bool) {
|
||||
if c.c != nil {
|
||||
c.clsmu.RLock()
|
||||
b = c.cls
|
||||
c.clsmu.RUnlock()
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func (c *rpcCodec) Close() error {
|
||||
if c.c == nil || c.isClosed() {
|
||||
return c.clsErr
|
||||
}
|
||||
c.clsmu.Lock()
|
||||
c.cls = true
|
||||
// var fErr error
|
||||
// if c.f != nil {
|
||||
// fErr = c.f.Flush()
|
||||
// }
|
||||
// _ = fErr
|
||||
// c.clsErr = c.c.Close()
|
||||
// if c.clsErr == nil && fErr != nil {
|
||||
// c.clsErr = fErr
|
||||
// }
|
||||
c.clsErr = c.c.Close()
|
||||
c.clsmu.Unlock()
|
||||
return c.clsErr
|
||||
}
|
||||
|
||||
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 {
|
||||
// Must protect for concurrent access as per API
|
||||
c.mu.Lock()
|
||||
defer c.mu.Unlock()
|
||||
return c.write(r, body, true)
|
||||
}
|
||||
|
||||
func (c *goRpcCodec) WriteResponse(r *rpc.Response, body interface{}) error {
|
||||
c.mu.Lock()
|
||||
defer c.mu.Unlock()
|
||||
return c.write(r, body, true)
|
||||
}
|
||||
|
||||
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)}
|
||||
}
|
304
vendor/github.com/ugorji/go/codec/shared_test.go
generated
vendored
Normal file
304
vendor/github.com/ugorji/go/codec/shared_test.go
generated
vendored
Normal file
@@ -0,0 +1,304 @@
|
||||
// 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
|
||||
|
||||
// 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=. <other parameters ...>
|
||||
// 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=. <other parameters ...>
|
||||
//
|
||||
// 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"
|
||||
"fmt"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"log"
|
||||
"sync"
|
||||
"testing"
|
||||
)
|
||||
|
||||
// DO NOT REMOVE - replacement line for go-codec-bench import declaration tag //
|
||||
|
||||
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 (
|
||||
testDepth int
|
||||
|
||||
testVerbose bool
|
||||
testInitDebug bool
|
||||
testStructToArray bool
|
||||
testCanonical bool
|
||||
testUseReset bool
|
||||
testSkipIntf bool
|
||||
testInternStr bool
|
||||
testUseMust bool
|
||||
testCheckCircRef bool
|
||||
|
||||
testUseIoEncDec int
|
||||
testUseIoWrapper bool
|
||||
|
||||
testMaxInitLen int
|
||||
|
||||
testNumRepeatString int
|
||||
|
||||
testRpcBufsize int
|
||||
)
|
||||
|
||||
// variables that are not flags, but which can configure the handles
|
||||
var (
|
||||
testEncodeOptions EncodeOptions
|
||||
testDecodeOptions DecodeOptions
|
||||
)
|
||||
|
||||
// flag variables used by bench
|
||||
var (
|
||||
benchDoInitBench bool
|
||||
benchVerify bool
|
||||
benchUnscientificRes bool = false
|
||||
benchMapStringKeyOnly 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.
|
||||
benchDepth int
|
||||
benchInitDebug bool
|
||||
)
|
||||
|
||||
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)
|
||||
testInitFlags()
|
||||
benchInitFlags()
|
||||
}
|
||||
|
||||
func testInitFlags() {
|
||||
// delete(testDecOpts.ExtFuncs, timeTyp)
|
||||
flag.IntVar(&testDepth, "tsd", 0, "Test Struc Depth")
|
||||
flag.BoolVar(&testVerbose, "tv", false, "Test Verbose (no longer used - here for compatibility)")
|
||||
flag.BoolVar(&testInitDebug, "tg", false, "Test Init Debug")
|
||||
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(&testStructToArray, "ts", false, "Set StructToArray option")
|
||||
flag.BoolVar(&testCanonical, "tc", false, "Set Canonical option")
|
||||
flag.BoolVar(&testInternStr, "te", false, "Set InternStr option")
|
||||
flag.BoolVar(&testSkipIntf, "tf", false, "Skip Interfaces")
|
||||
flag.BoolVar(&testUseReset, "tr", false, "Use Reset")
|
||||
flag.IntVar(&testNumRepeatString, "trs", 8, "Create string variables by repeating a string N times")
|
||||
flag.IntVar(&testMaxInitLen, "tx", 0, "Max Init Len")
|
||||
flag.BoolVar(&testUseMust, "tm", true, "Use Must(En|De)code")
|
||||
flag.BoolVar(&testCheckCircRef, "tl", false, "Use Check Circular Ref")
|
||||
}
|
||||
|
||||
func benchInitFlags() {
|
||||
flag.BoolVar(&benchMapStringKeyOnly, "bs", false, "Bench use maps with string keys only")
|
||||
flag.BoolVar(&benchInitDebug, "bg", false, "Bench Debug")
|
||||
flag.IntVar(&benchDepth, "bd", 1, "Bench Depth")
|
||||
flag.BoolVar(&benchDoInitBench, "bi", false, "Run Bench Init")
|
||||
flag.BoolVar(&benchVerify, "bv", false, "Verify Decoded Value during Benchmark")
|
||||
flag.BoolVar(&benchUnscientificRes, "bu", false, "Show Unscientific Results during Benchmark")
|
||||
}
|
||||
|
||||
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 sTestCodecEncode(ts interface{}, bsIn []byte, fn func([]byte) *bytes.Buffer,
|
||||
h Handle, bh *BasicHandle) (bs []byte, err error) {
|
||||
// bs = make([]byte, 0, approxSize)
|
||||
var e *Encoder
|
||||
var buf *bytes.Buffer
|
||||
if testUseReset {
|
||||
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 testUseMust {
|
||||
e.MustEncode(ts)
|
||||
} else {
|
||||
err = e.Encode(ts)
|
||||
}
|
||||
if testUseIoEncDec >= 0 {
|
||||
bs = buf.Bytes()
|
||||
bh.WriterBufferSize = oldWriteBufferSize
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func sTestCodecDecode(bs []byte, ts interface{}, h Handle, bh *BasicHandle) (err error) {
|
||||
var d *Decoder
|
||||
// var buf *bytes.Reader
|
||||
if testUseReset {
|
||||
d = testHEDGet(h).D
|
||||
} else {
|
||||
d = NewDecoder(nil, h)
|
||||
}
|
||||
var oldReadBufferSize int
|
||||
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)
|
||||
}
|
||||
if testUseMust {
|
||||
d.MustDecode(ts)
|
||||
} else {
|
||||
err = d.Decode(ts)
|
||||
}
|
||||
if testUseIoEncDec >= 0 {
|
||||
bh.ReaderBufferSize = oldReadBufferSize
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// --- functions below are used by both benchmarks and tests
|
||||
|
||||
func logT(x interface{}, format string, args ...interface{}) {
|
||||
if t, ok := x.(*testing.T); ok && t != nil {
|
||||
t.Logf(format, args...)
|
||||
} else if b, ok := x.(*testing.B); ok && b != nil {
|
||||
b.Logf(format, args...)
|
||||
} else { // if testing.Verbose() { // if testVerbose {
|
||||
if len(format) == 0 || format[len(format)-1] != '\n' {
|
||||
format = format + "\n"
|
||||
}
|
||||
fmt.Printf(format, 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)
|
||||
// }
|
652
vendor/github.com/ugorji/go/codec/simple.go
generated
vendored
Normal file
652
vendor/github.com/ugorji/go/codec/simple.go
generated
vendored
Normal file
@@ -0,0 +1,652 @@
|
||||
// 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 (
|
||||
"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
|
||||
)
|
||||
|
||||
type simpleEncDriver struct {
|
||||
noBuiltInTypes
|
||||
// encNoSeparator
|
||||
e *Encoder
|
||||
h *SimpleHandle
|
||||
w encWriter
|
||||
b [8]byte
|
||||
// c containerState
|
||||
encDriverTrackContainerWriter
|
||||
// encDriverNoopContainerWriter
|
||||
_ [2]uint64 // padding
|
||||
}
|
||||
|
||||
func (e *simpleEncDriver) EncodeNil() {
|
||||
e.w.writen1(simpleVdNil)
|
||||
}
|
||||
|
||||
func (e *simpleEncDriver) EncodeBool(b bool) {
|
||||
if e.h.EncZeroValuesAsNil && e.c != containerMapKey && !b {
|
||||
e.EncodeNil()
|
||||
return
|
||||
}
|
||||
if b {
|
||||
e.w.writen1(simpleVdTrue)
|
||||
} else {
|
||||
e.w.writen1(simpleVdFalse)
|
||||
}
|
||||
}
|
||||
|
||||
func (e *simpleEncDriver) EncodeFloat32(f float32) {
|
||||
if e.h.EncZeroValuesAsNil && e.c != containerMapKey && f == 0.0 {
|
||||
e.EncodeNil()
|
||||
return
|
||||
}
|
||||
e.w.writen1(simpleVdFloat32)
|
||||
bigenHelper{e.b[:4], e.w}.writeUint32(math.Float32bits(f))
|
||||
}
|
||||
|
||||
func (e *simpleEncDriver) EncodeFloat64(f float64) {
|
||||
if e.h.EncZeroValuesAsNil && e.c != containerMapKey && f == 0.0 {
|
||||
e.EncodeNil()
|
||||
return
|
||||
}
|
||||
e.w.writen1(simpleVdFloat64)
|
||||
bigenHelper{e.b[:8], e.w}.writeUint64(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.c != containerMapKey && v == 0 {
|
||||
e.EncodeNil()
|
||||
return
|
||||
}
|
||||
if v <= math.MaxUint8 {
|
||||
e.w.writen2(bd, uint8(v))
|
||||
} else if v <= math.MaxUint16 {
|
||||
e.w.writen1(bd + 1)
|
||||
bigenHelper{e.b[:2], e.w}.writeUint16(uint16(v))
|
||||
} else if v <= math.MaxUint32 {
|
||||
e.w.writen1(bd + 2)
|
||||
bigenHelper{e.b[:4], e.w}.writeUint32(uint32(v))
|
||||
} else { // if v <= math.MaxUint64 {
|
||||
e.w.writen1(bd + 3)
|
||||
bigenHelper{e.b[:8], e.w}.writeUint64(v)
|
||||
}
|
||||
}
|
||||
|
||||
func (e *simpleEncDriver) encLen(bd byte, length int) {
|
||||
if length == 0 {
|
||||
e.w.writen1(bd)
|
||||
} else if length <= math.MaxUint8 {
|
||||
e.w.writen1(bd + 1)
|
||||
e.w.writen1(uint8(length))
|
||||
} else if length <= math.MaxUint16 {
|
||||
e.w.writen1(bd + 2)
|
||||
bigenHelper{e.b[:2], e.w}.writeUint16(uint16(length))
|
||||
} else if int64(length) <= math.MaxUint32 {
|
||||
e.w.writen1(bd + 3)
|
||||
bigenHelper{e.b[:4], e.w}.writeUint32(uint32(length))
|
||||
} else {
|
||||
e.w.writen1(bd + 4)
|
||||
bigenHelper{e.b[:8], e.w}.writeUint64(uint64(length))
|
||||
}
|
||||
}
|
||||
|
||||
func (e *simpleEncDriver) EncodeExt(rv interface{}, xtag uint64, ext Ext, _ *Encoder) {
|
||||
bs := ext.WriteExt(rv)
|
||||
if bs == nil {
|
||||
e.EncodeNil()
|
||||
return
|
||||
}
|
||||
e.encodeExtPreamble(uint8(xtag), len(bs))
|
||||
e.w.writeb(bs)
|
||||
}
|
||||
|
||||
func (e *simpleEncDriver) EncodeRawExt(re *RawExt, _ *Encoder) {
|
||||
e.encodeExtPreamble(uint8(re.Tag), len(re.Data))
|
||||
e.w.writeb(re.Data)
|
||||
}
|
||||
|
||||
func (e *simpleEncDriver) encodeExtPreamble(xtag byte, length int) {
|
||||
e.encLen(simpleVdExt, length)
|
||||
e.w.writen1(xtag)
|
||||
}
|
||||
|
||||
func (e *simpleEncDriver) WriteArrayStart(length int) {
|
||||
e.c = containerArrayStart
|
||||
e.encLen(simpleVdArray, length)
|
||||
}
|
||||
|
||||
func (e *simpleEncDriver) WriteMapStart(length int) {
|
||||
e.c = containerMapStart
|
||||
e.encLen(simpleVdMap, length)
|
||||
}
|
||||
|
||||
func (e *simpleEncDriver) EncodeString(c charEncoding, v string) {
|
||||
if false && e.h.EncZeroValuesAsNil && e.c != containerMapKey && v == "" {
|
||||
e.EncodeNil()
|
||||
return
|
||||
}
|
||||
e.encLen(simpleVdString, len(v))
|
||||
e.w.writestr(v)
|
||||
}
|
||||
|
||||
// func (e *simpleEncDriver) EncodeSymbol(v string) {
|
||||
// e.EncodeString(cUTF8, v)
|
||||
// }
|
||||
|
||||
func (e *simpleEncDriver) EncodeStringBytes(c charEncoding, v []byte) {
|
||||
// if e.h.EncZeroValuesAsNil && e.c != containerMapKey && v == nil {
|
||||
if v == nil {
|
||||
e.EncodeNil()
|
||||
return
|
||||
}
|
||||
e.encLen(simpleVdByteArray, len(v))
|
||||
e.w.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()
|
||||
if err != nil {
|
||||
e.e.errorv(err)
|
||||
return
|
||||
}
|
||||
// time.Time marshalbinary takes about 14 bytes.
|
||||
e.w.writen2(simpleVdTime, uint8(len(v)))
|
||||
e.w.writeb(v)
|
||||
}
|
||||
|
||||
//------------------------------------
|
||||
|
||||
type simpleDecDriver struct {
|
||||
d *Decoder
|
||||
h *SimpleHandle
|
||||
r decReader
|
||||
bdRead bool
|
||||
bd byte
|
||||
br bool // a bytes reader?
|
||||
c containerState
|
||||
// b [scratchByteArrayLen]byte
|
||||
noBuiltInTypes
|
||||
// noStreamingCodec
|
||||
decDriverNoopContainerReader
|
||||
_ [3]uint64 // padding
|
||||
}
|
||||
|
||||
func (d *simpleDecDriver) readNextBd() {
|
||||
d.bd = d.r.readn1()
|
||||
d.bdRead = true
|
||||
}
|
||||
|
||||
func (d *simpleDecDriver) uncacheRead() {
|
||||
if d.bdRead {
|
||||
d.r.unreadn1()
|
||||
d.bdRead = false
|
||||
}
|
||||
}
|
||||
|
||||
func (d *simpleDecDriver) ContainerType() (vt valueType) {
|
||||
if !d.bdRead {
|
||||
d.readNextBd()
|
||||
}
|
||||
switch d.bd {
|
||||
case simpleVdNil:
|
||||
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
|
||||
// case simpleVdTime:
|
||||
// return valueTypeTime
|
||||
}
|
||||
// else {
|
||||
// d.d.errorf("isContainerType: unsupported parameter: %v", vt)
|
||||
// }
|
||||
return valueTypeUnset
|
||||
}
|
||||
|
||||
func (d *simpleDecDriver) TryDecodeAsNil() bool {
|
||||
if !d.bdRead {
|
||||
d.readNextBd()
|
||||
}
|
||||
if d.bd == simpleVdNil {
|
||||
d.bdRead = false
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func (d *simpleDecDriver) decCheckInteger() (ui uint64, neg bool) {
|
||||
if !d.bdRead {
|
||||
d.readNextBd()
|
||||
}
|
||||
switch d.bd {
|
||||
case simpleVdPosInt:
|
||||
ui = uint64(d.r.readn1())
|
||||
case simpleVdPosInt + 1:
|
||||
ui = uint64(bigen.Uint16(d.r.readx(2)))
|
||||
case simpleVdPosInt + 2:
|
||||
ui = uint64(bigen.Uint32(d.r.readx(4)))
|
||||
case simpleVdPosInt + 3:
|
||||
ui = uint64(bigen.Uint64(d.r.readx(8)))
|
||||
case simpleVdNegInt:
|
||||
ui = uint64(d.r.readn1())
|
||||
neg = true
|
||||
case simpleVdNegInt + 1:
|
||||
ui = uint64(bigen.Uint16(d.r.readx(2)))
|
||||
neg = true
|
||||
case simpleVdNegInt + 2:
|
||||
ui = uint64(bigen.Uint32(d.r.readx(4)))
|
||||
neg = true
|
||||
case simpleVdNegInt + 3:
|
||||
ui = uint64(bigen.Uint64(d.r.readx(8)))
|
||||
neg = true
|
||||
default:
|
||||
d.d.errorf("Integer only valid from pos/neg integer1..8. Invalid descriptor: %v", d.bd)
|
||||
return
|
||||
}
|
||||
// don't do this check, 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) {
|
||||
ui, neg := d.decCheckInteger()
|
||||
i = chkOvf.SignedIntV(ui)
|
||||
if neg {
|
||||
i = -i
|
||||
}
|
||||
d.bdRead = false
|
||||
return
|
||||
}
|
||||
|
||||
func (d *simpleDecDriver) DecodeUint64() (ui uint64) {
|
||||
ui, neg := d.decCheckInteger()
|
||||
if neg {
|
||||
d.d.errorf("Assigning negative signed value to unsigned type")
|
||||
return
|
||||
}
|
||||
d.bdRead = false
|
||||
return
|
||||
}
|
||||
|
||||
func (d *simpleDecDriver) DecodeFloat64() (f float64) {
|
||||
if !d.bdRead {
|
||||
d.readNextBd()
|
||||
}
|
||||
if d.bd == simpleVdFloat32 {
|
||||
f = float64(math.Float32frombits(bigen.Uint32(d.r.readx(4))))
|
||||
} else if d.bd == simpleVdFloat64 {
|
||||
f = math.Float64frombits(bigen.Uint64(d.r.readx(8)))
|
||||
} else {
|
||||
if d.bd >= simpleVdPosInt && d.bd <= simpleVdNegInt+3 {
|
||||
f = float64(d.DecodeInt64())
|
||||
} else {
|
||||
d.d.errorf("Float only valid from float32/64: Invalid descriptor: %v", d.bd)
|
||||
return
|
||||
}
|
||||
}
|
||||
d.bdRead = false
|
||||
return
|
||||
}
|
||||
|
||||
// bool can be decoded from bool only (single byte).
|
||||
func (d *simpleDecDriver) DecodeBool() (b bool) {
|
||||
if !d.bdRead {
|
||||
d.readNextBd()
|
||||
}
|
||||
if d.bd == simpleVdTrue {
|
||||
b = true
|
||||
} else if d.bd == simpleVdFalse {
|
||||
} else {
|
||||
d.d.errorf("Invalid single-byte value for bool: %s: %x", msgBadDesc, d.bd)
|
||||
return
|
||||
}
|
||||
d.bdRead = false
|
||||
return
|
||||
}
|
||||
|
||||
func (d *simpleDecDriver) ReadMapStart() (length int) {
|
||||
if !d.bdRead {
|
||||
d.readNextBd()
|
||||
}
|
||||
d.bdRead = false
|
||||
d.c = containerMapStart
|
||||
return d.decLen()
|
||||
}
|
||||
|
||||
func (d *simpleDecDriver) ReadArrayStart() (length int) {
|
||||
if !d.bdRead {
|
||||
d.readNextBd()
|
||||
}
|
||||
d.bdRead = false
|
||||
d.c = containerArrayStart
|
||||
return d.decLen()
|
||||
}
|
||||
|
||||
func (d *simpleDecDriver) ReadArrayElem() {
|
||||
d.c = containerArrayElem
|
||||
}
|
||||
|
||||
func (d *simpleDecDriver) ReadArrayEnd() {
|
||||
d.c = containerArrayEnd
|
||||
}
|
||||
|
||||
func (d *simpleDecDriver) ReadMapElemKey() {
|
||||
d.c = containerMapKey
|
||||
}
|
||||
|
||||
func (d *simpleDecDriver) ReadMapElemValue() {
|
||||
d.c = containerMapValue
|
||||
}
|
||||
|
||||
func (d *simpleDecDriver) ReadMapEnd() {
|
||||
d.c = containerMapEnd
|
||||
}
|
||||
|
||||
func (d *simpleDecDriver) decLen() int {
|
||||
switch d.bd % 8 {
|
||||
case 0:
|
||||
return 0
|
||||
case 1:
|
||||
return int(d.r.readn1())
|
||||
case 2:
|
||||
return int(bigen.Uint16(d.r.readx(2)))
|
||||
case 3:
|
||||
ui := uint64(bigen.Uint32(d.r.readx(4)))
|
||||
if chkOvf.Uint(ui, intBitsize) {
|
||||
d.d.errorf("overflow integer: %v", ui)
|
||||
return 0
|
||||
}
|
||||
return int(ui)
|
||||
case 4:
|
||||
ui := bigen.Uint64(d.r.readx(8))
|
||||
if chkOvf.Uint(ui, intBitsize) {
|
||||
d.d.errorf("overflow integer: %v", ui)
|
||||
return 0
|
||||
}
|
||||
return int(ui)
|
||||
}
|
||||
d.d.errorf("decLen: Cannot read length: bd%%8 must be in range 0..4. Got: %d", d.bd%8)
|
||||
return -1
|
||||
}
|
||||
|
||||
func (d *simpleDecDriver) DecodeString() (s string) {
|
||||
return string(d.DecodeBytes(d.d.b[:], true))
|
||||
}
|
||||
|
||||
func (d *simpleDecDriver) DecodeStringAsBytes() (s []byte) {
|
||||
return d.DecodeBytes(d.d.b[:], true)
|
||||
}
|
||||
|
||||
func (d *simpleDecDriver) DecodeBytes(bs []byte, zerocopy bool) (bsOut []byte) {
|
||||
if !d.bdRead {
|
||||
d.readNextBd()
|
||||
}
|
||||
if d.bd == simpleVdNil {
|
||||
d.bdRead = false
|
||||
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 len(bs) == 0 && zerocopy {
|
||||
bs = d.d.b[:]
|
||||
}
|
||||
bsOut, _ = fastpathTV.DecSliceUint8V(bs, true, d.d)
|
||||
return
|
||||
}
|
||||
|
||||
clen := d.decLen()
|
||||
d.bdRead = false
|
||||
if zerocopy {
|
||||
if d.br {
|
||||
return d.r.readx(clen)
|
||||
} else if len(bs) == 0 {
|
||||
bs = d.d.b[:]
|
||||
}
|
||||
}
|
||||
return decByteSlice(d.r, clen, d.d.h.MaxInitLen, bs)
|
||||
}
|
||||
|
||||
func (d *simpleDecDriver) DecodeTime() (t time.Time) {
|
||||
if !d.bdRead {
|
||||
d.readNextBd()
|
||||
}
|
||||
if d.bd == simpleVdNil {
|
||||
d.bdRead = false
|
||||
return
|
||||
}
|
||||
if d.bd != simpleVdTime {
|
||||
d.d.errorf("invalid descriptor for time.Time - expect 0x%x, received 0x%x", simpleVdTime, d.bd)
|
||||
return
|
||||
}
|
||||
d.bdRead = false
|
||||
clen := int(d.r.readn1())
|
||||
b := d.r.readx(clen)
|
||||
if err := (&t).UnmarshalBinary(b); err != nil {
|
||||
d.d.errorv(err)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func (d *simpleDecDriver) DecodeExt(rv interface{}, xtag uint64, ext Ext) (realxtag uint64) {
|
||||
if xtag > 0xff {
|
||||
d.d.errorf("decodeExt: tag must be <= 0xff; got: %v", xtag)
|
||||
return
|
||||
}
|
||||
realxtag1, xbs := d.decodeExtV(ext != nil, uint8(xtag))
|
||||
realxtag = uint64(realxtag1)
|
||||
if ext == nil {
|
||||
re := rv.(*RawExt)
|
||||
re.Tag = realxtag
|
||||
re.Data = detachZeroCopyBytes(d.br, re.Data, xbs)
|
||||
} else {
|
||||
ext.ReadExt(rv, xbs)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func (d *simpleDecDriver) decodeExtV(verifyTag bool, tag byte) (xtag byte, xbs []byte) {
|
||||
if !d.bdRead {
|
||||
d.readNextBd()
|
||||
}
|
||||
switch d.bd {
|
||||
case simpleVdExt, simpleVdExt + 1, simpleVdExt + 2, simpleVdExt + 3, simpleVdExt + 4:
|
||||
l := d.decLen()
|
||||
xtag = d.r.readn1()
|
||||
if verifyTag && xtag != tag {
|
||||
d.d.errorf("Wrong extension tag. Got %b. Expecting: %v", xtag, tag)
|
||||
return
|
||||
}
|
||||
xbs = d.r.readx(l)
|
||||
case simpleVdByteArray, simpleVdByteArray + 1,
|
||||
simpleVdByteArray + 2, simpleVdByteArray + 3, simpleVdByteArray + 4:
|
||||
xbs = d.DecodeBytes(nil, true)
|
||||
default:
|
||||
d.d.errorf("Invalid descriptor - expecting extensions/bytearray, got: 0x%x", d.bd)
|
||||
return
|
||||
}
|
||||
d.bdRead = false
|
||||
return
|
||||
}
|
||||
|
||||
func (d *simpleDecDriver) DecodeNaked() {
|
||||
if !d.bdRead {
|
||||
d.readNextBd()
|
||||
}
|
||||
|
||||
n := d.d.n
|
||||
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.DecodeString()
|
||||
case simpleVdByteArray, simpleVdByteArray + 1,
|
||||
simpleVdByteArray + 2, simpleVdByteArray + 3, simpleVdByteArray + 4:
|
||||
n.v = valueTypeBytes
|
||||
n.l = d.DecodeBytes(nil, false)
|
||||
case simpleVdExt, simpleVdExt + 1, simpleVdExt + 2, simpleVdExt + 3, simpleVdExt + 4:
|
||||
n.v = valueTypeExt
|
||||
l := d.decLen()
|
||||
n.u = uint64(d.r.readn1())
|
||||
n.l = d.r.readx(l)
|
||||
case simpleVdArray, simpleVdArray + 1, simpleVdArray + 2,
|
||||
simpleVdArray + 3, simpleVdArray + 4:
|
||||
n.v = valueTypeArray
|
||||
decodeFurther = true
|
||||
case simpleVdMap, simpleVdMap + 1, simpleVdMap + 2, simpleVdMap + 3, simpleVdMap + 4:
|
||||
n.v = valueTypeMap
|
||||
decodeFurther = true
|
||||
default:
|
||||
d.d.errorf("decodeNaked: Unrecognized d.bd: 0x%x", d.bd)
|
||||
}
|
||||
|
||||
if !decodeFurther {
|
||||
d.bdRead = false
|
||||
}
|
||||
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 {
|
||||
BasicHandle
|
||||
binaryEncodingType
|
||||
noElemSeparators
|
||||
// EncZeroValuesAsNil says to encode zero values for numbers, bool, string, etc as nil
|
||||
EncZeroValuesAsNil bool
|
||||
|
||||
_ [1]uint64 // padding
|
||||
}
|
||||
|
||||
// Name returns the name of the handle: simple
|
||||
func (h *SimpleHandle) Name() string { return "simple" }
|
||||
|
||||
// SetBytesExt sets an extension
|
||||
func (h *SimpleHandle) SetBytesExt(rt reflect.Type, tag uint64, ext BytesExt) (err error) {
|
||||
return h.SetExt(rt, tag, &extWrapper{ext, interfaceExtFailer{}})
|
||||
}
|
||||
|
||||
func (h *SimpleHandle) hasElemSeparators() bool { return true } // as it implements Write(Map|Array)XXX
|
||||
|
||||
func (h *SimpleHandle) newEncDriver(e *Encoder) encDriver {
|
||||
return &simpleEncDriver{e: e, w: e.w, h: h}
|
||||
}
|
||||
|
||||
func (h *SimpleHandle) newDecDriver(d *Decoder) decDriver {
|
||||
return &simpleDecDriver{d: d, h: h, r: d.r, br: d.bytes}
|
||||
}
|
||||
|
||||
func (e *simpleEncDriver) reset() {
|
||||
e.c = 0
|
||||
e.w = e.e.w
|
||||
}
|
||||
|
||||
func (d *simpleDecDriver) reset() {
|
||||
d.c = 0
|
||||
d.r, d.br = d.d.r, d.d.bytes
|
||||
d.bd, d.bdRead = 0, false
|
||||
}
|
||||
|
||||
var _ decDriver = (*simpleDecDriver)(nil)
|
||||
var _ encDriver = (*simpleEncDriver)(nil)
|
639
vendor/github.com/ugorji/go/codec/test-cbor-goldens.json
generated
vendored
Normal file
639
vendor/github.com/ugorji/go/codec/test-cbor-goldens.json
generated
vendored
Normal file
@@ -0,0 +1,639 @@
|
||||
[
|
||||
{
|
||||
"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
|
||||
}
|
||||
}
|
||||
]
|
126
vendor/github.com/ugorji/go/codec/test.py
generated
vendored
Normal file
126
vendor/github.com/ugorji/go/codec/test.py
generated
vendored
Normal file
@@ -0,0 +1,126 @@
|
||||
#!/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-get install python-dev
|
||||
# sudo apt-get install python-pip
|
||||
# pip install --user msgpack-python msgpack-rpc-python cbor
|
||||
|
||||
# Ensure all "string" keys are utf strings (else encoded as bytes)
|
||||
|
||||
import cbor, msgpack, msgpackrpc, sys, os, threading
|
||||
|
||||
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,
|
||||
False,
|
||||
True,
|
||||
u"null",
|
||||
None,
|
||||
u"some&day>some<day",
|
||||
1328176922000002000,
|
||||
u"",
|
||||
-2206187877999998000,
|
||||
u"bytestring",
|
||||
270,
|
||||
u"none",
|
||||
-2013855847999995777,
|
||||
#-6795364578871345152,
|
||||
]
|
||||
l1 = [
|
||||
{ "true": True,
|
||||
"false": False },
|
||||
{ "true": u"True",
|
||||
"false": False,
|
||||
"uint16(1616)": 1616 },
|
||||
{ "list": [1616, 32323232, True, -3232.0, {"TRUE":True, "FALSE":False}, [True, False] ],
|
||||
"int32":32323232, "bool": True,
|
||||
"LONG STRING": u"123456789012345678901234567890123456789012345678901234567890",
|
||||
"SHORT STRING": u"1234567890" },
|
||||
{ True: "true", 138: False, "false": 200 }
|
||||
]
|
||||
|
||||
l = []
|
||||
l.extend(l0)
|
||||
l.append(l0)
|
||||
l.append(1)
|
||||
l.extend(l1)
|
||||
return l
|
||||
|
||||
def build_test_data(destdir):
|
||||
l = get_test_data_list()
|
||||
for i in range(len(l)):
|
||||
# packer = msgpack.Packer()
|
||||
serialized = msgpack.dumps(l[i])
|
||||
f = open(os.path.join(destdir, str(i) + '.msgpack.golden'), 'wb')
|
||||
f.write(serialized)
|
||||
f.close()
|
||||
serialized = cbor.dumps(l[i])
|
||||
f = open(os.path.join(destdir, str(i) + '.cbor.golden'), 'wb')
|
||||
f.write(serialized)
|
||||
f.close()
|
||||
|
||||
def doRpcServer(port, stopTimeSec):
|
||||
class EchoHandler(object):
|
||||
def Echo123(self, msg1, msg2, msg3):
|
||||
return ("1:%s 2:%s 3:%s" % (msg1, msg2, msg3))
|
||||
def EchoStruct(self, msg):
|
||||
return ("%s" % msg)
|
||||
|
||||
addr = msgpackrpc.Address('127.0.0.1', port)
|
||||
server = msgpackrpc.Server(EchoHandler())
|
||||
server.listen(addr)
|
||||
# run thread to stop it after stopTimeSec seconds if > 0
|
||||
if stopTimeSec > 0:
|
||||
def myStopRpcServer():
|
||||
server.stop()
|
||||
t = threading.Timer(stopTimeSec, myStopRpcServer)
|
||||
t.start()
|
||||
server.start()
|
||||
|
||||
def doRpcClientToPythonSvc(port):
|
||||
address = msgpackrpc.Address('127.0.0.1', 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 doRpcClientToGoSvc(port):
|
||||
# print ">>>> port: ", port, " <<<<<"
|
||||
address = msgpackrpc.Address('127.0.0.1', 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:])
|
||||
|
186
vendor/github.com/ugorji/go/codec/values_flex_test.go
generated
vendored
Normal file
186
vendor/github.com/ugorji/go/codec/values_flex_test.go
generated
vendored
Normal file
@@ -0,0 +1,186 @@
|
||||
/* // +build testing */
|
||||
|
||||
// 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 "time"
|
||||
|
||||
// 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 unused types just stored here
|
||||
type Bbool bool
|
||||
type Sstring string
|
||||
type Sstructsmall struct {
|
||||
A int
|
||||
}
|
||||
|
||||
type Sstructbig struct {
|
||||
A int
|
||||
B bool
|
||||
c string
|
||||
// Sval Sstruct
|
||||
Ssmallptr *Sstructsmall
|
||||
Ssmall *Sstructsmall
|
||||
Sptr *Sstructbig
|
||||
}
|
||||
|
||||
type SstructbigMapBySlice struct {
|
||||
_struct struct{} `codec:",toarray"`
|
||||
A int
|
||||
B bool
|
||||
c string
|
||||
// Sval Sstruct
|
||||
Ssmallptr *Sstructsmall
|
||||
Ssmall *Sstructsmall
|
||||
Sptr *Sstructbig
|
||||
}
|
||||
|
||||
type Sinterface interface {
|
||||
Noop()
|
||||
}
|
||||
|
||||
// small struct for testing that codecgen works for unexported types
|
||||
type tLowerFirstLetter struct {
|
||||
I int
|
||||
u uint64
|
||||
S string
|
||||
b []byte
|
||||
}
|
||||
|
||||
// Some used types
|
||||
type wrapInt64 int64
|
||||
type wrapUint8 uint8
|
||||
type wrapBytes []uint8
|
||||
|
||||
type AnonInTestStrucIntf struct {
|
||||
Islice []interface{}
|
||||
Ms map[string]interface{}
|
||||
Nintf interface{} //don't set this, so we can test for nil
|
||||
T time.Time
|
||||
}
|
||||
|
||||
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
|
||||
|
||||
Mis map[int]string
|
||||
Mbu64 map[bool]struct{}
|
||||
Miwu64s map[int]wrapUint64Slice
|
||||
Mfwss map[float64]wrapStringSlice
|
||||
Mf32wss map[float32]wrapStringSlice
|
||||
Mui2wss map[uint64]wrapStringSlice
|
||||
Msu2wss map[stringUint64T]wrapStringSlice
|
||||
|
||||
Ci64 wrapInt64
|
||||
Swrapbytes []wrapBytes
|
||||
Swrapuint8 []wrapUint8
|
||||
|
||||
ArrStrUi64T [4]stringUint64T
|
||||
|
||||
Ui64array [4]uint64
|
||||
Ui64slicearray []*[4]uint64
|
||||
|
||||
// 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:"-",bson:"-"`
|
||||
Mtsptr map[string]*TestStrucFlex
|
||||
Mts map[string]TestStrucFlex
|
||||
Its []*TestStrucFlex
|
||||
Nteststruc *TestStrucFlex
|
||||
}
|
||||
|
||||
func newTestStrucFlex(depth, n int, bench, useInterface, useStringKeyOnly bool) (ts *TestStrucFlex) {
|
||||
ts = &TestStrucFlex{
|
||||
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"},
|
||||
},
|
||||
Mis: map[int]string{
|
||||
1: "one",
|
||||
22: "twenty two",
|
||||
-44: "minus forty four",
|
||||
},
|
||||
Mbu64: map[bool]struct{}{false: {}, true: {}},
|
||||
|
||||
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}},
|
||||
}
|
||||
|
||||
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,
|
||||
}
|
||||
}
|
||||
|
||||
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
|
||||
}
|
400
vendor/github.com/ugorji/go/codec/values_test.go
generated
vendored
Normal file
400
vendor/github.com/ugorji/go/codec/values_test.go
generated
vendored
Normal file
@@ -0,0 +1,400 @@
|
||||
/* // +build testing */
|
||||
|
||||
// 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
|
||||
|
||||
// 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"
|
||||
"strings"
|
||||
)
|
||||
|
||||
// func init() {
|
||||
// rt := reflect.TypeOf((*TestStruc)(nil)).Elem()
|
||||
// defTypeInfos.get(rt2id(rt), rt)
|
||||
// }
|
||||
|
||||
type wrapSliceUint64 []uint64
|
||||
type wrapSliceString []string
|
||||
type wrapUint64 uint64
|
||||
type wrapString string
|
||||
type wrapUint64Slice []wrapUint64
|
||||
type wrapStringSlice []wrapString
|
||||
|
||||
type stringUint64T struct {
|
||||
S string
|
||||
U uint64
|
||||
}
|
||||
|
||||
type AnonInTestStruc struct {
|
||||
AS string
|
||||
AI64 int64
|
||||
AI16 int16
|
||||
AUi64 uint64
|
||||
ASslice []string
|
||||
AI64slice []int64
|
||||
AUi64slice []uint64
|
||||
AF64slice []float64
|
||||
AF32slice []float32
|
||||
|
||||
// AMI32U32 map[int32]uint32
|
||||
// AMU32F64 map[uint32]float64 // json/bson do not like it
|
||||
AMSU16 map[string]uint16
|
||||
|
||||
// use these to test 0-len or nil slices/maps/arrays
|
||||
AI64arr0 [0]int64
|
||||
A164slice0 []int64
|
||||
AUi64sliceN []uint64
|
||||
AMSU16N map[string]uint16
|
||||
AMSU16E map[string]uint16
|
||||
}
|
||||
|
||||
// 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
|
||||
I16slice []int16
|
||||
Ui64slice []uint64
|
||||
Ui8slice []uint8
|
||||
Bslice []bool
|
||||
|
||||
Iptrslice []*int64
|
||||
|
||||
WrapSliceInt64 wrapSliceUint64
|
||||
WrapSliceString wrapSliceString
|
||||
|
||||
Msi64 map[string]int64
|
||||
}
|
||||
|
||||
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
|
||||
I16slice []int16
|
||||
Ui64slice []uint64
|
||||
Ui8slice []uint8
|
||||
Bslice []bool
|
||||
Byslice []byte
|
||||
|
||||
Iptrslice []*int64
|
||||
|
||||
WrapSliceInt64 wrapSliceUint64
|
||||
WrapSliceString wrapSliceString
|
||||
|
||||
Msi64 map[string]int64
|
||||
|
||||
Simplef testSimpleFields
|
||||
|
||||
SstrUi64T []stringUint64T
|
||||
|
||||
AnonInTestStruc
|
||||
|
||||
NotAnon AnonInTestStruc
|
||||
|
||||
// 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,
|
||||
},
|
||||
AMSU16: map[string]uint16{strRpt(n, "1"): 1, strRpt(n, "22"): 2, strRpt(n, "333"): 3, strRpt(n, "4444"): 4},
|
||||
|
||||
// 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-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,
|
||||
// standard ones
|
||||
0, -1, 1,
|
||||
// math.Float32frombits(0x7FF00000), math.Float32frombits(0xFFF00000), //+inf and -inf
|
||||
math.MaxFloat32, math.SmallestNonzeroFloat32,
|
||||
},
|
||||
|
||||
A164slice0: []int64{},
|
||||
AUi64sliceN: nil,
|
||||
AMSU16N: nil,
|
||||
AMSU16E: map[string]uint16{},
|
||||
}
|
||||
|
||||
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},
|
||||
I16slice: []int16{44, 55, 66},
|
||||
Ui64slice: []uint64{12121212, 34343434, 56565656},
|
||||
Ui8slice: []uint8{210, 211, 212},
|
||||
Bslice: []bool{true, false, true, false},
|
||||
Byslice: []byte{13, 14, 15},
|
||||
|
||||
Msi64: map[string]int64{
|
||||
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")},
|
||||
|
||||
// R: Raw([]byte("goodbye")),
|
||||
// Rext: RawExt{ 120, []byte("hello"), }, // TODO: don't set this - it's hard to test
|
||||
|
||||
// DecodeNaked bombs here, because the stringUint64T is decoded as a map,
|
||||
// and a map cannot be the key type of a map.
|
||||
// Thus, don't initialize this here.
|
||||
// Msu2wss: map[stringUint64T]wrapStringSlice{
|
||||
// {"5", 5}: []wrapString{"1", "2", "3", "4", "5"},
|
||||
// {"3", 3}: []wrapString{"1", "2", "3"},
|
||||
// },
|
||||
|
||||
// make Simplef same as top-level
|
||||
// TODO: 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")},
|
||||
I16slice: []int16{44, 55, 66},
|
||||
Ui64slice: []uint64{12121212, 34343434, 56565656},
|
||||
Ui8slice: []uint8{210, 211, 212},
|
||||
Bslice: []bool{true, false, true, false},
|
||||
|
||||
Msi64: map[string]int64{
|
||||
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: []stringUint64T{{"1", 1}, {"2", 2}, {"3", 3}, {"4", 4}},
|
||||
AnonInTestStruc: a,
|
||||
NotAnon: a,
|
||||
}
|
||||
|
||||
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 {
|
||||
// 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))
|
||||
// }
|
508
vendor/github.com/ugorji/go/codec/xml.go
generated
vendored
Normal file
508
vendor/github.com/ugorji/go/codec/xml.go
generated
vendored
Normal file
@@ -0,0 +1,508 @@
|
||||
// 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.
|
||||
|
||||
// +build ignore
|
||||
|
||||
package codec
|
||||
|
||||
import "reflect"
|
||||
|
||||
/*
|
||||
|
||||
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. <!NOTATION GIF87A SYSTEM "GIF">
|
||||
- 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.
|
||||
<!ATTLIST foo:oldjoke name ID #REQUIRED label CDATA #IMPLIED status ( funny | notfunny ) 'funny' >
|
||||
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.
|
||||
<!ELEMENT burns "ugorji is cool" > AND entities for the set: [<>&"']
|
||||
- Parameter entities e.g.
|
||||
<!ENTITY % personcontent "ugorji is cool"> <!ELEMENT burns (%personcontent;)*>
|
||||
|
||||
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. <hn:name xmlns:hn="http://www.ugorji.net" >
|
||||
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 ==> <map><key>abc</key><value>val</value></map>... or
|
||||
<map key="abc">val</map>... OR
|
||||
<key1>val1</key1><key2>val2</key2>... <- PREFERED
|
||||
[]string ==> <string>v1</string><string>v2</string>...
|
||||
string v1 ==> <string>v1</string>
|
||||
bool true ==> <bool>true</bool>
|
||||
float 1.0 ==> <float>1.0</float>
|
||||
...
|
||||
|
||||
F1 map[string]string ==> <F1><key>abc</key><value>val</value></F1>... OR
|
||||
<F1 key="abc">val</F1>... OR
|
||||
<F1><abc>val</abc>...</F1> <- PREFERED
|
||||
F2 []string ==> <F2>v1</F2><F2>v2</F2>...
|
||||
F3 bool ==> <F3>true</F3>
|
||||
...
|
||||
|
||||
- a scalar is encoded as:
|
||||
(value) of type T ==> <T><value/></T>
|
||||
(value) of field F ==> <F><value/></F>
|
||||
- A kv-pair is encoded as:
|
||||
(key,value) ==> <map><key><value/></key></map> OR <map key="value">
|
||||
(key,value) of field F ==> <F><key><value/></key></F> OR <F key="value">
|
||||
- A map or struct is just a list of kv-pairs
|
||||
- A list is encoded as sequences of same node e.g.
|
||||
<F1 key1="value11">
|
||||
<F1 key2="value12">
|
||||
<F2>value21</F2>
|
||||
<F2>value22</F2>
|
||||
- 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: <nil>,
|
||||
s: <string>hello</string><int>1</int><bool>true</bool><Time>2009-11-10T23:00:00Z</Time>
|
||||
err: <nil>,
|
||||
v2: [<nil>]
|
||||
err: <nil>,
|
||||
s: <T><V>hello</V><V>1</V><V>true</V><V>2009-11-10T23:00:00Z</V></T>
|
||||
err: <nil>,
|
||||
v4: {[<nil> <nil> <nil> <nil>]}
|
||||
-
|
||||
*/
|
||||
|
||||
// ----------- 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() {
|
||||
// TODO: implement.
|
||||
}
|
||||
|
||||
// ----------- 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
|
||||
}
|
||||
|
||||
func (h *XMLHandle) SetInterfaceExt(rt reflect.Type, tag uint64, ext InterfaceExt) (err error) {
|
||||
return h.SetExt(rt, tag, &extWrapper{bytesExtFailer{}, ext})
|
||||
}
|
||||
|
||||
var _ decDriver = (*xmlDecDriver)(nil)
|
||||
var _ encDriver = (*xmlEncDriver)(nil)
|
475
vendor/github.com/ugorji/go/codec/z_all_test.go
generated
vendored
Normal file
475
vendor/github.com/ugorji/go/codec/z_all_test.go
generated
vendored
Normal file
@@ -0,0 +1,475 @@
|
||||
// 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.
|
||||
|
||||
// +build alltests
|
||||
// +build go1.7
|
||||
|
||||
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 safe appengine notfastpath
|
||||
//
|
||||
// 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=( "" "safe" "codecgen" "notfastpath" "codecgen notfastpath" "codecgen safe" "safe notfastpath" )
|
||||
// for i in "${a[@]}"; do echo ">>>> TAGS: $i"; go test "-tags=alltests $i" -run=Suite; done
|
||||
//
|
||||
// This only works on go1.7 and above. This is when subtests and suites were supported.
|
||||
|
||||
import "testing"
|
||||
|
||||
// func TestMain(m *testing.M) {
|
||||
// println("calling TestMain")
|
||||
// // set some parameters
|
||||
// exitcode := m.Run()
|
||||
// os.Exit(exitcode)
|
||||
// }
|
||||
|
||||
func testGroupResetFlags() {
|
||||
testUseMust = false
|
||||
testCanonical = false
|
||||
testUseMust = false
|
||||
testInternStr = false
|
||||
testUseIoEncDec = -1
|
||||
testStructToArray = false
|
||||
testCheckCircRef = false
|
||||
testUseReset = false
|
||||
testMaxInitLen = 0
|
||||
testUseIoWrapper = false
|
||||
testNumRepeatString = 8
|
||||
testEncodeOptions.RecursiveEmptyCheck = false
|
||||
testDecodeOptions.MapValueReset = false
|
||||
testUseIoEncDec = -1
|
||||
testDepth = 0
|
||||
}
|
||||
|
||||
func testSuite(t *testing.T, f func(t *testing.T)) {
|
||||
// find . -name "*_test.go" | xargs grep -e 'flag.' | cut -d '&' -f 2 | cut -d ',' -f 1 | grep -e '^test'
|
||||
// Disregard the following: testInitDebug, testSkipIntf, testJsonIndent (Need a test for it)
|
||||
|
||||
testReinit() // so flag.Parse() is called first, and never called again
|
||||
|
||||
testDecodeOptions = DecodeOptions{}
|
||||
testEncodeOptions = EncodeOptions{}
|
||||
|
||||
testGroupResetFlags()
|
||||
|
||||
testReinit()
|
||||
t.Run("optionsFalse", f)
|
||||
|
||||
testCanonical = true
|
||||
testUseMust = true
|
||||
testInternStr = true
|
||||
testUseIoEncDec = 0
|
||||
testStructToArray = true
|
||||
testCheckCircRef = true
|
||||
testUseReset = true
|
||||
testDecodeOptions.MapValueReset = true
|
||||
testEncodeOptions.RecursiveEmptyCheck = true
|
||||
testReinit()
|
||||
t.Run("optionsTrue", f)
|
||||
|
||||
testDepth = 6
|
||||
testReinit()
|
||||
t.Run("optionsTrue-deepstruct", f)
|
||||
testDepth = 0
|
||||
|
||||
// testEncodeOptions.AsSymbols = AsSymbolAll
|
||||
testUseIoWrapper = true
|
||||
testReinit()
|
||||
t.Run("optionsTrue-ioWrapper", f)
|
||||
|
||||
testUseIoEncDec = -1
|
||||
|
||||
// make buffer small enough so that we have to re-fill multiple times.
|
||||
testSkipRPCTests = true
|
||||
testUseIoEncDec = 128
|
||||
// testDecodeOptions.ReaderBufferSize = 128
|
||||
// testEncodeOptions.WriterBufferSize = 128
|
||||
testReinit()
|
||||
t.Run("optionsTrue-bufio", f)
|
||||
// testDecodeOptions.ReaderBufferSize = 0
|
||||
// testEncodeOptions.WriterBufferSize = 0
|
||||
testUseIoEncDec = -1
|
||||
testSkipRPCTests = false
|
||||
|
||||
testNumRepeatString = 32
|
||||
testReinit()
|
||||
t.Run("optionsTrue-largestrings", f)
|
||||
|
||||
// The following here MUST be tested individually, as they create
|
||||
// side effects i.e. the decoded value is different.
|
||||
// testDecodeOptions.MapValueReset = true // ok - no side effects
|
||||
// testDecodeOptions.InterfaceReset = true // error??? because we do deepEquals to verify
|
||||
// testDecodeOptions.ErrorIfNoField = true // error, as expected, as fields not there
|
||||
// testDecodeOptions.ErrorIfNoArrayExpand = true // no error, but no error case either
|
||||
// testDecodeOptions.PreferArrayOverSlice = true // error??? because slice != array.
|
||||
// .... however, update deepEqual to take this option
|
||||
// testReinit()
|
||||
// t.Run("optionsTrue-resetOptions", f)
|
||||
|
||||
testGroupResetFlags()
|
||||
}
|
||||
|
||||
/*
|
||||
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
|
||||
*/
|
||||
|
||||
func testCodecGroup(t *testing.T) {
|
||||
// println("running testcodecsuite")
|
||||
// <setup code>
|
||||
|
||||
t.Run("TestBincCodecsTable", TestBincCodecsTable)
|
||||
t.Run("TestBincCodecsMisc", TestBincCodecsMisc)
|
||||
t.Run("TestBincCodecsEmbeddedPointer", TestBincCodecsEmbeddedPointer)
|
||||
t.Run("TestBincStdEncIntf", TestBincStdEncIntf)
|
||||
t.Run("TestBincMammoth", TestBincMammoth)
|
||||
t.Run("TestSimpleCodecsTable", TestSimpleCodecsTable)
|
||||
t.Run("TestSimpleCodecsMisc", TestSimpleCodecsMisc)
|
||||
t.Run("TestSimpleCodecsEmbeddedPointer", TestSimpleCodecsEmbeddedPointer)
|
||||
t.Run("TestSimpleStdEncIntf", TestSimpleStdEncIntf)
|
||||
t.Run("TestSimpleMammoth", TestSimpleMammoth)
|
||||
t.Run("TestMsgpackCodecsTable", TestMsgpackCodecsTable)
|
||||
t.Run("TestMsgpackCodecsMisc", TestMsgpackCodecsMisc)
|
||||
t.Run("TestMsgpackCodecsEmbeddedPointer", TestMsgpackCodecsEmbeddedPointer)
|
||||
t.Run("TestMsgpackStdEncIntf", TestMsgpackStdEncIntf)
|
||||
t.Run("TestMsgpackMammoth", TestMsgpackMammoth)
|
||||
t.Run("TestCborCodecsTable", TestCborCodecsTable)
|
||||
t.Run("TestCborCodecsMisc", TestCborCodecsMisc)
|
||||
t.Run("TestCborCodecsEmbeddedPointer", TestCborCodecsEmbeddedPointer)
|
||||
t.Run("TestCborMapEncodeForCanonical", TestCborMapEncodeForCanonical)
|
||||
t.Run("TestCborCodecChan", TestCborCodecChan)
|
||||
t.Run("TestCborStdEncIntf", TestCborStdEncIntf)
|
||||
t.Run("TestCborMammoth", TestCborMammoth)
|
||||
t.Run("TestJsonCodecsTable", TestJsonCodecsTable)
|
||||
t.Run("TestJsonCodecsMisc", TestJsonCodecsMisc)
|
||||
t.Run("TestJsonCodecsEmbeddedPointer", TestJsonCodecsEmbeddedPointer)
|
||||
t.Run("TestJsonCodecChan", TestJsonCodecChan)
|
||||
t.Run("TestJsonStdEncIntf", TestJsonStdEncIntf)
|
||||
t.Run("TestJsonMammoth", TestJsonMammoth)
|
||||
t.Run("TestJsonRaw", TestJsonRaw)
|
||||
t.Run("TestBincRaw", TestBincRaw)
|
||||
t.Run("TestMsgpackRaw", TestMsgpackRaw)
|
||||
t.Run("TestSimpleRaw", TestSimpleRaw)
|
||||
t.Run("TestCborRaw", TestCborRaw)
|
||||
t.Run("TestAllEncCircularRef", TestAllEncCircularRef)
|
||||
t.Run("TestAllAnonCycle", TestAllAnonCycle)
|
||||
t.Run("TestBincRpcGo", TestBincRpcGo)
|
||||
t.Run("TestSimpleRpcGo", TestSimpleRpcGo)
|
||||
t.Run("TestMsgpackRpcGo", TestMsgpackRpcGo)
|
||||
t.Run("TestCborRpcGo", TestCborRpcGo)
|
||||
t.Run("TestJsonRpcGo", TestJsonRpcGo)
|
||||
t.Run("TestMsgpackRpcSpec", TestMsgpackRpcSpec)
|
||||
t.Run("TestBincUnderlyingType", TestBincUnderlyingType)
|
||||
t.Run("TestJsonLargeInteger", TestJsonLargeInteger)
|
||||
t.Run("TestJsonDecodeNonStringScalarInStringContext", TestJsonDecodeNonStringScalarInStringContext)
|
||||
t.Run("TestJsonEncodeIndent", TestJsonEncodeIndent)
|
||||
|
||||
t.Run("TestJsonSwallowAndZero", TestJsonSwallowAndZero)
|
||||
t.Run("TestCborSwallowAndZero", TestCborSwallowAndZero)
|
||||
t.Run("TestMsgpackSwallowAndZero", TestMsgpackSwallowAndZero)
|
||||
t.Run("TestBincSwallowAndZero", TestBincSwallowAndZero)
|
||||
t.Run("TestSimpleSwallowAndZero", TestSimpleSwallowAndZero)
|
||||
t.Run("TestJsonRawExt", TestJsonRawExt)
|
||||
t.Run("TestCborRawExt", TestCborRawExt)
|
||||
t.Run("TestMsgpackRawExt", TestMsgpackRawExt)
|
||||
t.Run("TestBincRawExt", TestBincRawExt)
|
||||
t.Run("TestSimpleRawExt", TestSimpleRawExt)
|
||||
t.Run("TestJsonMapStructKey", TestJsonMapStructKey)
|
||||
t.Run("TestCborMapStructKey", TestCborMapStructKey)
|
||||
t.Run("TestMsgpackMapStructKey", TestMsgpackMapStructKey)
|
||||
t.Run("TestBincMapStructKey", TestBincMapStructKey)
|
||||
t.Run("TestSimpleMapStructKey", TestSimpleMapStructKey)
|
||||
t.Run("TestJsonDecodeNilMapValue", TestJsonDecodeNilMapValue)
|
||||
t.Run("TestCborDecodeNilMapValue", TestCborDecodeNilMapValue)
|
||||
t.Run("TestMsgpackDecodeNilMapValue", TestMsgpackDecodeNilMapValue)
|
||||
t.Run("TestBincDecodeNilMapValue", TestBincDecodeNilMapValue)
|
||||
t.Run("TestSimpleDecodeNilMapValue", TestSimpleDecodeNilMapValue)
|
||||
t.Run("TestJsonEmbeddedFieldPrecedence", TestJsonEmbeddedFieldPrecedence)
|
||||
t.Run("TestCborEmbeddedFieldPrecedence", TestCborEmbeddedFieldPrecedence)
|
||||
t.Run("TestMsgpackEmbeddedFieldPrecedence", TestMsgpackEmbeddedFieldPrecedence)
|
||||
t.Run("TestBincEmbeddedFieldPrecedence", TestBincEmbeddedFieldPrecedence)
|
||||
t.Run("TestSimpleEmbeddedFieldPrecedence", TestSimpleEmbeddedFieldPrecedence)
|
||||
t.Run("TestJsonLargeContainerLen", TestJsonLargeContainerLen)
|
||||
t.Run("TestCborLargeContainerLen", TestCborLargeContainerLen)
|
||||
t.Run("TestMsgpackLargeContainerLen", TestMsgpackLargeContainerLen)
|
||||
t.Run("TestBincLargeContainerLen", TestBincLargeContainerLen)
|
||||
t.Run("TestSimpleLargeContainerLen", TestSimpleLargeContainerLen)
|
||||
t.Run("TestJsonMammothMapsAndSlices", TestJsonMammothMapsAndSlices)
|
||||
t.Run("TestCborMammothMapsAndSlices", TestCborMammothMapsAndSlices)
|
||||
t.Run("TestMsgpackMammothMapsAndSlices", TestMsgpackMammothMapsAndSlices)
|
||||
t.Run("TestBincMammothMapsAndSlices", TestBincMammothMapsAndSlices)
|
||||
t.Run("TestSimpleMammothMapsAndSlices", TestSimpleMammothMapsAndSlices)
|
||||
t.Run("TestJsonTime", TestJsonTime)
|
||||
t.Run("TestCborTime", TestCborTime)
|
||||
t.Run("TestMsgpackTime", TestMsgpackTime)
|
||||
t.Run("TestBincTime", TestBincTime)
|
||||
t.Run("TestSimpleTime", TestSimpleTime)
|
||||
t.Run("TestJsonUintToInt", TestJsonUintToInt)
|
||||
t.Run("TestCborUintToInt", TestCborUintToInt)
|
||||
t.Run("TestMsgpackUintToInt", TestMsgpackUintToInt)
|
||||
t.Run("TestBincUintToInt", TestBincUintToInt)
|
||||
t.Run("TestSimpleUintToInt", TestSimpleUintToInt)
|
||||
t.Run("TestJsonDifferentMapOrSliceType", TestJsonDifferentMapOrSliceType)
|
||||
t.Run("TestCborDifferentMapOrSliceType", TestCborDifferentMapOrSliceType)
|
||||
t.Run("TestMsgpackDifferentMapOrSliceType", TestMsgpackDifferentMapOrSliceType)
|
||||
t.Run("TestBincDifferentMapOrSliceType", TestBincDifferentMapOrSliceType)
|
||||
t.Run("TestSimpleDifferentMapOrSliceType", TestSimpleDifferentMapOrSliceType)
|
||||
t.Run("TestJsonScalars", TestJsonScalars)
|
||||
t.Run("TestCborScalars", TestCborScalars)
|
||||
t.Run("TestMsgpackScalars", TestMsgpackScalars)
|
||||
t.Run("TestBincScalars", TestBincScalars)
|
||||
t.Run("TestSimpleScalars", TestSimpleScalars)
|
||||
t.Run("TestJsonIntfMapping", TestJsonIntfMapping)
|
||||
t.Run("TestCborIntfMapping", TestCborIntfMapping)
|
||||
t.Run("TestMsgpackIntfMapping", TestMsgpackIntfMapping)
|
||||
t.Run("TestBincIntfMapping", TestBincIntfMapping)
|
||||
t.Run("TestSimpleIntfMapping", TestSimpleIntfMapping)
|
||||
|
||||
t.Run("TestJsonInvalidUnicode", TestJsonInvalidUnicode)
|
||||
t.Run("TestCborHalfFloat", TestCborHalfFloat)
|
||||
// <tear-down code>
|
||||
}
|
||||
|
||||
func testJsonGroup(t *testing.T) {
|
||||
t.Run("TestJsonCodecsTable", TestJsonCodecsTable)
|
||||
t.Run("TestJsonCodecsMisc", TestJsonCodecsMisc)
|
||||
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("TestJsonSwallowAndZero", TestJsonSwallowAndZero)
|
||||
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("TestJsonInvalidUnicode", TestJsonInvalidUnicode)
|
||||
t.Run("TestJsonTime", TestJsonTime)
|
||||
t.Run("TestJsonUintToInt", TestJsonUintToInt)
|
||||
t.Run("TestJsonDifferentMapOrSliceType", TestJsonDifferentMapOrSliceType)
|
||||
t.Run("TestJsonScalars", TestJsonScalars)
|
||||
t.Run("TestJsonIntfMapping", TestJsonIntfMapping)
|
||||
}
|
||||
|
||||
func testBincGroup(t *testing.T) {
|
||||
t.Run("TestBincCodecsTable", TestBincCodecsTable)
|
||||
t.Run("TestBincCodecsMisc", TestBincCodecsMisc)
|
||||
t.Run("TestBincCodecsEmbeddedPointer", TestBincCodecsEmbeddedPointer)
|
||||
t.Run("TestBincStdEncIntf", TestBincStdEncIntf)
|
||||
t.Run("TestBincMammoth", TestBincMammoth)
|
||||
t.Run("TestBincRaw", TestBincRaw)
|
||||
t.Run("TestSimpleRpcGo", TestSimpleRpcGo)
|
||||
t.Run("TestBincUnderlyingType", TestBincUnderlyingType)
|
||||
|
||||
t.Run("TestBincSwallowAndZero", TestBincSwallowAndZero)
|
||||
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)
|
||||
}
|
||||
|
||||
func testCborGroup(t *testing.T) {
|
||||
t.Run("TestCborCodecsTable", TestCborCodecsTable)
|
||||
t.Run("TestCborCodecsMisc", TestCborCodecsMisc)
|
||||
t.Run("TestCborCodecsEmbeddedPointer", TestCborCodecsEmbeddedPointer)
|
||||
t.Run("TestCborMapEncodeForCanonical", TestCborMapEncodeForCanonical)
|
||||
t.Run("TestCborCodecChan", TestCborCodecChan)
|
||||
t.Run("TestCborStdEncIntf", TestCborStdEncIntf)
|
||||
t.Run("TestCborMammoth", TestCborMammoth)
|
||||
t.Run("TestCborRaw", TestCborRaw)
|
||||
t.Run("TestCborRpcGo", TestCborRpcGo)
|
||||
|
||||
t.Run("TestCborSwallowAndZero", TestCborSwallowAndZero)
|
||||
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("TestCborHalfFloat", TestCborHalfFloat)
|
||||
}
|
||||
|
||||
func testMsgpackGroup(t *testing.T) {
|
||||
t.Run("TestMsgpackCodecsTable", TestMsgpackCodecsTable)
|
||||
t.Run("TestMsgpackCodecsMisc", TestMsgpackCodecsMisc)
|
||||
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("TestMsgpackSwallowAndZero", TestMsgpackSwallowAndZero)
|
||||
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)
|
||||
}
|
||||
|
||||
func testSimpleGroup(t *testing.T) {
|
||||
t.Run("TestSimpleCodecsTable", TestSimpleCodecsTable)
|
||||
t.Run("TestSimpleCodecsMisc", TestSimpleCodecsMisc)
|
||||
t.Run("TestSimpleCodecsEmbeddedPointer", TestSimpleCodecsEmbeddedPointer)
|
||||
t.Run("TestSimpleStdEncIntf", TestSimpleStdEncIntf)
|
||||
t.Run("TestSimpleMammoth", TestSimpleMammoth)
|
||||
t.Run("TestSimpleRaw", TestSimpleRaw)
|
||||
t.Run("TestSimpleRpcGo", TestSimpleRpcGo)
|
||||
t.Run("TestSimpleSwallowAndZero", TestSimpleSwallowAndZero)
|
||||
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)
|
||||
}
|
||||
|
||||
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 TestCodecSuite(t *testing.T) {
|
||||
testSuite(t, testCodecGroup)
|
||||
|
||||
testGroupResetFlags()
|
||||
|
||||
oldIndent, oldCharsAsis, oldPreferFloat, oldMapKeyAsString :=
|
||||
testJsonH.Indent, testJsonH.HTMLCharsAsIs, testJsonH.PreferFloat, testJsonH.MapKeyAsString
|
||||
|
||||
testMaxInitLen = 10
|
||||
testJsonH.Indent = 8
|
||||
testJsonH.HTMLCharsAsIs = true
|
||||
testJsonH.MapKeyAsString = true
|
||||
// testJsonH.PreferFloat = true
|
||||
testReinit()
|
||||
t.Run("json-spaces-htmlcharsasis-initLen10", testJsonGroup)
|
||||
|
||||
testMaxInitLen = 10
|
||||
testJsonH.Indent = -1
|
||||
testJsonH.HTMLCharsAsIs = false
|
||||
testJsonH.MapKeyAsString = true
|
||||
// testJsonH.PreferFloat = false
|
||||
testReinit()
|
||||
t.Run("json-tabs-initLen10", testJsonGroup)
|
||||
|
||||
testJsonH.Indent, testJsonH.HTMLCharsAsIs, testJsonH.PreferFloat, testJsonH.MapKeyAsString =
|
||||
oldIndent, oldCharsAsis, oldPreferFloat, oldMapKeyAsString
|
||||
|
||||
oldIndefLen := testCborH.IndefiniteLength
|
||||
|
||||
testCborH.IndefiniteLength = true
|
||||
testReinit()
|
||||
t.Run("cbor-indefinitelength", testCborGroup)
|
||||
|
||||
testCborH.IndefiniteLength = oldIndefLen
|
||||
|
||||
oldTimeRFC3339 := testCborH.TimeRFC3339
|
||||
testCborH.TimeRFC3339 = !testCborH.TimeRFC3339
|
||||
testReinit()
|
||||
t.Run("cbor-rfc3339", testCborGroup)
|
||||
testCborH.TimeRFC3339 = oldTimeRFC3339
|
||||
|
||||
oldSymbols := testBincH.AsSymbols
|
||||
|
||||
testBincH.AsSymbols = 2 // AsSymbolNone
|
||||
testReinit()
|
||||
t.Run("binc-no-symbols", testBincGroup)
|
||||
|
||||
testBincH.AsSymbols = 1 // AsSymbolAll
|
||||
testReinit()
|
||||
t.Run("binc-all-symbols", testBincGroup)
|
||||
|
||||
testBincH.AsSymbols = oldSymbols
|
||||
|
||||
oldWriteExt := testMsgpackH.WriteExt
|
||||
oldNoFixedNum := testMsgpackH.NoFixedNum
|
||||
|
||||
testMsgpackH.WriteExt = !testMsgpackH.WriteExt
|
||||
testReinit()
|
||||
t.Run("msgpack-inverse-writeext", testMsgpackGroup)
|
||||
|
||||
testMsgpackH.WriteExt = oldWriteExt
|
||||
|
||||
testMsgpackH.NoFixedNum = !testMsgpackH.NoFixedNum
|
||||
testReinit()
|
||||
t.Run("msgpack-fixednum", testMsgpackGroup)
|
||||
|
||||
testMsgpackH.NoFixedNum = oldNoFixedNum
|
||||
|
||||
oldEncZeroValuesAsNil := testSimpleH.EncZeroValuesAsNil
|
||||
testSimpleH.EncZeroValuesAsNil = !testSimpleH.EncZeroValuesAsNil
|
||||
testUseMust = true
|
||||
testReinit()
|
||||
t.Run("simple-enczeroasnil", testSimpleMammothGroup) // testSimpleGroup
|
||||
testSimpleH.EncZeroValuesAsNil = oldEncZeroValuesAsNil
|
||||
|
||||
oldRpcBufsize := testRpcBufsize
|
||||
testRpcBufsize = 0
|
||||
t.Run("rpc-buf-0", testRpcGroup)
|
||||
testRpcBufsize = 0
|
||||
t.Run("rpc-buf-00", testRpcGroup)
|
||||
testRpcBufsize = 0
|
||||
t.Run("rpc-buf-000", testRpcGroup)
|
||||
testRpcBufsize = 16
|
||||
t.Run("rpc-buf-16", testRpcGroup)
|
||||
testRpcBufsize = 2048
|
||||
t.Run("rpc-buf-2048", testRpcGroup)
|
||||
testRpcBufsize = oldRpcBufsize
|
||||
|
||||
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)
|
||||
// })
|
||||
// }
|
47
vendor/github.com/ugorji/go/msgpack.org.md
generated
vendored
Normal file
47
vendor/github.com/ugorji/go/msgpack.org.md
generated
vendored
Normal file
@@ -0,0 +1,47 @@
|
||||
**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)
|
||||
```
|
Reference in New Issue
Block a user