Author: henrique
Date: Mon Oct 22 18:35:30 2012
New Revision: 1400991

URL: http://svn.apache.org/viewvc?rev=1400991&view=rev
Log:
Thrift-1738: node.js: export transport and protocol so they can be used outside 
the cassandra/server context
Client: Node.js
Patch: Barbara Raitz

exports and parse example.

Added:
    thrift/trunk/lib/nodejs/examples/parse.js
Modified:
    thrift/trunk/lib/nodejs/lib/thrift/index.js

Added: thrift/trunk/lib/nodejs/examples/parse.js
URL: 
http://svn.apache.org/viewvc/thrift/trunk/lib/nodejs/examples/parse.js?rev=1400991&view=auto
==============================================================================
--- thrift/trunk/lib/nodejs/examples/parse.js (added)
+++ thrift/trunk/lib/nodejs/examples/parse.js Mon Oct 22 18:35:30 2012
@@ -0,0 +1,28 @@
+/**
+
+  This is a standalone deserialize/parse example if you just want to 
deserialize
+  thrift decoupled from cassandra server
+
+  1.  acquire thrift template specification files from who ever built it (eg: 
EXAMPLE.thrift)
+
+  2.  Install thrift on local machine (ie, via "brew install thrift")
+
+  3.  generate thrift clients for nodejs using template specification files 
(#1)
+      thrift --gen js:node schema/EXAMPLE.thrift
+
+      This creates creates gen-node.js directory containing a new file, 
GENERATED.js
+
+  4.  Inside GENERATED.js is a class you will want to instanciate.  Find this 
class name and plug 
+      it into the example code below  (ie, "YOUR_CLASS_NAME")
+ */
+
+function parseThrift(thriftEncodedData, callback) {
+  var thrift = require('thrift');
+  var transport = new thrift.TFramedTransport(thriftEncodedData);
+  var protocol  = new thrift.TBinaryProtocol(transport);
+
+  var clientClass = require('../gen-nodejs/GENERATED').YOUR_CLASS_NAME;
+  var client = new clientClass();
+  client.read(protocol);
+  callback(null, client);
+}
\ No newline at end of file

Modified: thrift/trunk/lib/nodejs/lib/thrift/index.js
URL: 
http://svn.apache.org/viewvc/thrift/trunk/lib/nodejs/lib/thrift/index.js?rev=1400991&r1=1400990&r2=1400991&view=diff
==============================================================================
--- thrift/trunk/lib/nodejs/lib/thrift/index.js (original)
+++ thrift/trunk/lib/nodejs/lib/thrift/index.js Mon Oct 22 18:35:30 2012
@@ -26,3 +26,11 @@ exports.createStdIOClient = connection.c
 exports.createStdIOConnection = connection.createStdIOConnection;
 
 exports.createServer = require('./server').createServer;
+
+/*
+ * Export transport and protocol so they can be used outside of a 
+ * cassandra/server context
+ */
+exports.TFramedTransport = require('./transport').TFramedTransport;
+exports.TBufferedTransport = require('./transport').TBufferedTransport;
+exports.TBinaryProtocol = require('./protocol').TBinaryProtocol;


Reply via email to