18using std::stringstream;
26UDPClientMessage* UDPClientMessage::parse(
const char message[512],
const size_t bytes) {
31 messageType = MessageType::MESSAGETYPE_ACKNOWLEDGEMENT;
40 Console::println(
"UDPClientMessage::parse(): invalid message type: '" + (
string() + message[0]) +
"' (" + to_string(message[0]) +
")");
46 Integer::decode(
string(&message[1], 6),
clientId);
47 Integer::decode(
string(&message[7], 6),
messageId);
48 Integer::decode(
string(&message[13], 1),
retries);
50 stringstream*
frame =
nullptr;
52 frame =
new stringstream();
53 frame->write(&message[14], bytes - 14);
59 messageType(messageType),
65 time = Time::getCurrentMillis();
120 string retriesEncoded;
121 string clientIdEncoded;
122 string messageIdEncoded;
123 Integer::encode(
retries, retriesEncoded);
124 Integer::encode(
clientId, clientIdEncoded);
125 Integer::encode(
messageId, messageIdEncoded);
126 datagram+= clientIdEncoded;
127 datagram+= messageIdEncoded;
128 datagram+= retriesEncoded[retriesEncoded.length()];
129 if (
frame !=
nullptr) {
130 datagram+=
frame->str();
132 bytes = datagram.size();
133 memcpy(message, datagram.c_str(), bytes);
const uint32_t getMessageId()
void generate(char message[512], size_t &bytes)
Generate datagram.
void retry()
Mark message to be resend with increased retry count.
~UDPClientMessage()
Destructor.
const uint8_t getRetryCount()
const uint32_t getClientId()
stringstream * getFrame()
@ MESSAGETYPE_ACKNOWLEDGEMENT
UDPClientMessage(const MessageType messageType, const uint32_t clientId, const uint32_t messageId, const uint8_t retries, stringstream *frame)
Public constructor.
const MessageType getMessageType()
const int64_t getRetryTime()
static uint64_t getRetryTime(const uint8_t retries)
Get retry time for given retry count.