gen-helper.generated.go 12 KB

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