Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Python] Use 'T' suffix object for serialization #8230

Open
mhs4670go opened this issue Feb 6, 2024 · 0 comments
Open

[Python] Use 'T' suffix object for serialization #8230

mhs4670go opened this issue Feb 6, 2024 · 0 comments

Comments

@mhs4670go
Copy link

Hello. I'm a newbie on flatbuffers for python language.

I've got two questions about serialization with T-suffix object.

Seems that, when it comes to the serialization, StartXXX and EndXXX api are used like below.

builder = flatbuffers.Builder(1024)

# Create the first `Weapon` ('Sword').
MyGame.Sample.Weapon.Start(builder)
MyGame.Sample.Weapon.AddName(builder, weapon_one)
MyGame.Sample.Weapon.AddDamage(builder, 3)
sword = MyGame.Sample.Weapon.End(builder)

But, following method can do the same thing.

  1. Create Object
  2. Fill some contents
  3. Finish the object with packing the Object
builder = flatbuffers.Builder(1024)

sword = MyGame.Sample.Weapon.WeaponT() # Create T-suffix object
sword.name = weapon_one
sword.damage = 3

builder.Finish(sowrd.Pack(builder))
buf = builder.Output()

Q1) Is it safe to do a serialization with above second way?
Q2)
When I fill in the contents into the created T-suffix object, it is allowed to set an attribute that is not included in the schema like below.

sword = MyGame.Sample.Weapon.WeaponT()
sword.NonExistsAttribute = True # it causes no error

And, the serialization is done successfully. But, I think it is error-prone. Is there any verification api for this kind of check?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant