thrift-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Steve <st...@subwest.com>
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","")+"$"+tmes.name+"_args";
> if (result)
>   classStr = resultClass;  //Set cache result class for later
> else
>   resultClass = className.replace("$Client","")+"$"+tmes.name+"_result";
>
> byte[] bytes2 = mit.getBuffer();
> java.io.ByteArrayOutputStream baos = new java.io.ByteArrayOutputStream();
> baos.write(bytes2, mit.getBufferPosition(),
bytes.length-mit.getBufferPosition());
>
> Class myClass = Class.forName(classStr);
> TBase obj = (TBase)myClass.newInstance();
> deserializer.deserialize(obj, baos.toByteArray());
> thriftLogger.info(shortClassName+" "+obj.getClass().getSimpleName()+"
"+serializer.toString(obj));
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.

Thanks.


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
>
>
>



Mime
View raw message