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
use crate::graph::middleware::dot::Dot;

/**
 * Struct for the message sent over the network.
 */
#[derive(Serialize, Deserialize, Debug, Clone)]
pub struct Message {
    ///Message dot
    pub dot: Dot,
    ///Message payload
    pub payload: Vec<u8>,
    ///Message context
    pub context: Vec<Dot>,
}

impl Message {
    /**
     * Creates an empty message.
     */
    pub fn empty() -> Self {
        Self {
            dot: Dot::new(0, 0),
            payload: Vec::new(),
            context: Vec::new(),
        }
    }

    /**
     * Creates a message with payload, dot and context.
     */
    pub fn new(payload: Vec<u8>, dot: Dot, context: Vec<Dot>) -> Self {
        Self {
            payload,
            dot,
            context,
        }
    }
}