Skip to content

Commit

Permalink
Merge ab17088 into 7b66620
Browse files Browse the repository at this point in the history
  • Loading branch information
XiXiangFiles committed Nov 10, 2023
2 parents 7b66620 + ab17088 commit b222ae4
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 2 deletions.
15 changes: 13 additions & 2 deletions index.js
Expand Up @@ -1608,8 +1608,12 @@ question.encode = function (q, buf, offset) {

buf.writeUInt16BE(types.toType(q.type), offset)
offset += 2
if (q.QU === undefined || q.QU !== true) {
buf.writeUInt16BE(classes.toClass(q.class === undefined ? 'IN' : q.class), offset)
} else {
buf.writeUInt16BE(classes.toClass(q.class === undefined ? 'IN' : q.class) + QU_MASK, offset)
}

buf.writeUInt16BE(classes.toClass(q.class === undefined ? 'IN' : q.class), offset)
offset += 2

question.encode.bytes = offset - oldOffset
Expand All @@ -1630,7 +1634,14 @@ question.decode = function (buf, offset) {
q.type = types.toString(buf.readUInt16BE(offset))
offset += 2

q.class = classes.toString(buf.readUInt16BE(offset))
const classValue = buf.readUInt16BE(offset)
if (classValue >= QU_MASK) {
q.QU = true
q.class = classes.toString(classValue - QU_MASK)
} else {
q.class = classes.toString(classValue)
}

offset += 2

const qu = !!(q.class & QU_MASK)
Expand Down
39 changes: 39 additions & 0 deletions test.js
Expand Up @@ -163,6 +163,45 @@ tape('query', function (t) {
name: 'hello.srv.com'
}]
})
testEncoder(t, packet, {
type: 'query',
questions: [{
type: 'A',
QU: true,
name: 'hello.a.com'
}, {
type: 'SRV',
name: 'hello.srv.com'
}]
})

testEncoder(t, packet, {
type: 'query',
id: 42,
questions: [{
type: 'A',
QU: true,
class: 'IN',
name: 'hello.a.com'
}, {
type: 'SRV',
name: 'hello.srv.com'
}]
})

testEncoder(t, packet, {
type: 'query',
id: 42,
questions: [{
type: 'A',
QU: true,
class: 'CH',
name: 'hello.a.com'
}, {
type: 'SRV',
name: 'hello.srv.com'
}]
})

t.end()
})
Expand Down

0 comments on commit b222ae4

Please sign in to comment.