CIRCT 23.0.0git
Loading...
Searching...
No Matches
Public Member Functions | Static Public Member Functions | Private Attributes | List of all members
esi::MessageData Class Reference

A concrete flat message backed by a single vector of bytes. More...

#include <Common.h>

Inheritance diagram for esi::MessageData:
Inheritance graph
[legend]
Collaboration diagram for esi::MessageData:
Collaboration graph
[legend]

Public Member Functions

 MessageData ()=default
 Adopts the data vector buffer.
 
 MessageData (std::span< const uint8_t > data)
 
 MessageData (std::vector< uint8_t > &data)
 
 MessageData (std::vector< uint8_t > &&data)
 
 MessageData (const uint8_t *data, size_t size)
 
 ~MessageData ()=default
 
const uint8_t * getBytes () const
 
const std::vector< uint8_t > & getData () const
 Get the data as a vector of bytes.
 
 operator const std::vector< uint8_t > & () const
 Implicit conversion to a vector/span of bytes, to play nice with other APIs that accept bytearray-like things.
 
 operator std::span< const uint8_t > () const
 
std::vector< uint8_t > takeData ()
 Move the data out of this object.
 
size_t getSize () const
 Get the size of the data in bytes.
 
size_t size () const
 
bool empty () const
 Returns true if this message contains no data.
 
template<typename T >
const T * as () const
 Cast to a type.
 
std::string toHex () const
 Convert the data to a hex string.
 
size_t numSegments () const override
 Number of segments in the message.
 
Segment segment (size_t idx) const override
 Get a segment by index.
 
MessageData toMessageData () const override
 Flatten all segments into a standard MessageData.
 
- Public Member Functions inherited from esi::SegmentedMessageData
virtual ~SegmentedMessageData ()=default
 
size_t totalSize () const
 Total size across all segments.
 
bool empty () const
 True if totalSize() == 0.
 

Static Public Member Functions

template<typename T >
static MessageData from (T &t)
 Cast from a type to its raw bytes.
 

Private Attributes

std::vector< uint8_t > data
 

Detailed Description

A concrete flat message backed by a single vector of bytes.

This is also a one-segment SegmentedMessageData so flat and segmented messages can flow through the same internal APIs.

Definition at line 155 of file Common.h.

Constructor & Destructor Documentation

◆ MessageData() [1/5]

esi::MessageData::MessageData ( )
default

Adopts the data vector buffer.

Referenced by from().

◆ MessageData() [2/5]

esi::MessageData::MessageData ( std::span< const uint8_t >  data)
inline

Definition at line 159 of file Common.h.

◆ MessageData() [3/5]

esi::MessageData::MessageData ( std::vector< uint8_t > &  data)
inline

Definition at line 161 of file Common.h.

◆ MessageData() [4/5]

esi::MessageData::MessageData ( std::vector< uint8_t > &&  data)
inline

Definition at line 162 of file Common.h.

◆ MessageData() [5/5]

esi::MessageData::MessageData ( const uint8_t *  data,
size_t  size 
)
inline

Definition at line 163 of file Common.h.

◆ ~MessageData()

esi::MessageData::~MessageData ( )
default

Member Function Documentation

◆ as()

template<typename T >
const T * esi::MessageData::as ( ) const
inline

Cast to a type.

Throws if the size of the data does not match the size of the message. The lifetime of the resulting pointer is tied to the lifetime of this object.

Definition at line 190 of file Common.h.

References data.

Referenced by channelTest(), esi::fromMessageData(), loopbackAddTest(), runArrayFunc(), runArrayFunc(), runLoopbackI8(), runOddStructFunc(), and runStructFunc().

◆ empty()

bool esi::MessageData::empty ( ) const
inline

Returns true if this message contains no data.

Definition at line 184 of file Common.h.

References data.

◆ from()

template<typename T >
static MessageData esi::MessageData::from ( T &  t)
inlinestatic

Cast from a type to its raw bytes.

Definition at line 200 of file Common.h.

References MessageData().

Referenced by channelTest(), esi::services::TelemetryService::Metric::read(), runOddStructFunc(), and runStructFunc().

◆ getBytes()

const uint8_t * esi::MessageData::getBytes ( ) const
inline

◆ getData()

const std::vector< uint8_t > & esi::MessageData::getData ( ) const
inline

Get the data as a vector of bytes.

Definition at line 169 of file Common.h.

References data.

◆ getSize()

size_t esi::MessageData::getSize ( ) const
inline

◆ numSegments()

size_t esi::MessageData::numSegments ( ) const
inlineoverridevirtual

Number of segments in the message.

Implements esi::SegmentedMessageData.

Definition at line 207 of file Common.h.

◆ operator const std::vector< uint8_t > &()

esi::MessageData::operator const std::vector< uint8_t > & ( ) const
inline

Implicit conversion to a vector/span of bytes, to play nice with other APIs that accept bytearray-like things.

Definition at line 173 of file Common.h.

References data.

◆ operator std::span< const uint8_t >()

esi::MessageData::operator std::span< const uint8_t > ( ) const
inline

Definition at line 174 of file Common.h.

References data.

◆ segment()

Segment esi::MessageData::segment ( size_t  idx) const
inlineoverridevirtual

Get a segment by index.

Implements esi::SegmentedMessageData.

Definition at line 208 of file Common.h.

References data.

◆ size()

size_t esi::MessageData::size ( ) const
inline

Definition at line 181 of file Common.h.

References getSize().

Referenced by esiaccel.types.ArrayType::deserialize(), and esiaccel.types.ArrayType::is_valid().

◆ takeData()

std::vector< uint8_t > esi::MessageData::takeData ( )
inline

Move the data out of this object.

Definition at line 177 of file Common.h.

References data.

◆ toHex()

std::string MessageData::toHex ( ) const

Convert the data to a hex string.

Definition at line 22 of file Common.cpp.

References data.

◆ toMessageData()

MessageData esi::MessageData::toMessageData ( ) const
inlineoverridevirtual

Flatten all segments into a standard MessageData.

Reimplemented from esi::SegmentedMessageData.

Definition at line 213 of file Common.h.

Referenced by esi::ReadChannelPort::connect().

Member Data Documentation

◆ data

std::vector<uint8_t> esi::MessageData::data
private

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