gen-helper.generated.go 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250
  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. // ************************************************************
  5. // DO NOT EDIT.
  6. // THIS FILE IS AUTO-GENERATED from gen-helper.go.tmpl
  7. // ************************************************************
  8. package codec
  9. import (
  10. "encoding"
  11. "reflect"
  12. )
  13. // GenVersion is the current version of codecgen.
  14. const GenVersion = 8
  15. // This file is used to generate helper code for codecgen.
  16. // The values here i.e. genHelper(En|De)coder are not to be used directly by
  17. // library users. They WILL change continuously and without notice.
  18. //
  19. // To help enforce this, we create an unexported type with exported members.
  20. // The only way to get the type is via the one exported type that we control (somewhat).
  21. //
  22. // When static codecs are created for types, they will use this value
  23. // to perform encoding or decoding of primitives or known slice or map types.
  24. // GenHelperEncoder is exported so that it can be used externally by codecgen.
  25. //
  26. // Library users: DO NOT USE IT DIRECTLY. IT WILL CHANGE CONTINOUSLY WITHOUT NOTICE.
  27. func GenHelperEncoder(e *Encoder) (genHelperEncoder, encDriver) {
  28. return genHelperEncoder{e: e}, e.e
  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) (genHelperDecoder, decDriver) {
  34. return genHelperDecoder{d: d}, d.d
  35. }
  36. // Library users: DO NOT USE IT DIRECTLY. IT WILL CHANGE CONTINOUSLY WITHOUT NOTICE.
  37. func BasicHandleDoNotUse(h Handle) *BasicHandle {
  38. return h.getBasicHandle()
  39. }
  40. // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
  41. type genHelperEncoder struct {
  42. e *Encoder
  43. F fastpathT
  44. }
  45. // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
  46. type genHelperDecoder struct {
  47. d *Decoder
  48. F fastpathT
  49. }
  50. // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
  51. func (f genHelperEncoder) EncBasicHandle() *BasicHandle {
  52. return f.e.h
  53. }
  54. // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
  55. func (f genHelperEncoder) EncBinary() bool {
  56. return f.e.cf.be // f.e.hh.isBinaryEncoding()
  57. }
  58. // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
  59. func (f genHelperEncoder) EncFallback(iv interface{}) {
  60. // println(">>>>>>>>> EncFallback")
  61. // f.e.encodeI(iv, false, false)
  62. f.e.encodeValue(reflect.ValueOf(iv), nil, false)
  63. }
  64. // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
  65. func (f genHelperEncoder) EncTextMarshal(iv encoding.TextMarshaler) {
  66. bs, fnerr := iv.MarshalText()
  67. f.e.marshal(bs, fnerr, false, c_UTF8)
  68. }
  69. // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
  70. func (f genHelperEncoder) EncJSONMarshal(iv jsonMarshaler) {
  71. bs, fnerr := iv.MarshalJSON()
  72. f.e.marshal(bs, fnerr, true, c_UTF8)
  73. }
  74. // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
  75. func (f genHelperEncoder) EncBinaryMarshal(iv encoding.BinaryMarshaler) {
  76. bs, fnerr := iv.MarshalBinary()
  77. f.e.marshal(bs, fnerr, false, c_RAW)
  78. }
  79. // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
  80. func (f genHelperEncoder) EncRaw(iv Raw) {
  81. f.e.rawBytes(iv)
  82. }
  83. // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
  84. func (f genHelperEncoder) TimeRtidIfBinc() uintptr {
  85. if _, ok := f.e.hh.(*BincHandle); ok {
  86. return timeTypId
  87. }
  88. return 0
  89. }
  90. // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
  91. func (f genHelperEncoder) IsJSONHandle() bool {
  92. return f.e.cf.js
  93. }
  94. // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
  95. func (f genHelperEncoder) HasExtensions() bool {
  96. return len(f.e.h.extHandle) != 0
  97. }
  98. // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
  99. func (f genHelperEncoder) EncExt(v interface{}) (r bool) {
  100. rt := reflect.TypeOf(v)
  101. if rt.Kind() == reflect.Ptr {
  102. rt = rt.Elem()
  103. }
  104. rtid := rt2id(rt)
  105. if xfFn := f.e.h.getExt(rtid); xfFn != nil {
  106. f.e.e.EncodeExt(v, xfFn.tag, xfFn.ext, f.e)
  107. return true
  108. }
  109. return false
  110. }
  111. // ---------------- DECODER FOLLOWS -----------------
  112. // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
  113. func (f genHelperDecoder) DecBasicHandle() *BasicHandle {
  114. return f.d.h
  115. }
  116. // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
  117. func (f genHelperDecoder) DecBinary() bool {
  118. return f.d.be // f.d.hh.isBinaryEncoding()
  119. }
  120. // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
  121. func (f genHelperDecoder) DecSwallow() {
  122. f.d.swallow()
  123. }
  124. // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
  125. func (f genHelperDecoder) DecScratchBuffer() []byte {
  126. return f.d.b[:]
  127. }
  128. // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
  129. func (f genHelperDecoder) DecFallback(iv interface{}, chkPtr bool) {
  130. // println(">>>>>>>>> DecFallback")
  131. rv := reflect.ValueOf(iv)
  132. if chkPtr {
  133. rv = f.d.ensureDecodeable(rv)
  134. }
  135. f.d.decodeValue(rv, nil, false, false)
  136. // f.d.decodeValueFallback(rv)
  137. }
  138. // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
  139. func (f genHelperDecoder) DecSliceHelperStart() (decSliceHelper, int) {
  140. return f.d.decSliceHelperStart()
  141. }
  142. // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
  143. func (f genHelperDecoder) DecStructFieldNotFound(index int, name string) {
  144. f.d.structFieldNotFound(index, name)
  145. }
  146. // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
  147. func (f genHelperDecoder) DecArrayCannotExpand(sliceLen, streamLen int) {
  148. f.d.arrayCannotExpand(sliceLen, streamLen)
  149. }
  150. // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
  151. func (f genHelperDecoder) DecTextUnmarshal(tm encoding.TextUnmarshaler) {
  152. fnerr := tm.UnmarshalText(f.d.d.DecodeStringAsBytes())
  153. if fnerr != nil {
  154. panic(fnerr)
  155. }
  156. }
  157. // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
  158. func (f genHelperDecoder) DecJSONUnmarshal(tm jsonUnmarshaler) {
  159. // bs := f.dd.DecodeStringAsBytes()
  160. // grab the bytes to be read, as UnmarshalJSON needs the full JSON so as to unmarshal it itself.
  161. fnerr := tm.UnmarshalJSON(f.d.nextValueBytes())
  162. if fnerr != nil {
  163. panic(fnerr)
  164. }
  165. }
  166. // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
  167. func (f genHelperDecoder) DecBinaryUnmarshal(bm encoding.BinaryUnmarshaler) {
  168. fnerr := bm.UnmarshalBinary(f.d.d.DecodeBytes(nil, true))
  169. if fnerr != nil {
  170. panic(fnerr)
  171. }
  172. }
  173. // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
  174. func (f genHelperDecoder) DecRaw() []byte {
  175. return f.d.rawBytes()
  176. }
  177. // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
  178. func (f genHelperDecoder) TimeRtidIfBinc() uintptr {
  179. if _, ok := f.d.hh.(*BincHandle); ok {
  180. return timeTypId
  181. }
  182. return 0
  183. }
  184. // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
  185. func (f genHelperDecoder) IsJSONHandle() bool {
  186. return f.d.js
  187. }
  188. // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
  189. func (f genHelperDecoder) HasExtensions() bool {
  190. return len(f.d.h.extHandle) != 0
  191. }
  192. // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
  193. func (f genHelperDecoder) DecExt(v interface{}) (r bool) {
  194. rt := reflect.TypeOf(v).Elem()
  195. rtid := rt2id(rt)
  196. if xfFn := f.d.h.getExt(rtid); xfFn != nil {
  197. f.d.d.DecodeExt(v, xfFn.tag, xfFn.ext)
  198. return true
  199. }
  200. return false
  201. }
  202. // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
  203. func (f genHelperDecoder) DecInferLen(clen, maxlen, unit int) (rvlen int) {
  204. return decInferLen(clen, maxlen, unit)
  205. }
  206. // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
  207. func (f genHelperDecoder) StringView(v []byte) string {
  208. return stringView(v)
  209. }