{-# LANGUAGE UndecidableInstances #-}
module Binrep.Type.Text.Encoding.Utf32 where
import Binrep.Type.Text.Internal
import Binrep.Util.ByteOrder
import Rerefined.Predicate
import TypeLevelShow.Utils
import Data.Text.Encoding qualified as Text
import Data.Text ( Text )
data Utf32 (end :: ByteOrder)
instance Predicate (Utf32 end) where
type PredicateName d (Utf32 end) = "UTF-32" ++ EndianSuffix end
instance Refine (Utf32 end) Text where validate :: Proxy# (Utf32 end) -> Text -> Maybe RefineFailure
validate Proxy# (Utf32 end)
_ Text
_ = Maybe RefineFailure
forall a. Maybe a
Nothing
instance Encode (Utf32 BE) where encode' :: Text -> Bytes
encode' = Text -> Bytes
Text.encodeUtf32BE
instance Encode (Utf32 LE) where encode' :: Text -> Bytes
encode' = Text -> Bytes
Text.encodeUtf32LE
instance Decode (Utf32 BE) where decode :: Bytes -> Either String (AsText (Utf32 BE))
decode = (UnicodeException -> String)
-> (Bytes -> Either UnicodeException Text)
-> Bytes
-> Either String (AsText (Utf32 BE))
forall {k} (enc :: k) e.
(e -> String)
-> (Bytes -> Either e Text) -> Bytes -> Either String (AsText enc)
decodeText UnicodeException -> String
forall a. Show a => a -> String
show ((Bytes -> Either UnicodeException Text)
-> Bytes -> Either String (AsText (Utf32 BE)))
-> (Bytes -> Either UnicodeException Text)
-> Bytes
-> Either String (AsText (Utf32 BE))
forall a b. (a -> b) -> a -> b
$ (Bytes -> Text) -> Bytes -> Either UnicodeException Text
wrapUnsafeDecoder Bytes -> Text
Text.decodeUtf32BE
instance Decode (Utf32 LE) where decode :: Bytes -> Either String (AsText (Utf32 LE))
decode = (UnicodeException -> String)
-> (Bytes -> Either UnicodeException Text)
-> Bytes
-> Either String (AsText (Utf32 LE))
forall {k} (enc :: k) e.
(e -> String)
-> (Bytes -> Either e Text) -> Bytes -> Either String (AsText enc)
decodeText UnicodeException -> String
forall a. Show a => a -> String
show ((Bytes -> Either UnicodeException Text)
-> Bytes -> Either String (AsText (Utf32 LE)))
-> (Bytes -> Either UnicodeException Text)
-> Bytes
-> Either String (AsText (Utf32 LE))
forall a b. (a -> b) -> a -> b
$ (Bytes -> Text) -> Bytes -> Either UnicodeException Text
wrapUnsafeDecoder Bytes -> Text
Text.decodeUtf32LE