3 // Copyright (c) 2012-2015 Ugorji Nwoke. All rights reserved.
4 // Use of this source code is governed by a MIT license found in the LICENSE file.
6 // Code generated from gen-helper.go.tmpl - DO NOT EDIT.
16 // GenVersion is the current version of codecgen.
17 const GenVersion = {{ .Version }}
19 // This file is used to generate helper code for codecgen.
20 // The values here i.e. genHelper(En|De)coder are not to be used directly by
21 // library users. They WILL change continuously and without notice.
23 // To help enforce this, we create an unexported type with exported members.
24 // The only way to get the type is via the one exported type that we control (somewhat).
26 // When static codecs are created for types, they will use this value
27 // to perform encoding or decoding of primitives or known slice or map types.
29 // GenHelperEncoder is exported so that it can be used externally by codecgen.
31 // Library users: DO NOT USE IT DIRECTLY. IT WILL CHANGE CONTINOUSLY WITHOUT NOTICE.
32 func GenHelperEncoder(e *Encoder) (ge genHelperEncoder, ee genHelperEncDriver) {
33 ge = genHelperEncoder{e: e}
34 ee = genHelperEncDriver{encDriver: e.e}
38 // GenHelperDecoder is exported so that it can be used externally by codecgen.
40 // Library users: DO NOT USE IT DIRECTLY. IT WILL CHANGE CONTINOUSLY WITHOUT NOTICE.
41 func GenHelperDecoder(d *Decoder) (gd genHelperDecoder, dd genHelperDecDriver) {
42 gd = genHelperDecoder{d: d}
43 dd = genHelperDecDriver{decDriver: d.d}
47 type genHelperEncDriver struct {
51 func (x genHelperEncDriver) EncodeBuiltin(rt uintptr, v interface{}) {}
52 func (x genHelperEncDriver) EncStructFieldKey(keyType valueType, s string) {
54 if keyType == valueTypeString {
55 x.encDriver.EncodeString(cUTF8, s)
56 } else if keyType == valueTypeInt {
57 x.encDriver.EncodeInt(m.Int(strconv.ParseInt(s, 10, 64)))
58 } else if keyType == valueTypeUint {
59 x.encDriver.EncodeUint(m.Uint(strconv.ParseUint(s, 10, 64)))
60 } else if keyType == valueTypeFloat {
61 x.encDriver.EncodeFloat64(m.Float(strconv.ParseFloat(s, 64)))
63 // encStructFieldKey(x.encDriver, keyType, s)
65 func (x genHelperEncDriver) EncodeSymbol(s string) {
66 x.encDriver.EncodeString(cUTF8, s)
69 type genHelperDecDriver struct {
74 func (x genHelperDecDriver) DecodeBuiltin(rt uintptr, v interface{}) {}
75 func (x genHelperDecDriver) DecStructFieldKey(keyType valueType, buf *[decScratchByteArrayLen]byte) []byte {
76 return decStructFieldKey(x.decDriver, keyType, buf)
78 func (x genHelperDecDriver) DecodeInt(bitsize uint8) (i int64) {
79 return x.C.IntV(x.decDriver.DecodeInt64(), bitsize)
81 func (x genHelperDecDriver) DecodeUint(bitsize uint8) (ui uint64) {
82 return x.C.UintV(x.decDriver.DecodeUint64(), bitsize)
84 func (x genHelperDecDriver) DecodeFloat(chkOverflow32 bool) (f float64) {
86 if chkOverflow32 && chkOvf.Float32(f) {
87 panicv.errorf("float32 overflow: %v", f)
91 func (x genHelperDecDriver) DecodeFloat32As64() (f float64) {
93 if chkOvf.Float32(f) {
94 panicv.errorf("float32 overflow: %v", f)
99 // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
100 type genHelperEncoder struct {
106 // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
107 type genHelperDecoder struct {
113 // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
114 func (f genHelperEncoder) EncBasicHandle() *BasicHandle {
117 // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
118 func (f genHelperEncoder) EncBinary() bool {
119 return f.e.be // f.e.hh.isBinaryEncoding()
121 // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
122 func (f genHelperEncoder) IsJSONHandle() bool {
125 // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
126 func (f genHelperEncoder) EncFallback(iv interface{}) {
127 // println(">>>>>>>>> EncFallback")
128 // f.e.encodeI(iv, false, false)
129 f.e.encodeValue(reflect.ValueOf(iv), nil, false)
131 // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
132 func (f genHelperEncoder) EncTextMarshal(iv encoding.TextMarshaler) {
133 bs, fnerr := iv.MarshalText()
134 f.e.marshal(bs, fnerr, false, cUTF8)
136 // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
137 func (f genHelperEncoder) EncJSONMarshal(iv jsonMarshaler) {
138 bs, fnerr := iv.MarshalJSON()
139 f.e.marshal(bs, fnerr, true, cUTF8)
141 // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
142 func (f genHelperEncoder) EncBinaryMarshal(iv encoding.BinaryMarshaler) {
143 bs, fnerr := iv.MarshalBinary()
144 f.e.marshal(bs, fnerr, false, cRAW)
146 // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
147 func (f genHelperEncoder) EncRaw(iv Raw) { f.e.rawBytes(iv) }
148 // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
150 // Deprecated: builtin no longer supported - so we make this method a no-op,
151 // but leave in-place so that old generated files continue to work without regeneration.
152 func (f genHelperEncoder) TimeRtidIfBinc() (v uintptr) { return }
153 // func (f genHelperEncoder) TimeRtidIfBinc() uintptr {
154 // if _, ok := f.e.hh.(*BincHandle); ok {
159 // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
160 func (f genHelperEncoder) I2Rtid(v interface{}) uintptr {
163 // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
164 func (f genHelperEncoder) Extension(rtid uintptr) (xfn *extTypeTagFn) {
165 return f.e.h.getExt(rtid)
167 // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
168 func (f genHelperEncoder) EncExtension(v interface{}, xfFn *extTypeTagFn) {
169 f.e.e.EncodeExt(v, xfFn.tag, xfFn.ext, f.e)
171 // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
172 func (f genHelperEncoder) WriteStr(s string) {
175 // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
177 // Deprecated: No longer used,
178 // but leave in-place so that old generated files continue to work without regeneration.
179 func (f genHelperEncoder) HasExtensions() bool {
180 return len(f.e.h.extHandle) != 0
182 // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
184 // Deprecated: No longer used,
185 // but leave in-place so that old generated files continue to work without regeneration.
186 func (f genHelperEncoder) EncExt(v interface{}) (r bool) {
187 if xfFn := f.e.h.getExt(i2rtid(v)); xfFn != nil {
188 f.e.e.EncodeExt(v, xfFn.tag, xfFn.ext, f.e)
194 // ---------------- DECODER FOLLOWS -----------------
196 // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
197 func (f genHelperDecoder) DecBasicHandle() *BasicHandle {
200 // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
201 func (f genHelperDecoder) DecBinary() bool {
202 return f.d.be // f.d.hh.isBinaryEncoding()
204 // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
205 func (f genHelperDecoder) DecSwallow() { f.d.swallow() }
206 // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
207 func (f genHelperDecoder) DecScratchBuffer() []byte {
210 // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
211 func (f genHelperDecoder) DecScratchArrayBuffer() *[decScratchByteArrayLen]byte {
214 // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
215 func (f genHelperDecoder) DecFallback(iv interface{}, chkPtr bool) {
216 // println(">>>>>>>>> DecFallback")
217 rv := reflect.ValueOf(iv)
219 rv = f.d.ensureDecodeable(rv)
221 f.d.decodeValue(rv, nil, false)
222 // f.d.decodeValueFallback(rv)
224 // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
225 func (f genHelperDecoder) DecSliceHelperStart() (decSliceHelper, int) {
226 return f.d.decSliceHelperStart()
228 // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
229 func (f genHelperDecoder) DecStructFieldNotFound(index int, name string) {
230 f.d.structFieldNotFound(index, name)
232 // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
233 func (f genHelperDecoder) DecArrayCannotExpand(sliceLen, streamLen int) {
234 f.d.arrayCannotExpand(sliceLen, streamLen)
236 // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
237 func (f genHelperDecoder) DecTextUnmarshal(tm encoding.TextUnmarshaler) {
238 fnerr := tm.UnmarshalText(f.d.d.DecodeStringAsBytes())
243 // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
244 func (f genHelperDecoder) DecJSONUnmarshal(tm jsonUnmarshaler) {
245 // bs := f.dd.DecodeStringAsBytes()
246 // grab the bytes to be read, as UnmarshalJSON needs the full JSON so as to unmarshal it itself.
247 fnerr := tm.UnmarshalJSON(f.d.nextValueBytes())
252 // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
253 func (f genHelperDecoder) DecBinaryUnmarshal(bm encoding.BinaryUnmarshaler) {
254 fnerr := bm.UnmarshalBinary(f.d.d.DecodeBytes(nil, true))
259 // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
260 func (f genHelperDecoder) DecRaw() []byte { return f.d.rawBytes() }
261 // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
263 // Deprecated: builtin no longer supported - so we make this method a no-op,
264 // but leave in-place so that old generated files continue to work without regeneration.
265 func (f genHelperDecoder) TimeRtidIfBinc() (v uintptr) { return }
266 // func (f genHelperDecoder) TimeRtidIfBinc() uintptr {
267 // // Note: builtin is no longer supported - so make this a no-op
268 // if _, ok := f.d.hh.(*BincHandle); ok {
274 // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
275 func (f genHelperDecoder) IsJSONHandle() bool {
278 // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
279 func (f genHelperDecoder) I2Rtid(v interface{}) uintptr {
282 // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
283 func (f genHelperDecoder) Extension(rtid uintptr) (xfn *extTypeTagFn) {
284 return f.d.h.getExt(rtid)
286 // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
287 func (f genHelperDecoder) DecExtension(v interface{}, xfFn *extTypeTagFn) {
288 f.d.d.DecodeExt(v, xfFn.tag, xfFn.ext)
290 // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
292 // Deprecated: No longer used,
293 // but leave in-place so that old generated files continue to work without regeneration.
294 func (f genHelperDecoder) HasExtensions() bool {
295 return len(f.d.h.extHandle) != 0
297 // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
299 // Deprecated: No longer used,
300 // but leave in-place so that old generated files continue to work without regeneration.
301 func (f genHelperDecoder) DecExt(v interface{}) (r bool) {
302 if xfFn := f.d.h.getExt(i2rtid(v)); xfFn != nil {
303 f.d.d.DecodeExt(v, xfFn.tag, xfFn.ext)
308 // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
309 func (f genHelperDecoder) DecInferLen(clen, maxlen, unit int) (rvlen int) {
310 return decInferLen(clen, maxlen, unit)
312 // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
314 // Deprecated: no longer used,
315 // but leave in-place so that old generated files continue to work without regeneration.
316 func (f genHelperDecoder) StringView(v []byte) string { return stringView(v) }