| 456 | } |
| 457 | |
| 458 | static VALUE read_anything(VALUE protocol, int ttype, VALUE field_info) { |
| 459 | VALUE result = Qnil; |
| 460 | |
| 461 | if (ttype == TTYPE_BOOL) { |
| 462 | result = default_read_bool(protocol); |
| 463 | } else if (ttype == TTYPE_BYTE) { |
| 464 | result = default_read_byte(protocol); |
| 465 | } else if (ttype == TTYPE_I16) { |
| 466 | result = default_read_i16(protocol); |
| 467 | } else if (ttype == TTYPE_I32) { |
| 468 | result = default_read_i32(protocol); |
| 469 | } else if (ttype == TTYPE_I64) { |
| 470 | result = default_read_i64(protocol); |
| 471 | } else if (ttype == TTYPE_STRING) { |
| 472 | VALUE is_binary = rb_hash_aref(field_info, binary_sym); |
| 473 | if (is_binary != Qtrue) { |
| 474 | result = default_read_string(protocol); |
| 475 | } else { |
| 476 | result = default_read_binary(protocol); |
| 477 | } |
| 478 | } else if (ttype == TTYPE_DOUBLE) { |
| 479 | result = default_read_double(protocol); |
| 480 | } else if (ttype == TTYPE_UUID) { |
| 481 | result = default_read_uuid(protocol); |
| 482 | } else if (ttype == TTYPE_STRUCT) { |
| 483 | VALUE klass = rb_hash_aref(field_info, class_sym); |
| 484 | result = rb_class_new_instance(0, NULL, klass); |
| 485 | |
| 486 | if (rb_obj_is_kind_of(result, thrift_union_class)) { |
| 487 | rb_thrift_union_read(result, protocol); |
| 488 | } else { |
| 489 | rb_thrift_struct_read(result, protocol); |
| 490 | } |
| 491 | } else if (ttype == TTYPE_MAP) { |
| 492 | int i; |
| 493 | |
| 494 | VALUE map_header = default_read_map_begin(protocol); |
| 495 | int key_ttype = FIX2INT(rb_ary_entry(map_header, 0)); |
| 496 | int value_ttype = FIX2INT(rb_ary_entry(map_header, 1)); |
| 497 | int num_entries = FIX2INT(rb_ary_entry(map_header, 2)); |
| 498 | |
| 499 | if (num_entries < 0) { |
| 500 | rb_exc_raise(get_protocol_exception(INT2FIX(PROTOERR_NEGATIVE_SIZE), rb_str_new2("Negative container size"))); |
| 501 | } |
| 502 | |
| 503 | // Check the declared key and value types against the expected ones and skip the map contents |
| 504 | // if the types don't match. |
| 505 | VALUE key_info = rb_hash_aref(field_info, key_sym); |
| 506 | VALUE value_info = rb_hash_aref(field_info, value_sym); |
| 507 | |
| 508 | if (!NIL_P(key_info) && !NIL_P(value_info)) { |
| 509 | int specified_key_type = FIX2INT(rb_hash_aref(key_info, type_sym)); |
| 510 | int specified_value_type = FIX2INT(rb_hash_aref(value_info, type_sym)); |
| 511 | if (num_entries == 0 || (specified_key_type == key_ttype && specified_value_type == value_ttype)) { |
| 512 | result = rb_hash_new(); |
| 513 | |
| 514 | for (i = 0; i < num_entries; ++i) { |
| 515 | VALUE key, val; |
no test coverage detected