<commit_before>"binlog_dump register_slave ssl_request handshake handshake_response query resultset_header column_definition text_row binary_row prepare_statement prepared_statement_header execute".split(' ').forEach(function(name) {
  var ctor = require('./' + name);
  module.exports[ctor.name] = ctor;
});

// simple packets:
var Packet = require('./packet');

module.exports.OK = function OK() {
};

module.exports.OK.toPacket = function(args) {
  var length = 5 + Packet.lengthCodedNumberLength(args.affectedRows);
  if (args.insertId)
    length = Packet.lengthCodedNumberLength(args.insertId);
  var buffer = new Buffer(length);
  var packet = new Packet(0, buffer);
  packet.offset = 4;
  packet.writeInt8(0);
  packet.writeLengthCodedNumber(args.affectedRows);
  if (args.insertId)
    packet.writeLengthCodedNumber(args.insertId);
  return packet;
};

// warnings, statusFlags
module.exports.EOF = function EOF() {
};

module.exports.EOF.toPacket = function(warnings, statusFlags) {
  if (typeof warnings == 'undefined')
    warnings = 0;
  if (typeof statusFlags == 'undefined')
    statusFlags = 0;
  var packet = new Packet(0, new Buffer(9));
  packet.offset = 4;
  packet.writeInt8(0xfe);
  packet.writeInt16(warnings);
  packet.writeInt16(statusFlags);
  return packet;
};

module.exports.Error = function Error() {
};

module.exports.Error.toPacket = function(args) {
  var packet = new Packet(0, new Buffer(13 + Buffer.byteLength(args.message, 'utf8')));
  packet.offset = 4;
  packet.writeInt8(0xff);
  packet.writeInt16(args.code);
  packet.writeString('#_____');
  packet.writeString(args.message);
  return packet;
};
<commit_msg>Fix crash: Set the length correctly on OK packets with an insertId<commit_after>"binlog_dump register_slave ssl_request handshake handshake_response query resultset_header column_definition text_row binary_row prepare_statement prepared_statement_header execute".split(' ').forEach(function(name) {
  var ctor = require('./' + name);
  module.exports[ctor.name] = ctor;
});

// simple packets:
var Packet = require('./packet');

module.exports.OK = function OK() {
};

module.exports.OK.toPacket = function(args) {
  var length = 5 + Packet.lengthCodedNumberLength(args.affectedRows);
  if (args.insertId)
    length += Packet.lengthCodedNumberLength(args.insertId);
  var buffer = new Buffer(length);
  var packet = new Packet(0, buffer);
  packet.offset = 4;
  packet.writeInt8(0);
  packet.writeLengthCodedNumber(args.affectedRows);
  if (args.insertId)
    packet.writeLengthCodedNumber(args.insertId);
  return packet;
};

// warnings, statusFlags
module.exports.EOF = function EOF() {
};

module.exports.EOF.toPacket = function(warnings, statusFlags) {
  if (typeof warnings == 'undefined')
    warnings = 0;
  if (typeof statusFlags == 'undefined')
    statusFlags = 0;
  var packet = new Packet(0, new Buffer(9));
  packet.offset = 4;
  packet.writeInt8(0xfe);
  packet.writeInt16(warnings);
  packet.writeInt16(statusFlags);
  return packet;
};

module.exports.Error = function Error() {
};

module.exports.Error.toPacket = function(args) {
  var packet = new Packet(0, new Buffer(13 + Buffer.byteLength(args.message, 'utf8')));
  packet.offset = 4;
  packet.writeInt8(0xff);
  packet.writeInt16(args.code);
  packet.writeString('#_____');
  packet.writeString(args.message);
  return packet;
};

{'fraction_non_alphanumeric': 0.13408820023837903, 'fraction_numerical': 0.014898688915375448, 'mean_word_length': 4.910211267605634, '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': '7207946', 'n_tokens_mistral': 1096, 'n_tokens_neox': 1059, 'n_words': 231}