-
Notifications
You must be signed in to change notification settings - Fork 2
/
dictionary.go
48 lines (35 loc) · 909 Bytes
/
dictionary.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
package radius
import (
"errors"
)
var (
AttributeNotFound = errors.New("Attribute not found.")
AttributeNotAdded = errors.New("Couldn't add attribute.")
AttributeExists = errors.New("Attribute already exists.")
)
type Dictionary interface {
GetAttribute(vendorId uint32, typeId uint8) (Attribute, error)
AddAttribute(Attribute) error
}
type MemoryDictionary map[uint16]map[uint8]Attribute
func (m MemoryDictionary) GetAttribute(vId uint16, tId uint8) (Attribute, error) {
attr, ok := m[vId][tId]
if !ok {
return Attribute{}, AttributeNotFound
}
return attr, nil
}
func (m MemoryDictionary) AddAttribute(a Attribute) error {
_, ok := m[a.VendorId][a.TypeId]
if ok {
return AttributeExists
}
m[a.VendorId][a.TypeId] = a
return nil
}
type DictionaryParser interface {
ParseAttribute() Attribute
Done() bool
}
func LoadDictionary(p *DictionaryParser, d *Dictionary) error {
}