roblox_rs_shared_context/
lib.rs

1//! This module is responsible for sharing information between the roblox-rs-macro-expansion and roblox-rs-cli.
2
3use std::io::Cursor;
4
5use shared_context::SharedContext;
6
7pub mod shared_context;
8
9pub fn encode(context: &SharedContext) -> Vec<u8> {
10    bincode::serialize(context).expect("failed to serialize shared context")
11}
12
13pub fn decode(content: &[u8]) -> SharedContext {
14    let mut cursor = Cursor::new(content);
15    let mut context = SharedContext::default();
16
17    while let Ok(value) = bincode::deserialize_from::<_, SharedContext>(&mut cursor) {
18        context.imports.extend(value.imports);
19        context.exports.extend(value.exports);
20    }
21
22    context
23}