• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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    Array,
28
29    // Add any new type above this value.
30    MaxBaseType
31}
32
33table Type {
34    base_type:BaseType;
35    element:BaseType = None;  // Only if base_type == Vector
36                              // 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.
41}
42
43table KeyValue {
44    key:string (required, key);
45    value:string;
46}
47
48table EnumVal {
49    name:string (required);
50    value:long (key);
51    object:Object;  // Will be deprecated in favor of union_type in the future.
52    union_type:Type;
53    documentation:[string];
54}
55
56table Enum {
57    name:string (required, key);
58    values:[EnumVal] (required);  // In order of their values.
59    is_union:bool = false;
60    underlying_type:Type (required);
61    attributes:[KeyValue];
62    documentation:[string];
63}
64
65table Field {
66    name:string (required, key);
67    type:Type (required);
68    id:ushort;
69    offset:ushort;  // Offset into the vtable for tables, or into the struct.
70    default_integer:long = 0;
71    default_real:double = 0.0;
72    deprecated:bool = false;
73    required:bool = false;
74    key:bool = false;
75    attributes:[KeyValue];
76    documentation:[string];
77    optional:bool = false;
78}
79
80table Object {  // Used for both tables and structs.
81    name:string (required, key);
82    fields:[Field] (required);  // Sorted.
83    is_struct:bool = false;
84    minalign:int;
85    bytesize:int;  // For structs.
86    attributes:[KeyValue];
87    documentation:[string];
88}
89
90table RPCCall {
91    name:string (required, key);
92    request:Object (required);      // must be a table (not a struct)
93    response:Object (required);     // must be a table (not a struct)
94    attributes:[KeyValue];
95    documentation:[string];
96}
97
98table Service {
99    name:string (required, key);
100    calls:[RPCCall];
101    attributes:[KeyValue];
102    documentation:[string];
103}
104
105// New schema language features that are not supported by old code generators.
106enum AdvancedFeatures : ulong (bit_flags) {
107    AdvancedArrayFeatures,
108    AdvancedUnionFeatures,
109    OptionalScalars,
110    DefaultVectorsAndStrings,
111}
112
113table Schema {
114    objects:[Object] (required);    // Sorted.
115    enums:[Enum] (required);        // Sorted.
116    file_ident:string;
117    file_ext:string;
118    root_table:Object;
119    services:[Service];             // Sorted.
120    advanced_features:AdvancedFeatures;
121}
122
123root_type Schema;
124
125file_identifier "BFBS";
126file_extension "bfbs";
127