Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion kafka/protocol/types.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import struct
from struct import error
import uuid

from kafka.protocol.abstract import AbstractType

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


class UUID(AbstractType):
ZERO_UUID = uuid.UUID(int=0)

@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
Expand Down Expand Up @@ -346,7 +361,6 @@ def encode(cls, value):


class CompactArray(Array):

def encode(self, items):
if items is None:
return UnsignedVarInt32.encode(0)
Expand Down
Loading