Generic message buffer formatting class.
More...
#include <message.h>
|
| | Message (std::shared_ptr< std::vector< std::uint8_t >> buffer=std::make_shared< std::vector< std::uint8_t >>()) |
| |
| constexpr bool | HasPrependedLength () const noexcept |
| | Checks if the message was built with the payload length written near the front. More...
|
| |
| template<typename T > |
| requires std::is_enum_v< T > std::is_integral_v< T > Message & | PrependType (T type) |
| | Prepends a message type at the front of the byte buffer. More...
|
| |
| Message & | ReserveLength () |
| | Inserts a std::uint16_t near the front of the byte buffer for the payload length. More...
|
| |
| Message & | Append (std::uint8_t byte) noexcept |
| |
| Message & | Append (std::span< const std::uint8_t > bytes) noexcept |
| |
| template<typename T > |
| requires | requires (std::vector< std::uint8_t > &buffer, const T &value) |
| |
| Message & | Append (const T &value) noexcept(noexcept(*_bytes<< value)) |
| |
| const std::shared_ptr< std::vector< uint8_t > > & | ToBytes () const noexcept |
| |
| std::span< const std::uint8_t > | ToByteSpan () const noexcept |
| |
| void | Clear () noexcept |
| | Removes all bytes and any reserved-length state; shared storage remains owned. More...
|
| |
|
| template<typename Field > |
| static Field | ParseField (std::span< const std::uint8_t > &buffer) |
| |
| template<typename Field > |
| static std::optional< Field > | ParseOptionalField (std::span< const std::uint8_t > &buffer) |
| |
Generic message buffer formatting class.
Generic message type that formats a message into a byte buffer in a declarative manner. The intent is to call it via the Builder Pattern methods in a way that lays out the format of message obviously.
◆ Message()
| quicr::messages::Message::Message |
( |
std::shared_ptr< std::vector< std::uint8_t >> |
buffer = std::make_shared<std::vector<std::uint8_t>>() | ) |
|
|
inline |
Creates a builder over shared mutable byte storage.
- Parameters
-
| buffer | Storage to mutate. The builder retains shared ownership. |
- Exceptions
-
| std::invalid_argument | if buffer is null. |
◆ Append() [1/3]
| Message& quicr::messages::Message::Append |
( |
const T & |
value | ) |
|
|
inlinenoexcept |
◆ Append() [2/3]
| Message& quicr::messages::Message::Append |
( |
std::span< const std::uint8_t > |
bytes | ) |
|
|
inlinenoexcept |
Appends a non-owning byte range by copying it into the message.
- Parameters
-
| bytes | Bytes to copy; the span need only remain valid for this call. |
- Returns
- This builder.
◆ Append() [3/3]
| Message& quicr::messages::Message::Append |
( |
std::uint8_t |
byte | ) |
|
|
inlinenoexcept |
Appends one raw byte.
- Parameters
-
| byte | Byte to append without additional encoding. |
- Returns
- This builder.
◆ Clear()
| void quicr::messages::Message::Clear |
( |
| ) |
|
|
inlinenoexcept |
Removes all bytes and any reserved-length state; shared storage remains owned.
◆ HasPrependedLength()
| constexpr bool quicr::messages::Message::HasPrependedLength |
( |
| ) |
const |
|
inlineconstexprnoexcept |
Checks if the message was built with the payload length written near the front.
- Returns
- True if the message has space reserved for the payload size near the front, false otherwise.
◆ ParseField()
template<typename Field >
| static Field quicr::messages::Message::ParseField |
( |
std::span< const std::uint8_t > & |
buffer | ) |
|
|
inlinestatic |
Parses one field and advances the caller's span past consumed bytes.
- Template Parameters
-
| Field | Default-constructible type supporting BytesSpan >> Field. |
- Parameters
-
| buffer | Mutable span view; replaced with its unconsumed suffix. |
- Returns
- Parsed field value.
- Exceptions
-
| std::exception | Any exception raised by the field decoder. |
◆ ParseOptionalField()
template<typename Field >
| static std::optional<Field> quicr::messages::Message::ParseOptionalField |
( |
std::span< const std::uint8_t > & |
buffer | ) |
|
|
inlinestatic |
◆ PrependType()
template<typename T >
| requires std::is_enum_v<T> std::is_integral_v<T> Message& quicr::messages::Message::PrependType |
( |
T |
type | ) |
|
|
inline |
Prepends a message type at the front of the byte buffer.
- Template Parameters
-
| T | The enumeration/integral type of the message type. |
- Parameters
-
| type | The type of message to be written at the front of the buffer. |
- Returns
- A reference to the message currently being built.
- Note
- When building a message, this should be the first method called.
◆ requires()
template<typename T >
| requires quicr::messages::Message::requires |
( |
std::vector< std::uint8_t > & |
buffer, |
|
|
const T & |
value |
|
) |
| |
|
inline |
Appends a value using its byte-stream insertion operator.
- Template Parameters
-
| T | Serializable value type. |
- Parameters
-
- Returns
- This builder.
◆ ReserveLength()
| Message& quicr::messages::Message::ReserveLength |
( |
| ) |
|
|
inline |
Inserts a std::uint16_t near the front of the byte buffer for the payload length.
- Returns
- A reference to the message currently being built.
◆ ToBytes()
| const std::shared_ptr<std::vector<uint8_t> >& quicr::messages::Message::ToBytes |
( |
| ) |
const |
|
inlinenoexcept |
Finalizes the reserved two-byte big-endian payload length, if any.
The returned reference exposes the same shared mutable storage passed to the constructor. Payload lengths larger than 65535 are truncated to 16 bits by the current implementation.
- Returns
- Reference to the builder's shared byte-vector handle.
◆ ToByteSpan()
| std::span<const std::uint8_t> quicr::messages::Message::ToByteSpan |
( |
| ) |
const |
|
inlinenoexcept |
Finalizes the message and returns a non-owning view of its bytes.
- Returns
- Span valid while the shared vector remains alive and is not reallocated or mutated.
The documentation for this class was generated from the following file: