Files
ocis/vendor/github.com/shamaton/msgpack/v2/time/decode_stream.go
Michal Klos 4b99dd8c8f chore: consolidated bumps and security updates (#12325)
* 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)
2026-05-19 12:52:58 +00:00

78 lines
1.8 KiB
Go

package time
import (
"encoding/binary"
"fmt"
"reflect"
"time"
"github.com/shamaton/msgpack/v2/def"
"github.com/shamaton/msgpack/v2/ext"
)
var StreamDecoder = new(timeStreamDecoder)
type timeStreamDecoder struct{}
var _ ext.StreamDecoder = (*timeStreamDecoder)(nil)
func (td *timeStreamDecoder) Code() int8 {
return def.TimeStamp
}
func (td *timeStreamDecoder) IsType(code byte, innerType int8, dataLength int) bool {
switch code {
case def.Fixext4, def.Fixext8:
return innerType == td.Code()
case def.Ext8:
return innerType == td.Code() && dataLength == 12
}
return false
}
func (td *timeStreamDecoder) ToValue(code byte, data []byte, k reflect.Kind) (interface{}, error) {
switch code {
case def.Fixext4:
if len(data) < def.Byte4 {
return zero, def.ErrTooShortBytes
}
v := time.Unix(int64(binary.BigEndian.Uint32(data)), 0)
if decodeAsLocal {
return v, nil
}
return v.UTC(), nil
case def.Fixext8:
if len(data) < def.Byte8 {
return zero, def.ErrTooShortBytes
}
data64 := binary.BigEndian.Uint64(data)
nano := int64(data64 >> 34)
if nano > 999999999 {
return zero, fmt.Errorf("in timestamp 64 formats, nanoseconds must not be larger than 999999999 : %d", nano)
}
v := time.Unix(int64(data64&0x00000003ffffffff), nano)
if decodeAsLocal {
return v, nil
}
return v.UTC(), nil
case def.Ext8:
if len(data) < def.Byte4+def.Byte8 {
return zero, def.ErrTooShortBytes
}
nano := binary.BigEndian.Uint32(data[:4])
if nano > 999999999 {
return zero, fmt.Errorf("in timestamp 96 formats, nanoseconds must not be larger than 999999999 : %d", nano)
}
sec := binary.BigEndian.Uint64(data[4:12])
v := time.Unix(int64(sec), int64(nano))
if decodeAsLocal {
return v, nil
}
return v.UTC(), nil
}
return zero, fmt.Errorf("should not reach this line!! code %x decoding %v", code, k)
}