fix #17 only use explicit big-endian methods

This commit is contained in:
AJ ONeal 2017-01-30 11:43:41 -07:00
parent fa180b0d4b
commit 0c2184ae00
1 changed files with 15 additions and 15 deletions

View File

@ -47,7 +47,7 @@ pdns.unpack = function (ab) {
// DO: new Uint8Array(arrayBuffer);
// DO NOT: Uint8Array.from(arrayBuffer); // WILL NOT WORK
// DO: new DataView(arrayBuffer).getUint16(7);
// DO: new DataView(arrayBuffer).getUint16(7, false);
// DO NOT: arrayBuffer.slice();
//
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer
@ -57,12 +57,12 @@ pdns.unpack = function (ab) {
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView
var dv = new DataView(ab);
var id = dv.getUint16(0);
var header = pdns.unpackHeader(dv.getUint16(2));
var qdcount = dv.getUint16(4); // query count
var ancount = dv.getUint16(6); // answer count
var nscount = dv.getUint16(8); // authority count
var arcount = dv.getUint16(10); // additional count
var id = dv.getUint16(0, false);
var header = pdns.unpackHeader(dv.getUint16(2, false));
var qdcount = dv.getUint16(4, false); // query count
var ancount = dv.getUint16(6, false); // answer count
var nscount = dv.getUint16(8, false); // authority count
var arcount = dv.getUint16(10, false); // additional count
var total = 12;
var i;
var rec;
@ -97,9 +97,9 @@ pdns.unpack = function (ab) {
);
}
q.type = dv.getUint16(total);
q.type = dv.getUint16(total, false);
total += 2;
q.class = dv.getUint16(total);
q.class = dv.getUint16(total, false);
total += 2;
q.byteLength = total - ototal;
@ -142,13 +142,13 @@ pdns.unpack = function (ab) {
);
}
q.type = dv.getUint16(total);
q.type = dv.getUint16(total, false);
total += 2;
q.class = dv.getUint16(total);
q.class = dv.getUint16(total, false);
total += 2;
q.ttl = dv.getUint32(total);
q.ttl = dv.getUint32(total, false);
total += 4;
q.rdlength = dv.getUint16(total);
q.rdlength = dv.getUint16(total, false);
total += 2;
q.className = classes[q.class];
@ -157,13 +157,13 @@ pdns.unpack = function (ab) {
// TODO actually parse RDATA
q.rdstart = total;
console.log('q.rdata', q.rdata.byteLength, 'bytes:');
console.log('q.rdata', q.rdlength, 'bytes:');
console.log(new Uint8Array(ab).slice(total, total + q.rdlength));
//q.rdata = Array.prototype.slice.apply(q.rdata);
total += q.rdlength;
//q.rdend = q.rdstart + q.rdlength;
total += q.rdlength;
q.byteLength = total - ototal;
return q;
}