optimize: replace if..else by match
@@ -170,12 +170,14 @@ impl Depacketizer for H264Packet {
// https://tools.ietf.org/html/rfc6184#section-5.4
let b0 = packet[0];
let nalu_type = b0 & NALU_TYPE_BITMASK;
- if nalu_type > 0 && nalu_type < 24 {
+
+ match nalu_type {
+ 1..=23 => {
payload.put(&*ANNEXB_NALUSTART_CODE);
payload.put(&*packet.clone());
self.payload = payload.freeze();
- Ok(())
- } else if nalu_type == STAPA_NALU_TYPE {
+ }
+ STAPA_NALU_TYPE => {
let mut curr_offset = STAPA_HEADER_SIZE;
while curr_offset < packet.len() {
let nalu_size =
@@ -194,8 +196,8 @@ impl Depacketizer for H264Packet {
}
self.payload = payload.freeze();
- Ok(())
- } else if nalu_type == FUA_NALU_TYPE {
+ }
+ FUA_NALU_TYPE => {
if packet.len() < FUA_HEADER_SIZE as usize {
return Err(Error::ErrShortPacket);
}
@@ -210,13 +212,13 @@ impl Depacketizer for H264Packet {
payload.put_slice(&*packet.slice(FUA_HEADER_SIZE as usize..));
self.payload = payload.freeze();
- Ok(())
} else {
self.payload = packet.slice(FUA_HEADER_SIZE as usize..);
- Ok(())
}
- } else {
- Err(Error::NaluTypeIsNotHandled(nalu_type))
}
+ _ => return Err(Error::NaluTypeIsNotHandled(nalu_type)),
+ }
+
+ Ok(())
}
}
