Class BufferFormatter
Defined in File BufferFormatter.hpp
Class Documentation
-
class BufferFormatter
Public Functions
-
FormatterStatus write(NetworkBuffer *buf, uint8_t status, uint64_t tag, std::span<const iovec> data)
Writes data to the buffer with the specified STATUS, TAG, and DATA.
This is the most general write function, which allows you to specify the status, tag, and data. data is a vector of iovec, which is a struct containing a pointer to the data and the size of the data.
- Parameters:
buf – The pointer to the buffer.
status – The status value.
tag – The tag value, representing the ID of an e-link.
data – The data to be written.
- Returns:
FormatterStatus::MESSAGE_TOO_BIG if the message is too big, FormatterStatus::BUFFER_OK otherwise.
-
FormatterStatus write(NetworkBuffer *buf, uint8_t status, uint64_t tag, std::span<const std::uint8_t> data)
Writes data to the buffer with the specified STATUS, TAG, and DATA.
This is the most general write function, which allows you to specify the status, tag, and data. data is a span of uint8_t, which is a contiguous sequence of bytes.
- Parameters:
buf – The pointer to the buffer.
status – The status value.
tag – The tag value, representing the ID of an e-link.
data – The data to be written.
- Returns:
FormatterStatus::MESSAGE_TOO_BIG if the message is too big, FormatterStatus::BUFFER_OK otherwise.
-
FormatterStatus write(NetworkBuffer *buf, uint64_t tag, std::span<const iovec> data)
Writes data to the buffer with the specified TAG and DATA, status is set to 0.
This is a simplified write function, which allows you to specify the tag and data. data is a vector of iovec, which is a struct containing a pointer to the data and the size of the data.
- Parameters:
buf – The pointer to the buffer.
tag – The tag value, representing the ID of an e-link.
data – The data to be written.
- Returns:
FormatterStatus::MESSAGE_TOO_BIG if the message is too big, FormatterStatus::BUFFER_OK otherwise.
-
FormatterStatus write(NetworkBuffer *buf, uint64_t tag, std::span<const std::uint8_t> data)
Writes data to the buffer with the specified STATUS, TAG, and DATA.
This is a simplified write function, which allows you to specify the tag and data. data is a span of uint8_t, which is a contiguous sequence of bytes.
- Parameters:
buf – The pointer to the buffer.
tag – The tag value, representing the ID of an e-link.
data – The data to be written.
- Returns:
FormatterStatus::MESSAGE_TOO_BIG if the message is too big, FormatterStatus::BUFFER_OK otherwise.
-
void reset_buffer(NetworkBuffer *buf)
Function to be called when the buffer has been sent.
If the buffer is reutilized, it will be added again. The time complexity should remain the same as just updating the tag. Set mark that no tag is present in the buffer.
- Parameters:
buf – The pointer to the buffer.
-
void fill_header(NetworkBuffer *buf, uint8_t status, uint64_t tag, std::size_t payload_size)
Fill the header of the buffer with the specified STATUS, TAG, and MESSAGE_SIZE.
- Parameters:
buf – The pointer to the buffer.
status – The status value.
tag – The tag value, representing the ID of an e-link.
payload_size – The size of the message.
Public Static Functions
-
static void decode(std::span<const std::uint8_t> buf, const std::function<void(std::uint64_t, std::span<const std::uint8_t>, std::uint8_t)> &cb)
Decodes the buffer and calls the callback function for each decoded message.
- Parameters:
buf – The buffer to decode, which is a span of uint8_t.
cb – A callback function that will be called for each decoded message.
Public Static Attributes
-
static constexpr auto HDR_MAX_SIZE = sizeof(uint8_t) + sizeof(uint64_t) + sizeof(uint32_t)
-
static constexpr auto HDR_STATUS_FLAG_POS = unsigned{31}
-
static constexpr auto HDR_TAG_FLAG_POS = unsigned{30}
-
static constexpr auto NUM_BIT_PAYLOAD_SIZE = unsigned{30}
-
static constexpr auto MSG_MAX_SIZE = (1U << NUM_BIT_PAYLOAD_SIZE) - sizeof(uint8_t) - sizeof(uint64_t)
-
FormatterStatus write(NetworkBuffer *buf, uint8_t status, uint64_t tag, std::span<const iovec> data)