pub trait Encode {
    type Error: From<Error>;

    fn encoded_len(&self) -> Result<usize, Self::Error>;
    fn encode(&self, writer: &mut impl Writer) -> Result<(), Self::Error>;

    fn encoded_len_prefixed(&self) -> Result<usize, Self::Error> { ... }
    fn encode_prefixed(
        &self,
        writer: &mut impl Writer
    ) -> Result<(), Self::Error> { ... } }
Expand description

Encoding trait.

This trait describes how to encode a given type.

Required Associated Types

Type returned in the event of an encoding error.

Required Methods

Get the length of this type encoded in bytes, prior to Base64 encoding.

Encode this value using the provided Writer.

Provided Methods

Return the length of this type after encoding when prepended with a uint32 length prefix.

Encode this value, first prepending a uint32 length prefix set to Encode::encoded_len.

Implementations on Foreign Types

Encode a single byte to the writer.

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.

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).

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.

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.

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.

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.

Implementors