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
- getMemoBytesType ∷ MemoBytes t → t
- getMemoBytesHash ∷ MemoBytes t → SafeHash (MemoHashIndex 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 ∷ (DecCBOR 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 ∷ (DecCBOR 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
Generic (MemoBytes t) Source # | |
Show t ⇒ Show (MemoBytes t) Source # | |
Typeable t ⇒ ToCBOR (MemoBytes t) Source # | |
DecCBOR t ⇒ DecCBOR (MemoBytes t) Source # | |
SafeToHash (MemoBytes t) Source # | |
Defined in Cardano.Ledger.MemoBytes.Internal Methods originalBytes ∷ MemoBytes t → ByteString Source # originalBytesSize ∷ MemoBytes t → Int Source # makeHashWithExplicitProxys ∷ Proxy i → MemoBytes t → SafeHash i Source # | |
NFData t ⇒ NFData (MemoBytes t) Source # | |
Defined in Cardano.Ledger.MemoBytes.Internal | |
Eq t ⇒ Eq (MemoBytes t) Source # | Both binary representation and Haskell types are compared. |
(Typeable t, NoThunks t) ⇒ NoThunks (MemoBytes t) Source # | |
type Rep (MemoBytes t) Source # | |
Defined in Cardano.Ledger.MemoBytes.Internal type Rep (MemoBytes t) = D1 ('MetaData "MemoBytes" "Cardano.Ledger.MemoBytes.Internal" "cardano-ledger-core-1.18.0.0-inplace" 'False) (C1 ('MetaCons "MemoBytes" 'PrefixI 'True) (S1 ('MetaSel ('Just "mbRawType") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 t) :*: (S1 ('MetaSel ('Just "mbBytes") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 ShortByteString) :*: S1 ('MetaSel ('Just "mbHash") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 (SafeHash (MemoHashIndex t)))))) |
type family MemoHashIndex (t ∷ Type) ∷ Type Source #
Instances
type MemoHashIndex (PlutusData era) Source # | |
Defined in Cardano.Ledger.Plutus.Data |
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
showMemo ∷ Show t ⇒ MemoBytes t → String Source #
Deprecated: As unused. Show instance will show the hash, which is enough most of the time
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.
printMemo ∷ Show t ⇒ MemoBytes t → IO () Source #
Deprecated: As unused. Show instance will show the hash, which is enough most of the time
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 ∷ (DecCBOR 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 #
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