"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.Tlv = void 0;
const bufio_1 = require("@node-dlc/bufio");
class Tlv {
    /**
     * Deserializes an tlv message
     * @param buf
     */
    static deserialize(buf) {
        const instance = new Tlv();
        const reader = new bufio_1.BufferReader(buf);
        instance.type = Number(reader.readBigSize()); // read type
        instance.length = reader.readBigSize();
        instance.body = reader.readBytes(Number(instance.length));
        return instance;
    }
    /**
     * Serializes the tlv message into a Buffer
     */
    serialize() {
        const writer = new bufio_1.BufferWriter();
        writer.writeBigSize(this.type);
        const dataWriter = new bufio_1.BufferWriter();
        dataWriter.writeBytes(this.body);
        writer.writeBigSize(dataWriter.size);
        writer.writeBytes(dataWriter.toBuffer());
        return writer.toBuffer();
    }
}
exports.Tlv = Tlv;
//# sourceMappingURL=Tlv.js.map