Module: Spark::CoreExtension::IO::InstanceMethods

Defined in:
lib/spark/ext/io.rb

Instance Method Summary collapse

Instance Method Details

#read_dataObject

[View source]

29
30
31
# File 'lib/spark/ext/io.rb', line 29

def read_data
  Marshal.load(read_string)
end

#read_intObject

Reading

[View source]

11
12
13
# File 'lib/spark/ext/io.rb', line 11

def read_int
  unpack_int(read(4))
end

#read_int_or_eofObject

[View source]

15
16
17
18
19
# 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_longObject

[View source]

21
22
23
# File 'lib/spark/ext/io.rb', line 21

def read_long
  unpack_long(read(8))
end

#read_stringObject

[View source]

25
26
27
# File 'lib/spark/ext/io.rb', line 25

def read_string
  read(read_int)
end

#write_data(data) ⇒ Object

[View source]

52
53
54
# File 'lib/spark/ext/io.rb', line 52

def write_data(data)
  write_string(Marshal.dump(data))
end

#write_int(data) ⇒ Object

Writing

[View source]

36
37
38
# File 'lib/spark/ext/io.rb', line 36

def write_int(data)
  write(pack_int(data))
end

#write_long(data) ⇒ Object

[View source]

40
41
42
# File 'lib/spark/ext/io.rb', line 40

def write_long(data)
  write(pack_long(data))
end

#write_string(data) ⇒ Object

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

[View source]

47
48
49
50
# File 'lib/spark/ext/io.rb', line 47

def write_string(data)
  write_int(data.bytesize)
  write(data)
end