Bryan Duxbury | c016628 | 2009-02-02 00:48:17 +0000 | [diff] [blame] | 1 | #include <ruby.h> |
| 2 | #include <struct.h> |
| 3 | #include <binary_protocol_accelerated.h> |
| 4 | #include <protocol.h> |
| 5 | #include <memory_buffer.h> |
| 6 | |
| 7 | // cached classes/modules |
| 8 | VALUE rb_cSet; |
| 9 | VALUE thrift_module; |
| 10 | VALUE thrift_types_module; |
| 11 | |
| 12 | // TType constants |
| 13 | int TTYPE_STOP; |
| 14 | int TTYPE_BOOL; |
| 15 | int TTYPE_BYTE; |
| 16 | int TTYPE_I16; |
| 17 | int TTYPE_I32; |
| 18 | int TTYPE_I64; |
| 19 | int TTYPE_DOUBLE; |
| 20 | int TTYPE_STRING; |
| 21 | int TTYPE_MAP; |
| 22 | int TTYPE_SET; |
| 23 | int TTYPE_LIST; |
| 24 | int TTYPE_STRUCT; |
| 25 | |
| 26 | // method ids |
| 27 | ID validate_method_id; |
| 28 | ID write_struct_begin_method_id; |
| 29 | ID write_struct_end_method_id; |
| 30 | ID write_field_begin_method_id; |
| 31 | ID write_field_end_method_id; |
| 32 | ID write_boolean_method_id; |
| 33 | ID write_byte_method_id; |
| 34 | ID write_i16_method_id; |
| 35 | ID write_i32_method_id; |
| 36 | ID write_i64_method_id; |
| 37 | ID write_double_method_id; |
| 38 | ID write_string_method_id; |
| 39 | ID write_map_begin_method_id; |
| 40 | ID write_map_end_method_id; |
| 41 | ID write_list_begin_method_id; |
| 42 | ID write_list_end_method_id; |
| 43 | ID write_set_begin_method_id; |
| 44 | ID write_set_end_method_id; |
| 45 | ID size_method_id; |
| 46 | ID read_bool_method_id; |
| 47 | ID read_byte_method_id; |
| 48 | ID read_i16_method_id; |
| 49 | ID read_i32_method_id; |
| 50 | ID read_i64_method_id; |
| 51 | ID read_string_method_id; |
| 52 | ID read_double_method_id; |
| 53 | ID read_map_begin_method_id; |
| 54 | ID read_map_end_method_id; |
| 55 | ID read_list_begin_method_id; |
| 56 | ID read_list_end_method_id; |
| 57 | ID read_set_begin_method_id; |
| 58 | ID read_set_end_method_id; |
| 59 | ID read_struct_begin_method_id; |
| 60 | ID read_struct_end_method_id; |
| 61 | ID read_field_begin_method_id; |
| 62 | ID read_field_end_method_id; |
| 63 | ID keys_method_id; |
| 64 | ID entries_method_id; |
| 65 | ID name_method_id; |
| 66 | ID sort_method_id; |
| 67 | ID write_field_stop_method_id; |
| 68 | ID skip_method_id; |
| 69 | ID write_method_id; |
| 70 | ID read_method_id; |
| 71 | ID native_qmark_method_id; |
| 72 | |
| 73 | // constant ids |
| 74 | ID fields_const_id; |
| 75 | ID transport_ivar_id; |
Kevin Clark | ead3382 | 2009-02-04 22:43:59 +0000 | [diff] [blame^] | 76 | ID strict_read_ivar_id; |
| 77 | ID strict_write_ivar_id; |
Bryan Duxbury | c016628 | 2009-02-02 00:48:17 +0000 | [diff] [blame] | 78 | |
| 79 | // cached symbols |
| 80 | VALUE type_sym; |
| 81 | VALUE name_sym; |
| 82 | VALUE key_sym; |
| 83 | VALUE value_sym; |
| 84 | VALUE element_sym; |
| 85 | VALUE class_sym; |
| 86 | VALUE protocol_exception_class; |
| 87 | |
| 88 | void Init_thrift_native() { |
| 89 | // cached classes |
| 90 | thrift_module = rb_const_get(rb_cObject, rb_intern("Thrift")); |
| 91 | thrift_types_module = rb_const_get(thrift_module, rb_intern("Types")); |
| 92 | rb_cSet = rb_const_get(rb_cObject, rb_intern("Set")); |
| 93 | protocol_exception_class = rb_const_get(thrift_module, rb_intern("ProtocolException")); |
| 94 | |
| 95 | // Init ttype constants |
| 96 | TTYPE_BOOL = FIX2INT(rb_const_get(thrift_types_module, rb_intern("BOOL"))); |
| 97 | TTYPE_BYTE = FIX2INT(rb_const_get(thrift_types_module, rb_intern("BYTE"))); |
| 98 | TTYPE_I16 = FIX2INT(rb_const_get(thrift_types_module, rb_intern("I16"))); |
| 99 | TTYPE_I32 = FIX2INT(rb_const_get(thrift_types_module, rb_intern("I32"))); |
| 100 | TTYPE_I64 = FIX2INT(rb_const_get(thrift_types_module, rb_intern("I64"))); |
| 101 | TTYPE_DOUBLE = FIX2INT(rb_const_get(thrift_types_module, rb_intern("DOUBLE"))); |
| 102 | TTYPE_STRING = FIX2INT(rb_const_get(thrift_types_module, rb_intern("STRING"))); |
| 103 | TTYPE_MAP = FIX2INT(rb_const_get(thrift_types_module, rb_intern("MAP"))); |
| 104 | TTYPE_SET = FIX2INT(rb_const_get(thrift_types_module, rb_intern("SET"))); |
| 105 | TTYPE_LIST = FIX2INT(rb_const_get(thrift_types_module, rb_intern("LIST"))); |
| 106 | TTYPE_STRUCT = FIX2INT(rb_const_get(thrift_types_module, rb_intern("STRUCT"))); |
| 107 | |
| 108 | // method ids |
| 109 | validate_method_id = rb_intern("validate"); |
| 110 | write_struct_begin_method_id = rb_intern("write_struct_begin"); |
| 111 | write_struct_end_method_id = rb_intern("write_struct_end"); |
| 112 | write_field_begin_method_id = rb_intern("write_field_begin"); |
| 113 | write_field_end_method_id = rb_intern("write_field_end"); |
| 114 | write_boolean_method_id = rb_intern("write_bool"); |
| 115 | write_byte_method_id = rb_intern("write_byte"); |
| 116 | write_i16_method_id = rb_intern("write_i16"); |
| 117 | write_i32_method_id = rb_intern("write_i32"); |
| 118 | write_i64_method_id = rb_intern("write_i64"); |
| 119 | write_double_method_id = rb_intern("write_double"); |
| 120 | write_string_method_id = rb_intern("write_string"); |
| 121 | write_map_begin_method_id = rb_intern("write_map_begin"); |
| 122 | write_map_end_method_id = rb_intern("write_map_end"); |
| 123 | write_list_begin_method_id = rb_intern("write_list_begin"); |
| 124 | write_list_end_method_id = rb_intern("write_list_end"); |
| 125 | write_set_begin_method_id = rb_intern("write_set_begin"); |
| 126 | write_set_end_method_id = rb_intern("write_set_end"); |
| 127 | size_method_id = rb_intern("size"); |
| 128 | read_bool_method_id = rb_intern("read_bool"); |
| 129 | read_byte_method_id = rb_intern("read_byte"); |
| 130 | read_i16_method_id = rb_intern("read_i16"); |
| 131 | read_i32_method_id = rb_intern("read_i32"); |
| 132 | read_i64_method_id = rb_intern("read_i64"); |
| 133 | read_string_method_id = rb_intern("read_string"); |
| 134 | read_double_method_id = rb_intern("read_double"); |
| 135 | read_map_begin_method_id = rb_intern("read_map_begin"); |
| 136 | read_map_end_method_id = rb_intern("read_map_end"); |
| 137 | read_list_begin_method_id = rb_intern("read_list_begin"); |
| 138 | read_list_end_method_id = rb_intern("read_list_end"); |
| 139 | read_set_begin_method_id = rb_intern("read_set_begin"); |
| 140 | read_set_end_method_id = rb_intern("read_set_end"); |
| 141 | read_struct_begin_method_id = rb_intern("read_struct_begin"); |
| 142 | read_struct_end_method_id = rb_intern("read_struct_end"); |
| 143 | read_field_begin_method_id = rb_intern("read_field_begin"); |
| 144 | read_field_end_method_id = rb_intern("read_field_end"); |
| 145 | keys_method_id = rb_intern("keys"); |
| 146 | entries_method_id = rb_intern("entries"); |
| 147 | name_method_id = rb_intern("name"); |
| 148 | sort_method_id = rb_intern("sort"); |
| 149 | write_field_stop_method_id = rb_intern("write_field_stop"); |
| 150 | skip_method_id = rb_intern("skip"); |
| 151 | write_method_id = rb_intern("write"); |
| 152 | read_method_id = rb_intern("read"); |
| 153 | native_qmark_method_id = rb_intern("native?"); |
| 154 | |
| 155 | // constant ids |
| 156 | fields_const_id = rb_intern("FIELDS"); |
| 157 | transport_ivar_id = rb_intern("@trans"); |
Kevin Clark | ead3382 | 2009-02-04 22:43:59 +0000 | [diff] [blame^] | 158 | strict_read_ivar_id = rb_intern("@strict_read"); |
| 159 | strict_write_ivar_id = rb_intern("@strict_write"); |
Bryan Duxbury | c016628 | 2009-02-02 00:48:17 +0000 | [diff] [blame] | 160 | |
| 161 | // cached symbols |
| 162 | type_sym = ID2SYM(rb_intern("type")); |
| 163 | name_sym = ID2SYM(rb_intern("name")); |
| 164 | key_sym = ID2SYM(rb_intern("key")); |
| 165 | value_sym = ID2SYM(rb_intern("value")); |
| 166 | element_sym = ID2SYM(rb_intern("element")); |
| 167 | class_sym = ID2SYM(rb_intern("class")); |
| 168 | |
| 169 | Init_protocol(); |
| 170 | Init_struct(); |
| 171 | Init_binary_protocol_accelerated(); |
| 172 | Init_memory_buffer(); |
Bryan Duxbury | 1e80d44 | 2009-02-03 18:16:54 +0000 | [diff] [blame] | 173 | } |