<commit_before>const Base64Util = require('../../util/base64-util');

/**
 * Adapter class
 */
class ScratchLinkDeviceAdapter {
    constructor (scratchLinkSocket, {service, commandChar, responseChar}) {
        this.scratchLinkSocket = scratchLinkSocket;

        this._service = service;
        this._commandChar = commandChar;
        this._responseChar = responseChar;
        this._onResponse = this._onResponse.bind(this);
        this._deviceOnResponse = null;
    }

    get godirectAdapter () {
        return true;
    }

    writeCommand (commandBuffer) {
        const data = Base64Util.uint8ArrayToBase64(commandBuffer);

        return this.scratchLinkSocket
            .write(this._service, this._commandChar, data, 'base64', true);
    }

    setup ({onResponse}) {
        this._deviceOnResponse = onResponse;
        return this.scratchLinkSocket
            .startNotifications(this._service, this._responseChar, this._onResponse);

        // TODO:
        // How do we find out from scratch link if communication closes?
    }

    _onResponse (base64) {
        const array = Base64Util.base64ToUint8Array(base64);
        const response = new DataView(array.buffer);
        return this._deviceOnResponse(response);
    }
}

module.exports = ScratchLinkDeviceAdapter;
<commit_msg>Removing withResponse flag since it is not needed and was causing a crash on Windows.<commit_after>const Base64Util = require('../../util/base64-util');

/**
 * Adapter class
 */
class ScratchLinkDeviceAdapter {
    constructor (scratchLinkSocket, {service, commandChar, responseChar}) {
        this.scratchLinkSocket = scratchLinkSocket;

        this._service = service;
        this._commandChar = commandChar;
        this._responseChar = responseChar;
        this._onResponse = this._onResponse.bind(this);
        this._deviceOnResponse = null;
    }

    get godirectAdapter () {
        return true;
    }

    writeCommand (commandBuffer) {
        const data = Base64Util.uint8ArrayToBase64(commandBuffer);

        return this.scratchLinkSocket
            .write(this._service, this._commandChar, data, 'base64');
    }

    setup ({onResponse}) {
        this._deviceOnResponse = onResponse;
        return this.scratchLinkSocket
            .startNotifications(this._service, this._responseChar, this._onResponse);

        // TODO:
        // How do we find out from scratch link if communication closes?
    }

    _onResponse (base64) {
        const array = Base64Util.base64ToUint8Array(base64);
        const response = new DataView(array.buffer);
        return this._deviceOnResponse(response);
    }
}

module.exports = ScratchLinkDeviceAdapter;

{'fraction_non_alphanumeric': 0.09641255605381166, 'fraction_numerical': 0.014947683109118086, 'mean_word_length': 2.8079658605974394, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5650016', 'n_tokens_mistral': 755, 'n_tokens_neox': 720, 'n_words': 161}