* chore(deps): bump filippo.io/edwards25519 from 1.1.0 to 1.1.1 * chore(deps): bump github.com/cloudflare/circl from 1.6.1 to 1.6.3 * chore(deps): bump github.com/russellhaering/goxmldsig from 1.5.0 to 1.6.0 * build(deps): bump fpicalausa/remove-stale-branches from 2.4.0 to 2.6.1 * build(deps): bump actions/upload-artifact from 4.6.2 to 7.0.1 * build(deps): bump actions/download-artifact from 4.3.0 to 8.0.1 * build(deps): bump pnpm/action-setup from 5.0.0 to 6.0.8 * chore(deps): bump github.com/shamaton/msgpack/v2 to v2.4.1 and reva to v2.0.0-20260519092700-9da01c6fb954 * chore: regenerate lock fil s and vendor * chore: changelog * fix: bump golang.org/x/image to v0.39.0 (GO-2026-4815, GO-2026-4961, GO-2026-4962)
100 lines
2.1 KiB
Go
100 lines
2.1 KiB
Go
package encoding
|
|
|
|
import (
|
|
"reflect"
|
|
|
|
"github.com/shamaton/msgpack/v2/ext"
|
|
"github.com/shamaton/msgpack/v2/time"
|
|
)
|
|
|
|
var (
|
|
extCoderMap = map[reflect.Type]ext.Encoder{time.Encoder.Type(): time.Encoder}
|
|
extCoders = []ext.Encoder{time.Encoder}
|
|
)
|
|
|
|
// AddExtEncoder adds encoders for extension types.
|
|
func AddExtEncoder(f ext.Encoder) {
|
|
// ignore time
|
|
if f.Type() == time.Encoder.Type() {
|
|
return
|
|
}
|
|
|
|
_, ok := extCoderMap[f.Type()]
|
|
if !ok {
|
|
extCoderMap[f.Type()] = f
|
|
updateExtCoders()
|
|
}
|
|
}
|
|
|
|
// RemoveExtEncoder removes encoders for extension types.
|
|
func RemoveExtEncoder(f ext.Encoder) {
|
|
// ignore time
|
|
if f.Type() == time.Encoder.Type() {
|
|
return
|
|
}
|
|
|
|
_, ok := extCoderMap[f.Type()]
|
|
if ok {
|
|
delete(extCoderMap, f.Type())
|
|
updateExtCoders()
|
|
}
|
|
}
|
|
|
|
func updateExtCoders() {
|
|
extCoders = make([]ext.Encoder, len(extCoderMap))
|
|
i := 0
|
|
for k := range extCoderMap {
|
|
extCoders[i] = extCoderMap[k]
|
|
i++
|
|
}
|
|
}
|
|
|
|
/*
|
|
func (e *encoder) isDateTime(value reflect.Value) (bool, time.Time) {
|
|
i := value.Interface()
|
|
switch t := i.(type) {
|
|
case time.Time:
|
|
return true, t
|
|
}
|
|
return false, now
|
|
}
|
|
|
|
func (e *encoder) calcTime(t time.Time) int {
|
|
secs := uint64(t.Unix())
|
|
if secs>>34 == 0 {
|
|
data := uint64(t.Nanosecond())<<34 | secs
|
|
if data&0xffffffff00000000 == 0 {
|
|
return def.Byte1 + def.Byte4
|
|
}
|
|
return def.Byte1 + def.Byte8
|
|
}
|
|
|
|
return def.Byte1 + def.Byte1 + def.Byte4 + def.Byte8
|
|
}
|
|
|
|
func (e *encoder) writeTime(t time.Time, offset int) int {
|
|
secs := uint64(t.Unix())
|
|
if secs>>34 == 0 {
|
|
data := uint64(t.Nanosecond())<<34 | secs
|
|
if data&0xffffffff00000000 == 0 {
|
|
offset = e.setByte1Int(def.Fixext4, offset)
|
|
offset = e.setByte1Int(def.TimeStamp, offset)
|
|
offset = e.setByte4Uint64(data, offset)
|
|
return offset
|
|
}
|
|
|
|
offset = e.setByte1Int(def.Fixext8, offset)
|
|
offset = e.setByte1Int(def.TimeStamp, offset)
|
|
offset = e.setByte8Uint64(data, offset)
|
|
return offset
|
|
}
|
|
|
|
offset = e.setByte1Int(def.Ext8, offset)
|
|
offset = e.setByte1Int(12, offset)
|
|
offset = e.setByte1Int(def.TimeStamp, offset)
|
|
offset = e.setByte4Int(t.Nanosecond(), offset)
|
|
offset = e.setByte8Uint64(secs, offset)
|
|
return offset
|
|
}
|
|
*/
|