[−][src]Struct blather::codec::Codec
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]
&mut self,
pathname: P,
size: usize
) -> Result<(), Error>
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]
&mut self,
writer: W,
size: usize
) -> Result<(), Error>
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
fn decode(&mut self, buf: &mut BytesMut) -> Result<Option<Input>, Error>
[src]
fn decode_eof(
&mut self,
buf: &mut BytesMut
) -> Result<Option<Self::Item>, Self::Error>
[src]
&mut self,
buf: &mut BytesMut
) -> Result<Option<Self::Item>, Self::Error>
fn framed<T>(self, io: T) -> Framed<T, Self> where
T: AsyncRead + AsyncWrite,
[src]
T: AsyncRead + AsyncWrite,
impl Default for Codec
[src]
impl<'_> Encoder<&'_ HashMap<String, String, RandomState>> for Codec
[src]
type Error = Error
The type of encoding errors. Read more
fn encode(
&mut self,
data: &HashMap<String, String>,
buf: &mut BytesMut
) -> Result<(), Error>
[src]
&mut self,
data: &HashMap<String, String>,
buf: &mut BytesMut
) -> Result<(), Error>
impl<'_> Encoder<&'_ KVLines> for Codec
[src]
type Error = Error
The type of encoding errors. Read more
fn encode(&mut self, kvlines: &KVLines, buf: &mut BytesMut) -> Result<(), Error>
[src]
impl<'_> Encoder<&'_ Params> for Codec
[src]
type Error = Error
The type of encoding errors. Read more
fn encode(&mut self, params: &Params, buf: &mut BytesMut) -> Result<(), Error>
[src]
impl<'_> Encoder<&'_ Telegram> for Codec
[src]
type Error = Error
The type of encoding errors. Read more
fn encode(&mut self, tg: &Telegram, buf: &mut BytesMut) -> Result<(), Error>
[src]
impl Encoder<Bytes> for Codec
[src]
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]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
pub fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,