[][src]Enum rtsp_types::Message

pub enum Message<Body> {
    Request(Request<Body>),
    Response(Response<Body>),
    Data(Data<Body>),
}

Enum holding all possible RTSP message types.

A Message can be a Request, a Response or Data.

The body of the message is generic and usually a type that implements AsRef<[u8]>. For empty bodies there also exists the Empty type.

Variants

Request(Request<Body>)

Request message

Response(Response<Body>)

Response message

Data(Data<Body>)

Data message

Implementations

impl<Body: AsRef<[u8]>> Message<Body>[src]

pub fn write<'b, W: Write + 'b>(&self, w: &'b mut W) -> Result<(), WriteError>[src]

Serialize the message to any std::io::Write.

Resuming writing after std::io::ErrorKind::WouldBlock is not supported. Any previously written data will have to be discarded for resuming.

Serializing an RTSP message

let request = rtsp_types::Request::builder(
        rtsp_types::Method::SetParameter,
        rtsp_types::Version::V2_0
    )
    .request_uri(rtsp_types::Url::parse("rtsp://example.com/test").expect("Invalid URI"))
    .header(rtsp_types::headers::CSEQ, "2")
    .header(rtsp_types::headers::CONTENT_TYPE, "text/parameters")
    .build(Vec::from(&b"barparam: barstuff"[..]));

 let mut data = Vec::new();
 request.write(&mut data).expect("Failed to serialize request");

 assert_eq!(
    data,
    b"SET_PARAMETER rtsp://example.com/test RTSP/2.0\r\n\
      Content-Length: 18\r\n\
      Content-Type: text/parameters\r\n\
      CSeq: 2\r\n\
      \r\n\
      barparam: barstuff",
 );

pub fn write_len(&self) -> u64[src]

Calculate the number of bytes needed to serialize the message.

impl<'a, T: From<&'a [u8]>> Message<T>[src]

pub fn parse<B: AsRef<[u8]> + 'a + ?Sized>(
    buf: &'a B
) -> Result<(Self, usize), ParseError>
[src]

Try parse a message from a &[u8] and also return how many bytes were consumed.

The body type of the returned message can be any type that implements From<&[u8]>. This includes Vec<u8> and &[u8] among others.

If parsing the message succeeds, in addition to the message itself also the number of bytes that were consumed from the input data are returned. This allows the caller to advance to the next message.

If parsing the message fails with ParseError::Incomplete then the caller has to provide more data for successfully parsing the message.

Otherwise, if parsing the message fails with ParseError::Error then the message can't be parsed and the caller can try skipping over some data until parsing succeeds again.

Parsing an RTSP message

let data = b"OPTIONS * RTSP/2.0\r\n\
             CSeq: 1\r\n\
             Supported: play.basic, play.scale\r\n\
             User-Agent: PhonyClient/1.2\r\n\
             \r\n";

let (message, consumed): (rtsp_types::Message<Vec<u8>>, _) =
    rtsp_types::Message::parse(data).expect("Failed to parse data");

assert_eq!(consumed, data.len());
match message {
    rtsp_types::Message::Request(ref request) => {
        assert_eq!(request.method(), rtsp_types::Method::Options);
    },
    _ => unreachable!(),
}

Trait Implementations

impl<Body: Clone> Clone for Message<Body>[src]

impl<Body: Debug> Debug for Message<Body>[src]

impl<Body: Eq> Eq for Message<Body>[src]

impl<Body: PartialEq> PartialEq<Message<Body>> for Message<Body>[src]

impl<Body> StructuralEq for Message<Body>[src]

impl<Body> StructuralPartialEq for Message<Body>[src]

Auto Trait Implementations

impl<Body> RefUnwindSafe for Message<Body> where
    Body: RefUnwindSafe

impl<Body> Send for Message<Body> where
    Body: Send

impl<Body> Sync for Message<Body> where
    Body: Sync

impl<Body> Unpin for Message<Body> where
    Body: Unpin

impl<Body> UnwindSafe for Message<Body> where
    Body: UnwindSafe

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> Conv for T

impl<T> Conv for T

impl<T> FmtForward for T

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> Pipe for T where
    T: ?Sized

impl<T> Pipe for T

impl<T> PipeAsRef for T

impl<T> PipeBorrow for T

impl<T> PipeDeref for T

impl<T> PipeRef for T

impl<T> Tap for T

impl<T> Tap for T

impl<T, U> TapAsRef<U> for T where
    U: ?Sized

impl<T, U> TapBorrow<U> for T where
    U: ?Sized

impl<T> TapDeref for T

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T> TryConv for T

impl<T> TryConv for T

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.