Skip to content

Instantly share code, notes, and snippets.

@prideout
Created January 19, 2016 04:09
Show Gist options
  • Save prideout/c962b47e5b8e3e4790e0 to your computer and use it in GitHub Desktop.
Save prideout/c962b47e5b8e3e4790e0 to your computer and use it in GitHub Desktop.
paste-to-console flatbuffers test for Python serialization
cd tests
cat > wombat.fbs <<EOF
namespace Fauna;
struct Foo { x:short; }
table Wombat { foos:[Foo]; }
EOF
../flatc -p wombat.fbs
cat > wombat.py <<EOF
import flatbuffers, binascii
from Fauna import Wombat, Foo
builder = flatbuffers.Builder(0)
Wombat.WombatStartFoosVector(builder, 2)
Foo.CreateFoo(builder, 0x1111)
Foo.CreateFoo(builder, 0x2222)
foos = builder.EndVector(2)
Wombat.WombatStart(builder)
Wombat.WombatAddFoos(builder, foos)
builder.Finish(Wombat.WombatEnd(builder))
print binascii.hexlify(builder.Bytes)
EOF
python wombat.py
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment