UNPKG

dns-packet-typescript

Version:

An abstract-encoding compliant module for encoding / decoding DNS packets

32 lines 910 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.encodingLength = exports.decode = exports.encode = void 0; function encode(s, buf, offset) { if (offset === void 0) { offset = 0; } if (!buf) buf = Buffer.allocUnsafe(encodingLength(s)); if (!offset) offset = 0; var len = buf.write(s, offset + 1); buf[offset] = len; encode.bytes = len + 1; 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[offset]; var s = buf.toString('utf-8', offset + 1, offset + 1 + len); decode.bytes = len + 1; return s; } exports.decode = decode; decode.bytes = 0; function encodingLength(s) { return Buffer.byteLength(s) + 1; } exports.encodingLength = encodingLength; //# sourceMappingURL=string.js.map