plutus-core-1.54.0.0: Language library for Plutus Core
Safe HaskellSafe-Inferred
LanguageHaskell2010

PlutusCore.Flat.Decoder

Description

Strict Decoder

Synopsis

Documentation

strictDecoderGet a → ByteStringIntEither DecodeException a Source #

Given a decoder and an input buffer returns either the decoded value or an error (if the input buffer is not fully consumed)

listTDecoderGet a → ByteStringIO (ListT IO a) Source #

Decode a list of values, one value at a time.

Useful in case that the decoded values takes a lot more memory than the encoded ones.

See ../test/Big.hs for a test and an example of use.

See also Flat.AsBin.

Since: 0.5

type Decoded a = Either DecodeException a Source #

A decoded value

data Get a Source #

A decoder.

Given:

  • end of input buffer
  • current position in input buffer

Returns:

  • decoded value
  • new position in input buffer

Instances

Instances details
MonadFail Get Source # 
Instance details

Defined in PlutusCore.Flat.Decoder.Types

Methods

failStringGet a Source #

Applicative Get Source # 
Instance details

Defined in PlutusCore.Flat.Decoder.Types

Methods

pure ∷ a → Get a Source #

(<*>)Get (a → b) → Get a → Get b Source #

liftA2 ∷ (a → b → c) → Get a → Get b → Get c Source #

(*>)Get a → Get b → Get b Source #

(<*)Get a → Get b → Get a Source #

Functor Get Source # 
Instance details

Defined in PlutusCore.Flat.Decoder.Types

Methods

fmap ∷ (a → b) → Get a → Get b Source #

(<$) ∷ a → Get b → Get a Source #

Monad Get Source # 
Instance details

Defined in PlutusCore.Flat.Decoder.Types

Methods

(>>=)Get a → (a → Get b) → Get b Source #

(>>)Get a → Get b → Get b Source #

return ∷ a → Get a Source #

Show (Get a) Source # 
Instance details

Defined in PlutusCore.Flat.Decoder.Types

Methods

showsPrecIntGet a → ShowS Source #

showGet a → String Source #

showList ∷ [Get a] → ShowS Source #

NFData (Get a) Source # 
Instance details

Defined in PlutusCore.Flat.Decoder.Types

Methods

rnfGet a → () Source #

decodeListWithGet a → Get [a] Source #

dFloatGet Float Source #

Decode a Float

dDoubleGet Double Source #

Decode a Double

dBoolGet Bool Source #

Decode a boolean

dWord8Get Word8 Source #

Return the 8 most significant bits (same as dBE8)

dBE8Get Word8 Source #

Return the 8 most significant bits

dBE16Get Word16 Source #

Return the 16 most significant bits

dBE32Get Word32 Source #

Return the 32 most significant bits

dBE64Get Word64 Source #

Return the 64 most significant bits

dBEBits8IntGet Word8 Source #

Return the n most significant bits (up to maximum of 8)

The bits are returned right shifted:

>>> unflatWith (dBEBits8 3) [0b11100001::Word8] == Right 0b00000111
True
>>> unflatWith (dBEBits8 9) [0b11100001::Word8,0b11111111]
Left (BadOp "read8: cannot read 9 bits")

dBEBits16IntGet Word16 Source #

Return the n most significant bits (up to maximum of 16)

The bits are returned right shifted:

>>> pPrint . asBits <$> unflatWith (dBEBits16 11) [0b10110111::Word8,0b11100001]
Right 00000101 10111111

If more than 16 bits are requested, only the last 16 are returned:

>>> pPrint . asBits <$> unflatWith (dBEBits16 19) [0b00000000::Word8,0b11111111,0b11100001]
Right 00000111 11111111

dBEBits32IntGet Word32 Source #

Return the n most significant bits (up to maximum of 32) The bits are returned right shifted.

dBEBits64IntGet Word64 Source #

Return the n most significant bits (up to maximum of 64) The bits are returned right shifted.

dropBitsIntGet () Source #

Drop the specified number of bits

data ConsState Source #

A special state, optimised for constructor decoding.

It consists of:

  • The bits to parse, the top bit being the first to parse (could use a Word16 instead, no difference in performance)
  • The number of decoded bits

Supports up to 512 constructors (9 bits).

Constructors

ConsState !Word !Int 

consOpenGet ConsState Source #

Switch to constructor decoding {-# INLINE consOpen #-}

consCloseIntGet () Source #

Switch back to normal decoding {-# NOINLINE consClose #-}

consBoolConsState → (ConsState, Bool) Source #

Decode a single bit

consBitsConsStateInt → (ConsState, Word) Source #

Decode from 1 to 3 bits

It could read more bits that are available, but it doesn't matter, errors will be checked in consClose.