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.



1920
1921
1922
1923
1924
1925
1926
# File 'lib/resolv.rb', line 1920

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

  params.each do |param|
    add param
  end
end

Class Method Details

.decode(msg) ⇒ Object

:nodoc:



1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
# File 'lib/resolv.rb', line 1980

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.



1931
1932
1933
# File 'lib/resolv.rb', line 1931

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.



1952
1953
1954
# File 'lib/resolv.rb', line 1952

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

#count ⇒ Object

Get the number of SvcParams in this list.



1938
1939
1940
# File 'lib/resolv.rb', line 1938

def count
  @params.count
end

#delete(key) ⇒ Object

Remove the SvcParam with the given key and return it.



1959
1960
1961
# File 'lib/resolv.rb', line 1959

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

#each(&block) ⇒ Object

Enumerate the +SvcParam+s in this list.



1966
1967
1968
1969
# File 'lib/resolv.rb', line 1966

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

#empty? ⇒ Boolean

Get whether this list is empty.

Returns:

  • (Boolean)


1945
1946
1947
# File 'lib/resolv.rb', line 1945

def empty?
  @params.empty?
end

#encode(msg) ⇒ Object

:nodoc:



1971
1972
1973
1974
1975
1976
1977
1978
# File 'lib/resolv.rb', line 1971

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