Safe Haskell | Safe |
---|---|
Language | Haskell98 |
This module defines various utility functions used across the Network.Haskoin modules.
- toStrictBS :: ByteString -> ByteString
- toLazyBS :: ByteString -> ByteString
- stringToBS :: String -> ByteString
- bsToString :: ByteString -> String
- bsToInteger :: ByteString -> Integer
- integerToBS :: Integer -> ByteString
- bsToHex :: ByteString -> String
- hexToBS :: String -> Maybe ByteString
- encode' :: Binary a => a -> ByteString
- decode' :: Binary a => ByteString -> a
- runPut' :: Put -> ByteString
- runGet' :: Binary a => Get a -> ByteString -> a
- decodeOrFail' :: Binary a => ByteString -> Either (ByteString, ByteOffset, String) (ByteString, ByteOffset, a)
- runGetOrFail' :: Binary a => Get a -> ByteString -> Either (ByteString, ByteOffset, String) (ByteString, ByteOffset, a)
- fromDecode :: Binary a => ByteString -> b -> (a -> b) -> b
- fromRunGet :: Binary a => Get a -> ByteString -> b -> (a -> b) -> b
- decodeToEither :: Binary a => ByteString -> Either String a
- decodeToMaybe :: Binary a => ByteString -> Maybe a
- isolate :: Binary a => Int -> Get a -> Get a
Documentation
toStrictBS :: ByteString -> ByteString Source #
Transforms a lazy bytestring into a strict bytestring
toLazyBS :: ByteString -> ByteString Source #
Transforms a strict bytestring into a lazy bytestring
stringToBS :: String -> ByteString Source #
Transforms a string into a strict bytestring
bsToString :: ByteString -> String Source #
Transform a strict bytestring to a string
bsToInteger :: ByteString -> Integer Source #
Decode a big endian Integer from a bytestring
integerToBS :: Integer -> ByteString Source #
Encode an Integer to a bytestring as big endian
bsToHex :: ByteString -> String Source #
Encode a bytestring to a base16 (HEX) representation
hexToBS :: String -> Maybe ByteString Source #
Decode a base16 (HEX) string from a bytestring. This function can fail if the string contains invalid HEX characters
Data.Binary helpers
encode' :: Binary a => a -> ByteString Source #
Strict version of Data.Binary.encode
decode' :: Binary a => ByteString -> a Source #
Strict version of Data.Binary.decode
runPut' :: Put -> ByteString Source #
Strict version of Data.Binary.runPut
decodeOrFail' :: Binary a => ByteString -> Either (ByteString, ByteOffset, String) (ByteString, ByteOffset, a) Source #
Strict version of Data.Binary.decodeOrFail
runGetOrFail' :: Binary a => Get a -> ByteString -> Either (ByteString, ByteOffset, String) (ByteString, ByteOffset, a) Source #
Strict version of Data.Binary.runGetOrFail
:: Binary a | |
=> ByteString | The bytestring to decode |
-> b | Default value to return when decoding fails |
-> (a -> b) | Function to apply when decoding succeeds |
-> b | Final result |
Try to decode a Data.Binary value. If decoding succeeds, apply the function to the result. Otherwise, return the default value.
:: Binary a | |
=> Get a | The Get monad to run |
-> ByteString | The bytestring to decode |
-> b | Default value to return when decoding fails |
-> (a -> b) | Function to apply when decoding succeeds |
-> b | Final result |
Try to run a Data.Binary.Get monad. If decoding succeeds, apply a function to the result. Otherwise, return the default value.
decodeToEither :: Binary a => ByteString -> Either String a Source #
Decode a Data.Binary value into the Either monad. A Right value is returned with the result upon success. Otherwise a Left value with the error message is returned.
decodeToMaybe :: Binary a => ByteString -> Maybe a Source #
Decode a Data.Binary value into the Maybe monad. A Just value is returned with the result upon success. Otherwise, Nothing is returned.