Json : Add --size-prefixed option to flatc (#4645)

to be able to convert to json size prefixed buffers.
This commit is contained in:
desqaz
2018-03-09 17:21:28 +01:00
committed by Wouter van Oortmerssen
parent cc158e7009
commit e78825e7a0
5 changed files with 28 additions and 11 deletions

View File

@@ -263,8 +263,9 @@ bool GenerateText(const Parser &parser, const void *flatbuffer,
std::string &text = *_text;
assert(parser.root_struct_def_); // call SetRootType()
text.reserve(1024); // Reduce amount of inevitable reallocs.
if (!GenStruct(*parser.root_struct_def_, GetRoot<Table>(flatbuffer), 0,
parser.opts, _text)) {
auto root = parser.opts.size_prefixed ?
GetSizePrefixedRoot<Table>(flatbuffer) : GetRoot<Table>(flatbuffer);
if (!GenStruct(*parser.root_struct_def_, root, 0, parser.opts, _text)) {
return false;
}
text += NewLine(parser.opts);