Module

Data.Byte.Codec

Package
purescript-byte-codec
Repository
athanclark/purescript-byte-codec

This is a synthetic interface on top of the lowest-level view JavaScript has over bytes - integers between 0 and 255.

The Flag system is useful for building a byte in a typesafe way; where each "flag" is actually a bit in the integer's value.

The toBinary / fromBinary API is useful for deserializing into a monomorphic type - an array of bits (as Booleans), where the index reflects the bit's significance (big-endian).

#FlagSet Source

newtype FlagSet (fs :: Row Type)

The type parameter to a FlagSet is a row of typelevel numbers, representing the bits present in the set.

Constructors

Instances

#nullFlagSet Source

#flagSetValue Source

flagSetValue :: forall fs. FlagSet fs -> Int

#Flag Source

newtype Flag f

The type parameter to a Flag must be a Data.Typelevel.Num natural number, between 0 and 7 - this also represents its index in the boolean array from getBinary.

Constructors

Instances

#flagValue Source

flagValue :: forall f. Flag f -> Int

#FlagLabel Source

class FlagLabel f (s :: Symbol) | f -> s

Instances

#f0 Source

f0 :: Flag D0

2^0

#f1 Source

f1 :: Flag D1

2^1

#f2 Source

f2 :: Flag D2

2^2

#f3 Source

f3 :: Flag D3

2^3

#f4 Source

f4 :: Flag D4

2^4

#f5 Source

f5 :: Flag D5

2^5

#f6 Source

f6 :: Flag D6

2^6

#f7 Source

f7 :: Flag D7

2^7

#addFlag Source

addFlag :: forall fl fs' fs f. FlagLabel f fl => Lacks fl fs => Cons fl f fs fs' => Flag f -> FlagSet fs -> FlagSet fs'

#getFlag Source

getFlag :: forall fl fs' fs f. FlagLabel f fl => Cons fl f fs fs' => Flag f -> FlagSet fs' -> FlagSet fs

#getFlagUnsafe Source

getFlagUnsafe :: forall fs' fs f. Flag f -> FlagSet fs' -> Maybe (FlagSet fs)

#toBinary Source

toBinary :: Int -> Vec D8 Boolean

Returns a big-endian array of bits - Performs a mod 256 of the input.

#fromBinary Source

fromBinary :: Vec D8 Boolean -> Int

Returns a byte value from an array of big-endian bits.