Module: RuneRb::Network::Writeable

Defined in:
lib/rune/network/writeable.rb

Overview

The Writeable module contains functions for writing data to a Buffer object.

Since:

  • 0.0.1

Instance Method Summary collapse

Instance Method Details

#write(value, type: :byte, mutation: :STD, signed: false, order: :BIG, options: {}) ⇒ Object

Write data to the payload.

Parameters:

  • value (Integer, String, Message, Array)

    the value to write.

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

    the type of value to write.

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

    an option mutation to apply to the value.

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

    the byte order to write the value.

Since:

  • 0.0.1



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/rune/network/writeable.rb', line 9

def write(value, type: :byte, mutation: :STD, signed: false, order: :BIG, options: {})
  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 :int24 then write_int24(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: signed)
  when :string then write_string(value)
  when :reverse_bytes then write_reverse_bytes(value)
  else raise "Unrecognized write type! #{type}"
  end
end