pub fn take_prefix(
        mut self,
        msg_limit: Option<usize>,
        mut byte_limit: Option<usize>,
    ) -> CertifiedSliceResult<(Option<Self>, Option<Self>)> {
        // Adjust the byte limit by subtracting the certification size.
        if let Some(byte_limit_) = byte_limit {
            let certification_count_bytes = self.certification.count_bytes();
            if certification_count_bytes > byte_limit_ {
                return Ok((None, Some(self)));
            }
            byte_limit = Some(byte_limit_ - certification_count_bytes);
        }

        match self.payload.take_prefix(msg_limit, byte_limit)? {
            (None, None) => unreachable!("slice with no messages or signals"),

            // Nothing taken, put back the payload.
            (None, Some(payload)) => {
                self.payload = payload;
                Ok((None, Some(self)))
            }

            // All messages taken.
            (Some(payload), None) => {
                self.payload = payload;
                Ok((Some(self), None))
            }

            // Messages actually split or empty (header-only) prefix.
            (Some(mut prefix_payload), Some(mut postfix_payload)) => {
                let certification = self.certification.clone();
                let prefix_witness = postfix_payload.pruned_witness(&self.merkle_proof)?;

                self.payload = postfix_payload;
                if prefix_payload.messages.is_some() {
                    // Messages actually split, prune postfix witness.
                    self.merkle_proof = prefix_payload.pruned_witness(&self.merkle_proof)?;
                }

                let prefix = UnpackedStreamSlice {
                    payload: prefix_payload,
                    merkle_proof: prefix_witness,
                    certification,
                };

                Ok((Some(prefix), Some(self)))
            }
        }
    }
/// Takes a prefix of the slice that meets the given limits. Returns the
/// prefix (if one can be created) and the remaining slice (if any).
///
/// Returns `Err(InvalidPayload)` or `Err(WitnessPruningFailed)` if
/// `self.payload` is malformed.
Takes a prefix of the slice that meets the given limits. Returns the
prefix (if one can be created) and the remaining slice (if any).


Takes a prefix of the slice that meets the given limits . Returns the prefix ( if one can be created ) and the remaining slice ( if any ) .
pub fn take_prefix(
        mut self,
        msg_limit: Option<usize>,
        mut byte_limit: Option<usize>,
    ) -> CertifiedSliceResult<(Option<Self>, Option<Self>)> {
        // Adjust the byte limit by subtracting the certification size.
        if let Some(byte_limit_) = byte_limit {
            let certification_count_bytes = self.certification.count_bytes();
            if certification_count_bytes > byte_limit_ {
                return Ok((None, Some(self)));
            }
            byte_limit = Some(byte_limit_ - certification_count_bytes);
        }
        match self.payload.take_prefix(msg_limit, byte_limit)? {
            (None, None) => unreachable!("slice with no messages or signals"),
            // Nothing taken, put back the payload.
            (None, Some(payload)) => {
                self.payload = payload;
                Ok((None, Some(self)))
            }
            // All messages taken.
            (Some(payload), None) => {
                self.payload = payload;
                Ok((Some(self), None))
            }
            // Messages actually split or empty (header-only) prefix.
            (Some(mut prefix_payload), Some(mut postfix_payload)) => {
                let certification = self.certification.clone();
                let prefix_witness = postfix_payload.pruned_witness(&self.merkle_proof)?;
                self.payload = postfix_payload;
                if prefix_payload.messages.is_some() {
                    // Messages actually split, prune postfix witness.
                    self.merkle_proof = prefix_payload.pruned_witness(&self.merkle_proof)?;
                }
                let prefix = UnpackedStreamSlice {
                    payload: prefix_payload,
                    merkle_proof: prefix_witness,
                    certification,
                };
                Ok((Some(prefix), Some(self)))
            }
        }
    }
pub fn take_prefix ( mut self , msg_limit : Option < usize > , mut byte_limit : Option < usize > , ) -> CertifiedSliceResult < ( Option < Self > , Option < Self > ) > { // Adjust the byte limit by subtracting the certification size. if let Some ( byte_limit_ ) = byte_limit { let certification_count_bytes = self . certification . count_bytes ( ) ; if certification_count_bytes > byte_limit_ { return Ok ( ( None , Some ( self ) ) ) ; } byte_limit = Some ( byte_limit_ - certification_count_bytes ) ; } match self . payload . take_prefix ( msg_limit , byte_limit ) ? { ( None , None ) => unreachable ! ( " " ) , // Nothing taken, put back the payload. ( None , Some ( payload ) ) => { self . payload = payload ; Ok ( ( None , Some ( self ) ) ) } // All messages taken. ( Some ( payload ) , None ) => { self . payload = payload ; Ok ( ( Some ( self ) , None ) ) } // Messages actually split or empty (header-only) prefix. ( Some ( mut prefix_payload ) , Some ( mut postfix_payload ) ) => { let certification = self . certification . clone ( ) ; let prefix_witness = postfix_payload . pruned_witness ( & self . merkle_proof ) ? ; self . payload = postfix_payload ; if prefix_payload . messages . is_some ( ) { // Messages actually split, prune postfix witness. self . merkle_proof = prefix_payload . pruned_witness ( & self . merkle_proof ) ? ; } let prefix = UnpackedStreamSlice { payload : prefix_payload , merkle_proof : prefix_witness , certification , } ; Ok ( ( Some ( prefix ) , Some ( self ) ) ) } } }
Takes a prefix of the slice that meets the given limits.
Takes a prefix of the slice that meets the given limits .
mut self
msg_limit
Option<usize>
byte_limit
Option<usize>
mut self
msg_limit
Option<usize>
byte_limit
Option<usize>