pub fn create(
        &mut self,
        minimum_ram_size: u32,
        writeable_flash_regions: usize,
        package_name: String,
    ) -> usize {
        // Need to calculate lengths ahead of time.
        // Need the base and the main section.
        let mut header_length = mem::size_of::<TbfHeaderBase>() + mem::size_of::<TbfHeaderMain>();

        // If we have a package name, add that section.
        self.package_name_pad = if !package_name.is_empty() {
            // Header increases by the TLV and name length.
            header_length += mem::size_of::<TbfHeaderTlv>() + package_name.len();
            // How much padding is needed to ensure we are aligned to 4?
            let pad = align4needed!(header_length);
            // Header length increases by that padding
            header_length += pad;
            pad
        } else {
            0
        };

        // Add room for the writeable flash regions header TLV.
        header_length += mem::size_of::<TbfHeaderWriteableFlashRegion>() * writeable_flash_regions;

        // Flags default to app is enabled.
        let flags = 0x0000_0001;

        // Fill in the fields that we can at this point.
        self.hdr_base.header_size = header_length as u16;
        self.hdr_base.flags = flags;
        self.hdr_main.minimum_ram_size = minimum_ram_size;

        // If a package name exists, keep track of it and add it to the header.
        self.package_name = package_name;
        if !self.package_name.is_empty() {
            self.hdr_pkg_name_tlv = Some(TbfHeaderTlv {
                tipe: TbfHeaderTypes::PackageName,
                length: self.package_name.len() as u16,
            });
        }

        // If there is an app state region, start setting up that header.
        for _ in 0..writeable_flash_regions {
            self.hdr_wfr.push(TbfHeaderWriteableFlashRegion {
                base: TbfHeaderTlv {
                    tipe: TbfHeaderTypes::WriteableFlashRegions,
                    length: 8,
                },
                offset: 0,
                size: 0,
            });
        }

        // Return the length by generating the header and seeing how long it is.
        self.generate()
            .expect("No header was generated")
            .get_ref()
            .len()
    }
/// Start creating the Tock Binary Format Header. This function expects
/// a few parameters that should be known very easily. Other values that
/// we need to create the header (like the location of things in the flash
/// binary) can be passed in later after we know the size of the header.
///
/// Returns: The length of the header in bytes. The length is guaranteed
///          to be a multiple of 4.
Start creating the Tock Binary Format Header. This function expects
a few parameters that should be known very easily. Other values that
we need to create the header (like the location of things in the flash
binary) can be passed in later after we know the size of the header.

The length of the header in bytes. The length is guaranteed
to be a multiple of 4.
Start creating the Tock Binary Format Header . This function expects a few parameters that should be known very easily . Other values that we need to create the header ( like the location of things in the flash binary ) can be passed in later after we know the size of the header . The length of the header in bytes . The length is guaranteed to be a multiple of 4 .
pub fn create(
        &mut self,
        minimum_ram_size: u32,
        writeable_flash_regions: usize,
        package_name: String,
    ) -> usize {
        // Need to calculate lengths ahead of time.
        // Need the base and the main section.
        let mut header_length = mem::size_of::<TbfHeaderBase>() + mem::size_of::<TbfHeaderMain>();
        // If we have a package name, add that section.
        self.package_name_pad = if !package_name.is_empty() {
            // Header increases by the TLV and name length.
            header_length += mem::size_of::<TbfHeaderTlv>() + package_name.len();
            // How much padding is needed to ensure we are aligned to 4?
            let pad = align4needed!(header_length);
            // Header length increases by that padding
            header_length += pad;
            pad
        } else {
            0
        };
        // Add room for the writeable flash regions header TLV.
        header_length += mem::size_of::<TbfHeaderWriteableFlashRegion>() * writeable_flash_regions;
        // Flags default to app is enabled.
        let flags = 0x0000_0001;
        // Fill in the fields that we can at this point.
        self.hdr_base.header_size = header_length as u16;
        self.hdr_base.flags = flags;
        self.hdr_main.minimum_ram_size = minimum_ram_size;
        // If a package name exists, keep track of it and add it to the header.
        self.package_name = package_name;
        if !self.package_name.is_empty() {
            self.hdr_pkg_name_tlv = Some(TbfHeaderTlv {
                tipe: TbfHeaderTypes::PackageName,
                length: self.package_name.len() as u16,
            });
        }
        // If there is an app state region, start setting up that header.
        for _ in 0..writeable_flash_regions {
            self.hdr_wfr.push(TbfHeaderWriteableFlashRegion {
                base: TbfHeaderTlv {
                    tipe: TbfHeaderTypes::WriteableFlashRegions,
                    length: 8,
                },
                offset: 0,
                size: 0,
            });
        }
        // Return the length by generating the header and seeing how long it is.
        self.generate()
            .expect("No header was generated")
            .get_ref()
            .len()
    }
pub fn create ( & mut self , minimum_ram_size : u32 , writeable_flash_regions : usize , package_name : String , ) -> usize { // Need to calculate lengths ahead of time. // Need the base and the main section. let mut header_length = mem :: size_of :: < TbfHeaderBase > ( ) + mem :: size_of :: < TbfHeaderMain > ( ) ; // If we have a package name, add that section. self . package_name_pad = if ! package_name . is_empty ( ) { // Header increases by the TLV and name length. header_length += mem :: size_of :: < TbfHeaderTlv > ( ) + package_name . len ( ) ; // How much padding is needed to ensure we are aligned to 4? let pad = align4needed ! ( header_length ) ; // Header length increases by that padding header_length += pad ; pad } else { 0 } ; // Add room for the writeable flash regions header TLV. header_length += mem :: size_of :: < TbfHeaderWriteableFlashRegion > ( ) * writeable_flash_regions ; // Flags default to app is enabled. let flags = 0x0000_0001 ; // Fill in the fields that we can at this point. self . hdr_base . header_size = header_length as u16 ; self . hdr_base . flags = flags ; self . hdr_main . minimum_ram_size = minimum_ram_size ; // If a package name exists, keep track of it and add it to the header. self . package_name = package_name ; if ! self . package_name . is_empty ( ) { self . hdr_pkg_name_tlv = Some ( TbfHeaderTlv { tipe : TbfHeaderTypes :: PackageName , length : self . package_name . len ( ) as u16 , } ) ; } // If there is an app state region, start setting up that header. for _ in 0 .. writeable_flash_regions { self . hdr_wfr . push ( TbfHeaderWriteableFlashRegion { base : TbfHeaderTlv { tipe : TbfHeaderTypes :: WriteableFlashRegions , length : 8 , } , offset : 0 , size : 0 , } ) ; } // Return the length by generating the header and seeing how long it is. self . generate ( ) . expect ( " " ) . get_ref ( ) . len ( ) }
Start creating the Tock Binary Format Header.
Start creating the Tock Binary Format Header .
&mut self
minimum_ram_size
u32
writeable_flash_regions
usize
package_name
String
&mut self
minimum_ram_size
u32
writeable_flash_regions
usize
package_name
String