1// This schema defines objects that represent a parsed schema, like 2// the binary version of a .fbs file. 3// This could be used to operate on unknown FlatBuffers at runtime. 4// It can even ... represent itself (!) 5 6namespace reflection; 7 8// These must correspond to the enum in idl.h. 9enum BaseType : byte { 10 None, 11 UType, 12 Bool, 13 Byte, 14 UByte, 15 Short, 16 UShort, 17 Int, 18 UInt, 19 Long, 20 ULong, 21 Float, 22 Double, 23 String, 24 Vector, 25 Obj, // Used for tables & structs. 26 Union, 27 Array, 28 Vector64, 29 30 // Add any new type above this value. 31 MaxBaseType 32} 33 34table Type { 35 base_type:BaseType; 36 element:BaseType = None; // Only if base_type == Vector 37 // or base_type == Array. 38 index:int = -1; // If base_type == Object, index into "objects" below. 39 // If base_type == Union, UnionType, or integral derived 40 // from an enum, index into "enums" below. 41 // If base_type == Vector && element == Union or UnionType. 42 fixed_length:uint16 = 0; // Only if base_type == Array. 43 /// The size (octets) of the `base_type` field. 44 base_size:uint = 4; // 4 Is a common size due to offsets being that size. 45 /// The size (octets) of the `element` field, if present. 46 element_size:uint = 0; 47} 48 49table KeyValue { 50 key:string (required, key); 51 value:string; 52} 53 54table EnumVal { 55 name:string (required); 56 value:long (key); 57 object:Object (deprecated); 58 union_type:Type; 59 documentation:[string]; 60 attributes:[KeyValue]; 61} 62 63table Enum { 64 name:string (required, key); 65 values:[EnumVal] (required); // In order of their values. 66 is_union:bool = false; 67 underlying_type:Type (required); 68 attributes:[KeyValue]; 69 documentation:[string]; 70 /// File that this Enum is declared in. 71 declaration_file: string; 72} 73 74table Field { 75 name:string (required, key); 76 type:Type (required); 77 id:ushort; 78 offset:ushort; // Offset into the vtable for tables, or into the struct. 79 default_integer:long = 0; 80 default_real:double = 0.0; 81 deprecated:bool = false; 82 required:bool = false; 83 key:bool = false; 84 attributes:[KeyValue]; 85 documentation:[string]; 86 optional:bool = false; 87 /// Number of padding octets to always add after this field. Structs only. 88 padding:uint16 = 0; 89 /// If the field uses 64-bit offsets. 90 offset64:bool = false; 91} 92 93table Object { // Used for both tables and structs. 94 name:string (required, key); 95 fields:[Field] (required); // Sorted. 96 is_struct:bool = false; 97 minalign:int; 98 bytesize:int; // For structs. 99 attributes:[KeyValue]; 100 documentation:[string]; 101 /// File that this Object is declared in. 102 declaration_file: string; 103} 104 105table RPCCall { 106 name:string (required, key); 107 request:Object (required); // must be a table (not a struct) 108 response:Object (required); // must be a table (not a struct) 109 attributes:[KeyValue]; 110 documentation:[string]; 111} 112 113table Service { 114 name:string (required, key); 115 calls:[RPCCall]; 116 attributes:[KeyValue]; 117 documentation:[string]; 118 /// File that this Service is declared in. 119 declaration_file: string; 120} 121 122/// New schema language features that are not supported by old code generators. 123enum AdvancedFeatures : ulong (bit_flags) { 124 AdvancedArrayFeatures, 125 AdvancedUnionFeatures, 126 OptionalScalars, 127 DefaultVectorsAndStrings, 128} 129 130/// File specific information. 131/// Symbols declared within a file may be recovered by iterating over all 132/// symbols and examining the `declaration_file` field. 133table SchemaFile { 134 /// Filename, relative to project root. 135 filename:string (required, key); 136 /// Names of included files, relative to project root. 137 included_filenames:[string]; 138} 139 140table Schema { 141 objects:[Object] (required); // Sorted. 142 enums:[Enum] (required); // Sorted. 143 file_ident:string; 144 file_ext:string; 145 root_table:Object; 146 services:[Service]; // Sorted. 147 advanced_features:AdvancedFeatures; 148 /// All the files used in this compilation. Files are relative to where 149 /// flatc was invoked. 150 fbs_files:[SchemaFile]; // Sorted. 151} 152 153root_type Schema; 154 155file_identifier "BFBS"; 156file_extension "bfbs"; 157