Module: EventMachine::Protocols::ObjectProtocol

### Home Classes Methods

### In Files

- lib/em/protocols/object_protocol.rb

### Methods

- #receive_data
- #receive_object
- #send_object
- #serializer

### Files

- ChangeLog
- DEFERRABLES
- EPOLL
- INSTALL
- KEYBOARD
- LEGAL
- LIGHTWEIGHT_CONCURRENCY
- PURE_RUBY
- RELEASE_NOTES
- SMTP
- SPAWNED_PROCESSES
- TODO

### Class/Module Index

Quicksearch

- EventMachine
- EventMachine
- EventMachine::Channel
- EventMachine::Completion
- EventMachine::Connection
- EventMachine::DNS
- EventMachine::DNS::Request
- EventMachine::DNS::RequestIdAlreadyUsed
- EventMachine::DNS::Resolver
- EventMachine::DNS::Socket
- EventMachine::DatagramObject
- EventMachine::DefaultDeferrable
- EventMachine::Deferrable
- EventMachine::DeferrableChildProcess
- EventMachine::Error
- EventMachine::EvmaKeyboard
- EventMachine::EvmaTCPClient
- EventMachine::EvmaTCPServer
- EventMachine::EvmaUDPSocket
- EventMachine::EvmaUNIXClient
- EventMachine::EvmaUNIXServer
- EventMachine::FileNotFoundException
- EventMachine::FileStreamer
- EventMachine::FileWatch
- EventMachine::Iterator
- EventMachine::LoopbreakReader
- EventMachine::PeriodicTimer
- EventMachine::Pool
- EventMachine::ProcessWatch
- EventMachine::Protocols
- EventMachine::Protocols
- EventMachine::Protocols::HeaderAndContentProtocol
- EventMachine::Protocols::HttpClient
- EventMachine::Protocols::HttpClient2
- EventMachine::Protocols::HttpClient2::Request
- EventMachine::Protocols::LineAndTextProtocol
- EventMachine::Protocols::LineProtocol
- EventMachine::Protocols::LineText2
- EventMachine::Protocols::Memcache
- EventMachine::Protocols::Memcache::ParserError
- EventMachine::Protocols::ObjectProtocol
- EventMachine::Protocols::Postgres3
- EventMachine::Protocols::SASLauth
- EventMachine::Protocols::SASLauthclient
- EventMachine::Protocols::SmtpClient
- EventMachine::Protocols::SmtpServer
- EventMachine::Protocols::Socks4
- EventMachine::Protocols::Stomp
- EventMachine::Protocols::Stomp::Message
- EventMachine::Protocols::TcpConnectTester
- EventMachine::Queue
- EventMachine::Reactor
- EventMachine::Selectable
- EventMachine::SpawnedProcess
- EventMachine::StreamObject
- EventMachine::SystemCmd
- EventMachine::ThreadedResource
- EventMachine::TickLoop
- EventMachine::Timer
- EventMachine::UuidGenerator
- EventMachine::YieldBlockFromSpawnedProcess
- Object
- Object::EM
- Object::P
- BufferedTokenizer
- IO
- StringIO
- TestConnection

No matching classes.

# EventMachine::Protocols::ObjectProtocol

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

### Public Instance Methods

receive_data(data) click to toggle source

@private

    # File lib/em/protocols/object_protocol.rb, line 21
    def receive_data data
      (@buf ||= '') << data

      while @buf.size >= 4
        if @buf.size >= 4+(size=@buf.unpack('N').first)
          @buf.slice!(0,4)
          receive_object serializer.load(@buf.slice!(0,size))
        else
          break
        end
      end
    end

receive_object(obj) click to toggle source

Invoked with ruby objects received over the network

    # File lib/em/protocols/object_protocol.rb, line 35
    def receive_object obj
      # stub
    end

send_object(obj) click to toggle source

Sends a ruby object over the network

    # 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

serializer() click to toggle source

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

[Validate]

Generated with the Darkfish Rdoc Generator 2.