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
impl KOFile
sourcepub fn new() -> Self
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.
sourcepub fn add_section_name(&mut self, name: impl Into<String>) -> StringIdx
pub fn add_section_name(&mut self, name: impl Into<String>) -> StringIdx
Adds a new string to the section header string table
sourcepub fn get_section_name(&self, index: StringIdx) -> Option<&String>
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
sourcepub fn get_section_name_by_index(&self, index: SectionIdx) -> Option<&String>
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
sourcepub fn add_section_header(&mut self, header: SectionHeader) -> SectionIdx
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.
sourcepub fn get_section_header(&self, index: SectionIdx) -> Option<&SectionHeader>
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
sourcepub fn get_header_name(&self, header: &SectionHeader) -> Option<&String>
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
sourcepub fn add_str_tab(&mut self, str_tab: StringTable)
pub fn add_str_tab(&mut self, str_tab: StringTable)
Adds a new string table to this Kerbal Object file
sourcepub fn add_sym_tab(&mut self, sym_tab: SymbolTable)
pub fn add_sym_tab(&mut self, sym_tab: SymbolTable)
Adds a new symbol table to this Kerbal Object file
sourcepub fn add_data_section(&mut self, data_section: DataSection)
pub fn add_data_section(&mut self, data_section: DataSection)
Adds a new data section to this Kerbal Object file
sourcepub fn add_func_section(&mut self, func_section: FuncSection)
pub fn add_func_section(&mut self, func_section: FuncSection)
Adds a new function section to this Kerbal Object file
sourcepub fn add_reld_section(&mut self, reld_section: ReldSection)
pub fn add_reld_section(&mut self, reld_section: ReldSection)
Adds a new relocation data section to this Kerbal Object file
sourcepub fn str_tabs(&self) -> Iter<'_, StringTable>
pub fn str_tabs(&self) -> Iter<'_, StringTable>
Returns an iterator over all of the string tables in this Kerbal Object file
sourcepub fn sym_tabs(&self) -> Iter<'_, SymbolTable>
pub fn sym_tabs(&self) -> Iter<'_, SymbolTable>
Returns an iterator over all of the symbol tables in this Kerbal Object file
sourcepub fn data_sections(&self) -> Iter<'_, DataSection>
pub fn data_sections(&self) -> Iter<'_, DataSection>
Returns an iterator over all of the data sections in this Kerbal Object file
sourcepub fn func_sections(&self) -> Iter<'_, FuncSection>
pub fn func_sections(&self) -> Iter<'_, FuncSection>
Returns an iterator over all of the function sections in this Kerbal Object file
sourcepub fn reld_sections(&self) -> Iter<'_, ReldSection>
pub fn reld_sections(&self) -> Iter<'_, ReldSection>
Returns an iterator over all of the relocation data sections in this Kerbal Object file
sourcepub fn new_section_header(
&mut self,
name: impl Into<String>,
kind: SectionKind
) -> SectionIdx
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
sourcepub fn get_section_index_by_name(
&self,
name: impl AsRef<str>
) -> Option<SectionIdx>
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
sourcepub fn section_headers(&self) -> Iter<'_, SectionHeader>
pub fn section_headers(&self) -> Iter<'_, SectionHeader>
Returns an iterator over all section headers in the Kerbal Object file’s section header table
sourcepub fn section_header_count(&self) -> usize
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.
sourcepub fn shstrtab_index(&self) -> SectionIdx
pub fn shstrtab_index(&self) -> SectionIdx
The index into the section header table of the section header string table
sourcepub fn validate(self) -> Result<WritableKOFile, (Self, ValidationError)>
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
sourcepub fn parse(source: &mut BufferIterator<'_>) -> Result<Self, KOParseError>
pub fn parse(source: &mut BufferIterator<'_>) -> Result<Self, KOParseError>
Parses an entire KOFile from a byte buffer
source§impl KOFile
impl KOFile
sourcepub fn new_strtab(&mut self, name: impl Into<String>) -> StringTable
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
sourcepub fn new_symtab(&mut self, name: impl Into<String>) -> SymbolTable
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
sourcepub fn new_data_section(&mut self, name: impl Into<String>) -> DataSection
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
sourcepub fn new_func_section(&mut self, name: impl Into<String>) -> FuncSection
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
sourcepub fn new_reld_section(&mut self, name: impl Into<String>) -> ReldSection
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
sourcepub fn str_tab_by_name(&self, name: impl AsRef<str>) -> Option<&StringTable>
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
sourcepub fn str_tab_by_name_mut(
&mut self,
name: impl AsRef<str>
) -> Option<&mut StringTable>
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
sourcepub fn sym_tab_by_name(&self, name: impl AsRef<str>) -> Option<&SymbolTable>
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
sourcepub fn sym_tab_by_name_mut(
&mut self,
name: impl AsRef<str>
) -> Option<&mut SymbolTable>
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
sourcepub fn data_section_by_name(
&self,
name: impl AsRef<str>
) -> Option<&DataSection>
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
sourcepub fn data_section_by_name_mut(
&mut self,
name: impl AsRef<str>
) -> Option<&mut DataSection>
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
sourcepub fn func_section_by_name(
&self,
name: impl AsRef<str>
) -> Option<&FuncSection>
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
sourcepub fn func_section_by_name_mut(
&mut self,
name: impl AsRef<str>
) -> Option<&mut FuncSection>
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
sourcepub fn reld_section_by_name(
&self,
name: impl AsRef<str>
) -> Option<&ReldSection>
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
sourcepub fn reld_section_by_name_mut(
&mut self,
name: impl AsRef<str>
) -> Option<&mut ReldSection>
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