ouroboros-consensus-0.18.0.0: Consensus layer for the Ouroboros blockchain protocol
Safe HaskellSafe-Inferred
LanguageHaskell2010

Ouroboros.Consensus.Util.Versioned

Contents

Synopsis

Documentation

data VersionDecoder a where Source #

How to decode a version of a format.

Constructors

IncompatibleStringVersionDecoder a

This version is incompatible, fail with IncompatibleVersion and the given message.

Decode ∷ (∀ s. Decoder s a) → VersionDecoder a

Decode the version using the given Decoder.

MigrateVersionDecoder from → (from → Either String to) → VersionDecoder to

Decode an other format (from) and migrate from that. When migration fails, the version decoder will fail with MigrationFailed.

data VersionError Source #

Constructors

IncompatibleVersion VersionNumber String

We cannot deserialise the version of the data with the given VersionNumber because its data format is incompatible.

For example, the given format lacks data that was added in later version that cannot be reconstructed from scratch.

UnknownVersion VersionNumber

The given VersionNumber is unknown and thus not supported.

MigrationFailed VersionNumber String

A migration from the given VersionNumber failed. See Migrate.

data Versioned a Source #

Constructors

Versioned 

Instances

Instances details
Show a ⇒ Show (Versioned a) Source # 
Instance details

Defined in Ouroboros.Consensus.Util.Versioned

Methods

showsPrecIntVersioned a → ShowS #

showVersioned a → String #

showList ∷ [Versioned a] → ShowS #

Eq a ⇒ Eq (Versioned a) Source # 
Instance details

Defined in Ouroboros.Consensus.Util.Versioned

Methods

(==)Versioned a → Versioned a → Bool #

(/=)Versioned a → Versioned a → Bool #

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 IntDecoder 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.

encodeVersionVersionNumberEncodingEncoding Source #

Given a VersionNumber and the encoding of an a, encode the corresponding Versioned a. Use decodeVersion to decode it.

opaque

data VersionNumber Source #

Instances

Instances details
Num VersionNumber Source # 
Instance details

Defined in Ouroboros.Consensus.Util.Versioned

Show VersionNumber Source # 
Instance details

Defined in Ouroboros.Consensus.Util.Versioned

Eq VersionNumber Source # 
Instance details

Defined in Ouroboros.Consensus.Util.Versioned

Ord VersionNumber Source # 
Instance details

Defined in Ouroboros.Consensus.Util.Versioned

Serialise VersionNumber Source # 
Instance details

Defined in Ouroboros.Consensus.Util.Versioned