"Fossies" - the Fresh Open Source Software Archive

Member "flatbuffers-23.1.21/tests/MyGame/Example/Ability.py" (21 Jan 2023, 1727 Bytes) of package /linux/misc/flatbuffers-23.1.21.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Python source code syntax highlighting (style: standard) with prefixed line numbers. Alternatively you can here view or download the uninterpreted source code file. See also the last Fossies "Diffs" side-by-side code changes report for "Ability.py": 22.10.25_vs_22.10.26.

    1 # automatically generated by the FlatBuffers compiler, do not modify
    2 
    3 # namespace: Example
    4 
    5 import flatbuffers
    6 from flatbuffers.compat import import_numpy
    7 np = import_numpy()
    8 
    9 class Ability(object):
   10     __slots__ = ['_tab']
   11 
   12     @classmethod
   13     def SizeOf(cls):
   14         return 8
   15 
   16     # Ability
   17     def Init(self, buf, pos):
   18         self._tab = flatbuffers.table.Table(buf, pos)
   19 
   20     # Ability
   21     def Id(self): return self._tab.Get(flatbuffers.number_types.Uint32Flags, self._tab.Pos + flatbuffers.number_types.UOffsetTFlags.py_type(0))
   22     # Ability
   23     def Distance(self): return self._tab.Get(flatbuffers.number_types.Uint32Flags, self._tab.Pos + flatbuffers.number_types.UOffsetTFlags.py_type(4))
   24 
   25 def CreateAbility(builder, id, distance):
   26     builder.Prep(4, 8)
   27     builder.PrependUint32(distance)
   28     builder.PrependUint32(id)
   29     return builder.Offset()
   30 
   31 
   32 class AbilityT(object):
   33 
   34     # AbilityT
   35     def __init__(self):
   36         self.id = 0  # type: int
   37         self.distance = 0  # type: int
   38 
   39     @classmethod
   40     def InitFromBuf(cls, buf, pos):
   41         ability = Ability()
   42         ability.Init(buf, pos)
   43         return cls.InitFromObj(ability)
   44 
   45     @classmethod
   46     def InitFromPackedBuf(cls, buf, pos=0):
   47         n = flatbuffers.encode.Get(flatbuffers.packer.uoffset, buf, pos)
   48         return cls.InitFromBuf(buf, pos+n)
   49 
   50     @classmethod
   51     def InitFromObj(cls, ability):
   52         x = AbilityT()
   53         x._UnPack(ability)
   54         return x
   55 
   56     # AbilityT
   57     def _UnPack(self, ability):
   58         if ability is None:
   59             return
   60         self.id = ability.Id()
   61         self.distance = ability.Distance()
   62 
   63     # AbilityT
   64     def Pack(self, builder):
   65         return CreateAbility(builder, self.id, self.distance)