Skip to content
This repository was archived by the owner on Aug 23, 2022. It is now read-only.

Commit 2af5af0

Browse files
author
Rain Liu
committed
change unmarshal return value as vec![]
1 parent 939e62a commit 2af5af0

File tree

2 files changed

+8
-11
lines changed

2 files changed

+8
-11
lines changed

src/compound_packet/compound_packet_test.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ fn test_bad_compound() {
4949

5050
let mut bad_compound = Bytes::copy_from_slice(&REAL_PACKET[84..104]);
5151
let p = unmarshal(&mut bad_compound).expect("Error unmarshalling packet");
52-
let compound = p.as_any().downcast_ref::<CompoundPacket>().unwrap();
52+
let compound = CompoundPacket(p);
5353

5454
// this should return an error,
5555
// it violates the "must start with RR or SR" rule

src/packet.rs

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use crate::error::Result;
22
use crate::{
3-
compound_packet::*, error::Error, goodbye::*, header::*,
4-
payload_feedbacks::full_intra_request::*, payload_feedbacks::picture_loss_indication::*,
3+
error::Error, goodbye::*, header::*, payload_feedbacks::full_intra_request::*,
4+
payload_feedbacks::picture_loss_indication::*,
55
payload_feedbacks::receiver_estimated_maximum_bitrate::*,
66
payload_feedbacks::slice_loss_indication::*, raw_packet::*, receiver_report::*,
77
sender_report::*, source_description::*,
@@ -44,7 +44,7 @@ impl Clone for Box<dyn Packet + Send + Sync> {
4444
/// If this is a reduced-size RTCP packet a feedback packet (Goodbye, SliceLossIndication, etc)
4545
/// will be returned. Otherwise, the underlying type of the returned packet will be
4646
/// CompoundPacket.
47-
pub fn unmarshal<B>(raw_data: &mut B) -> Result<Box<dyn Packet + Send + Sync>>
47+
pub fn unmarshal<B>(raw_data: &mut B) -> Result<Vec<Box<dyn Packet + Send + Sync>>>
4848
where
4949
B: Buf,
5050
{
@@ -59,11 +59,8 @@ where
5959
// Empty Packet
6060
0 => Err(Error::InvalidHeader),
6161

62-
// Single Packet
63-
1 => packets.pop().ok_or(Error::BadFirstPacket),
64-
65-
// Compound Packet
66-
_ => Ok(Box::new(CompoundPacket(packets))),
62+
// Multiple Packet
63+
_ => Ok(packets),
6764
}
6865
}
6966

@@ -187,13 +184,13 @@ mod test {
187184
media_ssrc: 0x902f9e2e,
188185
};
189186

190-
let expected: Box<dyn Packet + Send + Sync> = Box::new(CompoundPacket(vec![
187+
let expected: Vec<Box<dyn Packet + Send + Sync>> = vec![
191188
Box::new(a),
192189
Box::new(b),
193190
Box::new(c),
194191
Box::new(d),
195192
Box::new(e),
196-
]));
193+
];
197194

198195
assert!(packet == expected, "Invalid packets");
199196
}

0 commit comments

Comments
 (0)