mirror of
https://github.com/pion/stun.git
synced 2025-10-24 08:13:45 +08:00
all: refactor attributes
This commit is contained in:
31
attribute_software.go
Normal file
31
attribute_software.go
Normal 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
|
||||
}
|
||||
Reference in New Issue
Block a user