Safe Haskell | None |
---|---|
Language | Haskell2010 |
Ouroboros.Consensus.Util.IndexedMemPack
Description
This module is a derivative of Data.MemPack but we provide something that will be used to " index " the serialization.
The idea is that we can use this in the Cardano block to avoid serializing a tag next to the TxOut, as the Ledger layer establishes the property that TxOuts are forwards deserializable, meaning we can read them in any later era.
Synopsis
- class IndexedMemPack idx a where
- indexedPackedByteCount ∷ idx → a → Int
- indexedPackM ∷ idx → a → Pack s ()
- indexedUnpackM ∷ Buffer b ⇒ idx → Unpack b a
- indexedTypeName ∷ idx → String
- class MemPack a where
- indexedPackByteString ∷ ∀ a idx. (IndexedMemPack idx a, HasCallStack) ⇒ idx → a → ByteString
- indexedUnpackError ∷ ∀ idx a b. (Buffer b, IndexedMemPack idx a, HasCallStack) ⇒ idx → b → a
Documentation
class IndexedMemPack idx a where Source #
See MemPack
.
Methods
indexedPackedByteCount ∷ idx → a → Int Source #
indexedPackM ∷ idx → a → Pack s () Source #
indexedUnpackM ∷ Buffer b ⇒ idx → Unpack b a Source #
indexedTypeName ∷ idx → String Source #
Instances
class MemPack a where Source #
Efficient serialization interface that operates directly on memory buffers.
Minimal complete definition
Methods
Name of the type that is being deserialized for error reporting. Default
implementation relies on Typeable
.
packedByteCount ∷ a → Int Source #
Report the exact size in number of bytes that packed version of this type will
occupy. It is very important to get this right, otherwise packM
will result in a
runtime exception. Another words this is the expected property that it should hold:
packedByteCount a == bufferByteCount (pack a)
packM ∷ a → Pack s () Source #
Write binary representation of a type into the MutableByteArray
which can be
accessed with ask
, whenever direct operations on it are necessary.
unpackM ∷ Buffer b ⇒ Unpack b a Source #
Read binary representation of the type directly from the buffer, which can be
accessed with ask
when necessary. Direct reads from the buffer should be preceded
with advancing the buffer offset with MonadState
by the number of bytes that will
be consumed from the buffer and making sure that no reads outside of the buffer can
happen. Violation of these rules will lead to segfaults.
Instances
indexedPackByteString ∷ ∀ a idx. (IndexedMemPack idx a, HasCallStack) ⇒ idx → a → ByteString Source #
indexedUnpackError ∷ ∀ idx a b. (Buffer b, IndexedMemPack idx a, HasCallStack) ⇒ idx → b → a Source #