mirror of
				https://github.com/superseriousbusiness/gotosocial.git
				synced 2025-10-31 17:22:26 -05:00 
			
		
		
		
	[chore] update go dependencies (#4304)
- github.com/KimMachineGun/automemlimit v0.7.2 => v0.7.3
- github.com/gin-contrib/cors v1.7.5 => v1.7.6
- github.com/minio/minio-go/v7 v7.0.92 => v7.0.94
- github.com/spf13/cast v1.8.0 => v1.9.2
- github.com/uptrace/bun{,/*} v1.2.11 => v1.2.14
- golang.org/x/image v0.27.0 => v0.28.0
- golang.org/x/net v0.40.0 => v0.41.0
- code.superseriousbusiness.org/go-swagger v0.31.0-gts-go1.23-fix => v0.32.3-gts-go1.23-fix
Reviewed-on: https://codeberg.org/superseriousbusiness/gotosocial/pulls/4304
Co-authored-by: kim <grufwub@gmail.com>
Co-committed-by: kim <grufwub@gmail.com>
	
	
This commit is contained in:
		
					parent
					
						
							
								7712885038
							
						
					
				
			
			
				commit
				
					
						8b0ea56027
					
				
			
		
					 294 changed files with 139999 additions and 21873 deletions
				
			
		
							
								
								
									
										595
									
								
								vendor/github.com/ugorji/go/codec/simple.go
									
										
									
										generated
									
									
										vendored
									
									
								
							
							
						
						
									
										595
									
								
								vendor/github.com/ugorji/go/codec/simple.go
									
										
									
										generated
									
									
										vendored
									
									
								
							|  | @ -1,111 +1,65 @@ | |||
| //go:build notmono || codec.notmono | ||||
| 
 | ||||
| // Copyright (c) 2012-2020 Ugorji Nwoke. All rights reserved. | ||||
| // Use of this source code is governed by a MIT license found in the LICENSE file. | ||||
| 
 | ||||
| package codec | ||||
| 
 | ||||
| import ( | ||||
| 	"io" | ||||
| 	"math" | ||||
| 	"reflect" | ||||
| 	"time" | ||||
| ) | ||||
| 
 | ||||
| const ( | ||||
| 	_               uint8 = iota | ||||
| 	simpleVdNil           = 1 | ||||
| 	simpleVdFalse         = 2 | ||||
| 	simpleVdTrue          = 3 | ||||
| 	simpleVdFloat32       = 4 | ||||
| 	simpleVdFloat64       = 5 | ||||
| 
 | ||||
| 	// each lasts for 4 (ie n, n+1, n+2, n+3) | ||||
| 	simpleVdPosInt = 8 | ||||
| 	simpleVdNegInt = 12 | ||||
| 
 | ||||
| 	simpleVdTime = 24 | ||||
| 
 | ||||
| 	// containers: each lasts for 4 (ie n, n+1, n+2, ... n+7) | ||||
| 	simpleVdString    = 216 | ||||
| 	simpleVdByteArray = 224 | ||||
| 	simpleVdArray     = 232 | ||||
| 	simpleVdMap       = 240 | ||||
| 	simpleVdExt       = 248 | ||||
| ) | ||||
| 
 | ||||
| var simpledescNames = map[byte]string{ | ||||
| 	simpleVdNil:     "null", | ||||
| 	simpleVdFalse:   "false", | ||||
| 	simpleVdTrue:    "true", | ||||
| 	simpleVdFloat32: "float32", | ||||
| 	simpleVdFloat64: "float64", | ||||
| 
 | ||||
| 	simpleVdPosInt: "+int", | ||||
| 	simpleVdNegInt: "-int", | ||||
| 
 | ||||
| 	simpleVdTime: "time", | ||||
| 
 | ||||
| 	simpleVdString:    "string", | ||||
| 	simpleVdByteArray: "binary", | ||||
| 	simpleVdArray:     "array", | ||||
| 	simpleVdMap:       "map", | ||||
| 	simpleVdExt:       "ext", | ||||
| } | ||||
| 
 | ||||
| func simpledesc(bd byte) (s string) { | ||||
| 	s = simpledescNames[bd] | ||||
| 	if s == "" { | ||||
| 		s = "unknown" | ||||
| 	} | ||||
| 	return | ||||
| } | ||||
| 
 | ||||
| type simpleEncDriver struct { | ||||
| type simpleEncDriver[T encWriter] struct { | ||||
| 	noBuiltInTypes | ||||
| 	encDriverNoopContainerWriter | ||||
| 	encDriverNoState | ||||
| 	encDriverContainerNoTrackerT | ||||
| 	encInit2er | ||||
| 
 | ||||
| 	h *SimpleHandle | ||||
| 	e *encoderBase | ||||
| 	// b [8]byte | ||||
| 	e Encoder | ||||
| 	w T | ||||
| } | ||||
| 
 | ||||
| func (e *simpleEncDriver) encoder() *Encoder { | ||||
| 	return &e.e | ||||
| func (e *simpleEncDriver[T]) EncodeNil() { | ||||
| 	e.w.writen1(simpleVdNil) | ||||
| } | ||||
| 
 | ||||
| func (e *simpleEncDriver) EncodeNil() { | ||||
| 	e.e.encWr.writen1(simpleVdNil) | ||||
| } | ||||
| 
 | ||||
| func (e *simpleEncDriver) EncodeBool(b bool) { | ||||
| func (e *simpleEncDriver[T]) EncodeBool(b bool) { | ||||
| 	if e.h.EncZeroValuesAsNil && e.e.c != containerMapKey && !b { | ||||
| 		e.EncodeNil() | ||||
| 		return | ||||
| 	} | ||||
| 	if b { | ||||
| 		e.e.encWr.writen1(simpleVdTrue) | ||||
| 		e.w.writen1(simpleVdTrue) | ||||
| 	} else { | ||||
| 		e.e.encWr.writen1(simpleVdFalse) | ||||
| 		e.w.writen1(simpleVdFalse) | ||||
| 	} | ||||
| } | ||||
| 
 | ||||
| func (e *simpleEncDriver) EncodeFloat32(f float32) { | ||||
| func (e *simpleEncDriver[T]) EncodeFloat32(f float32) { | ||||
| 	if e.h.EncZeroValuesAsNil && e.e.c != containerMapKey && f == 0.0 { | ||||
| 		e.EncodeNil() | ||||
| 		return | ||||
| 	} | ||||
| 	e.e.encWr.writen1(simpleVdFloat32) | ||||
| 	bigen.writeUint32(e.e.w(), math.Float32bits(f)) | ||||
| 	e.w.writen1(simpleVdFloat32) | ||||
| 	e.w.writen4(bigen.PutUint32(math.Float32bits(f))) | ||||
| } | ||||
| 
 | ||||
| func (e *simpleEncDriver) EncodeFloat64(f float64) { | ||||
| func (e *simpleEncDriver[T]) EncodeFloat64(f float64) { | ||||
| 	if e.h.EncZeroValuesAsNil && e.e.c != containerMapKey && f == 0.0 { | ||||
| 		e.EncodeNil() | ||||
| 		return | ||||
| 	} | ||||
| 	e.e.encWr.writen1(simpleVdFloat64) | ||||
| 	bigen.writeUint64(e.e.w(), math.Float64bits(f)) | ||||
| 	e.w.writen1(simpleVdFloat64) | ||||
| 	e.w.writen8(bigen.PutUint64(math.Float64bits(f))) | ||||
| } | ||||
| 
 | ||||
| func (e *simpleEncDriver) EncodeInt(v int64) { | ||||
| func (e *simpleEncDriver[T]) EncodeInt(v int64) { | ||||
| 	if v < 0 { | ||||
| 		e.encUint(uint64(-v), simpleVdNegInt) | ||||
| 	} else { | ||||
|  | @ -113,62 +67,62 @@ func (e *simpleEncDriver) EncodeInt(v int64) { | |||
| 	} | ||||
| } | ||||
| 
 | ||||
| func (e *simpleEncDriver) EncodeUint(v uint64) { | ||||
| func (e *simpleEncDriver[T]) EncodeUint(v uint64) { | ||||
| 	e.encUint(v, simpleVdPosInt) | ||||
| } | ||||
| 
 | ||||
| func (e *simpleEncDriver) encUint(v uint64, bd uint8) { | ||||
| func (e *simpleEncDriver[T]) encUint(v uint64, bd uint8) { | ||||
| 	if e.h.EncZeroValuesAsNil && e.e.c != containerMapKey && v == 0 { | ||||
| 		e.EncodeNil() | ||||
| 		return | ||||
| 	} | ||||
| 	if v <= math.MaxUint8 { | ||||
| 		e.e.encWr.writen2(bd, uint8(v)) | ||||
| 		e.w.writen2(bd, uint8(v)) | ||||
| 	} else if v <= math.MaxUint16 { | ||||
| 		e.e.encWr.writen1(bd + 1) | ||||
| 		bigen.writeUint16(e.e.w(), uint16(v)) | ||||
| 		e.w.writen1(bd + 1) | ||||
| 		e.w.writen2(bigen.PutUint16(uint16(v))) | ||||
| 	} else if v <= math.MaxUint32 { | ||||
| 		e.e.encWr.writen1(bd + 2) | ||||
| 		bigen.writeUint32(e.e.w(), uint32(v)) | ||||
| 		e.w.writen1(bd + 2) | ||||
| 		e.w.writen4(bigen.PutUint32(uint32(v))) | ||||
| 	} else { // if v <= math.MaxUint64 { | ||||
| 		e.e.encWr.writen1(bd + 3) | ||||
| 		bigen.writeUint64(e.e.w(), v) | ||||
| 		e.w.writen1(bd + 3) | ||||
| 		e.w.writen8(bigen.PutUint64(v)) | ||||
| 	} | ||||
| } | ||||
| 
 | ||||
| func (e *simpleEncDriver) encLen(bd byte, length int) { | ||||
| func (e *simpleEncDriver[T]) encLen(bd byte, length int) { | ||||
| 	if length == 0 { | ||||
| 		e.e.encWr.writen1(bd) | ||||
| 		e.w.writen1(bd) | ||||
| 	} else if length <= math.MaxUint8 { | ||||
| 		e.e.encWr.writen1(bd + 1) | ||||
| 		e.e.encWr.writen1(uint8(length)) | ||||
| 		e.w.writen1(bd + 1) | ||||
| 		e.w.writen1(uint8(length)) | ||||
| 	} else if length <= math.MaxUint16 { | ||||
| 		e.e.encWr.writen1(bd + 2) | ||||
| 		bigen.writeUint16(e.e.w(), uint16(length)) | ||||
| 		e.w.writen1(bd + 2) | ||||
| 		e.w.writen2(bigen.PutUint16(uint16(length))) | ||||
| 	} else if int64(length) <= math.MaxUint32 { | ||||
| 		e.e.encWr.writen1(bd + 3) | ||||
| 		bigen.writeUint32(e.e.w(), uint32(length)) | ||||
| 		e.w.writen1(bd + 3) | ||||
| 		e.w.writen4(bigen.PutUint32(uint32(length))) | ||||
| 	} else { | ||||
| 		e.e.encWr.writen1(bd + 4) | ||||
| 		bigen.writeUint64(e.e.w(), uint64(length)) | ||||
| 		e.w.writen1(bd + 4) | ||||
| 		e.w.writen8(bigen.PutUint64(uint64(length))) | ||||
| 	} | ||||
| } | ||||
| 
 | ||||
| func (e *simpleEncDriver) EncodeExt(v interface{}, basetype reflect.Type, xtag uint64, ext Ext) { | ||||
| func (e *simpleEncDriver[T]) EncodeExt(v interface{}, basetype reflect.Type, xtag uint64, ext Ext) { | ||||
| 	var bs0, bs []byte | ||||
| 	if ext == SelfExt { | ||||
| 		bs0 = e.e.blist.get(1024) | ||||
| 		bs = bs0 | ||||
| 		e.e.sideEncode(v, basetype, &bs) | ||||
| 		sideEncode(e.h, &e.h.sideEncPool, func(se encoderI) { oneOffEncode(se, v, &bs, basetype, true) }) | ||||
| 	} else { | ||||
| 		bs = ext.WriteExt(v) | ||||
| 	} | ||||
| 	if bs == nil { | ||||
| 		e.EncodeNil() | ||||
| 		e.writeNilBytes() | ||||
| 		goto END | ||||
| 	} | ||||
| 	e.encodeExtPreamble(uint8(xtag), len(bs)) | ||||
| 	e.e.encWr.writeb(bs) | ||||
| 	e.w.writeb(bs) | ||||
| END: | ||||
| 	if ext == SelfExt { | ||||
| 		e.e.blist.put(bs) | ||||
|  | @ -178,25 +132,35 @@ END: | |||
| 	} | ||||
| } | ||||
| 
 | ||||
| func (e *simpleEncDriver) EncodeRawExt(re *RawExt) { | ||||
| func (e *simpleEncDriver[T]) EncodeRawExt(re *RawExt) { | ||||
| 	e.encodeExtPreamble(uint8(re.Tag), len(re.Data)) | ||||
| 	e.e.encWr.writeb(re.Data) | ||||
| 	e.w.writeb(re.Data) | ||||
| } | ||||
| 
 | ||||
| func (e *simpleEncDriver) encodeExtPreamble(xtag byte, length int) { | ||||
| func (e *simpleEncDriver[T]) encodeExtPreamble(xtag byte, length int) { | ||||
| 	e.encLen(simpleVdExt, length) | ||||
| 	e.e.encWr.writen1(xtag) | ||||
| 	e.w.writen1(xtag) | ||||
| } | ||||
| 
 | ||||
| func (e *simpleEncDriver) WriteArrayStart(length int) { | ||||
| func (e *simpleEncDriver[T]) WriteArrayStart(length int) { | ||||
| 	e.encLen(simpleVdArray, length) | ||||
| } | ||||
| 
 | ||||
| func (e *simpleEncDriver) WriteMapStart(length int) { | ||||
| func (e *simpleEncDriver[T]) WriteMapStart(length int) { | ||||
| 	e.encLen(simpleVdMap, length) | ||||
| } | ||||
| 
 | ||||
| func (e *simpleEncDriver) EncodeString(v string) { | ||||
| func (e *simpleEncDriver[T]) WriteArrayEmpty() { | ||||
| 	// e.WriteArrayStart(0) = e.encLen(simpleVdArray, 0) | ||||
| 	e.w.writen1(simpleVdArray) | ||||
| } | ||||
| 
 | ||||
| func (e *simpleEncDriver[T]) WriteMapEmpty() { | ||||
| 	// e.WriteMapStart(0) = e.encLen(simpleVdMap, 0) | ||||
| 	e.w.writen1(simpleVdMap) | ||||
| } | ||||
| 
 | ||||
| func (e *simpleEncDriver[T]) EncodeString(v string) { | ||||
| 	if e.h.EncZeroValuesAsNil && e.e.c != containerMapKey && v == "" { | ||||
| 		e.EncodeNil() | ||||
| 		return | ||||
|  | @ -206,57 +170,88 @@ func (e *simpleEncDriver) EncodeString(v string) { | |||
| 	} else { | ||||
| 		e.encLen(simpleVdString, len(v)) | ||||
| 	} | ||||
| 	e.e.encWr.writestr(v) | ||||
| 	e.w.writestr(v) | ||||
| } | ||||
| 
 | ||||
| func (e *simpleEncDriver) EncodeStringBytesRaw(v []byte) { | ||||
| func (e *simpleEncDriver[T]) EncodeStringNoEscape4Json(v string) { e.EncodeString(v) } | ||||
| 
 | ||||
| func (e *simpleEncDriver[T]) EncodeStringBytesRaw(v []byte) { | ||||
| 	// if e.h.EncZeroValuesAsNil && e.c != containerMapKey && v == nil { | ||||
| 	e.encLen(simpleVdByteArray, len(v)) | ||||
| 	e.w.writeb(v) | ||||
| } | ||||
| 
 | ||||
| func (e *simpleEncDriver[T]) EncodeBytes(v []byte) { | ||||
| 	if v == nil { | ||||
| 		e.EncodeNil() | ||||
| 		e.writeNilBytes() | ||||
| 		return | ||||
| 	} | ||||
| 	e.encLen(simpleVdByteArray, len(v)) | ||||
| 	e.e.encWr.writeb(v) | ||||
| 	e.EncodeStringBytesRaw(v) | ||||
| } | ||||
| 
 | ||||
| func (e *simpleEncDriver) EncodeTime(t time.Time) { | ||||
| func (e *simpleEncDriver[T]) encodeNilBytes() { | ||||
| 	b := byte(simpleVdNil) | ||||
| 	if e.h.NilCollectionToZeroLength { | ||||
| 		b = simpleVdArray | ||||
| 	} | ||||
| 	e.w.writen1(b) | ||||
| } | ||||
| 
 | ||||
| func (e *simpleEncDriver[T]) writeNilOr(v byte) { | ||||
| 	if !e.h.NilCollectionToZeroLength { | ||||
| 		v = simpleVdNil | ||||
| 	} | ||||
| 	e.w.writen1(v) | ||||
| } | ||||
| 
 | ||||
| func (e *simpleEncDriver[T]) writeNilArray() { | ||||
| 	e.writeNilOr(simpleVdArray) | ||||
| } | ||||
| 
 | ||||
| func (e *simpleEncDriver[T]) writeNilMap() { | ||||
| 	e.writeNilOr(simpleVdMap) | ||||
| } | ||||
| 
 | ||||
| func (e *simpleEncDriver[T]) writeNilBytes() { | ||||
| 	e.writeNilOr(simpleVdByteArray) | ||||
| } | ||||
| 
 | ||||
| func (e *simpleEncDriver[T]) EncodeTime(t time.Time) { | ||||
| 	// if e.h.EncZeroValuesAsNil && e.c != containerMapKey && t.IsZero() { | ||||
| 	if t.IsZero() { | ||||
| 		e.EncodeNil() | ||||
| 		return | ||||
| 	} | ||||
| 	v, err := t.MarshalBinary() | ||||
| 	e.e.onerror(err) | ||||
| 	e.e.encWr.writen2(simpleVdTime, uint8(len(v))) | ||||
| 	e.e.encWr.writeb(v) | ||||
| 	halt.onerror(err) | ||||
| 	e.w.writen2(simpleVdTime, uint8(len(v))) | ||||
| 	e.w.writeb(v) | ||||
| } | ||||
| 
 | ||||
| //------------------------------------ | ||||
| 
 | ||||
| type simpleDecDriver struct { | ||||
| type simpleDecDriver[T decReader] struct { | ||||
| 	h *SimpleHandle | ||||
| 	d *decoderBase | ||||
| 	r T | ||||
| 
 | ||||
| 	bdAndBdread | ||||
| 	_ bool | ||||
| 	// bytes bool | ||||
| 
 | ||||
| 	noBuiltInTypes | ||||
| 	// decDriverNoopNumberHelper | ||||
| 	decDriverNoopContainerReader | ||||
| 	decDriverNoopNumberHelper | ||||
| 	d Decoder | ||||
| 	decInit2er | ||||
| 
 | ||||
| 	// ds interface{} // must be *decoder[simpleDecDriverM[bytes...]] | ||||
| } | ||||
| 
 | ||||
| func (d *simpleDecDriver) decoder() *Decoder { | ||||
| 	return &d.d | ||||
| } | ||||
| 
 | ||||
| func (d *simpleDecDriver) descBd() string { | ||||
| 	return sprintf("%v (%s)", d.bd, simpledesc(d.bd)) | ||||
| } | ||||
| 
 | ||||
| func (d *simpleDecDriver) readNextBd() { | ||||
| 	d.bd = d.d.decRd.readn1() | ||||
| func (d *simpleDecDriver[T]) readNextBd() { | ||||
| 	d.bd = d.r.readn1() | ||||
| 	d.bdRead = true | ||||
| } | ||||
| 
 | ||||
| func (d *simpleDecDriver) advanceNil() (null bool) { | ||||
| func (d *simpleDecDriver[T]) advanceNil() (null bool) { | ||||
| 	if !d.bdRead { | ||||
| 		d.readNextBd() | ||||
| 	} | ||||
|  | @ -267,7 +262,7 @@ func (d *simpleDecDriver) advanceNil() (null bool) { | |||
| 	return | ||||
| } | ||||
| 
 | ||||
| func (d *simpleDecDriver) ContainerType() (vt valueType) { | ||||
| func (d *simpleDecDriver[T]) ContainerType() (vt valueType) { | ||||
| 	if !d.bdRead { | ||||
| 		d.readNextBd() | ||||
| 	} | ||||
|  | @ -291,88 +286,90 @@ func (d *simpleDecDriver) ContainerType() (vt valueType) { | |||
| 	return valueTypeUnset | ||||
| } | ||||
| 
 | ||||
| func (d *simpleDecDriver) TryNil() bool { | ||||
| func (d *simpleDecDriver[T]) TryNil() bool { | ||||
| 	return d.advanceNil() | ||||
| } | ||||
| 
 | ||||
| func (d *simpleDecDriver) decFloat() (f float64, ok bool) { | ||||
| func (d *simpleDecDriver[T]) decFloat() (f float64, ok bool) { | ||||
| 	ok = true | ||||
| 	switch d.bd { | ||||
| 	case simpleVdFloat32: | ||||
| 		f = float64(math.Float32frombits(bigen.Uint32(d.d.decRd.readn4()))) | ||||
| 		f = float64(math.Float32frombits(bigen.Uint32(d.r.readn4()))) | ||||
| 	case simpleVdFloat64: | ||||
| 		f = math.Float64frombits(bigen.Uint64(d.d.decRd.readn8())) | ||||
| 		f = math.Float64frombits(bigen.Uint64(d.r.readn8())) | ||||
| 	default: | ||||
| 		ok = false | ||||
| 	} | ||||
| 	return | ||||
| } | ||||
| 
 | ||||
| func (d *simpleDecDriver) decInteger() (ui uint64, neg, ok bool) { | ||||
| func (d *simpleDecDriver[T]) decInteger() (ui uint64, neg, ok bool) { | ||||
| 	ok = true | ||||
| 	switch d.bd { | ||||
| 	case simpleVdPosInt: | ||||
| 		ui = uint64(d.d.decRd.readn1()) | ||||
| 		ui = uint64(d.r.readn1()) | ||||
| 	case simpleVdPosInt + 1: | ||||
| 		ui = uint64(bigen.Uint16(d.d.decRd.readn2())) | ||||
| 		ui = uint64(bigen.Uint16(d.r.readn2())) | ||||
| 	case simpleVdPosInt + 2: | ||||
| 		ui = uint64(bigen.Uint32(d.d.decRd.readn4())) | ||||
| 		ui = uint64(bigen.Uint32(d.r.readn4())) | ||||
| 	case simpleVdPosInt + 3: | ||||
| 		ui = uint64(bigen.Uint64(d.d.decRd.readn8())) | ||||
| 		ui = uint64(bigen.Uint64(d.r.readn8())) | ||||
| 	case simpleVdNegInt: | ||||
| 		ui = uint64(d.d.decRd.readn1()) | ||||
| 		ui = uint64(d.r.readn1()) | ||||
| 		neg = true | ||||
| 	case simpleVdNegInt + 1: | ||||
| 		ui = uint64(bigen.Uint16(d.d.decRd.readn2())) | ||||
| 		ui = uint64(bigen.Uint16(d.r.readn2())) | ||||
| 		neg = true | ||||
| 	case simpleVdNegInt + 2: | ||||
| 		ui = uint64(bigen.Uint32(d.d.decRd.readn4())) | ||||
| 		ui = uint64(bigen.Uint32(d.r.readn4())) | ||||
| 		neg = true | ||||
| 	case simpleVdNegInt + 3: | ||||
| 		ui = uint64(bigen.Uint64(d.d.decRd.readn8())) | ||||
| 		ui = uint64(bigen.Uint64(d.r.readn8())) | ||||
| 		neg = true | ||||
| 	default: | ||||
| 		ok = false | ||||
| 		// d.d.errorf("integer only valid from pos/neg integer1..8. Invalid descriptor: %v", d.bd) | ||||
| 		// halt.errorf("integer only valid from pos/neg integer1..8. Invalid descriptor: %v", d.bd) | ||||
| 	} | ||||
| 	// DO NOT do this check below, because callers may only want the unsigned value: | ||||
| 	// | ||||
| 	// if ui > math.MaxInt64 { | ||||
| 	// 	d.d.errorf("decIntAny: Integer out of range for signed int64: %v", ui) | ||||
| 	// 	halt.errorf("decIntAny: Integer out of range for signed int64: %v", ui) | ||||
| 	//		return | ||||
| 	// } | ||||
| 	return | ||||
| } | ||||
| 
 | ||||
| func (d *simpleDecDriver) DecodeInt64() (i int64) { | ||||
| func (d *simpleDecDriver[T]) DecodeInt64() (i int64) { | ||||
| 	if d.advanceNil() { | ||||
| 		return | ||||
| 	} | ||||
| 	i = decNegintPosintFloatNumberHelper{&d.d}.int64(d.decInteger()) | ||||
| 	v1, v2, v3 := d.decInteger() | ||||
| 	i = decNegintPosintFloatNumberHelper{d}.int64(v1, v2, v3, false) | ||||
| 	d.bdRead = false | ||||
| 	return | ||||
| } | ||||
| 
 | ||||
| func (d *simpleDecDriver) DecodeUint64() (ui uint64) { | ||||
| func (d *simpleDecDriver[T]) DecodeUint64() (ui uint64) { | ||||
| 	if d.advanceNil() { | ||||
| 		return | ||||
| 	} | ||||
| 	ui = decNegintPosintFloatNumberHelper{&d.d}.uint64(d.decInteger()) | ||||
| 	ui = decNegintPosintFloatNumberHelper{d}.uint64(d.decInteger()) | ||||
| 	d.bdRead = false | ||||
| 	return | ||||
| } | ||||
| 
 | ||||
| func (d *simpleDecDriver) DecodeFloat64() (f float64) { | ||||
| func (d *simpleDecDriver[T]) DecodeFloat64() (f float64) { | ||||
| 	if d.advanceNil() { | ||||
| 		return | ||||
| 	} | ||||
| 	f = decNegintPosintFloatNumberHelper{&d.d}.float64(d.decFloat()) | ||||
| 	v1, v2 := d.decFloat() | ||||
| 	f = decNegintPosintFloatNumberHelper{d}.float64(v1, v2, false) | ||||
| 	d.bdRead = false | ||||
| 	return | ||||
| } | ||||
| 
 | ||||
| // bool can be decoded from bool only (single byte). | ||||
| func (d *simpleDecDriver) DecodeBool() (b bool) { | ||||
| func (d *simpleDecDriver[T]) DecodeBool() (b bool) { | ||||
| 	if d.advanceNil() { | ||||
| 		return | ||||
| 	} | ||||
|  | @ -380,13 +377,13 @@ func (d *simpleDecDriver) DecodeBool() (b bool) { | |||
| 	} else if d.bd == simpleVdTrue { | ||||
| 		b = true | ||||
| 	} else { | ||||
| 		d.d.errorf("cannot decode bool - %s: %x", msgBadDesc, d.bd) | ||||
| 		halt.errorf("cannot decode bool - %s: %x", msgBadDesc, d.bd) | ||||
| 	} | ||||
| 	d.bdRead = false | ||||
| 	return | ||||
| } | ||||
| 
 | ||||
| func (d *simpleDecDriver) ReadMapStart() (length int) { | ||||
| func (d *simpleDecDriver[T]) ReadMapStart() (length int) { | ||||
| 	if d.advanceNil() { | ||||
| 		return containerLenNil | ||||
| 	} | ||||
|  | @ -394,7 +391,7 @@ func (d *simpleDecDriver) ReadMapStart() (length int) { | |||
| 	return d.decLen() | ||||
| } | ||||
| 
 | ||||
| func (d *simpleDecDriver) ReadArrayStart() (length int) { | ||||
| func (d *simpleDecDriver[T]) ReadArrayStart() (length int) { | ||||
| 	if d.advanceNil() { | ||||
| 		return containerLenNil | ||||
| 	} | ||||
|  | @ -402,131 +399,128 @@ func (d *simpleDecDriver) ReadArrayStart() (length int) { | |||
| 	return d.decLen() | ||||
| } | ||||
| 
 | ||||
| func (d *simpleDecDriver) uint2Len(ui uint64) int { | ||||
| func (d *simpleDecDriver[T]) uint2Len(ui uint64) int { | ||||
| 	if chkOvf.Uint(ui, intBitsize) { | ||||
| 		d.d.errorf("overflow integer: %v", ui) | ||||
| 		halt.errorf("overflow integer: %v", ui) | ||||
| 	} | ||||
| 	return int(ui) | ||||
| } | ||||
| 
 | ||||
| func (d *simpleDecDriver) decLen() int { | ||||
| func (d *simpleDecDriver[T]) decLen() int { | ||||
| 	switch d.bd & 7 { // d.bd % 8 { | ||||
| 	case 0: | ||||
| 		return 0 | ||||
| 	case 1: | ||||
| 		return int(d.d.decRd.readn1()) | ||||
| 		return int(d.r.readn1()) | ||||
| 	case 2: | ||||
| 		return int(bigen.Uint16(d.d.decRd.readn2())) | ||||
| 		return int(bigen.Uint16(d.r.readn2())) | ||||
| 	case 3: | ||||
| 		return d.uint2Len(uint64(bigen.Uint32(d.d.decRd.readn4()))) | ||||
| 		return d.uint2Len(uint64(bigen.Uint32(d.r.readn4()))) | ||||
| 	case 4: | ||||
| 		return d.uint2Len(bigen.Uint64(d.d.decRd.readn8())) | ||||
| 		return d.uint2Len(bigen.Uint64(d.r.readn8())) | ||||
| 	} | ||||
| 	d.d.errorf("cannot read length: bd%%8 must be in range 0..4. Got: %d", d.bd%8) | ||||
| 	halt.errorf("cannot read length: bd%%8 must be in range 0..4. Got: %d", d.bd%8) | ||||
| 	return -1 | ||||
| } | ||||
| 
 | ||||
| func (d *simpleDecDriver) DecodeStringAsBytes() (s []byte) { | ||||
| 	return d.DecodeBytes(nil) | ||||
| func (d *simpleDecDriver[T]) DecodeStringAsBytes() ([]byte, dBytesAttachState) { | ||||
| 	return d.DecodeBytes() | ||||
| } | ||||
| 
 | ||||
| func (d *simpleDecDriver) DecodeBytes(bs []byte) (bsOut []byte) { | ||||
| 	d.d.decByteState = decByteStateNone | ||||
| func (d *simpleDecDriver[T]) DecodeBytes() (bs []byte, state dBytesAttachState) { | ||||
| 	if d.advanceNil() { | ||||
| 		return | ||||
| 	} | ||||
| 	var cond bool | ||||
| 	// check if an "array" of uint8's (see ContainerType for how to infer if an array) | ||||
| 	if d.bd >= simpleVdArray && d.bd <= simpleVdMap+4 { | ||||
| 		if bs == nil { | ||||
| 			d.d.decByteState = decByteStateReuseBuf | ||||
| 			bs = d.d.b[:] | ||||
| 		} | ||||
| 	if d.bd >= simpleVdArray && d.bd <= simpleVdArray+4 { | ||||
| 		slen := d.ReadArrayStart() | ||||
| 		var changed bool | ||||
| 		if bs, changed = usableByteSlice(bs, slen); changed { | ||||
| 			d.d.decByteState = decByteStateNone | ||||
| 		} | ||||
| 		bs, cond = usableByteSlice(d.d.buf, slen) | ||||
| 		for i := 0; i < len(bs); i++ { | ||||
| 			bs[i] = uint8(chkOvf.UintV(d.DecodeUint64(), 8)) | ||||
| 		} | ||||
| 		for i := len(bs); i < slen; i++ { | ||||
| 			bs = append(bs, uint8(chkOvf.UintV(d.DecodeUint64(), 8))) | ||||
| 		} | ||||
| 		return bs | ||||
| 		if cond { | ||||
| 			d.d.buf = bs | ||||
| 		} | ||||
| 		state = dBytesAttachBuffer | ||||
| 
 | ||||
| 		return | ||||
| 	} | ||||
| 
 | ||||
| 	clen := d.decLen() | ||||
| 	d.bdRead = false | ||||
| 	if d.d.zerocopy() { | ||||
| 		d.d.decByteState = decByteStateZerocopy | ||||
| 		return d.d.decRd.rb.readx(uint(clen)) | ||||
| 	} | ||||
| 	if bs == nil { | ||||
| 		d.d.decByteState = decByteStateReuseBuf | ||||
| 		bs = d.d.b[:] | ||||
| 	} | ||||
| 	return decByteSlice(d.d.r(), clen, d.d.h.MaxInitLen, bs) | ||||
| 	bs, cond = d.r.readxb(uint(clen)) | ||||
| 	state = d.d.attachState(cond) | ||||
| 	return | ||||
| } | ||||
| 
 | ||||
| func (d *simpleDecDriver) DecodeTime() (t time.Time) { | ||||
| func (d *simpleDecDriver[T]) DecodeTime() (t time.Time) { | ||||
| 	if d.advanceNil() { | ||||
| 		return | ||||
| 	} | ||||
| 	if d.bd != simpleVdTime { | ||||
| 		d.d.errorf("invalid descriptor for time.Time - expect 0x%x, received 0x%x", simpleVdTime, d.bd) | ||||
| 		halt.errorf("invalid descriptor for time.Time - expect 0x%x, received 0x%x", simpleVdTime, d.bd) | ||||
| 	} | ||||
| 	d.bdRead = false | ||||
| 	clen := uint(d.d.decRd.readn1()) | ||||
| 	b := d.d.decRd.readx(clen) | ||||
| 	d.d.onerror((&t).UnmarshalBinary(b)) | ||||
| 	clen := uint(d.r.readn1()) | ||||
| 	b := d.r.readx(clen) | ||||
| 	halt.onerror((&t).UnmarshalBinary(b)) | ||||
| 	return | ||||
| } | ||||
| 
 | ||||
| func (d *simpleDecDriver) DecodeExt(rv interface{}, basetype reflect.Type, xtag uint64, ext Ext) { | ||||
| 	if xtag > 0xff { | ||||
| 		d.d.errorf("ext: tag must be <= 0xff; got: %v", xtag) | ||||
| 	} | ||||
| 	if d.advanceNil() { | ||||
| func (d *simpleDecDriver[T]) DecodeExt(rv interface{}, basetype reflect.Type, xtag uint64, ext Ext) { | ||||
| 	xbs, _, _, ok := d.decodeExtV(ext != nil, xtag) | ||||
| 	if !ok { | ||||
| 		return | ||||
| 	} | ||||
| 	xbs, realxtag1, zerocopy := d.decodeExtV(ext != nil, uint8(xtag)) | ||||
| 	realxtag := uint64(realxtag1) | ||||
| 	if ext == nil { | ||||
| 		re := rv.(*RawExt) | ||||
| 		re.Tag = realxtag | ||||
| 		re.setData(xbs, zerocopy) | ||||
| 	} else if ext == SelfExt { | ||||
| 		d.d.sideDecode(rv, basetype, xbs) | ||||
| 	if ext == SelfExt { | ||||
| 		sideDecode(d.h, &d.h.sideDecPool, func(sd decoderI) { oneOffDecode(sd, rv, xbs, basetype, true) }) | ||||
| 	} else { | ||||
| 		ext.ReadExt(rv, xbs) | ||||
| 	} | ||||
| } | ||||
| 
 | ||||
| func (d *simpleDecDriver) decodeExtV(verifyTag bool, tag byte) (xbs []byte, xtag byte, zerocopy bool) { | ||||
| func (d *simpleDecDriver[T]) DecodeRawExt(re *RawExt) { | ||||
| 	xbs, realxtag, state, ok := d.decodeExtV(false, 0) | ||||
| 	if !ok { | ||||
| 		return | ||||
| 	} | ||||
| 	re.Tag = uint64(realxtag) | ||||
| 	re.setData(xbs, state >= dBytesAttachViewZerocopy) | ||||
| } | ||||
| 
 | ||||
| func (d *simpleDecDriver[T]) decodeExtV(verifyTag bool, xtagIn uint64) (xbs []byte, xtag byte, bstate dBytesAttachState, ok bool) { | ||||
| 	if xtagIn > 0xff { | ||||
| 		halt.errorf("ext: tag must be <= 0xff; got: %v", xtagIn) | ||||
| 	} | ||||
| 	if d.advanceNil() { | ||||
| 		return | ||||
| 	} | ||||
| 	tag := uint8(xtagIn) | ||||
| 	switch d.bd { | ||||
| 	case simpleVdExt, simpleVdExt + 1, simpleVdExt + 2, simpleVdExt + 3, simpleVdExt + 4: | ||||
| 		l := d.decLen() | ||||
| 		xtag = d.d.decRd.readn1() | ||||
| 		xtag = d.r.readn1() | ||||
| 		if verifyTag && xtag != tag { | ||||
| 			d.d.errorf("wrong extension tag. Got %b. Expecting: %v", xtag, tag) | ||||
| 		} | ||||
| 		if d.d.bytes { | ||||
| 			xbs = d.d.decRd.rb.readx(uint(l)) | ||||
| 			zerocopy = true | ||||
| 		} else { | ||||
| 			xbs = decByteSlice(d.d.r(), l, d.d.h.MaxInitLen, d.d.b[:]) | ||||
| 			halt.errorf("wrong extension tag. Got %b. Expecting: %v", xtag, tag) | ||||
| 		} | ||||
| 		xbs, ok = d.r.readxb(uint(l)) | ||||
| 		bstate = d.d.attachState(ok) | ||||
| 	case simpleVdByteArray, simpleVdByteArray + 1, | ||||
| 		simpleVdByteArray + 2, simpleVdByteArray + 3, simpleVdByteArray + 4: | ||||
| 		xbs = d.DecodeBytes(nil) | ||||
| 		xbs, bstate = d.DecodeBytes() | ||||
| 	default: | ||||
| 		d.d.errorf("ext - %s - expecting extensions/bytearray, got: 0x%x", msgBadDesc, d.bd) | ||||
| 		halt.errorf("ext - %s - expecting extensions/bytearray, got: 0x%x", msgBadDesc, d.bd) | ||||
| 	} | ||||
| 	d.bdRead = false | ||||
| 	ok = true | ||||
| 	return | ||||
| } | ||||
| 
 | ||||
| func (d *simpleDecDriver) DecodeNaked() { | ||||
| func (d *simpleDecDriver[T]) DecodeNaked() { | ||||
| 	if !d.bdRead { | ||||
| 		d.readNextBd() | ||||
| 	} | ||||
|  | @ -566,19 +560,20 @@ func (d *simpleDecDriver) DecodeNaked() { | |||
| 	case simpleVdString, simpleVdString + 1, | ||||
| 		simpleVdString + 2, simpleVdString + 3, simpleVdString + 4: | ||||
| 		n.v = valueTypeString | ||||
| 		n.s = d.d.stringZC(d.DecodeStringAsBytes()) | ||||
| 		n.s = d.d.detach2Str(d.DecodeStringAsBytes()) | ||||
| 	case simpleVdByteArray, simpleVdByteArray + 1, | ||||
| 		simpleVdByteArray + 2, simpleVdByteArray + 3, simpleVdByteArray + 4: | ||||
| 		d.d.fauxUnionReadRawBytes(false) | ||||
| 		d.d.fauxUnionReadRawBytes(d, false, d.h.RawToString) //, d.h.ZeroCopy) | ||||
| 	case simpleVdExt, simpleVdExt + 1, simpleVdExt + 2, simpleVdExt + 3, simpleVdExt + 4: | ||||
| 		n.v = valueTypeExt | ||||
| 		l := d.decLen() | ||||
| 		n.u = uint64(d.d.decRd.readn1()) | ||||
| 		if d.d.bytes { | ||||
| 			n.l = d.d.decRd.rb.readx(uint(l)) | ||||
| 		} else { | ||||
| 			n.l = decByteSlice(d.d.r(), l, d.d.h.MaxInitLen, d.d.b[:]) | ||||
| 		} | ||||
| 		n.u = uint64(d.r.readn1()) | ||||
| 		n.l = d.r.readx(uint(l)) | ||||
| 		// MARKER: not necessary to detach for extensions | ||||
| 		// var useBuf bool | ||||
| 		// n.l, useBuf = d.r.readxb(uint(l)) | ||||
| 		// n.a = d.d.attachState(useBuf) | ||||
| 		// n.l = d.d.detach2Bytes(n.l, nil, n.a) | ||||
| 	case simpleVdArray, simpleVdArray + 1, simpleVdArray + 2, | ||||
| 		simpleVdArray + 3, simpleVdArray + 4: | ||||
| 		n.v = valueTypeArray | ||||
|  | @ -587,7 +582,7 @@ func (d *simpleDecDriver) DecodeNaked() { | |||
| 		n.v = valueTypeMap | ||||
| 		decodeFurther = true | ||||
| 	default: | ||||
| 		d.d.errorf("cannot infer value - %s 0x%x", msgBadDesc, d.bd) | ||||
| 		halt.errorf("cannot infer value - %s 0x%x", msgBadDesc, d.bd) | ||||
| 	} | ||||
| 
 | ||||
| 	if !decodeFurther { | ||||
|  | @ -595,32 +590,18 @@ func (d *simpleDecDriver) DecodeNaked() { | |||
| 	} | ||||
| } | ||||
| 
 | ||||
| func (d *simpleDecDriver) nextValueBytes(v0 []byte) (v []byte) { | ||||
| func (d *simpleDecDriver[T]) nextValueBytes() (v []byte) { | ||||
| 	if !d.bdRead { | ||||
| 		d.readNextBd() | ||||
| 	} | ||||
| 	v = v0 | ||||
| 	var h = decNextValueBytesHelper{d: &d.d} | ||||
| 	var cursor = d.d.rb.c - 1 | ||||
| 	h.append1(&v, d.bd) | ||||
| 	v = d.nextValueBytesBdReadR(v) | ||||
| 	d.r.startRecording() | ||||
| 	d.nextValueBytesBdReadR() | ||||
| 	v = d.r.stopRecording() | ||||
| 	d.bdRead = false | ||||
| 	h.bytesRdV(&v, cursor) | ||||
| 	return | ||||
| } | ||||
| 
 | ||||
| func (d *simpleDecDriver) nextValueBytesR(v0 []byte) (v []byte) { | ||||
| 	d.readNextBd() | ||||
| 	v = v0 | ||||
| 	var h = decNextValueBytesHelper{d: &d.d} | ||||
| 	h.append1(&v, d.bd) | ||||
| 	return d.nextValueBytesBdReadR(v) | ||||
| } | ||||
| 
 | ||||
| func (d *simpleDecDriver) nextValueBytesBdReadR(v0 []byte) (v []byte) { | ||||
| 	v = v0 | ||||
| 	var h = decNextValueBytesHelper{d: &d.d} | ||||
| 
 | ||||
| func (d *simpleDecDriver[T]) nextValueBytesBdReadR() { | ||||
| 	c := d.bd | ||||
| 
 | ||||
| 	var length uint | ||||
|  | @ -629,38 +610,33 @@ func (d *simpleDecDriver) nextValueBytesBdReadR(v0 []byte) (v []byte) { | |||
| 	case simpleVdNil, simpleVdFalse, simpleVdTrue, simpleVdString, simpleVdByteArray: | ||||
| 		// pass | ||||
| 	case simpleVdPosInt, simpleVdNegInt: | ||||
| 		h.append1(&v, d.d.decRd.readn1()) | ||||
| 		d.r.readn1() | ||||
| 	case simpleVdPosInt + 1, simpleVdNegInt + 1: | ||||
| 		h.appendN(&v, d.d.decRd.readx(2)...) | ||||
| 		d.r.skip(2) | ||||
| 	case simpleVdPosInt + 2, simpleVdNegInt + 2, simpleVdFloat32: | ||||
| 		h.appendN(&v, d.d.decRd.readx(4)...) | ||||
| 		d.r.skip(4) | ||||
| 	case simpleVdPosInt + 3, simpleVdNegInt + 3, simpleVdFloat64: | ||||
| 		h.appendN(&v, d.d.decRd.readx(8)...) | ||||
| 		d.r.skip(8) | ||||
| 	case simpleVdTime: | ||||
| 		c = d.d.decRd.readn1() | ||||
| 		h.append1(&v, c) | ||||
| 		h.appendN(&v, d.d.decRd.readx(uint(c))...) | ||||
| 		c = d.r.readn1() | ||||
| 		d.r.skip(uint(c)) | ||||
| 
 | ||||
| 	default: | ||||
| 		switch c & 7 { // c % 8 { | ||||
| 		case 0: | ||||
| 			length = 0 | ||||
| 		case 1: | ||||
| 			b := d.d.decRd.readn1() | ||||
| 			b := d.r.readn1() | ||||
| 			length = uint(b) | ||||
| 			h.append1(&v, b) | ||||
| 		case 2: | ||||
| 			x := d.d.decRd.readn2() | ||||
| 			x := d.r.readn2() | ||||
| 			length = uint(bigen.Uint16(x)) | ||||
| 			h.appendN(&v, x[:]...) | ||||
| 		case 3: | ||||
| 			x := d.d.decRd.readn4() | ||||
| 			x := d.r.readn4() | ||||
| 			length = uint(bigen.Uint32(x)) | ||||
| 			h.appendN(&v, x[:]...) | ||||
| 		case 4: | ||||
| 			x := d.d.decRd.readn8() | ||||
| 			x := d.r.readn8() | ||||
| 			length = uint(bigen.Uint64(x)) | ||||
| 			h.appendN(&v, x[:]...) | ||||
| 		} | ||||
| 
 | ||||
| 		bExt := c >= simpleVdExt && c <= simpleVdExt+7 | ||||
|  | @ -670,11 +646,11 @@ func (d *simpleDecDriver) nextValueBytesBdReadR(v0 []byte) (v []byte) { | |||
| 		bMap := c >= simpleVdMap && c <= simpleVdMap+7 | ||||
| 
 | ||||
| 		if !(bExt || bStr || bByteArray || bArray || bMap) { | ||||
| 			d.d.errorf("cannot infer value - %s 0x%x", msgBadDesc, c) | ||||
| 			halt.errorf("cannot infer value - %s 0x%x", msgBadDesc, c) | ||||
| 		} | ||||
| 
 | ||||
| 		if bExt { | ||||
| 			h.append1(&v, d.d.decRd.readn1()) // tag | ||||
| 			d.r.readn1() // tag | ||||
| 		} | ||||
| 
 | ||||
| 		if length == 0 { | ||||
|  | @ -683,68 +659,91 @@ func (d *simpleDecDriver) nextValueBytesBdReadR(v0 []byte) (v []byte) { | |||
| 
 | ||||
| 		if bArray { | ||||
| 			for i := uint(0); i < length; i++ { | ||||
| 				v = d.nextValueBytesR(v) | ||||
| 				d.readNextBd() | ||||
| 				d.nextValueBytesBdReadR() | ||||
| 			} | ||||
| 		} else if bMap { | ||||
| 			for i := uint(0); i < length; i++ { | ||||
| 				v = d.nextValueBytesR(v) | ||||
| 				v = d.nextValueBytesR(v) | ||||
| 				d.readNextBd() | ||||
| 				d.nextValueBytesBdReadR() | ||||
| 				d.readNextBd() | ||||
| 				d.nextValueBytesBdReadR() | ||||
| 			} | ||||
| 		} else { | ||||
| 			h.appendN(&v, d.d.decRd.readx(length)...) | ||||
| 			d.r.skip(length) | ||||
| 		} | ||||
| 	} | ||||
| 	return | ||||
| } | ||||
| 
 | ||||
| //------------------------------------ | ||||
| 
 | ||||
| // SimpleHandle is a Handle for a very simple encoding format. | ||||
| // ---- | ||||
| // | ||||
| // simple is a simplistic codec similar to binc, but not as compact. | ||||
| //   - Encoding of a value is always preceded by the descriptor byte (bd) | ||||
| //   - True, false, nil are encoded fully in 1 byte (the descriptor) | ||||
| //   - Integers (intXXX, uintXXX) are encoded in 1, 2, 4 or 8 bytes (plus a descriptor byte). | ||||
| //     There are positive (uintXXX and intXXX >= 0) and negative (intXXX < 0) integers. | ||||
| //   - Floats are encoded in 4 or 8 bytes (plus a descriptor byte) | ||||
| //   - Length of containers (strings, bytes, array, map, extensions) | ||||
| //     are encoded in 0, 1, 2, 4 or 8 bytes. | ||||
| //     Zero-length containers have no length encoded. | ||||
| //     For others, the number of bytes is given by pow(2, bd%3) | ||||
| //   - maps are encoded as [bd] [length] [[key][value]]... | ||||
| //   - arrays are encoded as [bd] [length] [value]... | ||||
| //   - extensions are encoded as [bd] [length] [tag] [byte]... | ||||
| //   - strings/bytearrays are encoded as [bd] [length] [byte]... | ||||
| //   - time.Time are encoded as [bd] [length] [byte]... | ||||
| // The following below are similar across all format files (except for the format name). | ||||
| // | ||||
| // The full spec will be published soon. | ||||
| type SimpleHandle struct { | ||||
| 	binaryEncodingType | ||||
| 	BasicHandle | ||||
| 	// EncZeroValuesAsNil says to encode zero values for numbers, bool, string, etc as nil | ||||
| 	EncZeroValuesAsNil bool | ||||
| // We keep them together here, so that we can easily copy and compare. | ||||
| 
 | ||||
| // ---- | ||||
| 
 | ||||
| func (d *simpleEncDriver[T]) init(hh Handle, shared *encoderBase, enc encoderI) (fp interface{}) { | ||||
| 	callMake(&d.w) | ||||
| 	d.h = hh.(*SimpleHandle) | ||||
| 	d.e = shared | ||||
| 	if shared.bytes { | ||||
| 		fp = simpleFpEncBytes | ||||
| 	} else { | ||||
| 		fp = simpleFpEncIO | ||||
| 	} | ||||
| 	// d.w.init() | ||||
| 	d.init2(enc) | ||||
| 	return | ||||
| } | ||||
| 
 | ||||
| // Name returns the name of the handle: simple | ||||
| func (h *SimpleHandle) Name() string { return "simple" } | ||||
| func (e *simpleEncDriver[T]) writeBytesAsis(b []byte) { e.w.writeb(b) } | ||||
| 
 | ||||
| func (h *SimpleHandle) desc(bd byte) string { return simpledesc(bd) } | ||||
| func (e *simpleEncDriver[T]) writerEnd() { e.w.end() } | ||||
| 
 | ||||
| func (h *SimpleHandle) newEncDriver() encDriver { | ||||
| 	var e = &simpleEncDriver{h: h} | ||||
| 	e.e.e = e | ||||
| 	e.e.init(h) | ||||
| 	e.reset() | ||||
| 	return e | ||||
| func (e *simpleEncDriver[T]) resetOutBytes(out *[]byte) { | ||||
| 	e.w.resetBytes(*out, out) | ||||
| } | ||||
| 
 | ||||
| func (h *SimpleHandle) newDecDriver() decDriver { | ||||
| 	d := &simpleDecDriver{h: h} | ||||
| 	d.d.d = d | ||||
| 	d.d.init(h) | ||||
| 	d.reset() | ||||
| 	return d | ||||
| func (e *simpleEncDriver[T]) resetOutIO(out io.Writer) { | ||||
| 	e.w.resetIO(out, e.h.WriterBufferSize, &e.e.blist) | ||||
| } | ||||
| 
 | ||||
| var _ decDriver = (*simpleDecDriver)(nil) | ||||
| var _ encDriver = (*simpleEncDriver)(nil) | ||||
| // ---- | ||||
| 
 | ||||
| func (d *simpleDecDriver[T]) init(hh Handle, shared *decoderBase, dec decoderI) (fp interface{}) { | ||||
| 	callMake(&d.r) | ||||
| 	d.h = hh.(*SimpleHandle) | ||||
| 	d.d = shared | ||||
| 	if shared.bytes { | ||||
| 		fp = simpleFpDecBytes | ||||
| 	} else { | ||||
| 		fp = simpleFpDecIO | ||||
| 	} | ||||
| 	// d.r.init() | ||||
| 	d.init2(dec) | ||||
| 	return | ||||
| } | ||||
| 
 | ||||
| func (d *simpleDecDriver[T]) NumBytesRead() int { | ||||
| 	return int(d.r.numread()) | ||||
| } | ||||
| 
 | ||||
| func (d *simpleDecDriver[T]) resetInBytes(in []byte) { | ||||
| 	d.r.resetBytes(in) | ||||
| } | ||||
| 
 | ||||
| func (d *simpleDecDriver[T]) resetInIO(r io.Reader) { | ||||
| 	d.r.resetIO(r, d.h.ReaderBufferSize, d.h.MaxInitLen, &d.d.blist) | ||||
| } | ||||
| 
 | ||||
| // ---- (custom stanza) | ||||
| 
 | ||||
| func (d *simpleDecDriver[T]) descBd() string { | ||||
| 	return sprintf("%v (%s)", d.bd, simpledesc(d.bd)) | ||||
| } | ||||
| 
 | ||||
| func (d *simpleDecDriver[T]) DecodeFloat32() (f float32) { | ||||
| 	return float32(chkOvf.Float32V(d.DecodeFloat64())) | ||||
| } | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue