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