Skip to content

Commit a2fbbf6

Browse files
committed
Py3: use bytes for Message payload and key
1 parent d62630d commit a2fbbf6

File tree

3 files changed

+12
-11
lines changed

3 files changed

+12
-11
lines changed

confluent_kafka/src/Producer.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -370,8 +370,8 @@ static PyMethodDef Producer_methods[] = {
370370
"message has been succesfully delivered or permanently fails delivery.\n"
371371
"\n"
372372
" :param str topic: Topic to produce message to\n"
373-
" :param str value: Message payload\n"
374-
" :param str key: Message key\n"
373+
" :param str|bytes value: Message payload\n"
374+
" :param str|bytes key: Message key\n"
375375
" :param int partition: Partition to produce to, elses uses the "
376376
"configured partitioner.\n"
377377
" :param func on_delivery(err,msg): Delivery report callback to call "

confluent_kafka/src/confluent_kafka.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -339,12 +339,12 @@ static PyMethodDef Message_methods[] = {
339339

340340
{ "value", (PyCFunction)Message_value, METH_NOARGS,
341341
" :returns: message value (payload) or None if not available.\n"
342-
" :rtype: str or None\n"
342+
" :rtype: str|bytes or None\n"
343343
"\n"
344344
},
345345
{ "key", (PyCFunction)Message_key, METH_NOARGS,
346346
" :returns: message key or None if not available.\n"
347-
" :rtype: str or None\n"
347+
" :rtype: str|bytes or None\n"
348348
"\n"
349349
},
350350
{ "topic", (PyCFunction)Message_topic, METH_NOARGS,
@@ -486,10 +486,10 @@ PyObject *Message_new0 (const rd_kafka_message_t *rkm) {
486486
self->topic = cfl_PyUnistr(
487487
_FromString(rd_kafka_topic_name(rkm->rkt)));
488488
if (rkm->payload)
489-
self->value = cfl_PyUnistr(_FromStringAndSize(rkm->payload,
490-
rkm->len));
489+
self->value = cfl_PyBin(_FromStringAndSize(rkm->payload,
490+
rkm->len));
491491
if (rkm->key)
492-
self->key = cfl_PyUnistr(
492+
self->key = cfl_PyBin(
493493
_FromStringAndSize(rkm->key, rkm->key_len));
494494

495495
self->partition = rkm->partition;

confluent_kafka/src/confluent_kafka.h

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,12 +41,12 @@
4141
*
4242
****************************************************************************/
4343

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

5151
/**
5252
* @brief Unicode type, same usage as PyBin()
@@ -62,7 +62,8 @@
6262
* @returns Unicode Python string object
6363
*/
6464
#define cfl_PyObject_Unistr(X) PyObject_Str(X)
65-
#else
65+
66+
#else /* Python 2 */
6667

6768
/* See comments above */
6869
#define cfl_PyBin(X) PyString ## X

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy