gen-helper.go.tmpl

  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 = {{ .Version }} 
 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// FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
107func (f genHelperEncoder) EncBinary() bool {
108	return f.e.be // f.e.hh.isBinaryEncoding()
109}
110// FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
111func (f genHelperEncoder) IsJSONHandle() bool {
112	return f.e.js
113}
114// FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
115func (f genHelperEncoder) EncFallback(iv interface{}) {
116	// println(">>>>>>>>> EncFallback")
117	// f.e.encodeI(iv, false, false)
118	f.e.encodeValue(reflect.ValueOf(iv), nil, false)
119}
120// FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
121func (f genHelperEncoder) EncTextMarshal(iv encoding.TextMarshaler) {
122	bs, fnerr := iv.MarshalText()
123	f.e.marshal(bs, fnerr, false, cUTF8)
124}
125// FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
126func (f genHelperEncoder) EncJSONMarshal(iv jsonMarshaler) {
127	bs, fnerr := iv.MarshalJSON()
128	f.e.marshal(bs, fnerr, true, cUTF8)
129}
130// FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
131func (f genHelperEncoder) EncBinaryMarshal(iv encoding.BinaryMarshaler) {
132	bs, fnerr := iv.MarshalBinary()
133	f.e.marshal(bs, fnerr, false, cRAW)
134}
135// FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
136func (f genHelperEncoder) EncRaw(iv Raw) { f.e.rawBytes(iv) }
137// FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
138//
139// Deprecated: builtin no longer supported - so we make this method a no-op, 
140// but leave in-place so that old generated files continue to work without regeneration.
141func (f genHelperEncoder) TimeRtidIfBinc() (v uintptr) { return }
142// func (f genHelperEncoder) TimeRtidIfBinc() uintptr {
143// 	if _, ok := f.e.hh.(*BincHandle); ok {
144// 		return timeTypId
145// 	}
146// }
147
148// FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
149func (f genHelperEncoder) I2Rtid(v interface{}) uintptr {
150	return i2rtid(v)
151}
152// FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
153func (f genHelperEncoder) Extension(rtid uintptr) (xfn *extTypeTagFn) {
154	return f.e.h.getExt(rtid)
155}
156// FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
157func (f genHelperEncoder) EncExtension(v interface{}, xfFn *extTypeTagFn) {
158	f.e.e.EncodeExt(v, xfFn.tag, xfFn.ext, f.e)
159}
160// FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
161//
162// Deprecated: No longer used,
163// but leave in-place so that old generated files continue to work without regeneration.
164func (f genHelperEncoder) HasExtensions() bool {
165	return len(f.e.h.extHandle) != 0
166}
167// FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
168//
169// Deprecated: No longer used,
170// but leave in-place so that old generated files continue to work without regeneration.
171func (f genHelperEncoder) EncExt(v interface{}) (r bool) {
172	if xfFn := f.e.h.getExt(i2rtid(v)); xfFn != nil {
173		f.e.e.EncodeExt(v, xfFn.tag, xfFn.ext, f.e)
174		return true
175	}
176	return false 
177}
178
179// ---------------- DECODER FOLLOWS -----------------
180
181// FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
182func (f genHelperDecoder) DecBasicHandle() *BasicHandle {
183	return f.d.h
184}
185// FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
186func (f genHelperDecoder) DecBinary() bool {
187     return f.d.be // f.d.hh.isBinaryEncoding()
188}
189// FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
190func (f genHelperDecoder) DecSwallow() { f.d.swallow() }
191// FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
192func (f genHelperDecoder) DecScratchBuffer() []byte {
193	return f.d.b[:]
194}
195// FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
196func (f genHelperDecoder) DecScratchArrayBuffer() *[decScratchByteArrayLen]byte {
197	return &f.d.b
198}
199// FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
200func (f genHelperDecoder) DecFallback(iv interface{}, chkPtr bool) {
201	// println(">>>>>>>>> DecFallback")
202	rv := reflect.ValueOf(iv)
203	if chkPtr {
204		rv = f.d.ensureDecodeable(rv)
205	}
206	f.d.decodeValue(rv, nil, false)
207	// f.d.decodeValueFallback(rv)
208}
209// FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
210func (f genHelperDecoder) DecSliceHelperStart() (decSliceHelper, int) {
211	return f.d.decSliceHelperStart()
212}
213// FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
214func (f genHelperDecoder) DecStructFieldNotFound(index int, name string) {
215	f.d.structFieldNotFound(index, name)
216}
217// FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
218func (f genHelperDecoder) DecArrayCannotExpand(sliceLen, streamLen int) {
219	f.d.arrayCannotExpand(sliceLen, streamLen)
220}
221// FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
222func (f genHelperDecoder) DecTextUnmarshal(tm encoding.TextUnmarshaler) {
223	fnerr := tm.UnmarshalText(f.d.d.DecodeStringAsBytes())
224	if fnerr != nil {
225		panic(fnerr)
226	}
227}
228// FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
229func (f genHelperDecoder) DecJSONUnmarshal(tm jsonUnmarshaler) {
230	// bs := f.dd.DecodeStringAsBytes()
231	// grab the bytes to be read, as UnmarshalJSON needs the full JSON so as to unmarshal it itself.
232	fnerr := tm.UnmarshalJSON(f.d.nextValueBytes())
233	if fnerr != nil {
234		panic(fnerr)
235	}
236}
237// FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
238func (f genHelperDecoder) DecBinaryUnmarshal(bm encoding.BinaryUnmarshaler) {
239	fnerr := bm.UnmarshalBinary(f.d.d.DecodeBytes(nil, true))
240	if fnerr != nil {
241		panic(fnerr)
242	}
243}
244// FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
245func (f genHelperDecoder) DecRaw() []byte {	return f.d.rawBytes() }
246// FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
247//
248// Deprecated: builtin no longer supported - so we make this method a no-op, 
249// but leave in-place so that old generated files continue to work without regeneration.
250func (f genHelperDecoder) TimeRtidIfBinc() (v uintptr) { return }
251// func (f genHelperDecoder) TimeRtidIfBinc() uintptr {
252// 	// Note: builtin is no longer supported - so make this a no-op
253// 	if _, ok := f.d.hh.(*BincHandle); ok {
254// 		return timeTypId
255// 	}
256// 	return 0
257// }
258
259// FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
260func (f genHelperDecoder) IsJSONHandle() bool {
261	return f.d.js 
262}
263// FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
264func (f genHelperDecoder) I2Rtid(v interface{}) uintptr {
265	return i2rtid(v)
266}
267// FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
268func (f genHelperDecoder) Extension(rtid uintptr) (xfn *extTypeTagFn) {
269	return f.d.h.getExt(rtid)
270}
271// FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
272func (f genHelperDecoder) DecExtension(v interface{}, xfFn *extTypeTagFn) {
273	f.d.d.DecodeExt(v, xfFn.tag, xfFn.ext)
274}
275// FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
276//
277// Deprecated: No longer used,
278// but leave in-place so that old generated files continue to work without regeneration.
279func (f genHelperDecoder) HasExtensions() bool {
280	return len(f.d.h.extHandle) != 0
281}
282// FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
283//
284// Deprecated: No longer used,
285// but leave in-place so that old generated files continue to work without regeneration.
286func (f genHelperDecoder) DecExt(v interface{}) (r bool) {
287	if xfFn := f.d.h.getExt(i2rtid(v)); xfFn != nil {
288		f.d.d.DecodeExt(v, xfFn.tag, xfFn.ext)
289		return true
290	}
291	return false 
292}
293// FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
294func (f genHelperDecoder) DecInferLen(clen, maxlen, unit int) (rvlen int) {
295	return decInferLen(clen, maxlen, unit)
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) StringView(v []byte) string { return stringView(v) }
302