fn from_payload(payload: &[u8]) -> Vec<Frame> {
        let mut frames = Vec::new();

        let max_addr = (payload
            .chunks(4)
            .rposition(|c| c != &[0xff; 4])
            .unwrap_or(0)
            + 1)
            * 4;

        let mut frame_num = 0;
        let mut addr = 0;
        while addr < max_addr {
            // Try skipping over 0xffffffff words.
            let nonempty_addr = addr
                + payload[addr..]
                    .chunks(4)
                    .position(|c| c != &[0xff; 4])
                    .unwrap()
                    * 4;
            let skip_addr = nonempty_addr & !Self::FLASH_SECTOR_MASK;
            if skip_addr > addr && (addr == 0 || addr & Self::FLASH_BUFFER_MASK != 0) {
                // Can only skip from the start or if the last addr wasn't an exact multiple of
                // 128 (per H1D boot rom).
                addr = skip_addr;
            }

            let mut frame = Frame {
                header: FrameHeader {
                    frame_num,
                    flash_offset: (addr + Self::FLASH_BASE_ADDRESS) as u32,
                    ..Default::default()
                },
                ..Default::default()
            };
            let slice_size = Self::DATA_LEN.min(payload.len() - addr);
            frame.data[..slice_size].copy_from_slice(&payload[addr..addr + slice_size]);
            frame.header.hash = frame.header_hash();
            frames.push(frame);

            addr += Self::DATA_LEN;
            frame_num += 1;
        }
        frames.last_mut().map(|f| f.header.frame_num |= Self::EOF);
        frames
    }
/// Creates a sequence of frames based on a `payload` binary.
Creates a sequence of frames based on a `payload` binary.
Creates a sequence of frames based on a ` payload ` binary .
fn from_payload(payload: &[u8]) -> Vec<Frame> {
        let mut frames = Vec::new();
        let max_addr = (payload
            .chunks(4)
            .rposition(|c| c != &[0xff; 4])
            .unwrap_or(0)
            + 1)
            * 4;
        let mut frame_num = 0;
        let mut addr = 0;
        while addr < max_addr {
            // Try skipping over 0xffffffff words.
            let nonempty_addr = addr
                + payload[addr..]
                    .chunks(4)
                    .position(|c| c != &[0xff; 4])
                    .unwrap()
                    * 4;
            let skip_addr = nonempty_addr & !Self::FLASH_SECTOR_MASK;
            if skip_addr > addr && (addr == 0 || addr & Self::FLASH_BUFFER_MASK != 0) {
                // Can only skip from the start or if the last addr wasn't an exact multiple of
                // 128 (per H1D boot rom).
                addr = skip_addr;
            }
            let mut frame = Frame {
                header: FrameHeader {
                    frame_num,
                    flash_offset: (addr + Self::FLASH_BASE_ADDRESS) as u32,
                    ..Default::default()
                },
                ..Default::default()
            };
            let slice_size = Self::DATA_LEN.min(payload.len() - addr);
            frame.data[..slice_size].copy_from_slice(&payload[addr..addr + slice_size]);
            frame.header.hash = frame.header_hash();
            frames.push(frame);
            addr += Self::DATA_LEN;
            frame_num += 1;
        }
        frames.last_mut().map(|f| f.header.frame_num |= Self::EOF);
        frames
    }
fn from_payload ( payload : & [ u8 ] ) -> Vec < Frame > { let mut frames = Vec :: new ( ) ; let max_addr = ( payload . chunks ( 4 ) . rposition ( | c | c != & [ 0xff ; 4 ] ) . unwrap_or ( 0 ) + 1 ) * 4 ; let mut frame_num = 0 ; let mut addr = 0 ; while addr < max_addr { // Try skipping over 0xffffffff words. let nonempty_addr = addr + payload [ addr .. ] . chunks ( 4 ) . position ( | c | c != & [ 0xff ; 4 ] ) . unwrap ( ) * 4 ; let skip_addr = nonempty_addr & ! Self :: FLASH_SECTOR_MASK ; if skip_addr > addr && ( addr == 0 || addr & Self :: FLASH_BUFFER_MASK != 0 ) { // Can only skip from the start or if the last addr wasn't an exact multiple of // 128 (per H1D boot rom). addr = skip_addr ; } let mut frame = Frame { header : FrameHeader { frame_num , flash_offset : ( addr + Self :: FLASH_BASE_ADDRESS ) as u32 , .. Default :: default ( ) } , .. Default :: default ( ) } ; let slice_size = Self :: DATA_LEN . min ( payload . len ( ) - addr ) ; frame . data [ .. slice_size ] . copy_from_slice ( & payload [ addr .. addr + slice_size ] ) ; frame . header . hash = frame . header_hash ( ) ; frames . push ( frame ) ; addr += Self :: DATA_LEN ; frame_num += 1 ; } frames . last_mut ( ) . map ( | f | f . header . frame_num |= Self :: EOF ) ; frames }
Creates a sequence of frames based on a `payload` binary.
Creates a sequence of frames based on a ` payload ` binary .
payload
&[u8]