Skip to content

Namespace cerializer

Namespace List > cerializer

The main namespace for the serialization library.

Classes

Type Name
class BasePacket
An abstract base class for all serializable message packets.
class Config
A message for setting runtime configuration parameters.
class Deserializer <typename T>
A class for deserializing messages from a generic input stream.
class Message <typename Derived, TypeVal, FieldTypes>
A template base class for defining serializable messages.
class MessageMaker
A factory class for creating message objects from binary data.
class Serializer <typename T>
A class for serializing messages to a generic output stream.
class SetStanceMessage
A message to set the turret's firing stance.
class SetStrategyMessage
A message to set the turret's targeting strategy.
class SetTargetSourceMessage
A message to set the active target source.
class StaticTargetMessage
A message for setting a static target position.
class StreamHandler <typename T>
A class for handling both serialization and deserialization on a single stream.
class Target
An example message class for representing a target.
struct is_std_array <typename T>
Type trait to check if a type is a std::array.
struct is_std_array< std::array< T, N > > <typename T, N>

Public Types

Type Name
typedef std::unique_ptr< BasePacket > BasePointer
Type alias for a unique pointer to a BasePacket , used for polymorphism.
enum ParseMode
Represents the current state of the deserializer's parsing process.
typedef std::array< char, 1+(std::get< 0 >(formatSize< Ts >())+...)> RenderedFormatString
A type alias for the character array that holds a rendered format string.
typedef std::tuple< uint8_t, uint8_t, char > TypeCharSpec
A type alias for a tuple describing a type's format: {size_digits, size_in_bytes, type_char}.

Public Attributes

Type Name
constexpr bool is_std_array_v = [**is\_std\_array**](structcerializer_1_1is__std__array.md)&lt;T&gt;::value
const uint16_t magicFoot = 0xFACE
Magic number to signify the end of a message.
const uint16_t magicHead = 0xCAFE
Magic number to signify the start of a message.

Public Functions

Type Name
constexpr TypeCharSpec formatSize ()
Gets the format size and type character for a given type.
constexpr TypeCharSpec formatSize ()
Specialization for character arrays, representing them as a string.
constexpr TypeCharSpec formatSize< bool > ()
Specialization for bool.
constexpr TypeCharSpec formatSize< char > ()
Specialization for char.
constexpr TypeCharSpec formatSize< double > ()
Specialization for double.
constexpr TypeCharSpec formatSize< float > ()
Specialization for float.
constexpr TypeCharSpec formatSize< int > ()
Specialization for int.
constexpr TypeCharSpec formatSize< long > ()
Specialization for long.
constexpr TypeCharSpec formatSize< long long > ()
Specialization for long long.
constexpr TypeCharSpec formatSize< short > ()
Specialization for short.
constexpr TypeCharSpec formatSize< signed char > ()
Specialization for signed char.
constexpr TypeCharSpec formatSize< unsigned char > ()
Specialization for unsigned char.
constexpr TypeCharSpec formatSize< unsigned int > ()
Specialization for unsigned int.
constexpr TypeCharSpec formatSize< unsigned long > ()
Specialization for unsigned long.
constexpr TypeCharSpec formatSize< unsigned long long > ()
Specialization for unsigned long long.
constexpr TypeCharSpec formatSize< unsigned short > ()
Specialization for unsigned short.
std::string hexify (auto data)
Converts a block of data into a hexadecimal string representation.
constexpr std::array< char,(sizeof(Ts)+...)> pack (const Ts &... args)
Packs a series of trivially copyable arguments into a single character array.
constexpr std::common_type< T, Y >::type postfixAdd (T & initial, const Y & add)
A utility function to perform a postfix addition, returning the original value.
constexpr RenderedFormatString< Ts... > renderFormat ()
Renders the format string for a series of types.
constexpr auto toCharArray (const T & thing)
Casts an object to its raw byte representation in a std::array.
constexpr Dest unpack (const Cont & binaryData)
Unpacks a character array into a specified destination type or a struct.
constexpr T unpack_one (const Cont & data)
Safely unpacks a single trivially copyable type from a container of bytes.

Public Types Documentation

typedef BasePointer

Type alias for a unique pointer to a BasePacket , used for polymorphism.

using cerializer::BasePointer = typedef std::unique_ptr<BasePacket>;

enum ParseMode

Represents the current state of the deserializer's parsing process.

enum cerializer::ParseMode {
    START,
    PRE_END,
    END,
    EMIT
};

typedef RenderedFormatString

A type alias for the character array that holds a rendered format string.

using cerializer::RenderedFormatString = typedef std::array<char, 1 + (std::get<0>(formatSize<Ts>()) + ...)>;

typedef TypeCharSpec

A type alias for a tuple describing a type's format: {size_digits, size_in_bytes, type_char}.

using cerializer::TypeCharSpec = typedef std::tuple<uint8_t, uint8_t, char>;

Public Attributes Documentation

variable is_std_array_v

constexpr bool cerializer::is_std_array_v;

variable magicFoot

Magic number to signify the end of a message.

const uint16_t cerializer::magicFoot;

variable magicHead

Magic number to signify the start of a message.

const uint16_t cerializer::magicHead;

Public Functions Documentation

function formatSize

Gets the format size and type character for a given type.

template<typename T>
constexpr TypeCharSpec cerializer::formatSize () 

This function provides the necessary information for building a format string similar to Python's struct module. Specializations are provided for common types. The generic fallback treats the type as a packed binary structure.

Template parameters:

  • T The type to inspect.

Returns:

A TypeCharSpec tuple containing {size_digits, size_in_bytes, type_char}.


function formatSize

Specialization for character arrays, representing them as a string.

template<typename T>
constexpr TypeCharSpec cerializer::formatSize () 

function formatSize< bool >

Specialization for bool.

template<>
constexpr TypeCharSpec cerializer::formatSize< bool > () 

function formatSize< char >

Specialization for char.

template<>
constexpr TypeCharSpec cerializer::formatSize< char > () 

function formatSize< double >

Specialization for double.

template<>
constexpr TypeCharSpec cerializer::formatSize< double > () 

function formatSize< float >

Specialization for float.

template<>
constexpr TypeCharSpec cerializer::formatSize< float > () 

function formatSize< int >

Specialization for int.

template<>
constexpr TypeCharSpec cerializer::formatSize< int > () 

function formatSize< long >

Specialization for long.

template<>
constexpr TypeCharSpec cerializer::formatSize< long > () 

function formatSize< long long >

Specialization for long long.

template<>
constexpr TypeCharSpec cerializer::formatSize< long long > () 

function formatSize< short >

Specialization for short.

template<>
constexpr TypeCharSpec cerializer::formatSize< short > () 

function formatSize< signed char >

Specialization for signed char.

template<>
constexpr TypeCharSpec cerializer::formatSize< signed char > () 

function formatSize< unsigned char >

Specialization for unsigned char.

template<>
constexpr TypeCharSpec cerializer::formatSize< unsigned char > () 

function formatSize< unsigned int >

Specialization for unsigned int.

template<>
constexpr TypeCharSpec cerializer::formatSize< unsigned int > () 

function formatSize< unsigned long >

Specialization for unsigned long.

template<>
constexpr TypeCharSpec cerializer::formatSize< unsigned long > () 

function formatSize< unsigned long long >

Specialization for unsigned long long.

template<>
constexpr TypeCharSpec cerializer::formatSize< unsigned long long > () 

function formatSize< unsigned short >

Specialization for unsigned short.

template<>
constexpr TypeCharSpec cerializer::formatSize< unsigned short > () 

function hexify

Converts a block of data into a hexadecimal string representation.

std::string cerializer::hexify (
    auto data
) 

Parameters:

  • data The data to be converted, expected to be a container of characters.

Returns:

A string containing the hexadecimal representation of the input data.


function pack

Packs a series of trivially copyable arguments into a single character array.

template<typename... Ts>
inline constexpr std::array< char,(sizeof(Ts)+...)> cerializer::pack (
    const Ts &... args
) 

This function performs serialization by copying the binary representation of each argument into a contiguous byte array. It handles endianness conversion for multi-byte types if the native endianness is big-endian.

Template parameters:

  • Ts The types of the arguments to pack.

Parameters:

  • args The arguments to be packed.

Returns:

A std::array<char, ...> containing the serialized data.


function postfixAdd

A utility function to perform a postfix addition, returning the original value.

template<std::integral T, std::integral Y>
inline constexpr std::common_type< T, Y >::type cerializer::postfixAdd (
    T & initial,
    const Y & add
) 

This is useful for advancing an offset or pointer while using its previous value in an expression.

Template parameters:

  • T The type of the value to be incremented.
  • Y The type of the value to add.

Parameters:

  • initial The value to be incremented, passed by reference.
  • add The value to add.

Returns:

The value of initial before the addition.


function renderFormat

Renders the format string for a series of types.

template<typename... Ts>
inline constexpr RenderedFormatString < Ts... > cerializer::renderFormat () 

function toCharArray

Casts an object to its raw byte representation in a std::array.

template<typename T>
constexpr auto cerializer::toCharArray (
    const T & thing
) 

Template parameters:

  • T The type of the object to convert.

Parameters:

  • thing The object to be converted.

Returns:

A std::array<char, sizeof(T)> containing the byte representation of the object.


function unpack

Unpacks a character array into a specified destination type or a struct.

template<typename Dest, typename... Ts, typename Cont>
inline constexpr Dest cerializer::unpack (
    const Cont & binaryData
) 

This function can operate in two modes: * If only Dest is provided, it unpacks the binary data directly into an object of type Dest. * If Dest and Ts... are provided, it unpacks the binary data into individual values of types Ts... and uses them to construct an object of type Dest.

It uses memcpy to ensure safe access to potentially misaligned data and handles endianness conversion.

Template parameters:

  • Dest The destination type to create.
  • Ts The types of the fields to unpack for constructing Dest.
  • Cont A container type for the binary data, like std::span or std::array.

Parameters:

  • binaryData The container holding the binary data.

Returns:

An object of type Dest constructed from the unpacked data.


function unpack_one

Safely unpacks a single trivially copyable type from a container of bytes.

template<typename T, typename Cont>
inline constexpr T cerializer::unpack_one (
    const Cont & data
) 

This function uses std::memcpy to avoid misaligned reads and handles endianness conversion for multi-byte types if the native endianness is big-endian.

Template parameters:

  • T The type of the object to unpack.
  • Cont The container type for the binary data.

Parameters:

  • data The container holding the bytes.

Returns:

An object of type T.



The documentation for this class was generated from the following file serializer.hpp