rtc_sdp/description/
common.rs1use std::fmt;
2
3use super::session::ATTR_KEY_CANDIDATE;
4
5pub type Information = String;
8
9#[derive(Debug, Default, Clone)]
12pub struct ConnectionInformation {
13 pub network_type: String,
14 pub address_type: String,
15 pub address: Option<Address>,
16}
17
18impl fmt::Display for ConnectionInformation {
19 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
20 if let Some(address) = &self.address {
21 write!(f, "{} {} {}", self.network_type, self.address_type, address,)
22 } else {
23 write!(f, "{} {}", self.network_type, self.address_type,)
24 }
25 }
26}
27
28#[derive(Debug, Default, Clone)]
30pub struct Address {
31 pub address: String,
32 pub ttl: Option<isize>,
33 pub range: Option<isize>,
34}
35
36impl fmt::Display for Address {
37 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
38 write!(f, "{}", self.address)?;
39 if let Some(t) = &self.ttl {
40 write!(f, "/{t}")?;
41 }
42 if let Some(r) = &self.range {
43 write!(f, "/{r}")?;
44 }
45 Ok(())
46 }
47}
48
49#[derive(Debug, Default, Clone)]
52pub struct Bandwidth {
53 pub experimental: bool,
54 pub bandwidth_type: String,
55 pub bandwidth: u64,
56}
57
58impl fmt::Display for Bandwidth {
59 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
60 let output = if self.experimental { "X-" } else { "" };
61 write!(f, "{}{}:{}", output, self.bandwidth_type, self.bandwidth)
62 }
63}
64
65pub type EncryptionKey = String;
67
68#[derive(Debug, Default, Clone)]
71pub struct Attribute {
72 pub key: String,
73 pub value: Option<String>,
74}
75
76impl fmt::Display for Attribute {
77 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
78 if let Some(value) = &self.value {
79 write!(f, "{}:{}", self.key, value)
80 } else {
81 write!(f, "{}", self.key)
82 }
83 }
84}
85
86impl Attribute {
87 pub fn new(key: String, value: Option<String>) -> Self {
89 Attribute { key, value }
90 }
91
92 pub fn is_ice_candidate(&self) -> bool {
94 self.key.as_str() == ATTR_KEY_CANDIDATE
95 }
96}