mirror of
https://github.com/google/flatbuffers.git
synced 2026-06-12 16:00:59 +00:00
Adds multi-line to FLatBufferToString (#4847)
Adding multi-line option to FlatBufferToString method in minireflect to allow more readable output for larger flatbuffers.
This commit is contained in:
committed by
Wouter van Oortmerssen
parent
c80f8d18c1
commit
ca5aaf62d3
@@ -283,13 +283,25 @@ inline void IterateFlatBuffer(const uint8_t *buffer,
|
|||||||
|
|
||||||
struct ToStringVisitor : public IterationVisitor {
|
struct ToStringVisitor : public IterationVisitor {
|
||||||
std::string s;
|
std::string s;
|
||||||
void StartSequence() { s += "{ "; }
|
std::string d;
|
||||||
void EndSequence() { s += " }"; }
|
ToStringVisitor(std::string delimiter): d(delimiter) {}
|
||||||
|
|
||||||
|
void StartSequence() {
|
||||||
|
s += "{";
|
||||||
|
s += d;
|
||||||
|
}
|
||||||
|
void EndSequence() {
|
||||||
|
s += d;
|
||||||
|
s += "}";
|
||||||
|
}
|
||||||
void Field(size_t /*field_idx*/, size_t set_idx, ElementaryType /*type*/,
|
void Field(size_t /*field_idx*/, size_t set_idx, ElementaryType /*type*/,
|
||||||
bool /*is_vector*/, const TypeTable * /*type_table*/,
|
bool /*is_vector*/, const TypeTable * /*type_table*/,
|
||||||
const char *name, const uint8_t *val) {
|
const char *name, const uint8_t *val) {
|
||||||
if (!val) return;
|
if (!val) return;
|
||||||
if (set_idx) s += ", ";
|
if (set_idx) {
|
||||||
|
s += ",";
|
||||||
|
s += d;
|
||||||
|
}
|
||||||
if (name) {
|
if (name) {
|
||||||
s += name;
|
s += name;
|
||||||
s += ": ";
|
s += ": ";
|
||||||
@@ -326,8 +338,9 @@ struct ToStringVisitor : public IterationVisitor {
|
|||||||
};
|
};
|
||||||
|
|
||||||
inline std::string FlatBufferToString(const uint8_t *buffer,
|
inline std::string FlatBufferToString(const uint8_t *buffer,
|
||||||
const TypeTable *type_table) {
|
const TypeTable *type_table,
|
||||||
ToStringVisitor tostring_visitor;
|
bool multi_line = false) {
|
||||||
|
ToStringVisitor tostring_visitor(multi_line ? "\n" : " ");
|
||||||
IterateFlatBuffer(buffer, type_table, &tostring_visitor);
|
IterateFlatBuffer(buffer, type_table, &tostring_visitor);
|
||||||
return tostring_visitor.s;
|
return tostring_visitor.s;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user