UNPKG

@munit-solutions/ocpp

Version:
31 lines 1.06 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); class Message { constructor(uniqueId = '', payload) { this.messageType = 3; this.toString = () => { return JSON.stringify(this.toArray()); }; this.toArray = () => { if (this.action !== undefined && !this.payload) throw new Error(); return this.messageType === 3 ? [this.messageType, this.uniqueId, this.payload] : [this.messageType, this.uniqueId, this.action, this.payload]; }; this.uniqueId = uniqueId; this.payload = payload; } parseString(message) { const [messageType, uniqueId, actionOrPayload, payload] = JSON.parse(message); this.messageType = messageType; this.uniqueId = uniqueId; if (payload) { this.action = actionOrPayload; this.payload = payload; } else { this.payload = actionOrPayload; } } } exports.default = Message; //# sourceMappingURL=Message.js.map