Module: EventMachine::Protocols::MsgpackProtocol
- Defined in:
- lib/msgpack_protocol.rb
Overview
MsgpackProtocol allows for easy communication using marshaled ruby objects
module RubyServer
include EM::P::MsgpackProtocol
def receive_object obj
send_object({'you said' => obj})
end
end
Constant Summary collapse
- VERSION =
'0.0.1'
Instance Method Summary collapse
- #initialize ⇒ Object
- #receive_data(data) ⇒ Object
-
#receive_object(obj) ⇒ Object
Invoked with ruby objects received over the network.
-
#send_object(obj) ⇒ Object
Sends a ruby object over the network.
Instance Method Details
#initialize ⇒ Object
18 19 20 21 |
# File 'lib/msgpack_protocol.rb', line 18 def initialize super @pac ||= MessagePack::Unpacker.new end |
#receive_data(data) ⇒ Object
24 25 26 |
# File 'lib/msgpack_protocol.rb', line 24 def receive_data data @pac.feed_each(data) { |obj| receive_object obj } end |
#receive_object(obj) ⇒ Object
Invoked with ruby objects received over the network
29 30 31 |
# File 'lib/msgpack_protocol.rb', line 29 def receive_object obj # stub end |
#send_object(obj) ⇒ Object
Sends a ruby object over the network
34 35 36 |
# File 'lib/msgpack_protocol.rb', line 34 def send_object obj send_data MessagePack::Packer.new.pack(obj).to_s end |