module Data.ByteArray.MemView
( MemView(..)
, memViewPlus
) where
import Foreign.Ptr
import Data.ByteArray.Types
import Data.Memory.Internal.Imports
data MemView = MemView {-# UNPACK #-} !(Ptr Word8) {-# UNPACK #-} !Int
deriving (Int -> MemView -> ShowS
[MemView] -> ShowS
MemView -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [MemView] -> ShowS
$cshowList :: [MemView] -> ShowS
show :: MemView -> String
$cshow :: MemView -> String
showsPrec :: Int -> MemView -> ShowS
$cshowsPrec :: Int -> MemView -> ShowS
Show,MemView -> MemView -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: MemView -> MemView -> Bool
$c/= :: MemView -> MemView -> Bool
== :: MemView -> MemView -> Bool
$c== :: MemView -> MemView -> Bool
Eq)
instance ByteArrayAccess MemView where
length :: MemView -> Int
length (MemView Ptr Word8
_ Int
l) = Int
l
withByteArray :: forall p a. MemView -> (Ptr p -> IO a) -> IO a
withByteArray (MemView Ptr Word8
p Int
_) Ptr p -> IO a
f = Ptr p -> IO a
f (forall a b. Ptr a -> Ptr b
castPtr Ptr Word8
p)
memViewPlus :: MemView -> Int -> MemView
memViewPlus :: MemView -> Int -> MemView
memViewPlus (MemView Ptr Word8
p Int
len) Int
n = Ptr Word8 -> Int -> MemView
MemView (Ptr Word8
p forall a b. Ptr a -> Int -> Ptr b
`plusPtr` Int
n) (Int
len forall a. Num a => a -> a -> a
- Int
n)