Debian Codegraph @

packet_test.go

raw symbols SCIP
1 // SPDX-FileCopyrightText: 2026 The Pion community <https://pion.ly>
2 // SPDX-License-Identifier: MIT
3
4 package rtcpscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/
5
6 import (
7 "testingscip-go gomod github.com/golang/go/src go1.24.0 testing/"
8
9 "github.com/stretchr/testify/assertscip-go gomod github.com/stretchr/testify v1.11.1 `github.com/stretchr/testify/assert`/"
10 )
11
12 // An RTCP packet from a packet dump.
13 func realPacketscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/realPacket().() []byte {
14 return []byte{
15 // Receiver Report (offset=0)
16 // v=2, p=0, count=1, RR, len=7
17 0x81, 0xc9, 0x0, 0x7,
18 // ssrc=0x902f9e2e
19 0x90, 0x2f, 0x9e, 0x2e,
20 // ssrc=0xbc5e9a40
21 0xbc, 0x5e, 0x9a, 0x40,
22 // fracLost=0, totalLost=0
23 0x0, 0x0, 0x0, 0x0,
24 // lastSeq=0x46e1
25 0x0, 0x0, 0x46, 0xe1,
26 // jitter=273
27 0x0, 0x0, 0x1, 0x11,
28 // lsr=0x9f36432
29 0x9, 0xf3, 0x64, 0x32,
30 // delay=150137
31 0x0, 0x2, 0x4a, 0x79,
32
33 // Source Description (offset=32)
34 // v=2, p=0, count=1, SDES, len=12
35 0x81, 0xca, 0x0, 0xc,
36 // ssrc=0x902f9e2e
37 0x90, 0x2f, 0x9e, 0x2e,
38 // CNAME, len=38
39 0x1, 0x26,
40 // text="{9c00eb92-1afb-9d49-a47d-91f64eee69f5}"
41 0x7b, 0x39, 0x63, 0x30,
42 0x30, 0x65, 0x62, 0x39,
43 0x32, 0x2d, 0x31, 0x61,
44 0x66, 0x62, 0x2d, 0x39,
45 0x64, 0x34, 0x39, 0x2d,
46 0x61, 0x34, 0x37, 0x64,
47 0x2d, 0x39, 0x31, 0x66,
48 0x36, 0x34, 0x65, 0x65,
49 0x65, 0x36, 0x39, 0x66,
50 0x35, 0x7d,
51 // END + padding
52 0x0, 0x0, 0x0, 0x0,
53
54 // Goodbye (offset=84)
55 // v=2, p=0, count=1, BYE, len=1
56 0x81, 0xcb, 0x0, 0x1,
57 // source=0x902f9e2e
58 0x90, 0x2f, 0x9e, 0x2e,
59
60 // Picture Loss Indication (offset=92)
61 0x81, 0xce, 0x0, 0x2,
62 // sender=0x902f9e2e
63 0x90, 0x2f, 0x9e, 0x2e,
64 // media=0x902f9e2e
65 0x90, 0x2f, 0x9e, 0x2e,
66
67 // RapidResynchronizationRequest (offset=104)
68 0x85, 0xcd, 0x0, 0x2,
69 // sender=0x902f9e2e
70 0x90, 0x2f, 0x9e, 0x2e,
71 // media=0x902f9e2e
72 0x90, 0x2f, 0x9e, 0x2e,
73
74 // ApplicationDefined (offset=116)
75 0x80, 0xcc, 0x00, 0x03,
76 // sender=0x4baae1ab
77 0x4b, 0xaa, 0xe1, 0xab,
78 // name='NAME'
79 0x4E, 0x41, 0x4D, 0x45,
80 // data='ABCD'
81 0x41, 0x42, 0x43, 0x44,
82 }
83 }
84
85 func TestUnmarshalscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/TestUnmarshal().(t *testingscip-go gomod github.com/golang/go/src go1.24.0 testing/.Tscip-go gomod github.com/golang/go/src go1.24.0 testing/T#) {
86 packet, err := Unmarshalscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/Unmarshal().(realPacketscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/realPacket().())
87 assertscip-go gomod github.com/stretchr/testify v1.11.1 `github.com/stretchr/testify/assert`/.NoErrorscip-go gomod github.com/stretchr/testify v1.11.1 `github.com/stretchr/testify/assert`/NoError().(t, err)
88
89 expected := []Packetscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/Packet#{
90 &ReceiverReportscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/ReceiverReport#{
91 SSRCscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/ReceiverReport#SSRC.: 0x902f9e2e,
92 Reportsscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/ReceiverReport#Reports.: []ReceptionReportscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/ReceptionReport#{{
93 SSRCscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/ReceptionReport#SSRC.: 0xbc5e9a40,
94 FractionLostscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/ReceptionReport#FractionLost.: 0,
95 TotalLostscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/ReceptionReport#TotalLost.: 0,
96 LastSequenceNumberscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/ReceptionReport#LastSequenceNumber.: 0x46e1,
97 Jitterscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/ReceptionReport#Jitter.: 273,
98 LastSenderReportscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/ReceptionReport#LastSenderReport.: 0x9f36432,
99 Delayscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/ReceptionReport#Delay.: 150137,
100 }},
101 ProfileExtensionsscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/ReceiverReport#ProfileExtensions.: []byte{},
102 },
103 NewCNAMESourceDescriptionscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/NewCNAMESourceDescription().(0x902f9e2e, "{9c00eb92-1afb-9d49-a47d-91f64eee69f5}"),
104 &Goodbyescip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/Goodbye#{
105 Sourcesscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/Goodbye#Sources.: []uint32{0x902f9e2e},
106 },
107 &PictureLossIndicationscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/PictureLossIndication#{
108 SenderSSRCscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/PictureLossIndication#SenderSSRC.: 0x902f9e2e,
109 MediaSSRCscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/PictureLossIndication#MediaSSRC.: 0x902f9e2e,
110 },
111 &RapidResynchronizationRequestscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/RapidResynchronizationRequest#{
112 SenderSSRCscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/RapidResynchronizationRequest#SenderSSRC.: 0x902f9e2e,
113 MediaSSRCscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/RapidResynchronizationRequest#MediaSSRC.: 0x902f9e2e,
114 },
115 &ApplicationDefinedscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/ApplicationDefined#{
116 SSRCscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/ApplicationDefined#SSRC.: 0x4baae1ab,
117 Namescip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/ApplicationDefined#Name.: "NAME",
118 Datascip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/ApplicationDefined#Data.: []byte{0x41, 0x42, 0x43, 0x44},
119 },
120 }
121
122 assertscip-go gomod github.com/stretchr/testify v1.11.1 `github.com/stretchr/testify/assert`/.Equalscip-go gomod github.com/stretchr/testify v1.11.1 `github.com/stretchr/testify/assert`/Equal().(t, expected, packet)
123 }
124
125 func TestUnmarshalNilscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/TestUnmarshalNil().(t *testingscip-go gomod github.com/golang/go/src go1.24.0 testing/.Tscip-go gomod github.com/golang/go/src go1.24.0 testing/T#) {
126 _, err := Unmarshalscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/Unmarshal().(nil)
127 assertscip-go gomod github.com/stretchr/testify v1.11.1 `github.com/stretchr/testify/assert`/.ErrorIsscip-go gomod github.com/stretchr/testify v1.11.1 `github.com/stretchr/testify/assert`/ErrorIs().(t, err, errInvalidHeaderscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/errInvalidHeader.)
128 }
129
130 func TestInvalidHeaderLengthscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/TestInvalidHeaderLength().(t *testingscip-go gomod github.com/golang/go/src go1.24.0 testing/.Tscip-go gomod github.com/golang/go/src go1.24.0 testing/T#) {
131 invalidPacket := []byte{
132 // Receiver Report (offset=0)
133 // v=2, p=0, count=1, RR, len=100
134 0x81, 0xc9, 0x0, 0x64,
135 }
136
137 _, err := Unmarshalscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/Unmarshal().(invalidPacket)
138 assertscip-go gomod github.com/stretchr/testify v1.11.1 `github.com/stretchr/testify/assert`/.ErrorIsscip-go gomod github.com/stretchr/testify v1.11.1 `github.com/stretchr/testify/assert`/ErrorIs().(t, err, errPacketTooShortscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/errPacketTooShort.)
139 }
140
141 func TestUnmarshalMaxLengthRawPacketscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/TestUnmarshalMaxLengthRawPacket().(t *testingscip-go gomod github.com/golang/go/src go1.24.0 testing/.Tscip-go gomod github.com/golang/go/src go1.24.0 testing/T#) {
142 rawPacket := make([]byte, 4*(0xFFFF+1))
143 rawPacket[0] = 0x80
144 rawPacket[1] = 0xfa
145 rawPacket[2] = 0xff
146 rawPacket[3] = 0xff
147
148 packets, err := Unmarshalscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/Unmarshal().(rawPacket)
149 assertscip-go gomod github.com/stretchr/testify v1.11.1 `github.com/stretchr/testify/assert`/.NoErrorscip-go gomod github.com/stretchr/testify v1.11.1 `github.com/stretchr/testify/assert`/NoError().(t, err)
150 assertscip-go gomod github.com/stretchr/testify v1.11.1 `github.com/stretchr/testify/assert`/.Lenscip-go gomod github.com/stretchr/testify v1.11.1 `github.com/stretchr/testify/assert`/Len().(t, packets, 1)
151
152 parsed, ok := packets[0].(*RawPacketscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/RawPacket#)
153 assertscip-go gomod github.com/stretchr/testify v1.11.1 `github.com/stretchr/testify/assert`/.Truescip-go gomod github.com/stretchr/testify v1.11.1 `github.com/stretchr/testify/assert`/True().(t, ok)
154 assertscip-go gomod github.com/stretchr/testify v1.11.1 `github.com/stretchr/testify/assert`/.Equalscip-go gomod github.com/stretchr/testify v1.11.1 `github.com/stretchr/testify/assert`/Equal().(t, rawPacket, []byte(*parsed))
155 }