gen-helper.generated.go

  1/* // +build ignore */
  2
  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.
  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 = 8
 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(x.encDriver, keyType, s)
 53}
 54func (x genHelperEncDriver) EncodeSymbol(s string) {
 55	x.encDriver.EncodeString(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.marshal(bs, fnerr, false, cUTF8)
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.marshal(bs, fnerr, true, cUTF8)
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.marshal(bs, fnerr, false, cRAW)
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*
173//
174// Deprecated: No longer used,
175// but leave in-place so that old generated files continue to work without regeneration.
176func (f genHelperEncoder) HasExtensions() bool {
177	return len(f.e.h.extHandle) != 0
178}
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) EncExt(v interface{}) (r bool) {
185	if xfFn := f.e.h.getExt(i2rtid(v)); xfFn != nil {
186		f.e.e.EncodeExt(v, xfFn.tag, xfFn.ext, f.e)
187		return true
188	}
189	return false
190}
191
192// ---------------- DECODER FOLLOWS -----------------
193
194// FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
195func (f genHelperDecoder) DecBasicHandle() *BasicHandle {
196	return f.d.h
197}
198
199// FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
200func (f genHelperDecoder) DecBinary() bool {
201	return f.d.be // f.d.hh.isBinaryEncoding()
202}
203
204// FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
205func (f genHelperDecoder) DecSwallow() { f.d.swallow() }
206
207// FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
208func (f genHelperDecoder) DecScratchBuffer() []byte {
209	return f.d.b[:]
210}
211
212// FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
213func (f genHelperDecoder) DecScratchArrayBuffer() *[decScratchByteArrayLen]byte {
214	return &f.d.b
215}
216
217// FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
218func (f genHelperDecoder) DecFallback(iv interface{}, chkPtr bool) {
219	// println(">>>>>>>>> DecFallback")
220	rv := reflect.ValueOf(iv)
221	if chkPtr {
222		rv = f.d.ensureDecodeable(rv)
223	}
224	f.d.decodeValue(rv, nil, false)
225	// f.d.decodeValueFallback(rv)
226}
227
228// FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
229func (f genHelperDecoder) DecSliceHelperStart() (decSliceHelper, int) {
230	return f.d.decSliceHelperStart()
231}
232
233// FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
234func (f genHelperDecoder) DecStructFieldNotFound(index int, name string) {
235	f.d.structFieldNotFound(index, name)
236}
237
238// FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
239func (f genHelperDecoder) DecArrayCannotExpand(sliceLen, streamLen int) {
240	f.d.arrayCannotExpand(sliceLen, streamLen)
241}
242
243// FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
244func (f genHelperDecoder) DecTextUnmarshal(tm encoding.TextUnmarshaler) {
245	fnerr := tm.UnmarshalText(f.d.d.DecodeStringAsBytes())
246	if fnerr != nil {
247		panic(fnerr)
248	}
249}
250
251// FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
252func (f genHelperDecoder) DecJSONUnmarshal(tm jsonUnmarshaler) {
253	// bs := f.dd.DecodeStringAsBytes()
254	// grab the bytes to be read, as UnmarshalJSON needs the full JSON so as to unmarshal it itself.
255	fnerr := tm.UnmarshalJSON(f.d.nextValueBytes())
256	if fnerr != nil {
257		panic(fnerr)
258	}
259}
260
261// FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
262func (f genHelperDecoder) DecBinaryUnmarshal(bm encoding.BinaryUnmarshaler) {
263	fnerr := bm.UnmarshalBinary(f.d.d.DecodeBytes(nil, true))
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) DecRaw() []byte { return f.d.rawBytes() }
271
272// FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
273//
274// Deprecated: builtin no longer supported - so we make this method a no-op,
275// but leave in-place so that old generated files continue to work without regeneration.
276func (f genHelperDecoder) TimeRtidIfBinc() (v uintptr) { return }
277
278// func (f genHelperDecoder) TimeRtidIfBinc() uintptr {
279// 	// Note: builtin is no longer supported - so make this a no-op
280// 	if _, ok := f.d.hh.(*BincHandle); ok {
281// 		return timeTypId
282// 	}
283// 	return 0
284// }
285
286// FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
287func (f genHelperDecoder) IsJSONHandle() bool {
288	return f.d.js
289}
290
291// FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
292func (f genHelperDecoder) I2Rtid(v interface{}) uintptr {
293	return i2rtid(v)
294}
295
296// FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
297func (f genHelperDecoder) Extension(rtid uintptr) (xfn *extTypeTagFn) {
298	return f.d.h.getExt(rtid)
299}
300
301// FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
302func (f genHelperDecoder) DecExtension(v interface{}, xfFn *extTypeTagFn) {
303	f.d.d.DecodeExt(v, xfFn.tag, xfFn.ext)
304}
305
306// FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
307//
308// Deprecated: No longer used,
309// but leave in-place so that old generated files continue to work without regeneration.
310func (f genHelperDecoder) HasExtensions() bool {
311	return len(f.d.h.extHandle) != 0
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) DecExt(v interface{}) (r bool) {
319	if xfFn := f.d.h.getExt(i2rtid(v)); xfFn != nil {
320		f.d.d.DecodeExt(v, xfFn.tag, xfFn.ext)
321		return true
322	}
323	return false
324}
325
326// FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
327func (f genHelperDecoder) DecInferLen(clen, maxlen, unit int) (rvlen int) {
328	return decInferLen(clen, maxlen, unit)
329}
330
331// FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
332//
333// Deprecated: no longer used,
334// but leave in-place so that old generated files continue to work without regeneration.
335func (f genHelperDecoder) StringView(v []byte) string { return stringView(v) }