(defn encode-val [n]
(let [sb (StringBuilder.)
vlq (to-vlq-signed n)]
(loop [digit (bit-and vlq vlq-base-mask)
vlq (bit-shift-right-zero-fill vlq vlq-base-shift)]
(if (pos? vlq)
(let [digit (bit-or digit vlq-continuation-bit)]
(.append sb (base64/encode digit))
(recur (bit-and vlq vlq-base-mask)
(bit-shift-right-zero-fill vlq vlq-base-shift)))
(.append sb (base64/encode digit))))
(str sb)))