• 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}
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;  // Will be deprecated in favor of union_type in the future.
46    union_type:Type;
47}
48
49table Enum {
50    name:string (required, key);
51    values:[EnumVal] (required);  // In order of their values.
52    is_union:bool = false;
53    underlying_type:Type (required);
54    attributes:[KeyValue];
55    documentation:[string];
56}
57
58table Field {
59    name:string (required, key);
60    type:Type (required);
61    id:ushort;
62    offset:ushort;  // Offset into the vtable for tables, or into the struct.
63    default_integer:long = 0;
64    default_real:double = 0.0;
65    deprecated:bool = false;
66    required:bool = false;
67    key:bool = false;
68    attributes:[KeyValue];
69    documentation:[string];
70}
71
72table Object {  // Used for both tables and structs.
73    name:string (required, key);
74    fields:[Field] (required);  // Sorted.
75    is_struct:bool = false;
76    minalign:int;
77    bytesize:int;  // For structs.
78    attributes:[KeyValue];
79    documentation:[string];
80}
81
82table Schema {
83    objects:[Object] (required);  // Sorted.
84    enums:[Enum] (required);      // Sorted.
85    file_ident:string;
86    file_ext:string;
87    root_table:Object;
88}
89
90root_type Schema;
91
92file_identifier "BFBS";
93file_extension "bfbs";
94