{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE OverloadedStrings #-}
{-# OPTIONS_GHC -Wno-unused-imports #-}
{-# OPTIONS_GHC -Wno-dodgy-exports #-}
{-# OPTIONS_GHC -Wno-unused-matches #-}
{-# OPTIONS_GHC -Wno-orphans #-}
{-# OPTIONS_GHC -Wno-unticked-promoted-constructors #-}
{-# OPTIONS_GHC -Wno-name-shadowing #-}
module Capnp.Gen.Capnp.Stream where
import qualified Capnp.Message as Message
import qualified Capnp.Untyped as Untyped
import qualified Capnp.Basics as Basics
import qualified Capnp.GenHelpers as GenHelpers
import qualified Capnp.Classes as Classes
import qualified GHC.Generics as Generics
import qualified Capnp.Bits as Std_
import qualified Data.Maybe as Std_
import qualified Capnp.GenHelpers.ReExports.Data.ByteString as BS
import qualified Prelude as Std_
import qualified Data.Word as Std_
import qualified Data.Int as Std_
import Prelude ((<$>), (<*>), (>>=))
newtype StreamResult msg
    = StreamResult'newtype_ (Untyped.Struct msg)
instance (Classes.FromStruct msg (StreamResult msg)) where
    fromStruct :: Struct msg -> m (StreamResult msg)
fromStruct Struct msg
struct = (StreamResult msg -> m (StreamResult msg)
forall (f :: * -> *) a. Applicative f => a -> f a
Std_.pure (Struct msg -> StreamResult msg
forall (msg :: Mutability). Struct msg -> StreamResult msg
StreamResult'newtype_ Struct msg
struct))
instance (Classes.ToStruct msg (StreamResult msg)) where
    toStruct :: StreamResult msg -> Struct msg
toStruct (StreamResult'newtype_ Struct msg
struct) = Struct msg
struct
instance (Untyped.HasMessage (StreamResult mut) mut) where
    message :: StreamResult mut -> Message mut
message (StreamResult'newtype_ Struct mut
struct) = (Struct mut -> Message mut
forall a (mut :: Mutability). HasMessage a mut => a -> Message mut
Untyped.message Struct mut
struct)
instance (Untyped.MessageDefault (StreamResult mut) mut) where
    messageDefault :: Message mut -> m (StreamResult mut)
messageDefault Message mut
msg = (Struct mut -> StreamResult mut
forall (msg :: Mutability). Struct msg -> StreamResult msg
StreamResult'newtype_ (Struct mut -> StreamResult mut)
-> m (Struct mut) -> m (StreamResult mut)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (Message mut -> m (Struct mut)
forall a (mut :: Mutability) (m :: * -> *).
(MessageDefault a mut, ReadCtx m mut) =>
Message mut -> m a
Untyped.messageDefault Message mut
msg))
instance (Classes.FromPtr msg (StreamResult msg)) where
    fromPtr :: Message msg -> Maybe (Ptr msg) -> m (StreamResult msg)
fromPtr Message msg
msg Maybe (Ptr msg)
ptr = (Struct msg -> StreamResult msg
forall (msg :: Mutability). Struct msg -> StreamResult msg
StreamResult'newtype_ (Struct msg -> StreamResult msg)
-> m (Struct msg) -> m (StreamResult msg)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (Message msg -> Maybe (Ptr msg) -> m (Struct msg)
forall (mut :: Mutability) a (m :: * -> *).
(FromPtr mut a, ReadCtx m mut) =>
Message mut -> Maybe (Ptr mut) -> m a
Classes.fromPtr Message msg
msg Maybe (Ptr msg)
ptr))
instance (Classes.ToPtr s (StreamResult (Message.Mut s))) where
    toPtr :: Message ('Mut s)
-> StreamResult ('Mut s) -> m (Maybe (Ptr ('Mut s)))
toPtr Message ('Mut s)
msg (StreamResult'newtype_ Struct ('Mut s)
struct) = (Message ('Mut s) -> Struct ('Mut s) -> m (Maybe (Ptr ('Mut s)))
forall s a (m :: * -> *).
(ToPtr s a, WriteCtx m s) =>
Message ('Mut s) -> a -> m (Maybe (Ptr ('Mut s)))
Classes.toPtr Message ('Mut s)
msg Struct ('Mut s)
struct)
instance (Classes.Allocate s (StreamResult (Message.Mut s))) where
    new :: Message ('Mut s) -> m (StreamResult ('Mut s))
new Message ('Mut s)
msg = (Struct ('Mut s) -> StreamResult ('Mut s)
forall (msg :: Mutability). Struct msg -> StreamResult msg
StreamResult'newtype_ (Struct ('Mut s) -> StreamResult ('Mut s))
-> m (Struct ('Mut s)) -> m (StreamResult ('Mut s))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (Message ('Mut s) -> Word16 -> Word16 -> m (Struct ('Mut s))
forall (m :: * -> *) s.
WriteCtx m s =>
Message ('Mut s) -> Word16 -> Word16 -> m (Struct ('Mut s))
Untyped.allocStruct Message ('Mut s)
msg Word16
0 Word16
0))
instance (Basics.ListElem mut (StreamResult mut)) where
    newtype List mut (StreamResult mut)
        = StreamResult'List_ (Untyped.ListOf mut (Untyped.Struct mut))
    listFromPtr :: Message mut -> Maybe (Ptr mut) -> m (List mut (StreamResult mut))
listFromPtr Message mut
msg Maybe (Ptr mut)
ptr = (ListOf mut (Struct mut) -> List mut (StreamResult mut)
forall (mut :: Mutability).
ListOf mut (Struct mut) -> List mut (StreamResult mut)
StreamResult'List_ (ListOf mut (Struct mut) -> List mut (StreamResult mut))
-> m (ListOf mut (Struct mut)) -> m (List mut (StreamResult mut))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (Message mut -> Maybe (Ptr mut) -> m (ListOf mut (Struct mut))
forall (mut :: Mutability) a (m :: * -> *).
(FromPtr mut a, ReadCtx m mut) =>
Message mut -> Maybe (Ptr mut) -> m a
Classes.fromPtr Message mut
msg Maybe (Ptr mut)
ptr))
    toUntypedList :: List mut (StreamResult mut) -> List mut
toUntypedList (StreamResult'List_ l) = (ListOf mut (Struct mut) -> List mut
forall (mut :: Mutability). ListOf mut (Struct mut) -> List mut
Untyped.ListStruct ListOf mut (Struct mut)
l)
    length :: List mut (StreamResult mut) -> Int
length (StreamResult'List_ l) = (ListOf mut (Struct mut) -> Int
forall (msg :: Mutability) a. ListOf msg a -> Int
Untyped.length ListOf mut (Struct mut)
l)
    index :: Int -> List mut (StreamResult mut) -> m (StreamResult mut)
index Int
i (StreamResult'List_ l) = (do
        Struct mut
elt <- (Int -> ListOf mut (Struct mut) -> m (Struct mut)
forall (m :: * -> *) (mut :: Mutability) a.
ReadCtx m mut =>
Int -> ListOf mut a -> m a
Untyped.index Int
i ListOf mut (Struct mut)
l)
        (Struct mut -> m (StreamResult mut)
forall (mut :: Mutability) a (m :: * -> *).
(FromStruct mut a, ReadCtx m mut) =>
Struct mut -> m a
Classes.fromStruct Struct mut
elt)
        )
instance (Basics.MutListElem s (StreamResult (Message.Mut s))) where
    setIndex :: StreamResult ('Mut s)
-> Int -> List ('Mut s) (StreamResult ('Mut s)) -> m ()
setIndex (StreamResult'newtype_ Struct ('Mut s)
elt) Int
i (StreamResult'List_ l) = (Struct ('Mut s) -> Int -> ListOf ('Mut s) (Struct ('Mut s)) -> m ()
forall (m :: * -> *) s a.
RWCtx m s =>
a -> Int -> ListOf ('Mut s) a -> m ()
Untyped.setIndex Struct ('Mut s)
elt Int
i ListOf ('Mut s) (Struct ('Mut s))
l)
    newList :: Message ('Mut s)
-> Int -> m (List ('Mut s) (StreamResult ('Mut s)))
newList Message ('Mut s)
msg Int
len = (ListOf ('Mut s) (Struct ('Mut s))
-> List ('Mut s) (StreamResult ('Mut s))
forall (mut :: Mutability).
ListOf mut (Struct mut) -> List mut (StreamResult mut)
StreamResult'List_ (ListOf ('Mut s) (Struct ('Mut s))
 -> List ('Mut s) (StreamResult ('Mut s)))
-> m (ListOf ('Mut s) (Struct ('Mut s)))
-> m (List ('Mut s) (StreamResult ('Mut s)))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (Message ('Mut s)
-> Word16 -> Word16 -> Int -> m (ListOf ('Mut s) (Struct ('Mut s)))
forall (m :: * -> *) s.
WriteCtx m s =>
Message ('Mut s)
-> Word16 -> Word16 -> Int -> m (ListOf ('Mut s) (Struct ('Mut s)))
Untyped.allocCompositeList Message ('Mut s)
msg Word16
0 Word16
0 Int
len))