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
mod cmd;
pub mod mem;
pub use cmd::ShellCmd;
pub trait Oracle {
type T;
fn as_cmd(&self) -> ShellCmd;
fn from_cmd_output(&self, output: String) -> Option<Self::T>;
}
pub fn encode_cmds(cmds: Vec<ShellCmd>) -> Option<Vec<u8>> {
Some(serde_json::to_string(&cmds).ok()?.into_bytes())
}
pub fn decode_cmds(raw: &[u8]) -> Option<Vec<ShellCmd>> {
serde_json::from_slice(&raw).ok()
}
pub fn encode_outputs(outputs: Vec<String>) -> Option<Vec<u8>> {
Some(serde_json::to_string(&outputs).ok()?.into_bytes())
}
pub fn decode_outputs(raw: &[u8]) -> Option<Vec<String>> {
serde_json::from_slice(&raw).ok()
}
pub fn execute_with_local_env(cmds: Vec<ShellCmd>) -> Vec<String> {
cmds.into_iter().map(|each| each.execute()).collect()
}