omni::structuredlog::BinaryBlobSizeCalculator

Defined in omni/structuredlog/BinarySerializer.h

class BinaryBlobSizeCalculator

A helper class to calculate the required size of a binary blob.

To use this, just track all of the data that you want to insert into your binary blob.

Public Functions

inline size_t getSize()

Retrieve the tracked blob size.

Returns

The memory size that is needed to store this blob.

template<typename T>
inline void track(T v)

Track a primitive type.

Parameters

v[in] The value to track. The actual value doesn’t matter; only the type matters.

template<typename T>
inline void track(T *v, uint16_t len)

Track an array type.

Parameters
  • v[in] The array of values to track. This may also be a string.

  • len[in] The number of elements in array v. If this is a string, this length includes the null terminator.

inline void track(const StringView &v)

Track a StringView.

Parameters

v[in] The string view to track.

inline void track(StringView &v)

Track a StringView.

Parameters

v[in] The string view to track.

inline void track(const char *const *v, const uint16_t *stringLengths, uint16_t len)

Track an array of strings into the buffer with pre-calculated lengths.

Note

This overload exists to avoid having to perform a strlen() on each string in the array twice (once when calculating the buffer size and once when writing the buffer).

Parameters
  • v[in] The array of strings to track. This may not be nullptr. The elements of this array may be nullptr; each element of this must be a null terminated string otherwise.

  • stringLengths[in] The length of each string in v. These length must include the null terminator of the string. This may not be nullptr.

  • len[in] The number of elements in array v and array stringLengths.

Returns

true if the value was successfully written.

Returns

false if the blob ran out of buffer space.

inline void track(const char *const *v, uint16_t len)

Track an array of strings type.

Parameters
  • v[in] The array of strings to track. This may not be nullptr. The elements of this array may be nullptr; each element of this must be a null terminated string otherwise.

  • len[in] The number of elements in array v.

template<typename T>
inline void trackFixed(T *v, uint16_t len)

Track an array of fixed size.

Parameters
  • v[in] The array of values to track. This may also be a string.

  • len[in] The fixed length of this data array as specified by the data schema. This can be larger than v.

Public Static Functions

template<typename T>
static inline size_t alignOffset(size_t offset)

Round an offset up to be aligned for a given type.

Parameters

offset[in] The offset to align.

Returns

offset rounded up to be aligned for the specified type.

Public Static Attributes

static constexpr uint32_t kVersion = 0

The version of binary blob ABI Headers that use these binary blobs should static assert on its version.

Do not modify the layout of the binary blob without incrementing this.