ouroboros-consensus-0.1.0.0: Consensus layer for the Ouroboros blockchain protocol
Safe HaskellNone
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
Eq a ⇒ Eq (Versioned a) Source # 
Instance details

Defined in Ouroboros.Consensus.Util.Versioned

Methods

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

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

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

Defined in Ouroboros.Consensus.Util.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 #

encodeVersionVersionNumber → Encoding → Encoding Source #

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

encodeVersioned ∷ (a → Encoding) → Versioned a → Encoding Source #

opaque

data VersionNumber Source #

Instances

Instances details
Eq VersionNumber Source # 
Instance details

Defined in Ouroboros.Consensus.Util.Versioned

Num VersionNumber Source # 
Instance details

Defined in Ouroboros.Consensus.Util.Versioned

Ord VersionNumber Source # 
Instance details

Defined in Ouroboros.Consensus.Util.Versioned

Show VersionNumber Source # 
Instance details

Defined in Ouroboros.Consensus.Util.Versioned

Serialise VersionNumber Source # 
Instance details

Defined in Ouroboros.Consensus.Util.Versioned

Methods

encodeVersionNumber → Encoding #

decode ∷ Decoder s VersionNumber #

encodeList ∷ [VersionNumber] → Encoding #

decodeList ∷ Decoder s [VersionNumber] #