Module: KafkaSyrup::Encoding

Defined in:
lib/kafka_syrup/encoding.rb

Class Method Summary collapse

Class Method Details

.read_array(io, &block) ⇒ Object



52
53
54
55
56
# File 'lib/kafka_syrup/encoding.rb', line 52

def read_array(io, &block)
  [].tap do |result|
    read_int32(io).times{ result << yield(io) }
  end
end

.write_array(items, &block) ⇒ Object



40
41
42
43
44
45
46
47
48
49
50
# File 'lib/kafka_syrup/encoding.rb', line 40

def write_array(items, &block)
  result  =  write_int32(items.length)
  if block_given?
    result += items.map(&block).join
  else
    items.each do |item|
      result += item.respond_to?(:encode) ? item.encode : item
    end
  end
  result
end