Class: FFI::MsgPack::MsgMap

Inherits:
Struct
  • Object
show all
Defined in:
lib/ffi/msgpack/msg_map.rb

Instance Method Summary collapse

Instance Method Details

#lengthInteger

The length of the MsgPack Array.

Returns:

  • (Integer)

    The length of the Array.



18
19
20
# File 'lib/ffi/msgpack/msg_map.rb', line 18

def length
  self[:size]
end

#to_hashHash

The Hash of the Msg Maps keys and values.

Returns:

  • (Hash)

    The Hash of the key->value values.



28
29
30
31
32
33
34
35
36
37
38
# File 'lib/ffi/msgpack/msg_map.rb', line 28

def to_hash
  hash = {}

  (0...self.length).each do |index|
    pair = MsgKeyValue.new(self[:ptr][index * MsgKeyValue.size])

    hash[pair.key.to_ruby] = pair.value.to_ruby
  end

  return hash
end