Method: Moped::Protocol::Message::ClassMethods#int64

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

#int64(name, options = {}) ⇒ Object

Declare a 64 bit signed integer field.

Examples:

class Query < Message
  int64 :cursor_id
end

with array type

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

Parameters:

  • name (String)

    the name of this field

  • options (Hash) (defaults to: {})

    the options for this field

Options Hash (options):

  • :type (:array)

    specify an array of 64 bit ints



238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
# File 'lib/moped/protocol/message.rb', line 238

def int64(name, options = {})
  attr_writer name

  if options[:type] == :array
    class_eval "      def \#{name}\n        @\#{name} ||= []\n      end\n\n      def serialize_\#{name}(buffer)\n        buffer << \#{name}.pack('q*<')\n      end\n\n      def deserialize_\#{name}(buffer)\n        raise NotImplementedError\n      end\n    RUBY\n  else\n    class_eval <<-RUBY, __FILE__, __LINE__ + 1\n      def \#{name}\n        @\#{name} ||= 0\n      end\n\n      def serialize_\#{name}(buffer)\n        buffer << [\#{name}].pack('q<')\n      end\n\n      def deserialize_\#{name}(buffer)\n        self.\#{name}, = buffer.read(8).unpack('q<')\n      end\n    RUBY\n  end\n\n  fields << name\nend\n", __FILE__, __LINE__ + 1