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
use std::fmt;
use flowcore::errors::Result;
use flowcore::model::submission::Submission;
use serde_derive::{Deserialize, Serialize};
/// A Message from the a client to the Coordinator
#[derive(Serialize, Deserialize, Debug, Clone)]
pub enum ClientMessage {
/// ** These messages are used to implement the `SubmissionProtocol` between the Coordinator
/// and the client
/// A submission from the client for execution
ClientSubmission(Box<Submission>),
/// Client requests that server enters the ddebugger at the next opportunity
EnterDebugger,
/// ** These messages are used to implement the context functions between the `cli_runtime_client`
/// and the `cli_runtime_server` that runs as part of the `Coordinator`
/// Simple acknowledgement from Client to a `ServerMessage`
Ack,
/// A String read from Stdin on Client, sent to the Server
Stdin(String),
/// A line of text read from Stdin using readline from Stdin on Client, sent to the Server
Line(String),
/// A Vector of Strings that are the flow's arguments from Client, sent to the Server
Args(Vec<String>),
/// An Error occurred in the `runtime_client`
Error(String),
/// EOF was detected on input reading using Stdin
GetStdinEof,
/// EOF was detected on input reading Stdin using Readline
GetLineEof,
/// Invalid - used when deserialization goes wrong
Invalid,
/// Contents read from a file
FileContents(String, Vec<u8>),
/// ** This message is just internal to the client and not sent to the Coordinator
/// Client is exiting Event loop
ClientExiting(Result<()>),
}
impl fmt::Display for ClientMessage {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(
f,
"{}",
match self {
ClientMessage::Ack => "Ack",
ClientMessage::Stdin(_) => "Stdin",
ClientMessage::Line(_) => "Line",
ClientMessage::Args(_) => "Args",
ClientMessage::Error(_) => "Error",
ClientMessage::GetStdinEof => "GetStdinEof",
ClientMessage::GetLineEof => "GetLineEof",
ClientMessage::ClientExiting(_) => "ClientExiting",
ClientMessage::ClientSubmission(_) => "ClientSubmission",
ClientMessage::EnterDebugger => "EnterDebugger",
ClientMessage::Invalid => "Invalid",
ClientMessage::FileContents(_, _) => "FileContents",
}
)
}
}
impl From<ClientMessage> for String {
fn from(msg: ClientMessage) -> Self {
serde_json::to_string(&msg).unwrap_or_default()
}
}
impl From<String> for ClientMessage {
fn from(string: String) -> Self {
match serde_json::from_str(&string) {
Ok(message) => message,
_ => ClientMessage::Invalid,
}
}
}