Method: Moped::Protocol::Message::ClassMethods#cstring

Defined in:
lib/moped/protocol/message.rb

#cstring(name) ⇒ Object

Declare a null terminated string field.

Examples:

class Query < Message
  cstring :collection
end

Parameters:

  • name (String)

    the name of this field



81
82
83
84
85
86
87
88
89
90
91
92
# File 'lib/moped/protocol/message.rb', line 81

def cstring(name)
  attr_accessor name

  class_eval <<-RUBY, __FILE__, __LINE__ + 1
    def serialize_#{name}(buffer)
      buffer << #{name}
      buffer << 0
    end
  RUBY

  fields << name
end