summarylogtreecommitdiffstats
path: root/0002-fix-for-flatbuffers-v2.patch
blob: 7b5de9a86b694bf25132e4a3c9419797607e6952 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
From 1caa1c81657ac96d73275564e146f8465a5dad18 Mon Sep 17 00:00:00 2001
From: japm48 <japm48gh@gmail.com>
Date: Sat, 25 Sep 2021 00:35:56 +0200
Subject: [PATCH] Fix for flatbuffers v2

---
 src/flatbuffers_json_visitor.h | 15 ++++++++++++---
 1 file changed, 12 insertions(+), 3 deletions(-)

diff --git a/src/flatbuffers_json_visitor.h b/src/flatbuffers_json_visitor.h
index 1c310ad..f8571d6 100644
--- a/src/flatbuffers_json_visitor.h
+++ b/src/flatbuffers_json_visitor.h
@@ -197,6 +197,15 @@ json_vector_to_chararray(flatbuffers::FlatBufferBuilder &fbb, const json &jvec,
 }
 
 
+inline bool check_type_is_vector(const flatbuffers::TypeCode &tc) {
+#if FLATBUFFERS_VERSION_MAJOR >= 2
+    return tc.is_repeating;
+#else
+    return tc.is_vector;
+#endif
+}
+
+
 /**
  * Iterate through a typetable-- I'll be honest here. This is kind of bullshit. We need to create all of
  * the types like Strings, Lists, Vectors, and other flatbuffer types before we create our table. I'm not
@@ -217,7 +226,7 @@ inline void IterateType(const flatbuffers::TypeTable *type_table, FromSigMFVisit
     for (size_t i = 0; i < type_table->num_elems; i++) {
         auto type_code = type_table->type_codes[i];
         auto type = static_cast<flatbuffers::ElementaryType>(type_code.base_type);
-        auto is_vector = type_code.is_vector != 0;
+        auto is_vector = check_type_is_vector(type_code);
         auto ref_idx = type_code.sequence_ref;
         const flatbuffers::TypeTable *ref = nullptr;
         if (ref_idx >= 0) { ref = type_table->type_refs[ref_idx](); }
@@ -277,7 +286,7 @@ inline void IterateType(const flatbuffers::TypeTable *type_table, FromSigMFVisit
     for (size_t i = 0; i < type_table->num_elems; i++) {
         auto type_code = type_table->type_codes[i];
         auto type = static_cast<flatbuffers::ElementaryType>(type_code.base_type);
-        auto is_vector = type_code.is_vector != 0;
+        auto is_vector = check_type_is_vector(type_code);
         auto ref_idx = type_code.sequence_ref;
         const flatbuffers::TypeTable *ref = nullptr;
         if (ref_idx >= 0) { ref = type_table->type_refs[ref_idx](); }
@@ -490,7 +499,7 @@ FlatBufferToJson(const uint8_t *buffer_root, const flatbuffers::TypeTable *typet
         // Gather all of the underlying info about this element in table
         auto type_code = typetable->type_codes[i];
         auto type = static_cast<flatbuffers::ElementaryType>(type_code.base_type);
-        auto is_vector = type_code.is_vector != 0;
+        auto is_vector = check_type_is_vector(type_code);
         auto ref_idx = type_code.sequence_ref;
         const flatbuffers::TypeTable *ref = nullptr;
         if (ref_idx >= 0) { ref = typetable->type_refs[ref_idx](); }