Safe Haskell | Safe-Inferred |
---|---|
Language | Haskell2010 |
Synopsis
- data VersionDecoder a where
- Incompatible ∷ String → VersionDecoder a
- Decode ∷ (∀ 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)] → ∀ s. Decoder s a
- decodeVersionWithHook ∷ ∀ a. (∀ s. Maybe Int → Decoder s a) → [(VersionNumber, VersionDecoder a)] → ∀ s. Decoder s a
- decodeVersioned ∷ [(VersionNumber, VersionDecoder a)] → ∀ 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.
Incompatible ∷ String → VersionDecoder a | This version is incompatible, fail with |
Decode ∷ (∀ 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 #
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
Exception VersionError Source # | |
Show VersionError Source # | |
Defined in Ouroboros.Consensus.Util.Versioned showsPrec ∷ Int → VersionError → ShowS # show ∷ VersionError → String # showList ∷ [VersionError] → ShowS # |
Versioned | |
|
decodeVersion ∷ [(VersionNumber, VersionDecoder a)] → ∀ 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 ∷ ∀ a. (∀ s. Maybe Int → Decoder s a) → [(VersionNumber, VersionDecoder a)] → ∀ 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)] → ∀ 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
adecodeVersion
to decode it.
opaque
data VersionNumber Source #
Instances
Num VersionNumber Source # | |
Defined in Ouroboros.Consensus.Util.Versioned | |
Show VersionNumber Source # | |
Defined in Ouroboros.Consensus.Util.Versioned showsPrec ∷ Int → VersionNumber → ShowS # show ∷ VersionNumber → String # showList ∷ [VersionNumber] → ShowS # | |
Eq VersionNumber Source # | |
Defined in Ouroboros.Consensus.Util.Versioned (==) ∷ VersionNumber → VersionNumber → Bool # (/=) ∷ VersionNumber → VersionNumber → Bool # | |
Ord VersionNumber Source # | |
Defined in Ouroboros.Consensus.Util.Versioned compare ∷ VersionNumber → VersionNumber → Ordering # (<) ∷ VersionNumber → VersionNumber → Bool # (<=) ∷ VersionNumber → VersionNumber → Bool # (>) ∷ VersionNumber → VersionNumber → Bool # (>=) ∷ VersionNumber → VersionNumber → Bool # | |
Serialise VersionNumber Source # | |
Defined in Ouroboros.Consensus.Util.Versioned encode ∷ VersionNumber → Encoding Source # decode ∷ Decoder s VersionNumber Source # encodeList ∷ [VersionNumber] → Encoding Source # decodeList ∷ Decoder s [VersionNumber] Source # |