Class: Doom::Game::Snapshot::Writer

Inherits:
Object
  • Object
show all
Defined in:
lib/doom/game/snapshot.rb

Overview

A cursor-based binary writer, so record offsets are never hand-managed.

Instance Method Summary collapse

Constructor Details

#initializeWriter

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_sObject



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'))