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



116
117
118
119
120
121
122
123
124
125
126
127
# File 'lib/moped/protocol/message.rb', line 116

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