Skip to content

Commit

Permalink
fix(is_con): Use decorators for unpacking A and B car contact str…
Browse files Browse the repository at this point in the history
…uct properties
  • Loading branch information
mkapal committed Apr 23, 2024
1 parent 1dbb7b7 commit 1f3a77b
Showing 1 changed file with 3 additions and 26 deletions.
29 changes: 3 additions & 26 deletions src/packets/IS_CON.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { byte, word } from '../decorators';
import { copyBuffer } from '../lfspack';
import { byte, struct, word } from '../decorators';
import { Packet } from './base';
import { PacketType } from './enums';
import { CarContact } from './structs';
Expand All @@ -24,30 +23,8 @@ export class IS_CON extends Packet {
@word() Time = 0;

/** Contact object - car A */
A: CarContact = new CarContact();
@struct(CarContact) A = new CarContact();

/** Contact object - car B */
B: CarContact = new CarContact();

unpack(buffer: Uint8Array): this {
super.unpack(buffer);

const carContactOffset = this.getFormatSize();
const carContactLength = new CarContact().getFormatSize();

const carContactBufferA = copyBuffer(
buffer.slice(carContactOffset, carContactOffset + carContactLength),
);
const carContactBufferB = copyBuffer(
buffer.slice(
carContactOffset + carContactLength,
carContactOffset + carContactLength * 2,
),
);

this.A = new CarContact().unpack(carContactBufferA);
this.B = new CarContact().unpack(carContactBufferB);

return this;
}
@struct(CarContact) B = new CarContact();
}

0 comments on commit 1f3a77b

Please sign in to comment.