Skip to content

Commit

Permalink
removed debug crud
Browse files Browse the repository at this point in the history
  • Loading branch information
christkv committed Mar 12, 2012
1 parent 6e6e320 commit 3a7483e
Showing 1 changed file with 0 additions and 34 deletions.
34 changes: 0 additions & 34 deletions lib/bson/bson.js
Expand Up @@ -408,7 +408,6 @@ var packElement = function(name, value, checkKeys, buffer, index, serializeFunct

switch(typeof value) {
case 'string':
// console.log("---------------------------- string name :: " + name)
// Encode String type
buffer[index++] = BSON.BSON_DATA_STRING;
// Number of written bytes
Expand All @@ -435,7 +434,6 @@ var packElement = function(name, value, checkKeys, buffer, index, serializeFunct
// Return index
return index;
case 'number':
// console.log("---------------------------- number name :: " + name)
// We have an integer value
if(Math.floor(value) === value && value >= BSON.JS_INT_MIN && value <= BSON.JS_INT_MAX) {
// If the value fits in 32 bits encode as int, if it fits in a double
Expand Down Expand Up @@ -503,7 +501,6 @@ var packElement = function(name, value, checkKeys, buffer, index, serializeFunct

return index;
case 'undefined':
// console.log("---------------------------- undefined name :: " + name)
// Set long type
buffer[index++] = BSON.BSON_DATA_NULL;
// Number of written bytes
Expand All @@ -513,7 +510,6 @@ var packElement = function(name, value, checkKeys, buffer, index, serializeFunct
buffer[index - 1] = 0;
return index;
case 'boolean':
// console.log("---------------------------- boolean name :: " + name)
// Write the type
buffer[index++] = BSON.BSON_DATA_BOOLEAN;
// Number of written bytes
Expand All @@ -527,7 +523,6 @@ var packElement = function(name, value, checkKeys, buffer, index, serializeFunct
case 'object':
if(value === null || value instanceof MinKey || value instanceof MaxKey
|| value['_bsontype'] == 'MinKey' || value['_bsontype'] == 'MaxKey') {
// console.log("---------------------------- min_key|max_key name :: " + name)
// Write the type of either min or max key
if(value === null) {
buffer[index++] = BSON.BSON_DATA_NULL;
Expand All @@ -544,7 +539,6 @@ var packElement = function(name, value, checkKeys, buffer, index, serializeFunct
buffer[index - 1] = 0;
return index;
} else if(value instanceof ObjectID || value['_bsontype'] == 'ObjectID') {
// console.log("---------------------------- object_id name :: " + name)
// Write the type
buffer[index++] = BSON.BSON_DATA_OID;
// Number of written bytes
Expand All @@ -559,7 +553,6 @@ var packElement = function(name, value, checkKeys, buffer, index, serializeFunct
index = index + 12;
return index;
} else if(value instanceof Date) {
// console.log("---------------------------- date name :: " + name)
// Write the type
buffer[index++] = BSON.BSON_DATA_DATE;
// Number of written bytes
Expand All @@ -584,7 +577,6 @@ var packElement = function(name, value, checkKeys, buffer, index, serializeFunct
buffer[index++] = (highBits >> 24) & 0xff;
return index;
} else if(typeof Buffer !== 'undefined' && Buffer.isBuffer(value)) {
// console.log("---------------------------- buffer name :: " + name)
// Write the type
buffer[index++] = BSON.BSON_DATA_BINARY;
// Number of written bytes
Expand All @@ -607,7 +599,6 @@ var packElement = function(name, value, checkKeys, buffer, index, serializeFunct
index = index + size;
return index;
} else if(value instanceof Long || value instanceof Timestamp || value['_bsontype'] == 'Long' || value['_bsontype'] == 'Timestamp') {
// console.log("---------------------------- long|timestamp name :: " + name)
// Write the type
buffer[index++] = value instanceof Long ? BSON.BSON_DATA_LONG : BSON.BSON_DATA_TIMESTAMP;
// Number of written bytes
Expand All @@ -630,7 +621,6 @@ var packElement = function(name, value, checkKeys, buffer, index, serializeFunct
buffer[index++] = (highBits >> 24) & 0xff;
return index;
} else if(value instanceof Double || value['_bsontype'] == 'Double') {
// console.log("---------------------------- double name :: " + name)
// Encode as double
buffer[index++] = BSON.BSON_DATA_NUMBER;
// Number of written bytes
Expand All @@ -644,7 +634,6 @@ var packElement = function(name, value, checkKeys, buffer, index, serializeFunct
index = index + 8;
return index;
} else if(value instanceof Code || value['_bsontype'] == 'Code') {
// console.log("---------------------------- code name :: " + name)
if(value.scope != null && Object.keys(value.scope).length > 0) {
// Write the type
buffer[index++] = BSON.BSON_DATA_CODE_W_SCOPE;
Expand Down Expand Up @@ -726,7 +715,6 @@ var packElement = function(name, value, checkKeys, buffer, index, serializeFunct
return index;
}
} else if(value instanceof Binary || value['_bsontype'] == 'Binary') {
// console.log("---------------------------- binary name :: " + name)
// Write the type
buffer[index++] = BSON.BSON_DATA_BINARY;
// Number of written bytes
Expand All @@ -751,7 +739,6 @@ var packElement = function(name, value, checkKeys, buffer, index, serializeFunct
index = index + value.position;
return index;
} else if(value instanceof Symbol || value['_bsontype'] == 'Symbol') {
// console.log("---------------------------- symbol name :: " + name)
// Write the type
buffer[index++] = BSON.BSON_DATA_SYMBOL;
// Number of written bytes
Expand All @@ -774,7 +761,6 @@ var packElement = function(name, value, checkKeys, buffer, index, serializeFunct
buffer[index++] = 0x00;
return index;
} else if(value instanceof DBRef || value['_bsontype'] == 'DBRef') {
// console.log("---------------------------- dbref name :: " + name)
// Write the type
buffer[index++] = BSON.BSON_DATA_OBJECT;
// Number of written bytes
Expand Down Expand Up @@ -807,7 +793,6 @@ var packElement = function(name, value, checkKeys, buffer, index, serializeFunct
// Return the end index
return endIndex;
} else if(value instanceof RegExp || Object.prototype.toString.call(value) === '[object RegExp]') {
// console.log("---------------------------- regexp name :: " + name)
// Write the type
buffer[index++] = BSON.BSON_DATA_REGEXP;
// Number of written bytes
Expand All @@ -830,7 +815,6 @@ var packElement = function(name, value, checkKeys, buffer, index, serializeFunct
buffer[index++] = 0x00;
return index;
} else {
// console.log("---------------------------- object|array :: " + name)
// Write the type
buffer[index++] = Array.isArray(value) ? BSON.BSON_DATA_ARRAY : BSON.BSON_DATA_OBJECT;
// Number of written bytes
Expand Down Expand Up @@ -1178,14 +1162,12 @@ BSON.deserialize = function(buffer, options, isArray) {
switch(elementType) {
case BSON.BSON_DATA_OID:
var string = supportsBuffer && Buffer.isBuffer(buffer) ? buffer.toString('binary', index, index + 12) : convertArraytoUtf8BinaryString(buffer, index, index + 12);
// console.log("================================================ object_id :: " + name)
// Decode the oid
object[name] = new ObjectID(string);
// Update index
index = index + 12;
break;
case BSON.BSON_DATA_STRING:
// console.log("================================================ string :: " + name)
// Read the content of the field
var stringSize = buffer[index++] | buffer[index++] << 8 | buffer[index++] << 16 | buffer[index++] << 24;
// Add string to object
Expand All @@ -1194,37 +1176,31 @@ BSON.deserialize = function(buffer, options, isArray) {
index = index + stringSize;
break;
case BSON.BSON_DATA_INT:
// console.log("================================================ int :: " + name)
// Decode the 32bit value
object[name] = buffer[index++] | buffer[index++] << 8 | buffer[index++] << 16 | buffer[index++] << 24;
break;
case BSON.BSON_DATA_NUMBER:
// console.log("================================================ number :: " + name)
// Decode the double value
object[name] = readIEEE754(buffer, index, 'little', 52, 8);
// Update the index
index = index + 8;
break;
case BSON.BSON_DATA_DATE:
// console.log("================================================ date :: " + name)
// Unpack the low and high bits
var lowBits = buffer[index++] | buffer[index++] << 8 | buffer[index++] << 16 | buffer[index++] << 24;
var highBits = buffer[index++] | buffer[index++] << 8 | buffer[index++] << 16 | buffer[index++] << 24;
// Set date object
object[name] = new Date(new Long(lowBits, highBits).toNumber());
break;
case BSON.BSON_DATA_BOOLEAN:
// console.log("================================================ boolean :: " + name)
// Parse the boolean value
object[name] = buffer[index++] == 1;
break;
case BSON.BSON_DATA_NULL:
// console.log("================================================ null :: " + name)
// Parse the boolean value
object[name] = null;
break;
case BSON.BSON_DATA_BINARY:
// console.log("================================================ binary :: " + name)
// Decode the size of the binary blob
var binarySize = buffer[index++] | buffer[index++] << 8 | buffer[index++] << 16 | buffer[index++] << 24;
// Decode the subtype
Expand All @@ -1244,7 +1220,6 @@ BSON.deserialize = function(buffer, options, isArray) {
index = index + binarySize;
break;
case BSON.BSON_DATA_ARRAY:
// console.log("================================================ array :: " + name)
options['index'] = index;
// Decode the size of the array document
var objectSize = buffer[index] | buffer[index + 1] << 8 | buffer[index + 2] << 16 | buffer[index + 3] << 24;
Expand All @@ -1254,7 +1229,6 @@ BSON.deserialize = function(buffer, options, isArray) {
index = index + objectSize;
break;
case BSON.BSON_DATA_OBJECT:
// console.log("================================================ object :: " + name)
options['index'] = index;
// Decode the size of the object document
var objectSize = buffer[index] | buffer[index + 1] << 8 | buffer[index + 2] << 16 | buffer[index + 3] << 24;
Expand All @@ -1264,7 +1238,6 @@ BSON.deserialize = function(buffer, options, isArray) {
index = index + objectSize;
break;
case BSON.BSON_DATA_REGEXP:
// console.log("================================================ regexp :: " + name)
// Create the regexp
var source = readCStyleString();
var regExpOptions = readCStyleString();
Expand All @@ -1289,7 +1262,6 @@ BSON.deserialize = function(buffer, options, isArray) {
object[name] = new RegExp(source, optionsArray.join(''));
break;
case BSON.BSON_DATA_LONG:
// console.log("================================================ long :: " + name)
// Unpack the low and high bits
var lowBits = buffer[index++] | buffer[index++] << 8 | buffer[index++] << 16 | buffer[index++] << 24;
var highBits = buffer[index++] | buffer[index++] << 8 | buffer[index++] << 16 | buffer[index++] << 24;
Expand All @@ -1299,7 +1271,6 @@ BSON.deserialize = function(buffer, options, isArray) {
object[name] = long.lessThanOrEqual(JS_INT_MAX_LONG) && long.greaterThanOrEqual(JS_INT_MIN_LONG) ? long.toNumber() : long;
break;
case BSON.BSON_DATA_SYMBOL:
// console.log("================================================ symbol :: " + name)
// Read the content of the field
var stringSize = buffer[index++] | buffer[index++] << 8 | buffer[index++] << 16 | buffer[index++] << 24;
// Add string to object
Expand All @@ -1308,25 +1279,21 @@ BSON.deserialize = function(buffer, options, isArray) {
index = index + stringSize;
break;
case BSON.BSON_DATA_TIMESTAMP:
// console.log("================================================ timestamp :: " + name)
// Unpack the low and high bits
var lowBits = buffer[index++] | buffer[index++] << 8 | buffer[index++] << 16 | buffer[index++] << 24;
var highBits = buffer[index++] | buffer[index++] << 8 | buffer[index++] << 16 | buffer[index++] << 24;
// Set the object
object[name] = new Timestamp(lowBits, highBits);
break;
case BSON.BSON_DATA_MIN_KEY:
// console.log("================================================ min_key :: " + name)
// Parse the object
object[name] = new MinKey();
break;
case BSON.BSON_DATA_MAX_KEY:
// console.log("================================================ max_key :: " + name)
// Parse the object
object[name] = new MaxKey();
break;
case BSON.BSON_DATA_CODE:
// console.log("================================================ code :: " + name)
// Read the content of the field
var stringSize = buffer[index++] | buffer[index++] << 8 | buffer[index++] << 16 | buffer[index++] << 24;
// Function string
Expand All @@ -1353,7 +1320,6 @@ BSON.deserialize = function(buffer, options, isArray) {
index = index + stringSize;
break;
case BSON.BSON_DATA_CODE_W_SCOPE:
// console.log("================================================ code_w_scope :: " + name)
// Read the content of the field
var totalSize = buffer[index++] | buffer[index++] << 8 | buffer[index++] << 16 | buffer[index++] << 24;
var stringSize = buffer[index++] | buffer[index++] << 8 | buffer[index++] << 16 | buffer[index++] << 24;
Expand Down

0 comments on commit 3a7483e

Please sign in to comment.