Class: NBTUtils::Tag::IntArray

Inherits:
Object
  • Object
show all
Includes:
NBTUtils::Tag
Defined in:
lib/nbt_utils/tag/int_array.rb

Instance Attribute Summary

Attributes included from NBTUtils::Tag

#name, #payload

Instance Method Summary collapse

Methods included from NBTUtils::Tag

add_tag_type, #binary_type_id, included, #name_to_nbt_string, #read_name, #tag_type_to_class, tag_type_to_class, #type_id

Constructor Details

#initialize(io, named: true) ⇒ IntArray

Returns a new instance of IntArray.



10
11
12
13
14
15
16
# File 'lib/nbt_utils/tag/int_array.rb', line 10

def initialize(io, named: true)
  read_name(io) if named

  len = ::BinData::Int32be.new.read(io).value

  @payload = ::BinData::Array.new(type: :int32be, initial_length: len).read(io)
end

Instance Method Details

#set_value(new_value, index) ⇒ Object



30
31
32
33
34
# File 'lib/nbt_utils/tag/int_array.rb', line 30

def set_value(new_value, index)
  b = ::BinData::Int32be.new
  b.value = new_value
  payload[index] = b.to_binary_s
end

#to_nbt_string(named: true) ⇒ Object



22
23
24
25
26
27
28
# File 'lib/nbt_utils/tag/int_array.rb', line 22

def to_nbt_string(named: true)
  result = named ? binary_type_id + name_to_nbt_string : ''
  len = ::BinData::Int32be.new
  len.value = payload.length
  result << len.to_binary_s
  result + payload.to_binary_s
end

#to_s(indent = 0) ⇒ Object



18
19
20
# File 'lib/nbt_utils/tag/int_array.rb', line 18

def to_s(indent = 0)
  (' ' * indent) + "TAG_Int_Array#{name ? "(\"#{name}\")" : ''}: [#{payload.length} bytes]"
end