all: refactor attributes

This commit is contained in:
Aleksandr Razumov
2017-02-11 05:23:49 +03:00
parent 3ec51bf758
commit fba9f6b02d
21 changed files with 1048 additions and 1107 deletions

31
attribute_software.go Normal file
View File

@@ -0,0 +1,31 @@
package stun
// Software is SOFTWARE attribute.
type Software struct {
Raw []byte
}
func (s *Software) String() string {
return string(s.Raw)
}
// NewSoftware returns *Software from string.
func NewSoftware(software string) *Software {
return &Software{Raw: []byte(software)}
}
// AddTo adds Software attribute to m.
func (s *Software) AddTo(m *Message) error {
m.Add(AttrSoftware, m.Raw)
return nil
}
// GetFrom decodes Software from m.
func (s *Software) GetFrom(m *Message) error {
v, err := m.Get(AttrSoftware)
if err != nil {
return err
}
s.Raw = v
return nil
}