FlexBuffer to JSON convertor for typed and fixedTypedvectors (#4947)
* FlexBuffer to JSON convertor for typed and fixedTypedvectors * moving the common implementation to template * signed unsigned comparison fix * fix a formatting ({ * changing logic to append comma in vector of elements in json
This commit is contained in:
parent
f445c1eb4a
commit
ab54e61805
|
@ -337,6 +337,16 @@ class Map : public Vector {
|
||||||
bool IsTheEmptyMap() const { return data_ == EmptyMap().data_; }
|
bool IsTheEmptyMap() const { return data_ == EmptyMap().data_; }
|
||||||
};
|
};
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
void AppendToString(std::string &s, T &&v, bool keys_quoted) {
|
||||||
|
s += "[ ";
|
||||||
|
for (size_t i = 0; i < v.size(); i++) {
|
||||||
|
if (i) s += ", ";
|
||||||
|
v[i].ToString(true, keys_quoted, s);
|
||||||
|
}
|
||||||
|
s += " ]";
|
||||||
|
}
|
||||||
|
|
||||||
class Reference {
|
class Reference {
|
||||||
public:
|
public:
|
||||||
Reference(const uint8_t *data, uint8_t parent_width, uint8_t byte_width,
|
Reference(const uint8_t *data, uint8_t parent_width, uint8_t byte_width,
|
||||||
|
@ -532,13 +542,11 @@ class Reference {
|
||||||
}
|
}
|
||||||
s += " }";
|
s += " }";
|
||||||
} else if (IsVector()) {
|
} else if (IsVector()) {
|
||||||
s += "[ ";
|
AppendToString<Vector>(s, AsVector(), keys_quoted);
|
||||||
auto v = AsVector();
|
} else if (IsTypedVector()) {
|
||||||
for (size_t i = 0; i < v.size(); i++) {
|
AppendToString<TypedVector>(s, AsTypedVector(), keys_quoted);
|
||||||
v[i].ToString(true, keys_quoted, s);
|
} else if (IsFixedTypedVector()) {
|
||||||
if (i < v.size() - 1) s += ", ";
|
AppendToString<FixedTypedVector>(s, AsFixedTypedVector(), keys_quoted);
|
||||||
}
|
|
||||||
s += " ]";
|
|
||||||
} else {
|
} else {
|
||||||
s += "(?)";
|
s += "(?)";
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue