gen-helper.generated.go 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233
  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 continously 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) TimeRtidIfBinc() uintptr {
  72. if _, ok := f.e.hh.(*BincHandle); ok {
  73. return timeTypId
  74. }
  75. return 0
  76. }
  77. // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
  78. func (f genHelperEncoder) IsJSONHandle() bool {
  79. return f.e.js
  80. }
  81. // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
  82. func (f genHelperEncoder) HasExtensions() bool {
  83. return len(f.e.h.extHandle) != 0
  84. }
  85. // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
  86. func (f genHelperEncoder) EncExt(v interface{}) (r bool) {
  87. rt := reflect.TypeOf(v)
  88. if rt.Kind() == reflect.Ptr {
  89. rt = rt.Elem()
  90. }
  91. rtid := reflect.ValueOf(rt).Pointer()
  92. if xfFn := f.e.h.getExt(rtid); xfFn != nil {
  93. f.e.e.EncodeExt(v, xfFn.tag, xfFn.ext, f.e)
  94. return true
  95. }
  96. return false
  97. }
  98. // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
  99. func (f genHelperEncoder) EncSendContainerState(c containerState) {
  100. if f.e.cr != nil {
  101. f.e.cr.sendContainerState(c)
  102. }
  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. f.d.decodeI(iv, chkPtr, false, false, false)
  125. }
  126. // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
  127. func (f genHelperDecoder) DecSliceHelperStart() (decSliceHelper, int) {
  128. return f.d.decSliceHelperStart()
  129. }
  130. // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
  131. func (f genHelperDecoder) DecStructFieldNotFound(index int, name string) {
  132. f.d.structFieldNotFound(index, name)
  133. }
  134. // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
  135. func (f genHelperDecoder) DecArrayCannotExpand(sliceLen, streamLen int) {
  136. f.d.arrayCannotExpand(sliceLen, streamLen)
  137. }
  138. // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
  139. func (f genHelperDecoder) DecTextUnmarshal(tm encoding.TextUnmarshaler) {
  140. fnerr := tm.UnmarshalText(f.d.d.DecodeBytes(f.d.b[:], true, true))
  141. if fnerr != nil {
  142. panic(fnerr)
  143. }
  144. }
  145. // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
  146. func (f genHelperDecoder) DecJSONUnmarshal(tm jsonUnmarshaler) {
  147. // bs := f.dd.DecodeBytes(f.d.b[:], true, true)
  148. // grab the bytes to be read, as UnmarshalJSON needs the full JSON so as to unmarshal it itself.
  149. fnerr := tm.UnmarshalJSON(f.d.nextValueBytes())
  150. if fnerr != nil {
  151. panic(fnerr)
  152. }
  153. }
  154. // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
  155. func (f genHelperDecoder) DecBinaryUnmarshal(bm encoding.BinaryUnmarshaler) {
  156. fnerr := bm.UnmarshalBinary(f.d.d.DecodeBytes(nil, false, true))
  157. if fnerr != nil {
  158. panic(fnerr)
  159. }
  160. }
  161. // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
  162. func (f genHelperDecoder) TimeRtidIfBinc() uintptr {
  163. if _, ok := f.d.hh.(*BincHandle); ok {
  164. return timeTypId
  165. }
  166. return 0
  167. }
  168. // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
  169. func (f genHelperDecoder) IsJSONHandle() bool {
  170. return f.d.js
  171. }
  172. // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
  173. func (f genHelperDecoder) HasExtensions() bool {
  174. return len(f.d.h.extHandle) != 0
  175. }
  176. // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
  177. func (f genHelperDecoder) DecExt(v interface{}) (r bool) {
  178. rt := reflect.TypeOf(v).Elem()
  179. rtid := reflect.ValueOf(rt).Pointer()
  180. if xfFn := f.d.h.getExt(rtid); xfFn != nil {
  181. f.d.d.DecodeExt(v, xfFn.tag, xfFn.ext)
  182. return true
  183. }
  184. return false
  185. }
  186. // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
  187. func (f genHelperDecoder) DecInferLen(clen, maxlen, unit int) (rvlen int, truncated bool) {
  188. return decInferLen(clen, maxlen, unit)
  189. }
  190. // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
  191. func (f genHelperDecoder) DecSendContainerState(c containerState) {
  192. if f.d.cr != nil {
  193. f.d.cr.sendContainerState(c)
  194. }
  195. }