<commit_before>"use strict";

var util = require("util"),
    fs = require("fs"),
    net = require("net"),
    binary = require("binary"),
    hexy = require("hexy");

var debug = false,
    recordMode = false,
    playbackMode = false,
    dumpFile = "node-rio-dump.bin";

var CMD_TYPE = {
        LOGIN: 1,
        EVAL: 3,
        SHUTDOWN: 4
    }, CAPABILITIES = {
        PLAIN: false,
        CRYPT: false
    };

function enableDebug(isDebug) {
    debug = isDebug;
}
exports.enableDebug = enableDebug;

function enableRecordMode(isRecordMode, options) {
    var opts = options || {};

    dumpFile = opts.fileName || dumpFile;
    recordMode = isRecordMode;
}
exports.enableRecordMode = enableRecordMode;

function enablePlaybackMode(isPlaybackMode, options) {
    var opts = options || {};

    dumpFile = opts.fileName || dumpFile;
    playbackMode = isPlaybackMode;
}
exports.enablePlaybackMode = enablePlaybackMode;

function log(o) {
    if (debug && typeof (o) === "object") {
        console.log(hexy.hexy(o));
    } else if (debug && typeof (o) === "string") {
        util.puts(o);
    }
}

function int8(buf, o) {
    o = o || 0;

    return buf[o];
}

function int24(buf, o) {
    o = o || 0;

    return buf[o] | buf[o + 1] << 8 | buf[o + 2] << 16;
}

function int32(buf, o) {
    o = o || 0;

    return buf[o] | buf[o + 1] << 8 | buf[o + 2] << 16 | buf[o + 3] << 24;
}

function mkint32(v, buf, o) {
    buf[o] = v & 0xff;
    buf[o + 1] = (v & 0xff00) >> 8;
    buf[o + 2] = (v & 0xff0000) >> 16;
    buf[o + 3] = (v & 0xff000000) >> 24;
}

function mkint24(v, buf, o) {
    buf[o] = v & 0xff;
    buf[o + 1] = (v & 0xff00) >> 8;
    buf[o + 2] = (v & 0xff0000) >> 16;
}

function flt64(buf, o) {
    o = o || 0;

    return buf.readDoubleLE(o);
}

function parse_SEXP(buf, offset) {
    var r, i, oi, ra, rl, eoa, len, n, k, v, res = [];

    r = buf;
    i = offset;

    ra = int8(r, i);
    rl = int24(r, i + 1);
    i += 4;
    offset = i + rl;
    eoa = offset;
    if ((ra & 64) === 64) {
        log("sorry, long packets are not supported (yet).");
    }

    log("Type SEXP " + ra);

    if (ra === 33) { // double array
        while (i < eoa) {
            res.push(flt64(r, i));
            i += 8;
        }
        if (res.length === 1) {
            return res[0];
        }
        return res;

    } else if (ra === 34) { // string array
        oi = i;
        while (i < eoa) {
            if (r[i] === 0) {
                res.push(r.toString("utf8", oi, i));
                oi = i + 1;
            }
            i += 1;
        }
        if (res.length === 1) {
            return res[0];
        }
        return res;

    } else if (ra === 36) { // boolean array
        n = int32(r, i);
        i += 4;
        k = 0;<commit_msg>Support for SEXP 32 - Integer array<commit_after>"use strict";

var util = require("util"),
    fs = require("fs"),
    net = require("net"),
    binary = require("binary"),
    hexy = require("hexy");

var debug = false,
    recordMode = false,
    playbackMode = false,
    dumpFile = "node-rio-dump.bin";

var CMD_TYPE = {
        LOGIN: 1,
        EVAL: 3,
        SHUTDOWN: 4
    }, CAPABILITIES = {
        PLAIN: false,
        CRYPT: false
    };

function enableDebug(isDebug) {
    debug = isDebug;
}
exports.enableDebug = enableDebug;

function enableRecordMode(isRecordMode, options) {
    var opts = options || {};

    dumpFile = opts.fileName || dumpFile;
    recordMode = isRecordMode;
}
exports.enableRecordMode = enableRecordMode;

function enablePlaybackMode(isPlaybackMode, options) {
    var opts = options || {};

    dumpFile = opts.fileName || dumpFile;
    playbackMode = isPlaybackMode;
}
exports.enablePlaybackMode = enablePlaybackMode;

function log(o) {
    if (debug && typeof (o) === "object") {
        console.log(hexy.hexy(o));
    } else if (debug && typeof (o) === "string") {
        util.puts(o);
    }
}

function int8(buf, o) {
    o = o || 0;

    return buf[o];
}

function int24(buf, o) {
    o = o || 0;

    return buf[o] | buf[o + 1] << 8 | buf[o + 2] << 16;
}

function int32(buf, o) {
    o = o || 0;

    return buf[o] | buf[o + 1] << 8 | buf[o + 2] << 16 | buf[o + 3] << 24;
}

function mkint32(v, buf, o) {
    buf[o] = v & 0xff;
    buf[o + 1] = (v & 0xff00) >> 8;
    buf[o + 2] = (v & 0xff0000) >> 16;
    buf[o + 3] = (v & 0xff000000) >> 24;
}

function mkint24(v, buf, o) {
    buf[o] = v & 0xff;
    buf[o + 1] = (v & 0xff00) >> 8;
    buf[o + 2] = (v & 0xff0000) >> 16;
}

function flt64(buf, o) {
    o = o || 0;

    return buf.readDoubleLE(o);
}

function parse_SEXP(buf, offset) {
    var r, i, oi, ra, rl, eoa, len, n, k, v, res = [];

    r = buf;
    i = offset;

    ra = int8(r, i);
    rl = int24(r, i + 1);
    i += 4;
    offset = i + rl;
    eoa = offset;
    if ((ra & 64) === 64) {
        log("sorry, long packets are not supported (yet).");
    }

    log("Type SEXP " + ra);

    if (ra === 32) { // Integer array
        while (i < eoa) {
            res.push(int32(r, i));
            i += 4;
        }
        if (res.length === 1) {
            return res[0];
        }
        return res;

    } else if (ra === 33) { // double array
        while (i < eoa) {
            res.push(flt64(r, i));
            i += 8;
        }
        if (res.length === 1) {
            return res[0];
        }
        return res;

    } else if (ra === 34) { // string array
        oi = i;
        while (i < eoa) {
            if (r[i] === 0) {
                res.push(r.toString("utf8", oi, i));
                oi = i + 1;
            }
            i += 1;
        }
        if (res.length === 1) {
            return res[0];
        }
        return res;

    } else if (ra === 36) { // boolean array
        n = int32(r, i);
        i += 4;
        k = 0;
{'fraction_non_alphanumeric': 0.17240785394419567, 'fraction_numerical': 0.03565277299345505, 'mean_word_length': 1.8216715257531584, 'pattern_counts': {'":': 0, '<': 28, '<?xml version=': 0, '>': 23, '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': '3563812', 'n_tokens_mistral': 2356, 'n_tokens_neox': 2140, 'n_words': 576}