From a0dfe319ae8c834cc4257ef7be4aa0982490d9a0 Mon Sep 17 00:00:00 2001 From: Dana Powers Date: Sat, 16 Jul 2016 11:55:44 -0700 Subject: [PATCH] Add protocol support for null Arrays --- kafka/protocol/types.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/kafka/protocol/types.py b/kafka/protocol/types.py index 7fdfc9d..da10326 100644 --- a/kafka/protocol/types.py +++ b/kafka/protocol/types.py @@ -155,6 +155,8 @@ class Array(AbstractType): raise ValueError('Array instantiated with no array_of type') def encode(self, items): + if items is None: + return Int32.encode(-1) return b''.join( [Int32.encode(len(items))] + [self.array_of.encode(item) for item in items] @@ -162,7 +164,11 @@ class Array(AbstractType): def decode(self, data): length = Int32.decode(data) + if length == -1: + return None return [self.array_of.decode(data) for _ in range(length)] def repr(self, list_of_items): + if list_of_items is None: + return 'NULL' return '[' + ', '.join([self.array_of.repr(item) for item in list_of_items]) + ']'