All data that is published is turned into a shared_ptr and wrapped in an envelope. You can save a call to std::move by pre-allocating your object as a shared_ptr, but remember, the object is shared at that point so avoid changing the data it points to. Subscribers only receive pointers to const data.

There are a handful of major envelope types.

  • All envelopes inherit from pipeline::AbstractEnvelope. This is a type-erased envelope that provides base functionality (timestamping and serialization).
  • The pipeline::DataEnvelope type is a type that holds serialized data (typically coming from a log or from the comms system). This is a type-erased envelope, and provides functionality for converting itself into a “concrete envelope” on demand, one you know the underlying type.
  • The pipeline::Envelope<T> type, or “concrete envelope”, wraps a particular type T, which you can either fetch directly (by const reference), or you can get the timestamp, or serialize the object (assuming T is serializable, it doesn’t need to be).

Subscribers can subscribe to the abstract envelope if they so desire. You can simply subscribe to the pipeline::AbstractEnvelope type and you will receive envelope pointers.

Each envelope has the following members:

  • publish_time() - The time the message was published.
  • to_json() - Serializes the object as a JSON blob.
  • to_bytes() - Serializes the object into a ByteBuffer.

Subscribing to the abstract envelope can be useful if you want to listen to what a publisher is sending without necessarily knowing the type.