From 30c96721a05e70dc70f4c2f4e4e241aa57a47d83 Mon Sep 17 00:00:00 2001 From: "Ryan X. Charles" Date: Mon, 15 Sep 2014 14:36:31 -0700 Subject: [PATCH] varIntNum --- lib/bufferwriter.js | 6 +++--- lib/message.js | 4 ++-- test/bufferwriter.js | 10 +++++----- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/lib/bufferwriter.js b/lib/bufferwriter.js index d813bcb..1e1a6b7 100644 --- a/lib/bufferwriter.js +++ b/lib/bufferwriter.js @@ -71,8 +71,8 @@ BufferWriter.prototype.writeUInt64LEBN = function(bn) { return this; }; -BufferWriter.prototype.writeVarInt = function(n) { - var buf = BufferWriter.varIntBuf(n); +BufferWriter.prototype.writeVarIntNum = function(n) { + var buf = BufferWriter.varIntBufNum(n); this.write(buf); return this; }; @@ -83,7 +83,7 @@ BufferWriter.prototype.writeVarIntBN = function(bn) { return this; }; -BufferWriter.varIntBuf = function(n) { +BufferWriter.varIntBufNum = function(n) { var buf = undefined; if (n < 253) { buf = new Buffer(1); diff --git a/lib/message.js b/lib/message.js index 0536d43..8174e4e 100644 --- a/lib/message.js +++ b/lib/message.js @@ -29,9 +29,9 @@ Message.magicHash = function(messagebuf) { if (!Buffer.isBuffer(messagebuf)) throw new Error('messagebuf must be a buffer'); var bw = new BufferWriter(); - bw.writeVarInt(Message.magicBytes.length); + bw.writeVarIntNum(Message.magicBytes.length); bw.write(Message.magicBytes); - bw.writeVarInt(messagebuf.length); + bw.writeVarIntNum(messagebuf.length); bw.write(messagebuf); var buf = bw.concat(); diff --git a/test/bufferwriter.js b/test/bufferwriter.js index acbc8f1..802c831 100644 --- a/test/bufferwriter.js +++ b/test/bufferwriter.js @@ -111,25 +111,25 @@ describe('BufferWriter', function() { it('should write a 1 byte varInt', function() { var bw = new BufferWriter(); - bw.writeVarInt(1); + bw.writeVarIntNum(1); bw.concat().length.should.equal(1); }); it('should write a 3 byte varInt', function() { var bw = new BufferWriter(); - bw.writeVarInt(1000); + bw.writeVarIntNum(1000); bw.concat().length.should.equal(3); }); it('should write a 5 byte varInt', function() { var bw = new BufferWriter(); - bw.writeVarInt(Math.pow(2, 16 + 1)); + bw.writeVarIntNum(Math.pow(2, 16 + 1)); bw.concat().length.should.equal(5); }); it('should write a 9 byte varInt', function() { var bw = new BufferWriter(); - bw.writeVarInt(Math.pow(2, 32 + 1)); + bw.writeVarIntNum(Math.pow(2, 32 + 1)); bw.concat().length.should.equal(9); }); @@ -137,7 +137,7 @@ describe('BufferWriter', function() { var bw = new BufferWriter(); var n = Math.pow(2, 53); n.should.equal(n + 1); //javascript number precision limit - bw.writeVarInt(n); + bw.writeVarIntNum(n); var br = new BufferReader({buf: bw.concat()}); br.readVarIntBN().toNumber().should.equal(n); });