codec-0.1: First-class record construction and bidirectional serialization

Safe HaskellNone
LanguageHaskell2010

Foreign.Codec

Contents

Synopsis

Foreign codecs

type ForeignCodec a = ForeignCodec' a a

A foreign codec for a given a pointer to itself. Use def from Default to get a codec that uses a Storable instance,

type ForeignCodec' p a = Codec (ForeignContext p) (ForeignContext p) a

A foreign codec for a given a pointer to p.

peekWith :: ForeignCodec' p a -> Ptr p -> IO a

Peek a value using a ForeignCodec'.

pokeWith :: ForeignCodec' p a -> Ptr p -> a -> IO ()

Poke a value using a ForeignCodec'.

field :: Int -> ForeignCodec' f a -> ForeignCodec' p a

A codec for a field of a foreign structure, given its byte offset and a sub-codec. You can get an offset easily using {#offset struct_type, field} with hsc2hs.

cast :: (Integral c, Storable c, Integral a) => ForeignCodec' c a

Store any integral type.

cBool :: Integral c => ForeignCodec' c Bool

Store a Bool in any Integral Ptr.

codecFor :: c -> ForeignCodec' c a -> ForeignCodec' c a

Restrict the pointer type of a given codec. Utility function for the numField macro.