This patch harmonizes the math between writeBitSet and readBitSet to eliminate the mismatch in number of bytes calculation, allowing structs to be serialized correctly.
git-svn-id: https://svn.apache.org/repos/asf/thrift/trunk@
1295995 13f79535-47bb-0310-9956-
ffa450edef68
* @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);