node-insim
Version:
An InSim library for NodeJS with TypeScript support
43 lines (42 loc) • 1.85 kB
JavaScript
;
var __extends = (this && this.__extends) || (function () {
var extendStatics = function (d, b) {
extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
return extendStatics(d, b);
};
return function (d, b) {
if (typeof b !== "function" && b !== null)
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
Object.defineProperty(exports, "__esModule", { value: true });
exports.SendableStruct = void 0;
var errors_1 = require("../../errors");
var lfspack_1 = require("../../lfspack");
var Struct_1 = require("./Struct");
var SendableStruct = /** @class */ (function (_super) {
__extends(SendableStruct, _super);
function SendableStruct() {
return _super !== null && _super.apply(this, arguments) || this;
}
SendableStruct.prototype.pack = function (propertyFormatOverrides) {
var _this = this;
var propertyNames = this.getValidPropertyNames();
var values = propertyNames.map(function (propertyName) {
return _this[propertyName];
});
var format = "<".concat(this.getFormat(propertyFormatOverrides));
var packedData = (0, lfspack_1.pack)(format, values);
if (!packedData) {
throw new errors_1.InSimError('Could not pack values into a packet');
}
return packedData;
};
return SendableStruct;
}(Struct_1.Struct));
exports.SendableStruct = SendableStruct;