packages feed

proto3-suite-0.3.0.0: gen/TestProtoOneofImport.hs

{-# LANGUAGE DeriveGeneric     #-}
{-# LANGUAGE DataKinds         #-}
{-# LANGUAGE GADTs             #-}
{-# LANGUAGE OverloadedStrings #-}
{-# OPTIONS_GHC -fno-warn-unused-imports #-}
{-# OPTIONS_GHC -fno-warn-name-shadowing #-}
{-# OPTIONS_GHC -fno-warn-unused-matches #-}

-- | Generated by Haskell protocol buffer compiler. DO NOT EDIT!
module TestProtoOneofImport where
import qualified Prelude as Hs
import qualified Proto3.Suite.DhallPB as HsDhallPb
import qualified Proto3.Suite.DotProto as HsProtobuf
import qualified Proto3.Suite.Types as HsProtobuf
import qualified Proto3.Suite.Class as HsProtobuf
import qualified Proto3.Suite.JSONPB as HsJSONPB
import Proto3.Suite.JSONPB ((.=), (.:))
import qualified Proto3.Wire as HsProtobuf
import Control.Applicative ((<*>), (<|>), (<$>))
import qualified Control.Applicative as Hs
import qualified Control.Monad as Hs
import qualified Data.Text.Lazy as Hs (Text)
import qualified Data.ByteString as Hs
import qualified Data.String as Hs (fromString)
import qualified Data.Vector as Hs (Vector)
import qualified Data.Int as Hs (Int16, Int32, Int64)
import qualified Data.Word as Hs (Word16, Word32, Word64)
import qualified Data.Proxy as Proxy
import qualified GHC.Generics as Hs
import qualified GHC.Enum as Hs
 
data WithOneof = WithOneof{withOneofPickOne ::
                           Hs.Maybe WithOneofPickOne}
               deriving (Hs.Show, Hs.Eq, Hs.Ord, Hs.Generic)
 
instance HsProtobuf.Named WithOneof where
        nameOf _ = (Hs.fromString "WithOneof")
 
instance HsProtobuf.Message WithOneof where
        encodeMessage _ WithOneof{withOneofPickOne = withOneofPickOne}
          = (Hs.mconcat
               [case withOneofPickOne of
                    Hs.Nothing -> Hs.mempty
                    Hs.Just x
                      -> case x of
                             WithOneofPickOneA y
                               -> (HsProtobuf.encodeMessageField (HsProtobuf.FieldNumber 1)
                                     (HsProtobuf.ForceEmit y))
                             WithOneofPickOneB y
                               -> (HsProtobuf.encodeMessageField (HsProtobuf.FieldNumber 2)
                                     (HsProtobuf.ForceEmit y))])
        decodeMessage _
          = (Hs.pure WithOneof) <*>
              (HsProtobuf.oneof Hs.Nothing
                 [((HsProtobuf.FieldNumber 1),
                   (Hs.pure (Hs.Just Hs.. WithOneofPickOneA)) <*>
                     HsProtobuf.decodeMessageField),
                  ((HsProtobuf.FieldNumber 2),
                   (Hs.pure (Hs.Just Hs.. WithOneofPickOneB)) <*>
                     HsProtobuf.decodeMessageField)])
        dotProto _ = []
 
instance HsJSONPB.ToJSONPB WithOneof where
        toJSONPB (WithOneof f1_or_f2)
          = (HsJSONPB.object
               [(let encodePickOne
                       = (case f1_or_f2 of
                              Hs.Just (WithOneofPickOneA f1) -> (HsJSONPB.pair "a" f1)
                              Hs.Just (WithOneofPickOneB f2) -> (HsJSONPB.pair "b" f2)
                              Hs.Nothing -> Hs.mempty)
                   in
                   \ options ->
                     if HsJSONPB.optEmitNamedOneof options then
                       ("pickOne" .= (HsJSONPB.objectOrNull [encodePickOne] options))
                         options
                       else encodePickOne options)])
        toEncodingPB (WithOneof f1_or_f2)
          = (HsJSONPB.pairs
               [(let encodePickOne
                       = (case f1_or_f2 of
                              Hs.Just (WithOneofPickOneA f1) -> (HsJSONPB.pair "a" f1)
                              Hs.Just (WithOneofPickOneB f2) -> (HsJSONPB.pair "b" f2)
                              Hs.Nothing -> Hs.mempty)
                   in
                   \ options ->
                     if HsJSONPB.optEmitNamedOneof options then
                       ("pickOne" .= (HsJSONPB.pairsOrNull [encodePickOne] options))
                         options
                       else encodePickOne options)])
 
instance HsJSONPB.FromJSONPB WithOneof where
        parseJSONPB
          = (HsJSONPB.withObject "WithOneof"
               (\ obj ->
                  (Hs.pure WithOneof) <*>
                    (let parsePickOne parseObj
                           = Hs.msum
                               [Hs.Just Hs.. WithOneofPickOneA <$>
                                  (HsJSONPB.parseField parseObj "a"),
                                Hs.Just Hs.. WithOneofPickOneB <$>
                                  (HsJSONPB.parseField parseObj "b"),
                                Hs.pure Hs.Nothing]
                       in
                       ((obj .: "pickOne") Hs.>>=
                          (HsJSONPB.withObject "pickOne" parsePickOne))
                         <|> (parsePickOne obj))))
 
instance HsJSONPB.ToJSON WithOneof where
        toJSON = HsJSONPB.toAesonValue
        toEncoding = HsJSONPB.toAesonEncoding
 
instance HsJSONPB.FromJSON WithOneof where
        parseJSON = HsJSONPB.parseJSONPB
 
instance HsJSONPB.ToSchema WithOneof where
        declareNamedSchema _
          = do let declare_pickOne = HsJSONPB.declareSchemaRef
               withOneofPickOne <- declare_pickOne Proxy.Proxy
               let _ = Hs.pure WithOneof <*> HsJSONPB.asProxy declare_pickOne
               Hs.return
                 (HsJSONPB.NamedSchema{HsJSONPB._namedSchemaName =
                                         Hs.Just "WithOneof",
                                       HsJSONPB._namedSchemaSchema =
                                         Hs.mempty{HsJSONPB._schemaParamSchema =
                                                     Hs.mempty{HsJSONPB._paramSchemaType =
                                                                 HsJSONPB.SwaggerObject},
                                                   HsJSONPB._schemaProperties =
                                                     HsJSONPB.insOrdFromList
                                                       [("pickOne", withOneofPickOne)]}})
 
instance HsDhallPb.Interpret WithOneof
 
instance HsDhallPb.Inject WithOneof
 
data WithOneofPickOne = WithOneofPickOneA Hs.Text
                      | WithOneofPickOneB Hs.Int32
                      deriving (Hs.Show, Hs.Eq, Hs.Ord, Hs.Generic)
 
instance HsProtobuf.Named WithOneofPickOne where
        nameOf _ = (Hs.fromString "WithOneofPickOne")
 
instance HsJSONPB.ToSchema WithOneofPickOne where
        declareNamedSchema _
          = do let declare_a = HsJSONPB.declareSchemaRef
               withOneofPickOneA <- declare_a Proxy.Proxy
               let _ = Hs.pure WithOneofPickOneA <*> HsJSONPB.asProxy declare_a
               let declare_b = HsJSONPB.declareSchemaRef
               withOneofPickOneB <- declare_b Proxy.Proxy
               let _ = Hs.pure WithOneofPickOneB <*> HsJSONPB.asProxy declare_b
               Hs.return
                 (HsJSONPB.NamedSchema{HsJSONPB._namedSchemaName =
                                         Hs.Just "WithOneofPickOne",
                                       HsJSONPB._namedSchemaSchema =
                                         Hs.mempty{HsJSONPB._schemaParamSchema =
                                                     Hs.mempty{HsJSONPB._paramSchemaType =
                                                                 HsJSONPB.SwaggerObject},
                                                   HsJSONPB._schemaProperties =
                                                     HsJSONPB.insOrdFromList
                                                       [("a", withOneofPickOneA),
                                                        ("b", withOneofPickOneB)],
                                                   HsJSONPB._schemaMinProperties = Hs.Just 1,
                                                   HsJSONPB._schemaMaxProperties = Hs.Just 1}})
 
instance HsDhallPb.Interpret WithOneofPickOne
 
instance HsDhallPb.Inject WithOneofPickOne