# automatically generated by the FlatBuffers compiler, do not modify

# namespace: flatbuf

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

# A union is a complex type with children in Field
# By default ids in the type vector refer to the offsets in the children
# optionally typeIds provides an indirection between the child offset and the type id
# for each child `typeIds[offset]` is the id used in the type vector
class Union(object):
    __slots__ = ['_tab']

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

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

    # Union
    def Mode(self):
        o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(4))
        if o != 0:
            return self._tab.Get(flatbuffers.number_types.Int16Flags, o + self._tab.Pos)
        return 0

    # Union
    def TypeIds(self, j):
        o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(6))
        if o != 0:
            a = self._tab.Vector(o)
            return self._tab.Get(flatbuffers.number_types.Int32Flags, a + flatbuffers.number_types.UOffsetTFlags.py_type(j * 4))
        return 0

    # Union
    def TypeIdsAsNumpy(self):
        o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(6))
        if o != 0:
            return self._tab.GetVectorAsNumpy(flatbuffers.number_types.Int32Flags, o)
        return 0

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

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

def Start(builder): builder.StartObject(2)
def UnionStart(builder):
    """This method is deprecated. Please switch to Start."""
    return Start(builder)
def AddMode(builder, mode): builder.PrependInt16Slot(0, mode, 0)
def UnionAddMode(builder, mode):
    """This method is deprecated. Please switch to AddMode."""
    return AddMode(builder, mode)
def AddTypeIds(builder, typeIds): builder.PrependUOffsetTRelativeSlot(1, flatbuffers.number_types.UOffsetTFlags.py_type(typeIds), 0)
def UnionAddTypeIds(builder, typeIds):
    """This method is deprecated. Please switch to AddTypeIds."""
    return AddTypeIds(builder, typeIds)
def StartTypeIdsVector(builder, numElems): return builder.StartVector(4, numElems, 4)
def UnionStartTypeIdsVector(builder, numElems):
    """This method is deprecated. Please switch to Start."""
    return StartTypeIdsVector(builder, numElems)
def End(builder): return builder.EndObject()
def UnionEnd(builder):
    """This method is deprecated. Please switch to End."""
    return End(builder)