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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
use std::fmt;
use serde_derive::{Deserialize, Serialize};
use crate::param::Param;
/// A Command sent by the debug_client to the debugger
#[derive(Serialize, Deserialize)]
pub enum DebugCommand {
/// Acknowledge event processed correctly
Ack,
/// Set a `breakpoint` - with an optional parameter
Breakpoint(Option<Param>),
/// `continue` execution of the flow
Continue,
/// Debug client is starting
DebugClientStarting,
/// `delete` an existing breakpoint - with an optional parameter
Delete(Option<Param>),
/// An error on the client side
Error(String),
/// `exit` the debugger and runtime
ExitDebugger,
/// List of all functions
FunctionList,
/// `inspect` a function
InspectFunction(usize),
/// Inspect overall state
Inspect,
/// Inspect an Input (function_id, input_number)
InspectInput(usize, usize),
/// Inspect an Output (function_id, sub-path)
InspectOutput(usize, String),
/// Inspect a Block (optional source function_id, optional destination function_id)
InspectBlock(Option<usize>, Option<usize>),
/// Invalid - used when deserialization goes wrong
Invalid,
/// `list` existing breakpoints
List,
/// `reset` flow execution back to the initial state
RunReset,
/// `step` forward in flow execution by executing one (default) or more `Jobs`
Step(Option<Param>),
/// `validate` the current state
Validate,
}
impl fmt::Display for DebugCommand {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(
f,
"DebugCommand {}",
match self {
DebugCommand::Ack => "Ack",
DebugCommand::Breakpoint(_) => "Breakpoint",
DebugCommand::Continue => "Continue",
DebugCommand::Delete(_) => "Delete",
DebugCommand::Error(_) => "Error",
DebugCommand::ExitDebugger => "ExitDebugger",
DebugCommand::FunctionList => "FunctionList",
DebugCommand::InspectFunction(_) => "InspectFunction",
DebugCommand::Inspect => "Inspect",
DebugCommand::InspectInput(_, _) => "InspectInput",
DebugCommand::InspectOutput(_, _) => "InspectOutput",
DebugCommand::InspectBlock(_, _) => "InspectBlock",
DebugCommand::Invalid => "Invalid",
DebugCommand::List => "List",
DebugCommand::RunReset => "RunReset",
DebugCommand::Step(_) => "Step",
DebugCommand::Validate => "Validate",
DebugCommand::DebugClientStarting => "DebugClientStarting",
}
)
}
}
impl From<DebugCommand> for String {
fn from(msg: DebugCommand) -> Self {
match serde_json::to_string(&msg) {
Ok(message_string) => message_string,
_ => String::new(),
}
}
}
impl From<String> for DebugCommand {
fn from(msg: String) -> Self {
match serde_json::from_str(&msg) {
Ok(message) => message,
_ => DebugCommand::Invalid,
}
}
}