hcobs-0.1.0.1: An implementation of the Consistent Overhead Byte Stuffing algorithm

Safe HaskellNone
LanguageHaskell2010

Data.Stuffed

Description

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]
Synopsis

Documentation

data Stuffed (a :: Nat) Source #

Wrapper for Lazy Bytestrings, parametrized on the Byte (Word8, represented as a type-level Nat) to be encoded away.

Instances
Eq (Stuffed a) Source # 
Instance details

Defined in Data.Stuffed

Methods

(==) :: Stuffed a -> Stuffed a -> Bool #

(/=) :: Stuffed a -> Stuffed a -> Bool #

Ord (Stuffed a) Source # 
Instance details

Defined in Data.Stuffed

Methods

compare :: Stuffed a -> Stuffed a -> Ordering #

(<) :: Stuffed a -> Stuffed a -> Bool #

(<=) :: Stuffed a -> Stuffed a -> Bool #

(>) :: Stuffed a -> Stuffed a -> Bool #

(>=) :: Stuffed a -> Stuffed a -> Bool #

max :: Stuffed a -> Stuffed a -> Stuffed a #

min :: Stuffed a -> Stuffed a -> Stuffed a #

Show (Stuffed a) Source # 
Instance details

Defined in Data.Stuffed

Methods

showsPrec :: Int -> Stuffed a -> ShowS #

show :: Stuffed a -> String #

showList :: [Stuffed a] -> ShowS #

Generic (Stuffed a) Source # 
Instance details

Defined in Data.Stuffed

Associated Types

type Rep (Stuffed a) :: Type -> Type #

Methods

from :: Stuffed a -> Rep (Stuffed a) x #

to :: Rep (Stuffed a) x -> Stuffed a #

Semigroup (Stuffed a) Source # 
Instance details

Defined in Data.Stuffed

Methods

(<>) :: Stuffed a -> Stuffed a -> Stuffed a #

sconcat :: NonEmpty (Stuffed a) -> Stuffed a #

stimes :: Integral b => b -> Stuffed a -> Stuffed a #

Monoid (Stuffed a) Source # 
Instance details

Defined in Data.Stuffed

Methods

mempty :: Stuffed a #

mappend :: Stuffed a -> Stuffed a -> Stuffed a #

mconcat :: [Stuffed a] -> Stuffed a #

type Rep (Stuffed a) Source # 
Instance details

Defined in Data.Stuffed

type Rep (Stuffed a) = D1 (MetaData "Stuffed" "Data.Stuffed" "hcobs-0.1.0.1-F00nRvWXBEHLlicQFVOXTU" True) (C1 (MetaCons "Stuffed" PrefixI False) (S1 (MetaSel (Nothing :: Maybe Symbol) NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 ByteString)))

stuff :: forall a. IsByte a => ByteString -> Stuffed a Source #

unstuff :: forall a. IsByte a => Stuffed a -> ByteString Source #

unwrap :: Stuffed a -> ByteString Source #

Extract the encoded bytestring from a Stuffed