diff options
Diffstat (limited to 'sdp/src/lib.rs')
-rw-r--r-- | sdp/src/lib.rs | 89 |
1 files changed, 87 insertions, 2 deletions
diff --git a/sdp/src/lib.rs b/sdp/src/lib.rs index 68c3c70..15b4ce2 100644 --- a/sdp/src/lib.rs +++ b/sdp/src/lib.rs @@ -1,5 +1,5 @@ use anyhow::{anyhow, bail}; -use std::str::FromStr; +use std::{fmt::Display, str::FromStr}; pub struct SessionDescription { pub version: String, @@ -72,7 +72,7 @@ impl FromStr for SessionDescription { "m" => media_descriptions.push(MediaDescription { connection_information: None, name: value.to_string(), - title: None, + title: None, // TODO never set, forgot it somewhere encryption_key: None, attributes: Vec::new(), bandwidth: Vec::new(), @@ -126,3 +126,88 @@ impl FromStr for SessionDescription { }) } } + +impl Display for SessionDescription { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + let Self { + attributes, + bandwidth, + connection_information, + description_uri, + email_address, + encryption_key, + media_descriptions, + originator, + phone_number, + session_information, + session_name, + time_descriptions, + time_zone_adjustments, + version, + } = self; + writeln!(f, "v={version}")?; + writeln!(f, "o={originator}")?; + writeln!(f, "s={session_name}")?; + // TODO check order + if let Some(session_information) = session_information { + writeln!(f, "i={session_information}")?; + } + if let Some(description_uri) = description_uri { + writeln!(f, "u={description_uri}")?; + } + if let Some(email_address) = email_address { + writeln!(f, "e={email_address}")?; + } + if let Some(phone_number) = phone_number { + writeln!(f, "p={phone_number}")?; + } + for TimeDescription { time, repeat_times } in time_descriptions { + writeln!(f, "t={time}")?; + for repeat_time in repeat_times { + writeln!(f, "r={repeat_time}")?; + } + } + if let Some(encryption_key) = encryption_key { + writeln!(f, "k={encryption_key}")?; + } + if let Some(time_zone_adjustments) = time_zone_adjustments { + writeln!(f, "z={time_zone_adjustments}")?; + } + if let Some(connection_information) = connection_information { + writeln!(f, "c={connection_information}")?; + } + for bandwidth in bandwidth { + writeln!(f, "b={bandwidth}")?; + } + for attribute in attributes { + writeln!(f, "a={attribute}")?; + } + for MediaDescription { + name, + title, + connection_information, + bandwidth, + encryption_key, + attributes, + } in media_descriptions + { + writeln!(f, "m={name}")?; + if let Some(title) = title { + writeln!(f, "t={title}")?; // TODO was offline, check param name + } + if let Some(connection_information) = connection_information { + writeln!(f, "c={connection_information}")?; + } + for bandwidth in bandwidth { + writeln!(f, "b={bandwidth}")?; + } + if let Some(encryption_key) = encryption_key { + writeln!(f, "k={encryption_key}")?; + } + for attribute in attributes { + writeln!(f, "a={attribute}")?; + } + } + Ok(()) + } +} |