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