gen-helper.go.tmpl 10 KB

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