2018-11-11 Richard Biener <rguenther@suse.de>
[official-gcc.git] / libgo / go / encoding / gob / enc_helpers.go
blobc3b4ca8972a68630c1c53d053b10f25e6dcbb3a4
1 // Code generated by go run encgen.go -output enc_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.
7 package gob
9 import (
10 "reflect"
13 var encArrayHelper = map[reflect.Kind]encHelper{
14 reflect.Bool: encBoolArray,
15 reflect.Complex64: encComplex64Array,
16 reflect.Complex128: encComplex128Array,
17 reflect.Float32: encFloat32Array,
18 reflect.Float64: encFloat64Array,
19 reflect.Int: encIntArray,
20 reflect.Int16: encInt16Array,
21 reflect.Int32: encInt32Array,
22 reflect.Int64: encInt64Array,
23 reflect.Int8: encInt8Array,
24 reflect.String: encStringArray,
25 reflect.Uint: encUintArray,
26 reflect.Uint16: encUint16Array,
27 reflect.Uint32: encUint32Array,
28 reflect.Uint64: encUint64Array,
29 reflect.Uintptr: encUintptrArray,
32 var encSliceHelper = map[reflect.Kind]encHelper{
33 reflect.Bool: encBoolSlice,
34 reflect.Complex64: encComplex64Slice,
35 reflect.Complex128: encComplex128Slice,
36 reflect.Float32: encFloat32Slice,
37 reflect.Float64: encFloat64Slice,
38 reflect.Int: encIntSlice,
39 reflect.Int16: encInt16Slice,
40 reflect.Int32: encInt32Slice,
41 reflect.Int64: encInt64Slice,
42 reflect.Int8: encInt8Slice,
43 reflect.String: encStringSlice,
44 reflect.Uint: encUintSlice,
45 reflect.Uint16: encUint16Slice,
46 reflect.Uint32: encUint32Slice,
47 reflect.Uint64: encUint64Slice,
48 reflect.Uintptr: encUintptrSlice,
51 func encBoolArray(state *encoderState, v reflect.Value) bool {
52 // Can only slice if it is addressable.
53 if !v.CanAddr() {
54 return false
56 return encBoolSlice(state, v.Slice(0, v.Len()))
59 func encBoolSlice(state *encoderState, v reflect.Value) bool {
60 slice, ok := v.Interface().([]bool)
61 if !ok {
62 // It is kind bool but not type bool. TODO: We can handle this unsafely.
63 return false
65 for _, x := range slice {
66 if x != false || state.sendZero {
67 if x {
68 state.encodeUint(1)
69 } else {
70 state.encodeUint(0)
74 return true
77 func encComplex64Array(state *encoderState, v reflect.Value) bool {
78 // Can only slice if it is addressable.
79 if !v.CanAddr() {
80 return false
82 return encComplex64Slice(state, v.Slice(0, v.Len()))
85 func encComplex64Slice(state *encoderState, v reflect.Value) bool {
86 slice, ok := v.Interface().([]complex64)
87 if !ok {
88 // It is kind complex64 but not type complex64. TODO: We can handle this unsafely.
89 return false
91 for _, x := range slice {
92 if x != 0+0i || state.sendZero {
93 rpart := floatBits(float64(real(x)))
94 ipart := floatBits(float64(imag(x)))
95 state.encodeUint(rpart)
96 state.encodeUint(ipart)
99 return true
102 func encComplex128Array(state *encoderState, v reflect.Value) bool {
103 // Can only slice if it is addressable.
104 if !v.CanAddr() {
105 return false
107 return encComplex128Slice(state, v.Slice(0, v.Len()))
110 func encComplex128Slice(state *encoderState, v reflect.Value) bool {
111 slice, ok := v.Interface().([]complex128)
112 if !ok {
113 // It is kind complex128 but not type complex128. TODO: We can handle this unsafely.
114 return false
116 for _, x := range slice {
117 if x != 0+0i || state.sendZero {
118 rpart := floatBits(real(x))
119 ipart := floatBits(imag(x))
120 state.encodeUint(rpart)
121 state.encodeUint(ipart)
124 return true
127 func encFloat32Array(state *encoderState, v reflect.Value) bool {
128 // Can only slice if it is addressable.
129 if !v.CanAddr() {
130 return false
132 return encFloat32Slice(state, v.Slice(0, v.Len()))
135 func encFloat32Slice(state *encoderState, v reflect.Value) bool {
136 slice, ok := v.Interface().([]float32)
137 if !ok {
138 // It is kind float32 but not type float32. TODO: We can handle this unsafely.
139 return false
141 for _, x := range slice {
142 if x != 0 || state.sendZero {
143 bits := floatBits(float64(x))
144 state.encodeUint(bits)
147 return true
150 func encFloat64Array(state *encoderState, v reflect.Value) bool {
151 // Can only slice if it is addressable.
152 if !v.CanAddr() {
153 return false
155 return encFloat64Slice(state, v.Slice(0, v.Len()))
158 func encFloat64Slice(state *encoderState, v reflect.Value) bool {
159 slice, ok := v.Interface().([]float64)
160 if !ok {
161 // It is kind float64 but not type float64. TODO: We can handle this unsafely.
162 return false
164 for _, x := range slice {
165 if x != 0 || state.sendZero {
166 bits := floatBits(x)
167 state.encodeUint(bits)
170 return true
173 func encIntArray(state *encoderState, v reflect.Value) bool {
174 // Can only slice if it is addressable.
175 if !v.CanAddr() {
176 return false
178 return encIntSlice(state, v.Slice(0, v.Len()))
181 func encIntSlice(state *encoderState, v reflect.Value) bool {
182 slice, ok := v.Interface().([]int)
183 if !ok {
184 // It is kind int but not type int. TODO: We can handle this unsafely.
185 return false
187 for _, x := range slice {
188 if x != 0 || state.sendZero {
189 state.encodeInt(int64(x))
192 return true
195 func encInt16Array(state *encoderState, v reflect.Value) bool {
196 // Can only slice if it is addressable.
197 if !v.CanAddr() {
198 return false
200 return encInt16Slice(state, v.Slice(0, v.Len()))
203 func encInt16Slice(state *encoderState, v reflect.Value) bool {
204 slice, ok := v.Interface().([]int16)
205 if !ok {
206 // It is kind int16 but not type int16. TODO: We can handle this unsafely.
207 return false
209 for _, x := range slice {
210 if x != 0 || state.sendZero {
211 state.encodeInt(int64(x))
214 return true
217 func encInt32Array(state *encoderState, v reflect.Value) bool {
218 // Can only slice if it is addressable.
219 if !v.CanAddr() {
220 return false
222 return encInt32Slice(state, v.Slice(0, v.Len()))
225 func encInt32Slice(state *encoderState, v reflect.Value) bool {
226 slice, ok := v.Interface().([]int32)
227 if !ok {
228 // It is kind int32 but not type int32. TODO: We can handle this unsafely.
229 return false
231 for _, x := range slice {
232 if x != 0 || state.sendZero {
233 state.encodeInt(int64(x))
236 return true
239 func encInt64Array(state *encoderState, v reflect.Value) bool {
240 // Can only slice if it is addressable.
241 if !v.CanAddr() {
242 return false
244 return encInt64Slice(state, v.Slice(0, v.Len()))
247 func encInt64Slice(state *encoderState, v reflect.Value) bool {
248 slice, ok := v.Interface().([]int64)
249 if !ok {
250 // It is kind int64 but not type int64. TODO: We can handle this unsafely.
251 return false
253 for _, x := range slice {
254 if x != 0 || state.sendZero {
255 state.encodeInt(x)
258 return true
261 func encInt8Array(state *encoderState, v reflect.Value) bool {
262 // Can only slice if it is addressable.
263 if !v.CanAddr() {
264 return false
266 return encInt8Slice(state, v.Slice(0, v.Len()))
269 func encInt8Slice(state *encoderState, v reflect.Value) bool {
270 slice, ok := v.Interface().([]int8)
271 if !ok {
272 // It is kind int8 but not type int8. TODO: We can handle this unsafely.
273 return false
275 for _, x := range slice {
276 if x != 0 || state.sendZero {
277 state.encodeInt(int64(x))
280 return true
283 func encStringArray(state *encoderState, v reflect.Value) bool {
284 // Can only slice if it is addressable.
285 if !v.CanAddr() {
286 return false
288 return encStringSlice(state, v.Slice(0, v.Len()))
291 func encStringSlice(state *encoderState, v reflect.Value) bool {
292 slice, ok := v.Interface().([]string)
293 if !ok {
294 // It is kind string but not type string. TODO: We can handle this unsafely.
295 return false
297 for _, x := range slice {
298 if x != "" || state.sendZero {
299 state.encodeUint(uint64(len(x)))
300 state.b.WriteString(x)
303 return true
306 func encUintArray(state *encoderState, v reflect.Value) bool {
307 // Can only slice if it is addressable.
308 if !v.CanAddr() {
309 return false
311 return encUintSlice(state, v.Slice(0, v.Len()))
314 func encUintSlice(state *encoderState, v reflect.Value) bool {
315 slice, ok := v.Interface().([]uint)
316 if !ok {
317 // It is kind uint but not type uint. TODO: We can handle this unsafely.
318 return false
320 for _, x := range slice {
321 if x != 0 || state.sendZero {
322 state.encodeUint(uint64(x))
325 return true
328 func encUint16Array(state *encoderState, v reflect.Value) bool {
329 // Can only slice if it is addressable.
330 if !v.CanAddr() {
331 return false
333 return encUint16Slice(state, v.Slice(0, v.Len()))
336 func encUint16Slice(state *encoderState, v reflect.Value) bool {
337 slice, ok := v.Interface().([]uint16)
338 if !ok {
339 // It is kind uint16 but not type uint16. TODO: We can handle this unsafely.
340 return false
342 for _, x := range slice {
343 if x != 0 || state.sendZero {
344 state.encodeUint(uint64(x))
347 return true
350 func encUint32Array(state *encoderState, v reflect.Value) bool {
351 // Can only slice if it is addressable.
352 if !v.CanAddr() {
353 return false
355 return encUint32Slice(state, v.Slice(0, v.Len()))
358 func encUint32Slice(state *encoderState, v reflect.Value) bool {
359 slice, ok := v.Interface().([]uint32)
360 if !ok {
361 // It is kind uint32 but not type uint32. TODO: We can handle this unsafely.
362 return false
364 for _, x := range slice {
365 if x != 0 || state.sendZero {
366 state.encodeUint(uint64(x))
369 return true
372 func encUint64Array(state *encoderState, v reflect.Value) bool {
373 // Can only slice if it is addressable.
374 if !v.CanAddr() {
375 return false
377 return encUint64Slice(state, v.Slice(0, v.Len()))
380 func encUint64Slice(state *encoderState, v reflect.Value) bool {
381 slice, ok := v.Interface().([]uint64)
382 if !ok {
383 // It is kind uint64 but not type uint64. TODO: We can handle this unsafely.
384 return false
386 for _, x := range slice {
387 if x != 0 || state.sendZero {
388 state.encodeUint(x)
391 return true
394 func encUintptrArray(state *encoderState, v reflect.Value) bool {
395 // Can only slice if it is addressable.
396 if !v.CanAddr() {
397 return false
399 return encUintptrSlice(state, v.Slice(0, v.Len()))
402 func encUintptrSlice(state *encoderState, v reflect.Value) bool {
403 slice, ok := v.Interface().([]uintptr)
404 if !ok {
405 // It is kind uintptr but not type uintptr. TODO: We can handle this unsafely.
406 return false
408 for _, x := range slice {
409 if x != 0 || state.sendZero {
410 state.encodeUint(uint64(x))
413 return true