gen-helper.go.tmpl 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251
  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 "encoding"
  7. // GenVersion is the current version of codecgen.
  8. const GenVersion = {{ .Version }}
  9. // This file is used to generate helper code for codecgen.
  10. // The values here i.e. genHelper(En|De)coder are not to be used directly by
  11. // library users. They WILL change continuously and without notice.
  12. {{/*
  13. // To help enforce this, we create an unexported type with exported members.
  14. // The only way to get the type is via the one exported type that we control (somewhat).
  15. //
  16. // When static codecs are created for types, they will use this value
  17. // to perform encoding or decoding of primitives or known slice or map types.
  18. */ -}}
  19. // GenHelperEncoder is exported so that it can be used externally by codecgen.
  20. //
  21. // Library users: DO NOT USE IT DIRECTLY. IT WILL CHANGE CONTINOUSLY WITHOUT NOTICE.
  22. func GenHelperEncoder(e *Encoder) (ge genHelperEncoder, ee genHelperEncDriver) {
  23. ge = genHelperEncoder{e: e}
  24. ee = genHelperEncDriver{encDriver: e.e}
  25. return
  26. }
  27. // GenHelperDecoder is exported so that it can be used externally by codecgen.
  28. //
  29. // Library users: DO NOT USE IT DIRECTLY. IT WILL CHANGE CONTINOUSLY WITHOUT NOTICE.
  30. func GenHelperDecoder(d *Decoder) (gd genHelperDecoder, dd genHelperDecDriver) {
  31. gd = genHelperDecoder{d: d}
  32. dd = genHelperDecDriver{decDriver: d.d}
  33. return
  34. }
  35. type genHelperEncDriver struct {
  36. encDriver
  37. }
  38. type genHelperDecDriver struct {
  39. decDriver
  40. }
  41. {{/*
  42. // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
  43. func (x genHelperEncDriver) EncStructFieldKey(keyType valueType, s string) {
  44. encStructFieldKey(s, x.encDriver, nil, keyType, false, false)
  45. }
  46. // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
  47. func (x genHelperDecDriver) DecStructFieldKey(keyType valueType, buf *[decScratchByteArrayLen]byte) []byte {
  48. return decStructFieldKey(x.decDriver, keyType, buf)
  49. }
  50. */ -}}
  51. // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
  52. type genHelperEncoder struct {
  53. M must
  54. F fastpathT
  55. e *Encoder
  56. }
  57. // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
  58. type genHelperDecoder struct {
  59. C checkOverflow
  60. F fastpathT
  61. d *Decoder
  62. }
  63. // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
  64. func (f genHelperEncoder) EncBasicHandle() *BasicHandle {
  65. return f.e.h
  66. }
  67. // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
  68. func (f genHelperEncoder) EncBinary() bool {
  69. return f.e.be // f.e.hh.isBinaryEncoding()
  70. }
  71. // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
  72. func (f genHelperEncoder) IsJSONHandle() bool {
  73. return f.e.js
  74. }
  75. // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
  76. func (f genHelperEncoder) EncFallback(iv interface{}) {
  77. // f.e.encodeI(iv, false, false)
  78. f.e.encodeValue(rv4i(iv), nil)
  79. }
  80. // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
  81. func (f genHelperEncoder) EncTextMarshal(iv encoding.TextMarshaler) {
  82. bs, fnerr := iv.MarshalText()
  83. f.e.marshalUtf8(bs, fnerr)
  84. }
  85. // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
  86. func (f genHelperEncoder) EncJSONMarshal(iv jsonMarshaler) {
  87. bs, fnerr := iv.MarshalJSON()
  88. f.e.marshalAsis(bs, fnerr)
  89. }
  90. // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
  91. func (f genHelperEncoder) EncBinaryMarshal(iv encoding.BinaryMarshaler) {
  92. bs, fnerr := iv.MarshalBinary()
  93. f.e.marshalRaw(bs, fnerr)
  94. }
  95. // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
  96. func (f genHelperEncoder) EncRaw(iv Raw) { f.e.rawBytes(iv) }
  97. // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
  98. func (f genHelperEncoder) I2Rtid(v interface{}) uintptr {
  99. return i2rtid(v)
  100. }
  101. // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
  102. func (f genHelperEncoder) Extension(rtid uintptr) (xfn *extTypeTagFn) {
  103. return f.e.h.getExt(rtid, true)
  104. }
  105. // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
  106. func (f genHelperEncoder) EncExtension(v interface{}, xfFn *extTypeTagFn) {
  107. f.e.e.EncodeExt(v, xfFn.tag, xfFn.ext)
  108. }
  109. // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
  110. func (f genHelperEncoder) WriteStr(s string) {
  111. f.e.w().writestr(s)
  112. }
  113. // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
  114. func (f genHelperEncoder) BytesView(v string) []byte { return bytesView(v) }
  115. // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
  116. func (f genHelperEncoder) EncWriteMapStart(length int) { f.e.mapStart(length) }
  117. // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
  118. func (f genHelperEncoder) EncWriteMapEnd() { f.e.mapEnd() }
  119. // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
  120. func (f genHelperEncoder) EncWriteArrayStart(length int) { f.e.arrayStart(length) }
  121. // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
  122. func (f genHelperEncoder) EncWriteArrayEnd() { f.e.arrayEnd() }
  123. // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
  124. func (f genHelperEncoder) EncWriteArrayElem() { f.e.arrayElem() }
  125. // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
  126. func (f genHelperEncoder) EncWriteMapElemKey() { f.e.mapElemKey() }
  127. // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
  128. func (f genHelperEncoder) EncWriteMapElemValue() { f.e.mapElemValue() }
  129. // ---------------- DECODER FOLLOWS -----------------
  130. // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
  131. func (f genHelperDecoder) DecBasicHandle() *BasicHandle {
  132. return f.d.h
  133. }
  134. // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
  135. func (f genHelperDecoder) DecBinary() bool {
  136. return f.d.be // f.d.hh.isBinaryEncoding()
  137. }
  138. // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
  139. func (f genHelperDecoder) DecSwallow() { f.d.swallow() }
  140. // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
  141. func (f genHelperDecoder) DecScratchBuffer() []byte {
  142. return f.d.b[:]
  143. }
  144. // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
  145. func (f genHelperDecoder) DecScratchArrayBuffer() *[decScratchByteArrayLen]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) DecFallback(iv interface{}, chkPtr bool) {
  150. rv := rv4i(iv)
  151. if chkPtr {
  152. f.d.ensureDecodeable(rv)
  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. if fnerr := tm.UnmarshalText(f.d.d.DecodeStringAsBytes()); fnerr != nil {
  171. panic(fnerr)
  172. }
  173. }
  174. // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
  175. func (f genHelperDecoder) DecJSONUnmarshal(tm jsonUnmarshaler) {
  176. // bs := f.dd.DecodeStringAsBytes()
  177. // grab the bytes to be read, as UnmarshalJSON needs the full JSON so as to unmarshal it itself.
  178. if fnerr := tm.UnmarshalJSON(f.d.nextValueBytes()); fnerr != nil {
  179. panic(fnerr)
  180. }
  181. }
  182. // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
  183. func (f genHelperDecoder) DecBinaryUnmarshal(bm encoding.BinaryUnmarshaler) {
  184. if fnerr := bm.UnmarshalBinary(f.d.d.DecodeBytes(nil, true)); fnerr != nil {
  185. panic(fnerr)
  186. }
  187. }
  188. // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
  189. func (f genHelperDecoder) DecRaw() []byte { return f.d.rawBytes() }
  190. // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
  191. func (f genHelperDecoder) IsJSONHandle() bool {
  192. return f.d.js
  193. }
  194. // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
  195. func (f genHelperDecoder) I2Rtid(v interface{}) uintptr {
  196. return i2rtid(v)
  197. }
  198. // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
  199. func (f genHelperDecoder) Extension(rtid uintptr) (xfn *extTypeTagFn) {
  200. return f.d.h.getExt(rtid, true)
  201. }
  202. // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
  203. func (f genHelperDecoder) DecExtension(v interface{}, xfFn *extTypeTagFn) {
  204. f.d.d.DecodeExt(v, xfFn.tag, xfFn.ext)
  205. }
  206. // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
  207. func (f genHelperDecoder) DecInferLen(clen, maxlen, unit int) (rvlen int) {
  208. return decInferLen(clen, maxlen, unit)
  209. }
  210. // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
  211. func (f genHelperDecoder) StringView(v []byte) string { return stringView(v) }
  212. // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
  213. func (f genHelperDecoder) DecReadMapStart() int { return f.d.mapStart() }
  214. // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
  215. func (f genHelperDecoder) DecReadMapEnd() { f.d.mapEnd() }
  216. // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
  217. func (f genHelperDecoder) DecReadArrayStart() int { return f.d.arrayStart() }
  218. // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
  219. func (f genHelperDecoder) DecReadArrayEnd() { f.d.arrayEnd() }
  220. // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
  221. func (f genHelperDecoder) DecReadArrayElem() { f.d.arrayElem() }
  222. // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
  223. func (f genHelperDecoder) DecReadMapElemKey() { f.d.mapElemKey() }
  224. // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
  225. func (f genHelperDecoder) DecReadMapElemValue() { f.d.mapElemValue() }
  226. // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
  227. func (f genHelperDecoder) DecDecodeFloat32() float32 { return f.d.decodeFloat32() }