CommandProcessor: start dump implementation

Update CommandProcessor, to support dumping existing
logs. In order to keep the CL size reasonable, this
CL only implements dumping of the timestamps of each
message. Dumping the payload will be added in a follow-on
CL.

Note that the new unit tests use ::testing::Invoke(),
in a way that mixes the mocking and faking test
strategies in a single object. The GMock documentation
discourages this kind of mixing, in favor of splitting
a class into one piece that is to be mocked, and another
that is to be faked [1].

The reason we mix the strategies, despite the recommendation
to the contrary, is that we don't always want to fake
Os::Write(). Some times, we just want to mock that method.

Along the way:
- add a ScopedRewinder to MessageBuffer
- add the kDumpBuffers command to protocol::Opcode.
  This command is numbered 0x20, to leave room for
  addition kWrite<MessageType> commands.

[1]
https://github.com/google/googletest/blob/master/googlemock/docs/v1_6/CookBook.md
Specifically, "Having to mix a mock and a fake..."

Bug: 32098312
Test: ./runtests.sh
Change-Id: If221b47ae5615bbc114db5755ce9eb46b9934b6e
diff --git a/command_processor.h b/command_processor.h
index 0c2ae66..90ec9b9 100644
--- a/command_processor.h
+++ b/command_processor.h
@@ -18,8 +18,10 @@
 #define COMMAND_PROCESSOR_H_
 
 #include <memory>
+#include <string>
 
 #include "android-base/macros.h"
+#include "android-base/unique_fd.h"
 
 #include "wifilogd/local_utils.h"
 #include "wifilogd/message_buffer.h"
@@ -52,7 +54,12 @@
                       int fd);
 
  private:
-  struct TimestampHeader {
+  class TimestampHeader {
+   public:
+    // Returns a string with a formatted representation of the timestamps
+    // contained within this header.
+    std::string ToString() const;
+
     Os::Timestamp since_boot_awake_only;
     Os::Timestamp since_boot_with_sleep;
     Os::Timestamp since_epoch;  // non-monotonic
@@ -64,6 +71,10 @@
   // true.
   bool CopyCommandToLog(NONNULL const void* command_buffer, size_t command_len);
 
+  // Dumps all of the logged messages to |dump_fd|. Returns true unless
+  // an unrecoverable error was encountered.
+  bool Dump(::android::base::unique_fd dump_fd);
+
   // The MessageBuffer is inlined, since there's not much value to mocking
   // simple data objects. See Testing on the Toilet Episode 173.
   MessageBuffer current_log_buffer_;