VLink 2.0.0
A high-performance communication middleware
Loading...
Searching...
No Matches
publisher.h File Reference

Type-safe event-model publisher for VLink topics. More...

#include <memory>
#include <string>
#include "./impl/publisher_impl.h"
#include "./node.h"
#include "./internal/publisher-inl.h"
Include dependency graph for publisher.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

 Type-safe publisher for the VLink event communication model. More...
 Convenience alias for Publisher with message security enabled. More...

Namespaces

Detailed Description

Type-safe event-model publisher for VLink topics.

Publisher<MsgT, SecT> is the write side of the VLink event model. It serialises a MsgT object and delivers it to all Subscriber nodes that share the same URL.

Event Model Data Flow
Publisher<T> Transport Back-end Subscriber<T>
| | |
|-- publish(msg) --------> | |
| serialize(msg) | |
| [loan if shm://] |-- bytes delivery ---------> |
| | |--> callback(msg)
| | | deserialize(bytes)
Supported Message Types
Category Type Serializer
Raw bytes Bytes kBytesType
Protobuf MyProto (MessageLite) kProtoType
Protobuf ptr MyProto* (Arena-managed) kProtoPtrType
FlatBuffers MyTableT (NativeTable) kFlatTableType
FlatBuffers MyBuilder (has fbb_+Finish) kFlatBuilderType
CDR (DDS only) MyCdrType (serialize/des.) kCdrType
Standard layout POD struct / trivial type kStandardType
String std::string kStringType
Custom T (has operator>>/<<) kCustomType
Subscriber Detection
Publisher<MyMsg> pub("dds://topic");
pub.detect_subscribers([](bool has) { // async notification
if (has) pub.publish(MyMsg{});
});
pub.wait_for_subscribers(); // blocking until subscriber appears
if (pub.has_subscribers()) { ... } // non-blocking query
Zero-copy on shm://
Publisher<MyStruct> pub("shm://topic");
if (pub.is_support_loan()) {
Bytes buf = pub.loan(sizeof(MyStruct));
new (buf.data()) MyStruct{...};
pub.publish(buf); // no copy; loan returned automatically
}
Note
Pass force = true to publish() to send even when no subscribers are present (e.g. for guaranteed-delivery or field-mode semantics).
Template Parameters
MsgTMessage type. Must satisfy Serializer::is_supported().
SecTSecurity mode; defaults to SecurityType::kWithoutSecurity.