@hackage / storable-offset

Storable offsets for record fields

Latest0.1.0.0

About

Metadata

  • Last updated , by OleksiiDivak
  • License BSD-3-Clause
  • Categories FFI
  • Maintained by: Oleksii Divak <frozenwitness@gmail.com>

  • Lottery factor: 0

Links

Installation

Readme

storable-offset

Tiny helper library that provides a way to access fields of Storable data structures.

Given an instance

{-# LANGUAGE DataKinds
           , MultiParamTypeClasses #-}

instance Offset "fieldName" DataType where rawOffset = #{offset data_type, field_name}

, you can now peek/poke fieldName directly using

{-# LANGUAGE TypeApplications #-}

peek $ offset @"fieldName" (ptr @DataType)

poke (offset @"fieldName" ptr) (val @DataType)