Class MessageCacheBuffer
Defined in File message_cache_buffer.hpp
Inheritance Relationships
Base Type
public rosbag2_cpp::cache::CacheBufferInterface(Class CacheBufferInterface)
Class Documentation
-
class MessageCacheBuffer : public rosbag2_cpp::cache::CacheBufferInterface
This class implements a single buffer for message cache.
The buffer is limited by total byte size of the stored messages or by total duration of the stored messages. When the buffer is full, the next incoming message is dropped.
Note
When both max_cache_size and max_cache_duration are set, the buffer will drop messages when either of the limits is exceeded.
Note
If max_cache_size is set to zero, the buffer will be only bounded by max_cache_duration.
Note
If max_cache_duration is set to zero, the buffer will be only bounded by max_cache_size.
Note
if max_cache_size more than zero, but an individual message exceeds the buffer size, the message still will be added to the buffer. This means that buffer can at times use more memory than max_cache_size, but never by more than a single message. When the buffer is full, the next incoming message is dropped.
Public Functions
-
explicit MessageCacheBuffer(size_t max_cache_size, uint32_t max_cache_duration = 0)
Parametrized constructor.
- Parameters:
max_cache_size – Maximum amount of memory which could be occupied by the messages stored in the buffer. Note. If max_cache_size is zero, the buffer will be only bounded by the max_cache_duration.
max_cache_duration – Maximum duration in seconds of message sequence allowed to be stored in the buffer. Note. If max_cache_duration is zero, the buffer will be only bounded by the max_cache_size.
- Throws:
std::invalid_argument – if both max_cache_size and max_cache_duration are zero.
-
virtual bool push(CacheBufferInterface::buffer_element_t msg) override
Pushes a new message into the buffer.
If buffer size got some space left, we push message regardless of its size, but if this results in exceeding buffer size or duration limits, we mark buffer to drop all new incoming messages. This flag is cleared when buffers are swapped.
- Parameters:
msg – Shared pointer to the rosbag2_storage::SerializedBagMessage to add to the buffer.
- Returns:
True if message was successfully pushed, otherwise false.
-
virtual void clear() override
Clear buffer.
-
virtual size_t size() override
Get number of elements in the buffer.
-
virtual const std::vector<CacheBufferInterface::buffer_element_t> &data() override
Get buffer data.
-
explicit MessageCacheBuffer(size_t max_cache_size, uint32_t max_cache_duration = 0)