node-insim
Version:
An InSim library for NodeJS with TypeScript support
85 lines (84 loc) • 3.51 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 __());
};
})();
var __read = (this && this.__read) || function (o, n) {
var m = typeof Symbol === "function" && o[Symbol.iterator];
if (!m) return o;
var i = m.call(o), r, ar = [], e;
try {
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
}
catch (error) { e = { error: error }; }
finally {
try {
if (r && !r.done && (m = i["return"])) m.call(i);
}
finally { if (e) throw e.error; }
}
return ar;
};
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
if (ar || !(i in from)) {
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
ar[i] = from[i];
}
}
return to.concat(ar || Array.prototype.slice.call(from));
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.SendablePacket = void 0;
var errors_1 = require("../../errors");
var lfspack_1 = require("../../lfspack");
var Packet_1 = require("./Packet");
var SendableStruct_1 = require("./SendableStruct");
var SendablePacket = /** @class */ (function (_super) {
__extends(SendablePacket, _super);
function SendablePacket() {
return _super !== null && _super.apply(this, arguments) || this;
}
/** @ignore */
SendablePacket.prototype.pack = function (propertyFormatOverrides) {
var _this = this;
var propertyNames = this.getValidPropertyNames();
var format = "<".concat(this.getFormat(propertyFormatOverrides));
var values = [];
propertyNames.forEach(function (propertyName) {
var propertyValue = _this[propertyName];
if (propertyName === 'Size') {
values.push(propertyValue / _this.SIZE_MULTIPLIER);
return;
}
// Spread all values of structs in packet properties
if (propertyValue instanceof SendableStruct_1.SendableStruct) {
var struct_1 = propertyValue;
var structValues = struct_1
.getValidPropertyNames()
.map(function (structPropName) { return struct_1[structPropName]; });
values.push.apply(values, __spreadArray([], __read(structValues), false));
return;
}
return values.push(propertyValue);
});
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 SendablePacket;
}(Packet_1.Packet));
exports.SendablePacket = SendablePacket;