module Network.AMQP.Generated where
import Data.Binary
import Data.Binary.Get
import Data.Binary.Put
import Data.Bits
import Data.Maybe
import Network.AMQP.Types
getContentHeaderProperties :: ShortInt -> Get ContentHeaderProperties
getContentHeaderProperties 10 = getPropBits 0 >>= \[] -> return CHConnection
getContentHeaderProperties 20 = getPropBits 0 >>= \[] -> return CHChannel
getContentHeaderProperties 40 = getPropBits 0 >>= \[] -> return CHExchange
getContentHeaderProperties 50 = getPropBits 0 >>= \[] -> return CHQueue
getContentHeaderProperties 60 = getPropBits 14 >>= \[a,b,c,d,e,f,g,h,i,j,k,l,m,n] -> condGet a >>= \a' -> condGet b >>= \b' -> condGet c >>= \c' -> condGet d >>= \d' -> condGet e >>= \e' -> condGet f >>= \f' -> condGet g >>= \g' -> condGet h >>= \h' -> condGet i >>= \i' -> condGet j >>= \j' -> condGet k >>= \k' -> condGet l >>= \l' -> condGet m >>= \m' -> condGet n >>= \n' -> return (CHBasic a' b' c' d' e' f' g' h' i' j' k' l' m' n' )
getContentHeaderProperties 90 = getPropBits 0 >>= \[] -> return CHTx
getContentHeaderProperties 85 = getPropBits 0 >>= \[] -> return CHConfirm
getContentHeaderProperties n = error ("Unexpected content header properties: " ++ show n)
putContentHeaderProperties :: ContentHeaderProperties -> Put
putContentHeaderProperties CHConnection = putPropBits []
putContentHeaderProperties CHChannel = putPropBits []
putContentHeaderProperties CHExchange = putPropBits []
putContentHeaderProperties CHQueue = putPropBits []
putContentHeaderProperties (CHBasic a b c d e f g h i j k l m n) = putPropBits [isJust a,isJust b,isJust c,isJust d,isJust e,isJust f,isJust g,isJust h,isJust i,isJust j,isJust k,isJust l,isJust m,isJust n] >> condPut a >> condPut b >> condPut c >> condPut d >> condPut e >> condPut f >> condPut g >> condPut h >> condPut i >> condPut j >> condPut k >> condPut l >> condPut m >> condPut n
putContentHeaderProperties CHTx = putPropBits []
putContentHeaderProperties CHConfirm = putPropBits []
getClassIDOf :: ContentHeaderProperties -> ShortInt
getClassIDOf (CHConnection) = 10
getClassIDOf (CHChannel) = 20
getClassIDOf (CHExchange) = 40
getClassIDOf (CHQueue) = 50
getClassIDOf (CHBasic _ _ _ _ _ _ _ _ _ _ _ _ _ _) = 60
getClassIDOf (CHTx) = 90
getClassIDOf (CHConfirm) = 85
data ContentHeaderProperties =
CHConnection
|CHChannel
|CHExchange
|CHQueue
|CHBasic
(Maybe ShortString)
(Maybe ShortString)
(Maybe FieldTable)
(Maybe Octet)
(Maybe Octet)
(Maybe ShortString)
(Maybe ShortString)
(Maybe ShortString)
(Maybe ShortString)
(Maybe Timestamp)
(Maybe ShortString)
(Maybe ShortString)
(Maybe ShortString)
(Maybe ShortString)
|CHTx
|CHConfirm
deriving Show
putBits :: [Bit] -> Put
putBits = putWord8 . putBits' 0
putBits' :: Int -> [Bit] -> Word8
putBits' _ [] = 0
putBits' offset (x:xs) = (shiftL (toInt x) offset) .|. (putBits' (offset+1) xs)
where toInt True = 1
toInt False = 0
getBits :: Int -> Get [Bit]
getBits num = getWord8 >>= return . getBits' num 0
getBits' :: Int -> Int -> Word8 -> [Bit]
getBits' 0 _ _ = []
getBits' num offset x = ((x .&. (2^offset)) /= 0) : (getBits' (num-1) (offset+1) x)
putPropBits :: [Bit] -> Put
putPropBits = putWord16be . putPropBits' 0
putPropBits' :: Int -> [Bit] -> Word16
putPropBits' _ [] = 0
putPropBits' offset (x:xs) = (shiftL (toInt x) (15-offset)) .|. (putPropBits' (offset+1) xs)
where toInt True = 1
toInt False = 0
getPropBits :: Int -> Get [Bit]
getPropBits num = getWord16be >>= return . getPropBits' num 0
getPropBits' :: Int -> Int -> Word16 -> [Bit]
getPropBits' 0 _ _ = []
getPropBits' num offset x = ((x .&. (2^(15-offset))) /= 0) : (getPropBits' (num-1) (offset+1) x)
condGet :: Binary a => Bool -> Get (Maybe a)
condGet False = return Nothing
condGet True = get >>= return . Just
condPut :: Binary a => Maybe a -> Put
condPut = maybe (return ()) put
instance Binary MethodPayload where
put (Connection_start a b c d e) = putWord16be 10 >> putWord16be 10 >> put a >> put b >> put c >> put d >> put e
put (Connection_start_ok a b c d) = putWord16be 10 >> putWord16be 11 >> put a >> put b >> put c >> put d
put (Connection_secure a) = putWord16be 10 >> putWord16be 20 >> put a
put (Connection_secure_ok a) = putWord16be 10 >> putWord16be 21 >> put a
put (Connection_tune a b c) = putWord16be 10 >> putWord16be 30 >> put a >> put b >> put c
put (Connection_tune_ok a b c) = putWord16be 10 >> putWord16be 31 >> put a >> put b >> put c
put (Connection_open a b c) = putWord16be 10 >> putWord16be 40 >> put a >> put b >> put c
put (Connection_open_ok a) = putWord16be 10 >> putWord16be 41 >> put a
put (Connection_close a b c d) = putWord16be 10 >> putWord16be 50 >> put a >> put b >> put c >> put d
put Connection_close_ok = putWord16be 10 >> putWord16be 51
put (Connection_blocked a) = putWord16be 10 >> putWord16be 60 >> put a
put Connection_unblocked = putWord16be 10 >> putWord16be 61
put (Channel_open a) = putWord16be 20 >> putWord16be 10 >> put a
put (Channel_open_ok a) = putWord16be 20 >> putWord16be 11 >> put a
put (Channel_flow a) = putWord16be 20 >> putWord16be 20 >> put a
put (Channel_flow_ok a) = putWord16be 20 >> putWord16be 21 >> put a
put (Channel_close a b c d) = putWord16be 20 >> putWord16be 40 >> put a >> put b >> put c >> put d
put Channel_close_ok = putWord16be 20 >> putWord16be 41
put (Exchange_declare a b c d e f g h i) = putWord16be 40 >> putWord16be 10 >> put a >> put b >> put c >> putBits [d,e,f,g,h] >> put i
put Exchange_declare_ok = putWord16be 40 >> putWord16be 11
put (Exchange_delete a b c d) = putWord16be 40 >> putWord16be 20 >> put a >> put b >> putBits [c,d]
put Exchange_delete_ok = putWord16be 40 >> putWord16be 21
put (Exchange_bind a b c d e f) = putWord16be 40 >> putWord16be 30 >> put a >> put b >> put c >> put d >> put e >> put f
put Exchange_bind_ok = putWord16be 40 >> putWord16be 31
put (Exchange_unbind a b c d e f) = putWord16be 40 >> putWord16be 40 >> put a >> put b >> put c >> put d >> put e >> put f
put Exchange_unbind_ok = putWord16be 40 >> putWord16be 51
put (Queue_declare a b c d e f g h) = putWord16be 50 >> putWord16be 10 >> put a >> put b >> putBits [c,d,e,f,g] >> put h
put (Queue_declare_ok a b c) = putWord16be 50 >> putWord16be 11 >> put a >> put b >> put c
put (Queue_bind a b c d e f) = putWord16be 50 >> putWord16be 20 >> put a >> put b >> put c >> put d >> put e >> put f
put Queue_bind_ok = putWord16be 50 >> putWord16be 21
put (Queue_unbind a b c d e) = putWord16be 50 >> putWord16be 50 >> put a >> put b >> put c >> put d >> put e
put Queue_unbind_ok = putWord16be 50 >> putWord16be 51
put (Queue_purge a b c) = putWord16be 50 >> putWord16be 30 >> put a >> put b >> put c
put (Queue_purge_ok a) = putWord16be 50 >> putWord16be 31 >> put a
put (Queue_delete a b c d e) = putWord16be 50 >> putWord16be 40 >> put a >> put b >> putBits [c,d,e]
put (Queue_delete_ok a) = putWord16be 50 >> putWord16be 41 >> put a
put (Basic_qos a b c) = putWord16be 60 >> putWord16be 10 >> put a >> put b >> put c
put Basic_qos_ok = putWord16be 60 >> putWord16be 11
put (Basic_consume a b c d e f g h) = putWord16be 60 >> putWord16be 20 >> put a >> put b >> put c >> putBits [d,e,f,g] >> put h
put (Basic_consume_ok a) = putWord16be 60 >> putWord16be 21 >> put a
put (Basic_cancel a b) = putWord16be 60 >> putWord16be 30 >> put a >> put b
put (Basic_cancel_ok a) = putWord16be 60 >> putWord16be 31 >> put a
put (Basic_publish a b c d e) = putWord16be 60 >> putWord16be 40 >> put a >> put b >> put c >> putBits [d,e]
put (Basic_return a b c d) = putWord16be 60 >> putWord16be 50 >> put a >> put b >> put c >> put d
put (Basic_deliver a b c d e) = putWord16be 60 >> putWord16be 60 >> put a >> put b >> put c >> put d >> put e
put (Basic_get a b c) = putWord16be 60 >> putWord16be 70 >> put a >> put b >> put c
put (Basic_get_ok a b c d e) = putWord16be 60 >> putWord16be 71 >> put a >> put b >> put c >> put d >> put e
put (Basic_get_empty a) = putWord16be 60 >> putWord16be 72 >> put a
put (Basic_ack a b) = putWord16be 60 >> putWord16be 80 >> put a >> put b
put (Basic_reject a b) = putWord16be 60 >> putWord16be 90 >> put a >> put b
put (Basic_recover_async a) = putWord16be 60 >> putWord16be 100 >> put a
put (Basic_recover a) = putWord16be 60 >> putWord16be 110 >> put a
put Basic_recover_ok = putWord16be 60 >> putWord16be 111
put (Basic_nack a b c) = putWord16be 60 >> putWord16be 120 >> put a >> putBits [b,c]
put Tx_select = putWord16be 90 >> putWord16be 10
put Tx_select_ok = putWord16be 90 >> putWord16be 11
put Tx_commit = putWord16be 90 >> putWord16be 20
put Tx_commit_ok = putWord16be 90 >> putWord16be 21
put Tx_rollback = putWord16be 90 >> putWord16be 30
put Tx_rollback_ok = putWord16be 90 >> putWord16be 31
put (Confirm_select a) = putWord16be 85 >> putWord16be 10 >> put a
put Confirm_select_ok = putWord16be 85 >> putWord16be 11
get = do
classID <- getWord16be
methodID <- getWord16be
case (classID, methodID) of
(10,10) -> get >>= \a -> get >>= \b -> get >>= \c -> get >>= \d -> get >>= \e -> return (Connection_start a b c d e)
(10,11) -> get >>= \a -> get >>= \b -> get >>= \c -> get >>= \d -> return (Connection_start_ok a b c d)
(10,20) -> get >>= \a -> return (Connection_secure a)
(10,21) -> get >>= \a -> return (Connection_secure_ok a)
(10,30) -> get >>= \a -> get >>= \b -> get >>= \c -> return (Connection_tune a b c)
(10,31) -> get >>= \a -> get >>= \b -> get >>= \c -> return (Connection_tune_ok a b c)
(10,40) -> get >>= \a -> get >>= \b -> get >>= \c -> return (Connection_open a b c)
(10,41) -> get >>= \a -> return (Connection_open_ok a)
(10,50) -> get >>= \a -> get >>= \b -> get >>= \c -> get >>= \d -> return (Connection_close a b c d)
(10,51) -> return Connection_close_ok
(10,60) -> get >>= \a -> return (Connection_blocked a)
(10,61) -> return Connection_unblocked
(20,10) -> get >>= \a -> return (Channel_open a)
(20,11) -> get >>= \a -> return (Channel_open_ok a)
(20,20) -> get >>= \a -> return (Channel_flow a)
(20,21) -> get >>= \a -> return (Channel_flow_ok a)
(20,40) -> get >>= \a -> get >>= \b -> get >>= \c -> get >>= \d -> return (Channel_close a b c d)
(20,41) -> return Channel_close_ok
(40,10) -> get >>= \a -> get >>= \b -> get >>= \c -> getBits 5 >>= \[d,e,f,g,h] -> get >>= \i -> return (Exchange_declare a b c d e f g h i)
(40,11) -> return Exchange_declare_ok
(40,20) -> get >>= \a -> get >>= \b -> getBits 2 >>= \[c,d] -> return (Exchange_delete a b c d)
(40,21) -> return Exchange_delete_ok
(40,30) -> get >>= \a -> get >>= \b -> get >>= \c -> get >>= \d -> get >>= \e -> get >>= \f -> return (Exchange_bind a b c d e f)
(40,31) -> return Exchange_bind_ok
(40,40) -> get >>= \a -> get >>= \b -> get >>= \c -> get >>= \d -> get >>= \e -> get >>= \f -> return (Exchange_unbind a b c d e f)
(40,51) -> return Exchange_unbind_ok
(50,10) -> get >>= \a -> get >>= \b -> getBits 5 >>= \[c,d,e,f,g] -> get >>= \h -> return (Queue_declare a b c d e f g h)
(50,11) -> get >>= \a -> get >>= \b -> get >>= \c -> return (Queue_declare_ok a b c)
(50,20) -> get >>= \a -> get >>= \b -> get >>= \c -> get >>= \d -> get >>= \e -> get >>= \f -> return (Queue_bind a b c d e f)
(50,21) -> return Queue_bind_ok
(50,50) -> get >>= \a -> get >>= \b -> get >>= \c -> get >>= \d -> get >>= \e -> return (Queue_unbind a b c d e)
(50,51) -> return Queue_unbind_ok
(50,30) -> get >>= \a -> get >>= \b -> get >>= \c -> return (Queue_purge a b c)
(50,31) -> get >>= \a -> return (Queue_purge_ok a)
(50,40) -> get >>= \a -> get >>= \b -> getBits 3 >>= \[c,d,e] -> return (Queue_delete a b c d e)
(50,41) -> get >>= \a -> return (Queue_delete_ok a)
(60,10) -> get >>= \a -> get >>= \b -> get >>= \c -> return (Basic_qos a b c)
(60,11) -> return Basic_qos_ok
(60,20) -> get >>= \a -> get >>= \b -> get >>= \c -> getBits 4 >>= \[d,e,f,g] -> get >>= \h -> return (Basic_consume a b c d e f g h)
(60,21) -> get >>= \a -> return (Basic_consume_ok a)
(60,30) -> get >>= \a -> get >>= \b -> return (Basic_cancel a b)
(60,31) -> get >>= \a -> return (Basic_cancel_ok a)
(60,40) -> get >>= \a -> get >>= \b -> get >>= \c -> getBits 2 >>= \[d,e] -> return (Basic_publish a b c d e)
(60,50) -> get >>= \a -> get >>= \b -> get >>= \c -> get >>= \d -> return (Basic_return a b c d)
(60,60) -> get >>= \a -> get >>= \b -> get >>= \c -> get >>= \d -> get >>= \e -> return (Basic_deliver a b c d e)
(60,70) -> get >>= \a -> get >>= \b -> get >>= \c -> return (Basic_get a b c)
(60,71) -> get >>= \a -> get >>= \b -> get >>= \c -> get >>= \d -> get >>= \e -> return (Basic_get_ok a b c d e)
(60,72) -> get >>= \a -> return (Basic_get_empty a)
(60,80) -> get >>= \a -> get >>= \b -> return (Basic_ack a b)
(60,90) -> get >>= \a -> get >>= \b -> return (Basic_reject a b)
(60,100) -> get >>= \a -> return (Basic_recover_async a)
(60,110) -> get >>= \a -> return (Basic_recover a)
(60,111) -> return Basic_recover_ok
(60,120) -> get >>= \a -> getBits 2 >>= \[b,c] -> return (Basic_nack a b c)
(90,10) -> return Tx_select
(90,11) -> return Tx_select_ok
(90,20) -> return Tx_commit
(90,21) -> return Tx_commit_ok
(90,30) -> return Tx_rollback
(90,31) -> return Tx_rollback_ok
(85,10) -> get >>= \a -> return (Confirm_select a)
(85,11) -> return Confirm_select_ok
x -> error ("Unexpected classID and methodID: " ++ show x)
data MethodPayload =
Connection_start
Octet
Octet
FieldTable
LongString
LongString
|
Connection_start_ok
FieldTable
ShortString
LongString
ShortString
|
Connection_secure
LongString
|
Connection_secure_ok
LongString
|
Connection_tune
ShortInt
LongInt
ShortInt
|
Connection_tune_ok
ShortInt
LongInt
ShortInt
|
Connection_open
ShortString
ShortString
Bit
|
Connection_open_ok
ShortString
|
Connection_close
ShortInt
ShortString
ShortInt
ShortInt
|
Connection_close_ok
|
Connection_blocked
ShortString
|
Connection_unblocked
|
Channel_open
ShortString
|
Channel_open_ok
LongString
|
Channel_flow
Bit
|
Channel_flow_ok
Bit
|
Channel_close
ShortInt
ShortString
ShortInt
ShortInt
|
Channel_close_ok
|
Exchange_declare
ShortInt
ShortString
ShortString
Bit
Bit
Bit
Bit
Bit
FieldTable
|
Exchange_declare_ok
|
Exchange_delete
ShortInt
ShortString
Bit
Bit
|
Exchange_delete_ok
|
Exchange_bind
ShortInt
ShortString
ShortString
ShortString
Bit
FieldTable
|
Exchange_bind_ok
|
Exchange_unbind
ShortInt
ShortString
ShortString
ShortString
Bit
FieldTable
|
Exchange_unbind_ok
|
Queue_declare
ShortInt
ShortString
Bit
Bit
Bit
Bit
Bit
FieldTable
|
Queue_declare_ok
ShortString
LongInt
LongInt
|
Queue_bind
ShortInt
ShortString
ShortString
ShortString
Bit
FieldTable
|
Queue_bind_ok
|
Queue_unbind
ShortInt
ShortString
ShortString
ShortString
FieldTable
|
Queue_unbind_ok
|
Queue_purge
ShortInt
ShortString
Bit
|
Queue_purge_ok
LongInt
|
Queue_delete
ShortInt
ShortString
Bit
Bit
Bit
|
Queue_delete_ok
LongInt
|
Basic_qos
LongInt
ShortInt
Bit
|
Basic_qos_ok
|
Basic_consume
ShortInt
ShortString
ShortString
Bit
Bit
Bit
Bit
FieldTable
|
Basic_consume_ok
ShortString
|
Basic_cancel
ShortString
Bit
|
Basic_cancel_ok
ShortString
|
Basic_publish
ShortInt
ShortString
ShortString
Bit
Bit
|
Basic_return
ShortInt
ShortString
ShortString
ShortString
|
Basic_deliver
ShortString
LongLongInt
Bit
ShortString
ShortString
|
Basic_get
ShortInt
ShortString
Bit
|
Basic_get_ok
LongLongInt
Bit
ShortString
ShortString
LongInt
|
Basic_get_empty
ShortString
|
Basic_ack
LongLongInt
Bit
|
Basic_reject
LongLongInt
Bit
|
Basic_recover_async
Bit
|
Basic_recover
Bit
|
Basic_recover_ok
|
Basic_nack
LongLongInt
Bit
Bit
|
Tx_select
|
Tx_select_ok
|
Tx_commit
|
Tx_commit_ok
|
Tx_rollback
|
Tx_rollback_ok
|
Confirm_select
Bit
|
Confirm_select_ok
deriving Show