(
defn-
write-twobit-bytes!
[
^
TwoBitWriter
w
^
bytes
bs
]
(
let
[
len
(
count
bs
)
in
(
ByteBuffer/wrap
bs
)
out
^
ByteBuffer
(
.-buffer
w
)
table
^
bytes
char->twobit
encode-four-bases
#(
->>
(
bit-or
(
bit-shift-left
(
long
(
aget
table
(
.get
in
)
)
)
6
)
(
bit-shift-left
(
long
(
aget
table
(
.get
in
)
)
)
4
)
(
bit-shift-left
(
long
(
aget
table
(
.get
in
)
)
)
2
)
(
long
(
aget
table
(
.get
in
)
)
)
)
unchecked-byte
(
.put
out
)
)
]
(
dotimes
[
_
(
quot
len
1024
)
]
(
ensure-buffer-room!
w
256
)
(
dotimes
[
_
256
]
(
encode-four-bases
)
)
)
(
let
[
remaining
(
rem
len
1024
)
]
(
when
(
pos?
remaining
)
(
ensure-buffer-room!
w
(
quot
(
+
remaining
3
)
4
)
)
(
dotimes
[
_
(
quot
remaining
4
)
]
(
encode-four-bases
)
)
(
when
(
pos?
(
rem
remaining
4
)
)
(
loop
[
b
0
i
(
rem
remaining
4
)
j
1
]
(
if
(
pos?
i
)
(
recur
(
bit-or
b
(
bit-shift-left
(
long
(
aget
table
(
.get
in
)
)
)
(
*
2
(
-
4
j
)
)
)
)
(
dec
i
)
(
inc
j
)
)
(
.put
out
(
unchecked-byte
b
)
)
)
)
)
)
)
)
)