1 // Code generated by go run decgen.go -output dec_helpers.go; DO NOT EDIT.
3 // Copyright 2014 The Go Authors. All rights reserved.
4 // Use of this source code is governed by a BSD-style
5 // license that can be found in the LICENSE file.
14 var decArrayHelper
= map[reflect
.Kind
]decHelper
{
15 reflect
.Bool
: decBoolArray
,
16 reflect
.Complex64
: decComplex64Array
,
17 reflect
.Complex128
: decComplex128Array
,
18 reflect
.Float32
: decFloat32Array
,
19 reflect
.Float64
: decFloat64Array
,
20 reflect
.Int
: decIntArray
,
21 reflect
.Int16
: decInt16Array
,
22 reflect
.Int32
: decInt32Array
,
23 reflect
.Int64
: decInt64Array
,
24 reflect
.Int8
: decInt8Array
,
25 reflect
.String
: decStringArray
,
26 reflect
.Uint
: decUintArray
,
27 reflect
.Uint16
: decUint16Array
,
28 reflect
.Uint32
: decUint32Array
,
29 reflect
.Uint64
: decUint64Array
,
30 reflect
.Uintptr
: decUintptrArray
,
33 var decSliceHelper
= map[reflect
.Kind
]decHelper
{
34 reflect
.Bool
: decBoolSlice
,
35 reflect
.Complex64
: decComplex64Slice
,
36 reflect
.Complex128
: decComplex128Slice
,
37 reflect
.Float32
: decFloat32Slice
,
38 reflect
.Float64
: decFloat64Slice
,
39 reflect
.Int
: decIntSlice
,
40 reflect
.Int16
: decInt16Slice
,
41 reflect
.Int32
: decInt32Slice
,
42 reflect
.Int64
: decInt64Slice
,
43 reflect
.Int8
: decInt8Slice
,
44 reflect
.String
: decStringSlice
,
45 reflect
.Uint
: decUintSlice
,
46 reflect
.Uint16
: decUint16Slice
,
47 reflect
.Uint32
: decUint32Slice
,
48 reflect
.Uint64
: decUint64Slice
,
49 reflect
.Uintptr
: decUintptrSlice
,
52 func decBoolArray(state
*decoderState
, v reflect
.Value
, length
int, ovfl error
) bool {
53 // Can only slice if it is addressable.
57 return decBoolSlice(state
, v
.Slice(0, v
.Len()), length
, ovfl
)
60 func decBoolSlice(state
*decoderState
, v reflect
.Value
, length
int, ovfl error
) bool {
61 slice
, ok
:= v
.Interface().([]bool)
63 // It is kind bool but not type bool. TODO: We can handle this unsafely.
66 for i
:= 0; i
< length
; i
++ {
67 if state
.b
.Len() == 0 {
68 errorf("decoding bool array or slice: length exceeds input size (%d elements)", length
)
70 slice
[i
] = state
.decodeUint() != 0
75 func decComplex64Array(state
*decoderState
, v reflect
.Value
, length
int, ovfl error
) bool {
76 // Can only slice if it is addressable.
80 return decComplex64Slice(state
, v
.Slice(0, v
.Len()), length
, ovfl
)
83 func decComplex64Slice(state
*decoderState
, v reflect
.Value
, length
int, ovfl error
) bool {
84 slice
, ok
:= v
.Interface().([]complex64
)
86 // It is kind complex64 but not type complex64. TODO: We can handle this unsafely.
89 for i
:= 0; i
< length
; i
++ {
90 if state
.b
.Len() == 0 {
91 errorf("decoding complex64 array or slice: length exceeds input size (%d elements)", length
)
93 real
:= float32FromBits(state
.decodeUint(), ovfl
)
94 imag
:= float32FromBits(state
.decodeUint(), ovfl
)
95 slice
[i
] = complex(float32(real
), float32(imag
))
100 func decComplex128Array(state
*decoderState
, v reflect
.Value
, length
int, ovfl error
) bool {
101 // Can only slice if it is addressable.
105 return decComplex128Slice(state
, v
.Slice(0, v
.Len()), length
, ovfl
)
108 func decComplex128Slice(state
*decoderState
, v reflect
.Value
, length
int, ovfl error
) bool {
109 slice
, ok
:= v
.Interface().([]complex128
)
111 // It is kind complex128 but not type complex128. TODO: We can handle this unsafely.
114 for i
:= 0; i
< length
; i
++ {
115 if state
.b
.Len() == 0 {
116 errorf("decoding complex128 array or slice: length exceeds input size (%d elements)", length
)
118 real
:= float64FromBits(state
.decodeUint())
119 imag
:= float64FromBits(state
.decodeUint())
120 slice
[i
] = complex(real
, imag
)
125 func decFloat32Array(state
*decoderState
, v reflect
.Value
, length
int, ovfl error
) bool {
126 // Can only slice if it is addressable.
130 return decFloat32Slice(state
, v
.Slice(0, v
.Len()), length
, ovfl
)
133 func decFloat32Slice(state
*decoderState
, v reflect
.Value
, length
int, ovfl error
) bool {
134 slice
, ok
:= v
.Interface().([]float32)
136 // It is kind float32 but not type float32. TODO: We can handle this unsafely.
139 for i
:= 0; i
< length
; i
++ {
140 if state
.b
.Len() == 0 {
141 errorf("decoding float32 array or slice: length exceeds input size (%d elements)", length
)
143 slice
[i
] = float32(float32FromBits(state
.decodeUint(), ovfl
))
148 func decFloat64Array(state
*decoderState
, v reflect
.Value
, length
int, ovfl error
) bool {
149 // Can only slice if it is addressable.
153 return decFloat64Slice(state
, v
.Slice(0, v
.Len()), length
, ovfl
)
156 func decFloat64Slice(state
*decoderState
, v reflect
.Value
, length
int, ovfl error
) bool {
157 slice
, ok
:= v
.Interface().([]float64)
159 // It is kind float64 but not type float64. TODO: We can handle this unsafely.
162 for i
:= 0; i
< length
; i
++ {
163 if state
.b
.Len() == 0 {
164 errorf("decoding float64 array or slice: length exceeds input size (%d elements)", length
)
166 slice
[i
] = float64FromBits(state
.decodeUint())
171 func decIntArray(state
*decoderState
, v reflect
.Value
, length
int, ovfl error
) bool {
172 // Can only slice if it is addressable.
176 return decIntSlice(state
, v
.Slice(0, v
.Len()), length
, ovfl
)
179 func decIntSlice(state
*decoderState
, v reflect
.Value
, length
int, ovfl error
) bool {
180 slice
, ok
:= v
.Interface().([]int)
182 // It is kind int but not type int. TODO: We can handle this unsafely.
185 for i
:= 0; i
< length
; i
++ {
186 if state
.b
.Len() == 0 {
187 errorf("decoding int array or slice: length exceeds input size (%d elements)", length
)
189 x
:= state
.decodeInt()
191 if x
< ^int64(^uint(0)>>1) ||
int64(^uint(0)>>1) < x
{
199 func decInt16Array(state
*decoderState
, v reflect
.Value
, length
int, ovfl error
) bool {
200 // Can only slice if it is addressable.
204 return decInt16Slice(state
, v
.Slice(0, v
.Len()), length
, ovfl
)
207 func decInt16Slice(state
*decoderState
, v reflect
.Value
, length
int, ovfl error
) bool {
208 slice
, ok
:= v
.Interface().([]int16)
210 // It is kind int16 but not type int16. TODO: We can handle this unsafely.
213 for i
:= 0; i
< length
; i
++ {
214 if state
.b
.Len() == 0 {
215 errorf("decoding int16 array or slice: length exceeds input size (%d elements)", length
)
217 x
:= state
.decodeInt()
218 if x
< math
.MinInt16 || math
.MaxInt16
< x
{
226 func decInt32Array(state
*decoderState
, v reflect
.Value
, length
int, ovfl error
) bool {
227 // Can only slice if it is addressable.
231 return decInt32Slice(state
, v
.Slice(0, v
.Len()), length
, ovfl
)
234 func decInt32Slice(state
*decoderState
, v reflect
.Value
, length
int, ovfl error
) bool {
235 slice
, ok
:= v
.Interface().([]int32)
237 // It is kind int32 but not type int32. TODO: We can handle this unsafely.
240 for i
:= 0; i
< length
; i
++ {
241 if state
.b
.Len() == 0 {
242 errorf("decoding int32 array or slice: length exceeds input size (%d elements)", length
)
244 x
:= state
.decodeInt()
245 if x
< math
.MinInt32 || math
.MaxInt32
< x
{
253 func decInt64Array(state
*decoderState
, v reflect
.Value
, length
int, ovfl error
) bool {
254 // Can only slice if it is addressable.
258 return decInt64Slice(state
, v
.Slice(0, v
.Len()), length
, ovfl
)
261 func decInt64Slice(state
*decoderState
, v reflect
.Value
, length
int, ovfl error
) bool {
262 slice
, ok
:= v
.Interface().([]int64)
264 // It is kind int64 but not type int64. TODO: We can handle this unsafely.
267 for i
:= 0; i
< length
; i
++ {
268 if state
.b
.Len() == 0 {
269 errorf("decoding int64 array or slice: length exceeds input size (%d elements)", length
)
271 slice
[i
] = state
.decodeInt()
276 func decInt8Array(state
*decoderState
, v reflect
.Value
, length
int, ovfl error
) bool {
277 // Can only slice if it is addressable.
281 return decInt8Slice(state
, v
.Slice(0, v
.Len()), length
, ovfl
)
284 func decInt8Slice(state
*decoderState
, v reflect
.Value
, length
int, ovfl error
) bool {
285 slice
, ok
:= v
.Interface().([]int8)
287 // It is kind int8 but not type int8. TODO: We can handle this unsafely.
290 for i
:= 0; i
< length
; i
++ {
291 if state
.b
.Len() == 0 {
292 errorf("decoding int8 array or slice: length exceeds input size (%d elements)", length
)
294 x
:= state
.decodeInt()
295 if x
< math
.MinInt8 || math
.MaxInt8
< x
{
303 func decStringArray(state
*decoderState
, v reflect
.Value
, length
int, ovfl error
) bool {
304 // Can only slice if it is addressable.
308 return decStringSlice(state
, v
.Slice(0, v
.Len()), length
, ovfl
)
311 func decStringSlice(state
*decoderState
, v reflect
.Value
, length
int, ovfl error
) bool {
312 slice
, ok
:= v
.Interface().([]string)
314 // It is kind string but not type string. TODO: We can handle this unsafely.
317 for i
:= 0; i
< length
; i
++ {
318 if state
.b
.Len() == 0 {
319 errorf("decoding string array or slice: length exceeds input size (%d elements)", length
)
321 u
:= state
.decodeUint()
323 if n
< 0 ||
uint64(n
) != u || n
> state
.b
.Len() {
324 errorf("length of string exceeds input size (%d bytes)", u
)
326 if n
> state
.b
.Len() {
327 errorf("string data too long for buffer: %d", n
)
330 data
:= state
.b
.Bytes()
332 errorf("invalid string length %d: exceeds input size %d", n
, len(data
))
334 slice
[i
] = string(data
[:n
])
340 func decUintArray(state
*decoderState
, v reflect
.Value
, length
int, ovfl error
) bool {
341 // Can only slice if it is addressable.
345 return decUintSlice(state
, v
.Slice(0, v
.Len()), length
, ovfl
)
348 func decUintSlice(state
*decoderState
, v reflect
.Value
, length
int, ovfl error
) bool {
349 slice
, ok
:= v
.Interface().([]uint)
351 // It is kind uint but not type uint. TODO: We can handle this unsafely.
354 for i
:= 0; i
< length
; i
++ {
355 if state
.b
.Len() == 0 {
356 errorf("decoding uint array or slice: length exceeds input size (%d elements)", length
)
358 x
:= state
.decodeUint()
359 /*TODO if math.MaxUint32 < x {
367 func decUint16Array(state
*decoderState
, v reflect
.Value
, length
int, ovfl error
) bool {
368 // Can only slice if it is addressable.
372 return decUint16Slice(state
, v
.Slice(0, v
.Len()), length
, ovfl
)
375 func decUint16Slice(state
*decoderState
, v reflect
.Value
, length
int, ovfl error
) bool {
376 slice
, ok
:= v
.Interface().([]uint16)
378 // It is kind uint16 but not type uint16. TODO: We can handle this unsafely.
381 for i
:= 0; i
< length
; i
++ {
382 if state
.b
.Len() == 0 {
383 errorf("decoding uint16 array or slice: length exceeds input size (%d elements)", length
)
385 x
:= state
.decodeUint()
386 if math
.MaxUint16
< x
{
394 func decUint32Array(state
*decoderState
, v reflect
.Value
, length
int, ovfl error
) bool {
395 // Can only slice if it is addressable.
399 return decUint32Slice(state
, v
.Slice(0, v
.Len()), length
, ovfl
)
402 func decUint32Slice(state
*decoderState
, v reflect
.Value
, length
int, ovfl error
) bool {
403 slice
, ok
:= v
.Interface().([]uint32)
405 // It is kind uint32 but not type uint32. TODO: We can handle this unsafely.
408 for i
:= 0; i
< length
; i
++ {
409 if state
.b
.Len() == 0 {
410 errorf("decoding uint32 array or slice: length exceeds input size (%d elements)", length
)
412 x
:= state
.decodeUint()
413 if math
.MaxUint32
< x
{
421 func decUint64Array(state
*decoderState
, v reflect
.Value
, length
int, ovfl error
) bool {
422 // Can only slice if it is addressable.
426 return decUint64Slice(state
, v
.Slice(0, v
.Len()), length
, ovfl
)
429 func decUint64Slice(state
*decoderState
, v reflect
.Value
, length
int, ovfl error
) bool {
430 slice
, ok
:= v
.Interface().([]uint64)
432 // It is kind uint64 but not type uint64. TODO: We can handle this unsafely.
435 for i
:= 0; i
< length
; i
++ {
436 if state
.b
.Len() == 0 {
437 errorf("decoding uint64 array or slice: length exceeds input size (%d elements)", length
)
439 slice
[i
] = state
.decodeUint()
444 func decUintptrArray(state
*decoderState
, v reflect
.Value
, length
int, ovfl error
) bool {
445 // Can only slice if it is addressable.
449 return decUintptrSlice(state
, v
.Slice(0, v
.Len()), length
, ovfl
)
452 func decUintptrSlice(state
*decoderState
, v reflect
.Value
, length
int, ovfl error
) bool {
453 slice
, ok
:= v
.Interface().([]uintptr)
455 // It is kind uintptr but not type uintptr. TODO: We can handle this unsafely.
458 for i
:= 0; i
< length
; i
++ {
459 if state
.b
.Len() == 0 {
460 errorf("decoding uintptr array or slice: length exceeds input size (%d elements)", length
)
462 x
:= state
.decodeUint()
463 if uint64(^uintptr(0)) < x
{
466 slice
[i
] = uintptr(x
)