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
crate::ix!();

pub trait Complete {

    /**
      | returns true if the current deserialization
      | is complete
      |
      */
    fn complete(&self) -> bool;
}

pub trait SetVersion {

    /**
      | set the serialization context version
      |
      */
    fn set_version(&mut self, version: i32);
}

pub trait ReadData {

    /**
      | read and deserialize data, advances
      | msg_bytes data pointer
      |
      */
    fn read(&mut self, msg_bytes: &mut [u8]) -> i32;
}

pub trait GetMessage {

    /**
      | decomposes a message from the context
      |
      */
    fn get_message(&mut self, 
            time:    Instant /* microseconds */,
            out_err: &mut u32) -> Option<NetMessage>;

}

/**
  | The TransportDeserializer takes care
  | of holding and deserializing the network
  | receive buffer. It can deserialize
  | the network buffer into a transport
  | protocol agnostic CNetMessage (command
  | & payload)
  |
  */
pub trait TransportDeserializer: 
Complete 
+ SetVersion 
+ ReadData 
+ GetMessage { }

/**
  | The TransportSerializer prepares
  | messages for the network transport
  |
  */
pub trait TransportSerializer: PrepareForTransport { }

pub trait PrepareForTransport {

    /**
      | prepare message for transport (header
      | construction, error-correction computation,
      | payload encryption, etc.)
      |
      */
    fn prepare_for_transport(&mut self, 
            msg:    &mut SerializedNetMsg,
            header: &mut Vec<u8>);

}