Update to 13.0-beta1

This commit is contained in:
Pavel Stupnikov
2022-11-23 14:30:36 +04:00
parent 269352680c
commit be23283677
504 changed files with 14161 additions and 9678 deletions
+28
View File
@@ -185,6 +185,17 @@ void Packet::Send_string(const std::string_view data)
this->buffer.emplace_back('\0');
}
/**
* Copy a sized byte buffer into the packet.
* @param data The data to send.
*/
void Packet::Send_buffer(const std::vector<byte> &data)
{
assert(this->CanWriteToPacket(sizeof(uint16) + data.size()));
this->Send_uint16((uint16)data.size());
this->buffer.insert(this->buffer.end(), data.begin(), data.end());
}
/**
* Send as many of the bytes as possible in the packet. This can mean
* that it is possible that not all bytes are sent. To cope with this
@@ -366,6 +377,23 @@ uint64 Packet::Recv_uint64()
return n;
}
/**
* Extract a sized byte buffer from the packet.
* @return The extracted buffer.
*/
std::vector<byte> Packet::Recv_buffer()
{
uint16 size = this->Recv_uint16();
if (size == 0 || !this->CanReadFromPacket(size, true)) return {};
std::vector<byte> data;
while (size-- > 0) {
data.push_back(this->buffer[this->pos++]);
}
return data;
}
/**
* Reads characters (bytes) from the packet until it finds a '\0', or reaches a
* maximum of \c length characters.