Class: RuneRb::Cache::Index

Inherits:
Object
  • Object
show all
Includes:
RuneRb::Core::Logging
Defined in:
lib/rune/cache/index.rb

Overview

An instance of a CacheIndex points to a file in the ‘main_file_cache.dat` file.

Since:

  • 0.1.0

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from RuneRb::Core::Logging

#err, #err!, #log, #log!

Constructor Details

#initialize(size, block) ⇒ Index

Constructs a new Cache Index given the block size and identifier.

Parameters:

  • size (Integer)

    the size of the block file

  • block (Integer)

    the first block of the file

Since:

  • 0.1.0



19
20
21
22
# File 'lib/rune/cache/index.rb', line 19

def initialize(size, block)
  @size = size
  @block = block
end

Instance Attribute Details

#blockInteger (readonly)

Note:

This attribute is read-only.

Returns the block of the file.

Returns:

  • (Integer)

    the block of the file.

Since:

  • 0.1.0



14
15
16
# File 'lib/rune/cache/index.rb', line 14

def block
  @block
end

#sizeInteger (readonly)

Note:

This attribute is read-only.

Returns the size of the file.

Returns:

  • (Integer)

    the size of the file.

Since:

  • 0.1.0



9
10
11
# File 'lib/rune/cache/index.rb', line 9

def size
  @size
end

Class Method Details

.decode(buffer) ⇒ Object

Decodes a buffer into an index.

Parameters:

  • buffer (String)

    the buffer to decode.

Since:

  • 0.1.0



26
27
28
29
30
31
32
33
34
35
# File 'lib/rune/cache/index.rb', line 26

def self.decode(buffer)
  #raise "Unexpected buffer length. Buffer #{buffer.bytesize}, Expected: #{RuneRb::Core::INDEX_SIZE}" unless buffer.bytesize == RuneRb::Core::INDEX_SIZE

  bytes = buffer.unpack('C*')
  size =  bytes[0] << 16 | bytes[1] << 8 | bytes[2]
  block = bytes[3] << 16 | bytes[4] << 8 | bytes[5]
  info "Decoded index: size: #{size}, block: #{block}"

  RuneRb::Cache::Index.new(size, block)
end