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)
14
15// GenVersion is the current version of codecgen.
16const GenVersion = 10
17
18// This file is used to generate helper code for codecgen.
19// The values here i.e. genHelper(En|De)coder are not to be used directly by
20// library users. They WILL change continuously and without notice.
21//
22// To help enforce this, we create an unexported type with exported members.
23// The only way to get the type is via the one exported type that we control (somewhat).
24//
25// When static codecs are created for types, they will use this value
26// to perform encoding or decoding of primitives or known slice or map types.
27
28// GenHelperEncoder is exported so that it can be used externally by codecgen.
29//
30// Library users: DO NOT USE IT DIRECTLY. IT WILL CHANGE CONTINOUSLY WITHOUT NOTICE.
31func GenHelperEncoder(e *Encoder) (ge genHelperEncoder, ee genHelperEncDriver) {
32	ge = genHelperEncoder{e: e}
33	ee = genHelperEncDriver{encDriver: e.e}
34	return
35}
36
37// GenHelperDecoder is exported so that it can be used externally by codecgen.
38//
39// Library users: DO NOT USE IT DIRECTLY. IT WILL CHANGE CONTINOUSLY WITHOUT NOTICE.
40func GenHelperDecoder(d *Decoder) (gd genHelperDecoder, dd genHelperDecDriver) {
41	gd = genHelperDecoder{d: d}
42	dd = genHelperDecDriver{decDriver: d.d}
43	return
44}
45
46type genHelperEncDriver struct {
47	encDriver
48}
49
50func (x genHelperEncDriver) EncodeBuiltin(rt uintptr, v interface{}) {}
51func (x genHelperEncDriver) EncStructFieldKey(keyType valueType, s string) {
52	encStructFieldKey(s, x.encDriver, nil, keyType, false, false)
53}
54func (x genHelperEncDriver) EncodeSymbol(s string) {
55	x.encDriver.EncodeStringEnc(cUTF8, s)
56}
57
58type genHelperDecDriver struct {
59	decDriver
60	C checkOverflow
61}
62
63func (x genHelperDecDriver) DecodeBuiltin(rt uintptr, v interface{}) {}
64func (x genHelperDecDriver) DecStructFieldKey(keyType valueType, buf *[decScratchByteArrayLen]byte) []byte {
65	return decStructFieldKey(x.decDriver, keyType, buf)
66}
67func (x genHelperDecDriver) DecodeInt(bitsize uint8) (i int64) {
68	return x.C.IntV(x.decDriver.DecodeInt64(), bitsize)
69}
70func (x genHelperDecDriver) DecodeUint(bitsize uint8) (ui uint64) {
71	return x.C.UintV(x.decDriver.DecodeUint64(), bitsize)
72}
73func (x genHelperDecDriver) DecodeFloat(chkOverflow32 bool) (f float64) {
74	f = x.DecodeFloat64()
75	if chkOverflow32 && chkOvf.Float32(f) {
76		panicv.errorf("float32 overflow: %v", f)
77	}
78	return
79}
80func (x genHelperDecDriver) DecodeFloat32As64() (f float64) {
81	f = x.DecodeFloat64()
82	if chkOvf.Float32(f) {
83		panicv.errorf("float32 overflow: %v", f)
84	}
85	return
86}
87
88// FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
89type genHelperEncoder struct {
90	M must
91	e *Encoder
92	F fastpathT
93}
94
95// FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
96type genHelperDecoder struct {
97	C checkOverflow
98	d *Decoder
99	F fastpathT
100}
101
102// FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
103func (f genHelperEncoder) EncBasicHandle() *BasicHandle {
104	return f.e.h
105}
106
107// FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
108func (f genHelperEncoder) EncBinary() bool {
109	return f.e.be // f.e.hh.isBinaryEncoding()
110}
111
112// FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
113func (f genHelperEncoder) IsJSONHandle() bool {
114	return f.e.js
115}
116
117// FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
118func (f genHelperEncoder) EncFallback(iv interface{}) {
119	// println(">>>>>>>>> EncFallback")
120	// f.e.encodeI(iv, false, false)
121	f.e.encodeValue(reflect.ValueOf(iv), nil, false)
122}
123
124// FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
125func (f genHelperEncoder) EncTextMarshal(iv encoding.TextMarshaler) {
126	bs, fnerr := iv.MarshalText()
127	f.e.marshalUtf8(bs, fnerr)
128}
129
130// FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
131func (f genHelperEncoder) EncJSONMarshal(iv jsonMarshaler) {
132	bs, fnerr := iv.MarshalJSON()
133	f.e.marshalAsis(bs, fnerr)
134}
135
136// FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
137func (f genHelperEncoder) EncBinaryMarshal(iv encoding.BinaryMarshaler) {
138	bs, fnerr := iv.MarshalBinary()
139	f.e.marshalRaw(bs, fnerr)
140}
141
142// FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
143func (f genHelperEncoder) EncRaw(iv Raw) { f.e.rawBytes(iv) }
144
145// FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
146//
147// Deprecated: builtin no longer supported - so we make this method a no-op,
148// but leave in-place so that old generated files continue to work without regeneration.
149func (f genHelperEncoder) TimeRtidIfBinc() (v uintptr) { return }
150
151// func (f genHelperEncoder) TimeRtidIfBinc() uintptr {
152// 	if _, ok := f.e.hh.(*BincHandle); ok {
153// 		return timeTypId
154// 	}
155// }
156
157// FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
158func (f genHelperEncoder) I2Rtid(v interface{}) uintptr {
159	return i2rtid(v)
160}
161
162// FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
163func (f genHelperEncoder) Extension(rtid uintptr) (xfn *extTypeTagFn) {
164	return f.e.h.getExt(rtid)
165}
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
172// FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
173func (f genHelperEncoder) WriteStr(s string) {
174	f.e.w.writestr(s)
175}
176
177// FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
178func (f genHelperEncoder) BytesView(v string) []byte { return bytesView(v) }
179
180// FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
181//
182// Deprecated: No longer used,
183// but leave in-place so that old generated files continue to work without regeneration.
184func (f genHelperEncoder) HasExtensions() bool {
185	return len(f.e.h.extHandle) != 0
186}
187
188// FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
189//
190// Deprecated: No longer used,
191// but leave in-place so that old generated files continue to work without regeneration.
192func (f genHelperEncoder) EncExt(v interface{}) (r bool) {
193	if xfFn := f.e.h.getExt(i2rtid(v)); xfFn != nil {
194		f.e.e.EncodeExt(v, xfFn.tag, xfFn.ext, f.e)
195		return true
196	}
197	return false
198}
199
200// ---------------- DECODER FOLLOWS -----------------
201
202// FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
203func (f genHelperDecoder) DecBasicHandle() *BasicHandle {
204	return f.d.h
205}
206
207// FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
208func (f genHelperDecoder) DecBinary() bool {
209	return f.d.be // f.d.hh.isBinaryEncoding()
210}
211
212// FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
213func (f genHelperDecoder) DecSwallow() { f.d.swallow() }
214
215// FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
216func (f genHelperDecoder) DecScratchBuffer() []byte {
217	return f.d.b[:]
218}
219
220// FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
221func (f genHelperDecoder) DecScratchArrayBuffer() *[decScratchByteArrayLen]byte {
222	return &f.d.b
223}
224
225// FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
226func (f genHelperDecoder) DecFallback(iv interface{}, chkPtr bool) {
227	// println(">>>>>>>>> DecFallback")
228	rv := reflect.ValueOf(iv)
229	if chkPtr {
230		rv = f.d.ensureDecodeable(rv)
231	}
232	f.d.decodeValue(rv, nil, false)
233	// f.d.decodeValueFallback(rv)
234}
235
236// FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
237func (f genHelperDecoder) DecSliceHelperStart() (decSliceHelper, int) {
238	return f.d.decSliceHelperStart()
239}
240
241// FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
242func (f genHelperDecoder) DecStructFieldNotFound(index int, name string) {
243	f.d.structFieldNotFound(index, name)
244}
245
246// FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
247func (f genHelperDecoder) DecArrayCannotExpand(sliceLen, streamLen int) {
248	f.d.arrayCannotExpand(sliceLen, streamLen)
249}
250
251// FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
252func (f genHelperDecoder) DecTextUnmarshal(tm encoding.TextUnmarshaler) {
253	fnerr := tm.UnmarshalText(f.d.d.DecodeStringAsBytes())
254	if fnerr != nil {
255		panic(fnerr)
256	}
257}
258
259// FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
260func (f genHelperDecoder) DecJSONUnmarshal(tm jsonUnmarshaler) {
261	// bs := f.dd.DecodeStringAsBytes()
262	// grab the bytes to be read, as UnmarshalJSON needs the full JSON so as to unmarshal it itself.
263	fnerr := tm.UnmarshalJSON(f.d.nextValueBytes())
264	if fnerr != nil {
265		panic(fnerr)
266	}
267}
268
269// FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
270func (f genHelperDecoder) DecBinaryUnmarshal(bm encoding.BinaryUnmarshaler) {
271	fnerr := bm.UnmarshalBinary(f.d.d.DecodeBytes(nil, true))
272	if fnerr != nil {
273		panic(fnerr)
274	}
275}
276
277// FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
278func (f genHelperDecoder) DecRaw() []byte { return f.d.rawBytes() }
279
280// FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
281//
282// Deprecated: builtin no longer supported - so we make this method a no-op,
283// but leave in-place so that old generated files continue to work without regeneration.
284func (f genHelperDecoder) TimeRtidIfBinc() (v uintptr) { return }
285
286// func (f genHelperDecoder) TimeRtidIfBinc() uintptr {
287// 	// Note: builtin is no longer supported - so make this a no-op
288// 	if _, ok := f.d.hh.(*BincHandle); ok {
289// 		return timeTypId
290// 	}
291// 	return 0
292// }
293
294// FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
295func (f genHelperDecoder) IsJSONHandle() bool {
296	return f.d.js
297}
298
299// FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
300func (f genHelperDecoder) I2Rtid(v interface{}) uintptr {
301	return i2rtid(v)
302}
303
304// FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
305func (f genHelperDecoder) Extension(rtid uintptr) (xfn *extTypeTagFn) {
306	return f.d.h.getExt(rtid)
307}
308
309// FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
310func (f genHelperDecoder) DecExtension(v interface{}, xfFn *extTypeTagFn) {
311	f.d.d.DecodeExt(v, xfFn.tag, xfFn.ext)
312}
313
314// FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
315//
316// Deprecated: No longer used,
317// but leave in-place so that old generated files continue to work without regeneration.
318func (f genHelperDecoder) HasExtensions() bool {
319	return len(f.d.h.extHandle) != 0
320}
321
322// FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
323//
324// Deprecated: No longer used,
325// but leave in-place so that old generated files continue to work without regeneration.
326func (f genHelperDecoder) DecExt(v interface{}) (r bool) {
327	if xfFn := f.d.h.getExt(i2rtid(v)); xfFn != nil {
328		f.d.d.DecodeExt(v, xfFn.tag, xfFn.ext)
329		return true
330	}
331	return false
332}
333
334// FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
335func (f genHelperDecoder) DecInferLen(clen, maxlen, unit int) (rvlen int) {
336	return decInferLen(clen, maxlen, unit)
337}
338
339// FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
340//
341// Deprecated: no longer used,
342// but leave in-place so that old generated files continue to work without regeneration.
343func (f genHelperDecoder) StringView(v []byte) string { return stringView(v) }
344