Module: Moped::Protocol::Message
- Defined in:
- lib/moped/protocol/message.rb
Overview
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.
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
Defined Under Namespace
Modules: ClassMethods
Class Method Summary collapse
-
.included(base) ⇒ Object
Extends the including class with
ClassMethods
.
Instance Method Summary collapse
-
#inspect ⇒ String
The nicely formatted version of the message.
-
#receive_replies(connection) ⇒ nil
Default implementation for a message is to do nothing when receiving replies.
-
#serialize(buffer = "") ⇒ String
(also: #to_s)
Serializes the message and all of its fields to a new buffer or to the provided buffer.
Class Method Details
.included(base) ⇒ Object
Extends the including class with ClassMethods
.
43 44 45 46 47 |
# File 'lib/moped/protocol/message.rb', line 43 def included(base) super base.extend ClassMethods end |
Instance Method Details
#inspect ⇒ String
Returns the nicely formatted version of the message.
327 328 329 330 331 332 333 |
# 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 |
#receive_replies(connection) ⇒ nil
Default implementation for a message is to do nothing when receiving replies.
314 |
# File 'lib/moped/protocol/message.rb', line 314 def receive_replies(connection); end |
#serialize(buffer = "") ⇒ String Also known as: to_s
Serializes the message and all of its fields to a new buffer or to the provided buffer.
321 322 323 |
# 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 |