diff --git a/header.go b/header.go index 72cee93..bc1a5e5 100644 --- a/header.go +++ b/header.go @@ -5,6 +5,7 @@ package rtcp import ( "encoding/binary" + "fmt" ) // PacketType specifies the type of an RTCP packet. @@ -59,7 +60,7 @@ func (p PacketType) String() string { case TypeExtendedReport: return "XR" default: - return string(p) + return fmt.Sprintf("invalid value %d", uint8(p)) } } diff --git a/header_test.go b/header_test.go index 910c9d5..5fdcb50 100644 --- a/header_test.go +++ b/header_test.go @@ -105,3 +105,17 @@ func TestHeaderRoundTrip(t *testing.T) { assert.Equalf(t, test.Header, decoded, "%q header round trip mismatch", test.Name) } } + +func TestPacketTypeString(t *testing.T) { + for _, test := range []struct { + Type PacketType + Want string + }{ + {TypeSenderReport, "SR"}, + {TypeExtendedReport, "XR"}, + {PacketType(65), "invalid value 65"}, + {PacketType(0), "invalid value 0"}, + } { + assert.Equal(t, test.Want, test.Type.String()) + } +} diff --git a/source_description.go b/source_description.go index 951bf8f..2f79b89 100644 --- a/source_description.go +++ b/source_description.go @@ -49,7 +49,7 @@ func (s SDESType) String() string { case SDESPrivate: return "PRIV" default: - return string(s) + return fmt.Sprintf("invalid value %d", uint8(s)) } } diff --git a/source_description_test.go b/source_description_test.go index eccf75b..3221550 100644 --- a/source_description_test.go +++ b/source_description_test.go @@ -375,3 +375,17 @@ func TestSourceDescriptionRoundTripMaxLength(t *testing.T) { assert.NoError(t, decoded.Unmarshal(data)) assert.Equal(t, desc, decoded) } + +func TestSDESTypeString(t *testing.T) { + for _, test := range []struct { + Type SDESType + Want string + }{ + {SDESCNAME, "CNAME"}, + {SDESPrivate, "PRIV"}, + {SDESType(65), "invalid value 65"}, + {SDESType(200), "invalid value 200"}, + } { + assert.Equal(t, test.Want, test.Type.String()) + } +}