Skip to content

Commit

Permalink
Refactored cut and paste on read long
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrew Wilson committed Mar 14, 2012
1 parent c557c32 commit 644d204
Showing 1 changed file with 10 additions and 16 deletions.
26 changes: 10 additions & 16 deletions lib/parser.js
Expand Up @@ -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;
Expand Down Expand Up @@ -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));
};
Expand Down

0 comments on commit 644d204

Please sign in to comment.