Skip to content

Commit 9b2d7bc

Browse files
committed
Add AttrType.Known method
Will allow us to check in pion/turn if a Attribute has been implemented. We should be returning errors if a client returns a unknown attribute Relates to pion/turn#76
1 parent 9bd9576 commit 9b2d7bc

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

attributes.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,14 @@ func (t AttrType) String() string {
171171
return s
172172
}
173173

174+
// Known returns true if AttrType is known and implemented
175+
// by this library.
176+
func (t AttrType) Known() bool {
177+
_, valid := attrNames()[t]
178+
179+
return valid
180+
}
181+
174182
// RawAttribute is a Type-Length-Value (TLV) object that
175183
// can be added to a STUN message. Attributes are divided into two
176184
// types: comprehension-required and comprehension-optional. STUN

attributes_test.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,3 +107,12 @@ func TestAttrTypeRange(t *testing.T) {
107107
})
108108
}
109109
}
110+
111+
func TestAttrTypeKnown(t *testing.T) {
112+
// All Attributes in attrNames should be known
113+
for attr := range attrNames() {
114+
assert.True(t, attr.Known())
115+
}
116+
117+
assert.False(t, AttrType(0xFFFF).Known()) // Known
118+
}

0 commit comments

Comments
 (0)