binrep-0.5.0: Encode precise binary representations directly in types
Safe HaskellSafe-Inferred
LanguageGHC2021

Binrep.Type.Prefix

Synopsis

Documentation

class Prefix a where Source #

Types which may be used as prefixes.

Generally, these will be integer types.

Note that this is separate to binary representation, so endianness is irrelevant.

TODO oops can't use Ints everywhere because of overflow :'( that's OK

Associated Types

type Max a :: Natural Source #

Methods

lenToPfx :: Int -> a Source #

used by put. guaranteed that it fits from refined. that is, lenToPfx <= Max.

pfxToLen :: a -> Int Source #

used by get. better not lie.

Instances

Instances details
Prefix Word16 Source # 
Instance details

Defined in Binrep.Type.Prefix

Associated Types

type Max Word16 :: Natural Source #

Prefix Word32 Source # 
Instance details

Defined in Binrep.Type.Prefix

Associated Types

type Max Word32 :: Natural Source #

Prefix Word8 Source # 
Instance details

Defined in Binrep.Type.Prefix

Associated Types

type Max Word8 :: Natural Source #

Prefix () Source #

Length prefixing with the unit means a length of 0.

This is the only sensible case. 1 doesn't work because refining checks <=.

I think there are laws here, where using this is the same as doing nothing at all.

Instance details

Defined in Binrep.Type.Prefix

Associated Types

type Max () :: Natural Source #

Methods

lenToPfx :: Int -> () Source #

pfxToLen :: () -> Int Source #

Prefix a => Prefix (Endian end a) Source # 
Instance details

Defined in Binrep.Type.Prefix

Associated Types

type Max (Endian end a) :: Natural Source #

Methods

lenToPfx :: Int -> Endian end a Source #

pfxToLen :: Endian end a -> Int Source #