Safe Haskell | Safe-Inferred |
---|---|
Language | Haskell2010 |
Cardano.Ledger.MemoBytes
Description
MemoBytes is an abstraction for a data type that encodes its own serialization.
The idea is to use a newtype around a MemoBytes applied to a non-memoizing type.
For example: newtype Foo = Foo (MemoBytes
NonMemoizingFoo)
This way all the instances for Foo (
can be derived for free. MemoBytes plays an important role in the Eq
, Show
, EncCBOR
, DecCBOR
, NoThunks
, Generic`)SafeToHash
class
introduced in the module SafeHash
Synopsis
- data MemoBytes t where
- pattern Memo ∷ t → ShortByteString → MemoBytes t
- type family MemoHashIndex (t ∷ Type) ∷ Type
- type Mem t = Annotator (MemoBytes t)
- mkMemoBytes ∷ ∀ t. t → ByteString → MemoBytes t
- getMemoBytesType ∷ MemoBytes t → t
- getMemoBytesHash ∷ MemoBytes t → SafeHash (MemoHashIndex t)
- memoBytes ∷ Version → Encode w t → MemoBytes t
- memoBytesEra ∷ ∀ era w t. Era era ⇒ Encode w t → MemoBytes t
- shorten ∷ ByteString → ShortByteString
- showMemo ∷ Show t ⇒ MemoBytes t → String
- printMemo ∷ Show t ⇒ MemoBytes t → IO ()
- shortToLazy ∷ ShortByteString → ByteString
- contentsEq ∷ Eq t ⇒ MemoBytes t → MemoBytes t → Bool
- decodeMemoBytes ∷ ∀ t m. (Typeable t, DecCBOR (Annotator t), MonadFail m) ⇒ Version → ByteString → m (MemoBytes t)
- class Memoized t where
- mkMemoized ∷ ∀ t. (EncCBOR (RawType t), Memoized t) ⇒ Version → RawType t → t
- mkMemoizedEra ∷ ∀ era t. (Era era, EncCBOR (RawType t), Memoized t) ⇒ RawType t → t
- decodeMemoized ∷ Decoder s t → Decoder s (MemoBytes t)
- getMemoSafeHash ∷ Memoized t ⇒ t → SafeHash (MemoHashIndex (RawType t))
- getMemoRawType ∷ Memoized t ⇒ t → RawType t
- zipMemoRawType ∷ (Memoized t1, Memoized t2) ⇒ (RawType t1 → RawType t2 → a) → t1 → t2 → a
- eqRawType ∷ ∀ t. (Memoized t, Eq (RawType t)) ⇒ t → t → Bool
- getMemoRawBytes ∷ Memoized t ⇒ t → ShortByteString
- lensMemoRawType ∷ ∀ era t a b. (Era era, EncCBOR (RawType t), Memoized t) ⇒ (RawType t → a) → (RawType t → b → RawType t) → Lens t t a b
- getterMemoRawType ∷ Memoized t ⇒ (RawType t → a) → SimpleGetter t a
- byteCountMemoBytes ∷ MemoBytes t → Int
- packMemoBytesM ∷ MemoBytes t → Pack s ()
- unpackMemoBytesM ∷ ∀ t b. (Typeable t, DecCBOR (Annotator t), Buffer b) ⇒ Version → Unpack b (MemoBytes t)
- class EqRaw a where
Documentation
data MemoBytes t where Source #
Pair together a type t
and its serialization. Used to encode a type
that is serialized over the network, and to remember the original bytes
that were used to transmit it. Important since hashes are computed
from the serialization of a type, and EncCBOR instances do not have unique
serializations.
Bundled Patterns
pattern Memo ∷ t → ShortByteString → MemoBytes t |
Instances
type family MemoHashIndex (t ∷ Type) ∷ Type Source #
Instances
type MemoHashIndex (PlutusData era) Source # | |
Defined in Cardano.Ledger.Plutus.Data |
type Mem t = Annotator (MemoBytes t) Source #
Useful when deriving DecCBOR(Annotator T) deriving via (Mem T) instance DecCBOR (Annotator T)
mkMemoBytes ∷ ∀ t. t → ByteString → MemoBytes t Source #
Smart constructor
getMemoBytesType ∷ MemoBytes t → t Source #
Extract the inner type of the MemoBytes
getMemoBytesHash ∷ MemoBytes t → SafeHash (MemoHashIndex t) Source #
Extract the hash value of the binary representation of the MemoBytes
shorten ∷ ByteString → ShortByteString Source #
Turn a lazy bytestring into a short bytestring.
showMemo ∷ Show t ⇒ MemoBytes t → String Source #
Turn a MemoBytes into a string, Showing both its internal structure and its original bytes. Useful since the Show instance of MemoBytes does not display the original bytes.
shortToLazy ∷ ShortByteString → ByteString Source #
Helper function. Converts a short bytestring to a lazy bytestring.
contentsEq ∷ Eq t ⇒ MemoBytes t → MemoBytes t → Bool Source #
Returns true if the contents of the MemoBytes are equal
decodeMemoBytes ∷ ∀ t m. (Typeable t, DecCBOR (Annotator t), MonadFail m) ⇒ Version → ByteString → m (MemoBytes t) Source #
Memoized
Class that relates the actual type with its raw and byte representations
mkMemoized ∷ ∀ t. (EncCBOR (RawType t), Memoized t) ⇒ Version → RawType t → t Source #
Construct memoized type from the raw type using its EncCBOR instance
getMemoSafeHash ∷ Memoized t ⇒ t → SafeHash (MemoHashIndex (RawType t)) Source #
Extract memoized SafeHash
getMemoRawType ∷ Memoized t ⇒ t → RawType t Source #
Extract the raw type from the memoized version
zipMemoRawType ∷ (Memoized t1, Memoized t2) ⇒ (RawType t1 → RawType t2 → a) → t1 → t2 → a Source #
This is a helper function that operates on raw types of two memoized types.
getMemoRawBytes ∷ Memoized t ⇒ t → ShortByteString Source #
Extract the raw bytes from the memoized version
lensMemoRawType ∷ ∀ era t a b. (Era era, EncCBOR (RawType t), Memoized t) ⇒ (RawType t → a) → (RawType t → b → RawType t) → Lens t t a b Source #
This is a helper Lens creator for any Memoized type.
getterMemoRawType ∷ Memoized t ⇒ (RawType t → a) → SimpleGetter t a Source #
This is a helper SimpleGetter creator for any Memoized type
MemoBytes MemPack definitions
byteCountMemoBytes ∷ MemoBytes t → Int Source #
packMemoBytesM ∷ MemoBytes t → Pack s () Source #
unpackMemoBytesM ∷ ∀ t b. (Typeable t, DecCBOR (Annotator t), Buffer b) ⇒ Version → Unpack b (MemoBytes t) Source #
Raw equality
Type class that implements equality on the Haskell type, ignoring any of the potentially memoized binary representation of the type.
Minimal complete definition
Nothing