mirror of
https://github.com/gortc/stun.git
synced 2025-09-26 20:41:36 +08:00
attributes: implement Setter for RawAttribute
This commit is contained in:
1
api/stun1.18.0.txt
Normal file
1
api/stun1.18.0.txt
Normal file
@@ -0,0 +1 @@
|
|||||||
|
pkg github.com/gortc/stun, method (RawAttribute) AddTo(*Message) error
|
@@ -146,6 +146,13 @@ type RawAttribute struct {
|
|||||||
Value []byte
|
Value []byte
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// AddTo implements Setter, adding attribute as a.Type with a.Value and ignoring
|
||||||
|
// the Length field.
|
||||||
|
func (a RawAttribute) AddTo(m *Message) error {
|
||||||
|
m.Add(a.Type, a.Value)
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
// Equal returns true if a == b.
|
// Equal returns true if a == b.
|
||||||
func (a RawAttribute) Equal(b RawAttribute) bool {
|
func (a RawAttribute) Equal(b RawAttribute) bool {
|
||||||
if a.Type != b.Type {
|
if a.Type != b.Type {
|
||||||
|
@@ -1,6 +1,7 @@
|
|||||||
package stun
|
package stun
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"bytes"
|
||||||
"testing"
|
"testing"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -21,6 +22,24 @@ func BenchmarkMessage_Get(b *testing.B) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestRawAttribute_AddTo(t *testing.T) {
|
||||||
|
v := []byte{1, 2, 3, 4}
|
||||||
|
m, err := Build(RawAttribute{
|
||||||
|
Type: AttrData,
|
||||||
|
Value: v,
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
gotV, gotErr := m.Get(AttrData)
|
||||||
|
if gotErr != nil {
|
||||||
|
t.Fatal(gotErr)
|
||||||
|
}
|
||||||
|
if !bytes.Equal(gotV, v) {
|
||||||
|
t.Error("value mismatch")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func TestMessage_GetNoAllocs(t *testing.T) {
|
func TestMessage_GetNoAllocs(t *testing.T) {
|
||||||
m := New()
|
m := New()
|
||||||
NewSoftware("c").AddTo(m)
|
NewSoftware("c").AddTo(m)
|
||||||
|
Reference in New Issue
Block a user