Make Copier support starting and ending bytes
This sets us up to be able to fill large power of two buffers in the
logger so they can be very efficiently handed to the OS to be written.
The code to do this will come later.
Change-Id: I65faab96ab9058e268fb773b30a2155bbef8f2f7
Signed-off-by: Austin Schuh <austin.linux@gmail.com>
diff --git a/aos/events/logging/buffer_encoder.cc b/aos/events/logging/buffer_encoder.cc
index ae20440..4b3ccf3 100644
--- a/aos/events/logging/buffer_encoder.cc
+++ b/aos/events/logging/buffer_encoder.cc
@@ -32,8 +32,8 @@
const size_t input_buffer_initial_size = input_buffer_.size();
input_buffer_.resize(input_buffer_initial_size + copy->size());
- const size_t written_size =
- copy->Copy(input_buffer_.data() + input_buffer_initial_size);
+ const size_t written_size = copy->Copy(
+ input_buffer_.data() + input_buffer_initial_size, 0, copy->size());
DCHECK_EQ(written_size, copy->size());
total_bytes_ += written_size;
diff --git a/aos/events/logging/buffer_encoder.h b/aos/events/logging/buffer_encoder.h
index 4cd661d..34de00a 100644
--- a/aos/events/logging/buffer_encoder.h
+++ b/aos/events/logging/buffer_encoder.h
@@ -23,7 +23,8 @@
size_t size() const { return size_; }
// Writes size() bytes to data, and returns the data written.
- [[nodiscard]] virtual size_t Copy(uint8_t *data) = 0;
+ [[nodiscard]] virtual size_t Copy(uint8_t *data, size_t start_byte,
+ size_t end_byte) = 0;
private:
size_t size_;
@@ -35,12 +36,15 @@
public:
SpanCopier(absl::Span<const uint8_t> data)
: Copier(data.size()), data_(data) {
- CHECK(data_.data());
+ CHECK(data_.data() != nullptr);
}
- size_t Copy(uint8_t *data) final {
- std::memcpy(data, data_.data(), data_.size());
- return data_.size();
+ size_t Copy(uint8_t *data, size_t start_byte, size_t end_byte) final {
+ DCHECK_LE(start_byte, end_byte);
+ DCHECK_LE(end_byte, data_.size());
+
+ std::memcpy(data, data_.data() + start_byte, end_byte - start_byte);
+ return end_byte - start_byte;
}
private:
diff --git a/aos/events/logging/buffer_encoder_param_test.h b/aos/events/logging/buffer_encoder_param_test.h
index e6c4867..9e7882d 100644
--- a/aos/events/logging/buffer_encoder_param_test.h
+++ b/aos/events/logging/buffer_encoder_param_test.h
@@ -20,15 +20,12 @@
public:
static constexpr size_t kMaxMessageSize = 2 * 1024 * 1024;
- class DetachedBufferCopier : public DataEncoder::Copier {
+ class DetachedBufferCopier : public DataEncoder::SpanCopier {
public:
DetachedBufferCopier(flatbuffers::DetachedBuffer &&data)
- : DataEncoder::Copier(data.size()), data_(std::move(data)) {}
-
- size_t Copy(uint8_t *data) final {
- std::memcpy(data, data_.data(), data_.size());
- return data_.size();
- }
+ : DataEncoder::SpanCopier(
+ absl::Span<const uint8_t>(data.data(), data.size())),
+ data_(std::move(data)) {}
private:
const flatbuffers::DetachedBuffer data_;
diff --git a/aos/events/logging/buffer_encoder_test.cc b/aos/events/logging/buffer_encoder_test.cc
index 8e12e37..5f3ecab 100644
--- a/aos/events/logging/buffer_encoder_test.cc
+++ b/aos/events/logging/buffer_encoder_test.cc
@@ -115,4 +115,33 @@
}),
::testing::Range(0, 100)));
+// Tests that SpanCopier copies as expected.
+TEST(SpanCopierTest, Matches) {
+ std::vector<uint8_t> data;
+ for (int i = 0; i < 32; ++i) {
+ data.push_back(i);
+ }
+
+ CHECK_EQ(data.size(), 32u);
+
+ for (int i = 0; i < 32; i += 8) {
+ for (int j = i; j < 32; j += 8) {
+ std::vector<uint8_t> destination(data.size(), 0);
+ DataEncoder::SpanCopier copier(
+ absl::Span<const uint8_t>(data.data(), data.size()));
+
+ copier.Copy(destination.data(), i, j);
+
+ size_t index = 0;
+ for (int k = i; k < j; ++k) {
+ EXPECT_EQ(destination[index], k);
+ ++index;
+ }
+ for (; index < destination.size(); ++index) {
+ EXPECT_EQ(destination[index], 0u);
+ }
+ }
+ }
+}
+
} // namespace aos::logger::testing
diff --git a/aos/events/logging/log_writer.cc b/aos/events/logging/log_writer.cc
index 5671a3f..84f7503 100644
--- a/aos/events/logging/log_writer.cc
+++ b/aos/events/logging/log_writer.cc
@@ -766,64 +766,6 @@
}
}
-// Class to copy a context into the provided buffer.
-class ContextDataCopier : public DataEncoder::Copier {
- public:
- ContextDataCopier(const Context &context, int channel_index, LogType log_type,
- EventLoop *event_loop)
- : DataEncoder::Copier(PackMessageSize(log_type, context.size)),
- context_(context),
- channel_index_(channel_index),
- log_type_(log_type),
- event_loop_(event_loop) {}
-
- monotonic_clock::time_point end_time() const { return end_time_; }
-
- size_t Copy(uint8_t *data) final {
- size_t result =
- PackMessageInline(data, context_, channel_index_, log_type_);
- end_time_ = event_loop_->monotonic_now();
- return result;
- }
-
- private:
- const Context &context_;
- const int channel_index_;
- const LogType log_type_;
- EventLoop *event_loop_;
- monotonic_clock::time_point end_time_;
-};
-
-// Class to copy a RemoteMessage into the provided buffer.
-class RemoteMessageCopier : public DataEncoder::Copier {
- public:
- RemoteMessageCopier(const message_bridge::RemoteMessage *message,
- int channel_index,
- aos::monotonic_clock::time_point monotonic_timestamp_time,
- EventLoop *event_loop)
- : DataEncoder::Copier(PackRemoteMessageSize()),
- message_(message),
- channel_index_(channel_index),
- monotonic_timestamp_time_(monotonic_timestamp_time),
- event_loop_(event_loop) {}
-
- monotonic_clock::time_point end_time() const { return end_time_; }
-
- size_t Copy(uint8_t *data) final {
- size_t result = PackRemoteMessageInline(data, message_, channel_index_,
- monotonic_timestamp_time_);
- end_time_ = event_loop_->monotonic_now();
- return result;
- }
-
- private:
- const message_bridge::RemoteMessage *message_;
- int channel_index_;
- aos::monotonic_clock::time_point monotonic_timestamp_time_;
- EventLoop *event_loop_;
- monotonic_clock::time_point end_time_;
-};
-
void Logger::WriteData(NewDataWriter *writer, const FetcherStruct &f) {
if (writer != nullptr) {
const UUID source_node_boot_uuid =
diff --git a/aos/events/logging/logfile_utils.cc b/aos/events/logging/logfile_utils.cc
index 90220c8..0918545 100644
--- a/aos/events/logging/logfile_utils.cc
+++ b/aos/events/logging/logfile_utils.cc
@@ -323,73 +323,144 @@
size_t PackRemoteMessageInline(
uint8_t *buffer, const message_bridge::RemoteMessage *msg,
int channel_index,
- const aos::monotonic_clock::time_point monotonic_timestamp_time) {
+ const aos::monotonic_clock::time_point monotonic_timestamp_time,
+ size_t start_byte, size_t end_byte) {
const flatbuffers::uoffset_t message_size = PackRemoteMessageSize();
+ DCHECK_EQ((start_byte % 8u), 0u);
+ DCHECK_EQ((end_byte % 8u), 0u);
+ DCHECK_LE(start_byte, end_byte);
+ DCHECK_LE(end_byte, message_size);
- // clang-format off
- // header:
- // +0x00 | 5C 00 00 00 | UOffset32 | 0x0000005C (92) Loc: +0x5C | size prefix
- buffer = Push<flatbuffers::uoffset_t>(
- buffer, message_size - sizeof(flatbuffers::uoffset_t));
- // +0x04 | 20 00 00 00 | UOffset32 | 0x00000020 (32) Loc: +0x24 | offset to root table `aos.logger.MessageHeader`
- buffer = Push<flatbuffers::uoffset_t>(buffer, 0x20);
- //
- // padding:
- // +0x08 | 00 00 00 00 00 00 | uint8_t[6] | ...... | padding
- buffer = Pad(buffer, 6);
- //
- // vtable (aos.logger.MessageHeader):
- // +0x0E | 16 00 | uint16_t | 0x0016 (22) | size of this vtable
- buffer = Push<flatbuffers::voffset_t>(buffer, 0x16);
- // +0x10 | 3C 00 | uint16_t | 0x003C (60) | size of referring table
- buffer = Push<flatbuffers::voffset_t>(buffer, 0x3c);
- // +0x12 | 38 00 | VOffset16 | 0x0038 (56) | offset to field `channel_index` (id: 0)
- buffer = Push<flatbuffers::voffset_t>(buffer, 0x38);
- // +0x14 | 2C 00 | VOffset16 | 0x002C (44) | offset to field `monotonic_sent_time` (id: 1)
- buffer = Push<flatbuffers::voffset_t>(buffer, 0x2c);
- // +0x16 | 24 00 | VOffset16 | 0x0024 (36) | offset to field `realtime_sent_time` (id: 2)
- buffer = Push<flatbuffers::voffset_t>(buffer, 0x24);
- // +0x18 | 34 00 | VOffset16 | 0x0034 (52) | offset to field `queue_index` (id: 3)
- buffer = Push<flatbuffers::voffset_t>(buffer, 0x34);
- // +0x1A | 00 00 | VOffset16 | 0x0000 (0) | offset to field `data` (id: 4) <null> (Vector)
- buffer = Push<flatbuffers::voffset_t>(buffer, 0x00);
- // +0x1C | 1C 00 | VOffset16 | 0x001C (28) | offset to field `monotonic_remote_time` (id: 5)
- buffer = Push<flatbuffers::voffset_t>(buffer, 0x1c);
- // +0x1E | 14 00 | VOffset16 | 0x0014 (20) | offset to field `realtime_remote_time` (id: 6)
- buffer = Push<flatbuffers::voffset_t>(buffer, 0x14);
- // +0x20 | 10 00 | VOffset16 | 0x0010 (16) | offset to field `remote_queue_index` (id: 7)
- buffer = Push<flatbuffers::voffset_t>(buffer, 0x10);
- // +0x22 | 04 00 | VOffset16 | 0x0004 (4) | offset to field `monotonic_timestamp_time` (id: 8)
- buffer = Push<flatbuffers::voffset_t>(buffer, 0x04);
- //
- // root_table (aos.logger.MessageHeader):
- // +0x24 | 16 00 00 00 | SOffset32 | 0x00000016 (22) Loc: +0x0E | offset to vtable
- buffer = Push<flatbuffers::uoffset_t>(buffer, 0x16);
- // +0x28 | F6 0B D8 11 A4 A8 B1 71 | int64_t | 0x71B1A8A411D80BF6 (8192514619791117302) | table field `monotonic_timestamp_time` (Long)
- buffer = Push<int64_t>(buffer,
- monotonic_timestamp_time.time_since_epoch().count());
- // +0x30 | 00 00 00 00 | uint8_t[4] | .... | padding
- // TODO(austin): Can we re-arrange the order to ditch the padding?
- // (Answer is yes, but what is the impact elsewhere? It will change the
- // binary format)
- buffer = Pad(buffer, 4);
- // +0x34 | 75 00 00 00 | uint32_t | 0x00000075 (117) | table field `remote_queue_index` (UInt)
- buffer = Push<uint32_t>(buffer, msg->remote_queue_index());
- // +0x38 | AA B0 43 0A 35 BE FA D2 | int64_t | 0xD2FABE350A43B0AA (-3244071446552268630) | table field `realtime_remote_time` (Long)
- buffer = Push<int64_t>(buffer, msg->realtime_remote_time());
- // +0x40 | D5 40 30 F3 C1 A7 26 1D | int64_t | 0x1D26A7C1F33040D5 (2100550727665467605) | table field `monotonic_remote_time` (Long)
- buffer = Push<int64_t>(buffer, msg->monotonic_remote_time());
- // +0x48 | 5B 25 32 A1 4A E8 46 CA | int64_t | 0xCA46E84AA132255B (-3871151422448720549) | table field `realtime_sent_time` (Long)
- buffer = Push<int64_t>(buffer, msg->realtime_sent_time());
- // +0x50 | 49 7D 45 1F 8C 36 6B A3 | int64_t | 0xA36B368C1F457D49 (-6671178447571288759) | table field `monotonic_sent_time` (Long)
- buffer = Push<int64_t>(buffer, msg->monotonic_sent_time());
- // +0x58 | 33 00 00 00 | uint32_t | 0x00000033 (51) | table field `queue_index` (UInt)
- buffer = Push<uint32_t>(buffer, msg->queue_index());
- // +0x5C | 76 00 00 00 | uint32_t | 0x00000076 (118) | table field `channel_index` (UInt)
- buffer = Push<uint32_t>(buffer, channel_index);
- // clang-format on
+ switch (start_byte) {
+ case 0x00u:
+ if ((end_byte) == 0x00u) {
+ break;
+ }
+ // clang-format off
+ // header:
+ // +0x00 | 5C 00 00 00 | UOffset32 | 0x0000005C (92) Loc: +0x5C | size prefix
+ buffer = Push<flatbuffers::uoffset_t>(
+ buffer, message_size - sizeof(flatbuffers::uoffset_t));
+ // +0x04 | 20 00 00 00 | UOffset32 | 0x00000020 (32) Loc: +0x24 | offset to root table `aos.logger.MessageHeader`
+ buffer = Push<flatbuffers::uoffset_t>(buffer, 0x20);
+ [[fallthrough]];
+ case 0x08u:
+ if ((end_byte) == 0x08u) {
+ break;
+ }
+ //
+ // padding:
+ // +0x08 | 00 00 00 00 00 00 | uint8_t[6] | ...... | padding
+ buffer = Pad(buffer, 6);
+ //
+ // vtable (aos.logger.MessageHeader):
+ // +0x0E | 16 00 | uint16_t | 0x0016 (22) | size of this vtable
+ buffer = Push<flatbuffers::voffset_t>(buffer, 0x16);
+ [[fallthrough]];
+ case 0x10u:
+ if ((end_byte) == 0x10u) {
+ break;
+ }
+ // +0x10 | 3C 00 | uint16_t | 0x003C (60) | size of referring table
+ buffer = Push<flatbuffers::voffset_t>(buffer, 0x3c);
+ // +0x12 | 38 00 | VOffset16 | 0x0038 (56) | offset to field `channel_index` (id: 0)
+ buffer = Push<flatbuffers::voffset_t>(buffer, 0x38);
+ // +0x14 | 2C 00 | VOffset16 | 0x002C (44) | offset to field `monotonic_sent_time` (id: 1)
+ buffer = Push<flatbuffers::voffset_t>(buffer, 0x2c);
+ // +0x16 | 24 00 | VOffset16 | 0x0024 (36) | offset to field `realtime_sent_time` (id: 2)
+ buffer = Push<flatbuffers::voffset_t>(buffer, 0x24);
+ [[fallthrough]];
+ case 0x18u:
+ if ((end_byte) == 0x18u) {
+ break;
+ }
+ // +0x18 | 34 00 | VOffset16 | 0x0034 (52) | offset to field `queue_index` (id: 3)
+ buffer = Push<flatbuffers::voffset_t>(buffer, 0x34);
+ // +0x1A | 00 00 | VOffset16 | 0x0000 (0) | offset to field `data` (id: 4) <null> (Vector)
+ buffer = Push<flatbuffers::voffset_t>(buffer, 0x00);
+ // +0x1C | 1C 00 | VOffset16 | 0x001C (28) | offset to field `monotonic_remote_time` (id: 5)
+ buffer = Push<flatbuffers::voffset_t>(buffer, 0x1c);
+ // +0x1E | 14 00 | VOffset16 | 0x0014 (20) | offset to field `realtime_remote_time` (id: 6)
+ buffer = Push<flatbuffers::voffset_t>(buffer, 0x14);
+ [[fallthrough]];
+ case 0x20u:
+ if ((end_byte) == 0x20u) {
+ break;
+ }
+ // +0x20 | 10 00 | VOffset16 | 0x0010 (16) | offset to field `remote_queue_index` (id: 7)
+ buffer = Push<flatbuffers::voffset_t>(buffer, 0x10);
+ // +0x22 | 04 00 | VOffset16 | 0x0004 (4) | offset to field `monotonic_timestamp_time` (id: 8)
+ buffer = Push<flatbuffers::voffset_t>(buffer, 0x04);
+ //
+ // root_table (aos.logger.MessageHeader):
+ // +0x24 | 16 00 00 00 | SOffset32 | 0x00000016 (22) Loc: +0x0E | offset to vtable
+ buffer = Push<flatbuffers::uoffset_t>(buffer, 0x16);
+ [[fallthrough]];
+ case 0x28u:
+ if ((end_byte) == 0x28u) {
+ break;
+ }
+ // +0x28 | F6 0B D8 11 A4 A8 B1 71 | int64_t | 0x71B1A8A411D80BF6 (8192514619791117302) | table field `monotonic_timestamp_time` (Long)
+ buffer = Push<int64_t>(buffer,
+ monotonic_timestamp_time.time_since_epoch().count());
+ [[fallthrough]];
+ case 0x30u:
+ if ((end_byte) == 0x30u) {
+ break;
+ }
+ // +0x30 | 00 00 00 00 | uint8_t[4] | .... | padding
+ // TODO(austin): Can we re-arrange the order to ditch the padding?
+ // (Answer is yes, but what is the impact elsewhere? It will change the
+ // binary format)
+ buffer = Pad(buffer, 4);
+ // +0x34 | 75 00 00 00 | uint32_t | 0x00000075 (117) | table field `remote_queue_index` (UInt)
+ buffer = Push<uint32_t>(buffer, msg->remote_queue_index());
+ [[fallthrough]];
+ case 0x38u:
+ if ((end_byte) == 0x38u) {
+ break;
+ }
+ // +0x38 | AA B0 43 0A 35 BE FA D2 | int64_t | 0xD2FABE350A43B0AA (-3244071446552268630) | table field `realtime_remote_time` (Long)
+ buffer = Push<int64_t>(buffer, msg->realtime_remote_time());
+ [[fallthrough]];
+ case 0x40u:
+ if ((end_byte) == 0x40u) {
+ break;
+ }
+ // +0x40 | D5 40 30 F3 C1 A7 26 1D | int64_t | 0x1D26A7C1F33040D5 (2100550727665467605) | table field `monotonic_remote_time` (Long)
+ buffer = Push<int64_t>(buffer, msg->monotonic_remote_time());
+ [[fallthrough]];
+ case 0x48u:
+ if ((end_byte) == 0x48u) {
+ break;
+ }
+ // +0x48 | 5B 25 32 A1 4A E8 46 CA | int64_t | 0xCA46E84AA132255B (-3871151422448720549) | table field `realtime_sent_time` (Long)
+ buffer = Push<int64_t>(buffer, msg->realtime_sent_time());
+ [[fallthrough]];
+ case 0x50u:
+ if ((end_byte) == 0x50u) {
+ break;
+ }
+ // +0x50 | 49 7D 45 1F 8C 36 6B A3 | int64_t | 0xA36B368C1F457D49 (-6671178447571288759) | table field `monotonic_sent_time` (Long)
+ buffer = Push<int64_t>(buffer, msg->monotonic_sent_time());
+ [[fallthrough]];
+ case 0x58u:
+ if ((end_byte) == 0x58u) {
+ break;
+ }
+ // +0x58 | 33 00 00 00 | uint32_t | 0x00000033 (51) | table field `queue_index` (UInt)
+ buffer = Push<uint32_t>(buffer, msg->queue_index());
+ // +0x5C | 76 00 00 00 | uint32_t | 0x00000076 (118) | table field `channel_index` (UInt)
+ buffer = Push<uint32_t>(buffer, channel_index);
+ // clang-format on
+ [[fallthrough]];
+ case 0x60u:
+ if ((end_byte) == 0x60u) {
+ break;
+ }
+ }
- return message_size;
+ return end_byte - start_byte;
}
flatbuffers::Offset<MessageHeader> PackMessage(
@@ -580,271 +651,565 @@
}
size_t PackMessageInline(uint8_t *buffer, const Context &context,
- int channel_index, LogType log_type) {
+ int channel_index, LogType log_type, size_t start_byte,
+ size_t end_byte) {
// TODO(austin): Figure out how to copy directly from shared memory instead of
// first into the fetcher's memory and then into here. That would save a lot
// of memory.
const flatbuffers::uoffset_t message_size =
PackMessageSize(log_type, context.size);
-
- buffer = Push<flatbuffers::uoffset_t>(
- buffer, message_size - sizeof(flatbuffers::uoffset_t));
+ DCHECK_EQ((message_size % 8), 0u) << ": Non 8 byte length...";
+ DCHECK_EQ((start_byte % 8u), 0u);
+ DCHECK_EQ((end_byte % 8u), 0u);
+ DCHECK_LE(start_byte, end_byte);
+ DCHECK_LE(end_byte, message_size);
// Pack all the data in. This is brittle but easy to change. Use the
// InlinePackMessage.Equivilent unit test to verify everything matches.
switch (log_type) {
case LogType::kLogMessage:
- // clang-format off
- // header:
- // +0x00 | 4C 00 00 00 | UOffset32 | 0x0000004C (76) Loc: +0x4C | size prefix
- // +0x04 | 18 00 00 00 | UOffset32 | 0x00000018 (24) Loc: +0x1C | offset to root table `aos.logger.MessageHeader`
- buffer = Push<flatbuffers::uoffset_t>(buffer, 0x18);
- //
- // padding:
- // +0x08 | 00 00 00 00 00 00 | uint8_t[6] | ...... | padding
- buffer = Pad(buffer, 6);
- //
- // vtable (aos.logger.MessageHeader):
- // +0x0E | 0E 00 | uint16_t | 0x000E (14) | size of this vtable
- buffer = Push<flatbuffers::voffset_t>(buffer, 0xe);
- // +0x10 | 20 00 | uint16_t | 0x0020 (32) | size of referring table
- buffer = Push<flatbuffers::voffset_t>(buffer, 0x20);
- // +0x12 | 1C 00 | VOffset16 | 0x001C (28) | offset to field `channel_index` (id: 0)
- buffer = Push<flatbuffers::voffset_t>(buffer, 0x1c);
- // +0x14 | 0C 00 | VOffset16 | 0x000C (12) | offset to field `monotonic_sent_time` (id: 1)
- buffer = Push<flatbuffers::voffset_t>(buffer, 0x0c);
- // +0x16 | 04 00 | VOffset16 | 0x0004 (4) | offset to field `realtime_sent_time` (id: 2)
- buffer = Push<flatbuffers::voffset_t>(buffer, 0x04);
- // +0x18 | 18 00 | VOffset16 | 0x0018 (24) | offset to field `queue_index` (id: 3)
- buffer = Push<flatbuffers::voffset_t>(buffer, 0x18);
- // +0x1A | 14 00 | VOffset16 | 0x0014 (20) | offset to field `data` (id: 4)
- buffer = Push<flatbuffers::voffset_t>(buffer, 0x14);
- //
- // root_table (aos.logger.MessageHeader):
- // +0x1C | 0E 00 00 00 | SOffset32 | 0x0000000E (14) Loc: +0x0E | offset to vtable
- buffer = Push<flatbuffers::uoffset_t>(buffer, 0x0e);
- // +0x20 | B2 E4 EF 89 19 7D 7F 6F | int64_t | 0x6F7F7D1989EFE4B2 (8034277808894108850) | table field `realtime_sent_time` (Long)
- buffer = Push<int64_t>(buffer, context.realtime_event_time.time_since_epoch().count());
- // +0x28 | 86 8D 92 65 FC 79 74 2B | int64_t | 0x2B7479FC65928D86 (3131261765872160134) | table field `monotonic_sent_time` (Long)
- buffer = Push<int64_t>(buffer, context.monotonic_event_time.time_since_epoch().count());
- // +0x30 | 0C 00 00 00 | UOffset32 | 0x0000000C (12) Loc: +0x3C | offset to field `data` (vector)
- buffer = Push<flatbuffers::uoffset_t>(buffer, 0x0c);
- // +0x34 | 86 00 00 00 | uint32_t | 0x00000086 (134) | table field `queue_index` (UInt)
- buffer = Push<uint32_t>(buffer, context.queue_index);
- // +0x38 | 71 00 00 00 | uint32_t | 0x00000071 (113) | table field `channel_index` (UInt)
- buffer = Push<uint32_t>(buffer, channel_index);
- //
- // vector (aos.logger.MessageHeader.data):
- // +0x3C | 0E 00 00 00 | uint32_t | 0x0000000E (14) | length of vector (# items)
- buffer = Push<flatbuffers::uoffset_t>(buffer, context.size);
- // +0x40 | FF | uint8_t | 0xFF (255) | value[0]
- // +0x41 | B8 | uint8_t | 0xB8 (184) | value[1]
- // +0x42 | EE | uint8_t | 0xEE (238) | value[2]
- // +0x43 | 00 | uint8_t | 0x00 (0) | value[3]
- // +0x44 | 20 | uint8_t | 0x20 (32) | value[4]
- // +0x45 | 4D | uint8_t | 0x4D (77) | value[5]
- // +0x46 | FF | uint8_t | 0xFF (255) | value[6]
- // +0x47 | 25 | uint8_t | 0x25 (37) | value[7]
- // +0x48 | 3C | uint8_t | 0x3C (60) | value[8]
- // +0x49 | 17 | uint8_t | 0x17 (23) | value[9]
- // +0x4A | 65 | uint8_t | 0x65 (101) | value[10]
- // +0x4B | 2F | uint8_t | 0x2F (47) | value[11]
- // +0x4C | 63 | uint8_t | 0x63 (99) | value[12]
- // +0x4D | 58 | uint8_t | 0x58 (88) | value[13]
- buffer = PushBytes(buffer, context.data, context.size);
- //
- // padding:
- // +0x4E | 00 00 | uint8_t[2] | .. | padding
- buffer = Pad(buffer, ((context.size + 7) & 0xfffffff8u) - context.size);
- // clang-format on
+ switch (start_byte) {
+ case 0x00u:
+ if ((end_byte) == 0x00u) {
+ break;
+ }
+ // clang-format off
+ // header:
+ // +0x00 | 4C 00 00 00 | UOffset32 | 0x0000004C (76) Loc: +0x4C | size prefix
+ buffer = Push<flatbuffers::uoffset_t>(
+ buffer, message_size - sizeof(flatbuffers::uoffset_t));
+
+ // +0x04 | 18 00 00 00 | UOffset32 | 0x00000018 (24) Loc: +0x1C | offset to root table `aos.logger.MessageHeader`
+ buffer = Push<flatbuffers::uoffset_t>(buffer, 0x18);
+ [[fallthrough]];
+ case 0x08u:
+ if ((end_byte) == 0x08u) {
+ break;
+ }
+ //
+ // padding:
+ // +0x08 | 00 00 00 00 00 00 | uint8_t[6] | ...... | padding
+ buffer = Pad(buffer, 6);
+ //
+ // vtable (aos.logger.MessageHeader):
+ // +0x0E | 0E 00 | uint16_t | 0x000E (14) | size of this vtable
+ buffer = Push<flatbuffers::voffset_t>(buffer, 0xe);
+ [[fallthrough]];
+ case 0x10u:
+ if ((end_byte) == 0x10u) {
+ break;
+ }
+ // +0x10 | 20 00 | uint16_t | 0x0020 (32) | size of referring table
+ buffer = Push<flatbuffers::voffset_t>(buffer, 0x20);
+ // +0x12 | 1C 00 | VOffset16 | 0x001C (28) | offset to field `channel_index` (id: 0)
+ buffer = Push<flatbuffers::voffset_t>(buffer, 0x1c);
+ // +0x14 | 0C 00 | VOffset16 | 0x000C (12) | offset to field `monotonic_sent_time` (id: 1)
+ buffer = Push<flatbuffers::voffset_t>(buffer, 0x0c);
+ // +0x16 | 04 00 | VOffset16 | 0x0004 (4) | offset to field `realtime_sent_time` (id: 2)
+ buffer = Push<flatbuffers::voffset_t>(buffer, 0x04);
+ [[fallthrough]];
+ case 0x18u:
+ if ((end_byte) == 0x18u) {
+ break;
+ }
+ // +0x18 | 18 00 | VOffset16 | 0x0018 (24) | offset to field `queue_index` (id: 3)
+ buffer = Push<flatbuffers::voffset_t>(buffer, 0x18);
+ // +0x1A | 14 00 | VOffset16 | 0x0014 (20) | offset to field `data` (id: 4)
+ buffer = Push<flatbuffers::voffset_t>(buffer, 0x14);
+ //
+ // root_table (aos.logger.MessageHeader):
+ // +0x1C | 0E 00 00 00 | SOffset32 | 0x0000000E (14) Loc: +0x0E | offset to vtable
+ buffer = Push<flatbuffers::uoffset_t>(buffer, 0x0e);
+ [[fallthrough]];
+ case 0x20u:
+ if ((end_byte) == 0x20u) {
+ break;
+ }
+ // +0x20 | B2 E4 EF 89 19 7D 7F 6F | int64_t | 0x6F7F7D1989EFE4B2 (8034277808894108850) | table field `realtime_sent_time` (Long)
+ buffer = Push<int64_t>(buffer, context.realtime_event_time.time_since_epoch().count());
+ [[fallthrough]];
+ case 0x28u:
+ if ((end_byte) == 0x28u) {
+ break;
+ }
+ // +0x28 | 86 8D 92 65 FC 79 74 2B | int64_t | 0x2B7479FC65928D86 (3131261765872160134) | table field `monotonic_sent_time` (Long)
+ buffer = Push<int64_t>(buffer, context.monotonic_event_time.time_since_epoch().count());
+ [[fallthrough]];
+ case 0x30u:
+ if ((end_byte) == 0x30u) {
+ break;
+ }
+ // +0x30 | 0C 00 00 00 | UOffset32 | 0x0000000C (12) Loc: +0x3C | offset to field `data` (vector)
+ buffer = Push<flatbuffers::uoffset_t>(buffer, 0x0c);
+ // +0x34 | 86 00 00 00 | uint32_t | 0x00000086 (134) | table field `queue_index` (UInt)
+ buffer = Push<uint32_t>(buffer, context.queue_index);
+ [[fallthrough]];
+ case 0x38u:
+ if ((end_byte) == 0x38u) {
+ break;
+ }
+ // +0x38 | 71 00 00 00 | uint32_t | 0x00000071 (113) | table field `channel_index` (UInt)
+ buffer = Push<uint32_t>(buffer, channel_index);
+ //
+ // vector (aos.logger.MessageHeader.data):
+ // +0x3C | 0E 00 00 00 | uint32_t | 0x0000000E (14) | length of vector (# items)
+ buffer = Push<flatbuffers::uoffset_t>(buffer, context.size);
+ [[fallthrough]];
+ case 0x40u:
+ if ((end_byte) == 0x40u) {
+ break;
+ }
+ [[fallthrough]];
+ default:
+ // +0x40 | FF | uint8_t | 0xFF (255) | value[0]
+ // +0x41 | B8 | uint8_t | 0xB8 (184) | value[1]
+ // +0x42 | EE | uint8_t | 0xEE (238) | value[2]
+ // +0x43 | 00 | uint8_t | 0x00 (0) | value[3]
+ // +0x44 | 20 | uint8_t | 0x20 (32) | value[4]
+ // +0x45 | 4D | uint8_t | 0x4D (77) | value[5]
+ // +0x46 | FF | uint8_t | 0xFF (255) | value[6]
+ // +0x47 | 25 | uint8_t | 0x25 (37) | value[7]
+ // +0x48 | 3C | uint8_t | 0x3C (60) | value[8]
+ // +0x49 | 17 | uint8_t | 0x17 (23) | value[9]
+ // +0x4A | 65 | uint8_t | 0x65 (101) | value[10]
+ // +0x4B | 2F | uint8_t | 0x2F (47) | value[11]
+ // +0x4C | 63 | uint8_t | 0x63 (99) | value[12]
+ // +0x4D | 58 | uint8_t | 0x58 (88) | value[13]
+ //
+ // padding:
+ // +0x4E | 00 00 | uint8_t[2] | .. | padding
+ // clang-format on
+ if (start_byte <= 0x40 && end_byte == message_size) {
+ // The easy one, slap it all down.
+ buffer = PushBytes(buffer, context.data, context.size);
+ buffer =
+ Pad(buffer, ((context.size + 7) & 0xfffffff8u) - context.size);
+ } else {
+ const size_t data_start_byte =
+ start_byte < 0x40 ? 0x0u : (start_byte - 0x40);
+ const size_t data_end_byte = end_byte - 0x40;
+ const size_t padded_size = ((context.size + 7) & 0xfffffff8u);
+ if (data_start_byte < padded_size) {
+ buffer = PushBytes(
+ buffer,
+ reinterpret_cast<const uint8_t *>(context.data) +
+ data_start_byte,
+ std::min(context.size, data_end_byte) - data_start_byte);
+ if (data_end_byte == padded_size) {
+ // We can only pad the last 7 bytes, so this only gets written
+ // if we write the last byte.
+ buffer = Pad(buffer,
+ ((context.size + 7) & 0xfffffff8u) - context.size);
+ }
+ }
+ }
+ break;
+ }
break;
case LogType::kLogDeliveryTimeOnly:
- // clang-format off
- // header:
- // +0x00 | 4C 00 00 00 | UOffset32 | 0x0000004C (76) Loc: +0x4C | size prefix
- // +0x04 | 1C 00 00 00 | UOffset32 | 0x0000001C (28) Loc: +0x20 | offset to root table `aos.logger.MessageHeader`
- buffer = Push<flatbuffers::uoffset_t>(buffer, 0x1c);
- //
- // padding:
- // +0x08 | 00 00 00 00 | uint8_t[4] | .... | padding
- buffer = Pad(buffer, 4);
- //
- // vtable (aos.logger.MessageHeader):
- // +0x0C | 14 00 | uint16_t | 0x0014 (20) | size of this vtable
- buffer = Push<flatbuffers::voffset_t>(buffer, 0x14);
- // +0x0E | 30 00 | uint16_t | 0x0030 (48) | size of referring table
- buffer = Push<flatbuffers::voffset_t>(buffer, 0x30);
- // +0x10 | 2C 00 | VOffset16 | 0x002C (44) | offset to field `channel_index` (id: 0)
- buffer = Push<flatbuffers::voffset_t>(buffer, 0x2c);
- // +0x12 | 20 00 | VOffset16 | 0x0020 (32) | offset to field `monotonic_sent_time` (id: 1)
- buffer = Push<flatbuffers::voffset_t>(buffer, 0x20);
- // +0x14 | 18 00 | VOffset16 | 0x0018 (24) | offset to field `realtime_sent_time` (id: 2)
- buffer = Push<flatbuffers::voffset_t>(buffer, 0x18);
- // +0x16 | 28 00 | VOffset16 | 0x0028 (40) | offset to field `queue_index` (id: 3)
- buffer = Push<flatbuffers::voffset_t>(buffer, 0x28);
- // +0x18 | 00 00 | VOffset16 | 0x0000 (0) | offset to field `data` (id: 4) <null> (Vector)
- buffer = Push<flatbuffers::voffset_t>(buffer, 0x00);
- // +0x1A | 10 00 | VOffset16 | 0x0010 (16) | offset to field `monotonic_remote_time` (id: 5)
- buffer = Push<flatbuffers::voffset_t>(buffer, 0x10);
- // +0x1C | 08 00 | VOffset16 | 0x0008 (8) | offset to field `realtime_remote_time` (id: 6)
- buffer = Push<flatbuffers::voffset_t>(buffer, 0x08);
- // +0x1E | 04 00 | VOffset16 | 0x0004 (4) | offset to field `remote_queue_index` (id: 7)
- buffer = Push<flatbuffers::voffset_t>(buffer, 0x04);
- //
- // root_table (aos.logger.MessageHeader):
- // +0x20 | 14 00 00 00 | SOffset32 | 0x00000014 (20) Loc: +0x0C | offset to vtable
- buffer = Push<flatbuffers::uoffset_t>(buffer, 0x14);
- // +0x24 | 69 00 00 00 | uint32_t | 0x00000069 (105) | table field `remote_queue_index` (UInt)
- buffer = Push<uint32_t>(buffer, context.remote_queue_index);
- // +0x28 | C6 85 F1 AB 83 B5 CD EB | int64_t | 0xEBCDB583ABF185C6 (-1455307527440726586) | table field `realtime_remote_time` (Long)
- buffer = Push<int64_t>(buffer, context.realtime_remote_time.time_since_epoch().count());
- // +0x30 | 47 24 D3 97 1E 42 2D 99 | int64_t | 0x992D421E97D32447 (-7409193112790948793) | table field `monotonic_remote_time` (Long)
- buffer = Push<int64_t>(buffer, context.monotonic_remote_time.time_since_epoch().count());
- // +0x38 | C8 B9 A7 AB 79 F2 CD 60 | int64_t | 0x60CDF279ABA7B9C8 (6975498002251626952) | table field `realtime_sent_time` (Long)
- buffer = Push<int64_t>(buffer, context.realtime_event_time.time_since_epoch().count());
- // +0x40 | EA 8F 2A 0F AF 01 7A AB | int64_t | 0xAB7A01AF0F2A8FEA (-6090553694679822358) | table field `monotonic_sent_time` (Long)
- buffer = Push<int64_t>(buffer, context.monotonic_event_time.time_since_epoch().count());
- // +0x48 | F5 00 00 00 | uint32_t | 0x000000F5 (245) | table field `queue_index` (UInt)
- buffer = Push<uint32_t>(buffer, context.queue_index);
- // +0x4C | 88 00 00 00 | uint32_t | 0x00000088 (136) | table field `channel_index` (UInt)
- buffer = Push<uint32_t>(buffer, channel_index);
+ switch (start_byte) {
+ case 0x00u:
+ if ((end_byte) == 0x00u) {
+ break;
+ }
+ // clang-format off
+ // header:
+ // +0x00 | 4C 00 00 00 | UOffset32 | 0x0000004C (76) Loc: +0x4C | size prefix
+ buffer = Push<flatbuffers::uoffset_t>(
+ buffer, message_size - sizeof(flatbuffers::uoffset_t));
+ // +0x04 | 1C 00 00 00 | UOffset32 | 0x0000001C (28) Loc: +0x20 | offset to root table `aos.logger.MessageHeader`
+ buffer = Push<flatbuffers::uoffset_t>(buffer, 0x1c);
- // clang-format on
+ [[fallthrough]];
+ case 0x08u:
+ if ((end_byte) == 0x08u) {
+ break;
+ }
+ //
+ // padding:
+ // +0x08 | 00 00 00 00 | uint8_t[4] | .... | padding
+ buffer = Pad(buffer, 4);
+ //
+ // vtable (aos.logger.MessageHeader):
+ // +0x0C | 14 00 | uint16_t | 0x0014 (20) | size of this vtable
+ buffer = Push<flatbuffers::voffset_t>(buffer, 0x14);
+ // +0x0E | 30 00 | uint16_t | 0x0030 (48) | size of referring table
+ buffer = Push<flatbuffers::voffset_t>(buffer, 0x30);
+ [[fallthrough]];
+ case 0x10u:
+ if ((end_byte) == 0x10u) {
+ break;
+ }
+ // +0x10 | 2C 00 | VOffset16 | 0x002C (44) | offset to field `channel_index` (id: 0)
+ buffer = Push<flatbuffers::voffset_t>(buffer, 0x2c);
+ // +0x12 | 20 00 | VOffset16 | 0x0020 (32) | offset to field `monotonic_sent_time` (id: 1)
+ buffer = Push<flatbuffers::voffset_t>(buffer, 0x20);
+ // +0x14 | 18 00 | VOffset16 | 0x0018 (24) | offset to field `realtime_sent_time` (id: 2)
+ buffer = Push<flatbuffers::voffset_t>(buffer, 0x18);
+ // +0x16 | 28 00 | VOffset16 | 0x0028 (40) | offset to field `queue_index` (id: 3)
+ buffer = Push<flatbuffers::voffset_t>(buffer, 0x28);
+ [[fallthrough]];
+ case 0x18u:
+ if ((end_byte) == 0x18u) {
+ break;
+ }
+ // +0x18 | 00 00 | VOffset16 | 0x0000 (0) | offset to field `data` (id: 4) <null> (Vector)
+ buffer = Push<flatbuffers::voffset_t>(buffer, 0x00);
+ // +0x1A | 10 00 | VOffset16 | 0x0010 (16) | offset to field `monotonic_remote_time` (id: 5)
+ buffer = Push<flatbuffers::voffset_t>(buffer, 0x10);
+ // +0x1C | 08 00 | VOffset16 | 0x0008 (8) | offset to field `realtime_remote_time` (id: 6)
+ buffer = Push<flatbuffers::voffset_t>(buffer, 0x08);
+ // +0x1E | 04 00 | VOffset16 | 0x0004 (4) | offset to field `remote_queue_index` (id: 7)
+ buffer = Push<flatbuffers::voffset_t>(buffer, 0x04);
+ [[fallthrough]];
+ case 0x20u:
+ if ((end_byte) == 0x20u) {
+ break;
+ }
+ //
+ // root_table (aos.logger.MessageHeader):
+ // +0x20 | 14 00 00 00 | SOffset32 | 0x00000014 (20) Loc: +0x0C | offset to vtable
+ buffer = Push<flatbuffers::uoffset_t>(buffer, 0x14);
+ // +0x24 | 69 00 00 00 | uint32_t | 0x00000069 (105) | table field `remote_queue_index` (UInt)
+ buffer = Push<uint32_t>(buffer, context.remote_queue_index);
+ [[fallthrough]];
+ case 0x28u:
+ if ((end_byte) == 0x28u) {
+ break;
+ }
+ // +0x28 | C6 85 F1 AB 83 B5 CD EB | int64_t | 0xEBCDB583ABF185C6 (-1455307527440726586) | table field `realtime_remote_time` (Long)
+ buffer = Push<int64_t>(buffer, context.realtime_remote_time.time_since_epoch().count());
+ [[fallthrough]];
+ case 0x30u:
+ if ((end_byte) == 0x30u) {
+ break;
+ }
+ // +0x30 | 47 24 D3 97 1E 42 2D 99 | int64_t | 0x992D421E97D32447 (-7409193112790948793) | table field `monotonic_remote_time` (Long)
+ buffer = Push<int64_t>(buffer, context.monotonic_remote_time.time_since_epoch().count());
+ [[fallthrough]];
+ case 0x38u:
+ if ((end_byte) == 0x38u) {
+ break;
+ }
+ // +0x38 | C8 B9 A7 AB 79 F2 CD 60 | int64_t | 0x60CDF279ABA7B9C8 (6975498002251626952) | table field `realtime_sent_time` (Long)
+ buffer = Push<int64_t>(buffer, context.realtime_event_time.time_since_epoch().count());
+ [[fallthrough]];
+ case 0x40u:
+ if ((end_byte) == 0x40u) {
+ break;
+ }
+ // +0x40 | EA 8F 2A 0F AF 01 7A AB | int64_t | 0xAB7A01AF0F2A8FEA (-6090553694679822358) | table field `monotonic_sent_time` (Long)
+ buffer = Push<int64_t>(buffer, context.monotonic_event_time.time_since_epoch().count());
+ [[fallthrough]];
+ case 0x48u:
+ if ((end_byte) == 0x48u) {
+ break;
+ }
+ // +0x48 | F5 00 00 00 | uint32_t | 0x000000F5 (245) | table field `queue_index` (UInt)
+ buffer = Push<uint32_t>(buffer, context.queue_index);
+ // +0x4C | 88 00 00 00 | uint32_t | 0x00000088 (136) | table field `channel_index` (UInt)
+ buffer = Push<uint32_t>(buffer, channel_index);
+
+ // clang-format on
+ }
break;
case LogType::kLogMessageAndDeliveryTime:
- // clang-format off
- // header:
- // +0x00 | 5C 00 00 00 | UOffset32 | 0x0000005C (92) Loc: +0x5C | size prefix
- // +0x04 | 1C 00 00 00 | UOffset32 | 0x0000001C (28) Loc: +0x20 | offset to root table `aos.logger.MessageHeader`
- buffer = Push<flatbuffers::uoffset_t>(buffer, 0x1c);
- //
- // padding:
- // +0x08 | 00 00 00 00 | uint8_t[4] | .... | padding
- buffer = Pad(buffer, 4);
- //
- // vtable (aos.logger.MessageHeader):
- // +0x0C | 14 00 | uint16_t | 0x0014 (20) | size of this vtable
- buffer = Push<flatbuffers::voffset_t>(buffer, 0x14);
- // +0x0E | 34 00 | uint16_t | 0x0034 (52) | size of referring table
- buffer = Push<flatbuffers::voffset_t>(buffer, 0x34);
- // +0x10 | 30 00 | VOffset16 | 0x0030 (48) | offset to field `channel_index` (id: 0)
- buffer = Push<flatbuffers::voffset_t>(buffer, 0x30);
- // +0x12 | 20 00 | VOffset16 | 0x0020 (32) | offset to field `monotonic_sent_time` (id: 1)
- buffer = Push<flatbuffers::voffset_t>(buffer, 0x20);
- // +0x14 | 18 00 | VOffset16 | 0x0018 (24) | offset to field `realtime_sent_time` (id: 2)
- buffer = Push<flatbuffers::voffset_t>(buffer, 0x18);
- // +0x16 | 2C 00 | VOffset16 | 0x002C (44) | offset to field `queue_index` (id: 3)
- buffer = Push<flatbuffers::voffset_t>(buffer, 0x2c);
- // +0x18 | 04 00 | VOffset16 | 0x0004 (4) | offset to field `data` (id: 4)
- buffer = Push<flatbuffers::voffset_t>(buffer, 0x04);
- // +0x1A | 10 00 | VOffset16 | 0x0010 (16) | offset to field `monotonic_remote_time` (id: 5)
- buffer = Push<flatbuffers::voffset_t>(buffer, 0x10);
- // +0x1C | 08 00 | VOffset16 | 0x0008 (8) | offset to field `realtime_remote_time` (id: 6)
- buffer = Push<flatbuffers::voffset_t>(buffer, 0x08);
- // +0x1E | 28 00 | VOffset16 | 0x0028 (40) | offset to field `remote_queue_index` (id: 7)
- buffer = Push<flatbuffers::voffset_t>(buffer, 0x28);
- //
- // root_table (aos.logger.MessageHeader):
- // +0x20 | 14 00 00 00 | SOffset32 | 0x00000014 (20) Loc: +0x0C | offset to vtable
- buffer = Push<flatbuffers::uoffset_t>(buffer, 0x14);
- // +0x24 | 30 00 00 00 | UOffset32 | 0x00000030 (48) Loc: +0x54 | offset to field `data` (vector)
- buffer = Push<flatbuffers::uoffset_t>(buffer, 0x30);
- // +0x28 | C4 C8 87 BF 40 6C 1F 29 | int64_t | 0x291F6C40BF87C8C4 (2963206105180129476) | table field `realtime_remote_time` (Long)
- buffer = Push<int64_t>(buffer, context.realtime_remote_time.time_since_epoch().count());
- // +0x30 | 0F 00 26 FD D2 6D C0 1F | int64_t | 0x1FC06DD2FD26000F (2287949363661897743) | table field `monotonic_remote_time` (Long)
- buffer = Push<int64_t>(buffer, context.monotonic_remote_time.time_since_epoch().count());
- // +0x38 | 29 75 09 C0 73 73 BF 88 | int64_t | 0x88BF7373C0097529 (-8593022623019338455) | table field `realtime_sent_time` (Long)
- buffer = Push<int64_t>(buffer, context.realtime_event_time.time_since_epoch().count());
- // +0x40 | 6D 8A AE 04 50 25 9C E9 | int64_t | 0xE99C255004AE8A6D (-1613373540899321235) | table field `monotonic_sent_time` (Long)
- buffer = Push<int64_t>(buffer, context.monotonic_event_time.time_since_epoch().count());
- // +0x48 | 47 00 00 00 | uint32_t | 0x00000047 (71) | table field `remote_queue_index` (UInt)
- buffer = Push<uint32_t>(buffer, context.remote_queue_index);
- // +0x4C | 4C 00 00 00 | uint32_t | 0x0000004C (76) | table field `queue_index` (UInt)
- buffer = Push<uint32_t>(buffer, context.queue_index);
- // +0x50 | 72 00 00 00 | uint32_t | 0x00000072 (114) | table field `channel_index` (UInt)
- buffer = Push<uint32_t>(buffer, channel_index);
- //
- // vector (aos.logger.MessageHeader.data):
- // +0x54 | 07 00 00 00 | uint32_t | 0x00000007 (7) | length of vector (# items)
- buffer = Push<flatbuffers::uoffset_t>(buffer, context.size);
- // +0x58 | B1 | uint8_t | 0xB1 (177) | value[0]
- // +0x59 | 4A | uint8_t | 0x4A (74) | value[1]
- // +0x5A | 50 | uint8_t | 0x50 (80) | value[2]
- // +0x5B | 24 | uint8_t | 0x24 (36) | value[3]
- // +0x5C | AF | uint8_t | 0xAF (175) | value[4]
- // +0x5D | C8 | uint8_t | 0xC8 (200) | value[5]
- // +0x5E | D5 | uint8_t | 0xD5 (213) | value[6]
- buffer = PushBytes(buffer, context.data, context.size);
- //
- // padding:
- // +0x5F | 00 | uint8_t[1] | . | padding
- buffer = Pad(buffer, ((context.size + 7) & 0xfffffff8u) - context.size);
- // clang-format on
+ switch (start_byte) {
+ case 0x00u:
+ if ((end_byte) == 0x00u) {
+ break;
+ }
+ // clang-format off
+ // header:
+ // +0x00 | 5C 00 00 00 | UOffset32 | 0x0000005C (92) Loc: +0x5C | size prefix
+ buffer = Push<flatbuffers::uoffset_t>(
+ buffer, message_size - sizeof(flatbuffers::uoffset_t));
+ // +0x04 | 1C 00 00 00 | UOffset32 | 0x0000001C (28) Loc: +0x20 | offset to root table `aos.logger.MessageHeader`
+ buffer = Push<flatbuffers::uoffset_t>(buffer, 0x1c);
+ [[fallthrough]];
+ case 0x08u:
+ if ((end_byte) == 0x08u) {
+ break;
+ }
+ //
+ // padding:
+ // +0x08 | 00 00 00 00 | uint8_t[4] | .... | padding
+ buffer = Pad(buffer, 4);
+ //
+ // vtable (aos.logger.MessageHeader):
+ // +0x0C | 14 00 | uint16_t | 0x0014 (20) | size of this vtable
+ buffer = Push<flatbuffers::voffset_t>(buffer, 0x14);
+ // +0x0E | 34 00 | uint16_t | 0x0034 (52) | size of referring table
+ buffer = Push<flatbuffers::voffset_t>(buffer, 0x34);
+ [[fallthrough]];
+ case 0x10u:
+ if ((end_byte) == 0x10u) {
+ break;
+ }
+ // +0x10 | 30 00 | VOffset16 | 0x0030 (48) | offset to field `channel_index` (id: 0)
+ buffer = Push<flatbuffers::voffset_t>(buffer, 0x30);
+ // +0x12 | 20 00 | VOffset16 | 0x0020 (32) | offset to field `monotonic_sent_time` (id: 1)
+ buffer = Push<flatbuffers::voffset_t>(buffer, 0x20);
+ // +0x14 | 18 00 | VOffset16 | 0x0018 (24) | offset to field `realtime_sent_time` (id: 2)
+ buffer = Push<flatbuffers::voffset_t>(buffer, 0x18);
+ // +0x16 | 2C 00 | VOffset16 | 0x002C (44) | offset to field `queue_index` (id: 3)
+ buffer = Push<flatbuffers::voffset_t>(buffer, 0x2c);
+ [[fallthrough]];
+ case 0x18u:
+ if ((end_byte) == 0x18u) {
+ break;
+ }
+ // +0x18 | 04 00 | VOffset16 | 0x0004 (4) | offset to field `data` (id: 4)
+ buffer = Push<flatbuffers::voffset_t>(buffer, 0x04);
+ // +0x1A | 10 00 | VOffset16 | 0x0010 (16) | offset to field `monotonic_remote_time` (id: 5)
+ buffer = Push<flatbuffers::voffset_t>(buffer, 0x10);
+ // +0x1C | 08 00 | VOffset16 | 0x0008 (8) | offset to field `realtime_remote_time` (id: 6)
+ buffer = Push<flatbuffers::voffset_t>(buffer, 0x08);
+ // +0x1E | 28 00 | VOffset16 | 0x0028 (40) | offset to field `remote_queue_index` (id: 7)
+ buffer = Push<flatbuffers::voffset_t>(buffer, 0x28);
+ [[fallthrough]];
+ case 0x20u:
+ if ((end_byte) == 0x20u) {
+ break;
+ }
+ //
+ // root_table (aos.logger.MessageHeader):
+ // +0x20 | 14 00 00 00 | SOffset32 | 0x00000014 (20) Loc: +0x0C | offset to vtable
+ buffer = Push<flatbuffers::uoffset_t>(buffer, 0x14);
+ // +0x24 | 30 00 00 00 | UOffset32 | 0x00000030 (48) Loc: +0x54 | offset to field `data` (vector)
+ buffer = Push<flatbuffers::uoffset_t>(buffer, 0x30);
+ [[fallthrough]];
+ case 0x28u:
+ if ((end_byte) == 0x28u) {
+ break;
+ }
+ // +0x28 | C4 C8 87 BF 40 6C 1F 29 | int64_t | 0x291F6C40BF87C8C4 (2963206105180129476) | table field `realtime_remote_time` (Long)
+ buffer = Push<int64_t>(buffer, context.realtime_remote_time.time_since_epoch().count());
+ [[fallthrough]];
+ case 0x30u:
+ if ((end_byte) == 0x30u) {
+ break;
+ }
+ // +0x30 | 0F 00 26 FD D2 6D C0 1F | int64_t | 0x1FC06DD2FD26000F (2287949363661897743) | table field `monotonic_remote_time` (Long)
+ buffer = Push<int64_t>(buffer, context.monotonic_remote_time.time_since_epoch().count());
+ [[fallthrough]];
+ case 0x38u:
+ if ((end_byte) == 0x38u) {
+ break;
+ }
+ // +0x38 | 29 75 09 C0 73 73 BF 88 | int64_t | 0x88BF7373C0097529 (-8593022623019338455) | table field `realtime_sent_time` (Long)
+ buffer = Push<int64_t>(buffer, context.realtime_event_time.time_since_epoch().count());
+ [[fallthrough]];
+ case 0x40u:
+ if ((end_byte) == 0x40u) {
+ break;
+ }
+ // +0x40 | 6D 8A AE 04 50 25 9C E9 | int64_t | 0xE99C255004AE8A6D (-1613373540899321235) | table field `monotonic_sent_time` (Long)
+ buffer = Push<int64_t>(buffer, context.monotonic_event_time.time_since_epoch().count());
+ [[fallthrough]];
+ case 0x48u:
+ if ((end_byte) == 0x48u) {
+ break;
+ }
+ // +0x48 | 47 00 00 00 | uint32_t | 0x00000047 (71) | table field `remote_queue_index` (UInt)
+ buffer = Push<uint32_t>(buffer, context.remote_queue_index);
+ // +0x4C | 4C 00 00 00 | uint32_t | 0x0000004C (76) | table field `queue_index` (UInt)
+ buffer = Push<uint32_t>(buffer, context.queue_index);
+ [[fallthrough]];
+ case 0x50u:
+ if ((end_byte) == 0x50u) {
+ break;
+ }
+ // +0x50 | 72 00 00 00 | uint32_t | 0x00000072 (114) | table field `channel_index` (UInt)
+ buffer = Push<uint32_t>(buffer, channel_index);
+ //
+ // vector (aos.logger.MessageHeader.data):
+ // +0x54 | 07 00 00 00 | uint32_t | 0x00000007 (7) | length of vector (# items)
+ buffer = Push<flatbuffers::uoffset_t>(buffer, context.size);
+ [[fallthrough]];
+ case 0x58u:
+ if ((end_byte) == 0x58u) {
+ break;
+ }
+ [[fallthrough]];
+ default:
+ // +0x58 | B1 | uint8_t | 0xB1 (177) | value[0]
+ // +0x59 | 4A | uint8_t | 0x4A (74) | value[1]
+ // +0x5A | 50 | uint8_t | 0x50 (80) | value[2]
+ // +0x5B | 24 | uint8_t | 0x24 (36) | value[3]
+ // +0x5C | AF | uint8_t | 0xAF (175) | value[4]
+ // +0x5D | C8 | uint8_t | 0xC8 (200) | value[5]
+ // +0x5E | D5 | uint8_t | 0xD5 (213) | value[6]
+ //
+ // padding:
+ // +0x5F | 00 | uint8_t[1] | . | padding
+ // clang-format on
+
+ if (start_byte <= 0x58 && end_byte == message_size) {
+ // The easy one, slap it all down.
+ buffer = PushBytes(buffer, context.data, context.size);
+ buffer =
+ Pad(buffer, ((context.size + 7) & 0xfffffff8u) - context.size);
+ } else {
+ const size_t data_start_byte =
+ start_byte < 0x58 ? 0x0u : (start_byte - 0x58);
+ const size_t data_end_byte = end_byte - 0x58;
+ const size_t padded_size = ((context.size + 7) & 0xfffffff8u);
+ if (data_start_byte < padded_size) {
+ buffer = PushBytes(
+ buffer,
+ reinterpret_cast<const uint8_t *>(context.data) +
+ data_start_byte,
+ std::min(context.size, data_end_byte) - data_start_byte);
+ if (data_end_byte == padded_size) {
+ // We can only pad the last 7 bytes, so this only gets written
+ // if we write the last byte.
+ buffer = Pad(buffer,
+ ((context.size + 7) & 0xfffffff8u) - context.size);
+ }
+ }
+ }
+
+ break;
+ }
break;
case LogType::kLogRemoteMessage:
- // This is the message we need to recreate.
- //
- // clang-format off
- // header:
- // +0x00 | 5C 00 00 00 | UOffset32 | 0x0000005C (92) Loc: +0x5C | size prefix
- // +0x04 | 18 00 00 00 | UOffset32 | 0x00000018 (24) Loc: +0x1C | offset to root table `aos.logger.MessageHeader`
- buffer = Push<flatbuffers::uoffset_t>(buffer, 0x18);
- //
- // padding:
- // +0x08 | 00 00 00 00 00 00 | uint8_t[6] | ...... | padding
- buffer = Pad(buffer, 6);
- //
- // vtable (aos.logger.MessageHeader):
- // +0x0E | 0E 00 | uint16_t | 0x000E (14) | size of this vtable
- buffer = Push<flatbuffers::voffset_t>(buffer, 0x0e);
- // +0x10 | 20 00 | uint16_t | 0x0020 (32) | size of referring table
- buffer = Push<flatbuffers::voffset_t>(buffer, 0x20);
- // +0x12 | 1C 00 | VOffset16 | 0x001C (28) | offset to field `channel_index` (id: 0)
- buffer = Push<flatbuffers::voffset_t>(buffer, 0x1c);
- // +0x14 | 0C 00 | VOffset16 | 0x000C (12) | offset to field `monotonic_sent_time` (id: 1)
- buffer = Push<flatbuffers::voffset_t>(buffer, 0x0c);
- // +0x16 | 04 00 | VOffset16 | 0x0004 (4) | offset to field `realtime_sent_time` (id: 2)
- buffer = Push<flatbuffers::voffset_t>(buffer, 0x04);
- // +0x18 | 18 00 | VOffset16 | 0x0018 (24) | offset to field `queue_index` (id: 3)
- buffer = Push<flatbuffers::voffset_t>(buffer, 0x18);
- // +0x1A | 14 00 | VOffset16 | 0x0014 (20) | offset to field `data` (id: 4)
- buffer = Push<flatbuffers::voffset_t>(buffer, 0x14);
- //
- // root_table (aos.logger.MessageHeader):
- // +0x1C | 0E 00 00 00 | SOffset32 | 0x0000000E (14) Loc: +0x0E | offset to vtable
- buffer = Push<flatbuffers::uoffset_t>(buffer, 0x0E);
- // +0x20 | D8 96 32 1A A0 D3 23 BB | int64_t | 0xBB23D3A01A3296D8 (-4961889679844403496) | table field `realtime_sent_time` (Long)
- buffer = Push<int64_t>(buffer, context.realtime_remote_time.time_since_epoch().count());
- // +0x28 | 2E 5D 23 B3 BE 84 CF C2 | int64_t | 0xC2CF84BEB3235D2E (-4409159555588334290) | table field `monotonic_sent_time` (Long)
- buffer = Push<int64_t>(buffer, context.monotonic_remote_time.time_since_epoch().count());
- // +0x30 | 0C 00 00 00 | UOffset32 | 0x0000000C (12) Loc: +0x3C | offset to field `data` (vector)
- buffer = Push<flatbuffers::uoffset_t>(buffer, 0x0C);
- // +0x34 | 69 00 00 00 | uint32_t | 0x00000069 (105) | table field `queue_index` (UInt)
- buffer = Push<uint32_t>(buffer, context.remote_queue_index);
- // +0x38 | F3 00 00 00 | uint32_t | 0x000000F3 (243) | table field `channel_index` (UInt)
- buffer = Push<uint32_t>(buffer, channel_index);
- //
- // vector (aos.logger.MessageHeader.data):
- // +0x3C | 1A 00 00 00 | uint32_t | 0x0000001A (26) | length of vector (# items)
- buffer = Push<flatbuffers::uoffset_t>(buffer, context.size);
- // +0x40 | 38 | uint8_t | 0x38 (56) | value[0]
- // +0x41 | 1A | uint8_t | 0x1A (26) | value[1]
- // ...
- // +0x58 | 90 | uint8_t | 0x90 (144) | value[24]
- // +0x59 | 92 | uint8_t | 0x92 (146) | value[25]
- buffer = PushBytes(buffer, context.data, context.size);
- //
- // padding:
- // +0x5A | 00 00 00 00 00 00 | uint8_t[6] | ...... | padding
- buffer = Pad(buffer, ((context.size + 7) & 0xfffffff8u) - context.size);
- // clang-format on
+ switch (start_byte) {
+ case 0x00u:
+ if ((end_byte) == 0x00u) {
+ break;
+ }
+ // This is the message we need to recreate.
+ //
+ // clang-format off
+ // header:
+ // +0x00 | 5C 00 00 00 | UOffset32 | 0x0000005C (92) Loc: +0x5C | size prefix
+ buffer = Push<flatbuffers::uoffset_t>(
+ buffer, message_size - sizeof(flatbuffers::uoffset_t));
+ // +0x04 | 18 00 00 00 | UOffset32 | 0x00000018 (24) Loc: +0x1C | offset to root table `aos.logger.MessageHeader`
+ buffer = Push<flatbuffers::uoffset_t>(buffer, 0x18);
+ [[fallthrough]];
+ case 0x08u:
+ if ((end_byte) == 0x08u) {
+ break;
+ }
+ //
+ // padding:
+ // +0x08 | 00 00 00 00 00 00 | uint8_t[6] | ...... | padding
+ buffer = Pad(buffer, 6);
+ //
+ // vtable (aos.logger.MessageHeader):
+ // +0x0E | 0E 00 | uint16_t | 0x000E (14) | size of this vtable
+ buffer = Push<flatbuffers::voffset_t>(buffer, 0x0e);
+ [[fallthrough]];
+ case 0x10u:
+ if ((end_byte) == 0x10u) {
+ break;
+ }
+ // +0x10 | 20 00 | uint16_t | 0x0020 (32) | size of referring table
+ buffer = Push<flatbuffers::voffset_t>(buffer, 0x20);
+ // +0x12 | 1C 00 | VOffset16 | 0x001C (28) | offset to field `channel_index` (id: 0)
+ buffer = Push<flatbuffers::voffset_t>(buffer, 0x1c);
+ // +0x14 | 0C 00 | VOffset16 | 0x000C (12) | offset to field `monotonic_sent_time` (id: 1)
+ buffer = Push<flatbuffers::voffset_t>(buffer, 0x0c);
+ // +0x16 | 04 00 | VOffset16 | 0x0004 (4) | offset to field `realtime_sent_time` (id: 2)
+ buffer = Push<flatbuffers::voffset_t>(buffer, 0x04);
+ [[fallthrough]];
+ case 0x18u:
+ if ((end_byte) == 0x18u) {
+ break;
+ }
+ // +0x18 | 18 00 | VOffset16 | 0x0018 (24) | offset to field `queue_index` (id: 3)
+ buffer = Push<flatbuffers::voffset_t>(buffer, 0x18);
+ // +0x1A | 14 00 | VOffset16 | 0x0014 (20) | offset to field `data` (id: 4)
+ buffer = Push<flatbuffers::voffset_t>(buffer, 0x14);
+ //
+ // root_table (aos.logger.MessageHeader):
+ // +0x1C | 0E 00 00 00 | SOffset32 | 0x0000000E (14) Loc: +0x0E | offset to vtable
+ buffer = Push<flatbuffers::uoffset_t>(buffer, 0x0E);
+ [[fallthrough]];
+ case 0x20u:
+ if ((end_byte) == 0x20u) {
+ break;
+ }
+ // +0x20 | D8 96 32 1A A0 D3 23 BB | int64_t | 0xBB23D3A01A3296D8 (-4961889679844403496) | table field `realtime_sent_time` (Long)
+ buffer = Push<int64_t>(buffer, context.realtime_remote_time.time_since_epoch().count());
+ [[fallthrough]];
+ case 0x28u:
+ if ((end_byte) == 0x28u) {
+ break;
+ }
+ // +0x28 | 2E 5D 23 B3 BE 84 CF C2 | int64_t | 0xC2CF84BEB3235D2E (-4409159555588334290) | table field `monotonic_sent_time` (Long)
+ buffer = Push<int64_t>(buffer, context.monotonic_remote_time.time_since_epoch().count());
+ [[fallthrough]];
+ case 0x30u:
+ if ((end_byte) == 0x30u) {
+ break;
+ }
+ // +0x30 | 0C 00 00 00 | UOffset32 | 0x0000000C (12) Loc: +0x3C | offset to field `data` (vector)
+ buffer = Push<flatbuffers::uoffset_t>(buffer, 0x0C);
+ // +0x34 | 69 00 00 00 | uint32_t | 0x00000069 (105) | table field `queue_index` (UInt)
+ buffer = Push<uint32_t>(buffer, context.remote_queue_index);
+ [[fallthrough]];
+ case 0x38u:
+ if ((end_byte) == 0x38u) {
+ break;
+ }
+ // +0x38 | F3 00 00 00 | uint32_t | 0x000000F3 (243) | table field `channel_index` (UInt)
+ buffer = Push<uint32_t>(buffer, channel_index);
+ //
+ // vector (aos.logger.MessageHeader.data):
+ // +0x3C | 1A 00 00 00 | uint32_t | 0x0000001A (26) | length of vector (# items)
+ buffer = Push<flatbuffers::uoffset_t>(buffer, context.size);
+ [[fallthrough]];
+ case 0x40u:
+ if ((end_byte) == 0x40u) {
+ break;
+ }
+ [[fallthrough]];
+ default:
+ // +0x40 | 38 | uint8_t | 0x38 (56) | value[0]
+ // +0x41 | 1A | uint8_t | 0x1A (26) | value[1]
+ // ...
+ // +0x58 | 90 | uint8_t | 0x90 (144) | value[24]
+ // +0x59 | 92 | uint8_t | 0x92 (146) | value[25]
+ //
+ // padding:
+ // +0x5A | 00 00 00 00 00 00 | uint8_t[6] | ...... | padding
+ // clang-format on
+ if (start_byte <= 0x40 && end_byte == message_size) {
+ // The easy one, slap it all down.
+ buffer = PushBytes(buffer, context.data, context.size);
+ buffer =
+ Pad(buffer, ((context.size + 7) & 0xfffffff8u) - context.size);
+ } else {
+ const size_t data_start_byte =
+ start_byte < 0x40 ? 0x0u : (start_byte - 0x40);
+ const size_t data_end_byte = end_byte - 0x40;
+ const size_t padded_size = ((context.size + 7) & 0xfffffff8u);
+ if (data_start_byte < padded_size) {
+ buffer = PushBytes(
+ buffer,
+ reinterpret_cast<const uint8_t *>(context.data) +
+ data_start_byte,
+ std::min(context.size, data_end_byte) - data_start_byte);
+ if (data_end_byte == padded_size) {
+ // We can only pad the last 7 bytes, so this only gets written
+ // if we write the last byte.
+ buffer = Pad(buffer,
+ ((context.size + 7) & 0xfffffff8u) - context.size);
+ }
+ }
+ }
+ break;
+ }
}
- return message_size;
+ return end_byte - start_byte;
}
SpanReader::SpanReader(std::string_view filename, bool quiet)
diff --git a/aos/events/logging/logfile_utils.h b/aos/events/logging/logfile_utils.h
index ca36ace..4e38feb 100644
--- a/aos/events/logging/logfile_utils.h
+++ b/aos/events/logging/logfile_utils.h
@@ -186,7 +186,8 @@
constexpr flatbuffers::uoffset_t PackRemoteMessageSize() { return 96u; }
size_t PackRemoteMessageInline(
uint8_t *data, const message_bridge::RemoteMessage *msg, int channel_index,
- const aos::monotonic_clock::time_point monotonic_timestamp_time);
+ const aos::monotonic_clock::time_point monotonic_timestamp_time,
+ size_t start_byte, size_t end_byte);
// Packes a message pointed to by the context into a MessageHeader.
flatbuffers::Offset<MessageHeader> PackMessage(
@@ -201,7 +202,8 @@
// This is equivalent to PackMessage, but doesn't require allocating a
// FlatBufferBuilder underneath.
size_t PackMessageInline(uint8_t *data, const Context &contex,
- int channel_index, LogType log_type);
+ int channel_index, LogType log_type, size_t start_byte,
+ size_t end_byte);
// Class to read chunks out of a log file.
class SpanReader {
@@ -912,6 +914,65 @@
// a single node.
std::string MaybeNodeName(const Node *);
+// Class to copy a RemoteMessage into the provided buffer.
+class RemoteMessageCopier : public DataEncoder::Copier {
+ public:
+ RemoteMessageCopier(const message_bridge::RemoteMessage *message,
+ int channel_index,
+ aos::monotonic_clock::time_point monotonic_timestamp_time,
+ EventLoop *event_loop)
+ : DataEncoder::Copier(PackRemoteMessageSize()),
+ message_(message),
+ channel_index_(channel_index),
+ monotonic_timestamp_time_(monotonic_timestamp_time),
+ event_loop_(event_loop) {}
+
+ monotonic_clock::time_point end_time() const { return end_time_; }
+
+ size_t Copy(uint8_t *data, size_t start_byte, size_t end_byte) final {
+ size_t result = PackRemoteMessageInline(data, message_, channel_index_,
+ monotonic_timestamp_time_,
+ start_byte, end_byte);
+ end_time_ = event_loop_->monotonic_now();
+ return result;
+ }
+
+ private:
+ const message_bridge::RemoteMessage *message_;
+ int channel_index_;
+ aos::monotonic_clock::time_point monotonic_timestamp_time_;
+ EventLoop *event_loop_;
+ monotonic_clock::time_point end_time_;
+};
+
+// Class to copy a context into the provided buffer.
+class ContextDataCopier : public DataEncoder::Copier {
+ public:
+ ContextDataCopier(const Context &context, int channel_index, LogType log_type,
+ EventLoop *event_loop)
+ : DataEncoder::Copier(PackMessageSize(log_type, context.size)),
+ context_(context),
+ channel_index_(channel_index),
+ log_type_(log_type),
+ event_loop_(event_loop) {}
+
+ monotonic_clock::time_point end_time() const { return end_time_; }
+
+ size_t Copy(uint8_t *data, size_t start_byte, size_t end_byte) final {
+ size_t result = PackMessageInline(data, context_, channel_index_, log_type_,
+ start_byte, end_byte);
+ end_time_ = event_loop_->monotonic_now();
+ return result;
+ }
+
+ private:
+ const Context &context_;
+ const int channel_index_;
+ const LogType log_type_;
+ EventLoop *event_loop_;
+ monotonic_clock::time_point end_time_;
+};
+
} // namespace aos::logger
#endif // AOS_EVENTS_LOGGING_LOGFILE_UTILS_H_
diff --git a/aos/events/logging/logfile_utils_test.cc b/aos/events/logging/logfile_utils_test.cc
index b3a9bbd..ec84b58 100644
--- a/aos/events/logging/logfile_utils_test.cc
+++ b/aos/events/logging/logfile_utils_test.cc
@@ -3100,6 +3100,90 @@
"/foo.afb");
}
+// Event loop which just has working time functions for the Copier classes
+// tested below.
+class TimeEventLoop : public EventLoop {
+ public:
+ TimeEventLoop() : EventLoop(nullptr) {}
+
+ aos::monotonic_clock::time_point monotonic_now() const final {
+ return aos::monotonic_clock::min_time;
+ }
+ realtime_clock::time_point realtime_now() const final {
+ return aos::realtime_clock::min_time;
+ }
+
+ void OnRun(::std::function<void()> /*on_run*/) final { LOG(FATAL); }
+
+ const std::string_view name() const final { return "time"; }
+ const Node *node() const final { return nullptr; }
+
+ void SetRuntimeAffinity(const cpu_set_t & /*cpuset*/) final { LOG(FATAL); }
+ void SetRuntimeRealtimePriority(int /*priority*/) final { LOG(FATAL); }
+
+ const cpu_set_t &runtime_affinity() const final {
+ LOG(FATAL);
+ return cpuset_;
+ }
+
+ TimerHandler *AddTimer(::std::function<void()> /*callback*/) final {
+ LOG(FATAL);
+ return nullptr;
+ }
+
+ std::unique_ptr<RawSender> MakeRawSender(const Channel * /*channel*/) final {
+ LOG(FATAL);
+ return std::unique_ptr<RawSender>();
+ }
+
+ const UUID &boot_uuid() const final {
+ LOG(FATAL);
+ return boot_uuid_;
+ }
+
+ void set_name(const std::string_view name) final { LOG(FATAL) << name; }
+
+ pid_t GetTid() final {
+ LOG(FATAL);
+ return 0;
+ }
+
+ int NumberBuffers(const Channel * /*channel*/) final {
+ LOG(FATAL);
+ return 0;
+ }
+
+ int runtime_realtime_priority() const final {
+ LOG(FATAL);
+ return 0;
+ }
+
+ std::unique_ptr<RawFetcher> MakeRawFetcher(
+ const Channel * /*channel*/) final {
+ LOG(FATAL);
+ return std::unique_ptr<RawFetcher>();
+ }
+
+ PhasedLoopHandler *AddPhasedLoop(
+ ::std::function<void(int)> /*callback*/,
+ const monotonic_clock::duration /*interval*/,
+ const monotonic_clock::duration /*offset*/) final {
+ LOG(FATAL);
+ return nullptr;
+ }
+
+ void MakeRawWatcher(
+ const Channel * /*channel*/,
+ std::function<void(const Context &context, const void *message)>
+ /*watcher*/) final {
+ LOG(FATAL);
+ }
+
+ private:
+ const cpu_set_t cpuset_ = DefaultAffinity();
+ UUID boot_uuid_ = UUID ::Zero();
+};
+
// Tests that all variations of PackMessage are equivalent to the inline
// PackMessage used to avoid allocations.
TEST_F(InlinePackMessage, Equivilent) {
@@ -3136,14 +3220,41 @@
67);
// And verify packing inline works as expected.
- EXPECT_EQ(repacked_message.size(),
- PackMessageInline(repacked_message.data(), context,
- channel_index, type));
+ EXPECT_EQ(
+ repacked_message.size(),
+ PackMessageInline(repacked_message.data(), context, channel_index,
+ type, 0u, repacked_message.size()));
EXPECT_EQ(absl::Span<uint8_t>(repacked_message),
absl::Span<uint8_t>(fbb.GetBufferSpan().data(),
fbb.GetBufferSpan().size()))
<< AnnotateBinaries(schema, "aos/events/logging/logger.bfbs",
fbb.GetBufferSpan());
+
+ // Ok, now we want to confirm that we can build up arbitrary pieces of
+ // said flatbuffer. Try all of them since it is cheap.
+ TimeEventLoop event_loop;
+ for (size_t i = 0; i < repacked_message.size(); i += 8) {
+ for (size_t j = i; j < repacked_message.size(); j += 8) {
+ std::vector<uint8_t> destination(repacked_message.size(), 67u);
+ ContextDataCopier copier(context, channel_index, type, &event_loop);
+
+ copier.Copy(destination.data(), i, j);
+
+ size_t index = 0;
+ for (size_t k = i; k < j; ++k) {
+ ASSERT_EQ(destination[index], repacked_message[k])
+ << ": Failed to match type " << static_cast<int>(type)
+ << ", index " << index << " while testing range " << i << " to "
+ << j;
+ ;
+ ++index;
+ }
+ // Now, confirm that none of the other bytes have been touched.
+ for (; index < destination.size(); ++index) {
+ ASSERT_EQ(destination[index], 67u);
+ }
+ }
+ }
}
}
}
@@ -3181,15 +3292,37 @@
std::vector<uint8_t> repacked_message(PackRemoteMessageSize(), 67);
// And verify packing inline works as expected.
- EXPECT_EQ(
- repacked_message.size(),
- PackRemoteMessageInline(repacked_message.data(), &random_msg.message(),
- channel_index, monotonic_timestamp_time));
+ EXPECT_EQ(repacked_message.size(),
+ PackRemoteMessageInline(
+ repacked_message.data(), &random_msg.message(), channel_index,
+ monotonic_timestamp_time, 0u, repacked_message.size()));
EXPECT_EQ(absl::Span<uint8_t>(repacked_message),
absl::Span<uint8_t>(fbb.GetBufferSpan().data(),
fbb.GetBufferSpan().size()))
<< AnnotateBinaries(schema, "aos/events/logging/logger.bfbs",
fbb.GetBufferSpan());
+
+ // Ok, now we want to confirm that we can build up arbitrary pieces of said
+ // flatbuffer. Try all of them since it is cheap.
+ TimeEventLoop event_loop;
+ for (size_t i = 0; i < repacked_message.size(); i += 8) {
+ for (size_t j = i; j < repacked_message.size(); j += 8) {
+ std::vector<uint8_t> destination(repacked_message.size(), 67u);
+ RemoteMessageCopier copier(&random_msg.message(), channel_index,
+ monotonic_timestamp_time, &event_loop);
+
+ copier.Copy(destination.data(), i, j);
+
+ size_t index = 0;
+ for (size_t k = i; k < j; ++k) {
+ ASSERT_EQ(destination[index], repacked_message[k]);
+ ++index;
+ }
+ for (; index < destination.size(); ++index) {
+ ASSERT_EQ(destination[index], 67u);
+ }
+ }
+ }
}
}
diff --git a/aos/events/logging/lzma_encoder.cc b/aos/events/logging/lzma_encoder.cc
index f583818..3959727 100644
--- a/aos/events/logging/lzma_encoder.cc
+++ b/aos/events/logging/lzma_encoder.cc
@@ -95,7 +95,7 @@
// since lzma is going to take it from here.
CHECK_LE(copy_size, input_buffer_.size());
- CHECK_EQ(copy->Copy(input_buffer_.data()), copy_size);
+ CHECK_EQ(copy->Copy(input_buffer_.data(), 0, copy_size), copy_size);
stream_.next_in = input_buffer_.data();
stream_.avail_in = copy_size;
diff --git a/aos/events/logging/snappy_encoder.cc b/aos/events/logging/snappy_encoder.cc
index 2ef8363..1b80fe0 100644
--- a/aos/events/logging/snappy_encoder.cc
+++ b/aos/events/logging/snappy_encoder.cc
@@ -142,7 +142,7 @@
CHECK_LE(copy_size + data_.size(), data_.capacity());
size_t starting_size = data_.size();
data_.resize(starting_size + copy_size);
- CHECK_EQ(copy->Copy(data_.data() + starting_size), copy_size);
+ CHECK_EQ(copy->Copy(data_.data() + starting_size, 0, copy_size), copy_size);
accumulated_checksum_ = AccumulateCrc32(
{data_.data() + starting_size, copy_size}, accumulated_checksum_);
}