gen-helper.generated.go 7.7 KB

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