bit-protocol-0.2.3.0: Encode binary protocols with some odd bit numbers into a bytestring

Safe HaskellNone
LanguageHaskell2010

Data.BitProtocol

Contents

Synopsis

Documentation

data BitsVal a Source #

Constructors

BitsVal 

Fields

Instances
Eq a => Eq (BitsVal a) Source # 
Instance details

Defined in Data.BitProtocol

Methods

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

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

Show a => Show (BitsVal a) Source # 
Instance details

Defined in Data.BitProtocol

Methods

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

show :: BitsVal a -> String #

showList :: [BitsVal a] -> ShowS #

Generic (BitsVal a) Source # 
Instance details

Defined in Data.BitProtocol

Associated Types

type Rep (BitsVal a) :: * -> * #

Methods

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

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

Num a => Semigroup (BitsVal a) Source # 
Instance details

Defined in Data.BitProtocol

Methods

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

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

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

Integral a => Monoid (BitsVal a) Source #

WARNING! Can overflow, so only concat on a small number of items

Instance details

Defined in Data.BitProtocol

Methods

mempty :: BitsVal a #

mappend :: BitsVal a -> BitsVal a -> BitsVal a #

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

Arbitrary a => Arbitrary (BitsVal a) Source # 
Instance details

Defined in Data.BitProtocol

Methods

arbitrary :: Gen (BitsVal a) #

shrink :: BitsVal a -> [BitsVal a] #

type Rep (BitsVal a) Source # 
Instance details

Defined in Data.BitProtocol

type Rep (BitsVal a) = D1 (MetaData "BitsVal" "Data.BitProtocol" "bit-protocol-0.2.3.0-2DEq4wlTM6ZD0TMOS1pZ9U" False) (C1 (MetaCons "BitsVal" PrefixI True) (S1 (MetaSel (Just "bvBitsNum") NoSourceUnpackedness NoSourceStrictness DecidedStrict) (Rec0 Natural) :*: S1 (MetaSel (Just "bvVal") NoSourceUnpackedness NoSourceStrictness DecidedStrict) (Rec0 a)))

encodeBS8 :: (Bits a, Integral a, Show a) => [BitsVal a] -> ByteString Source #

Converts a list of chars into a bytestring via construction of 8-bit chars. Pads with zeroes on the right if a sum is not divisible by 8.

parseBS8 :: (Bits a, Integral a, Show a) => [Natural] -> ByteString -> ([BitsVal a], BitsVal a, ByteString) Source #

Parse a ByteString by a given spec. Return the values consumed, a leftover BitsVal (will be 'BitsVal 0 0' for fully-consumed byte, something else for a half-consumed one) and a leftover ByteString tail.

parseBS8Prefixed :: (Bits a, Integral a, Show a) => [Natural] -> ByteString -> BitsVal a -> ([BitsVal a], BitsVal a, ByteString) Source #

Parse a ByteString which also has some non-consumed prefix with a number of bits under 8 usually.

helpers / nice things to have

numberToBits :: (Integral a, Bits a) => BitsVal a -> [Bool] Source #

Convert a number into a list of bools describing every bit.

internal

bitsValBiggerToCharUnsafe :: (Bits a, Integral a, Show a) => BitsVal a -> ([Word8], BitsVal a) Source #

Convert left 8 bits to a list of Word8, while giving a leftover value). Assumes that the BitsVal argument's length is more than 8.

readBitValue :: (Bits a, Integral a, Show a) => Natural -> BitsVal a -> ByteString -> (BitsVal a, BitsVal a) Source #

Read a single BitsVal from a BitsVal which wasn't consumed (part of a byte) and some ByteString big enough to cover that value