def to_bytes()
      packer = Packer.new()

      full_flags = ((@qr     << 15) & 0x8000) |
                   ((@opcode << 11) & 0x7800) |
                   ((@flags  <<  7) & 0x0780) |
                   ((@rcode  <<  0) & 0x000F)

      packer.pack('nnnnnn',
        @trn_id,             # trn_id
        full_flags,          # qr, opcode, flags, rcode
        @questions.length(), # qdcount
        @answers.length(),   # ancount
        0,                   # nscount (we don't handle)
        0,                   # arcount (we don't handle)
      )

      questions.each do |q|
        q.pack(packer)
      end

      answers.each do |a|
        a.pack(packer)
      end

      return packer.get()
    end
def to_bytes()
      packer = Packer.new()

      full_flags = ((@qr     << 15) & 0x8000) |
                   ((@opcode << 11) & 0x7800) |
                   ((@flags  <<  7) & 0x0780) |
                   ((@rcode  <<  0) & 0x000F)

      packer.pack('nnnnnn',
        @trn_id,             # trn_id
        full_flags,          # qr, opcode, flags, rcode
        @questions.length(), # qdcount
        @answers.length(),   # ancount
        0,                   # nscount (we don't handle)
        0,                   # arcount (we don't handle)
      )

      questions.each do |q|
        q.pack(packer)
      end

      answers.each do |a|
        a.pack(packer)
      end

      return packer.get()
    end
Serialize the packet to an array of bytes.