package stun
import "errors"
type UnknownAttributes []AttrType
func (a UnknownAttributes ) String () string {
s := ""
if len (a ) == 0 {
return "<nil>"
}
last := len (a ) - 1
for i , t := range a {
s += t .String ()
if i != last {
s += ", "
}
}
return s
}
const attrTypeSize = 4
func (a UnknownAttributes ) AddTo (m *Message ) error {
v := make ([]byte , 0 , attrTypeSize *20 )
for i , t := range a {
v = append (v , 0 , 0 , 0 , 0 )
first := attrTypeSize * i
last := first + attrTypeSize
bin .PutUint16 (v [first :last ], t .Value ())
}
m .Add (AttrUnknownAttributes , v )
return nil
}
var ErrBadUnknownAttrsSize = errors .New ("bad UNKNOWN-ATTRIBUTES size" )
func (a *UnknownAttributes ) GetFrom (m *Message ) error {
v , err := m .Get (AttrUnknownAttributes )
if err != nil {
return err
}
if len (v )%attrTypeSize != 0 {
return ErrBadUnknownAttrsSize
}
*a = (*a )[:0 ]
first := 0
for first < len (v ) {
last := first + attrTypeSize
*a = append (*a , AttrType (bin .Uint16 (v [first :last ])))
first = last
}
return nil
}
The pages are generated with Golds v0.8.2 . (GOOS=linux GOARCH=amd64)
Golds is a Go 101 project developed by Tapir Liu .
PR and bug reports are welcome and can be submitted to the issue list .
Please follow @zigo_101 (reachable from the left QR code) to get the latest news of Golds .