Austin Schuh | e89fa2d | 2019-08-14 20:24:23 -0700 | [diff] [blame] | 1 | // test schema file |
| 2 | |
| 3 | include "include_test1.fbs"; |
| 4 | |
| 5 | namespace MyGame; |
| 6 | |
| 7 | table InParentNamespace {} |
| 8 | |
| 9 | namespace MyGame.Example2; |
| 10 | |
| 11 | table Monster {} // Test having same name as below, but in different namespace. |
| 12 | |
| 13 | namespace MyGame.Example; |
| 14 | |
| 15 | attribute "priority"; |
| 16 | |
| 17 | /// Composite components of Monster color. |
Austin Schuh | 272c613 | 2020-11-14 16:37:52 -0800 | [diff] [blame] | 18 | enum Color:ubyte (bit_flags) { |
Austin Schuh | e89fa2d | 2019-08-14 20:24:23 -0700 | [diff] [blame] | 19 | Red = 0, // color Red = (1u << 0) |
| 20 | /// \brief color Green |
| 21 | /// Green is bit_flag with value (1u << 1) |
Austin Schuh | 272c613 | 2020-11-14 16:37:52 -0800 | [diff] [blame] | 22 | Green, |
Austin Schuh | e89fa2d | 2019-08-14 20:24:23 -0700 | [diff] [blame] | 23 | /// \brief color Blue (1u << 3) |
Austin Schuh | 272c613 | 2020-11-14 16:37:52 -0800 | [diff] [blame] | 24 | Blue = 3, |
| 25 | } |
| 26 | |
| 27 | enum Race:byte { |
| 28 | None = -1, |
| 29 | Human = 0, |
| 30 | Dwarf, |
| 31 | Elf, |
Austin Schuh | e89fa2d | 2019-08-14 20:24:23 -0700 | [diff] [blame] | 32 | } |
| 33 | |
James Kuszmaul | 8e62b02 | 2022-03-22 09:33:25 -0700 | [diff] [blame] | 34 | enum LongEnum:ulong (bit_flags) { |
| 35 | LongOne = 1, |
| 36 | LongTwo = 2, |
| 37 | // Because this is a bitflag, 40 will be out of range of a 32-bit integer, |
| 38 | // allowing us to exercise any logic special to big numbers. |
| 39 | LongBig = 40, |
| 40 | } |
| 41 | |
Austin Schuh | e89fa2d | 2019-08-14 20:24:23 -0700 | [diff] [blame] | 42 | union Any { Monster, TestSimpleTableWithEnum, MyGame.Example2.Monster } |
| 43 | |
| 44 | union AnyUniqueAliases { M: Monster, TS: TestSimpleTableWithEnum, M2: MyGame.Example2.Monster } |
| 45 | union AnyAmbiguousAliases { M1: Monster, M2: Monster, M3: Monster } |
| 46 | |
| 47 | struct Test { a:short; b:byte; } |
| 48 | |
| 49 | table TestSimpleTableWithEnum (csharp_partial, private) { |
| 50 | color: Color = Green; |
| 51 | } |
| 52 | |
| 53 | struct Vec3 (force_align: 8) { |
| 54 | x:float; |
| 55 | y:float; |
| 56 | z:float; |
| 57 | test1:double; |
| 58 | test2:Color; |
| 59 | test3:Test; |
| 60 | } |
| 61 | |
| 62 | struct Ability { |
| 63 | id:uint(key); |
| 64 | distance:uint; |
| 65 | } |
| 66 | |
James Kuszmaul | 8e62b02 | 2022-03-22 09:33:25 -0700 | [diff] [blame] | 67 | struct StructOfStructs { |
| 68 | a: Ability; |
| 69 | b: Test; |
| 70 | c: Ability; |
| 71 | } |
| 72 | |
Austin Schuh | 2dd86a9 | 2022-09-14 21:19:23 -0700 | [diff] [blame] | 73 | struct StructOfStructsOfStructs { |
| 74 | a: StructOfStructs; |
| 75 | } |
| 76 | |
Austin Schuh | e89fa2d | 2019-08-14 20:24:23 -0700 | [diff] [blame] | 77 | table Stat { |
| 78 | id:string; |
| 79 | val:long; |
James Kuszmaul | 8e62b02 | 2022-03-22 09:33:25 -0700 | [diff] [blame] | 80 | count:ushort (key); |
Austin Schuh | e89fa2d | 2019-08-14 20:24:23 -0700 | [diff] [blame] | 81 | } |
| 82 | |
| 83 | table Referrable { |
| 84 | id:ulong(key, hash:"fnv1a_64"); |
| 85 | } |
| 86 | |
Austin Schuh | 272c613 | 2020-11-14 16:37:52 -0800 | [diff] [blame] | 87 | /// an example documentation comment: "monster object" |
Austin Schuh | e89fa2d | 2019-08-14 20:24:23 -0700 | [diff] [blame] | 88 | table Monster { |
| 89 | pos:Vec3 (id: 0); |
| 90 | hp:short = 100 (id: 2); |
| 91 | mana:short = 150 (id: 1); |
James Kuszmaul | 8e62b02 | 2022-03-22 09:33:25 -0700 | [diff] [blame] | 92 | name:string (id: 3, key); |
Austin Schuh | e89fa2d | 2019-08-14 20:24:23 -0700 | [diff] [blame] | 93 | color:Color = Blue (id: 6); |
| 94 | inventory:[ubyte] (id: 5); |
| 95 | friendly:bool = false (deprecated, priority: 1, id: 4); |
| 96 | /// an example documentation comment: this will end up in the generated code |
| 97 | /// multiline too |
| 98 | testarrayoftables:[Monster] (id: 11); |
| 99 | testarrayofstring:[string] (id: 10); |
| 100 | testarrayofstring2:[string] (id: 28); |
| 101 | testarrayofbools:[bool] (id: 24); |
| 102 | testarrayofsortedstruct:[Ability] (id: 29); |
| 103 | enemy:MyGame.Example.Monster (id:12); // Test referring by full namespace. |
| 104 | test:Any (id: 8); |
| 105 | test4:[Test] (id: 9); |
| 106 | test5:[Test] (id: 31); |
| 107 | testnestedflatbuffer:[ubyte] (id:13, nested_flatbuffer: "Monster"); |
| 108 | testempty:Stat (id:14); |
| 109 | testbool:bool (id:15); |
| 110 | testhashs32_fnv1:int (id:16, hash:"fnv1_32"); |
| 111 | testhashu32_fnv1:uint (id:17, hash:"fnv1_32"); |
| 112 | testhashs64_fnv1:long (id:18, hash:"fnv1_64"); |
| 113 | testhashu64_fnv1:ulong (id:19, hash:"fnv1_64"); |
| 114 | testhashs32_fnv1a:int (id:20, hash:"fnv1a_32"); |
| 115 | testhashu32_fnv1a:uint (id:21, hash:"fnv1a_32", cpp_type:"Stat"); |
| 116 | testhashs64_fnv1a:long (id:22, hash:"fnv1a_64"); |
| 117 | testhashu64_fnv1a:ulong (id:23, hash:"fnv1a_64"); |
| 118 | testf:float = 3.14159 (id:25); |
| 119 | testf2:float = 3 (id:26); |
| 120 | testf3:float (id:27); |
| 121 | flex:[ubyte] (id:30, flexbuffer); |
| 122 | vector_of_longs:[long] (id:32); |
| 123 | vector_of_doubles:[double] (id:33); |
| 124 | parent_namespace_test:InParentNamespace (id:34); |
| 125 | vector_of_referrables:[Referrable](id:35); |
| 126 | single_weak_reference:ulong(id:36, hash:"fnv1a_64", cpp_type:"ReferrableT"); |
| 127 | vector_of_weak_references:[ulong](id:37, hash:"fnv1a_64", cpp_type:"ReferrableT"); |
| 128 | vector_of_strong_referrables:[Referrable](id:38, cpp_ptr_type:"default_ptr_type"); //was shared_ptr |
| 129 | co_owning_reference:ulong(id:39, hash:"fnv1a_64", cpp_type:"ReferrableT", cpp_ptr_type:"naked"); //was shared_ptr as well |
| 130 | vector_of_co_owning_references:[ulong](id:40, hash:"fnv1a_64", cpp_type:"ReferrableT", cpp_ptr_type:"default_ptr_type", cpp_ptr_type_get:".get()"); //was shared_ptr |
| 131 | non_owning_reference:ulong(id:41, hash:"fnv1a_64", cpp_type:"ReferrableT", cpp_ptr_type:"naked", cpp_ptr_type_get:""); //was weak_ptr |
| 132 | vector_of_non_owning_references:[ulong](id:42, hash:"fnv1a_64", cpp_type:"ReferrableT", cpp_ptr_type:"naked", cpp_ptr_type_get:""); //was weak_ptr |
| 133 | any_unique:AnyUniqueAliases(id:44); |
| 134 | any_ambiguous:AnyAmbiguousAliases (id:46); |
| 135 | vector_of_enums:[Color] (id:47); |
Austin Schuh | 272c613 | 2020-11-14 16:37:52 -0800 | [diff] [blame] | 136 | signed_enum:Race = None (id:48); |
| 137 | testrequirednestedflatbuffer:[ubyte] (id:49, nested_flatbuffer: "Monster"); |
James Kuszmaul | 8e62b02 | 2022-03-22 09:33:25 -0700 | [diff] [blame] | 138 | scalar_key_sorted_tables:[Stat] (id: 50); |
| 139 | native_inline:Test (id: 51, native_inline); |
| 140 | // The default value of this enum will be a numeric zero, which isn't a valid |
| 141 | // enum value. |
| 142 | long_enum_non_enum_default:LongEnum (id: 52); |
| 143 | long_enum_normal_default:LongEnum = LongOne (id: 53); |
James Kuszmaul | 3b15b0c | 2022-11-08 14:03:16 -0800 | [diff] [blame] | 144 | // Test that default values nan and +/-inf work. |
| 145 | nan_default:float = nan (id: 54); |
| 146 | inf_default:float = inf (id: 55); |
| 147 | positive_inf_default:float = +inf (id: 56); |
| 148 | infinity_default:float = infinity (id: 57); |
| 149 | positive_infinity_default:float = +infinity (id: 58); |
| 150 | negative_inf_default:float = -inf (id: 59); |
| 151 | negative_infinity_default:float = -infinity (id: 60); |
| 152 | double_inf_default:double = inf (id: 61); |
Austin Schuh | e89fa2d | 2019-08-14 20:24:23 -0700 | [diff] [blame] | 153 | } |
| 154 | |
| 155 | table TypeAliases { |
| 156 | i8:int8; |
| 157 | u8:uint8; |
| 158 | i16:int16; |
| 159 | u16:uint16; |
| 160 | i32:int32; |
| 161 | u32:uint32; |
| 162 | i64:int64; |
| 163 | u64:uint64; |
| 164 | f32:float32; |
| 165 | f64:float64; |
| 166 | v8:[int8]; |
| 167 | vf64:[float64]; |
| 168 | } |
| 169 | |
| 170 | rpc_service MonsterStorage { |
| 171 | Store(Monster):Stat (streaming: "none"); |
| 172 | Retrieve(Stat):Monster (streaming: "server", idempotent); |
| 173 | GetMaxHitPoint(Monster):Stat (streaming: "client"); |
| 174 | GetMinMaxHitPoints(Monster):Stat (streaming: "bidi"); |
| 175 | } |
| 176 | |
| 177 | root_type Monster; |
| 178 | |
| 179 | file_identifier "MONS"; |
| 180 | file_extension "mon"; |