binrep-1.0.0: Encode precise binary representations directly in types
Safe HaskellNone
LanguageGHC2021

Binrep.Type.Text

Synopsis

Documentation

type AsText (enc :: k) = Refined enc Text Source #

A string of a given encoding, stored in the Text type.

Essentially Text carrying a proof that it can be successfully encoded into the given encoding. For example, AsText ASCII means the Text stored is pure ASCII.

class Encode (enc :: k) where Source #

Bytestring encoders for text validated for a given encoding.

Methods

encode' :: Text -> Bytes Source #

Encode text to bytes. Internal function, use encode.

Instances

Instances details
Encode Ascii Source #

We reuse UTF-8 encoding for ASCII, since it is a subset of UTF-8.

Instance details

Defined in Binrep.Type.Text.Encoding.Ascii

Methods

encode' :: Text -> Bytes Source #

Encode ShiftJis Source # 
Instance details

Defined in Binrep.Type.Text.Encoding.ShiftJis

Methods

encode' :: Text -> Bytes Source #

Encode Utf8 Source # 
Instance details

Defined in Binrep.Type.Text.Encoding.Utf8

Methods

encode' :: Text -> Bytes Source #

Encode (Utf16 BE) Source # 
Instance details

Defined in Binrep.Type.Text.Encoding.Utf16

Methods

encode' :: Text -> Bytes Source #

Encode (Utf16 LE) Source # 
Instance details

Defined in Binrep.Type.Text.Encoding.Utf16

Methods

encode' :: Text -> Bytes Source #

Encode (Utf32 BE) Source # 
Instance details

Defined in Binrep.Type.Text.Encoding.Utf32

Methods

encode' :: Text -> Bytes Source #

Encode (Utf32 LE) Source # 
Instance details

Defined in Binrep.Type.Text.Encoding.Utf32

Methods

encode' :: Text -> Bytes Source #

encode :: forall {k} (enc :: k). Encode enc => AsText enc -> Bytes Source #

Encode some validated text.

encodeToRep :: forall {k1} {k2} (rep :: k1) (enc :: k2). (Encode enc, Refine rep Bytes) => AsText enc -> Either RefineFailure (Refined rep Bytes) Source #

Encode some text to a bytestring, asserting that the resulting value is valid for the requested bytestring representation.

This is intended to be used with visible type applications:

>>> let Right t = refine @UTF8 (Text.pack "hi")
>>> :t t
t :: AsText UTF8
>>> let Right bs = encodeToRep @'C t
>>> :t bs
bs :: Refined 'C Bytes

class Decode (enc :: k) where Source #

Methods

decode :: Bytes -> Either String (AsText enc) Source #

Decode a ByteString to Text with an explicit encoding.

This is intended to be used with visible type applications.

Instances

Instances details
Decode Ascii Source # 
Instance details

Defined in Binrep.Type.Text.Encoding.Ascii

Decode ShiftJis Source # 
Instance details

Defined in Binrep.Type.Text.Encoding.ShiftJis

Decode Utf8 Source # 
Instance details

Defined in Binrep.Type.Text.Encoding.Utf8

Decode (Utf16 BE) Source # 
Instance details

Defined in Binrep.Type.Text.Encoding.Utf16

Decode (Utf16 LE) Source # 
Instance details

Defined in Binrep.Type.Text.Encoding.Utf16

Decode (Utf32 BE) Source # 
Instance details

Defined in Binrep.Type.Text.Encoding.Utf32

Decode (Utf32 LE) Source # 
Instance details

Defined in Binrep.Type.Text.Encoding.Utf32