Made ToStringVisitor backwards compatible with older behavior.
This to support code that relied on tables being multiline,
but not vectors.
This behavior was changed in:
b1a925dfc2 (diff-c45c8fbffbc64f7ff4aa2978612b10d8)
Change-Id: I4c95471b643b2b3fab95e06b1294e19d686b492c
This commit is contained in:
parent
4f066c39ce
commit
3b23ff18ea
|
@ -287,10 +287,20 @@ struct ToStringVisitor : public IterationVisitor {
|
||||||
bool q;
|
bool q;
|
||||||
std::string in;
|
std::string in;
|
||||||
size_t indent_level;
|
size_t indent_level;
|
||||||
ToStringVisitor(std::string delimiter, bool quotes, std::string indent)
|
bool vector_delimited;
|
||||||
: d(delimiter), q(quotes), in(indent), indent_level(0) {}
|
ToStringVisitor(std::string delimiter, bool quotes, std::string indent,
|
||||||
|
bool vector_delimited = true)
|
||||||
|
: d(delimiter),
|
||||||
|
q(quotes),
|
||||||
|
in(indent),
|
||||||
|
indent_level(0),
|
||||||
|
vector_delimited(vector_delimited) {}
|
||||||
ToStringVisitor(std::string delimiter)
|
ToStringVisitor(std::string delimiter)
|
||||||
: d(delimiter), q(false), in(""), indent_level(0) {}
|
: d(delimiter),
|
||||||
|
q(false),
|
||||||
|
in(""),
|
||||||
|
indent_level(0),
|
||||||
|
vector_delimited(true) {}
|
||||||
|
|
||||||
void append_indent() {
|
void append_indent() {
|
||||||
for (size_t i = 0; i < indent_level; i++) { s += in; }
|
for (size_t i = 0; i < indent_level; i++) { s += in; }
|
||||||
|
@ -350,30 +360,38 @@ struct ToStringVisitor : public IterationVisitor {
|
||||||
void Unknown(const uint8_t *) { s += "(?)"; }
|
void Unknown(const uint8_t *) { s += "(?)"; }
|
||||||
void StartVector() {
|
void StartVector() {
|
||||||
s += "[";
|
s += "[";
|
||||||
|
if (vector_delimited) {
|
||||||
s += d;
|
s += d;
|
||||||
indent_level++;
|
indent_level++;
|
||||||
append_indent();
|
append_indent();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
void EndVector() {
|
void EndVector() {
|
||||||
|
if (vector_delimited) {
|
||||||
s += d;
|
s += d;
|
||||||
indent_level--;
|
indent_level--;
|
||||||
append_indent();
|
append_indent();
|
||||||
|
}
|
||||||
s += "]";
|
s += "]";
|
||||||
}
|
}
|
||||||
void Element(size_t i, ElementaryType /*type*/,
|
void Element(size_t i, ElementaryType /*type*/,
|
||||||
const TypeTable * /*type_table*/, const uint8_t * /*val*/) {
|
const TypeTable * /*type_table*/, const uint8_t * /*val*/) {
|
||||||
if (i) {
|
if (i) {
|
||||||
s += ",";
|
s += ",";
|
||||||
|
if (vector_delimited) {
|
||||||
s += d;
|
s += d;
|
||||||
append_indent();
|
append_indent();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
inline std::string FlatBufferToString(const uint8_t *buffer,
|
inline std::string FlatBufferToString(const uint8_t *buffer,
|
||||||
const TypeTable *type_table,
|
const TypeTable *type_table,
|
||||||
bool multi_line = false) {
|
bool multi_line = false,
|
||||||
ToStringVisitor tostring_visitor(multi_line ? "\n" : " ");
|
bool vector_delimited = true) {
|
||||||
|
ToStringVisitor tostring_visitor(multi_line ? "\n" : " ", false, "",
|
||||||
|
vector_delimited);
|
||||||
IterateFlatBuffer(buffer, type_table, &tostring_visitor);
|
IterateFlatBuffer(buffer, type_table, &tostring_visitor);
|
||||||
return tostring_visitor.s;
|
return tostring_visitor.s;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue