Safe Haskell | None |
---|---|
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 -> forall 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 -> forall 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 :: ( forall a. NestedCtxt_ blk Header a -> NestedCtxt_ blk' Header a) -> SerialisedHeader blk -> SerialisedHeader blk'
- decodeTrivialSerialisedHeader :: forall blk. TrivialDependency ( NestedCtxt_ blk Header ) => forall s. Decoder s ( SerialisedHeader blk)
- encodeTrivialSerialisedHeader :: forall 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
{
- headerOffset :: ! Word16
- headerSize :: ! Word16
-
class
HasBinaryBlockInfo
blk
where
- getBinaryBlockInfo :: blk -> BinaryBlockInfo
- type SizeInBytes = Word32
- 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 -> forall s. Decoder s a Source #
default decodeDisk :: Serialise a => CodecConfig blk -> forall 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 -> forall s. Decoder s ( ByteString -> a) Source #
default decodeDiskDep :: ( TrivialDependency (f blk), DecodeDisk blk ( ByteString -> TrivialIndex (f blk))) => CodecConfig blk -> f blk a -> forall 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 -> forall 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 # | |
Defined in Ouroboros.Consensus.HardFork.Combinator.Serialisation.SerialiseDisk encodeDiskDepIx :: CodecConfig ( HardForkBlock xs) -> SomeSecond ( NestedCtxt Header ) ( HardForkBlock xs) -> Encoding 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 :: ( forall a. NestedCtxt_ blk Header a -> NestedCtxt_ blk' Header a) -> SerialisedHeader blk -> SerialisedHeader blk' Source #
decodeTrivialSerialisedHeader :: forall blk. TrivialDependency ( NestedCtxt_ blk Header ) => forall s. Decoder s ( SerialisedHeader blk) Source #
Inverse to
encodeTrivialSerialisedHeader
encodeTrivialSerialisedHeader :: forall 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
.
Instances
Eq PrefixLen Source # | |
Ord PrefixLen Source # | |
Defined in Ouroboros.Consensus.Storage.Common |
|
Show PrefixLen Source # | |
Generic PrefixLen Source # | |
NoThunks PrefixLen Source # | |
type Rep PrefixLen Source # | |
Defined in Ouroboros.Consensus.Storage.Common
type
Rep
PrefixLen
=
D1
('
MetaData
"PrefixLen" "Ouroboros.Consensus.Storage.Common" "ouroboros-consensus-0.1.0.1-DT4Cvwf63DZKctsEvaJqCU" '
True
) (
C1
('
MetaCons
"PrefixLen" '
PrefixI
'
True
) (
S1
('
MetaSel
('
Just
"getPrefixLen") '
NoSourceUnpackedness
'
NoSourceStrictness
'
DecidedLazy
) (
Rec0
Word8
)))
|
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 # |
takePrefix :: PrefixLen -> ByteString -> ShortByteString Source #
Binary block info
data BinaryBlockInfo Source #
Information about the serialised block.
BinaryBlockInfo | |
|
Instances
Eq BinaryBlockInfo Source # | |
Defined in Ouroboros.Consensus.Storage.Common (==) :: BinaryBlockInfo -> BinaryBlockInfo -> Bool Source # (/=) :: BinaryBlockInfo -> BinaryBlockInfo -> Bool Source # |
|
Show BinaryBlockInfo Source # | |
Defined in Ouroboros.Consensus.Storage.Common |
|
Generic BinaryBlockInfo Source # | |
Defined in Ouroboros.Consensus.Storage.Common from :: BinaryBlockInfo -> Rep BinaryBlockInfo x Source # to :: Rep BinaryBlockInfo x -> BinaryBlockInfo Source # |
|
type Rep BinaryBlockInfo Source # | |
Defined in Ouroboros.Consensus.Storage.Common
type
Rep
BinaryBlockInfo
=
D1
('
MetaData
"BinaryBlockInfo" "Ouroboros.Consensus.Storage.Common" "ouroboros-consensus-0.1.0.1-DT4Cvwf63DZKctsEvaJqCU" '
False
) (
C1
('
MetaCons
"BinaryBlockInfo" '
PrefixI
'
True
) (
S1
('
MetaSel
('
Just
"headerOffset") '
NoSourceUnpackedness
'
SourceStrict
'
DecidedStrict
) (
Rec0
Word16
)
:*:
S1
('
MetaSel
('
Just
"headerSize") '
NoSourceUnpackedness
'
SourceStrict
'
DecidedStrict
) (
Rec0
Word16
)))
|
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 getBinaryBlockInfo :: DualBlock m a -> BinaryBlockInfo Source # |
Re-exported for convenience
type SizeInBytes = Word32 Source #
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 #