   [^Buffer buffer value]
   (let [bit-index (get-bit-index buffer)]
     (when (== 0 bit-index)
-      (let [bit-pos (get-bit-pos buffer)]
-        (when (pos? bit-pos)
-          (put-byte-at buffer bit-pos (get-bit-value buffer))))
-      (let [pos (get-pos buffer)]
-        (set-bit-pos buffer pos)
+      (let [bit-position (get-bit-position buffer)]
+        (when (pos? bit-position)
+          (put-byte-at buffer bit-position (get-bit-value buffer))))
+      (let [position (get-position buffer)]
+        (set-bit-position buffer position)
         (set-bit-value buffer 0)
-        (set-pos buffer (unchecked-inc pos))))
+        (set-position buffer (unchecked-inc position))))
     (let [bit-mask (bit-shift-left 1 bit-index)]
       (set-bit-index buffer (rem (unchecked-inc bit-index) 8))
       (set-bit-value buffer (unchecked-byte (if value

  #?(:clj (:import [java.nio ByteBuffer ByteOrder])))

(definterface+ IMikronBitBuffer
  (^long   get-bit-pos* []            "Gets the current position of the buffer.")
  (^Object set-bit-pos* [^long value] "Sets the current position of the buffer.")

  (^long   get-bit-index* []            "Gets the current index of the buffer.")
  (^Object set-bit-index* [^long value] "Sets the current index of the buffer.")

  ^mikron.runtime.buffer.IMikronByteBuffer [^Buffer buffer]
  (.-byte-buffer buffer))

(defn get-bit-position
  "Gets the bit position of `buffer`."
  #?(:clj {:inline (fn [buffer] `(get-bit-position* (get-bit-buffer ~buffer)))})
  ^long [^Buffer buffer]
  (get-bit-position* (get-bit-buffer buffer)))

(defn set-bit-position
  "Sets the bit position of `buffer` to `value`."
  #?(:clj {:inline (fn [buffer value] `(set-bit-position* (get-bit-buffer ~buffer) ~value))})
  [^Buffer buffer ^long value]
  (set-bit-position* (get-bit-buffer buffer) value))

(defn get-bit-index
  "Gets the bit index of `buffer`."
