forevervm_sdk/api/
protocol.rs

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
//! Types for the WebSocket protocol.

use super::{
    api_types::{ApiExecResultResponse, Instruction},
    id_types::{InstructionSeq, MachineName, MachineOutputSeq, RequestSeq},
    ApiErrorResponse,
};
use serde::{Deserialize, Serialize};

#[derive(Debug, Serialize, Deserialize)]
#[serde(tag = "type", rename_all = "snake_case")]
pub enum MessageToServer {
    Exec {
        instruction: Instruction,
        request_id: RequestSeq,
    },
}

#[derive(Debug, Serialize, Deserialize, Clone, Copy)]
#[serde(rename_all = "snake_case")]
pub enum MessageLevel {
    Info,
    Warn,
    Error,
}

#[derive(Debug, Serialize, Deserialize)]
#[serde(tag = "type", rename_all = "snake_case")]
pub enum MessageFromServer {
    Connected {
        machine_name: MachineName,
    },

    ExecReceived {
        seq: InstructionSeq,
        request_id: RequestSeq,
    },

    Result(ApiExecResultResponse),

    Output {
        chunk: StandardOutput,
        instruction_id: InstructionSeq,
    },

    Error(ApiErrorResponse),

    /// Use to send log / diagnostic messages to the client.
    Message {
        message: String,
        level: MessageLevel,
    },
}

#[derive(Serialize, Deserialize, Debug, Clone, PartialEq)]
pub enum StandardOutputStream {
    #[serde(rename = "stdout")]
    Stdout,
    #[serde(rename = "stderr")]
    Stderr,
}

#[derive(Serialize, Deserialize, Debug, Clone, PartialEq)]
pub struct StandardOutput {
    pub stream: StandardOutputStream,
    pub data: String,
    pub seq: MachineOutputSeq,
}