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.
git-svn-id: https://svn.apache.org/repos/asf/thrift/trunk@1400991 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/lib/nodejs/examples/parse.js b/lib/nodejs/examples/parse.js
new file mode 100644
index 0000000..61b933a
--- /dev/null
+++ b/lib/nodejs/examples/parse.js
@@ -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