flat-0.4.4: Principled and efficient bit-oriented binary serialization.

Safe HaskellNone
LanguageHaskell2010

Flat.Instances.Text

Contents

Description

Flat instances for the text library

Synopsis

Documentation

newtype UTF8Text Source #

The desired text encoding can be explicitly specified using the wrappers UTF8Text and UTF16Text.

The default encoding is UTF8:

>>> tst (UTF8Text $ T.pack "日日日") == tst (T.pack "日日日")
True

A wrapper to encode/decode Text as UTF8 (slower but more compact)

Constructors

UTF8Text 

Fields

newtype UTF16Text Source #

>>> tst (UTF16Text $ T.pack "aaa")
(True,72,[1,6,97,0,97,0,97,0,0])
>>> tst (UTF16Text $ T.pack "𐍈𐍈𐍈")
(True,120,[1,12,0,216,72,223,0,216,72,223,0,216,72,223,0])

A wrapper to encode/decode Text as UTF16 (faster but bigger)

Constructors

UTF16Text 

Fields

Orphan instances

Flat Text Source # 
Instance details

Flat Text Source #

Text (and Data.Text.Lazy) is encoded as a byte aligned array of bytes corresponding to its UTF8 encoding.

>>> tst $ T.pack ""
(True,16,[1,0])
>>> tst $ T.pack "aaa"
(True,120,[1,3,97,97,97,0])
>>> tst $ T.pack "¢¢¢"
(True,120,[1,6,194,162,194,162,194,162,0])
>>> tst $ T.pack "日日日"
(True,120,[1,9,230,151,165,230,151,165,230,151,165,0])
>>> tst $ T.pack "𐍈𐍈𐍈"
(True,120,[1,12,240,144,141,136,240,144,141,136,240,144,141,136,0])

Strict and Lazy Text has the same encoding:

>>> tst (T.pack "abc") == tst (TL.pack "abc")
True
Instance details