# automatically generated by the FlatBuffers compiler, do not modify

# namespace: Packets

import flatbuffers
from flatbuffers.compat import import_numpy
np = import_numpy()

class ActionsResult(object):
    __slots__ = ['_tab']

    @classmethod
    def GetRootAs(cls, buf, offset=0):
        n = flatbuffers.encode.Get(flatbuffers.packer.uoffset, buf, offset)
        x = ActionsResult()
        x.Init(buf, n + offset)
        return x

    @classmethod
    def GetRootAsActionsResult(cls, buf, offset=0):
        """This method is deprecated. Please switch to GetRootAs."""
        return cls.GetRootAs(buf, offset)
    # ActionsResult
    def Init(self, buf, pos):
        self._tab = flatbuffers.table.Table(buf, pos)

    # ActionsResult
    def Results(self, j):
        o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(4))
        if o != 0:
            x = self._tab.Vector(o)
            x += flatbuffers.number_types.UOffsetTFlags.py_type(j) * 4
            x = self._tab.Indirect(x)
            from gamium.protocol.generated.Packets.ActionResult import ActionResult
            obj = ActionResult()
            obj.Init(self._tab.Bytes, x)
            return obj
        return None

    # ActionsResult
    def ResultsLength(self):
        o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(4))
        if o != 0:
            return self._tab.VectorLen(o)
        return 0

    # ActionsResult
    def ResultsIsNone(self):
        o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(4))
        return o == 0

def ActionsResultStart(builder): builder.StartObject(1)
def Start(builder):
    return ActionsResultStart(builder)
def ActionsResultAddResults(builder, results): builder.PrependUOffsetTRelativeSlot(0, flatbuffers.number_types.UOffsetTFlags.py_type(results), 0)
def AddResults(builder, results):
    return ActionsResultAddResults(builder, results)
def ActionsResultStartResultsVector(builder, numElems): return builder.StartVector(4, numElems, 4)
def StartResultsVector(builder, numElems):
    return ActionsResultStartResultsVector(builder, numElems)
def ActionsResultEnd(builder): return builder.EndObject()
def End(builder):
    return ActionsResultEnd(builder)
import gamium.protocol.generated.Packets.ActionResult
try:
    from typing import List
except:
    pass

class ActionsResultT(object):

    # ActionsResultT
    def __init__(self):
        self.results = None  # type: List[gamium.protocol.generated.Packets.ActionResult.ActionResultT]

    @classmethod
    def InitFromBuf(cls, buf, pos):
        actionsResult = ActionsResult()
        actionsResult.Init(buf, pos)
        return cls.InitFromObj(actionsResult)

    @classmethod
    def InitFromPackedBuf(cls, buf, pos=0):
        n = flatbuffers.encode.Get(flatbuffers.packer.uoffset, buf, pos)
        return cls.InitFromBuf(buf, pos+n)

    @classmethod
    def InitFromObj(cls, actionsResult):
        x = ActionsResultT()
        x._UnPack(actionsResult)
        return x

    # ActionsResultT
    def _UnPack(self, actionsResult):
        if actionsResult is None:
            return
        if not actionsResult.ResultsIsNone():
            self.results = []
            for i in range(actionsResult.ResultsLength()):
                if actionsResult.Results(i) is None:
                    self.results.append(None)
                else:
                    actionResult_ = gamium.protocol.generated.Packets.ActionResult.ActionResultT.InitFromObj(actionsResult.Results(i))
                    self.results.append(actionResult_)

    # ActionsResultT
    def Pack(self, builder):
        if self.results is not None:
            resultslist = []
            for i in range(len(self.results)):
                resultslist.append(self.results[i].Pack(builder))
            ActionsResultStartResultsVector(builder, len(self.results))
            for i in reversed(range(len(self.results))):
                builder.PrependUOffsetTRelative(resultslist[i])
            results = builder.EndVector()
        ActionsResultStart(builder)
        if self.results is not None:
            ActionsResultAddResults(builder, results)
        actionsResult = ActionsResultEnd(builder)
        return actionsResult
