thrift-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Steve Angelovich <>
Subject thrift and JNI
Date Thu, 28 Jul 2011 19:51:50 GMT

Has anybody considered using thrift in conjunction with JNI?

I have a large java application where I want to be able to implement 
some algorithms in either java or c++.  Right now we do this by writing 
a small amount of JNI code or using SWIG.

I'd like to generalize this a little so that the JNI code only has to be 
written once instead of for each algorithm.  I can do this purely using 
JNI but then I end up with very tight coupling between my c++ code and 
the java code.

Does it make any sense to use thrift to define my interface.  Then when 
moving between the java and c++ I wouldn't require a socket connection 
but would use a memory based transport.

Does this very small code segment look correct for how to move the 
contents of the TData java class into a memory buffer and then get it 
back?  This is all java code but I could do the same thing with the 
first half java and the complementary code in c++.

     byte[] buf = null ;
       TData data = new TData() ;
       TMemoryBuffer transportIn = new TMemoryBuffer(0) ;
       TProtocol oprot = new TBinaryProtocol(transportIn) ;
       data.write(oprot) ;

       transportIn.flush() ;
       buf = transportIn.getArray() ;
       System.out.println("buf.length=" + buf.length) ;

       TTransport transportOut = new TMemoryInputTransport(buf) ;
       TProtocol iprot = new TBinaryProtocol(transportOut) ;
       TData data = new TData() ; ;
       System.out.println(data.toString()) ;

Has anybody considered writing an implementation of TTransport based on 
the NIO ByteBuffer class?


This e-mail, including any attached files, may contain confidential and privileged information
for the sole use of the intended recipient.  Any review, use, distribution, or disclosure
by others is strictly prohibited.  If you are not the intended recipient (or authorized to
receive information for the intended recipient), please contact the sender by reply e-mail
and delete all copies of this message.

View raw message