Name: node-thrift
Owner: racker
Description: nodejs thrift implementation
Created: 2011-08-04 19:53:52.0
Updated: 2013-12-31 17:39:21.0
Pushed: 2012-06-26 03:48:16.0
Homepage: http://thrift.apache.org/
Size: 234
Language: JavaScript
GitHub Committers
User | Most Recent Commit | # Commits |
---|
Other Committers
User | Most Recent Commit | # Commits |
---|
Thrift protocol implementation for nodejs. As of version 0.0.1, the basic protocol has been implemented. A Thrift compiler that will generate the .js files from a Thrift specification is being implemented as well, see the Thrift Compiler section below.
NOTE: you must use the framed thrift transport, TFramedTransport in most implementations, on the server side. Using a popular example, this is enabled by default in Cassandra 0.7 (but configuration must be changed in Cassandra 0.6.x and earlier).
npm install thrift
A Thrift compiler is being built in a forked version of the upstream thrift library. You can check it out here: https://github.com/wadey/thrift
Once you build this patched version of Thrift, you can compile nodejs sources by running the following:
thrift --gen js:node thrift_file
Here is a Cassandra example:
var thrift = require('thrift'),
Cassandra = require('./gen-nodejs/Cassandra')
ttypes = require('./gen-nodejs/cassandra_types');
var connection = thrift.createConnection("localhost", 9160),
client = thrift.createClient(Cassandra, connection);
connection.on('error', function(err) {
console.error(err);
});
client.get_slice("Keyspace", "key", new ttypes.ColumnParent({column_family: "ExampleCF"}), new ttypes.SlicePredicate({slice_range: new ttypes.SliceRange({start: '', finish: ''})}), ttypes.ConsistencyLevel.ONE, function(err, data) {
if (err) {
// handle err
} else {
// data == [ttypes.ColumnOrSuperColumn, ...]
}
connection.end();
});
Since JavaScript represents all numbers as doubles, int64 values cannot be accurately represented naturally. To solve this, int64 values in responses will be wrapped with Thirft.Int64 objects. The Int64 implementation used is broofa/node-int64.
An example based on the one shown on the Thrift front page is included in the examples folder.