Class: Seafoam::Binary::IOBinaryReader

Inherits:
Object
  • Object
show all
Defined in:
lib/seafoam/binary/io_binary_reader.rb

Overview

An adapter to read binary values from an IO stream.

Instance Method Summary collapse

Constructor Details

#initialize(io) ⇒ IOBinaryReader

Returns a new instance of IOBinaryReader.



7
8
9
# File 'lib/seafoam/binary/io_binary_reader.rb', line 7

def initialize(io)
  @io = io
end

Instance Method Details

#eof?Boolean

Returns:

  • (Boolean)


85
86
87
# File 'lib/seafoam/binary/io_binary_reader.rb', line 85

def eof?
  @io.eof?
end

#peek_sint8Object



51
52
53
54
55
# File 'lib/seafoam/binary/io_binary_reader.rb', line 51

def peek_sint8
  byte = @io.read(1).unpack1("c")
  @io.ungetbyte(byte)
  byte
end

#read_bytes(length) ⇒ Object



15
16
17
# File 'lib/seafoam/binary/io_binary_reader.rb', line 15

def read_bytes(length)
  @io.read(length)
end

#read_float32Object



23
24
25
# File 'lib/seafoam/binary/io_binary_reader.rb', line 23

def read_float32
  @io.read(4).unpack1("g")
end

#read_float64Object



19
20
21
# File 'lib/seafoam/binary/io_binary_reader.rb', line 19

def read_float64
  @io.read(8).unpack1("G")
end

#read_sint16Object



35
36
37
# File 'lib/seafoam/binary/io_binary_reader.rb', line 35

def read_sint16
  @io.read(2).unpack1("s>")
end

#read_sint32Object



31
32
33
# File 'lib/seafoam/binary/io_binary_reader.rb', line 31

def read_sint32
  @io.read(4).unpack1("l>")
end

#read_sint64Object



27
28
29
# File 'lib/seafoam/binary/io_binary_reader.rb', line 27

def read_sint64
  @io.read(8).unpack1("q>")
end

#read_sint8Object



43
44
45
# File 'lib/seafoam/binary/io_binary_reader.rb', line 43

def read_sint8
  @io.read(1).unpack1("c")
end

#read_uint16Object



39
40
41
# File 'lib/seafoam/binary/io_binary_reader.rb', line 39

def read_uint16
  @io.read(2).unpack1("S>")
end

#read_uint8Object



47
48
49
# File 'lib/seafoam/binary/io_binary_reader.rb', line 47

def read_uint8
  @io.readbyte
end

#read_utf8(length) ⇒ Object



11
12
13
# File 'lib/seafoam/binary/io_binary_reader.rb', line 11

def read_utf8(length)
  read_bytes(length).force_encoding(Encoding::UTF_8)
end

#skip(count) ⇒ Object



81
82
83
# File 'lib/seafoam/binary/io_binary_reader.rb', line 81

def skip(count)
  @io.seek(count, IO::SEEK_CUR)
end

#skip_float32(count = 1) ⇒ Object



61
62
63
# File 'lib/seafoam/binary/io_binary_reader.rb', line 61

def skip_float32(count = 1)
  skip(count * 4)
end

#skip_float64(count = 1) ⇒ Object



57
58
59
# File 'lib/seafoam/binary/io_binary_reader.rb', line 57

def skip_float64(count = 1)
  skip(count * 8)
end

#skip_int16(count = 1) ⇒ Object



73
74
75
# File 'lib/seafoam/binary/io_binary_reader.rb', line 73

def skip_int16(count = 1)
  skip(count * 2)
end

#skip_int32(count = 1) ⇒ Object



69
70
71
# File 'lib/seafoam/binary/io_binary_reader.rb', line 69

def skip_int32(count = 1)
  skip(count * 4)
end

#skip_int64(count = 1) ⇒ Object



65
66
67
# File 'lib/seafoam/binary/io_binary_reader.rb', line 65

def skip_int64(count = 1)
  skip(count * 8)
end

#skip_int8(count = 1) ⇒ Object



77
78
79
# File 'lib/seafoam/binary/io_binary_reader.rb', line 77

def skip_int8(count = 1)
  skip(count)
end