thrift 0.8.0 → 0.13.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (99) hide show
  1. checksums.yaml +7 -0
  2. data/{README → README.md} +0 -0
  3. data/ext/binary_protocol_accelerated.c +33 -14
  4. data/ext/bytes.c +36 -0
  5. data/ext/bytes.h +31 -0
  6. data/ext/compact_protocol.c +27 -8
  7. data/ext/constants.h +8 -5
  8. data/ext/extconf.rb +5 -1
  9. data/ext/memory_buffer.c +12 -9
  10. data/ext/protocol.c +0 -185
  11. data/ext/protocol.h +0 -20
  12. data/ext/strlcpy.h +7 -3
  13. data/ext/struct.c +27 -7
  14. data/ext/thrift_native.c +16 -11
  15. data/lib/thrift.rb +10 -4
  16. data/lib/thrift/bytes.rb +131 -0
  17. data/lib/thrift/client.rb +13 -4
  18. data/lib/thrift/exceptions.rb +3 -0
  19. data/lib/thrift/multiplexed_processor.rb +76 -0
  20. data/lib/thrift/processor.rb +24 -6
  21. data/lib/thrift/protocol/base_protocol.rb +109 -12
  22. data/lib/thrift/protocol/binary_protocol.rb +22 -7
  23. data/lib/thrift/protocol/binary_protocol_accelerated.rb +8 -0
  24. data/lib/thrift/protocol/compact_protocol.rb +23 -6
  25. data/lib/thrift/protocol/json_protocol.rb +786 -0
  26. data/lib/thrift/protocol/multiplexed_protocol.rb +44 -0
  27. data/lib/thrift/protocol/protocol_decorator.rb +194 -0
  28. data/lib/thrift/server/base_server.rb +8 -2
  29. data/lib/thrift/server/mongrel_http_server.rb +2 -0
  30. data/lib/thrift/server/simple_server.rb +5 -1
  31. data/lib/thrift/server/thin_http_server.rb +91 -0
  32. data/lib/thrift/server/thread_pool_server.rb +5 -1
  33. data/lib/thrift/server/threaded_server.rb +5 -1
  34. data/lib/thrift/struct.rb +1 -1
  35. data/lib/thrift/struct_union.rb +2 -2
  36. data/lib/thrift/transport/base_server_transport.rb +1 -1
  37. data/lib/thrift/transport/base_transport.rb +30 -20
  38. data/lib/thrift/transport/buffered_transport.rb +25 -11
  39. data/lib/thrift/transport/framed_transport.rb +20 -11
  40. data/lib/thrift/transport/http_client_transport.rb +16 -6
  41. data/lib/thrift/transport/io_stream_transport.rb +5 -2
  42. data/lib/thrift/transport/memory_buffer_transport.rb +10 -6
  43. data/lib/thrift/transport/server_socket.rb +6 -1
  44. data/lib/thrift/transport/socket.rb +23 -17
  45. data/lib/thrift/transport/ssl_server_socket.rb +41 -0
  46. data/lib/thrift/transport/ssl_socket.rb +51 -0
  47. data/lib/thrift/transport/unix_server_socket.rb +5 -1
  48. data/lib/thrift/transport/unix_socket.rb +5 -1
  49. data/lib/thrift/union.rb +3 -6
  50. data/spec/BaseService.thrift +27 -0
  51. data/spec/ExtendedService.thrift +25 -0
  52. data/spec/Referenced.thrift +44 -0
  53. data/spec/ThriftNamespacedSpec.thrift +53 -0
  54. data/spec/ThriftSpec.thrift +52 -1
  55. data/spec/base_protocol_spec.rb +158 -93
  56. data/spec/base_transport_spec.rb +194 -157
  57. data/spec/binary_protocol_accelerated_spec.rb +14 -14
  58. data/spec/binary_protocol_spec.rb +29 -16
  59. data/spec/binary_protocol_spec_shared.rb +148 -65
  60. data/spec/bytes_spec.rb +160 -0
  61. data/spec/client_spec.rb +45 -47
  62. data/spec/compact_protocol_spec.rb +36 -22
  63. data/spec/exception_spec.rb +79 -80
  64. data/spec/flat_spec.rb +62 -0
  65. data/spec/http_client_spec.rb +91 -16
  66. data/spec/json_protocol_spec.rb +552 -0
  67. data/spec/namespaced_spec.rb +67 -0
  68. data/spec/nonblocking_server_spec.rb +26 -28
  69. data/spec/processor_spec.rb +29 -32
  70. data/spec/serializer_spec.rb +31 -33
  71. data/spec/server_socket_spec.rb +32 -28
  72. data/spec/server_spec.rb +112 -84
  73. data/spec/socket_spec.rb +27 -20
  74. data/spec/socket_spec_shared.rb +32 -32
  75. data/spec/spec_helper.rb +17 -11
  76. data/spec/ssl_server_socket_spec.rb +34 -0
  77. data/spec/ssl_socket_spec.rb +78 -0
  78. data/spec/struct_nested_containers_spec.rb +191 -0
  79. data/spec/struct_spec.rb +159 -161
  80. data/spec/thin_http_server_spec.rb +141 -0
  81. data/spec/types_spec.rb +71 -69
  82. data/spec/union_spec.rb +97 -76
  83. data/spec/unix_socket_spec.rb +49 -41
  84. metadata +268 -188
  85. data/CHANGELOG +0 -1
  86. data/benchmark/gen-rb/benchmark_constants.rb +0 -10
  87. data/benchmark/gen-rb/benchmark_service.rb +0 -80
  88. data/benchmark/gen-rb/benchmark_types.rb +0 -9
  89. data/spec/gen-rb/nonblocking_service.rb +0 -272
  90. data/spec/gen-rb/thrift_spec_constants.rb +0 -10
  91. data/spec/gen-rb/thrift_spec_types.rb +0 -345
  92. data/spec/mongrel_http_server_spec.rb +0 -117
  93. data/test/debug_proto/gen-rb/debug_proto_test_constants.rb +0 -273
  94. data/test/debug_proto/gen-rb/debug_proto_test_types.rb +0 -760
  95. data/test/debug_proto/gen-rb/empty_service.rb +0 -24
  96. data/test/debug_proto/gen-rb/inherited.rb +0 -79
  97. data/test/debug_proto/gen-rb/reverse_order_service.rb +0 -82
  98. data/test/debug_proto/gen-rb/service_for_exception_with_a_map.rb +0 -81
  99. data/test/debug_proto/gen-rb/srv.rb +0 -330
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 6c894aeced9c6d4f7f4e66441472dbe37603b45722cffe89007e6faa1d2771c8
4
+ data.tar.gz: 3417f5e29c4459b18933e1a6c2eb6575ce0b8c6c073bac4836043742854a8c01
5
+ SHA512:
6
+ metadata.gz: 4daf374c7752cfd11fb60fa7f1a5323f026bacbff118987f7e4342bfc79e9da8cc80e2872ddf571e2b705a310fe7921bc0c011215ec5f222cee252e0ec9a513f
7
+ data.tar.gz: 4712fd01cd41fde2877df76808af17ce303656c3a003dcda92c876766aba508cdaf802511e3698ce5f4476064a435057e47493f05a2e4f928c67e16ec7554562
File without changes
@@ -22,7 +22,8 @@
22
22
  #include <stdint.h>
23
23
  #include <constants.h>
24
24
  #include <struct.h>
25
- #include "macros.h"
25
+ #include <macros.h>
26
+ #include <bytes.h>
26
27
 
27
28
  VALUE rb_thrift_binary_proto_native_qmark(VALUE self) {
28
29
  return Qtrue;
@@ -78,8 +79,9 @@ static void write_i64_direct(VALUE trans, int64_t value) {
78
79
 
79
80
  static void write_string_direct(VALUE trans, VALUE str) {
80
81
  if (TYPE(str) != T_STRING) {
81
- rb_raise(rb_eStandardError, "Value should be a string");
82
+ rb_raise(rb_eStandardError, "Value should be a string");
82
83
  }
84
+ str = convert_to_utf8_byte_buffer(str);
83
85
  write_i32_direct(trans, RSTRING_LEN(str));
84
86
  rb_funcall(trans, write_method_id, 1, str);
85
87
  }
@@ -217,11 +219,21 @@ VALUE rb_thrift_binary_proto_write_string(VALUE self, VALUE str) {
217
219
  return Qnil;
218
220
  }
219
221
 
222
+ VALUE rb_thrift_binary_proto_write_binary(VALUE self, VALUE buf) {
223
+ CHECK_NIL(buf);
224
+ VALUE trans = GET_TRANSPORT(self);
225
+ buf = force_binary_encoding(buf);
226
+ write_i32_direct(trans, RSTRING_LEN(buf));
227
+ rb_funcall(trans, write_method_id, 1, buf);
228
+ return Qnil;
229
+ }
230
+
220
231
  //---------------------------------------
221
232
  // interface reading methods
222
233
  //---------------------------------------
223
234
 
224
235
  VALUE rb_thrift_binary_proto_read_string(VALUE self);
236
+ VALUE rb_thrift_binary_proto_read_binary(VALUE self);
225
237
  VALUE rb_thrift_binary_proto_read_byte(VALUE self);
226
238
  VALUE rb_thrift_binary_proto_read_i32(VALUE self);
227
239
  VALUE rb_thrift_binary_proto_read_i16(VALUE self);
@@ -271,27 +283,27 @@ VALUE rb_thrift_binary_proto_read_message_end(VALUE self) {
271
283
  return Qnil;
272
284
  }
273
285
 
274
- VALUE rb_thift_binary_proto_read_struct_begin(VALUE self) {
286
+ VALUE rb_thrift_binary_proto_read_struct_begin(VALUE self) {
275
287
  return Qnil;
276
288
  }
277
289
 
278
- VALUE rb_thift_binary_proto_read_struct_end(VALUE self) {
290
+ VALUE rb_thrift_binary_proto_read_struct_end(VALUE self) {
279
291
  return Qnil;
280
292
  }
281
293
 
282
- VALUE rb_thift_binary_proto_read_field_end(VALUE self) {
294
+ VALUE rb_thrift_binary_proto_read_field_end(VALUE self) {
283
295
  return Qnil;
284
296
  }
285
297
 
286
- VALUE rb_thift_binary_proto_read_map_end(VALUE self) {
298
+ VALUE rb_thrift_binary_proto_read_map_end(VALUE self) {
287
299
  return Qnil;
288
300
  }
289
301
 
290
- VALUE rb_thift_binary_proto_read_list_end(VALUE self) {
302
+ VALUE rb_thrift_binary_proto_read_list_end(VALUE self) {
291
303
  return Qnil;
292
304
  }
293
305
 
294
- VALUE rb_thift_binary_proto_read_set_end(VALUE self) {
306
+ VALUE rb_thrift_binary_proto_read_set_end(VALUE self) {
295
307
  return Qnil;
296
308
  }
297
309
 
@@ -379,6 +391,11 @@ VALUE rb_thrift_binary_proto_read_double(VALUE self) {
379
391
  }
380
392
 
381
393
  VALUE rb_thrift_binary_proto_read_string(VALUE self) {
394
+ VALUE buffer = rb_thrift_binary_proto_read_binary(self);
395
+ return convert_to_string(buffer);
396
+ }
397
+
398
+ VALUE rb_thrift_binary_proto_read_binary(VALUE self) {
382
399
  int size = read_i32_direct(self);
383
400
  return READ(self, size);
384
401
  }
@@ -407,6 +424,7 @@ void Init_binary_protocol_accelerated() {
407
424
  rb_define_method(bpa_class, "write_i64", rb_thrift_binary_proto_write_i64, 1);
408
425
  rb_define_method(bpa_class, "write_double", rb_thrift_binary_proto_write_double, 1);
409
426
  rb_define_method(bpa_class, "write_string", rb_thrift_binary_proto_write_string, 1);
427
+ rb_define_method(bpa_class, "write_binary", rb_thrift_binary_proto_write_binary, 1);
410
428
  // unused methods
411
429
  rb_define_method(bpa_class, "write_message_end", rb_thrift_binary_proto_write_message_end, 0);
412
430
  rb_define_method(bpa_class, "write_struct_begin", rb_thrift_binary_proto_write_struct_begin, 1);
@@ -428,14 +446,15 @@ void Init_binary_protocol_accelerated() {
428
446
  rb_define_method(bpa_class, "read_i64", rb_thrift_binary_proto_read_i64, 0);
429
447
  rb_define_method(bpa_class, "read_double", rb_thrift_binary_proto_read_double, 0);
430
448
  rb_define_method(bpa_class, "read_string", rb_thrift_binary_proto_read_string, 0);
449
+ rb_define_method(bpa_class, "read_binary", rb_thrift_binary_proto_read_binary, 0);
431
450
  // unused methods
432
451
  rb_define_method(bpa_class, "read_message_end", rb_thrift_binary_proto_read_message_end, 0);
433
- rb_define_method(bpa_class, "read_struct_begin", rb_thift_binary_proto_read_struct_begin, 0);
434
- rb_define_method(bpa_class, "read_struct_end", rb_thift_binary_proto_read_struct_end, 0);
435
- rb_define_method(bpa_class, "read_field_end", rb_thift_binary_proto_read_field_end, 0);
436
- rb_define_method(bpa_class, "read_map_end", rb_thift_binary_proto_read_map_end, 0);
437
- rb_define_method(bpa_class, "read_list_end", rb_thift_binary_proto_read_list_end, 0);
438
- rb_define_method(bpa_class, "read_set_end", rb_thift_binary_proto_read_set_end, 0);
452
+ rb_define_method(bpa_class, "read_struct_begin", rb_thrift_binary_proto_read_struct_begin, 0);
453
+ rb_define_method(bpa_class, "read_struct_end", rb_thrift_binary_proto_read_struct_end, 0);
454
+ rb_define_method(bpa_class, "read_field_end", rb_thrift_binary_proto_read_field_end, 0);
455
+ rb_define_method(bpa_class, "read_map_end", rb_thrift_binary_proto_read_map_end, 0);
456
+ rb_define_method(bpa_class, "read_list_end", rb_thrift_binary_proto_read_list_end, 0);
457
+ rb_define_method(bpa_class, "read_set_end", rb_thrift_binary_proto_read_set_end, 0);
439
458
 
440
459
  rbuf_ivar_id = rb_intern("@rbuf");
441
460
  }
@@ -0,0 +1,36 @@
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
+ #include <ruby.h>
21
+ #ifdef HAVE_RUBY_ENCODING_H
22
+ #include <ruby/encoding.h>
23
+ #endif
24
+ #include <constants.h>
25
+
26
+ VALUE force_binary_encoding(VALUE buffer) {
27
+ return rb_funcall(thrift_bytes_module, force_binary_encoding_id, 1, buffer);
28
+ }
29
+
30
+ VALUE convert_to_utf8_byte_buffer(VALUE string) {
31
+ return rb_funcall(thrift_bytes_module, convert_to_utf8_byte_buffer_id, 1, string);
32
+ }
33
+
34
+ VALUE convert_to_string(VALUE utf8_buffer) {
35
+ return rb_funcall(thrift_bytes_module, convert_to_string_id, 1, utf8_buffer);
36
+ }
@@ -0,0 +1,31 @@
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
+ #include <ruby.h>
21
+
22
+ /*
23
+ * A collection of utilities for working with bytes and byte buffers.
24
+ *
25
+ * These methods are the native analogies to some of the methods in
26
+ * Thrift::Bytes (thrift/bytes.rb).
27
+ */
28
+
29
+ VALUE force_binary_encoding(VALUE buffer);
30
+ VALUE convert_to_utf8_byte_buffer(VALUE string);
31
+ VALUE convert_to_string(VALUE utf8_buffer);
@@ -20,9 +20,10 @@
20
20
  #include <ruby.h>
21
21
  #include <stdbool.h>
22
22
  #include <stdint.h>
23
- #include "constants.h"
24
- #include "struct.h"
25
- #include "macros.h"
23
+ #include <constants.h>
24
+ #include <struct.h>
25
+ #include <macros.h>
26
+ #include <bytes.h>
26
27
 
27
28
  #define LAST_ID(obj) FIX2INT(rb_ary_pop(rb_ivar_get(obj, last_field_id)))
28
29
  #define SET_LAST_ID(obj, val) rb_ary_push(rb_ivar_get(obj, last_field_id), val)
@@ -39,6 +40,7 @@ static ID rbuf_ivar_id;
39
40
  static int VERSION;
40
41
  static int VERSION_MASK;
41
42
  static int TYPE_MASK;
43
+ static int TYPE_BITS;
42
44
  static int TYPE_SHIFT_AMOUNT;
43
45
  static int PROTOCOL_ID;
44
46
 
@@ -166,6 +168,7 @@ static void write_collection_begin(VALUE transport, VALUE elem_type, VALUE size_
166
168
 
167
169
  VALUE rb_thrift_compact_proto_write_i32(VALUE self, VALUE i32);
168
170
  VALUE rb_thrift_compact_proto_write_string(VALUE self, VALUE str);
171
+ VALUE rb_thrift_compact_proto_write_binary(VALUE self, VALUE buf);
169
172
 
170
173
  VALUE rb_thrift_compact_proto_write_message_end(VALUE self) {
171
174
  return Qnil;
@@ -304,9 +307,16 @@ VALUE rb_thrift_compact_proto_write_double(VALUE self, VALUE dub) {
304
307
  }
305
308
 
306
309
  VALUE rb_thrift_compact_proto_write_string(VALUE self, VALUE str) {
310
+ str = convert_to_utf8_byte_buffer(str);
311
+ rb_thrift_compact_proto_write_binary(self, str);
312
+ return Qnil;
313
+ }
314
+
315
+ VALUE rb_thrift_compact_proto_write_binary(VALUE self, VALUE buf) {
316
+ buf = force_binary_encoding(buf);
307
317
  VALUE transport = GET_TRANSPORT(self);
308
- write_varint32(transport, RSTRING_LEN(str));
309
- WRITE(transport, RSTRING_PTR(str), RSTRING_LEN(str));
318
+ write_varint32(transport, RSTRING_LEN(buf));
319
+ WRITE(transport, StringValuePtr(buf), RSTRING_LEN(buf));
310
320
  return Qnil;
311
321
  }
312
322
 
@@ -317,6 +327,7 @@ VALUE rb_thrift_compact_proto_write_string(VALUE self, VALUE str) {
317
327
  #define is_bool_type(ctype) (((ctype) & 0x0F) == CTYPE_BOOLEAN_TRUE || ((ctype) & 0x0F) == CTYPE_BOOLEAN_FALSE)
318
328
 
319
329
  VALUE rb_thrift_compact_proto_read_string(VALUE self);
330
+ VALUE rb_thrift_compact_proto_read_binary(VALUE self);
320
331
  VALUE rb_thrift_compact_proto_read_byte(VALUE self);
321
332
  VALUE rb_thrift_compact_proto_read_i32(VALUE self);
322
333
  VALUE rb_thrift_compact_proto_read_i16(VALUE self);
@@ -440,7 +451,7 @@ VALUE rb_thrift_compact_proto_read_message_begin(VALUE self) {
440
451
  rb_exc_raise(get_protocol_exception(INT2FIX(-1), rb_str_new2(buf)));
441
452
  }
442
453
 
443
- int8_t type = (version_and_type >> TYPE_SHIFT_AMOUNT) & 0x03;
454
+ int8_t type = (version_and_type >> TYPE_SHIFT_AMOUNT) & TYPE_BITS;
444
455
  int32_t seqid = read_varint64(self);
445
456
  VALUE messageName = rb_thrift_compact_proto_read_string(self);
446
457
  return rb_ary_new3(3, messageName, INT2FIX(type), INT2NUM(seqid));
@@ -545,19 +556,25 @@ VALUE rb_thrift_compact_proto_read_double(VALUE self) {
545
556
  }
546
557
 
547
558
  VALUE rb_thrift_compact_proto_read_string(VALUE self) {
559
+ VALUE buffer = rb_thrift_compact_proto_read_binary(self);
560
+ return convert_to_string(buffer);
561
+ }
562
+
563
+ VALUE rb_thrift_compact_proto_read_binary(VALUE self) {
548
564
  int64_t size = read_varint64(self);
549
565
  return READ(self, size);
550
566
  }
551
567
 
552
568
  static void Init_constants() {
553
569
  thrift_compact_protocol_class = rb_const_get(thrift_module, rb_intern("CompactProtocol"));
554
-
570
+
555
571
  VERSION = rb_num2ll(rb_const_get(thrift_compact_protocol_class, rb_intern("VERSION")));
556
572
  VERSION_MASK = rb_num2ll(rb_const_get(thrift_compact_protocol_class, rb_intern("VERSION_MASK")));
557
573
  TYPE_MASK = rb_num2ll(rb_const_get(thrift_compact_protocol_class, rb_intern("TYPE_MASK")));
574
+ TYPE_BITS = rb_num2ll(rb_const_get(thrift_compact_protocol_class, rb_intern("TYPE_BITS")));
558
575
  TYPE_SHIFT_AMOUNT = FIX2INT(rb_const_get(thrift_compact_protocol_class, rb_intern("TYPE_SHIFT_AMOUNT")));
559
576
  PROTOCOL_ID = FIX2INT(rb_const_get(thrift_compact_protocol_class, rb_intern("PROTOCOL_ID")));
560
-
577
+
561
578
  last_field_id = rb_intern("@last_field");
562
579
  boolean_field_id = rb_intern("@boolean_field");
563
580
  bool_value_id = rb_intern("@bool_value");
@@ -580,6 +597,7 @@ static void Init_rb_methods() {
580
597
  rb_define_method(thrift_compact_protocol_class, "write_i64", rb_thrift_compact_proto_write_i64, 1);
581
598
  rb_define_method(thrift_compact_protocol_class, "write_double", rb_thrift_compact_proto_write_double, 1);
582
599
  rb_define_method(thrift_compact_protocol_class, "write_string", rb_thrift_compact_proto_write_string, 1);
600
+ rb_define_method(thrift_compact_protocol_class, "write_binary", rb_thrift_compact_proto_write_binary, 1);
583
601
 
584
602
  rb_define_method(thrift_compact_protocol_class, "write_message_end", rb_thrift_compact_proto_write_message_end, 0);
585
603
  rb_define_method(thrift_compact_protocol_class, "write_struct_begin", rb_thrift_compact_proto_write_struct_begin, 1);
@@ -602,6 +620,7 @@ static void Init_rb_methods() {
602
620
  rb_define_method(thrift_compact_protocol_class, "read_i64", rb_thrift_compact_proto_read_i64, 0);
603
621
  rb_define_method(thrift_compact_protocol_class, "read_double", rb_thrift_compact_proto_read_double, 0);
604
622
  rb_define_method(thrift_compact_protocol_class, "read_string", rb_thrift_compact_proto_read_string, 0);
623
+ rb_define_method(thrift_compact_protocol_class, "read_binary", rb_thrift_compact_proto_read_binary, 0);
605
624
 
606
625
  rb_define_method(thrift_compact_protocol_class, "read_message_end", rb_thrift_compact_proto_read_message_end, 0);
607
626
  rb_define_method(thrift_compact_protocol_class, "read_struct_begin", rb_thrift_compact_proto_read_struct_begin, 0);
@@ -42,19 +42,20 @@ extern ID write_i32_method_id;
42
42
  extern ID write_i64_method_id;
43
43
  extern ID write_double_method_id;
44
44
  extern ID write_string_method_id;
45
+ extern ID write_binary_method_id;
45
46
  extern ID write_map_begin_method_id;
46
47
  extern ID write_map_end_method_id;
47
48
  extern ID write_list_begin_method_id;
48
49
  extern ID write_list_end_method_id;
49
50
  extern ID write_set_begin_method_id;
50
51
  extern ID write_set_end_method_id;
51
- extern ID size_method_id;
52
52
  extern ID read_bool_method_id;
53
53
  extern ID read_byte_method_id;
54
54
  extern ID read_i16_method_id;
55
55
  extern ID read_i32_method_id;
56
56
  extern ID read_i64_method_id;
57
57
  extern ID read_string_method_id;
58
+ extern ID read_binary_method_id;
58
59
  extern ID read_double_method_id;
59
60
  extern ID read_map_begin_method_id;
60
61
  extern ID read_map_end_method_id;
@@ -67,15 +68,15 @@ extern ID read_struct_end_method_id;
67
68
  extern ID read_field_begin_method_id;
68
69
  extern ID read_field_end_method_id;
69
70
  extern ID keys_method_id;
70
- extern ID entries_method_id;
71
- extern ID name_method_id;
72
- extern ID sort_method_id;
71
+ extern ID entries_method_id;
73
72
  extern ID write_field_stop_method_id;
74
73
  extern ID skip_method_id;
75
74
  extern ID write_method_id;
76
75
  extern ID read_all_method_id;
77
76
  extern ID read_into_buffer_method_id;
78
- extern ID native_qmark_method_id;
77
+ extern ID force_binary_encoding_id;
78
+ extern ID convert_to_utf8_byte_buffer_id;
79
+ extern ID convert_to_string_id;
79
80
 
80
81
  extern ID fields_const_id;
81
82
  extern ID transport_ivar_id;
@@ -88,9 +89,11 @@ extern VALUE key_sym;
88
89
  extern VALUE value_sym;
89
90
  extern VALUE element_sym;
90
91
  extern VALUE class_sym;
92
+ extern VALUE binary_sym;
91
93
 
92
94
  extern VALUE rb_cSet;
93
95
  extern VALUE thrift_module;
94
96
  extern VALUE thrift_types_module;
97
+ extern VALUE thrift_bytes_module;
95
98
  extern VALUE class_thrift_protocol;
96
99
  extern VALUE protocol_exception_class;
@@ -21,8 +21,12 @@ if defined?(RUBY_ENGINE) && RUBY_ENGINE =~ /jruby/
21
21
  File.open('Makefile', 'w'){|f| f.puts "all:\n\ninstall:\n" }
22
22
  else
23
23
  require 'mkmf'
24
+ require 'rbconfig'
24
25
 
25
- $CFLAGS = "-g -O2 -Wall -Werror"
26
+ $ARCH_FLAGS = RbConfig::CONFIG['CFLAGS'].scan( /(-arch )(\S+)/ ).map{|x,y| x + y + ' ' }.join('')
27
+
28
+
29
+ $CFLAGS = "-fsigned-char -g -O2 -Wall -Werror " + $ARCH_FLAGS
26
30
 
27
31
  have_func("strlcpy", "string.h")
28
32
 
@@ -19,7 +19,8 @@
19
19
 
20
20
  #include <ruby.h>
21
21
  #include <constants.h>
22
- #include "macros.h"
22
+ #include <bytes.h>
23
+ #include <macros.h>
23
24
 
24
25
  ID buf_ivar_id;
25
26
  ID index_ivar_id;
@@ -37,7 +38,8 @@ VALUE rb_thrift_memory_buffer_read_into_buffer(VALUE self, VALUE buffer_value, V
37
38
 
38
39
  VALUE rb_thrift_memory_buffer_write(VALUE self, VALUE str) {
39
40
  VALUE buf = GET_BUF(self);
40
- rb_str_buf_cat(buf, RSTRING_PTR(str), RSTRING_LEN(str));
41
+ str = force_binary_encoding(str);
42
+ rb_str_buf_cat(buf, StringValuePtr(str), RSTRING_LEN(str));
41
43
  return Qnil;
42
44
  }
43
45
 
@@ -93,25 +95,26 @@ VALUE rb_thrift_memory_buffer_read_into_buffer(VALUE self, VALUE buffer_value, V
93
95
  int index;
94
96
  VALUE buf = GET_BUF(self);
95
97
 
98
+ index = FIX2INT(rb_ivar_get(self, index_ivar_id));
96
99
  while (i < size) {
97
- index = FIX2INT(rb_ivar_get(self, index_ivar_id));
98
100
  if (index >= RSTRING_LEN(buf)) {
99
101
  rb_raise(rb_eEOFError, "Not enough bytes remain in memory buffer");
100
102
  }
101
103
  char byte = RSTRING_PTR(buf)[index++];
102
104
 
103
- if (index >= GARBAGE_BUFFER_SIZE) {
104
- rb_ivar_set(self, buf_ivar_id, rb_funcall(buf, slice_method_id, 2, INT2FIX(index), INT2FIX(RSTRING_LEN(buf) - 1)));
105
- index = 0;
106
- }
107
- rb_ivar_set(self, index_ivar_id, INT2FIX(index));
108
-
109
105
  if (i >= RSTRING_LEN(buffer_value)) {
110
106
  rb_raise(rb_eIndexError, "index %d out of string", i);
111
107
  }
112
108
  ((char*)RSTRING_PTR(buffer_value))[i] = byte;
113
109
  i++;
114
110
  }
111
+
112
+ if (index >= GARBAGE_BUFFER_SIZE) {
113
+ rb_ivar_set(self, buf_ivar_id, rb_funcall(buf, slice_method_id, 2, INT2FIX(index), INT2FIX(RSTRING_LEN(buf) - 1)));
114
+ index = 0;
115
+ }
116
+ rb_ivar_set(self, index_ivar_id, INT2FIX(index));
117
+
115
118
  return INT2FIX(i);
116
119
  }
117
120
 
@@ -1,185 +0,0 @@
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
- #include <ruby.h>
21
- #include <protocol.h>
22
- #include <stdbool.h>
23
- #include <constants.h>
24
- #include <struct.h>
25
-
26
- static VALUE skip(VALUE self, int ttype) {
27
- if (ttype == TTYPE_STOP) {
28
- return Qnil;
29
- } else if (ttype == TTYPE_BOOL) {
30
- rb_funcall(self, read_bool_method_id, 0);
31
- } else if (ttype == TTYPE_BYTE) {
32
- rb_funcall(self, read_byte_method_id, 0);
33
- } else if (ttype == TTYPE_I16) {
34
- rb_funcall(self, read_i16_method_id, 0);
35
- } else if (ttype == TTYPE_I32) {
36
- rb_funcall(self, read_i32_method_id, 0);
37
- } else if (ttype == TTYPE_I64) {
38
- rb_funcall(self, read_i64_method_id, 0);
39
- } else if (ttype == TTYPE_DOUBLE) {
40
- rb_funcall(self, read_double_method_id, 0);
41
- } else if (ttype == TTYPE_STRING) {
42
- rb_funcall(self, read_string_method_id, 0);
43
- } else if (ttype == TTYPE_STRUCT) {
44
- rb_funcall(self, read_struct_begin_method_id, 0);
45
- while (true) {
46
- VALUE field_header = rb_funcall(self, read_field_begin_method_id, 0);
47
- if (NIL_P(field_header) || FIX2INT(rb_ary_entry(field_header, 1)) == TTYPE_STOP ) {
48
- break;
49
- }
50
- skip(self, FIX2INT(rb_ary_entry(field_header, 1)));
51
- rb_funcall(self, read_field_end_method_id, 0);
52
- }
53
- rb_funcall(self, read_struct_end_method_id, 0);
54
- } else if (ttype == TTYPE_MAP) {
55
- int i;
56
- VALUE map_header = rb_funcall(self, read_map_begin_method_id, 0);
57
- int ktype = FIX2INT(rb_ary_entry(map_header, 0));
58
- int vtype = FIX2INT(rb_ary_entry(map_header, 1));
59
- int size = FIX2INT(rb_ary_entry(map_header, 2));
60
-
61
- for (i = 0; i < size; i++) {
62
- skip(self, ktype);
63
- skip(self, vtype);
64
- }
65
- rb_funcall(self, read_map_end_method_id, 0);
66
- } else if (ttype == TTYPE_LIST || ttype == TTYPE_SET) {
67
- int i;
68
- VALUE collection_header = rb_funcall(self, ttype == TTYPE_LIST ? read_list_begin_method_id : read_set_begin_method_id, 0);
69
- int etype = FIX2INT(rb_ary_entry(collection_header, 0));
70
- int size = FIX2INT(rb_ary_entry(collection_header, 1));
71
- for (i = 0; i < size; i++) {
72
- skip(self, etype);
73
- }
74
- rb_funcall(self, ttype == TTYPE_LIST ? read_list_end_method_id : read_set_end_method_id, 0);
75
- } else {
76
- rb_raise(rb_eNotImpError, "don't know how to skip type %d", ttype);
77
- }
78
-
79
- return Qnil;
80
- }
81
-
82
- VALUE rb_thrift_protocol_native_qmark(VALUE self) {
83
- return Qfalse;
84
- }
85
-
86
- VALUE rb_thrift_protocol_skip(VALUE protocol, VALUE ttype) {
87
- return skip(protocol, FIX2INT(ttype));
88
- }
89
-
90
- VALUE rb_thrift_write_message_end(VALUE self) {
91
- return Qnil;
92
- }
93
-
94
- VALUE rb_thrift_write_struct_begin(VALUE self, VALUE name) {
95
- return Qnil;
96
- }
97
-
98
- VALUE rb_thrift_write_struct_end(VALUE self) {
99
- return Qnil;
100
- }
101
-
102
- VALUE rb_thrift_write_field_end(VALUE self) {
103
- return Qnil;
104
- }
105
-
106
- VALUE rb_thrift_write_map_end(VALUE self) {
107
- return Qnil;
108
- }
109
-
110
- VALUE rb_thrift_write_list_end(VALUE self) {
111
- return Qnil;
112
- }
113
-
114
- VALUE rb_thrift_write_set_end(VALUE self) {
115
- return Qnil;
116
- }
117
-
118
- VALUE rb_thrift_read_message_end(VALUE self) {
119
- return Qnil;
120
- }
121
-
122
- VALUE rb_thift_read_struct_begin(VALUE self) {
123
- return Qnil;
124
- }
125
-
126
- VALUE rb_thift_read_struct_end(VALUE self) {
127
- return Qnil;
128
- }
129
-
130
- VALUE rb_thift_read_field_end(VALUE self) {
131
- return Qnil;
132
- }
133
-
134
- VALUE rb_thift_read_map_end(VALUE self) {
135
- return Qnil;
136
- }
137
-
138
- VALUE rb_thift_read_list_end(VALUE self) {
139
- return Qnil;
140
- }
141
-
142
- VALUE rb_thift_read_set_end(VALUE self) {
143
- return Qnil;
144
- }
145
-
146
- void Init_protocol() {
147
- VALUE c_protocol = rb_const_get(thrift_module, rb_intern("BaseProtocol"));
148
-
149
- rb_define_method(c_protocol, "skip", rb_thrift_protocol_skip, 1);
150
- rb_define_method(c_protocol, "write_message_end", rb_thrift_write_message_end, 0);
151
- rb_define_method(c_protocol, "write_struct_begin", rb_thrift_write_struct_begin, 1);
152
- rb_define_method(c_protocol, "write_struct_end", rb_thrift_write_struct_end, 0);
153
- rb_define_method(c_protocol, "write_field_end", rb_thrift_write_field_end, 0);
154
- rb_define_method(c_protocol, "write_map_end", rb_thrift_write_map_end, 0);
155
- rb_define_method(c_protocol, "write_list_end", rb_thrift_write_list_end, 0);
156
- rb_define_method(c_protocol, "write_set_end", rb_thrift_write_set_end, 0);
157
- rb_define_method(c_protocol, "read_message_end", rb_thrift_read_message_end, 0);
158
- rb_define_method(c_protocol, "read_struct_begin", rb_thift_read_struct_begin, 0);
159
- rb_define_method(c_protocol, "read_struct_end", rb_thift_read_struct_end, 0);
160
- rb_define_method(c_protocol, "read_field_end", rb_thift_read_field_end, 0);
161
- rb_define_method(c_protocol, "read_map_end", rb_thift_read_map_end, 0);
162
- rb_define_method(c_protocol, "read_list_end", rb_thift_read_list_end, 0);
163
- rb_define_method(c_protocol, "read_set_end", rb_thift_read_set_end, 0);
164
- rb_define_method(c_protocol, "native?", rb_thrift_protocol_native_qmark, 0);
165
-
166
- // native_proto_method_table *npmt;
167
- // npmt = ALLOC(native_proto_method_table);
168
- // npmt->write_message_end = rb_thrift_write_message_end;
169
- // npmt->write_struct_begin = rb_thrift_write_struct_begin;
170
- // npmt->write_struct_end = rb_thrift_write_struct_end;
171
- // npmt->write_field_end = rb_thrift_write_field_end;
172
- // npmt->write_map_end = rb_thrift_write_map_end;
173
- // npmt->write_list_end = rb_thrift_write_list_end;
174
- // npmt->write_set_end = rb_thrift_write_set_end;
175
- // npmt->read_message_end = rb_thrift_read_message_end;
176
- // npmt->read_struct_begin = rb_thift_read_struct_begin;
177
- // npmt->read_struct_end = rb_thift_read_struct_end;
178
- // npmt->read_field_end = rb_thift_read_field_end;
179
- // npmt->read_map_end = rb_thift_read_map_end;
180
- // npmt->read_list_end = rb_thift_read_list_end;
181
- // npmt->read_set_end = rb_thift_read_set_end;
182
- //
183
- // VALUE method_table_object = Data_Wrap_Struct(rb_cObject, 0, free, npmt);
184
- // rb_const_set(c_protocol, rb_intern("@native_method_table"), method_table_object);
185
- }