Safe Haskell | None |
---|---|
Language | Haskell2010 |
Serialization monoid and serializable types.
Synopsis
- class (Semigroup s, Monoid s) => Serializer s where
- endian :: Proxy s -> Endian
- word8 :: Word8 -> s
- word16 :: Word16 -> s
- word32 :: Word32 -> s
- word64 :: Word64 -> s
- word16L :: Word16 -> s
- word16B :: Word16 -> s
- word32L :: Word32 -> s
- word32B :: Word32 -> s
- word64L :: Word64 -> s
- word64B :: Word64 -> s
- byteString :: ByteString -> s
- shortByteString :: ShortByteString -> s
- lazyByteString :: ByteString -> s
- builder :: Builder -> s
- buildBytes :: Builder -> [Word8]
- buildByteString :: Builder -> ByteString
- buildLazyByteString :: Builder -> ByteString
- newtype BinarySerializer = BinarySerializer {}
- newtype CerealSerializer = CerealSerializer {}
- word16H :: Serializer s => Word16 -> s
- word32H :: Serializer s => Word32 -> s
- word64H :: Serializer s => Word64 -> s
- word :: Serializer s => Word -> s
- wordL :: Serializer s => Word -> s
- wordB :: Serializer s => Word -> s
- wordH :: Serializer s => Word -> s
- int8 :: Serializer s => Int8 -> s
- int16 :: Serializer s => Int16 -> s
- int16L :: Serializer s => Int16 -> s
- int16B :: Serializer s => Int16 -> s
- int16H :: Serializer s => Int16 -> s
- int32 :: Serializer s => Int32 -> s
- int32L :: Serializer s => Int32 -> s
- int32B :: Serializer s => Int32 -> s
- int32H :: Serializer s => Int32 -> s
- int64 :: Serializer s => Int64 -> s
- int64L :: Serializer s => Int64 -> s
- int64B :: Serializer s => Int64 -> s
- int64H :: Serializer s => Int64 -> s
- int :: Serializer s => Int -> s
- intL :: Serializer s => Int -> s
- intB :: Serializer s => Int64 -> s
- intH :: Serializer s => Int -> s
- newtype LittleEndianSerializer s = LittleEndianSerializer {
- serializeL :: s
- newtype BigEndianSerializer s = BigEndianSerializer {
- serializeB :: s
- serializeIn :: Serializer s => Endian -> (forall s'. Serializer s' => s') -> s
- serializeH :: Serializer s => (forall s'. Serializer s' => s') -> s
- class Serializable α where
- put :: Serializer s => α -> s
- putIn :: (Serializer s, Serializable α) => Endian -> α -> s
- putL :: (Serializer s, Serializable α) => α -> s
- putB :: (Serializer s, Serializable α) => α -> s
- putH :: (Serializer s, Serializable α) => α -> s
- toBytes :: Serializable α => α -> [Word8]
- toByteString :: Serializable α => α -> ByteString
- toLazyByteString :: Serializable α => α -> ByteString
- class Serializable α => SizedSerializable α where
- class RestSerializable α where
- putRest :: Serializer s => α -> s
Serialization monoid
class (Semigroup s, Monoid s) => Serializer s where Source #
Serialization monoid.
endian :: Proxy s -> Endian Source #
Default byte order of the serializer.
Serialize a byte. word8
x = byteString
(singleton
x)
word16 :: Word16 -> s Source #
Serialize an unsigned 16-bit integer in the default byte order.
word32 :: Word32 -> s Source #
Serialize an unsigned 32-bit integer in the default byte order.
word64 :: Word64 -> s Source #
Serialize an unsigned 64-bit integer in the default byte order.
word16L :: Word16 -> s Source #
Serialize an unsigned 16-bit integer in little endian.
word16B :: Word16 -> s Source #
Serialize an unsigned 16-bit integer in big endian.
word32L :: Word32 -> s Source #
Serialize an unsigned 32-bit integer in little endian.
word32B :: Word32 -> s Source #
Serialize an unsigned 32-bit integer in big endian.
word64L :: Word64 -> s Source #
Serialize an unsigned 64-bit integer in little endian.
word64B :: Word64 -> s Source #
Serialize an unsigned 64-bit integer in big endian.
byteString :: ByteString -> s Source #
Serialize a ByteString
. Must be a monoid homomorphism.
shortByteString :: ShortByteString -> s Source #
Serialize a ShortByteString
. Must be a monoid homomorphism.
lazyByteString :: ByteString -> s Source #
Serialize a lazy ByteString
. Must be a monoid homomorphism.
builder :: Builder -> s Source #
Serialize a Builder
. Must be a monoid homomorphism.
Instances
buildBytes :: Builder -> [Word8] Source #
A shorthand for "LBS.unpack' .
.toLazyByteString
buildByteString :: Builder -> ByteString Source #
A shorthand for
.toStrict
. toLazyByteString
buildLazyByteString :: Builder -> ByteString Source #
An alias for
.toLazyByteString
newtype BinarySerializer Source #
A wrapper around the Put
monoid (to avoid orphan instances).
Instances
newtype CerealSerializer Source #
A wrapper around the Put
monoid (to avoid orphan instances).
Instances
Binary words serialization
word16H :: Serializer s => Word16 -> s Source #
Serialize an usigned 16-bit integer in host byte order.
word32H :: Serializer s => Word32 -> s Source #
Serialize an unsigned 32-bit integer in host byte order.
word64H :: Serializer s => Word64 -> s Source #
Serialize an unsigned 64-bit integer in host byte order.
word :: Serializer s => Word -> s Source #
Serialize an unsigned native-sized integer in serializer default byte order.
wordL :: Serializer s => Word -> s Source #
Serialize an unsigned native-sized integer in little endian.
wordB :: Serializer s => Word -> s Source #
Serialize an unsigned native-sized integer in big endian.
wordH :: Serializer s => Word -> s Source #
Serialize an unsigned native-sized integer in host byte order.
int8 :: Serializer s => Int8 -> s Source #
Serialize a signed 8-bit integer.
int16 :: Serializer s => Int16 -> s Source #
Serialize a signed 16-bit integer in serializer default byte order.
int16L :: Serializer s => Int16 -> s Source #
Serialize a signed 16-bit integer in little endian.
int16B :: Serializer s => Int16 -> s Source #
Serialize a signed 16-bit integer in big endian.
int16H :: Serializer s => Int16 -> s Source #
Serialize a signed 16-bit integer in host byte order.
int32 :: Serializer s => Int32 -> s Source #
Serialize a signed 32-bit integer in serializer default byte order.
int32L :: Serializer s => Int32 -> s Source #
Serialize a signed 32-bit integer in little endian.
int32B :: Serializer s => Int32 -> s Source #
Serialize a signed 32-bit integer in big endian.
int32H :: Serializer s => Int32 -> s Source #
Serialize a signed 32-bit integer in host byte order.
int64 :: Serializer s => Int64 -> s Source #
Serialize a signed 64-bit integer in serializer default byte order.
int64L :: Serializer s => Int64 -> s Source #
Serialize a signed 64-bit integer in little endian.
int64B :: Serializer s => Int64 -> s Source #
Serialize a signed 64-bit integer in big endian.
int64H :: Serializer s => Int64 -> s Source #
Serialize a signed 64-bit integer in host byte order.
int :: Serializer s => Int -> s Source #
Serialize a signed native-sized integer in serializer default byte order.
intL :: Serializer s => Int -> s Source #
Serialize a signed native-sized integer in little endian.
intB :: Serializer s => Int64 -> s Source #
Serialize a signed native-sized integer in big endian.
intH :: Serializer s => Int -> s Source #
Serialize a signed native-sized integer in host byte order.
Endian serializers
newtype LittleEndianSerializer s Source #
Serializer wrapper with little endian default byte order.
Instances
newtype BigEndianSerializer s Source #
Serializer wrapper with big endian default byte order.
Instances
serializeIn :: Serializer s => Endian -> (forall s'. Serializer s' => s') -> s Source #
Force the default byte order.
serializeH :: Serializer s => (forall s'. Serializer s' => s') -> s Source #
Force the default byte order to be the host byte order.
Serializable types
class Serializable α where Source #
Serializable type. put
must work under assumption that it will be
followed by more output.
put :: Serializer s => α -> s Source #
Instances
putIn :: (Serializer s, Serializable α) => Endian -> α -> s Source #
Serialize a value using the provided default byte order.
putL :: (Serializer s, Serializable α) => α -> s Source #
Serialize a value using little endian as the default byte order.
putB :: (Serializer s, Serializable α) => α -> s Source #
Serialize a value using big endian as the default byte order.
putH :: (Serializer s, Serializable α) => α -> s Source #
Serialize a value using host byte order as the default byte order.
toBytes :: Serializable α => α -> [Word8] Source #
A shorthand for
.buildBytes
. put
toByteString :: Serializable α => α -> ByteString Source #
A shorthand for
.buildByteString
. put
toLazyByteString :: Serializable α => α -> ByteString Source #
A shorthand for
.buildLazyByteString
. put
class Serializable α => SizedSerializable α where Source #
Types with fixed serialized size.
Instances
class RestSerializable α where Source #
Serializable type. putRest
must work under assumption that it will not
be followed by any more output.
putRest :: Serializer s => α -> s Source #
Instances
RestSerializable ByteString Source # | |
Defined in Data.Serializer putRest :: Serializer s => ByteString -> s Source # | |
RestSerializable ByteString Source # | |
Defined in Data.Serializer putRest :: Serializer s => ByteString -> s Source # | |
RestSerializable ShortByteString Source # | |
Defined in Data.Serializer putRest :: Serializer s => ShortByteString -> s Source # | |
RestSerializable Builder Source # | |
Defined in Data.Serializer putRest :: Serializer s => Builder -> s Source # | |
Serializable α => RestSerializable [α] Source # | |
Defined in Data.Serializer putRest :: Serializer s => [α] -> s Source # | |
(Serializable α, RestSerializable β) => RestSerializable (α, β) Source # | |
Defined in Data.Serializer putRest :: Serializer s => (α, β) -> s Source # |