MIP_SDK  latest-2-g34f3e39
MicroStrain Communications Library for embedded systems
Public Member Functions | Static Public Attributes | List of all members
microstrain::Serializer< E > Class Template Reference

Serializes or deserializes data to/from a byte buffer. More...

#include <serializer.hpp>

Inheritance diagram for microstrain::Serializer< E >:
microstrain::SerializerBase mip::PacketView::AllocatedField

Public Member Functions

template<typename... Ts>
bool insert (const Ts &... values)
 Serializes one or more values. More...
 
template<typename... Ts>
bool extract (Ts &... values)
 Deserializes one or more values. More...
 
template<class T , class S >
bool extract_count (T &count, S max_count)
 Deserializes an integer with maximum permissible value. More...
 
template<class T , class S >
bool extract_count (T *count, S max_count)
 
 SerializerBase ()=default
 
 SerializerBase (uint8_t *ptr, size_t capacity, size_t offset=0)
 
 SerializerBase (const uint8_t *ptr, size_t size, size_t offset=0)
 
 SerializerBase (microstrain::Span< const uint8_t > buffer, size_t offset=0)
 
- Public Member Functions inherited from microstrain::SerializerBase
 SerializerBase ()=default
 
 SerializerBase (uint8_t *ptr, size_t capacity, size_t offset=0)
 
 SerializerBase (const uint8_t *ptr, size_t size, size_t offset=0)
 
 SerializerBase (microstrain::Span< const uint8_t > buffer, size_t offset=0)
 
uint8_t * getPointer (size_t required_size)
 Obtains a pointer to the current offset for reading/writing a value of the specified size. This function does NOT advance the offset value. Generally, you should use getPtrAndAdvance() instead. More...
 
uint8_t * getPtrAndAdvance (size_t size)
 Obtains a pointer to the current offset for reading/writing a value of specified size, and post-increments the offset by that size. Use this function just like pointer(). More...
 
void invalidate ()
 Marks the buffer as invalid, i.e. overrun/error state. All further accesses via pointer(), getPtrAndAdvance(), etc. will fail. (basePointer() and capacity() remain valid) More...
 
size_t setOffset (size_t offset)
 Sets a new offset and returns the old value. This can be used to save/restore the current offset. Calling setOffset() after an overrun with an in-range (i.e. non-overrun) value restores the non-overrun status. More...
 

Static Public Attributes

static const serialization::Endian ENDIAN = E
 

Detailed Description

template<serialization::Endian E>
class microstrain::Serializer< E >

Serializes or deserializes data to/from a byte buffer.

Create one of these to handle serialization or deserialization of one or more values to/from a buffer of bytes.

You can use this->insert/extract or directly call the insert/extract non- member functions taking a serializer reference.

The endianness is included as part of the Serializer's type so that it doesn't have to be repeatedly re-specified. It is not included as a runtime parameter for performance reasons (most of the time only a buffer of a known, specific endianness is required).

Template Parameters
EEndianness of the target buffer.

Member Function Documentation

◆ extract()

template<serialization::Endian E>
template<typename... Ts>
bool microstrain::Serializer< E >::extract ( Ts &...  values)

Deserializes one or more values.

This function defers to the non-member function microstrain::extract. By doing so, it allows the user to provide custom overloads for their own types. Any type supported by the non-member functions may be used here.

Template Parameters
TsTypes of values to deserialize.
Parameters
[out]valuesOne or more parameters to deserialize.
Returns
True if all values were successfully read.

◆ extract_count() [1/2]

template<serialization::Endian E>
template<class T , class S >
bool microstrain::Serializer< E >::extract_count ( T &  count,
max_count 
)

Deserializes an integer with maximum permissible value.

This function is intended to be used with protocols which have embedded length fields. This function returns false and invalidates the serializer if the count is too large.

Template Parameters
TType of value to read. Expected to be integer-like and must support bool operator<=(S).
SType of the maximum value. Usually the same integral type as T, but the only requirement is that it can be compared with T.
Parameters
[out]countValue read from the buffer. Set to 0 on failure.
max_countMaximum permissible value for count (inclusive).
Returns
True if the count was successfully read and is less than or equal to max_count.

◆ extract_count() [2/2]

template<serialization::Endian E>
template<class T , class S >
bool microstrain::Serializer< E >::extract_count ( T *  count,
max_count 
)
inline

◆ insert()

template<serialization::Endian E>
template<typename... Ts>
bool microstrain::Serializer< E >::insert ( const Ts &...  values)

Serializes one or more values.

This function defers to the non-member function microstrain::insert. By doing so, it allows the user to provide custom overloads for their own types. Any type supported by the non-member functions may be used here.

Template Parameters
TsTypes of values to serialize.
Parameters
valuesOne or more parameters to serialize.
Returns
True if all values were successfully written.

◆ SerializerBase() [1/4]

template<serialization::Endian E>
microstrain::SerializerBase::SerializerBase
default

◆ SerializerBase() [2/4]

template<serialization::Endian E>
microstrain::SerializerBase::SerializerBase
inline

◆ SerializerBase() [3/4]

template<serialization::Endian E>
microstrain::SerializerBase::SerializerBase
inline

◆ SerializerBase() [4/4]

template<serialization::Endian E>
microstrain::SerializerBase::SerializerBase
inline

Member Data Documentation

◆ ENDIAN

template<serialization::Endian E>
const serialization::Endian microstrain::Serializer< E >::ENDIAN = E
static

The documentation for this class was generated from the following file: