Skip to content

Commit 6469fef

Browse files
committed
Added HeaderAndPacketMarshalSize
Sometimes it is handy to get both header and packet length and avoid calculation of header length again.
1 parent 24a0ea8 commit 6469fef

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

packet.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -579,6 +579,8 @@ func (p *Packet) paddingSize() byte {
579579
// MarshalPacketTo serializes the header and payload into bytes.
580580
// Parts of pion code passes RTP header and payload separately, so this function
581581
// is provided to help with that.
582+
//
583+
// Deprecated: this function is a temporary workaround and will be removed in pion/webrtc v5.
582584
func MarshalPacketTo(buf []byte, header *Header, payload []byte) (int, error) {
583585
n, err := header.MarshalTo(buf)
584586
if err != nil {
@@ -591,6 +593,19 @@ func MarshalPacketTo(buf []byte, header *Header, payload []byte) (int, error) {
591593
// PacketMarshalSize returns the size of the header and payload once marshaled.
592594
// Parts of pion code passes RTP header and payload separately, so this function
593595
// is provided to help with that.
596+
//
597+
// Deprecated: this function is a temporary workaround and will be removed in pion/webrtc v5.
594598
func PacketMarshalSize(header *Header, payload []byte) int {
595599
return header.MarshalSize() + len(payload) + int(header.PaddingSize)
596600
}
601+
602+
// HeaderAndPacketMarshalSize returns the size of the header and full packet once marshaled.
603+
// Parts of pion code passes RTP header and payload separately, so this function
604+
// is provided to help with that.
605+
//
606+
// Deprecated: this function is a temporary workaround and will be removed in pion/webrtc v5.
607+
func HeaderAndPacketMarshalSize(header *Header, payload []byte) (headerSize int, packetSize int) {
608+
headerSize = header.MarshalSize()
609+
610+
return headerSize, headerSize + len(payload) + int(header.PaddingSize)
611+
}

packet_test.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1290,7 +1290,12 @@ func TestMarshalRTPPacketFuncs(t *testing.T) {
12901290
assert.NoError(t, err)
12911291
assert.Equal(t, len(rawPkt), n)
12921292
assert.Equal(t, rawPkt, buf[:n])
1293+
12931294
assert.Equal(t, n, PacketMarshalSize(&parsedPacket.Header, parsedPacket.Payload))
1295+
1296+
hdrLen, packetLen := HeaderAndPacketMarshalSize(&parsedPacket.Header, parsedPacket.Payload)
1297+
assert.Equal(t, parsedPacket.Header.MarshalSize(), hdrLen)
1298+
assert.Equal(t, n, packetLen)
12941299
}
12951300

12961301
func TestDeprecatedPaddingSizeField(t *testing.T) {

0 commit comments

Comments
 (0)