Class CdrSizeCalculator

Class Documentation

class CdrSizeCalculator

This class offers an interface to calculate the encoded size of a type serialized using a support encoding algorithm.

Public Functions

Cdr_DllAPI CdrSizeCalculator(CdrVersion cdr_version)

Constructor.

Parameters:

cdr_version[in] Represents the version of the encoding algorithm that will be used for the encoding. The default value is CdrVersion::XCDRv2.

Cdr_DllAPI CdrSizeCalculator(CdrVersion cdr_version, EncodingAlgorithmFlag encoding)

Constructor.

Parameters:
  • cdr_version[in] Represents the version of the encoding algorithm that will be used for the encoding. The default value is CdrVersion::XCDRv2.

  • encoding[in] Represents the initial encoding.

Cdr_DllAPI CdrVersion get_cdr_version () const

Retrieves the version of the encoding algorithm used by the instance.

Returns:

Configured CdrVersion.

Cdr_DllAPI EncodingAlgorithmFlag get_encoding () const

Retrieves the current encoding algorithm used by the instance.

Returns:

Configured EncodingAlgorithmFlag.

template<class _T, typename std::enable_if<!std::is_enum<_T>::value>::type* = nullptr, typename = void>
inline size_t calculate_serialized_size(const _T &data, size_t &current_alignment)

Generic template which calculates the encoded size of an instance of an unknown type.

Template Parameters:

_T – Instance’s type.

Parameters:
  • data[in] Reference to the instance.

  • current_alignment[inout] Current alignment in the encoding.

Returns:

Encoded size of the instance.

template<class _T, typename std::enable_if<std::is_enum<_T>::value>::type* = nullptr, typename std::enable_if<std::is_same<typename std::underlying_type<_T>::type, int32_t>::value>::type* = nullptr>
inline size_t calculate_serialized_size(const _T &data, size_t &current_alignment)

Template which calculates the encoded size of an instance of an enumeration of 32bits.

Template Parameters:

_T – Instance’s type.

Parameters:
  • data[in] Reference to the instance.

  • current_alignment[inout] Current alignment in the encoding.

Returns:

Encoded size of the instance.

template<class _T, typename std::enable_if<std::is_enum<_T>::value>::type* = nullptr, typename std::enable_if<std::is_same<typename std::underlying_type<_T>::type, uint32_t>::value>::type* = nullptr>
inline size_t calculate_serialized_size(const _T &data, size_t &current_alignment)

Template which calculates the encoded size of an instance of an enumeration of unsigned 32bits.

Template Parameters:

_T – Instance’s type.

Parameters:
  • data[in] Reference to the instance.

  • current_alignment[inout] Current alignment in the encoding.

Returns:

Encoded size of the instance.

template<class _T, typename std::enable_if<std::is_enum<_T>::value>::type* = nullptr, typename std::enable_if<std::is_same<typename std::underlying_type<_T>::type, int16_t>::value>::type* = nullptr>
inline size_t calculate_serialized_size(const _T &data, size_t &current_alignment)

Template which calculates the encoded size of an instance of an enumeration of 16bits.

Template Parameters:

_T – Instance’s type.

Parameters:
  • data[in] Reference to the instance.

  • current_alignment[inout] Current alignment in the encoding.

Returns:

Encoded size of the instance.

template<class _T, typename std::enable_if<std::is_enum<_T>::value>::type* = nullptr, typename std::enable_if<std::is_same<typename std::underlying_type<_T>::type, uint16_t>::value>::type* = nullptr>
inline size_t calculate_serialized_size(const _T &data, size_t &current_alignment)

Template which calculates the encoded size of an instance of an enumeration of unsigned 16bits.

Template Parameters:

_T – Instance’s type.

Parameters:
  • data[in] Reference to the instance.

  • current_alignment[inout] Current alignment in the encoding.

Returns:

Encoded size of the instance.

template<class _T, typename std::enable_if<std::is_enum<_T>::value>::type* = nullptr, typename std::enable_if<std::is_same<typename std::underlying_type<_T>::type, int8_t>::value>::type* = nullptr>
inline size_t calculate_serialized_size(const _T &data, size_t &current_alignment)

Template which calculates the encoded size of an instance of an enumeration of 8bits.

Template Parameters:

_T – Instance’s type.

Parameters:
  • data[in] Reference to the instance.

  • current_alignment[inout] Current alignment in the encoding.

Returns:

Encoded size of the instance.

template<class _T, typename std::enable_if<std::is_enum<_T>::value>::type* = nullptr, typename std::enable_if<std::is_same<typename std::underlying_type<_T>::type, uint8_t>::value>::type* = nullptr>
inline size_t calculate_serialized_size(const _T &data, size_t &current_alignment)

Template which calculates the encoded size of an instance of an enumeration of unsigned 8bits.

Template Parameters:

_T – Instance’s type.

Parameters:
  • data[in] Reference to the instance.

  • current_alignment[inout] Current alignment in the encoding.

Returns:

Encoded size of the instance.

inline TEMPLATE_SPEC size_t calculate_serialized_size (const int8_t &data, size_t &current_alignment)

Specific template which calculates the encoded size of an instance of an int8_t.

Parameters:
  • data[in] Reference to the instance.

  • current_alignment[inout] Current alignment in the encoding.

Returns:

Encoded size of the instance.

inline TEMPLATE_SPEC size_t calculate_serialized_size (const uint8_t &data, size_t &current_alignment)

Specific template which calculates the encoded size of an instance of an uint8_t.

Parameters:
  • data[in] Reference to the instance.

  • current_alignment[inout] Current alignment in the encoding.

Returns:

Encoded size of the instance.

inline TEMPLATE_SPEC size_t calculate_serialized_size (const char &data, size_t &current_alignment)

Specific template which calculates the encoded size of an instance of a char.

Parameters:
  • data[in] Reference to the instance.

  • current_alignment[inout] Current alignment in the encoding.

Returns:

Encoded size of the instance.

inline TEMPLATE_SPEC size_t calculate_serialized_size (const bool &data, size_t &current_alignment)

Specific template which calculates the encoded size of an instance of a bool.

Parameters:
  • data[in] Reference to the instance.

  • current_alignment[inout] Current alignment in the encoding.

Returns:

Encoded size of the instance.

inline TEMPLATE_SPEC size_t calculate_serialized_size (const wchar_t &data, size_t &current_alignment)

Specific template which calculates the encoded size of an instance of a wchar.

Parameters:
  • data[in] Reference to the instance.

  • current_alignment[inout] Current alignment in the encoding.

Returns:

Encoded size of the instance.

inline TEMPLATE_SPEC size_t calculate_serialized_size (const int16_t &data, size_t &current_alignment)

Specific template which calculates the encoded size of an instance of a int16_t.

Parameters:
  • data[in] Reference to the instance.

  • current_alignment[inout] Current alignment in the encoding.

Returns:

Encoded size of the instance.

inline TEMPLATE_SPEC size_t calculate_serialized_size (const uint16_t &data, size_t &current_alignment)

Specific template which calculates the encoded size of an instance of a uint16_t.

Parameters:
  • data[in] Reference to the instance.

  • current_alignment[inout] Current alignment in the encoding.

Returns:

Encoded size of the instance.

inline TEMPLATE_SPEC size_t calculate_serialized_size (const int32_t &data, size_t &current_alignment)

Specific template which calculates the encoded size of an instance of a int32_t.

Parameters:
  • data[in] Reference to the instance.

  • current_alignment[inout] Current alignment in the encoding.

Returns:

Encoded size of the instance.

inline TEMPLATE_SPEC size_t calculate_serialized_size (const uint32_t &data, size_t &current_alignment)

Specific template which calculates the encoded size of an instance of a uint32_t.

Parameters:
  • data[in] Reference to the instance.

  • current_alignment[inout] Current alignment in the encoding.

Returns:

Encoded size of the instance.

inline TEMPLATE_SPEC size_t calculate_serialized_size (const int64_t &data, size_t &current_alignment)

Specific template which calculates the encoded size of an instance of a int64_t.

Parameters:
  • data[in] Reference to the instance.

  • current_alignment[inout] Current alignment in the encoding.

Returns:

Encoded size of the instance.

inline TEMPLATE_SPEC size_t calculate_serialized_size (const uint64_t &data, size_t &current_alignment)

Specific template which calculates the encoded size of an instance of a uint64_t.

Parameters:
  • data[in] Reference to the instance.

  • current_alignment[inout] Current alignment in the encoding.

Returns:

Encoded size of the instance.

inline TEMPLATE_SPEC size_t calculate_serialized_size (const float &data, size_t &current_alignment)

Specific template which calculates the encoded size of an instance of a float.

Parameters:
  • data[in] Reference to the instance.

  • current_alignment[inout] Current alignment in the encoding.

Returns:

Encoded size of the instance.

inline TEMPLATE_SPEC size_t calculate_serialized_size (const double &data, size_t &current_alignment)

Specific template which calculates the encoded size of an instance of a double.

Parameters:
  • data[in] Reference to the instance.

  • current_alignment[inout] Current alignment in the encoding.

Returns:

Encoded size of the instance.

inline TEMPLATE_SPEC size_t calculate_serialized_size (const long double &data, size_t &current_alignment)

Specific template which calculates the encoded size of an instance of a long double.

Parameters:
  • data[in] Reference to the instance.

  • current_alignment[inout] Current alignment in the encoding.

Returns:

Encoded size of the instance.

inline TEMPLATE_SPEC size_t calculate_serialized_size (const std::string &data, size_t &current_alignment)

Specific template which calculates the encoded size of an instance of a std::string.

Parameters:
  • data[in] Reference to the instance.

  • current_alignment[inout] Current alignment in the encoding.

Returns:

Encoded size of the instance.

inline TEMPLATE_SPEC size_t calculate_serialized_size (const std::wstring &data, size_t &current_alignment)

Specific template which calculates the encoded size of an instance of a std::wstring.

Parameters:
  • data[in] Reference to the instance.

  • current_alignment[inout] Current alignment in the encoding.

Returns:

Encoded size of the instance.

template<size_t MAX_CHARS>
inline size_t calculate_serialized_size(const fixed_string<MAX_CHARS> &data, size_t &current_alignment)

Specific template which calculates the encoded size of an instance of a fixed_string.

Parameters:
  • data[in] Reference to the instance.

  • current_alignment[inout] Current alignment in the encoding.

Returns:

Encoded size of the instance.

template<class _T, typename std::enable_if<!std::is_enum<_T>::value && !std::is_arithmetic<_T>::value>::type* = nullptr>
inline size_t calculate_serialized_size(const std::vector<_T> &data, size_t &current_alignment)

Specific template which calculates the encoded size of an instance of a sequence of non-primitives.

Parameters:
  • data[in] Reference to the instance.

  • current_alignment[inout] Current alignment in the encoding.

Returns:

Encoded size of the instance.

template<class _T, typename std::enable_if<std::is_enum<_T>::value || std::is_arithmetic<_T>::value>::type* = nullptr>
inline size_t calculate_serialized_size(const std::vector<_T> &data, size_t &current_alignment)

Specific template which calculates the encoded size of an instance of a sequence of primitives.

Parameters:
  • data[in] Reference to the instance.

  • current_alignment[inout] Current alignment in the encoding.

Returns:

Encoded size of the instance.

inline TEMPLATE_SPEC size_t calculate_serialized_size (const std::vector< bool > &data, size_t &current_alignment)

Specific template which calculates the encoded size of an instance of a sequence of bool.

Parameters:
  • data[in] Reference to the instance.

  • current_alignment[inout] Current alignment in the encoding.

Returns:

Encoded size of the instance.

template<class _T, size_t _Size>
inline size_t calculate_serialized_size(const std::array<_T, _Size> &data, size_t &current_alignment)

Specific template which calculates the encoded size of an instance of an array.

Parameters:
  • data[in] Reference to the instance.

  • current_alignment[inout] Current alignment in the encoding.

Returns:

Encoded size of the instance.

template<class _K, class _V, typename std::enable_if<!std::is_enum<_V>::value && !std::is_arithmetic<_V>::value>::type* = nullptr>
inline size_t calculate_serialized_size(const std::map<_K, _V> &data, size_t &current_alignment)

Specific template which calculates the encoded size of an instance of a map of non-primitives.

Parameters:
  • data[in] Reference to the instance.

  • current_alignment[inout] Current alignment in the encoding.

Returns:

Encoded size of the instance.

template<class _K, class _V, typename std::enable_if<std::is_enum<_V>::value || std::is_arithmetic<_V>::value>::type* = nullptr>
inline size_t calculate_serialized_size(const std::map<_K, _V> &data, size_t &current_alignment)

Specific template which calculates the encoded size of an instance of a map of primitives.

Parameters:
  • data[in] Reference to the instance.

  • current_alignment[inout] Current alignment in the encoding.

Returns:

Encoded size of the instance.

template<size_t N, typename std::enable_if<(N < 9)>::type* = nullptr>
inline size_t calculate_serialized_size(const std::bitset<N> &data, size_t &current_alignment)

Specific template which calculates the encoded size of an instance of a bitset of 8bits.

Parameters:
  • data[in] Reference to the instance.

  • current_alignment[inout] Current alignment in the encoding.

Returns:

Encoded size of the instance.

template<size_t N, typename std::enable_if<(8 < N && N < 17)>::type* = nullptr>
inline size_t calculate_serialized_size(const std::bitset<N> &data, size_t &current_alignment)

Specific template which calculates the encoded size of an instance of a bitset of 16bits.

Parameters:
  • data[in] Reference to the instance.

  • current_alignment[inout] Current alignment in the encoding.

Returns:

Encoded size of the instance.

template<size_t N, typename std::enable_if<(16 < N && N < 33)>::type* = nullptr>
inline size_t calculate_serialized_size(const std::bitset<N> &data, size_t &current_alignment)

Specific template which calculates the encoded size of an instance of a bitset of 32bits.

Parameters:
  • data[in] Reference to the instance.

  • current_alignment[inout] Current alignment in the encoding.

Returns:

Encoded size of the instance.

template<size_t N, typename std::enable_if<(32 < N && N < 65)>::type* = nullptr>
inline size_t calculate_serialized_size(const std::bitset<N> &data, size_t &current_alignment)

Specific template which calculates the encoded size of an instance of a bitset of 64bits.

Parameters:
  • data[in] Reference to the instance.

  • current_alignment[inout] Current alignment in the encoding.

Returns:

Encoded size of the instance.

template<class _T>
inline size_t calculate_serialized_size(const optional<_T> &data, size_t &current_alignment)

Specific template which calculates the encoded size of an instance of an optional type.

Parameters:
  • data[in] Reference to the instance.

  • current_alignment[inout] Current alignment in the encoding.

Returns:

Encoded size of the instance.

template<class _T>
inline size_t calculate_serialized_size(const external<_T> &data, size_t &current_alignment)

Specific template which calculates the encoded size of an instance of an external type.

Parameters:
  • data[in] Reference to the instance.

  • current_alignment[inout] Current alignment in the encoding.

Throws:

exception::BadParamException – This exception is thrown when the external is null.

Returns:

Encoded size of the instance.

template<class _T>
inline size_t calculate_array_serialized_size(const _T *data, size_t num_elements, size_t &current_alignment)

Specific template which calculates the encoded size of an instance of an array of unknown type.

Template Parameters:

_T – Array’s type.

Parameters:
  • data[in] Reference to the array’s instance.

  • num_elements[in] Number of elements in the array.

  • current_alignment[inout] Current alignment in the encoding.

Returns:

Encoded size of the instance.

inline TEMPLATE_SPEC size_t calculate_array_serialized_size (const int8_t *data, size_t num_elements, size_t &current_alignment)

Specific template which calculates the encoded size of an instance of an array of int8_t.

Parameters:
  • data[in] Reference to the array’s instance.

  • num_elements[in] Number of elements in the array.

  • current_alignment[inout] Current alignment in the encoding.

Returns:

Encoded size of the instance.

inline TEMPLATE_SPEC size_t calculate_array_serialized_size (const uint8_t *data, size_t num_elements, size_t &current_alignment)

Specific template which calculates the encoded size of an instance of an array of uint8_t.

Parameters:
  • data[in] Reference to the array’s instance.

  • num_elements[in] Number of elements in the array.

  • current_alignment[inout] Current alignment in the encoding.

Returns:

Encoded size of the instance.

inline TEMPLATE_SPEC size_t calculate_array_serialized_size (const char *data, size_t num_elements, size_t &current_alignment)

Specific template which calculates the encoded size of an instance of an array of char.

Parameters:
  • data[in] Reference to the array’s instance.

  • num_elements[in] Number of elements in the array.

  • current_alignment[inout] Current alignment in the encoding.

Returns:

Encoded size of the instance.

inline TEMPLATE_SPEC size_t calculate_array_serialized_size (const wchar_t *data, size_t num_elements, size_t &current_alignment)

Specific template which calculates the encoded size of an instance of an array of wchar.

Parameters:
  • data[in] Reference to the array’s instance.

  • num_elements[in] Number of elements in the array.

  • current_alignment[inout] Current alignment in the encoding.

Returns:

Encoded size of the instance.

inline TEMPLATE_SPEC size_t calculate_array_serialized_size (const int16_t *data, size_t num_elements, size_t &current_alignment)

Specific template which calculates the encoded size of an instance of an array of int16_t.

Parameters:
  • data[in] Reference to the array’s instance.

  • num_elements[in] Number of elements in the array.

  • current_alignment[inout] Current alignment in the encoding.

Returns:

Encoded size of the instance.

inline TEMPLATE_SPEC size_t calculate_array_serialized_size (const uint16_t *data, size_t num_elements, size_t &current_alignment)

Specific template which calculates the encoded size of an instance of an array of uint16_t.

Parameters:
  • data[in] Reference to the array’s instance.

  • num_elements[in] Number of elements in the array.

  • current_alignment[inout] Current alignment in the encoding.

Returns:

Encoded size of the instance.

inline TEMPLATE_SPEC size_t calculate_array_serialized_size (const int32_t *data, size_t num_elements, size_t &current_alignment)

Specific template which calculates the encoded size of an instance of an array of int32_t.

Parameters:
  • data[in] Reference to the array’s instance.

  • num_elements[in] Number of elements in the array.

  • current_alignment[inout] Current alignment in the encoding.

Returns:

Encoded size of the instance.

inline TEMPLATE_SPEC size_t calculate_array_serialized_size (const uint32_t *data, size_t num_elements, size_t &current_alignment)

Specific template which calculates the encoded size of an instance of an array of uint32_t.

Parameters:
  • data[in] Reference to the array’s instance.

  • num_elements[in] Number of elements in the array.

  • current_alignment[inout] Current alignment in the encoding.

Returns:

Encoded size of the instance.

inline TEMPLATE_SPEC size_t calculate_array_serialized_size (const int64_t *data, size_t num_elements, size_t &current_alignment)

Specific template which calculates the encoded size of an instance of an array of int64_t.

Parameters:
  • data[in] Reference to the array’s instance.

  • num_elements[in] Number of elements in the array.

  • current_alignment[inout] Current alignment in the encoding.

Returns:

Encoded size of the instance.

inline TEMPLATE_SPEC size_t calculate_array_serialized_size (const uint64_t *data, size_t num_elements, size_t &current_alignment)

Specific template which calculates the encoded size of an instance of an array of uint64_t.

Parameters:
  • data[in] Reference to the array’s instance.

  • num_elements[in] Number of elements in the array.

  • current_alignment[inout] Current alignment in the encoding.

Returns:

Encoded size of the instance.

inline TEMPLATE_SPEC size_t calculate_array_serialized_size (const float *data, size_t num_elements, size_t &current_alignment)

Specific template which calculates the encoded size of an instance of an array of float.

Parameters:
  • data[in] Reference to the array’s instance.

  • num_elements[in] Number of elements in the array.

  • current_alignment[inout] Current alignment in the encoding.

Returns:

Encoded size of the instance.

inline TEMPLATE_SPEC size_t calculate_array_serialized_size (const double *data, size_t num_elements, size_t &current_alignment)

Specific template which calculates the encoded size of an instance of an array of double.

Parameters:
  • data[in] Reference to the array’s instance.

  • num_elements[in] Number of elements in the array.

  • current_alignment[inout] Current alignment in the encoding.

Returns:

Encoded size of the instance.

inline TEMPLATE_SPEC size_t calculate_array_serialized_size (const long double *data, size_t num_elements, size_t &current_alignment)

Specific template which calculates the encoded size of an instance of an array of long double.

Parameters:
  • data[in] Reference to the array’s instance.

  • num_elements[in] Number of elements in the array.

  • current_alignment[inout] Current alignment in the encoding.

Returns:

Encoded size of the instance.

template<class _T, size_t _N>
inline size_t calculate_array_serialized_size(const std::array<_T, _N> *data, size_t num_elements, size_t &current_alignment)

Specific template which calculates the encoded size of an instance of a multi-dimensional array.

Parameters:
  • data[in] Reference to the array’s instance.

  • num_elements[in] Number of elements in the array.

  • current_alignment[inout] Current alignment in the encoding.

Returns:

Encoded size of the instance.

template<class _T, typename std::enable_if<std::is_enum<_T>::value || std::is_arithmetic<_T>::value>::type* = nullptr>
inline size_t calculate_array_serialized_size(const std::vector<_T> &data, size_t &current_alignment)

Specific template which calculates the encoded size of an std::vector of primitives as an array.

Parameters:
  • data[in] Reference to the instance.

  • current_alignment[inout] Current alignment in the encoding.

Returns:

Encoded size of the instance.

template<class _T, typename std::enable_if<!std::is_enum<_T>::value && !std::is_arithmetic<_T>::value>::type* = nullptr>
inline size_t calculate_array_serialized_size(const std::vector<_T> &data, size_t &current_alignment)

Specific template which calculates the encoded size of an std::vector of non-primitives as an array.

Parameters:
  • data[in] Reference to the instance.

  • current_alignment[inout] Current alignment in the encoding.

Returns:

Encoded size of the instance.

inline TEMPLATE_SPEC size_t calculate_array_serialized_size (const std::vector< bool > &data, size_t &current_alignment)

Specific template which calculates the encoded size of an std::vector of bool as an array.

Parameters:
  • data[in] Reference to the instance.

  • current_alignment[inout] Current alignment in the encoding.

Returns:

Encoded size of the instance.

template<class _T>
inline size_t calculate_member_serialized_size(const MemberId &id, const _T &data, size_t &current_alignment)

Generic template which calculates the encoded size of the constructed type’s member of a unknown type.

Template Parameters:

_T – Member’s type.

Parameters:
  • id[in] Member’s identifier.

  • data[in] Reference to the member’s instance.

  • current_alignment[inout] Current alignment in the encoding.

Returns:

Encoded size of the member’s instance.

template<class _T>
inline size_t calculate_member_serialized_size(const MemberId &id, const optional<_T> &data, size_t &current_alignment)

Generic template which calculates the encoded size of the constructed type’s member of type optional.

Template Parameters:

_T – Member’s optional type.

Parameters:
  • id[in] Member’s identifier.

  • data[in] Reference to the member’s instance.

  • current_alignment[inout] Current alignment in the encoding.

Returns:

Encoded size of the member’s instance.

Cdr_DllAPI size_t begin_calculate_type_serialized_size (EncodingAlgorithmFlag new_encoding, size_t &current_alignment)

Indicates a new constructed type will be calculated.

Parameters:
  • new_encoding[in] New encoding algorithm used for the constructed type.

  • current_alignment[inout] Current alignment in the encoding.

Returns:

If new encoding algorithm encodes a header, return the encoded size of it.

Cdr_DllAPI size_t end_calculate_type_serialized_size (EncodingAlgorithmFlag new_encoding, size_t &current_alignment)

Indicates the ending of a constructed type.

Parameters:
  • new_encoding[in] New encoding algorithm used after the constructed type.

  • current_alignment[inout] Current alignment in the encoding.

Returns:

If current encoding algorithm encodes a final mark, return the encoded size of it.