Struct blather::codec::Codec[][src]

pub struct Codec { /* fields omitted */ }

The Codec (exposed externally as ClntIfCodec) is used to keep track of the state of the inbound and outbound communication.

Implementations

impl Codec[src]

A Codec used to encode and decode the blather protocol.

Notes

Normally the Codec object is hidden inside a Framed object. In order to call methods in the codec it must be accessed through the Framed object:

let mut conn = Framed::new(socket, Codec::new());
// ...
conn.codec_mut().expect_chunks(len);

pub fn new() -> Codec[src]

pub fn new_with_max_length(max_line_length: usize) -> Self[src]

pub fn max_line_length(&self) -> usize[src]

pub fn expect_chunks(&mut self, size: usize)[src]

Set the decoder to treat the next size bytes as raw bytes to be received in chunks.

Decoder behavior

The decoder will return an Input::Chunk(buf, remain) to the application each time a new chunk has been received. In addition to the actual chunk number of bytes remaining will be returned. The remaining bytes value is adjusted to subtract the currently returned chunk, which means that the application can detect the end of the buffer by checking if the remaining value is zero.

pub fn expect_buf(&mut self, size: usize) -> Result<(), Error>[src]

Expect a buffer of a certain size to be received. The returned buffer will be stored in process memory.

Decoder behavior

One a complete buffer has been successfully reaceived the Decoder will return an Input::Buf(b) where b is a bytes::BytesMut containing the entire buffer.

Once the entire buffer has been received by the Decoder it will revert to expect an Input::Telegram.

pub fn expect_file<P: Into<PathBuf>>(
    &mut self,
    pathname: P,
    size: usize
) -> Result<(), Error>
[src]

Expects a certain amount of bytes of data to arrive from the peer, and that data should be stored to a file.

Decoder behavior

On successful completion the Decoder will return an Input::File(pathname) once the entire file length has successfully been received, where the pathname is a PathBuf which matches the pathname parameter passed to this function.

pub fn expect_writer<W: 'static + Write + Send + Sync>(
    &mut self,
    writer: W,
    size: usize
) -> Result<(), Error>
[src]

Called from an application to request that data should be written to a supplied writer.

The writer’s ownership will be transferred to the Decoder and will automatically be dropped once the entire buffer has been written.

Decoder behavior

On successful completion the Decoder will return an Input::WriteDone to signal that the entire buffer has been received and written to the Writer.

Once the complete Params buffer has been received the Decoder will revert back to waiting for a Telegram.

pub fn expect_params(&mut self)[src]

Tell the Decoder to expect lines of key/value pairs.

Decoder behavior

On successful completion the Framed StreamExt next() will return an Input::Params(params) once a complete Params buffer has been received.

Once the complete Params buffer has been received the Decoder will revert back to waiting for a Telegram.

pub fn expect_kvlines(&mut self)[src]

Tell the Decoder to expect lines ordered key/value pairs.

Decoder behavior

On successful completion the Framed StreamExt next() will return an Input::KVLines(kvlines) once a complete KVLines buffer has been received.

Once the complete KVLines buffer has been received the Decoder will revert back to waiting for a Telegram.

pub fn skip(&mut self, size: usize) -> Result<(), Error>[src]

Skip bytes.

Decoder behavior

Simply ignore the number of specified bytes, then revert back to waiting for a Telegram.

Trait Implementations

impl Debug for Codec[src]

impl Decoder for Codec[src]

A Decoder implementation that is used to assist in decoding data arriving over a DDM client interface.

The default behavior for the Decoder is to wait for a Telegram buffer. It will, on success, return an Input::Telegram(tg), where tg is a blather::Telegram object.

type Item = Input

The type of decoded frames.

type Error = Error

The type of unrecoverable frame decoding errors. Read more

impl Default for Codec[src]

impl Encoder<&'_ [u8]> for Codec[src]

type Error = Error

The type of encoding errors. Read more

impl Encoder<&'_ HashMap<String, String, RandomState>> for Codec[src]

type Error = Error

The type of encoding errors. Read more

impl Encoder<&'_ KVLines> for Codec[src]

type Error = Error

The type of encoding errors. Read more

impl Encoder<&'_ Params> for Codec[src]

type Error = Error

The type of encoding errors. Read more

impl Encoder<&'_ Telegram> for Codec[src]

type Error = Error

The type of encoding errors. Read more

impl Encoder<Bytes> for Codec[src]

type Error = Error

The type of encoding errors. Read more

Auto Trait Implementations

impl !RefUnwindSafe for Codec

impl Send for Codec

impl Sync for Codec

impl Unpin for Codec

impl !UnwindSafe for Codec

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> From<T> for T[src]

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

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.