Class: BinaryPList::Trailer

Inherits:
Struct
  • Object
show all
Defined in:
lib/binary_plist/trailer.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#num_objectsObject

Returns the value of attribute num_objects

Returns:

  • (Object)

    the current value of num_objects



14
15
16
# File 'lib/binary_plist/trailer.rb', line 14

def num_objects
  @num_objects
end

#object_ref_sizeObject

Returns the value of attribute object_ref_size

Returns:

  • (Object)

    the current value of object_ref_size



14
15
16
# File 'lib/binary_plist/trailer.rb', line 14

def object_ref_size
  @object_ref_size
end

#offset_int_sizeObject

Returns the value of attribute offset_int_size

Returns:

  • (Object)

    the current value of offset_int_size



14
15
16
# File 'lib/binary_plist/trailer.rb', line 14

def offset_int_size
  @offset_int_size
end

#offset_table_offsetObject

Returns the value of attribute offset_table_offset

Returns:

  • (Object)

    the current value of offset_table_offset



14
15
16
# File 'lib/binary_plist/trailer.rb', line 14

def offset_table_offset
  @offset_table_offset
end

#sort_versionObject

Returns the value of attribute sort_version

Returns:

  • (Object)

    the current value of sort_version



14
15
16
# File 'lib/binary_plist/trailer.rb', line 14

def sort_version
  @sort_version
end

#top_objectObject

Returns the value of attribute top_object

Returns:

  • (Object)

    the current value of top_object



14
15
16
# File 'lib/binary_plist/trailer.rb', line 14

def top_object
  @top_object
end

Class Method Details

.load(io) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/binary_plist/trailer.rb', line 20

def self.load(io)
  bytes = io.is_a?(String) ? bytes : io.read(32)

  sort_version, offset_int_size, object_ref_size,
    num_objects, top_object, offset_table_offset =
    bytes.unpack("@5 CCC Q>3")

  Trailer.new(sort_version,
              offset_int_size,
              object_ref_size,
              num_objects,
              top_object,
              offset_table_offset)
end

Instance Method Details

#check_object_offset!(offset) ⇒ Object



40
41
42
43
44
# File 'lib/binary_plist/trailer.rb', line 40

def check_object_offset!(offset)
  return if object_table_range.include?(offset)

  raise OffsetOutOfRangeError, offset: offset, range: object_table_range
end

#check_object_reference!(ref) ⇒ Object



46
47
48
49
50
# File 'lib/binary_plist/trailer.rb', line 46

def check_object_reference!(ref)
  return unless num_objects < ref

  raise ObjectOutOfRangeError, num: num, max: trailer.num_objects
end

#object_table_rangeObject



52
53
54
# File 'lib/binary_plist/trailer.rb', line 52

def object_table_range
  (8...offset_table_offset)
end

#offset_table_rangeObject



56
57
58
# File 'lib/binary_plist/trailer.rb', line 56

def offset_table_range
  (offset_table_offset..offset_table_offset + num_objects * offset_int_size)
end

#packObject



35
36
37
38
# File 'lib/binary_plist/trailer.rb', line 35

def pack
  [0, 0, 0, 0, 0, sort_version, offset_int_size, object_ref_size,
   num_objects, top_object, offset_table_offset].pack("C8Q>3")
end