gen-helper.go.tmpl 10.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243
  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. // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
  42. type genHelperEncoder struct {
  43. M must
  44. F fastpathT
  45. e *Encoder
  46. }
  47. // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
  48. type genHelperDecoder struct {
  49. C checkOverflow
  50. F fastpathT
  51. d *Decoder
  52. }
  53. // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
  54. func (f genHelperEncoder) EncBasicHandle() *BasicHandle {
  55. return f.e.h
  56. }
  57. // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
  58. func (f genHelperEncoder) EncBinary() bool {
  59. return f.e.be // f.e.hh.isBinaryEncoding()
  60. }
  61. // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
  62. func (f genHelperEncoder) IsJSONHandle() bool {
  63. return f.e.js
  64. }
  65. // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
  66. func (f genHelperEncoder) EncFallback(iv interface{}) {
  67. // f.e.encodeI(iv, false, false)
  68. f.e.encodeValue(rv4i(iv), nil)
  69. }
  70. // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
  71. func (f genHelperEncoder) EncTextMarshal(iv encoding.TextMarshaler) {
  72. bs, fnerr := iv.MarshalText()
  73. f.e.marshalUtf8(bs, fnerr)
  74. }
  75. // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
  76. func (f genHelperEncoder) EncJSONMarshal(iv jsonMarshaler) {
  77. bs, fnerr := iv.MarshalJSON()
  78. f.e.marshalAsis(bs, fnerr)
  79. }
  80. // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
  81. func (f genHelperEncoder) EncBinaryMarshal(iv encoding.BinaryMarshaler) {
  82. bs, fnerr := iv.MarshalBinary()
  83. f.e.marshalRaw(bs, fnerr)
  84. }
  85. // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
  86. func (f genHelperEncoder) EncRaw(iv Raw) { f.e.rawBytes(iv) }
  87. // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
  88. func (f genHelperEncoder) I2Rtid(v interface{}) uintptr {
  89. return i2rtid(v)
  90. }
  91. // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
  92. func (f genHelperEncoder) Extension(rtid uintptr) (xfn *extTypeTagFn) {
  93. return f.e.h.getExt(rtid, true)
  94. }
  95. // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
  96. func (f genHelperEncoder) EncExtension(v interface{}, xfFn *extTypeTagFn) {
  97. f.e.e.EncodeExt(v, xfFn.tag, xfFn.ext)
  98. }
  99. // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
  100. func (f genHelperEncoder) WriteStr(s string) {
  101. f.e.w().writestr(s)
  102. }
  103. // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
  104. func (f genHelperEncoder) BytesView(v string) []byte { return bytesView(v) }
  105. // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
  106. func (f genHelperEncoder) EncWriteMapStart(length int) { f.e.mapStart(length) }
  107. // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
  108. func (f genHelperEncoder) EncWriteMapEnd() { f.e.mapEnd() }
  109. // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
  110. func (f genHelperEncoder) EncWriteArrayStart(length int) { f.e.arrayStart(length) }
  111. // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
  112. func (f genHelperEncoder) EncWriteArrayEnd() { f.e.arrayEnd() }
  113. // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
  114. func (f genHelperEncoder) EncWriteArrayElem() { f.e.arrayElem() }
  115. // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
  116. func (f genHelperEncoder) EncWriteMapElemKey() { f.e.mapElemKey() }
  117. // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
  118. func (f genHelperEncoder) EncWriteMapElemValue() { f.e.mapElemValue() }
  119. // ---------------- DECODER FOLLOWS -----------------
  120. // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
  121. func (f genHelperDecoder) DecBasicHandle() *BasicHandle {
  122. return f.d.h
  123. }
  124. // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
  125. func (f genHelperDecoder) DecBinary() bool {
  126. return f.d.be // f.d.hh.isBinaryEncoding()
  127. }
  128. // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
  129. func (f genHelperDecoder) DecSwallow() { f.d.swallow() }
  130. // // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
  131. // func (f genHelperDecoder) DecScratchBuffer() []byte {
  132. // return f.d.b[:]
  133. // }
  134. // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
  135. func (f genHelperDecoder) DecScratchArrayBuffer() *[decScratchByteArrayLen]byte {
  136. return &f.d.b
  137. }
  138. // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
  139. func (f genHelperDecoder) DecFallback(iv interface{}, chkPtr bool) {
  140. rv := rv4i(iv)
  141. if chkPtr {
  142. f.d.ensureDecodeable(rv)
  143. }
  144. f.d.decodeValue(rv, nil)
  145. }
  146. // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
  147. func (f genHelperDecoder) DecSliceHelperStart() (decSliceHelper, int) {
  148. return f.d.decSliceHelperStart()
  149. }
  150. // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
  151. func (f genHelperDecoder) DecStructFieldNotFound(index int, name string) {
  152. f.d.structFieldNotFound(index, name)
  153. }
  154. // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
  155. func (f genHelperDecoder) DecArrayCannotExpand(sliceLen, streamLen int) {
  156. f.d.arrayCannotExpand(sliceLen, streamLen)
  157. }
  158. // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
  159. func (f genHelperDecoder) DecTextUnmarshal(tm encoding.TextUnmarshaler) {
  160. if fnerr := tm.UnmarshalText(f.d.d.DecodeStringAsBytes()); fnerr != nil {
  161. halt.errorv(fnerr)
  162. }
  163. }
  164. // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
  165. func (f genHelperDecoder) DecJSONUnmarshal(tm jsonUnmarshaler) {
  166. // bs := f.dd.DecodeStringAsBytes()
  167. // grab the bytes to be read, as UnmarshalJSON needs the full JSON so as to unmarshal it itself.
  168. if fnerr := tm.UnmarshalJSON(f.d.nextValueBytes()); fnerr != nil {
  169. halt.errorv(fnerr)
  170. }
  171. }
  172. // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
  173. func (f genHelperDecoder) DecBinaryUnmarshal(bm encoding.BinaryUnmarshaler) {
  174. if fnerr := bm.UnmarshalBinary(f.d.d.DecodeBytes(nil, true)); fnerr != nil {
  175. halt.errorv(fnerr)
  176. }
  177. }
  178. // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
  179. func (f genHelperDecoder) DecRaw() []byte { return f.d.rawBytes() }
  180. // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
  181. func (f genHelperDecoder) IsJSONHandle() bool {
  182. return f.d.js
  183. }
  184. // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
  185. func (f genHelperDecoder) I2Rtid(v interface{}) uintptr {
  186. return i2rtid(v)
  187. }
  188. // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
  189. func (f genHelperDecoder) Extension(rtid uintptr) (xfn *extTypeTagFn) {
  190. return f.d.h.getExt(rtid, true)
  191. }
  192. // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
  193. func (f genHelperDecoder) DecExtension(v interface{}, xfFn *extTypeTagFn) {
  194. f.d.d.DecodeExt(v, xfFn.tag, xfFn.ext)
  195. }
  196. // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
  197. func (f genHelperDecoder) DecInferLen(clen, maxlen, unit int) (rvlen int) {
  198. return decInferLen(clen, maxlen, unit)
  199. }
  200. // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
  201. func (f genHelperDecoder) StringView(v []byte) string { return stringView(v) }
  202. // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
  203. func (f genHelperDecoder) DecReadMapStart() int { return f.d.mapStart() }
  204. // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
  205. func (f genHelperDecoder) DecReadMapEnd() { f.d.mapEnd() }
  206. // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
  207. func (f genHelperDecoder) DecReadArrayStart() int { return f.d.arrayStart() }
  208. // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
  209. func (f genHelperDecoder) DecReadArrayEnd() { f.d.arrayEnd() }
  210. // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
  211. func (f genHelperDecoder) DecReadArrayElem() { f.d.arrayElem() }
  212. // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
  213. func (f genHelperDecoder) DecReadMapElemKey() { f.d.mapElemKey() }
  214. // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
  215. func (f genHelperDecoder) DecReadMapElemValue() { f.d.mapElemValue() }
  216. // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
  217. func (f genHelperDecoder) DecDecodeFloat32() float32 { return f.d.decodeFloat32() }
  218. // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
  219. func (f genHelperDecoder) DecCheckBreak() bool { return f.d.checkBreak() }