-- | Copyright  : Will Thompson and Iñaki García Etxebarria
-- License    : LGPL-2.1
-- Maintainer : Iñaki García Etxebarria

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

module GI.Json.Functions
    ( 

 -- * Methods


-- ** boxedCanDeserialize #method:boxedCanDeserialize#

    boxedCanDeserialize                     ,


-- ** boxedCanSerialize #method:boxedCanSerialize#

    boxedCanSerialize                       ,


-- ** boxedDeserialize #method:boxedDeserialize#

    boxedDeserialize                        ,


-- ** boxedSerialize #method:boxedSerialize#

    boxedSerialize                          ,


-- ** constructGobject #method:constructGobject#

    constructGobject                        ,


-- ** fromString #method:fromString#

    fromString                              ,


-- ** gobjectDeserialize #method:gobjectDeserialize#

    gobjectDeserialize                      ,


-- ** gobjectFromData #method:gobjectFromData#

    gobjectFromData                         ,


-- ** gobjectSerialize #method:gobjectSerialize#

    gobjectSerialize                        ,


-- ** gobjectToData #method:gobjectToData#

    gobjectToData                           ,


-- ** gvariantDeserialize #method:gvariantDeserialize#

    gvariantDeserialize                     ,


-- ** gvariantDeserializeData #method:gvariantDeserializeData#

    gvariantDeserializeData                 ,


-- ** gvariantSerialize #method:gvariantSerialize#

    gvariantSerialize                       ,


-- ** gvariantSerializeData #method:gvariantSerializeData#

    gvariantSerializeData                   ,


-- ** serializeGobject #method:serializeGobject#

    serializeGobject                        ,


-- ** stringCompare #method:stringCompare#

    stringCompare                           ,


-- ** stringEqual #method:stringEqual#

    stringEqual                             ,


-- ** stringHash #method:stringHash#

    stringHash                              ,


-- ** toString #method:toString#

    toString                                ,




    ) 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.GArray as B.GArray
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.Coerce as Coerce
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 GHC.Records as R

import qualified GI.GObject.Objects.Object as GObject.Object
import {-# SOURCE #-} qualified GI.Json.Enums as Json.Enums
import {-# SOURCE #-} qualified GI.Json.Structs.Node as Json.Node

-- function to_string
-- Args: [ Arg
--           { argCName = "node"
--           , argType = TInterface Name { namespace = "Json" , name = "Node" }
--           , direction = DirectionIn
--           , mayBeNull = False
--           , argDoc =
--               Documentation
--                 { rawDocText = Just "a JSON tree" , sinceVersion = Nothing }
--           , argScope = ScopeTypeInvalid
--           , argClosure = -1
--           , argDestroy = -1
--           , argCallerAllocates = False
--           , transfer = TransferNothing
--           }
--       , Arg
--           { argCName = "pretty"
--           , argType = TBasicType TBoolean
--           , direction = DirectionIn
--           , mayBeNull = False
--           , argDoc =
--               Documentation
--                 { rawDocText =
--                     Just "whether the output should be prettyfied for printing"
--                 , sinceVersion = Nothing
--                 }
--           , argScope = ScopeTypeInvalid
--           , argClosure = -1
--           , argDestroy = -1
--           , argCallerAllocates = False
--           , transfer = TransferNothing
--           }
--       ]
-- Lengths: []
-- returnType: Just (TBasicType TUTF8)
-- throws : False
-- Skip return : False

foreign import ccall "json_to_string" json_to_string :: 
    Ptr Json.Node.Node ->                   -- node : TInterface (Name {namespace = "Json", name = "Node"})
    CInt ->                                 -- pretty : TBasicType TBoolean
    IO CString

-- | Generates a stringified JSON representation of the contents of
-- the given @node@.
-- 
-- /Since: 1.2/
toString ::
    (B.CallStack.HasCallStack, MonadIO m) =>
    Json.Node.Node
    -- ^ /@node@/: a JSON tree
    -> Bool
    -- ^ /@pretty@/: whether the output should be prettyfied for printing
    -> m T.Text
    -- ^ __Returns:__ the string representation of the node
toString :: forall (m :: * -> *).
(HasCallStack, MonadIO m) =>
Node -> Bool -> m Text
toString Node
node Bool
pretty = IO Text -> m Text
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO Text -> m Text) -> IO Text -> m Text
forall a b. (a -> b) -> a -> b
$ do
    Ptr Node
node' <- Node -> IO (Ptr Node)
forall a. (HasCallStack, ManagedPtrNewtype a) => a -> IO (Ptr a)
unsafeManagedPtrGetPtr Node
node
    let pretty' :: CInt
pretty' = (Int -> CInt
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Int -> CInt) -> (Bool -> Int) -> Bool -> CInt
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Bool -> Int
forall a. Enum a => a -> Int
fromEnum) Bool
pretty
    CString
result <- Ptr Node -> CInt -> IO CString
json_to_string Ptr Node
node' CInt
pretty'
    Text -> CString -> IO ()
forall a. HasCallStack => Text -> Ptr a -> IO ()
checkUnexpectedReturnNULL Text
"toString" CString
result
    Text
result' <- HasCallStack => CString -> IO Text
CString -> IO Text
cstringToText CString
result
    CString -> IO ()
forall a. Ptr a -> IO ()
freeMem CString
result
    Node -> IO ()
forall a. ManagedPtrNewtype a => a -> IO ()
touchManagedPtr Node
node
    Text -> IO Text
forall (m :: * -> *) a. Monad m => a -> m a
return Text
result'


-- function string_hash
-- Args: [ Arg
--           { argCName = "key"
--           , argType = TBasicType TUTF8
--           , direction = DirectionIn
--           , mayBeNull = False
--           , argDoc =
--               Documentation
--                 { rawDocText = Just "a JSON string to hash"
--                 , sinceVersion = Nothing
--                 }
--           , argScope = ScopeTypeInvalid
--           , argClosure = -1
--           , argDestroy = -1
--           , argCallerAllocates = False
--           , transfer = TransferNothing
--           }
--       ]
-- Lengths: []
-- returnType: Just (TBasicType TUInt)
-- throws : False
-- Skip return : False

foreign import ccall "json_string_hash" json_string_hash :: 
    CString ->                              -- key : TBasicType TUTF8
    IO Word32

-- | Calculate a hash value for the given /@key@/ (a UTF-8 JSON string).
-- 
-- Note: Member names are compared byte-wise, without applying any Unicode
-- decomposition or normalisation. This is not explicitly mentioned in the JSON
-- standard (ECMA-404), but is assumed.
-- 
-- /Since: 1.2/
stringHash ::
    (B.CallStack.HasCallStack, MonadIO m) =>
    T.Text
    -- ^ /@key@/: a JSON string to hash
    -> m Word32
    -- ^ __Returns:__ hash value for /@key@/
stringHash :: forall (m :: * -> *). (HasCallStack, MonadIO m) => Text -> m Word32
stringHash Text
key = IO Word32 -> m Word32
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO Word32 -> m Word32) -> IO Word32 -> m Word32
forall a b. (a -> b) -> a -> b
$ do
    CString
key' <- Text -> IO CString
textToCString Text
key
    Word32
result <- CString -> IO Word32
json_string_hash CString
key'
    CString -> IO ()
forall a. Ptr a -> IO ()
freeMem CString
key'
    Word32 -> IO Word32
forall (m :: * -> *) a. Monad m => a -> m a
return Word32
result


-- function string_equal
-- Args: [ Arg
--           { argCName = "a"
--           , argType = TBasicType TUTF8
--           , direction = DirectionIn
--           , mayBeNull = False
--           , argDoc =
--               Documentation
--                 { rawDocText = Just "a JSON string" , sinceVersion = Nothing }
--           , argScope = ScopeTypeInvalid
--           , argClosure = -1
--           , argDestroy = -1
--           , argCallerAllocates = False
--           , transfer = TransferNothing
--           }
--       , Arg
--           { argCName = "b"
--           , argType = TBasicType TUTF8
--           , direction = DirectionIn
--           , mayBeNull = False
--           , argDoc =
--               Documentation
--                 { rawDocText = Just "another JSON string"
--                 , sinceVersion = Nothing
--                 }
--           , argScope = ScopeTypeInvalid
--           , argClosure = -1
--           , argDestroy = -1
--           , argCallerAllocates = False
--           , transfer = TransferNothing
--           }
--       ]
-- Lengths: []
-- returnType: Just (TBasicType TBoolean)
-- throws : False
-- Skip return : False

foreign import ccall "json_string_equal" json_string_equal :: 
    CString ->                              -- a : TBasicType TUTF8
    CString ->                              -- b : TBasicType TUTF8
    IO CInt

-- | Check whether /@a@/ and /@b@/ are equal UTF-8 JSON strings.
-- 
-- /Since: 1.2/
stringEqual ::
    (B.CallStack.HasCallStack, MonadIO m) =>
    T.Text
    -- ^ /@a@/: a JSON string
    -> T.Text
    -- ^ /@b@/: another JSON string
    -> m Bool
    -- ^ __Returns:__ @TRUE@ if /@a@/ and /@b@/ are equal; @FALSE@ otherwise
stringEqual :: forall (m :: * -> *).
(HasCallStack, MonadIO m) =>
Text -> Text -> m Bool
stringEqual Text
a Text
b = IO Bool -> m Bool
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO Bool -> m Bool) -> IO Bool -> m Bool
forall a b. (a -> b) -> a -> b
$ do
    CString
a' <- Text -> IO CString
textToCString Text
a
    CString
b' <- Text -> IO CString
textToCString Text
b
    CInt
result <- CString -> CString -> IO CInt
json_string_equal CString
a' CString
b'
    let result' :: Bool
result' = (CInt -> CInt -> Bool
forall a. Eq a => a -> a -> Bool
/= CInt
0) CInt
result
    CString -> IO ()
forall a. Ptr a -> IO ()
freeMem CString
a'
    CString -> IO ()
forall a. Ptr a -> IO ()
freeMem CString
b'
    Bool -> IO Bool
forall (m :: * -> *) a. Monad m => a -> m a
return Bool
result'


-- function string_compare
-- Args: [ Arg
--           { argCName = "a"
--           , argType = TBasicType TUTF8
--           , direction = DirectionIn
--           , mayBeNull = False
--           , argDoc =
--               Documentation
--                 { rawDocText = Just "a JSON string" , sinceVersion = Nothing }
--           , argScope = ScopeTypeInvalid
--           , argClosure = -1
--           , argDestroy = -1
--           , argCallerAllocates = False
--           , transfer = TransferNothing
--           }
--       , Arg
--           { argCName = "b"
--           , argType = TBasicType TUTF8
--           , direction = DirectionIn
--           , mayBeNull = False
--           , argDoc =
--               Documentation
--                 { rawDocText = Just "another JSON string"
--                 , sinceVersion = Nothing
--                 }
--           , argScope = ScopeTypeInvalid
--           , argClosure = -1
--           , argDestroy = -1
--           , argCallerAllocates = False
--           , transfer = TransferNothing
--           }
--       ]
-- Lengths: []
-- returnType: Just (TBasicType TInt)
-- throws : False
-- Skip return : False

foreign import ccall "json_string_compare" json_string_compare :: 
    CString ->                              -- a : TBasicType TUTF8
    CString ->                              -- b : TBasicType TUTF8
    IO Int32

-- | Check whether /@a@/ and /@b@/ are equal UTF-8 JSON strings and return an ordering
-- over them in @strcmp()@ style.
-- 
-- /Since: 1.2/
stringCompare ::
    (B.CallStack.HasCallStack, MonadIO m) =>
    T.Text
    -- ^ /@a@/: a JSON string
    -> T.Text
    -- ^ /@b@/: another JSON string
    -> m Int32
    -- ^ __Returns:__ an integer less than zero if @a \< b@, equal to zero if @a == b@, and
    --   greater than zero if @a > b@
stringCompare :: forall (m :: * -> *).
(HasCallStack, MonadIO m) =>
Text -> Text -> m Int32
stringCompare Text
a Text
b = IO Int32 -> m Int32
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO Int32 -> m Int32) -> IO Int32 -> m Int32
forall a b. (a -> b) -> a -> b
$ do
    CString
a' <- Text -> IO CString
textToCString Text
a
    CString
b' <- Text -> IO CString
textToCString Text
b
    Int32
result <- CString -> CString -> IO Int32
json_string_compare CString
a' CString
b'
    CString -> IO ()
forall a. Ptr a -> IO ()
freeMem CString
a'
    CString -> IO ()
forall a. Ptr a -> IO ()
freeMem CString
b'
    Int32 -> IO Int32
forall (m :: * -> *) a. Monad m => a -> m a
return Int32
result


-- function serialize_gobject
-- Args: [ Arg
--           { argCName = "gobject"
--           , argType =
--               TInterface Name { namespace = "GObject" , name = "Object" }
--           , direction = DirectionIn
--           , mayBeNull = False
--           , argDoc =
--               Documentation
--                 { rawDocText = Just "the object to serialize"
--                 , sinceVersion = Nothing
--                 }
--           , argScope = ScopeTypeInvalid
--           , argClosure = -1
--           , argDestroy = -1
--           , argCallerAllocates = False
--           , transfer = TransferNothing
--           }
--       , Arg
--           { argCName = "length"
--           , argType = TBasicType TUInt64
--           , direction = DirectionOut
--           , mayBeNull = False
--           , argDoc =
--               Documentation
--                 { rawDocText = Just "return value for the length of the buffer"
--                 , sinceVersion = Nothing
--                 }
--           , argScope = ScopeTypeInvalid
--           , argClosure = -1
--           , argDestroy = -1
--           , argCallerAllocates = False
--           , transfer = TransferEverything
--           }
--       ]
-- Lengths: []
-- returnType: Just (TBasicType TUTF8)
-- throws : False
-- Skip return : False

foreign import ccall "json_serialize_gobject" json_serialize_gobject :: 
    Ptr GObject.Object.Object ->            -- gobject : TInterface (Name {namespace = "GObject", name = "Object"})
    Ptr Word64 ->                           -- length : TBasicType TUInt64
    IO CString

{-# DEPRECATED serializeGobject ["(Since version 0.10)","Use [func/@json@/.gobject_to_data] instead"] #-}
-- | Serializes a @GObject@ instance into a JSON data stream.
-- 
-- If the object implements the [iface/@json@/.Serializable] interface, it will be
-- asked to serizalize all its properties; otherwise, the default
-- implementation will be use to translate the compatible types into JSON
-- native types.
serializeGobject ::
    (B.CallStack.HasCallStack, MonadIO m, GObject.Object.IsObject a) =>
    a
    -- ^ /@gobject@/: the object to serialize
    -> m ((T.Text, Word64))
    -- ^ __Returns:__ a JSON data stream representing the given object
serializeGobject :: forall (m :: * -> *) a.
(HasCallStack, MonadIO m, IsObject a) =>
a -> m (Text, Word64)
serializeGobject a
gobject = IO (Text, Word64) -> m (Text, Word64)
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO (Text, Word64) -> m (Text, Word64))
-> IO (Text, Word64) -> m (Text, Word64)
forall a b. (a -> b) -> a -> b
$ do
    Ptr Object
gobject' <- a -> IO (Ptr Object)
forall a b. (HasCallStack, ManagedPtrNewtype a) => a -> IO (Ptr b)
unsafeManagedPtrCastPtr a
gobject
    Ptr Word64
length_ <- IO (Ptr Word64)
forall a. Storable a => IO (Ptr a)
allocMem :: IO (Ptr Word64)
    CString
result <- Ptr Object -> Ptr Word64 -> IO CString
json_serialize_gobject Ptr Object
gobject' Ptr Word64
length_
    Text -> CString -> IO ()
forall a. HasCallStack => Text -> Ptr a -> IO ()
checkUnexpectedReturnNULL Text
"serializeGobject" CString
result
    Text
result' <- HasCallStack => CString -> IO Text
CString -> IO Text
cstringToText CString
result
    CString -> IO ()
forall a. Ptr a -> IO ()
freeMem CString
result
    Word64
length_' <- Ptr Word64 -> IO Word64
forall a. Storable a => Ptr a -> IO a
peek Ptr Word64
length_
    a -> IO ()
forall a. ManagedPtrNewtype a => a -> IO ()
touchManagedPtr a
gobject
    Ptr Word64 -> IO ()
forall a. Ptr a -> IO ()
freeMem Ptr Word64
length_
    (Text, Word64) -> IO (Text, Word64)
forall (m :: * -> *) a. Monad m => a -> m a
return (Text
result', Word64
length_')


-- function gvariant_serialize_data
-- Args: [ Arg
--           { argCName = "variant"
--           , argType = TVariant
--           , direction = DirectionIn
--           , mayBeNull = False
--           , argDoc =
--               Documentation
--                 { rawDocText = Just "A #GVariant to convert"
--                 , sinceVersion = Nothing
--                 }
--           , argScope = ScopeTypeInvalid
--           , argClosure = -1
--           , argDestroy = -1
--           , argCallerAllocates = False
--           , transfer = TransferNothing
--           }
--       , Arg
--           { argCName = "length"
--           , argType = TBasicType TUInt64
--           , direction = DirectionOut
--           , mayBeNull = False
--           , argDoc =
--               Documentation
--                 { rawDocText = Just "the length of the returned string"
--                 , sinceVersion = Nothing
--                 }
--           , argScope = ScopeTypeInvalid
--           , argClosure = -1
--           , argDestroy = -1
--           , argCallerAllocates = False
--           , transfer = TransferEverything
--           }
--       ]
-- Lengths: []
-- returnType: Just (TBasicType TUTF8)
-- throws : False
-- Skip return : False

foreign import ccall "json_gvariant_serialize_data" json_gvariant_serialize_data :: 
    Ptr GVariant ->                         -- variant : TVariant
    Ptr Word64 ->                           -- length : TBasicType TUInt64
    IO CString

-- | Converts /@variant@/ to its JSON encoded string representation.
-- 
-- This is a convenience function around [func/@json@/.gvariant_serialize], to
-- obtain the JSON tree, and then [class/@json@/.Generator] to stringify it.
-- 
-- /Since: 0.14/
gvariantSerializeData ::
    (B.CallStack.HasCallStack, MonadIO m) =>
    GVariant
    -- ^ /@variant@/: A t'GVariant' to convert
    -> m ((T.Text, Word64))
    -- ^ __Returns:__ The JSON encoded string corresponding to
    --   the given variant
gvariantSerializeData :: forall (m :: * -> *).
(HasCallStack, MonadIO m) =>
GVariant -> m (Text, Word64)
gvariantSerializeData GVariant
variant = IO (Text, Word64) -> m (Text, Word64)
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO (Text, Word64) -> m (Text, Word64))
-> IO (Text, Word64) -> m (Text, Word64)
forall a b. (a -> b) -> a -> b
$ do
    Ptr GVariant
variant' <- GVariant -> IO (Ptr GVariant)
forall a. (HasCallStack, ManagedPtrNewtype a) => a -> IO (Ptr a)
unsafeManagedPtrGetPtr GVariant
variant
    Ptr Word64
length_ <- IO (Ptr Word64)
forall a. Storable a => IO (Ptr a)
allocMem :: IO (Ptr Word64)
    CString
result <- Ptr GVariant -> Ptr Word64 -> IO CString
json_gvariant_serialize_data Ptr GVariant
variant' Ptr Word64
length_
    Text -> CString -> IO ()
forall a. HasCallStack => Text -> Ptr a -> IO ()
checkUnexpectedReturnNULL Text
"gvariantSerializeData" CString
result
    Text
result' <- HasCallStack => CString -> IO Text
CString -> IO Text
cstringToText CString
result
    CString -> IO ()
forall a. Ptr a -> IO ()
freeMem CString
result
    Word64
length_' <- Ptr Word64 -> IO Word64
forall a. Storable a => Ptr a -> IO a
peek Ptr Word64
length_
    GVariant -> IO ()
forall a. ManagedPtrNewtype a => a -> IO ()
touchManagedPtr GVariant
variant
    Ptr Word64 -> IO ()
forall a. Ptr a -> IO ()
freeMem Ptr Word64
length_
    (Text, Word64) -> IO (Text, Word64)
forall (m :: * -> *) a. Monad m => a -> m a
return (Text
result', Word64
length_')


-- function gvariant_serialize
-- Args: [ Arg
--           { argCName = "variant"
--           , argType = TVariant
--           , direction = DirectionIn
--           , mayBeNull = False
--           , argDoc =
--               Documentation
--                 { rawDocText = Just "A `GVariant` to convert"
--                 , sinceVersion = Nothing
--                 }
--           , argScope = ScopeTypeInvalid
--           , argClosure = -1
--           , argDestroy = -1
--           , argCallerAllocates = False
--           , transfer = TransferNothing
--           }
--       ]
-- Lengths: []
-- returnType: Just (TInterface Name { namespace = "Json" , name = "Node" })
-- throws : False
-- Skip return : False

foreign import ccall "json_gvariant_serialize" json_gvariant_serialize :: 
    Ptr GVariant ->                         -- variant : TVariant
    IO (Ptr Json.Node.Node)

-- | Converts @variant@ to a JSON tree.
-- 
-- /Since: 0.14/
gvariantSerialize ::
    (B.CallStack.HasCallStack, MonadIO m) =>
    GVariant
    -- ^ /@variant@/: A @GVariant@ to convert
    -> m Json.Node.Node
    -- ^ __Returns:__ the root of the JSON data structure
    --   obtained from @variant@
gvariantSerialize :: forall (m :: * -> *).
(HasCallStack, MonadIO m) =>
GVariant -> m Node
gvariantSerialize GVariant
variant = IO Node -> m Node
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO Node -> m Node) -> IO Node -> m Node
forall a b. (a -> b) -> a -> b
$ do
    Ptr GVariant
variant' <- GVariant -> IO (Ptr GVariant)
forall a. (HasCallStack, ManagedPtrNewtype a) => a -> IO (Ptr a)
unsafeManagedPtrGetPtr GVariant
variant
    Ptr Node
result <- Ptr GVariant -> IO (Ptr Node)
json_gvariant_serialize Ptr GVariant
variant'
    Text -> Ptr Node -> IO ()
forall a. HasCallStack => Text -> Ptr a -> IO ()
checkUnexpectedReturnNULL Text
"gvariantSerialize" Ptr Node
result
    Node
result' <- ((ManagedPtr Node -> Node) -> Ptr Node -> IO Node
forall a.
(HasCallStack, GBoxed a) =>
(ManagedPtr a -> a) -> Ptr a -> IO a
wrapBoxed ManagedPtr Node -> Node
Json.Node.Node) Ptr Node
result
    GVariant -> IO ()
forall a. ManagedPtrNewtype a => a -> IO ()
touchManagedPtr GVariant
variant
    Node -> IO Node
forall (m :: * -> *) a. Monad m => a -> m a
return Node
result'


-- function gvariant_deserialize_data
-- Args: [ Arg
--           { argCName = "json"
--           , argType = TBasicType TUTF8
--           , direction = DirectionIn
--           , mayBeNull = False
--           , argDoc =
--               Documentation
--                 { rawDocText = Just "A JSON data string" , sinceVersion = Nothing }
--           , argScope = ScopeTypeInvalid
--           , argClosure = -1
--           , argDestroy = -1
--           , argCallerAllocates = False
--           , transfer = TransferNothing
--           }
--       , Arg
--           { argCName = "length"
--           , argType = TBasicType TInt64
--           , direction = DirectionIn
--           , mayBeNull = False
--           , argDoc =
--               Documentation
--                 { rawDocText =
--                     Just "The length of @json, or -1 if `NUL`-terminated"
--                 , sinceVersion = Nothing
--                 }
--           , argScope = ScopeTypeInvalid
--           , argClosure = -1
--           , argDestroy = -1
--           , argCallerAllocates = False
--           , transfer = TransferNothing
--           }
--       , Arg
--           { argCName = "signature"
--           , argType = TBasicType TUTF8
--           , direction = DirectionIn
--           , mayBeNull = True
--           , argDoc =
--               Documentation
--                 { rawDocText = Just "A valid `GVariant` type string"
--                 , sinceVersion = Nothing
--                 }
--           , argScope = ScopeTypeInvalid
--           , argClosure = -1
--           , argDestroy = -1
--           , argCallerAllocates = False
--           , transfer = TransferNothing
--           }
--       ]
-- Lengths: []
-- returnType: Just TVariant
-- throws : True
-- Skip return : False

foreign import ccall "json_gvariant_deserialize_data" json_gvariant_deserialize_data :: 
    CString ->                              -- json : TBasicType TUTF8
    Int64 ->                                -- length : TBasicType TInt64
    CString ->                              -- signature : TBasicType TUTF8
    Ptr (Ptr GError) ->                     -- error
    IO (Ptr GVariant)

-- | Converts a JSON string to a @GVariant@ value.
-- 
-- This function works exactly like [func/@json@/.gvariant_deserialize], but
-- takes a JSON encoded string instead.
-- 
-- The string is first converted to a [struct/@json@/.Node] using
-- [class/@json@/.Parser], and then @json_gvariant_deserialize@ is called on
-- the node.
-- 
-- The returned variant has a floating reference that will need to be sunk
-- by the caller code.
-- 
-- /Since: 0.14/
gvariantDeserializeData ::
    (B.CallStack.HasCallStack, MonadIO m) =>
    T.Text
    -- ^ /@json@/: A JSON data string
    -> Int64
    -- ^ /@length@/: The length of /@json@/, or -1 if @NUL@-terminated
    -> Maybe (T.Text)
    -- ^ /@signature@/: A valid @GVariant@ type string
    -> m (Maybe GVariant)
    -- ^ __Returns:__ A newly created @GVariant@D compliant /(Can throw 'Data.GI.Base.GError.GError')/
gvariantDeserializeData :: forall (m :: * -> *).
(HasCallStack, MonadIO m) =>
Text -> Int64 -> Maybe Text -> m (Maybe GVariant)
gvariantDeserializeData Text
json Int64
length_ Maybe Text
signature = IO (Maybe GVariant) -> m (Maybe GVariant)
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO (Maybe GVariant) -> m (Maybe GVariant))
-> IO (Maybe GVariant) -> m (Maybe GVariant)
forall a b. (a -> b) -> a -> b
$ do
    CString
json' <- Text -> IO CString
textToCString Text
json
    CString
maybeSignature <- case Maybe Text
signature of
        Maybe Text
Nothing -> CString -> IO CString
forall (m :: * -> *) a. Monad m => a -> m a
return CString
forall a. Ptr a
nullPtr
        Just Text
jSignature -> do
            CString
jSignature' <- Text -> IO CString
textToCString Text
jSignature
            CString -> IO CString
forall (m :: * -> *) a. Monad m => a -> m a
return CString
jSignature'
    IO (Maybe GVariant) -> IO () -> IO (Maybe GVariant)
forall a b. IO a -> IO b -> IO a
onException (do
        Ptr GVariant
result <- (Ptr (Ptr GError) -> IO (Ptr GVariant)) -> IO (Ptr GVariant)
forall a. (Ptr (Ptr GError) -> IO a) -> IO a
propagateGError ((Ptr (Ptr GError) -> IO (Ptr GVariant)) -> IO (Ptr GVariant))
-> (Ptr (Ptr GError) -> IO (Ptr GVariant)) -> IO (Ptr GVariant)
forall a b. (a -> b) -> a -> b
$ CString
-> Int64 -> CString -> Ptr (Ptr GError) -> IO (Ptr GVariant)
json_gvariant_deserialize_data CString
json' Int64
length_ CString
maybeSignature
        Maybe GVariant
maybeResult <- Ptr GVariant
-> (Ptr GVariant -> IO GVariant) -> IO (Maybe GVariant)
forall a b. Ptr a -> (Ptr a -> IO b) -> IO (Maybe b)
convertIfNonNull Ptr GVariant
result ((Ptr GVariant -> IO GVariant) -> IO (Maybe GVariant))
-> (Ptr GVariant -> IO GVariant) -> IO (Maybe GVariant)
forall a b. (a -> b) -> a -> b
$ \Ptr GVariant
result' -> do
            GVariant
result'' <- Ptr GVariant -> IO GVariant
B.GVariant.newGVariantFromPtr Ptr GVariant
result'
            GVariant -> IO GVariant
forall (m :: * -> *) a. Monad m => a -> m a
return GVariant
result''
        CString -> IO ()
forall a. Ptr a -> IO ()
freeMem CString
json'
        CString -> IO ()
forall a. Ptr a -> IO ()
freeMem CString
maybeSignature
        Maybe GVariant -> IO (Maybe GVariant)
forall (m :: * -> *) a. Monad m => a -> m a
return Maybe GVariant
maybeResult
     ) (do
        CString -> IO ()
forall a. Ptr a -> IO ()
freeMem CString
json'
        CString -> IO ()
forall a. Ptr a -> IO ()
freeMem CString
maybeSignature
     )


-- function gvariant_deserialize
-- Args: [ Arg
--           { argCName = "json_node"
--           , argType = TInterface Name { namespace = "Json" , name = "Node" }
--           , direction = DirectionIn
--           , mayBeNull = False
--           , argDoc =
--               Documentation
--                 { rawDocText = Just "the node to convert"
--                 , sinceVersion = Nothing
--                 }
--           , argScope = ScopeTypeInvalid
--           , argClosure = -1
--           , argDestroy = -1
--           , argCallerAllocates = False
--           , transfer = TransferNothing
--           }
--       , Arg
--           { argCName = "signature"
--           , argType = TBasicType TUTF8
--           , direction = DirectionIn
--           , mayBeNull = True
--           , argDoc =
--               Documentation
--                 { rawDocText = Just "a valid `GVariant` type string"
--                 , sinceVersion = Nothing
--                 }
--           , argScope = ScopeTypeInvalid
--           , argClosure = -1
--           , argDestroy = -1
--           , argCallerAllocates = False
--           , transfer = TransferNothing
--           }
--       ]
-- Lengths: []
-- returnType: Just TVariant
-- throws : True
-- Skip return : False

foreign import ccall "json_gvariant_deserialize" json_gvariant_deserialize :: 
    Ptr Json.Node.Node ->                   -- json_node : TInterface (Name {namespace = "Json", name = "Node"})
    CString ->                              -- signature : TBasicType TUTF8
    Ptr (Ptr GError) ->                     -- error
    IO (Ptr GVariant)

-- | Converts a JSON data structure to a @GVariant@.
-- 
-- If @signature@ is not @NULL@, it will be used to resolve ambiguous
-- data types.
-- 
-- If no error occurs, the resulting @GVariant@ is guaranteed to conform
-- to @signature@.
-- 
-- If @signature@ is not @NULL@ but does not represent a valid @GVariant@ type
-- string, @NULL@ is returned and the @error@ is set to
-- @G_IO_ERROR_INVALID_ARGUMENT@.
-- 
-- If a @signature@ is provided but the JSON structure cannot be mapped to it,
-- @NULL@ is returned and the @error@ is set to @G_IO_ERROR_INVALID_DATA@.
-- 
-- If @signature@ is @NULL@, the conversion is done based strictly on the types
-- in the JSON nodes.
-- 
-- The returned variant has a floating reference that will need to be sunk
-- by the caller code.
-- 
-- /Since: 0.14/
gvariantDeserialize ::
    (B.CallStack.HasCallStack, MonadIO m) =>
    Json.Node.Node
    -- ^ /@jsonNode@/: the node to convert
    -> Maybe (T.Text)
    -- ^ /@signature@/: a valid @GVariant@ type string
    -> m (Maybe GVariant)
    -- ^ __Returns:__ A newly created @GVariant@ /(Can throw 'Data.GI.Base.GError.GError')/
gvariantDeserialize :: forall (m :: * -> *).
(HasCallStack, MonadIO m) =>
Node -> Maybe Text -> m (Maybe GVariant)
gvariantDeserialize Node
jsonNode Maybe Text
signature = IO (Maybe GVariant) -> m (Maybe GVariant)
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO (Maybe GVariant) -> m (Maybe GVariant))
-> IO (Maybe GVariant) -> m (Maybe GVariant)
forall a b. (a -> b) -> a -> b
$ do
    Ptr Node
jsonNode' <- Node -> IO (Ptr Node)
forall a. (HasCallStack, ManagedPtrNewtype a) => a -> IO (Ptr a)
unsafeManagedPtrGetPtr Node
jsonNode
    CString
maybeSignature <- case Maybe Text
signature of
        Maybe Text
Nothing -> CString -> IO CString
forall (m :: * -> *) a. Monad m => a -> m a
return CString
forall a. Ptr a
nullPtr
        Just Text
jSignature -> do
            CString
jSignature' <- Text -> IO CString
textToCString Text
jSignature
            CString -> IO CString
forall (m :: * -> *) a. Monad m => a -> m a
return CString
jSignature'
    IO (Maybe GVariant) -> IO () -> IO (Maybe GVariant)
forall a b. IO a -> IO b -> IO a
onException (do
        Ptr GVariant
result <- (Ptr (Ptr GError) -> IO (Ptr GVariant)) -> IO (Ptr GVariant)
forall a. (Ptr (Ptr GError) -> IO a) -> IO a
propagateGError ((Ptr (Ptr GError) -> IO (Ptr GVariant)) -> IO (Ptr GVariant))
-> (Ptr (Ptr GError) -> IO (Ptr GVariant)) -> IO (Ptr GVariant)
forall a b. (a -> b) -> a -> b
$ Ptr Node -> CString -> Ptr (Ptr GError) -> IO (Ptr GVariant)
json_gvariant_deserialize Ptr Node
jsonNode' CString
maybeSignature
        Maybe GVariant
maybeResult <- Ptr GVariant
-> (Ptr GVariant -> IO GVariant) -> IO (Maybe GVariant)
forall a b. Ptr a -> (Ptr a -> IO b) -> IO (Maybe b)
convertIfNonNull Ptr GVariant
result ((Ptr GVariant -> IO GVariant) -> IO (Maybe GVariant))
-> (Ptr GVariant -> IO GVariant) -> IO (Maybe GVariant)
forall a b. (a -> b) -> a -> b
$ \Ptr GVariant
result' -> do
            GVariant
result'' <- Ptr GVariant -> IO GVariant
B.GVariant.newGVariantFromPtr Ptr GVariant
result'
            GVariant -> IO GVariant
forall (m :: * -> *) a. Monad m => a -> m a
return GVariant
result''
        Node -> IO ()
forall a. ManagedPtrNewtype a => a -> IO ()
touchManagedPtr Node
jsonNode
        CString -> IO ()
forall a. Ptr a -> IO ()
freeMem CString
maybeSignature
        Maybe GVariant -> IO (Maybe GVariant)
forall (m :: * -> *) a. Monad m => a -> m a
return Maybe GVariant
maybeResult
     ) (do
        CString -> IO ()
forall a. Ptr a -> IO ()
freeMem CString
maybeSignature
     )


-- function gobject_to_data
-- Args: [ Arg
--           { argCName = "gobject"
--           , argType =
--               TInterface Name { namespace = "GObject" , name = "Object" }
--           , direction = DirectionIn
--           , mayBeNull = False
--           , argDoc =
--               Documentation
--                 { rawDocText = Just "the object to serialize"
--                 , sinceVersion = Nothing
--                 }
--           , argScope = ScopeTypeInvalid
--           , argClosure = -1
--           , argDestroy = -1
--           , argCallerAllocates = False
--           , transfer = TransferNothing
--           }
--       , Arg
--           { argCName = "length"
--           , argType = TBasicType TUInt64
--           , direction = DirectionOut
--           , mayBeNull = False
--           , argDoc =
--               Documentation
--                 { rawDocText = Just "return value for the length of the buffer"
--                 , sinceVersion = Nothing
--                 }
--           , argScope = ScopeTypeInvalid
--           , argClosure = -1
--           , argDestroy = -1
--           , argCallerAllocates = False
--           , transfer = TransferEverything
--           }
--       ]
-- Lengths: []
-- returnType: Just (TBasicType TUTF8)
-- throws : False
-- Skip return : False

foreign import ccall "json_gobject_to_data" json_gobject_to_data :: 
    Ptr GObject.Object.Object ->            -- gobject : TInterface (Name {namespace = "GObject", name = "Object"})
    Ptr Word64 ->                           -- length : TBasicType TUInt64
    IO CString

-- | Serializes a @GObject@ instance into a JSON data stream, iterating
-- recursively over each property.
-- 
-- If the given object implements the [iface/@json@/.Serializable] interface,
-- it will be asked to serialize all its properties; otherwise, the default
-- implementation will be use to translate the compatible types into
-- JSON native types.
-- 
-- /Since: 0.10/
gobjectToData ::
    (B.CallStack.HasCallStack, MonadIO m, GObject.Object.IsObject a) =>
    a
    -- ^ /@gobject@/: the object to serialize
    -> m ((T.Text, Word64))
    -- ^ __Returns:__ a JSON data stream representing the given object
gobjectToData :: forall (m :: * -> *) a.
(HasCallStack, MonadIO m, IsObject a) =>
a -> m (Text, Word64)
gobjectToData a
gobject = IO (Text, Word64) -> m (Text, Word64)
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO (Text, Word64) -> m (Text, Word64))
-> IO (Text, Word64) -> m (Text, Word64)
forall a b. (a -> b) -> a -> b
$ do
    Ptr Object
gobject' <- a -> IO (Ptr Object)
forall a b. (HasCallStack, ManagedPtrNewtype a) => a -> IO (Ptr b)
unsafeManagedPtrCastPtr a
gobject
    Ptr Word64
length_ <- IO (Ptr Word64)
forall a. Storable a => IO (Ptr a)
allocMem :: IO (Ptr Word64)
    CString
result <- Ptr Object -> Ptr Word64 -> IO CString
json_gobject_to_data Ptr Object
gobject' Ptr Word64
length_
    Text -> CString -> IO ()
forall a. HasCallStack => Text -> Ptr a -> IO ()
checkUnexpectedReturnNULL Text
"gobjectToData" CString
result
    Text
result' <- HasCallStack => CString -> IO Text
CString -> IO Text
cstringToText CString
result
    CString -> IO ()
forall a. Ptr a -> IO ()
freeMem CString
result
    Word64
length_' <- Ptr Word64 -> IO Word64
forall a. Storable a => Ptr a -> IO a
peek Ptr Word64
length_
    a -> IO ()
forall a. ManagedPtrNewtype a => a -> IO ()
touchManagedPtr a
gobject
    Ptr Word64 -> IO ()
forall a. Ptr a -> IO ()
freeMem Ptr Word64
length_
    (Text, Word64) -> IO (Text, Word64)
forall (m :: * -> *) a. Monad m => a -> m a
return (Text
result', Word64
length_')


-- function gobject_serialize
-- Args: [ Arg
--           { argCName = "gobject"
--           , argType =
--               TInterface Name { namespace = "GObject" , name = "Object" }
--           , direction = DirectionIn
--           , mayBeNull = False
--           , argDoc =
--               Documentation
--                 { rawDocText = Just "the object to serialize"
--                 , sinceVersion = Nothing
--                 }
--           , argScope = ScopeTypeInvalid
--           , argClosure = -1
--           , argDestroy = -1
--           , argCallerAllocates = False
--           , transfer = TransferNothing
--           }
--       ]
-- Lengths: []
-- returnType: Just (TInterface Name { namespace = "Json" , name = "Node" })
-- throws : False
-- Skip return : False

foreign import ccall "json_gobject_serialize" json_gobject_serialize :: 
    Ptr GObject.Object.Object ->            -- gobject : TInterface (Name {namespace = "GObject", name = "Object"})
    IO (Ptr Json.Node.Node)

-- | Creates a JSON tree representing the passed object instance.
-- 
-- Each member of the returned JSON object will map to a property of
-- the object type.
-- 
-- The returned JSON tree will be returned as a @JsonNode@ with a type
-- of @JSON_NODE_OBJECT@.
-- 
-- /Since: 0.10/
gobjectSerialize ::
    (B.CallStack.HasCallStack, MonadIO m, GObject.Object.IsObject a) =>
    a
    -- ^ /@gobject@/: the object to serialize
    -> m Json.Node.Node
    -- ^ __Returns:__ the newly created JSON tree
gobjectSerialize :: forall (m :: * -> *) a.
(HasCallStack, MonadIO m, IsObject a) =>
a -> m Node
gobjectSerialize a
gobject = IO Node -> m Node
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO Node -> m Node) -> IO Node -> m Node
forall a b. (a -> b) -> a -> b
$ do
    Ptr Object
gobject' <- a -> IO (Ptr Object)
forall a b. (HasCallStack, ManagedPtrNewtype a) => a -> IO (Ptr b)
unsafeManagedPtrCastPtr a
gobject
    Ptr Node
result <- Ptr Object -> IO (Ptr Node)
json_gobject_serialize Ptr Object
gobject'
    Text -> Ptr Node -> IO ()
forall a. HasCallStack => Text -> Ptr a -> IO ()
checkUnexpectedReturnNULL Text
"gobjectSerialize" Ptr Node
result
    Node
result' <- ((ManagedPtr Node -> Node) -> Ptr Node -> IO Node
forall a.
(HasCallStack, GBoxed a) =>
(ManagedPtr a -> a) -> Ptr a -> IO a
wrapBoxed ManagedPtr Node -> Node
Json.Node.Node) Ptr Node
result
    a -> IO ()
forall a. ManagedPtrNewtype a => a -> IO ()
touchManagedPtr a
gobject
    Node -> IO Node
forall (m :: * -> *) a. Monad m => a -> m a
return Node
result'


-- function gobject_from_data
-- Args: [ Arg
--           { argCName = "gtype"
--           , argType = TBasicType TGType
--           , direction = DirectionIn
--           , mayBeNull = False
--           , argDoc =
--               Documentation
--                 { rawDocText = Just "the type of the object to construct"
--                 , sinceVersion = Nothing
--                 }
--           , argScope = ScopeTypeInvalid
--           , argClosure = -1
--           , argDestroy = -1
--           , argCallerAllocates = False
--           , transfer = TransferNothing
--           }
--       , Arg
--           { argCName = "data"
--           , argType = TBasicType TUTF8
--           , direction = DirectionIn
--           , mayBeNull = False
--           , argDoc =
--               Documentation
--                 { rawDocText = Just "a JSON data stream" , sinceVersion = Nothing }
--           , argScope = ScopeTypeInvalid
--           , argClosure = -1
--           , argDestroy = -1
--           , argCallerAllocates = False
--           , transfer = TransferNothing
--           }
--       , Arg
--           { argCName = "length"
--           , argType = TBasicType TInt64
--           , direction = DirectionIn
--           , mayBeNull = False
--           , argDoc =
--               Documentation
--                 { rawDocText =
--                     Just "length of the data stream, or -1 if it is `NUL`-terminated"
--                 , sinceVersion = Nothing
--                 }
--           , argScope = ScopeTypeInvalid
--           , argClosure = -1
--           , argDestroy = -1
--           , argCallerAllocates = False
--           , transfer = TransferNothing
--           }
--       ]
-- Lengths: []
-- returnType: Just (TInterface Name { namespace = "GObject" , name = "Object" })
-- throws : True
-- Skip return : False

foreign import ccall "json_gobject_from_data" json_gobject_from_data :: 
    CGType ->                               -- gtype : TBasicType TGType
    CString ->                              -- data : TBasicType TUTF8
    Int64 ->                                -- length : TBasicType TInt64
    Ptr (Ptr GError) ->                     -- error
    IO (Ptr GObject.Object.Object)

-- | Deserializes a JSON data stream and creates an instance of the
-- given type.
-- 
-- If the type implements the [iface/@json@/.Serializable] interface, it will
-- be asked to deserialize all the JSON members into their respective properties;
-- otherwise, the default implementation will be used to translate the
-- compatible JSON native types.
-- 
-- **Note**: the JSON data stream must be an object
-- 
-- /Since: 0.10/
gobjectFromData ::
    (B.CallStack.HasCallStack, MonadIO m) =>
    GType
    -- ^ /@gtype@/: the type of the object to construct
    -> T.Text
    -- ^ /@data@/: a JSON data stream
    -> Int64
    -- ^ /@length@/: length of the data stream, or -1 if it is @NUL@-terminated
    -> m (Maybe GObject.Object.Object)
    -- ^ __Returns:__ a new object instance of the given type /(Can throw 'Data.GI.Base.GError.GError')/
gobjectFromData :: forall (m :: * -> *).
(HasCallStack, MonadIO m) =>
GType -> Text -> Int64 -> m (Maybe Object)
gobjectFromData GType
gtype Text
data_ Int64
length_ = IO (Maybe Object) -> m (Maybe Object)
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO (Maybe Object) -> m (Maybe Object))
-> IO (Maybe Object) -> m (Maybe Object)
forall a b. (a -> b) -> a -> b
$ do
    let gtype' :: Word64
gtype' = GType -> Word64
gtypeToCGType GType
gtype
    CString
data_' <- Text -> IO CString
textToCString Text
data_
    IO (Maybe Object) -> IO () -> IO (Maybe Object)
forall a b. IO a -> IO b -> IO a
onException (do
        Ptr Object
result <- (Ptr (Ptr GError) -> IO (Ptr Object)) -> IO (Ptr Object)
forall a. (Ptr (Ptr GError) -> IO a) -> IO a
propagateGError ((Ptr (Ptr GError) -> IO (Ptr Object)) -> IO (Ptr Object))
-> (Ptr (Ptr GError) -> IO (Ptr Object)) -> IO (Ptr Object)
forall a b. (a -> b) -> a -> b
$ Word64 -> CString -> Int64 -> Ptr (Ptr GError) -> IO (Ptr Object)
json_gobject_from_data Word64
gtype' CString
data_' Int64
length_
        Maybe Object
maybeResult <- Ptr Object -> (Ptr Object -> IO Object) -> IO (Maybe Object)
forall a b. Ptr a -> (Ptr a -> IO b) -> IO (Maybe b)
convertIfNonNull Ptr Object
result ((Ptr Object -> IO Object) -> IO (Maybe Object))
-> (Ptr Object -> IO Object) -> IO (Maybe Object)
forall a b. (a -> b) -> a -> b
$ \Ptr Object
result' -> do
            Object
result'' <- ((ManagedPtr Object -> Object) -> Ptr Object -> IO Object
forall a b.
(HasCallStack, GObject a, GObject b) =>
(ManagedPtr a -> a) -> Ptr b -> IO a
wrapObject ManagedPtr Object -> Object
GObject.Object.Object) Ptr Object
result'
            Object -> IO Object
forall (m :: * -> *) a. Monad m => a -> m a
return Object
result''
        CString -> IO ()
forall a. Ptr a -> IO ()
freeMem CString
data_'
        Maybe Object -> IO (Maybe Object)
forall (m :: * -> *) a. Monad m => a -> m a
return Maybe Object
maybeResult
     ) (do
        CString -> IO ()
forall a. Ptr a -> IO ()
freeMem CString
data_'
     )


-- function gobject_deserialize
-- Args: [ Arg
--           { argCName = "gtype"
--           , argType = TBasicType TGType
--           , direction = DirectionIn
--           , mayBeNull = False
--           , argDoc =
--               Documentation
--                 { rawDocText = Just "the type of the object to create"
--                 , sinceVersion = Nothing
--                 }
--           , argScope = ScopeTypeInvalid
--           , argClosure = -1
--           , argDestroy = -1
--           , argCallerAllocates = False
--           , transfer = TransferNothing
--           }
--       , Arg
--           { argCName = "node"
--           , argType = TInterface Name { namespace = "Json" , name = "Node" }
--           , direction = DirectionIn
--           , mayBeNull = False
--           , argDoc =
--               Documentation
--                 { rawDocText =
--                     Just
--                       "a node of type `JSON_NODE_OBJECT` describing the\n  object instance for the given type"
--                 , sinceVersion = Nothing
--                 }
--           , argScope = ScopeTypeInvalid
--           , argClosure = -1
--           , argDestroy = -1
--           , argCallerAllocates = False
--           , transfer = TransferNothing
--           }
--       ]
-- Lengths: []
-- returnType: Just (TInterface Name { namespace = "GObject" , name = "Object" })
-- throws : False
-- Skip return : False

foreign import ccall "json_gobject_deserialize" json_gobject_deserialize :: 
    CGType ->                               -- gtype : TBasicType TGType
    Ptr Json.Node.Node ->                   -- node : TInterface (Name {namespace = "Json", name = "Node"})
    IO (Ptr GObject.Object.Object)

-- | Creates a new @GObject@ instance of the given type, and constructs it
-- using the members of the object in the given node.
-- 
-- /Since: 0.10/
gobjectDeserialize ::
    (B.CallStack.HasCallStack, MonadIO m) =>
    GType
    -- ^ /@gtype@/: the type of the object to create
    -> Json.Node.Node
    -- ^ /@node@/: a node of type @JSON_NODE_OBJECT@ describing the
    --   object instance for the given type
    -> m GObject.Object.Object
    -- ^ __Returns:__ The newly created instance
gobjectDeserialize :: forall (m :: * -> *).
(HasCallStack, MonadIO m) =>
GType -> Node -> m Object
gobjectDeserialize GType
gtype Node
node = IO Object -> m Object
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO Object -> m Object) -> IO Object -> m Object
forall a b. (a -> b) -> a -> b
$ do
    let gtype' :: Word64
gtype' = GType -> Word64
gtypeToCGType GType
gtype
    Ptr Node
node' <- Node -> IO (Ptr Node)
forall a. (HasCallStack, ManagedPtrNewtype a) => a -> IO (Ptr a)
unsafeManagedPtrGetPtr Node
node
    Ptr Object
result <- Word64 -> Ptr Node -> IO (Ptr Object)
json_gobject_deserialize Word64
gtype' Ptr Node
node'
    Text -> Ptr Object -> IO ()
forall a. HasCallStack => Text -> Ptr a -> IO ()
checkUnexpectedReturnNULL Text
"gobjectDeserialize" Ptr Object
result
    Object
result' <- ((ManagedPtr Object -> Object) -> Ptr Object -> IO Object
forall a b.
(HasCallStack, GObject a, GObject b) =>
(ManagedPtr a -> a) -> Ptr b -> IO a
wrapObject ManagedPtr Object -> Object
GObject.Object.Object) Ptr Object
result
    Node -> IO ()
forall a. ManagedPtrNewtype a => a -> IO ()
touchManagedPtr Node
node
    Object -> IO Object
forall (m :: * -> *) a. Monad m => a -> m a
return Object
result'


-- function from_string
-- Args: [ Arg
--           { argCName = "str"
--           , argType = TBasicType TUTF8
--           , direction = DirectionIn
--           , mayBeNull = False
--           , argDoc =
--               Documentation
--                 { rawDocText = Just "a valid UTF-8 string containing JSON data"
--                 , sinceVersion = Nothing
--                 }
--           , argScope = ScopeTypeInvalid
--           , argClosure = -1
--           , argDestroy = -1
--           , argCallerAllocates = False
--           , transfer = TransferNothing
--           }
--       ]
-- Lengths: []
-- returnType: Just (TInterface Name { namespace = "Json" , name = "Node" })
-- throws : True
-- Skip return : False

foreign import ccall "json_from_string" json_from_string :: 
    CString ->                              -- str : TBasicType TUTF8
    Ptr (Ptr GError) ->                     -- error
    IO (Ptr Json.Node.Node)

-- | Parses the given string and returns the corresponding JSON tree.
-- 
-- If the string is empty, this function will return @NULL@.
-- 
-- In case of parsing error, this function returns @NULL@ and sets
-- the error appropriately.
-- 
-- /Since: 1.2/
fromString ::
    (B.CallStack.HasCallStack, MonadIO m) =>
    T.Text
    -- ^ /@str@/: a valid UTF-8 string containing JSON data
    -> m (Maybe Json.Node.Node)
    -- ^ __Returns:__ the root node of the JSON tree /(Can throw 'Data.GI.Base.GError.GError')/
fromString :: forall (m :: * -> *).
(HasCallStack, MonadIO m) =>
Text -> m (Maybe Node)
fromString Text
str = IO (Maybe Node) -> m (Maybe Node)
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO (Maybe Node) -> m (Maybe Node))
-> IO (Maybe Node) -> m (Maybe Node)
forall a b. (a -> b) -> a -> b
$ do
    CString
str' <- Text -> IO CString
textToCString Text
str
    IO (Maybe Node) -> IO () -> IO (Maybe Node)
forall a b. IO a -> IO b -> IO a
onException (do
        Ptr Node
result <- (Ptr (Ptr GError) -> IO (Ptr Node)) -> IO (Ptr Node)
forall a. (Ptr (Ptr GError) -> IO a) -> IO a
propagateGError ((Ptr (Ptr GError) -> IO (Ptr Node)) -> IO (Ptr Node))
-> (Ptr (Ptr GError) -> IO (Ptr Node)) -> IO (Ptr Node)
forall a b. (a -> b) -> a -> b
$ CString -> Ptr (Ptr GError) -> IO (Ptr Node)
json_from_string CString
str'
        Maybe Node
maybeResult <- Ptr Node -> (Ptr Node -> IO Node) -> IO (Maybe Node)
forall a b. Ptr a -> (Ptr a -> IO b) -> IO (Maybe b)
convertIfNonNull Ptr Node
result ((Ptr Node -> IO Node) -> IO (Maybe Node))
-> (Ptr Node -> IO Node) -> IO (Maybe Node)
forall a b. (a -> b) -> a -> b
$ \Ptr Node
result' -> do
            Node
result'' <- ((ManagedPtr Node -> Node) -> Ptr Node -> IO Node
forall a.
(HasCallStack, GBoxed a) =>
(ManagedPtr a -> a) -> Ptr a -> IO a
wrapBoxed ManagedPtr Node -> Node
Json.Node.Node) Ptr Node
result'
            Node -> IO Node
forall (m :: * -> *) a. Monad m => a -> m a
return Node
result''
        CString -> IO ()
forall a. Ptr a -> IO ()
freeMem CString
str'
        Maybe Node -> IO (Maybe Node)
forall (m :: * -> *) a. Monad m => a -> m a
return Maybe Node
maybeResult
     ) (do
        CString -> IO ()
forall a. Ptr a -> IO ()
freeMem CString
str'
     )


-- function construct_gobject
-- Args: [ Arg
--           { argCName = "gtype"
--           , argType = TBasicType TGType
--           , direction = DirectionIn
--           , mayBeNull = False
--           , argDoc =
--               Documentation
--                 { rawDocText = Just "the type of the object to construct"
--                 , sinceVersion = Nothing
--                 }
--           , argScope = ScopeTypeInvalid
--           , argClosure = -1
--           , argDestroy = -1
--           , argCallerAllocates = False
--           , transfer = TransferNothing
--           }
--       , Arg
--           { argCName = "data"
--           , argType = TBasicType TUTF8
--           , direction = DirectionIn
--           , mayBeNull = False
--           , argDoc =
--               Documentation
--                 { rawDocText = Just "a JSON data stream" , sinceVersion = Nothing }
--           , argScope = ScopeTypeInvalid
--           , argClosure = -1
--           , argDestroy = -1
--           , argCallerAllocates = False
--           , transfer = TransferNothing
--           }
--       , Arg
--           { argCName = "length"
--           , argType = TBasicType TUInt64
--           , direction = DirectionIn
--           , mayBeNull = False
--           , argDoc =
--               Documentation
--                 { rawDocText = Just "length of the data stream"
--                 , sinceVersion = Nothing
--                 }
--           , argScope = ScopeTypeInvalid
--           , argClosure = -1
--           , argDestroy = -1
--           , argCallerAllocates = False
--           , transfer = TransferNothing
--           }
--       ]
-- Lengths: []
-- returnType: Just (TInterface Name { namespace = "GObject" , name = "Object" })
-- throws : True
-- Skip return : False

foreign import ccall "json_construct_gobject" json_construct_gobject :: 
    CGType ->                               -- gtype : TBasicType TGType
    CString ->                              -- data : TBasicType TUTF8
    Word64 ->                               -- length : TBasicType TUInt64
    Ptr (Ptr GError) ->                     -- error
    IO (Ptr GObject.Object.Object)

{-# DEPRECATED constructGobject ["(Since version 0.10)","Use [func/@json@/.gobject_from_data] instead"] #-}
-- | Deserializes a JSON data stream and creates an instance of the given
-- type
-- 
-- If the given type implements the [iface/@json@/.Serializable] interface, it
-- will be asked to deserialize all the JSON members into their respective
-- properties; otherwise, the default implementation will be used to translate
-- the compatible JSON native types.
-- 
-- **Note**: the JSON data stream must be an object.
-- 
-- /Since: 0.4/
constructGobject ::
    (B.CallStack.HasCallStack, MonadIO m) =>
    GType
    -- ^ /@gtype@/: the type of the object to construct
    -> T.Text
    -- ^ /@data@/: a JSON data stream
    -> Word64
    -- ^ /@length@/: length of the data stream
    -> m (Maybe GObject.Object.Object)
    -- ^ __Returns:__ a new object instance of the given type /(Can throw 'Data.GI.Base.GError.GError')/
constructGobject :: forall (m :: * -> *).
(HasCallStack, MonadIO m) =>
GType -> Text -> Word64 -> m (Maybe Object)
constructGobject GType
gtype Text
data_ Word64
length_ = IO (Maybe Object) -> m (Maybe Object)
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO (Maybe Object) -> m (Maybe Object))
-> IO (Maybe Object) -> m (Maybe Object)
forall a b. (a -> b) -> a -> b
$ do
    let gtype' :: Word64
gtype' = GType -> Word64
gtypeToCGType GType
gtype
    CString
data_' <- Text -> IO CString
textToCString Text
data_
    IO (Maybe Object) -> IO () -> IO (Maybe Object)
forall a b. IO a -> IO b -> IO a
onException (do
        Ptr Object
result <- (Ptr (Ptr GError) -> IO (Ptr Object)) -> IO (Ptr Object)
forall a. (Ptr (Ptr GError) -> IO a) -> IO a
propagateGError ((Ptr (Ptr GError) -> IO (Ptr Object)) -> IO (Ptr Object))
-> (Ptr (Ptr GError) -> IO (Ptr Object)) -> IO (Ptr Object)
forall a b. (a -> b) -> a -> b
$ Word64 -> CString -> Word64 -> Ptr (Ptr GError) -> IO (Ptr Object)
json_construct_gobject Word64
gtype' CString
data_' Word64
length_
        Maybe Object
maybeResult <- Ptr Object -> (Ptr Object -> IO Object) -> IO (Maybe Object)
forall a b. Ptr a -> (Ptr a -> IO b) -> IO (Maybe b)
convertIfNonNull Ptr Object
result ((Ptr Object -> IO Object) -> IO (Maybe Object))
-> (Ptr Object -> IO Object) -> IO (Maybe Object)
forall a b. (a -> b) -> a -> b
$ \Ptr Object
result' -> do
            Object
result'' <- ((ManagedPtr Object -> Object) -> Ptr Object -> IO Object
forall a b.
(HasCallStack, GObject a, GObject b) =>
(ManagedPtr a -> a) -> Ptr b -> IO a
wrapObject ManagedPtr Object -> Object
GObject.Object.Object) Ptr Object
result'
            Object -> IO Object
forall (m :: * -> *) a. Monad m => a -> m a
return Object
result''
        CString -> IO ()
forall a. Ptr a -> IO ()
freeMem CString
data_'
        Maybe Object -> IO (Maybe Object)
forall (m :: * -> *) a. Monad m => a -> m a
return Maybe Object
maybeResult
     ) (do
        CString -> IO ()
forall a. Ptr a -> IO ()
freeMem CString
data_'
     )


-- function boxed_serialize
-- Args: [ Arg
--           { argCName = "gboxed_type"
--           , argType = TBasicType TGType
--           , direction = DirectionIn
--           , mayBeNull = False
--           , argDoc =
--               Documentation
--                 { rawDocText = Just "a boxed type" , sinceVersion = Nothing }
--           , argScope = ScopeTypeInvalid
--           , argClosure = -1
--           , argDestroy = -1
--           , argCallerAllocates = False
--           , transfer = TransferNothing
--           }
--       , Arg
--           { argCName = "boxed"
--           , argType = TBasicType TPtr
--           , direction = DirectionIn
--           , mayBeNull = True
--           , argDoc =
--               Documentation
--                 { rawDocText = Just "a pointer to a boxed of type `gboxed_type`"
--                 , sinceVersion = Nothing
--                 }
--           , argScope = ScopeTypeInvalid
--           , argClosure = -1
--           , argDestroy = -1
--           , argCallerAllocates = False
--           , transfer = TransferNothing
--           }
--       ]
-- Lengths: []
-- returnType: Just (TInterface Name { namespace = "Json" , name = "Node" })
-- throws : False
-- Skip return : False

foreign import ccall "json_boxed_serialize" json_boxed_serialize :: 
    CGType ->                               -- gboxed_type : TBasicType TGType
    Ptr () ->                               -- boxed : TBasicType TPtr
    IO (Ptr Json.Node.Node)

-- | Serializes a pointer to a @GBoxed@ of the given type into a [struct/@json@/.Node].
-- 
-- If the serialization is not possible, this function will return @NULL@.
-- 
-- /Since: 0.10/
boxedSerialize ::
    (B.CallStack.HasCallStack, MonadIO m) =>
    GType
    -- ^ /@gboxedType@/: a boxed type
    -> Ptr ()
    -- ^ /@boxed@/: a pointer to a boxed of type @gboxed_type@
    -> m (Maybe Json.Node.Node)
    -- ^ __Returns:__ a node with the serialized boxed type
boxedSerialize :: forall (m :: * -> *).
(HasCallStack, MonadIO m) =>
GType -> Ptr () -> m (Maybe Node)
boxedSerialize GType
gboxedType Ptr ()
boxed = IO (Maybe Node) -> m (Maybe Node)
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO (Maybe Node) -> m (Maybe Node))
-> IO (Maybe Node) -> m (Maybe Node)
forall a b. (a -> b) -> a -> b
$ do
    let gboxedType' :: Word64
gboxedType' = GType -> Word64
gtypeToCGType GType
gboxedType
    Ptr Node
result <- Word64 -> Ptr () -> IO (Ptr Node)
json_boxed_serialize Word64
gboxedType' Ptr ()
boxed
    Maybe Node
maybeResult <- Ptr Node -> (Ptr Node -> IO Node) -> IO (Maybe Node)
forall a b. Ptr a -> (Ptr a -> IO b) -> IO (Maybe b)
convertIfNonNull Ptr Node
result ((Ptr Node -> IO Node) -> IO (Maybe Node))
-> (Ptr Node -> IO Node) -> IO (Maybe Node)
forall a b. (a -> b) -> a -> b
$ \Ptr Node
result' -> do
        Node
result'' <- ((ManagedPtr Node -> Node) -> Ptr Node -> IO Node
forall a.
(HasCallStack, GBoxed a) =>
(ManagedPtr a -> a) -> Ptr a -> IO a
wrapBoxed ManagedPtr Node -> Node
Json.Node.Node) Ptr Node
result'
        Node -> IO Node
forall (m :: * -> *) a. Monad m => a -> m a
return Node
result''
    Maybe Node -> IO (Maybe Node)
forall (m :: * -> *) a. Monad m => a -> m a
return Maybe Node
maybeResult


-- function boxed_deserialize
-- Args: [ Arg
--           { argCName = "gboxed_type"
--           , argType = TBasicType TGType
--           , direction = DirectionIn
--           , mayBeNull = False
--           , argDoc =
--               Documentation
--                 { rawDocText = Just "a boxed type" , sinceVersion = Nothing }
--           , argScope = ScopeTypeInvalid
--           , argClosure = -1
--           , argDestroy = -1
--           , argCallerAllocates = False
--           , transfer = TransferNothing
--           }
--       , Arg
--           { argCName = "node"
--           , argType = TInterface Name { namespace = "Json" , name = "Node" }
--           , direction = DirectionIn
--           , mayBeNull = False
--           , argDoc =
--               Documentation
--                 { rawDocText = Just "a node" , sinceVersion = Nothing }
--           , argScope = ScopeTypeInvalid
--           , argClosure = -1
--           , argDestroy = -1
--           , argCallerAllocates = False
--           , transfer = TransferNothing
--           }
--       ]
-- Lengths: []
-- returnType: Just (TBasicType TPtr)
-- throws : False
-- Skip return : False

foreign import ccall "json_boxed_deserialize" json_boxed_deserialize :: 
    CGType ->                               -- gboxed_type : TBasicType TGType
    Ptr Json.Node.Node ->                   -- node : TInterface (Name {namespace = "Json", name = "Node"})
    IO (Ptr ())

-- | Deserializes the given [struct/@json@/.Node] into a @GBoxed@ of the given type.
-- 
-- /Since: 0.10/
boxedDeserialize ::
    (B.CallStack.HasCallStack, MonadIO m) =>
    GType
    -- ^ /@gboxedType@/: a boxed type
    -> Json.Node.Node
    -- ^ /@node@/: a node
    -> m (Ptr ())
    -- ^ __Returns:__ the newly allocated boxed data
boxedDeserialize :: forall (m :: * -> *).
(HasCallStack, MonadIO m) =>
GType -> Node -> m (Ptr ())
boxedDeserialize GType
gboxedType Node
node = IO (Ptr ()) -> m (Ptr ())
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO (Ptr ()) -> m (Ptr ())) -> IO (Ptr ()) -> m (Ptr ())
forall a b. (a -> b) -> a -> b
$ do
    let gboxedType' :: Word64
gboxedType' = GType -> Word64
gtypeToCGType GType
gboxedType
    Ptr Node
node' <- Node -> IO (Ptr Node)
forall a. (HasCallStack, ManagedPtrNewtype a) => a -> IO (Ptr a)
unsafeManagedPtrGetPtr Node
node
    Ptr ()
result <- Word64 -> Ptr Node -> IO (Ptr ())
json_boxed_deserialize Word64
gboxedType' Ptr Node
node'
    Node -> IO ()
forall a. ManagedPtrNewtype a => a -> IO ()
touchManagedPtr Node
node
    Ptr () -> IO (Ptr ())
forall (m :: * -> *) a. Monad m => a -> m a
return Ptr ()
result


-- function boxed_can_serialize
-- Args: [ Arg
--           { argCName = "gboxed_type"
--           , argType = TBasicType TGType
--           , direction = DirectionIn
--           , mayBeNull = False
--           , argDoc =
--               Documentation
--                 { rawDocText = Just "a boxed type" , sinceVersion = Nothing }
--           , argScope = ScopeTypeInvalid
--           , argClosure = -1
--           , argDestroy = -1
--           , argCallerAllocates = False
--           , transfer = TransferNothing
--           }
--       , Arg
--           { argCName = "node_type"
--           , argType =
--               TInterface Name { namespace = "Json" , name = "NodeType" }
--           , direction = DirectionOut
--           , mayBeNull = False
--           , argDoc =
--               Documentation
--                 { rawDocText =
--                     Just
--                       "the node type to which the boxed type\n  can be serialized into"
--                 , sinceVersion = Nothing
--                 }
--           , argScope = ScopeTypeInvalid
--           , argClosure = -1
--           , argDestroy = -1
--           , argCallerAllocates = False
--           , transfer = TransferEverything
--           }
--       ]
-- Lengths: []
-- returnType: Just (TBasicType TBoolean)
-- throws : False
-- Skip return : False

foreign import ccall "json_boxed_can_serialize" json_boxed_can_serialize :: 
    CGType ->                               -- gboxed_type : TBasicType TGType
    Ptr CUInt ->                            -- node_type : TInterface (Name {namespace = "Json", name = "NodeType"})
    IO CInt

-- | Checks whether it is possible to serialize a @GBoxed@ of
-- type @gboxed_type@ into a [struct/@json@/.Node].
-- 
-- The type of the node is placed inside @node_type@ if the function
-- returns @TRUE@, and it\'s undefined otherwise.
-- 
-- /Since: 0.10/
boxedCanSerialize ::
    (B.CallStack.HasCallStack, MonadIO m) =>
    GType
    -- ^ /@gboxedType@/: a boxed type
    -> m ((Bool, Json.Enums.NodeType))
    -- ^ __Returns:__ @TRUE@ if the type can be serialized, and @FALSE@ otherwise
boxedCanSerialize :: forall (m :: * -> *).
(HasCallStack, MonadIO m) =>
GType -> m (Bool, NodeType)
boxedCanSerialize GType
gboxedType = IO (Bool, NodeType) -> m (Bool, NodeType)
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO (Bool, NodeType) -> m (Bool, NodeType))
-> IO (Bool, NodeType) -> m (Bool, NodeType)
forall a b. (a -> b) -> a -> b
$ do
    let gboxedType' :: Word64
gboxedType' = GType -> Word64
gtypeToCGType GType
gboxedType
    Ptr CUInt
nodeType <- IO (Ptr CUInt)
forall a. Storable a => IO (Ptr a)
allocMem :: IO (Ptr CUInt)
    CInt
result <- Word64 -> Ptr CUInt -> IO CInt
json_boxed_can_serialize Word64
gboxedType' Ptr CUInt
nodeType
    let result' :: Bool
result' = (CInt -> CInt -> Bool
forall a. Eq a => a -> a -> Bool
/= CInt
0) CInt
result
    CUInt
nodeType' <- Ptr CUInt -> IO CUInt
forall a. Storable a => Ptr a -> IO a
peek Ptr CUInt
nodeType
    let nodeType'' :: NodeType
nodeType'' = (Int -> NodeType
forall a. Enum a => Int -> a
toEnum (Int -> NodeType) -> (CUInt -> Int) -> CUInt -> NodeType
forall b c a. (b -> c) -> (a -> b) -> a -> c
. CUInt -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral) CUInt
nodeType'
    Ptr CUInt -> IO ()
forall a. Ptr a -> IO ()
freeMem Ptr CUInt
nodeType
    (Bool, NodeType) -> IO (Bool, NodeType)
forall (m :: * -> *) a. Monad m => a -> m a
return (Bool
result', NodeType
nodeType'')


-- function boxed_can_deserialize
-- Args: [ Arg
--           { argCName = "gboxed_type"
--           , argType = TBasicType TGType
--           , direction = DirectionIn
--           , mayBeNull = False
--           , argDoc =
--               Documentation
--                 { rawDocText = Just "a boxed type" , sinceVersion = Nothing }
--           , argScope = ScopeTypeInvalid
--           , argClosure = -1
--           , argDestroy = -1
--           , argCallerAllocates = False
--           , transfer = TransferNothing
--           }
--       , Arg
--           { argCName = "node_type"
--           , argType =
--               TInterface Name { namespace = "Json" , name = "NodeType" }
--           , direction = DirectionIn
--           , mayBeNull = False
--           , argDoc =
--               Documentation
--                 { rawDocText = Just "a node type" , sinceVersion = Nothing }
--           , argScope = ScopeTypeInvalid
--           , argClosure = -1
--           , argDestroy = -1
--           , argCallerAllocates = False
--           , transfer = TransferNothing
--           }
--       ]
-- Lengths: []
-- returnType: Just (TBasicType TBoolean)
-- throws : False
-- Skip return : False

foreign import ccall "json_boxed_can_deserialize" json_boxed_can_deserialize :: 
    CGType ->                               -- gboxed_type : TBasicType TGType
    CUInt ->                                -- node_type : TInterface (Name {namespace = "Json", name = "NodeType"})
    IO CInt

-- | Checks whether it is possible to deserialize a @GBoxed@ of
-- type @gboxed_type@ from a [struct/@json@/.Node] of type @node_type@.
-- 
-- /Since: 0.10/
boxedCanDeserialize ::
    (B.CallStack.HasCallStack, MonadIO m) =>
    GType
    -- ^ /@gboxedType@/: a boxed type
    -> Json.Enums.NodeType
    -- ^ /@nodeType@/: a node type
    -> m Bool
    -- ^ __Returns:__ @TRUE@ if the type can be deserialized, and @FALSE@ otherwise
boxedCanDeserialize :: forall (m :: * -> *).
(HasCallStack, MonadIO m) =>
GType -> NodeType -> m Bool
boxedCanDeserialize GType
gboxedType NodeType
nodeType = IO Bool -> m Bool
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO Bool -> m Bool) -> IO Bool -> m Bool
forall a b. (a -> b) -> a -> b
$ do
    let gboxedType' :: Word64
gboxedType' = GType -> Word64
gtypeToCGType GType
gboxedType
    let nodeType' :: CUInt
nodeType' = (Int -> CUInt
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Int -> CUInt) -> (NodeType -> Int) -> NodeType -> CUInt
forall b c a. (b -> c) -> (a -> b) -> a -> c
. NodeType -> Int
forall a. Enum a => a -> Int
fromEnum) NodeType
nodeType
    CInt
result <- Word64 -> CUInt -> IO CInt
json_boxed_can_deserialize Word64
gboxedType' CUInt
nodeType'
    let result' :: Bool
result' = (CInt -> CInt -> Bool
forall a. Eq a => a -> a -> Bool
/= CInt
0) CInt
result
    Bool -> IO Bool
forall (m :: * -> *) a. Monad m => a -> m a
return Bool
result'