lintel 0.2.0
Loading...
Searching...
No Matches
Public Member Functions | Static Public Attributes | List of all members
lintel::Event Class Reference

#include <Event.h>

Public Member Functions

 Event ()=default
 
 Event (const std::string &topic, const std::string &type)
 
void setTopic (const std::string &topic)
 
void setType (const std::string &type)
 
const char * topic () const
 
const char * type () const
 
void setSequence (std::int64_t sequence)
 
std::int64_t sequence () const
 
void setTimestamp (std::int64_t timestamp)
 
std::int64_t timestamp () const
 
void setContent (const std::byte *data, std::size_t size)
 
template<typename T >
void assign (const T &content)
 
template<typename T >
T as () const
 
std::size_t contentLength () const
 
const std::byte * content () const
 
bool isContentEmpty () const
 

Static Public Attributes

static constexpr std::size_t NAME_SIZE = 32
 
static constexpr std::size_t CONTENT_SIZE = 256
 

Detailed Description

A fixed-size, trivially copyable event that is exchanged over the EventBus.

The event is a POD-like value type: it is safe to store it inside the lock-free shared memory queues and to copy it between processes. The sizes of the topic/type identifiers and of the payload buffer are compile-time constants (matching the "configurable fixed slots" design decision); the queue capacities and topic/subscriber counts are configured at runtime.

Constructor & Destructor Documentation

◆ Event() [1/2]

lintel::Event::Event ( )
default

Default constructor; zero-initializes the event.

◆ Event() [2/2]

lintel::Event::Event ( const std::string &  topic,
const std::string &  type 
)
inline

Construct an event with topic and type set.

Parameters
topicidentifier of the channel this event belongs to
typeidentifier of the event type

Member Function Documentation

◆ as()

template<typename T >
T lintel::Event::as ( ) const
inline

Convert the content buffer back into an object of type T.

Template Parameters
Ttarget type
Returns
the converted object

◆ assign()

template<typename T >
void lintel::Event::assign ( const T &  content)
inline

Assign an object of type T to the reserved content space. Warning: T must be trivially copyable and must not exceed CONTENT_SIZE.

Template Parameters
Ttype of the object
Parameters
contentobject which gets copied into the content buffer

◆ content()

const std::byte * lintel::Event::content ( ) const
inline
Returns
pointer to the raw payload bytes

◆ contentLength()

std::size_t lintel::Event::contentLength ( ) const
inline
Returns
the number of valid payload bytes

◆ isContentEmpty()

bool lintel::Event::isContentEmpty ( ) const
inline
Returns
true if the event has no payload

◆ sequence()

std::int64_t lintel::Event::sequence ( ) const
inline
Returns
the sequence number

◆ setContent()

void lintel::Event::setContent ( const std::byte *  data,
std::size_t  size 
)
inline

Copy a payload of given size into the content buffer.

Parameters
datapointer to the payload (may be nullptr when size is zero)
sizenumber of bytes to copy; clamped to CONTENT_SIZE

◆ setSequence()

void lintel::Event::setSequence ( std::int64_t  sequence)
inline

Set the monotonically increasing sequence number.

Parameters
sequencethe sequence number

◆ setTimestamp()

void lintel::Event::setTimestamp ( std::int64_t  timestamp)
inline

Set the creation timestamp (Unix epoch seconds).

Parameters
timestampthe timestamp

◆ setTopic()

void lintel::Event::setTopic ( const std::string &  topic)
inline

Set the topic (truncated to NAME_SIZE).

Parameters
topicthe topic name

◆ setType()

void lintel::Event::setType ( const std::string &  type)
inline

Set the type (truncated to NAME_SIZE).

Parameters
typethe type name

◆ timestamp()

std::int64_t lintel::Event::timestamp ( ) const
inline
Returns
the creation timestamp (Unix epoch seconds)

◆ topic()

const char * lintel::Event::topic ( ) const
inline
Returns
the topic name (NUL-terminated)

◆ type()

const char * lintel::Event::type ( ) const
inline
Returns
the type name (NUL-terminated)

Member Data Documentation

◆ CONTENT_SIZE

constexpr std::size_t lintel::Event::CONTENT_SIZE = 256
staticconstexpr

Maximum payload size in bytes.

◆ NAME_SIZE

constexpr std::size_t lintel::Event::NAME_SIZE = 32
staticconstexpr

Maximum length of the topic/subscriber name, including the terminator.


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