From: Henrique Mendonca Date: Mon, 22 Oct 2012 18:35:30 +0000 (+0000) Subject: Thrift-1738: node.js: export transport and protocol so they can be used outside the... X-Git-Tag: 0.9.1~261 X-Git-Url: https://source.supwisdom.com/gerrit/gitweb?a=commitdiff_plain;h=8d410de0a057e301505c870a9a67e0e73510d0a0;p=common%2Fthrift.git 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 00000000..61b933a7 --- /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 diff --git a/lib/nodejs/lib/thrift/index.js b/lib/nodejs/lib/thrift/index.js index c7cedc0c..fb96353c 100644 --- a/lib/nodejs/lib/thrift/index.js +++ b/lib/nodejs/lib/thrift/index.js @@ -26,3 +26,11 @@ exports.createStdIOClient = connection.createStdIOClient; 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;