blob: c3665ebdc00eaee201a3555c96bf92752b895203 [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 {
34 base_type:BaseType;
Austin Schuh272c6132020-11-14 16:37:52 -080035 element:BaseType = None; // Only if base_type == Vector
Austin Schuhe89fa2d2019-08-14 20:24:23 -070036 // 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 fixed_length:uint16 = 0; // Only if base_type == Array.
James Kuszmaul8e62b022022-03-22 09:33:25 -070041 /// The size (octets) of the `base_type` field.
42 base_size:uint = 4; // 4 Is a common size due to offsets being that size.
43 /// The size (octets) of the `element` field, if present.
44 element_size:uint = 0;
Austin Schuhe89fa2d2019-08-14 20:24:23 -070045}
46
47table KeyValue {
48 key:string (required, key);
49 value:string;
50}
51
52table EnumVal {
53 name:string (required);
54 value:long (key);
James Kuszmaul8e62b022022-03-22 09:33:25 -070055 object:Object (deprecated);
Austin Schuhe89fa2d2019-08-14 20:24:23 -070056 union_type:Type;
57 documentation:[string];
58}
59
60table Enum {
61 name:string (required, key);
62 values:[EnumVal] (required); // In order of their values.
63 is_union:bool = false;
64 underlying_type:Type (required);
65 attributes:[KeyValue];
66 documentation:[string];
James Kuszmaul8e62b022022-03-22 09:33:25 -070067 /// File that this Enum is declared in.
68 declaration_file: string;
Austin Schuhe89fa2d2019-08-14 20:24:23 -070069}
70
71table Field {
72 name:string (required, key);
73 type:Type (required);
74 id:ushort;
75 offset:ushort; // Offset into the vtable for tables, or into the struct.
76 default_integer:long = 0;
77 default_real:double = 0.0;
78 deprecated:bool = false;
79 required:bool = false;
80 key:bool = false;
81 attributes:[KeyValue];
82 documentation:[string];
Austin Schuh272c6132020-11-14 16:37:52 -080083 optional:bool = false;
James Kuszmaul8e62b022022-03-22 09:33:25 -070084 /// Number of padding octets to always add after this field. Structs only.
85 padding:uint16 = 0;
Austin Schuhe89fa2d2019-08-14 20:24:23 -070086}
87
88table Object { // Used for both tables and structs.
89 name:string (required, key);
90 fields:[Field] (required); // Sorted.
91 is_struct:bool = false;
92 minalign:int;
93 bytesize:int; // For structs.
94 attributes:[KeyValue];
95 documentation:[string];
James Kuszmaul8e62b022022-03-22 09:33:25 -070096 /// File that this Object is declared in.
97 declaration_file: string;
Austin Schuhe89fa2d2019-08-14 20:24:23 -070098}
99
100table RPCCall {
101 name:string (required, key);
102 request:Object (required); // must be a table (not a struct)
103 response:Object (required); // must be a table (not a struct)
104 attributes:[KeyValue];
105 documentation:[string];
106}
107
108table Service {
109 name:string (required, key);
110 calls:[RPCCall];
111 attributes:[KeyValue];
112 documentation:[string];
James Kuszmaul8e62b022022-03-22 09:33:25 -0700113 /// File that this Service is declared in.
114 declaration_file: string;
115}
116
117/// New schema language features that are not supported by old code generators.
118enum AdvancedFeatures : ulong (bit_flags) {
119 AdvancedArrayFeatures,
120 AdvancedUnionFeatures,
121 OptionalScalars,
122 DefaultVectorsAndStrings,
123}
124
125/// File specific information.
126/// Symbols declared within a file may be recovered by iterating over all
127/// symbols and examining the `declaration_file` field.
128table SchemaFile {
129 /// Filename, relative to project root.
130 filename:string (required, key);
131 /// Names of included files, relative to project root.
132 included_filenames:[string];
Austin Schuhe89fa2d2019-08-14 20:24:23 -0700133}
134
135table Schema {
136 objects:[Object] (required); // Sorted.
137 enums:[Enum] (required); // Sorted.
138 file_ident:string;
139 file_ext:string;
140 root_table:Object;
141 services:[Service]; // Sorted.
James Kuszmaul8e62b022022-03-22 09:33:25 -0700142 advanced_features:AdvancedFeatures;
143 /// All the files used in this compilation. Files are relative to where
144 /// flatc was invoked.
145 fbs_files:[SchemaFile]; // Sorted.
Austin Schuhe89fa2d2019-08-14 20:24:23 -0700146}
147
148root_type Schema;
149
150file_identifier "BFBS";
151file_extension "bfbs";