Crunch
A Message Definition Language for Getting Things Right
Loading...
Searching...
No Matches
Crunch::serdes::TlvLayout Struct Reference

Public Types

enum class  WireType : uint8_t { Varint = 0 , LengthDelimited = 1 }
 Wire types for TLV encoding.
 

Static Public Member Functions

static constexpr Crunch::Format GetFormat ()
 
template<typename Message >
static consteval std::size_t Size () noexcept
 Calculates the maximum possible serialized size of a message.
 
template<typename Message >
static constexpr std::size_t Serialize (const Message &msg, std::span< std::byte > output) noexcept
 Serializes a message into the output buffer.
 
template<typename Message >
static constexpr auto Deserialize (std::span< const std::byte > input, Message &msg) noexcept -> std::optional< Error >
 Deserializes a message from the input buffer.
 

Static Public Attributes

static constexpr std::size_t WireTypeBits = 3
 Number of bits used for the wire type in a tag.
 
static constexpr std::size_t MaxTagBits
 The maximum number of bits required for a Tag (FieldID + WireType). Used for calculating the maximum size of a tag varint.
 

Member Function Documentation

◆ Deserialize()

template<typename Message >
static constexpr auto Crunch::serdes::TlvLayout::Deserialize ( std::span< const std::byte >  input,
Message &  msg 
) -> std::optional<Error>
inlinestaticconstexprnoexcept

Deserializes a message from the input buffer.

Template Parameters
MessageThe message type.
Parameters
inputThe input buffer.
msgThe message object to populate.
Returns
std::nullopt on success, or Error.

◆ Serialize()

template<typename Message >
static constexpr std::size_t Crunch::serdes::TlvLayout::Serialize ( const Message &  msg,
std::span< std::byte >  output 
)
inlinestaticconstexprnoexcept

Serializes a message into the output buffer.

Template Parameters
MessageThe message type.
Parameters
msgThe message to serialize.
outputThe output buffer.
Returns
The number of bytes written (offset).

◆ Size()

template<typename Message >
static consteval std::size_t Crunch::serdes::TlvLayout::Size ( )
inlinestaticnoexcept

Calculates the maximum possible serialized size of a message.

Template Parameters
MessageThe message type.
Returns
The size in bytes.

Member Data Documentation

◆ MaxTagBits

constexpr std::size_t Crunch::serdes::TlvLayout::MaxTagBits
staticconstexpr
Initial value:
=
sizeof(FieldId) * 8 + WireTypeBits
int32_t FieldId
Unique identifier for a field within a Crunch message.
Definition: crunch_types.hpp:11
static constexpr std::size_t WireTypeBits
Number of bits used for the wire type in a tag.
Definition: crunch_tlv_layout.hpp:66

The maximum number of bits required for a Tag (FieldID + WireType). Used for calculating the maximum size of a tag varint.


The documentation for this struct was generated from the following file: