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

Bytezap

Synopsis

Documentation

type Poke# = Addr# -> State# RealWorld -> (# State# RealWorld, Addr# #) Source #

TODO inner poke type

TODO can I change this to

Ptr Word8 -> IO (Ptr Word8)

without any performance loss? it's the same underneath newtypes and datas. Ptr is a data rather than a newtype, but IO is just a newtype.

I originally did this to beat ptr-poker, but idk. Now doubtful.

newtype Poke Source #

Unboxed poke operation.

A newtype allows us a monoidal interface.

Constructors

Poke 

Fields

  • unPoke :: Poke#

    Write at an offset from an address and return the next offset.

    The returned offset must be after the argument offset.

    TODO I use that output order because it matches IO. Probs doesn't matter.

Instances

Instances details
Monoid Poke Source #

The empty Poke simply returns its arguments.

Instance details

Defined in Bytezap

Methods

mempty :: Poke #

mappend :: Poke -> Poke -> Poke #

mconcat :: [Poke] -> Poke #

Semigroup Poke Source #

Sequence two Pokes left-to-right.

Instance details

Defined in Bytezap

Methods

(<>) :: Poke -> Poke -> Poke #

sconcat :: NonEmpty Poke -> Poke #

stimes :: Integral b => b -> Poke -> Poke #

Put Poke Source #

Fairly useless because Poke doesn't have a BLen instance.

Instance details

Defined in Binrep.Put.Bytezap

Methods

put :: Poke -> Poke Source #

GenericFoldMap Poke Source # 
Instance details

Defined in Binrep.Put.Bytezap

Associated Types

type GenericFoldMapC Poke a #

type GenericFoldMapC Poke a Source # 
Instance details

Defined in Binrep.Put.Bytezap

poke :: Poke# -> Poke Source #

Construct a Poke.

runPoke :: Int -> Poke -> ByteString Source #

Allocate a buffer of the given size and run a Poke over it.

The Poke must fill the buffer exactly. If it goes under, you should get some random garbage at the end. If it goes over, your computer will probably explode.

data Write Source #

Instructions on how to perform a sized write.

The Poke in writePoke must write the _exact_ number of bytes specified in writeSize. Otherwise, your computer explodes.

Constructors

Write 

Fields

Instances

Instances details
Monoid Write Source #

The empty Write is the empty Poke, which writes zero bytes.

Instance details

Defined in Bytezap

Methods

mempty :: Write #

mappend :: Write -> Write -> Write #

mconcat :: [Write] -> Write #

Semigroup Write Source #

Sequence the Pokes, sum the sizes.

Instance details

Defined in Bytezap

Methods

(<>) :: Write -> Write -> Write #

sconcat :: NonEmpty Write -> Write #

stimes :: Integral b => b -> Write -> Write #

Show Write Source #

Serialize and show the resulting ByteString.

Instance details

Defined in Bytezap

Methods

showsPrec :: Int -> Write -> ShowS #

show :: Write -> String #

showList :: [Write] -> ShowS #

BLen Write Source # 
Instance details

Defined in Binrep.BLen.Simple

Methods

blen :: Write -> Int Source #

Get Write Source #

Parse a bytestring and... immediate reserialize it.

Note that this _does_ perform work: we make a new bytestring so we don't rely on the input bytestring. To use the input bytestring directly, see Binrep.Type.Thin.

Instance details

Defined in Binrep.Get.Flatparse

Methods

get :: Getter Write Source #

Put Write Source # 
Instance details

Defined in Binrep.Put.Bytezap

Methods

put :: Write -> Poke Source #

Put Write Source # 
Instance details

Defined in Bytezap.Class

Methods

put :: Write -> Write Source #

Get (Thin Write) Source # 
Instance details

Defined in Binrep.Type.Thin

Methods

get :: Getter (Thin Write) Source #

write :: Int -> Poke# -> Write Source #

Construct a Write.