@@ -810,6 +810,158 @@ PyObject *Message_new0 (const Handle *handle, const rd_kafka_message_t *rkm) {
810810
811811
812812
813+ /****************************************************************************
814+ *
815+ *
816+ * Uuid
817+ *
818+ *
819+ *
820+ *
821+ ****************************************************************************/
822+ static PyObject * Uuid_most_significant_bits (Uuid * self , PyObject * ignore ) {
823+ if (self -> cUuid ) {
824+ return cfl_PyLong_FromLong (rd_kafka_Uuid_most_significant_bits (self -> cUuid ));
825+ }
826+ Py_RETURN_NONE ;
827+ }
828+
829+ static PyObject * Uuid_least_significant_bits (Uuid * self , PyObject * ignore ) {
830+ if (self -> cUuid ) {
831+ return cfl_PyLong_FromLong (rd_kafka_Uuid_least_significant_bits (self -> cUuid ));
832+ }
833+ Py_RETURN_NONE ;
834+ }
835+
836+ static PyMethodDef Uuid_methods [] = {
837+ { "get_most_significant_bits" , (PyCFunction )Uuid_most_significant_bits , METH_NOARGS ,
838+ " :returns: Most significant 64 bits of the 128 bits Uuid\n"
839+ " :rtype: int\n"
840+ "\n"
841+ },
842+ { "get_least_significant_bits" , (PyCFunction )Uuid_least_significant_bits , METH_NOARGS ,
843+ " :returns: Least significant 64 bits of the 128 bits Uuid\n"
844+ " :rtype: int\n"
845+ "\n"
846+ },
847+ { NULL }
848+ };
849+
850+
851+ static PyObject * Uuid_str0 (Uuid * self ) {
852+ if (self -> cUuid ) {
853+ const char * base64str = rd_kafka_Uuid_base64str (self -> cUuid );
854+ if (base64str )
855+ return cfl_PyUnistr (_FromString (base64str ));
856+ }
857+ Py_RETURN_NONE ;
858+ }
859+
860+ static long Uuid_hash (Uuid * self ) {
861+
862+ return rd_kafka_Uuid_most_significant_bits (self -> cUuid ) ^ rd_kafka_Uuid_least_significant_bits (self -> cUuid );
863+ }
864+
865+
866+ static PyObject * Uuid_new (PyTypeObject * type , PyObject * args ,
867+ PyObject * kwargs ) {
868+ PyObject * self = type -> tp_alloc (type , 1 );
869+ return self ;
870+ }
871+
872+
873+ static int Uuid_init (PyObject * self0 , PyObject * args ,
874+ PyObject * kwargs ) {
875+ Uuid * self = (Uuid * )self0 ;
876+ static char * kws [] = { "most_significant_bits" ,
877+ "least_significant_bits" ,
878+ NULL };
879+ int64_t most_significant_bits ;
880+ int64_t least_significant_bits ;
881+
882+ if (!PyArg_ParseTupleAndKeywords (args , kwargs , "LL" , kws ,
883+ & most_significant_bits ,
884+ & least_significant_bits ))
885+ return -1 ;
886+
887+ self -> cUuid = rd_kafka_Uuid_new (most_significant_bits , least_significant_bits );
888+
889+ return 0 ;
890+ }
891+
892+ static int Uuid_clear (Uuid * self ) {
893+ if (self -> cUuid ) {
894+ rd_kafka_Uuid_destroy (self -> cUuid );
895+ self -> cUuid = NULL ;
896+ }
897+ return 0 ;
898+ }
899+
900+ static int Uuid_traverse (Uuid * self ,
901+ visitproc visit , void * arg ) {
902+ return 0 ;
903+ }
904+
905+ static void Uuid_dealloc (Uuid * self ) {
906+ PyObject_GC_UnTrack (self );
907+ Uuid_clear (self );
908+
909+ Py_TYPE (self )-> tp_free ((PyObject * )self );
910+ }
911+
912+ PyTypeObject UuidType = {
913+ PyVarObject_HEAD_INIT (NULL , 0 )
914+ "cimpl.Uuid" , /* tp_name */
915+ sizeof (Uuid ), /* tp_basicsize */
916+ 0 , /* tp_itemsize */
917+ (destructor )Uuid_dealloc , /* tp_dealloc */
918+ 0 , /* tp_print */
919+ 0 , /* tp_getattr */
920+ 0 , /* tp_setattr */
921+ 0 , /* tp_compare */
922+ (reprfunc )Uuid_str0 , /* tp_repr */
923+ 0 , /* tp_as_number */
924+ 0 , /* tp_as_sequence */
925+ 0 , /* tp_as_mapping */
926+ (hashfunc )Uuid_hash , /* tp_hash */
927+ 0 , /* tp_call */
928+ 0 , /* tp_str */
929+ PyObject_GenericGetAttr , /* tp_getattro */
930+ 0 , /* tp_setattro */
931+ 0 , /* tp_as_buffer */
932+ Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE |
933+ Py_TPFLAGS_HAVE_GC , /* tp_flags */
934+ "Generic Uuid. Being used in various identifiers including topic_id.\n"
935+ "\n"
936+ ".. py:function:: Uuid(most_significant_bits, least_significant_bits)\n"
937+ "\n"
938+ " Instantiate a Uuid object.\n"
939+ "\n"
940+ " :param long most_significant_bits: Most significant 64 bits of the 128 bits Uuid.\n"
941+ " :param long least_significant_bits: Least significant 64 bits of the 128 bits Uuid.\n"
942+ " :rtype: Uuid\n"
943+ "\n"
944+ "\n" , /* tp_doc */
945+ (traverseproc )Uuid_traverse , /* tp_traverse */
946+ (inquiry )Uuid_clear , /* tp_clear */
947+ 0 , /* tp_richcompare */
948+ 0 , /* tp_weaklistoffset */
949+ 0 , /* tp_iter */
950+ 0 , /* tp_iternext */
951+ Uuid_methods , /* tp_methods */
952+ 0 , /* tp_members */
953+ 0 , /* tp_getset */
954+ 0 , /* tp_base */
955+ 0 , /* tp_dict */
956+ 0 , /* tp_descr_get */
957+ 0 , /* tp_descr_set */
958+ 0 , /* tp_dictoffset */
959+ Uuid_init , /* tp_init */
960+ 0 , /* tp_alloc */
961+ Uuid_new /* tp_new */
962+ };
963+
964+
813965
814966/****************************************************************************
815967 *
@@ -1488,6 +1640,47 @@ PyObject *c_Node_to_py(const rd_kafka_Node_t *c_node) {
14881640 return NULL ;
14891641}
14901642
1643+ PyObject * c_Uuid_to_py (const rd_kafka_Uuid_t * c_uuid ) {
1644+ PyObject * uuid = NULL ;
1645+ PyObject * Uuid_type = NULL ;
1646+ PyObject * args = NULL ;
1647+ PyObject * kwargs = NULL ;
1648+
1649+ if (!c_uuid )
1650+ Py_RETURN_NONE ;
1651+
1652+ Uuid_type = cfl_PyObject_lookup ("confluent_kafka" ,
1653+ "Uuid" );
1654+ if (!Uuid_type ) {
1655+ goto err ;
1656+ }
1657+
1658+
1659+ kwargs = PyDict_New ();
1660+
1661+ cfl_PyDict_SetLong (kwargs , "most_significant_bits" , rd_kafka_Uuid_most_significant_bits (c_uuid ));
1662+ cfl_PyDict_SetLong (kwargs , "least_significant_bits" , rd_kafka_Uuid_least_significant_bits (c_uuid ));
1663+
1664+ args = PyTuple_New (0 );
1665+
1666+ uuid = PyObject_Call (Uuid_type , args , kwargs );
1667+
1668+ Py_DECREF (Uuid_type );
1669+ Py_DECREF (args );
1670+ Py_DECREF (kwargs );
1671+
1672+ return uuid ;
1673+
1674+ err :
1675+ Py_XDECREF (Uuid_type );
1676+ Py_XDECREF (args );
1677+ Py_XDECREF (kwargs );
1678+ Py_XDECREF (uuid );
1679+
1680+ return NULL ;
1681+
1682+ }
1683+
14911684
14921685/****************************************************************************
14931686 *
@@ -2834,6 +3027,8 @@ static PyObject *_init_cimpl (void) {
28343027 return NULL ;
28353028 if (PyType_Ready (& MessageType ) < 0 )
28363029 return NULL ;
3030+ if (PyType_Ready (& UuidType ) < 0 )
3031+ return NULL ;
28373032 if (PyType_Ready (& TopicPartitionType ) < 0 )
28383033 return NULL ;
28393034 if (PyType_Ready (& ProducerType ) < 0 )
@@ -2863,6 +3058,9 @@ static PyObject *_init_cimpl (void) {
28633058 Py_INCREF (& MessageType );
28643059 PyModule_AddObject (m , "Message" , (PyObject * )& MessageType );
28653060
3061+ Py_INCREF (& UuidType );
3062+ PyModule_AddObject (m , "Uuid" , (PyObject * )& UuidType );
3063+
28663064 Py_INCREF (& TopicPartitionType );
28673065 PyModule_AddObject (m , "TopicPartition" ,
28683066 (PyObject * )& TopicPartitionType );
0 commit comments