Class: Nl::Raw::NlAttr

Inherits:
Struct
  • Object
show all
Defined in:
nl/lib/nl/raw/wire.rb,
nl/lib/nl/raw/wire.rb

Overview

Fixed-format header prepended to every Netlink attribute.

This corresponds to Linux's struct nlattr.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#len ⇒ Integer

Returns attribute length in bytes, including this header but excluding trailing alignment padding.

Returns:

  • (Integer) —

    attribute length in bytes, including this header but excluding trailing alignment padding



112
113
114
115
# File 'nl/lib/nl/raw/wire.rb', line 112

NlAttr = Struct.new(
  :len, #: Integer
  :type, #: Integer
)

#type ⇒ Integer

Returns attribute type combined with optional NLA_F_ flags.

Returns:

  • (Integer) —

    attribute type combined with optional NLA_F_ flags



112
113
114
115
# File 'nl/lib/nl/raw/wire.rb', line 112

NlAttr = Struct.new(
  :len, #: Integer
  :type, #: Integer
)

Class Method Details

.decode(decoder) ⇒ NlAttr

Decodes an attribute header from the decoder's current position.

Parameters:

  • decoder (Decoder) —

    the source decoder

Returns:

  • (NlAttr) —

    the decoded header



129
130
131
132
133
# File 'nl/lib/nl/raw/wire.rb', line 129

def self.decode(decoder)
  obj = new(*decoder.get_values(FORMAT))
  decoder.align_to(Constants::NLA_ALIGNTO)
  obj
end

Instance Method Details

#encode(encoder) ⇒ void

This method returns an undefined value.

Encodes this attribute header at the encoder's current position.

Parameters:

  • encoder (Encoder) —

    the destination encoder



140
141
142
143
144
# File 'nl/lib/nl/raw/wire.rb', line 140

def encode(encoder)
  encoder.reserve(Constants::NLA_HDRLEN)
  encoder.put_values(FORMAT, to_a)
  encoder.align_to(Constants::NLA_ALIGNTO)
end