thrift 0.23.0 → 0.25.0

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 (120) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +203 -40
  3. data/ext/binary_protocol_accelerated.c +130 -40
  4. data/ext/bytes.c +14 -0
  5. data/ext/compact_protocol.c +184 -91
  6. data/ext/constants.h +3 -0
  7. data/ext/extconf.rb +12 -4
  8. data/ext/macros.h +11 -0
  9. data/ext/memory_buffer.c +67 -12
  10. data/ext/struct.c +192 -71
  11. data/ext/thrift_native.c +7 -0
  12. data/lib/thrift/bytes.rb +6 -3
  13. data/lib/thrift/client.rb +31 -33
  14. data/lib/thrift/exceptions.rb +11 -8
  15. data/lib/thrift/multiplexed_processor.rb +17 -8
  16. data/lib/thrift/processor.rb +25 -3
  17. data/lib/thrift/protocol/base_protocol.rb +66 -31
  18. data/lib/thrift/protocol/binary_protocol.rb +80 -37
  19. data/lib/thrift/protocol/binary_protocol_accelerated.rb +7 -2
  20. data/lib/thrift/protocol/compact_protocol.rb +204 -88
  21. data/lib/thrift/protocol/header_protocol.rb +15 -3
  22. data/lib/thrift/protocol/json_protocol.rb +158 -109
  23. data/lib/thrift/protocol/multiplexed_protocol.rb +3 -3
  24. data/lib/thrift/protocol/protocol_decorator.rb +6 -2
  25. data/lib/thrift/serializer/deserializer.rb +1 -0
  26. data/lib/thrift/serializer/serializer.rb +7 -0
  27. data/lib/thrift/server/base_server.rb +11 -2
  28. data/lib/thrift/server/nonblocking_server.rb +69 -20
  29. data/lib/thrift/server/rack_application.rb +69 -0
  30. data/lib/thrift/server/simple_server.rb +27 -15
  31. data/lib/thrift/server/thin_http_server.rb +21 -44
  32. data/lib/thrift/server/thread_pool_server.rb +21 -17
  33. data/lib/thrift/server/threaded_server.rb +22 -18
  34. data/lib/thrift/struct.rb +34 -18
  35. data/lib/thrift/struct_union.rb +37 -36
  36. data/lib/thrift/thrift_native.rb +2 -1
  37. data/lib/thrift/transport/base_server_transport.rb +3 -0
  38. data/lib/thrift/transport/base_transport.rb +26 -4
  39. data/lib/thrift/transport/buffered_transport.rb +5 -4
  40. data/lib/thrift/transport/framed_transport.rb +33 -7
  41. data/lib/thrift/transport/header_transport.rb +159 -33
  42. data/lib/thrift/transport/http_client_transport.rb +28 -14
  43. data/lib/thrift/transport/io_stream_transport.rb +3 -1
  44. data/lib/thrift/transport/memory_buffer_transport.rb +14 -9
  45. data/lib/thrift/transport/server_socket.rb +10 -8
  46. data/lib/thrift/transport/socket.rb +85 -48
  47. data/lib/thrift/transport/ssl_server_socket.rb +67 -6
  48. data/lib/thrift/transport/ssl_socket.rb +73 -14
  49. data/lib/thrift/transport/unix_server_socket.rb +6 -2
  50. data/lib/thrift/transport/unix_socket.rb +5 -6
  51. data/lib/thrift/types.rb +23 -22
  52. data/lib/thrift/union.rb +21 -11
  53. data/lib/thrift/uuid.rb +9 -8
  54. data/lib/thrift.rb +40 -39
  55. metadata +7 -266
  56. data/benchmark/Benchmark.thrift +0 -24
  57. data/benchmark/benchmark.rb +0 -285
  58. data/benchmark/client.rb +0 -117
  59. data/benchmark/server.rb +0 -120
  60. data/benchmark/thin_server.rb +0 -45
  61. data/lib/thrift/server/mongrel_http_server.rb +0 -60
  62. data/spec/BaseService.thrift +0 -27
  63. data/spec/ExtendedService.thrift +0 -25
  64. data/spec/Referenced.thrift +0 -44
  65. data/spec/ThriftNamespacedSpec.thrift +0 -53
  66. data/spec/ThriftSpec.thrift +0 -187
  67. data/spec/base_protocol_spec.rb +0 -224
  68. data/spec/base_transport_spec.rb +0 -387
  69. data/spec/binary_protocol_accelerated_spec.rb +0 -46
  70. data/spec/binary_protocol_spec.rb +0 -72
  71. data/spec/binary_protocol_spec_shared.rb +0 -445
  72. data/spec/bytes_spec.rb +0 -99
  73. data/spec/client_spec.rb +0 -166
  74. data/spec/compact_protocol_spec.rb +0 -196
  75. data/spec/constants_demo_spec.rb +0 -101
  76. data/spec/exception_spec.rb +0 -140
  77. data/spec/flat_spec.rb +0 -62
  78. data/spec/header_protocol_spec.rb +0 -475
  79. data/spec/header_transport_spec.rb +0 -386
  80. data/spec/http_client_spec.rb +0 -159
  81. data/spec/json_protocol_spec.rb +0 -552
  82. data/spec/namespaced_spec.rb +0 -66
  83. data/spec/nonblocking_server_spec.rb +0 -361
  84. data/spec/processor_spec.rb +0 -79
  85. data/spec/serializer_spec.rb +0 -66
  86. data/spec/server_socket_spec.rb +0 -84
  87. data/spec/server_spec.rb +0 -186
  88. data/spec/socket_spec.rb +0 -67
  89. data/spec/socket_spec_shared.rb +0 -167
  90. data/spec/spec_helper.rb +0 -69
  91. data/spec/ssl_server_socket_spec.rb +0 -45
  92. data/spec/ssl_socket_spec.rb +0 -87
  93. data/spec/struct_nested_containers_spec.rb +0 -190
  94. data/spec/struct_spec.rb +0 -397
  95. data/spec/support/header_protocol_helper.rb +0 -54
  96. data/spec/thin_http_server_spec.rb +0 -126
  97. data/spec/types_spec.rb +0 -117
  98. data/spec/union_spec.rb +0 -272
  99. data/spec/unix_socket_spec.rb +0 -115
  100. data/spec/uuid_validation_spec.rb +0 -238
  101. data/test/fuzz/Makefile.am +0 -173
  102. data/test/fuzz/README.md +0 -149
  103. data/test/fuzz/fuzz_common.rb +0 -95
  104. data/test/fuzz/fuzz_parse_binary_protocol.rb +0 -22
  105. data/test/fuzz/fuzz_parse_binary_protocol_accelerated.rb +0 -22
  106. data/test/fuzz/fuzz_parse_binary_protocol_accelerated_harness.rb +0 -22
  107. data/test/fuzz/fuzz_parse_binary_protocol_harness.rb +0 -22
  108. data/test/fuzz/fuzz_parse_compact_protocol.rb +0 -22
  109. data/test/fuzz/fuzz_parse_compact_protocol_harness.rb +0 -22
  110. data/test/fuzz/fuzz_parse_json_protocol.rb +0 -22
  111. data/test/fuzz/fuzz_parse_json_protocol_harness.rb +0 -22
  112. data/test/fuzz/fuzz_roundtrip_binary_protocol.rb +0 -22
  113. data/test/fuzz/fuzz_roundtrip_binary_protocol_accelerated.rb +0 -22
  114. data/test/fuzz/fuzz_roundtrip_binary_protocol_accelerated_harness.rb +0 -22
  115. data/test/fuzz/fuzz_roundtrip_binary_protocol_harness.rb +0 -22
  116. data/test/fuzz/fuzz_roundtrip_compact_protocol.rb +0 -22
  117. data/test/fuzz/fuzz_roundtrip_compact_protocol_harness.rb +0 -22
  118. data/test/fuzz/fuzz_roundtrip_json_protocol.rb +0 -22
  119. data/test/fuzz/fuzz_roundtrip_json_protocol_harness.rb +0 -22
  120. data/test/fuzz/fuzz_tracer.rb +0 -28
@@ -1,44 +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
- #
21
- # Licensed to the Apache Software Foundation (ASF) under one
22
- # or more contributor license agreements. See the NOTICE file
23
- # distributed with this work for additional information
24
- # regarding copyright ownership. The ASF licenses this file
25
- # to you under the Apache License, Version 2.0 (the
26
- # "License"); you may not use this file except in compliance
27
- # with the License. You may obtain a copy of the License at
28
- #
29
- # http://www.apache.org/licenses/LICENSE-2.0
30
- #
31
- # Unless required by applicable law or agreed to in writing,
32
- # software distributed under the License is distributed on an
33
- # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
34
- # KIND, either express or implied. See the License for the
35
- # specific language governing permissions and limitations
36
- # under the License.
37
- #
38
-
39
- namespace rb OtherNamespace
40
-
41
- enum SomeEnum {
42
- ONE
43
- TWO
44
- }
@@ -1,53 +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
- #
21
- # Licensed to the Apache Software Foundation (ASF) under one
22
- # or more contributor license agreements. See the NOTICE file
23
- # distributed with this work for additional information
24
- # regarding copyright ownership. The ASF licenses this file
25
- # to you under the Apache License, Version 2.0 (the
26
- # "License"); you may not use this file except in compliance
27
- # with the License. You may obtain a copy of the License at
28
- #
29
- # http://www.apache.org/licenses/LICENSE-2.0
30
- #
31
- # Unless required by applicable law or agreed to in writing,
32
- # software distributed under the License is distributed on an
33
- # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
34
- # KIND, either express or implied. See the License for the
35
- # specific language governing permissions and limitations
36
- # under the License.
37
- #
38
-
39
- namespace rb NamespacedSpecNamespace
40
-
41
- include "Referenced.thrift"
42
-
43
- struct Hello {
44
- 1: string greeting = "hello world"
45
- }
46
-
47
- service NamespacedNonblockingService {
48
- Hello greeting(1:bool english)
49
- bool block()
50
- oneway void unblock(1:i32 n)
51
- oneway void shutdown()
52
- void sleep(1:double seconds)
53
- }
@@ -1,187 +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
- #
21
- # Licensed to the Apache Software Foundation (ASF) under one
22
- # or more contributor license agreements. See the NOTICE file
23
- # distributed with this work for additional information
24
- # regarding copyright ownership. The ASF licenses this file
25
- # to you under the Apache License, Version 2.0 (the
26
- # "License"); you may not use this file except in compliance
27
- # with the License. You may obtain a copy of the License at
28
- #
29
- # http://www.apache.org/licenses/LICENSE-2.0
30
- #
31
- # Unless required by applicable law or agreed to in writing,
32
- # software distributed under the License is distributed on an
33
- # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
34
- # KIND, either express or implied. See the License for the
35
- # specific language governing permissions and limitations
36
- # under the License.
37
- #
38
-
39
- namespace rb SpecNamespace
40
-
41
- struct Hello {
42
- 1: string greeting = "hello world"
43
- }
44
-
45
- enum SomeEnum {
46
- ONE
47
- TWO
48
- }
49
-
50
- struct StructWithSomeEnum {
51
- 1: SomeEnum some_enum;
52
- }
53
-
54
- union TestUnion {
55
- /**
56
- * A doc string
57
- */
58
- 1: string string_field;
59
- 2: i32 i32_field;
60
- 3: i32 other_i32_field;
61
- 4: SomeEnum enum_field;
62
- 5: binary binary_field;
63
- 6: uuid uuid_field;
64
- }
65
-
66
- struct Foo {
67
- 1: i32 simple = 53,
68
- 2: string words = "words",
69
- 3: Hello hello = {'greeting' : "hello, world!"},
70
- 4: list<i32> ints = [1, 2, 2, 3],
71
- 5: map<i32, map<string, double>> complex,
72
- 6: set<i16> shorts = [5, 17, 239],
73
- 7: optional string opt_string
74
- 8: bool my_bool
75
- 9: optional uuid opt_uuid
76
- }
77
-
78
- struct Foo2 {
79
- 1: binary my_binary
80
- }
81
-
82
- struct BoolStruct {
83
- 1: bool yesno = 1
84
- }
85
-
86
- struct SimpleList {
87
- 1: list<bool> bools,
88
- 2: list<byte> bytes,
89
- 3: list<i16> i16s,
90
- 4: list<i32> i32s,
91
- 5: list<i64> i64s,
92
- 6: list<double> doubles,
93
- 7: list<string> strings,
94
- 8: list<map<i16, i16>> maps,
95
- 9: list<list<i16>> lists,
96
- 10: list<set<i16>> sets,
97
- 11: list<Hello> hellos,
98
- 12: list<uuid> uuids
99
- }
100
-
101
- exception Xception {
102
- 1: string message,
103
- 2: i32 code = 1
104
- }
105
-
106
- service NonblockingService {
107
- Hello greeting(1:bool english)
108
- bool block()
109
- oneway void unblock(1:i32 n)
110
- oneway void shutdown()
111
- void sleep(1:double seconds)
112
- }
113
-
114
- union My_union {
115
- 1: bool im_true,
116
- 2: byte a_bite,
117
- 3: i16 integer16,
118
- 4: i32 integer32,
119
- 5: i64 integer64,
120
- 6: double double_precision,
121
- 7: string some_characters,
122
- 8: i32 other_i32
123
- 9: SomeEnum some_enum;
124
- 10: map<SomeEnum, list<SomeEnum>> my_map;
125
- 11: uuid unique_id;
126
- }
127
-
128
- struct Struct_with_union {
129
- 1: My_union fun_union
130
- 2: i32 integer32
131
- 3: string some_characters
132
- }
133
-
134
- struct StructWithEnumMap {
135
- 1: map<SomeEnum, list<SomeEnum>> my_map;
136
- }
137
-
138
- # Nested lists
139
- struct NestedListInList {
140
- 1: list<list<byte>> value
141
- }
142
-
143
- struct NestedListInSet {
144
- 1: set<list<byte>> value
145
- }
146
-
147
- struct NestedListInMapKey {
148
- 1: map<list<byte>, byte> value
149
- }
150
-
151
- struct NestedListInMapValue {
152
- 1: map<byte, list<byte>> value
153
- }
154
-
155
- # Nested sets
156
- struct NestedSetInList {
157
- 1: list<set<byte>> value
158
- }
159
-
160
- struct NestedSetInSet {
161
- 1: set<set<byte>> value
162
- }
163
-
164
- struct NestedSetInMapKey {
165
- 1: map<set<byte>, byte> value
166
- }
167
-
168
- struct NestedSetInMapValue {
169
- 1: map<byte, set<byte>> value
170
- }
171
-
172
- # Nested maps
173
- struct NestedMapInList {
174
- 1: list<map<byte, byte>> value
175
- }
176
-
177
- struct NestedMapInSet {
178
- 1: set<map<byte, byte>> value
179
- }
180
-
181
- struct NestedMapInMapKey {
182
- 2: map<map<byte, byte>, byte> value
183
- }
184
-
185
- struct NestedMapInMapValue {
186
- 2: map<byte, map<byte, byte>> value
187
- }
@@ -1,224 +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
- require 'spec_helper'
21
-
22
- describe 'BaseProtocol' do
23
- before(:each) do
24
- @trans = double("MockTransport")
25
- @prot = Thrift::BaseProtocol.new(@trans)
26
- end
27
-
28
- describe Thrift::BaseProtocol do
29
- # most of the methods are stubs, so we can ignore them
30
-
31
- it "should provide a reasonable to_s" do
32
- expect(@trans).to receive(:to_s).once.and_return("trans")
33
- expect(@prot.to_s).to eq("trans")
34
- end
35
-
36
- it "should make trans accessible" do
37
- expect(@prot.trans).to eql(@trans)
38
- end
39
-
40
- it 'should write out a field nicely (deprecated write_field signature)' do
41
- expect(@prot).to receive(:write_field_begin).with('field', 'type', 'fid').ordered
42
- expect(@prot).to receive(:write_type).with({:name => 'field', :type => 'type'}, 'value').ordered
43
- expect(@prot).to receive(:write_field_end).ordered
44
- @prot.write_field('field', 'type', 'fid', 'value')
45
- end
46
-
47
- it 'should write out a field nicely' do
48
- expect(@prot).to receive(:write_field_begin).with('field', 'type', 'fid').ordered
49
- expect(@prot).to receive(:write_type).with({:name => 'field', :type => 'type', :binary => false}, 'value').ordered
50
- expect(@prot).to receive(:write_field_end).ordered
51
- @prot.write_field({:name => 'field', :type => 'type', :binary => false}, 'fid', 'value')
52
- end
53
-
54
- it 'should write out the different types (deprecated write_type signature)' do
55
- expect(@prot).to receive(:write_bool).with('bool').ordered
56
- expect(@prot).to receive(:write_byte).with('byte').ordered
57
- expect(@prot).to receive(:write_double).with('double').ordered
58
- expect(@prot).to receive(:write_i16).with('i16').ordered
59
- expect(@prot).to receive(:write_i32).with('i32').ordered
60
- expect(@prot).to receive(:write_i64).with('i64').ordered
61
- expect(@prot).to receive(:write_string).with('string').ordered
62
- struct = double('Struct')
63
- expect(struct).to receive(:write).with(@prot).ordered
64
- @prot.write_type(Thrift::Types::BOOL, 'bool')
65
- @prot.write_type(Thrift::Types::BYTE, 'byte')
66
- @prot.write_type(Thrift::Types::DOUBLE, 'double')
67
- @prot.write_type(Thrift::Types::I16, 'i16')
68
- @prot.write_type(Thrift::Types::I32, 'i32')
69
- @prot.write_type(Thrift::Types::I64, 'i64')
70
- @prot.write_type(Thrift::Types::STRING, 'string')
71
- @prot.write_type(Thrift::Types::STRUCT, struct)
72
- # all other types are not implemented
73
- [Thrift::Types::STOP, Thrift::Types::VOID, Thrift::Types::MAP, Thrift::Types::SET, Thrift::Types::LIST].each do |type|
74
- expect { @prot.write_type(type, type.to_s) }.to raise_error(NotImplementedError)
75
- end
76
- end
77
-
78
- it 'should write out the different types' do
79
- expect(@prot).to receive(:write_bool).with('bool').ordered
80
- expect(@prot).to receive(:write_byte).with('byte').ordered
81
- expect(@prot).to receive(:write_double).with('double').ordered
82
- expect(@prot).to receive(:write_i16).with('i16').ordered
83
- expect(@prot).to receive(:write_i32).with('i32').ordered
84
- expect(@prot).to receive(:write_i64).with('i64').ordered
85
- expect(@prot).to receive(:write_string).with('string').ordered
86
- expect(@prot).to receive(:write_binary).with('binary').ordered
87
- struct = double('Struct')
88
- expect(struct).to receive(:write).with(@prot).ordered
89
- @prot.write_type({:type => Thrift::Types::BOOL}, 'bool')
90
- @prot.write_type({:type => Thrift::Types::BYTE}, 'byte')
91
- @prot.write_type({:type => Thrift::Types::DOUBLE}, 'double')
92
- @prot.write_type({:type => Thrift::Types::I16}, 'i16')
93
- @prot.write_type({:type => Thrift::Types::I32}, 'i32')
94
- @prot.write_type({:type => Thrift::Types::I64}, 'i64')
95
- @prot.write_type({:type => Thrift::Types::STRING}, 'string')
96
- @prot.write_type({:type => Thrift::Types::STRING, :binary => true}, 'binary')
97
- @prot.write_type({:type => Thrift::Types::STRUCT}, struct)
98
- # all other types are not implemented
99
- [Thrift::Types::STOP, Thrift::Types::VOID, Thrift::Types::MAP, Thrift::Types::SET, Thrift::Types::LIST].each do |type|
100
- expect { @prot.write_type({:type => type}, type.to_s) }.to raise_error(NotImplementedError)
101
- end
102
- end
103
-
104
- it 'should read the different types (deprecated read_type signature)' do
105
- expect(@prot).to receive(:read_bool).ordered
106
- expect(@prot).to receive(:read_byte).ordered
107
- expect(@prot).to receive(:read_i16).ordered
108
- expect(@prot).to receive(:read_i32).ordered
109
- expect(@prot).to receive(:read_i64).ordered
110
- expect(@prot).to receive(:read_double).ordered
111
- expect(@prot).to receive(:read_string).ordered
112
- @prot.read_type(Thrift::Types::BOOL)
113
- @prot.read_type(Thrift::Types::BYTE)
114
- @prot.read_type(Thrift::Types::I16)
115
- @prot.read_type(Thrift::Types::I32)
116
- @prot.read_type(Thrift::Types::I64)
117
- @prot.read_type(Thrift::Types::DOUBLE)
118
- @prot.read_type(Thrift::Types::STRING)
119
- # all other types are not implemented
120
- [Thrift::Types::STOP, Thrift::Types::VOID, Thrift::Types::MAP,
121
- Thrift::Types::SET, Thrift::Types::LIST, Thrift::Types::STRUCT].each do |type|
122
- expect { @prot.read_type(type) }.to raise_error(NotImplementedError)
123
- end
124
- end
125
-
126
- it 'should read the different types' do
127
- expect(@prot).to receive(:read_bool).ordered
128
- expect(@prot).to receive(:read_byte).ordered
129
- expect(@prot).to receive(:read_i16).ordered
130
- expect(@prot).to receive(:read_i32).ordered
131
- expect(@prot).to receive(:read_i64).ordered
132
- expect(@prot).to receive(:read_double).ordered
133
- expect(@prot).to receive(:read_string).ordered
134
- expect(@prot).to receive(:read_binary).ordered
135
- @prot.read_type({:type => Thrift::Types::BOOL})
136
- @prot.read_type({:type => Thrift::Types::BYTE})
137
- @prot.read_type({:type => Thrift::Types::I16})
138
- @prot.read_type({:type => Thrift::Types::I32})
139
- @prot.read_type({:type => Thrift::Types::I64})
140
- @prot.read_type({:type => Thrift::Types::DOUBLE})
141
- @prot.read_type({:type => Thrift::Types::STRING})
142
- @prot.read_type({:type => Thrift::Types::STRING, :binary => true})
143
- # all other types are not implemented
144
- [Thrift::Types::STOP, Thrift::Types::VOID, Thrift::Types::MAP,
145
- Thrift::Types::SET, Thrift::Types::LIST, Thrift::Types::STRUCT].each do |type|
146
- expect { @prot.read_type({:type => type}) }.to raise_error(NotImplementedError)
147
- end
148
- end
149
-
150
- it "should skip the basic types" do
151
- expect(@prot).to receive(:read_bool).ordered
152
- expect(@prot).to receive(:read_byte).ordered
153
- expect(@prot).to receive(:read_i16).ordered
154
- expect(@prot).to receive(:read_i32).ordered
155
- expect(@prot).to receive(:read_i64).ordered
156
- expect(@prot).to receive(:read_double).ordered
157
- expect(@prot).to receive(:read_string).ordered
158
- @prot.skip(Thrift::Types::BOOL)
159
- @prot.skip(Thrift::Types::BYTE)
160
- @prot.skip(Thrift::Types::I16)
161
- @prot.skip(Thrift::Types::I32)
162
- @prot.skip(Thrift::Types::I64)
163
- @prot.skip(Thrift::Types::DOUBLE)
164
- @prot.skip(Thrift::Types::STRING)
165
- end
166
-
167
- it "should skip structs" do
168
- real_skip = @prot.method(:skip)
169
- expect(@prot).to receive(:read_struct_begin).ordered
170
- expect(@prot).to receive(:read_field_begin).exactly(4).times.and_return(
171
- ['field 1', Thrift::Types::STRING, 1],
172
- ['field 2', Thrift::Types::I32, 2],
173
- ['field 3', Thrift::Types::MAP, 3],
174
- [nil, Thrift::Types::STOP, 0]
175
- )
176
- expect(@prot).to receive(:read_field_end).exactly(3).times
177
- expect(@prot).to receive(:read_string).exactly(3).times
178
- expect(@prot).to receive(:read_i32).ordered
179
- expect(@prot).to receive(:read_map_begin).ordered.and_return([Thrift::Types::STRING, Thrift::Types::STRING, 1])
180
- # @prot.should_receive(:read_string).exactly(2).times
181
- expect(@prot).to receive(:read_map_end).ordered
182
- expect(@prot).to receive(:read_struct_end).ordered
183
- real_skip.call(Thrift::Types::STRUCT)
184
- end
185
-
186
- it "should skip maps" do
187
- real_skip = @prot.method(:skip)
188
- expect(@prot).to receive(:read_map_begin).ordered.and_return([Thrift::Types::STRING, Thrift::Types::STRUCT, 1])
189
- expect(@prot).to receive(:read_string).ordered
190
- expect(@prot).to receive(:read_struct_begin).ordered.and_return(["some_struct"])
191
- expect(@prot).to receive(:read_field_begin).ordered.and_return([nil, Thrift::Types::STOP, nil]);
192
- expect(@prot).to receive(:read_struct_end).ordered
193
- expect(@prot).to receive(:read_map_end).ordered
194
- real_skip.call(Thrift::Types::MAP)
195
- end
196
-
197
- it "should skip sets" do
198
- real_skip = @prot.method(:skip)
199
- expect(@prot).to receive(:read_set_begin).ordered.and_return([Thrift::Types::I64, 9])
200
- expect(@prot).to receive(:read_i64).ordered.exactly(9).times
201
- expect(@prot).to receive(:read_set_end)
202
- real_skip.call(Thrift::Types::SET)
203
- end
204
-
205
- it "should skip lists" do
206
- real_skip = @prot.method(:skip)
207
- expect(@prot).to receive(:read_list_begin).ordered.and_return([Thrift::Types::DOUBLE, 11])
208
- expect(@prot).to receive(:read_double).ordered.exactly(11).times
209
- expect(@prot).to receive(:read_list_end)
210
- real_skip.call(Thrift::Types::LIST)
211
- end
212
- end
213
-
214
- describe Thrift::BaseProtocolFactory do
215
- it "should raise NotImplementedError" do
216
- # returning nil since Protocol is just an abstract class
217
- expect { Thrift::BaseProtocolFactory.new.get_protocol(double("MockTransport")) }.to raise_error(NotImplementedError)
218
- end
219
-
220
- it "should provide a reasonable to_s" do
221
- expect(Thrift::BaseProtocolFactory.new.to_s).to eq("base")
222
- end
223
- end
224
- end