From fd2138bde283b7b5d8f4fe3ca7b70fb669022d18 Mon Sep 17 00:00:00 2001 From: Ray Slakinski Date: Thu, 4 Oct 2012 10:19:02 -0400 Subject: [PATCH] start of a ruby sample --- ruby/client.rb | 4 + ruby/helloworld/hello_world.rb | 131 ++++++++++++++++++++++++ ruby/helloworld/helloworld_constants.rb | 16 +++ ruby/helloworld/helloworld_types.rb | 25 +++++ ruby/server.rb | 0 5 files changed, 176 insertions(+) create mode 100644 ruby/client.rb create mode 100644 ruby/helloworld/hello_world.rb create mode 100644 ruby/helloworld/helloworld_constants.rb create mode 100644 ruby/helloworld/helloworld_types.rb create mode 100644 ruby/server.rb diff --git a/ruby/client.rb b/ruby/client.rb new file mode 100644 index 0000000..0f82f75 --- /dev/null +++ b/ruby/client.rb @@ -0,0 +1,4 @@ +$:.push('helloworld') + +require 'thrift' +require 'hello_world' diff --git a/ruby/helloworld/hello_world.rb b/ruby/helloworld/hello_world.rb new file mode 100644 index 0000000..8037d9b --- /dev/null +++ b/ruby/helloworld/hello_world.rb @@ -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 + diff --git a/ruby/helloworld/helloworld_constants.rb b/ruby/helloworld/helloworld_constants.rb new file mode 100644 index 0000000..08524be --- /dev/null +++ b/ruby/helloworld/helloworld_constants.rb @@ -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!" + diff --git a/ruby/helloworld/helloworld_types.rb b/ruby/helloworld/helloworld_types.rb new file mode 100644 index 0000000..c51773a --- /dev/null +++ b/ruby/helloworld/helloworld_types.rb @@ -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 + diff --git a/ruby/server.rb b/ruby/server.rb new file mode 100644 index 0000000..e69de29