Skip to content

Commit

Permalink
refactor!: remove the size argument in many places
Browse files Browse the repository at this point in the history
  • Loading branch information
thetayloredman committed Mar 2, 2023
1 parent 8e1e99f commit 7fba3ee
Show file tree
Hide file tree
Showing 7 changed files with 18 additions and 18 deletions.
2 changes: 1 addition & 1 deletion src/DumbClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ export default class DumbClient extends Emitter<DumbClientEventArguments> {
log("forwarding close");
this.emit(DumbClientEvents.Close);
});
this._shell.on(ShellEvents.Packet, (_size, data) => {
this._shell.on(ShellEvents.Packet, (data) => {
log("forwarding packet", data);
this.emit(DumbClientEvents.Packet, new Packet(data));
});
Expand Down
6 changes: 3 additions & 3 deletions src/shell/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export enum ShellEvents {
Close = "close"
}
export type ShellEventArguments = {
[ShellEvents.Packet]: [number, Buffer];
[ShellEvents.Packet]: [Buffer];
[ShellEvents.Reset]: [];
[ShellEvents.Close]: [];
};
Expand All @@ -56,9 +56,9 @@ export default class Shell extends Emitter<ShellEventArguments> {
log("forwarding close");
this.emit(ShellEvents.Close);
});
this._stream.on(StreamEvents.Packet, (size, packet) => {
this._stream.on(StreamEvents.Packet, (packet) => {
log("forwarding+decoding packet", packet);
this.emit(ShellEvents.Packet, size, this._algorithm.decode(packet));
this.emit(ShellEvents.Packet, this._algorithm.decode(packet));
});
}

Expand Down
4 changes: 2 additions & 2 deletions src/stream/DirectStream.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export type DirectStreamEventArguments = {
*/
[DirectStreamEvents.Read]: [ControlCharacters.ReadByte, 1, number] | [SizedControlCharacters, number, Buffer];
/** Emitted when an End of Packet is received along with (size, data) parameters. */
[DirectStreamEvents.Packet]: [number, Buffer];
[DirectStreamEvents.Packet]: [Buffer];
};

/**
Expand Down Expand Up @@ -217,7 +217,7 @@ export default class DirectStream extends Emitter<DirectStreamEventArguments> {
/** Called internally to clear and emit a packet. */
private _emitPacket(): void {
debug("triggering packet");
this.emit(DirectStreamEvents.Packet, this._packetSize, this._packet);
this.emit(DirectStreamEvents.Packet, this._packet);
this._packet = Buffer.alloc(0);
this._packetSize = 0;
}
Expand Down
6 changes: 3 additions & 3 deletions src/stream/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export type StreamEventArguments = {
/**
* Fired whenever an End Of Packet is received, with two parameters, size and data.
*/
[StreamEvents.Packet]: [number, Buffer];
[StreamEvents.Packet]: [Buffer];
/**
* Fired whenever the remote sends Read Reset.
*/
Expand Down Expand Up @@ -86,9 +86,9 @@ export default class Stream extends Emitter<StreamEventArguments> {
log("forwarding read", data);
this.emit(StreamEvents.Read, data instanceof Buffer ? data : Buffer.from([data]));
});
this._stream.on(DirectStreamEvents.Packet, (size, data) => {
this._stream.on(DirectStreamEvents.Packet, (data) => {
log("forwarding packet", data);
this.emit(StreamEvents.Packet, size, data);
this.emit(StreamEvents.Packet, data);
});
this._provider.on(IOProviderEvents.Close, () => {
log("forwarding close");
Expand Down
2 changes: 1 addition & 1 deletion src/tests/shell/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ describe("Shell", () => {
manual.write(Buffer.concat([direct.encode(data), Buffer.from([ControlCharacters.EndOfPacket])]));

expect(localPacket).toBeCalledTimes(1);
expect(localPacket).toBeCalledWith(13, data);
expect(localPacket).toBeCalledWith(data);
});

describe("close", () => {
Expand Down
12 changes: 6 additions & 6 deletions src/tests/stream/DirectStream.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ describe("Stream", () => {

expect(onRead).not.toHaveBeenCalled();
expect(onPacket).toHaveBeenCalledTimes(1);
expect(onPacket).toHaveBeenCalledWith(0, Buffer.alloc(0));
expect(onPacket).toHaveBeenCalledWith(Buffer.alloc(0));
expect(onReset).not.toHaveBeenCalled();
});

Expand All @@ -106,7 +106,7 @@ describe("Stream", () => {
expect(onRead).toHaveBeenCalledTimes(1);
expect(onRead).toHaveBeenCalledWith(ControlCharacters.ReadByte, 1, 1);
expect(onPacket).toHaveBeenCalledTimes(1);
expect(onPacket).toHaveBeenCalledWith(1, Buffer.from([1]));
expect(onPacket).toHaveBeenCalledWith(Buffer.from([1]));
expect(onReset).not.toHaveBeenCalled();
});

Expand Down Expand Up @@ -157,7 +157,7 @@ describe("Stream", () => {
Buffer.from([0x0, 0x1, 0x2, 0x3, 0x4, 0x5, 0x6, 0x7, 0x8, 0x9, 0xa, 0xb])
);
expect(onPacket).toHaveBeenCalledTimes(1);
expect(onPacket).toHaveBeenCalledWith(12, Buffer.from([0x0, 0x1, 0x2, 0x3, 0x4, 0x5, 0x6, 0x7, 0x8, 0x9, 0xa, 0xb]));
expect(onPacket).toHaveBeenCalledWith(Buffer.from([0x0, 0x1, 0x2, 0x3, 0x4, 0x5, 0x6, 0x7, 0x8, 0x9, 0xa, 0xb]));
expect(onReset).not.toHaveBeenCalled();
});

Expand All @@ -179,7 +179,7 @@ describe("Stream", () => {
Buffer.from([0x0, 0x1, 0x2, 0x3, 0x4, 0x5, 0x6, 0x7, 0x8, 0x9, 0xa, 0xb])
);
expect(onPacket).toHaveBeenCalledTimes(1);
expect(onPacket).toHaveBeenCalledWith(12, Buffer.from([0x0, 0x1, 0x2, 0x3, 0x4, 0x5, 0x6, 0x7, 0x8, 0x9, 0xa, 0xb]));
expect(onPacket).toHaveBeenCalledWith(Buffer.from([0x0, 0x1, 0x2, 0x3, 0x4, 0x5, 0x6, 0x7, 0x8, 0x9, 0xa, 0xb]));
expect(onReset).not.toHaveBeenCalled();
});

Expand All @@ -201,7 +201,7 @@ describe("Stream", () => {
Buffer.from([0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b])
);
expect(onPacket).toHaveBeenCalledTimes(1);
expect(onPacket).toHaveBeenCalledWith(12, Buffer.from([0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b]));
expect(onPacket).toHaveBeenCalledWith(Buffer.from([0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b]));
expect(onReset).not.toHaveBeenCalled();
});

Expand All @@ -213,7 +213,7 @@ describe("Stream", () => {
expect(onRead).toHaveBeenCalledTimes(1);
expect(onRead).toHaveBeenCalledWith(ControlCharacters.ReadByte, 1, 0);
expect(onPacket).toHaveBeenCalledTimes(1);
expect(onPacket).toHaveBeenCalledWith(0, Buffer.alloc(0));
expect(onPacket).toHaveBeenCalledWith(Buffer.alloc(0));
expect(onReset).toHaveBeenCalledTimes(1);
expect(onReset).toHaveBeenCalledWith();
});
Expand Down
4 changes: 2 additions & 2 deletions src/tests/stream/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ describe("Stream", () => {
);

expect(onPacket).toBeCalledTimes(1);
expect(onPacket).toBeCalledWith(13, Buffer.from("Hello, World!"));
expect(onPacket).toBeCalledWith(Buffer.from("Hello, World!"));
});

it("emits Reset when a remote read reset is encountered and does discard the packet so far", () => {
Expand Down Expand Up @@ -164,7 +164,7 @@ describe("Stream", () => {

expect(onReset).toBeCalledTimes(1);
expect(onPacket).toBeCalledTimes(1);
expect(onPacket).toBeCalledWith(0, Buffer.alloc(0));
expect(onPacket).toBeCalledWith(Buffer.alloc(0));
expect(onRead).toBeCalledTimes(2);
});

Expand Down

0 comments on commit 7fba3ee

Please sign in to comment.