blob: 61d2f0c90691b38d2ac37d1e39cd4b25c1f89582 [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.
40 fixed_length:uint16 = 0 (id: 3); // Only if base_type == Array.
Austin Schuhe89fa2d2019-08-14 20:24:23 -070041}
42
43table KeyValue {
Austin Schuhf13042b2020-11-25 23:11:41 -080044 key:string (required, key, id: 0);
45 value:string (id: 1);
Austin Schuhe89fa2d2019-08-14 20:24:23 -070046}
47
48table EnumVal {
Austin Schuhf13042b2020-11-25 23:11:41 -080049 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 Schuhe89fa2d2019-08-14 20:24:23 -070054}
55
56table Enum {
Austin Schuhf13042b2020-11-25 23:11:41 -080057 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 Schuhe89fa2d2019-08-14 20:24:23 -070063}
64
65table Field {
Austin Schuhf13042b2020-11-25 23:11:41 -080066 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 Schuhe89fa2d2019-08-14 20:24:23 -070078}
79
80table Object { // Used for both tables and structs.
Austin Schuhf13042b2020-11-25 23:11:41 -080081 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 Schuhe89fa2d2019-08-14 20:24:23 -070088}
89
90table RPCCall {
Austin Schuhf13042b2020-11-25 23:11:41 -080091 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 Schuhe89fa2d2019-08-14 20:24:23 -070096}
97
98table Service {
Austin Schuhf13042b2020-11-25 23:11:41 -080099 name:string (required, key, id: 0);
100 calls:[RPCCall] (id: 1);
101 attributes:[KeyValue] (id: 2);
102 documentation:[string] (id: 3);
Austin Schuhe89fa2d2019-08-14 20:24:23 -0700103}
104
105table Schema {
Austin Schuhf13042b2020-11-25 23:11:41 -0800106 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 Schuhe89fa2d2019-08-14 20:24:23 -0700112}
113
114root_type Schema;
115
116file_identifier "BFBS";
117file_extension "bfbs";