File: Binary.hs

package info (click to toggle)
haskell-text-binary 0.2.1.1-10
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 60 kB
  • sloc: haskell: 26; makefile: 4
file content (28 lines) | stat: -rw-r--r-- 674 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
{-# LANGUAGE CPP #-}
{-# OPTIONS_GHC -fno-warn-orphans #-}

module Data.Text.Binary where

#if !(MIN_VERSION_text(1,2,1))
import qualified Data.Text as T
import qualified Data.Text.Encoding as T
import qualified Data.Text.Lazy as L
import qualified Data.Text.Lazy.Encoding as L
import Data.Binary

instance Binary T.Text where
    put = put . T.encodeUtf8
    get   = do
      bs <- get
      case T.decodeUtf8' bs of
        Left exn -> fail (show exn)
        Right a -> return a

instance Binary L.Text where
    put = put . L.encodeUtf8
    get   = do
      bs <- get
      case L.decodeUtf8' bs of
        Left exn -> fail (show exn)
        Right a -> return a
#endif