Module: PacketGen::Types::Fieldable

Overview

Mixin to define minimal API for a class to be embbeded as a field in Fields type.

Optional methods

These methods may, optionally, be defined by fieldable types:

  • from_human to load data from a human-readable string.

Author:

  • Sylvain Daubert

Since:

  • 3.1.6

Instance Method Summary collapse

Instance Method Details

#format_inspectString

Format object when inspecting a Field object

Returns:

Since:

  • 3.1.6



60
61
62
# File 'lib/packetgen/types/fieldable.rb', line 60

def format_inspect
  to_human
end

#read(str) ⇒ Fields

This method is abstract.

subclass should overload it.

Populate object from a binary string

Parameters:

Returns:

Since:

  • 3.1.6



32
33
34
# File 'lib/packetgen/types/fieldable.rb', line 32

def read(str)
  super
end

#szInteger

Size of object as binary string

Returns:

  • (Integer)

Since:

  • 3.1.6



45
46
47
# File 'lib/packetgen/types/fieldable.rb', line 45

def sz
  to_s.size
end

#to_humanString

This method is abstract.

subclass should overload it.

Return a human-readbale string

Returns:

Since:

  • 3.1.6



52
53
54
# File 'lib/packetgen/types/fieldable.rb', line 52

def to_human
  super
end

#to_sString

This method is abstract.

subclass should overload it.

Return object as a binary string

Returns:

Since:

  • 3.1.6



39
40
41
# File 'lib/packetgen/types/fieldable.rb', line 39

def to_s
  super
end

#type_nameString

Get type name

Returns:

Since:

  • 3.1.6



21
22
23
# File 'lib/packetgen/types/fieldable.rb', line 21

def type_name
  self.class.to_s.split('::').last
end