Class: Moped::Protocol::Reply

Inherits:
Object
  • Object
show all
Includes:
Message
Defined in:
lib/moped/protocol/reply.rb

Overview

The Protocol class representing messages received from a mongo connection.

Examples:

socket = TCPSocket.new "127.0.0.1", 27017
command = Moped::Protocol::Command.new "admin", buildinfo: 1
socket.write command.serialize
reply = Moped::Protocol::Reply.deserialize(socket)
reply.documents[0]["version"] # => "2.0.0"

Instance Attribute Summary collapse

Class Method Summary collapse

Methods included from Message

included, #inspect, #receive_replies, #serialize

Instance Attribute Details

#countNumber

Returns the number of documents returned.

Returns:

  • (Number)

    the number of documents returned



48
# File 'lib/moped/protocol/reply.rb', line 48

int32    :count

#cursor_idNumber

Returns the id of the cursor on the server.

Returns:

  • (Number)

    the id of the cursor on the server



40
# File 'lib/moped/protocol/reply.rb', line 40

int64    :cursor_id

#documentsArray

Returns the returned documents.

Returns:

  • (Array)

    the returned documents



52
# File 'lib/moped/protocol/reply.rb', line 52

document :documents, type: :array

#flagsArray<Symbol>

Returns the flags for this reply.

Returns:



34
35
36
# File 'lib/moped/protocol/reply.rb', line 34

flags    :flags, cursor_not_found:  2 ** 0,
query_failure:     2 ** 1,
await_capable:     2 ** 3

#lengthNumber

Returns the length of the message.

Returns:

  • (Number)

    the length of the message



18
# File 'lib/moped/protocol/reply.rb', line 18

int32 :length

#offsetNumber

Returns the starting position within the cursor.

Returns:

  • (Number)

    the starting position within the cursor



44
# File 'lib/moped/protocol/reply.rb', line 44

int32    :offset

#op_codeNumber

Returns the operation code of this message (always 1).

Returns:

  • (Number)

    the operation code of this message (always 1)



30
# File 'lib/moped/protocol/reply.rb', line 30

int32 :op_code

#request_idNumber

Returns the request id of the message.

Returns:

  • (Number)

    the request id of the message



22
# File 'lib/moped/protocol/reply.rb', line 22

int32 :request_id

#response_toNumber

Returns the id that generated the message.

Returns:

  • (Number)

    the id that generated the message



26
# File 'lib/moped/protocol/reply.rb', line 26

int32 :response_to

Class Method Details

.deserialize(buffer) ⇒ Reply

Consumes a buffer, returning the deserialized Reply message.

reply from.

Examples:

socket = TCPSocket.new "localhost", 27017
socket.write Moped::Protocol::Command.new(:admin, ismaster: 1).serialize
reply = Moped::Protocol::Reply.deserialize(socket)
reply.documents[0]['ismaster'] # => 1

Parameters:

  • buffer (#read)

    an IO or IO-like resource to deserialize the

Returns:

  • (Reply)

    the deserialized reply



69
70
71
72
73
74
75
# File 'lib/moped/protocol/reply.rb', line 69

def deserialize(buffer)
  reply = allocate
  fields.each do |field|
    reply.__send__ :"deserialize_#{field}", buffer
  end
  reply
end