Module: RuneRb::System::Patches::Writeable

Includes:
Network::Constants
Defined in:
app/system/patches/writeable.rb

Overview

Since:

  • 0.9.3

Constant Summary

Constants included from Network::Constants

Network::Constants::BIT_MASK_OUT, Network::Constants::BYTE_MUTATIONS, Network::Constants::BYTE_ORDERS, Network::Constants::BYTE_SIZE, Network::Constants::CONNECTION_TYPES, Network::Constants::LOGIN_RESPONSES, Network::Constants::MESSAGE_SIZES, Network::Constants::PROTOCOL_TEMPLATES, Network::Constants::RW_TYPES, Network::Constants::SIDEBAR_INTERFACES

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#accessSymbol (readonly)

Returns the access mode for the Message.

Returns:

  • (Symbol)

    the access mode for the Message.

Since:

  • 0.9.3


8
9
10
# File 'app/system/patches/writeable.rb', line 8

def access
  @access
end

#writeableString (readonly)

Returns the writeable content.

Returns:

  • (String)

    the writeable content.

Since:

  • 0.9.3


5
6
7
# File 'app/system/patches/writeable.rb', line 5

def writeable
  @writeable
end

Instance Method Details

#compileObject

Compiles the writeable message

Since:

  • 0.9.3


45
46
47
# File 'app/system/patches/writeable.rb', line 45

def compile
  @type == :RAW ? @payload : @payload.prepend(RuneRb::Network::Message.compile_header(@header, @type))
end

#switch_accessObject

Since:

  • 0.9.3


49
50
51
# File 'app/system/patches/writeable.rb', line 49

def switch_access
  @access = @access == :BYTE ? :BIT : :BYTE
end

#write(value, opt = { type: :byte, mutation: :STD, order: :BIG }) ⇒ Object

Write data to the payload.

Parameters:

  • value (Integer, String, Message, Array)

    the value to write.

  • opt (Hash) (defaults to: { type: :byte, mutation: :STD, order: :BIG })

    options for the write operation.

Since:

  • 0.9.3


13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'app/system/patches/writeable.rb', line 13

def write(value, opt = { type: :byte, mutation: :STD, order: :BIG })
  return unless RuneRb::Network::Message.validate(self, :write, opt)

  case opt[:type]
  when *RW_TYPES[:bit] then write_bit(value)
  when *RW_TYPES[:byte] then write_byte(value, opt[:mutation] || :STD)
  when *RW_TYPES[:short] then write_short(value, opt[:mutation] || :STD, opt[:order] || :BIG)
  when *RW_TYPES[:medium] then write_medium(value, opt[:mutation] || :STD, opt[:order] || :BIG)
  when *RW_TYPES[:int] then write_int(value, opt[:mutation] || :STD, opt[:order] || :BIG)
  when *RW_TYPES[:long] then write_long(value, opt[:mutation] || :STD, opt[:order] || :BIG)
  when *RW_TYPES[:smart] then write_smart(value, opt[:mutation] || :STD)
  when *RW_TYPES[:string] then write_string(value)
  when :bits then write_bits(value, opt[:amount])
  when :bytes then write_bytes(value)
  when :reverse_bytes then write_reverse_bytes(value)
  when :padding then write_padding(value)
  end
  update_length

  self
rescue StandardError => e
  puts 'An error occurred while writing!'
  puts e
  puts e.backtrace
end

#writeable?Boolean

A function to indicate the Message is writable.

Returns:

  • (Boolean)

Since:

  • 0.9.3


40
41
42
# File 'app/system/patches/writeable.rb', line 40

def writeable?
  true
end