Method: Corosync::CMAP#set

Defined in:
lib/corosync/cmap.rb

#set(name, type, value) ⇒ Number, String

Set a key to the specified type & value. This will create the key if it doesn’t exist, and will otherwise modify it, including changing the type if it doesn’t match.

Parameters:

  • name (String)

    The name of the key

  • type (Symbol)

    One of CMAP’s supported types

  • value (Number, String)

    The value to set

Returns:

  • (Number, String)

    The value as stored in the CMAP service. This will normally be the value passed in, but if you store a non-string as a string, the return will be the result of to_s



126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
# File 'lib/corosync/cmap.rb', line 126

def set(name, type, value)
  # get byte size
  if type == :string then
    size = value.bytesize
  elsif SIZEMAP.keys.include?(type) then
    size = SIZEMAP[type].bytes
  elsif type == :float then
    size = 4
  elsif type == :double then
    size = 8
  elsif type == :binary then
    size = value.bytesize
  end

  value_ptr = FFI::MemoryPointer.new(size)
  value_ptr.write_type(type, value)
  Corosync.cs_send(:cmap_set, @handle, name, value_ptr, size, type)

  value
end