Trait ssh_encoding::Encode
source · pub trait Encode {
// Required methods
fn encoded_len(&self) -> Result<usize, Error>;
fn encode(&self, writer: &mut impl Writer) -> Result<(), Error>;
// Provided methods
fn encoded_len_prefixed(&self) -> Result<usize, Error> { ... }
fn encode_prefixed(&self, writer: &mut impl Writer) -> Result<(), Error> { ... }
}
Expand description
Encoding trait.
This trait describes how to encode a given type.
Required Methods§
sourcefn encoded_len(&self) -> Result<usize, Error>
fn encoded_len(&self) -> Result<usize, Error>
Get the length of this type encoded in bytes, prior to Base64 encoding.
Provided Methods§
sourcefn encoded_len_prefixed(&self) -> Result<usize, Error>
fn encoded_len_prefixed(&self) -> Result<usize, Error>
Return the length of this type after encoding when prepended with a
uint32
length prefix.
sourcefn encode_prefixed(&self, writer: &mut impl Writer) -> Result<(), Error>
fn encode_prefixed(&self, writer: &mut impl Writer) -> Result<(), Error>
Encode this value, first prepending a uint32
length prefix
set to Encode::encoded_len
.
Implementations on Foreign Types§
source§impl Encode for usize
impl Encode for usize
Encode a usize
as a uint32
as described in RFC4251 § 5.
Uses Encode
impl on u32
after converting from a usize
, handling
potential overflow if usize
is bigger than u32
.
source§impl Encode for u32
impl Encode for u32
Encode a uint32
as described in RFC4251 § 5:
Represents a 32-bit unsigned integer. Stored as four bytes in the order of decreasing significance (network byte order). For example: the value 699921578 (0x29b7f4aa) is stored as 29 b7 f4 aa.
source§impl Encode for [u8]
impl Encode for [u8]
Encodes [u8]
into byte[n]
as described in RFC4251 § 5:
A byte represents an arbitrary 8-bit value (octet). Fixed length data is sometimes represented as an array of bytes, written
byte[n]
, where n is the number of bytes in the array.
source§impl<const N: usize> Encode for [u8; N]
impl<const N: usize> Encode for [u8; N]
Encodes [u8; N]
into byte[n]
as described in RFC4251 § 5:
A byte represents an arbitrary 8-bit value (octet). Fixed length data is sometimes represented as an array of bytes, written
byte[n]
, where n is the number of bytes in the array.
source§impl Encode for &str
impl Encode for &str
Encode a string
as described in RFC4251 § 5:
Arbitrary length binary string. Strings are allowed to contain arbitrary binary data, including null characters and 8-bit characters. They are stored as a uint32 containing its length (number of bytes that follow) and zero (= empty string) or more bytes that are the value of the string. Terminating null characters are not used.
Strings are also used to store text. In that case, US-ASCII is used for internal names, and ISO-10646 UTF-8 for text that might be displayed to the user. The terminating null character SHOULD NOT normally be stored in the string. For example: the US-ASCII string “testing” is represented as 00 00 00 07 t e s t i n g. The UTF-8 mapping does not alter the encoding of US-ASCII characters.
source§impl Encode for u64
impl Encode for u64
Encode a uint64
as described in RFC4251 § 5:
Represents a 64-bit unsigned integer. Stored as eight bytes in the order of decreasing significance (network byte order).