UNPKG

@node-lightning/wire

Version:
53 lines 1.86 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.PongMessage = void 0; const bufio_1 = require("@node-lightning/bufio"); const MessageType_1 = require("../MessageType"); class PongMessage { /** * In order to allow for the existence of long-lived TCP * connections, at times it may be required that both ends keep * alive the TCP connection at the application level. * * The pong message is a reply to a ping message and must * reply with the specify number of bytes when the num_pong_bytes * value is less than 65532. * for the number of pong bytes it expects to receive as * a reply. The ignored bits should be set to 0. */ constructor(numPongBytes = 0) { /** * Message type = 19 */ this.type = MessageType_1.MessageType.Pong; this.ignored = Buffer.alloc(numPongBytes); } /** * Deserializes a pong message from a Buffer into a PongMessage * instance. */ static deserialize(payload) { const instance = new PongMessage(); const reader = new bufio_1.BufferReader(payload); reader.readUInt16BE(); // read off type const byteslen = reader.readUInt16BE(); instance.ignored = reader.readBytes(byteslen); return instance; } /** * Serializes a PongMessage into a Buffer that can be * streamed on the wire. */ serialize() { const len = 2 + // type 2 + // byteslen +this.ignored.length; const writer = new bufio_1.BufferWriter(Buffer.alloc(len)); writer.writeUInt16BE(this.type); writer.writeUInt16BE(this.ignored.length); writer.writeBytes(this.ignored); return writer.toBuffer(); } } exports.PongMessage = PongMessage; //# sourceMappingURL=PongMessage.js.map