gen-helper.generated.go 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242
  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, c_UTF8)
  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, c_UTF8)
  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, c_RAW)
  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. if _, ok := f.e.hh.(*BincHandle); ok {
  79. return timeTypId
  80. }
  81. return 0
  82. }
  83. // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
  84. func (f genHelperEncoder) IsJSONHandle() bool {
  85. return f.e.cf.js
  86. }
  87. // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
  88. func (f genHelperEncoder) HasExtensions() bool {
  89. return len(f.e.h.extHandle) != 0
  90. }
  91. // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
  92. func (f genHelperEncoder) EncExt(v interface{}) (r bool) {
  93. rt := reflect.TypeOf(v)
  94. if rt.Kind() == reflect.Ptr {
  95. rt = rt.Elem()
  96. }
  97. rtid := rt2id(rt)
  98. if xfFn := f.e.h.getExt(rtid); xfFn != nil {
  99. f.e.e.EncodeExt(v, xfFn.tag, xfFn.ext, f.e)
  100. return true
  101. }
  102. return false
  103. }
  104. // ---------------- DECODER FOLLOWS -----------------
  105. // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
  106. func (f genHelperDecoder) DecBasicHandle() *BasicHandle {
  107. return f.d.h
  108. }
  109. // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
  110. func (f genHelperDecoder) DecBinary() bool {
  111. return f.d.be // f.d.hh.isBinaryEncoding()
  112. }
  113. // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
  114. func (f genHelperDecoder) DecSwallow() {
  115. f.d.swallow()
  116. }
  117. // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
  118. func (f genHelperDecoder) DecScratchBuffer() []byte {
  119. return f.d.b[:]
  120. }
  121. // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
  122. func (f genHelperDecoder) DecFallback(iv interface{}, chkPtr bool) {
  123. // println(">>>>>>>>> DecFallback")
  124. rv := reflect.ValueOf(iv)
  125. if chkPtr {
  126. rv = f.d.ensureDecodeable(rv)
  127. }
  128. f.d.decodeValue(rv, nil, false)
  129. // f.d.decodeValueFallback(rv)
  130. }
  131. // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
  132. func (f genHelperDecoder) DecSliceHelperStart() (decSliceHelper, int) {
  133. return f.d.decSliceHelperStart()
  134. }
  135. // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
  136. func (f genHelperDecoder) DecStructFieldNotFound(index int, name string) {
  137. f.d.structFieldNotFound(index, name)
  138. }
  139. // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
  140. func (f genHelperDecoder) DecArrayCannotExpand(sliceLen, streamLen int) {
  141. f.d.arrayCannotExpand(sliceLen, streamLen)
  142. }
  143. // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
  144. func (f genHelperDecoder) DecTextUnmarshal(tm encoding.TextUnmarshaler) {
  145. fnerr := tm.UnmarshalText(f.d.d.DecodeStringAsBytes())
  146. if fnerr != nil {
  147. panic(fnerr)
  148. }
  149. }
  150. // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
  151. func (f genHelperDecoder) DecJSONUnmarshal(tm jsonUnmarshaler) {
  152. // bs := f.dd.DecodeStringAsBytes()
  153. // grab the bytes to be read, as UnmarshalJSON needs the full JSON so as to unmarshal it itself.
  154. fnerr := tm.UnmarshalJSON(f.d.nextValueBytes())
  155. if fnerr != nil {
  156. panic(fnerr)
  157. }
  158. }
  159. // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
  160. func (f genHelperDecoder) DecBinaryUnmarshal(bm encoding.BinaryUnmarshaler) {
  161. fnerr := bm.UnmarshalBinary(f.d.d.DecodeBytes(nil, true))
  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) DecRaw() []byte {
  168. return f.d.rawBytes()
  169. }
  170. // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
  171. func (f genHelperDecoder) TimeRtidIfBinc() uintptr {
  172. if _, ok := f.d.hh.(*BincHandle); ok {
  173. return timeTypId
  174. }
  175. return 0
  176. }
  177. // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
  178. func (f genHelperDecoder) IsJSONHandle() bool {
  179. return f.d.js
  180. }
  181. // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
  182. func (f genHelperDecoder) HasExtensions() bool {
  183. return len(f.d.h.extHandle) != 0
  184. }
  185. // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
  186. func (f genHelperDecoder) DecExt(v interface{}) (r bool) {
  187. rt := reflect.TypeOf(v).Elem()
  188. rtid := rt2id(rt)
  189. if xfFn := f.d.h.getExt(rtid); xfFn != nil {
  190. f.d.d.DecodeExt(v, xfFn.tag, xfFn.ext)
  191. return true
  192. }
  193. return false
  194. }
  195. // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
  196. func (f genHelperDecoder) DecInferLen(clen, maxlen, unit int) (rvlen int) {
  197. return decInferLen(clen, maxlen, unit)
  198. }
  199. // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
  200. func (f genHelperDecoder) StringView(v []byte) string {
  201. return stringView(v)
  202. }