summaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authorShivendra Agarwal <shiva.agarwal0@gmail.com>2018-11-12 22:19:11 +0530
committerWouter van Oortmerssen <aardappel@gmail.com>2018-11-12 08:49:11 -0800
commitab54e61805321eaea8f0e886531c4f5aa79773c7 (patch)
tree45f659889370a513ba2554462b70fc314988b3e7 /include
parentf445c1eb4aa70b4717b4eb53bdd89c447359d3c2 (diff)
downloadflatbuffers-ab54e61805321eaea8f0e886531c4f5aa79773c7.tar.gz
flatbuffers-ab54e61805321eaea8f0e886531c4f5aa79773c7.tar.bz2
flatbuffers-ab54e61805321eaea8f0e886531c4f5aa79773c7.zip
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
Diffstat (limited to 'include')
-rw-r--r--include/flatbuffers/flexbuffers.h22
1 files changed, 15 insertions, 7 deletions
diff --git a/include/flatbuffers/flexbuffers.h b/include/flatbuffers/flexbuffers.h
index cea9d8eb..de010b92 100644
--- a/include/flatbuffers/flexbuffers.h
+++ b/include/flatbuffers/flexbuffers.h
@@ -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 += "(?)";
}