Comparing version 0.2.5 to 0.2.6
@@ -21,6 +21,7 @@ 'use strict'; | ||
var fields = _ref.fields; | ||
var compareToValue = _ref.compareToValue; | ||
var rest = _objectWithoutProperties(_ref, ['compareTo', 'fields']); | ||
var rest = _objectWithoutProperties(_ref, ['compareTo', 'fields', 'compareToValue']); | ||
compareTo = getField(compareTo, rootNode); | ||
compareTo = compareToValue !== undefined ? compareToValue : getField(compareTo, rootNode); | ||
if (typeof fields[compareTo] === 'undefined' && typeof rest['default'] === "undefined") throw new Error(compareTo + " has no associated fieldInfo in switch"); | ||
@@ -41,6 +42,7 @@ | ||
var fields = _ref2.fields; | ||
var compareToValue = _ref2.compareToValue; | ||
var rest = _objectWithoutProperties(_ref2, ['compareTo', 'fields']); | ||
var rest = _objectWithoutProperties(_ref2, ['compareTo', 'fields', 'compareToValue']); | ||
compareTo = getField(compareTo, rootNode); | ||
compareTo = compareToValue !== undefined ? compareToValue : getField(compareTo, rootNode); | ||
if (typeof fields[compareTo] === 'undefined' && typeof rest['default'] === "undefined") throw new Error(compareTo + " has no associated fieldInfo in switch"); | ||
@@ -60,6 +62,7 @@ | ||
var fields = _ref3.fields; | ||
var compareToValue = _ref3.compareToValue; | ||
var rest = _objectWithoutProperties(_ref3, ['compareTo', 'fields']); | ||
var rest = _objectWithoutProperties(_ref3, ['compareTo', 'fields', 'compareToValue']); | ||
compareTo = getField(compareTo, rootNode); | ||
compareTo = compareToValue !== undefined ? compareToValue : getField(compareTo, rootNode); | ||
if (typeof fields[compareTo] === 'undefined' && typeof rest['default'] === "undefined") throw new Error(compareTo + " has no associated fieldInfo in switch"); | ||
@@ -66,0 +69,0 @@ |
{ | ||
"name": "protodef", | ||
"version": "0.2.5", | ||
"version": "0.2.6", | ||
"description": "A simple yet powerful way to define binary protocols", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -114,9 +114,15 @@ # ProtoDef | ||
### 0.2.6 | ||
* add compareToValue (optional) option to switch | ||
### 0.2.5 | ||
* fix small error in switch | ||
### 0.2.4 | ||
* get back the example file as one file for simplicity and for tonic | ||
### 0.2.3 | ||
* fix a small mistake in mapping error | ||
@@ -123,0 +129,0 @@ * improve internal code |
@@ -8,4 +8,4 @@ var { getField, getFieldInfo, tryDoc} = require('../utils'); | ||
function readSwitch(buffer, offset, {compareTo,fields,...rest}, rootNode) { | ||
compareTo = getField(compareTo, rootNode); | ||
function readSwitch(buffer, offset, {compareTo,fields,compareToValue,...rest}, rootNode) { | ||
compareTo = compareToValue!==undefined ? compareToValue : getField(compareTo, rootNode); | ||
if (typeof fields[compareTo] === 'undefined' && typeof rest.default === "undefined") | ||
@@ -20,4 +20,4 @@ throw new Error(compareTo + " has no associated fieldInfo in switch"); | ||
function writeSwitch(value, buffer, offset, {compareTo,fields,...rest}, rootNode) { | ||
compareTo = getField(compareTo, rootNode); | ||
function writeSwitch(value, buffer, offset, {compareTo,fields,compareToValue,...rest}, rootNode) { | ||
compareTo = compareToValue!==undefined ? compareToValue : getField(compareTo, rootNode); | ||
if (typeof fields[compareTo] === 'undefined' && typeof rest.default === "undefined") | ||
@@ -31,4 +31,4 @@ throw new Error(compareTo + " has no associated fieldInfo in switch"); | ||
function sizeOfSwitch(value, {compareTo,fields,...rest}, rootNode) { | ||
compareTo = getField(compareTo, rootNode); | ||
function sizeOfSwitch(value, {compareTo,fields,compareToValue,...rest}, rootNode) { | ||
compareTo = compareToValue!==undefined ? compareToValue : getField(compareTo, rootNode); | ||
if (typeof fields[compareTo] === 'undefined' && typeof rest.default === "undefined") | ||
@@ -35,0 +35,0 @@ throw new Error(compareTo + " has no associated fieldInfo in switch"); |
@@ -1,4 +0,6 @@ | ||
var ITERATIONS = 100000; | ||
var ITERATIONS = 10000; | ||
var ProtoDef=require("../").ProtoDef; | ||
var ProtoDef=require("protodef").ProtoDef; | ||
var Parser=require("protodef").Parser; | ||
var Serializer=require("protodef").Serializer; | ||
@@ -82,14 +84,26 @@ var testDataWrite = [ | ||
var inputData = []; | ||
var size=ITERATIONS*testDataWrite.length; | ||
it("bench serializing",function(done){ | ||
var start, i, j; | ||
console.log('Beginning write test'); | ||
var serializer = new Serializer(proto, "packet"); | ||
start = Date.now(); | ||
for(i = 0; i < ITERATIONS; i++) { | ||
for(j = 0; j < testDataWrite.length; j++) { | ||
inputData.push(proto.createPacketBuffer("packet",testDataWrite[j])); | ||
serializer.write(testDataWrite[j]); | ||
} | ||
} | ||
var result=(Date.now() - start) / 1000; | ||
console.log('Finished write test in ' + result + ' seconds'); | ||
done(); | ||
function wait(cb) { | ||
var i=0; | ||
serializer.on("data",function(data){ | ||
inputData.push(data); | ||
i++; | ||
if(i==size) | ||
cb(); | ||
}); | ||
} | ||
wait(function(){ | ||
console.log('Finished write test in ' + (Date.now() - start) / 1000 + ' seconds'); | ||
done(); | ||
}); | ||
}); | ||
@@ -99,9 +113,18 @@ | ||
console.log('Beginning read test'); | ||
start = Date.now(); | ||
for (j = 0; j < inputData.length; j++) { | ||
proto.parsePacketBuffer("packet",inputData[j]); | ||
var start = Date.now(); | ||
var parser=new Parser(proto,"packet"); | ||
inputData.forEach(function(data) {parser.write(data)}); | ||
function wait(cb) { | ||
var i=0; | ||
parser.on("data",function(){ | ||
i++; | ||
if(i==inputData.length) | ||
cb(); | ||
}); | ||
} | ||
console.log('Finished read test in ' + (Date.now() - start) / 1000 + ' seconds'); | ||
done(); | ||
wait(function(){ | ||
console.log('Finished read test in ' + (Date.now() - start) / 1000 + ' seconds'); | ||
done(); | ||
}); | ||
}); | ||
}); |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 1 instance in 1 package
155
0
128269
34
2151