gen-helper.generated.go 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244
  1. /* // +build ignore */
  2. // Copyright (c) 2012-2015 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 = 8
  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. // GenHelperEncoder is exported so that it can be used externally by codecgen.
  22. //
  23. // Library users: DO NOT USE IT DIRECTLY. IT WILL CHANGE CONTINOUSLY WITHOUT NOTICE.
  24. func GenHelperEncoder(e *Encoder) (genHelperEncoder, encDriver) {
  25. return genHelperEncoder{e: e}, e.e
  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) (genHelperDecoder, decDriver) {
  31. return genHelperDecoder{d: d}, d.d
  32. }
  33. // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
  34. type genHelperEncoder struct {
  35. e *Encoder
  36. F fastpathT
  37. }
  38. // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
  39. type genHelperDecoder struct {
  40. d *Decoder
  41. F fastpathT
  42. }
  43. // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
  44. func (f genHelperEncoder) EncBasicHandle() *BasicHandle {
  45. return f.e.h
  46. }
  47. // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
  48. func (f genHelperEncoder) EncBinary() bool {
  49. return f.e.cf.be // f.e.hh.isBinaryEncoding()
  50. }
  51. // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
  52. func (f genHelperEncoder) EncFallback(iv interface{}) {
  53. // println(">>>>>>>>> EncFallback")
  54. // f.e.encodeI(iv, false, false)
  55. f.e.encodeValue(reflect.ValueOf(iv), nil, false)
  56. }
  57. // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
  58. func (f genHelperEncoder) EncTextMarshal(iv encoding.TextMarshaler) {
  59. bs, fnerr := iv.MarshalText()
  60. f.e.marshal(bs, fnerr, false, cUTF8)
  61. }
  62. // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
  63. func (f genHelperEncoder) EncJSONMarshal(iv jsonMarshaler) {
  64. bs, fnerr := iv.MarshalJSON()
  65. f.e.marshal(bs, fnerr, true, cUTF8)
  66. }
  67. // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
  68. func (f genHelperEncoder) EncBinaryMarshal(iv encoding.BinaryMarshaler) {
  69. bs, fnerr := iv.MarshalBinary()
  70. f.e.marshal(bs, fnerr, false, cRAW)
  71. }
  72. // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
  73. func (f genHelperEncoder) EncRaw(iv Raw) {
  74. f.e.rawBytes(iv)
  75. }
  76. // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
  77. func (f genHelperEncoder) TimeRtidIfBinc() uintptr {
  78. // // Note: builtin is no longer supported - so make this a no-op
  79. // if _, ok := f.e.hh.(*BincHandle); ok {
  80. // return timeTypId
  81. // }
  82. return 0
  83. }
  84. // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
  85. func (f genHelperEncoder) IsJSONHandle() bool {
  86. return f.e.cf.js
  87. }
  88. // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
  89. func (f genHelperEncoder) HasExtensions() bool {
  90. return len(f.e.h.extHandle) != 0
  91. }
  92. // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
  93. func (f genHelperEncoder) EncExt(v interface{}) (r bool) {
  94. rt := reflect.TypeOf(v)
  95. if rt.Kind() == reflect.Ptr {
  96. rt = rt.Elem()
  97. }
  98. rtid := rt2id(rt)
  99. if xfFn := f.e.h.getExt(rtid); xfFn != nil {
  100. f.e.e.EncodeExt(v, xfFn.tag, xfFn.ext, f.e)
  101. return true
  102. }
  103. return false
  104. }
  105. // ---------------- DECODER FOLLOWS -----------------
  106. // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
  107. func (f genHelperDecoder) DecBasicHandle() *BasicHandle {
  108. return f.d.h
  109. }
  110. // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
  111. func (f genHelperDecoder) DecBinary() bool {
  112. return f.d.be // f.d.hh.isBinaryEncoding()
  113. }
  114. // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
  115. func (f genHelperDecoder) DecSwallow() {
  116. f.d.swallow()
  117. }
  118. // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
  119. func (f genHelperDecoder) DecScratchBuffer() []byte {
  120. return f.d.b[:]
  121. }
  122. // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
  123. func (f genHelperDecoder) DecFallback(iv interface{}, chkPtr bool) {
  124. // println(">>>>>>>>> DecFallback")
  125. rv := reflect.ValueOf(iv)
  126. if chkPtr {
  127. rv = f.d.ensureDecodeable(rv)
  128. }
  129. f.d.decodeValue(rv, nil, false)
  130. // f.d.decodeValueFallback(rv)
  131. }
  132. // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
  133. func (f genHelperDecoder) DecSliceHelperStart() (decSliceHelper, int) {
  134. return f.d.decSliceHelperStart()
  135. }
  136. // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
  137. func (f genHelperDecoder) DecStructFieldNotFound(index int, name string) {
  138. f.d.structFieldNotFound(index, name)
  139. }
  140. // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
  141. func (f genHelperDecoder) DecArrayCannotExpand(sliceLen, streamLen int) {
  142. f.d.arrayCannotExpand(sliceLen, streamLen)
  143. }
  144. // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
  145. func (f genHelperDecoder) DecTextUnmarshal(tm encoding.TextUnmarshaler) {
  146. fnerr := tm.UnmarshalText(f.d.d.DecodeStringAsBytes())
  147. if fnerr != nil {
  148. panic(fnerr)
  149. }
  150. }
  151. // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
  152. func (f genHelperDecoder) DecJSONUnmarshal(tm jsonUnmarshaler) {
  153. // bs := f.dd.DecodeStringAsBytes()
  154. // grab the bytes to be read, as UnmarshalJSON needs the full JSON so as to unmarshal it itself.
  155. fnerr := tm.UnmarshalJSON(f.d.nextValueBytes())
  156. if fnerr != nil {
  157. panic(fnerr)
  158. }
  159. }
  160. // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
  161. func (f genHelperDecoder) DecBinaryUnmarshal(bm encoding.BinaryUnmarshaler) {
  162. fnerr := bm.UnmarshalBinary(f.d.d.DecodeBytes(nil, true))
  163. if fnerr != nil {
  164. panic(fnerr)
  165. }
  166. }
  167. // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
  168. func (f genHelperDecoder) DecRaw() []byte {
  169. return f.d.rawBytes()
  170. }
  171. // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
  172. func (f genHelperDecoder) TimeRtidIfBinc() uintptr {
  173. // // Note: builtin is no longer supported - so make this a no-op
  174. // if _, ok := f.d.hh.(*BincHandle); ok {
  175. // return timeTypId
  176. // }
  177. return 0
  178. }
  179. // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
  180. func (f genHelperDecoder) IsJSONHandle() bool {
  181. return f.d.js
  182. }
  183. // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
  184. func (f genHelperDecoder) HasExtensions() bool {
  185. return len(f.d.h.extHandle) != 0
  186. }
  187. // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
  188. func (f genHelperDecoder) DecExt(v interface{}) (r bool) {
  189. rt := reflect.TypeOf(v).Elem()
  190. rtid := rt2id(rt)
  191. if xfFn := f.d.h.getExt(rtid); xfFn != nil {
  192. f.d.d.DecodeExt(v, xfFn.tag, xfFn.ext)
  193. return true
  194. }
  195. return false
  196. }
  197. // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
  198. func (f genHelperDecoder) DecInferLen(clen, maxlen, unit int) (rvlen int) {
  199. return decInferLen(clen, maxlen, unit)
  200. }
  201. // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
  202. func (f genHelperDecoder) StringView(v []byte) string {
  203. return stringView(v)
  204. }