Class: Nl::Protocols::Raw::DataTypes::IndexedArray
- Inherits:
-
Object
- Object
- Nl::Protocols::Raw::DataTypes::IndexedArray
- Defined in:
- lib/nl/protocols/raw.rb
Instance Method Summary collapse
- #decode(decoder) ⇒ Object
- #encode(encoder, values) ⇒ Object
-
#initialize(sub_type) ⇒ IndexedArray
constructor
A new instance of IndexedArray.
Constructor Details
#initialize(sub_type) ⇒ IndexedArray
Returns a new instance of IndexedArray.
364 365 366 |
# File 'lib/nl/protocols/raw.rb', line 364 def initialize(sub_type) @sub_type = sub_type end |
Instance Method Details
#decode(decoder) ⇒ Object
379 380 381 382 383 384 385 386 387 388 389 390 |
# File 'lib/nl/protocols/raw.rb', line 379 def decode(decoder) result = [] while decoder.available? nlattr = Core::NlAttr.decode(decoder) element = decoder.limit(nlattr.len - Core::NLA_HDRLEN) do @sub_type.decode(decoder) end decoder.align_to(Core::NLA_ALIGNTO) result << element end result end |
#encode(encoder, values) ⇒ Object
368 369 370 371 372 373 374 375 376 377 |
# File 'lib/nl/protocols/raw.rb', line 368 def encode(encoder, values) values.each_with_index do |value, i| nlattr = Core::NlAttr.new(0, i + 1) encoder.measure(Endian::Host::U16) do nlattr.encode(encoder) @sub_type.encode(encoder, value) end encoder.align_to(Core::NLA_ALIGNTO) end end |