|
VLink
2.0.0
A high-performance communication middleware
|
Read-side primitive of the VLink event communication model. 更多...
#include <memory>#include <string>#include <type_traits>#include "./base/functional.h"#include "./impl/subscriber_impl.h"#include "./node.h"#include "./internal/subscriber-inl.h"类 | |
| class | vlink::Subscriber< MsgT, SecT > |
| Type-safe topic listener for the VLink event communication model. 更多... | |
| class | vlink::SecuritySubscriber< MsgT > |
Convenience alias of Subscriber with per-message decryption enabled. 更多... | |
命名空间 | |
| vlink | |
Read-side primitive of the VLink event communication model.
Subscriber<MsgT, SecT> attaches a callback to a VLink topic. Each frame delivered by the transport back-end is deserialised into a MsgT instance and forwarded to the user callback registered via listen(). Unlike Getter, the subscriber retains no value history – it simply forwards every event in delivery order.
The class is a thin, header-only template wrapper around SubscriberImpl. Codec dispatch is fully resolved at compile time using the type detected by Serializer::get_type_of<MsgT>().
* Transport Back-end Subscriber<MsgT> * ------------------ ----------------- * | inbound frame | * |--------------------------------------> | * | | Serializer::deserialize * | | (thread-local scratch) * | | * | | optional MessageLoop hop * | | * | v * | user callback(const MsgT&) *
| Category | Example C++ Type | Serializer::Type | Notes |
|---|---|---|---|
| Raw bytes | Bytes | kBytesType | Pass-through to callback. |
| Protobuf value | MyProto | kProtoType | ParseFromArray path. |
| Protobuf pointer | MyProto* | kProtoPtrType | Needs bind_proto_arena. |
| FlatBuffers obj | MyTableT (NativeTable) | kFlatTableType | Object API. |
| FlatBuffers ptr | MyTable* | kFlatPtrType | Zero-copy view of buffer. |
| DDS CDR | type with deserialize(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. |
MsgT is a shared pointer whose element_type derives from IntraDataType (generated via VLINK_INTRA_DATA_DECLARE) and the URL scheme is intra://, the shared pointer is forwarded zero-copy to the callback without serialisation: thread_local scratch storage and is overwritten on the next delivery. Copy the value before storing it outside the callback scope. This warning does not apply to Bytes or IntraData arguments, which are owned by value or by shared pointer.listen() more than once is a fatal error. The subscriber must be initialised (either by InitType::kWithInit or by explicit init()) before listen() is called.