packages feed

safecopy 0.8.0 → 0.8.1

raw patch · 3 files changed

+34/−7 lines, 3 files

Files

safecopy.cabal view
@@ -7,7 +7,7 @@ -- The package version. See the Haskell package versioning policy -- (http://www.haskell.org/haskellwiki/Package_versioning_policy) for -- standards guiding when and how versions should be incremented.-Version:             0.8.0+Version:             0.8.1  -- A short (one-line) description of the package. Synopsis:            Binary serialization with version control.
src/Data/SafeCopy.hs view
@@ -73,7 +73,8 @@     (       safeGet     , safePut-    , SafeCopy(version, kind, getCopy, putCopy, errorTypeName)+    , SafeCopy(version, kind, getCopy, putCopy, objectProfile, errorTypeName)+    , Profile(..)     , Prim(..)     , Migrate(..)     , Reverse(..)
src/Data/SafeCopy/SafeCopy.hs view
@@ -61,6 +61,10 @@     Extends   :: (Migrate a) => Proxy (MigrateFrom a) -> Kind a     Extended  :: (Migrate (Reverse a)) => Kind a -> Kind a +isPrimitive :: Kind a -> Bool+isPrimitive Primitive = True+isPrimitive _ = False+ -- | Wrapper for data that was saved without a version tag. newtype Prim a = Prim { getPrimitive :: a } @@ -108,11 +112,12 @@     --   lifetime, instead of everytime 'safeGet' or 'safePut' is     --   used.     internalConsistency :: Consistency a-    internalConsistency =-        let ret = computeConsistency proxy-            proxy = proxyFromConsistency ret-        in ret+    internalConsistency = computeConsistency Proxy +    -- | Version profile.+    objectProfile :: Profile a+    objectProfile = mkProfile Proxy+     -- | The name of the type. This is only used in error     -- message strings.     -- Feel free to leave undefined in your instances.@@ -275,6 +280,24 @@ ------------------------------------------------- -- Consistency checking +data Profile a =+  PrimitiveProfile |+  InvalidProfile String |+  Profile+  { profileCurrentVersion :: Int32+  , profileSupportedVersions :: [Int32]+  } deriving (Show)++mkProfile :: SafeCopy a => Proxy a -> Profile a+mkProfile a_proxy =+  case computeConsistency a_proxy of+    NotConsistent msg -> InvalidProfile msg+    Consistent | isPrimitive (kindFromProxy a_proxy) -> PrimitiveProfile+    Consistent ->+      Profile{ profileCurrentVersion    = unVersion (versionFromProxy a_proxy)+             , profileSupportedVersions = availableVersions a_proxy+             }+ data Consistency a = Consistent | NotConsistent String  availableVersions :: SafeCopy a => Proxy a -> [Int32]@@ -287,8 +310,11 @@         Primitive         -> []         Base              -> [unVersion (versionFromKind b_kind)]         Extends b_proxy   -> unVersion (versionFromKind b_kind) : worker False (kindFromProxy b_proxy)-        Extended sub_kind | fwd  -> worker False sub_kind+        Extended sub_kind | fwd  -> worker False (getForwardKind sub_kind)         Extended sub_kind -> worker False sub_kind++getForwardKind :: (Migrate (Reverse a)) => Kind a -> Kind (MigrateFrom (Reverse a))+getForwardKind _ = kind  -- Extend chains must end in a Base kind. Ending in a Primitive is an error. validChain :: SafeCopy a => Proxy a -> Bool