 
 ;; ## Long Lexicoder
 
-; TODO: use prefix length encoding, otherwise simple values like 0 double in size when escaped.
+(defn- flip-long-sign
+  "Flip the sign bit on a long value."
+  ^long
+  [^long x]
+  (bit-xor x Long/MIN_VALUE))
+
+
+(defn- get-long-byte
+  "Return the `i`th byte in a long, where 0 gives the least significant byte."
+  [l i]
+  (bit-and 0xFF (bit-shift-right l (* i 8))))
+
+
 (defrecord LongLexicoder
   []
 

        (recur (inc i)
               (->
                 (aget ^bytes data (+ offset i))
                 (long)
                 (bit-and 0xFF)
                 (as-> b (if (neg? b) (+ b 256) b))
                 (bit-shift-left (- 56 (* i 8)))
                 (+ value)))
        ; Unflip sign bit.
        (bit-xor value Long/MIN_VALUE)))))


(alter-meta! #'->LongLexicoder assoc :private true)

      (let [bits (Double/doubleToRawLongBits
                   (if (zero? value) 0.0 (double value)))]
        (if (neg? bits)
          (flip-long-sign (bit-not bits))
          bits))))

  (decode*
