blob: 6b8f39fb554b90e4521ed96f76ccf36bea3aad93 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
|
module ConvertByteString (
ToByteString(..),
FromByteString(..),
ConvertByteString(..),
BA.ScrubbedBytes,
) where
import Data.ByteArray qualified as BA
import Data.ByteString (ByteString)
import Data.ByteString.Unsafe qualified as BS
import Foreign.Ptr
class ToByteString a where
toByteString :: a -> ByteString
withByteArray :: a -> (Ptr p -> IO b) -> IO b
class FromByteString a where
fromByteString :: ByteString -> a
class ConvertByteString a b where
convert :: a -> b
instance ToByteString ByteString where
toByteString = id
withByteArray bs f = BS.unsafeUseAsCString bs (f . castPtr)
instance FromByteString ByteString where
fromByteString = id
instance ToByteString a => ConvertByteString a ByteString where
convert = toByteString
instance ToByteString BA.ScrubbedBytes where
toByteString = BA.convert
withByteArray = BA.withByteArray
instance FromByteString BA.ScrubbedBytes where
fromByteString = BA.convert
instance BA.ByteArrayAccess a => ConvertByteString a BA.ScrubbedBytes where
convert = BA.convert
|