{-# LANGUAGE CPP #-}
{-# LANGUAGE PatternSynonyms #-}
{-# LANGUAGE ViewPatterns #-}
#if MIN_VERSION_lens(5,0,0)
{-# LANGUAGE Safe #-}
#else
{-# LANGUAGE Trustworthy #-}
#endif
module Data.ByteString.Short.Base32.Lens
(
_Base32
, _Base32Unpadded
, _Base32Hex
, _Base32HexUnpadded
, pattern Base32
, pattern Base32Unpadded
, pattern Base32Hex
, pattern Base32HexUnpadded
) where
import Control.Lens
import Data.ByteString.Short (ShortByteString)
import qualified Data.ByteString.Short.Base32 as SB32
import qualified Data.ByteString.Short.Base32.Hex as SB32H
_Base32 :: Prism' ShortByteString ShortByteString
_Base32 :: p ShortByteString (f ShortByteString)
-> p ShortByteString (f ShortByteString)
_Base32 = (ShortByteString -> ShortByteString)
-> (ShortByteString -> Maybe ShortByteString)
-> Prism
ShortByteString ShortByteString ShortByteString ShortByteString
forall b s a. (b -> s) -> (s -> Maybe a) -> Prism s s a b
prism' ShortByteString -> ShortByteString
SB32.encodeBase32' ((ShortByteString -> Maybe ShortByteString)
-> Prism
ShortByteString ShortByteString ShortByteString ShortByteString)
-> (ShortByteString -> Maybe ShortByteString)
-> Prism
ShortByteString ShortByteString ShortByteString ShortByteString
forall a b. (a -> b) -> a -> b
$ \ShortByteString
s -> case ShortByteString -> Either Text ShortByteString
SB32.decodeBase32 ShortByteString
s of
Left Text
_ -> Maybe ShortByteString
forall a. Maybe a
Nothing
Right ShortByteString
a -> ShortByteString -> Maybe ShortByteString
forall a. a -> Maybe a
Just ShortByteString
a
{-# INLINE _Base32 #-}
_Base32Unpadded :: Prism' ShortByteString ShortByteString
_Base32Unpadded :: p ShortByteString (f ShortByteString)
-> p ShortByteString (f ShortByteString)
_Base32Unpadded = (ShortByteString -> ShortByteString)
-> (ShortByteString -> Maybe ShortByteString)
-> Prism
ShortByteString ShortByteString ShortByteString ShortByteString
forall b s a. (b -> s) -> (s -> Maybe a) -> Prism s s a b
prism' ShortByteString -> ShortByteString
SB32.encodeBase32Unpadded' ((ShortByteString -> Maybe ShortByteString)
-> Prism
ShortByteString ShortByteString ShortByteString ShortByteString)
-> (ShortByteString -> Maybe ShortByteString)
-> Prism
ShortByteString ShortByteString ShortByteString ShortByteString
forall a b. (a -> b) -> a -> b
$ \ShortByteString
s -> case ShortByteString -> Either Text ShortByteString
SB32.decodeBase32Unpadded ShortByteString
s of
Left Text
_ -> Maybe ShortByteString
forall a. Maybe a
Nothing
Right ShortByteString
a -> ShortByteString -> Maybe ShortByteString
forall a. a -> Maybe a
Just ShortByteString
a
{-# INLINE _Base32Unpadded #-}
_Base32Hex :: Prism' ShortByteString ShortByteString
_Base32Hex :: p ShortByteString (f ShortByteString)
-> p ShortByteString (f ShortByteString)
_Base32Hex = (ShortByteString -> ShortByteString)
-> (ShortByteString -> Maybe ShortByteString)
-> Prism
ShortByteString ShortByteString ShortByteString ShortByteString
forall b s a. (b -> s) -> (s -> Maybe a) -> Prism s s a b
prism' ShortByteString -> ShortByteString
SB32H.encodeBase32' ((ShortByteString -> Maybe ShortByteString)
-> Prism
ShortByteString ShortByteString ShortByteString ShortByteString)
-> (ShortByteString -> Maybe ShortByteString)
-> Prism
ShortByteString ShortByteString ShortByteString ShortByteString
forall a b. (a -> b) -> a -> b
$ \ShortByteString
s -> case ShortByteString -> Either Text ShortByteString
SB32H.decodeBase32 ShortByteString
s of
Left Text
_ -> Maybe ShortByteString
forall a. Maybe a
Nothing
Right ShortByteString
a -> ShortByteString -> Maybe ShortByteString
forall a. a -> Maybe a
Just ShortByteString
a
{-# INLINE _Base32Hex #-}
_Base32HexUnpadded :: Prism' ShortByteString ShortByteString
_Base32HexUnpadded :: p ShortByteString (f ShortByteString)
-> p ShortByteString (f ShortByteString)
_Base32HexUnpadded = (ShortByteString -> ShortByteString)
-> (ShortByteString -> Maybe ShortByteString)
-> Prism
ShortByteString ShortByteString ShortByteString ShortByteString
forall b s a. (b -> s) -> (s -> Maybe a) -> Prism s s a b
prism' ShortByteString -> ShortByteString
SB32H.encodeBase32Unpadded' ((ShortByteString -> Maybe ShortByteString)
-> Prism
ShortByteString ShortByteString ShortByteString ShortByteString)
-> (ShortByteString -> Maybe ShortByteString)
-> Prism
ShortByteString ShortByteString ShortByteString ShortByteString
forall a b. (a -> b) -> a -> b
$ \ShortByteString
s -> case ShortByteString -> Either Text ShortByteString
SB32H.decodeBase32Unpadded ShortByteString
s of
Left Text
_ -> Maybe ShortByteString
forall a. Maybe a
Nothing
Right ShortByteString
a -> ShortByteString -> Maybe ShortByteString
forall a. a -> Maybe a
Just ShortByteString
a
{-# INLINE _Base32HexUnpadded #-}
pattern Base32 :: ShortByteString -> ShortByteString
pattern $bBase32 :: ShortByteString -> ShortByteString
$mBase32 :: forall r.
ShortByteString -> (ShortByteString -> r) -> (Void# -> r) -> r
Base32 a <- (preview _Base32 -> Just a) where
Base32 ShortByteString
a = Tagged ShortByteString (Identity ShortByteString)
-> Tagged ShortByteString (Identity ShortByteString)
Prism
ShortByteString ShortByteString ShortByteString ShortByteString
_Base32 (Tagged ShortByteString (Identity ShortByteString)
-> Tagged ShortByteString (Identity ShortByteString))
-> ShortByteString -> ShortByteString
forall t b. AReview t b -> b -> t
# ShortByteString
a
pattern Base32Unpadded :: ShortByteString -> ShortByteString
pattern $bBase32Unpadded :: ShortByteString -> ShortByteString
$mBase32Unpadded :: forall r.
ShortByteString -> (ShortByteString -> r) -> (Void# -> r) -> r
Base32Unpadded a <- (preview _Base32Unpadded -> Just a) where
Base32Unpadded ShortByteString
a = Tagged ShortByteString (Identity ShortByteString)
-> Tagged ShortByteString (Identity ShortByteString)
Prism
ShortByteString ShortByteString ShortByteString ShortByteString
_Base32Unpadded (Tagged ShortByteString (Identity ShortByteString)
-> Tagged ShortByteString (Identity ShortByteString))
-> ShortByteString -> ShortByteString
forall t b. AReview t b -> b -> t
# ShortByteString
a
pattern Base32Hex :: ShortByteString -> ShortByteString
pattern $bBase32Hex :: ShortByteString -> ShortByteString
$mBase32Hex :: forall r.
ShortByteString -> (ShortByteString -> r) -> (Void# -> r) -> r
Base32Hex a <- (preview _Base32Hex -> Just a) where
Base32Hex ShortByteString
a = Tagged ShortByteString (Identity ShortByteString)
-> Tagged ShortByteString (Identity ShortByteString)
Prism
ShortByteString ShortByteString ShortByteString ShortByteString
_Base32Hex (Tagged ShortByteString (Identity ShortByteString)
-> Tagged ShortByteString (Identity ShortByteString))
-> ShortByteString -> ShortByteString
forall t b. AReview t b -> b -> t
# ShortByteString
a
pattern Base32HexUnpadded :: ShortByteString -> ShortByteString
pattern $bBase32HexUnpadded :: ShortByteString -> ShortByteString
$mBase32HexUnpadded :: forall r.
ShortByteString -> (ShortByteString -> r) -> (Void# -> r) -> r
Base32HexUnpadded a <- (preview _Base32HexUnpadded -> Just a) where
Base32HexUnpadded ShortByteString
a = Tagged ShortByteString (Identity ShortByteString)
-> Tagged ShortByteString (Identity ShortByteString)
Prism
ShortByteString ShortByteString ShortByteString ShortByteString
_Base32HexUnpadded (Tagged ShortByteString (Identity ShortByteString)
-> Tagged ShortByteString (Identity ShortByteString))
-> ShortByteString -> ShortByteString
forall t b. AReview t b -> b -> t
# ShortByteString
a