-;; Copyright (c) 2015 Andrey Antukh <niwi@niwi.nz>
+;; Copyright (c) 2015-2016 Andrey Antukh <niwi@niwi.nz>
 ;; All rights reserved.
 ;;
 ;; Redistribution and use in source and binary forms, with or without

  es6 typed arrays (from javascript environments)."
  #?(:clj
     (:import java.nio.ByteBuffer
              io.netty.buffer.ByteBuf
              io.netty.buffer.ByteBufAllocator)))

(defprotocol IBufferShort
  (read-short [_ pos] "Read short integer (16 bits) from buffer.")

  (get-capacity [buff]
    (reduce #(+ %1 (get-capacity %2)) 0 buff)))

;; --- ES6 Typed Arrays

#?(:cljs
   (extend-type js/DataView
     IBufferShort
     (read-short [buff pos]
       (.getInt16 buff pos (= *byteorder* :little-endian)))
     (write-short [buff pos value]
       (.setInt16 buff pos value (= *byteorder* :little-endian)))
     (read-ushort [buff pos]
       (.getUint16 buff pos (= *byteorder* :little-endian)))
     (write-ushort [buff pos value]
       (.setUint16 buff pos value (= *byteorder* :little-endian)))

     IBufferInt
     (read-int [buff pos]
       (.getInt32 buff pos (= *byteorder* :little-endian)))
     (write-int [buff pos value]
       (.setInt32 buff pos value (= *byteorder* :little-endian)))
     (read-uint [buff pos]
       (.getUint32 buff pos (= *byteorder* :little-endian)))
     (write-uint [buff pos value]
       (.setUint32 buff pos value (= *byteorder* :little-endian)))

     IBufferFloat
     (read-float [buff pos]
       (.getFloat32 buff pos (= *byteorder* :little-endian)))
     (write-float [buff pos value]
       (.setFloat32 buff pos value (= *byteorder* :little-endian)))

     IBufferDouble
     (read-double [buff pos]
       (.getFloat64 buff pos (= *byteorder* :little-endian)))
     (write-double [buff pos value]
       (.setFloat64 buff pos value (= *byteorder* :little-endian)))

     IBufferByte
     (read-byte [buff pos]
