wasm_encoder/core/
tags.rs1use crate::{Encode, Section, SectionId, encode_section};
2use alloc::vec::Vec;
3
4#[derive(Clone, Default, Debug)]
23pub struct TagSection {
24 bytes: Vec<u8>,
25 num_added: u32,
26}
27
28impl TagSection {
29 pub fn new() -> Self {
31 Self::default()
32 }
33
34 pub fn len(&self) -> u32 {
36 self.num_added
37 }
38
39 pub fn is_empty(&self) -> bool {
41 self.num_added == 0
42 }
43
44 pub fn tag(&mut self, tag_type: TagType) -> &mut Self {
46 tag_type.encode(&mut self.bytes);
47 self.num_added += 1;
48 self
49 }
50}
51
52impl Encode for TagSection {
53 fn encode(&self, sink: &mut Vec<u8>) {
54 encode_section(sink, self.num_added, &self.bytes);
55 }
56}
57
58impl Section for TagSection {
59 fn id(&self) -> u8 {
60 SectionId::Tag.into()
61 }
62}
63
64#[repr(u8)]
66#[derive(Clone, Copy, Debug, PartialEq, Eq)]
67pub enum TagKind {
68 Exception = 0x0,
70}
71
72#[derive(Clone, Copy, Debug, PartialEq, Eq)]
74pub struct TagType {
75 pub kind: TagKind,
77 pub func_type_idx: u32,
79}
80
81impl Encode for TagType {
82 fn encode(&self, sink: &mut Vec<u8>) {
83 sink.push(self.kind as u8);
84 self.func_type_idx.encode(sink);
85 }
86}