CIRCT 24.0.0git
Loading...
Searching...
No Matches
esi::MessageData Class Reference

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

#include <Common.h>

Inheritance diagram for esi::MessageData:
Collaboration diagram for esi::MessageData:

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. Throws if the segment has been take()n.
MessageData toMessageData () const override
 Flatten all segments into a standard MessageData.
Public Member Functions inherited from esi::SegmentedMessageData
virtual ~SegmentedMessageData ()=default
virtual std::unique_ptr< services::HostMemRegion > take (size_t segIdx)
 Optionally called by a backend once it has transmitted segment segIdx, to obtain ownership of the HostMem region backing it (e.g.
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 197 of file Common.h.

Constructor & Destructor Documentation

◆ MessageData() [1/5]

esi::MessageData::MessageData ( )
default

Adopts the data vector buffer.

Referenced by from(), and toMessageData().

◆ MessageData() [2/5]

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

Definition at line 201 of file Common.h.

References data, and size().

◆ MessageData() [3/5]

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

Definition at line 203 of file Common.h.

References data.

◆ MessageData() [4/5]

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

Definition at line 204 of file Common.h.

References data.

◆ MessageData() [5/5]

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

Definition at line 205 of file Common.h.

References data, and size().

◆ ~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 232 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 226 of file Common.h.

References data.

◆ from()

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

Cast from a type to its raw bytes.

Definition at line 242 of file Common.h.

References MessageData().

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

◆ getBytes()

◆ getData()

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

Get the data as a vector of bytes.

Definition at line 211 of file Common.h.

References data.

◆ getSize()

◆ numSegments()

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

Number of segments in the message.

Implements esi::SegmentedMessageData.

Definition at line 249 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 215 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 216 of file Common.h.

References data.

◆ segment()

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

Get a segment by index. Throws if the segment has been take()n.

Implements esi::SegmentedMessageData.

Definition at line 250 of file Common.h.

References data.

◆ size()

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

Definition at line 223 of file Common.h.

References getSize().

Referenced by MessageData(), and MessageData().

◆ takeData()

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

Move the data out of this object.

Definition at line 219 of file Common.h.

References data.

◆ toHex()

std::string MessageData::toHex ( ) const

Convert the data to a hex string.

Definition at line 23 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 255 of file Common.h.

References MessageData().

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

Member Data Documentation

◆ data


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