-
Notifications
You must be signed in to change notification settings - Fork 0
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
Added vector union, string and struct union support for Python #3
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -0,0 +1,77 @@ | ||||||
# automatically generated by the FlatBuffers compiler, do not modify | ||||||
|
||||||
# namespace: | ||||||
|
||||||
import flatbuffers | ||||||
from flatbuffers.compat import import_numpy | ||||||
np = import_numpy() | ||||||
|
||||||
class Attacker(object): | ||||||
__slots__ = ['_tab'] | ||||||
|
||||||
@classmethod | ||||||
def GetRootAs(cls, buf, offset=0): | ||||||
n = flatbuffers.encode.Get(flatbuffers.packer.uoffset, buf, offset) | ||||||
x = Attacker() | ||||||
x.Init(buf, n + offset) | ||||||
return x | ||||||
|
||||||
@classmethod | ||||||
def GetRootAsAttacker(cls, buf, offset=0): | ||||||
"""This method is deprecated. Please switch to GetRootAs.""" | ||||||
return cls.GetRootAs(buf, offset) | ||||||
@classmethod | ||||||
def AttackerBufferHasIdentifier(cls, buf, offset, size_prefixed=False): | ||||||
return flatbuffers.util.BufferHasIdentifier(buf, offset, b"\x4D\x4F\x56\x49", size_prefixed=size_prefixed) | ||||||
|
||||||
# Attacker | ||||||
def Init(self, buf, pos): | ||||||
self._tab = flatbuffers.table.Table(buf, pos) | ||||||
|
||||||
# Attacker | ||||||
def SwordAttackDamage(self): | ||||||
o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(4)) | ||||||
if o != 0: | ||||||
return self._tab.Get(flatbuffers.number_types.Int32Flags, o + self._tab.Pos) | ||||||
return 0 | ||||||
|
||||||
def AttackerStart(builder): builder.StartObject(1) | ||||||
def Start(builder): | ||||||
return AttackerStart(builder) | ||||||
def AttackerAddSwordAttackDamage(builder, swordAttackDamage): builder.PrependInt32Slot(0, swordAttackDamage, 0) | ||||||
def AddSwordAttackDamage(builder, swordAttackDamage): | ||||||
return AttackerAddSwordAttackDamage(builder, swordAttackDamage) | ||||||
def AttackerEnd(builder): return builder.EndObject() | ||||||
def End(builder): | ||||||
return AttackerEnd(builder) | ||||||
|
||||||
class AttackerT(object): | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
Similarly, Explicitly inheriting from object is redundant. |
||||||
|
||||||
# AttackerT | ||||||
def __init__(self): | ||||||
self.swordAttackDamage = 0 # type: int | ||||||
|
||||||
@classmethod | ||||||
def InitFromBuf(cls, buf, pos): | ||||||
attacker = Attacker() | ||||||
attacker.Init(buf, pos) | ||||||
return cls.InitFromObj(attacker) | ||||||
|
||||||
@classmethod | ||||||
def InitFromObj(cls, attacker): | ||||||
x = AttackerT() | ||||||
x._UnPack(attacker) | ||||||
return x | ||||||
|
||||||
# AttackerT | ||||||
def _UnPack(self, attacker): | ||||||
if attacker is None: | ||||||
return | ||||||
self.swordAttackDamage = attacker.SwordAttackDamage() | ||||||
|
||||||
# AttackerT | ||||||
def Pack(self, builder): | ||||||
AttackerStart(builder) | ||||||
AttackerAddSwordAttackDamage(builder, self.swordAttackDamage) | ||||||
attacker = AttackerEnd(builder) | ||||||
return attacker |
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -0,0 +1,55 @@ | ||||||
# automatically generated by the FlatBuffers compiler, do not modify | ||||||
|
||||||
# namespace: | ||||||
|
||||||
import flatbuffers | ||||||
from flatbuffers.compat import import_numpy | ||||||
np = import_numpy() | ||||||
|
||||||
class BookReader(object): | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
__slots__ = ['_tab'] | ||||||
|
||||||
@classmethod | ||||||
def SizeOf(cls): | ||||||
return 4 | ||||||
|
||||||
# BookReader | ||||||
def Init(self, buf, pos): | ||||||
self._tab = flatbuffers.table.Table(buf, pos) | ||||||
|
||||||
# BookReader | ||||||
def BooksRead(self): return self._tab.Get(flatbuffers.number_types.Int32Flags, self._tab.Pos + flatbuffers.number_types.UOffsetTFlags.py_type(0)) | ||||||
|
||||||
def CreateBookReader(builder, booksRead): | ||||||
builder.Prep(4, 4) | ||||||
builder.PrependInt32(booksRead) | ||||||
return builder.Offset() | ||||||
|
||||||
|
||||||
class BookReaderT(object): | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
Same as above: Explicitly inheriting from object is redundant. |
||||||
|
||||||
# BookReaderT | ||||||
def __init__(self): | ||||||
self.booksRead = 0 # type: int | ||||||
|
||||||
@classmethod | ||||||
def InitFromBuf(cls, buf, pos): | ||||||
bookReader = BookReader() | ||||||
bookReader.Init(buf, pos) | ||||||
return cls.InitFromObj(bookReader) | ||||||
|
||||||
@classmethod | ||||||
def InitFromObj(cls, bookReader): | ||||||
x = BookReaderT() | ||||||
x._UnPack(bookReader) | ||||||
return x | ||||||
|
||||||
# BookReaderT | ||||||
def _UnPack(self, bookReader): | ||||||
if bookReader is None: | ||||||
return | ||||||
self.booksRead = bookReader.BooksRead() | ||||||
|
||||||
# BookReaderT | ||||||
def Pack(self, builder): | ||||||
return CreateBookReader(builder, self.booksRead) |
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -0,0 +1,38 @@ | ||||||
# automatically generated by the FlatBuffers compiler, do not modify | ||||||
|
||||||
# namespace: | ||||||
|
||||||
class Character(object): | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
NONE = 0 | ||||||
MuLan = 1 | ||||||
Rapunzel = 2 | ||||||
Belle = 3 | ||||||
BookFan = 4 | ||||||
Other = 5 | ||||||
Unused = 6 | ||||||
|
||||||
def CharacterCreator(unionType, table): | ||||||
from flatbuffers.table import Table | ||||||
if not isinstance(table, Table): | ||||||
return None | ||||||
if unionType == Character().MuLan: | ||||||
import Attacker | ||||||
return Attacker.AttackerT.InitFromBuf(table.Bytes, table.Pos) | ||||||
if unionType == Character().Rapunzel: | ||||||
import Rapunzel | ||||||
return Rapunzel.RapunzelT.InitFromBuf(table.Bytes, table.Pos) | ||||||
if unionType == Character().Belle: | ||||||
import BookReader | ||||||
return BookReader.BookReaderT.InitFromBuf(table.Bytes, table.Pos) | ||||||
if unionType == Character().BookFan: | ||||||
import BookReader | ||||||
return BookReader.BookReaderT.InitFromBuf(table.Bytes, table.Pos) | ||||||
if unionType == Character().Other: | ||||||
tab = Table(table.Bytes, table.Pos) | ||||||
union = tab.UnionString(table.Pos) | ||||||
return union | ||||||
if unionType == Character().Unused: | ||||||
tab = Table(table.Bytes, table.Pos) | ||||||
union = tab.UnionString(table.Pos) | ||||||
return union | ||||||
return None |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Attacker
inherits fromobject
by default, so explicitly inheriting from object is redundant. Removing it keeps the code simpler. Explained here.