{-# 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.Interfaces.Converter.Converter' is implemented by objects that convert
-- binary data in various ways. The conversion can be
-- stateful and may fail at any place.
-- 
-- Some example conversions are: character set conversion,
-- compression, decompression and regular expression
-- replace.
-- 
-- /Since: 2.24/

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

module GI.Gio.Interfaces.Converter
    ( 

-- * Exported types
    Converter(..)                           ,
    noConverter                             ,
    IsConverter                             ,
    toConverter                             ,


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

#if defined(ENABLE_OVERLOADING)
    ResolveConverterMethod                  ,
#endif


-- ** convert #method:convert#

#if defined(ENABLE_OVERLOADING)
    ConverterConvertMethodInfo              ,
#endif
    converterConvert                        ,


-- ** reset #method:reset#

#if defined(ENABLE_OVERLOADING)
    ConverterResetMethodInfo                ,
#endif
    converterReset                          ,




    ) 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.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 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.GObject.Objects.Object as GObject.Object
import {-# SOURCE #-} qualified GI.Gio.Enums as Gio.Enums
import {-# SOURCE #-} qualified GI.Gio.Flags as Gio.Flags

-- interface Converter 
-- | Memory-managed wrapper type.
newtype Converter = Converter (ManagedPtr Converter)
    deriving (Converter -> Converter -> Bool
(Converter -> Converter -> Bool)
-> (Converter -> Converter -> Bool) -> Eq Converter
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Converter -> Converter -> Bool
$c/= :: Converter -> Converter -> Bool
== :: Converter -> Converter -> Bool
$c== :: Converter -> Converter -> Bool
Eq)
-- | A convenience alias for `Nothing` :: `Maybe` `Converter`.
noConverter :: Maybe Converter
noConverter :: Maybe Converter
noConverter = Maybe Converter
forall a. Maybe a
Nothing

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

#endif

foreign import ccall "g_converter_get_type"
    c_g_converter_get_type :: IO GType

instance GObject Converter where
    gobjectType :: IO GType
gobjectType = IO GType
c_g_converter_get_type
    

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

-- | Type class for types which can be safely cast to `Converter`, for instance with `toConverter`.
class (GObject o, O.IsDescendantOf Converter o) => IsConverter o
instance (GObject o, O.IsDescendantOf Converter o) => IsConverter o

instance O.HasParentTypes Converter
type instance O.ParentTypes Converter = '[GObject.Object.Object]

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

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

#if defined(ENABLE_OVERLOADING)
#endif

#if defined(ENABLE_OVERLOADING)
type family ResolveConverterMethod (t :: Symbol) (o :: *) :: * where
    ResolveConverterMethod "bindProperty" o = GObject.Object.ObjectBindPropertyMethodInfo
    ResolveConverterMethod "bindPropertyFull" o = GObject.Object.ObjectBindPropertyFullMethodInfo
    ResolveConverterMethod "convert" o = ConverterConvertMethodInfo
    ResolveConverterMethod "forceFloating" o = GObject.Object.ObjectForceFloatingMethodInfo
    ResolveConverterMethod "freezeNotify" o = GObject.Object.ObjectFreezeNotifyMethodInfo
    ResolveConverterMethod "getv" o = GObject.Object.ObjectGetvMethodInfo
    ResolveConverterMethod "isFloating" o = GObject.Object.ObjectIsFloatingMethodInfo
    ResolveConverterMethod "notify" o = GObject.Object.ObjectNotifyMethodInfo
    ResolveConverterMethod "notifyByPspec" o = GObject.Object.ObjectNotifyByPspecMethodInfo
    ResolveConverterMethod "ref" o = GObject.Object.ObjectRefMethodInfo
    ResolveConverterMethod "refSink" o = GObject.Object.ObjectRefSinkMethodInfo
    ResolveConverterMethod "reset" o = ConverterResetMethodInfo
    ResolveConverterMethod "runDispose" o = GObject.Object.ObjectRunDisposeMethodInfo
    ResolveConverterMethod "stealData" o = GObject.Object.ObjectStealDataMethodInfo
    ResolveConverterMethod "stealQdata" o = GObject.Object.ObjectStealQdataMethodInfo
    ResolveConverterMethod "thawNotify" o = GObject.Object.ObjectThawNotifyMethodInfo
    ResolveConverterMethod "unref" o = GObject.Object.ObjectUnrefMethodInfo
    ResolveConverterMethod "watchClosure" o = GObject.Object.ObjectWatchClosureMethodInfo
    ResolveConverterMethod "getData" o = GObject.Object.ObjectGetDataMethodInfo
    ResolveConverterMethod "getProperty" o = GObject.Object.ObjectGetPropertyMethodInfo
    ResolveConverterMethod "getQdata" o = GObject.Object.ObjectGetQdataMethodInfo
    ResolveConverterMethod "setData" o = GObject.Object.ObjectSetDataMethodInfo
    ResolveConverterMethod "setDataFull" o = GObject.Object.ObjectSetDataFullMethodInfo
    ResolveConverterMethod "setProperty" o = GObject.Object.ObjectSetPropertyMethodInfo
    ResolveConverterMethod l o = O.MethodResolutionFailed l o

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

#endif

-- method Converter::convert
-- method type : OrdinaryMethod
-- Args: [ Arg
--           { argCName = "converter"
--           , argType =
--               TInterface Name { namespace = "Gio" , name = "Converter" }
--           , direction = DirectionIn
--           , mayBeNull = False
--           , argDoc =
--               Documentation
--                 { rawDocText = Just "a #GConverter." , sinceVersion = Nothing }
--           , argScope = ScopeTypeInvalid
--           , argClosure = -1
--           , argDestroy = -1
--           , argCallerAllocates = False
--           , transfer = TransferNothing
--           }
--       , Arg
--           { argCName = "inbuf"
--           , argType = TCArray False (-1) 2 (TBasicType TUInt8)
--           , direction = DirectionIn
--           , mayBeNull = True
--           , argDoc =
--               Documentation
--                 { rawDocText =
--                     Just "the buffer\n        containing the data to convert."
--                 , sinceVersion = Nothing
--                 }
--           , argScope = ScopeTypeInvalid
--           , argClosure = -1
--           , argDestroy = -1
--           , argCallerAllocates = False
--           , transfer = TransferNothing
--           }
--       , Arg
--           { argCName = "inbuf_size"
--           , argType = TBasicType TUInt64
--           , direction = DirectionIn
--           , mayBeNull = False
--           , argDoc =
--               Documentation
--                 { rawDocText = Just "the number of bytes in @inbuf"
--                 , sinceVersion = Nothing
--                 }
--           , argScope = ScopeTypeInvalid
--           , argClosure = -1
--           , argDestroy = -1
--           , argCallerAllocates = False
--           , transfer = TransferNothing
--           }
--       , Arg
--           { argCName = "outbuf"
--           , argType = TCArray False (-1) 4 (TBasicType TUInt8)
--           , direction = DirectionIn
--           , mayBeNull = True
--           , argDoc =
--               Documentation
--                 { rawDocText = Just "a buffer to write\n   converted data in."
--                 , sinceVersion = Nothing
--                 }
--           , argScope = ScopeTypeInvalid
--           , argClosure = -1
--           , argDestroy = -1
--           , argCallerAllocates = False
--           , transfer = TransferNothing
--           }
--       , Arg
--           { argCName = "outbuf_size"
--           , argType = TBasicType TUInt64
--           , direction = DirectionIn
--           , mayBeNull = False
--           , argDoc =
--               Documentation
--                 { rawDocText =
--                     Just "the number of bytes in @outbuf, must be at least one"
--                 , sinceVersion = Nothing
--                 }
--           , argScope = ScopeTypeInvalid
--           , argClosure = -1
--           , argDestroy = -1
--           , argCallerAllocates = False
--           , transfer = TransferNothing
--           }
--       , Arg
--           { argCName = "flags"
--           , argType =
--               TInterface Name { namespace = "Gio" , name = "ConverterFlags" }
--           , direction = DirectionIn
--           , mayBeNull = False
--           , argDoc =
--               Documentation
--                 { rawDocText =
--                     Just "a #GConverterFlags controlling the conversion details"
--                 , sinceVersion = Nothing
--                 }
--           , argScope = ScopeTypeInvalid
--           , argClosure = -1
--           , argDestroy = -1
--           , argCallerAllocates = False
--           , transfer = TransferNothing
--           }
--       , Arg
--           { argCName = "bytes_read"
--           , argType = TBasicType TUInt64
--           , direction = DirectionOut
--           , mayBeNull = False
--           , argDoc =
--               Documentation
--                 { rawDocText =
--                     Just
--                       "will be set to the number of bytes read from @inbuf on success"
--                 , sinceVersion = Nothing
--                 }
--           , argScope = ScopeTypeInvalid
--           , argClosure = -1
--           , argDestroy = -1
--           , argCallerAllocates = False
--           , transfer = TransferEverything
--           }
--       , Arg
--           { argCName = "bytes_written"
--           , argType = TBasicType TUInt64
--           , direction = DirectionOut
--           , mayBeNull = False
--           , argDoc =
--               Documentation
--                 { rawDocText =
--                     Just
--                       "will be set to the number of bytes written to @outbuf on success"
--                 , sinceVersion = Nothing
--                 }
--           , argScope = ScopeTypeInvalid
--           , argClosure = -1
--           , argDestroy = -1
--           , argCallerAllocates = False
--           , transfer = TransferEverything
--           }
--       ]
-- Lengths: [ Arg
--              { argCName = "outbuf_size"
--              , argType = TBasicType TUInt64
--              , direction = DirectionIn
--              , mayBeNull = False
--              , argDoc =
--                  Documentation
--                    { rawDocText =
--                        Just "the number of bytes in @outbuf, must be at least one"
--                    , sinceVersion = Nothing
--                    }
--              , argScope = ScopeTypeInvalid
--              , argClosure = -1
--              , argDestroy = -1
--              , argCallerAllocates = False
--              , transfer = TransferNothing
--              }
--          , Arg
--              { argCName = "inbuf_size"
--              , argType = TBasicType TUInt64
--              , direction = DirectionIn
--              , mayBeNull = False
--              , argDoc =
--                  Documentation
--                    { rawDocText = Just "the number of bytes in @inbuf"
--                    , sinceVersion = Nothing
--                    }
--              , argScope = ScopeTypeInvalid
--              , argClosure = -1
--              , argDestroy = -1
--              , argCallerAllocates = False
--              , transfer = TransferNothing
--              }
--          ]
-- returnType: Just
--               (TInterface Name { namespace = "Gio" , name = "ConverterResult" })
-- throws : True
-- Skip return : False

foreign import ccall "g_converter_convert" g_converter_convert :: 
    Ptr Converter ->                        -- converter : TInterface (Name {namespace = "Gio", name = "Converter"})
    Ptr Word8 ->                            -- inbuf : TCArray False (-1) 2 (TBasicType TUInt8)
    Word64 ->                               -- inbuf_size : TBasicType TUInt64
    Ptr Word8 ->                            -- outbuf : TCArray False (-1) 4 (TBasicType TUInt8)
    Word64 ->                               -- outbuf_size : TBasicType TUInt64
    CUInt ->                                -- flags : TInterface (Name {namespace = "Gio", name = "ConverterFlags"})
    Ptr Word64 ->                           -- bytes_read : TBasicType TUInt64
    Ptr Word64 ->                           -- bytes_written : TBasicType TUInt64
    Ptr (Ptr GError) ->                     -- error
    IO CUInt

-- | This is the main operation used when converting data. It is to be called
-- multiple times in a loop, and each time it will do some work, i.e.
-- producing some output (in /@outbuf@/) or consuming some input (from /@inbuf@/) or
-- both. If its not possible to do any work an error is returned.
-- 
-- Note that a single call may not consume all input (or any input at all).
-- Also a call may produce output even if given no input, due to state stored
-- in the converter producing output.
-- 
-- If any data was either produced or consumed, and then an error happens, then
-- only the successful conversion is reported and the error is returned on the
-- next call.
-- 
-- A full conversion loop involves calling this method repeatedly, each time
-- giving it new input and space output space. When there is no more input
-- data after the data in /@inbuf@/, the flag 'GI.Gio.Flags.ConverterFlagsInputAtEnd' must be set.
-- The loop will be (unless some error happens) returning 'GI.Gio.Enums.ConverterResultConverted'
-- each time until all data is consumed and all output is produced, then
-- 'GI.Gio.Enums.ConverterResultFinished' is returned instead. Note, that 'GI.Gio.Enums.ConverterResultFinished'
-- may be returned even if 'GI.Gio.Flags.ConverterFlagsInputAtEnd' is not set, for instance
-- in a decompression converter where the end of data is detectable from the
-- data (and there might even be other data after the end of the compressed data).
-- 
-- When some data has successfully been converted /@bytesRead@/ and is set to
-- the number of bytes read from /@inbuf@/, and /@bytesWritten@/ is set to indicate
-- how many bytes was written to /@outbuf@/. If there are more data to output
-- or consume (i.e. unless the 'GI.Gio.Flags.ConverterFlagsInputAtEnd' is specified) then
-- 'GI.Gio.Enums.ConverterResultConverted' is returned, and if no more data is to be output
-- then 'GI.Gio.Enums.ConverterResultFinished' is returned.
-- 
-- On error 'GI.Gio.Enums.ConverterResultError' is returned and /@error@/ is set accordingly.
-- Some errors need special handling:
-- 
-- 'GI.Gio.Enums.IOErrorEnumNoSpace' is returned if there is not enough space
-- to write the resulting converted data, the application should
-- call the function again with a larger /@outbuf@/ to continue.
-- 
-- 'GI.Gio.Enums.IOErrorEnumPartialInput' is returned if there is not enough
-- input to fully determine what the conversion should produce,
-- and the 'GI.Gio.Flags.ConverterFlagsInputAtEnd' flag is not set. This happens for
-- example with an incomplete multibyte sequence when converting text,
-- or when a regexp matches up to the end of the input (and may match
-- further input). It may also happen when /@inbufSize@/ is zero and
-- there is no more data to produce.
-- 
-- When this happens the application should read more input and then
-- call the function again. If further input shows that there is no
-- more data call the function again with the same data but with
-- the 'GI.Gio.Flags.ConverterFlagsInputAtEnd' flag set. This may cause the conversion
-- to finish as e.g. in the regexp match case (or, to fail again with
-- 'GI.Gio.Enums.IOErrorEnumPartialInput' in e.g. a charset conversion where the
-- input is actually partial).
-- 
-- After 'GI.Gio.Interfaces.Converter.converterConvert' has returned 'GI.Gio.Enums.ConverterResultFinished' the
-- converter object is in an invalid state where its not allowed
-- to call 'GI.Gio.Interfaces.Converter.converterConvert' anymore. At this time you can only
-- free the object or call 'GI.Gio.Interfaces.Converter.converterReset' to reset it to the
-- initial state.
-- 
-- If the flag 'GI.Gio.Flags.ConverterFlagsFlush' is set then conversion is modified
-- to try to write out all internal state to the output. The application
-- has to call the function multiple times with the flag set, and when
-- the available input has been consumed and all internal state has
-- been produced then 'GI.Gio.Enums.ConverterResultFlushed' (or 'GI.Gio.Enums.ConverterResultFinished' if
-- really at the end) is returned instead of 'GI.Gio.Enums.ConverterResultConverted'.
-- This is somewhat similar to what happens at the end of the input stream,
-- but done in the middle of the data.
-- 
-- This has different meanings for different conversions. For instance
-- in a compression converter it would mean that we flush all the
-- compression state into output such that if you uncompress the
-- compressed data you get back all the input data. Doing this may
-- make the final file larger due to padding though. Another example
-- is a regexp conversion, where if you at the end of the flushed data
-- have a match, but there is also a potential longer match. In the
-- non-flushed case we would ask for more input, but when flushing we
-- treat this as the end of input and do the match.
-- 
-- Flushing is not always possible (like if a charset converter flushes
-- at a partial multibyte sequence). Converters are supposed to try
-- to produce as much output as possible and then return an error
-- (typically 'GI.Gio.Enums.IOErrorEnumPartialInput').
-- 
-- /Since: 2.24/
converterConvert ::
    (B.CallStack.HasCallStack, MonadIO m, IsConverter a) =>
    a
    -- ^ /@converter@/: a t'GI.Gio.Interfaces.Converter.Converter'.
    -> Maybe (ByteString)
    -- ^ /@inbuf@/: the buffer
    --         containing the data to convert.
    -> Maybe (ByteString)
    -- ^ /@outbuf@/: a buffer to write
    --    converted data in.
    -> [Gio.Flags.ConverterFlags]
    -- ^ /@flags@/: a t'GI.Gio.Flags.ConverterFlags' controlling the conversion details
    -> m ((Gio.Enums.ConverterResult, Word64, Word64))
    -- ^ __Returns:__ a t'GI.Gio.Enums.ConverterResult', 'GI.Gio.Enums.ConverterResultError' on error. /(Can throw 'Data.GI.Base.GError.GError')/
converterConvert :: a
-> Maybe ByteString
-> Maybe ByteString
-> [ConverterFlags]
-> m (ConverterResult, Word64, Word64)
converterConvert converter :: a
converter inbuf :: Maybe ByteString
inbuf outbuf :: Maybe ByteString
outbuf flags :: [ConverterFlags]
flags = IO (ConverterResult, Word64, Word64)
-> m (ConverterResult, Word64, Word64)
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO (ConverterResult, Word64, Word64)
 -> m (ConverterResult, Word64, Word64))
-> IO (ConverterResult, Word64, Word64)
-> m (ConverterResult, Word64, Word64)
forall a b. (a -> b) -> a -> b
$ do
    let outbufSize :: Word64
outbufSize = case Maybe ByteString
outbuf of
            Nothing -> 0
            Just jOutbuf :: ByteString
jOutbuf -> Int -> Word64
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Int -> Word64) -> Int -> Word64
forall a b. (a -> b) -> a -> b
$ ByteString -> Int
B.length ByteString
jOutbuf
    let inbufSize :: Word64
inbufSize = case Maybe ByteString
inbuf of
            Nothing -> 0
            Just jInbuf :: ByteString
jInbuf -> Int -> Word64
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Int -> Word64) -> Int -> Word64
forall a b. (a -> b) -> a -> b
$ ByteString -> Int
B.length ByteString
jInbuf
    Ptr Converter
converter' <- a -> IO (Ptr Converter)
forall a b. (HasCallStack, ManagedPtrNewtype a) => a -> IO (Ptr b)
unsafeManagedPtrCastPtr a
converter
    Ptr Word8
maybeInbuf <- case Maybe ByteString
inbuf of
        Nothing -> Ptr Word8 -> IO (Ptr Word8)
forall (m :: * -> *) a. Monad m => a -> m a
return Ptr Word8
forall a. Ptr a
nullPtr
        Just jInbuf :: ByteString
jInbuf -> do
            Ptr Word8
jInbuf' <- ByteString -> IO (Ptr Word8)
packByteString ByteString
jInbuf
            Ptr Word8 -> IO (Ptr Word8)
forall (m :: * -> *) a. Monad m => a -> m a
return Ptr Word8
jInbuf'
    Ptr Word8
maybeOutbuf <- case Maybe ByteString
outbuf of
        Nothing -> Ptr Word8 -> IO (Ptr Word8)
forall (m :: * -> *) a. Monad m => a -> m a
return Ptr Word8
forall a. Ptr a
nullPtr
        Just jOutbuf :: ByteString
jOutbuf -> do
            Ptr Word8
jOutbuf' <- ByteString -> IO (Ptr Word8)
packByteString ByteString
jOutbuf
            Ptr Word8 -> IO (Ptr Word8)
forall (m :: * -> *) a. Monad m => a -> m a
return Ptr Word8
jOutbuf'
    let flags' :: CUInt
flags' = [ConverterFlags] -> CUInt
forall b a. (Num b, IsGFlag a) => [a] -> b
gflagsToWord [ConverterFlags]
flags
    Ptr Word64
bytesRead <- IO (Ptr Word64)
forall a. Storable a => IO (Ptr a)
allocMem :: IO (Ptr Word64)
    Ptr Word64
bytesWritten <- IO (Ptr Word64)
forall a. Storable a => IO (Ptr a)
allocMem :: IO (Ptr Word64)
    IO (ConverterResult, Word64, Word64)
-> IO () -> IO (ConverterResult, Word64, Word64)
forall a b. IO a -> IO b -> IO a
onException (do
        CUInt
result <- (Ptr (Ptr GError) -> IO CUInt) -> IO CUInt
forall a. (Ptr (Ptr GError) -> IO a) -> IO a
propagateGError ((Ptr (Ptr GError) -> IO CUInt) -> IO CUInt)
-> (Ptr (Ptr GError) -> IO CUInt) -> IO CUInt
forall a b. (a -> b) -> a -> b
$ Ptr Converter
-> Ptr Word8
-> Word64
-> Ptr Word8
-> Word64
-> CUInt
-> Ptr Word64
-> Ptr Word64
-> Ptr (Ptr GError)
-> IO CUInt
g_converter_convert Ptr Converter
converter' Ptr Word8
maybeInbuf Word64
inbufSize Ptr Word8
maybeOutbuf Word64
outbufSize CUInt
flags' Ptr Word64
bytesRead Ptr Word64
bytesWritten
        let result' :: ConverterResult
result' = (Int -> ConverterResult
forall a. Enum a => Int -> a
toEnum (Int -> ConverterResult)
-> (CUInt -> Int) -> CUInt -> ConverterResult
forall b c a. (b -> c) -> (a -> b) -> a -> c
. CUInt -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral) CUInt
result
        Word64
bytesRead' <- Ptr Word64 -> IO Word64
forall a. Storable a => Ptr a -> IO a
peek Ptr Word64
bytesRead
        Word64
bytesWritten' <- Ptr Word64 -> IO Word64
forall a. Storable a => Ptr a -> IO a
peek Ptr Word64
bytesWritten
        a -> IO ()
forall a. ManagedPtrNewtype a => a -> IO ()
touchManagedPtr a
converter
        Ptr Word8 -> IO ()
forall a. Ptr a -> IO ()
freeMem Ptr Word8
maybeInbuf
        Ptr Word8 -> IO ()
forall a. Ptr a -> IO ()
freeMem Ptr Word8
maybeOutbuf
        Ptr Word64 -> IO ()
forall a. Ptr a -> IO ()
freeMem Ptr Word64
bytesRead
        Ptr Word64 -> IO ()
forall a. Ptr a -> IO ()
freeMem Ptr Word64
bytesWritten
        (ConverterResult, Word64, Word64)
-> IO (ConverterResult, Word64, Word64)
forall (m :: * -> *) a. Monad m => a -> m a
return (ConverterResult
result', Word64
bytesRead', Word64
bytesWritten')
     ) (do
        Ptr Word8 -> IO ()
forall a. Ptr a -> IO ()
freeMem Ptr Word8
maybeInbuf
        Ptr Word8 -> IO ()
forall a. Ptr a -> IO ()
freeMem Ptr Word8
maybeOutbuf
        Ptr Word64 -> IO ()
forall a. Ptr a -> IO ()
freeMem Ptr Word64
bytesRead
        Ptr Word64 -> IO ()
forall a. Ptr a -> IO ()
freeMem Ptr Word64
bytesWritten
     )

#if defined(ENABLE_OVERLOADING)
data ConverterConvertMethodInfo
instance (signature ~ (Maybe (ByteString) -> Maybe (ByteString) -> [Gio.Flags.ConverterFlags] -> m ((Gio.Enums.ConverterResult, Word64, Word64))), MonadIO m, IsConverter a) => O.MethodInfo ConverterConvertMethodInfo a signature where
    overloadedMethod = converterConvert

#endif

-- method Converter::reset
-- method type : OrdinaryMethod
-- Args: [ Arg
--           { argCName = "converter"
--           , argType =
--               TInterface Name { namespace = "Gio" , name = "Converter" }
--           , direction = DirectionIn
--           , mayBeNull = False
--           , argDoc =
--               Documentation
--                 { rawDocText = Just "a #GConverter." , sinceVersion = Nothing }
--           , argScope = ScopeTypeInvalid
--           , argClosure = -1
--           , argDestroy = -1
--           , argCallerAllocates = False
--           , transfer = TransferNothing
--           }
--       ]
-- Lengths: []
-- returnType: Nothing
-- throws : False
-- Skip return : False

foreign import ccall "g_converter_reset" g_converter_reset :: 
    Ptr Converter ->                        -- converter : TInterface (Name {namespace = "Gio", name = "Converter"})
    IO ()

-- | Resets all internal state in the converter, making it behave
-- as if it was just created. If the converter has any internal
-- state that would produce output then that output is lost.
-- 
-- /Since: 2.24/
converterReset ::
    (B.CallStack.HasCallStack, MonadIO m, IsConverter a) =>
    a
    -- ^ /@converter@/: a t'GI.Gio.Interfaces.Converter.Converter'.
    -> m ()
converterReset :: a -> m ()
converterReset converter :: a
converter = 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 Converter
converter' <- a -> IO (Ptr Converter)
forall a b. (HasCallStack, ManagedPtrNewtype a) => a -> IO (Ptr b)
unsafeManagedPtrCastPtr a
converter
    Ptr Converter -> IO ()
g_converter_reset Ptr Converter
converter'
    a -> IO ()
forall a. ManagedPtrNewtype a => a -> IO ()
touchManagedPtr a
converter
    () -> IO ()
forall (m :: * -> *) a. Monad m => a -> m a
return ()

#if defined(ENABLE_OVERLOADING)
data ConverterResetMethodInfo
instance (signature ~ (m ()), MonadIO m, IsConverter a) => O.MethodInfo ConverterResetMethodInfo a signature where
    overloadedMethod = converterReset

#endif