-
Notifications
You must be signed in to change notification settings - Fork 5
/
list.go
79 lines (60 loc) · 1.36 KB
/
list.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
73
74
75
76
77
78
79
package sml
type ListEntry struct {
ObjName OctetString
Status int64
ValTime Time
Unit uint8
Scaler int8
Value Value
ValueSignature OctetString
}
func ListEntryParse(buf *Buffer) (ListEntry, error) {
Debug(buf, "ListEntryParse")
elem := ListEntry{}
var err error
if err := Expect(buf, TYPELIST, 7); err != nil {
return elem, err
}
if elem.ObjName, err = OctetStringParse(buf); err != nil {
return elem, err
}
if elem.Status, err = StatusParse(buf); err != nil {
return elem, err
}
if elem.ValTime, err = TimeParse(buf); err != nil {
return elem, err
}
if elem.Unit, err = U8Parse(buf); err != nil {
return elem, err
}
if elem.Scaler, err = I8Parse(buf); err != nil {
return elem, err
}
if elem.Value, err = ValueParse(buf); err != nil {
return elem, err
}
if elem.ValueSignature, err = OctetStringParse(buf); err != nil {
return elem, err
}
return elem, nil
}
func ListParse(buf *Buffer) ([]ListEntry, error) {
if BufOptionalIsSkipped(buf) {
return nil, nil
}
Debug(buf, "ListParse")
if err := ExpectType(buf, TYPELIST); err != nil {
return nil, err
}
list := make([]ListEntry, 0)
elems := BufGetNextLength(buf)
for elems > 0 {
elem, err := ListEntryParse(buf)
if err != nil {
return nil, err
}
list = append(list, elem)
elems--
}
return list, nil
}