Sha256: 0b6927a64e58ac555abb4aa91a7b0637772f0c4dce9a8f19cb332ceea619da3f

Contents?: true

Size: 1.16 KB

Versions: 140

Compression:

Stored size: 1.16 KB

Contents

module EventMachine
  module Protocols
    # 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
    #
    module ObjectProtocol
      # By default returns Marshal, override to return JSON or YAML, or any
      # other serializer/deserializer responding to #dump and #load.
      def serializer
        Marshal
      end

      # @private
      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

      # Invoked with ruby objects received over the network
      def receive_object obj
        # stub
      end

      # Sends a ruby object over the network
      def send_object obj
        data = serializer.dump(obj)
        send_data [data.respond_to?(:bytesize) ? data.bytesize : data.size, data].pack('Na*')
      end
    end
  end
end

Version data entries

140 entries across 137 versions & 11 rubygems

Version Path
devcycle-ruby-server-sdk-1.1.0 examples/sinatra/vendor/bundle/ruby/3.0.0/gems/eventmachine-1.2.7/lib/em/protocols/object_protocol.rb
devcycle-ruby-server-sdk-1.1.0 examples/sinatra/vendor/bundle/ruby/3.1.0/gems/eventmachine-1.2.7/lib/em/protocols/object_protocol.rb
devcycle-ruby-server-sdk-1.1.0 examples/sinatra/vendor/bundle/ruby/2.6.0/gems/eventmachine-1.2.7/lib/em/protocols/object_protocol.rb
eventmachine-mkroman-1.3.0.dev.1 lib/em/protocols/object_protocol.rb
wj_eventmachine-1.3.2 lib/em/protocols/object_protocol.rb
wj_eventmachine-1.3.1 lib/em/protocols/object_protocol.rb
wj_eventmachine-1.3.0.dev.1 lib/em/protocols/object_protocol.rb
sensu-em-2.7.0-java lib/em/protocols/object_protocol.rb
eventmachine-1.2.7-java lib/em/protocols/object_protocol.rb
eventmachine-1.2.7-x64-mingw32 lib/em/protocols/object_protocol.rb
eventmachine-1.2.7-x86-mingw32 lib/em/protocols/object_protocol.rb
eventmachine-1.2.7 lib/em/protocols/object_protocol.rb
eventmachine-1.2.6-x64-mingw32 lib/em/protocols/object_protocol.rb
eventmachine-1.2.6-x86-mingw32 lib/em/protocols/object_protocol.rb
eventmachine-1.2.6-java lib/em/protocols/object_protocol.rb
eventmachine-1.2.6 lib/em/protocols/object_protocol.rb
eventmachine-1.2.5-x86-mingw32 lib/em/protocols/object_protocol.rb
eventmachine-1.2.5-x64-mingw32 lib/em/protocols/object_protocol.rb
eventmachine-1.2.5-java lib/em/protocols/object_protocol.rb
eventmachine-1.2.5 lib/em/protocols/object_protocol.rb