Class: Nl::DataTypes::IndexedArray
Instance Method Summary collapse
- #coerce(values, context: nil) ⇒ Object
- #decode(decoder, context: nil, nlattr_type_flags: 0) ⇒ Object
- #encode(encoder, values, context: nil) ⇒ Object
-
#initialize(sub_type) ⇒ IndexedArray
constructor
A new instance of IndexedArray.
Methods inherited from Base
Constructor Details
#initialize(sub_type) ⇒ IndexedArray
Returns a new instance of IndexedArray.
420 421 422 |
# File 'nl/lib/nl/datatypes.rb', line 420 def initialize(sub_type) @sub_type = sub_type end |
Instance Method Details
#coerce(values, context: nil) ⇒ Object
435 436 437 |
# File 'nl/lib/nl/datatypes.rb', line 435 def coerce(values, context: nil) values.map { @sub_type.coerce(it, context:) } end |
#decode(decoder, context: nil, nlattr_type_flags: 0) ⇒ Object
439 440 441 442 443 444 445 446 447 448 449 450 451 |
# File 'nl/lib/nl/datatypes.rb', line 439 def decode(decoder, context: nil, nlattr_type_flags: 0) result = [] while decoder.available? nlattr = Raw::NlAttr.decode(decoder) flags = nlattr.type & (Raw::NLA_F_NESTED | Raw::NLA_F_NET_BYTEORDER) element = decoder.limit(nlattr.len - Raw::NLA_HDRLEN) do @sub_type.decode(decoder, context:, nlattr_type_flags: flags) end decoder.align_to(Raw::NLA_ALIGNTO) result << element end result end |
#encode(encoder, values, context: nil) ⇒ Object
424 425 426 427 428 429 430 431 432 433 |
# File 'nl/lib/nl/datatypes.rb', line 424 def encode(encoder, values, context: nil) values.each_with_index do |value, i| nlattr = Raw::NlAttr.new(0, i + 1) encoder.measure(Endian::Host::U16) do nlattr.encode(encoder) @sub_type.encode(encoder, value, context:) end encoder.align_to(Raw::NLA_ALIGNTO) end end |