Happstack.Data.Serialize
- class (Typeable a, Version a) => Serialize a where
- class Version a where
- class Migrate a b where
- migrate :: a -> b
- data Mode a
- data Contained a
- contain :: a -> Contained a
- extension :: forall a b. (Serialize b, Migrate b a) => VersionId a -> Proxy b -> Mode a
- safeGet :: forall a. Serialize a => Get a
- safePut :: forall a. Serialize a => a -> Put
- getSafeGet :: forall a. Serialize a => Get (Get a)
- getSafePut :: forall a. Serialize a => PutM (a -> Put)
- serialize :: Serialize a => a -> ByteString
- deserialize :: Serialize a => ByteString -> (a, ByteString)
- collectVersions :: forall a. (Typeable a, Version a) => Proxy a -> [ByteString]
- data Object
- mkObject :: Serialize a => a -> Object
- deserializeObject :: ByteString -> (Object, ByteString)
- parseObject :: Serialize a => Object -> a
- module Happstack.Data.Proxy
Documentation
class (Typeable a, Version a) => Serialize a where
Instances
class Version a where
The Version type class is used to describe whether a type is fundamental
or if it is meant to extend another type. For a user defined type that
does not extend any others, one can use the default instance of Version, e.g.
instance Version MyType
to define it has having a version id of 0 and previous
type.
Instances
Version Bool | |
Version Char | |
Version Double | |
Version Float | |
Version Int | |
Version Int8 | |
Version Int16 | |
Version Int32 | |
Version Int64 | |
Version Integer | |
Version Ordering | |
Version Word8 | |
Version Word16 | |
Version Word32 | |
Version Word64 | |
Version () | |
Version ByteString | |
Version ByteString | |
Version Text | |
Version Text | |
Version AbsoluteTime | |
Version LocalTime | |
Version ZonedTime | |
Version TimeOfDay | |
Version TimeZone | |
Version UTCTime | |
Version NominalDiffTime | |
Version Day | |
Version UniversalTime | |
Version DiffTime | |
Version Object | |
Version [a] | |
Typeable a => Version (Ratio a) | |
Version (Maybe a) | |
Version (IntMap a) | |
Version (Set a) | |
Version (Proxy a) | |
Version (Either a b) | |
Version (a, b) | |
Version (Map a b) | |
Version (a, b, c) | |
Version (a, b, c, d) | |
Version (a, b, c, d, e) |
class Migrate a b where
Migrate instances are needed to allow upgrades of MACID state. It should be declared as instance Migrate Old New where migrate = transition_function
Methods
migrate :: a -> b
data Mode a
data Contained a
extension :: forall a b. (Serialize b, Migrate b a) => VersionId a -> Proxy b -> Mode a
Creates a Mode that is a new version of the type carried by the provided proxy
and with the provided version number. Note that since VersionId is an instance of
Num that you may use int literals when calling extension, e.g.
extension 1 (Proxy :: Proxy OldState)
safeGet :: forall a. Serialize a => Get a
Equivalent of Data.Binary.get for instances of Serialize Takes into account versioning of types.
safePut :: forall a. Serialize a => a -> Put
Equivalent of Data.Binary.put for instances of Serialize. Takes into account versioning of types.
getSafeGet :: forall a. Serialize a => Get (Get a)
getSafePut :: forall a. Serialize a => PutM (a -> Put)
serialize :: Serialize a => a -> ByteString
Pure version of safePut
. Serializes to a ByteString
deserialize :: Serialize a => ByteString -> (a, ByteString)
Pure version of safeGet
. Parses a ByteString into the expected type
and a remainder.
collectVersions :: forall a. (Typeable a, Version a) => Proxy a -> [ByteString]
Version lookups
data Object
Uniform container for any serialized data. It contains a string rep of the type and the actual data serialized to a byte string.
mkObject :: Serialize a => a -> Object
Serializes data and stores it along with its type name in an Object
deserializeObject :: ByteString -> (Object, ByteString)
deserialize
specialized to Objects
parseObject :: Serialize a => Object -> a
Attempts to convert an Object back into its base type.
If the conversion fails error
will be called.
module Happstack.Data.Proxy