VLink  2.0.0
A high-performance communication middleware
publisher.h File Reference

Write-side primitive of the VLink event communication model. More...

#include <memory>
#include <string>
#include <type_traits>
#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

class  vlink::Publisher< MsgT, SecT >
 Type-safe topic emitter for the VLink event communication model. More...
 
class  vlink::SecurityPublisher< MsgT >
 Convenience alias of Publisher with per-message security enabled. More...
 

Namespaces

 

Detailed Description

Write-side primitive of the VLink event communication model.

Publisher<MsgT, SecT> is the message emitter for VLink topics. Each call to publish() serialises an instance of MsgT according to the compile-time-detected codec and hands the resulting payload to the active transport back-end, which fans the bytes out to every connected Subscriber that shares the same topic URL.

The class is a thin, header-only template wrapper around PublisherImpl; all runtime work is delegated to the impl. Codec selection is fully resolved at compile time so the runtime dispatch is zero-cost.

Event-model Data Flow
*   Publisher<MsgT>               Transport Back-end              Subscriber<MsgT>
*   ----------------              ------------------              -----------------
*      |                                  |                              |
*      |-- publish(msg, force) ---------->|                              |
*      |   Serializer::serialize          |                              |
*      |   (loan-aware on shm/zenoh)      |                              |
*      |                                  |--- frame on wire ----------->|
*      |                                  |                              |
*      |                                  |                              |--> callback
*      |                                  |                              |    Serializer::
*      |                                  |                              |    deserialize
* 
Supported Message Types
Category Example C++ Type Serializer::Type Notes
Raw bytes Bytes kBytesType Pass-through, no codec call.
Protobuf value MyProto kProtoType Uses SerializeToArray.
Protobuf pointer MyProto* kProtoPtrType Caller owns lifetime.
FlatBuffers obj MyTableT (NativeTable) kFlatTableType Object API.
FlatBuffers ptr MyTable* (Table pointer) kFlatPtrType Zero-copy read view.
FlatBuffers build MyBuilder (fbb_ + Finish) kFlatBuilderType Finishes builder on publish.
DDS CDR type with serialize(Cdr&) kCdrType DDS fast path.
POD struct trivial standard-layout type kStandardType sizeof(T) byte copy.
UTF-8 text std::string kStringType Length-prefixed.
Custom type with operator>>/<< kCustomType User-supplied codec.
Subscriber Detection
Use the detection API to gate writes on the presence of at least one matching subscriber. This is purely informational; pass force=true to publish() if you wish to write regardless of detection state.
vlink::Publisher<MyMsg> pub("dds://sensor/imu");
pub.detect_subscribers([&pub](bool present) {
if (present) { pub.publish(MyMsg{}); }
});
if (pub.wait_for_subscribers(std::chrono::milliseconds(500))) {
pub.publish(MyMsg{});
}
if (pub.has_subscribers()) { pub.publish(MyMsg{}); }
Zero-copy Loan on Loan-capable Transports
vlink::Publisher<vlink::Bytes> pub("shm://image/raw");
if (pub.is_support_loan()) {
vlink::Bytes buf = pub.loan(sizeof(FrameHeader) + payload_size);
::memcpy(buf.data(), &header, sizeof(header));
pub.publish(buf);
}
Note
Loans bypass an extra copy by writing directly into transport-managed memory. Loans are not used when security is enabled because ciphertext length differs from plaintext length.
See also
subscriber.h, node.h, serializer.h, extension/security.h