node-insim
Version:
An InSim library for NodeJS with TypeScript support
16 lines (15 loc) • 601 B
JavaScript
import { InSimError } from '../../errors';
import { pack } from '../../lfspack';
import { Struct } from './Struct';
export class SendableStruct extends Struct {
pack(propertyFormatOverrides) {
const propertyNames = this.getValidPropertyNames();
const values = propertyNames.map((propertyName) => this[propertyName]);
const format = `<${this.getFormat(propertyFormatOverrides)}`;
const packedData = pack(format, values);
if (!packedData) {
throw new InSimError('Could not pack values into a packet');
}
return packedData;
}
}