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

Provides a DSL for defining struct-like fields for building messages for the Mongo Wire.

@example

  class Command
    extend Message::ClassMethods

    int32 :length
  end

  Command.fields # => [:length]
  command = Command.new
  command.length = 12
  command.serialize_length("") # => "\f\x00\x00\x00"

Methods

cstring   document   fields   finalize   flags   int32   int64  

Public Instance methods

Declare a null terminated string field.

@example

  class Query < Message
    cstring :collection
  end

@param [String] name the name of this field

Declare a BSON Document field.

@example

  class Update < Message
    document :selector
  end

@example optional document field

  class Query < Message
    document :selector
    document :fields, optional: true
  end

@example array of documents

  class Reply < Message
    document :documents, type: :array
  end

@param [String] name the name of this field @param [Hash] options the options for this field @option options [:array] :type specify an array of documents @option options [Boolean] :optional specify this field as optional

@return [Array] the fields defined for this message

Declares the message class as complete, and defines its serialization method from the declared fields.

Declare a flag field (32 bit signed integer)

@example

  class Update < Message
    flags :flags, upsert: 2 ** 0,
                  multi:  2 ** 1
  end

@param [String] name the name of this field @param [Hash{Symbol => Number}] flags the flags for this flag field

Declare a 32 bit signed integer field.

@example

  class Query < Message
    int32 :length
  end

@param [String] name the name of this field

Declare a 64 bit signed integer field.

@example

  class Query < Message
    int64 :cursor_id
  end

@example with array type

  class KillCursors < Message
    int64 :cursor_ids, type: :array
  end

@param [String] name the name of this field @param [Hash] options the options for this field @option options [:array] :type specify an array of 64 bit ints

[Validate]