[ 
https://issues.apache.org/jira/browse/THRIFT-1557?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13249847#comment-13249847
 ] 

Bryan Duxbury commented on THRIFT-1557:
---------------------------------------

bq. However, the point here is with the same code, using TCompactProtocol (Case 
1 in my attached code) gives correct result while TBinaryProtocol (Case 2 in my 
attached code) injects unexpected leading characters into the result

Actually, this isn't the point. In both cases you're not accessing the array 
contents the correct way. It just so happens that in the Compact protocol case, 
the data comes out aligned in this instance, but the Binary version does not. 
In another spot in another deserialized struct, they could both fail or both 
succeed arbitrarily.

To reiterate, this is 100% an issue in how you're using the structs, not the 
library. If you are not comfortable with ByteBuffers, you can use the getter 
for your field that returns byte[] instead. It will take care of all of this 
for you.
                
> Using TFramedTransport together with TBinaryProtocol produces unexpected 
> deserialization for binary in Java
> -----------------------------------------------------------------------------------------------------------
>
>                 Key: THRIFT-1557
>                 URL: https://issues.apache.org/jira/browse/THRIFT-1557
>             Project: Thrift
>          Issue Type: Bug
>          Components: Java - Library
>    Affects Versions: 0.8, 0.9
>         Environment: Windows x64, jdk 6u31, libthrift 0.8, 0.9
>            Reporter: MXI MXI
>              Labels: features
>         Attachments: UnexpectedLeadingCharacters.png.jpg, 
> thrift1557_eclipse.zip
>
>
> I create a simple service, called BinService. It has just one method - bin() 
> which returns a static byte array (ByteBuffer in Java).
> #--Here is the service:
> namespace java bin
> service BinService {
>    *binary* bin()
> }
> #---------------------
> I tried to test this service in several cases and one gave incorrect result:
>  - Using THsHaServer, TFramedTransport & *TCompactProtocol* => The result was 
> correct
>  - Using THsHaServer, TFramedTransport & *TBinaryProtocol* => The result was 
> incorrect (unexpected leading characters were injected into the return result)
> The amazing thing is when I tried to implement a same client in CSharp, the 
> result was correct (i.e. using TFramedTransport & *TBinaryProtocol*). By the 
> way, there is no support for TCompactProtocol in CSharp, using 
> TBinaryProtocol is a must for this reason.  
> I wonder whether it is possible to use TFramedTransport with TBinaryProtocol 
> in Java. 
> I will attach the code using for reproducing this issue.
> N.B. This issue can be seen in both version 0.8 and 0.9.

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: 
https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

Reply via email to