blob: 8513e4c2f0274eeac86bd3c280fec64b3129a639 [file] [log] [blame]
Jake Farrellee4aaae2012-10-23 00:48:17 +00001/*
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 */
Henrique Mendonca8d410de2012-10-22 18:35:30 +000019/**
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
Jake Farrellee4aaae2012-10-23 00:48:17 +000026 2. Install thrift on local machine
Henrique Mendonca8d410de2012-10-22 18:35:30 +000027
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
37function parseThrift(thriftEncodedData, callback) {
Cameron Martincaef0ed2025-01-15 11:58:39 +010038 var thrift = require("thrift");
Henrique Mendonca8d410de2012-10-22 18:35:30 +000039 var transport = new thrift.TFramedTransport(thriftEncodedData);
Cameron Martincaef0ed2025-01-15 11:58:39 +010040 var protocol = new thrift.TBinaryProtocol(transport);
Henrique Mendonca8d410de2012-10-22 18:35:30 +000041
Cameron Martincaef0ed2025-01-15 11:58:39 +010042 var clientClass = require("../gen-nodejs/GENERATED").YOUR_CLASS_NAME;
Henrique Mendonca8d410de2012-10-22 18:35:30 +000043 var client = new clientClass();
44 client.read(protocol);
45 callback(null, client);
Jake Farrellee4aaae2012-10-23 00:48:17 +000046}