MIP_SDK  latest-2-g34f3e39
MicroStrain Communications Library for embedded systems
Public Member Functions | List of all members
mip::SizedPacketBuf< BufferSize > Class Template Reference

A mip packet with a self-contained buffer (useful with std::vector). More...

#include <mip_packet.hpp>

Inheritance diagram for mip::SizedPacketBuf< BufferSize >:
mip::PacketView mip::C::mip_packet_view

Public Member Functions

 SizedPacketBuf (uint8_t descriptorSet=INVALID_DESCRIPTOR_SET)
 
 SizedPacketBuf (const uint8_t *data, size_t length)
 Creates a PacketBuf by copying existing data. More...
 
 SizedPacketBuf (const PacketView &packet)
 
 SizedPacketBuf (microstrain::Span< const uint8_t > data)
 Construct from a span. More...
 
 SizedPacketBuf (const SizedPacketBuf &other)
 Copy constructor. More...
 
template<size_t OtherSize>
 SizedPacketBuf (const SizedPacketBuf< OtherSize > &other)
 Copy constructor (required to insert packets into std::vector in some cases). More...
 
SizedPacketBufoperator= (const SizedPacketBuf &other)
 Copy assignment operator. More...
 
template<size_t OtherSize>
SizedPacketBufoperator= (const SizedPacketBuf< OtherSize > &other)
 Assignment operator, copies data from another buffer to this one. More...
 
template<class FieldType >
 SizedPacketBuf (const FieldType &field, uint8_t fieldDescriptor=INVALID_FIELD_DESCRIPTOR, typename std::enable_if< std::is_class< FieldType >::value, void >::type *=nullptr)
 Create a packet containing just the given field. More...
 
PacketView ref ()
 Explicitly obtains a reference to the packet data. More...
 
const PacketViewref () const
 Explicitly obtains a const reference to the packet data. More...
 
uint8_t * buffer ()
 Returns a pointer to the underlying buffer. This is technically the same as PacketRef::pointer but is writable. More...
 
microstrain::Span< uint8_t, BufferSize > bufferSpan ()
 Returns a Span covering the entire buffer. More...
 
void copyFrom (const uint8_t *data, size_t length)
 Copies the data from the pointer to this buffer. The data is not inspected. More...
 
void copyFrom (const PacketView &packet)
 Copies an existing packet. The packet is assumed to be valid (undefined behavior otherwise). More...
 
- Public Member Functions inherited from mip::PacketView
 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::Span< uint8_t > buffer, uint8_t descriptorSet)
 Create a new MIP packet in an existing buffer. More...
 
 PacketView (microstrain::Span< const uint8_t > buffer)
 Create a reference to an existing MIP packet. More...
 
bool isData () const
 
Serializer createField (uint8_t fieldDescriptor, uint8_t length)
 
microstrain::Span< const uint8_t > totalSpan () const
 Gets a span over the whole packet. More...
 
microstrain::Span< const uint8_t > payloadSpan () const
 Gets a span over just the 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 (uint8_t *buffer, size_t maxLength)
 Copies this packet to an external buffer. More...
 
bool copyPacketTo (microstrain::Span< uint8_t > buffer)
 Copies this packet to an external buffer (span version). More...
 

Additional Inherited Members

- Static Public Member Functions inherited from mip::PacketView
template<class FieldType >
static PacketView createFromField (uint8_t *buffer, size_t bufferSize, 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 inherited from mip::PacketView
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
 

Detailed Description

template<size_t BufferSize>
class mip::SizedPacketBuf< BufferSize >

A mip packet with a self-contained buffer (useful with std::vector).

Constructor & Destructor Documentation

◆ SizedPacketBuf() [1/7]

template<size_t BufferSize>
mip::SizedPacketBuf< BufferSize >::SizedPacketBuf ( uint8_t  descriptorSet = INVALID_DESCRIPTOR_SET)
inline

◆ SizedPacketBuf() [2/7]

template<size_t BufferSize>
mip::SizedPacketBuf< BufferSize >::SizedPacketBuf ( const uint8_t *  data,
size_t  length 
)
inlineexplicit

Creates a PacketBuf by copying existing data.

◆ SizedPacketBuf() [3/7]

template<size_t BufferSize>
mip::SizedPacketBuf< BufferSize >::SizedPacketBuf ( const PacketView packet)
inlineexplicit

◆ SizedPacketBuf() [4/7]

template<size_t BufferSize>
mip::SizedPacketBuf< BufferSize >::SizedPacketBuf ( microstrain::Span< const uint8_t >  data)
inlineexplicit

Construct from a span.

◆ SizedPacketBuf() [5/7]

template<size_t BufferSize>
mip::SizedPacketBuf< BufferSize >::SizedPacketBuf ( const SizedPacketBuf< BufferSize > &  other)
inline

Copy constructor.

◆ SizedPacketBuf() [6/7]

template<size_t BufferSize>
template<size_t OtherSize>
mip::SizedPacketBuf< BufferSize >::SizedPacketBuf ( const SizedPacketBuf< OtherSize > &  other)
inlineexplicit

Copy constructor (required to insert packets into std::vector in some cases).

◆ SizedPacketBuf() [7/7]

template<size_t BufferSize>
template<class FieldType >
mip::SizedPacketBuf< BufferSize >::SizedPacketBuf ( const FieldType &  field,
uint8_t  fieldDescriptor = INVALID_FIELD_DESCRIPTOR,
typename std::enable_if< std::is_class< FieldType >::value, void >::type *  = nullptr 
)
inline

Create a packet containing just the given field.

Template Parameters
FieldTypeType of the MIP field. This can't be explicitly specified due to being a constructor.
Parameters
fieldThe field object to serialize.
fieldDescriptorIf specified (not INVALID_FIELD_DESCRIPTOR), overrides the field descriptor.

Member Function Documentation

◆ buffer()

template<size_t BufferSize>
uint8_t* mip::SizedPacketBuf< BufferSize >::buffer ( )
inline

Returns a pointer to the underlying buffer. This is technically the same as PacketRef::pointer but is writable.

◆ bufferSpan()

template<size_t BufferSize>
microstrain::Span<uint8_t, BufferSize> mip::SizedPacketBuf< BufferSize >::bufferSpan ( )
inline

Returns a Span covering the entire buffer.

◆ copyFrom() [1/2]

template<size_t BufferSize>
void mip::SizedPacketBuf< BufferSize >::copyFrom ( const PacketView packet)
inline

Copies an existing packet. The packet is assumed to be valid (undefined behavior otherwise).

Parameters
packetA "sane" (isSane()) mip packet.

◆ copyFrom() [2/2]

template<size_t BufferSize>
void mip::SizedPacketBuf< BufferSize >::copyFrom ( const uint8_t *  data,
size_t  length 
)
inline

Copies the data from the pointer to this buffer. The data is not inspected.

Parameters
dataPointer to the start of the packet.
lengthTotal length of the packet.

◆ operator=() [1/2]

template<size_t BufferSize>
SizedPacketBuf& mip::SizedPacketBuf< BufferSize >::operator= ( const SizedPacketBuf< BufferSize > &  other)
inline

Copy assignment operator.

◆ operator=() [2/2]

template<size_t BufferSize>
template<size_t OtherSize>
SizedPacketBuf& mip::SizedPacketBuf< BufferSize >::operator= ( const SizedPacketBuf< OtherSize > &  other)
inline

Assignment operator, copies data from another buffer to this one.

◆ ref() [1/2]

template<size_t BufferSize>
PacketView mip::SizedPacketBuf< BufferSize >::ref ( )
inline

Explicitly obtains a reference to the packet data.

◆ ref() [2/2]

template<size_t BufferSize>
const PacketView& mip::SizedPacketBuf< BufferSize >::ref ( ) const
inline

Explicitly obtains a const reference to the packet data.


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