-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathtype_scene_extension.go
72 lines (63 loc) · 1.42 KB
/
type_scene_extension.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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
package zcl
type SceneExtension interface {
ClusterID() uint16
Val
}
type SceneExtensionSet []SceneExtension
func (SceneExtensionSet) TypeID() TypeID {
return new(Zset).TypeID()
}
func (s SceneExtensionSet) MarshalZcl() ([]byte, error) {
var data []byte
for _, v := range s {
cl := Zu16(v.ClusterID())
clDt, _ := cl.MarshalZcl()
dt, err := v.MarshalZcl()
if err != nil {
return nil, err
}
data = append(data, append(clDt, uint8(len(dt)))...)
data = append(data, dt...)
}
return data, nil
}
func (s *SceneExtensionSet) UnmarshalZcl(b []byte) ([]byte, error) {
for len(b) > 0 {
se := &sceneExtension{}
var err error
b, err = (&se.cluster).UnmarshalZcl(b)
if err != nil {
return nil, err
}
b, err = (&se.data).UnmarshalZcl(b)
if err != nil {
return nil, err
}
*s = append(*s, se)
}
return nil, nil
}
func (s SceneExtensionSet) String() string {
var str []string
for _, v := range s {
str = append(str, Sprintf("%v", v))
}
return StrJoin(str, ", ")
}
type sceneExtension struct {
cluster Zu16
data Zbytes
}
func (s sceneExtension) MarshalZcl() ([]byte, error) {
return []byte(s.data), nil
}
func (s *sceneExtension) UnmarshalZcl(b []byte) ([]byte, error) {
s.data = Zbytes(b)
return nil, nil
}
func (s *sceneExtension) ClusterID() uint16 {
return uint16(s.cluster)
}
func (s *sceneExtension) String() string {
return Sprintf("Cluster[0x%04X] %s", s.cluster, s.data.String())
}