if (!NIL_P(key_info) && !NIL_P(value_info)) {
int specified_key_type = FIX2INT(rb_hash_aref(key_info, type_sym));
int specified_value_type = FIX2INT(rb_hash_aref(value_info, type_sym));
- if (specified_key_type == key_ttype && specified_value_type == value_ttype) {
+ if (num_entries == 0 || (specified_key_type == key_ttype && specified_value_type == value_ttype)) {
result = rb_hash_new();
for (i = 0; i < num_entries; ++i) {
when Types::MAP
key_type, val_type, size = iprot.read_map_begin
# Skip the map contents if the declared key or value types don't match the expected ones.
- if (key_type != field[:key][:type] || val_type != field[:value][:type])
+ if (size != 0 && (key_type != field[:key][:type] || val_type != field[:value][:type]))
size.times do
iprot.skip(key_type)
iprot.skip(val_type)
brcp2.should == brcp
end
+ it "should deserialize an empty map to an empty hash" do
+ struct = SingleMapTestStruct.new(:i32_map => {})
+ ser = Thrift::Serializer.new(Thrift::CompactProtocolFactory.new)
+ bytes = ser.serialize(struct)
+
+ deser = Thrift::Deserializer.new(Thrift::CompactProtocolFactory.new)
+ struct2 = SingleMapTestStruct.new
+ deser.deserialize(struct2, bytes)
+ struct.should == struct2
+ end
+
class JankyHandler
def Janky(i32arg)
i32arg * 2
49: map<byte, list<byte>> byte_list_map;
}
+// To be used to test the serialization of an empty map
+struct SingleMapTestStruct {
+ 1: required map<i32, i32> i32_map;
+}
const CompactProtoTestStruct COMPACT_TEST = {
'a_byte' : 127,