hcobs 0.1.0.0 → 0.1.0.1
raw patch · 7 files changed
+36/−12 lines, 7 filessetup-changedPVP ok
version bump matches the API change (PVP)
API changes (from Hackage documentation)
Files
- README.md +1/−1
- Setup.hs +2/−0
- hcobs.cabal +3/−3
- src/Data/Stuffed.hs +24/−2
- src/Data/Stuffed/Internal.hs +4/−3
- test/Allocation.hs +1/−1
- test/Spec.hs +1/−2
README.md view
@@ -4,7 +4,7 @@ Haskell implementation of the [Consistent Overhead Byte Stuffing](https://en.wikipedia.org/wiki/Consistent_Overhead_Byte_Stuffing) algorithm. -It provides a `Stuffed` newtype wrapper for Lazy Bytestrings, which is parametrized on the Byte (Word8, representated as a type-level Nat) to be encoded away.+It provides a `Stuffed` newtype wrapper for Lazy Bytestrings, which is parametrized on the Byte (Word8, represented as a type-level Nat) to be encoded away. The implementation tries to be as efficient as possible, type safe and easy to use. If you have a "sink" like
+ Setup.hs view
@@ -0,0 +1,2 @@+import Distribution.Simple+main = defaultMain
hcobs.cabal view
@@ -1,5 +1,5 @@ name: hcobs-version: 0.1.0.0+version: 0.1.0.1 synopsis: An implementation of the Consistent Overhead Byte Stuffing algorithm description: An implementation of the Consistent Overhead Byte Stuffing algorithm. homepage: https://github.com/berdario/hcobs#readme@@ -69,12 +69,12 @@ , bytestring , deepseq , base64-bytestring- default-language: Haskell2010+ default-language: Haskell2010 benchmark mainbench type: exitcode-stdio-1.0 hs-source-dirs: src, bench- other-modules: Data.Stuffed+ other-modules: Data.Stuffed main-is: MainBench.hs build-depends: base , bytestring
src/Data/Stuffed.hs view
@@ -8,6 +8,26 @@ {-# LANGUAGE DataKinds #-} {-# LANGUAGE KindSignatures #-} +-- | This module tries to be as efficient as possible, type safe and easy to use. If you have a "sink" like+--+-- > sink :: Stuffed 0 -> IO ()+-- > sink = undefined+--+-- You'd then simply be able to encode a Bytestring with+--+-- > sink $ stuff bytes+--+-- You can try this out in ghci with:+--+-- >>> :set -XOverloadedStrings+-- >>> :set -XDataKinds+-- >>> import Data.Stuffed+-- >>> let stuffedBytes = stuff "a\0b\0c" :: Stuffed 0+-- >>> unpack $ unwrap stuffedBytes -- directly access the underlying bytestring+-- [2,97,2,98,2,99]+-- >>> unpack $ unstuff stuffedBytes+-- [97,0,98,0,99]+ module Data.Stuffed ( Stuffed , stuff@@ -27,10 +47,11 @@ import Data.Word (Word8) import GHC.Generics (Generic) import GHC.Types (Nat)-import Prelude hiding (concat, length, null, splitAt)+import Prelude hiding (concat, length, null, splitAt, last) import Data.Stuffed.Internal (IsByte) +-- | Wrapper for Lazy Bytestrings, parametrized on the Byte (Word8, represented as a type-level 'Nat') to be encoded away. newtype Stuffed (a :: Nat) = Stuffed ByteString deriving (Eq, Ord, Show, Semigroup, Monoid, Generic) @@ -49,7 +70,7 @@ buildStuffed :: Word8 -> B.ByteString -> B.ByteString buildStuffed excluded bs = B.cons last stuffed where- excludedOffset = fromIntegral excluded + 1+ excludedOffset = excluded + 1 swapExcluded n current | current == excluded = (excludedOffset, n) | otherwise = (n + 1, current) (last, stuffed) = B.mapAccumR swapExcluded excludedOffset bs@@ -68,5 +89,6 @@ swapExcluded n current | n == excluded = (current - 1, excluded) | otherwise = (n - 1, current) +-- | Extract the encoded bytestring from a Stuffed unwrap :: Stuffed a -> ByteString unwrap (Stuffed bs) = bs
src/Data/Stuffed/Internal.hs view
@@ -8,13 +8,14 @@ (IsByte) where +import Prelude import GHC.TypeLits (CmpNat, ErrorMessage (..), KnownNat, TypeError) import GHC.Types (Nat) type IsByte a = (KnownNat a, IsByteLT a (CmpNat a 256) ~ 'True) type family IsByteLT (n :: Nat) x where- IsByteLT n 'LT = 'True- IsByteLT n _ = TypeError (Text "Stuffed can be parametrized only on bytes" :$$:- Text "(" :<>: ShowType n :<>: Text " is not within range [0, 255]" )+ IsByteLT _ 'LT = 'True+ IsByteLT n _ = TypeError ('Text "Stuffed can be parametrized only on bytes" ':$$:+ 'Text "(" ':<>: 'ShowType n ':<>: 'Text " is not within range [0, 255]" )
test/Allocation.hs view
@@ -13,7 +13,7 @@ instance NFData (Stuffed a) -stuffZero :: _ -> Stuffed 0+stuffZero :: BSL.ByteString -> Stuffed 0 stuffZero = stuff main :: IO ()
test/Spec.hs view
@@ -10,7 +10,7 @@ import Control.Monad.Morph (generalize, hoist) import Data.ByteString.Lazy (ByteString, length, notElem, fromStrict) import Data.Proxy (Proxy(..))-import Data.Reflection (Reifies, reflect, reifyNat)+import Data.Reflection (reflect, reifyNat) import Data.Word (Word8) import GHC.Exts (Constraint) import GHC.TypeLits (KnownNat, CmpNat)@@ -20,7 +20,6 @@ import Prelude hiding (length, notElem) import System.Exit (exitFailure) import Unsafe.Coerce (unsafeCoerce)-import System.IO.Unsafe import Data.Stuffed (Stuffed, stuff, unstuff, unwrap)