-
Notifications
You must be signed in to change notification settings - Fork 23
/
attr.go
48 lines (43 loc) · 822 Bytes
/
attr.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 (
"fmt"
)
type AttrEncoder interface {
Encode() []byte
Type() AttributeType
Bytes() []byte
Length() uint8
String() string
}
type Attr struct {
attrType AttributeType
length uint8
bytes []byte
}
func (a Attr) Encode() []byte {
panic("TODO")
}
func (a Attr) Type() AttributeType {
return a.attrType
}
func (a Attr) Bytes() []byte {
return a.bytes
}
func (a Attr) Length() uint8 {
if a.length == 0 {
// Calc if not set
return uint8(2 + len(a.Bytes()))
}
return a.length
}
func (a Attr) String() string {
// TODO: More verbosely print bytes?
return fmt.Sprintf("{Type=%s bytes=%+v}", a.Type().String(), a.bytes)
}
func NewAttr(attrType AttributeType, bytes []byte, length uint8) AttrEncoder {
return Attr{
attrType: attrType,
length: length,
bytes: bytes,
}
}