Class: CassandraCQL::Collections::Map

Inherits:
Object
  • Object
show all
Defined in:
lib/cassandra-cql/collections/map.rb

Class Method Summary collapse

Class Method Details

.cast(value) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/cassandra-cql/collections/map.rb', line 4

def self.cast(value)
  length = value.unpack('S>').first
  pos = 2
  result = {}
  length.times do
    key_length = value.byteslice(pos, 2).unpack('S>').first
    pos += 2
    key = value.byteslice(pos, key_length)
    pos += key_length

    val_length = value.byteslice(pos, 2).unpack('S>').first
    pos += 2
    val = value.byteslice(pos, val_length)
    pos += val_length
    cast_key, cast_val = yield key, val
    result[cast_key] = cast_val
  end
  result
end