thrift 0.24.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.
- checksums.yaml +4 -4
- data/README.md +107 -4
- data/ext/binary_protocol_accelerated.c +52 -17
- data/ext/compact_protocol.c +135 -70
- data/ext/constants.h +3 -0
- data/ext/extconf.rb +4 -4
- data/ext/macros.h +11 -0
- data/ext/memory_buffer.c +35 -17
- data/ext/struct.c +185 -64
- data/ext/thrift_native.c +6 -0
- data/lib/thrift/bytes.rb +2 -2
- data/lib/thrift/client.rb +31 -22
- data/lib/thrift/exceptions.rb +10 -8
- data/lib/thrift/multiplexed_processor.rb +5 -6
- data/lib/thrift/processor.rb +24 -3
- data/lib/thrift/protocol/base_protocol.rb +53 -27
- data/lib/thrift/protocol/binary_protocol.rb +54 -40
- data/lib/thrift/protocol/binary_protocol_accelerated.rb +6 -2
- data/lib/thrift/protocol/compact_protocol.rb +193 -88
- data/lib/thrift/protocol/header_protocol.rb +14 -3
- data/lib/thrift/protocol/json_protocol.rb +146 -104
- data/lib/thrift/protocol/multiplexed_protocol.rb +2 -3
- data/lib/thrift/protocol/protocol_decorator.rb +5 -2
- data/lib/thrift/serializer/serializer.rb +6 -0
- data/lib/thrift/server/base_server.rb +10 -2
- data/lib/thrift/server/nonblocking_server.rb +49 -26
- data/lib/thrift/server/rack_application.rb +69 -0
- data/lib/thrift/server/simple_server.rb +27 -23
- data/lib/thrift/server/thin_http_server.rb +20 -44
- data/lib/thrift/server/thread_pool_server.rb +20 -17
- data/lib/thrift/server/threaded_server.rb +22 -26
- data/lib/thrift/struct.rb +33 -18
- data/lib/thrift/struct_union.rb +36 -30
- data/lib/thrift/transport/base_transport.rb +23 -5
- data/lib/thrift/transport/buffered_transport.rb +4 -4
- data/lib/thrift/transport/framed_transport.rb +32 -7
- data/lib/thrift/transport/header_transport.rb +130 -50
- data/lib/thrift/transport/http_client_transport.rb +27 -14
- data/lib/thrift/transport/io_stream_transport.rb +2 -1
- data/lib/thrift/transport/memory_buffer_transport.rb +8 -10
- data/lib/thrift/transport/server_socket.rb +4 -5
- data/lib/thrift/transport/socket.rb +20 -22
- data/lib/thrift/transport/ssl_server_socket.rb +64 -4
- data/lib/thrift/transport/ssl_socket.rb +32 -5
- data/lib/thrift/transport/unix_server_socket.rb +1 -1
- data/lib/thrift/transport/unix_socket.rb +4 -6
- data/lib/thrift/types.rb +22 -22
- data/lib/thrift/union.rb +20 -11
- data/lib/thrift/uuid.rb +8 -8
- data/lib/thrift.rb +39 -39
- metadata +5 -230
- data/benchmark/Benchmark.thrift +0 -24
- data/benchmark/benchmark.rb +0 -286
- data/benchmark/client.rb +0 -118
- data/benchmark/server.rb +0 -121
- data/benchmark/thin_server.rb +0 -46
- data/lib/thrift/server/mongrel_http_server.rb +0 -61
- data/spec/BaseService.thrift +0 -27
- data/spec/ExtendedService.thrift +0 -25
- data/spec/Referenced.thrift +0 -44
- data/spec/ThriftNamespacedSpec.thrift +0 -53
- data/spec/ThriftSpec.thrift +0 -203
- data/spec/base_protocol_spec.rb +0 -244
- data/spec/base_transport_spec.rb +0 -428
- data/spec/binary_protocol_accelerated_spec.rb +0 -47
- data/spec/binary_protocol_spec.rb +0 -73
- data/spec/binary_protocol_spec_shared.rb +0 -509
- data/spec/bytes_spec.rb +0 -117
- data/spec/client_spec.rb +0 -167
- data/spec/compact_protocol_spec.rb +0 -295
- data/spec/constants_demo_spec.rb +0 -102
- data/spec/exception_spec.rb +0 -141
- data/spec/flat_spec.rb +0 -63
- data/spec/header_protocol_spec.rb +0 -476
- data/spec/header_transport_spec.rb +0 -431
- data/spec/http_client_spec.rb +0 -160
- data/spec/json_protocol_spec.rb +0 -574
- data/spec/multiplexed_processor_spec.rb +0 -75
- data/spec/namespaced_spec.rb +0 -67
- data/spec/nonblocking_server_spec.rb +0 -429
- data/spec/processor_spec.rb +0 -80
- data/spec/recursion_depth_spec.rb +0 -223
- data/spec/serializer_spec.rb +0 -67
- data/spec/server_socket_spec.rb +0 -121
- data/spec/server_spec.rb +0 -238
- data/spec/socket_spec.rb +0 -174
- data/spec/socket_spec_shared.rb +0 -168
- data/spec/spec_helper.rb +0 -70
- data/spec/ssl_server_socket_spec.rb +0 -85
- data/spec/ssl_socket_spec.rb +0 -248
- data/spec/struct_nested_containers_spec.rb +0 -191
- data/spec/struct_spec.rb +0 -398
- data/spec/support/header_protocol_helper.rb +0 -55
- data/spec/thin_http_server_spec.rb +0 -127
- data/spec/types_spec.rb +0 -118
- data/spec/union_spec.rb +0 -273
- data/spec/unix_socket_spec.rb +0 -131
- data/spec/uuid_validation_spec.rb +0 -239
- data/test/fuzz/Makefile +0 -779
- data/test/fuzz/Makefile.am +0 -173
- data/test/fuzz/Makefile.in +0 -775
- data/test/fuzz/README.md +0 -149
- data/test/fuzz/fuzz_common.rb +0 -96
- data/test/fuzz/fuzz_parse_binary_protocol.rb +0 -23
- data/test/fuzz/fuzz_parse_binary_protocol_accelerated.rb +0 -23
- data/test/fuzz/fuzz_parse_binary_protocol_accelerated_harness.rb +0 -23
- data/test/fuzz/fuzz_parse_binary_protocol_harness.rb +0 -23
- data/test/fuzz/fuzz_parse_compact_protocol.rb +0 -23
- data/test/fuzz/fuzz_parse_compact_protocol_harness.rb +0 -23
- data/test/fuzz/fuzz_parse_json_protocol.rb +0 -23
- data/test/fuzz/fuzz_parse_json_protocol_harness.rb +0 -23
- data/test/fuzz/fuzz_roundtrip_binary_protocol.rb +0 -23
- data/test/fuzz/fuzz_roundtrip_binary_protocol_accelerated.rb +0 -23
- data/test/fuzz/fuzz_roundtrip_binary_protocol_accelerated_harness.rb +0 -23
- data/test/fuzz/fuzz_roundtrip_binary_protocol_harness.rb +0 -23
- data/test/fuzz/fuzz_roundtrip_compact_protocol.rb +0 -23
- data/test/fuzz/fuzz_roundtrip_compact_protocol_harness.rb +0 -23
- data/test/fuzz/fuzz_roundtrip_json_protocol.rb +0 -23
- data/test/fuzz/fuzz_roundtrip_json_protocol_harness.rb +0 -23
- data/test/fuzz/fuzz_tracer.rb +0 -29
|
@@ -19,7 +19,8 @@
|
|
|
19
19
|
# under the License.
|
|
20
20
|
#
|
|
21
21
|
|
|
22
|
-
require
|
|
22
|
+
require "io/wait"
|
|
23
|
+
require "socket"
|
|
23
24
|
|
|
24
25
|
module Thrift
|
|
25
26
|
class SSLServerSocket < ServerSocket
|
|
@@ -31,12 +32,71 @@ module Thrift
|
|
|
31
32
|
attr_accessor :ssl_context
|
|
32
33
|
|
|
33
34
|
def listen
|
|
34
|
-
|
|
35
|
-
@handle = OpenSSL::SSL::SSLServer.new(
|
|
35
|
+
tcp_server = TCPServer.new(@host, @port)
|
|
36
|
+
@handle = OpenSSL::SSL::SSLServer.new(tcp_server, @ssl_context).tap do |server|
|
|
37
|
+
server.start_immediately = false
|
|
38
|
+
end
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
def accept
|
|
42
|
+
return if @handle.nil?
|
|
43
|
+
|
|
44
|
+
transport = nil
|
|
45
|
+
ssl_socket = @handle.accept
|
|
46
|
+
deadline = Process.clock_gettime(Process::CLOCK_MONOTONIC) + @client_timeout unless @client_timeout.nil? || @client_timeout == 0
|
|
47
|
+
ssl_socket.to_io.setsockopt(::Socket::IPPROTO_TCP, ::Socket::TCP_NODELAY, 1)
|
|
48
|
+
accept_ssl_socket(ssl_socket, deadline)
|
|
49
|
+
|
|
50
|
+
transport = Socket.new.tap do |accepted_transport|
|
|
51
|
+
accepted_transport.timeout = @client_timeout
|
|
52
|
+
accepted_transport.handle = ssl_socket
|
|
53
|
+
end
|
|
54
|
+
ensure
|
|
55
|
+
# Thread#kill leaves $! nil, but marks the thread as aborting.
|
|
56
|
+
close_accepted_socket(ssl_socket) if transport.nil? || $! || Thread.current.status == "aborting"
|
|
36
57
|
end
|
|
37
58
|
|
|
38
59
|
def to_s
|
|
39
|
-
"ssl(#{super
|
|
60
|
+
"ssl(#{super})"
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
private
|
|
64
|
+
|
|
65
|
+
def accept_ssl_socket(ssl_socket, deadline)
|
|
66
|
+
return ssl_socket.accept unless deadline
|
|
67
|
+
|
|
68
|
+
loop do
|
|
69
|
+
case ssl_socket.accept_nonblock(exception: false)
|
|
70
|
+
when ssl_socket
|
|
71
|
+
return ssl_socket
|
|
72
|
+
when :wait_readable
|
|
73
|
+
wait_for_handshake(ssl_socket, :read, deadline)
|
|
74
|
+
when :wait_writable
|
|
75
|
+
wait_for_handshake(ssl_socket, :write, deadline)
|
|
76
|
+
else
|
|
77
|
+
raise TransportException.new(TransportException::NOT_OPEN, "SSL server socket: Unexpected TLS handshake result")
|
|
78
|
+
end
|
|
79
|
+
end
|
|
80
|
+
end
|
|
81
|
+
|
|
82
|
+
def wait_for_handshake(ssl_socket, direction, deadline)
|
|
83
|
+
remaining = deadline - Process.clock_gettime(Process::CLOCK_MONOTONIC)
|
|
84
|
+
ready = if remaining > 0
|
|
85
|
+
if direction == :read
|
|
86
|
+
ssl_socket.to_io.wait_readable(remaining)
|
|
87
|
+
else
|
|
88
|
+
ssl_socket.to_io.wait_writable(remaining)
|
|
89
|
+
end
|
|
90
|
+
end
|
|
91
|
+
return if ready
|
|
92
|
+
|
|
93
|
+
raise OpenSSL::SSL::SSLError, "SSL server socket: Timed out accepting TLS connection"
|
|
94
|
+
end
|
|
95
|
+
|
|
96
|
+
def close_accepted_socket(ssl_socket)
|
|
97
|
+
ssl_socket&.close
|
|
98
|
+
rescue StandardError
|
|
99
|
+
nil
|
|
40
100
|
end
|
|
41
101
|
end
|
|
42
102
|
end
|
|
@@ -18,23 +18,28 @@
|
|
|
18
18
|
# specific language governing permissions and limitations
|
|
19
19
|
# under the License.
|
|
20
20
|
|
|
21
|
-
require
|
|
21
|
+
require "io/wait"
|
|
22
|
+
require "ipaddr"
|
|
22
23
|
|
|
23
24
|
module Thrift
|
|
24
25
|
class SSLSocket < Socket
|
|
25
|
-
def initialize(host =
|
|
26
|
+
def initialize(host = "localhost", port = 9090, timeout = nil, ssl_context = nil, server_hostname: host)
|
|
26
27
|
super(host, port, timeout)
|
|
27
28
|
@ssl_context = ssl_context
|
|
29
|
+
@server_hostname = server_hostname
|
|
28
30
|
end
|
|
29
31
|
|
|
30
32
|
attr_accessor :ssl_context
|
|
33
|
+
attr_accessor :server_hostname
|
|
31
34
|
|
|
32
35
|
def open
|
|
33
36
|
deadline = Process.clock_gettime(Process::CLOCK_MONOTONIC) + @timeout unless @timeout.nil? || @timeout == 0
|
|
34
37
|
socket = connect_socket(deadline)
|
|
35
38
|
|
|
36
39
|
begin
|
|
37
|
-
|
|
40
|
+
ssl_context = configured_ssl_context
|
|
41
|
+
ssl_socket = OpenSSL::SSL::SSLSocket.new(socket, ssl_context)
|
|
42
|
+
ssl_socket.hostname = @server_hostname if send_server_hostname?
|
|
38
43
|
ssl_socket.sync_close = true
|
|
39
44
|
@handle = ssl_socket
|
|
40
45
|
|
|
@@ -63,7 +68,7 @@ module Thrift
|
|
|
63
68
|
@handle.connect
|
|
64
69
|
end
|
|
65
70
|
|
|
66
|
-
@handle.post_connection_check(
|
|
71
|
+
@handle.post_connection_check(server_hostname_for_verification)
|
|
67
72
|
@handle
|
|
68
73
|
rescue TransportException
|
|
69
74
|
close_socket(@handle)
|
|
@@ -77,7 +82,29 @@ module Thrift
|
|
|
77
82
|
end
|
|
78
83
|
|
|
79
84
|
def to_s
|
|
80
|
-
"ssl(#{super
|
|
85
|
+
"ssl(#{super})"
|
|
86
|
+
end
|
|
87
|
+
|
|
88
|
+
private
|
|
89
|
+
|
|
90
|
+
def configured_ssl_context
|
|
91
|
+
@ssl_context ||= OpenSSL::SSL::SSLContext.new.tap do |context|
|
|
92
|
+
context.verify_mode = OpenSSL::SSL::VERIFY_PEER
|
|
93
|
+
context.cert_store = OpenSSL::X509::Store.new.tap(&:set_default_paths)
|
|
94
|
+
end
|
|
95
|
+
end
|
|
96
|
+
|
|
97
|
+
def send_server_hostname?
|
|
98
|
+
return false if @server_hostname.nil? || @server_hostname.empty?
|
|
99
|
+
|
|
100
|
+
IPAddr.new(@server_hostname)
|
|
101
|
+
false
|
|
102
|
+
rescue IPAddr::InvalidAddressError
|
|
103
|
+
true
|
|
104
|
+
end
|
|
105
|
+
|
|
106
|
+
def server_hostname_for_verification
|
|
107
|
+
@server_hostname.nil? || @server_hostname.empty? ? @host : @server_hostname
|
|
81
108
|
end
|
|
82
109
|
end
|
|
83
110
|
end
|
|
@@ -19,7 +19,7 @@
|
|
|
19
19
|
# under the License.
|
|
20
20
|
#
|
|
21
21
|
|
|
22
|
-
require
|
|
22
|
+
require "socket"
|
|
23
23
|
|
|
24
24
|
module Thrift
|
|
25
25
|
class UNIXSocket < Socket
|
|
@@ -31,11 +31,9 @@ module Thrift
|
|
|
31
31
|
end
|
|
32
32
|
|
|
33
33
|
def open
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
raise TransportException.new(TransportException::NOT_OPEN, "Could not open UNIX socket at #{@path}")
|
|
38
|
-
end
|
|
34
|
+
@handle = ::UNIXSocket.new(@path)
|
|
35
|
+
rescue StandardError
|
|
36
|
+
raise TransportException.new(TransportException::NOT_OPEN, "Could not open UNIX socket at #{@path}")
|
|
39
37
|
end
|
|
40
38
|
|
|
41
39
|
def to_s
|
data/lib/thrift/types.rb
CHANGED
|
@@ -18,7 +18,7 @@
|
|
|
18
18
|
# under the License.
|
|
19
19
|
#
|
|
20
20
|
|
|
21
|
-
require
|
|
21
|
+
require "set"
|
|
22
22
|
|
|
23
23
|
module Thrift
|
|
24
24
|
module Types
|
|
@@ -48,27 +48,27 @@ module Thrift
|
|
|
48
48
|
def self.check_type(value, field, name, skip_nil = true)
|
|
49
49
|
return if value.nil? and skip_nil
|
|
50
50
|
klasses = case field[:type]
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
51
|
+
when Types::VOID
|
|
52
|
+
NilClass
|
|
53
|
+
when Types::BOOL
|
|
54
|
+
[TrueClass, FalseClass]
|
|
55
|
+
when Types::BYTE, Types::I16, Types::I32, Types::I64
|
|
56
|
+
Integer
|
|
57
|
+
when Types::DOUBLE
|
|
58
|
+
Float
|
|
59
|
+
when Types::STRING
|
|
60
|
+
String
|
|
61
|
+
when Types::UUID
|
|
62
|
+
String
|
|
63
|
+
when Types::STRUCT
|
|
64
|
+
[Struct, Union]
|
|
65
|
+
when Types::MAP
|
|
66
|
+
Hash
|
|
67
|
+
when Types::SET
|
|
68
|
+
Set
|
|
69
|
+
when Types::LIST
|
|
70
|
+
Array
|
|
71
|
+
end
|
|
72
72
|
valid = klasses && [*klasses].any? { |klass| klass === value }
|
|
73
73
|
raise TypeError, "Expected #{type_name(field[:type])}, received #{value.class} for field #{name}" unless valid
|
|
74
74
|
# check elements now
|
data/lib/thrift/union.rb
CHANGED
|
@@ -18,6 +18,8 @@
|
|
|
18
18
|
# under the License.
|
|
19
19
|
#
|
|
20
20
|
|
|
21
|
+
require "thrift/struct_union"
|
|
22
|
+
|
|
21
23
|
module Thrift
|
|
22
24
|
class Union
|
|
23
25
|
def initialize(name = nil, value = nil)
|
|
@@ -54,13 +56,17 @@ module Thrift
|
|
|
54
56
|
end
|
|
55
57
|
end
|
|
56
58
|
|
|
57
|
-
def read(iprot)
|
|
59
|
+
def read(iprot, remaining_depth = DEFAULT_RECURSION_DEPTH)
|
|
60
|
+
raise ProtocolException.new(ProtocolException::DEPTH_LIMIT, "Maximum recursion depth exceeded") if remaining_depth <= 0
|
|
61
|
+
@setfield = nil
|
|
62
|
+
@value = nil
|
|
63
|
+
|
|
58
64
|
iprot.read_struct_begin
|
|
59
|
-
|
|
60
|
-
handle_message(iprot, fid, ftype)
|
|
65
|
+
_, ftype, fid = iprot.read_field_begin
|
|
66
|
+
handle_message(iprot, fid, ftype, remaining_depth)
|
|
61
67
|
iprot.read_field_end
|
|
62
68
|
|
|
63
|
-
|
|
69
|
+
_, ftype, _ = iprot.read_field_begin
|
|
64
70
|
unless (ftype == Types::STOP)
|
|
65
71
|
raise ProtocolException.new(ProtocolException::INVALID_DATA, "Too many fields for union")
|
|
66
72
|
end
|
|
@@ -69,11 +75,12 @@ module Thrift
|
|
|
69
75
|
validate
|
|
70
76
|
end
|
|
71
77
|
|
|
72
|
-
def write(oprot)
|
|
78
|
+
def write(oprot, remaining_depth = DEFAULT_RECURSION_DEPTH)
|
|
79
|
+
raise ProtocolException.new(ProtocolException::DEPTH_LIMIT, "Maximum recursion depth exceeded") if remaining_depth <= 0
|
|
73
80
|
validate
|
|
74
81
|
oprot.write_struct_begin(self.class.name)
|
|
75
82
|
|
|
76
|
-
fid =
|
|
83
|
+
fid = name_to_id(@setfield.to_s)
|
|
77
84
|
|
|
78
85
|
field_info = struct_fields[fid]
|
|
79
86
|
unless field_info
|
|
@@ -83,8 +90,10 @@ module Thrift
|
|
|
83
90
|
type = field_info[:type]
|
|
84
91
|
if is_container? type
|
|
85
92
|
oprot.write_field_begin(@setfield, type, fid)
|
|
86
|
-
write_container(oprot, @value, field_info)
|
|
93
|
+
write_container(oprot, @value, field_info, remaining_depth)
|
|
87
94
|
oprot.write_field_end
|
|
95
|
+
elsif type == Types::STRUCT
|
|
96
|
+
oprot.write_field(field_info, fid, @value, remaining_depth)
|
|
88
97
|
else
|
|
89
98
|
oprot.write_field(@setfield, type, fid, @value)
|
|
90
99
|
end
|
|
@@ -94,7 +103,7 @@ module Thrift
|
|
|
94
103
|
end
|
|
95
104
|
|
|
96
105
|
def ==(other)
|
|
97
|
-
other.equal?(self) || other.instance_of?(self.class) && @setfield == other.get_set_field && @value == other.get_value
|
|
106
|
+
other.equal?(self) || (other.instance_of?(self.class) && @setfield == other.get_set_field && @value == other.get_value)
|
|
98
107
|
end
|
|
99
108
|
alias_method :eql?, :==
|
|
100
109
|
|
|
@@ -107,7 +116,7 @@ module Thrift
|
|
|
107
116
|
if field_info[:name].to_sym == @setfield
|
|
108
117
|
@value
|
|
109
118
|
else
|
|
110
|
-
raise
|
|
119
|
+
raise "#{field_info[:name]} is not union's set field."
|
|
111
120
|
end
|
|
112
121
|
end
|
|
113
122
|
|
|
@@ -169,10 +178,10 @@ module Thrift
|
|
|
169
178
|
|
|
170
179
|
protected
|
|
171
180
|
|
|
172
|
-
def handle_message(iprot, fid, ftype)
|
|
181
|
+
def handle_message(iprot, fid, ftype, remaining_depth)
|
|
173
182
|
field = struct_fields[fid]
|
|
174
183
|
if field and field[:type] == ftype
|
|
175
|
-
@value = read_field(iprot, field)
|
|
184
|
+
@value = read_field(iprot, field, remaining_depth)
|
|
176
185
|
name = field[:name].to_sym
|
|
177
186
|
@setfield = name
|
|
178
187
|
else
|
data/lib/thrift/uuid.rb
CHANGED
|
@@ -18,32 +18,32 @@
|
|
|
18
18
|
# under the License.
|
|
19
19
|
#
|
|
20
20
|
|
|
21
|
-
require
|
|
21
|
+
require "thrift/protocol/base_protocol"
|
|
22
22
|
|
|
23
23
|
module Thrift
|
|
24
24
|
module UUID
|
|
25
|
-
UUID_REGEX = /\A[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}\z
|
|
25
|
+
UUID_REGEX = /\A[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}\z/
|
|
26
26
|
|
|
27
27
|
def self.validate_uuid!(uuid)
|
|
28
28
|
unless uuid.is_a?(String)
|
|
29
|
-
raise ProtocolException.new(ProtocolException::INVALID_DATA,
|
|
29
|
+
raise ProtocolException.new(ProtocolException::INVALID_DATA, "UUID must be a string")
|
|
30
30
|
end
|
|
31
31
|
|
|
32
|
-
unless uuid
|
|
33
|
-
raise ProtocolException.new(ProtocolException::INVALID_DATA,
|
|
32
|
+
unless UUID_REGEX.match?(uuid)
|
|
33
|
+
raise ProtocolException.new(ProtocolException::INVALID_DATA, "Invalid UUID format")
|
|
34
34
|
end
|
|
35
35
|
end
|
|
36
36
|
|
|
37
37
|
def self.uuid_bytes(uuid)
|
|
38
|
-
[uuid.delete(
|
|
38
|
+
[uuid.delete("-")].pack("H*")
|
|
39
39
|
end
|
|
40
40
|
|
|
41
41
|
def self.uuid_from_bytes(bytes)
|
|
42
42
|
unless bytes.bytesize == 16
|
|
43
|
-
raise ProtocolException.new(ProtocolException::INVALID_DATA,
|
|
43
|
+
raise ProtocolException.new(ProtocolException::INVALID_DATA, "Invalid UUID data length")
|
|
44
44
|
end
|
|
45
45
|
|
|
46
|
-
hex = bytes.
|
|
46
|
+
hex = bytes.unpack1("H*")
|
|
47
47
|
"#{hex[0, 8]}-#{hex[8, 4]}-#{hex[12, 4]}-#{hex[16, 4]}-#{hex[20, 12]}"
|
|
48
48
|
end
|
|
49
49
|
end
|
data/lib/thrift.rb
CHANGED
|
@@ -23,51 +23,51 @@
|
|
|
23
23
|
|
|
24
24
|
$:.unshift File.dirname(__FILE__)
|
|
25
25
|
|
|
26
|
-
require
|
|
27
|
-
require
|
|
28
|
-
require
|
|
29
|
-
require
|
|
30
|
-
require
|
|
31
|
-
require
|
|
32
|
-
require
|
|
33
|
-
require
|
|
34
|
-
require
|
|
35
|
-
require
|
|
26
|
+
require "thrift/bytes"
|
|
27
|
+
require "thrift/exceptions"
|
|
28
|
+
require "thrift/types"
|
|
29
|
+
require "thrift/processor"
|
|
30
|
+
require "thrift/multiplexed_processor"
|
|
31
|
+
require "thrift/client"
|
|
32
|
+
require "thrift/struct"
|
|
33
|
+
require "thrift/union"
|
|
34
|
+
require "thrift/struct_union"
|
|
35
|
+
require "thrift/uuid"
|
|
36
36
|
|
|
37
37
|
# serializer
|
|
38
|
-
require
|
|
39
|
-
require
|
|
38
|
+
require "thrift/serializer/serializer"
|
|
39
|
+
require "thrift/serializer/deserializer"
|
|
40
40
|
|
|
41
41
|
# protocol
|
|
42
|
-
require
|
|
43
|
-
require
|
|
44
|
-
require
|
|
45
|
-
require
|
|
46
|
-
require
|
|
47
|
-
require
|
|
48
|
-
require
|
|
42
|
+
require "thrift/protocol/base_protocol"
|
|
43
|
+
require "thrift/protocol/binary_protocol"
|
|
44
|
+
require "thrift/protocol/binary_protocol_accelerated"
|
|
45
|
+
require "thrift/protocol/compact_protocol"
|
|
46
|
+
require "thrift/protocol/json_protocol"
|
|
47
|
+
require "thrift/protocol/multiplexed_protocol"
|
|
48
|
+
require "thrift/protocol/header_protocol"
|
|
49
49
|
|
|
50
50
|
# transport
|
|
51
|
-
require
|
|
52
|
-
require
|
|
53
|
-
require
|
|
54
|
-
require
|
|
55
|
-
require
|
|
56
|
-
require
|
|
57
|
-
require
|
|
58
|
-
require
|
|
59
|
-
require
|
|
60
|
-
require
|
|
61
|
-
require
|
|
62
|
-
require
|
|
63
|
-
require
|
|
64
|
-
require
|
|
51
|
+
require "thrift/transport/base_transport"
|
|
52
|
+
require "thrift/transport/base_server_transport"
|
|
53
|
+
require "thrift/transport/socket"
|
|
54
|
+
require "thrift/transport/ssl_socket"
|
|
55
|
+
require "thrift/transport/server_socket"
|
|
56
|
+
require "thrift/transport/ssl_server_socket"
|
|
57
|
+
require "thrift/transport/unix_socket"
|
|
58
|
+
require "thrift/transport/unix_server_socket"
|
|
59
|
+
require "thrift/transport/buffered_transport"
|
|
60
|
+
require "thrift/transport/framed_transport"
|
|
61
|
+
require "thrift/transport/header_transport"
|
|
62
|
+
require "thrift/transport/http_client_transport"
|
|
63
|
+
require "thrift/transport/io_stream_transport"
|
|
64
|
+
require "thrift/transport/memory_buffer_transport"
|
|
65
65
|
|
|
66
66
|
# server
|
|
67
|
-
require
|
|
68
|
-
require
|
|
69
|
-
require
|
|
70
|
-
require
|
|
71
|
-
require
|
|
67
|
+
require "thrift/server/base_server"
|
|
68
|
+
require "thrift/server/nonblocking_server"
|
|
69
|
+
require "thrift/server/simple_server"
|
|
70
|
+
require "thrift/server/threaded_server"
|
|
71
|
+
require "thrift/server/thread_pool_server"
|
|
72
72
|
|
|
73
|
-
require
|
|
73
|
+
require "thrift/thrift_native"
|