Socket
Socket
Sign inDemoInstall

google-protobuf

Package Overview
Dependencies
210
Maintainers
1
Versions
90
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 3.0.0-alpha.5 to 3.0.0-alpha.6

52

binary/reader_test.js

@@ -363,2 +363,54 @@ // Protocol Buffers - Google's data interchange format

/**
* Tests reading a field from hexadecimal string (format: '08 BE EF').
* @param {Function} readField
* @param {number} expected
* @param {string} hexString
*/
function doTestHexStringVarint_(readField, expected, hexString) {
var bytesCount = (hexString.length + 1) / 3;
var bytes = new Uint8Array(bytesCount);
for (var i = 0; i < bytesCount; i++) {
byte = parseInt(hexString.substring(i * 3, i * 3 + 2), 16);
bytes[i] = byte;
}
var reader = jspb.BinaryReader.alloc(bytes);
reader.nextField();
assertEquals(expected, readField.call(reader));
}
/**
* Tests non-canonical redundant varint decoding.
*/
it('testRedundantVarintFields', function() {
assertNotNull(jspb.BinaryReader.prototype.readUint32);
assertNotNull(jspb.BinaryReader.prototype.readUint64);
assertNotNull(jspb.BinaryReader.prototype.readSint32);
assertNotNull(jspb.BinaryReader.prototype.readSint64);
// uint32 and sint32 take no more than 5 bytes
// 08 - field prefix (type = 0 means varint)
doTestHexStringVarint_(
jspb.BinaryReader.prototype.readUint32,
12, '08 8C 80 80 80 00');
// 11 stands for -6 in zigzag encoding
doTestHexStringVarint_(
jspb.BinaryReader.prototype.readSint32,
-6, '08 8B 80 80 80 00');
// uint64 and sint64 take no more than 10 bytes
// 08 - field prefix (type = 0 means varint)
doTestHexStringVarint_(
jspb.BinaryReader.prototype.readUint64,
12, '08 8C 80 80 80 80 80 80 80 80 00');
// 11 stands for -6 in zigzag encoding
doTestHexStringVarint_(
jspb.BinaryReader.prototype.readSint64,
-6, '08 8B 80 80 80 80 80 80 80 80 00');
});
/**
* Tests 64-bit fields that are handled as strings.

@@ -365,0 +417,0 @@ */

@@ -200,3 +200,38 @@ // Protocol Buffers - Google's data interchange format

/*
* Going from decimal strings to hash strings should be lossless.
*/
it('testDecimalToHashConversion', function() {
var result;
var convert = jspb.utils.decimalStringToHash64;
result = convert('0');
assertEquals(String.fromCharCode.apply(null,
[0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00]), result);
result = convert('-1');
assertEquals(String.fromCharCode.apply(null,
[0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF]), result);
result = convert('18446744073709551615');
assertEquals(String.fromCharCode.apply(null,
[0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF]), result);
result = convert('9223372036854775808');
assertEquals(String.fromCharCode.apply(null,
[0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80]), result);
result = convert('-9223372036854775808');
assertEquals(String.fromCharCode.apply(null,
[0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80]), result);
result = convert('123456789123456789');
assertEquals(String.fromCharCode.apply(null,
[0x15, 0x5F, 0xD0, 0xAC, 0x4B, 0x9B, 0xB6, 0x01]), result);
result = convert('-123456789123456789');
assertEquals(String.fromCharCode.apply(null,
[0xEB, 0xA0, 0x2F, 0x53, 0xB4, 0x64, 0x49, 0xFE]), result);
});
/**

@@ -203,0 +238,0 @@ * Going from hash strings to hex strings should be lossless.

@@ -571,2 +571,52 @@ // Protocol Buffers - Google's data interchange format

/**
* Converts a signed or unsigned decimal string into its hash string
* representation.
* @param {string} dec
* @return {string}
*/
jspb.utils.decimalStringToHash64 = function(dec) {
goog.asserts.assert(dec.length > 0);
// Check for minus sign.
var minus = false;
if (dec[0] === '-') {
minus = true;
dec = dec.slice(1);
}
// Store result as a byte array.
var resultBytes = [0, 0, 0, 0, 0, 0, 0, 0];
// Set result to m*result + c.
function muladd(m, c) {
for (var i = 0; i < 8 && (m !== 1 || c > 0); i++) {
var r = m * resultBytes[i] + c;
resultBytes[i] = r & 0xFF;
c = r >>> 8;
}
}
// Negate the result bits.
function neg() {
for (var i = 0; i < 8; i++) {
resultBytes[i] = (~resultBytes[i]) & 0xFF;
}
}
// For each decimal digit, set result to 10*result + digit.
for (var i = 0; i < dec.length; i++) {
muladd(10, jspb.utils.DIGITS.indexOf(dec[i]));
}
// If there's a minus sign, convert into two's complement.
if (minus) {
neg();
muladd(1, 1);
}
return String.fromCharCode.apply(null, resultBytes);
};
/**
* Converts an 8-character hash string into its hexadecimal representation.

@@ -573,0 +623,0 @@ * @param {string} hash

17

gulpfile.js
var gulp = require('gulp');
var exec = require('child_process').exec;
var execFile = require('child_process').execFile;
var glob = require('glob');
function exec(command, cb) {
execFile('sh', ['-c', command], cb);
}
var protoc = process.env.PROTOC || '../src/protoc';

@@ -45,3 +49,12 @@

gulp.task('make_commonjs_out', ['dist', 'genproto_commonjs', 'commonjs_asserts'], function (cb) {
gulp.task('commonjs_testdeps', function (cb) {
exec('mkdir -p commonjs_out/test_node_modules && ./node_modules/google-closure-library/closure/bin/calcdeps.py -i commonjs/export_testdeps.js -p . -p node_modules/google-closure-library/closure -o compiled --compiler_jar node_modules/google-closure-compiler/compiler.jar > commonjs_out/test_node_modules/testdeps_commonjs.js',
function (err, stdout, stderr) {
console.log(stdout);
console.log(stderr);
cb(err);
});
});
gulp.task('make_commonjs_out', ['dist', 'genproto_commonjs', 'commonjs_asserts', 'commonjs_testdeps'], function (cb) {
// TODO(haberman): minify this more aggressively.

@@ -48,0 +61,0 @@ // Will require proper externs/exports.

12

package.json
{
"name": "google-protobuf",
"version": "3.0.0-alpha.5",
"version": "3.0.0-alpha.6",
"description": "Protocol Buffers for JavaScript",
"main": "google-protobuf.js",
"dependencies": {
},
"devDependencies": {
"glob": "~6.0.4",
"google-closure-compiler": "~20151216.2.0",
"google-closure-library": "~20160125.0.0",

@@ -15,4 +11,8 @@ "gulp": "~3.9.0",

},
"devDependencies": {
"google-closure-compiler": "~20151216.2.0",
"glob": "~6.0.4"
},
"scripts": {
"test": "./node_modules/gulp/bin/gulp.js test"
"test": "node ./node_modules/gulp/bin/gulp.js test"
},

@@ -19,0 +19,0 @@ "repository": {

Sorry, the diff of this file is too big to display

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc