Module: RuneRb::IO::Writeable

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

Overview

Since:

  • 0.0.1

Instance Method Summary collapse

Instance Method Details

#finish_accessObject

Completes bit access.

Since:

  • 0.0.1



40
41
42
43
44
# File 'lib/rrb/io/writeable.rb', line 40

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

#switch_accessObject

Enables or Disables bit writing by setting the Buffer#bit_access variable.

Since:

  • 0.0.1



34
35
36
37
# File 'lib/rrb/io/writeable.rb', line 34

def switch_access
  @bit_access = !@bit_access
  self
end

#write(value, type: :byte, mutation: :STD, order: :BIG, options: {}) ⇒ RuneRb::IO::Message, RuneRb::IO::Writeable

Write data to the payload.

Parameters:

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

    the type of value to write.

  • value (Integer, String, Message, Array)

    the value to write.

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

    mutation that should be applied to the data.

  • order (Symbol) (defaults to: :BIG)

    the order to write the data in

  • options (Hash) (defaults to: {})

    options for the operation

Returns:

Since:

  • 0.0.1



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/rrb/io/writeable.rb', line 12

def write(value, type: :byte, mutation: :STD, order: :BIG, options: {})
  return unless RuneRb::IO::Validation.validate(self, 'write', { mutation: mutation, order: order })

  case type
  when :bits then write_bits(value, options[:amount] || 1)
  when :bit then write_bit(value)
  when :byte then write_byte(value, mutation: mutation)
  when :bytes then write_bytes(value)
  when :short then write_short(value, mutation: mutation, order: order)
  when :medium then write_medium(value, mutation: mutation, order: order)
  when :int then write_int(value, mutation: mutation, order: order)
  when :long then write_long(value, mutation: mutation, order: order)
  when :smart then write_smart(value, mutation: mutation, signed: options[:signed] || false)
  when :string then write_string(value)
  when :reverse_bytes then write_reverse_bytes(value)
  else raise "Unrecognized write type! #{type}"
  end

  self
end