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 ⇒ ∀ s. idx → Unpack s b a
- indexedTypeName ∷ idx → String
- class MemPack a where
- indexedPackByteString ∷ ∀ a idx. (IndexedMemPack idx a, HasCallStack) ⇒ idx → a → ByteString
- indexedPackByteArray ∷ ∀ a idx. (IndexedMemPack idx a, HasCallStack) ⇒ Bool → idx → a → ByteArray
- indexedUnpackError ∷ ∀ idx a b. (Buffer b, IndexedMemPack idx a, HasCallStack) ⇒ idx → b → a
- indexedUnpackEither ∷ (IndexedMemPack idx a, Buffer b, HasCallStack) ⇒ idx → b → Either SomeError a
- unpackEither ∷ (MemPack a, Buffer b, HasCallStack) ⇒ b → Either SomeError 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 ⇒ ∀ s. idx → Unpack s 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 s b a Source #
Read binary representation of the type directly from the buffer, which can be
accessed with ask
when necessary.
Warning - Direct reads from the buffer should be preceded with advancing the buffer offset
within MonadState
by the exact number of bytes that gets consumed from that buffer.
⚠ - Violation of the above rule will lead to segfaults.
Instances
indexedPackByteString ∷ ∀ a idx. (IndexedMemPack idx a, HasCallStack) ⇒ idx → a → ByteString Source #
indexedPackByteArray ∷ ∀ a idx. (IndexedMemPack idx a, HasCallStack) ⇒ Bool → idx → a → ByteArray Source #
indexedUnpackError ∷ ∀ idx a b. (Buffer b, IndexedMemPack idx a, HasCallStack) ⇒ idx → b → a Source #
indexedUnpackEither ∷ (IndexedMemPack idx a, Buffer b, HasCallStack) ⇒ idx → b → Either SomeError a Source #
unpackEither ∷ (MemPack a, Buffer b, HasCallStack) ⇒ b → Either SomeError a Source #