µSer
uSer.hh File Reference

Main header file for the µSer Serialization library. More...

#include <cstddef>
#include <array>
#include <type_traits>
#include <utility>
#include <cassert>
#include <iterator>
#include <tuple>
#include <cstdint>
#include <limits>
#include <memory>
#include <ostream>
#include <iomanip>

Classes

struct  uSer::ByteOrder::LE
 Attribute: Store an integer as Little Endian. More...
 
struct  uSer::ByteOrder::BE
 Attribute: Store an integer as Big Endian. More...
 
struct  uSer::ByteOrder::PDP
 Attribute: Store an integer as PDP-Endian. More...
 
struct  uSer::SignFormat::TwosComplement
 Attribute: Store a signed integer in Two's Complement format. More...
 
struct  uSer::SignFormat::SignedMagnitude
 Attribute: Store a signed integer in Signed-Magnitude format. More...
 
struct  uSer::SignFormat::OnesComplement
 Attribute: Store a signed integer in One's Complement format. More...
 
struct  uSer::Padding::None
 Attribute: Store no padding bits after the actual bits of an integer. This is the default. Can only be applied to integers. More...
 
struct  uSer::Padding::Fixed< Count >
 Attribute: Store a fixed number of padding bits after the actual bits of an integer. Can only be applied to integers. More...
 
struct  uSer::Dyn::Size< Ref >
 An attribute that defines the size of a container that is a member of a struct to depend on external data, typically previously deserialized. More...
 
struct  uSer::Dyn::Optional< Ref >
 An attribute that decides whether a member of a struct is (de)serialized at all depending on external data, typically previously deserialized. More...
 
struct  uSer::Hook::SerPre< Ref >
 Attribute: Define a function to be called before the object (which can but need not be a struct member) is serialized. More...
 
struct  uSer::Hook::DeSerPre< Ref >
 Attribute: Define a function to be called before the object (which can but need not be a struct member) is deserialized. More...
 
struct  uSer::Hook::SerPost< Ref >
 Attribute: Define a function to be called after the object (which can but need not be a struct member) is serialized. More...
 
struct  uSer::Hook::DeSerPost< Ref >
 Attribute: Define a function to be called after the object (which can but need not be a struct member) is deserialized. More...
 
struct  uSer::Width< W >
 Attribute: Define the serialized size of an integer type. May not be larger than the C(++) data type used. More...
 
struct  uSer::RawInfo< SWord_, wSize_ >
 Attribute: Declares the serialization word explicitly. More...
 
struct  uSer::StructMembers< MemPtrs >
 Define the members of a struct by providing member pointers. More...
 
struct  uSer::Unlimited
 Indicates a dynamic data structure whose maximum serialized size can not be pre-calculated (e.g. when containers are used) More...
 
struct  uSer::MaxSize< N >
 Indicates a fixed maximum size for a dynamic data structure. More...
 
struct  uSer::NoDyn
 Indicates a data structure with no dynamic data. More...
 
struct  uSer::FixedSize< Size >
 
struct  uSer::DynSize
 
struct  uSer::InfSize
 
class  uSer::Exception
 

Namespaces

 uSerExtAnnot
 Namespace that collects external annotations. Contents is generated via the USER_EXT_ANNOT macros.
 
 uSer
 µSer main API.
 
 uSer::ByteOrder
 Byte orders for integers in serialized data.
 
 uSer::SignFormat
 Formats for signed integers.
 
 uSer::Hook
 Attributes to define hook functions for uSer.
 

Macros

#define USER_STRUCT(name, ...)   using uSer_Self = name; using uSer_Attributes = ::uSer::DefAttr<__VA_ARGS__>;
 Begin intrusive struct definition. More...
 
#define USER_MEM_ANNOT(name, ...)   static ::uSer::DefAttr<__VA_ARGS__> uSer_MemAttributes (::uSer::Helper::VTag<&uSer_Self:: name >);
 Define attributes for single struct member. More...
 
#define USER_ENUM_MEM(...)   using uSer_Members = ::uSer::StructMembers<USER_PPM_MAP_LIST(USER_ENUM_MEMPTR,uSer_Self,__VA_ARGS__)>;
 List previously defined struct members. More...
 
#define USER_MEM(type, name, ...)   type name; USER_MEM_ANNOT(name, __VA_ARGS__)
 Define and annotate struct member. More...
 
#define USER_DEF_MEM(...)   USER_PPM_MAP(USER_DEF_MEM_I,,__VA_ARGS__) using uSer_Members = ::uSer::StructMembers<USER_PPM_MAP_LIST(USER_DEF_MEM_GET_MPTR,uSer_Self,__VA_ARGS__)>;
 Define and annotate multiple struct members with attributes in one step. See Defining and annotating all struct members in one step. More...
 
#define USER_EXT_ANNOT(name, ...)   namespace uSerExtAnnot { template <> struct ExtAttr<name> { using Type = ::uSer::DefAttr<__VA_ARGS__>; }; }
 Annotate external data type (struct) More...
 
#define USER_EXT_MEM_ANNOT(sname, name, ...)   namespace uSerExtAnnot { template <> struct ExtMemAttr<&sname :: name> { using Type = ::uSer::DefAttr<__VA_ARGS__>; }; }
 Annotate external struct member. More...
 
#define USER_EXT_ENUM_MEM(sname, ...)   namespace uSerExtAnnot { template <> struct ExtStructMembers<sname> { using Type = ::uSer::StructMembers<USER_PPM_MAP_LIST(USER_ENUM_MEMPTR,sname,__VA_ARGS__)>; }; }
 List external struct members. More...
 
#define USER_EXT_DEF_MEM(sname, ...)   USER_PPM_MAP(USER_EXT_ENUM_MEM_I,sname,__VA_ARGS__) namespace uSerExtAnnot { template <> struct ExtStructMembers <sname>{ using Type = ::uSer::StructMembers<USER_PPM_MAP_LIST(USER_EXT_ENUM_MEM_GET_MPTR,sname,__VA_ARGS__)>; }; }
 Define and annotate multiple members of any external struct with attributes in one step. This macro must be called in the global namespace. See Non-Intrusive struct annotation. More...
 
#define USER_EXTERN_C   extern "C"
 This macro evaluates to extern "C" from C++, and to nothing in C. It can be used to define C++ functions that can be called from C code.
 

Typedefs

using uSer::AttrNone = Attributes<>
 
using uSer::ByteOrder::Native = LE
 This alias only exists if the compiler provides a BYTE_ORDER macro. It is an alias for LE, BE or PDP depending on the host byte order.
 
template<typename RawIter , typename Obj , typename... Attr>
using uSer::RawMaxDynamic = typename decltype(SWalk::walk(GetSerAlgo< true, RawIter, Attr... >::template root< Obj, InfSize, Helper::GetRootAttr< Attr... >>(std::declval< RawIter >(), std::declval< Obj & >(), infSize), Helper::GetRootAttr< Attr... >{}))::MaxDyn
 Indicates the maximum number of dynamic serialization words in raw data; may be an alias to Unlimited, NoDyn, or MaxSize.
 

Enumerations

Functions

const char * uSer_getErrorMessage (uSer_ErrorCode ec)
 Returns a string describing the error indicated by the given error code.
 
template<typename... Attr, typename RawIter , typename Obj , typename SizeT , std::enable_if_t< std::is_convertible_v< SizeT, Helper::SizeDefTag >, int > = 42>
decltype(auto) uSer::serialize (RawIter &&raw, const Obj &obj, SizeT size, std::size_t *sizeUsed=nullptr)
 
template<typename... Attr, typename SWord , typename Obj , std::size_t N>
decltype(auto) uSer::serialize (SWord(&raw)[N], const Obj &obj, std::size_t *sizeUsed=nullptr)
 
template<typename... Attr, typename SWord , typename Obj , std::size_t N>
decltype(auto) uSer::serialize (std::array< SWord, N > &raw, const Obj &obj, std::size_t *sizeUsed=nullptr)
 
template<typename... Attr, typename RawIter , typename Obj >
decltype(auto) uSer::serialize (RawIter &&raw, const Obj &obj, std::size_t size, std::size_t *sizeUsed=nullptr)
 
template<typename... Attr, typename RawContainer , typename Obj , decltype(std::size(std::declval< RawContainer >()))* = nullptr>
decltype(auto) uSer::serialize (RawContainer &&raw, const Obj &obj, std::size_t *sizeUsed=nullptr)
 
template<typename... Attr, typename RawIter , typename Obj , typename SizeT , std::enable_if_t< std::is_convertible_v< SizeT, Helper::SizeDefTag >, int > = 42>
decltype(auto) uSer::deserialize (RawIter &&raw, Obj &obj, SizeT size, std::size_t *sizeUsed=nullptr)
 
template<typename... Attr, typename SWord , typename Obj , std::size_t N>
decltype(auto) uSer::deserialize (const SWord(&raw)[N], Obj &obj, std::size_t *sizeUsed=nullptr)
 
template<typename... Attr, typename SWord , typename Obj , std::size_t N>
decltype(auto) uSer::deserialize (const std::array< SWord, N > &raw, Obj &obj, std::size_t *sizeUsed=nullptr)
 
template<typename... Attr, typename SWord , typename Obj , std::size_t N>
decltype(auto) uSer::deserialize (SWord(&raw)[N], Obj &obj, std::size_t *sizeUsed=nullptr)
 
template<typename... Attr, typename SWord , typename Obj , std::size_t N>
decltype(auto) uSer::deserialize (std::array< SWord, N > &raw, Obj &obj, std::size_t *sizeUsed=nullptr)
 
template<typename... Attr, typename RawIter , typename Obj >
decltype(auto) uSer::deserialize (RawIter &&raw, Obj &obj, std::size_t size, std::size_t *sizeUsed=nullptr)
 
template<typename... Attr, typename RawContainer , typename Obj , decltype(std::size(std::declval< RawContainer >()))* = nullptr>
decltype(auto) uSer::deserialize (RawContainer &&raw, Obj &obj, std::size_t *sizeUsed=nullptr)
 
template<typename... Attr, typename Obj >
constexpr bool uSer::compare (const Obj &a, const Obj &b)
 
template<typename... Attr, typename Obj >
std::ostream & uSer::print (std::ostream &os, const Obj &obj)
 

Detailed Description

Main header file for the µSer Serialization library.

Author
Niklas Gürtler

Macro Definition Documentation

#define USER_DEF_MEM (   ...)    USER_PPM_MAP(USER_DEF_MEM_I,,__VA_ARGS__) using uSer_Members = ::uSer::StructMembers<USER_PPM_MAP_LIST(USER_DEF_MEM_GET_MPTR,uSer_Self,__VA_ARGS__)>;

Define and annotate multiple struct members with attributes in one step. See Defining and annotating all struct members in one step.

Parameters
...A sequence of the form (type1,name1,attributes1...),(type2,name2,attributes2...), ...
#define USER_ENUM_MEM (   ...)    using uSer_Members = ::uSer::StructMembers<USER_PPM_MAP_LIST(USER_ENUM_MEMPTR,uSer_Self,__VA_ARGS__)>;

List previously defined struct members.

Call this macro after USER_STRUCT and the definition of member variables to make the members known to µSer. See Defining and annotating struct members separately

Parameters
...The names of member variables.
#define USER_EXT_ANNOT (   name,
  ... 
)    namespace uSerExtAnnot { template <> struct ExtAttr<name> { using Type = ::uSer::DefAttr<__VA_ARGS__>; }; }

Annotate external data type (struct)

Adds annotations to any type. It is recommended to only use this on structs. This macro must be called in the global namespace. See Non-Intrusive struct annotation

Parameters
nameThe fully-qualified name of the annotated type (including namespaces)
...A list of attributes
#define USER_EXT_DEF_MEM (   sname,
  ... 
)    USER_PPM_MAP(USER_EXT_ENUM_MEM_I,sname,__VA_ARGS__) namespace uSerExtAnnot { template <> struct ExtStructMembers <sname>{ using Type = ::uSer::StructMembers<USER_PPM_MAP_LIST(USER_EXT_ENUM_MEM_GET_MPTR,sname,__VA_ARGS__)>; }; }

Define and annotate multiple members of any external struct with attributes in one step. This macro must be called in the global namespace. See Non-Intrusive struct annotation.

Parameters
snameThe fully-qualified name of the surrounding struct (including namespaces)
...A sequence of the form (type1,name1,attributes1...),(type2,name2,attributes2...), ...
#define USER_EXT_ENUM_MEM (   sname,
  ... 
)    namespace uSerExtAnnot { template <> struct ExtStructMembers<sname> { using Type = ::uSer::StructMembers<USER_PPM_MAP_LIST(USER_ENUM_MEMPTR,sname,__VA_ARGS__)>; }; }

List external struct members.

Makes the list of members of any struct known to µSer. This macro must be called in the global namespace. See Non-Intrusive struct annotation

Parameters
snameThe fully-qualified name of the surrounding struct (including namespaces)
...The names of member variables.
#define USER_EXT_MEM_ANNOT (   sname,
  name,
  ... 
)    namespace uSerExtAnnot { template <> struct ExtMemAttr<&sname :: name> { using Type = ::uSer::DefAttr<__VA_ARGS__>; }; }

Annotate external struct member.

Adds annotations to the member of any struct. This macro must be called in the global namespace. See Non-Intrusive struct annotation

Parameters
snameThe fully-qualified name of the surrounding struct (including namespaces)
nameName of the member
...A list of attributes
#define USER_MEM (   type,
  name,
  ... 
)    type name; USER_MEM_ANNOT(name, __VA_ARGS__)

Define and annotate struct member.

Defines a member with type name and annotates it via USER_MEM_ANNOT in one step. See Defining and annotating a single member in one step

Parameters
typeThe type for the member
nameThe name for the member
#define USER_MEM_ANNOT (   name,
  ... 
)    static ::uSer::DefAttr<__VA_ARGS__> uSer_MemAttributes (::uSer::Helper::VTag<&uSer_Self:: name >);

Define attributes for single struct member.

Call this macro if you want to annotate a single struct member. See Annotating a single struct member

Parameters
nameName of the parameter
...A list of attributes.
#define USER_STRUCT (   name,
  ... 
)    using uSer_Self = name; using uSer_Attributes = ::uSer::DefAttr<__VA_ARGS__>;

Begin intrusive struct definition.

Call this macro at the beginning of a struct definition. See Defining and annotating struct members separately

Parameters
nameThe name of the struct
...A list of attributes. If none, specify uSer::AttrNone to avoid compiler warnings

Enumeration Type Documentation

Error code for serialization functions.

Enumerator
uSer_EOK 

No error was indicated (success)

uSer_EDYNRANGE 

The size of a dynamic data structure exceeds the allowed maximum.

uSer_EBUFSIZE 

Raw buffer overflow.

uSer_EHOOK 

This error is never raised by uSer, but can be used by hooks.