Remove buffer dependency

This commit is contained in:
Jack Hadrill
2022-02-22 22:35:55 +00:00
parent 4d7cf1347f
commit 5c17b880cf
19 changed files with 106 additions and 96 deletions

View File

@@ -2,8 +2,8 @@ import { packOutgoingPacket, unpackIncomingPacket } from '../../src/messages/pac
test('Pack an outgoing packet.', () => {
// Given
const messageType = Buffer.from([0x12, 0x34])
const data = Buffer.from([0x12, 0x34, 0x56, 0x78])
const messageType = new Uint8Array([0x12, 0x34])
const data = new Uint8Array([0x12, 0x34, 0x56, 0x78])
// When
const packedPacket = packOutgoingPacket({
@@ -12,7 +12,7 @@ test('Pack an outgoing packet.', () => {
})
// Then
const expectedResult = Buffer.from([
const expectedResult = new Uint8Array([
// Message type
0x12, 0x34,
// Data length
@@ -25,7 +25,7 @@ test('Pack an outgoing packet.', () => {
test('Unpack an incoming packet.', () => {
// Given
const incomingPacket = Buffer.from([
const incomingPacket = new Uint8Array([
// Message type
0x12, 0x34,
// Sender ID
@@ -42,5 +42,5 @@ test('Unpack an incoming packet.', () => {
// Then
expect(unpackedResult.messageType).toBe(0x1234)
expect(unpackedResult.senderId).toBe(0xaabbccdd)
expect(unpackedResult.data).toMatchObject(Buffer.from([0x12, 0x34, 0x56, 0x78]))
expect(unpackedResult.data).toMatchObject(new Uint8Array([0x12, 0x34, 0x56, 0x78]))
})