thrift-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Barbara Raitz <bra...@gmail.com>
Subject Is there a serializer/deserializer for the Thrift format in Node.JS?
Date Wed, 19 Sep 2012 17:37:24 GMT
I'm working on a project that combines NodeJS, ZooKeeper, and Thrift and am
blocked on the Thrift serialize/deserialize portion.  I've been looking
very closely at this project
https://github.com/apache/thrift/tree/trunk/lib/nodejs .  However, this
example is tightly coupled with Cassandra.  I don't want to make a
connection.  I've been trying to deconstruct the code to get access to the
parser portion of it.

1.  right/wrong approach?

Perhaps someone could nudge me in the right direction.  I've generated the
"types" file from the thrift struct via the command:  *thrift ---gen
js:node <endpoint.thrift>*, which generates *Endpoint.prototype.read =
function(input)*

I've tried something like the following, which is not working.


  // create transport given serializedInput
  var transport =
require('../node_modules/thrift/lib/thrift/transport').TFramedTransport;
  var thisTransport = new transport(serializedInputBuffer, function(buf) {
    console.log("TRANSPORT FLUSHED "); console.log(buf);
  });

  // create protocol bound to transport
  var TBinaryProtocol =
require('../node_modules/thrift/lib/thrift/protocol').TBinaryProtocol;
  var protocol = new TBinaryProtocol(thisTransport);

  // try to call the read method given this protocol
  // I edited endpoint_types.js and exported the read method
  var endpoint = require('../config/thrift/gen-nodejs/endpoint_types');
  endpoint.read(protocol);
  protocol.flush();


console.log of the serialized input is:

<SlowBuffer 0c 00 01 0b 00 01 00 00 00 0e 31 30 2e 32 30 36 2e 32 33 37 2e
32 34 31 08 00 02 00 00 11 d7 00 0d 00 02 0b 0c 00 00 00 00 08 00 03 00 00
00 02 00>

The transport callback does get tripped, and returns:

<Buffer 00 00 00 00>


2.  Any advice?

Clearly, I'm doing something wrong.  There should be an easier way (that
works).  I greatly appreciate any feedback!

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message