Skip to content

Commit cac82a1

Browse files
committed
Add BitField documentation.
1 parent 511102c commit cac82a1

File tree

1 file changed

+25
-1
lines changed

1 file changed

+25
-1
lines changed

README.md

+25-1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,12 @@ Primitive Structures:
1818
* **String**: char, string(len)
1919
* **Array**: array(type, len)
2020
* **Position**: tell, skip(len), seek(pos), seek(pos, func)
21+
* **BitField**: bitfield(structure, bitShift)
22+
* ``structure`` is ``Object`` with keys as field names and bit-sizes of each value (functions returning bit-sizes can be used as well); can contain sub-structures inside.
23+
* ``bitField`` is starting binary shift (if needed).
24+
* BitField values are returned as unsigned integer (so you can work with them using simple JavaScript binary operators).
25+
* Left-to-right (like big-endian) mode is the only supported for now.
26+
* BitField structures are always padded to one byte after parsing.
2127

2228
jParser Methods:
2329

@@ -51,14 +57,32 @@ var parser = new jParser(file, {
5157
recordIndex: 'int32',
5258
hash: ['array', 'uint32', 4],
5359
fileName: ['string', 256],
60+
flags: ['bitfield', {
61+
version: 2,
62+
precisionFlag: 1,
63+
availabilityFlag: 1,
64+
marker: {
65+
part1: 2,
66+
part2: 2
67+
}
68+
}]
5469
}
5570
});
5671
parser.parse('header');
5772
// {
5873
// fileId: 42,
5974
// recordIndex: 6002,
6075
// hash: [4237894687, 3491173757, 3626834111, 2631772842],
61-
// fileName: ".\\Resources\\Excel\\Items_Weapons.xls"
76+
// fileName: ".\\Resources\\Excel\\Items_Weapons.xls",
77+
// flags: {
78+
// version: 3,
79+
// precisionFlag: 0,
80+
// availabilityFlag: 1,
81+
// marker: {
82+
// part1: 2,
83+
// part2: 0
84+
// }
85+
// }
6286
// }
6387
```
6488

0 commit comments

Comments
 (0)