module Data.Ruby.Marshal.Int (
getInt8
, getInt16le
, getInt24le
, getInt32le
, Int16
, getWord8
, getWord16le
, getWord24le
, getWord32le
, Word8
) where
import Control.Applicative
import Data.Bits (shiftL, (.|.))
import qualified Data.ByteString as BS
import Data.Int (Int16, Int32, Int8)
import Data.Serialize.Get (Get, getBytes, getWord16le, getWord32le,
getWord8)
import Data.Word (Word32, Word8)
import Prelude
getInt8 :: Get Int8
getInt8 = fromIntegral <$> getWord8
getInt16le :: Get Int16
getInt16le = fromIntegral <$> getWord16le
getWord24le :: Get Word32
getWord24le = do
s <- getBytes 3
return $! (fromIntegral (s `BS.index` 2) `shiftL` 16) .|.
(fromIntegral (s `BS.index` 1) `shiftL` 8) .|.
fromIntegral (s `BS.index` 0)
getInt24le :: Get Int32
getInt24le = fromIntegral <$> getWord24le
getInt32le :: Get Int32
getInt32le = fromIntegral <$> getWord32le