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_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