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