46 inline const array<uint8_t, 512>&
getData()
const {
108 Console::println(
"UDPPacket::getByte(): position out of range: " + to_string(
position) +
" >= " + to_string(
PACKET_MAX_SIZE));
112 Console::println(
"UDPPacket::getByte(): position out of range: " + to_string(
position) +
" >= " + to_string(
size));
125 Console::println(
"UDPPacket::putByte(): position out of range: " + to_string(
position) +
" >= " + to_string(
PACKET_MAX_SIZE));
140 value+= (uint32_t)
getByte() << 8;
162 value+= (uint32_t)
getByte() << 8;
163 value+= (uint32_t)
getByte() << 16;
164 value+= (uint32_t)
getByte() << 24;
188 value+= (uint64_t)
getByte() << 8;
189 value+= (uint64_t)
getByte() << 16;
190 value+= (uint64_t)
getByte() << 24;
191 value+= (uint64_t)
getByte() << 32;
192 value+= (uint64_t)
getByte() << 40;
193 value+= (uint64_t)
getByte() << 48;
194 value+= (uint64_t)
getByte() << 56;
220 uint32_t floatAsInt =
getInt();
221 return *((
float*)&floatAsInt);
230 uint32_t* floatAsInt = ((uint32_t*)&value);
242 for (
auto i = 0; i < length; i++) value+=
getByte();
252 if (value.size() > 255) {
253 Console::println(
"UDPPacket::putString(): string size out of range: string will be clamped to max length of 255 bytes");
255 putByte(value.size() > 255?255:value.size());
256 for (
auto i = 0; i < value.size() && i < 256; i++) {
269 for (
auto i = 0; i < byteCount; i++) bytes[i] =
getByte();
280 for (
auto i = 0; i < byteCount; i++) bytes[i] =
getByte();
291 for (
auto i = 0; i < byteCount; i++)
putByte(bytes[i]);
const UDPPacket * getBytes(uint8_t *bytes, uint16_t byteCount) const
Get raw bytes from packet.
UDPPacket * putInt64(uint64_t value)
Puts a int64 into packet.
const array< uint8_t, 512 > & getData() const
Get data.
array< uint8_t, 512 > data
UDPPacket * putInt16(uint16_t value)
Puts a int16 into packet.
const UDPPacket * setPosition(uint16_t position) const
Set position.
uint32_t getInt() const
Get a int from packet.
uint16_t getSize() const
Get size of packet.
uint16_t getPosition() const
Get position.
UDPPacket * putByte(uint8_t value)
Puts a byte into packet.
uint32_t getInt64() const
Get a int64 from packet.
UDPPacket * setPosition(uint16_t position)
Set position.
UDPPacket * putBool(bool value)
Puts a bool into packet.
bool getBool() const
Get a bool from packet.
UDPPacket * putFloat(float value)
Puts a float into packet.
UDPPacket()
Public constructor.
static constexpr uint16_t PACKET_MAX_SIZE
UDPPacket * getBytes(uint8_t *bytes, uint16_t byteCount)
Get raw bytes from packet.
UDPPacket * putPacket(const UDPPacket *packet)
Puts another packet into this packet.
uint16_t getInt16() const
Get a int16 from packet.
UDPPacket * putBytes(const uint8_t *bytes, uint16_t byteCount)
Puts raw bytes into packet.
void reset() const
Reset position for read.
float getFloat() const
Get a float from packet.
uint8_t getByte() const
Get a byte from packet.
UDPPacket * putString(const string &value)
Puts a string into packet.
UDPPacket * putInt(uint32_t value)
Puts a int into packet.
string getString() const
Get a string value.