store-0.7.18: Fast binary serialization

Safe Haskell | Safe-Inferred
Language | Haskell2010

Data.Store.Version

Description

This module provides utilities which help ensure that we aren't attempting to de-serialize data that is an older or newer version. The `WithVersion` utility wraps up a datatype along with a version tag. This version tag can either be provided by the user (`namedVersionConfig`), or use a computed hash (`hashedVersionConfig`).

The magic here is using an SYB traversal (`Data`) to get the structure of all the data-types involved. This info is rendered to text and hashed to yield a hash which describes it.

NOTE that this API is still quite new and so is likely to break compatibility in the future. It should also be expected that the computed hashes may change between major version bumps, though this will be minimized when directly feasible.

Synopsis

- newtype StoreVersion = StoreVersion {
  - unStoreVersion :: ByteString
  }
- data VersionConfig a = VersionConfig {
  - vcExpectedHash :: Maybe String
  - vcManualName :: Maybe String
  - vcIgnore :: Set String
  - vcRenames :: Map String String
  }
- hashedVersionConfig :: String -> VersionConfig a
- namedVersionConfig :: String -> String -> VersionConfig a
- encodeWithVersionQ :: Data a => VersionConfig a -> Q Exp
- decodeWithVersionQ :: Data a => VersionConfig a -> Q Exp

# Documentation

newtype StoreVersion Source #

Constructors

StoreVersion |

Fields

- unStoreVersion :: ByteString

#### Instances

Instances details

Data StoreVersion Source # |

Instance details

Defined in Data.Store.Version

Methods

gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b) -> (forall g. g -> c g) -> StoreVersion -> c StoreVersion Source #

gunfold :: (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c StoreVersion Source #

toConstr :: StoreVersion -> Constr Source #

dataTypeOf :: StoreVersion -> DataType Source #

dataCast1 :: Typeable t => (forall d. Data d => c (t d)) -> Maybe (c StoreVersion) Source #

dataCast2 :: Typeable t => (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c StoreVersion) Source #

gmapT :: (forall b. Data b => b -> b) -> StoreVersion -> StoreVersion Source #

gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> StoreVersion -> r Source #

gmapQr :: forall r r'. (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> StoreVersion -> r Source #

gmapQ :: (forall d. Data d => d -> u) -> StoreVersion -> [u] Source #

gmapQi :: Int -> (forall d. Data d => d -> u) -> StoreVersion -> u Source #

gmapM :: Monad m => (forall d. Data d => d -> m d) -> StoreVersion -> m StoreVersion Source #

gmapMp :: MonadPlus m => (forall d. Data d => d -> m d) -> StoreVersion -> m StoreVersion Source #

gmapMo :: MonadPlus m => (forall d. Data d => d -> m d) -> StoreVersion -> m StoreVersion Source #

Generic StoreVersion Source # |
Instance details Defined in Data.Store.Version Associated Types type Rep StoreVersion :: Type -> Type Source # Methods from :: StoreVersion -> Rep StoreVersion x Source # to :: Rep StoreVersion x -> StoreVersion Source #
Show StoreVersion Source # |
Instance details Defined in Data.Store.Version Methods showsPrec :: Int -> StoreVersion -> ShowS Source # show :: StoreVersion -> String Source # showList :: [StoreVersion] -> ShowS Source #
Eq StoreVersion Source # |
Instance details Defined in Data.Store.Version Methods (==) :: StoreVersion -> StoreVersion -> Bool Source # (/=) :: StoreVersion -> StoreVersion -> Bool Source #
Ord StoreVersion Source # |

Instance details

Defined in Data.Store.Version

Methods

compare :: StoreVersion -> StoreVersion -> Ordering Source #

(<) :: StoreVersion -> StoreVersion -> Bool Source #

(<=) :: StoreVersion -> StoreVersion -> Bool Source #

(>) :: StoreVersion -> StoreVersion -> Bool Source #

(>=) :: StoreVersion -> StoreVersion -> Bool Source #

max :: StoreVersion -> StoreVersion -> StoreVersion Source #

min :: StoreVersion -> StoreVersion -> StoreVersion Source #

Store StoreVersion Source # |
Instance details Defined in Data.Store.Version Methods size :: Size StoreVersion Source # poke :: StoreVersion -> Poke () Source # peek :: Peek StoreVersion Source #
type Rep StoreVersion Source # |
Instance details Defined in Data.Store.Version type Rep StoreVersion = D1 ('MetaData "StoreVersion" "Data.Store.Version" "store-0.7.18-DEbNI8Jp01nGX9bIwkiCqj" 'True) (C1 ('MetaCons "StoreVersion" 'PrefixI 'True) (S1 ('MetaSel ('Just "unStoreVersion") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 ByteString)))

data VersionConfig a Source #

Configuration for the version checking of a particular type.

Constructors

VersionConfig |

Fields

- vcExpectedHash :: Maybe String

  When set, specifies the hash which is expected to be computed.

- vcManualName :: Maybe String

  When set, specifies the name to instead use to tag the data.

- vcIgnore :: Set String

  DataTypes to ignore.

- vcRenames :: Map String String

  Allowed renamings of datatypes, useful when they move.

#### Instances

Instances details

Data a => Data (VersionConfig a) Source # |

Instance details

Defined in Data.Store.Version

Methods

gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b) -> (forall g. g -> c g) -> VersionConfig a -> c (VersionConfig a) Source #

gunfold :: (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c (VersionConfig a) Source #

toConstr :: VersionConfig a -> Constr Source #

dataTypeOf :: VersionConfig a -> DataType Source #

dataCast1 :: Typeable t => (forall d. Data d => c (t d)) -> Maybe (c (VersionConfig a)) Source #

dataCast2 :: Typeable t => (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c (VersionConfig a)) Source #

gmapT :: (forall b. Data b => b -> b) -> VersionConfig a -> VersionConfig a Source #

gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> VersionConfig a -> r Source #

gmapQr :: forall r r'. (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> VersionConfig a -> r Source #

gmapQ :: (forall d. Data d => d -> u) -> VersionConfig a -> [u] Source #

gmapQi :: Int -> (forall d. Data d => d -> u) -> VersionConfig a -> u Source #

gmapM :: Monad m => (forall d. Data d => d -> m d) -> VersionConfig a -> m (VersionConfig a) Source #

gmapMp :: MonadPlus m => (forall d. Data d => d -> m d) -> VersionConfig a -> m (VersionConfig a) Source #

gmapMo :: MonadPlus m => (forall d. Data d => d -> m d) -> VersionConfig a -> m (VersionConfig a) Source #

Generic (VersionConfig a) Source # |
Instance details Defined in Data.Store.Version Associated Types type Rep (VersionConfig a) :: Type -> Type Source # Methods from :: VersionConfig a -> Rep (VersionConfig a) x Source # to :: Rep (VersionConfig a) x -> VersionConfig a Source #
Show (VersionConfig a) Source # |
Instance details Defined in Data.Store.Version Methods showsPrec :: Int -> VersionConfig a -> ShowS Source # show :: VersionConfig a -> String Source # showList :: [VersionConfig a] -> ShowS Source #
Eq (VersionConfig a) Source # |
Instance details Defined in Data.Store.Version Methods (==) :: VersionConfig a -> VersionConfig a -> Bool Source # (/=) :: VersionConfig a -> VersionConfig a -> Bool Source #
type Rep (VersionConfig a) Source # |

Instance details

Defined in Data.Store.Version

type Rep (VersionConfig a) = D1 ('MetaData "VersionConfig" "Data.Store.Version" "store-0.7.18-DEbNI8Jp01nGX9bIwkiCqj" 'False) (C1 ('MetaCons "VersionConfig" 'PrefixI 'True) ((S1 ('MetaSel ('Just "vcExpectedHash") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 (Maybe String)) :*: S1 ('MetaSel ('Just "vcManualName") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 (Maybe String))) :*: (S1 ('MetaSel ('Just "vcIgnore") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 (Set String)) :*: S1 ('MetaSel ('Just "vcRenames") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 (Map String String)))))

hashedVersionConfig :: String -> VersionConfig a Source #

namedVersionConfig :: String -> String -> VersionConfig a Source #

encodeWithVersionQ :: Data a => VersionConfig a -> Q Exp Source #

decodeWithVersionQ :: Data a => VersionConfig a -> Q Exp Source #