    (extend-type ByteBuf
      IBufferShort
      (read-short [buff pos]
-       (.getShort buff pos))
+       (if (= *byteorder* :little-endian)
+         (.getShortLE buff pos)
+         (.getShort buff pos)))
      (write-short [buff pos value]
-       (.setShort buff pos value))
+       (if (= *byteorder* :little-endian)
+         (.setShortLE buff pos value)
+         (.setShort buff pos value)))
      (read-ushort [buff pos]
-       (let [val (.getShort buff pos)]
+       (let [val (read-short buff pos)]
          (bit-and 0xFFFF (Integer. (int val)))))
      (write-ushort [buff pos value]
        (let [value (.shortValue (Integer. (int value)))]
-         (.setShort buff pos value)))
+         (write-short buff pos value)))
 
      IBufferInt
      (read-int [buff pos]
-       (.getInt buff pos))
+       (if (= *byteorder* :little-endian)
+         (.getIntLE buff pos)
+         (.getInt buff pos)))
      (write-int [buff pos value]
-       (.setInt buff pos value))
+       (if (= *byteorder* :little-endian)
+         (.setIntLE buff pos value)
+         (.setInt buff pos value)))
      (read-uint [buff pos]
-       (let [val (.getInt buff pos)]
+       (let [val (read-int buff pos)]
          (bit-and 0xFFFFFFFF (Long. (long val)))))
      (write-uint [buff pos value]
        (let [value (.intValue (Long. (long value)))]
-         (.setInt buff pos value)))
+         (write-int buff pos value)))
 
      IBufferLong
      (read-long [buff pos]
-       (.getLong buff pos))
+       (if (= *byteorder* :little-endian)
+         (.getLongLE buff pos)
+         (.getLong buff pos)))
      (write-long [buff pos value]
-       (.setLong buff pos value))
+       (if (= *byteorder* :little-endian)
+         (.setLongLE buff pos value)
+         (.setLong buff pos value)))
      (read-ulong [buff pos]
-       (let [val (.getLong buff pos)
+       (let [val (read-long buff pos)
              ^bytes magnitude (-> (ByteBuffer/allocate 8) (.putLong val) .array)]
          (bigint (BigInteger. 1 magnitude))))
      (write-ulong [buff pos value]
        (let [value (.longValue (bigint value))]
-         (.setLong buff pos value)))
+         (write-long buff pos value)))
 
      IBufferFloat
      (read-float [buff pos]
-       (.getFloat buff pos))
+       (if (= *byteorder* :little-endian)
+         (.getFloatLE buff pos)
+         (.getFloat buff pos)))
      (write-float [buff pos value]
-       (.setFloat buff pos value))
+       (if (= *byteorder* :little-endian)
+         (.setFloatLE buff pos value)
+         (.setFloat buff pos value)))
 
      IBufferDouble
      (read-double [buff pos]
-       (.getDouble buff pos))
+       (if (= *byteorder* :little-endian)
+         (.getDoubleLE buff pos)
+         (.getDouble buff pos)))
      (write-double [buff pos value]
-       (.setDouble buff pos value))
+       (if (= *byteorder* :little-endian)
+         (.setDoubleLE buff pos value)
+         (.setDouble buff pos value)))
 
      IBufferByte
      (read-byte [buff pos]

;; Copyright (c) 2015 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
              java.nio.ByteOrder
              io.netty.buffer.ByteBuf
              io.netty.buffer.ByteBufAllocator)))

(def ^:dynamic *byteorder*
  "Defines the default byte order used for the write and read
  operations on the byte buffers."
  :big-endian)

;; --- Protocols

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