From 813bf91b30cecdf4dcc07c21e1f7ba2fa6dfec78 Mon Sep 17 00:00:00 2001 From: Dana Powers Date: Mon, 24 Feb 2025 13:14:05 -0800 Subject: [PATCH 1/2] Add UUID protocol type --- kafka/protocol/types.py | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/kafka/protocol/types.py b/kafka/protocol/types.py index 812c5e74d..798fec2f4 100644 --- a/kafka/protocol/types.py +++ b/kafka/protocol/types.py @@ -1,5 +1,6 @@ import struct from struct import error +import uuid from kafka.protocol.abstract import AbstractType @@ -88,6 +89,18 @@ def decode(cls, data): return _unpack(cls._unpack, data.read(8)) +class UUID(AbstractType): + @classmethod + def encode(cls, value): + if isinstance(value, uuid.UUID): + return value.bytes + return uuid.UUID(value).bytes + + @classmethod + def decode(cls, data): + return uuid.UUID(bytes=data.read(16)) + + class String(AbstractType): def __init__(self, encoding='utf-8'): self.encoding = encoding @@ -346,7 +359,6 @@ def encode(cls, value): class CompactArray(Array): - def encode(self, items): if items is None: return UnsignedVarInt32.encode(0) From a1f2bf3fef9d84d80c537c581ff585d4b0616ec1 Mon Sep 17 00:00:00 2001 From: Dana Powers Date: Sat, 13 Dec 2025 10:03:47 -0800 Subject: [PATCH 2/2] Add ZERO_UUID const --- kafka/protocol/types.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/kafka/protocol/types.py b/kafka/protocol/types.py index 798fec2f4..7889e06d5 100644 --- a/kafka/protocol/types.py +++ b/kafka/protocol/types.py @@ -90,6 +90,8 @@ def decode(cls, data): class UUID(AbstractType): + ZERO_UUID = uuid.UUID(int=0) + @classmethod def encode(cls, value): if isinstance(value, uuid.UUID):