{"size": 1587, "ext": "js", "max_stars_repo_path": "dist/lib/Structures/NodeMessage.js", "max_stars_repo_name": "takase1121/veza", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "dist/lib/Structures/NodeMessage.js", "max_issues_repo_name": "takase1121/veza", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "dist/lib/Structures/NodeMessage.js", "max_forks_repo_name": "takase1121/veza", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": null, "max_issues_count": null, "max_forks_count": null, "avg_line_length": 27.3620689655, "max_line_length": 109, "alphanum_fraction": 0.5601764335}
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const Header_1 = require("../Util/Header");
const DataFormat_1 = require("../Util/DataFormat");
class NodeMessage {
    /**
     * @since 0.0.1
     * @param client The socket that received this message.
     * @param id The ID of the message.
     * @param receptive Whether or not this message accepts a reply.
     * @param data The data received from the socket.
     */
    constructor(client, id, receptive, data) {
        Object.defineProperties(this, {
            client: { value: client },
            id: { value: id, enumerable: true },
            receptive: { value: receptive, enumerable: true }
        });
        this.data = data;
    }
    /**
     * Reply to the socket.
     * @since 0.0.1
     * @param content The content to send.
     */
    reply(content) {
        if (this.receptive) {
            this.client.socket.write(Header_1.createFromID(this.id, false, DataFormat_1.serialize(content)));
        }
    }
    /**
     * Freeze the message.
     * @since 0.0.1
     */
    freeze() {
        return Object.freeze(this);
    }
    /**
     * The toJSON overload for JSON.stringify.
     * @since 0.0.1
     */
    toJSON() {
        return {
            id: this.id,
            data: this.data,
            receptive: this.receptive
        };
    }
    /**
     * The toString overload for string casting.
     * @since 0.0.1
     */
    toString() {
        return `NodeMessage<${this.id}>`;
    }
}
exports.NodeMessage = NodeMessage;
//# sourceMappingURL=NodeMessage.js.map