Compare commits
No commits in common. "fff25999c9f0eedfca678f8c99eb89a69f69ada4" and "1500c62e5167e66fac42421a0268833cc1668f45" have entirely different histories.
fff25999c9
...
1500c62e51
2 changed files with 7 additions and 7 deletions
|
@ -10,7 +10,6 @@ maintainer: rhiannon morris <rhi@rhiannon.website>
|
||||||
common deps
|
common deps
|
||||||
default-language: Haskell2010
|
default-language: Haskell2010
|
||||||
default-extensions:
|
default-extensions:
|
||||||
BangPatterns,
|
|
||||||
BlockArguments,
|
BlockArguments,
|
||||||
DerivingStrategies,
|
DerivingStrategies,
|
||||||
DuplicateRecordFields,
|
DuplicateRecordFields,
|
||||||
|
|
|
@ -5,6 +5,7 @@ import IPS.Types
|
||||||
import Data.Attoparsec.ByteString (Parser)
|
import Data.Attoparsec.ByteString (Parser)
|
||||||
import qualified Data.Attoparsec.ByteString as Parse
|
import qualified Data.Attoparsec.ByteString as Parse
|
||||||
import Data.Bits
|
import Data.Bits
|
||||||
|
import Data.Bifunctor
|
||||||
import qualified Data.ByteString as ByteString
|
import qualified Data.ByteString as ByteString
|
||||||
import Data.Functor
|
import Data.Functor
|
||||||
import qualified Data.Vector.Generic as Vector
|
import qualified Data.Vector.Generic as Vector
|
||||||
|
@ -23,17 +24,17 @@ parseBody = uncurry Vector.fromListN <$> go where
|
||||||
go = eof <|> chunk
|
go = eof <|> chunk
|
||||||
eof = Parse.string "EOF" $> (0, [])
|
eof = Parse.string "EOF" $> (0, [])
|
||||||
chunk = liftA2 cons parseChunk go
|
chunk = liftA2 cons parseChunk go
|
||||||
where cons c (!n, cs) = (n + 1, c : cs)
|
where cons c = bimap (+ 1) (c :)
|
||||||
|
|
||||||
parseChunk :: Parser Chunk
|
parseChunk :: Parser Chunk
|
||||||
parseChunk = do
|
parseChunk = do
|
||||||
offset <- parseWord24
|
offset <- parseWord24
|
||||||
size <- parseWord16
|
size₀ <- parseWord16
|
||||||
body <-
|
body <-
|
||||||
if size == 0 then
|
if size₀ == 0 then
|
||||||
liftA2 RLE parseWord16 Parse.anyWord8
|
liftA2 RLE parseWord16 Parse.anyWord8
|
||||||
else
|
else
|
||||||
Normal . makeBytes <$> Parse.take (fromIntegral size)
|
Normal . makeBytes <$> Parse.take (fromIntegral size₀)
|
||||||
pure $ Chunk {offset, body}
|
pure $ Chunk {offset, body}
|
||||||
|
|
||||||
parseWord16 :: Parser Word16
|
parseWord16 :: Parser Word16
|
||||||
|
@ -44,7 +45,7 @@ parseWord24 = parseWordBE 3
|
||||||
|
|
||||||
parseWordBE :: (Integral a, Bits a) => Word -> Parser a
|
parseWordBE :: (Integral a, Bits a) => Word -> Parser a
|
||||||
parseWordBE = go 0 where
|
parseWordBE = go 0 where
|
||||||
go !acc 0 = pure acc
|
go acc 0 = pure acc
|
||||||
go !acc i = do
|
go acc i = do
|
||||||
b <- fromIntegral <$> Parse.anyWord8
|
b <- fromIntegral <$> Parse.anyWord8
|
||||||
go ((acc `shiftL` 8) .|. b) (i - 1)
|
go ((acc `shiftL` 8) .|. b) (i - 1)
|
||||||
|
|
Loading…
Reference in a new issue