thrift-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Steve <>
Subject Re: Captured TBinaryProtocol data
Date Sat, 05 Nov 2011 20:26:19 GMT
I found a solution. Just thought I'd document it here in the mailing
list, in case anyone googles this later and needs the same solution.

I extended TSocket to also write data to a byte array for each read/write.
I already had TBinaryProtocol extended, so on any writeMessageEnd &
readMessageEnd, I take
the array in the extended TSocket class (reset it for later use too) and
deserialize what is already accumulated.

I found I could deserialize with:

> TMemoryInputTransport mit = new TMemoryInputTransport(bytes);
> TBinaryProtocol tb = new TBinaryProtocol(mit);
> TMessage tmes = tb.readMessageBegin();
> String classStr = className.replace("$Client","")+"$""_args";
> if (result)
>   classStr = resultClass;  //Set cache result class for later
> else
>   resultClass = className.replace("$Client","")+"$""_result";
> byte[] bytes2 = mit.getBuffer();
> baos = new;
> baos.write(bytes2, mit.getBufferPosition(),
> Class myClass = Class.forName(classStr);
> TBase obj = (TBase)myClass.newInstance();
> deserializer.deserialize(obj, baos.toByteArray());
>" "+obj.getClass().getSimpleName()+"
Assumes className is the client.

Not the most efficient, but since I don't use it often, it isn't bad.
It allows me to check the data w/o changing the client or server protocols.


On 11/1/2011 9:19 PM, Steve wrote:
> Hi,
> I use the TBinaryProtocol and I have extended TSocket to occasionally
> record the binary data of some transmissions.  Is there anyway to
> deserialize or translate this data?  There are some deserialization
> commands, but it looks like you need to know the data type, and I don't
> think that works for function messages.
> Thanks for any help,
> Steve

View raw message