thrift-mavericks 0.8.0 → 0.9.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (59) hide show
  1. checksums.yaml +8 -8
  2. data/ext/binary_protocol_accelerated.c +21 -2
  3. data/ext/bytes.c +36 -0
  4. data/ext/bytes.h +31 -0
  5. data/ext/compact_protocol.c +24 -7
  6. data/ext/constants.h +5 -5
  7. data/ext/extconf.rb +3 -1
  8. data/ext/memory_buffer.c +11 -8
  9. data/ext/protocol.c +0 -185
  10. data/ext/protocol.h +0 -20
  11. data/ext/struct.c +0 -3
  12. data/ext/thrift_native.c +10 -11
  13. data/lib/thrift.rb +3 -0
  14. data/lib/thrift/bytes.rb +131 -0
  15. data/lib/thrift/exceptions.rb +3 -0
  16. data/lib/thrift/protocol/base_protocol.rb +96 -9
  17. data/lib/thrift/protocol/binary_protocol.rb +15 -7
  18. data/lib/thrift/protocol/compact_protocol.rb +14 -6
  19. data/lib/thrift/protocol/json_protocol.rb +766 -0
  20. data/lib/thrift/server/mongrel_http_server.rb +2 -0
  21. data/lib/thrift/server/thin_http_server.rb +91 -0
  22. data/lib/thrift/struct.rb +1 -1
  23. data/lib/thrift/struct_union.rb +2 -2
  24. data/lib/thrift/transport/base_transport.rb +22 -20
  25. data/lib/thrift/transport/buffered_transport.rb +16 -10
  26. data/lib/thrift/transport/framed_transport.rb +11 -10
  27. data/lib/thrift/transport/http_client_transport.rb +11 -6
  28. data/lib/thrift/transport/io_stream_transport.rb +1 -1
  29. data/lib/thrift/transport/memory_buffer_transport.rb +6 -6
  30. data/lib/thrift/transport/socket.rb +4 -2
  31. data/spec/ThriftSpec.thrift +52 -1
  32. data/spec/base_protocol_spec.rb +108 -51
  33. data/spec/base_transport_spec.rb +49 -50
  34. data/spec/binary_protocol_accelerated_spec.rb +9 -13
  35. data/spec/binary_protocol_spec.rb +15 -10
  36. data/spec/binary_protocol_spec_shared.rb +92 -12
  37. data/spec/bytes_spec.rb +160 -0
  38. data/spec/client_spec.rb +13 -14
  39. data/spec/compact_protocol_spec.rb +4 -5
  40. data/spec/exception_spec.rb +39 -40
  41. data/spec/gen-rb/thrift_spec_types.rb +192 -0
  42. data/spec/http_client_spec.rb +65 -9
  43. data/spec/json_protocol_spec.rb +513 -0
  44. data/spec/nonblocking_server_spec.rb +18 -20
  45. data/spec/processor_spec.rb +13 -16
  46. data/spec/serializer_spec.rb +17 -19
  47. data/spec/server_socket_spec.rb +6 -7
  48. data/spec/server_spec.rb +46 -58
  49. data/spec/socket_spec.rb +11 -11
  50. data/spec/socket_spec_shared.rb +1 -1
  51. data/spec/spec_helper.rb +13 -10
  52. data/spec/struct_nested_containers_spec.rb +191 -0
  53. data/spec/struct_spec.rb +84 -86
  54. data/spec/thin_http_server_spec.rb +140 -0
  55. data/spec/types_spec.rb +65 -66
  56. data/spec/union_spec.rb +57 -47
  57. data/spec/unix_socket_spec.rb +8 -9
  58. metadata +72 -14
  59. data/spec/mongrel_http_server_spec.rb +0 -117
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- MTM1MzYyOTc4ODA4Nzc2ZWE3MTgzNTFjMGRmYTIwOWMxZWQ3NTcyMw==
4
+ MWE0NzljMmJhMDg3OTliOTA4YTlmMGNiN2I3OGRhMTNlNTFiMGE3Mg==
5
5
  data.tar.gz: !binary |-
6
- NTU3OGFmNzJkNGU3N2Q4OTQ2NTk4MmUzMmIyNmRjOGI5OTk1MWQxZg==
6
+ ZDM5YjY1YmU5ZTA2OWM0ODE4ZmRhYTJlODIwMjE2MjRhYTYyYWFjMQ==
7
7
  !binary "U0hBNTEy":
8
8
  metadata.gz: !binary |-
9
- Zjg4ZWY2ZDNjOGI2MjkyMzAyYWJmNjU5OWYzMzAxM2NlMzAyNzQ0YjUxZTQx
10
- ZGI5ZmIyYWQyNDdhNzViMzc0NGQ3YmZmODhjMmFjODMwNmVlM2E3ZmZmM2Rm
11
- NTU2YzIxOGVkNGEwNzQ2MTIwZjc3Nzc5MjhlY2Y2MjBiZmFmNzc=
9
+ MzcyNDdjMmFiY2Y2ZTYzMzJjZjc3NmI5NDQ5MDYwN2ZhYTQzY2ZhNDk4Yzc1
10
+ NjhhZWJjMDM2MDkyNTk1Y2MzNjcyNjY0MTAyZDI1MDcxZWYwZTYxMmVkMGI2
11
+ MGVmMGU4MWIyMTMzMTFjNTc2MzRlNTk4MmNiNWZkNjAwODNjZmI=
12
12
  data.tar.gz: !binary |-
13
- Y2ZhYmRmNGVjYzAwNjQyMjMzNDU0YzYxNDRmNzhiMmQzYWQyYzk1N2RmMGNk
14
- YzI5ZmY0NGUyOWQxNDQ0ODNlY2Y4ZDBmNWJiOGU5Zjc5Y2RjZjQyODFlYjg3
15
- NGQyMDRjNGFmZGNmMzBjYmIxMzdjMzRlMzdlYzY1NmNlZTY1NjA=
13
+ ZGE1MjIzNjE3MmFiZGZhMGYxYzAyNzA0NDgwYThjNGQ0YWNiOWMyYTFkNGQx
14
+ NWFhYTE0ZmI0ZGRjMzIzOGRjMzRkNTQzOWYyOWY1YzM1NzZjYWVhMGIxOTI2
15
+ OWUxMDE4MmYxZmE0Y2YzNmIxNzkzNmU2ZTAxNTI3NjNlODc4NDM=
@@ -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);
@@ -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,6 +446,7 @@ 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
452
  rb_define_method(bpa_class, "read_struct_begin", rb_thift_binary_proto_read_struct_begin, 0);
data/ext/bytes.c ADDED
@@ -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
+ }
data/ext/bytes.h ADDED
@@ -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)
@@ -166,6 +167,7 @@ static void write_collection_begin(VALUE transport, VALUE elem_type, VALUE size_
166
167
 
167
168
  VALUE rb_thrift_compact_proto_write_i32(VALUE self, VALUE i32);
168
169
  VALUE rb_thrift_compact_proto_write_string(VALUE self, VALUE str);
170
+ VALUE rb_thrift_compact_proto_write_binary(VALUE self, VALUE buf);
169
171
 
170
172
  VALUE rb_thrift_compact_proto_write_message_end(VALUE self) {
171
173
  return Qnil;
@@ -304,9 +306,16 @@ VALUE rb_thrift_compact_proto_write_double(VALUE self, VALUE dub) {
304
306
  }
305
307
 
306
308
  VALUE rb_thrift_compact_proto_write_string(VALUE self, VALUE str) {
309
+ str = convert_to_utf8_byte_buffer(str);
310
+ rb_thrift_compact_proto_write_binary(self, str);
311
+ return Qnil;
312
+ }
313
+
314
+ VALUE rb_thrift_compact_proto_write_binary(VALUE self, VALUE buf) {
315
+ buf = force_binary_encoding(buf);
307
316
  VALUE transport = GET_TRANSPORT(self);
308
- write_varint32(transport, RSTRING_LEN(str));
309
- WRITE(transport, RSTRING_PTR(str), RSTRING_LEN(str));
317
+ write_varint32(transport, RSTRING_LEN(buf));
318
+ WRITE(transport, RSTRING_PTR(buf), RSTRING_LEN(buf));
310
319
  return Qnil;
311
320
  }
312
321
 
@@ -317,6 +326,7 @@ VALUE rb_thrift_compact_proto_write_string(VALUE self, VALUE str) {
317
326
  #define is_bool_type(ctype) (((ctype) & 0x0F) == CTYPE_BOOLEAN_TRUE || ((ctype) & 0x0F) == CTYPE_BOOLEAN_FALSE)
318
327
 
319
328
  VALUE rb_thrift_compact_proto_read_string(VALUE self);
329
+ VALUE rb_thrift_compact_proto_read_binary(VALUE self);
320
330
  VALUE rb_thrift_compact_proto_read_byte(VALUE self);
321
331
  VALUE rb_thrift_compact_proto_read_i32(VALUE self);
322
332
  VALUE rb_thrift_compact_proto_read_i16(VALUE self);
@@ -545,19 +555,24 @@ VALUE rb_thrift_compact_proto_read_double(VALUE self) {
545
555
  }
546
556
 
547
557
  VALUE rb_thrift_compact_proto_read_string(VALUE self) {
558
+ VALUE buffer = rb_thrift_compact_proto_read_binary(self);
559
+ return convert_to_string(buffer);
560
+ }
561
+
562
+ VALUE rb_thrift_compact_proto_read_binary(VALUE self) {
548
563
  int64_t size = read_varint64(self);
549
564
  return READ(self, size);
550
565
  }
551
566
 
552
567
  static void Init_constants() {
553
568
  thrift_compact_protocol_class = rb_const_get(thrift_module, rb_intern("CompactProtocol"));
554
-
569
+
555
570
  VERSION = rb_num2ll(rb_const_get(thrift_compact_protocol_class, rb_intern("VERSION")));
556
571
  VERSION_MASK = rb_num2ll(rb_const_get(thrift_compact_protocol_class, rb_intern("VERSION_MASK")));
557
572
  TYPE_MASK = rb_num2ll(rb_const_get(thrift_compact_protocol_class, rb_intern("TYPE_MASK")));
558
573
  TYPE_SHIFT_AMOUNT = FIX2INT(rb_const_get(thrift_compact_protocol_class, rb_intern("TYPE_SHIFT_AMOUNT")));
559
574
  PROTOCOL_ID = FIX2INT(rb_const_get(thrift_compact_protocol_class, rb_intern("PROTOCOL_ID")));
560
-
575
+
561
576
  last_field_id = rb_intern("@last_field");
562
577
  boolean_field_id = rb_intern("@boolean_field");
563
578
  bool_value_id = rb_intern("@bool_value");
@@ -580,6 +595,7 @@ static void Init_rb_methods() {
580
595
  rb_define_method(thrift_compact_protocol_class, "write_i64", rb_thrift_compact_proto_write_i64, 1);
581
596
  rb_define_method(thrift_compact_protocol_class, "write_double", rb_thrift_compact_proto_write_double, 1);
582
597
  rb_define_method(thrift_compact_protocol_class, "write_string", rb_thrift_compact_proto_write_string, 1);
598
+ rb_define_method(thrift_compact_protocol_class, "write_binary", rb_thrift_compact_proto_write_binary, 1);
583
599
 
584
600
  rb_define_method(thrift_compact_protocol_class, "write_message_end", rb_thrift_compact_proto_write_message_end, 0);
585
601
  rb_define_method(thrift_compact_protocol_class, "write_struct_begin", rb_thrift_compact_proto_write_struct_begin, 1);
@@ -602,6 +618,7 @@ static void Init_rb_methods() {
602
618
  rb_define_method(thrift_compact_protocol_class, "read_i64", rb_thrift_compact_proto_read_i64, 0);
603
619
  rb_define_method(thrift_compact_protocol_class, "read_double", rb_thrift_compact_proto_read_double, 0);
604
620
  rb_define_method(thrift_compact_protocol_class, "read_string", rb_thrift_compact_proto_read_string, 0);
621
+ rb_define_method(thrift_compact_protocol_class, "read_binary", rb_thrift_compact_proto_read_binary, 0);
605
622
 
606
623
  rb_define_method(thrift_compact_protocol_class, "read_message_end", rb_thrift_compact_proto_read_message_end, 0);
607
624
  rb_define_method(thrift_compact_protocol_class, "read_struct_begin", rb_thrift_compact_proto_read_struct_begin, 0);
data/ext/constants.h CHANGED
@@ -48,7 +48,6 @@ extern ID write_list_begin_method_id;
48
48
  extern ID write_list_end_method_id;
49
49
  extern ID write_set_begin_method_id;
50
50
  extern ID write_set_end_method_id;
51
- extern ID size_method_id;
52
51
  extern ID read_bool_method_id;
53
52
  extern ID read_byte_method_id;
54
53
  extern ID read_i16_method_id;
@@ -67,15 +66,15 @@ extern ID read_struct_end_method_id;
67
66
  extern ID read_field_begin_method_id;
68
67
  extern ID read_field_end_method_id;
69
68
  extern ID keys_method_id;
70
- extern ID entries_method_id;
71
- extern ID name_method_id;
72
- extern ID sort_method_id;
69
+ extern ID entries_method_id;
73
70
  extern ID write_field_stop_method_id;
74
71
  extern ID skip_method_id;
75
72
  extern ID write_method_id;
76
73
  extern ID read_all_method_id;
77
74
  extern ID read_into_buffer_method_id;
78
- extern ID native_qmark_method_id;
75
+ extern ID force_binary_encoding_id;
76
+ extern ID convert_to_utf8_byte_buffer_id;
77
+ extern ID convert_to_string_id;
79
78
 
80
79
  extern ID fields_const_id;
81
80
  extern ID transport_ivar_id;
@@ -92,5 +91,6 @@ extern VALUE class_sym;
92
91
  extern VALUE rb_cSet;
93
92
  extern VALUE thrift_module;
94
93
  extern VALUE thrift_types_module;
94
+ extern VALUE thrift_bytes_module;
95
95
  extern VALUE class_thrift_protocol;
96
96
  extern VALUE protocol_exception_class;
data/ext/extconf.rb CHANGED
@@ -22,7 +22,9 @@ if defined?(RUBY_ENGINE) && RUBY_ENGINE =~ /jruby/
22
22
  else
23
23
  require 'mkmf'
24
24
 
25
- $CFLAGS = "-g -O2 -Wall -Werror"
25
+ $ARCH_FLAGS = Config::CONFIG['CFLAGS'].scan( /(-arch )(\S+)/ ).map{|x,y| x + y + ' ' }.join('')
26
+
27
+ $CFLAGS = "-fsigned-char -g -O2 -Wall -Werror " + $ARCH_FLAGS
26
28
 
27
29
  have_func("strlcpy", "string.h")
28
30
 
data/ext/memory_buffer.c CHANGED
@@ -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,6 +38,7 @@ 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);
41
+ str = force_binary_encoding(str);
40
42
  rb_str_buf_cat(buf, RSTRING_PTR(str), RSTRING_LEN(str));
41
43
  return Qnil;
42
44
  }
@@ -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
 
data/ext/protocol.c CHANGED
@@ -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
- }