The base class for building all messages needed to implement the Mongo Wire Protocol. It provides a minimal DSL for defining typed fields for serialization and deserialization over the wire.
@example
class KillCursors < Moped::Protocol::Message
# header fields
int32 :length
int32 :request_id
int32 :response_to
int32 :op_code
# message fields
int32 :reserved
int32 :number_of_cursors
int64 :cursor_ids, type: :array
# Customize field reader
def number_of_cursors
cursor_ids.length
end
end
Note that all messages must implement the header fields required by the Mongo Wire Protocol, namely:
int32 :length int32 :request_id int32 :response_to int32 :op_code
@return [String] the nicely formatted version of the message
# File lib/moped/protocol/message.rb, line 327 def inspect fields = self.class.fields.map do |field| "@#{field}=" + __send__(field).inspect end "#<#{self.class.name}\n" << " #{fields * "\n "}>" end
Default implementation for a message is to do nothing when receiving replies.
@example Receive replies.
message.receive_replies(connection)
@param [ Connection ] connection The connection.
@since 1.0.0
@return [ nil ] nil.
# File lib/moped/protocol/message.rb, line 314 def receive_replies(connection); end
Serializes the message and all of its fields to a new buffer or to the provided buffer.
@param [String] buffer a buffer to serialize to @return [String] the result of serliazing this message
# File lib/moped/protocol/message.rb, line 321 def serialize(buffer = "") raise NotImplementedError, "This method is generated after calling #finalize on a message class" end
Generated with the Darkfish Rdoc Generator 2.