Class: Doom::Game::Snapshot::Writer
- Inherits:
-
Object
- Object
- Doom::Game::Snapshot::Writer
- Defined in:
- lib/doom/game/snapshot.rb
Overview
A cursor-based binary writer, so record offsets are never hand-managed.
Instance Method Summary collapse
- #bool(v) ⇒ Object
- #f64(v) ⇒ Object
- #i64(v) ⇒ Object
-
#initialize ⇒ Writer
constructor
A new instance of Writer.
-
#list(items) ⇒ Object
length-prefixed homogeneous array.
- #str(s) ⇒ Object
- #to_s ⇒ Object
- #u16(v) ⇒ Object
- #u32(v) ⇒ Object
- #u8(v) ⇒ Object
Constructor Details
#initialize ⇒ Writer
Returns a new instance of Writer.
29 30 31 |
# File 'lib/doom/game/snapshot.rb', line 29 def initialize @buf = +''.b end |
Instance Method Details
#bool(v) ⇒ Object
38 |
# File 'lib/doom/game/snapshot.rb', line 38 def bool(v) = u8(v ? 1 : 0) |
#f64(v) ⇒ Object
37 |
# File 'lib/doom/game/snapshot.rb', line 37 def f64(v) = append([v].pack('E')) |
#i64(v) ⇒ Object
36 |
# File 'lib/doom/game/snapshot.rb', line 36 def i64(v) = append([v].pack('q<')) |
#list(items) ⇒ Object
length-prefixed homogeneous array
47 48 49 50 |
# File 'lib/doom/game/snapshot.rb', line 47 def list(items, &) u32(items.size) items.each(&) end |
#str(s) ⇒ Object
40 41 42 43 44 |
# File 'lib/doom/game/snapshot.rb', line 40 def str(s) bytes = s.to_s.b u16(bytes.bytesize) append(bytes) end |
#to_s ⇒ Object
52 |
# File 'lib/doom/game/snapshot.rb', line 52 def to_s = @buf.dup |
#u16(v) ⇒ Object
34 |
# File 'lib/doom/game/snapshot.rb', line 34 def u16(v) = append([v & 0xffff].pack('S<')) |
#u32(v) ⇒ Object
35 |
# File 'lib/doom/game/snapshot.rb', line 35 def u32(v) = append([v & 0xffffffff].pack('L<')) |
#u8(v) ⇒ Object
33 |
# File 'lib/doom/game/snapshot.rb', line 33 def u8(v) = append([v & 0xff].pack('C')) |