| 1 |
// comment this out // + build ignore |
| 2 |
|
| 3 |
// Copyright (c) 2012-2020 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 |
|
| 8 |
package codec |
| 9 |
|
| 10 |
import ( |
| 11 |
"encoding" |
| 12 |
"reflect" |
| 13 |
) |
| 14 |
|
| 15 |
// GenVersion is the current version of codecgen. |
| 16 |
const 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 |
{{/* |
| 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 |
|
| 30 |
// GenHelperEncoder is exported so that it can be used externally by codecgen. |
| 31 |
// |
| 32 |
// Library users: DO NOT USE IT DIRECTLY or INDIRECTLY. IT WILL CHANGE CONTINOUSLY WITHOUT NOTICE. |
| 33 |
func GenHelper() (g genHelper) { return } |
| 34 |
|
| 35 |
type genHelper struct {} |
| 36 |
|
| 37 |
func (genHelper) Encoder(e *Encoder) (ge genHelperEncoder, ee genHelperEncDriver) { |
| 38 |
ge = genHelperEncoder{e: e} |
| 39 |
ee = genHelperEncDriver{encDriver: e.e} |
| 40 |
return |
| 41 |
} |
| 42 |
|
| 43 |
func (genHelper) Decoder(d *Decoder) (gd genHelperDecoder, dd genHelperDecDriver) { |
| 44 |
gd = genHelperDecoder{d: d} |
| 45 |
dd = genHelperDecDriver{decDriver: d.d} |
| 46 |
return |
| 47 |
} |
| 48 |
|
| 49 |
type genHelperEncDriver struct { |
| 50 |
encDriver |
| 51 |
} |
| 52 |
|
| 53 |
type genHelperDecDriver struct { |
| 54 |
decDriver |
| 55 |
} |
| 56 |
|
| 57 |
// FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE* |
| 58 |
type genHelperEncoder struct { |
| 59 |
M mustHdl |
| 60 |
F fastpathT |
| 61 |
e *Encoder |
| 62 |
} |
| 63 |
|
| 64 |
// FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE* |
| 65 |
type genHelperDecoder struct { |
| 66 |
C checkOverflow |
| 67 |
F fastpathT |
| 68 |
d *Decoder |
| 69 |
} |
| 70 |
|
| 71 |
// FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE* |
| 72 |
func (f genHelperEncoder) EncBasicHandle() *BasicHandle { |
| 73 |
return f.e.h |
| 74 |
} |
| 75 |
// FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE* |
| 76 |
func (f genHelperEncoder) EncBinary() bool { |
| 77 |
return f.e.be // f.e.hh.isBinaryEncoding() |
| 78 |
} |
| 79 |
// FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE* |
| 80 |
func (f genHelperEncoder) IsJSONHandle() bool { |
| 81 |
return f.e.js |
| 82 |
} |
| 83 |
// FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE* |
| 84 |
func (f genHelperEncoder) EncFallback(iv interface{}) { |
| 85 |
// f.e.encodeI(iv, false, false) |
| 86 |
f.e.encodeValue(reflect.ValueOf(iv), nil) |
| 87 |
} |
| 88 |
// FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE* |
| 89 |
func (f genHelperEncoder) EncTextMarshal(iv encoding.TextMarshaler) { |
| 90 |
bs, fnerr := iv.MarshalText() |
| 91 |
f.e.marshalUtf8(bs, fnerr) |
| 92 |
} |
| 93 |
// FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE* |
| 94 |
func (f genHelperEncoder) EncJSONMarshal(iv jsonMarshaler) { |
| 95 |
bs, fnerr := iv.MarshalJSON() |
| 96 |
f.e.marshalAsis(bs, fnerr) |
| 97 |
} |
| 98 |
// FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE* |
| 99 |
func (f genHelperEncoder) EncBinaryMarshal(iv encoding.BinaryMarshaler) { |
| 100 |
bs, fnerr := iv.MarshalBinary() |
| 101 |
f.e.marshalRaw(bs, fnerr) |
| 102 |
} |
| 103 |
// FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE* |
| 104 |
func (f genHelperEncoder) EncRaw(iv Raw) { f.e.rawBytes(iv) } |
| 105 |
|
| 106 |
// FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE* |
| 107 |
func (f genHelperEncoder) Extension(v interface{}) (xfn *extTypeTagFn) { |
| 108 |
return f.e.h.getExtForI(v) |
| 109 |
} |
| 110 |
// FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE* |
| 111 |
func (f genHelperEncoder) EncExtension(v interface{}, xfFn *extTypeTagFn) { |
| 112 |
f.e.e.EncodeExt(v, xfFn.rt, xfFn.tag, xfFn.ext) |
| 113 |
} |
| 114 |
// FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE* |
| 115 |
func (f genHelperEncoder) WriteStr(s string) { |
| 116 |
f.e.w().writestr(s) |
| 117 |
} |
| 118 |
// FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE* |
| 119 |
func (f genHelperEncoder) EncWriteMapStart(length int) { f.e.mapStart(length) } |
| 120 |
// FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE* |
| 121 |
func (f genHelperEncoder) EncWriteMapEnd() { f.e.mapEnd() } |
| 122 |
// FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE* |
| 123 |
func (f genHelperEncoder) EncWriteArrayStart(length int) { f.e.arrayStart(length) } |
| 124 |
// FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE* |
| 125 |
func (f genHelperEncoder) EncWriteArrayEnd() { f.e.arrayEnd() } |
| 126 |
// FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE* |
| 127 |
func (f genHelperEncoder) EncWriteArrayElem() { f.e.arrayElem() } |
| 128 |
// FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE* |
| 129 |
func (f genHelperEncoder) EncWriteMapElemKey() { f.e.mapElemKey() } |
| 130 |
// FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE* |
| 131 |
func (f genHelperEncoder) EncWriteMapElemValue() { f.e.mapElemValue() } |
| 132 |
// FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE* |
| 133 |
func (f genHelperEncoder) EncEncodeComplex64(v complex64) { f.e.encodeComplex64(v) } |
| 134 |
// FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE* |
| 135 |
func (f genHelperEncoder) EncEncodeComplex128(v complex128) { f.e.encodeComplex128(v) } |
| 136 |
// FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE* |
| 137 |
func (f genHelperEncoder) EncEncode(v interface{}) { f.e.encode(v) } |
| 138 |
// FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE* |
| 139 |
func (f genHelperEncoder) EncFnGivenAddr(v interface{}) *codecFn { return f.e.h.fn(reflect.TypeOf(v).Elem()) } |
| 140 |
// FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE* |
| 141 |
func (f genHelperEncoder) EncEncodeNumBoolStrKindGivenAddr(v interface{}, encFn *codecFn) { |
| 142 |
f.e.encodeValueNonNil(reflect.ValueOf(v).Elem(), encFn) |
| 143 |
} |
| 144 |
// FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE* |
| 145 |
func (f genHelperEncoder) EncEncodeMapNonNil(v interface{}) { |
| 146 |
if skipFastpathTypeSwitchInDirectCall || !fastpathEncodeTypeSwitch(v, f.e) { |
| 147 |
f.e.encodeValueNonNil(reflect.ValueOf(v), nil) |
| 148 |
} |
| 149 |
} |
| 150 |
|
| 151 |
// ---------------- DECODER FOLLOWS ----------------- |
| 152 |
|
| 153 |
// FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE* |
| 154 |
func (f genHelperDecoder) DecBasicHandle() *BasicHandle { |
| 155 |
return f.d.h |
| 156 |
} |
| 157 |
// FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE* |
| 158 |
func (f genHelperDecoder) DecBinary() bool { |
| 159 |
return f.d.be // f.d.hh.isBinaryEncoding() |
| 160 |
} |
| 161 |
// FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE* |
| 162 |
func (f genHelperDecoder) DecSwallow() { f.d.swallow() } |
| 163 |
|
| 164 |
// // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE* |
| 165 |
// func (f genHelperDecoder) DecScratchBuffer() []byte { |
| 166 |
// return f.d.b[:] |
| 167 |
// } |
| 168 |
|
| 169 |
// FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE* |
| 170 |
func (f genHelperDecoder) DecScratchArrayBuffer() *[decScratchByteArrayLen]byte { |
| 171 |
return &f.d.b |
| 172 |
} |
| 173 |
// FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE* |
| 174 |
func (f genHelperDecoder) DecFallback(iv interface{}, chkPtr bool) { |
| 175 |
rv := reflect.ValueOf(iv) |
| 176 |
if chkPtr { |
| 177 |
if x, _ := isDecodeable(rv); !x { |
| 178 |
f.d.haltAsNotDecodeable(rv) |
| 179 |
} |
| 180 |
} |
| 181 |
f.d.decodeValue(rv, nil) |
| 182 |
} |
| 183 |
// FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE* |
| 184 |
func (f genHelperDecoder) DecSliceHelperStart() (decSliceHelper, int) { |
| 185 |
return f.d.decSliceHelperStart() |
| 186 |
} |
| 187 |
// FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE* |
| 188 |
func (f genHelperDecoder) DecStructFieldNotFound(index int, name string) { |
| 189 |
f.d.structFieldNotFound(index, name) |
| 190 |
} |
| 191 |
// FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE* |
| 192 |
func (f genHelperDecoder) DecArrayCannotExpand(sliceLen, streamLen int) { |
| 193 |
f.d.arrayCannotExpand(sliceLen, streamLen) |
| 194 |
} |
| 195 |
// FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE* |
| 196 |
func (f genHelperDecoder) DecTextUnmarshal(tm encoding.TextUnmarshaler) { |
| 197 |
halt.onerror(tm.UnmarshalText(f.d.d.DecodeStringAsBytes())) |
| 198 |
} |
| 199 |
// FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE* |
| 200 |
func (f genHelperDecoder) DecJSONUnmarshal(tm jsonUnmarshaler) { |
| 201 |
f.d.jsonUnmarshalV(tm) |
| 202 |
} |
| 203 |
// FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE* |
| 204 |
func (f genHelperDecoder) DecBinaryUnmarshal(bm encoding.BinaryUnmarshaler) { |
| 205 |
halt.onerror(bm.UnmarshalBinary(f.d.d.DecodeBytes(nil))) |
| 206 |
} |
| 207 |
// FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE* |
| 208 |
func (f genHelperDecoder) DecRaw() []byte { return f.d.rawBytes() } |
| 209 |
|
| 210 |
// FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE* |
| 211 |
func (f genHelperDecoder) IsJSONHandle() bool { |
| 212 |
return f.d.js |
| 213 |
} |
| 214 |
{{/* |
| 215 |
// FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE* |
| 216 |
func (f genHelperDecoder) I2Rtid(v interface{}) uintptr { |
| 217 |
return i2rtid(v) |
| 218 |
} |
| 219 |
*/ -}} |
| 220 |
// FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE* |
| 221 |
func (f genHelperDecoder) Extension(v interface{}) (xfn *extTypeTagFn) { |
| 222 |
return f.d.h.getExtForI(v) |
| 223 |
} |
| 224 |
// FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE* |
| 225 |
func (f genHelperDecoder) DecExtension(v interface{}, xfFn *extTypeTagFn) { |
| 226 |
f.d.d.DecodeExt(v, xfFn.rt, xfFn.tag, xfFn.ext) |
| 227 |
} |
| 228 |
// FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE* |
| 229 |
func (f genHelperDecoder) DecInferLen(clen, maxlen, unit int) (rvlen int) { |
| 230 |
return decInferLen(clen, maxlen, unit) |
| 231 |
} |
| 232 |
|
| 233 |
// FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE* |
| 234 |
func (f genHelperDecoder) DecReadMapStart() int { return f.d.mapStart(f.d.d.ReadMapStart()) } |
| 235 |
// FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE* |
| 236 |
func (f genHelperDecoder) DecReadMapEnd() { f.d.mapEnd() } |
| 237 |
// FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE* |
| 238 |
func (f genHelperDecoder) DecReadArrayStart() int { return f.d.arrayStart(f.d.d.ReadArrayStart()) } |
| 239 |
// FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE* |
| 240 |
func (f genHelperDecoder) DecReadArrayEnd() { f.d.arrayEnd() } |
| 241 |
// FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE* |
| 242 |
func (f genHelperDecoder) DecReadArrayElem() { f.d.arrayElem() } |
| 243 |
// FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE* |
| 244 |
func (f genHelperDecoder) DecReadMapElemKey() { f.d.mapElemKey() } |
| 245 |
// FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE* |
| 246 |
func (f genHelperDecoder) DecReadMapElemValue() { f.d.mapElemValue() } |
| 247 |
|
| 248 |
// FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE* |
| 249 |
func (f genHelperDecoder) DecDecodeFloat32() float32 { return f.d.decodeFloat32() } |
| 250 |
// FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE* |
| 251 |
func (f genHelperDecoder) DecCheckBreak() bool { return f.d.checkBreak() } |
| 252 |
// FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE* |
| 253 |
func (f genHelperDecoder) DecStringZC(v []byte) string { return f.d.stringZC(v) } |
| 254 |
// FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE* |
| 255 |
func (f genHelperDecoder) DecodeBytesInto(v []byte) []byte { return f.d.decodeBytesInto(v) } |