You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@thrift.apache.org by Steve <st...@subwest.com> on 2011/11/02 02:19:41 UTC

Captured TBinaryProtocol data

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



Re: Captured TBinaryProtocol data

Posted by Steve <st...@subwest.com>.
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
>
>
>



Re: Captured TBinaryProtocol data

Posted by Bryan Duxbury <br...@rapleaf.com>.
There aren't any prebuilt tools that I know of that would allow you to
deserialize captured binary protocol RPC calls. You could probably write a
utility using TDeserializer, but as you pointed out, you need to know the
data type to make it work.

On Tue, Nov 1, 2011 at 6:19 PM, Steve <st...@subwest.com> 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
>
>
>