1module BitParser exposing
17import Bytes exposing (Bytes)
18import Bytes.Decode as BD
19import Bytes.Encode as BE
22run : BitParser a -> Bytes -> Maybe a
23run (BitParser f) bytes =
24 BD.decode (f { running = Nothing, offset = 0 }) bytes |> Maybe.map Tuple.second
27type alias BitParserState =
28 { running : Maybe { byte : Int, length : Int }
34 = BitParser (BitParserState -> BD.Decoder ( BitParserState, a ))
37getOffset : BitParser Int
39 BitParser (\state -> BD.succeed ( state, state.offset ))
45 (\{ running, offset } ->
55 ( { running = Just { byte = Bitwise.shiftRightBy 1 i, length = 7 }
62 Just { byte, length } ->
65 ( { running = Nothing, offset = newOffset }, byte )
68 ( { running = Just { byte = Bitwise.shiftRightBy 1 byte, length = length - 1 }
77rawBits : Int -> BitParser (List Int)
85 bit |> andThen (\b -> map (\x -> b :: x) (go (i - 1)))
91-- PERF: use `bytes` on byte boundaries
94bits : Int -> BitParser Bytes
96 rawBits n |> map bitsToBytes
99intBits : Int -> BitParser Int
101 rawBits n |> map bitsToInt
104bitsToInt : List Int -> Int
106 List.foldr (\b acc -> Bitwise.shiftLeftBy 1 acc |> Bitwise.or b) 0
109bitsToBytes : List Int -> Bytes
117 if List.length bb > 8 then
118 BE.unsignedInt8 (List.take 8 bb |> bitsToInt) :: go (List.drop 8 bb)
121 [ BE.unsignedInt8 (bb |> bitsToInt) ]
123 go bs |> BE.sequence |> BE.encode
128 BE.encode (BE.sequence [])
131andThen : (a -> BitParser b) -> BitParser a -> BitParser b
132andThen f (BitParser g) =
133 BitParser (\s -> g s |> BD.andThen (\( s1, a ) -> f a |> (\(BitParser h) -> h s1)))
136map : (a -> b) -> BitParser a -> BitParser b
138 BitParser (\s -> g s |> BD.map (Tuple.mapSecond f))
141succeed : a -> BitParser a
143 BitParser (\state -> BD.succeed ( state, a ))
148 BitParser (always BD.fail)
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list