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



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

int32    :count

#cursor_idNumber



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

int64    :cursor_id

#documentsArray



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

document :documents, type: :array

#flagsArray<Symbol>



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



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

int32 :length

#offsetNumber



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

int32    :offset

#op_codeNumber



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

int32 :op_code

#request_idNumber



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

int32 :request_id

#response_toNumber



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


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