storable-offset-0.1.0.0: Storable offsets for record fields
Safe HaskellSafe-Inferred
LanguageHaskell2010

Foreign.Storable.Offset

Description

Utility functions for using Storable to access record fields of data structures.

Functions in this module rely on the TypeApplications pragma (the Offset class itself doesn't).

Synopsis

Offset

class Offset (x :: Symbol) r where Source #

Methods

rawOffset :: Int Source #

Byte distance between the start of datatype r within memory and its field x.

offset :: forall x r a. (HasField x r a, Offset x r) => Ptr r -> Ptr a Source #

Advances a pointer based on field's Offset, inheriting field's type.

Resulting pointer can be used to peek or poke the field directly.

Helper functions

pokeField :: forall x r a. (HasField x r a, Offset x r, Storable a) => Ptr r -> r -> IO () Source #

Retrieves the field and pokes it at proper offset.

Useful for declaring poke for the entire datatype.