Class: RocketAMF::Ext::Deserializer
- Inherits:
-
Object
- Object
- RocketAMF::Ext::Deserializer
- Defined in:
- ext/rocketamf_ext/deserializer.c
Instance Method Summary collapse
-
#deserialize(ver, src) ⇒ Object
Deserialize the string or StringIO from AMF to a ruby object.
-
#initialize(class_mapper) ⇒ Object
constructor
Initializer.
-
#read_object ⇒ Object
Reads an object from the deserializer’s stream and returns it.
-
#stream ⇒ StringIO
Returns the source that the deserializer is reading from.
Constructor Details
#initialize(class_mapper) ⇒ Object
Initializer
677 678 679 680 681 682 |
# File 'ext/rocketamf_ext/deserializer.c', line 677
static VALUE des_initialize(VALUE self, VALUE class_mapper) {
AMF_DESERIALIZER *des;
Data_Get_Struct(self, AMF_DESERIALIZER, des);
des->class_mapper = class_mapper;
return self;
}
|
Instance Method Details
#deserialize(amf_ver, str) ⇒ Object #deserialize(amf_ver, StringIO) ⇒ Object
Deserialize the string or StringIO from AMF to a ruby object.
703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 |
# File 'ext/rocketamf_ext/deserializer.c', line 703
VALUE des_deserialize(VALUE self, VALUE ver, VALUE src) {
AMF_DESERIALIZER *des;
Data_Get_Struct(self, AMF_DESERIALIZER, des);
// Process version
int int_ver = FIX2INT(ver);
if(int_ver != 0 && int_ver != 3) rb_raise(rb_eArgError, "unsupported version %d", int_ver);
des->version = int_ver;
// Process source
if(src != Qnil) {
des_set_src(des, src);
} else if(!des->src) {
rb_raise(rb_eArgError, "Missing deserialization source");
}
// Deserialize from source
VALUE ret;
if(des->version == 0) {
des->obj_cache = rb_ary_new();
ret = des0_deserialize(self, des_read_byte(des));
} else {
des->obj_cache = rb_ary_new();
des->str_cache = rb_ary_new();
des->trait_cache = rb_ary_new();
ret = des3_deserialize(self);
}
// Update source position
rb_funcall(des->src, rb_intern("pos="), 1, LONG2NUM(des->pos)); // Update source StringIO pos
return ret;
}
|
#read_object ⇒ Object
Reads an object from the deserializer’s stream and returns it.
743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 |
# File 'ext/rocketamf_ext/deserializer.c', line 743
VALUE des_read_object(VALUE self) {
AMF_DESERIALIZER *des;
Data_Get_Struct(self, AMF_DESERIALIZER, des);
// Update internal pos from source in case they've modified it
des->pos = NUM2LONG(rb_funcall(des->src, rb_intern("pos"), 0));
// Deserialize
VALUE ret;
if(des->version == 0) {
ret = des0_deserialize(self, des_read_byte(des));
} else {
ret = des3_deserialize(self);
}
// Update source position
rb_funcall(des->src, rb_intern("pos="), 1, LONG2NUM(des->pos)); // Update source StringIO pos
return ret;
}
|
#stream ⇒ StringIO
Returns the source that the deserializer is reading from
690 691 692 693 694 |
# File 'ext/rocketamf_ext/deserializer.c', line 690
static VALUE des_source(VALUE self) {
AMF_DESERIALIZER *des;
Data_Get_Struct(self, AMF_DESERIALIZER, des);
return des->src;
}
|