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. |
| 40 | fixed_length:uint16 = 0 (id: 3); // Only if base_type == Array. |
Austin Schuh | e89fa2d | 2019-08-14 20:24:23 -0700 | [diff] [blame] | 41 | } |
| 42 | |
| 43 | table KeyValue { |
Austin Schuh | f13042b | 2020-11-25 23:11:41 -0800 | [diff] [blame] | 44 | key:string (required, key, id: 0); |
| 45 | value:string (id: 1); |
Austin Schuh | e89fa2d | 2019-08-14 20:24:23 -0700 | [diff] [blame] | 46 | } |
| 47 | |
| 48 | table EnumVal { |
Austin Schuh | f13042b | 2020-11-25 23:11:41 -0800 | [diff] [blame] | 49 | name:string (required, id: 0); |
| 50 | value:long (key, id: 1); |
| 51 | object:Object (id: 2); // Will be deprecated in favor of union_type in the future. |
| 52 | union_type:Type (id: 3); |
| 53 | documentation:[string] (id: 4); |
Austin Schuh | e89fa2d | 2019-08-14 20:24:23 -0700 | [diff] [blame] | 54 | } |
| 55 | |
| 56 | table Enum { |
Austin Schuh | f13042b | 2020-11-25 23:11:41 -0800 | [diff] [blame] | 57 | name:string (required, key, id: 0); |
| 58 | values:[EnumVal] (required, id: 1); // In order of their values. |
| 59 | is_union:bool = false (id: 2); |
| 60 | underlying_type:Type (required, id: 3); |
| 61 | attributes:[KeyValue] (id: 4); |
| 62 | documentation:[string] (id: 5); |
Austin Schuh | e89fa2d | 2019-08-14 20:24:23 -0700 | [diff] [blame] | 63 | } |
| 64 | |
| 65 | table Field { |
Austin Schuh | f13042b | 2020-11-25 23:11:41 -0800 | [diff] [blame] | 66 | name:string (required, key, id: 0); |
| 67 | type:Type (required, id: 1); |
| 68 | id:ushort (id: 2); |
| 69 | offset:ushort (id: 3); // Offset into the vtable for tables, or into the struct. |
| 70 | default_integer:long = 0 (id: 4); |
| 71 | default_real:double = 0.0 (id: 5); |
| 72 | deprecated:bool = false (id: 6); |
| 73 | required:bool = false (id: 7); |
| 74 | key:bool = false (id: 8); |
| 75 | attributes:[KeyValue] (id: 9); |
| 76 | documentation:[string] (id: 10); |
| 77 | optional:bool = false (id: 11); |
Austin Schuh | e89fa2d | 2019-08-14 20:24:23 -0700 | [diff] [blame] | 78 | } |
| 79 | |
| 80 | table Object { // Used for both tables and structs. |
Austin Schuh | f13042b | 2020-11-25 23:11:41 -0800 | [diff] [blame] | 81 | name:string (required, key, id: 0); |
| 82 | fields:[Field] (required, id: 1); // Sorted. |
| 83 | is_struct:bool = false (id: 2); |
| 84 | minalign:int (id: 3); |
| 85 | bytesize:int (id: 4); // For structs. |
| 86 | attributes:[KeyValue] (id: 5); |
| 87 | documentation:[string] (id: 6); |
Austin Schuh | e89fa2d | 2019-08-14 20:24:23 -0700 | [diff] [blame] | 88 | } |
| 89 | |
| 90 | table RPCCall { |
Austin Schuh | f13042b | 2020-11-25 23:11:41 -0800 | [diff] [blame] | 91 | name:string (required, key, id: 0); |
| 92 | request:Object (required, id: 1); // must be a table (not a struct) |
| 93 | response:Object (required, id: 2); // must be a table (not a struct) |
| 94 | attributes:[KeyValue] (id: 3); |
| 95 | documentation:[string] (id: 4); |
Austin Schuh | e89fa2d | 2019-08-14 20:24:23 -0700 | [diff] [blame] | 96 | } |
| 97 | |
| 98 | table Service { |
Austin Schuh | f13042b | 2020-11-25 23:11:41 -0800 | [diff] [blame] | 99 | name:string (required, key, id: 0); |
| 100 | calls:[RPCCall] (id: 1); |
| 101 | attributes:[KeyValue] (id: 2); |
| 102 | documentation:[string] (id: 3); |
Austin Schuh | e89fa2d | 2019-08-14 20:24:23 -0700 | [diff] [blame] | 103 | } |
| 104 | |
| 105 | table Schema { |
Austin Schuh | f13042b | 2020-11-25 23:11:41 -0800 | [diff] [blame] | 106 | objects:[Object] (required, id: 0); // Sorted. |
| 107 | enums:[Enum] (required, id: 1); // Sorted. |
| 108 | file_ident:string (id: 2); |
| 109 | file_ext:string (id: 3); |
| 110 | root_table:Object (id: 4); |
| 111 | services:[Service] (id: 5); // Sorted. |
Austin Schuh | e89fa2d | 2019-08-14 20:24:23 -0700 | [diff] [blame] | 112 | } |
| 113 | |
| 114 | root_type Schema; |
| 115 | |
| 116 | file_identifier "BFBS"; |
| 117 | file_extension "bfbs"; |