vendor: remove dep and use vndr
Signed-off-by: Antonio Murdaca <runcom@redhat.com>
This commit is contained in:
parent
16f44674a4
commit
148e72d81e
16131 changed files with 73815 additions and 4235138 deletions
205
vendor/github.com/ugorji/go/codec/cbor_test.go
generated
vendored
205
vendor/github.com/ugorji/go/codec/cbor_test.go
generated
vendored
|
@ -1,205 +0,0 @@
|
|||
// 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
|
||||
|
||||
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 doTestCborGoldens(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 TestCborGoldens(t *testing.T) {
|
||||
doTestCborGoldens(t)
|
||||
}
|
1508
vendor/github.com/ugorji/go/codec/codec_test.go
generated
vendored
1508
vendor/github.com/ugorji/go/codec/codec_test.go
generated
vendored
File diff suppressed because it is too large
Load diff
37
vendor/github.com/ugorji/go/codec/codecgen/README.md
generated
vendored
37
vendor/github.com/ugorji/go/codec/codecgen/README.md
generated
vendored
|
@ -1,37 +0,0 @@
|
|||
# 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.
|
||||
|
317
vendor/github.com/ugorji/go/codec/codecgen/gen.go
generated
vendored
317
vendor/github.com/ugorji/go/codec/codecgen/gen.go
generated
vendored
|
@ -1,317 +0,0 @@
|
|||
// 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.
|
||||
|
||||
// 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
|
||||
|
||||
package main
|
||||
{{ if .Types }}import "{{ .ImportPath }}"{{ end }}
|
||||
func main() {
|
||||
{{ $.PackageName }}.CodecGenTempWrite{{ .RandString }}()
|
||||
}
|
||||
`
|
||||
|
||||
// const genFrunPkgTmpl = `//+build codecgen
|
||||
const genFrunPkgTmpl = `
|
||||
package {{ $.PackageName }}
|
||||
|
||||
import (
|
||||
{{ if not .CodecPkgFiles }}{{ .CodecPkgName }} "{{ .CodecImportPath }}"{{ end }}
|
||||
"os"
|
||||
"reflect"
|
||||
"bytes"
|
||||
"strings"
|
||||
"go/format"
|
||||
)
|
||||
|
||||
func CodecGenTempWrite{{ .RandString }}() {
|
||||
fout, err := os.Create("{{ .OutFile }}")
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
defer fout.Close()
|
||||
var out bytes.Buffer
|
||||
|
||||
var typs []reflect.Type
|
||||
{{ range $index, $element := .Types }}
|
||||
var t{{ $index }} {{ . }}
|
||||
typs = append(typs, reflect.TypeOf(t{{ $index }}))
|
||||
{{ end }}
|
||||
{{ if not .CodecPkgFiles }}{{ .CodecPkgName }}.{{ end }}Gen(&out, "{{ .BuildTag }}", "{{ .PackageName }}", "{{ .RandString }}", {{ .UseUnsafe }}, {{ if not .CodecPkgFiles }}{{ .CodecPkgName }}.{{ end }}NewTypeInfos(strings.Split("{{ .StructTags }}", ",")), typs...)
|
||||
bout, err := format.Source(out.Bytes())
|
||||
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, useUnsafe bool, goRunTag string,
|
||||
st string, regexName *regexp.Regexp, notRegexName *regexp.Regexp, deleteTempFile 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
|
||||
}
|
||||
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
|
||||
CodecPkgFiles bool
|
||||
UseUnsafe bool
|
||||
}
|
||||
tv := tmplT{
|
||||
CodecPkgName: genCodecPkg,
|
||||
OutFile: outfile,
|
||||
CodecImportPath: codecPkgPath,
|
||||
BuildTag: buildTag,
|
||||
UseUnsafe: useUnsafe,
|
||||
RandString: strconv.FormatInt(uid, 10),
|
||||
StructTags: st,
|
||||
}
|
||||
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
|
||||
s := tv.ImportPath
|
||||
const vendorStart = "vendor/"
|
||||
const vendorInline = "/vendor/"
|
||||
if i := strings.LastIndex(s, vendorInline); i >= 0 {
|
||||
tv.ImportPath = s[i+len(vendorInline):]
|
||||
} else if strings.HasPrefix(s, vendorStart) {
|
||||
tv.ImportPath = s[len(vendorStart):]
|
||||
}
|
||||
}
|
||||
astfiles := make([]*ast.File, len(infiles))
|
||||
for i, infile := range infiles {
|
||||
if filepath.Dir(infile) != lastdir {
|
||||
err = errors.New("in files must all be in same directory as outfile")
|
||||
return
|
||||
}
|
||||
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
|
||||
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="+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 {
|
||||
return
|
||||
}
|
||||
if err = bw.Flush(); err != nil {
|
||||
return
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
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")
|
||||
u := flag.Bool("u", false, "Use unsafe, e.g. to avoid unnecessary allocation on []byte->string")
|
||||
d := flag.Int64("d", 0, "random identifier for use in generated code")
|
||||
flag.Parse()
|
||||
if err := Generate(*o, *t, *c, *d, *u, *rt, *st,
|
||||
regexp.MustCompile(*r), regexp.MustCompile(*nr), !*x, flag.Args()...); 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
3
vendor/github.com/ugorji/go/codec/codecgen/z.go
generated
vendored
|
@ -1,3 +0,0 @@
|
|||
package main
|
||||
|
||||
const genCodecPath = "github.com/ugorji/go/codec"
|
24
vendor/github.com/ugorji/go/codec/codecgen_test.go
generated
vendored
24
vendor/github.com/ugorji/go/codec/codecgen_test.go
generated
vendored
|
@ -1,24 +0,0 @@
|
|||
// +build x,codecgen
|
||||
|
||||
package codec
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func _TestCodecgenJson1(t *testing.T) {
|
||||
// This is just a simplistic test for codecgen.
|
||||
// It is typically disabled. We only enable it for debugging purposes.
|
||||
const callCodecgenDirect bool = true
|
||||
v := newTestStruc(2, false, !testSkipIntf, false)
|
||||
var bs []byte
|
||||
e := NewEncoderBytes(&bs, testJsonH)
|
||||
if callCodecgenDirect {
|
||||
v.CodecEncodeSelf(e)
|
||||
e.w.atEndOfEncode()
|
||||
} else {
|
||||
e.MustEncode(v)
|
||||
}
|
||||
fmt.Printf("%s\n", bs)
|
||||
}
|
527
vendor/github.com/ugorji/go/codec/fast-path.go.tmpl
generated
vendored
527
vendor/github.com/ugorji/go/codec/fast-path.go.tmpl
generated
vendored
|
@ -1,527 +0,0 @@
|
|||
// +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.
|
||||
|
||||
// ************************************************************
|
||||
// DO NOT EDIT.
|
||||
// THIS FILE IS AUTO-GENERATED from fast-path.go.tmpl
|
||||
// ************************************************************
|
||||
|
||||
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
|
||||
|
||||
const fastpathCheckNilFalse = false // for reflect
|
||||
const fastpathCheckNilTrue = true // for type switch
|
||||
|
||||
type fastpathT struct {}
|
||||
|
||||
var fastpathTV fastpathT
|
||||
|
||||
type fastpathE struct {
|
||||
rtid uintptr
|
||||
rt reflect.Type
|
||||
encfn func(*encFnInfo, reflect.Value)
|
||||
decfn func(*decFnInfo, 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(*encFnInfo, reflect.Value), fd func(*decFnInfo, reflect.Value)) (f fastpathE) {
|
||||
xrt := reflect.TypeOf(v)
|
||||
xptr := reflect.ValueOf(xrt).Pointer()
|
||||
fastpathAV[i] = fastpathE{xptr, xrt, fe, fd}
|
||||
i++
|
||||
return
|
||||
}
|
||||
|
||||
{{range .Values}}{{if not .Primitive}}{{if not .MapKey }}
|
||||
fn([]{{ .Elem }}(nil), (*encFnInfo).{{ .MethodNamePfx "fastpathEnc" false }}R, (*decFnInfo).{{ .MethodNamePfx "fastpathDec" false }}R){{end}}{{end}}{{end}}
|
||||
|
||||
{{range .Values}}{{if not .Primitive}}{{if .MapKey }}
|
||||
fn(map[{{ .MapKey }}]{{ .Elem }}(nil), (*encFnInfo).{{ .MethodNamePfx "fastpathEnc" false }}R, (*decFnInfo).{{ .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 }}
|
||||
case []{{ .Elem }}:{{else}}
|
||||
case map[{{ .MapKey }}]{{ .Elem }}:{{end}}
|
||||
fastpathTV.{{ .MethodNamePfx "Enc" false }}V(v, fastpathCheckNilTrue, e){{if not .MapKey }}
|
||||
case *[]{{ .Elem }}:{{else}}
|
||||
case *map[{{ .MapKey }}]{{ .Elem }}:{{end}}
|
||||
fastpathTV.{{ .MethodNamePfx "Enc" false }}V(*v, fastpathCheckNilTrue, e)
|
||||
{{end}}{{end}}
|
||||
default:
|
||||
_ = v // TODO: workaround https://github.com/golang/go/issues/12927 (remove after go 1.6 release)
|
||||
return false
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
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, fastpathCheckNilTrue, e)
|
||||
case *[]{{ .Elem }}:
|
||||
fastpathTV.{{ .MethodNamePfx "Enc" false }}V(*v, fastpathCheckNilTrue, e)
|
||||
{{end}}{{end}}{{end}}
|
||||
default:
|
||||
_ = v // TODO: workaround https://github.com/golang/go/issues/12927 (remove after go 1.6 release)
|
||||
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, fastpathCheckNilTrue, e)
|
||||
case *map[{{ .MapKey }}]{{ .Elem }}:
|
||||
fastpathTV.{{ .MethodNamePfx "Enc" false }}V(*v, fastpathCheckNilTrue, e)
|
||||
{{end}}{{end}}{{end}}
|
||||
default:
|
||||
_ = v // TODO: workaround https://github.com/golang/go/issues/12927 (remove after go 1.6 release)
|
||||
return false
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
// -- -- fast path functions
|
||||
{{range .Values}}{{if not .Primitive}}{{if not .MapKey }}
|
||||
|
||||
func (f *encFnInfo) {{ .MethodNamePfx "fastpathEnc" false }}R(rv reflect.Value) {
|
||||
if f.ti.mbs {
|
||||
fastpathTV.{{ .MethodNamePfx "EncAsMap" false }}V(rv.Interface().([]{{ .Elem }}), fastpathCheckNilFalse, f.e)
|
||||
} else {
|
||||
fastpathTV.{{ .MethodNamePfx "Enc" false }}V(rv.Interface().([]{{ .Elem }}), fastpathCheckNilFalse, f.e)
|
||||
}
|
||||
}
|
||||
func (_ fastpathT) {{ .MethodNamePfx "Enc" false }}V(v []{{ .Elem }}, checkNil bool, e *Encoder) {
|
||||
ee := e.e
|
||||
cr := e.cr
|
||||
if checkNil && v == nil {
|
||||
ee.EncodeNil()
|
||||
return
|
||||
}
|
||||
ee.EncodeArrayStart(len(v))
|
||||
for _, v2 := range v {
|
||||
if cr != nil { cr.sendContainerState(containerArrayElem) }
|
||||
{{ encmd .Elem "v2"}}
|
||||
}
|
||||
if cr != nil { cr.sendContainerState(containerArrayEnd) }{{/* ee.EncodeEnd() */}}
|
||||
}
|
||||
|
||||
func (_ fastpathT) {{ .MethodNamePfx "EncAsMap" false }}V(v []{{ .Elem }}, checkNil bool, e *Encoder) {
|
||||
ee := e.e
|
||||
cr := e.cr
|
||||
if checkNil && v == nil {
|
||||
ee.EncodeNil()
|
||||
return
|
||||
}
|
||||
if len(v)%2 == 1 {
|
||||
e.errorf("mapBySlice requires even slice length, but got %v", len(v))
|
||||
return
|
||||
}
|
||||
ee.EncodeMapStart(len(v) / 2)
|
||||
for j, v2 := range v {
|
||||
if cr != nil {
|
||||
if j%2 == 0 {
|
||||
cr.sendContainerState(containerMapKey)
|
||||
} else {
|
||||
cr.sendContainerState(containerMapValue)
|
||||
}
|
||||
}
|
||||
{{ encmd .Elem "v2"}}
|
||||
}
|
||||
if cr != nil { cr.sendContainerState(containerMapEnd) }
|
||||
}
|
||||
|
||||
{{end}}{{end}}{{end}}
|
||||
|
||||
{{range .Values}}{{if not .Primitive}}{{if .MapKey }}
|
||||
|
||||
func (f *encFnInfo) {{ .MethodNamePfx "fastpathEnc" false }}R(rv reflect.Value) {
|
||||
fastpathTV.{{ .MethodNamePfx "Enc" false }}V(rv.Interface().(map[{{ .MapKey }}]{{ .Elem }}), fastpathCheckNilFalse, f.e)
|
||||
}
|
||||
func (_ fastpathT) {{ .MethodNamePfx "Enc" false }}V(v map[{{ .MapKey }}]{{ .Elem }}, checkNil bool, e *Encoder) {
|
||||
ee := e.e
|
||||
cr := e.cr
|
||||
if checkNil && v == nil {
|
||||
ee.EncodeNil()
|
||||
return
|
||||
}
|
||||
ee.EncodeMapStart(len(v))
|
||||
{{if eq .MapKey "string"}}asSymbols := e.h.AsSymbols&AsSymbolMapStringKeysFlag != 0
|
||||
{{end}}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))
|
||||
for j := range v2 {
|
||||
if cr != nil { cr.sendContainerState(containerMapKey) }
|
||||
e.asis(v2[j].v)
|
||||
if cr != nil { cr.sendContainerState(containerMapValue) }
|
||||
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))
|
||||
for _, k2 := range v2 {
|
||||
if cr != nil { cr.sendContainerState(containerMapKey) }
|
||||
{{if eq .MapKey "string"}}if asSymbols {
|
||||
ee.EncodeSymbol(k2)
|
||||
} else {
|
||||
ee.EncodeString(c_UTF8, k2)
|
||||
}{{else}}{{ $y := printf "%s(k2)" .MapKey }}{{ encmd .MapKey $y }}{{end}}
|
||||
if cr != nil { cr.sendContainerState(containerMapValue) }
|
||||
{{ $y := printf "v[%s(k2)]" .MapKey }}{{ encmd .Elem $y }}
|
||||
} {{end}}
|
||||
} else {
|
||||
for k2, v2 := range v {
|
||||
if cr != nil { cr.sendContainerState(containerMapKey) }
|
||||
{{if eq .MapKey "string"}}if asSymbols {
|
||||
ee.EncodeSymbol(k2)
|
||||
} else {
|
||||
ee.EncodeString(c_UTF8, k2)
|
||||
}{{else}}{{ encmd .MapKey "k2"}}{{end}}
|
||||
if cr != nil { cr.sendContainerState(containerMapValue) }
|
||||
{{ encmd .Elem "v2"}}
|
||||
}
|
||||
}
|
||||
if cr != nil { cr.sendContainerState(containerMapEnd) }{{/* ee.EncodeEnd() */}}
|
||||
}
|
||||
|
||||
{{end}}{{end}}{{end}}
|
||||
|
||||
// -- decode
|
||||
|
||||
// -- -- fast path type switch
|
||||
func fastpathDecodeTypeSwitch(iv interface{}, d *Decoder) bool {
|
||||
switch v := iv.(type) {
|
||||
{{range .Values}}{{if not .Primitive}}{{if not .MapKey }}
|
||||
case []{{ .Elem }}:{{else}}
|
||||
case map[{{ .MapKey }}]{{ .Elem }}:{{end}}
|
||||
fastpathTV.{{ .MethodNamePfx "Dec" false }}V(v, fastpathCheckNilFalse, false, d){{if not .MapKey }}
|
||||
case *[]{{ .Elem }}:{{else}}
|
||||
case *map[{{ .MapKey }}]{{ .Elem }}:{{end}}
|
||||
v2, changed2 := fastpathTV.{{ .MethodNamePfx "Dec" false }}V(*v, fastpathCheckNilFalse, true, d)
|
||||
if changed2 {
|
||||
*v = v2
|
||||
}
|
||||
{{end}}{{end}}
|
||||
default:
|
||||
_ = v // TODO: workaround https://github.com/golang/go/issues/12927 (remove after go 1.6 release)
|
||||
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 (f *decFnInfo) {{ .MethodNamePfx "fastpathDec" false }}R(rv reflect.Value) {
|
||||
array := f.seq == seqTypeArray
|
||||
if !array && rv.CanAddr() { {{/* // CanSet => CanAddr + Exported */}}
|
||||
vp := rv.Addr().Interface().(*[]{{ .Elem }})
|
||||
v, changed := fastpathTV.{{ .MethodNamePfx "Dec" false }}V(*vp, fastpathCheckNilFalse, !array, f.d)
|
||||
if changed {
|
||||
*vp = v
|
||||
}
|
||||
} else {
|
||||
v := rv.Interface().([]{{ .Elem }})
|
||||
fastpathTV.{{ .MethodNamePfx "Dec" false }}V(v, fastpathCheckNilFalse, false, f.d)
|
||||
}
|
||||
}
|
||||
|
||||
func (f fastpathT) {{ .MethodNamePfx "Dec" false }}X(vp *[]{{ .Elem }}, checkNil bool, d *Decoder) {
|
||||
v, changed := f.{{ .MethodNamePfx "Dec" false }}V(*vp, checkNil, true, d)
|
||||
if changed {
|
||||
*vp = v
|
||||
}
|
||||
}
|
||||
func (_ fastpathT) {{ .MethodNamePfx "Dec" false }}V(v []{{ .Elem }}, checkNil bool, canChange bool, d *Decoder) (_ []{{ .Elem }}, changed bool) {
|
||||
dd := d.d
|
||||
{{/* // if dd.isContainerType(valueTypeNil) { dd.TryDecodeAsNil() */}}
|
||||
if checkNil && dd.TryDecodeAsNil() {
|
||||
if v != nil {
|
||||
changed = true
|
||||
}
|
||||
return nil, changed
|
||||
}
|
||||
|
||||
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
|
||||
}
|
||||
|
||||
if containerLenS > 0 {
|
||||
x2read := containerLenS
|
||||
var xtrunc bool
|
||||
if containerLenS > cap(v) {
|
||||
if canChange { {{/*
|
||||
// fast-path is for "basic" immutable types, so no need to copy them over
|
||||
// s := make([]{{ .Elem }}, decInferLen(containerLenS, d.h.MaxInitLen))
|
||||
// copy(s, v[:cap(v)])
|
||||
// v = s */}}
|
||||
var xlen int
|
||||
xlen, xtrunc = decInferLen(containerLenS, d.h.MaxInitLen, {{ .Size }})
|
||||
if xtrunc {
|
||||
if xlen <= cap(v) {
|
||||
v = v[:xlen]
|
||||
} else {
|
||||
v = make([]{{ .Elem }}, xlen)
|
||||
}
|
||||
} else {
|
||||
v = make([]{{ .Elem }}, xlen)
|
||||
}
|
||||
changed = true
|
||||
} else {
|
||||
d.arrayCannotExpand(len(v), containerLenS)
|
||||
}
|
||||
x2read = len(v)
|
||||
} else if containerLenS != len(v) {
|
||||
if canChange {
|
||||
v = v[:containerLenS]
|
||||
changed = true
|
||||
}
|
||||
} {{/* // all checks done. cannot go past len. */}}
|
||||
j := 0
|
||||
for ; j < x2read; j++ {
|
||||
slh.ElemContainerState(j)
|
||||
{{ if eq .Elem "interface{}" }}d.decode(&v[j]){{ else }}v[j] = {{ decmd .Elem }}{{ end }}
|
||||
}
|
||||
if xtrunc { {{/* // means canChange=true, changed=true already. */}}
|
||||
for ; j < containerLenS; j++ {
|
||||
v = append(v, {{ zerocmd .Elem }})
|
||||
slh.ElemContainerState(j)
|
||||
{{ if eq .Elem "interface{}" }}d.decode(&v[j]){{ else }}v[j] = {{ decmd .Elem }}{{ end }}
|
||||
}
|
||||
} else if !canChange {
|
||||
for ; j < containerLenS; j++ {
|
||||
slh.ElemContainerState(j)
|
||||
d.swallow()
|
||||
}
|
||||
}
|
||||
} else {
|
||||
breakFound := dd.CheckBreak() {{/* check break first, so we can initialize v with a capacity of 4 if necessary */}}
|
||||
if breakFound {
|
||||
if canChange {
|
||||
if v == nil {
|
||||
v = []{{ .Elem }}{}
|
||||
} else if len(v) != 0 {
|
||||
v = v[:0]
|
||||
}
|
||||
changed = true
|
||||
}
|
||||
slh.End()
|
||||
return v, changed
|
||||
}
|
||||
if cap(v) == 0 {
|
||||
v = make([]{{ .Elem }}, 1, 4)
|
||||
changed = true
|
||||
}
|
||||
j := 0
|
||||
for ; !breakFound; j++ {
|
||||
if j >= len(v) {
|
||||
if canChange {
|
||||
v = append(v, {{ zerocmd .Elem }})
|
||||
changed = true
|
||||
} else {
|
||||
d.arrayCannotExpand(len(v), j+1)
|
||||
}
|
||||
}
|
||||
slh.ElemContainerState(j)
|
||||
if j < len(v) { {{/* // all checks done. cannot go past len. */}}
|
||||
{{ if eq .Elem "interface{}" }}d.decode(&v[j])
|
||||
{{ else }}v[j] = {{ decmd .Elem }}{{ end }}
|
||||
} else {
|
||||
d.swallow()
|
||||
}
|
||||
breakFound = dd.CheckBreak()
|
||||
}
|
||||
if canChange && j < len(v) {
|
||||
v = v[:j]
|
||||
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 (f *decFnInfo) {{ .MethodNamePfx "fastpathDec" false }}R(rv reflect.Value) {
|
||||
if rv.CanAddr() {
|
||||
vp := rv.Addr().Interface().(*map[{{ .MapKey }}]{{ .Elem }})
|
||||
v, changed := fastpathTV.{{ .MethodNamePfx "Dec" false }}V(*vp, fastpathCheckNilFalse, true, f.d)
|
||||
if changed {
|
||||
*vp = v
|
||||
}
|
||||
} else {
|
||||
v := rv.Interface().(map[{{ .MapKey }}]{{ .Elem }})
|
||||
fastpathTV.{{ .MethodNamePfx "Dec" false }}V(v, fastpathCheckNilFalse, false, f.d)
|
||||
}
|
||||
}
|
||||
func (f fastpathT) {{ .MethodNamePfx "Dec" false }}X(vp *map[{{ .MapKey }}]{{ .Elem }}, checkNil bool, d *Decoder) {
|
||||
v, changed := f.{{ .MethodNamePfx "Dec" false }}V(*vp, checkNil, true, d)
|
||||
if changed {
|
||||
*vp = v
|
||||
}
|
||||
}
|
||||
func (_ fastpathT) {{ .MethodNamePfx "Dec" false }}V(v map[{{ .MapKey }}]{{ .Elem }}, checkNil bool, canChange bool,
|
||||
d *Decoder) (_ map[{{ .MapKey }}]{{ .Elem }}, changed bool) {
|
||||
dd := d.d
|
||||
cr := d.cr
|
||||
{{/* // if dd.isContainerType(valueTypeNil) {dd.TryDecodeAsNil() */}}
|
||||
if checkNil && dd.TryDecodeAsNil() {
|
||||
if v != nil {
|
||||
changed = true
|
||||
}
|
||||
return nil, changed
|
||||
}
|
||||
|
||||
containerLen := dd.ReadMapStart()
|
||||
if canChange && v == nil {
|
||||
xlen, _ := decInferLen(containerLen, d.h.MaxInitLen, {{ .Size }})
|
||||
v = make(map[{{ .MapKey }}]{{ .Elem }}, xlen)
|
||||
changed = true
|
||||
}
|
||||
{{ if eq .Elem "interface{}" }}mapGet := !d.h.MapValueReset && !d.h.InterfaceReset{{end}}
|
||||
var mk {{ .MapKey }}
|
||||
var mv {{ .Elem }}
|
||||
if containerLen > 0 {
|
||||
for j := 0; j < containerLen; j++ {
|
||||
if cr != nil { cr.sendContainerState(containerMapKey) }
|
||||
{{ 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 cr != nil { cr.sendContainerState(containerMapValue) }
|
||||
{{ 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
|
||||
}
|
||||
}
|
||||
} else if containerLen < 0 {
|
||||
for j := 0; !dd.CheckBreak(); j++ {
|
||||
if cr != nil { cr.sendContainerState(containerMapKey) }
|
||||
{{ 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 cr != nil { cr.sendContainerState(containerMapValue) }
|
||||
{{ 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
|
||||
}
|
||||
}
|
||||
}
|
||||
if cr != nil { cr.sendContainerState(containerMapEnd) }
|
||||
return v, changed
|
||||
}
|
||||
|
||||
{{end}}{{end}}{{end}}
|
104
vendor/github.com/ugorji/go/codec/gen-dec-array.go.tmpl
generated
vendored
104
vendor/github.com/ugorji/go/codec/gen-dec-array.go.tmpl
generated
vendored
|
@ -1,104 +0,0 @@
|
|||
{{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 if {{var "l"}} > 0 {
|
||||
{{if isChan }}if {{var "v"}} == nil {
|
||||
{{var "rl"}}, _ = z.DecInferLen({{var "l"}}, z.DecBasicHandle().MaxInitLen, {{ .Size }})
|
||||
{{var "v"}} = make({{ .CTyp }}, {{var "rl"}})
|
||||
{{var "c"}} = true
|
||||
}
|
||||
for {{var "r"}} := 0; {{var "r"}} < {{var "l"}}; {{var "r"}}++ {
|
||||
{{var "h"}}.ElemContainerState({{var "r"}})
|
||||
var {{var "t"}} {{ .Typ }}
|
||||
{{ $x := printf "%st%s" .TempVar .Rand }}{{ decLineVar $x }}
|
||||
{{var "v"}} <- {{var "t"}}
|
||||
}
|
||||
{{ else }} var {{var "rr"}}, {{var "rl"}} int {{/* // num2read, length of slice/array/chan */}}
|
||||
var {{var "rt"}} bool {{/* truncated */}}
|
||||
_, _ = {{var "rl"}}, {{var "rt"}}
|
||||
{{var "rr"}} = {{var "l"}} // len({{var "v"}})
|
||||
if {{var "l"}} > cap({{var "v"}}) {
|
||||
{{if isArray }}z.DecArrayCannotExpand(len({{var "v"}}), {{var "l"}})
|
||||
{{ else }}{{if not .Immutable }}
|
||||
{{var "rg"}} := len({{var "v"}}) > 0
|
||||
{{var "v2"}} := {{var "v"}} {{end}}
|
||||
{{var "rl"}}, {{var "rt"}} = z.DecInferLen({{var "l"}}, z.DecBasicHandle().MaxInitLen, {{ .Size }})
|
||||
if {{var "rt"}} {
|
||||
if {{var "rl"}} <= cap({{var "v"}}) {
|
||||
{{var "v"}} = {{var "v"}}[:{{var "rl"}}]
|
||||
} else {
|
||||
{{var "v"}} = make([]{{ .Typ }}, {{var "rl"}})
|
||||
}
|
||||
} else {
|
||||
{{var "v"}} = make([]{{ .Typ }}, {{var "rl"}})
|
||||
}
|
||||
{{var "c"}} = true
|
||||
{{var "rr"}} = len({{var "v"}}) {{if not .Immutable }}
|
||||
if {{var "rg"}} { copy({{var "v"}}, {{var "v2"}}) } {{end}} {{end}}{{/* end not Immutable, isArray */}}
|
||||
} {{if isSlice }} else if {{var "l"}} != len({{var "v"}}) {
|
||||
{{var "v"}} = {{var "v"}}[:{{var "l"}}]
|
||||
{{var "c"}} = true
|
||||
} {{end}} {{/* end isSlice:47 */}}
|
||||
{{var "j"}} := 0
|
||||
for ; {{var "j"}} < {{var "rr"}} ; {{var "j"}}++ {
|
||||
{{var "h"}}.ElemContainerState({{var "j"}})
|
||||
{{ $x := printf "%[1]vv%[2]v[%[1]vj%[2]v]" .TempVar .Rand }}{{ decLineVar $x }}
|
||||
}
|
||||
{{if isArray }}for ; {{var "j"}} < {{var "l"}} ; {{var "j"}}++ {
|
||||
{{var "h"}}.ElemContainerState({{var "j"}})
|
||||
z.DecSwallow()
|
||||
}
|
||||
{{ else }}if {{var "rt"}} {
|
||||
for ; {{var "j"}} < {{var "l"}} ; {{var "j"}}++ {
|
||||
{{var "v"}} = append({{var "v"}}, {{ zero}})
|
||||
{{var "h"}}.ElemContainerState({{var "j"}})
|
||||
{{ $x := printf "%[1]vv%[2]v[%[1]vj%[2]v]" .TempVar .Rand }}{{ decLineVar $x }}
|
||||
}
|
||||
} {{end}} {{/* end isArray:56 */}}
|
||||
{{end}} {{/* end isChan:16 */}}
|
||||
} else { {{/* len < 0 */}}
|
||||
{{var "j"}} := 0
|
||||
for ; !r.CheckBreak(); {{var "j"}}++ {
|
||||
{{if isChan }}
|
||||
{{var "h"}}.ElemContainerState({{var "j"}})
|
||||
var {{var "t"}} {{ .Typ }}
|
||||
{{ $x := printf "%st%s" .TempVar .Rand }}{{ decLineVar $x }}
|
||||
{{var "v"}} <- {{var "t"}}
|
||||
{{ else }}
|
||||
if {{var "j"}} >= len({{var "v"}}) {
|
||||
{{if isArray }}z.DecArrayCannotExpand(len({{var "v"}}), {{var "j"}}+1)
|
||||
{{ else }}{{var "v"}} = append({{var "v"}}, {{zero}})// var {{var "z"}} {{ .Typ }}
|
||||
{{var "c"}} = true {{end}}
|
||||
}
|
||||
{{var "h"}}.ElemContainerState({{var "j"}})
|
||||
if {{var "j"}} < len({{var "v"}}) {
|
||||
{{ $x := printf "%[1]vv%[2]v[%[1]vj%[2]v]" .TempVar .Rand }}{{ decLineVar $x }}
|
||||
} else {
|
||||
z.DecSwallow()
|
||||
}
|
||||
{{end}}
|
||||
}
|
||||
{{if isSlice }}if {{var "j"}} < len({{var "v"}}) {
|
||||
{{var "v"}} = {{var "v"}}[:{{var "j"}}]
|
||||
{{var "c"}} = true
|
||||
} else if {{var "j"}} == 0 && {{var "v"}} == nil {
|
||||
{{var "v"}} = []{{ .Typ }}{}
|
||||
{{var "c"}} = true
|
||||
}{{end}}
|
||||
}
|
||||
{{var "h"}}.End()
|
||||
{{if not isArray }}if {{var "c"}} {
|
||||
*{{ .Varname }} = {{var "v"}}
|
||||
}{{end}}
|
58
vendor/github.com/ugorji/go/codec/gen-dec-map.go.tmpl
generated
vendored
58
vendor/github.com/ugorji/go/codec/gen-dec-map.go.tmpl
generated
vendored
|
@ -1,58 +0,0 @@
|
|||
{{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"}} {{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 {
|
||||
for {{var "j"}} := 0; {{var "j"}} < {{var "l"}}; {{var "j"}}++ {
|
||||
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}}
|
||||
z.DecSendContainerState(codecSelfer_containerMapValue{{ .Sfx }})
|
||||
{{ $x := printf "%vmv%v" .TempVar .Rand }}{{ decLineVar $x }}
|
||||
if {{if decElemKindPtr}} {{var "ms"}} && {{end}} {{var "v"}} != nil {
|
||||
{{var "v"}}[{{var "mk"}}] = {{var "mv"}}
|
||||
}
|
||||
}
|
||||
} else if {{var "l"}} < 0 {
|
||||
for {{var "j"}} := 0; !r.CheckBreak(); {{var "j"}}++ {
|
||||
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}}
|
||||
z.DecSendContainerState(codecSelfer_containerMapValue{{ .Sfx }})
|
||||
{{ $x := printf "%vmv%v" .TempVar .Rand }}{{ decLineVar $x }}
|
||||
if {{if decElemKindPtr}} {{var "ms"}} && {{end}} {{var "v"}} != nil {
|
||||
{{var "v"}}[{{var "mk"}}] = {{var "mv"}}
|
||||
}
|
||||
}
|
||||
} // else len==0: TODO: Should we clear map entries?
|
||||
z.DecSendContainerState(codecSelfer_containerMapEnd{{ .Sfx }})
|
372
vendor/github.com/ugorji/go/codec/gen-helper.go.tmpl
generated
vendored
372
vendor/github.com/ugorji/go/codec/gen-helper.go.tmpl
generated
vendored
|
@ -1,372 +0,0 @@
|
|||
/* // +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.
|
||||
|
||||
// ************************************************************
|
||||
// DO NOT EDIT.
|
||||
// THIS FILE IS AUTO-GENERATED from gen-helper.go.tmpl
|
||||
// ************************************************************
|
||||
|
||||
package codec
|
||||
|
||||
import (
|
||||
"encoding"
|
||||
"reflect"
|
||||
)
|
||||
|
||||
// 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) (genHelperEncoder, encDriver) {
|
||||
return genHelperEncoder{e:e}, e.e
|
||||
}
|
||||
|
||||
// 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) (genHelperDecoder, decDriver) {
|
||||
return genHelperDecoder{d:d}, d.d
|
||||
}
|
||||
|
||||
// FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
|
||||
type genHelperEncoder struct {
|
||||
e *Encoder
|
||||
F fastpathT
|
||||
}
|
||||
|
||||
// FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
|
||||
type genHelperDecoder struct {
|
||||
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) EncFallback(iv interface{}) {
|
||||
// println(">>>>>>>>> EncFallback")
|
||||
f.e.encodeI(iv, false, 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, c_UTF8)
|
||||
}
|
||||
// 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, c_UTF8)
|
||||
}
|
||||
// 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, c_RAW)
|
||||
}
|
||||
// FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
|
||||
func (f genHelperEncoder) EncRaw(iv Raw) {
|
||||
f.e.raw(iv)
|
||||
}
|
||||
// FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
|
||||
func (f genHelperEncoder) TimeRtidIfBinc() uintptr {
|
||||
if _, ok := f.e.hh.(*BincHandle); ok {
|
||||
return timeTypId
|
||||
}
|
||||
return 0
|
||||
}
|
||||
// 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) HasExtensions() bool {
|
||||
return len(f.e.h.extHandle) != 0
|
||||
}
|
||||
// FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
|
||||
func (f genHelperEncoder) EncExt(v interface{}) (r bool) {
|
||||
rt := reflect.TypeOf(v)
|
||||
if rt.Kind() == reflect.Ptr {
|
||||
rt = rt.Elem()
|
||||
}
|
||||
rtid := reflect.ValueOf(rt).Pointer()
|
||||
if xfFn := f.e.h.getExt(rtid); xfFn != nil {
|
||||
f.e.e.EncodeExt(v, xfFn.tag, xfFn.ext, f.e)
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
// FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
|
||||
func (f genHelperEncoder) EncSendContainerState(c containerState) {
|
||||
if f.e.cr != nil {
|
||||
f.e.cr.sendContainerState(c)
|
||||
}
|
||||
}
|
||||
|
||||
// ---------------- 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) DecFallback(iv interface{}, chkPtr bool) {
|
||||
// println(">>>>>>>>> DecFallback")
|
||||
f.d.decodeI(iv, chkPtr, false, false, false)
|
||||
}
|
||||
// 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.DecodeBytes(f.d.b[:], true, true))
|
||||
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.DecodeBytes(f.d.b[:], true, true)
|
||||
// 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, false, 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.raw()
|
||||
}
|
||||
// FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
|
||||
func (f genHelperDecoder) TimeRtidIfBinc() uintptr {
|
||||
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) HasExtensions() bool {
|
||||
return len(f.d.h.extHandle) != 0
|
||||
}
|
||||
// FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
|
||||
func (f genHelperDecoder) DecExt(v interface{}) (r bool) {
|
||||
rt := reflect.TypeOf(v).Elem()
|
||||
rtid := reflect.ValueOf(rt).Pointer()
|
||||
if xfFn := f.d.h.getExt(rtid); 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, truncated bool) {
|
||||
return decInferLen(clen, maxlen, unit)
|
||||
}
|
||||
// FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
|
||||
func (f genHelperDecoder) DecSendContainerState(c containerState) {
|
||||
if f.d.cr != nil {
|
||||
f.d.cr.sendContainerState(c)
|
||||
}
|
||||
}
|
||||
|
||||
{{/*
|
||||
|
||||
// FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
|
||||
func (f genHelperEncoder) EncDriver() encDriver {
|
||||
return f.e.e
|
||||
}
|
||||
// FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
|
||||
func (f genHelperDecoder) DecDriver() decDriver {
|
||||
return f.d.d
|
||||
}
|
||||
|
||||
// FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
|
||||
func (f genHelperEncoder) EncNil() {
|
||||
f.e.e.EncodeNil()
|
||||
}
|
||||
// FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
|
||||
func (f genHelperEncoder) EncBytes(v []byte) {
|
||||
f.e.e.EncodeStringBytes(c_RAW, v)
|
||||
}
|
||||
// FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
|
||||
func (f genHelperEncoder) EncArrayStart(length int) {
|
||||
f.e.e.EncodeArrayStart(length)
|
||||
}
|
||||
// FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
|
||||
func (f genHelperEncoder) EncArrayEnd() {
|
||||
f.e.e.EncodeArrayEnd()
|
||||
}
|
||||
// FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
|
||||
func (f genHelperEncoder) EncArrayEntrySeparator() {
|
||||
f.e.e.EncodeArrayEntrySeparator()
|
||||
}
|
||||
// FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
|
||||
func (f genHelperEncoder) EncMapStart(length int) {
|
||||
f.e.e.EncodeMapStart(length)
|
||||
}
|
||||
// FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
|
||||
func (f genHelperEncoder) EncMapEnd() {
|
||||
f.e.e.EncodeMapEnd()
|
||||
}
|
||||
// FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
|
||||
func (f genHelperEncoder) EncMapEntrySeparator() {
|
||||
f.e.e.EncodeMapEntrySeparator()
|
||||
}
|
||||
// FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
|
||||
func (f genHelperEncoder) EncMapKVSeparator() {
|
||||
f.e.e.EncodeMapKVSeparator()
|
||||
}
|
||||
|
||||
// ---------
|
||||
|
||||
// FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
|
||||
func (f genHelperDecoder) DecBytes(v *[]byte) {
|
||||
*v = f.d.d.DecodeBytes(*v)
|
||||
}
|
||||
// FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
|
||||
func (f genHelperDecoder) DecTryNil() bool {
|
||||
return f.d.d.TryDecodeAsNil()
|
||||
}
|
||||
// FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
|
||||
func (f genHelperDecoder) DecContainerIsNil() (b bool) {
|
||||
return f.d.d.IsContainerType(valueTypeNil)
|
||||
}
|
||||
// FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
|
||||
func (f genHelperDecoder) DecContainerIsMap() (b bool) {
|
||||
return f.d.d.IsContainerType(valueTypeMap)
|
||||
}
|
||||
// FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
|
||||
func (f genHelperDecoder) DecContainerIsArray() (b bool) {
|
||||
return f.d.d.IsContainerType(valueTypeArray)
|
||||
}
|
||||
// FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
|
||||
func (f genHelperDecoder) DecCheckBreak() bool {
|
||||
return f.d.d.CheckBreak()
|
||||
}
|
||||
// FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
|
||||
func (f genHelperDecoder) DecMapStart() int {
|
||||
return f.d.d.ReadMapStart()
|
||||
}
|
||||
// FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
|
||||
func (f genHelperDecoder) DecArrayStart() int {
|
||||
return f.d.d.ReadArrayStart()
|
||||
}
|
||||
// FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
|
||||
func (f genHelperDecoder) DecMapEnd() {
|
||||
f.d.d.ReadMapEnd()
|
||||
}
|
||||
// FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
|
||||
func (f genHelperDecoder) DecArrayEnd() {
|
||||
f.d.d.ReadArrayEnd()
|
||||
}
|
||||
// FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
|
||||
func (f genHelperDecoder) DecArrayEntrySeparator() {
|
||||
f.d.d.ReadArrayEntrySeparator()
|
||||
}
|
||||
// FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
|
||||
func (f genHelperDecoder) DecMapEntrySeparator() {
|
||||
f.d.d.ReadMapEntrySeparator()
|
||||
}
|
||||
// FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
|
||||
func (f genHelperDecoder) DecMapKVSeparator() {
|
||||
f.d.d.ReadMapKVSeparator()
|
||||
}
|
||||
// FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
|
||||
func (f genHelperDecoder) ReadStringAsBytes(bs []byte) []byte {
|
||||
return f.d.d.DecodeStringAsBytes(bs)
|
||||
}
|
||||
|
||||
|
||||
// -- encode calls (primitives)
|
||||
{{range .Values}}{{if .Primitive }}{{if ne .Primitive "interface{}" }}
|
||||
// FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
|
||||
func (f genHelperEncoder) {{ .MethodNamePfx "Enc" true }}(v {{ .Primitive }}) {
|
||||
ee := f.e.e
|
||||
{{ encmd .Primitive "v" }}
|
||||
}
|
||||
{{ end }}{{ end }}{{ end }}
|
||||
|
||||
// -- decode calls (primitives)
|
||||
{{range .Values}}{{if .Primitive }}{{if ne .Primitive "interface{}" }}
|
||||
// FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
|
||||
func (f genHelperDecoder) {{ .MethodNamePfx "Dec" true }}(vp *{{ .Primitive }}) {
|
||||
dd := f.d.d
|
||||
*vp = {{ decmd .Primitive }}
|
||||
}
|
||||
// FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
|
||||
func (f genHelperDecoder) {{ .MethodNamePfx "Read" true }}() (v {{ .Primitive }}) {
|
||||
dd := f.d.d
|
||||
v = {{ decmd .Primitive }}
|
||||
return
|
||||
}
|
||||
{{ end }}{{ end }}{{ end }}
|
||||
|
||||
|
||||
// -- encode calls (slices/maps)
|
||||
{{range .Values}}{{if not .Primitive }}{{if .Slice }}
|
||||
// FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
|
||||
func (f genHelperEncoder) {{ .MethodNamePfx "Enc" false }}(v []{{ .Elem }}) { {{ else }}
|
||||
// FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
|
||||
func (f genHelperEncoder) {{ .MethodNamePfx "Enc" false }}(v map[{{ .MapKey }}]{{ .Elem }}) { {{end}}
|
||||
f.F.{{ .MethodNamePfx "Enc" false }}V(v, false, f.e)
|
||||
}
|
||||
{{ end }}{{ end }}
|
||||
|
||||
// -- decode calls (slices/maps)
|
||||
{{range .Values}}{{if not .Primitive }}
|
||||
// FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
|
||||
{{if .Slice }}func (f genHelperDecoder) {{ .MethodNamePfx "Dec" false }}(vp *[]{{ .Elem }}) {
|
||||
{{else}}func (f genHelperDecoder) {{ .MethodNamePfx "Dec" false }}(vp *map[{{ .MapKey }}]{{ .Elem }}) { {{end}}
|
||||
v, changed := f.F.{{ .MethodNamePfx "Dec" false }}V(*vp, false, true, f.d)
|
||||
if changed {
|
||||
*vp = v
|
||||
}
|
||||
}
|
||||
{{ end }}{{ end }}
|
||||
*/}}
|
259
vendor/github.com/ugorji/go/codec/helper_test.go
generated
vendored
259
vendor/github.com/ugorji/go/codec/helper_test.go
generated
vendored
|
@ -1,259 +0,0 @@
|
|||
// 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).
|
||||
//
|
||||
// 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 unsafe" -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"
|
||||
"errors"
|
||||
"flag"
|
||||
"fmt"
|
||||
"reflect"
|
||||
"sync"
|
||||
"testing"
|
||||
)
|
||||
|
||||
type testHED struct {
|
||||
H Handle
|
||||
E *Encoder
|
||||
D *Decoder
|
||||
}
|
||||
|
||||
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
|
||||
)
|
||||
|
||||
// variables used by tests
|
||||
var (
|
||||
testVerbose bool
|
||||
testInitDebug bool
|
||||
testUseIoEncDec bool
|
||||
testStructToArray bool
|
||||
testCanonical bool
|
||||
testUseReset bool
|
||||
testWriteNoSymbols bool
|
||||
testSkipIntf bool
|
||||
testInternStr bool
|
||||
testUseMust bool
|
||||
testCheckCircRef bool
|
||||
testJsonIndent int
|
||||
testMaxInitLen int
|
||||
)
|
||||
|
||||
func init() {
|
||||
testHEDs = make([]testHED, 0, 32)
|
||||
testHandles = append(testHandles,
|
||||
testNoopH, testMsgpackH, testBincH, testSimpleH,
|
||||
testCborH, testJsonH)
|
||||
}
|
||||
|
||||
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 testInitAll() {
|
||||
flag.Parse()
|
||||
for _, f := range testPreInitFns {
|
||||
f()
|
||||
}
|
||||
for _, f := range testPostInitFns {
|
||||
f()
|
||||
}
|
||||
}
|
||||
|
||||
func testCodecEncode(ts interface{}, bsIn []byte,
|
||||
fn func([]byte) *bytes.Buffer, h Handle) (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)
|
||||
}
|
||||
if testUseIoEncDec {
|
||||
buf = fn(bsIn)
|
||||
e.Reset(buf)
|
||||
} else {
|
||||
bs = bsIn
|
||||
e.ResetBytes(&bs)
|
||||
}
|
||||
if testUseMust {
|
||||
e.MustEncode(ts)
|
||||
} else {
|
||||
err = e.Encode(ts)
|
||||
}
|
||||
if testUseIoEncDec {
|
||||
bs = buf.Bytes()
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func testCodecDecode(bs []byte, ts interface{}, h Handle) (err error) {
|
||||
var d *Decoder
|
||||
var buf *bytes.Reader
|
||||
if testUseReset {
|
||||
d = testHEDGet(h).D
|
||||
} else {
|
||||
d = NewDecoder(nil, h)
|
||||
}
|
||||
if testUseIoEncDec {
|
||||
buf = bytes.NewReader(bs)
|
||||
d.Reset(buf)
|
||||
} else {
|
||||
d.ResetBytes(bs)
|
||||
}
|
||||
if testUseMust {
|
||||
d.MustDecode(ts)
|
||||
} else {
|
||||
err = d.Decode(ts)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// ----- functions below are used only by tests (not benchmarks)
|
||||
|
||||
const (
|
||||
testLogToT = true
|
||||
failNowOnFail = true
|
||||
)
|
||||
|
||||
func checkErrT(t *testing.T, err error) {
|
||||
if err != nil {
|
||||
logT(t, err.Error())
|
||||
failT(t)
|
||||
}
|
||||
}
|
||||
|
||||
func checkEqualT(t *testing.T, v1 interface{}, v2 interface{}, desc string) (err error) {
|
||||
if err = deepEqual(v1, v2); err != nil {
|
||||
logT(t, "Not Equal: %s: %v. v1: %v, v2: %v", desc, err, v1, v2)
|
||||
failT(t)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func failT(t *testing.T) {
|
||||
if failNowOnFail {
|
||||
t.FailNow()
|
||||
} else {
|
||||
t.Fail()
|
||||
}
|
||||
}
|
||||
|
||||
// --- 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 logT(x interface{}, format string, args ...interface{}) {
|
||||
if t, ok := x.(*testing.T); ok && t != nil && testLogToT {
|
||||
if testVerbose {
|
||||
t.Logf(format, args...)
|
||||
}
|
||||
} else if b, ok := x.(*testing.B); ok && b != nil && testLogToT {
|
||||
b.Logf(format, args...)
|
||||
} else {
|
||||
if len(format) == 0 || format[len(format)-1] != '\n' {
|
||||
format = format + "\n"
|
||||
}
|
||||
fmt.Printf(format, args...)
|
||||
}
|
||||
}
|
||||
|
||||
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
|
||||
}
|
199
vendor/github.com/ugorji/go/codec/prebuild.sh
generated
vendored
199
vendor/github.com/ugorji/go/codec/prebuild.sh
generated
vendored
|
@ -1,199 +0,0 @@
|
|||
#!/bin/bash
|
||||
|
||||
# _needgen is a helper function to tell if we need to generate files for msgp, codecgen.
|
||||
_needgen() {
|
||||
local a="$1"
|
||||
zneedgen=0
|
||||
if [[ ! -e "$a" ]]
|
||||
then
|
||||
zneedgen=1
|
||||
echo 1
|
||||
return 0
|
||||
fi
|
||||
for i in `ls -1 *.go.tmpl gen.go values_test.go`
|
||||
do
|
||||
if [[ "$a" -ot "$i" ]]
|
||||
then
|
||||
zneedgen=1
|
||||
echo 1
|
||||
return 0
|
||||
fi
|
||||
done
|
||||
echo 0
|
||||
}
|
||||
|
||||
# _build generates fast-path.go and gen-helper.go.
|
||||
#
|
||||
# It is needed because there is some dependency between the generated code
|
||||
# and the other classes. Consequently, we have to totally remove the
|
||||
# generated files and put stubs in place, before calling "go run" again
|
||||
# to recreate them.
|
||||
_build() {
|
||||
if ! [[ "${zforce}" == "1" ||
|
||||
"1" == $( _needgen "fast-path.generated.go" ) ||
|
||||
"1" == $( _needgen "gen-helper.generated.go" ) ||
|
||||
"1" == $( _needgen "gen.generated.go" ) ||
|
||||
1 == 0 ]]
|
||||
then
|
||||
return 0
|
||||
fi
|
||||
|
||||
# echo "Running prebuild"
|
||||
if [ "${zbak}" == "1" ]
|
||||
then
|
||||
# echo "Backing up old generated files"
|
||||
_zts=`date '+%m%d%Y_%H%M%S'`
|
||||
_gg=".generated.go"
|
||||
[ -e "gen-helper${_gg}" ] && mv gen-helper${_gg} gen-helper${_gg}__${_zts}.bak
|
||||
[ -e "fast-path${_gg}" ] && mv fast-path${_gg} fast-path${_gg}__${_zts}.bak
|
||||
# [ -e "safe${_gg}" ] && mv safe${_gg} safe${_gg}__${_zts}.bak
|
||||
# [ -e "unsafe${_gg}" ] && mv unsafe${_gg} unsafe${_gg}__${_zts}.bak
|
||||
else
|
||||
rm -f fast-path.generated.go gen.generated.go gen-helper.generated.go \
|
||||
*safe.generated.go *_generated_test.go *.generated_ffjson_expose.go
|
||||
fi
|
||||
|
||||
cat > gen.generated.go <<EOF
|
||||
// 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 = \`
|
||||
EOF
|
||||
|
||||
cat >> gen.generated.go < gen-dec-map.go.tmpl
|
||||
|
||||
cat >> gen.generated.go <<EOF
|
||||
\`
|
||||
|
||||
const genDecListTmpl = \`
|
||||
EOF
|
||||
|
||||
cat >> gen.generated.go < gen-dec-array.go.tmpl
|
||||
|
||||
cat >> gen.generated.go <<EOF
|
||||
\`
|
||||
|
||||
EOF
|
||||
|
||||
cat > gen-from-tmpl.codec.generated.go <<EOF
|
||||
package codec
|
||||
import "io"
|
||||
func GenInternalGoFile(r io.Reader, w io.Writer, safe bool) error {
|
||||
return genInternalGoFile(r, w, safe)
|
||||
}
|
||||
EOF
|
||||
|
||||
cat > gen-from-tmpl.generated.go <<EOF
|
||||
//+build ignore
|
||||
|
||||
package main
|
||||
|
||||
//import "flag"
|
||||
import "ugorji.net/codec"
|
||||
import "os"
|
||||
|
||||
func run(fnameIn, fnameOut string, safe bool) {
|
||||
fin, err := os.Open(fnameIn)
|
||||
if err != nil { panic(err) }
|
||||
defer fin.Close()
|
||||
fout, err := os.Create(fnameOut)
|
||||
if err != nil { panic(err) }
|
||||
defer fout.Close()
|
||||
err = codec.GenInternalGoFile(fin, fout, safe)
|
||||
if err != nil { panic(err) }
|
||||
}
|
||||
|
||||
func main() {
|
||||
// do not make safe/unsafe variants.
|
||||
// Instead, depend on escape analysis, and place string creation and usage appropriately.
|
||||
// run("unsafe.go.tmpl", "safe.generated.go", true)
|
||||
// run("unsafe.go.tmpl", "unsafe.generated.go", false)
|
||||
run("fast-path.go.tmpl", "fast-path.generated.go", false)
|
||||
run("gen-helper.go.tmpl", "gen-helper.generated.go", false)
|
||||
}
|
||||
|
||||
EOF
|
||||
go run -tags=notfastpath gen-from-tmpl.generated.go && \
|
||||
rm -f gen-from-tmpl.*generated.go
|
||||
}
|
||||
|
||||
_codegenerators() {
|
||||
if [[ $zforce == "1" ||
|
||||
"1" == $( _needgen "values_codecgen${zsfx}" ) ||
|
||||
"1" == $( _needgen "values_msgp${zsfx}" ) ||
|
||||
"1" == $( _needgen "values_ffjson${zsfx}" ) ||
|
||||
1 == 0 ]]
|
||||
then
|
||||
# codecgen creates some temporary files in the directory (main, pkg).
|
||||
# Consequently, we should start msgp and ffjson first, and also put a small time latency before
|
||||
# starting codecgen.
|
||||
# Without this, ffjson chokes on one of the temporary files from codecgen.
|
||||
if [[ $zexternal == "1" ]]
|
||||
then
|
||||
echo "ffjson ... " && \
|
||||
ffjson -w values_ffjson${zsfx} $zfin &
|
||||
zzzIdFF=$!
|
||||
echo "msgp ... " && \
|
||||
msgp -tests=false -o=values_msgp${zsfx} -file=$zfin &
|
||||
zzzIdMsgp=$!
|
||||
|
||||
sleep 1 # give ffjson and msgp some buffer time. see note above.
|
||||
fi
|
||||
|
||||
echo "codecgen - !unsafe ... " && \
|
||||
codecgen -rt codecgen -t 'x,codecgen,!unsafe' -o values_codecgen${zsfx} -d 19780 $zfin &
|
||||
zzzIdC=$!
|
||||
echo "codecgen - unsafe ... " && \
|
||||
codecgen -u -rt codecgen -t 'x,codecgen,unsafe' -o values_codecgen_unsafe${zsfx} -d 19781 $zfin &
|
||||
zzzIdCU=$!
|
||||
wait $zzzIdC $zzzIdCU $zzzIdMsgp $zzzIdFF && \
|
||||
# remove (M|Unm)arshalJSON implementations, so they don't conflict with encoding/json bench \
|
||||
if [[ $zexternal == "1" ]]
|
||||
then
|
||||
sed -i 's+ MarshalJSON(+ _MarshalJSON(+g' values_ffjson${zsfx} && \
|
||||
sed -i 's+ UnmarshalJSON(+ _UnmarshalJSON(+g' values_ffjson${zsfx}
|
||||
fi && \
|
||||
echo "generators done!" && \
|
||||
true
|
||||
fi
|
||||
}
|
||||
|
||||
# _init reads the arguments and sets up the flags
|
||||
_init() {
|
||||
OPTIND=1
|
||||
while getopts "fbx" flag
|
||||
do
|
||||
case "x$flag" in
|
||||
'xf') zforce=1;;
|
||||
'xb') zbak=1;;
|
||||
'xx') zexternal=1;;
|
||||
*) echo "prebuild.sh accepts [-fbx] only"; return 1;;
|
||||
esac
|
||||
done
|
||||
shift $((OPTIND-1))
|
||||
OPTIND=1
|
||||
}
|
||||
|
||||
# main script.
|
||||
# First ensure that this is being run from the basedir (i.e. dirname of script is .)
|
||||
if [ "." = `dirname $0` ]
|
||||
then
|
||||
zmydir=`pwd`
|
||||
zfin="test_values.generated.go"
|
||||
zsfx="_generated_test.go"
|
||||
# rm -f *_generated_test.go
|
||||
rm -f codecgen-*.go && \
|
||||
_init "$@" && \
|
||||
_build && \
|
||||
cp $zmydir/values_test.go $zmydir/$zfin && \
|
||||
_codegenerators && \
|
||||
echo prebuild done successfully
|
||||
rm -f $zmydir/$zfin
|
||||
else
|
||||
echo "Script must be run from the directory it resides in"
|
||||
fi
|
||||
|
30
vendor/github.com/ugorji/go/codec/py_test.go
generated
vendored
30
vendor/github.com/ugorji/go/codec/py_test.go
generated
vendored
|
@ -1,30 +0,0 @@
|
|||
// +build x
|
||||
|
||||
// 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
|
||||
|
||||
// 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)
|
||||
}
|
639
vendor/github.com/ugorji/go/codec/test-cbor-goldens.json
generated
vendored
639
vendor/github.com/ugorji/go/codec/test-cbor-goldens.json
generated
vendored
|
@ -1,639 +0,0 @@
|
|||
[
|
||||
{
|
||||
"cbor": "AA==",
|
||||
"hex": "00",
|
||||
"roundtrip": true,
|
||||
"decoded": 0
|
||||
},
|
||||
{
|
||||
"cbor": "AQ==",
|
||||
"hex": "01",
|
||||
"roundtrip": true,
|
||||
"decoded": 1
|
||||
},
|
||||
{
|
||||
"cbor": "Cg==",
|
||||
"hex": "0a",
|
||||
"roundtrip": true,
|
||||
"decoded": 10
|
||||
},
|
||||
{
|
||||
"cbor": "Fw==",
|
||||
"hex": "17",
|
||||
"roundtrip": true,
|
||||
"decoded": 23
|
||||
},
|
||||
{
|
||||
"cbor": "GBg=",
|
||||
"hex": "1818",
|
||||
"roundtrip": true,
|
||||
"decoded": 24
|
||||
},
|
||||
{
|
||||
"cbor": "GBk=",
|
||||
"hex": "1819",
|
||||
"roundtrip": true,
|
||||
"decoded": 25
|
||||
},
|
||||
{
|
||||
"cbor": "GGQ=",
|
||||
"hex": "1864",
|
||||
"roundtrip": true,
|
||||
"decoded": 100
|
||||
},
|
||||
{
|
||||
"cbor": "GQPo",
|
||||
"hex": "1903e8",
|
||||
"roundtrip": true,
|
||||
"decoded": 1000
|
||||
},
|
||||
{
|
||||
"cbor": "GgAPQkA=",
|
||||
"hex": "1a000f4240",
|
||||
"roundtrip": true,
|
||||
"decoded": 1000000
|
||||
},
|
||||
{
|
||||
"cbor": "GwAAAOjUpRAA",
|
||||
"hex": "1b000000e8d4a51000",
|
||||
"roundtrip": true,
|
||||
"decoded": 1000000000000
|
||||
},
|
||||
{
|
||||
"cbor": "G///////////",
|
||||
"hex": "1bffffffffffffffff",
|
||||
"roundtrip": true,
|
||||
"decoded": 18446744073709551615
|
||||
},
|
||||
{
|
||||
"cbor": "wkkBAAAAAAAAAAA=",
|
||||
"hex": "c249010000000000000000",
|
||||
"roundtrip": true,
|
||||
"decoded": 18446744073709551616
|
||||
},
|
||||
{
|
||||
"cbor": "O///////////",
|
||||
"hex": "3bffffffffffffffff",
|
||||
"roundtrip": true,
|
||||
"decoded": -18446744073709551616,
|
||||
"skip": true
|
||||
},
|
||||
{
|
||||
"cbor": "w0kBAAAAAAAAAAA=",
|
||||
"hex": "c349010000000000000000",
|
||||
"roundtrip": true,
|
||||
"decoded": -18446744073709551617
|
||||
},
|
||||
{
|
||||
"cbor": "IA==",
|
||||
"hex": "20",
|
||||
"roundtrip": true,
|
||||
"decoded": -1
|
||||
},
|
||||
{
|
||||
"cbor": "KQ==",
|
||||
"hex": "29",
|
||||
"roundtrip": true,
|
||||
"decoded": -10
|
||||
},
|
||||
{
|
||||
"cbor": "OGM=",
|
||||
"hex": "3863",
|
||||
"roundtrip": true,
|
||||
"decoded": -100
|
||||
},
|
||||
{
|
||||
"cbor": "OQPn",
|
||||
"hex": "3903e7",
|
||||
"roundtrip": true,
|
||||
"decoded": -1000
|
||||
},
|
||||
{
|
||||
"cbor": "+QAA",
|
||||
"hex": "f90000",
|
||||
"roundtrip": true,
|
||||
"decoded": 0.0
|
||||
},
|
||||
{
|
||||
"cbor": "+YAA",
|
||||
"hex": "f98000",
|
||||
"roundtrip": true,
|
||||
"decoded": -0.0
|
||||
},
|
||||
{
|
||||
"cbor": "+TwA",
|
||||
"hex": "f93c00",
|
||||
"roundtrip": true,
|
||||
"decoded": 1.0
|
||||
},
|
||||
{
|
||||
"cbor": "+z/xmZmZmZma",
|
||||
"hex": "fb3ff199999999999a",
|
||||
"roundtrip": true,
|
||||
"decoded": 1.1
|
||||
},
|
||||
{
|
||||
"cbor": "+T4A",
|
||||
"hex": "f93e00",
|
||||
"roundtrip": true,
|
||||
"decoded": 1.5
|
||||
},
|
||||
{
|
||||
"cbor": "+Xv/",
|
||||
"hex": "f97bff",
|
||||
"roundtrip": true,
|
||||
"decoded": 65504.0
|
||||
},
|
||||
{
|
||||
"cbor": "+kfDUAA=",
|
||||
"hex": "fa47c35000",
|
||||
"roundtrip": true,
|
||||
"decoded": 100000.0
|
||||
},
|
||||
{
|
||||
"cbor": "+n9///8=",
|
||||
"hex": "fa7f7fffff",
|
||||
"roundtrip": true,
|
||||
"decoded": 3.4028234663852886e+38
|
||||
},
|
||||
{
|
||||
"cbor": "+3435DyIAHWc",
|
||||
"hex": "fb7e37e43c8800759c",
|
||||
"roundtrip": true,
|
||||
"decoded": 1.0e+300
|
||||
},
|
||||
{
|
||||
"cbor": "+QAB",
|
||||
"hex": "f90001",
|
||||
"roundtrip": true,
|
||||
"decoded": 5.960464477539063e-08
|
||||
},
|
||||
{
|
||||
"cbor": "+QQA",
|
||||
"hex": "f90400",
|
||||
"roundtrip": true,
|
||||
"decoded": 6.103515625e-05
|
||||
},
|
||||
{
|
||||
"cbor": "+cQA",
|
||||
"hex": "f9c400",
|
||||
"roundtrip": true,
|
||||
"decoded": -4.0
|
||||
},
|
||||
{
|
||||
"cbor": "+8AQZmZmZmZm",
|
||||
"hex": "fbc010666666666666",
|
||||
"roundtrip": true,
|
||||
"decoded": -4.1
|
||||
},
|
||||
{
|
||||
"cbor": "+XwA",
|
||||
"hex": "f97c00",
|
||||
"roundtrip": true,
|
||||
"diagnostic": "Infinity"
|
||||
},
|
||||
{
|
||||
"cbor": "+X4A",
|
||||
"hex": "f97e00",
|
||||
"roundtrip": true,
|
||||
"diagnostic": "NaN"
|
||||
},
|
||||
{
|
||||
"cbor": "+fwA",
|
||||
"hex": "f9fc00",
|
||||
"roundtrip": true,
|
||||
"diagnostic": "-Infinity"
|
||||
},
|
||||
{
|
||||
"cbor": "+n+AAAA=",
|
||||
"hex": "fa7f800000",
|
||||
"roundtrip": false,
|
||||
"diagnostic": "Infinity"
|
||||
},
|
||||
{
|
||||
"cbor": "+n/AAAA=",
|
||||
"hex": "fa7fc00000",
|
||||
"roundtrip": false,
|
||||
"diagnostic": "NaN"
|
||||
},
|
||||
{
|
||||
"cbor": "+v+AAAA=",
|
||||
"hex": "faff800000",
|
||||
"roundtrip": false,
|
||||
"diagnostic": "-Infinity"
|
||||
},
|
||||
{
|
||||
"cbor": "+3/wAAAAAAAA",
|
||||
"hex": "fb7ff0000000000000",
|
||||
"roundtrip": false,
|
||||
"diagnostic": "Infinity"
|
||||
},
|
||||
{
|
||||
"cbor": "+3/4AAAAAAAA",
|
||||
"hex": "fb7ff8000000000000",
|
||||
"roundtrip": false,
|
||||
"diagnostic": "NaN"
|
||||
},
|
||||
{
|
||||
"cbor": "+//wAAAAAAAA",
|
||||
"hex": "fbfff0000000000000",
|
||||
"roundtrip": false,
|
||||
"diagnostic": "-Infinity"
|
||||
},
|
||||
{
|
||||
"cbor": "9A==",
|
||||
"hex": "f4",
|
||||
"roundtrip": true,
|
||||
"decoded": false
|
||||
},
|
||||
{
|
||||
"cbor": "9Q==",
|
||||
"hex": "f5",
|
||||
"roundtrip": true,
|
||||
"decoded": true
|
||||
},
|
||||
{
|
||||
"cbor": "9g==",
|
||||
"hex": "f6",
|
||||
"roundtrip": true,
|
||||
"decoded": null
|
||||
},
|
||||
{
|
||||
"cbor": "9w==",
|
||||
"hex": "f7",
|
||||
"roundtrip": true,
|
||||
"diagnostic": "undefined"
|
||||
},
|
||||
{
|
||||
"cbor": "8A==",
|
||||
"hex": "f0",
|
||||
"roundtrip": true,
|
||||
"diagnostic": "simple(16)"
|
||||
},
|
||||
{
|
||||
"cbor": "+Bg=",
|
||||
"hex": "f818",
|
||||
"roundtrip": true,
|
||||
"diagnostic": "simple(24)"
|
||||
},
|
||||
{
|
||||
"cbor": "+P8=",
|
||||
"hex": "f8ff",
|
||||
"roundtrip": true,
|
||||
"diagnostic": "simple(255)"
|
||||
},
|
||||
{
|
||||
"cbor": "wHQyMDEzLTAzLTIxVDIwOjA0OjAwWg==",
|
||||
"hex": "c074323031332d30332d32315432303a30343a30305a",
|
||||
"roundtrip": true,
|
||||
"diagnostic": "0(\"2013-03-21T20:04:00Z\")"
|
||||
},
|
||||
{
|
||||
"cbor": "wRpRS2ew",
|
||||
"hex": "c11a514b67b0",
|
||||
"roundtrip": true,
|
||||
"diagnostic": "1(1363896240)"
|
||||
},
|
||||
{
|
||||
"cbor": "wftB1FLZ7CAAAA==",
|
||||
"hex": "c1fb41d452d9ec200000",
|
||||
"roundtrip": true,
|
||||
"diagnostic": "1(1363896240.5)"
|
||||
},
|
||||
{
|
||||
"cbor": "10QBAgME",
|
||||
"hex": "d74401020304",
|
||||
"roundtrip": true,
|
||||
"diagnostic": "23(h'01020304')"
|
||||
},
|
||||
{
|
||||
"cbor": "2BhFZElFVEY=",
|
||||
"hex": "d818456449455446",
|
||||
"roundtrip": true,
|
||||
"diagnostic": "24(h'6449455446')"
|
||||
},
|
||||
{
|
||||
"cbor": "2CB2aHR0cDovL3d3dy5leGFtcGxlLmNvbQ==",
|
||||
"hex": "d82076687474703a2f2f7777772e6578616d706c652e636f6d",
|
||||
"roundtrip": true,
|
||||
"diagnostic": "32(\"http://www.example.com\")"
|
||||
},
|
||||
{
|
||||
"cbor": "QA==",
|
||||
"hex": "40",
|
||||
"roundtrip": true,
|
||||
"diagnostic": "h''"
|
||||
},
|
||||
{
|
||||
"cbor": "RAECAwQ=",
|
||||
"hex": "4401020304",
|
||||
"roundtrip": true,
|
||||
"diagnostic": "h'01020304'"
|
||||
},
|
||||
{
|
||||
"cbor": "YA==",
|
||||
"hex": "60",
|
||||
"roundtrip": true,
|
||||
"decoded": ""
|
||||
},
|
||||
{
|
||||
"cbor": "YWE=",
|
||||
"hex": "6161",
|
||||
"roundtrip": true,
|
||||
"decoded": "a"
|
||||
},
|
||||
{
|
||||
"cbor": "ZElFVEY=",
|
||||
"hex": "6449455446",
|
||||
"roundtrip": true,
|
||||
"decoded": "IETF"
|
||||
},
|
||||
{
|
||||
"cbor": "YiJc",
|
||||
"hex": "62225c",
|
||||
"roundtrip": true,
|
||||
"decoded": "\"\\"
|
||||
},
|
||||
{
|
||||
"cbor": "YsO8",
|
||||
"hex": "62c3bc",
|
||||
"roundtrip": true,
|
||||
"decoded": "ü"
|
||||
},
|
||||
{
|
||||
"cbor": "Y+awtA==",
|
||||
"hex": "63e6b0b4",
|
||||
"roundtrip": true,
|
||||
"decoded": "水"
|
||||
},
|
||||
{
|
||||
"cbor": "ZPCQhZE=",
|
||||
"hex": "64f0908591",
|
||||
"roundtrip": true,
|
||||
"decoded": "𐅑"
|
||||
},
|
||||
{
|
||||
"cbor": "gA==",
|
||||
"hex": "80",
|
||||
"roundtrip": true,
|
||||
"decoded": [
|
||||
|
||||
]
|
||||
},
|
||||
{
|
||||
"cbor": "gwECAw==",
|
||||
"hex": "83010203",
|
||||
"roundtrip": true,
|
||||
"decoded": [
|
||||
1,
|
||||
2,
|
||||
3
|
||||
]
|
||||
},
|
||||
{
|
||||
"cbor": "gwGCAgOCBAU=",
|
||||
"hex": "8301820203820405",
|
||||
"roundtrip": true,
|
||||
"decoded": [
|
||||
1,
|
||||
[
|
||||
2,
|
||||
3
|
||||
],
|
||||
[
|
||||
4,
|
||||
5
|
||||
]
|
||||
]
|
||||
},
|
||||
{
|
||||
"cbor": "mBkBAgMEBQYHCAkKCwwNDg8QERITFBUWFxgYGBk=",
|
||||
"hex": "98190102030405060708090a0b0c0d0e0f101112131415161718181819",
|
||||
"roundtrip": true,
|
||||
"decoded": [
|
||||
1,
|
||||
2,
|
||||
3,
|
||||
4,
|
||||
5,
|
||||
6,
|
||||
7,
|
||||
8,
|
||||
9,
|
||||
10,
|
||||
11,
|
||||
12,
|
||||
13,
|
||||
14,
|
||||
15,
|
||||
16,
|
||||
17,
|
||||
18,
|
||||
19,
|
||||
20,
|
||||
21,
|
||||
22,
|
||||
23,
|
||||
24,
|
||||
25
|
||||
]
|
||||
},
|
||||
{
|
||||
"cbor": "oA==",
|
||||
"hex": "a0",
|
||||
"roundtrip": true,
|
||||
"decoded": {
|
||||
}
|
||||
},
|
||||
{
|
||||
"cbor": "ogECAwQ=",
|
||||
"hex": "a201020304",
|
||||
"roundtrip": true,
|
||||
"skip": true,
|
||||
"diagnostic": "{1: 2, 3: 4}"
|
||||
},
|
||||
{
|
||||
"cbor": "omFhAWFiggID",
|
||||
"hex": "a26161016162820203",
|
||||
"roundtrip": true,
|
||||
"decoded": {
|
||||
"a": 1,
|
||||
"b": [
|
||||
2,
|
||||
3
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"cbor": "gmFhoWFiYWM=",
|
||||
"hex": "826161a161626163",
|
||||
"roundtrip": true,
|
||||
"decoded": [
|
||||
"a",
|
||||
{
|
||||
"b": "c"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"cbor": "pWFhYUFhYmFCYWNhQ2FkYURhZWFF",
|
||||
"hex": "a56161614161626142616361436164614461656145",
|
||||
"roundtrip": true,
|
||||
"decoded": {
|
||||
"a": "A",
|
||||
"b": "B",
|
||||
"c": "C",
|
||||
"d": "D",
|
||||
"e": "E"
|
||||
}
|
||||
},
|
||||
{
|
||||
"cbor": "X0IBAkMDBAX/",
|
||||
"hex": "5f42010243030405ff",
|
||||
"roundtrip": false,
|
||||
"skip": true,
|
||||
"diagnostic": "(_ h'0102', h'030405')"
|
||||
},
|
||||
{
|
||||
"cbor": "f2VzdHJlYWRtaW5n/w==",
|
||||
"hex": "7f657374726561646d696e67ff",
|
||||
"roundtrip": false,
|
||||
"decoded": "streaming"
|
||||
},
|
||||
{
|
||||
"cbor": "n/8=",
|
||||
"hex": "9fff",
|
||||
"roundtrip": false,
|
||||
"decoded": [
|
||||
|
||||
]
|
||||
},
|
||||
{
|
||||
"cbor": "nwGCAgOfBAX//w==",
|
||||
"hex": "9f018202039f0405ffff",
|
||||
"roundtrip": false,
|
||||
"decoded": [
|
||||
1,
|
||||
[
|
||||
2,
|
||||
3
|
||||
],
|
||||
[
|
||||
4,
|
||||
5
|
||||
]
|
||||
]
|
||||
},
|
||||
{
|
||||
"cbor": "nwGCAgOCBAX/",
|
||||
"hex": "9f01820203820405ff",
|
||||
"roundtrip": false,
|
||||
"decoded": [
|
||||
1,
|
||||
[
|
||||
2,
|
||||
3
|
||||
],
|
||||
[
|
||||
4,
|
||||
5
|
||||
]
|
||||
]
|
||||
},
|
||||
{
|
||||
"cbor": "gwGCAgOfBAX/",
|
||||
"hex": "83018202039f0405ff",
|
||||
"roundtrip": false,
|
||||
"decoded": [
|
||||
1,
|
||||
[
|
||||
2,
|
||||
3
|
||||
],
|
||||
[
|
||||
4,
|
||||
5
|
||||
]
|
||||
]
|
||||
},
|
||||
{
|
||||
"cbor": "gwGfAgP/ggQF",
|
||||
"hex": "83019f0203ff820405",
|
||||
"roundtrip": false,
|
||||
"decoded": [
|
||||
1,
|
||||
[
|
||||
2,
|
||||
3
|
||||
],
|
||||
[
|
||||
4,
|
||||
5
|
||||
]
|
||||
]
|
||||
},
|
||||
{
|
||||
"cbor": "nwECAwQFBgcICQoLDA0ODxAREhMUFRYXGBgYGf8=",
|
||||
"hex": "9f0102030405060708090a0b0c0d0e0f101112131415161718181819ff",
|
||||
"roundtrip": false,
|
||||
"decoded": [
|
||||
1,
|
||||
2,
|
||||
3,
|
||||
4,
|
||||
5,
|
||||
6,
|
||||
7,
|
||||
8,
|
||||
9,
|
||||
10,
|
||||
11,
|
||||
12,
|
||||
13,
|
||||
14,
|
||||
15,
|
||||
16,
|
||||
17,
|
||||
18,
|
||||
19,
|
||||
20,
|
||||
21,
|
||||
22,
|
||||
23,
|
||||
24,
|
||||
25
|
||||
]
|
||||
},
|
||||
{
|
||||
"cbor": "v2FhAWFinwID//8=",
|
||||
"hex": "bf61610161629f0203ffff",
|
||||
"roundtrip": false,
|
||||
"decoded": {
|
||||
"a": 1,
|
||||
"b": [
|
||||
2,
|
||||
3
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"cbor": "gmFhv2FiYWP/",
|
||||
"hex": "826161bf61626163ff",
|
||||
"roundtrip": false,
|
||||
"decoded": [
|
||||
"a",
|
||||
{
|
||||
"b": "c"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"cbor": "v2NGdW71Y0FtdCH/",
|
||||
"hex": "bf6346756ef563416d7421ff",
|
||||
"roundtrip": false,
|
||||
"decoded": {
|
||||
"Fun": true,
|
||||
"Amt": -2
|
||||
}
|
||||
}
|
||||
]
|
126
vendor/github.com/ugorji/go/codec/test.py
generated
vendored
126
vendor/github.com/ugorji/go/codec/test.py
generated
vendored
|
@ -1,126 +0,0 @@
|
|||
#!/usr/bin/env python
|
||||
|
||||
# This will create golden files in a directory passed to it.
|
||||
# A Test calls this internally to create the golden files
|
||||
# So it can process them (so we don't have to checkin the files).
|
||||
|
||||
# Ensure msgpack-python and cbor are installed first, using:
|
||||
# sudo apt-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"someday",
|
||||
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('localhost', 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('localhost', 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('localhost', 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:])
|
||||
|
107
vendor/github.com/ugorji/go/codec/tests.sh
generated
vendored
107
vendor/github.com/ugorji/go/codec/tests.sh
generated
vendored
|
@ -1,107 +0,0 @@
|
|||
#!/bin/bash
|
||||
|
||||
# Run all the different permutations of all the tests.
|
||||
# This helps ensure that nothing gets broken.
|
||||
|
||||
_run() {
|
||||
# 1. VARIATIONS: regular (t), canonical (c), IO R/W (i),
|
||||
# binc-nosymbols (n), struct2array (s), intern string (e),
|
||||
# json-indent (d), circular (l)
|
||||
# 2. MODE: reflection (r), external (x), codecgen (g), unsafe (u), notfastpath (f)
|
||||
# 3. OPTIONS: verbose (v), reset (z), must (m),
|
||||
#
|
||||
# Use combinations of mode to get exactly what you want,
|
||||
# and then pass the variations you need.
|
||||
|
||||
ztags=""
|
||||
zargs=""
|
||||
local OPTIND
|
||||
OPTIND=1
|
||||
# "_xurtcinsvgzmefdl" === "_cdefgilmnrtsuvxz"
|
||||
while getopts "_cdefgilmnrtsuvwxz" flag
|
||||
do
|
||||
case "x$flag" in
|
||||
'xr') ;;
|
||||
'xf') ztags="$ztags notfastpath" ;;
|
||||
'xg') ztags="$ztags codecgen" ;;
|
||||
'xx') ztags="$ztags x" ;;
|
||||
'xu') ztags="$ztags unsafe" ;;
|
||||
'xv') zargs="$zargs -tv" ;;
|
||||
'xz') zargs="$zargs -tr" ;;
|
||||
'xm') zargs="$zargs -tm" ;;
|
||||
'xl') zargs="$zargs -tl" ;;
|
||||
'xw') zargs="$zargs -tx=10" ;;
|
||||
*) ;;
|
||||
esac
|
||||
done
|
||||
# shift $((OPTIND-1))
|
||||
printf '............. TAGS: %s .............\n' "$ztags"
|
||||
# echo ">>>>>>> TAGS: $ztags"
|
||||
|
||||
OPTIND=1
|
||||
while getopts "_cdefgilmnrtsuvwxz" flag
|
||||
do
|
||||
case "x$flag" in
|
||||
'xt') printf ">>>>>>> REGULAR : "; go test "-tags=$ztags" $zargs ; sleep 2 ;;
|
||||
'xc') printf ">>>>>>> CANONICAL : "; go test "-tags=$ztags" $zargs -tc; sleep 2 ;;
|
||||
'xi') printf ">>>>>>> I/O : "; go test "-tags=$ztags" $zargs -ti; sleep 2 ;;
|
||||
'xn') printf ">>>>>>> NO_SYMBOLS : "; go test "-tags=$ztags" -run=Binc $zargs -tn; sleep 2 ;;
|
||||
'xs') printf ">>>>>>> TO_ARRAY : "; go test "-tags=$ztags" $zargs -ts; sleep 2 ;;
|
||||
'xe') printf ">>>>>>> INTERN : "; go test "-tags=$ztags" $zargs -te; sleep 2 ;;
|
||||
'xd') printf ">>>>>>> INDENT : ";
|
||||
go test "-tags=$ztags" -run=JsonCodecsTable -td=-1 $zargs;
|
||||
go test "-tags=$ztags" -run=JsonCodecsTable -td=8 $zargs;
|
||||
sleep 2 ;;
|
||||
*) ;;
|
||||
esac
|
||||
done
|
||||
shift $((OPTIND-1))
|
||||
|
||||
OPTIND=1
|
||||
}
|
||||
|
||||
# echo ">>>>>>> RUNNING VARIATIONS OF TESTS"
|
||||
if [[ "x$@" = "x" || "x$@" = "x-A" ]]; then
|
||||
# All: r, x, g, gu
|
||||
_run "-_tcinsed_ml" # regular
|
||||
_run "-_tcinsed_ml_z" # regular with reset
|
||||
_run "-w_tcinsed_ml" # regular with max init len
|
||||
_run "-_tcinsed_ml_f" # regular with no fastpath (notfastpath)
|
||||
_run "-x_tcinsed_ml" # external
|
||||
_run "-gx_tcinsed_ml" # codecgen: requires external
|
||||
_run "-gxu_tcinsed_ml" # codecgen + unsafe
|
||||
elif [[ "x$@" = "x-Z" ]]; then
|
||||
# Regular
|
||||
_run "-_tcinsed_ml" # regular
|
||||
_run "-_tcinsed_ml_z" # regular with reset
|
||||
elif [[ "x$@" = "x-F" ]]; then
|
||||
# regular with notfastpath
|
||||
_run "-_tcinsed_ml_f" # regular
|
||||
_run "-_tcinsed_ml_zf" # regular with reset
|
||||
elif [[ "x$@" = "x-C" ]]; then
|
||||
# codecgen
|
||||
_run "-gx_tcinsed_ml" # codecgen: requires external
|
||||
_run "-gxu_tcinsed_ml" # codecgen + unsafe
|
||||
_run "-gxuw_tcinsed_ml" # codecgen + unsafe + maxinitlen
|
||||
elif [[ "x$@" = "x-X" ]]; then
|
||||
# external
|
||||
_run "-x_tcinsed_ml" # external
|
||||
elif [[ "x$@" = "x-h" || "x$@" = "x-?" ]]; then
|
||||
cat <<EOF
|
||||
Usage: tests.sh [options...]
|
||||
-A run through all tests (regular, external, codecgen)
|
||||
-Z regular tests only
|
||||
-F regular tests only (without fastpath, so they run quickly)
|
||||
-C codecgen only
|
||||
-X external only
|
||||
-h show help (usage)
|
||||
-? same as -h
|
||||
(no options)
|
||||
same as -A
|
||||
(unrecognized options)
|
||||
just pass on the options from the command line
|
||||
EOF
|
||||
else
|
||||
# e.g. ./tests.sh "-w_tcinsed_ml"
|
||||
_run "$@"
|
||||
fi
|
203
vendor/github.com/ugorji/go/codec/values_test.go
generated
vendored
203
vendor/github.com/ugorji/go/codec/values_test.go
generated
vendored
|
@ -1,203 +0,0 @@
|
|||
/* // +build testing */
|
||||
|
||||
// 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
|
||||
|
||||
// This file contains values used by tests and benchmarks.
|
||||
// JSON/BSON do not like maps with keys that are not strings,
|
||||
// so we only use maps with string keys here.
|
||||
|
||||
import (
|
||||
"math"
|
||||
"time"
|
||||
)
|
||||
|
||||
var testStrucTime = time.Date(2012, 2, 2, 2, 2, 2, 2000, time.UTC).UTC()
|
||||
|
||||
type AnonInTestStruc struct {
|
||||
AS string
|
||||
AI64 int64
|
||||
AI16 int16
|
||||
AUi64 uint64
|
||||
ASslice []string
|
||||
AI64slice []int64
|
||||
AF64slice []float64
|
||||
// AMI32U32 map[int32]uint32
|
||||
// AMU32F64 map[uint32]float64 // json/bson do not like it
|
||||
AMSU16 map[string]uint16
|
||||
}
|
||||
|
||||
type AnonInTestStrucIntf struct {
|
||||
Islice []interface{}
|
||||
Ms map[string]interface{}
|
||||
Nintf interface{} //don't set this, so we can test for nil
|
||||
T time.Time
|
||||
}
|
||||
|
||||
type TestStruc struct {
|
||||
_struct struct{} `codec:",omitempty"` //set omitempty for every field
|
||||
|
||||
S string
|
||||
I64 int64
|
||||
I16 int16
|
||||
Ui64 uint64
|
||||
Ui8 uint8
|
||||
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
|
||||
|
||||
// TODO: test these separately, specifically for reflection and codecgen.
|
||||
// Unfortunately, ffjson doesn't support these. Its compilation even fails.
|
||||
// Ui64array [4]uint64
|
||||
// Ui64slicearray [][4]uint64
|
||||
|
||||
AnonInTestStruc
|
||||
|
||||
//M map[interface{}]interface{} `json:"-",bson:"-"`
|
||||
Msi64 map[string]int64
|
||||
|
||||
// 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 included if nil).
|
||||
*AnonInTestStrucIntf `codec:",omitempty"`
|
||||
|
||||
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
|
||||
Mtsptr map[string]*TestStruc
|
||||
Mts map[string]TestStruc
|
||||
Its []*TestStruc
|
||||
Nteststruc *TestStruc
|
||||
}
|
||||
|
||||
// small struct for testing that codecgen works for unexported types
|
||||
type tLowerFirstLetter struct {
|
||||
I int
|
||||
u uint64
|
||||
S string
|
||||
b []byte
|
||||
}
|
||||
|
||||
func newTestStruc(depth int, bench bool, useInterface, useStringKeyOnly bool) (ts *TestStruc) {
|
||||
var i64a, i64b, i64c, i64d int64 = 64, 6464, 646464, 64646464
|
||||
|
||||
ts = &TestStruc{
|
||||
S: "some string",
|
||||
I64: math.MaxInt64 * 2 / 3, // 64,
|
||||
I16: 1616,
|
||||
Ui64: uint64(int64(math.MaxInt64 * 2 / 3)), // 64, //don't use MaxUint64, as bson can't write it
|
||||
Ui8: 160,
|
||||
B: true,
|
||||
By: 5,
|
||||
|
||||
Sslice: []string{"one", "two", "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{
|
||||
"one": 1,
|
||||
"two": 2,
|
||||
},
|
||||
AnonInTestStruc: AnonInTestStruc{
|
||||
// There's more leeway in altering this.
|
||||
AS: "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{"Aone", "Atwo", "Athree",
|
||||
"Afour.reverse_solidus.\u005c", "Afive.Gclef.\U0001d11E"},
|
||||
AI64slice: []int64{1, -22, 333, -4444, 55555, -666666},
|
||||
AMSU16: map[string]uint16{"1": 1, "22": 2, "333": 3, "4444": 4},
|
||||
AF64slice: []float64{11.11e-11, 22.22E+22, 33.33E-33, 44.44e+44, 555.55E-6, 666.66E6},
|
||||
},
|
||||
}
|
||||
if useInterface {
|
||||
ts.AnonInTestStrucIntf = &AnonInTestStrucIntf{
|
||||
Islice: []interface{}{"true", true, "no", false, uint64(288), float64(0.4)},
|
||||
Ms: map[string]interface{}{
|
||||
"true": "true",
|
||||
"int64(9)": false,
|
||||
},
|
||||
T: testStrucTime,
|
||||
}
|
||||
}
|
||||
|
||||
//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
|
||||
}
|
||||
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["0"] = newTestStruc(depth, bench, useInterface, useStringKeyOnly)
|
||||
ts.Mts["0"] = *(ts.Mtsptr["0"])
|
||||
ts.Its = append(ts.Its, ts.Mtsptr["0"])
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// Some other types
|
||||
|
||||
type Sstring string
|
||||
type Bbool bool
|
||||
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()
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue