Safe Haskell | None |
---|---|
Language | Haskell2010 |
Variable length encodings
- Unsigned Little Endian Base 128 (ULEB128)
The word is splitted in chunks of 7 bits, starting from least significant bits. Each chunk is put in a Word8. The highest bit indicates if there is a following byte (0 false, 1 true)
Synopsis
- fromULEB128 :: (Bits a, Monad m, Integral a) => m Word8 -> m a
- toULEB128 :: (Bits a, Monad m, Integral a) => (Word8 -> m ()) -> a -> m ()
- getULEB128 :: (Integral a, Bits a) => Get a
- putULEB128 :: (Integral a, Bits a) => a -> Put
- getSLEB128 :: (Integral a, Bits a) => Get a
- putSLEB128 :: (Integral a, Bits a) => a -> Put
- getLEB128Buffer :: BitOrder -> Get Buffer
Documentation
fromULEB128 :: (Bits a, Monad m, Integral a) => m Word8 -> m a Source #
Convert a stream of ULEB 128 bytes into an Integral
>>>
:set -XBinaryLiterals
>>>
import Control.Monad.Trans.State
>>>
getNext = do { ~(x:xs) <- get; put xs; pure x }
>>>
let x = evalState (fromULEB128 getNext) [0b10000001, 0b01111111] :: Word64
>>>
x == 0b11111110000001
True
toULEB128 :: (Bits a, Monad m, Integral a) => (Word8 -> m ()) -> a -> m () Source #
Convert an Integral into a stream of ULEB128 bytes
>>>
:set -XBinaryLiterals
>>>
:set -XFlexibleContexts
>>>
let f = toULEB128 (putStr . (++ " ") . bitsToString)
>>>
f (0b1001001010101010 :: Word64)
10101010 10100101 00000010