Added support for nested flatbuffers serializing to json (#4391)

* added bool for nested_flatbuffer
setting bool flag nested_flatbuffer according to attributes
setting nested type

* added JSON serialization for nested flatbuffers

* simplified lookup of nested_flatbuffer StructDef

* added nested_flatbuffer parsing workound relying on flexbuffers

* moved nested flatbuffer parsing into its own function for clarity
removed flexbuffers workound to simplify and speed up nested_flatbuffer parsing
added support for 'legacy' nested_flatbuffers, ubyte arrays

* inlined functions for nested parser init/clean since only used once

* whitespace formatting

* changed type of FieldDef.nested_flatbuffer from bool to StructDef*
removed subsequent type lookups

* removed copies of unrequired data when initializing nested parser

* applied changes requested by reviewer

* removed superfluous lookup of nested_flatbuffer field attributes

* renamed camelCased variables to snake_case
This commit is contained in:
Christian Helmich
2017-07-29 02:27:51 +09:00
committed by Wouter van Oortmerssen
parent 360c34467c
commit 89a68942ac
4 changed files with 60 additions and 13 deletions

View File

@@ -165,6 +165,10 @@ template<typename T> static bool GenField(const FieldDef &fd,
opts, _text);
}
static bool GenStruct(const StructDef &struct_def, const Table *table,
int indent, const IDLOptions &opts,
std::string *_text);
// Generate text for non-scalar field.
static bool GenFieldOffset(const FieldDef &fd, const Table *table, bool fixed,
int indent, Type *union_type,
@@ -180,6 +184,10 @@ static bool GenFieldOffset(const FieldDef &fd, const Table *table, bool fixed,
auto root = flexbuffers::GetRoot(vec->data(), vec->size());
root.ToString(true, opts.strict_json, *_text);
return true;
} else if (fd.nested_flatbuffer) {
auto vec = table->GetPointer<const Vector<uint8_t> *>(fd.value.offset);
auto root = GetRoot<Table>(vec->data());
return GenStruct(*fd.nested_flatbuffer, root, indent, opts, _text);
} else {
val = IsStruct(fd.value.type)
? table->GetStruct<const void *>(fd.value.offset)