MessageOutput< TMessageSpec > Class Template Reference

Space-ng SDK: sol3::core::MessageOutput< TMessageSpec > Class Template Reference
Space-ng SDK
sol3::core::MessageOutput< TMessageSpec > Class Template Reference

#include <sol3/core/message_output.h>

Inheritance diagram for sol3::core::MessageOutput< TMessageSpec >:
sol3::core::AnyMessageOutput

Public Types

using TableType = typename TMessageSpec::TableType
 
using NativeTableType = typename TableType::NativeTableType
 
using Builder = typename TableType::Builder
 

Public Member Functions

 MessageOutput (IBufferExchange &exchange, uint32_t component_id, size_t slot_count, size_t slot_size)
 
msg::MessageHeaderT const & header () const
 
NativeTableTypepayload ()
 Mutable access to the native FlatBuffers payload. More...
 
NativeTableType const & payload () const
 
TableType const * payloadRoot () const
 
void addStamp (msg::Stamp const &stamp)
 Append a timestamp to the header. More...
 
uint64_t write ()
 
template<typename TBuilderFunction >
uint64_t write (TBuilderFunction &&builder_function)
 
- Public Member Functions inherited from sol3::core::AnyMessageOutput
 AnyMessageOutput (IBufferExchange &exchange, MessagePort port, MessageSchema schema, size_t slot_count, size_t slot_size)
 
 ~AnyMessageOutput ()
 Unregisters the output buffer from the exchange. More...
 
 AnyMessageOutput (AnyMessageOutput &&rhs)=delete
 
AnyMessageOutputoperator= (AnyMessageOutput &&rhs)=delete
 
 AnyMessageOutput (AnyMessageOutput const &)=delete
 
AnyMessageOutputoperator= (AnyMessageOutput const &rhs)=delete
 
MessagePort const & port () const
 Destination message port. More...
 
flatbuffers::span< uint8_t const > headerSpan () const
 
flatbuffers::span< uint8_t const > payloadSpan () const
 
uint64_t write (flatbuffers::span< uint8_t const > header_span, flatbuffers::span< uint8_t const > payload_span)
 Returns the sequence number of the slot written to. More...
 
msg::MessageHeader const * headerRoot () const
 
template<typename TTableType >
TTableType const * payloadRoot () const
 
MessageSchema schema () const
 

Detailed Description

template<typename TMessageSpec>
class sol3::core::MessageOutput< TMessageSpec >

Typed output writer for publishing messages defined by MessageSpec<TableType, kInterfaceType, kInterfaceId> into an IBufferExchange as a sequence ring.

Constructs and registers a shared-memory buffer sized for the requested number of slots and slot size. On destruction, unregisters the buffer.

Member Typedef Documentation

◆ Builder

template<typename TMessageSpec >
using sol3::core::MessageOutput< TMessageSpec >::Builder = typename TableType::Builder

◆ NativeTableType

template<typename TMessageSpec >
using sol3::core::MessageOutput< TMessageSpec >::NativeTableType = typename TableType::NativeTableType

◆ TableType

template<typename TMessageSpec >
using sol3::core::MessageOutput< TMessageSpec >::TableType = typename TMessageSpec::TableType

Constructor & Destructor Documentation

◆ MessageOutput()

template<typename TMessageSpec >
sol3::core::MessageOutput< TMessageSpec >::MessageOutput ( IBufferExchange exchange,
uint32_t  component_id,
size_t  slot_count,
size_t  slot_size 
)
inline

Creates and registers an output buffer for component component with slot_count slots of size slot_size bytes each.

The buffer is advertised on the message port derived from TMessageSpec::makeMessagePort(component) and becomes discoverable by readers via the exchange.

Member Function Documentation

◆ addStamp()

template<typename TMessageSpec >
void sol3::core::MessageOutput< TMessageSpec >::addStamp ( msg::Stamp const &  stamp)
inline

Append a timestamp to the header.

◆ header()

template<typename TMessageSpec >
msg::MessageHeaderT const& sol3::core::MessageOutput< TMessageSpec >::header ( ) const
inline

◆ payload() [1/2]

template<typename TMessageSpec >
NativeTableType& sol3::core::MessageOutput< TMessageSpec >::payload ( )
inline

Mutable access to the native FlatBuffers payload.

◆ payload() [2/2]

template<typename TMessageSpec >
NativeTableType const& sol3::core::MessageOutput< TMessageSpec >::payload ( ) const
inline

◆ payloadRoot()

template<typename TMessageSpec >
TableType const* sol3::core::MessageOutput< TMessageSpec >::payloadRoot ( ) const
inline

◆ write() [1/2]

template<typename TMessageSpec >
uint64_t sol3::core::MessageOutput< TMessageSpec >::write ( )
inline

Takes the current value of payload(), which is a flatbuffer NativeTableType, and packs it into FlatBuffers buffer, stamps the header, and writes header+payload into the next ring slot. Returns the sequence number of the slot written to.

After this function returns the headSpan and payloadSpan will contained the serialized flatbuffer data that was copied to the sequence ring slot

The following should be true: reader.read(writer.write()).payloadSpan() == writer.payloadSpan()

◆ write() [2/2]

template<typename TMessageSpec >
template<typename TBuilderFunction >
uint64_t sol3::core::MessageOutput< TMessageSpec >::write ( TBuilderFunction &&  builder_function)
inline

Performant alternative to the payload() mutate then write() pattern, this allows use of the flatbuffer typed builder interface, and bypasses the payload NativeTableType interface altogether. Avoids a packing from the payload object into the buffer builder, and an additional copy/serialization step. Call this instead of write().

Expects a function with signature: Usage example:

writer.write([i](flatbuffers::FlatBufferBuilder& fbb) -> flatbuffers::Offset<msg::Text> { auto offset = fbb.CreateString(fmt::format("Hello {}", i)); msg::TextBuilder builder(fbb); builder.add_data(offset); return builder.Finish() });

Returns message sequence number


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