use crate::{Encode, Section, SectionId, encode_section};
use alloc::vec::Vec;
#[derive(Clone, Debug, Default)]
pub struct FunctionSection {
bytes: Vec<u8>,
num_added: u32,
}
impl FunctionSection {
pub fn new() -> Self {
Self::default()
}
pub fn len(&self) -> u32 {
self.num_added
}
pub fn is_empty(&self) -> bool {
self.num_added == 0
}
pub fn function(&mut self, type_index: u32) -> &mut Self {
type_index.encode(&mut self.bytes);
self.num_added += 1;
self
}
}
impl Encode for FunctionSection {
fn encode(&self, sink: &mut Vec<u8>) {
encode_section(sink, self.num_added, &self.bytes);
}
}
impl Section for FunctionSection {
fn id(&self) -> u8 {
SectionId::Function.into()
}
}