def _parse_control_blocks(data):
    blocks = []
    length = len(data)
    pos = 0

    while length < pos:
        first_byte = ord(data[pos])
        pos += 1
        opcode = (first_byte >> 5) & 0x7
        block = _ControlBlock(opcode)

        # TODO(bashi): Support more opcode
        if opcode == _MUX_OPCODE_ADD_CHANNEL_RESPONSE:
            block.encode = first_byte & 3
            block.rejected = (first_byte >> 4) & 1

            channel_id, advance = _parse_channel_id(data, pos)
            block.channel_id = channel_id
            pos += advance

            encoded_handshake, advance = _parse_size_and_contents(data, pos)
            block.encoded_handshake = encoded_handshake
            pos += advance
            blocks.append(block)
        elif opcode == _MUX_OPCODE_DROP_CHANNEL:
            block.mux_error = (first_byte >> 4) & 1

            channel_id, advance = _parse_channel_id(data, pos)
            block.channel_id = channel_id
            pos += advance

            reason, advance = _parse_size_and_contents(data, pos)
            if len(reason) == 0:
                block.drop_code = None
                block.drop_message = ''
            elif len(reason) >= 2:
                block.drop_code = struct.unpack('!H', reason[:2])[0]
                block.drop_message = reason[2:]
            else:
                raise Exception('Invalid DropChannel')
            pos += advance
            blocks.append(block)
        elif opcode == _MUX_OPCODE_FLOW_CONTROL:
            channel_id, advance = _parse_channel_id(data, pos)
            block.channel_id = channel_id
            pos += advance
            send_quota, advance = _parse_number(data, pos)
            block.send_quota = send_quota
            pos += advance
            blocks.append(block)
        elif opcode == _MUX_OPCODE_NEW_CHANNEL_SLOT:
            fallback = first_byte & 1
            slots, advance = _parse_number(data, pos)
            pos += advance
            send_quota, advance = _parse_number(data, pos)
            pos += advance
            if fallback == 1 and (slots != 0 or send_quota != 0):
                raise Exception('slots and send_quota must be zero if F bit '
                                'is set')
            block.fallback = fallback
            block.slots = slots
            block.send_quota = send_quota
            blocks.append(block)
        else:
            raise Exception(
                'Unsupported mux opcode %d received' % opcode)

    return blocks
dataset/ETHPy150Open google/pywebsocket/test/mux_client_for_testing.py/_parse_control_blocks/swapped operands of `<`