poetry run install-flatc
from scripts.install_flatc import download_and_extract_flatc
download_and_extract_flatc()
flatc --python -o <output_path> <fbs_file>
reference from tests/test_flatbuffers_modifier.py
from flatbuffers_modifier import FlatbuffersModifier
with open("tests/data/output/monster.bin", "rb") as f:
data = f.read()
# add compiled flatbuffers schema to sys.path
modifier = FlatbuffersModifier(data, "MyGame.Sample", "Monster")
modifications = {
"hp": 500,
"weapon.damage": 10,
"weapon.type": "Bow"
}
updated_data = modifier.modify_fields(modifications)
with open("tests/data/output/updated_monster.bin", "wb") as f:
f.write(updated_data)