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_; }
|
||||
};
|
||||
|
||||
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 {
|
||||
public:
|
||||
Reference(const uint8_t *data, uint8_t parent_width, uint8_t byte_width,
|
||||
|
@ -532,13 +542,11 @@ class Reference {
|
|||
}
|
||||
s += " }";
|
||||
} else if (IsVector()) {
|
||||
s += "[ ";
|
||||
auto v = AsVector();
|
||||
for (size_t i = 0; i < v.size(); i++) {
|
||||
v[i].ToString(true, keys_quoted, s);
|
||||
if (i < v.size() - 1) s += ", ";
|
||||
}
|
||||
s += " ]";
|
||||
AppendToString<Vector>(s, AsVector(), keys_quoted);
|
||||
} else if (IsTypedVector()) {
|
||||
AppendToString<TypedVector>(s, AsTypedVector(), keys_quoted);
|
||||
} else if (IsFixedTypedVector()) {
|
||||
AppendToString<FixedTypedVector>(s, AsFixedTypedVector(), keys_quoted);
|
||||
} else {
|
||||
s += "(?)";
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue