Skip to content

Commit

Permalink
Fix clippy lints
Browse files Browse the repository at this point in the history
  • Loading branch information
dholroyd committed Mar 11, 2024
1 parent 1294be2 commit 832be80
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 12 deletions.
21 changes: 13 additions & 8 deletions src/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,12 @@ pub struct RtpPacketBuilder<'a> {
csrc_count: u8,
}

impl<'a> Default for RtpPacketBuilder<'a> {
fn default() -> Self {
Self::new()
}
}

impl<'a> RtpPacketBuilder<'a> {
/// Create a new RTP packet builder
pub fn new() -> Self {
Expand Down Expand Up @@ -154,7 +160,7 @@ impl<'a> RtpPacketBuilder<'a> {
self
} else {
self.csrcs[self.csrc_count as usize] = csrc;
self.csrc_count = self.csrc_count + 1;
self.csrc_count += 1;
self
}
}
Expand Down Expand Up @@ -256,23 +262,23 @@ impl<'a> RtpPacketBuilder<'a> {
let mut write_index = 12usize;
for index in 0..self.csrc_count as usize {
let csrc = self.csrcs[index];
target[write_index + 0] = (csrc >> 24) as u8;
target[write_index] = (csrc >> 24) as u8;
target[write_index + 1] = (csrc >> 16) as u8;
target[write_index + 2] = (csrc >> 8) as u8;
target[write_index + 3] = (csrc) as u8;

write_index = write_index + 4;
write_index += 4;
}

if let Some((id, payload)) = self.extension {
target[write_index + 0] = (id >> 8) as u8;
target[write_index] = (id >> 8) as u8;
target[write_index + 1] = (id & 0xFF) as u8;

let len = payload.len() / 4;
target[write_index + 2] = (len >> 8) as u8;
target[write_index + 3] = (len & 0xFF) as u8;

write_index = write_index + 4;
write_index += 4;

/* the target buffer has been ensured to hold that many bytes */
target[write_index..(write_index + payload.len())].copy_from_slice(payload);
Expand Down Expand Up @@ -307,12 +313,11 @@ impl<'a> RtpPacketBuilder<'a> {
}

/// Build the RTP packet.
/// On success it returns a buffer containing the target packet.
/// On success, it returns a buffer containing the target packet.
pub fn build(&self) -> Result<Vec<u8>, RtpPacketBuildError> {
self.validate_content()?;

let mut buffer = Vec::<u8>::new();
buffer.resize(self.target_length(), 0);
let mut buffer = vec![0; self.target_length()];

let length = self.build_into_unchecked(buffer.as_mut_slice());
assert_eq!(length, buffer.len());
Expand Down
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ impl std::ops::Sub for Seq {
}
impl PartialOrd for Seq {
fn partial_cmp(&self, other: &Seq) -> Option<std::cmp::Ordering> {
(*self - *other).partial_cmp(&0)
Some(self.cmp(other))
}
}
impl Ord for Seq {
Expand Down
6 changes: 3 additions & 3 deletions src/reader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -397,14 +397,14 @@ mod tests {
let reader = RtpReader::new(&TEST_RTP_PACKET).unwrap();
let buffer = reader.create_builder().build().unwrap();

assert_eq!(&buffer.as_slice()[..], &TEST_RTP_PACKET[..]);
assert_eq!(buffer.as_slice(), &TEST_RTP_PACKET[..]);
}

#[test]
fn builder_juggle_extension() {
let reader = RtpReader::new(&TEST_RTP_PACKET_WITH_EXTENSION).unwrap();
let buffer = reader.create_builder().build().unwrap();
assert_eq!(&buffer.as_slice()[..], &TEST_RTP_PACKET_WITH_EXTENSION[..]);
assert_eq!(buffer.as_slice(), &TEST_RTP_PACKET_WITH_EXTENSION[..]);
}

#[test]
Expand All @@ -418,7 +418,7 @@ mod tests {
.unwrap();

let expected = &TEST_RTP_PACKET_WITH_EXTENSION[0..(3 + 4) * 4];
assert_eq!(&buffer.as_slice()[..], expected);
assert_eq!(buffer.as_slice(), expected);
}

#[test]
Expand Down

0 comments on commit 832be80

Please sign in to comment.