Skip to content

Commit

Permalink
Merge branch 'main' of github.com:ykisii/BinaryToJSON into main
Browse files Browse the repository at this point in the history
  • Loading branch information
ykisii committed Apr 28, 2023
2 parents 47dbbc5 + ed9900d commit 35bc458
Showing 1 changed file with 39 additions and 0 deletions.
39 changes: 39 additions & 0 deletions test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,4 +92,43 @@ Deno.test(
console.log(data);
assertEquals({}, data);
},
);

Deno.test(
"read 5bytes",
function(): void {
const buffer = new ArrayBuffer(5);
const arry = new Uint8Array(buffer);
arry[0] = 0x00;
arry[1] = 0x01;
arry[2] = 0x02;
arry[3] = 0x03;
arry[4] = 0x04;
const format = [{"dat":5}];
const b2j = new BinaryToJSON();
const data: any = b2j.convert(arry, format);
console.log(data);
assertEquals(0x0001020304, data['dat']);
},
);

Deno.test(
"read 8bytes",
function(): void {
const buffer = new ArrayBuffer(8);
const arry = new Uint8Array(buffer);
arry[0] = 0x00;
arry[1] = 0x01;
arry[2] = 0x02;
arry[3] = 0x03;
arry[4] = 0x04;
arry[5] = 0x05;
arry[6] = 0x06;
arry[7] = 0x07;
const format = [{"dat":8}];
const b2j = new BinaryToJSON();
const data: any = b2j.convert(arry, format);
console.log(data);
assertEquals(0x0001020304050607, data['dat']);
},
);

0 comments on commit 35bc458

Please sign in to comment.