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.
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 {
118 // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
119 func (f genHelperEncoder) EncBinary() bool {
120 return f.e.be // f.e.hh.isBinaryEncoding()
123 // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
124 func (f genHelperEncoder) IsJSONHandle() bool {
128 // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
129 func (f genHelperEncoder) EncFallback(iv interface{}) {
130 // println(">>>>>>>>> EncFallback")
131 // f.e.encodeI(iv, false, false)
132 f.e.encodeValue(reflect.ValueOf(iv), nil, false)
135 // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
136 func (f genHelperEncoder) EncTextMarshal(iv encoding.TextMarshaler) {
137 bs, fnerr := iv.MarshalText()
138 f.e.marshal(bs, fnerr, false, cUTF8)
141 // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
142 func (f genHelperEncoder) EncJSONMarshal(iv jsonMarshaler) {
143 bs, fnerr := iv.MarshalJSON()
144 f.e.marshal(bs, fnerr, true, cUTF8)
147 // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
148 func (f genHelperEncoder) EncBinaryMarshal(iv encoding.BinaryMarshaler) {
149 bs, fnerr := iv.MarshalBinary()
150 f.e.marshal(bs, fnerr, false, cRAW)
153 // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
154 func (f genHelperEncoder) EncRaw(iv Raw) { f.e.rawBytes(iv) }
156 // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
158 // Deprecated: builtin no longer supported - so we make this method a no-op,
159 // but leave in-place so that old generated files continue to work without regeneration.
160 func (f genHelperEncoder) TimeRtidIfBinc() (v uintptr) { return }
162 // func (f genHelperEncoder) TimeRtidIfBinc() uintptr {
163 // if _, ok := f.e.hh.(*BincHandle); ok {
168 // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
169 func (f genHelperEncoder) I2Rtid(v interface{}) uintptr {
173 // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
174 func (f genHelperEncoder) Extension(rtid uintptr) (xfn *extTypeTagFn) {
175 return f.e.h.getExt(rtid)
178 // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
179 func (f genHelperEncoder) EncExtension(v interface{}, xfFn *extTypeTagFn) {
180 f.e.e.EncodeExt(v, xfFn.tag, xfFn.ext, f.e)
183 // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
184 func (f genHelperEncoder) WriteStr(s string) {
188 // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
190 // Deprecated: No longer used,
191 // but leave in-place so that old generated files continue to work without regeneration.
192 func (f genHelperEncoder) HasExtensions() bool {
193 return len(f.e.h.extHandle) != 0
196 // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
198 // Deprecated: No longer used,
199 // but leave in-place so that old generated files continue to work without regeneration.
200 func (f genHelperEncoder) EncExt(v interface{}) (r bool) {
201 if xfFn := f.e.h.getExt(i2rtid(v)); xfFn != nil {
202 f.e.e.EncodeExt(v, xfFn.tag, xfFn.ext, f.e)
208 // ---------------- DECODER FOLLOWS -----------------
210 // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
211 func (f genHelperDecoder) DecBasicHandle() *BasicHandle {
215 // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
216 func (f genHelperDecoder) DecBinary() bool {
217 return f.d.be // f.d.hh.isBinaryEncoding()
220 // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
221 func (f genHelperDecoder) DecSwallow() { f.d.swallow() }
223 // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
224 func (f genHelperDecoder) DecScratchBuffer() []byte {
228 // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
229 func (f genHelperDecoder) DecScratchArrayBuffer() *[decScratchByteArrayLen]byte {
233 // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
234 func (f genHelperDecoder) DecFallback(iv interface{}, chkPtr bool) {
235 // println(">>>>>>>>> DecFallback")
236 rv := reflect.ValueOf(iv)
238 rv = f.d.ensureDecodeable(rv)
240 f.d.decodeValue(rv, nil, false)
241 // f.d.decodeValueFallback(rv)
244 // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
245 func (f genHelperDecoder) DecSliceHelperStart() (decSliceHelper, int) {
246 return f.d.decSliceHelperStart()
249 // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
250 func (f genHelperDecoder) DecStructFieldNotFound(index int, name string) {
251 f.d.structFieldNotFound(index, name)
254 // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
255 func (f genHelperDecoder) DecArrayCannotExpand(sliceLen, streamLen int) {
256 f.d.arrayCannotExpand(sliceLen, streamLen)
259 // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
260 func (f genHelperDecoder) DecTextUnmarshal(tm encoding.TextUnmarshaler) {
261 fnerr := tm.UnmarshalText(f.d.d.DecodeStringAsBytes())
267 // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
268 func (f genHelperDecoder) DecJSONUnmarshal(tm jsonUnmarshaler) {
269 // bs := f.dd.DecodeStringAsBytes()
270 // grab the bytes to be read, as UnmarshalJSON needs the full JSON so as to unmarshal it itself.
271 fnerr := tm.UnmarshalJSON(f.d.nextValueBytes())
277 // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
278 func (f genHelperDecoder) DecBinaryUnmarshal(bm encoding.BinaryUnmarshaler) {
279 fnerr := bm.UnmarshalBinary(f.d.d.DecodeBytes(nil, true))
285 // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
286 func (f genHelperDecoder) DecRaw() []byte { return f.d.rawBytes() }
288 // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
290 // Deprecated: builtin no longer supported - so we make this method a no-op,
291 // but leave in-place so that old generated files continue to work without regeneration.
292 func (f genHelperDecoder) TimeRtidIfBinc() (v uintptr) { return }
294 // func (f genHelperDecoder) TimeRtidIfBinc() uintptr {
295 // // Note: builtin is no longer supported - so make this a no-op
296 // if _, ok := f.d.hh.(*BincHandle); ok {
302 // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
303 func (f genHelperDecoder) IsJSONHandle() bool {
307 // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
308 func (f genHelperDecoder) I2Rtid(v interface{}) uintptr {
312 // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
313 func (f genHelperDecoder) Extension(rtid uintptr) (xfn *extTypeTagFn) {
314 return f.d.h.getExt(rtid)
317 // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
318 func (f genHelperDecoder) DecExtension(v interface{}, xfFn *extTypeTagFn) {
319 f.d.d.DecodeExt(v, xfFn.tag, xfFn.ext)
322 // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
324 // Deprecated: No longer used,
325 // but leave in-place so that old generated files continue to work without regeneration.
326 func (f genHelperDecoder) HasExtensions() bool {
327 return len(f.d.h.extHandle) != 0
330 // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
332 // Deprecated: No longer used,
333 // but leave in-place so that old generated files continue to work without regeneration.
334 func (f genHelperDecoder) DecExt(v interface{}) (r bool) {
335 if xfFn := f.d.h.getExt(i2rtid(v)); xfFn != nil {
336 f.d.d.DecodeExt(v, xfFn.tag, xfFn.ext)
342 // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
343 func (f genHelperDecoder) DecInferLen(clen, maxlen, unit int) (rvlen int) {
344 return decInferLen(clen, maxlen, unit)
347 // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
349 // Deprecated: no longer used,
350 // but leave in-place so that old generated files continue to work without regeneration.
351 func (f genHelperDecoder) StringView(v []byte) string { return stringView(v) }