forked from ruabmbua/enet-sys
-
Notifications
You must be signed in to change notification settings - Fork 0
/
protocol.rs
141 lines (126 loc) · 3.9 KB
/
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
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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
use libc::*;
pub const ENET_PROTOCOL_MINIMUM_MTU: size_t = 576;
pub const ENET_PROTOCOL_MAXIMUM_MTU: size_t = 4096;
pub const ENET_PROTOCOL_MAXIMUM_PACKET_COMMANDS: size_t = 32;
pub const ENET_PROTOCOL_MINIMUM_WINDOW_SIZE: size_t = 4096;
pub const ENET_PROTOCOL_MAXIMUM_WINDOW_SIZE: size_t = 65536;
pub const ENET_PROTOCOL_MINIMUM_CHANNEL_COUNT: size_t = 1;
pub const ENET_PROTOCOL_MAXIMUM_CHANNEL_COUNT: size_t = 255;
pub const ENET_PROTOCOL_MAXIMUM_PEER_ID: size_t = 0xfff;
pub const ENET_PROTOCOL_MAXIMUM_FRAGMENT_COUNT: size_t = 1024 * 1024;
#[repr(C)]
unsafe_unions!{
pub union ENetProtocol: [u8; 48] {
header: ENetProtocolCommandHeader,
acknowledge: ENetProtocolAcknowledge,
connect: ENetProtocolConnect,
verifyConnect: ENetProtocolVerifyConnect,
disconnect: ENetProtocolDisconnect,
ping: ENetProtocolPing,
sendReliable: ENetProtocolSendReliable,
sendUnreliable: ENetProtocolSendUnreliable,
sendUnsequenced: ENetProtocolSendUnsequenced,
sendFragment: ENetProtocolSendFragment,
bandwidthLimit: ENetProtocolBandwidthLimit,
throttleConfigure: ENetProtocolThrottleConfigure,
}
}
#[repr(C)]
pub struct ENetProtocolAcknowledge {
pub header: ENetProtocolCommandHeader,
pub receivedReliableSequenceNumber: uint16_t,
pub receivedSentTime: uint16_t,
}
#[repr(C)]
pub struct ENetProtocolBandwidthLimit {
pub header: ENetProtocolCommandHeader,
pub incomingBandwidth: uint32_t,
pub outgoingBandwidth: uint32_t,
}
#[repr(C)]
pub struct ENetProtocolConnect {
pub header: ENetProtocolCommandHeader,
pub outgoingPeerID: uint16_t,
pub incomingSessionID: uint8_t,
pub outgoingSessionID: uint8_t,
pub mtu: uint32_t,
pub windowSize: uint32_t,
pub channelCount: uint32_t,
pub incomingBandwidth: uint32_t,
pub outgoingBandwidth: uint32_t,
pub packetThrottleInterval: uint32_t,
pub packetThrottleAcceleration: uint32_t,
pub packetThrottleDeceleration: uint32_t,
pub connectID: uint32_t,
pub data: uint32_t,
}
#[repr(C)]
pub struct ENetProtocolDisconnect {
pub header: ENetProtocolCommandHeader,
pub data: uint32_t,
}
#[repr(C)]
pub struct ENetProtocolCommandHeader {
pub command: uint8_t,
pub channelID: uint8_t,
pub reliableSequenceNumber: uint16_t,
}
#[repr(C)]
pub struct ENetProtocolHeader {
pub peerID: uint16_t,
pub sendTime: uint16_t,
}
#[repr(C)]
pub struct ENetProtocolPing {
pub header: ENetProtocolCommandHeader,
}
#[repr(C)]
pub struct ENetProtocolSendFragment {
pub header: ENetProtocolCommandHeader,
pub startSequenceNumber: uint16_t,
pub dataLength: uint16_t,
pub fragmentCount: uint32_t,
pub fragmentNumber: uint32_t,
pub totalLength: uint32_t,
pub fragmentOffset: uint32_t,
}
#[repr(C)]
pub struct ENetProtocolSendReliable {
pub header: ENetProtocolCommandHeader,
pub dataLength: uint16_t,
}
#[repr(C)]
pub struct ENetProtocolSendUnreliable {
pub header: ENetProtocolCommandHeader,
pub unreliableSequenceNumber: uint16_t,
pub dataLength: uint16_t,
}
#[repr(C)]
pub struct ENetProtocolSendUnsequenced {
pub header: ENetProtocolCommandHeader,
pub unsequencedGroup: uint16_t,
pub dataLength: uint16_t,
}
#[repr(C)]
pub struct ENetProtocolThrottleConfigure {
pub header: ENetProtocolCommandHeader,
pub packetThrottleInterval: uint32_t,
pub packetThrottleAcceleration: uint32_t,
pub packetThrottleDeceleration: uint32_t,
}
#[repr(C)]
pub struct ENetProtocolVerifyConnect {
pub header: ENetProtocolCommandHeader,
pub outgoingPeerID: uint16_t,
pub incomingSessionID: uint8_t,
pub outgoingSessionID: uint8_t,
pub mtu: uint32_t,
pub windowSize: uint32_t,
pub channelCount: uint32_t,
pub incomingBandwidth: uint32_t,
pub outgoingBandwidth: uint32_t,
pub packetThrottleInterval: uint32_t,
pub packetThrottleAcceleration: uint32_t,
pub packetThrottleDeceleration: uint32_t,
pub connectID: uint32_t,
}