Class Mongo::Protocol::Message
In: lib/mongo/protocol/message.rb
Parent: Object

A base class providing functionality required by all messages in the MongoDB wire protocol. It provides a minimal DSL for defining typed fields to enable serialization and deserialization over the wire.

@example

  class WireProtocolMessage < Message

    private

    def op_code
      1234
    end

    FLAGS = [:first_bit, :bit_two]

    # payload
    field :flags, BitVector.new(FLAGS)
    field :namespace, CString
    field :document, Document
    field :documents, Document, true
  end

@abstract @api semiprivate

Methods

Included Modules

Id Serializers

Constants

BATCH_SIZE = 'batchSize'.freeze   The batch size constant.

@since 2.2.0

COLLECTION = 'collection'.freeze   The collection constant.

@since 2.2.0

LIMIT = 'limit'.freeze   The limit constant.

@since 2.2.0

ORDERED = 'ordered'.freeze   The ordered constant.

@since 2.2.0

Q = 'q'.freeze   The q constant.

@since 2.2.0

MAX_MESSAGE_SIZE = 50331648.freeze   Default max message size of 48MB.

@since 2.2.1

Attributes

request_id  [R]  Returns the request id for the message

@return [Fixnum] The request id for this message

Public Class methods

Deserializes messages from an IO stream

@param [ Integer ] max_message_size The max message size. @param [ IO ] io Stream containing a message

@return [ Message ] Instance of a Message class

Public Instance methods

Tests for equality between two wire protocol messages by comparing class and field values.

@param other [Mongo::Protocol::Message] The wire protocol message. @return [true, false] The equality of the messages.

Compress a message.

@param [ String, Symbol ] compressor The compressor to use. @param [ Integer ] zlib_compression_level The zlib compression level to use.

@return [ self ] Always returns self. Other message types should override this method.

@since 2.5.0

eql?(other)

Alias for #==

Creates a hash from the values of the fields of a message.

@return [ Fixnum ] The hash code for the message.

Inflate a message.

@return [ self ] Always returns self. Other message types should override this method.

@since 2.5.0

Default number returned value for protocol messages.

@return [ 0 ] This method must be overridden, otherwise, always returns 0.

@since 2.5.0

The default for messages is not to require a reply after sending a message to the server.

@example Does the message require a reply?

  message.replyable?

@return [ false ] The default is to not require a reply.

@since 2.0.0

Serializes message into bytes that can be sent on the wire

@param buffer [String] buffer where the message should be inserted @return [String] buffer containing the serialized message

Generates a request id for a message

@return [Fixnum] a request id used for sending a message to the

  server. The server will put this id in the response_to field of
  a reply.
to_s(buffer = BSON::ByteBuffer.new, max_bson_size = nil)

Alias for serialize

[Validate]