class ThriftClient::Simple::ThriftService

Public Class Methods

_arg_structs() click to toggle source
# File lib/thrift_client/simple.rb, line 240
def self._arg_structs
  @_arg_structs = {} if @_arg_structs.nil?
  @_arg_structs
end
new(sock) click to toggle source
# File lib/thrift_client/simple.rb, line 236
def initialize(sock)
  @sock = sock
end
thrift_method(name, rtype, *args) click to toggle source
# File lib/thrift_client/simple.rb, line 245
def self.thrift_method(name, rtype, *args)
  arg_struct = ThriftClient::Simple.make_struct("Args__#{self.name}__#{name}", *args)
  rv_struct = ThriftClient::Simple.make_struct("Retval__#{self.name}__#{name}", ThriftClient::Simple::Field.new(:rv, rtype, 0))
  _arg_structs[name.to_sym] = [ arg_struct, rv_struct ]

  arg_names = args.map { |a| a.name.to_s }.join(", ")
  class_eval "def #{name}(#{arg_names}); _proxy(:#{name}#{args.size > 0 ? ', ' : ''}#{arg_names}); end"
end

Public Instance Methods

_proxy(method_name, *args) click to toggle source
# File lib/thrift_client/simple.rb, line 254
def _proxy(method_name, *args)
  cls = self.class.ancestors.find { |cls| cls.respond_to?(:_arg_structs) and cls._arg_structs[method_name.to_sym] }
  arg_class, rv_class = cls._arg_structs[method_name.to_sym]
  arg_struct = arg_class.new(*args)
  @sock.write(ThriftClient::Simple.pack_request(method_name, arg_struct))
  rv = ThriftClient::Simple.read_response(@sock, rv_class)
  rv[2]
end