Class: Moped::Protocol::Reply
- Includes:
- Message
- Defined in:
- lib/moped/protocol/reply.rb
Overview
The Protocol class representing messages received from a mongo connection.
Constant Summary collapse
- UNAUTHORIZED =
10057
Instance Attribute Summary collapse
-
#count ⇒ Number
The number of documents returned.
-
#cursor_id ⇒ Number
The id of the cursor on the server.
-
#documents ⇒ Array
The returned documents.
-
#flags ⇒ Array<Symbol>
The flags for this reply.
-
#length ⇒ Number
The length of the message.
-
#offset ⇒ Number
The starting position within the cursor.
-
#op_code ⇒ Number
The operation code of this message (always 1).
-
#request_id ⇒ Number
The request id of the message.
-
#response_to ⇒ Number
The id that generated the message.
Class Method Summary collapse
-
.deserialize(buffer) ⇒ Reply
Consumes a buffer, returning the deserialized Reply message.
Instance Method Summary collapse
-
#command_failure? ⇒ true, false
Is the reply the result of a command failure?.
-
#cursor_not_found? ⇒ true, false
Was the provided cursor id not found on the server?.
-
#query_failed? ⇒ true, false
Did the query fail on the server?.
-
#unauthorized? ⇒ true, false
Is the reply an error message that we are not authorized for the query or command?.
Methods included from Message
included, #inspect, #receive_replies, #serialize
Instance Attribute Details
#count ⇒ Number
Returns the number of documents returned.
50 |
# File 'lib/moped/protocol/reply.rb', line 50 int32 :count |
#cursor_id ⇒ Number
Returns the id of the cursor on the server.
42 |
# File 'lib/moped/protocol/reply.rb', line 42 int64 :cursor_id |
#documents ⇒ Array
Returns the returned documents.
54 |
# File 'lib/moped/protocol/reply.rb', line 54 document :documents, type: :array |
#flags ⇒ Array<Symbol>
Returns the flags for this reply.
36 37 38 |
# File 'lib/moped/protocol/reply.rb', line 36 flags :flags, cursor_not_found: 2 ** 0, query_failure: 2 ** 1, await_capable: 2 ** 3 |
#length ⇒ Number
Returns the length of the message.
20 |
# File 'lib/moped/protocol/reply.rb', line 20 int32 :length |
#offset ⇒ Number
Returns the starting position within the cursor.
46 |
# File 'lib/moped/protocol/reply.rb', line 46 int32 :offset |
#op_code ⇒ Number
Returns the operation code of this message (always 1).
32 |
# File 'lib/moped/protocol/reply.rb', line 32 int32 :op_code |
#request_id ⇒ Number
Returns the request id of the message.
24 |
# File 'lib/moped/protocol/reply.rb', line 24 int32 :request_id |
#response_to ⇒ Number
Returns the id that generated the message.
28 |
# File 'lib/moped/protocol/reply.rb', line 28 int32 :response_to |
Class Method Details
.deserialize(buffer) ⇒ Reply
Consumes a buffer, returning the deserialized Reply message.
reply from.
127 128 129 130 131 132 133 |
# File 'lib/moped/protocol/reply.rb', line 127 def deserialize(buffer) reply = allocate fields.each do |field| reply.__send__ :"deserialize_#{field}", buffer end reply end |
Instance Method Details
#command_failure? ⇒ true, false
This is when ok is not 1, or “err” or “errmsg” are present.
Is the reply the result of a command failure?
68 69 70 71 |
# File 'lib/moped/protocol/reply.rb', line 68 def command_failure? result = documents[0] result["ok"] != 1 || result["err"] || result["errmsg"] end |
#cursor_not_found? ⇒ true, false
Was the provided cursor id not found on the server?
81 82 83 |
# File 'lib/moped/protocol/reply.rb', line 81 def cursor_not_found? flags.include?(:cursor_not_found) end |
#query_failed? ⇒ true, false
Did the query fail on the server?
93 94 95 |
# File 'lib/moped/protocol/reply.rb', line 93 def query_failed? flags.include?(:query_failure) end |
#unauthorized? ⇒ true, false
So far this can be a “code” of 10057 in the error message or an “assertionCode” of 10057.
Is the reply an error message that we are not authorized for the query or command?
109 110 111 112 |
# File 'lib/moped/protocol/reply.rb', line 109 def result = documents[0] result["code"] == UNAUTHORIZED || result["assertionCode"] == UNAUTHORIZED end |