gen-helper.go.tmpl 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249
  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) EncBinary() bool {
  61. return f.e.be // f.e.hh.isBinaryEncoding()
  62. }
  63. // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
  64. func (f genHelperEncoder) IsJSONHandle() bool {
  65. return f.e.js
  66. }
  67. // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
  68. func (f genHelperEncoder) EncFallback(iv interface{}) {
  69. // f.e.encodeI(iv, false, false)
  70. f.e.encodeValue(reflect.ValueOf(iv), nil)
  71. }
  72. // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
  73. func (f genHelperEncoder) EncTextMarshal(iv encoding.TextMarshaler) {
  74. bs, fnerr := iv.MarshalText()
  75. f.e.marshalUtf8(bs, fnerr)
  76. }
  77. // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
  78. func (f genHelperEncoder) EncJSONMarshal(iv jsonMarshaler) {
  79. bs, fnerr := iv.MarshalJSON()
  80. f.e.marshalAsis(bs, fnerr)
  81. }
  82. // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
  83. func (f genHelperEncoder) EncBinaryMarshal(iv encoding.BinaryMarshaler) {
  84. bs, fnerr := iv.MarshalBinary()
  85. f.e.marshalRaw(bs, fnerr)
  86. }
  87. // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
  88. func (f genHelperEncoder) EncRaw(iv Raw) { f.e.rawBytes(iv) }
  89. // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
  90. func (f genHelperEncoder) Extension(v interface{}) (xfn *extTypeTagFn) {
  91. return f.e.h.getExtForI(v)
  92. }
  93. // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
  94. func (f genHelperEncoder) EncExtension(v interface{}, xfFn *extTypeTagFn) {
  95. f.e.e.EncodeExt(v, xfFn.rt, xfFn.tag, xfFn.ext)
  96. }
  97. // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
  98. func (f genHelperEncoder) WriteStr(s string) {
  99. f.e.w().writestr(s)
  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) EncEncodeMapNonNil(v interface{}) {
  123. if skipFastpathTypeSwitchInDirectCall || !fastpathEncodeTypeSwitch(v, f.e) {
  124. f.e.encodeValue(reflect.ValueOf(v), nil)
  125. }
  126. }
  127. // ---------------- DECODER FOLLOWS -----------------
  128. // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
  129. func (f genHelperDecoder) DecBasicHandle() *BasicHandle {
  130. return f.d.h
  131. }
  132. // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
  133. func (f genHelperDecoder) DecBinary() bool {
  134. return f.d.be // f.d.hh.isBinaryEncoding()
  135. }
  136. // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
  137. func (f genHelperDecoder) DecSwallow() { f.d.swallow() }
  138. // // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
  139. // func (f genHelperDecoder) DecScratchBuffer() []byte {
  140. // return f.d.b[:]
  141. // }
  142. // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
  143. func (f genHelperDecoder) DecScratchArrayBuffer() *[decScratchByteArrayLen]byte {
  144. return &f.d.b
  145. }
  146. // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
  147. func (f genHelperDecoder) DecFallback(iv interface{}, chkPtr bool) {
  148. rv := reflect.ValueOf(iv)
  149. if chkPtr {
  150. if x, _ := isDecodeable(rv); !x {
  151. f.d.haltAsNotDecodeable(rv)
  152. }
  153. }
  154. f.d.decodeValue(rv, nil)
  155. }
  156. // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
  157. func (f genHelperDecoder) DecSliceHelperStart() (decSliceHelper, int) {
  158. return f.d.decSliceHelperStart()
  159. }
  160. // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
  161. func (f genHelperDecoder) DecStructFieldNotFound(index int, name string) {
  162. f.d.structFieldNotFound(index, name)
  163. }
  164. // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
  165. func (f genHelperDecoder) DecArrayCannotExpand(sliceLen, streamLen int) {
  166. f.d.arrayCannotExpand(sliceLen, streamLen)
  167. }
  168. // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
  169. func (f genHelperDecoder) DecTextUnmarshal(tm encoding.TextUnmarshaler) {
  170. halt.onerror(tm.UnmarshalText(f.d.d.DecodeStringAsBytes()))
  171. }
  172. // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
  173. func (f genHelperDecoder) DecJSONUnmarshal(tm jsonUnmarshaler) {
  174. f.d.jsonUnmarshalV(tm)
  175. }
  176. // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
  177. func (f genHelperDecoder) DecBinaryUnmarshal(bm encoding.BinaryUnmarshaler) {
  178. halt.onerror(bm.UnmarshalBinary(f.d.d.DecodeBytes(nil)))
  179. }
  180. // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
  181. func (f genHelperDecoder) DecRaw() []byte { return f.d.rawBytes() }
  182. // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
  183. func (f genHelperDecoder) IsJSONHandle() bool {
  184. return f.d.js
  185. }
  186. {{/*
  187. // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
  188. func (f genHelperDecoder) I2Rtid(v interface{}) uintptr {
  189. return i2rtid(v)
  190. }
  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) DecCheckBreak() bool { return f.d.checkBreak() }
  222. // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
  223. func (f genHelperDecoder) DecStringZC(v []byte) string { return f.d.stringZC(v) }
  224. // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
  225. func (f genHelperDecoder) DecodeBytesInto(v []byte) []byte { return f.d.decodeBytesInto(v) }