{-# LANGUAGE BangPatterns #-}
{-# LANGUAGE MagicHash #-}
{-# LANGUAGE OverloadedStrings #-}
module Data.ByteString.Short.Base16
( encodeBase16
, encodeBase16'
, decodeBase16
, decodeBase16Lenient
, isBase16
, isValidBase16
) where
import Prelude hiding (all, elem)
import Data.ByteString.Short (ShortByteString, toShort, fromShort)
import qualified Data.ByteString.Base16 as B16
import Data.Text (Text)
encodeBase16 :: ShortByteString -> Text
encodeBase16 :: ShortByteString -> Text
encodeBase16 = ByteString -> Text
B16.encodeBase16 (ByteString -> Text)
-> (ShortByteString -> ByteString) -> ShortByteString -> Text
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ShortByteString -> ByteString
fromShort
{-# INLINE encodeBase16 #-}
encodeBase16' :: ShortByteString -> ShortByteString
encodeBase16' :: ShortByteString -> ShortByteString
encodeBase16' = ByteString -> ShortByteString
toShort (ByteString -> ShortByteString)
-> (ShortByteString -> ByteString)
-> ShortByteString
-> ShortByteString
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ByteString -> ByteString
B16.encodeBase16' (ByteString -> ByteString)
-> (ShortByteString -> ByteString) -> ShortByteString -> ByteString
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ShortByteString -> ByteString
fromShort
{-# INLINE encodeBase16' #-}
decodeBase16 :: ShortByteString -> Either Text ShortByteString
decodeBase16 :: ShortByteString -> Either Text ShortByteString
decodeBase16 = (ByteString -> ShortByteString)
-> Either Text ByteString -> Either Text ShortByteString
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap ByteString -> ShortByteString
toShort (Either Text ByteString -> Either Text ShortByteString)
-> (ShortByteString -> Either Text ByteString)
-> ShortByteString
-> Either Text ShortByteString
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ByteString -> Either Text ByteString
B16.decodeBase16 (ByteString -> Either Text ByteString)
-> (ShortByteString -> ByteString)
-> ShortByteString
-> Either Text ByteString
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ShortByteString -> ByteString
fromShort
{-# INLINE decodeBase16 #-}
decodeBase16Lenient :: ShortByteString -> ShortByteString
decodeBase16Lenient :: ShortByteString -> ShortByteString
decodeBase16Lenient = ByteString -> ShortByteString
toShort (ByteString -> ShortByteString)
-> (ShortByteString -> ByteString)
-> ShortByteString
-> ShortByteString
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ByteString -> ByteString
B16.decodeBase16Lenient (ByteString -> ByteString)
-> (ShortByteString -> ByteString) -> ShortByteString -> ByteString
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ShortByteString -> ByteString
fromShort
{-# INLINE decodeBase16Lenient #-}
isBase16 :: ShortByteString -> Bool
isBase16 :: ShortByteString -> Bool
isBase16 = ByteString -> Bool
B16.isBase16 (ByteString -> Bool)
-> (ShortByteString -> ByteString) -> ShortByteString -> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ShortByteString -> ByteString
fromShort
{-# INLINE isBase16 #-}
isValidBase16 :: ShortByteString -> Bool
isValidBase16 :: ShortByteString -> Bool
isValidBase16 = ByteString -> Bool
B16.isValidBase16 (ByteString -> Bool)
-> (ShortByteString -> ByteString) -> ShortByteString -> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ShortByteString -> ByteString
fromShort
{-# INLINE isValidBase16 #-}