-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathsoftware.go
More file actions
44 lines (37 loc) · 751 Bytes
/
software.go
File metadata and controls
44 lines (37 loc) · 751 Bytes
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
package stun
import (
"errors"
"fmt"
)
type Software struct {
Value string
}
func (s *Software) Type() uint16 {
return ATTR_TYPE_SOFTWARE
}
func (s *Software) Length() uint16 {
return uint16(len(s.Value))
}
func (s *Software) Pack(b []byte) error {
b = b[4:]
if len(b) < int(s.Length()) {
return errors.New("Buffer is too short for software")
}
i := copy(b[:], s.Value)
if i != int(s.Length()) {
return errors.New("Copy failed")
}
return nil
}
func (s *Software) UnPack(b []byte) error {
l := int(toUint16(b[2:4]))
if len(b) < l+4 {
return errors.New("Buffer is shorter than declared")
}
b = b[4:]
s.Value = string(b[0:l])
return nil
}
func (s *Software) String() string {
return fmt.Sprintf("Software: %s", s.Value)
}