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