omni::structuredlog::BlobReader
Defined in omni/structuredlog/BinarySerializer.h
-
template<bool validate = false, OnBlobWriterValidationErrorFunc onValidationError = ignoreBlobWriterValidationError>
class BlobReader A class to read binary blobs produced by the BlobWriter.
You’ll need some sort of external schema or fixed layout to be able to read the blob.
- Param validate
If this parameter is true, then the read position will be tracked while reading the blob and attempting to read past the end of the buffer will cause methods to fail. Note that a message will not be logged because this class is used in the log system. This is needed for the tests.
Public Functions
-
inline BlobReader(const void *blob, size_t blobSize)
Constructor.
- Parameters
blob – [in] The buffer to read from.
blobSize – [in] The length of
buffer
.
-
template<typename T>
inline bool read(T *out) read a primitive type element out of the buffer.
- Parameters
out – [out] The value will be written to this. This may not be nullptr.
- Returns
true
if the value was successfully read.- Returns
false
if the end of the buffer was reached.
-
inline bool read(const char **out, uint16_t *outLen, uint16_t maxLen)
Read an array of strings out of the buffer.
- Parameters
out – [out] Receives the array of strings from the blob if
maxLen
is not 0. This may be nullptr ifmaxLen
is 0. Note that the strings pointed to will point into the data blob that’s being read from.outLen – [out] Receives the length of the output array. This may not be nullptr.
maxLen – [in] The maximum length that can be read into
out
in this call. If this is set to 0, then the array length with be read intooutLen
and the buffer pointer will not increment to point at the next member, so that an array can be allocated and read in the next call to this function. An exception to this is the case whereoutLen
is set to 0; the buffer pointer will be incremented to point at the next member in this case.
- Returns
true
if the value was successfully read.- Returns
false
if the end of the buffer was reached.
-
template<typename T>
inline bool read(const T **out, uint16_t *outLen) Read a string out of the buffer.
- Parameters
out – [out] Receives the array from the binary blob. This will be pointing to data from within the blob. This may not be nullptr.
outLen – [out] Receives the length of the array that was read. This includes the null terminator if this was as string. This may not be nullptr.
- Returns
true
if the value was successfully read.- Returns
false
if the end of the buffer was reached.
-
template<typename T>
inline bool read(const T **out, uint16_t fixedLen) Read a fixed length array out of the buffer.
- Parameters
out – [out] Receives the array from the binary blob. This will be pointing to data from within the blob. This may not be nullptr.
fixedLen – [out] The fixed length of the array/string. This should not be 0.
- Returns
true
if the value was successfully read.- Returns
false
if the end of the buffer was reached.
-
template<typename T>
inline void alignBuffer() Align the buffer for a given type.
Remark
This will advance the buffer so that the next write is aligned for the specified type.
Public Static Attributes
-
static constexpr uint32_t kVersion = 0
The version of binary blob ABI that this reader was built to read.
Protected Functions
-
inline void outOfMemoryErrorMessage(size_t size)
Send an error message to the onValidationError callback when the end of the buffer has been reached.
- Parameters
size – [in] The size that was requested that would have extended past the end of the buffer.