-
Notifications
You must be signed in to change notification settings - Fork 37
/
Copy pathobject.go
76 lines (63 loc) · 3.24 KB
/
object.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
package parser
import (
"github.com/alecthomas/participle/lexer"
"github.com/sleepinggenius2/gosmi/types"
)
type ObjectGroup struct {
Pos lexer.Position
Objects []types.SmiIdentifier `parser:"\"OBJECTS\" \"{\" @Ident ( \",\" @Ident )* \",\"? \"}\""` // Required
Status Status `parser:"\"STATUS\" @( \"current\" | \"deprecated\" | \"obsolete\" )"` // Required
Description string `parser:"\"DESCRIPTION\" @Text"` // Required
Reference string `parser:"( \"REFERENCE\" @Text )?"`
}
type ObjectIdentity struct {
Pos lexer.Position
Status Status `parser:"\"STATUS\" @( \"current\" | \"deprecated\" | \"obsolete\" )"` // Required
Description string `parser:"\"DESCRIPTION\" @Text"` // Required
Reference string `parser:"( \"REFERENCE\" @Text )?"`
}
type Access string
const (
// In order from least to greatest
AccessWriteOnly Access = "write-only" // Do not use
AccessNotImplemented Access = "not-implemented"
AccessNotAccessible Access = "not-accessible"
AccessAccessibleForNotify Access = "accesible-for-notify"
AccessReadOnly Access = "read-only"
AccessReadWrite Access = "read-write"
AccessReadCreate Access = "read-create"
)
func (a Access) ToSmi() types.Access {
switch a {
case AccessWriteOnly:
return types.AccessUnknown // What should this be?
case AccessNotImplemented:
return types.AccessNotImplemented
case AccessNotAccessible:
return types.AccessNotAccessible
case AccessAccessibleForNotify:
return types.AccessNotify
case AccessReadOnly:
return types.AccessReadOnly
case AccessReadWrite, AccessReadCreate:
return types.AccessReadWrite
}
return types.AccessUnknown
}
type Index struct {
Pos lexer.Position
Implied bool `parser:"@\"IMPLIED\"?"`
Name types.SmiIdentifier `parser:"@Ident"`
}
type ObjectType struct {
Pos lexer.Position
Syntax Syntax `parser:"\"SYNTAX\" @@"` // Required
Units string `parser:"( \"UNITS\" @Text )?"`
Access Access `parser:"( \"ACCESS\" | \"MAX-ACCESS\" ) @( \"write-only\" | \"not-accessible\" | \"accessible-for-notify\" | \"read-only\" | \"read-write\" | \"read-create\" )"` // Required
Status Status `parser:"\"STATUS\" @( \"mandatory\" | \"optional\" | \"current\" | \"deprecated\" | \"obsolete\" )"` // Required
Description string `parser:"( \"DESCRIPTION\" @Text )?"` // Required RFC 1212+
Reference string `parser:"( \"REFERENCE\" @Text )?"`
Index []Index `parser:"( ( \"INDEX\" \"{\" @@ ( \",\" @@ )* \",\"? \"}\" )"` // Required for "row" without AUGMENTS
Augments *types.SmiIdentifier `parser:"| ( \"AUGMENTS\" \"{\" @Ident \"}\" ) )?"` // Required for "row" without INDEX
Defval *string `parser:"( \"DEFVAL\" \"{\" @( \"-\"? Int | BinString | HexString | Text | Ident | ( \"{\" ( Int+ | ( Ident ( \",\" Ident )* \",\"? )? ) \"}\" ) ) \"}\" )?"`
}