Safe Haskell | None |
---|---|
Language | Haskell2010 |
Data.PersistState
Synopsis
- class Persist s t where
- type HostEndian = LittleEndian
- newtype BigEndian a = BigEndian {
- unBE :: a
- newtype LittleEndian a = LittleEndian {
- unLE :: a
- encode :: forall s a. Persist s a => PutState s -> a -> ByteString
- decode :: forall s a. Persist s a => GetState s -> ByteString -> Either String a
- data Get s a
- type family GetState s
- stateGet :: Get s (GetState s)
- setStateGet :: GetState s -> Get s ()
- modifyStateGet :: (GetState s -> GetState s) -> Get s ()
- runGet :: Get s a -> GetState s -> ByteString -> Either String a
- ensure :: Int -> Get s ()
- skip :: Int -> Get s ()
- getBytes :: Int -> Get s ByteString
- getByteString :: Int -> Get s ByteString
- remaining :: Get s Int
- eof :: Get s ()
- getHE :: Persist s (HostEndian a) => Get s a
- getLE :: Persist s (LittleEndian a) => Get s a
- getBE :: Persist s (BigEndian a) => Get s a
- data Put s a
- type family PutState s
- statePut :: Put s (PutState s)
- setStatePut :: PutState s -> Put s ()
- modifyStatePut :: (PutState s -> PutState s) -> Put s ()
- runPut :: Put s a -> PutState s -> ByteString
- evalPut :: Put s a -> PutState s -> (a, ByteString)
- grow :: Int -> Put s ()
- putByteString :: ByteString -> Put s ()
- putHE :: Persist s (HostEndian a) => a -> Put s ()
- putLE :: Persist s (LittleEndian a) => a -> Put s ()
- putBE :: Persist s (BigEndian a) => a -> Put s ()
The Persist class
class Persist s t where Source #
Minimal complete definition
Nothing
Methods
Encode a value in the Put monad.
Decode a value in the Get monad
put :: (Generic t, GPersistPut s (Rep t)) => t -> Put s () Source #
Encode a value in the Put monad.
get :: (Generic t, GPersistGet s (Rep t)) => Get s t Source #
Decode a value in the Get monad
Instances
Endianness
type HostEndian = LittleEndian Source #
Instances
newtype LittleEndian a Source #
Constructors
LittleEndian | |
Fields
|
Instances
Serialization
encode :: forall s a. Persist s a => PutState s -> a -> ByteString Source #
Encode a value using binary serialization to a strict ByteString.
decode :: forall s a. Persist s a => GetState s -> ByteString -> Either String a Source #
Decode a value from a strict ByteString, reconstructing the original structure.
The Get type
setStateGet :: GetState s -> Get s () Source #
runGet :: Get s a -> GetState s -> ByteString -> Either String a Source #
Run the Get monad applies a get
-based parser on the input ByteString
ensure :: Int -> Get s () Source #
Ensure that n
bytes are available. Fails if fewer than n
bytes are available.
getByteString :: Int -> Get s ByteString Source #
An efficient get
method for strict ByteStrings. Fails if fewer
than n
bytes are left in the input. This function creates a fresh
copy of the underlying bytes.
remaining :: Get s Int Source #
Get the number of remaining unparsed bytes. Useful for checking whether all input has been consumed.
The Put type
setStatePut :: PutState s -> Put s () Source #
putByteString :: ByteString -> Put s () Source #