gen-helper.generated.go 7.6 KB

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