Class: Spark::Serializer::Pair
- Inherits:
-
Base
- Object
- Base
- Spark::Serializer::Pair
show all
- Defined in:
- lib/spark/serializer/pair.rb
Instance Method Summary
collapse
Methods inherited from Base
#==, #batched?, #check_each, #error, #inspect, #load_from_file, #name, #unbatch!
Constructor Details
#initialize(serializer1, serializer2) ⇒ Pair
Returns a new instance of Pair.
5
6
7
8
|
# File 'lib/spark/serializer/pair.rb', line 5
def initialize(serializer1, serializer2)
@serializer1 = serializer1
@serializer2 = serializer2
end
|
Instance Method Details
#aggregate(item1, item2) ⇒ Object
14
15
16
|
# File 'lib/spark/serializer/pair.rb', line 14
def aggregate(item1, item2)
item1.zip(item2)
end
|
#load_from_io(io) ⇒ Object
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
|
# File 'lib/spark/serializer/pair.rb', line 18
def load_from_io(io)
return to_enum(__callee__, io) unless block_given?
loop do
size = io.read_int_or_eof
break if size == Spark::Constant::DATA_EOF
item1 = @serializer1.load(io.read(size))
item2 = @serializer2.load(io.read_string)
item1 = [item1] unless @serializer1.batched?
item2 = [item2] unless @serializer2.batched?
aggregate(item1, item2).each do |item|
yield item
end
end
end
|
#to_s ⇒ Object
10
11
12
|
# File 'lib/spark/serializer/pair.rb', line 10
def to_s
"#{name}(#{@serializer1}, #{@serializer2})"
end
|