<commit_before>'use strict';

var utils = require('../../lifx').utils;

var Packet = {
  size: 20
};

/**
 * Converts packet specific data from a buffer to an object
 * @param  {Buffer} buf Buffer containing only packet specific data no header
 * @return {Object}     Information contained in packet
 */
Packet.toObject = function(buf) {
  var obj = {};
  var offset = 0;

  // Check length
  if (buf.length !== this.size) {
    throw new Error('Invalid length given for stateHostFirmware LIFX packet');
  }

  obj.build = utils.readUInt64LE(buf, offset);
  offset += 8;

  obj.install = utils.readUInt64LE(buf, offset);
  offset += 8;

  obj.version = buf.readUInt32LE(offset);
  offset += 4;

  return obj;
};

/**
 * Converts the given packet specific object into a packet
 * @param  {Object} obj object with configuration data
 * @return {Buffer}     packet
 */
Packet.toBuffer = function(obj) {
  var buf = new Buffer(this.size);
  buf.fill(0);
  var offset = 0;

  utils.writeUInt64LE(buf, offset, obj.build);
  offset += 8;

  utils.writeUInt64LE(buf, offset, obj.install);
  offset += 8;

  buf.writeUInt32LE(obj.version, offset);
  offset += 4;

  return buf;
};

module.exports = Packet;
<commit_msg>Convert firmware version to a readable format<commit_after>'use strict';

var utils = require('../../lifx').utils;

var Packet = {
  size: 20
};

/**
 * Converts packet specific data from a buffer to an object
 * @param  {Buffer} buf Buffer containing only packet specific data no header
 * @return {Object}     Information contained in packet
 */
Packet.toObject = function(buf) {
  var obj = {};
  var offset = 0;

  // Check length
  if (buf.length !== this.size) {
    throw new Error('Invalid length given for stateHostFirmware LIFX packet');
  }

  obj.build = utils.readUInt64LE(buf, offset);
  offset += 8;

  obj.install = utils.readUInt64LE(buf, offset);
  offset += 8;

  var version = buf.readUInt32LE(offset);
  obj.majorVersion = (version >> 16) & 0xFF;
  obj.minorVersion = version & 0xFF;
  offset += 4;

  return obj;
};

/**
 * Converts the given packet specific object into a packet
 * @param  {Object} obj object with configuration data
 * @return {Buffer}     packet
 */
Packet.toBuffer = function(obj) {
  var buf = new Buffer(this.size);
  buf.fill(0);
  var offset = 0;

  utils.writeUInt64LE(buf, offset, obj.build);
  offset += 8;

  utils.writeUInt64LE(buf, offset, obj.install);
  offset += 8;

  buf.writeUInt32LE(obj.version, offset);
  offset += 4;

  return buf;
};

module.exports = Packet;

{'fraction_non_alphanumeric': 0.13220205209155486, 'fraction_numerical': 0.01973164956590371, 'mean_word_length': 3.4395796847635727, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, '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': '1869155', 'n_tokens_mistral': 861, 'n_tokens_neox': 805, 'n_words': 254}