]>
Commit | Line | Data |
---|---|---|
f67539c2 TL |
1 | /* |
2 | * Licensed to the Apache Software Foundation (ASF) under one | |
3 | * or more contributor license agreements. See the NOTICE file | |
4 | * distributed with this work for additional information | |
5 | * regarding copyright ownership. The ASF licenses this file | |
6 | * to you under the Apache License, Version 2.0 (the | |
7 | * "License"); you may not use this file except in compliance | |
8 | * with the License. You may obtain a copy of the License at | |
9 | * | |
10 | * http://www.apache.org/licenses/LICENSE-2.0 | |
11 | * | |
12 | * Unless required by applicable law or agreed to in writing, | |
13 | * software distributed under the License is distributed on an | |
14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | |
15 | * KIND, either express or implied. See the License for the | |
16 | * specific language governing permissions and limitations | |
17 | * under the License. | |
18 | */ | |
19 | /** | |
20 | ||
21 | This is a standalone deserialize/parse example if you just want to deserialize | |
22 | thrift decoupled from cassandra server | |
23 | ||
24 | 1. acquire thrift template specification files from who ever built it (eg: EXAMPLE.thrift) | |
25 | ||
26 | 2. Install thrift on local machine | |
27 | ||
28 | 3. generate thrift clients for nodejs using template specification files (#1) | |
29 | thrift --gen js:node schema/EXAMPLE.thrift | |
30 | ||
31 | This creates creates gen-node.js directory containing a new file, GENERATED.js | |
32 | ||
33 | 4. Inside GENERATED.js is a class you will want to instanciate. Find this class name and plug | |
34 | it into the example code below (ie, "YOUR_CLASS_NAME") | |
35 | */ | |
36 | ||
37 | function parseThrift(thriftEncodedData, callback) { | |
38 | var thrift = require('thrift'); | |
39 | var transport = new thrift.TFramedTransport(thriftEncodedData); | |
40 | var protocol = new thrift.TBinaryProtocol(transport); | |
41 | ||
42 | var clientClass = require('../gen-nodejs/GENERATED').YOUR_CLASS_NAME; | |
43 | var client = new clientClass(); | |
44 | client.read(protocol); | |
45 | callback(null, client); | |
46 | } |