    {-# OPTIONS_GHC -optc-DZSTD_STATIC_LINKING_ONLY #-}
    {-# LINE 1 "Codec/Compression/Zstd/FFI/Types.hsc" #-}
    -- Copyright (c) 2016-present, Facebook, Inc.
    -- All rights reserved.
    --
    -- This source code is licensed under the BSD-style license found in
    -- the LICENSE file in the root directory of this source tree. An
    -- additional grant of patent rights can be found in the PATENTS file
    -- in the same directory.

    {-# LANGUAGE ExistentialQuantification #-}

    -- |
    -- Module      : Codec.Compression.Zstd.FFI
    -- Copyright   : (c) 2016-present, Facebook, Inc. All rights reserved.
    --
    -- License     : BSD3
    -- Maintainer  : bos@serpentine.com
    -- Stability   : experimental
    -- Portability : GHC
    --
    -- Types and functions that support the low-level FFI bindings.

    module Codec.Compression.Zstd.FFI.Types
        (
          Buffer(..)
        , In
        , Out
        , CCtx
        , DCtx
        , CDict
        , DDict
        , peekPtr
        , pokePtr
        , peekSize
        , pokeSize
        , peekPos
        , pokePos
        ) where

    import Foreign.C.Types (CInt(..), CSize(..))
    import Foreign.Storable
    import GHC.Ptr (Ptr(..))

    -- | An opaque compression context structure.
    data CCtx
    -- | An opaque decompression context structure.
    data DCtx

    -- | An opaque pre-digested compression dictionary structure.
    data CDict
    -- | An opaque pre-digested decompression dictionary structure.
    data DDict

    -- | A tag type to indicate that a 'Buffer' is used for tracking input.
    data In
    -- | A tag type to indicate that a 'Buffer' is used for tracking output.
    data Out

    -- | A streaming buffer type. The type parameter statically indicates
    -- whether the buffer is used to track an input or output buffer.
    data Buffer io = forall a. Buffer {
          -- | Pointer to the start of the buffer.  This can be set once
          -- by the caller, and read by the streaming function.
          ()
    bufPtr  :: {-# UNPACK #-} !(Ptr a)
          -- | Size of the buffer (in bytes).  This can be set once by the
          -- caller, and is read by the streaming function.
        , forall io. Buffer io -> CSize
    bufSize :: {-# UNPACK #-} !CSize
          -- | Current offset into the buffer (in bytes).  This must be
          -- initially set to zero by the caller, and is updated by the
          -- streaming function.
        , forall io. Buffer io -> CSize
    bufPos  :: {-# UNPACK #-} !CSize
        }

    instance Storable (Buffer io) where
        sizeOf :: Buffer io -> Int
    sizeOf Buffer io
    _     = Int
    24
    {-# LINE 78 "Codec/Compression/Zstd/FFI/Types.hsc" #-}
        alignment _  = alignment (undefined :: CInt)

        peek :: Ptr (Buffer io) -> IO (Buffer io)
    peek Ptr (Buffer io)
    p = do
          ptr <- ((\Ptr (Buffer io)
    hsc_ptr -> Ptr (Buffer io) -> Int -> IO (Ptr (ZonkAny 0))
    forall b. Ptr b -> Int -> IO (Ptr (ZonkAny 0))
    forall a b. Storable a => Ptr b -> Int -> IO a
    peekByteOff Ptr (Buffer io)
    hsc_ptr Int
    0)) Ptr (Buffer io)
    p
    {-# LINE 82 "Codec/Compression/Zstd/FFI/Types.hsc" #-}
          size <- ((\hsc_ptr -> peekByteOff hsc_ptr 8)) p
    {-# LINE 83 "Codec/Compression/Zstd/FFI/Types.hsc" #-}
          pos <- ((\hsc_ptr -> peekByteOff hsc_ptr 16)) p
    {-# LINE 84 "Codec/Compression/Zstd/FFI/Types.hsc" #-}
          return (Buffer ptr size pos)

        poke :: Ptr (Buffer io) -> Buffer io -> IO ()
    poke Ptr (Buffer io)
    p (Buffer Ptr a
    ptr CSize
    size CSize
    pos) = do
          ((\Ptr (Buffer io)
    hsc_ptr -> Ptr (Buffer io) -> Int -> Ptr a -> IO ()
    forall b. Ptr b -> Int -> Ptr a -> IO ()
    forall a b. Storable a => Ptr b -> Int -> a -> IO ()
    pokeByteOff Ptr (Buffer io)
    hsc_ptr Int
    0)) Ptr (Buffer io)
    p Ptr a
    ptr
    {-# LINE 88 "Codec/Compression/Zstd/FFI/Types.hsc" #-}
          ((\hsc_ptr -> pokeByteOff hsc_ptr 8)) p size
    {-# LINE 89 "Codec/Compression/Zstd/FFI/Types.hsc" #-}
          ((\hsc_ptr -> pokeByteOff hsc_ptr 16)) p pos
    {-# LINE 90 "Codec/Compression/Zstd/FFI/Types.hsc" #-}

    -- | Read the 'bufPtr' value from a 'Buffer'.
    peekPtr :: Ptr (Buffer io) -> IO CSize
    peekPtr :: forall io. Ptr (Buffer io) -> IO CSize
    peekPtr Ptr (Buffer io)
    p = ((\Ptr (Buffer io)
    hsc_ptr -> Ptr (Buffer io) -> Int -> IO CSize
    forall b. Ptr b -> Int -> IO CSize
    forall a b. Storable a => Ptr b -> Int -> IO a
    peekByteOff Ptr (Buffer io)
    hsc_ptr Int
    0)) Ptr (Buffer io)
    p
    {-# LINE 94 "Codec/Compression/Zstd/FFI/Types.hsc" #-}

    -- | Write to the 'bufPtr' value in a 'Buffer'.
    pokePtr :: Ptr (Buffer io) -> Ptr a -> IO ()
    pokePtr :: forall io a. Ptr (Buffer io) -> Ptr a -> IO ()
    pokePtr Ptr (Buffer io)
    dst Ptr a
    p = ((\Ptr (Buffer io)
    hsc_ptr -> Ptr (Buffer io) -> Int -> Ptr a -> IO ()
    forall b. Ptr b -> Int -> Ptr a -> IO ()
    forall a b. Storable a => Ptr b -> Int -> a -> IO ()
    pokeByteOff Ptr (Buffer io)
    hsc_ptr Int
    0)) Ptr (Buffer io)
    dst Ptr a
    p
    {-# LINE 98 "Codec/Compression/Zstd/FFI/Types.hsc" #-}

    -- | Read the 'bufSize' value from a 'Buffer'.
    peekSize :: Ptr (Buffer io) -> IO CSize
    peekSize :: forall io. Ptr (Buffer io) -> IO CSize
    peekSize Ptr (Buffer io)
    p = ((\Ptr (Buffer io)
    hsc_ptr -> Ptr (Buffer io) -> Int -> IO CSize
    forall b. Ptr b -> Int -> IO CSize
    forall a b. Storable a => Ptr b -> Int -> IO a
    peekByteOff Ptr (Buffer io)
    hsc_ptr Int
    8)) Ptr (Buffer io)
    p
    {-# LINE 102 "Codec/Compression/Zstd/FFI/Types.hsc" #-}

    -- | Write to the 'bufSize' value in a 'Buffer'.
    pokeSize :: Ptr (Buffer io) -> CSize -> IO ()
    pokeSize :: forall io. Ptr (Buffer io) -> CSize -> IO ()
    pokeSize Ptr (Buffer io)
    dst CSize
    s = ((\Ptr (Buffer io)
    hsc_ptr -> Ptr (Buffer io) -> Int -> CSize -> IO ()
    forall b. Ptr b -> Int -> CSize -> IO ()
    forall a b. Storable a => Ptr b -> Int -> a -> IO ()
    pokeByteOff Ptr (Buffer io)
    hsc_ptr Int
    8)) Ptr (Buffer io)
    dst CSize
    s
    {-# LINE 106 "Codec/Compression/Zstd/FFI/Types.hsc" #-}

    -- | Read the 'bufPos' value from a 'Buffer'.
    peekPos :: Ptr (Buffer io) -> IO CSize
    peekPos :: forall io. Ptr (Buffer io) -> IO CSize
    peekPos Ptr (Buffer io)
    p = ((\Ptr (Buffer io)
    hsc_ptr -> Ptr (Buffer io) -> Int -> IO CSize
    forall b. Ptr b -> Int -> IO CSize
    forall a b. Storable a => Ptr b -> Int -> IO a
    peekByteOff Ptr (Buffer io)
    hsc_ptr Int
    16)) Ptr (Buffer io)
    p
    {-# LINE 110 "Codec/Compression/Zstd/FFI/Types.hsc" #-}

    -- | Write to the 'bufPos' value in a 'Buffer'.
    pokePos :: Ptr (Buffer io) -> CSize -> IO ()
    pokePos :: forall io. Ptr (Buffer io) -> CSize -> IO ()
    pokePos Ptr (Buffer io)
    dst CSize
    s = ((\Ptr (Buffer io)
    hsc_ptr -> Ptr (Buffer io) -> Int -> CSize -> IO ()
    forall b. Ptr b -> Int -> CSize -> IO ()
    forall a b. Storable a => Ptr b -> Int -> a -> IO ()
    pokeByteOff Ptr (Buffer io)
    hsc_ptr Int
    16)) Ptr (Buffer io)
    dst CSize
    s
    {-# LINE 114 "Codec/Compression/Zstd/FFI/Types.hsc" #-}