Class: Gem::Resolv::DNS::Message::MessageDecoder
- Inherits:
-
Object
- Object
- Gem::Resolv::DNS::Message::MessageDecoder
- Defined in:
- lib/rubygems/vendor/resolv/lib/resolv.rb
Overview
:nodoc:
Instance Method Summary collapse
- #get_bytes(len = @limit - @index) ⇒ Object
- #get_label ⇒ Object
- #get_labels ⇒ Object
- #get_length16 ⇒ Object
- #get_list ⇒ Object
- #get_name ⇒ Object
- #get_question ⇒ Object
- #get_rr ⇒ Object
- #get_string ⇒ Object
- #get_string_list ⇒ Object
- #get_unpack(template) ⇒ Object
-
#initialize(data) {|_self| ... } ⇒ MessageDecoder
constructor
A new instance of MessageDecoder.
- #inspect ⇒ Object
Constructor Details
#initialize(data) {|_self| ... } ⇒ MessageDecoder
Returns a new instance of MessageDecoder.
1565 1566 1567 1568 1569 1570 |
# File 'lib/rubygems/vendor/resolv/lib/resolv.rb', line 1565 def initialize(data) @data = data @index = 0 @limit = data.bytesize yield self end |
Instance Method Details
#get_bytes(len = @limit - @index) ⇒ Object
1590 1591 1592 1593 1594 1595 |
# File 'lib/rubygems/vendor/resolv/lib/resolv.rb', line 1590 def get_bytes(len = @limit - @index) raise DecodeError.new("limit exceeded") if @limit < @index + len d = @data.byteslice(@index, len) @index += len return d end |
#get_label ⇒ Object
1676 1677 1678 |
# File 'lib/rubygems/vendor/resolv/lib/resolv.rb', line 1676 def get_label return Label::Str.new(self.get_string) end |
#get_labels ⇒ Object
1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 |
# File 'lib/rubygems/vendor/resolv/lib/resolv.rb', line 1647 def get_labels prev_index = @index save_index = nil d = [] while true raise DecodeError.new("limit exceeded") if @limit <= @index case @data.getbyte(@index) when 0 @index += 1 if save_index @index = save_index end return d when 192..255 idx = self.get_unpack('n')[0] & 0x3fff if prev_index <= idx raise DecodeError.new("non-backward name pointer") end prev_index = idx if !save_index save_index = @index end @index = idx else d << self.get_label end end end |
#get_length16 ⇒ Object
1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 |
# File 'lib/rubygems/vendor/resolv/lib/resolv.rb', line 1576 def get_length16 len, = self.get_unpack('n') save_limit = @limit @limit = @index + len d = yield(len) if @index < @limit raise DecodeError.new("junk exists") elsif @limit < @index raise DecodeError.new("limit exceeded") end @limit = save_limit return d end |
#get_list ⇒ Object
1635 1636 1637 1638 1639 1640 1641 |
# File 'lib/rubygems/vendor/resolv/lib/resolv.rb', line 1635 def get_list [].tap do |values| while @index < @limit values << yield end end end |
#get_name ⇒ Object
1643 1644 1645 |
# File 'lib/rubygems/vendor/resolv/lib/resolv.rb', line 1643 def get_name return Name.new(self.get_labels) end |
#get_question ⇒ Object
1680 1681 1682 1683 1684 |
# File 'lib/rubygems/vendor/resolv/lib/resolv.rb', line 1680 def get_question name = self.get_name type, klass = self.get_unpack("nn") return name, Resource.get_class(type, klass) end |
#get_rr ⇒ Object
1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 |
# File 'lib/rubygems/vendor/resolv/lib/resolv.rb', line 1686 def get_rr name = self.get_name type, klass, ttl = self.get_unpack('nnN') typeclass = Resource.get_class(type, klass) res = self.get_length16 do begin typeclass.decode_rdata self rescue => e raise DecodeError, e., e.backtrace end end res.instance_variable_set :@ttl, ttl return name, ttl, res end |
#get_string ⇒ Object
1618 1619 1620 1621 1622 1623 1624 1625 |
# File 'lib/rubygems/vendor/resolv/lib/resolv.rb', line 1618 def get_string raise DecodeError.new("limit exceeded") if @limit <= @index len = @data.getbyte(@index) raise DecodeError.new("limit exceeded") if @limit < @index + 1 + len d = @data.byteslice(@index + 1, len) @index += 1 + len return d end |
#get_string_list ⇒ Object
1627 1628 1629 1630 1631 1632 1633 |
# File 'lib/rubygems/vendor/resolv/lib/resolv.rb', line 1627 def get_string_list strings = [] while @index < @limit strings << self.get_string end strings end |
#get_unpack(template) ⇒ Object
1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 |
# File 'lib/rubygems/vendor/resolv/lib/resolv.rb', line 1597 def get_unpack(template) len = 0 template.each_byte {|byte| byte = "%c" % byte case byte when ?c, ?C len += 1 when ?n len += 2 when ?N len += 4 else raise StandardError.new("unsupported template: '#{byte.chr}' in '#{template}'") end } raise DecodeError.new("limit exceeded") if @limit < @index + len arr = @data.unpack("@#{@index}#{template}") @index += len return arr end |
#inspect ⇒ Object
1572 1573 1574 |
# File 'lib/rubygems/vendor/resolv/lib/resolv.rb', line 1572 def inspect "\#<#{self.class}: #{@data.byteslice(0, @index).inspect} #{@data.byteslice(@index..-1).inspect}>" end |