docs: clean up whitespace and fix typo in tutorial.md (#8695)

* docs: remove trailing whitespace

* docs: fix typo in tutorial.md
This commit is contained in:
Daniel Nguyen
2025-09-25 11:02:22 -05:00
committed by GitHub
parent 1872409707
commit 27325e002a
26 changed files with 108 additions and 108 deletions

View File

@@ -165,11 +165,11 @@ serializing and deserializing the flatbuffer binary data.
=== "C"
!!! Note
!!! Note
If you're working in C, you need to use the separate project
[FlatCC](https://github.com/dvidelabs/flatcc) which contains a schema
compiler and runtime library in C for C. See
If you're working in C, you need to use the separate project
[FlatCC](https://github.com/dvidelabs/flatcc) which contains a schema
compiler and runtime library in C for C. See
[flatcc build instructions](https://github.com/dvidelabs/flatcc#building).
Please be aware of the difference between `flatc` and `flatcc` tools.
@@ -291,7 +291,7 @@ generally involves two things:
// Convenient namespace macro to manage long namespace prefix.
#undef ns
// Specified in the schema.
#define ns(x) FLATBUFFERS_WRAP_NAMESPACE(MyGame_Sample, x)
#define ns(x) FLATBUFFERS_WRAP_NAMESPACE(MyGame_Sample, x)
// A helper to simplify creating vectors from C-arrays.
#define c_vec_len(V) (sizeof(V)/sizeof((V)[0]))
@@ -333,14 +333,14 @@ generally involves two things:
=== "JavaScript"
```javascript
// The following code is an example - use your desired module flavor by
// transpiling from TS.
// The following code is an example - use your desired module flavor by
// transpiling from TS.
var flatbuffers = require('/js/flatbuffers').flatbuffers;
var MyGame = require('./monster_generated').MyGame; // Generated by `flatc`.
//------------------------------------------------------------------------//
// The following code is for browser-based HTML/JavaScript. Use the above
// The following code is for browser-based HTML/JavaScript. Use the above
// code for JavaScript module loaders (e.g. Node.js).
<script src="../js/flatbuffers.js"></script>
<script src="monster_generated.js"></script> // Generated by `flatc`.
@@ -384,12 +384,12 @@ generally involves two things:
// The last segment of the class name matches the file name.
$class = substr($class_name, strrpos($class_name, "\\") + 1);
// `flatbuffers` root.
$root_dir = join(DIRECTORY_SEPARATOR, array(dirname(dirname(__FILE__))));
$root_dir = join(DIRECTORY_SEPARATOR, array(dirname(dirname(__FILE__))));
// Contains the `*.php` files for the FlatBuffers library and the `flatc`
// generated files.
$paths = array(join(DIRECTORY_SEPARATOR, array($root_dir, "php")),
join(DIRECTORY_SEPARATOR,
join(DIRECTORY_SEPARATOR,
array($root_dir, "samples", "MyGame", "Sample")));
foreach ($paths as $path) {
$file = join(DIRECTORY_SEPARATOR, array($path, $class . ".php"));
@@ -546,7 +546,7 @@ for it. The builder will automatically resize the backing buffer when necessary.
=== "Lobster"
```lobster
// Construct a Builder with 1024 byte backing array.
// Construct a Builder with 1024 byte backing array.
let builder = flatbuffers_builder {}
```
@@ -630,9 +630,9 @@ Let's serialize two weapon strings.
=== "C"
```c
flatbuffers_string_ref_t weapon_one_name
flatbuffers_string_ref_t weapon_one_name
= flatbuffers_string_create_str(B, "Sword");
flatbuffers_string_ref_t weapon_two_name
flatbuffers_string_ref_t weapon_two_name
= flatbuffers_string_create_str(B, "Axe");
```
@@ -722,7 +722,7 @@ Let's serialize two weapon strings.
=== "TypeScript"
```ts
```ts
let weaponOne = builder.createString('Sword');
let weaponTwo = builder.createString('Axe');
```
@@ -760,9 +760,9 @@ offset to the weapon's name and a numerical value for the damage field.
uint16_t weapon_one_damage = 3;
uint16_t weapon_two_damage = 5;
ns(Weapon_ref_t) sword
ns(Weapon_ref_t) sword
= ns(Weapon_create(B, weapon_one_name, weapon_one_damage));
ns(Weapon_ref_t) axe
ns(Weapon_ref_t) axe
= ns(Weapon_create(B, weapon_two_name, weapon_two_damage));
```
@@ -772,7 +772,7 @@ offset to the weapon's name and a numerical value for the damage field.
short weaponOneDamage = 3;
short weaponTwoDamage = 5;
// Use the `CreateWeapon()` helper function to create the weapons, since we
// Use the `CreateWeapon()` helper function to create the weapons, since we
// set every field.
Offset<Weapon> sword =
Weapon.CreateWeapon(builder, weaponOneName, weaponOneDamage);
@@ -1073,7 +1073,7 @@ The Builder provides multiple ways to create `vectors`.
=== "Java"
```java
// Place the two weapons into an array, and pass it to the
// Place the two weapons into an array, and pass it to the
// `createWeaponsVector()` method to create a FlatBuffer vector.
int[] weaps = new int[2];
weaps[0] = sword;
@@ -1096,7 +1096,7 @@ The Builder provides multiple ways to create `vectors`.
=== "Kotlin"
```kotlin
// Place the two weapons into an array, and pass it to the
// Place the two weapons into an array, and pass it to the
// `createWeaponsVector()` method to create a FlatBuffer vector.
val weaps = intArrayOf(sword, axe)
@@ -1537,7 +1537,7 @@ the necessary values and Offsets to make a `Monster`.
```java
// Serialize a name for our monster, called "Orc".
int name = builder.createString("Orc");
// Create our monster using `startMonster()` and `endMonster()`.
Monster.startMonster(builder);
Monster.addPos(builder, Vec3.createVec3(builder, 1.0f, 2.0f, 3.0f));
@@ -1567,7 +1567,7 @@ the necessary values and Offsets to make a `Monster`.
MyGame.Sample.Monster.addName(builder, name);
MyGame.Sample.Monster.addInventory(builder, inv);
MyGame.Sample.Monster.addWeapons(builder, weapons);
MyGame.Sample.Monster.addEquippedType(builder,
MyGame.Sample.Monster.addEquippedType(builder,
MyGame.Sample.Equipment.Weapon);
MyGame.Sample.Monster.addEquipped(builder, axe);
MyGame.Sample.Monster.addPath(builder, path);
@@ -1649,7 +1649,7 @@ the necessary values and Offsets to make a `Monster`.
\MyGame\Sample\Monster::AddInventory($builder, $inv);
\MyGame\Sample\Monster::AddColor($builder, \MyGame\Sample\Color::Red);
\MyGame\Sample\Monster::AddWeapons($builder, $weapons);
\MyGame\Sample\Monster::AddEquippedType($builder,
\MyGame\Sample\Monster::AddEquippedType($builder,
\MyGame\Sample\Equipment::Weapon);
\MyGame\Sample\Monster::AddEquipped($builder, $axe);
\MyGame\Sample\Monster::AddPath($builder, $path);
@@ -1782,7 +1782,7 @@ deserializing the buffer later.
```dart
// Call `finish()` to instruct the builder that this monster is complete.
// See the next code section, as in Dart `finish` will also return the byte
// See the next code section, as in Dart `finish` will also return the byte
// array.
```
@@ -1982,7 +1982,7 @@ like so:
```php
// This must be called after `finish()`.
$buf = $builder->dataBuffer(); // Of type `Google\FlatBuffers\ByteBuffer`
// The data in this ByteBuffer does NOT start at 0, but at
// The data in this ByteBuffer does NOT start at 0, but at
// buf->getPosition().
// The end of the data is marked by buf->capacity(), so the size is
// buf->capacity() - buf->getPosition().
@@ -2056,7 +2056,7 @@ functions to get the root object given the buffer.
```c++
uint8_t *buffer_pointer = /* the data you just read */;
// Get an view to the root object inside the buffer.
// Get a view to the root object inside the buffer.
Monster monster = GetMonster(buffer_pointer);
```
@@ -2076,7 +2076,7 @@ functions to get the root object given the buffer.
```c#
byte[] bytes = /* the data you just read */
// Get an view to the root object inside the buffer.
// Get a view to the root object inside the buffer.
Monster monster = Monster.GetRootAsMonster(new ByteBuffer(bytes));
```
@@ -2204,7 +2204,7 @@ functions to get the root object given the buffer.
```ts
// the data you just read, as a `Uint8Array`.
// Note that the example here uses `readFileSync` from the built-in `fs`
// Note that the example here uses `readFileSync` from the built-in `fs`
// module, but other methods for accessing the file contents will also work.
let bytes = new Uint8Array(readFileSync('./monsterdata.bin'));
@@ -2656,9 +2656,9 @@ you need to handle the result as a FlatBuffer table. Here we iterate over the
ns(Weapon_vec_t) weapons = ns(Monster_weapons(monster));
size_t weapons_len = ns(Weapon_vec_len(weapons));
// We can use `const char *` instead of `flatbuffers_string_t`.
const char *second_weapon_name =
const char *second_weapon_name =
ns(Weapon_name(ns(Weapon_vec_at(weapons, 1))));
uint16_t second_weapon_damage =
uint16_t second_weapon_damage =
ns(Weapon_damage(ns(Weapon_vec_at(weapons, 1))));
```
@@ -2791,11 +2791,11 @@ only stores a FlatBuffer `table`).
```c++
auto union_type = monster.equipped_type();
if (union_type == Equipment_Weapon) {
// Requires `static_cast` to type `const Weapon*`.
auto weapon = static_cast<const Weapon*>(monster->equipped());
auto weapon_name = weapon->name()->str(); // "Axe"
auto weapon_damage = weapon->damage(); // 5
}
@@ -2807,7 +2807,7 @@ only stores a FlatBuffer `table`).
// Access union type field.
if (ns(Monster_equipped_type(monster)) == ns(Equipment_Weapon)) {
// Cast to appropriate type:
// C allows for silent void pointer assignment, so we need no
// C allows for silent void pointer assignment, so we need no
// explicit cast.
ns(Weapon_table_t) weapon = ns(Monster_equipped(monster));
const char *weapon_name = ns(Weapon_name(weapon)); // "Axe"
@@ -2819,10 +2819,10 @@ only stores a FlatBuffer `table`).
```c#
var unionType = monster.EquippedType;
if (unionType == Equipment.Weapon) {
var weapon = monster.Equipped<Weapon>().Value;
var weaponName = weapon.Name; // "Axe"
var weaponDamage = weapon.Damage; // 5
}
@@ -2852,7 +2852,7 @@ only stores a FlatBuffer `table`).
unionType := monster.EquippedType()
if unionType == sample.EquipmentWeapon {
// Create a `sample.Weapon` object that can be initialized with the
// Create a `sample.Weapon` object that can be initialized with the
// contents of the `flatbuffers.Table` (`unionTable`), which was
// populated by `monster.Equipped()`.
unionWeapon = new(sample.Weapon)
@@ -2887,7 +2887,7 @@ only stores a FlatBuffer `table`).
// 'Axe'
var weaponName = monster.equipped(new MyGame.Sample.Weapon()).name();
// 5
var weaponDamage =
var weaponDamage =
monster.equipped(new MyGame.Sample.Weapon()).damage();
}
```
@@ -2912,8 +2912,8 @@ only stores a FlatBuffer `table`).
union_type = monster.equipped_type
if union_type == MyGame_Sample_Equipment_Weapon:
// `monster.equipped_as_Weapon` returns a FlatBuffer handle much like
// normal table fields, but this is only valid to call if we already
// `monster.equipped_as_Weapon` returns a FlatBuffer handle much like
// normal table fields, but this is only valid to call if we already
// know it is the correct type.
let union_weapon = monster.equipped_as_Weapon
@@ -2945,8 +2945,8 @@ only stores a FlatBuffer `table`).
$weapon_name =
$monster->getEquipped(new \MyGame\Sample\Weapon())->getName();
// 5
$weapon_damage =
$monster->getEquipped(new \MyGame\Sample\Weapon())->getDamage();
$weapon_damage =
$monster->getEquipped(new \MyGame\Sample\Weapon())->getDamage();
}
```
@@ -2996,8 +2996,8 @@ only stores a FlatBuffer `table`).
if (unionType == MyGame.Sample.Equipment.Weapon) {
// 'Axe'
let weaponName = monster.equipped(new MyGame.Sample.Weapon()).name();
// 5
let weaponName = monster.equipped(new MyGame.Sample.Weapon()).name();
// 5
let weaponDamage = monster.equipped(new MyGame.Sample.Weapon()).damage();
}
```