Create a "static" flatbuffer API

This provides a generated API for working with flatbuffer objects that
generates a statically determined layout for the flatbuffer and uses
that layout to construct the flatbuffer without needing to dynamically
allocate any memory. For situations where dynamic sizing is appropriate,
this API does allow for increasing the size of any vectors in the
flatbuffer objects.

This change includes a checked-in version of the generated code so that
reviewers for this and future changes can readily examine what the
generated code looks like.

Future tasks:
* Support for unions?
* Consider precomputing some constants for sizes/alignments rather than
  massive constant expressions.

Change-Id: I6bf72d6c722d5390ab2239289a8a2a4e118c8d47
Signed-off-by: James Kuszmaul <james.kuszmaul@bluerivertech.com>
diff --git a/aos/flatbuffers/static_flatbuffers.h b/aos/flatbuffers/static_flatbuffers.h
new file mode 100644
index 0000000..47d79e6
--- /dev/null
+++ b/aos/flatbuffers/static_flatbuffers.h
@@ -0,0 +1,43 @@
+#ifndef AOS_FLATBUFFERS_STATIC_FLATBUFFERS_H_
+#define AOS_FLATBUFFERS_STATIC_FLATBUFFERS_H_
+#include <map>
+#include <set>
+#include <string>
+#include <string_view>
+#include <vector>
+
+#include "flatbuffers/reflection_generated.h"
+namespace aos::fbs {
+
+// Raw C++ code needed to represent a single flatbuffer table.
+// The various strings in this struct represent the actual C++ code that will be
+// used for this object; it is split up into pieces in order to allow us to
+// combine multiple flatbuffer tables into a single generated file (namely,
+// pulling the include declarations out to the top and including a set of
+// dependencies so that we can order the code correctly).
+// Primarily exposed here to allow for testing of intermediate functions.
+struct GeneratedObject {
+  // Fully qualified name of the object, in flatbuffer schema rules (e.g.
+  // aos.examples.Ping).
+  std::string name;
+  // All #include statements required for this object.
+  std::set<std::string> include_declarations;
+  // Fully qualified names of all sub-objects, in flatbuffer schema rules (e.g.
+  // aos.examples.Ping). Used to manage ordering of codegen.
+  std::set<std::string> subobjects;
+  // Actual code specific to this object.
+  std::string code;
+};
+
+// Produces generated code for all flatbuffer tables in the file corresponding
+// to the provided Schema object.
+std::string GenerateCodeForRootTableFile(const reflection::Schema *schema);
+
+// Helper functions to generate the code for individual objects; primarily
+// exposed for testing.
+GeneratedObject GenerateCodeForObject(const reflection::Schema *schema,
+                                      int object_index);
+GeneratedObject GenerateCodeForObject(const reflection::Schema *schema,
+                                      const reflection::Object *object);
+}  // namespace aos::fbs
+#endif  // AOS_FLATBUFFERS_STATIC_FLATBUFFERS_H_