<commit_before>var debug = require('debug')('mdns:lib:bufferconsumer');
var BufferConsumer = module.exports = function BufferConsumer(arg) {
  if (!(arg instanceof Buffer)) {
    throw new Error('Expected instance of Buffer');
  }
  this._view = arg;

  this._offset = 0;
};

BufferConsumer.prototype.slice = function slice(length) {
  if ((this._offset + length) > this._view.length) {
    debug('slice beyond buffer.', {
      offset:this._offset,
      length:length,
      bufferLength: this._view.length
    });
    throw new Error('Buffer overflow');
  }
  var v = this._view.slice(this._offset, this._offset + length);
  this._offset += length;
  return v;
};

BufferConsumer.prototype.isEOF = function isEOF() {
  return this._offset >= this._view.length;
};

BufferConsumer.prototype.byte = function byte() {
  this._offset += 1;
  return this._view.readUInt8(this._offset - 1);
};

BufferConsumer.prototype.short = function short() {
  this._offset += 2;
  return this._view.readUInt16BE(this._offset - 2);
};

BufferConsumer.prototype.long = function long() {
  this._offset += 4;
  return this._view.readUInt32BE(this._offset - 4);
};


/**
 * Consumes a DNS name, which will either finish with a NULL byte or a suffix
 * reference (i.e., 0xc0 <ref>).
 */
BufferConsumer.prototype.name = function name(join) {
  if (typeof join === 'undefined') { join = true; }
  var parts = [];
  var len;
  this.ref = undefined;
  for (;;) {
    try {
      len = this.byte();
    } catch (e) {
      if (e instanceof RangeError) { break; }
    }
    if (!len) {
      break;
    } else if (len === 0xc0) {
      // TODO: This indicates a pointer to another valid name inside the
      // DNSPacket, and is always a suffix: we're at the end of the name.
      // We should probably hold onto this value instead of discarding it.
      this.ref = this.byte();
      break;
    }

    // Otherwise, consume a string!<commit_msg>Check only the 2 MSBs to detect label format<commit_after>var debug = require('debug')('mdns:lib:bufferconsumer');
var BufferConsumer = module.exports = function BufferConsumer(arg) {
  if (!(arg instanceof Buffer)) {
    throw new Error('Expected instance of Buffer');
  }
  this._view = arg;

  this._offset = 0;
};

BufferConsumer.prototype.slice = function slice(length) {
  if ((this._offset + length) > this._view.length) {
    debug('slice beyond buffer.', {
      offset:this._offset,
      length:length,
      bufferLength: this._view.length
    });
    throw new Error('Buffer overflow');
  }
  var v = this._view.slice(this._offset, this._offset + length);
  this._offset += length;
  return v;
};

BufferConsumer.prototype.isEOF = function isEOF() {
  return this._offset >= this._view.length;
};

BufferConsumer.prototype.byte = function byte() {
  this._offset += 1;
  return this._view.readUInt8(this._offset - 1);
};

BufferConsumer.prototype.short = function short() {
  this._offset += 2;
  return this._view.readUInt16BE(this._offset - 2);
};

BufferConsumer.prototype.long = function long() {
  this._offset += 4;
  return this._view.readUInt32BE(this._offset - 4);
};


/**
 * Consumes a DNS name, which will either finish with a NULL byte or a suffix
 * reference (i.e., 0xc0 <ref>).
 */
BufferConsumer.prototype.name = function name(join) {
  if (typeof join === 'undefined') { join = true; }
  var parts = [];
  var len;
  this.ref = undefined;
  for (;;) {
    try {
      len = this.byte();
    } catch (e) {
      if (e instanceof RangeError) { break; }
    }
    if (!len) {
      break;
    } else if ((len & 0xc0) === 0xc0) {
      // TODO: This indicates a pointer to another valid name inside the
      // DNSPacket, and is always a suffix: we're at the end of the name.
      // We should probably hold onto this value instead of discarding it.
      this.ref = this.byte();
      break;
    }

    // Otherwise, consume a string!
{'fraction_non_alphanumeric': 0.1376028806584362, 'fraction_numerical': 0.009002057613168725, 'mean_word_length': 3.0722513089005234, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 9, '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': '5591785', 'n_tokens_mistral': 1222, 'n_tokens_neox': 1180, 'n_words': 354}