Skip to content

Commit 4951d40

Browse files
committed
Use prettier's default formatting style
1 parent e9d6c96 commit 4951d40

File tree

15 files changed

+1007
-1279
lines changed

15 files changed

+1007
-1279
lines changed

.prettierrc

Lines changed: 0 additions & 7 deletions
This file was deleted.

benchmark/bench.js

Lines changed: 58 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -1,51 +1,54 @@
1-
var binary = require('binary');
2-
var Benchmark = require('benchmark');
3-
var bp = require('binparse').bp;
4-
var Parser = require('binary-parser').Parser;
5-
var Destruct = require('destruct-js');
6-
const Struct = require('structron');
1+
var binary = require("binary");
2+
var Benchmark = require("benchmark");
3+
var bp = require("binparse").bp;
4+
var Parser = require("../dist/binary_parser").Parser;
5+
var Destruct = require("destruct-js");
6+
const Struct = require("structron");
77

8-
var suite = new Benchmark.Suite;
8+
var suite = new Benchmark.Suite();
99

1010
// binparse
11-
const PointParser = bp.object('Point', {
12-
x: bp.lu16,
13-
y: bp.lu16,
14-
z: bp.lu16,
11+
const PointParser = bp.object("Point", {
12+
x: bp.lu16,
13+
y: bp.lu16,
14+
z: bp.lu16,
1515
});
1616

17-
const PointsParser = bp.object('SimpleObject', {
18-
length: bp.variable('len', bp.lu32),
19-
points: bp.array('Points', PointParser, 'len'),
17+
const PointsParser = bp.object("SimpleObject", {
18+
length: bp.variable("len", bp.lu32),
19+
points: bp.array("Points", PointParser, "len"),
2020
});
2121

2222
// binary-parser
23-
const Points = new Parser()
24-
.uint32le('len')
25-
.array('points', {
26-
length: 'len',
27-
type: new Parser()
28-
.uint16le('x')
29-
.uint16le('y')
30-
.uint16le('z')
31-
});
23+
const Points = new Parser().uint32le("len").array("points", {
24+
length: "len",
25+
type: new Parser().uint16le("x").uint16le("y").uint16le("z"),
26+
});
3227

3328
// destruct-js
34-
const spec = new Destruct.Spec({mode: Destruct.Mode.LE});
35-
spec.field('len', Destruct.UInt32)
36-
.loop('points', (r) => r.len, new Destruct.Spec({mode: Destruct.Mode.LE})
37-
.field('x', Destruct.UInt16)
38-
.field('y', Destruct.UInt16)
39-
.field('z', Destruct.UInt16));
29+
const spec = new Destruct.Spec({ mode: Destruct.Mode.LE });
30+
spec
31+
.field("len", Destruct.UInt32)
32+
.loop(
33+
"points",
34+
(r) => r.len,
35+
new Destruct.Spec({ mode: Destruct.Mode.LE })
36+
.field("x", Destruct.UInt16)
37+
.field("y", Destruct.UInt16)
38+
.field("z", Destruct.UInt16)
39+
);
4040

4141
// structron
4242
const PointsStruct = new Struct()
43-
.addMember(Struct.TYPES.UINT_LE, 'len')
43+
.addMember(Struct.TYPES.UINT_LE, "len")
4444
.addArray(
45-
new Struct().addMember(Struct.TYPES.USHORT_LE, 'x')
46-
.addMember(Struct.TYPES.USHORT_LE, 'y')
47-
.addMember(Struct.TYPES.USHORT_LE, 'z'),
48-
'points', 0, 'len'
45+
new Struct()
46+
.addMember(Struct.TYPES.USHORT_LE, "x")
47+
.addMember(Struct.TYPES.USHORT_LE, "y")
48+
.addMember(Struct.TYPES.USHORT_LE, "z"),
49+
"points",
50+
0,
51+
"len"
4952
);
5053

5154
// Prepare input
@@ -54,29 +57,29 @@ var buf = Buffer.alloc(4 + n * 2 * 3);
5457

5558
buf.writeUInt32LE(n, 0);
5659
for (var i = 0; i < n; i++) {
57-
buf.writeUInt16LE(123, i * 6 + 0 + 4);
58-
buf.writeUInt16LE(456, i * 6 + 2 + 4);
59-
buf.writeUInt16LE(789, i * 6 + 4 + 4);
60+
buf.writeUInt16LE(123, i * 6 + 0 + 4);
61+
buf.writeUInt16LE(456, i * 6 + 2 + 4);
62+
buf.writeUInt16LE(789, i * 6 + 4 + 4);
6063
}
6164

6265
// Run benchmarks
6366
suite
64-
.add('binparse', function() {
65-
const points = PointsParser.read(buf);
66-
})
67-
.add('binary-parser', function() {
68-
const points = Points.parse(buf);
69-
})
70-
.add('destruct-js', function() {
71-
const points = spec.read(buf);
72-
})
73-
.add('structron', function() {
74-
const points = PointsStruct.read(buf);
75-
})
76-
.on('cycle', function(event) {
67+
.add("binparse", function () {
68+
const points = PointsParser.read(buf);
69+
})
70+
.add("binary-parser", function () {
71+
const points = Points.parse(buf);
72+
})
73+
.add("destruct-js", function () {
74+
const points = spec.read(buf);
75+
})
76+
.add("structron", function () {
77+
const points = PointsStruct.read(buf);
78+
})
79+
.on("cycle", function (event) {
7780
console.log(String(event.target));
78-
})
79-
.on('complete', function() {
80-
console.log('Fastest is ' + this.filter('fastest').map('name'));
81-
})
82-
.run({ 'async': true });
81+
})
82+
.on("complete", function () {
83+
console.log("Fastest is " + this.filter("fastest").map("name"));
84+
})
85+
.run({ async: true });

example/bmp.js

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
var Parser = require('../dist/binary_parser').Parser;
1+
var Parser = require("../dist/binary_parser").Parser;
22

33
// C structure BITMAPFILEHEADER
44
// typedef struct tagBITMAPFILEHEADER {
@@ -9,15 +9,15 @@ var Parser = require('../dist/binary_parser').Parser;
99
// DWORD bfOffBits;
1010
// } BITMAPFILEHEADER, *PBITMAPFILEHEADER;
1111
var bmpFileHeader = new Parser()
12-
.endianess('little')
13-
.string('type', {
12+
.endianess("little")
13+
.string("type", {
1414
length: 2,
15-
assert: 'BM',
15+
assert: "BM",
1616
})
17-
.uint32('size')
18-
.uint16('reserved1')
19-
.uint16('reserved2')
20-
.uint32('offBits');
17+
.uint32("size")
18+
.uint16("reserved1")
19+
.uint16("reserved2")
20+
.uint32("offBits");
2121

2222
// C structure BITMAPINFOHEADER definition
2323
// typedef struct tagBITMAPINFOHEADER {
@@ -34,27 +34,27 @@ var bmpFileHeader = new Parser()
3434
// DWORD biClrImportant;
3535
// } BITMAPINFOHEADER;
3636
var bmpInfoHeader = new Parser()
37-
.endianess('little')
38-
.uint32('size')
39-
.int32('width')
40-
.int32('height')
41-
.uint16('planes')
42-
.uint16('bitCount')
43-
.uint32('compression')
44-
.uint32('sizeImage')
45-
.int32('xPelsPerMeter')
46-
.int32('yPelsPerMeter')
47-
.uint32('clrUsed')
48-
.uint32('clrImportant');
37+
.endianess("little")
38+
.uint32("size")
39+
.int32("width")
40+
.int32("height")
41+
.uint16("planes")
42+
.uint16("bitCount")
43+
.uint32("compression")
44+
.uint32("sizeImage")
45+
.int32("xPelsPerMeter")
46+
.int32("yPelsPerMeter")
47+
.uint32("clrUsed")
48+
.uint32("clrImportant");
4949

5050
var bmpFile = new Parser()
51-
.nest('fileHeader', {
51+
.nest("fileHeader", {
5252
type: bmpFileHeader,
5353
})
54-
.nest('infoHeader', {
54+
.nest("infoHeader", {
5555
type: bmpInfoHeader,
5656
});
5757

58-
require('fs').readFile('test.bmp', function (err, data) {
58+
require("fs").readFile("test.bmp", function (err, data) {
5959
console.log(bmpFile.parse(data));
6060
});

example/classfile.js

Lines changed: 35 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,55 +1,55 @@
1-
var Parser = require('../dist/binary_parser').Parser;
1+
var Parser = require("../dist/binary_parser").Parser;
22

3-
var ConstantClassInfo = Parser.start().uint16be('name_index');
3+
var ConstantClassInfo = Parser.start().uint16be("name_index");
44

55
var ConstantFieldrefInfo = Parser.start()
6-
.uint16be('class_index')
7-
.uint16be('name_and_type_index');
6+
.uint16be("class_index")
7+
.uint16be("name_and_type_index");
88

99
var ConstantMethodrefInfo = Parser.start()
10-
.uint16be('class_index')
11-
.uint16be('name_and_type_index');
10+
.uint16be("class_index")
11+
.uint16be("name_and_type_index");
1212

1313
var ConstantInterfaceMethodrefInfo = Parser.start()
14-
.uint16be('class_index')
15-
.uint16be('name_and_type_index');
14+
.uint16be("class_index")
15+
.uint16be("name_and_type_index");
1616

17-
var ConstantStringInfo = Parser.start().uint16be('string_index');
17+
var ConstantStringInfo = Parser.start().uint16be("string_index");
1818

19-
var ConstantIntegerInfo = Parser.start().uint32be('bytes');
19+
var ConstantIntegerInfo = Parser.start().uint32be("bytes");
2020

21-
var ConstantFloatInfo = Parser.start().uint32be('bytes');
21+
var ConstantFloatInfo = Parser.start().uint32be("bytes");
2222

2323
var ConstantLongInfo = Parser.start()
24-
.uint32be('high_bytes')
25-
.uint32be('low_bytes');
24+
.uint32be("high_bytes")
25+
.uint32be("low_bytes");
2626

2727
var ConstantDoubleInfo = Parser.start()
28-
.uint32be('high_bytes')
29-
.uint32be('low_bytes');
28+
.uint32be("high_bytes")
29+
.uint32be("low_bytes");
3030

3131
var ConstantNameAndTypeInfo = Parser.start()
32-
.uint16be('name_index')
33-
.uint16be('descriptor_index');
32+
.uint16be("name_index")
33+
.uint16be("descriptor_index");
3434

3535
var ConstantUtf8Info = Parser.start()
36-
.uint16be('len')
37-
.string('bytes', { length: 'len' });
36+
.uint16be("len")
37+
.string("bytes", { length: "len" });
3838

3939
var ConstantMethodHandleInfo = Parser.start()
40-
.uint8('reference_kind')
41-
.uint16be('reference_index');
40+
.uint8("reference_kind")
41+
.uint16be("reference_index");
4242

43-
var ConstantMethodTypeInfo = Parser.start().uint16be('descriptor_index');
43+
var ConstantMethodTypeInfo = Parser.start().uint16be("descriptor_index");
4444

4545
var ConstantInvokeDynamicInfo = Parser.start()
46-
.uint16be('bootstrap_method_attr_index')
47-
.uint16be('name_and_type_index');
46+
.uint16be("bootstrap_method_attr_index")
47+
.uint16be("name_and_type_index");
4848

4949
var CpInfo = Parser.start()
50-
.uint8('tag')
51-
.choice('info', {
52-
tag: 'tag',
50+
.uint8("tag")
51+
.choice("info", {
52+
tag: "tag",
5353
choices: {
5454
7: ConstantClassInfo,
5555
9: ConstantFieldrefInfo,
@@ -68,18 +68,18 @@ var CpInfo = Parser.start()
6868
});
6969

7070
var ClassFile = Parser.start()
71-
.endianess('big')
72-
.uint32('magic', { assert: 0xcafebabe })
73-
.uint16('minor_version')
74-
.uint16('major_version')
75-
.uint16('constant_pool_count')
76-
.array('cp_info', {
71+
.endianess("big")
72+
.uint32("magic", { assert: 0xcafebabe })
73+
.uint16("minor_version")
74+
.uint16("major_version")
75+
.uint16("constant_pool_count")
76+
.array("cp_info", {
7777
type: CpInfo,
7878
length: function () {
7979
return this.constant_pool_count - 1;
8080
},
8181
});
8282

83-
require('fs').readFile('Hello.class', function (err, data) {
84-
console.log(require('util').inspect(ClassFile.parse(data), { depth: null }));
83+
require("fs").readFile("Hello.class", function (err, data) {
84+
console.log(require("util").inspect(ClassFile.parse(data), { depth: null }));
8585
});

0 commit comments

Comments
 (0)