1// comment this out // + build ignore
2
3// Copyright (c) 2012-2018 Ugorji Nwoke. All rights reserved.
4// Use of this source code is governed by a MIT license found in the LICENSE file.
5
6// Code generated from gen-helper.go.tmpl - DO NOT EDIT.
7
8package codec
9
10import (
11	"encoding"
12	"reflect"
13	"strconv"
14)
15
16// GenVersion is the current version of codecgen.
17const GenVersion = {{ .Version }}
18
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.
22//
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).
25//
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.
28
29// GenHelperEncoder is exported so that it can be used externally by codecgen.
30//
31// Library users: DO NOT USE IT DIRECTLY. IT WILL CHANGE CONTINOUSLY WITHOUT NOTICE.
32func GenHelperEncoder(e *Encoder) (ge genHelperEncoder, ee genHelperEncDriver) {
33	ge = genHelperEncoder{e: e}
34	ee = genHelperEncDriver{encDriver: e.e}
35	return
36}
37
38// GenHelperDecoder is exported so that it can be used externally by codecgen.
39//
40// Library users: DO NOT USE IT DIRECTLY. IT WILL CHANGE CONTINOUSLY WITHOUT NOTICE.
41func GenHelperDecoder(d *Decoder) (gd genHelperDecoder, dd genHelperDecDriver) {
42	gd = genHelperDecoder{d: d}
43	dd = genHelperDecDriver{decDriver: d.d}
44	return
45}
46
47type genHelperEncDriver struct {
48	encDriver
49}
50
51func (x genHelperEncDriver) EncodeBuiltin(rt uintptr, v interface{}) {}
52func (x genHelperEncDriver) EncStructFieldKey(keyType valueType, s string) {
53	var m must
54	if keyType == valueTypeString {
55		x.encDriver.EncodeStringEnc(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)))
62	}
63	// encStructFieldKey(x.encDriver, keyType, s)
64}
65func (x genHelperEncDriver) EncodeSymbol(s string) {
66	x.encDriver.EncodeStringEnc(cUTF8, s)
67}
68
69type genHelperDecDriver struct {
70	decDriver
71	C checkOverflow
72}
73
74func (x genHelperDecDriver) DecodeBuiltin(rt uintptr, v interface{}) {}
75func (x genHelperDecDriver) DecStructFieldKey(keyType valueType, buf *[decScratchByteArrayLen]byte) []byte {
76	return decStructFieldKey(x.decDriver, keyType, buf)
77}
78func (x genHelperDecDriver) DecodeInt(bitsize uint8) (i int64) {
79	return x.C.IntV(x.decDriver.DecodeInt64(), bitsize)
80}
81func (x genHelperDecDriver) DecodeUint(bitsize uint8) (ui uint64) {
82	return x.C.UintV(x.decDriver.DecodeUint64(), bitsize)
83}
84func (x genHelperDecDriver) DecodeFloat(chkOverflow32 bool) (f float64) {
85	f = x.DecodeFloat64()
86	if chkOverflow32 && chkOvf.Float32(f) {
87		panicv.errorf("float32 overflow: %v", f)
88	}
89	return
90}
91func (x genHelperDecDriver) DecodeFloat32As64() (f float64) {
92	f = x.DecodeFloat64()
93	if chkOvf.Float32(f) {
94		panicv.errorf("float32 overflow: %v", f)
95	}
96	return
97}
98
99// FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
100type genHelperEncoder struct {
101	M must
102	e *Encoder
103	F fastpathT
104}
105
106// FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
107type genHelperDecoder struct {
108	C checkOverflow
109	d *Decoder
110	F fastpathT
111}
112
113// FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
114func (f genHelperEncoder) EncBasicHandle() *BasicHandle {
115	return f.e.h
116}
117// FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
118func (f genHelperEncoder) EncBinary() bool {
119	return f.e.be // f.e.hh.isBinaryEncoding()
120}
121// FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
122func (f genHelperEncoder) IsJSONHandle() bool {
123	return f.e.js
124}
125// FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
126func (f genHelperEncoder) EncFallback(iv interface{}) {
127	// println(">>>>>>>>> EncFallback")
128	// f.e.encodeI(iv, false, false)
129	f.e.encodeValue(reflect.ValueOf(iv), nil, false)
130}
131// FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
132func (f genHelperEncoder) EncTextMarshal(iv encoding.TextMarshaler) {
133	bs, fnerr := iv.MarshalText()
134	f.e.marshalUtf8(bs, fnerr)
135}
136// FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
137func (f genHelperEncoder) EncJSONMarshal(iv jsonMarshaler) {
138	bs, fnerr := iv.MarshalJSON()
139	f.e.marshalAsis(bs, fnerr)
140}
141// FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
142func (f genHelperEncoder) EncBinaryMarshal(iv encoding.BinaryMarshaler) {
143	bs, fnerr := iv.MarshalBinary()
144	f.e.marshalRaw(bs, fnerr)
145}
146// FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
147func (f genHelperEncoder) EncRaw(iv Raw) { f.e.rawBytes(iv) }
148// FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
149//
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.
152func (f genHelperEncoder) TimeRtidIfBinc() (v uintptr) { return }
153// func (f genHelperEncoder) TimeRtidIfBinc() uintptr {
154// 	if _, ok := f.e.hh.(*BincHandle); ok {
155// 		return timeTypId
156// 	}
157// }
158
159// FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
160func (f genHelperEncoder) I2Rtid(v interface{}) uintptr {
161	return i2rtid(v)
162}
163// FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
164func (f genHelperEncoder) Extension(rtid uintptr) (xfn *extTypeTagFn) {
165	return f.e.h.getExt(rtid)
166}
167// FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
168func (f genHelperEncoder) EncExtension(v interface{}, xfFn *extTypeTagFn) {
169	f.e.e.EncodeExt(v, xfFn.tag, xfFn.ext, f.e)
170}
171// FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
172func (f genHelperEncoder) WriteStr(s string) {
173	f.e.w.writestr(s)
174}
175// FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
176//
177// Deprecated: No longer used,
178// but leave in-place so that old generated files continue to work without regeneration.
179func (f genHelperEncoder) HasExtensions() bool {
180	return len(f.e.h.extHandle) != 0
181}
182// FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
183//
184// Deprecated: No longer used,
185// but leave in-place so that old generated files continue to work without regeneration.
186func (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)
189		return true
190	}
191	return false
192}
193
194// ---------------- DECODER FOLLOWS -----------------
195
196// FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
197func (f genHelperDecoder) DecBasicHandle() *BasicHandle {
198	return f.d.h
199}
200// FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
201func (f genHelperDecoder) DecBinary() bool {
202     return f.d.be // f.d.hh.isBinaryEncoding()
203}
204// FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
205func (f genHelperDecoder) DecSwallow() { f.d.swallow() }
206// FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
207func (f genHelperDecoder) DecScratchBuffer() []byte {
208	return f.d.b[:]
209}
210// FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
211func (f genHelperDecoder) DecScratchArrayBuffer() *[decScratchByteArrayLen]byte {
212	return &f.d.b
213}
214// FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
215func (f genHelperDecoder) DecFallback(iv interface{}, chkPtr bool) {
216	// println(">>>>>>>>> DecFallback")
217	rv := reflect.ValueOf(iv)
218	if chkPtr {
219		rv = f.d.ensureDecodeable(rv)
220	}
221	f.d.decodeValue(rv, nil, false)
222	// f.d.decodeValueFallback(rv)
223}
224// FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
225func (f genHelperDecoder) DecSliceHelperStart() (decSliceHelper, int) {
226	return f.d.decSliceHelperStart()
227}
228// FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
229func (f genHelperDecoder) DecStructFieldNotFound(index int, name string) {
230	f.d.structFieldNotFound(index, name)
231}
232// FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
233func (f genHelperDecoder) DecArrayCannotExpand(sliceLen, streamLen int) {
234	f.d.arrayCannotExpand(sliceLen, streamLen)
235}
236// FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
237func (f genHelperDecoder) DecTextUnmarshal(tm encoding.TextUnmarshaler) {
238	fnerr := tm.UnmarshalText(f.d.d.DecodeStringAsBytes())
239	if fnerr != nil {
240		panic(fnerr)
241	}
242}
243// FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
244func (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())
248	if fnerr != nil {
249		panic(fnerr)
250	}
251}
252// FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
253func (f genHelperDecoder) DecBinaryUnmarshal(bm encoding.BinaryUnmarshaler) {
254	fnerr := bm.UnmarshalBinary(f.d.d.DecodeBytes(nil, true))
255	if fnerr != nil {
256		panic(fnerr)
257	}
258}
259// FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
260func (f genHelperDecoder) DecRaw() []byte {	return f.d.rawBytes() }
261// FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
262//
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.
265func (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 {
269// 		return timeTypId
270// 	}
271// 	return 0
272// }
273
274// FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
275func (f genHelperDecoder) IsJSONHandle() bool {
276	return f.d.js
277}
278// FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
279func (f genHelperDecoder) I2Rtid(v interface{}) uintptr {
280	return i2rtid(v)
281}
282// FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
283func (f genHelperDecoder) Extension(rtid uintptr) (xfn *extTypeTagFn) {
284	return f.d.h.getExt(rtid)
285}
286// FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
287func (f genHelperDecoder) DecExtension(v interface{}, xfFn *extTypeTagFn) {
288	f.d.d.DecodeExt(v, xfFn.tag, xfFn.ext)
289}
290// FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
291//
292// Deprecated: No longer used,
293// but leave in-place so that old generated files continue to work without regeneration.
294func (f genHelperDecoder) HasExtensions() bool {
295	return len(f.d.h.extHandle) != 0
296}
297// FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
298//
299// Deprecated: No longer used,
300// but leave in-place so that old generated files continue to work without regeneration.
301func (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)
304		return true
305	}
306	return false
307}
308// FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
309func (f genHelperDecoder) DecInferLen(clen, maxlen, unit int) (rvlen int) {
310	return decInferLen(clen, maxlen, unit)
311}
312// FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
313//
314// Deprecated: no longer used,
315// but leave in-place so that old generated files continue to work without regeneration.
316func (f genHelperDecoder) StringView(v []byte) string { return stringView(v) }
317
318