18#ifndef FLATBUFFERS_IDL_H_
19#define FLATBUFFERS_IDL_H_
31#if !defined(FLATBUFFERS_CPP98_STL)
40#if !defined(FLATBUFFERS_MAX_PARSING_DEPTH)
41#define FLATBUFFERS_MAX_PARSING_DEPTH 64
51#define FLATBUFFERS_GEN_TYPES_SCALAR(TD) \
52 TD(NONE, "", uint8_t, byte, byte, byte, uint8, u8, UByte, UInt8) \
53 TD(UTYPE, "", uint8_t, byte, byte, byte, uint8, u8, UByte, UInt8) \
54 TD(BOOL, "bool", uint8_t, boolean,bool, bool, bool, bool, Boolean, Bool) \
55 TD(CHAR, "byte", int8_t, byte, int8, sbyte, int8, i8, Byte, Int8) \
56 TD(UCHAR, "ubyte", uint8_t, byte, byte, byte, uint8, u8, UByte, UInt8) \
57 TD(SHORT, "short", int16_t, short, int16, short, int16, i16, Short, Int16) \
58 TD(USHORT, "ushort", uint16_t, short, uint16, ushort, uint16, u16, UShort, UInt16) \
59 TD(INT, "int", int32_t, int, int32, int, int32, i32, Int, Int32) \
60 TD(UINT, "uint", uint32_t, int, uint32, uint, uint32, u32, UInt, UInt32) \
61 TD(LONG, "long", int64_t, long, int64, long, int64, i64, Long, Int64) \
62 TD(ULONG, "ulong", uint64_t, long, uint64, ulong, uint64, u64, ULong, UInt64) \
63 TD(FLOAT, "float", float, float, float32, float, float32, f32, Float, Float32) \
64 TD(DOUBLE, "double", double, double, float64, double, float64, f64, Double, Double)
65#define FLATBUFFERS_GEN_TYPES_POINTER(TD) \
66 TD(STRING, "string", Offset<void>, int, int, StringOffset, int, unused, Int, Offset<String>) \
67 TD(VECTOR, "", Offset<void>, int, int, VectorOffset, int, unused, Int, Offset<UOffset>) \
68 TD(STRUCT, "", Offset<void>, int, int, int, int, unused, Int, Offset<UOffset>) \
69 TD(UNION, "", Offset<void>, int, int, int, int, unused, Int, Offset<UOffset>)
70#define FLATBUFFERS_GEN_TYPE_ARRAY(TD) \
71 TD(ARRAY, "", int, int, int, int, int, unused, Int, Offset<UOffset>)
110#define FLATBUFFERS_GEN_TYPES(TD) \
111 FLATBUFFERS_GEN_TYPES_SCALAR(TD) \
112 FLATBUFFERS_GEN_TYPES_POINTER(TD) \
113 FLATBUFFERS_GEN_TYPE_ARRAY(TD)
120 #define FLATBUFFERS_TD(ENUM, ...) \
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; }
145 return (t == BASE_TYPE_UTYPE) || (t == BASE_TYPE_UCHAR) ||
146 (t == BASE_TYPE_USHORT) || (t == BASE_TYPE_UINT) ||
147 (t == BASE_TYPE_ULONG);
166 EnumDef *_ed =
nullptr, uint16_t _fixed_length = 0)
208 for (
auto it =
vec.begin(); it !=
vec.end(); ++it)
214 bool Add(
const std::string &name, T *e)
217 auto it =
dict.find(name);
218 if (it !=
dict.end())
224 void Move(
const std::string &oldname,
const std::string &newname)
226 auto it =
dict.find(oldname);
227 if (it !=
dict.end())
229 auto obj = it->second;
241 auto it =
dict.find(name);
242 return it ==
dict.end() ? nullptr : it->second;
246 std::map<std::string, T *>
dict;
267 size_t min_size = std::min(a.
components.size(), b.components.size());
268 for (
size_t i = 0; i < min_size; ++i)
273 return a.
components.size() < b.components.size();
311 const Parser &parser)
const;
364 auto padding = PaddingBytes(
bytesize, min_align);
367 fields.vec.back()->padding = padding;
387struct EnumValBuilder;
395 uint64_t
GetAsUInt64()
const {
return static_cast<uint64_t
>(value); }
397 bool IsZero()
const {
return 0 == value; }
406 friend EnumValBuilder;
409 EnumVal(
const std::string &_name, int64_t _val) :
name(_name), value(_val) {}
443 size_t size()
const {
return vals.vec.size(); }
445 const std::vector<EnumVal *> &
Vals()
const {
return vals.vec; }
447 const EnumVal *
Lookup(
const std::string &enum_name)
const {
return vals.Lookup(enum_name); }
458 friend EnumValBuilder;
462inline bool IsString(
const Type &type) {
return type.base_type == BASE_TYPE_STRING; }
466 return type.base_type == BASE_TYPE_STRUCT && type.struct_def->fixed;
471 return type.enum_def !=
nullptr && type.enum_def->is_union;
474inline bool IsVector(
const Type &type) {
return type.base_type == BASE_TYPE_VECTOR; }
476inline bool IsArray(
const Type &type) {
return type.base_type == BASE_TYPE_ARRAY; }
482 return type.enum_def !=
nullptr &&
IsInteger(type.base_type);
487 return IsStruct(type) ? type.struct_def->bytesize
489 :
SizeOf(type.base_type));
496 return type.struct_def->minalign;
500 return IsStruct(type.VectorType()) ? type.struct_def->minalign :
SizeOf(type.element);
504 return SizeOf(type.base_type);
711 explicit CheckedError(
bool error) : is_error_(error), has_been_checked_(false) {}
715 is_error_ = other.is_error_;
716 has_been_checked_ =
false;
717 other.has_been_checked_ =
true;
730 has_been_checked_ =
true;
736 mutable bool has_been_checked_;
743#define FLATBUFFERS_CHECKED_ERROR CheckedError \
744 __attribute__((warn_unused_result))
746#define FLATBUFFERS_CHECKED_ERROR CheckedError
757 anonymous_counter_(0), parse_depth_counter_(0)
813 bool Parse(
const char *_source,
const char **include_paths =
nullptr,
814 const char *source_filename =
nullptr);
816 bool ParseJson(
const char *json,
const char *json_filename =
nullptr);
848 flexbuffers::Builder *builder);
863 class ParseDepthGuard;
865 void Message(
const std::string &msg);
866 void Warning(
const std::string &msg);
870 bool Is(
int t)
const;
871 bool IsIdent(
const char *
id)
const;
873 std::string TokenToStringId(
int t)
const;
874 EnumDef *LookupEnum(
const std::string &
id);
884 const StructDef *parent_struct_def, uoffset_t count,
885 bool inside_vector =
false);
886 template <
typename F>
891 void SerializeStruct(
const StructDef &struct_def,
const Value &val);
907 StructDef *LookupCreateStruct(
const std::string &name,
bool create_if_new =
true,
908 bool definition =
false);
927 const char *source_filename);
929 const char *source_filename,
const char *include_filename);
932 const char *suffix,
BaseType baseType);
936 bool SupportsAdvancedUnionFeatures()
const;
937 bool SupportsAdvancedArrayFeatures()
const;
939 bool SupportsDefaultVectorsAndStrings()
const;
976 std::string file_being_parsed_;
978 std::vector<std::pair<Value, FieldDef *>> field_stack_;
980 int anonymous_counter_;
981 int parse_depth_counter_;
986extern std::string
MakeCamel(
const std::string &in,
bool first =
true);
999 const std::string &tablename, std::string *text);
1002 const std::string &file_name);
1012 const std::string &file_name);
1017 const std::string &file_name);
1022 const std::string &file_name);
1025 const std::string &file_name);
1030 const std::string &file_name);
1034extern bool GenerateTS(
const Parser &parser,
const std::string &path,
const std::string &file_name);
1038extern bool GenerateGo(
const Parser &parser,
const std::string &path,
const std::string &file_name);
1043 const std::string &file_name);
1048 const std::string &file_name);
1053 const std::string &file_name);
1058 const std::string &file_name);
1063 const std::string &file_name);
1068 const std::string &file_name);
1071 const std::string &file_name);
1076 const std::string &file_name);
1082 const std::string &file_name);
1087 const std::string &file_name);
1092 const std::string &file_name);
1097 const std::string &file_name);
1102 const std::string &file_name);
1107 const std::string &file_name);
1112 const std::string &file_names);
1117 const std::string &file_name);
1134 const std::string &file_name);
1139 const std::string &file_name);
1142 const std::string &file_name);
#define FLATBUFFERS_ASSERT
CheckedError & operator=(const CheckedError &other)
CheckedError(const CheckedError &other)
Helper class to hold data needed in creation of a FlatBuffer. To serialize data, you typically call o...
void ForceDefaults(bool fd)
In order to save space, fields that are set to their default value don't get serialized into the buff...
std::map< std::string, std::set< std::string > > files_included_per_file_
StructDef * LookupStructThruParentNamespaces(const std::string &id) const
flexbuffers::Reference flex_root_
Type * DeserializeType(const reflection::Type *type)
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
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_
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_
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_TD(ENUM,...)
#define FLATBUFFERS_GEN_TYPES(TD)
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)
std::string TextMakeRule(const Parser &parser, const std::string &path, const std::string &file_names)
bool IsScalar(BaseType t)
bool GenerateTextFromTable(const Parser &parser, const void *table, const std::string &tablename, std::string *text)
bool GenerateJava(const Parser &parser, const std::string &path, const std::string &file_name)
bool GenerateCSharp(const Parser &parser, const std::string &path, const std::string &file_name)
std::string RustMakeRule(const Parser &parser, const std::string &path, const std::string &file_name)
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 operator==(const EnumVal &lhs, const EnumVal &rhs)
bool IsUnsigned(BaseType t)
std::string TSMakeRule(const Parser &parser, const std::string &path, const std::string &file_name)
void vector_emplace_back(std::vector< T > *vector, V &&data)
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 GenerateRust(const Parser &parser, const std::string &path, const std::string &file_name)
std::string CPPMakeRule(const Parser &parser, const std::string &path, const std::string &file_name)
bool GenerateCPP(const Parser &parser, const std::string &path, const std::string &file_name)
bool GenerateLobster(const Parser &parser, const std::string &path, const std::string &file_name)
bool IsOneByte(BaseType t)
bool GenerateSwift(const Parser &parser, const std::string &path, const std::string &file_name)
bool GenerateKotlin(const Parser &parser, const std::string &path, const std::string &file_name)
bool GenerateGo(const Parser &parser, const std::string &path, const std::string &file_name)
bool GenerateDart(const Parser &parser, const std::string &path, const std::string &file_name)
bool GenerateGoGRPC(const Parser &parser, const std::string &path, const std::string &file_name)
size_t InlineAlignment(const Type &type)
std::string MakeCamel(const std::string &in, bool first=true)
bool IsArray(const Type &type)
std::string GenerateFBS(const Parser &parser, const std::string &file_name)
size_t SizeOf(BaseType t)
bool GenerateTextFile(const Parser &parser, const std::string &path, const std::string &file_name)
bool GeneratePython(const Parser &parser, const std::string &path, const std::string &file_name)
std::string BinaryMakeRule(const Parser &parser, const std::string &path, const std::string &file_name)
bool GenerateText(const Parser &parser, const void *flatbuffer, std::string *text)
std::string MakeScreamingCamel(const std::string &in)
size_t InlineSize(const Type &type)
const char *const kTypeNames[]
bool GeneratePythonGRPC(const Parser &parser, const std::string &path, const std::string &file_name)
std::string JavaCSharpMakeRule(const Parser &parser, const std::string &path, const std::string &file_name)
bool GenerateTS(const Parser &parser, const std::string &path, const std::string &file_name)
bool GenerateJsonSchema(const Parser &parser, std::string *json)
bool IsVector(const Type &type)
bool IsEnum(const Type &type)
bool GeneratePhp(const Parser &parser, const std::string &path, const std::string &file_name)
bool EqualByName(const Type &a, const Type &b)
bool GenerateLua(const Parser &parser, const std::string &path, const std::string &file_name)
std::string DartMakeRule(const Parser &parser, const std::string &path, const std::string &file_name)
bool GenerateBinary(const Parser &parser, const std::string &path, const std::string &file_name)
SymbolTable< Value > attributes
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
bool Deserialize(const Parser &parser, const reflection::EnumVal *val)
friend bool operator==(const EnumVal &lhs, const EnumVal &rhs)
int64_t GetAsInt64() const
std::vector< std::string > doc_comment
Offset< reflection::EnumVal > Serialize(FlatBufferBuilder *builder, const Parser &parser) const
StructDef * nested_flatbuffer
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)
bool union_value_namespacing
std::string filename_suffix
unsigned long lang_to_generate
bool cpp_static_reflection
bool java_primitive_has_method
std::string proto_namespace_suffix
bool generate_name_strings
std::vector< std::string > cpp_includes
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 output_default_scalars_in_json
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 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
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
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 Deserialize(const Parser &parser, const reflection::Type *type)
bool operator==(const Type &o)
Offset< reflection::Type > Serialize(FlatBufferBuilder *builder) const