summaryrefslogtreecommitdiff
path: root/docs/source
diff options
context:
space:
mode:
authorRichard A Hofer <rofer@google.com>2021-01-28 15:35:37 -0500
committerGitHub <noreply@github.com>2021-01-28 12:35:37 -0800
commit13d9e35858fe8c96f7244bf0e4b66af2b24b59f3 (patch)
tree55075d6b8bd9f20d89ce3eaeb9a7a84814b33f60 /docs/source
parent6effe431bbdef0580b6552a3246f7ec6b3751a2c (diff)
downloadflatbuffers-13d9e35858fe8c96f7244bf0e4b66af2b24b59f3.tar.gz
flatbuffers-13d9e35858fe8c96f7244bf0e4b66af2b24b59f3.tar.bz2
flatbuffers-13d9e35858fe8c96f7244bf0e4b66af2b24b59f3.zip
Better python generated code naming (#6336)
* Remove a lot of redundancy from the Python generated code. Update tutorial to reflect new Python generated code. * Add aliases for newly deprecated Python generated methods. This should help with backwards compatibility. * Fix incorrect names in deprecated comments.
Diffstat (limited to 'docs/source')
-rw-r--r--docs/source/Tutorial.md52
1 files changed, 26 insertions, 26 deletions
diff --git a/docs/source/Tutorial.md b/docs/source/Tutorial.md
index 0d531a3f..9c842cc4 100644
--- a/docs/source/Tutorial.md
+++ b/docs/source/Tutorial.md
@@ -741,16 +741,16 @@ our `orc` Monster, let's create some `Weapon`s: a `Sword` and an `Axe`.
weapon_two = builder.CreateString('Axe')
# Create the first `Weapon` ('Sword').
- MyGame.Sample.Weapon.WeaponStart(builder)
- MyGame.Sample.Weapon.WeaponAddName(builder, weapon_one)
- MyGame.Sample.Weapon.WeaponAddDamage(builder, 3)
- sword = MyGame.Sample.Weapon.WeaponEnd(builder)
+ MyGame.Sample.Weapon.Start(builder)
+ MyGame.Sample.Weapon.AddName(builder, weapon_one)
+ MyGame.Sample.Weapon.AddDamage(builder, 3)
+ sword = MyGame.Sample.Weapon.End(builder)
# Create the second `Weapon` ('Axe').
- MyGame.Sample.Weapon.WeaponStart(builder)
- MyGame.Sample.Weapon.WeaponAddName(builder, weapon_two)
- MyGame.Sample.Weapon.WeaponAddDamage(builder, 5)
- axe = MyGame.Sample.Weapon.WeaponEnd(builder)
+ MyGame.Sample.Weapon.Start(builder)
+ MyGame.Sample.Weapon.AddName(builder, weapon_two)
+ MyGame.Sample.Weapon.AddDamage(builder, 5)
+ axe = MyGame.Sample.Weapon.End(builder)
~~~
</div>
<div class="language-javascript">
@@ -1014,7 +1014,7 @@ traversal. This is generally easy to do on any tree structures.
# Create a `vector` representing the inventory of the Orc. Each number
# could correspond to an item that can be claimed after he is slain.
# Note: Since we prepend the bytes, this loop iterates in reverse.
- MyGame.Sample.Monster.MonsterStartInventoryVector(builder, 10)
+ MyGame.Sample.Monster.StartInventoryVector(builder, 10)
for i in reversed(range(0, 10)):
builder.PrependByte(i)
inv = builder.EndVector()
@@ -1204,7 +1204,7 @@ offsets.
~~~{.py}
# Create a FlatBuffer vector and prepend the weapons.
# Note: Since we prepend the data, prepend them in reverse order.
- MyGame.Sample.Monster.MonsterStartWeaponsVector(builder, 2)
+ MyGame.Sample.Monster.StartWeaponsVector(builder, 2)
builder.PrependUOffsetTRelative(axe)
builder.PrependUOffsetTRelative(sword)
weapons = builder.EndVector()
@@ -1333,7 +1333,7 @@ for the `path` field above:
</div>
<div class="language-python">
~~~{.py}
- MyGame.Sample.Monster.MonsterStartPathVector(builder, 2)
+ MyGame.Sample.Monster.StartPathVector(builder, 2)
MyGame.Sample.Vec3.CreateVec3(builder, 1.0, 2.0, 3.0)
MyGame.Sample.Vec3.CreateVec3(builder, 4.0, 5.0, 6.0)
path = builder.EndVector()
@@ -1524,21 +1524,21 @@ can serialize the monster itself:
</div>
<div class="language-python">
~~~{.py}
- # Create our monster by using `MonsterStart()` and `MonsterEnd()`.
- MyGame.Sample.Monster.MonsterStart(builder)
- MyGame.Sample.Monster.MonsterAddPos(builder,
+ # Create our monster by using `Monster.Start()` and `Monster.End()`.
+ MyGame.Sample.Monster.Start(builder)
+ MyGame.Sample.Monster.AddPos(builder,
MyGame.Sample.Vec3.CreateVec3(builder, 1.0, 2.0, 3.0))
- MyGame.Sample.Monster.MonsterAddHp(builder, 300)
- MyGame.Sample.Monster.MonsterAddName(builder, name)
- MyGame.Sample.Monster.MonsterAddInventory(builder, inv)
- MyGame.Sample.Monster.MonsterAddColor(builder,
+ MyGame.Sample.Monster.AddHp(builder, 300)
+ MyGame.Sample.Monster.AddName(builder, name)
+ MyGame.Sample.Monster.AddInventory(builder, inv)
+ MyGame.Sample.Monster.AddColor(builder,
MyGame.Sample.Color.Color().Red)
- MyGame.Sample.Monster.MonsterAddWeapons(builder, weapons)
- MyGame.Sample.Monster.MonsterAddEquippedType(
+ MyGame.Sample.Monster.AddWeapons(builder, weapons)
+ MyGame.Sample.Monster.AddEquippedType(
builder, MyGame.Sample.Equipment.Equipment().Weapon)
- MyGame.Sample.Monster.MonsterAddEquipped(builder, axe)
- MyGame.Sample.Monster.MonsterAddPath(builder, path)
- orc = MyGame.Sample.Monster.MonsterEnd(builder)
+ MyGame.Sample.Monster.AddEquipped(builder, axe)
+ MyGame.Sample.Monster.AddPath(builder, path)
+ orc = MyGame.Sample.Monster.End(builder)
~~~
</div>
<div class="language-javascript">
@@ -1848,9 +1848,9 @@ Here is a repetition of these lines, to help highlight them more clearly:
</div>
<div class="language-python">
~~~{.py}
- MyGame.Sample.Monster.MonsterAddEquippedType( # Union type
+ MyGame.Sample.Monster.AddEquippedType( # Union type
builder, MyGame.Sample.Equipment.Equipment().Weapon)
- MyGame.Sample.Monster.MonsterAddEquipped(builder, axe) # Union data
+ MyGame.Sample.Monster.AddEquipped(builder, axe) # Union data
~~~
</div>
<div class="language-javascript">
@@ -2382,7 +2382,7 @@ won't work.**
buf = /* the data you just read, in an object of type "bytearray" */
// Get an accessor to the root object inside the buffer.
- monster = MyGame.Sample.Monster.Monster.GetRootAsMonster(buf, 0)
+ monster = MyGame.Sample.Monster.Monster.GetRootAs(buf, 0)
# Note: We use `0` for the offset here, which is typical for most buffers
# you would read. If you wanted to read from the `builder.Bytes` directly,