dns-packet-typescript
Version:
An abstract-encoding compliant module for encoding / decoding DNS packets
41 lines • 1.34 kB
JavaScript
Object.defineProperty(exports, "__esModule", { value: true });
exports.encodingLength = exports.decode = exports.encode = void 0;
var name = require("./name");
function encode(data, buf, offset) {
if (offset === void 0) { offset = 0; }
if (!buf)
buf = Buffer.allocUnsafe(encodingLength(data));
if (!offset)
offset = 0;
buf.writeUInt16BE(data.priority || 0, offset + 2);
buf.writeUInt16BE(data.weight || 0, offset + 4);
buf.writeUInt16BE(data.port || 0, offset + 6);
name.encode(data.target, buf, offset + 8);
var len = name.encode.bytes + 6;
buf.writeUInt16BE(len, offset);
encode.bytes = len + 2;
return buf;
}
exports.encode = encode;
encode.bytes = 0;
function decode(buf, offset) {
if (offset === void 0) { offset = 0; }
if (!offset)
offset = 0;
var len = buf.readUInt16BE(offset);
var data = {};
data.priority = buf.readUInt16BE(offset + 2);
data.weight = buf.readUInt16BE(offset + 4);
data.port = buf.readUInt16BE(offset + 6);
data.target = name.decode(buf, offset + 8);
decode.bytes = len + 2;
return data;
}
exports.decode = decode;
decode.bytes = 0;
function encodingLength(data) {
return 8 + name.encodingLength(data.target);
}
exports.encodingLength = encodingLength;
//# sourceMappingURL=rsrv.js.map
;