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

Inherits:
Object
  • Object
show all
Defined in:
lib/rubygems/vendor/resolv/lib/resolv.rb

Overview

:nodoc:

Instance Method Summary collapse

Constructor Details

#initialize {|_self| ... } ⇒ MessageEncoder

Returns a new instance of MessageEncoder.

Yields:

  • (_self)

Yield Parameters:



1482
1483
1484
1485
1486
# File 'lib/rubygems/vendor/resolv/lib/resolv.rb', line 1482

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

Instance Method Details

#put_bytes(d) ⇒ Object



1492
1493
1494
# File 'lib/rubygems/vendor/resolv/lib/resolv.rb', line 1492

def put_bytes(d)
  @data << d
end

#put_label(d) ⇒ Object



1540
1541
1542
# File 'lib/rubygems/vendor/resolv/lib/resolv.rb', line 1540

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

#put_labels(d, compress: true) ⇒ Object



1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
# File 'lib/rubygems/vendor/resolv/lib/resolv.rb', line 1524

def put_labels(d, compress: true)
  d.each_index {|i|
    domain = d[i..-1]
    if compress && 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_length16Object



1500
1501
1502
1503
1504
1505
1506
1507
# File 'lib/rubygems/vendor/resolv/lib/resolv.rb', line 1500

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, compress: true) ⇒ Object



1520
1521
1522
# File 'lib/rubygems/vendor/resolv/lib/resolv.rb', line 1520

def put_name(d, compress: true)
  put_labels(d.to_a, compress: compress)
end

#put_pack(template, *d) ⇒ Object



1496
1497
1498
# File 'lib/rubygems/vendor/resolv/lib/resolv.rb', line 1496

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

#put_string(d) ⇒ Object



1509
1510
1511
1512
# File 'lib/rubygems/vendor/resolv/lib/resolv.rb', line 1509

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

#put_string_list(ds) ⇒ Object



1514
1515
1516
1517
1518
# File 'lib/rubygems/vendor/resolv/lib/resolv.rb', line 1514

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

#to_sObject



1488
1489
1490
# File 'lib/rubygems/vendor/resolv/lib/resolv.rb', line 1488

def to_s
  return @data
end