pub trait Compress {
// Required method
fn compress(&self, buf: &mut Compressor) -> Result<(), ShortBuf>;
}
Expand description
A type that knows how to compress itself.
The term compressing
refers to the process of producing the DNS
wire-format representation of a value’s data allowing it to optionally
employ domain name compression.
Because BufMut
doesn’t allow looking back at the data added to the
message before, compression cannot be implemented using just Compose
.
Instead, a special type, Compressor
is provided that implements all
the necessary logic for name compression.
Compress
should only be implemented for domain name types or types that
contain or may contain domain names and want to support name compression.
For all other types, Compressor::compose
uses their Compose
implementation for appending.
Required Methods§
Sourcefn compress(&self, buf: &mut Compressor) -> Result<(), ShortBuf>
fn compress(&self, buf: &mut Compressor) -> Result<(), ShortBuf>
Appends the wire-format representation of the value to buf
.
If buf
does not have enough space available for appending the
representation, the method returns an error. If this happens, some
data may have been appended to the buffer.
For implementers of composite types, this means that they can simply
compress or compose their consitutent types onto buf
bailing out
if that fails. There is no need to truncate buf
back to its prior
state on failure.