You're Invited:Meet the Socket Team at BlackHat and DEF CON in Las Vegas, Aug 4-6.RSVP
Socket
Book a DemoInstallSign in
Socket

binary-parser-encoder

Package Overview
Dependencies
Maintainers
1
Versions
11
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

binary-parser-encoder - npm Package Compare versions

Comparing version

to
1.4.5

.nyc_output/519d562d-9cdb-4951-853c-2c3ea9351ca8.json

23

lib/binary_parser.js

@@ -79,2 +79,5 @@ //========================================================================================

: 256;
this.encoderOpts = {
bitEndianess: false
};
};

@@ -251,2 +254,7 @@

Parser.prototype.encoderSetOptions = function(opts) {
Object.assign(this.encoderOpts, opts);
return this;
};
Parser.prototype.create = function(constructorFn) {

@@ -471,2 +479,3 @@ if (!(constructorFn instanceof Function)) {

parser.endian = this.endian;
parser.encoderOpts = this.encoderOpts;

@@ -674,11 +683,21 @@ if (this.head) {

var isBitLittleEndian =
this.endian === "le" && this.encoderOpts.bitEndianess;
var tmpVal = ctx.generateTmpVariable();
var boundVal = ctx.generateTmpVariable();
ctx.pushCode("var {0} = 0;", tmpVal);
ctx.pushCode("var {0} = 0;", boundVal);
var bitOffset = 0;
ctx.bitFields.forEach(function(parser) {
ctx.pushCode(
"{0} = ({1} & {2});",
boundVal,
parser.varName,
(1 << parser.options.length) - 1
);
ctx.pushCode(
"{0} |= ({1} << {2});",
tmpVal,
parser.varName,
sum - parser.options.length - bitOffset
boundVal,
isBitLittleEndian ? bitOffset : sum - bitOffset - parser.options.length
);

@@ -685,0 +704,0 @@ ctx.pushCode("{0} = {0} >>> 0;", tmpVal);

12

package.json
{
"name": "binary-parser-encoder",
"version": "1.4.4",
"version": "1.4.5",
"description": "Blazing-fast binary parser builder",
"main": "lib/binary_parser.js",
"devDependencies": {
"istanbul": "^0.4.5",
"mocha": "^3.5.3",
"prettier": "^1.9.2"
"mocha": "^6.1.4",
"nyc": "^14.1.0",
"prettier": "^1.17.1"
},

@@ -15,3 +15,3 @@ "scripts": {

"test": "npx mocha --reporter spec",
"cover": "npx istanbul cover --report html node_modules/.bin/_mocha"
"cover": "npx nyc --reporter html mocha"
},

@@ -47,3 +47,3 @@ "keywords": [

"dependencies": {
"smart-buffer": "^4.0.1"
"smart-buffer": "^4.0.2"
},

@@ -50,0 +50,0 @@ "engines": {

@@ -341,2 +341,17 @@ # Binary-parser-encoder

### setEncoderOptions(opts)
Set specific options for encoding.
Current supported `opts` object may contain:
- bitEndianess: true|false (default false) When true, tell the encoder to respect endianess BITs order, so that
encoding is exactly the reverse of the parsing process for bits fields.
```javascript
var parser = new Parser()
.endianess("little")
.setEncoderOpts({bitEndianess: true}) // Use BITs endianess for bits fields
.bit4("a")
.bit4("b")
.uint16("c");
```
### namely(alias)

@@ -343,0 +358,0 @@ Set an alias to this parser, so there will be an opportunity to refer to it by