|
template<typename T >
requires std::integral<T> || std::is_enum_v<T> || std::floating_point<T> |
| constexpr T | LittleEndian (T value) noexcept |
| | Converts a value to/from Little Endian byte order.
|
| |
| constexpr std::expected< CrunchHeader, Error > | GetHeader (std::span< const std::byte > input) noexcept |
| | Parses and returns a copy of the header from the input buffer.
|
| |
| template<typename Message , typename Serdes > |
| constexpr std::size_t | WriteHeader (std::span< std::byte > output) noexcept |
| | Writes the standard header to the output buffer.
|
| |
| template<typename Message , typename Serdes > |
| constexpr std::expected< std::size_t, Error > | ValidateHeader (std::span< const std::byte > input) noexcept |
| | Validates the header and returns offset after header on success.
|
| |
template<messages::CrunchMessage Message, typename Integrity , typename Serdes >
requires IntegrityPolicy<Integrity> && SerdesPolicy<Serdes, Message> |
| constexpr auto | GetBuffer () noexcept |
| | Creates a correctly sized Buffer for the given configuration.
|
| |
| template<messages::CrunchMessage Message> |
| constexpr auto | Validate (const Message &message) noexcept -> std::optional< Error > |
| | Validates a message (field presence + message-level validation).
|
| |
template<typename BufferType , typename Message >
requires IsBuffer<BufferType> && messages::CrunchMessage<Message> && std::same_as<typename BufferType::MessageType, Message> |
| constexpr auto | Serialize (BufferType &buffer, const Message &message) noexcept -> std::optional< Error > |
| | Serializes a message into the provided buffer.
|
| |
template<typename BufferType , typename Message >
requires IsBuffer<BufferType> && messages::CrunchMessage<Message> && std::same_as<typename BufferType::MessageType, Message> |
| constexpr void | SerializeWithoutValidation (BufferType &buffer, const Message &message) noexcept |
| | Serializes a message into the provided buffer without validation.
|
| |
template<typename BufferType , typename Message >
requires IsBuffer<BufferType> && messages::CrunchMessage<Message> && std::same_as<typename BufferType::MessageType, Message> |
| constexpr auto | Deserialize (const BufferType &buffer, Message &out_message) -> std::optional< Error > |
| | Deserializes a message from a buffer.
|
| |
The public API for Crunch.
This section contains all the interfaces for serializing and deserializing messages, and transitively provides the necessary types for defining messages and fields.
Top-level APIs
- GetBuffer: Creates a strongly-typed buffer of the maximum serialized message size for a given Message, Integrity, and Serdes combination.
- Validate: Validates field presence and message-level constraints.
- Serialize: Validates and writes a message into a buffer, appending integrity checks.
- Deserialize: Verifies integrity and reads a message from a buffer.
template<typename BufferType , typename Message >
requires IsBuffer<BufferType> && messages::CrunchMessage<Message> && std::same_as<typename BufferType::MessageType, Message>
| constexpr auto Crunch::Deserialize |
( |
const BufferType & |
buffer, |
|
|
Message & |
out_message |
|
) |
| -> std::optional<Error> |
|
constexpr |
Deserializes a message from a buffer.
Verifies the integrity of the buffer, then attempts to deserialize the content into a Message object.
Constraints:
- BufferType must be an instantiation of Crunch::Buffer.
- Message must satisfy the CrunchMessage concept.
- BufferType::MessageType must be the same as Message.
- Template Parameters
-
| BufferType | The Buffer type |
| Message | The CrunchMessage type to deserialize into. |
- Parameters
-
| buffer | The source Buffer to read from. |
| out_message | Output parameter for the deserialized message. |
- Returns
- std::optional<Error> std::nullopt on success, or an Error (Integrity/Deserialization).
template<messages::CrunchMessage Message, typename Integrity , typename Serdes >
requires IntegrityPolicy<Integrity> && SerdesPolicy<Serdes, Message>
| constexpr auto Crunch::GetBuffer |
( |
| ) |
|
|
constexprnoexcept |
Creates a correctly sized Buffer for the given configuration.
This function calculates the exact size required for the message serialization plus any integrity overhead at compile time.
- Template Parameters
-
| Message | The CrunchMessage type. |
| Integrity | The IntegrityPolicy (e.g., integrity::None, integrity::CRC16). |
| Serdes | The SerdesPolicy (e.g., serdes::PackedLayout). |
- Returns
- A Buffer object ready for use with Serialize/Deserialize.
template<typename BufferType , typename Message >
requires IsBuffer<BufferType> && messages::CrunchMessage<Message> && std::same_as<typename BufferType::MessageType, Message>
| constexpr auto Crunch::Serialize |
( |
BufferType & |
buffer, |
|
|
const Message & |
message |
|
) |
| -> std::optional<Error> |
|
constexprnoexcept |
Serializes a message into the provided buffer.
Validates the message content, serializes it according to the Serdes policy, and applies the Integrity policy (e.g., checksum).
Constraints:
- BufferType must be an instantiation of Crunch::Buffer.
- Message must satisfy the CrunchMessage concept.
- BufferType::MessageType must be the same as Message.
- Template Parameters
-
| BufferType | The Buffer type (deduced from buffer parameter). |
| Message | The CrunchMessage type to serialize. |
- Parameters
-
| buffer | The destination Buffer (must match Message type). |
| message | The message to serialize. |
- Returns
- std::optional<Error> std::nullopt on success, or an Error if validation fails.
template<typename BufferType , typename Message >
requires IsBuffer<BufferType> && messages::CrunchMessage<Message> && std::same_as<typename BufferType::MessageType, Message>
| constexpr void Crunch::SerializeWithoutValidation |
( |
BufferType & |
buffer, |
|
|
const Message & |
message |
|
) |
| |
|
constexprnoexcept |
Serializes a message into the provided buffer without validation.
Does strictly serialization logic (header, payload, checksum) without running any validation checks. Useful for forwarding invalid messages, testing, or performance-critical paths where validation is done elsewhere.
- Template Parameters
-
| BufferType | The Buffer type |
| Message | The CrunchMessage type to serialize. |
- Parameters
-
| buffer | The destination Buffer (must match Message type). |
| message | The message to serialize. |