Struct kerbalobjects::ksm::sections::CodeSection
source · pub struct CodeSection {
pub section_type: CodeType,
/* private fields */
}
Expand description
A code section within a KSM file.
A KSM file can have as many of these as required, as each one can represent a user-defined function, or other types of code.
There should be a minimum of three of them in each KSM file in order for it to be properly loaded into kOS.
All of the function code sections should come first, followed by a required, but possibly empty Initialization section, followed by a required, but possibly empty Main section.
Fields§
§section_type: CodeType
The type of code section that this is
Implementations§
source§impl CodeSection
impl CodeSection
sourcepub fn with_instructions(self, iter: impl IntoIterator<Item = Instr>) -> Self
pub fn with_instructions(self, iter: impl IntoIterator<Item = Instr>) -> Self
A builder-style method that takes in an iterator of instructions that should be added to this CodeSection
sourcepub fn instructions(&self) -> Iter<'_, Instr>
pub fn instructions(&self) -> Iter<'_, Instr>
Returns an iterator over all of the instructions in this code section
sourcepub fn size_bytes(&self, index_bytes: IntSize) -> usize
pub fn size_bytes(&self, index_bytes: IntSize) -> usize
Returns how large this section will be if it is written with the provided number of argument index bytes
sourcepub fn write(&self, buf: &mut Vec<u8>, index_bytes: IntSize)
pub fn write(&self, buf: &mut Vec<u8>, index_bytes: IntSize)
Converts this code section into bytes and appends it to the provided buffer.
This requires the number of bytes required to index into the argument section so that instruction operands can be written using the correct byte width.
sourcepub fn parse(
source: &mut BufferIterator<'_>,
index_bytes: IntSize
) -> Result<Self, CodeSectionParseError>
pub fn parse( source: &mut BufferIterator<'_>, index_bytes: IntSize ) -> Result<Self, CodeSectionParseError>
Parses a code section from bytes.
This requires the number of bytes required to index into the argument section so that instruction operands can be read using the correct byte width.
Trait Implementations§
source§impl Clone for CodeSection
impl Clone for CodeSection
source§fn clone(&self) -> CodeSection
fn clone(&self) -> CodeSection
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read more