Squashed 'third_party/flatbuffers/' changes from d6a8dbd26..338393f85
338393f85 Documentation updates for Optional Scalars (#6014) (#6270)
c27bc2d76 [C++] Add ParseJson(), Parser(Parser&&), update fuzzers (#6284)
bc518a512 Fixed FlexBufferBuilder asserting on duplicate keys
100c59054 Added a few more paths for auto labeler (#6281)
e58c18244 Add --require-explicit-ids to require explicit ids (#6277)
69a8b2a57 idl_gen_json_schema.cpp: Changed generation of array element types (#6253)
25eba6f35 fix typo (#6280)
e1f0f75ba Updated Ms build Action to fix build issue (#6279)
faeb04fbe Add type annotation to unspecified array (#6264)
537212afe [Swift] Adds a format file and reformats the swift project (#6250)
6764f25d9 Adds a fix for enum generation (#6263)
Change-Id: I716bd4d2521fb0a673e50a699cef761e042052b2
git-subtree-dir: third_party/flatbuffers
git-subtree-split: 338393f854eb5ba24761a22cd9316ff5cee4eab0
diff --git a/include/flatbuffers/base.h b/include/flatbuffers/base.h
index 085099a..95b788e 100644
--- a/include/flatbuffers/base.h
+++ b/include/flatbuffers/base.h
@@ -197,6 +197,7 @@
#if (!defined(_MSC_VER) || _MSC_FULL_VER >= 180020827) && \
(!defined(__GNUC__) || (__GNUC__ * 100 + __GNUC_MINOR__ >= 404)) || \
defined(__clang__)
+ #define FLATBUFFERS_DEFAULT_DECLARATION
#define FLATBUFFERS_DELETE_FUNC(func) func = delete;
#else
#define FLATBUFFERS_DELETE_FUNC(func) private: func;
diff --git a/include/flatbuffers/flatbuffers.h b/include/flatbuffers/flatbuffers.h
index 8683832..1f25d4e 100644
--- a/include/flatbuffers/flatbuffers.h
+++ b/include/flatbuffers/flatbuffers.h
@@ -1240,7 +1240,7 @@
}
/// @brief Get the serialized buffer (after you call `Finish()`) as a span.
- /// @return Returns a constructed flatbuffers::span that is a view over the
+ /// @return Returns a constructed flatbuffers::span that is a view over the
/// FlatBuffer data inside the buffer.
flatbuffers::span<uint8_t> GetBufferSpan() const {
Finished();
diff --git a/include/flatbuffers/flexbuffers.h b/include/flatbuffers/flexbuffers.h
index a45d14b..f2088b3 100644
--- a/include/flatbuffers/flexbuffers.h
+++ b/include/flatbuffers/flexbuffers.h
@@ -900,6 +900,7 @@
BuilderFlag flags = BUILDER_FLAG_SHARE_KEYS)
: buf_(initial_size),
finished_(false),
+ has_duplicate_keys_(false),
flags_(flags),
force_min_bit_width_(BIT_WIDTH_8),
key_pool(KeyOffsetCompare(buf_)),
@@ -907,6 +908,11 @@
buf_.clear();
}
+#ifdef FLATBUFFERS_DEFAULT_DECLARATION
+ Builder(Builder &&) = default;
+ Builder &operator=(Builder &&) = default;
+#endif
+
/// @brief Get the serialized buffer (after you call `Finish()`).
/// @return Returns a vector owned by this class.
const std::vector<uint8_t> &GetBuffer() const {
@@ -1124,12 +1130,16 @@
auto bs = reinterpret_cast<const char *>(
flatbuffers::vector_data(buf_) + b.key.u_);
auto comp = strcmp(as, bs);
- // If this assertion hits, you've added two keys with the same
- // value to this map.
+ // We want to disallow duplicate keys, since this results in a
+ // map where values cannot be found.
+ // But we can't assert here (since we don't want to fail on
+ // random JSON input) or have an error mechanism.
+ // Instead, we set has_duplicate_keys_ in the builder to
+ // signal this.
// TODO: Have to check for pointer equality, as some sort
// implementation apparently call this function with the same
// element?? Why?
- FLATBUFFERS_ASSERT(comp || &a == &b);
+ if (!comp && &a != &b) has_duplicate_keys_ = true;
return comp < 0;
});
// First create a vector out of all keys.
@@ -1143,6 +1153,10 @@
return static_cast<size_t>(vec.u_);
}
+ // Call this after EndMap to see if the map had any duplicate keys.
+ // Any map with such keys won't be able to retrieve all values.
+ bool HasDuplicateKeys() const { return has_duplicate_keys_; }
+
template<typename F> size_t Vector(F f) {
auto start = StartVector();
f();
@@ -1574,6 +1588,7 @@
std::vector<Value> stack_;
bool finished_;
+ bool has_duplicate_keys_;
BuilderFlag flags_;
diff --git a/include/flatbuffers/idl.h b/include/flatbuffers/idl.h
index a28745f..6afdc7a 100644
--- a/include/flatbuffers/idl.h
+++ b/include/flatbuffers/idl.h
@@ -601,6 +601,9 @@
MiniReflect mini_reflect;
+ // If set, require all fields in a table to be explicitly numbered.
+ bool require_explicit_ids;
+
// The corresponding language bit will be set if a language is included
// for code generation.
unsigned long lang_to_generate;
@@ -661,6 +664,7 @@
filename_extension(),
lang(IDLOptions::kJava),
mini_reflect(IDLOptions::kNone),
+ require_explicit_ids(false),
lang_to_generate(0),
set_empty_strings_to_null(true),
set_empty_vectors_to_null(true) {}
@@ -800,6 +804,11 @@
}
}
+#ifdef FLATBUFFERS_DEFAULT_DECLARATION
+ Parser(Parser&&) = default;
+ Parser& operator=(Parser&&) = default;
+#endif
+
// Parse the string containing either schema or JSON data, which will
// populate the SymbolTable's or the FlatBufferBuilder above.
// include_paths is used to resolve any include statements, and typically
@@ -814,6 +823,8 @@
bool Parse(const char *_source, const char **include_paths = nullptr,
const char *source_filename = nullptr);
+ bool ParseJson(const char *json, const char *json_filename = nullptr);
+
// Set the root type. May override the one set in the schema.
bool SetRootType(const char *name);
@@ -941,6 +952,7 @@
const char **include_paths,
const char *source_filename,
const char *include_filename);
+ FLATBUFFERS_CHECKED_ERROR DoParseJson();
FLATBUFFERS_CHECKED_ERROR CheckClash(std::vector<FieldDef *> &fields,
StructDef *struct_def,
const char *suffix, BaseType baseType);