Module Moped::Protocol::Message
In: lib/moped/protocol/message.rb

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

Methods

Classes and Modules

Module Moped::Protocol::Message::ClassMethods

Constants

INT32_DECODE_STR = 'l<'
INT64_DECODE_ARRAY_STR = 'q<*'
INT64_DECODE_STR = 'q<'

Public Instance methods

@return [String] the nicely formatted version of the message

Default implementation for a message is to do nothing when receiving replies.

@example Receive replies.

  message.receive_replies(connection)

@param [ Connection ] connection The connection.

@return [ nil ] nil.

@since 1.0.0

Serializes the message and all of its fields to a new buffer or to the provided buffer.

@example Serliaze the message.

  message.serialize

@param [ String ] buffer A buffer to serialize to.

@return [ String ] The result of serliazing this message

@since 1.0.0

to_s(buffer = "")

Alias for serialize

[Validate]