diff options
Diffstat (limited to 'vendor/github.com/json-iterator/go')
53 files changed, 0 insertions, 9323 deletions
diff --git a/vendor/github.com/json-iterator/go/.codecov.yml b/vendor/github.com/json-iterator/go/.codecov.yml deleted file mode 100644 index 955dc0b..0000000 --- a/vendor/github.com/json-iterator/go/.codecov.yml +++ /dev/null | |||
@@ -1,3 +0,0 @@ | |||
1 | ignore: | ||
2 | - "output_tests/.*" | ||
3 | |||
diff --git a/vendor/github.com/json-iterator/go/.gitignore b/vendor/github.com/json-iterator/go/.gitignore deleted file mode 100644 index 1555653..0000000 --- a/vendor/github.com/json-iterator/go/.gitignore +++ /dev/null | |||
@@ -1,4 +0,0 @@ | |||
1 | /vendor | ||
2 | /bug_test.go | ||
3 | /coverage.txt | ||
4 | /.idea | ||
diff --git a/vendor/github.com/json-iterator/go/.travis.yml b/vendor/github.com/json-iterator/go/.travis.yml deleted file mode 100644 index 449e67c..0000000 --- a/vendor/github.com/json-iterator/go/.travis.yml +++ /dev/null | |||
@@ -1,14 +0,0 @@ | |||
1 | language: go | ||
2 | |||
3 | go: | ||
4 | - 1.8.x | ||
5 | - 1.x | ||
6 | |||
7 | before_install: | ||
8 | - go get -t -v ./... | ||
9 | |||
10 | script: | ||
11 | - ./test.sh | ||
12 | |||
13 | after_success: | ||
14 | - bash <(curl -s https://codecov.io/bash) | ||
diff --git a/vendor/github.com/json-iterator/go/Gopkg.lock b/vendor/github.com/json-iterator/go/Gopkg.lock deleted file mode 100644 index c8a9fbb..0000000 --- a/vendor/github.com/json-iterator/go/Gopkg.lock +++ /dev/null | |||
@@ -1,21 +0,0 @@ | |||
1 | # This file is autogenerated, do not edit; changes may be undone by the next 'dep ensure'. | ||
2 | |||
3 | |||
4 | [[projects]] | ||
5 | name = "github.com/modern-go/concurrent" | ||
6 | packages = ["."] | ||
7 | revision = "e0a39a4cb4216ea8db28e22a69f4ec25610d513a" | ||
8 | version = "1.0.0" | ||
9 | |||
10 | [[projects]] | ||
11 | name = "github.com/modern-go/reflect2" | ||
12 | packages = ["."] | ||
13 | revision = "4b7aa43c6742a2c18fdef89dd197aaae7dac7ccd" | ||
14 | version = "1.0.1" | ||
15 | |||
16 | [solve-meta] | ||
17 | analyzer-name = "dep" | ||
18 | analyzer-version = 1 | ||
19 | inputs-digest = "ea54a775e5a354cb015502d2e7aa4b74230fc77e894f34a838b268c25ec8eeb8" | ||
20 | solver-name = "gps-cdcl" | ||
21 | solver-version = 1 | ||
diff --git a/vendor/github.com/json-iterator/go/Gopkg.toml b/vendor/github.com/json-iterator/go/Gopkg.toml deleted file mode 100644 index 313a0f8..0000000 --- a/vendor/github.com/json-iterator/go/Gopkg.toml +++ /dev/null | |||
@@ -1,26 +0,0 @@ | |||
1 | # Gopkg.toml example | ||
2 | # | ||
3 | # Refer to https://github.com/golang/dep/blob/master/docs/Gopkg.toml.md | ||
4 | # for detailed Gopkg.toml documentation. | ||
5 | # | ||
6 | # required = ["github.com/user/thing/cmd/thing"] | ||
7 | # ignored = ["github.com/user/project/pkgX", "bitbucket.org/user/project/pkgA/pkgY"] | ||
8 | # | ||
9 | # [[constraint]] | ||
10 | # name = "github.com/user/project" | ||
11 | # version = "1.0.0" | ||
12 | # | ||
13 | # [[constraint]] | ||
14 | # name = "github.com/user/project2" | ||
15 | # branch = "dev" | ||
16 | # source = "github.com/myfork/project2" | ||
17 | # | ||
18 | # [[override]] | ||
19 | # name = "github.com/x/y" | ||
20 | # version = "2.4.0" | ||
21 | |||
22 | ignored = ["github.com/davecgh/go-spew*","github.com/google/gofuzz*","github.com/stretchr/testify*"] | ||
23 | |||
24 | [[constraint]] | ||
25 | name = "github.com/modern-go/reflect2" | ||
26 | version = "1.0.1" | ||
diff --git a/vendor/github.com/json-iterator/go/LICENSE b/vendor/github.com/json-iterator/go/LICENSE deleted file mode 100644 index 2cf4f5a..0000000 --- a/vendor/github.com/json-iterator/go/LICENSE +++ /dev/null | |||
@@ -1,21 +0,0 @@ | |||
1 | MIT License | ||
2 | |||
3 | Copyright (c) 2016 json-iterator | ||
4 | |||
5 | Permission is hereby granted, free of charge, to any person obtaining a copy | ||
6 | of this software and associated documentation files (the "Software"), to deal | ||
7 | in the Software without restriction, including without limitation the rights | ||
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
9 | copies of the Software, and to permit persons to whom the Software is | ||
10 | furnished to do so, subject to the following conditions: | ||
11 | |||
12 | The above copyright notice and this permission notice shall be included in all | ||
13 | copies or substantial portions of the Software. | ||
14 | |||
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
21 | SOFTWARE. | ||
diff --git a/vendor/github.com/json-iterator/go/README.md b/vendor/github.com/json-iterator/go/README.md deleted file mode 100644 index c589add..0000000 --- a/vendor/github.com/json-iterator/go/README.md +++ /dev/null | |||
@@ -1,85 +0,0 @@ | |||
1 | [![Sourcegraph](https://sourcegraph.com/github.com/json-iterator/go/-/badge.svg)](https://sourcegraph.com/github.com/json-iterator/go?badge) | ||
2 | [![GoDoc](http://img.shields.io/badge/go-documentation-blue.svg?style=flat-square)](https://pkg.go.dev/github.com/json-iterator/go) | ||
3 | [![Build Status](https://travis-ci.org/json-iterator/go.svg?branch=master)](https://travis-ci.org/json-iterator/go) | ||
4 | [![codecov](https://codecov.io/gh/json-iterator/go/branch/master/graph/badge.svg)](https://codecov.io/gh/json-iterator/go) | ||
5 | [![rcard](https://goreportcard.com/badge/github.com/json-iterator/go)](https://goreportcard.com/report/github.com/json-iterator/go) | ||
6 | [![License](http://img.shields.io/badge/license-mit-blue.svg?style=flat-square)](https://raw.githubusercontent.com/json-iterator/go/master/LICENSE) | ||
7 | [![Gitter chat](https://badges.gitter.im/gitterHQ/gitter.png)](https://gitter.im/json-iterator/Lobby) | ||
8 | |||
9 | A high-performance 100% compatible drop-in replacement of "encoding/json" | ||
10 | |||
11 | # Benchmark | ||
12 | |||
13 | ![benchmark](http://jsoniter.com/benchmarks/go-benchmark.png) | ||
14 | |||
15 | Source code: https://github.com/json-iterator/go-benchmark/blob/master/src/github.com/json-iterator/go-benchmark/benchmark_medium_payload_test.go | ||
16 | |||
17 | Raw Result (easyjson requires static code generation) | ||
18 | |||
19 | | | ns/op | allocation bytes | allocation times | | ||
20 | | --------------- | ----------- | ---------------- | ---------------- | | ||
21 | | std decode | 35510 ns/op | 1960 B/op | 99 allocs/op | | ||
22 | | easyjson decode | 8499 ns/op | 160 B/op | 4 allocs/op | | ||
23 | | jsoniter decode | 5623 ns/op | 160 B/op | 3 allocs/op | | ||
24 | | std encode | 2213 ns/op | 712 B/op | 5 allocs/op | | ||
25 | | easyjson encode | 883 ns/op | 576 B/op | 3 allocs/op | | ||
26 | | jsoniter encode | 837 ns/op | 384 B/op | 4 allocs/op | | ||
27 | |||
28 | Always benchmark with your own workload. | ||
29 | The result depends heavily on the data input. | ||
30 | |||
31 | # Usage | ||
32 | |||
33 | 100% compatibility with standard lib | ||
34 | |||
35 | Replace | ||
36 | |||
37 | ```go | ||
38 | import "encoding/json" | ||
39 | json.Marshal(&data) | ||
40 | ``` | ||
41 | |||
42 | with | ||
43 | |||
44 | ```go | ||
45 | import jsoniter "github.com/json-iterator/go" | ||
46 | |||
47 | var json = jsoniter.ConfigCompatibleWithStandardLibrary | ||
48 | json.Marshal(&data) | ||
49 | ``` | ||
50 | |||
51 | Replace | ||
52 | |||
53 | ```go | ||
54 | import "encoding/json" | ||
55 | json.Unmarshal(input, &data) | ||
56 | ``` | ||
57 | |||
58 | with | ||
59 | |||
60 | ```go | ||
61 | import jsoniter "github.com/json-iterator/go" | ||
62 | |||
63 | var json = jsoniter.ConfigCompatibleWithStandardLibrary | ||
64 | json.Unmarshal(input, &data) | ||
65 | ``` | ||
66 | |||
67 | [More documentation](http://jsoniter.com/migrate-from-go-std.html) | ||
68 | |||
69 | # How to get | ||
70 | |||
71 | ``` | ||
72 | go get github.com/json-iterator/go | ||
73 | ``` | ||
74 | |||
75 | # Contribution Welcomed ! | ||
76 | |||
77 | Contributors | ||
78 | |||
79 | - [thockin](https://github.com/thockin) | ||
80 | - [mattn](https://github.com/mattn) | ||
81 | - [cch123](https://github.com/cch123) | ||
82 | - [Oleg Shaldybin](https://github.com/olegshaldybin) | ||
83 | - [Jason Toffaletti](https://github.com/toffaletti) | ||
84 | |||
85 | Report issue or pull request, or email [email protected], or [![Gitter chat](https://badges.gitter.im/gitterHQ/gitter.png)](https://gitter.im/json-iterator/Lobby) | ||
diff --git a/vendor/github.com/json-iterator/go/adapter.go b/vendor/github.com/json-iterator/go/adapter.go deleted file mode 100644 index 92d2cc4..0000000 --- a/vendor/github.com/json-iterator/go/adapter.go +++ /dev/null | |||
@@ -1,150 +0,0 @@ | |||
1 | package jsoniter | ||
2 | |||
3 | import ( | ||
4 | "bytes" | ||
5 | "io" | ||
6 | ) | ||
7 | |||
8 | // RawMessage to make replace json with jsoniter | ||
9 | type RawMessage []byte | ||
10 | |||
11 | // Unmarshal adapts to json/encoding Unmarshal API | ||
12 | // | ||
13 | // Unmarshal parses the JSON-encoded data and stores the result in the value pointed to by v. | ||
14 | // Refer to https://godoc.org/encoding/json#Unmarshal for more information | ||
15 | func Unmarshal(data []byte, v interface{}) error { | ||
16 | return ConfigDefault.Unmarshal(data, v) | ||
17 | } | ||
18 | |||
19 | // UnmarshalFromString is a convenient method to read from string instead of []byte | ||
20 | func UnmarshalFromString(str string, v interface{}) error { | ||
21 | return ConfigDefault.UnmarshalFromString(str, v) | ||
22 | } | ||
23 | |||
24 | // Get quick method to get value from deeply nested JSON structure | ||
25 | func Get(data []byte, path ...interface{}) Any { | ||
26 | return ConfigDefault.Get(data, path...) | ||
27 | } | ||
28 | |||
29 | // Marshal adapts to json/encoding Marshal API | ||
30 | // | ||
31 | // Marshal returns the JSON encoding of v, adapts to json/encoding Marshal API | ||
32 | // Refer to https://godoc.org/encoding/json#Marshal for more information | ||
33 | func Marshal(v interface{}) ([]byte, error) { | ||
34 | return ConfigDefault.Marshal(v) | ||
35 | } | ||
36 | |||
37 | // MarshalIndent same as json.MarshalIndent. Prefix is not supported. | ||
38 | func MarshalIndent(v interface{}, prefix, indent string) ([]byte, error) { | ||
39 | return ConfigDefault.MarshalIndent(v, prefix, indent) | ||
40 | } | ||
41 | |||
42 | // MarshalToString convenient method to write as string instead of []byte | ||
43 | func MarshalToString(v interface{}) (string, error) { | ||
44 | return ConfigDefault.MarshalToString(v) | ||
45 | } | ||
46 | |||
47 | // NewDecoder adapts to json/stream NewDecoder API. | ||
48 | // | ||
49 | // NewDecoder returns a new decoder that reads from r. | ||
50 | // | ||
51 | // Instead of a json/encoding Decoder, an Decoder is returned | ||
52 | // Refer to https://godoc.org/encoding/json#NewDecoder for more information | ||
53 | func NewDecoder(reader io.Reader) *Decoder { | ||
54 | return ConfigDefault.NewDecoder(reader) | ||
55 | } | ||
56 | |||
57 | // Decoder reads and decodes JSON values from an input stream. | ||
58 | // Decoder provides identical APIs with json/stream Decoder (Token() and UseNumber() are in progress) | ||
59 | type Decoder struct { | ||
60 | iter *Iterator | ||
61 | } | ||
62 | |||
63 | // Decode decode JSON into interface{} | ||
64 | func (adapter *Decoder) Decode(obj interface{}) error { | ||
65 | if adapter.iter.head == adapter.iter.tail && adapter.iter.reader != nil { | ||
66 | if !adapter.iter.loadMore() { | ||
67 | return io.EOF | ||
68 | } | ||
69 | } | ||
70 | adapter.iter.ReadVal(obj) | ||
71 | err := adapter.iter.Error | ||
72 | if err == io.EOF { | ||
73 | return nil | ||
74 | } | ||
75 | return adapter.iter.Error | ||
76 | } | ||
77 | |||
78 | // More is there more? | ||
79 | func (adapter *Decoder) More() bool { | ||
80 | iter := adapter.iter | ||
81 | if iter.Error != nil { | ||
82 | return false | ||
83 | } | ||
84 | c := iter.nextToken() | ||
85 | if c == 0 { | ||
86 | return false | ||
87 | } | ||
88 | iter.unreadByte() | ||
89 | return c != ']' && c != '}' | ||
90 | } | ||
91 | |||
92 | // Buffered remaining buffer | ||
93 | func (adapter *Decoder) Buffered() io.Reader { | ||
94 | remaining := adapter.iter.buf[adapter.iter.head:adapter.iter.tail] | ||
95 | return bytes.NewReader(remaining) | ||
96 | } | ||
97 | |||
98 | // UseNumber causes the Decoder to unmarshal a number into an interface{} as a | ||
99 | // Number instead of as a float64. | ||
100 | func (adapter *Decoder) UseNumber() { | ||
101 | cfg := adapter.iter.cfg.configBeforeFrozen | ||
102 | cfg.UseNumber = true | ||
103 | adapter.iter.cfg = cfg.frozeWithCacheReuse(adapter.iter.cfg.extraExtensions) | ||
104 | } | ||
105 | |||
106 | // DisallowUnknownFields causes the Decoder to return an error when the destination | ||
107 | // is a struct and the input contains object keys which do not match any | ||
108 | // non-ignored, exported fields in the destination. | ||
109 | func (adapter *Decoder) DisallowUnknownFields() { | ||
110 | cfg := adapter.iter.cfg.configBeforeFrozen | ||
111 | cfg.DisallowUnknownFields = true | ||
112 | adapter.iter.cfg = cfg.frozeWithCacheReuse(adapter.iter.cfg.extraExtensions) | ||
113 | } | ||
114 | |||
115 | // NewEncoder same as json.NewEncoder | ||
116 | func NewEncoder(writer io.Writer) *Encoder { | ||
117 | return ConfigDefault.NewEncoder(writer) | ||
118 | } | ||
119 | |||
120 | // Encoder same as json.Encoder | ||
121 | type Encoder struct { | ||
122 | stream *Stream | ||
123 | } | ||
124 | |||
125 | // Encode encode interface{} as JSON to io.Writer | ||
126 | func (adapter *Encoder) Encode(val interface{}) error { | ||
127 | adapter.stream.WriteVal(val) | ||
128 | adapter.stream.WriteRaw("\n") | ||
129 | adapter.stream.Flush() | ||
130 | return adapter.stream.Error | ||
131 | } | ||
132 | |||
133 | // SetIndent set the indention. Prefix is not supported | ||
134 | func (adapter *Encoder) SetIndent(prefix, indent string) { | ||
135 | config := adapter.stream.cfg.configBeforeFrozen | ||
136 | config.IndentionStep = len(indent) | ||
137 | adapter.stream.cfg = config.frozeWithCacheReuse(adapter.stream.cfg.extraExtensions) | ||
138 | } | ||
139 | |||
140 | // SetEscapeHTML escape html by default, set to false to disable | ||
141 | func (adapter *Encoder) SetEscapeHTML(escapeHTML bool) { | ||
142 | config := adapter.stream.cfg.configBeforeFrozen | ||
143 | config.EscapeHTML = escapeHTML | ||
144 | adapter.stream.cfg = config.frozeWithCacheReuse(adapter.stream.cfg.extraExtensions) | ||
145 | } | ||
146 | |||
147 | // Valid reports whether data is a valid JSON encoding. | ||
148 | func Valid(data []byte) bool { | ||
149 | return ConfigDefault.Valid(data) | ||
150 | } | ||
diff --git a/vendor/github.com/json-iterator/go/any.go b/vendor/github.com/json-iterator/go/any.go deleted file mode 100644 index f6b8aea..0000000 --- a/vendor/github.com/json-iterator/go/any.go +++ /dev/null | |||
@@ -1,325 +0,0 @@ | |||
1 | package jsoniter | ||
2 | |||
3 | import ( | ||
4 | "errors" | ||
5 | "fmt" | ||
6 | "github.com/modern-go/reflect2" | ||
7 | "io" | ||
8 | "reflect" | ||
9 | "strconv" | ||
10 | "unsafe" | ||
11 | ) | ||
12 | |||
13 | // Any generic object representation. | ||
14 | // The lazy json implementation holds []byte and parse lazily. | ||
15 | type Any interface { | ||
16 | LastError() error | ||
17 | ValueType() ValueType | ||
18 | MustBeValid() Any | ||
19 | ToBool() bool | ||
20 | ToInt() int | ||
21 | ToInt32() int32 | ||
22 | ToInt64() int64 | ||
23 | ToUint() uint | ||
24 | ToUint32() uint32 | ||
25 | ToUint64() uint64 | ||
26 | ToFloat32() float32 | ||
27 | ToFloat64() float64 | ||
28 | ToString() string | ||
29 | ToVal(val interface{}) | ||
30 | Get(path ...interface{}) Any | ||
31 | Size() int | ||
32 | Keys() []string | ||
33 | GetInterface() interface{} | ||
34 | WriteTo(stream *Stream) | ||
35 | } | ||
36 | |||
37 | type baseAny struct{} | ||
38 | |||
39 | func (any *baseAny) Get(path ...interface{}) Any { | ||
40 | return &invalidAny{baseAny{}, fmt.Errorf("GetIndex %v from simple value", path)} | ||
41 | } | ||
42 | |||
43 | func (any *baseAny) Size() int { | ||
44 | return 0 | ||
45 | } | ||
46 | |||
47 | func (any *baseAny) Keys() []string { | ||
48 | return []string{} | ||
49 | } | ||
50 | |||
51 | func (any *baseAny) ToVal(obj interface{}) { | ||
52 | panic("not implemented") | ||
53 | } | ||
54 | |||
55 | // WrapInt32 turn int32 into Any interface | ||
56 | func WrapInt32(val int32) Any { | ||
57 | return &int32Any{baseAny{}, val} | ||
58 | } | ||
59 | |||
60 | // WrapInt64 turn int64 into Any interface | ||
61 | func WrapInt64(val int64) Any { | ||
62 | return &int64Any{baseAny{}, val} | ||
63 | } | ||
64 | |||
65 | // WrapUint32 turn uint32 into Any interface | ||
66 | func WrapUint32(val uint32) Any { | ||
67 | return &uint32Any{baseAny{}, val} | ||
68 | } | ||
69 | |||
70 | // WrapUint64 turn uint64 into Any interface | ||
71 | func WrapUint64(val uint64) Any { | ||
72 | return &uint64Any{baseAny{}, val} | ||
73 | } | ||
74 | |||
75 | // WrapFloat64 turn float64 into Any interface | ||
76 | func WrapFloat64(val float64) Any { | ||
77 | return &floatAny{baseAny{}, val} | ||
78 | } | ||
79 | |||
80 | // WrapString turn string into Any interface | ||
81 | func WrapString(val string) Any { | ||
82 | return &stringAny{baseAny{}, val} | ||
83 | } | ||
84 | |||
85 | // Wrap turn a go object into Any interface | ||
86 | func Wrap(val interface{}) Any { | ||
87 | if val == nil { | ||
88 | return &nilAny{} | ||
89 | } | ||
90 | asAny, isAny := val.(Any) | ||
91 | if isAny { | ||
92 | return asAny | ||
93 | } | ||
94 | typ := reflect2.TypeOf(val) | ||
95 | switch typ.Kind() { | ||
96 | case reflect.Slice: | ||
97 | return wrapArray(val) | ||
98 | case reflect.Struct: | ||
99 | return wrapStruct(val) | ||
100 | case reflect.Map: | ||
101 | return wrapMap(val) | ||
102 | case reflect.String: | ||
103 | return WrapString(val.(string)) | ||
104 | case reflect.Int: | ||
105 | if strconv.IntSize == 32 { | ||
106 | return WrapInt32(int32(val.(int))) | ||
107 | } | ||
108 | return WrapInt64(int64(val.(int))) | ||
109 | case reflect.Int8: | ||
110 | return WrapInt32(int32(val.(int8))) | ||
111 | case reflect.Int16: | ||
112 | return WrapInt32(int32(val.(int16))) | ||
113 | case reflect.Int32: | ||
114 | return WrapInt32(val.(int32)) | ||
115 | case reflect.Int64: | ||
116 | return WrapInt64(val.(int64)) | ||
117 | case reflect.Uint: | ||
118 | if strconv.IntSize == 32 { | ||
119 | return WrapUint32(uint32(val.(uint))) | ||
120 | } | ||
121 | return WrapUint64(uint64(val.(uint))) | ||
122 | case reflect.Uintptr: | ||
123 | if ptrSize == 32 { | ||
124 | return WrapUint32(uint32(val.(uintptr))) | ||
125 | } | ||
126 | return WrapUint64(uint64(val.(uintptr))) | ||
127 | case reflect.Uint8: | ||
128 | return WrapUint32(uint32(val.(uint8))) | ||
129 | case reflect.Uint16: | ||
130 | return WrapUint32(uint32(val.(uint16))) | ||
131 | case reflect.Uint32: | ||
132 | return WrapUint32(uint32(val.(uint32))) | ||
133 | case reflect.Uint64: | ||
134 | return WrapUint64(val.(uint64)) | ||
135 | case reflect.Float32: | ||
136 | return WrapFloat64(float64(val.(float32))) | ||
137 | case reflect.Float64: | ||
138 | return WrapFloat64(val.(float64)) | ||
139 | case reflect.Bool: | ||
140 | if val.(bool) == true { | ||
141 | return &trueAny{} | ||
142 | } | ||
143 | return &falseAny{} | ||
144 | } | ||
145 | return &invalidAny{baseAny{}, fmt.Errorf("unsupported type: %v", typ)} | ||
146 | } | ||
147 | |||
148 | // ReadAny read next JSON element as an Any object. It is a better json.RawMessage. | ||
149 | func (iter *Iterator) ReadAny() Any { | ||
150 | return iter.readAny() | ||
151 | } | ||
152 | |||
153 | func (iter *Iterator) readAny() Any { | ||
154 | c := iter.nextToken() | ||
155 | switch c { | ||
156 | case '"': | ||
157 | iter.unreadByte() | ||
158 | return &stringAny{baseAny{}, iter.ReadString()} | ||
159 | case 'n': | ||
160 | iter.skipThreeBytes('u', 'l', 'l') // null | ||
161 | return &nilAny{} | ||
162 | case 't': | ||
163 | iter.skipThreeBytes('r', 'u', 'e') // true | ||
164 | return &trueAny{} | ||
165 | case 'f': | ||
166 | iter.skipFourBytes('a', 'l', 's', 'e') // false | ||
167 | return &falseAny{} | ||
168 | case '{': | ||
169 | return iter.readObjectAny() | ||
170 | case '[': | ||
171 | return iter.readArrayAny() | ||
172 | case '-': | ||
173 | return iter.readNumberAny(false) | ||
174 | case 0: | ||
175 | return &invalidAny{baseAny{}, errors.New("input is empty")} | ||
176 | default: | ||
177 | return iter.readNumberAny(true) | ||
178 | } | ||
179 | } | ||
180 | |||
181 | func (iter *Iterator) readNumberAny(positive bool) Any { | ||
182 | iter.startCapture(iter.head - 1) | ||
183 | iter.skipNumber() | ||
184 | lazyBuf := iter.stopCapture() | ||
185 | return &numberLazyAny{baseAny{}, iter.cfg, lazyBuf, nil} | ||
186 | } | ||
187 | |||
188 | func (iter *Iterator) readObjectAny() Any { | ||
189 | iter.startCapture(iter.head - 1) | ||
190 | iter.skipObject() | ||
191 | lazyBuf := iter.stopCapture() | ||
192 | return &objectLazyAny{baseAny{}, iter.cfg, lazyBuf, nil} | ||
193 | } | ||
194 | |||
195 | func (iter *Iterator) readArrayAny() Any { | ||
196 | iter.startCapture(iter.head - 1) | ||
197 | iter.skipArray() | ||
198 | lazyBuf := iter.stopCapture() | ||
199 | return &arrayLazyAny{baseAny{}, iter.cfg, lazyBuf, nil} | ||
200 | } | ||
201 | |||
202 | func locateObjectField(iter *Iterator, target string) []byte { | ||
203 | var found []byte | ||
204 | iter.ReadObjectCB(func(iter *Iterator, field string) bool { | ||
205 | if field == target { | ||
206 | found = iter.SkipAndReturnBytes() | ||
207 | return false | ||
208 | } | ||
209 | iter.Skip() | ||
210 | return true | ||
211 | }) | ||
212 | return found | ||
213 | } | ||
214 | |||
215 | func locateArrayElement(iter *Iterator, target int) []byte { | ||
216 | var found []byte | ||
217 | n := 0 | ||
218 | iter.ReadArrayCB(func(iter *Iterator) bool { | ||
219 | if n == target { | ||
220 | found = iter.SkipAndReturnBytes() | ||
221 | return false | ||
222 | } | ||
223 | iter.Skip() | ||
224 | n++ | ||
225 | return true | ||
226 | }) | ||
227 | return found | ||
228 | } | ||
229 | |||
230 | func locatePath(iter *Iterator, path []interface{}) Any { | ||
231 | for i, pathKeyObj := range path { | ||
232 | switch pathKey := pathKeyObj.(type) { | ||
233 | case string: | ||
234 | valueBytes := locateObjectField(iter, pathKey) | ||
235 | if valueBytes == nil { | ||
236 | return newInvalidAny(path[i:]) | ||
237 | } | ||
238 | iter.ResetBytes(valueBytes) | ||
239 | case int: | ||
240 | valueBytes := locateArrayElement(iter, pathKey) | ||
241 | if valueBytes == nil { | ||
242 | return newInvalidAny(path[i:]) | ||
243 | } | ||
244 | iter.ResetBytes(valueBytes) | ||
245 | case int32: | ||
246 | if '*' == pathKey { | ||
247 | return iter.readAny().Get(path[i:]...) | ||
248 | } | ||
249 | return newInvalidAny(path[i:]) | ||
250 | default: | ||
251 | return newInvalidAny(path[i:]) | ||
252 | } | ||
253 | } | ||
254 | if iter.Error != nil && iter.Error != io.EOF { | ||
255 | return &invalidAny{baseAny{}, iter.Error} | ||
256 | } | ||
257 | return iter.readAny() | ||
258 | } | ||
259 | |||
260 | var anyType = reflect2.TypeOfPtr((*Any)(nil)).Elem() | ||
261 | |||
262 | func createDecoderOfAny(ctx *ctx, typ reflect2.Type) ValDecoder { | ||
263 | if typ == anyType { | ||
264 | return &directAnyCodec{} | ||
265 | } | ||
266 | if typ.Implements(anyType) { | ||
267 | return &anyCodec{ | ||
268 | valType: typ, | ||
269 | } | ||
270 | } | ||
271 | return nil | ||
272 | } | ||
273 | |||
274 | func createEncoderOfAny(ctx *ctx, typ reflect2.Type) ValEncoder { | ||
275 | if typ == anyType { | ||
276 | return &directAnyCodec{} | ||
277 | } | ||
278 | if typ.Implements(anyType) { | ||
279 | return &anyCodec{ | ||
280 | valType: typ, | ||
281 | } | ||
282 | } | ||
283 | return nil | ||
284 | } | ||
285 | |||
286 | type anyCodec struct { | ||
287 | valType reflect2.Type | ||
288 | } | ||
289 | |||
290 | func (codec *anyCodec) Decode(ptr unsafe.Pointer, iter *Iterator) { | ||
291 | panic("not implemented") | ||
292 | } | ||
293 | |||
294 | func (codec *anyCodec) Encode(ptr unsafe.Pointer, stream *Stream) { | ||
295 | obj := codec.valType.UnsafeIndirect(ptr) | ||
296 | any := obj.(Any) | ||
297 | any.WriteTo(stream) | ||
298 | } | ||
299 | |||
300 | func (codec *anyCodec) IsEmpty(ptr unsafe.Pointer) bool { | ||
301 | obj := codec.valType.UnsafeIndirect(ptr) | ||
302 | any := obj.(Any) | ||
303 | return any.Size() == 0 | ||
304 | } | ||
305 | |||
306 | type directAnyCodec struct { | ||
307 | } | ||
308 | |||
309 | func (codec *directAnyCodec) Decode(ptr unsafe.Pointer, iter *Iterator) { | ||
310 | *(*Any)(ptr) = iter.readAny() | ||
311 | } | ||
312 | |||
313 | func (codec *directAnyCodec) Encode(ptr unsafe.Pointer, stream *Stream) { | ||
314 | any := *(*Any)(ptr) | ||
315 | if any == nil { | ||
316 | stream.WriteNil() | ||
317 | return | ||
318 | } | ||
319 | any.WriteTo(stream) | ||
320 | } | ||
321 | |||
322 | func (codec *directAnyCodec) IsEmpty(ptr unsafe.Pointer) bool { | ||
323 | any := *(*Any)(ptr) | ||
324 | return any.Size() == 0 | ||
325 | } | ||
diff --git a/vendor/github.com/json-iterator/go/any_array.go b/vendor/github.com/json-iterator/go/any_array.go deleted file mode 100644 index 0449e9a..0000000 --- a/vendor/github.com/json-iterator/go/any_array.go +++ /dev/null | |||
@@ -1,278 +0,0 @@ | |||
1 | package jsoniter | ||
2 | |||
3 | import ( | ||
4 | "reflect" | ||
5 | "unsafe" | ||
6 | ) | ||
7 | |||
8 | type arrayLazyAny struct { | ||
9 | baseAny | ||
10 | cfg *frozenConfig | ||
11 | buf []byte | ||
12 | err error | ||
13 | } | ||
14 | |||
15 | func (any *arrayLazyAny) ValueType() ValueType { | ||
16 | return ArrayValue | ||
17 | } | ||
18 | |||
19 | func (any *arrayLazyAny) MustBeValid() Any { | ||
20 | return any | ||
21 | } | ||
22 | |||
23 | func (any *arrayLazyAny) LastError() error { | ||
24 | return any.err | ||
25 | } | ||
26 | |||
27 | func (any *arrayLazyAny) ToBool() bool { | ||
28 | iter := any.cfg.BorrowIterator(any.buf) | ||
29 | defer any.cfg.ReturnIterator(iter) | ||
30 | return iter.ReadArray() | ||
31 | } | ||
32 | |||
33 | func (any *arrayLazyAny) ToInt() int { | ||
34 | if any.ToBool() { | ||
35 | return 1 | ||
36 | } | ||
37 | return 0 | ||
38 | } | ||
39 | |||
40 | func (any *arrayLazyAny) ToInt32() int32 { | ||
41 | if any.ToBool() { | ||
42 | return 1 | ||
43 | } | ||
44 | return 0 | ||
45 | } | ||
46 | |||
47 | func (any *arrayLazyAny) ToInt64() int64 { | ||
48 | if any.ToBool() { | ||
49 | return 1 | ||
50 | } | ||
51 | return 0 | ||
52 | } | ||
53 | |||
54 | func (any *arrayLazyAny) ToUint() uint { | ||
55 | if any.ToBool() { | ||
56 | return 1 | ||
57 | } | ||
58 | return 0 | ||
59 | } | ||
60 | |||
61 | func (any *arrayLazyAny) ToUint32() uint32 { | ||
62 | if any.ToBool() { | ||
63 | return 1 | ||
64 | } | ||
65 | return 0 | ||
66 | } | ||
67 | |||
68 | func (any *arrayLazyAny) ToUint64() uint64 { | ||
69 | if any.ToBool() { | ||
70 | return 1 | ||
71 | } | ||
72 | return 0 | ||
73 | } | ||
74 | |||
75 | func (any *arrayLazyAny) ToFloat32() float32 { | ||
76 | if any.ToBool() { | ||
77 | return 1 | ||
78 | } | ||
79 | return 0 | ||
80 | } | ||
81 | |||
82 | func (any *arrayLazyAny) ToFloat64() float64 { | ||
83 | if any.ToBool() { | ||
84 | return 1 | ||
85 | } | ||
86 | return 0 | ||
87 | } | ||
88 | |||
89 | func (any *arrayLazyAny) ToString() string { | ||
90 | return *(*string)(unsafe.Pointer(&any.buf)) | ||
91 | } | ||
92 | |||
93 | func (any *arrayLazyAny) ToVal(val interface{}) { | ||
94 | iter := any.cfg.BorrowIterator(any.buf) | ||
95 | defer any.cfg.ReturnIterator(iter) | ||
96 | iter.ReadVal(val) | ||
97 | } | ||
98 | |||
99 | func (any *arrayLazyAny) Get(path ...interface{}) Any { | ||
100 | if len(path) == 0 { | ||
101 | return any | ||
102 | } | ||
103 | switch firstPath := path[0].(type) { | ||
104 | case int: | ||
105 | iter := any.cfg.BorrowIterator(any.buf) | ||
106 | defer any.cfg.ReturnIterator(iter) | ||
107 | valueBytes := locateArrayElement(iter, firstPath) | ||
108 | if valueBytes == nil { | ||
109 | return newInvalidAny(path) | ||
110 | } | ||
111 | iter.ResetBytes(valueBytes) | ||
112 | return locatePath(iter, path[1:]) | ||
113 | case int32: | ||
114 | if '*' == firstPath { | ||
115 | iter := any.cfg.BorrowIterator(any.buf) | ||
116 | defer any.cfg.ReturnIterator(iter) | ||
117 | arr := make([]Any, 0) | ||
118 | iter.ReadArrayCB(func(iter *Iterator) bool { | ||
119 | found := iter.readAny().Get(path[1:]...) | ||
120 | if found.ValueType() != InvalidValue { | ||
121 | arr = append(arr, found) | ||
122 | } | ||
123 | return true | ||
124 | }) | ||
125 | return wrapArray(arr) | ||
126 | } | ||
127 | return newInvalidAny(path) | ||
128 | default: | ||
129 | return newInvalidAny(path) | ||
130 | } | ||
131 | } | ||
132 | |||
133 | func (any *arrayLazyAny) Size() int { | ||
134 | size := 0 | ||
135 | iter := any.cfg.BorrowIterator(any.buf) | ||
136 | defer any.cfg.ReturnIterator(iter) | ||
137 | iter.ReadArrayCB(func(iter *Iterator) bool { | ||
138 | size++ | ||
139 | iter.Skip() | ||
140 | return true | ||
141 | }) | ||
142 | return size | ||
143 | } | ||
144 | |||
145 | func (any *arrayLazyAny) WriteTo(stream *Stream) { | ||
146 | stream.Write(any.buf) | ||
147 | } | ||
148 | |||
149 | func (any *arrayLazyAny) GetInterface() interface{} { | ||
150 | iter := any.cfg.BorrowIterator(any.buf) | ||
151 | defer any.cfg.ReturnIterator(iter) | ||
152 | return iter.Read() | ||
153 | } | ||
154 | |||
155 | type arrayAny struct { | ||
156 | baseAny | ||
157 | val reflect.Value | ||
158 | } | ||
159 | |||
160 | func wrapArray(val interface{}) *arrayAny { | ||
161 | return &arrayAny{baseAny{}, reflect.ValueOf(val)} | ||
162 | } | ||
163 | |||
164 | func (any *arrayAny) ValueType() ValueType { | ||
165 | return ArrayValue | ||
166 | } | ||
167 | |||
168 | func (any *arrayAny) MustBeValid() Any { | ||
169 | return any | ||
170 | } | ||
171 | |||
172 | func (any *arrayAny) LastError() error { | ||
173 | return nil | ||
174 | } | ||
175 | |||
176 | func (any *arrayAny) ToBool() bool { | ||
177 | return any.val.Len() != 0 | ||
178 | } | ||
179 | |||
180 | func (any *arrayAny) ToInt() int { | ||
181 | if any.val.Len() == 0 { | ||
182 | return 0 | ||
183 | } | ||
184 | return 1 | ||
185 | } | ||
186 | |||
187 | func (any *arrayAny) ToInt32() int32 { | ||
188 | if any.val.Len() == 0 { | ||
189 | return 0 | ||
190 | } | ||
191 | return 1 | ||
192 | } | ||
193 | |||
194 | func (any *arrayAny) ToInt64() int64 { | ||
195 | if any.val.Len() == 0 { | ||
196 | return 0 | ||
197 | } | ||
198 | return 1 | ||
199 | } | ||
200 | |||
201 | func (any *arrayAny) ToUint() uint { | ||
202 | if any.val.Len() == 0 { | ||
203 | return 0 | ||
204 | } | ||
205 | return 1 | ||
206 | } | ||
207 | |||
208 | func (any *arrayAny) ToUint32() uint32 { | ||
209 | if any.val.Len() == 0 { | ||
210 | return 0 | ||
211 | } | ||
212 | return 1 | ||
213 | } | ||
214 | |||
215 | func (any *arrayAny) ToUint64() uint64 { | ||
216 | if any.val.Len() == 0 { | ||
217 | return 0 | ||
218 | } | ||
219 | return 1 | ||
220 | } | ||
221 | |||
222 | func (any *arrayAny) ToFloat32() float32 { | ||
223 | if any.val.Len() == 0 { | ||
224 | return 0 | ||
225 | } | ||
226 | return 1 | ||
227 | } | ||
228 | |||
229 | func (any *arrayAny) ToFloat64() float64 { | ||
230 | if any.val.Len() == 0 { | ||
231 | return 0 | ||
232 | } | ||
233 | return 1 | ||
234 | } | ||
235 | |||
236 | func (any *arrayAny) ToString() string { | ||
237 | str, _ := MarshalToString(any.val.Interface()) | ||
238 | return str | ||
239 | } | ||
240 | |||
241 | func (any *arrayAny) Get(path ...interface{}) Any { | ||
242 | if len(path) == 0 { | ||
243 | return any | ||
244 | } | ||
245 | switch firstPath := path[0].(type) { | ||
246 | case int: | ||
247 | if firstPath < 0 || firstPath >= any.val.Len() { | ||
248 | return newInvalidAny(path) | ||
249 | } | ||
250 | return Wrap(any.val.Index(firstPath).Interface()) | ||
251 | case int32: | ||
252 | if '*' == firstPath { | ||
253 | mappedAll := make([]Any, 0) | ||
254 | for i := 0; i < any.val.Len(); i++ { | ||
255 | mapped := Wrap(any.val.Index(i).Interface()).Get(path[1:]...) | ||
256 | if mapped.ValueType() != InvalidValue { | ||
257 | mappedAll = append(mappedAll, mapped) | ||
258 | } | ||
259 | } | ||
260 | return wrapArray(mappedAll) | ||
261 | } | ||
262 | return newInvalidAny(path) | ||
263 | default: | ||
264 | return newInvalidAny(path) | ||
265 | } | ||
266 | } | ||
267 | |||
268 | func (any *arrayAny) Size() int { | ||
269 | return any.val.Len() | ||
270 | } | ||
271 | |||
272 | func (any *arrayAny) WriteTo(stream *Stream) { | ||
273 | stream.WriteVal(any.val) | ||
274 | } | ||
275 | |||
276 | func (any *arrayAny) GetInterface() interface{} { | ||
277 | return any.val.Interface() | ||
278 | } | ||
diff --git a/vendor/github.com/json-iterator/go/any_bool.go b/vendor/github.com/json-iterator/go/any_bool.go deleted file mode 100644 index 9452324..0000000 --- a/vendor/github.com/json-iterator/go/any_bool.go +++ /dev/null | |||
@@ -1,137 +0,0 @@ | |||
1 | package jsoniter | ||
2 | |||
3 | type trueAny struct { | ||
4 | baseAny | ||
5 | } | ||
6 | |||
7 | func (any *trueAny) LastError() error { | ||
8 | return nil | ||
9 | } | ||
10 | |||
11 | func (any *trueAny) ToBool() bool { | ||
12 | return true | ||
13 | } | ||
14 | |||
15 | func (any *trueAny) ToInt() int { | ||
16 | return 1 | ||
17 | } | ||
18 | |||
19 | func (any *trueAny) ToInt32() int32 { | ||
20 | return 1 | ||
21 | } | ||
22 | |||
23 | func (any *trueAny) ToInt64() int64 { | ||
24 | return 1 | ||
25 | } | ||
26 | |||
27 | func (any *trueAny) ToUint() uint { | ||
28 | return 1 | ||
29 | } | ||
30 | |||
31 | func (any *trueAny) ToUint32() uint32 { | ||
32 | return 1 | ||
33 | } | ||
34 | |||
35 | func (any *trueAny) ToUint64() uint64 { | ||
36 | return 1 | ||
37 | } | ||
38 | |||
39 | func (any *trueAny) ToFloat32() float32 { | ||
40 | return 1 | ||
41 | } | ||
42 | |||
43 | func (any *trueAny) ToFloat64() float64 { | ||
44 | return 1 | ||
45 | } | ||
46 | |||
47 | func (any *trueAny) ToString() string { | ||
48 | return "true" | ||
49 | } | ||
50 | |||
51 | func (any *trueAny) WriteTo(stream *Stream) { | ||
52 | stream.WriteTrue() | ||
53 | } | ||
54 | |||
55 | func (any *trueAny) Parse() *Iterator { | ||
56 | return nil | ||
57 | } | ||
58 | |||
59 | func (any *trueAny) GetInterface() interface{} { | ||
60 | return true | ||
61 | } | ||
62 | |||
63 | func (any *trueAny) ValueType() ValueType { | ||
64 | return BoolValue | ||
65 | } | ||
66 | |||
67 | func (any *trueAny) MustBeValid() Any { | ||
68 | return any | ||
69 | } | ||
70 | |||
71 | type falseAny struct { | ||
72 | baseAny | ||
73 | } | ||
74 | |||
75 | func (any *falseAny) LastError() error { | ||
76 | return nil | ||
77 | } | ||
78 | |||
79 | func (any *falseAny) ToBool() bool { | ||
80 | return false | ||
81 | } | ||
82 | |||
83 | func (any *falseAny) ToInt() int { | ||
84 | return 0 | ||
85 | } | ||
86 | |||
87 | func (any *falseAny) ToInt32() int32 { | ||
88 | return 0 | ||
89 | } | ||
90 | |||
91 | func (any *falseAny) ToInt64() int64 { | ||
92 | return 0 | ||
93 | } | ||
94 | |||
95 | func (any *falseAny) ToUint() uint { | ||
96 | return 0 | ||
97 | } | ||
98 | |||
99 | func (any *falseAny) ToUint32() uint32 { | ||
100 | return 0 | ||
101 | } | ||
102 | |||
103 | func (any *falseAny) ToUint64() uint64 { | ||
104 | return 0 | ||
105 | } | ||
106 | |||
107 | func (any *falseAny) ToFloat32() float32 { | ||
108 | return 0 | ||
109 | } | ||
110 | |||
111 | func (any *falseAny) ToFloat64() float64 { | ||
112 | return 0 | ||
113 | } | ||
114 | |||
115 | func (any *falseAny) ToString() string { | ||
116 | return "false" | ||
117 | } | ||
118 | |||
119 | func (any *falseAny) WriteTo(stream *Stream) { | ||
120 | stream.WriteFalse() | ||
121 | } | ||
122 | |||
123 | func (any *falseAny) Parse() *Iterator { | ||
124 | return nil | ||
125 | } | ||
126 | |||
127 | func (any *falseAny) GetInterface() interface{} { | ||
128 | return false | ||
129 | } | ||
130 | |||
131 | func (any *falseAny) ValueType() ValueType { | ||
132 | return BoolValue | ||
133 | } | ||
134 | |||
135 | func (any *falseAny) MustBeValid() Any { | ||
136 | return any | ||
137 | } | ||
diff --git a/vendor/github.com/json-iterator/go/any_float.go b/vendor/github.com/json-iterator/go/any_float.go deleted file mode 100644 index 35fdb09..0000000 --- a/vendor/github.com/json-iterator/go/any_float.go +++ /dev/null | |||
@@ -1,83 +0,0 @@ | |||
1 | package jsoniter | ||
2 | |||
3 | import ( | ||
4 | "strconv" | ||
5 | ) | ||
6 | |||
7 | type floatAny struct { | ||
8 | baseAny | ||
9 | val float64 | ||
10 | } | ||
11 | |||
12 | func (any *floatAny) Parse() *Iterator { | ||
13 | return nil | ||
14 | } | ||
15 | |||
16 | func (any *floatAny) ValueType() ValueType { | ||
17 | return NumberValue | ||
18 | } | ||
19 | |||
20 | func (any *floatAny) MustBeValid() Any { | ||
21 | return any | ||
22 | } | ||
23 | |||
24 | func (any *floatAny) LastError() error { | ||
25 | return nil | ||
26 | } | ||
27 | |||
28 | func (any *floatAny) ToBool() bool { | ||
29 | return any.ToFloat64() != 0 | ||
30 | } | ||
31 | |||
32 | func (any *floatAny) ToInt() int { | ||
33 | return int(any.val) | ||
34 | } | ||
35 | |||
36 | func (any *floatAny) ToInt32() int32 { | ||
37 | return int32(any.val) | ||
38 | } | ||
39 | |||
40 | func (any *floatAny) ToInt64() int64 { | ||
41 | return int64(any.val) | ||
42 | } | ||
43 | |||
44 | func (any *floatAny) ToUint() uint { | ||
45 | if any.val > 0 { | ||
46 | return uint(any.val) | ||
47 | } | ||
48 | return 0 | ||
49 | } | ||
50 | |||
51 | func (any *floatAny) ToUint32() uint32 { | ||
52 | if any.val > 0 { | ||
53 | return uint32(any.val) | ||
54 | } | ||
55 | return 0 | ||
56 | } | ||
57 | |||
58 | func (any *floatAny) ToUint64() uint64 { | ||
59 | if any.val > 0 { | ||
60 | return uint64(any.val) | ||
61 | } | ||
62 | return 0 | ||
63 | } | ||
64 | |||
65 | func (any *floatAny) ToFloat32() float32 { | ||
66 | return float32(any.val) | ||
67 | } | ||
68 | |||
69 | func (any *floatAny) ToFloat64() float64 { | ||
70 | return any.val | ||
71 | } | ||
72 | |||
73 | func (any *floatAny) ToString() string { | ||
74 | return strconv.FormatFloat(any.val, 'E', -1, 64) | ||
75 | } | ||
76 | |||
77 | func (any *floatAny) WriteTo(stream *Stream) { | ||
78 | stream.WriteFloat64(any.val) | ||
79 | } | ||
80 | |||
81 | func (any *floatAny) GetInterface() interface{} { | ||
82 | return any.val | ||
83 | } | ||
diff --git a/vendor/github.com/json-iterator/go/any_int32.go b/vendor/github.com/json-iterator/go/any_int32.go deleted file mode 100644 index 1b56f39..0000000 --- a/vendor/github.com/json-iterator/go/any_int32.go +++ /dev/null | |||
@@ -1,74 +0,0 @@ | |||
1 | package jsoniter | ||
2 | |||
3 | import ( | ||
4 | "strconv" | ||
5 | ) | ||
6 | |||
7 | type int32Any struct { | ||
8 | baseAny | ||
9 | val int32 | ||
10 | } | ||
11 | |||
12 | func (any *int32Any) LastError() error { | ||
13 | return nil | ||
14 | } | ||
15 | |||
16 | func (any *int32Any) ValueType() ValueType { | ||
17 | return NumberValue | ||
18 | } | ||
19 | |||
20 | func (any *int32Any) MustBeValid() Any { | ||
21 | return any | ||
22 | } | ||
23 | |||
24 | func (any *int32Any) ToBool() bool { | ||
25 | return any.val != 0 | ||
26 | } | ||
27 | |||
28 | func (any *int32Any) ToInt() int { | ||
29 | return int(any.val) | ||
30 | } | ||
31 | |||
32 | func (any *int32Any) ToInt32() int32 { | ||
33 | return any.val | ||
34 | } | ||
35 | |||
36 | func (any *int32Any) ToInt64() int64 { | ||
37 | return int64(any.val) | ||
38 | } | ||
39 | |||
40 | func (any *int32Any) ToUint() uint { | ||
41 | return uint(any.val) | ||
42 | } | ||
43 | |||
44 | func (any *int32Any) ToUint32() uint32 { | ||
45 | return uint32(any.val) | ||
46 | } | ||
47 | |||
48 | func (any *int32Any) ToUint64() uint64 { | ||
49 | return uint64(any.val) | ||
50 | } | ||
51 | |||
52 | func (any *int32Any) ToFloat32() float32 { | ||
53 | return float32(any.val) | ||
54 | } | ||
55 | |||
56 | func (any *int32Any) ToFloat64() float64 { | ||
57 | return float64(any.val) | ||
58 | } | ||
59 | |||
60 | func (any *int32Any) ToString() string { | ||
61 | return strconv.FormatInt(int64(any.val), 10) | ||
62 | } | ||
63 | |||
64 | func (any *int32Any) WriteTo(stream *Stream) { | ||
65 | stream.WriteInt32(any.val) | ||
66 | } | ||
67 | |||
68 | func (any *int32Any) Parse() *Iterator { | ||
69 | return nil | ||
70 | } | ||
71 | |||
72 | func (any *int32Any) GetInterface() interface{} { | ||
73 | return any.val | ||
74 | } | ||
diff --git a/vendor/github.com/json-iterator/go/any_int64.go b/vendor/github.com/json-iterator/go/any_int64.go deleted file mode 100644 index c440d72..0000000 --- a/vendor/github.com/json-iterator/go/any_int64.go +++ /dev/null | |||
@@ -1,74 +0,0 @@ | |||
1 | package jsoniter | ||
2 | |||
3 | import ( | ||
4 | "strconv" | ||
5 | ) | ||
6 | |||
7 | type int64Any struct { | ||
8 | baseAny | ||
9 | val int64 | ||
10 | } | ||
11 | |||
12 | func (any *int64Any) LastError() error { | ||
13 | return nil | ||
14 | } | ||
15 | |||
16 | func (any *int64Any) ValueType() ValueType { | ||
17 | return NumberValue | ||
18 | } | ||
19 | |||
20 | func (any *int64Any) MustBeValid() Any { | ||
21 | return any | ||
22 | } | ||
23 | |||
24 | func (any *int64Any) ToBool() bool { | ||
25 | return any.val != 0 | ||
26 | } | ||
27 | |||
28 | func (any *int64Any) ToInt() int { | ||
29 | return int(any.val) | ||
30 | } | ||
31 | |||
32 | func (any *int64Any) ToInt32() int32 { | ||
33 | return int32(any.val) | ||
34 | } | ||
35 | |||
36 | func (any *int64Any) ToInt64() int64 { | ||
37 | return any.val | ||
38 | } | ||
39 | |||
40 | func (any *int64Any) ToUint() uint { | ||
41 | return uint(any.val) | ||
42 | } | ||
43 | |||
44 | func (any *int64Any) ToUint32() uint32 { | ||
45 | return uint32(any.val) | ||
46 | } | ||
47 | |||
48 | func (any *int64Any) ToUint64() uint64 { | ||
49 | return uint64(any.val) | ||
50 | } | ||
51 | |||
52 | func (any *int64Any) ToFloat32() float32 { | ||
53 | return float32(any.val) | ||
54 | } | ||
55 | |||
56 | func (any *int64Any) ToFloat64() float64 { | ||
57 | return float64(any.val) | ||
58 | } | ||
59 | |||
60 | func (any *int64Any) ToString() string { | ||
61 | return strconv.FormatInt(any.val, 10) | ||
62 | } | ||
63 | |||
64 | func (any *int64Any) WriteTo(stream *Stream) { | ||
65 | stream.WriteInt64(any.val) | ||
66 | } | ||
67 | |||
68 | func (any *int64Any) Parse() *Iterator { | ||
69 | return nil | ||
70 | } | ||
71 | |||
72 | func (any *int64Any) GetInterface() interface{} { | ||
73 | return any.val | ||
74 | } | ||
diff --git a/vendor/github.com/json-iterator/go/any_invalid.go b/vendor/github.com/json-iterator/go/any_invalid.go deleted file mode 100644 index 1d859ea..0000000 --- a/vendor/github.com/json-iterator/go/any_invalid.go +++ /dev/null | |||
@@ -1,82 +0,0 @@ | |||
1 | package jsoniter | ||
2 | |||
3 | import "fmt" | ||
4 | |||
5 | type invalidAny struct { | ||
6 | baseAny | ||
7 | err error | ||
8 | } | ||
9 | |||
10 | func newInvalidAny(path []interface{}) *invalidAny { | ||
11 | return &invalidAny{baseAny{}, fmt.Errorf("%v not found", path)} | ||
12 | } | ||
13 | |||
14 | func (any *invalidAny) LastError() error { | ||
15 | return any.err | ||
16 | } | ||
17 | |||
18 | func (any *invalidAny) ValueType() ValueType { | ||
19 | return InvalidValue | ||
20 | } | ||
21 | |||
22 | func (any *invalidAny) MustBeValid() Any { | ||
23 | panic(any.err) | ||
24 | } | ||
25 | |||
26 | func (any *invalidAny) ToBool() bool { | ||
27 | return false | ||
28 | } | ||
29 | |||
30 | func (any *invalidAny) ToInt() int { | ||
31 | return 0 | ||
32 | } | ||
33 | |||
34 | func (any *invalidAny) ToInt32() int32 { | ||
35 | return 0 | ||
36 | } | ||
37 | |||
38 | func (any *invalidAny) ToInt64() int64 { | ||
39 | return 0 | ||
40 | } | ||
41 | |||
42 | func (any *invalidAny) ToUint() uint { | ||
43 | return 0 | ||
44 | } | ||
45 | |||
46 | func (any *invalidAny) ToUint32() uint32 { | ||
47 | return 0 | ||
48 | } | ||
49 | |||
50 | func (any *invalidAny) ToUint64() uint64 { | ||
51 | return 0 | ||
52 | } | ||
53 | |||
54 | func (any *invalidAny) ToFloat32() float32 { | ||
55 | return 0 | ||
56 | } | ||
57 | |||
58 | func (any *invalidAny) ToFloat64() float64 { | ||
59 | return 0 | ||
60 | } | ||
61 | |||
62 | func (any *invalidAny) ToString() string { | ||
63 | return "" | ||
64 | } | ||
65 | |||
66 | func (any *invalidAny) WriteTo(stream *Stream) { | ||
67 | } | ||
68 | |||
69 | func (any *invalidAny) Get(path ...interface{}) Any { | ||
70 | if any.err == nil { | ||
71 | return &invalidAny{baseAny{}, fmt.Errorf("get %v from invalid", path)} | ||
72 | } | ||
73 | return &invalidAny{baseAny{}, fmt.Errorf("%v, get %v from invalid", any.err, path)} | ||
74 | } | ||
75 | |||
76 | func (any *invalidAny) Parse() *Iterator { | ||
77 | return nil | ||
78 | } | ||
79 | |||
80 | func (any *invalidAny) GetInterface() interface{} { | ||
81 | return nil | ||
82 | } | ||
diff --git a/vendor/github.com/json-iterator/go/any_nil.go b/vendor/github.com/json-iterator/go/any_nil.go deleted file mode 100644 index d04cb54..0000000 --- a/vendor/github.com/json-iterator/go/any_nil.go +++ /dev/null | |||
@@ -1,69 +0,0 @@ | |||
1 | package jsoniter | ||
2 | |||
3 | type nilAny struct { | ||
4 | baseAny | ||
5 | } | ||
6 | |||
7 | func (any *nilAny) LastError() error { | ||
8 | return nil | ||
9 | } | ||
10 | |||
11 | func (any *nilAny) ValueType() ValueType { | ||
12 | return NilValue | ||
13 | } | ||
14 | |||
15 | func (any *nilAny) MustBeValid() Any { | ||
16 | return any | ||
17 | } | ||
18 | |||
19 | func (any *nilAny) ToBool() bool { | ||
20 | return false | ||
21 | } | ||
22 | |||
23 | func (any *nilAny) ToInt() int { | ||
24 | return 0 | ||
25 | } | ||
26 | |||
27 | func (any *nilAny) ToInt32() int32 { | ||
28 | return 0 | ||
29 | } | ||
30 | |||
31 | func (any *nilAny) ToInt64() int64 { | ||
32 | return 0 | ||
33 | } | ||
34 | |||
35 | func (any *nilAny) ToUint() uint { | ||
36 | return 0 | ||
37 | } | ||
38 | |||
39 | func (any *nilAny) ToUint32() uint32 { | ||
40 | return 0 | ||
41 | } | ||
42 | |||
43 | func (any *nilAny) ToUint64() uint64 { | ||
44 | return 0 | ||
45 | } | ||
46 | |||
47 | func (any *nilAny) ToFloat32() float32 { | ||
48 | return 0 | ||
49 | } | ||
50 | |||
51 | func (any *nilAny) ToFloat64() float64 { | ||
52 | return 0 | ||
53 | } | ||
54 | |||
55 | func (any *nilAny) ToString() string { | ||
56 | return "" | ||
57 | } | ||
58 | |||
59 | func (any *nilAny) WriteTo(stream *Stream) { | ||
60 | stream.WriteNil() | ||
61 | } | ||
62 | |||
63 | func (any *nilAny) Parse() *Iterator { | ||
64 | return nil | ||
65 | } | ||
66 | |||
67 | func (any *nilAny) GetInterface() interface{} { | ||
68 | return nil | ||
69 | } | ||
diff --git a/vendor/github.com/json-iterator/go/any_number.go b/vendor/github.com/json-iterator/go/any_number.go deleted file mode 100644 index 9d1e901..0000000 --- a/vendor/github.com/json-iterator/go/any_number.go +++ /dev/null | |||
@@ -1,123 +0,0 @@ | |||
1 | package jsoniter | ||
2 | |||
3 | import ( | ||
4 | "io" | ||
5 | "unsafe" | ||
6 | ) | ||
7 | |||
8 | type numberLazyAny struct { | ||
9 | baseAny | ||
10 | cfg *frozenConfig | ||
11 | buf []byte | ||
12 | err error | ||
13 | } | ||
14 | |||
15 | func (any *numberLazyAny) ValueType() ValueType { | ||
16 | return NumberValue | ||
17 | } | ||
18 | |||
19 | func (any *numberLazyAny) MustBeValid() Any { | ||
20 | return any | ||
21 | } | ||
22 | |||
23 | func (any *numberLazyAny) LastError() error { | ||
24 | return any.err | ||
25 | } | ||
26 | |||
27 | func (any *numberLazyAny) ToBool() bool { | ||
28 | return any.ToFloat64() != 0 | ||
29 | } | ||
30 | |||
31 | func (any *numberLazyAny) ToInt() int { | ||
32 | iter := any.cfg.BorrowIterator(any.buf) | ||
33 | defer any.cfg.ReturnIterator(iter) | ||
34 | val := iter.ReadInt() | ||
35 | if iter.Error != nil && iter.Error != io.EOF { | ||
36 | any.err = iter.Error | ||
37 | } | ||
38 | return val | ||
39 | } | ||
40 | |||
41 | func (any *numberLazyAny) ToInt32() int32 { | ||
42 | iter := any.cfg.BorrowIterator(any.buf) | ||
43 | defer any.cfg.ReturnIterator(iter) | ||
44 | val := iter.ReadInt32() | ||
45 | if iter.Error != nil && iter.Error != io.EOF { | ||
46 | any.err = iter.Error | ||
47 | } | ||
48 | return val | ||
49 | } | ||
50 | |||
51 | func (any *numberLazyAny) ToInt64() int64 { | ||
52 | iter := any.cfg.BorrowIterator(any.buf) | ||
53 | defer any.cfg.ReturnIterator(iter) | ||
54 | val := iter.ReadInt64() | ||
55 | if iter.Error != nil && iter.Error != io.EOF { | ||
56 | any.err = iter.Error | ||
57 | } | ||
58 | return val | ||
59 | } | ||
60 | |||
61 | func (any *numberLazyAny) ToUint() uint { | ||
62 | iter := any.cfg.BorrowIterator(any.buf) | ||
63 | defer any.cfg.ReturnIterator(iter) | ||
64 | val := iter.ReadUint() | ||
65 | if iter.Error != nil && iter.Error != io.EOF { | ||
66 | any.err = iter.Error | ||
67 | } | ||
68 | return val | ||
69 | } | ||
70 | |||
71 | func (any *numberLazyAny) ToUint32() uint32 { | ||
72 | iter := any.cfg.BorrowIterator(any.buf) | ||
73 | defer any.cfg.ReturnIterator(iter) | ||
74 | val := iter.ReadUint32() | ||
75 | if iter.Error != nil && iter.Error != io.EOF { | ||
76 | any.err = iter.Error | ||
77 | } | ||
78 | return val | ||
79 | } | ||
80 | |||
81 | func (any *numberLazyAny) ToUint64() uint64 { | ||
82 | iter := any.cfg.BorrowIterator(any.buf) | ||
83 | defer any.cfg.ReturnIterator(iter) | ||
84 | val := iter.ReadUint64() | ||
85 | if iter.Error != nil && iter.Error != io.EOF { | ||
86 | any.err = iter.Error | ||
87 | } | ||
88 | return val | ||
89 | } | ||
90 | |||
91 | func (any *numberLazyAny) ToFloat32() float32 { | ||
92 | iter := any.cfg.BorrowIterator(any.buf) | ||
93 | defer any.cfg.ReturnIterator(iter) | ||
94 | val := iter.ReadFloat32() | ||
95 | if iter.Error != nil && iter.Error != io.EOF { | ||
96 | any.err = iter.Error | ||
97 | } | ||
98 | return val | ||
99 | } | ||
100 | |||
101 | func (any *numberLazyAny) ToFloat64() float64 { | ||
102 | iter := any.cfg.BorrowIterator(any.buf) | ||
103 | defer any.cfg.ReturnIterator(iter) | ||
104 | val := iter.ReadFloat64() | ||
105 | if iter.Error != nil && iter.Error != io.EOF { | ||
106 | any.err = iter.Error | ||
107 | } | ||
108 | return val | ||
109 | } | ||
110 | |||
111 | func (any *numberLazyAny) ToString() string { | ||
112 | return *(*string)(unsafe.Pointer(&any.buf)) | ||
113 | } | ||
114 | |||
115 | func (any *numberLazyAny) WriteTo(stream *Stream) { | ||
116 | stream.Write(any.buf) | ||
117 | } | ||
118 | |||
119 | func (any *numberLazyAny) GetInterface() interface{} { | ||
120 | iter := any.cfg.BorrowIterator(any.buf) | ||
121 | defer any.cfg.ReturnIterator(iter) | ||
122 | return iter.Read() | ||
123 | } | ||
diff --git a/vendor/github.com/json-iterator/go/any_object.go b/vendor/github.com/json-iterator/go/any_object.go deleted file mode 100644 index c44ef5c..0000000 --- a/vendor/github.com/json-iterator/go/any_object.go +++ /dev/null | |||
@@ -1,374 +0,0 @@ | |||
1 | package jsoniter | ||
2 | |||
3 | import ( | ||
4 | "reflect" | ||
5 | "unsafe" | ||
6 | ) | ||
7 | |||
8 | type objectLazyAny struct { | ||
9 | baseAny | ||
10 | cfg *frozenConfig | ||
11 | buf []byte | ||
12 | err error | ||
13 | } | ||
14 | |||
15 | func (any *objectLazyAny) ValueType() ValueType { | ||
16 | return ObjectValue | ||
17 | } | ||
18 | |||
19 | func (any *objectLazyAny) MustBeValid() Any { | ||
20 | return any | ||
21 | } | ||
22 | |||
23 | func (any *objectLazyAny) LastError() error { | ||
24 | return any.err | ||
25 | } | ||
26 | |||
27 | func (any *objectLazyAny) ToBool() bool { | ||
28 | return true | ||
29 | } | ||
30 | |||
31 | func (any *objectLazyAny) ToInt() int { | ||
32 | return 0 | ||
33 | } | ||
34 | |||
35 | func (any *objectLazyAny) ToInt32() int32 { | ||
36 | return 0 | ||
37 | } | ||
38 | |||
39 | func (any *objectLazyAny) ToInt64() int64 { | ||
40 | return 0 | ||
41 | } | ||
42 | |||
43 | func (any *objectLazyAny) ToUint() uint { | ||
44 | return 0 | ||
45 | } | ||
46 | |||
47 | func (any *objectLazyAny) ToUint32() uint32 { | ||
48 | return 0 | ||
49 | } | ||
50 | |||
51 | func (any *objectLazyAny) ToUint64() uint64 { | ||
52 | return 0 | ||
53 | } | ||
54 | |||
55 | func (any *objectLazyAny) ToFloat32() float32 { | ||
56 | return 0 | ||
57 | } | ||
58 | |||
59 | func (any *objectLazyAny) ToFloat64() float64 { | ||
60 | return 0 | ||
61 | } | ||
62 | |||
63 | func (any *objectLazyAny) ToString() string { | ||
64 | return *(*string)(unsafe.Pointer(&any.buf)) | ||
65 | } | ||
66 | |||
67 | func (any *objectLazyAny) ToVal(obj interface{}) { | ||
68 | iter := any.cfg.BorrowIterator(any.buf) | ||
69 | defer any.cfg.ReturnIterator(iter) | ||
70 | iter.ReadVal(obj) | ||
71 | } | ||
72 | |||
73 | func (any *objectLazyAny) Get(path ...interface{}) Any { | ||
74 | if len(path) == 0 { | ||
75 | return any | ||
76 | } | ||
77 | switch firstPath := path[0].(type) { | ||
78 | case string: | ||
79 | iter := any.cfg.BorrowIterator(any.buf) | ||
80 | defer any.cfg.ReturnIterator(iter) | ||
81 | valueBytes := locateObjectField(iter, firstPath) | ||
82 | if valueBytes == nil { | ||
83 | return newInvalidAny(path) | ||
84 | } | ||
85 | iter.ResetBytes(valueBytes) | ||
86 | return locatePath(iter, path[1:]) | ||
87 | case int32: | ||
88 | if '*' == firstPath { | ||
89 | mappedAll := map[string]Any{} | ||
90 | iter := any.cfg.BorrowIterator(any.buf) | ||
91 | defer any.cfg.ReturnIterator(iter) | ||
92 | iter.ReadMapCB(func(iter *Iterator, field string) bool { | ||
93 | mapped := locatePath(iter, path[1:]) | ||
94 | if mapped.ValueType() != InvalidValue { | ||
95 | mappedAll[field] = mapped | ||
96 | } | ||
97 | return true | ||
98 | }) | ||
99 | return wrapMap(mappedAll) | ||
100 | } | ||
101 | return newInvalidAny(path) | ||
102 | default: | ||
103 | return newInvalidAny(path) | ||
104 | } | ||
105 | } | ||
106 | |||
107 | func (any *objectLazyAny) Keys() []string { | ||
108 | keys := []string{} | ||
109 | iter := any.cfg.BorrowIterator(any.buf) | ||
110 | defer any.cfg.ReturnIterator(iter) | ||
111 | iter.ReadMapCB(func(iter *Iterator, field string) bool { | ||
112 | iter.Skip() | ||
113 | keys = append(keys, field) | ||
114 | return true | ||
115 | }) | ||
116 | return keys | ||
117 | } | ||
118 | |||
119 | func (any *objectLazyAny) Size() int { | ||
120 | size := 0 | ||
121 | iter := any.cfg.BorrowIterator(any.buf) | ||
122 | defer any.cfg.ReturnIterator(iter) | ||
123 | iter.ReadObjectCB(func(iter *Iterator, field string) bool { | ||
124 | iter.Skip() | ||
125 | size++ | ||
126 | return true | ||
127 | }) | ||
128 | return size | ||
129 | } | ||
130 | |||
131 | func (any *objectLazyAny) WriteTo(stream *Stream) { | ||
132 | stream.Write(any.buf) | ||
133 | } | ||
134 | |||
135 | func (any *objectLazyAny) GetInterface() interface{} { | ||
136 | iter := any.cfg.BorrowIterator(any.buf) | ||
137 | defer any.cfg.ReturnIterator(iter) | ||
138 | return iter.Read() | ||
139 | } | ||
140 | |||
141 | type objectAny struct { | ||
142 | baseAny | ||
143 | err error | ||
144 | val reflect.Value | ||
145 | } | ||
146 | |||
147 | func wrapStruct(val interface{}) *objectAny { | ||
148 | return &objectAny{baseAny{}, nil, reflect.ValueOf(val)} | ||
149 | } | ||
150 | |||
151 | func (any *objectAny) ValueType() ValueType { | ||
152 | return ObjectValue | ||
153 | } | ||
154 | |||
155 | func (any *objectAny) MustBeValid() Any { | ||
156 | return any | ||
157 | } | ||
158 | |||
159 | func (any *objectAny) Parse() *Iterator { | ||
160 | return nil | ||
161 | } | ||
162 | |||
163 | func (any *objectAny) LastError() error { | ||
164 | return any.err | ||
165 | } | ||
166 | |||
167 | func (any *objectAny) ToBool() bool { | ||
168 | return any.val.NumField() != 0 | ||
169 | } | ||
170 | |||
171 | func (any *objectAny) ToInt() int { | ||
172 | return 0 | ||
173 | } | ||
174 | |||
175 | func (any *objectAny) ToInt32() int32 { | ||
176 | return 0 | ||
177 | } | ||
178 | |||
179 | func (any *objectAny) ToInt64() int64 { | ||
180 | return 0 | ||
181 | } | ||
182 | |||
183 | func (any *objectAny) ToUint() uint { | ||
184 | return 0 | ||
185 | } | ||
186 | |||
187 | func (any *objectAny) ToUint32() uint32 { | ||
188 | return 0 | ||
189 | } | ||
190 | |||
191 | func (any *objectAny) ToUint64() uint64 { | ||
192 | return 0 | ||
193 | } | ||
194 | |||
195 | func (any *objectAny) ToFloat32() float32 { | ||
196 | return 0 | ||
197 | } | ||
198 | |||
199 | func (any *objectAny) ToFloat64() float64 { | ||
200 | return 0 | ||
201 | } | ||
202 | |||
203 | func (any *objectAny) ToString() string { | ||
204 | str, err := MarshalToString(any.val.Interface()) | ||
205 | any.err = err | ||
206 | return str | ||
207 | } | ||
208 | |||
209 | func (any *objectAny) Get(path ...interface{}) Any { | ||
210 | if len(path) == 0 { | ||
211 | return any | ||
212 | } | ||
213 | switch firstPath := path[0].(type) { | ||
214 | case string: | ||
215 | field := any.val.FieldByName(firstPath) | ||
216 | if !field.IsValid() { | ||
217 | return newInvalidAny(path) | ||
218 | } | ||
219 | return Wrap(field.Interface()) | ||
220 | case int32: | ||
221 | if '*' == firstPath { | ||
222 | mappedAll := map[string]Any{} | ||
223 | for i := 0; i < any.val.NumField(); i++ { | ||
224 | field := any.val.Field(i) | ||
225 | if field.CanInterface() { | ||
226 | mapped := Wrap(field.Interface()).Get(path[1:]...) | ||
227 | if mapped.ValueType() != InvalidValue { | ||
228 | mappedAll[any.val.Type().Field(i).Name] = mapped | ||
229 | } | ||
230 | } | ||
231 | } | ||
232 | return wrapMap(mappedAll) | ||
233 | } | ||
234 | return newInvalidAny(path) | ||
235 | default: | ||
236 | return newInvalidAny(path) | ||
237 | } | ||
238 | } | ||
239 | |||
240 | func (any *objectAny) Keys() []string { | ||
241 | keys := make([]string, 0, any.val.NumField()) | ||
242 | for i := 0; i < any.val.NumField(); i++ { | ||
243 | keys = append(keys, any.val.Type().Field(i).Name) | ||
244 | } | ||
245 | return keys | ||
246 | } | ||
247 | |||
248 | func (any *objectAny) Size() int { | ||
249 | return any.val.NumField() | ||
250 | } | ||
251 | |||
252 | func (any *objectAny) WriteTo(stream *Stream) { | ||
253 | stream.WriteVal(any.val) | ||
254 | } | ||
255 | |||
256 | func (any *objectAny) GetInterface() interface{} { | ||
257 | return any.val.Interface() | ||
258 | } | ||
259 | |||
260 | type mapAny struct { | ||
261 | baseAny | ||
262 | err error | ||
263 | val reflect.Value | ||
264 | } | ||
265 | |||
266 | func wrapMap(val interface{}) *mapAny { | ||
267 | return &mapAny{baseAny{}, nil, reflect.ValueOf(val)} | ||
268 | } | ||
269 | |||
270 | func (any *mapAny) ValueType() ValueType { | ||
271 | return ObjectValue | ||
272 | } | ||
273 | |||
274 | func (any *mapAny) MustBeValid() Any { | ||
275 | return any | ||
276 | } | ||
277 | |||
278 | func (any *mapAny) Parse() *Iterator { | ||
279 | return nil | ||
280 | } | ||
281 | |||
282 | func (any *mapAny) LastError() error { | ||
283 | return any.err | ||
284 | } | ||
285 | |||
286 | func (any *mapAny) ToBool() bool { | ||
287 | return true | ||
288 | } | ||
289 | |||
290 | func (any *mapAny) ToInt() int { | ||
291 | return 0 | ||
292 | } | ||
293 | |||
294 | func (any *mapAny) ToInt32() int32 { | ||
295 | return 0 | ||
296 | } | ||
297 | |||
298 | func (any *mapAny) ToInt64() int64 { | ||
299 | return 0 | ||
300 | } | ||
301 | |||
302 | func (any *mapAny) ToUint() uint { | ||
303 | return 0 | ||
304 | } | ||
305 | |||
306 | func (any *mapAny) ToUint32() uint32 { | ||
307 | return 0 | ||
308 | } | ||
309 | |||
310 | func (any *mapAny) ToUint64() uint64 { | ||
311 | return 0 | ||
312 | } | ||
313 | |||
314 | func (any *mapAny) ToFloat32() float32 { | ||
315 | return 0 | ||
316 | } | ||
317 | |||
318 | func (any *mapAny) ToFloat64() float64 { | ||
319 | return 0 | ||
320 | } | ||
321 | |||
322 | func (any *mapAny) ToString() string { | ||
323 | str, err := MarshalToString(any.val.Interface()) | ||
324 | any.err = err | ||
325 | return str | ||
326 | } | ||
327 | |||
328 | func (any *mapAny) Get(path ...interface{}) Any { | ||
329 | if len(path) == 0 { | ||
330 | return any | ||
331 | } | ||
332 | switch firstPath := path[0].(type) { | ||
333 | case int32: | ||
334 | if '*' == firstPath { | ||
335 | mappedAll := map[string]Any{} | ||
336 | for _, key := range any.val.MapKeys() { | ||
337 | keyAsStr := key.String() | ||
338 | element := Wrap(any.val.MapIndex(key).Interface()) | ||
339 | mapped := element.Get(path[1:]...) | ||
340 | if mapped.ValueType() != InvalidValue { | ||
341 | mappedAll[keyAsStr] = mapped | ||
342 | } | ||
343 | } | ||
344 | return wrapMap(mappedAll) | ||
345 | } | ||
346 | return newInvalidAny(path) | ||
347 | default: | ||
348 | value := any.val.MapIndex(reflect.ValueOf(firstPath)) | ||
349 | if !value.IsValid() { | ||
350 | return newInvalidAny(path) | ||
351 | } | ||
352 | return Wrap(value.Interface()) | ||
353 | } | ||
354 | } | ||
355 | |||
356 | func (any *mapAny) Keys() []string { | ||
357 | keys := make([]string, 0, any.val.Len()) | ||
358 | for _, key := range any.val.MapKeys() { | ||
359 | keys = append(keys, key.String()) | ||
360 | } | ||
361 | return keys | ||
362 | } | ||
363 | |||
364 | func (any *mapAny) Size() int { | ||
365 | return any.val.Len() | ||
366 | } | ||
367 | |||
368 | func (any *mapAny) WriteTo(stream *Stream) { | ||
369 | stream.WriteVal(any.val) | ||
370 | } | ||
371 | |||
372 | func (any *mapAny) GetInterface() interface{} { | ||
373 | return any.val.Interface() | ||
374 | } | ||
diff --git a/vendor/github.com/json-iterator/go/any_str.go b/vendor/github.com/json-iterator/go/any_str.go deleted file mode 100644 index 1f12f66..0000000 --- a/vendor/github.com/json-iterator/go/any_str.go +++ /dev/null | |||
@@ -1,166 +0,0 @@ | |||
1 | package jsoniter | ||
2 | |||
3 | import ( | ||
4 | "fmt" | ||
5 | "strconv" | ||
6 | ) | ||
7 | |||
8 | type stringAny struct { | ||
9 | baseAny | ||
10 | val string | ||
11 | } | ||
12 | |||
13 | func (any *stringAny) Get(path ...interface{}) Any { | ||
14 | if len(path) == 0 { | ||
15 | return any | ||
16 | } | ||
17 | return &invalidAny{baseAny{}, fmt.Errorf("GetIndex %v from simple value", path)} | ||
18 | } | ||
19 | |||
20 | func (any *stringAny) Parse() *Iterator { | ||
21 | return nil | ||
22 | } | ||
23 | |||
24 | func (any *stringAny) ValueType() ValueType { | ||
25 | return StringValue | ||
26 | } | ||
27 | |||
28 | func (any *stringAny) MustBeValid() Any { | ||
29 | return any | ||
30 | } | ||
31 | |||
32 | func (any *stringAny) LastError() error { | ||
33 | return nil | ||
34 | } | ||
35 | |||
36 | func (any *stringAny) ToBool() bool { | ||
37 | str := any.ToString() | ||
38 | if str == "0" { | ||
39 | return false | ||
40 | } | ||
41 | for _, c := range str { | ||
42 | switch c { | ||
43 | case ' ', '\n', '\r', '\t': | ||
44 | default: | ||
45 | return true | ||
46 | } | ||
47 | } | ||
48 | return false | ||
49 | } | ||
50 | |||
51 | func (any *stringAny) ToInt() int { | ||
52 | return int(any.ToInt64()) | ||
53 | |||
54 | } | ||
55 | |||
56 | func (any *stringAny) ToInt32() int32 { | ||
57 | return int32(any.ToInt64()) | ||
58 | } | ||
59 | |||
60 | func (any *stringAny) ToInt64() int64 { | ||
61 | if any.val == "" { | ||
62 | return 0 | ||
63 | } | ||
64 | |||
65 | flag := 1 | ||
66 | startPos := 0 | ||
67 | if any.val[0] == '+' || any.val[0] == '-' { | ||
68 | startPos = 1 | ||
69 | } | ||
70 | |||
71 | if any.val[0] == '-' { | ||
72 | flag = -1 | ||
73 | } | ||
74 | |||
75 | endPos := startPos | ||
76 | for i := startPos; i < len(any.val); i++ { | ||
77 | if any.val[i] >= '0' && any.val[i] <= '9' { | ||
78 | endPos = i + 1 | ||
79 | } else { | ||
80 | break | ||
81 | } | ||
82 | } | ||
83 | parsed, _ := strconv.ParseInt(any.val[startPos:endPos], 10, 64) | ||
84 | return int64(flag) * parsed | ||
85 | } | ||
86 | |||
87 | func (any *stringAny) ToUint() uint { | ||
88 | return uint(any.ToUint64()) | ||
89 | } | ||
90 | |||
91 | func (any *stringAny) ToUint32() uint32 { | ||
92 | return uint32(any.ToUint64()) | ||
93 | } | ||
94 | |||
95 | func (any *stringAny) ToUint64() uint64 { | ||
96 | if any.val == "" { | ||
97 | return 0 | ||
98 | } | ||
99 | |||
100 | startPos := 0 | ||
101 | |||
102 | if any.val[0] == '-' { | ||
103 | return 0 | ||
104 | } | ||
105 | if any.val[0] == '+' { | ||
106 | startPos = 1 | ||
107 | } | ||
108 | |||
109 | endPos := startPos | ||
110 | for i := startPos; i < len(any.val); i++ { | ||
111 | if any.val[i] >= '0' && any.val[i] <= '9' { | ||
112 | endPos = i + 1 | ||
113 | } else { | ||
114 | break | ||
115 | } | ||
116 | } | ||
117 | parsed, _ := strconv.ParseUint(any.val[startPos:endPos], 10, 64) | ||
118 | return parsed | ||
119 | } | ||
120 | |||
121 | func (any *stringAny) ToFloat32() float32 { | ||
122 | return float32(any.ToFloat64()) | ||
123 | } | ||
124 | |||
125 | func (any *stringAny) ToFloat64() float64 { | ||
126 | if len(any.val) == 0 { | ||
127 | return 0 | ||
128 | } | ||
129 | |||
130 | // first char invalid | ||
131 | if any.val[0] != '+' && any.val[0] != '-' && (any.val[0] > '9' || any.val[0] < '0') { | ||
132 | return 0 | ||
133 | } | ||
134 | |||
135 | // extract valid num expression from string | ||
136 | // eg 123true => 123, -12.12xxa => -12.12 | ||
137 | endPos := 1 | ||
138 | for i := 1; i < len(any.val); i++ { | ||
139 | if any.val[i] == '.' || any.val[i] == 'e' || any.val[i] == 'E' || any.val[i] == '+' || any.val[i] == '-' { | ||
140 | endPos = i + 1 | ||
141 | continue | ||
142 | } | ||
143 | |||
144 | // end position is the first char which is not digit | ||
145 | if any.val[i] >= '0' && any.val[i] <= '9' { | ||
146 | endPos = i + 1 | ||
147 | } else { | ||
148 | endPos = i | ||
149 | break | ||
150 | } | ||
151 | } | ||
152 | parsed, _ := strconv.ParseFloat(any.val[:endPos], 64) | ||
153 | return parsed | ||
154 | } | ||
155 | |||
156 | func (any *stringAny) ToString() string { | ||
157 | return any.val | ||
158 | } | ||
159 | |||
160 | func (any *stringAny) WriteTo(stream *Stream) { | ||
161 | stream.WriteString(any.val) | ||
162 | } | ||
163 | |||
164 | func (any *stringAny) GetInterface() interface{} { | ||
165 | return any.val | ||
166 | } | ||
diff --git a/vendor/github.com/json-iterator/go/any_uint32.go b/vendor/github.com/json-iterator/go/any_uint32.go deleted file mode 100644 index 656bbd3..0000000 --- a/vendor/github.com/json-iterator/go/any_uint32.go +++ /dev/null | |||
@@ -1,74 +0,0 @@ | |||
1 | package jsoniter | ||
2 | |||
3 | import ( | ||
4 | "strconv" | ||
5 | ) | ||
6 | |||
7 | type uint32Any struct { | ||
8 | baseAny | ||
9 | val uint32 | ||
10 | } | ||
11 | |||
12 | func (any *uint32Any) LastError() error { | ||
13 | return nil | ||
14 | } | ||
15 | |||
16 | func (any *uint32Any) ValueType() ValueType { | ||
17 | return NumberValue | ||
18 | } | ||
19 | |||
20 | func (any *uint32Any) MustBeValid() Any { | ||
21 | return any | ||
22 | } | ||
23 | |||
24 | func (any *uint32Any) ToBool() bool { | ||
25 | return any.val != 0 | ||
26 | } | ||
27 | |||
28 | func (any *uint32Any) ToInt() int { | ||
29 | return int(any.val) | ||
30 | } | ||
31 | |||
32 | func (any *uint32Any) ToInt32() int32 { | ||
33 | return int32(any.val) | ||
34 | } | ||
35 | |||
36 | func (any *uint32Any) ToInt64() int64 { | ||
37 | return int64(any.val) | ||
38 | } | ||
39 | |||
40 | func (any *uint32Any) ToUint() uint { | ||
41 | return uint(any.val) | ||
42 | } | ||
43 | |||
44 | func (any *uint32Any) ToUint32() uint32 { | ||
45 | return any.val | ||
46 | } | ||
47 | |||
48 | func (any *uint32Any) ToUint64() uint64 { | ||
49 | return uint64(any.val) | ||
50 | } | ||
51 | |||
52 | func (any *uint32Any) ToFloat32() float32 { | ||
53 | return float32(any.val) | ||
54 | } | ||
55 | |||
56 | func (any *uint32Any) ToFloat64() float64 { | ||
57 | return float64(any.val) | ||
58 | } | ||
59 | |||
60 | func (any *uint32Any) ToString() string { | ||
61 | return strconv.FormatInt(int64(any.val), 10) | ||
62 | } | ||
63 | |||
64 | func (any *uint32Any) WriteTo(stream *Stream) { | ||
65 | stream.WriteUint32(any.val) | ||
66 | } | ||
67 | |||
68 | func (any *uint32Any) Parse() *Iterator { | ||
69 | return nil | ||
70 | } | ||
71 | |||
72 | func (any *uint32Any) GetInterface() interface{} { | ||
73 | return any.val | ||
74 | } | ||
diff --git a/vendor/github.com/json-iterator/go/any_uint64.go b/vendor/github.com/json-iterator/go/any_uint64.go deleted file mode 100644 index 7df2fce..0000000 --- a/vendor/github.com/json-iterator/go/any_uint64.go +++ /dev/null | |||
@@ -1,74 +0,0 @@ | |||
1 | package jsoniter | ||
2 | |||
3 | import ( | ||
4 | "strconv" | ||
5 | ) | ||
6 | |||
7 | type uint64Any struct { | ||
8 | baseAny | ||
9 | val uint64 | ||
10 | } | ||
11 | |||
12 | func (any *uint64Any) LastError() error { | ||
13 | return nil | ||
14 | } | ||
15 | |||
16 | func (any *uint64Any) ValueType() ValueType { | ||
17 | return NumberValue | ||
18 | } | ||
19 | |||
20 | func (any *uint64Any) MustBeValid() Any { | ||
21 | return any | ||
22 | } | ||
23 | |||
24 | func (any *uint64Any) ToBool() bool { | ||
25 | return any.val != 0 | ||
26 | } | ||
27 | |||
28 | func (any *uint64Any) ToInt() int { | ||
29 | return int(any.val) | ||
30 | } | ||
31 | |||
32 | func (any *uint64Any) ToInt32() int32 { | ||
33 | return int32(any.val) | ||
34 | } | ||
35 | |||
36 | func (any *uint64Any) ToInt64() int64 { | ||
37 | return int64(any.val) | ||
38 | } | ||
39 | |||
40 | func (any *uint64Any) ToUint() uint { | ||
41 | return uint(any.val) | ||
42 | } | ||
43 | |||
44 | func (any *uint64Any) ToUint32() uint32 { | ||
45 | return uint32(any.val) | ||
46 | } | ||
47 | |||
48 | func (any *uint64Any) ToUint64() uint64 { | ||
49 | return any.val | ||
50 | } | ||
51 | |||
52 | func (any *uint64Any) ToFloat32() float32 { | ||
53 | return float32(any.val) | ||
54 | } | ||
55 | |||
56 | func (any *uint64Any) ToFloat64() float64 { | ||
57 | return float64(any.val) | ||
58 | } | ||
59 | |||
60 | func (any *uint64Any) ToString() string { | ||
61 | return strconv.FormatUint(any.val, 10) | ||
62 | } | ||
63 | |||
64 | func (any *uint64Any) WriteTo(stream *Stream) { | ||
65 | stream.WriteUint64(any.val) | ||
66 | } | ||
67 | |||
68 | func (any *uint64Any) Parse() *Iterator { | ||
69 | return nil | ||
70 | } | ||
71 | |||
72 | func (any *uint64Any) GetInterface() interface{} { | ||
73 | return any.val | ||
74 | } | ||
diff --git a/vendor/github.com/json-iterator/go/build.sh b/vendor/github.com/json-iterator/go/build.sh deleted file mode 100644 index b45ef68..0000000 --- a/vendor/github.com/json-iterator/go/build.sh +++ /dev/null | |||
@@ -1,12 +0,0 @@ | |||
1 | #!/bin/bash | ||
2 | set -e | ||
3 | set -x | ||
4 | |||
5 | if [ ! -d /tmp/build-golang/src/github.com/json-iterator ]; then | ||
6 | mkdir -p /tmp/build-golang/src/github.com/json-iterator | ||
7 | ln -s $PWD /tmp/build-golang/src/github.com/json-iterator/go | ||
8 | fi | ||
9 | export GOPATH=/tmp/build-golang | ||
10 | go get -u github.com/golang/dep/cmd/dep | ||
11 | cd /tmp/build-golang/src/github.com/json-iterator/go | ||
12 | exec $GOPATH/bin/dep ensure -update | ||
diff --git a/vendor/github.com/json-iterator/go/config.go b/vendor/github.com/json-iterator/go/config.go deleted file mode 100644 index 2adcdc3..0000000 --- a/vendor/github.com/json-iterator/go/config.go +++ /dev/null | |||
@@ -1,375 +0,0 @@ | |||
1 | package jsoniter | ||
2 | |||
3 | import ( | ||
4 | "encoding/json" | ||
5 | "io" | ||
6 | "reflect" | ||
7 | "sync" | ||
8 | "unsafe" | ||
9 | |||
10 | "github.com/modern-go/concurrent" | ||
11 | "github.com/modern-go/reflect2" | ||
12 | ) | ||
13 | |||
14 | // Config customize how the API should behave. | ||
15 | // The API is created from Config by Froze. | ||
16 | type Config struct { | ||
17 | IndentionStep int | ||
18 | MarshalFloatWith6Digits bool | ||
19 | EscapeHTML bool | ||
20 | SortMapKeys bool | ||
21 | UseNumber bool | ||
22 | DisallowUnknownFields bool | ||
23 | TagKey string | ||
24 | OnlyTaggedField bool | ||
25 | ValidateJsonRawMessage bool | ||
26 | ObjectFieldMustBeSimpleString bool | ||
27 | CaseSensitive bool | ||
28 | } | ||
29 | |||
30 | // API the public interface of this package. | ||
31 | // Primary Marshal and Unmarshal. | ||
32 | type API interface { | ||
33 | IteratorPool | ||
34 | StreamPool | ||
35 | MarshalToString(v interface{}) (string, error) | ||
36 | Marshal(v interface{}) ([]byte, error) | ||
37 | MarshalIndent(v interface{}, prefix, indent string) ([]byte, error) | ||
38 | UnmarshalFromString(str string, v interface{}) error | ||
39 | Unmarshal(data []byte, v interface{}) error | ||
40 | Get(data []byte, path ...interface{}) Any | ||
41 | NewEncoder(writer io.Writer) *Encoder | ||
42 | NewDecoder(reader io.Reader) *Decoder | ||
43 | Valid(data []byte) bool | ||
44 | RegisterExtension(extension Extension) | ||
45 | DecoderOf(typ reflect2.Type) ValDecoder | ||
46 | EncoderOf(typ reflect2.Type) ValEncoder | ||
47 | } | ||
48 | |||
49 | // ConfigDefault the default API | ||
50 | var ConfigDefault = Config{ | ||
51 | EscapeHTML: true, | ||
52 | }.Froze() | ||
53 | |||
54 | // ConfigCompatibleWithStandardLibrary tries to be 100% compatible with standard library behavior | ||
55 | var ConfigCompatibleWithStandardLibrary = Config{ | ||
56 | EscapeHTML: true, | ||
57 | SortMapKeys: true, | ||
58 | ValidateJsonRawMessage: true, | ||
59 | }.Froze() | ||
60 | |||
61 | // ConfigFastest marshals float with only 6 digits precision | ||
62 | var ConfigFastest = Config{ | ||
63 | EscapeHTML: false, | ||
64 | MarshalFloatWith6Digits: true, // will lose precession | ||
65 | ObjectFieldMustBeSimpleString: true, // do not unescape object field | ||
66 | }.Froze() | ||
67 | |||
68 | type frozenConfig struct { | ||
69 | configBeforeFrozen Config | ||
70 | sortMapKeys bool | ||
71 | indentionStep int | ||
72 | objectFieldMustBeSimpleString bool | ||
73 | onlyTaggedField bool | ||
74 | disallowUnknownFields bool | ||
75 | decoderCache *concurrent.Map | ||
76 | encoderCache *concurrent.Map | ||
77 | encoderExtension Extension | ||
78 | decoderExtension Extension | ||
79 | extraExtensions []Extension | ||
80 | streamPool *sync.Pool | ||
81 | iteratorPool *sync.Pool | ||
82 | caseSensitive bool | ||
83 | } | ||
84 | |||
85 | func (cfg *frozenConfig) initCache() { | ||
86 | cfg.decoderCache = concurrent.NewMap() | ||
87 | cfg.encoderCache = concurrent.NewMap() | ||
88 | } | ||
89 | |||
90 | func (cfg *frozenConfig) addDecoderToCache(cacheKey uintptr, decoder ValDecoder) { | ||
91 | cfg.decoderCache.Store(cacheKey, decoder) | ||
92 | } | ||
93 | |||
94 | func (cfg *frozenConfig) addEncoderToCache(cacheKey uintptr, encoder ValEncoder) { | ||
95 | cfg.encoderCache.Store(cacheKey, encoder) | ||
96 | } | ||
97 | |||
98 | func (cfg *frozenConfig) getDecoderFromCache(cacheKey uintptr) ValDecoder { | ||
99 | decoder, found := cfg.decoderCache.Load(cacheKey) | ||
100 | if found { | ||
101 | return decoder.(ValDecoder) | ||
102 | } | ||
103 | return nil | ||
104 | } | ||
105 | |||
106 | func (cfg *frozenConfig) getEncoderFromCache(cacheKey uintptr) ValEncoder { | ||
107 | encoder, found := cfg.encoderCache.Load(cacheKey) | ||
108 | if found { | ||
109 | return encoder.(ValEncoder) | ||
110 | } | ||
111 | return nil | ||
112 | } | ||
113 | |||
114 | var cfgCache = concurrent.NewMap() | ||
115 | |||
116 | func getFrozenConfigFromCache(cfg Config) *frozenConfig { | ||
117 | obj, found := cfgCache.Load(cfg) | ||
118 | if found { | ||
119 | return obj.(*frozenConfig) | ||
120 | } | ||
121 | return nil | ||
122 | } | ||
123 | |||
124 | func addFrozenConfigToCache(cfg Config, frozenConfig *frozenConfig) { | ||
125 | cfgCache.Store(cfg, frozenConfig) | ||
126 | } | ||
127 | |||
128 | // Froze forge API from config | ||
129 | func (cfg Config) Froze() API { | ||
130 | api := &frozenConfig{ | ||
131 | sortMapKeys: cfg.SortMapKeys, | ||
132 | indentionStep: cfg.IndentionStep, | ||
133 | objectFieldMustBeSimpleString: cfg.ObjectFieldMustBeSimpleString, | ||
134 | onlyTaggedField: cfg.OnlyTaggedField, | ||
135 | disallowUnknownFields: cfg.DisallowUnknownFields, | ||
136 | caseSensitive: cfg.CaseSensitive, | ||
137 | } | ||
138 | api.streamPool = &sync.Pool{ | ||
139 | New: func() interface{} { | ||
140 | return NewStream(api, nil, 512) | ||
141 | }, | ||
142 | } | ||
143 | api.iteratorPool = &sync.Pool{ | ||
144 | New: func() interface{} { | ||
145 | return NewIterator(api) | ||
146 | }, | ||
147 | } | ||
148 | api.initCache() | ||
149 | encoderExtension := EncoderExtension{} | ||
150 | decoderExtension := DecoderExtension{} | ||
151 | if cfg.MarshalFloatWith6Digits { | ||
152 | api.marshalFloatWith6Digits(encoderExtension) | ||
153 | } | ||
154 | if cfg.EscapeHTML { | ||
155 | api.escapeHTML(encoderExtension) | ||
156 | } | ||
157 | if cfg.UseNumber { | ||
158 | api.useNumber(decoderExtension) | ||
159 | } | ||
160 | if cfg.ValidateJsonRawMessage { | ||
161 | api.validateJsonRawMessage(encoderExtension) | ||
162 | } | ||
163 | api.encoderExtension = encoderExtension | ||
164 | api.decoderExtension = decoderExtension | ||
165 | api.configBeforeFrozen = cfg | ||
166 | return api | ||
167 | } | ||
168 | |||
169 | func (cfg Config) frozeWithCacheReuse(extraExtensions []Extension) *frozenConfig { | ||
170 | api := getFrozenConfigFromCache(cfg) | ||
171 | if api != nil { | ||
172 | return api | ||
173 | } | ||
174 | api = cfg.Froze().(*frozenConfig) | ||
175 | for _, extension := range extraExtensions { | ||
176 | api.RegisterExtension(extension) | ||
177 | } | ||
178 | addFrozenConfigToCache(cfg, api) | ||
179 | return api | ||
180 | } | ||
181 | |||
182 | func (cfg *frozenConfig) validateJsonRawMessage(extension EncoderExtension) { | ||
183 | encoder := &funcEncoder{func(ptr unsafe.Pointer, stream *Stream) { | ||
184 | rawMessage := *(*json.RawMessage)(ptr) | ||
185 | iter := cfg.BorrowIterator([]byte(rawMessage)) | ||
186 | defer cfg.ReturnIterator(iter) | ||
187 | iter.Read() | ||
188 | if iter.Error != nil && iter.Error != io.EOF { | ||
189 | stream.WriteRaw("null") | ||
190 | } else { | ||
191 | stream.WriteRaw(string(rawMessage)) | ||
192 | } | ||
193 | }, func(ptr unsafe.Pointer) bool { | ||
194 | return len(*((*json.RawMessage)(ptr))) == 0 | ||
195 | }} | ||
196 | extension[reflect2.TypeOfPtr((*json.RawMessage)(nil)).Elem()] = encoder | ||
197 | extension[reflect2.TypeOfPtr((*RawMessage)(nil)).Elem()] = encoder | ||
198 | } | ||
199 | |||
200 | func (cfg *frozenConfig) useNumber(extension DecoderExtension) { | ||
201 | extension[reflect2.TypeOfPtr((*interface{})(nil)).Elem()] = &funcDecoder{func(ptr unsafe.Pointer, iter *Iterator) { | ||
202 | exitingValue := *((*interface{})(ptr)) | ||
203 | if exitingValue != nil && reflect.TypeOf(exitingValue).Kind() == reflect.Ptr { | ||
204 | iter.ReadVal(exitingValue) | ||
205 | return | ||
206 | } | ||
207 | if iter.WhatIsNext() == NumberValue { | ||
208 | *((*interface{})(ptr)) = json.Number(iter.readNumberAsString()) | ||
209 | } else { | ||
210 | *((*interface{})(ptr)) = iter.Read() | ||
211 | } | ||
212 | }} | ||
213 | } | ||
214 | func (cfg *frozenConfig) getTagKey() string { | ||
215 | tagKey := cfg.configBeforeFrozen.TagKey | ||
216 | if tagKey == "" { | ||
217 | return "json" | ||
218 | } | ||
219 | return tagKey | ||
220 | } | ||
221 | |||
222 | func (cfg *frozenConfig) RegisterExtension(extension Extension) { | ||
223 | cfg.extraExtensions = append(cfg.extraExtensions, extension) | ||
224 | copied := cfg.configBeforeFrozen | ||
225 | cfg.configBeforeFrozen = copied | ||
226 | } | ||
227 | |||
228 | type lossyFloat32Encoder struct { | ||
229 | } | ||
230 | |||
231 | func (encoder *lossyFloat32Encoder) Encode(ptr unsafe.Pointer, stream *Stream) { | ||
232 | stream.WriteFloat32Lossy(*((*float32)(ptr))) | ||
233 | } | ||
234 | |||
235 | func (encoder *lossyFloat32Encoder) IsEmpty(ptr unsafe.Pointer) bool { | ||
236 | return *((*float32)(ptr)) == 0 | ||
237 | } | ||
238 | |||
239 | type lossyFloat64Encoder struct { | ||
240 | } | ||
241 | |||
242 | func (encoder *lossyFloat64Encoder) Encode(ptr unsafe.Pointer, stream *Stream) { | ||
243 | stream.WriteFloat64Lossy(*((*float64)(ptr))) | ||
244 | } | ||
245 | |||
246 | func (encoder *lossyFloat64Encoder) IsEmpty(ptr unsafe.Pointer) bool { | ||
247 | return *((*float64)(ptr)) == 0 | ||
248 | } | ||
249 | |||
250 | // EnableLossyFloatMarshalling keeps 10**(-6) precision | ||
251 | // for float variables for better performance. | ||
252 | func (cfg *frozenConfig) marshalFloatWith6Digits(extension EncoderExtension) { | ||
253 | // for better performance | ||
254 | extension[reflect2.TypeOfPtr((*float32)(nil)).Elem()] = &lossyFloat32Encoder{} | ||
255 | extension[reflect2.TypeOfPtr((*float64)(nil)).Elem()] = &lossyFloat64Encoder{} | ||
256 | } | ||
257 | |||
258 | type htmlEscapedStringEncoder struct { | ||
259 | } | ||
260 | |||
261 | func (encoder *htmlEscapedStringEncoder) Encode(ptr unsafe.Pointer, stream *Stream) { | ||
262 | str := *((*string)(ptr)) | ||
263 | stream.WriteStringWithHTMLEscaped(str) | ||
264 | } | ||
265 | |||
266 | func (encoder *htmlEscapedStringEncoder) IsEmpty(ptr unsafe.Pointer) bool { | ||
267 | return *((*string)(ptr)) == "" | ||
268 | } | ||
269 | |||
270 | func (cfg *frozenConfig) escapeHTML(encoderExtension EncoderExtension) { | ||
271 | encoderExtension[reflect2.TypeOfPtr((*string)(nil)).Elem()] = &htmlEscapedStringEncoder{} | ||
272 | } | ||
273 | |||
274 | func (cfg *frozenConfig) cleanDecoders() { | ||
275 | typeDecoders = map[string]ValDecoder{} | ||
276 | fieldDecoders = map[string]ValDecoder{} | ||
277 | *cfg = *(cfg.configBeforeFrozen.Froze().(*frozenConfig)) | ||
278 | } | ||
279 | |||
280 | func (cfg *frozenConfig) cleanEncoders() { | ||
281 | typeEncoders = map[string]ValEncoder{} | ||
282 | fieldEncoders = map[string]ValEncoder{} | ||
283 | *cfg = *(cfg.configBeforeFrozen.Froze().(*frozenConfig)) | ||
284 | } | ||
285 | |||
286 | func (cfg *frozenConfig) MarshalToString(v interface{}) (string, error) { | ||
287 | stream := cfg.BorrowStream(nil) | ||
288 | defer cfg.ReturnStream(stream) | ||
289 | stream.WriteVal(v) | ||
290 | if stream.Error != nil { | ||
291 | return "", stream.Error | ||
292 | } | ||
293 | return string(stream.Buffer()), nil | ||
294 | } | ||
295 | |||
296 | func (cfg *frozenConfig) Marshal(v interface{}) ([]byte, error) { | ||
297 | stream := cfg.BorrowStream(nil) | ||
298 | defer cfg.ReturnStream(stream) | ||
299 | stream.WriteVal(v) | ||
300 | if stream.Error != nil { | ||
301 | return nil, stream.Error | ||
302 | } | ||
303 | result := stream.Buffer() | ||
304 | copied := make([]byte, len(result)) | ||
305 | copy(copied, result) | ||
306 | return copied, nil | ||
307 | } | ||
308 | |||
309 | func (cfg *frozenConfig) MarshalIndent(v interface{}, prefix, indent string) ([]byte, error) { | ||
310 | if prefix != "" { | ||
311 | panic("prefix is not supported") | ||
312 | } | ||
313 | for _, r := range indent { | ||
314 | if r != ' ' { | ||
315 | panic("indent can only be space") | ||
316 | } | ||
317 | } | ||
318 | newCfg := cfg.configBeforeFrozen | ||
319 | newCfg.IndentionStep = len(indent) | ||
320 | return newCfg.frozeWithCacheReuse(cfg.extraExtensions).Marshal(v) | ||
321 | } | ||
322 | |||
323 | func (cfg *frozenConfig) UnmarshalFromString(str string, v interface{}) error { | ||
324 | data := []byte(str) | ||
325 | iter := cfg.BorrowIterator(data) | ||
326 | defer cfg.ReturnIterator(iter) | ||
327 | iter.ReadVal(v) | ||
328 | c := iter.nextToken() | ||
329 | if c == 0 { | ||
330 | if iter.Error == io.EOF { | ||
331 | return nil | ||
332 | } | ||
333 | return iter.Error | ||
334 | } | ||
335 | iter.ReportError("Unmarshal", "there are bytes left after unmarshal") | ||
336 | return iter.Error | ||
337 | } | ||
338 | |||
339 | func (cfg *frozenConfig) Get(data []byte, path ...interface{}) Any { | ||
340 | iter := cfg.BorrowIterator(data) | ||
341 | defer cfg.ReturnIterator(iter) | ||
342 | return locatePath(iter, path) | ||
343 | } | ||
344 | |||
345 | func (cfg *frozenConfig) Unmarshal(data []byte, v interface{}) error { | ||
346 | iter := cfg.BorrowIterator(data) | ||
347 | defer cfg.ReturnIterator(iter) | ||
348 | iter.ReadVal(v) | ||
349 | c := iter.nextToken() | ||
350 | if c == 0 { | ||
351 | if iter.Error == io.EOF { | ||
352 | return nil | ||
353 | } | ||
354 | return iter.Error | ||
355 | } | ||
356 | iter.ReportError("Unmarshal", "there are bytes left after unmarshal") | ||
357 | return iter.Error | ||
358 | } | ||
359 | |||
360 | func (cfg *frozenConfig) NewEncoder(writer io.Writer) *Encoder { | ||
361 | stream := NewStream(cfg, writer, 512) | ||
362 | return &Encoder{stream} | ||
363 | } | ||
364 | |||
365 | func (cfg *frozenConfig) NewDecoder(reader io.Reader) *Decoder { | ||
366 | iter := Parse(cfg, reader, 512) | ||
367 | return &Decoder{iter} | ||
368 | } | ||
369 | |||
370 | func (cfg *frozenConfig) Valid(data []byte) bool { | ||
371 | iter := cfg.BorrowIterator(data) | ||
372 | defer cfg.ReturnIterator(iter) | ||
373 | iter.Skip() | ||
374 | return iter.Error == nil | ||
375 | } | ||
diff --git a/vendor/github.com/json-iterator/go/fuzzy_mode_convert_table.md b/vendor/github.com/json-iterator/go/fuzzy_mode_convert_table.md deleted file mode 100644 index 3095662..0000000 --- a/vendor/github.com/json-iterator/go/fuzzy_mode_convert_table.md +++ /dev/null | |||
@@ -1,7 +0,0 @@ | |||
1 | | json type \ dest type | bool | int | uint | float |string| | ||
2 | | --- | --- | --- | --- |--|--| | ||
3 | | number | positive => true <br/> negative => true <br/> zero => false| 23.2 => 23 <br/> -32.1 => -32| 12.1 => 12 <br/> -12.1 => 0|as normal|same as origin| | ||
4 | | string | empty string => false <br/> string "0" => false <br/> other strings => true | "123.32" => 123 <br/> "-123.4" => -123 <br/> "123.23xxxw" => 123 <br/> "abcde12" => 0 <br/> "-32.1" => -32| 13.2 => 13 <br/> -1.1 => 0 |12.1 => 12.1 <br/> -12.3 => -12.3<br/> 12.4xxa => 12.4 <br/> +1.1e2 =>110 |same as origin| | ||
5 | | bool | true => true <br/> false => false| true => 1 <br/> false => 0 | true => 1 <br/> false => 0 |true => 1 <br/>false => 0|true => "true" <br/> false => "false"| | ||
6 | | object | true | 0 | 0 |0|originnal json| | ||
7 | | array | empty array => false <br/> nonempty array => true| [] => 0 <br/> [1,2] => 1 | [] => 0 <br/> [1,2] => 1 |[] => 0<br/>[1,2] => 1|original json| \ No newline at end of file | ||
diff --git a/vendor/github.com/json-iterator/go/iter.go b/vendor/github.com/json-iterator/go/iter.go deleted file mode 100644 index 29b31cf..0000000 --- a/vendor/github.com/json-iterator/go/iter.go +++ /dev/null | |||
@@ -1,349 +0,0 @@ | |||
1 | package jsoniter | ||
2 | |||
3 | import ( | ||
4 | "encoding/json" | ||
5 | "fmt" | ||
6 | "io" | ||
7 | ) | ||
8 | |||
9 | // ValueType the type for JSON element | ||
10 | type ValueType int | ||
11 | |||
12 | const ( | ||
13 | // InvalidValue invalid JSON element | ||
14 | InvalidValue ValueType = iota | ||
15 | // StringValue JSON element "string" | ||
16 | StringValue | ||
17 | // NumberValue JSON element 100 or 0.10 | ||
18 | NumberValue | ||
19 | // NilValue JSON element null | ||
20 | NilValue | ||
21 | // BoolValue JSON element true or false | ||
22 | BoolValue | ||
23 | // ArrayValue JSON element [] | ||
24 | ArrayValue | ||
25 | // ObjectValue JSON element {} | ||
26 | ObjectValue | ||
27 | ) | ||
28 | |||
29 | var hexDigits []byte | ||
30 | var valueTypes []ValueType | ||
31 | |||
32 | func init() { | ||
33 | hexDigits = make([]byte, 256) | ||
34 | for i := 0; i < len(hexDigits); i++ { | ||
35 | hexDigits[i] = 255 | ||
36 | } | ||
37 | for i := '0'; i <= '9'; i++ { | ||
38 | hexDigits[i] = byte(i - '0') | ||
39 | } | ||
40 | for i := 'a'; i <= 'f'; i++ { | ||
41 | hexDigits[i] = byte((i - 'a') + 10) | ||
42 | } | ||
43 | for i := 'A'; i <= 'F'; i++ { | ||
44 | hexDigits[i] = byte((i - 'A') + 10) | ||
45 | } | ||
46 | valueTypes = make([]ValueType, 256) | ||
47 | for i := 0; i < len(valueTypes); i++ { | ||
48 | valueTypes[i] = InvalidValue | ||
49 | } | ||
50 | valueTypes['"'] = StringValue | ||
51 | valueTypes['-'] = NumberValue | ||
52 | valueTypes['0'] = NumberValue | ||
53 | valueTypes['1'] = NumberValue | ||
54 | valueTypes['2'] = NumberValue | ||
55 | valueTypes['3'] = NumberValue | ||
56 | valueTypes['4'] = NumberValue | ||
57 | valueTypes['5'] = NumberValue | ||
58 | valueTypes['6'] = NumberValue | ||
59 | valueTypes['7'] = NumberValue | ||
60 | valueTypes['8'] = NumberValue | ||
61 | valueTypes['9'] = NumberValue | ||
62 | valueTypes['t'] = BoolValue | ||
63 | valueTypes['f'] = BoolValue | ||
64 | valueTypes['n'] = NilValue | ||
65 | valueTypes['['] = ArrayValue | ||
66 | valueTypes['{'] = ObjectValue | ||
67 | } | ||
68 | |||
69 | // Iterator is a io.Reader like object, with JSON specific read functions. | ||
70 | // Error is not returned as return value, but stored as Error member on this iterator instance. | ||
71 | type Iterator struct { | ||
72 | cfg *frozenConfig | ||
73 | reader io.Reader | ||
74 | buf []byte | ||
75 | head int | ||
76 | tail int | ||
77 | depth int | ||
78 | captureStartedAt int | ||
79 | captured []byte | ||
80 | Error error | ||
81 | Attachment interface{} // open for customized decoder | ||
82 | } | ||
83 | |||
84 | // NewIterator creates an empty Iterator instance | ||
85 | func NewIterator(cfg API) *Iterator { | ||
86 | return &Iterator{ | ||
87 | cfg: cfg.(*frozenConfig), | ||
88 | reader: nil, | ||
89 | buf: nil, | ||
90 | head: 0, | ||
91 | tail: 0, | ||
92 | depth: 0, | ||
93 | } | ||
94 | } | ||
95 | |||
96 | // Parse creates an Iterator instance from io.Reader | ||
97 | func Parse(cfg API, reader io.Reader, bufSize int) *Iterator { | ||
98 | return &Iterator{ | ||
99 | cfg: cfg.(*frozenConfig), | ||
100 | reader: reader, | ||
101 | buf: make([]byte, bufSize), | ||
102 | head: 0, | ||
103 | tail: 0, | ||
104 | depth: 0, | ||
105 | } | ||
106 | } | ||
107 | |||
108 | // ParseBytes creates an Iterator instance from byte array | ||
109 | func ParseBytes(cfg API, input []byte) *Iterator { | ||
110 | return &Iterator{ | ||
111 | cfg: cfg.(*frozenConfig), | ||
112 | reader: nil, | ||
113 | buf: input, | ||
114 | head: 0, | ||
115 | tail: len(input), | ||
116 | depth: 0, | ||
117 | } | ||
118 | } | ||
119 | |||
120 | // ParseString creates an Iterator instance from string | ||
121 | func ParseString(cfg API, input string) *Iterator { | ||
122 | return ParseBytes(cfg, []byte(input)) | ||
123 | } | ||
124 | |||
125 | // Pool returns a pool can provide more iterator with same configuration | ||
126 | func (iter *Iterator) Pool() IteratorPool { | ||
127 | return iter.cfg | ||
128 | } | ||
129 | |||
130 | // Reset reuse iterator instance by specifying another reader | ||
131 | func (iter *Iterator) Reset(reader io.Reader) *Iterator { | ||
132 | iter.reader = reader | ||
133 | iter.head = 0 | ||
134 | iter.tail = 0 | ||
135 | iter.depth = 0 | ||
136 | return iter | ||
137 | } | ||
138 | |||
139 | // ResetBytes reuse iterator instance by specifying another byte array as input | ||
140 | func (iter *Iterator) ResetBytes(input []byte) *Iterator { | ||
141 | iter.reader = nil | ||
142 | iter.buf = input | ||
143 | iter.head = 0 | ||
144 | iter.tail = len(input) | ||
145 | iter.depth = 0 | ||
146 | return iter | ||
147 | } | ||
148 | |||
149 | // WhatIsNext gets ValueType of relatively next json element | ||
150 | func (iter *Iterator) WhatIsNext() ValueType { | ||
151 | valueType := valueTypes[iter.nextToken()] | ||
152 | iter.unreadByte() | ||
153 | return valueType | ||
154 | } | ||
155 | |||
156 | func (iter *Iterator) skipWhitespacesWithoutLoadMore() bool { | ||
157 | for i := iter.head; i < iter.tail; i++ { | ||
158 | c := iter.buf[i] | ||
159 | switch c { | ||
160 | case ' ', '\n', '\t', '\r': | ||
161 | continue | ||
162 | } | ||
163 | iter.head = i | ||
164 | return false | ||
165 | } | ||
166 | return true | ||
167 | } | ||
168 | |||
169 | func (iter *Iterator) isObjectEnd() bool { | ||
170 | c := iter.nextToken() | ||
171 | if c == ',' { | ||
172 | return false | ||
173 | } | ||
174 | if c == '}' { | ||
175 | return true | ||
176 | } | ||
177 | iter.ReportError("isObjectEnd", "object ended prematurely, unexpected char "+string([]byte{c})) | ||
178 | return true | ||
179 | } | ||
180 | |||
181 | func (iter *Iterator) nextToken() byte { | ||
182 | // a variation of skip whitespaces, returning the next non-whitespace token | ||
183 | for { | ||
184 | for i := iter.head; i < iter.tail; i++ { | ||
185 | c := iter.buf[i] | ||
186 | switch c { | ||
187 | case ' ', '\n', '\t', '\r': | ||
188 | continue | ||
189 | } | ||
190 | iter.head = i + 1 | ||
191 | return c | ||
192 | } | ||
193 | if !iter.loadMore() { | ||
194 | return 0 | ||
195 | } | ||
196 | } | ||
197 | } | ||
198 | |||
199 | // ReportError record a error in iterator instance with current position. | ||
200 | func (iter *Iterator) ReportError(operation string, msg string) { | ||
201 | if iter.Error != nil { | ||
202 | if iter.Error != io.EOF { | ||
203 | return | ||
204 | } | ||
205 | } | ||
206 | peekStart := iter.head - 10 | ||
207 | if peekStart < 0 { | ||
208 | peekStart = 0 | ||
209 | } | ||
210 | peekEnd := iter.head + 10 | ||
211 | if peekEnd > iter.tail { | ||
212 | peekEnd = iter.tail | ||
213 | } | ||
214 | parsing := string(iter.buf[peekStart:peekEnd]) | ||
215 | contextStart := iter.head - 50 | ||
216 | if contextStart < 0 { | ||
217 | contextStart = 0 | ||
218 | } | ||
219 | contextEnd := iter.head + 50 | ||
220 | if contextEnd > iter.tail { | ||
221 | contextEnd = iter.tail | ||
222 | } | ||
223 | context := string(iter.buf[contextStart:contextEnd]) | ||
224 | iter.Error = fmt.Errorf("%s: %s, error found in #%v byte of ...|%s|..., bigger context ...|%s|...", | ||
225 | operation, msg, iter.head-peekStart, parsing, context) | ||
226 | } | ||
227 | |||
228 | // CurrentBuffer gets current buffer as string for debugging purpose | ||
229 | func (iter *Iterator) CurrentBuffer() string { | ||
230 | peekStart := iter.head - 10 | ||
231 | if peekStart < 0 { | ||
232 | peekStart = 0 | ||
233 | } | ||
234 | return fmt.Sprintf("parsing #%v byte, around ...|%s|..., whole buffer ...|%s|...", iter.head, | ||
235 | string(iter.buf[peekStart:iter.head]), string(iter.buf[0:iter.tail])) | ||
236 | } | ||
237 | |||
238 | func (iter *Iterator) readByte() (ret byte) { | ||
239 | if iter.head == iter.tail { | ||
240 | if iter.loadMore() { | ||
241 | ret = iter.buf[iter.head] | ||
242 | iter.head++ | ||
243 | return ret | ||
244 | } | ||
245 | return 0 | ||
246 | } | ||
247 | ret = iter.buf[iter.head] | ||
248 | iter.head++ | ||
249 | return ret | ||
250 | } | ||
251 | |||
252 | func (iter *Iterator) loadMore() bool { | ||
253 | if iter.reader == nil { | ||
254 | if iter.Error == nil { | ||
255 | iter.head = iter.tail | ||
256 | iter.Error = io.EOF | ||
257 | } | ||
258 | return false | ||
259 | } | ||
260 | if iter.captured != nil { | ||
261 | iter.captured = append(iter.captured, | ||
262 | iter.buf[iter.captureStartedAt:iter.tail]...) | ||
263 | iter.captureStartedAt = 0 | ||
264 | } | ||
265 | for { | ||
266 | n, err := iter.reader.Read(iter.buf) | ||
267 | if n == 0 { | ||
268 | if err != nil { | ||
269 | if iter.Error == nil { | ||
270 | iter.Error = err | ||
271 | } | ||
272 | return false | ||
273 | } | ||
274 | } else { | ||
275 | iter.head = 0 | ||
276 | iter.tail = n | ||
277 | return true | ||
278 | } | ||
279 | } | ||
280 | } | ||
281 | |||
282 | func (iter *Iterator) unreadByte() { | ||
283 | if iter.Error != nil { | ||
284 | return | ||
285 | } | ||
286 | iter.head-- | ||
287 | return | ||
288 | } | ||
289 | |||
290 | // Read read the next JSON element as generic interface{}. | ||
291 | func (iter *Iterator) Read() interface{} { | ||
292 | valueType := iter.WhatIsNext() | ||
293 | switch valueType { | ||
294 | case StringValue: | ||
295 | return iter.ReadString() | ||
296 | case NumberValue: | ||
297 | if iter.cfg.configBeforeFrozen.UseNumber { | ||
298 | return json.Number(iter.readNumberAsString()) | ||
299 | } | ||
300 | return iter.ReadFloat64() | ||
301 | case NilValue: | ||
302 | iter.skipFourBytes('n', 'u', 'l', 'l') | ||
303 | return nil | ||
304 | case BoolValue: | ||
305 | return iter.ReadBool() | ||
306 | case ArrayValue: | ||
307 | arr := []interface{}{} | ||
308 | iter.ReadArrayCB(func(iter *Iterator) bool { | ||
309 | var elem interface{} | ||
310 | iter.ReadVal(&elem) | ||
311 | arr = append(arr, elem) | ||
312 | return true | ||
313 | }) | ||
314 | return arr | ||
315 | case ObjectValue: | ||
316 | obj := map[string]interface{}{} | ||
317 | iter.ReadMapCB(func(Iter *Iterator, field string) bool { | ||
318 | var elem interface{} | ||
319 | iter.ReadVal(&elem) | ||
320 | obj[field] = elem | ||
321 | return true | ||
322 | }) | ||
323 | return obj | ||
324 | default: | ||
325 | iter.ReportError("Read", fmt.Sprintf("unexpected value type: %v", valueType)) | ||
326 | return nil | ||
327 | } | ||
328 | } | ||
329 | |||
330 | // limit maximum depth of nesting, as allowed by https://tools.ietf.org/html/rfc7159#section-9 | ||
331 | const maxDepth = 10000 | ||
332 | |||
333 | func (iter *Iterator) incrementDepth() (success bool) { | ||
334 | iter.depth++ | ||
335 | if iter.depth <= maxDepth { | ||
336 | return true | ||
337 | } | ||
338 | iter.ReportError("incrementDepth", "exceeded max depth") | ||
339 | return false | ||
340 | } | ||
341 | |||
342 | func (iter *Iterator) decrementDepth() (success bool) { | ||
343 | iter.depth-- | ||
344 | if iter.depth >= 0 { | ||
345 | return true | ||
346 | } | ||
347 | iter.ReportError("decrementDepth", "unexpected negative nesting") | ||
348 | return false | ||
349 | } | ||
diff --git a/vendor/github.com/json-iterator/go/iter_array.go b/vendor/github.com/json-iterator/go/iter_array.go deleted file mode 100644 index 204fe0e..0000000 --- a/vendor/github.com/json-iterator/go/iter_array.go +++ /dev/null | |||
@@ -1,64 +0,0 @@ | |||
1 | package jsoniter | ||
2 | |||
3 | // ReadArray read array element, tells if the array has more element to read. | ||
4 | func (iter *Iterator) ReadArray() (ret bool) { | ||
5 | c := iter.nextToken() | ||
6 | switch c { | ||
7 | case 'n': | ||
8 | iter.skipThreeBytes('u', 'l', 'l') | ||
9 | return false // null | ||
10 | case '[': | ||
11 | c = iter.nextToken() | ||
12 | if c != ']' { | ||
13 | iter.unreadByte() | ||
14 | return true | ||
15 | } | ||
16 | return false | ||
17 | case ']': | ||
18 | return false | ||
19 | case ',': | ||
20 | return true | ||
21 | default: | ||
22 | iter.ReportError("ReadArray", "expect [ or , or ] or n, but found "+string([]byte{c})) | ||
23 | return | ||
24 | } | ||
25 | } | ||
26 | |||
27 | // ReadArrayCB read array with callback | ||
28 | func (iter *Iterator) ReadArrayCB(callback func(*Iterator) bool) (ret bool) { | ||
29 | c := iter.nextToken() | ||
30 | if c == '[' { | ||
31 | if !iter.incrementDepth() { | ||
32 | return false | ||
33 | } | ||
34 | c = iter.nextToken() | ||
35 | if c != ']' { | ||
36 | iter.unreadByte() | ||
37 | if !callback(iter) { | ||
38 | iter.decrementDepth() | ||
39 | return false | ||
40 | } | ||
41 | c = iter.nextToken() | ||
42 | for c == ',' { | ||
43 | if !callback(iter) { | ||
44 | iter.decrementDepth() | ||
45 | return false | ||
46 | } | ||
47 | c = iter.nextToken() | ||
48 | } | ||
49 | if c != ']' { | ||
50 | iter.ReportError("ReadArrayCB", "expect ] in the end, but found "+string([]byte{c})) | ||
51 | iter.decrementDepth() | ||
52 | return false | ||
53 | } | ||
54 | return iter.decrementDepth() | ||
55 | } | ||
56 | return iter.decrementDepth() | ||
57 | } | ||
58 | if c == 'n' { | ||
59 | iter.skipThreeBytes('u', 'l', 'l') | ||
60 | return true // null | ||
61 | } | ||
62 | iter.ReportError("ReadArrayCB", "expect [ or n, but found "+string([]byte{c})) | ||
63 | return false | ||
64 | } | ||
diff --git a/vendor/github.com/json-iterator/go/iter_float.go b/vendor/github.com/json-iterator/go/iter_float.go deleted file mode 100644 index 8a3d8b6..0000000 --- a/vendor/github.com/json-iterator/go/iter_float.go +++ /dev/null | |||
@@ -1,342 +0,0 @@ | |||
1 | package jsoniter | ||
2 | |||
3 | import ( | ||
4 | "encoding/json" | ||
5 | "io" | ||
6 | "math/big" | ||
7 | "strconv" | ||
8 | "strings" | ||
9 | "unsafe" | ||
10 | ) | ||
11 | |||
12 | var floatDigits []int8 | ||
13 | |||
14 | const invalidCharForNumber = int8(-1) | ||
15 | const endOfNumber = int8(-2) | ||
16 | const dotInNumber = int8(-3) | ||
17 | |||
18 | func init() { | ||
19 | floatDigits = make([]int8, 256) | ||
20 | for i := 0; i < len(floatDigits); i++ { | ||
21 | floatDigits[i] = invalidCharForNumber | ||
22 | } | ||
23 | for i := int8('0'); i <= int8('9'); i++ { | ||
24 | floatDigits[i] = i - int8('0') | ||
25 | } | ||
26 | floatDigits[','] = endOfNumber | ||
27 | floatDigits[']'] = endOfNumber | ||
28 | floatDigits['}'] = endOfNumber | ||
29 | floatDigits[' '] = endOfNumber | ||
30 | floatDigits['\t'] = endOfNumber | ||
31 | floatDigits['\n'] = endOfNumber | ||
32 | floatDigits['.'] = dotInNumber | ||
33 | } | ||
34 | |||
35 | // ReadBigFloat read big.Float | ||
36 | func (iter *Iterator) ReadBigFloat() (ret *big.Float) { | ||
37 | str := iter.readNumberAsString() | ||
38 | if iter.Error != nil && iter.Error != io.EOF { | ||
39 | return nil | ||
40 | } | ||
41 | prec := 64 | ||
42 | if len(str) > prec { | ||
43 | prec = len(str) | ||
44 | } | ||
45 | val, _, err := big.ParseFloat(str, 10, uint(prec), big.ToZero) | ||
46 | if err != nil { | ||
47 | iter.Error = err | ||
48 | return nil | ||
49 | } | ||
50 | return val | ||
51 | } | ||
52 | |||
53 | // ReadBigInt read big.Int | ||
54 | func (iter *Iterator) ReadBigInt() (ret *big.Int) { | ||
55 | str := iter.readNumberAsString() | ||
56 | if iter.Error != nil && iter.Error != io.EOF { | ||
57 | return nil | ||
58 | } | ||
59 | ret = big.NewInt(0) | ||
60 | var success bool | ||
61 | ret, success = ret.SetString(str, 10) | ||
62 | if !success { | ||
63 | iter.ReportError("ReadBigInt", "invalid big int") | ||
64 | return nil | ||
65 | } | ||
66 | return ret | ||
67 | } | ||
68 | |||
69 | //ReadFloat32 read float32 | ||
70 | func (iter *Iterator) ReadFloat32() (ret float32) { | ||
71 | c := iter.nextToken() | ||
72 | if c == '-' { | ||
73 | return -iter.readPositiveFloat32() | ||
74 | } | ||
75 | iter.unreadByte() | ||
76 | return iter.readPositiveFloat32() | ||
77 | } | ||
78 | |||
79 | func (iter *Iterator) readPositiveFloat32() (ret float32) { | ||
80 | i := iter.head | ||
81 | // first char | ||
82 | if i == iter.tail { | ||
83 | return iter.readFloat32SlowPath() | ||
84 | } | ||
85 | c := iter.buf[i] | ||
86 | i++ | ||
87 | ind := floatDigits[c] | ||
88 | switch ind { | ||
89 | case invalidCharForNumber: | ||
90 | return iter.readFloat32SlowPath() | ||
91 | case endOfNumber: | ||
92 | iter.ReportError("readFloat32", "empty number") | ||
93 | return | ||
94 | case dotInNumber: | ||
95 | iter.ReportError("readFloat32", "leading dot is invalid") | ||
96 | return | ||
97 | case 0: | ||
98 | if i == iter.tail { | ||
99 | return iter.readFloat32SlowPath() | ||
100 | } | ||
101 | c = iter.buf[i] | ||
102 | switch c { | ||
103 | case '0', '1', '2', '3', '4', '5', '6', '7', '8', '9': | ||
104 | iter.ReportError("readFloat32", "leading zero is invalid") | ||
105 | return | ||
106 | } | ||
107 | } | ||
108 | value := uint64(ind) | ||
109 | // chars before dot | ||
110 | non_decimal_loop: | ||
111 | for ; i < iter.tail; i++ { | ||
112 | c = iter.buf[i] | ||
113 | ind := floatDigits[c] | ||
114 | switch ind { | ||
115 | case invalidCharForNumber: | ||
116 | return iter.readFloat32SlowPath() | ||
117 | case endOfNumber: | ||
118 | iter.head = i | ||
119 | return float32(value) | ||
120 | case dotInNumber: | ||
121 | break non_decimal_loop | ||
122 | } | ||
123 | if value > uint64SafeToMultiple10 { | ||
124 | return iter.readFloat32SlowPath() | ||
125 | } | ||
126 | value = (value << 3) + (value << 1) + uint64(ind) // value = value * 10 + ind; | ||
127 | } | ||
128 | // chars after dot | ||
129 | if c == '.' { | ||
130 | i++ | ||
131 | decimalPlaces := 0 | ||
132 | if i == iter.tail { | ||
133 | return iter.readFloat32SlowPath() | ||
134 | } | ||
135 | for ; i < iter.tail; i++ { | ||
136 | c = iter.buf[i] | ||
137 | ind := floatDigits[c] | ||
138 | switch ind { | ||
139 | case endOfNumber: | ||
140 | if decimalPlaces > 0 && decimalPlaces < len(pow10) { | ||
141 | iter.head = i | ||
142 | return float32(float64(value) / float64(pow10[decimalPlaces])) | ||
143 | } | ||
144 | // too many decimal places | ||
145 | return iter.readFloat32SlowPath() | ||
146 | case invalidCharForNumber, dotInNumber: | ||
147 | return iter.readFloat32SlowPath() | ||
148 | } | ||
149 | decimalPlaces++ | ||
150 | if value > uint64SafeToMultiple10 { | ||
151 | return iter.readFloat32SlowPath() | ||
152 | } | ||
153 | value = (value << 3) + (value << 1) + uint64(ind) | ||
154 | } | ||
155 | } | ||
156 | return iter.readFloat32SlowPath() | ||
157 | } | ||
158 | |||
159 | func (iter *Iterator) readNumberAsString() (ret string) { | ||
160 | strBuf := [16]byte{} | ||
161 | str := strBuf[0:0] | ||
162 | load_loop: | ||
163 | for { | ||
164 | for i := iter.head; i < iter.tail; i++ { | ||
165 | c := iter.buf[i] | ||
166 | switch c { | ||
167 | case '+', '-', '.', 'e', 'E', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9': | ||
168 | str = append(str, c) | ||
169 | continue | ||
170 | default: | ||
171 | iter.head = i | ||
172 | break load_loop | ||
173 | } | ||
174 | } | ||
175 | if !iter.loadMore() { | ||
176 | break | ||
177 | } | ||
178 | } | ||
179 | if iter.Error != nil && iter.Error != io.EOF { | ||
180 | return | ||
181 | } | ||
182 | if len(str) == 0 { | ||
183 | iter.ReportError("readNumberAsString", "invalid number") | ||
184 | } | ||
185 | return *(*string)(unsafe.Pointer(&str)) | ||
186 | } | ||
187 | |||
188 | func (iter *Iterator) readFloat32SlowPath() (ret float32) { | ||
189 | str := iter.readNumberAsString() | ||
190 | if iter.Error != nil && iter.Error != io.EOF { | ||
191 | return | ||
192 | } | ||
193 | errMsg := validateFloat(str) | ||
194 | if errMsg != "" { | ||
195 | iter.ReportError("readFloat32SlowPath", errMsg) | ||
196 | return | ||
197 | } | ||
198 | val, err := strconv.ParseFloat(str, 32) | ||
199 | if err != nil { | ||
200 | iter.Error = err | ||
201 | return | ||
202 | } | ||
203 | return float32(val) | ||
204 | } | ||
205 | |||
206 | // ReadFloat64 read float64 | ||
207 | func (iter *Iterator) ReadFloat64() (ret float64) { | ||
208 | c := iter.nextToken() | ||
209 | if c == '-' { | ||
210 | return -iter.readPositiveFloat64() | ||
211 | } | ||
212 | iter.unreadByte() | ||
213 | return iter.readPositiveFloat64() | ||
214 | } | ||
215 | |||
216 | func (iter *Iterator) readPositiveFloat64() (ret float64) { | ||
217 | i := iter.head | ||
218 | // first char | ||
219 | if i == iter.tail { | ||
220 | return iter.readFloat64SlowPath() | ||
221 | } | ||
222 | c := iter.buf[i] | ||
223 | i++ | ||
224 | ind := floatDigits[c] | ||
225 | switch ind { | ||
226 | case invalidCharForNumber: | ||
227 | return iter.readFloat64SlowPath() | ||
228 | case endOfNumber: | ||
229 | iter.ReportError("readFloat64", "empty number") | ||
230 | return | ||
231 | case dotInNumber: | ||
232 | iter.ReportError("readFloat64", "leading dot is invalid") | ||
233 | return | ||
234 | case 0: | ||
235 | if i == iter.tail { | ||
236 | return iter.readFloat64SlowPath() | ||
237 | } | ||
238 | c = iter.buf[i] | ||
239 | switch c { | ||
240 | case '0', '1', '2', '3', '4', '5', '6', '7', '8', '9': | ||
241 | iter.ReportError("readFloat64", "leading zero is invalid") | ||
242 | return | ||
243 | } | ||
244 | } | ||
245 | value := uint64(ind) | ||
246 | // chars before dot | ||
247 | non_decimal_loop: | ||
248 | for ; i < iter.tail; i++ { | ||
249 | c = iter.buf[i] | ||
250 | ind := floatDigits[c] | ||
251 | switch ind { | ||
252 | case invalidCharForNumber: | ||
253 | return iter.readFloat64SlowPath() | ||
254 | case endOfNumber: | ||
255 | iter.head = i | ||
256 | return float64(value) | ||
257 | case dotInNumber: | ||
258 | break non_decimal_loop | ||
259 | } | ||
260 | if value > uint64SafeToMultiple10 { | ||
261 | return iter.readFloat64SlowPath() | ||
262 | } | ||
263 | value = (value << 3) + (value << 1) + uint64(ind) // value = value * 10 + ind; | ||
264 | } | ||
265 | // chars after dot | ||
266 | if c == '.' { | ||
267 | i++ | ||
268 | decimalPlaces := 0 | ||
269 | if i == iter.tail { | ||
270 | return iter.readFloat64SlowPath() | ||
271 | } | ||
272 | for ; i < iter.tail; i++ { | ||
273 | c = iter.buf[i] | ||
274 | ind := floatDigits[c] | ||
275 | switch ind { | ||
276 | case endOfNumber: | ||
277 | if decimalPlaces > 0 && decimalPlaces < len(pow10) { | ||
278 | iter.head = i | ||
279 | return float64(value) / float64(pow10[decimalPlaces]) | ||
280 | } | ||
281 | // too many decimal places | ||
282 | return iter.readFloat64SlowPath() | ||
283 | case invalidCharForNumber, dotInNumber: | ||
284 | return iter.readFloat64SlowPath() | ||
285 | } | ||
286 | decimalPlaces++ | ||
287 | if value > uint64SafeToMultiple10 { | ||
288 | return iter.readFloat64SlowPath() | ||
289 | } | ||
290 | value = (value << 3) + (value << 1) + uint64(ind) | ||
291 | if value > maxFloat64 { | ||
292 | return iter.readFloat64SlowPath() | ||
293 | } | ||
294 | } | ||
295 | } | ||
296 | return iter.readFloat64SlowPath() | ||
297 | } | ||
298 | |||
299 | func (iter *Iterator) readFloat64SlowPath() (ret float64) { | ||
300 | str := iter.readNumberAsString() | ||
301 | if iter.Error != nil && iter.Error != io.EOF { | ||
302 | return | ||
303 | } | ||
304 | errMsg := validateFloat(str) | ||
305 | if errMsg != "" { | ||
306 | iter.ReportError("readFloat64SlowPath", errMsg) | ||
307 | return | ||
308 | } | ||
309 | val, err := strconv.ParseFloat(str, 64) | ||
310 | if err != nil { | ||
311 | iter.Error = err | ||
312 | return | ||
313 | } | ||
314 | return val | ||
315 | } | ||
316 | |||
317 | func validateFloat(str string) string { | ||
318 | // strconv.ParseFloat is not validating `1.` or `1.e1` | ||
319 | if len(str) == 0 { | ||
320 | return "empty number" | ||
321 | } | ||
322 | if str[0] == '-' { | ||
323 | return "-- is not valid" | ||
324 | } | ||
325 | dotPos := strings.IndexByte(str, '.') | ||
326 | if dotPos != -1 { | ||
327 | if dotPos == len(str)-1 { | ||
328 | return "dot can not be last character" | ||
329 | } | ||
330 | switch str[dotPos+1] { | ||
331 | case '0', '1', '2', '3', '4', '5', '6', '7', '8', '9': | ||
332 | default: | ||
333 | return "missing digit after dot" | ||
334 | } | ||
335 | } | ||
336 | return "" | ||
337 | } | ||
338 | |||
339 | // ReadNumber read json.Number | ||
340 | func (iter *Iterator) ReadNumber() (ret json.Number) { | ||
341 | return json.Number(iter.readNumberAsString()) | ||
342 | } | ||
diff --git a/vendor/github.com/json-iterator/go/iter_int.go b/vendor/github.com/json-iterator/go/iter_int.go deleted file mode 100644 index d786a89..0000000 --- a/vendor/github.com/json-iterator/go/iter_int.go +++ /dev/null | |||
@@ -1,346 +0,0 @@ | |||
1 | package jsoniter | ||
2 | |||
3 | import ( | ||
4 | "math" | ||
5 | "strconv" | ||
6 | ) | ||
7 | |||
8 | var intDigits []int8 | ||
9 | |||
10 | const uint32SafeToMultiply10 = uint32(0xffffffff)/10 - 1 | ||
11 | const uint64SafeToMultiple10 = uint64(0xffffffffffffffff)/10 - 1 | ||
12 | const maxFloat64 = 1<<53 - 1 | ||
13 | |||
14 | func init() { | ||
15 | intDigits = make([]int8, 256) | ||
16 | for i := 0; i < len(intDigits); i++ { | ||
17 | intDigits[i] = invalidCharForNumber | ||
18 | } | ||
19 | for i := int8('0'); i <= int8('9'); i++ { | ||
20 | intDigits[i] = i - int8('0') | ||
21 | } | ||
22 | } | ||
23 | |||
24 | // ReadUint read uint | ||
25 | func (iter *Iterator) ReadUint() uint { | ||
26 | if strconv.IntSize == 32 { | ||
27 | return uint(iter.ReadUint32()) | ||
28 | } | ||
29 | return uint(iter.ReadUint64()) | ||
30 | } | ||
31 | |||
32 | // ReadInt read int | ||
33 | func (iter *Iterator) ReadInt() int { | ||
34 | if strconv.IntSize == 32 { | ||
35 | return int(iter.ReadInt32()) | ||
36 | } | ||
37 | return int(iter.ReadInt64()) | ||
38 | } | ||
39 | |||
40 | // ReadInt8 read int8 | ||
41 | func (iter *Iterator) ReadInt8() (ret int8) { | ||
42 | c := iter.nextToken() | ||
43 | if c == '-' { | ||
44 | val := iter.readUint32(iter.readByte()) | ||
45 | if val > math.MaxInt8+1 { | ||
46 | iter.ReportError("ReadInt8", "overflow: "+strconv.FormatInt(int64(val), 10)) | ||
47 | return | ||
48 | } | ||
49 | return -int8(val) | ||
50 | } | ||
51 | val := iter.readUint32(c) | ||
52 | if val > math.MaxInt8 { | ||
53 | iter.ReportError("ReadInt8", "overflow: "+strconv.FormatInt(int64(val), 10)) | ||
54 | return | ||
55 | } | ||
56 | return int8(val) | ||
57 | } | ||
58 | |||
59 | // ReadUint8 read uint8 | ||
60 | func (iter *Iterator) ReadUint8() (ret uint8) { | ||
61 | val := iter.readUint32(iter.nextToken()) | ||
62 | if val > math.MaxUint8 { | ||
63 | iter.ReportError("ReadUint8", "overflow: "+strconv.FormatInt(int64(val), 10)) | ||
64 | return | ||
65 | } | ||
66 | return uint8(val) | ||
67 | } | ||
68 | |||
69 | // ReadInt16 read int16 | ||
70 | func (iter *Iterator) ReadInt16() (ret int16) { | ||
71 | c := iter.nextToken() | ||
72 | if c == '-' { | ||
73 | val := iter.readUint32(iter.readByte()) | ||
74 | if val > math.MaxInt16+1 { | ||
75 | iter.ReportError("ReadInt16", "overflow: "+strconv.FormatInt(int64(val), 10)) | ||
76 | return | ||
77 | } | ||
78 | return -int16(val) | ||
79 | } | ||
80 | val := iter.readUint32(c) | ||
81 | if val > math.MaxInt16 { | ||
82 | iter.ReportError("ReadInt16", "overflow: "+strconv.FormatInt(int64(val), 10)) | ||
83 | return | ||
84 | } | ||
85 | return int16(val) | ||
86 | } | ||
87 | |||
88 | // ReadUint16 read uint16 | ||
89 | func (iter *Iterator) ReadUint16() (ret uint16) { | ||
90 | val := iter.readUint32(iter.nextToken()) | ||
91 | if val > math.MaxUint16 { | ||
92 | iter.ReportError("ReadUint16", "overflow: "+strconv.FormatInt(int64(val), 10)) | ||
93 | return | ||
94 | } | ||
95 | return uint16(val) | ||
96 | } | ||
97 | |||
98 | // ReadInt32 read int32 | ||
99 | func (iter *Iterator) ReadInt32() (ret int32) { | ||
100 | c := iter.nextToken() | ||
101 | if c == '-' { | ||
102 | val := iter.readUint32(iter.readByte()) | ||
103 | if val > math.MaxInt32+1 { | ||
104 | iter.ReportError("ReadInt32", "overflow: "+strconv.FormatInt(int64(val), 10)) | ||
105 | return | ||
106 | } | ||
107 | return -int32(val) | ||
108 | } | ||
109 | val := iter.readUint32(c) | ||
110 | if val > math.MaxInt32 { | ||
111 | iter.ReportError("ReadInt32", "overflow: "+strconv.FormatInt(int64(val), 10)) | ||
112 | return | ||
113 | } | ||
114 | return int32(val) | ||
115 | } | ||
116 | |||
117 | // ReadUint32 read uint32 | ||
118 | func (iter *Iterator) ReadUint32() (ret uint32) { | ||
119 | return iter.readUint32(iter.nextToken()) | ||
120 | } | ||
121 | |||
122 | func (iter *Iterator) readUint32(c byte) (ret uint32) { | ||
123 | ind := intDigits[c] | ||
124 | if ind == 0 { | ||
125 | iter.assertInteger() | ||
126 | return 0 // single zero | ||
127 | } | ||
128 | if ind == invalidCharForNumber { | ||
129 | iter.ReportError("readUint32", "unexpected character: "+string([]byte{byte(ind)})) | ||
130 | return | ||
131 | } | ||
132 | value := uint32(ind) | ||
133 | if iter.tail-iter.head > 10 { | ||
134 | i := iter.head | ||
135 | ind2 := intDigits[iter.buf[i]] | ||
136 | if ind2 == invalidCharForNumber { | ||
137 | iter.head = i | ||
138 | iter.assertInteger() | ||
139 | return value | ||
140 | } | ||
141 | i++ | ||
142 | ind3 := intDigits[iter.buf[i]] | ||
143 | if ind3 == invalidCharForNumber { | ||
144 | iter.head = i | ||
145 | iter.assertInteger() | ||
146 | return value*10 + uint32(ind2) | ||
147 | } | ||
148 | //iter.head = i + 1 | ||
149 | //value = value * 100 + uint32(ind2) * 10 + uint32(ind3) | ||
150 | i++ | ||
151 | ind4 := intDigits[iter.buf[i]] | ||
152 | if ind4 == invalidCharForNumber { | ||
153 | iter.head = i | ||
154 | iter.assertInteger() | ||
155 | return value*100 + uint32(ind2)*10 + uint32(ind3) | ||
156 | } | ||
157 | i++ | ||
158 | ind5 := intDigits[iter.buf[i]] | ||
159 | if ind5 == invalidCharForNumber { | ||
160 | iter.head = i | ||
161 | iter.assertInteger() | ||
162 | return value*1000 + uint32(ind2)*100 + uint32(ind3)*10 + uint32(ind4) | ||
163 | } | ||
164 | i++ | ||
165 | ind6 := intDigits[iter.buf[i]] | ||
166 | if ind6 == invalidCharForNumber { | ||
167 | iter.head = i | ||
168 | iter.assertInteger() | ||
169 | return value*10000 + uint32(ind2)*1000 + uint32(ind3)*100 + uint32(ind4)*10 + uint32(ind5) | ||
170 | } | ||
171 | i++ | ||
172 | ind7 := intDigits[iter.buf[i]] | ||
173 | if ind7 == invalidCharForNumber { | ||
174 | iter.head = i | ||
175 | iter.assertInteger() | ||
176 | return value*100000 + uint32(ind2)*10000 + uint32(ind3)*1000 + uint32(ind4)*100 + uint32(ind5)*10 + uint32(ind6) | ||
177 | } | ||
178 | i++ | ||
179 | ind8 := intDigits[iter.buf[i]] | ||
180 | if ind8 == invalidCharForNumber { | ||
181 | iter.head = i | ||
182 | iter.assertInteger() | ||
183 | return value*1000000 + uint32(ind2)*100000 + uint32(ind3)*10000 + uint32(ind4)*1000 + uint32(ind5)*100 + uint32(ind6)*10 + uint32(ind7) | ||
184 | } | ||
185 | i++ | ||
186 | ind9 := intDigits[iter.buf[i]] | ||
187 | value = value*10000000 + uint32(ind2)*1000000 + uint32(ind3)*100000 + uint32(ind4)*10000 + uint32(ind5)*1000 + uint32(ind6)*100 + uint32(ind7)*10 + uint32(ind8) | ||
188 | iter.head = i | ||
189 | if ind9 == invalidCharForNumber { | ||
190 | iter.assertInteger() | ||
191 | return value | ||
192 | } | ||
193 | } | ||
194 | for { | ||
195 | for i := iter.head; i < iter.tail; i++ { | ||
196 | ind = intDigits[iter.buf[i]] | ||
197 | if ind == invalidCharForNumber { | ||
198 | iter.head = i | ||
199 | iter.assertInteger() | ||
200 | return value | ||
201 | } | ||
202 | if value > uint32SafeToMultiply10 { | ||
203 | value2 := (value << 3) + (value << 1) + uint32(ind) | ||
204 | if value2 < value { | ||
205 | iter.ReportError("readUint32", "overflow") | ||
206 | return | ||
207 | } | ||
208 | value = value2 | ||
209 | continue | ||
210 | } | ||
211 | value = (value << 3) + (value << 1) + uint32(ind) | ||
212 | } | ||
213 | if !iter.loadMore() { | ||
214 | iter.assertInteger() | ||
215 | return value | ||
216 | } | ||
217 | } | ||
218 | } | ||
219 | |||
220 | // ReadInt64 read int64 | ||
221 | func (iter *Iterator) ReadInt64() (ret int64) { | ||
222 | c := iter.nextToken() | ||
223 | if c == '-' { | ||
224 | val := iter.readUint64(iter.readByte()) | ||
225 | if val > math.MaxInt64+1 { | ||
226 | iter.ReportError("ReadInt64", "overflow: "+strconv.FormatUint(uint64(val), 10)) | ||
227 | return | ||
228 | } | ||
229 | return -int64(val) | ||
230 | } | ||
231 | val := iter.readUint64(c) | ||
232 | if val > math.MaxInt64 { | ||
233 | iter.ReportError("ReadInt64", "overflow: "+strconv.FormatUint(uint64(val), 10)) | ||
234 | return | ||
235 | } | ||
236 | return int64(val) | ||
237 | } | ||
238 | |||
239 | // ReadUint64 read uint64 | ||
240 | func (iter *Iterator) ReadUint64() uint64 { | ||
241 | return iter.readUint64(iter.nextToken()) | ||
242 | } | ||
243 | |||
244 | func (iter *Iterator) readUint64(c byte) (ret uint64) { | ||
245 | ind := intDigits[c] | ||
246 | if ind == 0 { | ||
247 | iter.assertInteger() | ||
248 | return 0 // single zero | ||
249 | } | ||
250 | if ind == invalidCharForNumber { | ||
251 | iter.ReportError("readUint64", "unexpected character: "+string([]byte{byte(ind)})) | ||
252 | return | ||
253 | } | ||
254 | value := uint64(ind) | ||
255 | if iter.tail-iter.head > 10 { | ||
256 | i := iter.head | ||
257 | ind2 := intDigits[iter.buf[i]] | ||
258 | if ind2 == invalidCharForNumber { | ||
259 | iter.head = i | ||
260 | iter.assertInteger() | ||
261 | return value | ||
262 | } | ||
263 | i++ | ||
264 | ind3 := intDigits[iter.buf[i]] | ||
265 | if ind3 == invalidCharForNumber { | ||
266 | iter.head = i | ||
267 | iter.assertInteger() | ||
268 | return value*10 + uint64(ind2) | ||
269 | } | ||
270 | //iter.head = i + 1 | ||
271 | //value = value * 100 + uint32(ind2) * 10 + uint32(ind3) | ||
272 | i++ | ||
273 | ind4 := intDigits[iter.buf[i]] | ||
274 | if ind4 == invalidCharForNumber { | ||
275 | iter.head = i | ||
276 | iter.assertInteger() | ||
277 | return value*100 + uint64(ind2)*10 + uint64(ind3) | ||
278 | } | ||
279 | i++ | ||
280 | ind5 := intDigits[iter.buf[i]] | ||
281 | if ind5 == invalidCharForNumber { | ||
282 | iter.head = i | ||
283 | iter.assertInteger() | ||
284 | return value*1000 + uint64(ind2)*100 + uint64(ind3)*10 + uint64(ind4) | ||
285 | } | ||
286 | i++ | ||
287 | ind6 := intDigits[iter.buf[i]] | ||
288 | if ind6 == invalidCharForNumber { | ||
289 | iter.head = i | ||
290 | iter.assertInteger() | ||
291 | return value*10000 + uint64(ind2)*1000 + uint64(ind3)*100 + uint64(ind4)*10 + uint64(ind5) | ||
292 | } | ||
293 | i++ | ||
294 | ind7 := intDigits[iter.buf[i]] | ||
295 | if ind7 == invalidCharForNumber { | ||
296 | iter.head = i | ||
297 | iter.assertInteger() | ||
298 | return value*100000 + uint64(ind2)*10000 + uint64(ind3)*1000 + uint64(ind4)*100 + uint64(ind5)*10 + uint64(ind6) | ||
299 | } | ||
300 | i++ | ||
301 | ind8 := intDigits[iter.buf[i]] | ||
302 | if ind8 == invalidCharForNumber { | ||
303 | iter.head = i | ||
304 | iter.assertInteger() | ||
305 | return value*1000000 + uint64(ind2)*100000 + uint64(ind3)*10000 + uint64(ind4)*1000 + uint64(ind5)*100 + uint64(ind6)*10 + uint64(ind7) | ||
306 | } | ||
307 | i++ | ||
308 | ind9 := intDigits[iter.buf[i]] | ||
309 | value = value*10000000 + uint64(ind2)*1000000 + uint64(ind3)*100000 + uint64(ind4)*10000 + uint64(ind5)*1000 + uint64(ind6)*100 + uint64(ind7)*10 + uint64(ind8) | ||
310 | iter.head = i | ||
311 | if ind9 == invalidCharForNumber { | ||
312 | iter.assertInteger() | ||
313 | return value | ||
314 | } | ||
315 | } | ||
316 | for { | ||
317 | for i := iter.head; i < iter.tail; i++ { | ||
318 | ind = intDigits[iter.buf[i]] | ||
319 | if ind == invalidCharForNumber { | ||
320 | iter.head = i | ||
321 | iter.assertInteger() | ||
322 | return value | ||
323 | } | ||
324 | if value > uint64SafeToMultiple10 { | ||
325 | value2 := (value << 3) + (value << 1) + uint64(ind) | ||
326 | if value2 < value { | ||
327 | iter.ReportError("readUint64", "overflow") | ||
328 | return | ||
329 | } | ||
330 | value = value2 | ||
331 | continue | ||
332 | } | ||
333 | value = (value << 3) + (value << 1) + uint64(ind) | ||
334 | } | ||
335 | if !iter.loadMore() { | ||
336 | iter.assertInteger() | ||
337 | return value | ||
338 | } | ||
339 | } | ||
340 | } | ||
341 | |||
342 | func (iter *Iterator) assertInteger() { | ||
343 | if iter.head < iter.tail && iter.buf[iter.head] == '.' { | ||
344 | iter.ReportError("assertInteger", "can not decode float as int") | ||
345 | } | ||
346 | } | ||
diff --git a/vendor/github.com/json-iterator/go/iter_object.go b/vendor/github.com/json-iterator/go/iter_object.go deleted file mode 100644 index 58ee89c..0000000 --- a/vendor/github.com/json-iterator/go/iter_object.go +++ /dev/null | |||
@@ -1,267 +0,0 @@ | |||
1 | package jsoniter | ||
2 | |||
3 | import ( | ||
4 | "fmt" | ||
5 | "strings" | ||
6 | ) | ||
7 | |||
8 | // ReadObject read one field from object. | ||
9 | // If object ended, returns empty string. | ||
10 | // Otherwise, returns the field name. | ||
11 | func (iter *Iterator) ReadObject() (ret string) { | ||
12 | c := iter.nextToken() | ||
13 | switch c { | ||
14 | case 'n': | ||
15 | iter.skipThreeBytes('u', 'l', 'l') | ||
16 | return "" // null | ||
17 | case '{': | ||
18 | c = iter.nextToken() | ||
19 | if c == '"' { | ||
20 | iter.unreadByte() | ||
21 | field := iter.ReadString() | ||
22 | c = iter.nextToken() | ||
23 | if c != ':' { | ||
24 | iter.ReportError("ReadObject", "expect : after object field, but found "+string([]byte{c})) | ||
25 | } | ||
26 | return field | ||
27 | } | ||
28 | if c == '}' { | ||
29 | return "" // end of object | ||
30 | } | ||
31 | iter.ReportError("ReadObject", `expect " after {, but found `+string([]byte{c})) | ||
32 | return | ||
33 | case ',': | ||
34 | field := iter.ReadString() | ||
35 | c = iter.nextToken() | ||
36 | if c != ':' { | ||
37 | iter.ReportError("ReadObject", "expect : after object field, but found "+string([]byte{c})) | ||
38 | } | ||
39 | return field | ||
40 | case '}': | ||
41 | return "" // end of object | ||
42 | default: | ||
43 | iter.ReportError("ReadObject", fmt.Sprintf(`expect { or , or } or n, but found %s`, string([]byte{c}))) | ||
44 | return | ||
45 | } | ||
46 | } | ||
47 | |||
48 | // CaseInsensitive | ||
49 | func (iter *Iterator) readFieldHash() int64 { | ||
50 | hash := int64(0x811c9dc5) | ||
51 | c := iter.nextToken() | ||
52 | if c != '"' { | ||
53 | iter.ReportError("readFieldHash", `expect ", but found `+string([]byte{c})) | ||
54 | return 0 | ||
55 | } | ||
56 | for { | ||
57 | for i := iter.head; i < iter.tail; i++ { | ||
58 | // require ascii string and no escape | ||
59 | b := iter.buf[i] | ||
60 | if b == '\\' { | ||
61 | iter.head = i | ||
62 | for _, b := range iter.readStringSlowPath() { | ||
63 | if 'A' <= b && b <= 'Z' && !iter.cfg.caseSensitive { | ||
64 | b += 'a' - 'A' | ||
65 | } | ||
66 | hash ^= int64(b) | ||
67 | hash *= 0x1000193 | ||
68 | } | ||
69 | c = iter.nextToken() | ||
70 | if c != ':' { | ||
71 | iter.ReportError("readFieldHash", `expect :, but found `+string([]byte{c})) | ||
72 | return 0 | ||
73 | } | ||
74 | return hash | ||
75 | } | ||
76 | if b == '"' { | ||
77 | iter.head = i + 1 | ||
78 | c = iter.nextToken() | ||
79 | if c != ':' { | ||
80 | iter.ReportError("readFieldHash", `expect :, but found `+string([]byte{c})) | ||
81 | return 0 | ||
82 | } | ||
83 | return hash | ||
84 | } | ||
85 | if 'A' <= b && b <= 'Z' && !iter.cfg.caseSensitive { | ||
86 | b += 'a' - 'A' | ||
87 | } | ||
88 | hash ^= int64(b) | ||
89 | hash *= 0x1000193 | ||
90 | } | ||
91 | if !iter.loadMore() { | ||
92 | iter.ReportError("readFieldHash", `incomplete field name`) | ||
93 | return 0 | ||
94 | } | ||
95 | } | ||
96 | } | ||
97 | |||
98 | func calcHash(str string, caseSensitive bool) int64 { | ||
99 | if !caseSensitive { | ||
100 | str = strings.ToLower(str) | ||
101 | } | ||
102 | hash := int64(0x811c9dc5) | ||
103 | for _, b := range []byte(str) { | ||
104 | hash ^= int64(b) | ||
105 | hash *= 0x1000193 | ||
106 | } | ||
107 | return int64(hash) | ||
108 | } | ||
109 | |||
110 | // ReadObjectCB read object with callback, the key is ascii only and field name not copied | ||
111 | func (iter *Iterator) ReadObjectCB(callback func(*Iterator, string) bool) bool { | ||
112 | c := iter.nextToken() | ||
113 | var field string | ||
114 | if c == '{' { | ||
115 | if !iter.incrementDepth() { | ||
116 | return false | ||
117 | } | ||
118 | c = iter.nextToken() | ||
119 | if c == '"' { | ||
120 | iter.unreadByte() | ||
121 | field = iter.ReadString() | ||
122 | c = iter.nextToken() | ||
123 | if c != ':' { | ||
124 | iter.ReportError("ReadObject", "expect : after object field, but found "+string([]byte{c})) | ||
125 | } | ||
126 | if !callback(iter, field) { | ||
127 | iter.decrementDepth() | ||
128 | return false | ||
129 | } | ||
130 | c = iter.nextToken() | ||
131 | for c == ',' { | ||
132 | field = iter.ReadString() | ||
133 | c = iter.nextToken() | ||
134 | if c != ':' { | ||
135 | iter.ReportError("ReadObject", "expect : after object field, but found "+string([]byte{c})) | ||
136 | } | ||
137 | if !callback(iter, field) { | ||
138 | iter.decrementDepth() | ||
139 | return false | ||
140 | } | ||
141 | c = iter.nextToken() | ||
142 | } | ||
143 | if c != '}' { | ||
144 | iter.ReportError("ReadObjectCB", `object not ended with }`) | ||
145 | iter.decrementDepth() | ||
146 | return false | ||
147 | } | ||
148 | return iter.decrementDepth() | ||
149 | } | ||
150 | if c == '}' { | ||
151 | return iter.decrementDepth() | ||
152 | } | ||
153 | iter.ReportError("ReadObjectCB", `expect " after {, but found `+string([]byte{c})) | ||
154 | iter.decrementDepth() | ||
155 | return false | ||
156 | } | ||
157 | if c == 'n' { | ||
158 | iter.skipThreeBytes('u', 'l', 'l') | ||
159 | return true // null | ||
160 | } | ||
161 | iter.ReportError("ReadObjectCB", `expect { or n, but found `+string([]byte{c})) | ||
162 | return false | ||
163 | } | ||
164 | |||
165 | // ReadMapCB read map with callback, the key can be any string | ||
166 | func (iter *Iterator) ReadMapCB(callback func(*Iterator, string) bool) bool { | ||
167 | c := iter.nextToken() | ||
168 | if c == '{' { | ||
169 | if !iter.incrementDepth() { | ||
170 | return false | ||
171 | } | ||
172 | c = iter.nextToken() | ||
173 | if c == '"' { | ||
174 | iter.unreadByte() | ||
175 | field := iter.ReadString() | ||
176 | if iter.nextToken() != ':' { | ||
177 | iter.ReportError("ReadMapCB", "expect : after object field, but found "+string([]byte{c})) | ||
178 | iter.decrementDepth() | ||
179 | return false | ||
180 | } | ||
181 | if !callback(iter, field) { | ||
182 | iter.decrementDepth() | ||
183 | return false | ||
184 | } | ||
185 | c = iter.nextToken() | ||
186 | for c == ',' { | ||
187 | field = iter.ReadString() | ||
188 | if iter.nextToken() != ':' { | ||
189 | iter.ReportError("ReadMapCB", "expect : after object field, but found "+string([]byte{c})) | ||
190 | iter.decrementDepth() | ||
191 | return false | ||
192 | } | ||
193 | if !callback(iter, field) { | ||
194 | iter.decrementDepth() | ||
195 | return false | ||
196 | } | ||
197 | c = iter.nextToken() | ||
198 | } | ||
199 | if c != '}' { | ||
200 | iter.ReportError("ReadMapCB", `object not ended with }`) | ||
201 | iter.decrementDepth() | ||
202 | return false | ||
203 | } | ||
204 | return iter.decrementDepth() | ||
205 | } | ||
206 | if c == '}' { | ||
207 | return iter.decrementDepth() | ||
208 | } | ||
209 | iter.ReportError("ReadMapCB", `expect " after {, but found `+string([]byte{c})) | ||
210 | iter.decrementDepth() | ||
211 | return false | ||
212 | } | ||
213 | if c == 'n' { | ||
214 | iter.skipThreeBytes('u', 'l', 'l') | ||
215 | return true // null | ||
216 | } | ||
217 | iter.ReportError("ReadMapCB", `expect { or n, but found `+string([]byte{c})) | ||
218 | return false | ||
219 | } | ||
220 | |||
221 | func (iter *Iterator) readObjectStart() bool { | ||
222 | c := iter.nextToken() | ||
223 | if c == '{' { | ||
224 | c = iter.nextToken() | ||
225 | if c == '}' { | ||
226 | return false | ||
227 | } | ||
228 | iter.unreadByte() | ||
229 | return true | ||
230 | } else if c == 'n' { | ||
231 | iter.skipThreeBytes('u', 'l', 'l') | ||
232 | return false | ||
233 | } | ||
234 | iter.ReportError("readObjectStart", "expect { or n, but found "+string([]byte{c})) | ||
235 | return false | ||
236 | } | ||
237 | |||
238 | func (iter *Iterator) readObjectFieldAsBytes() (ret []byte) { | ||
239 | str := iter.ReadStringAsSlice() | ||
240 | if iter.skipWhitespacesWithoutLoadMore() { | ||
241 | if ret == nil { | ||
242 | ret = make([]byte, len(str)) | ||
243 | copy(ret, str) | ||
244 | } | ||
245 | if !iter.loadMore() { | ||
246 | return | ||
247 | } | ||
248 | } | ||
249 | if iter.buf[iter.head] != ':' { | ||
250 | iter.ReportError("readObjectFieldAsBytes", "expect : after object field, but found "+string([]byte{iter.buf[iter.head]})) | ||
251 | return | ||
252 | } | ||
253 | iter.head++ | ||
254 | if iter.skipWhitespacesWithoutLoadMore() { | ||
255 | if ret == nil { | ||
256 | ret = make([]byte, len(str)) | ||
257 | copy(ret, str) | ||
258 | } | ||
259 | if !iter.loadMore() { | ||
260 | return | ||
261 | } | ||
262 | } | ||
263 | if ret == nil { | ||
264 | return str | ||
265 | } | ||
266 | return ret | ||
267 | } | ||
diff --git a/vendor/github.com/json-iterator/go/iter_skip.go b/vendor/github.com/json-iterator/go/iter_skip.go deleted file mode 100644 index e91eefb..0000000 --- a/vendor/github.com/json-iterator/go/iter_skip.go +++ /dev/null | |||
@@ -1,130 +0,0 @@ | |||
1 | package jsoniter | ||
2 | |||
3 | import "fmt" | ||
4 | |||
5 | // ReadNil reads a json object as nil and | ||
6 | // returns whether it's a nil or not | ||
7 | func (iter *Iterator) ReadNil() (ret bool) { | ||
8 | c := iter.nextToken() | ||
9 | if c == 'n' { | ||
10 | iter.skipThreeBytes('u', 'l', 'l') // null | ||
11 | return true | ||
12 | } | ||
13 | iter.unreadByte() | ||
14 | return false | ||
15 | } | ||
16 | |||
17 | // ReadBool reads a json object as BoolValue | ||
18 | func (iter *Iterator) ReadBool() (ret bool) { | ||
19 | c := iter.nextToken() | ||
20 | if c == 't' { | ||
21 | iter.skipThreeBytes('r', 'u', 'e') | ||
22 | return true | ||
23 | } | ||
24 | if c == 'f' { | ||
25 | iter.skipFourBytes('a', 'l', 's', 'e') | ||
26 | return false | ||
27 | } | ||
28 | iter.ReportError("ReadBool", "expect t or f, but found "+string([]byte{c})) | ||
29 | return | ||
30 | } | ||
31 | |||
32 | // SkipAndReturnBytes skip next JSON element, and return its content as []byte. | ||
33 | // The []byte can be kept, it is a copy of data. | ||
34 | func (iter *Iterator) SkipAndReturnBytes() []byte { | ||
35 | iter.startCapture(iter.head) | ||
36 | iter.Skip() | ||
37 | return iter.stopCapture() | ||
38 | } | ||
39 | |||
40 | // SkipAndAppendBytes skips next JSON element and appends its content to | ||
41 | // buffer, returning the result. | ||
42 | func (iter *Iterator) SkipAndAppendBytes(buf []byte) []byte { | ||
43 | iter.startCaptureTo(buf, iter.head) | ||
44 | iter.Skip() | ||
45 | return iter.stopCapture() | ||
46 | } | ||
47 | |||
48 | func (iter *Iterator) startCaptureTo(buf []byte, captureStartedAt int) { | ||
49 | if iter.captured != nil { | ||
50 | panic("already in capture mode") | ||
51 | } | ||
52 | iter.captureStartedAt = captureStartedAt | ||
53 | iter.captured = buf | ||
54 | } | ||
55 | |||
56 | func (iter *Iterator) startCapture(captureStartedAt int) { | ||
57 | iter.startCaptureTo(make([]byte, 0, 32), captureStartedAt) | ||
58 | } | ||
59 | |||
60 | func (iter *Iterator) stopCapture() []byte { | ||
61 | if iter.captured == nil { | ||
62 | panic("not in capture mode") | ||
63 | } | ||
64 | captured := iter.captured | ||
65 | remaining := iter.buf[iter.captureStartedAt:iter.head] | ||
66 | iter.captureStartedAt = -1 | ||
67 | iter.captured = nil | ||
68 | return append(captured, remaining...) | ||
69 | } | ||
70 | |||
71 | // Skip skips a json object and positions to relatively the next json object | ||
72 | func (iter *Iterator) Skip() { | ||
73 | c := iter.nextToken() | ||
74 | switch c { | ||
75 | case '"': | ||
76 | iter.skipString() | ||
77 | case 'n': | ||
78 | iter.skipThreeBytes('u', 'l', 'l') // null | ||
79 | case 't': | ||
80 | iter.skipThreeBytes('r', 'u', 'e') // true | ||
81 | case 'f': | ||
82 | iter.skipFourBytes('a', 'l', 's', 'e') // false | ||
83 | case '0': | ||
84 | iter.unreadByte() | ||
85 | iter.ReadFloat32() | ||
86 | case '-', '1', '2', '3', '4', '5', '6', '7', '8', '9': | ||
87 | iter.skipNumber() | ||
88 | case '[': | ||
89 | iter.skipArray() | ||
90 | case '{': | ||
91 | iter.skipObject() | ||
92 | default: | ||
93 | iter.ReportError("Skip", fmt.Sprintf("do not know how to skip: %v", c)) | ||
94 | return | ||
95 | } | ||
96 | } | ||
97 | |||
98 | func (iter *Iterator) skipFourBytes(b1, b2, b3, b4 byte) { | ||
99 | if iter.readByte() != b1 { | ||
100 | iter.ReportError("skipFourBytes", fmt.Sprintf("expect %s", string([]byte{b1, b2, b3, b4}))) | ||
101 | return | ||
102 | } | ||
103 | if iter.readByte() != b2 { | ||
104 | iter.ReportError("skipFourBytes", fmt.Sprintf("expect %s", string([]byte{b1, b2, b3, b4}))) | ||
105 | return | ||
106 | } | ||
107 | if iter.readByte() != b3 { | ||
108 | iter.ReportError("skipFourBytes", fmt.Sprintf("expect %s", string([]byte{b1, b2, b3, b4}))) | ||
109 | return | ||
110 | } | ||
111 | if iter.readByte() != b4 { | ||
112 | iter.ReportError("skipFourBytes", fmt.Sprintf("expect %s", string([]byte{b1, b2, b3, b4}))) | ||
113 | return | ||
114 | } | ||
115 | } | ||
116 | |||
117 | func (iter *Iterator) skipThreeBytes(b1, b2, b3 byte) { | ||
118 | if iter.readByte() != b1 { | ||
119 | iter.ReportError("skipThreeBytes", fmt.Sprintf("expect %s", string([]byte{b1, b2, b3}))) | ||
120 | return | ||
121 | } | ||
122 | if iter.readByte() != b2 { | ||
123 | iter.ReportError("skipThreeBytes", fmt.Sprintf("expect %s", string([]byte{b1, b2, b3}))) | ||
124 | return | ||
125 | } | ||
126 | if iter.readByte() != b3 { | ||
127 | iter.ReportError("skipThreeBytes", fmt.Sprintf("expect %s", string([]byte{b1, b2, b3}))) | ||
128 | return | ||
129 | } | ||
130 | } | ||
diff --git a/vendor/github.com/json-iterator/go/iter_skip_sloppy.go b/vendor/github.com/json-iterator/go/iter_skip_sloppy.go deleted file mode 100644 index 9303de4..0000000 --- a/vendor/github.com/json-iterator/go/iter_skip_sloppy.go +++ /dev/null | |||
@@ -1,163 +0,0 @@ | |||
1 | //+build jsoniter_sloppy | ||
2 | |||
3 | package jsoniter | ||
4 | |||
5 | // sloppy but faster implementation, do not validate the input json | ||
6 | |||
7 | func (iter *Iterator) skipNumber() { | ||
8 | for { | ||
9 | for i := iter.head; i < iter.tail; i++ { | ||
10 | c := iter.buf[i] | ||
11 | switch c { | ||
12 | case ' ', '\n', '\r', '\t', ',', '}', ']': | ||
13 | iter.head = i | ||
14 | return | ||
15 | } | ||
16 | } | ||
17 | if !iter.loadMore() { | ||
18 | return | ||
19 | } | ||
20 | } | ||
21 | } | ||
22 | |||
23 | func (iter *Iterator) skipArray() { | ||
24 | level := 1 | ||
25 | if !iter.incrementDepth() { | ||
26 | return | ||
27 | } | ||
28 | for { | ||
29 | for i := iter.head; i < iter.tail; i++ { | ||
30 | switch iter.buf[i] { | ||
31 | case '"': // If inside string, skip it | ||
32 | iter.head = i + 1 | ||
33 | iter.skipString() | ||
34 | i = iter.head - 1 // it will be i++ soon | ||
35 | case '[': // If open symbol, increase level | ||
36 | level++ | ||
37 | if !iter.incrementDepth() { | ||
38 | return | ||
39 | } | ||
40 | case ']': // If close symbol, increase level | ||
41 | level-- | ||
42 | if !iter.decrementDepth() { | ||
43 | return | ||
44 | } | ||
45 | |||
46 | // If we have returned to the original level, we're done | ||
47 | if level == 0 { | ||
48 | iter.head = i + 1 | ||
49 | return | ||
50 | } | ||
51 | } | ||
52 | } | ||
53 | if !iter.loadMore() { | ||
54 | iter.ReportError("skipObject", "incomplete array") | ||
55 | return | ||
56 | } | ||
57 | } | ||
58 | } | ||
59 | |||
60 | func (iter *Iterator) skipObject() { | ||
61 | level := 1 | ||
62 | if !iter.incrementDepth() { | ||
63 | return | ||
64 | } | ||
65 | |||
66 | for { | ||
67 | for i := iter.head; i < iter.tail; i++ { | ||
68 | switch iter.buf[i] { | ||
69 | case '"': // If inside string, skip it | ||
70 | iter.head = i + 1 | ||
71 | iter.skipString() | ||
72 | i = iter.head - 1 // it will be i++ soon | ||
73 | case '{': // If open symbol, increase level | ||
74 | level++ | ||
75 | if !iter.incrementDepth() { | ||
76 | return | ||
77 | } | ||
78 | case '}': // If close symbol, increase level | ||
79 | level-- | ||
80 | if !iter.decrementDepth() { | ||
81 | return | ||
82 | } | ||
83 | |||
84 | // If we have returned to the original level, we're done | ||
85 | if level == 0 { | ||
86 | iter.head = i + 1 | ||
87 | return | ||
88 | } | ||
89 | } | ||
90 | } | ||
91 | if !iter.loadMore() { | ||
92 | iter.ReportError("skipObject", "incomplete object") | ||
93 | return | ||
94 | } | ||
95 | } | ||
96 | } | ||
97 | |||
98 | func (iter *Iterator) skipString() { | ||
99 | for { | ||
100 | end, escaped := iter.findStringEnd() | ||
101 | if end == -1 { | ||
102 | if !iter.loadMore() { | ||
103 | iter.ReportError("skipString", "incomplete string") | ||
104 | return | ||
105 | } | ||
106 | if escaped { | ||
107 | iter.head = 1 // skip the first char as last char read is \ | ||
108 | } | ||
109 | } else { | ||
110 | iter.head = end | ||
111 | return | ||
112 | } | ||
113 | } | ||
114 | } | ||
115 | |||
116 | // adapted from: https://github.com/buger/jsonparser/blob/master/parser.go | ||
117 | // Tries to find the end of string | ||
118 | // Support if string contains escaped quote symbols. | ||
119 | func (iter *Iterator) findStringEnd() (int, bool) { | ||
120 | escaped := false | ||
121 | for i := iter.head; i < iter.tail; i++ { | ||
122 | c := iter.buf[i] | ||
123 | if c == '"' { | ||
124 | if !escaped { | ||
125 | return i + 1, false | ||
126 | } | ||
127 | j := i - 1 | ||
128 | for { | ||
129 | if j < iter.head || iter.buf[j] != '\\' { | ||
130 | // even number of backslashes | ||
131 | // either end of buffer, or " found | ||
132 | return i + 1, true | ||
133 | } | ||
134 | j-- | ||
135 | if j < iter.head || iter.buf[j] != '\\' { | ||
136 | // odd number of backslashes | ||
137 | // it is \" or \\\" | ||
138 | break | ||
139 | } | ||
140 | j-- | ||
141 | } | ||
142 | } else if c == '\\' { | ||
143 | escaped = true | ||
144 | } | ||
145 | } | ||
146 | j := iter.tail - 1 | ||
147 | for { | ||
148 | if j < iter.head || iter.buf[j] != '\\' { | ||
149 | // even number of backslashes | ||
150 | // either end of buffer, or " found | ||
151 | return -1, false // do not end with \ | ||
152 | } | ||
153 | j-- | ||
154 | if j < iter.head || iter.buf[j] != '\\' { | ||
155 | // odd number of backslashes | ||
156 | // it is \" or \\\" | ||
157 | break | ||
158 | } | ||
159 | j-- | ||
160 | |||
161 | } | ||
162 | return -1, true // end with \ | ||
163 | } | ||
diff --git a/vendor/github.com/json-iterator/go/iter_skip_strict.go b/vendor/github.com/json-iterator/go/iter_skip_strict.go deleted file mode 100644 index 6cf66d0..0000000 --- a/vendor/github.com/json-iterator/go/iter_skip_strict.go +++ /dev/null | |||
@@ -1,99 +0,0 @@ | |||
1 | //+build !jsoniter_sloppy | ||
2 | |||
3 | package jsoniter | ||
4 | |||
5 | import ( | ||
6 | "fmt" | ||
7 | "io" | ||
8 | ) | ||
9 | |||
10 | func (iter *Iterator) skipNumber() { | ||
11 | if !iter.trySkipNumber() { | ||
12 | iter.unreadByte() | ||
13 | if iter.Error != nil && iter.Error != io.EOF { | ||
14 | return | ||
15 | } | ||
16 | iter.ReadFloat64() | ||
17 | if iter.Error != nil && iter.Error != io.EOF { | ||
18 | iter.Error = nil | ||
19 | iter.ReadBigFloat() | ||
20 | } | ||
21 | } | ||
22 | } | ||
23 | |||
24 | func (iter *Iterator) trySkipNumber() bool { | ||
25 | dotFound := false | ||
26 | for i := iter.head; i < iter.tail; i++ { | ||
27 | c := iter.buf[i] | ||
28 | switch c { | ||
29 | case '0', '1', '2', '3', '4', '5', '6', '7', '8', '9': | ||
30 | case '.': | ||
31 | if dotFound { | ||
32 | iter.ReportError("validateNumber", `more than one dot found in number`) | ||
33 | return true // already failed | ||
34 | } | ||
35 | if i+1 == iter.tail { | ||
36 | return false | ||
37 | } | ||
38 | c = iter.buf[i+1] | ||
39 | switch c { | ||
40 | case '0', '1', '2', '3', '4', '5', '6', '7', '8', '9': | ||
41 | default: | ||
42 | iter.ReportError("validateNumber", `missing digit after dot`) | ||
43 | return true // already failed | ||
44 | } | ||
45 | dotFound = true | ||
46 | default: | ||
47 | switch c { | ||
48 | case ',', ']', '}', ' ', '\t', '\n', '\r': | ||
49 | if iter.head == i { | ||
50 | return false // if - without following digits | ||
51 | } | ||
52 | iter.head = i | ||
53 | return true // must be valid | ||
54 | } | ||
55 | return false // may be invalid | ||
56 | } | ||
57 | } | ||
58 | return false | ||
59 | } | ||
60 | |||
61 | func (iter *Iterator) skipString() { | ||
62 | if !iter.trySkipString() { | ||
63 | iter.unreadByte() | ||
64 | iter.ReadString() | ||
65 | } | ||
66 | } | ||
67 | |||
68 | func (iter *Iterator) trySkipString() bool { | ||
69 | for i := iter.head; i < iter.tail; i++ { | ||
70 | c := iter.buf[i] | ||
71 | if c == '"' { | ||
72 | iter.head = i + 1 | ||
73 | return true // valid | ||
74 | } else if c == '\\' { | ||
75 | return false | ||
76 | } else if c < ' ' { | ||
77 | iter.ReportError("trySkipString", | ||
78 | fmt.Sprintf(`invalid control character found: %d`, c)) | ||
79 | return true // already failed | ||
80 | } | ||
81 | } | ||
82 | return false | ||
83 | } | ||
84 | |||
85 | func (iter *Iterator) skipObject() { | ||
86 | iter.unreadByte() | ||
87 | iter.ReadObjectCB(func(iter *Iterator, field string) bool { | ||
88 | iter.Skip() | ||
89 | return true | ||
90 | }) | ||
91 | } | ||
92 | |||
93 | func (iter *Iterator) skipArray() { | ||
94 | iter.unreadByte() | ||
95 | iter.ReadArrayCB(func(iter *Iterator) bool { | ||
96 | iter.Skip() | ||
97 | return true | ||
98 | }) | ||
99 | } | ||
diff --git a/vendor/github.com/json-iterator/go/iter_str.go b/vendor/github.com/json-iterator/go/iter_str.go deleted file mode 100644 index adc487e..0000000 --- a/vendor/github.com/json-iterator/go/iter_str.go +++ /dev/null | |||
@@ -1,215 +0,0 @@ | |||
1 | package jsoniter | ||
2 | |||
3 | import ( | ||
4 | "fmt" | ||
5 | "unicode/utf16" | ||
6 | ) | ||
7 | |||
8 | // ReadString read string from iterator | ||
9 | func (iter *Iterator) ReadString() (ret string) { | ||
10 | c := iter.nextToken() | ||
11 | if c == '"' { | ||
12 | for i := iter.head; i < iter.tail; i++ { | ||
13 | c := iter.buf[i] | ||
14 | if c == '"' { | ||
15 | ret = string(iter.buf[iter.head:i]) | ||
16 | iter.head = i + 1 | ||
17 | return ret | ||
18 | } else if c == '\\' { | ||
19 | break | ||
20 | } else if c < ' ' { | ||
21 | iter.ReportError("ReadString", | ||
22 | fmt.Sprintf(`invalid control character found: %d`, c)) | ||
23 | return | ||
24 | } | ||
25 | } | ||
26 | return iter.readStringSlowPath() | ||
27 | } else if c == 'n' { | ||
28 | iter.skipThreeBytes('u', 'l', 'l') | ||
29 | return "" | ||
30 | } | ||
31 | iter.ReportError("ReadString", `expects " or n, but found `+string([]byte{c})) | ||
32 | return | ||
33 | } | ||
34 | |||
35 | func (iter *Iterator) readStringSlowPath() (ret string) { | ||
36 | var str []byte | ||
37 | var c byte | ||
38 | for iter.Error == nil { | ||
39 | c = iter.readByte() | ||
40 | if c == '"' { | ||
41 | return string(str) | ||
42 | } | ||
43 | if c == '\\' { | ||
44 | c = iter.readByte() | ||
45 | str = iter.readEscapedChar(c, str) | ||
46 | } else { | ||
47 | str = append(str, c) | ||
48 | } | ||
49 | } | ||
50 | iter.ReportError("readStringSlowPath", "unexpected end of input") | ||
51 | return | ||
52 | } | ||
53 | |||
54 | func (iter *Iterator) readEscapedChar(c byte, str []byte) []byte { | ||
55 | switch c { | ||
56 | case 'u': | ||
57 | r := iter.readU4() | ||
58 | if utf16.IsSurrogate(r) { | ||
59 | c = iter.readByte() | ||
60 | if iter.Error != nil { | ||
61 | return nil | ||
62 | } | ||
63 | if c != '\\' { | ||
64 | iter.unreadByte() | ||
65 | str = appendRune(str, r) | ||
66 | return str | ||
67 | } | ||
68 | c = iter.readByte() | ||
69 | if iter.Error != nil { | ||
70 | return nil | ||
71 | } | ||
72 | if c != 'u' { | ||
73 | str = appendRune(str, r) | ||
74 | return iter.readEscapedChar(c, str) | ||
75 | } | ||
76 | r2 := iter.readU4() | ||
77 | if iter.Error != nil { | ||
78 | return nil | ||
79 | } | ||
80 | combined := utf16.DecodeRune(r, r2) | ||
81 | if combined == '\uFFFD' { | ||
82 | str = appendRune(str, r) | ||
83 | str = appendRune(str, r2) | ||
84 | } else { | ||
85 | str = appendRune(str, combined) | ||
86 | } | ||
87 | } else { | ||
88 | str = appendRune(str, r) | ||
89 | } | ||
90 | case '"': | ||
91 | str = append(str, '"') | ||
92 | case '\\': | ||
93 | str = append(str, '\\') | ||
94 | case '/': | ||
95 | str = append(str, '/') | ||
96 | case 'b': | ||
97 | str = append(str, '\b') | ||
98 | case 'f': | ||
99 | str = append(str, '\f') | ||
100 | case 'n': | ||
101 | str = append(str, '\n') | ||
102 | case 'r': | ||
103 | str = append(str, '\r') | ||
104 | case 't': | ||
105 | str = append(str, '\t') | ||
106 | default: | ||
107 | iter.ReportError("readEscapedChar", | ||
108 | `invalid escape char after \`) | ||
109 | return nil | ||
110 | } | ||
111 | return str | ||
112 | } | ||
113 | |||
114 | // ReadStringAsSlice read string from iterator without copying into string form. | ||
115 | // The []byte can not be kept, as it will change after next iterator call. | ||
116 | func (iter *Iterator) ReadStringAsSlice() (ret []byte) { | ||
117 | c := iter.nextToken() | ||
118 | if c == '"' { | ||
119 | for i := iter.head; i < iter.tail; i++ { | ||
120 | // require ascii string and no escape | ||
121 | // for: field name, base64, number | ||
122 | if iter.buf[i] == '"' { | ||
123 | // fast path: reuse the underlying buffer | ||
124 | ret = iter.buf[iter.head:i] | ||
125 | iter.head = i + 1 | ||
126 | return ret | ||
127 | } | ||
128 | } | ||
129 | readLen := iter.tail - iter.head | ||
130 | copied := make([]byte, readLen, readLen*2) | ||
131 | copy(copied, iter.buf[iter.head:iter.tail]) | ||
132 | iter.head = iter.tail | ||
133 | for iter.Error == nil { | ||
134 | c := iter.readByte() | ||
135 | if c == '"' { | ||
136 | return copied | ||
137 | } | ||
138 | copied = append(copied, c) | ||
139 | } | ||
140 | return copied | ||
141 | } | ||
142 | iter.ReportError("ReadStringAsSlice", `expects " or n, but found `+string([]byte{c})) | ||
143 | return | ||
144 | } | ||
145 | |||
146 | func (iter *Iterator) readU4() (ret rune) { | ||
147 | for i := 0; i < 4; i++ { | ||
148 | c := iter.readByte() | ||
149 | if iter.Error != nil { | ||
150 | return | ||
151 | } | ||
152 | if c >= '0' && c <= '9' { | ||
153 | ret = ret*16 + rune(c-'0') | ||
154 | } else if c >= 'a' && c <= 'f' { | ||
155 | ret = ret*16 + rune(c-'a'+10) | ||
156 | } else if c >= 'A' && c <= 'F' { | ||
157 | ret = ret*16 + rune(c-'A'+10) | ||
158 | } else { | ||
159 | iter.ReportError("readU4", "expects 0~9 or a~f, but found "+string([]byte{c})) | ||
160 | return | ||
161 | } | ||
162 | } | ||
163 | return ret | ||
164 | } | ||
165 | |||
166 | const ( | ||
167 | t1 = 0x00 // 0000 0000 | ||
168 | tx = 0x80 // 1000 0000 | ||
169 | t2 = 0xC0 // 1100 0000 | ||
170 | t3 = 0xE0 // 1110 0000 | ||
171 | t4 = 0xF0 // 1111 0000 | ||
172 | t5 = 0xF8 // 1111 1000 | ||
173 | |||
174 | maskx = 0x3F // 0011 1111 | ||
175 | mask2 = 0x1F // 0001 1111 | ||
176 | mask3 = 0x0F // 0000 1111 | ||
177 | mask4 = 0x07 // 0000 0111 | ||
178 | |||
179 | rune1Max = 1<<7 - 1 | ||
180 | rune2Max = 1<<11 - 1 | ||
181 | rune3Max = 1<<16 - 1 | ||
182 | |||
183 | surrogateMin = 0xD800 | ||
184 | surrogateMax = 0xDFFF | ||
185 | |||
186 | maxRune = '\U0010FFFF' // Maximum valid Unicode code point. | ||
187 | runeError = '\uFFFD' // the "error" Rune or "Unicode replacement character" | ||
188 | ) | ||
189 | |||
190 | func appendRune(p []byte, r rune) []byte { | ||
191 | // Negative values are erroneous. Making it unsigned addresses the problem. | ||
192 | switch i := uint32(r); { | ||
193 | case i <= rune1Max: | ||
194 | p = append(p, byte(r)) | ||
195 | return p | ||
196 | case i <= rune2Max: | ||
197 | p = append(p, t2|byte(r>>6)) | ||
198 | p = append(p, tx|byte(r)&maskx) | ||
199 | return p | ||
200 | case i > maxRune, surrogateMin <= i && i <= surrogateMax: | ||
201 | r = runeError | ||
202 | fallthrough | ||
203 | case i <= rune3Max: | ||
204 | p = append(p, t3|byte(r>>12)) | ||
205 | p = append(p, tx|byte(r>>6)&maskx) | ||
206 | p = append(p, tx|byte(r)&maskx) | ||
207 | return p | ||
208 | default: | ||
209 | p = append(p, t4|byte(r>>18)) | ||
210 | p = append(p, tx|byte(r>>12)&maskx) | ||
211 | p = append(p, tx|byte(r>>6)&maskx) | ||
212 | p = append(p, tx|byte(r)&maskx) | ||
213 | return p | ||
214 | } | ||
215 | } | ||
diff --git a/vendor/github.com/json-iterator/go/jsoniter.go b/vendor/github.com/json-iterator/go/jsoniter.go deleted file mode 100644 index c2934f9..0000000 --- a/vendor/github.com/json-iterator/go/jsoniter.go +++ /dev/null | |||
@@ -1,18 +0,0 @@ | |||
1 | // Package jsoniter implements encoding and decoding of JSON as defined in | ||
2 | // RFC 4627 and provides interfaces with identical syntax of standard lib encoding/json. | ||
3 | // Converting from encoding/json to jsoniter is no more than replacing the package with jsoniter | ||
4 | // and variable type declarations (if any). | ||
5 | // jsoniter interfaces gives 100% compatibility with code using standard lib. | ||
6 | // | ||
7 | // "JSON and Go" | ||
8 | // (https://golang.org/doc/articles/json_and_go.html) | ||
9 | // gives a description of how Marshal/Unmarshal operate | ||
10 | // between arbitrary or predefined json objects and bytes, | ||
11 | // and it applies to jsoniter.Marshal/Unmarshal as well. | ||
12 | // | ||
13 | // Besides, jsoniter.Iterator provides a different set of interfaces | ||
14 | // iterating given bytes/string/reader | ||
15 | // and yielding parsed elements one by one. | ||
16 | // This set of interfaces reads input as required and gives | ||
17 | // better performance. | ||
18 | package jsoniter | ||
diff --git a/vendor/github.com/json-iterator/go/pool.go b/vendor/github.com/json-iterator/go/pool.go deleted file mode 100644 index e2389b5..0000000 --- a/vendor/github.com/json-iterator/go/pool.go +++ /dev/null | |||
@@ -1,42 +0,0 @@ | |||
1 | package jsoniter | ||
2 | |||
3 | import ( | ||
4 | "io" | ||
5 | ) | ||
6 | |||
7 | // IteratorPool a thread safe pool of iterators with same configuration | ||
8 | type IteratorPool interface { | ||
9 | BorrowIterator(data []byte) *Iterator | ||
10 | ReturnIterator(iter *Iterator) | ||
11 | } | ||
12 | |||
13 | // StreamPool a thread safe pool of streams with same configuration | ||
14 | type StreamPool interface { | ||
15 | BorrowStream(writer io.Writer) *Stream | ||
16 | ReturnStream(stream *Stream) | ||
17 | } | ||
18 | |||
19 | func (cfg *frozenConfig) BorrowStream(writer io.Writer) *Stream { | ||
20 | stream := cfg.streamPool.Get().(*Stream) | ||
21 | stream.Reset(writer) | ||
22 | return stream | ||
23 | } | ||
24 | |||
25 | func (cfg *frozenConfig) ReturnStream(stream *Stream) { | ||
26 | stream.out = nil | ||
27 | stream.Error = nil | ||
28 | stream.Attachment = nil | ||
29 | cfg.streamPool.Put(stream) | ||
30 | } | ||
31 | |||
32 | func (cfg *frozenConfig) BorrowIterator(data []byte) *Iterator { | ||
33 | iter := cfg.iteratorPool.Get().(*Iterator) | ||
34 | iter.ResetBytes(data) | ||
35 | return iter | ||
36 | } | ||
37 | |||
38 | func (cfg *frozenConfig) ReturnIterator(iter *Iterator) { | ||
39 | iter.Error = nil | ||
40 | iter.Attachment = nil | ||
41 | cfg.iteratorPool.Put(iter) | ||
42 | } | ||
diff --git a/vendor/github.com/json-iterator/go/reflect.go b/vendor/github.com/json-iterator/go/reflect.go deleted file mode 100644 index 39acb32..0000000 --- a/vendor/github.com/json-iterator/go/reflect.go +++ /dev/null | |||
@@ -1,337 +0,0 @@ | |||
1 | package jsoniter | ||
2 | |||
3 | import ( | ||
4 | "fmt" | ||
5 | "reflect" | ||
6 | "unsafe" | ||
7 | |||
8 | "github.com/modern-go/reflect2" | ||
9 | ) | ||
10 | |||
11 | // ValDecoder is an internal type registered to cache as needed. | ||
12 | // Don't confuse jsoniter.ValDecoder with json.Decoder. | ||
13 | // For json.Decoder's adapter, refer to jsoniter.AdapterDecoder(todo link). | ||
14 | // | ||
15 | // Reflection on type to create decoders, which is then cached | ||
16 | // Reflection on value is avoided as we can, as the reflect.Value itself will allocate, with following exceptions | ||
17 | // 1. create instance of new value, for example *int will need a int to be allocated | ||
18 | // 2. append to slice, if the existing cap is not enough, allocate will be done using Reflect.New | ||
19 | // 3. assignment to map, both key and value will be reflect.Value | ||
20 | // For a simple struct binding, it will be reflect.Value free and allocation free | ||
21 | type ValDecoder interface { | ||
22 | Decode(ptr unsafe.Pointer, iter *Iterator) | ||
23 | } | ||
24 | |||
25 | // ValEncoder is an internal type registered to cache as needed. | ||
26 | // Don't confuse jsoniter.ValEncoder with json.Encoder. | ||
27 | // For json.Encoder's adapter, refer to jsoniter.AdapterEncoder(todo godoc link). | ||
28 | type ValEncoder interface { | ||
29 | IsEmpty(ptr unsafe.Pointer) bool | ||
30 | Encode(ptr unsafe.Pointer, stream *Stream) | ||
31 | } | ||
32 | |||
33 | type checkIsEmpty interface { | ||
34 | IsEmpty(ptr unsafe.Pointer) bool | ||
35 | } | ||
36 | |||
37 | type ctx struct { | ||
38 | *frozenConfig | ||
39 | prefix string | ||
40 | encoders map[reflect2.Type]ValEncoder | ||
41 | decoders map[reflect2.Type]ValDecoder | ||
42 | } | ||
43 | |||
44 | func (b *ctx) caseSensitive() bool { | ||
45 | if b.frozenConfig == nil { | ||
46 | // default is case-insensitive | ||
47 | return false | ||
48 | } | ||
49 | return b.frozenConfig.caseSensitive | ||
50 | } | ||
51 | |||
52 | func (b *ctx) append(prefix string) *ctx { | ||
53 | return &ctx{ | ||
54 | frozenConfig: b.frozenConfig, | ||
55 | prefix: b.prefix + " " + prefix, | ||
56 | encoders: b.encoders, | ||
57 | decoders: b.decoders, | ||
58 | } | ||
59 | } | ||
60 | |||
61 | // ReadVal copy the underlying JSON into go interface, same as json.Unmarshal | ||
62 | func (iter *Iterator) ReadVal(obj interface{}) { | ||
63 | depth := iter.depth | ||
64 | cacheKey := reflect2.RTypeOf(obj) | ||
65 | decoder := iter.cfg.getDecoderFromCache(cacheKey) | ||
66 | if decoder == nil { | ||
67 | typ := reflect2.TypeOf(obj) | ||
68 | if typ == nil || typ.Kind() != reflect.Ptr { | ||
69 | iter.ReportError("ReadVal", "can only unmarshal into pointer") | ||
70 | return | ||
71 | } | ||
72 | decoder = iter.cfg.DecoderOf(typ) | ||
73 | } | ||
74 | ptr := reflect2.PtrOf(obj) | ||
75 | if ptr == nil { | ||
76 | iter.ReportError("ReadVal", "can not read into nil pointer") | ||
77 | return | ||
78 | } | ||
79 | decoder.Decode(ptr, iter) | ||
80 | if iter.depth != depth { | ||
81 | iter.ReportError("ReadVal", "unexpected mismatched nesting") | ||
82 | return | ||
83 | } | ||
84 | } | ||
85 | |||
86 | // WriteVal copy the go interface into underlying JSON, same as json.Marshal | ||
87 | func (stream *Stream) WriteVal(val interface{}) { | ||
88 | if nil == val { | ||
89 | stream.WriteNil() | ||
90 | return | ||
91 | } | ||
92 | cacheKey := reflect2.RTypeOf(val) | ||
93 | encoder := stream.cfg.getEncoderFromCache(cacheKey) | ||
94 | if encoder == nil { | ||
95 | typ := reflect2.TypeOf(val) | ||
96 | encoder = stream.cfg.EncoderOf(typ) | ||
97 | } | ||
98 | encoder.Encode(reflect2.PtrOf(val), stream) | ||
99 | } | ||
100 | |||
101 | func (cfg *frozenConfig) DecoderOf(typ reflect2.Type) ValDecoder { | ||
102 | cacheKey := typ.RType() | ||
103 | decoder := cfg.getDecoderFromCache(cacheKey) | ||
104 | if decoder != nil { | ||
105 | return decoder | ||
106 | } | ||
107 | ctx := &ctx{ | ||
108 | frozenConfig: cfg, | ||
109 | prefix: "", | ||
110 | decoders: map[reflect2.Type]ValDecoder{}, | ||
111 | encoders: map[reflect2.Type]ValEncoder{}, | ||
112 | } | ||
113 | ptrType := typ.(*reflect2.UnsafePtrType) | ||
114 | decoder = decoderOfType(ctx, ptrType.Elem()) | ||
115 | cfg.addDecoderToCache(cacheKey, decoder) | ||
116 | return decoder | ||
117 | } | ||
118 | |||
119 | func decoderOfType(ctx *ctx, typ reflect2.Type) ValDecoder { | ||
120 | decoder := getTypeDecoderFromExtension(ctx, typ) | ||
121 | if decoder != nil { | ||
122 | return decoder | ||
123 | } | ||
124 | decoder = createDecoderOfType(ctx, typ) | ||
125 | for _, extension := range extensions { | ||
126 | decoder = extension.DecorateDecoder(typ, decoder) | ||
127 | } | ||
128 | decoder = ctx.decoderExtension.DecorateDecoder(typ, decoder) | ||
129 | for _, extension := range ctx.extraExtensions { | ||
130 | decoder = extension.DecorateDecoder(typ, decoder) | ||
131 | } | ||
132 | return decoder | ||
133 | } | ||
134 | |||
135 | func createDecoderOfType(ctx *ctx, typ reflect2.Type) ValDecoder { | ||
136 | decoder := ctx.decoders[typ] | ||
137 | if decoder != nil { | ||
138 | return decoder | ||
139 | } | ||
140 | placeholder := &placeholderDecoder{} | ||
141 | ctx.decoders[typ] = placeholder | ||
142 | decoder = _createDecoderOfType(ctx, typ) | ||
143 | placeholder.decoder = decoder | ||
144 | return decoder | ||
145 | } | ||
146 | |||
147 | func _createDecoderOfType(ctx *ctx, typ reflect2.Type) ValDecoder { | ||
148 | decoder := createDecoderOfJsonRawMessage(ctx, typ) | ||
149 | if decoder != nil { | ||
150 | return decoder | ||
151 | } | ||
152 | decoder = createDecoderOfJsonNumber(ctx, typ) | ||
153 | if decoder != nil { | ||
154 | return decoder | ||
155 | } | ||
156 | decoder = createDecoderOfMarshaler(ctx, typ) | ||
157 | if decoder != nil { | ||
158 | return decoder | ||
159 | } | ||
160 | decoder = createDecoderOfAny(ctx, typ) | ||
161 | if decoder != nil { | ||
162 | return decoder | ||
163 | } | ||
164 | decoder = createDecoderOfNative(ctx, typ) | ||
165 | if decoder != nil { | ||
166 | return decoder | ||
167 | } | ||
168 | switch typ.Kind() { | ||
169 | case reflect.Interface: | ||
170 | ifaceType, isIFace := typ.(*reflect2.UnsafeIFaceType) | ||
171 | if isIFace { | ||
172 | return &ifaceDecoder{valType: ifaceType} | ||
173 | } | ||
174 | return &efaceDecoder{} | ||
175 | case reflect.Struct: | ||
176 | return decoderOfStruct(ctx, typ) | ||
177 | case reflect.Array: | ||
178 | return decoderOfArray(ctx, typ) | ||
179 | case reflect.Slice: | ||
180 | return decoderOfSlice(ctx, typ) | ||
181 | case reflect.Map: | ||
182 | return decoderOfMap(ctx, typ) | ||
183 | case reflect.Ptr: | ||
184 | return decoderOfOptional(ctx, typ) | ||
185 | default: | ||
186 | return &lazyErrorDecoder{err: fmt.Errorf("%s%s is unsupported type", ctx.prefix, typ.String())} | ||
187 | } | ||
188 | } | ||
189 | |||
190 | func (cfg *frozenConfig) EncoderOf(typ reflect2.Type) ValEncoder { | ||
191 | cacheKey := typ.RType() | ||
192 | encoder := cfg.getEncoderFromCache(cacheKey) | ||
193 | if encoder != nil { | ||
194 | return encoder | ||
195 | } | ||
196 | ctx := &ctx{ | ||
197 | frozenConfig: cfg, | ||
198 | prefix: "", | ||
199 | decoders: map[reflect2.Type]ValDecoder{}, | ||
200 | encoders: map[reflect2.Type]ValEncoder{}, | ||
201 | } | ||
202 | encoder = encoderOfType(ctx, typ) | ||
203 | if typ.LikePtr() { | ||
204 | encoder = &onePtrEncoder{encoder} | ||
205 | } | ||
206 | cfg.addEncoderToCache(cacheKey, encoder) | ||
207 | return encoder | ||
208 | } | ||
209 | |||
210 | type onePtrEncoder struct { | ||
211 | encoder ValEncoder | ||
212 | } | ||
213 | |||
214 | func (encoder *onePtrEncoder) IsEmpty(ptr unsafe.Pointer) bool { | ||
215 | return encoder.encoder.IsEmpty(unsafe.Pointer(&ptr)) | ||
216 | } | ||
217 | |||
218 | func (encoder *onePtrEncoder) Encode(ptr unsafe.Pointer, stream *Stream) { | ||
219 | encoder.encoder.Encode(unsafe.Pointer(&ptr), stream) | ||
220 | } | ||
221 | |||
222 | func encoderOfType(ctx *ctx, typ reflect2.Type) ValEncoder { | ||
223 | encoder := getTypeEncoderFromExtension(ctx, typ) | ||
224 | if encoder != nil { | ||
225 | return encoder | ||
226 | } | ||
227 | encoder = createEncoderOfType(ctx, typ) | ||
228 | for _, extension := range extensions { | ||
229 | encoder = extension.DecorateEncoder(typ, encoder) | ||
230 | } | ||
231 | encoder = ctx.encoderExtension.DecorateEncoder(typ, encoder) | ||
232 | for _, extension := range ctx.extraExtensions { | ||
233 | encoder = extension.DecorateEncoder(typ, encoder) | ||
234 | } | ||
235 | return encoder | ||
236 | } | ||
237 | |||
238 | func createEncoderOfType(ctx *ctx, typ reflect2.Type) ValEncoder { | ||
239 | encoder := ctx.encoders[typ] | ||
240 | if encoder != nil { | ||
241 | return encoder | ||
242 | } | ||
243 | placeholder := &placeholderEncoder{} | ||
244 | ctx.encoders[typ] = placeholder | ||
245 | encoder = _createEncoderOfType(ctx, typ) | ||
246 | placeholder.encoder = encoder | ||
247 | return encoder | ||
248 | } | ||
249 | func _createEncoderOfType(ctx *ctx, typ reflect2.Type) ValEncoder { | ||
250 | encoder := createEncoderOfJsonRawMessage(ctx, typ) | ||
251 | if encoder != nil { | ||
252 | return encoder | ||
253 | } | ||
254 | encoder = createEncoderOfJsonNumber(ctx, typ) | ||
255 | if encoder != nil { | ||
256 | return encoder | ||
257 | } | ||
258 | encoder = createEncoderOfMarshaler(ctx, typ) | ||
259 | if encoder != nil { | ||
260 | return encoder | ||
261 | } | ||
262 | encoder = createEncoderOfAny(ctx, typ) | ||
263 | if encoder != nil { | ||
264 | return encoder | ||
265 | } | ||
266 | encoder = createEncoderOfNative(ctx, typ) | ||
267 | if encoder != nil { | ||
268 | return encoder | ||
269 | } | ||
270 | kind := typ.Kind() | ||
271 | switch kind { | ||
272 | case reflect.Interface: | ||
273 | return &dynamicEncoder{typ} | ||
274 | case reflect.Struct: | ||
275 | return encoderOfStruct(ctx, typ) | ||
276 | case reflect.Array: | ||
277 | return encoderOfArray(ctx, typ) | ||
278 | case reflect.Slice: | ||
279 | return encoderOfSlice(ctx, typ) | ||
280 | case reflect.Map: | ||
281 | return encoderOfMap(ctx, typ) | ||
282 | case reflect.Ptr: | ||
283 | return encoderOfOptional(ctx, typ) | ||
284 | default: | ||
285 | return &lazyErrorEncoder{err: fmt.Errorf("%s%s is unsupported type", ctx.prefix, typ.String())} | ||
286 | } | ||
287 | } | ||
288 | |||
289 | type lazyErrorDecoder struct { | ||
290 | err error | ||
291 | } | ||
292 | |||
293 | func (decoder *lazyErrorDecoder) Decode(ptr unsafe.Pointer, iter *Iterator) { | ||
294 | if iter.WhatIsNext() != NilValue { | ||
295 | if iter.Error == nil { | ||
296 | iter.Error = decoder.err | ||
297 | } | ||
298 | } else { | ||
299 | iter.Skip() | ||
300 | } | ||
301 | } | ||
302 | |||
303 | type lazyErrorEncoder struct { | ||
304 | err error | ||
305 | } | ||
306 | |||
307 | func (encoder *lazyErrorEncoder) Encode(ptr unsafe.Pointer, stream *Stream) { | ||
308 | if ptr == nil { | ||
309 | stream.WriteNil() | ||
310 | } else if stream.Error == nil { | ||
311 | stream.Error = encoder.err | ||
312 | } | ||
313 | } | ||
314 | |||
315 | func (encoder *lazyErrorEncoder) IsEmpty(ptr unsafe.Pointer) bool { | ||
316 | return false | ||
317 | } | ||
318 | |||
319 | type placeholderDecoder struct { | ||
320 | decoder ValDecoder | ||
321 | } | ||
322 | |||
323 | func (decoder *placeholderDecoder) Decode(ptr unsafe.Pointer, iter *Iterator) { | ||
324 | decoder.decoder.Decode(ptr, iter) | ||
325 | } | ||
326 | |||
327 | type placeholderEncoder struct { | ||
328 | encoder ValEncoder | ||
329 | } | ||
330 | |||
331 | func (encoder *placeholderEncoder) Encode(ptr unsafe.Pointer, stream *Stream) { | ||
332 | encoder.encoder.Encode(ptr, stream) | ||
333 | } | ||
334 | |||
335 | func (encoder *placeholderEncoder) IsEmpty(ptr unsafe.Pointer) bool { | ||
336 | return encoder.encoder.IsEmpty(ptr) | ||
337 | } | ||
diff --git a/vendor/github.com/json-iterator/go/reflect_array.go b/vendor/github.com/json-iterator/go/reflect_array.go deleted file mode 100644 index 13a0b7b..0000000 --- a/vendor/github.com/json-iterator/go/reflect_array.go +++ /dev/null | |||
@@ -1,104 +0,0 @@ | |||
1 | package jsoniter | ||
2 | |||
3 | import ( | ||
4 | "fmt" | ||
5 | "github.com/modern-go/reflect2" | ||
6 | "io" | ||
7 | "unsafe" | ||
8 | ) | ||
9 | |||
10 | func decoderOfArray(ctx *ctx, typ reflect2.Type) ValDecoder { | ||
11 | arrayType := typ.(*reflect2.UnsafeArrayType) | ||
12 | decoder := decoderOfType(ctx.append("[arrayElem]"), arrayType.Elem()) | ||
13 | return &arrayDecoder{arrayType, decoder} | ||
14 | } | ||
15 | |||
16 | func encoderOfArray(ctx *ctx, typ reflect2.Type) ValEncoder { | ||
17 | arrayType := typ.(*reflect2.UnsafeArrayType) | ||
18 | if arrayType.Len() == 0 { | ||
19 | return emptyArrayEncoder{} | ||
20 | } | ||
21 | encoder := encoderOfType(ctx.append("[arrayElem]"), arrayType.Elem()) | ||
22 | return &arrayEncoder{arrayType, encoder} | ||
23 | } | ||
24 | |||
25 | type emptyArrayEncoder struct{} | ||
26 | |||
27 | func (encoder emptyArrayEncoder) Encode(ptr unsafe.Pointer, stream *Stream) { | ||
28 | stream.WriteEmptyArray() | ||
29 | } | ||
30 | |||
31 | func (encoder emptyArrayEncoder) IsEmpty(ptr unsafe.Pointer) bool { | ||
32 | return true | ||
33 | } | ||
34 | |||
35 | type arrayEncoder struct { | ||
36 | arrayType *reflect2.UnsafeArrayType | ||
37 | elemEncoder ValEncoder | ||
38 | } | ||
39 | |||
40 | func (encoder *arrayEncoder) Encode(ptr unsafe.Pointer, stream *Stream) { | ||
41 | stream.WriteArrayStart() | ||
42 | elemPtr := unsafe.Pointer(ptr) | ||
43 | encoder.elemEncoder.Encode(elemPtr, stream) | ||
44 | for i := 1; i < encoder.arrayType.Len(); i++ { | ||
45 | stream.WriteMore() | ||
46 | elemPtr = encoder.arrayType.UnsafeGetIndex(ptr, i) | ||
47 | encoder.elemEncoder.Encode(elemPtr, stream) | ||
48 | } | ||
49 | stream.WriteArrayEnd() | ||
50 | if stream.Error != nil && stream.Error != io.EOF { | ||
51 | stream.Error = fmt.Errorf("%v: %s", encoder.arrayType, stream.Error.Error()) | ||
52 | } | ||
53 | } | ||
54 | |||
55 | func (encoder *arrayEncoder) IsEmpty(ptr unsafe.Pointer) bool { | ||
56 | return false | ||
57 | } | ||
58 | |||
59 | type arrayDecoder struct { | ||
60 | arrayType *reflect2.UnsafeArrayType | ||
61 | elemDecoder ValDecoder | ||
62 | } | ||
63 | |||
64 | func (decoder *arrayDecoder) Decode(ptr unsafe.Pointer, iter *Iterator) { | ||
65 | decoder.doDecode(ptr, iter) | ||
66 | if iter.Error != nil && iter.Error != io.EOF { | ||
67 | iter.Error = fmt.Errorf("%v: %s", decoder.arrayType, iter.Error.Error()) | ||
68 | } | ||
69 | } | ||
70 | |||
71 | func (decoder *arrayDecoder) doDecode(ptr unsafe.Pointer, iter *Iterator) { | ||
72 | c := iter.nextToken() | ||
73 | arrayType := decoder.arrayType | ||
74 | if c == 'n' { | ||
75 | iter.skipThreeBytes('u', 'l', 'l') | ||
76 | return | ||
77 | } | ||
78 | if c != '[' { | ||
79 | iter.ReportError("decode array", "expect [ or n, but found "+string([]byte{c})) | ||
80 | return | ||
81 | } | ||
82 | c = iter.nextToken() | ||
83 | if c == ']' { | ||
84 | return | ||
85 | } | ||
86 | iter.unreadByte() | ||
87 | elemPtr := arrayType.UnsafeGetIndex(ptr, 0) | ||
88 | decoder.elemDecoder.Decode(elemPtr, iter) | ||
89 | length := 1 | ||
90 | for c = iter.nextToken(); c == ','; c = iter.nextToken() { | ||
91 | if length >= arrayType.Len() { | ||
92 | iter.Skip() | ||
93 | continue | ||
94 | } | ||
95 | idx := length | ||
96 | length += 1 | ||
97 | elemPtr = arrayType.UnsafeGetIndex(ptr, idx) | ||
98 | decoder.elemDecoder.Decode(elemPtr, iter) | ||
99 | } | ||
100 | if c != ']' { | ||
101 | iter.ReportError("decode array", "expect ], but found "+string([]byte{c})) | ||
102 | return | ||
103 | } | ||
104 | } | ||
diff --git a/vendor/github.com/json-iterator/go/reflect_dynamic.go b/vendor/github.com/json-iterator/go/reflect_dynamic.go deleted file mode 100644 index 8b6bc8b..0000000 --- a/vendor/github.com/json-iterator/go/reflect_dynamic.go +++ /dev/null | |||
@@ -1,70 +0,0 @@ | |||
1 | package jsoniter | ||
2 | |||
3 | import ( | ||
4 | "github.com/modern-go/reflect2" | ||
5 | "reflect" | ||
6 | "unsafe" | ||
7 | ) | ||
8 | |||
9 | type dynamicEncoder struct { | ||
10 | valType reflect2.Type | ||
11 | } | ||
12 | |||
13 | func (encoder *dynamicEncoder) Encode(ptr unsafe.Pointer, stream *Stream) { | ||
14 | obj := encoder.valType.UnsafeIndirect(ptr) | ||
15 | stream.WriteVal(obj) | ||
16 | } | ||
17 | |||
18 | func (encoder *dynamicEncoder) IsEmpty(ptr unsafe.Pointer) bool { | ||
19 | return encoder.valType.UnsafeIndirect(ptr) == nil | ||
20 | } | ||
21 | |||
22 | type efaceDecoder struct { | ||
23 | } | ||
24 | |||
25 | func (decoder *efaceDecoder) Decode(ptr unsafe.Pointer, iter *Iterator) { | ||
26 | pObj := (*interface{})(ptr) | ||
27 | obj := *pObj | ||
28 | if obj == nil { | ||
29 | *pObj = iter.Read() | ||
30 | return | ||
31 | } | ||
32 | typ := reflect2.TypeOf(obj) | ||
33 | if typ.Kind() != reflect.Ptr { | ||
34 | *pObj = iter.Read() | ||
35 | return | ||
36 | } | ||
37 | ptrType := typ.(*reflect2.UnsafePtrType) | ||
38 | ptrElemType := ptrType.Elem() | ||
39 | if iter.WhatIsNext() == NilValue { | ||
40 | if ptrElemType.Kind() != reflect.Ptr { | ||
41 | iter.skipFourBytes('n', 'u', 'l', 'l') | ||
42 | *pObj = nil | ||
43 | return | ||
44 | } | ||
45 | } | ||
46 | if reflect2.IsNil(obj) { | ||
47 | obj := ptrElemType.New() | ||
48 | iter.ReadVal(obj) | ||
49 | *pObj = obj | ||
50 | return | ||
51 | } | ||
52 | iter.ReadVal(obj) | ||
53 | } | ||
54 | |||
55 | type ifaceDecoder struct { | ||
56 | valType *reflect2.UnsafeIFaceType | ||
57 | } | ||
58 | |||
59 | func (decoder *ifaceDecoder) Decode(ptr unsafe.Pointer, iter *Iterator) { | ||
60 | if iter.ReadNil() { | ||
61 | decoder.valType.UnsafeSet(ptr, decoder.valType.UnsafeNew()) | ||
62 | return | ||
63 | } | ||
64 | obj := decoder.valType.UnsafeIndirect(ptr) | ||
65 | if reflect2.IsNil(obj) { | ||
66 | iter.ReportError("decode non empty interface", "can not unmarshal into nil") | ||
67 | return | ||
68 | } | ||
69 | iter.ReadVal(obj) | ||
70 | } | ||
diff --git a/vendor/github.com/json-iterator/go/reflect_extension.go b/vendor/github.com/json-iterator/go/reflect_extension.go deleted file mode 100644 index 74a97bf..0000000 --- a/vendor/github.com/json-iterator/go/reflect_extension.go +++ /dev/null | |||
@@ -1,483 +0,0 @@ | |||
1 | package jsoniter | ||
2 | |||
3 | import ( | ||
4 | "fmt" | ||
5 | "github.com/modern-go/reflect2" | ||
6 | "reflect" | ||
7 | "sort" | ||
8 | "strings" | ||
9 | "unicode" | ||
10 | "unsafe" | ||
11 | ) | ||
12 | |||
13 | var typeDecoders = map[string]ValDecoder{} | ||
14 | var fieldDecoders = map[string]ValDecoder{} | ||
15 | var typeEncoders = map[string]ValEncoder{} | ||
16 | var fieldEncoders = map[string]ValEncoder{} | ||
17 | var extensions = []Extension{} | ||
18 | |||
19 | // StructDescriptor describe how should we encode/decode the struct | ||
20 | type StructDescriptor struct { | ||
21 | Type reflect2.Type | ||
22 | Fields []*Binding | ||
23 | } | ||
24 | |||
25 | // GetField get one field from the descriptor by its name. | ||
26 | // Can not use map here to keep field orders. | ||
27 | func (structDescriptor *StructDescriptor) GetField(fieldName string) *Binding { | ||
28 | for _, binding := range structDescriptor.Fields { | ||
29 | if binding.Field.Name() == fieldName { | ||
30 | return binding | ||
31 | } | ||
32 | } | ||
33 | return nil | ||
34 | } | ||
35 | |||
36 | // Binding describe how should we encode/decode the struct field | ||
37 | type Binding struct { | ||
38 | levels []int | ||
39 | Field reflect2.StructField | ||
40 | FromNames []string | ||
41 | ToNames []string | ||
42 | Encoder ValEncoder | ||
43 | Decoder ValDecoder | ||
44 | } | ||
45 | |||
46 | // Extension the one for all SPI. Customize encoding/decoding by specifying alternate encoder/decoder. | ||
47 | // Can also rename fields by UpdateStructDescriptor. | ||
48 | type Extension interface { | ||
49 | UpdateStructDescriptor(structDescriptor *StructDescriptor) | ||
50 | CreateMapKeyDecoder(typ reflect2.Type) ValDecoder | ||
51 | CreateMapKeyEncoder(typ reflect2.Type) ValEncoder | ||
52 | CreateDecoder(typ reflect2.Type) ValDecoder | ||
53 | CreateEncoder(typ reflect2.Type) ValEncoder | ||
54 | DecorateDecoder(typ reflect2.Type, decoder ValDecoder) ValDecoder | ||
55 | DecorateEncoder(typ reflect2.Type, encoder ValEncoder) ValEncoder | ||
56 | } | ||
57 | |||
58 | // DummyExtension embed this type get dummy implementation for all methods of Extension | ||
59 | type DummyExtension struct { | ||
60 | } | ||
61 | |||
62 | // UpdateStructDescriptor No-op | ||
63 | func (extension *DummyExtension) UpdateStructDescriptor(structDescriptor *StructDescriptor) { | ||
64 | } | ||
65 | |||
66 | // CreateMapKeyDecoder No-op | ||
67 | func (extension *DummyExtension) CreateMapKeyDecoder(typ reflect2.Type) ValDecoder { | ||
68 | return nil | ||
69 | } | ||
70 | |||
71 | // CreateMapKeyEncoder No-op | ||
72 | func (extension *DummyExtension) CreateMapKeyEncoder(typ reflect2.Type) ValEncoder { | ||
73 | return nil | ||
74 | } | ||
75 | |||
76 | // CreateDecoder No-op | ||
77 | func (extension *DummyExtension) CreateDecoder(typ reflect2.Type) ValDecoder { | ||
78 | return nil | ||
79 | } | ||
80 | |||
81 | // CreateEncoder No-op | ||
82 | func (extension *DummyExtension) CreateEncoder(typ reflect2.Type) ValEncoder { | ||
83 | return nil | ||
84 | } | ||
85 | |||
86 | // DecorateDecoder No-op | ||
87 | func (extension *DummyExtension) DecorateDecoder(typ reflect2.Type, decoder ValDecoder) ValDecoder { | ||
88 | return decoder | ||
89 | } | ||
90 | |||
91 | // DecorateEncoder No-op | ||
92 | func (extension *DummyExtension) DecorateEncoder(typ reflect2.Type, encoder ValEncoder) ValEncoder { | ||
93 | return encoder | ||
94 | } | ||
95 | |||
96 | type EncoderExtension map[reflect2.Type]ValEncoder | ||
97 | |||
98 | // UpdateStructDescriptor No-op | ||
99 | func (extension EncoderExtension) UpdateStructDescriptor(structDescriptor *StructDescriptor) { | ||
100 | } | ||
101 | |||
102 | // CreateDecoder No-op | ||
103 | func (extension EncoderExtension) CreateDecoder(typ reflect2.Type) ValDecoder { | ||
104 | return nil | ||
105 | } | ||
106 | |||
107 | // CreateEncoder get encoder from map | ||
108 | func (extension EncoderExtension) CreateEncoder(typ reflect2.Type) ValEncoder { | ||
109 | return extension[typ] | ||
110 | } | ||
111 | |||
112 | // CreateMapKeyDecoder No-op | ||
113 | func (extension EncoderExtension) CreateMapKeyDecoder(typ reflect2.Type) ValDecoder { | ||
114 | return nil | ||
115 | } | ||
116 | |||
117 | // CreateMapKeyEncoder No-op | ||
118 | func (extension EncoderExtension) CreateMapKeyEncoder(typ reflect2.Type) ValEncoder { | ||
119 | return nil | ||
120 | } | ||
121 | |||
122 | // DecorateDecoder No-op | ||
123 | func (extension EncoderExtension) DecorateDecoder(typ reflect2.Type, decoder ValDecoder) ValDecoder { | ||
124 | return decoder | ||
125 | } | ||
126 | |||
127 | // DecorateEncoder No-op | ||
128 | func (extension EncoderExtension) DecorateEncoder(typ reflect2.Type, encoder ValEncoder) ValEncoder { | ||
129 | return encoder | ||
130 | } | ||
131 | |||
132 | type DecoderExtension map[reflect2.Type]ValDecoder | ||
133 | |||
134 | // UpdateStructDescriptor No-op | ||
135 | func (extension DecoderExtension) UpdateStructDescriptor(structDescriptor *StructDescriptor) { | ||
136 | } | ||
137 | |||
138 | // CreateMapKeyDecoder No-op | ||
139 | func (extension DecoderExtension) CreateMapKeyDecoder(typ reflect2.Type) ValDecoder { | ||
140 | return nil | ||
141 | } | ||
142 | |||
143 | // CreateMapKeyEncoder No-op | ||
144 | func (extension DecoderExtension) CreateMapKeyEncoder(typ reflect2.Type) ValEncoder { | ||
145 | return nil | ||
146 | } | ||
147 | |||
148 | // CreateDecoder get decoder from map | ||
149 | func (extension DecoderExtension) CreateDecoder(typ reflect2.Type) ValDecoder { | ||
150 | return extension[typ] | ||
151 | } | ||
152 | |||
153 | // CreateEncoder No-op | ||
154 | func (extension DecoderExtension) CreateEncoder(typ reflect2.Type) ValEncoder { | ||
155 | return nil | ||
156 | } | ||
157 | |||
158 | // DecorateDecoder No-op | ||
159 | func (extension DecoderExtension) DecorateDecoder(typ reflect2.Type, decoder ValDecoder) ValDecoder { | ||
160 | return decoder | ||
161 | } | ||
162 | |||
163 | // DecorateEncoder No-op | ||
164 | func (extension DecoderExtension) DecorateEncoder(typ reflect2.Type, encoder ValEncoder) ValEncoder { | ||
165 | return encoder | ||
166 | } | ||
167 | |||
168 | type funcDecoder struct { | ||
169 | fun DecoderFunc | ||
170 | } | ||
171 | |||
172 | func (decoder *funcDecoder) Decode(ptr unsafe.Pointer, iter *Iterator) { | ||
173 | decoder.fun(ptr, iter) | ||
174 | } | ||
175 | |||
176 | type funcEncoder struct { | ||
177 | fun EncoderFunc | ||
178 | isEmptyFunc func(ptr unsafe.Pointer) bool | ||
179 | } | ||
180 | |||
181 | func (encoder *funcEncoder) Encode(ptr unsafe.Pointer, stream *Stream) { | ||
182 | encoder.fun(ptr, stream) | ||
183 | } | ||
184 | |||
185 | func (encoder *funcEncoder) IsEmpty(ptr unsafe.Pointer) bool { | ||
186 | if encoder.isEmptyFunc == nil { | ||
187 | return false | ||
188 | } | ||
189 | return encoder.isEmptyFunc(ptr) | ||
190 | } | ||
191 | |||
192 | // DecoderFunc the function form of TypeDecoder | ||
193 | type DecoderFunc func(ptr unsafe.Pointer, iter *Iterator) | ||
194 | |||
195 | // EncoderFunc the function form of TypeEncoder | ||
196 | type EncoderFunc func(ptr unsafe.Pointer, stream *Stream) | ||
197 | |||
198 | // RegisterTypeDecoderFunc register TypeDecoder for a type with function | ||
199 | func RegisterTypeDecoderFunc(typ string, fun DecoderFunc) { | ||
200 | typeDecoders[typ] = &funcDecoder{fun} | ||
201 | } | ||
202 | |||
203 | // RegisterTypeDecoder register TypeDecoder for a typ | ||
204 | func RegisterTypeDecoder(typ string, decoder ValDecoder) { | ||
205 | typeDecoders[typ] = decoder | ||
206 | } | ||
207 | |||
208 | // RegisterFieldDecoderFunc register TypeDecoder for a struct field with function | ||
209 | func RegisterFieldDecoderFunc(typ string, field string, fun DecoderFunc) { | ||
210 | RegisterFieldDecoder(typ, field, &funcDecoder{fun}) | ||
211 | } | ||
212 | |||
213 | // RegisterFieldDecoder register TypeDecoder for a struct field | ||
214 | func RegisterFieldDecoder(typ string, field string, decoder ValDecoder) { | ||
215 | fieldDecoders[fmt.Sprintf("%s/%s", typ, field)] = decoder | ||
216 | } | ||
217 | |||
218 | // RegisterTypeEncoderFunc register TypeEncoder for a type with encode/isEmpty function | ||
219 | func RegisterTypeEncoderFunc(typ string, fun EncoderFunc, isEmptyFunc func(unsafe.Pointer) bool) { | ||
220 | typeEncoders[typ] = &funcEncoder{fun, isEmptyFunc} | ||
221 | } | ||
222 | |||
223 | // RegisterTypeEncoder register TypeEncoder for a type | ||
224 | func RegisterTypeEncoder(typ string, encoder ValEncoder) { | ||
225 | typeEncoders[typ] = encoder | ||
226 | } | ||
227 | |||
228 | // RegisterFieldEncoderFunc register TypeEncoder for a struct field with encode/isEmpty function | ||
229 | func RegisterFieldEncoderFunc(typ string, field string, fun EncoderFunc, isEmptyFunc func(unsafe.Pointer) bool) { | ||
230 | RegisterFieldEncoder(typ, field, &funcEncoder{fun, isEmptyFunc}) | ||
231 | } | ||
232 | |||
233 | // RegisterFieldEncoder register TypeEncoder for a struct field | ||
234 | func RegisterFieldEncoder(typ string, field string, encoder ValEncoder) { | ||
235 | fieldEncoders[fmt.Sprintf("%s/%s", typ, field)] = encoder | ||
236 | } | ||
237 | |||
238 | // RegisterExtension register extension | ||
239 | func RegisterExtension(extension Extension) { | ||
240 | extensions = append(extensions, extension) | ||
241 | } | ||
242 | |||
243 | func getTypeDecoderFromExtension(ctx *ctx, typ reflect2.Type) ValDecoder { | ||
244 | decoder := _getTypeDecoderFromExtension(ctx, typ) | ||
245 | if decoder != nil { | ||
246 | for _, extension := range extensions { | ||
247 | decoder = extension.DecorateDecoder(typ, decoder) | ||
248 | } | ||
249 | decoder = ctx.decoderExtension.DecorateDecoder(typ, decoder) | ||
250 | for _, extension := range ctx.extraExtensions { | ||
251 | decoder = extension.DecorateDecoder(typ, decoder) | ||
252 | } | ||
253 | } | ||
254 | return decoder | ||
255 | } | ||
256 | func _getTypeDecoderFromExtension(ctx *ctx, typ reflect2.Type) ValDecoder { | ||
257 | for _, extension := range extensions { | ||
258 | decoder := extension.CreateDecoder(typ) | ||
259 | if decoder != nil { | ||
260 | return decoder | ||
261 | } | ||
262 | } | ||
263 | decoder := ctx.decoderExtension.CreateDecoder(typ) | ||
264 | if decoder != nil { | ||
265 | return decoder | ||
266 | } | ||
267 | for _, extension := range ctx.extraExtensions { | ||
268 | decoder := extension.CreateDecoder(typ) | ||
269 | if decoder != nil { | ||
270 | return decoder | ||
271 | } | ||
272 | } | ||
273 | typeName := typ.String() | ||
274 | decoder = typeDecoders[typeName] | ||
275 | if decoder != nil { | ||
276 | return decoder | ||
277 | } | ||
278 | if typ.Kind() == reflect.Ptr { | ||
279 | ptrType := typ.(*reflect2.UnsafePtrType) | ||
280 | decoder := typeDecoders[ptrType.Elem().String()] | ||
281 | if decoder != nil { | ||
282 | return &OptionalDecoder{ptrType.Elem(), decoder} | ||
283 | } | ||
284 | } | ||
285 | return nil | ||
286 | } | ||
287 | |||
288 | func getTypeEncoderFromExtension(ctx *ctx, typ reflect2.Type) ValEncoder { | ||
289 | encoder := _getTypeEncoderFromExtension(ctx, typ) | ||
290 | if encoder != nil { | ||
291 | for _, extension := range extensions { | ||
292 | encoder = extension.DecorateEncoder(typ, encoder) | ||
293 | } | ||
294 | encoder = ctx.encoderExtension.DecorateEncoder(typ, encoder) | ||
295 | for _, extension := range ctx.extraExtensions { | ||
296 | encoder = extension.DecorateEncoder(typ, encoder) | ||
297 | } | ||
298 | } | ||
299 | return encoder | ||
300 | } | ||
301 | |||
302 | func _getTypeEncoderFromExtension(ctx *ctx, typ reflect2.Type) ValEncoder { | ||
303 | for _, extension := range extensions { | ||
304 | encoder := extension.CreateEncoder(typ) | ||
305 | if encoder != nil { | ||
306 | return encoder | ||
307 | } | ||
308 | } | ||
309 | encoder := ctx.encoderExtension.CreateEncoder(typ) | ||
310 | if encoder != nil { | ||
311 | return encoder | ||
312 | } | ||
313 | for _, extension := range ctx.extraExtensions { | ||
314 | encoder := extension.CreateEncoder(typ) | ||
315 | if encoder != nil { | ||
316 | return encoder | ||
317 | } | ||
318 | } | ||
319 | typeName := typ.String() | ||
320 | encoder = typeEncoders[typeName] | ||
321 | if encoder != nil { | ||
322 | return encoder | ||
323 | } | ||
324 | if typ.Kind() == reflect.Ptr { | ||
325 | typePtr := typ.(*reflect2.UnsafePtrType) | ||
326 | encoder := typeEncoders[typePtr.Elem().String()] | ||
327 | if encoder != nil { | ||
328 | return &OptionalEncoder{encoder} | ||
329 | } | ||
330 | } | ||
331 | return nil | ||
332 | } | ||
333 | |||
334 | func describeStruct(ctx *ctx, typ reflect2.Type) *StructDescriptor { | ||
335 | structType := typ.(*reflect2.UnsafeStructType) | ||
336 | embeddedBindings := []*Binding{} | ||
337 | bindings := []*Binding{} | ||
338 | for i := 0; i < structType.NumField(); i++ { | ||
339 | field := structType.Field(i) | ||
340 | tag, hastag := field.Tag().Lookup(ctx.getTagKey()) | ||
341 | if ctx.onlyTaggedField && !hastag && !field.Anonymous() { | ||
342 | continue | ||
343 | } | ||
344 | if tag == "-" || field.Name() == "_" { | ||
345 | continue | ||
346 | } | ||
347 | tagParts := strings.Split(tag, ",") | ||
348 | if field.Anonymous() && (tag == "" || tagParts[0] == "") { | ||
349 | if field.Type().Kind() == reflect.Struct { | ||
350 | structDescriptor := describeStruct(ctx, field.Type()) | ||
351 | for _, binding := range structDescriptor.Fields { | ||
352 | binding.levels = append([]int{i}, binding.levels...) | ||
353 | omitempty := binding.Encoder.(*structFieldEncoder).omitempty | ||
354 | binding.Encoder = &structFieldEncoder{field, binding.Encoder, omitempty} | ||
355 | binding.Decoder = &structFieldDecoder{field, binding.Decoder} | ||
356 | embeddedBindings = append(embeddedBindings, binding) | ||
357 | } | ||
358 | continue | ||
359 | } else if field.Type().Kind() == reflect.Ptr { | ||
360 | ptrType := field.Type().(*reflect2.UnsafePtrType) | ||
361 | if ptrType.Elem().Kind() == reflect.Struct { | ||
362 | structDescriptor := describeStruct(ctx, ptrType.Elem()) | ||
363 | for _, binding := range structDescriptor.Fields { | ||
364 | binding.levels = append([]int{i}, binding.levels...) | ||
365 | omitempty := binding.Encoder.(*structFieldEncoder).omitempty | ||
366 | binding.Encoder = &dereferenceEncoder{binding.Encoder} | ||
367 | binding.Encoder = &structFieldEncoder{field, binding.Encoder, omitempty} | ||
368 | binding.Decoder = &dereferenceDecoder{ptrType.Elem(), binding.Decoder} | ||
369 | binding.Decoder = &structFieldDecoder{field, binding.Decoder} | ||
370 | embeddedBindings = append(embeddedBindings, binding) | ||
371 | } | ||
372 | continue | ||
373 | } | ||
374 | } | ||
375 | } | ||
376 | fieldNames := calcFieldNames(field.Name(), tagParts[0], tag) | ||
377 | fieldCacheKey := fmt.Sprintf("%s/%s", typ.String(), field.Name()) | ||
378 | decoder := fieldDecoders[fieldCacheKey] | ||
379 | if decoder == nil { | ||
380 | decoder = decoderOfType(ctx.append(field.Name()), field.Type()) | ||
381 | } | ||
382 | encoder := fieldEncoders[fieldCacheKey] | ||
383 | if encoder == nil { | ||
384 | encoder = encoderOfType(ctx.append(field.Name()), field.Type()) | ||
385 | } | ||
386 | binding := &Binding{ | ||
387 | Field: field, | ||
388 | FromNames: fieldNames, | ||
389 | ToNames: fieldNames, | ||
390 | Decoder: decoder, | ||
391 | Encoder: encoder, | ||
392 | } | ||
393 | binding.levels = []int{i} | ||
394 | bindings = append(bindings, binding) | ||
395 | } | ||
396 | return createStructDescriptor(ctx, typ, bindings, embeddedBindings) | ||
397 | } | ||
398 | func createStructDescriptor(ctx *ctx, typ reflect2.Type, bindings []*Binding, embeddedBindings []*Binding) *StructDescriptor { | ||
399 | structDescriptor := &StructDescriptor{ | ||
400 | Type: typ, | ||
401 | Fields: bindings, | ||
402 | } | ||
403 | for _, extension := range extensions { | ||
404 | extension.UpdateStructDescriptor(structDescriptor) | ||
405 | } | ||
406 | ctx.encoderExtension.UpdateStructDescriptor(structDescriptor) | ||
407 | ctx.decoderExtension.UpdateStructDescriptor(structDescriptor) | ||
408 | for _, extension := range ctx.extraExtensions { | ||
409 | extension.UpdateStructDescriptor(structDescriptor) | ||
410 | } | ||
411 | processTags(structDescriptor, ctx.frozenConfig) | ||
412 | // merge normal & embedded bindings & sort with original order | ||
413 | allBindings := sortableBindings(append(embeddedBindings, structDescriptor.Fields...)) | ||
414 | sort.Sort(allBindings) | ||
415 | structDescriptor.Fields = allBindings | ||
416 | return structDescriptor | ||
417 | } | ||
418 | |||
419 | type sortableBindings []*Binding | ||
420 | |||
421 | func (bindings sortableBindings) Len() int { | ||
422 | return len(bindings) | ||
423 | } | ||
424 | |||
425 | func (bindings sortableBindings) Less(i, j int) bool { | ||
426 | left := bindings[i].levels | ||
427 | right := bindings[j].levels | ||
428 | k := 0 | ||
429 | for { | ||
430 | if left[k] < right[k] { | ||
431 | return true | ||
432 | } else if left[k] > right[k] { | ||
433 | return false | ||
434 | } | ||
435 | k++ | ||
436 | } | ||
437 | } | ||
438 | |||
439 | func (bindings sortableBindings) Swap(i, j int) { | ||
440 | bindings[i], bindings[j] = bindings[j], bindings[i] | ||
441 | } | ||
442 | |||
443 | func processTags(structDescriptor *StructDescriptor, cfg *frozenConfig) { | ||
444 | for _, binding := range structDescriptor.Fields { | ||
445 | shouldOmitEmpty := false | ||
446 | tagParts := strings.Split(binding.Field.Tag().Get(cfg.getTagKey()), ",") | ||
447 | for _, tagPart := range tagParts[1:] { | ||
448 | if tagPart == "omitempty" { | ||
449 | shouldOmitEmpty = true | ||
450 | } else if tagPart == "string" { | ||
451 | if binding.Field.Type().Kind() == reflect.String { | ||
452 | binding.Decoder = &stringModeStringDecoder{binding.Decoder, cfg} | ||
453 | binding.Encoder = &stringModeStringEncoder{binding.Encoder, cfg} | ||
454 | } else { | ||
455 | binding.Decoder = &stringModeNumberDecoder{binding.Decoder} | ||
456 | binding.Encoder = &stringModeNumberEncoder{binding.Encoder} | ||
457 | } | ||
458 | } | ||
459 | } | ||
460 | binding.Decoder = &structFieldDecoder{binding.Field, binding.Decoder} | ||
461 | binding.Encoder = &structFieldEncoder{binding.Field, binding.Encoder, shouldOmitEmpty} | ||
462 | } | ||
463 | } | ||
464 | |||
465 | func calcFieldNames(originalFieldName string, tagProvidedFieldName string, wholeTag string) []string { | ||
466 | // ignore? | ||
467 | if wholeTag == "-" { | ||
468 | return []string{} | ||
469 | } | ||
470 | // rename? | ||
471 | var fieldNames []string | ||
472 | if tagProvidedFieldName == "" { | ||
473 | fieldNames = []string{originalFieldName} | ||
474 | } else { | ||
475 | fieldNames = []string{tagProvidedFieldName} | ||
476 | } | ||
477 | // private? | ||
478 | isNotExported := unicode.IsLower(rune(originalFieldName[0])) || originalFieldName[0] == '_' | ||
479 | if isNotExported { | ||
480 | fieldNames = []string{} | ||
481 | } | ||
482 | return fieldNames | ||
483 | } | ||
diff --git a/vendor/github.com/json-iterator/go/reflect_json_number.go b/vendor/github.com/json-iterator/go/reflect_json_number.go deleted file mode 100644 index 98d45c1..0000000 --- a/vendor/github.com/json-iterator/go/reflect_json_number.go +++ /dev/null | |||
@@ -1,112 +0,0 @@ | |||
1 | package jsoniter | ||
2 | |||
3 | import ( | ||
4 | "encoding/json" | ||
5 | "github.com/modern-go/reflect2" | ||
6 | "strconv" | ||
7 | "unsafe" | ||
8 | ) | ||
9 | |||
10 | type Number string | ||
11 | |||
12 | // String returns the literal text of the number. | ||
13 | func (n Number) String() string { return string(n) } | ||
14 | |||
15 | // Float64 returns the number as a float64. | ||
16 | func (n Number) Float64() (float64, error) { | ||
17 | return strconv.ParseFloat(string(n), 64) | ||
18 | } | ||
19 | |||
20 | // Int64 returns the number as an int64. | ||
21 | func (n Number) Int64() (int64, error) { | ||
22 | return strconv.ParseInt(string(n), 10, 64) | ||
23 | } | ||
24 | |||
25 | func CastJsonNumber(val interface{}) (string, bool) { | ||
26 | switch typedVal := val.(type) { | ||
27 | case json.Number: | ||
28 | return string(typedVal), true | ||
29 | case Number: | ||
30 | return string(typedVal), true | ||
31 | } | ||
32 | return "", false | ||
33 | } | ||
34 | |||
35 | var jsonNumberType = reflect2.TypeOfPtr((*json.Number)(nil)).Elem() | ||
36 | var jsoniterNumberType = reflect2.TypeOfPtr((*Number)(nil)).Elem() | ||
37 | |||
38 | func createDecoderOfJsonNumber(ctx *ctx, typ reflect2.Type) ValDecoder { | ||
39 | if typ.AssignableTo(jsonNumberType) { | ||
40 | return &jsonNumberCodec{} | ||
41 | } | ||
42 | if typ.AssignableTo(jsoniterNumberType) { | ||
43 | return &jsoniterNumberCodec{} | ||
44 | } | ||
45 | return nil | ||
46 | } | ||
47 | |||
48 | func createEncoderOfJsonNumber(ctx *ctx, typ reflect2.Type) ValEncoder { | ||
49 | if typ.AssignableTo(jsonNumberType) { | ||
50 | return &jsonNumberCodec{} | ||
51 | } | ||
52 | if typ.AssignableTo(jsoniterNumberType) { | ||
53 | return &jsoniterNumberCodec{} | ||
54 | } | ||
55 | return nil | ||
56 | } | ||
57 | |||
58 | type jsonNumberCodec struct { | ||
59 | } | ||
60 | |||
61 | func (codec *jsonNumberCodec) Decode(ptr unsafe.Pointer, iter *Iterator) { | ||
62 | switch iter.WhatIsNext() { | ||
63 | case StringValue: | ||
64 | *((*json.Number)(ptr)) = json.Number(iter.ReadString()) | ||
65 | case NilValue: | ||
66 | iter.skipFourBytes('n', 'u', 'l', 'l') | ||
67 | *((*json.Number)(ptr)) = "" | ||
68 | default: | ||
69 | *((*json.Number)(ptr)) = json.Number([]byte(iter.readNumberAsString())) | ||
70 | } | ||
71 | } | ||
72 | |||
73 | func (codec *jsonNumberCodec) Encode(ptr unsafe.Pointer, stream *Stream) { | ||
74 | number := *((*json.Number)(ptr)) | ||
75 | if len(number) == 0 { | ||
76 | stream.writeByte('0') | ||
77 | } else { | ||
78 | stream.WriteRaw(string(number)) | ||
79 | } | ||
80 | } | ||
81 | |||
82 | func (codec *jsonNumberCodec) IsEmpty(ptr unsafe.Pointer) bool { | ||
83 | return len(*((*json.Number)(ptr))) == 0 | ||
84 | } | ||
85 | |||
86 | type jsoniterNumberCodec struct { | ||
87 | } | ||
88 | |||
89 | func (codec *jsoniterNumberCodec) Decode(ptr unsafe.Pointer, iter *Iterator) { | ||
90 | switch iter.WhatIsNext() { | ||
91 | case StringValue: | ||
92 | *((*Number)(ptr)) = Number(iter.ReadString()) | ||
93 | case NilValue: | ||
94 | iter.skipFourBytes('n', 'u', 'l', 'l') | ||
95 | *((*Number)(ptr)) = "" | ||
96 | default: | ||
97 | *((*Number)(ptr)) = Number([]byte(iter.readNumberAsString())) | ||
98 | } | ||
99 | } | ||
100 | |||
101 | func (codec *jsoniterNumberCodec) Encode(ptr unsafe.Pointer, stream *Stream) { | ||
102 | number := *((*Number)(ptr)) | ||
103 | if len(number) == 0 { | ||
104 | stream.writeByte('0') | ||
105 | } else { | ||
106 | stream.WriteRaw(string(number)) | ||
107 | } | ||
108 | } | ||
109 | |||
110 | func (codec *jsoniterNumberCodec) IsEmpty(ptr unsafe.Pointer) bool { | ||
111 | return len(*((*Number)(ptr))) == 0 | ||
112 | } | ||
diff --git a/vendor/github.com/json-iterator/go/reflect_json_raw_message.go b/vendor/github.com/json-iterator/go/reflect_json_raw_message.go deleted file mode 100644 index eba434f..0000000 --- a/vendor/github.com/json-iterator/go/reflect_json_raw_message.go +++ /dev/null | |||
@@ -1,76 +0,0 @@ | |||
1 | package jsoniter | ||
2 | |||
3 | import ( | ||
4 | "encoding/json" | ||
5 | "github.com/modern-go/reflect2" | ||
6 | "unsafe" | ||
7 | ) | ||
8 | |||
9 | var jsonRawMessageType = reflect2.TypeOfPtr((*json.RawMessage)(nil)).Elem() | ||
10 | var jsoniterRawMessageType = reflect2.TypeOfPtr((*RawMessage)(nil)).Elem() | ||
11 | |||
12 | func createEncoderOfJsonRawMessage(ctx *ctx, typ reflect2.Type) ValEncoder { | ||
13 | if typ == jsonRawMessageType { | ||
14 | return &jsonRawMessageCodec{} | ||
15 | } | ||
16 | if typ == jsoniterRawMessageType { | ||
17 | return &jsoniterRawMessageCodec{} | ||
18 | } | ||
19 | return nil | ||
20 | } | ||
21 | |||
22 | func createDecoderOfJsonRawMessage(ctx *ctx, typ reflect2.Type) ValDecoder { | ||
23 | if typ == jsonRawMessageType { | ||
24 | return &jsonRawMessageCodec{} | ||
25 | } | ||
26 | if typ == jsoniterRawMessageType { | ||
27 | return &jsoniterRawMessageCodec{} | ||
28 | } | ||
29 | return nil | ||
30 | } | ||
31 | |||
32 | type jsonRawMessageCodec struct { | ||
33 | } | ||
34 | |||
35 | func (codec *jsonRawMessageCodec) Decode(ptr unsafe.Pointer, iter *Iterator) { | ||
36 | if iter.ReadNil() { | ||
37 | *((*json.RawMessage)(ptr)) = nil | ||
38 | } else { | ||
39 | *((*json.RawMessage)(ptr)) = iter.SkipAndReturnBytes() | ||
40 | } | ||
41 | } | ||
42 | |||
43 | func (codec *jsonRawMessageCodec) Encode(ptr unsafe.Pointer, stream *Stream) { | ||
44 | if *((*json.RawMessage)(ptr)) == nil { | ||
45 | stream.WriteNil() | ||
46 | } else { | ||
47 | stream.WriteRaw(string(*((*json.RawMessage)(ptr)))) | ||
48 | } | ||
49 | } | ||
50 | |||
51 | func (codec *jsonRawMessageCodec) IsEmpty(ptr unsafe.Pointer) bool { | ||
52 | return len(*((*json.RawMessage)(ptr))) == 0 | ||
53 | } | ||
54 | |||
55 | type jsoniterRawMessageCodec struct { | ||
56 | } | ||
57 | |||
58 | func (codec *jsoniterRawMessageCodec) Decode(ptr unsafe.Pointer, iter *Iterator) { | ||
59 | if iter.ReadNil() { | ||
60 | *((*RawMessage)(ptr)) = nil | ||
61 | } else { | ||
62 | *((*RawMessage)(ptr)) = iter.SkipAndReturnBytes() | ||
63 | } | ||
64 | } | ||
65 | |||
66 | func (codec *jsoniterRawMessageCodec) Encode(ptr unsafe.Pointer, stream *Stream) { | ||
67 | if *((*RawMessage)(ptr)) == nil { | ||
68 | stream.WriteNil() | ||
69 | } else { | ||
70 | stream.WriteRaw(string(*((*RawMessage)(ptr)))) | ||
71 | } | ||
72 | } | ||
73 | |||
74 | func (codec *jsoniterRawMessageCodec) IsEmpty(ptr unsafe.Pointer) bool { | ||
75 | return len(*((*RawMessage)(ptr))) == 0 | ||
76 | } | ||
diff --git a/vendor/github.com/json-iterator/go/reflect_map.go b/vendor/github.com/json-iterator/go/reflect_map.go deleted file mode 100644 index 5829671..0000000 --- a/vendor/github.com/json-iterator/go/reflect_map.go +++ /dev/null | |||
@@ -1,346 +0,0 @@ | |||
1 | package jsoniter | ||
2 | |||
3 | import ( | ||
4 | "fmt" | ||
5 | "github.com/modern-go/reflect2" | ||
6 | "io" | ||
7 | "reflect" | ||
8 | "sort" | ||
9 | "unsafe" | ||
10 | ) | ||
11 | |||
12 | func decoderOfMap(ctx *ctx, typ reflect2.Type) ValDecoder { | ||
13 | mapType := typ.(*reflect2.UnsafeMapType) | ||
14 | keyDecoder := decoderOfMapKey(ctx.append("[mapKey]"), mapType.Key()) | ||
15 | elemDecoder := decoderOfType(ctx.append("[mapElem]"), mapType.Elem()) | ||
16 | return &mapDecoder{ | ||
17 | mapType: mapType, | ||
18 | keyType: mapType.Key(), | ||
19 | elemType: mapType.Elem(), | ||
20 | keyDecoder: keyDecoder, | ||
21 | elemDecoder: elemDecoder, | ||
22 | } | ||
23 | } | ||
24 | |||
25 | func encoderOfMap(ctx *ctx, typ reflect2.Type) ValEncoder { | ||
26 | mapType := typ.(*reflect2.UnsafeMapType) | ||
27 | if ctx.sortMapKeys { | ||
28 | return &sortKeysMapEncoder{ | ||
29 | mapType: mapType, | ||
30 | keyEncoder: encoderOfMapKey(ctx.append("[mapKey]"), mapType.Key()), | ||
31 | elemEncoder: encoderOfType(ctx.append("[mapElem]"), mapType.Elem()), | ||
32 | } | ||
33 | } | ||
34 | return &mapEncoder{ | ||
35 | mapType: mapType, | ||
36 | keyEncoder: encoderOfMapKey(ctx.append("[mapKey]"), mapType.Key()), | ||
37 | elemEncoder: encoderOfType(ctx.append("[mapElem]"), mapType.Elem()), | ||
38 | } | ||
39 | } | ||
40 | |||
41 | func decoderOfMapKey(ctx *ctx, typ reflect2.Type) ValDecoder { | ||
42 | decoder := ctx.decoderExtension.CreateMapKeyDecoder(typ) | ||
43 | if decoder != nil { | ||
44 | return decoder | ||
45 | } | ||
46 | for _, extension := range ctx.extraExtensions { | ||
47 | decoder := extension.CreateMapKeyDecoder(typ) | ||
48 | if decoder != nil { | ||
49 | return decoder | ||
50 | } | ||
51 | } | ||
52 | |||
53 | ptrType := reflect2.PtrTo(typ) | ||
54 | if ptrType.Implements(unmarshalerType) { | ||
55 | return &referenceDecoder{ | ||
56 | &unmarshalerDecoder{ | ||
57 | valType: ptrType, | ||
58 | }, | ||
59 | } | ||
60 | } | ||
61 | if typ.Implements(unmarshalerType) { | ||
62 | return &unmarshalerDecoder{ | ||
63 | valType: typ, | ||
64 | } | ||
65 | } | ||
66 | if ptrType.Implements(textUnmarshalerType) { | ||
67 | return &referenceDecoder{ | ||
68 | &textUnmarshalerDecoder{ | ||
69 | valType: ptrType, | ||
70 | }, | ||
71 | } | ||
72 | } | ||
73 | if typ.Implements(textUnmarshalerType) { | ||
74 | return &textUnmarshalerDecoder{ | ||
75 | valType: typ, | ||
76 | } | ||
77 | } | ||
78 | |||
79 | switch typ.Kind() { | ||
80 | case reflect.String: | ||
81 | return decoderOfType(ctx, reflect2.DefaultTypeOfKind(reflect.String)) | ||
82 | case reflect.Bool, | ||
83 | reflect.Uint8, reflect.Int8, | ||
84 | reflect.Uint16, reflect.Int16, | ||
85 | reflect.Uint32, reflect.Int32, | ||
86 | reflect.Uint64, reflect.Int64, | ||
87 | reflect.Uint, reflect.Int, | ||
88 | reflect.Float32, reflect.Float64, | ||
89 | reflect.Uintptr: | ||
90 | typ = reflect2.DefaultTypeOfKind(typ.Kind()) | ||
91 | return &numericMapKeyDecoder{decoderOfType(ctx, typ)} | ||
92 | default: | ||
93 | return &lazyErrorDecoder{err: fmt.Errorf("unsupported map key type: %v", typ)} | ||
94 | } | ||
95 | } | ||
96 | |||
97 | func encoderOfMapKey(ctx *ctx, typ reflect2.Type) ValEncoder { | ||
98 | encoder := ctx.encoderExtension.CreateMapKeyEncoder(typ) | ||
99 | if encoder != nil { | ||
100 | return encoder | ||
101 | } | ||
102 | for _, extension := range ctx.extraExtensions { | ||
103 | encoder := extension.CreateMapKeyEncoder(typ) | ||
104 | if encoder != nil { | ||
105 | return encoder | ||
106 | } | ||
107 | } | ||
108 | |||
109 | if typ == textMarshalerType { | ||
110 | return &directTextMarshalerEncoder{ | ||
111 | stringEncoder: ctx.EncoderOf(reflect2.TypeOf("")), | ||
112 | } | ||
113 | } | ||
114 | if typ.Implements(textMarshalerType) { | ||
115 | return &textMarshalerEncoder{ | ||
116 | valType: typ, | ||
117 | stringEncoder: ctx.EncoderOf(reflect2.TypeOf("")), | ||
118 | } | ||
119 | } | ||
120 | |||
121 | switch typ.Kind() { | ||
122 | case reflect.String: | ||
123 | return encoderOfType(ctx, reflect2.DefaultTypeOfKind(reflect.String)) | ||
124 | case reflect.Bool, | ||
125 | reflect.Uint8, reflect.Int8, | ||
126 | reflect.Uint16, reflect.Int16, | ||
127 | reflect.Uint32, reflect.Int32, | ||
128 | reflect.Uint64, reflect.Int64, | ||
129 | reflect.Uint, reflect.Int, | ||
130 | reflect.Float32, reflect.Float64, | ||
131 | reflect.Uintptr: | ||
132 | typ = reflect2.DefaultTypeOfKind(typ.Kind()) | ||
133 | return &numericMapKeyEncoder{encoderOfType(ctx, typ)} | ||
134 | default: | ||
135 | if typ.Kind() == reflect.Interface { | ||
136 | return &dynamicMapKeyEncoder{ctx, typ} | ||
137 | } | ||
138 | return &lazyErrorEncoder{err: fmt.Errorf("unsupported map key type: %v", typ)} | ||
139 | } | ||
140 | } | ||
141 | |||
142 | type mapDecoder struct { | ||
143 | mapType *reflect2.UnsafeMapType | ||
144 | keyType reflect2.Type | ||
145 | elemType reflect2.Type | ||
146 | keyDecoder ValDecoder | ||
147 | elemDecoder ValDecoder | ||
148 | } | ||
149 | |||
150 | func (decoder *mapDecoder) Decode(ptr unsafe.Pointer, iter *Iterator) { | ||
151 | mapType := decoder.mapType | ||
152 | c := iter.nextToken() | ||
153 | if c == 'n' { | ||
154 | iter.skipThreeBytes('u', 'l', 'l') | ||
155 | *(*unsafe.Pointer)(ptr) = nil | ||
156 | mapType.UnsafeSet(ptr, mapType.UnsafeNew()) | ||
157 | return | ||
158 | } | ||
159 | if mapType.UnsafeIsNil(ptr) { | ||
160 | mapType.UnsafeSet(ptr, mapType.UnsafeMakeMap(0)) | ||
161 | } | ||
162 | if c != '{' { | ||
163 | iter.ReportError("ReadMapCB", `expect { or n, but found `+string([]byte{c})) | ||
164 | return | ||
165 | } | ||
166 | c = iter.nextToken() | ||
167 | if c == '}' { | ||
168 | return | ||
169 | } | ||
170 | iter.unreadByte() | ||
171 | key := decoder.keyType.UnsafeNew() | ||
172 | decoder.keyDecoder.Decode(key, iter) | ||
173 | c = iter.nextToken() | ||
174 | if c != ':' { | ||
175 | iter.ReportError("ReadMapCB", "expect : after object field, but found "+string([]byte{c})) | ||
176 | return | ||
177 | } | ||
178 | elem := decoder.elemType.UnsafeNew() | ||
179 | decoder.elemDecoder.Decode(elem, iter) | ||
180 | decoder.mapType.UnsafeSetIndex(ptr, key, elem) | ||
181 | for c = iter.nextToken(); c == ','; c = iter.nextToken() { | ||
182 | key := decoder.keyType.UnsafeNew() | ||
183 | decoder.keyDecoder.Decode(key, iter) | ||
184 | c = iter.nextToken() | ||
185 | if c != ':' { | ||
186 | iter.ReportError("ReadMapCB", "expect : after object field, but found "+string([]byte{c})) | ||
187 | return | ||
188 | } | ||
189 | elem := decoder.elemType.UnsafeNew() | ||
190 | decoder.elemDecoder.Decode(elem, iter) | ||
191 | decoder.mapType.UnsafeSetIndex(ptr, key, elem) | ||
192 | } | ||
193 | if c != '}' { | ||
194 | iter.ReportError("ReadMapCB", `expect }, but found `+string([]byte{c})) | ||
195 | } | ||
196 | } | ||
197 | |||
198 | type numericMapKeyDecoder struct { | ||
199 | decoder ValDecoder | ||
200 | } | ||
201 | |||
202 | func (decoder *numericMapKeyDecoder) Decode(ptr unsafe.Pointer, iter *Iterator) { | ||
203 | c := iter.nextToken() | ||
204 | if c != '"' { | ||
205 | iter.ReportError("ReadMapCB", `expect ", but found `+string([]byte{c})) | ||
206 | return | ||
207 | } | ||
208 | decoder.decoder.Decode(ptr, iter) | ||
209 | c = iter.nextToken() | ||
210 | if c != '"' { | ||
211 | iter.ReportError("ReadMapCB", `expect ", but found `+string([]byte{c})) | ||
212 | return | ||
213 | } | ||
214 | } | ||
215 | |||
216 | type numericMapKeyEncoder struct { | ||
217 | encoder ValEncoder | ||
218 | } | ||
219 | |||
220 | func (encoder *numericMapKeyEncoder) Encode(ptr unsafe.Pointer, stream *Stream) { | ||
221 | stream.writeByte('"') | ||
222 | encoder.encoder.Encode(ptr, stream) | ||
223 | stream.writeByte('"') | ||
224 | } | ||
225 | |||
226 | func (encoder *numericMapKeyEncoder) IsEmpty(ptr unsafe.Pointer) bool { | ||
227 | return false | ||
228 | } | ||
229 | |||
230 | type dynamicMapKeyEncoder struct { | ||
231 | ctx *ctx | ||
232 | valType reflect2.Type | ||
233 | } | ||
234 | |||
235 | func (encoder *dynamicMapKeyEncoder) Encode(ptr unsafe.Pointer, stream *Stream) { | ||
236 | obj := encoder.valType.UnsafeIndirect(ptr) | ||
237 | encoderOfMapKey(encoder.ctx, reflect2.TypeOf(obj)).Encode(reflect2.PtrOf(obj), stream) | ||
238 | } | ||
239 | |||
240 | func (encoder *dynamicMapKeyEncoder) IsEmpty(ptr unsafe.Pointer) bool { | ||
241 | obj := encoder.valType.UnsafeIndirect(ptr) | ||
242 | return encoderOfMapKey(encoder.ctx, reflect2.TypeOf(obj)).IsEmpty(reflect2.PtrOf(obj)) | ||
243 | } | ||
244 | |||
245 | type mapEncoder struct { | ||
246 | mapType *reflect2.UnsafeMapType | ||
247 | keyEncoder ValEncoder | ||
248 | elemEncoder ValEncoder | ||
249 | } | ||
250 | |||
251 | func (encoder *mapEncoder) Encode(ptr unsafe.Pointer, stream *Stream) { | ||
252 | if *(*unsafe.Pointer)(ptr) == nil { | ||
253 | stream.WriteNil() | ||
254 | return | ||
255 | } | ||
256 | stream.WriteObjectStart() | ||
257 | iter := encoder.mapType.UnsafeIterate(ptr) | ||
258 | for i := 0; iter.HasNext(); i++ { | ||
259 | if i != 0 { | ||
260 | stream.WriteMore() | ||
261 | } | ||
262 | key, elem := iter.UnsafeNext() | ||
263 | encoder.keyEncoder.Encode(key, stream) | ||
264 | if stream.indention > 0 { | ||
265 | stream.writeTwoBytes(byte(':'), byte(' ')) | ||
266 | } else { | ||
267 | stream.writeByte(':') | ||
268 | } | ||
269 | encoder.elemEncoder.Encode(elem, stream) | ||
270 | } | ||
271 | stream.WriteObjectEnd() | ||
272 | } | ||
273 | |||
274 | func (encoder *mapEncoder) IsEmpty(ptr unsafe.Pointer) bool { | ||
275 | iter := encoder.mapType.UnsafeIterate(ptr) | ||
276 | return !iter.HasNext() | ||
277 | } | ||
278 | |||
279 | type sortKeysMapEncoder struct { | ||
280 | mapType *reflect2.UnsafeMapType | ||
281 | keyEncoder ValEncoder | ||
282 | elemEncoder ValEncoder | ||
283 | } | ||
284 | |||
285 | func (encoder *sortKeysMapEncoder) Encode(ptr unsafe.Pointer, stream *Stream) { | ||
286 | if *(*unsafe.Pointer)(ptr) == nil { | ||
287 | stream.WriteNil() | ||
288 | return | ||
289 | } | ||
290 | stream.WriteObjectStart() | ||
291 | mapIter := encoder.mapType.UnsafeIterate(ptr) | ||
292 | subStream := stream.cfg.BorrowStream(nil) | ||
293 | subStream.Attachment = stream.Attachment | ||
294 | subIter := stream.cfg.BorrowIterator(nil) | ||
295 | keyValues := encodedKeyValues{} | ||
296 | for mapIter.HasNext() { | ||
297 | key, elem := mapIter.UnsafeNext() | ||
298 | subStreamIndex := subStream.Buffered() | ||
299 | encoder.keyEncoder.Encode(key, subStream) | ||
300 | if subStream.Error != nil && subStream.Error != io.EOF && stream.Error == nil { | ||
301 | stream.Error = subStream.Error | ||
302 | } | ||
303 | encodedKey := subStream.Buffer()[subStreamIndex:] | ||
304 | subIter.ResetBytes(encodedKey) | ||
305 | decodedKey := subIter.ReadString() | ||
306 | if stream.indention > 0 { | ||
307 | subStream.writeTwoBytes(byte(':'), byte(' ')) | ||
308 | } else { | ||
309 | subStream.writeByte(':') | ||
310 | } | ||
311 | encoder.elemEncoder.Encode(elem, subStream) | ||
312 | keyValues = append(keyValues, encodedKV{ | ||
313 | key: decodedKey, | ||
314 | keyValue: subStream.Buffer()[subStreamIndex:], | ||
315 | }) | ||
316 | } | ||
317 | sort.Sort(keyValues) | ||
318 | for i, keyValue := range keyValues { | ||
319 | if i != 0 { | ||
320 | stream.WriteMore() | ||
321 | } | ||
322 | stream.Write(keyValue.keyValue) | ||
323 | } | ||
324 | if subStream.Error != nil && stream.Error == nil { | ||
325 | stream.Error = subStream.Error | ||
326 | } | ||
327 | stream.WriteObjectEnd() | ||
328 | stream.cfg.ReturnStream(subStream) | ||
329 | stream.cfg.ReturnIterator(subIter) | ||
330 | } | ||
331 | |||
332 | func (encoder *sortKeysMapEncoder) IsEmpty(ptr unsafe.Pointer) bool { | ||
333 | iter := encoder.mapType.UnsafeIterate(ptr) | ||
334 | return !iter.HasNext() | ||
335 | } | ||
336 | |||
337 | type encodedKeyValues []encodedKV | ||
338 | |||
339 | type encodedKV struct { | ||
340 | key string | ||
341 | keyValue []byte | ||
342 | } | ||
343 | |||
344 | func (sv encodedKeyValues) Len() int { return len(sv) } | ||
345 | func (sv encodedKeyValues) Swap(i, j int) { sv[i], sv[j] = sv[j], sv[i] } | ||
346 | func (sv encodedKeyValues) Less(i, j int) bool { return sv[i].key < sv[j].key } | ||
diff --git a/vendor/github.com/json-iterator/go/reflect_marshaler.go b/vendor/github.com/json-iterator/go/reflect_marshaler.go deleted file mode 100644 index 3e21f37..0000000 --- a/vendor/github.com/json-iterator/go/reflect_marshaler.go +++ /dev/null | |||
@@ -1,225 +0,0 @@ | |||
1 | package jsoniter | ||
2 | |||
3 | import ( | ||
4 | "encoding" | ||
5 | "encoding/json" | ||
6 | "unsafe" | ||
7 | |||
8 | "github.com/modern-go/reflect2" | ||
9 | ) | ||
10 | |||
11 | var marshalerType = reflect2.TypeOfPtr((*json.Marshaler)(nil)).Elem() | ||
12 | var unmarshalerType = reflect2.TypeOfPtr((*json.Unmarshaler)(nil)).Elem() | ||
13 | var textMarshalerType = reflect2.TypeOfPtr((*encoding.TextMarshaler)(nil)).Elem() | ||
14 | var textUnmarshalerType = reflect2.TypeOfPtr((*encoding.TextUnmarshaler)(nil)).Elem() | ||
15 | |||
16 | func createDecoderOfMarshaler(ctx *ctx, typ reflect2.Type) ValDecoder { | ||
17 | ptrType := reflect2.PtrTo(typ) | ||
18 | if ptrType.Implements(unmarshalerType) { | ||
19 | return &referenceDecoder{ | ||
20 | &unmarshalerDecoder{ptrType}, | ||
21 | } | ||
22 | } | ||
23 | if ptrType.Implements(textUnmarshalerType) { | ||
24 | return &referenceDecoder{ | ||
25 | &textUnmarshalerDecoder{ptrType}, | ||
26 | } | ||
27 | } | ||
28 | return nil | ||
29 | } | ||
30 | |||
31 | func createEncoderOfMarshaler(ctx *ctx, typ reflect2.Type) ValEncoder { | ||
32 | if typ == marshalerType { | ||
33 | checkIsEmpty := createCheckIsEmpty(ctx, typ) | ||
34 | var encoder ValEncoder = &directMarshalerEncoder{ | ||
35 | checkIsEmpty: checkIsEmpty, | ||
36 | } | ||
37 | return encoder | ||
38 | } | ||
39 | if typ.Implements(marshalerType) { | ||
40 | checkIsEmpty := createCheckIsEmpty(ctx, typ) | ||
41 | var encoder ValEncoder = &marshalerEncoder{ | ||
42 | valType: typ, | ||
43 | checkIsEmpty: checkIsEmpty, | ||
44 | } | ||
45 | return encoder | ||
46 | } | ||
47 | ptrType := reflect2.PtrTo(typ) | ||
48 | if ctx.prefix != "" && ptrType.Implements(marshalerType) { | ||
49 | checkIsEmpty := createCheckIsEmpty(ctx, ptrType) | ||
50 | var encoder ValEncoder = &marshalerEncoder{ | ||
51 | valType: ptrType, | ||
52 | checkIsEmpty: checkIsEmpty, | ||
53 | } | ||
54 | return &referenceEncoder{encoder} | ||
55 | } | ||
56 | if typ == textMarshalerType { | ||
57 | checkIsEmpty := createCheckIsEmpty(ctx, typ) | ||
58 | var encoder ValEncoder = &directTextMarshalerEncoder{ | ||
59 | checkIsEmpty: checkIsEmpty, | ||
60 | stringEncoder: ctx.EncoderOf(reflect2.TypeOf("")), | ||
61 | } | ||
62 | return encoder | ||
63 | } | ||
64 | if typ.Implements(textMarshalerType) { | ||
65 | checkIsEmpty := createCheckIsEmpty(ctx, typ) | ||
66 | var encoder ValEncoder = &textMarshalerEncoder{ | ||
67 | valType: typ, | ||
68 | stringEncoder: ctx.EncoderOf(reflect2.TypeOf("")), | ||
69 | checkIsEmpty: checkIsEmpty, | ||
70 | } | ||
71 | return encoder | ||
72 | } | ||
73 | // if prefix is empty, the type is the root type | ||
74 | if ctx.prefix != "" && ptrType.Implements(textMarshalerType) { | ||
75 | checkIsEmpty := createCheckIsEmpty(ctx, ptrType) | ||
76 | var encoder ValEncoder = &textMarshalerEncoder{ | ||
77 | valType: ptrType, | ||
78 | stringEncoder: ctx.EncoderOf(reflect2.TypeOf("")), | ||
79 | checkIsEmpty: checkIsEmpty, | ||
80 | } | ||
81 | return &referenceEncoder{encoder} | ||
82 | } | ||
83 | return nil | ||
84 | } | ||
85 | |||
86 | type marshalerEncoder struct { | ||
87 | checkIsEmpty checkIsEmpty | ||
88 | valType reflect2.Type | ||
89 | } | ||
90 | |||
91 | func (encoder *marshalerEncoder) Encode(ptr unsafe.Pointer, stream *Stream) { | ||
92 | obj := encoder.valType.UnsafeIndirect(ptr) | ||
93 | if encoder.valType.IsNullable() && reflect2.IsNil(obj) { | ||
94 | stream.WriteNil() | ||
95 | return | ||
96 | } | ||
97 | marshaler := obj.(json.Marshaler) | ||
98 | bytes, err := marshaler.MarshalJSON() | ||
99 | if err != nil { | ||
100 | stream.Error = err | ||
101 | } else { | ||
102 | // html escape was already done by jsoniter | ||
103 | // but the extra '\n' should be trimed | ||
104 | l := len(bytes) | ||
105 | if l > 0 && bytes[l-1] == '\n' { | ||
106 | bytes = bytes[:l-1] | ||
107 | } | ||
108 | stream.Write(bytes) | ||
109 | } | ||
110 | } | ||
111 | |||
112 | func (encoder *marshalerEncoder) IsEmpty(ptr unsafe.Pointer) bool { | ||
113 | return encoder.checkIsEmpty.IsEmpty(ptr) | ||
114 | } | ||
115 | |||
116 | type directMarshalerEncoder struct { | ||
117 | checkIsEmpty checkIsEmpty | ||
118 | } | ||
119 | |||
120 | func (encoder *directMarshalerEncoder) Encode(ptr unsafe.Pointer, stream *Stream) { | ||
121 | marshaler := *(*json.Marshaler)(ptr) | ||
122 | if marshaler == nil { | ||
123 | stream.WriteNil() | ||
124 | return | ||
125 | } | ||
126 | bytes, err := marshaler.MarshalJSON() | ||
127 | if err != nil { | ||
128 | stream.Error = err | ||
129 | } else { | ||
130 | stream.Write(bytes) | ||
131 | } | ||
132 | } | ||
133 | |||
134 | func (encoder *directMarshalerEncoder) IsEmpty(ptr unsafe.Pointer) bool { | ||
135 | return encoder.checkIsEmpty.IsEmpty(ptr) | ||
136 | } | ||
137 | |||
138 | type textMarshalerEncoder struct { | ||
139 | valType reflect2.Type | ||
140 | stringEncoder ValEncoder | ||
141 | checkIsEmpty checkIsEmpty | ||
142 | } | ||
143 | |||
144 | func (encoder *textMarshalerEncoder) Encode(ptr unsafe.Pointer, stream *Stream) { | ||
145 | obj := encoder.valType.UnsafeIndirect(ptr) | ||
146 | if encoder.valType.IsNullable() && reflect2.IsNil(obj) { | ||
147 | stream.WriteNil() | ||
148 | return | ||
149 | } | ||
150 | marshaler := (obj).(encoding.TextMarshaler) | ||
151 | bytes, err := marshaler.MarshalText() | ||
152 | if err != nil { | ||
153 | stream.Error = err | ||
154 | } else { | ||
155 | str := string(bytes) | ||
156 | encoder.stringEncoder.Encode(unsafe.Pointer(&str), stream) | ||
157 | } | ||
158 | } | ||
159 | |||
160 | func (encoder *textMarshalerEncoder) IsEmpty(ptr unsafe.Pointer) bool { | ||
161 | return encoder.checkIsEmpty.IsEmpty(ptr) | ||
162 | } | ||
163 | |||
164 | type directTextMarshalerEncoder struct { | ||
165 | stringEncoder ValEncoder | ||
166 | checkIsEmpty checkIsEmpty | ||
167 | } | ||
168 | |||
169 | func (encoder *directTextMarshalerEncoder) Encode(ptr unsafe.Pointer, stream *Stream) { | ||
170 | marshaler := *(*encoding.TextMarshaler)(ptr) | ||
171 | if marshaler == nil { | ||
172 | stream.WriteNil() | ||
173 | return | ||
174 | } | ||
175 | bytes, err := marshaler.MarshalText() | ||
176 | if err != nil { | ||
177 | stream.Error = err | ||
178 | } else { | ||
179 | str := string(bytes) | ||
180 | encoder.stringEncoder.Encode(unsafe.Pointer(&str), stream) | ||
181 | } | ||
182 | } | ||
183 | |||
184 | func (encoder *directTextMarshalerEncoder) IsEmpty(ptr unsafe.Pointer) bool { | ||
185 | return encoder.checkIsEmpty.IsEmpty(ptr) | ||
186 | } | ||
187 | |||
188 | type unmarshalerDecoder struct { | ||
189 | valType reflect2.Type | ||
190 | } | ||
191 | |||
192 | func (decoder *unmarshalerDecoder) Decode(ptr unsafe.Pointer, iter *Iterator) { | ||
193 | valType := decoder.valType | ||
194 | obj := valType.UnsafeIndirect(ptr) | ||
195 | unmarshaler := obj.(json.Unmarshaler) | ||
196 | iter.nextToken() | ||
197 | iter.unreadByte() // skip spaces | ||
198 | bytes := iter.SkipAndReturnBytes() | ||
199 | err := unmarshaler.UnmarshalJSON(bytes) | ||
200 | if err != nil { | ||
201 | iter.ReportError("unmarshalerDecoder", err.Error()) | ||
202 | } | ||
203 | } | ||
204 | |||
205 | type textUnmarshalerDecoder struct { | ||
206 | valType reflect2.Type | ||
207 | } | ||
208 | |||
209 | func (decoder *textUnmarshalerDecoder) Decode(ptr unsafe.Pointer, iter *Iterator) { | ||
210 | valType := decoder.valType | ||
211 | obj := valType.UnsafeIndirect(ptr) | ||
212 | if reflect2.IsNil(obj) { | ||
213 | ptrType := valType.(*reflect2.UnsafePtrType) | ||
214 | elemType := ptrType.Elem() | ||
215 | elem := elemType.UnsafeNew() | ||
216 | ptrType.UnsafeSet(ptr, unsafe.Pointer(&elem)) | ||
217 | obj = valType.UnsafeIndirect(ptr) | ||
218 | } | ||
219 | unmarshaler := (obj).(encoding.TextUnmarshaler) | ||
220 | str := iter.ReadString() | ||
221 | err := unmarshaler.UnmarshalText([]byte(str)) | ||
222 | if err != nil { | ||
223 | iter.ReportError("textUnmarshalerDecoder", err.Error()) | ||
224 | } | ||
225 | } | ||
diff --git a/vendor/github.com/json-iterator/go/reflect_native.go b/vendor/github.com/json-iterator/go/reflect_native.go deleted file mode 100644 index f88722d..0000000 --- a/vendor/github.com/json-iterator/go/reflect_native.go +++ /dev/null | |||
@@ -1,453 +0,0 @@ | |||
1 | package jsoniter | ||
2 | |||
3 | import ( | ||
4 | "encoding/base64" | ||
5 | "reflect" | ||
6 | "strconv" | ||
7 | "unsafe" | ||
8 | |||
9 | "github.com/modern-go/reflect2" | ||
10 | ) | ||
11 | |||
12 | const ptrSize = 32 << uintptr(^uintptr(0)>>63) | ||
13 | |||
14 | func createEncoderOfNative(ctx *ctx, typ reflect2.Type) ValEncoder { | ||
15 | if typ.Kind() == reflect.Slice && typ.(reflect2.SliceType).Elem().Kind() == reflect.Uint8 { | ||
16 | sliceDecoder := decoderOfSlice(ctx, typ) | ||
17 | return &base64Codec{sliceDecoder: sliceDecoder} | ||
18 | } | ||
19 | typeName := typ.String() | ||
20 | kind := typ.Kind() | ||
21 | switch kind { | ||
22 | case reflect.String: | ||
23 | if typeName != "string" { | ||
24 | return encoderOfType(ctx, reflect2.TypeOfPtr((*string)(nil)).Elem()) | ||
25 | } | ||
26 | return &stringCodec{} | ||
27 | case reflect.Int: | ||
28 | if typeName != "int" { | ||
29 | return encoderOfType(ctx, reflect2.TypeOfPtr((*int)(nil)).Elem()) | ||
30 | } | ||
31 | if strconv.IntSize == 32 { | ||
32 | return &int32Codec{} | ||
33 | } | ||
34 | return &int64Codec{} | ||
35 | case reflect.Int8: | ||
36 | if typeName != "int8" { | ||
37 | return encoderOfType(ctx, reflect2.TypeOfPtr((*int8)(nil)).Elem()) | ||
38 | } | ||
39 | return &int8Codec{} | ||
40 | case reflect.Int16: | ||
41 | if typeName != "int16" { | ||
42 | return encoderOfType(ctx, reflect2.TypeOfPtr((*int16)(nil)).Elem()) | ||
43 | } | ||
44 | return &int16Codec{} | ||
45 | case reflect.Int32: | ||
46 | if typeName != "int32" { | ||
47 | return encoderOfType(ctx, reflect2.TypeOfPtr((*int32)(nil)).Elem()) | ||
48 | } | ||
49 | return &int32Codec{} | ||
50 | case reflect.Int64: | ||
51 | if typeName != "int64" { | ||
52 | return encoderOfType(ctx, reflect2.TypeOfPtr((*int64)(nil)).Elem()) | ||
53 | } | ||
54 | return &int64Codec{} | ||
55 | case reflect.Uint: | ||
56 | if typeName != "uint" { | ||
57 | return encoderOfType(ctx, reflect2.TypeOfPtr((*uint)(nil)).Elem()) | ||
58 | } | ||
59 | if strconv.IntSize == 32 { | ||
60 | return &uint32Codec{} | ||
61 | } | ||
62 | return &uint64Codec{} | ||
63 | case reflect.Uint8: | ||
64 | if typeName != "uint8" { | ||
65 | return encoderOfType(ctx, reflect2.TypeOfPtr((*uint8)(nil)).Elem()) | ||
66 | } | ||
67 | return &uint8Codec{} | ||
68 | case reflect.Uint16: | ||
69 | if typeName != "uint16" { | ||
70 | return encoderOfType(ctx, reflect2.TypeOfPtr((*uint16)(nil)).Elem()) | ||
71 | } | ||
72 | return &uint16Codec{} | ||
73 | case reflect.Uint32: | ||
74 | if typeName != "uint32" { | ||
75 | return encoderOfType(ctx, reflect2.TypeOfPtr((*uint32)(nil)).Elem()) | ||
76 | } | ||
77 | return &uint32Codec{} | ||
78 | case reflect.Uintptr: | ||
79 | if typeName != "uintptr" { | ||
80 | return encoderOfType(ctx, reflect2.TypeOfPtr((*uintptr)(nil)).Elem()) | ||
81 | } | ||
82 | if ptrSize == 32 { | ||
83 | return &uint32Codec{} | ||
84 | } | ||
85 | return &uint64Codec{} | ||
86 | case reflect.Uint64: | ||
87 | if typeName != "uint64" { | ||
88 | return encoderOfType(ctx, reflect2.TypeOfPtr((*uint64)(nil)).Elem()) | ||
89 | } | ||
90 | return &uint64Codec{} | ||
91 | case reflect.Float32: | ||
92 | if typeName != "float32" { | ||
93 | return encoderOfType(ctx, reflect2.TypeOfPtr((*float32)(nil)).Elem()) | ||
94 | } | ||
95 | return &float32Codec{} | ||
96 | case reflect.Float64: | ||
97 | if typeName != "float64" { | ||
98 | return encoderOfType(ctx, reflect2.TypeOfPtr((*float64)(nil)).Elem()) | ||
99 | } | ||
100 | return &float64Codec{} | ||
101 | case reflect.Bool: | ||
102 | if typeName != "bool" { | ||
103 | return encoderOfType(ctx, reflect2.TypeOfPtr((*bool)(nil)).Elem()) | ||
104 | } | ||
105 | return &boolCodec{} | ||
106 | } | ||
107 | return nil | ||
108 | } | ||
109 | |||
110 | func createDecoderOfNative(ctx *ctx, typ reflect2.Type) ValDecoder { | ||
111 | if typ.Kind() == reflect.Slice && typ.(reflect2.SliceType).Elem().Kind() == reflect.Uint8 { | ||
112 | sliceDecoder := decoderOfSlice(ctx, typ) | ||
113 | return &base64Codec{sliceDecoder: sliceDecoder} | ||
114 | } | ||
115 | typeName := typ.String() | ||
116 | switch typ.Kind() { | ||
117 | case reflect.String: | ||
118 | if typeName != "string" { | ||
119 | return decoderOfType(ctx, reflect2.TypeOfPtr((*string)(nil)).Elem()) | ||
120 | } | ||
121 | return &stringCodec{} | ||
122 | case reflect.Int: | ||
123 | if typeName != "int" { | ||
124 | return decoderOfType(ctx, reflect2.TypeOfPtr((*int)(nil)).Elem()) | ||
125 | } | ||
126 | if strconv.IntSize == 32 { | ||
127 | return &int32Codec{} | ||
128 | } | ||
129 | return &int64Codec{} | ||
130 | case reflect.Int8: | ||
131 | if typeName != "int8" { | ||
132 | return decoderOfType(ctx, reflect2.TypeOfPtr((*int8)(nil)).Elem()) | ||
133 | } | ||
134 | return &int8Codec{} | ||
135 | case reflect.Int16: | ||
136 | if typeName != "int16" { | ||
137 | return decoderOfType(ctx, reflect2.TypeOfPtr((*int16)(nil)).Elem()) | ||
138 | } | ||
139 | return &int16Codec{} | ||
140 | case reflect.Int32: | ||
141 | if typeName != "int32" { | ||
142 | return decoderOfType(ctx, reflect2.TypeOfPtr((*int32)(nil)).Elem()) | ||
143 | } | ||
144 | return &int32Codec{} | ||
145 | case reflect.Int64: | ||
146 | if typeName != "int64" { | ||
147 | return decoderOfType(ctx, reflect2.TypeOfPtr((*int64)(nil)).Elem()) | ||
148 | } | ||
149 | return &int64Codec{} | ||
150 | case reflect.Uint: | ||
151 | if typeName != "uint" { | ||
152 | return decoderOfType(ctx, reflect2.TypeOfPtr((*uint)(nil)).Elem()) | ||
153 | } | ||
154 | if strconv.IntSize == 32 { | ||
155 | return &uint32Codec{} | ||
156 | } | ||
157 | return &uint64Codec{} | ||
158 | case reflect.Uint8: | ||
159 | if typeName != "uint8" { | ||
160 | return decoderOfType(ctx, reflect2.TypeOfPtr((*uint8)(nil)).Elem()) | ||
161 | } | ||
162 | return &uint8Codec{} | ||
163 | case reflect.Uint16: | ||
164 | if typeName != "uint16" { | ||
165 | return decoderOfType(ctx, reflect2.TypeOfPtr((*uint16)(nil)).Elem()) | ||
166 | } | ||
167 | return &uint16Codec{} | ||
168 | case reflect.Uint32: | ||
169 | if typeName != "uint32" { | ||
170 | return decoderOfType(ctx, reflect2.TypeOfPtr((*uint32)(nil)).Elem()) | ||
171 | } | ||
172 | return &uint32Codec{} | ||
173 | case reflect.Uintptr: | ||
174 | if typeName != "uintptr" { | ||
175 | return decoderOfType(ctx, reflect2.TypeOfPtr((*uintptr)(nil)).Elem()) | ||
176 | } | ||
177 | if ptrSize == 32 { | ||
178 | return &uint32Codec{} | ||
179 | } | ||
180 | return &uint64Codec{} | ||
181 | case reflect.Uint64: | ||
182 | if typeName != "uint64" { | ||
183 | return decoderOfType(ctx, reflect2.TypeOfPtr((*uint64)(nil)).Elem()) | ||
184 | } | ||
185 | return &uint64Codec{} | ||
186 | case reflect.Float32: | ||
187 | if typeName != "float32" { | ||
188 | return decoderOfType(ctx, reflect2.TypeOfPtr((*float32)(nil)).Elem()) | ||
189 | } | ||
190 | return &float32Codec{} | ||
191 | case reflect.Float64: | ||
192 | if typeName != "float64" { | ||
193 | return decoderOfType(ctx, reflect2.TypeOfPtr((*float64)(nil)).Elem()) | ||
194 | } | ||
195 | return &float64Codec{} | ||
196 | case reflect.Bool: | ||
197 | if typeName != "bool" { | ||
198 | return decoderOfType(ctx, reflect2.TypeOfPtr((*bool)(nil)).Elem()) | ||
199 | } | ||
200 | return &boolCodec{} | ||
201 | } | ||
202 | return nil | ||
203 | } | ||
204 | |||
205 | type stringCodec struct { | ||
206 | } | ||
207 | |||
208 | func (codec *stringCodec) Decode(ptr unsafe.Pointer, iter *Iterator) { | ||
209 | *((*string)(ptr)) = iter.ReadString() | ||
210 | } | ||
211 | |||
212 | func (codec *stringCodec) Encode(ptr unsafe.Pointer, stream *Stream) { | ||
213 | str := *((*string)(ptr)) | ||
214 | stream.WriteString(str) | ||
215 | } | ||
216 | |||
217 | func (codec *stringCodec) IsEmpty(ptr unsafe.Pointer) bool { | ||
218 | return *((*string)(ptr)) == "" | ||
219 | } | ||
220 | |||
221 | type int8Codec struct { | ||
222 | } | ||
223 | |||
224 | func (codec *int8Codec) Decode(ptr unsafe.Pointer, iter *Iterator) { | ||
225 | if !iter.ReadNil() { | ||
226 | *((*int8)(ptr)) = iter.ReadInt8() | ||
227 | } | ||
228 | } | ||
229 | |||
230 | func (codec *int8Codec) Encode(ptr unsafe.Pointer, stream *Stream) { | ||
231 | stream.WriteInt8(*((*int8)(ptr))) | ||
232 | } | ||
233 | |||
234 | func (codec *int8Codec) IsEmpty(ptr unsafe.Pointer) bool { | ||
235 | return *((*int8)(ptr)) == 0 | ||
236 | } | ||
237 | |||
238 | type int16Codec struct { | ||
239 | } | ||
240 | |||
241 | func (codec *int16Codec) Decode(ptr unsafe.Pointer, iter *Iterator) { | ||
242 | if !iter.ReadNil() { | ||
243 | *((*int16)(ptr)) = iter.ReadInt16() | ||
244 | } | ||
245 | } | ||
246 | |||
247 | func (codec *int16Codec) Encode(ptr unsafe.Pointer, stream *Stream) { | ||
248 | stream.WriteInt16(*((*int16)(ptr))) | ||
249 | } | ||
250 | |||
251 | func (codec *int16Codec) IsEmpty(ptr unsafe.Pointer) bool { | ||
252 | return *((*int16)(ptr)) == 0 | ||
253 | } | ||
254 | |||
255 | type int32Codec struct { | ||
256 | } | ||
257 | |||
258 | func (codec *int32Codec) Decode(ptr unsafe.Pointer, iter *Iterator) { | ||
259 | if !iter.ReadNil() { | ||
260 | *((*int32)(ptr)) = iter.ReadInt32() | ||
261 | } | ||
262 | } | ||
263 | |||
264 | func (codec *int32Codec) Encode(ptr unsafe.Pointer, stream *Stream) { | ||
265 | stream.WriteInt32(*((*int32)(ptr))) | ||
266 | } | ||
267 | |||
268 | func (codec *int32Codec) IsEmpty(ptr unsafe.Pointer) bool { | ||
269 | return *((*int32)(ptr)) == 0 | ||
270 | } | ||
271 | |||
272 | type int64Codec struct { | ||
273 | } | ||
274 | |||
275 | func (codec *int64Codec) Decode(ptr unsafe.Pointer, iter *Iterator) { | ||
276 | if !iter.ReadNil() { | ||
277 | *((*int64)(ptr)) = iter.ReadInt64() | ||
278 | } | ||
279 | } | ||
280 | |||
281 | func (codec *int64Codec) Encode(ptr unsafe.Pointer, stream *Stream) { | ||
282 | stream.WriteInt64(*((*int64)(ptr))) | ||
283 | } | ||
284 | |||
285 | func (codec *int64Codec) IsEmpty(ptr unsafe.Pointer) bool { | ||
286 | return *((*int64)(ptr)) == 0 | ||
287 | } | ||
288 | |||
289 | type uint8Codec struct { | ||
290 | } | ||
291 | |||
292 | func (codec *uint8Codec) Decode(ptr unsafe.Pointer, iter *Iterator) { | ||
293 | if !iter.ReadNil() { | ||
294 | *((*uint8)(ptr)) = iter.ReadUint8() | ||
295 | } | ||
296 | } | ||
297 | |||
298 | func (codec *uint8Codec) Encode(ptr unsafe.Pointer, stream *Stream) { | ||
299 | stream.WriteUint8(*((*uint8)(ptr))) | ||
300 | } | ||
301 | |||
302 | func (codec *uint8Codec) IsEmpty(ptr unsafe.Pointer) bool { | ||
303 | return *((*uint8)(ptr)) == 0 | ||
304 | } | ||
305 | |||
306 | type uint16Codec struct { | ||
307 | } | ||
308 | |||
309 | func (codec *uint16Codec) Decode(ptr unsafe.Pointer, iter *Iterator) { | ||
310 | if !iter.ReadNil() { | ||
311 | *((*uint16)(ptr)) = iter.ReadUint16() | ||
312 | } | ||
313 | } | ||
314 | |||
315 | func (codec *uint16Codec) Encode(ptr unsafe.Pointer, stream *Stream) { | ||
316 | stream.WriteUint16(*((*uint16)(ptr))) | ||
317 | } | ||
318 | |||
319 | func (codec *uint16Codec) IsEmpty(ptr unsafe.Pointer) bool { | ||
320 | return *((*uint16)(ptr)) == 0 | ||
321 | } | ||
322 | |||
323 | type uint32Codec struct { | ||
324 | } | ||
325 | |||
326 | func (codec *uint32Codec) Decode(ptr unsafe.Pointer, iter *Iterator) { | ||
327 | if !iter.ReadNil() { | ||
328 | *((*uint32)(ptr)) = iter.ReadUint32() | ||
329 | } | ||
330 | } | ||
331 | |||
332 | func (codec *uint32Codec) Encode(ptr unsafe.Pointer, stream *Stream) { | ||
333 | stream.WriteUint32(*((*uint32)(ptr))) | ||
334 | } | ||
335 | |||
336 | func (codec *uint32Codec) IsEmpty(ptr unsafe.Pointer) bool { | ||
337 | return *((*uint32)(ptr)) == 0 | ||
338 | } | ||
339 | |||
340 | type uint64Codec struct { | ||
341 | } | ||
342 | |||
343 | func (codec *uint64Codec) Decode(ptr unsafe.Pointer, iter *Iterator) { | ||
344 | if !iter.ReadNil() { | ||
345 | *((*uint64)(ptr)) = iter.ReadUint64() | ||
346 | } | ||
347 | } | ||
348 | |||
349 | func (codec *uint64Codec) Encode(ptr unsafe.Pointer, stream *Stream) { | ||
350 | stream.WriteUint64(*((*uint64)(ptr))) | ||
351 | } | ||
352 | |||
353 | func (codec *uint64Codec) IsEmpty(ptr unsafe.Pointer) bool { | ||
354 | return *((*uint64)(ptr)) == 0 | ||
355 | } | ||
356 | |||
357 | type float32Codec struct { | ||
358 | } | ||
359 | |||
360 | func (codec *float32Codec) Decode(ptr unsafe.Pointer, iter *Iterator) { | ||
361 | if !iter.ReadNil() { | ||
362 | *((*float32)(ptr)) = iter.ReadFloat32() | ||
363 | } | ||
364 | } | ||
365 | |||
366 | func (codec *float32Codec) Encode(ptr unsafe.Pointer, stream *Stream) { | ||
367 | stream.WriteFloat32(*((*float32)(ptr))) | ||
368 | } | ||
369 | |||
370 | func (codec *float32Codec) IsEmpty(ptr unsafe.Pointer) bool { | ||
371 | return *((*float32)(ptr)) == 0 | ||
372 | } | ||
373 | |||
374 | type float64Codec struct { | ||
375 | } | ||
376 | |||
377 | func (codec *float64Codec) Decode(ptr unsafe.Pointer, iter *Iterator) { | ||
378 | if !iter.ReadNil() { | ||
379 | *((*float64)(ptr)) = iter.ReadFloat64() | ||
380 | } | ||
381 | } | ||
382 | |||
383 | func (codec *float64Codec) Encode(ptr unsafe.Pointer, stream *Stream) { | ||
384 | stream.WriteFloat64(*((*float64)(ptr))) | ||
385 | } | ||
386 | |||
387 | func (codec *float64Codec) IsEmpty(ptr unsafe.Pointer) bool { | ||
388 | return *((*float64)(ptr)) == 0 | ||
389 | } | ||
390 | |||
391 | type boolCodec struct { | ||
392 | } | ||
393 | |||
394 | func (codec *boolCodec) Decode(ptr unsafe.Pointer, iter *Iterator) { | ||
395 | if !iter.ReadNil() { | ||
396 | *((*bool)(ptr)) = iter.ReadBool() | ||
397 | } | ||
398 | } | ||
399 | |||
400 | func (codec *boolCodec) Encode(ptr unsafe.Pointer, stream *Stream) { | ||
401 | stream.WriteBool(*((*bool)(ptr))) | ||
402 | } | ||
403 | |||
404 | func (codec *boolCodec) IsEmpty(ptr unsafe.Pointer) bool { | ||
405 | return !(*((*bool)(ptr))) | ||
406 | } | ||
407 | |||
408 | type base64Codec struct { | ||
409 | sliceType *reflect2.UnsafeSliceType | ||
410 | sliceDecoder ValDecoder | ||
411 | } | ||
412 | |||
413 | func (codec *base64Codec) Decode(ptr unsafe.Pointer, iter *Iterator) { | ||
414 | if iter.ReadNil() { | ||
415 | codec.sliceType.UnsafeSetNil(ptr) | ||
416 | return | ||
417 | } | ||
418 | switch iter.WhatIsNext() { | ||
419 | case StringValue: | ||
420 | src := iter.ReadString() | ||
421 | dst, err := base64.StdEncoding.DecodeString(src) | ||
422 | if err != nil { | ||
423 | iter.ReportError("decode base64", err.Error()) | ||
424 | } else { | ||
425 | codec.sliceType.UnsafeSet(ptr, unsafe.Pointer(&dst)) | ||
426 | } | ||
427 | case ArrayValue: | ||
428 | codec.sliceDecoder.Decode(ptr, iter) | ||
429 | default: | ||
430 | iter.ReportError("base64Codec", "invalid input") | ||
431 | } | ||
432 | } | ||
433 | |||
434 | func (codec *base64Codec) Encode(ptr unsafe.Pointer, stream *Stream) { | ||
435 | if codec.sliceType.UnsafeIsNil(ptr) { | ||
436 | stream.WriteNil() | ||
437 | return | ||
438 | } | ||
439 | src := *((*[]byte)(ptr)) | ||
440 | encoding := base64.StdEncoding | ||
441 | stream.writeByte('"') | ||
442 | if len(src) != 0 { | ||
443 | size := encoding.EncodedLen(len(src)) | ||
444 | buf := make([]byte, size) | ||
445 | encoding.Encode(buf, src) | ||
446 | stream.buf = append(stream.buf, buf...) | ||
447 | } | ||
448 | stream.writeByte('"') | ||
449 | } | ||
450 | |||
451 | func (codec *base64Codec) IsEmpty(ptr unsafe.Pointer) bool { | ||
452 | return len(*((*[]byte)(ptr))) == 0 | ||
453 | } | ||
diff --git a/vendor/github.com/json-iterator/go/reflect_optional.go b/vendor/github.com/json-iterator/go/reflect_optional.go deleted file mode 100644 index fa71f47..0000000 --- a/vendor/github.com/json-iterator/go/reflect_optional.go +++ /dev/null | |||
@@ -1,129 +0,0 @@ | |||
1 | package jsoniter | ||
2 | |||
3 | import ( | ||
4 | "github.com/modern-go/reflect2" | ||
5 | "unsafe" | ||
6 | ) | ||
7 | |||
8 | func decoderOfOptional(ctx *ctx, typ reflect2.Type) ValDecoder { | ||
9 | ptrType := typ.(*reflect2.UnsafePtrType) | ||
10 | elemType := ptrType.Elem() | ||
11 | decoder := decoderOfType(ctx, elemType) | ||
12 | return &OptionalDecoder{elemType, decoder} | ||
13 | } | ||
14 | |||
15 | func encoderOfOptional(ctx *ctx, typ reflect2.Type) ValEncoder { | ||
16 | ptrType := typ.(*reflect2.UnsafePtrType) | ||
17 | elemType := ptrType.Elem() | ||
18 | elemEncoder := encoderOfType(ctx, elemType) | ||
19 | encoder := &OptionalEncoder{elemEncoder} | ||
20 | return encoder | ||
21 | } | ||
22 | |||
23 | type OptionalDecoder struct { | ||
24 | ValueType reflect2.Type | ||
25 | ValueDecoder ValDecoder | ||
26 | } | ||
27 | |||
28 | func (decoder *OptionalDecoder) Decode(ptr unsafe.Pointer, iter *Iterator) { | ||
29 | if iter.ReadNil() { | ||
30 | *((*unsafe.Pointer)(ptr)) = nil | ||
31 | } else { | ||
32 | if *((*unsafe.Pointer)(ptr)) == nil { | ||
33 | //pointer to null, we have to allocate memory to hold the value | ||
34 | newPtr := decoder.ValueType.UnsafeNew() | ||
35 | decoder.ValueDecoder.Decode(newPtr, iter) | ||
36 | *((*unsafe.Pointer)(ptr)) = newPtr | ||
37 | } else { | ||
38 | //reuse existing instance | ||
39 | decoder.ValueDecoder.Decode(*((*unsafe.Pointer)(ptr)), iter) | ||
40 | } | ||
41 | } | ||
42 | } | ||
43 | |||
44 | type dereferenceDecoder struct { | ||
45 | // only to deference a pointer | ||
46 | valueType reflect2.Type | ||
47 | valueDecoder ValDecoder | ||
48 | } | ||
49 | |||
50 | func (decoder *dereferenceDecoder) Decode(ptr unsafe.Pointer, iter *Iterator) { | ||
51 | if *((*unsafe.Pointer)(ptr)) == nil { | ||
52 | //pointer to null, we have to allocate memory to hold the value | ||
53 | newPtr := decoder.valueType.UnsafeNew() | ||
54 | decoder.valueDecoder.Decode(newPtr, iter) | ||
55 | *((*unsafe.Pointer)(ptr)) = newPtr | ||
56 | } else { | ||
57 | //reuse existing instance | ||
58 | decoder.valueDecoder.Decode(*((*unsafe.Pointer)(ptr)), iter) | ||
59 | } | ||
60 | } | ||
61 | |||
62 | type OptionalEncoder struct { | ||
63 | ValueEncoder ValEncoder | ||
64 | } | ||
65 | |||
66 | func (encoder *OptionalEncoder) Encode(ptr unsafe.Pointer, stream *Stream) { | ||
67 | if *((*unsafe.Pointer)(ptr)) == nil { | ||
68 | stream.WriteNil() | ||
69 | } else { | ||
70 | encoder.ValueEncoder.Encode(*((*unsafe.Pointer)(ptr)), stream) | ||
71 | } | ||
72 | } | ||
73 | |||
74 | func (encoder *OptionalEncoder) IsEmpty(ptr unsafe.Pointer) bool { | ||
75 | return *((*unsafe.Pointer)(ptr)) == nil | ||
76 | } | ||
77 | |||
78 | type dereferenceEncoder struct { | ||
79 | ValueEncoder ValEncoder | ||
80 | } | ||
81 | |||
82 | func (encoder *dereferenceEncoder) Encode(ptr unsafe.Pointer, stream *Stream) { | ||
83 | if *((*unsafe.Pointer)(ptr)) == nil { | ||
84 | stream.WriteNil() | ||
85 | } else { | ||
86 | encoder.ValueEncoder.Encode(*((*unsafe.Pointer)(ptr)), stream) | ||
87 | } | ||
88 | } | ||
89 | |||
90 | func (encoder *dereferenceEncoder) IsEmpty(ptr unsafe.Pointer) bool { | ||
91 | dePtr := *((*unsafe.Pointer)(ptr)) | ||
92 | if dePtr == nil { | ||
93 | return true | ||
94 | } | ||
95 | return encoder.ValueEncoder.IsEmpty(dePtr) | ||
96 | } | ||
97 | |||
98 | func (encoder *dereferenceEncoder) IsEmbeddedPtrNil(ptr unsafe.Pointer) bool { | ||
99 | deReferenced := *((*unsafe.Pointer)(ptr)) | ||
100 | if deReferenced == nil { | ||
101 | return true | ||
102 | } | ||
103 | isEmbeddedPtrNil, converted := encoder.ValueEncoder.(IsEmbeddedPtrNil) | ||
104 | if !converted { | ||
105 | return false | ||
106 | } | ||
107 | fieldPtr := unsafe.Pointer(deReferenced) | ||
108 | return isEmbeddedPtrNil.IsEmbeddedPtrNil(fieldPtr) | ||
109 | } | ||
110 | |||
111 | type referenceEncoder struct { | ||
112 | encoder ValEncoder | ||
113 | } | ||
114 | |||
115 | func (encoder *referenceEncoder) Encode(ptr unsafe.Pointer, stream *Stream) { | ||
116 | encoder.encoder.Encode(unsafe.Pointer(&ptr), stream) | ||
117 | } | ||
118 | |||
119 | func (encoder *referenceEncoder) IsEmpty(ptr unsafe.Pointer) bool { | ||
120 | return encoder.encoder.IsEmpty(unsafe.Pointer(&ptr)) | ||
121 | } | ||
122 | |||
123 | type referenceDecoder struct { | ||
124 | decoder ValDecoder | ||
125 | } | ||
126 | |||
127 | func (decoder *referenceDecoder) Decode(ptr unsafe.Pointer, iter *Iterator) { | ||
128 | decoder.decoder.Decode(unsafe.Pointer(&ptr), iter) | ||
129 | } | ||
diff --git a/vendor/github.com/json-iterator/go/reflect_slice.go b/vendor/github.com/json-iterator/go/reflect_slice.go deleted file mode 100644 index 9441d79..0000000 --- a/vendor/github.com/json-iterator/go/reflect_slice.go +++ /dev/null | |||
@@ -1,99 +0,0 @@ | |||
1 | package jsoniter | ||
2 | |||
3 | import ( | ||
4 | "fmt" | ||
5 | "github.com/modern-go/reflect2" | ||
6 | "io" | ||
7 | "unsafe" | ||
8 | ) | ||
9 | |||
10 | func decoderOfSlice(ctx *ctx, typ reflect2.Type) ValDecoder { | ||
11 | sliceType := typ.(*reflect2.UnsafeSliceType) | ||
12 | decoder := decoderOfType(ctx.append("[sliceElem]"), sliceType.Elem()) | ||
13 | return &sliceDecoder{sliceType, decoder} | ||
14 | } | ||
15 | |||
16 | func encoderOfSlice(ctx *ctx, typ reflect2.Type) ValEncoder { | ||
17 | sliceType := typ.(*reflect2.UnsafeSliceType) | ||
18 | encoder := encoderOfType(ctx.append("[sliceElem]"), sliceType.Elem()) | ||
19 | return &sliceEncoder{sliceType, encoder} | ||
20 | } | ||
21 | |||
22 | type sliceEncoder struct { | ||
23 | sliceType *reflect2.UnsafeSliceType | ||
24 | elemEncoder ValEncoder | ||
25 | } | ||
26 | |||
27 | func (encoder *sliceEncoder) Encode(ptr unsafe.Pointer, stream *Stream) { | ||
28 | if encoder.sliceType.UnsafeIsNil(ptr) { | ||
29 | stream.WriteNil() | ||
30 | return | ||
31 | } | ||
32 | length := encoder.sliceType.UnsafeLengthOf(ptr) | ||
33 | if length == 0 { | ||
34 | stream.WriteEmptyArray() | ||
35 | return | ||
36 | } | ||
37 | stream.WriteArrayStart() | ||
38 | encoder.elemEncoder.Encode(encoder.sliceType.UnsafeGetIndex(ptr, 0), stream) | ||
39 | for i := 1; i < length; i++ { | ||
40 | stream.WriteMore() | ||
41 | elemPtr := encoder.sliceType.UnsafeGetIndex(ptr, i) | ||
42 | encoder.elemEncoder.Encode(elemPtr, stream) | ||
43 | } | ||
44 | stream.WriteArrayEnd() | ||
45 | if stream.Error != nil && stream.Error != io.EOF { | ||
46 | stream.Error = fmt.Errorf("%v: %s", encoder.sliceType, stream.Error.Error()) | ||
47 | } | ||
48 | } | ||
49 | |||
50 | func (encoder *sliceEncoder) IsEmpty(ptr unsafe.Pointer) bool { | ||
51 | return encoder.sliceType.UnsafeLengthOf(ptr) == 0 | ||
52 | } | ||
53 | |||
54 | type sliceDecoder struct { | ||
55 | sliceType *reflect2.UnsafeSliceType | ||
56 | elemDecoder ValDecoder | ||
57 | } | ||
58 | |||
59 | func (decoder *sliceDecoder) Decode(ptr unsafe.Pointer, iter *Iterator) { | ||
60 | decoder.doDecode(ptr, iter) | ||
61 | if iter.Error != nil && iter.Error != io.EOF { | ||
62 | iter.Error = fmt.Errorf("%v: %s", decoder.sliceType, iter.Error.Error()) | ||
63 | } | ||
64 | } | ||
65 | |||
66 | func (decoder *sliceDecoder) doDecode(ptr unsafe.Pointer, iter *Iterator) { | ||
67 | c := iter.nextToken() | ||
68 | sliceType := decoder.sliceType | ||
69 | if c == 'n' { | ||
70 | iter.skipThreeBytes('u', 'l', 'l') | ||
71 | sliceType.UnsafeSetNil(ptr) | ||
72 | return | ||
73 | } | ||
74 | if c != '[' { | ||
75 | iter.ReportError("decode slice", "expect [ or n, but found "+string([]byte{c})) | ||
76 | return | ||
77 | } | ||
78 | c = iter.nextToken() | ||
79 | if c == ']' { | ||
80 | sliceType.UnsafeSet(ptr, sliceType.UnsafeMakeSlice(0, 0)) | ||
81 | return | ||
82 | } | ||
83 | iter.unreadByte() | ||
84 | sliceType.UnsafeGrow(ptr, 1) | ||
85 | elemPtr := sliceType.UnsafeGetIndex(ptr, 0) | ||
86 | decoder.elemDecoder.Decode(elemPtr, iter) | ||
87 | length := 1 | ||
88 | for c = iter.nextToken(); c == ','; c = iter.nextToken() { | ||
89 | idx := length | ||
90 | length += 1 | ||
91 | sliceType.UnsafeGrow(ptr, length) | ||
92 | elemPtr = sliceType.UnsafeGetIndex(ptr, idx) | ||
93 | decoder.elemDecoder.Decode(elemPtr, iter) | ||
94 | } | ||
95 | if c != ']' { | ||
96 | iter.ReportError("decode slice", "expect ], but found "+string([]byte{c})) | ||
97 | return | ||
98 | } | ||
99 | } | ||
diff --git a/vendor/github.com/json-iterator/go/reflect_struct_decoder.go b/vendor/github.com/json-iterator/go/reflect_struct_decoder.go deleted file mode 100644 index 92ae912..0000000 --- a/vendor/github.com/json-iterator/go/reflect_struct_decoder.go +++ /dev/null | |||
@@ -1,1097 +0,0 @@ | |||
1 | package jsoniter | ||
2 | |||
3 | import ( | ||
4 | "fmt" | ||
5 | "io" | ||
6 | "strings" | ||
7 | "unsafe" | ||
8 | |||
9 | "github.com/modern-go/reflect2" | ||
10 | ) | ||
11 | |||
12 | func decoderOfStruct(ctx *ctx, typ reflect2.Type) ValDecoder { | ||
13 | bindings := map[string]*Binding{} | ||
14 | structDescriptor := describeStruct(ctx, typ) | ||
15 | for _, binding := range structDescriptor.Fields { | ||
16 | for _, fromName := range binding.FromNames { | ||
17 | old := bindings[fromName] | ||
18 | if old == nil { | ||
19 | bindings[fromName] = binding | ||
20 | continue | ||
21 | } | ||
22 | ignoreOld, ignoreNew := resolveConflictBinding(ctx.frozenConfig, old, binding) | ||
23 | if ignoreOld { | ||
24 | delete(bindings, fromName) | ||
25 | } | ||
26 | if !ignoreNew { | ||
27 | bindings[fromName] = binding | ||
28 | } | ||
29 | } | ||
30 | } | ||
31 | fields := map[string]*structFieldDecoder{} | ||
32 | for k, binding := range bindings { | ||
33 | fields[k] = binding.Decoder.(*structFieldDecoder) | ||
34 | } | ||
35 | |||
36 | if !ctx.caseSensitive() { | ||
37 | for k, binding := range bindings { | ||
38 | if _, found := fields[strings.ToLower(k)]; !found { | ||
39 | fields[strings.ToLower(k)] = binding.Decoder.(*structFieldDecoder) | ||
40 | } | ||
41 | } | ||
42 | } | ||
43 | |||
44 | return createStructDecoder(ctx, typ, fields) | ||
45 | } | ||
46 | |||
47 | func createStructDecoder(ctx *ctx, typ reflect2.Type, fields map[string]*structFieldDecoder) ValDecoder { | ||
48 | if ctx.disallowUnknownFields { | ||
49 | return &generalStructDecoder{typ: typ, fields: fields, disallowUnknownFields: true} | ||
50 | } | ||
51 | knownHash := map[int64]struct{}{ | ||
52 | 0: {}, | ||
53 | } | ||
54 | |||
55 | switch len(fields) { | ||
56 | case 0: | ||
57 | return &skipObjectDecoder{typ} | ||
58 | case 1: | ||
59 | for fieldName, fieldDecoder := range fields { | ||
60 | fieldHash := calcHash(fieldName, ctx.caseSensitive()) | ||
61 | _, known := knownHash[fieldHash] | ||
62 | if known { | ||
63 | return &generalStructDecoder{typ, fields, false} | ||
64 | } | ||
65 | knownHash[fieldHash] = struct{}{} | ||
66 | return &oneFieldStructDecoder{typ, fieldHash, fieldDecoder} | ||
67 | } | ||
68 | case 2: | ||
69 | var fieldHash1 int64 | ||
70 | var fieldHash2 int64 | ||
71 | var fieldDecoder1 *structFieldDecoder | ||
72 | var fieldDecoder2 *structFieldDecoder | ||
73 | for fieldName, fieldDecoder := range fields { | ||
74 | fieldHash := calcHash(fieldName, ctx.caseSensitive()) | ||
75 | _, known := knownHash[fieldHash] | ||
76 | if known { | ||
77 | return &generalStructDecoder{typ, fields, false} | ||
78 | } | ||
79 | knownHash[fieldHash] = struct{}{} | ||
80 | if fieldHash1 == 0 { | ||
81 | fieldHash1 = fieldHash | ||
82 | fieldDecoder1 = fieldDecoder | ||
83 | } else { | ||
84 | fieldHash2 = fieldHash | ||
85 | fieldDecoder2 = fieldDecoder | ||
86 | } | ||
87 | } | ||
88 | return &twoFieldsStructDecoder{typ, fieldHash1, fieldDecoder1, fieldHash2, fieldDecoder2} | ||
89 | case 3: | ||
90 | var fieldName1 int64 | ||
91 | var fieldName2 int64 | ||
92 | var fieldName3 int64 | ||
93 | var fieldDecoder1 *structFieldDecoder | ||
94 | var fieldDecoder2 *structFieldDecoder | ||
95 | var fieldDecoder3 *structFieldDecoder | ||
96 | for fieldName, fieldDecoder := range fields { | ||
97 | fieldHash := calcHash(fieldName, ctx.caseSensitive()) | ||
98 | _, known := knownHash[fieldHash] | ||
99 | if known { | ||
100 | return &generalStructDecoder{typ, fields, false} | ||
101 | } | ||
102 | knownHash[fieldHash] = struct{}{} | ||
103 | if fieldName1 == 0 { | ||
104 | fieldName1 = fieldHash | ||
105 | fieldDecoder1 = fieldDecoder | ||
106 | } else if fieldName2 == 0 { | ||
107 | fieldName2 = fieldHash | ||
108 | fieldDecoder2 = fieldDecoder | ||
109 | } else { | ||
110 | fieldName3 = fieldHash | ||
111 | fieldDecoder3 = fieldDecoder | ||
112 | } | ||
113 | } | ||
114 | return &threeFieldsStructDecoder{typ, | ||
115 | fieldName1, fieldDecoder1, | ||
116 | fieldName2, fieldDecoder2, | ||
117 | fieldName3, fieldDecoder3} | ||
118 | case 4: | ||
119 | var fieldName1 int64 | ||
120 | var fieldName2 int64 | ||
121 | var fieldName3 int64 | ||
122 | var fieldName4 int64 | ||
123 | var fieldDecoder1 *structFieldDecoder | ||
124 | var fieldDecoder2 *structFieldDecoder | ||
125 | var fieldDecoder3 *structFieldDecoder | ||
126 | var fieldDecoder4 *structFieldDecoder | ||
127 | for fieldName, fieldDecoder := range fields { | ||
128 | fieldHash := calcHash(fieldName, ctx.caseSensitive()) | ||
129 | _, known := knownHash[fieldHash] | ||
130 | if known { | ||
131 | return &generalStructDecoder{typ, fields, false} | ||
132 | } | ||
133 | knownHash[fieldHash] = struct{}{} | ||
134 | if fieldName1 == 0 { | ||
135 | fieldName1 = fieldHash | ||
136 | fieldDecoder1 = fieldDecoder | ||
137 | } else if fieldName2 == 0 { | ||
138 | fieldName2 = fieldHash | ||
139 | fieldDecoder2 = fieldDecoder | ||
140 | } else if fieldName3 == 0 { | ||
141 | fieldName3 = fieldHash | ||
142 | fieldDecoder3 = fieldDecoder | ||
143 | } else { | ||
144 | fieldName4 = fieldHash | ||
145 | fieldDecoder4 = fieldDecoder | ||
146 | } | ||
147 | } | ||
148 | return &fourFieldsStructDecoder{typ, | ||
149 | fieldName1, fieldDecoder1, | ||
150 | fieldName2, fieldDecoder2, | ||
151 | fieldName3, fieldDecoder3, | ||
152 | fieldName4, fieldDecoder4} | ||
153 | case 5: | ||
154 | var fieldName1 int64 | ||
155 | var fieldName2 int64 | ||
156 | var fieldName3 int64 | ||
157 | var fieldName4 int64 | ||
158 | var fieldName5 int64 | ||
159 | var fieldDecoder1 *structFieldDecoder | ||
160 | var fieldDecoder2 *structFieldDecoder | ||
161 | var fieldDecoder3 *structFieldDecoder | ||
162 | var fieldDecoder4 *structFieldDecoder | ||
163 | var fieldDecoder5 *structFieldDecoder | ||
164 | for fieldName, fieldDecoder := range fields { | ||
165 | fieldHash := calcHash(fieldName, ctx.caseSensitive()) | ||
166 | _, known := knownHash[fieldHash] | ||
167 | if known { | ||
168 | return &generalStructDecoder{typ, fields, false} | ||
169 | } | ||
170 | knownHash[fieldHash] = struct{}{} | ||
171 | if fieldName1 == 0 { | ||
172 | fieldName1 = fieldHash | ||
173 | fieldDecoder1 = fieldDecoder | ||
174 | } else if fieldName2 == 0 { | ||
175 | fieldName2 = fieldHash | ||
176 | fieldDecoder2 = fieldDecoder | ||
177 | } else if fieldName3 == 0 { | ||
178 | fieldName3 = fieldHash | ||
179 | fieldDecoder3 = fieldDecoder | ||
180 | } else if fieldName4 == 0 { | ||
181 | fieldName4 = fieldHash | ||
182 | fieldDecoder4 = fieldDecoder | ||
183 | } else { | ||
184 | fieldName5 = fieldHash | ||
185 | fieldDecoder5 = fieldDecoder | ||
186 | } | ||
187 | } | ||
188 | return &fiveFieldsStructDecoder{typ, | ||
189 | fieldName1, fieldDecoder1, | ||
190 | fieldName2, fieldDecoder2, | ||
191 | fieldName3, fieldDecoder3, | ||
192 | fieldName4, fieldDecoder4, | ||
193 | fieldName5, fieldDecoder5} | ||
194 | case 6: | ||
195 | var fieldName1 int64 | ||
196 | var fieldName2 int64 | ||
197 | var fieldName3 int64 | ||
198 | var fieldName4 int64 | ||
199 | var fieldName5 int64 | ||
200 | var fieldName6 int64 | ||
201 | var fieldDecoder1 *structFieldDecoder | ||
202 | var fieldDecoder2 *structFieldDecoder | ||
203 | var fieldDecoder3 *structFieldDecoder | ||
204 | var fieldDecoder4 *structFieldDecoder | ||
205 | var fieldDecoder5 *structFieldDecoder | ||
206 | var fieldDecoder6 *structFieldDecoder | ||
207 | for fieldName, fieldDecoder := range fields { | ||
208 | fieldHash := calcHash(fieldName, ctx.caseSensitive()) | ||
209 | _, known := knownHash[fieldHash] | ||
210 | if known { | ||
211 | return &generalStructDecoder{typ, fields, false} | ||
212 | } | ||
213 | knownHash[fieldHash] = struct{}{} | ||
214 | if fieldName1 == 0 { | ||
215 | fieldName1 = fieldHash | ||
216 | fieldDecoder1 = fieldDecoder | ||
217 | } else if fieldName2 == 0 { | ||
218 | fieldName2 = fieldHash | ||
219 | fieldDecoder2 = fieldDecoder | ||
220 | } else if fieldName3 == 0 { | ||
221 | fieldName3 = fieldHash | ||
222 | fieldDecoder3 = fieldDecoder | ||
223 | } else if fieldName4 == 0 { | ||
224 | fieldName4 = fieldHash | ||
225 | fieldDecoder4 = fieldDecoder | ||
226 | } else if fieldName5 == 0 { | ||
227 | fieldName5 = fieldHash | ||
228 | fieldDecoder5 = fieldDecoder | ||
229 | } else { | ||
230 | fieldName6 = fieldHash | ||
231 | fieldDecoder6 = fieldDecoder | ||
232 | } | ||
233 | } | ||
234 | return &sixFieldsStructDecoder{typ, | ||
235 | fieldName1, fieldDecoder1, | ||
236 | fieldName2, fieldDecoder2, | ||
237 | fieldName3, fieldDecoder3, | ||
238 | fieldName4, fieldDecoder4, | ||
239 | fieldName5, fieldDecoder5, | ||
240 | fieldName6, fieldDecoder6} | ||
241 | case 7: | ||
242 | var fieldName1 int64 | ||
243 | var fieldName2 int64 | ||
244 | var fieldName3 int64 | ||
245 | var fieldName4 int64 | ||
246 | var fieldName5 int64 | ||
247 | var fieldName6 int64 | ||
248 | var fieldName7 int64 | ||
249 | var fieldDecoder1 *structFieldDecoder | ||
250 | var fieldDecoder2 *structFieldDecoder | ||
251 | var fieldDecoder3 *structFieldDecoder | ||
252 | var fieldDecoder4 *structFieldDecoder | ||
253 | var fieldDecoder5 *structFieldDecoder | ||
254 | var fieldDecoder6 *structFieldDecoder | ||
255 | var fieldDecoder7 *structFieldDecoder | ||
256 | for fieldName, fieldDecoder := range fields { | ||
257 | fieldHash := calcHash(fieldName, ctx.caseSensitive()) | ||
258 | _, known := knownHash[fieldHash] | ||
259 | if known { | ||
260 | return &generalStructDecoder{typ, fields, false} | ||
261 | } | ||
262 | knownHash[fieldHash] = struct{}{} | ||
263 | if fieldName1 == 0 { | ||
264 | fieldName1 = fieldHash | ||
265 | fieldDecoder1 = fieldDecoder | ||
266 | } else if fieldName2 == 0 { | ||
267 | fieldName2 = fieldHash | ||
268 | fieldDecoder2 = fieldDecoder | ||
269 | } else if fieldName3 == 0 { | ||
270 | fieldName3 = fieldHash | ||
271 | fieldDecoder3 = fieldDecoder | ||
272 | } else if fieldName4 == 0 { | ||
273 | fieldName4 = fieldHash | ||
274 | fieldDecoder4 = fieldDecoder | ||
275 | } else if fieldName5 == 0 { | ||
276 | fieldName5 = fieldHash | ||
277 | fieldDecoder5 = fieldDecoder | ||
278 | } else if fieldName6 == 0 { | ||
279 | fieldName6 = fieldHash | ||
280 | fieldDecoder6 = fieldDecoder | ||
281 | } else { | ||
282 | fieldName7 = fieldHash | ||
283 | fieldDecoder7 = fieldDecoder | ||
284 | } | ||
285 | } | ||
286 | return &sevenFieldsStructDecoder{typ, | ||
287 | fieldName1, fieldDecoder1, | ||
288 | fieldName2, fieldDecoder2, | ||
289 | fieldName3, fieldDecoder3, | ||
290 | fieldName4, fieldDecoder4, | ||
291 | fieldName5, fieldDecoder5, | ||
292 | fieldName6, fieldDecoder6, | ||
293 | fieldName7, fieldDecoder7} | ||
294 | case 8: | ||
295 | var fieldName1 int64 | ||
296 | var fieldName2 int64 | ||
297 | var fieldName3 int64 | ||
298 | var fieldName4 int64 | ||
299 | var fieldName5 int64 | ||
300 | var fieldName6 int64 | ||
301 | var fieldName7 int64 | ||
302 | var fieldName8 int64 | ||
303 | var fieldDecoder1 *structFieldDecoder | ||
304 | var fieldDecoder2 *structFieldDecoder | ||
305 | var fieldDecoder3 *structFieldDecoder | ||
306 | var fieldDecoder4 *structFieldDecoder | ||
307 | var fieldDecoder5 *structFieldDecoder | ||
308 | var fieldDecoder6 *structFieldDecoder | ||
309 | var fieldDecoder7 *structFieldDecoder | ||
310 | var fieldDecoder8 *structFieldDecoder | ||
311 | for fieldName, fieldDecoder := range fields { | ||
312 | fieldHash := calcHash(fieldName, ctx.caseSensitive()) | ||
313 | _, known := knownHash[fieldHash] | ||
314 | if known { | ||
315 | return &generalStructDecoder{typ, fields, false} | ||
316 | } | ||
317 | knownHash[fieldHash] = struct{}{} | ||
318 | if fieldName1 == 0 { | ||
319 | fieldName1 = fieldHash | ||
320 | fieldDecoder1 = fieldDecoder | ||
321 | } else if fieldName2 == 0 { | ||
322 | fieldName2 = fieldHash | ||
323 | fieldDecoder2 = fieldDecoder | ||
324 | } else if fieldName3 == 0 { | ||
325 | fieldName3 = fieldHash | ||
326 | fieldDecoder3 = fieldDecoder | ||
327 | } else if fieldName4 == 0 { | ||
328 | fieldName4 = fieldHash | ||
329 | fieldDecoder4 = fieldDecoder | ||
330 | } else if fieldName5 == 0 { | ||
331 | fieldName5 = fieldHash | ||
332 | fieldDecoder5 = fieldDecoder | ||
333 | } else if fieldName6 == 0 { | ||
334 | fieldName6 = fieldHash | ||
335 | fieldDecoder6 = fieldDecoder | ||
336 | } else if fieldName7 == 0 { | ||
337 | fieldName7 = fieldHash | ||
338 | fieldDecoder7 = fieldDecoder | ||
339 | } else { | ||
340 | fieldName8 = fieldHash | ||
341 | fieldDecoder8 = fieldDecoder | ||
342 | } | ||
343 | } | ||
344 | return &eightFieldsStructDecoder{typ, | ||
345 | fieldName1, fieldDecoder1, | ||
346 | fieldName2, fieldDecoder2, | ||
347 | fieldName3, fieldDecoder3, | ||
348 | fieldName4, fieldDecoder4, | ||
349 | fieldName5, fieldDecoder5, | ||
350 | fieldName6, fieldDecoder6, | ||
351 | fieldName7, fieldDecoder7, | ||
352 | fieldName8, fieldDecoder8} | ||
353 | case 9: | ||
354 | var fieldName1 int64 | ||
355 | var fieldName2 int64 | ||
356 | var fieldName3 int64 | ||
357 | var fieldName4 int64 | ||
358 | var fieldName5 int64 | ||
359 | var fieldName6 int64 | ||
360 | var fieldName7 int64 | ||
361 | var fieldName8 int64 | ||
362 | var fieldName9 int64 | ||
363 | var fieldDecoder1 *structFieldDecoder | ||
364 | var fieldDecoder2 *structFieldDecoder | ||
365 | var fieldDecoder3 *structFieldDecoder | ||
366 | var fieldDecoder4 *structFieldDecoder | ||
367 | var fieldDecoder5 *structFieldDecoder | ||
368 | var fieldDecoder6 *structFieldDecoder | ||
369 | var fieldDecoder7 *structFieldDecoder | ||
370 | var fieldDecoder8 *structFieldDecoder | ||
371 | var fieldDecoder9 *structFieldDecoder | ||
372 | for fieldName, fieldDecoder := range fields { | ||
373 | fieldHash := calcHash(fieldName, ctx.caseSensitive()) | ||
374 | _, known := knownHash[fieldHash] | ||
375 | if known { | ||
376 | return &generalStructDecoder{typ, fields, false} | ||
377 | } | ||
378 | knownHash[fieldHash] = struct{}{} | ||
379 | if fieldName1 == 0 { | ||
380 | fieldName1 = fieldHash | ||
381 | fieldDecoder1 = fieldDecoder | ||
382 | } else if fieldName2 == 0 { | ||
383 | fieldName2 = fieldHash | ||
384 | fieldDecoder2 = fieldDecoder | ||
385 | } else if fieldName3 == 0 { | ||
386 | fieldName3 = fieldHash | ||
387 | fieldDecoder3 = fieldDecoder | ||
388 | } else if fieldName4 == 0 { | ||
389 | fieldName4 = fieldHash | ||
390 | fieldDecoder4 = fieldDecoder | ||
391 | } else if fieldName5 == 0 { | ||
392 | fieldName5 = fieldHash | ||
393 | fieldDecoder5 = fieldDecoder | ||
394 | } else if fieldName6 == 0 { | ||
395 | fieldName6 = fieldHash | ||
396 | fieldDecoder6 = fieldDecoder | ||
397 | } else if fieldName7 == 0 { | ||
398 | fieldName7 = fieldHash | ||
399 | fieldDecoder7 = fieldDecoder | ||
400 | } else if fieldName8 == 0 { | ||
401 | fieldName8 = fieldHash | ||
402 | fieldDecoder8 = fieldDecoder | ||
403 | } else { | ||
404 | fieldName9 = fieldHash | ||
405 | fieldDecoder9 = fieldDecoder | ||
406 | } | ||
407 | } | ||
408 | return &nineFieldsStructDecoder{typ, | ||
409 | fieldName1, fieldDecoder1, | ||
410 | fieldName2, fieldDecoder2, | ||
411 | fieldName3, fieldDecoder3, | ||
412 | fieldName4, fieldDecoder4, | ||
413 | fieldName5, fieldDecoder5, | ||
414 | fieldName6, fieldDecoder6, | ||
415 | fieldName7, fieldDecoder7, | ||
416 | fieldName8, fieldDecoder8, | ||
417 | fieldName9, fieldDecoder9} | ||
418 | case 10: | ||
419 | var fieldName1 int64 | ||
420 | var fieldName2 int64 | ||
421 | var fieldName3 int64 | ||
422 | var fieldName4 int64 | ||
423 | var fieldName5 int64 | ||
424 | var fieldName6 int64 | ||
425 | var fieldName7 int64 | ||
426 | var fieldName8 int64 | ||
427 | var fieldName9 int64 | ||
428 | var fieldName10 int64 | ||
429 | var fieldDecoder1 *structFieldDecoder | ||
430 | var fieldDecoder2 *structFieldDecoder | ||
431 | var fieldDecoder3 *structFieldDecoder | ||
432 | var fieldDecoder4 *structFieldDecoder | ||
433 | var fieldDecoder5 *structFieldDecoder | ||
434 | var fieldDecoder6 *structFieldDecoder | ||
435 | var fieldDecoder7 *structFieldDecoder | ||
436 | var fieldDecoder8 *structFieldDecoder | ||
437 | var fieldDecoder9 *structFieldDecoder | ||
438 | var fieldDecoder10 *structFieldDecoder | ||
439 | for fieldName, fieldDecoder := range fields { | ||
440 | fieldHash := calcHash(fieldName, ctx.caseSensitive()) | ||
441 | _, known := knownHash[fieldHash] | ||
442 | if known { | ||
443 | return &generalStructDecoder{typ, fields, false} | ||
444 | } | ||
445 | knownHash[fieldHash] = struct{}{} | ||
446 | if fieldName1 == 0 { | ||
447 | fieldName1 = fieldHash | ||
448 | fieldDecoder1 = fieldDecoder | ||
449 | } else if fieldName2 == 0 { | ||
450 | fieldName2 = fieldHash | ||
451 | fieldDecoder2 = fieldDecoder | ||
452 | } else if fieldName3 == 0 { | ||
453 | fieldName3 = fieldHash | ||
454 | fieldDecoder3 = fieldDecoder | ||
455 | } else if fieldName4 == 0 { | ||
456 | fieldName4 = fieldHash | ||
457 | fieldDecoder4 = fieldDecoder | ||
458 | } else if fieldName5 == 0 { | ||
459 | fieldName5 = fieldHash | ||
460 | fieldDecoder5 = fieldDecoder | ||
461 | } else if fieldName6 == 0 { | ||
462 | fieldName6 = fieldHash | ||
463 | fieldDecoder6 = fieldDecoder | ||
464 | } else if fieldName7 == 0 { | ||
465 | fieldName7 = fieldHash | ||
466 | fieldDecoder7 = fieldDecoder | ||
467 | } else if fieldName8 == 0 { | ||
468 | fieldName8 = fieldHash | ||
469 | fieldDecoder8 = fieldDecoder | ||
470 | } else if fieldName9 == 0 { | ||
471 | fieldName9 = fieldHash | ||
472 | fieldDecoder9 = fieldDecoder | ||
473 | } else { | ||
474 | fieldName10 = fieldHash | ||
475 | fieldDecoder10 = fieldDecoder | ||
476 | } | ||
477 | } | ||
478 | return &tenFieldsStructDecoder{typ, | ||
479 | fieldName1, fieldDecoder1, | ||
480 | fieldName2, fieldDecoder2, | ||
481 | fieldName3, fieldDecoder3, | ||
482 | fieldName4, fieldDecoder4, | ||
483 | fieldName5, fieldDecoder5, | ||
484 | fieldName6, fieldDecoder6, | ||
485 | fieldName7, fieldDecoder7, | ||
486 | fieldName8, fieldDecoder8, | ||
487 | fieldName9, fieldDecoder9, | ||
488 | fieldName10, fieldDecoder10} | ||
489 | } | ||
490 | return &generalStructDecoder{typ, fields, false} | ||
491 | } | ||
492 | |||
493 | type generalStructDecoder struct { | ||
494 | typ reflect2.Type | ||
495 | fields map[string]*structFieldDecoder | ||
496 | disallowUnknownFields bool | ||
497 | } | ||
498 | |||
499 | func (decoder *generalStructDecoder) Decode(ptr unsafe.Pointer, iter *Iterator) { | ||
500 | if !iter.readObjectStart() { | ||
501 | return | ||
502 | } | ||
503 | if !iter.incrementDepth() { | ||
504 | return | ||
505 | } | ||
506 | var c byte | ||
507 | for c = ','; c == ','; c = iter.nextToken() { | ||
508 | decoder.decodeOneField(ptr, iter) | ||
509 | } | ||
510 | if iter.Error != nil && iter.Error != io.EOF && len(decoder.typ.Type1().Name()) != 0 { | ||
511 | iter.Error = fmt.Errorf("%v.%s", decoder.typ, iter.Error.Error()) | ||
512 | } | ||
513 | if c != '}' { | ||
514 | iter.ReportError("struct Decode", `expect }, but found `+string([]byte{c})) | ||
515 | } | ||
516 | iter.decrementDepth() | ||
517 | } | ||
518 | |||
519 | func (decoder *generalStructDecoder) decodeOneField(ptr unsafe.Pointer, iter *Iterator) { | ||
520 | var field string | ||
521 | var fieldDecoder *structFieldDecoder | ||
522 | if iter.cfg.objectFieldMustBeSimpleString { | ||
523 | fieldBytes := iter.ReadStringAsSlice() | ||
524 | field = *(*string)(unsafe.Pointer(&fieldBytes)) | ||
525 | fieldDecoder = decoder.fields[field] | ||
526 | if fieldDecoder == nil && !iter.cfg.caseSensitive { | ||
527 | fieldDecoder = decoder.fields[strings.ToLower(field)] | ||
528 | } | ||
529 | } else { | ||
530 | field = iter.ReadString() | ||
531 | fieldDecoder = decoder.fields[field] | ||
532 | if fieldDecoder == nil && !iter.cfg.caseSensitive { | ||
533 | fieldDecoder = decoder.fields[strings.ToLower(field)] | ||
534 | } | ||
535 | } | ||
536 | if fieldDecoder == nil { | ||
537 | if decoder.disallowUnknownFields { | ||
538 | msg := "found unknown field: " + field | ||
539 | iter.ReportError("ReadObject", msg) | ||
540 | } | ||
541 | c := iter.nextToken() | ||
542 | if c != ':' { | ||
543 | iter.ReportError("ReadObject", "expect : after object field, but found "+string([]byte{c})) | ||
544 | } | ||
545 | iter.Skip() | ||
546 | return | ||
547 | } | ||
548 | c := iter.nextToken() | ||
549 | if c != ':' { | ||
550 | iter.ReportError("ReadObject", "expect : after object field, but found "+string([]byte{c})) | ||
551 | } | ||
552 | fieldDecoder.Decode(ptr, iter) | ||
553 | } | ||
554 | |||
555 | type skipObjectDecoder struct { | ||
556 | typ reflect2.Type | ||
557 | } | ||
558 | |||
559 | func (decoder *skipObjectDecoder) Decode(ptr unsafe.Pointer, iter *Iterator) { | ||
560 | valueType := iter.WhatIsNext() | ||
561 | if valueType != ObjectValue && valueType != NilValue { | ||
562 | iter.ReportError("skipObjectDecoder", "expect object or null") | ||
563 | return | ||
564 | } | ||
565 | iter.Skip() | ||
566 | } | ||
567 | |||
568 | type oneFieldStructDecoder struct { | ||
569 | typ reflect2.Type | ||
570 | fieldHash int64 | ||
571 | fieldDecoder *structFieldDecoder | ||
572 | } | ||
573 | |||
574 | func (decoder *oneFieldStructDecoder) Decode(ptr unsafe.Pointer, iter *Iterator) { | ||
575 | if !iter.readObjectStart() { | ||
576 | return | ||
577 | } | ||
578 | if !iter.incrementDepth() { | ||
579 | return | ||
580 | } | ||
581 | for { | ||
582 | if iter.readFieldHash() == decoder.fieldHash { | ||
583 | decoder.fieldDecoder.Decode(ptr, iter) | ||
584 | } else { | ||
585 | iter.Skip() | ||
586 | } | ||
587 | if iter.isObjectEnd() { | ||
588 | break | ||
589 | } | ||
590 | } | ||
591 | if iter.Error != nil && iter.Error != io.EOF && len(decoder.typ.Type1().Name()) != 0 { | ||
592 | iter.Error = fmt.Errorf("%v.%s", decoder.typ, iter.Error.Error()) | ||
593 | } | ||
594 | iter.decrementDepth() | ||
595 | } | ||
596 | |||
597 | type twoFieldsStructDecoder struct { | ||
598 | typ reflect2.Type | ||
599 | fieldHash1 int64 | ||
600 | fieldDecoder1 *structFieldDecoder | ||
601 | fieldHash2 int64 | ||
602 | fieldDecoder2 *structFieldDecoder | ||
603 | } | ||
604 | |||
605 | func (decoder *twoFieldsStructDecoder) Decode(ptr unsafe.Pointer, iter *Iterator) { | ||
606 | if !iter.readObjectStart() { | ||
607 | return | ||
608 | } | ||
609 | if !iter.incrementDepth() { | ||
610 | return | ||
611 | } | ||
612 | for { | ||
613 | switch iter.readFieldHash() { | ||
614 | case decoder.fieldHash1: | ||
615 | decoder.fieldDecoder1.Decode(ptr, iter) | ||
616 | case decoder.fieldHash2: | ||
617 | decoder.fieldDecoder2.Decode(ptr, iter) | ||
618 | default: | ||
619 | iter.Skip() | ||
620 | } | ||
621 | if iter.isObjectEnd() { | ||
622 | break | ||
623 | } | ||
624 | } | ||
625 | if iter.Error != nil && iter.Error != io.EOF && len(decoder.typ.Type1().Name()) != 0 { | ||
626 | iter.Error = fmt.Errorf("%v.%s", decoder.typ, iter.Error.Error()) | ||
627 | } | ||
628 | iter.decrementDepth() | ||
629 | } | ||
630 | |||
631 | type threeFieldsStructDecoder struct { | ||
632 | typ reflect2.Type | ||
633 | fieldHash1 int64 | ||
634 | fieldDecoder1 *structFieldDecoder | ||
635 | fieldHash2 int64 | ||
636 | fieldDecoder2 *structFieldDecoder | ||
637 | fieldHash3 int64 | ||
638 | fieldDecoder3 *structFieldDecoder | ||
639 | } | ||
640 | |||
641 | func (decoder *threeFieldsStructDecoder) Decode(ptr unsafe.Pointer, iter *Iterator) { | ||
642 | if !iter.readObjectStart() { | ||
643 | return | ||
644 | } | ||
645 | if !iter.incrementDepth() { | ||
646 | return | ||
647 | } | ||
648 | for { | ||
649 | switch iter.readFieldHash() { | ||
650 | case decoder.fieldHash1: | ||
651 | decoder.fieldDecoder1.Decode(ptr, iter) | ||
652 | case decoder.fieldHash2: | ||
653 | decoder.fieldDecoder2.Decode(ptr, iter) | ||
654 | case decoder.fieldHash3: | ||
655 | decoder.fieldDecoder3.Decode(ptr, iter) | ||
656 | default: | ||
657 | iter.Skip() | ||
658 | } | ||
659 | if iter.isObjectEnd() { | ||
660 | break | ||
661 | } | ||
662 | } | ||
663 | if iter.Error != nil && iter.Error != io.EOF && len(decoder.typ.Type1().Name()) != 0 { | ||
664 | iter.Error = fmt.Errorf("%v.%s", decoder.typ, iter.Error.Error()) | ||
665 | } | ||
666 | iter.decrementDepth() | ||
667 | } | ||
668 | |||
669 | type fourFieldsStructDecoder struct { | ||
670 | typ reflect2.Type | ||
671 | fieldHash1 int64 | ||
672 | fieldDecoder1 *structFieldDecoder | ||
673 | fieldHash2 int64 | ||
674 | fieldDecoder2 *structFieldDecoder | ||
675 | fieldHash3 int64 | ||
676 | fieldDecoder3 *structFieldDecoder | ||
677 | fieldHash4 int64 | ||
678 | fieldDecoder4 *structFieldDecoder | ||
679 | } | ||
680 | |||
681 | func (decoder *fourFieldsStructDecoder) Decode(ptr unsafe.Pointer, iter *Iterator) { | ||
682 | if !iter.readObjectStart() { | ||
683 | return | ||
684 | } | ||
685 | if !iter.incrementDepth() { | ||
686 | return | ||
687 | } | ||
688 | for { | ||
689 | switch iter.readFieldHash() { | ||
690 | case decoder.fieldHash1: | ||
691 | decoder.fieldDecoder1.Decode(ptr, iter) | ||
692 | case decoder.fieldHash2: | ||
693 | decoder.fieldDecoder2.Decode(ptr, iter) | ||
694 | case decoder.fieldHash3: | ||
695 | decoder.fieldDecoder3.Decode(ptr, iter) | ||
696 | case decoder.fieldHash4: | ||
697 | decoder.fieldDecoder4.Decode(ptr, iter) | ||
698 | default: | ||
699 | iter.Skip() | ||
700 | } | ||
701 | if iter.isObjectEnd() { | ||
702 | break | ||
703 | } | ||
704 | } | ||
705 | if iter.Error != nil && iter.Error != io.EOF && len(decoder.typ.Type1().Name()) != 0 { | ||
706 | iter.Error = fmt.Errorf("%v.%s", decoder.typ, iter.Error.Error()) | ||
707 | } | ||
708 | iter.decrementDepth() | ||
709 | } | ||
710 | |||
711 | type fiveFieldsStructDecoder struct { | ||
712 | typ reflect2.Type | ||
713 | fieldHash1 int64 | ||
714 | fieldDecoder1 *structFieldDecoder | ||
715 | fieldHash2 int64 | ||
716 | fieldDecoder2 *structFieldDecoder | ||
717 | fieldHash3 int64 | ||
718 | fieldDecoder3 *structFieldDecoder | ||
719 | fieldHash4 int64 | ||
720 | fieldDecoder4 *structFieldDecoder | ||
721 | fieldHash5 int64 | ||
722 | fieldDecoder5 *structFieldDecoder | ||
723 | } | ||
724 | |||
725 | func (decoder *fiveFieldsStructDecoder) Decode(ptr unsafe.Pointer, iter *Iterator) { | ||
726 | if !iter.readObjectStart() { | ||
727 | return | ||
728 | } | ||
729 | if !iter.incrementDepth() { | ||
730 | return | ||
731 | } | ||
732 | for { | ||
733 | switch iter.readFieldHash() { | ||
734 | case decoder.fieldHash1: | ||
735 | decoder.fieldDecoder1.Decode(ptr, iter) | ||
736 | case decoder.fieldHash2: | ||
737 | decoder.fieldDecoder2.Decode(ptr, iter) | ||
738 | case decoder.fieldHash3: | ||
739 | decoder.fieldDecoder3.Decode(ptr, iter) | ||
740 | case decoder.fieldHash4: | ||
741 | decoder.fieldDecoder4.Decode(ptr, iter) | ||
742 | case decoder.fieldHash5: | ||
743 | decoder.fieldDecoder5.Decode(ptr, iter) | ||
744 | default: | ||
745 | iter.Skip() | ||
746 | } | ||
747 | if iter.isObjectEnd() { | ||
748 | break | ||
749 | } | ||
750 | } | ||
751 | if iter.Error != nil && iter.Error != io.EOF && len(decoder.typ.Type1().Name()) != 0 { | ||
752 | iter.Error = fmt.Errorf("%v.%s", decoder.typ, iter.Error.Error()) | ||
753 | } | ||
754 | iter.decrementDepth() | ||
755 | } | ||
756 | |||
757 | type sixFieldsStructDecoder struct { | ||
758 | typ reflect2.Type | ||
759 | fieldHash1 int64 | ||
760 | fieldDecoder1 *structFieldDecoder | ||
761 | fieldHash2 int64 | ||
762 | fieldDecoder2 *structFieldDecoder | ||
763 | fieldHash3 int64 | ||
764 | fieldDecoder3 *structFieldDecoder | ||
765 | fieldHash4 int64 | ||
766 | fieldDecoder4 *structFieldDecoder | ||
767 | fieldHash5 int64 | ||
768 | fieldDecoder5 *structFieldDecoder | ||
769 | fieldHash6 int64 | ||
770 | fieldDecoder6 *structFieldDecoder | ||
771 | } | ||
772 | |||
773 | func (decoder *sixFieldsStructDecoder) Decode(ptr unsafe.Pointer, iter *Iterator) { | ||
774 | if !iter.readObjectStart() { | ||
775 | return | ||
776 | } | ||
777 | if !iter.incrementDepth() { | ||
778 | return | ||
779 | } | ||
780 | for { | ||
781 | switch iter.readFieldHash() { | ||
782 | case decoder.fieldHash1: | ||
783 | decoder.fieldDecoder1.Decode(ptr, iter) | ||
784 | case decoder.fieldHash2: | ||
785 | decoder.fieldDecoder2.Decode(ptr, iter) | ||
786 | case decoder.fieldHash3: | ||
787 | decoder.fieldDecoder3.Decode(ptr, iter) | ||
788 | case decoder.fieldHash4: | ||
789 | decoder.fieldDecoder4.Decode(ptr, iter) | ||
790 | case decoder.fieldHash5: | ||
791 | decoder.fieldDecoder5.Decode(ptr, iter) | ||
792 | case decoder.fieldHash6: | ||
793 | decoder.fieldDecoder6.Decode(ptr, iter) | ||
794 | default: | ||
795 | iter.Skip() | ||
796 | } | ||
797 | if iter.isObjectEnd() { | ||
798 | break | ||
799 | } | ||
800 | } | ||
801 | if iter.Error != nil && iter.Error != io.EOF && len(decoder.typ.Type1().Name()) != 0 { | ||
802 | iter.Error = fmt.Errorf("%v.%s", decoder.typ, iter.Error.Error()) | ||
803 | } | ||
804 | iter.decrementDepth() | ||
805 | } | ||
806 | |||
807 | type sevenFieldsStructDecoder struct { | ||
808 | typ reflect2.Type | ||
809 | fieldHash1 int64 | ||
810 | fieldDecoder1 *structFieldDecoder | ||
811 | fieldHash2 int64 | ||
812 | fieldDecoder2 *structFieldDecoder | ||
813 | fieldHash3 int64 | ||
814 | fieldDecoder3 *structFieldDecoder | ||
815 | fieldHash4 int64 | ||
816 | fieldDecoder4 *structFieldDecoder | ||
817 | fieldHash5 int64 | ||
818 | fieldDecoder5 *structFieldDecoder | ||
819 | fieldHash6 int64 | ||
820 | fieldDecoder6 *structFieldDecoder | ||
821 | fieldHash7 int64 | ||
822 | fieldDecoder7 *structFieldDecoder | ||
823 | } | ||
824 | |||
825 | func (decoder *sevenFieldsStructDecoder) Decode(ptr unsafe.Pointer, iter *Iterator) { | ||
826 | if !iter.readObjectStart() { | ||
827 | return | ||
828 | } | ||
829 | if !iter.incrementDepth() { | ||
830 | return | ||
831 | } | ||
832 | for { | ||
833 | switch iter.readFieldHash() { | ||
834 | case decoder.fieldHash1: | ||
835 | decoder.fieldDecoder1.Decode(ptr, iter) | ||
836 | case decoder.fieldHash2: | ||
837 | decoder.fieldDecoder2.Decode(ptr, iter) | ||
838 | case decoder.fieldHash3: | ||
839 | decoder.fieldDecoder3.Decode(ptr, iter) | ||
840 | case decoder.fieldHash4: | ||
841 | decoder.fieldDecoder4.Decode(ptr, iter) | ||
842 | case decoder.fieldHash5: | ||
843 | decoder.fieldDecoder5.Decode(ptr, iter) | ||
844 | case decoder.fieldHash6: | ||
845 | decoder.fieldDecoder6.Decode(ptr, iter) | ||
846 | case decoder.fieldHash7: | ||
847 | decoder.fieldDecoder7.Decode(ptr, iter) | ||
848 | default: | ||
849 | iter.Skip() | ||
850 | } | ||
851 | if iter.isObjectEnd() { | ||
852 | break | ||
853 | } | ||
854 | } | ||
855 | if iter.Error != nil && iter.Error != io.EOF && len(decoder.typ.Type1().Name()) != 0 { | ||
856 | iter.Error = fmt.Errorf("%v.%s", decoder.typ, iter.Error.Error()) | ||
857 | } | ||
858 | iter.decrementDepth() | ||
859 | } | ||
860 | |||
861 | type eightFieldsStructDecoder struct { | ||
862 | typ reflect2.Type | ||
863 | fieldHash1 int64 | ||
864 | fieldDecoder1 *structFieldDecoder | ||
865 | fieldHash2 int64 | ||
866 | fieldDecoder2 *structFieldDecoder | ||
867 | fieldHash3 int64 | ||
868 | fieldDecoder3 *structFieldDecoder | ||
869 | fieldHash4 int64 | ||
870 | fieldDecoder4 *structFieldDecoder | ||
871 | fieldHash5 int64 | ||
872 | fieldDecoder5 *structFieldDecoder | ||
873 | fieldHash6 int64 | ||
874 | fieldDecoder6 *structFieldDecoder | ||
875 | fieldHash7 int64 | ||
876 | fieldDecoder7 *structFieldDecoder | ||
877 | fieldHash8 int64 | ||
878 | fieldDecoder8 *structFieldDecoder | ||
879 | } | ||
880 | |||
881 | func (decoder *eightFieldsStructDecoder) Decode(ptr unsafe.Pointer, iter *Iterator) { | ||
882 | if !iter.readObjectStart() { | ||
883 | return | ||
884 | } | ||
885 | if !iter.incrementDepth() { | ||
886 | return | ||
887 | } | ||
888 | for { | ||
889 | switch iter.readFieldHash() { | ||
890 | case decoder.fieldHash1: | ||
891 | decoder.fieldDecoder1.Decode(ptr, iter) | ||
892 | case decoder.fieldHash2: | ||
893 | decoder.fieldDecoder2.Decode(ptr, iter) | ||
894 | case decoder.fieldHash3: | ||
895 | decoder.fieldDecoder3.Decode(ptr, iter) | ||
896 | case decoder.fieldHash4: | ||
897 | decoder.fieldDecoder4.Decode(ptr, iter) | ||
898 | case decoder.fieldHash5: | ||
899 | decoder.fieldDecoder5.Decode(ptr, iter) | ||
900 | case decoder.fieldHash6: | ||
901 | decoder.fieldDecoder6.Decode(ptr, iter) | ||
902 | case decoder.fieldHash7: | ||
903 | decoder.fieldDecoder7.Decode(ptr, iter) | ||
904 | case decoder.fieldHash8: | ||
905 | decoder.fieldDecoder8.Decode(ptr, iter) | ||
906 | default: | ||
907 | iter.Skip() | ||
908 | } | ||
909 | if iter.isObjectEnd() { | ||
910 | break | ||
911 | } | ||
912 | } | ||
913 | if iter.Error != nil && iter.Error != io.EOF && len(decoder.typ.Type1().Name()) != 0 { | ||
914 | iter.Error = fmt.Errorf("%v.%s", decoder.typ, iter.Error.Error()) | ||
915 | } | ||
916 | iter.decrementDepth() | ||
917 | } | ||
918 | |||
919 | type nineFieldsStructDecoder struct { | ||
920 | typ reflect2.Type | ||
921 | fieldHash1 int64 | ||
922 | fieldDecoder1 *structFieldDecoder | ||
923 | fieldHash2 int64 | ||
924 | fieldDecoder2 *structFieldDecoder | ||
925 | fieldHash3 int64 | ||
926 | fieldDecoder3 *structFieldDecoder | ||
927 | fieldHash4 int64 | ||
928 | fieldDecoder4 *structFieldDecoder | ||
929 | fieldHash5 int64 | ||
930 | fieldDecoder5 *structFieldDecoder | ||
931 | fieldHash6 int64 | ||
932 | fieldDecoder6 *structFieldDecoder | ||
933 | fieldHash7 int64 | ||
934 | fieldDecoder7 *structFieldDecoder | ||
935 | fieldHash8 int64 | ||
936 | fieldDecoder8 *structFieldDecoder | ||
937 | fieldHash9 int64 | ||
938 | fieldDecoder9 *structFieldDecoder | ||
939 | } | ||
940 | |||
941 | func (decoder *nineFieldsStructDecoder) Decode(ptr unsafe.Pointer, iter *Iterator) { | ||
942 | if !iter.readObjectStart() { | ||
943 | return | ||
944 | } | ||
945 | if !iter.incrementDepth() { | ||
946 | return | ||
947 | } | ||
948 | for { | ||
949 | switch iter.readFieldHash() { | ||
950 | case decoder.fieldHash1: | ||
951 | decoder.fieldDecoder1.Decode(ptr, iter) | ||
952 | case decoder.fieldHash2: | ||
953 | decoder.fieldDecoder2.Decode(ptr, iter) | ||
954 | case decoder.fieldHash3: | ||
955 | decoder.fieldDecoder3.Decode(ptr, iter) | ||
956 | case decoder.fieldHash4: | ||
957 | decoder.fieldDecoder4.Decode(ptr, iter) | ||
958 | case decoder.fieldHash5: | ||
959 | decoder.fieldDecoder5.Decode(ptr, iter) | ||
960 | case decoder.fieldHash6: | ||
961 | decoder.fieldDecoder6.Decode(ptr, iter) | ||
962 | case decoder.fieldHash7: | ||
963 | decoder.fieldDecoder7.Decode(ptr, iter) | ||
964 | case decoder.fieldHash8: | ||
965 | decoder.fieldDecoder8.Decode(ptr, iter) | ||
966 | case decoder.fieldHash9: | ||
967 | decoder.fieldDecoder9.Decode(ptr, iter) | ||
968 | default: | ||
969 | iter.Skip() | ||
970 | } | ||
971 | if iter.isObjectEnd() { | ||
972 | break | ||
973 | } | ||
974 | } | ||
975 | if iter.Error != nil && iter.Error != io.EOF && len(decoder.typ.Type1().Name()) != 0 { | ||
976 | iter.Error = fmt.Errorf("%v.%s", decoder.typ, iter.Error.Error()) | ||
977 | } | ||
978 | iter.decrementDepth() | ||
979 | } | ||
980 | |||
981 | type tenFieldsStructDecoder struct { | ||
982 | typ reflect2.Type | ||
983 | fieldHash1 int64 | ||
984 | fieldDecoder1 *structFieldDecoder | ||
985 | fieldHash2 int64 | ||
986 | fieldDecoder2 *structFieldDecoder | ||
987 | fieldHash3 int64 | ||
988 | fieldDecoder3 *structFieldDecoder | ||
989 | fieldHash4 int64 | ||
990 | fieldDecoder4 *structFieldDecoder | ||
991 | fieldHash5 int64 | ||
992 | fieldDecoder5 *structFieldDecoder | ||
993 | fieldHash6 int64 | ||
994 | fieldDecoder6 *structFieldDecoder | ||
995 | fieldHash7 int64 | ||
996 | fieldDecoder7 *structFieldDecoder | ||
997 | fieldHash8 int64 | ||
998 | fieldDecoder8 *structFieldDecoder | ||
999 | fieldHash9 int64 | ||
1000 | fieldDecoder9 *structFieldDecoder | ||
1001 | fieldHash10 int64 | ||
1002 | fieldDecoder10 *structFieldDecoder | ||
1003 | } | ||
1004 | |||
1005 | func (decoder *tenFieldsStructDecoder) Decode(ptr unsafe.Pointer, iter *Iterator) { | ||
1006 | if !iter.readObjectStart() { | ||
1007 | return | ||
1008 | } | ||
1009 | if !iter.incrementDepth() { | ||
1010 | return | ||
1011 | } | ||
1012 | for { | ||
1013 | switch iter.readFieldHash() { | ||
1014 | case decoder.fieldHash1: | ||
1015 | decoder.fieldDecoder1.Decode(ptr, iter) | ||
1016 | case decoder.fieldHash2: | ||
1017 | decoder.fieldDecoder2.Decode(ptr, iter) | ||
1018 | case decoder.fieldHash3: | ||
1019 | decoder.fieldDecoder3.Decode(ptr, iter) | ||
1020 | case decoder.fieldHash4: | ||
1021 | decoder.fieldDecoder4.Decode(ptr, iter) | ||
1022 | case decoder.fieldHash5: | ||
1023 | decoder.fieldDecoder5.Decode(ptr, iter) | ||
1024 | case decoder.fieldHash6: | ||
1025 | decoder.fieldDecoder6.Decode(ptr, iter) | ||
1026 | case decoder.fieldHash7: | ||
1027 | decoder.fieldDecoder7.Decode(ptr, iter) | ||
1028 | case decoder.fieldHash8: | ||
1029 | decoder.fieldDecoder8.Decode(ptr, iter) | ||
1030 | case decoder.fieldHash9: | ||
1031 | decoder.fieldDecoder9.Decode(ptr, iter) | ||
1032 | case decoder.fieldHash10: | ||
1033 | decoder.fieldDecoder10.Decode(ptr, iter) | ||
1034 | default: | ||
1035 | iter.Skip() | ||
1036 | } | ||
1037 | if iter.isObjectEnd() { | ||
1038 | break | ||
1039 | } | ||
1040 | } | ||
1041 | if iter.Error != nil && iter.Error != io.EOF && len(decoder.typ.Type1().Name()) != 0 { | ||
1042 | iter.Error = fmt.Errorf("%v.%s", decoder.typ, iter.Error.Error()) | ||
1043 | } | ||
1044 | iter.decrementDepth() | ||
1045 | } | ||
1046 | |||
1047 | type structFieldDecoder struct { | ||
1048 | field reflect2.StructField | ||
1049 | fieldDecoder ValDecoder | ||
1050 | } | ||
1051 | |||
1052 | func (decoder *structFieldDecoder) Decode(ptr unsafe.Pointer, iter *Iterator) { | ||
1053 | fieldPtr := decoder.field.UnsafeGet(ptr) | ||
1054 | decoder.fieldDecoder.Decode(fieldPtr, iter) | ||
1055 | if iter.Error != nil && iter.Error != io.EOF { | ||
1056 | iter.Error = fmt.Errorf("%s: %s", decoder.field.Name(), iter.Error.Error()) | ||
1057 | } | ||
1058 | } | ||
1059 | |||
1060 | type stringModeStringDecoder struct { | ||
1061 | elemDecoder ValDecoder | ||
1062 | cfg *frozenConfig | ||
1063 | } | ||
1064 | |||
1065 | func (decoder *stringModeStringDecoder) Decode(ptr unsafe.Pointer, iter *Iterator) { | ||
1066 | decoder.elemDecoder.Decode(ptr, iter) | ||
1067 | str := *((*string)(ptr)) | ||
1068 | tempIter := decoder.cfg.BorrowIterator([]byte(str)) | ||
1069 | defer decoder.cfg.ReturnIterator(tempIter) | ||
1070 | *((*string)(ptr)) = tempIter.ReadString() | ||
1071 | } | ||
1072 | |||
1073 | type stringModeNumberDecoder struct { | ||
1074 | elemDecoder ValDecoder | ||
1075 | } | ||
1076 | |||
1077 | func (decoder *stringModeNumberDecoder) Decode(ptr unsafe.Pointer, iter *Iterator) { | ||
1078 | if iter.WhatIsNext() == NilValue { | ||
1079 | decoder.elemDecoder.Decode(ptr, iter) | ||
1080 | return | ||
1081 | } | ||
1082 | |||
1083 | c := iter.nextToken() | ||
1084 | if c != '"' { | ||
1085 | iter.ReportError("stringModeNumberDecoder", `expect ", but found `+string([]byte{c})) | ||
1086 | return | ||
1087 | } | ||
1088 | decoder.elemDecoder.Decode(ptr, iter) | ||
1089 | if iter.Error != nil { | ||
1090 | return | ||
1091 | } | ||
1092 | c = iter.readByte() | ||
1093 | if c != '"' { | ||
1094 | iter.ReportError("stringModeNumberDecoder", `expect ", but found `+string([]byte{c})) | ||
1095 | return | ||
1096 | } | ||
1097 | } | ||
diff --git a/vendor/github.com/json-iterator/go/reflect_struct_encoder.go b/vendor/github.com/json-iterator/go/reflect_struct_encoder.go deleted file mode 100644 index 152e3ef..0000000 --- a/vendor/github.com/json-iterator/go/reflect_struct_encoder.go +++ /dev/null | |||
@@ -1,211 +0,0 @@ | |||
1 | package jsoniter | ||
2 | |||
3 | import ( | ||
4 | "fmt" | ||
5 | "github.com/modern-go/reflect2" | ||
6 | "io" | ||
7 | "reflect" | ||
8 | "unsafe" | ||
9 | ) | ||
10 | |||
11 | func encoderOfStruct(ctx *ctx, typ reflect2.Type) ValEncoder { | ||
12 | type bindingTo struct { | ||
13 | binding *Binding | ||
14 | toName string | ||
15 | ignored bool | ||
16 | } | ||
17 | orderedBindings := []*bindingTo{} | ||
18 | structDescriptor := describeStruct(ctx, typ) | ||
19 | for _, binding := range structDescriptor.Fields { | ||
20 | for _, toName := range binding.ToNames { | ||
21 | new := &bindingTo{ | ||
22 | binding: binding, | ||
23 | toName: toName, | ||
24 | } | ||
25 | for _, old := range orderedBindings { | ||
26 | if old.toName != toName { | ||
27 | continue | ||
28 | } | ||
29 | old.ignored, new.ignored = resolveConflictBinding(ctx.frozenConfig, old.binding, new.binding) | ||
30 | } | ||
31 | orderedBindings = append(orderedBindings, new) | ||
32 | } | ||
33 | } | ||
34 | if len(orderedBindings) == 0 { | ||
35 | return &emptyStructEncoder{} | ||
36 | } | ||
37 | finalOrderedFields := []structFieldTo{} | ||
38 | for _, bindingTo := range orderedBindings { | ||
39 | if !bindingTo.ignored { | ||
40 | finalOrderedFields = append(finalOrderedFields, structFieldTo{ | ||
41 | encoder: bindingTo.binding.Encoder.(*structFieldEncoder), | ||
42 | toName: bindingTo.toName, | ||
43 | }) | ||
44 | } | ||
45 | } | ||
46 | return &structEncoder{typ, finalOrderedFields} | ||
47 | } | ||
48 | |||
49 | func createCheckIsEmpty(ctx *ctx, typ reflect2.Type) checkIsEmpty { | ||
50 | encoder := createEncoderOfNative(ctx, typ) | ||
51 | if encoder != nil { | ||
52 | return encoder | ||
53 | } | ||
54 | kind := typ.Kind() | ||
55 | switch kind { | ||
56 | case reflect.Interface: | ||
57 | return &dynamicEncoder{typ} | ||
58 | case reflect.Struct: | ||
59 | return &structEncoder{typ: typ} | ||
60 | case reflect.Array: | ||
61 | return &arrayEncoder{} | ||
62 | case reflect.Slice: | ||
63 | return &sliceEncoder{} | ||
64 | case reflect.Map: | ||
65 | return encoderOfMap(ctx, typ) | ||
66 | case reflect.Ptr: | ||
67 | return &OptionalEncoder{} | ||
68 | default: | ||
69 | return &lazyErrorEncoder{err: fmt.Errorf("unsupported type: %v", typ)} | ||
70 | } | ||
71 | } | ||
72 | |||
73 | func resolveConflictBinding(cfg *frozenConfig, old, new *Binding) (ignoreOld, ignoreNew bool) { | ||
74 | newTagged := new.Field.Tag().Get(cfg.getTagKey()) != "" | ||
75 | oldTagged := old.Field.Tag().Get(cfg.getTagKey()) != "" | ||
76 | if newTagged { | ||
77 | if oldTagged { | ||
78 | if len(old.levels) > len(new.levels) { | ||
79 | return true, false | ||
80 | } else if len(new.levels) > len(old.levels) { | ||
81 | return false, true | ||
82 | } else { | ||
83 | return true, true | ||
84 | } | ||
85 | } else { | ||
86 | return true, false | ||
87 | } | ||
88 | } else { | ||
89 | if oldTagged { | ||
90 | return true, false | ||
91 | } | ||
92 | if len(old.levels) > len(new.levels) { | ||
93 | return true, false | ||
94 | } else if len(new.levels) > len(old.levels) { | ||
95 | return false, true | ||
96 | } else { | ||
97 | return true, true | ||
98 | } | ||
99 | } | ||
100 | } | ||
101 | |||
102 | type structFieldEncoder struct { | ||
103 | field reflect2.StructField | ||
104 | fieldEncoder ValEncoder | ||
105 | omitempty bool | ||
106 | } | ||
107 | |||
108 | func (encoder *structFieldEncoder) Encode(ptr unsafe.Pointer, stream *Stream) { | ||
109 | fieldPtr := encoder.field.UnsafeGet(ptr) | ||
110 | encoder.fieldEncoder.Encode(fieldPtr, stream) | ||
111 | if stream.Error != nil && stream.Error != io.EOF { | ||
112 | stream.Error = fmt.Errorf("%s: %s", encoder.field.Name(), stream.Error.Error()) | ||
113 | } | ||
114 | } | ||
115 | |||
116 | func (encoder *structFieldEncoder) IsEmpty(ptr unsafe.Pointer) bool { | ||
117 | fieldPtr := encoder.field.UnsafeGet(ptr) | ||
118 | return encoder.fieldEncoder.IsEmpty(fieldPtr) | ||
119 | } | ||
120 | |||
121 | func (encoder *structFieldEncoder) IsEmbeddedPtrNil(ptr unsafe.Pointer) bool { | ||
122 | isEmbeddedPtrNil, converted := encoder.fieldEncoder.(IsEmbeddedPtrNil) | ||
123 | if !converted { | ||
124 | return false | ||
125 | } | ||
126 | fieldPtr := encoder.field.UnsafeGet(ptr) | ||
127 | return isEmbeddedPtrNil.IsEmbeddedPtrNil(fieldPtr) | ||
128 | } | ||
129 | |||
130 | type IsEmbeddedPtrNil interface { | ||
131 | IsEmbeddedPtrNil(ptr unsafe.Pointer) bool | ||
132 | } | ||
133 | |||
134 | type structEncoder struct { | ||
135 | typ reflect2.Type | ||
136 | fields []structFieldTo | ||
137 | } | ||
138 | |||
139 | type structFieldTo struct { | ||
140 | encoder *structFieldEncoder | ||
141 | toName string | ||
142 | } | ||
143 | |||
144 | func (encoder *structEncoder) Encode(ptr unsafe.Pointer, stream *Stream) { | ||
145 | stream.WriteObjectStart() | ||
146 | isNotFirst := false | ||
147 | for _, field := range encoder.fields { | ||
148 | if field.encoder.omitempty && field.encoder.IsEmpty(ptr) { | ||
149 | continue | ||
150 | } | ||
151 | if field.encoder.IsEmbeddedPtrNil(ptr) { | ||
152 | continue | ||
153 | } | ||
154 | if isNotFirst { | ||
155 | stream.WriteMore() | ||
156 | } | ||
157 | stream.WriteObjectField(field.toName) | ||
158 | field.encoder.Encode(ptr, stream) | ||
159 | isNotFirst = true | ||
160 | } | ||
161 | stream.WriteObjectEnd() | ||
162 | if stream.Error != nil && stream.Error != io.EOF { | ||
163 | stream.Error = fmt.Errorf("%v.%s", encoder.typ, stream.Error.Error()) | ||
164 | } | ||
165 | } | ||
166 | |||
167 | func (encoder *structEncoder) IsEmpty(ptr unsafe.Pointer) bool { | ||
168 | return false | ||
169 | } | ||
170 | |||
171 | type emptyStructEncoder struct { | ||
172 | } | ||
173 | |||
174 | func (encoder *emptyStructEncoder) Encode(ptr unsafe.Pointer, stream *Stream) { | ||
175 | stream.WriteEmptyObject() | ||
176 | } | ||
177 | |||
178 | func (encoder *emptyStructEncoder) IsEmpty(ptr unsafe.Pointer) bool { | ||
179 | return false | ||
180 | } | ||
181 | |||
182 | type stringModeNumberEncoder struct { | ||
183 | elemEncoder ValEncoder | ||
184 | } | ||
185 | |||
186 | func (encoder *stringModeNumberEncoder) Encode(ptr unsafe.Pointer, stream *Stream) { | ||
187 | stream.writeByte('"') | ||
188 | encoder.elemEncoder.Encode(ptr, stream) | ||
189 | stream.writeByte('"') | ||
190 | } | ||
191 | |||
192 | func (encoder *stringModeNumberEncoder) IsEmpty(ptr unsafe.Pointer) bool { | ||
193 | return encoder.elemEncoder.IsEmpty(ptr) | ||
194 | } | ||
195 | |||
196 | type stringModeStringEncoder struct { | ||
197 | elemEncoder ValEncoder | ||
198 | cfg *frozenConfig | ||
199 | } | ||
200 | |||
201 | func (encoder *stringModeStringEncoder) Encode(ptr unsafe.Pointer, stream *Stream) { | ||
202 | tempStream := encoder.cfg.BorrowStream(nil) | ||
203 | tempStream.Attachment = stream.Attachment | ||
204 | defer encoder.cfg.ReturnStream(tempStream) | ||
205 | encoder.elemEncoder.Encode(ptr, tempStream) | ||
206 | stream.WriteString(string(tempStream.Buffer())) | ||
207 | } | ||
208 | |||
209 | func (encoder *stringModeStringEncoder) IsEmpty(ptr unsafe.Pointer) bool { | ||
210 | return encoder.elemEncoder.IsEmpty(ptr) | ||
211 | } | ||
diff --git a/vendor/github.com/json-iterator/go/stream.go b/vendor/github.com/json-iterator/go/stream.go deleted file mode 100644 index 23d8a3a..0000000 --- a/vendor/github.com/json-iterator/go/stream.go +++ /dev/null | |||
@@ -1,210 +0,0 @@ | |||
1 | package jsoniter | ||
2 | |||
3 | import ( | ||
4 | "io" | ||
5 | ) | ||
6 | |||
7 | // stream is a io.Writer like object, with JSON specific write functions. | ||
8 | // Error is not returned as return value, but stored as Error member on this stream instance. | ||
9 | type Stream struct { | ||
10 | cfg *frozenConfig | ||
11 | out io.Writer | ||
12 | buf []byte | ||
13 | Error error | ||
14 | indention int | ||
15 | Attachment interface{} // open for customized encoder | ||
16 | } | ||
17 | |||
18 | // NewStream create new stream instance. | ||
19 | // cfg can be jsoniter.ConfigDefault. | ||
20 | // out can be nil if write to internal buffer. | ||
21 | // bufSize is the initial size for the internal buffer in bytes. | ||
22 | func NewStream(cfg API, out io.Writer, bufSize int) *Stream { | ||
23 | return &Stream{ | ||
24 | cfg: cfg.(*frozenConfig), | ||
25 | out: out, | ||
26 | buf: make([]byte, 0, bufSize), | ||
27 | Error: nil, | ||
28 | indention: 0, | ||
29 | } | ||
30 | } | ||
31 | |||
32 | // Pool returns a pool can provide more stream with same configuration | ||
33 | func (stream *Stream) Pool() StreamPool { | ||
34 | return stream.cfg | ||
35 | } | ||
36 | |||
37 | // Reset reuse this stream instance by assign a new writer | ||
38 | func (stream *Stream) Reset(out io.Writer) { | ||
39 | stream.out = out | ||
40 | stream.buf = stream.buf[:0] | ||
41 | } | ||
42 | |||
43 | // Available returns how many bytes are unused in the buffer. | ||
44 | func (stream *Stream) Available() int { | ||
45 | return cap(stream.buf) - len(stream.buf) | ||
46 | } | ||
47 | |||
48 | // Buffered returns the number of bytes that have been written into the current buffer. | ||
49 | func (stream *Stream) Buffered() int { | ||
50 | return len(stream.buf) | ||
51 | } | ||
52 | |||
53 | // Buffer if writer is nil, use this method to take the result | ||
54 | func (stream *Stream) Buffer() []byte { | ||
55 | return stream.buf | ||
56 | } | ||
57 | |||
58 | // SetBuffer allows to append to the internal buffer directly | ||
59 | func (stream *Stream) SetBuffer(buf []byte) { | ||
60 | stream.buf = buf | ||
61 | } | ||
62 | |||
63 | // Write writes the contents of p into the buffer. | ||
64 | // It returns the number of bytes written. | ||
65 | // If nn < len(p), it also returns an error explaining | ||
66 | // why the write is short. | ||
67 | func (stream *Stream) Write(p []byte) (nn int, err error) { | ||
68 | stream.buf = append(stream.buf, p...) | ||
69 | if stream.out != nil { | ||
70 | nn, err = stream.out.Write(stream.buf) | ||
71 | stream.buf = stream.buf[nn:] | ||
72 | return | ||
73 | } | ||
74 | return len(p), nil | ||
75 | } | ||
76 | |||
77 | // WriteByte writes a single byte. | ||
78 | func (stream *Stream) writeByte(c byte) { | ||
79 | stream.buf = append(stream.buf, c) | ||
80 | } | ||
81 | |||
82 | func (stream *Stream) writeTwoBytes(c1 byte, c2 byte) { | ||
83 | stream.buf = append(stream.buf, c1, c2) | ||
84 | } | ||
85 | |||
86 | func (stream *Stream) writeThreeBytes(c1 byte, c2 byte, c3 byte) { | ||
87 | stream.buf = append(stream.buf, c1, c2, c3) | ||
88 | } | ||
89 | |||
90 | func (stream *Stream) writeFourBytes(c1 byte, c2 byte, c3 byte, c4 byte) { | ||
91 | stream.buf = append(stream.buf, c1, c2, c3, c4) | ||
92 | } | ||
93 | |||
94 | func (stream *Stream) writeFiveBytes(c1 byte, c2 byte, c3 byte, c4 byte, c5 byte) { | ||
95 | stream.buf = append(stream.buf, c1, c2, c3, c4, c5) | ||
96 | } | ||
97 | |||
98 | // Flush writes any buffered data to the underlying io.Writer. | ||
99 | func (stream *Stream) Flush() error { | ||
100 | if stream.out == nil { | ||
101 | return nil | ||
102 | } | ||
103 | if stream.Error != nil { | ||
104 | return stream.Error | ||
105 | } | ||
106 | _, err := stream.out.Write(stream.buf) | ||
107 | if err != nil { | ||
108 | if stream.Error == nil { | ||
109 | stream.Error = err | ||
110 | } | ||
111 | return err | ||
112 | } | ||
113 | stream.buf = stream.buf[:0] | ||
114 | return nil | ||
115 | } | ||
116 | |||
117 | // WriteRaw write string out without quotes, just like []byte | ||
118 | func (stream *Stream) WriteRaw(s string) { | ||
119 | stream.buf = append(stream.buf, s...) | ||
120 | } | ||
121 | |||
122 | // WriteNil write null to stream | ||
123 | func (stream *Stream) WriteNil() { | ||
124 | stream.writeFourBytes('n', 'u', 'l', 'l') | ||
125 | } | ||
126 | |||
127 | // WriteTrue write true to stream | ||
128 | func (stream *Stream) WriteTrue() { | ||
129 | stream.writeFourBytes('t', 'r', 'u', 'e') | ||
130 | } | ||
131 | |||
132 | // WriteFalse write false to stream | ||
133 | func (stream *Stream) WriteFalse() { | ||
134 | stream.writeFiveBytes('f', 'a', 'l', 's', 'e') | ||
135 | } | ||
136 | |||
137 | // WriteBool write true or false into stream | ||
138 | func (stream *Stream) WriteBool(val bool) { | ||
139 | if val { | ||
140 | stream.WriteTrue() | ||
141 | } else { | ||
142 | stream.WriteFalse() | ||
143 | } | ||
144 | } | ||
145 | |||
146 | // WriteObjectStart write { with possible indention | ||
147 | func (stream *Stream) WriteObjectStart() { | ||
148 | stream.indention += stream.cfg.indentionStep | ||
149 | stream.writeByte('{') | ||
150 | stream.writeIndention(0) | ||
151 | } | ||
152 | |||
153 | // WriteObjectField write "field": with possible indention | ||
154 | func (stream *Stream) WriteObjectField(field string) { | ||
155 | stream.WriteString(field) | ||
156 | if stream.indention > 0 { | ||
157 | stream.writeTwoBytes(':', ' ') | ||
158 | } else { | ||
159 | stream.writeByte(':') | ||
160 | } | ||
161 | } | ||
162 | |||
163 | // WriteObjectEnd write } with possible indention | ||
164 | func (stream *Stream) WriteObjectEnd() { | ||
165 | stream.writeIndention(stream.cfg.indentionStep) | ||
166 | stream.indention -= stream.cfg.indentionStep | ||
167 | stream.writeByte('}') | ||
168 | } | ||
169 | |||
170 | // WriteEmptyObject write {} | ||
171 | func (stream *Stream) WriteEmptyObject() { | ||
172 | stream.writeByte('{') | ||
173 | stream.writeByte('}') | ||
174 | } | ||
175 | |||
176 | // WriteMore write , with possible indention | ||
177 | func (stream *Stream) WriteMore() { | ||
178 | stream.writeByte(',') | ||
179 | stream.writeIndention(0) | ||
180 | } | ||
181 | |||
182 | // WriteArrayStart write [ with possible indention | ||
183 | func (stream *Stream) WriteArrayStart() { | ||
184 | stream.indention += stream.cfg.indentionStep | ||
185 | stream.writeByte('[') | ||
186 | stream.writeIndention(0) | ||
187 | } | ||
188 | |||
189 | // WriteEmptyArray write [] | ||
190 | func (stream *Stream) WriteEmptyArray() { | ||
191 | stream.writeTwoBytes('[', ']') | ||
192 | } | ||
193 | |||
194 | // WriteArrayEnd write ] with possible indention | ||
195 | func (stream *Stream) WriteArrayEnd() { | ||
196 | stream.writeIndention(stream.cfg.indentionStep) | ||
197 | stream.indention -= stream.cfg.indentionStep | ||
198 | stream.writeByte(']') | ||
199 | } | ||
200 | |||
201 | func (stream *Stream) writeIndention(delta int) { | ||
202 | if stream.indention == 0 { | ||
203 | return | ||
204 | } | ||
205 | stream.writeByte('\n') | ||
206 | toWrite := stream.indention - delta | ||
207 | for i := 0; i < toWrite; i++ { | ||
208 | stream.buf = append(stream.buf, ' ') | ||
209 | } | ||
210 | } | ||
diff --git a/vendor/github.com/json-iterator/go/stream_float.go b/vendor/github.com/json-iterator/go/stream_float.go deleted file mode 100644 index 826aa59..0000000 --- a/vendor/github.com/json-iterator/go/stream_float.go +++ /dev/null | |||
@@ -1,111 +0,0 @@ | |||
1 | package jsoniter | ||
2 | |||
3 | import ( | ||
4 | "fmt" | ||
5 | "math" | ||
6 | "strconv" | ||
7 | ) | ||
8 | |||
9 | var pow10 []uint64 | ||
10 | |||
11 | func init() { | ||
12 | pow10 = []uint64{1, 10, 100, 1000, 10000, 100000, 1000000} | ||
13 | } | ||
14 | |||
15 | // WriteFloat32 write float32 to stream | ||
16 | func (stream *Stream) WriteFloat32(val float32) { | ||
17 | if math.IsInf(float64(val), 0) || math.IsNaN(float64(val)) { | ||
18 | stream.Error = fmt.Errorf("unsupported value: %f", val) | ||
19 | return | ||
20 | } | ||
21 | abs := math.Abs(float64(val)) | ||
22 | fmt := byte('f') | ||
23 | // Note: Must use float32 comparisons for underlying float32 value to get precise cutoffs right. | ||
24 | if abs != 0 { | ||
25 | if float32(abs) < 1e-6 || float32(abs) >= 1e21 { | ||
26 | fmt = 'e' | ||
27 | } | ||
28 | } | ||
29 | stream.buf = strconv.AppendFloat(stream.buf, float64(val), fmt, -1, 32) | ||
30 | } | ||
31 | |||
32 | // WriteFloat32Lossy write float32 to stream with ONLY 6 digits precision although much much faster | ||
33 | func (stream *Stream) WriteFloat32Lossy(val float32) { | ||
34 | if math.IsInf(float64(val), 0) || math.IsNaN(float64(val)) { | ||
35 | stream.Error = fmt.Errorf("unsupported value: %f", val) | ||
36 | return | ||
37 | } | ||
38 | if val < 0 { | ||
39 | stream.writeByte('-') | ||
40 | val = -val | ||
41 | } | ||
42 | if val > 0x4ffffff { | ||
43 | stream.WriteFloat32(val) | ||
44 | return | ||
45 | } | ||
46 | precision := 6 | ||
47 | exp := uint64(1000000) // 6 | ||
48 | lval := uint64(float64(val)*float64(exp) + 0.5) | ||
49 | stream.WriteUint64(lval / exp) | ||
50 | fval := lval % exp | ||
51 | if fval == 0 { | ||
52 | return | ||
53 | } | ||
54 | stream.writeByte('.') | ||
55 | for p := precision - 1; p > 0 && fval < pow10[p]; p-- { | ||
56 | stream.writeByte('0') | ||
57 | } | ||
58 | stream.WriteUint64(fval) | ||
59 | for stream.buf[len(stream.buf)-1] == '0' { | ||
60 | stream.buf = stream.buf[:len(stream.buf)-1] | ||
61 | } | ||
62 | } | ||
63 | |||
64 | // WriteFloat64 write float64 to stream | ||
65 | func (stream *Stream) WriteFloat64(val float64) { | ||
66 | if math.IsInf(val, 0) || math.IsNaN(val) { | ||
67 | stream.Error = fmt.Errorf("unsupported value: %f", val) | ||
68 | return | ||
69 | } | ||
70 | abs := math.Abs(val) | ||
71 | fmt := byte('f') | ||
72 | // Note: Must use float32 comparisons for underlying float32 value to get precise cutoffs right. | ||
73 | if abs != 0 { | ||
74 | if abs < 1e-6 || abs >= 1e21 { | ||
75 | fmt = 'e' | ||
76 | } | ||
77 | } | ||
78 | stream.buf = strconv.AppendFloat(stream.buf, float64(val), fmt, -1, 64) | ||
79 | } | ||
80 | |||
81 | // WriteFloat64Lossy write float64 to stream with ONLY 6 digits precision although much much faster | ||
82 | func (stream *Stream) WriteFloat64Lossy(val float64) { | ||
83 | if math.IsInf(val, 0) || math.IsNaN(val) { | ||
84 | stream.Error = fmt.Errorf("unsupported value: %f", val) | ||
85 | return | ||
86 | } | ||
87 | if val < 0 { | ||
88 | stream.writeByte('-') | ||
89 | val = -val | ||
90 | } | ||
91 | if val > 0x4ffffff { | ||
92 | stream.WriteFloat64(val) | ||
93 | return | ||
94 | } | ||
95 | precision := 6 | ||
96 | exp := uint64(1000000) // 6 | ||
97 | lval := uint64(val*float64(exp) + 0.5) | ||
98 | stream.WriteUint64(lval / exp) | ||
99 | fval := lval % exp | ||
100 | if fval == 0 { | ||
101 | return | ||
102 | } | ||
103 | stream.writeByte('.') | ||
104 | for p := precision - 1; p > 0 && fval < pow10[p]; p-- { | ||
105 | stream.writeByte('0') | ||
106 | } | ||
107 | stream.WriteUint64(fval) | ||
108 | for stream.buf[len(stream.buf)-1] == '0' { | ||
109 | stream.buf = stream.buf[:len(stream.buf)-1] | ||
110 | } | ||
111 | } | ||
diff --git a/vendor/github.com/json-iterator/go/stream_int.go b/vendor/github.com/json-iterator/go/stream_int.go deleted file mode 100644 index d1059ee..0000000 --- a/vendor/github.com/json-iterator/go/stream_int.go +++ /dev/null | |||
@@ -1,190 +0,0 @@ | |||
1 | package jsoniter | ||
2 | |||
3 | var digits []uint32 | ||
4 | |||
5 | func init() { | ||
6 | digits = make([]uint32, 1000) | ||
7 | for i := uint32(0); i < 1000; i++ { | ||
8 | digits[i] = (((i / 100) + '0') << 16) + ((((i / 10) % 10) + '0') << 8) + i%10 + '0' | ||
9 | if i < 10 { | ||
10 | digits[i] += 2 << 24 | ||
11 | } else if i < 100 { | ||
12 | digits[i] += 1 << 24 | ||
13 | } | ||
14 | } | ||
15 | } | ||
16 | |||
17 | func writeFirstBuf(space []byte, v uint32) []byte { | ||
18 | start := v >> 24 | ||
19 | if start == 0 { | ||
20 | space = append(space, byte(v>>16), byte(v>>8)) | ||
21 | } else if start == 1 { | ||
22 | space = append(space, byte(v>>8)) | ||
23 | } | ||
24 | space = append(space, byte(v)) | ||
25 | return space | ||
26 | } | ||
27 | |||
28 | func writeBuf(buf []byte, v uint32) []byte { | ||
29 | return append(buf, byte(v>>16), byte(v>>8), byte(v)) | ||
30 | } | ||
31 | |||
32 | // WriteUint8 write uint8 to stream | ||
33 | func (stream *Stream) WriteUint8(val uint8) { | ||
34 | stream.buf = writeFirstBuf(stream.buf, digits[val]) | ||
35 | } | ||
36 | |||
37 | // WriteInt8 write int8 to stream | ||
38 | func (stream *Stream) WriteInt8(nval int8) { | ||
39 | var val uint8 | ||
40 | if nval < 0 { | ||
41 | val = uint8(-nval) | ||
42 | stream.buf = append(stream.buf, '-') | ||
43 | } else { | ||
44 | val = uint8(nval) | ||
45 | } | ||
46 | stream.buf = writeFirstBuf(stream.buf, digits[val]) | ||
47 | } | ||
48 | |||
49 | // WriteUint16 write uint16 to stream | ||
50 | func (stream *Stream) WriteUint16(val uint16) { | ||
51 | q1 := val / 1000 | ||
52 | if q1 == 0 { | ||
53 | stream.buf = writeFirstBuf(stream.buf, digits[val]) | ||
54 | return | ||
55 | } | ||
56 | r1 := val - q1*1000 | ||
57 | stream.buf = writeFirstBuf(stream.buf, digits[q1]) | ||
58 | stream.buf = writeBuf(stream.buf, digits[r1]) | ||
59 | return | ||
60 | } | ||
61 | |||
62 | // WriteInt16 write int16 to stream | ||
63 | func (stream *Stream) WriteInt16(nval int16) { | ||
64 | var val uint16 | ||
65 | if nval < 0 { | ||
66 | val = uint16(-nval) | ||
67 | stream.buf = append(stream.buf, '-') | ||
68 | } else { | ||
69 | val = uint16(nval) | ||
70 | } | ||
71 | stream.WriteUint16(val) | ||
72 | } | ||
73 | |||
74 | // WriteUint32 write uint32 to stream | ||
75 | func (stream *Stream) WriteUint32(val uint32) { | ||
76 | q1 := val / 1000 | ||
77 | if q1 == 0 { | ||
78 | stream.buf = writeFirstBuf(stream.buf, digits[val]) | ||
79 | return | ||
80 | } | ||
81 | r1 := val - q1*1000 | ||
82 | q2 := q1 / 1000 | ||
83 | if q2 == 0 { | ||
84 | stream.buf = writeFirstBuf(stream.buf, digits[q1]) | ||
85 | stream.buf = writeBuf(stream.buf, digits[r1]) | ||
86 | return | ||
87 | } | ||
88 | r2 := q1 - q2*1000 | ||
89 | q3 := q2 / 1000 | ||
90 | if q3 == 0 { | ||
91 | stream.buf = writeFirstBuf(stream.buf, digits[q2]) | ||
92 | } else { | ||
93 | r3 := q2 - q3*1000 | ||
94 | stream.buf = append(stream.buf, byte(q3+'0')) | ||
95 | stream.buf = writeBuf(stream.buf, digits[r3]) | ||
96 | } | ||
97 | stream.buf = writeBuf(stream.buf, digits[r2]) | ||
98 | stream.buf = writeBuf(stream.buf, digits[r1]) | ||
99 | } | ||
100 | |||
101 | // WriteInt32 write int32 to stream | ||
102 | func (stream *Stream) WriteInt32(nval int32) { | ||
103 | var val uint32 | ||
104 | if nval < 0 { | ||
105 | val = uint32(-nval) | ||
106 | stream.buf = append(stream.buf, '-') | ||
107 | } else { | ||
108 | val = uint32(nval) | ||
109 | } | ||
110 | stream.WriteUint32(val) | ||
111 | } | ||
112 | |||
113 | // WriteUint64 write uint64 to stream | ||
114 | func (stream *Stream) WriteUint64(val uint64) { | ||
115 | q1 := val / 1000 | ||
116 | if q1 == 0 { | ||
117 | stream.buf = writeFirstBuf(stream.buf, digits[val]) | ||
118 | return | ||
119 | } | ||
120 | r1 := val - q1*1000 | ||
121 | q2 := q1 / 1000 | ||
122 | if q2 == 0 { | ||
123 | stream.buf = writeFirstBuf(stream.buf, digits[q1]) | ||
124 | stream.buf = writeBuf(stream.buf, digits[r1]) | ||
125 | return | ||
126 | } | ||
127 | r2 := q1 - q2*1000 | ||
128 | q3 := q2 / 1000 | ||
129 | if q3 == 0 { | ||
130 | stream.buf = writeFirstBuf(stream.buf, digits[q2]) | ||
131 | stream.buf = writeBuf(stream.buf, digits[r2]) | ||
132 | stream.buf = writeBuf(stream.buf, digits[r1]) | ||
133 | return | ||
134 | } | ||
135 | r3 := q2 - q3*1000 | ||
136 | q4 := q3 / 1000 | ||
137 | if q4 == 0 { | ||
138 | stream.buf = writeFirstBuf(stream.buf, digits[q3]) | ||
139 | stream.buf = writeBuf(stream.buf, digits[r3]) | ||
140 | stream.buf = writeBuf(stream.buf, digits[r2]) | ||
141 | stream.buf = writeBuf(stream.buf, digits[r1]) | ||
142 | return | ||
143 | } | ||
144 | r4 := q3 - q4*1000 | ||
145 | q5 := q4 / 1000 | ||
146 | if q5 == 0 { | ||
147 | stream.buf = writeFirstBuf(stream.buf, digits[q4]) | ||
148 | stream.buf = writeBuf(stream.buf, digits[r4]) | ||
149 | stream.buf = writeBuf(stream.buf, digits[r3]) | ||
150 | stream.buf = writeBuf(stream.buf, digits[r2]) | ||
151 | stream.buf = writeBuf(stream.buf, digits[r1]) | ||
152 | return | ||
153 | } | ||
154 | r5 := q4 - q5*1000 | ||
155 | q6 := q5 / 1000 | ||
156 | if q6 == 0 { | ||
157 | stream.buf = writeFirstBuf(stream.buf, digits[q5]) | ||
158 | } else { | ||
159 | stream.buf = writeFirstBuf(stream.buf, digits[q6]) | ||
160 | r6 := q5 - q6*1000 | ||
161 | stream.buf = writeBuf(stream.buf, digits[r6]) | ||
162 | } | ||
163 | stream.buf = writeBuf(stream.buf, digits[r5]) | ||
164 | stream.buf = writeBuf(stream.buf, digits[r4]) | ||
165 | stream.buf = writeBuf(stream.buf, digits[r3]) | ||
166 | stream.buf = writeBuf(stream.buf, digits[r2]) | ||
167 | stream.buf = writeBuf(stream.buf, digits[r1]) | ||
168 | } | ||
169 | |||
170 | // WriteInt64 write int64 to stream | ||
171 | func (stream *Stream) WriteInt64(nval int64) { | ||
172 | var val uint64 | ||
173 | if nval < 0 { | ||
174 | val = uint64(-nval) | ||
175 | stream.buf = append(stream.buf, '-') | ||
176 | } else { | ||
177 | val = uint64(nval) | ||
178 | } | ||
179 | stream.WriteUint64(val) | ||
180 | } | ||
181 | |||
182 | // WriteInt write int to stream | ||
183 | func (stream *Stream) WriteInt(val int) { | ||
184 | stream.WriteInt64(int64(val)) | ||
185 | } | ||
186 | |||
187 | // WriteUint write uint to stream | ||
188 | func (stream *Stream) WriteUint(val uint) { | ||
189 | stream.WriteUint64(uint64(val)) | ||
190 | } | ||
diff --git a/vendor/github.com/json-iterator/go/stream_str.go b/vendor/github.com/json-iterator/go/stream_str.go deleted file mode 100644 index 54c2ba0..0000000 --- a/vendor/github.com/json-iterator/go/stream_str.go +++ /dev/null | |||
@@ -1,372 +0,0 @@ | |||
1 | package jsoniter | ||
2 | |||
3 | import ( | ||
4 | "unicode/utf8" | ||
5 | ) | ||
6 | |||
7 | // htmlSafeSet holds the value true if the ASCII character with the given | ||
8 | // array position can be safely represented inside a JSON string, embedded | ||
9 | // inside of HTML <script> tags, without any additional escaping. | ||
10 | // | ||
11 | // All values are true except for the ASCII control characters (0-31), the | ||
12 | // double quote ("), the backslash character ("\"), HTML opening and closing | ||
13 | // tags ("<" and ">"), and the ampersand ("&"). | ||
14 | var htmlSafeSet = [utf8.RuneSelf]bool{ | ||
15 | ' ': true, | ||
16 | '!': true, | ||
17 | '"': false, | ||
18 | '#': true, | ||
19 | '$': true, | ||
20 | '%': true, | ||
21 | '&': false, | ||
22 | '\'': true, | ||
23 | '(': true, | ||
24 | ')': true, | ||
25 | '*': true, | ||
26 | '+': true, | ||
27 | ',': true, | ||
28 | '-': true, | ||
29 | '.': true, | ||
30 | '/': true, | ||
31 | '0': true, | ||
32 | '1': true, | ||
33 | '2': true, | ||
34 | '3': true, | ||
35 | '4': true, | ||
36 | '5': true, | ||
37 | '6': true, | ||
38 | '7': true, | ||
39 | '8': true, | ||
40 | '9': true, | ||
41 | ':': true, | ||
42 | ';': true, | ||
43 | '<': false, | ||
44 | '=': true, | ||
45 | '>': false, | ||
46 | '?': true, | ||
47 | '@': true, | ||
48 | 'A': true, | ||
49 | 'B': true, | ||
50 | 'C': true, | ||
51 | 'D': true, | ||
52 | 'E': true, | ||
53 | 'F': true, | ||
54 | 'G': true, | ||
55 | 'H': true, | ||
56 | 'I': true, | ||
57 | 'J': true, | ||
58 | 'K': true, | ||
59 | 'L': true, | ||
60 | 'M': true, | ||
61 | 'N': true, | ||
62 | 'O': true, | ||
63 | 'P': true, | ||
64 | 'Q': true, | ||
65 | 'R': true, | ||
66 | 'S': true, | ||
67 | 'T': true, | ||
68 | 'U': true, | ||
69 | 'V': true, | ||
70 | 'W': true, | ||
71 | 'X': true, | ||
72 | 'Y': true, | ||
73 | 'Z': true, | ||
74 | '[': true, | ||
75 | '\\': false, | ||
76 | ']': true, | ||
77 | '^': true, | ||
78 | '_': true, | ||
79 | '`': true, | ||
80 | 'a': true, | ||
81 | 'b': true, | ||
82 | 'c': true, | ||
83 | 'd': true, | ||
84 | 'e': true, | ||
85 | 'f': true, | ||
86 | 'g': true, | ||
87 | 'h': true, | ||
88 | 'i': true, | ||
89 | 'j': true, | ||
90 | 'k': true, | ||
91 | 'l': true, | ||
92 | 'm': true, | ||
93 | 'n': true, | ||
94 | 'o': true, | ||
95 | 'p': true, | ||
96 | 'q': true, | ||
97 | 'r': true, | ||
98 | 's': true, | ||
99 | 't': true, | ||
100 | 'u': true, | ||
101 | 'v': true, | ||
102 | 'w': true, | ||
103 | 'x': true, | ||
104 | 'y': true, | ||
105 | 'z': true, | ||
106 | '{': true, | ||
107 | '|': true, | ||
108 | '}': true, | ||
109 | '~': true, | ||
110 | '\u007f': true, | ||
111 | } | ||
112 | |||
113 | // safeSet holds the value true if the ASCII character with the given array | ||
114 | // position can be represented inside a JSON string without any further | ||
115 | // escaping. | ||
116 | // | ||
117 | // All values are true except for the ASCII control characters (0-31), the | ||
118 | // double quote ("), and the backslash character ("\"). | ||
119 | var safeSet = [utf8.RuneSelf]bool{ | ||
120 | ' ': true, | ||
121 | '!': true, | ||
122 | '"': false, | ||
123 | '#': true, | ||
124 | '$': true, | ||
125 | '%': true, | ||
126 | '&': true, | ||
127 | '\'': true, | ||
128 | '(': true, | ||
129 | ')': true, | ||
130 | '*': true, | ||
131 | '+': true, | ||
132 | ',': true, | ||
133 | '-': true, | ||
134 | '.': true, | ||
135 | '/': true, | ||
136 | '0': true, | ||
137 | '1': true, | ||
138 | '2': true, | ||
139 | '3': true, | ||
140 | '4': true, | ||
141 | '5': true, | ||
142 | '6': true, | ||
143 | '7': true, | ||
144 | '8': true, | ||
145 | '9': true, | ||
146 | ':': true, | ||
147 | ';': true, | ||
148 | '<': true, | ||
149 | '=': true, | ||
150 | '>': true, | ||
151 | '?': true, | ||
152 | '@': true, | ||
153 | 'A': true, | ||
154 | 'B': true, | ||
155 | 'C': true, | ||
156 | 'D': true, | ||
157 | 'E': true, | ||
158 | 'F': true, | ||
159 | 'G': true, | ||
160 | 'H': true, | ||
161 | 'I': true, | ||
162 | 'J': true, | ||
163 | 'K': true, | ||
164 | 'L': true, | ||
165 | 'M': true, | ||
166 | 'N': true, | ||
167 | 'O': true, | ||
168 | 'P': true, | ||
169 | 'Q': true, | ||
170 | 'R': true, | ||
171 | 'S': true, | ||
172 | 'T': true, | ||
173 | 'U': true, | ||
174 | 'V': true, | ||
175 | 'W': true, | ||
176 | 'X': true, | ||
177 | 'Y': true, | ||
178 | 'Z': true, | ||
179 | '[': true, | ||
180 | '\\': false, | ||
181 | ']': true, | ||
182 | '^': true, | ||
183 | '_': true, | ||
184 | '`': true, | ||
185 | 'a': true, | ||
186 | 'b': true, | ||
187 | 'c': true, | ||
188 | 'd': true, | ||
189 | 'e': true, | ||
190 | 'f': true, | ||
191 | 'g': true, | ||
192 | 'h': true, | ||
193 | 'i': true, | ||
194 | 'j': true, | ||
195 | 'k': true, | ||
196 | 'l': true, | ||
197 | 'm': true, | ||
198 | 'n': true, | ||
199 | 'o': true, | ||
200 | 'p': true, | ||
201 | 'q': true, | ||
202 | 'r': true, | ||
203 | 's': true, | ||
204 | 't': true, | ||
205 | 'u': true, | ||
206 | 'v': true, | ||
207 | 'w': true, | ||
208 | 'x': true, | ||
209 | 'y': true, | ||
210 | 'z': true, | ||
211 | '{': true, | ||
212 | '|': true, | ||
213 | '}': true, | ||
214 | '~': true, | ||
215 | '\u007f': true, | ||
216 | } | ||
217 | |||
218 | var hex = "0123456789abcdef" | ||
219 | |||
220 | // WriteStringWithHTMLEscaped write string to stream with html special characters escaped | ||
221 | func (stream *Stream) WriteStringWithHTMLEscaped(s string) { | ||
222 | valLen := len(s) | ||
223 | stream.buf = append(stream.buf, '"') | ||
224 | // write string, the fast path, without utf8 and escape support | ||
225 | i := 0 | ||
226 | for ; i < valLen; i++ { | ||
227 | c := s[i] | ||
228 | if c < utf8.RuneSelf && htmlSafeSet[c] { | ||
229 | stream.buf = append(stream.buf, c) | ||
230 | } else { | ||
231 | break | ||
232 | } | ||
233 | } | ||
234 | if i == valLen { | ||
235 | stream.buf = append(stream.buf, '"') | ||
236 | return | ||
237 | } | ||
238 | writeStringSlowPathWithHTMLEscaped(stream, i, s, valLen) | ||
239 | } | ||
240 | |||
241 | func writeStringSlowPathWithHTMLEscaped(stream *Stream, i int, s string, valLen int) { | ||
242 | start := i | ||
243 | // for the remaining parts, we process them char by char | ||
244 | for i < valLen { | ||
245 | if b := s[i]; b < utf8.RuneSelf { | ||
246 | if htmlSafeSet[b] { | ||
247 | i++ | ||
248 | continue | ||
249 | } | ||
250 | if start < i { | ||
251 | stream.WriteRaw(s[start:i]) | ||
252 | } | ||
253 | switch b { | ||
254 | case '\\', '"': | ||
255 | stream.writeTwoBytes('\\', b) | ||
256 | case '\n': | ||
257 | stream.writeTwoBytes('\\', 'n') | ||
258 | case '\r': | ||
259 | stream.writeTwoBytes('\\', 'r') | ||
260 | case '\t': | ||
261 | stream.writeTwoBytes('\\', 't') | ||
262 | default: | ||
263 | // This encodes bytes < 0x20 except for \t, \n and \r. | ||
264 | // If escapeHTML is set, it also escapes <, >, and & | ||
265 | // because they can lead to security holes when | ||
266 | // user-controlled strings are rendered into JSON | ||
267 | // and served to some browsers. | ||
268 | stream.WriteRaw(`\u00`) | ||
269 | stream.writeTwoBytes(hex[b>>4], hex[b&0xF]) | ||
270 | } | ||
271 | i++ | ||
272 | start = i | ||
273 | continue | ||
274 | } | ||
275 | c, size := utf8.DecodeRuneInString(s[i:]) | ||
276 | if c == utf8.RuneError && size == 1 { | ||
277 | if start < i { | ||
278 | stream.WriteRaw(s[start:i]) | ||
279 | } | ||
280 | stream.WriteRaw(`\ufffd`) | ||
281 | i++ | ||
282 | start = i | ||
283 | continue | ||
284 | } | ||
285 | // U+2028 is LINE SEPARATOR. | ||
286 | // U+2029 is PARAGRAPH SEPARATOR. | ||
287 | // They are both technically valid characters in JSON strings, | ||
288 | // but don't work in JSONP, which has to be evaluated as JavaScript, | ||
289 | // and can lead to security holes there. It is valid JSON to | ||
290 | // escape them, so we do so unconditionally. | ||
291 | // See http://timelessrepo.com/json-isnt-a-javascript-subset for discussion. | ||
292 | if c == '\u2028' || c == '\u2029' { | ||
293 | if start < i { | ||
294 | stream.WriteRaw(s[start:i]) | ||
295 | } | ||
296 | stream.WriteRaw(`\u202`) | ||
297 | stream.writeByte(hex[c&0xF]) | ||
298 | i += size | ||
299 | start = i | ||
300 | continue | ||
301 | } | ||
302 | i += size | ||
303 | } | ||
304 | if start < len(s) { | ||
305 | stream.WriteRaw(s[start:]) | ||
306 | } | ||
307 | stream.writeByte('"') | ||
308 | } | ||
309 | |||
310 | // WriteString write string to stream without html escape | ||
311 | func (stream *Stream) WriteString(s string) { | ||
312 | valLen := len(s) | ||
313 | stream.buf = append(stream.buf, '"') | ||
314 | // write string, the fast path, without utf8 and escape support | ||
315 | i := 0 | ||
316 | for ; i < valLen; i++ { | ||
317 | c := s[i] | ||
318 | if c > 31 && c != '"' && c != '\\' { | ||
319 | stream.buf = append(stream.buf, c) | ||
320 | } else { | ||
321 | break | ||
322 | } | ||
323 | } | ||
324 | if i == valLen { | ||
325 | stream.buf = append(stream.buf, '"') | ||
326 | return | ||
327 | } | ||
328 | writeStringSlowPath(stream, i, s, valLen) | ||
329 | } | ||
330 | |||
331 | func writeStringSlowPath(stream *Stream, i int, s string, valLen int) { | ||
332 | start := i | ||
333 | // for the remaining parts, we process them char by char | ||
334 | for i < valLen { | ||
335 | if b := s[i]; b < utf8.RuneSelf { | ||
336 | if safeSet[b] { | ||
337 | i++ | ||
338 | continue | ||
339 | } | ||
340 | if start < i { | ||
341 | stream.WriteRaw(s[start:i]) | ||
342 | } | ||
343 | switch b { | ||
344 | case '\\', '"': | ||
345 | stream.writeTwoBytes('\\', b) | ||
346 | case '\n': | ||
347 | stream.writeTwoBytes('\\', 'n') | ||
348 | case '\r': | ||
349 | stream.writeTwoBytes('\\', 'r') | ||
350 | case '\t': | ||
351 | stream.writeTwoBytes('\\', 't') | ||
352 | default: | ||
353 | // This encodes bytes < 0x20 except for \t, \n and \r. | ||
354 | // If escapeHTML is set, it also escapes <, >, and & | ||
355 | // because they can lead to security holes when | ||
356 | // user-controlled strings are rendered into JSON | ||
357 | // and served to some browsers. | ||
358 | stream.WriteRaw(`\u00`) | ||
359 | stream.writeTwoBytes(hex[b>>4], hex[b&0xF]) | ||
360 | } | ||
361 | i++ | ||
362 | start = i | ||
363 | continue | ||
364 | } | ||
365 | i++ | ||
366 | continue | ||
367 | } | ||
368 | if start < len(s) { | ||
369 | stream.WriteRaw(s[start:]) | ||
370 | } | ||
371 | stream.writeByte('"') | ||
372 | } | ||
diff --git a/vendor/github.com/json-iterator/go/test.sh b/vendor/github.com/json-iterator/go/test.sh deleted file mode 100644 index f4e7c0b..0000000 --- a/vendor/github.com/json-iterator/go/test.sh +++ /dev/null | |||
@@ -1,12 +0,0 @@ | |||
1 | #!/usr/bin/env bash | ||
2 | |||
3 | set -e | ||
4 | echo "" > coverage.txt | ||
5 | |||
6 | for d in $(go list ./... | grep -v vendor); do | ||
7 | go test -coverprofile=profile.out -coverpkg=github.com/json-iterator/go $d | ||
8 | if [ -f profile.out ]; then | ||
9 | cat profile.out >> coverage.txt | ||
10 | rm profile.out | ||
11 | fi | ||
12 | done | ||