Constructors
BufferCodec#encode# :: CodeBuffer# from toThe
encodefunction translates elements of the bufferfromto the bufferto. It should translate as many elements as possible given the sizes of the buffers, including translating zero elements if there is either not enough room into, orfromdoes not contain a complete multibyte sequence.If multiple CodingProgress returns are possible, OutputUnderflow must be preferred to InvalidSequence. This allows GHC's IO library to assume that if we observe InvalidSequence there is at least a single element available in the output buffer.
The fact that as many elements as possible are translated is used by the IO library in order to report translation errors at the point they actually occur, rather than when the buffer is translated.
recover# :: Buffer from -> Buffer to -> State# RealWorld -> (# State# RealWorld, Buffer from, Buffer to #)The
recoverfunction is used to continue decoding in the presence of invalid or unrepresentable sequences. This includes both those detected byencodereturningInvalidSequenceand those that occur because the input byte sequence appears to be truncated.Progress will usually be made by skipping the first element of the
frombuffer. This function should only be called if you are certain that you wish to do this skipping and if thetobuffer has at least one element of free space. Because this function deals with decoding failure, it assumes that the from buffer has at least one element.recovermay raise an exception rather than skipping anything.Currently, some implementations of
recovermay mutate the input buffer. In particular, this feature is used to implement transliteration.close# :: IO ()Resources associated with the encoding may now be released. The
encodefunction may not be called again after callingclose.getState# :: IO stateReturn the current state of the codec.
Many codecs are not stateful, and in these case the state can be represented as
(). Other codecs maintain a state. For example, UTF-16 recognises a BOM (byte-order-mark) character at the beginning of the input, and remembers thereafter whether to use big-endian or little-endian mode. In this case, the state of the codec would include two pieces of information: whether we are at the beginning of the stream (the BOM only occurs at the beginning), and if not, whether to use the big or little-endian encoding.setState# :: state -> IO ()