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
.
80 81 82 83 |
# File 'lib/moped/protocol/message.rb', line 80 def included(base) super base.extend(ClassMethods) end |
Instance Method Details
#inspect ⇒ String
Returns the nicely formatted version of the message.
68 69 70 71 72 73 74 |
# File 'lib/moped/protocol/message.rb', line 68 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.
49 |
# File 'lib/moped/protocol/message.rb', line 49 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.
62 63 64 |
# File 'lib/moped/protocol/message.rb', line 62 def serialize(buffer = "") raise NotImplementedError, "This method is generated after calling #finalize on a message class" end |