Skip to content

Commit 46a1cc6

Browse files
authored
Add UUID protocol type (#2703)
1 parent 23b848c commit 46a1cc6

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

kafka/protocol/types.py

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import struct
22
from struct import error
3+
import uuid
34

45
from kafka.protocol.abstract import AbstractType
56

@@ -88,6 +89,20 @@ def decode(cls, data):
8889
return _unpack(cls._unpack, data.read(8))
8990

9091

92+
class UUID(AbstractType):
93+
ZERO_UUID = uuid.UUID(int=0)
94+
95+
@classmethod
96+
def encode(cls, value):
97+
if isinstance(value, uuid.UUID):
98+
return value.bytes
99+
return uuid.UUID(value).bytes
100+
101+
@classmethod
102+
def decode(cls, data):
103+
return uuid.UUID(bytes=data.read(16))
104+
105+
91106
class String(AbstractType):
92107
def __init__(self, encoding='utf-8'):
93108
self.encoding = encoding
@@ -346,7 +361,6 @@ def encode(cls, value):
346361

347362

348363
class CompactArray(Array):
349-
350364
def encode(self, items):
351365
if items is None:
352366
return UnsignedVarInt32.encode(0)

0 commit comments

Comments
 (0)