jml_thrift 1.0.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (89) hide show
  1. checksums.yaml +7 -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 +460 -0
  9. data/ext/binary_protocol_accelerated.h +20 -0
  10. data/ext/bytes.c +36 -0
  11. data/ext/bytes.h +31 -0
  12. data/ext/compact_protocol.c +635 -0
  13. data/ext/compact_protocol.h +20 -0
  14. data/ext/constants.h +96 -0
  15. data/ext/extconf.rb +32 -0
  16. data/ext/macros.h +41 -0
  17. data/ext/memory_buffer.c +134 -0
  18. data/ext/memory_buffer.h +20 -0
  19. data/ext/protocol.c +0 -0
  20. data/ext/protocol.h +0 -0
  21. data/ext/strlcpy.c +41 -0
  22. data/ext/strlcpy.h +34 -0
  23. data/ext/struct.c +688 -0
  24. data/ext/struct.h +25 -0
  25. data/ext/thrift_native.c +195 -0
  26. data/lib/thrift.rb +66 -0
  27. data/lib/thrift/bytes.rb +131 -0
  28. data/lib/thrift/client.rb +62 -0
  29. data/lib/thrift/core_ext.rb +23 -0
  30. data/lib/thrift/core_ext/fixnum.rb +29 -0
  31. data/lib/thrift/exceptions.rb +87 -0
  32. data/lib/thrift/processor.rb +57 -0
  33. data/lib/thrift/protocol/base_protocol.rb +377 -0
  34. data/lib/thrift/protocol/binary_protocol.rb +237 -0
  35. data/lib/thrift/protocol/binary_protocol_accelerated.rb +39 -0
  36. data/lib/thrift/protocol/compact_protocol.rb +434 -0
  37. data/lib/thrift/protocol/json_protocol.rb +769 -0
  38. data/lib/thrift/serializer/deserializer.rb +33 -0
  39. data/lib/thrift/serializer/serializer.rb +34 -0
  40. data/lib/thrift/server/base_server.rb +31 -0
  41. data/lib/thrift/server/mongrel_http_server.rb +60 -0
  42. data/lib/thrift/server/nonblocking_server.rb +305 -0
  43. data/lib/thrift/server/simple_server.rb +43 -0
  44. data/lib/thrift/server/thin_http_server.rb +91 -0
  45. data/lib/thrift/server/thread_pool_server.rb +75 -0
  46. data/lib/thrift/server/threaded_server.rb +47 -0
  47. data/lib/thrift/struct.rb +237 -0
  48. data/lib/thrift/struct_union.rb +192 -0
  49. data/lib/thrift/thrift_native.rb +24 -0
  50. data/lib/thrift/transport/base_server_transport.rb +37 -0
  51. data/lib/thrift/transport/base_transport.rb +109 -0
  52. data/lib/thrift/transport/buffered_transport.rb +114 -0
  53. data/lib/thrift/transport/framed_transport.rb +117 -0
  54. data/lib/thrift/transport/http_client_transport.rb +56 -0
  55. data/lib/thrift/transport/io_stream_transport.rb +39 -0
  56. data/lib/thrift/transport/memory_buffer_transport.rb +125 -0
  57. data/lib/thrift/transport/server_socket.rb +63 -0
  58. data/lib/thrift/transport/socket.rb +139 -0
  59. data/lib/thrift/transport/unix_server_socket.rb +60 -0
  60. data/lib/thrift/transport/unix_socket.rb +40 -0
  61. data/lib/thrift/types.rb +101 -0
  62. data/lib/thrift/union.rb +179 -0
  63. data/spec/ThriftSpec.thrift +183 -0
  64. data/spec/base_protocol_spec.rb +217 -0
  65. data/spec/base_transport_spec.rb +350 -0
  66. data/spec/binary_protocol_accelerated_spec.rb +42 -0
  67. data/spec/binary_protocol_spec.rb +66 -0
  68. data/spec/binary_protocol_spec_shared.rb +455 -0
  69. data/spec/bytes_spec.rb +160 -0
  70. data/spec/client_spec.rb +99 -0
  71. data/spec/compact_protocol_spec.rb +143 -0
  72. data/spec/exception_spec.rb +141 -0
  73. data/spec/http_client_spec.rb +120 -0
  74. data/spec/json_protocol_spec.rb +513 -0
  75. data/spec/nonblocking_server_spec.rb +263 -0
  76. data/spec/processor_spec.rb +80 -0
  77. data/spec/serializer_spec.rb +67 -0
  78. data/spec/server_socket_spec.rb +79 -0
  79. data/spec/server_spec.rb +147 -0
  80. data/spec/socket_spec.rb +61 -0
  81. data/spec/socket_spec_shared.rb +104 -0
  82. data/spec/spec_helper.rb +61 -0
  83. data/spec/struct_nested_containers_spec.rb +191 -0
  84. data/spec/struct_spec.rb +293 -0
  85. data/spec/thin_http_server_spec.rb +141 -0
  86. data/spec/types_spec.rb +115 -0
  87. data/spec/union_spec.rb +203 -0
  88. data/spec/unix_socket_spec.rb +107 -0
  89. metadata +310 -0
@@ -0,0 +1,25 @@
1
+ /*
2
+ * Licensed to the Apache Software Foundation (ASF) under one
3
+ * or more contributor license agreements. See the NOTICE file
4
+ * distributed with this work for additional information
5
+ * regarding copyright ownership. The ASF licenses this file
6
+ * to you under the Apache License, Version 2.0 (the
7
+ * "License"); you may not use this file except in compliance
8
+ * with the License. You may obtain a copy of the License at
9
+ *
10
+ * http://www.apache.org/licenses/LICENSE-2.0
11
+ *
12
+ * Unless required by applicable law or agreed to in writing,
13
+ * software distributed under the License is distributed on an
14
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15
+ * KIND, either express or implied. See the License for the
16
+ * specific language governing permissions and limitations
17
+ * under the License.
18
+ */
19
+
20
+
21
+ #include <stdbool.h>
22
+ #include <ruby.h>
23
+
24
+ void Init_struct();
25
+ void Init_union();
@@ -0,0 +1,195 @@
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 <bytes.h>
22
+ #include <struct.h>
23
+ #include <binary_protocol_accelerated.h>
24
+ #include <compact_protocol.h>
25
+ #include <memory_buffer.h>
26
+
27
+ // cached classes/modules
28
+ VALUE rb_cSet;
29
+ VALUE thrift_module;
30
+ VALUE thrift_bytes_module;
31
+ VALUE thrift_types_module;
32
+
33
+ // TType constants
34
+ int TTYPE_STOP;
35
+ int TTYPE_BOOL;
36
+ int TTYPE_BYTE;
37
+ int TTYPE_I16;
38
+ int TTYPE_I32;
39
+ int TTYPE_I64;
40
+ int TTYPE_DOUBLE;
41
+ int TTYPE_STRING;
42
+ int TTYPE_MAP;
43
+ int TTYPE_SET;
44
+ int TTYPE_LIST;
45
+ int TTYPE_STRUCT;
46
+
47
+ // method ids
48
+ ID validate_method_id;
49
+ ID write_struct_begin_method_id;
50
+ ID write_struct_end_method_id;
51
+ ID write_field_begin_method_id;
52
+ ID write_field_end_method_id;
53
+ ID write_boolean_method_id;
54
+ ID write_byte_method_id;
55
+ ID write_i16_method_id;
56
+ ID write_i32_method_id;
57
+ ID write_i64_method_id;
58
+ ID write_double_method_id;
59
+ ID write_string_method_id;
60
+ ID write_map_begin_method_id;
61
+ ID write_map_end_method_id;
62
+ ID write_list_begin_method_id;
63
+ ID write_list_end_method_id;
64
+ ID write_set_begin_method_id;
65
+ ID write_set_end_method_id;
66
+ ID read_bool_method_id;
67
+ ID read_byte_method_id;
68
+ ID read_i16_method_id;
69
+ ID read_i32_method_id;
70
+ ID read_i64_method_id;
71
+ ID read_string_method_id;
72
+ ID read_double_method_id;
73
+ ID read_map_begin_method_id;
74
+ ID read_map_end_method_id;
75
+ ID read_list_begin_method_id;
76
+ ID read_list_end_method_id;
77
+ ID read_set_begin_method_id;
78
+ ID read_set_end_method_id;
79
+ ID read_struct_begin_method_id;
80
+ ID read_struct_end_method_id;
81
+ ID read_field_begin_method_id;
82
+ ID read_field_end_method_id;
83
+ ID keys_method_id;
84
+ ID entries_method_id;
85
+ ID write_field_stop_method_id;
86
+ ID skip_method_id;
87
+ ID write_method_id;
88
+ ID read_all_method_id;
89
+ ID read_into_buffer_method_id;
90
+ ID force_binary_encoding_id;
91
+ ID convert_to_utf8_byte_buffer_id;
92
+ ID convert_to_string_id;
93
+
94
+ // constant ids
95
+ ID fields_const_id;
96
+ ID transport_ivar_id;
97
+ ID strict_read_ivar_id;
98
+ ID strict_write_ivar_id;
99
+
100
+ // cached symbols
101
+ VALUE type_sym;
102
+ VALUE name_sym;
103
+ VALUE key_sym;
104
+ VALUE value_sym;
105
+ VALUE element_sym;
106
+ VALUE class_sym;
107
+ VALUE protocol_exception_class;
108
+
109
+ void Init_thrift_native() {
110
+ // cached classes
111
+ thrift_module = rb_const_get(rb_cObject, rb_intern("Thrift"));
112
+ thrift_bytes_module = rb_const_get(thrift_module, rb_intern("Bytes"));
113
+ thrift_types_module = rb_const_get(thrift_module, rb_intern("Types"));
114
+ rb_cSet = rb_const_get(rb_cObject, rb_intern("Set"));
115
+ protocol_exception_class = rb_const_get(thrift_module, rb_intern("ProtocolException"));
116
+
117
+ // Init ttype constants
118
+ TTYPE_BOOL = FIX2INT(rb_const_get(thrift_types_module, rb_intern("BOOL")));
119
+ TTYPE_BYTE = FIX2INT(rb_const_get(thrift_types_module, rb_intern("BYTE")));
120
+ TTYPE_I16 = FIX2INT(rb_const_get(thrift_types_module, rb_intern("I16")));
121
+ TTYPE_I32 = FIX2INT(rb_const_get(thrift_types_module, rb_intern("I32")));
122
+ TTYPE_I64 = FIX2INT(rb_const_get(thrift_types_module, rb_intern("I64")));
123
+ TTYPE_DOUBLE = FIX2INT(rb_const_get(thrift_types_module, rb_intern("DOUBLE")));
124
+ TTYPE_STRING = FIX2INT(rb_const_get(thrift_types_module, rb_intern("STRING")));
125
+ TTYPE_MAP = FIX2INT(rb_const_get(thrift_types_module, rb_intern("MAP")));
126
+ TTYPE_SET = FIX2INT(rb_const_get(thrift_types_module, rb_intern("SET")));
127
+ TTYPE_LIST = FIX2INT(rb_const_get(thrift_types_module, rb_intern("LIST")));
128
+ TTYPE_STRUCT = FIX2INT(rb_const_get(thrift_types_module, rb_intern("STRUCT")));
129
+
130
+ // method ids
131
+ validate_method_id = rb_intern("validate");
132
+ write_struct_begin_method_id = rb_intern("write_struct_begin");
133
+ write_struct_end_method_id = rb_intern("write_struct_end");
134
+ write_field_begin_method_id = rb_intern("write_field_begin");
135
+ write_field_end_method_id = rb_intern("write_field_end");
136
+ write_boolean_method_id = rb_intern("write_bool");
137
+ write_byte_method_id = rb_intern("write_byte");
138
+ write_i16_method_id = rb_intern("write_i16");
139
+ write_i32_method_id = rb_intern("write_i32");
140
+ write_i64_method_id = rb_intern("write_i64");
141
+ write_double_method_id = rb_intern("write_double");
142
+ write_string_method_id = rb_intern("write_string");
143
+ write_map_begin_method_id = rb_intern("write_map_begin");
144
+ write_map_end_method_id = rb_intern("write_map_end");
145
+ write_list_begin_method_id = rb_intern("write_list_begin");
146
+ write_list_end_method_id = rb_intern("write_list_end");
147
+ write_set_begin_method_id = rb_intern("write_set_begin");
148
+ write_set_end_method_id = rb_intern("write_set_end");
149
+ read_bool_method_id = rb_intern("read_bool");
150
+ read_byte_method_id = rb_intern("read_byte");
151
+ read_i16_method_id = rb_intern("read_i16");
152
+ read_i32_method_id = rb_intern("read_i32");
153
+ read_i64_method_id = rb_intern("read_i64");
154
+ read_string_method_id = rb_intern("read_string");
155
+ read_double_method_id = rb_intern("read_double");
156
+ read_map_begin_method_id = rb_intern("read_map_begin");
157
+ read_map_end_method_id = rb_intern("read_map_end");
158
+ read_list_begin_method_id = rb_intern("read_list_begin");
159
+ read_list_end_method_id = rb_intern("read_list_end");
160
+ read_set_begin_method_id = rb_intern("read_set_begin");
161
+ read_set_end_method_id = rb_intern("read_set_end");
162
+ read_struct_begin_method_id = rb_intern("read_struct_begin");
163
+ read_struct_end_method_id = rb_intern("read_struct_end");
164
+ read_field_begin_method_id = rb_intern("read_field_begin");
165
+ read_field_end_method_id = rb_intern("read_field_end");
166
+ keys_method_id = rb_intern("keys");
167
+ entries_method_id = rb_intern("entries");
168
+ write_field_stop_method_id = rb_intern("write_field_stop");
169
+ skip_method_id = rb_intern("skip");
170
+ write_method_id = rb_intern("write");
171
+ read_all_method_id = rb_intern("read_all");
172
+ read_into_buffer_method_id = rb_intern("read_into_buffer");
173
+ force_binary_encoding_id = rb_intern("force_binary_encoding");
174
+ convert_to_utf8_byte_buffer_id = rb_intern("convert_to_utf8_byte_buffer");
175
+ convert_to_string_id = rb_intern("convert_to_string");
176
+
177
+ // constant ids
178
+ fields_const_id = rb_intern("FIELDS");
179
+ transport_ivar_id = rb_intern("@trans");
180
+ strict_read_ivar_id = rb_intern("@strict_read");
181
+ strict_write_ivar_id = rb_intern("@strict_write");
182
+
183
+ // cached symbols
184
+ type_sym = ID2SYM(rb_intern("type"));
185
+ name_sym = ID2SYM(rb_intern("name"));
186
+ key_sym = ID2SYM(rb_intern("key"));
187
+ value_sym = ID2SYM(rb_intern("value"));
188
+ element_sym = ID2SYM(rb_intern("element"));
189
+ class_sym = ID2SYM(rb_intern("class"));
190
+
191
+ Init_struct();
192
+ Init_binary_protocol_accelerated();
193
+ Init_compact_protocol();
194
+ Init_memory_buffer();
195
+ }
@@ -0,0 +1,66 @@
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
+ # Contains some contributions under the Thrift Software License.
20
+ # Please see doc/old-thrift-license.txt in the Thrift distribution for
21
+ # details.
22
+
23
+ $:.unshift File.dirname(__FILE__)
24
+
25
+ require 'thrift/bytes'
26
+ require 'thrift/core_ext'
27
+ require 'thrift/exceptions'
28
+ require 'thrift/types'
29
+ require 'thrift/processor'
30
+ require 'thrift/client'
31
+ require 'thrift/struct'
32
+ require 'thrift/union'
33
+ require 'thrift/struct_union'
34
+
35
+ # serializer
36
+ require 'thrift/serializer/serializer'
37
+ require 'thrift/serializer/deserializer'
38
+
39
+ # protocol
40
+ require 'thrift/protocol/base_protocol'
41
+ require 'thrift/protocol/binary_protocol'
42
+ require 'thrift/protocol/binary_protocol_accelerated'
43
+ require 'thrift/protocol/compact_protocol'
44
+ require 'thrift/protocol/json_protocol'
45
+
46
+ # transport
47
+ require 'thrift/transport/base_transport'
48
+ require 'thrift/transport/base_server_transport'
49
+ require 'thrift/transport/socket'
50
+ require 'thrift/transport/server_socket'
51
+ require 'thrift/transport/unix_socket'
52
+ require 'thrift/transport/unix_server_socket'
53
+ require 'thrift/transport/buffered_transport'
54
+ require 'thrift/transport/framed_transport'
55
+ require 'thrift/transport/http_client_transport'
56
+ require 'thrift/transport/io_stream_transport'
57
+ require 'thrift/transport/memory_buffer_transport'
58
+
59
+ # server
60
+ require 'thrift/server/base_server'
61
+ require 'thrift/server/nonblocking_server'
62
+ require 'thrift/server/simple_server'
63
+ require 'thrift/server/threaded_server'
64
+ require 'thrift/server/thread_pool_server'
65
+
66
+ require 'thrift/thrift_native'
@@ -0,0 +1,131 @@
1
+ # encoding: ascii-8bit
2
+ #
3
+ # Licensed to the Apache Software Foundation (ASF) under one
4
+ # or more contributor license agreements. See the NOTICE file
5
+ # distributed with this work for additional information
6
+ # regarding copyright ownership. The ASF licenses this file
7
+ # to you under the Apache License, Version 2.0 (the
8
+ # "License"); you may not use this file except in compliance
9
+ # with the License. You may obtain a copy of the License at
10
+ #
11
+ # http://www.apache.org/licenses/LICENSE-2.0
12
+ #
13
+ # Unless required by applicable law or agreed to in writing,
14
+ # software distributed under the License is distributed on an
15
+ # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16
+ # KIND, either express or implied. See the License for the
17
+ # specific language governing permissions and limitations
18
+ # under the License.
19
+ #
20
+
21
+ module Thrift
22
+ # A collection of utilities for working with bytes and byte buffers.
23
+ module Bytes
24
+ if RUBY_VERSION >= '1.9'
25
+ # Creates and empty byte buffer (String with BINARY encoding)
26
+ #
27
+ # size - The Integer size of the buffer (default: nil) to create
28
+ #
29
+ # Returns a String with BINARY encoding, filled with null characters
30
+ # if size is greater than zero
31
+ def self.empty_byte_buffer(size = nil)
32
+ if (size && size > 0)
33
+ "\0".force_encoding(Encoding::BINARY) * size
34
+ else
35
+ ''.force_encoding(Encoding::BINARY)
36
+ end
37
+ end
38
+
39
+ # Forces the encoding of the buffer to BINARY. If the buffer
40
+ # passed is frozen, then it will be duplicated.
41
+ #
42
+ # buffer - The String to force the encoding of.
43
+ #
44
+ # Returns the String passed with an encoding of BINARY; returned
45
+ # String may be a duplicate.
46
+ def self.force_binary_encoding(buffer)
47
+ buffer = buffer.dup if buffer.frozen?
48
+ buffer.force_encoding(Encoding::BINARY)
49
+ end
50
+
51
+ # Gets the byte value of a given position in a String.
52
+ #
53
+ # string - The String to retrive the byte value from.
54
+ # index - The Integer location of the byte value to retrieve.
55
+ #
56
+ # Returns an Integer value between 0 and 255.
57
+ def self.get_string_byte(string, index)
58
+ string.getbyte(index)
59
+ end
60
+
61
+ # Sets the byte value given to a given index in a String.
62
+ #
63
+ # string - The String to set the byte value in.
64
+ # index - The Integer location to set the byte value at.
65
+ # byte - The Integer value (0 to 255) to set in the string.
66
+ #
67
+ # Returns an Integer value of the byte value to set.
68
+ def self.set_string_byte(string, index, byte)
69
+ string.setbyte(index, byte)
70
+ end
71
+
72
+ # Converts the given String to a UTF-8 byte buffer.
73
+ #
74
+ # string - The String to convert.
75
+ #
76
+ # Returns a new String with BINARY encoding, containing the UTF-8
77
+ # bytes of the original string.
78
+ def self.convert_to_utf8_byte_buffer(string)
79
+ if string.encoding != Encoding::UTF_8
80
+ # transcode to UTF-8
81
+ string = string.encode(Encoding::UTF_8)
82
+ else
83
+ # encoding is already UTF-8, but a duplicate is needed
84
+ string = string.dup
85
+ end
86
+ string.force_encoding(Encoding::BINARY)
87
+ end
88
+
89
+ # Converts the given UTF-8 byte buffer into a String
90
+ #
91
+ # utf8_buffer - A String, with BINARY encoding, containing UTF-8 bytes
92
+ #
93
+ # Returns a new String with UTF-8 encoding,
94
+ def self.convert_to_string(utf8_buffer)
95
+ # duplicate the buffer, force encoding to UTF-8
96
+ utf8_buffer.dup.force_encoding(Encoding::UTF_8)
97
+ end
98
+ else
99
+ def self.empty_byte_buffer(size = nil)
100
+ if (size && size > 0)
101
+ "\0" * size
102
+ else
103
+ ''
104
+ end
105
+ end
106
+
107
+ def self.force_binary_encoding(buffer)
108
+ buffer
109
+ end
110
+
111
+ def self.get_string_byte(string, index)
112
+ string[index]
113
+ end
114
+
115
+ def self.set_string_byte(string, index, byte)
116
+ string[index] = byte
117
+ end
118
+
119
+ def self.convert_to_utf8_byte_buffer(string)
120
+ # This assumes $KCODE is 'UTF8'/'U', which would mean the String is already a UTF-8 byte buffer
121
+ # TODO consider handling other $KCODE values and transcoding with iconv
122
+ string
123
+ end
124
+
125
+ def self.convert_to_string(utf8_buffer)
126
+ # See comment in 'convert_to_utf8_byte_buffer' for relevant assumptions.
127
+ utf8_buffer
128
+ end
129
+ end
130
+ end
131
+ end
@@ -0,0 +1,62 @@
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
+ module Thrift
21
+ module Client
22
+ def initialize(iprot, oprot=nil)
23
+ @iprot = iprot
24
+ @oprot = oprot || iprot
25
+ @seqid = 0
26
+ end
27
+
28
+ def send_message(name, args_class, args = {})
29
+ @oprot.write_message_begin(name, MessageTypes::CALL, @seqid)
30
+ data = args_class.new
31
+ args.each do |k, v|
32
+ data.send("#{k.to_s}=", v)
33
+ end
34
+ begin
35
+ data.write(@oprot)
36
+ rescue StandardError => e
37
+ @oprot.trans.close
38
+ raise e
39
+ end
40
+ @oprot.write_message_end
41
+ @oprot.trans.flush
42
+ end
43
+
44
+ def receive_message(result_klass)
45
+ fname, mtype, rseqid = @iprot.read_message_begin
46
+ handle_exception(mtype)
47
+ result = result_klass.new
48
+ result.read(@iprot)
49
+ @iprot.read_message_end
50
+ result
51
+ end
52
+
53
+ def handle_exception(mtype)
54
+ if mtype == MessageTypes::EXCEPTION
55
+ x = ApplicationException.new
56
+ x.read(@iprot)
57
+ @iprot.read_message_end
58
+ raise x
59
+ end
60
+ end
61
+ end
62
+ end