Class: Steam::ByteReader

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/steam/byte_reader.rb

Overview

Reads bytes from a given IO object.

Instance Method Summary collapse

Constructor Details

#initialize(io) ⇒ ByteReader

Create a ByteReader object

Parameters:

  • io (:read)

    an io object



12
13
14
# File 'lib/steam/byte_reader.rb', line 12

def initialize(io)
  @io = io
end

Instance Method Details

#signed_int32Integer

Reads an signed 32 bit integer from the stream

Returns:

  • (Integer)

    The 32 bit integer



34
35
36
# File 'lib/steam/byte_reader.rb', line 34

def signed_int32
  @io.read(4).unpack('<i*').first
end

#string(len) ⇒ String

Reads a string of a given length from the stream

Parameters:

  • len (Integer)

    the number of bytes to read

Returns:

  • (String)

    The read string



20
21
22
# File 'lib/steam/byte_reader.rb', line 20

def string(len)
  read(len)
end

#unsigned_int32Integer

Reads an unsigned 32 bit integer from the stream

Returns:

  • (Integer)

    The 32 bit integer



27
28
29
# File 'lib/steam/byte_reader.rb', line 27

def unsigned_int32
  @io.read(4).unpack('<I*').first
end