Make Copier and Encoder support writing partial messages

Along with changes to DummyEncoder, this gets us nicely setup to create
nice round buffer sizes for both DummyEncoder and LzmaEncoder.  Those
can be written using O_DIRECT in a follow on commit for much more
efficient IO.

To do this, we need to introduce both start and stop bytes to Copier,
and then teach Encoder how to return what it was able to encode, and
then to restart part way through a message.

--flush_size now sets the buffer size.

Change-Id: I7a26d2ce677a28bd0e73333514302dc0612195c2
Signed-off-by: Austin Schuh <austin.linux@gmail.com>
diff --git a/aos/events/logging/log_namer.cc b/aos/events/logging/log_namer.cc
index c0c7c73..86d813f 100644
--- a/aos/events/logging/log_namer.cc
+++ b/aos/events/logging/log_namer.cc
@@ -14,6 +14,8 @@
 #include "flatbuffers/flatbuffers.h"
 #include "glog/logging.h"
 
+DECLARE_int32(flush_size);
+
 namespace aos {
 namespace logger {
 
@@ -568,7 +570,12 @@
                                      EventLoop *event_loop, const Node *node)
     : LogNamer(configuration, event_loop, node),
       base_name_(base_name),
-      old_base_name_() {}
+      old_base_name_(),
+      encoder_factory_([](size_t max_message_size) {
+        // TODO(austin): For slow channels, can we allocate less memory?
+        return std::make_unique<DummyEncoder>(max_message_size,
+                                              FLAGS_flush_size);
+      }) {}
 
 MultiNodeLogNamer::~MultiNodeLogNamer() {
   if (!ran_out_of_space_) {