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
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
27}
28
29table Type {
30    base_type:BaseType;
31    element:BaseType = None;  // Only if base_type == Vector.
32    index:int = -1;  // If base_type == Object, index into "objects" below.
33                     // If base_type == Union, UnionType, or integral derived
34                     // from an enum, index into "enums" below.
35}
36
37table KeyValue {
38    key:string (required, key);
39    value:string;
40}
41
42table EnumVal {
43    name:string (required);
44    value:long (key);
45    object:Object;  // Only if part of a union.
46}
47
48table Enum {
49    name:string (required, key);
50    values:[EnumVal] (required);  // In order of their values.
51    is_union:bool = false;
52    underlying_type:Type (required);
53    attributes:[KeyValue];
54    documentation:[string];
55}
56
57table Field {
58    name:string (required, key);
59    type:Type (required);
60    id:ushort;
61    offset:ushort;  // Offset into the vtable for tables, or into the struct.
62    default_integer:long = 0;
63    default_real:double = 0.0;
64    deprecated:bool = false;
65    required:bool = false;
66    key:bool = false;
67    attributes:[KeyValue];
68    documentation:[string];
69}
70
71table Object {  // Used for both tables and structs.
72    name:string (required, key);
73    fields:[Field] (required);  // Sorted.
74    is_struct:bool = false;
75    minalign:int;
76    bytesize:int;  // For structs.
77    attributes:[KeyValue];
78    documentation:[string];
79}
80
81table Schema {
82    objects:[Object] (required);  // Sorted.
83    enums:[Enum] (required);      // Sorted.
84    file_ident:string;
85    file_ext:string;
86    root_table:Object;
87}
88
89root_type Schema;
90
91file_identifier "BFBS";
92file_extension "bfbs";
93