Add support for parsing JSON into a FlatBufferBuilder

This lets us parse JSON into a sub-message as well, and create a size
prefixed flatbuffer.

Change-Id: I7a6301a74feab06e62686f28e87140b69065dd1f
diff --git a/aos/json_to_flatbuffer.h b/aos/json_to_flatbuffer.h
index f90a602..c061c69 100644
--- a/aos/json_to_flatbuffer.h
+++ b/aos/json_to_flatbuffer.h
@@ -11,10 +11,28 @@
 
 namespace aos {
 
-// Parses the flatbuffer into the vector, or returns an empty vector.
+// Parses the flatbuffer into the buffer, or returns an empty buffer.
 flatbuffers::DetachedBuffer JsonToFlatbuffer(
     const std::string_view data, const flatbuffers::TypeTable *typetable);
 
+// Parses the flatbuffer into the builder, and returns the offset.
+flatbuffers::Offset<flatbuffers::Table> JsonToFlatbuffer(
+    const std::string_view data, const flatbuffers::TypeTable *typetable,
+    flatbuffers::FlatBufferBuilder *fbb);
+
+// Typed versions of the above methods.
+template <typename T>
+inline flatbuffers::DetachedBuffer JsonToFlatbuffer(
+    const std::string_view data) {
+  return JsonToFlatbuffer(data, T::MiniReflectTypeTable());
+}
+template <typename T>
+inline flatbuffers::Offset<T> JsonToFlatbuffer(
+    const std::string_view data, flatbuffers::FlatBufferBuilder *fbb) {
+  return flatbuffers::Offset<T>(
+      JsonToFlatbuffer(data, T::MiniReflectTypeTable(), fbb).o);
+}
+
 // Converts a flatbuffer into a Json string.
 // multi_line controls if the Json is written out on multiple lines or one.
 // The methods below are generally more useful than BufferFlatbufferToJson and