Module: EventMachine::Protocols::ObjectProtocol

Defined in:
lib/em/protocols/object_protocol.rb

Overview

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

Instance Method Summary (collapse)

Instance Method Details

- (Object) receive_object(obj)

Invoked with ruby objects received over the network



35
36
37
# File 'lib/em/protocols/object_protocol.rb', line 35

def receive_object obj
  # stub
end

- (Object) send_object(obj)

Sends a ruby object over the network



40
41
42
43
# File 'lib/em/protocols/object_protocol.rb', line 40

def send_object obj
  data = serializer.dump(obj)
  send_data [data.respond_to?(:bytesize) ? data.bytesize : data.size, data].pack('Na*')
end

- (Object) serializer

By default returns Marshal, override to return JSON or YAML, or any other serializer/deserializer responding to #dump and #load.



16
17
18
# File 'lib/em/protocols/object_protocol.rb', line 16

def serializer
  Marshal
end