![]() |
CppSerdes
1.0
A serialization/deserialization library designed with embedded systems in mind
|
CppSerdes library namespace. More...
Namespaces | |
init_formatter | |
init_formatter() constructs a serdes::formatter object lambda without using dynamic memory allocation. A number of different use cases are supported, see serdes::formatter for examples. | |
init_this_formatter | |
init_this_formatter() constructs a serdes::formatter object lambda without using dynamic memory allocation. Same as init_formatter but captures "this", only necessary for older compilers which don't capture "this" automatically. | |
literals | |
provides fixed size literals, useful when specifying serialization actions to convey exact bit widths | |
Classes | |
struct | align |
specifies a number of bits to be used to align the bit offset as a multiple of More... | |
struct | array |
a container for fixed or dynamically sized arrays, with an upper bounds limit for safety More... | |
struct | bitpack |
bitpack a value into an exact number of specified bits. If applied to an array it will be applied to each element of the array, not the total bits in the array More... | |
struct | delimited_array |
a container for dynamically sized arrays with their ending marked by a reserved delimiter value More... | |
struct | formatter |
a lambda function wrapper that can describe any serialization/deserialization formatting process. While it does use more overhead (because of the lambda), it also can describe any format process as manipulatable runtime data, which the other hard coded interfaces don't allow. More... | |
struct | info |
CppSerdes library information. More... | |
struct | packet |
a serialization/deserialization helper class, with load, store, and stream operators More... | |
struct | packet_base |
inheritable base class to allow format recording and application with no additional memory storage (except for the virtual table pointer) More... | |
struct | pad |
specifies a number of bits to be used to pad (add to) the current bit offset More... | |
struct | sized_pointer |
Holds a pointer to an array (with its type information) with a constant size. More... | |
struct | sized_pointer< void > |
Holds a pointer to a void array (with type information stored as a runtime element size paramenter) with a constant size. More... | |
struct | status_t |
status returned after any serialization/deserialization process More... | |
Enumerations | |
enum | status_e { status_e::NO_ERROR = 0, status_e::EXCEEDED_SERIAL_SIZE = 1, status_e::ARRAY_SIZE_OVER_MAX = 2, status_e::INVALID_FIELD = 3, status_e::NO_LOAD_TO_RVALUE = 4, status_e::DELIMITER_NOT_FOUND = 5, status_e::FORMATTER_NOT_SET = 6 } |
error status of serialization/deserialization process More... | |
enum | mode_e { mode_e::LOADING, mode_e::STORING, mode_e::UNSPECIFIED } |
the serdes mode of operation More... | |
Functions | |
template<typename T > | |
constexpr T | bit_length (T &&x) noexcept |
Does nothing but annotate a passed value as a bit length, used for writting clearer code. More... | |
template<typename T_array , typename T_val , detail::requires_unsigned_type< T_val > * = nullptr> | |
CONSTEXPR_ABOVE_CPP11 size_t | bitcpy (T_val &dest, const T_array *const source, const size_t bit_offset=0, const size_t bits=detail::default_bitsize< T_val >::value) noexcept |
[[deserialize, uint destination]] copies the specified number of bits from an array into a value More... | |
template<typename T_array , typename T_val , detail::requires_small_non_integral_type< T_val > * = nullptr> | |
size_t | bitcpy (T_val &dest, const T_array *const source, const size_t bit_offset=0, const size_t bits=detail::default_bitsize< T_val >::value) noexcept |
[[deserialize, integral value <= 8 bytes destination]] copies the specified number of bits from an array into a integral value with <= 8 bytes More... | |
template<typename T_array , typename T_val , detail::requires_unsigned_type< T_val > * = nullptr> | |
CONSTEXPR_ABOVE_CPP11 size_t | bitcpy (sized_pointer< T_val > &dest, const T_array *const source, const size_t bit_offset, const size_t bits) noexcept |
[[deserialize, partial sized_pointer destination]] copies the specified number of bits from an array into a sized_pointer array (no default bits, since it can't necessarily be known at compile time) More... | |
template<typename T_array , typename T_val , detail::requires_unsigned_type< T_val > * = nullptr> | |
CONSTEXPR_ABOVE_CPP11 size_t | bitcpy (sized_pointer< T_val > &dest, const T_array *const source, const size_t bit_offset=0) noexcept |
[[deserialize, entire sized_pointer destination]] copies the specified number of bits from an array into a sized_pointer array using a bit length equal to the entire bit capacity of the sized_pointer object. More... | |
template<typename T_array = void, typename T_val = void, detail::requires_not_a_pointer_type< T_val > * = nullptr> | |
CONSTEXPR_ABOVE_CPP11 size_t | bitcpy (T_val &dest, const sized_pointer< T_array > source, size_t bit_offset=0, const size_t bits=detail::default_bitsize< T_val >::value) noexcept |
[[deserialize, size safe]] copies the specified number of bits from an sized_pointer into a value. used to prevent reading beyond the boundary of the source array. More... | |
template<typename T_array = void, typename T_val = void, detail::requires_pointer_type< T_val > * = nullptr> | |
size_t | bitcpy (T_val &dest, const sized_pointer< T_array > source, const size_t bit_offset=0, const size_t bits=detail::default_bitsize< T_val >::value) noexcept |
[[deserialize, size safe, pointer dest]] copies the specified number of bits from an sized_pointer into a value. used to prevent reading beyond the boundary of the source array. More... | |
template<typename T_array , typename T_val > | |
size_t | bitcpy (std::atomic< T_val > &dest, const T_array *const source, const size_t bit_offset=0, const size_t bits=detail::default_bitsize< T_val >::value) noexcept |
[[deserialize, atomic dest]] copies the specified number of bits from an array into an atomic value More... | |
template<typename T_val = void> | |
CONSTEXPR_ABOVE_CPP11 size_t | bitcpy (T_val &dest, const sized_pointer< void > &source, const size_t bit_offset=0, const size_t bits=detail::default_bitsize< T_val >::value) noexcept |
[[deserialize, size safe, type punned (void) source array]] copies the specified number of bits from an array with a runtime determined base type into a value More... | |
template<typename T_array , typename T_val , detail::requires_unsigned_type< T_val > * = nullptr> | |
CONSTEXPR_ABOVE_CPP11 size_t | bitcpy (T_array *const dest, const T_val source, const size_t bit_offset=0, const size_t bits=detail::default_bitsize< T_val >::value) noexcept |
[[serialize, uint source]] copies the specified number of bits from a value into an array More... | |
template<typename T_array , typename T_val , detail::requires_unsigned_type< T_val > * = nullptr> | |
CONSTEXPR_ABOVE_CPP11 size_t | bitcpy (T_array *const dest, const sized_pointer< const T_val > &source, const size_t bit_offset, const size_t bits) noexcept |
[[serialize, partial sized_pointer source]] copies the specified number of bits from a value into an array (no default bits, since it can't necessarily be known at compile time) More... | |
template<typename T_array , typename T_val , detail::requires_unsigned_type< T_val > * = nullptr> | |
CONSTEXPR_ABOVE_CPP11 size_t | bitcpy (T_array *const dest, const sized_pointer< const T_val > &source, const size_t bit_offset=0) noexcept |
[[serialize, entire sized_pointer source]] copies the entire sized_pointer object from a value into an array More... | |
template<typename T_array , typename T_val , detail::requires_large_non_integral_type< T_val > * = nullptr> | |
CONSTEXPR_ABOVE_CPP11_AND_NON_LITERAL_STORAGE size_t | bitcpy (T_array *const dest, const T_val &source, const size_t bit_offset=0, const size_t bits=detail::default_bitsize< T_val >::value) noexcept |
[[serialize, large non integral type source]] copies the specified number of bits from a value into an array More... | |
template<typename T_array = void, typename T_val = void> | |
CONSTEXPR_ABOVE_CPP11 size_t | bitcpy (sized_pointer< T_array > dest, const T_val &source, const size_t bit_offset=0, const size_t bits=detail::default_bitsize< T_val >::value) noexcept |
[[serialize, size safe]] copies the specified number of bits from a value into an sized array More... | |
template<typename T_array , typename T_val > | |
size_t | bitcpy (T_array *const dest, const std::atomic< T_val > &source, const size_t bit_offset=0, const size_t bits=detail::default_bitsize< T_val >::value) noexcept |
[[serialize, atomic source]] copies the specified number of bits from an atomic value into an sized array More... | |
template<typename T_val > | |
CONSTEXPR_ABOVE_CPP11 size_t | bitcpy (sized_pointer< void > &dest, const T_val &source, const size_t bit_offset=0, const size_t bits=detail::default_bitsize< T_val >::value) noexcept |
[[serialize, size safe, type punned (void) dest array]] copies the specified number of bits from a value into an sized array More... | |
void | printhex (const uint8_t data, const bool add_newline=true) |
prints uint8_t value in hex format More... | |
void | printhex (const uint16_t data, const bool add_newline=true) |
prints uint16_t value in hex format More... | |
void | printhex (const uint32_t data, const bool add_newline=true) |
prints uint32_t value in hex format More... | |
void | printhex (const uint64_t data, const bool add_newline=true) |
prints uint64_t value in hex format More... | |
void | printhex (const bool data, const bool add_newline=true) |
prints bool value in hex format More... | |
template<typename T = void, typename std::enable_if< std::is_signed< T >::valueBITCPY_INT128_CONDITIONAL_DEFINE(||std::is_same< T, __int128_t >::value), T >::type * = nullptr> | |
void | printhex (const T data, const bool add_newline=true) |
prints signed value in hex format More... | |
template<bool use_brackets = true, typename T = void, size_t N = 0u> | |
void | printhex (const T(&data)[N], const bool add_newline=true) |
prints an array in hex format More... | |
template<bool use_brackets = true, typename T = void, size_t N = 0u> | |
void | printbin (const T(&data)[N], const bool add_newline=true) |
prints an array in binary format More... | |
template<typename T , typename std::enable_if<!std::is_array< T >::value &&!std::is_same< T, bool >::value, T >::type * = nullptr> | |
void | printbin (const T data, const bool add_newline=true) |
prints a non-array non-bool value in binary format More... | |
void | printbin (const bool data, const bool add_newline=true) |
prints a bool value in binary format More... | |
const char * | status2str (status_e err_status) noexcept |
converts an error status enum to a c style string More... | |
void | virtual_formatter (packet &) |
used to initialize a formatter object to be optionally overridable. the default behaviour if not overridden is to do nothing. | |
Variables | |
constexpr void(* | pure_virtual_formatter )(packet &) = nullptr |
used to initialize a formatter object to be required but uninitialized. the default behaviour if not overridden is to give a status_e::FORMATTER_NOT_SET error | |
CppSerdes library namespace.
|
strong |
|
strong |
error status of serialization/deserialization process
Enumerator | |
---|---|
NO_ERROR |
no serialization/deserialization errors occurred |
EXCEEDED_SERIAL_SIZE |
during serialization/deserialization the serial array boundary was reached (causes the serdes process to abort) |
ARRAY_SIZE_OVER_MAX |
the serdes::array object's size exceeded the maximum size of the array when evaluated (causes the serdes process to abort) |
INVALID_FIELD |
a fields validation check failed (causes the serdes process to abort) |
NO_LOAD_TO_RVALUE |
tried to loading data from a serial buffer into a temperary rvalue (causes the serdes process to abort) |
DELIMITER_NOT_FOUND |
the specified delimiter in a delimited_array object was not found before the end of the array (causes the serdes process to abort) |
FORMATTER_NOT_SET |
a pure_virtual_formatter (a.k.a "serdes::formatter(nullptr)") was used but not overriden (causes the serdes process to abort) |
|
noexcept |
Does nothing but annotate a passed value as a bit length, used for writting clearer code.
x | bit length value |
T | the type of the bit length value |
|
noexcept |
[[serialize, uint source]] copies the specified number of bits from a value into an array
[[serialize, signed type source]] copies the specified number of bits from a value into an array
[[serialize, integral value <= 8 bytes source]] copies the specified number of bits from a value into an array
[[serialize, bool source]] copies the specified number of bits from a value into an array
T_array | destination serial array base type |
T_val | source value type |
dest | pointer to the start of the destination serial array |
source | source value reference |
bit_offset | starting bit of the destination array to start copying from |
bits | number of bits to copy from |
|
noexcept |
[[deserialize, uint destination]] copies the specified number of bits from an array into a value
[[deserialize, large non integral type dest]] copies the specified number of bits from an array into a large non integral type value
[[deserialize, signed destination]] copies the specified number of bits from an array into a signed value
[[deserialize, bool destination]] copies the specified number of bits from an array into a boolean value
T_array | serial array base type |
T_val | destination value type |
dest | destination value reference |
source | pointer to the start of the source serial array |
bit_offset | starting bit of the source array to start copying from |
bits | number of bits to copy from |
T_array | serial array base type |
T_val | destination value type, a boolean for this case. |
dest | destination boolean value reference |
source | pointer to the start of the source serial array |
bit_offset | starting bit of the source array to start copying from |
bits | number of bits to copy from |
|
noexcept |
[[deserialize, integral value <= 8 bytes destination]] copies the specified number of bits from an array into a integral value with <= 8 bytes
T_array | serial array base type |
T_val | destination value type |
dest | destination value reference |
source | pointer to the start of the source serial array |
bit_offset | starting bit of the source array to start copying from |
bits | number of bits to copy from |
|
noexcept |
[[serialize, partial sized_pointer source]] copies the specified number of bits from a value into an array (no default bits, since it can't necessarily be known at compile time)
T_array | destination serial array base type |
T_val | source value type |
dest | pointer to the start of the destination serial array |
source | source value reference |
bit_offset | starting bit of the destination array to start copying from |
bits | number of bits to copy from |
|
noexcept |
[[deserialize, partial sized_pointer destination]] copies the specified number of bits from an array into a sized_pointer array (no default bits, since it can't necessarily be known at compile time)
T_array | serial array base type |
T_val | destination value type |
dest | destination value sized_pointer<T_val> reference |
source | pointer to the start of the source serial array |
bit_offset | starting bit of the source array to start copying from |
bits | number of bits to copy from |
|
noexcept |
[[serialize, entire sized_pointer source]] copies the entire sized_pointer object from a value into an array
T_array | destination serial array base type |
T_val | source value type |
dest | pointer to the start of the destination serial array |
source | source value reference |
bit_offset | starting bit of the destination array to start copying from |
|
noexcept |
[[serialize, large non integral type source]] copies the specified number of bits from a value into an array
T_array | destination serial array base type |
T_val | source value type |
dest | pointer to the start of the destination serial array |
source | source value reference |
bit_offset | starting bit of the destination array to start copying from |
bits | number of bits to copy from |
|
noexcept |
[[deserialize, entire sized_pointer destination]] copies the specified number of bits from an array into a sized_pointer array using a bit length equal to the entire bit capacity of the sized_pointer object.
T_array | serial array base type |
T_val | destination value type |
dest | destination value sized_pointer<T_val> reference |
source | pointer to the start of the source serial array |
bit_offset | starting bit of the source array to start copying from |
|
noexcept |
[[serialize, size safe]] copies the specified number of bits from a value into an sized array
T_array | destination serial array base type |
T_val | source value type |
dest | pointer to the start of the destination serial array |
source | source value reference |
bit_offset | starting bit of the destination array to start copying from |
bits | number of bits to copy from |
|
noexcept |
[[serialize, atomic source]] copies the specified number of bits from an atomic value into an sized array
T_array | destination serial array base type |
T_val | source value type |
dest | pointer to the start of the destination serial array |
source | source value reference |
bit_offset | starting bit of the destination array to start copying from |
bits | number of bits to copy from |
|
noexcept |
[[deserialize, size safe]] copies the specified number of bits from an sized_pointer into a value. used to prevent reading beyond the boundary of the source array.
T_array | serial array base type |
T_val | destination value type |
dest | destination value reference |
source | pointer to the start of the source serial array |
bit_offset | starting bit of the source array to start copying from |
bits | number of bits to copy from |
|
noexcept |
[[serialize, size safe, type punned (void) dest array]] copies the specified number of bits from a value into an sized array
T_array | destination serial array base type |
T_val | source value type |
dest | pointer to the start of the destination serial array |
source | source value reference |
bit_offset | starting bit of the destination array to start copying from |
bits | number of bits to copy from |
|
noexcept |
[[deserialize, size safe, pointer dest]] copies the specified number of bits from an sized_pointer into a value. used to prevent reading beyond the boundary of the source array.
T_array | serial array base type |
T_val | destination value type |
dest | destination value reference |
source | pointer to the start of the source serial array |
bit_offset | starting bit of the source array to start copying from |
bits | number of bits to copy from |
|
noexcept |
[[deserialize, atomic dest]] copies the specified number of bits from an array into an atomic value
T_array | serial array base type |
T_val | destination value type |
dest | destination value reference |
source | pointer to the start of the source serial array |
bit_offset | starting bit of the source array to start copying from |
bits | number of bits to copy from |
|
noexcept |
[[deserialize, size safe, type punned (void) source array]] copies the specified number of bits from an array with a runtime determined base type into a value
T_array | serial array base type |
T_val | destination value type |
dest | destination value reference |
source | pointer to the start of the source serial array |
bit_offset | starting bit of the source array to start copying from |
bits | number of bits to copy from |
void serdes::printbin | ( | const T(&) | data[N], |
const bool | add_newline = true |
||
) |
prints an array in binary format
use_brackets | if true, curly brackets will surround the printed statement |
data | value to print |
add_newline | if true, a newline will be added to the end |
void serdes::printbin | ( | const T | data, |
const bool | add_newline = true |
||
) |
prints a non-array non-bool value in binary format
data | value to print |
add_newline | if true, a newline will be added to the end |
|
inline |
prints a bool value in binary format
data | value to print |
add_newline | if true, a newline will be added to the end |
|
inline |
prints uint8_t value in hex format
data | value to print |
add_newline | if true, a newline will be added to the end |
|
inline |
prints uint16_t value in hex format
data | value to print |
add_newline | if true, a newline will be added to the end |
|
inline |
prints uint32_t value in hex format
data | value to print |
add_newline | if true, a newline will be added to the end |
|
inline |
prints uint64_t value in hex format
data | value to print |
add_newline | if true, a newline will be added to the end |
|
inline |
prints bool value in hex format
data | value to print |
add_newline | if true, a newline will be added to the end |
void serdes::printhex | ( | const T | data, |
const bool | add_newline = true |
||
) |
prints signed value in hex format
data | value to print |
add_newline | if true, a newline will be added to the end |
void serdes::printhex | ( | const T(&) | data[N], |
const bool | add_newline = true |
||
) |
prints an array in hex format
use_brackets | if true, curly brackets will surround the printed statement |
data | value to print |
add_newline | if true, a newline will be added to the end |
|
inlinenoexcept |
converts an error status enum to a c style string
err_status | error status enumeration |