mirror of
https://github.com/google/flatbuffers.git
synced 2026-06-06 05:27:24 +00:00
* Create a function GenerateGenerateTextFromTable in order to create a json from any Table Signed-off-by: Anthony Liot <anthony.liot@gmail.com> * Update the test to failed if loadfile or parser return false Signed-off-by: Anthony Liot <anthony.liot@gmail.com> * Fix snake_case name typo + space before &/* Signed-off-by: Anthony Liot <anthony.liot@gmail.com> * use auto Signed-off-by: Anthony Liot <anthony.liot@gmail.com> * Use clang-format on the added code Signed-off-by: Anthony Liot <anthony.liot@gmail.com>
This commit is contained in:
committed by
Wouter van Oortmerssen
parent
2d67de3151
commit
249f3b3714
@@ -262,6 +262,23 @@ static bool GenStruct(const StructDef &struct_def, const Table *table,
|
||||
return true;
|
||||
}
|
||||
|
||||
// Generate a text representation of a flatbuffer in JSON format.
|
||||
bool GenerateTextFromTable(const Parser &parser, const void *table,
|
||||
const std::string &table_name, std::string *_text) {
|
||||
auto struct_def = parser.LookupStruct(table_name);
|
||||
if (struct_def == nullptr) {
|
||||
return false;
|
||||
}
|
||||
auto text = *_text;
|
||||
text.reserve(1024); // Reduce amount of inevitable reallocs.
|
||||
auto root = static_cast<const Table *>(table);
|
||||
if (!GenStruct(*struct_def, root, 0, parser.opts, _text)) {
|
||||
return false;
|
||||
}
|
||||
text += NewLine(parser.opts);
|
||||
return true;
|
||||
}
|
||||
|
||||
// Generate a text representation of a flatbuffer in JSON format.
|
||||
bool GenerateText(const Parser &parser, const void *flatbuffer,
|
||||
std::string *_text) {
|
||||
|
||||
Reference in New Issue
Block a user