Add support for editing the logfile headers
This lets us fix bugs in logfiles if the need arises.
Change-Id: I374c4f6b3745835af2279d4b29f6f8098a5d7770
diff --git a/aos/events/logging/logfile_utils.cc b/aos/events/logging/logfile_utils.cc
index e55b80d..a5ca084 100644
--- a/aos/events/logging/logfile_utils.cc
+++ b/aos/events/logging/logfile_utils.cc
@@ -39,6 +39,26 @@
QueueSizedFlatbuffer(fbb->Release());
}
+void DetachedBufferWriter::WriteSizedFlatbuffer(
+ absl::Span<const uint8_t> span) {
+ // Cheat aggressively... Write out the queued up data, and then write this
+ // data once without buffering. It is hard to make a DetachedBuffer out of
+ // this data, and we don't want to worry about lifetimes.
+ Flush();
+ iovec_.clear();
+ iovec_.reserve(1);
+
+ struct iovec n;
+ n.iov_base = const_cast<uint8_t *>(span.data());
+ n.iov_len = span.size();
+ iovec_.emplace_back(n);
+
+ const ssize_t written = writev(fd_, iovec_.data(), iovec_.size());
+
+ PCHECK(written == static_cast<ssize_t>(n.iov_len))
+ << ": Wrote " << written << " expected " << n.iov_len;
+}
+
void DetachedBufferWriter::QueueSizedFlatbuffer(
flatbuffers::DetachedBuffer &&buffer) {
queued_size_ += buffer.size();