Browse Source

readVarInt -> readVarIntNum

"varInt" refers to the varInt object, which is not actually implemented yet.
This function should therefore really be called readVarIntNum.
patch-2
Ryan X. Charles 11 years ago
parent
commit
3c668c9cf0
  1. 2
      lib/bufferreader.js
  2. 12
      test/bufferreader.js

2
lib/bufferreader.js

@ -79,7 +79,7 @@ BufferReader.prototype.readUInt64LEBN = function() {
return bn;
};
BufferReader.prototype.readVarInt = function() {
BufferReader.prototype.readVarIntNum = function() {
var first = this.readUInt8();
switch (first) {
case 0xFD:

12
test/bufferreader.js

@ -168,32 +168,32 @@ describe('BufferReader', function() {
});
describe('#readVarInt', function() {
describe('#readVarIntNum', function() {
it('should read a 1 byte varint', function() {
var buf = new Buffer([50]);
var br = new BufferReader({buf: buf});
br.readVarInt().should.equal(50);
br.readVarIntNum().should.equal(50);
});
it('should read a 3 byte varint', function() {
var buf = new Buffer([253, 253, 0]);
var br = new BufferReader({buf: buf});
br.readVarInt().should.equal(253);
br.readVarIntNum().should.equal(253);
});
it('should read a 5 byte varint', function() {
var buf = new Buffer([254, 0, 0, 0, 0]);
buf.writeUInt32LE(50000, 1);
var br = new BufferReader({buf: buf});
br.readVarInt().should.equal(50000);
br.readVarIntNum().should.equal(50000);
});
it('should throw an error on a 9 byte varint over the javascript uint precision limit', function() {
var buf = BufferWriter().writeVarIntBN(BN(Math.pow(2, 54).toString())).concat();
var br = new BufferReader({buf: buf});
(function() {
br.readVarInt();
br.readVarIntNum();
}).should.throw('number too large to retain precision - use readVarIntBN');
});
@ -201,7 +201,7 @@ describe('BufferReader', function() {
var buf = BufferWriter().writeVarIntBN(BN(Math.pow(2, 53).toString())).concat();
var br = new BufferReader({buf: buf});
(function() {
br.readVarInt();
br.readVarIntNum();
}).should.not.throw('number too large to retain precision - use readVarIntBN');
});

Loading…
Cancel
Save