packages feed

derive-storable-plugin-0.2.0.0: test/ids/Handwritten/Instances.hs

{-# OPTIONS_GHC -fplugin Foreign.Storable.Generic.Plugin #-}
{-# OPTIONS_GHC -fplugin-opt=Foreign.Storable.Generic.Plugin:-crash #-} 

module Instances where

import Types
import Foreign.Storable.Generic


instance GStorable Flat where
    gsizeOf _ = 16
    galignment _ = 8
    gpeekByteOff ptr offset = Flat 
        <$> gpeekByteOff ptr offset
        <*> gpeekByteOff ptr (offset+8)
    gpokeByteOff ptr offset (Flat a b) =  
           gpokeByteOff ptr  offset    a
        >> gpokeByteOff ptr (offset+8) b

instance GStorable Nested where 
    gsizeOf _ = 16
    galignment _ = 8
    gpeekByteOff ptr offset = Nested <$> (Flat 
        <$> gpeekByteOff ptr offset
        <*> gpeekByteOff ptr (offset+8))
    gpokeByteOff ptr offset (Nested (Flat a b)) =  
           gpokeByteOff ptr  offset    a
        >> gpokeByteOff ptr (offset+8) b

instance GStorable Nested2 where
    gsizeOf _ = 16
    galignment _ = 8
    gpeekByteOff ptr offset = Nested2 <$> (Nested <$> (Flat 
        <$> gpeekByteOff ptr offset
        <*> gpeekByteOff ptr (offset+8)))
    gpokeByteOff ptr offset (Nested2 (Nested (Flat a b))) =  
           gpokeByteOff ptr  offset    a
        >> gpokeByteOff ptr (offset+8) b