Method: Moped::Connection#read

Defined in:
lib/moped/connection.rb

#readHash

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Read from the connection.

Examples:

Read from the connection.

connection.read

Returns:

  • (Hash)

    The returned document.

Since:

  • 1.0.0



84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
# File 'lib/moped/connection.rb', line 84

def read
  reply = Protocol::Reply.allocate
  reply.length,
    reply.request_id,
    reply.response_to,
    reply.op_code,
    reply.flags,
    reply.cursor_id,
    reply.offset,
    reply.count = @sock.read(36).unpack('l<5q<l<2')

  if reply.count == 0
    reply.documents = []
  else
    buffer = StringIO.new(@sock.read(reply.length - 36))

    reply.documents = reply.count.times.map do
      BSON::Document.deserialize(buffer)
    end
  end
  reply
end