Expand description
§Encoding of messages.
To facilitates handling of literals,Encoder::encode returns an instance ofEncoded
.The idea is that the encoder not only “dumps” the final serialization of a message but can be iterated over.
§Example
useimap_codec::{ encode::{Encoder, Fragment}, imap_types::{ command::{Command, CommandBody}, core::LiteralMode, }, CommandCodec,};letcommand = Command::new("A1", CommandBody::login("Alice","Pa²²W0rD").unwrap()).unwrap();forfragmentinCommandCodec::default().encode(&command) {matchfragment { Fragment::Line { data } => {// A line that is ready to be send.println!("C: {}", String::from_utf8(data).unwrap()); } Fragment::Literal { data, mode } =>matchmode { LiteralMode::Sync => {// Wait for a continuation request.println!("S: + ...") } LiteralMode::NonSync => {// We don't need to wait for a continuation request // as the server will also not send it.} }, }}
Output of example:
C: A1 LOGIN alice {10}S: + ...C: Pa²²W0rD
Structs§
- Encoded
- An encoded message.
Enums§
- Fragment
- The intended action of a client or server.
Traits§
- Encoder
- Encoder.