Module: BERTRPC::Encodes

Included in:
Action
Defined in:
lib/bertrpc/encodes.rb

Instance Method Summary collapse

Instance Method Details

#decode_bert_response(bert_response) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/bertrpc/encodes.rb', line 7

def decode_bert_response(bert_response)
  ruby_response = BERT.decode(bert_response)
  case ruby_response[0]
    when :reply
      ruby_response[1]
    when :noreply
      nil
    when :error
      error(ruby_response[1])
    else
      raise
  end
end

#encode_ruby_request(ruby_request) ⇒ Object



3
4
5
# File 'lib/bertrpc/encodes.rb', line 3

def encode_ruby_request(ruby_request)
  BERT.encode(ruby_request)
end

#error(err) ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/bertrpc/encodes.rb', line 21

def error(err)
  level, code, klass, message, backtrace = err

  case level
    when :protocol
      raise ProtocolError.new([code, message], klass, backtrace)
    when :server
      raise ServerError.new([code, message], klass, backtrace)
    when :user
      raise UserError.new([code, message], klass, backtrace)
    when :proxy
      raise ProxyError.new([code, message], klass, backtrace)
    else
      raise
  end
end