blob: 51e5b63f940b530ac7d077b75627e874e120fd21 [file] [log] [blame]
Austin Schuhe89fa2d2019-08-14 20:24:23 -07001// 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,
Austin Schuh272c6132020-11-14 16:37:52 -080027 Array,
28
29 // Add any new type above this value.
30 MaxBaseType
Austin Schuhe89fa2d2019-08-14 20:24:23 -070031}
32
33table Type {
Austin Schuhf13042b2020-11-25 23:11:41 -080034 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 Schuha1d006e2022-09-14 21:50:42 -070040 // If base_type == Vector && element == Union or UnionType.
Austin Schuhf13042b2020-11-25 23:11:41 -080041 fixed_length:uint16 = 0 (id: 3); // Only if base_type == Array.
James Kuszmauldac091f2022-03-22 09:35:06 -070042 /// 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 Schuhe89fa2d2019-08-14 20:24:23 -070046}
47
48table KeyValue {
Austin Schuhf13042b2020-11-25 23:11:41 -080049 key:string (required, key, id: 0);
50 value:string (id: 1);
Austin Schuhe89fa2d2019-08-14 20:24:23 -070051}
52
53table EnumVal {
James Kuszmauldac091f2022-03-22 09:35:06 -070054 name:string (id: 0, required);
55 value:long (id: 1, key);
56 object:Object (id: 2, deprecated);
Austin Schuhf13042b2020-11-25 23:11:41 -080057 union_type:Type (id: 3);
58 documentation:[string] (id: 4);
Austin Schuhe89fa2d2019-08-14 20:24:23 -070059}
60
61table Enum {
James Kuszmauldac091f2022-03-22 09:35:06 -070062 name:string (id: 0, required, key);
63 values:[EnumVal] (id: 1, required); // In order of their values.
Austin Schuhf13042b2020-11-25 23:11:41 -080064 is_union:bool = false (id: 2);
James Kuszmauldac091f2022-03-22 09:35:06 -070065 underlying_type:Type (id: 3, required);
Austin Schuhf13042b2020-11-25 23:11:41 -080066 attributes:[KeyValue] (id: 4);
67 documentation:[string] (id: 5);
James Kuszmauldac091f2022-03-22 09:35:06 -070068 /// File that this Enum is declared in.
69 declaration_file: string (id: 6);
Austin Schuhe89fa2d2019-08-14 20:24:23 -070070}
71
72table Field {
James Kuszmauldac091f2022-03-22 09:35:06 -070073 name:string (id: 0, required, key);
74 type:Type (id: 1, required);
Austin Schuhf13042b2020-11-25 23:11:41 -080075 id:ushort (id: 2);
76 offset:ushort (id: 3); // Offset into the vtable for tables, or into the struct.
77 default_integer:long = 0 (id: 4);
78 default_real:double = 0.0 (id: 5);
79 deprecated:bool = false (id: 6);
80 required:bool = false (id: 7);
81 key:bool = false (id: 8);
82 attributes:[KeyValue] (id: 9);
83 documentation:[string] (id: 10);
84 optional:bool = false (id: 11);
James Kuszmauldac091f2022-03-22 09:35:06 -070085 /// Number of padding octets to always add after this field. Structs only.
86 padding:uint16 = 0 (id: 12);
Austin Schuhe89fa2d2019-08-14 20:24:23 -070087}
88
89table Object { // Used for both tables and structs.
James Kuszmauldac091f2022-03-22 09:35:06 -070090 name:string (id: 0, required, key);
91 fields:[Field] (id: 1, required); // Sorted.
Austin Schuhf13042b2020-11-25 23:11:41 -080092 is_struct:bool = false (id: 2);
93 minalign:int (id: 3);
94 bytesize:int (id: 4); // For structs.
95 attributes:[KeyValue] (id: 5);
96 documentation:[string] (id: 6);
James Kuszmauldac091f2022-03-22 09:35:06 -070097 /// File that this Object is declared in.
98 declaration_file: string (id: 7);
Austin Schuhe89fa2d2019-08-14 20:24:23 -070099}
100
101table RPCCall {
Austin Schuhf13042b2020-11-25 23:11:41 -0800102 name:string (required, key, id: 0);
103 request:Object (required, id: 1); // must be a table (not a struct)
104 response:Object (required, id: 2); // must be a table (not a struct)
105 attributes:[KeyValue] (id: 3);
106 documentation:[string] (id: 4);
Austin Schuhe89fa2d2019-08-14 20:24:23 -0700107}
108
109table Service {
James Kuszmauldac091f2022-03-22 09:35:06 -0700110 name:string (id: 0, required, key);
Austin Schuhf13042b2020-11-25 23:11:41 -0800111 calls:[RPCCall] (id: 1);
112 attributes:[KeyValue] (id: 2);
113 documentation:[string] (id: 3);
James Kuszmauldac091f2022-03-22 09:35:06 -0700114 /// File that this Service is declared in.
115 declaration_file: string (id: 4);
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 (id: 0, required, key);
132 /// Names of included files, relative to project root.
133 included_filenames:[string] (id: 1);
Austin Schuhe89fa2d2019-08-14 20:24:23 -0700134}
135
136table Schema {
James Kuszmauldac091f2022-03-22 09:35:06 -0700137 objects:[Object] (id: 0, required); // Sorted.
138 enums:[Enum] (id: 1, required); // Sorted.
Austin Schuhf13042b2020-11-25 23:11:41 -0800139 file_ident:string (id: 2);
140 file_ext:string (id: 3);
141 root_table:Object (id: 4);
142 services:[Service] (id: 5); // Sorted.
James Kuszmauldac091f2022-03-22 09:35:06 -0700143 advanced_features:AdvancedFeatures (id: 6);
144 /// All the files used in this compilation. Files are relative to where
145 /// flatc was invoked.
146 fbs_files:[SchemaFile] (id: 7); // Sorted.
Austin Schuhe89fa2d2019-08-14 20:24:23 -0700147}
148
149root_type Schema;
150
151file_identifier "BFBS";
152file_extension "bfbs";