start of a ruby sample
This commit is contained in:
parent
b7398debab
commit
fd2138bde2
4
ruby/client.rb
Normal file
4
ruby/client.rb
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
$:.push('helloworld')
|
||||||
|
|
||||||
|
require 'thrift'
|
||||||
|
require 'hello_world'
|
131
ruby/helloworld/hello_world.rb
Normal file
131
ruby/helloworld/hello_world.rb
Normal file
@ -0,0 +1,131 @@
|
|||||||
|
#
|
||||||
|
# Autogenerated by Thrift Compiler (0.8.0)
|
||||||
|
#
|
||||||
|
# DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING
|
||||||
|
#
|
||||||
|
|
||||||
|
require 'thrift'
|
||||||
|
require 'helloworld_types'
|
||||||
|
|
||||||
|
module HelloWorld
|
||||||
|
class Client
|
||||||
|
include ::Thrift::Client
|
||||||
|
|
||||||
|
def ping()
|
||||||
|
send_ping()
|
||||||
|
return recv_ping()
|
||||||
|
end
|
||||||
|
|
||||||
|
def send_ping()
|
||||||
|
send_message('ping', Ping_args)
|
||||||
|
end
|
||||||
|
|
||||||
|
def recv_ping()
|
||||||
|
result = receive_message(Ping_result)
|
||||||
|
return result.success unless result.success.nil?
|
||||||
|
raise ::Thrift::ApplicationException.new(::Thrift::ApplicationException::MISSING_RESULT, 'ping failed: unknown result')
|
||||||
|
end
|
||||||
|
|
||||||
|
def sayHello(msg)
|
||||||
|
send_sayHello(msg)
|
||||||
|
return recv_sayHello()
|
||||||
|
end
|
||||||
|
|
||||||
|
def send_sayHello(msg)
|
||||||
|
send_message('sayHello', SayHello_args, :msg => msg)
|
||||||
|
end
|
||||||
|
|
||||||
|
def recv_sayHello()
|
||||||
|
result = receive_message(SayHello_result)
|
||||||
|
return result.success unless result.success.nil?
|
||||||
|
raise ::Thrift::ApplicationException.new(::Thrift::ApplicationException::MISSING_RESULT, 'sayHello failed: unknown result')
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
class Processor
|
||||||
|
include ::Thrift::Processor
|
||||||
|
|
||||||
|
def process_ping(seqid, iprot, oprot)
|
||||||
|
args = read_args(iprot, Ping_args)
|
||||||
|
result = Ping_result.new()
|
||||||
|
result.success = @handler.ping()
|
||||||
|
write_result(result, oprot, 'ping', seqid)
|
||||||
|
end
|
||||||
|
|
||||||
|
def process_sayHello(seqid, iprot, oprot)
|
||||||
|
args = read_args(iprot, SayHello_args)
|
||||||
|
result = SayHello_result.new()
|
||||||
|
result.success = @handler.sayHello(args.msg)
|
||||||
|
write_result(result, oprot, 'sayHello', seqid)
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
# HELPER FUNCTIONS AND STRUCTURES
|
||||||
|
|
||||||
|
class Ping_args
|
||||||
|
include ::Thrift::Struct, ::Thrift::Struct_Union
|
||||||
|
|
||||||
|
FIELDS = {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
def struct_fields; FIELDS; end
|
||||||
|
|
||||||
|
def validate
|
||||||
|
end
|
||||||
|
|
||||||
|
::Thrift::Struct.generate_accessors self
|
||||||
|
end
|
||||||
|
|
||||||
|
class Ping_result
|
||||||
|
include ::Thrift::Struct, ::Thrift::Struct_Union
|
||||||
|
SUCCESS = 0
|
||||||
|
|
||||||
|
FIELDS = {
|
||||||
|
SUCCESS => {:type => ::Thrift::Types::STRING, :name => 'success'}
|
||||||
|
}
|
||||||
|
|
||||||
|
def struct_fields; FIELDS; end
|
||||||
|
|
||||||
|
def validate
|
||||||
|
end
|
||||||
|
|
||||||
|
::Thrift::Struct.generate_accessors self
|
||||||
|
end
|
||||||
|
|
||||||
|
class SayHello_args
|
||||||
|
include ::Thrift::Struct, ::Thrift::Struct_Union
|
||||||
|
MSG = 1
|
||||||
|
|
||||||
|
FIELDS = {
|
||||||
|
MSG => {:type => ::Thrift::Types::STRUCT, :name => 'msg', :class => Message}
|
||||||
|
}
|
||||||
|
|
||||||
|
def struct_fields; FIELDS; end
|
||||||
|
|
||||||
|
def validate
|
||||||
|
end
|
||||||
|
|
||||||
|
::Thrift::Struct.generate_accessors self
|
||||||
|
end
|
||||||
|
|
||||||
|
class SayHello_result
|
||||||
|
include ::Thrift::Struct, ::Thrift::Struct_Union
|
||||||
|
SUCCESS = 0
|
||||||
|
|
||||||
|
FIELDS = {
|
||||||
|
SUCCESS => {:type => ::Thrift::Types::STRING, :name => 'success'}
|
||||||
|
}
|
||||||
|
|
||||||
|
def struct_fields; FIELDS; end
|
||||||
|
|
||||||
|
def validate
|
||||||
|
end
|
||||||
|
|
||||||
|
::Thrift::Struct.generate_accessors self
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
|
|
16
ruby/helloworld/helloworld_constants.rb
Normal file
16
ruby/helloworld/helloworld_constants.rb
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
#
|
||||||
|
# Autogenerated by Thrift Compiler (0.8.0)
|
||||||
|
#
|
||||||
|
# DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING
|
||||||
|
#
|
||||||
|
|
||||||
|
require 'helloworld_types'
|
||||||
|
|
||||||
|
HELLO_IN_ENGLISH = %q"hello!"
|
||||||
|
|
||||||
|
HELLO_IN_KOREAN = %q"an-nyoung-ha-se-yo"
|
||||||
|
|
||||||
|
HELLO_IN_FRENCH = %q"bonjour!"
|
||||||
|
|
||||||
|
HELLO_IN_JAPANESE = %q"konichiwa!"
|
||||||
|
|
25
ruby/helloworld/helloworld_types.rb
Normal file
25
ruby/helloworld/helloworld_types.rb
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
#
|
||||||
|
# Autogenerated by Thrift Compiler (0.8.0)
|
||||||
|
#
|
||||||
|
# DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING
|
||||||
|
#
|
||||||
|
|
||||||
|
|
||||||
|
class Message
|
||||||
|
include ::Thrift::Struct, ::Thrift::Struct_Union
|
||||||
|
NAME = 1
|
||||||
|
LANG = 2
|
||||||
|
|
||||||
|
FIELDS = {
|
||||||
|
NAME => {:type => ::Thrift::Types::STRING, :name => 'name'},
|
||||||
|
LANG => {:type => ::Thrift::Types::STRING, :name => 'lang', :default => %q"en", :optional => true}
|
||||||
|
}
|
||||||
|
|
||||||
|
def struct_fields; FIELDS; end
|
||||||
|
|
||||||
|
def validate
|
||||||
|
end
|
||||||
|
|
||||||
|
::Thrift::Struct.generate_accessors self
|
||||||
|
end
|
||||||
|
|
0
ruby/server.rb
Normal file
0
ruby/server.rb
Normal file
Reference in New Issue
Block a user