Module: Bones::RPC::Adapter::Erlang

Defined in:
lib/bones/rpc/adapter/erlang.rb

Instance Method Summary collapse

Instance Method Details

#pack(message, buffer = "") ⇒ Object



11
12
13
14
15
16
# File 'lib/bones/rpc/adapter/erlang.rb', line 11

def pack(message, buffer="")
  data = ::Erlang.term_to_binary(message)
  len = data.bytesize
  buffer << [len].pack('N')
  buffer << data
end

#unpack(buffer) ⇒ Object



18
19
20
21
22
# File 'lib/bones/rpc/adapter/erlang.rb', line 18

def unpack(buffer)
  len, = buffer.read(4).unpack('N')
  data = buffer.read(len)
  ::Erlang.binary_to_term(data)
end