Module: RuneRb::Core::ReadableBuffer

Defined in:
lib/rune/core/readable_buffer.rb

Overview

The Readable module contains the functions used to read data from a Buffer object.

Since:

  • 0.1.0

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#bit_accessBoolean (readonly)

Returns is #bit_access enabled?.

Returns:

Since:

  • 0.1.0



7
8
9
# File 'lib/rune/core/readable_buffer.rb', line 7

def bit_access
  @bit_access
end

#bit_positionInteger (readonly)

Returns the current bit position.

Returns:

  • (Integer)

    the current bit position.

Since:

  • 0.1.0



11
12
13
# File 'lib/rune/core/readable_buffer.rb', line 11

def bit_position
  @bit_position
end

Instance Method Details

#finish_accessObject

Completes a bit access by setting the Readable#bit_position to the start of the next byte, then toggling Readable#bit_access.

Since:

  • 0.1.0



39
40
41
42
# File 'lib/rune/core/readable_buffer.rb', line 39

def finish_access
  @bit_position = (@bit_position + 7) / 8
  switch_access
end

#read(type: :byte, signed: false, mutation: :STD, order: :BIG, options: nil) ⇒ Object

Read data from the payload according to the option parameter.

Parameters:

  • type (Symbol) (defaults to: :byte)

    the type of database to read

  • mutation (Symbol) (defaults to: :STD)

    an option mutation to apply to the read value.

Since:

  • 0.1.0



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/rune/core/readable_buffer.rb', line 17

def read(type: :byte, signed: false, mutation: :STD, order: :BIG, options: nil)
  case type
  when :bits then read_bits(options[:amount])
  when :byte then read_byte(signed:, mutation:)
  when :bytes then read_bytes(options[:amount] || 1, mutation:)
  when :short then read_short(signed:, mutation:, order:)
  when :int24 then read_int24(signed:, mutation:, order:)
  when :int then read_int(signed:, mutation:, order:)
  when :long then read_long(signed:, mutation:, order:)
  when :smart then read_smart(signed:, mutation:)
  when :string then read_string
  when :reverse_bytes then read_bytes_reverse(options[:amount] || 1, mutation:)
  else raise "Unrecognized read type! #{type}"
  end
end

#switch_accessObject

Enables or Disables bit reading by setting the Readable#bit_access variable.

Since:

  • 0.1.0



34
35
36
# File 'lib/rune/core/readable_buffer.rb', line 34

def switch_access
  @bit_access = !@bit_access
end