Skip to content

Instantly share code, notes, and snippets.

@reinh
Last active January 3, 2016 17:38
Show Gist options
  • Save reinh/8496570 to your computer and use it in GitHub Desktop.
Save reinh/8496570 to your computer and use it in GitHub Desktop.
encode :: [Word8] => BL.ByteString
encode = runPut . putZSCII
putZSCII :: [Word8] -> Put
putZSCII zstring = do
mapM_
(putWord16be . encodeZchar)
(chunksOf 3 zstring)
putWord16be 0xb1000000000000000
encodeZchar :: [Word8] -> Word16
encodeZchar = go . fmap fromIntegral
where
go [w1, w2, w3] = w1 << 10 .|. w2 << 5 .|. w3
go [w1, w2] = go [w1, w2, 5]
go [w1] = go [w1, 5, 5]
(<<) = shiftL
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment