Class: Resolv::DNS::SvcParams

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/resolv.rb

Overview

SvcParams for service binding RRs. [RFC9460]

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(params = []) ⇒ SvcParams

Create a list of SvcParams with the given initial content.

params has to be an enumerable of +SvcParam+s. If its content has +SvcParam+s with the duplicate key, the one appears last takes precedence.



1823
1824
1825
1826
1827
1828
1829
# File 'lib/resolv.rb', line 1823

def initialize(params = [])
  @params = {}

  params.each do |param|
    add param
  end
end

Class Method Details

.decode(msg) ⇒ Object

:nodoc:



1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
# File 'lib/resolv.rb', line 1883

def self.decode(msg) # :nodoc:
  params = msg.get_list do
    key, = msg.get_unpack('n')
    msg.get_length16 do
      SvcParam::ClassHash[key].decode(msg)
    end
  end

  return self.new(params)
end

Instance Method Details

#[](key) ⇒ Object

Get SvcParam for the given key in this list.



1834
1835
1836
# File 'lib/resolv.rb', line 1834

def [](key)
  @params[canonical_key(key)]
end

#add(param) ⇒ Object

Add the SvcParam param to this list, overwriting the existing one with the same key.



1855
1856
1857
# File 'lib/resolv.rb', line 1855

def add(param)
  @params[param.class.key_number] = param
end

#countObject

Get the number of SvcParams in this list.



1841
1842
1843
# File 'lib/resolv.rb', line 1841

def count
  @params.count
end

#delete(key) ⇒ Object

Remove the SvcParam with the given key and return it.



1862
1863
1864
# File 'lib/resolv.rb', line 1862

def delete(key)
  @params.delete(canonical_key(key))
end

#each(&block) ⇒ Object

Enumerate the +SvcParam+s in this list.



1869
1870
1871
1872
# File 'lib/resolv.rb', line 1869

def each(&block)
  return enum_for(:each) unless block
  @params.each_value(&block)
end

#empty?Boolean

Get whether this list is empty.

Returns:

  • (Boolean)


1848
1849
1850
# File 'lib/resolv.rb', line 1848

def empty?
  @params.empty?
end

#encode(msg) ⇒ Object

:nodoc:



1874
1875
1876
1877
1878
1879
1880
1881
# File 'lib/resolv.rb', line 1874

def encode(msg) # :nodoc:
  @params.keys.sort.each do |key|
    msg.put_pack('n', key)
    msg.put_length16 do
      @params.fetch(key).encode(msg)
    end
  end
end