Safe Haskell | Safe-Inferred |
---|---|
Language | Haskell2010 |
Serialisation for on-disk storage.
We have separate classes for on-disk and on-the-wire serialisation, because the encoding formats of the same type may differ, depending on the context.
We separate the encoder from the decoder, because sometimes the encoded
type will differ from the decoded one. For example, we encode a blk
, but
decode an
(when reading something from disk, we
have the precise bytestring that we can pass in as the annotation). If we
coupled the encoder to the decoder, we wouldn't be able to cleanly model
this use case. Moreover, sometimes we only need a single direction.ByteString
-> blk
Synopsis
- class DecodeDisk blk a where
- decodeDisk ∷ CodecConfig blk → ∀ s. Decoder s a
- class EncodeDisk blk a where
- encodeDisk ∷ CodecConfig blk → a → Encoding
- class DecodeDiskDep f blk where
- decodeDiskDep ∷ CodecConfig blk → f blk a → ∀ s. Decoder s (ByteString → a)
- class DecodeDiskDepIx f blk where
- decodeDiskDepIx ∷ CodecConfig blk → Decoder s (SomeSecond f blk)
- class EncodeDiskDep f blk where
- encodeDiskDep ∷ CodecConfig blk → f blk a → a → Encoding
- class EncodeDiskDepIx f blk where
- encodeDiskDepIx ∷ CodecConfig blk → SomeSecond f blk → Encoding
- newtype SerialisedHeader blk = SerialisedHeaderFromDepPair {}
- castSerialisedHeader ∷ (∀ a. NestedCtxt_ blk Header a → NestedCtxt_ blk' Header a) → SerialisedHeader blk → SerialisedHeader blk'
- decodeTrivialSerialisedHeader ∷ ∀ blk. TrivialDependency (NestedCtxt_ blk Header) ⇒ ∀ s. Decoder s (SerialisedHeader blk)
- encodeTrivialSerialisedHeader ∷ ∀ blk. TrivialDependency (NestedCtxt_ blk Header) ⇒ SerialisedHeader blk → Encoding
- serialisedHeaderFromPair ∷ (SomeSecond (NestedCtxt Header) blk, ByteString) → SerialisedHeader blk
- serialisedHeaderToPair ∷ SerialisedHeader blk → (SomeSecond (NestedCtxt Header) blk, ByteString)
- newtype PrefixLen = PrefixLen {}
- class HasNestedContent f blk ⇒ ReconstructNestedCtxt f blk where
- reconstructPrefixLen ∷ proxy (f blk) → PrefixLen
- reconstructNestedCtxt ∷ proxy (f blk) → ShortByteString → SizeInBytes → SomeSecond (NestedCtxt f) blk
- addPrefixLen ∷ Word8 → PrefixLen → PrefixLen
- takePrefix ∷ PrefixLen → ByteString → ShortByteString
- data BinaryBlockInfo = BinaryBlockInfo {}
- class HasBinaryBlockInfo blk where
- getBinaryBlockInfo ∷ blk → BinaryBlockInfo
- data SizeInBytes
- decodeDepPair ∷ DecodeDiskDep f blk ⇒ CodecConfig blk → GenDepPair Serialised (f blk) → Decoder s (DepPair (f blk))
- encodeDepPair ∷ EncodeDiskDep f blk ⇒ CodecConfig blk → DepPair (f blk) → GenDepPair Serialised (f blk)
Serialisation to/from disk storage
class DecodeDisk blk a where Source #
Decode a type a
read from disk.
There is no version negotiation for on disk serialisation. However, instances can still decide to perform versioning internally to maintain compatibility.
Nothing
decodeDisk ∷ CodecConfig blk → ∀ s. Decoder s a Source #
default decodeDisk ∷ Serialise a ⇒ CodecConfig blk → ∀ s. Decoder s a Source #
Instances
class EncodeDisk blk a where Source #
Encode a type a
so that it can be stored on disk.
There is no version negotiation for on disk serialisation. However, instances can still decide to perform versioning internally to maintain compatibility.
Nothing
encodeDisk ∷ CodecConfig blk → a → Encoding Source #
default encodeDisk ∷ Serialise a ⇒ CodecConfig blk → a → Encoding Source #
Instances
Support for dependent pairs
class DecodeDiskDep f blk where Source #
Decode a dependent value
Typical usage: f = NestedCtxt Header
.
Nothing
decodeDiskDep ∷ CodecConfig blk → f blk a → ∀ s. Decoder s (ByteString → a) Source #
default decodeDiskDep ∷ (TrivialDependency (f blk), DecodeDisk blk (ByteString → TrivialIndex (f blk))) ⇒ CodecConfig blk → f blk a → ∀ s. Decoder s (ByteString → a) Source #
Instances
SerialiseHFC xs ⇒ DecodeDiskDep (NestedCtxt Header) (HardForkBlock xs) Source # | |
Defined in Ouroboros.Consensus.HardFork.Combinator.Serialisation.SerialiseDisk decodeDiskDep ∷ CodecConfig (HardForkBlock xs) → NestedCtxt Header (HardForkBlock xs) a → ∀ s. Decoder s (ByteString → a) Source # |
class DecodeDiskDepIx f blk where Source #
Decode dependent index
Nothing
decodeDiskDepIx ∷ CodecConfig blk → Decoder s (SomeSecond f blk) Source #
default decodeDiskDepIx ∷ TrivialDependency (f blk) ⇒ CodecConfig blk → Decoder s (SomeSecond f blk) Source #
Instances
SerialiseHFC xs ⇒ DecodeDiskDepIx (NestedCtxt Header) (HardForkBlock xs) Source # | |
Defined in Ouroboros.Consensus.HardFork.Combinator.Serialisation.SerialiseDisk decodeDiskDepIx ∷ CodecConfig (HardForkBlock xs) → Decoder s (SomeSecond (NestedCtxt Header) (HardForkBlock xs)) Source # |
class EncodeDiskDep f blk where Source #
Encode a dependent value
Nothing
encodeDiskDep ∷ CodecConfig blk → f blk a → a → Encoding Source #
default encodeDiskDep ∷ (TrivialDependency (f blk), EncodeDisk blk (TrivialIndex (f blk))) ⇒ CodecConfig blk → f blk a → a → Encoding Source #
Instances
SerialiseHFC xs ⇒ EncodeDiskDep (NestedCtxt Header) (HardForkBlock xs) Source # | |
Defined in Ouroboros.Consensus.HardFork.Combinator.Serialisation.SerialiseDisk encodeDiskDep ∷ CodecConfig (HardForkBlock xs) → NestedCtxt Header (HardForkBlock xs) a → a → Encoding Source # | |
EncodeDiskDep (NestedCtxt Header) m ⇒ EncodeDiskDep (NestedCtxt Header) (DualBlock m a) Source # | |
Defined in Ouroboros.Consensus.Ledger.Dual encodeDiskDep ∷ CodecConfig (DualBlock m a) → NestedCtxt Header (DualBlock m a) a0 → a0 → Encoding Source # |
class EncodeDiskDepIx f blk where Source #
Encode dependent index
Nothing
encodeDiskDepIx ∷ CodecConfig blk → SomeSecond f blk → Encoding Source #
default encodeDiskDepIx ∷ TrivialDependency (f blk) ⇒ CodecConfig blk → SomeSecond f blk → Encoding Source #
Instances
SerialiseHFC xs ⇒ EncodeDiskDepIx (NestedCtxt Header) (HardForkBlock xs) Source # | |
EncodeDiskDepIx (NestedCtxt Header) m ⇒ EncodeDiskDepIx (NestedCtxt Header) (DualBlock m a) Source # | |
Defined in Ouroboros.Consensus.Ledger.Dual encodeDiskDepIx ∷ CodecConfig (DualBlock m a) → SomeSecond (NestedCtxt Header) (DualBlock m a) → Encoding Source # |
Serialised header
newtype SerialisedHeader blk Source #
A Serialised
header along with context identifying what kind of header
it is.
The SerialiseNodeToNodeDep
for Header
will decide how to actually
encode this.
Instances
castSerialisedHeader ∷ (∀ a. NestedCtxt_ blk Header a → NestedCtxt_ blk' Header a) → SerialisedHeader blk → SerialisedHeader blk' Source #
decodeTrivialSerialisedHeader ∷ ∀ blk. TrivialDependency (NestedCtxt_ blk Header) ⇒ ∀ s. Decoder s (SerialisedHeader blk) Source #
Inverse to encodeTrivialSerialisedHeader
encodeTrivialSerialisedHeader ∷ ∀ blk. TrivialDependency (NestedCtxt_ blk Header) ⇒ SerialisedHeader blk → Encoding Source #
Encode the header without the NestedCtxt
Uses CBOR-in-CBOR
serialisedHeaderFromPair ∷ (SomeSecond (NestedCtxt Header) blk, ByteString) → SerialisedHeader blk Source #
serialisedHeaderToPair ∷ SerialisedHeader blk → (SomeSecond (NestedCtxt Header) blk, ByteString) Source #
Reconstruct nested type
Number of bytes from the start of a block needed to reconstruct the nested context.
See reconstructPrefixLen
.
class HasNestedContent f blk ⇒ ReconstructNestedCtxt f blk where Source #
Nothing
reconstructPrefixLen ∷ proxy (f blk) → PrefixLen Source #
Number of bytes required to reconstruct the nested context.
This will be the minimum length of the ShortByteString
passed to
reconstructNestedCtxt
.
default reconstructPrefixLen ∷ TrivialDependency (NestedCtxt_ blk f) ⇒ proxy (f blk) → PrefixLen Source #
reconstructNestedCtxt Source #
∷ proxy (f blk) | |
→ ShortByteString | First bytes ( |
→ SizeInBytes | Block size |
→ SomeSecond (NestedCtxt f) blk |
Reconstruct the type of nested contents
TODO: Allow to fail.
default reconstructNestedCtxt ∷ TrivialDependency (NestedCtxt_ blk f) ⇒ proxy (f blk) → ShortByteString → SizeInBytes → SomeSecond (NestedCtxt f) blk Source #
Instances
SerialiseHFC xs ⇒ ReconstructNestedCtxt Header (HardForkBlock xs) Source # | |
Defined in Ouroboros.Consensus.HardFork.Combinator.Serialisation.SerialiseDisk reconstructPrefixLen ∷ proxy (Header (HardForkBlock xs)) → PrefixLen Source # reconstructNestedCtxt ∷ proxy (Header (HardForkBlock xs)) → ShortByteString → SizeInBytes → SomeSecond (NestedCtxt Header) (HardForkBlock xs) Source # | |
ReconstructNestedCtxt Header m ⇒ ReconstructNestedCtxt Header (DualBlock m a) Source # | |
Defined in Ouroboros.Consensus.Ledger.Dual reconstructPrefixLen ∷ proxy (Header (DualBlock m a)) → PrefixLen Source # reconstructNestedCtxt ∷ proxy (Header (DualBlock m a)) → ShortByteString → SizeInBytes → SomeSecond (NestedCtxt Header) (DualBlock m a) Source # |
Binary block info
data BinaryBlockInfo Source #
Information about the serialised block.
BinaryBlockInfo | |
|
Instances
class HasBinaryBlockInfo blk where Source #
getBinaryBlockInfo ∷ blk → BinaryBlockInfo Source #
Return information about the serialised block, i.e., how to extract the bytes corresponding to the header from the serialised block.
Instances
SerialiseHFC xs ⇒ HasBinaryBlockInfo (HardForkBlock xs) Source # | |
HasBinaryBlockInfo m ⇒ HasBinaryBlockInfo (DualBlock m a) Source # | The binary info just refers to the main block This is sufficient, because we never need just the header of the auxiliary. |
Defined in Ouroboros.Consensus.Ledger.Dual |
Re-exported for convenience
data SizeInBytes Source #
Instances
Exported for the benefit of tests
decodeDepPair ∷ DecodeDiskDep f blk ⇒ CodecConfig blk → GenDepPair Serialised (f blk) → Decoder s (DepPair (f blk)) Source #
encodeDepPair ∷ EncodeDiskDep f blk ⇒ CodecConfig blk → DepPair (f blk) → GenDepPair Serialised (f blk) Source #