Module: RuneRb::IO::Readable

Defined in:
lib/rrb/io/readable.rb

Overview

Provides functions for reading integer values from a string-based buffer.

Since:

  • 0.0.1

Instance Method Summary collapse

Instance Method Details

#read(type: :byte, signed: false, mutation: :STD, order: :BIG, options: {}) ⇒ 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.0.1



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/rrb/io/readable.rb', line 11

def read(type: :byte, signed: false, mutation: :STD, order: :BIG, options: {})
  return unless RuneRb::IO::Validation.validate(self, 'read', { bit_access: @bit_access, mutation: mutation, order: order })

  case type
  when :byte then read_byte(signed: signed, mutation: mutation)
  when :bytes then read_bytes(options[:amount] || 1, mutation: mutation)
  when :short then read_short(signed: signed, mutation: mutation, order: order)
  when :medium then read_medium(signed: signed, mutation: mutation, order: order)
  when :int then read_int(signed: signed, mutation: mutation, order: order)
  when :long then read_long(signed: signed, mutation: mutation, order: order)
  when :smart then read_smart(signed: signed, mutation: mutation)
  when :string then read_string
  when :reverse_bytes then read_bytes_reverse(options[:amount] || 1, mutation: mutation)
  else raise TypeError, "Unrecognized read type! Expected: [byte bytes short medium int long smart string reverse_bytes] | Received: #{type}"
  end
end