thrift-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Henrique Mendonça <henri...@apache.org>
Subject Re: Is there a serializer/deserializer for the Thrift format in Node.JS?
Date Wed, 19 Sep 2012 19:58:23 GMT
Hi Barbara,

The example is not related to Cassandra but it does create a
connection, please have a look on:
https://github.com/apache/thrift/blob/trunk/lib/nodejs/examples/Makefile
e.g.:
make server &
make client

your code does look ok, though. A very similar example in c#:
http://www.markhneedham.com/blog/2008/08/29/c-thrift-examples/
In your case, it's perhaps a problem with the FramedTransport. You
should be using a straightforward transport, but I afraid we don't
have one for node yet... it might not be a big thing to write one
yourself, though.
someone else might have a better idea... let's see


On 19 September 2012 19:37, Barbara Raitz <braitz@gmail.com> wrote:
> 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
View raw message