{-# LANGUAGE TypeApplications #-}


-- | Copyright  : Will Thompson, Iñaki García Etxebarria and Jonas Platte
-- License    : LGPL-2.1
-- Maintainer : Iñaki García Etxebarria
-- 
-- t'GI.Gio.Objects.MemoryInputStream.MemoryInputStream' is a class for using arbitrary
-- memory chunks as input for GIO streaming input operations.
-- 
-- As of GLib 2.34, t'GI.Gio.Objects.MemoryInputStream.MemoryInputStream' implements
-- t'GI.Gio.Interfaces.PollableInputStream.PollableInputStream'.

#if (MIN_VERSION_haskell_gi_overloading(1,0,0) && !defined(__HADDOCK_VERSION__))
#define ENABLE_OVERLOADING
#endif

module GI.Gio.Objects.MemoryInputStream
    ( 

-- * Exported types
    MemoryInputStream(..)                   ,
    IsMemoryInputStream                     ,
    toMemoryInputStream                     ,


 -- * Methods
-- ** Overloaded methods #method:Overloaded methods#

#if defined(ENABLE_OVERLOADING)
    ResolveMemoryInputStreamMethod          ,
#endif


-- ** addBytes #method:addBytes#

#if defined(ENABLE_OVERLOADING)
    MemoryInputStreamAddBytesMethodInfo     ,
#endif
    memoryInputStreamAddBytes               ,


-- ** addData #method:addData#

#if defined(ENABLE_OVERLOADING)
    MemoryInputStreamAddDataMethodInfo      ,
#endif
    memoryInputStreamAddData                ,


-- ** new #method:new#

    memoryInputStreamNew                    ,


-- ** newFromBytes #method:newFromBytes#

    memoryInputStreamNewFromBytes           ,


-- ** newFromData #method:newFromData#

    memoryInputStreamNewFromData            ,




    ) where

import Data.GI.Base.ShortPrelude
import qualified Data.GI.Base.ShortPrelude as SP
import qualified Data.GI.Base.Overloading as O
import qualified Prelude as P

import qualified Data.GI.Base.Attributes as GI.Attributes
import qualified Data.GI.Base.BasicTypes as B.Types
import qualified Data.GI.Base.ManagedPtr as B.ManagedPtr
import qualified Data.GI.Base.GClosure as B.GClosure
import qualified Data.GI.Base.GError as B.GError
import qualified Data.GI.Base.GVariant as B.GVariant
import qualified Data.GI.Base.GValue as B.GValue
import qualified Data.GI.Base.GParamSpec as B.GParamSpec
import qualified Data.GI.Base.CallStack as B.CallStack
import qualified Data.GI.Base.Properties as B.Properties
import qualified Data.GI.Base.Signals as B.Signals
import qualified Control.Monad.IO.Class as MIO
import qualified Data.Text as T
import qualified Data.ByteString.Char8 as B
import qualified Data.Map as Map
import qualified Foreign.Ptr as FP
import qualified GHC.OverloadedLabels as OL

import qualified GI.GLib.Callbacks as GLib.Callbacks
import qualified GI.GLib.Structs.Bytes as GLib.Bytes
import qualified GI.GObject.Objects.Object as GObject.Object
import {-# SOURCE #-} qualified GI.Gio.Interfaces.PollableInputStream as Gio.PollableInputStream
import {-# SOURCE #-} qualified GI.Gio.Interfaces.Seekable as Gio.Seekable
import {-# SOURCE #-} qualified GI.Gio.Objects.InputStream as Gio.InputStream

-- | Memory-managed wrapper type.
newtype MemoryInputStream = MemoryInputStream (SP.ManagedPtr MemoryInputStream)
    deriving (MemoryInputStream -> MemoryInputStream -> Bool
(MemoryInputStream -> MemoryInputStream -> Bool)
-> (MemoryInputStream -> MemoryInputStream -> Bool)
-> Eq MemoryInputStream
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: MemoryInputStream -> MemoryInputStream -> Bool
$c/= :: MemoryInputStream -> MemoryInputStream -> Bool
== :: MemoryInputStream -> MemoryInputStream -> Bool
$c== :: MemoryInputStream -> MemoryInputStream -> Bool
Eq)

instance SP.ManagedPtrNewtype MemoryInputStream where
    toManagedPtr :: MemoryInputStream -> ManagedPtr MemoryInputStream
toManagedPtr (MemoryInputStream ManagedPtr MemoryInputStream
p) = ManagedPtr MemoryInputStream
p

foreign import ccall "g_memory_input_stream_get_type"
    c_g_memory_input_stream_get_type :: IO B.Types.GType

instance B.Types.TypedObject MemoryInputStream where
    glibType :: IO GType
glibType = IO GType
c_g_memory_input_stream_get_type

instance B.Types.GObject MemoryInputStream

-- | Convert 'MemoryInputStream' to and from 'Data.GI.Base.GValue.GValue' with 'Data.GI.Base.GValue.toGValue' and 'Data.GI.Base.GValue.fromGValue'.
instance B.GValue.IsGValue MemoryInputStream where
    toGValue :: MemoryInputStream -> IO GValue
toGValue MemoryInputStream
o = do
        GType
gtype <- IO GType
c_g_memory_input_stream_get_type
        MemoryInputStream
-> (Ptr MemoryInputStream -> IO GValue) -> IO GValue
forall a c.
(HasCallStack, ManagedPtrNewtype a) =>
a -> (Ptr a -> IO c) -> IO c
B.ManagedPtr.withManagedPtr MemoryInputStream
o (GType
-> (GValue -> Ptr MemoryInputStream -> IO ())
-> Ptr MemoryInputStream
-> IO GValue
forall a. GType -> (GValue -> a -> IO ()) -> a -> IO GValue
B.GValue.buildGValue GType
gtype GValue -> Ptr MemoryInputStream -> IO ()
forall a. GObject a => GValue -> Ptr a -> IO ()
B.GValue.set_object)
        
    fromGValue :: GValue -> IO MemoryInputStream
fromGValue GValue
gv = do
        Ptr MemoryInputStream
ptr <- GValue -> IO (Ptr MemoryInputStream)
forall b. GObject b => GValue -> IO (Ptr b)
B.GValue.get_object GValue
gv :: IO (Ptr MemoryInputStream)
        (ManagedPtr MemoryInputStream -> MemoryInputStream)
-> Ptr MemoryInputStream -> IO MemoryInputStream
forall a b.
(HasCallStack, GObject a, GObject b) =>
(ManagedPtr a -> a) -> Ptr b -> IO a
B.ManagedPtr.newObject ManagedPtr MemoryInputStream -> MemoryInputStream
MemoryInputStream Ptr MemoryInputStream
ptr
        
    

-- | Type class for types which can be safely cast to `MemoryInputStream`, for instance with `toMemoryInputStream`.
class (SP.GObject o, O.IsDescendantOf MemoryInputStream o) => IsMemoryInputStream o
instance (SP.GObject o, O.IsDescendantOf MemoryInputStream o) => IsMemoryInputStream o

instance O.HasParentTypes MemoryInputStream
type instance O.ParentTypes MemoryInputStream = '[Gio.InputStream.InputStream, GObject.Object.Object, Gio.PollableInputStream.PollableInputStream, Gio.Seekable.Seekable]

-- | Cast to `MemoryInputStream`, for types for which this is known to be safe. For general casts, use `Data.GI.Base.ManagedPtr.castTo`.
toMemoryInputStream :: (MonadIO m, IsMemoryInputStream o) => o -> m MemoryInputStream
toMemoryInputStream :: o -> m MemoryInputStream
toMemoryInputStream = IO MemoryInputStream -> m MemoryInputStream
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO MemoryInputStream -> m MemoryInputStream)
-> (o -> IO MemoryInputStream) -> o -> m MemoryInputStream
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (ManagedPtr MemoryInputStream -> MemoryInputStream)
-> o -> IO MemoryInputStream
forall o o'.
(HasCallStack, ManagedPtrNewtype o, TypedObject o,
 ManagedPtrNewtype o', TypedObject o') =>
(ManagedPtr o' -> o') -> o -> IO o'
unsafeCastTo ManagedPtr MemoryInputStream -> MemoryInputStream
MemoryInputStream

#if defined(ENABLE_OVERLOADING)
type family ResolveMemoryInputStreamMethod (t :: Symbol) (o :: *) :: * where
    ResolveMemoryInputStreamMethod "addBytes" o = MemoryInputStreamAddBytesMethodInfo
    ResolveMemoryInputStreamMethod "addData" o = MemoryInputStreamAddDataMethodInfo
    ResolveMemoryInputStreamMethod "bindProperty" o = GObject.Object.ObjectBindPropertyMethodInfo
    ResolveMemoryInputStreamMethod "bindPropertyFull" o = GObject.Object.ObjectBindPropertyFullMethodInfo
    ResolveMemoryInputStreamMethod "canPoll" o = Gio.PollableInputStream.PollableInputStreamCanPollMethodInfo
    ResolveMemoryInputStreamMethod "canSeek" o = Gio.Seekable.SeekableCanSeekMethodInfo
    ResolveMemoryInputStreamMethod "canTruncate" o = Gio.Seekable.SeekableCanTruncateMethodInfo
    ResolveMemoryInputStreamMethod "clearPending" o = Gio.InputStream.InputStreamClearPendingMethodInfo
    ResolveMemoryInputStreamMethod "close" o = Gio.InputStream.InputStreamCloseMethodInfo
    ResolveMemoryInputStreamMethod "closeAsync" o = Gio.InputStream.InputStreamCloseAsyncMethodInfo
    ResolveMemoryInputStreamMethod "closeFinish" o = Gio.InputStream.InputStreamCloseFinishMethodInfo
    ResolveMemoryInputStreamMethod "createSource" o = Gio.PollableInputStream.PollableInputStreamCreateSourceMethodInfo
    ResolveMemoryInputStreamMethod "forceFloating" o = GObject.Object.ObjectForceFloatingMethodInfo
    ResolveMemoryInputStreamMethod "freezeNotify" o = GObject.Object.ObjectFreezeNotifyMethodInfo
    ResolveMemoryInputStreamMethod "getv" o = GObject.Object.ObjectGetvMethodInfo
    ResolveMemoryInputStreamMethod "hasPending" o = Gio.InputStream.InputStreamHasPendingMethodInfo
    ResolveMemoryInputStreamMethod "isClosed" o = Gio.InputStream.InputStreamIsClosedMethodInfo
    ResolveMemoryInputStreamMethod "isFloating" o = GObject.Object.ObjectIsFloatingMethodInfo
    ResolveMemoryInputStreamMethod "isReadable" o = Gio.PollableInputStream.PollableInputStreamIsReadableMethodInfo
    ResolveMemoryInputStreamMethod "notify" o = GObject.Object.ObjectNotifyMethodInfo
    ResolveMemoryInputStreamMethod "notifyByPspec" o = GObject.Object.ObjectNotifyByPspecMethodInfo
    ResolveMemoryInputStreamMethod "read" o = Gio.InputStream.InputStreamReadMethodInfo
    ResolveMemoryInputStreamMethod "readAll" o = Gio.InputStream.InputStreamReadAllMethodInfo
    ResolveMemoryInputStreamMethod "readAllAsync" o = Gio.InputStream.InputStreamReadAllAsyncMethodInfo
    ResolveMemoryInputStreamMethod "readAllFinish" o = Gio.InputStream.InputStreamReadAllFinishMethodInfo
    ResolveMemoryInputStreamMethod "readAsync" o = Gio.InputStream.InputStreamReadAsyncMethodInfo
    ResolveMemoryInputStreamMethod "readBytes" o = Gio.InputStream.InputStreamReadBytesMethodInfo
    ResolveMemoryInputStreamMethod "readBytesAsync" o = Gio.InputStream.InputStreamReadBytesAsyncMethodInfo
    ResolveMemoryInputStreamMethod "readBytesFinish" o = Gio.InputStream.InputStreamReadBytesFinishMethodInfo
    ResolveMemoryInputStreamMethod "readFinish" o = Gio.InputStream.InputStreamReadFinishMethodInfo
    ResolveMemoryInputStreamMethod "readNonblocking" o = Gio.PollableInputStream.PollableInputStreamReadNonblockingMethodInfo
    ResolveMemoryInputStreamMethod "ref" o = GObject.Object.ObjectRefMethodInfo
    ResolveMemoryInputStreamMethod "refSink" o = GObject.Object.ObjectRefSinkMethodInfo
    ResolveMemoryInputStreamMethod "runDispose" o = GObject.Object.ObjectRunDisposeMethodInfo
    ResolveMemoryInputStreamMethod "seek" o = Gio.Seekable.SeekableSeekMethodInfo
    ResolveMemoryInputStreamMethod "skip" o = Gio.InputStream.InputStreamSkipMethodInfo
    ResolveMemoryInputStreamMethod "skipAsync" o = Gio.InputStream.InputStreamSkipAsyncMethodInfo
    ResolveMemoryInputStreamMethod "skipFinish" o = Gio.InputStream.InputStreamSkipFinishMethodInfo
    ResolveMemoryInputStreamMethod "stealData" o = GObject.Object.ObjectStealDataMethodInfo
    ResolveMemoryInputStreamMethod "stealQdata" o = GObject.Object.ObjectStealQdataMethodInfo
    ResolveMemoryInputStreamMethod "tell" o = Gio.Seekable.SeekableTellMethodInfo
    ResolveMemoryInputStreamMethod "thawNotify" o = GObject.Object.ObjectThawNotifyMethodInfo
    ResolveMemoryInputStreamMethod "truncate" o = Gio.Seekable.SeekableTruncateMethodInfo
    ResolveMemoryInputStreamMethod "unref" o = GObject.Object.ObjectUnrefMethodInfo
    ResolveMemoryInputStreamMethod "watchClosure" o = GObject.Object.ObjectWatchClosureMethodInfo
    ResolveMemoryInputStreamMethod "getData" o = GObject.Object.ObjectGetDataMethodInfo
    ResolveMemoryInputStreamMethod "getProperty" o = GObject.Object.ObjectGetPropertyMethodInfo
    ResolveMemoryInputStreamMethod "getQdata" o = GObject.Object.ObjectGetQdataMethodInfo
    ResolveMemoryInputStreamMethod "setData" o = GObject.Object.ObjectSetDataMethodInfo
    ResolveMemoryInputStreamMethod "setDataFull" o = GObject.Object.ObjectSetDataFullMethodInfo
    ResolveMemoryInputStreamMethod "setPending" o = Gio.InputStream.InputStreamSetPendingMethodInfo
    ResolveMemoryInputStreamMethod "setProperty" o = GObject.Object.ObjectSetPropertyMethodInfo
    ResolveMemoryInputStreamMethod l o = O.MethodResolutionFailed l o

instance (info ~ ResolveMemoryInputStreamMethod t MemoryInputStream, O.MethodInfo info MemoryInputStream p) => OL.IsLabel t (MemoryInputStream -> p) where
#if MIN_VERSION_base(4,10,0)
    fromLabel = O.overloadedMethod @info
#else
    fromLabel _ = O.overloadedMethod @info
#endif

#endif

#if defined(ENABLE_OVERLOADING)
instance O.HasAttributeList MemoryInputStream
type instance O.AttributeList MemoryInputStream = MemoryInputStreamAttributeList
type MemoryInputStreamAttributeList = ('[ ] :: [(Symbol, *)])
#endif

#if defined(ENABLE_OVERLOADING)
#endif

#if defined(ENABLE_OVERLOADING)
type instance O.SignalList MemoryInputStream = MemoryInputStreamSignalList
type MemoryInputStreamSignalList = ('[ '("notify", GObject.Object.ObjectNotifySignalInfo)] :: [(Symbol, *)])

#endif

-- method MemoryInputStream::new
-- method type : Constructor
-- Args: []
-- Lengths: []
-- returnType: Just
--               (TInterface
--                  Name { namespace = "Gio" , name = "MemoryInputStream" })
-- throws : False
-- Skip return : False

foreign import ccall "g_memory_input_stream_new" g_memory_input_stream_new :: 
    IO (Ptr MemoryInputStream)

-- | Creates a new empty t'GI.Gio.Objects.MemoryInputStream.MemoryInputStream'.
memoryInputStreamNew ::
    (B.CallStack.HasCallStack, MonadIO m) =>
    m MemoryInputStream
    -- ^ __Returns:__ a new t'GI.Gio.Objects.InputStream.InputStream'
memoryInputStreamNew :: m MemoryInputStream
memoryInputStreamNew  = IO MemoryInputStream -> m MemoryInputStream
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO MemoryInputStream -> m MemoryInputStream)
-> IO MemoryInputStream -> m MemoryInputStream
forall a b. (a -> b) -> a -> b
$ do
    Ptr MemoryInputStream
result <- IO (Ptr MemoryInputStream)
g_memory_input_stream_new
    Text -> Ptr MemoryInputStream -> IO ()
forall a. HasCallStack => Text -> Ptr a -> IO ()
checkUnexpectedReturnNULL Text
"memoryInputStreamNew" Ptr MemoryInputStream
result
    MemoryInputStream
result' <- ((ManagedPtr MemoryInputStream -> MemoryInputStream)
-> Ptr MemoryInputStream -> IO MemoryInputStream
forall a b.
(HasCallStack, GObject a, GObject b) =>
(ManagedPtr a -> a) -> Ptr b -> IO a
wrapObject ManagedPtr MemoryInputStream -> MemoryInputStream
MemoryInputStream) Ptr MemoryInputStream
result
    MemoryInputStream -> IO MemoryInputStream
forall (m :: * -> *) a. Monad m => a -> m a
return MemoryInputStream
result'

#if defined(ENABLE_OVERLOADING)
#endif

-- method MemoryInputStream::new_from_bytes
-- method type : Constructor
-- Args: [ Arg
--           { argCName = "bytes"
--           , argType = TInterface Name { namespace = "GLib" , name = "Bytes" }
--           , direction = DirectionIn
--           , mayBeNull = False
--           , argDoc =
--               Documentation
--                 { rawDocText = Just "a #GBytes" , sinceVersion = Nothing }
--           , argScope = ScopeTypeInvalid
--           , argClosure = -1
--           , argDestroy = -1
--           , argCallerAllocates = False
--           , transfer = TransferNothing
--           }
--       ]
-- Lengths: []
-- returnType: Just
--               (TInterface
--                  Name { namespace = "Gio" , name = "MemoryInputStream" })
-- throws : False
-- Skip return : False

foreign import ccall "g_memory_input_stream_new_from_bytes" g_memory_input_stream_new_from_bytes :: 
    Ptr GLib.Bytes.Bytes ->                 -- bytes : TInterface (Name {namespace = "GLib", name = "Bytes"})
    IO (Ptr MemoryInputStream)

-- | Creates a new t'GI.Gio.Objects.MemoryInputStream.MemoryInputStream' with data from the given /@bytes@/.
-- 
-- /Since: 2.34/
memoryInputStreamNewFromBytes ::
    (B.CallStack.HasCallStack, MonadIO m) =>
    GLib.Bytes.Bytes
    -- ^ /@bytes@/: a t'GI.GLib.Structs.Bytes.Bytes'
    -> m MemoryInputStream
    -- ^ __Returns:__ new t'GI.Gio.Objects.InputStream.InputStream' read from /@bytes@/
memoryInputStreamNewFromBytes :: Bytes -> m MemoryInputStream
memoryInputStreamNewFromBytes Bytes
bytes = IO MemoryInputStream -> m MemoryInputStream
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO MemoryInputStream -> m MemoryInputStream)
-> IO MemoryInputStream -> m MemoryInputStream
forall a b. (a -> b) -> a -> b
$ do
    Ptr Bytes
bytes' <- Bytes -> IO (Ptr Bytes)
forall a. (HasCallStack, ManagedPtrNewtype a) => a -> IO (Ptr a)
unsafeManagedPtrGetPtr Bytes
bytes
    Ptr MemoryInputStream
result <- Ptr Bytes -> IO (Ptr MemoryInputStream)
g_memory_input_stream_new_from_bytes Ptr Bytes
bytes'
    Text -> Ptr MemoryInputStream -> IO ()
forall a. HasCallStack => Text -> Ptr a -> IO ()
checkUnexpectedReturnNULL Text
"memoryInputStreamNewFromBytes" Ptr MemoryInputStream
result
    MemoryInputStream
result' <- ((ManagedPtr MemoryInputStream -> MemoryInputStream)
-> Ptr MemoryInputStream -> IO MemoryInputStream
forall a b.
(HasCallStack, GObject a, GObject b) =>
(ManagedPtr a -> a) -> Ptr b -> IO a
wrapObject ManagedPtr MemoryInputStream -> MemoryInputStream
MemoryInputStream) Ptr MemoryInputStream
result
    Bytes -> IO ()
forall a. ManagedPtrNewtype a => a -> IO ()
touchManagedPtr Bytes
bytes
    MemoryInputStream -> IO MemoryInputStream
forall (m :: * -> *) a. Monad m => a -> m a
return MemoryInputStream
result'

#if defined(ENABLE_OVERLOADING)
#endif

-- method MemoryInputStream::new_from_data
-- method type : Constructor
-- Args: [ Arg
--           { argCName = "data"
--           , argType = TCArray False (-1) 1 (TBasicType TUInt8)
--           , direction = DirectionIn
--           , mayBeNull = False
--           , argDoc =
--               Documentation
--                 { rawDocText = Just "input data" , sinceVersion = Nothing }
--           , argScope = ScopeTypeInvalid
--           , argClosure = -1
--           , argDestroy = -1
--           , argCallerAllocates = False
--           , transfer = TransferEverything
--           }
--       , Arg
--           { argCName = "len"
--           , argType = TBasicType TInt64
--           , direction = DirectionIn
--           , mayBeNull = False
--           , argDoc =
--               Documentation
--                 { rawDocText =
--                     Just
--                       "length of the data, may be -1 if @data is a nul-terminated string"
--                 , sinceVersion = Nothing
--                 }
--           , argScope = ScopeTypeInvalid
--           , argClosure = -1
--           , argDestroy = -1
--           , argCallerAllocates = False
--           , transfer = TransferNothing
--           }
--       , Arg
--           { argCName = "destroy"
--           , argType =
--               TInterface Name { namespace = "GLib" , name = "DestroyNotify" }
--           , direction = DirectionIn
--           , mayBeNull = True
--           , argDoc =
--               Documentation
--                 { rawDocText =
--                     Just "function that is called to free @data, or %NULL"
--                 , sinceVersion = Nothing
--                 }
--           , argScope = ScopeTypeAsync
--           , argClosure = -1
--           , argDestroy = -1
--           , argCallerAllocates = False
--           , transfer = TransferNothing
--           }
--       ]
-- Lengths: [ Arg
--              { argCName = "len"
--              , argType = TBasicType TInt64
--              , direction = DirectionIn
--              , mayBeNull = False
--              , argDoc =
--                  Documentation
--                    { rawDocText =
--                        Just
--                          "length of the data, may be -1 if @data is a nul-terminated string"
--                    , sinceVersion = Nothing
--                    }
--              , argScope = ScopeTypeInvalid
--              , argClosure = -1
--              , argDestroy = -1
--              , argCallerAllocates = False
--              , transfer = TransferNothing
--              }
--          ]
-- returnType: Just
--               (TInterface
--                  Name { namespace = "Gio" , name = "MemoryInputStream" })
-- throws : False
-- Skip return : False

foreign import ccall "g_memory_input_stream_new_from_data" g_memory_input_stream_new_from_data :: 
    Ptr Word8 ->                            -- data : TCArray False (-1) 1 (TBasicType TUInt8)
    Int64 ->                                -- len : TBasicType TInt64
    FunPtr GLib.Callbacks.C_DestroyNotify -> -- destroy : TInterface (Name {namespace = "GLib", name = "DestroyNotify"})
    IO (Ptr MemoryInputStream)

-- | Creates a new t'GI.Gio.Objects.MemoryInputStream.MemoryInputStream' with data in memory of a given size.
memoryInputStreamNewFromData ::
    (B.CallStack.HasCallStack, MonadIO m) =>
    ByteString
    -- ^ /@data@/: input data
    -> Maybe (GLib.Callbacks.DestroyNotify)
    -- ^ /@destroy@/: function that is called to free /@data@/, or 'P.Nothing'
    -> m MemoryInputStream
    -- ^ __Returns:__ new t'GI.Gio.Objects.InputStream.InputStream' read from /@data@/ of /@len@/ bytes.
memoryInputStreamNewFromData :: ByteString -> Maybe DestroyNotify -> m MemoryInputStream
memoryInputStreamNewFromData ByteString
data_ Maybe DestroyNotify
destroy = IO MemoryInputStream -> m MemoryInputStream
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO MemoryInputStream -> m MemoryInputStream)
-> IO MemoryInputStream -> m MemoryInputStream
forall a b. (a -> b) -> a -> b
$ do
    let len :: Int64
len = Int -> Int64
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Int -> Int64) -> Int -> Int64
forall a b. (a -> b) -> a -> b
$ ByteString -> Int
B.length ByteString
data_
    Ptr Word8
data_' <- ByteString -> IO (Ptr Word8)
packByteString ByteString
data_
    FunPtr DestroyNotify
maybeDestroy <- case Maybe DestroyNotify
destroy of
        Maybe DestroyNotify
Nothing -> FunPtr DestroyNotify -> IO (FunPtr DestroyNotify)
forall (m :: * -> *) a. Monad m => a -> m a
return (Ptr Any -> FunPtr DestroyNotify
forall a b. Ptr a -> FunPtr b
castPtrToFunPtr Ptr Any
forall a. Ptr a
nullPtr)
        Just DestroyNotify
jDestroy -> do
            Ptr (FunPtr DestroyNotify)
ptrdestroy <- IO (Ptr (FunPtr DestroyNotify))
forall a. Storable a => IO (Ptr a)
callocMem :: IO (Ptr (FunPtr GLib.Callbacks.C_DestroyNotify))
            FunPtr DestroyNotify
jDestroy' <- DestroyNotify -> IO (FunPtr DestroyNotify)
GLib.Callbacks.mk_DestroyNotify (Maybe (Ptr (FunPtr DestroyNotify))
-> DestroyNotify -> DestroyNotify
GLib.Callbacks.wrap_DestroyNotify (Ptr (FunPtr DestroyNotify) -> Maybe (Ptr (FunPtr DestroyNotify))
forall a. a -> Maybe a
Just Ptr (FunPtr DestroyNotify)
ptrdestroy) DestroyNotify
jDestroy)
            Ptr (FunPtr DestroyNotify) -> FunPtr DestroyNotify -> IO ()
forall a. Storable a => Ptr a -> a -> IO ()
poke Ptr (FunPtr DestroyNotify)
ptrdestroy FunPtr DestroyNotify
jDestroy'
            FunPtr DestroyNotify -> IO (FunPtr DestroyNotify)
forall (m :: * -> *) a. Monad m => a -> m a
return FunPtr DestroyNotify
jDestroy'
    Ptr MemoryInputStream
result <- Ptr Word8
-> Int64 -> FunPtr DestroyNotify -> IO (Ptr MemoryInputStream)
g_memory_input_stream_new_from_data Ptr Word8
data_' Int64
len FunPtr DestroyNotify
maybeDestroy
    Text -> Ptr MemoryInputStream -> IO ()
forall a. HasCallStack => Text -> Ptr a -> IO ()
checkUnexpectedReturnNULL Text
"memoryInputStreamNewFromData" Ptr MemoryInputStream
result
    MemoryInputStream
result' <- ((ManagedPtr MemoryInputStream -> MemoryInputStream)
-> Ptr MemoryInputStream -> IO MemoryInputStream
forall a b.
(HasCallStack, GObject a, GObject b) =>
(ManagedPtr a -> a) -> Ptr b -> IO a
wrapObject ManagedPtr MemoryInputStream -> MemoryInputStream
MemoryInputStream) Ptr MemoryInputStream
result
    MemoryInputStream -> IO MemoryInputStream
forall (m :: * -> *) a. Monad m => a -> m a
return MemoryInputStream
result'

#if defined(ENABLE_OVERLOADING)
#endif

-- method MemoryInputStream::add_bytes
-- method type : OrdinaryMethod
-- Args: [ Arg
--           { argCName = "stream"
--           , argType =
--               TInterface Name { namespace = "Gio" , name = "MemoryInputStream" }
--           , direction = DirectionIn
--           , mayBeNull = False
--           , argDoc =
--               Documentation
--                 { rawDocText = Just "a #GMemoryInputStream"
--                 , sinceVersion = Nothing
--                 }
--           , argScope = ScopeTypeInvalid
--           , argClosure = -1
--           , argDestroy = -1
--           , argCallerAllocates = False
--           , transfer = TransferNothing
--           }
--       , Arg
--           { argCName = "bytes"
--           , argType = TInterface Name { namespace = "GLib" , name = "Bytes" }
--           , direction = DirectionIn
--           , mayBeNull = False
--           , argDoc =
--               Documentation
--                 { rawDocText = Just "input data" , sinceVersion = Nothing }
--           , argScope = ScopeTypeInvalid
--           , argClosure = -1
--           , argDestroy = -1
--           , argCallerAllocates = False
--           , transfer = TransferNothing
--           }
--       ]
-- Lengths: []
-- returnType: Nothing
-- throws : False
-- Skip return : False

foreign import ccall "g_memory_input_stream_add_bytes" g_memory_input_stream_add_bytes :: 
    Ptr MemoryInputStream ->                -- stream : TInterface (Name {namespace = "Gio", name = "MemoryInputStream"})
    Ptr GLib.Bytes.Bytes ->                 -- bytes : TInterface (Name {namespace = "GLib", name = "Bytes"})
    IO ()

-- | Appends /@bytes@/ to data that can be read from the input stream.
-- 
-- /Since: 2.34/
memoryInputStreamAddBytes ::
    (B.CallStack.HasCallStack, MonadIO m, IsMemoryInputStream a) =>
    a
    -- ^ /@stream@/: a t'GI.Gio.Objects.MemoryInputStream.MemoryInputStream'
    -> GLib.Bytes.Bytes
    -- ^ /@bytes@/: input data
    -> m ()
memoryInputStreamAddBytes :: a -> Bytes -> m ()
memoryInputStreamAddBytes a
stream Bytes
bytes = IO () -> m ()
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO () -> m ()) -> IO () -> m ()
forall a b. (a -> b) -> a -> b
$ do
    Ptr MemoryInputStream
stream' <- a -> IO (Ptr MemoryInputStream)
forall a b. (HasCallStack, ManagedPtrNewtype a) => a -> IO (Ptr b)
unsafeManagedPtrCastPtr a
stream
    Ptr Bytes
bytes' <- Bytes -> IO (Ptr Bytes)
forall a. (HasCallStack, ManagedPtrNewtype a) => a -> IO (Ptr a)
unsafeManagedPtrGetPtr Bytes
bytes
    Ptr MemoryInputStream -> Ptr Bytes -> IO ()
g_memory_input_stream_add_bytes Ptr MemoryInputStream
stream' Ptr Bytes
bytes'
    a -> IO ()
forall a. ManagedPtrNewtype a => a -> IO ()
touchManagedPtr a
stream
    Bytes -> IO ()
forall a. ManagedPtrNewtype a => a -> IO ()
touchManagedPtr Bytes
bytes
    () -> IO ()
forall (m :: * -> *) a. Monad m => a -> m a
return ()

#if defined(ENABLE_OVERLOADING)
data MemoryInputStreamAddBytesMethodInfo
instance (signature ~ (GLib.Bytes.Bytes -> m ()), MonadIO m, IsMemoryInputStream a) => O.MethodInfo MemoryInputStreamAddBytesMethodInfo a signature where
    overloadedMethod = memoryInputStreamAddBytes

#endif

-- method MemoryInputStream::add_data
-- method type : OrdinaryMethod
-- Args: [ Arg
--           { argCName = "stream"
--           , argType =
--               TInterface Name { namespace = "Gio" , name = "MemoryInputStream" }
--           , direction = DirectionIn
--           , mayBeNull = False
--           , argDoc =
--               Documentation
--                 { rawDocText = Just "a #GMemoryInputStream"
--                 , sinceVersion = Nothing
--                 }
--           , argScope = ScopeTypeInvalid
--           , argClosure = -1
--           , argDestroy = -1
--           , argCallerAllocates = False
--           , transfer = TransferNothing
--           }
--       , Arg
--           { argCName = "data"
--           , argType = TCArray False (-1) 2 (TBasicType TUInt8)
--           , direction = DirectionIn
--           , mayBeNull = False
--           , argDoc =
--               Documentation
--                 { rawDocText = Just "input data" , sinceVersion = Nothing }
--           , argScope = ScopeTypeInvalid
--           , argClosure = -1
--           , argDestroy = -1
--           , argCallerAllocates = False
--           , transfer = TransferEverything
--           }
--       , Arg
--           { argCName = "len"
--           , argType = TBasicType TInt64
--           , direction = DirectionIn
--           , mayBeNull = False
--           , argDoc =
--               Documentation
--                 { rawDocText =
--                     Just
--                       "length of the data, may be -1 if @data is a nul-terminated string"
--                 , sinceVersion = Nothing
--                 }
--           , argScope = ScopeTypeInvalid
--           , argClosure = -1
--           , argDestroy = -1
--           , argCallerAllocates = False
--           , transfer = TransferNothing
--           }
--       , Arg
--           { argCName = "destroy"
--           , argType =
--               TInterface Name { namespace = "GLib" , name = "DestroyNotify" }
--           , direction = DirectionIn
--           , mayBeNull = True
--           , argDoc =
--               Documentation
--                 { rawDocText =
--                     Just "function that is called to free @data, or %NULL"
--                 , sinceVersion = Nothing
--                 }
--           , argScope = ScopeTypeAsync
--           , argClosure = -1
--           , argDestroy = -1
--           , argCallerAllocates = False
--           , transfer = TransferNothing
--           }
--       ]
-- Lengths: [ Arg
--              { argCName = "len"
--              , argType = TBasicType TInt64
--              , direction = DirectionIn
--              , mayBeNull = False
--              , argDoc =
--                  Documentation
--                    { rawDocText =
--                        Just
--                          "length of the data, may be -1 if @data is a nul-terminated string"
--                    , sinceVersion = Nothing
--                    }
--              , argScope = ScopeTypeInvalid
--              , argClosure = -1
--              , argDestroy = -1
--              , argCallerAllocates = False
--              , transfer = TransferNothing
--              }
--          ]
-- returnType: Nothing
-- throws : False
-- Skip return : False

foreign import ccall "g_memory_input_stream_add_data" g_memory_input_stream_add_data :: 
    Ptr MemoryInputStream ->                -- stream : TInterface (Name {namespace = "Gio", name = "MemoryInputStream"})
    Ptr Word8 ->                            -- data : TCArray False (-1) 2 (TBasicType TUInt8)
    Int64 ->                                -- len : TBasicType TInt64
    FunPtr GLib.Callbacks.C_DestroyNotify -> -- destroy : TInterface (Name {namespace = "GLib", name = "DestroyNotify"})
    IO ()

-- | Appends /@data@/ to data that can be read from the input stream
memoryInputStreamAddData ::
    (B.CallStack.HasCallStack, MonadIO m, IsMemoryInputStream a) =>
    a
    -- ^ /@stream@/: a t'GI.Gio.Objects.MemoryInputStream.MemoryInputStream'
    -> ByteString
    -- ^ /@data@/: input data
    -> Maybe (GLib.Callbacks.DestroyNotify)
    -- ^ /@destroy@/: function that is called to free /@data@/, or 'P.Nothing'
    -> m ()
memoryInputStreamAddData :: a -> ByteString -> Maybe DestroyNotify -> m ()
memoryInputStreamAddData a
stream ByteString
data_ Maybe DestroyNotify
destroy = IO () -> m ()
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO () -> m ()) -> IO () -> m ()
forall a b. (a -> b) -> a -> b
$ do
    let len :: Int64
len = Int -> Int64
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Int -> Int64) -> Int -> Int64
forall a b. (a -> b) -> a -> b
$ ByteString -> Int
B.length ByteString
data_
    Ptr MemoryInputStream
stream' <- a -> IO (Ptr MemoryInputStream)
forall a b. (HasCallStack, ManagedPtrNewtype a) => a -> IO (Ptr b)
unsafeManagedPtrCastPtr a
stream
    Ptr Word8
data_' <- ByteString -> IO (Ptr Word8)
packByteString ByteString
data_
    FunPtr DestroyNotify
maybeDestroy <- case Maybe DestroyNotify
destroy of
        Maybe DestroyNotify
Nothing -> FunPtr DestroyNotify -> IO (FunPtr DestroyNotify)
forall (m :: * -> *) a. Monad m => a -> m a
return (Ptr Any -> FunPtr DestroyNotify
forall a b. Ptr a -> FunPtr b
castPtrToFunPtr Ptr Any
forall a. Ptr a
nullPtr)
        Just DestroyNotify
jDestroy -> do
            Ptr (FunPtr DestroyNotify)
ptrdestroy <- IO (Ptr (FunPtr DestroyNotify))
forall a. Storable a => IO (Ptr a)
callocMem :: IO (Ptr (FunPtr GLib.Callbacks.C_DestroyNotify))
            FunPtr DestroyNotify
jDestroy' <- DestroyNotify -> IO (FunPtr DestroyNotify)
GLib.Callbacks.mk_DestroyNotify (Maybe (Ptr (FunPtr DestroyNotify))
-> DestroyNotify -> DestroyNotify
GLib.Callbacks.wrap_DestroyNotify (Ptr (FunPtr DestroyNotify) -> Maybe (Ptr (FunPtr DestroyNotify))
forall a. a -> Maybe a
Just Ptr (FunPtr DestroyNotify)
ptrdestroy) DestroyNotify
jDestroy)
            Ptr (FunPtr DestroyNotify) -> FunPtr DestroyNotify -> IO ()
forall a. Storable a => Ptr a -> a -> IO ()
poke Ptr (FunPtr DestroyNotify)
ptrdestroy FunPtr DestroyNotify
jDestroy'
            FunPtr DestroyNotify -> IO (FunPtr DestroyNotify)
forall (m :: * -> *) a. Monad m => a -> m a
return FunPtr DestroyNotify
jDestroy'
    Ptr MemoryInputStream
-> Ptr Word8 -> Int64 -> FunPtr DestroyNotify -> IO ()
g_memory_input_stream_add_data Ptr MemoryInputStream
stream' Ptr Word8
data_' Int64
len FunPtr DestroyNotify
maybeDestroy
    a -> IO ()
forall a. ManagedPtrNewtype a => a -> IO ()
touchManagedPtr a
stream
    () -> IO ()
forall (m :: * -> *) a. Monad m => a -> m a
return ()

#if defined(ENABLE_OVERLOADING)
data MemoryInputStreamAddDataMethodInfo
instance (signature ~ (ByteString -> Maybe (GLib.Callbacks.DestroyNotify) -> m ()), MonadIO m, IsMemoryInputStream a) => O.MethodInfo MemoryInputStreamAddDataMethodInfo a signature where
    overloadedMethod = memoryInputStreamAddData

#endif