Commit ab54e618 authored by Shivendra Agarwal's avatar Shivendra Agarwal Committed by Wouter van Oortmerssen

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
parent f445c1eb
...@@ -337,6 +337,16 @@ class Map : public Vector { ...@@ -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 { ...@@ -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 += "(?)";
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment