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