class Rsrb::Net::Packet

Attributes

buffer[R]

The buffer for this packet

opcode[R]

The opcode for this packet

type[R]

The packet type. Fixed, Variable or Variable Short

Public Class Methods

new(opcode, type, buffer) click to toggle source
# File lib/rsrb/net/packet.rb, line 12
def initialize(opcode, type, buffer)
  @opcode = opcode
  @type = type
  @buffer = buffer
end

Public Instance Methods

<<(data) click to toggle source
# File lib/rsrb/net/packet.rb, line 167
def <<(data)
  @buffer << data
end
empty?() click to toggle source
# File lib/rsrb/net/packet.rb, line 171
def empty?
  @buffer.empty?
end
is_raw() click to toggle source

Is the packet raw data

# File lib/rsrb/net/packet.rb, line 19
def is_raw
  opcode == -1
end
length() click to toggle source
# File lib/rsrb/net/packet.rb, line 175
def length
  @buffer.length
end
read(is, offset, length) click to toggle source

Reads a series of bytes

# File lib/rsrb/net/packet.rb, line 151
def read(is, offset, length)
  (0...length).each {|e|
    is[offset + e] = read_byte
  }
end
read_byte() click to toggle source

Reads a byte from the array, and seeks forward.

# File lib/rsrb/net/packet.rb, line 24
def read_byte
  val = @buffer.unpack("c").first
  @buffer.slice!(0...1)
  val
end
read_byte_a() click to toggle source

Reads a byte type a, and seeks forward.

# File lib/rsrb/net/packet.rb, line 77
def read_byte_a
  (read_byte - 128).byte
end
read_byte_c() click to toggle source

Reads byte type c from the array, and seeks forward.

# File lib/rsrb/net/packet.rb, line 67
def read_byte_c
  (-read_byte).byte
end
read_byte_s() click to toggle source

Reads byte type s from the array, and seeks forward.

# File lib/rsrb/net/packet.rb, line 72
def read_byte_s
  (128 - read_byte).byte
end
read_bytes(size) click to toggle source

Reads several bytes from the array, and seeks forward.

# File lib/rsrb/net/packet.rb, line 31
def read_bytes(size)
  @buffer.slice!(0...size)
end
read_int() click to toggle source

Reads an int from the array, and seeks forward.

# File lib/rsrb/net/packet.rb, line 55
def read_int
  (read_ubyte << 24) + (read_ubyte << 16) + (read_ubyte << 8) + read_ubyte
end
read_int1() click to toggle source

Reads a V1 integer.

# File lib/rsrb/net/packet.rb, line 115
def read_int1

end
read_int2() click to toggle source

Reads a V2 integer.

# File lib/rsrb/net/packet.rb, line 120
def read_int2

end
read_leshort() click to toggle source

Reads a little-endian short from the array, and seeks forward.

# File lib/rsrb/net/packet.rb, line 82
def read_leshort
  i = read_ubyte | (read_ubyte << 8)
  
              if i > 32767
                      i -= 0x10000
  end
                    
              i.short
end
read_leshort_a() click to toggle source

Reads a little-endian short type a from the array, and seeks forward.

# File lib/rsrb/net/packet.rb, line 104
def read_leshort_a
  i = (read_byte - 128).ubyte | (read_ubyte << 8)
  
              if i > 32767
                      i -= 0x10000
  end
                    
              i.short
end
read_long() click to toggle source

Reads a long from the array, and seeks forward.

# File lib/rsrb/net/packet.rb, line 60
def read_long
  l = (read_int & 0xffffffff).long
  l1 = (read_int & 0xffffffff).long
  return ((l << 32) + l1).long
end
read_reverse(is, offset, length) click to toggle source

Reads a series of bytes in reverse, and seeks forward.

# File lib/rsrb/net/packet.rb, line 141
def read_reverse(is, offset, length)
  
end
read_reverse_a(is, offset, length) click to toggle source

Reads a series of bytes type a in reverse, and seeks forward.

# File lib/rsrb/net/packet.rb, line 146
def read_reverse_a(is, offset, length)
  
end
read_short() click to toggle source

Reads a short from the array, and seeks forward.

# File lib/rsrb/net/packet.rb, line 41
def read_short
  val = @buffer.unpack("n").first
  @buffer.slice!(0...2)
  val
end
read_short_a() click to toggle source

Reads a short type a from the array, and seeks forward.

# File lib/rsrb/net/packet.rb, line 93
def read_short_a
  i = (read_ubyte << 8) | (read_byte - 128).ubyte

              if i > 32767
                      i -= 0x10000
  end
                    
              i.short
end
read_smart() click to toggle source

Reads a smart

# File lib/rsrb/net/packet.rb, line 158
def read_smart
  
end
read_str(terminator = 10) click to toggle source

Reads a string from the array, and seeks forward.

# File lib/rsrb/net/packet.rb, line 130
def read_str(terminator = 10)
  str = ""
  while @buffer.length > 0 and (b = @buffer.unpack("C").first) != terminator
    str << b.chr
    @buffer.slice!(0...1)
  end
  @buffer.slice!(0...1)
  str
end
read_tribyte() click to toggle source

Reads a three byte integer, and seeks forward.

# File lib/rsrb/net/packet.rb, line 125
def read_tribyte
  
end
read_ubyte() click to toggle source

Reads an unsigned byte from the array, and seeks forward.

# File lib/rsrb/net/packet.rb, line 36
def read_ubyte
  read_byte.ubyte
end
read_ushort() click to toggle source

Reads a short from the array, and seeks forward.

# File lib/rsrb/net/packet.rb, line 48
def read_ushort
  val = @buffer.unpack("S").first
  @buffer.slice!(0...2)
  val
end
read_usmart() click to toggle source

Reads an unsigned smart

# File lib/rsrb/net/packet.rb, line 163
def read_usmart
  
end
size() click to toggle source
# File lib/rsrb/net/packet.rb, line 179
def size
  @buffer.size
end
slice!(range) click to toggle source
# File lib/rsrb/net/packet.rb, line 183
def slice!(range)
  @buffer.slice!(range)
end