module Spark::CoreExtension::IO::InstanceMethods

Public Instance Methods

read_data() click to toggle source
# File lib/spark/ext/io.rb, line 29
def read_data
  Marshal.load(read_string)
end
read_int() click to toggle source

Reading

# File lib/spark/ext/io.rb, line 11
def read_int
  unpack_int(read(4))
end
read_int_or_eof() click to toggle source
# File lib/spark/ext/io.rb, line 15
def read_int_or_eof
  bytes = read(4)
  return Spark::Constant::DATA_EOF if bytes.nil?
  unpack_int(bytes)
end
read_long() click to toggle source
# File lib/spark/ext/io.rb, line 21
def read_long
  unpack_long(read(8))
end
read_string() click to toggle source
# File lib/spark/ext/io.rb, line 25
def read_string
  read(read_int)
end
write_data(data) click to toggle source
# File lib/spark/ext/io.rb, line 52
def write_data(data)
  write_string(Marshal.dump(data))
end
write_int(data) click to toggle source

Writing

# File lib/spark/ext/io.rb, line 36
def write_int(data)
  write(pack_int(data))
end
write_long(data) click to toggle source
# File lib/spark/ext/io.rb, line 40
def write_long(data)
  write(pack_long(data))
end
write_string(data) click to toggle source

Size and data can have different encoding Marshal: both ASCII Oj: ASCII and UTF-8

# File lib/spark/ext/io.rb, line 47
def write_string(data)
  write_int(data.bytesize)
  write(data)
end