github.com/ugorji/go/codec@v1.2.13-0.20240307214044-07c54c229a5a/gen-helper.go.tmpl (about) 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) EncWr() *encWr { 77 return f.e.w() 78 } 79 // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE* 80 func (f genHelperEncoder) EncBinary() bool { 81 return f.e.be // f.e.hh.isBinaryEncoding() 82 } 83 // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE* 84 func (f genHelperEncoder) IsJSONHandle() bool { 85 return f.e.js 86 } 87 // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE* 88 func (f genHelperEncoder) EncFallback(iv interface{}) { 89 // f.e.encodeI(iv, false, false) 90 f.e.encodeValue(reflect.ValueOf(iv), nil) 91 } 92 // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE* 93 func (f genHelperEncoder) EncTextMarshal(iv encoding.TextMarshaler) { 94 bs, fnerr := iv.MarshalText() 95 f.e.marshalUtf8(bs, fnerr) 96 } 97 // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE* 98 func (f genHelperEncoder) EncJSONMarshal(iv jsonMarshaler) { 99 bs, fnerr := iv.MarshalJSON() 100 f.e.marshalAsis(bs, fnerr) 101 } 102 // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE* 103 func (f genHelperEncoder) EncBinaryMarshal(iv encoding.BinaryMarshaler) { 104 bs, fnerr := iv.MarshalBinary() 105 f.e.marshalRaw(bs, fnerr) 106 } 107 // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE* 108 func (f genHelperEncoder) EncRaw(iv Raw) { f.e.rawBytes(iv) } 109 110 // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE* 111 func (f genHelperEncoder) Extension(v interface{}) (xfn *extTypeTagFn) { 112 return f.e.h.getExtForI(v) 113 } 114 // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE* 115 func (f genHelperEncoder) EncExtension(v interface{}, xfFn *extTypeTagFn) { 116 f.e.e.EncodeExt(v, xfFn.rt, xfFn.tag, xfFn.ext) 117 } 118 119 // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE* 120 func (f genHelperEncoder) EncWriteMapStart(length int) { f.e.mapStart(length) } 121 // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE* 122 func (f genHelperEncoder) EncWriteMapEnd() { f.e.mapEnd() } 123 // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE* 124 func (f genHelperEncoder) EncWriteArrayStart(length int) { f.e.arrayStart(length) } 125 // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE* 126 func (f genHelperEncoder) EncWriteArrayEnd() { f.e.arrayEnd() } 127 // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE* 128 func (f genHelperEncoder) EncWriteArrayElem() { f.e.arrayElem() } 129 // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE* 130 func (f genHelperEncoder) EncWriteMapElemKey() { f.e.mapElemKey() } 131 // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE* 132 func (f genHelperEncoder) EncWriteMapElemValue() { f.e.mapElemValue() } 133 // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE* 134 func (f genHelperEncoder) EncEncodeComplex64(v complex64) { f.e.encodeComplex64(v) } 135 // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE* 136 func (f genHelperEncoder) EncEncodeComplex128(v complex128) { f.e.encodeComplex128(v) } 137 // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE* 138 func (f genHelperEncoder) EncEncode(v interface{}) { f.e.encode(v) } 139 // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE* 140 func (f genHelperEncoder) EncFnGivenAddr(v interface{}) *codecFn { return f.e.h.fn(reflect.TypeOf(v).Elem()) } 141 // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE* 142 func (f genHelperEncoder) EncEncodeNumBoolStrKindGivenAddr(v interface{}, encFn *codecFn) { 143 f.e.encodeValueNonNil(reflect.ValueOf(v).Elem(), encFn) 144 } 145 // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE* 146 func (f genHelperEncoder) EncEncodeMapNonNil(v interface{}) { 147 if skipFastpathTypeSwitchInDirectCall || !fastpathEncodeTypeSwitch(v, f.e) { 148 f.e.encodeValueNonNil(reflect.ValueOf(v), nil) 149 } 150 } 151 152 // ---------------- DECODER FOLLOWS ----------------- 153 154 // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE* 155 func (f genHelperDecoder) DecBasicHandle() *BasicHandle { 156 return f.d.h 157 } 158 // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE* 159 func (f genHelperDecoder) DecBinary() bool { 160 return f.d.be // f.d.hh.isBinaryEncoding() 161 } 162 // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE* 163 func (f genHelperDecoder) DecSwallow() { f.d.swallow() } 164 165 // // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE* 166 // func (f genHelperDecoder) DecScratchBuffer() []byte { 167 // return f.d.b[:] 168 // } 169 170 // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE* 171 func (f genHelperDecoder) DecScratchArrayBuffer() *[decScratchByteArrayLen]byte { 172 return &f.d.b 173 } 174 // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE* 175 func (f genHelperDecoder) DecFallback(iv interface{}, chkPtr bool) { 176 rv := reflect.ValueOf(iv) 177 if chkPtr { 178 if x, _ := isDecodeable(rv); !x { 179 f.d.haltAsNotDecodeable(rv) 180 } 181 } 182 f.d.decodeValue(rv, nil) 183 } 184 // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE* 185 func (f genHelperDecoder) DecSliceHelperStart() (decSliceHelper, int) { 186 return f.d.decSliceHelperStart() 187 } 188 // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE* 189 func (f genHelperDecoder) DecStructFieldNotFound(index int, name string) { 190 f.d.structFieldNotFound(index, name) 191 } 192 // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE* 193 func (f genHelperDecoder) DecArrayCannotExpand(sliceLen, streamLen int) { 194 f.d.arrayCannotExpand(sliceLen, streamLen) 195 } 196 // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE* 197 func (f genHelperDecoder) DecTextUnmarshal(tm encoding.TextUnmarshaler) { 198 halt.onerror(tm.UnmarshalText(f.d.d.DecodeStringAsBytes())) 199 } 200 // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE* 201 func (f genHelperDecoder) DecJSONUnmarshal(tm jsonUnmarshaler) { 202 f.d.jsonUnmarshalV(tm) 203 } 204 // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE* 205 func (f genHelperDecoder) DecBinaryUnmarshal(bm encoding.BinaryUnmarshaler) { 206 halt.onerror(bm.UnmarshalBinary(f.d.d.DecodeBytes(nil))) 207 } 208 // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE* 209 func (f genHelperDecoder) DecRaw() []byte { return f.d.rawBytes() } 210 211 // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE* 212 func (f genHelperDecoder) IsJSONHandle() bool { 213 return f.d.js 214 } 215 // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE* 216 func (f genHelperDecoder) Extension(v interface{}) (xfn *extTypeTagFn) { 217 return f.d.h.getExtForI(v) 218 } 219 // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE* 220 func (f genHelperDecoder) DecExtension(v interface{}, xfFn *extTypeTagFn) { 221 f.d.d.DecodeExt(v, xfFn.rt, xfFn.tag, xfFn.ext) 222 } 223 // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE* 224 func (f genHelperDecoder) DecInferLen(clen, maxlen, unit int) (rvlen int) { 225 return decInferLen(clen, maxlen, unit) 226 } 227 228 // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE* 229 func (f genHelperDecoder) DecReadMapStart() int { return f.d.mapStart(f.d.d.ReadMapStart()) } 230 // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE* 231 func (f genHelperDecoder) DecReadMapEnd() { f.d.mapEnd() } 232 // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE* 233 func (f genHelperDecoder) DecReadArrayStart() int { return f.d.arrayStart(f.d.d.ReadArrayStart()) } 234 // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE* 235 func (f genHelperDecoder) DecReadArrayEnd() { f.d.arrayEnd() } 236 // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE* 237 func (f genHelperDecoder) DecReadArrayElem() { f.d.arrayElem() } 238 // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE* 239 func (f genHelperDecoder) DecReadMapElemKey() { f.d.mapElemKey() } 240 // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE* 241 func (f genHelperDecoder) DecReadMapElemValue() { f.d.mapElemValue() } 242 243 // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE* 244 func (f genHelperDecoder) DecDecodeFloat32() float32 { return f.d.decodeFloat32() } 245 // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE* 246 func (f genHelperDecoder) DecStringZC(v []byte) string { return f.d.stringZC(v) } 247 // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE* 248 func (f genHelperDecoder) DecodeBytesInto(v []byte) []byte { return f.d.decodeBytesInto(v) } 249 // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE* 250 func (f genHelperDecoder) DecContainerNext(j, containerLen int, hasLen bool) bool { 251 // return f.d.containerNext(j, containerLen, hasLen) 252 // rewriting so it can be inlined 253 if hasLen { 254 return j < containerLen 255 } 256 return !f.d.checkBreak() 257 } 258 259 {{/* 260 // MARKER: remove WriteStr, as it cannot be inlined as of 20230201. 261 // Instead, generated code calls (*encWr).WriteStr directly. 262 263 // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE* 264 // func (f genHelperEncoder) WriteStr(s string) { 265 // f.e.encWr.writestr(s) 266 // } 267 268 // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE* 269 func (f genHelperDecoder) I2Rtid(v interface{}) uintptr { 270 return i2rtid(v) 271 } 272 273 */ -}}