5#include <crunch/crunch_detail.hpp>
6#include <crunch/fields/crunch_enum.hpp>
7#include <crunch/fields/crunch_string.hpp>
8#include <crunch/integrity/crunch_integrity.hpp>
9#include <crunch/messages/crunch_messages.hpp>
10#include <crunch/serdes/crunch_serdes.hpp>
11#include <crunch/serdes/crunch_static_layout.hpp>
40using detail::IsBuffer;
54template <messages::CrunchMessage Message,
typename Integrity,
typename Serdes>
55 requires IntegrityPolicy<Integrity> && SerdesPolicy<Serdes, Message>
58 constexpr std::size_t N =
59 detail::GetBufferSize<Message, Integrity, Serdes>();
80template <messages::CrunchMessage Message>
81[[nodiscard]]
constexpr auto Validate(
const Message& message)
noexcept
82 -> std::optional<Error> {
104template <
typename BufferType,
typename Message>
105 requires IsBuffer<BufferType> && messages::CrunchMessage<Message> &&
106 std::same_as<typename BufferType::MessageType, Message>
107[[nodiscard]]
constexpr auto Serialize(BufferType& buffer,
108 const Message& message)
noexcept
109 -> std::optional<Error> {
110 using Serdes =
typename BufferType::SerdesType;
111 using Integrity =
typename BufferType::IntegrityType;
112 auto res = detail::Serialize<Integrity, Serdes>(buffer.data, message);
116 buffer.used_bytes = *res;
132template <
typename BufferType,
typename Message>
133 requires IsBuffer<BufferType> && messages::CrunchMessage<Message> &&
134 std::same_as<typename BufferType::MessageType, Message>
136 const Message& message)
noexcept {
137 using Serdes =
typename BufferType::SerdesType;
138 using Integrity =
typename BufferType::IntegrityType;
139 buffer.used_bytes = detail::SerializeWithoutValidation<Integrity, Serdes>(
140 buffer.data, message);
161template <
typename BufferType,
typename Message>
162 requires IsBuffer<BufferType> && messages::CrunchMessage<Message> &&
163 std::same_as<typename BufferType::MessageType, Message>
165 Message& out_message)
166 -> std::optional<Error> {
167 using Serdes =
typename BufferType::SerdesType;
168 using Integrity =
typename BufferType::IntegrityType;
169 return detail::Deserialize<Integrity, Serdes>(
170 buffer.serialized_message_span(), out_message);
constexpr auto Validate(const Message &message) noexcept -> std::optional< Error >
Forward declaration of Validate to enable recursion in ValidateField.
Definition: crunch_detail.hpp:138
The public API for Crunch.
Definition: crunch_endian.hpp:10
constexpr auto Validate(const Message &message) noexcept -> std::optional< Error >
Validates a message (field presence + message-level validation).
Definition: crunch.hpp:81
constexpr auto Deserialize(const BufferType &buffer, Message &out_message) -> std::optional< Error >
Deserializes a message from a buffer.
Definition: crunch.hpp:164
constexpr void SerializeWithoutValidation(BufferType &buffer, const Message &message) noexcept
Serializes a message into the provided buffer without validation.
Definition: crunch.hpp:135
constexpr auto Serialize(BufferType &buffer, const Message &message) noexcept -> std::optional< Error >
Serializes a message into the provided buffer.
Definition: crunch.hpp:107
constexpr auto GetBuffer() noexcept
Creates a correctly sized Buffer for the given configuration.
Definition: crunch.hpp:57
A lightweight wrapper around a std::array for serializing/deserializing messages.
Definition: crunch_detail.hpp:31