MCPcopy Index your code
hub / github.com/vmihailenco/msgpack / encodeTime

Method encodeTime

time.go:51–75  ·  view source on GitHub ↗
(tm time.Time)

Source from the content-addressed store, hash-verified

49}
50
51func (e *Encoder) encodeTime(tm time.Time) []byte {
52 if e.timeBuf == nil {
53 e.timeBuf = make([]byte, 12)
54 }
55
56 secs := uint64(tm.Unix())
57 if secs>>34 == 0 {
58 data := uint64(tm.Nanosecond())<<34 | secs
59
60 if data&0xffffffff00000000 == 0 {
61 b := e.timeBuf[:4]
62 binary.BigEndian.PutUint32(b, uint32(data))
63 return b
64 }
65
66 b := e.timeBuf[:8]
67 binary.BigEndian.PutUint64(b, data)
68 return b
69 }
70
71 b := e.timeBuf[:12]
72 binary.BigEndian.PutUint32(b, uint32(tm.Nanosecond()))
73 binary.BigEndian.PutUint64(b[4:], secs)
74 return b
75}
76
77func (d *Decoder) DecodeTime() (time.Time, error) {
78 c, err := d.readCode()

Callers 2

EncodeTimeMethod · 0.95
timeEncoderFunction · 0.80

Calls

no outgoing calls

Tested by

no test coverage detected