Add PeekMessage/ConsumeMessage to SpanReader
We have log files with duplicate headers on the front of them.
Considering they have useful data, add a flag which enables support for
detecting and recovering.
Change-Id: I30a85c7023b71dfa8ecce63fb8288565d5a01737
Signed-off-by: Austin Schuh <austin.schuh@bluerivertech.com>
diff --git a/aos/events/logging/logfile_utils.h b/aos/events/logging/logfile_utils.h
index 4bb481d..ee13a7c 100644
--- a/aos/events/logging/logfile_utils.h
+++ b/aos/events/logging/logfile_utils.h
@@ -211,10 +211,19 @@
std::string_view filename() const { return filename_; }
- // Returns a span with the data for a message from the log file, excluding
- // the size.
+ // Returns a span with the data for the next message from the log file,
+ // including the size. The result is only guarenteed to be valid until
+ // ReadMessage() or PeekMessage() is called again.
absl::Span<const uint8_t> ReadMessage();
+ // Returns a span with the data for the next message without consuming it.
+ // Multiple calls to PeekMessage return the same data. ReadMessage or
+ // ConsumeMessage must be called to get the next message.
+ absl::Span<const uint8_t> PeekMessage();
+ // Consumes the message so the next call to ReadMessage or PeekMessage returns
+ // new data. This does not invalidate the data.
+ void ConsumeMessage();
+
private:
// TODO(austin): Optimization:
// Allocate the 256k blocks like we do today. But, refcount them with