MIP_SDK
v3.0.0-533-g58dc0c0
MicroStrain Communications Library for embedded systems
|
C++ class representing a view of a MIP packet. More...
#include <mip_packet.hpp>
Classes | |
class | AllocatedField |
class | FieldIterator |
Public Member Functions | |
PacketView (uint8_t *buffer, size_t bufferSize, uint8_t descriptorSet) | |
Create a brand-new MIP packet in the given buffer. More... | |
PacketView (const uint8_t *buffer, size_t length) | |
Initializes a MIP packet from an existing buffer. More... | |
PacketView (const C::mip_packet_view *other) | |
Constructs a C++ PacketRef class from the base C object. More... | |
PacketView (const C::mip_packet_view &other) | |
Constructs a C++ PacketRef class from the base C object. More... | |
PacketView (microstrain::U8ArrayView buffer, uint8_t descriptorSet) | |
Create a new MIP packet in an existing buffer. More... | |
PacketView (microstrain::ConstU8ArrayView buffer) | |
Create a reference to an existing MIP packet. More... | |
bool | isData () const |
const uint8_t * | pointer () const |
const uint8_t * | payloadPointer () const |
Get a pointer to the entire packet data. More... | |
uint8_t | payload (size_t i) const |
Get a pointer to the payload data. More... | |
const uint8_t * | bufferPointer () const |
uint8_t * | bufferPointerWr () |
Returns a writable pointer to the data buffer. More... | |
Serializer | createField (uint8_t fieldDescriptor, uint8_t length) |
microstrain::ConstU8ArrayView | data () const |
Gets a const byte view for the whole packet. More... | |
microstrain::ConstU8ArrayView | payload () const |
Gets a const byte view of just the payload. More... | |
microstrain::ConstU8ArrayView | buffer () const |
Gets a const view to the entire storage buffer (usually more than just the packet). More... | |
microstrain::U8ArrayView | bufferWr () |
Gets a writeable view to the entire storage buffer (usually more than just the packet). More... | |
bool | addField (const FieldView &field) |
Copies the given mip field to the packet. More... | |
bool | addField (uint8_t fieldDescriptor, microstrain::ConstU8ArrayView payload) |
Creates a mip field with the given descriptor and copies the given payload. More... | |
AllocatedField | createField (uint8_t fieldDescriptor) |
uint8_t | operator[] (unsigned int index) const |
FieldIterator | begin () const |
FieldIterator | end () const |
FieldView | firstField () const |
Returns the first field in the packet. More... | |
template<class FieldType > | |
bool | addField (const FieldType &field, uint8_t fieldDescriptor=INVALID_FIELD_DESCRIPTOR) |
Adds a field of the given type to the packet. More... | |
bool | copyPacketTo (microstrain::U8ArrayView buffer) const |
Copies this packet to an external buffer (span version). More... | |
Static Public Member Functions | |
template<class FieldType > | |
static PacketView | createFromField (microstrain::ConstU8ArrayView packetBuffer, const FieldType &field, uint8_t fieldDescriptor=INVALID_FIELD_DESCRIPTOR) |
Creates a new PacketRef containing a single MIP field from an instance of the field type. More... | |
Static Public Attributes | |
static constexpr size_t | PAYLOAD_LENGTH_MAX = C::MIP_PACKET_PAYLOAD_LENGTH_MAX |
static constexpr size_t | PACKET_SIZE_MIN = C::MIP_PACKET_LENGTH_MIN |
static constexpr size_t | PACKET_SIZE_MAX = C::MIP_PACKET_LENGTH_MAX |
C++ class representing a view of a MIP packet.
This is a thin wrapper around the mip_packet_view C structure. Like the C version, it does not contain or own the data buffer. Any of the C functions can be used with the C++ packet class because it inherits from the C struct.
Fields may be iterated over using the C-style methods, with an iterator, or with a range-based for loop:
|
inline |
Create a brand-new MIP packet in the given buffer.
Use this along with the packet building functions to create MIP packets.
packet | |
buffer | This is where the packet bytes will be stored. Must be at least MIP_PACKET_LENGTH_MIN bytes in size. |
buffer_size | The size of buffer, in bytes. |
descriptor_set | The MIP descriptor set for the packet. |
|
inline |
Initializes a MIP packet from an existing buffer.
Use this when receiving or parsing MIP packets.
The data in the buffer should be a valid or suspected MIP packet.
packet | |
buffer | The data buffer containing the bytes for a MIP packet. Must be at least MIP_PACKET_LENGTH_MIN bytes in size. |
length | The length of the data pointed to by buffer. |
|
inline |
Constructs a C++ PacketRef class from the base C object.
|
inline |
Constructs a C++ PacketRef class from the base C object.
|
inline |
Create a new MIP packet in an existing buffer.
buffer | Place to store the MIP packet bytes. |
descriptorSet | Initializes the packet to this descriptor set. |
|
inline |
Create a reference to an existing MIP packet.
buffer | Buffer containing an existing MIP packet. |
|
inline |
Adds a field of the given type to the packet.
FieldType | Any field class from a file in the mip/definitions directory. |
field | Instance of the field to add to the packet. |
fieldDescriptor | If specified, overrides the field descriptor. |
|
inline |
Copies the given mip field to the packet.
|
inline |
Creates a mip field with the given descriptor and copies the given payload.
|
inline |
Returns a forward iterator to the first field in the packet.
|
inline |
Gets a const view to the entire storage buffer (usually more than just the packet).
|
inline |
|
inline |
Returns a writable pointer to the data buffer.
|
inline |
Gets a writeable view to the entire storage buffer (usually more than just the packet).
|
inline |
Copies this packet to an external buffer (span version).
This packet must be sane (see isSane()). Undefined behavior otherwise due to lookup of totalLength().
buffer | Data is copied to this buffer. |
|
inline |
|
inline |
|
inlinestatic |
Creates a new PacketRef containing a single MIP field from an instance of the field type.
This works just like the addField<FieldType>() function but also initializes and finalizes the packet. It is assumed that the field will fit in an empty packet; otherwise the field can't ever be used. The field classes are predefined so this doesn't need runtime checking.
FieldType | Any field class from a file in the mip/definitions directory. |
packetBuffer | Buffer to hold the packet bytes. |
field | Instance of the field to add to the packet. |
fieldDescriptor | If specified, overrides the field descriptor. |
|
inline |
Gets a const byte view for the whole packet.
|
inline |
Returns a sentry object representing the end of fields in the packet.
|
inline |
Returns the first field in the packet.
Subsequent fields can be obtained via the returned Field class, but iteration is best done with begin()/end() or the range-based for loop.
|
inline |
|
inline |
|
inline |
Gets a const byte view of just the payload.
|
inline |
Get a pointer to the payload data.
|
inline |
Get a pointer to the entire packet data.
|
inline |
|
staticconstexpr |
|
staticconstexpr |
|
staticconstexpr |