17#ifndef FLATBUFFERS_IDL_H_
18#define FLATBUFFERS_IDL_H_
37#if !defined(FLATBUFFERS_MAX_PARSING_DEPTH)
38# define FLATBUFFERS_MAX_PARSING_DEPTH 64
47#define FLATBUFFERS_GEN_TYPES_SCALAR(TD) \
48 TD(NONE, "", uint8_t, byte, byte, byte, uint8, u8, UByte, UInt8, 0) \
49 TD(UTYPE, "", uint8_t, byte, byte, byte, uint8, u8, UByte, UInt8, 1) \
50 TD(BOOL, "bool", uint8_t, boolean,bool, bool, bool, bool, Boolean, Bool, 2) \
51 TD(CHAR, "byte", int8_t, byte, int8, sbyte, int8, i8, Byte, Int8, 3) \
52 TD(UCHAR, "ubyte", uint8_t, byte, byte, byte, uint8, u8, UByte, UInt8, 4) \
53 TD(SHORT, "short", int16_t, short, int16, short, int16, i16, Short, Int16, 5) \
54 TD(USHORT, "ushort", uint16_t, short, uint16, ushort, uint16, u16, UShort, UInt16, 6) \
55 TD(INT, "int", int32_t, int, int32, int, int32, i32, Int, Int32, 7) \
56 TD(UINT, "uint", uint32_t, int, uint32, uint, uint32, u32, UInt, UInt32, 8) \
57 TD(LONG, "long", int64_t, long, int64, long, int64, i64, Long, Int64, 9) \
58 TD(ULONG, "ulong", uint64_t, long, uint64, ulong, uint64, u64, ULong, UInt64, 10) \
59 TD(FLOAT, "float", float, float, float32, float, float32, f32, Float, Float32, 11) \
60 TD(DOUBLE, "double", double, double, float64, double, float64, f64, Double, Double, 12)
61#define FLATBUFFERS_GEN_TYPES_POINTER(TD) \
62 TD(STRING, "string", Offset<void>, int, int, StringOffset, int, unused, Int, Offset<String>, 13) \
63 TD(VECTOR, "", Offset<void>, int, int, VectorOffset, int, unused, Int, Offset<UOffset>, 14) \
64 TD(VECTOR64, "", Offset64<void>, int, int, VectorOffset, int, unused, Int, Offset<UOffset>, 18) \
65 TD(STRUCT, "", Offset<void>, int, int, int, int, unused, Int, Offset<UOffset>, 15) \
66 TD(UNION, "", Offset<void>, int, int, int, int, unused, Int, Offset<UOffset>, 16)
67#define FLATBUFFERS_GEN_TYPE_ARRAY(TD) \
68 TD(ARRAY, "", int, int, int, int, int, unused, Int, Offset<UOffset>, 17)
109#define FLATBUFFERS_GEN_TYPES(TD) \
110 FLATBUFFERS_GEN_TYPES_SCALAR(TD) \
111 FLATBUFFERS_GEN_TYPES_POINTER(TD) \
112 FLATBUFFERS_GEN_TYPE_ARRAY(TD)
119 #define FLATBUFFERS_TD(ENUM, IDLTYPE, \
120 CTYPE, JTYPE, GTYPE, NTYPE, PTYPE, RTYPE, KTYPE, STYPE, ENUM_VALUE) \
121 BASE_TYPE_ ## ENUM = ENUM_VALUE,
123 #undef FLATBUFFERS_TD
126#define FLATBUFFERS_TD(ENUM, IDLTYPE, CTYPE, ...) \
127 static_assert(sizeof(CTYPE) <= sizeof(largest_scalar_t), \
128 "define largest_scalar_t as " #CTYPE);
133 t <= BASE_TYPE_DOUBLE; }
135 t <= BASE_TYPE_ULONG; }
137 t == BASE_TYPE_DOUBLE; }
139 t == BASE_TYPE_ULONG; }
142 t <= BASE_TYPE_UCHAR; }
144 t == BASE_TYPE_VECTOR64; }
147 return (t == BASE_TYPE_UTYPE) || (t == BASE_TYPE_UCHAR) ||
148 (t == BASE_TYPE_USHORT) || (t == BASE_TYPE_UINT) ||
149 (t == BASE_TYPE_ULONG);
154 #define FLATBUFFERS_TD(ENUM, IDLTYPE, CTYPE, ...) \
155 case BASE_TYPE_##ENUM: return sizeof(CTYPE);
157 #undef FLATBUFFERS_TD
165 #define FLATBUFFERS_TD(ENUM, IDLTYPE, ...) \
166 case BASE_TYPE_##ENUM: return IDLTYPE;
168 #undef FLATBUFFERS_TD
176 #define FLATBUFFERS_TD(ENUM, IDLTYPE, CTYPE, ...) \
177 case BASE_TYPE_##ENUM: return #CTYPE;
179 #undef FLATBUFFERS_TD
195 EnumDef *_ed =
nullptr, uint16_t _fixed_length = 0)
228 offset(static_cast<voffset_t>(~(static_cast<voffset_t>(0U)))) {}
239 for (
auto it =
vec.begin(); it !=
vec.end(); ++it) {
delete *it; }
242 bool Add(
const std::string &name, T *e) {
244 auto it =
dict.find(name);
245 if (it !=
dict.end())
return true;
250 void Move(
const std::string &oldname,
const std::string &newname) {
251 auto it =
dict.find(oldname);
252 if (it !=
dict.end()) {
253 auto obj = it->second;
261 T *
Lookup(
const std::string &name)
const {
262 auto it =
dict.find(name);
263 return it ==
dict.end() ? nullptr : it->second;
267 std::map<std::string, T *>
dict;
280 size_t max_components = 1000)
const;
287 size_t min_size = std::min(a.
components.size(), b.components.size());
288 for (
size_t i = 0; i < min_size; ++i) {
292 return a.
components.size() < b.components.size();
310 const Vector<Offset<reflection::KeyValue>> *attrs);
340 const Parser &parser)
const;
401 auto padding = PaddingBytes(
bytesize, min_align);
403 if (
fields.vec.size())
fields.vec.back()->padding = padding;
407 const Parser &parser)
const;
425struct EnumValBuilder;
429 const Parser &parser)
const;
438 const Vector<Offset<reflection::KeyValue>> *attrs);
440 uint64_t
GetAsUInt64()
const {
return static_cast<uint64_t
>(value); }
442 bool IsZero()
const {
return 0 == value; }
452 friend EnumValBuilder;
455 EnumVal(
const std::string &_name, int64_t _val) :
name(_name), value(_val) {}
465 const Parser &parser)
const;
482 bool skip_union_default =
false)
const;
490 size_t size()
const {
return vals.vec.size(); }
492 const std::vector<EnumVal *> &
Vals()
const {
return vals.vec; }
495 return vals.Lookup(enum_name);
505 bool IsUInt64()
const {
509 friend EnumValBuilder;
514 return type.base_type == BASE_TYPE_STRING;
518 return type.base_type == BASE_TYPE_STRUCT &&
type.struct_def->fixed;
522 return type.base_type == BASE_TYPE_STRUCT &&
type.struct_def->predecl;
526 return type.base_type == BASE_TYPE_STRUCT && !
type.struct_def->fixed;
530 return type.enum_def !=
nullptr &&
type.enum_def->is_union;
548 return type.base_type == BASE_TYPE_ARRAY;
561 ?
type.struct_def->bytesize
569 return type.struct_def->minalign;
578 return lhs.value == rhs.value;
581 return !(lhs == rhs);
587 (a.
struct_def !=
nullptr && b.struct_def !=
nullptr &&
590 (a.
enum_def !=
nullptr && b.enum_def !=
nullptr &&
596 const Parser &parser)
const;
605 const Parser &parser)
const;
879 : is_error_(error), has_been_checked_(false) {}
882 is_error_ = other.is_error_;
883 has_been_checked_ =
false;
884 other.has_been_checked_ =
true;
895 has_been_checked_ =
true;
901 mutable bool has_been_checked_;
908#define FLATBUFFERS_CHECKED_ERROR CheckedError \
909 __attribute__((warn_unused_result))
911#define FLATBUFFERS_CHECKED_ERROR CheckedError
927 anonymous_counter_(0),
928 parse_depth_counter_(0) {
992 bool Parse(
const char *_source,
const char **include_paths =
nullptr,
993 const char *source_filename =
nullptr);
995 bool ParseJson(
const char *json,
const char *json_filename =
nullptr);
1009 const std::string &file_name)
const;
1031 flexbuffers::Builder *builder);
1051 class ParseDepthGuard;
1053 void Message(
const std::string &msg);
1054 void Warning(
const std::string &msg);
1058 bool Is(
int t)
const;
1059 bool IsIdent(
const char *
id)
const;
1061 std::string TokenToStringId(
int t)
const;
1062 EnumDef *LookupEnum(
const std::string &
id);
1068 const std::string &name,
const Type &
type,
1074 size_t parent_fieldn,
1077 bool inside_vector =
false);
1078 template<
typename F>
1083 std::string *value, uoffset_t *ovalue);
1084 void SerializeStruct(
const StructDef &struct_def,
const Value &val);
1087 template<
typename F>
1105 std::string *result);
1106 StructDef *LookupCreateStruct(
const std::string &name,
1107 bool create_if_new =
true,
1108 bool definition =
false);
1110 const char *filename);
1119 bool isextend,
bool inside_oneof);
1128 flexbuffers::Builder *builder);
1131 const char *source_filename);
1133 const char **include_paths,
1134 const char *source_filename);
1139 const char **include_paths,
1140 const char *source_filename,
1141 const char *include_filename);
1145 const char *suffix,
BaseType baseType);
1147 const std::string &align_constant,
size_t min_align,
size_t *align);
1149 bool SupportsAdvancedUnionFeatures()
const;
1150 bool SupportsAdvancedArrayFeatures()
const;
1152 bool SupportsDefaultVectorsAndStrings()
const;
1153 bool Supports64BitOffsets()
const;
1154 bool SupportsUnionUnderlyingType()
const;
1160 const std::string &GetPooledString(
const std::string &s)
const;
1194 const char *source_;
1196 std::vector<std::pair<Value, FieldDef *>> field_stack_;
1200 mutable std::set<std::string> string_cache_;
1202 int anonymous_counter_;
1203 int parse_depth_counter_;
1218 const std::string &tablename,
1223 const std::string &file_name);
1228 const std::string &file_name);
1233 const std::string &file_name);
1238 const std::string &file_name);
1243 const std::string &file_name);
1248 const std::string &file_name);
1251 const std::string &file_name);
#define FLATBUFFERS_ASSERT
CheckedError & operator=(const CheckedError &other)
CheckedError(const CheckedError &other)
void ForceDefaults(bool fd)
In order to save space, fields that are set to their default value don't get serialized into the buff...
StructDef * LookupStructThruParentNamespaces(const std::string &id) const
flexbuffers::Reference flex_root_
Type * DeserializeType(const reflection::Type *type)
std::map< std::string, std::set< IncludedFile > > files_included_per_file_
std::string file_being_parsed_
Namespace * current_namespace_
SymbolTable< ServiceDef > services_
Parser(const IDLOptions &options=IDLOptions())
bool Parse(const char *_source, const char **include_paths=nullptr, const char *source_filename=nullptr)
bool SetRootType(const char *name)
SymbolTable< EnumDef > enums_
std::string file_identifier_
SymbolTable< Type > types_
std::string ConformTo(const Parser &base)
StructDef * LookupStruct(const std::string &id) const
SymbolTable< StructDef > structs_
std::vector< std::string > native_included_files_
std::string file_extension_
std::set< std::string > GetIncludedFilesRecursive(const std::string &file_name) const
Parser(const Parser &)=delete
Parser & operator=(const Parser &)=delete
std::vector< Namespace * > namespaces_
FLATBUFFERS_CHECKED_ERROR Error(const std::string &msg)
uint64_t advanced_features_
flexbuffers::Builder flex_builder_
std::string UnqualifiedName(const std::string &fullQualifiedName)
FlatBufferBuilder builder_
StructDef * root_struct_def_
Parser & operator=(Parser &&)=default
std::ptrdiff_t BytesConsumed() const
bool Deserialize(const reflection::Schema *schema)
bool ParseJson(const char *json, const char *json_filename=nullptr)
std::map< uint64_t, std::string > included_files_
bool ParseFlexBuffer(const char *source, const char *source_filename, flexbuffers::Builder *builder)
std::map< std::string, bool > known_attributes_
static bool SupportsOptionalScalars(const flatbuffers::IDLOptions &opts)
Namespace * empty_namespace_
Parser(Parser &&)=default
std::vector< IncludedFile > GetIncludedFiles() const
bool Deserialize(const uint8_t *buf, const size_t size)
void Move(const std::string &oldname, const std::string &newname)
bool Add(const std::string &name, T *e)
std::map< std::string, T * > dict
T * Lookup(const std::string &name) const
#define FLATBUFFERS_CHECKED_ERROR
#define FLATBUFFERS_GEN_TYPES(TD)
#define FLATBUFFERS_TD(ENUM, IDLTYPE, CTYPE, JTYPE, GTYPE, NTYPE, PTYPE, RTYPE, KTYPE, STYPE, ENUM_VALUE)
bool GenerateSwiftGRPC(const Parser &parser, const std::string &path, const std::string &file_name)
bool operator!=(const EnumVal &lhs, const EnumVal &rhs)
bool IsInteger(BaseType t)
bool IsScalar(BaseType t)
bool GenerateTSGRPC(const Parser &parser, const std::string &path, const std::string &file_name)
bool IsUnion(const Type &type)
bool IsSeries(const Type &type)
bool IsStruct(const Type &type)
bool GenerateJavaGRPC(const Parser &parser, const std::string &path, const std::string &file_name)
bool IsUnsigned(BaseType t)
bool IsIncompleteStruct(const Type &type)
const char * GenText(const Parser &parser, const void *flatbuffer, std::string *text)
std::string NumToString(T t)
bool operator<(const Namespace &a, const Namespace &b)
bool GenerateCppGRPC(const Parser &parser, const std::string &path, const std::string &file_name)
bool IsString(const Type &type)
bool IsOneByte(BaseType t)
bool operator==(const Array< T, length > &lhs, const Array< T, length > &rhs) noexcept
const char * GenTextFromTable(const Parser &parser, const void *table, const std::string &tablename, std::string *text)
bool GenerateGoGRPC(const Parser &parser, const std::string &path, const std::string &file_name)
size_t InlineAlignment(const Type &type)
bool IsVectorOfTable(const Type &type)
bool IsUnionType(const Type &type)
const char * TypeName(const BaseType t)
bool IsArray(const Type &type)
bool IsTable(const Type &type)
const char * GenTextFile(const Parser &parser, const std::string &path, const std::string &file_name)
size_t InlineSize(const Type &type)
const char * StringOf(const BaseType t)
bool GeneratePythonGRPC(const Parser &parser, const std::string &path, const std::string &file_name)
size_t SizeOf(const BaseType t)
bool IsVectorOfStruct(const Type &type)
bool IsEnum(const Type &type)
bool EqualByName(const Type &a, const Type &b)
bool IsVector(BaseType t)
SymbolTable< Value > attributes
const std::string * declaration_file
std::vector< std::string > doc_comment
bool DeserializeAttributes(Parser &parser, const Vector< Offset< reflection::KeyValue > > *attrs)
flatbuffers::Offset< flatbuffers::Vector< flatbuffers::Offset< reflection::KeyValue > > > SerializeAttributes(FlatBufferBuilder *builder, const Parser &parser) const
uoffset_t serialized_location
Namespace * defined_namespace
bool uses_multiple_type_instances
uint64_t Distance() const
EnumVal * ReverseLookup(int64_t enum_idx, bool skip_union_default=false) const
std::string ToString(const EnumVal &ev) const
std::string AllFlags() const
Offset< reflection::Enum > Serialize(FlatBufferBuilder *builder, const Parser &parser) const
const EnumVal * Lookup(const std::string &enum_name) const
void ChangeEnumValue(EnumVal *ev, T new_val)
const std::vector< EnumVal * > & Vals() const
EnumVal * FindByValue(const std::string &constant) const
bool Deserialize(Parser &parser, const reflection::Enum *values)
const EnumVal * MaxValue() const
const EnumVal * MinValue() const
uint64_t Distance(const EnumVal *v1, const EnumVal *v2) const
uint64_t GetAsUInt64() const
flatbuffers::Offset< flatbuffers::Vector< flatbuffers::Offset< reflection::KeyValue > > > SerializeAttributes(FlatBufferBuilder *builder, const Parser &parser) const
friend bool operator==(const EnumVal &lhs, const EnumVal &rhs)
SymbolTable< Value > attributes
bool DeserializeAttributes(Parser &parser, const Vector< Offset< reflection::KeyValue > > *attrs)
int64_t GetAsInt64() const
bool Deserialize(Parser &parser, const reflection::EnumVal *val)
std::vector< std::string > doc_comment
Offset< reflection::EnumVal > Serialize(FlatBufferBuilder *builder, const Parser &parser) const
StructDef * nested_flatbuffer
FieldDef * sibling_union_field
Offset< reflection::Field > Serialize(FlatBufferBuilder *builder, uint16_t id, const Parser &parser) const
bool IsScalarOptional() const
static Presence MakeFieldPresence(bool optional, bool required)
bool Deserialize(Parser &parser, const reflection::Field *field)
CaseStyle cpp_object_api_field_case_style
bool union_value_namespacing
std::string filename_suffix
unsigned long lang_to_generate
bool cpp_static_reflection
bool java_primitive_has_method
std::string go_module_name
bool swift_implementation_only
bool no_leak_private_annotations
bool python_no_type_prefix_suffix
std::string proto_namespace_suffix
ProtoIdGapAction proto_id_gap_action
bool json_nested_legacy_flatbuffers
bool json_nested_flexbuffers
bool generate_name_strings
std::vector< std::string > cpp_includes
std::string java_package_prefix
std::string cpp_object_api_pointer_type
std::string object_suffix
bool require_explicit_ids
bool set_empty_strings_to_null
bool java_checkerframework
bool cpp_object_api_string_flexible_constructor
bool binary_schema_gen_embed
std::string cpp_object_api_string_type
bool cs_gen_json_serializer
bool include_dependence_headers
std::string include_prefix
bool json_nested_flatbuffers
bool output_default_scalars_in_json
bool emit_min_max_enum_values
bool generate_object_based_api
std::string filename_extension
std::string object_prefix
bool output_enum_identifiers
bool set_empty_vectors_to_null
bool skip_unexpected_fields_in_json
bool rust_module_root_file
bool binary_schema_builtins
bool protobuf_ascii_alike
bool binary_schema_comments
std::string GetFullyQualifiedName(const std::string &name, size_t max_components=1000) const
std::vector< std::string > components
const char * prev_cursor_
std::vector< std::string > doc_comment_
int64_t CursorPosition() const
bool attr_is_trivial_ascii_string_
void ResetState(const char *source)
Offset< reflection::RPCCall > Serialize(FlatBufferBuilder *builder, const Parser &parser) const
bool Deserialize(Parser &parser, const reflection::RPCCall *call)
SymbolTable< RPCCall > calls
Offset< reflection::Service > Serialize(FlatBufferBuilder *builder, const Parser &parser) const
bool Deserialize(Parser &parser, const reflection::Service *service)
flatbuffers::unique_ptr< std::string > original_location
Offset< reflection::Object > Serialize(FlatBufferBuilder *builder, const Parser &parser) const
std::vector< voffset_t > reserved_ids
SymbolTable< FieldDef > fields
void PadLastField(size_t min_align)
bool Deserialize(Parser &parser, const reflection::Object *object)
Type(BaseType _base_type=BASE_TYPE_NONE, StructDef *_sd=nullptr, EnumDef *_ed=nullptr, uint16_t _fixed_length=0)
bool operator==(const Type &o) const
bool Deserialize(const Parser &parser, const reflection::Type *type)
Offset< reflection::Type > Serialize(FlatBufferBuilder *builder) const