Commit f34f51f3 authored by Millian Poquet's avatar Millian Poquet
Browse files

code: do not store messages on stack

This is to prevent stack overflows if messages are big.
Partial revert of 0c6d1256
parent 6963b757
Pipeline #443077 failed with stages
in 1 minute and 1 second
......@@ -23,13 +23,14 @@ void write_message(const Message & message, rsg::TcpSocket & socket)
// Generate message buffer (header + content).
const uint32_t content_size = message.ByteSizeLong();
const uint32_t message_size = content_size + 4;
uint8_t message_content[message_size];
auto message_content = new uint8_t[message_size]();
memcpy(message_content, &content_size, 4); // TODO: set endianness
bool serialize_ok = message.SerializeToArray(message_content + 4, content_size);
RSG_ENFORCE(serialize_ok, "Could not serialize Protobuf message");
// Send message on socket.
socket.send_all(message_content, message_size);
delete[] message_content;
}
template <typename Message>
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment