|
@@ -3,6 +3,8 @@
|
|
|
#include <arpa/inet.h>
|
|
|
#include <string.h>
|
|
|
|
|
|
+typedef CoreOutPacket OutPacket;
|
|
|
+
|
|
|
void coreInitInPacket(CoreInPacket* in, const void* data, size_t n) {
|
|
|
in->data = data;
|
|
|
in->size = n;
|
|
@@ -103,71 +105,69 @@ bool coreInPacketRead(CoreInPacket* in, void* buffer, size_t n) {
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
-void coreInitOutPacket(CoreOutPacket* out) {
|
|
|
+void coreInitOutPacket(OutPacket* out) {
|
|
|
coreInitBuffer(&out->data);
|
|
|
}
|
|
|
|
|
|
-void coreDestroyOutPacket(CoreOutPacket* out) {
|
|
|
+void coreDestroyOutPacket(OutPacket* out) {
|
|
|
coreDestroyBuffer(&out->data);
|
|
|
}
|
|
|
|
|
|
-CoreOutPacket* coreOutPacketWriteU8(CoreOutPacket* out, u8 u) {
|
|
|
+OutPacket* coreOutPacketWriteU8(OutPacket* out, u8 u) {
|
|
|
coreAddSizedBufferData(&out->data, &u, sizeof(u));
|
|
|
return out;
|
|
|
}
|
|
|
|
|
|
-CoreOutPacket* coreOutPacketWriteU16(CoreOutPacket* out, u16 u) {
|
|
|
+OutPacket* coreOutPacketWriteU16(OutPacket* out, u16 u) {
|
|
|
u = htons(u);
|
|
|
coreAddSizedBufferData(&out->data, &u, sizeof(u));
|
|
|
return out;
|
|
|
}
|
|
|
|
|
|
-CoreOutPacket* coreOutPacketWriteU32(CoreOutPacket* out, u32 u) {
|
|
|
+OutPacket* coreOutPacketWriteU32(OutPacket* out, u32 u) {
|
|
|
u = htonl(u);
|
|
|
coreAddSizedBufferData(&out->data, &u, sizeof(u));
|
|
|
return out;
|
|
|
}
|
|
|
|
|
|
-CoreOutPacket* coreOutPacketWriteI8(CoreOutPacket* out, i8 i) {
|
|
|
+OutPacket* coreOutPacketWriteI8(OutPacket* out, i8 i) {
|
|
|
if(i < 0) {
|
|
|
return coreOutPacketWriteU8(out, (u8)((i32)i + (i32)128));
|
|
|
}
|
|
|
return coreOutPacketWriteU8(out, (u8)((u32)i + (u32)128));
|
|
|
}
|
|
|
|
|
|
-CoreOutPacket* coreOutPacketWriteI16(CoreOutPacket* out, i16 i) {
|
|
|
+OutPacket* coreOutPacketWriteI16(OutPacket* out, i16 i) {
|
|
|
if(i < 0) {
|
|
|
return coreOutPacketWriteU16(out, (u16)((i32)i + (i32)32768));
|
|
|
}
|
|
|
return coreOutPacketWriteU16(out, (u16)((u32)i + (u32)32768));
|
|
|
}
|
|
|
|
|
|
-CoreOutPacket* coreOutPacketWriteI32(CoreOutPacket* out, i32 i) {
|
|
|
+OutPacket* coreOutPacketWriteI32(OutPacket* out, i32 i) {
|
|
|
if(i < 0) {
|
|
|
return coreOutPacketWriteU32(out, (u32)(i + (i32)2147483648));
|
|
|
}
|
|
|
return coreOutPacketWriteU32(out, (u32)((u32)i + (u32)2147483648));
|
|
|
}
|
|
|
|
|
|
-CoreOutPacket* coreOutPacketWriteFloat(CoreOutPacket* out, float f) {
|
|
|
+OutPacket* coreOutPacketWriteFloat(OutPacket* out, float f) {
|
|
|
u32 u;
|
|
|
static_assert(sizeof(u) == sizeof(f), "float and u32 size do not match");
|
|
|
memcpy(&u, &f, sizeof(float));
|
|
|
return coreOutPacketWriteU32(out, u);
|
|
|
}
|
|
|
|
|
|
-CoreOutPacket* coreOutPacketWriteString(CoreOutPacket* out, const char* buffer,
|
|
|
- size_t n) {
|
|
|
+OutPacket* coreOutPacketWriteString(OutPacket* out, const char* s, size_t n) {
|
|
|
size_t end = n > 65535 ? 65535 : n;
|
|
|
coreOutPacketWriteU16(out, (u16)end);
|
|
|
for(size_t i = 0; i < end; i++) {
|
|
|
- coreOutPacketWriteU8(out, (u8)(*(buffer++)));
|
|
|
+ coreOutPacketWriteU8(out, (u8)(*(s++)));
|
|
|
}
|
|
|
return out;
|
|
|
}
|
|
|
|
|
|
-CoreOutPacket* coreOutPacketWrite(CoreOutPacket* out, const void* buffer,
|
|
|
- size_t n) {
|
|
|
+OutPacket* coreOutPacketWrite(OutPacket* out, const void* buffer, size_t n) {
|
|
|
coreAddSizedBufferData(&out->data, buffer, n);
|
|
|
return out;
|
|
|
}
|