# automatically generated by the FlatBuffers compiler, do not modify

# namespace: Types

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

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

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

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

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

    # ErrorResult
    def Reason(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

def ErrorResultStart(builder): builder.StartObject(2)
def Start(builder):
    return ErrorResultStart(builder)
def ErrorResultAddCode(builder, code): builder.PrependInt32Slot(0, code, 0)
def AddCode(builder, code):
    return ErrorResultAddCode(builder, code)
def ErrorResultAddReason(builder, reason): builder.PrependUOffsetTRelativeSlot(1, flatbuffers.number_types.UOffsetTFlags.py_type(reason), 0)
def AddReason(builder, reason):
    return ErrorResultAddReason(builder, reason)
def ErrorResultEnd(builder): return builder.EndObject()
def End(builder):
    return ErrorResultEnd(builder)

class ErrorResultT(object):

    # ErrorResultT
    def __init__(self):
        self.code = 0  # type: int
        self.reason = None  # type: str

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

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

    # ErrorResultT
    def _UnPack(self, errorResult):
        if errorResult is None:
            return
        self.code = errorResult.Code()
        self.reason = errorResult.Reason()

    # ErrorResultT
    def Pack(self, builder):
        if self.reason is not None:
            reason = builder.CreateString(self.reason)
        ErrorResultStart(builder)
        ErrorResultAddCode(builder, self.code)
        if self.reason is not None:
            ErrorResultAddReason(builder, reason)
        errorResult = ErrorResultEnd(builder)
        return errorResult
