const ByteStream = require("../../ByteStream/ByteStream") class KeepAliveMessage { constructor(config, crypto, logger, data = null) { this.config = config this.crypto = crypto this.logger = logger this.type = 20108 this.data = data } encode() { const stream = new ByteStream() stream.writeUInt32(Math.floor(Date.now() / 1000)) stream.writeUInt32(this.data?.counter || 0) this.logger.debug(`Encoding KeepAliveMessage`, { timestamp: Math.floor(Date.now() / 1000), counter: this.data?.counter || 0, }) return stream.getBuffer() } decode(buffer) { const stream = new ByteStream(buffer) const data = { timestamp: stream.readUInt32(), counter: stream.readUInt32(), } this.logger.debug(`Decoded KeepAliveMessage`, data) return data } getType() { return this.type } } module.exports = KeepAliveMessage