From 81312c21281430449aef20f7a71ad9e0962791d3 Mon Sep 17 00:00:00 2001 From: Wouter van Oortmerssen Date: Thu, 21 May 2015 16:33:29 -0700 Subject: Initial reflection and resizing functionality. Tested: on Linux. Change-Id: I8f7bccf9b1ad87fea788f85e23fa69435758feca --- reflection/generate_code.sh | 1 + reflection/reflection.fbs | 79 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 80 insertions(+) create mode 100644 reflection/generate_code.sh create mode 100644 reflection/reflection.fbs (limited to 'reflection') diff --git a/reflection/generate_code.sh b/reflection/generate_code.sh new file mode 100644 index 00000000..90f655d2 --- /dev/null +++ b/reflection/generate_code.sh @@ -0,0 +1 @@ +../flatc -c --no-prefix -o ../include/flatbuffers reflection.fbs diff --git a/reflection/reflection.fbs b/reflection/reflection.fbs new file mode 100644 index 00000000..b2a262a3 --- /dev/null +++ b/reflection/reflection.fbs @@ -0,0 +1,79 @@ +// This schema defines objects that represent a parsed schema, like +// the binary version of a .fbs file. +// This could be used to operate on unknown FlatBuffers at runtime. +// It can even ... represent itself (!) + +namespace reflection; + +// These must correspond to the enum in idl.h. +enum BaseType : byte { + None, + UType, + Bool, + Byte, + UByte, + Short, + UShort, + Int, + UInt, + Long, + ULong, + Float, + Double, + String, + Vector, + Obj, // Used for tables & structs. + Union // +} + +table Type { + base_type:BaseType; + element:BaseType = None; // Only if base_type == Vector. + index:int = -1; // If base_type == Object, index into "objects" below. + // If base_type == Union, UnionType, or integral derived + // from an enum, index into "enums" below. +} + +table EnumVal { + name:string (required); + value:long (key); + object:Object; // Only if part of a union. +} + +table Enum { + name:string (required, key); + values:[EnumVal] (required); // In order of their values. + is_union:bool = false; + underlying_type:Type (required); +} + +table Field { + name:string (required, key); + type:Type (required); + id:ushort; + offset:ushort; // Offset into the vtable for tables, or into the struct. + default_integer:long = 0; + default_real:double = 0.0; + deprecated:bool = false; + required:bool = false; + key:bool = false; +} + +table Object { // Used for both tables and structs. + name:string (required, key); + fields:[Field] (required); // Sorted. + is_struct:bool = false; +} + +table Schema { + objects:[Object] (required); // Sorted. + enums:[Enum] (required); // Sorted. + file_ident:string; + file_ext:string; + root_table:Object; +} + +root_type Schema; + +file_identifier "BFBS"; +file_extension "bfbs"; -- cgit v1.2.3