Permalink
Browse files

Refactored cut and paste on read long

  • Loading branch information...
1 parent c557c32 commit 644d20406bf4add3a2e34c4085de73baff1bf1c2 Andrew Wilson committed Mar 14, 2012
Showing with 10 additions and 16 deletions.
  1. +10 −16 lib/parser.js
View
26 lib/parser.js
@@ -77,14 +77,17 @@ Parser.prototype.writeDouble = function(value) {
ctype.wdouble(value, endian, this.buffer, (this.position += 8) - 8);
};
+Parser.prototype.readLongBytes = function() {
+ var bytes = [], numBytes = 8;
+ for (var i = 0; i < numBytes; i++) {
+ bytes.push(ctype.ruint8(this.buffer, endian, this.position + i));
+ }
+ this.position += numBytes;
+ return (new BigInteger(bytes));
+};
Parser.prototype.readLong = function() {
- var bytes = [], numBytes = 8;
- for (var i = 0; i < numBytes; i++) {
- bytes.push(ctype.ruint8(this.buffer, endian, this.position + i));
- }
- this.position += numBytes;
- return (new BigInteger(bytes))[0];
+ return this.readLongBytes()[0];
};
Parser.prototype.writeLong = function(value) {
var bytes, numBytes = 8;
@@ -117,18 +120,9 @@ Parser.prototype.writeString = function(value) {
this.position += length;
};
-Parser.prototype.readDateBytes = function() {
- var bytes = [], numBytes = 8;
- for (var i = 0; i < numBytes; i++) {
- bytes.push(ctype.ruint8(this.buffer, endian, this.position + i));
- }
- this.position += numBytes;
- return (new BigInteger(bytes));
-};
-
Parser.prototype.readDate = function(value) {
var bigInt, i = 0, numBytes = 8;
- bigInt = this.readDateBytes();
+ bigInt = this.readLongBytes();
var intStr = bigInt.divide(thousand).toString();
return new Date(parseInt(intStr));
};

0 comments on commit 644d204

Please sign in to comment.