File: txt.rb

package info (click to toggle)
ruby-net-dns 0.9.2-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 452 kB
  • sloc: ruby: 3,944; makefile: 6
file content (58 lines) | stat: -rw-r--r-- 1,336 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
module Net # :nodoc:
  module DNS
    class RR
      #------------------------------------------------------------
      # RR type TXT
      #------------------------------------------------------------
      class TXT < RR
        attr_reader :txt

        private

        def build_pack
          str = ""
          @txt.split(" ").each do |txt|
            str += [txt.length, txt].pack("C a*")
          end
          @txt_pack = str
          @rdlength = @txt_pack.size
        end

        def get_data
          @txt_pack
        end

        def subclass_new_from_hash(args)
          if args.key? :txt
            @txt = args[:txt].strip
          else
            raise ArgumentError, ":txt field is mandatory but missing"
          end
        end

        def subclass_new_from_string(str)
          @txt = str.strip
        end

        def subclass_new_from_binary(data, offset)
          off_end = offset + @rdlength
          @txt = ""
          while offset < off_end
            len = data.unpack("@#{offset} C")[0]
            offset += 1
            str = data[offset..offset + len - 1]
            offset += len
            @txt << str << " "
          end
          offset
        end

        private

        def set_type
          @type = Net::DNS::RR::Types.new("TXT")
        end
      end
    end
  end
end