gen-helper.go.tmpl 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273
  1. // comment this out // + build ignore
  2. // Copyright (c) 2012-2020 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 = {{ .Version }}
  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. */ -}}
  22. // GenHelperEncoder is exported so that it can be used externally by codecgen.
  23. //
  24. // Library users: DO NOT USE IT DIRECTLY or INDIRECTLY. IT WILL CHANGE CONTINOUSLY WITHOUT NOTICE.
  25. func GenHelper() (g genHelper) { return }
  26. type genHelper struct {}
  27. func (genHelper) Encoder(e *Encoder) (ge genHelperEncoder, ee genHelperEncDriver) {
  28. ge = genHelperEncoder{e: e}
  29. ee = genHelperEncDriver{encDriver: e.e}
  30. return
  31. }
  32. func (genHelper) Decoder(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. type genHelperDecDriver struct {
  41. decDriver
  42. }
  43. // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
  44. type genHelperEncoder struct {
  45. M mustHdl
  46. F fastpathT
  47. e *Encoder
  48. }
  49. // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
  50. type genHelperDecoder struct {
  51. C checkOverflow
  52. F fastpathT
  53. d *Decoder
  54. }
  55. // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
  56. func (f genHelperEncoder) EncBasicHandle() *BasicHandle {
  57. return f.e.h
  58. }
  59. // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
  60. func (f genHelperEncoder) EncWr() *encWr {
  61. return f.e.w()
  62. }
  63. // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
  64. func (f genHelperEncoder) EncBinary() bool {
  65. return f.e.be // f.e.hh.isBinaryEncoding()
  66. }
  67. // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
  68. func (f genHelperEncoder) IsJSONHandle() bool {
  69. return f.e.js
  70. }
  71. // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
  72. func (f genHelperEncoder) EncFallback(iv interface{}) {
  73. // f.e.encodeI(iv, false, false)
  74. f.e.encodeValue(reflect.ValueOf(iv), nil)
  75. }
  76. // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
  77. func (f genHelperEncoder) EncTextMarshal(iv encoding.TextMarshaler) {
  78. bs, fnerr := iv.MarshalText()
  79. f.e.marshalUtf8(bs, fnerr)
  80. }
  81. // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
  82. func (f genHelperEncoder) EncJSONMarshal(iv jsonMarshaler) {
  83. bs, fnerr := iv.MarshalJSON()
  84. f.e.marshalAsis(bs, fnerr)
  85. }
  86. // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
  87. func (f genHelperEncoder) EncBinaryMarshal(iv encoding.BinaryMarshaler) {
  88. bs, fnerr := iv.MarshalBinary()
  89. f.e.marshalRaw(bs, fnerr)
  90. }
  91. // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
  92. func (f genHelperEncoder) EncRaw(iv Raw) { f.e.rawBytes(iv) }
  93. // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
  94. func (f genHelperEncoder) Extension(v interface{}) (xfn *extTypeTagFn) {
  95. return f.e.h.getExtForI(v)
  96. }
  97. // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
  98. func (f genHelperEncoder) EncExtension(v interface{}, xfFn *extTypeTagFn) {
  99. f.e.e.EncodeExt(v, xfFn.rt, xfFn.tag, xfFn.ext)
  100. }
  101. // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
  102. func (f genHelperEncoder) EncWriteMapStart(length int) { f.e.mapStart(length) }
  103. // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
  104. func (f genHelperEncoder) EncWriteMapEnd() { f.e.mapEnd() }
  105. // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
  106. func (f genHelperEncoder) EncWriteArrayStart(length int) { f.e.arrayStart(length) }
  107. // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
  108. func (f genHelperEncoder) EncWriteArrayEnd() { f.e.arrayEnd() }
  109. // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
  110. func (f genHelperEncoder) EncWriteArrayElem() { f.e.arrayElem() }
  111. // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
  112. func (f genHelperEncoder) EncWriteMapElemKey() { f.e.mapElemKey() }
  113. // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
  114. func (f genHelperEncoder) EncWriteMapElemValue() { f.e.mapElemValue() }
  115. // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
  116. func (f genHelperEncoder) EncEncodeComplex64(v complex64) { f.e.encodeComplex64(v) }
  117. // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
  118. func (f genHelperEncoder) EncEncodeComplex128(v complex128) { f.e.encodeComplex128(v) }
  119. // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
  120. func (f genHelperEncoder) EncEncode(v interface{}) { f.e.encode(v) }
  121. // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
  122. func (f genHelperEncoder) EncFnGivenAddr(v interface{}) *codecFn { return f.e.h.fn(reflect.TypeOf(v).Elem()) }
  123. // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
  124. func (f genHelperEncoder) EncEncodeNumBoolStrKindGivenAddr(v interface{}, encFn *codecFn) {
  125. f.e.encodeValueNonNil(reflect.ValueOf(v).Elem(), encFn)
  126. }
  127. // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
  128. func (f genHelperEncoder) EncEncodeMapNonNil(v interface{}) {
  129. if skipFastpathTypeSwitchInDirectCall || !fastpathEncodeTypeSwitch(v, f.e) {
  130. f.e.encodeValueNonNil(reflect.ValueOf(v), nil)
  131. }
  132. }
  133. // ---------------- DECODER FOLLOWS -----------------
  134. // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
  135. func (f genHelperDecoder) DecBasicHandle() *BasicHandle {
  136. return f.d.h
  137. }
  138. // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
  139. func (f genHelperDecoder) DecBinary() bool {
  140. return f.d.be // f.d.hh.isBinaryEncoding()
  141. }
  142. // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
  143. func (f genHelperDecoder) DecSwallow() { f.d.swallow() }
  144. // // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
  145. // func (f genHelperDecoder) DecScratchBuffer() []byte {
  146. // return f.d.b[:]
  147. // }
  148. // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
  149. func (f genHelperDecoder) DecScratchArrayBuffer() *[decScratchByteArrayLen]byte {
  150. return &f.d.b
  151. }
  152. // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
  153. func (f genHelperDecoder) DecFallback(iv interface{}, chkPtr bool) {
  154. rv := reflect.ValueOf(iv)
  155. if chkPtr {
  156. if x, _ := isDecodeable(rv); !x {
  157. f.d.haltAsNotDecodeable(rv)
  158. }
  159. }
  160. f.d.decodeValue(rv, nil)
  161. }
  162. // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
  163. func (f genHelperDecoder) DecSliceHelperStart() (decSliceHelper, int) {
  164. return f.d.decSliceHelperStart()
  165. }
  166. // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
  167. func (f genHelperDecoder) DecStructFieldNotFound(index int, name string) {
  168. f.d.structFieldNotFound(index, name)
  169. }
  170. // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
  171. func (f genHelperDecoder) DecArrayCannotExpand(sliceLen, streamLen int) {
  172. f.d.arrayCannotExpand(sliceLen, streamLen)
  173. }
  174. // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
  175. func (f genHelperDecoder) DecTextUnmarshal(tm encoding.TextUnmarshaler) {
  176. halt.onerror(tm.UnmarshalText(f.d.d.DecodeStringAsBytes()))
  177. }
  178. // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
  179. func (f genHelperDecoder) DecJSONUnmarshal(tm jsonUnmarshaler) {
  180. f.d.jsonUnmarshalV(tm)
  181. }
  182. // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
  183. func (f genHelperDecoder) DecBinaryUnmarshal(bm encoding.BinaryUnmarshaler) {
  184. halt.onerror(bm.UnmarshalBinary(f.d.d.DecodeBytes(nil)))
  185. }
  186. // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
  187. func (f genHelperDecoder) DecRaw() []byte { return f.d.rawBytes() }
  188. // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
  189. func (f genHelperDecoder) IsJSONHandle() bool {
  190. return f.d.js
  191. }
  192. // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
  193. func (f genHelperDecoder) Extension(v interface{}) (xfn *extTypeTagFn) {
  194. return f.d.h.getExtForI(v)
  195. }
  196. // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
  197. func (f genHelperDecoder) DecExtension(v interface{}, xfFn *extTypeTagFn) {
  198. f.d.d.DecodeExt(v, xfFn.rt, xfFn.tag, xfFn.ext)
  199. }
  200. // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
  201. func (f genHelperDecoder) DecInferLen(clen, maxlen, unit int) (rvlen int) {
  202. return decInferLen(clen, maxlen, unit)
  203. }
  204. // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
  205. func (f genHelperDecoder) DecReadMapStart() int { return f.d.mapStart(f.d.d.ReadMapStart()) }
  206. // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
  207. func (f genHelperDecoder) DecReadMapEnd() { f.d.mapEnd() }
  208. // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
  209. func (f genHelperDecoder) DecReadArrayStart() int { return f.d.arrayStart(f.d.d.ReadArrayStart()) }
  210. // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
  211. func (f genHelperDecoder) DecReadArrayEnd() { f.d.arrayEnd() }
  212. // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
  213. func (f genHelperDecoder) DecReadArrayElem() { f.d.arrayElem() }
  214. // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
  215. func (f genHelperDecoder) DecReadMapElemKey() { f.d.mapElemKey() }
  216. // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
  217. func (f genHelperDecoder) DecReadMapElemValue() { f.d.mapElemValue() }
  218. // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
  219. func (f genHelperDecoder) DecDecodeFloat32() float32 { return f.d.decodeFloat32() }
  220. // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
  221. func (f genHelperDecoder) DecStringZC(v []byte) string { return f.d.stringZC(v) }
  222. // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
  223. func (f genHelperDecoder) DecodeBytesInto(v []byte) []byte { return f.d.decodeBytesInto(v) }
  224. // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
  225. func (f genHelperDecoder) DecContainerNext(j, containerLen int, hasLen bool) bool {
  226. // return f.d.containerNext(j, containerLen, hasLen)
  227. // rewriting so it can be inlined
  228. if hasLen {
  229. return j < containerLen
  230. }
  231. return !f.d.checkBreak()
  232. }
  233. {{/*
  234. // MARKER: remove WriteStr, as it cannot be inlined as of 20230201.
  235. // Instead, generated code calls (*encWr).WriteStr directly.
  236. // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
  237. // func (f genHelperEncoder) WriteStr(s string) {
  238. // f.e.encWr.writestr(s)
  239. // }
  240. // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
  241. func (f genHelperDecoder) I2Rtid(v interface{}) uintptr {
  242. return i2rtid(v)
  243. }
  244. */ -}}