gear_core/code/
instrumented.rs1use crate::code::Code;
7use alloc::vec::Vec;
8use scale_decode::DecodeAsType;
9use scale_encode::EncodeAsType;
10use scale_info::{
11 TypeInfo,
12 scale::{Decode, Encode},
13};
14
15#[derive(
19 Clone, Debug, PartialEq, Eq, Decode, DecodeAsType, Encode, EncodeAsType, TypeInfo, Hash,
20)]
21pub struct InstantiatedSectionSizes {
22 code_section: u32,
24 data_section: u32,
27 global_section: u32,
29 table_section: u32,
31 element_section: u32,
33 type_section: u32,
35}
36
37impl InstantiatedSectionSizes {
38 pub fn new(
40 code_section: u32,
41 data_section: u32,
42 global_section: u32,
43 table_section: u32,
44 element_section: u32,
45 type_section: u32,
46 ) -> Self {
47 Self {
48 code_section,
49 data_section,
50 global_section,
51 table_section,
52 element_section,
53 type_section,
54 }
55 }
56
57 pub fn code_section(&self) -> u32 {
59 self.code_section
60 }
61
62 pub fn data_section(&self) -> u32 {
64 self.data_section
65 }
66
67 pub fn global_section(&self) -> u32 {
69 self.global_section
70 }
71
72 pub fn table_section(&self) -> u32 {
74 self.table_section
75 }
76
77 pub fn element_section(&self) -> u32 {
79 self.element_section
80 }
81
82 pub fn type_section(&self) -> u32 {
84 self.type_section
85 }
86}
87
88#[derive(
90 Clone, Debug, Decode, DecodeAsType, Encode, EncodeAsType, TypeInfo, PartialEq, Eq, Hash,
91)]
92pub struct InstrumentedCode {
93 bytes: Vec<u8>,
95 instantiated_section_sizes: InstantiatedSectionSizes,
97}
98
99impl InstrumentedCode {
100 pub fn new(bytes: Vec<u8>, instantiated_section_sizes: InstantiatedSectionSizes) -> Self {
102 Self {
103 bytes,
104 instantiated_section_sizes,
105 }
106 }
107
108 pub fn bytes(&self) -> &[u8] {
110 &self.bytes
111 }
112
113 pub fn instantiated_section_sizes(&self) -> &InstantiatedSectionSizes {
115 &self.instantiated_section_sizes
116 }
117
118 pub fn into_bytes(self) -> Vec<u8> {
120 self.bytes
121 }
122}
123
124impl From<Code> for InstrumentedCode {
125 fn from(code: Code) -> Self {
126 code.into_parts().1
127 }
128}