# automatically generated by the FlatBuffers compiler, do not modify

# namespace: Dl

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

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

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

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

    # OptionalType
    def ElemType(self):
        o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(4))
        if o != 0:
            x = self._tab.Indirect(o + self._tab.Pos)
            from FlatBuffers.Dl.TypeInfo import TypeInfo
            obj = TypeInfo()
            obj.Init(self._tab.Bytes, x)
            return obj
        return None

def OptionalTypeStart(builder):
    builder.StartObject(1)

def Start(builder):
    OptionalTypeStart(builder)

def OptionalTypeAddElemType(builder, elemType):
    builder.PrependUOffsetTRelativeSlot(0, flatbuffers.number_types.UOffsetTFlags.py_type(elemType), 0)

def AddElemType(builder, elemType):
    OptionalTypeAddElemType(builder, elemType)

def OptionalTypeEnd(builder):
    return builder.EndObject()

def End(builder):
    return OptionalTypeEnd(builder)

import FlatBuffers.Dl.TypeInfo
try:
    from typing import Optional
except:
    pass

class OptionalTypeT(object):

    # OptionalTypeT
    def __init__(self):
        self.elemType = None  # type: Optional[FlatBuffers.Dl.TypeInfo.TypeInfoT]

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

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

    # OptionalTypeT
    def _UnPack(self, optionalType):
        if optionalType is None:
            return
        if optionalType.ElemType() is not None:
            self.elemType = FlatBuffers.Dl.TypeInfo.TypeInfoT.InitFromObj(optionalType.ElemType())

    # OptionalTypeT
    def Pack(self, builder):
        if self.elemType is not None:
            elemType = self.elemType.Pack(builder)
        OptionalTypeStart(builder)
        if self.elemType is not None:
            OptionalTypeAddElemType(builder, elemType)
        optionalType = OptionalTypeEnd(builder)
        return optionalType
