diff options
Diffstat (limited to 'js')
-rw-r--r-- | js/binary/reader_test.js | 52 | ||||
-rw-r--r-- | js/gulpfile.js | 37 | ||||
-rw-r--r-- | js/package.json | 16 |
3 files changed, 96 insertions, 9 deletions
diff --git a/js/binary/reader_test.js b/js/binary/reader_test.js index 6f7e5d45..db674cf8 100644 --- a/js/binary/reader_test.js +++ b/js/binary/reader_test.js @@ -360,6 +360,58 @@ describe('binaryReaderTest', function() { /** + * 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. */ it('testStringInt64Fields', function() { diff --git a/js/gulpfile.js b/js/gulpfile.js index c5220153..cca99131 100644 --- a/js/gulpfile.js +++ b/js/gulpfile.js @@ -8,6 +8,21 @@ function exec(command, cb) { var protoc = process.env.PROTOC || '../src/protoc'; +var wellKnownTypes = [ + '../src/google/protobuf/any.proto', + '../src/google/protobuf/api.proto', + '../src/google/protobuf/compiler/plugin.proto', + '../src/google/protobuf/descriptor.proto', + '../src/google/protobuf/duration.proto', + '../src/google/protobuf/empty.proto', + '../src/google/protobuf/field_mask.proto', + '../src/google/protobuf/source_context.proto', + '../src/google/protobuf/struct.proto', + '../src/google/protobuf/timestamp.proto', + '../src/google/protobuf/type.proto', + '../src/google/protobuf/wrappers.proto', +]; + gulp.task('genproto_closure', function (cb) { exec(protoc + ' --js_out=library=testproto_libs,binary:. -I ../src -I . *.proto ../src/google/protobuf/descriptor.proto', function (err, stdout, stderr) { @@ -26,7 +41,25 @@ gulp.task('genproto_commonjs', function (cb) { }); }); -gulp.task('dist', function (cb) { +gulp.task('genproto_commonjs_wellknowntypes', function (cb) { + exec('mkdir -p commonjs_out/node_modules/google-protobuf && ' + protoc + ' --js_out=import_style=commonjs,binary:commonjs_out/node_modules/google-protobuf -I ../src ../src/google/protobuf/descriptor.proto', + function (err, stdout, stderr) { + console.log(stdout); + console.log(stderr); + cb(err); + }); +}); + +gulp.task('genproto_wellknowntypes', function (cb) { + exec(protoc + ' --js_out=import_style=commonjs,binary:. -I ../src ' + wellKnownTypes.join(' '), + function (err, stdout, stderr) { + console.log(stdout); + console.log(stderr); + cb(err); + }); +}); + +gulp.task('dist', ['genproto_wellknowntypes'], function (cb) { // TODO(haberman): minify this more aggressively. // Will require proper externs/exports. exec('./node_modules/google-closure-library/closure/bin/calcdeps.py -i message.js -i binary/reader.js -i binary/writer.js -i commonjs/export.js -p . -p node_modules/google-closure-library/closure -o compiled --compiler_jar node_modules/google-closure-compiler/compiler.jar > google-protobuf.js', @@ -55,7 +88,7 @@ gulp.task('commonjs_testdeps', function (cb) { }); }); -gulp.task('make_commonjs_out', ['dist', 'genproto_commonjs', 'commonjs_asserts', 'commonjs_testdeps'], function (cb) { +gulp.task('make_commonjs_out', ['dist', 'genproto_commonjs', 'genproto_commonjs_wellknowntypes', 'commonjs_asserts', 'commonjs_testdeps'], function (cb) { // TODO(haberman): minify this more aggressively. // Will require proper externs/exports. var cmd = "mkdir -p commonjs_out/binary && mkdir -p commonjs_out/test_node_modules && "; diff --git a/js/package.json b/js/package.json index c16417ca..657b08bd 100644 --- a/js/package.json +++ b/js/package.json @@ -1,17 +1,19 @@ { "name": "google-protobuf", - "version": "3.0.0-alpha.5", + "version": "3.0.0-alpha.6.2", "description": "Protocol Buffers for JavaScript", "main": "google-protobuf.js", - "dependencies": { + "files": [ + "google" + ], + "dependencies": {}, + "devDependencies": { + "glob": "~6.0.4", + "google-closure-compiler": "~20160619.0.0", "google-closure-library": "~20160125.0.0", "gulp": "~3.9.0", "jasmine": "~2.4.1" }, - "devDependencies": { - "google-closure-compiler": "~20151216.2.0", - "glob": "~6.0.4" - }, "scripts": { "test": "node ./node_modules/gulp/bin/gulp.js test" }, @@ -19,6 +21,6 @@ "type": "git", "url": "https://github.com/google/protobuf/tree/master/js" }, - "author": "", + "author": "Google Protocol Buffers Team", "license": "Apache-2.0" } |