64 Packet(
size_t initial_size);
84 while((
size_t)(pointer - data) > (data_size -
sizeof(be_v))){
87 memcpy(pointer, &be_v,
sizeof(be_v));
88 pointer +=
sizeof(be_v);
89 used_size = std::max(used_size, (
size_t)(pointer - data));
107 if((
size_t)(pointer - data) <= (used_size -
sizeof(be_v))){
108 memcpy(&be_v, pointer,
sizeof(be_v));
109 pointer +=
sizeof(be_v);
131 size_t size()
const {
return used_size; }
134 size_t remaining()
const {
return used_size - (pointer - data); }
143 uint8_t *data, *pointer;
144 size_t data_size, used_size;
153 #ifdef NRG_ENABLE_ZLIB_COMPRESSION
Packet & seek(off_t offset, int whence)
Seeks the packet to some offset using SEEK_SET, SEEK_CUR or SEEK_END.
Contains several definitions that can be used to configure the library at compile time...
virtual PacketReadable & read32(uint32_t &v)=0
Read a uint32_t, automatically converting endianness.
virtual PacketReadable & read64(uint64_t &v)=0
Read a uint64_t, automatically converting endianness.
virtual ~PacketWritable()
Standard Destructor.
Definition: nrg_packet.h:54
Packet()
Default Constructor.
void writeBE(const T &be_v)
Generic write function without endian conversion, be careful with types like size_t that differ acros...
Definition: nrg_packet.h:83
virtual PacketWritable & write16(const uint16_t &v)=0
Write a uint16_t, automatically converting endianness.
virtual PacketWritable & write32(const uint32_t &v)=0
Write a uint32_t, automatically converting endianness.
size_t remaining() const
Get the amount of data that can be read from the internal pointer's current position.
Definition: nrg_packet.h:134
Class for storing data to be sent / received across the network.
Definition: nrg_packet.h:58
virtual PacketReadable & readArray(uint8_t *v, size_t size)=0
Read an array of size size into v, make sure it's big enough!
virtual PacketWritable & write8(const uint8_t &v)=0
Write a uint8_t, automatically converting endianness.
void read(T &v)
Generic read function with endian conversion, be careful with types like size_t that differ across pl...
Definition: nrg_packet.h:115
PacketWritable & write16(const uint16_t &v)
Write a uint16_t, automatically converting endianness.
PacketWritable & write8(const uint8_t &v)
Write a uint8_t, automatically converting endianness.
Contains the NetAddress class for wrapping POSIX sockaddr structures and resolving hostnames to IP ad...
const uint8_t * getPointer() const
Returns the internal pointer.
Definition: nrg_packet.h:137
PacketReadable & read64(uint64_t &v)
Read a uint64_t, automatically converting endianness.
PacketReadable & read16(uint16_t &v)
Read a uint16_t, automatically converting endianness.
virtual ~PacketReadable()
Standard Destructor.
Definition: nrg_packet.h:44
PacketReadable & readArray(uint8_t *v, size_t size)
Read an array of size size into v, make sure it's big enough!
PacketReadable & read32(uint32_t &v)
Read a uint32_t, automatically converting endianness.
virtual PacketReadable & read8(uint8_t &v)=0
Read a uint8_t, automatically converting endianness.
virtual PacketReadable & read16(uint16_t &v)=0
Read a uint16_t, automatically converting endianness.
virtual Packet & reset()
Clears all data in the Packet.
off_t tell() const
Get the current offset of this Packet's internal pointer.
virtual PacketWritable & writeArray(const void *v, size_t size)=0
Write an array of size size, no endian conversion is performed.
Interface for Packet's reading functions.
Definition: nrg_packet.h:38
PacketWritable & write32(const uint32_t &v)
Write a uint32_t, automatically converting endianness.
size_t size() const
Get the total used-size of this packet.
Definition: nrg_packet.h:131
const uint8_t * getBasePointer() const
Returns the base address of the packet's data without affecting the internal pointer.
Definition: nrg_packet.h:140
virtual PacketWritable & write64(const uint64_t &v)=0
Write a uint64_t, automatically converting endianness.
void readBE(T &be_v)
Generic read function without endian conversion, be careful with types like size_t that differ across...
Definition: nrg_packet.h:106
Defines functions for converting between big and little endian byte orders.
PacketWritable & write64(const uint64_t &v)
Write a uint64_t, automatically converting endianness.
virtual ~Packet()
Standard Destructor.
Packet & operator=(const Packet &other)
Assignment operator.
PacketWritable & writeArray(const void *v, size_t size)
Write an array of size size, no endian conversion is performed.
Common defines and includes used by all the other nrg header files.
void write(const T &v)
Generic write function with endian conversion, be careful with types like size_t that differ across p...
Definition: nrg_packet.h:94
PacketReadable & read8(uint8_t &v)
Read a uint8_t, automatically converting endianness.
Interface for Packet's writing functions.
Definition: nrg_packet.h:48