Module: PacketGen::Header::SCTP::Padded32

Included in:
BaseChunk, ErrorMixin, ParameterMixin
Defined in:
lib/packetgen/header/sctp/padded32.rb

Overview

Mixin to handle 32-bit padding in SCTP classes

Since:

  • 3.4.0

Instance Method Summary collapse

Instance Method Details

#padded?bool

Say if binary string is padded

Returns:

  • (bool)

Since:

  • 3.4.0



27
28
29
30
# File 'lib/packetgen/header/sctp/padded32.rb', line 27

def padded?
  str = to_s(no_padding: true)
  (str.size % 4).positive?
end

#to_s(no_padding: false) ⇒ ::String

Handle padding

Parameters:

  • no_padding (Bool) (defaults to: false)

Returns:

  • (::String)

Since:

  • 3.4.0



17
18
19
20
21
22
23
# File 'lib/packetgen/header/sctp/padded32.rb', line 17

def to_s(no_padding: false)
  s = super()
  return s if no_padding

  padlen = -(s.size % -4)
  s << force_binary("\x00" * padlen)
end