Struct domain::base::message_builder::StreamTarget
source · pub struct StreamTarget<Target> { /* private fields */ }
Expand description
A builder target for sending messages on stream transports.
When messages are sent over stream-oriented transports such as TCP, a DNS message is preceded by a 16 bit length value in order to determine the end of a message. This type transparently adds this length value as the first two octets of an octets builder and itself presents an octets builder interface for building the actual message. Whenever data is pushed to that builder interface, the type will update the length value.
Because the length is 16 bits long, the assembled message can be at most 65536 octets long, independently of the maximum length the underlying builder allows.
Implementations§
source§impl<Target: Composer> StreamTarget<Target>
impl<Target: Composer> StreamTarget<Target>
sourcepub fn new(target: Target) -> Result<Self, Target::AppendError>
pub fn new(target: Target) -> Result<Self, Target::AppendError>
Creates a new stream target wrapping an octets builder.
The function will truncate the builder back to empty and append the length value. Because of the latter, this can fail if the octets builder doesn’t even have space for that.
source§impl StreamTarget<Vec<u8>>
impl StreamTarget<Vec<u8>>
source§impl StreamTarget<BytesMut>
impl StreamTarget<BytesMut>
source§impl<Target> StreamTarget<Target>
impl<Target> StreamTarget<Target>
sourcepub fn into_target(self) -> Target
pub fn into_target(self) -> Target
Converts the stream target into the underlying octets builder.
The returned builder will contain the 16 bit length value with the correct content and the assembled message.
source§impl<Target: AsRef<[u8]>> StreamTarget<Target>
impl<Target: AsRef<[u8]>> StreamTarget<Target>
sourcepub fn as_stream_slice(&self) -> &[u8] ⓘ
pub fn as_stream_slice(&self) -> &[u8] ⓘ
Returns an octets slice of the message for stream transports.
The slice will start with the length octets and can be send as is through a stream transport such as TCP.
sourcepub fn as_dgram_slice(&self) -> &[u8] ⓘ
pub fn as_dgram_slice(&self) -> &[u8] ⓘ
Returns an octets slice of the message for datagram transports.
The slice will not contain the length octets but only the actual message itself. This slice can be used for sending via datagram transports such as UDP.
Trait Implementations§
source§impl<Target: Clone> Clone for StreamTarget<Target>
impl<Target: Clone> Clone for StreamTarget<Target>
source§fn clone(&self) -> StreamTarget<Target>
fn clone(&self) -> StreamTarget<Target>
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read more