sessionm-thrift 0.8.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 (81) hide show
  1. data/CHANGELOG +1 -0
  2. data/README +43 -0
  3. data/benchmark/Benchmark.thrift +24 -0
  4. data/benchmark/benchmark.rb +271 -0
  5. data/benchmark/client.rb +74 -0
  6. data/benchmark/server.rb +82 -0
  7. data/benchmark/thin_server.rb +44 -0
  8. data/ext/binary_protocol_accelerated.c +441 -0
  9. data/ext/binary_protocol_accelerated.h +20 -0
  10. data/ext/compact_protocol.c +618 -0
  11. data/ext/compact_protocol.h +20 -0
  12. data/ext/constants.h +96 -0
  13. data/ext/extconf.rb +30 -0
  14. data/ext/macros.h +41 -0
  15. data/ext/memory_buffer.c +131 -0
  16. data/ext/memory_buffer.h +20 -0
  17. data/ext/protocol.c +185 -0
  18. data/ext/protocol.h +20 -0
  19. data/ext/strlcpy.c +41 -0
  20. data/ext/strlcpy.h +30 -0
  21. data/ext/struct.c +691 -0
  22. data/ext/struct.h +25 -0
  23. data/ext/thrift_native.c +196 -0
  24. data/lib/thrift.rb +64 -0
  25. data/lib/thrift/client.rb +62 -0
  26. data/lib/thrift/core_ext.rb +23 -0
  27. data/lib/thrift/core_ext/fixnum.rb +29 -0
  28. data/lib/thrift/exceptions.rb +84 -0
  29. data/lib/thrift/processor.rb +57 -0
  30. data/lib/thrift/protocol/base_protocol.rb +290 -0
  31. data/lib/thrift/protocol/binary_protocol.rb +229 -0
  32. data/lib/thrift/protocol/binary_protocol_accelerated.rb +39 -0
  33. data/lib/thrift/protocol/compact_protocol.rb +426 -0
  34. data/lib/thrift/serializer/deserializer.rb +33 -0
  35. data/lib/thrift/serializer/serializer.rb +34 -0
  36. data/lib/thrift/server/base_server.rb +31 -0
  37. data/lib/thrift/server/mongrel_http_server.rb +58 -0
  38. data/lib/thrift/server/nonblocking_server.rb +305 -0
  39. data/lib/thrift/server/simple_server.rb +43 -0
  40. data/lib/thrift/server/thread_pool_server.rb +75 -0
  41. data/lib/thrift/server/threaded_server.rb +47 -0
  42. data/lib/thrift/struct.rb +237 -0
  43. data/lib/thrift/struct_union.rb +192 -0
  44. data/lib/thrift/thrift_native.rb +24 -0
  45. data/lib/thrift/transport/base_server_transport.rb +37 -0
  46. data/lib/thrift/transport/base_transport.rb +107 -0
  47. data/lib/thrift/transport/buffered_transport.rb +108 -0
  48. data/lib/thrift/transport/framed_transport.rb +116 -0
  49. data/lib/thrift/transport/http_client_transport.rb +51 -0
  50. data/lib/thrift/transport/io_stream_transport.rb +39 -0
  51. data/lib/thrift/transport/memory_buffer_transport.rb +125 -0
  52. data/lib/thrift/transport/server_socket.rb +63 -0
  53. data/lib/thrift/transport/socket.rb +137 -0
  54. data/lib/thrift/transport/unix_server_socket.rb +60 -0
  55. data/lib/thrift/transport/unix_socket.rb +40 -0
  56. data/lib/thrift/types.rb +101 -0
  57. data/lib/thrift/union.rb +179 -0
  58. data/spec/ThriftSpec.thrift +132 -0
  59. data/spec/base_protocol_spec.rb +160 -0
  60. data/spec/base_transport_spec.rb +351 -0
  61. data/spec/binary_protocol_accelerated_spec.rb +46 -0
  62. data/spec/binary_protocol_spec.rb +61 -0
  63. data/spec/binary_protocol_spec_shared.rb +375 -0
  64. data/spec/client_spec.rb +100 -0
  65. data/spec/compact_protocol_spec.rb +144 -0
  66. data/spec/exception_spec.rb +142 -0
  67. data/spec/http_client_spec.rb +64 -0
  68. data/spec/mongrel_http_server_spec.rb +117 -0
  69. data/spec/nonblocking_server_spec.rb +265 -0
  70. data/spec/processor_spec.rb +83 -0
  71. data/spec/serializer_spec.rb +69 -0
  72. data/spec/server_socket_spec.rb +80 -0
  73. data/spec/server_spec.rb +159 -0
  74. data/spec/socket_spec.rb +61 -0
  75. data/spec/socket_spec_shared.rb +104 -0
  76. data/spec/spec_helper.rb +58 -0
  77. data/spec/struct_spec.rb +295 -0
  78. data/spec/types_spec.rb +116 -0
  79. data/spec/union_spec.rb +193 -0
  80. data/spec/unix_socket_spec.rb +108 -0
  81. metadata +247 -0
@@ -0,0 +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
+
20
+ void Init_compact_protocol();
data/ext/constants.h ADDED
@@ -0,0 +1,96 @@
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
+ extern int TTYPE_STOP;
21
+ extern int TTYPE_BOOL;
22
+ extern int TTYPE_BYTE;
23
+ extern int TTYPE_I16;
24
+ extern int TTYPE_I32;
25
+ extern int TTYPE_I64;
26
+ extern int TTYPE_DOUBLE;
27
+ extern int TTYPE_STRING;
28
+ extern int TTYPE_MAP;
29
+ extern int TTYPE_SET;
30
+ extern int TTYPE_LIST;
31
+ extern int TTYPE_STRUCT;
32
+
33
+ extern ID validate_method_id;
34
+ extern ID write_struct_begin_method_id;
35
+ extern ID write_struct_end_method_id;
36
+ extern ID write_field_begin_method_id;
37
+ extern ID write_field_end_method_id;
38
+ extern ID write_boolean_method_id;
39
+ extern ID write_byte_method_id;
40
+ extern ID write_i16_method_id;
41
+ extern ID write_i32_method_id;
42
+ extern ID write_i64_method_id;
43
+ extern ID write_double_method_id;
44
+ extern ID write_string_method_id;
45
+ extern ID write_map_begin_method_id;
46
+ extern ID write_map_end_method_id;
47
+ extern ID write_list_begin_method_id;
48
+ extern ID write_list_end_method_id;
49
+ extern ID write_set_begin_method_id;
50
+ extern ID write_set_end_method_id;
51
+ extern ID size_method_id;
52
+ extern ID read_bool_method_id;
53
+ extern ID read_byte_method_id;
54
+ extern ID read_i16_method_id;
55
+ extern ID read_i32_method_id;
56
+ extern ID read_i64_method_id;
57
+ extern ID read_string_method_id;
58
+ extern ID read_double_method_id;
59
+ extern ID read_map_begin_method_id;
60
+ extern ID read_map_end_method_id;
61
+ extern ID read_list_begin_method_id;
62
+ extern ID read_list_end_method_id;
63
+ extern ID read_set_begin_method_id;
64
+ extern ID read_set_end_method_id;
65
+ extern ID read_struct_begin_method_id;
66
+ extern ID read_struct_end_method_id;
67
+ extern ID read_field_begin_method_id;
68
+ extern ID read_field_end_method_id;
69
+ extern ID keys_method_id;
70
+ extern ID entries_method_id;
71
+ extern ID name_method_id;
72
+ extern ID sort_method_id;
73
+ extern ID write_field_stop_method_id;
74
+ extern ID skip_method_id;
75
+ extern ID write_method_id;
76
+ extern ID read_all_method_id;
77
+ extern ID read_into_buffer_method_id;
78
+ extern ID native_qmark_method_id;
79
+
80
+ extern ID fields_const_id;
81
+ extern ID transport_ivar_id;
82
+ extern ID strict_read_ivar_id;
83
+ extern ID strict_write_ivar_id;
84
+
85
+ extern VALUE type_sym;
86
+ extern VALUE name_sym;
87
+ extern VALUE key_sym;
88
+ extern VALUE value_sym;
89
+ extern VALUE element_sym;
90
+ extern VALUE class_sym;
91
+
92
+ extern VALUE rb_cSet;
93
+ extern VALUE thrift_module;
94
+ extern VALUE thrift_types_module;
95
+ extern VALUE class_thrift_protocol;
96
+ extern VALUE protocol_exception_class;
data/ext/extconf.rb ADDED
@@ -0,0 +1,30 @@
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
+ if defined?(RUBY_ENGINE) && RUBY_ENGINE =~ /jruby/
21
+ File.open('Makefile', 'w'){|f| f.puts "all:\n\ninstall:\n" }
22
+ else
23
+ require 'mkmf'
24
+
25
+ $CFLAGS = "-g -O2 -Wall -Werror"
26
+
27
+ have_func("strlcpy", "string.h")
28
+
29
+ create_makefile 'thrift_native'
30
+ end
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
@@ -0,0 +1,131 @@
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 <constants.h>
22
+ #include "macros.h"
23
+
24
+ ID buf_ivar_id;
25
+ ID index_ivar_id;
26
+
27
+ ID slice_method_id;
28
+
29
+ int GARBAGE_BUFFER_SIZE;
30
+
31
+ #define GET_BUF(self) rb_ivar_get(self, buf_ivar_id)
32
+
33
+ VALUE rb_thrift_memory_buffer_write(VALUE self, VALUE str);
34
+ VALUE rb_thrift_memory_buffer_read(VALUE self, VALUE length_value);
35
+ VALUE rb_thrift_memory_buffer_read_byte(VALUE self);
36
+ VALUE rb_thrift_memory_buffer_read_into_buffer(VALUE self, VALUE buffer_value, VALUE size_value);
37
+
38
+ VALUE rb_thrift_memory_buffer_write(VALUE self, VALUE str) {
39
+ VALUE buf = GET_BUF(self);
40
+ rb_str_buf_cat(buf, RSTRING_PTR(str), RSTRING_LEN(str));
41
+ return Qnil;
42
+ }
43
+
44
+ VALUE rb_thrift_memory_buffer_read(VALUE self, VALUE length_value) {
45
+ int length = FIX2INT(length_value);
46
+
47
+ VALUE index_value = rb_ivar_get(self, index_ivar_id);
48
+ int index = FIX2INT(index_value);
49
+
50
+ VALUE buf = GET_BUF(self);
51
+ VALUE data = rb_funcall(buf, slice_method_id, 2, index_value, length_value);
52
+
53
+ index += length;
54
+ if (index > RSTRING_LEN(buf)) {
55
+ index = RSTRING_LEN(buf);
56
+ }
57
+ if (index >= GARBAGE_BUFFER_SIZE) {
58
+ rb_ivar_set(self, buf_ivar_id, rb_funcall(buf, slice_method_id, 2, INT2FIX(index), INT2FIX(RSTRING_LEN(buf) - 1)));
59
+ index = 0;
60
+ }
61
+ rb_ivar_set(self, index_ivar_id, INT2FIX(index));
62
+
63
+ if (RSTRING_LEN(data) < length) {
64
+ rb_raise(rb_eEOFError, "Not enough bytes remain in memory buffer");
65
+ }
66
+
67
+ return data;
68
+ }
69
+
70
+ VALUE rb_thrift_memory_buffer_read_byte(VALUE self) {
71
+ VALUE index_value = rb_ivar_get(self, index_ivar_id);
72
+ int index = FIX2INT(index_value);
73
+
74
+ VALUE buf = GET_BUF(self);
75
+ if (index >= RSTRING_LEN(buf)) {
76
+ rb_raise(rb_eEOFError, "Not enough bytes remain in memory buffer");
77
+ }
78
+ char byte = RSTRING_PTR(buf)[index++];
79
+
80
+ if (index >= GARBAGE_BUFFER_SIZE) {
81
+ rb_ivar_set(self, buf_ivar_id, rb_funcall(buf, slice_method_id, 2, INT2FIX(index), INT2FIX(RSTRING_LEN(buf) - 1)));
82
+ index = 0;
83
+ }
84
+ rb_ivar_set(self, index_ivar_id, INT2FIX(index));
85
+
86
+ int result = (int) byte;
87
+ return INT2FIX(result);
88
+ }
89
+
90
+ VALUE rb_thrift_memory_buffer_read_into_buffer(VALUE self, VALUE buffer_value, VALUE size_value) {
91
+ int i = 0;
92
+ int size = FIX2INT(size_value);
93
+ int index;
94
+ VALUE buf = GET_BUF(self);
95
+
96
+ while (i < size) {
97
+ index = FIX2INT(rb_ivar_get(self, index_ivar_id));
98
+ if (index >= RSTRING_LEN(buf)) {
99
+ rb_raise(rb_eEOFError, "Not enough bytes remain in memory buffer");
100
+ }
101
+ char byte = RSTRING_PTR(buf)[index++];
102
+
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
+ if (i >= RSTRING_LEN(buffer_value)) {
110
+ rb_raise(rb_eIndexError, "index %d out of string", i);
111
+ }
112
+ ((char*)RSTRING_PTR(buffer_value))[i] = byte;
113
+ i++;
114
+ }
115
+ return INT2FIX(i);
116
+ }
117
+
118
+ void Init_memory_buffer() {
119
+ VALUE thrift_memory_buffer_class = rb_const_get(thrift_module, rb_intern("MemoryBufferTransport"));
120
+ rb_define_method(thrift_memory_buffer_class, "write", rb_thrift_memory_buffer_write, 1);
121
+ rb_define_method(thrift_memory_buffer_class, "read", rb_thrift_memory_buffer_read, 1);
122
+ rb_define_method(thrift_memory_buffer_class, "read_byte", rb_thrift_memory_buffer_read_byte, 0);
123
+ rb_define_method(thrift_memory_buffer_class, "read_into_buffer", rb_thrift_memory_buffer_read_into_buffer, 2);
124
+
125
+ buf_ivar_id = rb_intern("@buf");
126
+ index_ivar_id = rb_intern("@index");
127
+
128
+ slice_method_id = rb_intern("slice");
129
+
130
+ GARBAGE_BUFFER_SIZE = FIX2INT(rb_const_get(thrift_memory_buffer_class, rb_intern("GARBAGE_BUFFER_SIZE")));
131
+ }
@@ -0,0 +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
+
20
+ void Init_memory_buffer();
data/ext/protocol.c ADDED
@@ -0,0 +1,185 @@
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
+ }