1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36
use std::fmt; use nom::{ IResult, combinator::map, branch::alt, bytes::complete::tag }; #[derive(Debug, PartialEq, Clone)] pub enum SdpTransport { Udp, Tcp, RtpAvp, RtpSavp } pub fn parse_transport(input: &[u8]) -> IResult<&[u8], SdpTransport> { alt(( map(tag("UDP"), |_| SdpTransport::Udp), map(tag("TCP"), |_| SdpTransport::Tcp), map(tag("RTP/AVP"), |_| SdpTransport::RtpAvp), map(tag("RTP/SAVP"), |_| SdpTransport::RtpSavp) ))(input) } impl fmt::Display for SdpTransport { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { match self { SdpTransport::Udp => write!(f, "UDP"), SdpTransport::Tcp => write!(f, "TCP"), SdpTransport::RtpAvp => write!(f, "RTP/AVP"), SdpTransport::RtpSavp => write!(f, "RTP/SAVP") } } }