Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Py3: use bytes for Message payload and key
  • Loading branch information
edenhill committed May 25, 2016
commit a2fbbf688402a33b48ade378b4fe6a1e1efd6ee6
4 changes: 2 additions & 2 deletions confluent_kafka/src/Producer.c
Original file line number Diff line number Diff line change
Expand Up @@ -370,8 +370,8 @@ static PyMethodDef Producer_methods[] = {
"message has been succesfully delivered or permanently fails delivery.\n"
"\n"
" :param str topic: Topic to produce message to\n"
" :param str value: Message payload\n"
" :param str key: Message key\n"
" :param str|bytes value: Message payload\n"
" :param str|bytes key: Message key\n"
" :param int partition: Partition to produce to, elses uses the "
"configured partitioner.\n"
" :param func on_delivery(err,msg): Delivery report callback to call "
Expand Down
10 changes: 5 additions & 5 deletions confluent_kafka/src/confluent_kafka.c
Original file line number Diff line number Diff line change
Expand Up @@ -339,12 +339,12 @@ static PyMethodDef Message_methods[] = {

{ "value", (PyCFunction)Message_value, METH_NOARGS,
" :returns: message value (payload) or None if not available.\n"
" :rtype: str or None\n"
" :rtype: str|bytes or None\n"
"\n"
},
{ "key", (PyCFunction)Message_key, METH_NOARGS,
" :returns: message key or None if not available.\n"
" :rtype: str or None\n"
" :rtype: str|bytes or None\n"
"\n"
},
{ "topic", (PyCFunction)Message_topic, METH_NOARGS,
Expand Down Expand Up @@ -486,10 +486,10 @@ PyObject *Message_new0 (const rd_kafka_message_t *rkm) {
self->topic = cfl_PyUnistr(
_FromString(rd_kafka_topic_name(rkm->rkt)));
if (rkm->payload)
self->value = cfl_PyUnistr(_FromStringAndSize(rkm->payload,
rkm->len));
self->value = cfl_PyBin(_FromStringAndSize(rkm->payload,
rkm->len));
if (rkm->key)
self->key = cfl_PyUnistr(
self->key = cfl_PyBin(
_FromStringAndSize(rkm->key, rkm->key_len));

self->partition = rkm->partition;
Expand Down
9 changes: 5 additions & 4 deletions confluent_kafka/src/confluent_kafka.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,12 @@
*
****************************************************************************/

#ifdef PY3
#ifdef PY3 /* Python 3 */
/**
* @brief Binary type, use as cfl_PyBin(_X(A,B)) where _X() is the type-less
* suffix of a PyBinary/Str_X() function
* suffix of a PyBytes/Str_X() function
*/
#define cfl_PyBin(X) PyBinary ## X
#define cfl_PyBin(X) PyBytes ## X

/**
* @brief Unicode type, same usage as PyBin()
Expand All @@ -62,7 +62,8 @@
* @returns Unicode Python string object
*/
#define cfl_PyObject_Unistr(X) PyObject_Str(X)
#else

#else /* Python 2 */

/* See comments above */
#define cfl_PyBin(X) PyString ## X
Expand Down