-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDatagram.inl
45 lines (44 loc) · 892 Bytes
/
Datagram.inl
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
namespace Tool
{
namespace Network
{
template<typename t> t Datagram::Read(void)
{
t result;
unt i;
if(data.size() >= sizeof(t))
{
for (i = 0; i < sizeof(t); ++i)
{
((w8*)&result)[i] = this->data.front();
this->data.pop();
}
return result;
}
else
throw std::out_of_range("Datagram hasn't");
}
template<typename t> void Datagram::Write(t & value)
{
unt i;
for(i = 0; i < sizeof(value); ++i)
data.push(((w8*)&value)[i]);
}
template<bool> bool Datagram::Read(void)
{
bool result;
if(data.size() >= 1)
{
result = (this->data.front()?true:false);
this->data.pop();
return result;
}
else
throw std::out_of_range("Datagram hasn't any data!");
}
template<bool> void Datagram::Write(bool & value)
{
data.push(value ? 1 : 0);
}
}
}