const vector<t_field*>& fields = tstruct->get_members();
vector<t_field*>::const_iterator f_iter;
bool has_optional = false;
+ int optional_count = 0;
for (f_iter = fields.begin(); f_iter != fields.end(); ++f_iter) {
if ((*f_iter)->get_req() == t_field::T_OPTIONAL || (*f_iter)->get_req() == t_field::T_OPT_IN_REQ_OUT) {
+ optional_count++;
has_optional = true;
}
if ((*f_iter)->get_req() == t_field::T_REQUIRED) {
}
}
- indent(out) << "oprot.writeBitSet(optionals);" << endl;
+ indent(out) << "oprot.writeBitSet(optionals, " << optional_count << ");" << endl;
int j = 0;
for (f_iter = fields.begin(); f_iter != fields.end(); ++f_iter) {
if ((*f_iter)->get_req() == t_field::T_OPTIONAL || (*f_iter)->get_req() == t_field::T_OPT_IN_REQ_OUT) {
return TupleScheme.class;
}
- public void writeBitSet(BitSet bs) throws TException {
- byte[] bytes = toByteArray(bs);
+ public void writeBitSet(BitSet bs, int vectorWidth) throws TException {
+ byte[] bytes = toByteArray(bs, vectorWidth);
for (byte b : bytes) {
writeByte(b);
}
* assumed to be the least significant bit.
*
* @param bits
+ * @param vectorWidth
* @return a byte array of at least length 1
*/
- public static byte[] toByteArray(BitSet bits) {
- byte[] bytes = new byte[bits.length() / 8 + 1];
+ public static byte[] toByteArray(BitSet bits, int vectorWidth) {
+ byte[] bytes = new byte[vectorWidth / 8 + 1];
for (int i = 0; i < bits.length(); i++) {
if (bits.get(i)) {
bytes[bytes.length - i / 8 - 1] |= 1 << (i % 8);
package org.apache.thrift.protocol;
-import java.util.HashMap;
-import java.util.Map;
+import org.apache.thrift.TDeserializer;
+import org.apache.thrift.TSerializer;
-import org.apache.thrift.TException;
-import org.apache.thrift.transport.TMemoryBuffer;
-import org.apache.thrift.transport.TMemoryInputTransport;
+import thrift.test.TupleProtocolTestStruct;
-import thrift.test.Complex;
-import thrift.test.Simple;
public class TestTTupleProtocol extends ProtocolTestBase {
protected TProtocolFactory getFactory() {
return new TTupleProtocol.Factory();
}
+
+ public void testBitsetLengthIssue() throws Exception {
+ final TupleProtocolTestStruct t1 = new TupleProtocolTestStruct();
+ t1.setField1(0);
+ t1.setField2(12);
+ new TDeserializer(new TTupleProtocol.Factory()).deserialize(new TupleProtocolTestStruct(), new TSerializer(new TTupleProtocol.Factory()).serialize(t1));
+ }
}
3: i32 field3;
}
+struct TupleProtocolTestStruct {
+ optional i32 field1;
+ optional i32 field2;
+ optional i32 field3;
+ optional i32 field4;
+ optional i32 field5;
+ optional i32 field6;
+ optional i32 field7;
+ optional i32 field8;
+ optional i32 field9;
+ optional i32 field10;
+ optional i32 field11;
+ optional i32 field12;
+}
\ No newline at end of file