Class: NBTFile::ListWriterState

Inherits:
Object
  • Object
show all
Includes:
Tokens, WriteMethods
Defined in:
lib/nbtfile.rb

Instance Method Summary collapse

Methods included from WriteMethods

#emit_byte, #emit_byte_array, #emit_double, #emit_float, #emit_int, #emit_integer, #emit_list_header, #emit_long, #emit_short, #emit_string, #emit_type, #emit_value

Methods included from CommonMethods

#sign_bit

Constructor Details

#initialize(cont, type, capturing) ⇒ ListWriterState

Returns a new instance of ListWriterState.



433
434
435
436
437
438
439
# File 'lib/nbtfile.rb', line 433

def initialize(cont, type, capturing)
  @cont = cont
  @type = type
  @count = 0
  @value = StringIO.new()
  @capturing = capturing
end

Instance Method Details

#_emit_item(io, type, value) ⇒ Object



459
460
461
462
# File 'lib/nbtfile.rb', line 459

def _emit_item(io, type, value)
  @count += 1
  emit_value(@value, type, value, @value, self, @cont)
end

#emit_item(io, value) ⇒ Object



455
456
457
# File 'lib/nbtfile.rb', line 455

def emit_item(io, value)
  _emit_item(io, @type, value)
end

#emit_token(io, token) ⇒ Object



441
442
443
444
445
446
447
448
449
450
451
452
453
# File 'lib/nbtfile.rb', line 441

def emit_token(io, token)
  type = token.class

  if type == TAG_End
    out = @capturing || io
    emit_list_header(out, @type, @count)
    out.write(@value.string)
  elsif type != @type
    raise RuntimeError, "unexpected token #{token.class}, expected #{@type}"
  end

  _emit_item(io, type, token.value)
end