From 8e6990ca7bff6f5190db1c45f954e0728cda7e0e Mon Sep 17 00:00:00 2001 From: Raphael Fakhri <153192858+RaphaelFakhri@users.noreply.github.com> Date: Tue, 29 Sep 2026 17:07:08 +0000 Subject: [PATCH] Format unknown packet and SDES types as numbers PacketType.String and SDESType.String converted unknown values with string(p), which yields the Unicode character for that code point instead of the number. Use the same 'invalid value' format as BlockTypeType. --- header.go | 3 ++- header_test.go | 14 ++++++++++++++ source_description.go | 2 +- source_description_test.go | 14 ++++++++++++++ 4 files changed, 31 insertions(+), 2 deletions(-) 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()) + } +}