0
1

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 14

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

Last updated at Posted at 2024-12-16

はじめに

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

RTCPパーサ/ビルダ

本日はRTCPのビルダを作っていきます
プロトコルは前日までのブログを見てください。
(12/17追記:wipなのでご注意ください)

コード

pub struct RtpBuilder<'a> {
    version: u8,
    padding: u8,
    rc: u8,
    pt: u8,
    length:u16,

impl<'a> RtpBuilder<'a> {
    pub fn new() -> Self {
        RtpBuilder {
            version: 0,
            padding: 0,
            rc: 0,
            pt: 0,
            length:0,
        }
    }
    fn version(mut self, version: u8) -> Self {
        self.version = version;
        self
    }
    fn padding(mut self, padding: u8) -> Self {
        self.padding = padding;
        self
    }
    fn rc(mut self, marker: u8) -> Self {
        self.marker = marker;
        self
    }
    fn pt(mut self, payload_type: u8) -> Self {
        self.payload_type = payload_type;
        self
    }
    fn length(mut self, sequence_number: u16) -> Self {
        self.sequence_number = sequence_number;
        self
    }


    fn build(&self, rtp_packet: &mut [u8]) {
        rtp_packet[0] = self.version;
        rtp_packet[0] |= self.padding << 2;
        rtp_packet[0] |= self.rc << 3;
        rtp_packet[1] = self.pt;
        rtp_packet[2..4].copy_from_slice(&length.to_be_bytes());
        }
    }
}

終わりに

記事が手抜きになっていますね。。。
仕事が炎上しているので。。。
土日に記事執筆がんばります。。。
なんとか25記事書きたい。。。

0
1
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
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?