# automatically generated by the FlatBuffers compiler, do not modify

# namespace: Dl

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

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

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

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

    # Node
    def Input(self, j):
        o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(4))
        if o != 0:
            a = self._tab.Vector(o)
            return self._tab.String(a + flatbuffers.number_types.UOffsetTFlags.py_type(j * 4))
        return ""

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

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

    # Node
    def Output(self, j):
        o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(6))
        if o != 0:
            a = self._tab.Vector(o)
            return self._tab.String(a + flatbuffers.number_types.UOffsetTFlags.py_type(j * 4))
        return ""

    # Node
    def OutputLength(self):
        o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(6))
        if o != 0:
            return self._tab.VectorLen(o)
        return 0

    # Node
    def OutputIsNone(self):
        o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(6))
        return o == 0

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

    # Node
    def OpType(self):
        o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(10))
        if o != 0:
            return self._tab.String(o + self._tab.Pos)
        return None

    # Node
    def Domain(self):
        o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(12))
        if o != 0:
            return self._tab.String(o + self._tab.Pos)
        return None

    # Node
    def Attribute(self, j):
        o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(14))
        if o != 0:
            x = self._tab.Vector(o)
            x += flatbuffers.number_types.UOffsetTFlags.py_type(j) * 4
            x = self._tab.Indirect(x)
            from FlatBuffers.Dl.Attribute import Attribute
            obj = Attribute()
            obj.Init(self._tab.Bytes, x)
            return obj
        return None

    # Node
    def AttributeLength(self):
        o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(14))
        if o != 0:
            return self._tab.VectorLen(o)
        return 0

    # Node
    def AttributeIsNone(self):
        o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(14))
        return o == 0

    # Node
    def DocString(self):
        o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(16))
        if o != 0:
            return self._tab.String(o + self._tab.Pos)
        return None

def NodeStart(builder):
    builder.StartObject(7)

def Start(builder):
    NodeStart(builder)

def NodeAddInput(builder, input):
    builder.PrependUOffsetTRelativeSlot(0, flatbuffers.number_types.UOffsetTFlags.py_type(input), 0)

def AddInput(builder, input):
    NodeAddInput(builder, input)

def NodeStartInputVector(builder, numElems):
    return builder.StartVector(4, numElems, 4)

def StartInputVector(builder, numElems):
    return NodeStartInputVector(builder, numElems)

def NodeAddOutput(builder, output):
    builder.PrependUOffsetTRelativeSlot(1, flatbuffers.number_types.UOffsetTFlags.py_type(output), 0)

def AddOutput(builder, output):
    NodeAddOutput(builder, output)

def NodeStartOutputVector(builder, numElems):
    return builder.StartVector(4, numElems, 4)

def StartOutputVector(builder, numElems):
    return NodeStartOutputVector(builder, numElems)

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

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

def NodeAddOpType(builder, opType):
    builder.PrependUOffsetTRelativeSlot(3, flatbuffers.number_types.UOffsetTFlags.py_type(opType), 0)

def AddOpType(builder, opType):
    NodeAddOpType(builder, opType)

def NodeAddDomain(builder, domain):
    builder.PrependUOffsetTRelativeSlot(4, flatbuffers.number_types.UOffsetTFlags.py_type(domain), 0)

def AddDomain(builder, domain):
    NodeAddDomain(builder, domain)

def NodeAddAttribute(builder, attribute):
    builder.PrependUOffsetTRelativeSlot(5, flatbuffers.number_types.UOffsetTFlags.py_type(attribute), 0)

def AddAttribute(builder, attribute):
    NodeAddAttribute(builder, attribute)

def NodeStartAttributeVector(builder, numElems):
    return builder.StartVector(4, numElems, 4)

def StartAttributeVector(builder, numElems):
    return NodeStartAttributeVector(builder, numElems)

def NodeAddDocString(builder, docString):
    builder.PrependUOffsetTRelativeSlot(6, flatbuffers.number_types.UOffsetTFlags.py_type(docString), 0)

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

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

def End(builder):
    return NodeEnd(builder)

import FlatBuffers.Dl.Attribute
try:
    from typing import List
except:
    pass

class NodeT(object):

    # NodeT
    def __init__(self):
        self.input = None  # type: List[str]
        self.output = None  # type: List[str]
        self.name = None  # type: str
        self.opType = None  # type: str
        self.domain = None  # type: str
        self.attribute = None  # type: List[FlatBuffers.Dl.Attribute.AttributeT]
        self.docString = None  # type: str

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

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

    # NodeT
    def _UnPack(self, node):
        if node is None:
            return
        if not node.InputIsNone():
            self.input = []
            for i in range(node.InputLength()):
                self.input.append(node.Input(i))
        if not node.OutputIsNone():
            self.output = []
            for i in range(node.OutputLength()):
                self.output.append(node.Output(i))
        self.name = node.Name()
        self.opType = node.OpType()
        self.domain = node.Domain()
        if not node.AttributeIsNone():
            self.attribute = []
            for i in range(node.AttributeLength()):
                if node.Attribute(i) is None:
                    self.attribute.append(None)
                else:
                    attribute_ = FlatBuffers.Dl.Attribute.AttributeT.InitFromObj(node.Attribute(i))
                    self.attribute.append(attribute_)
        self.docString = node.DocString()

    # NodeT
    def Pack(self, builder):
        if self.input is not None:
            inputlist = []
            for i in range(len(self.input)):
                inputlist.append(builder.CreateString(self.input[i]))
            NodeStartInputVector(builder, len(self.input))
            for i in reversed(range(len(self.input))):
                builder.PrependUOffsetTRelative(inputlist[i])
            input = builder.EndVector()
        if self.output is not None:
            outputlist = []
            for i in range(len(self.output)):
                outputlist.append(builder.CreateString(self.output[i]))
            NodeStartOutputVector(builder, len(self.output))
            for i in reversed(range(len(self.output))):
                builder.PrependUOffsetTRelative(outputlist[i])
            output = builder.EndVector()
        if self.name is not None:
            name = builder.CreateString(self.name)
        if self.opType is not None:
            opType = builder.CreateString(self.opType)
        if self.domain is not None:
            domain = builder.CreateString(self.domain)
        if self.attribute is not None:
            attributelist = []
            for i in range(len(self.attribute)):
                attributelist.append(self.attribute[i].Pack(builder))
            NodeStartAttributeVector(builder, len(self.attribute))
            for i in reversed(range(len(self.attribute))):
                builder.PrependUOffsetTRelative(attributelist[i])
            attribute = builder.EndVector()
        if self.docString is not None:
            docString = builder.CreateString(self.docString)
        NodeStart(builder)
        if self.input is not None:
            NodeAddInput(builder, input)
        if self.output is not None:
            NodeAddOutput(builder, output)
        if self.name is not None:
            NodeAddName(builder, name)
        if self.opType is not None:
            NodeAddOpType(builder, opType)
        if self.domain is not None:
            NodeAddDomain(builder, domain)
        if self.attribute is not None:
            NodeAddAttribute(builder, attribute)
        if self.docString is not None:
            NodeAddDocString(builder, docString)
        node = NodeEnd(builder)
        return node
