github.com/ugorji/go/codec@v1.2.13-0.20240307214044-07c54c229a5a/gen-helper.generated.go (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 = 28
    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  // GenHelperEncoder is exported so that it can be used externally by codecgen.
    23  //
    24  // Library users: DO NOT USE IT DIRECTLY or INDIRECTLY. IT WILL CHANGE CONTINOUSLY WITHOUT NOTICE.
    25  func GenHelper() (g genHelper) { return }
    26  
    27  type genHelper struct{}
    28  
    29  func (genHelper) Encoder(e *Encoder) (ge genHelperEncoder, ee genHelperEncDriver) {
    30  	ge = genHelperEncoder{e: e}
    31  	ee = genHelperEncDriver{encDriver: e.e}
    32  	return
    33  }
    34  
    35  func (genHelper) Decoder(d *Decoder) (gd genHelperDecoder, dd genHelperDecDriver) {
    36  	gd = genHelperDecoder{d: d}
    37  	dd = genHelperDecDriver{decDriver: d.d}
    38  	return
    39  }
    40  
    41  type genHelperEncDriver struct {
    42  	encDriver
    43  }
    44  
    45  type genHelperDecDriver struct {
    46  	decDriver
    47  }
    48  
    49  // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
    50  type genHelperEncoder struct {
    51  	M mustHdl
    52  	F fastpathT
    53  	e *Encoder
    54  }
    55  
    56  // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
    57  type genHelperDecoder struct {
    58  	C checkOverflow
    59  	F fastpathT
    60  	d *Decoder
    61  }
    62  
    63  // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
    64  func (f genHelperEncoder) EncBasicHandle() *BasicHandle {
    65  	return f.e.h
    66  }
    67  
    68  // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
    69  func (f genHelperEncoder) EncWr() *encWr {
    70  	return f.e.w()
    71  }
    72  
    73  // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
    74  func (f genHelperEncoder) EncBinary() bool {
    75  	return f.e.be // f.e.hh.isBinaryEncoding()
    76  }
    77  
    78  // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
    79  func (f genHelperEncoder) IsJSONHandle() bool {
    80  	return f.e.js
    81  }
    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  
    89  // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
    90  func (f genHelperEncoder) EncTextMarshal(iv encoding.TextMarshaler) {
    91  	bs, fnerr := iv.MarshalText()
    92  	f.e.marshalUtf8(bs, fnerr)
    93  }
    94  
    95  // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
    96  func (f genHelperEncoder) EncJSONMarshal(iv jsonMarshaler) {
    97  	bs, fnerr := iv.MarshalJSON()
    98  	f.e.marshalAsis(bs, fnerr)
    99  }
   100  
   101  // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
   102  func (f genHelperEncoder) EncBinaryMarshal(iv encoding.BinaryMarshaler) {
   103  	bs, fnerr := iv.MarshalBinary()
   104  	f.e.marshalRaw(bs, fnerr)
   105  }
   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  
   115  // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
   116  func (f genHelperEncoder) EncExtension(v interface{}, xfFn *extTypeTagFn) {
   117  	f.e.e.EncodeExt(v, xfFn.rt, xfFn.tag, xfFn.ext)
   118  }
   119  
   120  // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
   121  func (f genHelperEncoder) EncWriteMapStart(length int) { f.e.mapStart(length) }
   122  
   123  // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
   124  func (f genHelperEncoder) EncWriteMapEnd() { f.e.mapEnd() }
   125  
   126  // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
   127  func (f genHelperEncoder) EncWriteArrayStart(length int) { f.e.arrayStart(length) }
   128  
   129  // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
   130  func (f genHelperEncoder) EncWriteArrayEnd() { f.e.arrayEnd() }
   131  
   132  // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
   133  func (f genHelperEncoder) EncWriteArrayElem() { f.e.arrayElem() }
   134  
   135  // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
   136  func (f genHelperEncoder) EncWriteMapElemKey() { f.e.mapElemKey() }
   137  
   138  // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
   139  func (f genHelperEncoder) EncWriteMapElemValue() { f.e.mapElemValue() }
   140  
   141  // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
   142  func (f genHelperEncoder) EncEncodeComplex64(v complex64) { f.e.encodeComplex64(v) }
   143  
   144  // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
   145  func (f genHelperEncoder) EncEncodeComplex128(v complex128) { f.e.encodeComplex128(v) }
   146  
   147  // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
   148  func (f genHelperEncoder) EncEncode(v interface{}) { f.e.encode(v) }
   149  
   150  // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
   151  func (f genHelperEncoder) EncFnGivenAddr(v interface{}) *codecFn {
   152  	return f.e.h.fn(reflect.TypeOf(v).Elem())
   153  }
   154  
   155  // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
   156  func (f genHelperEncoder) EncEncodeNumBoolStrKindGivenAddr(v interface{}, encFn *codecFn) {
   157  	f.e.encodeValueNonNil(reflect.ValueOf(v).Elem(), encFn)
   158  }
   159  
   160  // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
   161  func (f genHelperEncoder) EncEncodeMapNonNil(v interface{}) {
   162  	if skipFastpathTypeSwitchInDirectCall || !fastpathEncodeTypeSwitch(v, f.e) {
   163  		f.e.encodeValueNonNil(reflect.ValueOf(v), nil)
   164  	}
   165  }
   166  
   167  // ---------------- DECODER FOLLOWS -----------------
   168  
   169  // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
   170  func (f genHelperDecoder) DecBasicHandle() *BasicHandle {
   171  	return f.d.h
   172  }
   173  
   174  // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
   175  func (f genHelperDecoder) DecBinary() bool {
   176  	return f.d.be // f.d.hh.isBinaryEncoding()
   177  }
   178  
   179  // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
   180  func (f genHelperDecoder) DecSwallow() { f.d.swallow() }
   181  
   182  // // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
   183  // func (f genHelperDecoder) DecScratchBuffer() []byte {
   184  // 	return f.d.b[:]
   185  // }
   186  
   187  // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
   188  func (f genHelperDecoder) DecScratchArrayBuffer() *[decScratchByteArrayLen]byte {
   189  	return &f.d.b
   190  }
   191  
   192  // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
   193  func (f genHelperDecoder) DecFallback(iv interface{}, chkPtr bool) {
   194  	rv := reflect.ValueOf(iv)
   195  	if chkPtr {
   196  		if x, _ := isDecodeable(rv); !x {
   197  			f.d.haltAsNotDecodeable(rv)
   198  		}
   199  	}
   200  	f.d.decodeValue(rv, nil)
   201  }
   202  
   203  // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
   204  func (f genHelperDecoder) DecSliceHelperStart() (decSliceHelper, int) {
   205  	return f.d.decSliceHelperStart()
   206  }
   207  
   208  // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
   209  func (f genHelperDecoder) DecStructFieldNotFound(index int, name string) {
   210  	f.d.structFieldNotFound(index, name)
   211  }
   212  
   213  // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
   214  func (f genHelperDecoder) DecArrayCannotExpand(sliceLen, streamLen int) {
   215  	f.d.arrayCannotExpand(sliceLen, streamLen)
   216  }
   217  
   218  // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
   219  func (f genHelperDecoder) DecTextUnmarshal(tm encoding.TextUnmarshaler) {
   220  	halt.onerror(tm.UnmarshalText(f.d.d.DecodeStringAsBytes()))
   221  }
   222  
   223  // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
   224  func (f genHelperDecoder) DecJSONUnmarshal(tm jsonUnmarshaler) {
   225  	f.d.jsonUnmarshalV(tm)
   226  }
   227  
   228  // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
   229  func (f genHelperDecoder) DecBinaryUnmarshal(bm encoding.BinaryUnmarshaler) {
   230  	halt.onerror(bm.UnmarshalBinary(f.d.d.DecodeBytes(nil)))
   231  }
   232  
   233  // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
   234  func (f genHelperDecoder) DecRaw() []byte { return f.d.rawBytes() }
   235  
   236  // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
   237  func (f genHelperDecoder) IsJSONHandle() bool {
   238  	return f.d.js
   239  }
   240  
   241  // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
   242  func (f genHelperDecoder) Extension(v interface{}) (xfn *extTypeTagFn) {
   243  	return f.d.h.getExtForI(v)
   244  }
   245  
   246  // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
   247  func (f genHelperDecoder) DecExtension(v interface{}, xfFn *extTypeTagFn) {
   248  	f.d.d.DecodeExt(v, xfFn.rt, xfFn.tag, xfFn.ext)
   249  }
   250  
   251  // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
   252  func (f genHelperDecoder) DecInferLen(clen, maxlen, unit int) (rvlen int) {
   253  	return decInferLen(clen, maxlen, unit)
   254  }
   255  
   256  // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
   257  func (f genHelperDecoder) DecReadMapStart() int { return f.d.mapStart(f.d.d.ReadMapStart()) }
   258  
   259  // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
   260  func (f genHelperDecoder) DecReadMapEnd() { f.d.mapEnd() }
   261  
   262  // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
   263  func (f genHelperDecoder) DecReadArrayStart() int { return f.d.arrayStart(f.d.d.ReadArrayStart()) }
   264  
   265  // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
   266  func (f genHelperDecoder) DecReadArrayEnd() { f.d.arrayEnd() }
   267  
   268  // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
   269  func (f genHelperDecoder) DecReadArrayElem() { f.d.arrayElem() }
   270  
   271  // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
   272  func (f genHelperDecoder) DecReadMapElemKey() { f.d.mapElemKey() }
   273  
   274  // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
   275  func (f genHelperDecoder) DecReadMapElemValue() { f.d.mapElemValue() }
   276  
   277  // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
   278  func (f genHelperDecoder) DecDecodeFloat32() float32 { return f.d.decodeFloat32() }
   279  
   280  // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
   281  func (f genHelperDecoder) DecStringZC(v []byte) string { return f.d.stringZC(v) }
   282  
   283  // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
   284  func (f genHelperDecoder) DecodeBytesInto(v []byte) []byte { return f.d.decodeBytesInto(v) }
   285  
   286  // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
   287  func (f genHelperDecoder) DecContainerNext(j, containerLen int, hasLen bool) bool {
   288  	// return f.d.containerNext(j, containerLen, hasLen)
   289  	// rewriting so it can be inlined
   290  	if hasLen {
   291  		return j < containerLen
   292  	}
   293  	return !f.d.checkBreak()
   294  }