You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@thrift.apache.org by br...@apache.org on 2012/03/02 00:41:09 UTC
svn commit: r1295995 -
/thrift/trunk/lib/java/src/org/apache/thrift/protocol/TTupleProtocol.java
Author: bryanduxbury
Date: Thu Mar 1 23:41:09 2012
New Revision: 1295995
URL: http://svn.apache.org/viewvc?rev=1295995&view=rev
Log:
THRIFT-1529. java: TupleProtocol can unintentionally include an extra byte in bit vectors when number of optional fields is an integral of 8
This patch harmonizes the math between writeBitSet and readBitSet to eliminate the mismatch in number of bytes calculation, allowing structs to be serialized correctly.
Modified:
thrift/trunk/lib/java/src/org/apache/thrift/protocol/TTupleProtocol.java
Modified: thrift/trunk/lib/java/src/org/apache/thrift/protocol/TTupleProtocol.java
URL: http://svn.apache.org/viewvc/thrift/trunk/lib/java/src/org/apache/thrift/protocol/TTupleProtocol.java?rev=1295995&r1=1295994&r2=1295995&view=diff
==============================================================================
--- thrift/trunk/lib/java/src/org/apache/thrift/protocol/TTupleProtocol.java (original)
+++ thrift/trunk/lib/java/src/org/apache/thrift/protocol/TTupleProtocol.java Thu Mar 1 23:41:09 2012
@@ -86,7 +86,7 @@ public final class TTupleProtocol extend
* @return a byte array of at least length 1
*/
public static byte[] toByteArray(BitSet bits, int vectorWidth) {
- byte[] bytes = new byte[vectorWidth / 8 + 1];
+ byte[] bytes = new byte[(int) Math.ceil(vectorWidth/8.0)];
for (int i = 0; i < bits.length(); i++) {
if (bits.get(i)) {
bytes[bytes.length - i / 8 - 1] |= 1 << (i % 8);