protobuf-rpc-register 0.4.1 → 0.4.2
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/lib/protobuf/rpc/clients/base.rb +19 -6
- data/lib/protobuf/rpc/register/version.rb +1 -1
- data/lib/protobuf/rpc/serializer.rb +3 -0
- metadata +1 -1
    
        checksums.yaml
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            ---
         | 
| 2 2 | 
             
            SHA1:
         | 
| 3 | 
            -
              metadata.gz:  | 
| 4 | 
            -
              data.tar.gz:  | 
| 3 | 
            +
              metadata.gz: db71b6ff98bdd94c7a855de0374b81b0d7fd8a58
         | 
| 4 | 
            +
              data.tar.gz: 9a60f0893f84f3f9bc748e99d1db6c8e7aad4b97
         | 
| 5 5 | 
             
            SHA512:
         | 
| 6 | 
            -
              metadata.gz:  | 
| 7 | 
            -
              data.tar.gz:  | 
| 6 | 
            +
              metadata.gz: b05063712e2f79ac0af00e3d270b9d691d44e7c1987575cbf19a06aa6a42f1dea863ca82c0282b2193306d689eda819f0e14eb31dc0e196a4c4b23228a13b8d8
         | 
| 7 | 
            +
              data.tar.gz: c17fe1a97f2ac8662a27ffaa546998e8f77af06d66f186935453bd92bee878cccbbf6aae7232b218896837ab8c5ffe4257e6c64da1ff227f9ba08d4497384f19
         | 
| @@ -3,22 +3,23 @@ module Protobuf | |
| 3 3 | 
             
                module Clients
         | 
| 4 4 | 
             
                  class Base
         | 
| 5 5 | 
             
                    attr_accessor :logger, :error_logger
         | 
| 6 | 
            +
                    attr_accessor :host, :port, :timeout
         | 
| 6 7 |  | 
| 7 8 | 
             
                    mattr_reader(:mutex) { Mutex.new }
         | 
| 8 9 |  | 
| 9 10 | 
             
                    def initialize(host: nil, port: nil, timeout: 1, stdout: STDOUT, stderr: STDERR, namespace: nil)
         | 
| 11 | 
            +
                      @host = host
         | 
| 12 | 
            +
                      @port = port
         | 
| 13 | 
            +
                      @timeout = timeout
         | 
| 10 14 | 
             
                      @namespace = namespace
         | 
| 11 15 | 
             
                      @logger ||= Logger.new(stdout)
         | 
| 12 16 | 
             
                      @error_logger ||= Logger.new(stderr)
         | 
| 13 17 | 
             
                    end
         | 
| 14 18 |  | 
| 15 | 
            -
                    def send_rpc_request(method, msg)
         | 
| 19 | 
            +
                    def send_rpc_request(method, msg, serializer: serializer)
         | 
| 16 20 | 
             
                      res = nil
         | 
| 17 21 |  | 
| 18 | 
            -
                       | 
| 19 | 
            -
                      svc_class = [names[0..-3], 'Services', names[-1]].flatten.join('::')
         | 
| 20 | 
            -
             | 
| 21 | 
            -
                      Object.const_get(svc_class).client(host: host, port: port, timeout: timeout).send(method, Serializer.dump(msg)) do |c|
         | 
| 22 | 
            +
                      internal_client.send(method, Serializer.dump(msg, serializer: serializer)) do |c|
         | 
| 22 23 | 
             
                        c.on_success do |rpc_compressed_message|
         | 
| 23 24 | 
             
                          res = Protobuf::Rpc::Serializer.load(rpc_compressed_message)
         | 
| 24 25 | 
             
                        end
         | 
| @@ -50,6 +51,14 @@ module Protobuf | |
| 50 51 |  | 
| 51 52 | 
             
                    private
         | 
| 52 53 |  | 
| 54 | 
            +
                    def internal_client
         | 
| 55 | 
            +
                      @internal_client ||= begin
         | 
| 56 | 
            +
                        names = self.class.name.split('::')
         | 
| 57 | 
            +
                        svc_class = [names[0..-3], 'Services', names[-1]].flatten.join('::')
         | 
| 58 | 
            +
                        Object.const_get(svc_class).client(host: host, port: port, timeout: timeout)
         | 
| 59 | 
            +
                      end
         | 
| 60 | 
            +
                    end
         | 
| 61 | 
            +
             | 
| 53 62 | 
             
                    def define_error_class(res)
         | 
| 54 63 | 
             
                      module_name = (@namespace || 'Protobuf').camelize
         | 
| 55 64 | 
             
                      m = Object.const_defined?(module_name, false) ? Object.const_get(module_name, false) : Object.const_set(module_name, Module.new)
         | 
| @@ -100,13 +109,17 @@ module Protobuf | |
| 100 109 | 
             
                      define_method(rpc_method) do |*args|
         | 
| 101 110 | 
             
                        msg = if args.first.is_a?(Protobuf::Message)
         | 
| 102 111 | 
             
                                args.shift
         | 
| 112 | 
            +
                              elsif args.first.respond_to?(:to_hash)
         | 
| 113 | 
            +
                                Messages::RpcCompressedMessage.new(response_body: ActiveSupport::Gzip.compress(args.first.to_hash.to_json),
         | 
| 114 | 
            +
                                                                   serializer: :JSON,
         | 
| 115 | 
            +
                                                                   compressed: true)
         | 
| 103 116 | 
             
                              else
         | 
| 104 117 | 
             
                                names = self.class.name.split('::')
         | 
| 105 118 | 
             
                                msg_class = Object.const_get([names[0..-3], 'Messages', names[-1]].flatten.join('::'))
         | 
| 106 119 | 
             
                                msg_class.new(*args)
         | 
| 107 120 | 
             
                              end
         | 
| 108 121 |  | 
| 109 | 
            -
                        send_rpc_request(rpc_method, msg)
         | 
| 122 | 
            +
                        send_rpc_request(rpc_method, msg, serializer: :JSON)
         | 
| 110 123 | 
             
                      end
         | 
| 111 124 | 
             
                    end
         | 
| 112 125 | 
             
                  end
         | 
| @@ -80,6 +80,7 @@ module Protobuf | |
| 80 80 | 
             
                    end
         | 
| 81 81 |  | 
| 82 82 | 
             
                    def msgpack(dumped_message, msg)
         | 
| 83 | 
            +
                      require 'msgpack' unless msg.respond_to?(:to_msgpack)
         | 
| 83 84 | 
             
                      dumped_message.response_body = msg.to_msgpack
         | 
| 84 85 | 
             
                      dumped_message.serializer = :MSGPACK
         | 
| 85 86 | 
             
                    end
         | 
| @@ -91,11 +92,13 @@ module Protobuf | |
| 91 92 | 
             
                    end
         | 
| 92 93 |  | 
| 93 94 | 
             
                    def oj(dumped_message, msg)
         | 
| 95 | 
            +
                      require 'oj' unless defined?(:Oj)
         | 
| 94 96 | 
             
                      dumped_message.response_body = Oj.dump(msg)
         | 
| 95 97 | 
             
                      dumped_message.serializer = :JSON
         | 
| 96 98 | 
             
                    end
         | 
| 97 99 |  | 
| 98 100 | 
             
                    def multi_json(dumped_message, msg)
         | 
| 101 | 
            +
                      require 'multi_json' unless defined?(:MultiJson)
         | 
| 99 102 | 
             
                      dumped_message.response_body = MultiJson.dump(msg)
         | 
| 100 103 | 
             
                      dumped_message.serializer = :JSON
         | 
| 101 104 | 
             
                    end
         |