ObjectProtocol allows for easy communication using marshaled ruby objects
module RubyServer include EM::P::ObjectProtocol def receive_object obj send_object({'you said' => obj}) end end
Invoked with ruby objects received over the network
# File lib/em/protocols/object_protocol.rb, line 34 def receive_object obj # stub end
Sends a ruby object over the network
# File lib/em/protocols/object_protocol.rb, line 39 def send_object obj data = serializer.dump(obj) send_data [data.respond_to?(:bytesize) ? data.bytesize : data.size, data].pack('Na*') end
By default returns Marshal, override to return JSON or YAML, or any other serializer/deserializer responding to dump and load.
# File lib/em/protocols/object_protocol.rb, line 16 def serializer Marshal end