<commit_before>var defs = require('./defs'),
    commands = defs.commands,
    commandsById = defs.commandsById,
    tlvs = defs.tlvs,
    tlvsById = defs.tlvsById;

var pduHeadParams = [
	'command_length',
	'command_id',
	'command_status',
	'sequence_number'
];

function PDU(command, options) {
	if (Buffer.isBuffer(arguments[0])) {
		return this.fromBuffer(arguments[0]);
	}
	options = options || {};
	this.command = command;
	this.command_length = 0;
	this.command_id = commands[command].id;
	this.command_status = options.command_status || 0;
	this.sequence_number = options.sequence_number || 0;
	var params = commands[command].params || {};
	for (var key in params) if (params.hasOwnProperty(key)) {
		if (key in options) {
			this[key] = options[key];
		} else {
			this[key] = params[key].default || params[key].type.default;
		}
	}
	for (var key in options) if (options.hasOwnProperty(key) && key in tlvs) {
		this[key] = options[key];
	}
}

PDU.fromBuffer = function(buffer) {
	if (buffer.length < 16 || buffer.length < buffer.readUInt32BE(0)) {
		return false;
	}
	return new PDU(buffer);
};

PDU.prototype.isResponse = function() {
	return !!(this.command_id & 0x80000000);
};

PDU.prototype.response = function(options) {
	options = options || {};
	options.sequence_number = this.sequence_number;
	if (this.command == 'unknown') {
		return new PDU('generic_nack', options);
	}
	return new PDU(this.command + '_resp', options);
};

PDU.prototype.fromBuffer = function(buffer) {
	pduHeadParams.forEach(function(key, i) {<commit_msg>Respond unknown pdus with a ESME_RINVCMDID command_status.<commit_after>var defs = require('./defs'),
    commands = defs.commands,
    commandsById = defs.commandsById,
    tlvs = defs.tlvs,
    tlvsById = defs.tlvsById;

var pduHeadParams = [
	'command_length',
	'command_id',
	'command_status',
	'sequence_number'
];

function PDU(command, options) {
	if (Buffer.isBuffer(arguments[0])) {
		return this.fromBuffer(arguments[0]);
	}
	options = options || {};
	this.command = command;
	this.command_length = 0;
	this.command_id = commands[command].id;
	this.command_status = options.command_status || 0;
	this.sequence_number = options.sequence_number || 0;
	var params = commands[command].params || {};
	for (var key in params) if (params.hasOwnProperty(key)) {
		if (key in options) {
			this[key] = options[key];
		} else {
			this[key] = params[key].default || params[key].type.default;
		}
	}
	for (var key in options) if (options.hasOwnProperty(key) && key in tlvs) {
		this[key] = options[key];
	}
}

PDU.fromBuffer = function(buffer) {
	if (buffer.length < 16 || buffer.length < buffer.readUInt32BE(0)) {
		return false;
	}
	return new PDU(buffer);
};

PDU.prototype.isResponse = function() {
	return !!(this.command_id & 0x80000000);
};

PDU.prototype.response = function(options) {
	options = options || {};
	options.sequence_number = this.sequence_number;
	if (this.command == 'unknown') {
		if (!('command_status' in options)) {
			options.command_status = defs.errors.ESME_RINVCMDID;
		}
		return new PDU('generic_nack', options);
	}
	return new PDU(this.command + '_resp', options);
};

PDU.prototype.fromBuffer = function(buffer) {
	pduHeadParams.forEach(function(key, i) {
{'fraction_non_alphanumeric': 0.15310856789359728, 'fraction_numerical': 0.011753789050417568, 'mean_word_length': 4.528205128205128, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 2, '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': '851570', 'n_tokens_mistral': 1184, 'n_tokens_neox': 1132, 'n_words': 230}