{-# LANGUAGE DeriveGeneric #-} {-# LANGUAGE DeriveAnyClass #-} {-# LANGUAGE DataKinds #-} {-# LANGUAGE GADTs #-} {-# LANGUAGE TypeApplications #-} {-# 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.Class as HsProtobuf import qualified Proto3.Suite.DotProto as HsProtobuf import qualified Proto3.Suite.JSONPB as HsJSONPB import Proto3.Suite.JSONPB ((.=), (.:)) import qualified Proto3.Suite.Types as HsProtobuf import qualified Proto3.Wire as HsProtobuf import qualified Control.Applicative as Hs import Control.Applicative ((<*>), (<|>), (<$>)) import qualified Control.DeepSeq as Hs import qualified Control.Monad as Hs import qualified Data.ByteString as Hs import qualified Data.Coerce as Hs import qualified Data.Int as Hs (Int16, Int32, Int64) import qualified Data.List.NonEmpty as Hs (NonEmpty(..)) import qualified Data.Map as Hs (Map, mapKeysMonotonic) import qualified Data.Proxy as Proxy import qualified Data.String as Hs (fromString) import qualified Data.Text.Lazy as Hs (Text) import qualified Data.Vector as Hs (Vector) import qualified Data.Word as Hs (Word16, Word32, Word64) import qualified GHC.Enum as Hs import qualified GHC.Generics as Hs import qualified Unsafe.Coerce as Hs data AMessage = AMessage{amessageX :: Hs.Text, amessageY :: Hs.Int32} deriving (Hs.Show, Hs.Eq, Hs.Ord, Hs.Generic, Hs.NFData) instance HsProtobuf.Named AMessage where nameOf _ = (Hs.fromString "AMessage") instance HsProtobuf.HasDefault AMessage instance HsProtobuf.Message AMessage where encodeMessage _ AMessage{amessageX = amessageX, amessageY = amessageY} = (Hs.mconcat [(HsProtobuf.encodeMessageField (HsProtobuf.FieldNumber 1) amessageX), (HsProtobuf.encodeMessageField (HsProtobuf.FieldNumber 2) amessageY)]) decodeMessage _ = (Hs.pure AMessage) <*> (HsProtobuf.at HsProtobuf.decodeMessageField (HsProtobuf.FieldNumber 1)) <*> (HsProtobuf.at HsProtobuf.decodeMessageField (HsProtobuf.FieldNumber 2)) dotProto _ = [(HsProtobuf.DotProtoField (HsProtobuf.FieldNumber 1) (HsProtobuf.Prim HsProtobuf.String) (HsProtobuf.Single "x") [] ""), (HsProtobuf.DotProtoField (HsProtobuf.FieldNumber 2) (HsProtobuf.Prim HsProtobuf.Int32) (HsProtobuf.Single "y") [] "")] instance HsJSONPB.ToJSONPB AMessage where toJSONPB (AMessage f1 f2) = (HsJSONPB.object ["x" .= f1, "y" .= f2]) toEncodingPB (AMessage f1 f2) = (HsJSONPB.pairs ["x" .= f1, "y" .= f2]) instance HsJSONPB.FromJSONPB AMessage where parseJSONPB = (HsJSONPB.withObject "AMessage" (\ obj -> (Hs.pure AMessage) <*> obj .: "x" <*> obj .: "y")) instance HsJSONPB.ToJSON AMessage where toJSON = HsJSONPB.toAesonValue toEncoding = HsJSONPB.toAesonEncoding instance HsJSONPB.FromJSON AMessage where parseJSON = HsJSONPB.parseJSONPB instance HsJSONPB.ToSchema AMessage where declareNamedSchema _ = do let declare_x = HsJSONPB.declareSchemaRef amessageX <- declare_x Proxy.Proxy let declare_y = HsJSONPB.declareSchemaRef amessageY <- declare_y Proxy.Proxy let _ = Hs.pure AMessage <*> HsJSONPB.asProxy declare_x <*> HsJSONPB.asProxy declare_y Hs.return (HsJSONPB.NamedSchema{HsJSONPB._namedSchemaName = Hs.Just "AMessage", HsJSONPB._namedSchemaSchema = Hs.mempty{HsJSONPB._schemaParamSchema = Hs.mempty{HsJSONPB._paramSchemaType = Hs.Just HsJSONPB.SwaggerObject}, HsJSONPB._schemaProperties = HsJSONPB.insOrdFromList [("x", amessageX), ("y", amessageY)]}}) newtype WithOneof = WithOneof{withOneofPickOne :: Hs.Maybe WithOneofPickOne} deriving (Hs.Show, Hs.Eq, Hs.Ord, Hs.Generic, Hs.NFData) instance HsProtobuf.Named WithOneof where nameOf _ = (Hs.fromString "WithOneof") instance HsProtobuf.HasDefault 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)) WithOneofPickOneC y -> (HsProtobuf.encodeMessageField (HsProtobuf.FieldNumber 3) (Hs.coerce @(Hs.Maybe TestProtoOneofImport.AMessage) @(HsProtobuf.Nested TestProtoOneofImport.AMessage) (Hs.Just 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), ((HsProtobuf.FieldNumber 3), (Hs.pure (Hs.fmap WithOneofPickOneC)) <*> (Hs.coerce @(_ (HsProtobuf.Nested TestProtoOneofImport.AMessage)) @(_ (Hs.Maybe TestProtoOneofImport.AMessage)) HsProtobuf.decodeMessageField))]) dotProto _ = [] instance HsJSONPB.ToJSONPB WithOneof where toJSONPB (WithOneof f1_or_f2_or_f3) = (HsJSONPB.object [(let encodePickOne = (case f1_or_f2_or_f3 of Hs.Just (WithOneofPickOneA f1) -> (HsJSONPB.pair "a" f1) Hs.Just (WithOneofPickOneB f2) -> (HsJSONPB.pair "b" f2) Hs.Just (WithOneofPickOneC f3) -> (HsJSONPB.pair "c" f3) 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_or_f3) = (HsJSONPB.pairs [(let encodePickOne = (case f1_or_f2_or_f3 of Hs.Just (WithOneofPickOneA f1) -> (HsJSONPB.pair "a" f1) Hs.Just (WithOneofPickOneB f2) -> (HsJSONPB.pair "b" f2) Hs.Just (WithOneofPickOneC f3) -> (HsJSONPB.pair "c" f3) 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.Just Hs.. WithOneofPickOneC <$> (HsJSONPB.parseField parseObj "c"), 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 = Hs.Just HsJSONPB.SwaggerObject}, HsJSONPB._schemaProperties = HsJSONPB.insOrdFromList [("pickOne", withOneofPickOne)]}}) data WithOneofPickOne = WithOneofPickOneA Hs.Text | WithOneofPickOneB Hs.Int32 | WithOneofPickOneC TestProtoOneofImport.AMessage deriving (Hs.Show, Hs.Eq, Hs.Ord, Hs.Generic, Hs.NFData) 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 let declare_c = HsJSONPB.declareSchemaRef withOneofPickOneC <- declare_c Proxy.Proxy let _ = Hs.pure WithOneofPickOneC <*> HsJSONPB.asProxy declare_c Hs.return (HsJSONPB.NamedSchema{HsJSONPB._namedSchemaName = Hs.Just "WithOneofPickOne", HsJSONPB._namedSchemaSchema = Hs.mempty{HsJSONPB._schemaParamSchema = Hs.mempty{HsJSONPB._paramSchemaType = Hs.Just HsJSONPB.SwaggerObject}, HsJSONPB._schemaProperties = HsJSONPB.insOrdFromList [("a", withOneofPickOneA), ("b", withOneofPickOneB), ("c", withOneofPickOneC)], HsJSONPB._schemaMinProperties = Hs.Just 1, HsJSONPB._schemaMaxProperties = Hs.Just 1}})