Class: RuneRb::IO::Message::Header
- Inherits:
-
Struct
- Object
- Struct
- RuneRb::IO::Message::Header
- Defined in:
- lib/rrb/io/message.rb
Overview
Models the heading of a protocol data unit received from a peer socket.
Instance Attribute Summary collapse
-
#length ⇒ Object
Returns the value of attribute length.
-
#op_code ⇒ Object
Returns the value of attribute op_code.
-
#type ⇒ Object
Returns the value of attribute type.
Instance Method Summary collapse
-
#compile_header ⇒ String, NilClass
Generates a binary string representation of the Header object.
- #inspect ⇒ Object
Instance Attribute Details
#length ⇒ Object
Returns the value of attribute length
21 22 23 |
# File 'lib/rrb/io/message.rb', line 21 def length @length end |
#op_code ⇒ Object
Returns the value of attribute op_code
21 22 23 |
# File 'lib/rrb/io/message.rb', line 21 def op_code @op_code end |
#type ⇒ Object
Returns the value of attribute type
21 22 23 |
# File 'lib/rrb/io/message.rb', line 21 def type @type end |
Instance Method Details
#compile_header ⇒ String, NilClass
Generates a binary string representation of the RuneRb::IO::Message::Header object.
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/rrb/io/message.rb', line 25 def compile_header case self.type when :FIXED then [self.op_code].pack('C') # Fixed packet lengths are known by both the client and server, so no length packing is necesssary when :RAW then '' when :VARIABLE_SHORT then [self.op_code, self.length].pack('Cn') # Variable Short packet lengths fall into the range of a short type and can be packed as such when :VARIABLE_BYTE # Variable Byte packet lengths fall into the range of a byte type and can be packed as such if self.length.nonzero? && self.length.positive? [self.op_code, self.length].pack('Cc') elsif self.length.nonzero? && self.length.negative? self.type = :FIXED compile_header end else compile_header end end |
#inspect ⇒ Object
41 42 43 |
# File 'lib/rrb/io/message.rb', line 41 def inspect "[Header]: [OpCode]: #{self.op_code} || [Length]: #{self.length}" end |