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 PacketGen::Types::Fields object

Returns:

Since:

  • 3.1.6



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

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



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

def read(str)
  super
end

#szInteger

Size of object as binary string

Returns:

  • (Integer)

Since:

  • 3.1.6



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

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



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

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



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

def to_s
  super
end

#type_nameString

Get type name

Returns:

Since:

  • 3.1.6



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

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