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