cassandra-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cassandra-node.apache-extras....@codespot.com
Subject [cassandra-node] push by gdusbabek@gmail.com - constuct buffers in binary format on 2011-11-09 14:08 GMT
Date Wed, 09 Nov 2011 14:09:30 GMT
Revision: e09d41dd793d
Author:   Gary Dusbabek <gdusbabek@gmail.com>
Date:     Wed Nov  9 06:08:31 2011
Log:      constuct buffers in binary format

http://code.google.com/a/apache-extras.org/p/cassandra-node/source/detail?r=e09d41dd793d

Modified:
  /test/test_decoder.js

=======================================
--- /test/test_decoder.js	Wed May 25 11:47:28 2011
+++ /test/test_decoder.js	Wed Nov  9 06:08:31 2011
@@ -20,6 +20,10 @@
  var bytesToBigLong = require('../lib/decoder').bytesToBigLong;
  var bytesToNum = require('../lib/decoder').bytesToNum;

+function makeBuffer(string) {
+  return new Buffer(string, 'binary');
+}
+
  // friggen big integer library is broken.
  exports.testBigIntegerBrokenness = function(test, assert) {
    // the the v8 lib behaved like the java BigInteger, this test would pass.
@@ -37,44 +41,44 @@
    assert.ok(!zero1.equals(zero2));

    // instead, we need to rely on bytesToBigLong to return the right thing.
-   
assert.ok(zero2.equals(bytesToBigLong('\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000')));
+   
assert.ok(zero2.equals(bytesToBigLong(makeBuffer('\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000'))));

    test.finish();
  };

  exports.testNumConversion = function(test, assert) {
-  assert.strictEqual('0',  
bytesToNum('\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000').toString());  
// 1
-  assert.strictEqual('1',  
bytesToNum('\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0001').toString());  
// 1
-  assert.strictEqual('2',  
bytesToNum('\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0002').toString());  
// 2
-   
assert.strictEqual('255' ,bytesToNum('\u0000\u0000\u0000\u0000\u0000\u0000\u0000ÿ').toString());
 
// 255
-   
assert.strictEqual('2550' ,bytesToNum('\u0000\u0000\u0000\u0000\u0000\u0000\tö').toString());
 
// 2550
-  assert.strictEqual('8025521',  
bytesToNum('\u0000\u0000\u0000\u0000\u0000zu±').toString()); // 8025521
-  assert.strictEqual('218025521',  
bytesToNum('\u0000\u0000\u0000\u0000\fþÎ1').toString()); // 218025521
+  assert.strictEqual('0',  
bytesToNum(makeBuffer('\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000')).toString());  
// 1
+  assert.strictEqual('1',  
bytesToNum(makeBuffer('\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0001')).toString());  
// 1
+  assert.strictEqual('2',  
bytesToNum(makeBuffer('\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0002')).toString());  
// 2
+   
assert.strictEqual('255' ,bytesToNum(makeBuffer('\u0000\u0000\u0000\u0000\u0000\u0000\u0000ÿ')).toString());
 
// 255
+   
assert.strictEqual('2550' ,bytesToNum(makeBuffer('\u0000\u0000\u0000\u0000\u0000\u0000\tö')).toString());
 
// 2550
+  assert.strictEqual('8025521',  
bytesToNum(makeBuffer('\u0000\u0000\u0000\u0000\u0000zu±')).toString()); //  
8025521
+  assert.strictEqual('218025521',  
bytesToNum(makeBuffer('\u0000\u0000\u0000\u0000\fþÎ1')).toString()); //  
218025521

    // these values ensure that none 8 byte sequences work as well.
-  assert.strictEqual(2147483647, bytesToNum('\u007f\u00ff\u00ff\u00ff'));  
// [127,-1,-1,-1]
-  assert.strictEqual(-2147483648, bytesToNum('\u0080\u0000\u0000\u0000'));  
// [-128,0,0,0]
-  assert.strictEqual(-1, bytesToNum('\u00ff')); // [-1]
-  assert.strictEqual(1, bytesToNum('\u0001')); // [1]
-
-  assert.strictEqual('-1', bytesToNum('ÿÿÿÿÿÿÿÿ').toString());
+  assert.strictEqual(2147483647,  
bytesToNum(makeBuffer('\u007f\u00ff\u00ff\u00ff'))); // [127,-1,-1,-1]
+  assert.strictEqual(-2147483648,  
bytesToNum(makeBuffer('\u0080\u0000\u0000\u0000'))); // [-128,0,0,0]
+  assert.strictEqual(-1, bytesToNum(makeBuffer('\u00ff'))); // [-1]
+  assert.strictEqual(1, bytesToNum(makeBuffer('\u0001'))); // [1]
+
+  assert.strictEqual('-1', bytesToNum(makeBuffer('ÿÿÿÿÿÿÿÿ')).toString());
    test.finish();
  };

  exports.testLongConversion = function(test, assert) {
    assert.ok(bytesToBigLong);
    // we have to compare against strings.
-  assert.ok(new  
BigInteger('0').equals(bytesToBigLong('\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000')));
-  assert.strictEqual('0',  
bytesToBigLong('\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000').toString());  
// 1
-  assert.strictEqual('1',  
bytesToBigLong('\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0001').toString());  
// 1
-  assert.strictEqual('2',  
bytesToBigLong('\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0002').toString());  
// 2
-   
assert.strictEqual('255' ,bytesToBigLong('\u0000\u0000\u0000\u0000\u0000\u0000\u0000ÿ').toString());
 
// 255
-   
assert.strictEqual('2550' ,bytesToBigLong('\u0000\u0000\u0000\u0000\u0000\u0000\tö').toString());
 
// 2550
-  assert.strictEqual('8025521',  
bytesToBigLong('\u0000\u0000\u0000\u0000\u0000zu±').toString()); // 8025521
-  assert.strictEqual('218025521',  
bytesToBigLong('\u0000\u0000\u0000\u0000\fþÎ1').toString()); // 218025521
-  assert.strictEqual('6544218025521',  
bytesToBigLong('\u0000\u0000\u0005ó±Ên1').toString()); // 6544218025521
-  assert.strictEqual('8776496549718025521',  
bytesToBigLong('yÌa\u001c²be1').toString()); // 8776496549718025521
-  assert.strictEqual('-1', bytesToBigLong('ÿÿÿÿÿÿÿÿ').toString()); // -1
+  assert.ok(new  
BigInteger('0').equals(bytesToBigLong(makeBuffer('\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000'))));
+  assert.strictEqual('0',  
bytesToBigLong(makeBuffer('\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000')).toString());
 
// 1
+  assert.strictEqual('1',  
bytesToBigLong(makeBuffer('\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0001')).toString());
 
// 1
+  assert.strictEqual('2',  
bytesToBigLong(makeBuffer('\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0002')).toString());
 
// 2
+   
assert.strictEqual('255' ,bytesToBigLong(makeBuffer('\u0000\u0000\u0000\u0000\u0000\u0000\u0000ÿ')).toString());
 
// 255
+   
assert.strictEqual('2550' ,bytesToBigLong(makeBuffer('\u0000\u0000\u0000\u0000\u0000\u0000\tö')).toString());
 
// 2550
+  assert.strictEqual('8025521',  
bytesToBigLong(makeBuffer('\u0000\u0000\u0000\u0000\u0000zu±')).toString());  
// 8025521
+  assert.strictEqual('218025521',  
bytesToBigLong(makeBuffer('\u0000\u0000\u0000\u0000\fþÎ1')).toString()); //  
218025521
+  assert.strictEqual('6544218025521',  
bytesToBigLong(makeBuffer('\u0000\u0000\u0005ó±Ên1')).toString()); //  
6544218025521
+  assert.strictEqual('8776496549718025521',  
bytesToBigLong(makeBuffer('yÌa\u001c²be1')).toString()); //  
8776496549718025521
+  assert.strictEqual('-1',  
bytesToBigLong(makeBuffer('ÿÿÿÿÿÿÿÿ')).toString()); // -1

    test.finish();
  };
Mime
View raw message