summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRoger Hu <roger.hu@gmail.com>2014-06-16 07:52:56 -0700
committerAsk Solem <ask@celeryproject.org>2015-10-30 12:15:38 -0700
commit612211932b0cec65642fd8e47b7bb3f563eef14a (patch)
tree52a0177e114cd301417276e2e380f0fa3c341104
parent5a4503490e8888147347f52c03b3ecf533220132 (diff)
downloadlibrabbitmq-612211932b0cec65642fd8e47b7bb3f563eef14a.tar.gz
Add support for boolean.
As I was trying to add AMQP extensions, I noticed that I couldn't pass in a dictionary with boolean types without adding support. Add indent.
-rw-r--r--Modules/_librabbitmq/connection.c23
1 files changed, 23 insertions, 0 deletions
diff --git a/Modules/_librabbitmq/connection.c b/Modules/_librabbitmq/connection.c
index 2897266..af52cd4 100644
--- a/Modules/_librabbitmq/connection.c
+++ b/Modules/_librabbitmq/connection.c
@@ -39,6 +39,9 @@ _PYRMQ_INLINE void
AMQTable_SetStringValue(amqp_table_t*, amqp_bytes_t, amqp_bytes_t);
_PYRMQ_INLINE void
+AMQTable_SetBoolValue(amqp_table_t*, amqp_bytes_t, int);
+
+_PYRMQ_INLINE void
AMQTable_SetIntValue(amqp_table_t *, amqp_bytes_t, int);
_PYRMQ_INLINE void
@@ -161,6 +164,15 @@ AMQTable_SetStringValue(amqp_table_t *table,
}
_PYRMQ_INLINE void
+AMQTable_SetBoolValue(amqp_table_t *table,
+ amqp_bytes_t key, int value)
+{
+ amqp_table_entry_t *entry = AMQTable_AddEntry(table, key);
+ entry->value.kind = AMQP_FIELD_KIND_BOOLEAN;
+ entry->value.value.boolean = value;
+}
+
+_PYRMQ_INLINE void
AMQTable_SetIntValue(amqp_table_t *table,
amqp_bytes_t key, int value)
{
@@ -266,6 +278,17 @@ PyDict_ToAMQTable(amqp_connection_state_t conn, PyObject *src, amqp_pool_t *pool
PyString_AS_AMQBYTES(dkey),
PyIter_ToAMQArray(conn, dvalue, pool));
}
+ else if (PyBool_Check(dvalue)) {
+ /* Bool */
+ clong_value = 0; /* default false */
+
+ if (dvalue == Py_True)
+ clong_value = 1;
+
+ AMQTable_SetBoolValue(&dst,
+ PyString_AS_AMQBYTES(dkey),
+ clong_value);
+ }
else if (PyLong_Check(dvalue) || PyInt_Check(dvalue)) {
/* Int | Long */
clong_value = (int64_t)PyLong_AsLong(dvalue);