bool VerifyBufferFromStart(const char *identifier, size_t start) {
- if (identifier && (size_ < 2 * sizeof(flatbuffers::uoffset_t) ||
- !BufferHasIdentifier(buf_ + start, identifier))) {
+ if (identifier && !Check((size_ >= 2 * sizeof(flatbuffers::uoffset_t) &&
+ BufferHasIdentifier(buf_ + start, identifier)))) {
return false;
}
@@ -2452,12 +2591,26 @@ class Table {
return field_offset ? reinterpret_cast(p) : nullptr;
}
+ template
+ flatbuffers::Optional GetOptional(voffset_t field) const {
+ auto field_offset = GetOptionalFieldOffset(field);
+ auto p = data_ + field_offset;
+ return field_offset ? Optional(static_cast(ReadScalar(p)))
+ : Optional();
+ }
+
template bool SetField(voffset_t field, T val, T def) {
auto field_offset = GetOptionalFieldOffset(field);
if (!field_offset) return IsTheSameAs(val, def);
WriteScalar(data_ + field_offset, val);
return true;
}
+ template bool SetField(voffset_t field, T val) {
+ auto field_offset = GetOptionalFieldOffset(field);
+ if (!field_offset) return false;
+ WriteScalar(data_ + field_offset, val);
+ return true;
+ }
bool SetPointer(voffset_t field, const uint8_t *val) {
auto field_offset = GetOptionalFieldOffset(field);
@@ -2525,6 +2678,17 @@ class Table {
uint8_t data_[1];
};
+// This specialization allows avoiding warnings like:
+// MSVC C4800: type: forcing value to bool 'true' or 'false'.
+template<>
+inline flatbuffers::Optional Table::GetOptional(
+ voffset_t field) const {
+ auto field_offset = GetOptionalFieldOffset(field);
+ auto p = data_ + field_offset;
+ return field_offset ? Optional(ReadScalar(p) != 0)
+ : Optional();
+}
+
template
void FlatBufferBuilder::Required(Offset table, voffset_t field) {
auto table_ptr = reinterpret_cast(buf_.data_at(table.o));
@@ -2702,10 +2866,16 @@ inline const char * const *ElementaryTypeNames() {
// clang-format on
// Basic type info cost just 16bits per field!
+// We're explicitly defining the signedness since the signedness of integer
+// bitfields is otherwise implementation-defined and causes warnings on older
+// GCC compilers.
struct TypeCode {
- uint16_t base_type : 4; // ElementaryType
- uint16_t is_vector : 1;
- int16_t sequence_ref : 11; // Index into type_refs below, or -1 for none.
+ // ElementaryType
+ unsigned short base_type : 4;
+ // Either vector (in table) or array (in struct)
+ unsigned short is_repeating : 1;
+ // Index into type_refs below, or -1 for none.
+ signed short sequence_ref : 11;
};
static_assert(sizeof(TypeCode) == 2, "TypeCode");
@@ -2720,6 +2890,7 @@ struct TypeTable {
size_t num_elems; // of type_codes, values, names (but not type_refs).
const TypeCode *type_codes; // num_elems count
const TypeFunction *type_refs; // less than num_elems entries (see TypeCode).
+ const int16_t *array_sizes; // less than num_elems entries (see TypeCode).
const int64_t *values; // Only set for non-consecutive enum/union or structs.
const char *const *names; // Only set if compiled with --reflect-names.
};
diff --git a/third_party/flatbuffers-c-bridge/third_party/flatbuffers/include/flatbuffers/flexbuffers.h b/third_party/flatbuffers-c-bridge/third_party/flatbuffers/include/flatbuffers/flexbuffers.h
index dceaa3b4..c71928e8 100644
--- a/third_party/flatbuffers-c-bridge/third_party/flatbuffers/include/flatbuffers/flexbuffers.h
+++ b/third_party/flatbuffers-c-bridge/third_party/flatbuffers/include/flatbuffers/flexbuffers.h
@@ -155,7 +155,7 @@ inline uint64_t ReadUInt64(const uint8_t *data, uint8_t byte_width) {
// constant, which here it isn't. Test if memcpy is still faster than
// the conditionals in ReadSizedScalar. Can also use inline asm.
// clang-format off
- #if defined(_MSC_VER) && (defined(_M_X64) || defined _M_IX86)
+ #if defined(_MSC_VER) && ((defined(_M_X64) && !defined(_M_ARM64EC)) || defined _M_IX86)
uint64_t u = 0;
__movsb(reinterpret_cast(&u),
reinterpret_cast(data), byte_width);
@@ -900,6 +900,7 @@ class Builder FLATBUFFERS_FINAL_CLASS {
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 @@ class Builder FLATBUFFERS_FINAL_CLASS {
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 &GetBuffer() const {
@@ -1124,12 +1130,16 @@ class Builder FLATBUFFERS_FINAL_CLASS {
auto bs = reinterpret_cast(
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 @@ class Builder FLATBUFFERS_FINAL_CLASS {
return static_cast(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 size_t Vector(F f) {
auto start = StartVector();
f();
@@ -1256,7 +1270,7 @@ class Builder FLATBUFFERS_FINAL_CLASS {
// auto id = builder.LastValue(); // Remember where we stored it.
// .. more code goes here ..
// builder.ReuseValue(id); // Refers to same double by offset.
- // LastValue works regardless of wether the value has a key or not.
+ // LastValue works regardless of whether the value has a key or not.
// Works on any data type.
struct Value;
Value LastValue() { return stack_.back(); }
@@ -1417,7 +1431,10 @@ class Builder FLATBUFFERS_FINAL_CLASS {
Value(uint64_t u, Type t, BitWidth bw)
: u_(u), type_(t), min_bit_width_(bw) {}
- Value(float f) : f_(f), type_(FBT_FLOAT), min_bit_width_(BIT_WIDTH_32) {}
+ Value(float f)
+ : f_(static_cast(f)),
+ type_(FBT_FLOAT),
+ min_bit_width_(BIT_WIDTH_32) {}
Value(double f) : f_(f), type_(FBT_FLOAT), min_bit_width_(WidthF(f)) {}
uint8_t StoredPackedType(BitWidth parent_bit_width_ = BIT_WIDTH_8) const {
@@ -1522,7 +1539,8 @@ class Builder FLATBUFFERS_FINAL_CLASS {
Type vector_type = FBT_KEY;
// Check bit widths and types for all elements.
for (size_t i = start; i < stack_.size(); i += step) {
- auto elem_width = stack_[i].ElemWidth(buf_.size(), i + prefix_elems);
+ auto elem_width =
+ stack_[i].ElemWidth(buf_.size(), i - start + prefix_elems);
bit_width = (std::max)(bit_width, elem_width);
if (typed) {
if (i == start) {
@@ -1570,6 +1588,7 @@ class Builder FLATBUFFERS_FINAL_CLASS {
std::vector stack_;
bool finished_;
+ bool has_duplicate_keys_;
BuilderFlag flags_;
diff --git a/third_party/flatbuffers-c-bridge/third_party/flatbuffers/include/flatbuffers/grpc.h b/third_party/flatbuffers-c-bridge/third_party/flatbuffers/include/flatbuffers/grpc.h
index bd24c501..b7935551 100644
--- a/third_party/flatbuffers-c-bridge/third_party/flatbuffers/include/flatbuffers/grpc.h
+++ b/third_party/flatbuffers-c-bridge/third_party/flatbuffers/include/flatbuffers/grpc.h
@@ -20,8 +20,8 @@
// Helper functionality to glue FlatBuffers and GRPC.
#include "flatbuffers/flatbuffers.h"
-#include "grpc++/support/byte_buffer.h"
#include "grpc/byte_buffer_reader.h"
+#include "grpcpp/support/byte_buffer.h"
namespace flatbuffers {
namespace grpc {
@@ -287,8 +287,9 @@ template class SerializationTraits> {
}
// Deserialize by pulling the
- static grpc::Status Deserialize(grpc_byte_buffer *buffer,
+ static grpc::Status Deserialize(ByteBuffer *buf,
flatbuffers::grpc::Message *msg) {
+ grpc_byte_buffer *buffer = *reinterpret_cast(buf);
if (!buffer) {
return ::grpc::Status(::grpc::StatusCode::INTERNAL, "No payload");
}
diff --git a/third_party/flatbuffers-c-bridge/third_party/flatbuffers/include/flatbuffers/idl.h b/third_party/flatbuffers-c-bridge/third_party/flatbuffers/include/flatbuffers/idl.h
index 12b2b142..29bf6215 100644
--- a/third_party/flatbuffers-c-bridge/third_party/flatbuffers/include/flatbuffers/idl.h
+++ b/third_party/flatbuffers-c-bridge/third_party/flatbuffers/include/flatbuffers/idl.h
@@ -35,7 +35,7 @@
// Definition Language) / schema file.
// Limits maximum depth of nested objects.
-// Prevents stack overflow while parse flatbuffers or json.
+// Prevents stack overflow while parse scheme, or json, or flexbuffer.
#if !defined(FLATBUFFERS_MAX_PARSING_DEPTH)
# define FLATBUFFERS_MAX_PARSING_DEPTH 64
#endif
@@ -239,7 +239,7 @@ template class SymbolTable {
struct Namespace {
Namespace() : from_table(0) {}
- // Given a (potentally unqualified) name, return the "fully qualified" name
+ // Given a (potentially unqualified) name, return the "fully qualified" name
// which has a full namespaced descriptor.
// With max_components you can request less than the number of components
// the current namespace has.
@@ -291,11 +291,11 @@ struct Definition {
struct FieldDef : public Definition {
FieldDef()
: deprecated(false),
- required(false),
key(false),
shared(false),
native_inline(false),
flexbuffer(false),
+ presence(kDefault),
nested_flatbuffer(NULL),
padding(0) {}
@@ -304,16 +304,48 @@ struct FieldDef : public Definition {
bool Deserialize(Parser &parser, const reflection::Field *field);
+ bool IsScalarOptional() const {
+ return IsScalar(value.type.base_type) && IsOptional();
+ }
+ bool IsOptional() const {
+ return presence == kOptional;
+ }
+ bool IsRequired() const {
+ return presence == kRequired;
+ }
+ bool IsDefault() const {
+ return presence == kDefault;
+ }
+
Value value;
bool deprecated; // Field is allowed to be present in old data, but can't be.
// written in new data nor accessed in new code.
- bool required; // Field must always be present.
bool key; // Field functions as a key for creating sorted vectors.
bool shared; // Field will be using string pooling (i.e. CreateSharedString)
// as default serialization behavior if field is a string.
bool native_inline; // Field will be defined inline (instead of as a pointer)
// for native tables if field is a struct.
bool flexbuffer; // This field contains FlexBuffer data.
+
+ enum Presence {
+ // Field must always be present.
+ kRequired,
+ // Non-presence should be signalled to and controlled by users.
+ kOptional,
+ // Non-presence is hidden from users.
+ // Implementations may omit writing default values.
+ kDefault,
+ };
+ Presence static MakeFieldPresence(bool optional, bool required) {
+ FLATBUFFERS_ASSERT(!(required && optional));
+ // clang-format off
+ return required ? FieldDef::kRequired
+ : optional ? FieldDef::kOptional
+ : FieldDef::kDefault;
+ // clang-format on
+ }
+ Presence presence;
+
StructDef *nested_flatbuffer; // This field contains nested FlatBuffer data.
size_t padding; // Bytes to always pad after this field.
};
@@ -410,9 +442,7 @@ struct EnumDef : public Definition {
size_t size() const { return vals.vec.size(); }
- const std::vector &Vals() const {
- return vals.vec;
- }
+ const std::vector &Vals() const { return vals.vec; }
const EnumVal *Lookup(const std::string &enum_name) const {
return vals.Lookup(enum_name);
@@ -433,6 +463,10 @@ struct EnumDef : public Definition {
SymbolTable vals;
};
+inline bool IsString(const Type &type) {
+ return type.base_type == BASE_TYPE_STRING;
+}
+
inline bool IsStruct(const Type &type) {
return type.base_type == BASE_TYPE_STRUCT && type.struct_def->fixed;
}
@@ -508,12 +542,10 @@ struct ServiceDef : public Definition {
// Container of options that may apply to any of the source/text generators.
struct IDLOptions {
+ bool gen_jvmstatic;
// Use flexbuffers instead for binary and text generation
bool use_flexbuffers;
bool strict_json;
- bool skip_js_exports;
- bool use_goog_js_export_format;
- bool use_ES6_js_export_format;
bool output_default_scalars_in_json;
int indent_step;
bool output_enum_identifiers;
@@ -532,6 +564,7 @@ struct IDLOptions {
std::string cpp_object_api_pointer_type;
std::string cpp_object_api_string_type;
bool cpp_object_api_string_flexible_constructor;
+ bool cpp_direct_copy;
bool gen_nullable;
bool java_checkerframework;
bool gen_generated;
@@ -545,11 +578,8 @@ struct IDLOptions {
bool binary_schema_comments;
bool binary_schema_builtins;
bool binary_schema_gen_embed;
- bool skip_flatbuffers_import;
std::string go_import;
std::string go_namespace;
- bool reexport_ts_modules;
- bool js_ts_short_names;
bool protobuf_ascii_alike;
bool size_prefixed;
std::string root_type;
@@ -558,9 +588,11 @@ struct IDLOptions {
bool cs_gen_json_serializer;
std::vector cpp_includes;
std::string cpp_std;
+ bool cpp_static_reflection;
std::string proto_namespace_suffix;
std::string filename_suffix;
std::string filename_extension;
+ bool no_warnings;
// Possible options for the more general generator below.
enum Language {
@@ -568,7 +600,6 @@ struct IDLOptions {
kCSharp = 1 << 1,
kGo = 1 << 2,
kCpp = 1 << 3,
- kJs = 1 << 4,
kPython = 1 << 5,
kPhp = 1 << 6,
kJson = 1 << 7,
@@ -590,6 +621,9 @@ struct IDLOptions {
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;
@@ -603,11 +637,9 @@ struct IDLOptions {
bool set_empty_vectors_to_null;
IDLOptions()
- : use_flexbuffers(false),
+ : gen_jvmstatic(false),
+ use_flexbuffers(false),
strict_json(false),
- skip_js_exports(false),
- use_goog_js_export_format(false),
- use_ES6_js_export_format(false),
output_default_scalars_in_json(false),
indent_step(2),
output_enum_identifiers(true),
@@ -625,6 +657,7 @@ struct IDLOptions {
gen_compare(false),
cpp_object_api_pointer_type("std::unique_ptr"),
cpp_object_api_string_flexible_constructor(false),
+ cpp_direct_copy(true),
gen_nullable(false),
java_checkerframework(false),
gen_generated(false),
@@ -636,18 +669,18 @@ struct IDLOptions {
binary_schema_comments(false),
binary_schema_builtins(false),
binary_schema_gen_embed(false),
- skip_flatbuffers_import(false),
- reexport_ts_modules(true),
- js_ts_short_names(false),
protobuf_ascii_alike(false),
size_prefixed(false),
force_defaults(false),
java_primitive_has_method(false),
cs_gen_json_serializer(false),
+ cpp_static_reflection(false),
filename_suffix("_generated"),
filename_extension(),
+ no_warnings(false),
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) {}
@@ -747,9 +780,10 @@ class Parser : public ParserState {
root_struct_def_(nullptr),
opts(options),
uses_flexbuffers_(false),
+ advanced_features_(0),
source_(nullptr),
- anonymous_counter(0),
- recurse_protection_counter(0) {
+ anonymous_counter_(0),
+ parse_depth_counter_(0) {
if (opts.force_defaults) { builder_.ForceDefaults(true); }
// Start out with the empty namespace being current.
empty_namespace_ = new Namespace();
@@ -776,6 +810,7 @@ class Parser : public ParserState {
known_attributes_["native_inline"] = true;
known_attributes_["native_custom_alloc"] = true;
known_attributes_["native_type"] = true;
+ known_attributes_["native_type_pack_name"] = true;
known_attributes_["native_default"] = true;
known_attributes_["flexbuffer"] = true;
known_attributes_["private"] = true;
@@ -801,6 +836,8 @@ class Parser : public ParserState {
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);
@@ -835,12 +872,20 @@ class Parser : public ParserState {
flexbuffers::Builder *builder);
StructDef *LookupStruct(const std::string &id) const;
+ StructDef *LookupStructThruParentNamespaces(const std::string &id) const;
std::string UnqualifiedName(const std::string &fullQualifiedName);
FLATBUFFERS_CHECKED_ERROR Error(const std::string &msg);
+ // @brief Verify that any of 'opts.lang_to_generate' supports Optional scalars
+ // in a schema.
+ // @param opts Options used to parce a schema and generate code.
+ static bool SupportsOptionalScalars(const flatbuffers::IDLOptions &opts);
+
private:
+ class ParseDepthGuard;
+
void Message(const std::string &msg);
void Warning(const std::string &msg);
FLATBUFFERS_CHECKED_ERROR ParseHexNum(int nibbles, uint64_t *val);
@@ -859,7 +904,7 @@ class Parser : public ParserState {
const std::string &name, const Type &type,
FieldDef **dest);
FLATBUFFERS_CHECKED_ERROR ParseField(StructDef &struct_def);
- FLATBUFFERS_CHECKED_ERROR ParseString(Value &val);
+ FLATBUFFERS_CHECKED_ERROR ParseString(Value &val, bool use_string_pooling);
FLATBUFFERS_CHECKED_ERROR ParseComma();
FLATBUFFERS_CHECKED_ERROR ParseAnyValue(Value &val, FieldDef *field,
size_t parent_fieldn,
@@ -891,6 +936,7 @@ class Parser : public ParserState {
FLATBUFFERS_CHECKED_ERROR TokenError();
FLATBUFFERS_CHECKED_ERROR ParseSingleValue(const std::string *name, Value &e,
bool check_now);
+ FLATBUFFERS_CHECKED_ERROR ParseFunction(const std::string *name, Value &e);
FLATBUFFERS_CHECKED_ERROR ParseEnumFromString(const Type &type,
std::string *result);
StructDef *LookupCreateStruct(const std::string &name,
@@ -912,6 +958,8 @@ class Parser : public ParserState {
FLATBUFFERS_CHECKED_ERROR ParseProtoCurliesOrIdent();
FLATBUFFERS_CHECKED_ERROR ParseTypeFromProtoType(Type *type);
FLATBUFFERS_CHECKED_ERROR SkipAnyJsonValue();
+ FLATBUFFERS_CHECKED_ERROR ParseFlexBufferNumericConstant(
+ flexbuffers::Builder *builder);
FLATBUFFERS_CHECKED_ERROR ParseFlexBufferValue(flexbuffers::Builder *builder);
FLATBUFFERS_CHECKED_ERROR StartParseFile(const char *source,
const char *source_filename);
@@ -922,12 +970,17 @@ class Parser : public ParserState {
const char **include_paths,
const char *source_filename,
const char *include_filename);
+ FLATBUFFERS_CHECKED_ERROR DoParseJson();
FLATBUFFERS_CHECKED_ERROR CheckClash(std::vector &fields,
StructDef *struct_def,
const char *suffix, BaseType baseType);
+ FLATBUFFERS_CHECKED_ERROR ParseAlignAttribute(
+ const std::string &align_constant, size_t min_align, size_t *align);
bool SupportsAdvancedUnionFeatures() const;
bool SupportsAdvancedArrayFeatures() const;
+ bool SupportsOptionalScalars() const;
+ bool SupportsDefaultVectorsAndStrings() const;
Namespace *UniqueNamespace(Namespace *ns);
FLATBUFFERS_CHECKED_ERROR RecurseError();
@@ -950,7 +1003,7 @@ class Parser : public ParserState {
std::string file_identifier_;
std::string file_extension_;
- std::map included_files_;
+ std::map included_files_;
std::map> files_included_per_file_;
std::vector native_included_files_;
@@ -959,6 +1012,8 @@ class Parser : public ParserState {
IDLOptions opts;
bool uses_flexbuffers_;
+ uint64_t advanced_features_;
+
private:
const char *source_;
@@ -966,8 +1021,8 @@ class Parser : public ParserState {
std::vector> field_stack_;
- int anonymous_counter;
- int recurse_protection_counter;
+ int anonymous_counter_;
+ int parse_depth_counter_; // stack-overflow guard
};
// Utility functions for multiple generators:
@@ -992,6 +1047,10 @@ extern bool GenerateText(const Parser &parser, const void *flatbuffer,
extern bool GenerateTextFile(const Parser &parser, const std::string &path,
const std::string &file_name);
+// Generate Json schema to string
+// See idl_gen_json_schema.cpp.
+extern bool GenerateJsonSchema(const Parser &parser, std::string *json);
+
// Generate binary files from a given FlatBuffer, and a given Parser
// object that has been populated with the corresponding schema.
// See code_generators.cpp.
@@ -1018,8 +1077,8 @@ extern bool GenerateJava(const Parser &parser, const std::string &path,
// Generate JavaScript or TypeScript code from the definitions in the Parser
// object. See idl_gen_js.
-extern bool GenerateJSTS(const Parser &parser, const std::string &path,
- const std::string &file_name);
+extern bool GenerateTS(const Parser &parser, const std::string &path,
+ const std::string &file_name);
// Generate Go files from the definitions in the Parser object.
// See idl_gen_go.cpp.
@@ -1071,10 +1130,10 @@ extern std::string GenerateFBS(const Parser &parser,
extern bool GenerateFBS(const Parser &parser, const std::string &path,
const std::string &file_name);
-// Generate a make rule for the generated JavaScript or TypeScript code.
-// See idl_gen_js.cpp.
-extern std::string JSTSMakeRule(const Parser &parser, const std::string &path,
- const std::string &file_name);
+// Generate a make rule for the generated TypeScript code.
+// See idl_gen_ts.cpp.
+extern std::string TSMakeRule(const Parser &parser, const std::string &path,
+ const std::string &file_name);
// Generate a make rule for the generated C++ header.
// See idl_gen_cpp.cpp.
@@ -1132,6 +1191,8 @@ bool GeneratePythonGRPC(const Parser &parser, const std::string &path,
extern bool GenerateSwiftGRPC(const Parser &parser, const std::string &path,
const std::string &file_name);
+extern bool GenerateTSGRPC(const Parser &parser, const std::string &path,
+ const std::string &file_name);
} // namespace flatbuffers
#endif // FLATBUFFERS_IDL_H_
diff --git a/third_party/flatbuffers-c-bridge/third_party/flatbuffers/include/flatbuffers/minireflect.h b/third_party/flatbuffers-c-bridge/third_party/flatbuffers/include/flatbuffers/minireflect.h
index 67a79a93..26fd86c9 100644
--- a/third_party/flatbuffers-c-bridge/third_party/flatbuffers/include/flatbuffers/minireflect.h
+++ b/third_party/flatbuffers-c-bridge/third_party/flatbuffers/include/flatbuffers/minireflect.h
@@ -38,7 +38,7 @@ struct IterationVisitor {
// These mark the scope of a table or struct.
virtual void StartSequence() {}
virtual void EndSequence() {}
- // Called for each field regardless of wether it is present or not.
+ // Called for each field regardless of whether it is present or not.
// If not present, val == nullptr. set_idx is the index of all set fields.
virtual void Field(size_t /*field_idx*/, size_t /*set_idx*/,
ElementaryType /*type*/, bool /*is_vector*/,
@@ -234,10 +234,11 @@ inline void IterateObject(const uint8_t *obj, const TypeTable *type_table,
visitor->StartSequence();
const uint8_t *prev_val = nullptr;
size_t set_idx = 0;
+ size_t array_idx = 0;
for (size_t i = 0; i < type_table->num_elems; i++) {
auto type_code = type_table->type_codes[i];
auto type = static_cast(type_code.base_type);
- auto is_vector = type_code.is_vector != 0;
+ auto is_repeating = type_code.is_repeating != 0;
auto ref_idx = type_code.sequence_ref;
const TypeTable *ref = nullptr;
if (ref_idx >= 0) { ref = type_table->type_refs[ref_idx](); }
@@ -249,15 +250,25 @@ inline void IterateObject(const uint8_t *obj, const TypeTable *type_table,
} else {
val = obj + type_table->values[i];
}
- visitor->Field(i, set_idx, type, is_vector, ref, name, val);
+ visitor->Field(i, set_idx, type, is_repeating, ref, name, val);
if (val) {
set_idx++;
- if (is_vector) {
- val += ReadScalar(val);
- auto vec = reinterpret_cast *>(val);
+ if (is_repeating) {
+ auto elem_ptr = val;
+ size_t size = 0;
+ if (type_table->st == ST_TABLE) {
+ // variable length vector
+ val += ReadScalar(val);
+ auto vec = reinterpret_cast *>(val);
+ elem_ptr = vec->Data();
+ size = vec->size();
+ } else {
+ // otherwise fixed size array
+ size = type_table->array_sizes[array_idx];
+ ++array_idx;
+ }
visitor->StartVector();
- auto elem_ptr = vec->Data();
- for (size_t j = 0; j < vec->size(); j++) {
+ for (size_t j = 0; j < size; j++) {
visitor->Element(j, type, ref, elem_ptr);
IterateValue(type, elem_ptr, ref, prev_val, static_cast(j),
visitor);
diff --git a/third_party/flatbuffers-c-bridge/third_party/flatbuffers/include/flatbuffers/pch/flatc_pch.h b/third_party/flatbuffers-c-bridge/third_party/flatbuffers/include/flatbuffers/pch/flatc_pch.h
new file mode 100644
index 00000000..77132790
--- /dev/null
+++ b/third_party/flatbuffers-c-bridge/third_party/flatbuffers/include/flatbuffers/pch/flatc_pch.h
@@ -0,0 +1,39 @@
+/*
+ * Copyright 2017 Google Inc. All rights reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef FLATBUFFERS_FLATC_PCH_H_
+#define FLATBUFFERS_FLATC_PCH_H_
+
+// stl
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+
+// flatbuffers
+#include "flatbuffers/pch/pch.h"
+#include "flatbuffers/code_generators.h"
+#include "flatbuffers/flatbuffers.h"
+#include "flatbuffers/flexbuffers.h"
+#include "flatbuffers/idl.h"
+
+#endif // FLATBUFFERS_FLATC_PCH_H_
diff --git a/third_party/flatbuffers-c-bridge/third_party/flatbuffers/include/flatbuffers/pch/pch.h b/third_party/flatbuffers-c-bridge/third_party/flatbuffers/include/flatbuffers/pch/pch.h
new file mode 100644
index 00000000..804e99ed
--- /dev/null
+++ b/third_party/flatbuffers-c-bridge/third_party/flatbuffers/include/flatbuffers/pch/pch.h
@@ -0,0 +1,38 @@
+/*
+ * Copyright 2017 Google Inc. All rights reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef FLATBUFFERS_PCH_H_
+#define FLATBUFFERS_PCH_H_
+
+// stl
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include