module PacketGen::Headerable
This mixin module defines minimal API for a class to act as a header in {Packet}. @author Sylvain Daubert @since 3.0.2
Public Class Methods
@api private Extend klass
with {ClassMethods}. @param [Class] klass @return [void]
# File lib/packetgen/headerable.rb, line 34 def self.included(klass) klass.extend ClassMethods end
Public Instance Methods
@abstract This method is called when a header is added to a packet.
This base method does nothing but may be overriden by subclasses.
@param [Packet] packet packet to which self is added @return [void]
# File lib/packetgen/headerable.rb, line 80 def added_to_packet(packet) end
return header method name @return [String]
# File lib/packetgen/headerable.rb, line 46 def method_name return @method_name if defined? @method_name @method_name = protocol_name.downcase.gsub(/::/, '_') end
Reference on packet which owns this header @return [Packet,nil]
# File lib/packetgen/headerable.rb, line 62 def packet @packet ||= nil end
@api private Set packet to which this header belongs @param [Packet] packet @return [Packet] packet
# File lib/packetgen/headerable.rb, line 70 def packet=(packet) @packet = packet added_to_packet(packet) @packet end
@abstract Should be redefined by subclasses. This method should check invariant
fields from header.
Called by {Packet#parse} when guessing first header to check if header is correct @return [Boolean]
# File lib/packetgen/headerable.rb, line 56 def parse? true end
Return header protocol name @return [String]
# File lib/packetgen/headerable.rb, line 40 def protocol_name self.class.protocol_name end
@abstract This method MUST be redefined by subclasses. Populate headerable object from a binary string. @param [String] str @return [self] @raise [NotImplementedError]
# File lib/packetgen/headerable.rb, line 87 def read(str) # Do not call super and rescue NoMethodError: too slow raise NotImplementedError, "#{self.class} should implement #read" if method(:read).super_method.nil? super end