Skip to content

Commit da00e19

Browse files
committed
Add UUID protocol type
1 parent 223c320 commit da00e19

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

kafka/protocol/types.py

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import struct
44
from struct import error
5+
import uuid
56

67
from kafka.protocol.abstract import AbstractType
78

@@ -90,6 +91,18 @@ def decode(cls, data):
9091
return _unpack(cls._unpack, data.read(8))
9192

9293

94+
class UUID(AbstractType):
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+
93106
class String(AbstractType):
94107
def __init__(self, encoding='utf-8'):
95108
self.encoding = encoding
@@ -348,7 +361,6 @@ def encode(cls, value):
348361

349362

350363
class CompactArray(Array):
351-
352364
def encode(self, items):
353365
if items is None:
354366
return UnsignedVarInt32.encode(0)
@@ -362,4 +374,3 @@ def decode(self, data):
362374
if length == -1:
363375
return None
364376
return [self.array_of.decode(data) for _ in range(length)]
365-

0 commit comments

Comments
 (0)