Skip to content

Commit

Permalink
add: control key(__skip === __reserve)
Browse files Browse the repository at this point in the history
  • Loading branch information
ykisii committed May 22, 2023
1 parent b4ee858 commit f9b663f
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 5 deletions.
2 changes: 1 addition & 1 deletion binary_to_json.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ export class BinaryToJSON {

private getValue(br: BinaryReader, format:{}) : number | null | string {
const [key, val] = Object.entries(format)[0];
if (key === "__reserve") {
if (key === "__reserve" || key === "__skip") {
br.seek(br.position + Number(val));
return null;
}
Expand Down
25 changes: 21 additions & 4 deletions test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,17 +132,34 @@ Deno.test(
assertEquals(0x0001020304050607, data['dat']);
},
);
/*
Deno.test(
"complex dat",
function(): void {
const file = Deno.openSync("xxx.DAT");
/*
const file = Deno.openSync("XXX.DAT");
const buffer = Deno.readAllSync(file);
Deno.close(file.rid);
const format = JSON.parse(Deno.readTextFileSync("prct_format.json"));
const b2j = new BinaryToJSON();
const data: any = b2j.convert(buffer, format);
console.log(data);
//console.log(data);
*/
},
);
*/

Deno.test(
"skip bytes",
function(): void {
const buffer = new ArrayBuffer(4);
const arry = new Uint8Array(buffer);
arry[0] = 0x0D;
arry[1] = 0x0C;
arry[2] = 0x0B;
arry[3] = 0x0A;
const format = [{"__skip":2},{"dat":2}];
const b2j = new BinaryToJSON();
const data: any = b2j.convert(arry, format);
console.log(data);
assertEquals(0x0B0A, data['dat']);
},
);

0 comments on commit f9b663f

Please sign in to comment.