Allow detaching buffers from Sender::Builders to send later

This can be helpful, because unlike the Builder itself a detached buffer
is moveable.

Change-Id: I246750fcd7622c2eed0a72172f90fe02fcc9be07
diff --git a/aos/events/event_loop.h b/aos/events/event_loop.h
index c36b195..a1a617e 100644
--- a/aos/events/event_loop.h
+++ b/aos/events/event_loop.h
@@ -295,6 +295,15 @@
       CHECK(!allocator_->is_allocated()) << ": Message was not sent yet";
     }
 
+    // Detaches a buffer, for later use calling Sender::Send directly.
+    //
+    // Note that the underlying memory remains with the Sender, so creating
+    // another Builder before destroying the FlatbufferDetachedBuffer will fail.
+    FlatbufferDetachedBuffer<T> Detach(flatbuffers::Offset<T> offset) {
+      fbb_.Finish(offset);
+      return fbb_.Release();
+    }
+
    private:
     flatbuffers::FlatBufferBuilder fbb_;
     ChannelPreallocatedAllocator *allocator_;
@@ -313,6 +322,10 @@
   // Sends a prebuilt flatbuffer.
   bool Send(const Flatbuffer<T> &flatbuffer);
 
+  // Sends a prebuilt flatbuffer which was detached from a Builder created via
+  // MakeBuilder() on this object.
+  bool SendDetached(FlatbufferDetachedBuffer<T> detached);
+
   // Returns the name of the underlying queue.
   const Channel *channel() const { return sender_->channel(); }