# automatically generated by the FlatBuffers compiler, do not modify

# namespace: Packets

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

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

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

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

    # HelloResult
    def AppName(self):
        o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(4))
        if o != 0:
            return self._tab.String(o + self._tab.Pos)
        return None

    # HelloResult
    def AppVersion(self):
        o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(6))
        if o != 0:
            return self._tab.String(o + self._tab.Pos)
        return None

    # HelloResult
    def GamiumVersion(self):
        o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(8))
        if o != 0:
            return self._tab.String(o + self._tab.Pos)
        return None

    # HelloResult
    def FramesFromStart(self):
        o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(10))
        if o != 0:
            return self._tab.Get(flatbuffers.number_types.Uint64Flags, o + self._tab.Pos)
        return 0

    # HelloResult
    def SecondsFromStart(self):
        o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(12))
        if o != 0:
            return self._tab.Get(flatbuffers.number_types.Float32Flags, o + self._tab.Pos)
        return 0.0

    # HelloResult
    def ClientSequence(self):
        o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(14))
        if o != 0:
            return self._tab.Get(flatbuffers.number_types.Uint32Flags, o + self._tab.Pos)
        return 0

    # HelloResult
    def Envs(self, j):
        o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(16))
        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.Env import Env
            obj = Env()
            obj.Init(self._tab.Bytes, x)
            return obj
        return None

    # HelloResult
    def EnvsLength(self):
        o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(16))
        if o != 0:
            return self._tab.VectorLen(o)
        return 0

    # HelloResult
    def EnvsIsNone(self):
        o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(16))
        return o == 0

def HelloResultStart(builder): builder.StartObject(7)
def Start(builder):
    return HelloResultStart(builder)
def HelloResultAddAppName(builder, appName): builder.PrependUOffsetTRelativeSlot(0, flatbuffers.number_types.UOffsetTFlags.py_type(appName), 0)
def AddAppName(builder, appName):
    return HelloResultAddAppName(builder, appName)
def HelloResultAddAppVersion(builder, appVersion): builder.PrependUOffsetTRelativeSlot(1, flatbuffers.number_types.UOffsetTFlags.py_type(appVersion), 0)
def AddAppVersion(builder, appVersion):
    return HelloResultAddAppVersion(builder, appVersion)
def HelloResultAddGamiumVersion(builder, gamiumVersion): builder.PrependUOffsetTRelativeSlot(2, flatbuffers.number_types.UOffsetTFlags.py_type(gamiumVersion), 0)
def AddGamiumVersion(builder, gamiumVersion):
    return HelloResultAddGamiumVersion(builder, gamiumVersion)
def HelloResultAddFramesFromStart(builder, framesFromStart): builder.PrependUint64Slot(3, framesFromStart, 0)
def AddFramesFromStart(builder, framesFromStart):
    return HelloResultAddFramesFromStart(builder, framesFromStart)
def HelloResultAddSecondsFromStart(builder, secondsFromStart): builder.PrependFloat32Slot(4, secondsFromStart, 0.0)
def AddSecondsFromStart(builder, secondsFromStart):
    return HelloResultAddSecondsFromStart(builder, secondsFromStart)
def HelloResultAddClientSequence(builder, clientSequence): builder.PrependUint32Slot(5, clientSequence, 0)
def AddClientSequence(builder, clientSequence):
    return HelloResultAddClientSequence(builder, clientSequence)
def HelloResultAddEnvs(builder, envs): builder.PrependUOffsetTRelativeSlot(6, flatbuffers.number_types.UOffsetTFlags.py_type(envs), 0)
def AddEnvs(builder, envs):
    return HelloResultAddEnvs(builder, envs)
def HelloResultStartEnvsVector(builder, numElems): return builder.StartVector(4, numElems, 4)
def StartEnvsVector(builder, numElems):
    return HelloResultStartEnvsVector(builder, numElems)
def HelloResultEnd(builder): return builder.EndObject()
def End(builder):
    return HelloResultEnd(builder)
import gamium.protocol.generated.Packets.Env
try:
    from typing import List
except:
    pass

class HelloResultT(object):

    # HelloResultT
    def __init__(self):
        self.appName = None  # type: str
        self.appVersion = None  # type: str
        self.gamiumVersion = None  # type: str
        self.framesFromStart = 0  # type: int
        self.secondsFromStart = 0.0  # type: float
        self.clientSequence = 0  # type: int
        self.envs = None  # type: List[gamium.protocol.generated.Packets.Env.EnvT]

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

    @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, helloResult):
        x = HelloResultT()
        x._UnPack(helloResult)
        return x

    # HelloResultT
    def _UnPack(self, helloResult):
        if helloResult is None:
            return
        self.appName = helloResult.AppName()
        self.appVersion = helloResult.AppVersion()
        self.gamiumVersion = helloResult.GamiumVersion()
        self.framesFromStart = helloResult.FramesFromStart()
        self.secondsFromStart = helloResult.SecondsFromStart()
        self.clientSequence = helloResult.ClientSequence()
        if not helloResult.EnvsIsNone():
            self.envs = []
            for i in range(helloResult.EnvsLength()):
                if helloResult.Envs(i) is None:
                    self.envs.append(None)
                else:
                    env_ = gamium.protocol.generated.Packets.Env.EnvT.InitFromObj(helloResult.Envs(i))
                    self.envs.append(env_)

    # HelloResultT
    def Pack(self, builder):
        if self.appName is not None:
            appName = builder.CreateString(self.appName)
        if self.appVersion is not None:
            appVersion = builder.CreateString(self.appVersion)
        if self.gamiumVersion is not None:
            gamiumVersion = builder.CreateString(self.gamiumVersion)
        if self.envs is not None:
            envslist = []
            for i in range(len(self.envs)):
                envslist.append(self.envs[i].Pack(builder))
            HelloResultStartEnvsVector(builder, len(self.envs))
            for i in reversed(range(len(self.envs))):
                builder.PrependUOffsetTRelative(envslist[i])
            envs = builder.EndVector()
        HelloResultStart(builder)
        if self.appName is not None:
            HelloResultAddAppName(builder, appName)
        if self.appVersion is not None:
            HelloResultAddAppVersion(builder, appVersion)
        if self.gamiumVersion is not None:
            HelloResultAddGamiumVersion(builder, gamiumVersion)
        HelloResultAddFramesFromStart(builder, self.framesFromStart)
        HelloResultAddSecondsFromStart(builder, self.secondsFromStart)
        HelloResultAddClientSequence(builder, self.clientSequence)
        if self.envs is not None:
            HelloResultAddEnvs(builder, envs)
        helloResult = HelloResultEnd(builder)
        return helloResult
