module EventMachine::Protocols::MsgpackProtocol

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

Constants

VERSION

Public Class Methods

new() click to toggle source
Calls superclass method
# File lib/msgpack_protocol.rb, line 18
def initialize
  super
  @pac ||= MessagePack::Unpacker.new
end

Public Instance Methods

receive_data(data) click to toggle source

@private

# File lib/msgpack_protocol.rb, line 24
def receive_data data
  @pac.feed_each(data) { |obj| receive_object obj }
end
receive_object(obj) click to toggle source

Invoked with ruby objects received over the network

# File lib/msgpack_protocol.rb, line 29
def receive_object obj
  # stub
end
send_object(obj) click to toggle source

Sends a ruby object over the network

# File lib/msgpack_protocol.rb, line 34
def send_object obj
  send_data MessagePack::Packer.new.pack(obj).to_s
end