// Specialization of Print above for pointer types. template<> void Print<const void *>(const void *val, Type type, int indent, StructDef *union_sd, const IDLOptions &opts, std::string *_text) { switch (type.base_type) { case BASE_TYPE_UNION: // If this assert hits, you have an corrupt buffer, a union type field // was not present or was out of range. assert(union_sd); GenStruct(*union_sd, reinterpret_cast<const Table *>(val), indent, opts, _text); break; case BASE_TYPE_STRUCT: GenStruct(*type.struct_def, reinterpret_cast<const Table *>(val), indent, opts, _text); break; case BASE_TYPE_STRING: { EscapeString(*reinterpret_cast<const String *>(val), _text); break; } case BASE_TYPE_VECTOR: type = type.VectorType(); // Call PrintVector above specifically for each element type: switch (type.base_type) { #define FLATBUFFERS_TD(ENUM, IDLTYPE, CTYPE, JTYPE, GTYPE, NTYPE, \ PTYPE) \ case BASE_TYPE_ ## ENUM: \ PrintVector<CTYPE>( \ *reinterpret_cast<const Vector<CTYPE> *>(val), \ type, indent, opts, _text); break; FLATBUFFERS_GEN_TYPES(FLATBUFFERS_TD) #undef FLATBUFFERS_TD } break; default: assert(0); } }
bool generateStructs() { for (auto it = parser_.structs_.vec.begin(); it != parser_.structs_.vec.end(); ++it) { auto &struct_def = **it; std::string declcode; GenStruct(struct_def, &declcode); if (!SaveType(struct_def, declcode, true)) return false; } return true; }
// Generate a text representation of a flatbuffer in JSON format. void GenerateText(const Parser &parser, const void *flatbuffer, int indent_step, std::string *_text) { std::string &text = *_text; assert(parser.root_struct_def); // call SetRootType() text.reserve(1024); // Reduce amount of inevitable reallocs. GenStruct(*parser.root_struct_def, GetRoot<Table>(flatbuffer), 0, indent_step, _text); text += NewLine(indent_step); }
// Generate a text representation of a flatbuffer in JSON format. void GenerateText(const Parser &parser, const void *flatbuffer, const GeneratorOptions &opts, std::string *_text) { std::string &text = *_text; assert(parser.root_struct_def_); // call SetRootType() text.reserve(1024); // Reduce amount of inevitable reallocs. GenStruct(*parser.root_struct_def_, GetRoot<Table>(flatbuffer), 0, opts, _text); text += NewLine(opts); }