Safe Haskell | Safe-Inferred |
---|---|
Language | Haskell2010 |
Deprecated: Use Binary
from 'cardano-ledger-binary' package instead
Synopsis
- class Typeable a ⇒ EncCBORGroup a where
- encCBORGroup ∷ a → Encoding
- encodedGroupSizeExpr ∷ (∀ x. EncCBOR x ⇒ Proxy x → Size) → Proxy a → Size
- listLen ∷ a → Word
- listLenBound ∷ Proxy a → Word
- class Typeable a ⇒ DecCBORGroup a where
- decCBORGroup ∷ Decoder s a
- newtype CBORGroup a = CBORGroup {
- unCBORGroup ∷ a
- decodeList ∷ Decoder s a → Decoder s [a]
- decodeSeq ∷ Decoder s a → Decoder s (Seq a)
- decodeStrictSeq ∷ Decoder s a → Decoder s (StrictSeq a)
- decodeSet ∷ Ord a ⇒ Decoder s a → Decoder s (Set a)
- decodeMap ∷ Ord k ⇒ Decoder s k → Decoder s v → Decoder s (Map k v)
- decodeMapContents ∷ Decoder s a → Decoder s [a]
- decodeMapTraverse ∷ (Ord a, Applicative t) ⇒ Decoder s (t a) → Decoder s (t b) → Decoder s (t (Map a b))
- decodeMaybe ∷ Decoder s a → Decoder s (Maybe a)
- decodeRecordNamed ∷ Text → (a → Int) → Decoder s a → Decoder s a
- decodeRecordNamedT ∷ (MonadTrans m, Monad (m (Decoder s))) ⇒ Text → (a → Int) → m (Decoder s) a → m (Decoder s) a
- decodeRecordSum ∷ Text → (Word → Decoder s (Int, a)) → Decoder s a
- decodeNullMaybe ∷ Decoder s a → Decoder s (Maybe a)
- encodeFoldable ∷ (EncCBOR a, Foldable f) ⇒ f a → Encoding
- encodeFoldableEncoder ∷ Foldable f ⇒ (a → Encoding) → f a → Encoding
- encodeFoldableMapEncoder ∷ Foldable f ⇒ (Word → a → Maybe Encoding) → f a → Encoding
- encodeNullMaybe ∷ (a → Encoding) → Maybe a → Encoding
- encodeMap ∷ (k → Encoding) → (v → Encoding) → Map k v → Encoding
- groupRecord ∷ (EncCBORGroup a, DecCBORGroup a) ⇒ Decoder s a
- ratioEncCBOR ∷ EncCBOR a ⇒ Ratio a → Encoding
- ratioDecCBOR ∷ (Integral a, DecCBOR a) ⇒ Decoder s (Ratio a)
- mapEncCBOR ∷ (EncCBOR a, EncCBOR b) ⇒ Map a b → Encoding
- mapDecCBOR ∷ (Ord a, DecCBOR a, DecCBOR b) ⇒ Decoder s (Map a b)
- translateViaCBORAnnotator ∷ (ToCBOR a, DecCBOR (Annotator b)) ⇒ Version → Text → a → Except DecoderError b
- ipv4ToBytes ∷ IPv4 → ByteString
- ipv4FromBytes ∷ ByteString → Either String IPv4
- ipv4EncCBOR ∷ IPv4 → Encoding
- ipv4DecCBOR ∷ Decoder s IPv4
- ipv6ToBytes ∷ IPv6 → ByteString
- ipv6FromBytes ∷ ByteString → Either String IPv6
- ipv6EncCBOR ∷ IPv6 → Encoding
- ipv6DecCBOR ∷ Decoder s IPv6
- listLenInt ∷ EncCBORGroup a ⇒ a → Int
- runByteBuilder ∷ Int → Builder → ByteString
- utcTimeEncCBOR ∷ UTCTime → Encoding
- utcTimeDecCBOR ∷ Decoder s UTCTime
- data Sized a = Sized {
- sizedValue ∷ !a
- sizedSize ∷ Int64
- mkSized ∷ EncCBOR a ⇒ Version → a → Sized a
- sizedDecoder ∷ Decoder s a → Decoder s (Sized a)
- toSizedL ∷ EncCBOR s ⇒ Version → Lens' s a → Lens' (Sized s) a
Documentation
class Typeable a ⇒ EncCBORGroup a where Source #
encCBORGroup ∷ a → Encoding Source #
encodedGroupSizeExpr ∷ (∀ x. EncCBOR x ⇒ Proxy x → Size) → Proxy a → Size Source #
listLenBound ∷ Proxy a → Word Source #
Instances
EncCBORGroup ProtVer Source # | |
EncCBORGroup Ptr Source # | |
Crypto c ⇒ EncCBORGroup (PoolParams c) Source # | |
Defined in Cardano.Ledger.PoolParams encCBORGroup ∷ PoolParams c → Encoding Source # encodedGroupSizeExpr ∷ (∀ x. EncCBOR x ⇒ Proxy x → Size) → Proxy (PoolParams c) → Size Source # listLen ∷ PoolParams c → Word Source # listLenBound ∷ Proxy (PoolParams c) → Word Source # | |
(Typeable r, EncCBOR a) ⇒ EncCBORGroup (Mismatch r a) Source # | |
EncCBOR a ⇒ EncCBORGroup (a, a) | |
class Typeable a ⇒ DecCBORGroup a where Source #
decCBORGroup ∷ Decoder s a Source #
Instances
DecCBORGroup ProtVer Source # | |
Defined in Cardano.Ledger.BaseTypes | |
DecCBORGroup Ptr Source # | |
Defined in Cardano.Ledger.Credential decCBORGroup ∷ Decoder s Ptr Source # | |
Crypto c ⇒ DecCBORGroup (PoolParams c) Source # | |
Defined in Cardano.Ledger.PoolParams decCBORGroup ∷ Decoder s (PoolParams c) Source # | |
(Typeable r, DecCBOR a) ⇒ DecCBORGroup (Mismatch r a) Source # | |
Defined in Cardano.Ledger.BaseTypes decCBORGroup ∷ Decoder s (Mismatch r a) Source # | |
DecCBOR a ⇒ DecCBORGroup (a, a) | |
Defined in Cardano.Ledger.Binary.Group decCBORGroup ∷ Decoder s (a, a) Source # |
CBORGroup | |
|
Instances
Show a ⇒ Show (CBORGroup a) | |
(DecCBORGroup a, EncCBORGroup a) ⇒ DecCBOR (CBORGroup a) | |
EncCBORGroup a ⇒ EncCBOR (CBORGroup a) | |
Eq a ⇒ Eq (CBORGroup a) | |
decodeList ∷ Decoder s a → Decoder s [a] Source #
for list.Decoder
- [>= 2] - Allows variable as well as exact list length encoding.
- [< 2] - Expects variable list length encoding
decodeSeq ∷ Decoder s a → Decoder s (Seq a) Source #
Decoder for Seq
. Same behavior for all versions, allows variable as
well as exact list length encoding
decodeStrictSeq ∷ Decoder s a → Decoder s (StrictSeq a) Source #
Decoder for StrictSeq
. Same behavior for all versions, allows variable as
well as exact list length encoding.
decodeSet ∷ Ord a ⇒ Decoder s a → Decoder s (Set a) Source #
Decoder
for Set
. Versions variance:
- [>= 9] - Allows variable as well as exact list length encoding. Duplicates are not allowed. Set tag 258 is permitted, but not enforced.
- [>= 2, < 9] - Allows variable as well as exact list length encoding. Duplicates are silently ignored, set tag 258 is not permitted.
- [< 2] - Expects exact list length encoding and enforces strict order without any duplicates. Also enforces special set tag 258, which was abandoned starting with version 2
decodeMap ∷ Ord k ⇒ Decoder s k → Decoder s v → Decoder s (Map k v) Source #
Decoder
for Map
. Versions variance:
- [>= 9] - Allows variable as well as exact list length encoding. Duplicate keys will result in a deserialization failure
- [>= 2] - Allows variable as well as exact list length encoding. Duplicate keys are silently ignored
- [< 2] - Expects exact list length encoding and enforces strict order without any duplicates.
An example of how to use versioning
>>>
:set -XOverloadedStrings
>>>
import Codec.CBOR.FlatTerm
>>>
fromFlatTerm (toPlainDecoder 1 (decodeMap decodeInt decodeBytes)) [TkMapLen 2,TkInt 1,TkBytes "Foo",TkInt 2,TkBytes "Bar"]
Right (fromList [(1,"Foo"),(2,"Bar")])>>>
fromFlatTerm (toPlainDecoder 1 (decodeMap decodeInt decodeBytes)) [TkMapBegin,TkInt 1,TkBytes "Foo",TkInt 2,TkBytes "Bar"]
Left "decodeMapLen: unexpected token TkMapBegin">>>
fromFlatTerm (toPlainDecoder 2 (decodeMap decodeInt decodeBytes)) [TkMapBegin,TkInt 1,TkBytes "Foo",TkInt 2,TkBytes "Bar",TkBreak]
Right (fromList [(1,"Foo"),(2,"Bar")])
decodeMapContents ∷ Decoder s a → Decoder s [a] Source #
decodeMapTraverse ∷ (Ord a, Applicative t) ⇒ Decoder s (t a) → Decoder s (t b) → Decoder s (t (Map a b)) Source #
decodeRecordNamedT ∷ (MonadTrans m, Monad (m (Decoder s))) ⇒ Text → (a → Int) → m (Decoder s) a → m (Decoder s) a Source #
decodeNullMaybe ∷ Decoder s a → Decoder s (Maybe a) Source #
Alternative way to decode a Maybe type.
Note - this is not the default method for decoding Maybe
, use decodeMaybe
instead.
encodeFoldableEncoder ∷ Foldable f ⇒ (a → Encoding) → f a → Encoding Source #
Encode any Foldable with the variable list length encoding, which will use indefinite encoding over 23 elements and definite otherwise.
encodeFoldableMapEncoder Source #
∷ Foldable f | |
⇒ (Word → a → Maybe Encoding) | A function that accepts an index of the value in the foldable data strucure, the actual value and optionally produces the encoding of the value and an index if that value should be encoded. |
→ f a | |
→ Encoding |
Encode a data structure as a Map with the 0-based index for a Key to a value. Uses variable map length encoding, which means an indefinite encoding for maps with over 23 elements and definite otherwise.
encodeNullMaybe ∷ (a → Encoding) → Maybe a → Encoding Source #
Alternative way to encode a Maybe type.
Note - this is not the default method for encoding Maybe
, use encodeMaybe
instead
encodeMap ∷ (k → Encoding) → (v → Encoding) → Map k v → Encoding Source #
Encode a Map. Versions variance:
- [>= 2] - Variable length encoding for Maps larger than 23 key value pairs, otherwise exact length encoding
- [< 2] - Variable length encoding.
groupRecord ∷ (EncCBORGroup a, DecCBORGroup a) ⇒ Decoder s a Source #
translateViaCBORAnnotator Source #
∷ (ToCBOR a, DecCBOR (Annotator b)) | |
⇒ Version | Version that will be used for deserialization |
→ Text | |
→ a | |
→ Except DecoderError b |
Translation function between values through a related binary representation. This
function allows you to translate one type into another (or the same one) through their
common binary format. It is possible for the source type to be encoded with a different
version than the version that will be used for decoding. This is useful for types that
build upon one another and are "upgradeable" through their binary representation. It is
important to note that the deserialization will happen with Annotator
, since that is
usually the way we deserialize upgradeable types that live on chain. Moreover, encoding
does not require a version, because memoized types that were decoded with annotation
will have the bytes retained and thus will have the ToCBOR
instance.
ipv4ToBytes ∷ IPv4 → ByteString Source #
ipv4EncCBOR ∷ IPv4 → Encoding Source #
ipv4DecCBOR ∷ Decoder s IPv4 Source #
ipv6ToBytes ∷ IPv6 → ByteString Source #
ipv6EncCBOR ∷ IPv6 → Encoding Source #
ipv6DecCBOR ∷ Decoder s IPv6 Source #
listLenInt ∷ EncCBORGroup a ⇒ a → Int Source #
runByteBuilder ∷ Int → Builder → ByteString Source #
Run a ByteString Builder
using a strategy aimed at making smaller
things efficiently.
It takes a size hint and produces a strict ByteString
. This will be fast
when the size hint is the same or slightly bigger than the true size.
A CBOR deserialized value together with its size. When deserializing use
either decodeSized
or its DecCBOR
instance.
Use mkSized
to construct such value.
Sized | |
|
Instances
Generic (Sized a) | |
Show a ⇒ Show (Sized a) | |
DecCBOR a ⇒ DecCBOR (Sized a) | |
EncCBOR a ⇒ EncCBOR (Sized a) | Discards the size. |
NFData a ⇒ NFData (Sized a) | |
Defined in Cardano.Ledger.Binary.Decoding.Sized | |
Eq a ⇒ Eq (Sized a) | |
NoThunks a ⇒ NoThunks (Sized a) | |
type Rep (Sized a) | |
Defined in Cardano.Ledger.Binary.Decoding.Sized type Rep (Sized a) = D1 ('MetaData "Sized" "Cardano.Ledger.Binary.Decoding.Sized" "cardano-ledger-binary-1.5.0.0-inplace" 'False) (C1 ('MetaCons "Sized" 'PrefixI 'True) (S1 ('MetaSel ('Just "sizedValue") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 a) :*: S1 ('MetaSel ('Just "sizedSize") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Int64))) |
mkSized ∷ EncCBOR a ⇒ Version → a → Sized a Source #
Construct a Sized
value by serializing it first and recording the amount
of bytes it requires. Note, however, CBOR serialization is not canonical,
therefore it is *NOT* a requirement that this property holds:
sizedSize (mkSized a) === sizedSize (unsafeDeserialize (serialize a) :: a)