• Home
  • Raw
  • Download

Lines Matching +full:json +full:- +full:schema +full:- +full:traverse

14 This page assumes you have written a FlatBuffers schema and compiled it
15 with the Schema Compiler. If you have not, please see
16 [Using the schema compiler](@ref flatbuffers_guide_using_schema_compiler)
17 and [Writing a schema](@ref flatbuffers_guide_writing_schema).
19 Assuming you wrote a schema, say `mygame.fbs` (though the extension doesn't
21 compiler (e.g. `flatc -c mygame.fbs`), you can now start using this in
46 *Note: See [Tutorial](@ref flatbuffers_guide_tutorial) for a more in-depth
52 schema with the `--cpp` option to `flatc`. Then you can include both FlatBuffers
84 std::cout << "hp : " << monster->hp() << std::endl; // '80'
85 std::cout << "mana : " << monster->mana() << std::endl; // default value of '150'
86 std::cout << "name : " << monster->name()->c_str() << std::endl; // "MyMonster"
93 - `shared` (on a field): For string fields, this enables the usage of string
103 (requiring pre-order construction of all data, and making mutation harder).
106 can be used (through `--gen-object-api`) that is able to unpack & pack a
117 GetMonster(flatbuffer)->UnPackTo(&monsterobj);
128 The following attributes are specific to the object-based API code generation:
130 - `native_inline` (on a field): Because FlatBuffer tables and structs are
136 - `native_default("value")` (on a field): For members that are declared
140 - `native_custom_alloc("custom_allocator")` (on a table or struct): When using the
141 object-based API all generated NativeTables that are allocated when unpacking
145 unpacking when using the object-based API.
149 schema:
184 - `native_type("type")` (on a struct): In some cases, a more optimal C++ data
185 type exists for a given struct. For example, the following schema:
194 generates the following Object-Based API class:
203 However, it can be useful to instead use a user-defined C++ type since it
210 vector2 operator-(vector2 rhs) const { ... }
219 the Object-Based API.
231 - `native_type_pack_name("name")` (on a struct when `native_type` is
246 Finally, the following top-level attributes:
248 - `native_include("path")` (at file level): Because the `native_type` attribute
254 - `force_align`: this attribute may not be respected in the object API,
265 [schema](@ref flatbuffers_guide_writing_schema) documentation). Then you have
270 Then, in JSON or however you create these buffers, make sure they use the
279 influence this either globally (using the `--cpp-ptr-type` argument to
284 pointer type specified by the `--cpp-ptr-type` argument to `flatc` from a
290 influence this either globally (using the `--cpp-str-type` argument to
297 string type. This behavior impedes efficient and zero-copy construction of
298 custom string types; the `--cpp-str-flex-ctor` argument to `flatc` or the
310 even allows you to change sizes of strings and vectors in-place.
312 The way this works is very elegant; there is actually a FlatBuffer schema that
315 FlatBuffer, corresponding to this meta-schema.
317 Loading in one of these binary schemas at runtime allows you traverse any
323 schema, as well as a lot of helper functions.
331 generated code, which doesn't do any (binary) schema access at all. It was designed
332 to keep the overhead of reflection as low as possible (on the order of 2-6
334 information the (binary) schema contains.
336 You add this information to your generated code by specifying `--reflect-types`
337 (or instead `--reflect-names` if you also want field / enum names).
344 string produced is very similar to the JSON produced by the `Parser` based
360 - Designate one of the fields in a table as they "key" field. You do this
364 - Write out tables of this type as usual, collect their offsets in an
366 - Instead of `CreateVector`, call `CreateVectorOfSortedTables`,
369 - Now when you're accessing the FlatBuffer, you can use `Vector::LookupByKey`
371 `myvector->LookupByKey("Fred")`, which returns a pointer to the
392 To compute offsets to sub-elements of a struct, make sure they
406 very quick. These offsets are not verified at run-time, so a malformed
444 ## Text & schema parsing
451 Another reason might be that you already have a lot of data in JSON
452 format, or a tool that generates JSON, and if you can write a schema for
455 (see the schema documentation for some specifics on the JSON format
458 Schema evolution compatibility for the JSON format follows the same rules as the binary format (JSO…
469 flatc -b myschema.fbs mydata.json
486 Load text (either a schema or json) into an in-memory buffer (there is a
500 This works similarly to how the command-line compiler works: a sequence
503 load a schema file (which populates `Parser` with definitions), followed
504 by one or more JSON files.
506 As optional argument to `Parse`, you may specify a null-terminated list of
514 After each JSON file, the `Parser::fbb` member variable is the
523 and is entirely read-only (all const), so is safe to access from multiple
545 (`flatc` will refuse to compile a schema that uses these features).
552 ## Depth limit of nested objects and stack-overflow control
553 The parser of Flatbuffers schema or json-files is kind of recursive parser.
554 To avoid stack-overflow problem the parser has a built-in limiter of
555 recursion depth. Number of nested declarations in a schema or number of
556 nested json-objects is limited. By default, this depth limit set to `64`.
560 CMake-based projects.
562 ## Dependence from C-locale {#flatbuffers_locale_cpp}
567 depend from C-locale: `strtod()` or `strtof()`, for example.
571 and may lead to an error while parsing a Flatbuffers schema or a json file.
575 locale-independent or locale-narrow functions `strtof_l`, `strtod_l`,
577 These functions use specified locale rather than the global or per-thread
578 locale instead. They are part of POSIX-2008 but not part of the C/C++
582 - CMake `"CMakeLists.txt"`:
583 - Check existence of `strtol_l` and `strtod_l` in the `<stdlib.h>`.
584 - Compile-time `"/include/base.h"`:
585 - `_MSC_VER >= 1900`: MSVC2012 or higher if build with MSVC.
586 - `_XOPEN_SOURCE>=700`: POSIX-2008 if build with GCC/Clang.
590 To override or stop this detection use CMake `-DFLATBUFFERS_LOCALE_INDEPENDENT={0|1}`
600 ## Support of floating-point numbers
602 compatible with the `IEEE-754` floating-point standard.
603 The schema and json parser may fail if `fast-math` or `/fp:fast` mode is active.
605 ### Support of hexadecimal and special floating-point numbers
606 According to the [grammar](@ref flatbuffers_grammar) `fbs` and `json` files
607 may use hexadecimal and special (`NaN`, `Inf`) floating-point literals.
608 The Flatbuffers uses `strtof` and `strtod` functions to parse floating-point
612 The support of floating-point literals will be limited at compile time
616 ### Comparison of floating-point NaN values
617 The floating-point `NaN` (`not a number`) is special value which
621 The `IEEE-754` defines two kind of `NaNs`:
622 - Quiet NaNs, or `qNaNs`.
623 - Signaling NaNs, or `sNaNs`.
625 According to the `IEEE-754`, a comparison with `NaN` always returns
629 in the serialized data but are generated in code (see [Writing a schema](@ref flatbuffers_guide_wri…
631 If a schema has a lot of `NaN` defaults the Flatbuffers can override
632 the unordered comparison by the ordered: `(NaN==NaN)->true`.
636 if GCC or Clang used. These compilers have a compile-time implementation