{-# LANGUAGE CPP, ForeignFunctionInterface #-}
module SMR.Core.Codec.Word
( fromBE64, fromLE64
, fromBE32, fromLE32
, fromBE16, fromLE16
, toBE64, toLE64
, toBE32, toLE32
, toBE16, toLE16)
where
import Data.Word as Word
#include "MachDeps.h"
data Endian
= Big | Little
deriving Eq
systemEndian :: Endian
#ifdef WORDS_BIGENDIAN
systemEndian = Big
#else
systemEndian = Little
#endif
fromBE64 :: Word64 -> Word64
fromBE64 = if systemEndian == Big then id else Word.byteSwap64
{-# INLINE fromBE64 #-}
fromLE64 :: Word64 -> Word64
fromLE64 = if systemEndian == Little then id else Word.byteSwap64
{-# INLINE fromLE64 #-}
fromBE32 :: Word32 -> Word32
fromBE32 = if systemEndian == Big then id else Word.byteSwap32
{-# INLINE fromBE32 #-}
fromLE32 :: Word32 -> Word32
fromLE32 = if systemEndian == Little then id else Word.byteSwap32
{-# INLINE fromLE32 #-}
fromBE16 :: Word16 -> Word16
fromBE16 = if systemEndian == Big then id else Word.byteSwap16
{-# INLINE fromBE16 #-}
fromLE16 :: Word16 -> Word16
fromLE16 = if systemEndian == Little then id else Word.byteSwap16
{-# INLINE fromLE16 #-}
toBE64 :: Word64 -> Word64
toBE64 = fromBE64
{-# INLINE toBE64 #-}
toLE64 :: Word64 -> Word64
toLE64 = fromLE64
{-# INLINE toLE64 #-}
toBE32 :: Word32 -> Word32
toBE32 = fromBE32
{-# INLINE toBE32 #-}
toLE32 :: Word32 -> Word32
toLE32 = fromLE32
{-# INLINE toLE32 #-}
toBE16 :: Word16 -> Word16
toBE16 = fromBE16
{-# INLINE toBE16 #-}
toLE16 :: Word16 -> Word16
toLE16 = fromLE16
{-# INLINE toLE16 #-}