| 1 |
use crate::{encode_section, Encode, Section, SectionId}; |
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
#[derive(Clone, Debug, Default)] |
| 24 |
pub struct FunctionSection { |
| 25 |
bytes: Vec<u8>, |
| 26 |
num_added: u32, |
| 27 |
} |
| 28 |
|
| 29 |
impl FunctionSection { |
| 30 |
|
| 31 |
pub fn new() -> Self { |
| 32 |
Self::default() |
| 33 |
} |
| 34 |
|
| 35 |
|
| 36 |
pub fn len(&self) -> u32 { |
| 37 |
self.num_added |
| 38 |
} |
| 39 |
|
| 40 |
|
| 41 |
pub fn is_empty(&self) -> bool { |
| 42 |
self.num_added == 0 |
| 43 |
} |
| 44 |
|
| 45 |
|
| 46 |
pub fn function(&mut self, type_index: u32) -> &mut Self { |
| 47 |
type_index.encode(&mut self.bytes); |
| 48 |
self.num_added += 1; |
| 49 |
self |
| 50 |
} |
| 51 |
} |
| 52 |
|
| 53 |
impl Encode for FunctionSection { |
| 54 |
fn encode(&self, sink: &mut Vec<u8>) { |
| 55 |
encode_section(sink, self.num_added, &self.bytes); |
| 56 |
} |
| 57 |
} |
| 58 |
|
| 59 |
impl Section for FunctionSection { |
| 60 |
fn id(&self) -> u8 { |
| 61 |
SectionId::Function.into() |
| 62 |
} |
| 63 |
} |