Struct kerbalobjects::ko::KOFile

source ·
pub struct KOFile { /* private fields */ }
Expand description

An in-memory representation of a KO file

Can be modified, written, or read.

Implementations§

source§

impl KOFile

source

pub fn new() -> Self

Creates a new, empty, Kerbal Object file.

Creates a new section header table, initialized with a first element that is a Null section, and a string table that is the section header string table.

source

pub fn add_section_name(&mut self, name: impl Into<String>) -> StringIdx

Adds a new string to the section header string table

source

pub fn get_section_name(&self, index: StringIdx) -> Option<&String>

Gets a section name from the section header string table at the specified index, or returns None if none exists at that index

source

pub fn get_section_name_by_index(&self, index: SectionIdx) -> Option<&String>

Returns the name of the section referred to by the index into the Kerbal Object file’s section header table, or None if a section header at that index doesn’t exist

source

pub fn add_section_header(&mut self, header: SectionHeader) -> SectionIdx

Adds a new section header to the section header table, and returns the index of the section header

This will panic if you insert more than u16::MAX section headers. Don’t do that.

source

pub fn get_section_header(&self, index: SectionIdx) -> Option<&SectionHeader>

Gets the section header at the provided index into the section header table, or None if none exists at that index

source

pub fn get_header_name(&self, header: &SectionHeader) -> Option<&String>

Gets the name of the section referred to by the provided section header, or None if no section with that header is found in this KO file

source

pub fn add_str_tab(&mut self, str_tab: StringTable)

Adds a new string table to this Kerbal Object file

source

pub fn add_sym_tab(&mut self, sym_tab: SymbolTable)

Adds a new symbol table to this Kerbal Object file

source

pub fn add_data_section(&mut self, data_section: DataSection)

Adds a new data section to this Kerbal Object file

source

pub fn add_func_section(&mut self, func_section: FuncSection)

Adds a new function section to this Kerbal Object file

source

pub fn add_reld_section(&mut self, reld_section: ReldSection)

Adds a new relocation data section to this Kerbal Object file

source

pub fn str_tabs(&self) -> Iter<'_, StringTable>

Returns an iterator over all of the string tables in this Kerbal Object file

source

pub fn sym_tabs(&self) -> Iter<'_, SymbolTable>

Returns an iterator over all of the symbol tables in this Kerbal Object file

source

pub fn data_sections(&self) -> Iter<'_, DataSection>

Returns an iterator over all of the data sections in this Kerbal Object file

source

pub fn func_sections(&self) -> Iter<'_, FuncSection>

Returns an iterator over all of the function sections in this Kerbal Object file

source

pub fn reld_sections(&self) -> Iter<'_, ReldSection>

Returns an iterator over all of the relocation data sections in this Kerbal Object file

source

pub fn new_section_header( &mut self, name: impl Into<String>, kind: SectionKind ) -> SectionIdx

Adds a new section header of the provided name and section kind to this Kerbal Object file, and returns the index into the section header table of this new header

source

pub fn get_section_index_by_name( &self, name: impl AsRef<str> ) -> Option<SectionIdx>

Returns the index into the section header table of the section with the provided name, or None if there is no such section

source

pub fn header(&self) -> KOHeader

The Kerbal Object file header

source

pub fn section_headers(&self) -> Iter<'_, SectionHeader>

Returns an iterator over all section headers in the Kerbal Object file’s section header table

source

pub fn section_header_count(&self) -> usize

Returns the number of sections registered in the section header table. This will always be at least 1, because of the Null section present in all valid section header tables.

source

pub fn shstrtab_index(&self) -> SectionIdx

The index into the section header table of the section header string table

source

pub fn validate(self) -> Result<WritableKOFile, (Self, ValidationError)>

Consumes and verifies that a Kerbal Object file’s section header data is sound so that it can be written out as a proper KerbalObject file

This can fail if a section header kind doesn’t match with a section’s kind, or if a section’s header index doesn’t exist

A WritableKOFile can be turned back into a KOFile

source

pub fn parse(source: &mut BufferIterator<'_>) -> Result<Self, KOParseError>

Parses an entire KOFile from a byte buffer

source§

impl KOFile

source

pub fn new_strtab(&mut self, name: impl Into<String>) -> StringTable

Creates a new StringTable, and adds a new entry for it in the section header table with the provided name.

Returns the new StringTable

source

pub fn new_symtab(&mut self, name: impl Into<String>) -> SymbolTable

Creates a new SymbolTable, and adds a new entry for it in the section header table with the provided name.

Returns the new SymbolTable

source

pub fn new_data_section(&mut self, name: impl Into<String>) -> DataSection

Creates a new DataSection, and adds a new entry for it in the section header table with the provided name.

Returns the new DataSection

source

pub fn new_func_section(&mut self, name: impl Into<String>) -> FuncSection

Creates a new FuncSection, and adds a new entry for it in the section header table with the provided name.

Returns the new FuncSection

source

pub fn new_reld_section(&mut self, name: impl Into<String>) -> ReldSection

Creates a new ReldSection, and adds a new entry for it in the section header table with the provided name.

Returns the new ReldSection

source

pub fn str_tab_by_name(&self, name: impl AsRef<str>) -> Option<&StringTable>

Gets a reference to the StringTable with the provided name, or None if a StringTable by that name doesn’t exist

source

pub fn str_tab_by_name_mut( &mut self, name: impl AsRef<str> ) -> Option<&mut StringTable>

Gets a mutable reference to the StringTable with the provided name, or None if a StringTable by that name doesn’t exist

source

pub fn sym_tab_by_name(&self, name: impl AsRef<str>) -> Option<&SymbolTable>

Gets a reference to the SymbolTable with the provided name, or None if a SymbolTable by that name doesn’t exist

source

pub fn sym_tab_by_name_mut( &mut self, name: impl AsRef<str> ) -> Option<&mut SymbolTable>

Gets a mutable reference to the SymbolTable with the provided name, or None if a SymbolTable by that name doesn’t exist

source

pub fn data_section_by_name( &self, name: impl AsRef<str> ) -> Option<&DataSection>

Gets a reference to the DataSection with the provided name, or None if a DataSection by that name doesn’t exist

source

pub fn data_section_by_name_mut( &mut self, name: impl AsRef<str> ) -> Option<&mut DataSection>

Gets a mutable reference to the DataSection with the provided name, or None if a DataSection by that name doesn’t exist

source

pub fn func_section_by_name( &self, name: impl AsRef<str> ) -> Option<&FuncSection>

Gets a reference to the FuncSection with the provided name, or None if a FuncSection by that name doesn’t exist

source

pub fn func_section_by_name_mut( &mut self, name: impl AsRef<str> ) -> Option<&mut FuncSection>

Gets a mutable reference to the FuncSection with the provided name, or None if a FuncSection by that name doesn’t exist

source

pub fn reld_section_by_name( &self, name: impl AsRef<str> ) -> Option<&ReldSection>

Gets a reference to the ReldSection with the provided name, or None if a ReldSection by that name doesn’t exist

source

pub fn reld_section_by_name_mut( &mut self, name: impl AsRef<str> ) -> Option<&mut ReldSection>

Gets a mutable reference to the ReldSection with the provided name, or None if a ReldSection by that name doesn’t exist

Trait Implementations§

source§

impl Debug for KOFile

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl Default for KOFile

source§

fn default() -> Self

Returns the “default value” for a type. Read more
source§

impl From<WritableKOFile> for KOFile

source§

fn from(w_kofile: WritableKOFile) -> Self

Converts to this type from the input type.

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.