safecopy-0.10.4.2: Binary serialization with version control.

Safe Haskell | Safe-Inferred
Language | Haskell2010

Data.SafeCopy.Internal

Synopsis

- class SafeCopy (MigrateFrom a) => Migrate a where
  - type MigrateFrom a
  - migrate :: MigrateFrom a -> a
- newtype Reverse a = Reverse {
  - unReverse :: a
  }
- data Kind a where
  - Primitive :: Kind a
  - Base :: Kind a
  - Extends :: Migrate a => Proxy (MigrateFrom a) -> Kind a
  - Extended :: Migrate (Reverse a) => Kind a -> Kind a
- isPrimitive :: Kind a -> Bool
- newtype Prim a = Prim {
  - getPrimitive :: a
  }
- class Typeable a => SafeCopy a where
  - version :: Version a
  - kind :: Kind a
  - getCopy :: Contained (Get a)
  - putCopy :: a -> Contained Put
  - internalConsistency :: Consistency a
  - objectProfile :: Profile a
  - errorTypeName :: Proxy a -> String
- class GPutCopy f p where
  - gputCopy :: p -> f p -> Put
- type SafeCopy' a = SafeCopy a
- class GPutFields f p where
  - gputFields :: p -> f p -> RWST () [Put] (Set TypeRep) PutM ()
- class GGetCopy f p where
  - ggetCopy :: p -> Get (f a)
- class GGetFields f p where
  - ggetFields :: p -> StateT (Map TypeRep Int32) Get (Get (f a))
- data DatatypeInfo
  - = ConstructorCount {
    - _size :: Word8
    }
  - | ConstructorInfo {
    - _size :: Word8
    - _code :: Word8
    }
- getSafeGetGeneric :: forall a. SafeCopy a => StateT (Map TypeRep Int32) Get (Get a)
- getSafePutGeneric :: forall a. SafeCopy a => (a -> Contained Put) -> a -> RWST () [Put] (Set TypeRep) PutM ()
- type GSafeCopy a = (SafeCopy a, Generic a, GPutCopy (Rep a) DatatypeInfo, Constructors a)
- safePutGeneric :: forall a. GSafeCopy a => a -> Put
- putCopyDefault :: forall a. GSafeCopy a => a -> Contained Put
- constructGetterFromVersion :: SafeCopy a => Version a -> Kind a -> Either String (Get a)
- safeGet :: SafeCopy a => Get a
- getSafeGet :: forall a. SafeCopy a => Get (Get a)
- safePut :: SafeCopy a => a -> Put
- getSafePut :: forall a. SafeCopy a => PutM (a -> Put)
- extended_extension :: (Migrate a, Migrate (Reverse a)) => Kind a
- extended_base :: Migrate (Reverse a) => Kind a
- extension :: Migrate a => Kind a
- base :: Kind a
- primitive :: Kind a
- newtype Version a = Version {
  - unVersion :: Int32
  }
- castVersion :: Version a -> Version b
- newtype Contained a = Contained {
  - unsafeUnPack :: a
  }
- contain :: a -> Contained a
- data Profile a
  - = PrimitiveProfile
  - | InvalidProfile String
  - | Profile {
    - profileCurrentVersion :: Int32
    - profileSupportedVersions :: [Int32]
    }
- mkProfile :: SafeCopy a => Proxy a -> Profile a
- data Consistency a
  - = Consistent
  - | NotConsistent String
- availableVersions :: SafeCopy a => Proxy a -> [Int32]
- getForwardKind :: Migrate (Reverse a) => Kind a -> Kind (MigrateFrom (Reverse a))
- validChain :: SafeCopy a => Proxy a -> Bool
- checkConsistency :: (SafeCopy a, MonadFail m) => Proxy a -> m b -> m b
- unpureCheckConsistency :: SafeCopy a => Proxy a -> b -> b
- computeConsistency :: forall a. SafeCopy a => Proxy a -> Consistency a
- isObviouslyConsistent :: Kind a -> Bool
- proxyFromConsistency :: Consistency a -> Proxy a
- proxyFromKind :: Kind a -> Proxy a
- consistentFromProxy :: SafeCopy a => Proxy a -> Consistency a
- versionFromProxy :: SafeCopy a => Proxy a -> Version a
- versionFromKind :: SafeCopy a => Kind a -> Version a
- versionFromReverseKind :: SafeCopy (MigrateFrom (Reverse a)) => Kind a -> Version (MigrateFrom (Reverse a))
- kindFromProxy :: SafeCopy a => Proxy a -> Kind a
- data Proxy a = Proxy
- mkProxy :: a -> Proxy a
- asProxyType :: a -> Proxy a -> a
- deriveSafeCopy :: Version a -> Name -> Name -> Q [Dec]
- deriveSafeCopyIndexedType :: Version a -> Name -> Name -> [Name] -> Q [Dec]
- deriveSafeCopySimple :: Version a -> Name -> Name -> Q [Dec]
- deriveSafeCopySimpleIndexedType :: Version a -> Name -> Name -> [Name] -> Q [Dec]
- deriveSafeCopyHappstackData :: Version a -> Name -> Name -> Q [Dec]
- deriveSafeCopyHappstackDataIndexedType :: Version a -> Name -> Name -> [Name] -> Q [Dec]
- data DeriveType
  - = Normal
  - | Simple
  - | HappstackData
- forceTag :: DeriveType -> Bool
- tyVarName :: TyVarBndr s -> Name
- internalDeriveSafeCopy :: DeriveType -> Version a -> Name -> Name -> Q [Dec]
- internalDeriveSafeCopy' :: DeriveType -> Version a -> Name -> Name -> Info -> Q [Dec]
- internalDeriveSafeCopyIndexedType :: DeriveType -> Version a -> Name -> Name -> [Name] -> Q [Dec]
- internalDeriveSafeCopyIndexedType' :: DeriveType -> Version a -> Name -> Name -> [Name] -> Info -> Q [Dec]
- mkPutCopy :: DeriveType -> [(Integer, Con)] -> DecQ
- mkGetCopy :: DeriveType -> String -> [(Integer, Con)] -> DecQ
- mkSafeFunctions :: String -> Name -> Con -> Q ([StmtQ], Type -> Name)
- followSynonyms :: Type -> Q Type
- conSize :: Con -> Int
- conName :: Con -> Name
- conTypes :: Con -> [Type]
- typeName :: Type -> String

# Documentation

class SafeCopy (MigrateFrom a) => Migrate a where Source #

The central mechanism for dealing with version control.

This type class specifies what data migrations can happen and how they happen.

Associated Types

type MigrateFrom a Source #

This is the type we're extending. Each type capable of migration can only extend one other type.

Methods

migrate :: MigrateFrom a -> a Source #

This method specifies how to migrate from the older type to the newer one. It will never be necessary to use this function manually as it all taken care of internally in the library.

#### Instances

Instances details

Migrate Double Source # |
Instance details Defined in Data.SafeCopy.Instances Associated Types type MigrateFrom Double Source # Methods migrate :: MigrateFrom Double -> Double Source #
Migrate Float Source # |
Instance details Defined in Data.SafeCopy.Instances Associated Types type MigrateFrom Float Source # Methods migrate :: MigrateFrom Float -> Float Source #

newtype Reverse a Source #

This is a wrapper type used migrating backwards in the chain of compatible types.

Constructors

Reverse |

Fields

- unReverse :: a

data Kind a where Source #

The kind of a data type determines how it is tagged (if at all).

Primitives kinds (see `primitive`) are not tagged with a version id and hence cannot be extended later.

Extensions (see `extension`) tell the system that there exists a previous version of the data type which should be migrated if needed.

There is also a default kind which is neither primitive nor an extension of a previous type.

Constructors

Primitive :: Kind a |
Base :: Kind a |
Extends :: Migrate a => Proxy (MigrateFrom a) -> Kind a |
Extended :: Migrate (Reverse a) => Kind a -> Kind a |

isPrimitive :: Kind a -> Bool Source #

newtype Prim a Source #

Wrapper for data that was saved without a version tag.

Constructors

Prim |

Fields

- getPrimitive :: a

#### Instances

Instances details

SafeCopy a => SafeCopy (Prim a) Source # |
Instance details Defined in Data.SafeCopy.Instances Methods version :: Version (Prim a) Source # kind :: Kind (Prim a) Source # getCopy :: Contained (Get (Prim a)) Source # putCopy :: Prim a -> Contained Put Source # internalConsistency :: Consistency (Prim a) Source # objectProfile :: Profile (Prim a) Source # errorTypeName :: Proxy (Prim a) -> String Source #

class Typeable a => SafeCopy a where Source #

The centerpiece of this library. Defines a version for a data type together with how it should be serialized/parsed.

Users should define instances of `SafeCopy` for their types even though `getCopy` and `putCopy` can't be used directly. To serialize/parse a data type using `SafeCopy`, see `safeGet` and `safePut`.

Minimal complete definition

Nothing

Methods

version :: Version a Source #

The version of the type.

Only used as a key so it must be unique (this is checked at run-time) but doesn't have to be sequential or continuous.

The default version is '0'.

kind :: Kind a Source #

The kind specifies how versions are dealt with. By default, values are tagged with their version id and don't have any previous versions. See `extension` and the much less used `primitive`.

getCopy :: Contained (Get a) Source #

This method defines how a value should be parsed without also worrying about writing out the version tag. This function cannot be used directly. One should use `safeGet`, instead.

default getCopy :: (GGetCopy (Rep a) DatatypeInfo, Constructors a) => Contained (Get a) Source #

putCopy :: a -> Contained Put Source #

This method defines how a value should be parsed without worrying about previous versions or migrations. This function cannot be used directly. One should use 'safePut, instead.

default putCopy :: (GPutCopy (Rep a) DatatypeInfo, Constructors a) => a -> Contained Put Source #

internalConsistency :: Consistency a Source #

Internal function that should not be overrided. `Consistent` iff the version history is consistent (i.e. there are no duplicate version numbers) and the chain of migrations is valid.

This function is in the typeclass so that this information is calculated only once during the program lifetime, instead of everytime `safeGet` or `safePut` is used.

objectProfile :: Profile a Source #

Version profile.

errorTypeName :: Proxy a -> String Source #

The name of the type. This is only used in error message strings.

default errorTypeName :: Typeable a => Proxy a -> String Source #

#### Instances

Instances details

SafeCopy Int16 Source # |
Instance details Defined in Data.SafeCopy.Instances Methods version :: Version Int16 Source # kind :: Kind Int16 Source # getCopy :: Contained (Get Int16) Source # putCopy :: Int16 -> Contained Put Source # internalConsistency :: Consistency Int16 Source # objectProfile :: Profile Int16 Source # errorTypeName :: Proxy Int16 -> String Source #
SafeCopy Int32 Source # |
Instance details Defined in Data.SafeCopy.Instances Methods version :: Version Int32 Source # kind :: Kind Int32 Source # getCopy :: Contained (Get Int32) Source # putCopy :: Int32 -> Contained Put Source # internalConsistency :: Consistency Int32 Source # objectProfile :: Profile Int32 Source # errorTypeName :: Proxy Int32 -> String Source #
SafeCopy Int64 Source # |
Instance details Defined in Data.SafeCopy.Instances Methods version :: Version Int64 Source # kind :: Kind Int64 Source # getCopy :: Contained (Get Int64) Source # putCopy :: Int64 -> Contained Put Source # internalConsistency :: Consistency Int64 Source # objectProfile :: Profile Int64 Source # errorTypeName :: Proxy Int64 -> String Source #
SafeCopy Int8 Source # |
Instance details Defined in Data.SafeCopy.Instances Methods version :: Version Int8 Source # kind :: Kind Int8 Source # getCopy :: Contained (Get Int8) Source # putCopy :: Int8 -> Contained Put Source # internalConsistency :: Consistency Int8 Source # objectProfile :: Profile Int8 Source # errorTypeName :: Proxy Int8 -> String Source #
SafeCopy Word16 Source # |
Instance details Defined in Data.SafeCopy.Instances Methods version :: Version Word16 Source # kind :: Kind Word16 Source # getCopy :: Contained (Get Word16) Source # putCopy :: Word16 -> Contained Put Source # internalConsistency :: Consistency Word16 Source # objectProfile :: Profile Word16 Source # errorTypeName :: Proxy Word16 -> String Source #
SafeCopy Word32 Source # |
Instance details Defined in Data.SafeCopy.Instances Methods version :: Version Word32 Source # kind :: Kind Word32 Source # getCopy :: Contained (Get Word32) Source # putCopy :: Word32 -> Contained Put Source # internalConsistency :: Consistency Word32 Source # objectProfile :: Profile Word32 Source # errorTypeName :: Proxy Word32 -> String Source #
SafeCopy Word64 Source # |
Instance details Defined in Data.SafeCopy.Instances Methods version :: Version Word64 Source # kind :: Kind Word64 Source # getCopy :: Contained (Get Word64) Source # putCopy :: Word64 -> Contained Put Source # internalConsistency :: Consistency Word64 Source # objectProfile :: Profile Word64 Source # errorTypeName :: Proxy Word64 -> String Source #
SafeCopy Word8 Source # |
Instance details Defined in Data.SafeCopy.Instances Methods version :: Version Word8 Source # kind :: Kind Word8 Source # getCopy :: Contained (Get Word8) Source # putCopy :: Word8 -> Contained Put Source # internalConsistency :: Consistency Word8 Source # objectProfile :: Profile Word8 Source # errorTypeName :: Proxy Word8 -> String Source #
SafeCopy ByteString Source # |
Instance details Defined in Data.SafeCopy.Instances Methods version :: Version ByteString Source # kind :: Kind ByteString Source # getCopy :: Contained (Get ByteString) Source # putCopy :: ByteString -> Contained Put Source # internalConsistency :: Consistency ByteString Source # objectProfile :: Profile ByteString Source # errorTypeName :: Proxy ByteString -> String Source #
SafeCopy ByteString Source # |
Instance details Defined in Data.SafeCopy.Instances Methods version :: Version ByteString Source # kind :: Kind ByteString Source # getCopy :: Contained (Get ByteString) Source # putCopy :: ByteString -> Contained Put Source # internalConsistency :: Consistency ByteString Source # objectProfile :: Profile ByteString Source # errorTypeName :: Proxy ByteString -> String Source #
SafeCopy IntSet Source # |
Instance details Defined in Data.SafeCopy.Instances Methods version :: Version IntSet Source # kind :: Kind IntSet Source # getCopy :: Contained (Get IntSet) Source # putCopy :: IntSet -> Contained Put Source # internalConsistency :: Consistency IntSet Source # objectProfile :: Profile IntSet Source # errorTypeName :: Proxy IntSet -> String Source #
SafeCopy Ordering Source # |
Instance details Defined in Data.SafeCopy.Instances Methods version :: Version Ordering Source # kind :: Kind Ordering Source # getCopy :: Contained (Get Ordering) Source # putCopy :: Ordering -> Contained Put Source # internalConsistency :: Consistency Ordering Source # objectProfile :: Profile Ordering Source # errorTypeName :: Proxy Ordering -> String Source #
SafeCopy CalendarTime Source # |
Instance details Defined in Data.SafeCopy.Instances Methods version :: Version CalendarTime Source # kind :: Kind CalendarTime Source # getCopy :: Contained (Get CalendarTime) Source # putCopy :: CalendarTime -> Contained Put Source # internalConsistency :: Consistency CalendarTime Source # objectProfile :: Profile CalendarTime Source # errorTypeName :: Proxy CalendarTime -> String Source #
SafeCopy ClockTime Source # |
Instance details Defined in Data.SafeCopy.Instances Methods version :: Version ClockTime Source # kind :: Kind ClockTime Source # getCopy :: Contained (Get ClockTime) Source # putCopy :: ClockTime -> Contained Put Source # internalConsistency :: Consistency ClockTime Source # objectProfile :: Profile ClockTime Source # errorTypeName :: Proxy ClockTime -> String Source #
SafeCopy Day Source # |
Instance details Defined in Data.SafeCopy.Instances Methods version :: Version Day Source # kind :: Kind Day Source # getCopy :: Contained (Get Day) Source # putCopy :: Day -> Contained Put Source # internalConsistency :: Consistency Day Source # objectProfile :: Profile Day Source # errorTypeName :: Proxy Day -> String Source #
SafeCopy Month Source # |
Instance details Defined in Data.SafeCopy.Instances Methods version :: Version Month Source # kind :: Kind Month Source # getCopy :: Contained (Get Month) Source # putCopy :: Month -> Contained Put Source # internalConsistency :: Consistency Month Source # objectProfile :: Profile Month Source # errorTypeName :: Proxy Month -> String Source #
SafeCopy TimeDiff Source # |
Instance details Defined in Data.SafeCopy.Instances Methods version :: Version TimeDiff Source # kind :: Kind TimeDiff Source # getCopy :: Contained (Get TimeDiff) Source # putCopy :: TimeDiff -> Contained Put Source # internalConsistency :: Consistency TimeDiff Source # objectProfile :: Profile TimeDiff Source # errorTypeName :: Proxy TimeDiff -> String Source #
SafeCopy Text Source # |
Instance details Defined in Data.SafeCopy.Instances Methods version :: Version Text Source # kind :: Kind Text Source # getCopy :: Contained (Get Text) Source # putCopy :: Text -> Contained Put Source # internalConsistency :: Consistency Text Source # objectProfile :: Profile Text Source # errorTypeName :: Proxy Text -> String Source #
SafeCopy Text Source # |
Instance details Defined in Data.SafeCopy.Instances Methods version :: Version Text Source # kind :: Kind Text Source # getCopy :: Contained (Get Text) Source # putCopy :: Text -> Contained Put Source # internalConsistency :: Consistency Text Source # objectProfile :: Profile Text Source # errorTypeName :: Proxy Text -> String Source #
SafeCopy Day Source # |
Instance details Defined in Data.SafeCopy.Instances Methods version :: Version Day Source # kind :: Kind Day Source # getCopy :: Contained (Get Day) Source # putCopy :: Day -> Contained Put Source # internalConsistency :: Consistency Day Source # objectProfile :: Profile Day Source # errorTypeName :: Proxy Day -> String Source #
SafeCopy AbsoluteTime Source # |
Instance details Defined in Data.SafeCopy.Instances Methods version :: Version AbsoluteTime Source # kind :: Kind AbsoluteTime Source # getCopy :: Contained (Get AbsoluteTime) Source # putCopy :: AbsoluteTime -> Contained Put Source # internalConsistency :: Consistency AbsoluteTime Source # objectProfile :: Profile AbsoluteTime Source # errorTypeName :: Proxy AbsoluteTime -> String Source #
SafeCopy DiffTime Source # |
Instance details Defined in Data.SafeCopy.Instances Methods version :: Version DiffTime Source # kind :: Kind DiffTime Source # getCopy :: Contained (Get DiffTime) Source # putCopy :: DiffTime -> Contained Put Source # internalConsistency :: Consistency DiffTime Source # objectProfile :: Profile DiffTime Source # errorTypeName :: Proxy DiffTime -> String Source #
SafeCopy NominalDiffTime Source # |

Instance details

Defined in Data.SafeCopy.Instances

Methods

version :: Version NominalDiffTime Source #

kind :: Kind NominalDiffTime Source #

getCopy :: Contained (Get NominalDiffTime) Source #

putCopy :: NominalDiffTime -> Contained Put Source #

internalConsistency :: Consistency NominalDiffTime Source #

objectProfile :: Profile NominalDiffTime Source #

errorTypeName :: Proxy NominalDiffTime -> String Source #

SafeCopy UTCTime Source # |
Instance details Defined in Data.SafeCopy.Instances Methods version :: Version UTCTime Source # kind :: Kind UTCTime Source # getCopy :: Contained (Get UTCTime) Source # putCopy :: UTCTime -> Contained Put Source # internalConsistency :: Consistency UTCTime Source # objectProfile :: Profile UTCTime Source # errorTypeName :: Proxy UTCTime -> String Source #
SafeCopy UniversalTime Source # |
Instance details Defined in Data.SafeCopy.Instances Methods version :: Version UniversalTime Source # kind :: Kind UniversalTime Source # getCopy :: Contained (Get UniversalTime) Source # putCopy :: UniversalTime -> Contained Put Source # internalConsistency :: Consistency UniversalTime Source # objectProfile :: Profile UniversalTime Source # errorTypeName :: Proxy UniversalTime -> String Source #
SafeCopy LocalTime Source # |
Instance details Defined in Data.SafeCopy.Instances Methods version :: Version LocalTime Source # kind :: Kind LocalTime Source # getCopy :: Contained (Get LocalTime) Source # putCopy :: LocalTime -> Contained Put Source # internalConsistency :: Consistency LocalTime Source # objectProfile :: Profile LocalTime Source # errorTypeName :: Proxy LocalTime -> String Source #
SafeCopy TimeOfDay Source # |
Instance details Defined in Data.SafeCopy.Instances Methods version :: Version TimeOfDay Source # kind :: Kind TimeOfDay Source # getCopy :: Contained (Get TimeOfDay) Source # putCopy :: TimeOfDay -> Contained Put Source # internalConsistency :: Consistency TimeOfDay Source # objectProfile :: Profile TimeOfDay Source # errorTypeName :: Proxy TimeOfDay -> String Source #
SafeCopy TimeZone Source # |
Instance details Defined in Data.SafeCopy.Instances Methods version :: Version TimeZone Source # kind :: Kind TimeZone Source # getCopy :: Contained (Get TimeZone) Source # putCopy :: TimeZone -> Contained Put Source # internalConsistency :: Consistency TimeZone Source # objectProfile :: Profile TimeZone Source # errorTypeName :: Proxy TimeZone -> String Source #
SafeCopy ZonedTime Source # |
Instance details Defined in Data.SafeCopy.Instances Methods version :: Version ZonedTime Source # kind :: Kind ZonedTime Source # getCopy :: Contained (Get ZonedTime) Source # putCopy :: ZonedTime -> Contained Put Source # internalConsistency :: Consistency ZonedTime Source # objectProfile :: Profile ZonedTime Source # errorTypeName :: Proxy ZonedTime -> String Source #
SafeCopy Integer Source # |
Instance details Defined in Data.SafeCopy.Instances Methods version :: Version Integer Source # kind :: Kind Integer Source # getCopy :: Contained (Get Integer) Source # putCopy :: Integer -> Contained Put Source # internalConsistency :: Consistency Integer Source # objectProfile :: Profile Integer Source # errorTypeName :: Proxy Integer -> String Source #
SafeCopy Natural Source # |
Instance details Defined in Data.SafeCopy.Instances Methods version :: Version Natural Source # kind :: Kind Natural Source # getCopy :: Contained (Get Natural) Source # putCopy :: Natural -> Contained Put Source # internalConsistency :: Consistency Natural Source # objectProfile :: Profile Natural Source # errorTypeName :: Proxy Natural -> String Source #
SafeCopy () Source # |
Instance details Defined in Data.SafeCopy.Instances Methods version :: Version () Source # kind :: Kind () Source # getCopy :: Contained (Get ()) Source # putCopy :: () -> Contained Put Source # internalConsistency :: Consistency () Source # objectProfile :: Profile () Source # errorTypeName :: Proxy () -> String Source #
SafeCopy Bool Source # |
Instance details Defined in Data.SafeCopy.Instances Methods version :: Version Bool Source # kind :: Kind Bool Source # getCopy :: Contained (Get Bool) Source # putCopy :: Bool -> Contained Put Source # internalConsistency :: Consistency Bool Source # objectProfile :: Profile Bool Source # errorTypeName :: Proxy Bool -> String Source #
SafeCopy Char Source # |
Instance details Defined in Data.SafeCopy.Instances Methods version :: Version Char Source # kind :: Kind Char Source # getCopy :: Contained (Get Char) Source # putCopy :: Char -> Contained Put Source # internalConsistency :: Consistency Char Source # objectProfile :: Profile Char Source # errorTypeName :: Proxy Char -> String Source #
SafeCopy Double Source # |
Instance details Defined in Data.SafeCopy.Instances Methods version :: Version Double Source # kind :: Kind Double Source # getCopy :: Contained (Get Double) Source # putCopy :: Double -> Contained Put Source # internalConsistency :: Consistency Double Source # objectProfile :: Profile Double Source # errorTypeName :: Proxy Double -> String Source #
SafeCopy Float Source # |
Instance details Defined in Data.SafeCopy.Instances Methods version :: Version Float Source # kind :: Kind Float Source # getCopy :: Contained (Get Float) Source # putCopy :: Float -> Contained Put Source # internalConsistency :: Consistency Float Source # objectProfile :: Profile Float Source # errorTypeName :: Proxy Float -> String Source #
SafeCopy Int Source # |
Instance details Defined in Data.SafeCopy.Instances Methods version :: Version Int Source # kind :: Kind Int Source # getCopy :: Contained (Get Int) Source # putCopy :: Int -> Contained Put Source # internalConsistency :: Consistency Int Source # objectProfile :: Profile Int Source # errorTypeName :: Proxy Int -> String Source #
SafeCopy Word Source # |
Instance details Defined in Data.SafeCopy.Instances Methods version :: Version Word Source # kind :: Kind Word Source # getCopy :: Contained (Get Word) Source # putCopy :: Word -> Contained Put Source # internalConsistency :: Consistency Word Source # objectProfile :: Profile Word Source # errorTypeName :: Proxy Word -> String Source #
SafeCopy a => SafeCopy (NonEmpty a) Source # |
Instance details Defined in Data.SafeCopy.Instances Methods version :: Version (NonEmpty a) Source # kind :: Kind (NonEmpty a) Source # getCopy :: Contained (Get (NonEmpty a)) Source # putCopy :: NonEmpty a -> Contained Put Source # internalConsistency :: Consistency (NonEmpty a) Source # objectProfile :: Profile (NonEmpty a) Source # errorTypeName :: Proxy (NonEmpty a) -> String Source #
(Integral a, SafeCopy a) => SafeCopy (Ratio a) Source # |
Instance details Defined in Data.SafeCopy.Instances Methods version :: Version (Ratio a) Source # kind :: Kind (Ratio a) Source # getCopy :: Contained (Get (Ratio a)) Source # putCopy :: Ratio a -> Contained Put Source # internalConsistency :: Consistency (Ratio a) Source # objectProfile :: Profile (Ratio a) Source # errorTypeName :: Proxy (Ratio a) -> String Source #
SafeCopy a => SafeCopy (IntMap a) Source # |
Instance details Defined in Data.SafeCopy.Instances Methods version :: Version (IntMap a) Source # kind :: Kind (IntMap a) Source # getCopy :: Contained (Get (IntMap a)) Source # putCopy :: IntMap a -> Contained Put Source # internalConsistency :: Consistency (IntMap a) Source # objectProfile :: Profile (IntMap a) Source # errorTypeName :: Proxy (IntMap a) -> String Source #
SafeCopy a => SafeCopy (Seq a) Source # |
Instance details Defined in Data.SafeCopy.Instances Methods version :: Version (Seq a) Source # kind :: Kind (Seq a) Source # getCopy :: Contained (Get (Seq a)) Source # putCopy :: Seq a -> Contained Put Source # internalConsistency :: Consistency (Seq a) Source # objectProfile :: Profile (Seq a) Source # errorTypeName :: Proxy (Seq a) -> String Source #
(SafeCopy a, Ord a) => SafeCopy (Set a) Source # |
Instance details Defined in Data.SafeCopy.Instances Methods version :: Version (Set a) Source # kind :: Kind (Set a) Source # getCopy :: Contained (Get (Set a)) Source # putCopy :: Set a -> Contained Put Source # internalConsistency :: Consistency (Set a) Source # objectProfile :: Profile (Set a) Source # errorTypeName :: Proxy (Set a) -> String Source #
SafeCopy a => SafeCopy (Tree a) Source # |
Instance details Defined in Data.SafeCopy.Instances Methods version :: Version (Tree a) Source # kind :: Kind (Tree a) Source # getCopy :: Contained (Get (Tree a)) Source # putCopy :: Tree a -> Contained Put Source # internalConsistency :: Consistency (Tree a) Source # objectProfile :: Profile (Tree a) Source # errorTypeName :: Proxy (Tree a) -> String Source #
SafeCopy a => SafeCopy (Prim a) Source # |
Instance details Defined in Data.SafeCopy.Instances Methods version :: Version (Prim a) Source # kind :: Kind (Prim a) Source # getCopy :: Contained (Get (Prim a)) Source # putCopy :: Prim a -> Contained Put Source # internalConsistency :: Consistency (Prim a) Source # objectProfile :: Profile (Prim a) Source # errorTypeName :: Proxy (Prim a) -> String Source #
SafeCopy a => SafeCopy (Vector a) Source # |
Instance details Defined in Data.SafeCopy.Instances Methods version :: Version (Vector a) Source # kind :: Kind (Vector a) Source # getCopy :: Contained (Get (Vector a)) Source # putCopy :: Vector a -> Contained Put Source # internalConsistency :: Consistency (Vector a) Source # objectProfile :: Profile (Vector a) Source # errorTypeName :: Proxy (Vector a) -> String Source #
(SafeCopy a, Prim a) => SafeCopy (Vector a) Source # |
Instance details Defined in Data.SafeCopy.Instances Methods version :: Version (Vector a) Source # kind :: Kind (Vector a) Source # getCopy :: Contained (Get (Vector a)) Source # putCopy :: Vector a -> Contained Put Source # internalConsistency :: Consistency (Vector a) Source # objectProfile :: Profile (Vector a) Source # errorTypeName :: Proxy (Vector a) -> String Source #
(SafeCopy a, Storable a) => SafeCopy (Vector a) Source # |
Instance details Defined in Data.SafeCopy.Instances Methods version :: Version (Vector a) Source # kind :: Kind (Vector a) Source # getCopy :: Contained (Get (Vector a)) Source # putCopy :: Vector a -> Contained Put Source # internalConsistency :: Consistency (Vector a) Source # objectProfile :: Profile (Vector a) Source # errorTypeName :: Proxy (Vector a) -> String Source #
(SafeCopy a, Unbox a) => SafeCopy (Vector a) Source # |
Instance details Defined in Data.SafeCopy.Instances Methods version :: Version (Vector a) Source # kind :: Kind (Vector a) Source # getCopy :: Contained (Get (Vector a)) Source # putCopy :: Vector a -> Contained Put Source # internalConsistency :: Consistency (Vector a) Source # objectProfile :: Profile (Vector a) Source # errorTypeName :: Proxy (Vector a) -> String Source #
SafeCopy a => SafeCopy (Maybe a) Source # |
Instance details Defined in Data.SafeCopy.Instances Methods version :: Version (Maybe a) Source # kind :: Kind (Maybe a) Source # getCopy :: Contained (Get (Maybe a)) Source # putCopy :: Maybe a -> Contained Put Source # internalConsistency :: Consistency (Maybe a) Source # objectProfile :: Profile (Maybe a) Source # errorTypeName :: Proxy (Maybe a) -> String Source #
SafeCopy a => SafeCopy [a] Source # |
Instance details Defined in Data.SafeCopy.Instances Methods version :: Version [a] Source # kind :: Kind [a] Source # getCopy :: Contained (Get [a]) Source # putCopy :: [a] -> Contained Put Source # internalConsistency :: Consistency [a] Source # objectProfile :: Profile [a] Source # errorTypeName :: Proxy [a] -> String Source #
(IArray UArray e, Ix i, SafeCopy e, SafeCopy i) => SafeCopy (UArray i e) Source # |
Instance details Defined in Data.SafeCopy.Instances Methods version :: Version (UArray i e) Source # kind :: Kind (UArray i e) Source # getCopy :: Contained (Get (UArray i e)) Source # putCopy :: UArray i e -> Contained Put Source # internalConsistency :: Consistency (UArray i e) Source # objectProfile :: Profile (UArray i e) Source # errorTypeName :: Proxy (UArray i e) -> String Source #
(SafeCopy a, SafeCopy b) => SafeCopy (Either a b) Source # |
Instance details Defined in Data.SafeCopy.Instances Methods version :: Version (Either a b) Source # kind :: Kind (Either a b) Source # getCopy :: Contained (Get (Either a b)) Source # putCopy :: Either a b -> Contained Put Source # internalConsistency :: Consistency (Either a b) Source # objectProfile :: Profile (Either a b) Source # errorTypeName :: Proxy (Either a b) -> String Source #
(HasResolution a, Fractional (Fixed a), Typeable a) => SafeCopy (Fixed a) Source # |
Instance details Defined in Data.SafeCopy.Instances Methods version :: Version (Fixed a) Source # kind :: Kind (Fixed a) Source # getCopy :: Contained (Get (Fixed a)) Source # putCopy :: Fixed a -> Contained Put Source # internalConsistency :: Consistency (Fixed a) Source # objectProfile :: Profile (Fixed a) Source # errorTypeName :: Proxy (Fixed a) -> String Source #
(Ix i, SafeCopy e, SafeCopy i) => SafeCopy (Array i e) Source # |
Instance details Defined in Data.SafeCopy.Instances Methods version :: Version (Array i e) Source # kind :: Kind (Array i e) Source # getCopy :: Contained (Get (Array i e)) Source # putCopy :: Array i e -> Contained Put Source # internalConsistency :: Consistency (Array i e) Source # objectProfile :: Profile (Array i e) Source # errorTypeName :: Proxy (Array i e) -> String Source #
(SafeCopy a, SafeCopy b, Ord a) => SafeCopy (Map a b) Source # |
Instance details Defined in Data.SafeCopy.Instances Methods version :: Version (Map a b) Source # kind :: Kind (Map a b) Source # getCopy :: Contained (Get (Map a b)) Source # putCopy :: Map a b -> Contained Put Source # internalConsistency :: Consistency (Map a b) Source # objectProfile :: Profile (Map a b) Source # errorTypeName :: Proxy (Map a b) -> String Source #
(SafeCopy a, SafeCopy b) => SafeCopy (a, b) Source # |
Instance details Defined in Data.SafeCopy.Instances Methods version :: Version (a, b) Source # kind :: Kind (a, b) Source # getCopy :: Contained (Get (a, b)) Source # putCopy :: (a, b) -> Contained Put Source # internalConsistency :: Consistency (a, b) Source # objectProfile :: Profile (a, b) Source # errorTypeName :: Proxy (a, b) -> String Source #
(SafeCopy a, SafeCopy b, SafeCopy c) => SafeCopy (a, b, c) Source # |
Instance details Defined in Data.SafeCopy.Instances Methods version :: Version (a, b, c) Source # kind :: Kind (a, b, c) Source # getCopy :: Contained (Get (a, b, c)) Source # putCopy :: (a, b, c) -> Contained Put Source # internalConsistency :: Consistency (a, b, c) Source # objectProfile :: Profile (a, b, c) Source # errorTypeName :: Proxy (a, b, c) -> String Source #
(SafeCopy a, SafeCopy b, SafeCopy c, SafeCopy d) => SafeCopy (a, b, c, d) Source # |
Instance details Defined in Data.SafeCopy.Instances Methods version :: Version (a, b, c, d) Source # kind :: Kind (a, b, c, d) Source # getCopy :: Contained (Get (a, b, c, d)) Source # putCopy :: (a, b, c, d) -> Contained Put Source # internalConsistency :: Consistency (a, b, c, d) Source # objectProfile :: Profile (a, b, c, d) Source # errorTypeName :: Proxy (a, b, c, d) -> String Source #
(SafeCopy a, SafeCopy b, SafeCopy c, SafeCopy d, SafeCopy e) => SafeCopy (a, b, c, d, e) Source # |

Instance details

Defined in Data.SafeCopy.Instances

Methods

version :: Version (a, b, c, d, e) Source #

kind :: Kind (a, b, c, d, e) Source #

getCopy :: Contained (Get (a, b, c, d, e)) Source #

putCopy :: (a, b, c, d, e) -> Contained Put Source #

internalConsistency :: Consistency (a, b, c, d, e) Source #

objectProfile :: Profile (a, b, c, d, e) Source #

errorTypeName :: Proxy (a, b, c, d, e) -> String Source #

(SafeCopy a, SafeCopy b, SafeCopy c, SafeCopy d, SafeCopy e, SafeCopy f) => SafeCopy (a, b, c, d, e, f) Source # |

Instance details

Defined in Data.SafeCopy.Instances

Methods

version :: Version (a, b, c, d, e, f) Source #

kind :: Kind (a, b, c, d, e, f) Source #

getCopy :: Contained (Get (a, b, c, d, e, f)) Source #

putCopy :: (a, b, c, d, e, f) -> Contained Put Source #

internalConsistency :: Consistency (a, b, c, d, e, f) Source #

objectProfile :: Profile (a, b, c, d, e, f) Source #

errorTypeName :: Proxy (a, b, c, d, e, f) -> String Source #

(SafeCopy a, SafeCopy b, SafeCopy c, SafeCopy d, SafeCopy e, SafeCopy f, SafeCopy g) => SafeCopy (a, b, c, d, e, f, g) Source # |

Instance details

Defined in Data.SafeCopy.Instances

Methods

version :: Version (a, b, c, d, e, f, g) Source #

kind :: Kind (a, b, c, d, e, f, g) Source #

getCopy :: Contained (Get (a, b, c, d, e, f, g)) Source #

putCopy :: (a, b, c, d, e, f, g) -> Contained Put Source #

internalConsistency :: Consistency (a, b, c, d, e, f, g) Source #

objectProfile :: Profile (a, b, c, d, e, f, g) Source #

errorTypeName :: Proxy (a, b, c, d, e, f, g) -> String Source #

class GPutCopy f p where Source #

Methods

gputCopy :: p -> f p -> Put Source #

#### Instances

Instances details

(GPutCopy f p, GPutCopy g p) => GPutCopy (f :+: g) p Source # |
Instance details Defined in Data.SafeCopy.SafeCopy Methods gputCopy :: p -> (f :+: g) p -> Put Source #
(GPutFields a p, p ~ DatatypeInfo) => GPutCopy (M1 C c a) p Source # |
Instance details Defined in Data.SafeCopy.SafeCopy Methods gputCopy :: p -> M1 C c a p -> Put Source #
GPutCopy a p => GPutCopy (M1 D c a) p Source # |
Instance details Defined in Data.SafeCopy.SafeCopy Methods gputCopy :: p -> M1 D c a p -> Put Source #

type SafeCopy' a = SafeCopy a Source #

Deprecated: SafeCopy' is now equivalent to SafeCopy

A constraint that combines `SafeCopy` and `Typeable`.

class GPutFields f p where Source #

gputFields traverses the fields of a constructor and returns a put for the safecopy versions and a put for the field values.

Methods

gputFields :: p -> f p -> RWST () [Put] (Set TypeRep) PutM () Source #

#### Instances

Instances details

GPutFields (U1 :: Type -> Type) p Source # |
Instance details Defined in Data.SafeCopy.SafeCopy Methods gputFields :: p -> U1 p -> RWST () [Put] (Set TypeRep) PutM () Source #
GPutFields (V1 :: Type -> Type) p Source # |
Instance details Defined in Data.SafeCopy.SafeCopy Methods gputFields :: p -> V1 p -> RWST () [Put] (Set TypeRep) PutM () Source #
(GPutFields f p, GPutFields g p) => GPutFields (f :*: g) p Source # |
Instance details Defined in Data.SafeCopy.SafeCopy Methods gputFields :: p -> (f :*: g) p -> RWST () [Put] (Set TypeRep) PutM () Source #
SafeCopy a => GPutFields (K1 R a :: Type -> Type) p Source # |
Instance details Defined in Data.SafeCopy.SafeCopy Methods gputFields :: p -> K1 R a p -> RWST () [Put] (Set TypeRep) PutM () Source #
GPutFields f p => GPutFields (M1 S c f) p Source # |
Instance details Defined in Data.SafeCopy.SafeCopy Methods gputFields :: p -> M1 S c f p -> RWST () [Put] (Set TypeRep) PutM () Source #

class GGetCopy f p where Source #

Methods

ggetCopy :: p -> Get (f a) Source #

#### Instances

Instances details

(GGetCopy f p, GGetCopy g p, p ~ DatatypeInfo) => GGetCopy (f :+: g) p Source # |
Instance details Defined in Data.SafeCopy.SafeCopy Methods ggetCopy :: p -> Get ((f :+: g) a) Source #
GGetFields f p => GGetCopy (M1 C c f) p Source # |
Instance details Defined in Data.SafeCopy.SafeCopy Methods ggetCopy :: p -> Get (M1 C c f a) Source #
(GGetCopy f p, p ~ DatatypeInfo) => GGetCopy (M1 D d f) p Source # | The M1 type has a fourth type parameter p: newtype M1 i (c :: Meta) (f :: k -> *) (p :: k) = M1 {unM1 :: f p} Note that the type of the M1 field is `f p`, so in order to express this type we add a parameter of type p that we can apply to values of type f.
Instance details Defined in Data.SafeCopy.SafeCopy Methods ggetCopy :: p -> Get (M1 D d f a) Source #

class GGetFields f p where Source #

Methods

ggetFields :: p -> StateT (Map TypeRep Int32) Get (Get (f a)) Source #

#### Instances

Instances details

GGetFields (U1 :: Type -> Type) p Source # |
Instance details Defined in Data.SafeCopy.SafeCopy Methods ggetFields :: p -> StateT (Map TypeRep Int32) Get (Get (U1 a)) Source #
GGetFields (V1 :: Type -> Type) p Source # |
Instance details Defined in Data.SafeCopy.SafeCopy Methods ggetFields :: p -> StateT (Map TypeRep Int32) Get (Get (V1 a)) Source #
(GGetFields f p, GGetFields g p) => GGetFields (f :*: g) p Source # |
Instance details Defined in Data.SafeCopy.SafeCopy Methods ggetFields :: p -> StateT (Map TypeRep Int32) Get (Get ((f :*: g) a)) Source #
SafeCopy a => GGetFields (K1 R a :: Type -> Type) p Source # |
Instance details Defined in Data.SafeCopy.SafeCopy Methods ggetFields :: p -> StateT (Map TypeRep Int32) Get (Get (K1 R a a0)) Source #
GGetFields f p => GGetFields (M1 S c f) p Source # |
Instance details Defined in Data.SafeCopy.SafeCopy Methods ggetFields :: p -> StateT (Map TypeRep Int32) Get (Get (M1 S c f a)) Source #

data DatatypeInfo Source #

Constructors

ConstructorCount |

Fields

- _size :: Word8

ConstructorInfo |

Fields

- _size :: Word8
- _code :: Word8

#### Instances

Instances details

Show DatatypeInfo Source # |
Instance details Defined in Data.SafeCopy.SafeCopy Methods showsPrec :: Int -> DatatypeInfo -> ShowS Source # show :: DatatypeInfo -> String Source # showList :: [DatatypeInfo] -> ShowS Source #

getSafeGetGeneric :: forall a. SafeCopy a => StateT (Map TypeRep Int32) Get (Get a) Source #

Whereas the other `getSafeGet` is only run when we know we need a version, this one is run for every field and must decide whether to read a version or not. It constructs a Map TypeRep Int32 and reads when the new TypeRep is not in the map.

getSafePutGeneric :: forall a. SafeCopy a => (a -> Contained Put) -> a -> RWST () [Put] (Set TypeRep) PutM () Source #

This version returns (Put, Put), the collected version tags and the collected serialized fields. The original `getSafePut` result type prevents doing this because each fields may have a different type. Maybe you can show me a better way

type GSafeCopy a = (SafeCopy a, Generic a, GPutCopy (Rep a) DatatypeInfo, Constructors a) Source #

safePutGeneric :: forall a. GSafeCopy a => a -> Put Source #

Generic only version of safePut. Instead of calling `putCopy` it calls `putCopyDefault`, a copy of the implementation of the `SafeCopy` default method for `putCopy`.

putCopyDefault :: forall a. GSafeCopy a => a -> Contained Put Source #

See `safePutGeneric`. A copy of the code in the default implementation of the putCopy method.

constructGetterFromVersion :: SafeCopy a => Version a -> Kind a -> Either String (Get a) Source #

safeGet :: SafeCopy a => Get a Source #

Parse a version tagged data type and then migrate it to the desired type. Any serialized value has been extended by the return type can be parsed.

getSafeGet :: forall a. SafeCopy a => Get (Get a) Source #

Parse a version tag and return the corresponding migrated parser. This is useful when you can prove that multiple values have the same version. See `getSafePut`.

safePut :: SafeCopy a => a -> Put Source #

Serialize a data type by first writing out its version tag. This is much simpler than the corresponding `safeGet` since previous versions don't come into play.

getSafePut :: forall a. SafeCopy a => PutM (a -> Put) Source #

Serialize the version tag and return the associated putter. This is useful when serializing multiple values with the same version. See `getSafeGet`.

extended_extension :: (Migrate a, Migrate (Reverse a)) => Kind a Source #

The extended_extension kind lets the system know that there is at least one previous and one future version of this type.

extended_base :: Migrate (Reverse a) => Kind a Source #

The extended_base kind lets the system know that there is at least one future version of this type.

extension :: Migrate a => Kind a Source #

The extension kind lets the system know that there is at least one previous version of this type. A given data type can only extend a single other data type. However, it is perfectly fine to build chains of extensions. The migrations between each step is handled automatically.

base :: Kind a Source #

The default kind. Does not extend any type.

primitive :: Kind a Source #

Primitive kinds aren't version tagged. This kind is used for small or built-in types that won't change such as `Int` or `Bool`.

newtype Version a Source #

A simple numeric version id.

Constructors

Version |

Fields

- unVersion :: Int32

#### Instances

Instances details

Num (Version a) Source # |
Instance details Defined in Data.SafeCopy.SafeCopy Methods (+) :: Version a -> Version a -> Version a Source # (-) :: Version a -> Version a -> Version a Source # (*) :: Version a -> Version a -> Version a Source # negate :: Version a -> Version a Source # abs :: Version a -> Version a Source # signum :: Version a -> Version a Source # fromInteger :: Integer -> Version a Source #
Read (Version a) Source # |
Instance details Defined in Data.SafeCopy.SafeCopy Methods readsPrec :: Int -> ReadS (Version a) Source # readList :: ReadS [Version a] Source # readPrec :: ReadPrec (Version a) Source # readListPrec :: ReadPrec [Version a] Source #
Show (Version a) Source # |
Instance details Defined in Data.SafeCopy.SafeCopy Methods showsPrec :: Int -> Version a -> ShowS Source # show :: Version a -> String Source # showList :: [Version a] -> ShowS Source #
Serialize (Version a) Source # |
Instance details Defined in Data.SafeCopy.SafeCopy Methods put :: Putter (Version a) Source # get :: Get (Version a) Source #
Eq (Version a) Source # |
Instance details Defined in Data.SafeCopy.SafeCopy Methods (==) :: Version a -> Version a -> Bool Source # (/=) :: Version a -> Version a -> Bool Source #

castVersion :: Version a -> Version b Source #

newtype Contained a Source #

To ensure that no-one reads or writes values without handling versions correctly, it is necessary to restrict access to `getCopy` and `putCopy`. This is where `Contained` enters the picture. It allows you to put values in to a container but not to take them out again.

Constructors

Contained |

Fields

- unsafeUnPack :: a

contain :: a -> Contained a Source #

Place a value in an unbreakable container.

data Profile a Source #

Constructors

PrimitiveProfile |
InvalidProfile String |
Profile |

Fields

- profileCurrentVersion :: Int32
- profileSupportedVersions :: [Int32]

#### Instances

Instances details

Show (Profile a) Source # |
Instance details Defined in Data.SafeCopy.SafeCopy Methods showsPrec :: Int -> Profile a -> ShowS Source # show :: Profile a -> String Source # showList :: [Profile a] -> ShowS Source #

mkProfile :: SafeCopy a => Proxy a -> Profile a Source #

data Consistency a Source #

Constructors

Consistent |
NotConsistent String |

availableVersions :: SafeCopy a => Proxy a -> [Int32] Source #

getForwardKind :: Migrate (Reverse a) => Kind a -> Kind (MigrateFrom (Reverse a)) Source #

validChain :: SafeCopy a => Proxy a -> Bool Source #

checkConsistency :: (SafeCopy a, MonadFail m) => Proxy a -> m b -> m b Source #

unpureCheckConsistency :: SafeCopy a => Proxy a -> b -> b Source #

PutM doesn't have reasonable `fail` implementation. It just throws an unpure exception anyway.

computeConsistency :: forall a. SafeCopy a => Proxy a -> Consistency a Source #

isObviouslyConsistent :: Kind a -> Bool Source #

proxyFromConsistency :: Consistency a -> Proxy a Source #

proxyFromKind :: Kind a -> Proxy a Source #

consistentFromProxy :: SafeCopy a => Proxy a -> Consistency a Source #

versionFromProxy :: SafeCopy a => Proxy a -> Version a Source #

versionFromKind :: SafeCopy a => Kind a -> Version a Source #

versionFromReverseKind :: SafeCopy (MigrateFrom (Reverse a)) => Kind a -> Version (MigrateFrom (Reverse a)) Source #

kindFromProxy :: SafeCopy a => Proxy a -> Kind a Source #

data Proxy a Source #

Constructors

Proxy |

mkProxy :: a -> Proxy a Source #

asProxyType :: a -> Proxy a -> a Source #

deriveSafeCopy :: Version a -> Name -> Name -> Q [Dec] Source #

Derive an instance of `SafeCopy`.

When serializing, we put a `Word8` describing the constructor (if the data type has more than one constructor). For each type used in the constructor, we call `getSafePut` (which immediately serializes the version of the type). Then, for each field in the constructor, we use one of the put functions obtained in the last step.

For example, given the data type and the declaration below

    data T0 b = T0 b Int
    deriveSafeCopy 1 'base ''T0

we generate

    instance (SafeCopy a, SafeCopy b) =>
             SafeCopy (T0 b) where
        putCopy (T0 arg1 arg2) = contain $ do put_b   <- getSafePut
                                              put_Int <- getSafePut
                                              put_b   arg1
                                              put_Int arg2
                                              return ()
        getCopy = contain $ do get_b   <- getSafeGet
                               get_Int <- getSafeGet
                               return T0 <*> get_b <*> get_Int
        version = 1
        kind = base

And, should we create another data type as a newer version of `T0`, such as

    data T a b = C a a | D b Int
    deriveSafeCopy 2 'extension ''T

    instance SafeCopy b => Migrate (T a b) where
      type MigrateFrom (T a b) = T0 b
      migrate (T0 b i) = D b i

we generate

    instance (SafeCopy a, SafeCopy b) =>
             SafeCopy (T a b) where
        putCopy (C arg1 arg2) = contain $ do putWord8 0
                                             put_a <- getSafePut
                                             put_a arg1
                                             put_a arg2
                                             return ()
        putCopy (D arg1 arg2) = contain $ do putWord8 1
                                             put_b   <- getSafePut
                                             put_Int <- getSafePut
                                             put_b   arg1
                                             put_Int arg2
                                             return ()
        getCopy = contain $ do tag <- getWord8
                               case tag of
                                 0 -> do get_a <- getSafeGet
                                         return C <*> get_a <*> get_a
                                 1 -> do get_b   <- getSafeGet
                                         get_Int <- getSafeGet
                                         return D <*> get_b <*> get_Int
                                 _ -> fail $ "Could not identify tag \"" ++
                                             show tag ++ "\" for type Main.T " ++
                                             "that has only 2 constructors.  " ++
                                             "Maybe your data is corrupted?"
        version = 2
        kind = extension

Note that by using getSafePut, we saved 4 bytes in the case of the `C` constructor. For `D` and `T0`, we didn't save anything. The instance derived by this function always use at most the same space as those generated by `deriveSafeCopySimple`, but never more (as we don't call `getSafePut`/`getSafeGet` for types that aren't needed).

Note that you may use `deriveSafeCopySimple` with one version of your data type and `deriveSafeCopy` in another version without any problems.

deriveSafeCopyIndexedType :: Version a -> Name -> Name -> [Name] -> Q [Dec] Source #

deriveSafeCopySimple :: Version a -> Name -> Name -> Q [Dec] Source #

Derive an instance of `SafeCopy`. The instance derived by this function is simpler than the one derived by `deriveSafeCopy` in that we always use `safePut` and `safeGet` (instead of `getSafePut` and `getSafeGet`).

When serializing, we put a `Word8` describing the constructor (if the data type has more than one constructor) and, for each field of the constructor, we use `safePut`.

For example, given the data type and the declaration below

    data T a b = C a a | D b Int
    deriveSafeCopySimple 1 'base ''T

we generate

    instance (SafeCopy a, SafeCopy b) =>
             SafeCopy (T a b) where
        putCopy (C arg1 arg2) = contain $ do putWord8 0
                                             safePut arg1
                                             safePut arg2
                                             return ()
        putCopy (D arg1 arg2) = contain $ do putWord8 1
                                             safePut arg1
                                             safePut arg2
                                             return ()
        getCopy = contain $ do tag <- getWord8
                               case tag of
                                 0 -> do return C <*> safeGet <*> safeGet
                                 1 -> do return D <*> safeGet <*> safeGet
                                 _ -> fail $ "Could not identify tag \"" ++
                                             show tag ++ "\" for type Main.T " ++
                                             "that has only 2 constructors.  " ++
                                             "Maybe your data is corrupted?"
        version = 1
        kind = base

Using this simpler instance means that you may spend more bytes when serializing data. On the other hand, it is more straightforward and may match any other format you used in the past.

Note that you may use `deriveSafeCopy` with one version of your data type and `deriveSafeCopySimple` in another version without any problems.

deriveSafeCopySimpleIndexedType :: Version a -> Name -> Name -> [Name] -> Q [Dec] Source #

deriveSafeCopyHappstackData :: Version a -> Name -> Name -> Q [Dec] Source #

Derive an instance of `SafeCopy`. The instance derived by this function should be compatible with the instance derived by the module `Happstack.Data.SerializeTH` of the `happstack-data` package. The instances use only `safePut` and `safeGet` (as do the instances created by `deriveSafeCopySimple`), but we also always write a `Word8` tag, even if the data type isn't a sum type.

For example, given the data type and the declaration below

    data T0 b = T0 b Int
    deriveSafeCopy 1 'base ''T0

we generate

    instance (SafeCopy a, SafeCopy b) =>
             SafeCopy (T0 b) where
        putCopy (T0 arg1 arg2) = contain $ do putWord8 0
                                              safePut arg1
                                              safePut arg2
                                              return ()
        getCopy = contain $ do tag <- getWord8
                               case tag of
                                 0 -> do return T0 <*> safeGet <*> safeGet
                                 _ -> fail $ "Could not identify tag \"" ++
                                             show tag ++ "\" for type Main.T0 " ++
                                             "that has only 1 constructors.  " ++
                                             "Maybe your data is corrupted?"
        version = 1
        kind = base

This instance always consumes at least the same space as `deriveSafeCopy` or `deriveSafeCopySimple`, but may use more because of the useless tag. So we recomend using it only if you really need to read a previous version in this format, and not for newer versions.

Note that you may use `deriveSafeCopy` with one version of your data type and `deriveSafeCopyHappstackData` in another version without any problems.

deriveSafeCopyHappstackDataIndexedType :: Version a -> Name -> Name -> [Name] -> Q [Dec] Source #

data DeriveType Source #

Constructors

Normal |
Simple |
HappstackData |

forceTag :: DeriveType -> Bool Source #

tyVarName :: TyVarBndr s -> Name Source #

internalDeriveSafeCopy :: DeriveType -> Version a -> Name -> Name -> Q [Dec] Source #

internalDeriveSafeCopy' :: DeriveType -> Version a -> Name -> Name -> Info -> Q [Dec] Source #

internalDeriveSafeCopyIndexedType :: DeriveType -> Version a -> Name -> Name -> [Name] -> Q [Dec] Source #

internalDeriveSafeCopyIndexedType' :: DeriveType -> Version a -> Name -> Name -> [Name] -> Info -> Q [Dec] Source #

mkPutCopy :: DeriveType -> [(Integer, Con)] -> DecQ Source #

mkGetCopy :: DeriveType -> String -> [(Integer, Con)] -> DecQ Source #

mkSafeFunctions :: String -> Name -> Con -> Q ([StmtQ], Type -> Name) Source #

followSynonyms :: Type -> Q Type Source #

Follow type synonyms. This allows us to see, for example, that `[Char]` and `String` are the same type and we just need to call `getSafePut` or `getSafeGet` once for both.

conSize :: Con -> Int Source #

conName :: Con -> Name Source #

conTypes :: Con -> [Type] Source #

typeName :: Type -> String Source #