summaryrefslogtreecommitdiff
path: root/src/network/packet.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/network/packet.cpp')
-rw-r--r--src/network/packet.cpp38
1 files changed, 38 insertions, 0 deletions
diff --git a/src/network/packet.cpp b/src/network/packet.cpp
index 660e92c0d..cc60f2fbc 100644
--- a/src/network/packet.cpp
+++ b/src/network/packet.cpp
@@ -13,6 +13,18 @@
13 13
14namespace Network { 14namespace Network {
15 15
16#ifndef htonll
17u64 htonll(u64 x) {
18 return ((1 == htonl(1)) ? (x) : ((uint64_t)htonl((x)&0xFFFFFFFF) << 32) | htonl((x) >> 32));
19}
20#endif
21
22#ifndef ntohll
23u64 ntohll(u64 x) {
24 return ((1 == ntohl(1)) ? (x) : ((uint64_t)ntohl((x)&0xFFFFFFFF) << 32) | ntohl((x) >> 32));
25}
26#endif
27
16void Packet::Append(const void* in_data, std::size_t size_in_bytes) { 28void Packet::Append(const void* in_data, std::size_t size_in_bytes) {
17 if (in_data && (size_in_bytes > 0)) { 29 if (in_data && (size_in_bytes > 0)) {
18 std::size_t start = data.size(); 30 std::size_t start = data.size();
@@ -100,6 +112,20 @@ Packet& Packet::operator>>(u32& out_data) {
100 return *this; 112 return *this;
101} 113}
102 114
115Packet& Packet::operator>>(s64& out_data) {
116 s64 value;
117 Read(&value, sizeof(value));
118 out_data = ntohll(value);
119 return *this;
120}
121
122Packet& Packet::operator>>(u64& out_data) {
123 u64 value;
124 Read(&value, sizeof(value));
125 out_data = ntohll(value);
126 return *this;
127}
128
103Packet& Packet::operator>>(float& out_data) { 129Packet& Packet::operator>>(float& out_data) {
104 Read(&out_data, sizeof(out_data)); 130 Read(&out_data, sizeof(out_data));
105 return *this; 131 return *this;
@@ -183,6 +209,18 @@ Packet& Packet::operator<<(u32 in_data) {
183 return *this; 209 return *this;
184} 210}
185 211
212Packet& Packet::operator<<(s64 in_data) {
213 s64 toWrite = htonll(in_data);
214 Append(&toWrite, sizeof(toWrite));
215 return *this;
216}
217
218Packet& Packet::operator<<(u64 in_data) {
219 u64 toWrite = htonll(in_data);
220 Append(&toWrite, sizeof(toWrite));
221 return *this;
222}
223
186Packet& Packet::operator<<(float in_data) { 224Packet& Packet::operator<<(float in_data) {
187 Append(&in_data, sizeof(in_data)); 225 Append(&in_data, sizeof(in_data));
188 return *this; 226 return *this;