{-# LANGUAGE Trustworthy #-}
{-# LANGUAGE NoImplicitPrelude, ExistentialQuantification #-}
{-# OPTIONS_GHC -funbox-strict-fields #-}
module GHC.IO.Encoding.Types (
BufferCodec(..),
TextEncoding(..),
TextEncoder, TextDecoder,
CodeBuffer, EncodeBuffer, DecodeBuffer,
CodingProgress(..)
) where
import GHC.Base
import GHC.Word
import GHC.Show
import GHC.IO.Buffer
data BufferCodec from to state = BufferCodec {
encode :: CodeBuffer from to,
recover :: Buffer from -> Buffer to -> IO (Buffer from, Buffer to),
close :: IO (),
getState :: IO state,
setState :: state -> IO ()
}
type CodeBuffer from to = Buffer from -> Buffer to -> IO (CodingProgress, Buffer from, Buffer to)
type DecodeBuffer = CodeBuffer Word8 Char
type EncodeBuffer = CodeBuffer Char Word8
type TextDecoder state = BufferCodec Word8 CharBufElem state
type TextEncoder state = BufferCodec CharBufElem Word8 state
data TextEncoding
= forall dstate estate . TextEncoding {
textEncodingName :: String,
mkTextDecoder :: IO (TextDecoder dstate),
mkTextEncoder :: IO (TextEncoder estate)
}
instance Show TextEncoding where
show te = textEncodingName te
data CodingProgress = InputUnderflow
| OutputUnderflow
| InvalidSequence
deriving (Eq, Show)