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

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

Overview

:nodoc:

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of MessageEncoder.

Yields:

  • (_self)

Yield Parameters:



1413
1414
1415
1416
1417
# File 'lib/resolv.rb', line 1413

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

Instance Method Details

#put_bytes(d) ⇒ Object



1423
1424
1425
# File 'lib/resolv.rb', line 1423

def put_bytes(d)
  @data << d
end

#put_label(d) ⇒ Object



1469
1470
1471
# File 'lib/resolv.rb', line 1469

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

#put_labels(d) ⇒ Object



1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
# File 'lib/resolv.rb', line 1455

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

#put_length16Object



1431
1432
1433
1434
1435
1436
1437
1438
# File 'lib/resolv.rb', line 1431

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) ⇒ Object



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

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

#put_pack(template, *d) ⇒ Object



1427
1428
1429
# File 'lib/resolv.rb', line 1427

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

#put_string(d) ⇒ Object



1440
1441
1442
1443
# File 'lib/resolv.rb', line 1440

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

#put_string_list(ds) ⇒ Object



1445
1446
1447
1448
1449
# File 'lib/resolv.rb', line 1445

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

#to_sObject



1419
1420
1421
# File 'lib/resolv.rb', line 1419

def to_s
  return @data
end