Sha256: f1c957bf0f4e93c392a6ddd1f61727c0c3137b96d3c156ebd35755e06ed69040

Contents?: true

Size: 766 Bytes

Versions: 3

Compression:

Stored size: 766 Bytes

Contents

require 'ffi/msgpack/types'
require 'ffi/msgpack/msg_key_value'

module FFI
  module MsgPack
    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

3 entries across 3 versions & 1 rubygems

Version Path
ffi-msgpack-0.1.2 lib/ffi/msgpack/msg_map.rb
ffi-msgpack-0.1.1 lib/ffi/msgpack/msg_map.rb
ffi-msgpack-0.1.0 lib/ffi/msgpack/msg_map.rb