#
# Autogenerated by Thrift
#
# DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING
#

require 'thrift'
require 'test_types'

module UserStorage
  class Client
    include ::Thrift::Client

    def store(user)
      send_store(user)
      recv_store()
    end

    def send_store(user)
      send_message('store', Store_args, :user => user)
    end

    def recv_store()
      result = receive_message(Store_result)
      return
    end

    def retrieve(uid)
      send_retrieve(uid)
      return recv_retrieve()
    end

    def send_retrieve(uid)
      send_message('retrieve', Retrieve_args, :uid => uid)
    end

    def recv_retrieve()
      result = receive_message(Retrieve_result)
      return result.success unless result.success.nil?
      raise ::Thrift::ApplicationException.new(::Thrift::ApplicationException::MISSING_RESULT, 'retrieve failed: unknown result')
    end

  end

  class Processor
    include ::Thrift::Processor

    def process_store(seqid, iprot, oprot)
      args = read_args(iprot, Store_args)
      result = Store_result.new()
      @handler.store(args.user)
      write_result(result, oprot, 'store', seqid)
    end

    def process_retrieve(seqid, iprot, oprot)
      args = read_args(iprot, Retrieve_args)
      result = Retrieve_result.new()
      result.success = @handler.retrieve(args.uid)
      write_result(result, oprot, 'retrieve', seqid)
    end

  end

  # HELPER FUNCTIONS AND STRUCTURES

  class Store_args
    include ::Thrift::Struct
    USER = 1

    ::Thrift::Struct.field_accessor self, :user
    FIELDS = {
      USER => {:type => ::Thrift::Types::STRUCT, :name => 'user', :class => UserProfile}
    }

    def struct_fields; FIELDS; end

    def validate
    end

  end

  class Store_result
    include ::Thrift::Struct

    FIELDS = {

    }

    def struct_fields; FIELDS; end

    def validate
    end

  end

  class Retrieve_args
    include ::Thrift::Struct
    UID = 1

    ::Thrift::Struct.field_accessor self, :uid
    FIELDS = {
      UID => {:type => ::Thrift::Types::I32, :name => 'uid'}
    }

    def struct_fields; FIELDS; end

    def validate
    end

  end

  class Retrieve_result
    include ::Thrift::Struct
    SUCCESS = 0

    ::Thrift::Struct.field_accessor self, :success
    FIELDS = {
      SUCCESS => {:type => ::Thrift::Types::STRUCT, :name => 'success', :class => UserProfile}
    }

    def struct_fields; FIELDS; end

    def validate
    end

  end

end

