lib/garcon/stash/format.rb
# Deserialize records from buffer, and yield them.
#
# @param [String] buf
#   the buffer to read from
#
# @yield [Array] block
#   deserialized record [key, value] or [key] if the record is deleted
#
# @return [Fixnum] number of records
#
Deserialize records from buffer, and yield them.
Deserialize records from buffer and yield them .
def parse(buf)
        n, count = 0, 0
        while n < buf.size
          key_size, value_size = buf[n, 8].unpack('NN')
          data_size = key_size + 8
          data_size += value_size if value_size != DELETE
          data = buf[n, data_size]
          n += data_size
          unless buf[n, 4] == crc32(data)
            raise 'CRC mismatch: your stash might be corrupted!'
          end
          n += 4
          yield(value_size == DELETE ? [data[8, key_size]] : [data[8, key_size], data[8 + key_size, value_size]])
          count += 1
        end
        count
      end
def parse ( buf ) n , count = 0 , 0 while n < buf . size key_size , value_size = buf [ n , 8 ] . unpack ( 'NN' ) data_size = key_size + 8 data_size += value_size if value_size != DELETE data = buf [ n , data_size ] n += data_size unless buf [ n , 4 ] == crc32 ( data ) raise 'CRC mismatch: your stash might be corrupted!' end n += 4 yield ( value_size == DELETE ? [ data [ 8 , key_size ] ] : [ data [ 8 , key_size ] , data [ 8 + key_size , value_size ] ] ) count += 1 end count end
Deserialize records from buffer, and yield them.
Deserialize records from buffer and yield them .
number of records
number of records
Fixnum
buf
<not_specific>
<not_specific>
buf the buffer to read from
buf the buffer to read from
]
<not_specific>
block deserialized record [key, value] or [key] if the record is deleted
block deserialized record [ key value ] or [ key ] if the record is deleted