pub fn read_bytes(
        &mut self,
        address: &mut Option<SocketAddress>,
        max_bytes: usize,
    ) -> (Vec<Message>, usize) {
        let mut number_of_bytes_read = 0;
        let mut messages = vec![];
        while let Some(mut message) = self.read_message() {
            if message.address.is_some() && *address != message.address {
                if address.is_some() {
                    // We've already locked onto an address for this batch of messages, but we
                    // have found a message that doesn't match. We put it back for now and
                    // return the messages we have so far.
                    self.write_front(message);
                    break;
                }
                *address = message.address.clone();
            }

            // The split_packet contains any bytes that did not fit within the bounds.
            let split_packet = message.data.split_off(max_bytes - number_of_bytes_read);
            number_of_bytes_read += message.len();

            if !split_packet.is_empty() {
                // If not all the message data could fit move the ancillary data to the split off
                // message, so that the ancillary data is returned with the "last" message.
                self.write_front(Message::new(
                    split_packet,
                    message.address.clone(),
                    message.ancillary_data.take(),
                ));
            }

            // Whether or not the message has ancillary data. Note that this needs to be computed
            // after the split of message is pushed, since it might take ownership of the ancillary
            // data.
            let message_has_ancillary_data = message.ancillary_data.is_some();

            if !message.data.is_empty() {
                // If the message data is not empty (i.e., there were still some bytes that could
                // fit), push the message to the result.
                messages.push(message.into());
            }

            if number_of_bytes_read == max_bytes || message_has_ancillary_data {
                // If max_bytes have been read, or there is ancillary data, break the loop.
                break;
            }
        }

        (messages, number_of_bytes_read)
    }
/// Reads messages, where the total length of the returned messages is less than `max_bytes`.
///
/// Messages with ancillary data serve as dividers, and if such a message is encountered no more
/// messages will be read, even if less than `max_bytes` have been read.
///
/// Messages will be treated as streams, so messages may be split if the entire message does not
/// fit within the remaining bytes.
///
/// Returns a vector of read messages, where the sum of the message lengths is guaranteed to be
/// less than `max_bytes`. The returned `usize` indicates the exact number of bytes read.
Reads messages, where the total length of the returned messages is less than `max_bytes`.
Messages with ancillary data serve as dividers, and if such a message is encountered no more
messages will be read, even if less than `max_bytes` have been read.

Messages will be treated as streams, so messages may be split if the entire message does not
fit within the remaining bytes.

Returns a vector of read messages, where the sum of the message lengths is guaranteed to be
less than `max_bytes`. The returned `usize` indicates the exact number of bytes read.
Reads messages where the total length of the returned messages is less than ` max_bytes ` . Messages with ancillary data serve as dividers and if such a message is encountered no more messages will be read even if less than ` max_bytes ` have been read . Messages will be treated as streams so messages may be split if the entire message does not fit within the remaining bytes . Returns a vector of read messages where the sum of the message lengths is guaranteed to be less than ` max_bytes ` . The returned ` usize ` indicates the exact number of bytes read .
pub fn read_bytes(
        &mut self,
        address: &mut Option<SocketAddress>,
        max_bytes: usize,
    ) -> (Vec<Message>, usize) {
        let mut number_of_bytes_read = 0;
        let mut messages = vec![];
        while let Some(mut message) = self.read_message() {
            if message.address.is_some() && *address != message.address {
                if address.is_some() {
                    // We've already locked onto an address for this batch of messages, but we
                    // have found a message that doesn't match. We put it back for now and
                    // return the messages we have so far.
                    self.write_front(message);
                    break;
                }
                *address = message.address.clone();
            }
            // The split_packet contains any bytes that did not fit within the bounds.
            let split_packet = message.data.split_off(max_bytes - number_of_bytes_read);
            number_of_bytes_read += message.len();
            if !split_packet.is_empty() {
                // If not all the message data could fit move the ancillary data to the split off
                // message, so that the ancillary data is returned with the "last" message.
                self.write_front(Message::new(
                    split_packet,
                    message.address.clone(),
                    message.ancillary_data.take(),
                ));
            }
            // Whether or not the message has ancillary data. Note that this needs to be computed
            // after the split of message is pushed, since it might take ownership of the ancillary
            // data.
            let message_has_ancillary_data = message.ancillary_data.is_some();
            if !message.data.is_empty() {
                // If the message data is not empty (i.e., there were still some bytes that could
                // fit), push the message to the result.
                messages.push(message.into());
            }
            if number_of_bytes_read == max_bytes || message_has_ancillary_data {
                // If max_bytes have been read, or there is ancillary data, break the loop.
                break;
            }
        }
        (messages, number_of_bytes_read)
    }
pub fn read_bytes ( & mut self , address : & mut Option < SocketAddress > , max_bytes : usize , ) -> ( Vec < Message > , usize ) { let mut number_of_bytes_read = 0 ; let mut messages = vec ! [ ] ; while let Some ( mut message ) = self . read_message ( ) { if message . address . is_some ( ) && * address != message . address { if address . is_some ( ) { // We've already locked onto an address for this batch of messages, but we // have found a message that doesn't match. We put it back for now and // return the messages we have so far. self . write_front ( message ) ; break ; } * address = message . address . clone ( ) ; } // The split_packet contains any bytes that did not fit within the bounds. let split_packet = message . data . split_off ( max_bytes - number_of_bytes_read ) ; number_of_bytes_read += message . len ( ) ; if ! split_packet . is_empty ( ) { // If not all the message data could fit move the ancillary data to the split off // message, so that the ancillary data is returned with the "last" message. self . write_front ( Message :: new ( split_packet , message . address . clone ( ) , message . ancillary_data . take ( ) , ) ) ; } // Whether or not the message has ancillary data. Note that this needs to be computed // after the split of message is pushed, since it might take ownership of the ancillary // data. let message_has_ancillary_data = message . ancillary_data . is_some ( ) ; if ! message . data . is_empty ( ) { // If the message data is not empty (i.e., there were still some bytes that could // fit), push the message to the result. messages . push ( message . into ( ) ) ; } if number_of_bytes_read == max_bytes || message_has_ancillary_data { // If max_bytes have been read, or there is ancillary data, break the loop. break ; } } ( messages , number_of_bytes_read ) }
Reads messages, where the total length of the returned messages is less than `max_bytes`.
Reads messages where the total length of the returned messages is less than ` max_bytes ` .
&mut self
address
&mut Option<SocketAddress>
max_bytes
usize
&mut self
address
&mut Option<SocketAddress>
max_bytes
usize