Class: RocketAMF::Ext::FastMappingSet

Inherits:
Object
  • Object
show all
Defined in:
ext/rocketamf_ext/class_mapping.c

Instance Method Summary collapse

Constructor Details

#RocketAMF::Ext::MappingSet.newObject

Creates a mapping set object and populates the default mappings



77
78
79
80
# File 'ext/rocketamf_ext/class_mapping.c', line 77

static VALUE mapset_init(VALUE self) {
    rb_funcall(self, rb_intern("map_defaults"), 0);
    return self;
}

Instance Method Details

#map(mapping) ⇒ Object

Map a given AS class to a ruby class. Use fully qualified names for both.



132
133
134
135
136
137
138
139
140
141
142
# File 'ext/rocketamf_ext/class_mapping.c', line 132

static VALUE mapset_map(VALUE self, VALUE mapping) {
    MAPSET *set;
    Data_Get_Struct(self, MAPSET, set);

    VALUE as_class = rb_hash_aref(mapping, ID2SYM(rb_intern("as")));
    VALUE rb_class = rb_hash_aref(mapping, ID2SYM(rb_intern("ruby")));
    st_insert(set->as_mappings, (st_data_t)strdup(RSTRING_PTR(as_class)), rb_class);
    st_insert(set->rb_mappings, (st_data_t)strdup(RSTRING_PTR(rb_class)), as_class);

    return Qnil;
}

#map_defaultsObject

Adds required mapping configs, calling map for the required base mappings



88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
# File 'ext/rocketamf_ext/class_mapping.c', line 88

static VALUE mapset_map_defaults(VALUE self) {
    const int NUM_MAPPINGS = 9;
    const char* ruby_classes[] = {
        "RocketAMF::Types::AbstractMessage",
        "RocketAMF::Types::RemotingMessage",
        "RocketAMF::Types::AsyncMessage",
        "RocketAMF::Types::AsyncMessageExt",
        "RocketAMF::Types::CommandMessage",
        "RocketAMF::Types::CommandMessageExt",
        "RocketAMF::Types::AcknowledgeMessageExt",
        "RocketAMF::Types::ErrorMessage"
    };
    const char* as_classes[] = {
        "flex.messaging.messages.AbstractMessage",
        "flex.messaging.messages.RemotingMessage",
        "flex.messaging.messages.AsyncMessage",
        "DSA",
        "flex.messaging.messages.CommandMessage",
        "DSC",
        "flex.messaging.messages.AcknowledgeMessage",
        "DSK",
        "flex.messaging.messages.ErrorMessage"
    };

    int i;
    ID map_id = rb_intern("map");
    VALUE params = rb_hash_new();
    VALUE as_sym = ID2SYM(rb_intern("as"));
    VALUE ruby_sym = ID2SYM(rb_intern("ruby"));
    for(i = 0; i < NUM_MAPPINGS; i++) {
        rb_hash_aset(params, as_sym, rb_str_new2(as_classes[i]));
        rb_hash_aset(params, ruby_sym, rb_str_new2(ruby_classes[i]));
        rb_funcall(self, map_id, 1, params);
    }

    return self;
}