Module: PacketGen::Header::MLDv2
- Defined in:
- lib/packetgen/header/mldv2.rb,
lib/packetgen/header/mldv2/mlq.rb,
lib/packetgen/header/mldv2/mlr.rb,
lib/packetgen/header/mldv2/mcast_address_record.rb
Overview
This module contains all MLDv2 specific classes.
Defined Under Namespace
Classes: MLQ, MLR, McastAddressRecord, McastAddressRecords
Class Method Summary collapse
-
.decode(value) ⇒ Integer
Decode value for MLDv2 Max Resp Code.
-
.encode(value) ⇒ Integer
Encode value for MLDv2 Max Resp Code.
Class Method Details
.decode(value) ⇒ Integer
Decode value for MLDv2 Max Resp Code. See RFC 3810 §5.1.3
40 41 42 43 44 45 46 47 48 |
# File 'lib/packetgen/header/mldv2.rb', line 40 def self.decode(value) if value < 32_768 value else mant = value & 0xfff exp = (value >> 12) & 0x7 (0x1000 | mant) << (exp + 3) end end |
.encode(value) ⇒ Integer
Encode value for MLDv2 Max Resp Code. Value may be encoded as a float, so some error may occur. See RFC 3810 §5.1.3
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/packetgen/header/mldv2.rb', line 20 def self.encode(value) if value < 32_768 value elsif value > 8_387_583 0xffff else exp = 0 value >>= 3 while value > 8_191 exp += 1 value >>= 1 end 0x8000 | ((exp & 7) << 12) | (value & 0xfff) end end |