Class: Steam::ByteWriter
- Inherits:
-
Object
- Object
- Steam::ByteWriter
- Extended by:
- Forwardable
- Defined in:
- lib/steam/byte_writer.rb
Overview
Writes bytes to a given io object
Defined Under Namespace
Classes: Int64Type
Instance Method Summary collapse
-
#initialize ⇒ ByteWriter
constructor
A new instance of ByteWriter.
-
#rewind ⇒ Object
Rewind the stream.
-
#string ⇒ String
The byte representation of this writer object.
-
#write(bytes) ⇒ Object
Writes the given bytes to the stream.
-
#write_int32(value) ⇒ Object
Writes a 32 bit intger to the stream.
-
#write_int64(value) ⇒ Object
Writes a 64 bit intger to the stream.
-
#write_unsigned_int32(value) ⇒ Object
Writes an unsigned 32 bit integer from the stream.
Constructor Details
#initialize ⇒ ByteWriter
Returns a new instance of ByteWriter.
41 42 43 44 |
# File 'lib/steam/byte_writer.rb', line 41 def initialize @io = StringIO.new @io.set_encoding('BINARY') end |
Instance Method Details
#rewind ⇒ Object
Rewind the stream
47 48 49 |
# File 'lib/steam/byte_writer.rb', line 47 def rewind @io.rewind end |
#string ⇒ String
The byte representation of this writer object
78 79 80 81 |
# File 'lib/steam/byte_writer.rb', line 78 def string @io.rewind @io.string end |
#write(bytes) ⇒ Object
Writes the given bytes to the stream
71 72 73 |
# File 'lib/steam/byte_writer.rb', line 71 def write(bytes) @io.write(bytes) end |
#write_int32(value) ⇒ Object
Writes a 32 bit intger to the stream
57 58 59 |
# File 'lib/steam/byte_writer.rb', line 57 def write_int32(value) @io.write([value].pack('<l')) end |
#write_int64(value) ⇒ Object
Writes a 64 bit intger to the stream
62 63 64 65 66 67 68 |
# File 'lib/steam/byte_writer.rb', line 62 def write_int64(value) int64 = Int64Type.new(value) int64.int32s.each do |int| write_int32(int) end end |
#write_unsigned_int32(value) ⇒ Object
Writes an unsigned 32 bit integer from the stream
52 53 54 |
# File 'lib/steam/byte_writer.rb', line 52 def write_unsigned_int32(value) @io.write([value].pack('<I')) end |