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