byte-order-0.1.3.1: Portable big-endian and little-endian conversions

Safe Haskell | None
Language | Haskell2010

Data.Primitive.ByteArray.LittleEndian

Contents

- Aligned
- Unaligned

Description

This is drop-in replacement for the read, write, and index functions present in `Data.Primitive.ByteArray` and `Data.Primitive.ByteArray.Unaligned`. While the functions from those modules use native byte order, the functions in this one use little-endian byte order (least significant byte first).

Synopsis

- writeByteArray :: (PrimMonad m, Prim a, Bytes a) => MutableByteArray (PrimState m) -> Int -> a -> m ()
- readByteArray :: (PrimMonad m, Prim a, Bytes a) => MutableByteArray (PrimState m) -> Int -> m a
- indexByteArray :: (Prim a, Bytes a) => ByteArray -> Int -> a
- writeUnalignedByteArray :: (PrimMonad m, PrimUnaligned a, Bytes a) => MutableByteArray (PrimState m) -> Int -> a -> m ()
- readUnalignedByteArray :: (PrimMonad m, PrimUnaligned a, Bytes a) => MutableByteArray (PrimState m) -> Int -> m a
- indexUnalignedByteArray :: (PrimUnaligned a, Bytes a) => ByteArray -> Int -> a

# Aligned

writeByteArray :: (PrimMonad m, Prim a, Bytes a) => MutableByteArray (PrimState m) -> Int -> a -> m () Source #

Write a primitive value to the byte array. The offset is given in elements of type `a` rather than in bytes. The least significant byte in the value comes first.

readByteArray :: (PrimMonad m, Prim a, Bytes a) => MutableByteArray (PrimState m) -> Int -> m a Source #

Read a primitive value from the byte array, interpreting the first byte as the least significant one. The offset is given in elements of type `a` rather than in bytes.

indexByteArray :: (Prim a, Bytes a) => ByteArray -> Int -> a Source #

Read a primitive value from the byte array, interpreting the first byte as the least significant one. The offset is given in elements of type `a` rather than in bytes.

# Unaligned

writeUnalignedByteArray :: (PrimMonad m, PrimUnaligned a, Bytes a) => MutableByteArray (PrimState m) -> Int -> a -> m () Source #

Write a primitive value to the byte array. The offset is given in bytes rather than in elements of type `a`. The least significant byte in the value comes first.

readUnalignedByteArray :: (PrimMonad m, PrimUnaligned a, Bytes a) => MutableByteArray (PrimState m) -> Int -> m a Source #

Read a primitive value from the byte array, interpreting the first byte as the least significant one. The offset is given in bytes rather than in elements of type `a`.

indexUnalignedByteArray :: (PrimUnaligned a, Bytes a) => ByteArray -> Int -> a Source #

Read a primitive value from the byte array, interpreting the first byte as the least significant one. The offset is given in bytes rather than in elements of type `a`.