Module: Rack::BertRpc::Encoding

Included in:
Server
Defined in:
lib/rack/bert_rpc/encoding.rb

Instance Method Summary collapse

Instance Method Details

#error_response(type, error) ⇒ Object



22
23
24
25
26
27
28
29
30
31
# File 'lib/rack/bert_rpc/encoding.rb', line 22

def error_response(type, error)
  if error.is_a? String
    berpify(BERT.encode(BERT::Tuple[:error,
                          BERT::Tuple[type, 0, error]]))
  else
    berpify(BERT.encode(BERT::Tuple[:error,
                          BERT::Tuple[type, 0, error.class.to_s,
                            error.message, error.backtrace]]))
  end
end

#noreply_responseObject



37
38
39
# File 'lib/rack/bert_rpc/encoding.rb', line 37

def noreply_response
  berpify(BERT.encode(BERT::Tuple[:noreply]))
end

#read_rpc(input) ⇒ Object



13
14
15
16
17
18
19
20
# File 'lib/rack/bert_rpc/encoding.rb', line 13

def read_rpc(input)
  raw = input.read(4)
  return nil unless raw
  length = raw.unpack('N').first
  return nil unless length
  bert = input.read(length)
  BERT.decode(bert)
end

#reply_response(response) ⇒ Object



33
34
35
# File 'lib/rack/bert_rpc/encoding.rb', line 33

def reply_response(response)
  berpify(BERT.encode(BERT::Tuple[:reply, response]))
end