Safe Haskell | Safe-Inferred |
---|---|
Language | Haskell2010 |
PlutusCore.Flat.Decoder
Description
Strict Decoder
Synopsis
- strictDecoder ∷ Get a → ByteString → Int → Either DecodeException a
- listTDecoder ∷ Get a → ByteString → IO (ListT IO a)
- type Decoded a = Either DecodeException a
- data DecodeException
- = NotEnoughSpace Env
- | TooMuchSpace Env
- | BadEncoding Env String
- | BadOp String
- data 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
- dDouble ∷ Get Double
- dInteger ∷ Get Integer
- dNatural ∷ Get Natural
- dChar ∷ Get Char
- dBool ∷ Get Bool
- dWord8 ∷ Get Word8
- 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
- dBE16 ∷ Get Word16
- dBE32 ∷ Get Word32
- dBE64 ∷ Get Word64
- dBEBits8 ∷ Int → Get Word8
- dBEBits16 ∷ Int → Get Word16
- dBEBits32 ∷ Int → Get Word32
- dBEBits64 ∷ Int → Get Word64
- dropBits ∷ Int → Get ()
- data ConsState = ConsState !Word !Int
- consOpen ∷ Get ConsState
- consClose ∷ Int → Get ()
- consBool ∷ ConsState → (ConsState, Bool)
- consBits ∷ ConsState → Int → (ConsState, Word)
Documentation
strictDecoder ∷ Get a → ByteString → Int → Either 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)
listTDecoder ∷ Get a → ByteString → IO (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 DecodeException Source #
An exception during decoding
Constructors
NotEnoughSpace Env | |
TooMuchSpace Env | |
BadEncoding Env String | |
BadOp String |
Instances
Exception DecodeException Source # | |
Defined in PlutusCore.Flat.Decoder.Types | |
Show DecodeException Source # | |
Defined in PlutusCore.Flat.Decoder.Types | |
Eq DecodeException Source # | |
Defined in PlutusCore.Flat.Decoder.Types Methods | |
Ord DecodeException Source # | |
Defined in PlutusCore.Flat.Decoder.Types Methods compare ∷ DecodeException → DecodeException → Ordering Source # (<) ∷ DecodeException → DecodeException → Bool Source # (<=) ∷ DecodeException → DecodeException → Bool Source # (>) ∷ DecodeException → DecodeException → Bool Source # (>=) ∷ DecodeException → DecodeException → Bool Source # max ∷ DecodeException → DecodeException → DecodeException Source # min ∷ DecodeException → DecodeException → DecodeException Source # |
A decoder.
Given:
- end of input buffer
- current position in input buffer
Returns:
- decoded value
- new position in input buffer
decodeArrayWith ∷ Get a → Get [a] Source #
decodeListWith ∷ Get a → Get [a] Source #
dBEBits8 ∷ Int → Get 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")
dBEBits16 ∷ Int → Get 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
dBEBits32 ∷ Int → Get Word32 Source #
Return the n most significant bits (up to maximum of 32) The bits are returned right shifted.
dBEBits64 ∷ Int → Get Word64 Source #
Return the n most significant bits (up to maximum of 64) The bits are returned right shifted.
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).