       (copy (bytebuffer->inputstream bb) baos)
       (.toByteArray baos))))
 
-
-(defprotocol Encode
-  (encode [value]
-    "Encodes a Clojure value to a ByteBuffer."))
-
-(extend-protocol Encode
-  (Class/forName "[B")
-  (encode [value]
-    (ByteBuffer/wrap value))
-
-  String
-  (encode [value]
-    (let [encoder (.newEncoder (Charset/forName "UTF-8"))]
-      (.encode encoder (CharBuffer/wrap ^String value))))
-
-  Long
-  (encode [value]
-    (.putLong (ByteBuffer/allocate 8) value))
-
-  ByteBuffer
-  (encode [value]
-    value))
 
 
 ;;; Helper functions.

(defn- do-prepared*
  [{:keys [query-state]} prepared consistency args]
  (let [consistency (kw->consistency consistency)
        result (QueryProcessor/processPrepared prepared consistency query-state (map encode args))]
    (when (instance? ResultMessage$Rows result)
      (decode-resultset (.result ^ResultMessage$Rows result)))))


                       ^String name (.. meta name toString)]]
             [name (.compose type column)])
           (into {})))))


(defn abstract-type
  [value]
  (if value
    (condp instance? value
      Boolean BooleanType/instance
      ByteBuffer BytesType/instance
      Double DoubleType/instance
      Float FloatType/instance
      InetAddress InetAddressType/instance
      Integer Int32Type/instance
      List (ListType/getInstance ^AbstractType (abstract-type (first value)))
      Map (MapType/getInstance (abstract-type (ffirst value))
                               (abstract-type (second (first value))))
      Long LongType/instance
      Set (SetType/getInstance ^AbstractType (abstract-type (first value)))
      String UTF8Type/instance
      UUID UUIDType/instance)
    EmptyType/instance))


(defn- encode-value
  [value]
  (let [^AbstractType dbtype (abstract-type value)]
    (.decompose dbtype value)))


;;; Cassandra protocol implementation.
