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
This commit is contained in:
Sean DuBois
2025-12-05 13:04:52 -05:00
committed by Sean DuBois
parent 9bd95766b3
commit 9b2d7bcf7c
2 changed files with 17 additions and 0 deletions

View File

@@ -171,6 +171,14 @@ func (t AttrType) String() string {
return s
}
// Known returns true if AttrType is known and implemented
// by this library.
func (t AttrType) Known() bool {
_, valid := attrNames()[t]
return valid
}
// RawAttribute is a Type-Length-Value (TLV) object that
// can be added to a STUN message. Attributes are divided into two
// types: comprehension-required and comprehension-optional. STUN

View File

@@ -107,3 +107,12 @@ func TestAttrTypeRange(t *testing.T) {
})
}
}
func TestAttrTypeKnown(t *testing.T) {
// All Attributes in attrNames should be known
for attr := range attrNames() {
assert.True(t, attr.Known())
}
assert.False(t, AttrType(0xFFFF).Known()) // Known
}