1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
mod decode;
mod encode;
use self::decode::{Decode, DecodeContext};
use self::encode::{Encode, EncodeContext};
use crate::ast::WebidlBindings;
use std::io;
pub fn encode<W>(
section: &WebidlBindings,
indices: &walrus::IdsToIndices,
into: &mut W,
) -> io::Result<()>
where
W: io::Write,
{
let cx = &mut EncodeContext::new(indices);
section.encode(cx, into)
}
pub fn decode(ids: &walrus::IndicesToIds, from: &[u8]) -> Result<WebidlBindings, failure::Error> {
let mut cx = DecodeContext::new(ids);
let mut from = from;
WebidlBindings::decode(&mut cx, &mut from)?;
Ok(cx.webidl_bindings)
}
pub fn on_parse(
module: &mut walrus::Module,
ids: &walrus::IndicesToIds,
) -> Result<(), failure::Error> {
let section = match module.customs.remove_raw("webidl-bindings") {
Some(s) => s,
None => return Ok(()),
};
let bindings = decode(ids, §ion.data)?;
module.customs.add(bindings);
Ok(())
}