...

Source file src/encoding/gob/enc_helpers.go

Documentation: encoding/gob

		 1  // Code generated by go run encgen.go -output enc_helpers.go; DO NOT EDIT.
		 2  
		 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.
		 6  
		 7  package gob
		 8  
		 9  import (
		10  	"reflect"
		11  )
		12  
		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,
		30  }
		31  
		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,
		49  }
		50  
		51  func encBoolArray(state *encoderState, v reflect.Value) bool {
		52  	// Can only slice if it is addressable.
		53  	if !v.CanAddr() {
		54  		return false
		55  	}
		56  	return encBoolSlice(state, v.Slice(0, v.Len()))
		57  }
		58  
		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
		64  	}
		65  	for _, x := range slice {
		66  		if x != false || state.sendZero {
		67  			if x {
		68  				state.encodeUint(1)
		69  			} else {
		70  				state.encodeUint(0)
		71  			}
		72  		}
		73  	}
		74  	return true
		75  }
		76  
		77  func encComplex64Array(state *encoderState, v reflect.Value) bool {
		78  	// Can only slice if it is addressable.
		79  	if !v.CanAddr() {
		80  		return false
		81  	}
		82  	return encComplex64Slice(state, v.Slice(0, v.Len()))
		83  }
		84  
		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
		90  	}
		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)
		97  		}
		98  	}
		99  	return true
	 100  }
	 101  
	 102  func encComplex128Array(state *encoderState, v reflect.Value) bool {
	 103  	// Can only slice if it is addressable.
	 104  	if !v.CanAddr() {
	 105  		return false
	 106  	}
	 107  	return encComplex128Slice(state, v.Slice(0, v.Len()))
	 108  }
	 109  
	 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
	 115  	}
	 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)
	 122  		}
	 123  	}
	 124  	return true
	 125  }
	 126  
	 127  func encFloat32Array(state *encoderState, v reflect.Value) bool {
	 128  	// Can only slice if it is addressable.
	 129  	if !v.CanAddr() {
	 130  		return false
	 131  	}
	 132  	return encFloat32Slice(state, v.Slice(0, v.Len()))
	 133  }
	 134  
	 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
	 140  	}
	 141  	for _, x := range slice {
	 142  		if x != 0 || state.sendZero {
	 143  			bits := floatBits(float64(x))
	 144  			state.encodeUint(bits)
	 145  		}
	 146  	}
	 147  	return true
	 148  }
	 149  
	 150  func encFloat64Array(state *encoderState, v reflect.Value) bool {
	 151  	// Can only slice if it is addressable.
	 152  	if !v.CanAddr() {
	 153  		return false
	 154  	}
	 155  	return encFloat64Slice(state, v.Slice(0, v.Len()))
	 156  }
	 157  
	 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
	 163  	}
	 164  	for _, x := range slice {
	 165  		if x != 0 || state.sendZero {
	 166  			bits := floatBits(x)
	 167  			state.encodeUint(bits)
	 168  		}
	 169  	}
	 170  	return true
	 171  }
	 172  
	 173  func encIntArray(state *encoderState, v reflect.Value) bool {
	 174  	// Can only slice if it is addressable.
	 175  	if !v.CanAddr() {
	 176  		return false
	 177  	}
	 178  	return encIntSlice(state, v.Slice(0, v.Len()))
	 179  }
	 180  
	 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
	 186  	}
	 187  	for _, x := range slice {
	 188  		if x != 0 || state.sendZero {
	 189  			state.encodeInt(int64(x))
	 190  		}
	 191  	}
	 192  	return true
	 193  }
	 194  
	 195  func encInt16Array(state *encoderState, v reflect.Value) bool {
	 196  	// Can only slice if it is addressable.
	 197  	if !v.CanAddr() {
	 198  		return false
	 199  	}
	 200  	return encInt16Slice(state, v.Slice(0, v.Len()))
	 201  }
	 202  
	 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
	 208  	}
	 209  	for _, x := range slice {
	 210  		if x != 0 || state.sendZero {
	 211  			state.encodeInt(int64(x))
	 212  		}
	 213  	}
	 214  	return true
	 215  }
	 216  
	 217  func encInt32Array(state *encoderState, v reflect.Value) bool {
	 218  	// Can only slice if it is addressable.
	 219  	if !v.CanAddr() {
	 220  		return false
	 221  	}
	 222  	return encInt32Slice(state, v.Slice(0, v.Len()))
	 223  }
	 224  
	 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
	 230  	}
	 231  	for _, x := range slice {
	 232  		if x != 0 || state.sendZero {
	 233  			state.encodeInt(int64(x))
	 234  		}
	 235  	}
	 236  	return true
	 237  }
	 238  
	 239  func encInt64Array(state *encoderState, v reflect.Value) bool {
	 240  	// Can only slice if it is addressable.
	 241  	if !v.CanAddr() {
	 242  		return false
	 243  	}
	 244  	return encInt64Slice(state, v.Slice(0, v.Len()))
	 245  }
	 246  
	 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
	 252  	}
	 253  	for _, x := range slice {
	 254  		if x != 0 || state.sendZero {
	 255  			state.encodeInt(x)
	 256  		}
	 257  	}
	 258  	return true
	 259  }
	 260  
	 261  func encInt8Array(state *encoderState, v reflect.Value) bool {
	 262  	// Can only slice if it is addressable.
	 263  	if !v.CanAddr() {
	 264  		return false
	 265  	}
	 266  	return encInt8Slice(state, v.Slice(0, v.Len()))
	 267  }
	 268  
	 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
	 274  	}
	 275  	for _, x := range slice {
	 276  		if x != 0 || state.sendZero {
	 277  			state.encodeInt(int64(x))
	 278  		}
	 279  	}
	 280  	return true
	 281  }
	 282  
	 283  func encStringArray(state *encoderState, v reflect.Value) bool {
	 284  	// Can only slice if it is addressable.
	 285  	if !v.CanAddr() {
	 286  		return false
	 287  	}
	 288  	return encStringSlice(state, v.Slice(0, v.Len()))
	 289  }
	 290  
	 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
	 296  	}
	 297  	for _, x := range slice {
	 298  		if x != "" || state.sendZero {
	 299  			state.encodeUint(uint64(len(x)))
	 300  			state.b.WriteString(x)
	 301  		}
	 302  	}
	 303  	return true
	 304  }
	 305  
	 306  func encUintArray(state *encoderState, v reflect.Value) bool {
	 307  	// Can only slice if it is addressable.
	 308  	if !v.CanAddr() {
	 309  		return false
	 310  	}
	 311  	return encUintSlice(state, v.Slice(0, v.Len()))
	 312  }
	 313  
	 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
	 319  	}
	 320  	for _, x := range slice {
	 321  		if x != 0 || state.sendZero {
	 322  			state.encodeUint(uint64(x))
	 323  		}
	 324  	}
	 325  	return true
	 326  }
	 327  
	 328  func encUint16Array(state *encoderState, v reflect.Value) bool {
	 329  	// Can only slice if it is addressable.
	 330  	if !v.CanAddr() {
	 331  		return false
	 332  	}
	 333  	return encUint16Slice(state, v.Slice(0, v.Len()))
	 334  }
	 335  
	 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
	 341  	}
	 342  	for _, x := range slice {
	 343  		if x != 0 || state.sendZero {
	 344  			state.encodeUint(uint64(x))
	 345  		}
	 346  	}
	 347  	return true
	 348  }
	 349  
	 350  func encUint32Array(state *encoderState, v reflect.Value) bool {
	 351  	// Can only slice if it is addressable.
	 352  	if !v.CanAddr() {
	 353  		return false
	 354  	}
	 355  	return encUint32Slice(state, v.Slice(0, v.Len()))
	 356  }
	 357  
	 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
	 363  	}
	 364  	for _, x := range slice {
	 365  		if x != 0 || state.sendZero {
	 366  			state.encodeUint(uint64(x))
	 367  		}
	 368  	}
	 369  	return true
	 370  }
	 371  
	 372  func encUint64Array(state *encoderState, v reflect.Value) bool {
	 373  	// Can only slice if it is addressable.
	 374  	if !v.CanAddr() {
	 375  		return false
	 376  	}
	 377  	return encUint64Slice(state, v.Slice(0, v.Len()))
	 378  }
	 379  
	 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
	 385  	}
	 386  	for _, x := range slice {
	 387  		if x != 0 || state.sendZero {
	 388  			state.encodeUint(x)
	 389  		}
	 390  	}
	 391  	return true
	 392  }
	 393  
	 394  func encUintptrArray(state *encoderState, v reflect.Value) bool {
	 395  	// Can only slice if it is addressable.
	 396  	if !v.CanAddr() {
	 397  		return false
	 398  	}
	 399  	return encUintptrSlice(state, v.Slice(0, v.Len()))
	 400  }
	 401  
	 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
	 407  	}
	 408  	for _, x := range slice {
	 409  		if x != 0 || state.sendZero {
	 410  			state.encodeUint(uint64(x))
	 411  		}
	 412  	}
	 413  	return true
	 414  }
	 415  

View as plain text