Safe Haskell | None |
---|---|
Language | Haskell2010 |
Ouroboros.Consensus.Util.Versioned
Contents
Synopsis
-
data
VersionDecoder
a
where
- Incompatible :: String -> VersionDecoder a
- Decode :: ( forall s. Decoder s a) -> VersionDecoder a
- Migrate :: VersionDecoder from -> (from -> Either String to) -> VersionDecoder to
- data VersionError
-
data
Versioned
a =
Versioned
{
- versionNumber :: ! VersionNumber
- versioned :: !a
- decodeVersion :: [( VersionNumber , VersionDecoder a)] -> forall s. Decoder s a
- decodeVersionWithHook :: forall a. ( forall s. Maybe Int -> Decoder s a) -> [( VersionNumber , VersionDecoder a)] -> forall s. Decoder s a
- decodeVersioned :: [( VersionNumber , VersionDecoder a)] -> forall s. Decoder s ( Versioned a)
- encodeVersion :: VersionNumber -> Encoding -> Encoding
- encodeVersioned :: (a -> Encoding ) -> Versioned a -> Encoding
- data VersionNumber
Documentation
data VersionDecoder a where Source #
How to decode a version of a format.
Constructors
Incompatible :: String -> VersionDecoder a |
This version is incompatible, fail with
|
Decode :: ( forall s. Decoder s a) -> VersionDecoder a |
Decode the version using the given
|
Migrate :: VersionDecoder from -> (from -> Either String to) -> VersionDecoder to |
Decode an other format (
|
data VersionError Source #
Constructors
IncompatibleVersion VersionNumber String |
We cannot deserialise the version of the data with the given
For example, the given format lacks data that was added in later version that cannot be reconstructed from scratch. |
UnknownVersion VersionNumber |
The given
|
MigrationFailed VersionNumber String |
A migration from the given
|
Instances
Show VersionError Source # | |
Defined in Ouroboros.Consensus.Util.Versioned |
|
Exception VersionError Source # | |
Defined in Ouroboros.Consensus.Util.Versioned Methods toException :: VersionError -> SomeException Source # fromException :: SomeException -> Maybe VersionError Source # |
Constructors
Versioned | |
Fields
|
decodeVersion :: [( VersionNumber , VersionDecoder a)] -> forall s. Decoder s a Source #
Decode a
versioned
a
(encoded using
encodeVersion
or
encodeVersioned
).
The corresponding
VersionDecoder
for the deserialised
VersionNumber
is
looked up in the given list. The first match is used (using the semantics
of
lookup
). When no match is found, a decoder that fails with
UnknownVersion
is returned.
decodeVersionWithHook :: forall a. ( forall s. Maybe Int -> Decoder s a) -> [( VersionNumber , VersionDecoder a)] -> forall s. Decoder s a Source #
Same as
decodeVersion
, but with a hook that gets called in case the
encoding was not produced by a versioned encoder. This allows a transition
from non-versioned to versioned encodings.
Versioned encodings start with list length 2. Whenever the encoding starts
this way, this decoder will use the regular versioned decoder. When the
encoding starts differently, either with a different list length (
Just
as
argument) or with another token (
Nothing
as argument), the hook is called,
allowing the previous non-versioned decoder to try to decode the encoding.
Note that the hook should not try to decode the list length again .
Note that this will not work if the previous encoding can start with list length 2, as the new versioned decoder will be called in those cases, not the hook.
decodeVersioned :: [( VersionNumber , VersionDecoder a)] -> forall s. Decoder s ( Versioned a) Source #
encodeVersion :: VersionNumber -> Encoding -> Encoding Source #
Given a
VersionNumber
and the encoding of an
a
, encode the
corresponding
. Use
Versioned
a
decodeVersion
to decode it.
opaque
data VersionNumber Source #