github.com/patricebensoussan/go/codec@v1.2.99/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) 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) EncEncodeMapNonNil(v interface{}) {
   140  	if skipFastpathTypeSwitchInDirectCall || !fastpathEncodeTypeSwitch(v, f.e) {
   141  		f.e.encodeValue(reflect.ValueOf(v), nil)
   142  	}
   143  }
   144  
   145  // ---------------- DECODER FOLLOWS -----------------
   146  
   147  // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
   148  func (f genHelperDecoder) DecBasicHandle() *BasicHandle {
   149  	return f.d.h
   150  }
   151  // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
   152  func (f genHelperDecoder) DecBinary() bool {
   153       return f.d.be // f.d.hh.isBinaryEncoding()
   154  }
   155  // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
   156  func (f genHelperDecoder) DecSwallow() { f.d.swallow() }
   157  
   158  // // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
   159  // func (f genHelperDecoder) DecScratchBuffer() []byte {
   160  // 	return f.d.b[:]
   161  // }
   162  
   163  // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
   164  func (f genHelperDecoder) DecScratchArrayBuffer() *[decScratchByteArrayLen]byte {
   165  	return &f.d.b
   166  }
   167  // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
   168  func (f genHelperDecoder) DecFallback(iv interface{}, chkPtr bool) {
   169  	rv := reflect.ValueOf(iv)
   170  	if chkPtr {
   171      	if x, _ := isDecodeable(rv); !x {
   172  			f.d.haltAsNotDecodeable(rv)
   173  		}
   174  	}
   175  	f.d.decodeValue(rv, nil)
   176  }
   177  // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
   178  func (f genHelperDecoder) DecSliceHelperStart() (decSliceHelper, int) {
   179  	return f.d.decSliceHelperStart()
   180  }
   181  // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
   182  func (f genHelperDecoder) DecStructFieldNotFound(index int, name string) {
   183  	f.d.structFieldNotFound(index, name)
   184  }
   185  // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
   186  func (f genHelperDecoder) DecArrayCannotExpand(sliceLen, streamLen int) {
   187  	f.d.arrayCannotExpand(sliceLen, streamLen)
   188  }
   189  // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
   190  func (f genHelperDecoder) DecTextUnmarshal(tm encoding.TextUnmarshaler) {
   191  	halt.onerror(tm.UnmarshalText(f.d.d.DecodeStringAsBytes()))
   192  }
   193  // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
   194  func (f genHelperDecoder) DecJSONUnmarshal(tm jsonUnmarshaler) {
   195  	f.d.jsonUnmarshalV(tm)
   196  }
   197  // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
   198  func (f genHelperDecoder) DecBinaryUnmarshal(bm encoding.BinaryUnmarshaler) {
   199  	halt.onerror(bm.UnmarshalBinary(f.d.d.DecodeBytes(nil)))
   200  }
   201  // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
   202  func (f genHelperDecoder) DecRaw() []byte {	return f.d.rawBytes() }
   203  
   204  // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
   205  func (f genHelperDecoder) IsJSONHandle() bool {
   206  	return f.d.js 
   207  }
   208  {{/*
   209  // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
   210  func (f genHelperDecoder) I2Rtid(v interface{}) uintptr {
   211  	return i2rtid(v)
   212  }
   213  */ -}}
   214  // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
   215  func (f genHelperDecoder) Extension(v interface{}) (xfn *extTypeTagFn) {
   216  	return f.d.h.getExtForI(v)
   217  }
   218  // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
   219  func (f genHelperDecoder) DecExtension(v interface{}, xfFn *extTypeTagFn) {
   220  	f.d.d.DecodeExt(v, xfFn.rt, xfFn.tag, xfFn.ext)
   221  }
   222  // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
   223  func (f genHelperDecoder) DecInferLen(clen, maxlen, unit int) (rvlen int) {
   224  	return decInferLen(clen, maxlen, unit)
   225  }
   226  
   227  // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
   228  func (f genHelperDecoder) DecReadMapStart() int { return f.d.mapStart(f.d.d.ReadMapStart()) }
   229  // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
   230  func (f genHelperDecoder) DecReadMapEnd() { f.d.mapEnd() }
   231  // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
   232  func (f genHelperDecoder) DecReadArrayStart() int { return f.d.arrayStart(f.d.d.ReadArrayStart()) }
   233  // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
   234  func (f genHelperDecoder) DecReadArrayEnd() { f.d.arrayEnd() }
   235  // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
   236  func (f genHelperDecoder) DecReadArrayElem() { f.d.arrayElem() }
   237  // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
   238  func (f genHelperDecoder) DecReadMapElemKey() { f.d.mapElemKey() }
   239  // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
   240  func (f genHelperDecoder) DecReadMapElemValue() { f.d.mapElemValue() }
   241  
   242  // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
   243  func (f genHelperDecoder) DecDecodeFloat32() float32 { return f.d.decodeFloat32() }
   244  // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
   245  func (f genHelperDecoder) DecCheckBreak() bool { return f.d.checkBreak() }
   246  // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
   247  func (f genHelperDecoder) DecStringZC(v []byte) string { return f.d.stringZC(v) }
   248  // FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
   249  func (f genHelperDecoder) DecodeBytesInto(v []byte) []byte { return f.d.decodeBytesInto(v) }