From 97c7d8829b96f37ae8ee9d3980cc443d77845534 Mon Sep 17 00:00:00 2001 From: Dana Powers Date: Mon, 21 Dec 2015 01:45:23 -0800 Subject: Add Message.validate_crc() method --- kafka/protocol/message.py | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'kafka/protocol/message.py') diff --git a/kafka/protocol/message.py b/kafka/protocol/message.py index a67d7f5..f6cbb33 100644 --- a/kafka/protocol/message.py +++ b/kafka/protocol/message.py @@ -42,6 +42,13 @@ class Message(Struct): return cls(fields[4], key=fields[3], magic=fields[1], attributes=fields[2], crc=fields[0]) + def validate_crc(self): + raw_msg = self._encode_self(recalc_crc=False) + crc = crc32(raw_msg[4:]) + if crc == self.crc: + return True + return False + class PartialMessage(bytes): def __repr__(self): -- cgit v1.2.1