Class TransientLocalMessagesCache
Defined in File transient_local_messages_cache.hpp
Nested Relationships
Nested Types
Class Documentation
-
class TransientLocalMessagesCache
Thread-safe cache for transient-local messages with per-topic FIFO queues.
Maintains per-topic circular queues of the last N messages, where N is a configurable depth per topic. Used to prepend transient-local messages on bag splits and snapshots.
Public Functions
-
void add_topic(const std::string &topic_name, size_t queue_depth)
Add a topic to the cache with a specified queue depth. If the topic already exists, its queue depth will be updated. If the new depth is smaller than the current number of cached messages, the oldest messages will be discarded.
- Parameters:
topic_name – The name of the topic.
queue_depth – The maximum number of messages to store for this topic.
- Throws:
std::invalid_argument – if the queue depth is zero.
-
void remove_topic(const std::string &topic_name)
Remove a topic and all its cached messages from the cache.
- Parameters:
topic_name – The name of the topic to remove. No-op if the topic does not exist.
-
bool has_topic(const std::string &topic_name) const
Check whether a topic is registered in the cache.
- Parameters:
topic_name – The name of the topic.
- Returns:
true if the topic exists in the cache, false otherwise.
Push a message into the cache for a given topic. If the queue is full, the oldest message will be discarded.
- Parameters:
topic_name – The name of the topic.
message – The serialized message to cache.
- Throws:
std::runtime_error – if the topic has not been registered via add_topic().
-
std::vector<rosbag2_storage::SerializedBagMessageSharedPtr> get_messages_sorted_by_timestamp() const
Retrieve all cached messages across all topics, sorted by timestamp. Messages are sorted by recv_timestamp first, then send_timestamp, then topic_name.
- Returns:
A vector of cached messages sorted by timestamp.
-
void clear()
Clear all cached messages from all topics without removing the topic registrations.
-
size_t size() const
Get the total number of cached messages across all topics.
- Returns:
The total number of cached messages.
-
void add_topic(const std::string &topic_name, size_t queue_depth)