packages feed

thrift-compiler-0.1.0.1: test/fixtures/gen-hs2/A/Types.hs

-----------------------------------------------------------------
-- Autogenerated by Thrift
--
-- DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING
--  @generated
-----------------------------------------------------------------
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE BangPatterns #-}
{-# OPTIONS_GHC -fno-warn-unused-imports#-}
{-# OPTIONS_GHC -fno-warn-overlapping-patterns#-}
{-# OPTIONS_GHC -fno-warn-incomplete-patterns#-}
{-# OPTIONS_GHC -fno-warn-incomplete-uni-patterns#-}
{-# OPTIONS_GHC -fno-warn-incomplete-record-updates#-}
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
module A.Types
       (T, a, A(A, a_a, a_c, a_d, a_e, a_f, a_g, a_h),
        U(U_EMPTY, U_x, U_y, U_z), X(X, x_reason), u, b, default_d, zero)
       where
import qualified B.Types as B
import qualified Control.DeepSeq as DeepSeq
import qualified Control.Exception as Exception
import qualified Control.Monad as Monad
import qualified Control.Monad.ST.Trans as ST
import qualified Control.Monad.Trans.Class as Trans
import qualified Data.Aeson as Aeson
import qualified Data.Aeson.Types as Aeson
import qualified Data.Default as Default
import qualified Data.HashMap.Strict as HashMap
import qualified Data.Hashable as Hashable
import qualified Data.Int as Int
import qualified Data.List as List
import qualified Data.Map.Strict as Map
import qualified Data.Ord as Ord
import qualified Data.Set as Set
import qualified Data.Text as Text
import qualified Data.Text.Encoding as Text
import qualified Prelude as Prelude
import qualified Thrift.Binary.Parser as Parser
import qualified Thrift.CodegenTypesOnly as Thrift
import Control.Applicative ((<|>), (*>), (<*))
import Data.Aeson ((.:), (.:?), (.=), (.!=))
import Data.Aeson ((.:), (.=))
import Data.Monoid ((<>))
import Prelude ((.), (<$>), (<*>), (>>=), (==), (++))
import Prelude ((.), (<$>), (<*>), (>>=), (==), (/=), (<), (++))

type T = Int.Int64

a :: T
a = B.i64_value

data A = A{a_a :: T, a_c :: Prelude.Bool, a_d :: [[Int.Int32]],
           a_e :: Map.Map Int.Int32 Text.Text, a_f :: B.Number,
           a_g :: Prelude.Maybe Text.Text, a_h :: Text.Text}
         deriving (Prelude.Eq, Prelude.Show, Prelude.Ord)

instance Aeson.ToJSON A where
  toJSON
    (A __field__a __field__c __field__d __field__e __field__f
       __field__g __field__h)
    = Aeson.object
        ("a" .= __field__a :
           "c" .= __field__c :
             "d" .= __field__d :
               "e" .= Map.mapKeys Thrift.keyToStr __field__e :
                 "f" .= __field__f :
                   Prelude.maybe Prelude.id ((:) . ("g" .=)) __field__g
                     ("h" .= __field__h : Prelude.mempty))

instance Thrift.ThriftStruct A where
  buildStruct _proxy
    (A __field__a __field__c __field__d __field__e __field__f
       __field__g __field__h)
    = Thrift.genStruct _proxy
        (Thrift.genField _proxy "a" (Thrift.getI64Type _proxy) 1 0
           (Thrift.genI64 _proxy __field__a)
           :
           Thrift.genFieldBool _proxy "c" 3 1 __field__c :
             Thrift.genField _proxy "d" (Thrift.getListType _proxy) 4 3
               (Thrift.genList _proxy (Thrift.getListType _proxy)
                  (Thrift.genListPrim _proxy (Thrift.getI32Type _proxy)
                     (Thrift.genI32Prim _proxy))
                  __field__d)
               :
               Thrift.genField _proxy "e" (Thrift.getMapType _proxy) 5 4
                 ((Thrift.genMap _proxy (Thrift.getI32Type _proxy)
                     (Thrift.getStringType _proxy)
                     Prelude.False
                     (Thrift.genI32 _proxy)
                     (Thrift.genText _proxy)
                     . Map.toList)
                    __field__e)
                 :
                 Thrift.genField _proxy "f" (Thrift.getI32Type _proxy) 6 5
                   ((Thrift.genI32 _proxy . Prelude.fromIntegral .
                       Thrift.fromThriftEnum)
                      __field__f)
                   :
                   let (__cereal__g, __id__g)
                         = case __field__g of
                             Prelude.Just _val -> ((:)
                                                     (Thrift.genField _proxy "g"
                                                        (Thrift.getStringType _proxy)
                                                        7
                                                        6
                                                        (Thrift.genText _proxy _val)),
                                                   7)
                             Prelude.Nothing -> (Prelude.id, 6)
                     in
                     __cereal__g
                       (Thrift.genField _proxy "h" (Thrift.getStringType _proxy) 8 __id__g
                          (Thrift.genText _proxy __field__h)
                          : []))
  parseStruct _proxy
    = ST.runSTT
        (do Prelude.return ()
            __field__a <- ST.newSTRef a
            __field__c <- ST.newSTRef B.bool_value
            __field__d <- ST.newSTRef Default.def
            __field__e <- ST.newSTRef Default.def
            __field__f <- ST.newSTRef B.Number_Two
            __field__g <- ST.newSTRef Prelude.Nothing
            __field__h <- ST.newSTRef Prelude.Nothing
            let
              _parse _lastId
                = do _fieldBegin <- Trans.lift
                                      (Thrift.parseFieldBegin _proxy _lastId _idMap)
                     case _fieldBegin of
                       Thrift.FieldBegin _type _id _bool -> do case _id of
                                                                 1 | _type ==
                                                                       Thrift.getI64Type _proxy
                                                                     ->
                                                                     do !_val <- Trans.lift
                                                                                   (Thrift.parseI64
                                                                                      _proxy)
                                                                        ST.writeSTRef __field__a
                                                                          _val
                                                                 3 | _type ==
                                                                       Thrift.getBoolType _proxy
                                                                     ->
                                                                     do !_val <- Trans.lift
                                                                                   (Thrift.parseBoolF
                                                                                      _proxy
                                                                                      _bool)
                                                                        ST.writeSTRef __field__c
                                                                          _val
                                                                 4 | _type ==
                                                                       Thrift.getListType _proxy
                                                                     ->
                                                                     do !_val <- Trans.lift
                                                                                   (Prelude.snd <$>
                                                                                      Thrift.parseList
                                                                                        _proxy
                                                                                        (Prelude.snd
                                                                                           <$>
                                                                                           Thrift.parseList
                                                                                             _proxy
                                                                                             (Thrift.parseI32
                                                                                                _proxy)))
                                                                        ST.writeSTRef __field__d
                                                                          _val
                                                                 5 | _type ==
                                                                       Thrift.getMapType _proxy
                                                                     ->
                                                                     do !_val <- Trans.lift
                                                                                   (Map.fromList <$>
                                                                                      Thrift.parseMap
                                                                                        _proxy
                                                                                        (Thrift.parseI32
                                                                                           _proxy)
                                                                                        (Thrift.parseText
                                                                                           _proxy)
                                                                                        Prelude.False)
                                                                        ST.writeSTRef __field__e
                                                                          _val
                                                                 6 | _type ==
                                                                       Thrift.getI32Type _proxy
                                                                     ->
                                                                     do !_val <- Trans.lift
                                                                                   (Thrift.parseEnum
                                                                                      _proxy
                                                                                      "Number")
                                                                        ST.writeSTRef __field__f
                                                                          _val
                                                                 7 | _type ==
                                                                       Thrift.getStringType _proxy
                                                                     ->
                                                                     do !_val <- Trans.lift
                                                                                   (Thrift.parseText
                                                                                      _proxy)
                                                                        ST.writeSTRef __field__g
                                                                          (Prelude.Just _val)
                                                                 8 | _type ==
                                                                       Thrift.getStringType _proxy
                                                                     ->
                                                                     do !_val <- Trans.lift
                                                                                   (Thrift.parseText
                                                                                      _proxy)
                                                                        ST.writeSTRef __field__h
                                                                          (Prelude.Just _val)
                                                                 _ -> Trans.lift
                                                                        (Thrift.parseSkip _proxy
                                                                           _type
                                                                           (Prelude.Just _bool))
                                                               _parse _id
                       Thrift.FieldEnd -> do !__val__a <- ST.readSTRef __field__a
                                             !__val__c <- ST.readSTRef __field__c
                                             !__val__d <- ST.readSTRef __field__d
                                             !__val__e <- ST.readSTRef __field__e
                                             !__val__f <- ST.readSTRef __field__f
                                             !__val__g <- ST.readSTRef __field__g
                                             !__maybe__h <- ST.readSTRef __field__h
                                             case __maybe__h of
                                               Prelude.Nothing -> Prelude.fail
                                                                    "Error parsing type A: missing required field h of type Text.Text"
                                               Prelude.Just __val__h -> Prelude.pure
                                                                          (A __val__a __val__c
                                                                             __val__d
                                                                             __val__e
                                                                             __val__f
                                                                             __val__g
                                                                             __val__h)
              _idMap
                = HashMap.fromList
                    [("a", 1), ("c", 3), ("d", 4), ("e", 5), ("f", 6), ("g", 7),
                     ("h", 8)]
            _parse 0)

instance DeepSeq.NFData A where
  rnf
    (A __field__a __field__c __field__d __field__e __field__f
       __field__g __field__h)
    = DeepSeq.rnf __field__a `Prelude.seq`
        DeepSeq.rnf __field__c `Prelude.seq`
          DeepSeq.rnf __field__d `Prelude.seq`
            DeepSeq.rnf __field__e `Prelude.seq`
              DeepSeq.rnf __field__f `Prelude.seq`
                DeepSeq.rnf __field__g `Prelude.seq`
                  DeepSeq.rnf __field__h `Prelude.seq` ()

instance Default.Default A where
  def
    = A a B.bool_value Default.def Default.def B.Number_Two
        Prelude.Nothing
        ""

instance Hashable.Hashable A where
  hashWithSalt __salt (A _a _c _d _e _f _g _h)
    = Hashable.hashWithSalt
        (Hashable.hashWithSalt
           (Hashable.hashWithSalt
              (Hashable.hashWithSalt
                 (Hashable.hashWithSalt
                    (Hashable.hashWithSalt (Hashable.hashWithSalt __salt _a) _c)
                    _d)
                 ((Prelude.map (\ (_k, _v) -> (_k, _v)) . Map.toAscList) _e))
              _f)
           _g)
        _h

data U = U_x Int.Int8
       | U_y [Text.Text]
       | U_z (Set.Set Int.Int64)
       | U_EMPTY
         deriving (Prelude.Eq, Prelude.Show, Prelude.Ord)

instance Aeson.ToJSON U where
  toJSON (U_x __x) = Aeson.object ["x" .= __x]
  toJSON (U_y __y) = Aeson.object ["y" .= __y]
  toJSON (U_z __z) = Aeson.object ["z" .= __z]
  toJSON U_EMPTY = Aeson.object []

instance Thrift.ThriftStruct U where
  buildStruct _proxy (U_x __x)
    = Thrift.genStruct _proxy
        [Thrift.genFieldPrim _proxy "x" (Thrift.getByteType _proxy) 1 0
           (Thrift.genBytePrim _proxy)
           __x]
  buildStruct _proxy (U_y __y)
    = Thrift.genStruct _proxy
        [Thrift.genField _proxy "y" (Thrift.getListType _proxy) 2 0
           (Thrift.genList _proxy (Thrift.getStringType _proxy)
              (Thrift.genText _proxy)
              __y)]
  buildStruct _proxy (U_z __z)
    = Thrift.genStruct _proxy
        [Thrift.genField _proxy "z" (Thrift.getSetType _proxy) 3 0
           ((Thrift.genListPrim _proxy (Thrift.getI64Type _proxy)
               (Thrift.genI64Prim _proxy)
               . Set.toList)
              __z)]
  buildStruct _proxy U_EMPTY = Thrift.genStruct _proxy []
  parseStruct _proxy
    = do _fieldBegin <- Thrift.parseFieldBegin _proxy 0 _idMap
         case _fieldBegin of
           Thrift.FieldBegin _type _id _bool -> do case _id of
                                                     1 | _type == Thrift.getByteType _proxy ->
                                                         do _val <- Thrift.parseByte _proxy
                                                            Thrift.parseStop _proxy
                                                            Prelude.return (U_x _val)
                                                     2 | _type == Thrift.getListType _proxy ->
                                                         do _val <- Prelude.snd <$>
                                                                      Thrift.parseList _proxy
                                                                        (Thrift.parseText _proxy)
                                                            Thrift.parseStop _proxy
                                                            Prelude.return (U_y _val)
                                                     3 | _type == Thrift.getSetType _proxy ->
                                                         do _val <- Set.fromList . Prelude.snd <$>
                                                                      Thrift.parseList _proxy
                                                                        (Thrift.parseI64 _proxy)
                                                            Thrift.parseStop _proxy
                                                            Prelude.return (U_z _val)
                                                     _ -> do Thrift.parseSkip _proxy _type
                                                               Prelude.Nothing
                                                             Thrift.parseStop _proxy
                                                             Prelude.return U_EMPTY
           Thrift.FieldEnd -> Prelude.return U_EMPTY
    where
      _idMap = HashMap.fromList [("x", 1), ("y", 2), ("z", 3)]

instance DeepSeq.NFData U where
  rnf (U_x __x) = DeepSeq.rnf __x
  rnf (U_y __y) = DeepSeq.rnf __y
  rnf (U_z __z) = DeepSeq.rnf __z
  rnf U_EMPTY = ()

instance Default.Default U where
  def = U_EMPTY

instance Hashable.Hashable U where
  hashWithSalt __salt (U_x _x)
    = Hashable.hashWithSalt __salt (Hashable.hashWithSalt 1 _x)
  hashWithSalt __salt (U_y _y)
    = Hashable.hashWithSalt __salt (Hashable.hashWithSalt 2 _y)
  hashWithSalt __salt (U_z _z)
    = Hashable.hashWithSalt __salt
        (Hashable.hashWithSalt 3 (Set.elems _z))
  hashWithSalt __salt U_EMPTY
    = Hashable.hashWithSalt __salt (0 :: Prelude.Int)

newtype X = X{x_reason :: Text.Text}
            deriving (Prelude.Eq, Prelude.Show, Prelude.Ord)

instance Aeson.ToJSON X where
  toJSON (X __field__reason)
    = Aeson.object ("reason" .= __field__reason : Prelude.mempty)

instance Thrift.ThriftStruct X where
  buildStruct _proxy (X __field__reason)
    = Thrift.genStruct _proxy
        (Thrift.genField _proxy "reason" (Thrift.getStringType _proxy) 1 0
           (Thrift.genText _proxy __field__reason)
           : [])
  parseStruct _proxy
    = ST.runSTT
        (do Prelude.return ()
            __field__reason <- ST.newSTRef ""
            let
              _parse _lastId
                = do _fieldBegin <- Trans.lift
                                      (Thrift.parseFieldBegin _proxy _lastId _idMap)
                     case _fieldBegin of
                       Thrift.FieldBegin _type _id _bool -> do case _id of
                                                                 1 | _type ==
                                                                       Thrift.getStringType _proxy
                                                                     ->
                                                                     do !_val <- Trans.lift
                                                                                   (Thrift.parseText
                                                                                      _proxy)
                                                                        ST.writeSTRef
                                                                          __field__reason
                                                                          _val
                                                                 _ -> Trans.lift
                                                                        (Thrift.parseSkip _proxy
                                                                           _type
                                                                           (Prelude.Just _bool))
                                                               _parse _id
                       Thrift.FieldEnd -> do !__val__reason <- ST.readSTRef
                                                                 __field__reason
                                             Prelude.pure (X __val__reason)
              _idMap = HashMap.fromList [("reason", 1)]
            _parse 0)

instance DeepSeq.NFData X where
  rnf (X __field__reason)
    = DeepSeq.rnf __field__reason `Prelude.seq` ()

instance Default.Default X where
  def = X ""

instance Hashable.Hashable X where
  hashWithSalt __salt (X _reason)
    = Hashable.hashWithSalt __salt _reason

instance Exception.Exception X

u :: U
u = U_y [B.string_value]

b :: B.B
b = (Default.def :: B.B){B.b_a = B.i16_value, B.b_b = B.i32_value,
                         B.b_c = B.i64_value}

default_d :: B.B
default_d = Default.def :: B.B

zero :: B.Number
zero = B.Number_Zero