Copyright | (c) 2022 Composewell Technologies |
---|---|
License | BSD-3-Clause |
Maintainer | streamly@composewell.com |
Portability | GHC |
Safe Haskell | Safe-Inferred |
Language | Haskell2010 |
Encode Haskell data types to byte streams.
The primary purpose of this module is to serialize primitive Haskell types to streams for convenient byte by byte processing when such a need arises.
It would be inefficient to use this to build byte streams from algebraic data types. For general serialization of ADTs please use the Serialize type class instances. The fastest way to convert general Haskell types to byte streams is to serialize them to an array and then stream the array.
Synopsis
- class ToBytes a where
- unit :: Applicative m => Stream m Word8
- bool :: Applicative m => Bool -> Stream m Word8
- ordering :: Applicative m => Ordering -> Stream m Word8
- word8 :: Applicative m => Word8 -> Stream m Word8
- word16be :: Monad m => Word16 -> Stream m Word8
- word16le :: Monad m => Word16 -> Stream m Word8
- word32be :: Monad m => Word32 -> Stream m Word8
- word32le :: Monad m => Word32 -> Stream m Word8
- word64be :: Monad m => Word64 -> Stream m Word8
- word64le :: Monad m => Word64 -> Stream m Word8
- word64host :: Monad m => Word64 -> Stream m Word8
- int8 :: Applicative m => Int8 -> Stream m Word8
- int16be :: Monad m => Int16 -> Stream m Word8
- int16le :: Monad m => Int16 -> Stream m Word8
- int32be :: Monad m => Int32 -> Stream m Word8
- int32le :: Monad m => Int32 -> Stream m Word8
- int64be :: Monad m => Int64 -> Stream m Word8
- int64le :: Monad m => Int64 -> Stream m Word8
- float32be :: Monad m => Float -> Stream m Word8
- float32le :: Monad m => Float -> Stream m Word8
- double64be :: Monad m => Double -> Stream m Word8
- double64le :: Monad m => Double -> Stream m Word8
- charLatin1 :: Applicative m => Char -> Stream m Word8
- charUtf8 :: Monad m => Char -> Stream m Word8
Type class
Encoders
unit :: Applicative m => Stream m Word8 Source #
A value of type ()
is encoded as 0
in binary encoding.
0 ==> ()
Pre-release
ordering :: Applicative m => Ordering -> Stream m Word8 Source #
A value of type Ordering
is encoded as follows in binary encoding.
0 ==> LT 1 ==> EQ 2 ==> GT
Pre-release
word16be :: Monad m => Word16 -> Stream m Word8 Source #
Stream a Word16
as two bytes, the first byte is the MSB of the Word16
and second byte is the LSB (big endian representation).
Pre-release
word16le :: Monad m => Word16 -> Stream m Word8 Source #
Stream a Word16
as two bytes, the first byte is the LSB of the Word16
and second byte is the MSB (little endian representation).
Pre-release
word32be :: Monad m => Word32 -> Stream m Word8 Source #
Stream a Word32
as four bytes, the first byte is the MSB of the Word32
and last byte is the LSB (big endian representation).
Pre-release
word32le :: Monad m => Word32 -> Stream m Word8 Source #
Stream a Word32
as four bytes, the first byte is the MSB of the Word32
and last byte is the LSB (big endian representation).
Pre-release
word64be :: Monad m => Word64 -> Stream m Word8 Source #
Stream a Word64
as eight bytes, the first byte is the MSB of the Word64
and last byte is the LSB (big endian representation).
Pre-release
word64le :: Monad m => Word64 -> Stream m Word8 Source #
Stream a Word64
as eight bytes, the first byte is the MSB of the Word64
and last byte is the LSB (big endian representation).
Pre-release
word64host :: Monad m => Word64 -> Stream m Word8 Source #
Stream a Word64
as eight bytes in the host byte order.
Pre-release
int16be :: Monad m => Int16 -> Stream m Word8 Source #
Stream a Int16
as two bytes, the first byte is the MSB of the Int16
and second byte is the LSB (big endian representation).
Pre-release
int16le :: Monad m => Int16 -> Stream m Word8 Source #
Stream a Int16
as two bytes, the first byte is the LSB of the Int16
and second byte is the MSB (little endian representation).
Pre-release
int32be :: Monad m => Int32 -> Stream m Word8 Source #
Stream a Int32
as four bytes, the first byte is the MSB of the Int32
and last byte is the LSB (big endian representation).
Pre-release
int64be :: Monad m => Int64 -> Stream m Word8 Source #
Stream a Int64
as eight bytes, the first byte is the MSB of the Int64
and last byte is the LSB (big endian representation).
Pre-release
int64le :: Monad m => Int64 -> Stream m Word8 Source #
Stream a Int64
as eight bytes, the first byte is the LSB of the Int64
and last byte is the MSB (little endian representation).
Pre-release
charLatin1 :: Applicative m => Char -> Stream m Word8 Source #
Encode a Unicode character to stream of bytes in 0-255 range.