thrift 0.0.751142 → 0.0.810255.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (113) hide show
  1. data/CHANGELOG +3 -1
  2. data/Manifest +47 -44
  3. data/README +19 -6
  4. data/Rakefile +1 -1
  5. data/benchmark/Benchmark.thrift +19 -0
  6. data/benchmark/benchmark.rb +20 -3
  7. data/benchmark/client.rb +20 -2
  8. data/benchmark/server.rb +22 -4
  9. data/benchmark/thin_server.rb +22 -4
  10. data/ext/binary_protocol_accelerated.c +32 -21
  11. data/ext/binary_protocol_accelerated.h +19 -0
  12. data/ext/compact_protocol.c +665 -0
  13. data/ext/compact_protocol.h +20 -0
  14. data/ext/constants.h +19 -1
  15. data/ext/extconf.rb +19 -0
  16. data/ext/macros.h +41 -0
  17. data/ext/memory_buffer.c +29 -5
  18. data/ext/memory_buffer.h +19 -0
  19. data/ext/protocol.c +20 -1
  20. data/ext/protocol.h +19 -0
  21. data/ext/struct.c +115 -83
  22. data/ext/struct.h +19 -0
  23. data/ext/thrift_native.c +23 -2
  24. data/lib/thrift/client.rb +19 -1
  25. data/lib/thrift/core_ext/fixnum.rb +29 -0
  26. data/lib/thrift/core_ext.rb +23 -0
  27. data/lib/thrift/exceptions.rb +19 -2
  28. data/lib/thrift/processor.rb +19 -1
  29. data/lib/thrift/protocol/base_protocol.rb +290 -0
  30. data/lib/thrift/protocol/{binaryprotocol.rb → binary_protocol.rb} +27 -15
  31. data/lib/thrift/protocol/binary_protocol_accelerated.rb +35 -0
  32. data/lib/thrift/protocol/compact_protocol.rb +422 -0
  33. data/lib/thrift/serializer/deserializer.rb +33 -0
  34. data/lib/thrift/serializer/serializer.rb +34 -0
  35. data/lib/thrift/server/base_server.rb +31 -0
  36. data/lib/thrift/server/{httpserver.rb → mongrel_http_server.rb} +19 -5
  37. data/lib/thrift/server/{nonblockingserver.rb → nonblocking_server.rb} +42 -24
  38. data/lib/thrift/server/simple_server.rb +43 -0
  39. data/lib/thrift/server/thread_pool_server.rb +75 -0
  40. data/lib/thrift/server/threaded_server.rb +47 -0
  41. data/lib/thrift/struct.rb +73 -47
  42. data/lib/thrift/thrift_native.rb +24 -0
  43. data/lib/thrift/transport/base_server_transport.rb +37 -0
  44. data/lib/thrift/transport/base_transport.rb +70 -0
  45. data/lib/thrift/transport/buffered_transport.rb +77 -0
  46. data/lib/thrift/transport/framed_transport.rb +90 -0
  47. data/lib/thrift/transport/http_client_transport.rb +45 -0
  48. data/lib/thrift/transport/io_stream_transport.rb +39 -0
  49. data/lib/thrift/transport/memory_buffer_transport.rb +96 -0
  50. data/lib/thrift/transport/server_socket.rb +63 -0
  51. data/lib/thrift/transport/socket.rb +22 -53
  52. data/lib/thrift/transport/unix_server_socket.rb +60 -0
  53. data/lib/thrift/transport/unix_socket.rb +40 -0
  54. data/lib/thrift/types.rb +20 -2
  55. data/lib/thrift.rb +50 -19
  56. data/script/proto_benchmark.rb +121 -0
  57. data/script/read_struct.rb +43 -0
  58. data/script/write_struct.rb +30 -0
  59. data/spec/ThriftSpec.thrift +40 -2
  60. data/spec/{protocol_spec.rb → base_protocol_spec.rb} +25 -7
  61. data/spec/{transport_spec.rb → base_transport_spec.rb} +44 -52
  62. data/spec/binary_protocol_accelerated_spec.rb +41 -0
  63. data/spec/{binaryprotocol_spec.rb → binary_protocol_spec.rb} +20 -2
  64. data/spec/{binaryprotocol_spec_shared.rb → binary_protocol_spec_shared.rb} +117 -16
  65. data/spec/client_spec.rb +23 -4
  66. data/spec/compact_protocol_spec.rb +117 -0
  67. data/spec/exception_spec.rb +19 -0
  68. data/spec/http_client_spec.rb +49 -0
  69. data/spec/{httpserver_spec.rb → mongrel_http_server_spec.rb} +26 -7
  70. data/spec/{nonblockingserver_spec.rb → nonblocking_server_spec.rb} +25 -5
  71. data/spec/processor_spec.rb +19 -0
  72. data/spec/serializer_spec.rb +27 -10
  73. data/spec/server_socket_spec.rb +80 -0
  74. data/spec/server_spec.rb +35 -16
  75. data/spec/socket_spec.rb +19 -55
  76. data/spec/socket_spec_shared.rb +19 -0
  77. data/spec/spec_helper.rb +34 -9
  78. data/spec/struct_spec.rb +26 -18
  79. data/spec/types_spec.rb +19 -1
  80. data/spec/{unixsocket_spec.rb → unix_socket_spec.rb} +19 -1
  81. data/thrift.gemspec +6 -6
  82. data.tar.gz.sig +0 -0
  83. metadata +80 -70
  84. metadata.gz.sig +0 -0
  85. data/COPYING +0 -14
  86. data/LICENSE +0 -14
  87. data/Makefile.am +0 -15
  88. data/benchmark/gen-rb/BenchmarkService.rb +0 -81
  89. data/benchmark/gen-rb/Benchmark_constants.rb +0 -11
  90. data/benchmark/gen-rb/Benchmark_types.rb +0 -10
  91. data/lib/thrift/deprecation.rb +0 -155
  92. data/lib/thrift/protocol/binaryprotocolaccelerated.rb +0 -19
  93. data/lib/thrift/protocol/tbinaryprotocol.rb +0 -2
  94. data/lib/thrift/protocol/tprotocol.rb +0 -2
  95. data/lib/thrift/protocol.rb +0 -270
  96. data/lib/thrift/serializer.rb +0 -27
  97. data/lib/thrift/server/thttpserver.rb +0 -2
  98. data/lib/thrift/server/tserver.rb +0 -2
  99. data/lib/thrift/server.rb +0 -135
  100. data/lib/thrift/thrift.rb +0 -14
  101. data/lib/thrift/transport/httpclient.rb +0 -29
  102. data/lib/thrift/transport/thttpclient.rb +0 -2
  103. data/lib/thrift/transport/tsocket.rb +0 -2
  104. data/lib/thrift/transport/ttransport.rb +0 -2
  105. data/lib/thrift/transport/unixsocket.rb +0 -58
  106. data/lib/thrift/transport.rb +0 -319
  107. data/spec/backwards_compatibility_spec.rb +0 -136
  108. data/spec/binaryprotocolaccelerated_spec.rb +0 -101
  109. data/spec/deprecation_spec.rb +0 -443
  110. data/spec/gen-rb/NonblockingService.rb +0 -268
  111. data/spec/gen-rb/ThriftSpec_constants.rb +0 -11
  112. data/spec/gen-rb/ThriftSpec_types.rb +0 -134
  113. data/spec/httpclient_spec.rb +0 -31
data/ext/constants.h CHANGED
@@ -1,3 +1,21 @@
1
+ /*
2
+ * Licensed to the Apache Software Foundation (ASF) under one
3
+ * or more contributor license agreements. See the NOTICE file
4
+ * distributed with this work for additional information
5
+ * regarding copyright ownership. The ASF licenses this file
6
+ * to you under the Apache License, Version 2.0 (the
7
+ * "License"); you may not use this file except in compliance
8
+ * with the License. You may obtain a copy of the License at
9
+ *
10
+ * http://www.apache.org/licenses/LICENSE-2.0
11
+ *
12
+ * Unless required by applicable law or agreed to in writing,
13
+ * software distributed under the License is distributed on an
14
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15
+ * KIND, either express or implied. See the License for the
16
+ * specific language governing permissions and limitations
17
+ * under the License.
18
+ */
1
19
 
2
20
  extern int TTYPE_STOP;
3
21
  extern int TTYPE_BOOL;
@@ -55,7 +73,7 @@ extern ID sort_method_id;
55
73
  extern ID write_field_stop_method_id;
56
74
  extern ID skip_method_id;
57
75
  extern ID write_method_id;
58
- extern ID read_method_id;
76
+ extern ID read_all_method_id;
59
77
  extern ID native_qmark_method_id;
60
78
 
61
79
  extern ID fields_const_id;
data/ext/extconf.rb CHANGED
@@ -1,3 +1,22 @@
1
+ #
2
+ # Licensed to the Apache Software Foundation (ASF) under one
3
+ # or more contributor license agreements. See the NOTICE file
4
+ # distributed with this work for additional information
5
+ # regarding copyright ownership. The ASF licenses this file
6
+ # to you under the Apache License, Version 2.0 (the
7
+ # "License"); you may not use this file except in compliance
8
+ # with the License. You may obtain a copy of the License at
9
+ #
10
+ # http://www.apache.org/licenses/LICENSE-2.0
11
+ #
12
+ # Unless required by applicable law or agreed to in writing,
13
+ # software distributed under the License is distributed on an
14
+ # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15
+ # KIND, either express or implied. See the License for the
16
+ # specific language governing permissions and limitations
17
+ # under the License.
18
+ #
19
+
1
20
  require 'mkmf'
2
21
 
3
22
  $CFLAGS = "-g -O2 -Wall -Werror"
data/ext/macros.h ADDED
@@ -0,0 +1,41 @@
1
+ /*
2
+ * Licensed to the Apache Software Foundation (ASF) under one
3
+ * or more contributor license agreements. See the NOTICE file
4
+ * distributed with this work for additional information
5
+ * regarding copyright ownership. The ASF licenses this file
6
+ * to you under the Apache License, Version 2.0 (the
7
+ * "License"); you may not use this file except in compliance
8
+ * with the License. You may obtain a copy of the License at
9
+ *
10
+ * http://www.apache.org/licenses/LICENSE-2.0
11
+ *
12
+ * Unless required by applicable law or agreed to in writing,
13
+ * software distributed under the License is distributed on an
14
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15
+ * KIND, either express or implied. See the License for the
16
+ * specific language governing permissions and limitations
17
+ * under the License.
18
+ */
19
+
20
+ #define GET_TRANSPORT(obj) rb_ivar_get(obj, transport_ivar_id)
21
+ #define GET_STRICT_READ(obj) rb_ivar_get(obj, strict_read_ivar_id)
22
+ #define GET_STRICT_WRITE(obj) rb_ivar_get(obj, strict_write_ivar_id)
23
+ #define WRITE(obj, data, length) rb_funcall(obj, write_method_id, 1, rb_str_new(data, length))
24
+ #define CHECK_NIL(obj) if (NIL_P(obj)) { rb_raise(rb_eStandardError, "nil argument not allowed!");}
25
+ #define READ(obj, length) rb_funcall(GET_TRANSPORT(obj), read_all_method_id, 1, INT2FIX(length))
26
+
27
+ #ifndef RFLOAT_VALUE
28
+ # define RFLOAT_VALUE(v) RFLOAT(rb_Float(v))->value
29
+ #endif
30
+
31
+ #ifndef RSTRING_LEN
32
+ # define RSTRING_LEN(v) RSTRING(rb_String(v))->len
33
+ #endif
34
+
35
+ #ifndef RSTRING_PTR
36
+ # define RSTRING_PTR(v) RSTRING(rb_String(v))->ptr
37
+ #endif
38
+
39
+ #ifndef RARRAY_LEN
40
+ # define RARRAY_LEN(v) RARRAY(rb_Array(v))->len
41
+ #endif
data/ext/memory_buffer.c CHANGED
@@ -1,5 +1,25 @@
1
+ /**
2
+ * Licensed to the Apache Software Foundation (ASF) under one
3
+ * or more contributor license agreements. See the NOTICE file
4
+ * distributed with this work for additional information
5
+ * regarding copyright ownership. The ASF licenses this file
6
+ * to you under the Apache License, Version 2.0 (the
7
+ * "License"); you may not use this file except in compliance
8
+ * with the License. You may obtain a copy of the License at
9
+ *
10
+ * http://www.apache.org/licenses/LICENSE-2.0
11
+ *
12
+ * Unless required by applicable law or agreed to in writing,
13
+ * software distributed under the License is distributed on an
14
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15
+ * KIND, either express or implied. See the License for the
16
+ * specific language governing permissions and limitations
17
+ * under the License.
18
+ */
19
+
1
20
  #include <ruby.h>
2
21
  #include <constants.h>
22
+ #include "macros.h"
3
23
 
4
24
  ID buf_ivar_id;
5
25
  ID index_ivar_id;
@@ -12,7 +32,7 @@ int GARBAGE_BUFFER_SIZE;
12
32
 
13
33
  VALUE rb_thrift_memory_buffer_write(VALUE self, VALUE str) {
14
34
  VALUE buf = GET_BUF(self);
15
- rb_str_buf_cat(buf, RSTRING(str)->ptr, RSTRING(str)->len);
35
+ rb_str_buf_cat(buf, RSTRING_PTR(str), RSTRING_LEN(str));
16
36
  return Qnil;
17
37
  }
18
38
 
@@ -26,20 +46,24 @@ VALUE rb_thrift_memory_buffer_read(VALUE self, VALUE length_value) {
26
46
  VALUE data = rb_funcall(buf, slice_method_id, 2, index_value, length_value);
27
47
 
28
48
  index += length;
29
- if (index > RSTRING(buf)->len) {
30
- index = RSTRING(buf)->len;
49
+ if (index > RSTRING_LEN(buf)) {
50
+ index = RSTRING_LEN(buf);
31
51
  }
32
52
  if (index >= GARBAGE_BUFFER_SIZE) {
33
- rb_ivar_set(self, buf_ivar_id, rb_funcall(buf, slice_method_id, 2, INT2FIX(index), INT2FIX(-1)));
53
+ rb_ivar_set(self, buf_ivar_id, rb_funcall(buf, slice_method_id, 2, INT2FIX(index), INT2FIX(RSTRING_LEN(buf) - 1)));
34
54
  index = 0;
35
55
  }
36
56
 
57
+ if (RSTRING_LEN(data) < length) {
58
+ rb_raise(rb_eEOFError, "Not enough bytes remain in memory buffer");
59
+ }
60
+
37
61
  rb_ivar_set(self, index_ivar_id, INT2FIX(index));
38
62
  return data;
39
63
  }
40
64
 
41
65
  void Init_memory_buffer() {
42
- VALUE thrift_memory_buffer_class = rb_const_get(thrift_module, rb_intern("MemoryBuffer"));
66
+ VALUE thrift_memory_buffer_class = rb_const_get(thrift_module, rb_intern("MemoryBufferTransport"));
43
67
  rb_define_method(thrift_memory_buffer_class, "write", rb_thrift_memory_buffer_write, 1);
44
68
  rb_define_method(thrift_memory_buffer_class, "read", rb_thrift_memory_buffer_read, 1);
45
69
 
data/ext/memory_buffer.h CHANGED
@@ -1 +1,20 @@
1
+ /*
2
+ * Licensed to the Apache Software Foundation (ASF) under one
3
+ * or more contributor license agreements. See the NOTICE file
4
+ * distributed with this work for additional information
5
+ * regarding copyright ownership. The ASF licenses this file
6
+ * to you under the Apache License, Version 2.0 (the
7
+ * "License"); you may not use this file except in compliance
8
+ * with the License. You may obtain a copy of the License at
9
+ *
10
+ * http://www.apache.org/licenses/LICENSE-2.0
11
+ *
12
+ * Unless required by applicable law or agreed to in writing,
13
+ * software distributed under the License is distributed on an
14
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15
+ * KIND, either express or implied. See the License for the
16
+ * specific language governing permissions and limitations
17
+ * under the License.
18
+ */
19
+
1
20
  void Init_memory_buffer();
data/ext/protocol.c CHANGED
@@ -1,3 +1,22 @@
1
+ /**
2
+ * Licensed to the Apache Software Foundation (ASF) under one
3
+ * or more contributor license agreements. See the NOTICE file
4
+ * distributed with this work for additional information
5
+ * regarding copyright ownership. The ASF licenses this file
6
+ * to you under the Apache License, Version 2.0 (the
7
+ * "License"); you may not use this file except in compliance
8
+ * with the License. You may obtain a copy of the License at
9
+ *
10
+ * http://www.apache.org/licenses/LICENSE-2.0
11
+ *
12
+ * Unless required by applicable law or agreed to in writing,
13
+ * software distributed under the License is distributed on an
14
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15
+ * KIND, either express or implied. See the License for the
16
+ * specific language governing permissions and limitations
17
+ * under the License.
18
+ */
19
+
1
20
  #include <ruby.h>
2
21
  #include <protocol.h>
3
22
  #include <stdbool.h>
@@ -125,7 +144,7 @@ VALUE rb_thift_read_set_end(VALUE self) {
125
144
  }
126
145
 
127
146
  void Init_protocol() {
128
- VALUE c_protocol = rb_const_get(thrift_module, rb_intern("Protocol"));
147
+ VALUE c_protocol = rb_const_get(thrift_module, rb_intern("BaseProtocol"));
129
148
 
130
149
  rb_define_method(c_protocol, "skip", rb_thrift_protocol_skip, 1);
131
150
  rb_define_method(c_protocol, "write_message_end", rb_thrift_write_message_end, 0);
data/ext/protocol.h CHANGED
@@ -1 +1,20 @@
1
+ /*
2
+ * Licensed to the Apache Software Foundation (ASF) under one
3
+ * or more contributor license agreements. See the NOTICE file
4
+ * distributed with this work for additional information
5
+ * regarding copyright ownership. The ASF licenses this file
6
+ * to you under the Apache License, Version 2.0 (the
7
+ * "License"); you may not use this file except in compliance
8
+ * with the License. You may obtain a copy of the License at
9
+ *
10
+ * http://www.apache.org/licenses/LICENSE-2.0
11
+ *
12
+ * Unless required by applicable law or agreed to in writing,
13
+ * software distributed under the License is distributed on an
14
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15
+ * KIND, either express or implied. See the License for the
16
+ * specific language governing permissions and limitations
17
+ * under the License.
18
+ */
19
+
1
20
  void Init_protocol();
data/ext/struct.c CHANGED
@@ -1,5 +1,25 @@
1
+ /**
2
+ * Licensed to the Apache Software Foundation (ASF) under one
3
+ * or more contributor license agreements. See the NOTICE file
4
+ * distributed with this work for additional information
5
+ * regarding copyright ownership. The ASF licenses this file
6
+ * to you under the Apache License, Version 2.0 (the
7
+ * "License"); you may not use this file except in compliance
8
+ * with the License. You may obtain a copy of the License at
9
+ *
10
+ * http://www.apache.org/licenses/LICENSE-2.0
11
+ *
12
+ * Unless required by applicable law or agreed to in writing,
13
+ * software distributed under the License is distributed on an
14
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15
+ * KIND, either express or implied. See the License for the
16
+ * specific language governing permissions and limitations
17
+ * under the License.
18
+ */
19
+
1
20
  #include <struct.h>
2
21
  #include <constants.h>
22
+ #include "macros.h"
3
23
 
4
24
  #ifndef HAVE_STRLCPY
5
25
 
@@ -24,10 +44,30 @@ strlcpy (char *dst, const char *src, size_t dst_sz)
24
44
  #endif
25
45
 
26
46
  static native_proto_method_table *mt;
47
+ static native_proto_method_table *default_mt;
48
+ // static VALUE last_proto_class = Qnil;
27
49
 
28
50
  #define IS_CONTAINER(ttype) ((ttype) == TTYPE_MAP || (ttype) == TTYPE_LIST || (ttype) == TTYPE_SET)
29
51
  #define STRUCT_FIELDS(obj) rb_const_get(CLASS_OF(obj), fields_const_id)
30
52
 
53
+ // static void set_native_proto_function_pointers(VALUE protocol) {
54
+ // VALUE method_table_object = rb_const_get(CLASS_OF(protocol), rb_intern("@native_method_table"));
55
+ // // TODO: check nil?
56
+ // Data_Get_Struct(method_table_object, native_proto_method_table, mt);
57
+ // }
58
+
59
+ // static void check_native_proto_method_table(VALUE protocol) {
60
+ // VALUE protoclass = CLASS_OF(protocol);
61
+ // if (protoclass != last_proto_class) {
62
+ // last_proto_class = protoclass;
63
+ // if (rb_funcall(protocol, native_qmark_method_id, 0) == Qtrue) {
64
+ // set_native_proto_function_pointers(protocol);
65
+ // } else {
66
+ // mt = default_mt;
67
+ // }
68
+ // }
69
+ // }
70
+
31
71
  //-------------------------------------------
32
72
  // Writing section
33
73
  //-------------------------------------------
@@ -193,51 +233,44 @@ VALUE default_read_struct_end(VALUE protocol) {
193
233
  }
194
234
 
195
235
  static void set_default_proto_function_pointers() {
196
- mt = ALLOC(native_proto_method_table);
197
-
198
- mt->write_field_begin = default_write_field_begin;
199
- mt->write_field_stop = default_write_field_stop;
200
- mt->write_map_begin = default_write_map_begin;
201
- mt->write_map_end = default_write_map_end;
202
- mt->write_list_begin = default_write_list_begin;
203
- mt->write_list_end = default_write_list_end;
204
- mt->write_set_begin = default_write_set_begin;
205
- mt->write_set_end = default_write_set_end;
206
- mt->write_byte = default_write_byte;
207
- mt->write_bool = default_write_bool;
208
- mt->write_i16 = default_write_i16;
209
- mt->write_i32 = default_write_i32;
210
- mt->write_i64 = default_write_i64;
211
- mt->write_double = default_write_double;
212
- mt->write_string = default_write_string;
213
- mt->write_struct_begin = default_write_struct_begin;
214
- mt->write_struct_end = default_write_struct_end;
215
- mt->write_field_end = default_write_field_end;
216
-
217
- mt->read_struct_begin = default_read_struct_begin;
218
- mt->read_struct_end = default_read_struct_end;
219
- mt->read_field_begin = default_read_field_begin;
220
- mt->read_field_end = default_read_field_end;
221
- mt->read_map_begin = default_read_map_begin;
222
- mt->read_map_end = default_read_map_end;
223
- mt->read_list_begin = default_read_list_begin;
224
- mt->read_list_end = default_read_list_end;
225
- mt->read_set_begin = default_read_set_begin;
226
- mt->read_set_end = default_read_set_end;
227
- mt->read_byte = default_read_byte;
228
- mt->read_bool = default_read_bool;
229
- mt->read_i16 = default_read_i16;
230
- mt->read_i32 = default_read_i32;
231
- mt->read_i64 = default_read_i64;
232
- mt->read_double = default_read_double;
233
- mt->read_string = default_read_string;
234
-
235
- }
236
-
237
- static void set_native_proto_function_pointers(VALUE protocol) {
238
- VALUE method_table_object = rb_const_get(CLASS_OF(protocol), rb_intern("@native_method_table"));
239
- // TODO: check nil?
240
- Data_Get_Struct(method_table_object, native_proto_method_table, mt);
236
+ default_mt = ALLOC(native_proto_method_table);
237
+
238
+ default_mt->write_field_begin = default_write_field_begin;
239
+ default_mt->write_field_stop = default_write_field_stop;
240
+ default_mt->write_map_begin = default_write_map_begin;
241
+ default_mt->write_map_end = default_write_map_end;
242
+ default_mt->write_list_begin = default_write_list_begin;
243
+ default_mt->write_list_end = default_write_list_end;
244
+ default_mt->write_set_begin = default_write_set_begin;
245
+ default_mt->write_set_end = default_write_set_end;
246
+ default_mt->write_byte = default_write_byte;
247
+ default_mt->write_bool = default_write_bool;
248
+ default_mt->write_i16 = default_write_i16;
249
+ default_mt->write_i32 = default_write_i32;
250
+ default_mt->write_i64 = default_write_i64;
251
+ default_mt->write_double = default_write_double;
252
+ default_mt->write_string = default_write_string;
253
+ default_mt->write_struct_begin = default_write_struct_begin;
254
+ default_mt->write_struct_end = default_write_struct_end;
255
+ default_mt->write_field_end = default_write_field_end;
256
+
257
+ default_mt->read_struct_begin = default_read_struct_begin;
258
+ default_mt->read_struct_end = default_read_struct_end;
259
+ default_mt->read_field_begin = default_read_field_begin;
260
+ default_mt->read_field_end = default_read_field_end;
261
+ default_mt->read_map_begin = default_read_map_begin;
262
+ default_mt->read_map_end = default_read_map_end;
263
+ default_mt->read_list_begin = default_read_list_begin;
264
+ default_mt->read_list_end = default_read_list_end;
265
+ default_mt->read_set_begin = default_read_set_begin;
266
+ default_mt->read_set_end = default_read_set_end;
267
+ default_mt->read_byte = default_read_byte;
268
+ default_mt->read_bool = default_read_bool;
269
+ default_mt->read_i16 = default_read_i16;
270
+ default_mt->read_i32 = default_read_i32;
271
+ default_mt->read_i64 = default_read_i64;
272
+ default_mt->read_double = default_read_double;
273
+ default_mt->read_string = default_read_string;
241
274
  }
242
275
 
243
276
  // end default protocol methods
@@ -247,10 +280,10 @@ static VALUE rb_thrift_struct_write(VALUE self, VALUE protocol);
247
280
  static void write_anything(int ttype, VALUE value, VALUE protocol, VALUE field_info);
248
281
 
249
282
  VALUE get_field_value(VALUE obj, VALUE field_name) {
250
- char name_buf[RSTRING(field_name)->len + 1];
283
+ char name_buf[RSTRING_LEN(field_name) + 1];
251
284
 
252
285
  name_buf[0] = '@';
253
- strlcpy(&name_buf[1], RSTRING(field_name)->ptr, sizeof(name_buf));
286
+ strlcpy(&name_buf[1], RSTRING_PTR(field_name), sizeof(name_buf));
254
287
 
255
288
  VALUE value = rb_ivar_get(obj, rb_intern(name_buf));
256
289
 
@@ -277,7 +310,7 @@ static void write_container(int ttype, VALUE field_info, VALUE value, VALUE prot
277
310
 
278
311
  keys = rb_funcall(value, keys_method_id, 0);
279
312
 
280
- sz = RARRAY(keys)->len;
313
+ sz = RARRAY_LEN(keys);
281
314
 
282
315
  mt->write_map_begin(protocol, keytype_value, valuetype_value, INT2FIX(sz));
283
316
 
@@ -302,7 +335,7 @@ static void write_container(int ttype, VALUE field_info, VALUE value, VALUE prot
302
335
  } else if (ttype == TTYPE_LIST) {
303
336
  Check_Type(value, T_ARRAY);
304
337
 
305
- sz = RARRAY(value)->len;
338
+ sz = RARRAY_LEN(value);
306
339
 
307
340
  VALUE element_type_info = rb_hash_aref(field_info, element_sym);
308
341
  VALUE element_type_value = rb_hash_aref(element_type_info, type_sym);
@@ -332,7 +365,7 @@ static void write_container(int ttype, VALUE field_info, VALUE value, VALUE prot
332
365
  }
333
366
  }
334
367
 
335
- sz = RARRAY(items)->len;
368
+ sz = RARRAY_LEN(items);
336
369
 
337
370
  VALUE element_type_info = rb_hash_aref(field_info, element_sym);
338
371
  VALUE element_type_value = rb_hash_aref(element_type_info, type_sym);
@@ -383,22 +416,18 @@ static VALUE rb_thrift_struct_write(VALUE self, VALUE protocol) {
383
416
  // call validate
384
417
  rb_funcall(self, validate_method_id, 0);
385
418
 
386
- if (RTEST(rb_funcall(protocol, native_qmark_method_id, 0))) {
387
- set_native_proto_function_pointers(protocol);
388
- } else {
389
- set_default_proto_function_pointers();
390
- }
391
-
419
+ // check_native_proto_method_table(protocol);
420
+
392
421
  // write struct begin
393
422
  mt->write_struct_begin(protocol, rb_class_name(CLASS_OF(self)));
394
-
423
+
395
424
  // iterate through all the fields here
396
425
  VALUE struct_fields = STRUCT_FIELDS(self);
397
426
  VALUE struct_field_ids_unordered = rb_funcall(struct_fields, keys_method_id, 0);
398
427
  VALUE struct_field_ids_ordered = rb_funcall(struct_field_ids_unordered, sort_method_id, 0);
399
-
428
+
400
429
  int i = 0;
401
- for (i=0; i < RARRAY(struct_field_ids_ordered)->len; i++) {
430
+ for (i=0; i < RARRAY_LEN(struct_field_ids_ordered); i++) {
402
431
  VALUE field_id = rb_ary_entry(struct_field_ids_ordered, i);
403
432
  VALUE field_info = rb_hash_aref(struct_fields, field_id);
404
433
 
@@ -415,12 +444,12 @@ static VALUE rb_thrift_struct_write(VALUE self, VALUE protocol) {
415
444
  mt->write_field_end(protocol);
416
445
  }
417
446
  }
418
-
447
+
419
448
  mt->write_field_stop(protocol);
420
-
449
+
421
450
  // write struct end
422
451
  mt->write_struct_end(protocol);
423
-
452
+
424
453
  return Qnil;
425
454
  }
426
455
 
@@ -431,17 +460,17 @@ static VALUE rb_thrift_struct_write(VALUE self, VALUE protocol) {
431
460
  static VALUE rb_thrift_struct_read(VALUE self, VALUE protocol);
432
461
 
433
462
  static void set_field_value(VALUE obj, VALUE field_name, VALUE value) {
434
- char name_buf[RSTRING(field_name)->len + 1];
463
+ char name_buf[RSTRING_LEN(field_name) + 1];
435
464
 
436
465
  name_buf[0] = '@';
437
- strlcpy(&name_buf[1], RSTRING(field_name)->ptr, sizeof(name_buf));
466
+ strlcpy(&name_buf[1], RSTRING_PTR(field_name), sizeof(name_buf));
438
467
 
439
468
  rb_ivar_set(obj, rb_intern(name_buf), value);
440
469
  }
441
470
 
442
471
  static VALUE read_anything(VALUE protocol, int ttype, VALUE field_info) {
443
472
  VALUE result = Qnil;
444
-
473
+
445
474
  if (ttype == TTYPE_BOOL) {
446
475
  result = mt->read_bool(protocol);
447
476
  } else if (ttype == TTYPE_BYTE) {
@@ -467,21 +496,21 @@ static VALUE read_anything(VALUE protocol, int ttype, VALUE field_info) {
467
496
  int key_ttype = FIX2INT(rb_ary_entry(map_header, 0));
468
497
  int value_ttype = FIX2INT(rb_ary_entry(map_header, 1));
469
498
  int num_entries = FIX2INT(rb_ary_entry(map_header, 2));
470
-
499
+
471
500
  VALUE key_info = rb_hash_aref(field_info, key_sym);
472
501
  VALUE value_info = rb_hash_aref(field_info, value_sym);
473
502
 
474
503
  result = rb_hash_new();
475
-
504
+
476
505
  for (i = 0; i < num_entries; ++i) {
477
506
  VALUE key, val;
478
-
507
+
479
508
  key = read_anything(protocol, key_ttype, key_info);
480
509
  val = read_anything(protocol, value_ttype, value_info);
481
-
510
+
482
511
  rb_hash_aset(result, key, val);
483
512
  }
484
-
513
+
485
514
  mt->read_map_end(protocol);
486
515
  } else if (ttype == TTYPE_LIST) {
487
516
  int i;
@@ -490,7 +519,7 @@ static VALUE read_anything(VALUE protocol, int ttype, VALUE field_info) {
490
519
  int element_ttype = FIX2INT(rb_ary_entry(list_header, 0));
491
520
  int num_elements = FIX2INT(rb_ary_entry(list_header, 1));
492
521
  result = rb_ary_new2(num_elements);
493
-
522
+
494
523
  for (i = 0; i < num_elements; ++i) {
495
524
  rb_ary_push(result, read_anything(protocol, element_ttype, rb_hash_aref(field_info, element_sym)));
496
525
  }
@@ -505,34 +534,36 @@ static VALUE read_anything(VALUE protocol, int ttype, VALUE field_info) {
505
534
  int element_ttype = FIX2INT(rb_ary_entry(set_header, 0));
506
535
  int num_elements = FIX2INT(rb_ary_entry(set_header, 1));
507
536
  items = rb_ary_new2(num_elements);
508
-
537
+
509
538
  for (i = 0; i < num_elements; ++i) {
510
539
  rb_ary_push(items, read_anything(protocol, element_ttype, rb_hash_aref(field_info, element_sym)));
511
540
  }
512
-
541
+
513
542
 
514
543
  mt->read_set_end(protocol);
515
-
544
+
516
545
  result = rb_class_new_instance(1, &items, rb_cSet);
517
546
  } else {
518
547
  rb_raise(rb_eNotImpError, "read_anything not implemented for type %d!", ttype);
519
548
  }
520
-
549
+
521
550
  return result;
522
551
  }
523
552
 
524
553
  static VALUE rb_thrift_struct_read(VALUE self, VALUE protocol) {
554
+ // check_native_proto_method_table(protocol);
555
+
525
556
  // read struct begin
526
557
  mt->read_struct_begin(protocol);
527
558
 
528
559
  VALUE struct_fields = STRUCT_FIELDS(self);
529
-
560
+
530
561
  // read each field
531
562
  while (true) {
532
- VALUE field_header = rb_funcall(protocol, read_field_begin_method_id, 0);
563
+ VALUE field_header = mt->read_field_begin(protocol);
533
564
  VALUE field_type_value = rb_ary_entry(field_header, 1);
534
565
  int field_type = FIX2INT(field_type_value);
535
-
566
+
536
567
  if (field_type == TTYPE_STOP) {
537
568
  break;
538
569
  }
@@ -552,23 +583,24 @@ static VALUE rb_thrift_struct_read(VALUE self, VALUE protocol) {
552
583
  } else {
553
584
  rb_funcall(protocol, skip_method_id, 1, field_type_value);
554
585
  }
555
-
586
+
556
587
  // read field end
557
588
  mt->read_field_end(protocol);
558
589
  }
559
-
590
+
560
591
  // read struct end
561
592
  mt->read_struct_end(protocol);
562
-
593
+
563
594
  return Qnil;
564
595
  }
565
596
 
566
597
  void Init_struct() {
567
598
  VALUE struct_module = rb_const_get(thrift_module, rb_intern("Struct"));
568
-
599
+
569
600
  rb_define_method(struct_module, "write", rb_thrift_struct_write, 1);
570
601
  rb_define_method(struct_module, "read", rb_thrift_struct_read, 1);
571
-
602
+
572
603
  set_default_proto_function_pointers();
604
+ mt = default_mt;
573
605
  }
574
606
 
data/ext/struct.h CHANGED
@@ -1,3 +1,22 @@
1
+ /*
2
+ * Licensed to the Apache Software Foundation (ASF) under one
3
+ * or more contributor license agreements. See the NOTICE file
4
+ * distributed with this work for additional information
5
+ * regarding copyright ownership. The ASF licenses this file
6
+ * to you under the Apache License, Version 2.0 (the
7
+ * "License"); you may not use this file except in compliance
8
+ * with the License. You may obtain a copy of the License at
9
+ *
10
+ * http://www.apache.org/licenses/LICENSE-2.0
11
+ *
12
+ * Unless required by applicable law or agreed to in writing,
13
+ * software distributed under the License is distributed on an
14
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15
+ * KIND, either express or implied. See the License for the
16
+ * specific language governing permissions and limitations
17
+ * under the License.
18
+ */
19
+
1
20
  #include <stdbool.h>
2
21
  #include <ruby.h>
3
22
 
data/ext/thrift_native.c CHANGED
@@ -1,6 +1,26 @@
1
+ /**
2
+ * Licensed to the Apache Software Foundation (ASF) under one
3
+ * or more contributor license agreements. See the NOTICE file
4
+ * distributed with this work for additional information
5
+ * regarding copyright ownership. The ASF licenses this file
6
+ * to you under the Apache License, Version 2.0 (the
7
+ * "License"); you may not use this file except in compliance
8
+ * with the License. You may obtain a copy of the License at
9
+ *
10
+ * http://www.apache.org/licenses/LICENSE-2.0
11
+ *
12
+ * Unless required by applicable law or agreed to in writing,
13
+ * software distributed under the License is distributed on an
14
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15
+ * KIND, either express or implied. See the License for the
16
+ * specific language governing permissions and limitations
17
+ * under the License.
18
+ */
19
+
1
20
  #include <ruby.h>
2
21
  #include <struct.h>
3
22
  #include <binary_protocol_accelerated.h>
23
+ #include <compact_protocol.h>
4
24
  #include <protocol.h>
5
25
  #include <memory_buffer.h>
6
26
 
@@ -67,7 +87,7 @@ ID sort_method_id;
67
87
  ID write_field_stop_method_id;
68
88
  ID skip_method_id;
69
89
  ID write_method_id;
70
- ID read_method_id;
90
+ ID read_all_method_id;
71
91
  ID native_qmark_method_id;
72
92
 
73
93
  // constant ids
@@ -149,7 +169,7 @@ void Init_thrift_native() {
149
169
  write_field_stop_method_id = rb_intern("write_field_stop");
150
170
  skip_method_id = rb_intern("skip");
151
171
  write_method_id = rb_intern("write");
152
- read_method_id = rb_intern("read");
172
+ read_all_method_id = rb_intern("read_all");
153
173
  native_qmark_method_id = rb_intern("native?");
154
174
 
155
175
  // constant ids
@@ -169,5 +189,6 @@ void Init_thrift_native() {
169
189
  Init_protocol();
170
190
  Init_struct();
171
191
  Init_binary_protocol_accelerated();
192
+ Init_compact_protocol();
172
193
  Init_memory_buffer();
173
194
  }