gen-helper.generated.go 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335
  1. /* // +build ignore */
  2. // Copyright (c) 2012-2015 Ugorji Nwoke. All rights reserved.
  3. // Use of this source code is governed by a MIT license found in the LICENSE file.
  4. // Code generated from gen-helper.go.tmpl - DO NOT EDIT.
  5. package codec
  6. import (
  7. "encoding"
  8. "reflect"
  9. )
  10. // GenVersion is the current version of codecgen.
  11. const GenVersion = 8
  12. // This file is used to generate helper code for codecgen.
  13. // The values here i.e. genHelper(En|De)coder are not to be used directly by
  14. // library users. They WILL change continuously and without notice.
  15. //
  16. // To help enforce this, we create an unexported type with exported members.
  17. // The only way to get the type is via the one exported type that we control (somewhat).
  18. //
  19. // When static codecs are created for types, they will use this value
  20. // to perform encoding or decoding of primitives or known slice or map types.
  21. // GenHelperEncoder is exported so that it can be used externally by codecgen.
  22. //
  23. // Library users: DO NOT USE IT DIRECTLY. IT WILL CHANGE CONTINOUSLY WITHOUT NOTICE.
  24. func GenHelperEncoder(e *Encoder) (ge genHelperEncoder, ee genHelperEncDriver) {
  25. ge = genHelperEncoder{e: e}
  26. ee = genHelperEncDriver{encDriver: e.e}
  27. return
  28. }
  29. // GenHelperDecoder is exported so that it can be used externally by codecgen.
  30. //
  31. // Library users: DO NOT USE IT DIRECTLY. IT WILL CHANGE CONTINOUSLY WITHOUT NOTICE.
  32. func GenHelperDecoder(d *Decoder) (gd genHelperDecoder, dd genHelperDecDriver) {
  33. gd = genHelperDecoder{d: d}
  34. dd = genHelperDecDriver{decDriver: d.d}
  35. return
  36. }
  37. type genHelperEncDriver struct {
  38. encDriver
  39. }
  40. func (x genHelperEncDriver) EncodeBuiltin(rt uintptr, v interface{}) {}
  41. func (x genHelperEncDriver) EncStructFieldKey(keyType valueType, s string) {
  42. encStructFieldKey(x.encDriver, keyType, s)
  43. }
  44. func (x genHelperEncDriver) EncodeSymbol(s string) {
  45. x.encDriver.EncodeString(cUTF8, s)
  46. }
  47. type genHelperDecDriver struct {
  48. decDriver
  49. C checkOverflow
  50. }
  51. func (x genHelperDecDriver) DecodeBuiltin(rt uintptr, v interface{}) {}
  52. func (x genHelperDecDriver) DecStructFieldKey(keyType valueType, buf *[decScratchByteArrayLen]byte) []byte {
  53. return decStructFieldKey(x.decDriver, keyType, buf)
  54. }
  55. func (x genHelperDecDriver) DecodeInt(bitsize uint8) (i int64) {
  56. return x.C.IntV(x.decDriver.DecodeInt64(), bitsize)
  57. }
  58. func (x genHelperDecDriver) DecodeUint(bitsize uint8) (ui uint64) {
  59. return x.C.UintV(x.decDriver.DecodeUint64(), bitsize)
  60. }
  61. func (x genHelperDecDriver) DecodeFloat(chkOverflow32 bool) (f float64) {
  62. f = x.DecodeFloat64()
  63. if chkOverflow32 && chkOvf.Float32(f) {
  64. panicv.errorf("float32 overflow: %v", f)
  65. }
  66. return
  67. }
  68. func (x genHelperDecDriver) DecodeFloat32As64() (f float64) {
  69. f = x.DecodeFloat64()
  70. if chkOvf.Float32(f) {
  71. panicv.errorf("float32 overflow: %v", f)
  72. }
  73. return
  74. }
  75. // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
  76. type genHelperEncoder struct {
  77. M must
  78. e *Encoder
  79. F fastpathT
  80. }
  81. // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
  82. type genHelperDecoder struct {
  83. C checkOverflow
  84. d *Decoder
  85. F fastpathT
  86. }
  87. // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
  88. func (f genHelperEncoder) EncBasicHandle() *BasicHandle {
  89. return f.e.h
  90. }
  91. // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
  92. func (f genHelperEncoder) EncBinary() bool {
  93. return f.e.be // f.e.hh.isBinaryEncoding()
  94. }
  95. // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
  96. func (f genHelperEncoder) IsJSONHandle() bool {
  97. return f.e.js
  98. }
  99. // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
  100. func (f genHelperEncoder) EncFallback(iv interface{}) {
  101. // println(">>>>>>>>> EncFallback")
  102. // f.e.encodeI(iv, false, false)
  103. f.e.encodeValue(reflect.ValueOf(iv), nil, false)
  104. }
  105. // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
  106. func (f genHelperEncoder) EncTextMarshal(iv encoding.TextMarshaler) {
  107. bs, fnerr := iv.MarshalText()
  108. f.e.marshal(bs, fnerr, false, cUTF8)
  109. }
  110. // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
  111. func (f genHelperEncoder) EncJSONMarshal(iv jsonMarshaler) {
  112. bs, fnerr := iv.MarshalJSON()
  113. f.e.marshal(bs, fnerr, true, cUTF8)
  114. }
  115. // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
  116. func (f genHelperEncoder) EncBinaryMarshal(iv encoding.BinaryMarshaler) {
  117. bs, fnerr := iv.MarshalBinary()
  118. f.e.marshal(bs, fnerr, false, cRAW)
  119. }
  120. // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
  121. func (f genHelperEncoder) EncRaw(iv Raw) { f.e.rawBytes(iv) }
  122. // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
  123. //
  124. // Deprecated: builtin no longer supported - so we make this method a no-op,
  125. // but leave in-place so that old generated files continue to work without regeneration.
  126. func (f genHelperEncoder) TimeRtidIfBinc() (v uintptr) { return }
  127. // func (f genHelperEncoder) TimeRtidIfBinc() uintptr {
  128. // if _, ok := f.e.hh.(*BincHandle); ok {
  129. // return timeTypId
  130. // }
  131. // }
  132. // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
  133. func (f genHelperEncoder) I2Rtid(v interface{}) uintptr {
  134. return i2rtid(v)
  135. }
  136. // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
  137. func (f genHelperEncoder) Extension(rtid uintptr) (xfn *extTypeTagFn) {
  138. return f.e.h.getExt(rtid)
  139. }
  140. // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
  141. func (f genHelperEncoder) EncExtension(v interface{}, xfFn *extTypeTagFn) {
  142. f.e.e.EncodeExt(v, xfFn.tag, xfFn.ext, f.e)
  143. }
  144. // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
  145. //
  146. // Deprecated: No longer used,
  147. // but leave in-place so that old generated files continue to work without regeneration.
  148. func (f genHelperEncoder) HasExtensions() bool {
  149. return len(f.e.h.extHandle) != 0
  150. }
  151. // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
  152. //
  153. // Deprecated: No longer used,
  154. // but leave in-place so that old generated files continue to work without regeneration.
  155. func (f genHelperEncoder) EncExt(v interface{}) (r bool) {
  156. if xfFn := f.e.h.getExt(i2rtid(v)); xfFn != nil {
  157. f.e.e.EncodeExt(v, xfFn.tag, xfFn.ext, f.e)
  158. return true
  159. }
  160. return false
  161. }
  162. // ---------------- DECODER FOLLOWS -----------------
  163. // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
  164. func (f genHelperDecoder) DecBasicHandle() *BasicHandle {
  165. return f.d.h
  166. }
  167. // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
  168. func (f genHelperDecoder) DecBinary() bool {
  169. return f.d.be // f.d.hh.isBinaryEncoding()
  170. }
  171. // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
  172. func (f genHelperDecoder) DecSwallow() { f.d.swallow() }
  173. // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
  174. func (f genHelperDecoder) DecScratchBuffer() []byte {
  175. return f.d.b[:]
  176. }
  177. // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
  178. func (f genHelperDecoder) DecScratchArrayBuffer() *[decScratchByteArrayLen]byte {
  179. return &f.d.b
  180. }
  181. // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
  182. func (f genHelperDecoder) DecFallback(iv interface{}, chkPtr bool) {
  183. // println(">>>>>>>>> DecFallback")
  184. rv := reflect.ValueOf(iv)
  185. if chkPtr {
  186. rv = f.d.ensureDecodeable(rv)
  187. }
  188. f.d.decodeValue(rv, nil, false)
  189. // f.d.decodeValueFallback(rv)
  190. }
  191. // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
  192. func (f genHelperDecoder) DecSliceHelperStart() (decSliceHelper, int) {
  193. return f.d.decSliceHelperStart()
  194. }
  195. // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
  196. func (f genHelperDecoder) DecStructFieldNotFound(index int, name string) {
  197. f.d.structFieldNotFound(index, name)
  198. }
  199. // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
  200. func (f genHelperDecoder) DecArrayCannotExpand(sliceLen, streamLen int) {
  201. f.d.arrayCannotExpand(sliceLen, streamLen)
  202. }
  203. // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
  204. func (f genHelperDecoder) DecTextUnmarshal(tm encoding.TextUnmarshaler) {
  205. fnerr := tm.UnmarshalText(f.d.d.DecodeStringAsBytes())
  206. if fnerr != nil {
  207. panic(fnerr)
  208. }
  209. }
  210. // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
  211. func (f genHelperDecoder) DecJSONUnmarshal(tm jsonUnmarshaler) {
  212. // bs := f.dd.DecodeStringAsBytes()
  213. // grab the bytes to be read, as UnmarshalJSON needs the full JSON so as to unmarshal it itself.
  214. fnerr := tm.UnmarshalJSON(f.d.nextValueBytes())
  215. if fnerr != nil {
  216. panic(fnerr)
  217. }
  218. }
  219. // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
  220. func (f genHelperDecoder) DecBinaryUnmarshal(bm encoding.BinaryUnmarshaler) {
  221. fnerr := bm.UnmarshalBinary(f.d.d.DecodeBytes(nil, true))
  222. if fnerr != nil {
  223. panic(fnerr)
  224. }
  225. }
  226. // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
  227. func (f genHelperDecoder) DecRaw() []byte { return f.d.rawBytes() }
  228. // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
  229. //
  230. // Deprecated: builtin no longer supported - so we make this method a no-op,
  231. // but leave in-place so that old generated files continue to work without regeneration.
  232. func (f genHelperDecoder) TimeRtidIfBinc() (v uintptr) { return }
  233. // func (f genHelperDecoder) TimeRtidIfBinc() uintptr {
  234. // // Note: builtin is no longer supported - so make this a no-op
  235. // if _, ok := f.d.hh.(*BincHandle); ok {
  236. // return timeTypId
  237. // }
  238. // return 0
  239. // }
  240. // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
  241. func (f genHelperDecoder) IsJSONHandle() bool {
  242. return f.d.js
  243. }
  244. // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
  245. func (f genHelperDecoder) I2Rtid(v interface{}) uintptr {
  246. return i2rtid(v)
  247. }
  248. // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
  249. func (f genHelperDecoder) Extension(rtid uintptr) (xfn *extTypeTagFn) {
  250. return f.d.h.getExt(rtid)
  251. }
  252. // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
  253. func (f genHelperDecoder) DecExtension(v interface{}, xfFn *extTypeTagFn) {
  254. f.d.d.DecodeExt(v, xfFn.tag, xfFn.ext)
  255. }
  256. // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
  257. //
  258. // Deprecated: No longer used,
  259. // but leave in-place so that old generated files continue to work without regeneration.
  260. func (f genHelperDecoder) HasExtensions() bool {
  261. return len(f.d.h.extHandle) != 0
  262. }
  263. // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
  264. //
  265. // Deprecated: No longer used,
  266. // but leave in-place so that old generated files continue to work without regeneration.
  267. func (f genHelperDecoder) DecExt(v interface{}) (r bool) {
  268. if xfFn := f.d.h.getExt(i2rtid(v)); xfFn != nil {
  269. f.d.d.DecodeExt(v, xfFn.tag, xfFn.ext)
  270. return true
  271. }
  272. return false
  273. }
  274. // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
  275. func (f genHelperDecoder) DecInferLen(clen, maxlen, unit int) (rvlen int) {
  276. return decInferLen(clen, maxlen, unit)
  277. }
  278. // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
  279. //
  280. // Deprecated: no longer used,
  281. // but leave in-place so that old generated files continue to work without regeneration.
  282. func (f genHelperDecoder) StringView(v []byte) string { return stringView(v) }