@@ -816,15 +816,27 @@ static int TopicPartition_clear (TopicPartition *self) {
816
816
Py_DECREF (self -> error );
817
817
self -> error = NULL ;
818
818
}
819
+ if (self -> metadata ) {
820
+ free (self -> metadata );
821
+ self -> metadata = NULL ;
822
+ }
819
823
return 0 ;
820
824
}
821
825
822
826
static void TopicPartition_setup (TopicPartition * self , const char * topic ,
823
827
int partition , long long offset ,
828
+ const char * metadata ,
824
829
rd_kafka_resp_err_t err ) {
825
830
self -> topic = strdup (topic );
826
831
self -> partition = partition ;
827
832
self -> offset = offset ;
833
+
834
+ if (metadata != NULL ) {
835
+ self -> metadata = strdup (metadata );
836
+ } else {
837
+ self -> metadata = NULL ;
838
+ }
839
+
828
840
self -> error = KafkaError_new_or_None (err , NULL );
829
841
}
830
842
@@ -843,18 +855,22 @@ static int TopicPartition_init (PyObject *self, PyObject *args,
843
855
const char * topic ;
844
856
int partition = RD_KAFKA_PARTITION_UA ;
845
857
long long offset = RD_KAFKA_OFFSET_INVALID ;
858
+ const char * metadata = NULL ;
859
+
846
860
static char * kws [] = { "topic" ,
847
861
"partition" ,
848
862
"offset" ,
863
+ "metadata" ,
849
864
NULL };
850
865
851
- if (!PyArg_ParseTupleAndKeywords (args , kwargs , "s|iL" , kws ,
852
- & topic , & partition , & offset ))
866
+ if (!PyArg_ParseTupleAndKeywords (args , kwargs , "s|iLs" , kws ,
867
+ & topic , & partition , & offset ,
868
+ & metadata )) {
853
869
return -1 ;
870
+ }
854
871
855
872
TopicPartition_setup ((TopicPartition * )self ,
856
- topic , partition , offset , 0 );
857
-
873
+ topic , partition , offset , metadata , 0 );
858
874
return 0 ;
859
875
}
860
876
@@ -889,6 +905,9 @@ static PyMemberDef TopicPartition_members[] = {
889
905
" :py:const:`OFFSET_STORED`,"
890
906
" :py:const:`OFFSET_INVALID`\n"
891
907
},
908
+ {"metadata" , T_STRING , offsetof(TopicPartition , metadata ), READONLY ,
909
+ "attribute metadata: Optional application metadata committed with the "
910
+ "offset (string)" },
892
911
{ "error" , T_OBJECT , offsetof(TopicPartition , error ), READONLY ,
893
912
":attribute error: Indicates an error (with :py:class:`KafkaError`) unless None." },
894
913
{ NULL }
@@ -1038,14 +1057,15 @@ PyTypeObject TopicPartitionType = {
1038
1057
* @brief Internal factory to create a TopicPartition object.
1039
1058
*/
1040
1059
static PyObject * TopicPartition_new0 (const char * topic , int partition ,
1041
- long long offset ,
1060
+ long long offset , const char * metadata ,
1042
1061
rd_kafka_resp_err_t err ) {
1043
1062
TopicPartition * self ;
1044
1063
1045
1064
self = (TopicPartition * )TopicPartitionType .tp_new (
1046
1065
& TopicPartitionType , NULL , NULL );
1047
1066
1048
- TopicPartition_setup (self , topic , partition , offset , err );
1067
+ TopicPartition_setup (self , topic , partition ,
1068
+ offset , metadata , err );
1049
1069
1050
1070
return (PyObject * )self ;
1051
1071
}
@@ -1069,7 +1089,9 @@ PyObject *c_parts_to_py (const rd_kafka_topic_partition_list_t *c_parts) {
1069
1089
PyList_SET_ITEM (parts , i ,
1070
1090
TopicPartition_new0 (
1071
1091
rktpar -> topic , rktpar -> partition ,
1072
- rktpar -> offset , rktpar -> err ));
1092
+ rktpar -> offset ,
1093
+ rktpar -> metadata ,
1094
+ rktpar -> err ));
1073
1095
}
1074
1096
1075
1097
return parts ;
@@ -1094,6 +1116,7 @@ rd_kafka_topic_partition_list_t *py_to_c_parts (PyObject *plist) {
1094
1116
c_parts = rd_kafka_topic_partition_list_new ((int )PyList_Size (plist ));
1095
1117
1096
1118
for (i = 0 ; i < (size_t )PyList_Size (plist ) ; i ++ ) {
1119
+ rd_kafka_topic_partition_t * rktpar ;
1097
1120
TopicPartition * tp = (TopicPartition * )
1098
1121
PyList_GetItem (plist , i );
1099
1122
@@ -1106,10 +1129,17 @@ rd_kafka_topic_partition_list_t *py_to_c_parts (PyObject *plist) {
1106
1129
return NULL ;
1107
1130
}
1108
1131
1109
- rd_kafka_topic_partition_list_add (c_parts ,
1110
- tp -> topic ,
1111
- tp -> partition )-> offset =
1112
- tp -> offset ;
1132
+ rktpar = rd_kafka_topic_partition_list_add (c_parts ,
1133
+ tp -> topic ,
1134
+ tp -> partition );
1135
+ rktpar -> offset = tp -> offset ;
1136
+ if (tp -> metadata != NULL ) {
1137
+ rktpar -> metadata_size = strlen (tp -> metadata ) + 1 ;
1138
+ rktpar -> metadata = strdup (tp -> metadata );
1139
+ } else {
1140
+ rktpar -> metadata_size = 0 ;
1141
+ rktpar -> metadata = NULL ;
1142
+ }
1113
1143
}
1114
1144
1115
1145
return c_parts ;
0 commit comments