# Generated by the protocol compiler version 1.3.8
# DO NOT EDIT THIS FILE DIRECTLY!

__doc__ = "Message serializer for the DAQData protocol."

from itertools import chain, islice

__all__ = [
    "ProtocolError",
    "unmarshal_request",
    "unmarshal_reply",
    "BasicStatus_struct",
    "AnalogAlarm_struct",
    "DigitalAlarm_struct",
    "ServiceDiscovery_request",
    "OpenList_request",
    "AddToList_request",
    "RemoveFromList_request",
    "ClearList_request",
    "ProcList_request",
    "ReadingRequest_request",
    "SettingRequest_request",
    "ServiceDiscovery_reply",
    "OpenList_reply",
    "BinarySample_reply",
    "BooleanSample_reply",
    "BooleanArraySample_reply",
    "ShortSample_reply",
    "ShortArraySample_reply",
    "IntegerSample_reply",
    "IntegerArraySample_reply",
    "LongSample_reply",
    "LongArraySample_reply",
    "DoubleSample_reply",
    "DoubleArraySample_reply",
    "StringSample_reply",
    "StringArraySample_reply",
    "BasicStatusSample_reply",
    "BasicStatusArraySample_reply",
    "AnalogAlarmSample_reply",
    "AnalogAlarmArraySample_reply",
    "DigitalAlarmSample_reply",
    "DigitalAlarmArraySample_reply",
    "BasicControlSample_reply",
    "ErrorSample_reply",
]

import struct


class ProtocolError(Exception):
    """Exception class that gets raised when there's a problem marshaling
    or unmarshaling a message from the DAQData protocol."""

    def __init__(self, reason):
        self.reason = reason

    def __str__(self):
        return repr(self.reason)


# -- Internal marshalling routines --


def emitRawInt(tag, val):
    def emitEach(buf, n):
        curr = (val >> (n * 8)) & 0xFF
        next = val >> ((n + 1) * 8)
        if (next == 0 and (curr & 0x80) != 0x80) or (next == -1 and (curr & 0x80) == 0x80):
            buf.append(tag + n + 1)
        else:
            emitEach(buf, n + 1)
        buf.append(curr)

    tmp = bytearray()
    emitEach(tmp, 0)
    return bytes(tmp)


def marshal_bool(val):
    yield (0x71 if val else 0x70)


def marshal_int16(val):
    if isinstance(val, int):
        if val < 32768 and val > -32769:
            return emitRawInt(0x10, val)
        else:
            raise ProtocolError("value out of range for int16")
    else:
        raise ProtocolError("expected integer type")


def marshal_int32(val):
    if isinstance(val, int):
        if int(-2147483648) <= val <= int(2147483647):
            return emitRawInt(0x10, val)
        else:
            raise ProtocolError("value out of range for int32")
    else:
        raise ProtocolError("expected integer type")


def marshal_int64(val):
    if isinstance(val, int):
        if int(-9223372036854775808) <= val <= int(9223372036854775807):
            return emitRawInt(0x10, val)
        else:
            raise ProtocolError("value out of range for int64")
    else:
        raise ProtocolError("expected integer type")


def marshal_double(val):
    return chain(b"\x28", (ii for ii in struct.pack(">d", float(val))))


def marshal_string(val):
    if isinstance(val, str):
        return chain(emitRawInt(0x40, len(val)), (ord(ii) for ii in val))
    else:
        raise ProtocolError("expected string type")


def marshal_binary(val):
    if isinstance(val, bytearray):
        return chain(emitRawInt(0x30, len(val)), val)
    else:
        raise ProtocolError("expected bytearray type")


def marshal_array(fn, val):
    if isinstance(val, list):
        return chain(emitRawInt(0x50, len(val)), chain.from_iterable((fn(v) for v in val)))
    else:
        raise ProtocolError("expected list type")


def marshal_header():
    return (ii for ii in b"SDD\x02\x51\x03\x14\xee\xb9\x06\x99")


class BasicStatus_struct:
    def __eq__(self, other):
        return (
            (
                (not hasattr(self, "on") and not hasattr(other, "on"))
                or (hasattr(self, "on") and hasattr(other, "on") and self.on == other.on)
            )
            and (
                (not hasattr(self, "ready") and not hasattr(other, "ready"))
                or (hasattr(self, "ready") and hasattr(other, "ready") and self.ready == other.ready)
            )
            and (
                (not hasattr(self, "remote") and not hasattr(other, "remote"))
                or (hasattr(self, "remote") and hasattr(other, "remote") and self.remote == other.remote)
            )
            and (
                (not hasattr(self, "positive") and not hasattr(other, "positive"))
                or (hasattr(self, "positive") and hasattr(other, "positive") and self.positive == other.positive)
            )
            and (
                (not hasattr(self, "ramp") and not hasattr(other, "ramp"))
                or (hasattr(self, "ramp") and hasattr(other, "ramp") and self.ramp == other.ramp)
            )
        )

    def __ne__(self, other):
        return not self.__eq__(other)


def marshal_BasicStatus_struct(val):
    return chain(
        emitRawInt(
            0x50,
            0
            + (2 if hasattr(val, "on") else 0)
            + (2 if hasattr(val, "ready") else 0)
            + (2 if hasattr(val, "remote") else 0)
            + (2 if hasattr(val, "positive") else 0)
            + (2 if hasattr(val, "ramp") else 0),
        ),
        chain(b"\x12\x5c\x01", marshal_bool(val.on)) if hasattr(val, "on") else bytearray(),
        chain(b"\x12\xab\x23", marshal_bool(val.ready)) if hasattr(val, "ready") else bytearray(),
        chain(b"\x12\xe4\x86", marshal_bool(val.remote)) if hasattr(val, "remote") else bytearray(),
        chain(b"\x12\x27\x16", marshal_bool(val.positive)) if hasattr(val, "positive") else bytearray(),
        chain(b"\x12\x92\x38", marshal_bool(val.ramp)) if hasattr(val, "ramp") else bytearray(),
    )


class AnalogAlarm_struct:
    def __init__(self):
        self.minimum = float(0.0)
        self.maximum = float(0.0)
        self.alarm_enable = bool(False)
        self.alarm_status = bool(False)
        self.abort = bool(False)
        self.abort_inhibit = bool(False)
        self.tries_needed = int(0)
        self.tries_now = int(0)

    def __eq__(self, other):
        return (
            self.minimum == other.minimum
            and self.maximum == other.maximum
            and self.alarm_enable == other.alarm_enable
            and self.alarm_status == other.alarm_status
            and self.abort == other.abort
            and self.abort_inhibit == other.abort_inhibit
            and self.tries_needed == other.tries_needed
            and self.tries_now == other.tries_now
        )

    def __ne__(self, other):
        return not self.__eq__(other)


def marshal_AnalogAlarm_struct(val):
    return chain(
        b"\x51\x10",
        b"\x12\x23\x4c",
        marshal_double(val.minimum),
        b"\x12\xe2\x88",
        marshal_double(val.maximum),
        b"\x12\x8f\x20",
        marshal_bool(val.alarm_enable),
        b"\x12\x60\x36",
        marshal_bool(val.alarm_status),
        b"\x12\x4a\x1c",
        marshal_bool(val.abort),
        b"\x12\x81\x72",
        marshal_bool(val.abort_inhibit),
        b"\x12\x01\x32",
        marshal_int32(val.tries_needed),
        b"\x12\x2b\x3e",
        marshal_int32(val.tries_now),
    )


class DigitalAlarm_struct:
    def __init__(self):
        self.nominal = int(0)
        self.mask = int(0)
        self.alarm_enable = bool(False)
        self.alarm_status = bool(False)
        self.abort = bool(False)
        self.abort_inhibit = bool(False)
        self.tries_needed = int(0)
        self.tries_now = int(0)

    def __eq__(self, other):
        return (
            self.nominal == other.nominal
            and self.mask == other.mask
            and self.alarm_enable == other.alarm_enable
            and self.alarm_status == other.alarm_status
            and self.abort == other.abort
            and self.abort_inhibit == other.abort_inhibit
            and self.tries_needed == other.tries_needed
            and self.tries_now == other.tries_now
        )

    def __ne__(self, other):
        return not self.__eq__(other)


def marshal_DigitalAlarm_struct(val):
    return chain(
        b"\x51\x10",
        b"\x12\x4f\x1d",
        marshal_int32(val.nominal),
        b"\x12\x11\xeb",
        marshal_int32(val.mask),
        b"\x12\x8f\x20",
        marshal_bool(val.alarm_enable),
        b"\x12\x60\x36",
        marshal_bool(val.alarm_status),
        b"\x12\x4a\x1c",
        marshal_bool(val.abort),
        b"\x12\x81\x72",
        marshal_bool(val.abort_inhibit),
        b"\x12\x01\x32",
        marshal_int32(val.tries_needed),
        b"\x12\x2b\x3e",
        marshal_int32(val.tries_now),
    )


__all__.append("BasicControl_Reset")
BasicControl_Reset = 26767
__all__.append("BasicControl_On")
BasicControl_On = 13987
__all__.append("BasicControl_Off")
BasicControl_Off = 1495
__all__.append("BasicControl_Positive")
BasicControl_Positive = 10612
__all__.append("BasicControl_Negative")
BasicControl_Negative = 13679
__all__.append("BasicControl_Ramp")
BasicControl_Ramp = -15441
__all__.append("BasicControl_DC")
BasicControl_DC = -6841


def marshal_BasicControl_enum(val):
    if int(val) == 26767:
        return b"\x82\x68\x8f"
    elif int(val) == 13987:
        return b"\x82\x36\xa3"
    elif int(val) == 1495:
        return b"\x82\x05\xd7"
    elif int(val) == 10612:
        return b"\x82\x29\x74"
    elif int(val) == 13679:
        return b"\x82\x35\x6f"
    elif int(val) == -15441:
        return b"\x82\xc3\xaf"
    elif int(val) == -6841:
        return b"\x82\xe5\x47"
    else:
        raise ProtocolError("invalid value for enum 'BasicControl'")


class ServiceDiscovery_request:
    def __eq__(self, other):
        return True

    def __ne__(self, other):
        return False

    def marshal(self):
        """Returns a generator that emits a character stream representing
        the marshaled contents of ServiceDiscovery_request."""
        return chain(marshal_header(), b"\x12\xdf\xda", b"\x51\x00")


class OpenList_request:
    def __eq__(self, other):
        return True

    def __ne__(self, other):
        return False

    def marshal(self):
        """Returns a generator that emits a character stream representing
        the marshaled contents of OpenList_request."""
        return chain(marshal_header(), b"\x12\x08\x1c", b"\x51\x00")


class AddToList_request:
    def __init__(self):
        self.list_id = int(0)
        self.ref_id = int(0)
        self.drf_request = ""

    def __eq__(self, other):
        return self.list_id == other.list_id and self.ref_id == other.ref_id and self.drf_request == other.drf_request

    def __ne__(self, other):
        return not self.__eq__(other)

    def marshal(self):
        """Returns a generator that emits a character stream representing
        the marshaled contents of AddToList_request."""
        return chain(
            marshal_header(),
            b"\x11\x61",
            b"\x51\x06",
            b"\x12\xe8\x20",
            marshal_int32(self.list_id),
            b"\x12\x1e\xab",
            marshal_int32(self.ref_id),
            b"\x12\x63\x24",
            marshal_string(self.drf_request),
        )


class RemoveFromList_request:
    def __init__(self):
        self.list_id = int(0)
        self.ref_id = int(0)

    def __eq__(self, other):
        return self.list_id == other.list_id and self.ref_id == other.ref_id

    def __ne__(self, other):
        return not self.__eq__(other)

    def marshal(self):
        """Returns a generator that emits a character stream representing
        the marshaled contents of RemoveFromList_request."""
        return chain(
            marshal_header(),
            b"\x12\xf1\x21",
            b"\x51\x04",
            b"\x12\xe8\x20",
            marshal_int32(self.list_id),
            b"\x12\x1e\xab",
            marshal_int32(self.ref_id),
        )


class ClearList_request:
    def __init__(self):
        self.list_id = int(0)

    def __eq__(self, other):
        return self.list_id == other.list_id

    def __ne__(self, other):
        return not self.__eq__(other)

    def marshal(self):
        """Returns a generator that emits a character stream representing
        the marshaled contents of ClearList_request."""
        return chain(marshal_header(), b"\x12\xc3\x09", b"\x51\x02", b"\x12\xe8\x20", marshal_int32(self.list_id))


class ProcList_request:
    def __init__(self):
        self.list_id = int(0)

    def __eq__(self, other):
        return self.list_id == other.list_id

    def __ne__(self, other):
        return not self.__eq__(other)

    def marshal(self):
        """Returns a generator that emits a character stream representing
        the marshaled contents of ProcList_request."""
        return chain(marshal_header(), b"\x12\x31\x31", b"\x51\x02", b"\x12\xe8\x20", marshal_int32(self.list_id))


class ReadingRequest_request:
    def __init__(self):
        self.dataRequest = []

    def __eq__(self, other):
        return self.dataRequest == other.dataRequest

    def __ne__(self, other):
        return not self.__eq__(other)

    def marshal(self):
        """Returns a generator that emits a character stream representing
        the marshaled contents of ReadingRequest_request."""
        return chain(
            marshal_header(),
            b"\x12\xa8\x12",
            b"\x51\x02",
            b"\x12\x62\x7c",
            marshal_array(marshal_string, self.dataRequest),
        )


class SettingRequest_request:
    def __init__(self):
        self.dataRequest = []

    def __eq__(self, other):
        return self.dataRequest == other.dataRequest

    def __ne__(self, other):
        return not self.__eq__(other)

    def marshal(self):
        """Returns a generator that emits a character stream representing
        the marshaled contents of SettingRequest_request."""
        return chain(
            marshal_header(),
            b"\x12\x4f\xde",
            b"\x51\x02",
            b"\x12\x62\x7c",
            marshal_array(marshal_string, self.dataRequest),
        )


class ServiceDiscovery_reply:
    def __init__(self):
        self.load = int(0)

    def __eq__(self, other):
        return self.load == other.load

    def __ne__(self, other):
        return not self.__eq__(other)

    def marshal(self):
        """Returns a generator that emits a character stream representing
        the marshaled contents of ServiceDiscovery_reply."""
        return chain(marshal_header(), b"\x12\xcd\x7e", b"\x51\x02", b"\x12\x1e\xb3", marshal_int16(self.load))


class OpenList_reply:
    def __init__(self):
        self.list_id = int(0)

    def __eq__(self, other):
        return self.list_id == other.list_id

    def __ne__(self, other):
        return not self.__eq__(other)

    def marshal(self):
        """Returns a generator that emits a character stream representing
        the marshaled contents of OpenList_reply."""
        return chain(marshal_header(), b"\x12\x34\x9e", b"\x51\x02", b"\x12\xe8\x20", marshal_int32(self.list_id))


class BinarySample_reply:
    def __init__(self):
        self.value = bytearray(b"")
        self.time = int(0)

    def __eq__(self, other):
        return (
            self.value == other.value
            and self.time == other.time
            and (
                (not hasattr(self, "return_time") and not hasattr(other, "return_time"))
                or (
                    hasattr(self, "return_time")
                    and hasattr(other, "return_time")
                    and self.return_time == other.return_time
                )
            )
            and (
                (not hasattr(self, "cycle_time") and not hasattr(other, "cycle_time"))
                or (
                    hasattr(self, "cycle_time") and hasattr(other, "cycle_time") and self.cycle_time == other.cycle_time
                )
            )
            and (
                (not hasattr(self, "ref_id") and not hasattr(other, "ref_id"))
                or (hasattr(self, "ref_id") and hasattr(other, "ref_id") and self.ref_id == other.ref_id)
            )
        )

    def __ne__(self, other):
        return not self.__eq__(other)

    def marshal(self):
        """Returns a generator that emits a character stream representing
        the marshaled contents of BinarySample_reply."""
        return chain(
            marshal_header(),
            b"\x12\x96\x06",
            emitRawInt(
                0x50,
                4
                + (2 if hasattr(self, "return_time") else 0)
                + (2 if hasattr(self, "cycle_time") else 0)
                + (2 if hasattr(self, "ref_id") else 0),
            ),
            b"\x12\xc1\x60",
            marshal_binary(self.value),
            b"\x12\x69\x4b",
            marshal_int64(self.time),
            chain(b"\x12\x52\xc6", marshal_int64(self.return_time)) if hasattr(self, "return_time") else bytearray(),
            chain(b"\x12\x11\x87", marshal_int64(self.cycle_time)) if hasattr(self, "cycle_time") else bytearray(),
            chain(b"\x12\x1e\xab", marshal_int16(self.ref_id)) if hasattr(self, "ref_id") else bytearray(),
        )


class BooleanSample_reply:
    def __init__(self):
        self.value = bool(False)
        self.time = int(0)

    def __eq__(self, other):
        return (
            self.value == other.value
            and self.time == other.time
            and (
                (not hasattr(self, "return_time") and not hasattr(other, "return_time"))
                or (
                    hasattr(self, "return_time")
                    and hasattr(other, "return_time")
                    and self.return_time == other.return_time
                )
            )
            and (
                (not hasattr(self, "cycle_time") and not hasattr(other, "cycle_time"))
                or (
                    hasattr(self, "cycle_time") and hasattr(other, "cycle_time") and self.cycle_time == other.cycle_time
                )
            )
            and (
                (not hasattr(self, "ref_id") and not hasattr(other, "ref_id"))
                or (hasattr(self, "ref_id") and hasattr(other, "ref_id") and self.ref_id == other.ref_id)
            )
        )

    def __ne__(self, other):
        return not self.__eq__(other)

    def marshal(self):
        """Returns a generator that emits a character stream representing
        the marshaled contents of BooleanSample_reply."""
        return chain(
            marshal_header(),
            b"\x12\xcf\x8c",
            emitRawInt(
                0x50,
                4
                + (2 if hasattr(self, "return_time") else 0)
                + (2 if hasattr(self, "cycle_time") else 0)
                + (2 if hasattr(self, "ref_id") else 0),
            ),
            b"\x12\xc1\x60",
            marshal_bool(self.value),
            b"\x12\x69\x4b",
            marshal_int64(self.time),
            chain(b"\x12\x52\xc6", marshal_int64(self.return_time)) if hasattr(self, "return_time") else bytearray(),
            chain(b"\x12\x11\x87", marshal_int64(self.cycle_time)) if hasattr(self, "cycle_time") else bytearray(),
            chain(b"\x12\x1e\xab", marshal_int16(self.ref_id)) if hasattr(self, "ref_id") else bytearray(),
        )


class BooleanArraySample_reply:
    def __init__(self):
        self.value = []
        self.time = int(0)

    def __eq__(self, other):
        return (
            self.value == other.value
            and self.time == other.time
            and (
                (not hasattr(self, "return_time") and not hasattr(other, "return_time"))
                or (
                    hasattr(self, "return_time")
                    and hasattr(other, "return_time")
                    and self.return_time == other.return_time
                )
            )
            and (
                (not hasattr(self, "cycle_time") and not hasattr(other, "cycle_time"))
                or (
                    hasattr(self, "cycle_time") and hasattr(other, "cycle_time") and self.cycle_time == other.cycle_time
                )
            )
            and (
                (not hasattr(self, "ref_id") and not hasattr(other, "ref_id"))
                or (hasattr(self, "ref_id") and hasattr(other, "ref_id") and self.ref_id == other.ref_id)
            )
        )

    def __ne__(self, other):
        return not self.__eq__(other)

    def marshal(self):
        """Returns a generator that emits a character stream representing
        the marshaled contents of BooleanArraySample_reply."""
        return chain(
            marshal_header(),
            b"\x12\x23\x52",
            emitRawInt(
                0x50,
                4
                + (2 if hasattr(self, "return_time") else 0)
                + (2 if hasattr(self, "cycle_time") else 0)
                + (2 if hasattr(self, "ref_id") else 0),
            ),
            b"\x12\xc1\x60",
            marshal_array(marshal_bool, self.value),
            b"\x12\x69\x4b",
            marshal_int64(self.time),
            chain(b"\x12\x52\xc6", marshal_int64(self.return_time)) if hasattr(self, "return_time") else bytearray(),
            chain(b"\x12\x11\x87", marshal_int64(self.cycle_time)) if hasattr(self, "cycle_time") else bytearray(),
            chain(b"\x12\x1e\xab", marshal_int16(self.ref_id)) if hasattr(self, "ref_id") else bytearray(),
        )


class ShortSample_reply:
    def __init__(self):
        self.value = int(0)
        self.time = int(0)

    def __eq__(self, other):
        return (
            self.value == other.value
            and self.time == other.time
            and (
                (not hasattr(self, "return_time") and not hasattr(other, "return_time"))
                or (
                    hasattr(self, "return_time")
                    and hasattr(other, "return_time")
                    and self.return_time == other.return_time
                )
            )
            and (
                (not hasattr(self, "cycle_time") and not hasattr(other, "cycle_time"))
                or (
                    hasattr(self, "cycle_time") and hasattr(other, "cycle_time") and self.cycle_time == other.cycle_time
                )
            )
            and (
                (not hasattr(self, "unit") and not hasattr(other, "unit"))
                or (hasattr(self, "unit") and hasattr(other, "unit") and self.unit == other.unit)
            )
            and (
                (not hasattr(self, "format_hint") and not hasattr(other, "format_hint"))
                or (
                    hasattr(self, "format_hint")
                    and hasattr(other, "format_hint")
                    and self.format_hint == other.format_hint
                )
            )
            and (
                (not hasattr(self, "ref_id") and not hasattr(other, "ref_id"))
                or (hasattr(self, "ref_id") and hasattr(other, "ref_id") and self.ref_id == other.ref_id)
            )
        )

    def __ne__(self, other):
        return not self.__eq__(other)

    def marshal(self):
        """Returns a generator that emits a character stream representing
        the marshaled contents of ShortSample_reply."""
        return chain(
            marshal_header(),
            b"\x12\x73\xfe",
            emitRawInt(
                0x50,
                4
                + (2 if hasattr(self, "return_time") else 0)
                + (2 if hasattr(self, "cycle_time") else 0)
                + (2 if hasattr(self, "unit") else 0)
                + (2 if hasattr(self, "format_hint") else 0)
                + (2 if hasattr(self, "ref_id") else 0),
            ),
            b"\x12\xc1\x60",
            marshal_int16(self.value),
            b"\x12\x69\x4b",
            marshal_int64(self.time),
            chain(b"\x12\x52\xc6", marshal_int64(self.return_time)) if hasattr(self, "return_time") else bytearray(),
            chain(b"\x12\x11\x87", marshal_int64(self.cycle_time)) if hasattr(self, "cycle_time") else bytearray(),
            chain(b"\x12\xbd\xeb", marshal_string(self.unit)) if hasattr(self, "unit") else bytearray(),
            chain(b"\x12\x7e\xc2", marshal_int16(self.format_hint)) if hasattr(self, "format_hint") else bytearray(),
            chain(b"\x12\x1e\xab", marshal_int16(self.ref_id)) if hasattr(self, "ref_id") else bytearray(),
        )


class ShortArraySample_reply:
    def __init__(self):
        self.value = []
        self.time = int(0)

    def __eq__(self, other):
        return (
            self.value == other.value
            and self.time == other.time
            and (
                (not hasattr(self, "return_time") and not hasattr(other, "return_time"))
                or (
                    hasattr(self, "return_time")
                    and hasattr(other, "return_time")
                    and self.return_time == other.return_time
                )
            )
            and (
                (not hasattr(self, "cycle_time") and not hasattr(other, "cycle_time"))
                or (
                    hasattr(self, "cycle_time") and hasattr(other, "cycle_time") and self.cycle_time == other.cycle_time
                )
            )
            and (
                (not hasattr(self, "unit") and not hasattr(other, "unit"))
                or (hasattr(self, "unit") and hasattr(other, "unit") and self.unit == other.unit)
            )
            and (
                (not hasattr(self, "format_hint") and not hasattr(other, "format_hint"))
                or (
                    hasattr(self, "format_hint")
                    and hasattr(other, "format_hint")
                    and self.format_hint == other.format_hint
                )
            )
            and (
                (not hasattr(self, "ref_id") and not hasattr(other, "ref_id"))
                or (hasattr(self, "ref_id") and hasattr(other, "ref_id") and self.ref_id == other.ref_id)
            )
        )

    def __ne__(self, other):
        return not self.__eq__(other)

    def marshal(self):
        """Returns a generator that emits a character stream representing
        the marshaled contents of ShortArraySample_reply."""
        return chain(
            marshal_header(),
            b"\x12\xca\x60",
            emitRawInt(
                0x50,
                4
                + (2 if hasattr(self, "return_time") else 0)
                + (2 if hasattr(self, "cycle_time") else 0)
                + (2 if hasattr(self, "unit") else 0)
                + (2 if hasattr(self, "format_hint") else 0)
                + (2 if hasattr(self, "ref_id") else 0),
            ),
            b"\x12\xc1\x60",
            marshal_array(marshal_int16, self.value),
            b"\x12\x69\x4b",
            marshal_int64(self.time),
            chain(b"\x12\x52\xc6", marshal_int64(self.return_time)) if hasattr(self, "return_time") else bytearray(),
            chain(b"\x12\x11\x87", marshal_int64(self.cycle_time)) if hasattr(self, "cycle_time") else bytearray(),
            chain(b"\x12\xbd\xeb", marshal_string(self.unit)) if hasattr(self, "unit") else bytearray(),
            chain(b"\x12\x7e\xc2", marshal_int16(self.format_hint)) if hasattr(self, "format_hint") else bytearray(),
            chain(b"\x12\x1e\xab", marshal_int16(self.ref_id)) if hasattr(self, "ref_id") else bytearray(),
        )


class IntegerSample_reply:
    def __init__(self):
        self.value = int(0)
        self.time = int(0)

    def __eq__(self, other):
        return (
            self.value == other.value
            and self.time == other.time
            and (
                (not hasattr(self, "return_time") and not hasattr(other, "return_time"))
                or (
                    hasattr(self, "return_time")
                    and hasattr(other, "return_time")
                    and self.return_time == other.return_time
                )
            )
            and (
                (not hasattr(self, "cycle_time") and not hasattr(other, "cycle_time"))
                or (
                    hasattr(self, "cycle_time") and hasattr(other, "cycle_time") and self.cycle_time == other.cycle_time
                )
            )
            and (
                (not hasattr(self, "unit") and not hasattr(other, "unit"))
                or (hasattr(self, "unit") and hasattr(other, "unit") and self.unit == other.unit)
            )
            and (
                (not hasattr(self, "format_hint") and not hasattr(other, "format_hint"))
                or (
                    hasattr(self, "format_hint")
                    and hasattr(other, "format_hint")
                    and self.format_hint == other.format_hint
                )
            )
            and (
                (not hasattr(self, "ref_id") and not hasattr(other, "ref_id"))
                or (hasattr(self, "ref_id") and hasattr(other, "ref_id") and self.ref_id == other.ref_id)
            )
        )

    def __ne__(self, other):
        return not self.__eq__(other)

    def marshal(self):
        """Returns a generator that emits a character stream representing
        the marshaled contents of IntegerSample_reply."""
        return chain(
            marshal_header(),
            b"\x12\x7d\x64",
            emitRawInt(
                0x50,
                4
                + (2 if hasattr(self, "return_time") else 0)
                + (2 if hasattr(self, "cycle_time") else 0)
                + (2 if hasattr(self, "unit") else 0)
                + (2 if hasattr(self, "format_hint") else 0)
                + (2 if hasattr(self, "ref_id") else 0),
            ),
            b"\x12\xc1\x60",
            marshal_int32(self.value),
            b"\x12\x69\x4b",
            marshal_int64(self.time),
            chain(b"\x12\x52\xc6", marshal_int64(self.return_time)) if hasattr(self, "return_time") else bytearray(),
            chain(b"\x12\x11\x87", marshal_int64(self.cycle_time)) if hasattr(self, "cycle_time") else bytearray(),
            chain(b"\x12\xbd\xeb", marshal_string(self.unit)) if hasattr(self, "unit") else bytearray(),
            chain(b"\x12\x7e\xc2", marshal_int16(self.format_hint)) if hasattr(self, "format_hint") else bytearray(),
            chain(b"\x12\x1e\xab", marshal_int16(self.ref_id)) if hasattr(self, "ref_id") else bytearray(),
        )


class IntegerArraySample_reply:
    def __init__(self):
        self.value = []
        self.time = int(0)

    def __eq__(self, other):
        return (
            self.value == other.value
            and self.time == other.time
            and (
                (not hasattr(self, "return_time") and not hasattr(other, "return_time"))
                or (
                    hasattr(self, "return_time")
                    and hasattr(other, "return_time")
                    and self.return_time == other.return_time
                )
            )
            and (
                (not hasattr(self, "cycle_time") and not hasattr(other, "cycle_time"))
                or (
                    hasattr(self, "cycle_time") and hasattr(other, "cycle_time") and self.cycle_time == other.cycle_time
                )
            )
            and (
                (not hasattr(self, "unit") and not hasattr(other, "unit"))
                or (hasattr(self, "unit") and hasattr(other, "unit") and self.unit == other.unit)
            )
            and (
                (not hasattr(self, "format_hint") and not hasattr(other, "format_hint"))
                or (
                    hasattr(self, "format_hint")
                    and hasattr(other, "format_hint")
                    and self.format_hint == other.format_hint
                )
            )
            and (
                (not hasattr(self, "ref_id") and not hasattr(other, "ref_id"))
                or (hasattr(self, "ref_id") and hasattr(other, "ref_id") and self.ref_id == other.ref_id)
            )
        )

    def __ne__(self, other):
        return not self.__eq__(other)

    def marshal(self):
        """Returns a generator that emits a character stream representing
        the marshaled contents of IntegerArraySample_reply."""
        return chain(
            marshal_header(),
            b"\x12\x6c\xd0",
            emitRawInt(
                0x50,
                4
                + (2 if hasattr(self, "return_time") else 0)
                + (2 if hasattr(self, "cycle_time") else 0)
                + (2 if hasattr(self, "unit") else 0)
                + (2 if hasattr(self, "format_hint") else 0)
                + (2 if hasattr(self, "ref_id") else 0),
            ),
            b"\x12\xc1\x60",
            marshal_array(marshal_int32, self.value),
            b"\x12\x69\x4b",
            marshal_int64(self.time),
            chain(b"\x12\x52\xc6", marshal_int64(self.return_time)) if hasattr(self, "return_time") else bytearray(),
            chain(b"\x12\x11\x87", marshal_int64(self.cycle_time)) if hasattr(self, "cycle_time") else bytearray(),
            chain(b"\x12\xbd\xeb", marshal_string(self.unit)) if hasattr(self, "unit") else bytearray(),
            chain(b"\x12\x7e\xc2", marshal_int16(self.format_hint)) if hasattr(self, "format_hint") else bytearray(),
            chain(b"\x12\x1e\xab", marshal_int16(self.ref_id)) if hasattr(self, "ref_id") else bytearray(),
        )


class LongSample_reply:
    def __init__(self):
        self.value = int(0)
        self.time = int(0)

    def __eq__(self, other):
        return (
            self.value == other.value
            and self.time == other.time
            and (
                (not hasattr(self, "return_time") and not hasattr(other, "return_time"))
                or (
                    hasattr(self, "return_time")
                    and hasattr(other, "return_time")
                    and self.return_time == other.return_time
                )
            )
            and (
                (not hasattr(self, "cycle_time") and not hasattr(other, "cycle_time"))
                or (
                    hasattr(self, "cycle_time") and hasattr(other, "cycle_time") and self.cycle_time == other.cycle_time
                )
            )
            and (
                (not hasattr(self, "unit") and not hasattr(other, "unit"))
                or (hasattr(self, "unit") and hasattr(other, "unit") and self.unit == other.unit)
            )
            and (
                (not hasattr(self, "format_hint") and not hasattr(other, "format_hint"))
                or (
                    hasattr(self, "format_hint")
                    and hasattr(other, "format_hint")
                    and self.format_hint == other.format_hint
                )
            )
            and (
                (not hasattr(self, "ref_id") and not hasattr(other, "ref_id"))
                or (hasattr(self, "ref_id") and hasattr(other, "ref_id") and self.ref_id == other.ref_id)
            )
        )

    def __ne__(self, other):
        return not self.__eq__(other)

    def marshal(self):
        """Returns a generator that emits a character stream representing
        the marshaled contents of LongSample_reply."""
        return chain(
            marshal_header(),
            b"\x12\x34\xc2",
            emitRawInt(
                0x50,
                4
                + (2 if hasattr(self, "return_time") else 0)
                + (2 if hasattr(self, "cycle_time") else 0)
                + (2 if hasattr(self, "unit") else 0)
                + (2 if hasattr(self, "format_hint") else 0)
                + (2 if hasattr(self, "ref_id") else 0),
            ),
            b"\x12\xc1\x60",
            marshal_int64(self.value),
            b"\x12\x69\x4b",
            marshal_int64(self.time),
            chain(b"\x12\x52\xc6", marshal_int64(self.return_time)) if hasattr(self, "return_time") else bytearray(),
            chain(b"\x12\x11\x87", marshal_int64(self.cycle_time)) if hasattr(self, "cycle_time") else bytearray(),
            chain(b"\x12\xbd\xeb", marshal_string(self.unit)) if hasattr(self, "unit") else bytearray(),
            chain(b"\x12\x7e\xc2", marshal_int16(self.format_hint)) if hasattr(self, "format_hint") else bytearray(),
            chain(b"\x12\x1e\xab", marshal_int16(self.ref_id)) if hasattr(self, "ref_id") else bytearray(),
        )


class LongArraySample_reply:
    def __init__(self):
        self.value = []
        self.time = int(0)

    def __eq__(self, other):
        return (
            self.value == other.value
            and self.time == other.time
            and (
                (not hasattr(self, "return_time") and not hasattr(other, "return_time"))
                or (
                    hasattr(self, "return_time")
                    and hasattr(other, "return_time")
                    and self.return_time == other.return_time
                )
            )
            and (
                (not hasattr(self, "cycle_time") and not hasattr(other, "cycle_time"))
                or (
                    hasattr(self, "cycle_time") and hasattr(other, "cycle_time") and self.cycle_time == other.cycle_time
                )
            )
            and (
                (not hasattr(self, "unit") and not hasattr(other, "unit"))
                or (hasattr(self, "unit") and hasattr(other, "unit") and self.unit == other.unit)
            )
            and (
                (not hasattr(self, "format_hint") and not hasattr(other, "format_hint"))
                or (
                    hasattr(self, "format_hint")
                    and hasattr(other, "format_hint")
                    and self.format_hint == other.format_hint
                )
            )
            and (
                (not hasattr(self, "ref_id") and not hasattr(other, "ref_id"))
                or (hasattr(self, "ref_id") and hasattr(other, "ref_id") and self.ref_id == other.ref_id)
            )
        )

    def __ne__(self, other):
        return not self.__eq__(other)

    def marshal(self):
        """Returns a generator that emits a character stream representing
        the marshaled contents of LongArraySample_reply."""
        return chain(
            marshal_header(),
            b"\x12\xdd\x54",
            emitRawInt(
                0x50,
                4
                + (2 if hasattr(self, "return_time") else 0)
                + (2 if hasattr(self, "cycle_time") else 0)
                + (2 if hasattr(self, "unit") else 0)
                + (2 if hasattr(self, "format_hint") else 0)
                + (2 if hasattr(self, "ref_id") else 0),
            ),
            b"\x12\xc1\x60",
            marshal_array(marshal_int64, self.value),
            b"\x12\x69\x4b",
            marshal_int64(self.time),
            chain(b"\x12\x52\xc6", marshal_int64(self.return_time)) if hasattr(self, "return_time") else bytearray(),
            chain(b"\x12\x11\x87", marshal_int64(self.cycle_time)) if hasattr(self, "cycle_time") else bytearray(),
            chain(b"\x12\xbd\xeb", marshal_string(self.unit)) if hasattr(self, "unit") else bytearray(),
            chain(b"\x12\x7e\xc2", marshal_int16(self.format_hint)) if hasattr(self, "format_hint") else bytearray(),
            chain(b"\x12\x1e\xab", marshal_int16(self.ref_id)) if hasattr(self, "ref_id") else bytearray(),
        )


class DoubleSample_reply:
    def __init__(self):
        self.value = float(0.0)
        self.time = int(0)

    def __eq__(self, other):
        return (
            self.value == other.value
            and self.time == other.time
            and (
                (not hasattr(self, "return_time") and not hasattr(other, "return_time"))
                or (
                    hasattr(self, "return_time")
                    and hasattr(other, "return_time")
                    and self.return_time == other.return_time
                )
            )
            and (
                (not hasattr(self, "cycle_time") and not hasattr(other, "cycle_time"))
                or (
                    hasattr(self, "cycle_time") and hasattr(other, "cycle_time") and self.cycle_time == other.cycle_time
                )
            )
            and (
                (not hasattr(self, "unit") and not hasattr(other, "unit"))
                or (hasattr(self, "unit") and hasattr(other, "unit") and self.unit == other.unit)
            )
            and (
                (not hasattr(self, "format_hint") and not hasattr(other, "format_hint"))
                or (
                    hasattr(self, "format_hint")
                    and hasattr(other, "format_hint")
                    and self.format_hint == other.format_hint
                )
            )
            and (
                (not hasattr(self, "ref_id") and not hasattr(other, "ref_id"))
                or (hasattr(self, "ref_id") and hasattr(other, "ref_id") and self.ref_id == other.ref_id)
            )
        )

    def __ne__(self, other):
        return not self.__eq__(other)

    def marshal(self):
        """Returns a generator that emits a character stream representing
        the marshaled contents of DoubleSample_reply."""
        return chain(
            marshal_header(),
            b"\x12\x81\xd1",
            emitRawInt(
                0x50,
                4
                + (2 if hasattr(self, "return_time") else 0)
                + (2 if hasattr(self, "cycle_time") else 0)
                + (2 if hasattr(self, "unit") else 0)
                + (2 if hasattr(self, "format_hint") else 0)
                + (2 if hasattr(self, "ref_id") else 0),
            ),
            b"\x12\xc1\x60",
            marshal_double(self.value),
            b"\x12\x69\x4b",
            marshal_int64(self.time),
            chain(b"\x12\x52\xc6", marshal_int64(self.return_time)) if hasattr(self, "return_time") else bytearray(),
            chain(b"\x12\x11\x87", marshal_int64(self.cycle_time)) if hasattr(self, "cycle_time") else bytearray(),
            chain(b"\x12\xbd\xeb", marshal_string(self.unit)) if hasattr(self, "unit") else bytearray(),
            chain(b"\x12\x7e\xc2", marshal_int16(self.format_hint)) if hasattr(self, "format_hint") else bytearray(),
            chain(b"\x12\x1e\xab", marshal_int16(self.ref_id)) if hasattr(self, "ref_id") else bytearray(),
        )


class DoubleArraySample_reply:
    def __init__(self):
        self.value = []
        self.time = int(0)

    def __eq__(self, other):
        return (
            self.value == other.value
            and self.time == other.time
            and (
                (not hasattr(self, "return_time") and not hasattr(other, "return_time"))
                or (
                    hasattr(self, "return_time")
                    and hasattr(other, "return_time")
                    and self.return_time == other.return_time
                )
            )
            and (
                (not hasattr(self, "cycle_time") and not hasattr(other, "cycle_time"))
                or (
                    hasattr(self, "cycle_time") and hasattr(other, "cycle_time") and self.cycle_time == other.cycle_time
                )
            )
            and (
                (not hasattr(self, "unit") and not hasattr(other, "unit"))
                or (hasattr(self, "unit") and hasattr(other, "unit") and self.unit == other.unit)
            )
            and (
                (not hasattr(self, "format_hint") and not hasattr(other, "format_hint"))
                or (
                    hasattr(self, "format_hint")
                    and hasattr(other, "format_hint")
                    and self.format_hint == other.format_hint
                )
            )
            and (
                (not hasattr(self, "ref_id") and not hasattr(other, "ref_id"))
                or (hasattr(self, "ref_id") and hasattr(other, "ref_id") and self.ref_id == other.ref_id)
            )
        )

    def __ne__(self, other):
        return not self.__eq__(other)

    def marshal(self):
        """Returns a generator that emits a character stream representing
        the marshaled contents of DoubleArraySample_reply."""
        return chain(
            marshal_header(),
            b"\x12\x40\x0b",
            emitRawInt(
                0x50,
                4
                + (2 if hasattr(self, "return_time") else 0)
                + (2 if hasattr(self, "cycle_time") else 0)
                + (2 if hasattr(self, "unit") else 0)
                + (2 if hasattr(self, "format_hint") else 0)
                + (2 if hasattr(self, "ref_id") else 0),
            ),
            b"\x12\xc1\x60",
            marshal_array(marshal_double, self.value),
            b"\x12\x69\x4b",
            marshal_int64(self.time),
            chain(b"\x12\x52\xc6", marshal_int64(self.return_time)) if hasattr(self, "return_time") else bytearray(),
            chain(b"\x12\x11\x87", marshal_int64(self.cycle_time)) if hasattr(self, "cycle_time") else bytearray(),
            chain(b"\x12\xbd\xeb", marshal_string(self.unit)) if hasattr(self, "unit") else bytearray(),
            chain(b"\x12\x7e\xc2", marshal_int16(self.format_hint)) if hasattr(self, "format_hint") else bytearray(),
            chain(b"\x12\x1e\xab", marshal_int16(self.ref_id)) if hasattr(self, "ref_id") else bytearray(),
        )


class StringSample_reply:
    def __init__(self):
        self.value = ""
        self.time = int(0)

    def __eq__(self, other):
        return (
            self.value == other.value
            and self.time == other.time
            and (
                (not hasattr(self, "return_time") and not hasattr(other, "return_time"))
                or (
                    hasattr(self, "return_time")
                    and hasattr(other, "return_time")
                    and self.return_time == other.return_time
                )
            )
            and (
                (not hasattr(self, "cycle_time") and not hasattr(other, "cycle_time"))
                or (
                    hasattr(self, "cycle_time") and hasattr(other, "cycle_time") and self.cycle_time == other.cycle_time
                )
            )
            and (
                (not hasattr(self, "ref_id") and not hasattr(other, "ref_id"))
                or (hasattr(self, "ref_id") and hasattr(other, "ref_id") and self.ref_id == other.ref_id)
            )
        )

    def __ne__(self, other):
        return not self.__eq__(other)

    def marshal(self):
        """Returns a generator that emits a character stream representing
        the marshaled contents of StringSample_reply."""
        return chain(
            marshal_header(),
            b"\x12\x8d\xca",
            emitRawInt(
                0x50,
                4
                + (2 if hasattr(self, "return_time") else 0)
                + (2 if hasattr(self, "cycle_time") else 0)
                + (2 if hasattr(self, "ref_id") else 0),
            ),
            b"\x12\xc1\x60",
            marshal_string(self.value),
            b"\x12\x69\x4b",
            marshal_int64(self.time),
            chain(b"\x12\x52\xc6", marshal_int64(self.return_time)) if hasattr(self, "return_time") else bytearray(),
            chain(b"\x12\x11\x87", marshal_int64(self.cycle_time)) if hasattr(self, "cycle_time") else bytearray(),
            chain(b"\x12\x1e\xab", marshal_int16(self.ref_id)) if hasattr(self, "ref_id") else bytearray(),
        )


class StringArraySample_reply:
    def __init__(self):
        self.value = []
        self.time = int(0)

    def __eq__(self, other):
        return (
            self.value == other.value
            and self.time == other.time
            and (
                (not hasattr(self, "return_time") and not hasattr(other, "return_time"))
                or (
                    hasattr(self, "return_time")
                    and hasattr(other, "return_time")
                    and self.return_time == other.return_time
                )
            )
            and (
                (not hasattr(self, "cycle_time") and not hasattr(other, "cycle_time"))
                or (
                    hasattr(self, "cycle_time") and hasattr(other, "cycle_time") and self.cycle_time == other.cycle_time
                )
            )
            and (
                (not hasattr(self, "ref_id") and not hasattr(other, "ref_id"))
                or (hasattr(self, "ref_id") and hasattr(other, "ref_id") and self.ref_id == other.ref_id)
            )
        )

    def __ne__(self, other):
        return not self.__eq__(other)

    def marshal(self):
        """Returns a generator that emits a character stream representing
        the marshaled contents of StringArraySample_reply."""
        return chain(
            marshal_header(),
            b"\x12\x81\x22",
            emitRawInt(
                0x50,
                4
                + (2 if hasattr(self, "return_time") else 0)
                + (2 if hasattr(self, "cycle_time") else 0)
                + (2 if hasattr(self, "ref_id") else 0),
            ),
            b"\x12\xc1\x60",
            marshal_array(marshal_string, self.value),
            b"\x12\x69\x4b",
            marshal_int64(self.time),
            chain(b"\x12\x52\xc6", marshal_int64(self.return_time)) if hasattr(self, "return_time") else bytearray(),
            chain(b"\x12\x11\x87", marshal_int64(self.cycle_time)) if hasattr(self, "cycle_time") else bytearray(),
            chain(b"\x12\x1e\xab", marshal_int16(self.ref_id)) if hasattr(self, "ref_id") else bytearray(),
        )


class BasicStatusSample_reply:
    def __init__(self):
        self.value = BasicStatus_struct()
        self.time = int(0)

    def __eq__(self, other):
        return (
            self.value == other.value
            and self.time == other.time
            and (
                (not hasattr(self, "return_time") and not hasattr(other, "return_time"))
                or (
                    hasattr(self, "return_time")
                    and hasattr(other, "return_time")
                    and self.return_time == other.return_time
                )
            )
            and (
                (not hasattr(self, "cycle_time") and not hasattr(other, "cycle_time"))
                or (
                    hasattr(self, "cycle_time") and hasattr(other, "cycle_time") and self.cycle_time == other.cycle_time
                )
            )
            and (
                (not hasattr(self, "ref_id") and not hasattr(other, "ref_id"))
                or (hasattr(self, "ref_id") and hasattr(other, "ref_id") and self.ref_id == other.ref_id)
            )
        )

    def __ne__(self, other):
        return not self.__eq__(other)

    def marshal(self):
        """Returns a generator that emits a character stream representing
        the marshaled contents of BasicStatusSample_reply."""
        return chain(
            marshal_header(),
            b"\x12\xbc\x83",
            emitRawInt(
                0x50,
                4
                + (2 if hasattr(self, "return_time") else 0)
                + (2 if hasattr(self, "cycle_time") else 0)
                + (2 if hasattr(self, "ref_id") else 0),
            ),
            b"\x12\xc1\x60",
            marshal_BasicStatus_struct(self.value),
            b"\x12\x69\x4b",
            marshal_int64(self.time),
            chain(b"\x12\x52\xc6", marshal_int64(self.return_time)) if hasattr(self, "return_time") else bytearray(),
            chain(b"\x12\x11\x87", marshal_int64(self.cycle_time)) if hasattr(self, "cycle_time") else bytearray(),
            chain(b"\x12\x1e\xab", marshal_int16(self.ref_id)) if hasattr(self, "ref_id") else bytearray(),
        )


class BasicStatusArraySample_reply:
    def __init__(self):
        self.value = []
        self.time = int(0)

    def __eq__(self, other):
        return (
            self.value == other.value
            and self.time == other.time
            and (
                (not hasattr(self, "return_time") and not hasattr(other, "return_time"))
                or (
                    hasattr(self, "return_time")
                    and hasattr(other, "return_time")
                    and self.return_time == other.return_time
                )
            )
            and (
                (not hasattr(self, "cycle_time") and not hasattr(other, "cycle_time"))
                or (
                    hasattr(self, "cycle_time") and hasattr(other, "cycle_time") and self.cycle_time == other.cycle_time
                )
            )
            and (
                (not hasattr(self, "ref_id") and not hasattr(other, "ref_id"))
                or (hasattr(self, "ref_id") and hasattr(other, "ref_id") and self.ref_id == other.ref_id)
            )
        )

    def __ne__(self, other):
        return not self.__eq__(other)

    def marshal(self):
        """Returns a generator that emits a character stream representing
        the marshaled contents of BasicStatusArraySample_reply."""
        return chain(
            marshal_header(),
            b"\x12\x36\x84",
            emitRawInt(
                0x50,
                4
                + (2 if hasattr(self, "return_time") else 0)
                + (2 if hasattr(self, "cycle_time") else 0)
                + (2 if hasattr(self, "ref_id") else 0),
            ),
            b"\x12\xc1\x60",
            marshal_array(marshal_BasicStatus_struct, self.value),
            b"\x12\x69\x4b",
            marshal_int64(self.time),
            chain(b"\x12\x52\xc6", marshal_int64(self.return_time)) if hasattr(self, "return_time") else bytearray(),
            chain(b"\x12\x11\x87", marshal_int64(self.cycle_time)) if hasattr(self, "cycle_time") else bytearray(),
            chain(b"\x12\x1e\xab", marshal_int16(self.ref_id)) if hasattr(self, "ref_id") else bytearray(),
        )


class AnalogAlarmSample_reply:
    def __init__(self):
        self.value = AnalogAlarm_struct()
        self.time = int(0)

    def __eq__(self, other):
        return (
            self.value == other.value
            and self.time == other.time
            and (
                (not hasattr(self, "return_time") and not hasattr(other, "return_time"))
                or (
                    hasattr(self, "return_time")
                    and hasattr(other, "return_time")
                    and self.return_time == other.return_time
                )
            )
            and (
                (not hasattr(self, "cycle_time") and not hasattr(other, "cycle_time"))
                or (
                    hasattr(self, "cycle_time") and hasattr(other, "cycle_time") and self.cycle_time == other.cycle_time
                )
            )
            and (
                (not hasattr(self, "ref_id") and not hasattr(other, "ref_id"))
                or (hasattr(self, "ref_id") and hasattr(other, "ref_id") and self.ref_id == other.ref_id)
            )
        )

    def __ne__(self, other):
        return not self.__eq__(other)

    def marshal(self):
        """Returns a generator that emits a character stream representing
        the marshaled contents of AnalogAlarmSample_reply."""
        return chain(
            marshal_header(),
            b"\x12\x24\x21",
            emitRawInt(
                0x50,
                4
                + (2 if hasattr(self, "return_time") else 0)
                + (2 if hasattr(self, "cycle_time") else 0)
                + (2 if hasattr(self, "ref_id") else 0),
            ),
            b"\x12\xc1\x60",
            marshal_AnalogAlarm_struct(self.value),
            b"\x12\x69\x4b",
            marshal_int64(self.time),
            chain(b"\x12\x52\xc6", marshal_int64(self.return_time)) if hasattr(self, "return_time") else bytearray(),
            chain(b"\x12\x11\x87", marshal_int64(self.cycle_time)) if hasattr(self, "cycle_time") else bytearray(),
            chain(b"\x12\x1e\xab", marshal_int16(self.ref_id)) if hasattr(self, "ref_id") else bytearray(),
        )


class AnalogAlarmArraySample_reply:
    def __init__(self):
        self.value = []
        self.time = int(0)

    def __eq__(self, other):
        return (
            self.value == other.value
            and self.time == other.time
            and (
                (not hasattr(self, "return_time") and not hasattr(other, "return_time"))
                or (
                    hasattr(self, "return_time")
                    and hasattr(other, "return_time")
                    and self.return_time == other.return_time
                )
            )
            and (
                (not hasattr(self, "cycle_time") and not hasattr(other, "cycle_time"))
                or (
                    hasattr(self, "cycle_time") and hasattr(other, "cycle_time") and self.cycle_time == other.cycle_time
                )
            )
            and (
                (not hasattr(self, "ref_id") and not hasattr(other, "ref_id"))
                or (hasattr(self, "ref_id") and hasattr(other, "ref_id") and self.ref_id == other.ref_id)
            )
        )

    def __ne__(self, other):
        return not self.__eq__(other)

    def marshal(self):
        """Returns a generator that emits a character stream representing
        the marshaled contents of AnalogAlarmArraySample_reply."""
        return chain(
            marshal_header(),
            b"\x12\x18\xb8",
            emitRawInt(
                0x50,
                4
                + (2 if hasattr(self, "return_time") else 0)
                + (2 if hasattr(self, "cycle_time") else 0)
                + (2 if hasattr(self, "ref_id") else 0),
            ),
            b"\x12\xc1\x60",
            marshal_array(marshal_AnalogAlarm_struct, self.value),
            b"\x12\x69\x4b",
            marshal_int64(self.time),
            chain(b"\x12\x52\xc6", marshal_int64(self.return_time)) if hasattr(self, "return_time") else bytearray(),
            chain(b"\x12\x11\x87", marshal_int64(self.cycle_time)) if hasattr(self, "cycle_time") else bytearray(),
            chain(b"\x12\x1e\xab", marshal_int16(self.ref_id)) if hasattr(self, "ref_id") else bytearray(),
        )


class DigitalAlarmSample_reply:
    def __init__(self):
        self.value = DigitalAlarm_struct()
        self.time = int(0)

    def __eq__(self, other):
        return (
            self.value == other.value
            and self.time == other.time
            and (
                (not hasattr(self, "return_time") and not hasattr(other, "return_time"))
                or (
                    hasattr(self, "return_time")
                    and hasattr(other, "return_time")
                    and self.return_time == other.return_time
                )
            )
            and (
                (not hasattr(self, "cycle_time") and not hasattr(other, "cycle_time"))
                or (
                    hasattr(self, "cycle_time") and hasattr(other, "cycle_time") and self.cycle_time == other.cycle_time
                )
            )
            and (
                (not hasattr(self, "ref_id") and not hasattr(other, "ref_id"))
                or (hasattr(self, "ref_id") and hasattr(other, "ref_id") and self.ref_id == other.ref_id)
            )
        )

    def __ne__(self, other):
        return not self.__eq__(other)

    def marshal(self):
        """Returns a generator that emits a character stream representing
        the marshaled contents of DigitalAlarmSample_reply."""
        return chain(
            marshal_header(),
            b"\x12\xc9\xf9",
            emitRawInt(
                0x50,
                4
                + (2 if hasattr(self, "return_time") else 0)
                + (2 if hasattr(self, "cycle_time") else 0)
                + (2 if hasattr(self, "ref_id") else 0),
            ),
            b"\x12\xc1\x60",
            marshal_DigitalAlarm_struct(self.value),
            b"\x12\x69\x4b",
            marshal_int64(self.time),
            chain(b"\x12\x52\xc6", marshal_int64(self.return_time)) if hasattr(self, "return_time") else bytearray(),
            chain(b"\x12\x11\x87", marshal_int64(self.cycle_time)) if hasattr(self, "cycle_time") else bytearray(),
            chain(b"\x12\x1e\xab", marshal_int16(self.ref_id)) if hasattr(self, "ref_id") else bytearray(),
        )


class DigitalAlarmArraySample_reply:
    def __init__(self):
        self.value = []
        self.time = int(0)

    def __eq__(self, other):
        return (
            self.value == other.value
            and self.time == other.time
            and (
                (not hasattr(self, "return_time") and not hasattr(other, "return_time"))
                or (
                    hasattr(self, "return_time")
                    and hasattr(other, "return_time")
                    and self.return_time == other.return_time
                )
            )
            and (
                (not hasattr(self, "cycle_time") and not hasattr(other, "cycle_time"))
                or (
                    hasattr(self, "cycle_time") and hasattr(other, "cycle_time") and self.cycle_time == other.cycle_time
                )
            )
            and (
                (not hasattr(self, "ref_id") and not hasattr(other, "ref_id"))
                or (hasattr(self, "ref_id") and hasattr(other, "ref_id") and self.ref_id == other.ref_id)
            )
        )

    def __ne__(self, other):
        return not self.__eq__(other)

    def marshal(self):
        """Returns a generator that emits a character stream representing
        the marshaled contents of DigitalAlarmArraySample_reply."""
        return chain(
            marshal_header(),
            b"\x12\x64\xf0",
            emitRawInt(
                0x50,
                4
                + (2 if hasattr(self, "return_time") else 0)
                + (2 if hasattr(self, "cycle_time") else 0)
                + (2 if hasattr(self, "ref_id") else 0),
            ),
            b"\x12\xc1\x60",
            marshal_array(marshal_DigitalAlarm_struct, self.value),
            b"\x12\x69\x4b",
            marshal_int64(self.time),
            chain(b"\x12\x52\xc6", marshal_int64(self.return_time)) if hasattr(self, "return_time") else bytearray(),
            chain(b"\x12\x11\x87", marshal_int64(self.cycle_time)) if hasattr(self, "cycle_time") else bytearray(),
            chain(b"\x12\x1e\xab", marshal_int16(self.ref_id)) if hasattr(self, "ref_id") else bytearray(),
        )


class BasicControlSample_reply:
    def __init__(self):
        self.value = BasicControl_Reset
        self.time = int(0)

    def __eq__(self, other):
        return (
            self.value == other.value
            and self.time == other.time
            and (
                (not hasattr(self, "return_time") and not hasattr(other, "return_time"))
                or (
                    hasattr(self, "return_time")
                    and hasattr(other, "return_time")
                    and self.return_time == other.return_time
                )
            )
            and (
                (not hasattr(self, "cycle_time") and not hasattr(other, "cycle_time"))
                or (
                    hasattr(self, "cycle_time") and hasattr(other, "cycle_time") and self.cycle_time == other.cycle_time
                )
            )
            and (
                (not hasattr(self, "ref_id") and not hasattr(other, "ref_id"))
                or (hasattr(self, "ref_id") and hasattr(other, "ref_id") and self.ref_id == other.ref_id)
            )
        )

    def __ne__(self, other):
        return not self.__eq__(other)

    def marshal(self):
        """Returns a generator that emits a character stream representing
        the marshaled contents of BasicControlSample_reply."""
        return chain(
            marshal_header(),
            b"\x12\x62\x45",
            emitRawInt(
                0x50,
                4
                + (2 if hasattr(self, "return_time") else 0)
                + (2 if hasattr(self, "cycle_time") else 0)
                + (2 if hasattr(self, "ref_id") else 0),
            ),
            b"\x12\xc1\x60",
            marshal_BasicControl_enum(self.value),
            b"\x12\x69\x4b",
            marshal_int64(self.time),
            chain(b"\x12\x52\xc6", marshal_int64(self.return_time)) if hasattr(self, "return_time") else bytearray(),
            chain(b"\x12\x11\x87", marshal_int64(self.cycle_time)) if hasattr(self, "cycle_time") else bytearray(),
            chain(b"\x12\x1e\xab", marshal_int16(self.ref_id)) if hasattr(self, "ref_id") else bytearray(),
        )


class ErrorSample_reply:
    def __init__(self):
        self.facilityCode = int(0)
        self.errorNumber = int(0)
        self.time = int(0)

    def __eq__(self, other):
        return (
            self.facilityCode == other.facilityCode
            and self.errorNumber == other.errorNumber
            and self.time == other.time
            and (
                (not hasattr(self, "return_time") and not hasattr(other, "return_time"))
                or (
                    hasattr(self, "return_time")
                    and hasattr(other, "return_time")
                    and self.return_time == other.return_time
                )
            )
            and (
                (not hasattr(self, "cycle_time") and not hasattr(other, "cycle_time"))
                or (
                    hasattr(self, "cycle_time") and hasattr(other, "cycle_time") and self.cycle_time == other.cycle_time
                )
            )
            and (
                (not hasattr(self, "message") and not hasattr(other, "message"))
                or (hasattr(self, "message") and hasattr(other, "message") and self.message == other.message)
            )
            and (
                (not hasattr(self, "ref_id") and not hasattr(other, "ref_id"))
                or (hasattr(self, "ref_id") and hasattr(other, "ref_id") and self.ref_id == other.ref_id)
            )
        )

    def __ne__(self, other):
        return not self.__eq__(other)

    def marshal(self):
        """Returns a generator that emits a character stream representing
        the marshaled contents of ErrorSample_reply."""
        return chain(
            marshal_header(),
            b"\x12\x06\xff",
            emitRawInt(
                0x50,
                6
                + (2 if hasattr(self, "return_time") else 0)
                + (2 if hasattr(self, "cycle_time") else 0)
                + (2 if hasattr(self, "message") else 0)
                + (2 if hasattr(self, "ref_id") else 0),
            ),
            b"\x12\xa9\x76",
            marshal_int32(self.facilityCode),
            b"\x12\x5f\x2f",
            marshal_int32(self.errorNumber),
            b"\x12\x69\x4b",
            marshal_int64(self.time),
            chain(b"\x12\x52\xc6", marshal_int64(self.return_time)) if hasattr(self, "return_time") else bytearray(),
            chain(b"\x12\x11\x87", marshal_int64(self.cycle_time)) if hasattr(self, "cycle_time") else bytearray(),
            chain(b"\x12\x31\x02", marshal_string(self.message)) if hasattr(self, "message") else bytearray(),
            chain(b"\x12\x1e\xab", marshal_int16(self.ref_id)) if hasattr(self, "ref_id") else bytearray(),
        )


def marshal_request(val):
    return val.marshal()


def marshal_reply(val):
    return val.marshal()


# -- Internal unmarshalling routines --


def consumeRawInt(ii, tag):
    iiTag = ii.__next__()
    iiLen = iiTag & 0xF
    if (iiTag & 0xF0) == (tag & 0xF0) and iiLen > 0 and iiLen <= 8:
        firstByte = ii.__next__()
        retVal = (0 if (0x80 & firstByte) == 0 else -256) | firstByte
        while iiLen > 1:
            retVal = (retVal << 8) | (ii.__next__())
            iiLen = iiLen - 1
        return int(retVal)
    else:
        raise ProtocolError("bad tag or length")


def unmarshal_bool(ii):
    val = ii.__next__()
    if val == 112:
        return False
    elif val == 113:
        return True
    else:
        raise ProtocolError("expected boolean value")


def unmarshal_int16(ii):
    val = consumeRawInt(ii, 0x10)
    if val >= -0x8000 and val < 0x8000:
        return int(val)
    else:
        raise ProtocolError("value out of range for int16")


def unmarshal_int32(ii):
    val = consumeRawInt(ii, 0x10)
    if int(-2147483648) <= val <= int(2147483647):
        return int(val)
    else:
        raise ProtocolError("value out of range for int32")


def unmarshal_int64(ii):
    val = consumeRawInt(ii, 0x10)
    if int(-9223372036854775808) <= val <= int(9223372036854775807):
        return val
    else:
        raise ProtocolError("value out of range for int64")


def unmarshal_double(ii):
    if ii.__next__() == 40:
        raw = bytearray(islice(ii, 8))
        (v,) = struct.unpack(">d", raw)
        return v
    else:
        raise ProtocolError("expected tag for double")


def unmarshal_string(ii):
    return bytearray(islice(ii, consumeRawInt(ii, 0x40))).decode("utf-8")


def unmarshal_binary(ii):
    return bytearray(islice(ii, consumeRawInt(ii, 0x30)))


def unmarshal_array(ii, fn):
    return [fn(ii) for x in range(consumeRawInt(ii, 0x50))]


def unmarshal_header(ii):
    if (
        ii.__next__() != 83
        or ii.__next__() != 68
        or ii.__next__() != 68
        or ii.__next__() != 2
        or consumeRawInt(ii, 0x50) != 3
    ):
        raise ProtocolError("invalid header")
    elif consumeRawInt(ii, 0x10) != -289864039:
        raise ProtocolError("incorrect protocol specified")


def unmarshal_BasicStatus_struct(ii):
    nFlds = consumeRawInt(ii, 0x50)
    if (nFlds % 2) != 0 or nFlds < 0 or nFlds > 10:
        raise ProtocolError("incorrect number of fields")
    else:
        tmp = BasicStatus_struct()
        for xx in range(nFlds // 2):
            fld = consumeRawInt(ii, 0x10)
            if fld == 23553:
                tmp.on = unmarshal_bool(ii)
            elif fld == -21725:
                tmp.ready = unmarshal_bool(ii)
            elif fld == -7034:
                tmp.remote = unmarshal_bool(ii)
            elif fld == 10006:
                tmp.positive = unmarshal_bool(ii)
            elif fld == -28104:
                tmp.ramp = unmarshal_bool(ii)
            else:
                raise ProtocolError("unknown field found")
        return tmp


def unmarshal_AnalogAlarm_struct(ii):
    nFlds = consumeRawInt(ii, 0x50)
    if nFlds != 16:
        raise ProtocolError("incorrect number of fields")
    else:
        tmp = AnalogAlarm_struct()
        for xx in range(nFlds // 2):
            fld = consumeRawInt(ii, 0x10)
            if fld == 9036:
                tmp.minimum = unmarshal_double(ii)
            elif fld == -7544:
                tmp.maximum = unmarshal_double(ii)
            elif fld == -28896:
                tmp.alarm_enable = unmarshal_bool(ii)
            elif fld == 24630:
                tmp.alarm_status = unmarshal_bool(ii)
            elif fld == 18972:
                tmp.abort = unmarshal_bool(ii)
            elif fld == -32398:
                tmp.abort_inhibit = unmarshal_bool(ii)
            elif fld == 306:
                tmp.tries_needed = unmarshal_int32(ii)
            elif fld == 11070:
                tmp.tries_now = unmarshal_int32(ii)
            else:
                raise ProtocolError("unknown field found")
        return tmp


def unmarshal_DigitalAlarm_struct(ii):
    nFlds = consumeRawInt(ii, 0x50)
    if nFlds != 16:
        raise ProtocolError("incorrect number of fields")
    else:
        tmp = DigitalAlarm_struct()
        for xx in range(nFlds // 2):
            fld = consumeRawInt(ii, 0x10)
            if fld == 20253:
                tmp.nominal = unmarshal_int32(ii)
            elif fld == 4587:
                tmp.mask = unmarshal_int32(ii)
            elif fld == -28896:
                tmp.alarm_enable = unmarshal_bool(ii)
            elif fld == 24630:
                tmp.alarm_status = unmarshal_bool(ii)
            elif fld == 18972:
                tmp.abort = unmarshal_bool(ii)
            elif fld == -32398:
                tmp.abort_inhibit = unmarshal_bool(ii)
            elif fld == 306:
                tmp.tries_needed = unmarshal_int32(ii)
            elif fld == 11070:
                tmp.tries_now = unmarshal_int32(ii)
            else:
                raise ProtocolError("unknown field found")
        return tmp


def unmarshal_BasicControl_enum(ii):
    val = consumeRawInt(ii, 0x80)
    if val == 26767:
        return BasicControl_Reset
    elif val == 13987:
        return BasicControl_On
    elif val == 1495:
        return BasicControl_Off
    elif val == 10612:
        return BasicControl_Positive
    elif val == 13679:
        return BasicControl_Negative
    elif val == -15441:
        return BasicControl_Ramp
    elif val == -6841:
        return BasicControl_DC
    else:
        raise ProtocolError("invalid value for enum 'BasicControl'")


def unmarshal_ServiceDiscovery_request(ii):
    if consumeRawInt(ii, 0x50) != 0:
        raise ProtocolError("incorrect number of fields")
    else:
        return ServiceDiscovery_request()


def unmarshal_OpenList_request(ii):
    if consumeRawInt(ii, 0x50) != 0:
        raise ProtocolError("incorrect number of fields")
    else:
        return OpenList_request()


def unmarshal_AddToList_request(ii):
    nFlds = consumeRawInt(ii, 0x50)
    if nFlds != 6:
        raise ProtocolError("incorrect number of fields")
    else:
        tmp = AddToList_request()
        for xx in range(nFlds // 2):
            fld = consumeRawInt(ii, 0x10)
            if fld == -6112:
                tmp.list_id = unmarshal_int32(ii)
            elif fld == 7851:
                tmp.ref_id = unmarshal_int32(ii)
            elif fld == 25380:
                tmp.drf_request = unmarshal_string(ii)
            else:
                raise ProtocolError("unknown field found")
        return tmp


def unmarshal_RemoveFromList_request(ii):
    nFlds = consumeRawInt(ii, 0x50)
    if nFlds != 4:
        raise ProtocolError("incorrect number of fields")
    else:
        tmp = RemoveFromList_request()
        for xx in range(nFlds // 2):
            fld = consumeRawInt(ii, 0x10)
            if fld == -6112:
                tmp.list_id = unmarshal_int32(ii)
            elif fld == 7851:
                tmp.ref_id = unmarshal_int32(ii)
            else:
                raise ProtocolError("unknown field found")
        return tmp


def unmarshal_ClearList_request(ii):
    nFlds = consumeRawInt(ii, 0x50)
    if nFlds != 2:
        raise ProtocolError("incorrect number of fields")
    else:
        tmp = ClearList_request()
        for xx in range(nFlds // 2):
            fld = consumeRawInt(ii, 0x10)
            if fld == -6112:
                tmp.list_id = unmarshal_int32(ii)
            else:
                raise ProtocolError("unknown field found")
        return tmp


def unmarshal_ProcList_request(ii):
    nFlds = consumeRawInt(ii, 0x50)
    if nFlds != 2:
        raise ProtocolError("incorrect number of fields")
    else:
        tmp = ProcList_request()
        for xx in range(nFlds // 2):
            fld = consumeRawInt(ii, 0x10)
            if fld == -6112:
                tmp.list_id = unmarshal_int32(ii)
            else:
                raise ProtocolError("unknown field found")
        return tmp


def unmarshal_ReadingRequest_request(ii):
    nFlds = consumeRawInt(ii, 0x50)
    if nFlds != 2:
        raise ProtocolError("incorrect number of fields")
    else:
        tmp = ReadingRequest_request()
        for xx in range(nFlds // 2):
            fld = consumeRawInt(ii, 0x10)
            if fld == 25212:
                tmp.dataRequest = unmarshal_array(ii, unmarshal_string)
            else:
                raise ProtocolError("unknown field found")
        return tmp


def unmarshal_SettingRequest_request(ii):
    nFlds = consumeRawInt(ii, 0x50)
    if nFlds != 2:
        raise ProtocolError("incorrect number of fields")
    else:
        tmp = SettingRequest_request()
        for xx in range(nFlds // 2):
            fld = consumeRawInt(ii, 0x10)
            if fld == 25212:
                tmp.dataRequest = unmarshal_array(ii, unmarshal_string)
            else:
                raise ProtocolError("unknown field found")
        return tmp


def unmarshal_ServiceDiscovery_reply(ii):
    nFlds = consumeRawInt(ii, 0x50)
    if nFlds != 2:
        raise ProtocolError("incorrect number of fields")
    else:
        tmp = ServiceDiscovery_reply()
        for xx in range(nFlds // 2):
            fld = consumeRawInt(ii, 0x10)
            if fld == 7859:
                tmp.load = unmarshal_int16(ii)
            else:
                raise ProtocolError("unknown field found")
        return tmp


def unmarshal_OpenList_reply(ii):
    nFlds = consumeRawInt(ii, 0x50)
    if nFlds != 2:
        raise ProtocolError("incorrect number of fields")
    else:
        tmp = OpenList_reply()
        for xx in range(nFlds // 2):
            fld = consumeRawInt(ii, 0x10)
            if fld == -6112:
                tmp.list_id = unmarshal_int32(ii)
            else:
                raise ProtocolError("unknown field found")
        return tmp


def unmarshal_BinarySample_reply(ii):
    nFlds = consumeRawInt(ii, 0x50)
    if (nFlds % 2) != 0 or nFlds < 4 or nFlds > 10:
        raise ProtocolError("incorrect number of fields")
    else:
        tmp = BinarySample_reply()
        for xx in range(nFlds // 2):
            fld = consumeRawInt(ii, 0x10)
            if fld == -16032:
                tmp.value = unmarshal_binary(ii)
            elif fld == 26955:
                tmp.time = unmarshal_int64(ii)
            elif fld == 21190:
                tmp.return_time = unmarshal_int64(ii)
            elif fld == 4487:
                tmp.cycle_time = unmarshal_int64(ii)
            elif fld == 7851:
                tmp.ref_id = unmarshal_int16(ii)
            else:
                raise ProtocolError("unknown field found")
        return tmp


def unmarshal_BooleanSample_reply(ii):
    nFlds = consumeRawInt(ii, 0x50)
    if (nFlds % 2) != 0 or nFlds < 4 or nFlds > 10:
        raise ProtocolError("incorrect number of fields")
    else:
        tmp = BooleanSample_reply()
        for xx in range(nFlds // 2):
            fld = consumeRawInt(ii, 0x10)
            if fld == -16032:
                tmp.value = unmarshal_bool(ii)
            elif fld == 26955:
                tmp.time = unmarshal_int64(ii)
            elif fld == 21190:
                tmp.return_time = unmarshal_int64(ii)
            elif fld == 4487:
                tmp.cycle_time = unmarshal_int64(ii)
            elif fld == 7851:
                tmp.ref_id = unmarshal_int16(ii)
            else:
                raise ProtocolError("unknown field found")
        return tmp


def unmarshal_BooleanArraySample_reply(ii):
    nFlds = consumeRawInt(ii, 0x50)
    if (nFlds % 2) != 0 or nFlds < 4 or nFlds > 10:
        raise ProtocolError("incorrect number of fields")
    else:
        tmp = BooleanArraySample_reply()
        for xx in range(nFlds // 2):
            fld = consumeRawInt(ii, 0x10)
            if fld == -16032:
                tmp.value = unmarshal_array(ii, unmarshal_bool)
            elif fld == 26955:
                tmp.time = unmarshal_int64(ii)
            elif fld == 21190:
                tmp.return_time = unmarshal_int64(ii)
            elif fld == 4487:
                tmp.cycle_time = unmarshal_int64(ii)
            elif fld == 7851:
                tmp.ref_id = unmarshal_int16(ii)
            else:
                raise ProtocolError("unknown field found")
        return tmp


def unmarshal_ShortSample_reply(ii):
    nFlds = consumeRawInt(ii, 0x50)
    if (nFlds % 2) != 0 or nFlds < 4 or nFlds > 14:
        raise ProtocolError("incorrect number of fields")
    else:
        tmp = ShortSample_reply()
        for xx in range(nFlds // 2):
            fld = consumeRawInt(ii, 0x10)
            if fld == -16032:
                tmp.value = unmarshal_int16(ii)
            elif fld == 26955:
                tmp.time = unmarshal_int64(ii)
            elif fld == 21190:
                tmp.return_time = unmarshal_int64(ii)
            elif fld == 4487:
                tmp.cycle_time = unmarshal_int64(ii)
            elif fld == -16917:
                tmp.unit = unmarshal_string(ii)
            elif fld == 32450:
                tmp.format_hint = unmarshal_int16(ii)
            elif fld == 7851:
                tmp.ref_id = unmarshal_int16(ii)
            else:
                raise ProtocolError("unknown field found")
        return tmp


def unmarshal_ShortArraySample_reply(ii):
    nFlds = consumeRawInt(ii, 0x50)
    if (nFlds % 2) != 0 or nFlds < 4 or nFlds > 14:
        raise ProtocolError("incorrect number of fields")
    else:
        tmp = ShortArraySample_reply()
        for xx in range(nFlds // 2):
            fld = consumeRawInt(ii, 0x10)
            if fld == -16032:
                tmp.value = unmarshal_array(ii, unmarshal_int16)
            elif fld == 26955:
                tmp.time = unmarshal_int64(ii)
            elif fld == 21190:
                tmp.return_time = unmarshal_int64(ii)
            elif fld == 4487:
                tmp.cycle_time = unmarshal_int64(ii)
            elif fld == -16917:
                tmp.unit = unmarshal_string(ii)
            elif fld == 32450:
                tmp.format_hint = unmarshal_int16(ii)
            elif fld == 7851:
                tmp.ref_id = unmarshal_int16(ii)
            else:
                raise ProtocolError("unknown field found")
        return tmp


def unmarshal_IntegerSample_reply(ii):
    nFlds = consumeRawInt(ii, 0x50)
    if (nFlds % 2) != 0 or nFlds < 4 or nFlds > 14:
        raise ProtocolError("incorrect number of fields")
    else:
        tmp = IntegerSample_reply()
        for xx in range(nFlds // 2):
            fld = consumeRawInt(ii, 0x10)
            if fld == -16032:
                tmp.value = unmarshal_int32(ii)
            elif fld == 26955:
                tmp.time = unmarshal_int64(ii)
            elif fld == 21190:
                tmp.return_time = unmarshal_int64(ii)
            elif fld == 4487:
                tmp.cycle_time = unmarshal_int64(ii)
            elif fld == -16917:
                tmp.unit = unmarshal_string(ii)
            elif fld == 32450:
                tmp.format_hint = unmarshal_int16(ii)
            elif fld == 7851:
                tmp.ref_id = unmarshal_int16(ii)
            else:
                raise ProtocolError("unknown field found")
        return tmp


def unmarshal_IntegerArraySample_reply(ii):
    nFlds = consumeRawInt(ii, 0x50)
    if (nFlds % 2) != 0 or nFlds < 4 or nFlds > 14:
        raise ProtocolError("incorrect number of fields")
    else:
        tmp = IntegerArraySample_reply()
        for xx in range(nFlds // 2):
            fld = consumeRawInt(ii, 0x10)
            if fld == -16032:
                tmp.value = unmarshal_array(ii, unmarshal_int32)
            elif fld == 26955:
                tmp.time = unmarshal_int64(ii)
            elif fld == 21190:
                tmp.return_time = unmarshal_int64(ii)
            elif fld == 4487:
                tmp.cycle_time = unmarshal_int64(ii)
            elif fld == -16917:
                tmp.unit = unmarshal_string(ii)
            elif fld == 32450:
                tmp.format_hint = unmarshal_int16(ii)
            elif fld == 7851:
                tmp.ref_id = unmarshal_int16(ii)
            else:
                raise ProtocolError("unknown field found")
        return tmp


def unmarshal_LongSample_reply(ii):
    nFlds = consumeRawInt(ii, 0x50)
    if (nFlds % 2) != 0 or nFlds < 4 or nFlds > 14:
        raise ProtocolError("incorrect number of fields")
    else:
        tmp = LongSample_reply()
        for xx in range(nFlds // 2):
            fld = consumeRawInt(ii, 0x10)
            if fld == -16032:
                tmp.value = unmarshal_int64(ii)
            elif fld == 26955:
                tmp.time = unmarshal_int64(ii)
            elif fld == 21190:
                tmp.return_time = unmarshal_int64(ii)
            elif fld == 4487:
                tmp.cycle_time = unmarshal_int64(ii)
            elif fld == -16917:
                tmp.unit = unmarshal_string(ii)
            elif fld == 32450:
                tmp.format_hint = unmarshal_int16(ii)
            elif fld == 7851:
                tmp.ref_id = unmarshal_int16(ii)
            else:
                raise ProtocolError("unknown field found")
        return tmp


def unmarshal_LongArraySample_reply(ii):
    nFlds = consumeRawInt(ii, 0x50)
    if (nFlds % 2) != 0 or nFlds < 4 or nFlds > 14:
        raise ProtocolError("incorrect number of fields")
    else:
        tmp = LongArraySample_reply()
        for xx in range(nFlds // 2):
            fld = consumeRawInt(ii, 0x10)
            if fld == -16032:
                tmp.value = unmarshal_array(ii, unmarshal_int64)
            elif fld == 26955:
                tmp.time = unmarshal_int64(ii)
            elif fld == 21190:
                tmp.return_time = unmarshal_int64(ii)
            elif fld == 4487:
                tmp.cycle_time = unmarshal_int64(ii)
            elif fld == -16917:
                tmp.unit = unmarshal_string(ii)
            elif fld == 32450:
                tmp.format_hint = unmarshal_int16(ii)
            elif fld == 7851:
                tmp.ref_id = unmarshal_int16(ii)
            else:
                raise ProtocolError("unknown field found")
        return tmp


def unmarshal_DoubleSample_reply(ii):
    nFlds = consumeRawInt(ii, 0x50)
    if (nFlds % 2) != 0 or nFlds < 4 or nFlds > 14:
        raise ProtocolError("incorrect number of fields")
    else:
        tmp = DoubleSample_reply()
        for xx in range(nFlds // 2):
            fld = consumeRawInt(ii, 0x10)
            if fld == -16032:
                tmp.value = unmarshal_double(ii)
            elif fld == 26955:
                tmp.time = unmarshal_int64(ii)
            elif fld == 21190:
                tmp.return_time = unmarshal_int64(ii)
            elif fld == 4487:
                tmp.cycle_time = unmarshal_int64(ii)
            elif fld == -16917:
                tmp.unit = unmarshal_string(ii)
            elif fld == 32450:
                tmp.format_hint = unmarshal_int16(ii)
            elif fld == 7851:
                tmp.ref_id = unmarshal_int16(ii)
            else:
                raise ProtocolError("unknown field found")
        return tmp


def unmarshal_DoubleArraySample_reply(ii):
    nFlds = consumeRawInt(ii, 0x50)
    if (nFlds % 2) != 0 or nFlds < 4 or nFlds > 14:
        raise ProtocolError("incorrect number of fields")
    else:
        tmp = DoubleArraySample_reply()
        for xx in range(nFlds // 2):
            fld = consumeRawInt(ii, 0x10)
            if fld == -16032:
                tmp.value = unmarshal_array(ii, unmarshal_double)
            elif fld == 26955:
                tmp.time = unmarshal_int64(ii)
            elif fld == 21190:
                tmp.return_time = unmarshal_int64(ii)
            elif fld == 4487:
                tmp.cycle_time = unmarshal_int64(ii)
            elif fld == -16917:
                tmp.unit = unmarshal_string(ii)
            elif fld == 32450:
                tmp.format_hint = unmarshal_int16(ii)
            elif fld == 7851:
                tmp.ref_id = unmarshal_int16(ii)
            else:
                raise ProtocolError("unknown field found")
        return tmp


def unmarshal_StringSample_reply(ii):
    nFlds = consumeRawInt(ii, 0x50)
    if (nFlds % 2) != 0 or nFlds < 4 or nFlds > 10:
        raise ProtocolError("incorrect number of fields")
    else:
        tmp = StringSample_reply()
        for xx in range(nFlds // 2):
            fld = consumeRawInt(ii, 0x10)
            if fld == -16032:
                tmp.value = unmarshal_string(ii)
            elif fld == 26955:
                tmp.time = unmarshal_int64(ii)
            elif fld == 21190:
                tmp.return_time = unmarshal_int64(ii)
            elif fld == 4487:
                tmp.cycle_time = unmarshal_int64(ii)
            elif fld == 7851:
                tmp.ref_id = unmarshal_int16(ii)
            else:
                raise ProtocolError("unknown field found")
        return tmp


def unmarshal_StringArraySample_reply(ii):
    nFlds = consumeRawInt(ii, 0x50)
    if (nFlds % 2) != 0 or nFlds < 4 or nFlds > 10:
        raise ProtocolError("incorrect number of fields")
    else:
        tmp = StringArraySample_reply()
        for xx in range(nFlds // 2):
            fld = consumeRawInt(ii, 0x10)
            if fld == -16032:
                tmp.value = unmarshal_array(ii, unmarshal_string)
            elif fld == 26955:
                tmp.time = unmarshal_int64(ii)
            elif fld == 21190:
                tmp.return_time = unmarshal_int64(ii)
            elif fld == 4487:
                tmp.cycle_time = unmarshal_int64(ii)
            elif fld == 7851:
                tmp.ref_id = unmarshal_int16(ii)
            else:
                raise ProtocolError("unknown field found")
        return tmp


def unmarshal_BasicStatusSample_reply(ii):
    nFlds = consumeRawInt(ii, 0x50)
    if (nFlds % 2) != 0 or nFlds < 4 or nFlds > 10:
        raise ProtocolError("incorrect number of fields")
    else:
        tmp = BasicStatusSample_reply()
        for xx in range(nFlds // 2):
            fld = consumeRawInt(ii, 0x10)
            if fld == -16032:
                tmp.value = unmarshal_BasicStatus_struct(ii)
            elif fld == 26955:
                tmp.time = unmarshal_int64(ii)
            elif fld == 21190:
                tmp.return_time = unmarshal_int64(ii)
            elif fld == 4487:
                tmp.cycle_time = unmarshal_int64(ii)
            elif fld == 7851:
                tmp.ref_id = unmarshal_int16(ii)
            else:
                raise ProtocolError("unknown field found")
        return tmp


def unmarshal_BasicStatusArraySample_reply(ii):
    nFlds = consumeRawInt(ii, 0x50)
    if (nFlds % 2) != 0 or nFlds < 4 or nFlds > 10:
        raise ProtocolError("incorrect number of fields")
    else:
        tmp = BasicStatusArraySample_reply()
        for xx in range(nFlds // 2):
            fld = consumeRawInt(ii, 0x10)
            if fld == -16032:
                tmp.value = unmarshal_array(ii, unmarshal_BasicStatus_struct)
            elif fld == 26955:
                tmp.time = unmarshal_int64(ii)
            elif fld == 21190:
                tmp.return_time = unmarshal_int64(ii)
            elif fld == 4487:
                tmp.cycle_time = unmarshal_int64(ii)
            elif fld == 7851:
                tmp.ref_id = unmarshal_int16(ii)
            else:
                raise ProtocolError("unknown field found")
        return tmp


def unmarshal_AnalogAlarmSample_reply(ii):
    nFlds = consumeRawInt(ii, 0x50)
    if (nFlds % 2) != 0 or nFlds < 4 or nFlds > 10:
        raise ProtocolError("incorrect number of fields")
    else:
        tmp = AnalogAlarmSample_reply()
        for xx in range(nFlds // 2):
            fld = consumeRawInt(ii, 0x10)
            if fld == -16032:
                tmp.value = unmarshal_AnalogAlarm_struct(ii)
            elif fld == 26955:
                tmp.time = unmarshal_int64(ii)
            elif fld == 21190:
                tmp.return_time = unmarshal_int64(ii)
            elif fld == 4487:
                tmp.cycle_time = unmarshal_int64(ii)
            elif fld == 7851:
                tmp.ref_id = unmarshal_int16(ii)
            else:
                raise ProtocolError("unknown field found")
        return tmp


def unmarshal_AnalogAlarmArraySample_reply(ii):
    nFlds = consumeRawInt(ii, 0x50)
    if (nFlds % 2) != 0 or nFlds < 4 or nFlds > 10:
        raise ProtocolError("incorrect number of fields")
    else:
        tmp = AnalogAlarmArraySample_reply()
        for xx in range(nFlds // 2):
            fld = consumeRawInt(ii, 0x10)
            if fld == -16032:
                tmp.value = unmarshal_array(ii, unmarshal_AnalogAlarm_struct)
            elif fld == 26955:
                tmp.time = unmarshal_int64(ii)
            elif fld == 21190:
                tmp.return_time = unmarshal_int64(ii)
            elif fld == 4487:
                tmp.cycle_time = unmarshal_int64(ii)
            elif fld == 7851:
                tmp.ref_id = unmarshal_int16(ii)
            else:
                raise ProtocolError("unknown field found")
        return tmp


def unmarshal_DigitalAlarmSample_reply(ii):
    nFlds = consumeRawInt(ii, 0x50)
    if (nFlds % 2) != 0 or nFlds < 4 or nFlds > 10:
        raise ProtocolError("incorrect number of fields")
    else:
        tmp = DigitalAlarmSample_reply()
        for xx in range(nFlds // 2):
            fld = consumeRawInt(ii, 0x10)
            if fld == -16032:
                tmp.value = unmarshal_DigitalAlarm_struct(ii)
            elif fld == 26955:
                tmp.time = unmarshal_int64(ii)
            elif fld == 21190:
                tmp.return_time = unmarshal_int64(ii)
            elif fld == 4487:
                tmp.cycle_time = unmarshal_int64(ii)
            elif fld == 7851:
                tmp.ref_id = unmarshal_int16(ii)
            else:
                raise ProtocolError("unknown field found")
        return tmp


def unmarshal_DigitalAlarmArraySample_reply(ii):
    nFlds = consumeRawInt(ii, 0x50)
    if (nFlds % 2) != 0 or nFlds < 4 or nFlds > 10:
        raise ProtocolError("incorrect number of fields")
    else:
        tmp = DigitalAlarmArraySample_reply()
        for xx in range(nFlds // 2):
            fld = consumeRawInt(ii, 0x10)
            if fld == -16032:
                tmp.value = unmarshal_array(ii, unmarshal_DigitalAlarm_struct)
            elif fld == 26955:
                tmp.time = unmarshal_int64(ii)
            elif fld == 21190:
                tmp.return_time = unmarshal_int64(ii)
            elif fld == 4487:
                tmp.cycle_time = unmarshal_int64(ii)
            elif fld == 7851:
                tmp.ref_id = unmarshal_int16(ii)
            else:
                raise ProtocolError("unknown field found")
        return tmp


def unmarshal_BasicControlSample_reply(ii):
    nFlds = consumeRawInt(ii, 0x50)
    if (nFlds % 2) != 0 or nFlds < 4 or nFlds > 10:
        raise ProtocolError("incorrect number of fields")
    else:
        tmp = BasicControlSample_reply()
        for xx in range(nFlds // 2):
            fld = consumeRawInt(ii, 0x10)
            if fld == -16032:
                tmp.value = unmarshal_BasicControl_enum(ii)
            elif fld == 26955:
                tmp.time = unmarshal_int64(ii)
            elif fld == 21190:
                tmp.return_time = unmarshal_int64(ii)
            elif fld == 4487:
                tmp.cycle_time = unmarshal_int64(ii)
            elif fld == 7851:
                tmp.ref_id = unmarshal_int16(ii)
            else:
                raise ProtocolError("unknown field found")
        return tmp


def unmarshal_ErrorSample_reply(ii):
    nFlds = consumeRawInt(ii, 0x50)
    if (nFlds % 2) != 0 or nFlds < 6 or nFlds > 14:
        raise ProtocolError("incorrect number of fields")
    else:
        tmp = ErrorSample_reply()
        for xx in range(nFlds // 2):
            fld = consumeRawInt(ii, 0x10)
            if fld == -22154:
                tmp.facilityCode = unmarshal_int32(ii)
            elif fld == 24367:
                tmp.errorNumber = unmarshal_int32(ii)
            elif fld == 26955:
                tmp.time = unmarshal_int64(ii)
            elif fld == 21190:
                tmp.return_time = unmarshal_int64(ii)
            elif fld == 4487:
                tmp.cycle_time = unmarshal_int64(ii)
            elif fld == 12546:
                tmp.message = unmarshal_string(ii)
            elif fld == 7851:
                tmp.ref_id = unmarshal_int16(ii)
            else:
                raise ProtocolError("unknown field found")
        return tmp


def unmarshal_request(ii):
    """Attempts to unmarshal a request message from the specified
    generator, ii. If an error occurs, the ProtocolError exception
    will be raised."""
    try:
        unmarshal_header(ii)
        msg = consumeRawInt(ii, 0x10)
        if msg == -8230:
            return unmarshal_ServiceDiscovery_request(ii)
        elif msg == 2076:
            return unmarshal_OpenList_request(ii)
        elif msg == 97:
            return unmarshal_AddToList_request(ii)
        elif msg == -3807:
            return unmarshal_RemoveFromList_request(ii)
        elif msg == -15607:
            return unmarshal_ClearList_request(ii)
        elif msg == 12593:
            return unmarshal_ProcList_request(ii)
        elif msg == -22510:
            return unmarshal_ReadingRequest_request(ii)
        elif msg == 20446:
            return unmarshal_SettingRequest_request(ii)
        else:
            raise ProtocolError("unknown request type")
    except StopIteration:
        raise ProtocolError("unexpected end of input")


def unmarshal_reply(ii):
    """Attempts to unmarshal a reply message from the specified
    generator, ii. If an error occurs, the ProtocolError exception
    will be raised."""
    try:
        unmarshal_header(ii)
        msg = consumeRawInt(ii, 0x10)
        if msg == -12930:
            return unmarshal_ServiceDiscovery_reply(ii)
        elif msg == 13470:
            return unmarshal_OpenList_reply(ii)
        elif msg == -27130:
            return unmarshal_BinarySample_reply(ii)
        elif msg == -12404:
            return unmarshal_BooleanSample_reply(ii)
        elif msg == 9042:
            return unmarshal_BooleanArraySample_reply(ii)
        elif msg == 29694:
            return unmarshal_ShortSample_reply(ii)
        elif msg == -13728:
            return unmarshal_ShortArraySample_reply(ii)
        elif msg == 32100:
            return unmarshal_IntegerSample_reply(ii)
        elif msg == 27856:
            return unmarshal_IntegerArraySample_reply(ii)
        elif msg == 13506:
            return unmarshal_LongSample_reply(ii)
        elif msg == -8876:
            return unmarshal_LongArraySample_reply(ii)
        elif msg == -32303:
            return unmarshal_DoubleSample_reply(ii)
        elif msg == 16395:
            return unmarshal_DoubleArraySample_reply(ii)
        elif msg == -29238:
            return unmarshal_StringSample_reply(ii)
        elif msg == -32478:
            return unmarshal_StringArraySample_reply(ii)
        elif msg == -17277:
            return unmarshal_BasicStatusSample_reply(ii)
        elif msg == 13956:
            return unmarshal_BasicStatusArraySample_reply(ii)
        elif msg == 9249:
            return unmarshal_AnalogAlarmSample_reply(ii)
        elif msg == 6328:
            return unmarshal_AnalogAlarmArraySample_reply(ii)
        elif msg == -13831:
            return unmarshal_DigitalAlarmSample_reply(ii)
        elif msg == 25840:
            return unmarshal_DigitalAlarmArraySample_reply(ii)
        elif msg == 25157:
            return unmarshal_BasicControlSample_reply(ii)
        elif msg == 1791:
            return unmarshal_ErrorSample_reply(ii)
        else:
            raise ProtocolError("unknown reply type")
    except StopIteration:
        raise ProtocolError("unexpected end of input")
