Class: NBTFile::Private::ListEmitterState

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

Instance Method Summary collapse

Methods included from EmitMethods

#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) ⇒ ListEmitterState

Returns a new instance of ListEmitterState.



463
464
465
466
467
468
469
# File 'lib/nbtfile.rb', line 463

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



489
490
491
492
# File 'lib/nbtfile.rb', line 489

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

#emit_item(io, value) ⇒ Object



485
486
487
# File 'lib/nbtfile.rb', line 485

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

#emit_token(io, token) ⇒ Object



471
472
473
474
475
476
477
478
479
480
481
482
483
# File 'lib/nbtfile.rb', line 471

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