# automatically generated by the FlatBuffers compiler, do not modify

# namespace: Dl

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

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

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

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

    # ValueInfo
    def Name(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

    # ValueInfo
    def ValueInfoType(self):
        o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(6))
        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

    # ValueInfo
    def DocString(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

    # ValueInfo
    def Exponents(self, j):
        o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(10))
        if o != 0:
            a = self._tab.Vector(o)
            return self._tab.Get(flatbuffers.number_types.Int64Flags, a + flatbuffers.number_types.UOffsetTFlags.py_type(j * 8))
        return 0

    # ValueInfo
    def ExponentsAsNumpy(self):
        o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(10))
        if o != 0:
            return self._tab.GetVectorAsNumpy(flatbuffers.number_types.Int64Flags, o)
        return 0

    # ValueInfo
    def ExponentsLength(self):
        o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(10))
        if o != 0:
            return self._tab.VectorLen(o)
        return 0

    # ValueInfo
    def ExponentsIsNone(self):
        o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(10))
        return o == 0

def ValueInfoStart(builder):
    builder.StartObject(4)

def Start(builder):
    ValueInfoStart(builder)

def ValueInfoAddName(builder, name):
    builder.PrependUOffsetTRelativeSlot(0, flatbuffers.number_types.UOffsetTFlags.py_type(name), 0)

def AddName(builder, name):
    ValueInfoAddName(builder, name)

def ValueInfoAddValueInfoType(builder, valueInfoType):
    builder.PrependUOffsetTRelativeSlot(1, flatbuffers.number_types.UOffsetTFlags.py_type(valueInfoType), 0)

def AddValueInfoType(builder, valueInfoType):
    ValueInfoAddValueInfoType(builder, valueInfoType)

def ValueInfoAddDocString(builder, docString):
    builder.PrependUOffsetTRelativeSlot(2, flatbuffers.number_types.UOffsetTFlags.py_type(docString), 0)

def AddDocString(builder, docString):
    ValueInfoAddDocString(builder, docString)

def ValueInfoAddExponents(builder, exponents):
    builder.PrependUOffsetTRelativeSlot(3, flatbuffers.number_types.UOffsetTFlags.py_type(exponents), 0)

def AddExponents(builder, exponents):
    ValueInfoAddExponents(builder, exponents)

def ValueInfoStartExponentsVector(builder, numElems):
    return builder.StartVector(8, numElems, 8)

def StartExponentsVector(builder, numElems):
    return ValueInfoStartExponentsVector(builder, numElems)

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

def End(builder):
    return ValueInfoEnd(builder)

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

class ValueInfoT(object):

    # ValueInfoT
    def __init__(self):
        self.name = None  # type: str
        self.valueInfoType = None  # type: Optional[FlatBuffers.Dl.TypeInfo.TypeInfoT]
        self.docString = None  # type: str
        self.exponents = None  # type: List[int]

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

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

    # ValueInfoT
    def _UnPack(self, valueInfo):
        if valueInfo is None:
            return
        self.name = valueInfo.Name()
        if valueInfo.ValueInfoType() is not None:
            self.valueInfoType = FlatBuffers.Dl.TypeInfo.TypeInfoT.InitFromObj(valueInfo.ValueInfoType())
        self.docString = valueInfo.DocString()
        if not valueInfo.ExponentsIsNone():
            if np is None:
                self.exponents = []
                for i in range(valueInfo.ExponentsLength()):
                    self.exponents.append(valueInfo.Exponents(i))
            else:
                self.exponents = valueInfo.ExponentsAsNumpy()

    # ValueInfoT
    def Pack(self, builder):
        if self.name is not None:
            name = builder.CreateString(self.name)
        if self.valueInfoType is not None:
            valueInfoType = self.valueInfoType.Pack(builder)
        if self.docString is not None:
            docString = builder.CreateString(self.docString)
        if self.exponents is not None:
            if np is not None and type(self.exponents) is np.ndarray:
                exponents = builder.CreateNumpyVector(self.exponents)
            else:
                ValueInfoStartExponentsVector(builder, len(self.exponents))
                for i in reversed(range(len(self.exponents))):
                    builder.PrependInt64(self.exponents[i])
                exponents = builder.EndVector()
        ValueInfoStart(builder)
        if self.name is not None:
            ValueInfoAddName(builder, name)
        if self.valueInfoType is not None:
            ValueInfoAddValueInfoType(builder, valueInfoType)
        if self.docString is not None:
            ValueInfoAddDocString(builder, docString)
        if self.exponents is not None:
            ValueInfoAddExponents(builder, exponents)
        valueInfo = ValueInfoEnd(builder)
        return valueInfo
