另客网go项目公用的代码库

gen-helper.generated.go 12KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352
  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. //
  161. // Deprecated: No longer used,
  162. // but leave in-place so that old generated files continue to work without regeneration.
  163. func (f genHelperEncoder) HasExtensions() bool {
  164. return len(f.e.h.extHandle) != 0
  165. }
  166. // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
  167. //
  168. // Deprecated: No longer used,
  169. // but leave in-place so that old generated files continue to work without regeneration.
  170. func (f genHelperEncoder) EncExt(v interface{}) (r bool) {
  171. if xfFn := f.e.h.getExt(i2rtid(v)); xfFn != nil {
  172. f.e.e.EncodeExt(v, xfFn.tag, xfFn.ext, f.e)
  173. return true
  174. }
  175. return false
  176. }
  177. // ---------------- DECODER FOLLOWS -----------------
  178. // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
  179. func (f genHelperDecoder) DecBasicHandle() *BasicHandle {
  180. return f.d.h
  181. }
  182. // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
  183. func (f genHelperDecoder) DecBinary() bool {
  184. return f.d.be // f.d.hh.isBinaryEncoding()
  185. }
  186. // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
  187. func (f genHelperDecoder) DecSwallow() { f.d.swallow() }
  188. // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
  189. func (f genHelperDecoder) DecScratchBuffer() []byte {
  190. return f.d.b[:]
  191. }
  192. // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
  193. func (f genHelperDecoder) DecScratchArrayBuffer() *[decScratchByteArrayLen]byte {
  194. return &f.d.b
  195. }
  196. // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
  197. func (f genHelperDecoder) DecFallback(iv interface{}, chkPtr bool) {
  198. // println(">>>>>>>>> DecFallback")
  199. rv := reflect.ValueOf(iv)
  200. if chkPtr {
  201. rv = f.d.ensureDecodeable(rv)
  202. }
  203. f.d.decodeValue(rv, nil, false)
  204. // f.d.decodeValueFallback(rv)
  205. }
  206. // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
  207. func (f genHelperDecoder) DecSliceHelperStart() (decSliceHelper, int) {
  208. return f.d.decSliceHelperStart()
  209. }
  210. // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
  211. func (f genHelperDecoder) DecStructFieldNotFound(index int, name string) {
  212. f.d.structFieldNotFound(index, name)
  213. }
  214. // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
  215. func (f genHelperDecoder) DecArrayCannotExpand(sliceLen, streamLen int) {
  216. f.d.arrayCannotExpand(sliceLen, streamLen)
  217. }
  218. // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
  219. func (f genHelperDecoder) DecTextUnmarshal(tm encoding.TextUnmarshaler) {
  220. fnerr := tm.UnmarshalText(f.d.d.DecodeStringAsBytes())
  221. if fnerr != nil {
  222. panic(fnerr)
  223. }
  224. }
  225. // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
  226. func (f genHelperDecoder) DecJSONUnmarshal(tm jsonUnmarshaler) {
  227. // bs := f.dd.DecodeStringAsBytes()
  228. // grab the bytes to be read, as UnmarshalJSON needs the full JSON so as to unmarshal it itself.
  229. fnerr := tm.UnmarshalJSON(f.d.nextValueBytes())
  230. if fnerr != nil {
  231. panic(fnerr)
  232. }
  233. }
  234. // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
  235. func (f genHelperDecoder) DecBinaryUnmarshal(bm encoding.BinaryUnmarshaler) {
  236. fnerr := bm.UnmarshalBinary(f.d.d.DecodeBytes(nil, true))
  237. if fnerr != nil {
  238. panic(fnerr)
  239. }
  240. }
  241. // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
  242. func (f genHelperDecoder) DecRaw() []byte { return f.d.rawBytes() }
  243. // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
  244. //
  245. // Deprecated: builtin no longer supported - so we make this method a no-op,
  246. // but leave in-place so that old generated files continue to work without regeneration.
  247. func (f genHelperDecoder) TimeRtidIfBinc() (v uintptr) { return }
  248. // func (f genHelperDecoder) TimeRtidIfBinc() uintptr {
  249. // // Note: builtin is no longer supported - so make this a no-op
  250. // if _, ok := f.d.hh.(*BincHandle); ok {
  251. // return timeTypId
  252. // }
  253. // return 0
  254. // }
  255. // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
  256. func (f genHelperDecoder) IsJSONHandle() bool {
  257. return f.d.js
  258. }
  259. // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
  260. func (f genHelperDecoder) I2Rtid(v interface{}) uintptr {
  261. return i2rtid(v)
  262. }
  263. // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
  264. func (f genHelperDecoder) Extension(rtid uintptr) (xfn *extTypeTagFn) {
  265. return f.d.h.getExt(rtid)
  266. }
  267. // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
  268. func (f genHelperDecoder) DecExtension(v interface{}, xfFn *extTypeTagFn) {
  269. f.d.d.DecodeExt(v, xfFn.tag, xfFn.ext)
  270. }
  271. // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
  272. //
  273. // Deprecated: No longer used,
  274. // but leave in-place so that old generated files continue to work without regeneration.
  275. func (f genHelperDecoder) HasExtensions() bool {
  276. return len(f.d.h.extHandle) != 0
  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) DecExt(v interface{}) (r bool) {
  283. if xfFn := f.d.h.getExt(i2rtid(v)); xfFn != nil {
  284. f.d.d.DecodeExt(v, xfFn.tag, xfFn.ext)
  285. return true
  286. }
  287. return false
  288. }
  289. // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
  290. func (f genHelperDecoder) DecInferLen(clen, maxlen, unit int) (rvlen int) {
  291. return decInferLen(clen, maxlen, unit)
  292. }
  293. // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
  294. //
  295. // Deprecated: no longer used,
  296. // but leave in-place so that old generated files continue to work without regeneration.
  297. func (f genHelperDecoder) StringView(v []byte) string { return stringView(v) }