Add network packet binary send/recv methods

desync-debugging
Jonathan G Rennison 4 years ago
parent 9b74b979c8
commit 227ac91741

@ -153,6 +153,18 @@ void Packet::Send_string(const char *data)
while ((this->buffer[this->size++] = *data++) != '\0') {}
}
/**
* Sends a binary data over the network.
* @param data The data to send
*/
void Packet::Send_binary(const char *data, const size_t size)
{
assert(data != nullptr);
assert(this->size + size <= SEND_MTU);
memcpy(&this->buffer[this->size], data, size);
this->size += (PacketSize) size;
}
/*
* Receiving commands
@ -306,3 +318,16 @@ void Packet::Recv_string(char *buffer, size_t size, StringValidationSettings set
str_validate(bufp, last, settings);
}
/**
* Reads binary data.
* @param buffer The buffer to put the data into.
* @param size The size of the buffer.
*/
void Packet::Recv_binary(char *buffer, size_t size)
{
if (!this->CanReadFromPacket(size)) return;
memcpy(buffer, &this->buffer[this->pos], size);
this->pos += (PacketSize) size;
}

@ -69,6 +69,7 @@ public:
void Send_uint32(uint32 data);
void Send_uint64(uint64 data);
void Send_string(const char *data);
void Send_binary(const char *data, const size_t size);
/* Reading/receiving of packets */
void ReadRawPacketSize();
@ -81,6 +82,7 @@ public:
uint32 Recv_uint32();
uint64 Recv_uint64();
void Recv_string(char *buffer, size_t size, StringValidationSettings settings = SVS_REPLACE_WITH_QUESTION_MARK);
void Recv_binary(char *buffer, size_t size);
};
#endif /* NETWORK_CORE_PACKET_H */

Loading…
Cancel
Save