class Protobuf::Rpc::Middleware::RequestDecoder

Attributes

app[R]
env[R]

Public Class Methods

new(app) click to toggle source
# File lib/protobuf/rpc/middleware/request_decoder.rb, line 9
def initialize(app)
  @app = app
end

Public Instance Methods

_call(env) click to toggle source
# File lib/protobuf/rpc/middleware/request_decoder.rb, line 17
def _call(env)
  @env = env

  logger.debug { sign_message("Decoding request: #{env.encoded_request}") }
  env.service_name = service_name
  env.method_name = method_name
  env.request = request
  env.request_wrapper = request_wrapper
  env.client_host = request_wrapper.caller

  env.rpc_service = service
  env.rpc_method = rpc_method
  env.request_type = rpc_method.request_type
  env.response_type = rpc_method.response_type

  app.call(env)
end
call(env) click to toggle source
# File lib/protobuf/rpc/middleware/request_decoder.rb, line 13
def call(env)
  dup._call(env)
end
log_signature() click to toggle source
Calls superclass method Protobuf::Logging#log_signature
# File lib/protobuf/rpc/middleware/request_decoder.rb, line 35
def log_signature
  env.log_signature || super
end

Private Instance Methods

method_name() click to toggle source
# File lib/protobuf/rpc/middleware/request_decoder.rb, line 41
def method_name
  return @method_name unless @method_name.nil?

  @method_name = request_wrapper.method_name.underscore.to_sym
  fail MethodNotFound, "#{service.name}##{@method_name} is not a defined RPC method." unless service.rpc_method?(@method_name)
  @method_name
end
request() click to toggle source
# File lib/protobuf/rpc/middleware/request_decoder.rb, line 49
def request
  @request ||= rpc_method.request_type.decode(request_wrapper.request_proto)
rescue => exception
  raise BadRequestData, "Unable to decode request: #{exception.message}"
end
request_wrapper() click to toggle source

Decode the incoming request object into our expected request object

# File lib/protobuf/rpc/middleware/request_decoder.rb, line 57
def request_wrapper
  @request_wrapper ||= ::Protobuf::Socketrpc::Request.decode(env.encoded_request)
rescue => exception
  raise BadRequestData, "Unable to decode request: #{exception.message}"
end
rpc_method() click to toggle source
# File lib/protobuf/rpc/middleware/request_decoder.rb, line 63
def rpc_method
  @rpc_method ||= service.rpcs[method_name]
end
service() click to toggle source
# File lib/protobuf/rpc/middleware/request_decoder.rb, line 67
def service
  @service ||= service_name.constantize
rescue NameError
  raise ServiceNotFound, "Service class #{service_name} is not defined."
end
service_name() click to toggle source
# File lib/protobuf/rpc/middleware/request_decoder.rb, line 73
def service_name
  @service_name ||= request_wrapper.service_name
end