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.
Instance Attribute Summary collapse
-
#bit_access ⇒ Boolean
readonly
Is #bit_access enabled?.
-
#bit_position ⇒ Integer
readonly
The current bit position.
Instance Method Summary collapse
-
#finish_access ⇒ Object
Completes a bit access by setting the Readable#bit_position to the start of the next byte, then toggling Readable#bit_access.
-
#read(type: :byte, signed: false, mutation: :STD, order: :BIG, options: nil) ⇒ Object
Read data from the payload according to the option parameter.
-
#switch_access ⇒ Object
Enables or Disables bit reading by setting the Readable#bit_access variable.
Instance Attribute Details
#bit_access ⇒ Boolean (readonly)
Returns is #bit_access enabled?.
7 8 9 |
# File 'lib/rune/core/readable_buffer.rb', line 7 def bit_access @bit_access end |
#bit_position ⇒ Integer (readonly)
Returns the current bit position.
11 12 13 |
# File 'lib/rune/core/readable_buffer.rb', line 11 def bit_position @bit_position end |
Instance Method Details
#finish_access ⇒ Object
Completes a bit access by setting the Readable#bit_position to the start of the next byte, then toggling Readable#bit_access.
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.
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([:amount]) when :byte then read_byte(signed:, mutation:) when :bytes then read_bytes([: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([:amount] || 1, mutation:) else raise "Unrecognized read type! #{type}" end end |
#switch_access ⇒ Object
Enables or Disables bit reading by setting the Readable#bit_access variable.
34 35 36 |
# File 'lib/rune/core/readable_buffer.rb', line 34 def switch_access @bit_access = !@bit_access end |