Struct domain::base::message_builder::StreamTarget
source · pub struct StreamTarget<Target> { /* private fields */ }
Expand description
A builder target for sending messages on stream transports.
TODO: Rename this type and adjust the doc comments as it is usable both
for datagram AND stream transports via as_dgram_slice
and
as_stream_slice
.
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 moresource§impl<Target> Composer for StreamTarget<Target>
impl<Target> Composer for StreamTarget<Target>
source§fn append_compressed_name<N: ToName + ?Sized>(
&mut self,
name: &N,
) -> Result<(), Self::AppendError>
fn append_compressed_name<N: ToName + ?Sized>( &mut self, name: &N, ) -> Result<(), Self::AppendError>
fn can_compress(&self) -> bool
source§impl<Target: Debug> Debug for StreamTarget<Target>
impl<Target: Debug> Debug for StreamTarget<Target>
source§impl<Target: Default> Default for StreamTarget<Target>
impl<Target: Default> Default for StreamTarget<Target>
source§fn default() -> StreamTarget<Target>
fn default() -> StreamTarget<Target>
source§impl<Target> OctetsBuilder for StreamTarget<Target>
impl<Target> OctetsBuilder for StreamTarget<Target>
source§type AppendError = ShortBuf
type AppendError = ShortBuf
source§fn append_slice(&mut self, slice: &[u8]) -> Result<(), Self::AppendError>
fn append_slice(&mut self, slice: &[u8]) -> Result<(), Self::AppendError>
Auto Trait Implementations§
impl<Target> Freeze for StreamTarget<Target>where
Target: Freeze,
impl<Target> RefUnwindSafe for StreamTarget<Target>where
Target: RefUnwindSafe,
impl<Target> Send for StreamTarget<Target>where
Target: Send,
impl<Target> Sync for StreamTarget<Target>where
Target: Sync,
impl<Target> Unpin for StreamTarget<Target>where
Target: Unpin,
impl<Target> UnwindSafe for StreamTarget<Target>where
Target: UnwindSafe,
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)