thrift 0.0.751142

Sign up to get free protection for your applications and to get access to all the features.
Files changed (82) hide show
  1. data/CHANGELOG +2 -0
  2. data/COPYING +14 -0
  3. data/LICENSE +14 -0
  4. data/Makefile.am +15 -0
  5. data/Manifest +78 -0
  6. data/README +30 -0
  7. data/Rakefile +102 -0
  8. data/benchmark/Benchmark.thrift +5 -0
  9. data/benchmark/benchmark.rb +254 -0
  10. data/benchmark/client.rb +56 -0
  11. data/benchmark/gen-rb/BenchmarkService.rb +81 -0
  12. data/benchmark/gen-rb/Benchmark_constants.rb +11 -0
  13. data/benchmark/gen-rb/Benchmark_types.rb +10 -0
  14. data/benchmark/server.rb +64 -0
  15. data/benchmark/thin_server.rb +26 -0
  16. data/ext/binary_protocol_accelerated.c +463 -0
  17. data/ext/binary_protocol_accelerated.h +1 -0
  18. data/ext/constants.h +77 -0
  19. data/ext/extconf.rb +7 -0
  20. data/ext/memory_buffer.c +52 -0
  21. data/ext/memory_buffer.h +1 -0
  22. data/ext/protocol.c +166 -0
  23. data/ext/protocol.h +1 -0
  24. data/ext/struct.c +574 -0
  25. data/ext/struct.h +48 -0
  26. data/ext/thrift_native.c +173 -0
  27. data/lib/thrift/client.rb +44 -0
  28. data/lib/thrift/deprecation.rb +155 -0
  29. data/lib/thrift/exceptions.rb +65 -0
  30. data/lib/thrift/processor.rb +39 -0
  31. data/lib/thrift/protocol/binaryprotocol.rb +213 -0
  32. data/lib/thrift/protocol/binaryprotocolaccelerated.rb +19 -0
  33. data/lib/thrift/protocol/tbinaryprotocol.rb +2 -0
  34. data/lib/thrift/protocol/tprotocol.rb +2 -0
  35. data/lib/thrift/protocol.rb +270 -0
  36. data/lib/thrift/serializer.rb +27 -0
  37. data/lib/thrift/server/httpserver.rb +44 -0
  38. data/lib/thrift/server/nonblockingserver.rb +278 -0
  39. data/lib/thrift/server/thttpserver.rb +2 -0
  40. data/lib/thrift/server/tserver.rb +2 -0
  41. data/lib/thrift/server.rb +135 -0
  42. data/lib/thrift/struct.rb +272 -0
  43. data/lib/thrift/thrift.rb +14 -0
  44. data/lib/thrift/transport/httpclient.rb +29 -0
  45. data/lib/thrift/transport/socket.rb +167 -0
  46. data/lib/thrift/transport/thttpclient.rb +2 -0
  47. data/lib/thrift/transport/tsocket.rb +2 -0
  48. data/lib/thrift/transport/ttransport.rb +2 -0
  49. data/lib/thrift/transport/unixsocket.rb +58 -0
  50. data/lib/thrift/transport.rb +319 -0
  51. data/lib/thrift/types.rb +83 -0
  52. data/lib/thrift.rb +28 -0
  53. data/setup.rb +1585 -0
  54. data/spec/ThriftSpec.thrift +46 -0
  55. data/spec/backwards_compatibility_spec.rb +136 -0
  56. data/spec/binaryprotocol_spec.rb +45 -0
  57. data/spec/binaryprotocol_spec_shared.rb +274 -0
  58. data/spec/binaryprotocolaccelerated_spec.rb +101 -0
  59. data/spec/client_spec.rb +81 -0
  60. data/spec/deprecation_spec.rb +443 -0
  61. data/spec/exception_spec.rb +123 -0
  62. data/spec/gen-rb/NonblockingService.rb +268 -0
  63. data/spec/gen-rb/ThriftSpec_constants.rb +11 -0
  64. data/spec/gen-rb/ThriftSpec_types.rb +134 -0
  65. data/spec/httpclient_spec.rb +31 -0
  66. data/spec/httpserver_spec.rb +98 -0
  67. data/spec/nonblockingserver_spec.rb +245 -0
  68. data/spec/processor_spec.rb +64 -0
  69. data/spec/protocol_spec.rb +142 -0
  70. data/spec/serializer_spec.rb +52 -0
  71. data/spec/server_spec.rb +141 -0
  72. data/spec/socket_spec.rb +97 -0
  73. data/spec/socket_spec_shared.rb +85 -0
  74. data/spec/spec_helper.rb +35 -0
  75. data/spec/struct_spec.rb +244 -0
  76. data/spec/transport_spec.rb +359 -0
  77. data/spec/types_spec.rb +98 -0
  78. data/spec/unixsocket_spec.rb +90 -0
  79. data/thrift.gemspec +33 -0
  80. data.tar.gz.sig +0 -0
  81. metadata +200 -0
  82. metadata.gz.sig +0 -0
data/ext/protocol.c ADDED
@@ -0,0 +1,166 @@
1
+ #include <ruby.h>
2
+ #include <protocol.h>
3
+ #include <stdbool.h>
4
+ #include <constants.h>
5
+ #include <struct.h>
6
+
7
+ static VALUE skip(VALUE self, int ttype) {
8
+ if (ttype == TTYPE_STOP) {
9
+ return Qnil;
10
+ } else if (ttype == TTYPE_BOOL) {
11
+ rb_funcall(self, read_bool_method_id, 0);
12
+ } else if (ttype == TTYPE_BYTE) {
13
+ rb_funcall(self, read_byte_method_id, 0);
14
+ } else if (ttype == TTYPE_I16) {
15
+ rb_funcall(self, read_i16_method_id, 0);
16
+ } else if (ttype == TTYPE_I32) {
17
+ rb_funcall(self, read_i32_method_id, 0);
18
+ } else if (ttype == TTYPE_I64) {
19
+ rb_funcall(self, read_i64_method_id, 0);
20
+ } else if (ttype == TTYPE_DOUBLE) {
21
+ rb_funcall(self, read_double_method_id, 0);
22
+ } else if (ttype == TTYPE_STRING) {
23
+ rb_funcall(self, read_string_method_id, 0);
24
+ } else if (ttype == TTYPE_STRUCT) {
25
+ rb_funcall(self, read_struct_begin_method_id, 0);
26
+ while (true) {
27
+ VALUE field_header = rb_funcall(self, read_field_begin_method_id, 0);
28
+ if (NIL_P(field_header) || FIX2INT(rb_ary_entry(field_header, 1)) == TTYPE_STOP ) {
29
+ break;
30
+ }
31
+ skip(self, FIX2INT(rb_ary_entry(field_header, 1)));
32
+ rb_funcall(self, read_field_end_method_id, 0);
33
+ }
34
+ rb_funcall(self, read_struct_end_method_id, 0);
35
+ } else if (ttype == TTYPE_MAP) {
36
+ int i;
37
+ VALUE map_header = rb_funcall(self, read_map_begin_method_id, 0);
38
+ int ktype = FIX2INT(rb_ary_entry(map_header, 0));
39
+ int vtype = FIX2INT(rb_ary_entry(map_header, 1));
40
+ int size = FIX2INT(rb_ary_entry(map_header, 2));
41
+
42
+ for (i = 0; i < size; i++) {
43
+ skip(self, ktype);
44
+ skip(self, vtype);
45
+ }
46
+ rb_funcall(self, read_map_end_method_id, 0);
47
+ } else if (ttype == TTYPE_LIST || ttype == TTYPE_SET) {
48
+ int i;
49
+ VALUE collection_header = rb_funcall(self, ttype == TTYPE_LIST ? read_list_begin_method_id : read_set_begin_method_id, 0);
50
+ int etype = FIX2INT(rb_ary_entry(collection_header, 0));
51
+ int size = FIX2INT(rb_ary_entry(collection_header, 1));
52
+ for (i = 0; i < size; i++) {
53
+ skip(self, etype);
54
+ }
55
+ rb_funcall(self, ttype == TTYPE_LIST ? read_list_end_method_id : read_set_end_method_id, 0);
56
+ } else {
57
+ rb_raise(rb_eNotImpError, "don't know how to skip type %d", ttype);
58
+ }
59
+
60
+ return Qnil;
61
+ }
62
+
63
+ VALUE rb_thrift_protocol_native_qmark(VALUE self) {
64
+ return Qfalse;
65
+ }
66
+
67
+ VALUE rb_thrift_protocol_skip(VALUE protocol, VALUE ttype) {
68
+ return skip(protocol, FIX2INT(ttype));
69
+ }
70
+
71
+ VALUE rb_thrift_write_message_end(VALUE self) {
72
+ return Qnil;
73
+ }
74
+
75
+ VALUE rb_thrift_write_struct_begin(VALUE self, VALUE name) {
76
+ return Qnil;
77
+ }
78
+
79
+ VALUE rb_thrift_write_struct_end(VALUE self) {
80
+ return Qnil;
81
+ }
82
+
83
+ VALUE rb_thrift_write_field_end(VALUE self) {
84
+ return Qnil;
85
+ }
86
+
87
+ VALUE rb_thrift_write_map_end(VALUE self) {
88
+ return Qnil;
89
+ }
90
+
91
+ VALUE rb_thrift_write_list_end(VALUE self) {
92
+ return Qnil;
93
+ }
94
+
95
+ VALUE rb_thrift_write_set_end(VALUE self) {
96
+ return Qnil;
97
+ }
98
+
99
+ VALUE rb_thrift_read_message_end(VALUE self) {
100
+ return Qnil;
101
+ }
102
+
103
+ VALUE rb_thift_read_struct_begin(VALUE self) {
104
+ return Qnil;
105
+ }
106
+
107
+ VALUE rb_thift_read_struct_end(VALUE self) {
108
+ return Qnil;
109
+ }
110
+
111
+ VALUE rb_thift_read_field_end(VALUE self) {
112
+ return Qnil;
113
+ }
114
+
115
+ VALUE rb_thift_read_map_end(VALUE self) {
116
+ return Qnil;
117
+ }
118
+
119
+ VALUE rb_thift_read_list_end(VALUE self) {
120
+ return Qnil;
121
+ }
122
+
123
+ VALUE rb_thift_read_set_end(VALUE self) {
124
+ return Qnil;
125
+ }
126
+
127
+ void Init_protocol() {
128
+ VALUE c_protocol = rb_const_get(thrift_module, rb_intern("Protocol"));
129
+
130
+ rb_define_method(c_protocol, "skip", rb_thrift_protocol_skip, 1);
131
+ rb_define_method(c_protocol, "write_message_end", rb_thrift_write_message_end, 0);
132
+ rb_define_method(c_protocol, "write_struct_begin", rb_thrift_write_struct_begin, 1);
133
+ rb_define_method(c_protocol, "write_struct_end", rb_thrift_write_struct_end, 0);
134
+ rb_define_method(c_protocol, "write_field_end", rb_thrift_write_field_end, 0);
135
+ rb_define_method(c_protocol, "write_map_end", rb_thrift_write_map_end, 0);
136
+ rb_define_method(c_protocol, "write_list_end", rb_thrift_write_list_end, 0);
137
+ rb_define_method(c_protocol, "write_set_end", rb_thrift_write_set_end, 0);
138
+ rb_define_method(c_protocol, "read_message_end", rb_thrift_read_message_end, 0);
139
+ rb_define_method(c_protocol, "read_struct_begin", rb_thift_read_struct_begin, 0);
140
+ rb_define_method(c_protocol, "read_struct_end", rb_thift_read_struct_end, 0);
141
+ rb_define_method(c_protocol, "read_field_end", rb_thift_read_field_end, 0);
142
+ rb_define_method(c_protocol, "read_map_end", rb_thift_read_map_end, 0);
143
+ rb_define_method(c_protocol, "read_list_end", rb_thift_read_list_end, 0);
144
+ rb_define_method(c_protocol, "read_set_end", rb_thift_read_set_end, 0);
145
+ rb_define_method(c_protocol, "native?", rb_thrift_protocol_native_qmark, 0);
146
+
147
+ // native_proto_method_table *npmt;
148
+ // npmt = ALLOC(native_proto_method_table);
149
+ // npmt->write_message_end = rb_thrift_write_message_end;
150
+ // npmt->write_struct_begin = rb_thrift_write_struct_begin;
151
+ // npmt->write_struct_end = rb_thrift_write_struct_end;
152
+ // npmt->write_field_end = rb_thrift_write_field_end;
153
+ // npmt->write_map_end = rb_thrift_write_map_end;
154
+ // npmt->write_list_end = rb_thrift_write_list_end;
155
+ // npmt->write_set_end = rb_thrift_write_set_end;
156
+ // npmt->read_message_end = rb_thrift_read_message_end;
157
+ // npmt->read_struct_begin = rb_thift_read_struct_begin;
158
+ // npmt->read_struct_end = rb_thift_read_struct_end;
159
+ // npmt->read_field_end = rb_thift_read_field_end;
160
+ // npmt->read_map_end = rb_thift_read_map_end;
161
+ // npmt->read_list_end = rb_thift_read_list_end;
162
+ // npmt->read_set_end = rb_thift_read_set_end;
163
+ //
164
+ // VALUE method_table_object = Data_Wrap_Struct(rb_cObject, 0, free, npmt);
165
+ // rb_const_set(c_protocol, rb_intern("@native_method_table"), method_table_object);
166
+ }
data/ext/protocol.h ADDED
@@ -0,0 +1 @@
1
+ void Init_protocol();