enc_helpers.go 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414
  1. // Code generated by go run encgen.go -output enc_helpers.go; DO NOT EDIT.
  2. // Copyright 2014 The Go Authors. All rights reserved.
  3. // Use of this source code is governed by a BSD-style
  4. // license that can be found in the LICENSE file.
  5. package gob
  6. import (
  7. "reflect"
  8. )
  9. var encArrayHelper = map[reflect.Kind]encHelper{
  10. reflect.Bool: encBoolArray,
  11. reflect.Complex64: encComplex64Array,
  12. reflect.Complex128: encComplex128Array,
  13. reflect.Float32: encFloat32Array,
  14. reflect.Float64: encFloat64Array,
  15. reflect.Int: encIntArray,
  16. reflect.Int16: encInt16Array,
  17. reflect.Int32: encInt32Array,
  18. reflect.Int64: encInt64Array,
  19. reflect.Int8: encInt8Array,
  20. reflect.String: encStringArray,
  21. reflect.Uint: encUintArray,
  22. reflect.Uint16: encUint16Array,
  23. reflect.Uint32: encUint32Array,
  24. reflect.Uint64: encUint64Array,
  25. reflect.Uintptr: encUintptrArray,
  26. }
  27. var encSliceHelper = map[reflect.Kind]encHelper{
  28. reflect.Bool: encBoolSlice,
  29. reflect.Complex64: encComplex64Slice,
  30. reflect.Complex128: encComplex128Slice,
  31. reflect.Float32: encFloat32Slice,
  32. reflect.Float64: encFloat64Slice,
  33. reflect.Int: encIntSlice,
  34. reflect.Int16: encInt16Slice,
  35. reflect.Int32: encInt32Slice,
  36. reflect.Int64: encInt64Slice,
  37. reflect.Int8: encInt8Slice,
  38. reflect.String: encStringSlice,
  39. reflect.Uint: encUintSlice,
  40. reflect.Uint16: encUint16Slice,
  41. reflect.Uint32: encUint32Slice,
  42. reflect.Uint64: encUint64Slice,
  43. reflect.Uintptr: encUintptrSlice,
  44. }
  45. func encBoolArray(state *encoderState, v reflect.Value) bool {
  46. // Can only slice if it is addressable.
  47. if !v.CanAddr() {
  48. return false
  49. }
  50. return encBoolSlice(state, v.Slice(0, v.Len()))
  51. }
  52. func encBoolSlice(state *encoderState, v reflect.Value) bool {
  53. slice, ok := v.Interface().([]bool)
  54. if !ok {
  55. // It is kind bool but not type bool. TODO: We can handle this unsafely.
  56. return false
  57. }
  58. for _, x := range slice {
  59. if x != false || state.sendZero {
  60. if x {
  61. state.encodeUint(1)
  62. } else {
  63. state.encodeUint(0)
  64. }
  65. }
  66. }
  67. return true
  68. }
  69. func encComplex64Array(state *encoderState, v reflect.Value) bool {
  70. // Can only slice if it is addressable.
  71. if !v.CanAddr() {
  72. return false
  73. }
  74. return encComplex64Slice(state, v.Slice(0, v.Len()))
  75. }
  76. func encComplex64Slice(state *encoderState, v reflect.Value) bool {
  77. slice, ok := v.Interface().([]complex64)
  78. if !ok {
  79. // It is kind complex64 but not type complex64. TODO: We can handle this unsafely.
  80. return false
  81. }
  82. for _, x := range slice {
  83. if x != 0+0i || state.sendZero {
  84. rpart := floatBits(float64(real(x)))
  85. ipart := floatBits(float64(imag(x)))
  86. state.encodeUint(rpart)
  87. state.encodeUint(ipart)
  88. }
  89. }
  90. return true
  91. }
  92. func encComplex128Array(state *encoderState, v reflect.Value) bool {
  93. // Can only slice if it is addressable.
  94. if !v.CanAddr() {
  95. return false
  96. }
  97. return encComplex128Slice(state, v.Slice(0, v.Len()))
  98. }
  99. func encComplex128Slice(state *encoderState, v reflect.Value) bool {
  100. slice, ok := v.Interface().([]complex128)
  101. if !ok {
  102. // It is kind complex128 but not type complex128. TODO: We can handle this unsafely.
  103. return false
  104. }
  105. for _, x := range slice {
  106. if x != 0+0i || state.sendZero {
  107. rpart := floatBits(real(x))
  108. ipart := floatBits(imag(x))
  109. state.encodeUint(rpart)
  110. state.encodeUint(ipart)
  111. }
  112. }
  113. return true
  114. }
  115. func encFloat32Array(state *encoderState, v reflect.Value) bool {
  116. // Can only slice if it is addressable.
  117. if !v.CanAddr() {
  118. return false
  119. }
  120. return encFloat32Slice(state, v.Slice(0, v.Len()))
  121. }
  122. func encFloat32Slice(state *encoderState, v reflect.Value) bool {
  123. slice, ok := v.Interface().([]float32)
  124. if !ok {
  125. // It is kind float32 but not type float32. TODO: We can handle this unsafely.
  126. return false
  127. }
  128. for _, x := range slice {
  129. if x != 0 || state.sendZero {
  130. bits := floatBits(float64(x))
  131. state.encodeUint(bits)
  132. }
  133. }
  134. return true
  135. }
  136. func encFloat64Array(state *encoderState, v reflect.Value) bool {
  137. // Can only slice if it is addressable.
  138. if !v.CanAddr() {
  139. return false
  140. }
  141. return encFloat64Slice(state, v.Slice(0, v.Len()))
  142. }
  143. func encFloat64Slice(state *encoderState, v reflect.Value) bool {
  144. slice, ok := v.Interface().([]float64)
  145. if !ok {
  146. // It is kind float64 but not type float64. TODO: We can handle this unsafely.
  147. return false
  148. }
  149. for _, x := range slice {
  150. if x != 0 || state.sendZero {
  151. bits := floatBits(x)
  152. state.encodeUint(bits)
  153. }
  154. }
  155. return true
  156. }
  157. func encIntArray(state *encoderState, v reflect.Value) bool {
  158. // Can only slice if it is addressable.
  159. if !v.CanAddr() {
  160. return false
  161. }
  162. return encIntSlice(state, v.Slice(0, v.Len()))
  163. }
  164. func encIntSlice(state *encoderState, v reflect.Value) bool {
  165. slice, ok := v.Interface().([]int)
  166. if !ok {
  167. // It is kind int but not type int. TODO: We can handle this unsafely.
  168. return false
  169. }
  170. for _, x := range slice {
  171. if x != 0 || state.sendZero {
  172. state.encodeInt(int64(x))
  173. }
  174. }
  175. return true
  176. }
  177. func encInt16Array(state *encoderState, v reflect.Value) bool {
  178. // Can only slice if it is addressable.
  179. if !v.CanAddr() {
  180. return false
  181. }
  182. return encInt16Slice(state, v.Slice(0, v.Len()))
  183. }
  184. func encInt16Slice(state *encoderState, v reflect.Value) bool {
  185. slice, ok := v.Interface().([]int16)
  186. if !ok {
  187. // It is kind int16 but not type int16. TODO: We can handle this unsafely.
  188. return false
  189. }
  190. for _, x := range slice {
  191. if x != 0 || state.sendZero {
  192. state.encodeInt(int64(x))
  193. }
  194. }
  195. return true
  196. }
  197. func encInt32Array(state *encoderState, v reflect.Value) bool {
  198. // Can only slice if it is addressable.
  199. if !v.CanAddr() {
  200. return false
  201. }
  202. return encInt32Slice(state, v.Slice(0, v.Len()))
  203. }
  204. func encInt32Slice(state *encoderState, v reflect.Value) bool {
  205. slice, ok := v.Interface().([]int32)
  206. if !ok {
  207. // It is kind int32 but not type int32. TODO: We can handle this unsafely.
  208. return false
  209. }
  210. for _, x := range slice {
  211. if x != 0 || state.sendZero {
  212. state.encodeInt(int64(x))
  213. }
  214. }
  215. return true
  216. }
  217. func encInt64Array(state *encoderState, v reflect.Value) bool {
  218. // Can only slice if it is addressable.
  219. if !v.CanAddr() {
  220. return false
  221. }
  222. return encInt64Slice(state, v.Slice(0, v.Len()))
  223. }
  224. func encInt64Slice(state *encoderState, v reflect.Value) bool {
  225. slice, ok := v.Interface().([]int64)
  226. if !ok {
  227. // It is kind int64 but not type int64. TODO: We can handle this unsafely.
  228. return false
  229. }
  230. for _, x := range slice {
  231. if x != 0 || state.sendZero {
  232. state.encodeInt(x)
  233. }
  234. }
  235. return true
  236. }
  237. func encInt8Array(state *encoderState, v reflect.Value) bool {
  238. // Can only slice if it is addressable.
  239. if !v.CanAddr() {
  240. return false
  241. }
  242. return encInt8Slice(state, v.Slice(0, v.Len()))
  243. }
  244. func encInt8Slice(state *encoderState, v reflect.Value) bool {
  245. slice, ok := v.Interface().([]int8)
  246. if !ok {
  247. // It is kind int8 but not type int8. TODO: We can handle this unsafely.
  248. return false
  249. }
  250. for _, x := range slice {
  251. if x != 0 || state.sendZero {
  252. state.encodeInt(int64(x))
  253. }
  254. }
  255. return true
  256. }
  257. func encStringArray(state *encoderState, v reflect.Value) bool {
  258. // Can only slice if it is addressable.
  259. if !v.CanAddr() {
  260. return false
  261. }
  262. return encStringSlice(state, v.Slice(0, v.Len()))
  263. }
  264. func encStringSlice(state *encoderState, v reflect.Value) bool {
  265. slice, ok := v.Interface().([]string)
  266. if !ok {
  267. // It is kind string but not type string. TODO: We can handle this unsafely.
  268. return false
  269. }
  270. for _, x := range slice {
  271. if x != "" || state.sendZero {
  272. state.encodeUint(uint64(len(x)))
  273. state.b.WriteString(x)
  274. }
  275. }
  276. return true
  277. }
  278. func encUintArray(state *encoderState, v reflect.Value) bool {
  279. // Can only slice if it is addressable.
  280. if !v.CanAddr() {
  281. return false
  282. }
  283. return encUintSlice(state, v.Slice(0, v.Len()))
  284. }
  285. func encUintSlice(state *encoderState, v reflect.Value) bool {
  286. slice, ok := v.Interface().([]uint)
  287. if !ok {
  288. // It is kind uint but not type uint. TODO: We can handle this unsafely.
  289. return false
  290. }
  291. for _, x := range slice {
  292. if x != 0 || state.sendZero {
  293. state.encodeUint(uint64(x))
  294. }
  295. }
  296. return true
  297. }
  298. func encUint16Array(state *encoderState, v reflect.Value) bool {
  299. // Can only slice if it is addressable.
  300. if !v.CanAddr() {
  301. return false
  302. }
  303. return encUint16Slice(state, v.Slice(0, v.Len()))
  304. }
  305. func encUint16Slice(state *encoderState, v reflect.Value) bool {
  306. slice, ok := v.Interface().([]uint16)
  307. if !ok {
  308. // It is kind uint16 but not type uint16. TODO: We can handle this unsafely.
  309. return false
  310. }
  311. for _, x := range slice {
  312. if x != 0 || state.sendZero {
  313. state.encodeUint(uint64(x))
  314. }
  315. }
  316. return true
  317. }
  318. func encUint32Array(state *encoderState, v reflect.Value) bool {
  319. // Can only slice if it is addressable.
  320. if !v.CanAddr() {
  321. return false
  322. }
  323. return encUint32Slice(state, v.Slice(0, v.Len()))
  324. }
  325. func encUint32Slice(state *encoderState, v reflect.Value) bool {
  326. slice, ok := v.Interface().([]uint32)
  327. if !ok {
  328. // It is kind uint32 but not type uint32. TODO: We can handle this unsafely.
  329. return false
  330. }
  331. for _, x := range slice {
  332. if x != 0 || state.sendZero {
  333. state.encodeUint(uint64(x))
  334. }
  335. }
  336. return true
  337. }
  338. func encUint64Array(state *encoderState, v reflect.Value) bool {
  339. // Can only slice if it is addressable.
  340. if !v.CanAddr() {
  341. return false
  342. }
  343. return encUint64Slice(state, v.Slice(0, v.Len()))
  344. }
  345. func encUint64Slice(state *encoderState, v reflect.Value) bool {
  346. slice, ok := v.Interface().([]uint64)
  347. if !ok {
  348. // It is kind uint64 but not type uint64. TODO: We can handle this unsafely.
  349. return false
  350. }
  351. for _, x := range slice {
  352. if x != 0 || state.sendZero {
  353. state.encodeUint(x)
  354. }
  355. }
  356. return true
  357. }
  358. func encUintptrArray(state *encoderState, v reflect.Value) bool {
  359. // Can only slice if it is addressable.
  360. if !v.CanAddr() {
  361. return false
  362. }
  363. return encUintptrSlice(state, v.Slice(0, v.Len()))
  364. }
  365. func encUintptrSlice(state *encoderState, v reflect.Value) bool {
  366. slice, ok := v.Interface().([]uintptr)
  367. if !ok {
  368. // It is kind uintptr but not type uintptr. TODO: We can handle this unsafely.
  369. return false
  370. }
  371. for _, x := range slice {
  372. if x != 0 || state.sendZero {
  373. state.encodeUint(uint64(x))
  374. }
  375. }
  376. return true
  377. }