dlms-protocol
Version:
DLMS Protocol parser for JavaScript
43 lines (42 loc) • 1.25 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = void 0;
require("core-js/modules/web.dom-collections.iterator.js");
var _DlmsDataType = _interopRequireDefault(require("../enum/DlmsDataType"));
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
class DlmsString {
constructor() {
let data = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : null;
this.tag = _DlmsDataType.default.STRING;
this.totalBytes = 0;
this.rawValue = [];
this.bodyBytes = [];
this.value = '';
this.size = 0;
if (data) {
this.insertData(data);
}
}
getStandardLength() {
throw new Error("Method not implemented.");
}
getValue() {
return this.value;
}
insertData(data) {
if (this.tag !== data[0]) {
throw new Error("Tag mismatch.");
}
this.size = data[1];
this.bodyBytes = data.slice(2, 2 + this.size); // Extract the body bytes
this.value = this._bytesToString(this.bodyBytes);
this.rawValue = [this.tag, this.size, ...this.bodyBytes];
this.totalBytes = this.rawValue.length;
}
_bytesToString(bytes) {
return String.fromCharCode(...bytes);
}
}
exports.default = DlmsString;