| 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"
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
Declares the message class as complete, and defines its serialization method from the declared fields.
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