blob: 4d5623d42926d08293071ba91015a7e44e73d818 [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;
Kevin Clarkead33822009-02-04 22:43:59 +000076ID strict_read_ivar_id;
77ID strict_write_ivar_id;
Bryan Duxburyc0166282009-02-02 00:48:17 +000078
79// cached symbols
80VALUE type_sym;
81VALUE name_sym;
82VALUE key_sym;
83VALUE value_sym;
84VALUE element_sym;
85VALUE class_sym;
86VALUE protocol_exception_class;
87
88void 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 Clarkead33822009-02-04 22:43:59 +0000158 strict_read_ivar_id = rb_intern("@strict_read");
159 strict_write_ivar_id = rb_intern("@strict_write");
Bryan Duxburyc0166282009-02-02 00:48:17 +0000160
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 Duxbury1e80d442009-02-03 18:16:54 +0000173}