<commit_before>var types = require('./types')

var name = {}

name.decode = function (buf, offset) {
  var list = []
  var oldOffset = offset
  var len = buf[offset++]

  if (len >= 0xc0) {
    var res = name.decode(buf, buf.readUInt16BE(offset - 1) - 0xc000)
    name.decode.bytes = 2
    return res
  }

  while (len) {
    if (len >= 0xc0) {
      list.push(name.decode(buf, buf.readUInt16BE(offset - 1) - 0xc000))
      offset++
      break
    }

    list.push(buf.toString('utf-8', offset, offset + len))
    offset += len
    len = buf[offset++]
  }

  name.decode.bytes = offset - oldOffset
  return list.join('.')
}

name.encode = function (n, buf, offset) {
  var list = n.split('.')
  var oldOffset = offset

  for (var i = 0; i < list.length; i++) {
    var len = buf.write(list[i], offset + 1)
    buf[offset] = len
    offset += len + 1
  }

  buf[offset++] = 0

  name.encode.bytes = offset - oldOffset
  return buf
}

name.encodingLength = function (n) {
  return Buffer.byteLength(n) + 2
}

var str = {}

str.encode = function (s, buf, offset) {
  var len = buf.write(s, offset + 1)
  buf[offset] = len
  str.encode.bytes = len + 1
  return buf
}

str.decode = function (buf, offset) {
  var len = buf[offset]
  var s = buf.toString('utf-8', offset + 1, offset + 1 + len)
  str.decode.bytes = len + 1
  return s
}

str.encodingLength = function (s) {
  return Buffer.byteLength(s) + 1
}

var QUERY_FLAG = 0x0000
var RESPONSE_FLAG = 0x8400

var header = {}

header.decode = function (buf, offset) {
  var flags = buf.readUInt16BE(offset + 2)
  if (flags !== RESPONSE_FLAG && flags !== QUERY_FLAG) throw new Error('bad type: ' + flags)

  header.decode.bytes = 12
  return {
    type: flags === RESPONSE_FLAG ? 'response' : 'query',
    qdcount: buf.readUInt16BE(offset + 4),
    ancount: buf.readUInt16BE(offset + 6),
    nscount: buf.readUInt16BE(offset + 8),
    arcount: buf.readUInt16BE(offset + 10)
   }
}

header.encode = function (h, buf, offset) {
  buf.writeUInt16BE(0, offset)
  buf.writeUInt16BE(h.type === 'response' ? RESPONSE_FLAG : QUERY_FLAG, offset + 2)
  buf.writeUInt16BE(h.qdcount, offset + 4)
  buf.writeUInt16BE(h.ancount, offset + 6)
  buf.writeUInt16BE(h.nscount, offset + 8)
  buf.writeUInt16BE(h.arcount, offset + 10)

  header.encode.bytes = 12
  return buf
}

header.encodingLength = function (h) {
  return 12
}<commit_msg>fix response flag detection<commit_after>var types = require('./types')

var name = {}

name.decode = function (buf, offset) {
  var list = []
  var oldOffset = offset
  var len = buf[offset++]

  if (len >= 0xc0) {
    var res = name.decode(buf, buf.readUInt16BE(offset - 1) - 0xc000)
    name.decode.bytes = 2
    return res
  }

  while (len) {
    if (len >= 0xc0) {
      list.push(name.decode(buf, buf.readUInt16BE(offset - 1) - 0xc000))
      offset++
      break
    }

    list.push(buf.toString('utf-8', offset, offset + len))
    offset += len
    len = buf[offset++]
  }

  name.decode.bytes = offset - oldOffset
  return list.join('.')
}

name.encode = function (n, buf, offset) {
  var list = n.split('.')
  var oldOffset = offset

  for (var i = 0; i < list.length; i++) {
    var len = buf.write(list[i], offset + 1)
    buf[offset] = len
    offset += len + 1
  }

  buf[offset++] = 0

  name.encode.bytes = offset - oldOffset
  return buf
}

name.encodingLength = function (n) {
  return Buffer.byteLength(n) + 2
}

var str = {}

str.encode = function (s, buf, offset) {
  var len = buf.write(s, offset + 1)
  buf[offset] = len
  str.encode.bytes = len + 1
  return buf
}

str.decode = function (buf, offset) {
  var len = buf[offset]
  var s = buf.toString('utf-8', offset + 1, offset + 1 + len)
  str.decode.bytes = len + 1
  return s
}

str.encodingLength = function (s) {
  return Buffer.byteLength(s) + 1
}

var QUERY_FLAG = 0
var RESPONSE_FLAG = 1 << 15

var header = {}

header.decode = function (buf, offset) {
  var flags = buf.readUInt16BE(offset + 2)

  header.decode.bytes = 12
  return {
    type: flags & RESPONSE_FLAG ? 'response' : 'query',
    qdcount: buf.readUInt16BE(offset + 4),
    ancount: buf.readUInt16BE(offset + 6),
    nscount: buf.readUInt16BE(offset + 8),
    arcount: buf.readUInt16BE(offset + 10)
   }
}

header.encode = function (h, buf, offset) {
  buf.writeUInt16BE(0, offset)
  buf.writeUInt16BE(h.type === 'response' ? RESPONSE_FLAG : QUERY_FLAG, offset + 2)
  buf.writeUInt16BE(h.qdcount, offset + 4)
  buf.writeUInt16BE(h.ancount, offset + 6)
  buf.writeUInt16BE(h.nscount, offset + 8)
  buf.writeUInt16BE(h.arcount, offset + 10)

  header.encode.bytes = 12
  return buf
}

header.encodingLength = function (h) {
  return 12
}
{'fraction_non_alphanumeric': 0.14749516233068158, 'fraction_numerical': 0.034401204042141476, 'mean_word_length': 3.0277056277056276, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, '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': '1909485', 'n_tokens_mistral': 1854, 'n_tokens_neox': 1716, 'n_words': 434}