Sha256: 9bd6deef8567324890bda1e0a6f5bbb3d2573bcc3be76165f7e708184a4b5e13

Contents?: true

Size: 611 Bytes

Versions: 2

Compression:

Stored size: 611 Bytes

Contents

module RubySkynet
  module Common

    # Returns a BSON document read from the socket.
    # Returns nil if the operation times out or if a network
    #         connection failure occurs
    def self.read_bson_document(socket)
      bytebuf = BSON::ByteBuffer.new
      # Read 4 byte size of following BSON document
      bytes = socket.read(4)

      # Read BSON document
      sz = bytes.unpack("V")[0]
      raise "Invalid Data received from server:#{bytes.inspect}" unless sz

      bytebuf.append!(bytes)
      bytebuf.append!(socket.read(sz - 4))
      return BSON.deserialize(bytebuf)
    end

  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
ruby_skynet-0.4.0.pre lib/ruby_skynet/common.rb
ruby_skynet-0.3.0 lib/ruby_skynet/common.rb