-
Notifications
You must be signed in to change notification settings - Fork 1
/
time.go
44 lines (39 loc) · 938 Bytes
/
time.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
package hexabus
import (
"bytes"
"encoding/binary"
)
// struct to hold DTYPE_TIMESTAMP
type Timestamp struct {
TotalSeconds uint32
}
// decodes the payload from a timestamp packet into a Timestamp structure
// takes as argument a Packet.Data interface{}
func (t *Timestamp) Decode(data interface{}) (err error) {
buf := bytes.NewBuffer(data.([]byte))
err = binary.Read(buf, binary.BigEndian, t)
if err != nil {
return err
}
return nil
}
// struct to hold DTYPE_DATETIME
type DateTime struct {
Hours uint8
Minutes uint8
Seconds uint8
Day uint8
Month uint8
Year uint16
DayOfWeek uint8
}
// decodes the payload from a datetime packet into a DateTime structure
// takes as argument a Packet.Data interface{}
func (d *DateTime) Decode(data interface{}) (err error) {
buf := bytes.NewBuffer(data.([]byte))
err = binary.Read(buf, binary.BigEndian, d)
if err != nil {
return err
}
return nil
}