mirror of
https://github.com/luanti-org/luanti.git
synced 2025-10-05 19:31:04 +00:00
Clean up some packet-related code
This commit is contained in:
parent
5e89371ecd
commit
ee9258cefd
11 changed files with 94 additions and 239 deletions
|
@ -35,12 +35,16 @@ public:
|
|||
session_t getPeerId() const { return m_peer_id; }
|
||||
u16 getCommand() const { return m_command; }
|
||||
u32 getRemainingBytes() const { return m_datasize - m_read_offset; }
|
||||
const char *getRemainingString() { return getString(m_read_offset); }
|
||||
|
||||
// Returns a c-string without copying.
|
||||
// Returns a pointer to buffer data.
|
||||
// A better name for this would be getRawString()
|
||||
const char *getString(u32 from_offset) const;
|
||||
// major difference to putCString(): doesn't write len into the buffer
|
||||
const char *getRemainingString() const { return getString(m_read_offset); }
|
||||
|
||||
// Perform length check and skip ahead by `count` bytes.
|
||||
void skip(u32 count);
|
||||
|
||||
// Appends bytes from string buffer to packet
|
||||
void putRawString(const char *src, u32 len);
|
||||
void putRawString(std::string_view src)
|
||||
{
|
||||
|
@ -63,14 +67,9 @@ public:
|
|||
NetworkPacket &operator>>(bool &dst);
|
||||
NetworkPacket &operator<<(bool src);
|
||||
|
||||
u8 getU8(u32 offset);
|
||||
|
||||
NetworkPacket &operator>>(u8 &dst);
|
||||
NetworkPacket &operator<<(u8 src);
|
||||
|
||||
u8 *getU8Ptr(u32 offset);
|
||||
|
||||
u16 getU16(u32 from_offset);
|
||||
NetworkPacket &operator>>(u16 &dst);
|
||||
NetworkPacket &operator<<(u16 src);
|
||||
|
||||
|
@ -114,6 +113,7 @@ public:
|
|||
private:
|
||||
void checkReadOffset(u32 from_offset, u32 field_size) const;
|
||||
|
||||
// resize data buffer for writing
|
||||
inline void checkDataSize(u32 field_size)
|
||||
{
|
||||
if (m_read_offset + field_size > m_datasize) {
|
||||
|
@ -124,7 +124,7 @@ private:
|
|||
|
||||
std::vector<u8> m_data;
|
||||
u32 m_datasize = 0;
|
||||
u32 m_read_offset = 0;
|
||||
u32 m_read_offset = 0; // read and write offset
|
||||
u16 m_command = 0;
|
||||
session_t m_peer_id = 0;
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue