Comparing version 0.5.0 to 0.5.1
@@ -0,1 +1,6 @@ | ||
0.5.1 2016-07-05 | ||
----------------- | ||
- Fixed encoding/decoding issue in ObjectId timestamp generation. | ||
- Removed BinaryParser dependency from the serializer/deserializer. | ||
0.5.0 2016-07-05 | ||
@@ -2,0 +7,0 @@ ----------------- |
@@ -7,4 +7,3 @@ try { | ||
[ './binary_parser' | ||
, './binary' | ||
[ './binary' | ||
, './code' | ||
@@ -32,4 +31,3 @@ , './map' | ||
// Map all the classes | ||
[ './binary_parser' | ||
, './binary' | ||
[ './binary' | ||
, './code' | ||
@@ -61,4 +59,3 @@ , './map' | ||
// Map all the classes | ||
[ './binary_parser' | ||
, './binary' | ||
[ './binary' | ||
, './code' | ||
@@ -65,0 +62,0 @@ , './map' |
/** | ||
* Module dependencies. | ||
* @ignore | ||
*/ | ||
var BinaryParser = require('./binary_parser').BinaryParser; | ||
/** | ||
* Machine id. | ||
@@ -124,7 +118,2 @@ * | ||
} | ||
// // Encode low bits | ||
// buffer[index++] = lowBits & 0xff; | ||
// buffer[index++] = (lowBits >> 8) & 0xff; | ||
// buffer[index++] = (lowBits >> 16) & 0xff; | ||
// buffer[index++] = (lowBits >> 24) & 0xff; | ||
@@ -137,6 +126,6 @@ // Use pid | ||
// Encode time | ||
buffer[0] = time & 0xff; | ||
buffer[1] = (time >> 8) & 0xff; | ||
buffer[2] = (time >> 16) & 0xff; | ||
buffer[3] = (time >> 24) & 0xff; | ||
buffer[3] = time & 0xff; | ||
buffer[2] = (time >> 8) & 0xff; | ||
buffer[1] = (time >> 16) & 0xff; | ||
buffer[0] = (time >> 24) & 0xff; | ||
// Encode machine | ||
@@ -150,5 +139,5 @@ buffer[4] = MACHINE_ID & 0xff; | ||
// Encode index | ||
buffer[9] = inc & 0xff; | ||
buffer[11] = inc & 0xff; | ||
buffer[10] = (inc >> 8) & 0xff; | ||
buffer[11] = (inc >> 16) & 0xff; | ||
buffer[9] = (inc >> 16) & 0xff; | ||
// Return the buffer | ||
@@ -219,3 +208,3 @@ return buffer; | ||
var timestamp = new Date(); | ||
var time = this.id[0] | this.id[1] << 8 | this.id[2] << 16 | this.id[3] << 24; | ||
var time = this.id[3] | this.id[2] << 8 | this.id[1] << 16 | this.id[0] << 24; | ||
timestamp.setTime(Math.floor(time) * 1000); | ||
@@ -245,5 +234,10 @@ return timestamp; | ||
ObjectID.createFromTime = function createFromTime (time) { | ||
var id = BinaryParser.encodeInt(time, 32, true, true) + | ||
BinaryParser.encodeInt(0, 64, true, true); | ||
return new ObjectID(id); | ||
var buffer = new Buffer([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]); | ||
// Encode time into first 4 bytes | ||
buffer[3] = time & 0xff; | ||
buffer[2] = (time >> 8) & 0xff; | ||
buffer[1] = (time >> 16) & 0xff; | ||
buffer[0] = (time >> 24) & 0xff; | ||
// Return the new objectId | ||
return new ObjectID(buffer); | ||
}; | ||
@@ -333,10 +327,10 @@ | ||
, get: function () { | ||
return this.id[0] | this.id[1] << 8 | this.id[2] << 16 | this.id[3] << 24; | ||
return this.id[3] | this.id[2] << 8 | this.id[1] << 16 | this.id[0] << 24; | ||
} | ||
, set: function (value) { | ||
// Encode time into first 4 bytes | ||
this.id[0] = value & 0xff; | ||
this.id[1] = (value >> 8) & 0xff; | ||
this.id[2] = (value >> 16) & 0xff; | ||
this.id[3] = (value >> 24) & 0xff; | ||
this.id[3] = value & 0xff; | ||
this.id[2] = (value >> 8) & 0xff; | ||
this.id[1] = (value >> 16) & 0xff; | ||
this.id[0] = (value >> 24) & 0xff; | ||
} | ||
@@ -343,0 +337,0 @@ }); |
@@ -17,3 +17,3 @@ { | ||
], | ||
"version": "0.5.0", | ||
"version": "0.5.1", | ||
"author": "Christian Amor Kvalheim <christkv@gmail.com>", | ||
@@ -20,0 +20,0 @@ "contributors": [], |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
448808
30
11646