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
37
38
39
use std::fmt;

use nom::{
    IResult,
    branch::alt,
    combinator::map,
    bytes::complete::tag_no_case
};

#[derive(Debug, PartialEq, Clone)]
pub enum SdpAttributeType {
    Rtpmap,
    RecvOnly,
    SendOnly,
    SendRecv,
    Fmtp
}

impl fmt::Display for SdpAttributeType {
    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
        match self {
            SdpAttributeType::Rtpmap => write!(f, "rtpmap"),
            SdpAttributeType::RecvOnly => write!(f, "recvonly"),
            SdpAttributeType::SendRecv => write!(f, "sendrecv"),
            SdpAttributeType::SendOnly => write!(f, "sendonly"),
            SdpAttributeType::Fmtp => write!(f, "fmtp")
        }
    }
}

pub fn parse_attribute_type(input: &[u8]) -> IResult<&[u8], SdpAttributeType> {
    alt((
      map(tag_no_case("rtpmap"), |_| SdpAttributeType::Rtpmap),
      map(tag_no_case("fmtp"), |_| SdpAttributeType::Fmtp),
      map(tag_no_case("recvonly"), |_| SdpAttributeType::RecvOnly),
      map(tag_no_case("sendrecv"), |_| SdpAttributeType::SendRecv),
      map(tag_no_case("sendonly"), |_| SdpAttributeType::SendOnly)
    ))(input)
}