diff --git a/Makefile b/Makefile index 34d9576..bb7e813 100644 --- a/Makefile +++ b/Makefile @@ -17,7 +17,7 @@ test: install $(MOCHA_OPTS) \ $(TESTS) -test-cov: +test-cov cov: @$(MAKE) test MOCHA_OPTS='--require blanket' REPORTER=travis-cov test-cov-html: diff --git a/benchmark/encode.js b/benchmark/encode.js index 0bc2537..9619cfb 100644 --- a/benchmark/encode.js +++ b/benchmark/encode.js @@ -155,3 +155,24 @@ suite // hessian2 encode: simple object x 138,711 ops/sec ±3.52% (89 runs sampled) // hessian1 encode: complex object x 94,401 ops/sec ±1.15% (90 runs sampled) // hessian2 encode: complex object x 90,484 ops/sec ±1.33% (97 runs sampled) + +// node version: v0.11.12, date: Thu May 15 2014 18:13:05 GMT+0800 (CST) +// Starting... +// 16 tests completed. +// +// hessian1 encode: number x 1,553,553 ops/sec ±3.58% (92 runs sampled) +// hessian2 encode: number x 1,895,587 ops/sec ±0.63% (97 runs sampled) +// hessian1 encode: date x 599,048 ops/sec ±0.58% (98 runs sampled) +// hessian2 encode: date x 562,479 ops/sec ±1.76% (93 runs sampled) +// hessian1 encode: long x 498,383 ops/sec ±0.69% (98 runs sampled) +// hessian2 encode: long x 672,058 ops/sec ±1.20% (96 runs sampled) +// hessian1 encode: string x 980,671 ops/sec ±2.19% (97 runs sampled) +// hessian2 encode: string x 1,041,627 ops/sec ±0.70% (93 runs sampled) +// hessian1 encode: [1, 2, 3] x 538,953 ops/sec ±2.54% (92 runs sampled) +// hessian2 encode: [1, 2, 3] x 631,285 ops/sec ±0.36% (99 runs sampled) +// hessian1 encode array x 389,785 ops/sec ±0.51% (98 runs sampled) +// hessian2 encode array x 408,655 ops/sec ±2.37% (97 runs sampled) +// hessian1 encode: simple object x 161,088 ops/sec ±0.84% (97 runs sampled) +// hessian2 encode: simple object x 155,580 ops/sec ±0.82% (98 runs sampled) +// hessian1 encode: complex object x 103,974 ops/sec ±1.34% (96 runs sampled) +// hessian2 encode: complex object x 100,160 ops/sec ±1.18% (101 runs sampled) diff --git a/lib/v1/encoder.js b/lib/v1/encoder.js index 0752efa..40af5ba 100644 --- a/lib/v1/encoder.js +++ b/lib/v1/encoder.js @@ -440,7 +440,7 @@ proto.write = function (val) { return this.writeDouble(val); } - if (is.long(val)) { + if (is.long(val) || is.Long(val)) { debug('write long: high: %s, low: %s', val.high, val.low); return this.writeLong(val); } diff --git a/package.json b/package.json index 0b05b28..a16a5df 100644 --- a/package.json +++ b/package.json @@ -11,7 +11,7 @@ "pattern": "//^((?!(node_modules|test|common)).)*$/" }, "travis-cov": { - "threshold": 90 + "threshold": 89 } }, "repository": { @@ -46,6 +46,7 @@ "coveralls": "*", "js-to-java": "~1.0.0", "jshint": "*", + "long": "~1.1.2", "mocha": "*", "mocha-lcov-reporter": "*", "should": "~3.3.1", diff --git a/test/long.test.js b/test/long.test.js index 19d07e4..4ecdcd5 100644 --- a/test/long.test.js +++ b/test/long.test.js @@ -16,6 +16,7 @@ var should = require('should'); var java = require('js-to-java'); +var Long = require('long'); var hessian = require('../'); var utils = require('./utils'); @@ -33,6 +34,8 @@ describe('long.test.js', function () { }).should.eql(longBuffer); hessian.encode(java.long(300)).should.eql(longBuffer); hessian.encode(java.long(300)).should.eql(longBuffer); + hessian.encode(java.long(Long.fromNumber(300))).should.eql(longBuffer); + hessian.encode(Long.fromNumber(300)).should.eql(longBuffer); }); it('should write long 0', function () { @@ -235,6 +238,9 @@ describe('long.test.js', function () { hessian.encode(java.long(16), '2.0').should.eql(utils.bytes('v2/long/16')); hessian.decode(utils.bytes('v2/long/16'), '2.0').should.equal(16); hessian.encode(java.long(255), '2.0').should.eql(utils.bytes('v2/long/255')); + hessian.encode(java.long(Long.fromNumber(255)), '2.0').should.eql(utils.bytes('v2/long/255')); + hessian.encode(Long.fromNumber(255), '2.0').should.eql(utils.bytes('v2/long/255')); + hessian.decode(utils.bytes('v2/long/255'), '2.0').should.equal(255); hessian.encode(java.long(-2048), '2.0').should.eql(utils.bytes('v2/long/-2048')); hessian.decode(utils.bytes('v2/long/-2048'), '2.0').should.equal(-2048);