2017-01-13 14:06:34 +00:00
|
|
|
/* // +build ignore */
|
2015-06-29 21:50:55 +00:00
|
|
|
|
|
|
|
// Copyright (c) 2012-2015 Ugorji Nwoke. All rights reserved.
|
2015-08-19 01:12:51 +00:00
|
|
|
// Use of this source code is governed by a MIT license found in the LICENSE file.
|
2015-06-29 21:50:55 +00:00
|
|
|
|
|
|
|
// ************************************************************
|
|
|
|
// DO NOT EDIT.
|
|
|
|
// THIS FILE IS AUTO-GENERATED from gen-helper.go.tmpl
|
|
|
|
// ************************************************************
|
|
|
|
|
|
|
|
package codec
|
|
|
|
|
2015-09-22 15:44:21 +00:00
|
|
|
import (
|
|
|
|
"encoding"
|
|
|
|
"reflect"
|
|
|
|
)
|
|
|
|
|
2017-10-27 19:06:04 +00:00
|
|
|
// GenVersion is the current version of codecgen.
|
|
|
|
const GenVersion = {{ .Version }}
|
|
|
|
|
2015-06-29 21:50:55 +00:00
|
|
|
// This file is used to generate helper code for codecgen.
|
|
|
|
// The values here i.e. genHelper(En|De)coder are not to be used directly by
|
2016-07-23 00:11:47 +00:00
|
|
|
// library users. They WILL change continuously and without notice.
|
2015-06-29 21:50:55 +00:00
|
|
|
//
|
|
|
|
// To help enforce this, we create an unexported type with exported members.
|
|
|
|
// The only way to get the type is via the one exported type that we control (somewhat).
|
|
|
|
//
|
|
|
|
// When static codecs are created for types, they will use this value
|
|
|
|
// to perform encoding or decoding of primitives or known slice or map types.
|
|
|
|
|
|
|
|
// GenHelperEncoder is exported so that it can be used externally by codecgen.
|
2017-10-27 19:06:04 +00:00
|
|
|
//
|
2015-06-29 21:50:55 +00:00
|
|
|
// Library users: DO NOT USE IT DIRECTLY. IT WILL CHANGE CONTINOUSLY WITHOUT NOTICE.
|
|
|
|
func GenHelperEncoder(e *Encoder) (genHelperEncoder, encDriver) {
|
|
|
|
return genHelperEncoder{e:e}, e.e
|
|
|
|
}
|
|
|
|
|
|
|
|
// GenHelperDecoder is exported so that it can be used externally by codecgen.
|
2017-10-27 19:06:04 +00:00
|
|
|
//
|
2015-06-29 21:50:55 +00:00
|
|
|
// Library users: DO NOT USE IT DIRECTLY. IT WILL CHANGE CONTINOUSLY WITHOUT NOTICE.
|
|
|
|
func GenHelperDecoder(d *Decoder) (genHelperDecoder, decDriver) {
|
|
|
|
return genHelperDecoder{d:d}, d.d
|
|
|
|
}
|
|
|
|
|
|
|
|
// FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
|
|
|
|
type genHelperEncoder struct {
|
|
|
|
e *Encoder
|
|
|
|
F fastpathT
|
|
|
|
}
|
|
|
|
|
|
|
|
// FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
|
|
|
|
type genHelperDecoder struct {
|
|
|
|
d *Decoder
|
|
|
|
F fastpathT
|
|
|
|
}
|
|
|
|
|
|
|
|
// FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
|
|
|
|
func (f genHelperEncoder) EncBasicHandle() *BasicHandle {
|
|
|
|
return f.e.h
|
|
|
|
}
|
2015-09-22 15:44:21 +00:00
|
|
|
|
2015-06-29 21:50:55 +00:00
|
|
|
// FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
|
|
|
|
func (f genHelperEncoder) EncBinary() bool {
|
2017-10-27 19:06:04 +00:00
|
|
|
return f.e.cf.be // f.e.hh.isBinaryEncoding()
|
2015-06-29 21:50:55 +00:00
|
|
|
}
|
|
|
|
// FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
|
|
|
|
func (f genHelperEncoder) EncFallback(iv interface{}) {
|
|
|
|
// println(">>>>>>>>> EncFallback")
|
2017-10-27 19:06:04 +00:00
|
|
|
// f.e.encodeI(iv, false, false)
|
|
|
|
f.e.encodeValue(reflect.ValueOf(iv), nil, false)
|
2015-06-29 21:50:55 +00:00
|
|
|
}
|
2015-09-22 15:44:21 +00:00
|
|
|
// FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
|
|
|
|
func (f genHelperEncoder) EncTextMarshal(iv encoding.TextMarshaler) {
|
|
|
|
bs, fnerr := iv.MarshalText()
|
|
|
|
f.e.marshal(bs, fnerr, false, c_UTF8)
|
|
|
|
}
|
|
|
|
// FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
|
|
|
|
func (f genHelperEncoder) EncJSONMarshal(iv jsonMarshaler) {
|
|
|
|
bs, fnerr := iv.MarshalJSON()
|
|
|
|
f.e.marshal(bs, fnerr, true, c_UTF8)
|
|
|
|
}
|
|
|
|
// FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
|
|
|
|
func (f genHelperEncoder) EncBinaryMarshal(iv encoding.BinaryMarshaler) {
|
|
|
|
bs, fnerr := iv.MarshalBinary()
|
|
|
|
f.e.marshal(bs, fnerr, false, c_RAW)
|
|
|
|
}
|
|
|
|
// FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
|
2016-09-12 19:16:55 +00:00
|
|
|
func (f genHelperEncoder) EncRaw(iv Raw) {
|
2017-10-27 19:06:04 +00:00
|
|
|
f.e.rawBytes(iv)
|
2016-09-12 19:16:55 +00:00
|
|
|
}
|
|
|
|
// FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
|
2015-09-22 15:44:21 +00:00
|
|
|
func (f genHelperEncoder) TimeRtidIfBinc() uintptr {
|
|
|
|
if _, ok := f.e.hh.(*BincHandle); ok {
|
|
|
|
return timeTypId
|
|
|
|
}
|
|
|
|
return 0
|
|
|
|
}
|
|
|
|
// FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
|
|
|
|
func (f genHelperEncoder) IsJSONHandle() bool {
|
2017-10-27 19:06:04 +00:00
|
|
|
return f.e.cf.js
|
2015-09-22 15:44:21 +00:00
|
|
|
}
|
|
|
|
// FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
|
|
|
|
func (f genHelperEncoder) HasExtensions() bool {
|
|
|
|
return len(f.e.h.extHandle) != 0
|
|
|
|
}
|
|
|
|
// FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
|
|
|
|
func (f genHelperEncoder) EncExt(v interface{}) (r bool) {
|
|
|
|
rt := reflect.TypeOf(v)
|
|
|
|
if rt.Kind() == reflect.Ptr {
|
|
|
|
rt = rt.Elem()
|
|
|
|
}
|
2017-10-27 19:06:04 +00:00
|
|
|
rtid := rt2id(rt)
|
2015-09-22 15:44:21 +00:00
|
|
|
if xfFn := f.e.h.getExt(rtid); xfFn != nil {
|
|
|
|
f.e.e.EncodeExt(v, xfFn.tag, xfFn.ext, f.e)
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
return false
|
|
|
|
}
|
2015-10-30 22:07:00 +00:00
|
|
|
|
|
|
|
// ---------------- DECODER FOLLOWS -----------------
|
2015-06-29 21:50:55 +00:00
|
|
|
|
|
|
|
// FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
|
|
|
|
func (f genHelperDecoder) DecBasicHandle() *BasicHandle {
|
|
|
|
return f.d.h
|
|
|
|
}
|
|
|
|
// FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
|
|
|
|
func (f genHelperDecoder) DecBinary() bool {
|
|
|
|
return f.d.be // f.d.hh.isBinaryEncoding()
|
|
|
|
}
|
|
|
|
// FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
|
|
|
|
func (f genHelperDecoder) DecSwallow() {
|
|
|
|
f.d.swallow()
|
|
|
|
}
|
|
|
|
// FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
|
|
|
|
func (f genHelperDecoder) DecScratchBuffer() []byte {
|
|
|
|
return f.d.b[:]
|
|
|
|
}
|
|
|
|
// FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
|
|
|
|
func (f genHelperDecoder) DecFallback(iv interface{}, chkPtr bool) {
|
|
|
|
// println(">>>>>>>>> DecFallback")
|
2017-10-27 19:06:04 +00:00
|
|
|
rv := reflect.ValueOf(iv)
|
|
|
|
if chkPtr {
|
|
|
|
rv = f.d.ensureDecodeable(rv)
|
|
|
|
}
|
2017-11-07 16:57:05 +00:00
|
|
|
f.d.decodeValue(rv, nil, false)
|
2017-10-27 19:06:04 +00:00
|
|
|
// f.d.decodeValueFallback(rv)
|
2015-06-29 21:50:55 +00:00
|
|
|
}
|
|
|
|
// FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
|
|
|
|
func (f genHelperDecoder) DecSliceHelperStart() (decSliceHelper, int) {
|
|
|
|
return f.d.decSliceHelperStart()
|
|
|
|
}
|
|
|
|
// FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
|
|
|
|
func (f genHelperDecoder) DecStructFieldNotFound(index int, name string) {
|
|
|
|
f.d.structFieldNotFound(index, name)
|
|
|
|
}
|
|
|
|
// FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
|
|
|
|
func (f genHelperDecoder) DecArrayCannotExpand(sliceLen, streamLen int) {
|
|
|
|
f.d.arrayCannotExpand(sliceLen, streamLen)
|
|
|
|
}
|
2015-09-22 15:44:21 +00:00
|
|
|
// FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
|
|
|
|
func (f genHelperDecoder) DecTextUnmarshal(tm encoding.TextUnmarshaler) {
|
2017-10-27 19:06:04 +00:00
|
|
|
fnerr := tm.UnmarshalText(f.d.d.DecodeStringAsBytes())
|
2015-09-22 15:44:21 +00:00
|
|
|
if fnerr != nil {
|
|
|
|
panic(fnerr)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
|
|
|
|
func (f genHelperDecoder) DecJSONUnmarshal(tm jsonUnmarshaler) {
|
2017-10-27 19:06:04 +00:00
|
|
|
// bs := f.dd.DecodeStringAsBytes()
|
2015-10-30 22:07:00 +00:00
|
|
|
// grab the bytes to be read, as UnmarshalJSON needs the full JSON so as to unmarshal it itself.
|
|
|
|
fnerr := tm.UnmarshalJSON(f.d.nextValueBytes())
|
2015-09-22 15:44:21 +00:00
|
|
|
if fnerr != nil {
|
|
|
|
panic(fnerr)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
|
|
|
|
func (f genHelperDecoder) DecBinaryUnmarshal(bm encoding.BinaryUnmarshaler) {
|
2017-10-27 19:06:04 +00:00
|
|
|
fnerr := bm.UnmarshalBinary(f.d.d.DecodeBytes(nil, true))
|
2015-09-22 15:44:21 +00:00
|
|
|
if fnerr != nil {
|
|
|
|
panic(fnerr)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
|
2016-09-12 19:16:55 +00:00
|
|
|
func (f genHelperDecoder) DecRaw() []byte {
|
2017-10-27 19:06:04 +00:00
|
|
|
return f.d.rawBytes()
|
2016-09-12 19:16:55 +00:00
|
|
|
}
|
|
|
|
// FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
|
2015-09-22 15:44:21 +00:00
|
|
|
func (f genHelperDecoder) TimeRtidIfBinc() uintptr {
|
|
|
|
if _, ok := f.d.hh.(*BincHandle); ok {
|
|
|
|
return timeTypId
|
|
|
|
}
|
|
|
|
return 0
|
|
|
|
}
|
|
|
|
// FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
|
|
|
|
func (f genHelperDecoder) IsJSONHandle() bool {
|
|
|
|
return f.d.js
|
|
|
|
}
|
|
|
|
// FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
|
|
|
|
func (f genHelperDecoder) HasExtensions() bool {
|
|
|
|
return len(f.d.h.extHandle) != 0
|
|
|
|
}
|
|
|
|
// FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
|
|
|
|
func (f genHelperDecoder) DecExt(v interface{}) (r bool) {
|
|
|
|
rt := reflect.TypeOf(v).Elem()
|
2017-10-27 19:06:04 +00:00
|
|
|
rtid := rt2id(rt)
|
2015-09-22 15:44:21 +00:00
|
|
|
if xfFn := f.d.h.getExt(rtid); xfFn != nil {
|
|
|
|
f.d.d.DecodeExt(v, xfFn.tag, xfFn.ext)
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
return false
|
|
|
|
}
|
2015-10-07 20:10:00 +00:00
|
|
|
// FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
|
2017-10-27 19:06:04 +00:00
|
|
|
func (f genHelperDecoder) DecInferLen(clen, maxlen, unit int) (rvlen int) {
|
2015-10-07 20:10:00 +00:00
|
|
|
return decInferLen(clen, maxlen, unit)
|
|
|
|
}
|
2015-10-30 22:07:00 +00:00
|
|
|
// FOR USE BY CODECGEN ONLY. IT *WILL* CHANGE WITHOUT NOTICE. *DO NOT USE*
|
2017-10-27 19:06:04 +00:00
|
|
|
func (f genHelperDecoder) StringView(v []byte) string {
|
|
|
|
return stringView(v)
|
2015-06-29 21:50:55 +00:00
|
|
|
}
|
|
|
|
|