Trait bpx::Interface[][src]

pub trait Interface {
    fn find_section_by_type(&self, btype: u8) -> Option<SectionHandle>;
fn find_all_sections_of_type(&self, btype: u8) -> Vec<SectionHandle>;
fn find_section_by_index(&self, index: u32) -> Option<SectionHandle>;
fn get_section_header(&self, handle: SectionHandle) -> &SectionHeader;
fn get_section_index(&self, handle: SectionHandle) -> u32;
fn open_section(
        &mut self,
        handle: SectionHandle
    ) -> Result<&mut dyn SectionData>;
fn get_main_header(&self) -> &MainHeader; }
Expand description

The interface implemented by both the BPX encoder and decoder.

Required methods

Searches for the first section of a given type. Returns None if no section could be found.

Arguments
  • btype: section type byte.

returns: Option

Examples
use bpx::encoder::Encoder;
use bpx::Interface;

let file = Encoder::new(Vec::<u8>::new()).unwrap();
assert!(file.find_section_by_type(0).is_none());

Searches for all sections of a given type. Returns None if no section could be found.

Arguments
  • btype: section type byte.

returns: Vec<SectionHandle, Global>

Examples
use bpx::encoder::Encoder;
use bpx::Interface;

let file = Encoder::new(Vec::<u8>::new()).unwrap();
assert_eq!(file.find_all_sections_of_type(0).len(), 0);

Locates a section by its index in the file. Returns None if the section does not exist.

Arguments
  • index: the section index to search for.

returns: Option

Examples
use bpx::encoder::Encoder;
use bpx::Interface;

let file = Encoder::new(Vec::<u8>::new()).unwrap();
assert!(file.find_section_by_index(0).is_none());

Returns the BPX section header of a section.

Arguments
  • handle: a handle to the section.

returns: &SectionHeader

Panics

Panics if the given section handle is invalid.

Examples
use bpx::encoder::Encoder;
use bpx::Interface;
use bpx::builder::SectionHeaderBuilder;

let mut file = Encoder::new(Vec::<u8>::new()).unwrap();
let handle = file.create_section(SectionHeaderBuilder::new().with_type(1).build()).unwrap();
let header = file.get_section_header(handle);
assert_eq!(header.btype, 1);

Returns the section index from a section handle.

Arguments
  • handle: a handle to the section.

returns: u32

Panics

Panics if the given section handle is invalid.

Examples
use bpx::encoder::Encoder;
use bpx::Interface;
use bpx::builder::SectionHeaderBuilder;

let mut file = Encoder::new(Vec::<u8>::new()).unwrap();
let handle = file.create_section(SectionHeaderBuilder::new().build()).unwrap();
assert_eq!(file.get_section_index(handle), 0);

Opens a section for read and/or write.

Arguments
  • handle: a handle to the section.

returns: Result<&mut dyn SectionData, Error>

Errors

A BPX Error if an IO or any other file error occurs while reading the section from the file.

Panics

Panics if the given section handle is invalid.

Examples
use bpx::encoder::Encoder;
use bpx::Interface;
use bpx::builder::SectionHeaderBuilder;

let mut file = Encoder::new(Vec::<u8>::new()).unwrap();
let handle = file.create_section(SectionHeaderBuilder::new().build()).unwrap();
let section = file.open_section(handle).unwrap();
let data = section.load_in_memory().unwrap();
assert_eq!(data.len(), 0);

Returns a read-only reference to the BPX main header.

Examples
use bpx::encoder::Encoder;
use bpx::Interface;
use bpx::builder::SectionHeaderBuilder;

let mut file = Encoder::new(Vec::<u8>::new()).unwrap();
let header = file.get_main_header();
//Default BPX variant/type is 'P'
assert_eq!(header.btype, 'P' as u8);

Implementors