123456789_123456789_123456789_123456789_123456789_

Class: Resolv::DNS::Message::MessageEncoder

Do not use. This class is for internal use only.
Relationships & Source Files
Inherits: Object
Defined in: lib/resolv.rb

Class Method Summary

Instance Method Summary

Constructor Details

.new {|_self| ... } ⇒ MessageEncoder

Yields:

  • (_self)

Yield Parameters:

  • _self (MessageEncoder)

    the object that the method was called on

[ GitHub ]

  
# File 'lib/resolv.rb', line 1447

def initialize
  @data = ''.dup
  @names = {}
  yield self
end

Instance Method Details

#put_bytes(d)

[ GitHub ]

  
# File 'lib/resolv.rb', line 1457

def put_bytes(d)
  @data << d
end

#put_label(d)

[ GitHub ]

  
# File 'lib/resolv.rb', line 1505

def put_label(d)
  self.put_string(d.to_s)
end

#put_labels(d)

[ GitHub ]

  
# File 'lib/resolv.rb', line 1489

def put_labels(d)
  d.each_index {|i|
    domain = d[i..-1]
    if idx = @names[domain]
      self.put_pack("n", 0xc000 | idx)
      return
    else
      if @data.length < 0x4000
        @names[domain] = @data.length
      end
      self.put_label(d[i])
    end
  }
  @data << "\0"
end

#put_length16

[ GitHub ]

  
# File 'lib/resolv.rb', line 1465

def put_length16
  length_index = @data.length
  @data << "\0\0"
  data_start = @data.length
  yield
  data_end = @data.length
  @data[length_index, 2] = [data_end - data_start].pack("n")
end

#put_name(d)

[ GitHub ]

  
# File 'lib/resolv.rb', line 1485

def put_name(d)
  put_labels(d.to_a)
end

#put_pack(template, *d)

[ GitHub ]

  
# File 'lib/resolv.rb', line 1461

def put_pack(template, *d)
  @data << d.pack(template)
end

#put_string(d)

[ GitHub ]

  
# File 'lib/resolv.rb', line 1474

def put_string(d)
  self.put_pack("C", d.length)
  @data << d
end

#put_string_list(ds)

[ GitHub ]

  
# File 'lib/resolv.rb', line 1479

def put_string_list(ds)
  ds.each {|d|
    self.put_string(d)
  }
end

#to_s

[ GitHub ]

  
# File 'lib/resolv.rb', line 1453

def to_s
  return @data
end