# Resolv::DNS::Message::MessageDecoder (Class)

In: | resolv.rb
Parent: | Object

## Methods

get_bytes get_label get_labels get_length16 get_name get_question get_rr get_string get_unpack new

## Public Class methods

new(data) {|self| ...}

[Source]

    # File resolv.rb, line 1147
            def initialize(data)
              @data = data
              @index = 0
              @limit = data.length
              yield self
            end

## Public Instance methods

get_length16() {|len| ...}

[Source]

    # File resolv.rb, line 1154
            def get_length16
              len, = self.get_unpack('n')
              save_limit = @limit
              @limit = @index + len
              d = yield(len)
              if @index < @limit
                raise DecodeError.new("junk exist")
              elsif @limit < @index
                raise DecodeError.new("limit exceed")
              end
              @limit = save_limit
              return d
            end

get_bytes(len = @limit - @index)

[Source]

    # File resolv.rb, line 1168
            def get_bytes(len = @limit - @index)
              d = @data[@index, len]
              @index += len
              return d
            end

get_unpack(template)

[Source]

    # File resolv.rb, line 1174
            def get_unpack(template)
              len = 0
              template.each_byte {|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 exceed") if @limit < @index + len
              arr = @data.unpack("@#{@index}#{template}")
              @index += len
              return arr
            end

get_string()

[Source]

    # File resolv.rb, line 1194
            def get_string
              len = @data[@index]
              raise DecodeError.new("limit exceed") if @limit < @index + 1 + len
              d = @data[@index + 1, len]
              @index += 1 + len
              return d
            end

get_name()

[Source]

    # File resolv.rb, line 1202
            def get_name
              return Name.new(self.get_labels)
            end

get_labels(limit=nil)

[Source]

    # File resolv.rb, line 1206
            def get_labels(limit=nil)
              limit = @index if !limit || @index < limit
              d = []
              while true
                case @data[@index]
                when 0
                  @index += 1
                  return d
                when 192..255
                  idx = self.get_unpack('n')[0] & 0x3fff
                  if limit <= idx
                    raise DecodeError.new("non-backward name pointer")
                  end
                  save_index = @index
                  @index = idx
                  d += self.get_labels(limit)
                  @index = save_index
                  return d
                else
                  d << self.get_label
                end
              end
              return d
            end

get_label()

[Source]

    # File resolv.rb, line 1231
            def get_label
              return Label::Str.new(self.get_string)
            end

get_question()

[Source]

    # File resolv.rb, line 1235
            def get_question
              name = self.get_name
              type, klass = self.get_unpack("nn")
              return name, Resource.get_class(type, klass)
            end

get_rr()

[Source]

    # File resolv.rb, line 1241
            def get_rr
              name = self.get_name
              type, klass, ttl = self.get_unpack('nnN')
              typeclass = Resource.get_class(type, klass)
              return name, ttl, self.get_length16 {typeclass.decode_rdata(self)}
            end

[Validate]