Skip to content

Commit f9b663f

Browse files
committed
add: control key(__skip === __reserve)
1 parent b4ee858 commit f9b663f

File tree

2 files changed

+22
-5
lines changed

2 files changed

+22
-5
lines changed

binary_to_json.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ export class BinaryToJSON {
6363

6464
private getValue(br: BinaryReader, format:{}) : number | null | string {
6565
const [key, val] = Object.entries(format)[0];
66-
if (key === "__reserve") {
66+
if (key === "__reserve" || key === "__skip") {
6767
br.seek(br.position + Number(val));
6868
return null;
6969
}

test.ts

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -132,17 +132,34 @@ Deno.test(
132132
assertEquals(0x0001020304050607, data['dat']);
133133
},
134134
);
135-
/*
136135
Deno.test(
137136
"complex dat",
138137
function(): void {
139-
const file = Deno.openSync("xxx.DAT");
138+
/*
139+
const file = Deno.openSync("XXX.DAT");
140140
const buffer = Deno.readAllSync(file);
141141
Deno.close(file.rid);
142142
const format = JSON.parse(Deno.readTextFileSync("prct_format.json"));
143143
const b2j = new BinaryToJSON();
144144
const data: any = b2j.convert(buffer, format);
145-
console.log(data);
145+
//console.log(data);
146+
*/
146147
},
147148
);
148-
*/
149+
150+
Deno.test(
151+
"skip bytes",
152+
function(): void {
153+
const buffer = new ArrayBuffer(4);
154+
const arry = new Uint8Array(buffer);
155+
arry[0] = 0x0D;
156+
arry[1] = 0x0C;
157+
arry[2] = 0x0B;
158+
arry[3] = 0x0A;
159+
const format = [{"__skip":2},{"dat":2}];
160+
const b2j = new BinaryToJSON();
161+
const data: any = b2j.convert(arry, format);
162+
console.log(data);
163+
assertEquals(0x0B0A, data['dat']);
164+
},
165+
);

0 commit comments

Comments
 (0)