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

PlutusCore.Flat.Decoder

Description

Strict Decoder

Synopsis
  • strictDecoder :: Get a -> ListT IO a) #

    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 #

A decoded value

data DecodeException #

An exception during decoding

data Get a #

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 # 
Instance details

Defined in PlutusCore.Flat.Decoder.Types

Methods

fail :: String -> Get a #

Applicative Get # 
Instance details

Defined in PlutusCore.Flat.Decoder.Types

Methods

pure :: a -> Get a #

(<*>) :: Get (a -> b) -> Get a -> Get b #

liftA2 :: (a -> b -> c) -> Get a -> Get b -> Get c #

(*>) :: Get a -> Get b -> Get b #

(<*) :: Get a -> Get b -> Get a #

Functor Get # 
Instance details

Defined in PlutusCore.Flat.Decoder.Types

Methods

fmap :: (a -> b) -> Get a -> Get b #

(<$) :: a -> Get b -> Get a #

Monad Get # 
Instance details

Defined in PlutusCore.Flat.Decoder.Types

Methods

(>>=) :: Get a -> (a -> Get b) -> Get b #

(>>) :: Get a -> Get b -> Get b #

return :: a -> Get a #

Show (Get a) # 
Instance details

Defined in PlutusCore.Flat.Decoder.Types

Methods

showsPrec :: Int -> Get a -> ShowS #

show :: Get a -> String #

showList :: [Get a] -> ShowS #

NFData (Get a) # 
Instance details

Defined in PlutusCore.Flat.Decoder.Types

Methods

rnf :: Get a -> () #

dByteString :: Get ByteString #

dLazyByteString :: Get ByteString #

dShortByteString :: Get ShortByteString #

dShortByteString_ :: Get ShortByteString #

dUTF16 :: Get Text #

dUTF8 :: Get Text #

decodeArrayWith :: Get a -> Get [a] #

decodeListWith :: Get a -> Get [a] #

dFloat :: Get Float #

Decode a Float

dDouble :: Get Double #

Decode a Double

dInteger :: Get Integer #

dNatural :: Get Natural #

dChar :: Get Char #

dBool :: Get Bool #

Decode a boolean

dWord8 :: Get Word8 #

Return the 8 most significant bits (same as dBE8)

dWord16 :: Get Word16 #

dWord32 :: Get Word32 #

dWord64 :: Get Word64 #

dWord :: Get Word #

dInt8 :: Get Int8 #

dInt16 :: Get Int16 #

dInt32 :: Get Int32 #

dInt64 :: Get Int64 #

dInt :: Get Int #

dBE8 :: Get Word8 #

Return the 8 most significant bits

dBE16 :: Get Word16 #

Return the 16 most significant bits

dBE32 :: Get Word32 #

Return the 32 most significant bits

dBE64 :: Get Word64 #

Return the 64 most significant bits

dBEBits8 :: Int -> Get Word8 #

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") 

dBEBits16 :: Int -> Get Word16 #

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 

dBEBits32 :: Int -> Get Word32 #

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

dBEBits64 :: Int -> Get Word64 #

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

dropBits :: Int -> Get () #

Drop the specified number of bits

data ConsState #

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 

consOpen :: Get ConsState #

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

consClose :: Int -> Get () #

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

consBool :: ConsState -> (ConsState, Bool) #

Decode a single bit

consBits :: ConsState -> Int -> (ConsState, Word) #

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.