class Strum::Server::Packet::Header

A Packet Header object.

Public Class Methods

new(data = {}) click to toggle source

Create a new Header.

# File lib/strum/server/packet/header.rb, line 16
def initialize(data = {})
  self[:OperationCode] = data[:op_code]
  self[:PacketSize]    = data[:size]
  self[:Buffer] = Async::IO::Buffer.new
end

Public Instance Methods

<<(data = {})
Alias for: write
build(type) click to toggle source

Build's this header. @param type [Symbol] - How this Header should be packed. (:Byte, :Short)

Calls superclass method Strum::Internal::Generic#build
# File lib/strum/server/packet/header.rb, line 25
def build(type)
  super
  case type
  when :Byte
    self[:Buffer] << [self[:OperationCode].unsigned(:Byte),
                      self[:PacketSize].unsigned(:Short)].pack('CC')
  when :Short
    self[:Buffer] << [self[:OperationCode].unsigned(:Byte),
                      self[:PacketSize].unsigned(:Short)].pack('nn')
  else
    self[:Buffer] << [self[:OperationCode].unsigned(:Byte),
                      self[:PacketSize].unsigned(:Short)].pack('CC')
  end
  self[:Buffer]
end
write(data = {}) click to toggle source
# File lib/strum/server/packet/header.rb, line 41
def write(data = {})
  self[:OperationCode] = data[:OperationCode] if data[:OperationCode]
  self[:PacketSize] = data[:PacketSize] if data[:PacketSize]
end
Also aliased as: <<