Henrique Mendonca | 8d410de | 2012-10-22 18:35:30 +0000 | [diff] [blame^] | 1 | /** |
| 2 | |
| 3 | This is a standalone deserialize/parse example if you just want to deserialize |
| 4 | thrift decoupled from cassandra server |
| 5 | |
| 6 | 1. acquire thrift template specification files from who ever built it (eg: EXAMPLE.thrift) |
| 7 | |
| 8 | 2. Install thrift on local machine (ie, via "brew install thrift") |
| 9 | |
| 10 | 3. generate thrift clients for nodejs using template specification files (#1) |
| 11 | thrift --gen js:node schema/EXAMPLE.thrift |
| 12 | |
| 13 | This creates creates gen-node.js directory containing a new file, GENERATED.js |
| 14 | |
| 15 | 4. Inside GENERATED.js is a class you will want to instanciate. Find this class name and plug |
| 16 | it into the example code below (ie, "YOUR_CLASS_NAME") |
| 17 | */ |
| 18 | |
| 19 | function parseThrift(thriftEncodedData, callback) { |
| 20 | var thrift = require('thrift'); |
| 21 | var transport = new thrift.TFramedTransport(thriftEncodedData); |
| 22 | var protocol = new thrift.TBinaryProtocol(transport); |
| 23 | |
| 24 | var clientClass = require('../gen-nodejs/GENERATED').YOUR_CLASS_NAME; |
| 25 | var client = new clientClass(); |
| 26 | client.read(protocol); |
| 27 | callback(null, client); |
| 28 | } |