0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

ひとりアドベントカレンダー by MasAdvent Calendar 2024

Day 15

VoIPとSIPを通じてRustを勉強する:RTCP作成編2(共通部作成パーサ編)

Posted at

はじめに

本記事は自分のためでしかないアドベントカレンダー2024の記事です。
記事は25記事書くと思いますが期待はせずにお願いします

RTCPパーサ

本日はRTCPのパーサを作っていきます
プロトコルは前日までのブログを見てください。

パーサ

struct RtcpPacketParser<'a> {
    rtp_packet: &'a [u8],
}

impl<'a> RtcpPacketParser<'a> {
    pub fn new(rtp_packet: &'a [u8]) -> Self {
        let retval = RtpPacketParser {
            rtp_packet: &rtp_packet,
        };

        return retval;
    }

    fn version(&self) -> u8 {
        return self.rtp_packet[0] & 0b0000_0011;
    }

    fn padding(&self) -> u8 {
        return self.rtp_packet[0] & 0b0000_0100;
    }

    fn rc(&self) -> u8 {
        return self.rtp_packet[0] & 0b1111_1000;
    }
    fn pt(&self) -> u8 {
        return self.rtp_packet[1];
    }
    fn sequence_number(&self) -> u16 {
        return u16::from_be_bytes(self.rtp_packet[2..4].try_into().unwrap());
    }
}

以上です

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?