use crate::code::Code;
use alloc::vec::Vec;
use scale_decode::DecodeAsType;
use scale_encode::EncodeAsType;
use scale_info::{
TypeInfo,
scale::{Decode, Encode},
};
#[derive(
Clone, Debug, PartialEq, Eq, Decode, DecodeAsType, Encode, EncodeAsType, TypeInfo, Hash,
)]
pub struct InstantiatedSectionSizes {
code_section: u32,
data_section: u32,
global_section: u32,
table_section: u32,
element_section: u32,
type_section: u32,
}
impl InstantiatedSectionSizes {
pub fn new(
code_section: u32,
data_section: u32,
global_section: u32,
table_section: u32,
element_section: u32,
type_section: u32,
) -> Self {
Self {
code_section,
data_section,
global_section,
table_section,
element_section,
type_section,
}
}
pub fn code_section(&self) -> u32 {
self.code_section
}
pub fn data_section(&self) -> u32 {
self.data_section
}
pub fn global_section(&self) -> u32 {
self.global_section
}
pub fn table_section(&self) -> u32 {
self.table_section
}
pub fn element_section(&self) -> u32 {
self.element_section
}
pub fn type_section(&self) -> u32 {
self.type_section
}
}
#[derive(
Clone, Debug, Decode, DecodeAsType, Encode, EncodeAsType, TypeInfo, PartialEq, Eq, Hash,
)]
pub struct InstrumentedCode {
bytes: Vec<u8>,
instantiated_section_sizes: InstantiatedSectionSizes,
}
impl InstrumentedCode {
pub fn new(bytes: Vec<u8>, instantiated_section_sizes: InstantiatedSectionSizes) -> Self {
Self {
bytes,
instantiated_section_sizes,
}
}
pub fn bytes(&self) -> &[u8] {
&self.bytes
}
pub fn instantiated_section_sizes(&self) -> &InstantiatedSectionSizes {
&self.instantiated_section_sizes
}
pub fn into_bytes(self) -> Vec<u8> {
self.bytes
}
}
impl From<Code> for InstrumentedCode {
fn from(code: Code) -> Self {
code.into_parts().1
}
}