Sha256: 9d52f2f42863e83874907d5eb5cf942752973d3bd7eb35dfc8fffeb6b1230c31

Contents?: true

Size: 786 Bytes

Versions: 5

Compression:

Stored size: 786 Bytes

Contents

require 'ffi/msgpack/types'

module FFI
  module MsgPack
    autoload :MsgKeyValue, 'ffi/msgpack/msg_key_value'

    class MsgMap < FFI::Struct

      layout :size, :uint32,
             :ptr, :pointer

      #
      # The length of the MsgPack Array.
      #
      # @return [Integer]
      #   The length of the Array.
      #
      def length
        self[:size]
      end

      #
      # The Hash of the Msg Maps keys and values.
      #
      # @return [Hash]
      #   The Hash of the key->value values.
      #
      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

    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
ffi-msgpack-0.2.2 lib/ffi/msgpack/msg_map.rb
ffi-msgpack-0.2.1 lib/ffi/msgpack/msg_map.rb
ffi-msgpack-0.2.0 lib/ffi/msgpack/msg_map.rb
ffi-msgpack-0.1.4 lib/ffi/msgpack/msg_map.rb
ffi-msgpack-0.1.3 lib/ffi/msgpack/msg_map.rb